tempo.ts 0.7.6 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/chains.d.ts +6 -20
  3. package/dist/chains.d.ts.map +1 -1
  4. package/dist/chains.js +14 -15
  5. package/dist/chains.js.map +1 -1
  6. package/dist/ox/KeyAuthorization.d.ts +356 -0
  7. package/dist/ox/KeyAuthorization.d.ts.map +1 -0
  8. package/dist/ox/KeyAuthorization.js +360 -0
  9. package/dist/ox/KeyAuthorization.js.map +1 -0
  10. package/dist/ox/SignatureEnvelope.d.ts +21 -6
  11. package/dist/ox/SignatureEnvelope.d.ts.map +1 -1
  12. package/dist/ox/SignatureEnvelope.js +43 -3
  13. package/dist/ox/SignatureEnvelope.js.map +1 -1
  14. package/dist/ox/Transaction.d.ts +5 -1
  15. package/dist/ox/Transaction.d.ts.map +1 -1
  16. package/dist/ox/Transaction.js +5 -0
  17. package/dist/ox/Transaction.js.map +1 -1
  18. package/dist/ox/TransactionEnvelopeAA.d.ts +9 -0
  19. package/dist/ox/TransactionEnvelopeAA.d.ts.map +1 -1
  20. package/dist/ox/TransactionEnvelopeAA.js +17 -4
  21. package/dist/ox/TransactionEnvelopeAA.js.map +1 -1
  22. package/dist/ox/TransactionRequest.d.ts +7 -1
  23. package/dist/ox/TransactionRequest.d.ts.map +1 -1
  24. package/dist/ox/TransactionRequest.js +12 -0
  25. package/dist/ox/TransactionRequest.js.map +1 -1
  26. package/dist/ox/index.d.ts +1 -0
  27. package/dist/ox/index.d.ts.map +1 -1
  28. package/dist/ox/index.js +1 -0
  29. package/dist/ox/index.js.map +1 -1
  30. package/dist/prool/Instance.js +1 -1
  31. package/dist/prool/Instance.js.map +1 -1
  32. package/{src/prool/internal → dist/prool}/chain.json +4 -2
  33. package/dist/viem/Abis.d.ts +319 -6
  34. package/dist/viem/Abis.d.ts.map +1 -1
  35. package/dist/viem/Abis.js +199 -7
  36. package/dist/viem/Abis.js.map +1 -1
  37. package/dist/viem/Account.d.ts +103 -14
  38. package/dist/viem/Account.d.ts.map +1 -1
  39. package/dist/viem/Account.js +177 -23
  40. package/dist/viem/Account.js.map +1 -1
  41. package/dist/viem/Actions/account.d.ts.map +1 -1
  42. package/dist/viem/Actions/account.js +4 -5
  43. package/dist/viem/Actions/account.js.map +1 -1
  44. package/dist/viem/Actions/amm.d.ts +72 -0
  45. package/dist/viem/Actions/amm.d.ts.map +1 -1
  46. package/dist/viem/Actions/dex.d.ts +156 -4
  47. package/dist/viem/Actions/dex.d.ts.map +1 -1
  48. package/dist/viem/Actions/fee.d.ts +4 -0
  49. package/dist/viem/Actions/fee.d.ts.map +1 -1
  50. package/dist/viem/Actions/reward.d.ts +78 -0
  51. package/dist/viem/Actions/reward.d.ts.map +1 -1
  52. package/dist/viem/Actions/token.d.ts +585 -0
  53. package/dist/viem/Actions/token.d.ts.map +1 -1
  54. package/dist/viem/Actions/token.js +2 -2
  55. package/dist/viem/Actions/token.js.map +1 -1
  56. package/dist/viem/Addresses.d.ts +1 -1
  57. package/dist/viem/Addresses.d.ts.map +1 -1
  58. package/dist/viem/Addresses.js +1 -1
  59. package/dist/viem/Addresses.js.map +1 -1
  60. package/dist/viem/Chain.d.ts +35 -0
  61. package/dist/viem/Chain.d.ts.map +1 -1
  62. package/dist/viem/Chain.js +37 -0
  63. package/dist/viem/Chain.js.map +1 -1
  64. package/dist/viem/Formatters.d.ts.map +1 -1
  65. package/dist/viem/Formatters.js +8 -7
  66. package/dist/viem/Formatters.js.map +1 -1
  67. package/dist/viem/Storage.d.ts +1 -0
  68. package/dist/viem/Storage.d.ts.map +1 -1
  69. package/dist/viem/Storage.js +21 -0
  70. package/dist/viem/Storage.js.map +1 -1
  71. package/dist/viem/TokenIds.d.ts +1 -1
  72. package/dist/viem/TokenIds.d.ts.map +1 -1
  73. package/dist/viem/TokenIds.js +1 -1
  74. package/dist/viem/TokenIds.js.map +1 -1
  75. package/dist/viem/Transaction.d.ts +9 -1
  76. package/dist/viem/Transaction.d.ts.map +1 -1
  77. package/dist/viem/Transaction.js +2 -1
  78. package/dist/viem/Transaction.js.map +1 -1
  79. package/dist/viem/WebAuthnP256.d.ts +4 -1
  80. package/dist/viem/WebAuthnP256.d.ts.map +1 -1
  81. package/dist/viem/WebAuthnP256.js +3 -1
  82. package/dist/viem/WebAuthnP256.js.map +1 -1
  83. package/dist/wagmi/Connector.d.ts +25 -8
  84. package/dist/wagmi/Connector.d.ts.map +1 -1
  85. package/dist/wagmi/Connector.js +120 -27
  86. package/dist/wagmi/Connector.js.map +1 -1
  87. package/package.json +3 -2
  88. package/src/chains.ts +14 -15
  89. package/src/ox/KeyAuthorization.test.ts +1332 -0
  90. package/src/ox/KeyAuthorization.ts +542 -0
  91. package/src/ox/SignatureEnvelope.test.ts +624 -0
  92. package/src/ox/SignatureEnvelope.ts +89 -9
  93. package/src/ox/Transaction.test.ts +214 -0
  94. package/src/ox/Transaction.ts +13 -1
  95. package/src/ox/TransactionEnvelopeAA.test.ts +164 -4
  96. package/src/ox/TransactionEnvelopeAA.ts +36 -3
  97. package/src/ox/TransactionRequest.ts +22 -1
  98. package/src/ox/e2e.test.ts +612 -5
  99. package/src/ox/index.ts +1 -0
  100. package/src/prool/Instance.ts +1 -1
  101. package/src/prool/chain.json +238 -0
  102. package/src/server/Handler.test.ts +20 -36
  103. package/src/viem/Abis.ts +200 -7
  104. package/src/viem/Account.test.ts +444 -0
  105. package/src/viem/Account.ts +355 -42
  106. package/src/viem/Actions/account.ts +3 -5
  107. package/src/viem/Actions/amm.test.ts +4 -4
  108. package/src/viem/Actions/token.test.ts +8 -8
  109. package/src/viem/Actions/token.ts +2 -2
  110. package/src/viem/Addresses.ts +1 -1
  111. package/src/viem/Chain.test.ts +168 -0
  112. package/src/viem/Chain.ts +37 -1
  113. package/src/viem/Formatters.ts +8 -7
  114. package/src/viem/Storage.ts +22 -0
  115. package/src/viem/TokenIds.ts +1 -1
  116. package/src/viem/Transaction.ts +14 -2
  117. package/src/viem/WebAuthnP256.ts +8 -2
  118. package/src/viem/e2e.test.ts +299 -96
  119. package/src/wagmi/Actions/amm.test.ts +2 -2
  120. package/src/wagmi/Connector.test.ts +1 -1
  121. package/src/wagmi/Connector.ts +184 -54
  122. package/src/wagmi/Hooks/amm.test.ts +4 -4
  123. package/src/wagmi/Hooks/fee.test.ts +10 -4
  124. package/src/wagmi/Hooks/token.test.ts +0 -488
  125. package/dist/viem/internal/account.d.ts +0 -21
  126. package/dist/viem/internal/account.d.ts.map +0 -1
  127. package/dist/viem/internal/account.js +0 -61
  128. package/dist/viem/internal/account.js.map +0 -1
  129. package/src/viem/internal/account.ts +0 -89
@@ -2,15 +2,17 @@ import * as Http from 'node:http'
2
2
  import { createRequestListener } from '@remix-run/node-fetch-server'
3
3
  import { RpcRequest, RpcResponse, WebCryptoP256 } from 'ox'
4
4
  import { Account, Transaction } from 'tempo.ts/viem'
5
- import { http, parseGwei, publicActions, walletActions } from 'viem'
5
+ import { publicActions, walletActions } from 'viem'
6
6
  import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts'
7
+ import { defaultPrepareTransactionRequestParameters } from 'viem/actions'
7
8
  import { afterAll, afterEach, beforeAll, describe, expect, test } from 'vitest'
8
- import { fetchOptions, rpcUrl } from '../../test/config.js'
9
+ import { rpcUrl } from '../../test/config.js'
9
10
  import {
10
11
  accounts,
11
12
  client as client_,
12
13
  fundAddress,
13
14
  getClient,
15
+ http,
14
16
  } from '../../test/viem/config.js'
15
17
  import * as actions from './Actions/index.js'
16
18
  import { tempoActions } from './index.js'
@@ -41,11 +43,11 @@ describe('sendTransaction', () => {
41
43
  gas,
42
44
  gasPrice,
43
45
  hash: hash_,
44
- // @ts-expect-error
45
46
  keyAuthorization: __,
46
47
  maxFeePerGas,
47
48
  maxPriorityFeePerGas,
48
49
  nonce,
50
+ nonceKey,
49
51
  signature,
50
52
  transactionIndex,
51
53
  ...transaction
@@ -61,6 +63,7 @@ describe('sendTransaction', () => {
61
63
  expect(maxFeePerGas).toBeDefined()
62
64
  expect(maxPriorityFeePerGas).toBeDefined()
63
65
  expect(nonce).toBeDefined()
66
+ expect(nonceKey).toBeDefined()
64
67
  expect(signature).toBeDefined()
65
68
  expect(transactionIndex).toBeDefined()
66
69
  expect(transaction).toMatchInlineSnapshot(`
@@ -79,7 +82,6 @@ describe('sendTransaction', () => {
79
82
  "feePayerSignature": undefined,
80
83
  "feeToken": "0x20c0000000000000000000000000000000000001",
81
84
  "maxFeePerBlobGas": undefined,
82
- "nonceKey": 0n,
83
85
  "to": null,
84
86
  "type": "aa",
85
87
  "typeHex": "0x76",
@@ -117,11 +119,11 @@ describe('sendTransaction', () => {
117
119
  gas,
118
120
  gasPrice,
119
121
  hash: hash_,
120
- // @ts-expect-error
121
122
  keyAuthorization: __,
122
123
  maxFeePerGas,
123
124
  maxPriorityFeePerGas,
124
125
  nonce,
126
+ nonceKey,
125
127
  signature,
126
128
  transactionIndex,
127
129
  ...transaction
@@ -138,6 +140,7 @@ describe('sendTransaction', () => {
138
140
  expect(maxFeePerGas).toBeDefined()
139
141
  expect(maxPriorityFeePerGas).toBeDefined()
140
142
  expect(nonce).toBeDefined()
143
+ expect(nonceKey).toBeDefined()
141
144
  expect(signature).toBeDefined()
142
145
  expect(transactionIndex).toBeDefined()
143
146
  expect(transaction).toMatchInlineSnapshot(`
@@ -149,7 +152,6 @@ describe('sendTransaction', () => {
149
152
  "feePayerSignature": undefined,
150
153
  "feeToken": "0x20c0000000000000000000000000000000000001",
151
154
  "maxFeePerBlobGas": undefined,
152
- "nonceKey": 0n,
153
155
  "to": null,
154
156
  "type": "aa",
155
157
  "typeHex": "0x76",
@@ -182,11 +184,11 @@ describe('sendTransaction', () => {
182
184
  gas,
183
185
  gasPrice,
184
186
  hash: hash_,
185
- // @ts-expect-error
186
187
  keyAuthorization: __,
187
188
  maxFeePerGas,
188
189
  maxPriorityFeePerGas,
189
190
  nonce,
191
+ nonceKey,
190
192
  signature,
191
193
  transactionIndex,
192
194
  ...transaction
@@ -203,6 +205,7 @@ describe('sendTransaction', () => {
203
205
  expect(maxFeePerGas).toBeDefined()
204
206
  expect(maxPriorityFeePerGas).toBeDefined()
205
207
  expect(nonce).toBeDefined()
208
+ expect(nonceKey).toBeDefined()
206
209
  expect(signature).toBeDefined()
207
210
  expect(transactionIndex).toBeDefined()
208
211
  expect(transaction).toMatchInlineSnapshot(`
@@ -220,7 +223,6 @@ describe('sendTransaction', () => {
220
223
  "data": undefined,
221
224
  "feeToken": "0x20c0000000000000000000000000000000000001",
222
225
  "maxFeePerBlobGas": undefined,
223
- "nonceKey": 0n,
224
226
  "to": null,
225
227
  "type": "aa",
226
228
  "typeHex": "0x76",
@@ -232,6 +234,45 @@ describe('sendTransaction', () => {
232
234
  }
233
235
  `)
234
236
  })
237
+
238
+ test('with access key', async () => {
239
+ const account = accounts[0]
240
+ const accessKey = Account.fromP256(generatePrivateKey(), {
241
+ access: account,
242
+ })
243
+
244
+ const keyAuthorization = await account.signKeyAuthorization(accessKey)
245
+ await account.assignKeyAuthorization(keyAuthorization)
246
+
247
+ {
248
+ const receipt = await client.sendTransactionSync({
249
+ account: accessKey,
250
+ })
251
+ expect(receipt).toBeDefined()
252
+ }
253
+
254
+ // TODO: uncomment once unlimited spend supported
255
+ // {
256
+ // const receipt = await client.token.transferSync({
257
+ // account: accessKey,
258
+ // amount: 100n,
259
+ // token: '0x20c0000000000000000000000000000000000001',
260
+ // to: '0x0000000000000000000000000000000000000001',
261
+ // })
262
+ // expect(receipt).toBeDefined()
263
+ // }
264
+
265
+ {
266
+ const receipt = await client.token.createSync({
267
+ account: accessKey,
268
+ admin: accessKey.address,
269
+ currency: 'USD',
270
+ name: 'Test Token 4',
271
+ symbol: 'TEST4',
272
+ })
273
+ expect(receipt).toBeDefined()
274
+ }
275
+ })
235
276
  })
236
277
 
237
278
  describe('p256', () => {
@@ -257,11 +298,11 @@ describe('sendTransaction', () => {
257
298
  gas,
258
299
  gasPrice,
259
300
  hash,
260
- // @ts-expect-error
261
301
  keyAuthorization: __,
262
302
  maxFeePerGas,
263
303
  maxPriorityFeePerGas,
264
304
  nonce,
305
+ nonceKey,
265
306
  signature,
266
307
  transactionIndex,
267
308
  ...transaction
@@ -279,6 +320,7 @@ describe('sendTransaction', () => {
279
320
  expect(maxFeePerGas).toBeDefined()
280
321
  expect(maxPriorityFeePerGas).toBeDefined()
281
322
  expect(nonce).toBeDefined()
323
+ expect(nonceKey).toBeDefined()
282
324
  expect(signature).toBeDefined()
283
325
  expect(transactionIndex).toBeDefined()
284
326
  expect(transaction).toMatchInlineSnapshot(`
@@ -297,7 +339,6 @@ describe('sendTransaction', () => {
297
339
  "feePayerSignature": undefined,
298
340
  "feeToken": "0x20c0000000000000000000000000000000000001",
299
341
  "maxFeePerBlobGas": undefined,
300
- "nonceKey": 0n,
301
342
  "to": null,
302
343
  "type": "aa",
303
344
  "typeHex": "0x76",
@@ -341,11 +382,11 @@ describe('sendTransaction', () => {
341
382
  gas,
342
383
  gasPrice,
343
384
  hash,
344
- // @ts-expect-error
345
385
  keyAuthorization: __,
346
386
  maxFeePerGas,
347
387
  maxPriorityFeePerGas,
348
388
  nonce,
389
+ nonceKey,
349
390
  signature,
350
391
  transactionIndex,
351
392
  ...transaction
@@ -364,6 +405,7 @@ describe('sendTransaction', () => {
364
405
  expect(maxFeePerGas).toBeDefined()
365
406
  expect(maxPriorityFeePerGas).toBeDefined()
366
407
  expect(nonce).toBeDefined()
408
+ expect(nonceKey).toBeDefined()
367
409
  expect(signature).toBeDefined()
368
410
  expect(transactionIndex).toBeDefined()
369
411
  expect(transaction).toMatchInlineSnapshot(`
@@ -375,7 +417,6 @@ describe('sendTransaction', () => {
375
417
  "feePayerSignature": undefined,
376
418
  "feeToken": "0x20c0000000000000000000000000000000000001",
377
419
  "maxFeePerBlobGas": undefined,
378
- "nonceKey": 0n,
379
420
  "to": null,
380
421
  "type": "aa",
381
422
  "typeHex": "0x76",
@@ -411,11 +452,11 @@ describe('sendTransaction', () => {
411
452
  gas,
412
453
  gasPrice,
413
454
  hash: hash_,
414
- // @ts-expect-error
415
455
  keyAuthorization: __,
416
456
  maxFeePerGas,
417
457
  maxPriorityFeePerGas,
418
458
  nonce,
459
+ nonceKey,
419
460
  signature,
420
461
  transactionIndex,
421
462
  ...transaction
@@ -432,6 +473,7 @@ describe('sendTransaction', () => {
432
473
  expect(maxFeePerGas).toBeDefined()
433
474
  expect(maxPriorityFeePerGas).toBeDefined()
434
475
  expect(nonce).toBeDefined()
476
+ expect(nonceKey).toBeDefined()
435
477
  expect(signature).toBeDefined()
436
478
  expect(transactionIndex).toBeDefined()
437
479
  expect(transaction).toMatchInlineSnapshot(`
@@ -449,7 +491,6 @@ describe('sendTransaction', () => {
449
491
  "data": undefined,
450
492
  "feeToken": "0x20c0000000000000000000000000000000000001",
451
493
  "maxFeePerBlobGas": undefined,
452
- "nonceKey": 0n,
453
494
  "to": null,
454
495
  "type": "aa",
455
496
  "typeHex": "0x76",
@@ -461,6 +502,63 @@ describe('sendTransaction', () => {
461
502
  }
462
503
  `)
463
504
  })
505
+
506
+ test('with access key', async () => {
507
+ const account = accounts[0]
508
+ const accessKey = Account.fromP256(generatePrivateKey(), {
509
+ access: account,
510
+ })
511
+
512
+ const keyAuthorization = await account.signKeyAuthorization(accessKey)
513
+ await account.assignKeyAuthorization(keyAuthorization)
514
+
515
+ {
516
+ const receipt = await client.sendTransactionSync({
517
+ account: accessKey,
518
+ })
519
+ expect(receipt).toBeDefined()
520
+ }
521
+
522
+ {
523
+ const receipt = await client.sendTransactionSync({
524
+ account: accessKey,
525
+ to: '0x0000000000000000000000000000000000000000',
526
+ })
527
+ expect(receipt).toBeDefined()
528
+ }
529
+ })
530
+
531
+ test('with access key + fee payer', async () => {
532
+ const account = Account.fromP256(
533
+ // unfunded account with different key
534
+ '0x1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0f1a2b',
535
+ )
536
+ const accessKey = Account.fromP256(generatePrivateKey(), {
537
+ access: account,
538
+ })
539
+ const feePayer = accounts[0]
540
+
541
+ const keyAuthorization = await account.signKeyAuthorization(accessKey)
542
+ await account.assignKeyAuthorization(keyAuthorization)
543
+
544
+ {
545
+ const receipt = await client.sendTransactionSync({
546
+ account: accessKey,
547
+ feePayer,
548
+ to: '0x0000000000000000000000000000000000000000',
549
+ })
550
+ expect(receipt).toBeDefined()
551
+ }
552
+
553
+ {
554
+ const receipt = await client.sendTransactionSync({
555
+ account: accessKey,
556
+ feePayer,
557
+ to: '0x0000000000000000000000000000000000000000',
558
+ })
559
+ expect(receipt).toBeDefined()
560
+ }
561
+ })
464
562
  })
465
563
 
466
564
  describe('webcrypto', () => {
@@ -484,11 +582,11 @@ describe('sendTransaction', () => {
484
582
  from,
485
583
  gasPrice,
486
584
  hash,
487
- // @ts-expect-error
488
585
  keyAuthorization: __,
489
586
  maxFeePerGas,
490
587
  maxPriorityFeePerGas,
491
588
  nonce,
589
+ nonceKey,
492
590
  signature,
493
591
  transactionIndex,
494
592
  ...transaction
@@ -505,6 +603,7 @@ describe('sendTransaction', () => {
505
603
  expect(maxFeePerGas).toBeDefined()
506
604
  expect(maxPriorityFeePerGas).toBeDefined()
507
605
  expect(nonce).toBeDefined()
606
+ expect(nonceKey).toBeDefined()
508
607
  expect(signature).toBeDefined()
509
608
  expect(transactionIndex).toBeDefined()
510
609
  expect(transaction).toMatchInlineSnapshot(`
@@ -524,7 +623,6 @@ describe('sendTransaction', () => {
524
623
  "feeToken": "0x20c0000000000000000000000000000000000001",
525
624
  "gas": 29012n,
526
625
  "maxFeePerBlobGas": undefined,
527
- "nonceKey": 0n,
528
626
  "to": null,
529
627
  "type": "aa",
530
628
  "typeHex": "0x76",
@@ -567,7 +665,6 @@ describe('sendTransaction', () => {
567
665
  gas,
568
666
  gasPrice,
569
667
  hash,
570
- // @ts-expect-error
571
668
  keyAuthorization: __,
572
669
  maxFeePerGas,
573
670
  maxPriorityFeePerGas,
@@ -612,7 +709,6 @@ describe('sendTransaction', () => {
612
709
  from,
613
710
  gasPrice,
614
711
  hash: hash_,
615
- // @ts-expect-error
616
712
  keyAuthorization: __,
617
713
  maxFeePerGas,
618
714
  maxPriorityFeePerGas,
@@ -633,6 +729,35 @@ describe('sendTransaction', () => {
633
729
  expect(signature).toBeDefined()
634
730
  expect(transaction).toBeDefined()
635
731
  })
732
+
733
+ test('with access key', async () => {
734
+ const keyPair = await WebCryptoP256.createKeyPair()
735
+ const account = Account.fromWebCryptoP256(keyPair)
736
+ const accessKey = Account.fromWebCryptoP256(keyPair, {
737
+ access: account,
738
+ })
739
+
740
+ // fund account
741
+ await fundAddress(client, { address: account.address })
742
+
743
+ const keyAuthorization = await account.signKeyAuthorization(accessKey)
744
+ await account.assignKeyAuthorization(keyAuthorization)
745
+
746
+ {
747
+ const receipt = await client.sendTransactionSync({
748
+ account: accessKey,
749
+ })
750
+ expect(receipt).toBeDefined()
751
+ }
752
+
753
+ {
754
+ const receipt = await client.sendTransactionSync({
755
+ account: accessKey,
756
+ to: '0x0000000000000000000000000000000000000000',
757
+ })
758
+ expect(receipt).toBeDefined()
759
+ }
760
+ })
636
761
  })
637
762
 
638
763
  describe('webAuthn', () => {
@@ -662,11 +787,11 @@ describe('sendTransaction', () => {
662
787
  gas,
663
788
  gasPrice,
664
789
  hash,
665
- // @ts-expect-error
666
790
  keyAuthorization: __,
667
791
  maxFeePerGas,
668
792
  maxPriorityFeePerGas,
669
793
  nonce,
794
+ nonceKey,
670
795
  signature,
671
796
  transactionIndex,
672
797
  ...transaction
@@ -684,6 +809,7 @@ describe('sendTransaction', () => {
684
809
  expect(maxFeePerGas).toBeDefined()
685
810
  expect(maxPriorityFeePerGas).toBeDefined()
686
811
  expect(nonce).toBeDefined()
812
+ expect(nonceKey).toBeDefined()
687
813
  expect(signature).toBeDefined()
688
814
  expect(transactionIndex).toBeDefined()
689
815
  expect(transaction).toMatchInlineSnapshot(`
@@ -702,7 +828,6 @@ describe('sendTransaction', () => {
702
828
  "feePayerSignature": undefined,
703
829
  "feeToken": "0x20c0000000000000000000000000000000000001",
704
830
  "maxFeePerBlobGas": undefined,
705
- "nonceKey": 0n,
706
831
  "to": null,
707
832
  "type": "aa",
708
833
  "typeHex": "0x76",
@@ -750,11 +875,11 @@ describe('sendTransaction', () => {
750
875
  gas,
751
876
  gasPrice,
752
877
  hash,
753
- // @ts-expect-error
754
878
  keyAuthorization: __,
755
879
  maxFeePerGas,
756
880
  maxPriorityFeePerGas,
757
881
  nonce,
882
+ nonceKey,
758
883
  signature,
759
884
  transactionIndex,
760
885
  ...transaction
@@ -773,6 +898,7 @@ describe('sendTransaction', () => {
773
898
  expect(maxFeePerGas).toBeDefined()
774
899
  expect(maxPriorityFeePerGas).toBeDefined()
775
900
  expect(nonce).toBeDefined()
901
+ expect(nonceKey).toBeDefined()
776
902
  expect(signature).toBeDefined()
777
903
  expect(transactionIndex).toBeDefined()
778
904
  expect(transaction).toMatchInlineSnapshot(`
@@ -784,7 +910,6 @@ describe('sendTransaction', () => {
784
910
  "feePayerSignature": undefined,
785
911
  "feeToken": "0x20c0000000000000000000000000000000000001",
786
912
  "maxFeePerBlobGas": undefined,
787
- "nonceKey": 0n,
788
913
  "to": null,
789
914
  "type": "aa",
790
915
  "typeHex": "0x76",
@@ -824,11 +949,11 @@ describe('sendTransaction', () => {
824
949
  gas,
825
950
  gasPrice,
826
951
  hash: hash_,
827
- // @ts-expect-error
828
952
  keyAuthorization: __,
829
953
  maxFeePerGas,
830
954
  maxPriorityFeePerGas,
831
955
  nonce,
956
+ nonceKey,
832
957
  signature,
833
958
  transactionIndex,
834
959
  ...transaction
@@ -845,6 +970,7 @@ describe('sendTransaction', () => {
845
970
  expect(maxFeePerGas).toBeDefined()
846
971
  expect(maxPriorityFeePerGas).toBeDefined()
847
972
  expect(nonce).toBeDefined()
973
+ expect(nonceKey).toBeDefined()
848
974
  expect(signature).toBeDefined()
849
975
  expect(transactionIndex).toBeDefined()
850
976
  expect(transaction).toMatchInlineSnapshot(`
@@ -862,7 +988,6 @@ describe('sendTransaction', () => {
862
988
  "data": undefined,
863
989
  "feeToken": "0x20c0000000000000000000000000000000000001",
864
990
  "maxFeePerBlobGas": undefined,
865
- "nonceKey": 0n,
866
991
  "to": null,
867
992
  "type": "aa",
868
993
  "typeHex": "0x76",
@@ -874,6 +999,96 @@ describe('sendTransaction', () => {
874
999
  }
875
1000
  `)
876
1001
  })
1002
+
1003
+ test('with access key', async () => {
1004
+ const account = Account.fromHeadlessWebAuthn(
1005
+ '0x6a3086fb3f2f95a3f36ef5387d18151ff51dc98a1e0eb987b159ba196beb0c99',
1006
+ {
1007
+ rpId: 'localhost',
1008
+ origin: 'http://localhost',
1009
+ },
1010
+ )
1011
+ const accessKey = Account.fromP256(generatePrivateKey(), {
1012
+ access: account,
1013
+ })
1014
+
1015
+ // fund account
1016
+ await fundAddress(client, { address: account.address })
1017
+
1018
+ const keyAuthorization = await account.signKeyAuthorization(accessKey)
1019
+ await account.assignKeyAuthorization(keyAuthorization)
1020
+
1021
+ {
1022
+ const receipt = await client.sendTransactionSync({
1023
+ account: accessKey,
1024
+ })
1025
+ expect(receipt).toBeDefined()
1026
+ }
1027
+
1028
+ {
1029
+ const receipt = await client.sendTransactionSync({
1030
+ account: accessKey,
1031
+ to: '0x0000000000000000000000000000000000000000',
1032
+ })
1033
+ expect(receipt).toBeDefined()
1034
+ }
1035
+ })
1036
+ })
1037
+
1038
+ test('behavior: 2d nonces', async () => {
1039
+ const account = accounts[0]
1040
+
1041
+ // fund account
1042
+ await fundAddress(client, { address: account.address })
1043
+
1044
+ const receipts = await Promise.all([
1045
+ client.sendTransactionSync({
1046
+ account,
1047
+ nonceKey: 'random',
1048
+ to: '0x0000000000000000000000000000000000000000',
1049
+ }),
1050
+ client.sendTransactionSync({
1051
+ account,
1052
+ nonceKey: 'random',
1053
+ to: '0x0000000000000000000000000000000000000000',
1054
+ }),
1055
+ ])
1056
+
1057
+ expect(receipts[0].status).toBe('success')
1058
+ expect(receipts[1].status).toBe('success')
1059
+ expect(receipts[0].transactionHash).not.toBe(receipts[1].transactionHash)
1060
+ })
1061
+
1062
+ test('behavior: 2d nonces (implicit)', async () => {
1063
+ const account = accounts[0]
1064
+
1065
+ // fund account
1066
+ await fundAddress(client, { address: account.address })
1067
+
1068
+ const receipts = await Promise.all([
1069
+ client.sendTransactionSync({
1070
+ account,
1071
+ to: '0x0000000000000000000000000000000000000000',
1072
+ }),
1073
+ client.sendTransactionSync({
1074
+ account,
1075
+ to: '0x0000000000000000000000000000000000000000',
1076
+ }),
1077
+ client.sendTransactionSync({
1078
+ account,
1079
+ to: '0x0000000000000000000000000000000000000000',
1080
+ }),
1081
+ ])
1082
+
1083
+ const transactions = await Promise.all([
1084
+ client.getTransaction({ hash: receipts[0].transactionHash }),
1085
+ client.getTransaction({ hash: receipts[1].transactionHash }),
1086
+ client.getTransaction({ hash: receipts[2].transactionHash }),
1087
+ ])
1088
+
1089
+ expect(transactions[0].nonceKey).toBe(0n)
1090
+ expect(transactions[1].nonceKey).toBeGreaterThan(0n)
1091
+ expect(transactions[2].nonceKey).toBeGreaterThan(0n)
877
1092
  })
878
1093
  })
879
1094
 
@@ -889,6 +1104,7 @@ describe('signTransaction', () => {
889
1104
  account,
890
1105
  data: '0xdeadbeef',
891
1106
  feePayer: true,
1107
+ parameters: defaultPrepareTransactionRequestParameters,
892
1108
  to: '0xcafebabecafebabecafebabecafebabecafebabe',
893
1109
  })
894
1110
  let transaction = await client.signTransaction(request as never)
@@ -912,11 +1128,11 @@ describe('signTransaction', () => {
912
1128
  from,
913
1129
  gasPrice,
914
1130
  hash: hash_,
915
- // @ts-expect-error
916
1131
  keyAuthorization: __,
917
1132
  maxFeePerGas,
918
1133
  maxPriorityFeePerGas,
919
1134
  nonce,
1135
+ nonceKey,
920
1136
  signature,
921
1137
  transactionIndex,
922
1138
  ...transaction2
@@ -932,6 +1148,7 @@ describe('signTransaction', () => {
932
1148
  expect(maxFeePerGas).toBeDefined()
933
1149
  expect(maxPriorityFeePerGas).toBeDefined()
934
1150
  expect(nonce).toBeDefined()
1151
+ expect(nonceKey).toBeDefined()
935
1152
  expect(signature).toBeDefined()
936
1153
  expect(transactionIndex).toBeDefined()
937
1154
  expect(transaction2).toMatchInlineSnapshot(`
@@ -950,7 +1167,6 @@ describe('signTransaction', () => {
950
1167
  "feeToken": "0x20c0000000000000000000000000000000000001",
951
1168
  "gas": 24002n,
952
1169
  "maxFeePerBlobGas": undefined,
953
- "nonceKey": 0n,
954
1170
  "to": null,
955
1171
  "type": "aa",
956
1172
  "typeHex": "0x76",
@@ -966,11 +1182,7 @@ describe('signTransaction', () => {
966
1182
 
967
1183
  describe('relay', () => {
968
1184
  const client = getClient({
969
- transport: withFeePayer(
970
- http(undefined, { fetchOptions }),
971
- http('http://localhost:3050'),
972
- { policy: 'sign-and-broadcast' },
973
- ),
1185
+ transport: withFeePayer(http(), http('http://localhost:3050')),
974
1186
  })
975
1187
  .extend(tempoActions())
976
1188
  .extend(walletActions)
@@ -1067,7 +1279,6 @@ describe('relay', () => {
1067
1279
 
1068
1280
  const { receipt } = await client.fee.setUserTokenSync({
1069
1281
  account,
1070
- maxFeePerGas: parseGwei('20'),
1071
1282
  feePayer: true,
1072
1283
  token: 1n,
1073
1284
  })
@@ -1089,11 +1300,11 @@ describe('relay', () => {
1089
1300
  gas,
1090
1301
  gasPrice,
1091
1302
  hash,
1092
- // @ts-expect-error
1093
1303
  keyAuthorization: __,
1094
1304
  maxFeePerGas,
1095
1305
  maxPriorityFeePerGas,
1096
1306
  nonce,
1307
+ nonceKey,
1097
1308
  signature,
1098
1309
  transactionIndex,
1099
1310
  ...transaction
@@ -1110,6 +1321,7 @@ describe('relay', () => {
1110
1321
  expect(maxFeePerGas).toBeDefined()
1111
1322
  expect(maxPriorityFeePerGas).toBeDefined()
1112
1323
  expect(nonce).toBeDefined()
1324
+ expect(nonceKey).toBeDefined()
1113
1325
  expect(signature).toBeDefined()
1114
1326
  expect(transactionIndex).toBeDefined()
1115
1327
  expect(transaction).toMatchInlineSnapshot(`
@@ -1127,7 +1339,6 @@ describe('relay', () => {
1127
1339
  "data": undefined,
1128
1340
  "feeToken": "0x20c0000000000000000000000000000000000001",
1129
1341
  "maxFeePerBlobGas": undefined,
1130
- "nonceKey": 0n,
1131
1342
  "to": null,
1132
1343
  "type": "aa",
1133
1344
  "typeHex": "0x76",
@@ -1139,6 +1350,56 @@ describe('relay', () => {
1139
1350
  }
1140
1351
  `)
1141
1352
  })
1353
+
1354
+ test('behavior: 2d nonces', async () => {
1355
+ const account = privateKeyToAccount(
1356
+ // unfunded PK
1357
+ '0xecc3fe55647412647e5c6b657c496803b08ef956f927b7a821da298cfbdd9666',
1358
+ )
1359
+
1360
+ const receipts = await Promise.all([
1361
+ client.sendTransactionSync({
1362
+ account,
1363
+ feePayer: true,
1364
+ to: '0x0000000000000000000000000000000000000000',
1365
+ }),
1366
+ client.sendTransactionSync({
1367
+ account,
1368
+ feePayer: true,
1369
+ to: '0x0000000000000000000000000000000000000001',
1370
+ }),
1371
+ client.sendTransactionSync({
1372
+ account,
1373
+ feePayer: true,
1374
+ to: '0x0000000000000000000000000000000000000002',
1375
+ }),
1376
+ ])
1377
+
1378
+ expect(receipts.every((receipt) => receipt.status === 'success')).toBe(
1379
+ true,
1380
+ )
1381
+ })
1382
+
1383
+ test('behavior: policy: sign-and-broadcast', async () => {
1384
+ const client = getClient({
1385
+ transport: withFeePayer(http(), http('http://localhost:3050'), {
1386
+ policy: 'sign-and-broadcast',
1387
+ }),
1388
+ }).extend(tempoActions())
1389
+
1390
+ // unfunded account that needs sponsorship
1391
+ const account = privateKeyToAccount(
1392
+ '0xecc3fe55647412647e5c6b657c496803b08ef956f927b7a821da298cfbdd9666',
1393
+ )
1394
+
1395
+ const { receipt } = await client.fee.setUserTokenSync({
1396
+ account,
1397
+ feePayer: true,
1398
+ token: 1n,
1399
+ })
1400
+
1401
+ expect(receipt.status).toBe('success')
1402
+ })
1142
1403
  })
1143
1404
 
1144
1405
  describe('p256', () => {
@@ -1170,11 +1431,11 @@ describe('relay', () => {
1170
1431
  gas,
1171
1432
  gasPrice,
1172
1433
  hash,
1173
- // @ts-expect-error
1174
1434
  keyAuthorization: __,
1175
1435
  maxFeePerGas,
1176
1436
  maxPriorityFeePerGas,
1177
1437
  nonce,
1438
+ nonceKey,
1178
1439
  signature,
1179
1440
  transactionIndex,
1180
1441
  ...transaction
@@ -1191,6 +1452,7 @@ describe('relay', () => {
1191
1452
  expect(maxFeePerGas).toBeDefined()
1192
1453
  expect(maxPriorityFeePerGas).toBeDefined()
1193
1454
  expect(nonce).toBeDefined()
1455
+ expect(nonceKey).toBeDefined()
1194
1456
  expect(signature).toBeDefined()
1195
1457
  expect(transactionIndex).toBeDefined()
1196
1458
  expect(transaction).toMatchInlineSnapshot(`
@@ -1208,7 +1470,6 @@ describe('relay', () => {
1208
1470
  "data": undefined,
1209
1471
  "feeToken": "0x20c0000000000000000000000000000000000001",
1210
1472
  "maxFeePerBlobGas": undefined,
1211
- "nonceKey": 0n,
1212
1473
  "to": null,
1213
1474
  "type": "aa",
1214
1475
  "typeHex": "0x76",
@@ -1282,11 +1543,11 @@ describe('relay', () => {
1282
1543
  gas,
1283
1544
  gasPrice,
1284
1545
  hash,
1285
- // @ts-expect-error
1286
1546
  keyAuthorization: __,
1287
1547
  maxFeePerGas,
1288
1548
  maxPriorityFeePerGas,
1289
1549
  nonce,
1550
+ nonceKey,
1290
1551
  signature,
1291
1552
  transactionIndex,
1292
1553
  ...transaction
@@ -1303,6 +1564,7 @@ describe('relay', () => {
1303
1564
  expect(maxFeePerGas).toBeDefined()
1304
1565
  expect(maxPriorityFeePerGas).toBeDefined()
1305
1566
  expect(nonce).toBeDefined()
1567
+ expect(nonceKey).toBeDefined()
1306
1568
  expect(signature).toBeDefined()
1307
1569
  expect(transactionIndex).toBeDefined()
1308
1570
  expect(transaction).toMatchInlineSnapshot(`
@@ -1320,7 +1582,6 @@ describe('relay', () => {
1320
1582
  "data": undefined,
1321
1583
  "feeToken": "0x20c0000000000000000000000000000000000001",
1322
1584
  "maxFeePerBlobGas": undefined,
1323
- "nonceKey": 0n,
1324
1585
  "to": null,
1325
1586
  "type": "aa",
1326
1587
  "typeHex": "0x76",
@@ -1333,62 +1594,4 @@ describe('relay', () => {
1333
1594
  `)
1334
1595
  })
1335
1596
  })
1336
-
1337
- describe('policy: sign-only', () => {
1338
- test('relay co-signs and transport auto-submits', async () => {
1339
- const signClient = getClient({
1340
- transport: withFeePayer(
1341
- http(undefined, { fetchOptions }),
1342
- http('http://localhost:3050'),
1343
- { policy: 'sign-only' },
1344
- ),
1345
- })
1346
- .extend(tempoActions())
1347
- .extend(walletActions)
1348
- .extend(publicActions)
1349
-
1350
- // unfunded account that needs sponsorship
1351
- const account = privateKeyToAccount(
1352
- '0xecc3fe55647412647e5c6b657c496803b08ef956f927b7a821da298cfbdd9666',
1353
- )
1354
-
1355
- // With 'sign-only' policy, the relay co-signs and the transport auto-submits
1356
- const { user, token, receipt } = await signClient.fee.setUserTokenSync({
1357
- account,
1358
- feePayer: true,
1359
- token: 1n,
1360
- })
1361
-
1362
- // Verify the action returned the expected values
1363
- expect(user).toBe(account.address)
1364
- expect(token).toBe('0x20C0000000000000000000000000000000000001')
1365
- expect(receipt).toBeDefined()
1366
-
1367
- // Verify the transaction was successfully executed
1368
- const userToken = await signClient.fee.getUserToken({
1369
- account: account.address,
1370
- })
1371
- expect(userToken?.id).toBe(1n)
1372
-
1373
- const {
1374
- feePayerSignature,
1375
- from,
1376
- gas,
1377
- gasPrice,
1378
- maxFeePerGas,
1379
- maxPriorityFeePerGas,
1380
- signature,
1381
- } = (await signClient.getTransaction({
1382
- hash: receipt.transactionHash,
1383
- })) as any
1384
-
1385
- expect(feePayerSignature).toBeDefined()
1386
- expect(from).toBe(account.address.toLowerCase())
1387
- expect(gas).toBeDefined()
1388
- expect(gasPrice).toBeDefined()
1389
- expect(maxFeePerGas).toBeDefined()
1390
- expect(maxPriorityFeePerGas).toBeDefined()
1391
- expect(signature).toBeDefined()
1392
- })
1393
- })
1394
1597
  })