tempo.ts 0.11.0 → 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.
Files changed (196) hide show
  1. package/CHANGELOG.md +67 -4
  2. package/README.md +3 -34
  3. package/dist/server/Handler.d.ts +14 -14
  4. package/dist/server/Handler.d.ts.map +1 -1
  5. package/dist/server/Handler.js +16 -17
  6. package/dist/server/Handler.js.map +1 -1
  7. package/dist/wagmi/Actions/amm.d.ts +51 -51
  8. package/dist/wagmi/Actions/amm.d.ts.map +1 -1
  9. package/dist/wagmi/Actions/amm.js +37 -37
  10. package/dist/wagmi/Actions/amm.js.map +1 -1
  11. package/dist/wagmi/Actions/dex.d.ts +129 -129
  12. package/dist/wagmi/Actions/dex.d.ts.map +1 -1
  13. package/dist/wagmi/Actions/dex.js +73 -73
  14. package/dist/wagmi/Actions/dex.js.map +1 -1
  15. package/dist/wagmi/Actions/faucet.d.ts +9 -9
  16. package/dist/wagmi/Actions/faucet.d.ts.map +1 -1
  17. package/dist/wagmi/Actions/faucet.js +7 -7
  18. package/dist/wagmi/Actions/faucet.js.map +1 -1
  19. package/dist/wagmi/Actions/fee.d.ts +17 -17
  20. package/dist/wagmi/Actions/fee.d.ts.map +1 -1
  21. package/dist/wagmi/Actions/fee.js +10 -10
  22. package/dist/wagmi/Actions/fee.js.map +1 -1
  23. package/dist/wagmi/Actions/nonce.d.ts +9 -79
  24. package/dist/wagmi/Actions/nonce.d.ts.map +1 -1
  25. package/dist/wagmi/Actions/nonce.js +7 -89
  26. package/dist/wagmi/Actions/nonce.js.map +1 -1
  27. package/dist/wagmi/Actions/policy.d.ts +69 -70
  28. package/dist/wagmi/Actions/policy.d.ts.map +1 -1
  29. package/dist/wagmi/Actions/policy.js +43 -43
  30. package/dist/wagmi/Actions/policy.js.map +1 -1
  31. package/dist/wagmi/Actions/reward.d.ts +51 -51
  32. package/dist/wagmi/Actions/reward.d.ts.map +1 -1
  33. package/dist/wagmi/Actions/reward.js +31 -31
  34. package/dist/wagmi/Actions/reward.js.map +1 -1
  35. package/dist/wagmi/Actions/token.d.ts +238 -238
  36. package/dist/wagmi/Actions/token.d.ts.map +1 -1
  37. package/dist/wagmi/Actions/token.js +136 -136
  38. package/dist/wagmi/Actions/token.js.map +1 -1
  39. package/dist/wagmi/Connector.d.ts +2 -1
  40. package/dist/wagmi/Connector.d.ts.map +1 -1
  41. package/dist/wagmi/Connector.js +83 -22
  42. package/dist/wagmi/Connector.js.map +1 -1
  43. package/dist/wagmi/Hooks/nonce.d.ts +1 -52
  44. package/dist/wagmi/Hooks/nonce.d.ts.map +1 -1
  45. package/dist/wagmi/Hooks/nonce.js +1 -70
  46. package/dist/wagmi/Hooks/nonce.js.map +1 -1
  47. package/dist/wagmi/Hooks/policy.d.ts +0 -1
  48. package/dist/wagmi/Hooks/policy.d.ts.map +1 -1
  49. package/dist/wagmi/Hooks/policy.js.map +1 -1
  50. package/dist/wagmi/KeyManager.d.ts +6 -3
  51. package/dist/wagmi/KeyManager.d.ts.map +1 -1
  52. package/dist/wagmi/KeyManager.js +9 -4
  53. package/dist/wagmi/KeyManager.js.map +1 -1
  54. package/package.json +2 -2
  55. package/src/server/Handler.test.ts +2 -2
  56. package/src/server/Handler.ts +16 -17
  57. package/src/wagmi/Actions/amm.ts +63 -63
  58. package/src/wagmi/Actions/dex.test.ts +1 -1
  59. package/src/wagmi/Actions/dex.ts +153 -153
  60. package/src/wagmi/Actions/faucet.ts +11 -11
  61. package/src/wagmi/Actions/fee.ts +20 -20
  62. package/src/wagmi/Actions/nonce.test.ts +1 -64
  63. package/src/wagmi/Actions/nonce.ts +10 -142
  64. package/src/wagmi/Actions/policy.ts +83 -85
  65. package/src/wagmi/Actions/reward.ts +64 -61
  66. package/src/wagmi/Actions/token.ts +287 -283
  67. package/src/wagmi/Connector.ts +105 -31
  68. package/src/wagmi/Hooks/dex.test.ts +1 -1
  69. package/src/wagmi/Hooks/fee.test.ts +0 -6
  70. package/src/wagmi/Hooks/nonce.test.ts +1 -66
  71. package/src/wagmi/Hooks/nonce.ts +1 -114
  72. package/src/wagmi/Hooks/policy.ts +0 -2
  73. package/src/wagmi/KeyManager.ts +18 -5
  74. package/dist/viem/Abis.d.ts +0 -2649
  75. package/dist/viem/Abis.d.ts.map +0 -1
  76. package/dist/viem/Abis.js +0 -1677
  77. package/dist/viem/Abis.js.map +0 -1
  78. package/dist/viem/Account.d.ts +0 -244
  79. package/dist/viem/Account.d.ts.map +0 -1
  80. package/dist/viem/Account.js +0 -382
  81. package/dist/viem/Account.js.map +0 -1
  82. package/dist/viem/Actions/amm.d.ts +0 -1991
  83. package/dist/viem/Actions/amm.d.ts.map +0 -1
  84. package/dist/viem/Actions/amm.js +0 -814
  85. package/dist/viem/Actions/amm.js.map +0 -1
  86. package/dist/viem/Actions/dex.d.ts +0 -3900
  87. package/dist/viem/Actions/dex.d.ts.map +0 -1
  88. package/dist/viem/Actions/dex.js +0 -1414
  89. package/dist/viem/Actions/dex.js.map +0 -1
  90. package/dist/viem/Actions/faucet.d.ts +0 -69
  91. package/dist/viem/Actions/faucet.d.ts.map +0 -1
  92. package/dist/viem/Actions/faucet.js +0 -73
  93. package/dist/viem/Actions/faucet.js.map +0 -1
  94. package/dist/viem/Actions/fee.d.ts +0 -360
  95. package/dist/viem/Actions/fee.d.ts.map +0 -1
  96. package/dist/viem/Actions/fee.js +0 -237
  97. package/dist/viem/Actions/fee.js.map +0 -1
  98. package/dist/viem/Actions/nonce.d.ts +0 -257
  99. package/dist/viem/Actions/nonce.d.ts.map +0 -1
  100. package/dist/viem/Actions/nonce.js +0 -228
  101. package/dist/viem/Actions/nonce.js.map +0 -1
  102. package/dist/viem/Actions/policy.d.ts +0 -1680
  103. package/dist/viem/Actions/policy.d.ts.map +0 -1
  104. package/dist/viem/Actions/policy.js +0 -875
  105. package/dist/viem/Actions/policy.js.map +0 -1
  106. package/dist/viem/Actions/reward.d.ts +0 -2422
  107. package/dist/viem/Actions/reward.d.ts.map +0 -1
  108. package/dist/viem/Actions/reward.js +0 -651
  109. package/dist/viem/Actions/reward.js.map +0 -1
  110. package/dist/viem/Actions/token.d.ts +0 -16007
  111. package/dist/viem/Actions/token.d.ts.map +0 -1
  112. package/dist/viem/Actions/token.js +0 -2936
  113. package/dist/viem/Actions/token.js.map +0 -1
  114. package/dist/viem/Addresses.d.ts +0 -9
  115. package/dist/viem/Addresses.d.ts.map +0 -1
  116. package/dist/viem/Addresses.js +0 -9
  117. package/dist/viem/Addresses.js.map +0 -1
  118. package/dist/viem/Chain.d.ts +0 -451
  119. package/dist/viem/Chain.d.ts.map +0 -1
  120. package/dist/viem/Chain.js +0 -96
  121. package/dist/viem/Chain.js.map +0 -1
  122. package/dist/viem/Formatters.d.ts +0 -10
  123. package/dist/viem/Formatters.d.ts.map +0 -1
  124. package/dist/viem/Formatters.js +0 -104
  125. package/dist/viem/Formatters.js.map +0 -1
  126. package/dist/viem/Storage.d.ts +0 -24
  127. package/dist/viem/Storage.d.ts.map +0 -1
  128. package/dist/viem/Storage.js +0 -68
  129. package/dist/viem/Storage.js.map +0 -1
  130. package/dist/viem/Transaction.d.ts +0 -76
  131. package/dist/viem/Transaction.d.ts.map +0 -1
  132. package/dist/viem/Transaction.js +0 -176
  133. package/dist/viem/Transaction.js.map +0 -1
  134. package/dist/viem/Transport.d.ts +0 -33
  135. package/dist/viem/Transport.d.ts.map +0 -1
  136. package/dist/viem/Transport.js +0 -138
  137. package/dist/viem/Transport.js.map +0 -1
  138. package/dist/viem/WebAuthnP256.d.ts +0 -82
  139. package/dist/viem/WebAuthnP256.d.ts.map +0 -1
  140. package/dist/viem/WebAuthnP256.js +0 -97
  141. package/dist/viem/WebAuthnP256.js.map +0 -1
  142. package/dist/viem/WebCryptoP256.d.ts +0 -2
  143. package/dist/viem/WebCryptoP256.d.ts.map +0 -1
  144. package/dist/viem/WebCryptoP256.js +0 -2
  145. package/dist/viem/WebCryptoP256.js.map +0 -1
  146. package/dist/viem/internal/types.d.ts +0 -20
  147. package/dist/viem/internal/types.d.ts.map +0 -1
  148. package/dist/viem/internal/types.js +0 -2
  149. package/dist/viem/internal/types.js.map +0 -1
  150. package/dist/viem/internal/utils.d.ts +0 -14
  151. package/dist/viem/internal/utils.d.ts.map +0 -1
  152. package/dist/viem/internal/utils.js +0 -33
  153. package/dist/viem/internal/utils.js.map +0 -1
  154. package/src/chains.ts +0 -54
  155. package/src/viem/Abis.ts +0 -1688
  156. package/src/viem/Account.test.ts +0 -444
  157. package/src/viem/Account.ts +0 -601
  158. package/src/viem/Actions/account.test.ts +0 -414
  159. package/src/viem/Actions/account.ts +0 -106
  160. package/src/viem/Actions/amm.test.ts +0 -381
  161. package/src/viem/Actions/amm.ts +0 -1227
  162. package/src/viem/Actions/dex.test.ts +0 -1549
  163. package/src/viem/Actions/dex.ts +0 -2150
  164. package/src/viem/Actions/faucet.ts +0 -121
  165. package/src/viem/Actions/fee.test.ts +0 -259
  166. package/src/viem/Actions/fee.ts +0 -372
  167. package/src/viem/Actions/index.ts +0 -9
  168. package/src/viem/Actions/nonce.test.ts +0 -206
  169. package/src/viem/Actions/nonce.ts +0 -347
  170. package/src/viem/Actions/policy.test.ts +0 -534
  171. package/src/viem/Actions/policy.ts +0 -1335
  172. package/src/viem/Actions/reward.test.ts +0 -434
  173. package/src/viem/Actions/reward.ts +0 -944
  174. package/src/viem/Actions/token.test.ts +0 -3029
  175. package/src/viem/Actions/token.ts +0 -4458
  176. package/src/viem/Addresses.ts +0 -9
  177. package/src/viem/Chain.bench-d.ts +0 -12
  178. package/src/viem/Chain.test.ts +0 -168
  179. package/src/viem/Chain.ts +0 -157
  180. package/src/viem/Decorator.bench-d.ts +0 -11
  181. package/src/viem/Decorator.test.ts +0 -39
  182. package/src/viem/Decorator.ts +0 -3179
  183. package/src/viem/Formatters.ts +0 -164
  184. package/src/viem/P256.ts +0 -1
  185. package/src/viem/Secp256k1.ts +0 -1
  186. package/src/viem/Storage.ts +0 -110
  187. package/src/viem/TokenIds.ts +0 -1
  188. package/src/viem/Transaction.ts +0 -382
  189. package/src/viem/Transport.ts +0 -191
  190. package/src/viem/WebAuthnP256.ts +0 -146
  191. package/src/viem/WebCryptoP256.ts +0 -1
  192. package/src/viem/e2e.test.ts +0 -1602
  193. package/src/viem/index.ts +0 -30
  194. package/src/viem/internal/types.ts +0 -69
  195. package/src/viem/internal/utils.ts +0 -58
  196. package/src/wagmi/internal/types.ts +0 -16
@@ -1,28 +1,27 @@
1
+ import * as idb from 'idb-keyval'
1
2
  import * as Address from 'ox/Address'
2
3
  import type * as Hex from 'ox/Hex'
3
4
  import * as PublicKey from 'ox/PublicKey'
4
5
  import { KeyAuthorization, SignatureEnvelope } from 'ox/tempo'
5
6
  import {
6
7
  createClient,
8
+ defineChain,
7
9
  type EIP1193Provider,
8
10
  getAddress,
9
11
  type LocalAccount,
10
12
  SwitchChainError,
11
13
  } from 'viem'
12
14
  import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts'
15
+ import {
16
+ Account,
17
+ WebAuthnP256,
18
+ WebCryptoP256,
19
+ walletNamespaceCompat,
20
+ } from 'viem/tempo'
13
21
  import { ChainNotConfiguredError, createConnector } from 'wagmi'
14
22
  import type { OneOf } from '../internal/types.js'
15
- import * as Account from '../viem/Account.js'
16
- import type * as tempo_Chain from '../viem/Chain.js'
17
- import { normalizeValue } from '../viem/internal/utils.js'
18
- import * as Storage from '../viem/Storage.js'
19
- import { walletNamespaceCompat } from '../viem/Transport.js'
20
- import * as WebAuthnP256 from '../viem/WebAuthnP256.js'
21
- import * as WebCryptoP256 from '../viem/WebCryptoP256.js'
22
23
  import type * as KeyManager from './KeyManager.js'
23
24
 
24
- type Chain = ReturnType<ReturnType<typeof tempo_Chain.define>>
25
-
26
25
  /**
27
26
  * Connector for a Secp256k1 EOA.
28
27
  *
@@ -180,10 +179,14 @@ export function dangerous_secp256k1(
180
179
  const transport = transports[chain.id]
181
180
  if (!transport) throw new ChainNotConfiguredError()
182
181
 
182
+ if (!account) throw new Error('account not found.')
183
+
183
184
  return createClient({
184
185
  account,
185
- chain: chain as Chain,
186
- transport: walletNamespaceCompat(transport),
186
+ chain,
187
+ transport: walletNamespaceCompat(transport, {
188
+ account,
189
+ }),
187
190
  })
188
191
  },
189
192
  async getProvider({ chainId } = {}) {
@@ -221,12 +224,6 @@ export function webAuthn(options: webAuthn.Parameters) {
221
224
  return undefined
222
225
  })()
223
226
 
224
- const idbStorage = Storage.idb<{
225
- [key: `accessKey:${string}`]: WebCryptoP256.createKeyPair.ReturnType & {
226
- keyAuthorization: KeyAuthorization.KeyAuthorization
227
- }
228
- }>()
229
-
230
227
  type Properties = {
231
228
  connect<withCapabilities extends boolean = false>(parameters: {
232
229
  chainId?: number | undefined
@@ -249,6 +246,9 @@ export function webAuthn(options: webAuthn.Parameters) {
249
246
  }
250
247
  type Provider = Pick<EIP1193Provider, 'request'>
251
248
  type StorageItem = {
249
+ [
250
+ key: `pendingKeyAuthorization:${string}`
251
+ ]: KeyAuthorization.KeyAuthorization
252
252
  'webAuthn.activeCredential': WebAuthnP256.P256Credential
253
253
  'webAuthn.lastActiveCredential': WebAuthnP256.P256Credential
254
254
  }
@@ -329,7 +329,7 @@ export function webAuthn(options: webAuthn.Parameters) {
329
329
  const address = Address.fromPublicKey(
330
330
  PublicKey.fromHex(credential.publicKey),
331
331
  )
332
- return await idbStorage.getItem(`accessKey:${address}`)
332
+ return await idb.get(`accessKey:${address}`)
333
333
  })()
334
334
 
335
335
  // If the access key provisioning is not in strict mode, return the credential and key pair (if exists).
@@ -414,14 +414,11 @@ export function webAuthn(options: webAuthn.Parameters) {
414
414
  normalizeValue(credential),
415
415
  )
416
416
 
417
- account = Account.fromWebAuthnP256(credential, {
418
- storage: Storage.from(config.storage as never),
419
- })
417
+ account = Account.fromWebAuthnP256(credential)
420
418
 
421
419
  if (keyPair) {
422
420
  accessKey = Account.fromWebCryptoP256(keyPair, {
423
421
  access: account,
424
- storage: Storage.from(config.storage as never),
425
422
  })
426
423
 
427
424
  // If we are reconnecting, check if the access key is expired.
@@ -432,7 +429,9 @@ export function webAuthn(options: webAuthn.Parameters) {
432
429
  keyPair.keyAuthorization.expiry < Date.now() / 1000
433
430
  ) {
434
431
  // remove any pending key authorizations from storage.
435
- await account?.storage.removeItem('pendingKeyAuthorization')
432
+ await config?.storage?.removeItem(
433
+ `pendingKeyAuthorization:${account.address.toLowerCase()}`,
434
+ )
436
435
 
437
436
  const message = `Access key expired (on ${new Date(keyPair.keyAuthorization.expiry * 1000).toLocaleString()}).`
438
437
  accessKey = undefined
@@ -452,11 +451,14 @@ export function webAuthn(options: webAuthn.Parameters) {
452
451
  keyAuthorization ??
453
452
  (await account.signKeyAuthorization(accessKey, accessKeyOptions))
454
453
 
455
- await account.storage.setItem('pendingKeyAuthorization', keyAuth)
456
- await idbStorage.setItem(
457
- `accessKey:${account.address.toLowerCase()}`,
458
- { ...keyPair, keyAuthorization: keyAuth },
454
+ await config?.storage?.setItem(
455
+ `pendingKeyAuthorization:${account.address.toLowerCase()}`,
456
+ keyAuth,
459
457
  )
458
+ await idb.set(`accessKey:${account.address.toLowerCase()}`, {
459
+ ...keyPair,
460
+ keyAuthorization: keyAuth,
461
+ })
460
462
  }
461
463
  // If we are granting an access key and it is in strict mode, throw an error if the access key is not provisioned.
462
464
  } else if (accessKeyOptions?.strict) {
@@ -528,7 +530,7 @@ export function webAuthn(options: webAuthn.Parameters) {
528
530
  const targetAccount = await (async () => {
529
531
  if (!accessKey) return account
530
532
 
531
- const item = await idbStorage.getItem(
533
+ const item = await idb.get(
532
534
  `accessKey:${accessKey.address.toLowerCase()}`,
533
535
  )
534
536
  if (
@@ -536,7 +538,9 @@ export function webAuthn(options: webAuthn.Parameters) {
536
538
  item.keyAuthorization.expiry < Date.now() / 1000
537
539
  ) {
538
540
  // remove any pending key authorizations from storage.
539
- await account?.storage.removeItem('pendingKeyAuthorization')
541
+ await config?.storage?.removeItem(
542
+ `pendingKeyAuthorization:${accessKey.address.toLowerCase()}`,
543
+ )
540
544
 
541
545
  const message = `Access key expired (on ${new Date(item.keyAuthorization.expiry * 1000).toLocaleString()}).`
542
546
 
@@ -552,11 +556,60 @@ export function webAuthn(options: webAuthn.Parameters) {
552
556
  }
553
557
  return accessKey
554
558
  })()
559
+ if (!targetAccount) throw new Error('account not found.')
560
+
561
+ const targetChain = defineChain({
562
+ ...chain,
563
+ async prepareTransactionRequest(args, { phase }) {
564
+ const keyAuthorization = await (async () => {
565
+ {
566
+ const keyAuthorization = (
567
+ args as {
568
+ keyAuthorization?:
569
+ | KeyAuthorization.KeyAuthorization
570
+ | undefined
571
+ }
572
+ ).keyAuthorization
573
+ if (keyAuthorization) return keyAuthorization
574
+ }
575
+
576
+ const keyAuthorization = await config.storage?.getItem(
577
+ `pendingKeyAuthorization:${targetAccount?.address.toLowerCase()}`,
578
+ )
579
+ await config.storage?.removeItem(
580
+ `pendingKeyAuthorization:${targetAccount?.address.toLowerCase()}`,
581
+ )
582
+ return keyAuthorization
583
+ })()
584
+
585
+ const [prepareTransactionRequestFn, options] = (() => {
586
+ if (!chain.prepareTransactionRequest) return [undefined, undefined]
587
+ if (typeof chain.prepareTransactionRequest === 'function')
588
+ return [chain.prepareTransactionRequest, undefined]
589
+ return chain.prepareTransactionRequest
590
+ })()
591
+
592
+ const request = await (async () => {
593
+ if (!prepareTransactionRequestFn) return {}
594
+ if (!options || options?.runAt?.includes(phase))
595
+ return await prepareTransactionRequestFn(args, { phase })
596
+ return {}
597
+ })()
598
+
599
+ return {
600
+ ...args,
601
+ ...request,
602
+ keyAuthorization,
603
+ }
604
+ },
605
+ })
555
606
 
556
607
  return createClient({
557
608
  account: targetAccount,
558
- chain: chain as Chain,
559
- transport: walletNamespaceCompat(transport),
609
+ chain: targetChain,
610
+ transport: walletNamespaceCompat(transport, {
611
+ account: targetAccount,
612
+ }),
560
613
  })
561
614
  },
562
615
  async getProvider({ chainId } = {}) {
@@ -594,3 +647,24 @@ export namespace webAuthn {
594
647
  rpId?: string | undefined
595
648
  }
596
649
  }
650
+
651
+ /**
652
+ * Normalizes a value into a structured-clone compatible format.
653
+ *
654
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Window/structuredClone
655
+ */
656
+ function normalizeValue<type>(value: type): type {
657
+ if (Array.isArray(value)) return value.map(normalizeValue) as never
658
+ if (typeof value === 'function') return undefined as never
659
+ if (typeof value !== 'object' || value === null) return value
660
+ if (Object.getPrototypeOf(value) !== Object.prototype)
661
+ try {
662
+ return structuredClone(value)
663
+ } catch {
664
+ return undefined as never
665
+ }
666
+
667
+ const normalized: Record<string, unknown> = {}
668
+ for (const [k, v] of Object.entries(value)) normalized[k] = normalizeValue(v)
669
+ return normalized as never
670
+ }
@@ -1,6 +1,6 @@
1
- import { Tick } from 'tempo.ts/viem'
2
1
  import { Actions, Hooks } from 'tempo.ts/wagmi'
3
2
  import { type Address, isAddress, parseUnits } from 'viem'
3
+ import { Tick } from 'viem/tempo'
4
4
  import { describe, expect, test, vi } from 'vitest'
5
5
  import { useConnect } from 'wagmi'
6
6
  import { addresses } from '../../../test/config.js'
@@ -100,7 +100,6 @@ describe('useUserToken', () => {
100
100
  {
101
101
  "account": {
102
102
  "address": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
103
- "assignKeyAuthorization": [Function],
104
103
  "keyType": "secp256k1",
105
104
  "publicKey": "0x8318535b54105d4a7aae60c08fc45f9687181b4fdfc625bd1a753fa7397fed753547f11ca8696646f2f3acb08e31016afac23e630c5d11f59f61fef57b0d2aa5",
106
105
  "sign": [Function],
@@ -110,11 +109,6 @@ describe('useUserToken', () => {
110
109
  "signTransaction": [Function],
111
110
  "signTypedData": [Function],
112
111
  "source": "root",
113
- "storage": {
114
- "getItem": [Function],
115
- "removeItem": [Function],
116
- "setItem": [Function],
117
- },
118
112
  "type": "local",
119
113
  },
120
114
  "chainId": 1337,
@@ -6,7 +6,7 @@ import { config, renderHook } from '../../../test/wagmi/config.js'
6
6
  import * as hooks from './nonce.js'
7
7
  import * as tokenHooks from './token.js'
8
8
 
9
- const { useNonceKeyCount, useNonce } = hooks
9
+ const { useNonce } = hooks
10
10
 
11
11
  const account = accounts[0]
12
12
  const account2 = accounts[1]
@@ -90,35 +90,6 @@ describe('useNonce', () => {
90
90
  })
91
91
  })
92
92
 
93
- describe('useNonceKeyCount', () => {
94
- test('default', async () => {
95
- let testAccount: Address | undefined
96
-
97
- const { result, rerender } = await renderHook(() =>
98
- useNonceKeyCount({ account: testAccount }),
99
- )
100
-
101
- await vi.waitFor(() => result.current.fetchStatus === 'fetching')
102
-
103
- // Should be disabled when account is undefined
104
- expect(result.current.data).toBeUndefined()
105
- expect(result.current.isPending).toBe(true)
106
- expect(result.current.isEnabled).toBe(false)
107
-
108
- // Set account
109
- testAccount = account.address
110
- rerender()
111
-
112
- await vi.waitFor(() => expect(result.current.isSuccess).toBeTruthy(), {
113
- timeout: 5_000,
114
- })
115
-
116
- // Should now be enabled and have data
117
- expect(result.current.isEnabled).toBe(true)
118
- expect(result.current.data).toBe(0n)
119
- })
120
- })
121
-
122
93
  describe('useWatchNonceIncremented', () => {
123
94
  test('default', async () => {
124
95
  const { result: connectResult } = await renderHook(() => ({
@@ -169,39 +140,3 @@ describe('useWatchNonceIncremented', () => {
169
140
  expect(events[1]?.newNonce).toBe(2n)
170
141
  })
171
142
  })
172
-
173
- describe('useWatchActiveKeyCountChanged', () => {
174
- test('default', async () => {
175
- const { result: connectResult } = await renderHook(() => ({
176
- connect: useConnect(),
177
- transferSync: tokenHooks.useTransferSync(),
178
- }))
179
-
180
- await connectResult.current.connect.connectAsync({
181
- connector: config.connectors[0]!,
182
- })
183
-
184
- const events: any[] = []
185
- await renderHook(() =>
186
- hooks.useWatchActiveKeyCountChanged({
187
- onActiveKeyCountChanged(args) {
188
- events.push(args)
189
- },
190
- }),
191
- )
192
-
193
- await connectResult.current.transferSync.mutateAsync({
194
- to: account2.address,
195
- amount: 1n,
196
- token: 1n,
197
- nonceKey: 10n,
198
- nonce: 0,
199
- })
200
-
201
- await vi.waitUntil(() => events.length >= 1)
202
-
203
- expect(events).toHaveLength(1)
204
- expect(events[0]?.account).toBe(account.address)
205
- expect(events[0]?.newCount).toBe(2n)
206
- })
207
- })
@@ -6,12 +6,7 @@ import type { ConfigParameter, QueryParameter } from 'wagmi/internal'
6
6
  import { type UseQueryReturnType, useQuery } from 'wagmi/query'
7
7
 
8
8
  import type { ExactPartial, UnionCompute } from '../../internal/types.js'
9
- import {
10
- getNonce,
11
- getNonceKeyCount,
12
- watchActiveKeyCountChanged,
13
- watchNonceIncremented,
14
- } from '../Actions/nonce.js'
9
+ import { getNonce, watchNonceIncremented } from '../Actions/nonce.js'
15
10
 
16
11
  /**
17
12
  * Hook for getting the nonce for an account and nonce key.
@@ -74,67 +69,6 @@ export declare namespace useNonce {
74
69
  UseQueryReturnType<selectData, Error>
75
70
  }
76
71
 
77
- /**
78
- * Hook for getting the number of active nonce keys for an account.
79
- *
80
- * @example
81
- * ```tsx
82
- * import { Hooks } from 'tempo.ts/wagmi'
83
- *
84
- * function App() {
85
- * const { data, isLoading } = Hooks.nonce.useNonceKeyCount({
86
- * account: '0x...',
87
- * })
88
- *
89
- * if (isLoading) return <div>Loading...</div>
90
- * return <div>Active keys: {data?.toString()}</div>
91
- * }
92
- * ```
93
- *
94
- * @param parameters - Parameters.
95
- * @returns Query result with active nonce key count.
96
- */
97
- export function useNonceKeyCount<
98
- config extends Config = ResolvedRegister['config'],
99
- selectData = getNonceKeyCount.ReturnValue,
100
- >(parameters: useNonceKeyCount.Parameters<config, selectData> = {}) {
101
- const { account, query = {} } = parameters
102
-
103
- const config = useConfig(parameters)
104
- const chainId = useChainId({ config })
105
-
106
- const options = getNonceKeyCount.queryOptions(config, {
107
- ...parameters,
108
- chainId: parameters.chainId ?? chainId,
109
- query: undefined,
110
- })
111
- const enabled = Boolean(account && (query.enabled ?? true))
112
-
113
- return useQuery({ ...query, ...options, enabled })
114
- }
115
-
116
- export declare namespace useNonceKeyCount {
117
- export type Parameters<
118
- config extends Config = ResolvedRegister['config'],
119
- selectData = getNonceKeyCount.ReturnValue,
120
- > = ConfigParameter<config> &
121
- QueryParameter<
122
- getNonceKeyCount.ReturnValue,
123
- DefaultError,
124
- selectData,
125
- getNonceKeyCount.QueryKey<config>
126
- > &
127
- ExactPartial<
128
- Omit<
129
- getNonceKeyCount.queryOptions.Parameters<config, selectData>,
130
- 'query'
131
- >
132
- >
133
-
134
- export type ReturnValue<selectData = getNonceKeyCount.ReturnValue> =
135
- UseQueryReturnType<selectData, Error>
136
- }
137
-
138
72
  /**
139
73
  * Hook for watching nonce incremented events.
140
74
  *
@@ -181,50 +115,3 @@ export declare namespace useWatchNonceIncremented {
181
115
  ConfigParameter<config> & { enabled?: boolean | undefined }
182
116
  >
183
117
  }
184
-
185
- /**
186
- * Hook for watching active key count changed events.
187
- *
188
- * @example
189
- * ```tsx
190
- * import { Hooks } from 'tempo.ts/wagmi'
191
- *
192
- * function App() {
193
- * Hooks.nonce.useWatchActiveKeyCountChanged({
194
- * onActiveKeyCountChanged(args, log) {
195
- * console.log('Active key count changed:', args)
196
- * },
197
- * })
198
- *
199
- * return <div>Watching for active key count changes...</div>
200
- * }
201
- * ```
202
- *
203
- * @param parameters - Parameters.
204
- */
205
- export function useWatchActiveKeyCountChanged<
206
- config extends Config = ResolvedRegister['config'],
207
- >(parameters: useWatchActiveKeyCountChanged.Parameters<config> = {}) {
208
- const { enabled = true, onActiveKeyCountChanged, ...rest } = parameters
209
-
210
- const config = useConfig({ config: parameters.config })
211
- const configChainId = useChainId({ config })
212
- const chainId = parameters.chainId ?? configChainId
213
-
214
- useEffect(() => {
215
- if (!enabled) return
216
- if (!onActiveKeyCountChanged) return
217
- return watchActiveKeyCountChanged(config, {
218
- ...rest,
219
- chainId,
220
- onActiveKeyCountChanged,
221
- })
222
- }, [config, enabled, onActiveKeyCountChanged, chainId, rest])
223
- }
224
-
225
- export declare namespace useWatchActiveKeyCountChanged {
226
- type Parameters<config extends Config = Config> = UnionCompute<
227
- ExactPartial<watchActiveKeyCountChanged.Parameters<config>> &
228
- ConfigParameter<config> & { enabled?: boolean | undefined }
229
- >
230
- }
@@ -14,8 +14,6 @@ import {
14
14
  import type { ExactPartial, UnionCompute } from '../../internal/types.js'
15
15
  import * as Actions from '../Actions/policy.js'
16
16
 
17
- export type { PolicyType } from '../Actions/policy.js'
18
-
19
17
  /**
20
18
  * Hook for creating a new policy.
21
19
  *
@@ -1,7 +1,11 @@
1
1
  import type * as Hex from 'ox/Hex'
2
2
  import * as Json from 'ox/Json'
3
+ import {
4
+ type CreateStorageParameters,
5
+ createStorage,
6
+ type Storage,
7
+ } from 'wagmi'
3
8
  import type * as Handler from '../server/Handler.js'
4
- import * as Storage from '../viem/Storage.js'
5
9
 
6
10
  export type KeyManager = {
7
11
  /** Function to fetch create options for WebAuthn. */
@@ -24,8 +28,7 @@ export function from<manager extends KeyManager>(manager: manager): manager {
24
28
  }
25
29
 
26
30
  /** Instantiates a key manager from a Storage instance. */
27
- export function fromStorage(s: Storage.Storage): KeyManager {
28
- const storage = Storage.from(s, { key: 'webAuthn:publicKey' })
31
+ export function fromStorage(storage: Storage): KeyManager {
29
32
  return from({
30
33
  async getPublicKey(parameters) {
31
34
  const publicKey = await storage.getItem(parameters.credential.id)
@@ -53,8 +56,18 @@ export function fromStorage(s: Storage.Storage): KeyManager {
53
56
  *
54
57
  * @deprecated
55
58
  */
56
- export function localStorage(options: Storage.localStorage.Options = {}) {
57
- return fromStorage(Storage.localStorage(options))
59
+ export function localStorage(options: localStorage.Options = {}) {
60
+ const { key = 'wagmi.keyManager' } = options
61
+ const storage = createStorage({
62
+ ...options,
63
+ key,
64
+ storage: typeof window !== 'undefined' ? window.localStorage : undefined,
65
+ })
66
+ return fromStorage(storage)
67
+ }
68
+
69
+ export namespace localStorage {
70
+ export type Options = Omit<CreateStorageParameters, 'storage'>
58
71
  }
59
72
 
60
73
  /**