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