WIP (BlockchainLocal working)
Signed-off-by: James Zuccon <zuccon@gmail.com>
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
deriveHdPath,
|
||||
deriveHdPublicNode,
|
||||
deriveHdPrivateNodeFromSeed,
|
||||
deriveSeedFromBip39Mnemonic,
|
||||
generateRandomBytes,
|
||||
} from '@bitauth/libauth';
|
||||
|
||||
@@ -26,38 +27,16 @@ export class HDPrivateNode {
|
||||
/**
|
||||
* Construct a new HD Private Node.
|
||||
*
|
||||
* @param node {HdPrivateNodeValid} The HD Private Node.
|
||||
* @param node The HD Private Node.
|
||||
*/
|
||||
constructor(node: HdPrivateNodeValid) {
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a HD Private Node from the given XPriv Key.
|
||||
*
|
||||
* @param xpriv {string} The XPriv Key.
|
||||
*
|
||||
* @throws {Error} If HD Private Node cannot be created.
|
||||
*
|
||||
* @returns {HDPrivateNode} The created HD Private Node.
|
||||
*/
|
||||
public static fromXPriv(xpriv: string): HDPrivateNode {
|
||||
// Attempt to decode the XPriv Key.
|
||||
const decodeResult = decodeHdPrivateKey(xpriv);
|
||||
|
||||
// If a string is returned, this indicates an error...
|
||||
if (typeof decodeResult === 'string') {
|
||||
throw new Error(decodeResult);
|
||||
}
|
||||
|
||||
// Return a new HD Private Node from the given XPriv.
|
||||
return new HDPrivateNode(decodeResult.node);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a HD Private Node from a raw seed.
|
||||
*
|
||||
* @param seed {Uint8Array} The raw seed bytes.
|
||||
* @param seed The raw seed bytes.
|
||||
*
|
||||
* @throws {Error} If HD Private Node cannot be created.
|
||||
*
|
||||
@@ -83,6 +62,45 @@ export class HDPrivateNode {
|
||||
return new HDPrivateNode(deriveResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a HD Private Node from the given mnemonic.
|
||||
*
|
||||
* @param mnemonic The mnemonic.
|
||||
*
|
||||
* @throws {Error} If HD Private Node cannot be created.
|
||||
*
|
||||
* @returns {HDPrivateNode} The created HD Private Node.
|
||||
*/
|
||||
public static fromMnemonic(mnemonic: string): HDPrivateNode {
|
||||
// Derive the seed from the mnemonic.
|
||||
const seed = deriveSeedFromBip39Mnemonic(mnemonic);
|
||||
|
||||
// Return a new HDPrivateNode from the given seed.
|
||||
return HDPrivateNode.fromSeed(seed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a HD Private Node from the given XPriv Key.
|
||||
*
|
||||
* @param xpriv The XPriv Key.
|
||||
*
|
||||
* @throws {Error} If HD Private Node cannot be created.
|
||||
*
|
||||
* @returns {HDPrivateNode} The created HD Private Node.
|
||||
*/
|
||||
public static fromXPriv(xpriv: string): HDPrivateNode {
|
||||
// Attempt to decode the XPriv Key.
|
||||
const decodeResult = decodeHdPrivateKey(xpriv);
|
||||
|
||||
// If a string is returned, this indicates an error...
|
||||
if (typeof decodeResult === 'string') {
|
||||
throw new Error(decodeResult);
|
||||
}
|
||||
|
||||
// Return a new HD Private Node from the given XPriv.
|
||||
return new HDPrivateNode(decodeResult.node);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a random HD Private Node.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user