tempo.ts 0.7.6 → 0.8.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.
- package/CHANGELOG.md +26 -0
- package/dist/chains.d.ts +6 -20
- package/dist/chains.d.ts.map +1 -1
- package/dist/chains.js +14 -15
- package/dist/chains.js.map +1 -1
- package/dist/ox/KeyAuthorization.d.ts +356 -0
- package/dist/ox/KeyAuthorization.d.ts.map +1 -0
- package/dist/ox/KeyAuthorization.js +360 -0
- package/dist/ox/KeyAuthorization.js.map +1 -0
- package/dist/ox/SignatureEnvelope.d.ts +21 -6
- package/dist/ox/SignatureEnvelope.d.ts.map +1 -1
- package/dist/ox/SignatureEnvelope.js +43 -3
- package/dist/ox/SignatureEnvelope.js.map +1 -1
- package/dist/ox/Transaction.d.ts +5 -1
- package/dist/ox/Transaction.d.ts.map +1 -1
- package/dist/ox/Transaction.js +5 -0
- package/dist/ox/Transaction.js.map +1 -1
- package/dist/ox/TransactionEnvelopeAA.d.ts +9 -0
- package/dist/ox/TransactionEnvelopeAA.d.ts.map +1 -1
- package/dist/ox/TransactionEnvelopeAA.js +17 -4
- package/dist/ox/TransactionEnvelopeAA.js.map +1 -1
- package/dist/ox/TransactionRequest.d.ts +7 -1
- package/dist/ox/TransactionRequest.d.ts.map +1 -1
- package/dist/ox/TransactionRequest.js +12 -0
- package/dist/ox/TransactionRequest.js.map +1 -1
- package/dist/ox/index.d.ts +1 -0
- package/dist/ox/index.d.ts.map +1 -1
- package/dist/ox/index.js +1 -0
- package/dist/ox/index.js.map +1 -1
- package/dist/prool/Instance.js +1 -1
- package/dist/prool/Instance.js.map +1 -1
- package/{src/prool/internal → dist/prool}/chain.json +4 -2
- package/dist/viem/Abis.d.ts +319 -6
- package/dist/viem/Abis.d.ts.map +1 -1
- package/dist/viem/Abis.js +199 -7
- package/dist/viem/Abis.js.map +1 -1
- package/dist/viem/Account.d.ts +103 -14
- package/dist/viem/Account.d.ts.map +1 -1
- package/dist/viem/Account.js +177 -23
- package/dist/viem/Account.js.map +1 -1
- package/dist/viem/Actions/account.d.ts.map +1 -1
- package/dist/viem/Actions/account.js +4 -5
- package/dist/viem/Actions/account.js.map +1 -1
- package/dist/viem/Actions/amm.d.ts +72 -0
- package/dist/viem/Actions/amm.d.ts.map +1 -1
- package/dist/viem/Actions/dex.d.ts +156 -4
- package/dist/viem/Actions/dex.d.ts.map +1 -1
- package/dist/viem/Actions/fee.d.ts +4 -0
- package/dist/viem/Actions/fee.d.ts.map +1 -1
- package/dist/viem/Actions/reward.d.ts +78 -0
- package/dist/viem/Actions/reward.d.ts.map +1 -1
- package/dist/viem/Actions/token.d.ts +585 -0
- package/dist/viem/Actions/token.d.ts.map +1 -1
- package/dist/viem/Actions/token.js +2 -2
- package/dist/viem/Actions/token.js.map +1 -1
- package/dist/viem/Addresses.d.ts +1 -1
- package/dist/viem/Addresses.d.ts.map +1 -1
- package/dist/viem/Addresses.js +1 -1
- package/dist/viem/Addresses.js.map +1 -1
- package/dist/viem/Chain.d.ts +35 -0
- package/dist/viem/Chain.d.ts.map +1 -1
- package/dist/viem/Chain.js +37 -0
- package/dist/viem/Chain.js.map +1 -1
- package/dist/viem/Formatters.d.ts.map +1 -1
- package/dist/viem/Formatters.js +8 -7
- package/dist/viem/Formatters.js.map +1 -1
- package/dist/viem/Storage.d.ts +1 -0
- package/dist/viem/Storage.d.ts.map +1 -1
- package/dist/viem/Storage.js +21 -0
- package/dist/viem/Storage.js.map +1 -1
- package/dist/viem/TokenIds.d.ts +1 -1
- package/dist/viem/TokenIds.d.ts.map +1 -1
- package/dist/viem/TokenIds.js +1 -1
- package/dist/viem/TokenIds.js.map +1 -1
- package/dist/viem/Transaction.d.ts +9 -1
- package/dist/viem/Transaction.d.ts.map +1 -1
- package/dist/viem/Transaction.js +2 -1
- package/dist/viem/Transaction.js.map +1 -1
- package/dist/viem/WebAuthnP256.d.ts +4 -1
- package/dist/viem/WebAuthnP256.d.ts.map +1 -1
- package/dist/viem/WebAuthnP256.js +3 -1
- package/dist/viem/WebAuthnP256.js.map +1 -1
- package/dist/wagmi/Connector.d.ts +25 -8
- package/dist/wagmi/Connector.d.ts.map +1 -1
- package/dist/wagmi/Connector.js +120 -27
- package/dist/wagmi/Connector.js.map +1 -1
- package/package.json +3 -2
- package/src/chains.ts +14 -15
- package/src/ox/KeyAuthorization.test.ts +1332 -0
- package/src/ox/KeyAuthorization.ts +542 -0
- package/src/ox/SignatureEnvelope.test.ts +624 -0
- package/src/ox/SignatureEnvelope.ts +89 -9
- package/src/ox/Transaction.test.ts +214 -0
- package/src/ox/Transaction.ts +13 -1
- package/src/ox/TransactionEnvelopeAA.test.ts +164 -4
- package/src/ox/TransactionEnvelopeAA.ts +36 -3
- package/src/ox/TransactionRequest.ts +22 -1
- package/src/ox/e2e.test.ts +612 -5
- package/src/ox/index.ts +1 -0
- package/src/prool/Instance.ts +1 -1
- package/src/prool/chain.json +238 -0
- package/src/server/Handler.test.ts +20 -36
- package/src/viem/Abis.ts +200 -7
- package/src/viem/Account.test.ts +444 -0
- package/src/viem/Account.ts +355 -42
- package/src/viem/Actions/account.ts +3 -5
- package/src/viem/Actions/amm.test.ts +4 -4
- package/src/viem/Actions/token.test.ts +8 -8
- package/src/viem/Actions/token.ts +2 -2
- package/src/viem/Addresses.ts +1 -1
- package/src/viem/Chain.test.ts +168 -0
- package/src/viem/Chain.ts +37 -1
- package/src/viem/Formatters.ts +8 -7
- package/src/viem/Storage.ts +22 -0
- package/src/viem/TokenIds.ts +1 -1
- package/src/viem/Transaction.ts +14 -2
- package/src/viem/WebAuthnP256.ts +8 -2
- package/src/viem/e2e.test.ts +299 -96
- package/src/wagmi/Actions/amm.test.ts +2 -2
- package/src/wagmi/Connector.test.ts +1 -1
- package/src/wagmi/Connector.ts +184 -54
- package/src/wagmi/Hooks/amm.test.ts +4 -4
- package/src/wagmi/Hooks/fee.test.ts +10 -4
- package/src/wagmi/Hooks/token.test.ts +0 -488
- package/dist/viem/internal/account.d.ts +0 -21
- package/dist/viem/internal/account.d.ts.map +0 -1
- package/dist/viem/internal/account.js +0 -61
- package/dist/viem/internal/account.js.map +0 -1
- package/src/viem/internal/account.ts +0 -89
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getTransaction,
|
|
3
|
+
prepareTransactionRequest,
|
|
4
|
+
sendTransactionSync,
|
|
5
|
+
} from 'viem/actions'
|
|
6
|
+
import { describe, expect, test, vi } from 'vitest'
|
|
7
|
+
import { chain, client, clientWithAccount } from '../../test/viem/config.js'
|
|
8
|
+
|
|
9
|
+
describe('chain.prepareTransactionRequest', () => {
|
|
10
|
+
test('behavior: sequential nonce keys for feePayer transactions', async () => {
|
|
11
|
+
const requests = await Promise.all([
|
|
12
|
+
chain.prepareTransactionRequest({ feePayer: true } as never),
|
|
13
|
+
chain.prepareTransactionRequest({ feePayer: true } as never),
|
|
14
|
+
chain.prepareTransactionRequest({ feePayer: true } as never),
|
|
15
|
+
])
|
|
16
|
+
|
|
17
|
+
expect((requests[0] as any)?.nonceKey).toBe(0n)
|
|
18
|
+
expect((requests[1] as any)?.nonceKey).toBeGreaterThan(0n)
|
|
19
|
+
expect((requests[2] as any)?.nonceKey).toBeGreaterThan(0n)
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
test('behavior: nonce key counter resets after event loop tick', async () => {
|
|
23
|
+
const requests1 = await Promise.all([
|
|
24
|
+
chain.prepareTransactionRequest({ feePayer: true } as never),
|
|
25
|
+
chain.prepareTransactionRequest({ feePayer: true } as never),
|
|
26
|
+
])
|
|
27
|
+
|
|
28
|
+
expect((requests1[0] as any)?.nonceKey).toBe(0n)
|
|
29
|
+
expect((requests1[1] as any)?.nonceKey).toBeGreaterThan(0n)
|
|
30
|
+
|
|
31
|
+
// Wait for microtask queue to flush
|
|
32
|
+
await new Promise((resolve) => queueMicrotask(() => resolve(undefined)))
|
|
33
|
+
|
|
34
|
+
const requests2 = await Promise.all([
|
|
35
|
+
chain.prepareTransactionRequest({ feePayer: true } as never),
|
|
36
|
+
chain.prepareTransactionRequest({ feePayer: true } as never),
|
|
37
|
+
])
|
|
38
|
+
|
|
39
|
+
// Counter should have reset
|
|
40
|
+
expect((requests2[0] as any)?.nonceKey).toBe(0n)
|
|
41
|
+
expect((requests2[1] as any)?.nonceKey).toBeGreaterThan(0n)
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
test('behavior: explicit nonceKey overrides counter', async () => {
|
|
45
|
+
const requests = await Promise.all([
|
|
46
|
+
chain.prepareTransactionRequest({
|
|
47
|
+
feePayer: true,
|
|
48
|
+
nonceKey: 42n,
|
|
49
|
+
} as never),
|
|
50
|
+
chain.prepareTransactionRequest({ feePayer: true } as never),
|
|
51
|
+
chain.prepareTransactionRequest({
|
|
52
|
+
feePayer: true,
|
|
53
|
+
nonceKey: 100n,
|
|
54
|
+
} as never),
|
|
55
|
+
])
|
|
56
|
+
|
|
57
|
+
expect((requests[0] as any)?.nonceKey).toBe(42n)
|
|
58
|
+
expect((requests[1] as any)?.nonceKey).toBe(0n)
|
|
59
|
+
expect((requests[2] as any)?.nonceKey).toBe(100n)
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
test('behavior: default nonceKey when feePayer is not true', async () => {
|
|
63
|
+
const request = await chain.prepareTransactionRequest({} as never)
|
|
64
|
+
expect((request as any)?.nonceKey).toBe(0n)
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
test('behavior: nonce with sequential nonceKey', async () => {
|
|
68
|
+
const requests = await Promise.all([
|
|
69
|
+
chain.prepareTransactionRequest({ feePayer: true } as never), // nonceKey: 0n
|
|
70
|
+
chain.prepareTransactionRequest({ feePayer: true } as never), // nonceKey: 1n
|
|
71
|
+
chain.prepareTransactionRequest({ feePayer: true } as never), // nonceKey: 2n
|
|
72
|
+
])
|
|
73
|
+
|
|
74
|
+
// Note: 0n is falsy, so first request has nonce undefined
|
|
75
|
+
expect((requests[0] as any)?.nonce).toBe(undefined)
|
|
76
|
+
expect((requests[0] as any)?.nonceKey).toBe(0n)
|
|
77
|
+
|
|
78
|
+
// nonceKey >= 1n is truthy, so nonce is 0
|
|
79
|
+
expect((requests[1] as any)?.nonce).toBe(0)
|
|
80
|
+
expect((requests[1] as any)?.nonceKey).toBeGreaterThan(0n)
|
|
81
|
+
|
|
82
|
+
expect((requests[2] as any)?.nonce).toBe(0)
|
|
83
|
+
expect((requests[2] as any)?.nonceKey).toBeGreaterThan(0n)
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
test('behavior: explicit nonce is preserved', async () => {
|
|
87
|
+
const request = await chain.prepareTransactionRequest({
|
|
88
|
+
feePayer: true,
|
|
89
|
+
nonce: 123,
|
|
90
|
+
} as never)
|
|
91
|
+
expect((request as any)?.nonce).toBe(123)
|
|
92
|
+
expect((request as any)?.nonceKey).toBe(0n)
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
test('behavior: default nonceKey is 0n (falsy)', async () => {
|
|
96
|
+
const request = await chain.prepareTransactionRequest({} as never)
|
|
97
|
+
expect((request as any)?.nonceKey).toBe(0n)
|
|
98
|
+
expect((request as any)?.nonce).toBe(undefined)
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
test('behavior: resetScheduled optimization - only one microtask scheduled', async () => {
|
|
102
|
+
const queueMicrotaskSpy = vi.spyOn(globalThis, 'queueMicrotask')
|
|
103
|
+
const callCountBefore = queueMicrotaskSpy.mock.calls.length
|
|
104
|
+
|
|
105
|
+
// Prepare multiple transactions in parallel
|
|
106
|
+
await Promise.all([
|
|
107
|
+
chain.prepareTransactionRequest({ feePayer: true } as never),
|
|
108
|
+
chain.prepareTransactionRequest({ feePayer: true } as never),
|
|
109
|
+
chain.prepareTransactionRequest({ feePayer: true } as never),
|
|
110
|
+
chain.prepareTransactionRequest({ feePayer: true } as never),
|
|
111
|
+
chain.prepareTransactionRequest({ feePayer: true } as never),
|
|
112
|
+
])
|
|
113
|
+
|
|
114
|
+
const callCountAfter = queueMicrotaskSpy.mock.calls.length
|
|
115
|
+
|
|
116
|
+
// Only one microtask should have been scheduled for the reset
|
|
117
|
+
expect(callCountAfter - callCountBefore).toBe(1)
|
|
118
|
+
|
|
119
|
+
queueMicrotaskSpy.mockRestore()
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
describe('e2e', async () => {
|
|
123
|
+
test('behavior: prepareTransactionRequest', async () => {
|
|
124
|
+
const [request, request2, request3] = await Promise.all([
|
|
125
|
+
prepareTransactionRequest(client, {
|
|
126
|
+
to: '0x0000000000000000000000000000000000000000',
|
|
127
|
+
}),
|
|
128
|
+
prepareTransactionRequest(client, {
|
|
129
|
+
to: '0x0000000000000000000000000000000000000000',
|
|
130
|
+
}),
|
|
131
|
+
prepareTransactionRequest(client, {
|
|
132
|
+
to: '0x0000000000000000000000000000000000000000',
|
|
133
|
+
}),
|
|
134
|
+
])
|
|
135
|
+
expect(request.nonceKey).toBe(0n)
|
|
136
|
+
expect(request2.nonceKey).toBeGreaterThan(0n)
|
|
137
|
+
expect(request3.nonceKey).toBeGreaterThan(0n)
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
test('behavior: sendTransaction', async () => {
|
|
141
|
+
const receipts = await Promise.all([
|
|
142
|
+
sendTransactionSync(clientWithAccount, {
|
|
143
|
+
to: '0x0000000000000000000000000000000000000000',
|
|
144
|
+
}),
|
|
145
|
+
sendTransactionSync(clientWithAccount, {
|
|
146
|
+
to: '0x0000000000000000000000000000000000000001',
|
|
147
|
+
}),
|
|
148
|
+
sendTransactionSync(clientWithAccount, {
|
|
149
|
+
to: '0x0000000000000000000000000000000000000002',
|
|
150
|
+
}),
|
|
151
|
+
])
|
|
152
|
+
const transactions = await Promise.all([
|
|
153
|
+
getTransaction(clientWithAccount, {
|
|
154
|
+
hash: receipts[0].transactionHash,
|
|
155
|
+
}),
|
|
156
|
+
getTransaction(clientWithAccount, {
|
|
157
|
+
hash: receipts[1].transactionHash,
|
|
158
|
+
}),
|
|
159
|
+
getTransaction(clientWithAccount, {
|
|
160
|
+
hash: receipts[2].transactionHash,
|
|
161
|
+
}),
|
|
162
|
+
])
|
|
163
|
+
expect(transactions[0].nonceKey).toBe(0n)
|
|
164
|
+
expect(transactions[1].nonceKey).toBeGreaterThan(0n)
|
|
165
|
+
expect(transactions[2].nonceKey).toBeGreaterThan(0n)
|
|
166
|
+
})
|
|
167
|
+
})
|
|
168
|
+
})
|
package/src/viem/Chain.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as Hex from 'ox/Hex'
|
|
1
2
|
import {
|
|
2
3
|
defineTransaction,
|
|
3
4
|
defineTransactionReceipt,
|
|
@@ -25,6 +26,25 @@ export type Chain<
|
|
|
25
26
|
})
|
|
26
27
|
|
|
27
28
|
function config<const chain extends Chain>(chain: chain) {
|
|
29
|
+
const nonceKeyManager = {
|
|
30
|
+
counter: 0,
|
|
31
|
+
resetScheduled: false,
|
|
32
|
+
reset() {
|
|
33
|
+
this.counter = 0
|
|
34
|
+
this.resetScheduled = false
|
|
35
|
+
},
|
|
36
|
+
get() {
|
|
37
|
+
if (!this.resetScheduled) {
|
|
38
|
+
this.resetScheduled = true
|
|
39
|
+
queueMicrotask(() => this.reset())
|
|
40
|
+
}
|
|
41
|
+
const count = this.counter
|
|
42
|
+
this.counter++
|
|
43
|
+
if (count === 0) return 0n
|
|
44
|
+
return Hex.toBigInt(Hex.random(6))
|
|
45
|
+
},
|
|
46
|
+
}
|
|
47
|
+
|
|
28
48
|
return {
|
|
29
49
|
blockTime: 1_000,
|
|
30
50
|
contracts: {
|
|
@@ -66,6 +86,22 @@ function config<const chain extends Chain>(chain: chain) {
|
|
|
66
86
|
),
|
|
67
87
|
}),
|
|
68
88
|
},
|
|
89
|
+
async prepareTransactionRequest(r) {
|
|
90
|
+
const request = r as Transaction.TransactionRequest
|
|
91
|
+
const nonceKey = (() => {
|
|
92
|
+
if (typeof request.nonceKey !== 'undefined') return request.nonceKey
|
|
93
|
+
return nonceKeyManager.get()
|
|
94
|
+
})()
|
|
95
|
+
|
|
96
|
+
const nonce = (() => {
|
|
97
|
+
if (typeof request.nonce === 'number') return request.nonce
|
|
98
|
+
// TODO: remove this line once `eth_fillTransaction` supports nonce keys.
|
|
99
|
+
if (nonceKey) return 0
|
|
100
|
+
return undefined
|
|
101
|
+
})()
|
|
102
|
+
|
|
103
|
+
return { ...request, nonce, nonceKey } as unknown as typeof r
|
|
104
|
+
},
|
|
69
105
|
serializers: {
|
|
70
106
|
// TODO: casting to satisfy viem – viem v3 to have more flexible serializer type.
|
|
71
107
|
transaction: ((transaction, signature) =>
|
|
@@ -88,7 +124,7 @@ function config<const chain extends Chain>(chain: chain) {
|
|
|
88
124
|
)) as SerializeTransactionFn,
|
|
89
125
|
},
|
|
90
126
|
...chain,
|
|
91
|
-
} as const
|
|
127
|
+
} as const satisfies viem_Chain
|
|
92
128
|
}
|
|
93
129
|
|
|
94
130
|
export function define<const chain extends viem_Chain>(
|
package/src/viem/Formatters.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { parseAccount } from 'viem/accounts'
|
|
|
12
12
|
import type { UnionOmit } from '../internal/types.js'
|
|
13
13
|
import * as ox_Transaction from '../ox/Transaction.js'
|
|
14
14
|
import * as ox_TransactionRequest from '../ox/TransactionRequest.js'
|
|
15
|
+
import type { Account } from './Account.js'
|
|
15
16
|
import type { GetFeeTokenParameter } from './internal/types.js'
|
|
16
17
|
import {
|
|
17
18
|
isTempo,
|
|
@@ -77,6 +78,7 @@ export function formatTransactionRequest<chain extends Chain | undefined>(
|
|
|
77
78
|
action?: string | undefined,
|
|
78
79
|
): TransactionRequestRpc {
|
|
79
80
|
const request = r as Request<chain>
|
|
81
|
+
const account = request.account as Account | undefined
|
|
80
82
|
|
|
81
83
|
// Convert EIP-1559 transactions to AA transactions.
|
|
82
84
|
if (request.type === 'eip1559') (request as any).type = 'aa'
|
|
@@ -91,7 +93,7 @@ export function formatTransactionRequest<chain extends Chain | undefined>(
|
|
|
91
93
|
if (action)
|
|
92
94
|
request.calls = request.calls ?? [
|
|
93
95
|
{
|
|
94
|
-
to: r.to ||
|
|
96
|
+
to: r.to || '0x0000000000000000000000000000000000000000',
|
|
95
97
|
value: r.value,
|
|
96
98
|
data: r.data,
|
|
97
99
|
},
|
|
@@ -106,11 +108,10 @@ export function formatTransactionRequest<chain extends Chain | undefined>(
|
|
|
106
108
|
s: BigInt(auth.s!),
|
|
107
109
|
yParity: Number(auth.yParity),
|
|
108
110
|
})),
|
|
109
|
-
nonce: request.nonce ? BigInt(request.nonce) : undefined,
|
|
110
111
|
type: 'aa',
|
|
111
112
|
} as never)
|
|
112
113
|
|
|
113
|
-
if (action === 'estimateGas'
|
|
114
|
+
if (action === 'estimateGas') {
|
|
114
115
|
rpc.maxFeePerGas = undefined
|
|
115
116
|
rpc.maxPriorityFeePerGas = undefined
|
|
116
117
|
}
|
|
@@ -140,12 +141,12 @@ export function formatTransactionRequest<chain extends Chain | undefined>(
|
|
|
140
141
|
}
|
|
141
142
|
|
|
142
143
|
const [keyType, keyData] = (() => {
|
|
143
|
-
|
|
144
|
-
if (
|
|
144
|
+
const type = account?.keyType || account?.source
|
|
145
|
+
if (!type) return [undefined, undefined]
|
|
146
|
+
if (type === 'webAuthn')
|
|
145
147
|
// TODO: derive correct bytes size of key data based on webauthn create metadata.
|
|
146
148
|
return ['webAuthn', `0x${'ff'.repeat(1400)}`]
|
|
147
|
-
if (['p256', 'secp256k1'].includes(
|
|
148
|
-
return [r.account.source, undefined]
|
|
149
|
+
if (['p256', 'secp256k1'].includes(type)) return [type, undefined]
|
|
149
150
|
return [undefined, undefined]
|
|
150
151
|
})()
|
|
151
152
|
|
package/src/viem/Storage.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { createStore, del, get, set } from 'idb-keyval'
|
|
1
2
|
import * as Json from 'ox/Json'
|
|
2
3
|
|
|
3
4
|
import type { MaybePromise } from '../internal/types.js'
|
|
5
|
+
import { normalizeValue } from './internal/utils.js'
|
|
4
6
|
|
|
5
7
|
export type Storage<
|
|
6
8
|
schema extends Record<string, unknown> = Record<string, unknown>,
|
|
@@ -33,6 +35,26 @@ export namespace from {
|
|
|
33
35
|
}
|
|
34
36
|
}
|
|
35
37
|
|
|
38
|
+
export function idb<schema extends Record<string, unknown>>() {
|
|
39
|
+
const store =
|
|
40
|
+
typeof indexedDB !== 'undefined'
|
|
41
|
+
? createStore('tempo.ts', 'store')
|
|
42
|
+
: undefined
|
|
43
|
+
return from<schema>({
|
|
44
|
+
async getItem(name) {
|
|
45
|
+
const value = await get(name, store)
|
|
46
|
+
if (value === null) return null
|
|
47
|
+
return value
|
|
48
|
+
},
|
|
49
|
+
async removeItem(name) {
|
|
50
|
+
await del(name, store)
|
|
51
|
+
},
|
|
52
|
+
async setItem(name, value) {
|
|
53
|
+
await set(name, normalizeValue(value), store)
|
|
54
|
+
},
|
|
55
|
+
})
|
|
56
|
+
}
|
|
57
|
+
|
|
36
58
|
export function localStorage<schema extends Record<string, unknown>>(
|
|
37
59
|
options: localStorage.Options = {},
|
|
38
60
|
) {
|
package/src/viem/TokenIds.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const
|
|
1
|
+
export const pathUsd = 0n
|
package/src/viem/Transaction.ts
CHANGED
|
@@ -29,6 +29,7 @@ import {
|
|
|
29
29
|
type TransactionType as viem_TransactionType,
|
|
30
30
|
} from 'viem'
|
|
31
31
|
import type { ExactPartial, OneOf, PartialBy } from '../internal/types.js'
|
|
32
|
+
import type * as KeyAuthorization from '../ox/KeyAuthorization.js'
|
|
32
33
|
import * as SignatureEnvelope from '../ox/SignatureEnvelope.js'
|
|
33
34
|
import * as TxAA from '../ox/TransactionEnvelopeAA.js'
|
|
34
35
|
import type * as ox_TransactionReceipt from '../ox/TransactionReceipt.js'
|
|
@@ -43,7 +44,11 @@ export type Transaction<
|
|
|
43
44
|
>
|
|
44
45
|
export type TransactionRpc<pending extends boolean = false> = OneOf<
|
|
45
46
|
| viem_RpcTransaction<pending>
|
|
46
|
-
| (Omit<
|
|
47
|
+
| (Omit<
|
|
48
|
+
TransactionAA<Hex.Hex, Hex.Hex, pending, '0x76'>,
|
|
49
|
+
'keyAuthorization' | 'signature'
|
|
50
|
+
> & {
|
|
51
|
+
keyAuthorization?: KeyAuthorization.Rpc | null | undefined
|
|
47
52
|
signature: SignatureEnvelope.SignatureEnvelopeRpc
|
|
48
53
|
})
|
|
49
54
|
>
|
|
@@ -66,6 +71,7 @@ export type TransactionAA<
|
|
|
66
71
|
chainId: index
|
|
67
72
|
feeToken?: Address | undefined
|
|
68
73
|
feePayerSignature?: viem_Signature | undefined
|
|
74
|
+
keyAuthorization?: KeyAuthorization.Signed<quantity, index> | null | undefined
|
|
69
75
|
nonceKey?: quantity | undefined
|
|
70
76
|
signature: SignatureEnvelope.SignatureEnvelope
|
|
71
77
|
type: type
|
|
@@ -109,9 +115,13 @@ export type TransactionRequestAA<
|
|
|
109
115
|
ExactPartial<FeeValuesEIP1559<quantity>> & {
|
|
110
116
|
accessList?: AccessList | undefined
|
|
111
117
|
authorizationList?: AuthorizationList<index, boolean> | undefined
|
|
118
|
+
keyAuthorization?: KeyAuthorization.Signed<quantity, index> | undefined
|
|
112
119
|
calls?: readonly TxAA.Call<quantity>[] | undefined
|
|
113
120
|
feePayer?: Account | true | undefined
|
|
114
121
|
feeToken?: Address | bigint | undefined
|
|
122
|
+
nonceKey?: 'random' | quantity | undefined
|
|
123
|
+
validBefore?: index | undefined
|
|
124
|
+
validAfter?: index | undefined
|
|
115
125
|
}
|
|
116
126
|
|
|
117
127
|
export type TransactionSerializable = OneOf<
|
|
@@ -129,6 +139,7 @@ export type TransactionSerializableAA<
|
|
|
129
139
|
chainId: number
|
|
130
140
|
feeToken?: Address | bigint | undefined
|
|
131
141
|
feePayerSignature?: viem_Signature | null | undefined
|
|
142
|
+
keyAuthorization?: KeyAuthorization.Signed<quantity, index> | undefined
|
|
132
143
|
nonceKey?: quantity | undefined
|
|
133
144
|
signature?: SignatureEnvelope.SignatureEnvelope<quantity, index> | undefined
|
|
134
145
|
validBefore?: index | undefined
|
|
@@ -151,6 +162,7 @@ export function getType(
|
|
|
151
162
|
typeof transaction.calls !== 'undefined' ||
|
|
152
163
|
typeof transaction.feePayer !== 'undefined' ||
|
|
153
164
|
typeof transaction.feeToken !== 'undefined' ||
|
|
165
|
+
typeof transaction.nonceKey !== 'undefined' ||
|
|
154
166
|
typeof transaction.signature !== 'undefined' ||
|
|
155
167
|
typeof transaction.validBefore !== 'undefined' ||
|
|
156
168
|
typeof transaction.validAfter !== 'undefined'
|
|
@@ -303,7 +315,7 @@ async function serializeAA(
|
|
|
303
315
|
? rest.calls
|
|
304
316
|
: [
|
|
305
317
|
{
|
|
306
|
-
to: rest.to ||
|
|
318
|
+
to: rest.to || '0x0000000000000000000000000000000000000000',
|
|
307
319
|
value: rest.value,
|
|
308
320
|
data: rest.data,
|
|
309
321
|
},
|
package/src/viem/WebAuthnP256.ts
CHANGED
|
@@ -117,15 +117,17 @@ export declare namespace createCredential {
|
|
|
117
117
|
export async function getCredential(
|
|
118
118
|
parameters: getCredential.Parameters,
|
|
119
119
|
): Promise<getCredential.ReturnValue> {
|
|
120
|
-
const { raw } = await WebAuthnP256.sign({
|
|
120
|
+
const { metadata, raw, signature } = await WebAuthnP256.sign({
|
|
121
121
|
...parameters,
|
|
122
122
|
challenge: parameters.hash ?? '0x',
|
|
123
123
|
})
|
|
124
124
|
const publicKey = await parameters.getPublicKey(raw)
|
|
125
125
|
return {
|
|
126
126
|
id: raw.id,
|
|
127
|
+
metadata,
|
|
127
128
|
publicKey,
|
|
128
129
|
raw,
|
|
130
|
+
signature,
|
|
129
131
|
}
|
|
130
132
|
}
|
|
131
133
|
|
|
@@ -136,5 +138,9 @@ export declare namespace getCredential {
|
|
|
136
138
|
credential: WebAuthnP256.P256Credential['raw'],
|
|
137
139
|
) => Promise<Hex.Hex>
|
|
138
140
|
}
|
|
139
|
-
|
|
141
|
+
|
|
142
|
+
export type ReturnValue = WebAuthnP256.sign.ReturnType & {
|
|
143
|
+
id: string
|
|
144
|
+
publicKey: Hex.Hex
|
|
145
|
+
}
|
|
140
146
|
}
|