if (keypair.privateKey == null) throw new RangeError('Account private key missing')\r
if (keypair.index == null) throw new RangeError('Account keys derived but index missing')\r
const { publicKey, privateKey, index } = keypair\r
- this.#accounts[keypair.index] = Account.fromKeypair(bytes.toHex(publicKey as unknown as Uint8Array), bytes.toHex(privateKey as unknown as Uint8Array), index)\r
+ this.#accounts[keypair.index] = Account.fromKeypair(publicKey, privateKey, index)\r
}\r
console.log(`accounts: ${-now + (now = performance.now())} ms`)\r
}\r
addEventListener('message', (message) => {\r
const data = JSON.parse(new TextDecoder().decode(message.data ?? message))\r
for (const d of data) {\r
- d.publicKey = keyPair(d.privateKey).publicKey\r
+ d.publicKey = hexify(keyPair(d.privateKey).publicKey)\r
}\r
const buf = new TextEncoder().encode(JSON.stringify(data)).buffer\r
//@ts-expect-error\r
return Uint8Array.from(arr)\r
}\r
\r
+ function hexify (buf: Uint8Array) {\r
+ return buf.reduce((curr, next) => {\r
+ if (typeof next !== 'number')\r
+ throw new TypeError(`expected number to convert to hex; received ${typeof next}`)\r
+ if (next < 0 || next > 255)\r
+ throw new RangeError(`expected byte value 0-255; received ${next}`)\r
+ return curr + next.toString(16).padStart(2, '0')\r
+ }, '')\r
+ }\r
+\r
const sign = function (msg: Uint8Array, secretKey: Uint8Array) {\r
checkArrayTypes(msg, secretKey)\r
if (secretKey.length !== crypto_sign_SECRETKEYBYTES)\r