Skip to content

Commit 9a9ef21

Browse files
committed
fix: resolves wevm/viem#3836
1 parent f261274 commit 9a9ef21

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

.changeset/three-humans-bake.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"ox": patch
3+
---
4+
5+
Fixed zeroish conversion of `chainId` and `nonce` in `Authorization.fromTuple`.

src/core/Authorization.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,8 @@ export function fromTuple<const tuple extends Tuple>(
271271
yParity && r && s ? Signature.fromTuple([yParity, r, s]) : undefined
272272
return from({
273273
address,
274-
chainId: Number(chainId),
275-
nonce: BigInt(nonce),
274+
chainId: chainId === '0x' ? 0 : Number(chainId),
275+
nonce: nonce === '0x' ? 0n : BigInt(nonce),
276276
...signature,
277277
}) as never
278278
}

src/core/_test/Authorization.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,22 @@ describe('fromTuple', () => {
214214
`)
215215
})
216216

217+
test('behavior: zeroish nonce + chainId', () => {
218+
const tuple = [
219+
'0x',
220+
'0x0000000000000000000000000000000000000000',
221+
'0x',
222+
] as const satisfies Authorization.Tuple
223+
const authorization = Authorization.fromTuple(tuple)
224+
expect(authorization).toMatchInlineSnapshot(`
225+
{
226+
"address": "0x0000000000000000000000000000000000000000",
227+
"chainId": 0,
228+
"nonce": 0n,
229+
}
230+
`)
231+
})
232+
217233
test('behavior: signature', () => {
218234
const tuple = [
219235
'0x1',

0 commit comments

Comments
 (0)