diff --git a/packages/launchpad/src/index.ts b/packages/launchpad/src/index.ts index 5d2647c7..dc7a11d0 100644 --- a/packages/launchpad/src/index.ts +++ b/packages/launchpad/src/index.ts @@ -124,6 +124,7 @@ export { MsgWithdrawDelegatorReward, MsgWithdrawValidatorCommission, } from "./msgs"; +export { makeCosmoshubPath } from "./paths"; export { decodeAminoPubkey, decodeBech32Pubkey, @@ -137,6 +138,6 @@ export { AccountData, Algo, AminoSignResponse, OfflineSigner } from "./signer"; export { CosmosFeeTable, SigningCosmosClient } from "./signingcosmosclient"; export { isStdTx, isWrappedStdTx, makeStdTx, CosmosSdkTx, StdTx, WrappedStdTx, WrappedTx } from "./tx"; export { pubkeyType, PubKey, StdFee, StdSignature } from "./types"; -export { makeCosmoshubPath, executeKdf, KdfConfiguration } from "./wallet"; +export { executeKdf, KdfConfiguration } from "./wallet"; export { extractKdfConfiguration, Secp256k1HdWallet } from "./secp256k1hdwallet"; export { Secp256k1Wallet } from "./secp256k1wallet"; diff --git a/packages/launchpad/src/lcdapi/lcdclient.spec.ts b/packages/launchpad/src/lcdapi/lcdclient.spec.ts index d42c3d5d..1813b349 100644 --- a/packages/launchpad/src/lcdapi/lcdclient.spec.ts +++ b/packages/launchpad/src/lcdapi/lcdclient.spec.ts @@ -6,6 +6,7 @@ import { isBroadcastTxFailure } from "../cosmosclient"; import { makeSignDoc } from "../encoding"; import { parseLogs } from "../logs"; import { MsgSend } from "../msgs"; +import { makeCosmoshubPath } from "../paths"; import { Secp256k1HdWallet } from "../secp256k1hdwallet"; import { SigningCosmosClient } from "../signingcosmosclient"; import cosmoshub from "../testdata/cosmoshub.json"; @@ -21,7 +22,6 @@ import { } from "../testutils.spec"; import { isWrappedStdTx, makeStdTx, StdTx } from "../tx"; import { StdFee } from "../types"; -import { makeCosmoshubPath } from "../wallet"; import { setupAuthExtension } from "./auth"; import { TxsResponse } from "./base"; import { LcdApiArray, LcdClient } from "./lcdclient"; diff --git a/packages/launchpad/src/paths.spec.ts b/packages/launchpad/src/paths.spec.ts new file mode 100644 index 00000000..17fd85b6 --- /dev/null +++ b/packages/launchpad/src/paths.spec.ts @@ -0,0 +1,26 @@ +import { Slip10RawIndex } from "@cosmjs/crypto"; + +import { makeCosmoshubPath } from "./paths"; + +describe("paths", () => { + describe("makeCosmoshubPath", () => { + it("works", () => { + // m/44'/118'/0'/0/0 + expect(makeCosmoshubPath(0)).toEqual([ + Slip10RawIndex.hardened(44), + Slip10RawIndex.hardened(118), + Slip10RawIndex.hardened(0), + Slip10RawIndex.normal(0), + Slip10RawIndex.normal(0), + ]); + // m/44'/118'/0'/0/123 + expect(makeCosmoshubPath(123)).toEqual([ + Slip10RawIndex.hardened(44), + Slip10RawIndex.hardened(118), + Slip10RawIndex.hardened(0), + Slip10RawIndex.normal(0), + Slip10RawIndex.normal(123), + ]); + }); + }); +}); diff --git a/packages/launchpad/src/paths.ts b/packages/launchpad/src/paths.ts new file mode 100644 index 00000000..bf4dd185 --- /dev/null +++ b/packages/launchpad/src/paths.ts @@ -0,0 +1,15 @@ +import { HdPath, Slip10RawIndex } from "@cosmjs/crypto"; + +/** + * The Cosmos Hub derivation path in the form `m/44'/118'/0'/0/a` + * with 0-based account index `a`. + */ +export function makeCosmoshubPath(a: number): HdPath { + return [ + Slip10RawIndex.hardened(44), + Slip10RawIndex.hardened(118), + Slip10RawIndex.hardened(0), + Slip10RawIndex.normal(0), + Slip10RawIndex.normal(a), + ]; +} diff --git a/packages/launchpad/src/secp256k1hdwallet.ts b/packages/launchpad/src/secp256k1hdwallet.ts index acdbd10f..cea4e63b 100644 --- a/packages/launchpad/src/secp256k1hdwallet.ts +++ b/packages/launchpad/src/secp256k1hdwallet.ts @@ -15,6 +15,7 @@ import { assert, isNonNullObject } from "@cosmjs/utils"; import { rawSecp256k1PubkeyToAddress } from "./address"; import { serializeSignDoc, StdSignDoc } from "./encoding"; +import { makeCosmoshubPath } from "./paths"; import { encodeSecp256k1Signature } from "./signature"; import { AccountData, AminoSignResponse, OfflineSigner } from "./signer"; import { @@ -23,7 +24,6 @@ import { EncryptionConfiguration, executeKdf, KdfConfiguration, - makeCosmoshubPath, supportedAlgorithms, } from "./wallet"; diff --git a/packages/launchpad/src/signingcosmosclient.spec.ts b/packages/launchpad/src/signingcosmosclient.spec.ts index 02f73981..d898a447 100644 --- a/packages/launchpad/src/signingcosmosclient.spec.ts +++ b/packages/launchpad/src/signingcosmosclient.spec.ts @@ -5,6 +5,7 @@ import { Coin, coin, coins } from "./coins"; import { assertIsBroadcastTxSuccess, PrivateCosmosClient } from "./cosmosclient"; import { GasPrice } from "./gas"; import { MsgDelegate, MsgSend } from "./msgs"; +import { makeCosmoshubPath } from "./paths"; import { Secp256k1HdWallet } from "./secp256k1hdwallet"; import { PrivateSigningCosmosClient, SigningCosmosClient } from "./signingcosmosclient"; import { @@ -14,7 +15,6 @@ import { makeRandomAddress, pendingWithoutLaunchpad, } from "./testutils.spec"; -import { makeCosmoshubPath } from "./wallet"; describe("SigningCosmosClient", () => { describe("makeReadOnly", () => { diff --git a/packages/launchpad/src/wallet.ts b/packages/launchpad/src/wallet.ts index 1c64e773..dc85068a 100644 --- a/packages/launchpad/src/wallet.ts +++ b/packages/launchpad/src/wallet.ts @@ -1,28 +1,12 @@ import { Argon2id, - HdPath, isArgon2idOptions, Random, - Slip10RawIndex, xchacha20NonceLength, Xchacha20poly1305Ietf, } from "@cosmjs/crypto"; import { toAscii } from "@cosmjs/encoding"; -/** - * The Cosmoshub derivation path in the form `m/44'/118'/0'/0/a` - * with 0-based account index `a`. - */ -export function makeCosmoshubPath(a: number): HdPath { - return [ - Slip10RawIndex.hardened(44), - Slip10RawIndex.hardened(118), - Slip10RawIndex.hardened(0), - Slip10RawIndex.normal(0), - Slip10RawIndex.normal(a), - ]; -} - /** * A fixed salt is chosen to archive a deterministic password to key derivation. * This reduces the scope of a potential rainbow attack to all CosmJS users.