]> zoso.dev Git - libnemo.git/commitdiff
Rename function since we are no longer returning a pair of keys.
authorChris Duncan <chris@zoso.dev>
Tue, 3 Dec 2024 22:36:53 +0000 (14:36 -0800)
committerChris Duncan <chris@zoso.dev>
Tue, 3 Dec 2024 22:36:53 +0000 (14:36 -0800)
src/lib/account.ts
src/lib/nano-nacl.ts
src/lib/wallet.ts

index f85b2ebd5e049dab5d6be84124020c60d97a76f1..3e4a9878d6f05326b5894532662e6f94889f3b08 100644 (file)
@@ -109,7 +109,7 @@ export class Account {
        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
@@ -128,7 +128,9 @@ export class Account {
        * @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
index 4679023c80368c804933d9dc97cc7197a7a9e2f6..9ff8e241ef49e46221dba9080265d9323604dab1 100644 (file)
@@ -24,7 +24,7 @@ const n = () => {
        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
@@ -808,7 +808,7 @@ const n = () => {
                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
@@ -828,7 +828,7 @@ const n = () => {
                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
index c768e937feba807939053c3a6992ad27c63130be..d2c888c9afbb041c30373d91ff84e07e46b7c8b8 100644 (file)
@@ -101,11 +101,11 @@ abstract class Wallet {
                        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