From 4680b06d4715b1b62d903f45490d325506a1e959 Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 1 Dec 2024 14:57:30 +0000 Subject: [PATCH] feat: favor `v` in `Signature.toHex` (#35) * BREAKING CHANGE: Use v when converting signatures to hex format * changeset * Update blue-flowers-applaud.md --------- Co-authored-by: jxom <7336481+jxom@users.noreply.github.com> --- .changeset/blue-flowers-applaud.md | 5 +++++ src/core/Signature.ts | 2 +- src/core/_test/Signature.test.ts | 6 +++--- 3 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 .changeset/blue-flowers-applaud.md diff --git a/.changeset/blue-flowers-applaud.md b/.changeset/blue-flowers-applaud.md new file mode 100644 index 00000000..5ee17e4e --- /dev/null +++ b/.changeset/blue-flowers-applaud.md @@ -0,0 +1,5 @@ +--- +"ox": minor +--- + +Updated `Signature.toHex` to serialize the last byte as `v` instead of `yParity` for widened compatibility. diff --git a/src/core/Signature.ts b/src/core/Signature.ts index 40f4113b..3995b295 100644 --- a/src/core/Signature.ts +++ b/src/core/Signature.ts @@ -527,7 +527,7 @@ export function toHex(signature: Signature): 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', ) diff --git a/src/core/_test/Signature.test.ts b/src/core/_test/Signature.test.ts index 38a3b222..60b4ccb0 100644 --- a/src/core/_test/Signature.test.ts +++ b/src/core/_test/Signature.test.ts @@ -444,7 +444,7 @@ describe('serialize', () => { yParity: 1, }), ).toMatchInlineSnapshot( - `"0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db801"`, + `"0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db81c"`, ) expect( @@ -454,7 +454,7 @@ describe('serialize', () => { yParity: 0, }), ).toMatchInlineSnapshot( - `"0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db800"`, + `"0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db81b"`, ) expect( @@ -543,7 +543,7 @@ describe('toBytes', () => { 215, 109, 184, - 1, + 28, ] `, )