Extract and test makeCosmoshubPath
This commit is contained in:
parent
349508e8d7
commit
83a4b0ef80
@ -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";
|
||||
|
||||
@ -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";
|
||||
|
||||
26
packages/launchpad/src/paths.spec.ts
Normal file
26
packages/launchpad/src/paths.spec.ts
Normal file
@ -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),
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
15
packages/launchpad/src/paths.ts
Normal file
15
packages/launchpad/src/paths.ts
Normal file
@ -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),
|
||||
];
|
||||
}
|
||||
@ -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";
|
||||
|
||||
|
||||
@ -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", () => {
|
||||
|
||||
@ -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.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user