From 38a650f30764b6c015732cffc240dbca9c2a777f Mon Sep 17 00:00:00 2001 From: willclarktech Date: Wed, 24 Mar 2021 16:35:12 +0100 Subject: [PATCH] amino: Transfer paths from launchpad --- packages/amino/src/paths.spec.ts | 26 ++++++++++++++++++++++++++ packages/amino/src/paths.ts | 15 +++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 packages/amino/src/paths.spec.ts create mode 100644 packages/amino/src/paths.ts diff --git a/packages/amino/src/paths.spec.ts b/packages/amino/src/paths.spec.ts new file mode 100644 index 00000000..17fd85b6 --- /dev/null +++ b/packages/amino/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/amino/src/paths.ts b/packages/amino/src/paths.ts new file mode 100644 index 00000000..bf4dd185 --- /dev/null +++ b/packages/amino/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), + ]; +}