tempo.ts 0.11.0 → 0.12.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 (196) hide show
  1. package/CHANGELOG.md +67 -4
  2. package/README.md +3 -34
  3. package/dist/server/Handler.d.ts +14 -14
  4. package/dist/server/Handler.d.ts.map +1 -1
  5. package/dist/server/Handler.js +16 -17
  6. package/dist/server/Handler.js.map +1 -1
  7. package/dist/wagmi/Actions/amm.d.ts +51 -51
  8. package/dist/wagmi/Actions/amm.d.ts.map +1 -1
  9. package/dist/wagmi/Actions/amm.js +37 -37
  10. package/dist/wagmi/Actions/amm.js.map +1 -1
  11. package/dist/wagmi/Actions/dex.d.ts +129 -129
  12. package/dist/wagmi/Actions/dex.d.ts.map +1 -1
  13. package/dist/wagmi/Actions/dex.js +73 -73
  14. package/dist/wagmi/Actions/dex.js.map +1 -1
  15. package/dist/wagmi/Actions/faucet.d.ts +9 -9
  16. package/dist/wagmi/Actions/faucet.d.ts.map +1 -1
  17. package/dist/wagmi/Actions/faucet.js +7 -7
  18. package/dist/wagmi/Actions/faucet.js.map +1 -1
  19. package/dist/wagmi/Actions/fee.d.ts +17 -17
  20. package/dist/wagmi/Actions/fee.d.ts.map +1 -1
  21. package/dist/wagmi/Actions/fee.js +10 -10
  22. package/dist/wagmi/Actions/fee.js.map +1 -1
  23. package/dist/wagmi/Actions/nonce.d.ts +9 -79
  24. package/dist/wagmi/Actions/nonce.d.ts.map +1 -1
  25. package/dist/wagmi/Actions/nonce.js +7 -89
  26. package/dist/wagmi/Actions/nonce.js.map +1 -1
  27. package/dist/wagmi/Actions/policy.d.ts +69 -70
  28. package/dist/wagmi/Actions/policy.d.ts.map +1 -1
  29. package/dist/wagmi/Actions/policy.js +43 -43
  30. package/dist/wagmi/Actions/policy.js.map +1 -1
  31. package/dist/wagmi/Actions/reward.d.ts +51 -51
  32. package/dist/wagmi/Actions/reward.d.ts.map +1 -1
  33. package/dist/wagmi/Actions/reward.js +31 -31
  34. package/dist/wagmi/Actions/reward.js.map +1 -1
  35. package/dist/wagmi/Actions/token.d.ts +238 -238
  36. package/dist/wagmi/Actions/token.d.ts.map +1 -1
  37. package/dist/wagmi/Actions/token.js +136 -136
  38. package/dist/wagmi/Actions/token.js.map +1 -1
  39. package/dist/wagmi/Connector.d.ts +2 -1
  40. package/dist/wagmi/Connector.d.ts.map +1 -1
  41. package/dist/wagmi/Connector.js +83 -22
  42. package/dist/wagmi/Connector.js.map +1 -1
  43. package/dist/wagmi/Hooks/nonce.d.ts +1 -52
  44. package/dist/wagmi/Hooks/nonce.d.ts.map +1 -1
  45. package/dist/wagmi/Hooks/nonce.js +1 -70
  46. package/dist/wagmi/Hooks/nonce.js.map +1 -1
  47. package/dist/wagmi/Hooks/policy.d.ts +0 -1
  48. package/dist/wagmi/Hooks/policy.d.ts.map +1 -1
  49. package/dist/wagmi/Hooks/policy.js.map +1 -1
  50. package/dist/wagmi/KeyManager.d.ts +6 -3
  51. package/dist/wagmi/KeyManager.d.ts.map +1 -1
  52. package/dist/wagmi/KeyManager.js +9 -4
  53. package/dist/wagmi/KeyManager.js.map +1 -1
  54. package/package.json +2 -2
  55. package/src/server/Handler.test.ts +2 -2
  56. package/src/server/Handler.ts +16 -17
  57. package/src/wagmi/Actions/amm.ts +63 -63
  58. package/src/wagmi/Actions/dex.test.ts +1 -1
  59. package/src/wagmi/Actions/dex.ts +153 -153
  60. package/src/wagmi/Actions/faucet.ts +11 -11
  61. package/src/wagmi/Actions/fee.ts +20 -20
  62. package/src/wagmi/Actions/nonce.test.ts +1 -64
  63. package/src/wagmi/Actions/nonce.ts +10 -142
  64. package/src/wagmi/Actions/policy.ts +83 -85
  65. package/src/wagmi/Actions/reward.ts +64 -61
  66. package/src/wagmi/Actions/token.ts +287 -283
  67. package/src/wagmi/Connector.ts +105 -31
  68. package/src/wagmi/Hooks/dex.test.ts +1 -1
  69. package/src/wagmi/Hooks/fee.test.ts +0 -6
  70. package/src/wagmi/Hooks/nonce.test.ts +1 -66
  71. package/src/wagmi/Hooks/nonce.ts +1 -114
  72. package/src/wagmi/Hooks/policy.ts +0 -2
  73. package/src/wagmi/KeyManager.ts +18 -5
  74. package/dist/viem/Abis.d.ts +0 -2649
  75. package/dist/viem/Abis.d.ts.map +0 -1
  76. package/dist/viem/Abis.js +0 -1677
  77. package/dist/viem/Abis.js.map +0 -1
  78. package/dist/viem/Account.d.ts +0 -244
  79. package/dist/viem/Account.d.ts.map +0 -1
  80. package/dist/viem/Account.js +0 -382
  81. package/dist/viem/Account.js.map +0 -1
  82. package/dist/viem/Actions/amm.d.ts +0 -1991
  83. package/dist/viem/Actions/amm.d.ts.map +0 -1
  84. package/dist/viem/Actions/amm.js +0 -814
  85. package/dist/viem/Actions/amm.js.map +0 -1
  86. package/dist/viem/Actions/dex.d.ts +0 -3900
  87. package/dist/viem/Actions/dex.d.ts.map +0 -1
  88. package/dist/viem/Actions/dex.js +0 -1414
  89. package/dist/viem/Actions/dex.js.map +0 -1
  90. package/dist/viem/Actions/faucet.d.ts +0 -69
  91. package/dist/viem/Actions/faucet.d.ts.map +0 -1
  92. package/dist/viem/Actions/faucet.js +0 -73
  93. package/dist/viem/Actions/faucet.js.map +0 -1
  94. package/dist/viem/Actions/fee.d.ts +0 -360
  95. package/dist/viem/Actions/fee.d.ts.map +0 -1
  96. package/dist/viem/Actions/fee.js +0 -237
  97. package/dist/viem/Actions/fee.js.map +0 -1
  98. package/dist/viem/Actions/nonce.d.ts +0 -257
  99. package/dist/viem/Actions/nonce.d.ts.map +0 -1
  100. package/dist/viem/Actions/nonce.js +0 -228
  101. package/dist/viem/Actions/nonce.js.map +0 -1
  102. package/dist/viem/Actions/policy.d.ts +0 -1680
  103. package/dist/viem/Actions/policy.d.ts.map +0 -1
  104. package/dist/viem/Actions/policy.js +0 -875
  105. package/dist/viem/Actions/policy.js.map +0 -1
  106. package/dist/viem/Actions/reward.d.ts +0 -2422
  107. package/dist/viem/Actions/reward.d.ts.map +0 -1
  108. package/dist/viem/Actions/reward.js +0 -651
  109. package/dist/viem/Actions/reward.js.map +0 -1
  110. package/dist/viem/Actions/token.d.ts +0 -16007
  111. package/dist/viem/Actions/token.d.ts.map +0 -1
  112. package/dist/viem/Actions/token.js +0 -2936
  113. package/dist/viem/Actions/token.js.map +0 -1
  114. package/dist/viem/Addresses.d.ts +0 -9
  115. package/dist/viem/Addresses.d.ts.map +0 -1
  116. package/dist/viem/Addresses.js +0 -9
  117. package/dist/viem/Addresses.js.map +0 -1
  118. package/dist/viem/Chain.d.ts +0 -451
  119. package/dist/viem/Chain.d.ts.map +0 -1
  120. package/dist/viem/Chain.js +0 -96
  121. package/dist/viem/Chain.js.map +0 -1
  122. package/dist/viem/Formatters.d.ts +0 -10
  123. package/dist/viem/Formatters.d.ts.map +0 -1
  124. package/dist/viem/Formatters.js +0 -104
  125. package/dist/viem/Formatters.js.map +0 -1
  126. package/dist/viem/Storage.d.ts +0 -24
  127. package/dist/viem/Storage.d.ts.map +0 -1
  128. package/dist/viem/Storage.js +0 -68
  129. package/dist/viem/Storage.js.map +0 -1
  130. package/dist/viem/Transaction.d.ts +0 -76
  131. package/dist/viem/Transaction.d.ts.map +0 -1
  132. package/dist/viem/Transaction.js +0 -176
  133. package/dist/viem/Transaction.js.map +0 -1
  134. package/dist/viem/Transport.d.ts +0 -33
  135. package/dist/viem/Transport.d.ts.map +0 -1
  136. package/dist/viem/Transport.js +0 -138
  137. package/dist/viem/Transport.js.map +0 -1
  138. package/dist/viem/WebAuthnP256.d.ts +0 -82
  139. package/dist/viem/WebAuthnP256.d.ts.map +0 -1
  140. package/dist/viem/WebAuthnP256.js +0 -97
  141. package/dist/viem/WebAuthnP256.js.map +0 -1
  142. package/dist/viem/WebCryptoP256.d.ts +0 -2
  143. package/dist/viem/WebCryptoP256.d.ts.map +0 -1
  144. package/dist/viem/WebCryptoP256.js +0 -2
  145. package/dist/viem/WebCryptoP256.js.map +0 -1
  146. package/dist/viem/internal/types.d.ts +0 -20
  147. package/dist/viem/internal/types.d.ts.map +0 -1
  148. package/dist/viem/internal/types.js +0 -2
  149. package/dist/viem/internal/types.js.map +0 -1
  150. package/dist/viem/internal/utils.d.ts +0 -14
  151. package/dist/viem/internal/utils.d.ts.map +0 -1
  152. package/dist/viem/internal/utils.js +0 -33
  153. package/dist/viem/internal/utils.js.map +0 -1
  154. package/src/chains.ts +0 -54
  155. package/src/viem/Abis.ts +0 -1688
  156. package/src/viem/Account.test.ts +0 -444
  157. package/src/viem/Account.ts +0 -601
  158. package/src/viem/Actions/account.test.ts +0 -414
  159. package/src/viem/Actions/account.ts +0 -106
  160. package/src/viem/Actions/amm.test.ts +0 -381
  161. package/src/viem/Actions/amm.ts +0 -1227
  162. package/src/viem/Actions/dex.test.ts +0 -1549
  163. package/src/viem/Actions/dex.ts +0 -2150
  164. package/src/viem/Actions/faucet.ts +0 -121
  165. package/src/viem/Actions/fee.test.ts +0 -259
  166. package/src/viem/Actions/fee.ts +0 -372
  167. package/src/viem/Actions/index.ts +0 -9
  168. package/src/viem/Actions/nonce.test.ts +0 -206
  169. package/src/viem/Actions/nonce.ts +0 -347
  170. package/src/viem/Actions/policy.test.ts +0 -534
  171. package/src/viem/Actions/policy.ts +0 -1335
  172. package/src/viem/Actions/reward.test.ts +0 -434
  173. package/src/viem/Actions/reward.ts +0 -944
  174. package/src/viem/Actions/token.test.ts +0 -3029
  175. package/src/viem/Actions/token.ts +0 -4458
  176. package/src/viem/Addresses.ts +0 -9
  177. package/src/viem/Chain.bench-d.ts +0 -12
  178. package/src/viem/Chain.test.ts +0 -168
  179. package/src/viem/Chain.ts +0 -157
  180. package/src/viem/Decorator.bench-d.ts +0 -11
  181. package/src/viem/Decorator.test.ts +0 -39
  182. package/src/viem/Decorator.ts +0 -3179
  183. package/src/viem/Formatters.ts +0 -164
  184. package/src/viem/P256.ts +0 -1
  185. package/src/viem/Secp256k1.ts +0 -1
  186. package/src/viem/Storage.ts +0 -110
  187. package/src/viem/TokenIds.ts +0 -1
  188. package/src/viem/Transaction.ts +0 -382
  189. package/src/viem/Transport.ts +0 -191
  190. package/src/viem/WebAuthnP256.ts +0 -146
  191. package/src/viem/WebCryptoP256.ts +0 -1
  192. package/src/viem/e2e.test.ts +0 -1602
  193. package/src/viem/index.ts +0 -30
  194. package/src/viem/internal/types.ts +0 -69
  195. package/src/viem/internal/utils.ts +0 -58
  196. package/src/wagmi/internal/types.ts +0 -16
@@ -1,191 +0,0 @@
1
- import * as Address from 'ox/Address'
2
- import * as Hash from 'ox/Hash'
3
- import * as Hex from 'ox/Hex'
4
- import * as Provider from 'ox/Provider'
5
- import * as RpcRequest from 'ox/RpcRequest'
6
- import { createClient, createTransport, type Transport } from 'viem'
7
- import {
8
- getTransactionReceipt,
9
- sendTransaction,
10
- sendTransactionSync,
11
- } from 'viem/actions'
12
- import type * as tempo_Chain from './Chain.js'
13
- import * as Transaction from './Transaction.js'
14
-
15
- export type FeePayer = Transport<typeof withFeePayer.type>
16
-
17
- /**
18
- * Creates a fee payer transport that routes requests between
19
- * the default transport or the fee payer transport.
20
- *
21
- * The policy parameter controls how the fee payer handles transactions:
22
- * - `'sign-only'`: Fee payer co-signs the transaction and returns it to the client transport, which then broadcasts it via the default transport
23
- * - `'sign-and-broadcast'`: Fee payer co-signs and broadcasts the transaction directly
24
- *
25
- * @param defaultTransport - The default transport to use.
26
- * @param feePayerTransport - The fee payer transport to use.
27
- * @param parameters - Configuration parameters.
28
- * @returns A relay transport.
29
- */
30
- export function withFeePayer(
31
- defaultTransport: Transport,
32
- relayTransport: Transport,
33
- parameters?: withFeePayer.Parameters,
34
- ): withFeePayer.ReturnValue {
35
- const { policy = 'sign-only' } = parameters ?? {}
36
-
37
- return (config) => {
38
- const transport_default = defaultTransport(config)
39
- const transport_relay = relayTransport(config)
40
-
41
- return createTransport({
42
- key: withFeePayer.type,
43
- name: 'Relay Proxy',
44
- async request({ method, params }, options) {
45
- if (
46
- method === 'eth_sendRawTransactionSync' ||
47
- method === 'eth_sendRawTransaction'
48
- ) {
49
- const serialized = (params as any)[0] as `0x76${string}`
50
- const transaction = Transaction.deserialize(serialized)
51
-
52
- // If the transaction is intended to be sponsored, forward it to the relay.
53
- if (transaction.feePayerSignature === null) {
54
- // For 'sign-and-broadcast', relay signs and broadcasts
55
- if (policy === 'sign-and-broadcast')
56
- return transport_relay.request(
57
- { method, params },
58
- options,
59
- ) as never
60
-
61
- // For 'sign-only', request signature from relay using eth_signRawTransaction
62
- {
63
- // Request signature from relay using eth_signRawTransaction
64
- const signedTransaction = await transport_relay.request(
65
- {
66
- method: 'eth_signRawTransaction',
67
- params: [serialized],
68
- },
69
- options,
70
- )
71
-
72
- // Broadcast the signed transaction via the default transport
73
- return transport_default.request(
74
- { method, params: [signedTransaction] },
75
- options,
76
- ) as never
77
- }
78
- }
79
- }
80
- return transport_default.request({ method, params }, options) as never
81
- },
82
- type: withFeePayer.type,
83
- })
84
- }
85
- }
86
-
87
- export declare namespace withFeePayer {
88
- export const type = 'feePayer'
89
-
90
- export type Parameters = {
91
- /** Policy for how the fee payer should handle transactions. Defaults to `'sign-only'`. */
92
- policy?: 'sign-only' | 'sign-and-broadcast' | undefined
93
- }
94
-
95
- export type ReturnValue = FeePayer
96
- }
97
-
98
- /**
99
- * Creates a transport that instruments a compatibility layer for
100
- * `wallet_` RPC actions (`sendCalls`, `getCallsStatus`, etc).
101
- *
102
- * @param transport - Transport to wrap.
103
- * @returns Transport.
104
- */
105
- export function walletNamespaceCompat(transport: Transport): Transport {
106
- const sendCallsMagic = Hash.keccak256(Hex.fromString('TEMPO_5792'))
107
-
108
- return (options) => {
109
- const t = transport(options)
110
-
111
- const account = options.account
112
-
113
- type Chain = ReturnType<ReturnType<typeof tempo_Chain.define>>
114
- const chain = options.chain as Chain
115
-
116
- return {
117
- ...t,
118
- async request(args: never) {
119
- const request = RpcRequest.from(args)
120
-
121
- const client = createClient({
122
- account,
123
- chain,
124
- transport,
125
- })
126
-
127
- if (request.method === 'wallet_sendCalls') {
128
- const params = request.params[0] ?? {}
129
- const { capabilities, chainId, from } = params
130
- const { sync } = capabilities ?? {}
131
-
132
- if (!account) throw new Provider.DisconnectedError()
133
- if (!chainId) throw new Provider.UnsupportedChainIdError()
134
- if (Number(chainId) !== client.chain.id)
135
- throw new Provider.UnsupportedChainIdError()
136
- if (from && !Address.isEqual(from, account.address))
137
- throw new Provider.DisconnectedError()
138
-
139
- const calls = (params.calls ?? []).map((call) => ({
140
- to: call.to,
141
- value: call.value ? BigInt(call.value) : undefined,
142
- data: call.data,
143
- }))
144
-
145
- const hash = await (async () => {
146
- if (!sync)
147
- return sendTransaction(client, {
148
- account,
149
- calls,
150
- })
151
-
152
- const { transactionHash } = await sendTransactionSync(client, {
153
- account,
154
- calls,
155
- })
156
- return transactionHash
157
- })()
158
-
159
- const id = Hex.concat(hash, Hex.padLeft(chainId, 32), sendCallsMagic)
160
-
161
- return {
162
- capabilities: { sync },
163
- id,
164
- }
165
- }
166
-
167
- if (request.method === 'wallet_getCallsStatus') {
168
- const [id] = request.params ?? []
169
- if (!id) throw new Error('`id` not found')
170
- if (!id.endsWith(sendCallsMagic.slice(2)))
171
- throw new Error('`id` not supported')
172
- Hex.assert(id)
173
-
174
- const hash = Hex.slice(id, 0, 32)
175
- const chainId = Hex.slice(id, 32, 64)
176
-
177
- const receipt = await getTransactionReceipt(client, { hash })
178
- return {
179
- atomic: true,
180
- chainId: Number(chainId),
181
- receipts: [receipt],
182
- status: receipt.status === 'success' ? 200 : 500,
183
- version: '2.0.0',
184
- }
185
- }
186
-
187
- return t.request(args)
188
- },
189
- } as never
190
- }
191
- }
@@ -1,146 +0,0 @@
1
- import * as Bytes from 'ox/Bytes'
2
- import type * as Hex from 'ox/Hex'
3
- import * as PublicKey from 'ox/PublicKey'
4
- import * as WebAuthnP256 from 'ox/WebAuthnP256'
5
-
6
- export type P256Credential = {
7
- id: WebAuthnP256.P256Credential['id']
8
- publicKey: Hex.Hex
9
- raw: WebAuthnP256.P256Credential['raw']
10
- }
11
-
12
- /**
13
- * Creates a WebAuthn credential (ie. a passkey).
14
- *
15
- * This function returns the credential object, which includes the public key.
16
- * It is recommended to store the public key against the credential in an external store
17
- * as it is not possible to extract a public key from a credential after it has been created.
18
- *
19
- * @example
20
- * ```ts
21
- * import { WebAuthnP256 } from 'tempo.ts/viem'
22
- *
23
- * const credential = await WebAuthnP256.createCredential({ name: 'Example' })
24
- * // {
25
- * // id: 'oZ48...',
26
- * // publicKey: '0x...',
27
- * // }
28
- * ```
29
- *
30
- * @param parameters WebAuthnP256 createCredential options.
31
- * @returns WebAuthn credential.
32
- */
33
- export async function createCredential(
34
- parameters: createCredential.Parameters,
35
- ): Promise<createCredential.ReturnValue> {
36
- const { createFn, label, rpId, userId } = parameters
37
- const credential = await WebAuthnP256.createCredential({
38
- ...parameters,
39
- authenticatorSelection: {
40
- ...parameters.authenticatorSelection,
41
- requireResidentKey: true,
42
- residentKey: 'required',
43
- userVerification: 'required',
44
- },
45
- createFn,
46
- extensions: {
47
- ...parameters.extensions,
48
- credProps: true,
49
- },
50
- rp: rpId
51
- ? {
52
- id: rpId,
53
- name: rpId,
54
- }
55
- : undefined,
56
- name: undefined as never,
57
- user: {
58
- displayName: label,
59
- id: new Uint8Array(userId ?? Bytes.fromString(label)),
60
- name: label,
61
- },
62
- })
63
- return {
64
- id: credential.id,
65
- publicKey: PublicKey.toHex(credential.publicKey, {
66
- includePrefix: false,
67
- }),
68
- raw: credential.raw,
69
- }
70
- }
71
-
72
- export declare namespace createCredential {
73
- export type Parameters = Omit<
74
- WebAuthnP256.createCredential.Options,
75
- 'rp' | 'user'
76
- > & {
77
- /**
78
- * Credential creation function. Useful for environments that do not support
79
- * the WebAuthn API natively (i.e. React Native or testing environments).
80
- *
81
- * @default window.navigator.credentials.create
82
- */
83
- createFn?: WebAuthnP256.createCredential.Options['createFn'] | undefined
84
- /** Label. */
85
- label: string
86
- /** Relying Party ID. */
87
- rpId?: string | undefined
88
- /** User ID. */
89
- userId?: Bytes.Bytes | undefined
90
- }
91
-
92
- export type ReturnValue = P256Credential
93
- }
94
-
95
- /**
96
- * Gets a WebAuthn credential (ie. a passkey), and optionally signs over a digest/hash.
97
- *
98
- * A `getPublicKey` function is required to fetch the public key paired with the credential
99
- * from an external store. It is not possible to extract a public key from a credential after
100
- * the credential has been created with `WebAuthnP256.createCredential`.
101
- *
102
- * @example
103
- * ```ts
104
- * import { WebAuthnP256 } from 'tempo.ts/viem'
105
- *
106
- * const credential = await WebAuthnP256.getCredential({
107
- * async getPublicKey(credential) {
108
- * // Get public key from store
109
- * return store.getPublicKey(credential.id)
110
- * }
111
- * })
112
- * ```
113
- *
114
- * @param parameters WebAuthnP256 getCredential options.
115
- * @returns WebAuthn credential.
116
- */
117
- export async function getCredential(
118
- parameters: getCredential.Parameters,
119
- ): Promise<getCredential.ReturnValue> {
120
- const { metadata, raw, signature } = await WebAuthnP256.sign({
121
- ...parameters,
122
- challenge: parameters.hash ?? '0x',
123
- })
124
- const publicKey = await parameters.getPublicKey(raw)
125
- return {
126
- id: raw.id,
127
- metadata,
128
- publicKey,
129
- raw,
130
- signature,
131
- }
132
- }
133
-
134
- export declare namespace getCredential {
135
- export type Parameters = Omit<WebAuthnP256.sign.Options, 'challenge'> & {
136
- hash?: Hex.Hex | undefined
137
- getPublicKey: (
138
- credential: WebAuthnP256.P256Credential['raw'],
139
- ) => Promise<Hex.Hex>
140
- }
141
-
142
- export type ReturnValue = WebAuthnP256.sign.ReturnType & {
143
- id: string
144
- publicKey: Hex.Hex
145
- }
146
- }
@@ -1 +0,0 @@
1
- export { createKeyPair } from 'ox/WebCryptoP256'