amino: Transfer paths from launchpad

This commit is contained in:
willclarktech 2021-03-24 16:35:12 +01:00
parent cbf1a8f495
commit 38a650f307
No known key found for this signature in database
GPG Key ID: 551A86E2E398ADF7
2 changed files with 41 additions and 0 deletions

View 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),
]);
});
});
});

View 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),
];
}