accounts 0.18.4 → 0.19.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 (71) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/core/AccessKey.d.ts +5 -1
  3. package/dist/core/AccessKey.d.ts.map +1 -1
  4. package/dist/core/AccessKey.js +2 -0
  5. package/dist/core/AccessKey.js.map +1 -1
  6. package/dist/core/Adapter.d.ts +4 -0
  7. package/dist/core/Adapter.d.ts.map +1 -1
  8. package/dist/core/Client.d.ts.map +1 -1
  9. package/dist/core/Client.js +62 -2
  10. package/dist/core/Client.js.map +1 -1
  11. package/dist/core/ExecutionError.d.ts.map +1 -1
  12. package/dist/core/ExecutionError.js +38 -3
  13. package/dist/core/ExecutionError.js.map +1 -1
  14. package/dist/core/Provider.d.ts.map +1 -1
  15. package/dist/core/Provider.js +16 -4
  16. package/dist/core/Provider.js.map +1 -1
  17. package/dist/core/Schema.d.ts +43 -0
  18. package/dist/core/Schema.d.ts.map +1 -1
  19. package/dist/core/adapters/privy.d.ts.map +1 -1
  20. package/dist/core/adapters/privy.js +7 -2
  21. package/dist/core/adapters/privy.js.map +1 -1
  22. package/dist/core/zod/rpc.d.ts +18 -0
  23. package/dist/core/zod/rpc.d.ts.map +1 -1
  24. package/dist/core/zod/rpc.js +13 -2
  25. package/dist/core/zod/rpc.js.map +1 -1
  26. package/dist/react/Remote.d.ts.map +1 -1
  27. package/dist/react/Remote.js +5 -1
  28. package/dist/react/Remote.js.map +1 -1
  29. package/dist/server/CliAuth.d.ts.map +1 -1
  30. package/dist/server/CliAuth.js +6 -4
  31. package/dist/server/CliAuth.js.map +1 -1
  32. package/dist/server/internal/handlers/relay.d.ts +0 -7
  33. package/dist/server/internal/handlers/relay.d.ts.map +1 -1
  34. package/dist/server/internal/handlers/relay.js +0 -46
  35. package/dist/server/internal/handlers/relay.js.map +1 -1
  36. package/dist/server/internal/handlers/sponsorship.d.ts +0 -2
  37. package/dist/server/internal/handlers/sponsorship.d.ts.map +1 -1
  38. package/dist/server/internal/handlers/sponsorship.js +1 -2
  39. package/dist/server/internal/handlers/sponsorship.js.map +1 -1
  40. package/dist/trusted-hosts.json +1 -0
  41. package/package.json +5 -5
  42. package/src/cli/Provider.localnet.test.ts +3 -3
  43. package/src/core/AccessKey.permissions.test.ts +73 -0
  44. package/src/core/AccessKey.test.ts +29 -27
  45. package/src/core/AccessKey.ts +7 -1
  46. package/src/core/Adapter.ts +4 -0
  47. package/src/core/Client.test.ts +153 -1
  48. package/src/core/Client.ts +73 -2
  49. package/src/core/ExecutionError.ts +39 -3
  50. package/src/core/Provider.localnet.test.ts +116 -1
  51. package/src/core/Provider.ts +25 -8
  52. package/src/core/Schema.test-d.ts +14 -0
  53. package/src/core/adapters/deviceCode/deviceCode.localnet.test.ts +4 -1
  54. package/src/core/adapters/privy.test.ts +150 -8
  55. package/src/core/adapters/privy.ts +13 -5
  56. package/src/core/zod/request.test.ts +26 -0
  57. package/src/core/zod/rpc.ts +15 -4
  58. package/src/react/Remote.test.ts +153 -0
  59. package/src/react/Remote.ts +7 -1
  60. package/src/server/CliAuth.test.ts +5 -3
  61. package/src/server/CliAuth.ts +6 -4
  62. package/src/server/internal/handlers/relay.ts +0 -56
  63. package/src/server/internal/handlers/sponsorship.ts +1 -4
  64. package/src/trusted-hosts.json +1 -0
  65. package/dist/server/internal/handlers/multisig.d.ts +0 -214
  66. package/dist/server/internal/handlers/multisig.d.ts.map +0 -1
  67. package/dist/server/internal/handlers/multisig.js +0 -505
  68. package/dist/server/internal/handlers/multisig.js.map +0 -1
  69. package/src/server/internal/handlers/multisig.localnet.test.ts +0 -94
  70. package/src/server/internal/handlers/multisig.test.ts +0 -743
  71. package/src/server/internal/handlers/multisig.ts +0 -774
@@ -1,743 +0,0 @@
1
- import { Address, Hex, P256 } from 'ox'
2
- import { MultisigConfig, SignatureEnvelope, TxEnvelopeTempo } from 'ox/tempo'
3
- import { createClient, custom } from 'viem'
4
- import { Account, Transaction } from 'viem/tempo'
5
- import { tempoDevnet } from 'viem/tempo/chains'
6
- import { describe, expect, test } from 'vp/test'
7
-
8
- import * as Multisig from './multisig.js'
9
-
10
- const privateKey_1 = '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'
11
- const privateKey_2 = '0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d'
12
- const privateKey_3 = '0x7c852118294f7e395961158d39c448445a22a434adcd1d4e9048bcd3d85e9e4d'
13
- const feeToken = '0x20c0000000000000000000000000000000000000' as const
14
-
15
- describe('memoryStore', () => {
16
- test('behavior: submission claims are exclusive until TTL expiry', async () => {
17
- const store = Multisig.memoryStore()
18
- const operation = createOperation()
19
-
20
- await store.savePending(operation)
21
- const first = await store.claimSubmission(operation, { ttl: 1_000 })
22
- const second = await store.claimSubmission(operation, { ttl: 1_000 })
23
-
24
- expect({ first: first.status, second: second.status }).toMatchInlineSnapshot(`
25
- {
26
- "first": "claimed",
27
- "second": "submitting",
28
- }
29
- `)
30
- })
31
-
32
- test('behavior: expired submission claims can be reclaimed', async () => {
33
- const store = Multisig.memoryStore()
34
- const operation = createOperation()
35
-
36
- await store.savePending(operation)
37
- await store.claimSubmission(operation, { ttl: -1 })
38
- const reclaimed = await store.claimSubmission(operation, { ttl: 1_000 })
39
-
40
- expect(reclaimed.status).toMatchInlineSnapshot(`"claimed"`)
41
- })
42
-
43
- test('behavior: pending saves merge signatures and submitted operations are not listed as pending', async () => {
44
- const store = Multisig.memoryStore()
45
- const operation = createOperation()
46
-
47
- await store.savePending({ ...operation, signatures: [`0x${'11'.repeat(65)}`] })
48
- const merged = await store.savePending({ ...operation, signatures: [`0x${'22'.repeat(65)}`] })
49
- await store.claimSubmission(merged, { ttl: 1_000 })
50
- await store.setSubmitted(operation.id, `0x${'33'.repeat(32)}`)
51
-
52
- expect({
53
- listed: await store.listPendingByAddress(operation.account),
54
- signatures: merged.signatures.length,
55
- status: (await store.get(operation.id))?.status,
56
- }).toMatchInlineSnapshot(`
57
- {
58
- "listed": [],
59
- "signatures": 2,
60
- "status": "submitted",
61
- }
62
- `)
63
- })
64
- })
65
-
66
- describe('handleRawTransaction', () => {
67
- test('behavior: rejects first approvals when no config can be resolved', async () => {
68
- const owner = Account.fromSecp256k1(privateKey_1)
69
- const account = Account.fromMultisig({
70
- threshold: 1,
71
- owners: [{ owner: owner.address, weight: 1 }],
72
- })
73
- const transaction = {
74
- calls: [{ to: '0xcafebabecafebabecafebabecafebabecafebabe', value: 1n }],
75
- chainId: tempoDevnet.id,
76
- gas: 21_000n,
77
- maxFeePerGas: 1n,
78
- maxPriorityFeePerGas: 0n,
79
- multisig: account.config,
80
- nonce: 0n,
81
- }
82
- const signature = await owner.signTransaction(transaction as never)
83
- const serialized = withoutInit(
84
- await account.signTransaction({ ...transaction, signatures: [signature] } as never),
85
- )
86
-
87
- await expect(
88
- Multisig.handleRawTransaction({
89
- getClient: (() => undefined) as never,
90
- method: 'eth_sendRawTransaction',
91
- request: { params: [serialized] },
92
- store: Multisig.memoryStore(),
93
- }),
94
- ).rejects.toThrowErrorMatchingInlineSnapshot(
95
- `[RpcResponse.InvalidParamsError: Multisig config is required to collect approvals. Provide it in the bootstrap transaction or configure \`multisig.resolveConfig\`.]`,
96
- )
97
- })
98
-
99
- test('behavior: finalize submitted preserves async broadcast method', async () => {
100
- const owner = Account.fromSecp256k1(privateKey_1)
101
- const account = Account.fromMultisig({
102
- threshold: 1,
103
- owners: [{ owner: owner.address, weight: 1 }],
104
- })
105
- const transaction = {
106
- calls: [{ to: '0xcafebabecafebabecafebabecafebabecafebabe', value: 1n }],
107
- chainId: tempoDevnet.id,
108
- gas: 21_000n,
109
- maxFeePerGas: 1n,
110
- maxPriorityFeePerGas: 0n,
111
- multisig: account.config,
112
- nonce: 0n,
113
- }
114
- const signature = await owner.signTransaction(transaction as never)
115
- const serialized = await account.signTransaction({
116
- ...transaction,
117
- signatures: [signature],
118
- } as never)
119
- let broadcastMethod: string | undefined
120
-
121
- const hash = await Multisig.handleRawTransaction({
122
- finalize: 'submitted',
123
- getClient: (() => ({
124
- request: async ({ method, params }: { method: string; params: unknown }) => {
125
- broadcastMethod = method
126
- return hashRawTransaction(params)
127
- },
128
- })) as never,
129
- method: 'eth_sendRawTransaction',
130
- request: { params: [serialized] },
131
- store: Multisig.memoryStore(),
132
- })
133
-
134
- expect({ broadcastMethod, hash }).toMatchInlineSnapshot(`
135
- {
136
- "broadcastMethod": "eth_sendRawTransaction",
137
- "hash": "${hash}",
138
- }
139
- `)
140
- })
141
- })
142
-
143
- describe('config resolution', () => {
144
- test('behavior: reuses pending bootstrap config when a later approval omits init', async () => {
145
- const store = Multisig.memoryStore()
146
- const owner_1 = Account.fromSecp256k1(privateKey_1)
147
- const owner_2 = Account.fromSecp256k1(privateKey_2)
148
- const account = Account.fromMultisig({
149
- threshold: 2,
150
- owners: [
151
- { owner: owner_1.address, weight: 1 },
152
- { owner: owner_2.address, weight: 1 },
153
- ],
154
- })
155
- const transaction = {
156
- calls: [{ to: '0xcafebabecafebabecafebabecafebabecafebabe', value: 1n }],
157
- chainId: tempoDevnet.id,
158
- gas: 21_000n,
159
- maxFeePerGas: 1n,
160
- maxPriorityFeePerGas: 0n,
161
- multisig: account.config,
162
- nonce: 0n,
163
- }
164
- const signature_1 = await owner_1.signTransaction(transaction as never)
165
- const signature_2 = await owner_2.signTransaction(transaction as never)
166
- const first = await account.signTransaction({
167
- ...transaction,
168
- signatures: [signature_1],
169
- } as never)
170
- const second = withoutInit(
171
- await account.signTransaction({ ...transaction, signatures: [signature_2] } as never),
172
- )
173
-
174
- await Multisig.handleRawTransaction({
175
- getClient: (() => undefined) as never,
176
- method: 'eth_sendRawTransaction',
177
- request: { params: [first] },
178
- store,
179
- })
180
- const hash = await Multisig.handleRawTransaction({
181
- getClient: (() => ({
182
- request: async ({ params }: { params: unknown }) => hashRawTransaction(params),
183
- })) as never,
184
- method: 'eth_sendRawTransaction',
185
- request: { params: [second] },
186
- store,
187
- })
188
-
189
- expect(hash).toMatchInlineSnapshot(`"${hash}"`)
190
- })
191
-
192
- test('behavior: preserves bootstrap init when it arrives after a resolver-backed pending approval', async () => {
193
- const store = Multisig.memoryStore()
194
- const owner_1 = Account.fromSecp256k1(privateKey_1)
195
- const owner_2 = Account.fromSecp256k1(privateKey_2)
196
- const account = Account.fromMultisig({
197
- threshold: 2,
198
- owners: [
199
- { owner: owner_1.address, weight: 1 },
200
- { owner: owner_2.address, weight: 1 },
201
- ],
202
- })
203
- const transaction = {
204
- calls: [{ to: '0xcafebabecafebabecafebabecafebabecafebabe', value: 1n }],
205
- chainId: tempoDevnet.id,
206
- gas: 21_000n,
207
- maxFeePerGas: 1n,
208
- maxPriorityFeePerGas: 0n,
209
- multisig: account.config,
210
- nonce: 0n,
211
- }
212
- const signature_1 = await owner_1.signTransaction(transaction as never)
213
- const signature_2 = await owner_2.signTransaction(transaction as never)
214
- const first = withoutInit(
215
- await account.signTransaction({ ...transaction, signatures: [signature_1] } as never),
216
- )
217
- const second = await account.signTransaction({
218
- ...transaction,
219
- signatures: [signature_2],
220
- } as never)
221
- let submitted: `0x${string}` | undefined
222
-
223
- await Multisig.handleRawTransaction({
224
- getClient: (() => undefined) as never,
225
- method: 'eth_sendRawTransaction',
226
- request: { params: [first] },
227
- resolveConfig: () => account.config,
228
- store,
229
- })
230
- const hash = await Multisig.handleRawTransaction({
231
- getClient: (() => ({
232
- request: async ({ params }: { params: unknown }) => {
233
- submitted = Array.isArray(params) ? (params[0] as `0x${string}`) : undefined
234
- return hashRawTransaction(params)
235
- },
236
- })) as never,
237
- method: 'eth_sendRawTransaction',
238
- request: { params: [second] },
239
- resolveConfig: () => account.config,
240
- store,
241
- })
242
-
243
- const transaction_submitted = Transaction.deserialize(submitted! as never) as {
244
- signature: SignatureEnvelope.Multisig
245
- }
246
- expect({
247
- hash,
248
- init: transaction_submitted.signature.init
249
- ? MultisigConfig.getAddress(transaction_submitted.signature.init)
250
- : undefined,
251
- }).toMatchInlineSnapshot(`
252
- {
253
- "hash": "${hash}",
254
- "init": "${MultisigConfig.getAddress(account.config)}",
255
- }
256
- `)
257
- })
258
-
259
- test('behavior: attaches resolver-provided bootstrap config when approvals omit init', async () => {
260
- const store = Multisig.memoryStore()
261
- const owner_1 = Account.fromSecp256k1(privateKey_1)
262
- const owner_2 = Account.fromSecp256k1(privateKey_2)
263
- const account = Account.fromMultisig({
264
- threshold: 2,
265
- owners: [
266
- { owner: owner_1.address, weight: 1 },
267
- { owner: owner_2.address, weight: 1 },
268
- ],
269
- })
270
- const transaction = {
271
- calls: [{ to: '0xcafebabecafebabecafebabecafebabecafebabe', value: 1n }],
272
- chainId: tempoDevnet.id,
273
- gas: 21_000n,
274
- maxFeePerGas: 1n,
275
- maxPriorityFeePerGas: 0n,
276
- multisig: account.config,
277
- nonce: 0n,
278
- }
279
- const signature_1 = await owner_1.signTransaction(transaction as never)
280
- const signature_2 = await owner_2.signTransaction(transaction as never)
281
- const first = withoutInit(
282
- await account.signTransaction({ ...transaction, signatures: [signature_1] } as never),
283
- )
284
- const second = withoutInit(
285
- await account.signTransaction({ ...transaction, signatures: [signature_2] } as never),
286
- )
287
- let submitted: `0x${string}` | undefined
288
-
289
- await Multisig.handleRawTransaction({
290
- getClient: (() => undefined) as never,
291
- method: 'eth_sendRawTransaction',
292
- request: { params: [first] },
293
- resolveConfig: () => account.config,
294
- store,
295
- })
296
- const hash = await Multisig.handleRawTransaction({
297
- getClient: (() => ({
298
- request: async ({ params }: { params: unknown }) => {
299
- submitted = Array.isArray(params) ? (params[0] as `0x${string}`) : undefined
300
- return hashRawTransaction(params)
301
- },
302
- })) as never,
303
- method: 'eth_sendRawTransaction',
304
- request: { params: [second] },
305
- resolveConfig: () => account.config,
306
- store,
307
- })
308
-
309
- const transaction_submitted = Transaction.deserialize(submitted! as never) as {
310
- signature: SignatureEnvelope.Multisig
311
- }
312
- expect({
313
- hash,
314
- init: transaction_submitted.signature.init
315
- ? MultisigConfig.getAddress(transaction_submitted.signature.init)
316
- : undefined,
317
- }).toMatchInlineSnapshot(`
318
- {
319
- "hash": "${hash}",
320
- "init": "${MultisigConfig.getAddress(account.config)}",
321
- }
322
- `)
323
- })
324
-
325
- test('behavior: preserves bootstrap init when claimed operation omits stored init config', async () => {
326
- const base = Multisig.memoryStore()
327
- const store: Multisig.Store = {
328
- claimSubmission: async (operation, options) => {
329
- const result = await base.claimSubmission(operation, options)
330
- if (result.status !== 'claimed') return result
331
- return {
332
- operation: { ...result.operation, initConfig: undefined },
333
- status: result.status,
334
- }
335
- },
336
- get: base.get,
337
- listPendingByAddress: base.listPendingByAddress,
338
- savePending: base.savePending,
339
- setSubmitted: base.setSubmitted,
340
- }
341
- const owner = Account.fromSecp256k1(privateKey_1)
342
- const account = Account.fromMultisig({
343
- threshold: 1,
344
- owners: [{ owner: owner.address, weight: 1 }],
345
- })
346
- const transaction = {
347
- calls: [{ to: '0xcafebabecafebabecafebabecafebabecafebabe', value: 1n }],
348
- chainId: tempoDevnet.id,
349
- gas: 21_000n,
350
- maxFeePerGas: 1n,
351
- maxPriorityFeePerGas: 0n,
352
- multisig: account.config,
353
- nonce: 0n,
354
- }
355
- const signature = await owner.signTransaction(transaction as never)
356
- const serialized = await account.signTransaction({
357
- ...transaction,
358
- signatures: [signature],
359
- } as never)
360
- let submitted: `0x${string}` | undefined
361
-
362
- const hash = await Multisig.handleRawTransaction({
363
- getClient: (() => ({
364
- request: async ({ params }: { params: unknown }) => {
365
- submitted = Array.isArray(params) ? (params[0] as `0x${string}`) : undefined
366
- return hashRawTransaction(params)
367
- },
368
- })) as never,
369
- method: 'eth_sendRawTransaction',
370
- request: { params: [serialized] },
371
- store,
372
- })
373
-
374
- const transaction_submitted = Transaction.deserialize(submitted! as never) as {
375
- signature: SignatureEnvelope.Multisig
376
- }
377
- expect({
378
- hash,
379
- init: transaction_submitted.signature.init
380
- ? MultisigConfig.getAddress(transaction_submitted.signature.init)
381
- : undefined,
382
- }).toMatchInlineSnapshot(`
383
- {
384
- "hash": "${hash}",
385
- "init": "${MultisigConfig.getAddress(account.config)}",
386
- }
387
- `)
388
- })
389
-
390
- test('behavior: rejects resolved configs that do not match the multisig account', async () => {
391
- const owner_1 = Account.fromSecp256k1(privateKey_1)
392
- const owner_2 = Account.fromSecp256k1(privateKey_2)
393
- const account = Account.fromMultisig({
394
- threshold: 1,
395
- owners: [{ owner: owner_1.address, weight: 1 }],
396
- })
397
- const wrong = Account.fromMultisig({
398
- threshold: 1,
399
- owners: [{ owner: owner_2.address, weight: 1 }],
400
- })
401
- const transaction = {
402
- calls: [{ to: '0xcafebabecafebabecafebabecafebabecafebabe', value: 1n }],
403
- chainId: tempoDevnet.id,
404
- gas: 21_000n,
405
- maxFeePerGas: 1n,
406
- maxPriorityFeePerGas: 0n,
407
- multisig: account.config,
408
- nonce: 0n,
409
- }
410
- const signature = await owner_1.signTransaction(transaction as never)
411
- const serialized = await account.signTransaction({
412
- ...transaction,
413
- signatures: [signature],
414
- } as never)
415
-
416
- await expect(
417
- Multisig.handleRawTransaction({
418
- getClient: (() => undefined) as never,
419
- method: 'eth_sendRawTransaction',
420
- request: { params: [serialized] },
421
- resolveConfig: () => wrong.config,
422
- store: Multisig.memoryStore(),
423
- }),
424
- ).rejects.toThrowErrorMatchingInlineSnapshot(
425
- `[RpcResponse.InvalidParamsError: Signature from non-owner 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266.]`,
426
- )
427
- })
428
-
429
- test('behavior: accepts current configs for updated multisig signer sets', async () => {
430
- const owner_1 = Account.fromSecp256k1(privateKey_1)
431
- const owner_2 = Account.fromSecp256k1(privateKey_2)
432
- const account = Account.fromMultisig({
433
- threshold: 1,
434
- owners: [{ owner: owner_1.address, weight: 1 }],
435
- })
436
- const current = MultisigConfig.from({
437
- owners: [
438
- { owner: owner_1.address, weight: 1 },
439
- { owner: owner_2.address, weight: 1 },
440
- ],
441
- threshold: 1,
442
- })
443
- const transaction = {
444
- calls: [{ to: '0xcafebabecafebabecafebabecafebabecafebabe', value: 1n }],
445
- chainId: tempoDevnet.id,
446
- gas: 21_000n,
447
- maxFeePerGas: 1n,
448
- maxPriorityFeePerGas: 0n,
449
- multisig: account.config,
450
- nonce: 1n,
451
- }
452
- const signature = await owner_2.signTransaction(transaction as never)
453
- const serialized = withoutInit(
454
- await account.signTransaction({
455
- ...transaction,
456
- signatures: [signature],
457
- } as never),
458
- )
459
- let submitted: `0x${string}` | undefined
460
-
461
- const hash = await Multisig.handleRawTransaction({
462
- getClient: (() => ({
463
- request: async ({ params }: { params: unknown }) => {
464
- submitted = Array.isArray(params) ? (params[0] as `0x${string}`) : undefined
465
- return hashRawTransaction(params)
466
- },
467
- })) as never,
468
- method: 'eth_sendRawTransaction',
469
- request: { params: [serialized] },
470
- resolveConfig: () => current,
471
- store: Multisig.memoryStore(),
472
- })
473
-
474
- const transaction_submitted = Transaction.deserialize(submitted! as never) as {
475
- signature: SignatureEnvelope.Multisig
476
- }
477
- expect({
478
- account: transaction_submitted.signature.account,
479
- hash,
480
- init: transaction_submitted.signature.init,
481
- }).toMatchInlineSnapshot(`
482
- {
483
- "account": "${MultisigConfig.getAddress(account.config)}",
484
- "hash": "${hash}",
485
- "init": undefined,
486
- }
487
- `)
488
- })
489
- })
490
-
491
- describe('approval validation', () => {
492
- test('behavior: rejects P256 approvals whose embedded owner key did not sign the operation', async () => {
493
- const privateKey = P256.randomPrivateKey()
494
- const publicKey = P256.getPublicKey({ privateKey })
495
- const owner = Address.fromPublicKey(publicKey)
496
- const account = Account.fromMultisig({
497
- threshold: 1,
498
- owners: [{ owner, weight: 1 }],
499
- })
500
- const transaction = {
501
- calls: [{ to: '0xcafebabecafebabecafebabecafebabecafebabe', value: 1n }],
502
- chainId: tempoDevnet.id,
503
- gas: 21_000n,
504
- maxFeePerGas: 1n,
505
- maxPriorityFeePerGas: 0n,
506
- multisig: account.config,
507
- nonce: 0n,
508
- }
509
- const signature = SignatureEnvelope.serialize(
510
- SignatureEnvelope.from({
511
- publicKey,
512
- signature: P256.sign({ payload: `0x${'44'.repeat(32)}`, privateKey }),
513
- type: 'p256',
514
- }),
515
- )
516
- const serialized = await account.signTransaction({
517
- ...transaction,
518
- signatures: [signature],
519
- } as never)
520
-
521
- await expect(
522
- Multisig.handleRawTransaction({
523
- getClient: (() => ({
524
- request: async ({ params }: { params: unknown }) => hashRawTransaction(params),
525
- })) as never,
526
- method: 'eth_sendRawTransaction',
527
- request: { params: [serialized] },
528
- store: Multisig.memoryStore(),
529
- }),
530
- ).rejects.toThrowErrorMatchingInlineSnapshot(
531
- `[RpcResponse.InvalidParamsError: Invalid signature from owner ${owner}.]`,
532
- )
533
- })
534
- })
535
-
536
- describe('handleRawTransaction with sponsor', () => {
537
- test('behavior: broadcasts finalized multisig transactions with feePayerSignature and default feeToken', async () => {
538
- const store = Multisig.memoryStore()
539
- const owner_1 = Account.fromSecp256k1(privateKey_1)
540
- const owner_2 = Account.fromSecp256k1(privateKey_2)
541
- const feePayer = Account.fromSecp256k1(privateKey_3)
542
- const account = Account.fromMultisig({
543
- threshold: 2,
544
- owners: [
545
- { owner: owner_1.address, weight: 1 },
546
- { owner: owner_2.address, weight: 1 },
547
- ],
548
- })
549
- const transaction = {
550
- calls: [{ to: '0xcafebabecafebabecafebabecafebabecafebabe', value: 1n }],
551
- chainId: tempoDevnet.id,
552
- feePayerSignature: null,
553
- gas: 21_000n,
554
- maxFeePerGas: 1n,
555
- maxPriorityFeePerGas: 0n,
556
- multisig: account.config,
557
- nonce: 0n,
558
- }
559
- const signature_1 = await owner_1.signTransaction(transaction as never)
560
- const signature_2 = await owner_2.signTransaction(transaction as never)
561
- const first = await account.signTransaction({
562
- ...transaction,
563
- signatures: [signature_1],
564
- } as never)
565
- const second = await account.signTransaction({
566
- ...transaction,
567
- signatures: [signature_2],
568
- } as never)
569
- const broadcasted: string[] = []
570
-
571
- await Multisig.handleRawTransaction({
572
- getClient: (() => undefined) as never,
573
- method: 'eth_sendRawTransaction',
574
- request: { params: [first] },
575
- sponsor: {
576
- account: feePayer as never,
577
- resolveFeeToken: () => feeToken,
578
- },
579
- store,
580
- })
581
- const hash = await Multisig.handleRawTransaction({
582
- getClient: () =>
583
- createClient({
584
- chain: tempoDevnet,
585
- transport: custom({
586
- request: async ({ method, params }) => {
587
- if (method === 'eth_chainId') return Hex.fromNumber(tempoDevnet.id)
588
- broadcasted.push((params as readonly string[])[0]!)
589
- return hashRawTransaction(params)
590
- },
591
- }),
592
- }),
593
- method: 'eth_sendRawTransaction',
594
- request: { params: [second] },
595
- sponsor: {
596
- account: feePayer as never,
597
- resolveFeeToken: () => feeToken,
598
- },
599
- store,
600
- })
601
-
602
- const transaction_broadcasted = Transaction.deserialize(broadcasted[0] as never) as Record<
603
- string,
604
- unknown
605
- >
606
- const signature = transaction_broadcasted.signature as { init?: unknown; type?: string }
607
- expect({
608
- feePayerSignature: Boolean(transaction_broadcasted.feePayerSignature),
609
- feeToken: (transaction_broadcasted.feeToken as string).toLowerCase(),
610
- hash,
611
- init: Boolean(signature.init),
612
- signature: signature.type,
613
- }).toMatchInlineSnapshot(`
614
- {
615
- "feePayerSignature": true,
616
- "feeToken": "0x20c0000000000000000000000000000000000000",
617
- "hash": "${hash}",
618
- "init": true,
619
- "signature": "multisig",
620
- }
621
- `)
622
- })
623
-
624
- test('behavior: broadcasts already sponsored multisig transactions without replacing fee payer', async () => {
625
- const owner = Account.fromSecp256k1(privateKey_1)
626
- const feePayer_original = Account.fromSecp256k1(privateKey_2)
627
- const feePayer_relay = Account.fromSecp256k1(privateKey_3)
628
- const account = Account.fromMultisig({
629
- threshold: 1,
630
- owners: [{ owner: owner.address, weight: 1 }],
631
- })
632
- const transaction = {
633
- calls: [{ to: '0xcafebabecafebabecafebabecafebabecafebabe', value: 1n }],
634
- chainId: tempoDevnet.id,
635
- feePayerSignature: null,
636
- gas: 21_000n,
637
- maxFeePerGas: 1n,
638
- maxPriorityFeePerGas: 0n,
639
- multisig: account.config,
640
- nonce: 0n,
641
- }
642
- const signature = await owner.signTransaction(transaction as never)
643
- const serialized = await account.signTransaction({
644
- ...transaction,
645
- signatures: [signature],
646
- } as never)
647
- const sponsored: `0x${string}`[] = []
648
-
649
- await Multisig.handleRawTransaction({
650
- getClient: () =>
651
- createClient({
652
- chain: tempoDevnet,
653
- transport: custom({
654
- request: async ({ method, params }) => {
655
- if (method === 'eth_chainId') return Hex.fromNumber(tempoDevnet.id)
656
- sponsored.push((params as readonly `0x${string}`[])[0]!)
657
- return hashRawTransaction(params)
658
- },
659
- }),
660
- }),
661
- method: 'eth_sendRawTransaction',
662
- request: { params: [serialized] },
663
- sponsor: {
664
- account: feePayer_original as never,
665
- resolveFeeToken: () => feeToken,
666
- },
667
- store: Multisig.memoryStore(),
668
- })
669
- const presponsored = sponsored[0]
670
- if (!presponsored) throw new Error('Expected pre-sponsored transaction.')
671
-
672
- let broadcasted: `0x${string}` | undefined
673
- const hash = await Multisig.handleRawTransaction({
674
- getClient: (() => ({
675
- request: async ({ params }: { params: unknown }) => {
676
- broadcasted = Array.isArray(params) ? (params[0] as `0x${string}`) : undefined
677
- return hashRawTransaction(params)
678
- },
679
- })) as never,
680
- method: 'eth_sendRawTransaction',
681
- request: { params: [presponsored] },
682
- sponsor: {
683
- account: feePayer_relay as never,
684
- feeToken,
685
- validate: () => false,
686
- },
687
- store: Multisig.memoryStore(),
688
- })
689
-
690
- const transaction_broadcasted = Transaction.deserialize(broadcasted! as never) as Record<
691
- string,
692
- unknown
693
- >
694
- expect({
695
- feePayerSignature: Boolean(transaction_broadcasted.feePayerSignature),
696
- feeToken: (transaction_broadcasted.feeToken as string).toLowerCase(),
697
- hash,
698
- signature: (transaction_broadcasted.signature as { type?: string }).type,
699
- }).toMatchInlineSnapshot(`
700
- {
701
- "feePayerSignature": true,
702
- "feeToken": "0x20c0000000000000000000000000000000000000",
703
- "hash": "${hash}",
704
- "signature": "multisig",
705
- }
706
- `)
707
- })
708
- })
709
-
710
- function createOperation(): Multisig.Operation {
711
- const now = Date.now()
712
- return {
713
- account: '0x0000000000000000000000000000000000000001',
714
- chainId: tempoDevnet.id,
715
- createdAt: now,
716
- id: `0x${'22'.repeat(32)}`,
717
- payload: `0x${'33'.repeat(32)}`,
718
- signatures: [],
719
- status: 'pending',
720
- transaction: `0x76${'44'.repeat(32)}`,
721
- updatedAt: now,
722
- }
723
- }
724
-
725
- function hashRawTransaction(params: unknown) {
726
- const serialized = Array.isArray(params) ? params[0] : undefined
727
- if (typeof serialized !== 'string') throw new Error('Expected raw transaction.')
728
- return TxEnvelopeTempo.hash(
729
- TxEnvelopeTempo.deserialize(serialized as TxEnvelopeTempo.Serialized) as TxEnvelopeTempo.Signed,
730
- )
731
- }
732
-
733
- function withoutInit(serialized: `0x${string}`) {
734
- const transaction = Transaction.deserialize(serialized as never) as Record<string, unknown>
735
- const signature = transaction.signature as SignatureEnvelope.Multisig
736
- const { signature: _, ...unsigned } = transaction
737
- return TxEnvelopeTempo.serialize(TxEnvelopeTempo.from(unsigned as never), {
738
- signature: SignatureEnvelope.from({
739
- account: signature.account,
740
- signatures: signature.signatures,
741
- }),
742
- })
743
- }