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
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { factory } from '../../test/tempo/
|
|
1
|
+
import { factory } from '../../test/tempo/configurableAccounts.js'
|
|
2
2
|
import { Address, Hash, Hex, P256 } from 'ox'
|
|
3
3
|
import {
|
|
4
|
+
AccountConfig,
|
|
4
5
|
KeyAuthorization,
|
|
5
|
-
|
|
6
|
-
MultisigOperation,
|
|
6
|
+
AccountOperation,
|
|
7
7
|
SignatureEnvelope,
|
|
8
8
|
TxEnvelopeTempo,
|
|
9
9
|
} from 'ox/tempo'
|
|
@@ -33,15 +33,15 @@ const owners = [1n, 2n, 3n]
|
|
|
33
33
|
.sort((a, b) => a.address.localeCompare(b.address))
|
|
34
34
|
const owner_1 = owners[0]!.address
|
|
35
35
|
const owner_2 = owners[1]!.address
|
|
36
|
-
const config =
|
|
36
|
+
const config = AccountConfig.from({
|
|
37
37
|
owners: [
|
|
38
38
|
{ owner: owner_1, weight: 1 },
|
|
39
39
|
{ owner: owner_2, weight: 1 },
|
|
40
40
|
],
|
|
41
41
|
threshold: 2,
|
|
42
42
|
})
|
|
43
|
-
const currentConfig =
|
|
44
|
-
const account =
|
|
43
|
+
const currentConfig = AccountConfig.from({ ...config, version: 1n })
|
|
44
|
+
const account = AccountConfig.getAddress(config, { factory })
|
|
45
45
|
const ownerSignature_1 = owners[0]!.signature
|
|
46
46
|
const approval_1 = SignatureEnvelope.serialize(ownerSignature_1)
|
|
47
47
|
const approval_2 = SignatureEnvelope.serialize(owners[1]!.signature)
|
|
@@ -65,14 +65,14 @@ const keyAuthorization = KeyAuthorization.serialize(
|
|
|
65
65
|
}),
|
|
66
66
|
)
|
|
67
67
|
|
|
68
|
-
const transactionHash_ =
|
|
68
|
+
const transactionHash_ = AccountConfig.getSignPayload({
|
|
69
69
|
account,
|
|
70
70
|
config: currentConfig,
|
|
71
71
|
payload: TxEnvelopeTempo.getSignPayload(
|
|
72
72
|
TxEnvelopeTempo.deserialize(transaction),
|
|
73
73
|
),
|
|
74
74
|
})
|
|
75
|
-
const keyAuthorizationHash =
|
|
75
|
+
const keyAuthorizationHash = AccountConfig.getSignPayload({
|
|
76
76
|
account,
|
|
77
77
|
config: currentConfig,
|
|
78
78
|
payload: KeyAuthorization.getSignPayload(
|
|
@@ -139,13 +139,13 @@ function approvalAddresses(
|
|
|
139
139
|
describe('getHash', () => {
|
|
140
140
|
test('transaction and key authorization', () => {
|
|
141
141
|
expect({
|
|
142
|
-
keyAuthorization:
|
|
142
|
+
keyAuthorization: AccountOperation.getHash({
|
|
143
143
|
account,
|
|
144
144
|
config: currentConfig,
|
|
145
145
|
keyAuthorization,
|
|
146
146
|
type: 'keyAuthorization',
|
|
147
147
|
}),
|
|
148
|
-
transaction:
|
|
148
|
+
transaction: AccountOperation.getHash({
|
|
149
149
|
account,
|
|
150
150
|
config: currentConfig,
|
|
151
151
|
transaction,
|
|
@@ -162,7 +162,7 @@ describe('getHash', () => {
|
|
|
162
162
|
|
|
163
163
|
describe('selectApprovals', () => {
|
|
164
164
|
test('selects a deterministic weighted quorum', async () => {
|
|
165
|
-
const config =
|
|
165
|
+
const config = AccountConfig.from({
|
|
166
166
|
owners: [
|
|
167
167
|
{ owner: owners[0]!.address, weight: 2 },
|
|
168
168
|
{ owner: owners[1]!.address, weight: 1 },
|
|
@@ -170,8 +170,8 @@ describe('selectApprovals', () => {
|
|
|
170
170
|
],
|
|
171
171
|
threshold: 3,
|
|
172
172
|
})
|
|
173
|
-
const account =
|
|
174
|
-
const hash =
|
|
173
|
+
const account = AccountConfig.getAddress(config, { factory })
|
|
174
|
+
const hash = AccountOperation.getHash({
|
|
175
175
|
account,
|
|
176
176
|
config: { ...config, version: 1n },
|
|
177
177
|
transaction,
|
|
@@ -179,7 +179,7 @@ describe('selectApprovals', () => {
|
|
|
179
179
|
})
|
|
180
180
|
const approvals = owners.map((owner) => signApproval(owner, hash))
|
|
181
181
|
const alternate = signApproval(owners[0]!, hash, `0x${'01'.repeat(32)}`)
|
|
182
|
-
const selection = await
|
|
182
|
+
const selection = await AccountOperation.selectApprovals({
|
|
183
183
|
account,
|
|
184
184
|
approvals: [
|
|
185
185
|
approvals[2]!,
|
|
@@ -191,7 +191,7 @@ describe('selectApprovals', () => {
|
|
|
191
191
|
config,
|
|
192
192
|
hash,
|
|
193
193
|
})
|
|
194
|
-
const reversed = await
|
|
194
|
+
const reversed = await AccountOperation.selectApprovals({
|
|
195
195
|
account,
|
|
196
196
|
approvals: [
|
|
197
197
|
approvals[0]!,
|
|
@@ -227,7 +227,7 @@ describe('selectApprovals', () => {
|
|
|
227
227
|
`)
|
|
228
228
|
})
|
|
229
229
|
test('accepts an explicit account from a chain-configured factory', async () => {
|
|
230
|
-
const selected = await
|
|
230
|
+
const selected = await AccountOperation.selectApprovals({
|
|
231
231
|
account,
|
|
232
232
|
approvals: [],
|
|
233
233
|
config,
|
|
@@ -235,7 +235,7 @@ describe('selectApprovals', () => {
|
|
|
235
235
|
})
|
|
236
236
|
expect(selected.weight).toMatchInlineSnapshot(`0`)
|
|
237
237
|
})
|
|
238
|
-
test('rejects keychain and
|
|
238
|
+
test('rejects keychain and configurable owner approvals', async () => {
|
|
239
239
|
for (const signature of [
|
|
240
240
|
SignatureEnvelope.from({
|
|
241
241
|
inner: ownerSignature_1,
|
|
@@ -250,19 +250,19 @@ describe('selectApprovals', () => {
|
|
|
250
250
|
}),
|
|
251
251
|
])
|
|
252
252
|
await expect(
|
|
253
|
-
|
|
253
|
+
AccountOperation.selectApprovals({
|
|
254
254
|
account,
|
|
255
255
|
approvals: [SignatureEnvelope.serialize(signature)],
|
|
256
256
|
config,
|
|
257
257
|
hash: transactionHash_,
|
|
258
258
|
}),
|
|
259
259
|
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
260
|
-
`[
|
|
260
|
+
`[AccountOperation.InvalidApprovalError: Invalid operation approval: only primitive signatures can approve an account operation.]`,
|
|
261
261
|
)
|
|
262
262
|
})
|
|
263
263
|
|
|
264
264
|
test('rejects invalid and non-owner approvals', async () => {
|
|
265
|
-
const hash =
|
|
265
|
+
const hash = AccountOperation.getHash({
|
|
266
266
|
account,
|
|
267
267
|
config: currentConfig,
|
|
268
268
|
transaction,
|
|
@@ -275,24 +275,24 @@ describe('selectApprovals', () => {
|
|
|
275
275
|
const nonOwner = signApproval(owners[2]!, hash)
|
|
276
276
|
|
|
277
277
|
await expect(
|
|
278
|
-
|
|
278
|
+
AccountOperation.selectApprovals({
|
|
279
279
|
account,
|
|
280
280
|
approvals: [invalid],
|
|
281
281
|
config,
|
|
282
282
|
hash,
|
|
283
283
|
}),
|
|
284
284
|
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
285
|
-
`[
|
|
285
|
+
`[AccountOperation.InvalidApprovalError: Invalid operation approval: signature from owner 0x07e1ed8ea0e9601e5546b0a03aed683df3601407 is invalid.]`,
|
|
286
286
|
)
|
|
287
287
|
await expect(
|
|
288
|
-
|
|
288
|
+
AccountOperation.selectApprovals({
|
|
289
289
|
account,
|
|
290
290
|
approvals: [nonOwner],
|
|
291
291
|
config,
|
|
292
292
|
hash,
|
|
293
293
|
}),
|
|
294
294
|
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
295
|
-
`[
|
|
295
|
+
`[AccountOperation.InvalidApprovalError: Invalid operation approval: signature is from non-owner 0xd3a9f047ad43d7e2e4e7e491f1fe2e657a2651b6.]`,
|
|
296
296
|
)
|
|
297
297
|
})
|
|
298
298
|
})
|
|
@@ -301,13 +301,13 @@ describe('serializeKeyAuthorization', () => {
|
|
|
301
301
|
test('current and initial authorizations', async () => {
|
|
302
302
|
const results = []
|
|
303
303
|
for (const applicableConfig of [currentConfig, config]) {
|
|
304
|
-
const hash =
|
|
304
|
+
const hash = AccountOperation.getHash({
|
|
305
305
|
account,
|
|
306
306
|
config: applicableConfig,
|
|
307
307
|
keyAuthorization,
|
|
308
308
|
type: 'keyAuthorization',
|
|
309
309
|
})
|
|
310
|
-
const selection = await
|
|
310
|
+
const selection = await AccountOperation.selectApprovals({
|
|
311
311
|
account,
|
|
312
312
|
approvals: [
|
|
313
313
|
signApproval(owners[1]!, hash),
|
|
@@ -316,7 +316,7 @@ describe('serializeKeyAuthorization', () => {
|
|
|
316
316
|
config: applicableConfig,
|
|
317
317
|
hash,
|
|
318
318
|
})
|
|
319
|
-
const serialized =
|
|
319
|
+
const serialized = AccountOperation.serializeKeyAuthorization(
|
|
320
320
|
keyAuthorization,
|
|
321
321
|
{
|
|
322
322
|
account,
|
|
@@ -327,16 +327,16 @@ describe('serializeKeyAuthorization', () => {
|
|
|
327
327
|
const value = KeyAuthorization.deserialize(serialized)
|
|
328
328
|
results.push({
|
|
329
329
|
account:
|
|
330
|
-
value.signature?.type === '
|
|
330
|
+
value.signature?.type === 'configurable'
|
|
331
331
|
? value.signature.account
|
|
332
332
|
: undefined,
|
|
333
333
|
hash: Hash.keccak256(serialized),
|
|
334
334
|
signatureCount:
|
|
335
|
-
value.signature?.type === '
|
|
335
|
+
value.signature?.type === 'configurable'
|
|
336
336
|
? value.signature.signatures.length
|
|
337
337
|
: 0,
|
|
338
338
|
version:
|
|
339
|
-
value.signature?.type === '
|
|
339
|
+
value.signature?.type === 'configurable'
|
|
340
340
|
? value.signature.config.version
|
|
341
341
|
: undefined,
|
|
342
342
|
})
|
|
@@ -361,7 +361,7 @@ describe('serializeKeyAuthorization', () => {
|
|
|
361
361
|
})
|
|
362
362
|
|
|
363
363
|
test('rejects a signed authorization', async () => {
|
|
364
|
-
const selection = await
|
|
364
|
+
const selection = await AccountOperation.selectApprovals({
|
|
365
365
|
account,
|
|
366
366
|
approvals: [
|
|
367
367
|
signApproval(owners[0]!, keyAuthorizationHash),
|
|
@@ -370,7 +370,7 @@ describe('serializeKeyAuthorization', () => {
|
|
|
370
370
|
config: currentConfig,
|
|
371
371
|
hash: keyAuthorizationHash,
|
|
372
372
|
})
|
|
373
|
-
const signed =
|
|
373
|
+
const signed = AccountOperation.serializeKeyAuthorization(
|
|
374
374
|
keyAuthorization,
|
|
375
375
|
{
|
|
376
376
|
account,
|
|
@@ -380,13 +380,13 @@ describe('serializeKeyAuthorization', () => {
|
|
|
380
380
|
)
|
|
381
381
|
|
|
382
382
|
expect(() =>
|
|
383
|
-
|
|
383
|
+
AccountOperation.serializeKeyAuthorization(signed, {
|
|
384
384
|
account,
|
|
385
385
|
approvals: selection.selectedApprovals,
|
|
386
386
|
config: currentConfig,
|
|
387
387
|
}),
|
|
388
388
|
).toThrowErrorMatchingInlineSnapshot(
|
|
389
|
-
`[
|
|
389
|
+
`[AccountOperation.InvalidOperationError: Invalid account operation: keyAuthorization must not contain a signature.]`,
|
|
390
390
|
)
|
|
391
391
|
})
|
|
392
392
|
})
|
|
@@ -395,13 +395,13 @@ describe('serializeTransaction', () => {
|
|
|
395
395
|
test('current and initial transactions', async () => {
|
|
396
396
|
const results = []
|
|
397
397
|
for (const applicableConfig of [currentConfig, config]) {
|
|
398
|
-
const hash =
|
|
398
|
+
const hash = AccountOperation.getHash({
|
|
399
399
|
account,
|
|
400
400
|
config: applicableConfig,
|
|
401
401
|
transaction,
|
|
402
402
|
type: 'transaction',
|
|
403
403
|
})
|
|
404
|
-
const selection = await
|
|
404
|
+
const selection = await AccountOperation.selectApprovals({
|
|
405
405
|
account,
|
|
406
406
|
approvals: [
|
|
407
407
|
signApproval(owners[1]!, hash),
|
|
@@ -410,7 +410,7 @@ describe('serializeTransaction', () => {
|
|
|
410
410
|
config: applicableConfig,
|
|
411
411
|
hash,
|
|
412
412
|
})
|
|
413
|
-
const operation =
|
|
413
|
+
const operation = AccountOperation.from({
|
|
414
414
|
account,
|
|
415
415
|
approvals: selection.approvals,
|
|
416
416
|
config: applicableConfig,
|
|
@@ -424,19 +424,19 @@ describe('serializeTransaction', () => {
|
|
|
424
424
|
updatedAt: 1,
|
|
425
425
|
weight: selection.weight,
|
|
426
426
|
})
|
|
427
|
-
const serialized =
|
|
427
|
+
const serialized = AccountOperation.serializeTransaction(operation, {
|
|
428
428
|
approvals: selection.selectedApprovals,
|
|
429
429
|
})
|
|
430
430
|
const value = TxEnvelopeTempo.deserialize(serialized)
|
|
431
431
|
results.push({
|
|
432
432
|
account: value.signature?.account,
|
|
433
433
|
version:
|
|
434
|
-
value.signature?.type === '
|
|
434
|
+
value.signature?.type === 'configurable'
|
|
435
435
|
? value.signature.config.version
|
|
436
436
|
: undefined,
|
|
437
437
|
hash: Hash.keccak256(serialized),
|
|
438
438
|
signatureCount:
|
|
439
|
-
value.signature?.type === '
|
|
439
|
+
value.signature?.type === 'configurable'
|
|
440
440
|
? value.signature.signatures.length
|
|
441
441
|
: 0,
|
|
442
442
|
type: serialized.slice(0, 4),
|
|
@@ -487,13 +487,13 @@ describe('serializeTransaction', () => {
|
|
|
487
487
|
] as const
|
|
488
488
|
const results = []
|
|
489
489
|
for (const transaction of transactions) {
|
|
490
|
-
const hash =
|
|
490
|
+
const hash = AccountOperation.getHash({
|
|
491
491
|
account,
|
|
492
492
|
config: currentConfig,
|
|
493
493
|
transaction,
|
|
494
494
|
type: 'transaction',
|
|
495
495
|
})
|
|
496
|
-
const selection = await
|
|
496
|
+
const selection = await AccountOperation.selectApprovals({
|
|
497
497
|
account,
|
|
498
498
|
approvals: [
|
|
499
499
|
signApproval(owners[0]!, hash),
|
|
@@ -502,8 +502,8 @@ describe('serializeTransaction', () => {
|
|
|
502
502
|
config: currentConfig,
|
|
503
503
|
hash,
|
|
504
504
|
})
|
|
505
|
-
const serialized =
|
|
506
|
-
|
|
505
|
+
const serialized = AccountOperation.serializeTransaction(
|
|
506
|
+
AccountOperation.from({
|
|
507
507
|
account,
|
|
508
508
|
approvals: selection.approvals,
|
|
509
509
|
config: currentConfig,
|
|
@@ -524,7 +524,7 @@ describe('serializeTransaction', () => {
|
|
|
524
524
|
feePayerSignature: value.feePayerSignature,
|
|
525
525
|
from: value.from,
|
|
526
526
|
signatureCount:
|
|
527
|
-
value.signature?.type === '
|
|
527
|
+
value.signature?.type === 'configurable'
|
|
528
528
|
? value.signature.signatures.length
|
|
529
529
|
: 0,
|
|
530
530
|
type: serialized.slice(0, 4),
|
|
@@ -554,7 +554,7 @@ describe('serializeTransaction', () => {
|
|
|
554
554
|
})
|
|
555
555
|
|
|
556
556
|
test('rejects an approval not retained by the operation', async () => {
|
|
557
|
-
const hash =
|
|
557
|
+
const hash = AccountOperation.getHash({
|
|
558
558
|
account,
|
|
559
559
|
config: currentConfig,
|
|
560
560
|
transaction,
|
|
@@ -562,13 +562,13 @@ describe('serializeTransaction', () => {
|
|
|
562
562
|
})
|
|
563
563
|
const approval_1 = signApproval(owners[0]!, hash)
|
|
564
564
|
const approval_2 = signApproval(owners[1]!, hash)
|
|
565
|
-
const selection = await
|
|
565
|
+
const selection = await AccountOperation.selectApprovals({
|
|
566
566
|
account,
|
|
567
567
|
approvals: [approval_1],
|
|
568
568
|
config: currentConfig,
|
|
569
569
|
hash,
|
|
570
570
|
})
|
|
571
|
-
const operation =
|
|
571
|
+
const operation = AccountOperation.from({
|
|
572
572
|
account,
|
|
573
573
|
approvals: selection.approvals,
|
|
574
574
|
config: currentConfig,
|
|
@@ -584,19 +584,19 @@ describe('serializeTransaction', () => {
|
|
|
584
584
|
})
|
|
585
585
|
|
|
586
586
|
expect(() =>
|
|
587
|
-
|
|
587
|
+
AccountOperation.serializeTransaction(operation, {
|
|
588
588
|
approvals: [approval_2],
|
|
589
589
|
}),
|
|
590
590
|
).toThrowErrorMatchingInlineSnapshot(
|
|
591
|
-
`[
|
|
591
|
+
`[AccountOperation.InvalidOperationError: Invalid account operation: transaction signature is not a retained approval.]`,
|
|
592
592
|
)
|
|
593
593
|
})
|
|
594
594
|
})
|
|
595
595
|
|
|
596
596
|
describe('from', () => {
|
|
597
597
|
test('transaction states', () => {
|
|
598
|
-
const pending =
|
|
599
|
-
const submitting =
|
|
598
|
+
const pending = AccountOperation.from(transactionPending)
|
|
599
|
+
const submitting = AccountOperation.from({
|
|
600
600
|
...transactionPending,
|
|
601
601
|
approvals: [approval_1, approval_2],
|
|
602
602
|
expiresAt: 10,
|
|
@@ -605,7 +605,7 @@ describe('from', () => {
|
|
|
605
605
|
submissionId,
|
|
606
606
|
weight: 2,
|
|
607
607
|
})
|
|
608
|
-
const success =
|
|
608
|
+
const success = AccountOperation.from({
|
|
609
609
|
...transactionPending,
|
|
610
610
|
approvals: [approval_1, approval_2],
|
|
611
611
|
signatureCount: 2,
|
|
@@ -723,9 +723,9 @@ describe('from', () => {
|
|
|
723
723
|
}),
|
|
724
724
|
{ format: 'feePayer', sender: account },
|
|
725
725
|
)
|
|
726
|
-
const operation =
|
|
726
|
+
const operation = AccountOperation.from({
|
|
727
727
|
...transactionPending,
|
|
728
|
-
hash:
|
|
728
|
+
hash: AccountConfig.getSignPayload({
|
|
729
729
|
account,
|
|
730
730
|
config: currentConfig,
|
|
731
731
|
payload: TxEnvelopeTempo.getSignPayload(
|
|
@@ -793,9 +793,9 @@ describe('from', () => {
|
|
|
793
793
|
}),
|
|
794
794
|
{ format: 'feePayer' },
|
|
795
795
|
)
|
|
796
|
-
const operation =
|
|
796
|
+
const operation = AccountOperation.from({
|
|
797
797
|
...transactionPending,
|
|
798
|
-
hash:
|
|
798
|
+
hash: AccountConfig.getSignPayload({
|
|
799
799
|
account,
|
|
800
800
|
config: currentConfig,
|
|
801
801
|
payload: TxEnvelopeTempo.getSignPayload(
|
|
@@ -814,10 +814,10 @@ describe('from', () => {
|
|
|
814
814
|
})
|
|
815
815
|
|
|
816
816
|
test('initial transaction', () => {
|
|
817
|
-
const operation =
|
|
817
|
+
const operation = AccountOperation.from({
|
|
818
818
|
...transactionPending,
|
|
819
819
|
config,
|
|
820
|
-
hash:
|
|
820
|
+
hash: AccountConfig.getSignPayload({
|
|
821
821
|
account,
|
|
822
822
|
config,
|
|
823
823
|
payload: TxEnvelopeTempo.getSignPayload(
|
|
@@ -867,9 +867,9 @@ describe('from', () => {
|
|
|
867
867
|
})
|
|
868
868
|
|
|
869
869
|
test('key authorization states', () => {
|
|
870
|
-
const pending =
|
|
870
|
+
const pending = AccountOperation.from(keyAuthorizationPending)
|
|
871
871
|
const authorization = KeyAuthorization.deserialize(keyAuthorization)
|
|
872
|
-
const success =
|
|
872
|
+
const success = AccountOperation.from({
|
|
873
873
|
...keyAuthorizationPending,
|
|
874
874
|
approvals: [approval_1, approval_2],
|
|
875
875
|
keyAuthorization: KeyAuthorization.serialize(
|
|
@@ -878,7 +878,7 @@ describe('from', () => {
|
|
|
878
878
|
account,
|
|
879
879
|
config: currentConfig,
|
|
880
880
|
signatures: [ownerSignature_1, owners[1]!.signature],
|
|
881
|
-
type: '
|
|
881
|
+
type: 'configurable',
|
|
882
882
|
},
|
|
883
883
|
}),
|
|
884
884
|
),
|
|
@@ -962,15 +962,15 @@ describe('from', () => {
|
|
|
962
962
|
account,
|
|
963
963
|
config,
|
|
964
964
|
signatures: [ownerSignature_1, owners[1]!.signature],
|
|
965
|
-
type: '
|
|
965
|
+
type: 'configurable',
|
|
966
966
|
},
|
|
967
967
|
}),
|
|
968
968
|
)
|
|
969
|
-
const operation =
|
|
969
|
+
const operation = AccountOperation.from({
|
|
970
970
|
...keyAuthorizationPending,
|
|
971
971
|
approvals: [approval_1, approval_2],
|
|
972
972
|
config,
|
|
973
|
-
hash:
|
|
973
|
+
hash: AccountConfig.getSignPayload({
|
|
974
974
|
account,
|
|
975
975
|
config,
|
|
976
976
|
payload: KeyAuthorization.getSignPayload(authorization),
|
|
@@ -1025,8 +1025,8 @@ describe('from', () => {
|
|
|
1025
1025
|
|
|
1026
1026
|
describe('RPC conversion', () => {
|
|
1027
1027
|
test('round-trips transaction and key authorization operations', () => {
|
|
1028
|
-
const transactionRpc =
|
|
1029
|
-
const keyAuthorizationRpc =
|
|
1028
|
+
const transactionRpc = AccountOperation.toRpc(transactionPending)
|
|
1029
|
+
const keyAuthorizationRpc = AccountOperation.toRpc(keyAuthorizationPending)
|
|
1030
1030
|
|
|
1031
1031
|
expect(() =>
|
|
1032
1032
|
JSON.stringify({ keyAuthorizationRpc, transactionRpc }),
|
|
@@ -1095,11 +1095,11 @@ describe('RPC conversion', () => {
|
|
|
1095
1095
|
},
|
|
1096
1096
|
}
|
|
1097
1097
|
`)
|
|
1098
|
-
expect(
|
|
1099
|
-
|
|
1098
|
+
expect(AccountOperation.fromRpc(transactionRpc)).toStrictEqual(
|
|
1099
|
+
AccountOperation.from(transactionPending),
|
|
1100
1100
|
)
|
|
1101
|
-
expect(
|
|
1102
|
-
|
|
1101
|
+
expect(AccountOperation.fromRpc(keyAuthorizationRpc)).toStrictEqual(
|
|
1102
|
+
AccountOperation.from(keyAuthorizationPending),
|
|
1103
1103
|
)
|
|
1104
1104
|
})
|
|
1105
1105
|
})
|
|
@@ -1196,7 +1196,7 @@ describe('validation', () => {
|
|
|
1196
1196
|
name: 'weight unreachable by the retained owner approvals',
|
|
1197
1197
|
operation: {
|
|
1198
1198
|
...transactionPending,
|
|
1199
|
-
config:
|
|
1199
|
+
config: AccountConfig.from({
|
|
1200
1200
|
owners: [
|
|
1201
1201
|
{ owner: owner_1, weight: 1 },
|
|
1202
1202
|
{ owner: owner_2, weight: 2 },
|
|
@@ -1215,7 +1215,7 @@ describe('validation', () => {
|
|
|
1215
1215
|
operation: {
|
|
1216
1216
|
...transactionPending,
|
|
1217
1217
|
account: '0x0000000000000000000000000000000000000000',
|
|
1218
|
-
hash:
|
|
1218
|
+
hash: AccountConfig.getSignPayload({
|
|
1219
1219
|
account: '0x0000000000000000000000000000000000000000',
|
|
1220
1220
|
config: currentConfig,
|
|
1221
1221
|
payload: TxEnvelopeTempo.getSignPayload(
|
|
@@ -1292,21 +1292,21 @@ describe('validation', () => {
|
|
|
1292
1292
|
account,
|
|
1293
1293
|
config,
|
|
1294
1294
|
signatures: [ownerSignature_1],
|
|
1295
|
-
type: '
|
|
1295
|
+
type: 'configurable',
|
|
1296
1296
|
}),
|
|
1297
1297
|
],
|
|
1298
1298
|
},
|
|
1299
1299
|
},
|
|
1300
1300
|
])('rejects $name', ({ operation }) => {
|
|
1301
1301
|
expect(() =>
|
|
1302
|
-
|
|
1303
|
-
).toThrowError(
|
|
1302
|
+
AccountOperation.from(operation as AccountOperation.Operation),
|
|
1303
|
+
).toThrowError(AccountOperation.InvalidOperationError)
|
|
1304
1304
|
})
|
|
1305
1305
|
test('accepts initial accounts validated by the chain', () => {
|
|
1306
|
-
const value =
|
|
1306
|
+
const value = AccountOperation.from({
|
|
1307
1307
|
...transactionPending,
|
|
1308
1308
|
config,
|
|
1309
|
-
hash:
|
|
1309
|
+
hash: AccountOperation.getHash({
|
|
1310
1310
|
account,
|
|
1311
1311
|
config,
|
|
1312
1312
|
transaction,
|
|
@@ -1318,14 +1318,14 @@ describe('validation', () => {
|
|
|
1318
1318
|
})
|
|
1319
1319
|
|
|
1320
1320
|
test('rejects noncanonical RPC quantities', () => {
|
|
1321
|
-
const operation =
|
|
1321
|
+
const operation = AccountOperation.toRpc(transactionPending)
|
|
1322
1322
|
expect(() =>
|
|
1323
|
-
|
|
1323
|
+
AccountOperation.fromRpc({
|
|
1324
1324
|
...operation,
|
|
1325
1325
|
config: { ...operation.config, version: '0x01' },
|
|
1326
1326
|
}),
|
|
1327
1327
|
).toThrowError(
|
|
1328
|
-
'Invalid
|
|
1328
|
+
'Invalid account operation: config.version must use canonical quantity encoding.',
|
|
1329
1329
|
)
|
|
1330
1330
|
})
|
|
1331
1331
|
|
|
@@ -1340,7 +1340,7 @@ describe('validation', () => {
|
|
|
1340
1340
|
account,
|
|
1341
1341
|
config: currentConfig,
|
|
1342
1342
|
signatures: [ownerSignature_1, owners[2]!.signature],
|
|
1343
|
-
type: '
|
|
1343
|
+
type: 'configurable',
|
|
1344
1344
|
},
|
|
1345
1345
|
}),
|
|
1346
1346
|
),
|
|
@@ -1349,15 +1349,15 @@ describe('validation', () => {
|
|
|
1349
1349
|
weight: 2,
|
|
1350
1350
|
} as const
|
|
1351
1351
|
|
|
1352
|
-
expect(() =>
|
|
1353
|
-
'Invalid
|
|
1352
|
+
expect(() => AccountOperation.from(operation)).toThrowError(
|
|
1353
|
+
'Invalid account operation: key authorization signature is not a retained approval.',
|
|
1354
1354
|
)
|
|
1355
1355
|
})
|
|
1356
1356
|
|
|
1357
1357
|
test('rejects unordered key authorization approvals', () => {
|
|
1358
1358
|
const authorization = KeyAuthorization.deserialize(keyAuthorization)
|
|
1359
1359
|
const signatures = [
|
|
1360
|
-
...SignatureEnvelope.
|
|
1360
|
+
...SignatureEnvelope.sortApprovals({
|
|
1361
1361
|
account,
|
|
1362
1362
|
config: currentConfig,
|
|
1363
1363
|
payload: KeyAuthorization.getSignPayload(authorization),
|
|
@@ -1373,7 +1373,7 @@ describe('validation', () => {
|
|
|
1373
1373
|
account,
|
|
1374
1374
|
config: currentConfig,
|
|
1375
1375
|
signatures,
|
|
1376
|
-
type: '
|
|
1376
|
+
type: 'configurable',
|
|
1377
1377
|
},
|
|
1378
1378
|
}),
|
|
1379
1379
|
),
|
|
@@ -1382,8 +1382,8 @@ describe('validation', () => {
|
|
|
1382
1382
|
weight: 2,
|
|
1383
1383
|
} as const
|
|
1384
1384
|
|
|
1385
|
-
expect(() =>
|
|
1386
|
-
'Invalid
|
|
1385
|
+
expect(() => AccountOperation.from(operation)).toThrowError(
|
|
1386
|
+
'Invalid account operation: key authorization approvals are not canonically ordered.',
|
|
1387
1387
|
)
|
|
1388
1388
|
})
|
|
1389
1389
|
|
|
@@ -1398,7 +1398,7 @@ describe('validation', () => {
|
|
|
1398
1398
|
account,
|
|
1399
1399
|
config: currentConfig,
|
|
1400
1400
|
signatures: [ownerSignature_1, ownerSignature_1],
|
|
1401
|
-
type: '
|
|
1401
|
+
type: 'configurable',
|
|
1402
1402
|
},
|
|
1403
1403
|
}),
|
|
1404
1404
|
),
|
|
@@ -1407,13 +1407,13 @@ describe('validation', () => {
|
|
|
1407
1407
|
weight: 2,
|
|
1408
1408
|
} as const
|
|
1409
1409
|
|
|
1410
|
-
expect(() =>
|
|
1411
|
-
'Invalid
|
|
1410
|
+
expect(() => AccountOperation.from(operation)).toThrowError(
|
|
1411
|
+
'Invalid account operation: key authorization contains duplicate owner approvals.',
|
|
1412
1412
|
)
|
|
1413
1413
|
})
|
|
1414
1414
|
|
|
1415
1415
|
test('accepts case-insensitive initial configs', () => {
|
|
1416
|
-
const config =
|
|
1416
|
+
const config = AccountConfig.from({
|
|
1417
1417
|
owners: [
|
|
1418
1418
|
{
|
|
1419
1419
|
owner: Address.checksum(owner_1),
|
|
@@ -1427,7 +1427,7 @@ describe('validation', () => {
|
|
|
1427
1427
|
salt: `0x${'AB'.repeat(32)}`,
|
|
1428
1428
|
threshold: 2,
|
|
1429
1429
|
})
|
|
1430
|
-
const account =
|
|
1430
|
+
const account = AccountConfig.getAddress(config, { factory })
|
|
1431
1431
|
const authorization = KeyAuthorization.from({
|
|
1432
1432
|
account,
|
|
1433
1433
|
address: '0x3333333333333333333333333333333333333333',
|
|
@@ -1436,7 +1436,7 @@ describe('validation', () => {
|
|
|
1436
1436
|
isAdmin: false,
|
|
1437
1437
|
type: 'secp256k1',
|
|
1438
1438
|
})
|
|
1439
|
-
const signatures = SignatureEnvelope.
|
|
1439
|
+
const signatures = SignatureEnvelope.sortApprovals({
|
|
1440
1440
|
account,
|
|
1441
1441
|
config,
|
|
1442
1442
|
payload: KeyAuthorization.getSignPayload(authorization),
|
|
@@ -1446,12 +1446,12 @@ describe('validation', () => {
|
|
|
1446
1446
|
SignatureEnvelope.serialize(signature),
|
|
1447
1447
|
)
|
|
1448
1448
|
|
|
1449
|
-
const operation =
|
|
1449
|
+
const operation = AccountOperation.from({
|
|
1450
1450
|
account,
|
|
1451
1451
|
approvals,
|
|
1452
1452
|
config,
|
|
1453
1453
|
createdAt: 1,
|
|
1454
|
-
hash:
|
|
1454
|
+
hash: AccountConfig.getSignPayload({
|
|
1455
1455
|
account,
|
|
1456
1456
|
config,
|
|
1457
1457
|
payload: KeyAuthorization.getSignPayload(authorization),
|
|
@@ -1462,7 +1462,7 @@ describe('validation', () => {
|
|
|
1462
1462
|
account,
|
|
1463
1463
|
config,
|
|
1464
1464
|
signatures,
|
|
1465
|
-
type: '
|
|
1465
|
+
type: 'configurable',
|
|
1466
1466
|
},
|
|
1467
1467
|
}),
|
|
1468
1468
|
),
|