@unifold/core 0.1.68-beta.0 → 0.1.68-beta.2
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 +536 -17
- package/dist/index.d.ts +536 -17
- package/dist/index.js +710 -196
- package/dist/index.mjs +683 -196
- 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,18 +311,15 @@ 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
|
}
|
|
@@ -367,9 +342,23 @@ async function getBankTransferProviders(publishableKey, options = {}) {
|
|
|
367
342
|
}
|
|
368
343
|
});
|
|
369
344
|
if (!response.ok) {
|
|
370
|
-
throw new Error(
|
|
371
|
-
|
|
372
|
-
|
|
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}`);
|
|
373
362
|
}
|
|
374
363
|
return response.json();
|
|
375
364
|
}
|
|
@@ -442,10 +431,18 @@ function getChainName(chains, chainType, chainId) {
|
|
|
442
431
|
if (!chainType) return chainId || "Unknown";
|
|
443
432
|
return chainType.charAt(0).toUpperCase() + chainType.slice(1);
|
|
444
433
|
}
|
|
445
|
-
async function getProjectConfig(publishableKey) {
|
|
434
|
+
async function getProjectConfig(publishableKey, options) {
|
|
446
435
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
447
436
|
validatePublishableKey(pk);
|
|
448
|
-
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}` : ""}`;
|
|
449
446
|
const response = await fetch(url, {
|
|
450
447
|
method: "GET",
|
|
451
448
|
headers: {
|
|
@@ -467,9 +464,7 @@ async function getIpAddress() {
|
|
|
467
464
|
}
|
|
468
465
|
});
|
|
469
466
|
if (!response.ok) {
|
|
470
|
-
throw new Error(
|
|
471
|
-
`Failed to fetch IP address information: ${response.statusText}`
|
|
472
|
-
);
|
|
467
|
+
throw new Error(`Failed to fetch IP address information: ${response.statusText}`);
|
|
473
468
|
}
|
|
474
469
|
return response.json();
|
|
475
470
|
}
|
|
@@ -571,31 +566,24 @@ async function verifyRecipientAddress(request, publishableKey) {
|
|
|
571
566
|
body: JSON.stringify(request)
|
|
572
567
|
});
|
|
573
568
|
if (!response.ok) {
|
|
574
|
-
throw new Error(
|
|
575
|
-
`Failed to verify recipient address: ${response.statusText}`
|
|
576
|
-
);
|
|
569
|
+
throw new Error(`Failed to verify recipient address: ${response.statusText}`);
|
|
577
570
|
}
|
|
578
571
|
return response.json();
|
|
579
572
|
}
|
|
580
573
|
async function checkHypercoreActivation(request, publishableKey) {
|
|
581
574
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
582
575
|
validatePublishableKey(pk);
|
|
583
|
-
const response = await fetch(
|
|
584
|
-
|
|
585
|
-
{
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
body: JSON.stringify(request)
|
|
593
|
-
}
|
|
594
|
-
);
|
|
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
|
+
});
|
|
595
585
|
if (!response.ok) {
|
|
596
|
-
throw new Error(
|
|
597
|
-
`HyperCore activation check failed: ${response.statusText}`
|
|
598
|
-
);
|
|
586
|
+
throw new Error(`HyperCore activation check failed: ${response.statusText}`);
|
|
599
587
|
}
|
|
600
588
|
return response.json();
|
|
601
589
|
}
|
|
@@ -603,7 +591,8 @@ async function getExchanges(query, publishableKey) {
|
|
|
603
591
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
604
592
|
validatePublishableKey(pk);
|
|
605
593
|
const params = new URLSearchParams();
|
|
606
|
-
if (query?.destination_currency)
|
|
594
|
+
if (query?.destination_currency)
|
|
595
|
+
params.append("destination_currency", query.destination_currency);
|
|
607
596
|
if (query?.destination_network) params.append("destination_network", query.destination_network);
|
|
608
597
|
const queryString = params.toString();
|
|
609
598
|
const url = `${API_BASE_URL}/v1/public/onramps/exchanges${queryString ? `?${queryString}` : ""}`;
|
|
@@ -623,18 +612,15 @@ async function getExchanges(query, publishableKey) {
|
|
|
623
612
|
async function createExchangeSession(request, publishableKey) {
|
|
624
613
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
625
614
|
validatePublishableKey(pk);
|
|
626
|
-
const response = await fetch(
|
|
627
|
-
|
|
628
|
-
{
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
body: JSON.stringify(request)
|
|
636
|
-
}
|
|
637
|
-
);
|
|
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
|
+
});
|
|
638
624
|
if (!response.ok) {
|
|
639
625
|
throw new Error(`Failed to create exchange session: ${response.statusText}`);
|
|
640
626
|
}
|
|
@@ -787,15 +773,18 @@ async function confirmIntegrationTransfer(transferId, accessToken, mfaCode, publ
|
|
|
787
773
|
validatePublishableKey(pk);
|
|
788
774
|
const body = { access_token: accessToken };
|
|
789
775
|
if (mfaCode) body.mfa_code = mfaCode;
|
|
790
|
-
const response = await fetch(
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
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
|
+
);
|
|
799
788
|
if (!response.ok) {
|
|
800
789
|
const err = await response.json().catch(() => ({ message: response.statusText }));
|
|
801
790
|
throw new Error(`Failed to confirm transfer: ${err.message || response.statusText}`);
|
|
@@ -834,9 +823,7 @@ async function buildSolanaTransaction(request, publishableKey) {
|
|
|
834
823
|
});
|
|
835
824
|
if (!response.ok) {
|
|
836
825
|
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
837
|
-
throw new Error(
|
|
838
|
-
`Failed to build Solana transaction: ${error.message || response.statusText}`
|
|
839
|
-
);
|
|
826
|
+
throw new Error(`Failed to build Solana transaction: ${error.message || response.statusText}`);
|
|
840
827
|
}
|
|
841
828
|
return response.json();
|
|
842
829
|
}
|
|
@@ -854,50 +841,40 @@ async function sendSolanaTransaction(request, publishableKey) {
|
|
|
854
841
|
});
|
|
855
842
|
if (!response.ok) {
|
|
856
843
|
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
857
|
-
throw new Error(
|
|
858
|
-
`Failed to send Solana transaction: ${error.message || response.statusText}`
|
|
859
|
-
);
|
|
844
|
+
throw new Error(`Failed to send Solana transaction: ${error.message || response.statusText}`);
|
|
860
845
|
}
|
|
861
846
|
return response.json();
|
|
862
847
|
}
|
|
863
848
|
async function retrievePaymentIntent(clientSecret, publishableKey) {
|
|
864
849
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
865
850
|
validatePublishableKey(pk);
|
|
866
|
-
const response = await fetch(
|
|
867
|
-
|
|
868
|
-
{
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
body: JSON.stringify({ client_secret: clientSecret })
|
|
876
|
-
}
|
|
877
|
-
);
|
|
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
|
+
});
|
|
878
860
|
if (!response.ok) {
|
|
879
861
|
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
880
|
-
throw new Error(
|
|
881
|
-
`Failed to retrieve payment intent: ${error.message || response.statusText}`
|
|
882
|
-
);
|
|
862
|
+
throw new Error(`Failed to retrieve payment intent: ${error.message || response.statusText}`);
|
|
883
863
|
}
|
|
884
864
|
return response.json();
|
|
885
865
|
}
|
|
886
866
|
async function listPaymentIntentExecutions(clientSecret, publishableKey) {
|
|
887
867
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
888
868
|
validatePublishableKey(pk);
|
|
889
|
-
const response = await fetch(
|
|
890
|
-
|
|
891
|
-
{
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
body: JSON.stringify({ client_secret: clientSecret })
|
|
899
|
-
}
|
|
900
|
-
);
|
|
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
|
+
});
|
|
901
878
|
if (!response.ok) {
|
|
902
879
|
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
903
880
|
throw new Error(
|
|
@@ -920,9 +897,7 @@ async function getDepositQuote(request, publishableKey) {
|
|
|
920
897
|
});
|
|
921
898
|
if (!response.ok) {
|
|
922
899
|
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
923
|
-
throw new Error(
|
|
924
|
-
`Failed to get deposit quote: ${error.message || response.statusText}`
|
|
925
|
-
);
|
|
900
|
+
throw new Error(`Failed to get deposit quote: ${error.message || response.statusText}`);
|
|
926
901
|
}
|
|
927
902
|
const json = await response.json();
|
|
928
903
|
return json.data;
|
|
@@ -930,18 +905,15 @@ async function getDepositQuote(request, publishableKey) {
|
|
|
930
905
|
async function buildHypercoreTransaction(request, publishableKey) {
|
|
931
906
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
932
907
|
validatePublishableKey(pk);
|
|
933
|
-
const response = await fetch(
|
|
934
|
-
|
|
935
|
-
{
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
body: JSON.stringify(request)
|
|
943
|
-
}
|
|
944
|
-
);
|
|
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
|
+
});
|
|
945
917
|
if (!response.ok) {
|
|
946
918
|
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
947
919
|
throw new Error(
|
|
@@ -965,40 +937,60 @@ async function getCashAppLimits(currency = "usd", publishableKey) {
|
|
|
965
937
|
);
|
|
966
938
|
if (!response.ok) {
|
|
967
939
|
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
968
|
-
throw new Error(
|
|
969
|
-
`Failed to get Cash App limits: ${error.message || response.statusText}`
|
|
970
|
-
);
|
|
940
|
+
throw new Error(`Failed to get Cash App limits: ${error.message || response.statusText}`);
|
|
971
941
|
}
|
|
972
942
|
return response.json();
|
|
973
943
|
}
|
|
974
944
|
async function createCashAppSession(request, publishableKey) {
|
|
945
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
946
|
+
validatePublishableKey(pk);
|
|
947
|
+
const response = await fetch(`${API_BASE_URL}/v1/public/onramps/cashapp/sessions`, {
|
|
948
|
+
method: "POST",
|
|
949
|
+
headers: {
|
|
950
|
+
accept: "application/json",
|
|
951
|
+
"x-publishable-key": pk,
|
|
952
|
+
"Content-Type": "application/json"
|
|
953
|
+
},
|
|
954
|
+
body: JSON.stringify(request)
|
|
955
|
+
});
|
|
956
|
+
if (!response.ok) {
|
|
957
|
+
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
958
|
+
throw new Error(`Failed to create Cash App session: ${error.message || response.statusText}`);
|
|
959
|
+
}
|
|
960
|
+
return response.json();
|
|
961
|
+
}
|
|
962
|
+
async function getCashAppSessionStatus(externalId, publishableKey) {
|
|
975
963
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
976
964
|
validatePublishableKey(pk);
|
|
977
965
|
const response = await fetch(
|
|
978
|
-
`${API_BASE_URL}/v1/public/onramps/cashapp/sessions`,
|
|
966
|
+
`${API_BASE_URL}/v1/public/onramps/cashapp/sessions/${encodeURIComponent(externalId)}/status`,
|
|
979
967
|
{
|
|
980
|
-
method: "
|
|
968
|
+
method: "GET",
|
|
981
969
|
headers: {
|
|
982
970
|
accept: "application/json",
|
|
983
|
-
"x-publishable-key": pk
|
|
984
|
-
|
|
985
|
-
},
|
|
986
|
-
body: JSON.stringify(request)
|
|
971
|
+
"x-publishable-key": pk
|
|
972
|
+
}
|
|
987
973
|
}
|
|
988
974
|
);
|
|
989
975
|
if (!response.ok) {
|
|
990
976
|
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
991
977
|
throw new Error(
|
|
992
|
-
`Failed to
|
|
978
|
+
`Failed to get Cash App session status: ${error.message || response.statusText}`
|
|
993
979
|
);
|
|
994
980
|
}
|
|
995
981
|
return response.json();
|
|
996
982
|
}
|
|
997
|
-
async function
|
|
983
|
+
async function stripeGetDefaultToken(params, publishableKey) {
|
|
998
984
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
999
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);
|
|
1000
992
|
const response = await fetch(
|
|
1001
|
-
`${API_BASE_URL}/
|
|
993
|
+
`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/default_token?${query.toString()}`,
|
|
1002
994
|
{
|
|
1003
995
|
method: "GET",
|
|
1004
996
|
headers: {
|
|
@@ -1007,29 +999,317 @@ async function getCashAppSessionStatus(externalId, publishableKey) {
|
|
|
1007
999
|
}
|
|
1008
1000
|
}
|
|
1009
1001
|
);
|
|
1002
|
+
if (!response.ok) {
|
|
1003
|
+
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
1004
|
+
throwStripeError("Failed to get Stripe default token", response, error);
|
|
1005
|
+
}
|
|
1006
|
+
return response.json();
|
|
1007
|
+
}
|
|
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) {
|
|
1099
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1100
|
+
validatePublishableKey(pk);
|
|
1101
|
+
const response = await fetch(
|
|
1102
|
+
`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/customers/${encodeURIComponent(customerId)}`,
|
|
1103
|
+
{
|
|
1104
|
+
method: "GET",
|
|
1105
|
+
headers: {
|
|
1106
|
+
accept: "application/json",
|
|
1107
|
+
"x-publishable-key": pk,
|
|
1108
|
+
"x-stripe-oauth-token": oauthToken
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
);
|
|
1112
|
+
if (!response.ok) {
|
|
1113
|
+
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
1114
|
+
throwStripeError("Failed to get Stripe customer", response, error);
|
|
1115
|
+
}
|
|
1116
|
+
return response.json();
|
|
1117
|
+
}
|
|
1118
|
+
async function stripeListWallets(customerId, oauthToken, publishableKey) {
|
|
1119
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1120
|
+
validatePublishableKey(pk);
|
|
1121
|
+
const response = await fetch(
|
|
1122
|
+
`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/customers/${encodeURIComponent(customerId)}/wallet_addresses`,
|
|
1123
|
+
{
|
|
1124
|
+
method: "GET",
|
|
1125
|
+
headers: {
|
|
1126
|
+
accept: "application/json",
|
|
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
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
);
|
|
1010
1152
|
if (!response.ok) {
|
|
1011
1153
|
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
1012
1154
|
throw new Error(
|
|
1013
|
-
`Failed to
|
|
1155
|
+
`Failed to list Stripe payment tokens: ${error.message || response.statusText}`
|
|
1014
1156
|
);
|
|
1015
1157
|
}
|
|
1016
1158
|
return response.json();
|
|
1017
1159
|
}
|
|
1018
|
-
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) {
|
|
1019
1188
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1020
1189
|
validatePublishableKey(pk);
|
|
1021
1190
|
const response = await fetch(
|
|
1022
|
-
`${API_BASE_URL}/
|
|
1191
|
+
`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/sessions/${encodeURIComponent(sessionId)}/confirm`,
|
|
1023
1192
|
{
|
|
1024
1193
|
method: "POST",
|
|
1025
1194
|
headers: {
|
|
1026
1195
|
accept: "application/json",
|
|
1027
1196
|
"x-publishable-key": pk,
|
|
1197
|
+
"x-stripe-oauth-token": oauthToken,
|
|
1028
1198
|
"Content-Type": "application/json"
|
|
1029
1199
|
},
|
|
1030
|
-
body: JSON.stringify(request)
|
|
1200
|
+
body: JSON.stringify(request?.mandateData ? { mandate_data: request.mandateData } : {})
|
|
1031
1201
|
}
|
|
1032
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
|
+
}
|
|
1293
|
+
}
|
|
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
|
+
});
|
|
1033
1313
|
if (!response.ok) {
|
|
1034
1314
|
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
1035
1315
|
throw new Error(
|
|
@@ -1038,6 +1318,186 @@ async function sendHypercoreTransaction(request, publishableKey) {
|
|
|
1038
1318
|
}
|
|
1039
1319
|
return response.json();
|
|
1040
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
|
+
function isApplePayLimitReached(response) {
|
|
1427
|
+
return response.limits.some((l) => l.remaining === "0");
|
|
1428
|
+
}
|
|
1429
|
+
function getApplePayLimitUpgradeStatus(response) {
|
|
1430
|
+
const opt = response.limit_upgrade_options?.[0];
|
|
1431
|
+
if (!opt || typeof opt.status !== "string") return null;
|
|
1432
|
+
return opt.status;
|
|
1433
|
+
}
|
|
1434
|
+
async function getCoinbaseApplePayLimits(phone, publishableKey, signal) {
|
|
1435
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1436
|
+
validatePublishableKey(pk);
|
|
1437
|
+
const response = await fetch(
|
|
1438
|
+
`${API_BASE_URL}/v1/public/onramps/headless/coinbase/apple_pay/limits`,
|
|
1439
|
+
{
|
|
1440
|
+
method: "POST",
|
|
1441
|
+
headers: {
|
|
1442
|
+
accept: "application/json",
|
|
1443
|
+
"x-publishable-key": pk,
|
|
1444
|
+
"Content-Type": "application/json"
|
|
1445
|
+
},
|
|
1446
|
+
body: JSON.stringify({ phone }),
|
|
1447
|
+
signal
|
|
1448
|
+
}
|
|
1449
|
+
);
|
|
1450
|
+
const raw = await jsonOrThrow(response, "Failed to fetch Apple Pay limits");
|
|
1451
|
+
return {
|
|
1452
|
+
limits: raw.limits,
|
|
1453
|
+
limit_upgrade_options: raw.limit_upgrade_options,
|
|
1454
|
+
limit_reached: isApplePayLimitReached(raw),
|
|
1455
|
+
upgrade_status: getApplePayLimitUpgradeStatus(raw)
|
|
1456
|
+
};
|
|
1457
|
+
}
|
|
1458
|
+
async function requestCoinbaseApplePayLimitUpgrade(request, publishableKey, signal) {
|
|
1459
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1460
|
+
validatePublishableKey(pk);
|
|
1461
|
+
const response = await fetch(
|
|
1462
|
+
`${API_BASE_URL}/v1/public/onramps/headless/coinbase/apple_pay/limits/upgrade`,
|
|
1463
|
+
{
|
|
1464
|
+
method: "POST",
|
|
1465
|
+
headers: {
|
|
1466
|
+
accept: "application/json",
|
|
1467
|
+
"x-publishable-key": pk,
|
|
1468
|
+
"Content-Type": "application/json"
|
|
1469
|
+
},
|
|
1470
|
+
body: JSON.stringify(request),
|
|
1471
|
+
signal
|
|
1472
|
+
}
|
|
1473
|
+
);
|
|
1474
|
+
return jsonOrThrow(
|
|
1475
|
+
response,
|
|
1476
|
+
"Failed to request Apple Pay limit upgrade"
|
|
1477
|
+
);
|
|
1478
|
+
}
|
|
1479
|
+
async function createCoinbaseApplePaySession(request, onrampToken, publishableKey, signal) {
|
|
1480
|
+
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1481
|
+
validatePublishableKey(pk);
|
|
1482
|
+
const response = await fetch(
|
|
1483
|
+
`${API_BASE_URL}/v1/public/onramps/headless/coinbase/apple_pay/sessions`,
|
|
1484
|
+
{
|
|
1485
|
+
method: "POST",
|
|
1486
|
+
headers: {
|
|
1487
|
+
accept: "application/json",
|
|
1488
|
+
"x-publishable-key": pk,
|
|
1489
|
+
"Content-Type": "application/json",
|
|
1490
|
+
"x-onramp-token": onrampToken
|
|
1491
|
+
},
|
|
1492
|
+
body: JSON.stringify(request),
|
|
1493
|
+
signal
|
|
1494
|
+
}
|
|
1495
|
+
);
|
|
1496
|
+
return jsonOrThrow(
|
|
1497
|
+
response,
|
|
1498
|
+
"Failed to create Apple Pay session"
|
|
1499
|
+
);
|
|
1500
|
+
}
|
|
1041
1501
|
|
|
1042
1502
|
// src/lib/events.ts
|
|
1043
1503
|
var DepositEventType = /* @__PURE__ */ ((DepositEventType2) => {
|
|
@@ -1193,6 +1653,7 @@ export {
|
|
|
1193
1653
|
IneligibilityReason,
|
|
1194
1654
|
IntegrationProvider,
|
|
1195
1655
|
SOLANA_USDC_ADDRESS,
|
|
1656
|
+
StripeApiResponseError,
|
|
1196
1657
|
WithdrawEventType,
|
|
1197
1658
|
authenticateIntegrationOAuth,
|
|
1198
1659
|
buildHypercoreTransaction,
|
|
@@ -1200,20 +1661,27 @@ export {
|
|
|
1200
1661
|
checkHypercoreActivation,
|
|
1201
1662
|
confirmIntegrationTransfer,
|
|
1202
1663
|
createCashAppSession,
|
|
1664
|
+
createCoinbaseApplePaySession,
|
|
1203
1665
|
createDepositAddress,
|
|
1204
1666
|
createExchangeSession,
|
|
1205
1667
|
createIntegrationTransfer,
|
|
1206
1668
|
createOnrampSession,
|
|
1669
|
+
createOnrampVerificationSession,
|
|
1670
|
+
exchangeOnrampVerificationToken,
|
|
1207
1671
|
formatStablecoinAmount,
|
|
1208
1672
|
generateKSUID,
|
|
1209
1673
|
generatePrefixedKSUID,
|
|
1210
1674
|
getAddressBalance,
|
|
1211
1675
|
getAddressBalances,
|
|
1212
1676
|
getApiBaseUrl,
|
|
1677
|
+
getApplePayLimitUpgradeStatus,
|
|
1678
|
+
getApplePayProviders,
|
|
1213
1679
|
getBankTransferProviders,
|
|
1214
1680
|
getCashAppLimits,
|
|
1215
1681
|
getCashAppSessionStatus,
|
|
1216
1682
|
getChainName,
|
|
1683
|
+
getCoinbaseApplePayLimits,
|
|
1684
|
+
getCoinbaseLegalAgreements,
|
|
1217
1685
|
getDefaultOnrampToken,
|
|
1218
1686
|
getDepositAddress,
|
|
1219
1687
|
getDepositQuote,
|
|
@@ -1229,6 +1697,7 @@ export {
|
|
|
1229
1697
|
getIpAddress,
|
|
1230
1698
|
getOnrampQuotes,
|
|
1231
1699
|
getOnrampSessionStartUrl,
|
|
1700
|
+
getOnrampVerificationSession,
|
|
1232
1701
|
getPreferredIconUrl,
|
|
1233
1702
|
getProjectConfig,
|
|
1234
1703
|
getSupportedDepositTokens,
|
|
@@ -1238,16 +1707,34 @@ export {
|
|
|
1238
1707
|
getWalletByChainType,
|
|
1239
1708
|
getWalletMobileDeepLink,
|
|
1240
1709
|
i18n,
|
|
1710
|
+
isApplePayLimitReached,
|
|
1241
1711
|
listPaymentIntentExecutions,
|
|
1242
1712
|
pollDirectExecutions,
|
|
1243
1713
|
queryExecutions,
|
|
1244
1714
|
refreshIntegrationToken,
|
|
1715
|
+
requestCoinbaseApplePayLimitUpgrade,
|
|
1245
1716
|
retrievePaymentIntent,
|
|
1246
1717
|
revokeIntegrationToken,
|
|
1247
1718
|
sendHypercoreTransaction,
|
|
1719
|
+
sendOnrampVerificationOtp,
|
|
1248
1720
|
sendSolanaTransaction,
|
|
1249
1721
|
setApiConfig,
|
|
1250
1722
|
startIntegrationOAuth,
|
|
1723
|
+
stripeConfirmSession,
|
|
1724
|
+
stripeCreateAuthIntent,
|
|
1725
|
+
stripeCreateSession,
|
|
1726
|
+
stripeExchangeTokens,
|
|
1727
|
+
stripeGetConfig,
|
|
1728
|
+
stripeGetCustomer,
|
|
1729
|
+
stripeGetDefaultToken,
|
|
1730
|
+
stripeGetQuotes,
|
|
1731
|
+
stripeGetSession,
|
|
1732
|
+
stripeGetTransactionLimits,
|
|
1733
|
+
stripeListPaymentTokens,
|
|
1734
|
+
stripeListWallets,
|
|
1735
|
+
stripeRefreshQuote,
|
|
1736
|
+
stripeRefreshToken,
|
|
1251
1737
|
useUserIp,
|
|
1738
|
+
verifyOnrampVerificationOtp,
|
|
1252
1739
|
verifyRecipientAddress
|
|
1253
1740
|
};
|