From a8ec9df7d00aefdaec566f18b96aa8f3898e6c0b Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Tue, 3 Dec 2024 14:36:53 -0800 Subject: [PATCH] Rename function since we are no longer returning a pair of keys. --- src/lib/account.ts | 6 ++++-- src/lib/nano-nacl.ts | 6 +++--- src/lib/wallet.ts | 6 +++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/lib/account.ts b/src/lib/account.ts index f85b2eb..3e4a987 100644 --- a/src/lib/account.ts +++ b/src/lib/account.ts @@ -109,7 +109,7 @@ export class Account { static fromPrivateKey (privateKey: string, index?: number): Account { Account.#isInternal = true Account.#validateKey(privateKey) - const { publicKey } = NanoNaCl.keyPair(hex.toBytes(privateKey)) + const { publicKey } = NanoNaCl.convert(privateKey) const account = Account.fromPublicKey(bytes.toHex(publicKey), index) account.#prv = privateKey.toUpperCase() return account @@ -128,7 +128,9 @@ export class Account { * @param {number} [index] - Account number used when deriving the key * @returns {Account} The instantiated Account object */ - static fromKeypair (publicKey: string, privateKey: string, index?: number): Account { + static fromKeypair (privateKey: string, publicKey: string, index?: number): Account { + console.log(`privateKey: ${privateKey}`) + console.log(`publicKey: ${publicKey}`) Account.#isInternal = true Account.#validateKey(privateKey) const account = Account.fromPublicKey(publicKey, index) diff --git a/src/lib/nano-nacl.ts b/src/lib/nano-nacl.ts index 4679023..9ff8e24 100644 --- a/src/lib/nano-nacl.ts +++ b/src/lib/nano-nacl.ts @@ -24,7 +24,7 @@ const n = () => { addEventListener('message', (message) => { const data = JSON.parse(new TextDecoder().decode(message.data ?? message)) for (const d of data) { - d.publicKey = hexify(keyPair(d.privateKey).publicKey) + d.publicKey = hexify(convert(d.privateKey).publicKey) } const buf = new TextEncoder().encode(JSON.stringify(data)).buffer postMessage(buf, [buf]) @@ -808,7 +808,7 @@ const n = () => { return (crypto_sign_open(m, sm, sm.length, publicKey) >= 0) } - const keyPair = function (seed: string | Uint8Array) { + const convert = function (seed: string | Uint8Array) { if (typeof seed === 'string') seed = parseHex(seed) checkArrayTypes(seed) if (seed.length !== crypto_sign_SEEDBYTES) @@ -828,7 +828,7 @@ const n = () => { return { publicKey: pk } } - return { sign, open, detached, verify, keyPair } + return { sign, open, detached, verify, convert } } export const NanoNaCl = n() diff --git a/src/lib/wallet.ts b/src/lib/wallet.ts index c768e93..d2c888c 100644 --- a/src/lib/wallet.ts +++ b/src/lib/wallet.ts @@ -101,11 +101,11 @@ abstract class Wallet { const keypairs: KeyPair[] = await this.#pool.work('divide', data) console.log(`keypairs: ${-now + (now = performance.now())} ms`) for (const keypair of keypairs) { - if (keypair.publicKey == null) throw new RangeError('Account public key missing') if (keypair.privateKey == null) throw new RangeError('Account private key missing') + if (keypair.publicKey == null) throw new RangeError('Account public key missing') if (keypair.index == null) throw new RangeError('Account keys derived but index missing') - const { publicKey, privateKey, index } = keypair - this.#accounts[keypair.index] = Account.fromKeypair(publicKey, privateKey, index) + const { privateKey, publicKey, index } = keypair + this.#accounts[keypair.index] = Account.fromKeypair(privateKey, publicKey, index) } console.log(`accounts: ${-now + (now = performance.now())} ms`) } -- 2.34.1