@wagmi/core 3.0.2 → 3.2.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 (83) hide show
  1. package/dist/esm/exports/internal.js.map +1 -1
  2. package/dist/esm/exports/query.js +1 -1
  3. package/dist/esm/exports/query.js.map +1 -1
  4. package/dist/esm/exports/tempo.js +9 -0
  5. package/dist/esm/exports/tempo.js.map +1 -0
  6. package/dist/esm/tempo/Connectors.js +534 -0
  7. package/dist/esm/tempo/Connectors.js.map +1 -0
  8. package/dist/esm/tempo/KeyManager.js +106 -0
  9. package/dist/esm/tempo/KeyManager.js.map +1 -0
  10. package/dist/esm/tempo/actions/amm.js +437 -0
  11. package/dist/esm/tempo/actions/amm.js.map +1 -0
  12. package/dist/esm/tempo/actions/dex.js +1059 -0
  13. package/dist/esm/tempo/actions/dex.js.map +1 -0
  14. package/dist/esm/tempo/actions/faucet.js +64 -0
  15. package/dist/esm/tempo/actions/faucet.js.map +1 -0
  16. package/dist/esm/tempo/actions/fee.js +160 -0
  17. package/dist/esm/tempo/actions/fee.js.map +1 -0
  18. package/dist/esm/tempo/actions/index.js +11 -0
  19. package/dist/esm/tempo/actions/index.js.map +1 -0
  20. package/dist/esm/tempo/actions/nonce.js +91 -0
  21. package/dist/esm/tempo/actions/nonce.js.map +1 -0
  22. package/dist/esm/tempo/actions/policy.js +532 -0
  23. package/dist/esm/tempo/actions/policy.js.map +1 -0
  24. package/dist/esm/tempo/actions/reward.js +384 -0
  25. package/dist/esm/tempo/actions/reward.js.map +1 -0
  26. package/dist/esm/tempo/actions/token.js +1717 -0
  27. package/dist/esm/tempo/actions/token.js.map +1 -0
  28. package/dist/esm/tempo/actions/utils.js +2 -0
  29. package/dist/esm/tempo/actions/utils.js.map +1 -0
  30. package/dist/esm/tsconfig.build.tsbuildinfo +1 -1
  31. package/dist/esm/version.js +1 -1
  32. package/dist/types/exports/internal.d.ts +1 -1
  33. package/dist/types/exports/internal.d.ts.map +1 -1
  34. package/dist/types/exports/query.d.ts +1 -1
  35. package/dist/types/exports/query.d.ts.map +1 -1
  36. package/dist/types/exports/tempo.d.ts +5 -0
  37. package/dist/types/exports/tempo.d.ts.map +1 -0
  38. package/dist/types/tempo/Connectors.d.ts +99 -0
  39. package/dist/types/tempo/Connectors.d.ts.map +1 -0
  40. package/dist/types/tempo/KeyManager.d.ts +71 -0
  41. package/dist/types/tempo/KeyManager.d.ts.map +1 -0
  42. package/dist/types/tempo/actions/amm.d.ts +387 -0
  43. package/dist/types/tempo/actions/amm.d.ts.map +1 -0
  44. package/dist/types/tempo/actions/dex.d.ts +926 -0
  45. package/dist/types/tempo/actions/dex.d.ts.map +1 -0
  46. package/dist/types/tempo/actions/faucet.d.ts +70 -0
  47. package/dist/types/tempo/actions/faucet.d.ts.map +1 -0
  48. package/dist/types/tempo/actions/fee.d.ts +141 -0
  49. package/dist/types/tempo/actions/fee.d.ts.map +1 -0
  50. package/dist/types/tempo/actions/index.d.ts +10 -0
  51. package/dist/types/tempo/actions/index.d.ts.map +1 -0
  52. package/dist/types/tempo/actions/nonce.d.ts +79 -0
  53. package/dist/types/tempo/actions/nonce.d.ts.map +1 -0
  54. package/dist/types/tempo/actions/policy.d.ts +478 -0
  55. package/dist/types/tempo/actions/policy.d.ts.map +1 -0
  56. package/dist/types/tempo/actions/reward.d.ts +340 -0
  57. package/dist/types/tempo/actions/reward.d.ts.map +1 -0
  58. package/dist/types/tempo/actions/token.d.ts +1531 -0
  59. package/dist/types/tempo/actions/token.d.ts.map +1 -0
  60. package/dist/types/tempo/actions/utils.d.ts +9 -0
  61. package/dist/types/tempo/actions/utils.d.ts.map +1 -0
  62. package/dist/types/types/utils.d.ts +16 -0
  63. package/dist/types/types/utils.d.ts.map +1 -1
  64. package/dist/types/version.d.ts +1 -1
  65. package/package.json +14 -2
  66. package/src/exports/internal.ts +3 -0
  67. package/src/exports/query.ts +4 -1
  68. package/src/exports/tempo.ts +14 -0
  69. package/src/tempo/Connectors.ts +762 -0
  70. package/src/tempo/KeyManager.ts +176 -0
  71. package/src/tempo/actions/amm.ts +678 -0
  72. package/src/tempo/actions/dex.ts +1685 -0
  73. package/src/tempo/actions/faucet.ts +95 -0
  74. package/src/tempo/actions/fee.ts +259 -0
  75. package/src/tempo/actions/index.ts +10 -0
  76. package/src/tempo/actions/nonce.ts +147 -0
  77. package/src/tempo/actions/policy.ts +827 -0
  78. package/src/tempo/actions/reward.ts +624 -0
  79. package/src/tempo/actions/token.ts +2598 -0
  80. package/src/tempo/actions/utils.ts +26 -0
  81. package/src/types/utils.ts +19 -0
  82. package/src/version.ts +1 -1
  83. package/tempo/package.json +5 -0
@@ -0,0 +1,176 @@
1
+ import type { WebAuthnP256 } from 'ox'
2
+ import type * as Hex from 'ox/Hex'
3
+ import * as Json from 'ox/Json'
4
+ import {
5
+ type CreateStorageParameters,
6
+ createStorage,
7
+ type Storage,
8
+ } from '../createStorage.js'
9
+
10
+ export type KeyManager = {
11
+ /** Function to fetch create options for WebAuthn. */
12
+ getChallenge?:
13
+ | (() => Promise<{
14
+ challenge: Hex.Hex
15
+ rp?: { id: string; name: string } | undefined
16
+ }>)
17
+ | undefined
18
+ /** Function to fetch the public key for a credential. */
19
+ getPublicKey: (parameters: {
20
+ credential: WebAuthnP256.P256Credential['raw']
21
+ }) => Promise<Hex.Hex>
22
+ /** Function to set the public key for a credential. */
23
+ setPublicKey: (parameters: {
24
+ credential: WebAuthnP256.P256Credential['raw']
25
+ publicKey: Hex.Hex
26
+ }) => Promise<void>
27
+ }
28
+
29
+ /** Instantiates a key manager. */
30
+ export function from<manager extends KeyManager>(manager: manager): manager {
31
+ return manager
32
+ }
33
+
34
+ /** Instantiates a key manager from a Storage instance. */
35
+ export function fromStorage(storage: Storage): KeyManager {
36
+ return from({
37
+ async getPublicKey(parameters) {
38
+ const publicKey = await storage.getItem(parameters.credential.id)
39
+ if (!publicKey) throw new Error('publicKey not found.')
40
+ return publicKey as Hex.Hex
41
+ },
42
+ async setPublicKey(parameters) {
43
+ await storage.setItem(parameters.credential.id, parameters.publicKey)
44
+ },
45
+ })
46
+ }
47
+
48
+ /**
49
+ * Instantiates a key manager from a localStorage instance.
50
+ *
51
+ * WARNING: Do not use this in production.
52
+ * This is because we are unable to extract a user's public key after the registration
53
+ * process. If a user clears their storage, or visits the website on a different device,
54
+ * they will not be able to access their account.
55
+ *
56
+ * Instead, we recommend to set up a remote store such as [`KeyManager.http`](#http) to register
57
+ * public keys against their WebAuthn credential.
58
+ *
59
+ * @see {@link http}
60
+ *
61
+ * @deprecated
62
+ */
63
+ export function localStorage(options: localStorage.Options = {}) {
64
+ const { key = 'wagmi.keyManager' } = options
65
+ const storage = createStorage({
66
+ ...options,
67
+ key,
68
+ storage: typeof window !== 'undefined' ? window.localStorage : undefined,
69
+ })
70
+ return fromStorage(storage)
71
+ }
72
+
73
+ export namespace localStorage {
74
+ export type Options = Omit<CreateStorageParameters, 'storage'>
75
+ }
76
+
77
+ /**
78
+ * Instantiates a key manager that uses HTTP endpoints for credential management.
79
+ *
80
+ * @example
81
+ * ```tsx
82
+ * import { KeyManager } from '@wagmi/core/tempo'
83
+ *
84
+ * const keyManager = KeyManager.http('https://api.example.com')
85
+ * ```
86
+ *
87
+ * @param url - The URL to use for the HTTP endpoints.
88
+ * @param options - Configuration options for HTTP endpoints.
89
+ * @returns A KeyManager instance that uses HTTP for credential operations.
90
+ */
91
+ export function http(
92
+ url:
93
+ | string
94
+ | {
95
+ getChallenge?: string | Request | undefined
96
+ getPublicKey?: string | Request | undefined
97
+ setPublicKey?: string | Request | undefined
98
+ },
99
+ options: http.Options = {},
100
+ ): KeyManager {
101
+ const { fetch: fetchFn = globalThis.fetch } = options
102
+ const { getChallenge, getPublicKey, setPublicKey } = (() => {
103
+ const base = typeof url === 'string' ? url : ''
104
+ const urls = typeof url === 'object' ? url : {}
105
+ return {
106
+ getChallenge: urls.getChallenge ?? `${base}/challenge`,
107
+ getPublicKey: urls.getPublicKey ?? `${base}/:credentialId`,
108
+ setPublicKey: urls.setPublicKey ?? `${base}/:credentialId`,
109
+ }
110
+ })()
111
+
112
+ return from({
113
+ async getChallenge() {
114
+ const request =
115
+ getChallenge instanceof Request
116
+ ? getChallenge
117
+ : new Request(getChallenge)
118
+
119
+ const response = await fetchFn(request)
120
+
121
+ if (!response.ok)
122
+ throw new Error(`Failed to get create options: ${response.statusText}`)
123
+ return await response.json()
124
+ },
125
+
126
+ async getPublicKey(parameters) {
127
+ const request =
128
+ getPublicKey instanceof Request
129
+ ? getPublicKey
130
+ : new Request(getPublicKey)
131
+
132
+ const response = await fetchFn(
133
+ new Request(
134
+ request.url.replace(':credentialId', parameters.credential.id),
135
+ request,
136
+ ),
137
+ )
138
+
139
+ if (!response.ok)
140
+ throw new Error(`Failed to get public key: ${response.statusText}`)
141
+ const data = await response.json()
142
+ return data.publicKey as Hex.Hex
143
+ },
144
+
145
+ async setPublicKey(parameters) {
146
+ const request =
147
+ setPublicKey instanceof Request
148
+ ? setPublicKey
149
+ : new Request(setPublicKey)
150
+
151
+ const response = await fetchFn(
152
+ new Request(
153
+ request.url.replace(':credentialId', parameters.credential.id),
154
+ request,
155
+ ),
156
+ {
157
+ method: 'POST',
158
+ headers: {
159
+ 'Content-Type': 'application/json',
160
+ },
161
+ body: Json.stringify(parameters),
162
+ },
163
+ )
164
+
165
+ if (!response.ok)
166
+ throw new Error(`Failed to set public key: ${response.statusText}`)
167
+ },
168
+ })
169
+ }
170
+
171
+ export namespace http {
172
+ export type Options = {
173
+ /** Custom fetch function. @default `globalThis.fetch`. */
174
+ fetch?: typeof fetch | undefined
175
+ }
176
+ }