Skip to content

Commit

Permalink
feat: favor v in Signature.toHex (#35)
Browse files Browse the repository at this point in the history
* BREAKING CHANGE: Use v when converting signatures to hex format

* changeset

* Update blue-flowers-applaud.md

---------

Co-authored-by: jxom <[email protected]>
  • Loading branch information
gregfromstl and jxom authored Dec 1, 2024
1 parent 15f9863 commit 4680b06
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/blue-flowers-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ox": minor
---

Updated `Signature.toHex` to serialize the last byte as `v` instead of `yParity` for widened compatibility.
2 changes: 1 addition & 1 deletion src/core/Signature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ export function toHex(signature: Signature<boolean>): Hex.Hex {
Hex.fromNumber(s, { size: 32 }),
// If the signature is recovered, add the recovery byte to the signature.
typeof signature.yParity === 'number'
? Hex.fromNumber(signature.yParity, { size: 1 })
? Hex.fromNumber(yParityToV(signature.yParity), { size: 1 })
: '0x',
)

Expand Down
6 changes: 3 additions & 3 deletions src/core/_test/Signature.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ describe('serialize', () => {
yParity: 1,
}),
).toMatchInlineSnapshot(
`"0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db801"`,
`"0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db81c"`,
)

expect(
Expand All @@ -454,7 +454,7 @@ describe('serialize', () => {
yParity: 0,
}),
).toMatchInlineSnapshot(
`"0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db800"`,
`"0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db81b"`,
)

expect(
Expand Down Expand Up @@ -543,7 +543,7 @@ describe('toBytes', () => {
215,
109,
184,
1,
28,
]
`,
)
Expand Down

0 comments on commit 4680b06

Please sign in to comment.