*/\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
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
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