tempo.ts 0.11.1 → 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.
- package/CHANGELOG.md +61 -4
- package/README.md +3 -34
- package/dist/server/Handler.d.ts +14 -14
- package/dist/server/Handler.d.ts.map +1 -1
- package/dist/server/Handler.js +16 -17
- package/dist/server/Handler.js.map +1 -1
- package/dist/wagmi/Actions/amm.d.ts +51 -51
- package/dist/wagmi/Actions/amm.d.ts.map +1 -1
- package/dist/wagmi/Actions/amm.js +37 -37
- package/dist/wagmi/Actions/amm.js.map +1 -1
- package/dist/wagmi/Actions/dex.d.ts +129 -129
- package/dist/wagmi/Actions/dex.d.ts.map +1 -1
- package/dist/wagmi/Actions/dex.js +73 -73
- package/dist/wagmi/Actions/dex.js.map +1 -1
- package/dist/wagmi/Actions/faucet.d.ts +9 -9
- package/dist/wagmi/Actions/faucet.d.ts.map +1 -1
- package/dist/wagmi/Actions/faucet.js +7 -7
- package/dist/wagmi/Actions/faucet.js.map +1 -1
- package/dist/wagmi/Actions/fee.d.ts +17 -17
- package/dist/wagmi/Actions/fee.d.ts.map +1 -1
- package/dist/wagmi/Actions/fee.js +10 -10
- package/dist/wagmi/Actions/fee.js.map +1 -1
- package/dist/wagmi/Actions/nonce.d.ts +9 -79
- package/dist/wagmi/Actions/nonce.d.ts.map +1 -1
- package/dist/wagmi/Actions/nonce.js +7 -89
- package/dist/wagmi/Actions/nonce.js.map +1 -1
- package/dist/wagmi/Actions/policy.d.ts +69 -70
- package/dist/wagmi/Actions/policy.d.ts.map +1 -1
- package/dist/wagmi/Actions/policy.js +43 -43
- package/dist/wagmi/Actions/policy.js.map +1 -1
- package/dist/wagmi/Actions/reward.d.ts +51 -51
- package/dist/wagmi/Actions/reward.d.ts.map +1 -1
- package/dist/wagmi/Actions/reward.js +31 -31
- package/dist/wagmi/Actions/reward.js.map +1 -1
- package/dist/wagmi/Actions/token.d.ts +238 -238
- package/dist/wagmi/Actions/token.d.ts.map +1 -1
- package/dist/wagmi/Actions/token.js +136 -136
- package/dist/wagmi/Actions/token.js.map +1 -1
- package/dist/wagmi/Connector.d.ts +2 -1
- package/dist/wagmi/Connector.d.ts.map +1 -1
- package/dist/wagmi/Connector.js +83 -22
- package/dist/wagmi/Connector.js.map +1 -1
- package/dist/wagmi/Hooks/nonce.d.ts +1 -52
- package/dist/wagmi/Hooks/nonce.d.ts.map +1 -1
- package/dist/wagmi/Hooks/nonce.js +1 -70
- package/dist/wagmi/Hooks/nonce.js.map +1 -1
- package/dist/wagmi/Hooks/policy.d.ts +0 -1
- package/dist/wagmi/Hooks/policy.d.ts.map +1 -1
- package/dist/wagmi/Hooks/policy.js.map +1 -1
- package/dist/wagmi/KeyManager.d.ts +6 -3
- package/dist/wagmi/KeyManager.d.ts.map +1 -1
- package/dist/wagmi/KeyManager.js +9 -4
- package/dist/wagmi/KeyManager.js.map +1 -1
- package/package.json +2 -12
- package/src/server/Handler.test.ts +2 -2
- package/src/server/Handler.ts +16 -17
- package/src/wagmi/Actions/amm.ts +63 -63
- package/src/wagmi/Actions/dex.test.ts +1 -1
- package/src/wagmi/Actions/dex.ts +153 -153
- package/src/wagmi/Actions/faucet.ts +11 -11
- package/src/wagmi/Actions/fee.ts +20 -20
- package/src/wagmi/Actions/nonce.test.ts +1 -64
- package/src/wagmi/Actions/nonce.ts +10 -142
- package/src/wagmi/Actions/policy.ts +83 -85
- package/src/wagmi/Actions/reward.ts +64 -61
- package/src/wagmi/Actions/token.ts +287 -283
- package/src/wagmi/Connector.ts +105 -31
- package/src/wagmi/Hooks/dex.test.ts +1 -1
- package/src/wagmi/Hooks/fee.test.ts +0 -6
- package/src/wagmi/Hooks/nonce.test.ts +1 -66
- package/src/wagmi/Hooks/nonce.ts +1 -114
- package/src/wagmi/Hooks/policy.ts +0 -2
- package/src/wagmi/KeyManager.ts +18 -5
- package/dist/chains.d.ts +0 -73
- package/dist/chains.d.ts.map +0 -1
- package/dist/chains.js +0 -51
- package/dist/chains.js.map +0 -1
- package/dist/viem/Abis.d.ts +0 -2649
- package/dist/viem/Abis.d.ts.map +0 -1
- package/dist/viem/Abis.js +0 -1677
- package/dist/viem/Abis.js.map +0 -1
- package/dist/viem/Account.d.ts +0 -244
- package/dist/viem/Account.d.ts.map +0 -1
- package/dist/viem/Account.js +0 -382
- package/dist/viem/Account.js.map +0 -1
- package/dist/viem/Actions/account.d.ts +0 -40
- package/dist/viem/Actions/account.d.ts.map +0 -1
- package/dist/viem/Actions/account.js +0 -86
- package/dist/viem/Actions/account.js.map +0 -1
- package/dist/viem/Actions/amm.d.ts +0 -1991
- package/dist/viem/Actions/amm.d.ts.map +0 -1
- package/dist/viem/Actions/amm.js +0 -814
- package/dist/viem/Actions/amm.js.map +0 -1
- package/dist/viem/Actions/dex.d.ts +0 -3900
- package/dist/viem/Actions/dex.d.ts.map +0 -1
- package/dist/viem/Actions/dex.js +0 -1414
- package/dist/viem/Actions/dex.js.map +0 -1
- package/dist/viem/Actions/faucet.d.ts +0 -69
- package/dist/viem/Actions/faucet.d.ts.map +0 -1
- package/dist/viem/Actions/faucet.js +0 -73
- package/dist/viem/Actions/faucet.js.map +0 -1
- package/dist/viem/Actions/fee.d.ts +0 -360
- package/dist/viem/Actions/fee.d.ts.map +0 -1
- package/dist/viem/Actions/fee.js +0 -237
- package/dist/viem/Actions/fee.js.map +0 -1
- package/dist/viem/Actions/index.d.ts +0 -10
- package/dist/viem/Actions/index.d.ts.map +0 -1
- package/dist/viem/Actions/index.js +0 -10
- package/dist/viem/Actions/index.js.map +0 -1
- package/dist/viem/Actions/nonce.d.ts +0 -257
- package/dist/viem/Actions/nonce.d.ts.map +0 -1
- package/dist/viem/Actions/nonce.js +0 -228
- package/dist/viem/Actions/nonce.js.map +0 -1
- package/dist/viem/Actions/policy.d.ts +0 -1680
- package/dist/viem/Actions/policy.d.ts.map +0 -1
- package/dist/viem/Actions/policy.js +0 -875
- package/dist/viem/Actions/policy.js.map +0 -1
- package/dist/viem/Actions/reward.d.ts +0 -2422
- package/dist/viem/Actions/reward.d.ts.map +0 -1
- package/dist/viem/Actions/reward.js +0 -651
- package/dist/viem/Actions/reward.js.map +0 -1
- package/dist/viem/Actions/token.d.ts +0 -16007
- package/dist/viem/Actions/token.d.ts.map +0 -1
- package/dist/viem/Actions/token.js +0 -2936
- package/dist/viem/Actions/token.js.map +0 -1
- package/dist/viem/Addresses.d.ts +0 -9
- package/dist/viem/Addresses.d.ts.map +0 -1
- package/dist/viem/Addresses.js +0 -9
- package/dist/viem/Addresses.js.map +0 -1
- package/dist/viem/Chain.d.ts +0 -451
- package/dist/viem/Chain.d.ts.map +0 -1
- package/dist/viem/Chain.js +0 -96
- package/dist/viem/Chain.js.map +0 -1
- package/dist/viem/Decorator.d.ts +0 -2783
- package/dist/viem/Decorator.d.ts.map +0 -1
- package/dist/viem/Decorator.js +0 -137
- package/dist/viem/Decorator.js.map +0 -1
- package/dist/viem/Formatters.d.ts +0 -10
- package/dist/viem/Formatters.d.ts.map +0 -1
- package/dist/viem/Formatters.js +0 -104
- package/dist/viem/Formatters.js.map +0 -1
- package/dist/viem/P256.d.ts +0 -2
- package/dist/viem/P256.d.ts.map +0 -1
- package/dist/viem/P256.js +0 -2
- package/dist/viem/P256.js.map +0 -1
- package/dist/viem/Secp256k1.d.ts +0 -2
- package/dist/viem/Secp256k1.d.ts.map +0 -1
- package/dist/viem/Secp256k1.js +0 -2
- package/dist/viem/Secp256k1.js.map +0 -1
- package/dist/viem/Storage.d.ts +0 -24
- package/dist/viem/Storage.d.ts.map +0 -1
- package/dist/viem/Storage.js +0 -68
- package/dist/viem/Storage.js.map +0 -1
- package/dist/viem/TokenIds.d.ts +0 -2
- package/dist/viem/TokenIds.d.ts.map +0 -1
- package/dist/viem/TokenIds.js +0 -2
- package/dist/viem/TokenIds.js.map +0 -1
- package/dist/viem/Transaction.d.ts +0 -76
- package/dist/viem/Transaction.d.ts.map +0 -1
- package/dist/viem/Transaction.js +0 -176
- package/dist/viem/Transaction.js.map +0 -1
- package/dist/viem/Transport.d.ts +0 -33
- package/dist/viem/Transport.d.ts.map +0 -1
- package/dist/viem/Transport.js +0 -138
- package/dist/viem/Transport.js.map +0 -1
- package/dist/viem/WebAuthnP256.d.ts +0 -82
- package/dist/viem/WebAuthnP256.d.ts.map +0 -1
- package/dist/viem/WebAuthnP256.js +0 -97
- package/dist/viem/WebAuthnP256.js.map +0 -1
- package/dist/viem/WebCryptoP256.d.ts +0 -2
- package/dist/viem/WebCryptoP256.d.ts.map +0 -1
- package/dist/viem/WebCryptoP256.js +0 -2
- package/dist/viem/WebCryptoP256.js.map +0 -1
- package/dist/viem/index.d.ts +0 -26
- package/dist/viem/index.d.ts.map +0 -1
- package/dist/viem/index.js +0 -17
- package/dist/viem/index.js.map +0 -1
- package/dist/viem/internal/types.d.ts +0 -20
- package/dist/viem/internal/types.d.ts.map +0 -1
- package/dist/viem/internal/types.js +0 -2
- package/dist/viem/internal/types.js.map +0 -1
- package/dist/viem/internal/utils.d.ts +0 -14
- package/dist/viem/internal/utils.d.ts.map +0 -1
- package/dist/viem/internal/utils.js +0 -33
- package/dist/viem/internal/utils.js.map +0 -1
- package/src/chains.ts +0 -54
- package/src/viem/Abis.ts +0 -1688
- package/src/viem/Account.test.ts +0 -444
- package/src/viem/Account.ts +0 -601
- package/src/viem/Actions/account.test.ts +0 -414
- package/src/viem/Actions/account.ts +0 -106
- package/src/viem/Actions/amm.test.ts +0 -381
- package/src/viem/Actions/amm.ts +0 -1227
- package/src/viem/Actions/dex.test.ts +0 -1549
- package/src/viem/Actions/dex.ts +0 -2150
- package/src/viem/Actions/faucet.ts +0 -121
- package/src/viem/Actions/fee.test.ts +0 -259
- package/src/viem/Actions/fee.ts +0 -372
- package/src/viem/Actions/index.ts +0 -9
- package/src/viem/Actions/nonce.test.ts +0 -206
- package/src/viem/Actions/nonce.ts +0 -347
- package/src/viem/Actions/policy.test.ts +0 -534
- package/src/viem/Actions/policy.ts +0 -1335
- package/src/viem/Actions/reward.test.ts +0 -434
- package/src/viem/Actions/reward.ts +0 -944
- package/src/viem/Actions/token.test.ts +0 -3029
- package/src/viem/Actions/token.ts +0 -4458
- package/src/viem/Addresses.ts +0 -9
- package/src/viem/Chain.bench-d.ts +0 -12
- package/src/viem/Chain.test.ts +0 -168
- package/src/viem/Chain.ts +0 -157
- package/src/viem/Decorator.bench-d.ts +0 -11
- package/src/viem/Decorator.test.ts +0 -39
- package/src/viem/Decorator.ts +0 -3179
- package/src/viem/Formatters.ts +0 -164
- package/src/viem/P256.ts +0 -1
- package/src/viem/Secp256k1.ts +0 -1
- package/src/viem/Storage.ts +0 -110
- package/src/viem/TokenIds.ts +0 -1
- package/src/viem/Transaction.ts +0 -382
- package/src/viem/Transport.ts +0 -191
- package/src/viem/WebAuthnP256.ts +0 -146
- package/src/viem/WebCryptoP256.ts +0 -1
- package/src/viem/e2e.test.ts +0 -1602
- package/src/viem/index.ts +0 -30
- package/src/viem/internal/types.ts +0 -69
- package/src/viem/internal/utils.ts +0 -58
- package/src/wagmi/internal/types.ts +0 -16
package/src/viem/Transport.ts
DELETED
|
@@ -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
|
-
}
|
package/src/viem/WebAuthnP256.ts
DELETED
|
@@ -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'
|