Skip to content

Commit

Permalink
tests for formats
Browse files Browse the repository at this point in the history
  • Loading branch information
ChALkeR committed Oct 2, 2024
1 parent 8098158 commit 17c86f1
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion features/keychain/module/__tests__/ecdsa.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,32 @@ describe('EcDSA Signer Signature Encoding', () => {
expect(signature.toString('hex')).toBe(expected.binary)
})

it('sig|rec encoding', async () => {
const signature = await keychain.secp256k1.signBuffer({ seedId, keyId, data, enc: 'sig|rec' })
expect(signature instanceof Buffer).toBe(true)
expect(signature.toString('hex')).toBe(expected.binary)
})

it('rec|sig encoding', async () => {
const signature = await keychain.secp256k1.signBuffer({ seedId, keyId, data, enc: 'rec|sig' })
expect(signature instanceof Buffer).toBe(true)
const recsig = expected.binary.slice(128) + expected.binary.slice(0, 128)
expect(signature.toString('hex')).toBe(recsig)
})

it('sig,rec encoding', async () => {
const res = await keychain.secp256k1.signBuffer({ seedId, keyId, data, enc: 'sig,rec' })
expect(typeof res === 'object').toBe(true)
const { signature, recovery } = res
expect(signature instanceof Buffer).toBe(true)
expect(signature.toString('hex')).toBe(expected.binary.slice(0, 128))
expect(recovery === 0 || recovery === 1).toBe(true)
expect(recovery).toBe(Buffer.from(expected.binary, 'hex')[64])
})

it('Raw encoding', async () => {
const signature = await keychain.secp256k1.signBuffer({ seedId, keyId, data, enc: 'raw' })
expect(typeof signature === 'object')
expect(typeof signature === 'object').toBe(true)
expect(Object.getOwnPropertyNames(signature)).toStrictEqual(['r', 's', 'recoveryParam'])
const r = Buffer.from(signature.r.toArray('be', 32))
const s = Buffer.from(signature.s.toArray('be', 32))
Expand Down

0 comments on commit 17c86f1

Please sign in to comment.