From 67f201e6ad247cce948c7315a353864c732b90c1 Mon Sep 17 00:00:00 2001 From: Nicholas Dudfield Date: Tue, 8 Aug 2023 12:31:19 +0700 Subject: [PATCH] fix: s/validateNode/validateKey/ and fix --- packages/xrpl/src/Wallet/index.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/xrpl/src/Wallet/index.ts b/packages/xrpl/src/Wallet/index.ts index 9743edfaa4..b63d8d3da7 100644 --- a/packages/xrpl/src/Wallet/index.ts +++ b/packages/xrpl/src/Wallet/index.ts @@ -35,12 +35,17 @@ import { rfc1751MnemonicToKey } from './rfc1751' const DEFAULT_ALGORITHM: ECDSA = ECDSA.ed25519 const DEFAULT_DERIVATION_PATH = "m/44'/144'/0'/0/0" -function validateNode(node: HDKey): void { - if (node.privateKey === null) { +type ValidHDKey = HDKey & { + privateKey: Uint8Array + publicKey: Uint8Array +} + +function validateKey(node: HDKey): asserts node is ValidHDKey { + if (!(node.privateKey instanceof Uint8Array)) { throw new ValidationError('Unable to derive privateKey from mnemonic input') } - if (node.publicKey === null) { + if (!(node.publicKey instanceof Uint8Array)) { throw new ValidationError('Unable to derive publicKey from mnemonic input') } } @@ -251,7 +256,7 @@ export class Wallet { const node = masterNode.derive( opts.derivationPath ?? DEFAULT_DERIVATION_PATH, ) - validateNode(node) + validateKey(node) const publicKey = bytesToHex(node.publicKey) const privateKey = bytesToHex(node.privateKey)