@ngraveio/ur-blockchain-commons
Version:
A JS implementation of Uniform Resources(UR) Registry specification from Blockchain Commons.
102 lines (101 loc) • 3.89 kB
TypeScript
import { PathComponent } from './helpers/PathComponent';
interface KeypathInput {
path?: string | PathComponent[];
sourceFingerprint?: number;
depth?: number;
}
interface KeypathData {
components: PathComponent[];
sourceFingerprint?: number;
depth?: number;
}
interface postCBORData {
components: (number | boolean | [number, number] | [] | [number, boolean] | [number, boolean, number, boolean])[];
sourceFingerprint?: number;
depth?: number;
}
declare const Keypath_base: import("@ngraveio/bc-ur").RegistryItemClass<import("@ngraveio/bc-ur").RegistryItemBase>;
/**
* Keypath class for handling hierarchical key derivation paths.
*
* Metadata for the complete or partial derivation path of a key:
* - 'source-fingerprint': Fingerprint of the ancestor key or master key if components are empty.
* - 'depth': Number of derivation steps in the path.
*
* Valid Path String Rules:
* 1. Paths can include:
* - Single indices (e.g., `44'/0'/0'/0/0`).
* - Ranges with hardening applied to the second element (e.g., `1-6'`; `1h-6` is invalid).
* - Wildcards (`*`) at any depth (e.g., `44'/0'/0'/*`).
* - Pairs for external/internal addresses (e.g., `<0h;1h>` or `<0;1>`).
* - Mixed components combining ranges, wildcards, and pairs (e.g., `44'/0'/1'-5'/<0h;1h>/*`).
* 2. Rules for hardening:
* - Hardened indices must be ≤ `0x80000000`.
* - Hardened chars (`'` or `h`) must immediately follow the index.
* 3. Path formatting:
* - Paths can optionally start with `m`, but it is not required.
* - Components must be delimited by `/` and contain integers, ranges, wildcards, or pairs.
*
* Invalid Examples:
* - `1h-6` (hardening not applied to the second element in range).
* - `<0;1h>` (mixed hardening in pair).
*
* Usage:
* - The `components` can be passed as a string or an array of `PathComponent`.
* - `source-fingerprint`: The fingerprint of the ancestor or master key. Required if `components` is empty.
* - `depth`: The number of derivation steps in the path. If omitted, it will be inferred from `components`.
*/
export declare class Keypath extends Keypath_base {
data: KeypathData;
constructor(input: KeypathInput);
/**
* Sets the depth of the Keypath based on the number of components.
* Representing the number of derivation steps
*/
setDepth(): void;
/**
* Check if all the paths are hardened
* TODO: add tests
*/
isOnlyHardened(): boolean;
/**
* Check if all the paths are simple
* TODO: add tests
*/
isOnlySimple(): boolean;
/**
* Parses a path string into an array of PathComponent objects.
* @param path The path string to parse.
* @returns {PathComponent[]} Array of PathComponent objects.
*/
static pathToComponents(path: string): PathComponent[];
/**
* Converts an array of PathComponent objects back into a path string.
* @param components Array of PathComponent objects.
* @returns {string} Path string.
*/
static componentsToString(components: PathComponent[], hardenedFlag?: "'" | 'h'): string;
/**
* Converts the Keypath components back to a path string.
* @returns {string} Path string.
*/
toString(hardenedFlag?: "'" | 'h'): string;
/**
* Gets the components of the Keypath.
* @returns {PathComponent[]} Array of PathComponent objects.
*/
getComponents(): PathComponent[];
/**
* Gets the source fingerprint of the Keypath.
* @returns {number | undefined} Source fingerprint.
*/
getSourceFingerprint(): number | undefined;
/**
* Gets the depth of the Keypath.
* @returns {number | undefined} Depth.
*/
getDepth(): number | undefined;
preCBOR(): Map<string | number, any>;
static postCBOR(_data: Map<string | number, any>): postCBORData;
}
export {};