@unifold/core 0.1.67 → 0.1.68-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +527 -14
- package/dist/index.d.ts +527 -14
- package/dist/index.js +681 -194
- package/dist/index.mjs +656 -194
- package/package.json +11 -2
package/dist/index.mjs
CHANGED
|
@@ -128,18 +128,15 @@ async function createDepositAddress(overrides, publishableKey) {
|
|
|
128
128
|
async function getDepositAddress(params, publishableKey) {
|
|
129
129
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
130
130
|
validatePublishableKey(pk);
|
|
131
|
-
const response = await fetch(
|
|
132
|
-
|
|
133
|
-
{
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
body: JSON.stringify(params)
|
|
141
|
-
}
|
|
142
|
-
);
|
|
131
|
+
const response = await fetch(`${API_BASE_URL}/v1/public/deposit_addresses/existing`, {
|
|
132
|
+
method: "POST",
|
|
133
|
+
headers: {
|
|
134
|
+
accept: "application/json",
|
|
135
|
+
"x-publishable-key": pk,
|
|
136
|
+
"Content-Type": "application/json"
|
|
137
|
+
},
|
|
138
|
+
body: JSON.stringify(params)
|
|
139
|
+
});
|
|
143
140
|
if (!response.ok) {
|
|
144
141
|
throw new Error(`Failed to get deposit addresses: ${response.statusText}`);
|
|
145
142
|
}
|
|
@@ -165,18 +162,15 @@ async function queryExecutions(externalUserId, publishableKey, actionType = "dep
|
|
|
165
162
|
external_user_id: externalUserId,
|
|
166
163
|
action_type: actionType
|
|
167
164
|
};
|
|
168
|
-
const response = await fetch(
|
|
169
|
-
|
|
170
|
-
{
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
body: JSON.stringify(body)
|
|
178
|
-
}
|
|
179
|
-
);
|
|
165
|
+
const response = await fetch(`${API_BASE_URL}/v1/public/direct_executions/query`, {
|
|
166
|
+
method: "POST",
|
|
167
|
+
headers: {
|
|
168
|
+
accept: "application/json",
|
|
169
|
+
"x-publishable-key": pk,
|
|
170
|
+
"Content-Type": "application/json"
|
|
171
|
+
},
|
|
172
|
+
body: JSON.stringify(body)
|
|
173
|
+
});
|
|
180
174
|
if (!response.ok) {
|
|
181
175
|
throw new Error(`Failed to query executions: ${response.statusText}`);
|
|
182
176
|
}
|
|
@@ -185,18 +179,15 @@ async function queryExecutions(externalUserId, publishableKey, actionType = "dep
|
|
|
185
179
|
async function pollDirectExecutions(request, publishableKey) {
|
|
186
180
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
187
181
|
validatePublishableKey(pk);
|
|
188
|
-
const response = await fetch(
|
|
189
|
-
|
|
190
|
-
{
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
body: JSON.stringify(request)
|
|
198
|
-
}
|
|
199
|
-
);
|
|
182
|
+
const response = await fetch(`${API_BASE_URL}/v1/public/direct_executions/poll`, {
|
|
183
|
+
method: "POST",
|
|
184
|
+
headers: {
|
|
185
|
+
accept: "application/json",
|
|
186
|
+
"x-publishable-key": pk,
|
|
187
|
+
"Content-Type": "application/json"
|
|
188
|
+
},
|
|
189
|
+
body: JSON.stringify(request)
|
|
190
|
+
});
|
|
200
191
|
if (!response.ok) {
|
|
201
192
|
throw new Error(`Failed to poll direct executions: ${response.statusText}`);
|
|
202
193
|
}
|
|
@@ -222,9 +213,7 @@ async function getSupportedDestinationTokens(publishableKey, options) {
|
|
|
222
213
|
}
|
|
223
214
|
});
|
|
224
215
|
if (!response.ok) {
|
|
225
|
-
throw new Error(
|
|
226
|
-
`Failed to fetch supported destination tokens: ${response.statusText}`
|
|
227
|
-
);
|
|
216
|
+
throw new Error(`Failed to fetch supported destination tokens: ${response.statusText}`);
|
|
228
217
|
}
|
|
229
218
|
return response.json();
|
|
230
219
|
}
|
|
@@ -253,9 +242,7 @@ async function getSupportedDepositTokens(publishableKey, options) {
|
|
|
253
242
|
}
|
|
254
243
|
});
|
|
255
244
|
if (!response.ok) {
|
|
256
|
-
throw new Error(
|
|
257
|
-
`Failed to fetch supported deposit tokens: ${response.statusText}`
|
|
258
|
-
);
|
|
245
|
+
throw new Error(`Failed to fetch supported deposit tokens: ${response.statusText}`);
|
|
259
246
|
}
|
|
260
247
|
return response.json();
|
|
261
248
|
}
|
|
@@ -267,16 +254,13 @@ async function getTokenMetadata(request, publishableKey) {
|
|
|
267
254
|
chainId: request.chain_id,
|
|
268
255
|
tokenAddress: request.token_address
|
|
269
256
|
});
|
|
270
|
-
const response = await fetch(
|
|
271
|
-
|
|
272
|
-
{
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
accept: "application/json",
|
|
276
|
-
"x-publishable-key": pk
|
|
277
|
-
}
|
|
257
|
+
const response = await fetch(`${API_BASE_URL}/v1/public/tokens/token?${params.toString()}`, {
|
|
258
|
+
method: "GET",
|
|
259
|
+
headers: {
|
|
260
|
+
accept: "application/json",
|
|
261
|
+
"x-publishable-key": pk
|
|
278
262
|
}
|
|
279
|
-
);
|
|
263
|
+
});
|
|
280
264
|
if (!response.ok) {
|
|
281
265
|
throw new Error(`Failed to fetch token metadata: ${response.statusText}`);
|
|
282
266
|
}
|
|
@@ -295,16 +279,13 @@ function getPreferredIconUrl(iconUrls, preferredFormat = "svg") {
|
|
|
295
279
|
async function getFiatCurrencies(publishableKey) {
|
|
296
280
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
297
281
|
validatePublishableKey(pk);
|
|
298
|
-
const response = await fetch(
|
|
299
|
-
|
|
300
|
-
{
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
accept: "application/json",
|
|
304
|
-
"x-publishable-key": pk
|
|
305
|
-
}
|
|
282
|
+
const response = await fetch(`${API_BASE_URL}/v1/public/onramps/fiat_currencies`, {
|
|
283
|
+
method: "GET",
|
|
284
|
+
headers: {
|
|
285
|
+
accept: "application/json",
|
|
286
|
+
"x-publishable-key": pk
|
|
306
287
|
}
|
|
307
|
-
);
|
|
288
|
+
});
|
|
308
289
|
if (!response.ok) {
|
|
309
290
|
throw new Error(`Failed to fetch fiat currencies: ${response.statusText}`);
|
|
310
291
|
}
|
|
@@ -313,18 +294,15 @@ async function getFiatCurrencies(publishableKey) {
|
|
|
313
294
|
async function getOnrampQuotes(request, publishableKey) {
|
|
314
295
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
315
296
|
validatePublishableKey(pk);
|
|
316
|
-
const response = await fetch(
|
|
317
|
-
|
|
318
|
-
{
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
body: JSON.stringify(request)
|
|
326
|
-
}
|
|
327
|
-
);
|
|
297
|
+
const response = await fetch(`${API_BASE_URL}/v1/public/onramps/quotes`, {
|
|
298
|
+
method: "POST",
|
|
299
|
+
headers: {
|
|
300
|
+
accept: "application/json",
|
|
301
|
+
"x-publishable-key": pk,
|
|
302
|
+
"Content-Type": "application/json"
|
|
303
|
+
},
|
|
304
|
+
body: JSON.stringify(request)
|
|
305
|
+
});
|
|
328
306
|
if (!response.ok) {
|
|
329
307
|
throw new Error(`Failed to fetch onramp quotes: ${response.statusText}`);
|
|
330
308
|
}
|
|
@@ -333,23 +311,57 @@ async function getOnrampQuotes(request, publishableKey) {
|
|
|
333
311
|
async function createOnrampSession(request, publishableKey) {
|
|
334
312
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
335
313
|
validatePublishableKey(pk);
|
|
336
|
-
const response = await fetch(
|
|
337
|
-
|
|
338
|
-
{
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
body: JSON.stringify(request)
|
|
346
|
-
}
|
|
347
|
-
);
|
|
314
|
+
const response = await fetch(`${API_BASE_URL}/v1/public/onramps/sessions`, {
|
|
315
|
+
method: "POST",
|
|
316
|
+
headers: {
|
|
317
|
+
accept: "application/json",
|
|
318
|
+
"x-publishable-key": pk,
|
|
319
|
+
"Content-Type": "application/json"
|
|
320
|
+
},
|
|
321
|
+
body: JSON.stringify(request)
|
|
322
|
+
});
|
|
348
323
|
if (!response.ok) {
|
|
349
324
|
throw new Error(`Failed to create onramp session: ${response.statusText}`);
|
|
350
325
|
}
|
|
351
326
|
return response.json();
|
|
352
327
|
}
|
|
328
|
+
async function getBankTransferProviders(publishableKey, options = {}) {
|
|
329
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
330
|
+
validatePublishableKey(pk);
|
|
331
|
+
const params = new URLSearchParams();
|
|
332
|
+
if (options.countryCode) {
|
|
333
|
+
params.set("country_code", options.countryCode);
|
|
334
|
+
}
|
|
335
|
+
const queryString = params.toString();
|
|
336
|
+
const url = `${API_BASE_URL}/v1/public/onramps/bank_transfer/providers${queryString ? `?${queryString}` : ""}`;
|
|
337
|
+
const response = await fetch(url, {
|
|
338
|
+
method: "GET",
|
|
339
|
+
headers: {
|
|
340
|
+
accept: "application/json",
|
|
341
|
+
"x-publishable-key": pk
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
if (!response.ok) {
|
|
345
|
+
throw new Error(`Failed to fetch bank-transfer providers: ${response.statusText}`);
|
|
346
|
+
}
|
|
347
|
+
return response.json();
|
|
348
|
+
}
|
|
349
|
+
async function getApplePayProviders(publishableKey) {
|
|
350
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
351
|
+
validatePublishableKey(pk);
|
|
352
|
+
const url = `${API_BASE_URL}/v1/public/onramps/apple_pay/providers`;
|
|
353
|
+
const response = await fetch(url, {
|
|
354
|
+
method: "GET",
|
|
355
|
+
headers: {
|
|
356
|
+
accept: "application/json",
|
|
357
|
+
"x-publishable-key": pk
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
if (!response.ok) {
|
|
361
|
+
throw new Error(`Failed to fetch Apple Pay providers: ${response.statusText}`);
|
|
362
|
+
}
|
|
363
|
+
return response.json();
|
|
364
|
+
}
|
|
353
365
|
function getOnrampSessionStartUrl(request, publishableKey) {
|
|
354
366
|
const params = new URLSearchParams();
|
|
355
367
|
params.append("publishable_key", publishableKey);
|
|
@@ -367,6 +379,9 @@ function getOnrampSessionStartUrl(request, publishableKey) {
|
|
|
367
379
|
if (request.email) {
|
|
368
380
|
params.append("email", request.email);
|
|
369
381
|
}
|
|
382
|
+
if (request.payment_method) {
|
|
383
|
+
params.append("payment_method", request.payment_method);
|
|
384
|
+
}
|
|
370
385
|
return `${API_BASE_URL}/v1/public/onramps/sessions/start?${params.toString()}`;
|
|
371
386
|
}
|
|
372
387
|
async function getDefaultOnrampToken(params, publishableKey) {
|
|
@@ -416,10 +431,18 @@ function getChainName(chains, chainType, chainId) {
|
|
|
416
431
|
if (!chainType) return chainId || "Unknown";
|
|
417
432
|
return chainType.charAt(0).toUpperCase() + chainType.slice(1);
|
|
418
433
|
}
|
|
419
|
-
async function getProjectConfig(publishableKey) {
|
|
434
|
+
async function getProjectConfig(publishableKey, options) {
|
|
420
435
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
421
436
|
validatePublishableKey(pk);
|
|
422
|
-
const
|
|
437
|
+
const params = new URLSearchParams();
|
|
438
|
+
if (options?.countryCode) {
|
|
439
|
+
params.set("country_code", options.countryCode);
|
|
440
|
+
}
|
|
441
|
+
if (options?.subdivisionCode) {
|
|
442
|
+
params.set("subdivision_code", options.subdivisionCode);
|
|
443
|
+
}
|
|
444
|
+
const queryString = params.toString();
|
|
445
|
+
const url = `${API_BASE_URL}/v1/public/projects/config${queryString ? `?${queryString}` : ""}`;
|
|
423
446
|
const response = await fetch(url, {
|
|
424
447
|
method: "GET",
|
|
425
448
|
headers: {
|
|
@@ -441,9 +464,7 @@ async function getIpAddress() {
|
|
|
441
464
|
}
|
|
442
465
|
});
|
|
443
466
|
if (!response.ok) {
|
|
444
|
-
throw new Error(
|
|
445
|
-
`Failed to fetch IP address information: ${response.statusText}`
|
|
446
|
-
);
|
|
467
|
+
throw new Error(`Failed to fetch IP address information: ${response.statusText}`);
|
|
447
468
|
}
|
|
448
469
|
return response.json();
|
|
449
470
|
}
|
|
@@ -545,31 +566,24 @@ async function verifyRecipientAddress(request, publishableKey) {
|
|
|
545
566
|
body: JSON.stringify(request)
|
|
546
567
|
});
|
|
547
568
|
if (!response.ok) {
|
|
548
|
-
throw new Error(
|
|
549
|
-
`Failed to verify recipient address: ${response.statusText}`
|
|
550
|
-
);
|
|
569
|
+
throw new Error(`Failed to verify recipient address: ${response.statusText}`);
|
|
551
570
|
}
|
|
552
571
|
return response.json();
|
|
553
572
|
}
|
|
554
573
|
async function checkHypercoreActivation(request, publishableKey) {
|
|
555
574
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
556
575
|
validatePublishableKey(pk);
|
|
557
|
-
const response = await fetch(
|
|
558
|
-
|
|
559
|
-
{
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
body: JSON.stringify(request)
|
|
567
|
-
}
|
|
568
|
-
);
|
|
576
|
+
const response = await fetch(`${API_BASE_URL}/v1/public/addresses/hypercore/activation`, {
|
|
577
|
+
method: "POST",
|
|
578
|
+
headers: {
|
|
579
|
+
accept: "application/json",
|
|
580
|
+
"x-publishable-key": pk,
|
|
581
|
+
"Content-Type": "application/json"
|
|
582
|
+
},
|
|
583
|
+
body: JSON.stringify(request)
|
|
584
|
+
});
|
|
569
585
|
if (!response.ok) {
|
|
570
|
-
throw new Error(
|
|
571
|
-
`HyperCore activation check failed: ${response.statusText}`
|
|
572
|
-
);
|
|
586
|
+
throw new Error(`HyperCore activation check failed: ${response.statusText}`);
|
|
573
587
|
}
|
|
574
588
|
return response.json();
|
|
575
589
|
}
|
|
@@ -577,7 +591,8 @@ async function getExchanges(query, publishableKey) {
|
|
|
577
591
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
578
592
|
validatePublishableKey(pk);
|
|
579
593
|
const params = new URLSearchParams();
|
|
580
|
-
if (query?.destination_currency)
|
|
594
|
+
if (query?.destination_currency)
|
|
595
|
+
params.append("destination_currency", query.destination_currency);
|
|
581
596
|
if (query?.destination_network) params.append("destination_network", query.destination_network);
|
|
582
597
|
const queryString = params.toString();
|
|
583
598
|
const url = `${API_BASE_URL}/v1/public/onramps/exchanges${queryString ? `?${queryString}` : ""}`;
|
|
@@ -597,18 +612,15 @@ async function getExchanges(query, publishableKey) {
|
|
|
597
612
|
async function createExchangeSession(request, publishableKey) {
|
|
598
613
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
599
614
|
validatePublishableKey(pk);
|
|
600
|
-
const response = await fetch(
|
|
601
|
-
|
|
602
|
-
{
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
body: JSON.stringify(request)
|
|
610
|
-
}
|
|
611
|
-
);
|
|
615
|
+
const response = await fetch(`${API_BASE_URL}/v1/public/onramps/exchanges/sessions`, {
|
|
616
|
+
method: "POST",
|
|
617
|
+
headers: {
|
|
618
|
+
accept: "application/json",
|
|
619
|
+
"x-publishable-key": pk,
|
|
620
|
+
"Content-Type": "application/json"
|
|
621
|
+
},
|
|
622
|
+
body: JSON.stringify(request)
|
|
623
|
+
});
|
|
612
624
|
if (!response.ok) {
|
|
613
625
|
throw new Error(`Failed to create exchange session: ${response.statusText}`);
|
|
614
626
|
}
|
|
@@ -761,15 +773,18 @@ async function confirmIntegrationTransfer(transferId, accessToken, mfaCode, publ
|
|
|
761
773
|
validatePublishableKey(pk);
|
|
762
774
|
const body = { access_token: accessToken };
|
|
763
775
|
if (mfaCode) body.mfa_code = mfaCode;
|
|
764
|
-
const response = await fetch(
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
776
|
+
const response = await fetch(
|
|
777
|
+
`${API_BASE_URL}/v1/public/integrations/transfers/${transferId}/confirm`,
|
|
778
|
+
{
|
|
779
|
+
method: "POST",
|
|
780
|
+
headers: {
|
|
781
|
+
accept: "application/json",
|
|
782
|
+
"x-publishable-key": pk,
|
|
783
|
+
"Content-Type": "application/json"
|
|
784
|
+
},
|
|
785
|
+
body: JSON.stringify(body)
|
|
786
|
+
}
|
|
787
|
+
);
|
|
773
788
|
if (!response.ok) {
|
|
774
789
|
const err = await response.json().catch(() => ({ message: response.statusText }));
|
|
775
790
|
throw new Error(`Failed to confirm transfer: ${err.message || response.statusText}`);
|
|
@@ -808,9 +823,7 @@ async function buildSolanaTransaction(request, publishableKey) {
|
|
|
808
823
|
});
|
|
809
824
|
if (!response.ok) {
|
|
810
825
|
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
811
|
-
throw new Error(
|
|
812
|
-
`Failed to build Solana transaction: ${error.message || response.statusText}`
|
|
813
|
-
);
|
|
826
|
+
throw new Error(`Failed to build Solana transaction: ${error.message || response.statusText}`);
|
|
814
827
|
}
|
|
815
828
|
return response.json();
|
|
816
829
|
}
|
|
@@ -828,62 +841,110 @@ async function sendSolanaTransaction(request, publishableKey) {
|
|
|
828
841
|
});
|
|
829
842
|
if (!response.ok) {
|
|
830
843
|
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
831
|
-
throw new Error(
|
|
832
|
-
`Failed to send Solana transaction: ${error.message || response.statusText}`
|
|
833
|
-
);
|
|
844
|
+
throw new Error(`Failed to send Solana transaction: ${error.message || response.statusText}`);
|
|
834
845
|
}
|
|
835
846
|
return response.json();
|
|
836
847
|
}
|
|
837
848
|
async function retrievePaymentIntent(clientSecret, publishableKey) {
|
|
838
849
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
839
850
|
validatePublishableKey(pk);
|
|
840
|
-
const response = await fetch(
|
|
841
|
-
|
|
842
|
-
{
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
}
|
|
851
|
-
|
|
851
|
+
const response = await fetch(`${API_BASE_URL}/v1/public/payment_intents/retrieve`, {
|
|
852
|
+
method: "POST",
|
|
853
|
+
headers: {
|
|
854
|
+
accept: "application/json",
|
|
855
|
+
"x-publishable-key": pk,
|
|
856
|
+
"Content-Type": "application/json"
|
|
857
|
+
},
|
|
858
|
+
body: JSON.stringify({ client_secret: clientSecret })
|
|
859
|
+
});
|
|
860
|
+
if (!response.ok) {
|
|
861
|
+
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
862
|
+
throw new Error(`Failed to retrieve payment intent: ${error.message || response.statusText}`);
|
|
863
|
+
}
|
|
864
|
+
return response.json();
|
|
865
|
+
}
|
|
866
|
+
async function listPaymentIntentExecutions(clientSecret, publishableKey) {
|
|
867
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
868
|
+
validatePublishableKey(pk);
|
|
869
|
+
const response = await fetch(`${API_BASE_URL}/v1/public/payment_intents/executions`, {
|
|
870
|
+
method: "POST",
|
|
871
|
+
headers: {
|
|
872
|
+
accept: "application/json",
|
|
873
|
+
"x-publishable-key": pk,
|
|
874
|
+
"Content-Type": "application/json"
|
|
875
|
+
},
|
|
876
|
+
body: JSON.stringify({ client_secret: clientSecret })
|
|
877
|
+
});
|
|
852
878
|
if (!response.ok) {
|
|
853
879
|
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
854
880
|
throw new Error(
|
|
855
|
-
`Failed to
|
|
881
|
+
`Failed to list payment intent executions: ${error.message || response.statusText}`
|
|
856
882
|
);
|
|
857
883
|
}
|
|
858
884
|
return response.json();
|
|
859
885
|
}
|
|
860
|
-
async function
|
|
886
|
+
async function getDepositQuote(request, publishableKey) {
|
|
887
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
888
|
+
validatePublishableKey(pk);
|
|
889
|
+
const response = await fetch(`${API_BASE_URL}/v1/public/quotes`, {
|
|
890
|
+
method: "POST",
|
|
891
|
+
headers: {
|
|
892
|
+
accept: "application/json",
|
|
893
|
+
"x-publishable-key": pk,
|
|
894
|
+
"Content-Type": "application/json"
|
|
895
|
+
},
|
|
896
|
+
body: JSON.stringify(request)
|
|
897
|
+
});
|
|
898
|
+
if (!response.ok) {
|
|
899
|
+
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
900
|
+
throw new Error(`Failed to get deposit quote: ${error.message || response.statusText}`);
|
|
901
|
+
}
|
|
902
|
+
const json = await response.json();
|
|
903
|
+
return json.data;
|
|
904
|
+
}
|
|
905
|
+
async function buildHypercoreTransaction(request, publishableKey) {
|
|
906
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
907
|
+
validatePublishableKey(pk);
|
|
908
|
+
const response = await fetch(`${API_BASE_URL}/v1/public/transactions/hypercore/build`, {
|
|
909
|
+
method: "POST",
|
|
910
|
+
headers: {
|
|
911
|
+
accept: "application/json",
|
|
912
|
+
"x-publishable-key": pk,
|
|
913
|
+
"Content-Type": "application/json"
|
|
914
|
+
},
|
|
915
|
+
body: JSON.stringify(request)
|
|
916
|
+
});
|
|
917
|
+
if (!response.ok) {
|
|
918
|
+
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
919
|
+
throw new Error(
|
|
920
|
+
`Failed to build HyperCore transaction: ${error.message || response.statusText}`
|
|
921
|
+
);
|
|
922
|
+
}
|
|
923
|
+
return response.json();
|
|
924
|
+
}
|
|
925
|
+
async function getCashAppLimits(currency = "usd", publishableKey) {
|
|
861
926
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
862
927
|
validatePublishableKey(pk);
|
|
863
928
|
const response = await fetch(
|
|
864
|
-
`${API_BASE_URL}/v1/public/
|
|
929
|
+
`${API_BASE_URL}/v1/public/onramps/cashapp/limits?currency=${encodeURIComponent(currency)}`,
|
|
865
930
|
{
|
|
866
|
-
method: "
|
|
931
|
+
method: "GET",
|
|
867
932
|
headers: {
|
|
868
933
|
accept: "application/json",
|
|
869
|
-
"x-publishable-key": pk
|
|
870
|
-
|
|
871
|
-
},
|
|
872
|
-
body: JSON.stringify({ client_secret: clientSecret })
|
|
934
|
+
"x-publishable-key": pk
|
|
935
|
+
}
|
|
873
936
|
}
|
|
874
937
|
);
|
|
875
938
|
if (!response.ok) {
|
|
876
939
|
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
877
|
-
throw new Error(
|
|
878
|
-
`Failed to list payment intent executions: ${error.message || response.statusText}`
|
|
879
|
-
);
|
|
940
|
+
throw new Error(`Failed to get Cash App limits: ${error.message || response.statusText}`);
|
|
880
941
|
}
|
|
881
942
|
return response.json();
|
|
882
943
|
}
|
|
883
|
-
async function
|
|
944
|
+
async function createCashAppSession(request, publishableKey) {
|
|
884
945
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
885
946
|
validatePublishableKey(pk);
|
|
886
|
-
const response = await fetch(`${API_BASE_URL}/v1/public/
|
|
947
|
+
const response = await fetch(`${API_BASE_URL}/v1/public/onramps/cashapp/sessions`, {
|
|
887
948
|
method: "POST",
|
|
888
949
|
headers: {
|
|
889
950
|
accept: "application/json",
|
|
@@ -894,41 +955,42 @@ async function getDepositQuote(request, publishableKey) {
|
|
|
894
955
|
});
|
|
895
956
|
if (!response.ok) {
|
|
896
957
|
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
897
|
-
throw new Error(
|
|
898
|
-
`Failed to get deposit quote: ${error.message || response.statusText}`
|
|
899
|
-
);
|
|
958
|
+
throw new Error(`Failed to create Cash App session: ${error.message || response.statusText}`);
|
|
900
959
|
}
|
|
901
|
-
|
|
902
|
-
return json.data;
|
|
960
|
+
return response.json();
|
|
903
961
|
}
|
|
904
|
-
async function
|
|
962
|
+
async function getCashAppSessionStatus(externalId, publishableKey) {
|
|
905
963
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
906
964
|
validatePublishableKey(pk);
|
|
907
965
|
const response = await fetch(
|
|
908
|
-
`${API_BASE_URL}/v1/public/
|
|
966
|
+
`${API_BASE_URL}/v1/public/onramps/cashapp/sessions/${encodeURIComponent(externalId)}/status`,
|
|
909
967
|
{
|
|
910
|
-
method: "
|
|
968
|
+
method: "GET",
|
|
911
969
|
headers: {
|
|
912
970
|
accept: "application/json",
|
|
913
|
-
"x-publishable-key": pk
|
|
914
|
-
|
|
915
|
-
},
|
|
916
|
-
body: JSON.stringify(request)
|
|
971
|
+
"x-publishable-key": pk
|
|
972
|
+
}
|
|
917
973
|
}
|
|
918
974
|
);
|
|
919
975
|
if (!response.ok) {
|
|
920
976
|
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
921
977
|
throw new Error(
|
|
922
|
-
`Failed to
|
|
978
|
+
`Failed to get Cash App session status: ${error.message || response.statusText}`
|
|
923
979
|
);
|
|
924
980
|
}
|
|
925
981
|
return response.json();
|
|
926
982
|
}
|
|
927
|
-
async function
|
|
983
|
+
async function stripeGetDefaultToken(params, publishableKey) {
|
|
928
984
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
929
985
|
validatePublishableKey(pk);
|
|
986
|
+
const query = new URLSearchParams({
|
|
987
|
+
token_address: params.tokenAddress,
|
|
988
|
+
chain_id: params.chainId,
|
|
989
|
+
chain_type: params.chainType
|
|
990
|
+
});
|
|
991
|
+
if (params.countryCode) query.append("country_code", params.countryCode);
|
|
930
992
|
const response = await fetch(
|
|
931
|
-
`${API_BASE_URL}/
|
|
993
|
+
`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/default_token?${query.toString()}`,
|
|
932
994
|
{
|
|
933
995
|
method: "GET",
|
|
934
996
|
headers: {
|
|
@@ -939,71 +1001,315 @@ async function getCashAppLimits(currency = "usd", publishableKey) {
|
|
|
939
1001
|
);
|
|
940
1002
|
if (!response.ok) {
|
|
941
1003
|
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
942
|
-
|
|
943
|
-
`Failed to get Cash App limits: ${error.message || response.statusText}`
|
|
944
|
-
);
|
|
1004
|
+
throwStripeError("Failed to get Stripe default token", response, error);
|
|
945
1005
|
}
|
|
946
1006
|
return response.json();
|
|
947
1007
|
}
|
|
948
|
-
|
|
1008
|
+
var HEADLESS_STRIPE_BASE = "/v1/public/onramps/headless/stripe";
|
|
1009
|
+
var StripeApiResponseError = class extends Error {
|
|
1010
|
+
constructor(message, statusCode, stripeCode, errorType) {
|
|
1011
|
+
super(message);
|
|
1012
|
+
this.statusCode = statusCode;
|
|
1013
|
+
this.stripeCode = stripeCode;
|
|
1014
|
+
this.errorType = errorType;
|
|
1015
|
+
this.name = "StripeApiResponseError";
|
|
1016
|
+
}
|
|
1017
|
+
};
|
|
1018
|
+
function throwStripeError(prefix, response, error) {
|
|
1019
|
+
const stripeError = error.details?.stripe_error;
|
|
1020
|
+
const detailMessage = stripeError?.message || error.message || response.statusText;
|
|
1021
|
+
throw new StripeApiResponseError(
|
|
1022
|
+
`${prefix}: ${detailMessage}`,
|
|
1023
|
+
response.status,
|
|
1024
|
+
stripeError?.code,
|
|
1025
|
+
error.error_type
|
|
1026
|
+
);
|
|
1027
|
+
}
|
|
1028
|
+
async function stripeGetConfig(publishableKey) {
|
|
1029
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1030
|
+
validatePublishableKey(pk);
|
|
1031
|
+
const response = await fetch(`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/config`, {
|
|
1032
|
+
method: "GET",
|
|
1033
|
+
headers: {
|
|
1034
|
+
accept: "application/json",
|
|
1035
|
+
"x-publishable-key": pk
|
|
1036
|
+
}
|
|
1037
|
+
});
|
|
1038
|
+
if (!response.ok) {
|
|
1039
|
+
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
1040
|
+
throwStripeError("Failed to get Stripe config", response, error);
|
|
1041
|
+
}
|
|
1042
|
+
return response.json();
|
|
1043
|
+
}
|
|
1044
|
+
async function stripeCreateAuthIntent(email, publishableKey) {
|
|
1045
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1046
|
+
validatePublishableKey(pk);
|
|
1047
|
+
const response = await fetch(`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/oauth/start`, {
|
|
1048
|
+
method: "POST",
|
|
1049
|
+
headers: {
|
|
1050
|
+
accept: "application/json",
|
|
1051
|
+
"x-publishable-key": pk,
|
|
1052
|
+
"Content-Type": "application/json"
|
|
1053
|
+
},
|
|
1054
|
+
body: JSON.stringify({ email })
|
|
1055
|
+
});
|
|
1056
|
+
if (!response.ok) {
|
|
1057
|
+
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
1058
|
+
throwStripeError("Failed to create Stripe auth intent", response, error);
|
|
1059
|
+
}
|
|
1060
|
+
return response.json();
|
|
1061
|
+
}
|
|
1062
|
+
async function stripeExchangeTokens(authIntentId, publishableKey) {
|
|
1063
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1064
|
+
validatePublishableKey(pk);
|
|
1065
|
+
const response = await fetch(`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/oauth/token`, {
|
|
1066
|
+
method: "POST",
|
|
1067
|
+
headers: {
|
|
1068
|
+
accept: "application/json",
|
|
1069
|
+
"x-publishable-key": pk,
|
|
1070
|
+
"Content-Type": "application/json"
|
|
1071
|
+
},
|
|
1072
|
+
body: JSON.stringify({ auth_intent_id: authIntentId })
|
|
1073
|
+
});
|
|
1074
|
+
if (!response.ok) {
|
|
1075
|
+
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
1076
|
+
throwStripeError("Failed to exchange Stripe tokens", response, error);
|
|
1077
|
+
}
|
|
1078
|
+
return response.json();
|
|
1079
|
+
}
|
|
1080
|
+
async function stripeRefreshToken(refreshToken, publishableKey) {
|
|
1081
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1082
|
+
validatePublishableKey(pk);
|
|
1083
|
+
const response = await fetch(`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/oauth/token/refresh`, {
|
|
1084
|
+
method: "POST",
|
|
1085
|
+
headers: {
|
|
1086
|
+
accept: "application/json",
|
|
1087
|
+
"x-publishable-key": pk,
|
|
1088
|
+
"Content-Type": "application/json"
|
|
1089
|
+
},
|
|
1090
|
+
body: JSON.stringify({ refresh_token: refreshToken })
|
|
1091
|
+
});
|
|
1092
|
+
if (!response.ok) {
|
|
1093
|
+
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
1094
|
+
throwStripeError("Failed to refresh Stripe token", response, error);
|
|
1095
|
+
}
|
|
1096
|
+
return response.json();
|
|
1097
|
+
}
|
|
1098
|
+
async function stripeGetCustomer(customerId, oauthToken, publishableKey) {
|
|
949
1099
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
950
1100
|
validatePublishableKey(pk);
|
|
951
1101
|
const response = await fetch(
|
|
952
|
-
`${API_BASE_URL}/
|
|
1102
|
+
`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/customers/${encodeURIComponent(customerId)}`,
|
|
953
1103
|
{
|
|
954
|
-
method: "
|
|
1104
|
+
method: "GET",
|
|
955
1105
|
headers: {
|
|
956
1106
|
accept: "application/json",
|
|
957
1107
|
"x-publishable-key": pk,
|
|
958
|
-
"
|
|
959
|
-
}
|
|
960
|
-
body: JSON.stringify(request)
|
|
1108
|
+
"x-stripe-oauth-token": oauthToken
|
|
1109
|
+
}
|
|
961
1110
|
}
|
|
962
1111
|
);
|
|
963
1112
|
if (!response.ok) {
|
|
964
1113
|
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
965
|
-
|
|
966
|
-
`Failed to create Cash App session: ${error.message || response.statusText}`
|
|
967
|
-
);
|
|
1114
|
+
throwStripeError("Failed to get Stripe customer", response, error);
|
|
968
1115
|
}
|
|
969
1116
|
return response.json();
|
|
970
1117
|
}
|
|
971
|
-
async function
|
|
1118
|
+
async function stripeListWallets(customerId, oauthToken, publishableKey) {
|
|
972
1119
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
973
1120
|
validatePublishableKey(pk);
|
|
974
1121
|
const response = await fetch(
|
|
975
|
-
`${API_BASE_URL}/
|
|
1122
|
+
`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/customers/${encodeURIComponent(customerId)}/wallet_addresses`,
|
|
976
1123
|
{
|
|
977
1124
|
method: "GET",
|
|
978
1125
|
headers: {
|
|
979
1126
|
accept: "application/json",
|
|
980
|
-
"x-publishable-key": pk
|
|
1127
|
+
"x-publishable-key": pk,
|
|
1128
|
+
"x-stripe-oauth-token": oauthToken
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
);
|
|
1132
|
+
if (!response.ok) {
|
|
1133
|
+
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
1134
|
+
throwStripeError("Failed to list Stripe wallets", response, error);
|
|
1135
|
+
}
|
|
1136
|
+
return response.json();
|
|
1137
|
+
}
|
|
1138
|
+
async function stripeListPaymentTokens(customerId, oauthToken, publishableKey) {
|
|
1139
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1140
|
+
validatePublishableKey(pk);
|
|
1141
|
+
const response = await fetch(
|
|
1142
|
+
`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/customers/${encodeURIComponent(customerId)}/payment_tokens`,
|
|
1143
|
+
{
|
|
1144
|
+
method: "GET",
|
|
1145
|
+
headers: {
|
|
1146
|
+
accept: "application/json",
|
|
1147
|
+
"x-publishable-key": pk,
|
|
1148
|
+
"x-stripe-oauth-token": oauthToken
|
|
981
1149
|
}
|
|
982
1150
|
}
|
|
983
1151
|
);
|
|
984
1152
|
if (!response.ok) {
|
|
985
1153
|
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
986
1154
|
throw new Error(
|
|
987
|
-
`Failed to
|
|
1155
|
+
`Failed to list Stripe payment tokens: ${error.message || response.statusText}`
|
|
988
1156
|
);
|
|
989
1157
|
}
|
|
990
1158
|
return response.json();
|
|
991
1159
|
}
|
|
992
|
-
async function
|
|
1160
|
+
async function stripeCreateSession(request, oauthToken, publishableKey) {
|
|
1161
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1162
|
+
validatePublishableKey(pk);
|
|
1163
|
+
const response = await fetch(`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/sessions`, {
|
|
1164
|
+
method: "POST",
|
|
1165
|
+
headers: {
|
|
1166
|
+
accept: "application/json",
|
|
1167
|
+
"x-publishable-key": pk,
|
|
1168
|
+
"x-stripe-oauth-token": oauthToken,
|
|
1169
|
+
"Content-Type": "application/json"
|
|
1170
|
+
},
|
|
1171
|
+
body: JSON.stringify({
|
|
1172
|
+
crypto_customer_id: request.cryptoCustomerId,
|
|
1173
|
+
payment_token: request.paymentToken,
|
|
1174
|
+
source_amount: request.sourceAmount,
|
|
1175
|
+
source_currency: request.sourceCurrency,
|
|
1176
|
+
destination_currency: request.destinationCurrency,
|
|
1177
|
+
destination_network: request.destinationNetwork,
|
|
1178
|
+
wallet_address: request.walletAddress
|
|
1179
|
+
})
|
|
1180
|
+
});
|
|
1181
|
+
if (!response.ok) {
|
|
1182
|
+
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
1183
|
+
throwStripeError("Failed to create Stripe session", response, error);
|
|
1184
|
+
}
|
|
1185
|
+
return response.json();
|
|
1186
|
+
}
|
|
1187
|
+
async function stripeConfirmSession(sessionId, oauthToken, request, publishableKey) {
|
|
993
1188
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
994
1189
|
validatePublishableKey(pk);
|
|
995
1190
|
const response = await fetch(
|
|
996
|
-
`${API_BASE_URL}/
|
|
1191
|
+
`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/sessions/${encodeURIComponent(sessionId)}/confirm`,
|
|
997
1192
|
{
|
|
998
1193
|
method: "POST",
|
|
999
1194
|
headers: {
|
|
1000
1195
|
accept: "application/json",
|
|
1001
1196
|
"x-publishable-key": pk,
|
|
1197
|
+
"x-stripe-oauth-token": oauthToken,
|
|
1002
1198
|
"Content-Type": "application/json"
|
|
1003
1199
|
},
|
|
1004
|
-
body: JSON.stringify(request)
|
|
1200
|
+
body: JSON.stringify(request?.mandateData ? { mandate_data: request.mandateData } : {})
|
|
1201
|
+
}
|
|
1202
|
+
);
|
|
1203
|
+
if (!response.ok) {
|
|
1204
|
+
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
1205
|
+
throwStripeError("Failed to confirm Stripe session", response, error);
|
|
1206
|
+
}
|
|
1207
|
+
return response.json();
|
|
1208
|
+
}
|
|
1209
|
+
async function stripeRefreshQuote(sessionId, oauthToken, publishableKey) {
|
|
1210
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1211
|
+
validatePublishableKey(pk);
|
|
1212
|
+
const response = await fetch(
|
|
1213
|
+
`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/sessions/${encodeURIComponent(sessionId)}/quote/refresh`,
|
|
1214
|
+
{
|
|
1215
|
+
method: "POST",
|
|
1216
|
+
headers: {
|
|
1217
|
+
accept: "application/json",
|
|
1218
|
+
"x-publishable-key": pk,
|
|
1219
|
+
"x-stripe-oauth-token": oauthToken
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
);
|
|
1223
|
+
if (!response.ok) {
|
|
1224
|
+
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
1225
|
+
throwStripeError("Failed to refresh Stripe quote", response, error);
|
|
1226
|
+
}
|
|
1227
|
+
return response.json();
|
|
1228
|
+
}
|
|
1229
|
+
async function stripeGetSession(sessionId, oauthToken, publishableKey) {
|
|
1230
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1231
|
+
validatePublishableKey(pk);
|
|
1232
|
+
const response = await fetch(
|
|
1233
|
+
`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/sessions/${encodeURIComponent(sessionId)}`,
|
|
1234
|
+
{
|
|
1235
|
+
method: "GET",
|
|
1236
|
+
headers: {
|
|
1237
|
+
accept: "application/json",
|
|
1238
|
+
"x-publishable-key": pk,
|
|
1239
|
+
"x-stripe-oauth-token": oauthToken
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
);
|
|
1243
|
+
if (!response.ok) {
|
|
1244
|
+
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
1245
|
+
throwStripeError("Failed to get Stripe session", response, error);
|
|
1246
|
+
}
|
|
1247
|
+
return response.json();
|
|
1248
|
+
}
|
|
1249
|
+
async function stripeGetQuotes(request, oauthToken, publishableKey) {
|
|
1250
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1251
|
+
validatePublishableKey(pk);
|
|
1252
|
+
const headers = {
|
|
1253
|
+
accept: "application/json",
|
|
1254
|
+
"x-publishable-key": pk,
|
|
1255
|
+
"Content-Type": "application/json"
|
|
1256
|
+
};
|
|
1257
|
+
if (oauthToken) headers["x-stripe-oauth-token"] = oauthToken;
|
|
1258
|
+
const response = await fetch(`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/quotes`, {
|
|
1259
|
+
method: "POST",
|
|
1260
|
+
headers,
|
|
1261
|
+
body: JSON.stringify({
|
|
1262
|
+
source_amount: request.sourceAmount,
|
|
1263
|
+
source_currency: request.sourceCurrency,
|
|
1264
|
+
destination_currency: request.destinationCurrency,
|
|
1265
|
+
destination_network: request.destinationNetwork
|
|
1266
|
+
})
|
|
1267
|
+
});
|
|
1268
|
+
if (!response.ok) {
|
|
1269
|
+
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
1270
|
+
throwStripeError("Failed to get Stripe quotes", response, error);
|
|
1271
|
+
}
|
|
1272
|
+
return response.json();
|
|
1273
|
+
}
|
|
1274
|
+
async function stripeGetTransactionLimits(params, oauthToken, publishableKey) {
|
|
1275
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1276
|
+
validatePublishableKey(pk);
|
|
1277
|
+
const query = new URLSearchParams({
|
|
1278
|
+
crypto_customer_id: params.cryptoCustomerId,
|
|
1279
|
+
destination_network: params.destinationNetwork,
|
|
1280
|
+
wallet_address: params.walletAddress
|
|
1281
|
+
});
|
|
1282
|
+
if (params.destinationTag) query.append("destination_tag", params.destinationTag);
|
|
1283
|
+
if (params.refresh) query.append("refresh", "true");
|
|
1284
|
+
const response = await fetch(
|
|
1285
|
+
`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/transaction_limits?${query.toString()}`,
|
|
1286
|
+
{
|
|
1287
|
+
method: "GET",
|
|
1288
|
+
headers: {
|
|
1289
|
+
accept: "application/json",
|
|
1290
|
+
"x-publishable-key": pk,
|
|
1291
|
+
"x-stripe-oauth-token": oauthToken
|
|
1292
|
+
}
|
|
1005
1293
|
}
|
|
1006
1294
|
);
|
|
1295
|
+
if (!response.ok) {
|
|
1296
|
+
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
1297
|
+
throwStripeError("Failed to get Stripe transaction limits", response, error);
|
|
1298
|
+
}
|
|
1299
|
+
return response.json();
|
|
1300
|
+
}
|
|
1301
|
+
async function sendHypercoreTransaction(request, publishableKey) {
|
|
1302
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1303
|
+
validatePublishableKey(pk);
|
|
1304
|
+
const response = await fetch(`${API_BASE_URL}/v1/public/transactions/hypercore/send`, {
|
|
1305
|
+
method: "POST",
|
|
1306
|
+
headers: {
|
|
1307
|
+
accept: "application/json",
|
|
1308
|
+
"x-publishable-key": pk,
|
|
1309
|
+
"Content-Type": "application/json"
|
|
1310
|
+
},
|
|
1311
|
+
body: JSON.stringify(request)
|
|
1312
|
+
});
|
|
1007
1313
|
if (!response.ok) {
|
|
1008
1314
|
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
1009
1315
|
throw new Error(
|
|
@@ -1012,6 +1318,133 @@ async function sendHypercoreTransaction(request, publishableKey) {
|
|
|
1012
1318
|
}
|
|
1013
1319
|
return response.json();
|
|
1014
1320
|
}
|
|
1321
|
+
async function getCoinbaseLegalAgreements(publishableKey) {
|
|
1322
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1323
|
+
validatePublishableKey(pk);
|
|
1324
|
+
const response = await fetch(
|
|
1325
|
+
`${API_BASE_URL}/v1/public/onramps/headless/coinbase/legal_agreements`,
|
|
1326
|
+
{
|
|
1327
|
+
method: "GET",
|
|
1328
|
+
headers: { accept: "application/json", "x-publishable-key": pk }
|
|
1329
|
+
}
|
|
1330
|
+
);
|
|
1331
|
+
if (!response.ok) {
|
|
1332
|
+
throw new Error(`Failed to fetch Coinbase legal agreements: ${response.statusText}`);
|
|
1333
|
+
}
|
|
1334
|
+
return response.json();
|
|
1335
|
+
}
|
|
1336
|
+
var VERIFICATION_BASE = "/v1/public/onramps/verification_sessions";
|
|
1337
|
+
async function jsonOrThrow(response, label) {
|
|
1338
|
+
if (!response.ok) {
|
|
1339
|
+
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
1340
|
+
const body = error;
|
|
1341
|
+
const tag = body.error_type ? ` [${body.error_type}]` : "";
|
|
1342
|
+
throw new Error(`${label}${tag}: ${body.message || response.statusText}`);
|
|
1343
|
+
}
|
|
1344
|
+
return response.json();
|
|
1345
|
+
}
|
|
1346
|
+
async function createOnrampVerificationSession(request, publishableKey) {
|
|
1347
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1348
|
+
validatePublishableKey(pk);
|
|
1349
|
+
const response = await fetch(`${API_BASE_URL}${VERIFICATION_BASE}`, {
|
|
1350
|
+
method: "POST",
|
|
1351
|
+
headers: {
|
|
1352
|
+
accept: "application/json",
|
|
1353
|
+
"x-publishable-key": pk,
|
|
1354
|
+
"Content-Type": "application/json"
|
|
1355
|
+
},
|
|
1356
|
+
body: JSON.stringify(request)
|
|
1357
|
+
});
|
|
1358
|
+
return jsonOrThrow(response, "Failed to create verification session");
|
|
1359
|
+
}
|
|
1360
|
+
async function postVerificationAction(id, factor, action, body, publishableKey) {
|
|
1361
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1362
|
+
validatePublishableKey(pk);
|
|
1363
|
+
const response = await fetch(
|
|
1364
|
+
`${API_BASE_URL}${VERIFICATION_BASE}/${encodeURIComponent(id)}/${factor}/${action}`,
|
|
1365
|
+
{
|
|
1366
|
+
method: "POST",
|
|
1367
|
+
headers: {
|
|
1368
|
+
accept: "application/json",
|
|
1369
|
+
"x-publishable-key": pk,
|
|
1370
|
+
"Content-Type": "application/json"
|
|
1371
|
+
},
|
|
1372
|
+
body: JSON.stringify(body)
|
|
1373
|
+
}
|
|
1374
|
+
);
|
|
1375
|
+
return jsonOrThrow(response, `Failed to ${action} ${factor} OTP`);
|
|
1376
|
+
}
|
|
1377
|
+
async function sendOnrampVerificationOtp(id, factor, clientSecret, publishableKey) {
|
|
1378
|
+
return postVerificationAction(
|
|
1379
|
+
id,
|
|
1380
|
+
factor,
|
|
1381
|
+
"send",
|
|
1382
|
+
{ client_secret: clientSecret },
|
|
1383
|
+
publishableKey
|
|
1384
|
+
);
|
|
1385
|
+
}
|
|
1386
|
+
async function verifyOnrampVerificationOtp(id, factor, clientSecret, code, publishableKey) {
|
|
1387
|
+
return postVerificationAction(
|
|
1388
|
+
id,
|
|
1389
|
+
factor,
|
|
1390
|
+
"verify",
|
|
1391
|
+
{ client_secret: clientSecret, code },
|
|
1392
|
+
publishableKey
|
|
1393
|
+
);
|
|
1394
|
+
}
|
|
1395
|
+
async function exchangeOnrampVerificationToken(id, clientSecret, publishableKey) {
|
|
1396
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1397
|
+
validatePublishableKey(pk);
|
|
1398
|
+
const response = await fetch(
|
|
1399
|
+
`${API_BASE_URL}${VERIFICATION_BASE}/${encodeURIComponent(id)}/token`,
|
|
1400
|
+
{
|
|
1401
|
+
method: "POST",
|
|
1402
|
+
headers: {
|
|
1403
|
+
accept: "application/json",
|
|
1404
|
+
"x-publishable-key": pk,
|
|
1405
|
+
"Content-Type": "application/json"
|
|
1406
|
+
},
|
|
1407
|
+
body: JSON.stringify({ client_secret: clientSecret })
|
|
1408
|
+
}
|
|
1409
|
+
);
|
|
1410
|
+
return jsonOrThrow(
|
|
1411
|
+
response,
|
|
1412
|
+
"Failed to exchange verification token"
|
|
1413
|
+
);
|
|
1414
|
+
}
|
|
1415
|
+
async function getOnrampVerificationSession(id, clientSecret, publishableKey) {
|
|
1416
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1417
|
+
validatePublishableKey(pk);
|
|
1418
|
+
const url = new URL(`${API_BASE_URL}${VERIFICATION_BASE}/${encodeURIComponent(id)}`);
|
|
1419
|
+
url.searchParams.set("client_secret", clientSecret);
|
|
1420
|
+
const response = await fetch(url.toString(), {
|
|
1421
|
+
method: "GET",
|
|
1422
|
+
headers: { accept: "application/json", "x-publishable-key": pk }
|
|
1423
|
+
});
|
|
1424
|
+
return jsonOrThrow(response, "Failed to fetch verification session");
|
|
1425
|
+
}
|
|
1426
|
+
async function createCoinbaseApplePaySession(request, onrampToken, publishableKey, signal) {
|
|
1427
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1428
|
+
validatePublishableKey(pk);
|
|
1429
|
+
const response = await fetch(
|
|
1430
|
+
`${API_BASE_URL}/v1/public/onramps/headless/coinbase/apple_pay/sessions`,
|
|
1431
|
+
{
|
|
1432
|
+
method: "POST",
|
|
1433
|
+
headers: {
|
|
1434
|
+
accept: "application/json",
|
|
1435
|
+
"x-publishable-key": pk,
|
|
1436
|
+
"Content-Type": "application/json",
|
|
1437
|
+
"x-onramp-token": onrampToken
|
|
1438
|
+
},
|
|
1439
|
+
body: JSON.stringify(request),
|
|
1440
|
+
signal
|
|
1441
|
+
}
|
|
1442
|
+
);
|
|
1443
|
+
return jsonOrThrow(
|
|
1444
|
+
response,
|
|
1445
|
+
"Failed to create Apple Pay session"
|
|
1446
|
+
);
|
|
1447
|
+
}
|
|
1015
1448
|
|
|
1016
1449
|
// src/lib/events.ts
|
|
1017
1450
|
var DepositEventType = /* @__PURE__ */ ((DepositEventType2) => {
|
|
@@ -1023,6 +1456,10 @@ var WithdrawEventType = /* @__PURE__ */ ((WithdrawEventType2) => {
|
|
|
1023
1456
|
WithdrawEventType2["DIRECT_EXECUTION_SUCCEEDED"] = "direct_execution.succeeded";
|
|
1024
1457
|
return WithdrawEventType2;
|
|
1025
1458
|
})(WithdrawEventType || {});
|
|
1459
|
+
var CheckoutEventType = /* @__PURE__ */ ((CheckoutEventType2) => {
|
|
1460
|
+
CheckoutEventType2["PAYMENT_INTENT_SUCCEEDED"] = "payment_intent.succeeded";
|
|
1461
|
+
return CheckoutEventType2;
|
|
1462
|
+
})(CheckoutEventType || {});
|
|
1026
1463
|
|
|
1027
1464
|
// src/hooks/use-user-ip.ts
|
|
1028
1465
|
import { useQuery } from "@tanstack/react-query";
|
|
@@ -1157,11 +1594,13 @@ var en_default = {
|
|
|
1157
1594
|
var i18n = en_default;
|
|
1158
1595
|
export {
|
|
1159
1596
|
ActionType,
|
|
1597
|
+
CheckoutEventType,
|
|
1160
1598
|
DepositEventType,
|
|
1161
1599
|
ExecutionStatus,
|
|
1162
1600
|
IneligibilityReason,
|
|
1163
1601
|
IntegrationProvider,
|
|
1164
1602
|
SOLANA_USDC_ADDRESS,
|
|
1603
|
+
StripeApiResponseError,
|
|
1165
1604
|
WithdrawEventType,
|
|
1166
1605
|
authenticateIntegrationOAuth,
|
|
1167
1606
|
buildHypercoreTransaction,
|
|
@@ -1169,19 +1608,25 @@ export {
|
|
|
1169
1608
|
checkHypercoreActivation,
|
|
1170
1609
|
confirmIntegrationTransfer,
|
|
1171
1610
|
createCashAppSession,
|
|
1611
|
+
createCoinbaseApplePaySession,
|
|
1172
1612
|
createDepositAddress,
|
|
1173
1613
|
createExchangeSession,
|
|
1174
1614
|
createIntegrationTransfer,
|
|
1175
1615
|
createOnrampSession,
|
|
1616
|
+
createOnrampVerificationSession,
|
|
1617
|
+
exchangeOnrampVerificationToken,
|
|
1176
1618
|
formatStablecoinAmount,
|
|
1177
1619
|
generateKSUID,
|
|
1178
1620
|
generatePrefixedKSUID,
|
|
1179
1621
|
getAddressBalance,
|
|
1180
1622
|
getAddressBalances,
|
|
1181
1623
|
getApiBaseUrl,
|
|
1624
|
+
getApplePayProviders,
|
|
1625
|
+
getBankTransferProviders,
|
|
1182
1626
|
getCashAppLimits,
|
|
1183
1627
|
getCashAppSessionStatus,
|
|
1184
1628
|
getChainName,
|
|
1629
|
+
getCoinbaseLegalAgreements,
|
|
1185
1630
|
getDefaultOnrampToken,
|
|
1186
1631
|
getDepositAddress,
|
|
1187
1632
|
getDepositQuote,
|
|
@@ -1197,6 +1642,7 @@ export {
|
|
|
1197
1642
|
getIpAddress,
|
|
1198
1643
|
getOnrampQuotes,
|
|
1199
1644
|
getOnrampSessionStartUrl,
|
|
1645
|
+
getOnrampVerificationSession,
|
|
1200
1646
|
getPreferredIconUrl,
|
|
1201
1647
|
getProjectConfig,
|
|
1202
1648
|
getSupportedDepositTokens,
|
|
@@ -1213,9 +1659,25 @@ export {
|
|
|
1213
1659
|
retrievePaymentIntent,
|
|
1214
1660
|
revokeIntegrationToken,
|
|
1215
1661
|
sendHypercoreTransaction,
|
|
1662
|
+
sendOnrampVerificationOtp,
|
|
1216
1663
|
sendSolanaTransaction,
|
|
1217
1664
|
setApiConfig,
|
|
1218
1665
|
startIntegrationOAuth,
|
|
1666
|
+
stripeConfirmSession,
|
|
1667
|
+
stripeCreateAuthIntent,
|
|
1668
|
+
stripeCreateSession,
|
|
1669
|
+
stripeExchangeTokens,
|
|
1670
|
+
stripeGetConfig,
|
|
1671
|
+
stripeGetCustomer,
|
|
1672
|
+
stripeGetDefaultToken,
|
|
1673
|
+
stripeGetQuotes,
|
|
1674
|
+
stripeGetSession,
|
|
1675
|
+
stripeGetTransactionLimits,
|
|
1676
|
+
stripeListPaymentTokens,
|
|
1677
|
+
stripeListWallets,
|
|
1678
|
+
stripeRefreshQuote,
|
|
1679
|
+
stripeRefreshToken,
|
|
1219
1680
|
useUserIp,
|
|
1681
|
+
verifyOnrampVerificationOtp,
|
|
1220
1682
|
verifyRecipientAddress
|
|
1221
1683
|
};
|