tempo.ts 0.4.2 → 0.4.4
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/README.md +9 -1
- package/dist/viem/Abis.d.ts +0 -4
- package/dist/viem/Abis.d.ts.map +1 -1
- package/dist/viem/Abis.js +0 -1
- package/dist/viem/Abis.js.map +1 -1
- package/dist/viem/Actions/fee.d.ts +0 -4
- package/dist/viem/Actions/fee.d.ts.map +1 -1
- package/dist/viem/Actions/token.d.ts +12 -12
- package/dist/viem/Actions/token.js +12 -12
- package/dist/viem/Chain.d.ts.map +1 -1
- package/dist/viem/Chain.js +5 -1
- package/dist/viem/Chain.js.map +1 -1
- package/dist/viem/Decorator.d.ts +9 -9
- package/dist/viem/Formatters.d.ts.map +1 -1
- package/dist/viem/Formatters.js +19 -3
- package/dist/viem/Formatters.js.map +1 -1
- package/dist/viem/internal/account.d.ts +1 -4
- package/dist/viem/internal/account.d.ts.map +1 -1
- package/dist/viem/internal/account.js +4 -3
- package/dist/viem/internal/account.js.map +1 -1
- package/dist/wagmi/Actions/token.d.ts +1 -1
- package/dist/wagmi/Actions/token.js +1 -1
- package/dist/wagmi/Connector.d.ts +4 -3
- package/dist/wagmi/Connector.d.ts.map +1 -1
- package/dist/wagmi/Connector.js +91 -5
- package/dist/wagmi/Connector.js.map +1 -1
- package/dist/wagmi/Hooks/token.d.ts +1 -1
- package/dist/wagmi/Hooks/token.js +1 -1
- package/package.json +1 -1
- package/src/viem/Abis.ts +0 -1
- package/src/viem/Actions/token.ts +12 -12
- package/src/viem/Chain.ts +6 -1
- package/src/viem/Decorator.ts +9 -9
- package/src/viem/Formatters.ts +22 -3
- package/src/viem/e2e.test.ts +19 -19
- package/src/viem/internal/account.ts +5 -11
- package/src/wagmi/Actions/token.ts +1 -1
- package/src/wagmi/Connector.ts +125 -10
- package/src/wagmi/Hooks/token.ts +1 -1
package/src/viem/e2e.test.ts
CHANGED
|
@@ -278,11 +278,11 @@ describe('sendTransaction', () => {
|
|
|
278
278
|
"chainId": 1337,
|
|
279
279
|
"data": undefined,
|
|
280
280
|
"feePayerSignature": undefined,
|
|
281
|
-
"feeToken":
|
|
281
|
+
"feeToken": "0x20c0000000000000000000000000000000000001",
|
|
282
282
|
"from": "0xfc39755d501fa7b79164f74efb906e87ecde342c",
|
|
283
283
|
"gas": 29012n,
|
|
284
284
|
"gasPrice": 10000000000n,
|
|
285
|
-
"hash": "
|
|
285
|
+
"hash": "0x92497c48650181f386b4daeb3f784620b29af6dea6c8caeb995156f3f75af161",
|
|
286
286
|
"maxFeePerBlobGas": undefined,
|
|
287
287
|
"maxFeePerGas": 12000000000n,
|
|
288
288
|
"maxPriorityFeePerGas": 0n,
|
|
@@ -296,8 +296,8 @@ describe('sendTransaction', () => {
|
|
|
296
296
|
"y": 28479403900638612718017087999484027026245572142646745985103165612268853186552n,
|
|
297
297
|
},
|
|
298
298
|
"signature": {
|
|
299
|
-
"r":
|
|
300
|
-
"s":
|
|
299
|
+
"r": 73166565759729379192178736994258501393133045207516873483983141310238393892339n,
|
|
300
|
+
"s": 9678569667446118283593635726095491566145915132050642248430996816820250471583n,
|
|
301
301
|
},
|
|
302
302
|
"type": "p256",
|
|
303
303
|
},
|
|
@@ -365,11 +365,11 @@ describe('sendTransaction', () => {
|
|
|
365
365
|
"chainId": 1337,
|
|
366
366
|
"data": undefined,
|
|
367
367
|
"feePayerSignature": undefined,
|
|
368
|
-
"feeToken":
|
|
368
|
+
"feeToken": "0x20c0000000000000000000000000000000000001",
|
|
369
369
|
"from": "0xfc39755d501fa7b79164f74efb906e87ecde342c",
|
|
370
370
|
"gas": 100000n,
|
|
371
371
|
"gasPrice": 10000000000n,
|
|
372
|
-
"hash": "
|
|
372
|
+
"hash": "0x42d24b367d36fe86a48a5d3e569a4a7f528eba99c44e17304c6e88ba29e50666",
|
|
373
373
|
"maxFeePerBlobGas": undefined,
|
|
374
374
|
"maxFeePerGas": 12000000000n,
|
|
375
375
|
"maxPriorityFeePerGas": 0n,
|
|
@@ -383,8 +383,8 @@ describe('sendTransaction', () => {
|
|
|
383
383
|
"y": 28479403900638612718017087999484027026245572142646745985103165612268853186552n,
|
|
384
384
|
},
|
|
385
385
|
"signature": {
|
|
386
|
-
"r":
|
|
387
|
-
"s":
|
|
386
|
+
"r": 106143051119266858928184523090857221408816991676370960197147810502258413383473n,
|
|
387
|
+
"s": 49844357009853267306291709813432165511067109946085107128095783518674413076631n,
|
|
388
388
|
},
|
|
389
389
|
"type": "p256",
|
|
390
390
|
},
|
|
@@ -525,7 +525,7 @@ describe('sendTransaction', () => {
|
|
|
525
525
|
"chainId": 1337,
|
|
526
526
|
"data": undefined,
|
|
527
527
|
"feePayerSignature": undefined,
|
|
528
|
-
"feeToken":
|
|
528
|
+
"feeToken": "0x20c0000000000000000000000000000000000001",
|
|
529
529
|
"from": undefined,
|
|
530
530
|
"gas": 29012n,
|
|
531
531
|
"gasPrice": 10000000000n,
|
|
@@ -646,11 +646,11 @@ describe('sendTransaction', () => {
|
|
|
646
646
|
"chainId": 1337,
|
|
647
647
|
"data": undefined,
|
|
648
648
|
"feePayerSignature": undefined,
|
|
649
|
-
"feeToken":
|
|
649
|
+
"feeToken": "0x20c0000000000000000000000000000000000001",
|
|
650
650
|
"from": "0xfc39755d501fa7b79164f74efb906e87ecde342c",
|
|
651
651
|
"gas": 41404n,
|
|
652
652
|
"gasPrice": 10000000000n,
|
|
653
|
-
"hash": "
|
|
653
|
+
"hash": "0x0f9754978f1533d5e8a94c8f6e564150b8ca560a145d7adbafa95537cdd661e0",
|
|
654
654
|
"maxFeePerBlobGas": undefined,
|
|
655
655
|
"maxFeePerGas": 12000000000n,
|
|
656
656
|
"maxPriorityFeePerGas": 0n,
|
|
@@ -659,7 +659,7 @@ describe('sendTransaction', () => {
|
|
|
659
659
|
"signature": {
|
|
660
660
|
"metadata": {
|
|
661
661
|
"authenticatorData": "0x49960de5880e8c687434170f6476605b8fe4aeb9a28632c7995cf3ba831d97630500000000",
|
|
662
|
-
"clientDataJSON": "{"type":"webauthn.get","challenge":"
|
|
662
|
+
"clientDataJSON": "{"type":"webauthn.get","challenge":"pGxfglkRHnxAvl1iNopy9f3dCpA0yOtMWD52o4QjFIM","origin":"http://localhost","crossOrigin":false}",
|
|
663
663
|
},
|
|
664
664
|
"publicKey": {
|
|
665
665
|
"prefix": 4,
|
|
@@ -667,8 +667,8 @@ describe('sendTransaction', () => {
|
|
|
667
667
|
"y": 28479403900638612718017087999484027026245572142646745985103165612268853186552n,
|
|
668
668
|
},
|
|
669
669
|
"signature": {
|
|
670
|
-
"r":
|
|
671
|
-
"s":
|
|
670
|
+
"r": 46181083089071531854644596388726939003590007726502882093676118825353436035851n,
|
|
671
|
+
"s": 40251117141811933316754610200955094367484007878478703779665518197624832232922n,
|
|
672
672
|
},
|
|
673
673
|
"type": "webAuthn",
|
|
674
674
|
},
|
|
@@ -740,11 +740,11 @@ describe('sendTransaction', () => {
|
|
|
740
740
|
"chainId": 1337,
|
|
741
741
|
"data": undefined,
|
|
742
742
|
"feePayerSignature": undefined,
|
|
743
|
-
"feeToken":
|
|
743
|
+
"feeToken": "0x20c0000000000000000000000000000000000001",
|
|
744
744
|
"from": "0xfc39755d501fa7b79164f74efb906e87ecde342c",
|
|
745
745
|
"gas": 100000n,
|
|
746
746
|
"gasPrice": 10000000000n,
|
|
747
|
-
"hash": "
|
|
747
|
+
"hash": "0x9e431e3d0b4a04c5779d0918b1d3140429530c19cada91e5da2eb66edcd77efa",
|
|
748
748
|
"maxFeePerBlobGas": undefined,
|
|
749
749
|
"maxFeePerGas": 12000000000n,
|
|
750
750
|
"maxPriorityFeePerGas": 0n,
|
|
@@ -753,7 +753,7 @@ describe('sendTransaction', () => {
|
|
|
753
753
|
"signature": {
|
|
754
754
|
"metadata": {
|
|
755
755
|
"authenticatorData": "0x49960de5880e8c687434170f6476605b8fe4aeb9a28632c7995cf3ba831d97630500000000",
|
|
756
|
-
"clientDataJSON": "{"type":"webauthn.get","challenge":"
|
|
756
|
+
"clientDataJSON": "{"type":"webauthn.get","challenge":"DAabvi2LJ45ESyCwmmyBACb6VS9MdItb_FksnNfg2ZI","origin":"http://localhost","crossOrigin":false}",
|
|
757
757
|
},
|
|
758
758
|
"publicKey": {
|
|
759
759
|
"prefix": 4,
|
|
@@ -761,8 +761,8 @@ describe('sendTransaction', () => {
|
|
|
761
761
|
"y": 28479403900638612718017087999484027026245572142646745985103165612268853186552n,
|
|
762
762
|
},
|
|
763
763
|
"signature": {
|
|
764
|
-
"r":
|
|
765
|
-
"s":
|
|
764
|
+
"r": 89695469468583132282454887497226949335068684032456007061013932756262487728086n,
|
|
765
|
+
"s": 30364371922186410926529917972734911437767801874356315397917029751067680712123n,
|
|
766
766
|
},
|
|
767
767
|
"type": "webAuthn",
|
|
768
768
|
},
|
|
@@ -11,14 +11,7 @@ import type { RequiredBy } from '../../internal/types.js'
|
|
|
11
11
|
import * as SignatureEnvelope from '../../ox/SignatureEnvelope.js'
|
|
12
12
|
import * as Transaction from '../Transaction.js'
|
|
13
13
|
|
|
14
|
-
export type Account = RequiredBy<
|
|
15
|
-
Omit<LocalAccount, 'signTransaction'>,
|
|
16
|
-
'sign' | 'signAuthorization'
|
|
17
|
-
> & {
|
|
18
|
-
signTransaction: (
|
|
19
|
-
transaction: Transaction.TransactionSerializable,
|
|
20
|
-
) => Promise<Hex.Hex>
|
|
21
|
-
}
|
|
14
|
+
export type Account = RequiredBy<LocalAccount, 'sign' | 'signAuthorization'>
|
|
22
15
|
|
|
23
16
|
// TODO: this function will be redundant when Viem migrates to Ox.
|
|
24
17
|
/** @internal */
|
|
@@ -67,12 +60,13 @@ export function toPrivateKeyAccount(
|
|
|
67
60
|
)
|
|
68
61
|
return SignatureEnvelope.serialize(envelope)
|
|
69
62
|
},
|
|
70
|
-
async signTransaction(transaction) {
|
|
63
|
+
async signTransaction(transaction, options) {
|
|
64
|
+
const { serializer = Transaction.serialize } = options ?? {}
|
|
71
65
|
const signature = await sign({
|
|
72
|
-
hash: keccak256(await
|
|
66
|
+
hash: keccak256(await serializer(transaction)),
|
|
73
67
|
})
|
|
74
68
|
const envelope = SignatureEnvelope.from(signature)
|
|
75
|
-
return await
|
|
69
|
+
return await serializer(transaction, envelope as never)
|
|
76
70
|
},
|
|
77
71
|
async signTypedData(typedData) {
|
|
78
72
|
const signature = await sign({ hash: hashTypedData(typedData) })
|
package/src/wagmi/Connector.ts
CHANGED
|
@@ -1,16 +1,32 @@
|
|
|
1
1
|
import * as Address from 'ox/Address'
|
|
2
2
|
import * as Bytes from 'ox/Bytes'
|
|
3
|
-
import
|
|
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'
|
|
4
7
|
import {
|
|
5
8
|
createClient,
|
|
6
9
|
type EIP1193Provider,
|
|
7
10
|
getAddress,
|
|
8
|
-
type Hex,
|
|
9
11
|
type LocalAccount,
|
|
10
12
|
SwitchChainError,
|
|
13
|
+
type Transport,
|
|
14
|
+
type Account as viem_Account,
|
|
11
15
|
} from 'viem'
|
|
12
16
|
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts'
|
|
17
|
+
import {
|
|
18
|
+
getTransactionReceipt,
|
|
19
|
+
sendTransaction,
|
|
20
|
+
sendTransactionSync,
|
|
21
|
+
} from 'viem/actions'
|
|
13
22
|
import { ChainNotConfiguredError, createConnector } from 'wagmi'
|
|
23
|
+
import * as Account from '../viem/Account.js'
|
|
24
|
+
import type * as tempo_Chain from '../viem/Chain.js'
|
|
25
|
+
import * as WebAuthnP256 from '../viem/WebAuthnP256.js'
|
|
26
|
+
|
|
27
|
+
type Chain = ReturnType<ReturnType<typeof tempo_Chain.define>>
|
|
28
|
+
|
|
29
|
+
const sendCallsMagic = Hash.keccak256(Hex.fromString('TEMPO_5792'))
|
|
14
30
|
|
|
15
31
|
/**
|
|
16
32
|
* Connector for a Secp256k1 EOA.
|
|
@@ -45,7 +61,7 @@ export function dangerous_secp256k1(
|
|
|
45
61
|
type StorageItem = {
|
|
46
62
|
'secp256k1.activeAddress': Address.Address
|
|
47
63
|
'secp256k1.lastActiveAddress': Address.Address
|
|
48
|
-
[key: `secp256k1.${string}.privateKey`]: Hex
|
|
64
|
+
[key: `secp256k1.${string}.privateKey`]: Hex.Hex
|
|
49
65
|
}
|
|
50
66
|
|
|
51
67
|
return createConnector<Provider, Properties, StorageItem>((config) => ({
|
|
@@ -168,8 +184,10 @@ export function dangerous_secp256k1(
|
|
|
168
184
|
|
|
169
185
|
return createClient({
|
|
170
186
|
account,
|
|
171
|
-
chain,
|
|
172
|
-
transport,
|
|
187
|
+
chain: chain as Chain,
|
|
188
|
+
transport: withErc5792Compat(transport, {
|
|
189
|
+
account,
|
|
190
|
+
}),
|
|
173
191
|
})
|
|
174
192
|
},
|
|
175
193
|
async getProvider({ chainId } = {}) {
|
|
@@ -214,7 +232,7 @@ export function webAuthn(options: webAuthn.Parameters = {}) {
|
|
|
214
232
|
type StorageItem = {
|
|
215
233
|
'webAuthn.activeCredential': WebAuthnP256.P256Credential
|
|
216
234
|
'webAuthn.lastActiveCredential': WebAuthnP256.P256Credential
|
|
217
|
-
[key: `webAuthn.${string}.publicKey`]: Hex
|
|
235
|
+
[key: `webAuthn.${string}.publicKey`]: Hex.Hex
|
|
218
236
|
}
|
|
219
237
|
|
|
220
238
|
return createConnector<Provider, Properties, StorageItem>((config) => ({
|
|
@@ -270,6 +288,8 @@ export function webAuthn(options: webAuthn.Parameters = {}) {
|
|
|
270
288
|
credential ??= await WebAuthnP256.getCredential({
|
|
271
289
|
...(options.getOptions ?? {}),
|
|
272
290
|
credentialId: lastActiveCredential?.id,
|
|
291
|
+
// biome-ignore lint/suspicious/noTsIgnore: _
|
|
292
|
+
// @ts-ignore
|
|
273
293
|
async getPublicKey(credential) {
|
|
274
294
|
{
|
|
275
295
|
const publicKey =
|
|
@@ -282,7 +302,7 @@ export function webAuthn(options: webAuthn.Parameters = {}) {
|
|
|
282
302
|
`webAuthn.${credential.id}.publicKey`,
|
|
283
303
|
)
|
|
284
304
|
if (!publicKey) throw new Error('publicKey not found')
|
|
285
|
-
return publicKey as Hex
|
|
305
|
+
return publicKey as Hex.Hex
|
|
286
306
|
}
|
|
287
307
|
},
|
|
288
308
|
rpId: options.getOptions?.rpId ?? options.rpId,
|
|
@@ -356,8 +376,10 @@ export function webAuthn(options: webAuthn.Parameters = {}) {
|
|
|
356
376
|
|
|
357
377
|
return createClient({
|
|
358
378
|
account,
|
|
359
|
-
chain,
|
|
360
|
-
transport,
|
|
379
|
+
chain: chain as Chain,
|
|
380
|
+
transport: withErc5792Compat(transport, {
|
|
381
|
+
account,
|
|
382
|
+
}),
|
|
361
383
|
})
|
|
362
384
|
},
|
|
363
385
|
async getProvider({ chainId } = {}) {
|
|
@@ -376,7 +398,7 @@ export declare namespace webAuthn {
|
|
|
376
398
|
'createFn' | 'label' | 'rpId' | 'userId' | 'timeout'
|
|
377
399
|
> & {
|
|
378
400
|
/** Function to fetch a challenge to sign over at registration. */
|
|
379
|
-
getChallenge?: (() => Promise<Hex>) | undefined
|
|
401
|
+
getChallenge?: (() => Promise<Hex.Hex>) | undefined
|
|
380
402
|
})
|
|
381
403
|
| undefined
|
|
382
404
|
/** Options for WebAuthn authentication. */
|
|
@@ -392,3 +414,96 @@ export declare namespace webAuthn {
|
|
|
392
414
|
rpId?: string | undefined
|
|
393
415
|
}
|
|
394
416
|
}
|
|
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
|
+
}
|
package/src/wagmi/Hooks/token.ts
CHANGED