From 8919750d01a000c37321beef6ad37af0f8e0c3a6 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Sun, 24 Nov 2024 21:49:37 -0800 Subject: [PATCH] Attach export keyword directly to applicable functions and adjust property chain to reflect simplified API. --- src/lib/account.ts | 2 +- src/lib/tools.ts | 4 ++-- src/lib/workers/nano25519.ts | 24 +++++++++++------------- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/lib/account.ts b/src/lib/account.ts index a98a5be..ffc2f38 100644 --- a/src/lib/account.ts +++ b/src/lib/account.ts @@ -87,7 +87,7 @@ export class Account { */ static async fromPrivateKey (key: string, index?: number): Promise { Account.#validateKey(key) - const { publicKey } = Ed25519.sign.keyPair.fromSeed(hex.toBytes(key)) + const { publicKey } = Ed25519.keyPair.fromSeed(hex.toBytes(key)) const account = await Account.fromPublicKey(bytes.toHex(publicKey), index) account.#prv = key.toUpperCase() return account diff --git a/src/lib/tools.ts b/src/lib/tools.ts index c6bdbe2..510eb11 100644 --- a/src/lib/tools.ts +++ b/src/lib/tools.ts @@ -160,8 +160,8 @@ export async function verify (key: string, signature: string, ...input: string[] const data = await hash(input) return Ed25519.verify( hex.toBytes(data), - hex.toBytes(key), - hex.toBytes(signature)) + hex.toBytes(signature), + hex.toBytes(key)) } export default { convert, hash, sign, sweep, verify } diff --git a/src/lib/workers/nano25519.ts b/src/lib/workers/nano25519.ts index 37dbcb9..aa6aa91 100644 --- a/src/lib/workers/nano25519.ts +++ b/src/lib/workers/nano25519.ts @@ -2182,7 +2182,7 @@ import blake2b from 'blake2b' for (var i = 0; i < arr.length; i++) arr[i] = 0; } - const sign = function(msg, secretKey) { + export const sign = function(msg, secretKey) { checkArrayTypes(msg, secretKey); if (secretKey.length !== crypto_sign_SECRETKEYBYTES) throw new Error('bad secret key size'); @@ -2191,7 +2191,7 @@ import blake2b from 'blake2b' return signedMsg; }; - sign.open = function(signedMsg, publicKey) { + export const open = function(signedMsg, publicKey) { checkArrayTypes(signedMsg, publicKey); if (publicKey.length !== crypto_sign_PUBLICKEYBYTES) throw new Error('bad public key size'); @@ -2203,14 +2203,14 @@ import blake2b from 'blake2b' return m; }; - sign.detached = function(msg, secretKey) { + export const detached = function(msg, secretKey) { var signedMsg = sign(msg, secretKey); var sig = new Uint8Array(crypto_sign_BYTES); for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i]; return sig; }; - sign.detached.verify = function(msg, sig, publicKey) { + export const verify = function(msg, sig, publicKey) { checkArrayTypes(msg, sig, publicKey); if (sig.length !== crypto_sign_BYTES) throw new Error('bad signature size'); @@ -2224,14 +2224,14 @@ import blake2b from 'blake2b' return (crypto_sign_open(m, sm, sm.length, publicKey) >= 0); }; - sign.keyPair = function() { + export const keyPair = function() { var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES); var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES); crypto_sign_keypair(pk, sk); return {publicKey: pk, secretKey: sk}; }; - sign.keyPair.fromSecretKey = function(secretKey) { + keyPair.fromSecretKey = function(secretKey) { checkArrayTypes(secretKey); if (secretKey.length !== crypto_sign_SECRETKEYBYTES) throw new Error('bad secret key size'); @@ -2240,7 +2240,7 @@ import blake2b from 'blake2b' return {publicKey: pk, secretKey: new Uint8Array(secretKey)}; }; - sign.keyPair.fromSeed = function(seed) { + keyPair.fromSeed = function(seed) { checkArrayTypes(seed); if (seed.length !== crypto_sign_SEEDBYTES) throw new Error('bad seed size'); @@ -2251,10 +2251,10 @@ import blake2b from 'blake2b' return {publicKey: pk, secretKey: sk}; }; - sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES; - sign.secretKeyLength = crypto_sign_SECRETKEYBYTES; - sign.seedLength = crypto_sign_SEEDBYTES; - sign.signatureLength = crypto_sign_BYTES; + export const publicKeyLength = crypto_sign_PUBLICKEYBYTES; + export const secretKeyLength = crypto_sign_SECRETKEYBYTES; + export const seedLength = crypto_sign_SEEDBYTES; + export const signatureLength = crypto_sign_BYTES; const setPRNG = function(fn) { randombytes = fn; @@ -2287,5 +2287,3 @@ import blake2b from 'blake2b' } } })(); - - export { sign } -- 2.34.1