@usdctofiat/offramp 3.0.3 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +42 -1
- package/README.md +128 -23
- package/dist/{chunk-4KKKDDES.js → chunk-QMO7HTBZ.js} +255 -96
- package/dist/chunk-QMO7HTBZ.js.map +1 -0
- package/dist/{errors-D9bV_DWE.d.cts → errors-DYCRKcnY.d.cts} +44 -6
- package/dist/{errors-D9bV_DWE.d.ts → errors-DYCRKcnY.d.ts} +44 -6
- package/dist/index.cjs +259 -92
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +71 -6
- package/dist/index.d.ts +71 -6
- package/dist/index.js +9 -3
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +329 -111
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +24 -13
- package/dist/react.d.ts +24 -13
- package/dist/react.js +106 -27
- package/dist/react.js.map +1 -1
- package/package.json +2 -2
- package/dist/chunk-4KKKDDES.js.map +0 -1
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
// src/config.ts
|
|
2
2
|
import { getContracts, getGatingServiceAddress } from "@zkp2p/sdk";
|
|
3
|
-
var SDK_VERSION = "
|
|
3
|
+
var SDK_VERSION = "4.0.0";
|
|
4
4
|
var BASE_CHAIN_ID = 8453;
|
|
5
5
|
var RUNTIME_ENV = "production";
|
|
6
6
|
var API_BASE_URL = "https://api.zkp2p.xyz";
|
|
7
7
|
var BASE_RPC_URL = "https://mainnet.base.org";
|
|
8
|
+
function resolveApiBaseUrl(override) {
|
|
9
|
+
const trimmed = override?.trim();
|
|
10
|
+
return (trimmed && trimmed.length > 0 ? trimmed : API_BASE_URL).replace(/\/$/, "");
|
|
11
|
+
}
|
|
8
12
|
var contracts = getContracts(BASE_CHAIN_ID, RUNTIME_ENV);
|
|
9
13
|
var addresses = contracts.addresses;
|
|
10
14
|
var addrs = addresses;
|
|
@@ -21,13 +25,48 @@ var DEFAULT_INTENT_GUARDIAN_ADDRESS = "0xe29a5BD4D0CEbA6C125A0361E7D20ab4eA275C2
|
|
|
21
25
|
var REFERRER = "galleonlabs";
|
|
22
26
|
var MIN_DEPOSIT_USDC = 1;
|
|
23
27
|
var MIN_ORDER_USDC = 1;
|
|
28
|
+
var MAX_ORDER_USDC = 2500;
|
|
24
29
|
var INDEXER_MAX_ATTEMPTS = 12;
|
|
25
30
|
var INDEXER_INITIAL_DELAY_MS = 1e3;
|
|
26
31
|
var INDEXER_MAX_DELAY_MS = 1e4;
|
|
27
32
|
var PAYEE_REGISTRATION_TIMEOUT_MS = 8e3;
|
|
28
33
|
|
|
34
|
+
// src/errors.ts
|
|
35
|
+
var MakersCreateError = class extends Error {
|
|
36
|
+
status;
|
|
37
|
+
body;
|
|
38
|
+
constructor(message, status, body) {
|
|
39
|
+
super(message);
|
|
40
|
+
this.name = "MakersCreateError";
|
|
41
|
+
this.status = status;
|
|
42
|
+
this.body = body;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
var OfframpError = class extends Error {
|
|
46
|
+
code;
|
|
47
|
+
step;
|
|
48
|
+
cause;
|
|
49
|
+
txHash;
|
|
50
|
+
depositId;
|
|
51
|
+
constructor(message, code, step, cause, details) {
|
|
52
|
+
super(message);
|
|
53
|
+
this.name = "OfframpError";
|
|
54
|
+
this.code = code;
|
|
55
|
+
this.step = step;
|
|
56
|
+
this.cause = cause;
|
|
57
|
+
this.txHash = details?.txHash;
|
|
58
|
+
this.depositId = details?.depositId;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
function isUserCancellation(error) {
|
|
62
|
+
if (!(error instanceof Error)) return false;
|
|
63
|
+
const msg = error.message.toLowerCase();
|
|
64
|
+
return msg.includes("user rejected") || msg.includes("user denied") || msg.includes("user cancelled") || msg.includes("rejected the request") || msg.includes("action_rejected");
|
|
65
|
+
}
|
|
66
|
+
|
|
29
67
|
// src/platforms.ts
|
|
30
68
|
import {
|
|
69
|
+
apiUploadSellerCredentialBundle,
|
|
31
70
|
currencyInfo,
|
|
32
71
|
getCurrencyInfoFromHash,
|
|
33
72
|
getPaymentMethodsCatalog,
|
|
@@ -394,6 +433,113 @@ function getPeerExtensionRegistrationInfo(platform) {
|
|
|
394
433
|
const entry = getPlatformById(platform);
|
|
395
434
|
return entry?.extensionRegistration ?? null;
|
|
396
435
|
}
|
|
436
|
+
function getPeerExtensionRegistrationAuthParams(platform, options = {}) {
|
|
437
|
+
const info = getPeerExtensionRegistrationInfo(platform);
|
|
438
|
+
if (!info) return null;
|
|
439
|
+
const params = {
|
|
440
|
+
actionType: `transfer_${info.providerId}`,
|
|
441
|
+
captureMode: "sellerCredential",
|
|
442
|
+
platform: info.providerId
|
|
443
|
+
};
|
|
444
|
+
if (options.attestationServiceUrl) {
|
|
445
|
+
params.attestationServiceUrl = options.attestationServiceUrl;
|
|
446
|
+
}
|
|
447
|
+
return params;
|
|
448
|
+
}
|
|
449
|
+
function resolveRegistrationProcessor(platform) {
|
|
450
|
+
const info = getPeerExtensionRegistrationInfo(platform.id);
|
|
451
|
+
if (info?.providerId === "paypal" || info?.providerId === "wise") {
|
|
452
|
+
return info.providerId;
|
|
453
|
+
}
|
|
454
|
+
throw new Error(`${platform.name} does not require Peer extension registration.`);
|
|
455
|
+
}
|
|
456
|
+
async function postMakerCreate(processorName, payload, apiBaseUrl = API_BASE_URL) {
|
|
457
|
+
const controller = new AbortController();
|
|
458
|
+
const timeout = setTimeout(() => controller.abort(), PAYEE_REGISTRATION_TIMEOUT_MS);
|
|
459
|
+
try {
|
|
460
|
+
const res = await fetch(`${apiBaseUrl}/v2/makers/create`, {
|
|
461
|
+
method: "POST",
|
|
462
|
+
headers: { "Content-Type": "application/json" },
|
|
463
|
+
body: JSON.stringify({ processorName, ...payload }),
|
|
464
|
+
signal: controller.signal
|
|
465
|
+
});
|
|
466
|
+
if (!res.ok) {
|
|
467
|
+
const txt = await res.text().catch(() => "");
|
|
468
|
+
let detail = txt || res.statusText;
|
|
469
|
+
try {
|
|
470
|
+
const parsed = JSON.parse(txt);
|
|
471
|
+
if (typeof parsed.message === "string" && parsed.message.trim()) {
|
|
472
|
+
detail = parsed.message;
|
|
473
|
+
}
|
|
474
|
+
} catch {
|
|
475
|
+
}
|
|
476
|
+
throw new MakersCreateError(
|
|
477
|
+
`makers/create failed (${res.status}): ${detail}`,
|
|
478
|
+
res.status,
|
|
479
|
+
txt
|
|
480
|
+
);
|
|
481
|
+
}
|
|
482
|
+
const json = await res.json();
|
|
483
|
+
if (!json.success || !json.responseObject?.hashedOnchainId) {
|
|
484
|
+
throw new MakersCreateError(
|
|
485
|
+
json.message || "makers/create returned no hashedOnchainId",
|
|
486
|
+
json.statusCode ?? null,
|
|
487
|
+
""
|
|
488
|
+
);
|
|
489
|
+
}
|
|
490
|
+
return json.responseObject.hashedOnchainId;
|
|
491
|
+
} finally {
|
|
492
|
+
clearTimeout(timeout);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
function requireSarCredentialCapture(capturedMetadata) {
|
|
496
|
+
const capture = capturedMetadata.sarCredentialCapture;
|
|
497
|
+
if (!capture?.credentialBundle) {
|
|
498
|
+
throw new Error("Peer metadata did not include a seller credential bundle.");
|
|
499
|
+
}
|
|
500
|
+
if (!capture.offchainId) {
|
|
501
|
+
throw new Error("Peer metadata did not include seller credential offchainId.");
|
|
502
|
+
}
|
|
503
|
+
return capture;
|
|
504
|
+
}
|
|
505
|
+
async function uploadSellerCredentialBundle(processorName, offchainId, bundle) {
|
|
506
|
+
const params = processorName === "wise" ? { platform: "wise", bundle } : { platform: processorName, offchainId, bundle };
|
|
507
|
+
return apiUploadSellerCredentialBundle(params, API_BASE_URL, PAYEE_REGISTRATION_TIMEOUT_MS);
|
|
508
|
+
}
|
|
509
|
+
async function completePeerExtensionRegistration(input) {
|
|
510
|
+
const processorName = resolveRegistrationProcessor(input.platform);
|
|
511
|
+
if (input.capturedMetadata.platform !== processorName) {
|
|
512
|
+
throw new Error(
|
|
513
|
+
`Peer metadata is for ${input.capturedMetadata.platform}, not ${processorName}.`
|
|
514
|
+
);
|
|
515
|
+
}
|
|
516
|
+
const sarCredentialCapture = requireSarCredentialCapture(input.capturedMetadata);
|
|
517
|
+
const bundle = sarCredentialCapture.credentialBundle;
|
|
518
|
+
if (bundle.platform.toLowerCase() !== processorName) {
|
|
519
|
+
throw new Error("Seller credential bundle platform does not match registration platform.");
|
|
520
|
+
}
|
|
521
|
+
const validation = input.platform.validate(input.identifier);
|
|
522
|
+
if (!validation.valid) {
|
|
523
|
+
throw new Error(validation.error || "Invalid identifier");
|
|
524
|
+
}
|
|
525
|
+
const payload = buildDepositData(processorName, sarCredentialCapture.offchainId);
|
|
526
|
+
if (payload.offchainId !== validation.normalized) {
|
|
527
|
+
throw new Error("Seller credential offchainId does not match registration identifier.");
|
|
528
|
+
}
|
|
529
|
+
const hashedOnchainId = bundle.payeeIdHash;
|
|
530
|
+
const sellerCredentialResponse = await uploadSellerCredentialBundle(
|
|
531
|
+
processorName,
|
|
532
|
+
payload.offchainId,
|
|
533
|
+
bundle
|
|
534
|
+
);
|
|
535
|
+
return {
|
|
536
|
+
processorName,
|
|
537
|
+
offchainId: payload.offchainId,
|
|
538
|
+
hashedOnchainId,
|
|
539
|
+
sellerCredentialResponse,
|
|
540
|
+
sellerCredentialStatus: sellerCredentialResponse.responseObject
|
|
541
|
+
};
|
|
542
|
+
}
|
|
397
543
|
var EXTENSION_REGISTRATION_ERROR_PATTERNS = ["creating the maker", "create the maker"];
|
|
398
544
|
function isPeerExtensionRegistrationError(platform, message, statusCode) {
|
|
399
545
|
const info = getPeerExtensionRegistrationInfo(platform);
|
|
@@ -405,39 +551,6 @@ function isPeerExtensionRegistrationError(platform, message, statusCode) {
|
|
|
405
551
|
return EXTENSION_REGISTRATION_ERROR_PATTERNS.some((p) => lower.includes(p));
|
|
406
552
|
}
|
|
407
553
|
|
|
408
|
-
// src/errors.ts
|
|
409
|
-
var MakersCreateError = class extends Error {
|
|
410
|
-
status;
|
|
411
|
-
body;
|
|
412
|
-
constructor(message, status, body) {
|
|
413
|
-
super(message);
|
|
414
|
-
this.name = "MakersCreateError";
|
|
415
|
-
this.status = status;
|
|
416
|
-
this.body = body;
|
|
417
|
-
}
|
|
418
|
-
};
|
|
419
|
-
var OfframpError = class extends Error {
|
|
420
|
-
code;
|
|
421
|
-
step;
|
|
422
|
-
cause;
|
|
423
|
-
txHash;
|
|
424
|
-
depositId;
|
|
425
|
-
constructor(message, code, step, cause, details) {
|
|
426
|
-
super(message);
|
|
427
|
-
this.name = "OfframpError";
|
|
428
|
-
this.code = code;
|
|
429
|
-
this.step = step;
|
|
430
|
-
this.cause = cause;
|
|
431
|
-
this.txHash = details?.txHash;
|
|
432
|
-
this.depositId = details?.depositId;
|
|
433
|
-
}
|
|
434
|
-
};
|
|
435
|
-
function isUserCancellation(error) {
|
|
436
|
-
if (!(error instanceof Error)) return false;
|
|
437
|
-
const msg = error.message.toLowerCase();
|
|
438
|
-
return msg.includes("user rejected") || msg.includes("user denied") || msg.includes("user cancelled") || msg.includes("rejected the request") || msg.includes("action_rejected");
|
|
439
|
-
}
|
|
440
|
-
|
|
441
554
|
// src/otc.ts
|
|
442
555
|
import { createPublicClient, http, isAddress, zeroAddress } from "viem";
|
|
443
556
|
import { base } from "viem/chains";
|
|
@@ -445,13 +558,13 @@ import WhitelistPreIntentHookABI from "@zkp2p/contracts-v2/abis/base/WhitelistPr
|
|
|
445
558
|
|
|
446
559
|
// src/sdk-client.ts
|
|
447
560
|
import { OfframpClient } from "@zkp2p/sdk";
|
|
448
|
-
function createSdkClient(walletClient) {
|
|
561
|
+
function createSdkClient(walletClient, apiBaseUrl = API_BASE_URL) {
|
|
449
562
|
return new OfframpClient({
|
|
450
563
|
walletClient,
|
|
451
564
|
chainId: BASE_CHAIN_ID,
|
|
452
565
|
runtimeEnv: RUNTIME_ENV,
|
|
453
566
|
rpcUrl: BASE_RPC_URL,
|
|
454
|
-
baseApiUrl:
|
|
567
|
+
baseApiUrl: apiBaseUrl
|
|
455
568
|
});
|
|
456
569
|
}
|
|
457
570
|
|
|
@@ -875,50 +988,11 @@ function extractDepositIdFromLogs(logs) {
|
|
|
875
988
|
}
|
|
876
989
|
return null;
|
|
877
990
|
}
|
|
878
|
-
async function
|
|
879
|
-
const controller = new AbortController();
|
|
880
|
-
const timeout = setTimeout(() => controller.abort(), PAYEE_REGISTRATION_TIMEOUT_MS);
|
|
881
|
-
try {
|
|
882
|
-
const res = await fetch(`${API_BASE_URL}/v2/makers/create`, {
|
|
883
|
-
method: "POST",
|
|
884
|
-
headers: { "Content-Type": "application/json" },
|
|
885
|
-
body: JSON.stringify({ processorName, ...payload }),
|
|
886
|
-
signal: controller.signal
|
|
887
|
-
});
|
|
888
|
-
if (!res.ok) {
|
|
889
|
-
const txt = await res.text().catch(() => "");
|
|
890
|
-
let detail = txt || res.statusText;
|
|
891
|
-
try {
|
|
892
|
-
const parsed = JSON.parse(txt);
|
|
893
|
-
if (typeof parsed.message === "string" && parsed.message.trim()) {
|
|
894
|
-
detail = parsed.message;
|
|
895
|
-
}
|
|
896
|
-
} catch {
|
|
897
|
-
}
|
|
898
|
-
throw new MakersCreateError(
|
|
899
|
-
`makers/create failed (${res.status}): ${detail}`,
|
|
900
|
-
res.status,
|
|
901
|
-
txt
|
|
902
|
-
);
|
|
903
|
-
}
|
|
904
|
-
const json = await res.json();
|
|
905
|
-
if (!json.success || !json.responseObject?.hashedOnchainId) {
|
|
906
|
-
throw new MakersCreateError(
|
|
907
|
-
json.message || "makers/create returned no hashedOnchainId",
|
|
908
|
-
json.statusCode ?? null,
|
|
909
|
-
""
|
|
910
|
-
);
|
|
911
|
-
}
|
|
912
|
-
return json.responseObject.hashedOnchainId;
|
|
913
|
-
} finally {
|
|
914
|
-
clearTimeout(timeout);
|
|
915
|
-
}
|
|
916
|
-
}
|
|
917
|
-
async function validatePayeeDetails(processorName, offchainId) {
|
|
991
|
+
async function validatePayeeDetails(processorName, offchainId, apiBaseUrl = API_BASE_URL) {
|
|
918
992
|
const controller = new AbortController();
|
|
919
993
|
const timeout = setTimeout(() => controller.abort(), PAYEE_REGISTRATION_TIMEOUT_MS);
|
|
920
994
|
try {
|
|
921
|
-
const res = await fetch(`${
|
|
995
|
+
const res = await fetch(`${apiBaseUrl}/v2/makers/validate`, {
|
|
922
996
|
method: "POST",
|
|
923
997
|
headers: { "Content-Type": "application/json" },
|
|
924
998
|
body: JSON.stringify({ processorName, offchainId }),
|
|
@@ -996,10 +1070,11 @@ async function findUndelegatedDeposit(walletAddress) {
|
|
|
996
1070
|
return null;
|
|
997
1071
|
}
|
|
998
1072
|
}
|
|
999
|
-
async function offramp(walletClient, params, onProgress, telemetryContext) {
|
|
1073
|
+
async function offramp(walletClient, params, onProgress, telemetryContext, apiBaseUrl) {
|
|
1000
1074
|
const { amount, platform, currency, identifier } = params;
|
|
1001
1075
|
const platformId = platform.id;
|
|
1002
1076
|
const currencyCode = currency.code;
|
|
1077
|
+
const resolvedApiBaseUrl = resolveApiBaseUrl(apiBaseUrl);
|
|
1003
1078
|
const telemetry = telemetryContext ?? createTelemetryContext({
|
|
1004
1079
|
sdkVersion: SDK_VERSION,
|
|
1005
1080
|
telemetry: true,
|
|
@@ -1044,7 +1119,7 @@ async function offramp(walletClient, params, onProgress, telemetryContext) {
|
|
|
1044
1119
|
const existing = await findUndelegatedDeposit(walletAddress);
|
|
1045
1120
|
if (existing) {
|
|
1046
1121
|
emitProgress({ step: "resuming", depositId: existing.depositId });
|
|
1047
|
-
const client2 = createSdkClient(walletClient);
|
|
1122
|
+
const client2 = createSdkClient(walletClient, resolvedApiBaseUrl);
|
|
1048
1123
|
const txOverrides2 = { referrer: [REFERRER] };
|
|
1049
1124
|
try {
|
|
1050
1125
|
const result2 = await client2.setRateManager({
|
|
@@ -1080,7 +1155,7 @@ async function offramp(walletClient, params, onProgress, telemetryContext) {
|
|
|
1080
1155
|
const truncatedAmount = amt.toFixed(6).replace(/\.?0+$/, "");
|
|
1081
1156
|
const amountUnits = usdcToUnits(truncatedAmount);
|
|
1082
1157
|
const minUnits = usdcToUnits(String(MIN_ORDER_USDC));
|
|
1083
|
-
const maxUnits = usdcToUnits(String(Math.min(amt,
|
|
1158
|
+
const maxUnits = usdcToUnits(String(Math.min(amt, MAX_ORDER_USDC)));
|
|
1084
1159
|
try {
|
|
1085
1160
|
const publicClient = createPublicClient3({ chain: base3, transport: http3(BASE_RPC_URL) });
|
|
1086
1161
|
const balance = await publicClient.readContract({
|
|
@@ -1109,7 +1184,11 @@ async function offramp(walletClient, params, onProgress, telemetryContext) {
|
|
|
1109
1184
|
}
|
|
1110
1185
|
const canonicalName = platformId.startsWith("zelle") ? "zelle" : platformId;
|
|
1111
1186
|
if (!getPeerExtensionRegistrationInfo(platformId)) {
|
|
1112
|
-
const outcome = await validatePayeeDetails(
|
|
1187
|
+
const outcome = await validatePayeeDetails(
|
|
1188
|
+
canonicalName,
|
|
1189
|
+
normalizedIdentifier,
|
|
1190
|
+
resolvedApiBaseUrl
|
|
1191
|
+
);
|
|
1113
1192
|
if (outcome === "invalid") {
|
|
1114
1193
|
throw new OfframpError(
|
|
1115
1194
|
`Couldn't verify that ${platform.name} ${platform.identifier.label.toLowerCase()}. Double-check it and try again.`,
|
|
@@ -1118,7 +1197,7 @@ async function offramp(walletClient, params, onProgress, telemetryContext) {
|
|
|
1118
1197
|
);
|
|
1119
1198
|
}
|
|
1120
1199
|
}
|
|
1121
|
-
const client = createSdkClient(walletClient);
|
|
1200
|
+
const client = createSdkClient(walletClient, resolvedApiBaseUrl);
|
|
1122
1201
|
const txOverrides = { referrer: [REFERRER] };
|
|
1123
1202
|
emitProgress({ step: "approving" });
|
|
1124
1203
|
try {
|
|
@@ -1144,13 +1223,13 @@ async function offramp(walletClient, params, onProgress, telemetryContext) {
|
|
|
1144
1223
|
let hashedOnchainId;
|
|
1145
1224
|
try {
|
|
1146
1225
|
const payeePayload = buildDepositData(canonicalName, normalizedIdentifier);
|
|
1147
|
-
hashedOnchainId = await
|
|
1226
|
+
hashedOnchainId = await postMakerCreate(canonicalName, payeePayload, resolvedApiBaseUrl);
|
|
1148
1227
|
} catch (err) {
|
|
1149
1228
|
const status = err instanceof MakersCreateError ? err.status : null;
|
|
1150
1229
|
const message = err instanceof Error ? err.message : String(err);
|
|
1151
1230
|
if (isPeerExtensionRegistrationError(canonicalName, message, status)) {
|
|
1152
1231
|
throw new OfframpError(
|
|
1153
|
-
`${platform.name} maker is not yet registered in the Peer extension.
|
|
1232
|
+
`${platform.name} maker is not yet registered in the Peer extension. Register this handle with Peer, then retry.`,
|
|
1154
1233
|
"EXTENSION_REGISTRATION_REQUIRED",
|
|
1155
1234
|
"registering",
|
|
1156
1235
|
err
|
|
@@ -1342,6 +1421,14 @@ var CURRENCIES = buildCurrencies();
|
|
|
1342
1421
|
// src/offramp.ts
|
|
1343
1422
|
var IDEMPOTENCY_TTL_MS = 10 * 60 * 1e3;
|
|
1344
1423
|
var IDEMPOTENCY_STORAGE_PREFIX = "offramp:idempotency:";
|
|
1424
|
+
var warnedIdempotencyUnavailable = false;
|
|
1425
|
+
function warnIdempotencyUnavailableOnce() {
|
|
1426
|
+
if (warnedIdempotencyUnavailable) return;
|
|
1427
|
+
warnedIdempotencyUnavailable = true;
|
|
1428
|
+
console.warn(
|
|
1429
|
+
"[offramp] idempotencyKey was provided but sessionStorage is unavailable (Node/worker runtime). The idempotency cache is browser-only and no-ops here, so retries can create duplicate deposits. For server-side dedup, call deposits(walletAddress) and reuse an existing open deposit before creating one."
|
|
1430
|
+
);
|
|
1431
|
+
}
|
|
1345
1432
|
function getWalletAddress(walletClient) {
|
|
1346
1433
|
const address = walletClient.account?.address;
|
|
1347
1434
|
if (!address) {
|
|
@@ -1412,8 +1499,10 @@ function buildCurrencyGroups() {
|
|
|
1412
1499
|
var Offramp = class {
|
|
1413
1500
|
walletClient;
|
|
1414
1501
|
telemetry;
|
|
1502
|
+
apiBaseUrl;
|
|
1415
1503
|
constructor(options) {
|
|
1416
1504
|
this.walletClient = options.walletClient;
|
|
1505
|
+
this.apiBaseUrl = options.apiBaseUrl;
|
|
1417
1506
|
this.telemetry = createTelemetryContext({
|
|
1418
1507
|
sdkVersion: SDK_VERSION,
|
|
1419
1508
|
telemetry: options.telemetry,
|
|
@@ -1436,6 +1525,9 @@ var Offramp = class {
|
|
|
1436
1525
|
referralId: flowTelemetry.referralId
|
|
1437
1526
|
};
|
|
1438
1527
|
const sanitizedKey = sanitizeAttributionId(params.idempotencyKey);
|
|
1528
|
+
if (sanitizedKey && typeof sessionStorage === "undefined") {
|
|
1529
|
+
warnIdempotencyUnavailableOnce();
|
|
1530
|
+
}
|
|
1439
1531
|
const walletAddress = sanitizedKey ? getWalletAddress(this.walletClient) : null;
|
|
1440
1532
|
const storageKey = walletAddress && sanitizedKey ? getIdempotencyStorageKey(walletAddress, sanitizedKey) : null;
|
|
1441
1533
|
if (storageKey) {
|
|
@@ -1446,7 +1538,8 @@ var Offramp = class {
|
|
|
1446
1538
|
this.walletClient,
|
|
1447
1539
|
sanitizedParams,
|
|
1448
1540
|
onProgress,
|
|
1449
|
-
flowTelemetry
|
|
1541
|
+
flowTelemetry,
|
|
1542
|
+
this.apiBaseUrl
|
|
1450
1543
|
);
|
|
1451
1544
|
if (storageKey) {
|
|
1452
1545
|
writeIdempotencyResult(storageKey, result);
|
|
@@ -1495,24 +1588,89 @@ function createOfframp(options) {
|
|
|
1495
1588
|
// src/extension.ts
|
|
1496
1589
|
import {
|
|
1497
1590
|
PEER_EXTENSION_CHROME_URL,
|
|
1498
|
-
|
|
1499
|
-
createPeerExtensionSdk,
|
|
1500
|
-
isPeerExtensionAvailable,
|
|
1501
|
-
openPeerExtensionInstallPage,
|
|
1502
|
-
getPeerExtensionState
|
|
1591
|
+
createPeerExtensionSdk as createSdkPeerExtensionSdk
|
|
1503
1592
|
} from "@zkp2p/sdk";
|
|
1593
|
+
var resolveWindow = (options) => {
|
|
1594
|
+
if (options?.window) {
|
|
1595
|
+
return options.window;
|
|
1596
|
+
}
|
|
1597
|
+
if (typeof window === "undefined") {
|
|
1598
|
+
return void 0;
|
|
1599
|
+
}
|
|
1600
|
+
return window;
|
|
1601
|
+
};
|
|
1602
|
+
var requirePeer = (options) => {
|
|
1603
|
+
const resolvedWindow = resolveWindow(options);
|
|
1604
|
+
if (!resolvedWindow) {
|
|
1605
|
+
throw new Error("Peer extension SDK requires a browser window.");
|
|
1606
|
+
}
|
|
1607
|
+
if (!resolvedWindow.peer) {
|
|
1608
|
+
throw new Error("Peer extension not available. Install or enable the Peer extension.");
|
|
1609
|
+
}
|
|
1610
|
+
return resolvedWindow.peer;
|
|
1611
|
+
};
|
|
1612
|
+
var isPeerExtensionAvailable = (options) => {
|
|
1613
|
+
const resolvedWindow = resolveWindow(options);
|
|
1614
|
+
return Boolean(resolvedWindow?.peer);
|
|
1615
|
+
};
|
|
1616
|
+
var hasHeadlessMetadataBridge = (peer) => typeof peer.authenticate === "function" && typeof peer.onMetadataMessage === "function";
|
|
1617
|
+
var requirePeerMetadataBridge = (options) => {
|
|
1618
|
+
const peer = requirePeer(options);
|
|
1619
|
+
if (!hasHeadlessMetadataBridge(peer)) {
|
|
1620
|
+
throw new Error("Peer extension metadata bridge unavailable. Install or update Peer.");
|
|
1621
|
+
}
|
|
1622
|
+
return peer;
|
|
1623
|
+
};
|
|
1624
|
+
var isPeerExtensionMetadataBridgeAvailable = (options) => {
|
|
1625
|
+
const resolvedWindow = resolveWindow(options);
|
|
1626
|
+
return Boolean(resolvedWindow?.peer && hasHeadlessMetadataBridge(resolvedWindow.peer));
|
|
1627
|
+
};
|
|
1628
|
+
var openPeerExtensionInstallPage = (options) => {
|
|
1629
|
+
const resolvedWindow = resolveWindow(options);
|
|
1630
|
+
if (!resolvedWindow) {
|
|
1631
|
+
throw new Error("Peer extension SDK requires a browser window.");
|
|
1632
|
+
}
|
|
1633
|
+
resolvedWindow.open(PEER_EXTENSION_CHROME_URL, "_blank", "noopener,noreferrer");
|
|
1634
|
+
};
|
|
1635
|
+
var getPeerExtensionState = async (options) => {
|
|
1636
|
+
if (!isPeerExtensionAvailable(options)) {
|
|
1637
|
+
return "needs_install";
|
|
1638
|
+
}
|
|
1639
|
+
try {
|
|
1640
|
+
const status = await requirePeer(options).checkConnectionStatus();
|
|
1641
|
+
return status === "connected" ? "ready" : "needs_connection";
|
|
1642
|
+
} catch {
|
|
1643
|
+
return "needs_connection";
|
|
1644
|
+
}
|
|
1645
|
+
};
|
|
1646
|
+
var createPeerExtensionSdk = (options = {}) => {
|
|
1647
|
+
const sdk = createSdkPeerExtensionSdk(options);
|
|
1648
|
+
return {
|
|
1649
|
+
isAvailable: () => isPeerExtensionAvailable(options),
|
|
1650
|
+
requestConnection: () => requirePeer(options).requestConnection(),
|
|
1651
|
+
checkConnectionStatus: () => requirePeer(options).checkConnectionStatus(),
|
|
1652
|
+
getVersion: () => requirePeer(options).getVersion(),
|
|
1653
|
+
authenticate: (params) => requirePeerMetadataBridge(options).authenticate(params),
|
|
1654
|
+
onMetadataMessage: (callback) => requirePeerMetadataBridge(options).onMetadataMessage(callback),
|
|
1655
|
+
openInstallPage: () => sdk.openInstallPage(),
|
|
1656
|
+
getState: () => sdk.getState()
|
|
1657
|
+
};
|
|
1658
|
+
};
|
|
1659
|
+
var peerExtensionSdk = createPeerExtensionSdk();
|
|
1504
1660
|
|
|
1505
1661
|
export {
|
|
1506
1662
|
ESCROW_ADDRESS,
|
|
1663
|
+
MakersCreateError,
|
|
1664
|
+
OfframpError,
|
|
1507
1665
|
normalizePaypalMeUsername,
|
|
1508
1666
|
isValidIBAN,
|
|
1509
1667
|
PLATFORMS,
|
|
1510
1668
|
PLATFORM_LIMITS,
|
|
1511
1669
|
getPlatformLimits,
|
|
1512
1670
|
getPeerExtensionRegistrationInfo,
|
|
1671
|
+
getPeerExtensionRegistrationAuthParams,
|
|
1672
|
+
completePeerExtensionRegistration,
|
|
1513
1673
|
isPeerExtensionRegistrationError,
|
|
1514
|
-
MakersCreateError,
|
|
1515
|
-
OfframpError,
|
|
1516
1674
|
enableOtc,
|
|
1517
1675
|
disableOtc,
|
|
1518
1676
|
getOtcLink,
|
|
@@ -1529,10 +1687,11 @@ export {
|
|
|
1529
1687
|
Offramp,
|
|
1530
1688
|
createOfframp,
|
|
1531
1689
|
PEER_EXTENSION_CHROME_URL,
|
|
1532
|
-
peerExtensionSdk,
|
|
1533
|
-
createPeerExtensionSdk,
|
|
1534
1690
|
isPeerExtensionAvailable,
|
|
1691
|
+
isPeerExtensionMetadataBridgeAvailable,
|
|
1535
1692
|
openPeerExtensionInstallPage,
|
|
1536
|
-
getPeerExtensionState
|
|
1693
|
+
getPeerExtensionState,
|
|
1694
|
+
createPeerExtensionSdk,
|
|
1695
|
+
peerExtensionSdk
|
|
1537
1696
|
};
|
|
1538
|
-
//# sourceMappingURL=chunk-
|
|
1697
|
+
//# sourceMappingURL=chunk-QMO7HTBZ.js.map
|