Skip to content

Commit

Permalink
feat: add sodium.getKeysFromSeed (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
sparten11740 authored Oct 17, 2024
1 parent ae0b1d0 commit 96496f2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion features/keychain/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
22 changes: 13 additions & 9 deletions features/keychain/module/crypto/sodium.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down

0 comments on commit 96496f2

Please sign in to comment.