ox 1.8.5 → 1.8.7
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 +37 -0
- package/dist/tempo/{MultisigConfig.d.ts → AccountConfig.d.ts} +116 -63
- package/dist/tempo/AccountConfig.d.ts.map +1 -0
- package/dist/tempo/{MultisigConfig.js → AccountConfig.js} +109 -55
- package/dist/tempo/AccountConfig.js.map +1 -0
- package/dist/tempo/{MultisigOperation.d.ts → AccountOperation.d.ts} +62 -62
- package/dist/tempo/AccountOperation.d.ts.map +1 -0
- package/dist/tempo/{MultisigOperation.js → AccountOperation.js} +64 -64
- package/dist/tempo/AccountOperation.js.map +1 -0
- package/dist/tempo/{MultisigSimulation.d.ts → AccountSimulation.d.ts} +21 -21
- package/dist/tempo/AccountSimulation.d.ts.map +1 -0
- package/dist/tempo/{MultisigSimulation.js → AccountSimulation.js} +20 -20
- package/dist/tempo/AccountSimulation.js.map +1 -0
- package/dist/tempo/KeyAuthorization.d.ts +37 -27
- package/dist/tempo/KeyAuthorization.d.ts.map +1 -1
- package/dist/tempo/KeyAuthorization.js +17 -19
- package/dist/tempo/KeyAuthorization.js.map +1 -1
- package/dist/tempo/RpcSchemaTempo.d.ts +13 -13
- package/dist/tempo/RpcSchemaTempo.d.ts.map +1 -1
- package/dist/tempo/SignatureEnvelope.d.ts +36 -33
- package/dist/tempo/SignatureEnvelope.d.ts.map +1 -1
- package/dist/tempo/SignatureEnvelope.js +77 -77
- package/dist/tempo/SignatureEnvelope.js.map +1 -1
- package/dist/tempo/TokenRole.d.ts +4 -2
- package/dist/tempo/TokenRole.d.ts.map +1 -1
- package/dist/tempo/TokenRole.js +4 -1
- package/dist/tempo/TokenRole.js.map +1 -1
- package/dist/tempo/TransactionRequest.d.ts +11 -9
- package/dist/tempo/TransactionRequest.d.ts.map +1 -1
- package/dist/tempo/TransactionRequest.js +14 -10
- package/dist/tempo/TransactionRequest.js.map +1 -1
- package/dist/tempo/index.d.ts +56 -54
- package/dist/tempo/index.d.ts.map +1 -1
- package/dist/tempo/index.js +56 -54
- package/dist/tempo/index.js.map +1 -1
- package/dist/zod/tempo/{MultisigConfig.d.ts → AccountConfig.d.ts} +6 -6
- package/dist/zod/tempo/AccountConfig.d.ts.map +1 -0
- package/dist/zod/tempo/{MultisigConfig.js → AccountConfig.js} +12 -12
- package/dist/zod/tempo/AccountConfig.js.map +1 -0
- package/dist/zod/tempo/{MultisigOperation.d.ts → AccountOperation.d.ts} +5 -5
- package/dist/zod/tempo/AccountOperation.d.ts.map +1 -0
- package/dist/zod/tempo/{MultisigOperation.js → AccountOperation.js} +10 -10
- package/dist/zod/tempo/AccountOperation.js.map +1 -0
- package/dist/zod/tempo/{MultisigSimulation.d.ts → AccountSimulation.d.ts} +5 -5
- package/dist/zod/tempo/AccountSimulation.d.ts.map +1 -0
- package/dist/zod/tempo/AccountSimulation.js +44 -0
- package/dist/zod/tempo/AccountSimulation.js.map +1 -0
- package/dist/zod/tempo/AuthorizationTempo.d.ts +10 -10
- package/dist/zod/tempo/KeyAuthorization.d.ts +12 -12
- package/dist/zod/tempo/KeyAuthorization.js +6 -6
- package/dist/zod/tempo/KeyAuthorization.js.map +1 -1
- package/dist/zod/tempo/RpcSchemaTempo.d.ts +59 -59
- package/dist/zod/tempo/RpcSchemaTempo.d.ts.map +1 -1
- package/dist/zod/tempo/RpcSchemaTempo.js +28 -28
- package/dist/zod/tempo/RpcSchemaTempo.js.map +1 -1
- package/dist/zod/tempo/SignatureEnvelope.d.ts +7 -7
- package/dist/zod/tempo/SignatureEnvelope.d.ts.map +1 -1
- package/dist/zod/tempo/SignatureEnvelope.js +22 -16
- package/dist/zod/tempo/SignatureEnvelope.js.map +1 -1
- package/dist/zod/tempo/TokenRole.d.ts +1 -1
- package/dist/zod/tempo/TokenRole.d.ts.map +1 -1
- package/dist/zod/tempo/Transaction.d.ts +24 -24
- package/dist/zod/tempo/TransactionRequest.d.ts +84 -84
- package/dist/zod/tempo/TransactionRequest.d.ts.map +1 -1
- package/dist/zod/tempo/TransactionRequest.js +26 -17
- package/dist/zod/tempo/TransactionRequest.js.map +1 -1
- package/dist/zod/tempo/TxEnvelopeTempo.d.ts +12 -12
- package/dist/zod/tempo/ZoneRpcAuthentication.d.ts +3 -3
- package/dist/zod/tempo/z.d.ts +3 -3
- package/dist/zod/tempo/z.d.ts.map +1 -1
- package/dist/zod/tempo/z.js +3 -3
- package/dist/zod/tempo/z.js.map +1 -1
- package/package.json +31 -31
- package/src/tempo/{MultisigConfig.test-d.ts → AccountConfig.test-d.ts} +22 -12
- package/src/tempo/{MultisigConfig.test.ts → AccountConfig.test.ts} +155 -37
- package/src/tempo/{MultisigConfig.ts → AccountConfig.ts} +138 -66
- package/src/tempo/AccountOperation.test-d.ts +79 -0
- package/src/tempo/{MultisigOperation.test.ts → AccountOperation.test.ts} +97 -97
- package/src/tempo/{MultisigOperation.ts → AccountOperation.ts} +95 -97
- package/src/tempo/{MultisigSimulation.test-d.ts → AccountSimulation.test-d.ts} +7 -9
- package/src/tempo/{MultisigSimulation.test.ts → AccountSimulation.test.ts} +28 -28
- package/src/tempo/{MultisigSimulation.ts → AccountSimulation.ts} +28 -30
- package/src/tempo/KeyAuthorization.test-d.ts +15 -6
- package/src/tempo/KeyAuthorization.test.ts +117 -37
- package/src/tempo/KeyAuthorization.ts +68 -59
- package/src/tempo/RpcSchemaTempo.test-d.ts +19 -19
- package/src/tempo/RpcSchemaTempo.ts +13 -13
- package/src/tempo/SignatureEnvelope.test-d.ts +7 -7
- package/src/tempo/SignatureEnvelope.test.ts +34 -34
- package/src/tempo/SignatureEnvelope.ts +112 -108
- package/src/tempo/TokenRole.ts +4 -1
- package/src/tempo/Transaction.test.ts +4 -4
- package/src/tempo/TransactionRequest.test-d.ts +17 -6
- package/src/tempo/TransactionRequest.test.ts +32 -17
- package/src/tempo/TransactionRequest.ts +27 -19
- package/src/tempo/{multisig.e2e.test.ts → configurableAccounts.e2e.test.ts} +16 -16
- package/src/tempo/e2e.test.ts +32 -20
- package/src/tempo/index.ts +56 -54
- package/src/version.ts +1 -1
- package/src/zod/tempo/{MultisigConfig.ts → AccountConfig.ts} +12 -12
- package/src/zod/tempo/{MultisigOperation.ts → AccountOperation.ts} +9 -9
- package/src/zod/tempo/AccountSimulation.ts +53 -0
- package/src/zod/tempo/KeyAuthorization.ts +8 -8
- package/src/zod/tempo/RpcSchemaTempo.ts +28 -28
- package/src/zod/tempo/SignatureEnvelope.ts +23 -17
- package/src/zod/tempo/TransactionRequest.ts +29 -18
- package/src/zod/tempo/_test/AccountConfig.test-d.ts +13 -0
- package/src/zod/tempo/_test/{MultisigConfig.test.ts → AccountConfig.test.ts} +7 -7
- package/src/zod/tempo/_test/AccountOperation.test-d.ts +27 -0
- package/src/zod/tempo/_test/{MultisigOperation.test.ts → AccountOperation.test.ts} +9 -9
- package/src/zod/tempo/_test/AccountSimulation.test-d.ts +13 -0
- package/src/zod/tempo/_test/{MultisigSimulation.test.ts → AccountSimulation.test.ts} +13 -13
- package/src/zod/tempo/_test/KeyAuthorization.test.ts +9 -9
- package/src/zod/tempo/_test/RpcSchemaTempo.test-d.ts +27 -27
- package/src/zod/tempo/_test/RpcSchemaTempo.test.ts +16 -18
- package/src/zod/tempo/_test/SignatureEnvelope.test-d.ts +5 -5
- package/src/zod/tempo/_test/SignatureEnvelope.test.ts +12 -9
- package/src/zod/tempo/_test/TransactionRequest.test.ts +28 -8
- package/src/zod/tempo/z.ts +3 -3
- package/dist/tempo/MultisigConfig.d.ts.map +0 -1
- package/dist/tempo/MultisigConfig.js.map +0 -1
- package/dist/tempo/MultisigOperation.d.ts.map +0 -1
- package/dist/tempo/MultisigOperation.js.map +0 -1
- package/dist/tempo/MultisigSimulation.d.ts.map +0 -1
- package/dist/tempo/MultisigSimulation.js.map +0 -1
- package/dist/zod/tempo/MultisigConfig.d.ts.map +0 -1
- package/dist/zod/tempo/MultisigConfig.js.map +0 -1
- package/dist/zod/tempo/MultisigOperation.d.ts.map +0 -1
- package/dist/zod/tempo/MultisigOperation.js.map +0 -1
- package/dist/zod/tempo/MultisigSimulation.d.ts.map +0 -1
- package/dist/zod/tempo/MultisigSimulation.js +0 -44
- package/dist/zod/tempo/MultisigSimulation.js.map +0 -1
- package/src/tempo/MultisigOperation.test-d.ts +0 -79
- package/src/zod/tempo/MultisigSimulation.ts +0 -53
- package/src/zod/tempo/_test/MultisigConfig.test-d.ts +0 -13
- package/src/zod/tempo/_test/MultisigOperation.test-d.ts +0 -27
- package/src/zod/tempo/_test/MultisigSimulation.test-d.ts +0 -13
|
@@ -9,39 +9,44 @@ import type { Compute } from '../core/internal/types.js'
|
|
|
9
9
|
/** Maximum encoded byte length for one primitive owner approval. */
|
|
10
10
|
export const maxOwnerSignatureBytes = 2049
|
|
11
11
|
|
|
12
|
-
/** Maximum number of owners allowed in
|
|
12
|
+
/** Maximum number of owners allowed in an account config. */
|
|
13
13
|
export const maxOwners = 48
|
|
14
14
|
|
|
15
|
-
/** Maximum number of owner approvals in a
|
|
15
|
+
/** Maximum number of owner approvals in a configurable account signature. */
|
|
16
16
|
export const maxSignatures = 8
|
|
17
17
|
|
|
18
|
-
/**
|
|
19
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Maximum threshold accepted by an account config.
|
|
20
|
+
*
|
|
21
|
+
* The threshold must also be reachable by at most {@link ox#AccountConfig.maxSignatures}
|
|
22
|
+
* owner approvals.
|
|
23
|
+
*/
|
|
24
|
+
export const maxThreshold = 0xff
|
|
20
25
|
|
|
21
|
-
/** Maximum version accepted by
|
|
26
|
+
/** Maximum version accepted by an account config. */
|
|
22
27
|
export const maxVersion = 2n ** 64n - 1n
|
|
23
28
|
|
|
24
|
-
/** Tempo signature type byte for
|
|
29
|
+
/** Tempo signature type byte for configurable account signatures. */
|
|
25
30
|
export const signatureTypeByte = '0x05' as const
|
|
26
31
|
|
|
27
32
|
/** Zero 32-byte salt (the default when no salt is provided). */
|
|
28
33
|
export const zeroSalt = `0x${'00'.repeat(32)}` as const
|
|
29
34
|
|
|
30
|
-
/** Domain prefix for the
|
|
35
|
+
/** Domain prefix for the configurable account address derivation. */
|
|
31
36
|
const accountDomain = 'tempo:multisig:account'
|
|
32
37
|
|
|
33
|
-
/** Domain prefix for
|
|
38
|
+
/** Domain prefix for account configuration commitments. */
|
|
34
39
|
const configDomain = 'tempo:multisig:config'
|
|
35
40
|
|
|
36
41
|
/** Keccak-256 of the canonical recovery wallet creation code. */
|
|
37
42
|
const recoveryWalletInitCodeHash =
|
|
38
43
|
'0x583cc63a2e37f645b43eac911b1a6d6de08b83abdc308c61364edda8cfc3bd37'
|
|
39
44
|
|
|
40
|
-
/** Domain prefix for
|
|
45
|
+
/** Domain prefix for configurable account owner approvals. */
|
|
41
46
|
const signatureDomain = 'tempo:multisig:signature'
|
|
42
47
|
|
|
43
48
|
/**
|
|
44
|
-
* Complete
|
|
49
|
+
* Complete account configuration witness.
|
|
45
50
|
*/
|
|
46
51
|
export type Config<bigintType = bigint, numberType = number> = Compute<{
|
|
47
52
|
/** Weighted owner list, strictly ascending by owner address. */
|
|
@@ -54,7 +59,7 @@ export type Config<bigintType = bigint, numberType = number> = Compute<{
|
|
|
54
59
|
version: bigintType
|
|
55
60
|
}>
|
|
56
61
|
|
|
57
|
-
/** Input accepted when constructing
|
|
62
|
+
/** Input accepted when constructing an account configuration. */
|
|
58
63
|
export type Input<
|
|
59
64
|
versionType extends bigint | number = bigint | number,
|
|
60
65
|
numberType = number,
|
|
@@ -63,7 +68,7 @@ export type Input<
|
|
|
63
68
|
owners: readonly Owner<numberType>[]
|
|
64
69
|
/**
|
|
65
70
|
* Caller-chosen 32-byte salt mixed into the derived account address.
|
|
66
|
-
* Defaults to the zero salt (`
|
|
71
|
+
* Defaults to the zero salt (`AccountConfig.zeroSalt`) when omitted.
|
|
67
72
|
*/
|
|
68
73
|
salt?: Hex.Hex | undefined
|
|
69
74
|
/** Minimum total owner weight required to authorize a transaction. */
|
|
@@ -72,7 +77,7 @@ export type Input<
|
|
|
72
77
|
version?: versionType | undefined
|
|
73
78
|
}>
|
|
74
79
|
|
|
75
|
-
/**
|
|
80
|
+
/** Account config owner entry. */
|
|
76
81
|
export type Owner<numberType = number> = {
|
|
77
82
|
/** Owner address (recovered from the owner's approval). */
|
|
78
83
|
owner: Address.Address
|
|
@@ -80,10 +85,10 @@ export type Owner<numberType = number> = {
|
|
|
80
85
|
weight: numberType
|
|
81
86
|
}
|
|
82
87
|
|
|
83
|
-
/** JSON-RPC representation of
|
|
88
|
+
/** JSON-RPC representation of an account configuration. */
|
|
84
89
|
export type Rpc = Config<Hex.Hex, number>
|
|
85
90
|
|
|
86
|
-
/** RLP tuple representation of a {@link ox#
|
|
91
|
+
/** RLP tuple representation of a {@link ox#AccountConfig.Config}. */
|
|
87
92
|
export type Tuple = readonly [
|
|
88
93
|
salt: Hex.Hex,
|
|
89
94
|
version: Hex.Hex,
|
|
@@ -92,7 +97,7 @@ export type Tuple = readonly [
|
|
|
92
97
|
]
|
|
93
98
|
|
|
94
99
|
/**
|
|
95
|
-
* Asserts that
|
|
100
|
+
* Asserts that an {@link ox#AccountConfig.Config} is valid.
|
|
96
101
|
*
|
|
97
102
|
* Mirrors the Tempo configuration rules: owners non-empty and
|
|
98
103
|
* `<= maxOwners`, strictly ascending unique nonzero owner addresses, nonzero
|
|
@@ -102,9 +107,9 @@ export type Tuple = readonly [
|
|
|
102
107
|
*
|
|
103
108
|
* @example
|
|
104
109
|
* ```ts twoslash
|
|
105
|
-
* import {
|
|
110
|
+
* import { AccountConfig } from 'ox/tempo'
|
|
106
111
|
*
|
|
107
|
-
*
|
|
112
|
+
* AccountConfig.assert({
|
|
108
113
|
* threshold: 1,
|
|
109
114
|
* owners: [
|
|
110
115
|
* {
|
|
@@ -115,7 +120,7 @@ export type Tuple = readonly [
|
|
|
115
120
|
* })
|
|
116
121
|
* ```
|
|
117
122
|
*
|
|
118
|
-
* @param config - The
|
|
123
|
+
* @param config - The account config.
|
|
119
124
|
*/
|
|
120
125
|
export function assert<
|
|
121
126
|
versionType extends bigint | number = bigint | number,
|
|
@@ -186,16 +191,16 @@ export declare namespace assert {
|
|
|
186
191
|
}
|
|
187
192
|
|
|
188
193
|
/**
|
|
189
|
-
* Normalizes
|
|
194
|
+
* Normalizes an {@link ox#AccountConfig.Config}.
|
|
190
195
|
*
|
|
191
196
|
* Sorts owners into strictly ascending `owner` address order (the canonical
|
|
192
197
|
* form required for account derivation) and asserts the config is valid.
|
|
193
198
|
*
|
|
194
199
|
* @example
|
|
195
200
|
* ```ts twoslash
|
|
196
|
-
* import {
|
|
201
|
+
* import { AccountConfig } from 'ox/tempo'
|
|
197
202
|
*
|
|
198
|
-
* const config =
|
|
203
|
+
* const config = AccountConfig.from({
|
|
199
204
|
* owners: [
|
|
200
205
|
* {
|
|
201
206
|
* owner: '0x2222222222222222222222222222222222222222',
|
|
@@ -211,8 +216,8 @@ export declare namespace assert {
|
|
|
211
216
|
* // owners are now sorted ascending by address
|
|
212
217
|
* ```
|
|
213
218
|
*
|
|
214
|
-
* @param config - The
|
|
215
|
-
* @returns The normalized
|
|
219
|
+
* @param config - The account config.
|
|
220
|
+
* @returns The normalized account config.
|
|
216
221
|
*/
|
|
217
222
|
export function from<numberType = number>(
|
|
218
223
|
config: Input<0 | 0n, numberType> & { version?: 0 | 0n | undefined },
|
|
@@ -246,13 +251,13 @@ export function from<numberType = number>(
|
|
|
246
251
|
}
|
|
247
252
|
|
|
248
253
|
/**
|
|
249
|
-
* Converts a JSON-RPC
|
|
254
|
+
* Converts a JSON-RPC account configuration to its domain representation.
|
|
250
255
|
*
|
|
251
256
|
* @example
|
|
252
257
|
* ```ts twoslash
|
|
253
|
-
* import {
|
|
258
|
+
* import { AccountConfig } from 'ox/tempo'
|
|
254
259
|
*
|
|
255
|
-
* const config =
|
|
260
|
+
* const config = AccountConfig.fromRpc({
|
|
256
261
|
* owners: [
|
|
257
262
|
* {
|
|
258
263
|
* owner: '0x1111111111111111111111111111111111111111',
|
|
@@ -265,8 +270,8 @@ export function from<numberType = number>(
|
|
|
265
270
|
* })
|
|
266
271
|
* ```
|
|
267
272
|
*
|
|
268
|
-
* @param config - The JSON-RPC
|
|
269
|
-
* @returns The normalized
|
|
273
|
+
* @param config - The JSON-RPC account configuration.
|
|
274
|
+
* @returns The normalized account configuration.
|
|
270
275
|
*/
|
|
271
276
|
export function fromRpc(config: Rpc): Config {
|
|
272
277
|
return from({
|
|
@@ -283,14 +288,14 @@ export declare namespace fromRpc {
|
|
|
283
288
|
}
|
|
284
289
|
|
|
285
290
|
/**
|
|
286
|
-
* Converts an RLP {@link ox#
|
|
287
|
-
* {@link ox#
|
|
291
|
+
* Converts an RLP {@link ox#AccountConfig.Tuple} back to a
|
|
292
|
+
* {@link ox#AccountConfig.Config}.
|
|
288
293
|
*
|
|
289
294
|
* @example
|
|
290
295
|
* ```ts twoslash
|
|
291
|
-
* import {
|
|
296
|
+
* import { AccountConfig } from 'ox/tempo'
|
|
292
297
|
*
|
|
293
|
-
* const config =
|
|
298
|
+
* const config = AccountConfig.fromTuple([
|
|
294
299
|
* `0x${'00'.repeat(32)}`,
|
|
295
300
|
* '0x',
|
|
296
301
|
* '0x01',
|
|
@@ -299,7 +304,7 @@ export declare namespace fromRpc {
|
|
|
299
304
|
* ```
|
|
300
305
|
*
|
|
301
306
|
* @param tuple - The RLP tuple.
|
|
302
|
-
* @returns The
|
|
307
|
+
* @returns The account config.
|
|
303
308
|
*/
|
|
304
309
|
export function fromTuple(tuple: Tuple): Config {
|
|
305
310
|
const [salt, version, threshold, owners] = tuple
|
|
@@ -343,7 +348,7 @@ export function fromTuple(tuple: Tuple): Config {
|
|
|
343
348
|
}
|
|
344
349
|
|
|
345
350
|
/**
|
|
346
|
-
* Derives the stable
|
|
351
|
+
* Derives the stable configurable account address.
|
|
347
352
|
*
|
|
348
353
|
* The initial config is hashed into a CREATE2 salt using fixed-width
|
|
349
354
|
* big-endian fields, not RLP. The account uses the chain-configured recovery
|
|
@@ -354,9 +359,9 @@ export function fromTuple(tuple: Tuple): Config {
|
|
|
354
359
|
*
|
|
355
360
|
* @example
|
|
356
361
|
* ```ts twoslash
|
|
357
|
-
* import {
|
|
362
|
+
* import { AccountConfig } from 'ox/tempo'
|
|
358
363
|
*
|
|
359
|
-
* const initialConfig =
|
|
364
|
+
* const initialConfig = AccountConfig.from({
|
|
360
365
|
* owners: [
|
|
361
366
|
* {
|
|
362
367
|
* owner: '0x1111111111111111111111111111111111111111',
|
|
@@ -366,14 +371,14 @@ export function fromTuple(tuple: Tuple): Config {
|
|
|
366
371
|
* threshold: 1
|
|
367
372
|
* })
|
|
368
373
|
*
|
|
369
|
-
* const address =
|
|
374
|
+
* const address = AccountConfig.getAddress(initialConfig, {
|
|
370
375
|
* factory: '0x7171717171717171717171717171717171717171'
|
|
371
376
|
* })
|
|
372
377
|
* ```
|
|
373
378
|
*
|
|
374
|
-
* @param config - The initial
|
|
379
|
+
* @param config - The initial account config.
|
|
375
380
|
* @param options - The recovery factory configured by the chain.
|
|
376
|
-
* @returns The
|
|
381
|
+
* @returns The configurable account address.
|
|
377
382
|
*/
|
|
378
383
|
export function getAddress(
|
|
379
384
|
config: Input,
|
|
@@ -428,16 +433,16 @@ export declare namespace getAddress {
|
|
|
428
433
|
}
|
|
429
434
|
|
|
430
435
|
/**
|
|
431
|
-
* Computes the commitment for
|
|
436
|
+
* Computes the commitment for an account configuration.
|
|
432
437
|
*
|
|
433
438
|
* The commitment uses raw fixed-width fields, not RLP or ABI encoding:
|
|
434
439
|
* `keccak256("tempo:multisig:config" || salt || uint64be(version) || uint8(threshold) || uint8(owners.length) || owners)`.
|
|
435
440
|
*
|
|
436
441
|
* @example
|
|
437
442
|
* ```ts twoslash
|
|
438
|
-
* import {
|
|
443
|
+
* import { AccountConfig } from 'ox/tempo'
|
|
439
444
|
*
|
|
440
|
-
* const commitment =
|
|
445
|
+
* const commitment = AccountConfig.getCommitment({
|
|
441
446
|
* owners: [
|
|
442
447
|
* {
|
|
443
448
|
* owner: '0x1111111111111111111111111111111111111111',
|
|
@@ -449,7 +454,7 @@ export declare namespace getAddress {
|
|
|
449
454
|
* })
|
|
450
455
|
* ```
|
|
451
456
|
*
|
|
452
|
-
* @param config - The complete
|
|
457
|
+
* @param config - The complete account configuration.
|
|
453
458
|
* @returns The configuration commitment.
|
|
454
459
|
*/
|
|
455
460
|
export function getCommitment(config: Input): Hex.Hex {
|
|
@@ -480,7 +485,7 @@ export declare namespace getCommitment {
|
|
|
480
485
|
}
|
|
481
486
|
|
|
482
487
|
/**
|
|
483
|
-
* Computes the digest a
|
|
488
|
+
* Computes the digest a configurable account owner approves (signs).
|
|
484
489
|
*
|
|
485
490
|
* `keccak256("tempo:multisig:signature" || inner_digest || account || uint64be(version))`,
|
|
486
491
|
* where `inner_digest` is the transaction sign payload
|
|
@@ -492,9 +497,9 @@ export declare namespace getCommitment {
|
|
|
492
497
|
*
|
|
493
498
|
* @example
|
|
494
499
|
* ```ts twoslash
|
|
495
|
-
* import {
|
|
500
|
+
* import { AccountConfig, TxEnvelopeTempo } from 'ox/tempo'
|
|
496
501
|
*
|
|
497
|
-
* const config =
|
|
502
|
+
* const config = AccountConfig.from({
|
|
498
503
|
* owners: [
|
|
499
504
|
* {
|
|
500
505
|
* owner: '0x1111111111111111111111111111111111111111',
|
|
@@ -509,8 +514,8 @@ export declare namespace getCommitment {
|
|
|
509
514
|
* calls: []
|
|
510
515
|
* })
|
|
511
516
|
*
|
|
512
|
-
* const digest =
|
|
513
|
-
* account:
|
|
517
|
+
* const digest = AccountConfig.getSignPayload({
|
|
518
|
+
* account: AccountConfig.getAddress(config, {
|
|
514
519
|
* factory: '0x7171717171717171717171717171717171717171'
|
|
515
520
|
* }),
|
|
516
521
|
* config,
|
|
@@ -539,7 +544,7 @@ export function getSignPayload(value: getSignPayload.Value): Hex.Hex {
|
|
|
539
544
|
|
|
540
545
|
export declare namespace getSignPayload {
|
|
541
546
|
type Value = {
|
|
542
|
-
/** The
|
|
547
|
+
/** The configurable account address. */
|
|
543
548
|
account: Address.Address
|
|
544
549
|
/** Configuration whose version applies to the approval. */
|
|
545
550
|
config: Pick<Config<bigint | number>, 'version'>
|
|
@@ -557,13 +562,13 @@ export declare namespace getSignPayload {
|
|
|
557
562
|
}
|
|
558
563
|
|
|
559
564
|
/**
|
|
560
|
-
* Converts
|
|
565
|
+
* Converts an account configuration to its JSON-RPC representation.
|
|
561
566
|
*
|
|
562
567
|
* @example
|
|
563
568
|
* ```ts twoslash
|
|
564
|
-
* import {
|
|
569
|
+
* import { AccountConfig } from 'ox/tempo'
|
|
565
570
|
*
|
|
566
|
-
* const config =
|
|
571
|
+
* const config = AccountConfig.toRpc({
|
|
567
572
|
* owners: [
|
|
568
573
|
* {
|
|
569
574
|
* owner: '0x1111111111111111111111111111111111111111',
|
|
@@ -574,8 +579,8 @@ export declare namespace getSignPayload {
|
|
|
574
579
|
* })
|
|
575
580
|
* ```
|
|
576
581
|
*
|
|
577
|
-
* @param config - The
|
|
578
|
-
* @returns The JSON-RPC
|
|
582
|
+
* @param config - The account configuration.
|
|
583
|
+
* @returns The JSON-RPC account configuration.
|
|
579
584
|
*/
|
|
580
585
|
export function toRpc(config: Input): Rpc {
|
|
581
586
|
const value = from(config)
|
|
@@ -598,7 +603,7 @@ export declare namespace toRpc {
|
|
|
598
603
|
}
|
|
599
604
|
|
|
600
605
|
/**
|
|
601
|
-
* Converts a {@link ox#
|
|
606
|
+
* Converts a {@link ox#AccountConfig.Config} to its RLP tuple form.
|
|
602
607
|
*
|
|
603
608
|
* Tuple shape: `[salt, version, threshold, [[owner, weight], ...]]`. The
|
|
604
609
|
* 32-byte `salt` encodes as a full fixed-width string; other integers use
|
|
@@ -606,9 +611,9 @@ export declare namespace toRpc {
|
|
|
606
611
|
*
|
|
607
612
|
* @example
|
|
608
613
|
* ```ts twoslash
|
|
609
|
-
* import {
|
|
614
|
+
* import { AccountConfig } from 'ox/tempo'
|
|
610
615
|
*
|
|
611
|
-
* const tuple =
|
|
616
|
+
* const tuple = AccountConfig.toTuple({
|
|
612
617
|
* owners: [
|
|
613
618
|
* {
|
|
614
619
|
* owner: '0x1111111111111111111111111111111111111111',
|
|
@@ -619,7 +624,7 @@ export declare namespace toRpc {
|
|
|
619
624
|
* })
|
|
620
625
|
* ```
|
|
621
626
|
*
|
|
622
|
-
* @param config - The
|
|
627
|
+
* @param config - The account config.
|
|
623
628
|
* @returns The RLP tuple.
|
|
624
629
|
*/
|
|
625
630
|
export function toTuple(config: Input): Tuple {
|
|
@@ -640,14 +645,81 @@ export function toTuple(config: Input): Tuple {
|
|
|
640
645
|
}
|
|
641
646
|
|
|
642
647
|
/**
|
|
643
|
-
*
|
|
648
|
+
* Derives the configuration that replaces the current one in an owner update.
|
|
649
|
+
*
|
|
650
|
+
* Mirrors the `updateConfig` precompile ([TIP-1109](https://tips.sh/1109)):
|
|
651
|
+
* keeps the current salt, increments the version by one, and replaces the
|
|
652
|
+
* owners and threshold. Owners are sorted into canonical order and the next
|
|
653
|
+
* configuration is validated. The account address does not change.
|
|
654
|
+
*
|
|
655
|
+
* @example
|
|
656
|
+
* ```ts twoslash
|
|
657
|
+
* import { AccountConfig } from 'ox/tempo'
|
|
658
|
+
*
|
|
659
|
+
* const initialConfig = AccountConfig.from({
|
|
660
|
+
* owners: [
|
|
661
|
+
* {
|
|
662
|
+
* owner: '0x1111111111111111111111111111111111111111',
|
|
663
|
+
* weight: 1
|
|
664
|
+
* }
|
|
665
|
+
* ],
|
|
666
|
+
* threshold: 1
|
|
667
|
+
* })
|
|
668
|
+
*
|
|
669
|
+
* const config = AccountConfig.update(initialConfig, {
|
|
670
|
+
* owners: [
|
|
671
|
+
* {
|
|
672
|
+
* owner: '0x2222222222222222222222222222222222222222',
|
|
673
|
+
* weight: 1
|
|
674
|
+
* }
|
|
675
|
+
* ],
|
|
676
|
+
* threshold: 1
|
|
677
|
+
* })
|
|
678
|
+
* // config.version === 1n, with the initial salt
|
|
679
|
+
* ```
|
|
680
|
+
*
|
|
681
|
+
* @param config - The current account config.
|
|
682
|
+
* @param options - The replacement owners and threshold.
|
|
683
|
+
* @returns The next account config.
|
|
684
|
+
*/
|
|
685
|
+
export function update<numberType = number>(
|
|
686
|
+
config: Input<bigint | number, numberType>,
|
|
687
|
+
options: update.Options<numberType>,
|
|
688
|
+
): Config<bigint, numberType> {
|
|
689
|
+
const current = from(config)
|
|
690
|
+
if (current.version === maxVersion)
|
|
691
|
+
throw new InvalidConfigError({ reason: 'version overflow' })
|
|
692
|
+
return from({
|
|
693
|
+
owners: options.owners,
|
|
694
|
+
salt: current.salt,
|
|
695
|
+
threshold: options.threshold,
|
|
696
|
+
version: current.version + 1n,
|
|
697
|
+
})
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
export declare namespace update {
|
|
701
|
+
type Options<numberType = number> = {
|
|
702
|
+
/** Replacement weighted owners. Sorted into canonical order. */
|
|
703
|
+
owners: readonly Owner<numberType>[]
|
|
704
|
+
/** Replacement minimum total owner weight required for authorization. */
|
|
705
|
+
threshold: numberType
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
type ErrorType =
|
|
709
|
+
| assert.ErrorType
|
|
710
|
+
| InvalidConfigError
|
|
711
|
+
| Errors.GlobalErrorType
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
/**
|
|
715
|
+
* Validates an {@link ox#AccountConfig.Config}. Returns `true`
|
|
644
716
|
* if valid, `false` otherwise.
|
|
645
717
|
*
|
|
646
718
|
* @example
|
|
647
719
|
* ```ts twoslash
|
|
648
|
-
* import {
|
|
720
|
+
* import { AccountConfig } from 'ox/tempo'
|
|
649
721
|
*
|
|
650
|
-
* const valid =
|
|
722
|
+
* const valid = AccountConfig.validate({
|
|
651
723
|
* owners: [
|
|
652
724
|
* {
|
|
653
725
|
* owner: '0x1111111111111111111111111111111111111111',
|
|
@@ -659,7 +731,7 @@ export function toTuple(config: Input): Tuple {
|
|
|
659
731
|
* // @log: true
|
|
660
732
|
* ```
|
|
661
733
|
*
|
|
662
|
-
* @param config - The
|
|
734
|
+
* @param config - The account config.
|
|
663
735
|
* @returns Whether the config is valid.
|
|
664
736
|
*/
|
|
665
737
|
export function validate(config: Input): boolean {
|
|
@@ -671,11 +743,11 @@ export function validate(config: Input): boolean {
|
|
|
671
743
|
}
|
|
672
744
|
}
|
|
673
745
|
|
|
674
|
-
/** Thrown when
|
|
746
|
+
/** Thrown when an account config is invalid. */
|
|
675
747
|
export class InvalidConfigError extends Errors.BaseError {
|
|
676
|
-
override readonly name = '
|
|
748
|
+
override readonly name = 'AccountConfig.InvalidConfigError'
|
|
677
749
|
constructor({ reason }: { reason: string }) {
|
|
678
|
-
super(`Invalid
|
|
750
|
+
super(`Invalid account config: ${reason}.`)
|
|
679
751
|
}
|
|
680
752
|
}
|
|
681
753
|
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { expectTypeOf, test } from 'vp/test'
|
|
2
|
+
import type * as Hex from '../core/Hex.js'
|
|
3
|
+
import * as AccountOperation from './AccountOperation.js'
|
|
4
|
+
import type * as TxEnvelopeTempo from './TxEnvelopeTempo.js'
|
|
5
|
+
|
|
6
|
+
declare const transaction: AccountOperation.TransactionOperation
|
|
7
|
+
declare const transactionRpc: AccountOperation.TransactionRpc
|
|
8
|
+
declare const keyAuthorization: AccountOperation.KeyAuthorizationOperation
|
|
9
|
+
declare const keyAuthorizationRpc: AccountOperation.KeyAuthorizationRpc
|
|
10
|
+
declare const operation: AccountOperation.Operation
|
|
11
|
+
declare const operationRpc: AccountOperation.Rpc
|
|
12
|
+
declare const getHashOptions: AccountOperation.getHash.Options
|
|
13
|
+
declare const selectApprovalsOptions: AccountOperation.selectApprovals.Options
|
|
14
|
+
declare const serializedKeyAuthorization: Hex.Hex
|
|
15
|
+
declare const serializeKeyAuthorizationOptions: AccountOperation.serializeKeyAuthorization.Options
|
|
16
|
+
declare const serializeTransactionOptions: AccountOperation.serializeTransaction.Options
|
|
17
|
+
|
|
18
|
+
test('preserves operation kinds during validation', () => {
|
|
19
|
+
expectTypeOf(
|
|
20
|
+
AccountOperation.from(transaction),
|
|
21
|
+
).toEqualTypeOf<AccountOperation.TransactionOperation>()
|
|
22
|
+
expectTypeOf(
|
|
23
|
+
AccountOperation.from(keyAuthorization),
|
|
24
|
+
).toEqualTypeOf<AccountOperation.KeyAuthorizationOperation>()
|
|
25
|
+
expectTypeOf(
|
|
26
|
+
AccountOperation.from(operation),
|
|
27
|
+
).toEqualTypeOf<AccountOperation.Operation>()
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
test('preserves operation kinds during RPC conversion', () => {
|
|
31
|
+
expectTypeOf(
|
|
32
|
+
AccountOperation.fromRpc(transactionRpc),
|
|
33
|
+
).toEqualTypeOf<AccountOperation.TransactionOperation>()
|
|
34
|
+
expectTypeOf(
|
|
35
|
+
AccountOperation.fromRpc(keyAuthorizationRpc),
|
|
36
|
+
).toEqualTypeOf<AccountOperation.KeyAuthorizationOperation>()
|
|
37
|
+
expectTypeOf(
|
|
38
|
+
AccountOperation.toRpc(transaction),
|
|
39
|
+
).toEqualTypeOf<AccountOperation.TransactionRpc>()
|
|
40
|
+
expectTypeOf(
|
|
41
|
+
AccountOperation.toRpc(keyAuthorization),
|
|
42
|
+
).toEqualTypeOf<AccountOperation.KeyAuthorizationRpc>()
|
|
43
|
+
expectTypeOf(
|
|
44
|
+
AccountOperation.fromRpc(operationRpc),
|
|
45
|
+
).toEqualTypeOf<AccountOperation.Operation>()
|
|
46
|
+
expectTypeOf(
|
|
47
|
+
AccountOperation.toRpc(operation),
|
|
48
|
+
).toEqualTypeOf<AccountOperation.Rpc>()
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
test('uses JSON-RPC quantities only in RPC operations', () => {
|
|
52
|
+
expectTypeOf<
|
|
53
|
+
AccountOperation.Operation['config']['version']
|
|
54
|
+
>().toEqualTypeOf<bigint>()
|
|
55
|
+
expectTypeOf<
|
|
56
|
+
AccountOperation.Rpc['config']['version']
|
|
57
|
+
>().toEqualTypeOf<Hex.Hex>()
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
test('operation helpers return narrow types', async () => {
|
|
61
|
+
expectTypeOf(
|
|
62
|
+
AccountOperation.getHash(getHashOptions),
|
|
63
|
+
).toEqualTypeOf<Hex.Hex>()
|
|
64
|
+
expectTypeOf(
|
|
65
|
+
await AccountOperation.selectApprovals(selectApprovalsOptions),
|
|
66
|
+
).toEqualTypeOf<AccountOperation.selectApprovals.ReturnValue>()
|
|
67
|
+
expectTypeOf(
|
|
68
|
+
AccountOperation.serializeKeyAuthorization(
|
|
69
|
+
serializedKeyAuthorization,
|
|
70
|
+
serializeKeyAuthorizationOptions,
|
|
71
|
+
),
|
|
72
|
+
).toEqualTypeOf<Hex.Hex>()
|
|
73
|
+
expectTypeOf(
|
|
74
|
+
AccountOperation.serializeTransaction(
|
|
75
|
+
transaction,
|
|
76
|
+
serializeTransactionOptions,
|
|
77
|
+
),
|
|
78
|
+
).toEqualTypeOf<TxEnvelopeTempo.Serialized>()
|
|
79
|
+
})
|