tempo.ts 0.5.0 → 0.5.2

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 (44) hide show
  1. package/dist/viem/Actions/policy.d.ts +9 -1
  2. package/dist/viem/Actions/policy.d.ts.map +1 -1
  3. package/dist/viem/Actions/policy.js.map +1 -1
  4. package/dist/viem/Chain.d.ts.map +1 -1
  5. package/dist/viem/Chain.js +3 -1
  6. package/dist/viem/Chain.js.map +1 -1
  7. package/dist/viem/Formatters.js +1 -1
  8. package/dist/viem/Formatters.js.map +1 -1
  9. package/dist/viem/Transport.d.ts +8 -0
  10. package/dist/viem/Transport.d.ts.map +1 -1
  11. package/dist/viem/Transport.js +87 -1
  12. package/dist/viem/Transport.js.map +1 -1
  13. package/dist/wagmi/Actions/index.d.ts +1 -0
  14. package/dist/wagmi/Actions/index.d.ts.map +1 -1
  15. package/dist/wagmi/Actions/index.js +1 -0
  16. package/dist/wagmi/Actions/index.js.map +1 -1
  17. package/dist/wagmi/Actions/policy.d.ts +481 -0
  18. package/dist/wagmi/Actions/policy.d.ts.map +1 -0
  19. package/dist/wagmi/Actions/policy.js +530 -0
  20. package/dist/wagmi/Actions/policy.js.map +1 -0
  21. package/dist/wagmi/Connector.d.ts +1 -1
  22. package/dist/wagmi/Connector.d.ts.map +1 -1
  23. package/dist/wagmi/Connector.js +3 -85
  24. package/dist/wagmi/Connector.js.map +1 -1
  25. package/dist/wagmi/Hooks/index.d.ts +1 -0
  26. package/dist/wagmi/Hooks/index.d.ts.map +1 -1
  27. package/dist/wagmi/Hooks/index.js +1 -0
  28. package/dist/wagmi/Hooks/index.js.map +1 -1
  29. package/dist/wagmi/Hooks/policy.d.ts +424 -0
  30. package/dist/wagmi/Hooks/policy.d.ts.map +1 -0
  31. package/dist/wagmi/Hooks/policy.js +510 -0
  32. package/dist/wagmi/Hooks/policy.js.map +1 -0
  33. package/package.json +2 -2
  34. package/src/viem/Actions/policy.ts +25 -0
  35. package/src/viem/Chain.ts +3 -1
  36. package/src/viem/Formatters.ts +1 -1
  37. package/src/viem/Transport.ts +107 -1
  38. package/src/wagmi/Actions/index.ts +1 -0
  39. package/src/wagmi/Actions/policy.test.ts +461 -0
  40. package/src/wagmi/Actions/policy.ts +819 -0
  41. package/src/wagmi/Connector.ts +4 -112
  42. package/src/wagmi/Hooks/index.ts +1 -0
  43. package/src/wagmi/Hooks/policy.test.ts +665 -0
  44. package/src/wagmi/Hooks/policy.ts +875 -0
@@ -1,33 +1,22 @@
1
1
  import * as Address from 'ox/Address'
2
2
  import * as Bytes from 'ox/Bytes'
3
- import * as Hash from 'ox/Hash'
4
- import * as Hex from 'ox/Hex'
5
- import * as Provider from 'ox/Provider'
6
- import * as RpcRequest from 'ox/RpcRequest'
3
+ import type * as Hex from 'ox/Hex'
7
4
  import {
8
5
  createClient,
9
6
  type EIP1193Provider,
10
7
  getAddress,
11
8
  type LocalAccount,
12
9
  SwitchChainError,
13
- type Transport,
14
- type Account as viem_Account,
15
10
  } from 'viem'
16
11
  import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts'
17
- import {
18
- getTransactionReceipt,
19
- sendTransaction,
20
- sendTransactionSync,
21
- } from 'viem/actions'
22
12
  import { ChainNotConfiguredError, createConnector } from 'wagmi'
23
13
  import * as Account from '../viem/Account.js'
24
14
  import type * as tempo_Chain from '../viem/Chain.js'
15
+ import { walletNamespaceCompat } from '../viem/Transport.js'
25
16
  import * as WebAuthnP256 from '../viem/WebAuthnP256.js'
26
17
 
27
18
  type Chain = ReturnType<ReturnType<typeof tempo_Chain.define>>
28
19
 
29
- const sendCallsMagic = Hash.keccak256(Hex.fromString('TEMPO_5792'))
30
-
31
20
  /**
32
21
  * Connector for a Secp256k1 EOA.
33
22
  *
@@ -185,9 +174,7 @@ export function dangerous_secp256k1(
185
174
  return createClient({
186
175
  account,
187
176
  chain: chain as Chain,
188
- transport: withErc5792Compat(transport, {
189
- account,
190
- }),
177
+ transport: walletNamespaceCompat(transport),
191
178
  })
192
179
  },
193
180
  async getProvider({ chainId } = {}) {
@@ -377,9 +364,7 @@ export function webAuthn(options: webAuthn.Parameters = {}) {
377
364
  return createClient({
378
365
  account,
379
366
  chain: chain as Chain,
380
- transport: withErc5792Compat(transport, {
381
- account,
382
- }),
367
+ transport: walletNamespaceCompat(transport),
383
368
  })
384
369
  },
385
370
  async getProvider({ chainId } = {}) {
@@ -414,96 +399,3 @@ export declare namespace webAuthn {
414
399
  rpId?: string | undefined
415
400
  }
416
401
  }
417
-
418
- // TODO: This is a temporary workaround to support EIP-5792. To be removed
419
- // once we support a EIP-1193 Provider abstraction for Tempo accounts.
420
- // biome-ignore lint/correctness/noUnusedVariables: _
421
- function withErc5792Compat(
422
- transport: Transport,
423
- { account }: withErc5792Compat.Options,
424
- ): Transport {
425
- return (options) => {
426
- const t = transport(options)
427
-
428
- return {
429
- ...t,
430
- async request(args: never) {
431
- const request = RpcRequest.from(args)
432
-
433
- const client = createClient({
434
- account,
435
- chain: options.chain as Chain,
436
- transport,
437
- })
438
-
439
- if (request.method === 'wallet_sendCalls') {
440
- const params = request.params[0] ?? {}
441
- const { capabilities, chainId, from } = params
442
- const { sync } = capabilities ?? {}
443
-
444
- if (!account) throw new Provider.DisconnectedError()
445
- if (!chainId) throw new Provider.UnsupportedChainIdError()
446
- if (Number(chainId) !== client.chain.id)
447
- throw new Provider.UnsupportedChainIdError()
448
- if (from && !Address.isEqual(from, account.address))
449
- throw new Provider.DisconnectedError()
450
-
451
- const calls = (params.calls ?? []).map((call) => ({
452
- to: call.to,
453
- value: call.value ? BigInt(call.value) : undefined,
454
- data: call.data,
455
- }))
456
-
457
- const hash = await (async () => {
458
- if (!sync)
459
- return sendTransaction(client, {
460
- account,
461
- calls,
462
- })
463
-
464
- const { transactionHash } = await sendTransactionSync(client, {
465
- account,
466
- calls,
467
- })
468
- return transactionHash
469
- })()
470
-
471
- const id = Hex.concat(hash, Hex.padLeft(chainId, 32), sendCallsMagic)
472
-
473
- return {
474
- capabilities: { sync },
475
- id,
476
- }
477
- }
478
-
479
- if (request.method === 'wallet_getCallsStatus') {
480
- const [id] = request.params ?? []
481
- if (!id) throw new Error('`id` not found')
482
- if (!id.endsWith(sendCallsMagic.slice(2)))
483
- throw new Error('`id` not supported')
484
- Hex.assert(id)
485
-
486
- const hash = Hex.slice(id, 0, 32)
487
- const chainId = Hex.slice(id, 32, 64)
488
-
489
- const receipt = await getTransactionReceipt(client, { hash })
490
- return {
491
- atomic: true,
492
- chainId: Number(chainId),
493
- receipts: [receipt],
494
- status: receipt.status === 'success' ? 200 : 500,
495
- version: '2.0.0',
496
- }
497
- }
498
-
499
- return t.request(args)
500
- },
501
- } as never
502
- }
503
- }
504
-
505
- declare namespace withErc5792Compat {
506
- type Options = {
507
- account: viem_Account | undefined
508
- }
509
- }
@@ -2,5 +2,6 @@ export * as amm from './amm.js'
2
2
  export * as dex from './dex.js'
3
3
  export * as faucet from './faucet.js'
4
4
  export * as fee from './fee.js'
5
+ export * as policy from './policy.js'
5
6
  export * as reward from './reward.js'
6
7
  export * as token from './token.js'