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.
Files changed (297) hide show
  1. package/README.md +33 -2
  2. package/dist/chains.d.ts +509 -115
  3. package/dist/chains.d.ts.map +1 -1
  4. package/dist/chains.js +20 -9
  5. package/dist/chains.js.map +1 -1
  6. package/dist/ox/Order.d.ts +92 -0
  7. package/dist/ox/Order.d.ts.map +1 -0
  8. package/dist/ox/Order.js +88 -0
  9. package/dist/ox/Order.js.map +1 -0
  10. package/dist/ox/OrdersFilters.d.ts +72 -0
  11. package/dist/ox/OrdersFilters.d.ts.map +1 -0
  12. package/dist/ox/OrdersFilters.js +100 -0
  13. package/dist/ox/OrdersFilters.js.map +1 -0
  14. package/dist/ox/Pagination.d.ts +128 -0
  15. package/dist/ox/Pagination.d.ts.map +1 -0
  16. package/dist/ox/Pagination.js +78 -0
  17. package/dist/ox/Pagination.js.map +1 -0
  18. package/dist/ox/PoolId.d.ts +18 -0
  19. package/dist/ox/PoolId.d.ts.map +1 -0
  20. package/dist/ox/PoolId.js +13 -0
  21. package/dist/ox/PoolId.js.map +1 -0
  22. package/dist/ox/RpcSchema.d.ts +32 -0
  23. package/dist/ox/RpcSchema.d.ts.map +1 -0
  24. package/dist/ox/RpcSchema.js +2 -0
  25. package/dist/ox/RpcSchema.js.map +1 -0
  26. package/dist/ox/SignatureEnvelope.d.ts +1 -1
  27. package/dist/ox/SignatureEnvelope.d.ts.map +1 -1
  28. package/dist/ox/SignatureEnvelope.js.map +1 -1
  29. package/dist/{viem → ox}/Tick.d.ts +4 -0
  30. package/dist/ox/Tick.d.ts.map +1 -0
  31. package/dist/ox/Tick.js.map +1 -0
  32. package/dist/ox/Transaction.d.ts.map +1 -1
  33. package/dist/ox/Transaction.js +2 -1
  34. package/dist/ox/Transaction.js.map +1 -1
  35. package/dist/ox/TransactionEnvelopeAA.d.ts +6 -6
  36. package/dist/ox/TransactionEnvelopeAA.d.ts.map +1 -1
  37. package/dist/ox/TransactionEnvelopeAA.js +4 -2
  38. package/dist/ox/TransactionEnvelopeAA.js.map +1 -1
  39. package/dist/ox/TransactionRequest.d.ts +4 -0
  40. package/dist/ox/TransactionRequest.d.ts.map +1 -1
  41. package/dist/ox/TransactionRequest.js.map +1 -1
  42. package/dist/ox/index.d.ts +6 -0
  43. package/dist/ox/index.d.ts.map +1 -1
  44. package/dist/ox/index.js +6 -0
  45. package/dist/ox/index.js.map +1 -1
  46. package/dist/prool/Instance.d.ts.map +1 -1
  47. package/dist/prool/Instance.js +20 -4
  48. package/dist/prool/Instance.js.map +1 -1
  49. package/dist/viem/Abis.d.ts +1469 -1082
  50. package/dist/viem/Abis.d.ts.map +1 -1
  51. package/dist/viem/Abis.js +932 -671
  52. package/dist/viem/Abis.js.map +1 -1
  53. package/dist/viem/Account.d.ts +150 -0
  54. package/dist/viem/Account.d.ts.map +1 -0
  55. package/dist/viem/Account.js +221 -0
  56. package/dist/viem/Account.js.map +1 -0
  57. package/dist/viem/Actions/amm.d.ts +144 -161
  58. package/dist/viem/Actions/amm.d.ts.map +1 -1
  59. package/dist/viem/Actions/amm.js +109 -163
  60. package/dist/viem/Actions/amm.js.map +1 -1
  61. package/dist/viem/Actions/dex.d.ts +920 -664
  62. package/dist/viem/Actions/dex.d.ts.map +1 -1
  63. package/dist/viem/Actions/dex.js +129 -30
  64. package/dist/viem/Actions/dex.js.map +1 -1
  65. package/dist/viem/Actions/faucet.d.ts +34 -0
  66. package/dist/viem/Actions/faucet.d.ts.map +1 -0
  67. package/dist/viem/Actions/faucet.js +33 -0
  68. package/dist/viem/Actions/faucet.js.map +1 -0
  69. package/dist/viem/Actions/fee.d.ts +16 -30
  70. package/dist/viem/Actions/fee.d.ts.map +1 -1
  71. package/dist/viem/Actions/fee.js +13 -13
  72. package/dist/viem/Actions/fee.js.map +1 -1
  73. package/dist/viem/Actions/index.d.ts +2 -0
  74. package/dist/viem/Actions/index.d.ts.map +1 -1
  75. package/dist/viem/Actions/index.js +2 -0
  76. package/dist/viem/Actions/index.js.map +1 -1
  77. package/dist/viem/Actions/policy.d.ts +46 -46
  78. package/dist/viem/Actions/policy.js +46 -46
  79. package/dist/viem/Actions/reward.d.ts +3236 -0
  80. package/dist/viem/Actions/reward.d.ts.map +1 -0
  81. package/dist/viem/Actions/reward.js +725 -0
  82. package/dist/viem/Actions/reward.js.map +1 -0
  83. package/dist/viem/Actions/token.d.ts +4399 -2750
  84. package/dist/viem/Actions/token.d.ts.map +1 -1
  85. package/dist/viem/Actions/token.js +361 -482
  86. package/dist/viem/Actions/token.js.map +1 -1
  87. package/dist/viem/Addresses.d.ts +1 -2
  88. package/dist/viem/Addresses.d.ts.map +1 -1
  89. package/dist/viem/Addresses.js +1 -2
  90. package/dist/viem/Addresses.js.map +1 -1
  91. package/dist/viem/Chain.d.ts +38 -12
  92. package/dist/viem/Chain.d.ts.map +1 -1
  93. package/dist/viem/Chain.js +27 -18
  94. package/dist/viem/Chain.js.map +1 -1
  95. package/dist/viem/Decorator.d.ts +1009 -428
  96. package/dist/viem/Decorator.d.ts.map +1 -1
  97. package/dist/viem/Decorator.js +17 -5
  98. package/dist/viem/Decorator.js.map +1 -1
  99. package/dist/viem/Formatters.d.ts +8 -1
  100. package/dist/viem/Formatters.d.ts.map +1 -1
  101. package/dist/viem/Formatters.js +17 -0
  102. package/dist/viem/Formatters.js.map +1 -1
  103. package/dist/viem/P256.d.ts +2 -0
  104. package/dist/viem/P256.d.ts.map +1 -0
  105. package/dist/viem/P256.js +2 -0
  106. package/dist/viem/P256.js.map +1 -0
  107. package/dist/viem/Secp256k1.d.ts +2 -0
  108. package/dist/viem/Secp256k1.d.ts.map +1 -0
  109. package/dist/viem/Secp256k1.js +2 -0
  110. package/dist/viem/Secp256k1.js.map +1 -0
  111. package/dist/viem/TokenIds.d.ts +1 -2
  112. package/dist/viem/TokenIds.d.ts.map +1 -1
  113. package/dist/viem/TokenIds.js +1 -2
  114. package/dist/viem/TokenIds.js.map +1 -1
  115. package/dist/viem/Transaction.d.ts +1 -1
  116. package/dist/viem/Transaction.d.ts.map +1 -1
  117. package/dist/viem/Transaction.js +46 -5
  118. package/dist/viem/Transaction.js.map +1 -1
  119. package/dist/viem/WebAuthnP256.d.ts +79 -0
  120. package/dist/viem/WebAuthnP256.d.ts.map +1 -0
  121. package/dist/viem/WebAuthnP256.js +95 -0
  122. package/dist/viem/WebAuthnP256.js.map +1 -0
  123. package/dist/viem/WebCryptoP256.d.ts +2 -0
  124. package/dist/viem/WebCryptoP256.d.ts.map +1 -0
  125. package/dist/viem/WebCryptoP256.js +2 -0
  126. package/dist/viem/WebCryptoP256.js.map +1 -0
  127. package/dist/viem/index.d.ts +6 -3
  128. package/dist/viem/index.d.ts.map +1 -1
  129. package/dist/viem/index.js +6 -3
  130. package/dist/viem/index.js.map +1 -1
  131. package/dist/viem/internal/account.d.ts +24 -0
  132. package/dist/viem/internal/account.d.ts.map +1 -0
  133. package/dist/viem/internal/account.js +68 -0
  134. package/dist/viem/internal/account.js.map +1 -0
  135. package/dist/viem/internal/types.d.ts +10 -0
  136. package/dist/viem/internal/types.d.ts.map +1 -1
  137. package/dist/wagmi/Actions/amm.d.ts +428 -0
  138. package/dist/wagmi/Actions/amm.d.ts.map +1 -0
  139. package/dist/wagmi/Actions/amm.js +472 -0
  140. package/dist/wagmi/Actions/amm.js.map +1 -0
  141. package/dist/wagmi/Actions/dex.d.ts +908 -0
  142. package/dist/wagmi/Actions/dex.d.ts.map +1 -0
  143. package/dist/wagmi/Actions/dex.js +1023 -0
  144. package/dist/wagmi/Actions/dex.js.map +1 -0
  145. package/dist/wagmi/Actions/faucet.d.ts +35 -0
  146. package/dist/wagmi/Actions/faucet.d.ts.map +1 -0
  147. package/dist/wagmi/Actions/faucet.js +33 -0
  148. package/dist/wagmi/Actions/faucet.js.map +1 -0
  149. package/dist/wagmi/Actions/fee.d.ts +111 -0
  150. package/dist/wagmi/Actions/fee.d.ts.map +1 -0
  151. package/dist/wagmi/Actions/fee.js +126 -0
  152. package/dist/wagmi/Actions/fee.js.map +1 -0
  153. package/dist/wagmi/Actions/index.d.ts +7 -0
  154. package/dist/wagmi/Actions/index.d.ts.map +1 -0
  155. package/dist/wagmi/Actions/index.js +7 -0
  156. package/dist/wagmi/Actions/index.js.map +1 -0
  157. package/dist/wagmi/Actions/reward.d.ts +348 -0
  158. package/dist/wagmi/Actions/reward.d.ts.map +1 -0
  159. package/dist/wagmi/Actions/reward.js +388 -0
  160. package/dist/wagmi/Actions/reward.js.map +1 -0
  161. package/dist/wagmi/Actions/token.d.ts +1546 -0
  162. package/dist/wagmi/Actions/token.d.ts.map +1 -0
  163. package/dist/wagmi/Actions/token.js +1712 -0
  164. package/dist/wagmi/Actions/token.js.map +1 -0
  165. package/dist/wagmi/Connector.d.ts +81 -0
  166. package/dist/wagmi/Connector.d.ts.map +1 -0
  167. package/dist/wagmi/Connector.js +261 -0
  168. package/dist/wagmi/Connector.js.map +1 -0
  169. package/dist/wagmi/Hooks/amm.d.ts +421 -0
  170. package/dist/wagmi/Hooks/amm.d.ts.map +1 -0
  171. package/dist/wagmi/Hooks/amm.js +504 -0
  172. package/dist/wagmi/Hooks/amm.js.map +1 -0
  173. package/dist/wagmi/Hooks/dex.d.ts +816 -0
  174. package/dist/wagmi/Hooks/dex.d.ts.map +1 -0
  175. package/dist/wagmi/Hooks/dex.js +973 -0
  176. package/dist/wagmi/Hooks/dex.js.map +1 -0
  177. package/dist/wagmi/Hooks/faucet.d.ts +39 -0
  178. package/dist/wagmi/Hooks/faucet.d.ts.map +1 -0
  179. package/dist/wagmi/Hooks/faucet.js +40 -0
  180. package/dist/wagmi/Hooks/faucet.js.map +1 -0
  181. package/dist/wagmi/Hooks/fee.d.ts +97 -0
  182. package/dist/wagmi/Hooks/fee.d.ts.map +1 -0
  183. package/dist/wagmi/Hooks/fee.js +109 -0
  184. package/dist/wagmi/Hooks/fee.js.map +1 -0
  185. package/dist/wagmi/Hooks/index.d.ts +7 -0
  186. package/dist/wagmi/Hooks/index.d.ts.map +1 -0
  187. package/dist/wagmi/Hooks/index.js +7 -0
  188. package/dist/wagmi/Hooks/index.js.map +1 -0
  189. package/dist/wagmi/Hooks/reward.d.ts +307 -0
  190. package/dist/wagmi/Hooks/reward.d.ts.map +1 -0
  191. package/dist/wagmi/Hooks/reward.js +349 -0
  192. package/dist/wagmi/Hooks/reward.js.map +1 -0
  193. package/dist/wagmi/Hooks/token.d.ts +1388 -0
  194. package/dist/wagmi/Hooks/token.d.ts.map +1 -0
  195. package/dist/wagmi/Hooks/token.js +1657 -0
  196. package/dist/wagmi/Hooks/token.js.map +1 -0
  197. package/dist/wagmi/index.d.ts +4 -0
  198. package/dist/wagmi/index.d.ts.map +1 -0
  199. package/dist/wagmi/index.js +4 -0
  200. package/dist/wagmi/index.js.map +1 -0
  201. package/package.json +54 -10
  202. package/src/chains.ts +21 -9
  203. package/src/ox/Order.test.ts +78 -0
  204. package/src/ox/Order.ts +125 -0
  205. package/src/ox/OrdersFilters.test.ts +182 -0
  206. package/src/ox/OrdersFilters.ts +125 -0
  207. package/src/ox/Pagination.test.ts +162 -0
  208. package/src/ox/Pagination.ts +164 -0
  209. package/src/ox/PoolId.test.ts +33 -0
  210. package/src/ox/PoolId.ts +27 -0
  211. package/src/ox/RpcSchema.ts +35 -0
  212. package/src/ox/SignatureEnvelope.ts +3 -1
  213. package/src/{viem → ox}/Tick.test.ts +1 -1
  214. package/src/{viem → ox}/Tick.ts +5 -0
  215. package/src/ox/Transaction.test.ts +1 -1
  216. package/src/ox/Transaction.ts +2 -1
  217. package/src/ox/TransactionEnvelopeAA.test.ts +239 -96
  218. package/src/ox/TransactionEnvelopeAA.ts +9 -7
  219. package/src/ox/TransactionRequest.ts +4 -0
  220. package/src/ox/index.ts +6 -0
  221. package/src/prool/Instance.ts +51 -37
  222. package/src/prool/internal/chain.json +104 -52
  223. package/src/tsconfig.json +9 -0
  224. package/src/viem/Abis.ts +972 -710
  225. package/src/viem/Account.ts +279 -0
  226. package/src/viem/Actions/__snapshots__/dex.test.ts.snap +850 -0
  227. package/src/viem/Actions/amm.test.ts +173 -169
  228. package/src/viem/Actions/amm.ts +131 -203
  229. package/src/viem/Actions/dex.test.ts +563 -484
  230. package/src/viem/Actions/dex.ts +203 -30
  231. package/src/viem/Actions/faucet.ts +50 -0
  232. package/src/viem/Actions/fee.test.ts +23 -34
  233. package/src/viem/Actions/fee.ts +20 -13
  234. package/src/viem/Actions/index.ts +2 -0
  235. package/src/viem/Actions/policy.test.ts +19 -33
  236. package/src/viem/Actions/policy.ts +46 -46
  237. package/src/viem/Actions/reward.test.ts +457 -0
  238. package/src/viem/Actions/reward.ts +999 -0
  239. package/src/viem/Actions/token.test.ts +453 -287
  240. package/src/viem/Actions/token.ts +605 -693
  241. package/src/viem/Addresses.ts +1 -2
  242. package/src/viem/Chain.bench-d.ts +12 -0
  243. package/src/viem/Chain.ts +70 -20
  244. package/src/viem/Decorator.bench-d.ts +1 -1
  245. package/src/viem/Decorator.test.ts +3 -1
  246. package/src/viem/Decorator.ts +1049 -442
  247. package/src/viem/Formatters.ts +31 -5
  248. package/src/viem/P256.ts +1 -0
  249. package/src/viem/Secp256k1.ts +1 -0
  250. package/src/viem/TokenIds.ts +1 -2
  251. package/src/viem/Transaction.ts +53 -7
  252. package/src/viem/WebAuthnP256.ts +140 -0
  253. package/src/viem/WebCryptoP256.ts +1 -0
  254. package/src/viem/e2e.test.ts +1126 -297
  255. package/src/viem/index.ts +6 -3
  256. package/src/viem/internal/account.ts +107 -0
  257. package/src/viem/internal/types.ts +9 -0
  258. package/src/wagmi/Actions/__snapshots__/dex.test.ts.snap +310 -0
  259. package/src/wagmi/Actions/amm.test.ts +198 -0
  260. package/src/wagmi/Actions/amm.ts +691 -0
  261. package/src/wagmi/Actions/dex.test.ts +1507 -0
  262. package/src/wagmi/Actions/dex.ts +1640 -0
  263. package/src/wagmi/Actions/faucet.ts +46 -0
  264. package/src/wagmi/Actions/fee.test.ts +63 -0
  265. package/src/wagmi/Actions/fee.ts +208 -0
  266. package/src/wagmi/Actions/index.ts +6 -0
  267. package/src/wagmi/Actions/reward.test.ts +210 -0
  268. package/src/wagmi/Actions/reward.ts +632 -0
  269. package/src/wagmi/Actions/token.test.ts +1308 -0
  270. package/src/wagmi/Actions/token.ts +2613 -0
  271. package/src/wagmi/Connector.test.ts +53 -0
  272. package/src/wagmi/Connector.ts +390 -0
  273. package/src/wagmi/Hooks/__snapshots__/dex.test.ts.snap +457 -0
  274. package/src/wagmi/Hooks/amm.test.ts +424 -0
  275. package/src/wagmi/Hooks/amm.ts +806 -0
  276. package/src/wagmi/Hooks/dex.test.ts +1017 -0
  277. package/src/wagmi/Hooks/dex.ts +1685 -0
  278. package/src/wagmi/Hooks/faucet.ts +76 -0
  279. package/src/wagmi/Hooks/fee.test.ts +166 -0
  280. package/src/wagmi/Hooks/fee.ts +206 -0
  281. package/src/wagmi/Hooks/index.ts +6 -0
  282. package/src/wagmi/Hooks/reward.test.ts +219 -0
  283. package/src/wagmi/Hooks/reward.ts +672 -0
  284. package/src/wagmi/Hooks/token.test.ts +1670 -0
  285. package/src/wagmi/Hooks/token.ts +2906 -0
  286. package/src/wagmi/index.ts +3 -0
  287. package/src/wagmi/internal/types.ts +16 -0
  288. package/dist/viem/Client.d.ts +0 -27
  289. package/dist/viem/Client.d.ts.map +0 -1
  290. package/dist/viem/Client.js +0 -28
  291. package/dist/viem/Client.js.map +0 -1
  292. package/dist/viem/Tick.d.ts.map +0 -1
  293. package/dist/viem/Tick.js.map +0 -1
  294. package/src/viem/Client.bench-d.ts +0 -8
  295. package/src/viem/Client.test.ts +0 -178
  296. package/src/viem/Client.ts +0 -91
  297. /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
+ }