From 96496f2b4cb693f05c888137c2d1220c4a49e201 Mon Sep 17 00:00:00 2001 From: Jan W Date: Thu, 17 Oct 2024 17:37:48 +0200 Subject: [PATCH] feat: add `sodium.getKeysFromSeed` (#160) --- features/keychain/api/index.js | 2 +- features/keychain/module/crypto/sodium.js | 22 +++++++++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/features/keychain/api/index.js b/features/keychain/api/index.js index 8bf529ea..30ee3ad6 100644 --- a/features/keychain/api/index.js +++ b/features/keychain/api/index.js @@ -8,7 +8,7 @@ const createKeychainApi = ({ keychain }) => { encryptSecretBox: keychain.sodium.encryptSecretBox, decryptSecretBox: keychain.sodium.decryptSecretBox, getKeysFromSeed: (...args) => - keychain.sodium.getSodiumKeysFromSeed(...args).then(({ box, sign }) => ({ box, sign })), + keychain.sodium.getKeysFromSeed(...args).then(({ box, sign }) => ({ box, sign })), }, ed25519: { signBuffer: keychain.ed25519.signBuffer, diff --git a/features/keychain/module/crypto/sodium.js b/features/keychain/module/crypto/sodium.js index f8716c8b..374687bf 100644 --- a/features/keychain/module/crypto/sodium.js +++ b/features/keychain/module/crypto/sodium.js @@ -23,16 +23,20 @@ export const create = ({ getPrivateHDKey }) => { return sodium.getSodiumKeysFromSeed(sodiumSeed) } - const createInstance = () => ({ - getSodiumKeysFromSeed: async ({ seedId, keyId, exportPrivate }) => { - const { box, sign, secret } = await getSodiumKeysFromIdentifier({ seedId, keyId }) + const getKeysFromSeed = async ({ seedId, keyId, exportPrivate }) => { + const { box, sign, secret } = await getSodiumKeysFromIdentifier({ seedId, keyId }) - return { - box: cloneKeypair({ keys: box, exportPrivate }), - sign: cloneKeypair({ keys: sign, exportPrivate }), - secret: exportPrivate ? cloneBuffer(secret) : null, - } - }, + return { + box: cloneKeypair({ keys: box, exportPrivate }), + sign: cloneKeypair({ keys: sign, exportPrivate }), + secret: exportPrivate ? cloneBuffer(secret) : null, + } + } + + const createInstance = () => ({ + getKeysFromSeed, + /** @deprecated use getKeysFromSeed instead */ + getSodiumKeysFromSeed: getKeysFromSeed, sign: async ({ seedId, keyId, data }) => { const { sign } = await getSodiumKeysFromIdentifier({ seedId, keyId }) return sodium.sign({ message: data, privateKey: sign.privateKey })