* @returns {Account} The instantiated Account object\r
*/\r
static fromKeypair (privateKey: string, publicKey: string, index?: number): Account {\r
- console.log(`privateKey: ${privateKey}`)\r
- console.log(`publicKey: ${publicKey}`)\r
Account.#isInternal = true\r
Account.#validateKey(privateKey)\r
const account = Account.fromPublicKey(publicKey, index)\r
// SPDX-FileCopyrightText: 2024 Chris Duncan <chris@zoso.dev>\r
// SPDX-License-Identifier: GPL-3.0-or-later\r
-\r
+//@ts-nocheck\r
'use strict'\r
\r
import { Blake2b } from './blake2b.js'\r
for (let i = 0; i < 16; i++) r[i] = a[i] | 0\r
}\r
\r
- function car25519 (o): void {\r
+ function car25519 (o: Float64Array): void {\r
let v, c = 1\r
for (let i = 0; i < 16; i++) {\r
v = o[i] + c + 65535\r
}\r
\r
function sel25519 (p, q, b): void {\r
- var t, c = ~(b - 1)\r
- for (var i = 0; i < 16; i++) {\r
+ let t\r
+ const c = ~(b - 1)\r
+ for (let i = 0; i < 16; i++) {\r
t = c & (p[i] ^ q[i])\r
p[i] ^= t\r
q[i] ^= t\r
}\r
\r
function pack25519 (o, n): void {\r
- var i, j, b\r
- var m = gf(), t = gf()\r
- for (i = 0; i < 16; i++) t[i] = n[i]\r
+ let b: number\r
+ const m: Float64Array = gf()\r
+ const t: Float64Array = gf()\r
+ for (let i = 0; i < 16; i++) t[i] = n[i]\r
car25519(t)\r
car25519(t)\r
car25519(t)\r
- for (j = 0; j < 2; j++) {\r
+ for (let j = 0; j < 2; j++) {\r
m[0] = t[0] - 0xffed\r
- for (i = 1; i < 15; i++) {\r
+ for (let i = 1; i < 15; i++) {\r
m[i] = t[i] - 0xffff - ((m[i - 1] >> 16) & 1)\r
m[i - 1] &= 0xffff\r
}\r
m[14] &= 0xffff\r
sel25519(t, m, 1 - b)\r
}\r
- for (i = 0; i < 16; i++) {\r
+ for (let i = 0; i < 16; i++) {\r
o[2 * i] = t[i] & 0xff\r
o[2 * i + 1] = t[i] >> 8\r
}\r
scalarbase(p, hash)\r
pack(pk, p)\r
\r
- return hexify(pk)\r
+ return hexify(pk).toUpperCase()\r
}\r
\r
return { sign, open, detached, verify, convert }\r
let results = await this.ckd(indexes)\r
const data: any = []\r
results.forEach(r => data.push({ privateKey: r.privateKey, index: r.index }))\r
- let now = performance.now()\r
const keypairs: KeyPair[] = await this.#pool.work('divide', data)\r
- console.log(`keypairs: ${-now + (now = performance.now())} ms`)\r
for (const keypair of keypairs) {\r
if (keypair.privateKey == null) throw new RangeError('Account private key missing')\r
if (keypair.publicKey == null) throw new RangeError('Account public key missing')\r
const { privateKey, publicKey, index } = keypair\r
this.#accounts[keypair.index] = Account.fromKeypair(privateKey, publicKey, index)\r
}\r
- console.log(`accounts: ${-now + (now = performance.now())} ms`)\r
}\r
return this.#accounts.slice(from, to + 1)\r
}\r
async ckd (indexes: number[]): Promise<KeyPair[]> {\r
const data: any = []\r
indexes.forEach(i => data.push({ seed: this.seed, index: i }))\r
- let now = performance.now()\r
const privateKeys: KeyPair[] = await this.#pool.work('divide', data)\r
- console.log(`ckd: ${-now + (now = performance.now())} ms`)\r
return privateKeys\r
}\r
}\r
* @returns {Promise<Account>}\r
*/\r
async ckd (indexes: number[]): Promise<KeyPair[]> {\r
- let now = performance.now()\r
const results = indexes.map(index => {\r
const indexHex = index.toString(16).padStart(8, '0').toUpperCase()\r
const inputHex = `${this.seed}${indexHex}`.padStart(72, '0')\r
const privateKey: string = new Blake2b(32).update(inputBytes).digest('hex')\r
return { privateKey, index }\r
})\r
- console.log(`ckd: ${-now + (now = performance.now())} ms`)\r
return results\r
}\r
}\r