tempo.ts 0.4.3 → 0.5.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 (55) hide show
  1. package/README.md +2 -3
  2. package/dist/chains.d.ts +15 -1
  3. package/dist/chains.d.ts.map +1 -1
  4. package/dist/chains.js +2 -1
  5. package/dist/chains.js.map +1 -1
  6. package/dist/prool/Instance.d.ts +12 -4
  7. package/dist/prool/Instance.d.ts.map +1 -1
  8. package/dist/prool/Instance.js +34 -18
  9. package/dist/prool/Instance.js.map +1 -1
  10. package/dist/viem/Actions/faucet.d.ts +34 -1
  11. package/dist/viem/Actions/faucet.d.ts.map +1 -1
  12. package/dist/viem/Actions/faucet.js +35 -0
  13. package/dist/viem/Actions/faucet.js.map +1 -1
  14. package/dist/viem/Actions/token.d.ts +12 -12
  15. package/dist/viem/Actions/token.js +12 -12
  16. package/dist/viem/Chain.d.ts +6 -0
  17. package/dist/viem/Chain.d.ts.map +1 -1
  18. package/dist/viem/Decorator.d.ts +9 -9
  19. package/dist/viem/Transaction.d.ts +4 -1
  20. package/dist/viem/Transaction.d.ts.map +1 -1
  21. package/dist/viem/Transaction.js.map +1 -1
  22. package/dist/wagmi/Actions/token.d.ts +1 -1
  23. package/dist/wagmi/Actions/token.js +1 -1
  24. package/dist/wagmi/Connector.d.ts +4 -3
  25. package/dist/wagmi/Connector.d.ts.map +1 -1
  26. package/dist/wagmi/Connector.js +91 -5
  27. package/dist/wagmi/Connector.js.map +1 -1
  28. package/dist/wagmi/Hooks/token.d.ts +1 -1
  29. package/dist/wagmi/Hooks/token.js +1 -1
  30. package/package.json +1 -1
  31. package/src/chains.ts +2 -1
  32. package/src/ox/TransactionEnvelopeAA.test.ts +2 -663
  33. package/src/ox/e2e.test.ts +659 -0
  34. package/src/prool/Instance.ts +51 -23
  35. package/src/tsconfig.json +2 -2
  36. package/src/viem/Actions/amm.test.ts +68 -58
  37. package/src/viem/Actions/dex.test.ts +339 -283
  38. package/src/viem/Actions/faucet.ts +63 -1
  39. package/src/viem/Actions/fee.test.ts +34 -43
  40. package/src/viem/Actions/policy.test.ts +115 -81
  41. package/src/viem/Actions/reward.test.ts +92 -74
  42. package/src/viem/Actions/token.test.ts +691 -529
  43. package/src/viem/Actions/token.ts +12 -12
  44. package/src/viem/Decorator.ts +9 -9
  45. package/src/viem/Transaction.ts +4 -1
  46. package/src/viem/e2e.test.ts +451 -472
  47. package/src/wagmi/Actions/amm.test.ts +2 -5
  48. package/src/wagmi/Actions/dex.test.ts +2 -1
  49. package/src/wagmi/Actions/token.test.ts +2 -1
  50. package/src/wagmi/Actions/token.ts +1 -1
  51. package/src/wagmi/Connector.ts +125 -10
  52. package/src/wagmi/Hooks/amm.test.ts +2 -5
  53. package/src/wagmi/Hooks/dex.test.ts +2 -1
  54. package/src/wagmi/Hooks/token.test.ts +2 -1
  55. package/src/wagmi/Hooks/token.ts +1 -1
@@ -1,22 +1,6 @@
1
- import {
2
- Address,
3
- Hex,
4
- P256,
5
- Rlp,
6
- RpcTransport,
7
- Secp256k1,
8
- Value,
9
- WebAuthnP256,
10
- WebCryptoP256,
11
- } from 'ox'
12
- import { createClient, http, parseUnits } from 'viem'
13
- import { privateKeyToAccount } from 'viem/accounts'
14
- import { afterEach, beforeEach, describe, expect, test } from 'vitest'
15
- import { tempoLocal } from '../chains.js'
16
- import { Instance } from '../prool/index.js'
17
- import { Actions } from '../viem/index.js'
1
+ import { Hex, P256, Rlp, Secp256k1, Value } from 'ox'
2
+ import { describe, expect, test } from 'vitest'
18
3
  import { SignatureEnvelope } from './index.js'
19
- import * as Transaction from './Transaction.js'
20
4
  import * as TransactionEnvelopeAA from './TransactionEnvelopeAA.js'
21
5
 
22
6
  const privateKey =
@@ -1021,648 +1005,3 @@ describe('validate', () => {
1021
1005
  ).toBe(false)
1022
1006
  })
1023
1007
  })
1024
-
1025
- describe('e2e', () => {
1026
- const node = Instance.tempo({ port: 3000 })
1027
- beforeEach(() => node.start())
1028
- afterEach(() => node.stop())
1029
-
1030
- test('behavior: default (secp256k1)', async () => {
1031
- const address = '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'
1032
- const privateKey =
1033
- '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'
1034
-
1035
- const transport = RpcTransport.fromHttp('http://localhost:3000')
1036
-
1037
- const nonce = await transport.request({
1038
- method: 'eth_getTransactionCount',
1039
- params: [address, 'pending'],
1040
- })
1041
-
1042
- const transaction = TransactionEnvelopeAA.from({
1043
- calls: [
1044
- {
1045
- to: '0x0000000000000000000000000000000000000000',
1046
- },
1047
- ],
1048
- chainId: 1337,
1049
- feeToken: '0x20c0000000000000000000000000000000000001',
1050
- nonce: BigInt(nonce),
1051
- gas: 100_000n,
1052
- maxFeePerGas: Value.fromGwei('20'),
1053
- maxPriorityFeePerGas: Value.fromGwei('10'),
1054
- })
1055
-
1056
- const signature = Secp256k1.sign({
1057
- payload: TransactionEnvelopeAA.getSignPayload(transaction),
1058
- privateKey,
1059
- })
1060
-
1061
- const serialized_signed = TransactionEnvelopeAA.serialize(transaction, {
1062
- signature: SignatureEnvelope.from(signature),
1063
- })
1064
-
1065
- const receipt = await transport.request({
1066
- method: 'eth_sendRawTransactionSync',
1067
- params: [serialized_signed],
1068
- })
1069
-
1070
- expect(receipt).toBeDefined()
1071
-
1072
- {
1073
- const response = await transport.request({
1074
- method: 'eth_getTransactionByHash',
1075
- params: [receipt.transactionHash],
1076
- })
1077
- if (!response) throw new Error()
1078
-
1079
- const { blockNumber, blockHash, ...rest } = response
1080
-
1081
- expect(blockNumber).toBeDefined()
1082
- expect(blockHash).toBeDefined()
1083
- expect(rest).toMatchInlineSnapshot(`
1084
- {
1085
- "aaAuthorizationList": [],
1086
- "accessList": [],
1087
- "calls": [
1088
- {
1089
- "data": null,
1090
- "input": "0x",
1091
- "to": "0x0000000000000000000000000000000000000000",
1092
- "value": "0x0",
1093
- },
1094
- ],
1095
- "chainId": "0x539",
1096
- "feePayerSignature": null,
1097
- "feeToken": "0x20c0000000000000000000000000000000000001",
1098
- "from": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
1099
- "gas": "0x186a0",
1100
- "gasPrice": "0x4a817c800",
1101
- "hash": "0x61fa8aa9b36d3c247a33c79aa10f42232a74ceecd214f6170c55d2fbd8ec1ff1",
1102
- "maxFeePerGas": "0x4a817c800",
1103
- "maxPriorityFeePerGas": "0x2540be400",
1104
- "nonce": "0x0",
1105
- "nonceKey": "0x0",
1106
- "signature": {
1107
- "r": "0x64dfde319b7a0e771c12ba6d9f7d5bcdc70d9899734e0662f1e783fd14f4ce12",
1108
- "s": "0x43518ae2dbd1f8c7ca91d39d1215769a18f0bc6ecfd17fd4f5c024d029d8b4df",
1109
- "type": "secp256k1",
1110
- "v": "0x1",
1111
- "yParity": "0x1",
1112
- },
1113
- "transactionIndex": "0x1",
1114
- "type": "0x76",
1115
- "validAfter": null,
1116
- "validBefore": null,
1117
- }
1118
- `)
1119
- }
1120
-
1121
- const { blockNumber, blockHash, logs, logsBloom, ...rest } = receipt
1122
-
1123
- expect(blockNumber).toBeDefined()
1124
- expect(blockHash).toBeDefined()
1125
- expect(logs).toBeDefined()
1126
- expect(logsBloom).toBeDefined()
1127
- expect(rest).toMatchInlineSnapshot(`
1128
- {
1129
- "contractAddress": null,
1130
- "cumulativeGasUsed": "0x5c30",
1131
- "effectiveGasPrice": "0x4a817c800",
1132
- "feeToken": "0x20c0000000000000000000000000000000000001",
1133
- "from": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
1134
- "gasUsed": "0x5c30",
1135
- "status": "0x1",
1136
- "to": "0x0000000000000000000000000000000000000000",
1137
- "transactionHash": "0x61fa8aa9b36d3c247a33c79aa10f42232a74ceecd214f6170c55d2fbd8ec1ff1",
1138
- "transactionIndex": "0x1",
1139
- "type": "0x76",
1140
- }
1141
- `)
1142
- })
1143
-
1144
- test('behavior: default (p256)', async () => {
1145
- const privateKey =
1146
- '0x062d199fd1d30c4a905ed1164a31e73759a13827687a2f3057a7d19c220bc933'
1147
- const publicKey = P256.getPublicKey({ privateKey })
1148
- const address = Address.fromPublicKey(publicKey)
1149
-
1150
- const client = createClient({
1151
- account: privateKeyToAccount(
1152
- '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',
1153
- ),
1154
- chain: tempoLocal({ feeToken: 1n }),
1155
- transport: http('http://localhost:3000'),
1156
- })
1157
-
1158
- await Actions.token.transferSync(client, {
1159
- amount: parseUnits('10', 6),
1160
- token: 1n,
1161
- to: address,
1162
- })
1163
-
1164
- const transaction = TransactionEnvelopeAA.from({
1165
- calls: [
1166
- {
1167
- to: '0x0000000000000000000000000000000000000000',
1168
- },
1169
- ],
1170
- chainId: 1337,
1171
- gas: 100_000n,
1172
- maxFeePerGas: Value.fromGwei('20'),
1173
- maxPriorityFeePerGas: Value.fromGwei('10'),
1174
- })
1175
-
1176
- const signature = P256.sign({
1177
- payload: TransactionEnvelopeAA.getSignPayload(transaction),
1178
- privateKey,
1179
- hash: false,
1180
- })
1181
-
1182
- const serialized_signed = TransactionEnvelopeAA.serialize(transaction, {
1183
- signature: SignatureEnvelope.from({
1184
- signature,
1185
- publicKey,
1186
- prehash: false,
1187
- }),
1188
- })
1189
-
1190
- const receipt = await client.request({
1191
- method: 'eth_sendRawTransactionSync',
1192
- params: [serialized_signed],
1193
- })
1194
-
1195
- expect(receipt).toBeDefined()
1196
-
1197
- {
1198
- const response = await client.request({
1199
- method: 'eth_getTransactionByHash',
1200
- params: [receipt.transactionHash],
1201
- })
1202
- if (!response) throw new Error()
1203
-
1204
- const { blockNumber, blockHash, ...rest } = response
1205
-
1206
- expect(blockNumber).toBeDefined()
1207
- expect(blockHash).toBeDefined()
1208
- expect(rest).toMatchInlineSnapshot(`
1209
- {
1210
- "aaAuthorizationList": [],
1211
- "accessList": [],
1212
- "calls": [
1213
- {
1214
- "data": null,
1215
- "input": "0x",
1216
- "to": "0x0000000000000000000000000000000000000000",
1217
- "value": "0x0",
1218
- },
1219
- ],
1220
- "chainId": "0x539",
1221
- "feePayerSignature": null,
1222
- "feeToken": null,
1223
- "from": "0x6472aeab3269f4165775753156702c06ccc70f8b",
1224
- "gas": "0x186a0",
1225
- "gasPrice": "0x4a817c800",
1226
- "hash": "0x2a9e63842240099fddcd4f247dfc2ea37aa7f635693d4f6a446059310ffb38a9",
1227
- "maxFeePerGas": "0x4a817c800",
1228
- "maxPriorityFeePerGas": "0x2540be400",
1229
- "nonce": "0x0",
1230
- "nonceKey": "0x0",
1231
- "signature": {
1232
- "preHash": false,
1233
- "pubKeyX": "0xecbf69146add5d7c649c96d90b64d90702c6faae7115adbad50e5e61b2c5f40d",
1234
- "pubKeyY": "0xeca3a5fc6dc4225b4f3f9720750651d43c6eb45c0492b8e9930394d1524784c6",
1235
- "r": "0x008057a4a2b7b7e00421d1844646cf70ba427f471e69dc9a3a177bc7feb82450",
1236
- "s": "0x60e684124216b36469c072d137128ce30c5b961628c915ed1fcbf52fc8316cbe",
1237
- "type": "p256",
1238
- },
1239
- "transactionIndex": "0x1",
1240
- "type": "0x76",
1241
- "validAfter": null,
1242
- "validBefore": null,
1243
- }
1244
- `)
1245
- }
1246
-
1247
- const { blockNumber, blockHash, logs, logsBloom, ...rest } = receipt
1248
-
1249
- expect(blockNumber).toBeDefined()
1250
- expect(blockHash).toBeDefined()
1251
- expect(logs).toBeDefined()
1252
- expect(logsBloom).toBeDefined()
1253
- expect(rest).toMatchInlineSnapshot(`
1254
- {
1255
- "contractAddress": null,
1256
- "cumulativeGasUsed": "0x6fb8",
1257
- "effectiveGasPrice": "0x4a817c800",
1258
- "feeToken": "0x20c0000000000000000000000000000000000001",
1259
- "from": "0x6472aeab3269f4165775753156702c06ccc70f8b",
1260
- "gasUsed": "0x6fb8",
1261
- "status": "0x1",
1262
- "to": "0x0000000000000000000000000000000000000000",
1263
- "transactionHash": "0x2a9e63842240099fddcd4f247dfc2ea37aa7f635693d4f6a446059310ffb38a9",
1264
- "transactionIndex": "0x1",
1265
- "type": "0x76",
1266
- }
1267
- `)
1268
- })
1269
-
1270
- test('behavior: default (p256 - webcrypto)', async () => {
1271
- const keyPair = await WebCryptoP256.createKeyPair()
1272
- const address = Address.fromPublicKey(keyPair.publicKey)
1273
-
1274
- const client = createClient({
1275
- account: privateKeyToAccount(
1276
- '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',
1277
- ),
1278
- chain: tempoLocal({ feeToken: 1n }),
1279
- transport: http('http://localhost:3000'),
1280
- })
1281
-
1282
- await Actions.token.transferSync(client, {
1283
- amount: parseUnits('10', 6),
1284
- token: 1n,
1285
- to: address,
1286
- })
1287
-
1288
- const transaction = TransactionEnvelopeAA.from({
1289
- calls: [
1290
- {
1291
- to: '0x0000000000000000000000000000000000000000',
1292
- },
1293
- ],
1294
- chainId: 1337,
1295
- gas: 100_000n,
1296
- maxFeePerGas: Value.fromGwei('20'),
1297
- maxPriorityFeePerGas: Value.fromGwei('10'),
1298
- })
1299
-
1300
- const signature = await WebCryptoP256.sign({
1301
- payload: TransactionEnvelopeAA.getSignPayload(transaction),
1302
- privateKey: keyPair.privateKey,
1303
- })
1304
-
1305
- const serialized_signed = TransactionEnvelopeAA.serialize(transaction, {
1306
- signature: SignatureEnvelope.from({
1307
- signature,
1308
- publicKey: keyPair.publicKey,
1309
- prehash: true,
1310
- type: 'p256',
1311
- }),
1312
- })
1313
-
1314
- const receipt = await client.request({
1315
- method: 'eth_sendRawTransactionSync',
1316
- params: [serialized_signed],
1317
- })
1318
-
1319
- expect(receipt).toBeDefined()
1320
-
1321
- {
1322
- const response = await client.request({
1323
- method: 'eth_getTransactionByHash',
1324
- params: [receipt.transactionHash],
1325
- })
1326
- if (!response) throw new Error()
1327
-
1328
- const { blockNumber, blockHash, from, hash, signature, ...rest } =
1329
- response as any
1330
-
1331
- expect(blockNumber).toBeDefined()
1332
- expect(blockHash).toBeDefined()
1333
- expect(from).toBeDefined()
1334
- expect(hash).toBe(receipt.transactionHash)
1335
- expect(signature).toBeDefined()
1336
- expect(rest).toMatchInlineSnapshot(`
1337
- {
1338
- "aaAuthorizationList": [],
1339
- "accessList": [],
1340
- "calls": [
1341
- {
1342
- "data": null,
1343
- "input": "0x",
1344
- "to": "0x0000000000000000000000000000000000000000",
1345
- "value": "0x0",
1346
- },
1347
- ],
1348
- "chainId": "0x539",
1349
- "feePayerSignature": null,
1350
- "feeToken": null,
1351
- "gas": "0x186a0",
1352
- "gasPrice": "0x4a817c800",
1353
- "maxFeePerGas": "0x4a817c800",
1354
- "maxPriorityFeePerGas": "0x2540be400",
1355
- "nonce": "0x0",
1356
- "nonceKey": "0x0",
1357
- "transactionIndex": "0x1",
1358
- "type": "0x76",
1359
- "validAfter": null,
1360
- "validBefore": null,
1361
- }
1362
- `)
1363
- }
1364
-
1365
- const {
1366
- blockNumber,
1367
- blockHash,
1368
- from,
1369
- logs,
1370
- logsBloom,
1371
- transactionHash,
1372
- ...rest
1373
- } = receipt
1374
-
1375
- expect(blockNumber).toBeDefined()
1376
- expect(blockHash).toBeDefined()
1377
- expect(from).toBeDefined()
1378
- expect(logs).toBeDefined()
1379
- expect(logsBloom).toBeDefined()
1380
- expect(transactionHash).toBe(receipt.transactionHash)
1381
- expect(rest).toMatchInlineSnapshot(`
1382
- {
1383
- "contractAddress": null,
1384
- "cumulativeGasUsed": "0x6fb8",
1385
- "effectiveGasPrice": "0x4a817c800",
1386
- "feeToken": "0x20c0000000000000000000000000000000000001",
1387
- "gasUsed": "0x6fb8",
1388
- "status": "0x1",
1389
- "to": "0x0000000000000000000000000000000000000000",
1390
- "transactionIndex": "0x1",
1391
- "type": "0x76",
1392
- }
1393
- `)
1394
- })
1395
-
1396
- test('behavior: default (webauthn)', async () => {
1397
- const privateKey =
1398
- '0x062d199fd1d30c4a905ed1164a31e73759a13827687a2f3057a7d19c220bc933'
1399
- const publicKey = P256.getPublicKey({ privateKey })
1400
- const address = Address.fromPublicKey(publicKey)
1401
-
1402
- const client = createClient({
1403
- account: privateKeyToAccount(
1404
- '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',
1405
- ),
1406
- chain: tempoLocal({ feeToken: 1n }),
1407
- transport: http('http://localhost:3000'),
1408
- })
1409
-
1410
- await Actions.token.transferSync(client, {
1411
- amount: parseUnits('10', 6),
1412
- token: 1n,
1413
- to: address,
1414
- })
1415
-
1416
- const transaction = TransactionEnvelopeAA.from({
1417
- calls: [
1418
- {
1419
- to: '0x0000000000000000000000000000000000000000',
1420
- },
1421
- ],
1422
- chainId: 1337,
1423
- gas: 100_000n,
1424
- maxFeePerGas: Value.fromGwei('20'),
1425
- maxPriorityFeePerGas: Value.fromGwei('10'),
1426
- })
1427
-
1428
- const { metadata, payload } = WebAuthnP256.getSignPayload({
1429
- challenge: TransactionEnvelopeAA.getSignPayload(transaction),
1430
- rpId: 'localhost',
1431
- origin: 'http://localhost',
1432
- })
1433
-
1434
- const signature = P256.sign({
1435
- payload,
1436
- privateKey,
1437
- hash: true,
1438
- })
1439
-
1440
- const serialized_signed = TransactionEnvelopeAA.serialize(transaction, {
1441
- signature: SignatureEnvelope.from({
1442
- signature,
1443
- publicKey,
1444
- metadata,
1445
- }),
1446
- })
1447
-
1448
- const receipt = await client.request({
1449
- method: 'eth_sendRawTransactionSync',
1450
- params: [serialized_signed],
1451
- })
1452
-
1453
- expect(receipt).toBeDefined()
1454
-
1455
- {
1456
- const response = await client.request({
1457
- method: 'eth_getTransactionByHash',
1458
- params: [receipt.transactionHash],
1459
- })
1460
- if (!response) throw new Error()
1461
-
1462
- const { blockNumber, blockHash, ...rest } = response
1463
-
1464
- expect(blockNumber).toBeDefined()
1465
- expect(blockHash).toBeDefined()
1466
- expect(rest).toMatchInlineSnapshot(`
1467
- {
1468
- "aaAuthorizationList": [],
1469
- "accessList": [],
1470
- "calls": [
1471
- {
1472
- "data": null,
1473
- "input": "0x",
1474
- "to": "0x0000000000000000000000000000000000000000",
1475
- "value": "0x0",
1476
- },
1477
- ],
1478
- "chainId": "0x539",
1479
- "feePayerSignature": null,
1480
- "feeToken": null,
1481
- "from": "0x6472aeab3269f4165775753156702c06ccc70f8b",
1482
- "gas": "0x186a0",
1483
- "gasPrice": "0x4a817c800",
1484
- "hash": "0x3f5f2fc01b332f29a4f92e118e18cab3af88d02137440946f182afcef4ac5ab0",
1485
- "maxFeePerGas": "0x4a817c800",
1486
- "maxPriorityFeePerGas": "0x2540be400",
1487
- "nonce": "0x0",
1488
- "nonceKey": "0x0",
1489
- "signature": {
1490
- "pubKeyX": "0xecbf69146add5d7c649c96d90b64d90702c6faae7115adbad50e5e61b2c5f40d",
1491
- "pubKeyY": "0xeca3a5fc6dc4225b4f3f9720750651d43c6eb45c0492b8e9930394d1524784c6",
1492
- "r": "0x57383308881872875f2d3b0a00e3761d35a175d3b5821ec7370e7c445762ae99",
1493
- "s": "0x4ee7958e8358bcac83db7434a7887cdfdd51b8f201af562e6f09815a8d02469a",
1494
- "type": "webAuthn",
1495
- "webauthnData": "0x49960de5880e8c687434170f6476605b8fe4aeb9a28632c7995cf3ba831d976305000000007b2274797065223a22776562617574686e2e676574222c226368616c6c656e6765223a224a45314b6a5f764f375a52537536316157517567426d42654e6366534a7079435a6e2d714a4c3749684e6b222c226f726967696e223a22687474703a2f2f6c6f63616c686f7374222c2263726f73734f726967696e223a66616c73657d",
1496
- },
1497
- "transactionIndex": "0x1",
1498
- "type": "0x76",
1499
- "validAfter": null,
1500
- "validBefore": null,
1501
- }
1502
- `)
1503
- }
1504
-
1505
- const { blockNumber, blockHash, logs, logsBloom, ...rest } = receipt
1506
-
1507
- expect(blockNumber).toBeDefined()
1508
- expect(blockHash).toBeDefined()
1509
- expect(logs).toBeDefined()
1510
- expect(logsBloom).toBeDefined()
1511
-
1512
- expect(rest).toMatchInlineSnapshot(`
1513
- {
1514
- "contractAddress": null,
1515
- "cumulativeGasUsed": "0x79e8",
1516
- "effectiveGasPrice": "0x4a817c800",
1517
- "feeToken": "0x20c0000000000000000000000000000000000001",
1518
- "from": "0x6472aeab3269f4165775753156702c06ccc70f8b",
1519
- "gasUsed": "0x79e8",
1520
- "status": "0x1",
1521
- "to": "0x0000000000000000000000000000000000000000",
1522
- "transactionHash": "0x3f5f2fc01b332f29a4f92e118e18cab3af88d02137440946f182afcef4ac5ab0",
1523
- "transactionIndex": "0x1",
1524
- "type": "0x76",
1525
- }
1526
- `)
1527
- })
1528
-
1529
- test('behavior: feePayerSignature (user → feePayer)', async () => {
1530
- const feePayer = {
1531
- address: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
1532
- privateKey:
1533
- '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',
1534
- } as const
1535
- const sender = {
1536
- address: '0x0a275bEE91B39092Dfd57089Dee0EB0539020B90',
1537
- privateKey:
1538
- '0xfe24691eff5297c76e847dc78a8966b96cf65a44140b9a0d3f5100ce71d74a59',
1539
- } as const
1540
-
1541
- const transport = RpcTransport.fromHttp('http://localhost:3000')
1542
-
1543
- const nonce = await transport.request({
1544
- method: 'eth_getTransactionCount',
1545
- params: [sender.address, 'pending'],
1546
- })
1547
-
1548
- const transaction = TransactionEnvelopeAA.from({
1549
- calls: [{ to: '0x0000000000000000000000000000000000000000', value: 0n }],
1550
- chainId: 1337,
1551
- feePayerSignature: null,
1552
- nonce: BigInt(nonce),
1553
- gas: 100000n,
1554
- maxFeePerGas: Value.fromGwei('20'),
1555
- maxPriorityFeePerGas: Value.fromGwei('10'),
1556
- })
1557
-
1558
- const signature = Secp256k1.sign({
1559
- payload: TransactionEnvelopeAA.getSignPayload(transaction),
1560
- // unfunded PK
1561
- privateKey: sender.privateKey,
1562
- })
1563
-
1564
- const transaction_signed = TransactionEnvelopeAA.from(transaction, {
1565
- signature: SignatureEnvelope.from(signature),
1566
- })
1567
-
1568
- const feePayerSignature = Secp256k1.sign({
1569
- payload: TransactionEnvelopeAA.getFeePayerSignPayload(
1570
- transaction_signed,
1571
- { sender: sender.address },
1572
- ),
1573
- privateKey: feePayer.privateKey,
1574
- })
1575
-
1576
- const serialized_signed = TransactionEnvelopeAA.serialize(
1577
- transaction_signed,
1578
- {
1579
- feePayerSignature,
1580
- },
1581
- )
1582
-
1583
- const receipt = await transport.request({
1584
- method: 'eth_sendRawTransactionSync',
1585
- params: [serialized_signed],
1586
- })
1587
-
1588
- const { blockNumber, blockHash, logs, logsBloom, ...rest } = receipt
1589
-
1590
- expect(blockNumber).toBeDefined()
1591
- expect(blockHash).toBeDefined()
1592
- expect(logs).toBeDefined()
1593
- expect(logsBloom).toBeDefined()
1594
- expect(rest).toMatchInlineSnapshot(`
1595
- {
1596
- "contractAddress": null,
1597
- "cumulativeGasUsed": "0x5c30",
1598
- "effectiveGasPrice": "0x4a817c800",
1599
- "feeToken": "0x20c0000000000000000000000000000000000001",
1600
- "from": "0x0a275bee91b39092dfd57089dee0eb0539020b90",
1601
- "gasUsed": "0x5c30",
1602
- "status": "0x1",
1603
- "to": "0x0000000000000000000000000000000000000000",
1604
- "transactionHash": "0xec109f6683ab104359031628e425d08f13b3d7d8cca68672325305eac6b89919",
1605
- "transactionIndex": "0x1",
1606
- "type": "0x76",
1607
- }
1608
- `)
1609
-
1610
- const tx = await transport
1611
- .request({
1612
- method: 'eth_getTransactionByHash',
1613
- params: [receipt.transactionHash],
1614
- })
1615
- .then(Transaction.fromRpc)
1616
-
1617
- expect({
1618
- ...tx,
1619
- blockHash: undefined,
1620
- blockNumber: undefined,
1621
- }).toMatchInlineSnapshot(`
1622
- {
1623
- "aaAuthorizationList": [],
1624
- "accessList": [],
1625
- "blockHash": undefined,
1626
- "blockNumber": undefined,
1627
- "calls": [
1628
- {
1629
- "data": "0x",
1630
- "to": "0x0000000000000000000000000000000000000000",
1631
- "value": 0n,
1632
- },
1633
- ],
1634
- "chainId": 1337,
1635
- "data": undefined,
1636
- "feePayer": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
1637
- "feePayerSignature": {
1638
- "r": 90188278262501455201631375192727818264315724619851296903313643365872014474939n,
1639
- "s": 21522416408659292937651233939002591804919112021519345001364348623262878861140n,
1640
- "v": 27,
1641
- "yParity": 0,
1642
- },
1643
- "feeToken": null,
1644
- "from": "0x0a275bee91b39092dfd57089dee0eb0539020b90",
1645
- "gas": 100000n,
1646
- "gasPrice": 20000000000n,
1647
- "hash": "0xec109f6683ab104359031628e425d08f13b3d7d8cca68672325305eac6b89919",
1648
- "maxFeePerGas": 20000000000n,
1649
- "maxPriorityFeePerGas": 10000000000n,
1650
- "nonce": 0n,
1651
- "nonceKey": 0n,
1652
- "signature": {
1653
- "signature": {
1654
- "r": 10292676348145489655282185382992892512159498737579150910965384786990352734279n,
1655
- "s": 28525945667606979170826991633900153723921049713502164917966936632594819232361n,
1656
- "yParity": 0,
1657
- },
1658
- "type": "secp256k1",
1659
- },
1660
- "transactionIndex": 1,
1661
- "type": "aa",
1662
- "validAfter": null,
1663
- "validBefore": null,
1664
- "value": 0n,
1665
- }
1666
- `)
1667
- })
1668
- })