import { Blake2b } from './blake2b.js'\r
import { Bip39Mnemonic } from './bip39-mnemonic.js'\r
import { ADDRESS_GAP, SEED_LENGTH_BIP44, SEED_LENGTH_BLAKE2B } from './constants.js'\r
+import { hex } from './convert.js'\r
import { Entropy } from './entropy.js'\r
import { Pool } from './pool.js'\r
import { Rpc } from './rpc.js'\r
let results = await this.ckd(indexes)\r
if (!Array.isArray(results)) results = [results]\r
const data: any = []\r
- results.forEach(r => data.push({ privateKey: r.privateKey, index: r.index }))\r
+ results.forEach(r => data.push({ privateKey: hex.toBytes(r.privateKey as string), index: r.index }))\r
let now = performance.now()\r
const keypairs: [{ publicKey: string, privateKey: string, index: number }] = await this.#pool.work(data)\r
console.log(`accounts: ${-now + (now = performance.now())} ms`)\r
*/\r
addEventListener('message', (message) => {\r
const { privateKey, index } = message.data ?? message\r
- keyPair.fromSeed(seed).then(publicKey => postMessage({ publicKey, privateKey, index }))\r
+ keyPair.fromSeed(privateKey).then(publicKey => postMessage({ publicKey, privateKey, index }))\r
})\r
\r
\r
for (var i = 0; i < arr.length; i++) arr[i] = 0;\r
}\r
\r
-export const sign = function(msg, secretKey) {\r
+const sign = function(msg, secretKey) {\r
checkArrayTypes(msg, secretKey);\r
if (secretKey.length !== crypto_sign_SECRETKEYBYTES)\r
throw new Error('bad secret key size');\r
return signedMsg;\r
};\r
\r
-export const open = function(signedMsg, publicKey) {\r
+const open = function(signedMsg, publicKey) {\r
checkArrayTypes(signedMsg, publicKey);\r
if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)\r
throw new Error('bad public key size');\r
return m;\r
};\r
\r
-export const detached = function(msg, secretKey) {\r
+const detached = function(msg, secretKey) {\r
var signedMsg = sign(msg, secretKey);\r
var sig = new Uint8Array(crypto_sign_BYTES);\r
for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i];\r
return sig;\r
};\r
\r
-export const verify = function(msg, sig, publicKey) {\r
+const verify = function(msg, sig, publicKey) {\r
checkArrayTypes(msg, sig, publicKey);\r
if (sig.length !== crypto_sign_BYTES)\r
throw new Error('bad signature size');\r
return (crypto_sign_open(m, sm, sm.length, publicKey) >= 0);\r
};\r
\r
-export const keyPair = {\r
+const keyPair = {\r
create() {\r
var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);\r
var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);\r
}\r
}\r
\r
-export const publicKeyLength = crypto_sign_PUBLICKEYBYTES;\r
-export const secretKeyLength = crypto_sign_SECRETKEYBYTES;\r
-export const seedLength = crypto_sign_SEEDBYTES;\r
-export const signatureLength = crypto_sign_BYTES;\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
const setPRNG = function(fn) {\r
randombytes = fn;\r
})();\r
}\r
\r
-export const nacl = { sign, open, detached, verify, keyPair, publicKeyLength, secretKeyLength, seedLength, signatureLength }\r
+export const nacl = {\r
+ sign: fn.sign,\r
+ open: fn.open,\r
+ detached: fn.detached,\r
+ verify: fn.verify,\r
+ keyPair: fn.keyPair\r
+}\r
export default `(${fn.toString()})()`\r