tempo.ts 0.5.1 → 0.5.3
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.
- package/dist/viem/Actions/policy.d.ts +9 -1
- package/dist/viem/Actions/policy.d.ts.map +1 -1
- package/dist/viem/Actions/policy.js.map +1 -1
- package/dist/viem/Chain.d.ts.map +1 -1
- package/dist/viem/Chain.js +8 -2
- package/dist/viem/Chain.js.map +1 -1
- package/dist/viem/Transaction.js +4 -1
- package/dist/viem/Transaction.js.map +1 -1
- package/dist/viem/Transport.d.ts +8 -0
- package/dist/viem/Transport.d.ts.map +1 -1
- package/dist/viem/Transport.js +87 -1
- package/dist/viem/Transport.js.map +1 -1
- package/dist/wagmi/Actions/faucet.d.ts +31 -0
- package/dist/wagmi/Actions/faucet.d.ts.map +1 -1
- package/dist/wagmi/Actions/faucet.js +31 -0
- package/dist/wagmi/Actions/faucet.js.map +1 -1
- package/dist/wagmi/Actions/index.d.ts +1 -0
- package/dist/wagmi/Actions/index.d.ts.map +1 -1
- package/dist/wagmi/Actions/index.js +1 -0
- package/dist/wagmi/Actions/index.js.map +1 -1
- package/dist/wagmi/Actions/policy.d.ts +481 -0
- package/dist/wagmi/Actions/policy.d.ts.map +1 -0
- package/dist/wagmi/Actions/policy.js +530 -0
- package/dist/wagmi/Actions/policy.js.map +1 -0
- package/dist/wagmi/Connector.d.ts +1 -1
- package/dist/wagmi/Connector.d.ts.map +1 -1
- package/dist/wagmi/Connector.js +3 -85
- package/dist/wagmi/Connector.js.map +1 -1
- package/dist/wagmi/Hooks/faucet.d.ts +33 -1
- package/dist/wagmi/Hooks/faucet.d.ts.map +1 -1
- package/dist/wagmi/Hooks/faucet.js +37 -1
- package/dist/wagmi/Hooks/faucet.js.map +1 -1
- package/dist/wagmi/Hooks/index.d.ts +1 -0
- package/dist/wagmi/Hooks/index.d.ts.map +1 -1
- package/dist/wagmi/Hooks/index.js +1 -0
- package/dist/wagmi/Hooks/index.js.map +1 -1
- package/dist/wagmi/Hooks/policy.d.ts +424 -0
- package/dist/wagmi/Hooks/policy.d.ts.map +1 -0
- package/dist/wagmi/Hooks/policy.js +510 -0
- package/dist/wagmi/Hooks/policy.js.map +1 -0
- package/package.json +2 -2
- package/src/viem/Actions/policy.ts +25 -0
- package/src/viem/Chain.ts +9 -2
- package/src/viem/Transaction.ts +9 -4
- package/src/viem/Transport.ts +107 -1
- package/src/viem/e2e.test.ts +33 -24
- package/src/wagmi/Actions/faucet.ts +43 -0
- package/src/wagmi/Actions/index.ts +1 -0
- package/src/wagmi/Actions/policy.test.ts +461 -0
- package/src/wagmi/Actions/policy.ts +819 -0
- package/src/wagmi/Connector.ts +4 -112
- package/src/wagmi/Hooks/faucet.ts +69 -1
- package/src/wagmi/Hooks/index.ts +1 -0
- package/src/wagmi/Hooks/policy.test.ts +665 -0
- package/src/wagmi/Hooks/policy.ts +875 -0
package/src/wagmi/Connector.ts
CHANGED
|
@@ -1,33 +1,22 @@
|
|
|
1
1
|
import * as Address from 'ox/Address'
|
|
2
2
|
import * as Bytes from 'ox/Bytes'
|
|
3
|
-
import * as
|
|
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:
|
|
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:
|
|
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
|
-
}
|
|
@@ -5,7 +5,7 @@ import { useConfig } from 'wagmi'
|
|
|
5
5
|
import type { ConfigParameter } from 'wagmi/internal'
|
|
6
6
|
import { type UseMutationParameters, useMutation } from 'wagmi/query'
|
|
7
7
|
|
|
8
|
-
import { fund } from '../Actions/faucet.js'
|
|
8
|
+
import { fund, fundSync } from '../Actions/faucet.js'
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Hook for funding an account with an initial amount of set token(s)
|
|
@@ -74,3 +74,71 @@ export declare namespace useFund {
|
|
|
74
74
|
context
|
|
75
75
|
>
|
|
76
76
|
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Hook for funding an account with an initial amount of set token(s)
|
|
80
|
+
* on Tempo's testnet. Returns the transaction receipts.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```tsx
|
|
84
|
+
* import { Hooks } from 'tempo.ts/wagmi'
|
|
85
|
+
*
|
|
86
|
+
* function App() {
|
|
87
|
+
* const { mutate, isPending } = Hooks.faucet.useFundSync()
|
|
88
|
+
*
|
|
89
|
+
* return (
|
|
90
|
+
* <button
|
|
91
|
+
* onClick={() => mutate({ account: '0xdeadbeef...' })}
|
|
92
|
+
* disabled={isPending}
|
|
93
|
+
* >
|
|
94
|
+
* Fund Account
|
|
95
|
+
* </button>
|
|
96
|
+
* )
|
|
97
|
+
* }
|
|
98
|
+
* ```
|
|
99
|
+
*
|
|
100
|
+
* @param parameters - Parameters.
|
|
101
|
+
* @returns Mutation result.
|
|
102
|
+
*/
|
|
103
|
+
export function useFundSync<
|
|
104
|
+
config extends Config = ResolvedRegister['config'],
|
|
105
|
+
context = unknown,
|
|
106
|
+
>(
|
|
107
|
+
parameters: useFundSync.Parameters<config, context> = {},
|
|
108
|
+
): useFundSync.ReturnType<config, context> {
|
|
109
|
+
const { mutation } = parameters
|
|
110
|
+
const config = useConfig(parameters)
|
|
111
|
+
return useMutation({
|
|
112
|
+
...mutation,
|
|
113
|
+
async mutationFn(variables) {
|
|
114
|
+
return fundSync(config, variables)
|
|
115
|
+
},
|
|
116
|
+
mutationKey: ['fundSync'],
|
|
117
|
+
})
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export declare namespace useFundSync {
|
|
121
|
+
type Parameters<
|
|
122
|
+
config extends Config = Config,
|
|
123
|
+
context = unknown,
|
|
124
|
+
> = ConfigParameter<config> & {
|
|
125
|
+
mutation?:
|
|
126
|
+
| UseMutationParameters<
|
|
127
|
+
fundSync.ReturnValue,
|
|
128
|
+
BaseErrorType,
|
|
129
|
+
fundSync.Parameters<config>,
|
|
130
|
+
context
|
|
131
|
+
>
|
|
132
|
+
| undefined
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
type ReturnType<
|
|
136
|
+
config extends Config = Config,
|
|
137
|
+
context = unknown,
|
|
138
|
+
> = UseMutationResult<
|
|
139
|
+
fundSync.ReturnValue,
|
|
140
|
+
BaseErrorType,
|
|
141
|
+
fundSync.Parameters<config>,
|
|
142
|
+
context
|
|
143
|
+
>
|
|
144
|
+
}
|
package/src/wagmi/Hooks/index.ts
CHANGED