static fromPrivateKey (privateKey: string, index?: number): Account {\r
Account.#isInternal = true\r
Account.#validateKey(privateKey)\r
- const { publicKey } = NanoNaCl.keyPair(hex.toBytes(privateKey))\r
+ const { publicKey } = NanoNaCl.convert(privateKey)\r
const account = Account.fromPublicKey(bytes.toHex(publicKey), index)\r
account.#prv = privateKey.toUpperCase()\r
return account\r
* @param {number} [index] - Account number used when deriving the key\r
* @returns {Account} The instantiated Account object\r
*/\r
- static fromKeypair (publicKey: string, privateKey: string, index?: number): Account {\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
addEventListener('message', (message) => {\r
const data = JSON.parse(new TextDecoder().decode(message.data ?? message))\r
for (const d of data) {\r
- d.publicKey = hexify(keyPair(d.privateKey).publicKey)\r
+ d.publicKey = hexify(convert(d.privateKey).publicKey)\r
}\r
const buf = new TextEncoder().encode(JSON.stringify(data)).buffer\r
postMessage(buf, [buf])\r
return (crypto_sign_open(m, sm, sm.length, publicKey) >= 0)\r
}\r
\r
- const keyPair = function (seed: string | Uint8Array) {\r
+ const convert = function (seed: string | Uint8Array) {\r
if (typeof seed === 'string') seed = parseHex(seed)\r
checkArrayTypes(seed)\r
if (seed.length !== crypto_sign_SEEDBYTES)\r
return { publicKey: pk }\r
}\r
\r
- return { sign, open, detached, verify, keyPair }\r
+ return { sign, open, detached, verify, convert }\r
}\r
\r
export const NanoNaCl = n()\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.publicKey == null) throw new RangeError('Account public key missing')\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
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(publicKey, privateKey, index)\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