@oasisprotocol/privana-sdk 0.3.0 → 0.4.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/README.md +137 -17
- package/dist/chunk-RDMJGMI3.cjs +1757 -0
- package/dist/chunk-RDMJGMI3.cjs.map +1 -0
- package/dist/chunk-ZVNC4FTJ.js +1704 -0
- package/dist/chunk-ZVNC4FTJ.js.map +1 -0
- package/dist/index.cjs +323 -1718
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +1 -1
- package/dist/index.css.map +1 -1
- package/dist/index.d.cts +61 -60
- package/dist/index.d.ts +61 -60
- package/dist/index.js +52 -1576
- package/dist/index.js.map +1 -1
- package/dist/on-ramp-DIAOtdeU.d.cts +115 -0
- package/dist/on-ramp-DIAOtdeU.d.ts +115 -0
- package/dist/on-ramp.cjs +861 -0
- package/dist/on-ramp.cjs.map +1 -0
- package/dist/on-ramp.d.cts +137 -0
- package/dist/on-ramp.d.ts +137 -0
- package/dist/on-ramp.js +858 -0
- package/dist/on-ramp.js.map +1 -0
- package/package.json +12 -1
|
@@ -0,0 +1,1757 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var react = require('react');
|
|
5
|
+
var wagmi = require('wagmi');
|
|
6
|
+
var actions = require('wagmi/actions');
|
|
7
|
+
var siwe = require('viem/siwe');
|
|
8
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
9
|
+
var viem = require('viem');
|
|
10
|
+
var reactQuery = require('@tanstack/react-query');
|
|
11
|
+
var reactSlot = require('@radix-ui/react-slot');
|
|
12
|
+
var classVarianceAuthority = require('class-variance-authority');
|
|
13
|
+
var clsx = require('clsx');
|
|
14
|
+
var tailwindMerge = require('tailwind-merge');
|
|
15
|
+
var actions$1 = require('viem/actions');
|
|
16
|
+
|
|
17
|
+
// ../../shared/config.json
|
|
18
|
+
var config_default = {
|
|
19
|
+
chains: [
|
|
20
|
+
{
|
|
21
|
+
id: 84532,
|
|
22
|
+
name: "Base Sepolia",
|
|
23
|
+
explorerUrl: "https://sepolia.basescan.org"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
id: 11155111,
|
|
27
|
+
name: "Ethereum Sepolia",
|
|
28
|
+
explorerUrl: "https://sepolia.etherscan.io"
|
|
29
|
+
}
|
|
30
|
+
],
|
|
31
|
+
networks: {
|
|
32
|
+
testnet: {
|
|
33
|
+
chainId: 23295,
|
|
34
|
+
name: "Sapphire Testnet",
|
|
35
|
+
accountingContract: "0xaF8e5de153A584528B57DD4B9B0195956BBDF571",
|
|
36
|
+
apiUrl: "https://testnet.privana.finance"
|
|
37
|
+
},
|
|
38
|
+
mainnet: {
|
|
39
|
+
chainId: 23294,
|
|
40
|
+
name: "Sapphire Mainnet",
|
|
41
|
+
accountingContract: "0x0000000000000000000000000000000000000000",
|
|
42
|
+
apiUrl: ""
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// src/sdk/types/common.ts
|
|
48
|
+
var NETWORK_CONFIG = {
|
|
49
|
+
testnet: {
|
|
50
|
+
...config_default.networks.testnet,
|
|
51
|
+
accountingContract: config_default.networks.testnet.accountingContract
|
|
52
|
+
},
|
|
53
|
+
mainnet: {
|
|
54
|
+
...config_default.networks.mainnet,
|
|
55
|
+
accountingContract: config_default.networks.mainnet.accountingContract
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
function getChainId(network) {
|
|
59
|
+
return NETWORK_CONFIG[network].chainId;
|
|
60
|
+
}
|
|
61
|
+
function getAccountingContract(network) {
|
|
62
|
+
return NETWORK_CONFIG[network].accountingContract;
|
|
63
|
+
}
|
|
64
|
+
function getApiUrl(network) {
|
|
65
|
+
return NETWORK_CONFIG[network].apiUrl;
|
|
66
|
+
}
|
|
67
|
+
function normalizeHex(value) {
|
|
68
|
+
const normalized = value.trim().toLowerCase();
|
|
69
|
+
return normalized.startsWith("0x") ? normalized : `0x${normalized}`;
|
|
70
|
+
}
|
|
71
|
+
function normalizeAddress(value) {
|
|
72
|
+
return normalizeHex(value);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// src/sdk/types/chains.ts
|
|
76
|
+
var SUPPORTED_CHAINS = config_default.chains.map((chain) => ({
|
|
77
|
+
id: chain.id,
|
|
78
|
+
name: chain.name,
|
|
79
|
+
explorerUrl: chain.explorerUrl
|
|
80
|
+
}));
|
|
81
|
+
function getChainById(chainId) {
|
|
82
|
+
return SUPPORTED_CHAINS.find((c) => c.id === chainId);
|
|
83
|
+
}
|
|
84
|
+
function getExplorerAddressUrl(chainId, address) {
|
|
85
|
+
const chain = getChainById(chainId);
|
|
86
|
+
if (!chain) return void 0;
|
|
87
|
+
return `${chain.explorerUrl}/address/${address}#tokentxns`;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// src/sdk/auth/hosted-auth.ts
|
|
91
|
+
var HOSTED_AUTH_CLOCK_SKEW_MS = 3e4;
|
|
92
|
+
var PKCE_CHARSET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~";
|
|
93
|
+
var DEFAULT_RANDOM_LENGTH = 64;
|
|
94
|
+
var HOSTED_AUTH_CALLBACK_QUERY_KEYS = ["code", "error", "error_description", "state"];
|
|
95
|
+
function randomString(length) {
|
|
96
|
+
const values = new Uint8Array(length);
|
|
97
|
+
crypto.getRandomValues(values);
|
|
98
|
+
let output = "";
|
|
99
|
+
for (const value of values) {
|
|
100
|
+
output += PKCE_CHARSET[value % PKCE_CHARSET.length];
|
|
101
|
+
}
|
|
102
|
+
return output;
|
|
103
|
+
}
|
|
104
|
+
function toBase64Url(bytes) {
|
|
105
|
+
let binary = "";
|
|
106
|
+
bytes.forEach((byte) => {
|
|
107
|
+
binary += String.fromCharCode(byte);
|
|
108
|
+
});
|
|
109
|
+
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
|
|
110
|
+
}
|
|
111
|
+
function createPkceVerifier(length = DEFAULT_RANDOM_LENGTH) {
|
|
112
|
+
return randomString(length);
|
|
113
|
+
}
|
|
114
|
+
async function createPkceChallenge(verifier) {
|
|
115
|
+
const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(verifier));
|
|
116
|
+
return toBase64Url(new Uint8Array(digest));
|
|
117
|
+
}
|
|
118
|
+
function createHostedAuthState(length = DEFAULT_RANDOM_LENGTH) {
|
|
119
|
+
return randomString(length);
|
|
120
|
+
}
|
|
121
|
+
function createHostedAuthStorageKey(apiUrl, config) {
|
|
122
|
+
const normalizedApiUrl = apiUrl.replace(/\/$/, "");
|
|
123
|
+
return [
|
|
124
|
+
"privana",
|
|
125
|
+
"hosted-auth",
|
|
126
|
+
normalizedApiUrl,
|
|
127
|
+
config.clientId.trim(),
|
|
128
|
+
config.redirectUri.trim()
|
|
129
|
+
].join(":");
|
|
130
|
+
}
|
|
131
|
+
function createHostedAuthPendingStorageKey(apiUrl, config) {
|
|
132
|
+
return `${createHostedAuthStorageKey(apiUrl, config)}:pending`;
|
|
133
|
+
}
|
|
134
|
+
function persistHostedAuthPendingTransaction(storage, key, transaction) {
|
|
135
|
+
storage.setItem(key, JSON.stringify(transaction));
|
|
136
|
+
}
|
|
137
|
+
function readHostedAuthPendingTransaction(storage, key) {
|
|
138
|
+
const raw = storage.getItem(key);
|
|
139
|
+
if (!raw) return null;
|
|
140
|
+
try {
|
|
141
|
+
const parsed = JSON.parse(raw);
|
|
142
|
+
if (typeof parsed.codeVerifier !== "string" || typeof parsed.state !== "string") {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
codeVerifier: parsed.codeVerifier,
|
|
147
|
+
state: parsed.state
|
|
148
|
+
};
|
|
149
|
+
} catch {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function clearHostedAuthPendingTransaction(storage, key) {
|
|
154
|
+
storage.removeItem(key);
|
|
155
|
+
}
|
|
156
|
+
function parseHostedAuthCallback(url, redirectUri) {
|
|
157
|
+
const expectedUrl = new URL(redirectUri);
|
|
158
|
+
if (url.origin !== expectedUrl.origin || url.pathname !== expectedUrl.pathname) {
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
const code = url.searchParams.get("code");
|
|
162
|
+
if (code) {
|
|
163
|
+
return {
|
|
164
|
+
code,
|
|
165
|
+
state: url.searchParams.get("state")
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
const error = url.searchParams.get("error");
|
|
169
|
+
if (error) {
|
|
170
|
+
return {
|
|
171
|
+
error,
|
|
172
|
+
errorDescription: url.searchParams.get("error_description") ?? void 0,
|
|
173
|
+
state: url.searchParams.get("state")
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
function stripHostedAuthCallbackParams(url) {
|
|
179
|
+
const nextUrl = new URL(url.toString());
|
|
180
|
+
HOSTED_AUTH_CALLBACK_QUERY_KEYS.forEach((key) => {
|
|
181
|
+
nextUrl.searchParams.delete(key);
|
|
182
|
+
});
|
|
183
|
+
return `${nextUrl.pathname}${nextUrl.search}${nextUrl.hash}`;
|
|
184
|
+
}
|
|
185
|
+
function buildHostedAuthSession(response, config, now = Date.now()) {
|
|
186
|
+
return {
|
|
187
|
+
accessToken: response.access_token,
|
|
188
|
+
refreshToken: response.refresh_token,
|
|
189
|
+
idToken: response.id_token,
|
|
190
|
+
tokenType: response.token_type,
|
|
191
|
+
address: response.address,
|
|
192
|
+
clientId: config.clientId,
|
|
193
|
+
redirectUri: config.redirectUri,
|
|
194
|
+
expiresAt: now + response.expires_in * 1e3,
|
|
195
|
+
refreshExpiresAt: now + response.refresh_expires_in * 1e3
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
function applyRefreshResponse(session, response, now = Date.now()) {
|
|
199
|
+
return {
|
|
200
|
+
...session,
|
|
201
|
+
accessToken: response.token,
|
|
202
|
+
refreshToken: response.refresh_token,
|
|
203
|
+
expiresAt: now + response.expires_in * 1e3,
|
|
204
|
+
refreshExpiresAt: now + response.refresh_expires_in * 1e3
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
function isHostedAuthSessionActive(session, now = Date.now(), skewMs = HOSTED_AUTH_CLOCK_SKEW_MS) {
|
|
208
|
+
return session.expiresAt > now + skewMs;
|
|
209
|
+
}
|
|
210
|
+
function isHostedAuthRefreshActive(session, now = Date.now(), skewMs = HOSTED_AUTH_CLOCK_SKEW_MS) {
|
|
211
|
+
return session.refreshExpiresAt > now + skewMs;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// src/sdk/client/errors.ts
|
|
215
|
+
var AccountingApiError = class _AccountingApiError extends Error {
|
|
216
|
+
constructor(message, statusCode, detail) {
|
|
217
|
+
super(message);
|
|
218
|
+
this.statusCode = statusCode;
|
|
219
|
+
this.detail = detail;
|
|
220
|
+
this.name = "AccountingApiError";
|
|
221
|
+
Object.setPrototypeOf(this, _AccountingApiError.prototype);
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
var NetworkError = class _NetworkError extends Error {
|
|
225
|
+
constructor(message, cause) {
|
|
226
|
+
super(message);
|
|
227
|
+
this.cause = cause;
|
|
228
|
+
this.name = "NetworkError";
|
|
229
|
+
Object.setPrototypeOf(this, _NetworkError.prototype);
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
var ValidationError = class _ValidationError extends Error {
|
|
233
|
+
constructor(message, field) {
|
|
234
|
+
super(message);
|
|
235
|
+
this.field = field;
|
|
236
|
+
this.name = "ValidationError";
|
|
237
|
+
Object.setPrototypeOf(this, _ValidationError.prototype);
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
var HostedAuthError = class _HostedAuthError extends Error {
|
|
241
|
+
constructor(message) {
|
|
242
|
+
super(message);
|
|
243
|
+
this.name = "HostedAuthError";
|
|
244
|
+
Object.setPrototypeOf(this, _HostedAuthError.prototype);
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
var HostedAuthRequiredError = class _HostedAuthRequiredError extends HostedAuthError {
|
|
248
|
+
constructor(message = "Hosted redirect authentication is required. Start login with useHostedRedirectAuth().") {
|
|
249
|
+
super(message);
|
|
250
|
+
this.name = "HostedAuthRequiredError";
|
|
251
|
+
Object.setPrototypeOf(this, _HostedAuthRequiredError.prototype);
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
var HostedAuthStateMismatchError = class _HostedAuthStateMismatchError extends HostedAuthError {
|
|
255
|
+
constructor(message = "Hosted authentication returned an invalid state value.") {
|
|
256
|
+
super(message);
|
|
257
|
+
this.name = "HostedAuthStateMismatchError";
|
|
258
|
+
Object.setPrototypeOf(this, _HostedAuthStateMismatchError.prototype);
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
// src/sdk/client/http-client.ts
|
|
263
|
+
var HttpClient = class {
|
|
264
|
+
constructor(config) {
|
|
265
|
+
this.baseUrl = config.baseUrl.replace(/\/$/, "");
|
|
266
|
+
this.timeout = config.timeout ?? 3e4;
|
|
267
|
+
this.headers = {
|
|
268
|
+
"Content-Type": "application/json",
|
|
269
|
+
...config.headers
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
async get(path) {
|
|
273
|
+
return this.request("GET", path);
|
|
274
|
+
}
|
|
275
|
+
async post(path, body) {
|
|
276
|
+
return this.request("POST", path, body);
|
|
277
|
+
}
|
|
278
|
+
getBaseUrl() {
|
|
279
|
+
return this.baseUrl;
|
|
280
|
+
}
|
|
281
|
+
setHeader(name, value) {
|
|
282
|
+
this.headers[name] = value;
|
|
283
|
+
}
|
|
284
|
+
removeHeader(name) {
|
|
285
|
+
delete this.headers[name];
|
|
286
|
+
}
|
|
287
|
+
getHeader(name) {
|
|
288
|
+
return this.headers[name];
|
|
289
|
+
}
|
|
290
|
+
async request(method, path, body) {
|
|
291
|
+
const url = `${this.baseUrl}${path}`;
|
|
292
|
+
const controller = new AbortController();
|
|
293
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
294
|
+
try {
|
|
295
|
+
const response = await fetch(url, {
|
|
296
|
+
method,
|
|
297
|
+
headers: this.headers,
|
|
298
|
+
body: body ? JSON.stringify(body) : void 0,
|
|
299
|
+
signal: controller.signal
|
|
300
|
+
});
|
|
301
|
+
clearTimeout(timeoutId);
|
|
302
|
+
if (!response.ok) {
|
|
303
|
+
let detail;
|
|
304
|
+
try {
|
|
305
|
+
const errorBody = await response.json();
|
|
306
|
+
detail = errorBody.detail || errorBody.error_description || errorBody.message;
|
|
307
|
+
} catch {
|
|
308
|
+
detail = await response.text().catch(() => void 0);
|
|
309
|
+
}
|
|
310
|
+
throw new AccountingApiError(
|
|
311
|
+
`API request failed: ${response.status} ${response.statusText}`,
|
|
312
|
+
response.status,
|
|
313
|
+
detail
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
return response.json();
|
|
317
|
+
} catch (error) {
|
|
318
|
+
clearTimeout(timeoutId);
|
|
319
|
+
if (error instanceof AccountingApiError) {
|
|
320
|
+
throw error;
|
|
321
|
+
}
|
|
322
|
+
if (error instanceof Error) {
|
|
323
|
+
if (error.name === "AbortError") {
|
|
324
|
+
throw new NetworkError(`Request timeout after ${this.timeout}ms`);
|
|
325
|
+
}
|
|
326
|
+
throw new NetworkError(`Network request failed: ${error.message}`, error);
|
|
327
|
+
}
|
|
328
|
+
throw new NetworkError("Unknown network error occurred");
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
// src/sdk/client/privana-client.ts
|
|
334
|
+
var PRIVATE_READ_TOKEN_HEADER = "X-SIWE-Token";
|
|
335
|
+
var MAX_BATCH_BALANCE_TOKEN_IDS = 100;
|
|
336
|
+
var MAX_HISTORY_PAGE_SIZE = 100;
|
|
337
|
+
var PrivanaClient = class {
|
|
338
|
+
constructor(config) {
|
|
339
|
+
this.http = new HttpClient(config);
|
|
340
|
+
}
|
|
341
|
+
getBaseUrl() {
|
|
342
|
+
return this.http.getBaseUrl();
|
|
343
|
+
}
|
|
344
|
+
async getDepositAddress(request = {}) {
|
|
345
|
+
return this.http.post("/v1/accounting/deposits/address", {
|
|
346
|
+
chain_type: request.chain_type ?? "evm",
|
|
347
|
+
version: request.version ?? 0
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
async checkDeposit(request) {
|
|
351
|
+
return this.http.post("/v1/accounting/deposits/check", {
|
|
352
|
+
chain_type: request.chain_type ?? "evm",
|
|
353
|
+
chain_id: request.chain_id,
|
|
354
|
+
tx_hash: normalizeHex(request.tx_hash),
|
|
355
|
+
amount: String(request.amount),
|
|
356
|
+
log_index: request.log_index ?? 0,
|
|
357
|
+
version: request.version ?? 0
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
async getDepositStatus(depositId) {
|
|
361
|
+
return this.http.get(`/v1/accounting/deposits/status/${depositId}`);
|
|
362
|
+
}
|
|
363
|
+
async getBalance(tokenId) {
|
|
364
|
+
const token = normalizeHex(tokenId);
|
|
365
|
+
return this.http.get(`/v1/accounting/balances/${token}`);
|
|
366
|
+
}
|
|
367
|
+
async getBatchBalances(request) {
|
|
368
|
+
if (request.token_ids.length > MAX_BATCH_BALANCE_TOKEN_IDS) {
|
|
369
|
+
throw new Error(
|
|
370
|
+
`Batch balance requests support at most ${MAX_BATCH_BALANCE_TOKEN_IDS} token IDs`
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
return this.http.post("/v1/accounting/balances/batch", {
|
|
374
|
+
token_ids: request.token_ids.map((id) => normalizeHex(id))
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
async getHistory(request = {}) {
|
|
378
|
+
const offset = request.offset ?? -1;
|
|
379
|
+
const limit = request.limit ?? 50;
|
|
380
|
+
if (!Number.isSafeInteger(offset)) {
|
|
381
|
+
throw new Error("History offset must be an integer");
|
|
382
|
+
}
|
|
383
|
+
if (!Number.isSafeInteger(limit)) {
|
|
384
|
+
throw new Error("History limit must be an integer");
|
|
385
|
+
}
|
|
386
|
+
if (limit < 0 || limit > MAX_HISTORY_PAGE_SIZE) {
|
|
387
|
+
throw new Error(`History requests support between 0 and ${MAX_HISTORY_PAGE_SIZE} entries`);
|
|
388
|
+
}
|
|
389
|
+
const params = new URLSearchParams({
|
|
390
|
+
offset: String(offset),
|
|
391
|
+
limit: String(limit)
|
|
392
|
+
});
|
|
393
|
+
return this.http.get(`/v1/accounting/history?${params.toString()}`);
|
|
394
|
+
}
|
|
395
|
+
async listTokens() {
|
|
396
|
+
return this.http.get("/v1/accounting/tokens");
|
|
397
|
+
}
|
|
398
|
+
async getTokenInfo(tokenId) {
|
|
399
|
+
const token = normalizeHex(tokenId);
|
|
400
|
+
return this.http.get(`/v1/accounting/tokens/${token}`);
|
|
401
|
+
}
|
|
402
|
+
async lockFunds(request) {
|
|
403
|
+
return this.http.post("/v1/accounting/funds/lock", {
|
|
404
|
+
service_address: normalizeAddress(request.service_address),
|
|
405
|
+
token_id: normalizeHex(request.token_id),
|
|
406
|
+
amount: String(request.amount),
|
|
407
|
+
expiry: String(request.expiry),
|
|
408
|
+
nonce: String(request.nonce),
|
|
409
|
+
signature: normalizeHex(request.signature)
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
async modifyLock(request) {
|
|
413
|
+
return this.http.post("/v1/accounting/funds/modify-lock", {
|
|
414
|
+
lock_id: request.lock_id,
|
|
415
|
+
amount: String(request.amount),
|
|
416
|
+
new_expiry: String(request.new_expiry),
|
|
417
|
+
nonce: String(request.nonce),
|
|
418
|
+
signature: normalizeHex(request.signature)
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
async unlockFunds(request) {
|
|
422
|
+
return this.http.post("/v1/accounting/funds/unlock", {
|
|
423
|
+
user_address: normalizeAddress(request.user_address),
|
|
424
|
+
lock_id: request.lock_id
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
async unlockAllExpired(request) {
|
|
428
|
+
return this.http.post(
|
|
429
|
+
"/v1/accounting/funds/unlock-all-expired",
|
|
430
|
+
{
|
|
431
|
+
user_address: normalizeAddress(request.user_address)
|
|
432
|
+
}
|
|
433
|
+
);
|
|
434
|
+
}
|
|
435
|
+
async getLockedFunds(serviceAddress) {
|
|
436
|
+
const queryParams = serviceAddress ? `?service_address=${normalizeAddress(serviceAddress)}` : "";
|
|
437
|
+
return this.http.get(`/v1/accounting/funds/locked${queryParams}`);
|
|
438
|
+
}
|
|
439
|
+
async getTotalLockedBalance(tokenId) {
|
|
440
|
+
const token = normalizeHex(tokenId);
|
|
441
|
+
return this.http.get(`/v1/accounting/funds/locked/total/${token}`);
|
|
442
|
+
}
|
|
443
|
+
async getExpiredLocks() {
|
|
444
|
+
return this.http.get("/v1/accounting/funds/expired");
|
|
445
|
+
}
|
|
446
|
+
async transferFunds(request) {
|
|
447
|
+
return this.http.post("/v1/accounting/funds/transfer", {
|
|
448
|
+
to_address: normalizeAddress(request.to_address),
|
|
449
|
+
token_id: normalizeHex(request.token_id),
|
|
450
|
+
amount: String(request.amount),
|
|
451
|
+
nonce: String(request.nonce),
|
|
452
|
+
signature: normalizeHex(request.signature)
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
async getTransferNonce(userAddress) {
|
|
456
|
+
const user = normalizeAddress(userAddress);
|
|
457
|
+
return this.http.get(`/v1/accounting/funds/transfer/nonce/${user}`);
|
|
458
|
+
}
|
|
459
|
+
async getLockNonce(userAddress) {
|
|
460
|
+
const user = normalizeAddress(userAddress);
|
|
461
|
+
return this.http.get(`/v1/accounting/funds/lock/nonce/${user}`);
|
|
462
|
+
}
|
|
463
|
+
async getModifyLockNonce(userAddress) {
|
|
464
|
+
const user = normalizeAddress(userAddress);
|
|
465
|
+
return this.http.get(`/v1/accounting/funds/modify-lock/nonce/${user}`);
|
|
466
|
+
}
|
|
467
|
+
async transferLockedFunds(request) {
|
|
468
|
+
return this.http.post("/v1/accounting/funds/transfer-locked", {
|
|
469
|
+
user_address: normalizeAddress(request.user_address),
|
|
470
|
+
lock_id: request.lock_id,
|
|
471
|
+
to_address: normalizeAddress(request.to_address),
|
|
472
|
+
amount: String(request.amount),
|
|
473
|
+
service_address: normalizeAddress(request.service_address),
|
|
474
|
+
nonce: String(request.nonce),
|
|
475
|
+
signature: normalizeHex(request.signature)
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
async withdrawFromLock(request) {
|
|
479
|
+
return this.http.post(
|
|
480
|
+
"/v1/accounting/funds/withdraw-from-lock",
|
|
481
|
+
{
|
|
482
|
+
to_address: normalizeAddress(request.to_address),
|
|
483
|
+
lock_id: request.lock_id,
|
|
484
|
+
amount: String(request.amount),
|
|
485
|
+
nonce: String(request.nonce),
|
|
486
|
+
signature: normalizeHex(request.signature)
|
|
487
|
+
}
|
|
488
|
+
);
|
|
489
|
+
}
|
|
490
|
+
async requestWithdrawal(request) {
|
|
491
|
+
return this.http.post("/v1/accounting/withdraw", {
|
|
492
|
+
token_id: normalizeHex(request.token_id),
|
|
493
|
+
amount: String(request.amount),
|
|
494
|
+
nonce: String(request.nonce),
|
|
495
|
+
signature: normalizeHex(request.signature)
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
async getWithdrawalNonce(userAddress) {
|
|
499
|
+
const user = normalizeAddress(userAddress);
|
|
500
|
+
return this.http.get(`/v1/accounting/withdraw/nonce/${user}`);
|
|
501
|
+
}
|
|
502
|
+
async getTransferLockedNonce(serviceAddress) {
|
|
503
|
+
const service = normalizeAddress(serviceAddress);
|
|
504
|
+
return this.http.get(
|
|
505
|
+
`/v1/accounting/funds/transfer-locked/nonce/${service}`
|
|
506
|
+
);
|
|
507
|
+
}
|
|
508
|
+
async getPendingWithdrawals(userAddress) {
|
|
509
|
+
const user = normalizeAddress(userAddress);
|
|
510
|
+
return this.http.get(`/v1/accounting/withdraw/pending/${user}`);
|
|
511
|
+
}
|
|
512
|
+
async getWithdrawalInfo(index) {
|
|
513
|
+
return this.http.get(`/v1/accounting/withdraw/${index}`);
|
|
514
|
+
}
|
|
515
|
+
async getSiweDomain() {
|
|
516
|
+
return this.http.get("/v1/accounting/auth/domain");
|
|
517
|
+
}
|
|
518
|
+
async getSiweNonce(userAddress) {
|
|
519
|
+
const user = normalizeAddress(userAddress);
|
|
520
|
+
return this.http.get(`/v1/accounting/auth/nonce?address=${user}`);
|
|
521
|
+
}
|
|
522
|
+
async loginWithSiwe(request) {
|
|
523
|
+
return this.http.post("/v1/accounting/auth/login", {
|
|
524
|
+
siwe_message: request.siwe_message,
|
|
525
|
+
signature: normalizeHex(request.signature)
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
getHostedAuthAuthorizeUrl(request) {
|
|
529
|
+
const url = new URL(
|
|
530
|
+
"v1/accounting/auth/authorize",
|
|
531
|
+
`${this.http.getBaseUrl().replace(/\/$/, "")}/`
|
|
532
|
+
);
|
|
533
|
+
url.searchParams.set("client_id", request.client_id);
|
|
534
|
+
url.searchParams.set("redirect_uri", request.redirect_uri);
|
|
535
|
+
url.searchParams.set("code_challenge", request.code_challenge);
|
|
536
|
+
url.searchParams.set("state", request.state);
|
|
537
|
+
url.searchParams.set("chain_id", String(request.chain_id));
|
|
538
|
+
url.searchParams.set("response_mode", request.response_mode ?? "redirect");
|
|
539
|
+
url.searchParams.set("code_challenge_method", request.code_challenge_method ?? "S256");
|
|
540
|
+
return url.toString();
|
|
541
|
+
}
|
|
542
|
+
async exchangeHostedAuthCode(request) {
|
|
543
|
+
return this.http.post("/v1/accounting/auth/token", {
|
|
544
|
+
grant_type: request.grant_type ?? "authorization_code",
|
|
545
|
+
code: request.code,
|
|
546
|
+
code_verifier: request.code_verifier,
|
|
547
|
+
client_id: request.client_id,
|
|
548
|
+
redirect_uri: request.redirect_uri
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
async refreshJwtSession(request) {
|
|
552
|
+
return this.http.post("/v1/accounting/auth/jwt/refresh", {
|
|
553
|
+
refresh_token: request.refresh_token
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
async logoutJwtSession(request = {}) {
|
|
557
|
+
return this.http.post("/v1/accounting/auth/jwt/logout", {
|
|
558
|
+
refresh_token: request.refresh_token,
|
|
559
|
+
revoke_all: request.revoke_all ?? false
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
async signOnRampUrl(request) {
|
|
563
|
+
return this.http.post("/v1/accounting/onramp/sign-url", {
|
|
564
|
+
url: request.url
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
async createOnRampIntent(request) {
|
|
568
|
+
return this.http.post("/v1/accounting/onramp/intent", {
|
|
569
|
+
wallet_address: request.wallet_address ? normalizeAddress(request.wallet_address) : void 0,
|
|
570
|
+
token_id: normalizeHex(request.token_id),
|
|
571
|
+
chain_id: request.chain_id,
|
|
572
|
+
moonpay_currency_code: request.moonpay_currency_code,
|
|
573
|
+
base_currency_code: request.base_currency_code,
|
|
574
|
+
base_currency_amount: request.base_currency_amount
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
async updateOnRamp(transactionId, request) {
|
|
578
|
+
return this.http.post(
|
|
579
|
+
`/v1/accounting/onramp/${encodeURIComponent(transactionId)}`,
|
|
580
|
+
{
|
|
581
|
+
wallet_address: request.wallet_address ? normalizeAddress(request.wallet_address) : void 0,
|
|
582
|
+
token_id: request.token_id ? normalizeHex(request.token_id) : void 0,
|
|
583
|
+
chain_id: request.chain_id,
|
|
584
|
+
moonpay_transaction_id: request.moonpay_transaction_id,
|
|
585
|
+
base_currency_code: request.base_currency_code,
|
|
586
|
+
base_currency_amount: request.base_currency_amount,
|
|
587
|
+
quote_currency_amount: request.quote_currency_amount,
|
|
588
|
+
on_chain_tx_hash: request.on_chain_tx_hash ? normalizeHex(request.on_chain_tx_hash) : void 0,
|
|
589
|
+
deposit_tx_hash: request.deposit_tx_hash ? normalizeHex(request.deposit_tx_hash) : void 0
|
|
590
|
+
}
|
|
591
|
+
);
|
|
592
|
+
}
|
|
593
|
+
async getPendingOnRamps() {
|
|
594
|
+
return this.http.get("/v1/accounting/onramp/pending");
|
|
595
|
+
}
|
|
596
|
+
setPrivateReadToken(token) {
|
|
597
|
+
this.http.removeHeader("Authorization");
|
|
598
|
+
this.http.setHeader(PRIVATE_READ_TOKEN_HEADER, token);
|
|
599
|
+
}
|
|
600
|
+
getPrivateReadToken() {
|
|
601
|
+
return this.http.getHeader(PRIVATE_READ_TOKEN_HEADER);
|
|
602
|
+
}
|
|
603
|
+
clearPrivateReadToken() {
|
|
604
|
+
this.http.removeHeader(PRIVATE_READ_TOKEN_HEADER);
|
|
605
|
+
}
|
|
606
|
+
setBearerToken(token) {
|
|
607
|
+
this.http.removeHeader(PRIVATE_READ_TOKEN_HEADER);
|
|
608
|
+
this.http.setHeader("Authorization", `Bearer ${token}`);
|
|
609
|
+
}
|
|
610
|
+
clearBearerToken() {
|
|
611
|
+
this.http.removeHeader("Authorization");
|
|
612
|
+
}
|
|
613
|
+
};
|
|
614
|
+
var defaultResult = {
|
|
615
|
+
address: void 0,
|
|
616
|
+
isConnected: false,
|
|
617
|
+
status: "disconnected"
|
|
618
|
+
};
|
|
619
|
+
function useSafeAccount() {
|
|
620
|
+
const context = react.useContext(wagmi.WagmiContext);
|
|
621
|
+
const cacheRef = react.useRef(defaultResult);
|
|
622
|
+
const subscribe = react.useCallback(
|
|
623
|
+
(onChange) => {
|
|
624
|
+
if (!context) return () => {
|
|
625
|
+
};
|
|
626
|
+
return actions.watchAccount(context, { onChange });
|
|
627
|
+
},
|
|
628
|
+
[context]
|
|
629
|
+
);
|
|
630
|
+
const getSnapshot = react.useCallback(() => {
|
|
631
|
+
if (!context) return defaultResult;
|
|
632
|
+
const account = actions.getAccount(context);
|
|
633
|
+
if (cacheRef.current.address !== account.address || cacheRef.current.isConnected !== account.isConnected || cacheRef.current.status !== account.status) {
|
|
634
|
+
cacheRef.current = {
|
|
635
|
+
address: account.address,
|
|
636
|
+
isConnected: account.isConnected,
|
|
637
|
+
status: account.status
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
return cacheRef.current;
|
|
641
|
+
}, [context]);
|
|
642
|
+
const getServerSnapshot = react.useCallback(() => defaultResult, []);
|
|
643
|
+
return react.useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
// src/sdk/hooks/private-read-token-store.ts
|
|
647
|
+
var AUTH_CLOCK_SKEW_MS = 3e4;
|
|
648
|
+
var cache = /* @__PURE__ */ new Map();
|
|
649
|
+
function createScopeKey(apiUrl, chainId, address) {
|
|
650
|
+
return `${apiUrl.replace(/\/$/, "")}:${chainId}:${address.toLowerCase()}`;
|
|
651
|
+
}
|
|
652
|
+
function getCachedPrivateReadToken(scopeKey) {
|
|
653
|
+
const cached = cache.get(scopeKey);
|
|
654
|
+
if (!cached) return null;
|
|
655
|
+
if (cached.expiresAt <= Date.now() + AUTH_CLOCK_SKEW_MS) {
|
|
656
|
+
cache.delete(scopeKey);
|
|
657
|
+
return null;
|
|
658
|
+
}
|
|
659
|
+
return cached.token;
|
|
660
|
+
}
|
|
661
|
+
function setCachedPrivateReadToken(scopeKey, token, expiresAt) {
|
|
662
|
+
cache.set(scopeKey, { token, expiresAt });
|
|
663
|
+
}
|
|
664
|
+
function deleteCachedPrivateReadToken(scopeKey) {
|
|
665
|
+
cache.delete(scopeKey);
|
|
666
|
+
}
|
|
667
|
+
var DEFAULT_SIWE_VALIDITY_MS = 24 * 60 * 60 * 1e3;
|
|
668
|
+
var DEFAULT_STATEMENT = "Sign in to access your private account data.";
|
|
669
|
+
var AUTH_REFRESH_SKEW_MS = 3e4;
|
|
670
|
+
var SiweAuthContext = react.createContext(null);
|
|
671
|
+
function SiweAuthProvider({
|
|
672
|
+
children,
|
|
673
|
+
client,
|
|
674
|
+
networkConfig,
|
|
675
|
+
autoLogin = true,
|
|
676
|
+
statement
|
|
677
|
+
}) {
|
|
678
|
+
const wagmiContext = react.useContext(wagmi.WagmiContext);
|
|
679
|
+
const { address, isConnected, status } = useSafeAccount();
|
|
680
|
+
const [session, setSession] = react.useState(null);
|
|
681
|
+
const [tokens, setTokens] = react.useState(null);
|
|
682
|
+
const [isLoading, setIsLoading] = react.useState(false);
|
|
683
|
+
const [error, setError] = react.useState(null);
|
|
684
|
+
const [accessTokenExpiresAt, setAccessTokenExpiresAt] = react.useState(null);
|
|
685
|
+
const loginInFlight = react.useRef(false);
|
|
686
|
+
const autoAttemptedAddress = react.useRef(null);
|
|
687
|
+
const refreshInFlight = react.useRef(false);
|
|
688
|
+
const refreshDataRef = react.useRef(null);
|
|
689
|
+
const clearSession = react.useCallback(() => {
|
|
690
|
+
refreshDataRef.current = null;
|
|
691
|
+
setAccessTokenExpiresAt(null);
|
|
692
|
+
client.clearPrivateReadToken();
|
|
693
|
+
client.clearBearerToken();
|
|
694
|
+
setSession(null);
|
|
695
|
+
setTokens(null);
|
|
696
|
+
setError(null);
|
|
697
|
+
autoAttemptedAddress.current = null;
|
|
698
|
+
}, [client]);
|
|
699
|
+
const logout = react.useCallback(async () => {
|
|
700
|
+
setError(null);
|
|
701
|
+
const refreshToken = refreshDataRef.current?.refreshToken;
|
|
702
|
+
try {
|
|
703
|
+
if (refreshToken) {
|
|
704
|
+
await client.logoutJwtSession({ refresh_token: refreshToken });
|
|
705
|
+
}
|
|
706
|
+
} finally {
|
|
707
|
+
clearSession();
|
|
708
|
+
autoAttemptedAddress.current = address ?? null;
|
|
709
|
+
}
|
|
710
|
+
}, [clearSession, client, address]);
|
|
711
|
+
const login = react.useCallback(async () => {
|
|
712
|
+
if (!wagmiContext) throw new Error("WagmiProvider is required for SIWE auth");
|
|
713
|
+
if (!address) throw new Error("No wallet connected");
|
|
714
|
+
if (loginInFlight.current) return;
|
|
715
|
+
loginInFlight.current = true;
|
|
716
|
+
setIsLoading(true);
|
|
717
|
+
setError(null);
|
|
718
|
+
try {
|
|
719
|
+
const walletClient = await actions.getWalletClient(wagmiContext);
|
|
720
|
+
if (!walletClient) throw new Error("No wallet client available");
|
|
721
|
+
const [{ domain }, nonceRes] = await Promise.all([
|
|
722
|
+
client.getSiweDomain(),
|
|
723
|
+
client.getSiweNonce(address)
|
|
724
|
+
]);
|
|
725
|
+
const issuedAt = /* @__PURE__ */ new Date();
|
|
726
|
+
const expirationTime = new Date(issuedAt.getTime() + DEFAULT_SIWE_VALIDITY_MS);
|
|
727
|
+
const uri = typeof window !== "undefined" && window.location.origin ? window.location.origin : networkConfig.apiUrl;
|
|
728
|
+
const message = siwe.createSiweMessage({
|
|
729
|
+
address,
|
|
730
|
+
chainId: networkConfig.chainId,
|
|
731
|
+
domain,
|
|
732
|
+
uri,
|
|
733
|
+
version: "1",
|
|
734
|
+
nonce: nonceRes.nonce,
|
|
735
|
+
statement: statement ?? DEFAULT_STATEMENT,
|
|
736
|
+
issuedAt,
|
|
737
|
+
expirationTime
|
|
738
|
+
});
|
|
739
|
+
const signature = await walletClient.signMessage({
|
|
740
|
+
account: walletClient.account ?? address,
|
|
741
|
+
message
|
|
742
|
+
});
|
|
743
|
+
const res = await client.loginWithSiwe({ siwe_message: message, signature });
|
|
744
|
+
const loggedInAt = Date.now();
|
|
745
|
+
client.setPrivateReadToken(res.siwe_token);
|
|
746
|
+
client.setBearerToken(res.jwt_access_token);
|
|
747
|
+
refreshDataRef.current = {
|
|
748
|
+
refreshToken: res.jwt_refresh_token,
|
|
749
|
+
refreshExpiresAt: loggedInAt + res.jwt_refresh_expires_in * 1e3
|
|
750
|
+
};
|
|
751
|
+
setCachedPrivateReadToken(
|
|
752
|
+
createScopeKey(networkConfig.apiUrl, networkConfig.chainId, address),
|
|
753
|
+
res.siwe_token,
|
|
754
|
+
expirationTime.getTime()
|
|
755
|
+
);
|
|
756
|
+
setSession({ address: res.address });
|
|
757
|
+
setTokens({
|
|
758
|
+
siwe_token: res.siwe_token,
|
|
759
|
+
jwt_access_token: res.jwt_access_token,
|
|
760
|
+
jwt_refresh_token: res.jwt_refresh_token,
|
|
761
|
+
address: res.address
|
|
762
|
+
});
|
|
763
|
+
setAccessTokenExpiresAt(loggedInAt + res.jwt_expires_in * 1e3);
|
|
764
|
+
} catch (err) {
|
|
765
|
+
setError(err instanceof Error ? err : new Error("Sign-in failed"));
|
|
766
|
+
throw err;
|
|
767
|
+
} finally {
|
|
768
|
+
setIsLoading(false);
|
|
769
|
+
loginInFlight.current = false;
|
|
770
|
+
}
|
|
771
|
+
}, [wagmiContext, address, client, networkConfig.chainId, networkConfig.apiUrl, statement]);
|
|
772
|
+
const refreshAccessToken = react.useCallback(async () => {
|
|
773
|
+
const data = refreshDataRef.current;
|
|
774
|
+
if (!data || refreshInFlight.current) return;
|
|
775
|
+
if (Date.now() >= data.refreshExpiresAt - AUTH_REFRESH_SKEW_MS) {
|
|
776
|
+
clearSession();
|
|
777
|
+
return;
|
|
778
|
+
}
|
|
779
|
+
refreshInFlight.current = true;
|
|
780
|
+
try {
|
|
781
|
+
const res = await client.refreshJwtSession({ refresh_token: data.refreshToken });
|
|
782
|
+
const refreshedAt = Date.now();
|
|
783
|
+
client.setBearerToken(res.token);
|
|
784
|
+
refreshDataRef.current = {
|
|
785
|
+
refreshToken: res.refresh_token,
|
|
786
|
+
refreshExpiresAt: refreshedAt + res.refresh_expires_in * 1e3
|
|
787
|
+
};
|
|
788
|
+
setTokens(
|
|
789
|
+
(prev) => prev ? { ...prev, jwt_access_token: res.token, jwt_refresh_token: res.refresh_token } : prev
|
|
790
|
+
);
|
|
791
|
+
setAccessTokenExpiresAt(refreshedAt + res.expires_in * 1e3);
|
|
792
|
+
} catch {
|
|
793
|
+
clearSession();
|
|
794
|
+
} finally {
|
|
795
|
+
refreshInFlight.current = false;
|
|
796
|
+
}
|
|
797
|
+
}, [client, clearSession]);
|
|
798
|
+
react.useEffect(() => {
|
|
799
|
+
if (accessTokenExpiresAt == null) return;
|
|
800
|
+
const delay = Math.max(accessTokenExpiresAt - AUTH_REFRESH_SKEW_MS - Date.now(), 0);
|
|
801
|
+
const timer = setTimeout(() => {
|
|
802
|
+
void refreshAccessToken();
|
|
803
|
+
}, delay);
|
|
804
|
+
return () => clearTimeout(timer);
|
|
805
|
+
}, [accessTokenExpiresAt, refreshAccessToken]);
|
|
806
|
+
react.useEffect(() => {
|
|
807
|
+
if (!autoLogin) return;
|
|
808
|
+
if (status === "connecting" || status === "reconnecting") return;
|
|
809
|
+
if (!isConnected && session) {
|
|
810
|
+
clearSession();
|
|
811
|
+
return;
|
|
812
|
+
}
|
|
813
|
+
if (isConnected && address && session && address.toLowerCase() !== session.address.toLowerCase()) {
|
|
814
|
+
clearSession();
|
|
815
|
+
return;
|
|
816
|
+
}
|
|
817
|
+
if (isConnected && address && !session && !isLoading && autoAttemptedAddress.current !== address) {
|
|
818
|
+
autoAttemptedAddress.current = address;
|
|
819
|
+
void login().catch(() => {
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
}, [autoLogin, status, isConnected, address, session, isLoading, login, clearSession]);
|
|
823
|
+
const value = react.useMemo(
|
|
824
|
+
() => ({
|
|
825
|
+
isAuthenticated: !!session,
|
|
826
|
+
isLoading,
|
|
827
|
+
error,
|
|
828
|
+
session,
|
|
829
|
+
accessToken: tokens?.jwt_access_token,
|
|
830
|
+
tokens,
|
|
831
|
+
login,
|
|
832
|
+
logout
|
|
833
|
+
}),
|
|
834
|
+
[session, isLoading, error, tokens, login, logout]
|
|
835
|
+
);
|
|
836
|
+
return /* @__PURE__ */ jsxRuntime.jsx(SiweAuthContext.Provider, { value, children });
|
|
837
|
+
}
|
|
838
|
+
function useSiweAuth() {
|
|
839
|
+
const ctx = react.useContext(SiweAuthContext);
|
|
840
|
+
if (!ctx) throw new Error("useSiweAuth must be used within SiweAuthProvider");
|
|
841
|
+
return ctx;
|
|
842
|
+
}
|
|
843
|
+
var PrivanaContext = react.createContext(null);
|
|
844
|
+
function readStoredHostedAuthSession(storage, hostedAuthStorageKey, now = Date.now()) {
|
|
845
|
+
const raw = storage.getItem(hostedAuthStorageKey);
|
|
846
|
+
if (!raw) {
|
|
847
|
+
return null;
|
|
848
|
+
}
|
|
849
|
+
try {
|
|
850
|
+
const parsed = JSON.parse(raw);
|
|
851
|
+
if (!isHostedAuthRefreshActive(parsed, now, 0)) {
|
|
852
|
+
storage.removeItem(hostedAuthStorageKey);
|
|
853
|
+
return null;
|
|
854
|
+
}
|
|
855
|
+
return parsed;
|
|
856
|
+
} catch {
|
|
857
|
+
storage.removeItem(hostedAuthStorageKey);
|
|
858
|
+
return null;
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
function syncHostedAuthSessionToClient(client, hostedAuthConfig, hostedAuthSession) {
|
|
862
|
+
if (!hostedAuthConfig) {
|
|
863
|
+
client.clearBearerToken();
|
|
864
|
+
client.clearPrivateReadToken();
|
|
865
|
+
return;
|
|
866
|
+
}
|
|
867
|
+
if (hostedAuthSession && isHostedAuthSessionActive(hostedAuthSession)) {
|
|
868
|
+
client.setBearerToken(hostedAuthSession.accessToken);
|
|
869
|
+
client.clearPrivateReadToken();
|
|
870
|
+
return;
|
|
871
|
+
}
|
|
872
|
+
client.clearBearerToken();
|
|
873
|
+
client.clearPrivateReadToken();
|
|
874
|
+
}
|
|
875
|
+
var DEFAULT_NETWORK_CONFIG = NETWORK_CONFIG.testnet;
|
|
876
|
+
function PrivanaProvider({
|
|
877
|
+
children,
|
|
878
|
+
networkConfig: networkConfigOverride,
|
|
879
|
+
tokens,
|
|
880
|
+
chains,
|
|
881
|
+
pollingInterval = 1e4,
|
|
882
|
+
serviceAddress,
|
|
883
|
+
hostedAuth,
|
|
884
|
+
siweAuth
|
|
885
|
+
}) {
|
|
886
|
+
if (hostedAuth && siweAuth) {
|
|
887
|
+
throw new Error(
|
|
888
|
+
"PrivanaProvider: `hostedAuth` and `siweAuth` are mutually exclusive - provide only one. When both are set, private reads use hosted auth and the in-app SIWE login is ignored."
|
|
889
|
+
);
|
|
890
|
+
}
|
|
891
|
+
const networkConfig = react.useMemo(() => {
|
|
892
|
+
const config = {
|
|
893
|
+
...DEFAULT_NETWORK_CONFIG,
|
|
894
|
+
...networkConfigOverride
|
|
895
|
+
};
|
|
896
|
+
if (!config.chainId || config.chainId <= 0) {
|
|
897
|
+
throw new Error("PrivanaProvider: networkConfig.chainId must be a positive number");
|
|
898
|
+
}
|
|
899
|
+
if (!config.accountingContract || !config.accountingContract.startsWith("0x")) {
|
|
900
|
+
throw new Error("PrivanaProvider: networkConfig.accountingContract must be a valid address");
|
|
901
|
+
}
|
|
902
|
+
if (!config.apiUrl) {
|
|
903
|
+
throw new Error("PrivanaProvider: networkConfig.apiUrl must be provided");
|
|
904
|
+
}
|
|
905
|
+
return config;
|
|
906
|
+
}, [
|
|
907
|
+
networkConfigOverride?.chainId,
|
|
908
|
+
networkConfigOverride?.name,
|
|
909
|
+
networkConfigOverride?.accountingContract,
|
|
910
|
+
networkConfigOverride?.apiUrl
|
|
911
|
+
]);
|
|
912
|
+
const resolvedChains = react.useMemo(() => {
|
|
913
|
+
if (chains && chains.length > 0) return chains;
|
|
914
|
+
return SUPPORTED_CHAINS;
|
|
915
|
+
}, [chains]);
|
|
916
|
+
const client = react.useMemo(
|
|
917
|
+
() => new PrivanaClient({ baseUrl: networkConfig.apiUrl }),
|
|
918
|
+
[networkConfig.apiUrl]
|
|
919
|
+
);
|
|
920
|
+
const [allTokens, setAllTokens] = react.useState([]);
|
|
921
|
+
const [tokensStatus, setTokensStatus] = react.useState("loading");
|
|
922
|
+
const [tokensError, setTokensError] = react.useState();
|
|
923
|
+
react.useEffect(() => {
|
|
924
|
+
setTokensStatus("loading");
|
|
925
|
+
setTokensError(void 0);
|
|
926
|
+
client.listTokens().then(({ tokens: list }) => {
|
|
927
|
+
setAllTokens(
|
|
928
|
+
list.map((t) => ({
|
|
929
|
+
id: t.token_id,
|
|
930
|
+
symbol: t.symbol,
|
|
931
|
+
decimals: t.decimals,
|
|
932
|
+
contract: t.token_address ?? viem.zeroAddress,
|
|
933
|
+
name: t.name,
|
|
934
|
+
chainId: t.chain_id
|
|
935
|
+
}))
|
|
936
|
+
);
|
|
937
|
+
setTokensStatus("ready");
|
|
938
|
+
}).catch((err) => {
|
|
939
|
+
setTokensError(err instanceof Error ? err : new Error(String(err)));
|
|
940
|
+
setTokensStatus("error");
|
|
941
|
+
});
|
|
942
|
+
}, [client]);
|
|
943
|
+
const enabledTokens = react.useMemo(() => {
|
|
944
|
+
if (tokens && tokens.length > 0) {
|
|
945
|
+
const allowed = new Set(tokens.map((id) => id.toLowerCase()));
|
|
946
|
+
return allTokens.filter((t) => allowed.has(t.id.toLowerCase()));
|
|
947
|
+
}
|
|
948
|
+
return allTokens;
|
|
949
|
+
}, [allTokens, tokens]);
|
|
950
|
+
const tokenById = react.useMemo(
|
|
951
|
+
() => Object.fromEntries(enabledTokens.map((t) => [t.id.toLowerCase(), t])),
|
|
952
|
+
[enabledTokens]
|
|
953
|
+
);
|
|
954
|
+
const getTokenById = react.useMemo(() => (id) => tokenById[id.toLowerCase()], [tokenById]);
|
|
955
|
+
const chainById = react.useMemo(
|
|
956
|
+
() => Object.fromEntries(resolvedChains.map((c) => [c.id, c])),
|
|
957
|
+
[resolvedChains]
|
|
958
|
+
);
|
|
959
|
+
const getChainById2 = react.useMemo(() => (id) => chainById[id], [chainById]);
|
|
960
|
+
const hostedAuthConfig = react.useMemo(() => {
|
|
961
|
+
if (!hostedAuth) return null;
|
|
962
|
+
const clientId = hostedAuth.clientId.trim();
|
|
963
|
+
const redirectUri = hostedAuth.redirectUri.trim();
|
|
964
|
+
if (!clientId) {
|
|
965
|
+
throw new Error(
|
|
966
|
+
"PrivanaProvider: hostedAuth.clientId must be provided when hostedAuth is enabled"
|
|
967
|
+
);
|
|
968
|
+
}
|
|
969
|
+
if (!redirectUri) {
|
|
970
|
+
throw new Error(
|
|
971
|
+
"PrivanaProvider: hostedAuth.redirectUri must be provided when hostedAuth is enabled"
|
|
972
|
+
);
|
|
973
|
+
}
|
|
974
|
+
return {
|
|
975
|
+
clientId,
|
|
976
|
+
redirectUri
|
|
977
|
+
};
|
|
978
|
+
}, [hostedAuth]);
|
|
979
|
+
const hostedAuthStorageKey = react.useMemo(
|
|
980
|
+
() => hostedAuthConfig ? createHostedAuthStorageKey(networkConfig.apiUrl, hostedAuthConfig) : null,
|
|
981
|
+
[hostedAuthConfig, networkConfig.apiUrl]
|
|
982
|
+
);
|
|
983
|
+
const [hostedAuthSession, setHostedAuthSessionState] = react.useState(null);
|
|
984
|
+
const hostedAuthSessionRef = react.useRef(null);
|
|
985
|
+
const hostedAuthStateVersionRef = react.useRef(0);
|
|
986
|
+
const hostedAuthRefreshInflight = react.useRef(null);
|
|
987
|
+
const clearHostedAuthSession = react.useCallback(() => {
|
|
988
|
+
hostedAuthStateVersionRef.current += 1;
|
|
989
|
+
hostedAuthSessionRef.current = null;
|
|
990
|
+
hostedAuthRefreshInflight.current = null;
|
|
991
|
+
setHostedAuthSessionState(null);
|
|
992
|
+
client.clearBearerToken();
|
|
993
|
+
client.clearPrivateReadToken();
|
|
994
|
+
if (hostedAuthStorageKey && typeof window !== "undefined") {
|
|
995
|
+
window.sessionStorage.removeItem(hostedAuthStorageKey);
|
|
996
|
+
}
|
|
997
|
+
}, [client, hostedAuthStorageKey]);
|
|
998
|
+
const setHostedAuthSession = react.useCallback(
|
|
999
|
+
(session) => {
|
|
1000
|
+
if (!session) {
|
|
1001
|
+
clearHostedAuthSession();
|
|
1002
|
+
return;
|
|
1003
|
+
}
|
|
1004
|
+
hostedAuthStateVersionRef.current += 1;
|
|
1005
|
+
hostedAuthSessionRef.current = session;
|
|
1006
|
+
setHostedAuthSessionState(session);
|
|
1007
|
+
if (isHostedAuthSessionActive(session)) {
|
|
1008
|
+
client.setBearerToken(session.accessToken);
|
|
1009
|
+
} else {
|
|
1010
|
+
client.clearBearerToken();
|
|
1011
|
+
}
|
|
1012
|
+
client.clearPrivateReadToken();
|
|
1013
|
+
if (hostedAuthStorageKey && typeof window !== "undefined") {
|
|
1014
|
+
window.sessionStorage.setItem(hostedAuthStorageKey, JSON.stringify(session));
|
|
1015
|
+
}
|
|
1016
|
+
},
|
|
1017
|
+
[clearHostedAuthSession, client, hostedAuthStorageKey]
|
|
1018
|
+
);
|
|
1019
|
+
const refreshHostedAuthSession = react.useCallback(async () => {
|
|
1020
|
+
if (!hostedAuthConfig) {
|
|
1021
|
+
throw new HostedAuthRequiredError(
|
|
1022
|
+
"Hosted redirect authentication is not configured for this provider."
|
|
1023
|
+
);
|
|
1024
|
+
}
|
|
1025
|
+
const currentSession = hostedAuthSessionRef.current;
|
|
1026
|
+
if (!currentSession) {
|
|
1027
|
+
throw new HostedAuthRequiredError();
|
|
1028
|
+
}
|
|
1029
|
+
if (!isHostedAuthRefreshActive(currentSession)) {
|
|
1030
|
+
clearHostedAuthSession();
|
|
1031
|
+
throw new HostedAuthRequiredError(
|
|
1032
|
+
"Hosted redirect authentication has expired. Start login again."
|
|
1033
|
+
);
|
|
1034
|
+
}
|
|
1035
|
+
if (hostedAuthRefreshInflight.current) {
|
|
1036
|
+
return hostedAuthRefreshInflight.current;
|
|
1037
|
+
}
|
|
1038
|
+
const refreshPromise = (async () => {
|
|
1039
|
+
const refreshVersion = hostedAuthStateVersionRef.current;
|
|
1040
|
+
try {
|
|
1041
|
+
const response = await client.refreshJwtSession({
|
|
1042
|
+
refresh_token: currentSession.refreshToken
|
|
1043
|
+
});
|
|
1044
|
+
if (refreshVersion !== hostedAuthStateVersionRef.current) {
|
|
1045
|
+
const latestSession = hostedAuthSessionRef.current;
|
|
1046
|
+
if (latestSession) {
|
|
1047
|
+
return latestSession;
|
|
1048
|
+
}
|
|
1049
|
+
throw new HostedAuthRequiredError(
|
|
1050
|
+
"Hosted redirect authentication has changed. Start login again."
|
|
1051
|
+
);
|
|
1052
|
+
}
|
|
1053
|
+
const nextSession = applyRefreshResponse(currentSession, response);
|
|
1054
|
+
setHostedAuthSession(nextSession);
|
|
1055
|
+
return nextSession;
|
|
1056
|
+
} catch (error) {
|
|
1057
|
+
if (refreshVersion === hostedAuthStateVersionRef.current) {
|
|
1058
|
+
clearHostedAuthSession();
|
|
1059
|
+
}
|
|
1060
|
+
throw error;
|
|
1061
|
+
} finally {
|
|
1062
|
+
hostedAuthRefreshInflight.current = null;
|
|
1063
|
+
}
|
|
1064
|
+
})();
|
|
1065
|
+
hostedAuthRefreshInflight.current = refreshPromise;
|
|
1066
|
+
return refreshPromise;
|
|
1067
|
+
}, [clearHostedAuthSession, client, hostedAuthConfig, setHostedAuthSession]);
|
|
1068
|
+
react.useEffect(() => {
|
|
1069
|
+
hostedAuthSessionRef.current = hostedAuthSession;
|
|
1070
|
+
}, [hostedAuthSession]);
|
|
1071
|
+
react.useEffect(() => {
|
|
1072
|
+
if (!hostedAuthStorageKey || typeof window === "undefined") {
|
|
1073
|
+
hostedAuthStateVersionRef.current += 1;
|
|
1074
|
+
hostedAuthSessionRef.current = null;
|
|
1075
|
+
hostedAuthRefreshInflight.current = null;
|
|
1076
|
+
setHostedAuthSessionState(null);
|
|
1077
|
+
return;
|
|
1078
|
+
}
|
|
1079
|
+
const restoredSession = readStoredHostedAuthSession(window.sessionStorage, hostedAuthStorageKey);
|
|
1080
|
+
hostedAuthStateVersionRef.current += 1;
|
|
1081
|
+
hostedAuthSessionRef.current = restoredSession;
|
|
1082
|
+
hostedAuthRefreshInflight.current = null;
|
|
1083
|
+
setHostedAuthSessionState(restoredSession);
|
|
1084
|
+
}, [hostedAuthStorageKey]);
|
|
1085
|
+
react.useEffect(() => {
|
|
1086
|
+
syncHostedAuthSessionToClient(client, hostedAuthConfig, hostedAuthSession);
|
|
1087
|
+
}, [client, hostedAuthConfig, hostedAuthSession]);
|
|
1088
|
+
const value = react.useMemo(
|
|
1089
|
+
() => ({
|
|
1090
|
+
client,
|
|
1091
|
+
networkConfig,
|
|
1092
|
+
enabledTokens,
|
|
1093
|
+
defaultToken: enabledTokens[0],
|
|
1094
|
+
getTokenById,
|
|
1095
|
+
getChainById: getChainById2,
|
|
1096
|
+
chains: resolvedChains,
|
|
1097
|
+
tokensStatus,
|
|
1098
|
+
tokensError,
|
|
1099
|
+
pollingInterval,
|
|
1100
|
+
serviceAddress,
|
|
1101
|
+
hostedAuthConfig,
|
|
1102
|
+
hostedAuthSession,
|
|
1103
|
+
setHostedAuthSession,
|
|
1104
|
+
clearHostedAuthSession,
|
|
1105
|
+
refreshHostedAuthSession
|
|
1106
|
+
}),
|
|
1107
|
+
[
|
|
1108
|
+
client,
|
|
1109
|
+
networkConfig,
|
|
1110
|
+
enabledTokens,
|
|
1111
|
+
getTokenById,
|
|
1112
|
+
getChainById2,
|
|
1113
|
+
resolvedChains,
|
|
1114
|
+
tokensStatus,
|
|
1115
|
+
tokensError,
|
|
1116
|
+
pollingInterval,
|
|
1117
|
+
serviceAddress,
|
|
1118
|
+
hostedAuthConfig,
|
|
1119
|
+
hostedAuthSession,
|
|
1120
|
+
setHostedAuthSession,
|
|
1121
|
+
clearHostedAuthSession,
|
|
1122
|
+
refreshHostedAuthSession
|
|
1123
|
+
]
|
|
1124
|
+
);
|
|
1125
|
+
return /* @__PURE__ */ jsxRuntime.jsx(PrivanaContext.Provider, { value, children: siweAuth ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1126
|
+
SiweAuthProvider,
|
|
1127
|
+
{
|
|
1128
|
+
client,
|
|
1129
|
+
networkConfig,
|
|
1130
|
+
autoLogin: siweAuth.autoLogin,
|
|
1131
|
+
statement: siweAuth.statement,
|
|
1132
|
+
children
|
|
1133
|
+
}
|
|
1134
|
+
) : children });
|
|
1135
|
+
}
|
|
1136
|
+
function usePrivanaContext() {
|
|
1137
|
+
const context = react.useContext(PrivanaContext);
|
|
1138
|
+
if (!context) {
|
|
1139
|
+
throw new Error("usePrivanaContext must be used within a PrivanaProvider");
|
|
1140
|
+
}
|
|
1141
|
+
return context;
|
|
1142
|
+
}
|
|
1143
|
+
function useSafePrivanaContext() {
|
|
1144
|
+
return react.useContext(PrivanaContext);
|
|
1145
|
+
}
|
|
1146
|
+
var INITIAL_AUTH_BACKOFF_MS = 5e3;
|
|
1147
|
+
var MAX_AUTH_BACKOFF_MS = 6e4;
|
|
1148
|
+
var DEFAULT_SIWE_AUTH_VALIDITY_MS = 24 * 60 * 60 * 1e3;
|
|
1149
|
+
var PRIVATE_READ_STATEMENT = "Sign in to Privana to access private account data.";
|
|
1150
|
+
var privateReadFailureCache = /* @__PURE__ */ new Map();
|
|
1151
|
+
var privateReadInflight = /* @__PURE__ */ new Map();
|
|
1152
|
+
async function executeHostedAuthPrivateReadRequest({
|
|
1153
|
+
client,
|
|
1154
|
+
hostedAuthSession,
|
|
1155
|
+
refreshHostedAuthSession,
|
|
1156
|
+
request
|
|
1157
|
+
}) {
|
|
1158
|
+
const ensureHostedAuth = async (forceRefresh) => {
|
|
1159
|
+
if (!hostedAuthSession) {
|
|
1160
|
+
throw new HostedAuthRequiredError();
|
|
1161
|
+
}
|
|
1162
|
+
if (!forceRefresh && isHostedAuthSessionActive(hostedAuthSession)) {
|
|
1163
|
+
client.clearPrivateReadToken();
|
|
1164
|
+
client.setBearerToken(hostedAuthSession.accessToken);
|
|
1165
|
+
return hostedAuthSession.accessToken;
|
|
1166
|
+
}
|
|
1167
|
+
const refreshed = await refreshHostedAuthSession();
|
|
1168
|
+
client.clearPrivateReadToken();
|
|
1169
|
+
client.setBearerToken(refreshed.accessToken);
|
|
1170
|
+
return refreshed.accessToken;
|
|
1171
|
+
};
|
|
1172
|
+
await ensureHostedAuth(false);
|
|
1173
|
+
try {
|
|
1174
|
+
return await request();
|
|
1175
|
+
} catch (error) {
|
|
1176
|
+
if (!(error instanceof AccountingApiError) || error.statusCode !== 401) {
|
|
1177
|
+
throw error;
|
|
1178
|
+
}
|
|
1179
|
+
await ensureHostedAuth(true);
|
|
1180
|
+
return request();
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
function clearPrivateReadScope(scopeKey, client) {
|
|
1184
|
+
deleteCachedPrivateReadToken(scopeKey);
|
|
1185
|
+
privateReadFailureCache.delete(scopeKey);
|
|
1186
|
+
client.clearPrivateReadToken();
|
|
1187
|
+
}
|
|
1188
|
+
function recordPrivateReadFailure(scopeKey) {
|
|
1189
|
+
const previous = privateReadFailureCache.get(scopeKey);
|
|
1190
|
+
const backoffMs = Math.min(
|
|
1191
|
+
previous ? previous.backoffMs * 2 : INITIAL_AUTH_BACKOFF_MS,
|
|
1192
|
+
MAX_AUTH_BACKOFF_MS
|
|
1193
|
+
);
|
|
1194
|
+
privateReadFailureCache.set(scopeKey, {
|
|
1195
|
+
backoffMs,
|
|
1196
|
+
retryAt: Date.now() + backoffMs
|
|
1197
|
+
});
|
|
1198
|
+
}
|
|
1199
|
+
function ensureFailureBackoff(scopeKey) {
|
|
1200
|
+
const failure = privateReadFailureCache.get(scopeKey);
|
|
1201
|
+
if (!failure) return;
|
|
1202
|
+
if (failure.retryAt <= Date.now()) {
|
|
1203
|
+
privateReadFailureCache.delete(scopeKey);
|
|
1204
|
+
return;
|
|
1205
|
+
}
|
|
1206
|
+
throw new Error(
|
|
1207
|
+
`Private-read authentication is temporarily paused after a recent failure. Retry in ${Math.ceil(
|
|
1208
|
+
(failure.retryAt - Date.now()) / 1e3
|
|
1209
|
+
)}s.`
|
|
1210
|
+
);
|
|
1211
|
+
}
|
|
1212
|
+
function usePrivateReadRequest() {
|
|
1213
|
+
const wagmiContext = react.useContext(wagmi.WagmiContext);
|
|
1214
|
+
const { client, networkConfig, hostedAuthConfig, hostedAuthSession, refreshHostedAuthSession } = usePrivanaContext();
|
|
1215
|
+
const { address: walletAddress } = useSafeAccount();
|
|
1216
|
+
const privateReadAddress = hostedAuthConfig ? hostedAuthSession?.address ?? null : walletAddress ?? null;
|
|
1217
|
+
const privateReadReady = hostedAuthConfig ? !!hostedAuthSession : !!walletAddress;
|
|
1218
|
+
const executePrivateRead = react.useCallback(
|
|
1219
|
+
async (request) => {
|
|
1220
|
+
if (hostedAuthConfig) {
|
|
1221
|
+
return executeHostedAuthPrivateReadRequest({
|
|
1222
|
+
client,
|
|
1223
|
+
hostedAuthSession,
|
|
1224
|
+
refreshHostedAuthSession,
|
|
1225
|
+
request
|
|
1226
|
+
});
|
|
1227
|
+
}
|
|
1228
|
+
if (!wagmiContext) {
|
|
1229
|
+
throw new Error("WagmiProvider is required for authenticated private reads");
|
|
1230
|
+
}
|
|
1231
|
+
if (!walletAddress) {
|
|
1232
|
+
throw new Error("No wallet connected");
|
|
1233
|
+
}
|
|
1234
|
+
const walletClient = await actions.getWalletClient(wagmiContext);
|
|
1235
|
+
if (!walletClient) {
|
|
1236
|
+
throw new Error("No wallet client available");
|
|
1237
|
+
}
|
|
1238
|
+
const apiUrl = networkConfig.apiUrl;
|
|
1239
|
+
const scopeKey = createScopeKey(apiUrl, networkConfig.chainId, walletAddress);
|
|
1240
|
+
const getToken = async (forceRefresh) => {
|
|
1241
|
+
const inflight = privateReadInflight.get(scopeKey);
|
|
1242
|
+
if (inflight) {
|
|
1243
|
+
const token = await inflight;
|
|
1244
|
+
client.setPrivateReadToken(token);
|
|
1245
|
+
return token;
|
|
1246
|
+
}
|
|
1247
|
+
if (!forceRefresh) {
|
|
1248
|
+
const cached = getCachedPrivateReadToken(scopeKey);
|
|
1249
|
+
if (cached) {
|
|
1250
|
+
client.setPrivateReadToken(cached);
|
|
1251
|
+
return cached;
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
ensureFailureBackoff(scopeKey);
|
|
1255
|
+
const authPromise = (async () => {
|
|
1256
|
+
try {
|
|
1257
|
+
const [{ domain }, nonceResponse] = await Promise.all([
|
|
1258
|
+
client.getSiweDomain(),
|
|
1259
|
+
client.getSiweNonce(walletAddress)
|
|
1260
|
+
]);
|
|
1261
|
+
const issuedAt = /* @__PURE__ */ new Date();
|
|
1262
|
+
const expirationTime = new Date(issuedAt.getTime() + DEFAULT_SIWE_AUTH_VALIDITY_MS);
|
|
1263
|
+
const uri = typeof window !== "undefined" && window.location.origin ? window.location.origin : apiUrl;
|
|
1264
|
+
const message = siwe.createSiweMessage({
|
|
1265
|
+
address: walletAddress,
|
|
1266
|
+
chainId: walletClient.chain?.id ?? networkConfig.chainId,
|
|
1267
|
+
domain,
|
|
1268
|
+
expirationTime,
|
|
1269
|
+
issuedAt,
|
|
1270
|
+
nonce: nonceResponse.nonce,
|
|
1271
|
+
statement: PRIVATE_READ_STATEMENT,
|
|
1272
|
+
uri,
|
|
1273
|
+
version: "1"
|
|
1274
|
+
});
|
|
1275
|
+
const signature = await walletClient.signMessage({
|
|
1276
|
+
account: walletClient.account ?? walletAddress,
|
|
1277
|
+
message
|
|
1278
|
+
});
|
|
1279
|
+
const login = await client.loginWithSiwe({
|
|
1280
|
+
siwe_message: message,
|
|
1281
|
+
signature
|
|
1282
|
+
});
|
|
1283
|
+
setCachedPrivateReadToken(scopeKey, login.siwe_token, expirationTime.getTime());
|
|
1284
|
+
privateReadFailureCache.delete(scopeKey);
|
|
1285
|
+
client.setPrivateReadToken(login.siwe_token);
|
|
1286
|
+
return login.siwe_token;
|
|
1287
|
+
} catch (error) {
|
|
1288
|
+
const authError = error instanceof Error ? error : new Error("Failed to authenticate private reads");
|
|
1289
|
+
clearPrivateReadScope(scopeKey, client);
|
|
1290
|
+
recordPrivateReadFailure(scopeKey);
|
|
1291
|
+
throw authError;
|
|
1292
|
+
} finally {
|
|
1293
|
+
privateReadInflight.delete(scopeKey);
|
|
1294
|
+
}
|
|
1295
|
+
})();
|
|
1296
|
+
privateReadInflight.set(scopeKey, authPromise);
|
|
1297
|
+
return authPromise;
|
|
1298
|
+
};
|
|
1299
|
+
await getToken(false);
|
|
1300
|
+
try {
|
|
1301
|
+
return await request();
|
|
1302
|
+
} catch (error) {
|
|
1303
|
+
if (!(error instanceof AccountingApiError) || error.statusCode !== 401) {
|
|
1304
|
+
throw error;
|
|
1305
|
+
}
|
|
1306
|
+
clearPrivateReadScope(scopeKey, client);
|
|
1307
|
+
await getToken(true);
|
|
1308
|
+
return request();
|
|
1309
|
+
}
|
|
1310
|
+
},
|
|
1311
|
+
[
|
|
1312
|
+
client,
|
|
1313
|
+
hostedAuthConfig,
|
|
1314
|
+
hostedAuthSession,
|
|
1315
|
+
networkConfig.apiUrl,
|
|
1316
|
+
networkConfig.chainId,
|
|
1317
|
+
refreshHostedAuthSession,
|
|
1318
|
+
walletAddress,
|
|
1319
|
+
wagmiContext
|
|
1320
|
+
]
|
|
1321
|
+
);
|
|
1322
|
+
const privateReadQueryScope = react.useMemo(
|
|
1323
|
+
() => [networkConfig.apiUrl, networkConfig.chainId, privateReadAddress],
|
|
1324
|
+
[networkConfig.apiUrl, networkConfig.chainId, privateReadAddress]
|
|
1325
|
+
);
|
|
1326
|
+
return {
|
|
1327
|
+
executePrivateRead,
|
|
1328
|
+
privateReadAddress,
|
|
1329
|
+
privateReadReady,
|
|
1330
|
+
privateReadQueryScope
|
|
1331
|
+
};
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1334
|
+
// src/sdk/hooks/use-deposit-verification.ts
|
|
1335
|
+
function useDepositVerification(options = {}) {
|
|
1336
|
+
const { client } = usePrivanaContext();
|
|
1337
|
+
const queryClient = reactQuery.useQueryClient();
|
|
1338
|
+
const { executePrivateRead } = usePrivateReadRequest();
|
|
1339
|
+
const pollInterval = options.pollInterval ?? 5e3;
|
|
1340
|
+
const finalityRetryInterval = options.finalityRetryInterval ?? pollInterval;
|
|
1341
|
+
const pollTimeout = options.pollTimeout ?? 18e4;
|
|
1342
|
+
const [isVerifying, setIsVerifying] = react.useState(false);
|
|
1343
|
+
const [didTimeout, setDidTimeout] = react.useState(false);
|
|
1344
|
+
const [verificationFailed, setVerificationFailed] = react.useState(false);
|
|
1345
|
+
const [error, setError] = react.useState(null);
|
|
1346
|
+
const [txHash, setTxHash] = react.useState();
|
|
1347
|
+
const generationRef = react.useRef(0);
|
|
1348
|
+
const pollIntervalRef = react.useRef(null);
|
|
1349
|
+
const verificationContextRef = react.useRef(null);
|
|
1350
|
+
const onCreditedRef = react.useRef(options.onCredited);
|
|
1351
|
+
const onCheckTimeoutRef = react.useRef(options.onCheckTimeout);
|
|
1352
|
+
const onErrorRef = react.useRef(options.onError);
|
|
1353
|
+
react.useEffect(() => {
|
|
1354
|
+
onCreditedRef.current = options.onCredited;
|
|
1355
|
+
onCheckTimeoutRef.current = options.onCheckTimeout;
|
|
1356
|
+
onErrorRef.current = options.onError;
|
|
1357
|
+
}, [options.onCredited, options.onCheckTimeout, options.onError]);
|
|
1358
|
+
const stopPolling = react.useCallback(() => {
|
|
1359
|
+
if (pollIntervalRef.current) {
|
|
1360
|
+
clearTimeout(pollIntervalRef.current);
|
|
1361
|
+
pollIntervalRef.current = null;
|
|
1362
|
+
}
|
|
1363
|
+
}, []);
|
|
1364
|
+
const invalidateGeneration = react.useCallback(() => {
|
|
1365
|
+
generationRef.current++;
|
|
1366
|
+
}, []);
|
|
1367
|
+
react.useEffect(() => {
|
|
1368
|
+
return () => {
|
|
1369
|
+
invalidateGeneration();
|
|
1370
|
+
stopPolling();
|
|
1371
|
+
};
|
|
1372
|
+
}, [invalidateGeneration, stopPolling]);
|
|
1373
|
+
const runVerification = react.useCallback(
|
|
1374
|
+
async (ctx, generation) => {
|
|
1375
|
+
const isStale = () => generation !== generationRef.current;
|
|
1376
|
+
const { hash, chainId, amount } = ctx;
|
|
1377
|
+
setVerificationFailed(false);
|
|
1378
|
+
setError(null);
|
|
1379
|
+
setDidTimeout(false);
|
|
1380
|
+
setIsVerifying(true);
|
|
1381
|
+
const pollStartTime = Date.now();
|
|
1382
|
+
const markVerificationFailed = (err) => {
|
|
1383
|
+
setIsVerifying(false);
|
|
1384
|
+
setError(err);
|
|
1385
|
+
setVerificationFailed(true);
|
|
1386
|
+
onErrorRef.current?.(err);
|
|
1387
|
+
};
|
|
1388
|
+
const markVerificationTimedOut = () => {
|
|
1389
|
+
stopPolling();
|
|
1390
|
+
setIsVerifying(false);
|
|
1391
|
+
setDidTimeout(true);
|
|
1392
|
+
onCheckTimeoutRef.current?.(hash);
|
|
1393
|
+
queryClient.invalidateQueries({ queryKey: ["accounting-balance"] });
|
|
1394
|
+
};
|
|
1395
|
+
try {
|
|
1396
|
+
let triggerResult;
|
|
1397
|
+
while (!triggerResult) {
|
|
1398
|
+
if (isStale()) return;
|
|
1399
|
+
try {
|
|
1400
|
+
const result = await executePrivateRead(
|
|
1401
|
+
() => client.checkDeposit({
|
|
1402
|
+
chain_id: chainId,
|
|
1403
|
+
tx_hash: hash,
|
|
1404
|
+
amount: amount.toString()
|
|
1405
|
+
})
|
|
1406
|
+
);
|
|
1407
|
+
if (result.status === "error" && isInsufficientFinalityMessage(result.detail)) {
|
|
1408
|
+
if (Date.now() - pollStartTime > pollTimeout) {
|
|
1409
|
+
markVerificationTimedOut();
|
|
1410
|
+
return;
|
|
1411
|
+
}
|
|
1412
|
+
await sleep(finalityRetryInterval);
|
|
1413
|
+
if (isStale()) return;
|
|
1414
|
+
continue;
|
|
1415
|
+
}
|
|
1416
|
+
triggerResult = result;
|
|
1417
|
+
} catch (err) {
|
|
1418
|
+
if (isStale()) return;
|
|
1419
|
+
if (!isInsufficientFinalityError(err)) {
|
|
1420
|
+
throw err;
|
|
1421
|
+
}
|
|
1422
|
+
if (Date.now() - pollStartTime > pollTimeout) {
|
|
1423
|
+
markVerificationTimedOut();
|
|
1424
|
+
return;
|
|
1425
|
+
}
|
|
1426
|
+
await sleep(finalityRetryInterval);
|
|
1427
|
+
if (isStale()) return;
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
if (isStale()) return;
|
|
1431
|
+
if (triggerResult.status === "credited") {
|
|
1432
|
+
setIsVerifying(false);
|
|
1433
|
+
verificationContextRef.current = null;
|
|
1434
|
+
queryClient.invalidateQueries({ queryKey: ["accounting-balance"] });
|
|
1435
|
+
queryClient.invalidateQueries({ queryKey: ["accounting-history"] });
|
|
1436
|
+
onCreditedRef.current?.(hash, triggerResult);
|
|
1437
|
+
return;
|
|
1438
|
+
}
|
|
1439
|
+
if (triggerResult.status === "error") {
|
|
1440
|
+
markVerificationFailed(new Error(triggerResult.detail ?? "Deposit verification failed"));
|
|
1441
|
+
return;
|
|
1442
|
+
}
|
|
1443
|
+
const depositId = triggerResult.deposit_id;
|
|
1444
|
+
if (!depositId) {
|
|
1445
|
+
markVerificationFailed(new Error("Deposit check did not return a deposit id"));
|
|
1446
|
+
return;
|
|
1447
|
+
}
|
|
1448
|
+
let consecutiveFailures = 0;
|
|
1449
|
+
const checkStatus = async () => {
|
|
1450
|
+
if (isStale()) return true;
|
|
1451
|
+
if (Date.now() - pollStartTime > pollTimeout) {
|
|
1452
|
+
markVerificationTimedOut();
|
|
1453
|
+
return true;
|
|
1454
|
+
}
|
|
1455
|
+
try {
|
|
1456
|
+
const result = await executePrivateRead(() => client.getDepositStatus(depositId));
|
|
1457
|
+
if (isStale()) return true;
|
|
1458
|
+
consecutiveFailures = 0;
|
|
1459
|
+
if (result.status === "credited") {
|
|
1460
|
+
stopPolling();
|
|
1461
|
+
setIsVerifying(false);
|
|
1462
|
+
verificationContextRef.current = null;
|
|
1463
|
+
queryClient.invalidateQueries({ queryKey: ["accounting-balance"] });
|
|
1464
|
+
queryClient.invalidateQueries({ queryKey: ["accounting-history"] });
|
|
1465
|
+
onCreditedRef.current?.(hash, result);
|
|
1466
|
+
return true;
|
|
1467
|
+
}
|
|
1468
|
+
if (result.status === "error") {
|
|
1469
|
+
stopPolling();
|
|
1470
|
+
markVerificationFailed(new Error(result.detail ?? "Deposit verification failed"));
|
|
1471
|
+
return true;
|
|
1472
|
+
}
|
|
1473
|
+
} catch (err) {
|
|
1474
|
+
if (isStale()) return true;
|
|
1475
|
+
consecutiveFailures++;
|
|
1476
|
+
console.warn("Error polling deposit status:", err);
|
|
1477
|
+
if (consecutiveFailures >= 3) {
|
|
1478
|
+
stopPolling();
|
|
1479
|
+
markVerificationFailed(
|
|
1480
|
+
err instanceof Error ? err : new Error("Deposit status polling failed")
|
|
1481
|
+
);
|
|
1482
|
+
return true;
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
return false;
|
|
1486
|
+
};
|
|
1487
|
+
const pollLoop = async () => {
|
|
1488
|
+
const done = await checkStatus();
|
|
1489
|
+
if (!done && !isStale() && pollIntervalRef.current !== null) {
|
|
1490
|
+
pollIntervalRef.current = setTimeout(pollLoop, pollInterval);
|
|
1491
|
+
}
|
|
1492
|
+
};
|
|
1493
|
+
pollIntervalRef.current = setTimeout(pollLoop, pollInterval);
|
|
1494
|
+
} catch (err) {
|
|
1495
|
+
if (isStale()) return;
|
|
1496
|
+
stopPolling();
|
|
1497
|
+
markVerificationFailed(
|
|
1498
|
+
err instanceof Error ? err : new Error("Deposit verification failed")
|
|
1499
|
+
);
|
|
1500
|
+
}
|
|
1501
|
+
},
|
|
1502
|
+
[
|
|
1503
|
+
client,
|
|
1504
|
+
executePrivateRead,
|
|
1505
|
+
finalityRetryInterval,
|
|
1506
|
+
pollInterval,
|
|
1507
|
+
pollTimeout,
|
|
1508
|
+
queryClient,
|
|
1509
|
+
stopPolling
|
|
1510
|
+
]
|
|
1511
|
+
);
|
|
1512
|
+
const verify = react.useCallback(
|
|
1513
|
+
async (ctx) => {
|
|
1514
|
+
generationRef.current++;
|
|
1515
|
+
stopPolling();
|
|
1516
|
+
verificationContextRef.current = ctx;
|
|
1517
|
+
setTxHash(ctx.hash);
|
|
1518
|
+
const generation = generationRef.current;
|
|
1519
|
+
await runVerification(ctx, generation);
|
|
1520
|
+
},
|
|
1521
|
+
[runVerification, stopPolling]
|
|
1522
|
+
);
|
|
1523
|
+
const retryVerification = react.useCallback(async () => {
|
|
1524
|
+
const ctx = verificationContextRef.current;
|
|
1525
|
+
if (!ctx) {
|
|
1526
|
+
throw new Error("No pending verification to retry");
|
|
1527
|
+
}
|
|
1528
|
+
generationRef.current++;
|
|
1529
|
+
stopPolling();
|
|
1530
|
+
const generation = generationRef.current;
|
|
1531
|
+
await runVerification(ctx, generation);
|
|
1532
|
+
}, [runVerification, stopPolling]);
|
|
1533
|
+
const reset = react.useCallback(() => {
|
|
1534
|
+
generationRef.current++;
|
|
1535
|
+
stopPolling();
|
|
1536
|
+
verificationContextRef.current = null;
|
|
1537
|
+
setTxHash(void 0);
|
|
1538
|
+
setIsVerifying(false);
|
|
1539
|
+
setDidTimeout(false);
|
|
1540
|
+
setVerificationFailed(false);
|
|
1541
|
+
setError(null);
|
|
1542
|
+
}, [stopPolling]);
|
|
1543
|
+
return {
|
|
1544
|
+
isVerifying,
|
|
1545
|
+
didTimeout,
|
|
1546
|
+
verificationFailed,
|
|
1547
|
+
error,
|
|
1548
|
+
txHash,
|
|
1549
|
+
verify,
|
|
1550
|
+
retryVerification,
|
|
1551
|
+
reset
|
|
1552
|
+
};
|
|
1553
|
+
}
|
|
1554
|
+
function sleep(ms) {
|
|
1555
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
1556
|
+
}
|
|
1557
|
+
function isInsufficientFinalityError(error) {
|
|
1558
|
+
if (error instanceof AccountingApiError) {
|
|
1559
|
+
return isInsufficientFinalityMessage(error.detail) || isInsufficientFinalityMessage(error.message);
|
|
1560
|
+
}
|
|
1561
|
+
return error instanceof Error && isInsufficientFinalityMessage(error.message);
|
|
1562
|
+
}
|
|
1563
|
+
function isInsufficientFinalityMessage(message) {
|
|
1564
|
+
return message?.includes("Insufficient finality") ?? false;
|
|
1565
|
+
}
|
|
1566
|
+
function cn(...inputs) {
|
|
1567
|
+
return tailwindMerge.twMerge(clsx.clsx(inputs));
|
|
1568
|
+
}
|
|
1569
|
+
function formatTokenAmount(amount, decimals = 18) {
|
|
1570
|
+
const value = typeof amount === "string" ? BigInt(amount) : amount;
|
|
1571
|
+
const divisor = BigInt(10 ** decimals);
|
|
1572
|
+
const integerPart = value / divisor;
|
|
1573
|
+
const fractionalPart = value % divisor;
|
|
1574
|
+
const fractionalStr = fractionalPart.toString().padStart(decimals, "0");
|
|
1575
|
+
const twoDecimals = fractionalStr.slice(0, 2).padEnd(2, "0");
|
|
1576
|
+
const integerWithSpaces = integerPart.toString().replace(/\B(?=(\d{3})+(?!\d))/g, "\u2009");
|
|
1577
|
+
return `${integerWithSpaces}.${twoDecimals}`;
|
|
1578
|
+
}
|
|
1579
|
+
function parseTokenAmount(amount, decimals = 18) {
|
|
1580
|
+
const sanitized = amount.replace(/[\s\u2009]/g, "").replace(/,/g, ".");
|
|
1581
|
+
const lastDot = sanitized.lastIndexOf(".");
|
|
1582
|
+
const integerPart = lastDot === -1 ? sanitized : sanitized.slice(0, lastDot).replace(/\./g, "");
|
|
1583
|
+
const fractionalPart = lastDot === -1 ? "" : sanitized.slice(lastDot + 1);
|
|
1584
|
+
const paddedFractional = fractionalPart.padEnd(decimals, "0").slice(0, decimals);
|
|
1585
|
+
return BigInt(integerPart + paddedFractional);
|
|
1586
|
+
}
|
|
1587
|
+
function shortenAddress(address, chars = 4) {
|
|
1588
|
+
if (!address || address.length < chars * 2 + 2) return address;
|
|
1589
|
+
return `${address.slice(0, chars + 2)}...${address.slice(-chars)}`;
|
|
1590
|
+
}
|
|
1591
|
+
function formatTimeRemaining(expiryTimestamp) {
|
|
1592
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
1593
|
+
const diff = expiryTimestamp - now;
|
|
1594
|
+
if (diff <= 0) return "Expired";
|
|
1595
|
+
const days = Math.floor(diff / 86400);
|
|
1596
|
+
const hours = Math.floor(diff % 86400 / 3600);
|
|
1597
|
+
const minutes = Math.floor(diff % 3600 / 60);
|
|
1598
|
+
if (days > 0) {
|
|
1599
|
+
return hours > 0 ? `${days}d ${hours}h left` : `${days}d left`;
|
|
1600
|
+
}
|
|
1601
|
+
if (hours > 0) {
|
|
1602
|
+
return minutes > 0 ? `${hours}h ${minutes}m left` : `${hours}h left`;
|
|
1603
|
+
}
|
|
1604
|
+
return `${minutes}m left`;
|
|
1605
|
+
}
|
|
1606
|
+
var buttonVariants = classVarianceAuthority.cva(
|
|
1607
|
+
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
|
1608
|
+
{
|
|
1609
|
+
variants: {
|
|
1610
|
+
variant: {
|
|
1611
|
+
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
|
1612
|
+
destructive: "bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
|
1613
|
+
outline: "border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
|
|
1614
|
+
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
1615
|
+
ghost: "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
|
|
1616
|
+
link: "text-primary underline-offset-4 hover:underline"
|
|
1617
|
+
},
|
|
1618
|
+
size: {
|
|
1619
|
+
default: "h-9 px-4 py-2 has-[>svg]:px-3",
|
|
1620
|
+
sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
|
|
1621
|
+
lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
|
|
1622
|
+
icon: "size-9",
|
|
1623
|
+
"icon-sm": "size-8",
|
|
1624
|
+
"icon-lg": "size-10"
|
|
1625
|
+
}
|
|
1626
|
+
},
|
|
1627
|
+
defaultVariants: {
|
|
1628
|
+
variant: "default",
|
|
1629
|
+
size: "default"
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
);
|
|
1633
|
+
function Button({
|
|
1634
|
+
className,
|
|
1635
|
+
variant = "default",
|
|
1636
|
+
size = "default",
|
|
1637
|
+
asChild = false,
|
|
1638
|
+
...props
|
|
1639
|
+
}) {
|
|
1640
|
+
const Comp = asChild ? reactSlot.Slot : "button";
|
|
1641
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1642
|
+
Comp,
|
|
1643
|
+
{
|
|
1644
|
+
"data-slot": "button",
|
|
1645
|
+
"data-variant": variant,
|
|
1646
|
+
"data-size": size,
|
|
1647
|
+
className: cn(buttonVariants({ variant, size, className })),
|
|
1648
|
+
...props
|
|
1649
|
+
}
|
|
1650
|
+
);
|
|
1651
|
+
}
|
|
1652
|
+
|
|
1653
|
+
// ../../node_modules/@wagmi/core/dist/esm/utils/getAction.js
|
|
1654
|
+
function getAction(client, actionFn, name) {
|
|
1655
|
+
const action_implicit = client[actionFn.name];
|
|
1656
|
+
if (typeof action_implicit === "function")
|
|
1657
|
+
return action_implicit;
|
|
1658
|
+
const action_explicit = client[name];
|
|
1659
|
+
if (typeof action_explicit === "function")
|
|
1660
|
+
return action_explicit;
|
|
1661
|
+
return (params) => actionFn(client, params);
|
|
1662
|
+
}
|
|
1663
|
+
|
|
1664
|
+
// ../../node_modules/@wagmi/core/dist/esm/actions/getTransactionReceipt.js
|
|
1665
|
+
async function getTransactionReceipt(config, parameters) {
|
|
1666
|
+
const { chainId, ...rest } = parameters;
|
|
1667
|
+
const client = config.getClient({ chainId });
|
|
1668
|
+
const action = getAction(client, actions$1.getTransactionReceipt, "getTransactionReceipt");
|
|
1669
|
+
return action(rest);
|
|
1670
|
+
}
|
|
1671
|
+
async function waitForTransactionReceipt(config, parameters) {
|
|
1672
|
+
const { chainId, timeout = 0, ...rest } = parameters;
|
|
1673
|
+
const client = config.getClient({ chainId });
|
|
1674
|
+
const action = getAction(client, actions$1.waitForTransactionReceipt, "waitForTransactionReceipt");
|
|
1675
|
+
const receipt = await action({ ...rest, timeout });
|
|
1676
|
+
if (receipt.status === "reverted") {
|
|
1677
|
+
const action_getTransaction = getAction(client, actions$1.getTransaction, "getTransaction");
|
|
1678
|
+
const { from: account, ...txn } = await action_getTransaction({
|
|
1679
|
+
hash: receipt.transactionHash
|
|
1680
|
+
});
|
|
1681
|
+
const action_call = getAction(client, actions$1.call, "call");
|
|
1682
|
+
const code = await action_call({
|
|
1683
|
+
...txn,
|
|
1684
|
+
account,
|
|
1685
|
+
data: txn.input,
|
|
1686
|
+
gasPrice: txn.type !== "eip1559" ? txn.gasPrice : void 0,
|
|
1687
|
+
maxFeePerGas: txn.type === "eip1559" ? txn.maxFeePerGas : void 0,
|
|
1688
|
+
maxPriorityFeePerGas: txn.type === "eip1559" ? txn.maxPriorityFeePerGas : void 0
|
|
1689
|
+
});
|
|
1690
|
+
const reason = code?.data ? viem.hexToString(`0x${code.data.substring(138)}`) : "unknown reason";
|
|
1691
|
+
throw new Error(reason);
|
|
1692
|
+
}
|
|
1693
|
+
return {
|
|
1694
|
+
...receipt,
|
|
1695
|
+
chainId: client.chain.id
|
|
1696
|
+
};
|
|
1697
|
+
}
|
|
1698
|
+
|
|
1699
|
+
// ../../node_modules/@wagmi/core/dist/esm/actions/getChainId.js
|
|
1700
|
+
function getChainId2(config) {
|
|
1701
|
+
return config.state.chainId;
|
|
1702
|
+
}
|
|
1703
|
+
|
|
1704
|
+
exports.AccountingApiError = AccountingApiError;
|
|
1705
|
+
exports.Button = Button;
|
|
1706
|
+
exports.HOSTED_AUTH_CLOCK_SKEW_MS = HOSTED_AUTH_CLOCK_SKEW_MS;
|
|
1707
|
+
exports.HostedAuthError = HostedAuthError;
|
|
1708
|
+
exports.HostedAuthRequiredError = HostedAuthRequiredError;
|
|
1709
|
+
exports.HostedAuthStateMismatchError = HostedAuthStateMismatchError;
|
|
1710
|
+
exports.HttpClient = HttpClient;
|
|
1711
|
+
exports.NETWORK_CONFIG = NETWORK_CONFIG;
|
|
1712
|
+
exports.NetworkError = NetworkError;
|
|
1713
|
+
exports.PrivanaClient = PrivanaClient;
|
|
1714
|
+
exports.PrivanaProvider = PrivanaProvider;
|
|
1715
|
+
exports.SUPPORTED_CHAINS = SUPPORTED_CHAINS;
|
|
1716
|
+
exports.SiweAuthProvider = SiweAuthProvider;
|
|
1717
|
+
exports.ValidationError = ValidationError;
|
|
1718
|
+
exports.applyRefreshResponse = applyRefreshResponse;
|
|
1719
|
+
exports.buildHostedAuthSession = buildHostedAuthSession;
|
|
1720
|
+
exports.buttonVariants = buttonVariants;
|
|
1721
|
+
exports.clearHostedAuthPendingTransaction = clearHostedAuthPendingTransaction;
|
|
1722
|
+
exports.cn = cn;
|
|
1723
|
+
exports.createHostedAuthPendingStorageKey = createHostedAuthPendingStorageKey;
|
|
1724
|
+
exports.createHostedAuthState = createHostedAuthState;
|
|
1725
|
+
exports.createHostedAuthStorageKey = createHostedAuthStorageKey;
|
|
1726
|
+
exports.createPkceChallenge = createPkceChallenge;
|
|
1727
|
+
exports.createPkceVerifier = createPkceVerifier;
|
|
1728
|
+
exports.formatTimeRemaining = formatTimeRemaining;
|
|
1729
|
+
exports.formatTokenAmount = formatTokenAmount;
|
|
1730
|
+
exports.getAccountingContract = getAccountingContract;
|
|
1731
|
+
exports.getApiUrl = getApiUrl;
|
|
1732
|
+
exports.getChainById = getChainById;
|
|
1733
|
+
exports.getChainId = getChainId;
|
|
1734
|
+
exports.getChainId2 = getChainId2;
|
|
1735
|
+
exports.getExplorerAddressUrl = getExplorerAddressUrl;
|
|
1736
|
+
exports.getTransactionReceipt = getTransactionReceipt;
|
|
1737
|
+
exports.isHostedAuthRefreshActive = isHostedAuthRefreshActive;
|
|
1738
|
+
exports.isHostedAuthSessionActive = isHostedAuthSessionActive;
|
|
1739
|
+
exports.normalizeAddress = normalizeAddress;
|
|
1740
|
+
exports.normalizeHex = normalizeHex;
|
|
1741
|
+
exports.parseHostedAuthCallback = parseHostedAuthCallback;
|
|
1742
|
+
exports.parseTokenAmount = parseTokenAmount;
|
|
1743
|
+
exports.persistHostedAuthPendingTransaction = persistHostedAuthPendingTransaction;
|
|
1744
|
+
exports.readHostedAuthPendingTransaction = readHostedAuthPendingTransaction;
|
|
1745
|
+
exports.readStoredHostedAuthSession = readStoredHostedAuthSession;
|
|
1746
|
+
exports.shortenAddress = shortenAddress;
|
|
1747
|
+
exports.stripHostedAuthCallbackParams = stripHostedAuthCallbackParams;
|
|
1748
|
+
exports.syncHostedAuthSessionToClient = syncHostedAuthSessionToClient;
|
|
1749
|
+
exports.useDepositVerification = useDepositVerification;
|
|
1750
|
+
exports.usePrivanaContext = usePrivanaContext;
|
|
1751
|
+
exports.usePrivateReadRequest = usePrivateReadRequest;
|
|
1752
|
+
exports.useSafeAccount = useSafeAccount;
|
|
1753
|
+
exports.useSafePrivanaContext = useSafePrivanaContext;
|
|
1754
|
+
exports.useSiweAuth = useSiweAuth;
|
|
1755
|
+
exports.waitForTransactionReceipt = waitForTransactionReceipt;
|
|
1756
|
+
//# sourceMappingURL=chunk-RDMJGMI3.cjs.map
|
|
1757
|
+
//# sourceMappingURL=chunk-RDMJGMI3.cjs.map
|