tempo.ts 0.1.5 → 0.2.1
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 +33 -2
- package/dist/chains.d.ts +509 -115
- package/dist/chains.d.ts.map +1 -1
- package/dist/chains.js +20 -9
- package/dist/chains.js.map +1 -1
- package/dist/ox/Order.d.ts +92 -0
- package/dist/ox/Order.d.ts.map +1 -0
- package/dist/ox/Order.js +88 -0
- package/dist/ox/Order.js.map +1 -0
- package/dist/ox/OrdersFilters.d.ts +72 -0
- package/dist/ox/OrdersFilters.d.ts.map +1 -0
- package/dist/ox/OrdersFilters.js +100 -0
- package/dist/ox/OrdersFilters.js.map +1 -0
- package/dist/ox/Pagination.d.ts +128 -0
- package/dist/ox/Pagination.d.ts.map +1 -0
- package/dist/ox/Pagination.js +78 -0
- package/dist/ox/Pagination.js.map +1 -0
- package/dist/ox/PoolId.d.ts +18 -0
- package/dist/ox/PoolId.d.ts.map +1 -0
- package/dist/ox/PoolId.js +13 -0
- package/dist/ox/PoolId.js.map +1 -0
- package/dist/ox/RpcSchema.d.ts +32 -0
- package/dist/ox/RpcSchema.d.ts.map +1 -0
- package/dist/ox/RpcSchema.js +2 -0
- package/dist/ox/RpcSchema.js.map +1 -0
- package/dist/ox/SignatureEnvelope.d.ts +1 -1
- package/dist/ox/SignatureEnvelope.d.ts.map +1 -1
- package/dist/ox/SignatureEnvelope.js.map +1 -1
- package/dist/{viem → ox}/Tick.d.ts +4 -0
- package/dist/ox/Tick.d.ts.map +1 -0
- package/dist/ox/Tick.js.map +1 -0
- package/dist/ox/Transaction.d.ts.map +1 -1
- package/dist/ox/Transaction.js +2 -1
- package/dist/ox/Transaction.js.map +1 -1
- package/dist/ox/TransactionEnvelopeAA.d.ts +6 -6
- package/dist/ox/TransactionEnvelopeAA.d.ts.map +1 -1
- package/dist/ox/TransactionEnvelopeAA.js +4 -2
- package/dist/ox/TransactionEnvelopeAA.js.map +1 -1
- package/dist/ox/TransactionRequest.d.ts +4 -0
- package/dist/ox/TransactionRequest.d.ts.map +1 -1
- package/dist/ox/TransactionRequest.js.map +1 -1
- package/dist/ox/index.d.ts +6 -0
- package/dist/ox/index.d.ts.map +1 -1
- package/dist/ox/index.js +6 -0
- package/dist/ox/index.js.map +1 -1
- package/dist/prool/Instance.d.ts.map +1 -1
- package/dist/prool/Instance.js +20 -4
- package/dist/prool/Instance.js.map +1 -1
- package/dist/viem/Abis.d.ts +1469 -1082
- package/dist/viem/Abis.d.ts.map +1 -1
- package/dist/viem/Abis.js +932 -671
- package/dist/viem/Abis.js.map +1 -1
- package/dist/viem/Account.d.ts +150 -0
- package/dist/viem/Account.d.ts.map +1 -0
- package/dist/viem/Account.js +221 -0
- package/dist/viem/Account.js.map +1 -0
- package/dist/viem/Actions/amm.d.ts +144 -161
- package/dist/viem/Actions/amm.d.ts.map +1 -1
- package/dist/viem/Actions/amm.js +109 -163
- package/dist/viem/Actions/amm.js.map +1 -1
- package/dist/viem/Actions/dex.d.ts +920 -664
- package/dist/viem/Actions/dex.d.ts.map +1 -1
- package/dist/viem/Actions/dex.js +129 -30
- package/dist/viem/Actions/dex.js.map +1 -1
- package/dist/viem/Actions/faucet.d.ts +34 -0
- package/dist/viem/Actions/faucet.d.ts.map +1 -0
- package/dist/viem/Actions/faucet.js +33 -0
- package/dist/viem/Actions/faucet.js.map +1 -0
- package/dist/viem/Actions/fee.d.ts +16 -30
- package/dist/viem/Actions/fee.d.ts.map +1 -1
- package/dist/viem/Actions/fee.js +13 -13
- package/dist/viem/Actions/fee.js.map +1 -1
- package/dist/viem/Actions/index.d.ts +2 -0
- package/dist/viem/Actions/index.d.ts.map +1 -1
- package/dist/viem/Actions/index.js +2 -0
- package/dist/viem/Actions/index.js.map +1 -1
- package/dist/viem/Actions/policy.d.ts +46 -46
- package/dist/viem/Actions/policy.js +46 -46
- package/dist/viem/Actions/reward.d.ts +3236 -0
- package/dist/viem/Actions/reward.d.ts.map +1 -0
- package/dist/viem/Actions/reward.js +725 -0
- package/dist/viem/Actions/reward.js.map +1 -0
- package/dist/viem/Actions/token.d.ts +4399 -2750
- package/dist/viem/Actions/token.d.ts.map +1 -1
- package/dist/viem/Actions/token.js +361 -482
- package/dist/viem/Actions/token.js.map +1 -1
- package/dist/viem/Addresses.d.ts +1 -2
- package/dist/viem/Addresses.d.ts.map +1 -1
- package/dist/viem/Addresses.js +1 -2
- package/dist/viem/Addresses.js.map +1 -1
- package/dist/viem/Chain.d.ts +38 -12
- package/dist/viem/Chain.d.ts.map +1 -1
- package/dist/viem/Chain.js +27 -18
- package/dist/viem/Chain.js.map +1 -1
- package/dist/viem/Decorator.d.ts +1009 -428
- package/dist/viem/Decorator.d.ts.map +1 -1
- package/dist/viem/Decorator.js +17 -5
- package/dist/viem/Decorator.js.map +1 -1
- package/dist/viem/Formatters.d.ts +8 -1
- package/dist/viem/Formatters.d.ts.map +1 -1
- package/dist/viem/Formatters.js +17 -0
- package/dist/viem/Formatters.js.map +1 -1
- package/dist/viem/P256.d.ts +2 -0
- package/dist/viem/P256.d.ts.map +1 -0
- package/dist/viem/P256.js +2 -0
- package/dist/viem/P256.js.map +1 -0
- package/dist/viem/Secp256k1.d.ts +2 -0
- package/dist/viem/Secp256k1.d.ts.map +1 -0
- package/dist/viem/Secp256k1.js +2 -0
- package/dist/viem/Secp256k1.js.map +1 -0
- package/dist/viem/TokenIds.d.ts +1 -2
- package/dist/viem/TokenIds.d.ts.map +1 -1
- package/dist/viem/TokenIds.js +1 -2
- package/dist/viem/TokenIds.js.map +1 -1
- package/dist/viem/Transaction.d.ts +1 -1
- package/dist/viem/Transaction.d.ts.map +1 -1
- package/dist/viem/Transaction.js +46 -5
- package/dist/viem/Transaction.js.map +1 -1
- package/dist/viem/WebAuthnP256.d.ts +79 -0
- package/dist/viem/WebAuthnP256.d.ts.map +1 -0
- package/dist/viem/WebAuthnP256.js +95 -0
- package/dist/viem/WebAuthnP256.js.map +1 -0
- package/dist/viem/WebCryptoP256.d.ts +2 -0
- package/dist/viem/WebCryptoP256.d.ts.map +1 -0
- package/dist/viem/WebCryptoP256.js +2 -0
- package/dist/viem/WebCryptoP256.js.map +1 -0
- package/dist/viem/index.d.ts +6 -3
- package/dist/viem/index.d.ts.map +1 -1
- package/dist/viem/index.js +6 -3
- package/dist/viem/index.js.map +1 -1
- package/dist/viem/internal/account.d.ts +24 -0
- package/dist/viem/internal/account.d.ts.map +1 -0
- package/dist/viem/internal/account.js +68 -0
- package/dist/viem/internal/account.js.map +1 -0
- package/dist/viem/internal/types.d.ts +10 -0
- package/dist/viem/internal/types.d.ts.map +1 -1
- package/dist/wagmi/Actions/amm.d.ts +428 -0
- package/dist/wagmi/Actions/amm.d.ts.map +1 -0
- package/dist/wagmi/Actions/amm.js +472 -0
- package/dist/wagmi/Actions/amm.js.map +1 -0
- package/dist/wagmi/Actions/dex.d.ts +908 -0
- package/dist/wagmi/Actions/dex.d.ts.map +1 -0
- package/dist/wagmi/Actions/dex.js +1023 -0
- package/dist/wagmi/Actions/dex.js.map +1 -0
- package/dist/wagmi/Actions/faucet.d.ts +35 -0
- package/dist/wagmi/Actions/faucet.d.ts.map +1 -0
- package/dist/wagmi/Actions/faucet.js +33 -0
- package/dist/wagmi/Actions/faucet.js.map +1 -0
- package/dist/wagmi/Actions/fee.d.ts +111 -0
- package/dist/wagmi/Actions/fee.d.ts.map +1 -0
- package/dist/wagmi/Actions/fee.js +126 -0
- package/dist/wagmi/Actions/fee.js.map +1 -0
- package/dist/wagmi/Actions/index.d.ts +7 -0
- package/dist/wagmi/Actions/index.d.ts.map +1 -0
- package/dist/wagmi/Actions/index.js +7 -0
- package/dist/wagmi/Actions/index.js.map +1 -0
- package/dist/wagmi/Actions/reward.d.ts +348 -0
- package/dist/wagmi/Actions/reward.d.ts.map +1 -0
- package/dist/wagmi/Actions/reward.js +388 -0
- package/dist/wagmi/Actions/reward.js.map +1 -0
- package/dist/wagmi/Actions/token.d.ts +1546 -0
- package/dist/wagmi/Actions/token.d.ts.map +1 -0
- package/dist/wagmi/Actions/token.js +1712 -0
- package/dist/wagmi/Actions/token.js.map +1 -0
- package/dist/wagmi/Connector.d.ts +81 -0
- package/dist/wagmi/Connector.d.ts.map +1 -0
- package/dist/wagmi/Connector.js +261 -0
- package/dist/wagmi/Connector.js.map +1 -0
- package/dist/wagmi/Hooks/amm.d.ts +421 -0
- package/dist/wagmi/Hooks/amm.d.ts.map +1 -0
- package/dist/wagmi/Hooks/amm.js +504 -0
- package/dist/wagmi/Hooks/amm.js.map +1 -0
- package/dist/wagmi/Hooks/dex.d.ts +816 -0
- package/dist/wagmi/Hooks/dex.d.ts.map +1 -0
- package/dist/wagmi/Hooks/dex.js +973 -0
- package/dist/wagmi/Hooks/dex.js.map +1 -0
- package/dist/wagmi/Hooks/faucet.d.ts +39 -0
- package/dist/wagmi/Hooks/faucet.d.ts.map +1 -0
- package/dist/wagmi/Hooks/faucet.js +40 -0
- package/dist/wagmi/Hooks/faucet.js.map +1 -0
- package/dist/wagmi/Hooks/fee.d.ts +97 -0
- package/dist/wagmi/Hooks/fee.d.ts.map +1 -0
- package/dist/wagmi/Hooks/fee.js +109 -0
- package/dist/wagmi/Hooks/fee.js.map +1 -0
- package/dist/wagmi/Hooks/index.d.ts +7 -0
- package/dist/wagmi/Hooks/index.d.ts.map +1 -0
- package/dist/wagmi/Hooks/index.js +7 -0
- package/dist/wagmi/Hooks/index.js.map +1 -0
- package/dist/wagmi/Hooks/reward.d.ts +307 -0
- package/dist/wagmi/Hooks/reward.d.ts.map +1 -0
- package/dist/wagmi/Hooks/reward.js +349 -0
- package/dist/wagmi/Hooks/reward.js.map +1 -0
- package/dist/wagmi/Hooks/token.d.ts +1388 -0
- package/dist/wagmi/Hooks/token.d.ts.map +1 -0
- package/dist/wagmi/Hooks/token.js +1657 -0
- package/dist/wagmi/Hooks/token.js.map +1 -0
- package/dist/wagmi/index.d.ts +4 -0
- package/dist/wagmi/index.d.ts.map +1 -0
- package/dist/wagmi/index.js +4 -0
- package/dist/wagmi/index.js.map +1 -0
- package/package.json +54 -10
- package/src/chains.ts +21 -9
- package/src/ox/Order.test.ts +78 -0
- package/src/ox/Order.ts +125 -0
- package/src/ox/OrdersFilters.test.ts +182 -0
- package/src/ox/OrdersFilters.ts +125 -0
- package/src/ox/Pagination.test.ts +162 -0
- package/src/ox/Pagination.ts +164 -0
- package/src/ox/PoolId.test.ts +33 -0
- package/src/ox/PoolId.ts +27 -0
- package/src/ox/RpcSchema.ts +35 -0
- package/src/ox/SignatureEnvelope.ts +3 -1
- package/src/{viem → ox}/Tick.test.ts +1 -1
- package/src/{viem → ox}/Tick.ts +5 -0
- package/src/ox/Transaction.test.ts +1 -1
- package/src/ox/Transaction.ts +2 -1
- package/src/ox/TransactionEnvelopeAA.test.ts +239 -96
- package/src/ox/TransactionEnvelopeAA.ts +9 -7
- package/src/ox/TransactionRequest.ts +4 -0
- package/src/ox/index.ts +6 -0
- package/src/prool/Instance.ts +51 -37
- package/src/prool/internal/chain.json +104 -52
- package/src/tsconfig.json +9 -0
- package/src/viem/Abis.ts +972 -710
- package/src/viem/Account.ts +279 -0
- package/src/viem/Actions/__snapshots__/dex.test.ts.snap +850 -0
- package/src/viem/Actions/amm.test.ts +173 -169
- package/src/viem/Actions/amm.ts +131 -203
- package/src/viem/Actions/dex.test.ts +563 -484
- package/src/viem/Actions/dex.ts +203 -30
- package/src/viem/Actions/faucet.ts +50 -0
- package/src/viem/Actions/fee.test.ts +23 -34
- package/src/viem/Actions/fee.ts +20 -13
- package/src/viem/Actions/index.ts +2 -0
- package/src/viem/Actions/policy.test.ts +19 -33
- package/src/viem/Actions/policy.ts +46 -46
- package/src/viem/Actions/reward.test.ts +457 -0
- package/src/viem/Actions/reward.ts +999 -0
- package/src/viem/Actions/token.test.ts +453 -287
- package/src/viem/Actions/token.ts +605 -693
- package/src/viem/Addresses.ts +1 -2
- package/src/viem/Chain.bench-d.ts +12 -0
- package/src/viem/Chain.ts +70 -20
- package/src/viem/Decorator.bench-d.ts +1 -1
- package/src/viem/Decorator.test.ts +3 -1
- package/src/viem/Decorator.ts +1049 -442
- package/src/viem/Formatters.ts +31 -5
- package/src/viem/P256.ts +1 -0
- package/src/viem/Secp256k1.ts +1 -0
- package/src/viem/TokenIds.ts +1 -2
- package/src/viem/Transaction.ts +53 -7
- package/src/viem/WebAuthnP256.ts +140 -0
- package/src/viem/WebCryptoP256.ts +1 -0
- package/src/viem/e2e.test.ts +1126 -297
- package/src/viem/index.ts +6 -3
- package/src/viem/internal/account.ts +107 -0
- package/src/viem/internal/types.ts +9 -0
- package/src/wagmi/Actions/__snapshots__/dex.test.ts.snap +310 -0
- package/src/wagmi/Actions/amm.test.ts +198 -0
- package/src/wagmi/Actions/amm.ts +691 -0
- package/src/wagmi/Actions/dex.test.ts +1507 -0
- package/src/wagmi/Actions/dex.ts +1640 -0
- package/src/wagmi/Actions/faucet.ts +46 -0
- package/src/wagmi/Actions/fee.test.ts +63 -0
- package/src/wagmi/Actions/fee.ts +208 -0
- package/src/wagmi/Actions/index.ts +6 -0
- package/src/wagmi/Actions/reward.test.ts +210 -0
- package/src/wagmi/Actions/reward.ts +632 -0
- package/src/wagmi/Actions/token.test.ts +1308 -0
- package/src/wagmi/Actions/token.ts +2613 -0
- package/src/wagmi/Connector.test.ts +53 -0
- package/src/wagmi/Connector.ts +390 -0
- package/src/wagmi/Hooks/__snapshots__/dex.test.ts.snap +457 -0
- package/src/wagmi/Hooks/amm.test.ts +424 -0
- package/src/wagmi/Hooks/amm.ts +806 -0
- package/src/wagmi/Hooks/dex.test.ts +1017 -0
- package/src/wagmi/Hooks/dex.ts +1685 -0
- package/src/wagmi/Hooks/faucet.ts +76 -0
- package/src/wagmi/Hooks/fee.test.ts +166 -0
- package/src/wagmi/Hooks/fee.ts +206 -0
- package/src/wagmi/Hooks/index.ts +6 -0
- package/src/wagmi/Hooks/reward.test.ts +219 -0
- package/src/wagmi/Hooks/reward.ts +672 -0
- package/src/wagmi/Hooks/token.test.ts +1670 -0
- package/src/wagmi/Hooks/token.ts +2906 -0
- package/src/wagmi/index.ts +3 -0
- package/src/wagmi/internal/types.ts +16 -0
- package/dist/viem/Client.d.ts +0 -27
- package/dist/viem/Client.d.ts.map +0 -1
- package/dist/viem/Client.js +0 -28
- package/dist/viem/Client.js.map +0 -1
- package/dist/viem/Tick.d.ts.map +0 -1
- package/dist/viem/Tick.js.map +0 -1
- package/src/viem/Client.bench-d.ts +0 -8
- package/src/viem/Client.test.ts +0 -178
- package/src/viem/Client.ts +0 -91
- /package/dist/{viem → ox}/Tick.js +0 -0
package/src/viem/Formatters.ts
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
|
+
// TODO: Find opportunities to make this file less duplicated + more simplified with Viem v3.
|
|
2
|
+
|
|
1
3
|
import * as Hex from 'ox/Hex'
|
|
2
4
|
import {
|
|
5
|
+
type Chain,
|
|
6
|
+
type Account as viem_Account,
|
|
3
7
|
formatTransaction as viem_formatTransaction,
|
|
4
8
|
formatTransactionRequest as viem_formatTransactionRequest,
|
|
5
9
|
} from 'viem'
|
|
6
10
|
import { parseAccount } from 'viem/accounts'
|
|
11
|
+
import type { UnionOmit } from '../internal/types.js'
|
|
7
12
|
import * as ox_Transaction from '../ox/Transaction.js'
|
|
8
13
|
import * as ox_TransactionRequest from '../ox/TransactionRequest.js'
|
|
14
|
+
import type { GetFeeTokenParameter } from './internal/types.js'
|
|
9
15
|
import {
|
|
10
16
|
isTempo,
|
|
11
17
|
type Transaction,
|
|
12
18
|
type TransactionRequest,
|
|
13
|
-
type TransactionRequestAA,
|
|
14
19
|
type TransactionRequestRpc,
|
|
15
20
|
type TransactionRpc,
|
|
16
21
|
} from './Transaction.js'
|
|
@@ -53,12 +58,21 @@ export const formatTransaction = (
|
|
|
53
58
|
}
|
|
54
59
|
}
|
|
55
60
|
|
|
56
|
-
|
|
57
|
-
|
|
61
|
+
type Request<chain extends Chain | undefined> = UnionOmit<
|
|
62
|
+
TransactionRequest,
|
|
63
|
+
'feeToken'
|
|
64
|
+
> &
|
|
65
|
+
GetFeeTokenParameter<chain> & { account?: viem_Account | undefined }
|
|
66
|
+
export const formatTransactionRequest = <chain extends Chain | undefined>(
|
|
67
|
+
r: Request<chain>,
|
|
58
68
|
action?: string | undefined,
|
|
59
69
|
): TransactionRequestRpc => {
|
|
60
|
-
const request = r as
|
|
70
|
+
const request = r as Request<chain>
|
|
71
|
+
|
|
72
|
+
// Convert EIP-1559 transactions to AA transactions.
|
|
73
|
+
if (request.type === 'eip1559') (request as any).type = 'aa'
|
|
61
74
|
|
|
75
|
+
// If the request is not a Tempo transaction, route to Viem formatter.
|
|
62
76
|
if (!isTempo(request))
|
|
63
77
|
return viem_formatTransactionRequest(
|
|
64
78
|
r as never,
|
|
@@ -85,7 +99,7 @@ export const formatTransactionRequest = (
|
|
|
85
99
|
})),
|
|
86
100
|
nonce: request.nonce ? BigInt(request.nonce) : undefined,
|
|
87
101
|
type: 'aa',
|
|
88
|
-
})
|
|
102
|
+
} as never)
|
|
89
103
|
|
|
90
104
|
if (action === 'estimateGas') {
|
|
91
105
|
rpc.maxFeePerGas = undefined
|
|
@@ -97,8 +111,20 @@ export const formatTransactionRequest = (
|
|
|
97
111
|
rpc.data = undefined
|
|
98
112
|
rpc.value = undefined
|
|
99
113
|
|
|
114
|
+
const [keyType, keyData] = (() => {
|
|
115
|
+
if (!r.account?.source) return [undefined, undefined]
|
|
116
|
+
if (r.account.source === 'webAuthn')
|
|
117
|
+
// TODO: derive correct bytes size of key data based on webauthn create metadata.
|
|
118
|
+
return ['webAuthn', `0x${'ff'.repeat(1400)}`]
|
|
119
|
+
if (['p256', 'secp256k1'].includes(r.account.source))
|
|
120
|
+
return [r.account.source, undefined]
|
|
121
|
+
return [undefined, undefined]
|
|
122
|
+
})()
|
|
123
|
+
|
|
100
124
|
return {
|
|
101
125
|
...rpc,
|
|
126
|
+
...(keyType ? { keyType } : {}),
|
|
127
|
+
...(keyData ? { keyData } : {}),
|
|
102
128
|
...(request.feePayer
|
|
103
129
|
? {
|
|
104
130
|
feePayer:
|
package/src/viem/P256.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { randomPrivateKey } from 'ox/P256'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { randomPrivateKey } from 'ox/Secp256k1'
|
package/src/viem/TokenIds.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export const
|
|
2
|
-
export const defaultQuoteToken = 0n
|
|
1
|
+
export const linkingUsd = 0n
|
package/src/viem/Transaction.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// TODO: Find opportunities to make this file less duplicated + more simplified with Viem v3.
|
|
2
|
+
|
|
1
3
|
import * as Hex from 'ox/Hex'
|
|
2
4
|
import * as Secp256k1 from 'ox/Secp256k1'
|
|
3
5
|
import * as Signature from 'ox/Signature'
|
|
@@ -150,8 +152,16 @@ export function deserialize<
|
|
|
150
152
|
const serialized extends TransactionSerializedGeneric,
|
|
151
153
|
>(serializedTransaction: serialized): deserialize.ReturnValue<serialized> {
|
|
152
154
|
const type = Hex.slice(serializedTransaction, 0, 1)
|
|
153
|
-
if (type === '0x76')
|
|
154
|
-
|
|
155
|
+
if (type === '0x76') {
|
|
156
|
+
const from =
|
|
157
|
+
Hex.slice(serializedTransaction, -6) === '0xfeefeefeefee'
|
|
158
|
+
? Hex.slice(serializedTransaction, -26, -6)
|
|
159
|
+
: undefined
|
|
160
|
+
return {
|
|
161
|
+
...deserializeAA(serializedTransaction as `0x76${string}`),
|
|
162
|
+
from,
|
|
163
|
+
} as never
|
|
164
|
+
}
|
|
155
165
|
return viem_parseTransaction(serializedTransaction) as never
|
|
156
166
|
}
|
|
157
167
|
|
|
@@ -169,10 +179,31 @@ export async function serialize(
|
|
|
169
179
|
feePayer?: Account | true | undefined
|
|
170
180
|
from?: Address | undefined
|
|
171
181
|
},
|
|
172
|
-
signature?:
|
|
182
|
+
signature?:
|
|
183
|
+
| OneOf<SignatureEnvelope.SignatureEnvelope | viem_Signature>
|
|
184
|
+
| undefined,
|
|
173
185
|
) {
|
|
174
|
-
|
|
186
|
+
// Convert EIP-1559 transactions to AA transactions.
|
|
187
|
+
if (transaction.type === 'eip1559') (transaction as any).type = 'aa'
|
|
188
|
+
|
|
189
|
+
// If the transaction is not a Tempo transaction, route to Viem serializer.
|
|
190
|
+
if (!isTempo(transaction)) {
|
|
191
|
+
if (signature && 'type' in signature && signature.type !== 'secp256k1')
|
|
192
|
+
throw new Error(
|
|
193
|
+
'Unsupported signature type. Expected `secp256k1` but got `' +
|
|
194
|
+
signature.type +
|
|
195
|
+
'`.',
|
|
196
|
+
)
|
|
197
|
+
if (signature && 'type' in signature) {
|
|
198
|
+
const { r, s, yParity } = signature?.signature!
|
|
199
|
+
return viem_serializeTransaction(transaction as never, {
|
|
200
|
+
r: Hex.fromNumber(r, { size: 32 }),
|
|
201
|
+
s: Hex.fromNumber(s, { size: 32 }),
|
|
202
|
+
yParity,
|
|
203
|
+
})
|
|
204
|
+
}
|
|
175
205
|
return viem_serializeTransaction(transaction as never, signature)
|
|
206
|
+
}
|
|
176
207
|
|
|
177
208
|
const type = getType(transaction)
|
|
178
209
|
if (type === 'aa')
|
|
@@ -215,10 +246,11 @@ async function serializeAA(
|
|
|
215
246
|
feePayer?: Account | true | undefined
|
|
216
247
|
from?: Address | undefined
|
|
217
248
|
},
|
|
218
|
-
sig?: viem_Signature | undefined,
|
|
249
|
+
sig?: OneOf<SignatureEnvelope.SignatureEnvelope | viem_Signature> | undefined,
|
|
219
250
|
) {
|
|
220
251
|
const signature = (() => {
|
|
221
252
|
if (transaction.signature) return transaction.signature
|
|
253
|
+
if (sig && 'type' in sig) return sig as SignatureEnvelope.SignatureEnvelope
|
|
222
254
|
if (sig)
|
|
223
255
|
return SignatureEnvelope.from({
|
|
224
256
|
r: BigInt(sig.r!),
|
|
@@ -275,12 +307,13 @@ async function serializeAA(
|
|
|
275
307
|
})
|
|
276
308
|
|
|
277
309
|
const sender = (() => {
|
|
310
|
+
if (transaction.from) return transaction.from
|
|
278
311
|
if (signature.type === 'secp256k1')
|
|
279
312
|
return Secp256k1.recoverAddress({
|
|
280
313
|
payload: TxAA.getSignPayload(tx),
|
|
281
314
|
signature: signature.signature,
|
|
282
315
|
})
|
|
283
|
-
throw new Error('
|
|
316
|
+
throw new Error('Unable to extract sender from transaction or signature.')
|
|
284
317
|
})()
|
|
285
318
|
|
|
286
319
|
const hash = TxAA.getFeePayerSignPayload(tx, {
|
|
@@ -296,8 +329,21 @@ async function serializeAA(
|
|
|
296
329
|
})
|
|
297
330
|
}
|
|
298
331
|
|
|
332
|
+
if (feePayer === true) {
|
|
333
|
+
const serialized = TxAA.serialize(transaction_ox, {
|
|
334
|
+
feePayerSignature: null,
|
|
335
|
+
signature,
|
|
336
|
+
})
|
|
337
|
+
// if the transaction is ready to be sent off (signed), add the sender
|
|
338
|
+
// and a fee marker to the serialized transaction, so the fee payer proxy
|
|
339
|
+
// can infer the sender address.
|
|
340
|
+
if (transaction.from && signature)
|
|
341
|
+
return Hex.concat(serialized, transaction.from, '0xfeefeefeefee')
|
|
342
|
+
return serialized
|
|
343
|
+
}
|
|
344
|
+
|
|
299
345
|
return TxAA.serialize(transaction_ox, {
|
|
300
|
-
feePayerSignature:
|
|
346
|
+
feePayerSignature: undefined,
|
|
301
347
|
signature,
|
|
302
348
|
})
|
|
303
349
|
}
|
|
@@ -0,0 +1,140 @@
|
|
|
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 { raw } = 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
|
+
publicKey,
|
|
128
|
+
raw,
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export declare namespace getCredential {
|
|
133
|
+
export type Parameters = Omit<WebAuthnP256.sign.Options, 'challenge'> & {
|
|
134
|
+
hash?: Hex.Hex | undefined
|
|
135
|
+
getPublicKey: (
|
|
136
|
+
credential: WebAuthnP256.P256Credential['raw'],
|
|
137
|
+
) => Promise<Hex.Hex>
|
|
138
|
+
}
|
|
139
|
+
export type ReturnValue = P256Credential
|
|
140
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createKeyPair } from 'ox/WebCryptoP256'
|