From 00f734032d54afaaa27d330c4a3abb5b9513a4c2 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Tue, 8 Dec 2020 08:40:00 +0100 Subject: [PATCH] Add docs to HdPath --- packages/crypto/src/slip10.ts | 26 ++++++++++++++++++++++++++ packages/crypto/types/slip10.d.ts | 26 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/packages/crypto/src/slip10.ts b/packages/crypto/src/slip10.ts index 39a0bd8a..83275e0f 100644 --- a/packages/crypto/src/slip10.ts +++ b/packages/crypto/src/slip10.ts @@ -49,6 +49,32 @@ export class Slip10RawIndex extends Uint32 { } } +/** + * An array of raw SLIP10 indices. + * + * This can be constructed via string parsing: + * + * ```ts + * import { stringToPath } from "@cosmjs/crypto"; + * + * const path = stringToPath("m/0'/1/2'/2/1000000000"); + * ``` + * + * or manually: + * + * ```ts + * import { HdPath, Slip10RawIndex } from "@cosmjs/crypto"; + * + * // m/0'/1/2'/2/1000000000 + * const path: HdPath = [ + * Slip10RawIndex.hardened(0), + * Slip10RawIndex.normal(1), + * Slip10RawIndex.hardened(2), + * Slip10RawIndex.normal(2), + * Slip10RawIndex.normal(1000000000), + * ]; + * ``` + */ export type HdPath = readonly Slip10RawIndex[]; const secp256k1 = new elliptic.ec("secp256k1"); diff --git a/packages/crypto/types/slip10.d.ts b/packages/crypto/types/slip10.d.ts index cd90a65f..c808a0f0 100644 --- a/packages/crypto/types/slip10.d.ts +++ b/packages/crypto/types/slip10.d.ts @@ -21,6 +21,32 @@ export declare class Slip10RawIndex extends Uint32 { static normal(normalIndex: number): Slip10RawIndex; isHardened(): boolean; } +/** + * An array of raw SLIP10 indices. + * + * This can be constructed via string parsing: + * + * ```ts + * import { stringToPath } from "@cosmjs/crypto"; + * + * const path = stringToPath("m/0'/1/2'/2/1000000000"); + * ``` + * + * or manually: + * + * ```ts + * import { HdPath, Slip10RawIndex } from "@cosmjs/crypto"; + * + * // m/0'/1/2'/2/1000000000 + * const path: HdPath = [ + * Slip10RawIndex.hardened(0), + * Slip10RawIndex.normal(1), + * Slip10RawIndex.hardened(2), + * Slip10RawIndex.normal(2), + * Slip10RawIndex.normal(1000000000), + * ]; + * ``` + */ export declare type HdPath = readonly Slip10RawIndex[]; export declare class Slip10 { static derivePath(curve: Slip10Curve, seed: Uint8Array, path: HdPath): Slip10Result;