ox 1.8.6 → 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 +29 -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 +16 -16
- package/dist/tempo/KeyAuthorization.d.ts.map +1 -1
- package/dist/tempo/KeyAuthorization.js +10 -9
- 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/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/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 +6 -6
- package/src/tempo/KeyAuthorization.test.ts +52 -36
- package/src/tempo/KeyAuthorization.ts +29 -27
- 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/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/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
|
@@ -2,22 +2,22 @@ import * as Address from '../core/Address.js'
|
|
|
2
2
|
import * as Errors from '../core/Errors.js'
|
|
3
3
|
import * as Hash from '../core/Hash.js'
|
|
4
4
|
import * as Hex from '../core/Hex.js'
|
|
5
|
+
import * as AccountConfig from './AccountConfig.js'
|
|
5
6
|
import * as KeyAuthorization_ from './KeyAuthorization.js'
|
|
6
|
-
import * as MultisigConfig from './MultisigConfig.js'
|
|
7
7
|
import * as SignatureEnvelope from './SignatureEnvelope.js'
|
|
8
8
|
import * as TxEnvelopeTempo from './TxEnvelopeTempo.js'
|
|
9
9
|
|
|
10
|
-
/** Fields shared by every
|
|
10
|
+
/** Fields shared by every account operation. */
|
|
11
11
|
export type Base<quantity = bigint> = {
|
|
12
|
-
/** Root
|
|
12
|
+
/** Root configurable account. */
|
|
13
13
|
account: Address.Address
|
|
14
14
|
/** Every retained serialized owner approval. */
|
|
15
15
|
approvals: readonly Hex.Hex[]
|
|
16
16
|
/** Root configuration used to verify approvals. */
|
|
17
|
-
config:
|
|
17
|
+
config: AccountConfig.Config<quantity>
|
|
18
18
|
/** Unix creation time in milliseconds. */
|
|
19
19
|
createdAt: number
|
|
20
|
-
/** Deterministic
|
|
20
|
+
/** Deterministic account operation hash. */
|
|
21
21
|
hash: Hex.Hex
|
|
22
22
|
/** Number of approvals selected for quorum evaluation. */
|
|
23
23
|
signatureCount: number
|
|
@@ -29,7 +29,7 @@ export type Base<quantity = bigint> = {
|
|
|
29
29
|
weight: number
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
/**
|
|
32
|
+
/** Account transaction approval operation. */
|
|
33
33
|
export type TransactionOperation<quantity = bigint> = Base<quantity> & {
|
|
34
34
|
/** Time when another relay may reclaim the submission lease. */
|
|
35
35
|
expiresAt?: number | undefined
|
|
@@ -45,7 +45,7 @@ export type TransactionOperation<quantity = bigint> = Base<quantity> & {
|
|
|
45
45
|
type: 'transaction'
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
/**
|
|
48
|
+
/** Account key authorization approval operation. */
|
|
49
49
|
export type KeyAuthorizationOperation<quantity = bigint> = Base<quantity> & {
|
|
50
50
|
/** Canonical serialized key authorization. */
|
|
51
51
|
keyAuthorization: Hex.Hex
|
|
@@ -55,29 +55,29 @@ export type KeyAuthorizationOperation<quantity = bigint> = Base<quantity> & {
|
|
|
55
55
|
type: 'keyAuthorization'
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
/** Transaction or key authorization
|
|
58
|
+
/** Transaction or key authorization account operation. */
|
|
59
59
|
export type Operation<quantity = bigint> =
|
|
60
60
|
| TransactionOperation<quantity>
|
|
61
61
|
| KeyAuthorizationOperation<quantity>
|
|
62
62
|
|
|
63
|
-
/** JSON-RPC
|
|
63
|
+
/** JSON-RPC account transaction operation. */
|
|
64
64
|
export type TransactionRpc = TransactionOperation<Hex.Hex>
|
|
65
65
|
|
|
66
|
-
/** JSON-RPC
|
|
66
|
+
/** JSON-RPC account key authorization operation. */
|
|
67
67
|
export type KeyAuthorizationRpc = KeyAuthorizationOperation<Hex.Hex>
|
|
68
68
|
|
|
69
|
-
/** JSON-RPC
|
|
69
|
+
/** JSON-RPC account operation. */
|
|
70
70
|
export type Rpc = Operation<Hex.Hex>
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
|
-
* Derives the deterministic hash for
|
|
73
|
+
* Derives the deterministic hash for an account operation.
|
|
74
74
|
*
|
|
75
75
|
* @example
|
|
76
76
|
* ```ts twoslash
|
|
77
77
|
* // @noErrors
|
|
78
|
-
* import {
|
|
78
|
+
* import { AccountOperation } from 'ox/tempo'
|
|
79
79
|
*
|
|
80
|
-
* const hash =
|
|
80
|
+
* const hash = AccountOperation.getHash({
|
|
81
81
|
* account,
|
|
82
82
|
* config,
|
|
83
83
|
* transaction,
|
|
@@ -85,7 +85,7 @@ export type Rpc = Operation<Hex.Hex>
|
|
|
85
85
|
* })
|
|
86
86
|
* ```
|
|
87
87
|
*
|
|
88
|
-
* @param options - Operation payload and
|
|
88
|
+
* @param options - Operation payload and account identity.
|
|
89
89
|
* @returns The operation hash signed by each owner.
|
|
90
90
|
*/
|
|
91
91
|
export function getHash(options: getHash.Options): Hex.Hex {
|
|
@@ -98,7 +98,7 @@ export function getHash(options: getHash.Options): Hex.Hex {
|
|
|
98
98
|
: KeyAuthorization_.getSignPayload(
|
|
99
99
|
KeyAuthorization_.deserialize(options.keyAuthorization),
|
|
100
100
|
)
|
|
101
|
-
return
|
|
101
|
+
return AccountConfig.getSignPayload({
|
|
102
102
|
account,
|
|
103
103
|
config,
|
|
104
104
|
payload,
|
|
@@ -108,10 +108,10 @@ export function getHash(options: getHash.Options): Hex.Hex {
|
|
|
108
108
|
export declare namespace getHash {
|
|
109
109
|
/** Parameters for `getHash`. */
|
|
110
110
|
export type Options = {
|
|
111
|
-
/** Root
|
|
111
|
+
/** Root configurable account. */
|
|
112
112
|
account: Address.Address
|
|
113
|
-
/** Complete root
|
|
114
|
-
config:
|
|
113
|
+
/** Complete root account configuration witness. */
|
|
114
|
+
config: AccountConfig.Config
|
|
115
115
|
} & (
|
|
116
116
|
| {
|
|
117
117
|
/** Canonical serialized key authorization. */
|
|
@@ -131,7 +131,7 @@ export declare namespace getHash {
|
|
|
131
131
|
export type ErrorType =
|
|
132
132
|
| KeyAuthorization_.deserialize.ErrorType
|
|
133
133
|
| KeyAuthorization_.getSignPayload.ErrorType
|
|
134
|
-
|
|
|
134
|
+
| AccountConfig.getSignPayload.ErrorType
|
|
135
135
|
| TxEnvelopeTempo.deserialize.ErrorType
|
|
136
136
|
| TxEnvelopeTempo.getSignPayload.ErrorType
|
|
137
137
|
| Errors.GlobalErrorType
|
|
@@ -148,9 +148,9 @@ export declare namespace getHash {
|
|
|
148
148
|
* @example
|
|
149
149
|
* ```ts twoslash
|
|
150
150
|
* // @noErrors
|
|
151
|
-
* import {
|
|
151
|
+
* import { AccountOperation } from 'ox/tempo'
|
|
152
152
|
*
|
|
153
|
-
* const selection = await
|
|
153
|
+
* const selection = await AccountOperation.selectApprovals({
|
|
154
154
|
* account,
|
|
155
155
|
* approvals,
|
|
156
156
|
* config,
|
|
@@ -169,7 +169,7 @@ export async function selectApprovals(
|
|
|
169
169
|
throw new InvalidApprovalError({ reason: 'account is invalid' })
|
|
170
170
|
if (!Hash.validate(hash))
|
|
171
171
|
throw new InvalidApprovalError({ reason: 'hash is invalid' })
|
|
172
|
-
const config =
|
|
172
|
+
const config = AccountConfig.from(options.config)
|
|
173
173
|
return selectApprovals_internal({
|
|
174
174
|
account,
|
|
175
175
|
approvals,
|
|
@@ -181,12 +181,12 @@ export async function selectApprovals(
|
|
|
181
181
|
export declare namespace selectApprovals {
|
|
182
182
|
/** Parameters for `selectApprovals`. */
|
|
183
183
|
export type Options = {
|
|
184
|
-
/** Root
|
|
184
|
+
/** Root configurable account. */
|
|
185
185
|
account: Address.Address
|
|
186
186
|
/** Serialized primitive owner approvals. */
|
|
187
187
|
approvals: readonly SignatureEnvelope.Serialized[]
|
|
188
|
-
/** Current root
|
|
189
|
-
config:
|
|
188
|
+
/** Current root account configuration. */
|
|
189
|
+
config: AccountConfig.Config
|
|
190
190
|
/** Deterministic operation hash approved by root owners. */
|
|
191
191
|
hash: Hex.Hex
|
|
192
192
|
}
|
|
@@ -208,8 +208,8 @@ export declare namespace selectApprovals {
|
|
|
208
208
|
/** Error type for `selectApprovals`. */
|
|
209
209
|
export type ErrorType =
|
|
210
210
|
| InvalidApprovalError
|
|
211
|
-
|
|
|
212
|
-
|
|
|
211
|
+
| AccountConfig.assert.ErrorType
|
|
212
|
+
| AccountConfig.getSignPayload.ErrorType
|
|
213
213
|
| SignatureEnvelope.CoercionError
|
|
214
214
|
| SignatureEnvelope.extractAddress.ErrorType
|
|
215
215
|
| SignatureEnvelope.serialize.ErrorType
|
|
@@ -218,15 +218,15 @@ export declare namespace selectApprovals {
|
|
|
218
218
|
}
|
|
219
219
|
|
|
220
220
|
/**
|
|
221
|
-
* Serializes a key authorization with selected
|
|
221
|
+
* Serializes a key authorization with selected owner approvals.
|
|
222
222
|
*
|
|
223
223
|
* @example
|
|
224
224
|
* ```ts twoslash
|
|
225
225
|
* // @noErrors
|
|
226
|
-
* import {
|
|
226
|
+
* import { AccountOperation } from 'ox/tempo'
|
|
227
227
|
*
|
|
228
228
|
* const authorization =
|
|
229
|
-
*
|
|
229
|
+
* AccountOperation.serializeKeyAuthorization(
|
|
230
230
|
* keyAuthorization,
|
|
231
231
|
* {
|
|
232
232
|
* account,
|
|
@@ -237,7 +237,7 @@ export declare namespace selectApprovals {
|
|
|
237
237
|
* ```
|
|
238
238
|
*
|
|
239
239
|
* @param keyAuthorization - Canonical serialized unsigned key authorization.
|
|
240
|
-
* @param options -
|
|
240
|
+
* @param options - Configurable account, config, and selected approvals.
|
|
241
241
|
* @returns The signed serialized key authorization.
|
|
242
242
|
*/
|
|
243
243
|
export function serializeKeyAuthorization(
|
|
@@ -256,8 +256,8 @@ export function serializeKeyAuthorization(
|
|
|
256
256
|
throw new InvalidOperationError({
|
|
257
257
|
reason: 'keyAuthorization is not canonically serialized',
|
|
258
258
|
})
|
|
259
|
-
const config =
|
|
260
|
-
const signatures = SignatureEnvelope.
|
|
259
|
+
const config = AccountConfig.from(options.config)
|
|
260
|
+
const signatures = SignatureEnvelope.sortApprovals({
|
|
261
261
|
account: options.account,
|
|
262
262
|
config,
|
|
263
263
|
payload: KeyAuthorization_.getSignPayload(authorization),
|
|
@@ -279,12 +279,12 @@ export function serializeKeyAuthorization(
|
|
|
279
279
|
export declare namespace serializeKeyAuthorization {
|
|
280
280
|
/** Options for `serializeKeyAuthorization`. */
|
|
281
281
|
export type Options = {
|
|
282
|
-
/** Root
|
|
282
|
+
/** Root configurable account. */
|
|
283
283
|
account: Address.Address
|
|
284
284
|
/** Selected serialized owner approvals. */
|
|
285
285
|
approvals: readonly SignatureEnvelope.Serialized[]
|
|
286
|
-
/** Complete applicable root
|
|
287
|
-
config:
|
|
286
|
+
/** Complete applicable root account config. */
|
|
287
|
+
config: AccountConfig.Config
|
|
288
288
|
}
|
|
289
289
|
|
|
290
290
|
/** Error type for `serializeKeyAuthorization`. */
|
|
@@ -294,22 +294,22 @@ export declare namespace serializeKeyAuthorization {
|
|
|
294
294
|
| KeyAuthorization_.from.ErrorType
|
|
295
295
|
| KeyAuthorization_.getSignPayload.ErrorType
|
|
296
296
|
| KeyAuthorization_.serialize.ErrorType
|
|
297
|
-
|
|
|
297
|
+
| AccountConfig.assert.ErrorType
|
|
298
298
|
| SignatureEnvelope.assert.ErrorType
|
|
299
299
|
| SignatureEnvelope.InvalidSerializedError
|
|
300
|
-
| SignatureEnvelope.
|
|
300
|
+
| SignatureEnvelope.sortApprovals.ErrorType
|
|
301
301
|
| Errors.GlobalErrorType
|
|
302
302
|
}
|
|
303
303
|
|
|
304
304
|
/**
|
|
305
|
-
* Serializes
|
|
305
|
+
* Serializes an account transaction operation with selected owner approvals.
|
|
306
306
|
*
|
|
307
307
|
* @example
|
|
308
308
|
* ```ts twoslash
|
|
309
309
|
* // @noErrors
|
|
310
|
-
* import {
|
|
310
|
+
* import { AccountOperation } from 'ox/tempo'
|
|
311
311
|
*
|
|
312
|
-
* const transaction =
|
|
312
|
+
* const transaction = AccountOperation.serializeTransaction(
|
|
313
313
|
* operation,
|
|
314
314
|
* {
|
|
315
315
|
* approvals: selection.selectedApprovals
|
|
@@ -317,7 +317,7 @@ export declare namespace serializeKeyAuthorization {
|
|
|
317
317
|
* )
|
|
318
318
|
* ```
|
|
319
319
|
*
|
|
320
|
-
* @param operation -
|
|
320
|
+
* @param operation - Account transaction operation.
|
|
321
321
|
* @param options - Transaction serialization options.
|
|
322
322
|
* @returns The signed serialized Tempo transaction.
|
|
323
323
|
*/
|
|
@@ -333,7 +333,7 @@ export function serializeTransaction(
|
|
|
333
333
|
assertApproval(value.account, approval, value.config),
|
|
334
334
|
)
|
|
335
335
|
assertRetainedApprovals(value, approvals)
|
|
336
|
-
const signatures = SignatureEnvelope.
|
|
336
|
+
const signatures = SignatureEnvelope.sortApprovals({
|
|
337
337
|
account: value.account,
|
|
338
338
|
config: value.config,
|
|
339
339
|
payload: TxEnvelopeTempo.getSignPayload(envelope),
|
|
@@ -367,7 +367,7 @@ export declare namespace serializeTransaction {
|
|
|
367
367
|
export type ErrorType =
|
|
368
368
|
| from.ErrorType
|
|
369
369
|
| InvalidOperationError
|
|
370
|
-
| SignatureEnvelope.
|
|
370
|
+
| SignatureEnvelope.sortApprovals.ErrorType
|
|
371
371
|
| TxEnvelopeTempo.deserialize.ErrorType
|
|
372
372
|
| TxEnvelopeTempo.getSignPayload.ErrorType
|
|
373
373
|
| TxEnvelopeTempo.serialize.ErrorType
|
|
@@ -375,24 +375,24 @@ export declare namespace serializeTransaction {
|
|
|
375
375
|
}
|
|
376
376
|
|
|
377
377
|
/**
|
|
378
|
-
* Validates and normalizes
|
|
378
|
+
* Validates and normalizes an account operation.
|
|
379
379
|
*
|
|
380
380
|
* @example
|
|
381
381
|
* ```ts twoslash
|
|
382
382
|
* // @noErrors
|
|
383
|
-
* import {
|
|
383
|
+
* import { AccountOperation } from 'ox/tempo'
|
|
384
384
|
*
|
|
385
|
-
* const operation =
|
|
385
|
+
* const operation = AccountOperation.from(value)
|
|
386
386
|
* ```
|
|
387
387
|
*
|
|
388
|
-
* @param operation -
|
|
388
|
+
* @param operation - Account operation.
|
|
389
389
|
* @returns The validated operation.
|
|
390
390
|
*/
|
|
391
391
|
export function from<const operation extends Operation>(
|
|
392
392
|
operation: operation,
|
|
393
393
|
): from.ReturnValue<operation> {
|
|
394
394
|
try {
|
|
395
|
-
const config =
|
|
395
|
+
const config = AccountConfig.from(operation.config)
|
|
396
396
|
if (
|
|
397
397
|
typeof config.threshold !== 'number' ||
|
|
398
398
|
config.owners.some((owner) => typeof owner.weight !== 'number')
|
|
@@ -425,17 +425,17 @@ export declare namespace from {
|
|
|
425
425
|
}
|
|
426
426
|
|
|
427
427
|
/**
|
|
428
|
-
* Converts a JSON-RPC
|
|
428
|
+
* Converts a JSON-RPC account operation to its domain representation.
|
|
429
429
|
*
|
|
430
430
|
* @example
|
|
431
431
|
* ```ts twoslash
|
|
432
432
|
* // @noErrors
|
|
433
|
-
* import {
|
|
433
|
+
* import { AccountOperation } from 'ox/tempo'
|
|
434
434
|
*
|
|
435
|
-
* const operation =
|
|
435
|
+
* const operation = AccountOperation.fromRpc(value)
|
|
436
436
|
* ```
|
|
437
437
|
*
|
|
438
|
-
* @param operation - JSON-RPC
|
|
438
|
+
* @param operation - JSON-RPC account operation.
|
|
439
439
|
* @returns The validated operation.
|
|
440
440
|
*/
|
|
441
441
|
export function fromRpc<const operation extends Rpc>(
|
|
@@ -454,7 +454,7 @@ export function fromRpc<const operation extends Rpc>(
|
|
|
454
454
|
})
|
|
455
455
|
return from({
|
|
456
456
|
...operation,
|
|
457
|
-
config:
|
|
457
|
+
config: AccountConfig.fromRpc(operation.config),
|
|
458
458
|
} as Operation) as never
|
|
459
459
|
} catch (cause) {
|
|
460
460
|
if (cause instanceof InvalidOperationError) throw cause
|
|
@@ -474,17 +474,17 @@ export declare namespace fromRpc {
|
|
|
474
474
|
}
|
|
475
475
|
|
|
476
476
|
/**
|
|
477
|
-
* Converts
|
|
477
|
+
* Converts an account operation to its JSON-RPC representation.
|
|
478
478
|
*
|
|
479
479
|
* @example
|
|
480
480
|
* ```ts twoslash
|
|
481
481
|
* // @noErrors
|
|
482
|
-
* import {
|
|
482
|
+
* import { AccountOperation } from 'ox/tempo'
|
|
483
483
|
*
|
|
484
|
-
* const operationRpc =
|
|
484
|
+
* const operationRpc = AccountOperation.toRpc(operation)
|
|
485
485
|
* ```
|
|
486
486
|
*
|
|
487
|
-
* @param operation -
|
|
487
|
+
* @param operation - Account operation.
|
|
488
488
|
* @returns The JSON-RPC operation.
|
|
489
489
|
*/
|
|
490
490
|
export function toRpc<const operation extends Operation>(
|
|
@@ -493,7 +493,7 @@ export function toRpc<const operation extends Operation>(
|
|
|
493
493
|
const value = from(operation)
|
|
494
494
|
return {
|
|
495
495
|
...value,
|
|
496
|
-
config:
|
|
496
|
+
config: AccountConfig.toRpc(value.config),
|
|
497
497
|
} as never
|
|
498
498
|
}
|
|
499
499
|
|
|
@@ -505,7 +505,7 @@ export declare namespace toRpc {
|
|
|
505
505
|
: KeyAuthorizationRpc
|
|
506
506
|
|
|
507
507
|
/** Error type for `toRpc`. */
|
|
508
|
-
export type ErrorType = from.ErrorType |
|
|
508
|
+
export type ErrorType = from.ErrorType | AccountConfig.toRpc.ErrorType
|
|
509
509
|
}
|
|
510
510
|
|
|
511
511
|
/**
|
|
@@ -525,9 +525,9 @@ async function selectApprovals_internal(
|
|
|
525
525
|
const groups = new Map<string, ApprovalGroup>()
|
|
526
526
|
for (const serialized of options.approvals) {
|
|
527
527
|
const signature = SignatureEnvelope.from(serialized)
|
|
528
|
-
if (signature.type === 'keychain' || signature.type === '
|
|
528
|
+
if (signature.type === 'keychain' || signature.type === 'configurable')
|
|
529
529
|
throw new InvalidApprovalError({
|
|
530
|
-
reason: 'only primitive signatures can approve
|
|
530
|
+
reason: 'only primitive signatures can approve an account operation',
|
|
531
531
|
})
|
|
532
532
|
const address = SignatureEnvelope.extractAddress({
|
|
533
533
|
payload: options.hash,
|
|
@@ -578,7 +578,7 @@ async function selectApprovals_internal(
|
|
|
578
578
|
)
|
|
579
579
|
const selected: typeof ranked = []
|
|
580
580
|
let weight = 0
|
|
581
|
-
for (const approval of ranked.slice(0,
|
|
581
|
+
for (const approval of ranked.slice(0, AccountConfig.maxSignatures)) {
|
|
582
582
|
if (weight >= Number(options.config.threshold)) break
|
|
583
583
|
selected.push(approval)
|
|
584
584
|
weight += approval.weight
|
|
@@ -654,7 +654,7 @@ function compareHex(a: Hex.Hex, b: Hex.Hex) {
|
|
|
654
654
|
*
|
|
655
655
|
* @internal
|
|
656
656
|
*/
|
|
657
|
-
function assertBase(operation: Operation, config:
|
|
657
|
+
function assertBase(operation: Operation, config: AccountConfig.Config): void {
|
|
658
658
|
if (!Address.validate(operation.account))
|
|
659
659
|
throw new InvalidOperationError({ reason: 'account is invalid' })
|
|
660
660
|
if (Hex.toBigInt(operation.account) === 0n)
|
|
@@ -676,7 +676,7 @@ function assertBase(operation: Operation, config: MultisigConfig.Config): void {
|
|
|
676
676
|
})
|
|
677
677
|
if (operation.weight > 0xff)
|
|
678
678
|
throw new InvalidOperationError({ reason: 'weight exceeds u8 max' })
|
|
679
|
-
if (operation.signatureCount >
|
|
679
|
+
if (operation.signatureCount > AccountConfig.maxSignatures)
|
|
680
680
|
throw new InvalidOperationError({ reason: 'too many selected signatures' })
|
|
681
681
|
if (!Array.isArray(operation.approvals))
|
|
682
682
|
throw new InvalidOperationError({ reason: 'approvals must be an array' })
|
|
@@ -837,7 +837,7 @@ function assertTransaction(operation: TransactionOperation): void {
|
|
|
837
837
|
*/
|
|
838
838
|
function assertKeyAuthorization(
|
|
839
839
|
operation: KeyAuthorizationOperation,
|
|
840
|
-
config:
|
|
840
|
+
config: AccountConfig.Config,
|
|
841
841
|
): void {
|
|
842
842
|
const transactionFields = operation as KeyAuthorizationOperation & {
|
|
843
843
|
expiresAt?: unknown
|
|
@@ -887,9 +887,10 @@ function assertKeyAuthorization(
|
|
|
887
887
|
reason: 'pending key authorizations must be unsigned',
|
|
888
888
|
})
|
|
889
889
|
if (operation.status === 'success') {
|
|
890
|
-
if (signature?.type !== '
|
|
890
|
+
if (signature?.type !== 'configurable')
|
|
891
891
|
throw new InvalidOperationError({
|
|
892
|
-
reason:
|
|
892
|
+
reason:
|
|
893
|
+
'successful key authorizations require a configurable account signature',
|
|
893
894
|
})
|
|
894
895
|
if (signature.account.toLowerCase() !== operation.account.toLowerCase())
|
|
895
896
|
throw new InvalidOperationError({
|
|
@@ -926,10 +927,10 @@ function assertKeyAuthorization(
|
|
|
926
927
|
function assertApproval(
|
|
927
928
|
account: Address.Address,
|
|
928
929
|
serialized: SignatureEnvelope.Serialized,
|
|
929
|
-
config:
|
|
930
|
+
config: AccountConfig.Config,
|
|
930
931
|
): SignatureEnvelope.Primitive {
|
|
931
932
|
const approval = SignatureEnvelope.deserialize(serialized)
|
|
932
|
-
if (approval.type === 'keychain' || approval.type === '
|
|
933
|
+
if (approval.type === 'keychain' || approval.type === 'configurable')
|
|
933
934
|
throw new InvalidOperationError({
|
|
934
935
|
reason: 'only primitive owner approvals are allowed',
|
|
935
936
|
})
|
|
@@ -937,7 +938,7 @@ function assertApproval(
|
|
|
937
938
|
account,
|
|
938
939
|
config,
|
|
939
940
|
signatures: [approval],
|
|
940
|
-
type: '
|
|
941
|
+
type: 'configurable',
|
|
941
942
|
})
|
|
942
943
|
if (
|
|
943
944
|
SignatureEnvelope.serialize(approval).toLowerCase() !==
|
|
@@ -999,7 +1000,7 @@ function assertSelectedApprovals(
|
|
|
999
1000
|
retained.splice(index, 1)
|
|
1000
1001
|
}
|
|
1001
1002
|
|
|
1002
|
-
const digest =
|
|
1003
|
+
const digest = AccountConfig.getSignPayload({
|
|
1003
1004
|
account: operation.account,
|
|
1004
1005
|
config: operation.config,
|
|
1005
1006
|
payload: KeyAuthorization_.getSignPayload(authorization),
|
|
@@ -1049,7 +1050,7 @@ function isWeightReachable(
|
|
|
1049
1050
|
* @internal
|
|
1050
1051
|
*/
|
|
1051
1052
|
function assertOperationHash(operation: Operation, payload: Hex.Hex): void {
|
|
1052
|
-
const hash =
|
|
1053
|
+
const hash = AccountConfig.getSignPayload({
|
|
1053
1054
|
account: operation.account,
|
|
1054
1055
|
config: operation.config,
|
|
1055
1056
|
payload,
|
|
@@ -1073,20 +1074,17 @@ function assertInteger(value: unknown, field: string): asserts value is number {
|
|
|
1073
1074
|
}
|
|
1074
1075
|
|
|
1075
1076
|
/**
|
|
1076
|
-
* Compares normalized
|
|
1077
|
+
* Compares normalized account configurations.
|
|
1077
1078
|
*
|
|
1078
1079
|
* @internal
|
|
1079
1080
|
*/
|
|
1080
|
-
function sameConfig(
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
): boolean {
|
|
1084
|
-
const configA = MultisigConfig.from(a)
|
|
1085
|
-
const configB = MultisigConfig.from(b)
|
|
1081
|
+
function sameConfig(a: AccountConfig.Config, b: AccountConfig.Config): boolean {
|
|
1082
|
+
const configA = AccountConfig.from(a)
|
|
1083
|
+
const configB = AccountConfig.from(b)
|
|
1086
1084
|
return (
|
|
1087
1085
|
Hex.isEqual(
|
|
1088
|
-
configA.salt ??
|
|
1089
|
-
configB.salt ??
|
|
1086
|
+
configA.salt ?? AccountConfig.zeroSalt,
|
|
1087
|
+
configB.salt ?? AccountConfig.zeroSalt,
|
|
1090
1088
|
) &&
|
|
1091
1089
|
configA.threshold === configB.threshold &&
|
|
1092
1090
|
configA.version === configB.version &&
|
|
@@ -1101,18 +1099,18 @@ function sameConfig(
|
|
|
1101
1099
|
)
|
|
1102
1100
|
}
|
|
1103
1101
|
|
|
1104
|
-
/** Thrown when
|
|
1102
|
+
/** Thrown when an account operation owner approval is invalid. */
|
|
1105
1103
|
export class InvalidApprovalError extends Errors.BaseError<Error | undefined> {
|
|
1106
|
-
override readonly name = '
|
|
1104
|
+
override readonly name = 'AccountOperation.InvalidApprovalError'
|
|
1107
1105
|
|
|
1108
1106
|
/**
|
|
1109
|
-
* Creates an invalid
|
|
1107
|
+
* Creates an invalid operation approval error.
|
|
1110
1108
|
*
|
|
1111
1109
|
* @example
|
|
1112
1110
|
* ```ts twoslash
|
|
1113
|
-
* import {
|
|
1111
|
+
* import { AccountOperation } from 'ox/tempo'
|
|
1114
1112
|
*
|
|
1115
|
-
* throw new
|
|
1113
|
+
* throw new AccountOperation.InvalidApprovalError({
|
|
1116
1114
|
* reason: 'signature is from a non-owner'
|
|
1117
1115
|
* })
|
|
1118
1116
|
* ```
|
|
@@ -1122,8 +1120,8 @@ export class InvalidApprovalError extends Errors.BaseError<Error | undefined> {
|
|
|
1122
1120
|
constructor(options: InvalidApprovalError.Options = {}) {
|
|
1123
1121
|
super(
|
|
1124
1122
|
options.reason
|
|
1125
|
-
? `Invalid
|
|
1126
|
-
: 'Invalid
|
|
1123
|
+
? `Invalid operation approval: ${options.reason}.`
|
|
1124
|
+
: 'Invalid operation approval.',
|
|
1127
1125
|
{ cause: options.cause as Error | undefined },
|
|
1128
1126
|
)
|
|
1129
1127
|
}
|
|
@@ -1139,18 +1137,18 @@ export declare namespace InvalidApprovalError {
|
|
|
1139
1137
|
}
|
|
1140
1138
|
}
|
|
1141
1139
|
|
|
1142
|
-
/** Thrown when
|
|
1140
|
+
/** Thrown when an account operation is malformed or internally inconsistent. */
|
|
1143
1141
|
export class InvalidOperationError extends Errors.BaseError<Error | undefined> {
|
|
1144
|
-
override readonly name = '
|
|
1142
|
+
override readonly name = 'AccountOperation.InvalidOperationError'
|
|
1145
1143
|
|
|
1146
1144
|
/**
|
|
1147
|
-
* Creates an invalid
|
|
1145
|
+
* Creates an invalid account operation error.
|
|
1148
1146
|
*
|
|
1149
1147
|
* @example
|
|
1150
1148
|
* ```ts twoslash
|
|
1151
|
-
* import {
|
|
1149
|
+
* import { AccountOperation } from 'ox/tempo'
|
|
1152
1150
|
*
|
|
1153
|
-
* throw new
|
|
1151
|
+
* throw new AccountOperation.InvalidOperationError({
|
|
1154
1152
|
* reason: 'hash does not match the operation payload'
|
|
1155
1153
|
* })
|
|
1156
1154
|
* ```
|
|
@@ -1160,8 +1158,8 @@ export class InvalidOperationError extends Errors.BaseError<Error | undefined> {
|
|
|
1160
1158
|
constructor(options: InvalidOperationError.Options = {}) {
|
|
1161
1159
|
super(
|
|
1162
1160
|
options.reason
|
|
1163
|
-
? `Invalid
|
|
1164
|
-
: 'Invalid
|
|
1161
|
+
? `Invalid account operation: ${options.reason}.`
|
|
1162
|
+
: 'Invalid account operation.',
|
|
1165
1163
|
{ cause: options.cause as Error | undefined },
|
|
1166
1164
|
)
|
|
1167
1165
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { expectTypeOf, test } from 'vp/test'
|
|
2
|
-
import * as
|
|
2
|
+
import * as AccountSimulation from './AccountSimulation.js'
|
|
3
3
|
|
|
4
4
|
const rpc = {
|
|
5
5
|
approvals: [
|
|
@@ -11,23 +11,21 @@ const rpc = {
|
|
|
11
11
|
],
|
|
12
12
|
config:
|
|
13
13
|
'0xf83ba000000000000000000000000000000000000000000000000000000000000000008001d7d694111111111111111111111111111111111111111101',
|
|
14
|
-
} as const satisfies
|
|
14
|
+
} as const satisfies AccountSimulation.Rpc
|
|
15
15
|
|
|
16
16
|
test('fromRpc returns a domain spec', () => {
|
|
17
|
-
const spec =
|
|
17
|
+
const spec = AccountSimulation.fromRpc(rpc)
|
|
18
18
|
|
|
19
|
-
expectTypeOf(spec).toEqualTypeOf<
|
|
19
|
+
expectTypeOf(spec).toEqualTypeOf<AccountSimulation.Spec>()
|
|
20
20
|
expectTypeOf(spec.config.version).toEqualTypeOf<bigint>()
|
|
21
21
|
})
|
|
22
22
|
|
|
23
23
|
test('RPC specs use encoded configurations', () => {
|
|
24
|
-
expectTypeOf<
|
|
25
|
-
MultisigSimulation.Rpc['config']
|
|
26
|
-
>().toEqualTypeOf<`0x${string}`>()
|
|
24
|
+
expectTypeOf<AccountSimulation.Rpc['config']>().toEqualTypeOf<`0x${string}`>()
|
|
27
25
|
})
|
|
28
26
|
|
|
29
27
|
test('toRpc returns an RPC spec', () => {
|
|
30
28
|
expectTypeOf(
|
|
31
|
-
|
|
32
|
-
).toEqualTypeOf<
|
|
29
|
+
AccountSimulation.toRpc(AccountSimulation.fromRpc(rpc)),
|
|
30
|
+
).toEqualTypeOf<AccountSimulation.Rpc>()
|
|
33
31
|
})
|