ox 0.14.55 → 0.14.56
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/_cjs/tempo/{MultisigConfig.js → AccountConfig.js} +16 -4
- package/_cjs/tempo/AccountConfig.js.map +1 -0
- package/_cjs/tempo/{MultisigOperation.js → AccountOperation.js} +29 -29
- package/_cjs/tempo/AccountOperation.js.map +1 -0
- package/_cjs/tempo/{MultisigSimulation.js → AccountSimulation.js} +9 -9
- package/_cjs/tempo/AccountSimulation.js.map +1 -0
- package/_cjs/tempo/KeyAuthorization.js +12 -11
- package/_cjs/tempo/KeyAuthorization.js.map +1 -1
- package/_cjs/tempo/SignatureEnvelope.js +64 -64
- package/_cjs/tempo/SignatureEnvelope.js.map +1 -1
- package/_cjs/tempo/TransactionRequest.js +12 -9
- package/_cjs/tempo/TransactionRequest.js.map +1 -1
- package/_cjs/tempo/index.js +4 -4
- package/_cjs/tempo/index.js.map +1 -1
- package/_cjs/version.js +1 -1
- package/_esm/tempo/{MultisigConfig.js → AccountConfig.js} +103 -55
- package/_esm/tempo/AccountConfig.js.map +1 -0
- package/_esm/tempo/{MultisigOperation.js → AccountOperation.js} +64 -64
- package/_esm/tempo/AccountOperation.js.map +1 -0
- package/_esm/tempo/{MultisigSimulation.js → AccountSimulation.js} +20 -20
- package/_esm/tempo/AccountSimulation.js.map +1 -0
- package/_esm/tempo/KeyAuthorization.js +13 -12
- package/_esm/tempo/KeyAuthorization.js.map +1 -1
- package/_esm/tempo/SignatureEnvelope.js +71 -71
- package/_esm/tempo/SignatureEnvelope.js.map +1 -1
- package/_esm/tempo/TransactionRequest.js +12 -9
- package/_esm/tempo/TransactionRequest.js.map +1 -1
- package/_esm/tempo/index.js +50 -48
- package/_esm/tempo/index.js.map +1 -1
- package/_esm/version.js +1 -1
- package/_types/tempo/{MultisigConfig.d.ts → AccountConfig.d.ts} +110 -63
- package/_types/tempo/AccountConfig.d.ts.map +1 -0
- package/_types/tempo/{MultisigOperation.d.ts → AccountOperation.d.ts} +62 -62
- package/_types/tempo/AccountOperation.d.ts.map +1 -0
- package/_types/tempo/{MultisigSimulation.d.ts → AccountSimulation.d.ts} +21 -21
- package/_types/tempo/AccountSimulation.d.ts.map +1 -0
- package/_types/tempo/KeyAuthorization.d.ts +14 -14
- package/_types/tempo/KeyAuthorization.d.ts.map +1 -1
- package/_types/tempo/RpcSchemaTempo.d.ts +13 -13
- package/_types/tempo/RpcSchemaTempo.d.ts.map +1 -1
- package/_types/tempo/SignatureEnvelope.d.ts +36 -33
- package/_types/tempo/SignatureEnvelope.d.ts.map +1 -1
- package/_types/tempo/TransactionRequest.d.ts +11 -9
- package/_types/tempo/TransactionRequest.d.ts.map +1 -1
- package/_types/tempo/index.d.ts +50 -48
- package/_types/tempo/index.d.ts.map +1 -1
- package/_types/version.d.ts +1 -1
- package/package.json +31 -31
- package/tempo/AccountConfig/package.json +6 -0
- package/tempo/AccountConfig.test-d/package.json +6 -0
- package/tempo/{MultisigConfig.test-d.ts → AccountConfig.test-d.ts} +22 -12
- package/tempo/{MultisigConfig.test.ts → AccountConfig.test.ts} +155 -37
- package/tempo/{MultisigConfig.ts → AccountConfig.ts} +132 -66
- package/tempo/AccountOperation/package.json +6 -0
- package/tempo/AccountOperation.test-d/package.json +6 -0
- package/tempo/AccountOperation.test-d.ts +71 -0
- package/tempo/{MultisigOperation.test.ts → AccountOperation.test.ts} +97 -97
- package/tempo/{MultisigOperation.ts → AccountOperation.ts} +95 -97
- package/tempo/AccountSimulation/package.json +6 -0
- package/tempo/AccountSimulation.test-d/package.json +6 -0
- package/tempo/{MultisigSimulation.test-d.ts → AccountSimulation.test-d.ts} +7 -9
- package/tempo/{MultisigSimulation.test.ts → AccountSimulation.test.ts} +29 -29
- package/tempo/{MultisigSimulation.ts → AccountSimulation.ts} +28 -30
- package/tempo/KeyAuthorization.test-d.ts +14 -14
- package/tempo/KeyAuthorization.test.ts +70 -49
- package/tempo/KeyAuthorization.ts +29 -27
- package/tempo/RpcSchemaTempo.test-d.ts +19 -19
- package/tempo/RpcSchemaTempo.ts +13 -13
- package/tempo/SignatureEnvelope.test-d.ts +7 -7
- package/tempo/SignatureEnvelope.test.ts +34 -34
- package/tempo/SignatureEnvelope.ts +107 -103
- package/tempo/Transaction.test.ts +4 -4
- package/tempo/TransactionRequest.test-d.ts +16 -7
- package/tempo/TransactionRequest.test.ts +25 -17
- package/tempo/TransactionRequest.ts +25 -18
- package/tempo/{multisig.e2e.test.ts → configurableAccounts.e2e.test.ts} +16 -16
- package/tempo/index.ts +50 -48
- package/version.ts +1 -1
- package/_cjs/tempo/MultisigConfig.js.map +0 -1
- package/_cjs/tempo/MultisigOperation.js.map +0 -1
- package/_cjs/tempo/MultisigSimulation.js.map +0 -1
- package/_esm/tempo/MultisigConfig.js.map +0 -1
- package/_esm/tempo/MultisigOperation.js.map +0 -1
- package/_esm/tempo/MultisigSimulation.js.map +0 -1
- package/_types/tempo/MultisigConfig.d.ts.map +0 -1
- package/_types/tempo/MultisigOperation.d.ts.map +0 -1
- package/_types/tempo/MultisigSimulation.d.ts.map +0 -1
- package/tempo/MultisigConfig/package.json +0 -6
- package/tempo/MultisigConfig.test-d/package.json +0 -6
- package/tempo/MultisigOperation/package.json +0 -6
- package/tempo/MultisigOperation.test-d/package.json +0 -6
- package/tempo/MultisigOperation.test-d.ts +0 -71
- package/tempo/MultisigSimulation/package.json +0 -6
- package/tempo/MultisigSimulation.test-d/package.json +0 -6
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Address, Hash, P256 } from 'ox'
|
|
2
2
|
import {
|
|
3
|
+
AccountConfig,
|
|
4
|
+
AccountOperation,
|
|
3
5
|
KeyAuthorization,
|
|
4
|
-
MultisigConfig,
|
|
5
|
-
MultisigOperation,
|
|
6
6
|
SignatureEnvelope,
|
|
7
7
|
TxEnvelopeTempo,
|
|
8
8
|
} from 'ox/tempo'
|
|
9
9
|
import { describe, expect, test } from 'vitest'
|
|
10
|
-
import { factory } from '../../test/tempo/
|
|
10
|
+
import { factory } from '../../test/tempo/configurableAccounts.js'
|
|
11
11
|
|
|
12
12
|
const owners = [1n, 2n, 3n]
|
|
13
13
|
.map((value, index) => {
|
|
@@ -30,15 +30,15 @@ const owners = [1n, 2n, 3n]
|
|
|
30
30
|
.sort((a, b) => a.address.localeCompare(b.address))
|
|
31
31
|
const owner_1 = owners[0]!.address
|
|
32
32
|
const owner_2 = owners[1]!.address
|
|
33
|
-
const config =
|
|
33
|
+
const config = AccountConfig.from({
|
|
34
34
|
owners: [
|
|
35
35
|
{ owner: owner_1, weight: 1 },
|
|
36
36
|
{ owner: owner_2, weight: 1 },
|
|
37
37
|
],
|
|
38
38
|
threshold: 2,
|
|
39
39
|
})
|
|
40
|
-
const currentConfig =
|
|
41
|
-
const account =
|
|
40
|
+
const currentConfig = AccountConfig.from({ ...config, version: 1n })
|
|
41
|
+
const account = AccountConfig.getAddress(config, { factory })
|
|
42
42
|
const ownerSignature_1 = owners[0]!.signature
|
|
43
43
|
const approval_1 = SignatureEnvelope.serialize(ownerSignature_1)
|
|
44
44
|
const approval_2 = SignatureEnvelope.serialize(owners[1]!.signature)
|
|
@@ -62,14 +62,14 @@ const keyAuthorization = KeyAuthorization.serialize(
|
|
|
62
62
|
}),
|
|
63
63
|
)
|
|
64
64
|
|
|
65
|
-
const transactionHash_ =
|
|
65
|
+
const transactionHash_ = AccountConfig.getSignPayload({
|
|
66
66
|
account,
|
|
67
67
|
config: currentConfig,
|
|
68
68
|
payload: TxEnvelopeTempo.getSignPayload(
|
|
69
69
|
TxEnvelopeTempo.deserialize(transaction),
|
|
70
70
|
),
|
|
71
71
|
})
|
|
72
|
-
const keyAuthorizationHash =
|
|
72
|
+
const keyAuthorizationHash = AccountConfig.getSignPayload({
|
|
73
73
|
account,
|
|
74
74
|
config: currentConfig,
|
|
75
75
|
payload: KeyAuthorization.getSignPayload(
|
|
@@ -136,13 +136,13 @@ function approvalAddresses(
|
|
|
136
136
|
describe('getHash', () => {
|
|
137
137
|
test('transaction and key authorization', () => {
|
|
138
138
|
expect({
|
|
139
|
-
keyAuthorization:
|
|
139
|
+
keyAuthorization: AccountOperation.getHash({
|
|
140
140
|
account,
|
|
141
141
|
config: currentConfig,
|
|
142
142
|
keyAuthorization,
|
|
143
143
|
type: 'keyAuthorization',
|
|
144
144
|
}),
|
|
145
|
-
transaction:
|
|
145
|
+
transaction: AccountOperation.getHash({
|
|
146
146
|
account,
|
|
147
147
|
config: currentConfig,
|
|
148
148
|
transaction,
|
|
@@ -159,7 +159,7 @@ describe('getHash', () => {
|
|
|
159
159
|
|
|
160
160
|
describe('selectApprovals', () => {
|
|
161
161
|
test('selects a deterministic weighted quorum', async () => {
|
|
162
|
-
const config =
|
|
162
|
+
const config = AccountConfig.from({
|
|
163
163
|
owners: [
|
|
164
164
|
{ owner: owners[0]!.address, weight: 2 },
|
|
165
165
|
{ owner: owners[1]!.address, weight: 1 },
|
|
@@ -167,8 +167,8 @@ describe('selectApprovals', () => {
|
|
|
167
167
|
],
|
|
168
168
|
threshold: 3,
|
|
169
169
|
})
|
|
170
|
-
const account =
|
|
171
|
-
const hash =
|
|
170
|
+
const account = AccountConfig.getAddress(config, { factory })
|
|
171
|
+
const hash = AccountOperation.getHash({
|
|
172
172
|
account,
|
|
173
173
|
config: { ...config, version: 1n },
|
|
174
174
|
transaction,
|
|
@@ -176,7 +176,7 @@ describe('selectApprovals', () => {
|
|
|
176
176
|
})
|
|
177
177
|
const approvals = owners.map((owner) => signApproval(owner, hash))
|
|
178
178
|
const alternate = signApproval(owners[0]!, hash, `0x${'01'.repeat(32)}`)
|
|
179
|
-
const selection = await
|
|
179
|
+
const selection = await AccountOperation.selectApprovals({
|
|
180
180
|
account,
|
|
181
181
|
approvals: [
|
|
182
182
|
approvals[2]!,
|
|
@@ -188,7 +188,7 @@ describe('selectApprovals', () => {
|
|
|
188
188
|
config,
|
|
189
189
|
hash,
|
|
190
190
|
})
|
|
191
|
-
const reversed = await
|
|
191
|
+
const reversed = await AccountOperation.selectApprovals({
|
|
192
192
|
account,
|
|
193
193
|
approvals: [
|
|
194
194
|
approvals[0]!,
|
|
@@ -224,7 +224,7 @@ describe('selectApprovals', () => {
|
|
|
224
224
|
`)
|
|
225
225
|
})
|
|
226
226
|
test('accepts an explicit account from a chain-configured factory', async () => {
|
|
227
|
-
const selected = await
|
|
227
|
+
const selected = await AccountOperation.selectApprovals({
|
|
228
228
|
account,
|
|
229
229
|
approvals: [],
|
|
230
230
|
config,
|
|
@@ -232,7 +232,7 @@ describe('selectApprovals', () => {
|
|
|
232
232
|
})
|
|
233
233
|
expect(selected.weight).toMatchInlineSnapshot(`0`)
|
|
234
234
|
})
|
|
235
|
-
test('rejects keychain and
|
|
235
|
+
test('rejects keychain and configurable owner approvals', async () => {
|
|
236
236
|
for (const signature of [
|
|
237
237
|
SignatureEnvelope.from({
|
|
238
238
|
inner: ownerSignature_1,
|
|
@@ -247,19 +247,19 @@ describe('selectApprovals', () => {
|
|
|
247
247
|
}),
|
|
248
248
|
])
|
|
249
249
|
await expect(
|
|
250
|
-
|
|
250
|
+
AccountOperation.selectApprovals({
|
|
251
251
|
account,
|
|
252
252
|
approvals: [SignatureEnvelope.serialize(signature)],
|
|
253
253
|
config,
|
|
254
254
|
hash: transactionHash_,
|
|
255
255
|
}),
|
|
256
256
|
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
257
|
-
`[
|
|
257
|
+
`[AccountOperation.InvalidApprovalError: Invalid operation approval: only primitive signatures can approve an account operation.]`,
|
|
258
258
|
)
|
|
259
259
|
})
|
|
260
260
|
|
|
261
261
|
test('rejects invalid and non-owner approvals', async () => {
|
|
262
|
-
const hash =
|
|
262
|
+
const hash = AccountOperation.getHash({
|
|
263
263
|
account,
|
|
264
264
|
config: currentConfig,
|
|
265
265
|
transaction,
|
|
@@ -272,24 +272,24 @@ describe('selectApprovals', () => {
|
|
|
272
272
|
const nonOwner = signApproval(owners[2]!, hash)
|
|
273
273
|
|
|
274
274
|
await expect(
|
|
275
|
-
|
|
275
|
+
AccountOperation.selectApprovals({
|
|
276
276
|
account,
|
|
277
277
|
approvals: [invalid],
|
|
278
278
|
config,
|
|
279
279
|
hash,
|
|
280
280
|
}),
|
|
281
281
|
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
282
|
-
`[
|
|
282
|
+
`[AccountOperation.InvalidApprovalError: Invalid operation approval: signature from owner 0x07e1ed8ea0e9601e5546b0a03aed683df3601407 is invalid.]`,
|
|
283
283
|
)
|
|
284
284
|
await expect(
|
|
285
|
-
|
|
285
|
+
AccountOperation.selectApprovals({
|
|
286
286
|
account,
|
|
287
287
|
approvals: [nonOwner],
|
|
288
288
|
config,
|
|
289
289
|
hash,
|
|
290
290
|
}),
|
|
291
291
|
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
292
|
-
`[
|
|
292
|
+
`[AccountOperation.InvalidApprovalError: Invalid operation approval: signature is from non-owner 0xd3a9f047ad43d7e2e4e7e491f1fe2e657a2651b6.]`,
|
|
293
293
|
)
|
|
294
294
|
})
|
|
295
295
|
})
|
|
@@ -298,13 +298,13 @@ describe('serializeKeyAuthorization', () => {
|
|
|
298
298
|
test('behavior: current and initial authorizations', async () => {
|
|
299
299
|
const results = []
|
|
300
300
|
for (const applicableConfig of [currentConfig, config]) {
|
|
301
|
-
const hash =
|
|
301
|
+
const hash = AccountOperation.getHash({
|
|
302
302
|
account,
|
|
303
303
|
config: applicableConfig,
|
|
304
304
|
keyAuthorization,
|
|
305
305
|
type: 'keyAuthorization',
|
|
306
306
|
})
|
|
307
|
-
const selection = await
|
|
307
|
+
const selection = await AccountOperation.selectApprovals({
|
|
308
308
|
account,
|
|
309
309
|
approvals: [
|
|
310
310
|
signApproval(owners[1]!, hash),
|
|
@@ -313,7 +313,7 @@ describe('serializeKeyAuthorization', () => {
|
|
|
313
313
|
config: applicableConfig,
|
|
314
314
|
hash,
|
|
315
315
|
})
|
|
316
|
-
const serialized =
|
|
316
|
+
const serialized = AccountOperation.serializeKeyAuthorization(
|
|
317
317
|
keyAuthorization,
|
|
318
318
|
{
|
|
319
319
|
account,
|
|
@@ -324,16 +324,16 @@ describe('serializeKeyAuthorization', () => {
|
|
|
324
324
|
const value = KeyAuthorization.deserialize(serialized)
|
|
325
325
|
results.push({
|
|
326
326
|
account:
|
|
327
|
-
value.signature?.type === '
|
|
327
|
+
value.signature?.type === 'configurable'
|
|
328
328
|
? value.signature.account
|
|
329
329
|
: undefined,
|
|
330
330
|
hash: Hash.keccak256(serialized),
|
|
331
331
|
signatureCount:
|
|
332
|
-
value.signature?.type === '
|
|
332
|
+
value.signature?.type === 'configurable'
|
|
333
333
|
? value.signature.signatures.length
|
|
334
334
|
: 0,
|
|
335
335
|
version:
|
|
336
|
-
value.signature?.type === '
|
|
336
|
+
value.signature?.type === 'configurable'
|
|
337
337
|
? value.signature.config.version
|
|
338
338
|
: undefined,
|
|
339
339
|
})
|
|
@@ -358,7 +358,7 @@ describe('serializeKeyAuthorization', () => {
|
|
|
358
358
|
})
|
|
359
359
|
|
|
360
360
|
test('error: signed authorization', async () => {
|
|
361
|
-
const selection = await
|
|
361
|
+
const selection = await AccountOperation.selectApprovals({
|
|
362
362
|
account,
|
|
363
363
|
approvals: [
|
|
364
364
|
signApproval(owners[0]!, keyAuthorizationHash),
|
|
@@ -367,7 +367,7 @@ describe('serializeKeyAuthorization', () => {
|
|
|
367
367
|
config: currentConfig,
|
|
368
368
|
hash: keyAuthorizationHash,
|
|
369
369
|
})
|
|
370
|
-
const signed =
|
|
370
|
+
const signed = AccountOperation.serializeKeyAuthorization(
|
|
371
371
|
keyAuthorization,
|
|
372
372
|
{
|
|
373
373
|
account,
|
|
@@ -377,13 +377,13 @@ describe('serializeKeyAuthorization', () => {
|
|
|
377
377
|
)
|
|
378
378
|
|
|
379
379
|
expect(() =>
|
|
380
|
-
|
|
380
|
+
AccountOperation.serializeKeyAuthorization(signed, {
|
|
381
381
|
account,
|
|
382
382
|
approvals: selection.selectedApprovals,
|
|
383
383
|
config: currentConfig,
|
|
384
384
|
}),
|
|
385
385
|
).toThrowErrorMatchingInlineSnapshot(
|
|
386
|
-
`[
|
|
386
|
+
`[AccountOperation.InvalidOperationError: Invalid account operation: keyAuthorization must not contain a signature.]`,
|
|
387
387
|
)
|
|
388
388
|
})
|
|
389
389
|
})
|
|
@@ -392,13 +392,13 @@ describe('serializeTransaction', () => {
|
|
|
392
392
|
test('current and initial transactions', async () => {
|
|
393
393
|
const results = []
|
|
394
394
|
for (const applicableConfig of [currentConfig, config]) {
|
|
395
|
-
const hash =
|
|
395
|
+
const hash = AccountOperation.getHash({
|
|
396
396
|
account,
|
|
397
397
|
config: applicableConfig,
|
|
398
398
|
transaction,
|
|
399
399
|
type: 'transaction',
|
|
400
400
|
})
|
|
401
|
-
const selection = await
|
|
401
|
+
const selection = await AccountOperation.selectApprovals({
|
|
402
402
|
account,
|
|
403
403
|
approvals: [
|
|
404
404
|
signApproval(owners[1]!, hash),
|
|
@@ -407,7 +407,7 @@ describe('serializeTransaction', () => {
|
|
|
407
407
|
config: applicableConfig,
|
|
408
408
|
hash,
|
|
409
409
|
})
|
|
410
|
-
const operation =
|
|
410
|
+
const operation = AccountOperation.from({
|
|
411
411
|
account,
|
|
412
412
|
approvals: selection.approvals,
|
|
413
413
|
config: applicableConfig,
|
|
@@ -421,19 +421,19 @@ describe('serializeTransaction', () => {
|
|
|
421
421
|
updatedAt: 1,
|
|
422
422
|
weight: selection.weight,
|
|
423
423
|
})
|
|
424
|
-
const serialized =
|
|
424
|
+
const serialized = AccountOperation.serializeTransaction(operation, {
|
|
425
425
|
approvals: selection.selectedApprovals,
|
|
426
426
|
})
|
|
427
427
|
const value = TxEnvelopeTempo.deserialize(serialized)
|
|
428
428
|
results.push({
|
|
429
429
|
account: value.signature?.account,
|
|
430
430
|
version:
|
|
431
|
-
value.signature?.type === '
|
|
431
|
+
value.signature?.type === 'configurable'
|
|
432
432
|
? value.signature.config.version
|
|
433
433
|
: undefined,
|
|
434
434
|
hash: Hash.keccak256(serialized),
|
|
435
435
|
signatureCount:
|
|
436
|
-
value.signature?.type === '
|
|
436
|
+
value.signature?.type === 'configurable'
|
|
437
437
|
? value.signature.signatures.length
|
|
438
438
|
: 0,
|
|
439
439
|
type: serialized.slice(0, 4),
|
|
@@ -480,13 +480,13 @@ describe('serializeTransaction', () => {
|
|
|
480
480
|
] as const
|
|
481
481
|
const results = []
|
|
482
482
|
for (const transaction of transactions) {
|
|
483
|
-
const hash =
|
|
483
|
+
const hash = AccountOperation.getHash({
|
|
484
484
|
account,
|
|
485
485
|
config: currentConfig,
|
|
486
486
|
transaction,
|
|
487
487
|
type: 'transaction',
|
|
488
488
|
})
|
|
489
|
-
const selection = await
|
|
489
|
+
const selection = await AccountOperation.selectApprovals({
|
|
490
490
|
account,
|
|
491
491
|
approvals: [
|
|
492
492
|
signApproval(owners[0]!, hash),
|
|
@@ -495,8 +495,8 @@ describe('serializeTransaction', () => {
|
|
|
495
495
|
config: currentConfig,
|
|
496
496
|
hash,
|
|
497
497
|
})
|
|
498
|
-
const serialized =
|
|
499
|
-
|
|
498
|
+
const serialized = AccountOperation.serializeTransaction(
|
|
499
|
+
AccountOperation.from({
|
|
500
500
|
account,
|
|
501
501
|
approvals: selection.approvals,
|
|
502
502
|
config: currentConfig,
|
|
@@ -517,7 +517,7 @@ describe('serializeTransaction', () => {
|
|
|
517
517
|
feePayerSignature: value.feePayerSignature,
|
|
518
518
|
from: value.from,
|
|
519
519
|
signatureCount:
|
|
520
|
-
value.signature?.type === '
|
|
520
|
+
value.signature?.type === 'configurable'
|
|
521
521
|
? value.signature.signatures.length
|
|
522
522
|
: 0,
|
|
523
523
|
type: serialized.slice(0, 4),
|
|
@@ -547,7 +547,7 @@ describe('serializeTransaction', () => {
|
|
|
547
547
|
})
|
|
548
548
|
|
|
549
549
|
test('rejects an approval not retained by the operation', async () => {
|
|
550
|
-
const hash =
|
|
550
|
+
const hash = AccountOperation.getHash({
|
|
551
551
|
account,
|
|
552
552
|
config: currentConfig,
|
|
553
553
|
transaction,
|
|
@@ -555,13 +555,13 @@ describe('serializeTransaction', () => {
|
|
|
555
555
|
})
|
|
556
556
|
const approval_1 = signApproval(owners[0]!, hash)
|
|
557
557
|
const approval_2 = signApproval(owners[1]!, hash)
|
|
558
|
-
const selection = await
|
|
558
|
+
const selection = await AccountOperation.selectApprovals({
|
|
559
559
|
account,
|
|
560
560
|
approvals: [approval_1],
|
|
561
561
|
config: currentConfig,
|
|
562
562
|
hash,
|
|
563
563
|
})
|
|
564
|
-
const operation =
|
|
564
|
+
const operation = AccountOperation.from({
|
|
565
565
|
account,
|
|
566
566
|
approvals: selection.approvals,
|
|
567
567
|
config: currentConfig,
|
|
@@ -577,19 +577,19 @@ describe('serializeTransaction', () => {
|
|
|
577
577
|
})
|
|
578
578
|
|
|
579
579
|
expect(() =>
|
|
580
|
-
|
|
580
|
+
AccountOperation.serializeTransaction(operation, {
|
|
581
581
|
approvals: [approval_2],
|
|
582
582
|
}),
|
|
583
583
|
).toThrowErrorMatchingInlineSnapshot(
|
|
584
|
-
`[
|
|
584
|
+
`[AccountOperation.InvalidOperationError: Invalid account operation: transaction signature is not a retained approval.]`,
|
|
585
585
|
)
|
|
586
586
|
})
|
|
587
587
|
})
|
|
588
588
|
|
|
589
589
|
describe('from', () => {
|
|
590
590
|
test('transaction states', () => {
|
|
591
|
-
const pending =
|
|
592
|
-
const submitting =
|
|
591
|
+
const pending = AccountOperation.from(transactionPending)
|
|
592
|
+
const submitting = AccountOperation.from({
|
|
593
593
|
...transactionPending,
|
|
594
594
|
approvals: [approval_1, approval_2],
|
|
595
595
|
expiresAt: 10,
|
|
@@ -598,7 +598,7 @@ describe('from', () => {
|
|
|
598
598
|
submissionId,
|
|
599
599
|
weight: 2,
|
|
600
600
|
})
|
|
601
|
-
const success =
|
|
601
|
+
const success = AccountOperation.from({
|
|
602
602
|
...transactionPending,
|
|
603
603
|
approvals: [approval_1, approval_2],
|
|
604
604
|
signatureCount: 2,
|
|
@@ -716,9 +716,9 @@ describe('from', () => {
|
|
|
716
716
|
}),
|
|
717
717
|
{ format: 'feePayer', sender: account },
|
|
718
718
|
)
|
|
719
|
-
const operation =
|
|
719
|
+
const operation = AccountOperation.from({
|
|
720
720
|
...transactionPending,
|
|
721
|
-
hash:
|
|
721
|
+
hash: AccountConfig.getSignPayload({
|
|
722
722
|
account,
|
|
723
723
|
config: currentConfig,
|
|
724
724
|
payload: TxEnvelopeTempo.getSignPayload(
|
|
@@ -777,9 +777,9 @@ describe('from', () => {
|
|
|
777
777
|
}),
|
|
778
778
|
{ format: 'feePayer' },
|
|
779
779
|
)
|
|
780
|
-
const operation =
|
|
780
|
+
const operation = AccountOperation.from({
|
|
781
781
|
...transactionPending,
|
|
782
|
-
hash:
|
|
782
|
+
hash: AccountConfig.getSignPayload({
|
|
783
783
|
account,
|
|
784
784
|
config: currentConfig,
|
|
785
785
|
payload: TxEnvelopeTempo.getSignPayload(
|
|
@@ -793,10 +793,10 @@ describe('from', () => {
|
|
|
793
793
|
})
|
|
794
794
|
|
|
795
795
|
test('initial transaction', () => {
|
|
796
|
-
const operation =
|
|
796
|
+
const operation = AccountOperation.from({
|
|
797
797
|
...transactionPending,
|
|
798
798
|
config,
|
|
799
|
-
hash:
|
|
799
|
+
hash: AccountConfig.getSignPayload({
|
|
800
800
|
account,
|
|
801
801
|
config,
|
|
802
802
|
payload: TxEnvelopeTempo.getSignPayload(
|
|
@@ -846,9 +846,9 @@ describe('from', () => {
|
|
|
846
846
|
})
|
|
847
847
|
|
|
848
848
|
test('key authorization states', () => {
|
|
849
|
-
const pending =
|
|
849
|
+
const pending = AccountOperation.from(keyAuthorizationPending)
|
|
850
850
|
const authorization = KeyAuthorization.deserialize(keyAuthorization)
|
|
851
|
-
const success =
|
|
851
|
+
const success = AccountOperation.from({
|
|
852
852
|
...keyAuthorizationPending,
|
|
853
853
|
approvals: [approval_1, approval_2],
|
|
854
854
|
keyAuthorization: KeyAuthorization.serialize(
|
|
@@ -857,7 +857,7 @@ describe('from', () => {
|
|
|
857
857
|
account,
|
|
858
858
|
config: currentConfig,
|
|
859
859
|
signatures: [ownerSignature_1, owners[1]!.signature],
|
|
860
|
-
type: '
|
|
860
|
+
type: 'configurable',
|
|
861
861
|
},
|
|
862
862
|
}),
|
|
863
863
|
),
|
|
@@ -941,15 +941,15 @@ describe('from', () => {
|
|
|
941
941
|
account,
|
|
942
942
|
config,
|
|
943
943
|
signatures: [ownerSignature_1, owners[1]!.signature],
|
|
944
|
-
type: '
|
|
944
|
+
type: 'configurable',
|
|
945
945
|
},
|
|
946
946
|
}),
|
|
947
947
|
)
|
|
948
|
-
const operation =
|
|
948
|
+
const operation = AccountOperation.from({
|
|
949
949
|
...keyAuthorizationPending,
|
|
950
950
|
approvals: [approval_1, approval_2],
|
|
951
951
|
config,
|
|
952
|
-
hash:
|
|
952
|
+
hash: AccountConfig.getSignPayload({
|
|
953
953
|
account,
|
|
954
954
|
config,
|
|
955
955
|
payload: KeyAuthorization.getSignPayload(authorization),
|
|
@@ -1004,8 +1004,8 @@ describe('from', () => {
|
|
|
1004
1004
|
|
|
1005
1005
|
describe('RPC conversion', () => {
|
|
1006
1006
|
test('round-trips transaction and key authorization operations', () => {
|
|
1007
|
-
const transactionRpc =
|
|
1008
|
-
const keyAuthorizationRpc =
|
|
1007
|
+
const transactionRpc = AccountOperation.toRpc(transactionPending)
|
|
1008
|
+
const keyAuthorizationRpc = AccountOperation.toRpc(keyAuthorizationPending)
|
|
1009
1009
|
|
|
1010
1010
|
expect(() =>
|
|
1011
1011
|
JSON.stringify({ keyAuthorizationRpc, transactionRpc }),
|
|
@@ -1074,11 +1074,11 @@ describe('RPC conversion', () => {
|
|
|
1074
1074
|
},
|
|
1075
1075
|
}
|
|
1076
1076
|
`)
|
|
1077
|
-
expect(
|
|
1078
|
-
|
|
1077
|
+
expect(AccountOperation.fromRpc(transactionRpc)).toStrictEqual(
|
|
1078
|
+
AccountOperation.from(transactionPending),
|
|
1079
1079
|
)
|
|
1080
|
-
expect(
|
|
1081
|
-
|
|
1080
|
+
expect(AccountOperation.fromRpc(keyAuthorizationRpc)).toStrictEqual(
|
|
1081
|
+
AccountOperation.from(keyAuthorizationPending),
|
|
1082
1082
|
)
|
|
1083
1083
|
})
|
|
1084
1084
|
})
|
|
@@ -1175,7 +1175,7 @@ describe('validation', () => {
|
|
|
1175
1175
|
name: 'weight unreachable by the retained owner approvals',
|
|
1176
1176
|
operation: {
|
|
1177
1177
|
...transactionPending,
|
|
1178
|
-
config:
|
|
1178
|
+
config: AccountConfig.from({
|
|
1179
1179
|
owners: [
|
|
1180
1180
|
{ owner: owner_1, weight: 1 },
|
|
1181
1181
|
{ owner: owner_2, weight: 2 },
|
|
@@ -1194,7 +1194,7 @@ describe('validation', () => {
|
|
|
1194
1194
|
operation: {
|
|
1195
1195
|
...transactionPending,
|
|
1196
1196
|
account: '0x0000000000000000000000000000000000000000',
|
|
1197
|
-
hash:
|
|
1197
|
+
hash: AccountConfig.getSignPayload({
|
|
1198
1198
|
account: '0x0000000000000000000000000000000000000000',
|
|
1199
1199
|
config: currentConfig,
|
|
1200
1200
|
payload: TxEnvelopeTempo.getSignPayload(
|
|
@@ -1271,21 +1271,21 @@ describe('validation', () => {
|
|
|
1271
1271
|
account,
|
|
1272
1272
|
config,
|
|
1273
1273
|
signatures: [ownerSignature_1],
|
|
1274
|
-
type: '
|
|
1274
|
+
type: 'configurable',
|
|
1275
1275
|
}),
|
|
1276
1276
|
],
|
|
1277
1277
|
},
|
|
1278
1278
|
},
|
|
1279
1279
|
])('rejects $name', ({ operation }) => {
|
|
1280
1280
|
expect(() =>
|
|
1281
|
-
|
|
1282
|
-
).toThrowError(
|
|
1281
|
+
AccountOperation.from(operation as AccountOperation.Operation),
|
|
1282
|
+
).toThrowError(AccountOperation.InvalidOperationError)
|
|
1283
1283
|
})
|
|
1284
1284
|
test('accepts initial accounts validated by the chain', () => {
|
|
1285
|
-
const value =
|
|
1285
|
+
const value = AccountOperation.from({
|
|
1286
1286
|
...transactionPending,
|
|
1287
1287
|
config,
|
|
1288
|
-
hash:
|
|
1288
|
+
hash: AccountOperation.getHash({
|
|
1289
1289
|
account,
|
|
1290
1290
|
config,
|
|
1291
1291
|
transaction,
|
|
@@ -1297,14 +1297,14 @@ describe('validation', () => {
|
|
|
1297
1297
|
})
|
|
1298
1298
|
|
|
1299
1299
|
test('rejects noncanonical RPC quantities', () => {
|
|
1300
|
-
const operation =
|
|
1300
|
+
const operation = AccountOperation.toRpc(transactionPending)
|
|
1301
1301
|
expect(() =>
|
|
1302
|
-
|
|
1302
|
+
AccountOperation.fromRpc({
|
|
1303
1303
|
...operation,
|
|
1304
1304
|
config: { ...operation.config, version: '0x01' },
|
|
1305
1305
|
}),
|
|
1306
1306
|
).toThrowError(
|
|
1307
|
-
'Invalid
|
|
1307
|
+
'Invalid account operation: config.version must use canonical quantity encoding.',
|
|
1308
1308
|
)
|
|
1309
1309
|
})
|
|
1310
1310
|
|
|
@@ -1319,7 +1319,7 @@ describe('validation', () => {
|
|
|
1319
1319
|
account,
|
|
1320
1320
|
config: currentConfig,
|
|
1321
1321
|
signatures: [ownerSignature_1, owners[2]!.signature],
|
|
1322
|
-
type: '
|
|
1322
|
+
type: 'configurable',
|
|
1323
1323
|
},
|
|
1324
1324
|
}),
|
|
1325
1325
|
),
|
|
@@ -1328,15 +1328,15 @@ describe('validation', () => {
|
|
|
1328
1328
|
weight: 2,
|
|
1329
1329
|
} as const
|
|
1330
1330
|
|
|
1331
|
-
expect(() =>
|
|
1332
|
-
'Invalid
|
|
1331
|
+
expect(() => AccountOperation.from(operation)).toThrowError(
|
|
1332
|
+
'Invalid account operation: key authorization signature is not a retained approval.',
|
|
1333
1333
|
)
|
|
1334
1334
|
})
|
|
1335
1335
|
|
|
1336
1336
|
test('rejects unordered key authorization approvals', () => {
|
|
1337
1337
|
const authorization = KeyAuthorization.deserialize(keyAuthorization)
|
|
1338
1338
|
const signatures = [
|
|
1339
|
-
...SignatureEnvelope.
|
|
1339
|
+
...SignatureEnvelope.sortApprovals({
|
|
1340
1340
|
account,
|
|
1341
1341
|
config: currentConfig,
|
|
1342
1342
|
payload: KeyAuthorization.getSignPayload(authorization),
|
|
@@ -1352,7 +1352,7 @@ describe('validation', () => {
|
|
|
1352
1352
|
account,
|
|
1353
1353
|
config: currentConfig,
|
|
1354
1354
|
signatures,
|
|
1355
|
-
type: '
|
|
1355
|
+
type: 'configurable',
|
|
1356
1356
|
},
|
|
1357
1357
|
}),
|
|
1358
1358
|
),
|
|
@@ -1361,8 +1361,8 @@ describe('validation', () => {
|
|
|
1361
1361
|
weight: 2,
|
|
1362
1362
|
} as const
|
|
1363
1363
|
|
|
1364
|
-
expect(() =>
|
|
1365
|
-
'Invalid
|
|
1364
|
+
expect(() => AccountOperation.from(operation)).toThrowError(
|
|
1365
|
+
'Invalid account operation: key authorization approvals are not canonically ordered.',
|
|
1366
1366
|
)
|
|
1367
1367
|
})
|
|
1368
1368
|
|
|
@@ -1377,7 +1377,7 @@ describe('validation', () => {
|
|
|
1377
1377
|
account,
|
|
1378
1378
|
config: currentConfig,
|
|
1379
1379
|
signatures: [ownerSignature_1, ownerSignature_1],
|
|
1380
|
-
type: '
|
|
1380
|
+
type: 'configurable',
|
|
1381
1381
|
},
|
|
1382
1382
|
}),
|
|
1383
1383
|
),
|
|
@@ -1386,13 +1386,13 @@ describe('validation', () => {
|
|
|
1386
1386
|
weight: 2,
|
|
1387
1387
|
} as const
|
|
1388
1388
|
|
|
1389
|
-
expect(() =>
|
|
1390
|
-
'Invalid
|
|
1389
|
+
expect(() => AccountOperation.from(operation)).toThrowError(
|
|
1390
|
+
'Invalid account operation: key authorization contains duplicate owner approvals.',
|
|
1391
1391
|
)
|
|
1392
1392
|
})
|
|
1393
1393
|
|
|
1394
1394
|
test('accepts case-insensitive initial configs', () => {
|
|
1395
|
-
const config =
|
|
1395
|
+
const config = AccountConfig.from({
|
|
1396
1396
|
owners: [
|
|
1397
1397
|
{
|
|
1398
1398
|
owner: Address.checksum(owner_1),
|
|
@@ -1406,7 +1406,7 @@ describe('validation', () => {
|
|
|
1406
1406
|
salt: `0x${'AB'.repeat(32)}`,
|
|
1407
1407
|
threshold: 2,
|
|
1408
1408
|
})
|
|
1409
|
-
const account =
|
|
1409
|
+
const account = AccountConfig.getAddress(config, { factory })
|
|
1410
1410
|
const authorization = KeyAuthorization.from({
|
|
1411
1411
|
account,
|
|
1412
1412
|
address: '0x3333333333333333333333333333333333333333',
|
|
@@ -1415,7 +1415,7 @@ describe('validation', () => {
|
|
|
1415
1415
|
isAdmin: false,
|
|
1416
1416
|
type: 'secp256k1',
|
|
1417
1417
|
})
|
|
1418
|
-
const signatures = SignatureEnvelope.
|
|
1418
|
+
const signatures = SignatureEnvelope.sortApprovals({
|
|
1419
1419
|
account,
|
|
1420
1420
|
config,
|
|
1421
1421
|
payload: KeyAuthorization.getSignPayload(authorization),
|
|
@@ -1425,12 +1425,12 @@ describe('validation', () => {
|
|
|
1425
1425
|
SignatureEnvelope.serialize(signature),
|
|
1426
1426
|
)
|
|
1427
1427
|
|
|
1428
|
-
const operation =
|
|
1428
|
+
const operation = AccountOperation.from({
|
|
1429
1429
|
account,
|
|
1430
1430
|
approvals,
|
|
1431
1431
|
config,
|
|
1432
1432
|
createdAt: 1,
|
|
1433
|
-
hash:
|
|
1433
|
+
hash: AccountConfig.getSignPayload({
|
|
1434
1434
|
account,
|
|
1435
1435
|
config,
|
|
1436
1436
|
payload: KeyAuthorization.getSignPayload(authorization),
|
|
@@ -1441,7 +1441,7 @@ describe('validation', () => {
|
|
|
1441
1441
|
account,
|
|
1442
1442
|
config,
|
|
1443
1443
|
signatures,
|
|
1444
|
-
type: '
|
|
1444
|
+
type: 'configurable',
|
|
1445
1445
|
},
|
|
1446
1446
|
}),
|
|
1447
1447
|
),
|