ox 0.14.63 → 0.14.65

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/_cjs/core/AbiError.js +6 -2
  3. package/_cjs/core/AbiError.js.map +1 -1
  4. package/_cjs/core/AbiEvent.js +4 -0
  5. package/_cjs/core/AbiEvent.js.map +1 -1
  6. package/_cjs/core/AbiFunction.js +2 -2
  7. package/_cjs/core/AbiFunction.js.map +1 -1
  8. package/_cjs/core/AbiItem.js +6 -7
  9. package/_cjs/core/AbiItem.js.map +1 -1
  10. package/_cjs/core/Base32.js +15 -1
  11. package/_cjs/core/Base32.js.map +1 -1
  12. package/_cjs/core/Bytes.js +4 -5
  13. package/_cjs/core/Bytes.js.map +1 -1
  14. package/_cjs/core/Cbor.js +13 -2
  15. package/_cjs/core/Cbor.js.map +1 -1
  16. package/_cjs/core/Hex.js +2 -3
  17. package/_cjs/core/Hex.js.map +1 -1
  18. package/_cjs/core/Rlp.js +49 -8
  19. package/_cjs/core/Rlp.js.map +1 -1
  20. package/_cjs/core/RpcTransport.js +9 -4
  21. package/_cjs/core/RpcTransport.js.map +1 -1
  22. package/_cjs/core/Siwe.js +4 -0
  23. package/_cjs/core/Siwe.js.map +1 -1
  24. package/_cjs/core/TypedData.js +2 -2
  25. package/_cjs/core/TypedData.js.map +1 -1
  26. package/_cjs/core/internal/abiItem.js +1 -1
  27. package/_cjs/core/internal/abiItem.js.map +1 -1
  28. package/_cjs/erc4337/UserOperation.js +7 -4
  29. package/_cjs/erc4337/UserOperation.js.map +1 -1
  30. package/_cjs/erc8021/Attribution.js +13 -3
  31. package/_cjs/erc8021/Attribution.js.map +1 -1
  32. package/_cjs/tempo/SignaturePreAuthorized.js +177 -0
  33. package/_cjs/tempo/SignaturePreAuthorized.js.map +1 -0
  34. package/_cjs/tempo/Tick.js +3 -2
  35. package/_cjs/tempo/Tick.js.map +1 -1
  36. package/_cjs/tempo/index.js +2 -1
  37. package/_cjs/tempo/index.js.map +1 -1
  38. package/_cjs/version.js +1 -1
  39. package/_esm/core/AbiError.js +6 -2
  40. package/_esm/core/AbiError.js.map +1 -1
  41. package/_esm/core/AbiEvent.js +5 -0
  42. package/_esm/core/AbiEvent.js.map +1 -1
  43. package/_esm/core/AbiFunction.js +2 -2
  44. package/_esm/core/AbiFunction.js.map +1 -1
  45. package/_esm/core/AbiItem.js +8 -7
  46. package/_esm/core/AbiItem.js.map +1 -1
  47. package/_esm/core/Base32.js +17 -2
  48. package/_esm/core/Base32.js.map +1 -1
  49. package/_esm/core/Bytes.js +4 -5
  50. package/_esm/core/Bytes.js.map +1 -1
  51. package/_esm/core/Cbor.js +16 -2
  52. package/_esm/core/Cbor.js.map +1 -1
  53. package/_esm/core/Hex.js +3 -3
  54. package/_esm/core/Hex.js.map +1 -1
  55. package/_esm/core/Rlp.js +56 -8
  56. package/_esm/core/Rlp.js.map +1 -1
  57. package/_esm/core/RpcTransport.js +12 -4
  58. package/_esm/core/RpcTransport.js.map +1 -1
  59. package/_esm/core/Siwe.js +5 -0
  60. package/_esm/core/Siwe.js.map +1 -1
  61. package/_esm/core/TypedData.js +7 -6
  62. package/_esm/core/TypedData.js.map +1 -1
  63. package/_esm/core/internal/abiItem.js +2 -1
  64. package/_esm/core/internal/abiItem.js.map +1 -1
  65. package/_esm/erc4337/UserOperation.js +10 -4
  66. package/_esm/erc4337/UserOperation.js.map +1 -1
  67. package/_esm/erc8021/Attribution.js +15 -3
  68. package/_esm/erc8021/Attribution.js.map +1 -1
  69. package/_esm/tempo/SignaturePreAuthorized.js +314 -0
  70. package/_esm/tempo/SignaturePreAuthorized.js.map +1 -0
  71. package/_esm/tempo/Tick.js +4 -3
  72. package/_esm/tempo/Tick.js.map +1 -1
  73. package/_esm/tempo/index.js +8 -0
  74. package/_esm/tempo/index.js.map +1 -1
  75. package/_esm/version.js +1 -1
  76. package/_types/core/AbiError.d.ts +2 -2
  77. package/_types/core/AbiError.d.ts.map +1 -1
  78. package/_types/core/AbiEvent.d.ts.map +1 -1
  79. package/_types/core/AbiFunction.d.ts +1 -1
  80. package/_types/core/AbiFunction.d.ts.map +1 -1
  81. package/_types/core/AbiItem.d.ts.map +1 -1
  82. package/_types/core/Base32.d.ts +8 -3
  83. package/_types/core/Base32.d.ts.map +1 -1
  84. package/_types/core/Bytes.d.ts.map +1 -1
  85. package/_types/core/Cbor.d.ts.map +1 -1
  86. package/_types/core/Hex.d.ts.map +1 -1
  87. package/_types/core/Rlp.d.ts +9 -2
  88. package/_types/core/Rlp.d.ts.map +1 -1
  89. package/_types/core/RpcTransport.d.ts.map +1 -1
  90. package/_types/core/Siwe.d.ts.map +1 -1
  91. package/_types/core/internal/abiItem.d.ts +3 -1
  92. package/_types/core/internal/abiItem.d.ts.map +1 -1
  93. package/_types/erc4337/UserOperation.d.ts +20 -2
  94. package/_types/erc4337/UserOperation.d.ts.map +1 -1
  95. package/_types/erc8021/Attribution.d.ts.map +1 -1
  96. package/_types/package.json +1 -0
  97. package/_types/tempo/SignatureEnvelope.d.ts +4 -4
  98. package/_types/tempo/SignaturePreAuthorized.d.ts +192 -0
  99. package/_types/tempo/SignaturePreAuthorized.d.ts.map +1 -0
  100. package/_types/tempo/Tick.d.ts.map +1 -1
  101. package/_types/tempo/index.d.ts +8 -0
  102. package/_types/tempo/index.d.ts.map +1 -1
  103. package/_types/version.d.ts +1 -1
  104. package/core/AbiError.ts +33 -22
  105. package/core/AbiEvent.ts +7 -0
  106. package/core/AbiFunction.ts +7 -5
  107. package/core/AbiItem.ts +8 -7
  108. package/core/Base32.ts +17 -3
  109. package/core/Bytes.ts +3 -5
  110. package/core/Cbor.ts +20 -2
  111. package/core/Hex.ts +4 -4
  112. package/core/Rlp.ts +55 -5
  113. package/core/RpcTransport.ts +12 -4
  114. package/core/Siwe.ts +5 -0
  115. package/core/TypedData.ts +7 -6
  116. package/core/internal/abiItem.ts +13 -2
  117. package/erc4337/UserOperation.ts +37 -3
  118. package/erc8021/Attribution.ts +11 -7
  119. package/package.json +11 -1
  120. package/tempo/AccountSimulation.test.ts +1 -1
  121. package/tempo/SignatureEnvelope.test.ts +12 -0
  122. package/tempo/SignatureEnvelope.ts +4 -4
  123. package/tempo/SignaturePreAuthorized/package.json +6 -0
  124. package/tempo/SignaturePreAuthorized.test-d/package.json +6 -0
  125. package/tempo/SignaturePreAuthorized.test-d.ts +29 -0
  126. package/tempo/SignaturePreAuthorized.test.ts +410 -0
  127. package/tempo/SignaturePreAuthorized.ts +370 -0
  128. package/tempo/Tick.test.ts +10 -0
  129. package/tempo/Tick.ts +5 -3
  130. package/tempo/index.ts +9 -0
  131. package/version.ts +1 -1
@@ -0,0 +1,192 @@
1
+ import * as Errors from '../core/Errors.js';
2
+ import * as Hex from '../core/Hex.js';
3
+ import * as Rlp from '../core/Rlp.js';
4
+ import * as KeyAuthorization from './KeyAuthorization.js';
5
+ import * as SignatureEnvelope from './SignatureEnvelope.js';
6
+ /** Unwrapped [TIP-1165](https://tips.sh/1165) pre-authorized signature. */
7
+ export type Unwrapped = {
8
+ /** Root key's signed authorization of the access key. */
9
+ keyAuthorization: KeyAuthorization.Signed;
10
+ /** V2 keychain signature by the access key. */
11
+ signature: SignatureEnvelope.Keychain;
12
+ };
13
+ /** Wrapped [TIP-1165](https://tips.sh/1165) pre-authorized signature. */
14
+ export type Wrapped = Hex.Hex;
15
+ /**
16
+ * Magic bytes used to identify [TIP-1165](https://tips.sh/1165) pre-authorized signatures.
17
+ */
18
+ export declare const magicBytes: "0x1165116511651165116511651165116511651165116511651165116511651165";
19
+ /**
20
+ * Asserts that a value is a valid pre-authorized signature.
21
+ *
22
+ * A wrapped value must end with {@link ox#SignaturePreAuthorized.magicBytes} and decode strictly.
23
+ * An unwrapped value must hold a V2 keychain signature with a primitive inner
24
+ * signature, and a signed key authorization.
25
+ *
26
+ * @example
27
+ * ```ts twoslash
28
+ * import { SignaturePreAuthorized } from 'ox/tempo'
29
+ *
30
+ * SignaturePreAuthorized.assert('0xdeadbeef')
31
+ * // @error: InvalidWrappedSignatureError: Value `0xdeadbeef` is an invalid pre-authorized signature.
32
+ * ```
33
+ *
34
+ * @param value - The value to assert.
35
+ */
36
+ export declare function assert(value: Unwrapped | Wrapped): void;
37
+ export declare namespace assert {
38
+ type ErrorType = InvalidWrappedSignatureError | InvalidUnwrappedSignatureError | Errors.GlobalErrorType;
39
+ }
40
+ /**
41
+ * Instantiates a [TIP-1165](https://tips.sh/1165) pre-authorized signature from its wrapped or unwrapped form.
42
+ *
43
+ * @example
44
+ * ```ts twoslash
45
+ * // @noErrors
46
+ * import { SignaturePreAuthorized } from 'ox/tempo'
47
+ *
48
+ * // Instantiate from serialized format. // [!code focus]
49
+ * const unwrapped = SignaturePreAuthorized.from('0x...') // [!code focus]
50
+ * // @log: { keyAuthorization: { ... }, signature: { ... } } // [!code focus]
51
+ *
52
+ * // Instantiate from constituent parts. // [!code focus]
53
+ * const unwrapped = SignaturePreAuthorized.from({
54
+ * // [!code focus]
55
+ * keyAuthorization, // [!code focus]
56
+ * signature // [!code focus]
57
+ * }) // [!code focus]
58
+ * ```
59
+ *
60
+ * @param value - Wrapped or unwrapped pre-authorized signature.
61
+ * @returns Unwrapped pre-authorized signature.
62
+ */
63
+ export declare function from(value: Unwrapped | Wrapped): Unwrapped;
64
+ export declare namespace from {
65
+ type ReturnType = Unwrapped;
66
+ type ErrorType = assert.ErrorType | unwrap.ErrorType | Errors.GlobalErrorType;
67
+ }
68
+ /**
69
+ * Parses a [TIP-1165](https://tips.sh/1165) pre-authorized signature into its keychain signature and signed key authorization.
70
+ *
71
+ * Decoding is strict: the value must end with {@link ox#SignaturePreAuthorized.magicBytes},
72
+ * and the rest must be one canonical RLP list of exactly two items with no trailing bytes.
73
+ *
74
+ * @example
75
+ * ```ts twoslash
76
+ * // @noErrors
77
+ * import { SignaturePreAuthorized } from 'ox/tempo'
78
+ *
79
+ * const { keyAuthorization, signature } =
80
+ * SignaturePreAuthorized.unwrap('0x...')
81
+ * ```
82
+ *
83
+ * @param wrapped - Wrapped pre-authorized signature to parse.
84
+ * @returns Unwrapped pre-authorized signature.
85
+ */
86
+ export declare function unwrap(wrapped: Wrapped): Unwrapped;
87
+ export declare namespace unwrap {
88
+ type ErrorType = InvalidWrappedSignatureError | Errors.GlobalErrorType;
89
+ }
90
+ /**
91
+ * Serializes a [TIP-1165](https://tips.sh/1165) pre-authorized signature:
92
+ * `rlp([keychain_signature, signed_key_authorization]) ‖ magic`.
93
+ *
94
+ * The signature must be a V2 keychain signature whose inner signature is
95
+ * secp256k1, P256, or WebAuthn.
96
+ *
97
+ * @example
98
+ * ```ts twoslash
99
+ * import { Hash, Hex, Secp256k1 } from 'ox'
100
+ * import {
101
+ * KeyAuthorization,
102
+ * SignatureEnvelope,
103
+ * SignaturePreAuthorized
104
+ * } from 'ox/tempo'
105
+ *
106
+ * const account = '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'
107
+ * const accessKey = Secp256k1.randomPrivateKey()
108
+ * const rootKey = Secp256k1.randomPrivateKey()
109
+ *
110
+ * const authorization = KeyAuthorization.from({
111
+ * address: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
112
+ * chainId: 4217n,
113
+ * type: 'secp256k1'
114
+ * })
115
+ * const keyAuthorization = KeyAuthorization.from(
116
+ * authorization,
117
+ * {
118
+ * signature: SignatureEnvelope.from(
119
+ * Secp256k1.sign({
120
+ * payload:
121
+ * KeyAuthorization.getSignPayload(authorization),
122
+ * privateKey: rootKey
123
+ * })
124
+ * )
125
+ * }
126
+ * )
127
+ *
128
+ * const hash = Hash.keccak256(Hex.fromString('hello'))
129
+ * const signature = SignatureEnvelope.from({
130
+ * inner: SignatureEnvelope.from(
131
+ * Secp256k1.sign({
132
+ * payload: Hash.keccak256(
133
+ * Hex.concat('0x04', hash, account)
134
+ * ),
135
+ * privateKey: accessKey
136
+ * })
137
+ * ),
138
+ * userAddress: account
139
+ * })
140
+ *
141
+ * const wrapped = SignaturePreAuthorized.wrap({
142
+ * // [!code focus]
143
+ * keyAuthorization, // [!code focus]
144
+ * signature // [!code focus]
145
+ * }) // [!code focus]
146
+ * ```
147
+ *
148
+ * @param value - Unwrapped pre-authorized signature.
149
+ * @returns Wrapped pre-authorized signature.
150
+ */
151
+ export declare function wrap(value: Unwrapped): Wrapped;
152
+ export declare namespace wrap {
153
+ type ErrorType = assert.ErrorType | SignatureEnvelope.serialize.ErrorType | KeyAuthorization.toTuple.ErrorType | Rlp.fromHex.ErrorType | Hex.concat.ErrorType | Errors.GlobalErrorType;
154
+ }
155
+ /**
156
+ * Validates a wrapped pre-authorized signature. Returns `true` if it decodes strictly, `false` otherwise.
157
+ *
158
+ * This checks the encoding only. It does not verify either signature or read chain state.
159
+ *
160
+ * @example
161
+ * ```ts twoslash
162
+ * import { SignaturePreAuthorized } from 'ox/tempo'
163
+ *
164
+ * const valid = SignaturePreAuthorized.validate('0xdeadbeef')
165
+ * // @log: false
166
+ * ```
167
+ *
168
+ * @param wrapped - The wrapped signature to validate.
169
+ * @returns `true` if the wrapped signature is valid, `false` otherwise.
170
+ */
171
+ export declare function validate(wrapped: Wrapped): boolean;
172
+ export declare namespace validate {
173
+ type ErrorType = Errors.GlobalErrorType;
174
+ }
175
+ /** Thrown when a wrapped pre-authorized signature is invalid. */
176
+ export declare class InvalidWrappedSignatureError extends Errors.BaseError<Error | undefined> {
177
+ readonly name = "SignaturePreAuthorized.InvalidWrappedSignatureError";
178
+ constructor(wrapped: unknown, options?: {
179
+ cause?: Error | undefined;
180
+ });
181
+ }
182
+ /** Thrown when an unwrapped pre-authorized signature is malformed. */
183
+ export declare class InvalidUnwrappedSignatureError extends Errors.BaseError {
184
+ readonly name = "SignaturePreAuthorized.InvalidUnwrappedSignatureError";
185
+ /** The malformed value. */
186
+ readonly value: unknown;
187
+ constructor({ reason, value }: {
188
+ reason: string;
189
+ value: unknown;
190
+ });
191
+ }
192
+ //# sourceMappingURL=SignaturePreAuthorized.d.ts.map
@@ -0,0 +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AAQ,MAAM,CAAC,SAAS;IACxD,SAAkB,IAAI,+BAA8B;gBAExC,OAAO,EAAE,oBAAoB,CAAC,OAAO;CAKlD;AAED,MAAM,CAAC,OAAO,WAAW,oBAAoB,CAAC;IAC5C,KAAY,OAAO,GAAG;QACpB,IAAI,EAAE,MAAM,CAAA;KACb,CAAA;CACF;AAED;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,MAAM,CAAC,SAAS;IAC3D,SAAkB,IAAI,kCAAiC;gBAE3C,OAAO,EAAE,uBAAuB,CAAC,OAAO;CAKrD;AAED,MAAM,CAAC,OAAO,WAAW,uBAAuB,CAAC;IAC/C,KAAY,OAAO,GAAG;QACpB,KAAK,EAAE,MAAM,CAAA;KACd,CAAA;CACF;AAED;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,MAAM,CAAC,SAAS;IACzD,SAAkB,IAAI,gCAA+B;gBAEzC,OAAO,EAAE,qBAAqB,CAAC,OAAO;CAQnD;AAED,MAAM,CAAC,OAAO,WAAW,qBAAqB,CAAC;IAC7C,KAAY,OAAO,GAAG;QACpB,KAAK,EAAE,MAAM,CAAA;QACb,IAAI,EAAE,MAAM,CAAA;KACb,CAAA;CACF"}
@@ -283,6 +283,14 @@ export * as RpcSchemaTempo from './RpcSchemaTempo.js';
283
283
  * @category Reference
284
284
  */
285
285
  export * as SignatureEnvelope from './SignatureEnvelope.js';
286
+ /**
287
+ * Utilities for [TIP-1165](https://tips.sh/1165) pre-authorized access key signatures: a keychain
288
+ * signature bundled with the signed key authorization for its access key, so verifiers can accept
289
+ * it before the access key is registered onchain.
290
+ *
291
+ * @category Reference
292
+ */
293
+ export * as SignaturePreAuthorized from './SignaturePreAuthorized.js';
286
294
  /**
287
295
  * Tempo address encoding/decoding utilities for human-readable addresses.
288
296
  *
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../tempo/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAEhC,YAAY,EAAE,CAAA;AAEd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O,KAAK,kBAAkB,MAAM,yBAAyB,CAAA;AAC7D;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAA;AACvD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AACrD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA;AAEnD;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,OAAO,KAAK,qBAAqB,MAAM,4BAA4B,CAAA"}
@@ -1,3 +1,3 @@
1
1
  /** @internal */
2
- export declare const version = "0.14.63";
2
+ export declare const version = "0.14.65";
3
3
  //# sourceMappingURL=version.d.ts.map
package/core/AbiError.ts CHANGED
@@ -210,14 +210,17 @@ export function decode(
210
210
  }
211
211
  return parameters as [AbiError, Hex.Hex, decode.Options | undefined]
212
212
  })()
213
+ const { overloads } = abiError as AbiError
214
+
213
215
  if (Hex.size(data) < 4) throw new AbiItem.InvalidSelectorSizeError({ data })
214
- if (abiError.inputs?.length === 0) return undefined
215
216
 
216
- const values = AbiParameters.decode(
217
- abiError.inputs,
218
- Hex.slice(data, 4),
219
- options,
220
- )
217
+ const item = overloads
218
+ ? (fromAbi([abiError, ...overloads], data as never) as AbiError)
219
+ : abiError
220
+
221
+ if (item.inputs?.length === 0) return undefined
222
+
223
+ const values = AbiParameters.decode(item.inputs, Hex.slice(data, 4), options)
221
224
  if (values && Object.keys(values).length === 1) {
222
225
  if (Array.isArray(values)) return values[0]
223
226
  return Object.values(values)[0]
@@ -239,22 +242,30 @@ export declare namespace decode {
239
242
  abiError extends AbiError = AbiError,
240
243
  as extends 'Object' | 'Array' = 'Array',
241
244
  > = IsNarrowable<abiError, AbiError> extends true
242
- ? abiError['inputs'] extends readonly []
243
- ? undefined
244
- : abiError['inputs'] extends readonly [
245
- infer type extends abitype.AbiParameter,
246
- ]
247
- ? abitype.AbiParameterToPrimitiveType<type>
248
- : AbiParameters.decode.ReturnType<
249
- abiError['inputs'],
250
- as
251
- > extends infer types
252
- ? types extends readonly []
253
- ? undefined
254
- : types extends readonly [infer type]
255
- ? type
256
- : types
257
- : never
245
+ ? // distribute over the error and its overloads
246
+ | abiError
247
+ | (abiError['overloads'] extends readonly AbiError[]
248
+ ? abiError['overloads'][number]
249
+ : never) extends infer item extends AbiError
250
+ ? item extends AbiError
251
+ ? item['inputs'] extends readonly []
252
+ ? undefined
253
+ : item['inputs'] extends readonly [
254
+ infer type extends abitype.AbiParameter,
255
+ ]
256
+ ? abitype.AbiParameterToPrimitiveType<type>
257
+ : AbiParameters.decode.ReturnType<
258
+ item['inputs'],
259
+ as
260
+ > extends infer types
261
+ ? types extends readonly []
262
+ ? undefined
263
+ : types extends readonly [infer type]
264
+ ? type
265
+ : types
266
+ : never
267
+ : never
268
+ : never
258
269
  : unknown | readonly unknown[] | undefined
259
270
 
260
271
  type ErrorType =
package/core/AbiEvent.ts CHANGED
@@ -160,6 +160,13 @@ export function assertArgs<const abiEvent extends AbiEvent>(
160
160
  Solidity.bytesRegex.test(input.type)
161
161
  )
162
162
  return value.toLowerCase() === arg.toLowerCase()
163
+ // Small integers decode as numbers, so match a number or bigint either way.
164
+ if (
165
+ (typeof value === 'bigint' || Number.isInteger(value)) &&
166
+ (typeof arg === 'bigint' || Number.isInteger(arg)) &&
167
+ Solidity.integerRegex.test(input.type)
168
+ )
169
+ return BigInt(value as bigint | number) === BigInt(arg as bigint | number)
163
170
  return value === arg
164
171
  }
165
172
 
@@ -157,12 +157,12 @@ export function decodeData(
157
157
  const { overloads } = abiFunction
158
158
 
159
159
  if (Hex.size(data) < 4) throw new AbiItem.InvalidSelectorSizeError({ data })
160
- if (abiFunction.inputs?.length === 0) return undefined
161
160
 
162
161
  const item = overloads
163
162
  ? fromAbi([abiFunction, ...overloads], data as never)
164
163
  : abiFunction
165
164
 
165
+ if (item.inputs.length === 0) return undefined
166
166
  if (Hex.size(data) <= 4) return undefined
167
167
  return AbiParameters.decode(item.inputs, Hex.slice(data, 4))
168
168
  }
@@ -172,15 +172,17 @@ export declare namespace decodeData {
172
172
  abiFunction,
173
173
  AbiFunction
174
174
  > extends true
175
- ? abiFunction['inputs'] extends readonly []
176
- ? undefined
177
- :
178
- | AbiParameters_internal.ToPrimitiveTypes<abiFunction['inputs']>
175
+ ? abiFunction extends AbiFunction
176
+ ?
177
+ | (abiFunction['inputs'] extends readonly []
178
+ ? undefined
179
+ : AbiParameters_internal.ToPrimitiveTypes<abiFunction['inputs']>)
179
180
  | (abiFunction['overloads'] extends readonly AbiFunction[]
180
181
  ? AbiParameters_internal.ToPrimitiveTypes<
181
182
  abiFunction['overloads'][number]['inputs']
182
183
  >
183
184
  : never)
185
+ : never
184
186
  : unknown
185
187
 
186
188
  type ErrorType =
package/core/AbiItem.ts CHANGED
@@ -359,14 +359,14 @@ export function fromAbi<
359
359
  } as never
360
360
 
361
361
  let matchedAbiItem: AbiItem | undefined
362
+ // Without `args`, a zero-input overload is the preferred pick, but the other
363
+ // overloads are still attached so callers can resolve by selector.
364
+ let zeroArgAbiItem: AbiItem | undefined
362
365
  for (const abiItem of abiItems) {
363
366
  if (!('inputs' in abiItem)) continue
364
367
  if (!args || args.length === 0) {
365
- if (!abiItem.inputs || abiItem.inputs.length === 0)
366
- return {
367
- ...abiItem,
368
- ...(prepare ? { hash: getSignatureHash(abiItem) } : {}),
369
- } as never
368
+ if (!zeroArgAbiItem && (!abiItem.inputs || abiItem.inputs.length === 0))
369
+ zeroArgAbiItem = abiItem
370
370
  continue
371
371
  }
372
372
  if (!abiItem.inputs) continue
@@ -408,8 +408,9 @@ export function fromAbi<
408
408
 
409
409
  const abiItem = (() => {
410
410
  if (matchedAbiItem) return matchedAbiItem
411
- const [abiItem, ...overloads] = abiItems
412
- return { ...abiItem!, overloads }
411
+ const chosen = zeroArgAbiItem ?? abiItems[0]
412
+ const overloads = abiItems.filter((item) => item !== chosen)
413
+ return { ...chosen!, overloads }
413
414
  })()
414
415
 
415
416
  if (!abiItem) throw new NotFoundError({ name: name as string })
package/core/Base32.ts CHANGED
@@ -71,7 +71,7 @@ export declare namespace fromHex {
71
71
  * ```ts twoslash
72
72
  * import { Base32 } from 'ox'
73
73
  *
74
- * const value = Base32.toBytes('qqsa0')
74
+ * const value = Base32.toBytes('qrlsq')
75
75
  * ```
76
76
  *
77
77
  * @param value - The Base32 encoded string.
@@ -96,11 +96,16 @@ export function toBytes(value: string): Bytes.Bytes {
96
96
  bytes.push((acc >>> bits) & 0xff)
97
97
  }
98
98
  }
99
+ // Reject leftover bits that do not fill a whole symbol, or that are non-zero.
100
+ if (bits >= 5 || acc & ((1 << bits) - 1)) throw new InvalidPaddingError()
99
101
  return new Uint8Array(bytes)
100
102
  }
101
103
 
102
104
  export declare namespace toBytes {
103
- type ErrorType = InvalidCharacterError | Errors.GlobalErrorType
105
+ type ErrorType =
106
+ | InvalidCharacterError
107
+ | InvalidPaddingError
108
+ | Errors.GlobalErrorType
104
109
  }
105
110
 
106
111
  /**
@@ -110,7 +115,7 @@ export declare namespace toBytes {
110
115
  * ```ts twoslash
111
116
  * import { Base32 } from 'ox'
112
117
  *
113
- * const value = Base32.toHex('qqsa0')
118
+ * const value = Base32.toHex('qrlsq')
114
119
  * ```
115
120
  *
116
121
  * @param value - The Base32 encoded string.
@@ -132,3 +137,12 @@ export class InvalidCharacterError extends Errors.BaseError {
132
137
  super(`Invalid bech32 base32 character: "${character}".`)
133
138
  }
134
139
  }
140
+
141
+ /** Thrown when a Base32 string contains non-canonical (non-zero) trailing bits. */
142
+ export class InvalidPaddingError extends Errors.BaseError {
143
+ override readonly name = 'Base32.InvalidPaddingError'
144
+
145
+ constructor() {
146
+ super('Non-canonical trailing bits in Base32 input.')
147
+ }
148
+ }
package/core/Bytes.ts CHANGED
@@ -212,15 +212,13 @@ export declare namespace fromBoolean {
212
212
  export function fromHex(value: Hex.Hex, options: fromHex.Options = {}): Bytes {
213
213
  const { size } = options
214
214
 
215
- let hex = value
215
+ let hexString = value.slice(2)
216
+ if (hexString.length % 2) hexString = `0${hexString}`
216
217
  if (size) {
217
218
  internal_hex.assertSize(value, size)
218
- hex = Hex.padRight(value, size)
219
+ hexString = hexString.padEnd(size * 2, '0')
219
220
  }
220
221
 
221
- let hexString = hex.slice(2) as string
222
- if (hexString.length % 2) hexString = `0${hexString}`
223
-
224
222
  const length = hexString.length / 2
225
223
  const bytes = new Uint8Array(length)
226
224
  for (let index = 0, j = 0; index < length; index++) {
package/core/Cbor.ts CHANGED
@@ -863,7 +863,7 @@ namespace decodeCursor {
863
863
  ? String(key)
864
864
  : String(key)
865
865
  const value = decodeCursor(cursor)
866
- result[keyStr] = value
866
+ setEntry(result, keyStr, value)
867
867
  }
868
868
 
869
869
  return result
@@ -882,7 +882,7 @@ namespace decodeCursor {
882
882
  ? String(key)
883
883
  : String(key)
884
884
  const value = decodeCursor(cursor)
885
- result[keyStr] = value
885
+ setEntry(result, keyStr, value)
886
886
  }
887
887
 
888
888
  return result
@@ -893,6 +893,24 @@ namespace decodeCursor {
893
893
  type ErrorType = readLength.ErrorType | Errors.GlobalErrorType
894
894
  }
895
895
 
896
+ /** @internal */
897
+ function setEntry(
898
+ result: Record<string, unknown>,
899
+ key: string,
900
+ value: unknown,
901
+ ) {
902
+ // Define `__proto__` as an own property instead of assigning it, which
903
+ // would replace the prototype of `result` and drop the entry.
904
+ if (key === '__proto__')
905
+ Object.defineProperty(result, key, {
906
+ configurable: true,
907
+ enumerable: true,
908
+ value,
909
+ writable: true,
910
+ })
911
+ else result[key] = value
912
+ }
913
+
896
914
  /** @internal */
897
915
  export function readSimpleOrFloat(
898
916
  cursor: Cursor.Cursor,
package/core/Hex.ts CHANGED
@@ -252,7 +252,9 @@ export function fromNumber(
252
252
  maxValue = BigInt(Number.MAX_SAFE_INTEGER)
253
253
  }
254
254
 
255
- const minValue = typeof maxValue === 'bigint' && signed ? -maxValue - 1n : 0
255
+ // Negative values need a `size` to encode as two's complement.
256
+ const minValue =
257
+ size && typeof maxValue === 'bigint' && signed ? -maxValue - 1n : 0
256
258
 
257
259
  if ((maxValue && value_ > maxValue) || value_ < minValue) {
258
260
  const suffix = typeof value === 'bigint' ? 'n' : ''
@@ -568,9 +570,7 @@ export function toBigInt(hex: Hex, options: toBigInt.Options = {}): bigint {
568
570
  const value = BigInt(hex)
569
571
  if (!signed) return value
570
572
 
571
- const size = (hex.length - 2) / 2
572
-
573
- const max_unsigned = (1n << (BigInt(size) * 8n)) - 1n
573
+ const max_unsigned = (1n << (BigInt(size(hex)) * 8n)) - 1n
574
574
  const max_signed = max_unsigned >> 1n
575
575
 
576
576
  if (value <= max_signed) return value
package/core/Rlp.ts CHANGED
@@ -109,6 +109,14 @@ export function decodeRlpCursor<to extends 'Hex' | 'Bytes' = 'Hex'>(
109
109
  if (prefix < 0xc0) {
110
110
  const length = readLength(cursor, prefix, 0x80)
111
111
  const bytes = cursor.readBytes(length)
112
+ // A single byte below `0x80` must be its own encoding (no length
113
+ // prefix); wrapping it in an explicit one-byte-length prefix is a
114
+ // non-canonical alternate encoding of the same value (Yellow Paper,
115
+ // Appendix B).
116
+ if (prefix >= 0x80 && length === 1 && bytes[0]! < 0x80)
117
+ throw new NonCanonicalError({
118
+ reason: `single byte \`0x${bytes[0]!.toString(16).padStart(2, '0')}\` is wrapped in an explicit length prefix instead of being encoded as itself`,
119
+ })
112
120
  return (
113
121
  to === 'Hex' ? Hex.fromBytes(bytes) : bytes
114
122
  ) as decodeRlpCursor.ReturnType<to>
@@ -126,6 +134,7 @@ export declare namespace decodeRlpCursor {
126
134
  | Hex.fromBytes.ErrorType
127
135
  | readLength.ErrorType
128
136
  | readList.ErrorType
137
+ | NonCanonicalError
129
138
  | Errors.GlobalErrorType
130
139
  }
131
140
 
@@ -137,16 +146,48 @@ export function readLength(
137
146
  ) {
138
147
  if (offset === 0x80 && prefix < 0x80) return 1
139
148
  if (prefix <= offset + 55) return prefix - offset
140
- if (prefix === offset + 55 + 1) return cursor.readUint8()
141
- if (prefix === offset + 55 + 2) return cursor.readUint16()
142
- if (prefix === offset + 55 + 3) return cursor.readUint24()
143
- if (prefix === offset + 55 + 4) return cursor.readUint32()
149
+ // Long-form lengths must use the minimal number of length-bytes: a value
150
+ // that fits in fewer bytes (or in the short form, i.e. <= 55) encoded via
151
+ // a longer form is a non-canonical alternate encoding of the same value
152
+ // (Yellow Paper, Appendix B).
153
+ if (prefix === offset + 55 + 1) {
154
+ const length = cursor.readUint8()
155
+ if (length <= 55)
156
+ throw new NonCanonicalError({
157
+ reason: `length \`${length}\` fits in the short form and must not use a one-byte length prefix`,
158
+ })
159
+ return length
160
+ }
161
+ if (prefix === offset + 55 + 2) {
162
+ const length = cursor.readUint16()
163
+ if (length <= 0xff)
164
+ throw new NonCanonicalError({
165
+ reason: `length \`${length}\` fits in fewer length-bytes and must not use a two-byte length prefix`,
166
+ })
167
+ return length
168
+ }
169
+ if (prefix === offset + 55 + 3) {
170
+ const length = cursor.readUint24()
171
+ if (length <= 0xffff)
172
+ throw new NonCanonicalError({
173
+ reason: `length \`${length}\` fits in fewer length-bytes and must not use a three-byte length prefix`,
174
+ })
175
+ return length
176
+ }
177
+ if (prefix === offset + 55 + 4) {
178
+ const length = cursor.readUint32()
179
+ if (length <= 0xffffff)
180
+ throw new NonCanonicalError({
181
+ reason: `length \`${length}\` fits in fewer length-bytes and must not use a four-byte length prefix`,
182
+ })
183
+ return length
184
+ }
144
185
  throw new Errors.BaseError('Invalid RLP prefix')
145
186
  }
146
187
 
147
188
  /** @internal */
148
189
  export declare namespace readLength {
149
- type ErrorType = Errors.BaseError | Errors.GlobalErrorType
190
+ type ErrorType = NonCanonicalError | Errors.BaseError | Errors.GlobalErrorType
150
191
  }
151
192
 
152
193
  /** @internal */
@@ -365,3 +406,12 @@ function getSizeOfLength(length: number) {
365
406
  if (length <= 0xff_ff_ff_ff) return 4
366
407
  throw new Errors.BaseError('Length is too large.')
367
408
  }
409
+
410
+ /** Thrown when an RLP payload uses a non-canonical alternate encoding of a value. */
411
+ export class NonCanonicalError extends Errors.BaseError {
412
+ override readonly name = 'Rlp.NonCanonicalError'
413
+
414
+ constructor({ reason }: { reason: string }) {
415
+ super(`RLP payload is not canonically encoded: ${reason}.`)
416
+ }
417
+ }
@@ -103,13 +103,21 @@ export function fromHttp<
103
103
  fetchOptions?.signal,
104
104
  timeout > 0 ? signal : null,
105
105
  ].filter((s): s is AbortSignal => Boolean(s))
106
+ // Merge through `Headers` so `Headers` instances and tuple arrays
107
+ // keep their entries, and a caller's header replaces the default
108
+ // whatever its casing.
109
+ const headers: Record<string, string> = {}
110
+ for (const source of [
111
+ { 'Content-Type': 'application/json' },
112
+ fetchOptions?.headers,
113
+ ])
114
+ new Headers(source).forEach((value, key) => {
115
+ headers[key] = value
116
+ })
106
117
  const init: RequestInit = {
107
118
  ...fetchOptions,
108
119
  body,
109
- headers: {
110
- 'Content-Type': 'application/json',
111
- ...fetchOptions?.headers,
112
- },
120
+ headers,
113
121
  method: fetchOptions?.method ?? 'POST',
114
122
  signal: (() => {
115
123
  if (signals.length < 2) return signals[0] ?? null
package/core/Siwe.ts CHANGED
@@ -445,6 +445,11 @@ export function validateMessage(value: validateMessage.Value): boolean {
445
445
  if (nonce && message.nonce !== nonce) return false
446
446
  if (scheme && message.scheme !== scheme) return false
447
447
 
448
+ // EIP-4361 requires `nonce = 8*( ALPHA / DIGIT )` and `version = "1"`.
449
+ if (message.nonce !== undefined && !nonceRegex.test(message.nonce))
450
+ return false
451
+ if (message.version !== undefined && message.version !== '1') return false
452
+
448
453
  if (message.expirationTime && time >= message.expirationTime) return false
449
454
  if (message.notBefore && time < message.notBefore) return false
450
455