Skip to content

Commit

Permalink
refactor: rename arg to enc
Browse files Browse the repository at this point in the history
  • Loading branch information
feri42 committed Feb 29, 2024
1 parent be1cc80 commit d7cae80
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion features/keychain/module/__tests__/ethsign.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('ETH Signer', () => {
const sig = await secp256k1Signer.signBuffer({
data: buffer,
ecOptions: { canonical: true },
rawSignature: true,
enc: 'raw',
})
const signature = new Uint8Array(64)
signature.set(sig.r.toArrayLike(Uint8Array, 'be', 32), 0)
Expand Down
6 changes: 4 additions & 2 deletions features/keychain/module/crypto/secp256k1.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import assert from 'minimalistic-assert'
import elliptic from '@exodus/elliptic'
import { mapValues } from '@exodus/basic-utils'

Expand All @@ -6,10 +7,11 @@ export const create = ({ getPrivateHDKey }) => {
const curve = new EC('secp256k1')

const createInstance = () => ({
signBuffer: async ({ seedId, keyId, data, ecOptions, rawSignature }) => {
signBuffer: async ({ seedId, keyId, data, ecOptions, enc = 'der' }) => {
assert(['der', 'raw'].includes(enc), 'signBuffer: invalid enc')
const { privateKey } = getPrivateHDKey({ seedId, keyId })
const signature = curve.sign(data, privateKey, ecOptions)
return rawSignature ? { ...signature } : Buffer.from(signature.toDER())
return enc === 'der' ? Buffer.from(signature.toDER()) : { ...signature }
},
})

Expand Down

0 comments on commit d7cae80

Please sign in to comment.