]> zoso.dev Git - libnemo.git/commitdiff
We are only ever using this to get public keys if interacting with keys are all,...
authorChris Duncan <chris@zoso.dev>
Sat, 30 Nov 2024 08:15:17 +0000 (00:15 -0800)
committerChris Duncan <chris@zoso.dev>
Sat, 30 Nov 2024 08:15:17 +0000 (00:15 -0800)
src/lib/account.ts
src/lib/workers/nano-nacl.ts

index f083e7fd49ad80cd1828086a1ac84fdb97afdc3d..8d12132dfdff4f4abefcffaafff9deb0a9d3356a 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 } = nacl.keyPair.fromSeed(hex.toBytes(privateKey))\r
+               const { publicKey } = nacl.keyPair(hex.toBytes(privateKey))\r
                const account = Account.fromPublicKey(bytes.toHex(publicKey), index)\r
                account.#prv = privateKey.toUpperCase()\r
                return account\r
index d63cef402582415790b63575aba20286fb05d7e6..d2c5d98ac89c37e0152e10549a1e4a7f14d1c168 100644 (file)
@@ -21,7 +21,7 @@ const NanoNaCl = () => {
        */\r
        addEventListener('message', (message) => {\r
                const { privateKey, index } = message.data ?? message\r
-               const { publicKey } = keyPair.fromSeed(privateKey)\r
+               const { publicKey } = keyPair(privateKey)\r
                postMessage({ publicKey, privateKey, index })\r
        })\r
 \r
@@ -596,21 +596,11 @@ const NanoNaCl = () => {
                scalarmult(p, q, s)\r
        }\r
 \r
-       function crypto_sign_keypair (pk: Uint8Array, sk: Uint8Array, seeded?: boolean) {\r
+       function crypto_sign_keypair (pk: Uint8Array, sk: Uint8Array) {\r
                var d = new Uint8Array(64)\r
                var p = [gf(), gf(), gf(), gf()]\r
                var i\r
 \r
-               if (!seeded) {\r
-                       var QUOTA = 65536       // https://w3c.github.io/webcrypto/#Crypto-method-getRandomValues\r
-                       var i, n = 32, v = new Uint8Array(n)\r
-                       for (i = 0; i < n; i += QUOTA) {\r
-                               crypto.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA)))\r
-                       }\r
-                       for (i = 0; i < n; i++) sk[i] = v[i]\r
-                       cleanup(v)\r
-               }\r
-\r
                crypto_hash(d, sk, 32)\r
                d[0] &= 248\r
                d[31] &= 127\r
@@ -821,40 +811,17 @@ const NanoNaCl = () => {
                return (crypto_sign_open(m, sm, sm.length, publicKey) >= 0)\r
        }\r
 \r
-       const keyPair = {\r
-               create () {\r
-                       var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES)\r
-                       var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES)\r
-                       crypto_sign_keypair(pk, sk)\r
-                       return { publicKey: pk, secretKey: sk }\r
-               },\r
-\r
-               fromSecretKey (secretKey: Uint8Array) {\r
-                       checkArrayTypes(secretKey)\r
-                       if (secretKey.length !== crypto_sign_SECRETKEYBYTES)\r
-                               throw new Error('bad secret key size')\r
-                       var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES)\r
-                       for (var i = 0; i < pk.length; i++) pk[i] = secretKey[32 + i]\r
-                       return { publicKey: pk, secretKey: new Uint8Array(secretKey) }\r
-               },\r
-\r
-               fromSeed (seed: Uint8Array) {\r
-                       checkArrayTypes(seed)\r
-                       if (seed.length !== crypto_sign_SEEDBYTES)\r
-                               throw new Error('bad seed size')\r
-                       var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES)\r
-                       var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES)\r
-                       for (var i = 0; i < 32; i++) sk[i] = seed[i]\r
-                       crypto_sign_keypair(pk, sk, true)\r
-                       return { publicKey: pk, secretKey: sk }\r
-               }\r
+       const keyPair = function (seed: Uint8Array) {\r
+               checkArrayTypes(seed)\r
+               if (seed.length !== crypto_sign_SEEDBYTES)\r
+                       throw new Error('bad seed size')\r
+               var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES)\r
+               var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES)\r
+               for (var i = 0; i < 32; i++) sk[i] = seed[i]\r
+               crypto_sign_keypair(pk, sk)\r
+               return { publicKey: pk, secretKey: sk }\r
        }\r
 \r
-       const publicKeyLength = crypto_sign_PUBLICKEYBYTES\r
-       const secretKeyLength = crypto_sign_SECRETKEYBYTES\r
-       const seedLength = crypto_sign_SEEDBYTES\r
-       const signatureLength = crypto_sign_BYTES\r
-\r
        return { sign, open, detached, verify, keyPair }\r
 }\r
 \r