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
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import { WebCryptoP256 } from 'ox'
|
|
2
|
+
import * as Address from 'ox/Address'
|
|
3
|
+
import type * as Hex from 'ox/Hex'
|
|
4
|
+
import * as P256 from 'ox/P256'
|
|
5
|
+
import * as PublicKey from 'ox/PublicKey'
|
|
6
|
+
import * as Secp256k1 from 'ox/Secp256k1'
|
|
7
|
+
import * as Signature from 'ox/Signature'
|
|
8
|
+
import * as WebAuthnP256 from 'ox/WebAuthnP256'
|
|
9
|
+
import * as SignatureEnvelope from '../ox/SignatureEnvelope.js'
|
|
10
|
+
import * as internal from './internal/account.js'
|
|
11
|
+
|
|
12
|
+
export type { Account } from './internal/account.js'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Instantiates an Account from a headless WebAuthn credential (P256 private key).
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { Account } from 'tempo.ts/viem'
|
|
20
|
+
*
|
|
21
|
+
* const account = Account.fromHeadlessWebAuthn('0x...')
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @param privateKey P256 private key.
|
|
25
|
+
* @returns Account.
|
|
26
|
+
*/
|
|
27
|
+
export function fromHeadlessWebAuthn(
|
|
28
|
+
privateKey: Hex.Hex,
|
|
29
|
+
options: fromHeadlessWebAuthn.Options,
|
|
30
|
+
): fromP256.ReturnValue {
|
|
31
|
+
const { rpId, origin } = options
|
|
32
|
+
|
|
33
|
+
const publicKey = P256.getPublicKey({ privateKey })
|
|
34
|
+
const address = Address.fromPublicKey(publicKey)
|
|
35
|
+
|
|
36
|
+
return internal.toPrivateKeyAccount({
|
|
37
|
+
address,
|
|
38
|
+
publicKey,
|
|
39
|
+
async sign({ hash }) {
|
|
40
|
+
const { metadata, payload } = WebAuthnP256.getSignPayload({
|
|
41
|
+
...options,
|
|
42
|
+
challenge: hash,
|
|
43
|
+
rpId,
|
|
44
|
+
origin,
|
|
45
|
+
})
|
|
46
|
+
const signature = P256.sign({
|
|
47
|
+
payload,
|
|
48
|
+
privateKey,
|
|
49
|
+
hash: true,
|
|
50
|
+
})
|
|
51
|
+
return SignatureEnvelope.serialize({
|
|
52
|
+
metadata,
|
|
53
|
+
signature,
|
|
54
|
+
publicKey,
|
|
55
|
+
type: 'webAuthn',
|
|
56
|
+
})
|
|
57
|
+
},
|
|
58
|
+
source: 'webAuthn',
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export declare namespace fromHeadlessWebAuthn {
|
|
63
|
+
export type Options = Omit<
|
|
64
|
+
WebAuthnP256.getSignPayload.Options,
|
|
65
|
+
'challenge' | 'rpId' | 'origin'
|
|
66
|
+
> & {
|
|
67
|
+
rpId: string
|
|
68
|
+
origin: string
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export type ReturnValue = internal.toPrivateKeyAccount.ReturnValue
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Instantiates an Account from a P256 private key.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* import { Account } from 'tempo.ts/viem'
|
|
80
|
+
*
|
|
81
|
+
* const account = Account.fromP256('0x...')
|
|
82
|
+
* ```
|
|
83
|
+
*
|
|
84
|
+
* @param privateKey P256 private key.
|
|
85
|
+
* @returns Account.
|
|
86
|
+
*/
|
|
87
|
+
export function fromP256(privateKey: Hex.Hex): fromP256.ReturnValue {
|
|
88
|
+
const publicKey = P256.getPublicKey({ privateKey })
|
|
89
|
+
const address = Address.fromPublicKey(publicKey)
|
|
90
|
+
|
|
91
|
+
return internal.toPrivateKeyAccount({
|
|
92
|
+
address,
|
|
93
|
+
publicKey,
|
|
94
|
+
async sign({ hash }) {
|
|
95
|
+
const signature = P256.sign({ payload: hash, privateKey })
|
|
96
|
+
return SignatureEnvelope.serialize({
|
|
97
|
+
signature,
|
|
98
|
+
publicKey,
|
|
99
|
+
type: 'p256',
|
|
100
|
+
})
|
|
101
|
+
},
|
|
102
|
+
source: 'p256',
|
|
103
|
+
})
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export declare namespace fromP256 {
|
|
107
|
+
export type ReturnValue = internal.toPrivateKeyAccount.ReturnValue
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Instantiates an Account from a Secp256k1 private key.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```ts
|
|
115
|
+
* import { Account } from 'tempo.ts/viem'
|
|
116
|
+
*
|
|
117
|
+
* const account = Account.fromSecp256k1('0x...')
|
|
118
|
+
* ```
|
|
119
|
+
*
|
|
120
|
+
* @param privateKey Secp256k1 private key.
|
|
121
|
+
* @returns Account.
|
|
122
|
+
*/
|
|
123
|
+
// TODO: this function will be redundant when Viem migrates to Ox.
|
|
124
|
+
export function fromSecp256k1(privateKey: Hex.Hex): fromSecp256k1.ReturnValue {
|
|
125
|
+
const publicKey = Secp256k1.getPublicKey({ privateKey })
|
|
126
|
+
|
|
127
|
+
return internal.toPrivateKeyAccount({
|
|
128
|
+
address: Address.fromPublicKey(publicKey),
|
|
129
|
+
publicKey,
|
|
130
|
+
async sign(parameters) {
|
|
131
|
+
const { hash } = parameters
|
|
132
|
+
const signature = Secp256k1.sign({ payload: hash, privateKey })
|
|
133
|
+
return Signature.toHex(signature)
|
|
134
|
+
},
|
|
135
|
+
})
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export declare namespace fromSecp256k1 {
|
|
139
|
+
export type ReturnValue = internal.toPrivateKeyAccount.ReturnValue
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Instantiates an Account from a WebAuthn credential.
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
*
|
|
147
|
+
* ### Create Passkey + Instantiate Account
|
|
148
|
+
*
|
|
149
|
+
* Create a credential with `WebAuthnP256.createCredential` and then instantiate
|
|
150
|
+
* a Viem Account with `Account.fromWebAuthnP256`.
|
|
151
|
+
*
|
|
152
|
+
* It is highly recommended to store the credential's public key in an external store
|
|
153
|
+
* for future use (ie. for future calls to `WebAuthnP256.getCredential`).
|
|
154
|
+
*
|
|
155
|
+
* ```ts
|
|
156
|
+
* import { Account, WebAuthnP256 } from 'tempo.ts/viem'
|
|
157
|
+
* import { publicKeyStore } from './store'
|
|
158
|
+
*
|
|
159
|
+
* // 1. Create credential
|
|
160
|
+
* const credential = await WebAuthnP256.createCredential({ name: 'Example' })
|
|
161
|
+
*
|
|
162
|
+
* // 2. Instantiate account
|
|
163
|
+
* const account = Account.fromWebAuthnP256(credential)
|
|
164
|
+
*
|
|
165
|
+
* // 3. Store public key
|
|
166
|
+
* await publicKeyStore.set(credential.id, credential.publicKey)
|
|
167
|
+
*
|
|
168
|
+
* ```
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
*
|
|
172
|
+
* ### Get Credential + Instantiate Account
|
|
173
|
+
*
|
|
174
|
+
* Gets a credential from `WebAuthnP256.getCredential` and then instantiates
|
|
175
|
+
* an account with `Account.fromWebAuthnP256`.
|
|
176
|
+
*
|
|
177
|
+
* The `getPublicKey` function is required to fetch the public key paired with the credential
|
|
178
|
+
* from an external store. The public key is required to derive the account's address.
|
|
179
|
+
*
|
|
180
|
+
* ```ts
|
|
181
|
+
* import { Account, WebAuthnP256 } from 'tempo.ts/viem'
|
|
182
|
+
* import { publicKeyStore } from './store'
|
|
183
|
+
*
|
|
184
|
+
* // 1. Get credential
|
|
185
|
+
* const credential = await WebAuthnP256.getCredential({
|
|
186
|
+
* async getPublicKey(credential) {
|
|
187
|
+
* // 2. Get public key from external store.
|
|
188
|
+
* return await publicKeyStore.get(credential.id)
|
|
189
|
+
* }
|
|
190
|
+
* })
|
|
191
|
+
*
|
|
192
|
+
* // 3. Instantiate account
|
|
193
|
+
* const account = Account.fromWebAuthnP256(credential)
|
|
194
|
+
* ```
|
|
195
|
+
*
|
|
196
|
+
* @param credential WebAuthnP256 credential.
|
|
197
|
+
* @returns Account.
|
|
198
|
+
*/
|
|
199
|
+
export function fromWebAuthnP256(
|
|
200
|
+
credential: fromWebAuthnP256.Credential,
|
|
201
|
+
options: fromWebAuthnP256.Options = {},
|
|
202
|
+
): fromWebAuthnP256.ReturnValue {
|
|
203
|
+
const { id } = credential
|
|
204
|
+
const publicKey = PublicKey.fromHex(credential.publicKey)
|
|
205
|
+
return internal.toPrivateKeyAccount({
|
|
206
|
+
address: Address.fromPublicKey(publicKey),
|
|
207
|
+
publicKey,
|
|
208
|
+
async sign({ hash }) {
|
|
209
|
+
const { metadata, signature } = await WebAuthnP256.sign({
|
|
210
|
+
...options,
|
|
211
|
+
challenge: hash,
|
|
212
|
+
credentialId: id,
|
|
213
|
+
})
|
|
214
|
+
return SignatureEnvelope.serialize({
|
|
215
|
+
publicKey,
|
|
216
|
+
metadata,
|
|
217
|
+
signature,
|
|
218
|
+
type: 'webAuthn',
|
|
219
|
+
})
|
|
220
|
+
},
|
|
221
|
+
source: 'webAuthn',
|
|
222
|
+
})
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export declare namespace fromWebAuthnP256 {
|
|
226
|
+
export type Credential = {
|
|
227
|
+
id: WebAuthnP256.P256Credential['id']
|
|
228
|
+
publicKey: Hex.Hex
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export type Options = {
|
|
232
|
+
getFn?: WebAuthnP256.sign.Options['getFn'] | undefined
|
|
233
|
+
rpId?: WebAuthnP256.sign.Options['rpId'] | undefined
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export type ReturnValue = internal.toPrivateKeyAccount.ReturnValue
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Instantiates an Account from a P256 private key.
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```ts
|
|
244
|
+
* import { Account } from 'tempo.ts/viem'
|
|
245
|
+
* import { WebCryptoP256 } from 'ox'
|
|
246
|
+
*
|
|
247
|
+
* const keyPair = await WebCryptoP256.createKeyPair()
|
|
248
|
+
*
|
|
249
|
+
* const account = Account.fromWebCryptoP256(keyPair)
|
|
250
|
+
* ```
|
|
251
|
+
*
|
|
252
|
+
* @param keyPair WebCryptoP256 key pair.
|
|
253
|
+
* @returns Account.
|
|
254
|
+
*/
|
|
255
|
+
export function fromWebCryptoP256(
|
|
256
|
+
keyPair: Awaited<ReturnType<typeof WebCryptoP256.createKeyPair>>,
|
|
257
|
+
): fromWebCryptoP256.ReturnValue {
|
|
258
|
+
const { publicKey, privateKey } = keyPair
|
|
259
|
+
const address = Address.fromPublicKey(publicKey)
|
|
260
|
+
|
|
261
|
+
return internal.toPrivateKeyAccount({
|
|
262
|
+
address,
|
|
263
|
+
publicKey,
|
|
264
|
+
async sign({ hash }) {
|
|
265
|
+
const signature = await WebCryptoP256.sign({ payload: hash, privateKey })
|
|
266
|
+
return SignatureEnvelope.serialize({
|
|
267
|
+
signature,
|
|
268
|
+
prehash: true,
|
|
269
|
+
publicKey,
|
|
270
|
+
type: 'p256',
|
|
271
|
+
})
|
|
272
|
+
},
|
|
273
|
+
source: 'p256',
|
|
274
|
+
})
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export declare namespace fromWebCryptoP256 {
|
|
278
|
+
export type ReturnValue = internal.toPrivateKeyAccount.ReturnValue
|
|
279
|
+
}
|