ox 0.8.8 → 0.9.0

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 (248) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/_cjs/core/AbiEvent.js +1 -1
  3. package/_cjs/core/AbiEvent.js.map +1 -1
  4. package/_cjs/core/AbiItem.js +1 -1
  5. package/_cjs/core/AbiItem.js.map +1 -1
  6. package/_cjs/core/AbiParameters.js +4 -4
  7. package/_cjs/core/AbiParameters.js.map +1 -1
  8. package/_cjs/core/Authorization.js +5 -4
  9. package/_cjs/core/Authorization.js.map +1 -1
  10. package/_cjs/core/Blobs.js +1 -1
  11. package/_cjs/core/Blobs.js.map +1 -1
  12. package/_cjs/core/Block.js.map +1 -1
  13. package/_cjs/core/Bytes.js +1 -1
  14. package/_cjs/core/Bytes.js.map +1 -1
  15. package/_cjs/core/ContractAddress.js.map +1 -1
  16. package/_cjs/core/HdKey.js.map +1 -1
  17. package/_cjs/core/Hex.js +1 -1
  18. package/_cjs/core/Hex.js.map +1 -1
  19. package/_cjs/core/Keystore.js.map +1 -1
  20. package/_cjs/core/Mnemonic.js +2 -2
  21. package/_cjs/core/Mnemonic.js.map +1 -1
  22. package/_cjs/core/P256.js +1 -1
  23. package/_cjs/core/P256.js.map +1 -1
  24. package/_cjs/core/Provider.js.map +1 -1
  25. package/_cjs/core/PublicKey.js +1 -1
  26. package/_cjs/core/PublicKey.js.map +1 -1
  27. package/_cjs/core/RpcTransport.js +1 -1
  28. package/_cjs/core/RpcTransport.js.map +1 -1
  29. package/_cjs/core/Secp256k1.js +1 -1
  30. package/_cjs/core/Secp256k1.js.map +1 -1
  31. package/_cjs/core/Signature.js.map +1 -1
  32. package/_cjs/core/Siwe.js +4 -4
  33. package/_cjs/core/Siwe.js.map +1 -1
  34. package/_cjs/core/Transaction.js.map +1 -1
  35. package/_cjs/core/TransactionEnvelope.js.map +1 -1
  36. package/_cjs/core/TransactionEnvelopeEip1559.js.map +1 -1
  37. package/_cjs/core/TransactionEnvelopeEip2930.js.map +1 -1
  38. package/_cjs/core/TransactionEnvelopeEip4844.js.map +1 -1
  39. package/_cjs/core/TransactionEnvelopeEip7702.js.map +1 -1
  40. package/_cjs/core/TransactionEnvelopeLegacy.js.map +1 -1
  41. package/_cjs/core/TransactionReceipt.js.map +1 -1
  42. package/_cjs/core/TypedData.js +3 -3
  43. package/_cjs/core/TypedData.js.map +1 -1
  44. package/_cjs/core/WebAuthnP256.js +1 -1
  45. package/_cjs/core/WebAuthnP256.js.map +1 -1
  46. package/_cjs/core/WebCryptoP256.js.map +1 -1
  47. package/_cjs/core/internal/abiParameters.js +4 -4
  48. package/_cjs/core/internal/abiParameters.js.map +1 -1
  49. package/_cjs/core/internal/promise.js.map +1 -1
  50. package/_cjs/erc4337/UserOperation.js.map +1 -1
  51. package/_cjs/erc6492/{WrappedSignature.js → SignatureErc6492.js} +8 -8
  52. package/_cjs/erc6492/SignatureErc6492.js.map +1 -0
  53. package/_cjs/erc6492/index.js +2 -2
  54. package/_cjs/erc8010/SignatureErc8010.js +95 -0
  55. package/_cjs/erc8010/SignatureErc8010.js.map +1 -0
  56. package/_cjs/erc8010/index.js +5 -0
  57. package/_cjs/erc8010/index.js.map +1 -0
  58. package/_cjs/index.docs.js +1 -0
  59. package/_cjs/index.docs.js.map +1 -1
  60. package/_cjs/index.js +6 -6
  61. package/_cjs/index.js.map +1 -1
  62. package/_cjs/trusted-setups/internal/paths.js.map +1 -1
  63. package/_cjs/version.js +1 -1
  64. package/_esm/core/AbiEvent.js +1 -1
  65. package/_esm/core/AbiEvent.js.map +1 -1
  66. package/_esm/core/AbiItem.js +1 -1
  67. package/_esm/core/AbiItem.js.map +1 -1
  68. package/_esm/core/AbiParameters.js +4 -4
  69. package/_esm/core/AbiParameters.js.map +1 -1
  70. package/_esm/core/Authorization.js +5 -4
  71. package/_esm/core/Authorization.js.map +1 -1
  72. package/_esm/core/Blobs.js +1 -1
  73. package/_esm/core/Blobs.js.map +1 -1
  74. package/_esm/core/Block.js.map +1 -1
  75. package/_esm/core/Bytes.js +1 -1
  76. package/_esm/core/Bytes.js.map +1 -1
  77. package/_esm/core/ContractAddress.js.map +1 -1
  78. package/_esm/core/HdKey.js.map +1 -1
  79. package/_esm/core/Hex.js +1 -1
  80. package/_esm/core/Hex.js.map +1 -1
  81. package/_esm/core/Keystore.js +3 -2
  82. package/_esm/core/Keystore.js.map +1 -1
  83. package/_esm/core/Mnemonic.js +1 -1
  84. package/_esm/core/Mnemonic.js.map +1 -1
  85. package/_esm/core/P256.js +1 -1
  86. package/_esm/core/P256.js.map +1 -1
  87. package/_esm/core/Provider.js.map +1 -1
  88. package/_esm/core/PublicKey.js +1 -1
  89. package/_esm/core/PublicKey.js.map +1 -1
  90. package/_esm/core/RpcTransport.js +1 -1
  91. package/_esm/core/RpcTransport.js.map +1 -1
  92. package/_esm/core/Secp256k1.js +1 -1
  93. package/_esm/core/Secp256k1.js.map +1 -1
  94. package/_esm/core/Signature.js.map +1 -1
  95. package/_esm/core/Siwe.js +4 -4
  96. package/_esm/core/Siwe.js.map +1 -1
  97. package/_esm/core/Transaction.js.map +1 -1
  98. package/_esm/core/TransactionEnvelope.js.map +1 -1
  99. package/_esm/core/TransactionEnvelopeEip1559.js.map +1 -1
  100. package/_esm/core/TransactionEnvelopeEip2930.js.map +1 -1
  101. package/_esm/core/TransactionEnvelopeEip4844.js.map +1 -1
  102. package/_esm/core/TransactionEnvelopeEip7702.js.map +1 -1
  103. package/_esm/core/TransactionEnvelopeLegacy.js.map +1 -1
  104. package/_esm/core/TransactionReceipt.js.map +1 -1
  105. package/_esm/core/TypedData.js +3 -3
  106. package/_esm/core/TypedData.js.map +1 -1
  107. package/_esm/core/WebAuthnP256.js +1 -1
  108. package/_esm/core/WebAuthnP256.js.map +1 -1
  109. package/_esm/core/WebCryptoP256.js.map +1 -1
  110. package/_esm/core/internal/abiParameters.js +4 -4
  111. package/_esm/core/internal/abiParameters.js.map +1 -1
  112. package/_esm/core/internal/promise.js.map +1 -1
  113. package/_esm/erc4337/UserOperation.js.map +1 -1
  114. package/_esm/erc6492/{WrappedSignature.js → SignatureErc6492.js} +17 -17
  115. package/_esm/erc6492/{WrappedSignature.js.map → SignatureErc6492.js.map} +1 -1
  116. package/_esm/erc6492/index.js +3 -3
  117. package/_esm/erc8010/SignatureErc8010.js +184 -0
  118. package/_esm/erc8010/SignatureErc8010.js.map +1 -0
  119. package/_esm/erc8010/index.js +40 -0
  120. package/_esm/erc8010/index.js.map +1 -0
  121. package/_esm/index.docs.js +2 -0
  122. package/_esm/index.docs.js.map +1 -1
  123. package/_esm/index.js +236 -236
  124. package/_esm/index.js.map +1 -1
  125. package/_esm/trusted-setups/internal/paths.js +1 -0
  126. package/_esm/trusted-setups/internal/paths.js.map +1 -1
  127. package/_esm/version.js +1 -1
  128. package/_types/core/AbiEvent.d.ts +1 -2
  129. package/_types/core/AbiEvent.d.ts.map +1 -1
  130. package/_types/core/AbiParameters.d.ts.map +1 -1
  131. package/_types/core/Authorization.d.ts +1 -1
  132. package/_types/core/Authorization.d.ts.map +1 -1
  133. package/_types/core/Blobs.d.ts +1 -1
  134. package/_types/core/Blobs.d.ts.map +1 -1
  135. package/_types/core/Block.d.ts +1 -1
  136. package/_types/core/Block.d.ts.map +1 -1
  137. package/_types/core/Bytes.d.ts.map +1 -1
  138. package/_types/core/ContractAddress.d.ts +1 -1
  139. package/_types/core/ContractAddress.d.ts.map +1 -1
  140. package/_types/core/HdKey.d.ts +1 -1
  141. package/_types/core/HdKey.d.ts.map +1 -1
  142. package/_types/core/Hex.d.ts.map +1 -1
  143. package/_types/core/Keystore.d.ts.map +1 -1
  144. package/_types/core/Mnemonic.d.ts +1 -1
  145. package/_types/core/Mnemonic.d.ts.map +1 -1
  146. package/_types/core/P256.d.ts.map +1 -1
  147. package/_types/core/Provider.d.ts +2 -2
  148. package/_types/core/Provider.d.ts.map +1 -1
  149. package/_types/core/PublicKey.d.ts.map +1 -1
  150. package/_types/core/RpcRequest.d.ts +1 -1
  151. package/_types/core/RpcRequest.d.ts.map +1 -1
  152. package/_types/core/RpcTransport.d.ts +2 -2
  153. package/_types/core/RpcTransport.d.ts.map +1 -1
  154. package/_types/core/Secp256k1.d.ts +1 -1
  155. package/_types/core/Secp256k1.d.ts.map +1 -1
  156. package/_types/core/Signature.d.ts.map +1 -1
  157. package/_types/core/Siwe.d.ts.map +1 -1
  158. package/_types/core/Transaction.d.ts +1 -2
  159. package/_types/core/Transaction.d.ts.map +1 -1
  160. package/_types/core/TransactionEnvelope.d.ts.map +1 -1
  161. package/_types/core/TransactionEnvelopeEip1559.d.ts +1 -1
  162. package/_types/core/TransactionEnvelopeEip1559.d.ts.map +1 -1
  163. package/_types/core/TransactionEnvelopeEip2930.d.ts +1 -1
  164. package/_types/core/TransactionEnvelopeEip2930.d.ts.map +1 -1
  165. package/_types/core/TransactionEnvelopeEip4844.d.ts +1 -1
  166. package/_types/core/TransactionEnvelopeEip4844.d.ts.map +1 -1
  167. package/_types/core/TransactionEnvelopeEip7702.d.ts +1 -3
  168. package/_types/core/TransactionEnvelopeEip7702.d.ts.map +1 -1
  169. package/_types/core/TransactionEnvelopeLegacy.d.ts +1 -1
  170. package/_types/core/TransactionEnvelopeLegacy.d.ts.map +1 -1
  171. package/_types/core/TransactionReceipt.d.ts +1 -1
  172. package/_types/core/TransactionReceipt.d.ts.map +1 -1
  173. package/_types/core/TypedData.d.ts +1 -1
  174. package/_types/core/TypedData.d.ts.map +1 -1
  175. package/_types/core/WebAuthnP256.d.ts +2 -2
  176. package/_types/core/WebAuthnP256.d.ts.map +1 -1
  177. package/_types/core/WebCryptoP256.d.ts +1 -1
  178. package/_types/core/WebCryptoP256.d.ts.map +1 -1
  179. package/_types/core/internal/abiParameters.d.ts +1 -1
  180. package/_types/core/internal/abiParameters.d.ts.map +1 -1
  181. package/_types/core/internal/promise.d.ts.map +1 -1
  182. package/_types/core/internal/register.d.ts +1 -2
  183. package/_types/core/internal/register.d.ts.map +1 -1
  184. package/_types/erc4337/UserOperation.d.ts +1 -1
  185. package/_types/erc4337/UserOperation.d.ts.map +1 -1
  186. package/_types/erc6492/{WrappedSignature.d.ts → SignatureErc6492.d.ts} +26 -24
  187. package/_types/erc6492/SignatureErc6492.d.ts.map +1 -0
  188. package/_types/erc6492/index.d.ts +3 -3
  189. package/_types/erc8010/SignatureErc8010.d.ts +139 -0
  190. package/_types/erc8010/SignatureErc8010.d.ts.map +1 -0
  191. package/_types/erc8010/index.d.ts +42 -0
  192. package/_types/erc8010/index.d.ts.map +1 -0
  193. package/_types/index.d.ts +237 -237
  194. package/_types/index.d.ts.map +1 -1
  195. package/_types/index.docs.d.ts +1 -0
  196. package/_types/index.docs.d.ts.map +1 -1
  197. package/_types/trusted-setups/internal/paths.d.ts.map +1 -1
  198. package/_types/version.d.ts +1 -1
  199. package/core/AbiEvent.ts +3 -4
  200. package/core/AbiItem.ts +1 -1
  201. package/core/AbiParameters.ts +4 -4
  202. package/core/Authorization.ts +6 -6
  203. package/core/Blobs.ts +1 -1
  204. package/core/Block.ts +1 -1
  205. package/core/Bytes.ts +1 -1
  206. package/core/ContractAddress.ts +1 -1
  207. package/core/HdKey.ts +1 -1
  208. package/core/Hex.ts +1 -1
  209. package/core/Keystore.ts +3 -2
  210. package/core/Mnemonic.ts +1 -1
  211. package/core/P256.ts +1 -1
  212. package/core/Provider.ts +2 -2
  213. package/core/PublicKey.ts +2 -2
  214. package/core/RpcRequest.ts +1 -1
  215. package/core/RpcTransport.ts +3 -3
  216. package/core/Secp256k1.ts +2 -2
  217. package/core/Signature.ts +1 -1
  218. package/core/Siwe.ts +4 -5
  219. package/core/Transaction.ts +1 -2
  220. package/core/TransactionEnvelope.ts +1 -1
  221. package/core/TransactionEnvelopeEip1559.ts +3 -3
  222. package/core/TransactionEnvelopeEip2930.ts +3 -3
  223. package/core/TransactionEnvelopeEip4844.ts +5 -5
  224. package/core/TransactionEnvelopeEip7702.ts +6 -5
  225. package/core/TransactionEnvelopeLegacy.ts +3 -3
  226. package/core/TransactionReceipt.ts +1 -1
  227. package/core/TypedData.ts +4 -4
  228. package/core/WebAuthnP256.ts +2 -2
  229. package/core/WebCryptoP256.ts +1 -1
  230. package/core/internal/abiParameters.ts +5 -5
  231. package/core/internal/promise.ts +3 -1
  232. package/core/internal/register.ts +1 -2
  233. package/erc4337/UserOperation.ts +1 -1
  234. package/erc6492/SignatureErc6492/package.json +6 -0
  235. package/erc6492/{WrappedSignature.ts → SignatureErc6492.ts} +28 -25
  236. package/erc6492/index.ts +3 -3
  237. package/erc8010/SignatureErc8010/package.json +6 -0
  238. package/erc8010/SignatureErc8010.ts +235 -0
  239. package/erc8010/index.ts +43 -0
  240. package/erc8010/package.json +6 -0
  241. package/index.docs.ts +2 -0
  242. package/index.ts +237 -261
  243. package/package.json +15 -5
  244. package/trusted-setups/internal/paths.ts +1 -0
  245. package/version.ts +1 -1
  246. package/_cjs/erc6492/WrappedSignature.js.map +0 -1
  247. package/_types/erc6492/WrappedSignature.d.ts.map +0 -1
  248. package/erc6492/WrappedSignature/package.json +0 -6
@@ -5,8 +5,8 @@ import * as Errors from '../core/Errors.js'
5
5
  import * as Hex from '../core/Hex.js'
6
6
  import * as Signature from '../core/Signature.js'
7
7
 
8
- /** ERC-6492 Wrapped Signature. */
9
- export type WrappedSignature = {
8
+ /** Unwrapped ERC-6492 signature. */
9
+ export type Unwrapped = {
10
10
  /** Calldata to pass to the target address for counterfactual verification. */
11
11
  data: Hex.Hex
12
12
  /** The original signature. */
@@ -15,6 +15,9 @@ export type WrappedSignature = {
15
15
  to: Address.Address
16
16
  }
17
17
 
18
+ /** Wrapped ERC-6492 signature. */
19
+ export type Wrapped = Hex.Hex
20
+
18
21
  /**
19
22
  * Magic bytes used to identify ERC-6492 wrapped signatures.
20
23
  */
@@ -82,15 +85,15 @@ export const universalSignatureValidatorAbi = [
82
85
  *
83
86
  * @example
84
87
  * ```ts twoslash
85
- * import { WrappedSignature } from 'ox/erc6492'
88
+ * import { SignatureErc6492 } from 'ox/erc6492'
86
89
  *
87
- * WrappedSignature.assert('0xdeadbeef')
90
+ * SignatureErc6492.assert('0xdeadbeef')
88
91
  * // @error: InvalidWrappedSignatureError: Value `0xdeadbeef` is an invalid ERC-6492 wrapped signature.
89
92
  * ```
90
93
  *
91
94
  * @param wrapped - The wrapped signature to assert.
92
95
  */
93
- export function assert(wrapped: Hex.Hex) {
96
+ export function assert(wrapped: Wrapped) {
94
97
  if (Hex.slice(wrapped, -32) !== magicBytes)
95
98
  throw new InvalidWrappedSignatureError(wrapped)
96
99
  }
@@ -109,7 +112,7 @@ export declare namespace assert {
109
112
  * ```ts twoslash
110
113
  * // @noErrors
111
114
  * import { Secp256k1 } from 'ox'
112
- * import { WrappedSignature } from 'ox/erc6492' // [!code focus]
115
+ * import { SignatureErc6492 } from 'ox/erc6492' // [!code focus]
113
116
  *
114
117
  * const signature = Secp256k1.sign({
115
118
  * payload: '0x...',
@@ -117,11 +120,11 @@ export declare namespace assert {
117
120
  * })
118
121
  *
119
122
  * // Instantiate from serialized format. // [!code focus]
120
- * const wrapped = WrappedSignature.from('0x...') // [!code focus]
123
+ * const wrapped = SignatureErc6492.from('0x...') // [!code focus]
121
124
  * // @log: { data: '0x...', signature: { ... }, to: '0x...', } // [!code focus]
122
125
  *
123
126
  * // Instantiate from constituent parts. // [!code focus]
124
- * const wrapped = WrappedSignature.from({ // [!code focus]
127
+ * const wrapped = SignatureErc6492.from({ // [!code focus]
125
128
  * data: '0x...', // [!code focus]
126
129
  * signature, // [!code focus]
127
130
  * to: '0x...', // [!code focus]
@@ -132,13 +135,13 @@ export declare namespace assert {
132
135
  * @param wrapped - Wrapped signature to parse.
133
136
  * @returns Wrapped signature.
134
137
  */
135
- export function from(wrapped: WrappedSignature | Hex.Hex): WrappedSignature {
136
- if (typeof wrapped === 'string') return fromHex(wrapped)
138
+ export function from(wrapped: Unwrapped | Wrapped): Unwrapped {
139
+ if (typeof wrapped === 'string') return unwrap(wrapped)
137
140
  return wrapped
138
141
  }
139
142
 
140
143
  export declare namespace from {
141
- type ReturnType = WrappedSignature
144
+ type ReturnType = Unwrapped
142
145
 
143
146
  type ErrorType =
144
147
  | AbiParameters.from.ErrorType
@@ -152,15 +155,15 @@ export declare namespace from {
152
155
  *
153
156
  * @example
154
157
  * ```ts twoslash
155
- * import { WrappedSignature } from 'ox/erc6492'
158
+ * import { SignatureErc6492 } from 'ox/erc6492'
156
159
  *
157
- * const { data, signature, to } = WrappedSignature.fromHex('0x...')
160
+ * const { data, signature, to } = SignatureErc6492.unwrap('0x...')
158
161
  * ```
159
162
  *
160
163
  * @param wrapped - Wrapped signature to parse.
161
164
  * @returns Wrapped signature.
162
165
  */
163
- export function fromHex(wrapped: Hex.Hex): WrappedSignature {
166
+ export function unwrap(wrapped: Wrapped): Unwrapped {
164
167
  assert(wrapped)
165
168
 
166
169
  const [to, data, signature_hex] = AbiParameters.decode(
@@ -168,12 +171,12 @@ export function fromHex(wrapped: Hex.Hex): WrappedSignature {
168
171
  wrapped,
169
172
  )
170
173
 
171
- const signature = Signature.fromHex(signature_hex)
174
+ const signature = Signature.from(signature_hex)
172
175
 
173
176
  return { data, signature, to }
174
177
  }
175
178
 
176
- export declare namespace fromHex {
179
+ export declare namespace unwrap {
177
180
  type ErrorType =
178
181
  | AbiParameters.from.ErrorType
179
182
  | AbiParameters.decode.ErrorType
@@ -187,14 +190,14 @@ export declare namespace fromHex {
187
190
  * @example
188
191
  * ```ts twoslash
189
192
  * import { Secp256k1 } from 'ox'
190
- * import { WrappedSignature } from 'ox/erc6492' // [!code focus]
193
+ * import { SignatureErc6492 } from 'ox/erc6492' // [!code focus]
191
194
  *
192
195
  * const signature = Secp256k1.sign({
193
196
  * payload: '0x...',
194
197
  * privateKey: '0x...',
195
198
  * })
196
199
  *
197
- * const wrapped = WrappedSignature.toHex({ // [!code focus]
200
+ * const wrapped = SignatureErc6492.wrap({ // [!code focus]
198
201
  * data: '0xdeadbeef', // [!code focus]
199
202
  * signature, // [!code focus]
200
203
  * to: '0x00000000219ab540356cBB839Cbe05303d7705Fa', // [!code focus]
@@ -204,7 +207,7 @@ export declare namespace fromHex {
204
207
  * @param value - Wrapped signature to serialize.
205
208
  * @returns Serialized wrapped signature.
206
209
  */
207
- export function toHex(value: WrappedSignature): Hex.Hex {
210
+ export function wrap(value: Unwrapped): Wrapped {
208
211
  const { data, signature, to } = value
209
212
 
210
213
  return Hex.concat(
@@ -217,7 +220,7 @@ export function toHex(value: WrappedSignature): Hex.Hex {
217
220
  )
218
221
  }
219
222
 
220
- export declare namespace toHex {
223
+ export declare namespace wrap {
221
224
  type ErrorType =
222
225
  | AbiParameters.encode.ErrorType
223
226
  | Hex.concat.ErrorType
@@ -230,16 +233,16 @@ export declare namespace toHex {
230
233
  *
231
234
  * @example
232
235
  * ```ts twoslash
233
- * import { WrappedSignature } from 'ox/erc6492'
236
+ * import { SignatureErc6492 } from 'ox/erc6492'
234
237
  *
235
- * const valid = WrappedSignature.validate('0xdeadbeef')
238
+ * const valid = SignatureErc6492.validate('0xdeadbeef')
236
239
  * // @log: false
237
240
  * ```
238
241
  *
239
242
  * @param wrapped - The wrapped signature to validate.
240
243
  * @returns `true` if the wrapped signature is valid, `false` otherwise.
241
244
  */
242
- export function validate(wrapped: Hex.Hex): boolean {
245
+ export function validate(wrapped: Wrapped): boolean {
243
246
  try {
244
247
  assert(wrapped)
245
248
  return true
@@ -254,9 +257,9 @@ export declare namespace validate {
254
257
 
255
258
  /** Thrown when the ERC-6492 wrapped signature is invalid. */
256
259
  export class InvalidWrappedSignatureError extends Errors.BaseError {
257
- override readonly name = 'WrappedSignature.InvalidWrappedSignatureError'
260
+ override readonly name = 'SignatureErc6492.InvalidWrappedSignatureError'
258
261
 
259
- constructor(wrapped: Hex.Hex) {
262
+ constructor(wrapped: Wrapped) {
260
263
  super(`Value \`${wrapped}\` is an invalid ERC-6492 wrapped signature.`)
261
264
  }
262
265
  }
package/erc6492/index.ts CHANGED
@@ -8,14 +8,14 @@ export type {}
8
8
  * @example
9
9
  * ```ts twoslash
10
10
  * import { Secp256k1, PersonalMessage } from 'ox'
11
- * import { WrappedSignature } from 'ox/erc6492' // [!code focus]
11
+ * import { SignatureErc6492 } from 'ox/erc6492' // [!code focus]
12
12
  *
13
13
  * const signature = Secp256k1.sign({
14
14
  * payload: PersonalMessage.getSignPayload('0xdeadbeef'),
15
15
  * privateKey: '0x...',
16
16
  * })
17
17
  *
18
- * const wrapped = WrappedSignature.toHex({ // [!code focus]
18
+ * const wrapped = SignatureErc6492.wrap({ // [!code focus]
19
19
  * data: '0xcafebabe', // [!code focus]
20
20
  * signature, // [!code focus]
21
21
  * to: '0xcafebabecafebabecafebabecafebabecafebabe', // [!code focus]
@@ -25,4 +25,4 @@ export type {}
25
25
  *
26
26
  * @category ERC-6492
27
27
  */
28
- export * as WrappedSignature from './WrappedSignature.js'
28
+ export * as SignatureErc6492 from './SignatureErc6492.js'
@@ -0,0 +1,6 @@
1
+ {
2
+ "type": "module",
3
+ "types": "../../_types/erc8010/SignatureErc8010.d.ts",
4
+ "main": "../../_cjs/erc8010/SignatureErc8010.js",
5
+ "module": "../../_esm/erc8010/SignatureErc8010.js"
6
+ }
@@ -0,0 +1,235 @@
1
+ import * as AbiParameters from '../core/AbiParameters.js'
2
+ import * as Authorization from '../core/Authorization.js'
3
+ import * as Errors from '../core/Errors.js'
4
+ import * as Hex from '../core/Hex.js'
5
+ import * as Signature from '../core/Signature.js'
6
+
7
+ /** Unwrapped ERC-8010 signature. */
8
+ export type Unwrapped = {
9
+ /** Authorization signed by the delegatee. */
10
+ authorization: Authorization.Authorization<true>
11
+ /** Data to initialize the delegation. */
12
+ data?: Hex.Hex | undefined
13
+ /** The original signature. */
14
+ signature: Signature.Signature
15
+ }
16
+
17
+ /** Wrapped ERC-8010 signature. */
18
+ export type Wrapped = Hex.Hex
19
+
20
+ /**
21
+ * Magic bytes used to identify ERC-8010 wrapped signatures.
22
+ */
23
+ export const magicBytes =
24
+ '0x8010801080108010801080108010801080108010801080108010801080108010' as const
25
+
26
+ /**
27
+ * Asserts that the wrapped signature is valid.
28
+ *
29
+ * @example
30
+ * ```ts twoslash
31
+ * import { SignatureErc8010 } from 'ox/erc8010'
32
+ *
33
+ * SignatureErc8010.assert('0xdeadbeef')
34
+ * // @error: InvalidWrappedSignatureError: Value `0xdeadbeef` is an invalid ERC-8010 wrapped signature.
35
+ * ```
36
+ *
37
+ * @param value - The value to assert.
38
+ */
39
+ export function assert(value: Unwrapped | Wrapped) {
40
+ if (typeof value === 'string') {
41
+ if (Hex.slice(value, -32) !== magicBytes)
42
+ throw new InvalidWrappedSignatureError(value)
43
+ } else {
44
+ Signature.assert(value.authorization)
45
+ Signature.assert(value.signature)
46
+ }
47
+ }
48
+
49
+ export declare namespace assert {
50
+ type ErrorType =
51
+ | InvalidWrappedSignatureError
52
+ | Hex.slice.ErrorType
53
+ | Errors.GlobalErrorType
54
+ }
55
+
56
+ /**
57
+ * Parses an [ERC-8010 wrapped signature](https://github.com/jxom/ERCs/blob/16f7e3891fff2e1e9c25dea0485497739db8a816/ERCS/erc-8010.md) into its constituent parts.
58
+ *
59
+ * @example
60
+ * ```ts twoslash
61
+ * // @noErrors
62
+ * import { Secp256k1 } from 'ox'
63
+ * import { SignatureErc8010 } from 'ox/erc8010' // [!code focus]
64
+ *
65
+ * const signature = Secp256k1.sign({
66
+ * payload: '0x...',
67
+ * privateKey: '0x...',
68
+ * })
69
+ *
70
+ * // Instantiate from serialized format. // [!code focus]
71
+ * const wrapped = SignatureErc8010.from('0x...') // [!code focus]
72
+ * // @log: { authorization: { ... }, data: '0x...', signature: { ... } } // [!code focus]
73
+ *
74
+ * // Instantiate from constituent parts. // [!code focus]
75
+ * const wrapped = SignatureErc8010.from({ // [!code focus]
76
+ * authorization: { ... }, // [!code focus]
77
+ * data: '0x...', // [!code focus]
78
+ * signature, // [!code focus]
79
+ * })
80
+ * // @log: { authorization: { ... }, data: '0x...', signature: { ... } }
81
+ * ```
82
+ *
83
+ * @param value - Value to parse.
84
+ * @returns Parsed value.
85
+ */
86
+ export function from(value: Unwrapped | Wrapped): Unwrapped {
87
+ if (typeof value === 'string') return unwrap(value)
88
+ return value
89
+ }
90
+
91
+ export declare namespace from {
92
+ type ErrorType = unwrap.ErrorType | Errors.GlobalErrorType
93
+ }
94
+
95
+ /**
96
+ * Unwraps an [ERC-8010 wrapped signature](https://github.com/jxom/ERCs/blob/16f7e3891fff2e1e9c25dea0485497739db8a816/ERCS/erc-8010.md) into its constituent parts.
97
+ *
98
+ * @example
99
+ * ```ts twoslash
100
+ * import { SignatureErc8010 } from 'ox/erc8010'
101
+ *
102
+ * const { authorization, data, signature } = SignatureErc8010.unwrap('0x...')
103
+ * ```
104
+ *
105
+ * @param wrapped - Wrapped signature to unwrap.
106
+ * @returns Unwrapped signature.
107
+ */
108
+ export function unwrap(wrapped: Wrapped): Unwrapped {
109
+ assert(wrapped)
110
+
111
+ const suffixLength = Hex.toNumber(Hex.slice(wrapped, -64, -32))
112
+ const suffix = Hex.slice(wrapped, -suffixLength - 64, -64)
113
+ const signature = Signature.from(Hex.slice(wrapped, 0, -suffixLength - 64))
114
+
115
+ const chainId = Hex.toNumber(Hex.slice(suffix, 0, 32))
116
+ const delegation = Hex.slice(suffix, 32, 52)
117
+ const nonce = Hex.toBigInt(Hex.slice(suffix, 52, 84))
118
+ const yParity = Hex.toNumber(Hex.slice(suffix, 84, 85))
119
+ const r = Hex.toBigInt(Hex.slice(suffix, 85, 117))
120
+ const s = Hex.toBigInt(Hex.slice(suffix, 117, 149))
121
+
122
+ const authorization = Authorization.from({
123
+ address: delegation,
124
+ chainId,
125
+ nonce,
126
+ yParity,
127
+ r,
128
+ s,
129
+ })
130
+ const data = (() => {
131
+ try {
132
+ return Hex.slice(suffix, 149)
133
+ } catch {
134
+ return undefined
135
+ }
136
+ })()
137
+
138
+ return { authorization, data, signature }
139
+ }
140
+
141
+ export declare namespace unwrap {
142
+ type ErrorType = assert.ErrorType | Errors.GlobalErrorType
143
+ }
144
+
145
+ /**
146
+ * Wraps a signature into [ERC-8010 format](https://github.com/jxom/ERCs/blob/16f7e3891fff2e1e9c25dea0485497739db8a816/ERCS/erc-8010.md).
147
+ *
148
+ * @example
149
+ * ```ts twoslash
150
+ * // @noErrors
151
+ * import { Secp256k1 } from 'ox'
152
+ * import { SignatureErc8010 } from 'ox/erc8010' // [!code focus]
153
+ *
154
+ * const signature = Secp256k1.sign({
155
+ * payload: '0x...',
156
+ * privateKey: '0x...',
157
+ * })
158
+ *
159
+ * const wrapped = SignatureErc8010.wrap({ // [!code focus]
160
+ * authorization: { ... }, // [!code focus]
161
+ * data: '0xdeadbeef', // [!code focus]
162
+ * signature, // [!code focus]
163
+ * }) // [!code focus]
164
+ * ```
165
+ *
166
+ * @param value - Values to wrap.
167
+ * @returns Wrapped signature.
168
+ */
169
+ export function wrap(value: Unwrapped): Wrapped {
170
+ assert(value)
171
+
172
+ const { data, signature } = value
173
+ const authorization = AbiParameters.encodePacked(
174
+ ['uint256', 'address', 'uint256', 'uint8', 'uint256', 'uint256'],
175
+ [
176
+ BigInt(value.authorization.chainId),
177
+ value.authorization.address,
178
+ BigInt(value.authorization.nonce),
179
+ value.authorization.yParity,
180
+ value.authorization.r,
181
+ value.authorization.s,
182
+ ],
183
+ )
184
+ const suffix = AbiParameters.encodePacked(
185
+ ['bytes', 'bytes'],
186
+ [authorization, data ?? '0x'],
187
+ )
188
+ const suffixLength = Hex.fromNumber(Hex.size(suffix), { size: 32 })
189
+ return Hex.concat(
190
+ Signature.toHex(signature),
191
+ suffix,
192
+ suffixLength,
193
+ magicBytes,
194
+ )
195
+ }
196
+
197
+ export declare namespace wrap {
198
+ type ErrorType = Errors.GlobalErrorType
199
+ }
200
+
201
+ /**
202
+ * Validates a wrapped signature. Returns `true` if the wrapped signature is valid, `false` otherwise.
203
+ *
204
+ * @example
205
+ * ```ts twoslash
206
+ * import { SignatureErc8010 } from 'ox/erc8010'
207
+ *
208
+ * const valid = SignatureErc8010.validate('0xdeadbeef')
209
+ * // @log: false
210
+ * ```
211
+ *
212
+ * @param value - The value to validate.
213
+ * @returns `true` if the value is valid, `false` otherwise.
214
+ */
215
+ export function validate(value: Unwrapped | Wrapped): boolean {
216
+ try {
217
+ assert(value)
218
+ return true
219
+ } catch {
220
+ return false
221
+ }
222
+ }
223
+
224
+ export declare namespace validate {
225
+ type ErrorType = Errors.GlobalErrorType
226
+ }
227
+
228
+ /** Thrown when the ERC-8010 wrapped signature is invalid. */
229
+ export class InvalidWrappedSignatureError extends Errors.BaseError {
230
+ override readonly name = 'SignatureErc8010.InvalidWrappedSignatureError'
231
+
232
+ constructor(wrapped: Wrapped) {
233
+ super(`Value \`${wrapped}\` is an invalid ERC-8010 wrapped signature.`)
234
+ }
235
+ }
@@ -0,0 +1,43 @@
1
+ /** @entrypointCategory ERCs */
2
+ // biome-ignore lint/complexity/noUselessEmptyExport: tsdoc
3
+ export type {}
4
+
5
+ /**
6
+ * Utility functions for working with [ERC-8010 wrapped signatures](https://eips.ethereum.org/EIPS/eip-8010#specification).
7
+ *
8
+ * @example
9
+ * ```ts twoslash
10
+ * import { Authorization, Secp256k1, PersonalMessage } from 'ox'
11
+ * import { SignatureErc8010 } from 'ox/erc8010' // [!code focus]
12
+ *
13
+ * const authorization = Authorization.from({
14
+ * address: '0x1234567890abcdef1234567890abcdef12345678',
15
+ * chainId: 1,
16
+ * nonce: 69n,
17
+ * })
18
+ *
19
+ * const authorizationSignature = Secp256k1.sign({
20
+ * payload: Authorization.getSignPayload(authorization),
21
+ * privateKey: '0x...',
22
+ * })
23
+ *
24
+ * const authorizationSigned = Authorization.from(authorization, {
25
+ * signature: authorizationSignature,
26
+ * })
27
+ *
28
+ * const signature = Secp256k1.sign({
29
+ * payload: PersonalMessage.getSignPayload('0xdeadbeef'),
30
+ * privateKey: '0x...',
31
+ * })
32
+ *
33
+ * const wrapped = SignatureErc8010.wrap({ // [!code focus]
34
+ * authorization: authorizationSigned, // [!code focus]
35
+ * data: '0xcafebabe', // [!code focus]
36
+ * signature, // [!code focus]
37
+ * }) // [!code focus]
38
+ * // @log: '0x000000000000000000000000cafebabecafebabecafebabecafebabecafebabe000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000004deadbeef000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041fa78c5905fb0b9d6066ef531f962a62bc6ef0d5eb59ecb134056d206f75aaed7780926ff2601a935c2c79707d9e1799948c9f19dcdde1e090e903b19a07923d01c000000000000000000000000000000000000000000000000000000000000008010801080108010801080108010801080108010801080108010801080108010'
39
+ * ```
40
+ *
41
+ * @category ERC-8010
42
+ */
43
+ export * as SignatureErc8010 from './SignatureErc8010.js'
@@ -0,0 +1,6 @@
1
+ {
2
+ "type": "module",
3
+ "types": "../_types/erc8010/index.d.ts",
4
+ "main": "../_cjs/erc8010/index.js",
5
+ "module": "../_esm/erc8010/index.js"
6
+ }
package/index.docs.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  // @ts-nocheck
2
2
  /** Used by api-extractor for docgen. https://github.com/microsoft/rushstack/issues/3557 */
3
+ // biome-ignore assist/source/organizeImports: _
3
4
  export * from './index.js'
4
5
  export * from './erc4337/index.js'
5
6
  export * from './erc6492/index.js'
7
+ export * from './erc8010/index.js'