ox 0.9.16 → 0.10.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.
- package/CHANGELOG.md +27 -0
- package/README.md +4 -4
- package/TxEnvelope/package.json +6 -0
- package/TxEnvelopeEip1559/package.json +6 -0
- package/TxEnvelopeEip2930/package.json +6 -0
- package/TxEnvelopeEip4844/package.json +6 -0
- package/TxEnvelopeEip7702/package.json +6 -0
- package/TxEnvelopeLegacy/package.json +6 -0
- package/_cjs/core/{TransactionEnvelope.js → TxEnvelope.js} +1 -1
- package/_cjs/core/TxEnvelope.js.map +1 -0
- package/_cjs/core/{TransactionEnvelopeEip1559.js → TxEnvelopeEip1559.js} +2 -2
- package/_cjs/core/TxEnvelopeEip1559.js.map +1 -0
- package/_cjs/core/{TransactionEnvelopeEip2930.js → TxEnvelopeEip2930.js} +2 -2
- package/_cjs/core/TxEnvelopeEip2930.js.map +1 -0
- package/_cjs/core/{TransactionEnvelopeEip4844.js → TxEnvelopeEip4844.js} +4 -4
- package/_cjs/core/TxEnvelopeEip4844.js.map +1 -0
- package/_cjs/core/{TransactionEnvelopeEip7702.js → TxEnvelopeEip7702.js} +4 -4
- package/_cjs/core/TxEnvelopeEip7702.js.map +1 -0
- package/_cjs/core/{TransactionEnvelopeLegacy.js → TxEnvelopeLegacy.js} +2 -2
- package/_cjs/core/TxEnvelopeLegacy.js.map +1 -0
- package/_cjs/core/WebAuthnP256.js +1 -1
- package/_cjs/core/WebAuthnP256.js.map +1 -1
- package/_cjs/erc8021/Attribution.js +36 -6
- package/_cjs/erc8021/Attribution.js.map +1 -1
- package/_cjs/index.docs.js +1 -0
- package/_cjs/index.docs.js.map +1 -1
- package/_cjs/index.js +7 -7
- package/_cjs/index.js.map +1 -1
- package/_cjs/tempo/AuthorizationTempo.js +101 -0
- package/_cjs/tempo/AuthorizationTempo.js.map +1 -0
- package/_cjs/tempo/KeyAuthorization.js +123 -0
- package/_cjs/tempo/KeyAuthorization.js.map +1 -0
- package/_cjs/tempo/PoolId.js +10 -0
- package/_cjs/tempo/PoolId.js.map +1 -0
- package/_cjs/tempo/SignatureEnvelope.js +394 -0
- package/_cjs/tempo/SignatureEnvelope.js.map +1 -0
- package/_cjs/tempo/Tick.js +77 -0
- package/_cjs/tempo/Tick.js.map +1 -0
- package/_cjs/tempo/TokenId.js +28 -0
- package/_cjs/tempo/TokenId.js.map +1 -0
- package/_cjs/tempo/TokenRole.js +26 -0
- package/_cjs/tempo/TokenRole.js.map +1 -0
- package/_cjs/tempo/Transaction.js +80 -0
- package/_cjs/tempo/Transaction.js.map +1 -0
- package/_cjs/tempo/TransactionReceipt.js +26 -0
- package/_cjs/tempo/TransactionReceipt.js.map +1 -0
- package/_cjs/tempo/TransactionRequest.js +53 -0
- package/_cjs/tempo/TransactionRequest.js.map +1 -0
- package/_cjs/tempo/TxEnvelopeTempo.js +267 -0
- package/_cjs/tempo/TxEnvelopeTempo.js.map +1 -0
- package/_cjs/tempo/index.js +15 -0
- package/_cjs/tempo/index.js.map +1 -0
- package/_cjs/version.js +1 -1
- package/_esm/core/Blobs.js +8 -8
- package/_esm/core/{TransactionEnvelope.js → TxEnvelope.js} +11 -11
- package/_esm/core/TxEnvelope.js.map +1 -0
- package/_esm/core/{TransactionEnvelopeEip1559.js → TxEnvelopeEip1559.js} +42 -42
- package/_esm/core/TxEnvelopeEip1559.js.map +1 -0
- package/_esm/core/{TransactionEnvelopeEip2930.js → TxEnvelopeEip2930.js} +43 -43
- package/_esm/core/TxEnvelopeEip2930.js.map +1 -0
- package/_esm/core/{TransactionEnvelopeEip4844.js → TxEnvelopeEip4844.js} +42 -42
- package/_esm/core/TxEnvelopeEip4844.js.map +1 -0
- package/_esm/core/{TransactionEnvelopeEip7702.js → TxEnvelopeEip7702.js} +40 -40
- package/_esm/core/TxEnvelopeEip7702.js.map +1 -0
- package/_esm/core/{TransactionEnvelopeLegacy.js → TxEnvelopeLegacy.js} +42 -42
- package/_esm/core/TxEnvelopeLegacy.js.map +1 -0
- package/_esm/core/WebAuthnP256.js +1 -1
- package/_esm/core/WebAuthnP256.js.map +1 -1
- package/_esm/erc8021/Attribution.js +58 -13
- package/_esm/erc8021/Attribution.js.map +1 -1
- package/_esm/index.docs.js +1 -0
- package/_esm/index.docs.js.map +1 -1
- package/_esm/index.js +192 -192
- package/_esm/index.js.map +1 -1
- package/_esm/tempo/AuthorizationTempo.js +664 -0
- package/_esm/tempo/AuthorizationTempo.js.map +1 -0
- package/_esm/tempo/KeyAuthorization.js +426 -0
- package/_esm/tempo/KeyAuthorization.js.map +1 -0
- package/_esm/tempo/PoolId.js +28 -0
- package/_esm/tempo/PoolId.js.map +1 -0
- package/_esm/tempo/SignatureEnvelope.js +660 -0
- package/_esm/tempo/SignatureEnvelope.js.map +1 -0
- package/_esm/tempo/Tick.js +147 -0
- package/_esm/tempo/Tick.js.map +1 -0
- package/_esm/tempo/TokenId.js +71 -0
- package/_esm/tempo/TokenId.js.map +1 -0
- package/_esm/tempo/TokenRole.js +40 -0
- package/_esm/tempo/TokenRole.js.map +1 -0
- package/_esm/tempo/Transaction.js +167 -0
- package/_esm/tempo/Transaction.js.map +1 -0
- package/_esm/tempo/TransactionReceipt.js +138 -0
- package/_esm/tempo/TransactionReceipt.js.map +1 -0
- package/_esm/tempo/TransactionRequest.js +99 -0
- package/_esm/tempo/TransactionRequest.js.map +1 -0
- package/_esm/tempo/TxEnvelopeTempo.js +607 -0
- package/_esm/tempo/TxEnvelopeTempo.js.map +1 -0
- package/_esm/tempo/index.js +298 -0
- package/_esm/tempo/index.js.map +1 -0
- package/_esm/version.js +1 -1
- package/_types/core/Blobs.d.ts +8 -8
- package/_types/core/{TransactionEnvelope.d.ts → TxEnvelope.d.ts} +11 -11
- package/_types/core/TxEnvelope.d.ts.map +1 -0
- package/_types/core/{TransactionEnvelopeEip1559.d.ts → TxEnvelopeEip1559.d.ts} +54 -54
- package/_types/core/TxEnvelopeEip1559.d.ts.map +1 -0
- package/_types/core/{TransactionEnvelopeEip2930.d.ts → TxEnvelopeEip2930.d.ts} +55 -55
- package/_types/core/TxEnvelopeEip2930.d.ts.map +1 -0
- package/_types/core/{TransactionEnvelopeEip4844.d.ts → TxEnvelopeEip4844.d.ts} +54 -54
- package/_types/core/TxEnvelopeEip4844.d.ts.map +1 -0
- package/_types/core/{TransactionEnvelopeEip7702.d.ts → TxEnvelopeEip7702.d.ts} +49 -49
- package/_types/core/TxEnvelopeEip7702.d.ts.map +1 -0
- package/_types/core/{TransactionEnvelopeLegacy.d.ts → TxEnvelopeLegacy.d.ts} +54 -54
- package/_types/core/TxEnvelopeLegacy.d.ts.map +1 -0
- package/_types/core/WebAuthnP256.d.ts +1 -1
- package/_types/core/WebAuthnP256.d.ts.map +1 -1
- package/_types/erc8021/Attribution.d.ts +20 -6
- package/_types/erc8021/Attribution.d.ts.map +1 -1
- package/_types/index.d.ts +192 -192
- 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/tempo/AuthorizationTempo.d.ts +688 -0
- package/_types/tempo/AuthorizationTempo.d.ts.map +1 -0
- package/_types/tempo/KeyAuthorization.d.ts +437 -0
- package/_types/tempo/KeyAuthorization.d.ts.map +1 -0
- package/_types/tempo/PoolId.d.ts +33 -0
- package/_types/tempo/PoolId.d.ts.map +1 -0
- package/_types/tempo/SignatureEnvelope.d.ts +438 -0
- package/_types/tempo/SignatureEnvelope.d.ts.map +1 -0
- package/_types/tempo/Tick.d.ts +120 -0
- package/_types/tempo/Tick.d.ts.map +1 -0
- package/_types/tempo/TokenId.d.ts +55 -0
- package/_types/tempo/TokenId.d.ts.map +1 -0
- package/_types/tempo/TokenRole.d.ts +29 -0
- package/_types/tempo/TokenRole.d.ts.map +1 -0
- package/_types/tempo/Transaction.d.ts +208 -0
- package/_types/tempo/Transaction.d.ts.map +1 -0
- package/_types/tempo/TransactionReceipt.d.ts +165 -0
- package/_types/tempo/TransactionReceipt.d.ts.map +1 -0
- package/_types/tempo/TransactionRequest.d.ts +89 -0
- package/_types/tempo/TransactionRequest.d.ts.map +1 -0
- package/_types/tempo/TxEnvelopeTempo.d.ts +551 -0
- package/_types/tempo/TxEnvelopeTempo.d.ts.map +1 -0
- package/_types/tempo/index.d.ts +300 -0
- package/_types/tempo/index.d.ts.map +1 -0
- package/_types/version.d.ts +1 -1
- package/core/Blobs.ts +8 -8
- package/core/{TransactionEnvelope.ts → TxEnvelope.ts} +10 -10
- package/core/{TransactionEnvelopeEip1559.ts → TxEnvelopeEip1559.ts} +60 -69
- package/core/{TransactionEnvelopeEip2930.ts → TxEnvelopeEip2930.ts} +61 -72
- package/core/{TransactionEnvelopeEip4844.ts → TxEnvelopeEip4844.ts} +62 -71
- package/core/{TransactionEnvelopeEip7702.ts → TxEnvelopeEip7702.ts} +58 -67
- package/core/{TransactionEnvelopeLegacy.ts → TxEnvelopeLegacy.ts} +59 -68
- package/core/WebAuthnP256.ts +3 -1
- package/erc8021/Attribution.ts +77 -15
- package/index.docs.ts +1 -0
- package/index.ts +192 -195
- package/package.json +91 -31
- package/tempo/AuthorizationTempo/package.json +6 -0
- package/tempo/AuthorizationTempo.test.ts +1293 -0
- package/tempo/AuthorizationTempo.ts +884 -0
- package/tempo/KeyAuthorization/package.json +6 -0
- package/tempo/KeyAuthorization.test.ts +1373 -0
- package/tempo/KeyAuthorization.ts +622 -0
- package/tempo/PoolId/package.json +6 -0
- package/tempo/PoolId.test.ts +33 -0
- package/tempo/PoolId.ts +42 -0
- package/tempo/SignatureEnvelope/package.json +6 -0
- package/tempo/SignatureEnvelope.test.ts +1877 -0
- package/tempo/SignatureEnvelope.ts +973 -0
- package/tempo/Tick/package.json +6 -0
- package/tempo/Tick.test.ts +281 -0
- package/tempo/Tick.ts +186 -0
- package/tempo/TokenId/package.json +6 -0
- package/tempo/TokenId.test.ts +40 -0
- package/tempo/TokenId.ts +80 -0
- package/tempo/TokenRole/package.json +6 -0
- package/tempo/TokenRole.test.ts +16 -0
- package/tempo/TokenRole.ts +45 -0
- package/tempo/Transaction/package.json +6 -0
- package/tempo/Transaction.test.ts +523 -0
- package/tempo/Transaction.ts +339 -0
- package/tempo/TransactionReceipt/package.json +6 -0
- package/tempo/TransactionReceipt.ts +200 -0
- package/tempo/TransactionRequest/package.json +6 -0
- package/tempo/TransactionRequest.ts +160 -0
- package/tempo/TxEnvelopeTempo/package.json +6 -0
- package/tempo/TxEnvelopeTempo.test.ts +1371 -0
- package/tempo/TxEnvelopeTempo.ts +972 -0
- package/tempo/e2e.test.ts +1387 -0
- package/tempo/index.ts +308 -0
- package/tempo/package.json +6 -0
- package/version.ts +1 -1
- package/TransactionEnvelope/package.json +0 -6
- package/TransactionEnvelopeEip1559/package.json +0 -6
- package/TransactionEnvelopeEip2930/package.json +0 -6
- package/TransactionEnvelopeEip4844/package.json +0 -6
- package/TransactionEnvelopeEip7702/package.json +0 -6
- package/TransactionEnvelopeLegacy/package.json +0 -6
- package/_cjs/core/TransactionEnvelope.js.map +0 -1
- package/_cjs/core/TransactionEnvelopeEip1559.js.map +0 -1
- package/_cjs/core/TransactionEnvelopeEip2930.js.map +0 -1
- package/_cjs/core/TransactionEnvelopeEip4844.js.map +0 -1
- package/_cjs/core/TransactionEnvelopeEip7702.js.map +0 -1
- package/_cjs/core/TransactionEnvelopeLegacy.js.map +0 -1
- package/_esm/core/TransactionEnvelope.js.map +0 -1
- package/_esm/core/TransactionEnvelopeEip1559.js.map +0 -1
- package/_esm/core/TransactionEnvelopeEip2930.js.map +0 -1
- package/_esm/core/TransactionEnvelopeEip4844.js.map +0 -1
- package/_esm/core/TransactionEnvelopeEip7702.js.map +0 -1
- package/_esm/core/TransactionEnvelopeLegacy.js.map +0 -1
- package/_types/core/TransactionEnvelope.d.ts.map +0 -1
- package/_types/core/TransactionEnvelopeEip1559.d.ts.map +0 -1
- package/_types/core/TransactionEnvelopeEip2930.d.ts.map +0 -1
- package/_types/core/TransactionEnvelopeEip4844.d.ts.map +0 -1
- package/_types/core/TransactionEnvelopeEip7702.d.ts.map +0 -1
- package/_types/core/TransactionEnvelopeLegacy.d.ts.map +0 -1
|
@@ -11,9 +11,9 @@ import type {
|
|
|
11
11
|
} from './internal/types.js'
|
|
12
12
|
import * as Rlp from './Rlp.js'
|
|
13
13
|
import * as Signature from './Signature.js'
|
|
14
|
-
import * as TransactionEnvelope from './
|
|
14
|
+
import * as TransactionEnvelope from './TxEnvelope.js'
|
|
15
15
|
|
|
16
|
-
export type
|
|
16
|
+
export type TxEnvelopeLegacy<
|
|
17
17
|
signed extends boolean = boolean,
|
|
18
18
|
bigintType = bigint,
|
|
19
19
|
numberType = number,
|
|
@@ -28,7 +28,7 @@ export type TransactionEnvelopeLegacy<
|
|
|
28
28
|
}
|
|
29
29
|
>
|
|
30
30
|
|
|
31
|
-
export type Rpc<signed extends boolean = boolean> =
|
|
31
|
+
export type Rpc<signed extends boolean = boolean> = TxEnvelopeLegacy<
|
|
32
32
|
signed,
|
|
33
33
|
Hex.Hex,
|
|
34
34
|
Hex.Hex,
|
|
@@ -37,19 +37,19 @@ export type Rpc<signed extends boolean = boolean> = TransactionEnvelopeLegacy<
|
|
|
37
37
|
|
|
38
38
|
export type Serialized = Branded<`0x${string}`, 'legacy'>
|
|
39
39
|
|
|
40
|
-
export type Signed =
|
|
40
|
+
export type Signed = TxEnvelopeLegacy<true>
|
|
41
41
|
|
|
42
42
|
export const type = 'legacy'
|
|
43
43
|
export type Type = typeof type
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
|
-
* Asserts a {@link ox#
|
|
46
|
+
* Asserts a {@link ox#TxEnvelopeLegacy.TxEnvelopeLegacy} is valid.
|
|
47
47
|
*
|
|
48
48
|
* @example
|
|
49
49
|
* ```ts twoslash
|
|
50
|
-
* import {
|
|
50
|
+
* import { TxEnvelopeLegacy, Value } from 'ox'
|
|
51
51
|
*
|
|
52
|
-
*
|
|
52
|
+
* TxEnvelopeLegacy.assert({
|
|
53
53
|
* gasPrice: 2n ** 256n - 1n + 1n,
|
|
54
54
|
* chainId: 1,
|
|
55
55
|
* to: '0x0000000000000000000000000000000000000000',
|
|
@@ -62,7 +62,7 @@ export type Type = typeof type
|
|
|
62
62
|
*
|
|
63
63
|
* @param envelope - The transaction envelope to assert.
|
|
64
64
|
*/
|
|
65
|
-
export function assert(envelope: PartialBy<
|
|
65
|
+
export function assert(envelope: PartialBy<TxEnvelopeLegacy, 'type'>) {
|
|
66
66
|
const { chainId, gasPrice, to } = envelope
|
|
67
67
|
if (to) Address.assert(to, { strict: false })
|
|
68
68
|
if (typeof chainId !== 'undefined' && chainId <= 0)
|
|
@@ -80,13 +80,13 @@ export declare namespace assert {
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
/**
|
|
83
|
-
* Deserializes a {@link ox#
|
|
83
|
+
* Deserializes a {@link ox#TxEnvelopeLegacy.TxEnvelopeLegacy} from its serialized form.
|
|
84
84
|
*
|
|
85
85
|
* @example
|
|
86
86
|
* ```ts twoslash
|
|
87
|
-
* import {
|
|
87
|
+
* import { TxEnvelopeLegacy } from 'ox'
|
|
88
88
|
*
|
|
89
|
-
* const envelope =
|
|
89
|
+
* const envelope = TxEnvelopeLegacy.deserialize('0x01ef0182031184773594008477359400809470997970c51812dc3a010c7d01b50e0d17dc79c8880de0b6b3a764000080c0')
|
|
90
90
|
* // @log: {
|
|
91
91
|
* // @log: type: 'legacy',
|
|
92
92
|
* // @log: nonce: 785n,
|
|
@@ -100,9 +100,7 @@ export declare namespace assert {
|
|
|
100
100
|
* @param serialized - The serialized transaction.
|
|
101
101
|
* @returns Deserialized Transaction Envelope.
|
|
102
102
|
*/
|
|
103
|
-
export function deserialize(
|
|
104
|
-
serialized: Hex.Hex,
|
|
105
|
-
): Compute<TransactionEnvelopeLegacy> {
|
|
103
|
+
export function deserialize(serialized: Hex.Hex): Compute<TxEnvelopeLegacy> {
|
|
106
104
|
const tuple = Rlp.toHex(serialized)
|
|
107
105
|
|
|
108
106
|
const [nonce, gasPrice, gas, to, value, data, chainIdOrV_, r, s] =
|
|
@@ -131,7 +129,7 @@ export function deserialize(
|
|
|
131
129
|
|
|
132
130
|
const transaction = {
|
|
133
131
|
type,
|
|
134
|
-
} as
|
|
132
|
+
} as TxEnvelopeLegacy
|
|
135
133
|
if (Hex.validate(to) && to !== '0x') transaction.to = to
|
|
136
134
|
if (Hex.validate(gas) && gas !== '0x') transaction.gas = BigInt(gas)
|
|
137
135
|
if (Hex.validate(data) && data !== '0x') transaction.data = data
|
|
@@ -177,9 +175,9 @@ export declare namespace deserialize {
|
|
|
177
175
|
*
|
|
178
176
|
* @example
|
|
179
177
|
* ```ts twoslash
|
|
180
|
-
* import {
|
|
178
|
+
* import { TxEnvelopeLegacy, Value } from 'ox'
|
|
181
179
|
*
|
|
182
|
-
* const envelope =
|
|
180
|
+
* const envelope = TxEnvelopeLegacy.from({
|
|
183
181
|
* gasPrice: Value.fromGwei('10'),
|
|
184
182
|
* to: '0x0000000000000000000000000000000000000000',
|
|
185
183
|
* value: Value.fromEther('1'),
|
|
@@ -192,9 +190,9 @@ export declare namespace deserialize {
|
|
|
192
190
|
* It is possible to attach a `signature` to the transaction envelope.
|
|
193
191
|
*
|
|
194
192
|
* ```ts twoslash
|
|
195
|
-
* import { Secp256k1,
|
|
193
|
+
* import { Secp256k1, TxEnvelopeLegacy, Value } from 'ox'
|
|
196
194
|
*
|
|
197
|
-
* const envelope =
|
|
195
|
+
* const envelope = TxEnvelopeLegacy.from({
|
|
198
196
|
* chainId: 1,
|
|
199
197
|
* gasPrice: Value.fromGwei('10'),
|
|
200
198
|
* to: '0x0000000000000000000000000000000000000000',
|
|
@@ -202,11 +200,11 @@ export declare namespace deserialize {
|
|
|
202
200
|
* })
|
|
203
201
|
*
|
|
204
202
|
* const signature = Secp256k1.sign({
|
|
205
|
-
* payload:
|
|
203
|
+
* payload: TxEnvelopeLegacy.getSignPayload(envelope),
|
|
206
204
|
* privateKey: '0x...',
|
|
207
205
|
* })
|
|
208
206
|
*
|
|
209
|
-
* const envelope_signed =
|
|
207
|
+
* const envelope_signed = TxEnvelopeLegacy.from(envelope, { // [!code focus]
|
|
210
208
|
* signature, // [!code focus]
|
|
211
209
|
* }) // [!code focus]
|
|
212
210
|
* // @log: {
|
|
@@ -225,12 +223,12 @@ export declare namespace deserialize {
|
|
|
225
223
|
* @example
|
|
226
224
|
* ### From Serialized
|
|
227
225
|
*
|
|
228
|
-
* It is possible to instantiate an legacy Transaction Envelope from a {@link ox#
|
|
226
|
+
* It is possible to instantiate an legacy Transaction Envelope from a {@link ox#TxEnvelopeLegacy.Serialized} value.
|
|
229
227
|
*
|
|
230
228
|
* ```ts twoslash
|
|
231
|
-
* import {
|
|
229
|
+
* import { TxEnvelopeLegacy } from 'ox'
|
|
232
230
|
*
|
|
233
|
-
* const envelope =
|
|
231
|
+
* const envelope = TxEnvelopeLegacy.from('0xf858018203118502540be4008504a817c800809470997970c51812dc3a010c7d01b50e0d17dc79c8880de0b6b3a764000080c08477359400e1a001627c687261b0e7f8638af1112efa8a77e23656f6e7945275b19e9deed80261')
|
|
234
232
|
* // @log: {
|
|
235
233
|
* // @log: chainId: 1,
|
|
236
234
|
* // @log: gasPrice: 10000000000n,
|
|
@@ -245,22 +243,17 @@ export declare namespace deserialize {
|
|
|
245
243
|
* @returns A legacy Transaction Envelope.
|
|
246
244
|
*/
|
|
247
245
|
export function from<
|
|
248
|
-
const envelope extends
|
|
249
|
-
| UnionPartialBy<TransactionEnvelopeLegacy, 'type'>
|
|
250
|
-
| Hex.Hex,
|
|
246
|
+
const envelope extends UnionPartialBy<TxEnvelopeLegacy, 'type'> | Hex.Hex,
|
|
251
247
|
const signature extends Signature.Signature | undefined = undefined,
|
|
252
248
|
>(
|
|
253
|
-
envelope:
|
|
254
|
-
| envelope
|
|
255
|
-
| UnionPartialBy<TransactionEnvelopeLegacy, 'type'>
|
|
256
|
-
| Hex.Hex,
|
|
249
|
+
envelope: envelope | UnionPartialBy<TxEnvelopeLegacy, 'type'> | Hex.Hex,
|
|
257
250
|
options: from.Options<signature> = {},
|
|
258
251
|
): from.ReturnType<envelope, signature> {
|
|
259
252
|
const { signature } = options
|
|
260
253
|
|
|
261
254
|
const envelope_ = (
|
|
262
255
|
typeof envelope === 'string' ? deserialize(envelope) : envelope
|
|
263
|
-
) as
|
|
256
|
+
) as TxEnvelopeLegacy
|
|
264
257
|
|
|
265
258
|
assert(envelope_)
|
|
266
259
|
|
|
@@ -285,13 +278,13 @@ export declare namespace from {
|
|
|
285
278
|
}
|
|
286
279
|
|
|
287
280
|
type ReturnType<
|
|
288
|
-
envelope extends
|
|
289
|
-
|
|
|
290
|
-
| Hex.Hex
|
|
281
|
+
envelope extends UnionPartialBy<TxEnvelopeLegacy, 'type'> | Hex.Hex =
|
|
282
|
+
| TxEnvelopeLegacy
|
|
283
|
+
| Hex.Hex,
|
|
291
284
|
signature extends Signature.Signature | undefined = undefined,
|
|
292
285
|
> = Compute<
|
|
293
286
|
envelope extends Hex.Hex
|
|
294
|
-
?
|
|
287
|
+
? TxEnvelopeLegacy
|
|
295
288
|
: Assign<
|
|
296
289
|
envelope,
|
|
297
290
|
(signature extends Signature.Signature
|
|
@@ -313,7 +306,7 @@ export declare namespace from {
|
|
|
313
306
|
}
|
|
314
307
|
|
|
315
308
|
/**
|
|
316
|
-
* Returns the payload to sign for a {@link ox#
|
|
309
|
+
* Returns the payload to sign for a {@link ox#TxEnvelopeLegacy.TxEnvelopeLegacy}.
|
|
317
310
|
*
|
|
318
311
|
* @example
|
|
319
312
|
* The example below demonstrates how to compute the sign payload which can be used
|
|
@@ -321,9 +314,9 @@ export declare namespace from {
|
|
|
321
314
|
*
|
|
322
315
|
* ```ts twoslash
|
|
323
316
|
* // @noErrors
|
|
324
|
-
* import { Secp256k1,
|
|
317
|
+
* import { Secp256k1, TxEnvelopeLegacy } from 'ox'
|
|
325
318
|
*
|
|
326
|
-
* const envelope =
|
|
319
|
+
* const envelope = TxEnvelopeLegacy.from({
|
|
327
320
|
* nonce: 0n,
|
|
328
321
|
* gasPrice: 1000000000n,
|
|
329
322
|
* gas: 21000n,
|
|
@@ -331,7 +324,7 @@ export declare namespace from {
|
|
|
331
324
|
* value: 1000000000000000000n,
|
|
332
325
|
* })
|
|
333
326
|
*
|
|
334
|
-
* const payload =
|
|
327
|
+
* const payload = TxEnvelopeLegacy.getSignPayload(envelope) // [!code focus]
|
|
335
328
|
* // @log: '0x...'
|
|
336
329
|
*
|
|
337
330
|
* const signature = Secp256k1.sign({ payload, privateKey: '0x...' })
|
|
@@ -341,7 +334,7 @@ export declare namespace from {
|
|
|
341
334
|
* @returns The sign payload.
|
|
342
335
|
*/
|
|
343
336
|
export function getSignPayload(
|
|
344
|
-
envelope:
|
|
337
|
+
envelope: TxEnvelopeLegacy<false>,
|
|
345
338
|
): getSignPayload.ReturnType {
|
|
346
339
|
return hash(envelope, { presign: true })
|
|
347
340
|
}
|
|
@@ -353,13 +346,13 @@ export declare namespace getSignPayload {
|
|
|
353
346
|
}
|
|
354
347
|
|
|
355
348
|
/**
|
|
356
|
-
* Hashes a {@link ox#
|
|
349
|
+
* Hashes a {@link ox#TxEnvelopeLegacy.TxEnvelopeLegacy}. This is the "transaction hash".
|
|
357
350
|
*
|
|
358
351
|
* @example
|
|
359
352
|
* ```ts twoslash
|
|
360
|
-
* import { Secp256k1,
|
|
353
|
+
* import { Secp256k1, TxEnvelopeLegacy } from 'ox'
|
|
361
354
|
*
|
|
362
|
-
* const envelope =
|
|
355
|
+
* const envelope = TxEnvelopeLegacy.from({
|
|
363
356
|
* chainId: 1,
|
|
364
357
|
* nonce: 0n,
|
|
365
358
|
* gasPrice: 1000000000n,
|
|
@@ -369,13 +362,13 @@ export declare namespace getSignPayload {
|
|
|
369
362
|
* })
|
|
370
363
|
*
|
|
371
364
|
* const signature = Secp256k1.sign({
|
|
372
|
-
* payload:
|
|
365
|
+
* payload: TxEnvelopeLegacy.getSignPayload(envelope),
|
|
373
366
|
* privateKey: '0x...'
|
|
374
367
|
* })
|
|
375
368
|
*
|
|
376
|
-
* const envelope_signed =
|
|
369
|
+
* const envelope_signed = TxEnvelopeLegacy.from(envelope, { signature })
|
|
377
370
|
*
|
|
378
|
-
* const hash =
|
|
371
|
+
* const hash = TxEnvelopeLegacy.hash(envelope_signed) // [!code focus]
|
|
379
372
|
* ```
|
|
380
373
|
*
|
|
381
374
|
* @param envelope - The Legacy Transaction Envelope to hash.
|
|
@@ -383,7 +376,7 @@ export declare namespace getSignPayload {
|
|
|
383
376
|
* @returns The hash of the transaction envelope.
|
|
384
377
|
*/
|
|
385
378
|
export function hash<presign extends boolean = false>(
|
|
386
|
-
envelope:
|
|
379
|
+
envelope: TxEnvelopeLegacy<presign extends true ? false : true>,
|
|
387
380
|
options: hash.Options<presign> = {},
|
|
388
381
|
): hash.ReturnType {
|
|
389
382
|
const { presign } = options
|
|
@@ -417,21 +410,21 @@ export declare namespace hash {
|
|
|
417
410
|
}
|
|
418
411
|
|
|
419
412
|
/**
|
|
420
|
-
* Serializes a {@link ox#
|
|
413
|
+
* Serializes a {@link ox#TxEnvelopeLegacy.TxEnvelopeLegacy}.
|
|
421
414
|
*
|
|
422
415
|
* @example
|
|
423
416
|
* ```ts twoslash
|
|
424
417
|
* // @noErrors
|
|
425
|
-
* import {
|
|
418
|
+
* import { TxEnvelopeLegacy } from 'ox'
|
|
426
419
|
*
|
|
427
|
-
* const envelope =
|
|
420
|
+
* const envelope = TxEnvelopeLegacy.from({
|
|
428
421
|
* chainId: 1,
|
|
429
422
|
* gasPrice: Value.fromGwei('10'),
|
|
430
423
|
* to: '0x0000000000000000000000000000000000000000',
|
|
431
424
|
* value: Value.fromEther('1'),
|
|
432
425
|
* })
|
|
433
426
|
*
|
|
434
|
-
* const serialized =
|
|
427
|
+
* const serialized = TxEnvelopeLegacy.serialize(envelope) // [!code focus]
|
|
435
428
|
* ```
|
|
436
429
|
*
|
|
437
430
|
* @example
|
|
@@ -441,9 +434,9 @@ export declare namespace hash {
|
|
|
441
434
|
*
|
|
442
435
|
* ```ts twoslash
|
|
443
436
|
* // @noErrors
|
|
444
|
-
* import { Secp256k1,
|
|
437
|
+
* import { Secp256k1, TxEnvelopeLegacy, Value } from 'ox'
|
|
445
438
|
*
|
|
446
|
-
* const envelope =
|
|
439
|
+
* const envelope = TxEnvelopeLegacy.from({
|
|
447
440
|
* chainId: 1,
|
|
448
441
|
* gasPrice: Value.fromGwei('10'),
|
|
449
442
|
* to: '0x0000000000000000000000000000000000000000',
|
|
@@ -451,11 +444,11 @@ export declare namespace hash {
|
|
|
451
444
|
* })
|
|
452
445
|
*
|
|
453
446
|
* const signature = Secp256k1.sign({
|
|
454
|
-
* payload:
|
|
447
|
+
* payload: TxEnvelopeLegacy.getSignPayload(envelope),
|
|
455
448
|
* privateKey: '0x...',
|
|
456
449
|
* })
|
|
457
450
|
*
|
|
458
|
-
* const serialized =
|
|
451
|
+
* const serialized = TxEnvelopeLegacy.serialize(envelope, { // [!code focus]
|
|
459
452
|
* signature, // [!code focus]
|
|
460
453
|
* }) // [!code focus]
|
|
461
454
|
*
|
|
@@ -467,7 +460,7 @@ export declare namespace hash {
|
|
|
467
460
|
* @returns The serialized Transaction Envelope.
|
|
468
461
|
*/
|
|
469
462
|
export function serialize(
|
|
470
|
-
envelope: PartialBy<
|
|
463
|
+
envelope: PartialBy<TxEnvelopeLegacy, 'type'>,
|
|
471
464
|
options: serialize.Options = {},
|
|
472
465
|
): Serialized {
|
|
473
466
|
const { chainId = 0, gas, data, input, nonce, to, value, gasPrice } = envelope
|
|
@@ -547,13 +540,13 @@ export declare namespace serialize {
|
|
|
547
540
|
}
|
|
548
541
|
|
|
549
542
|
/**
|
|
550
|
-
* Converts an {@link ox#
|
|
543
|
+
* Converts an {@link ox#TxEnvelopeLegacy.TxEnvelopeLegacy} to an {@link ox#TxEnvelopeLegacy.Rpc}.
|
|
551
544
|
*
|
|
552
545
|
* @example
|
|
553
546
|
* ```ts twoslash
|
|
554
|
-
* import { RpcRequest,
|
|
547
|
+
* import { RpcRequest, TxEnvelopeLegacy, Value } from 'ox'
|
|
555
548
|
*
|
|
556
|
-
* const envelope =
|
|
549
|
+
* const envelope = TxEnvelopeLegacy.from({
|
|
557
550
|
* chainId: 1,
|
|
558
551
|
* nonce: 0n,
|
|
559
552
|
* gas: 21000n,
|
|
@@ -561,7 +554,7 @@ export declare namespace serialize {
|
|
|
561
554
|
* value: Value.fromEther('1'),
|
|
562
555
|
* })
|
|
563
556
|
*
|
|
564
|
-
* const envelope_rpc =
|
|
557
|
+
* const envelope_rpc = TxEnvelopeLegacy.toRpc(envelope) // [!code focus]
|
|
565
558
|
*
|
|
566
559
|
* const request = RpcRequest.from({
|
|
567
560
|
* id: 0,
|
|
@@ -573,7 +566,7 @@ export declare namespace serialize {
|
|
|
573
566
|
* @param envelope - The legacy transaction envelope to convert.
|
|
574
567
|
* @returns An RPC-formatted legacy transaction envelope.
|
|
575
568
|
*/
|
|
576
|
-
export function toRpc(envelope: Omit<
|
|
569
|
+
export function toRpc(envelope: Omit<TxEnvelopeLegacy, 'type'>): Rpc {
|
|
577
570
|
const signature = Signature.extract(envelope)!
|
|
578
571
|
|
|
579
572
|
return {
|
|
@@ -610,13 +603,13 @@ export declare namespace toRpc {
|
|
|
610
603
|
}
|
|
611
604
|
|
|
612
605
|
/**
|
|
613
|
-
* Validates a {@link ox#
|
|
606
|
+
* Validates a {@link ox#TxEnvelopeLegacy.TxEnvelopeLegacy}. Returns `true` if the envelope is valid, `false` otherwise.
|
|
614
607
|
*
|
|
615
608
|
* @example
|
|
616
609
|
* ```ts twoslash
|
|
617
|
-
* import {
|
|
610
|
+
* import { TxEnvelopeLegacy, Value } from 'ox'
|
|
618
611
|
*
|
|
619
|
-
* const valid =
|
|
612
|
+
* const valid = TxEnvelopeLegacy.assert({
|
|
620
613
|
* gasPrice: 2n ** 256n - 1n + 1n,
|
|
621
614
|
* chainId: 1,
|
|
622
615
|
* to: '0x0000000000000000000000000000000000000000',
|
|
@@ -627,9 +620,7 @@ export declare namespace toRpc {
|
|
|
627
620
|
*
|
|
628
621
|
* @param envelope - The transaction envelope to validate.
|
|
629
622
|
*/
|
|
630
|
-
export function validate(
|
|
631
|
-
envelope: PartialBy<TransactionEnvelopeLegacy, 'type'>,
|
|
632
|
-
) {
|
|
623
|
+
export function validate(envelope: PartialBy<TxEnvelopeLegacy, 'type'>) {
|
|
633
624
|
try {
|
|
634
625
|
assert(envelope)
|
|
635
626
|
return true
|
package/core/WebAuthnP256.ts
CHANGED
|
@@ -254,7 +254,8 @@ export function getCredentialCreationOptions(
|
|
|
254
254
|
publicKey: {
|
|
255
255
|
attestation,
|
|
256
256
|
authenticatorSelection,
|
|
257
|
-
challenge
|
|
257
|
+
challenge:
|
|
258
|
+
typeof challenge === 'string' ? Bytes.fromHex(challenge) : challenge,
|
|
258
259
|
...(excludeCredentialIds
|
|
259
260
|
? {
|
|
260
261
|
excludeCredentials: excludeCredentialIds?.map((id) => ({
|
|
@@ -301,6 +302,7 @@ export declare namespace getCredentialCreationOptions {
|
|
|
301
302
|
* An `ArrayBuffer`, `TypedArray`, or `DataView` used as a cryptographic challenge.
|
|
302
303
|
*/
|
|
303
304
|
challenge?:
|
|
305
|
+
| Hex.Hex
|
|
304
306
|
| internal.PublicKeyCredentialCreationOptions['challenge']
|
|
305
307
|
| undefined
|
|
306
308
|
/**
|
package/erc8021/Attribution.ts
CHANGED
|
@@ -31,12 +31,19 @@ export type AttributionSchemaId0 = {
|
|
|
31
31
|
export type AttributionSchemaId1 = {
|
|
32
32
|
/** Attribution codes identifying entities involved in the transaction. */
|
|
33
33
|
codes: readonly string[]
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
/* The custom code registry contract. */
|
|
35
|
+
codeRegistry: AttributionSchemaId1Registry
|
|
36
36
|
/** Schema identifier (1 for custom registry). */
|
|
37
37
|
id?: 1 | undefined
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
export type AttributionSchemaId1Registry = {
|
|
41
|
+
/** Address of the custom code registry contract. */
|
|
42
|
+
address: Address.Address
|
|
43
|
+
/** Chain Id of the chain the custom code registry contract is deployed on. */
|
|
44
|
+
chainId: number
|
|
45
|
+
}
|
|
46
|
+
|
|
40
47
|
/**
|
|
41
48
|
* Attribution schema identifier.
|
|
42
49
|
*
|
|
@@ -71,7 +78,10 @@ export const ercSuffixSize = /*#__PURE__*/ Hex.size(ercSuffix)
|
|
|
71
78
|
*
|
|
72
79
|
* const schemaId2 = Attribution.getSchemaId({
|
|
73
80
|
* codes: ['baseapp'],
|
|
74
|
-
*
|
|
81
|
+
* codeRegistry: {
|
|
82
|
+
* address: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
|
|
83
|
+
* chainId: 8453,
|
|
84
|
+
* }
|
|
75
85
|
* })
|
|
76
86
|
* // @log: 1
|
|
77
87
|
* ```
|
|
@@ -80,7 +90,7 @@ export const ercSuffixSize = /*#__PURE__*/ Hex.size(ercSuffix)
|
|
|
80
90
|
* @returns The schema ID (0 for canonical registry, 1 for custom registry).
|
|
81
91
|
*/
|
|
82
92
|
export function getSchemaId(attribution: Attribution): SchemaId {
|
|
83
|
-
if ('
|
|
93
|
+
if ('codeRegistry' in attribution) return 1
|
|
84
94
|
return 0
|
|
85
95
|
}
|
|
86
96
|
|
|
@@ -111,7 +121,10 @@ export declare namespace getSchemaId {
|
|
|
111
121
|
*
|
|
112
122
|
* const suffix = Attribution.toDataSuffix({
|
|
113
123
|
* codes: ['baseapp'],
|
|
114
|
-
*
|
|
124
|
+
* codeRegistry: {
|
|
125
|
+
* address: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
|
|
126
|
+
* chainId: 8453,
|
|
127
|
+
* }
|
|
115
128
|
* })
|
|
116
129
|
* ```
|
|
117
130
|
*
|
|
@@ -133,15 +146,17 @@ export function toDataSuffix(attribution: Attribution): Hex.Hex {
|
|
|
133
146
|
const schemaIdHex = Hex.fromNumber(schemaId, { size: 1 })
|
|
134
147
|
|
|
135
148
|
// Build the suffix based on schema
|
|
136
|
-
if (schemaId === 1)
|
|
137
|
-
|
|
149
|
+
if (schemaId === 1) {
|
|
150
|
+
const schema1 = attribution as AttributionSchemaId1
|
|
151
|
+
// Schema 1: codeRegistryAddress (20 bytes) ∥ chainId ∥ chainIdLength (1 byte) ∥ codes ∥ codesLength (1 byte) ∥ schemaId (1 byte) ∥ ercSuffix
|
|
138
152
|
return Hex.concat(
|
|
139
|
-
|
|
153
|
+
registryToData(schema1.codeRegistry),
|
|
140
154
|
codesHex,
|
|
141
155
|
codesLengthHex,
|
|
142
156
|
schemaIdHex,
|
|
143
157
|
ercSuffix,
|
|
144
158
|
)
|
|
159
|
+
}
|
|
145
160
|
|
|
146
161
|
// Schema 0: codes ∥ codesLength ∥ schemaId ∥ ercSuffix
|
|
147
162
|
return Hex.concat(codesHex, codesLengthHex, schemaIdHex, ercSuffix)
|
|
@@ -179,11 +194,14 @@ export declare namespace toDataSuffix {
|
|
|
179
194
|
* import { Attribution } from 'ox/erc8021'
|
|
180
195
|
*
|
|
181
196
|
* const attribution = Attribution.fromData(
|
|
182
|
-
* '
|
|
197
|
+
* '0xddddddddcccccccccccccccccccccccccccccccccccccccc210502626173656170702C6D6F7270686F0E0180218021802180218021802180218021'
|
|
183
198
|
* )
|
|
184
199
|
* // @log: {
|
|
185
200
|
* // @log: codes: ['baseapp', 'morpho'],
|
|
186
|
-
* // @log:
|
|
201
|
+
* // @log: registry: {
|
|
202
|
+
* // @log: address: '0xcccccccccccccccccccccccccccccccccccccccc`
|
|
203
|
+
* // @log: chainId: 8453,
|
|
204
|
+
* // @log: }
|
|
187
205
|
* // @log: id: 1
|
|
188
206
|
* // @log: }
|
|
189
207
|
* ```
|
|
@@ -225,7 +243,7 @@ export function fromData(data: Hex.Hex): Attribution | undefined {
|
|
|
225
243
|
}
|
|
226
244
|
|
|
227
245
|
// Schema 1: Custom registry
|
|
228
|
-
// Format: codeRegistryAddress (20 bytes) ∥ codes ∥ codesLength (1 byte) ∥ schemaId (1 byte) ∥ ercSuffix
|
|
246
|
+
// Format: codeRegistryAddress (20 bytes) ∥ chainId ∥ chainIdLength (1 byte) ∥ codes ∥ codesLength (1 byte) ∥ schemaId (1 byte) ∥ ercSuffix
|
|
229
247
|
if (schemaId === 1) {
|
|
230
248
|
// Extract codes length (1 byte before schema ID)
|
|
231
249
|
const codesLengthHex = Hex.slice(
|
|
@@ -242,13 +260,13 @@ export function fromData(data: Hex.Hex): Attribution | undefined {
|
|
|
242
260
|
const codesString = Hex.toString(codesHex)
|
|
243
261
|
const codes = codesString.length > 0 ? codesString.split(',') : []
|
|
244
262
|
|
|
245
|
-
// Extract registry
|
|
246
|
-
const
|
|
247
|
-
|
|
263
|
+
// Extract registry by reading backwards from just before codes
|
|
264
|
+
const codeRegistry = registryFromData(Hex.slice(data, 0, codesStart))
|
|
265
|
+
if (codeRegistry === undefined) return undefined
|
|
248
266
|
|
|
249
267
|
return {
|
|
250
268
|
codes,
|
|
251
|
-
|
|
269
|
+
codeRegistry,
|
|
252
270
|
id: 1,
|
|
253
271
|
}
|
|
254
272
|
}
|
|
@@ -257,6 +275,50 @@ export function fromData(data: Hex.Hex): Attribution | undefined {
|
|
|
257
275
|
return undefined
|
|
258
276
|
}
|
|
259
277
|
|
|
278
|
+
function registryFromData(
|
|
279
|
+
data: Hex.Hex,
|
|
280
|
+
): AttributionSchemaId1Registry | undefined {
|
|
281
|
+
// Expect at least: address (20 bytes) + chainIdLen (1 byte)
|
|
282
|
+
const minRegistrySize = 20 + 1
|
|
283
|
+
if (Hex.size(data) < minRegistrySize) return undefined
|
|
284
|
+
|
|
285
|
+
// Read chainId length from the last byte of the registry segment
|
|
286
|
+
const chainIdLenHex = Hex.slice(data, -1)
|
|
287
|
+
const chainIdLen = Hex.toNumber(chainIdLenHex)
|
|
288
|
+
|
|
289
|
+
if (chainIdLen === 0) return undefined
|
|
290
|
+
|
|
291
|
+
// Validate we have enough bytes to cover address + chainId + chainIdLen
|
|
292
|
+
const totalRegistrySize = 20 + chainIdLen + 1
|
|
293
|
+
if (Hex.size(data) < totalRegistrySize) return undefined
|
|
294
|
+
|
|
295
|
+
// Address is located immediately before chainId and chainIdLen (read from back)
|
|
296
|
+
const addressStart = -(chainIdLen + 1 + 20)
|
|
297
|
+
const addressEnd = -(chainIdLen + 1)
|
|
298
|
+
const addressHex = Hex.slice(data, addressStart, addressEnd)
|
|
299
|
+
// Chain ID occupies the bytes preceding the final length byte (read from back)
|
|
300
|
+
const chainIdHex = Hex.slice(data, -(chainIdLen + 1), -1)
|
|
301
|
+
|
|
302
|
+
const codeRegistry: AttributionSchemaId1Registry = {
|
|
303
|
+
address: addressHex as Address.Address,
|
|
304
|
+
chainId: Hex.toNumber(chainIdHex),
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
return codeRegistry
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function registryToData(registry: AttributionSchemaId1Registry): Hex.Hex {
|
|
311
|
+
const chainIdAsHex = Hex.fromNumber(registry.chainId)
|
|
312
|
+
const chainIdLen = Hex.size(chainIdAsHex)
|
|
313
|
+
// Need to padleft because the output of size may not be a full byte (1 -> 0x1 vs 0x01)
|
|
314
|
+
const paddedChainId = Hex.padLeft(chainIdAsHex, chainIdLen)
|
|
315
|
+
return Hex.concat(
|
|
316
|
+
registry.address as Hex.Hex,
|
|
317
|
+
paddedChainId,
|
|
318
|
+
Hex.fromNumber(chainIdLen, { size: 1 }),
|
|
319
|
+
)
|
|
320
|
+
}
|
|
321
|
+
|
|
260
322
|
export declare namespace fromData {
|
|
261
323
|
type ErrorType =
|
|
262
324
|
| Hex.slice.ErrorType
|
package/index.docs.ts
CHANGED