From a9407d840244f579059d89d00c4e235a60978a5a Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Tue, 3 Dec 2024 16:06:09 -0800 Subject: [PATCH] Remove performance logging and test logging. Add typings to NanoNaCl. --- src/lib/account.ts | 2 -- src/lib/nano-nacl.ts | 24 +++++++++++++----------- src/lib/wallet.ts | 7 ------- 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/lib/account.ts b/src/lib/account.ts index f9d7d1d..3e3d932 100644 --- a/src/lib/account.ts +++ b/src/lib/account.ts @@ -129,8 +129,6 @@ export class Account { * @returns {Account} The instantiated Account object */ 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 e9e9638..2a07669 100644 --- a/src/lib/nano-nacl.ts +++ b/src/lib/nano-nacl.ts @@ -1,6 +1,6 @@ // SPDX-FileCopyrightText: 2024 Chris Duncan // SPDX-License-Identifier: GPL-3.0-or-later - +//@ts-nocheck 'use strict' import { Blake2b } from './blake2b.js' @@ -59,7 +59,7 @@ const n = () => { for (let i = 0; i < 16; i++) r[i] = a[i] | 0 } - function car25519 (o): void { + function car25519 (o: Float64Array): void { let v, c = 1 for (let i = 0; i < 16; i++) { v = o[i] + c + 65535 @@ -70,8 +70,9 @@ const n = () => { } function sel25519 (p, q, b): void { - var t, c = ~(b - 1) - for (var i = 0; i < 16; i++) { + let t + const c = ~(b - 1) + for (let i = 0; i < 16; i++) { t = c & (p[i] ^ q[i]) p[i] ^= t q[i] ^= t @@ -79,15 +80,16 @@ const n = () => { } function pack25519 (o, n): void { - var i, j, b - var m = gf(), t = gf() - for (i = 0; i < 16; i++) t[i] = n[i] + let b: number + const m: Float64Array = gf() + const t: Float64Array = gf() + for (let i = 0; i < 16; i++) t[i] = n[i] car25519(t) car25519(t) car25519(t) - for (j = 0; j < 2; j++) { + for (let j = 0; j < 2; j++) { m[0] = t[0] - 0xffed - for (i = 1; i < 15; i++) { + for (let i = 1; i < 15; i++) { m[i] = t[i] - 0xffff - ((m[i - 1] >> 16) & 1) m[i - 1] &= 0xffff } @@ -96,7 +98,7 @@ const n = () => { m[14] &= 0xffff sel25519(t, m, 1 - b) } - for (i = 0; i < 16; i++) { + for (let i = 0; i < 16; i++) { o[2 * i] = t[i] & 0xff o[2 * i + 1] = t[i] >> 8 } @@ -831,7 +833,7 @@ const n = () => { scalarbase(p, hash) pack(pk, p) - return hexify(pk) + return hexify(pk).toUpperCase() } return { sign, open, detached, verify, convert } diff --git a/src/lib/wallet.ts b/src/lib/wallet.ts index d2c888c..142f2b9 100644 --- a/src/lib/wallet.ts +++ b/src/lib/wallet.ts @@ -97,9 +97,7 @@ abstract class Wallet { let results = await this.ckd(indexes) const data: any = [] results.forEach(r => data.push({ privateKey: r.privateKey, index: r.index })) - let now = performance.now() const keypairs: KeyPair[] = await this.#pool.work('divide', data) - console.log(`keypairs: ${-now + (now = performance.now())} ms`) for (const keypair of keypairs) { if (keypair.privateKey == null) throw new RangeError('Account private key missing') if (keypair.publicKey == null) throw new RangeError('Account public key missing') @@ -107,7 +105,6 @@ abstract class Wallet { const { privateKey, publicKey, index } = keypair this.#accounts[keypair.index] = Account.fromKeypair(privateKey, publicKey, index) } - console.log(`accounts: ${-now + (now = performance.now())} ms`) } return this.#accounts.slice(from, to + 1) } @@ -430,9 +427,7 @@ export class Bip44Wallet extends Wallet { async ckd (indexes: number[]): Promise { const data: any = [] indexes.forEach(i => data.push({ seed: this.seed, index: i })) - let now = performance.now() const privateKeys: KeyPair[] = await this.#pool.work('divide', data) - console.log(`ckd: ${-now + (now = performance.now())} ms`) return privateKeys } } @@ -574,7 +569,6 @@ export class Blake2bWallet extends Wallet { * @returns {Promise} */ async ckd (indexes: number[]): Promise { - let now = performance.now() const results = indexes.map(index => { const indexHex = index.toString(16).padStart(8, '0').toUpperCase() const inputHex = `${this.seed}${indexHex}`.padStart(72, '0') @@ -583,7 +577,6 @@ export class Blake2bWallet extends Wallet { const privateKey: string = new Blake2b(32).update(inputBytes).digest('hex') return { privateKey, index } }) - console.log(`ckd: ${-now + (now = performance.now())} ms`) return results } } -- 2.34.1