@zkp2p/sdk 0.4.3 → 0.5.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/README.md +55 -37
- package/dist/index.cjs +150 -339
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +53 -41
- package/dist/index.d.ts +53 -41
- package/dist/index.mjs +145 -337
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +2 -2
- package/dist/react.d.ts +2 -2
- package/dist/{vaultUtils-BZU2bc0T.d.mts → vaultUtils-CtNcKlpg.d.mts} +47 -50
- package/dist/{vaultUtils-BZU2bc0T.d.ts → vaultUtils-CtNcKlpg.d.ts} +47 -50
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -9,6 +9,7 @@ import './chunk-J5LGTIGS.mjs';
|
|
|
9
9
|
import { concatHex, encodeFunctionData, encodeAbiParameters, createPublicClient, http, formatUnits } from 'viem';
|
|
10
10
|
import { hardhat, base } from 'viem/chains';
|
|
11
11
|
import { createEncryptedBuyerTeeSessionMaterial as createEncryptedBuyerTeeSessionMaterial$1, createEncryptedSellerCredentialUpload } from '@zkp2p/zkp2p-attestation';
|
|
12
|
+
export { createNitroAttestationClient } from '@zkp2p/zkp2p-attestation';
|
|
12
13
|
import { AbiCoder } from 'ethers';
|
|
13
14
|
import { Attribution } from 'ox/erc8021';
|
|
14
15
|
|
|
@@ -468,29 +469,6 @@ async function createEncryptedSellerCredentialUploadForPlatform({
|
|
|
468
469
|
...attestationRuntime?.getRandomValues ? { getRandomValues: attestationRuntime.getRandomValues } : {}
|
|
469
470
|
});
|
|
470
471
|
}
|
|
471
|
-
async function apiCreatePaymentAttestation(payload, attestationServiceUrl, platform, actionType) {
|
|
472
|
-
return withRetry(async () => {
|
|
473
|
-
let res;
|
|
474
|
-
try {
|
|
475
|
-
const endpoint = `/verify/${encodeURIComponent(platform)}/${encodeURIComponent(actionType)}`;
|
|
476
|
-
res = await fetch(`${attestationServiceUrl}${endpoint}`, {
|
|
477
|
-
method: "POST",
|
|
478
|
-
headers: headers(),
|
|
479
|
-
body: JSON.stringify(payload)
|
|
480
|
-
});
|
|
481
|
-
} catch (error) {
|
|
482
|
-
throw new NetworkError("Failed to connect to Attestation Service", {
|
|
483
|
-
endpoint: `/verify/${platform}/${actionType}`,
|
|
484
|
-
error
|
|
485
|
-
});
|
|
486
|
-
}
|
|
487
|
-
if (!res.ok) {
|
|
488
|
-
const errorText = await res.text();
|
|
489
|
-
throw parseAPIError(res, errorText);
|
|
490
|
-
}
|
|
491
|
-
return res.json();
|
|
492
|
-
});
|
|
493
|
-
}
|
|
494
472
|
async function apiVerifyBuyerTeePayment(payload, attestationServiceUrl, platform, actionType) {
|
|
495
473
|
return withRetry(async () => {
|
|
496
474
|
let res;
|
|
@@ -528,6 +506,7 @@ async function apiRequestIdentityAttestation(payload, attestationServiceUrl, pla
|
|
|
528
506
|
body: JSON.stringify({
|
|
529
507
|
platform,
|
|
530
508
|
actionType,
|
|
509
|
+
callerAddress: payload.callerAddress,
|
|
531
510
|
encryptedSessionMaterial: payload.encryptedSessionMaterial,
|
|
532
511
|
params: payload.params
|
|
533
512
|
})
|
|
@@ -1328,8 +1307,7 @@ var IntentOperations = class {
|
|
|
1328
1307
|
paymentProof = precomputed.paymentProof;
|
|
1329
1308
|
verificationData = precomputed.verificationData;
|
|
1330
1309
|
} else {
|
|
1331
|
-
const
|
|
1332
|
-
const buyerTeeProof = parseBuyerTeePaymentProofInput(proof);
|
|
1310
|
+
const buyerTeeProof = parseBuyerTeePaymentProofInput(params.proof);
|
|
1333
1311
|
const attestationServiceUrl = params.attestationServiceUrl ?? this.defaultAttestationService();
|
|
1334
1312
|
const inputs = await this.config.host.getFulfillIntentInputs(intentHash, {
|
|
1335
1313
|
orchestratorAddress: orchestratorContext.address
|
|
@@ -1354,7 +1332,7 @@ var IntentOperations = class {
|
|
|
1354
1332
|
payeeDetails: inputs.payeeDetails,
|
|
1355
1333
|
timestampBufferMs: params.timestampBufferMs ?? "300000"
|
|
1356
1334
|
};
|
|
1357
|
-
const attestation =
|
|
1335
|
+
const attestation = await apiVerifyBuyerTeePayment(
|
|
1358
1336
|
{
|
|
1359
1337
|
encryptedSessionMaterial: buyerTeeProof.encryptedSessionMaterial,
|
|
1360
1338
|
params: buyerTeeProof.params,
|
|
@@ -1364,16 +1342,6 @@ var IntentOperations = class {
|
|
|
1364
1342
|
attestationServiceUrl,
|
|
1365
1343
|
buyerTeeProof.actionPlatform ?? platformConfig.actionPlatform,
|
|
1366
1344
|
buyerTeeProof.actionType ?? platformConfig.actionType
|
|
1367
|
-
) : await apiCreatePaymentAttestation(
|
|
1368
|
-
{
|
|
1369
|
-
proofType: "reclaim",
|
|
1370
|
-
proof: typeof proof === "string" ? proof : serializeProofInput(proof),
|
|
1371
|
-
chainId: this.config.getChainId(),
|
|
1372
|
-
intent
|
|
1373
|
-
},
|
|
1374
|
-
attestationServiceUrl,
|
|
1375
|
-
platformConfig.actionPlatform,
|
|
1376
|
-
platformConfig.actionType
|
|
1377
1345
|
);
|
|
1378
1346
|
paymentProof = encodePaymentAttestation(attestation);
|
|
1379
1347
|
verificationData = encodeVerifyPaymentData({
|
|
@@ -1381,6 +1349,7 @@ var IntentOperations = class {
|
|
|
1381
1349
|
paymentProof,
|
|
1382
1350
|
data: encodeAddressAsBytes(attestation.responseObject.signer)
|
|
1383
1351
|
});
|
|
1352
|
+
params.callbacks?.onAttestationComplete?.(attestation);
|
|
1384
1353
|
}
|
|
1385
1354
|
const args = [
|
|
1386
1355
|
{
|
|
@@ -1462,9 +1431,12 @@ var IntentOperations = class {
|
|
|
1462
1431
|
const deposit = await this.config.getIndexerService().fetchDepositWithRelations(record.depositId, {
|
|
1463
1432
|
includeIntents: false
|
|
1464
1433
|
});
|
|
1434
|
+
if (!deposit) {
|
|
1435
|
+
throw new Error(`Deposit ${record.depositId} not found on indexer for intent ${intentHash}`);
|
|
1436
|
+
}
|
|
1465
1437
|
let payee;
|
|
1466
1438
|
const paymentMethodHashLower = (record.paymentMethodHash || "").toLowerCase();
|
|
1467
|
-
for (const paymentMethod of deposit
|
|
1439
|
+
for (const paymentMethod of deposit.paymentMethods || []) {
|
|
1468
1440
|
if ((paymentMethod.paymentMethodHash || "").toLowerCase() === paymentMethodHashLower) {
|
|
1469
1441
|
payee = paymentMethod.payeeDetailsHash;
|
|
1470
1442
|
break;
|
|
@@ -1482,12 +1454,6 @@ var IntentOperations = class {
|
|
|
1482
1454
|
};
|
|
1483
1455
|
}
|
|
1484
1456
|
};
|
|
1485
|
-
function serializeProofInput(proof) {
|
|
1486
|
-
return JSON.stringify(
|
|
1487
|
-
proof,
|
|
1488
|
-
(_key, value) => typeof value === "bigint" ? value.toString() : value
|
|
1489
|
-
);
|
|
1490
|
-
}
|
|
1491
1457
|
function isRecord(value) {
|
|
1492
1458
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1493
1459
|
}
|
|
@@ -1498,7 +1464,9 @@ function isBuyerTeeParams(value) {
|
|
|
1498
1464
|
}
|
|
1499
1465
|
function parseBuyerTeePaymentProofInput(proof) {
|
|
1500
1466
|
if (!isRecord(proof) || proof.proofType !== "buyerTee") {
|
|
1501
|
-
|
|
1467
|
+
throw new Error(
|
|
1468
|
+
"Buyer TEE proof input is required; legacy proof inputs are no longer supported."
|
|
1469
|
+
);
|
|
1502
1470
|
}
|
|
1503
1471
|
if (typeof proof.encryptedSessionMaterial !== "string" || !isBuyerTeeParams(proof.params)) {
|
|
1504
1472
|
throw new Error("Buyer TEE proof requires encryptedSessionMaterial and params.");
|
|
@@ -3346,6 +3314,7 @@ var INTENT_FULFILLMENTS_QUERY = (
|
|
|
3346
3314
|
query GetFulfilledIntents($intentHashes: [String!]) {
|
|
3347
3315
|
Orchestrator_V21_IntentFulfilled(where: { intentHash: { _in: $intentHashes } }) {
|
|
3348
3316
|
intentHash
|
|
3317
|
+
amount
|
|
3349
3318
|
isManualRelease
|
|
3350
3319
|
fundsTransferredTo
|
|
3351
3320
|
}
|
|
@@ -4973,6 +4942,44 @@ async function fetchFulfillmentAndPayment(client, intentHash) {
|
|
|
4973
4942
|
});
|
|
4974
4943
|
}
|
|
4975
4944
|
|
|
4945
|
+
// src/utils/logger.ts
|
|
4946
|
+
var currentLevel = "info";
|
|
4947
|
+
function setLogLevel(level) {
|
|
4948
|
+
currentLevel = level;
|
|
4949
|
+
}
|
|
4950
|
+
function shouldLog(level) {
|
|
4951
|
+
switch (currentLevel) {
|
|
4952
|
+
case "debug":
|
|
4953
|
+
return true;
|
|
4954
|
+
case "info":
|
|
4955
|
+
return level !== "debug";
|
|
4956
|
+
case "error":
|
|
4957
|
+
return level === "error";
|
|
4958
|
+
default:
|
|
4959
|
+
return true;
|
|
4960
|
+
}
|
|
4961
|
+
}
|
|
4962
|
+
var logger = {
|
|
4963
|
+
debug: (...args) => {
|
|
4964
|
+
if (shouldLog("debug")) {
|
|
4965
|
+
console.log("[DEBUG]", ...args);
|
|
4966
|
+
}
|
|
4967
|
+
},
|
|
4968
|
+
info: (...args) => {
|
|
4969
|
+
if (shouldLog("info")) {
|
|
4970
|
+
console.log("[INFO]", ...args);
|
|
4971
|
+
}
|
|
4972
|
+
},
|
|
4973
|
+
warn: (...args) => {
|
|
4974
|
+
if (shouldLog("info")) {
|
|
4975
|
+
console.warn("[WARN]", ...args);
|
|
4976
|
+
}
|
|
4977
|
+
},
|
|
4978
|
+
error: (...args) => {
|
|
4979
|
+
console.error("[ERROR]", ...args);
|
|
4980
|
+
}
|
|
4981
|
+
};
|
|
4982
|
+
|
|
4976
4983
|
// src/adapters/api.ts
|
|
4977
4984
|
function createHeaders2(apiKey, authToken) {
|
|
4978
4985
|
const headers2 = { "Content-Type": "application/json" };
|
|
@@ -5080,10 +5087,17 @@ function buildLegacyVerifierCurrencies(deposit) {
|
|
|
5080
5087
|
const currenciesByMethod = /* @__PURE__ */ new Map();
|
|
5081
5088
|
for (const currency of deposit.currencies ?? []) {
|
|
5082
5089
|
const methodHash = currency.paymentMethodHash;
|
|
5090
|
+
const resolvedConversionRate = currency.conversionRate ?? currency.minConversionRate;
|
|
5091
|
+
if (resolvedConversionRate === null || resolvedConversionRate === void 0) {
|
|
5092
|
+
logger.warn(
|
|
5093
|
+
`[sdk] Skipping currency with missing conversion rate (deposit ${deposit.depositId}, currency ${currency.currencyCode})`
|
|
5094
|
+
);
|
|
5095
|
+
continue;
|
|
5096
|
+
}
|
|
5083
5097
|
const bucket = currenciesByMethod.get(methodHash) ?? [];
|
|
5084
5098
|
bucket.push({
|
|
5085
5099
|
currencyCode: currency.currencyCode,
|
|
5086
|
-
conversionRate:
|
|
5100
|
+
conversionRate: resolvedConversionRate,
|
|
5087
5101
|
minConversionRate: currency.minConversionRate,
|
|
5088
5102
|
managerRate: currency.managerRate ?? null,
|
|
5089
5103
|
rateManagerId: currency.rateManagerId ?? null
|
|
@@ -5286,19 +5300,6 @@ async function apiUploadSellerCredential(processorName, payeeDetails, bundle, ba
|
|
|
5286
5300
|
timeoutMs
|
|
5287
5301
|
});
|
|
5288
5302
|
}
|
|
5289
|
-
async function apiConfirmPayPalForwarding(payeeDetails, body, baseApiUrl, opts) {
|
|
5290
|
-
const endpoint = `/v2/makers/paypal/${encodeURIComponent(
|
|
5291
|
-
payeeDetails
|
|
5292
|
-
)}/seller-credential/forwarding-confirmation`;
|
|
5293
|
-
return apiFetch({
|
|
5294
|
-
url: `${withApiBase(baseApiUrl)}${endpoint}`,
|
|
5295
|
-
method: "POST",
|
|
5296
|
-
body,
|
|
5297
|
-
apiKey: opts?.apiKey,
|
|
5298
|
-
authToken: opts?.authToken,
|
|
5299
|
-
timeoutMs: opts?.timeoutMs
|
|
5300
|
-
});
|
|
5301
|
-
}
|
|
5302
5303
|
async function apiUploadGoogleOAuthSellerCredential(processorName, payeeDetails, body, baseApiUrl, opts) {
|
|
5303
5304
|
const endpoint = `/v2/makers/${encodeURIComponent(processorName)}/${encodeURIComponent(
|
|
5304
5305
|
payeeDetails
|
|
@@ -5381,6 +5382,58 @@ async function apiGetDepositBundle(params, optsOrBaseApiUrl, timeoutMs, apiKey)
|
|
|
5381
5382
|
});
|
|
5382
5383
|
return response.responseObject;
|
|
5383
5384
|
}
|
|
5385
|
+
|
|
5386
|
+
// src/sellerCredentials.ts
|
|
5387
|
+
function normalizeBaseApiUrl(value) {
|
|
5388
|
+
return (value?.trim().replace(/\/+$/u, "") || DEFAULT_BASE_API_URL).replace(/\/v1$/u, "");
|
|
5389
|
+
}
|
|
5390
|
+
function assertBundlePlatformMatches(params) {
|
|
5391
|
+
if (params.bundle.platform.toLowerCase() !== params.platform) {
|
|
5392
|
+
throw new Error("Seller credential bundle platform does not match upload platform");
|
|
5393
|
+
}
|
|
5394
|
+
}
|
|
5395
|
+
async function apiUploadSellerCredentialBundle(params, baseApiUrl, timeoutMs) {
|
|
5396
|
+
assertBundlePlatformMatches(params);
|
|
5397
|
+
const normalizedBaseApiUrl = normalizeBaseApiUrl(baseApiUrl);
|
|
5398
|
+
if (params.platform === "wise") {
|
|
5399
|
+
return apiUploadSellerCredential(
|
|
5400
|
+
params.platform,
|
|
5401
|
+
params.bundle.payeeIdHash,
|
|
5402
|
+
params.bundle,
|
|
5403
|
+
normalizedBaseApiUrl,
|
|
5404
|
+
timeoutMs
|
|
5405
|
+
);
|
|
5406
|
+
}
|
|
5407
|
+
const registeredPayeePayload = {
|
|
5408
|
+
offchainId: params.offchainId,
|
|
5409
|
+
processorName: params.platform
|
|
5410
|
+
};
|
|
5411
|
+
if (params.telegramUsername !== void 0) {
|
|
5412
|
+
registeredPayeePayload.telegramUsername = params.telegramUsername;
|
|
5413
|
+
}
|
|
5414
|
+
if (params.metadata !== void 0) {
|
|
5415
|
+
registeredPayeePayload.metadata = params.metadata;
|
|
5416
|
+
}
|
|
5417
|
+
const registeredPayeeResponse = await apiPostDepositDetails(
|
|
5418
|
+
registeredPayeePayload,
|
|
5419
|
+
normalizedBaseApiUrl,
|
|
5420
|
+
timeoutMs
|
|
5421
|
+
);
|
|
5422
|
+
if (!registeredPayeeResponse.success || !registeredPayeeResponse.responseObject) {
|
|
5423
|
+
throw new Error(registeredPayeeResponse.message || "Failed to register seller payee details");
|
|
5424
|
+
}
|
|
5425
|
+
const registeredPayee = registeredPayeeResponse.responseObject;
|
|
5426
|
+
if (registeredPayee.hashedOnchainId.toLowerCase() !== params.bundle.payeeIdHash.toLowerCase()) {
|
|
5427
|
+
throw new Error("Seller credential payee hash does not match registered payee details");
|
|
5428
|
+
}
|
|
5429
|
+
return apiUploadSellerCredential(
|
|
5430
|
+
params.platform,
|
|
5431
|
+
registeredPayee.hashedOnchainId,
|
|
5432
|
+
params.bundle,
|
|
5433
|
+
normalizedBaseApiUrl,
|
|
5434
|
+
timeoutMs
|
|
5435
|
+
);
|
|
5436
|
+
}
|
|
5384
5437
|
var formatTokenAmountForDisplay = (amount, decimals) => {
|
|
5385
5438
|
const formatted = formatUnits(amount, decimals);
|
|
5386
5439
|
if (!formatted.includes(".")) {
|
|
@@ -6383,7 +6436,7 @@ var Zkp2pClient = class {
|
|
|
6383
6436
|
* ```
|
|
6384
6437
|
*
|
|
6385
6438
|
* @param params.intentHash - The intent hash to fulfill (0x-prefixed, 32 bytes)
|
|
6386
|
-
* @param params.proof -
|
|
6439
|
+
* @param params.proof - Buyer TEE payment proof input
|
|
6387
6440
|
* @param params.timestampBufferMs - Allowed timestamp variance (default: 300000ms)
|
|
6388
6441
|
* @param params.attestationServiceUrl - Override attestation service URL
|
|
6389
6442
|
* @param params.postIntentHookData - Data to pass to post-intent hook
|
|
@@ -7268,7 +7321,9 @@ var Zkp2pClient = class {
|
|
|
7268
7321
|
* { limit: 50, orderBy: 'remainingDeposits', orderDirection: 'desc' }
|
|
7269
7322
|
* );
|
|
7270
7323
|
*
|
|
7271
|
-
* // Get historical fulfillment data
|
|
7324
|
+
* // Get historical fulfillment event data. Use `amount` for net USDC
|
|
7325
|
+
* // transferred to the taker; use getIntentFulfillmentAmounts() when you
|
|
7326
|
+
* // also need gross released USDC.
|
|
7272
7327
|
* const fulfillments = await client.indexer.getFulfilledIntentEvents(['0x...']);
|
|
7273
7328
|
* ```
|
|
7274
7329
|
*/
|
|
@@ -7330,13 +7385,15 @@ var Zkp2pClient = class {
|
|
|
7330
7385
|
return service.fetchExpiredIntents(params);
|
|
7331
7386
|
},
|
|
7332
7387
|
/**
|
|
7333
|
-
* Fetches fulfillment events for completed intents.
|
|
7388
|
+
* Fetches fulfillment events for completed intents. `amount` is the net
|
|
7389
|
+
* USDC transferred to the taker after protocol/referrer fees.
|
|
7334
7390
|
*/
|
|
7335
7391
|
getFulfilledIntentEvents: (intentHashes) => {
|
|
7336
7392
|
return service.fetchFulfilledIntentEvents(intentHashes);
|
|
7337
7393
|
},
|
|
7338
7394
|
/**
|
|
7339
|
-
* Fetches gross and net fulfillment amounts for an intent.
|
|
7395
|
+
* Fetches gross and net fulfillment amounts for an intent. Use
|
|
7396
|
+
* `takerAmountNetFees` as the buyer/taker received USDC amount.
|
|
7340
7397
|
*/
|
|
7341
7398
|
getIntentFulfillmentAmounts: (intentHash) => {
|
|
7342
7399
|
return service.fetchIntentFulfillmentAmounts(intentHash);
|
|
@@ -7954,14 +8011,14 @@ var Zkp2pClient = class {
|
|
|
7954
8011
|
const attestationServiceUrl = this.stripTrailingSlash(
|
|
7955
8012
|
opts?.attestationServiceUrl ?? this.defaultAttestationServiceForBaseApiUrl(baseApiUrl)
|
|
7956
8013
|
);
|
|
7957
|
-
const createBundle = (
|
|
7958
|
-
|
|
8014
|
+
const createBundle = (uploadPayload) => opts?.attestationRuntime ? apiCreateSellerCredentialBundle(
|
|
8015
|
+
uploadPayload,
|
|
7959
8016
|
attestationServiceUrl,
|
|
7960
8017
|
params.platform,
|
|
7961
8018
|
timeoutMs,
|
|
7962
8019
|
opts.attestationRuntime
|
|
7963
8020
|
) : apiCreateSellerCredentialBundle(
|
|
7964
|
-
|
|
8021
|
+
uploadPayload,
|
|
7965
8022
|
attestationServiceUrl,
|
|
7966
8023
|
params.platform,
|
|
7967
8024
|
timeoutMs
|
|
@@ -7973,77 +8030,42 @@ var Zkp2pClient = class {
|
|
|
7973
8030
|
if (!bundleResponse2.success || !bundleResponse2.responseObject) {
|
|
7974
8031
|
throw new Error(bundleResponse2.message || "Failed to create seller credential bundle");
|
|
7975
8032
|
}
|
|
7976
|
-
return
|
|
7977
|
-
|
|
7978
|
-
|
|
7979
|
-
|
|
7980
|
-
|
|
7981
|
-
timeoutMs
|
|
8033
|
+
return this.uploadSellerCredentialBundle(
|
|
8034
|
+
{
|
|
8035
|
+
bundle: bundleResponse2.responseObject,
|
|
8036
|
+
platform: params.platform
|
|
8037
|
+
},
|
|
8038
|
+
{ baseApiUrl, timeoutMs }
|
|
7982
8039
|
);
|
|
7983
8040
|
}
|
|
7984
|
-
const
|
|
7985
|
-
offchainId: params.offchainId,
|
|
7986
|
-
processorName: params.platform
|
|
7987
|
-
};
|
|
7988
|
-
if (params.telegramUsername !== void 0) {
|
|
7989
|
-
registeredPayeePayload.telegramUsername = params.telegramUsername;
|
|
7990
|
-
}
|
|
7991
|
-
if (params.metadata !== void 0) {
|
|
7992
|
-
registeredPayeePayload.metadata = params.metadata;
|
|
7993
|
-
}
|
|
7994
|
-
const registeredPayeeResponse = await apiPostDepositDetails(
|
|
7995
|
-
registeredPayeePayload,
|
|
7996
|
-
baseApiUrl,
|
|
7997
|
-
timeoutMs
|
|
7998
|
-
);
|
|
7999
|
-
if (!registeredPayeeResponse.success || !registeredPayeeResponse.responseObject) {
|
|
8000
|
-
throw new Error(registeredPayeeResponse.message || "Failed to register seller payee details");
|
|
8001
|
-
}
|
|
8002
|
-
const uploadPayload = {
|
|
8041
|
+
const bundlePayload = {
|
|
8003
8042
|
payeeId: params.payeeId,
|
|
8004
8043
|
sessionMaterial: params.sessionMaterial
|
|
8005
8044
|
};
|
|
8006
|
-
const bundleResponse = await createBundle(
|
|
8045
|
+
const bundleResponse = await createBundle(bundlePayload);
|
|
8007
8046
|
if (!bundleResponse.success || !bundleResponse.responseObject) {
|
|
8008
8047
|
throw new Error(bundleResponse.message || "Failed to create seller credential bundle");
|
|
8009
8048
|
}
|
|
8010
|
-
|
|
8011
|
-
|
|
8012
|
-
|
|
8013
|
-
|
|
8014
|
-
|
|
8015
|
-
|
|
8016
|
-
|
|
8017
|
-
|
|
8018
|
-
baseApiUrl,
|
|
8019
|
-
timeoutMs
|
|
8049
|
+
return this.uploadSellerCredentialBundle(
|
|
8050
|
+
{
|
|
8051
|
+
bundle: bundleResponse.responseObject,
|
|
8052
|
+
offchainId: params.offchainId,
|
|
8053
|
+
platform: params.platform,
|
|
8054
|
+
...params.telegramUsername !== void 0 ? { telegramUsername: params.telegramUsername } : {},
|
|
8055
|
+
...params.metadata !== void 0 ? { metadata: params.metadata } : {}
|
|
8056
|
+
},
|
|
8057
|
+
{ baseApiUrl, timeoutMs }
|
|
8020
8058
|
);
|
|
8021
8059
|
}
|
|
8022
8060
|
/**
|
|
8023
|
-
*
|
|
8024
|
-
*
|
|
8025
|
-
* Uses curator's `/forwarding-confirmation` route and forwards both API key and
|
|
8026
|
-
* bearer token so either auth strategy can satisfy the hybrid gate. The endpoint
|
|
8027
|
-
* is rate-limited server-side; callers should surface retry guidance from APIError.
|
|
8061
|
+
* Store an already-encrypted seller credential bundle with curator.
|
|
8028
8062
|
*/
|
|
8029
|
-
async
|
|
8063
|
+
async uploadSellerCredentialBundle(params, opts) {
|
|
8030
8064
|
const baseApiUrl = this.stripTrailingSlash(
|
|
8031
8065
|
opts?.baseApiUrl ?? this.baseApiUrl ?? DEFAULT_BASE_API_URL
|
|
8032
8066
|
);
|
|
8033
8067
|
const timeoutMs = opts?.timeoutMs ?? this.apiTimeoutMs;
|
|
8034
|
-
return
|
|
8035
|
-
params.payeeDetails,
|
|
8036
|
-
{
|
|
8037
|
-
payeeEmail: params.payeeEmail,
|
|
8038
|
-
forwardingInitiatorEmail: params.forwardingInitiatorEmail
|
|
8039
|
-
},
|
|
8040
|
-
baseApiUrl,
|
|
8041
|
-
{
|
|
8042
|
-
apiKey: this.apiKey,
|
|
8043
|
-
authToken: this.authorizationToken,
|
|
8044
|
-
timeoutMs
|
|
8045
|
-
}
|
|
8046
|
-
);
|
|
8068
|
+
return apiUploadSellerCredentialBundle(params, baseApiUrl, timeoutMs);
|
|
8047
8069
|
}
|
|
8048
8070
|
/**
|
|
8049
8071
|
* Upload a seller Gmail OAuth authorization code through curator.
|
|
@@ -8316,232 +8338,18 @@ var getPeerExtensionState = async (options) => {
|
|
|
8316
8338
|
return "needs_connection";
|
|
8317
8339
|
}
|
|
8318
8340
|
};
|
|
8319
|
-
var fiatAmountRegex = /^-?\d*(\.\d{0,6})?$/;
|
|
8320
|
-
var usdcAmountRegex = /^\d+$/;
|
|
8321
|
-
var assertObjectInput = (params) => {
|
|
8322
|
-
if (params === void 0) {
|
|
8323
|
-
throw new Error("Peer extension onramp requires query params with intentHash.");
|
|
8324
|
-
}
|
|
8325
|
-
if (params === null || typeof params !== "object" || Array.isArray(params)) {
|
|
8326
|
-
throw new Error("Peer extension onramp expects an object of query params.");
|
|
8327
|
-
}
|
|
8328
|
-
return params;
|
|
8329
|
-
};
|
|
8330
|
-
var normalizeOptionalString2 = (value, label) => {
|
|
8331
|
-
if (value === void 0) {
|
|
8332
|
-
return void 0;
|
|
8333
|
-
}
|
|
8334
|
-
if (typeof value !== "string") {
|
|
8335
|
-
throw new Error(`Peer extension onramp ${label} must be a non-empty string.`);
|
|
8336
|
-
}
|
|
8337
|
-
const trimmed = value.trim();
|
|
8338
|
-
if (!trimmed) {
|
|
8339
|
-
throw new Error(`Peer extension onramp ${label} must be a non-empty string.`);
|
|
8340
|
-
}
|
|
8341
|
-
return trimmed;
|
|
8342
|
-
};
|
|
8343
|
-
var normalizeOptionalUrl = (value, label) => {
|
|
8344
|
-
const trimmed = normalizeOptionalString2(value, label);
|
|
8345
|
-
if (trimmed === void 0) {
|
|
8346
|
-
return void 0;
|
|
8347
|
-
}
|
|
8348
|
-
let parsed;
|
|
8349
|
-
try {
|
|
8350
|
-
parsed = new URL(trimmed);
|
|
8351
|
-
} catch (error) {
|
|
8352
|
-
throw new Error(`Peer extension onramp ${label} must be a valid URL.`);
|
|
8353
|
-
}
|
|
8354
|
-
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
8355
|
-
throw new Error(`Peer extension onramp ${label} must use http or https.`);
|
|
8356
|
-
}
|
|
8357
|
-
return trimmed;
|
|
8358
|
-
};
|
|
8359
|
-
var normalizeFiatAmount = (value) => {
|
|
8360
|
-
if (value === void 0) {
|
|
8361
|
-
return void 0;
|
|
8362
|
-
}
|
|
8363
|
-
const normalized = typeof value === "number" ? String(value) : value;
|
|
8364
|
-
if (typeof normalized !== "string") {
|
|
8365
|
-
throw new Error("Peer extension onramp inputAmount must be a string or number.");
|
|
8366
|
-
}
|
|
8367
|
-
const trimmed = normalized.trim();
|
|
8368
|
-
if (!trimmed) {
|
|
8369
|
-
throw new Error("Peer extension onramp inputAmount must be a non-empty value.");
|
|
8370
|
-
}
|
|
8371
|
-
if (!fiatAmountRegex.test(trimmed)) {
|
|
8372
|
-
throw new Error(
|
|
8373
|
-
"Peer extension onramp inputAmount must be a non-negative number with up to 6 decimals."
|
|
8374
|
-
);
|
|
8375
|
-
}
|
|
8376
|
-
if (Number.isNaN(Number(trimmed)) || Number(trimmed) < 0) {
|
|
8377
|
-
throw new Error(
|
|
8378
|
-
"Peer extension onramp inputAmount must be a non-negative number with up to 6 decimals."
|
|
8379
|
-
);
|
|
8380
|
-
}
|
|
8381
|
-
return trimmed;
|
|
8382
|
-
};
|
|
8383
|
-
var normalizeUsdcAmount = (value) => {
|
|
8384
|
-
if (value === void 0) {
|
|
8385
|
-
return void 0;
|
|
8386
|
-
}
|
|
8387
|
-
if (typeof value === "bigint") {
|
|
8388
|
-
if (value < 0n) {
|
|
8389
|
-
throw new Error("Peer extension onramp amountUsdc must be a non-negative integer.");
|
|
8390
|
-
}
|
|
8391
|
-
return value.toString();
|
|
8392
|
-
}
|
|
8393
|
-
if (typeof value === "number") {
|
|
8394
|
-
if (!Number.isFinite(value) || value < 0 || !Number.isInteger(value)) {
|
|
8395
|
-
throw new Error("Peer extension onramp amountUsdc must be a non-negative integer.");
|
|
8396
|
-
}
|
|
8397
|
-
return String(value);
|
|
8398
|
-
}
|
|
8399
|
-
if (typeof value !== "string") {
|
|
8400
|
-
throw new Error("Peer extension onramp amountUsdc must be a string, number, or bigint.");
|
|
8401
|
-
}
|
|
8402
|
-
const trimmed = value.trim();
|
|
8403
|
-
if (!trimmed) {
|
|
8404
|
-
throw new Error("Peer extension onramp amountUsdc must be a non-empty value.");
|
|
8405
|
-
}
|
|
8406
|
-
if (!usdcAmountRegex.test(trimmed)) {
|
|
8407
|
-
throw new Error("Peer extension onramp amountUsdc must be a non-negative integer.");
|
|
8408
|
-
}
|
|
8409
|
-
return trimmed;
|
|
8410
|
-
};
|
|
8411
|
-
var normalizeIntegerParam = (value, label) => {
|
|
8412
|
-
if (value === void 0) {
|
|
8413
|
-
return void 0;
|
|
8414
|
-
}
|
|
8415
|
-
if (typeof value === "bigint") {
|
|
8416
|
-
if (value < 0n) {
|
|
8417
|
-
throw new Error(`Peer extension onramp ${label} must be a non-negative integer.`);
|
|
8418
|
-
}
|
|
8419
|
-
return value.toString();
|
|
8420
|
-
}
|
|
8421
|
-
if (typeof value === "number") {
|
|
8422
|
-
if (!Number.isFinite(value) || value < 0 || !Number.isInteger(value)) {
|
|
8423
|
-
throw new Error(`Peer extension onramp ${label} must be a non-negative integer.`);
|
|
8424
|
-
}
|
|
8425
|
-
if (!Number.isSafeInteger(value)) {
|
|
8426
|
-
throw new Error(
|
|
8427
|
-
`Peer extension onramp ${label} number input must be a safe integer; pass a string or bigint for larger values.`
|
|
8428
|
-
);
|
|
8429
|
-
}
|
|
8430
|
-
return String(value);
|
|
8431
|
-
}
|
|
8432
|
-
if (typeof value !== "string") {
|
|
8433
|
-
throw new Error(`Peer extension onramp ${label} must be a string, number, or bigint.`);
|
|
8434
|
-
}
|
|
8435
|
-
const trimmed = value.trim();
|
|
8436
|
-
if (!trimmed) {
|
|
8437
|
-
throw new Error(`Peer extension onramp ${label} must be a non-empty value.`);
|
|
8438
|
-
}
|
|
8439
|
-
if (!/^\d+$/.test(trimmed)) {
|
|
8440
|
-
throw new Error(`Peer extension onramp ${label} must be a non-negative integer.`);
|
|
8441
|
-
}
|
|
8442
|
-
return trimmed;
|
|
8443
|
-
};
|
|
8444
|
-
var intentHashRegex = /^0x[a-fA-F0-9]{64}$/;
|
|
8445
|
-
var normalizeIntentHash = (value) => {
|
|
8446
|
-
if (value === void 0) {
|
|
8447
|
-
throw new Error("Peer extension onramp intentHash is required.");
|
|
8448
|
-
}
|
|
8449
|
-
if (typeof value !== "string") {
|
|
8450
|
-
throw new Error("Peer extension onramp intentHash must be a string.");
|
|
8451
|
-
}
|
|
8452
|
-
const trimmed = value.trim();
|
|
8453
|
-
if (!trimmed) {
|
|
8454
|
-
throw new Error("Peer extension onramp intentHash must be a non-empty string.");
|
|
8455
|
-
}
|
|
8456
|
-
if (!intentHashRegex.test(trimmed)) {
|
|
8457
|
-
throw new Error(
|
|
8458
|
-
"Peer extension onramp intentHash must be a valid bytes32 hex string (0x + 64 hex characters)."
|
|
8459
|
-
);
|
|
8460
|
-
}
|
|
8461
|
-
return trimmed.toLowerCase();
|
|
8462
|
-
};
|
|
8463
|
-
var buildOnrampQueryString = (params) => {
|
|
8464
|
-
const validated = assertObjectInput(params);
|
|
8465
|
-
const searchParams = new URLSearchParams();
|
|
8466
|
-
const setParam = (key, value) => {
|
|
8467
|
-
if (value !== void 0) {
|
|
8468
|
-
searchParams.set(key, value);
|
|
8469
|
-
}
|
|
8470
|
-
};
|
|
8471
|
-
setParam("referrer", normalizeOptionalString2(validated.referrer, "referrer"));
|
|
8472
|
-
setParam("referrerLogo", normalizeOptionalUrl(validated.referrerLogo, "referrerLogo"));
|
|
8473
|
-
setParam("inputCurrency", normalizeOptionalString2(validated.inputCurrency, "inputCurrency"));
|
|
8474
|
-
setParam("inputAmount", normalizeFiatAmount(validated.inputAmount));
|
|
8475
|
-
setParam(
|
|
8476
|
-
"paymentPlatform",
|
|
8477
|
-
normalizeOptionalString2(validated.paymentPlatform, "paymentPlatform")
|
|
8478
|
-
);
|
|
8479
|
-
setParam("depositId", normalizeIntegerParam(validated.depositId, "depositId"));
|
|
8480
|
-
setParam("toToken", normalizeOptionalString2(validated.toToken, "toToken"));
|
|
8481
|
-
setParam("amountUsdc", normalizeUsdcAmount(validated.amountUsdc));
|
|
8482
|
-
setParam(
|
|
8483
|
-
"recipientAddress",
|
|
8484
|
-
normalizeOptionalString2(validated.recipientAddress, "recipientAddress")
|
|
8485
|
-
);
|
|
8486
|
-
setParam("intentHash", normalizeIntentHash(validated.intentHash));
|
|
8487
|
-
return searchParams.toString();
|
|
8488
|
-
};
|
|
8489
8341
|
var createPeerExtensionSdk = (options = {}) => ({
|
|
8490
8342
|
isAvailable: () => isPeerExtensionAvailable(options),
|
|
8491
8343
|
requestConnection: () => requirePeer(options).requestConnection(),
|
|
8492
8344
|
checkConnectionStatus: () => requirePeer(options).checkConnectionStatus(),
|
|
8493
|
-
openSidebar: (route) => requirePeer(options).openSidebar(route),
|
|
8494
|
-
onramp: (params, callback) => {
|
|
8495
|
-
if (typeof callback !== "function") {
|
|
8496
|
-
throw new Error("Peer extension onramp callback is required.");
|
|
8497
|
-
}
|
|
8498
|
-
requirePeer(options).onramp(buildOnrampQueryString(params), callback);
|
|
8499
|
-
},
|
|
8500
|
-
getOnrampTransaction: (intentHash) => requirePeer(options).getOnrampTransaction(normalizeIntentHash(intentHash)),
|
|
8501
8345
|
getVersion: () => requirePeer(options).getVersion(),
|
|
8346
|
+
authenticate: (params) => requirePeer(options).authenticate(params),
|
|
8347
|
+
onMetadataMessage: (callback) => requirePeer(options).onMetadataMessage(callback),
|
|
8502
8348
|
openInstallPage: () => openPeerExtensionInstallPage(options),
|
|
8503
8349
|
getState: () => getPeerExtensionState(options)
|
|
8504
8350
|
});
|
|
8505
8351
|
var peerExtensionSdk = createPeerExtensionSdk();
|
|
8506
8352
|
|
|
8507
|
-
|
|
8508
|
-
var currentLevel = "info";
|
|
8509
|
-
function setLogLevel(level) {
|
|
8510
|
-
currentLevel = level;
|
|
8511
|
-
}
|
|
8512
|
-
function shouldLog(level) {
|
|
8513
|
-
switch (currentLevel) {
|
|
8514
|
-
case "debug":
|
|
8515
|
-
return true;
|
|
8516
|
-
case "info":
|
|
8517
|
-
return level !== "debug";
|
|
8518
|
-
case "error":
|
|
8519
|
-
return level === "error";
|
|
8520
|
-
default:
|
|
8521
|
-
return true;
|
|
8522
|
-
}
|
|
8523
|
-
}
|
|
8524
|
-
var logger = {
|
|
8525
|
-
debug: (...args) => {
|
|
8526
|
-
if (shouldLog("debug")) {
|
|
8527
|
-
console.log("[DEBUG]", ...args);
|
|
8528
|
-
}
|
|
8529
|
-
},
|
|
8530
|
-
info: (...args) => {
|
|
8531
|
-
if (shouldLog("info")) {
|
|
8532
|
-
console.log("[INFO]", ...args);
|
|
8533
|
-
}
|
|
8534
|
-
},
|
|
8535
|
-
warn: (...args) => {
|
|
8536
|
-
if (shouldLog("info")) {
|
|
8537
|
-
console.warn("[WARN]", ...args);
|
|
8538
|
-
}
|
|
8539
|
-
},
|
|
8540
|
-
error: (...args) => {
|
|
8541
|
-
console.error("[ERROR]", ...args);
|
|
8542
|
-
}
|
|
8543
|
-
};
|
|
8544
|
-
|
|
8545
|
-
export { BASE_BUILDER_CODE, CHAINLINK_ORACLE_ADAPTER, CHAINLINK_ORACLE_FEEDS, ContractRouter, DEFAULT_ORACLE_MAX_STALENESS_SECONDS, IndexerClient, IndexerDepositService, IndexerRateManagerService, Zkp2pClient as OfframpClient, PAYMENT_PLATFORMS, PEER_EXTENSION_CHROME_URL, PLATFORM_METADATA, PYTH_CONTRACT_BASE, PYTH_ORACLE_ADAPTER, PYTH_ORACLE_FEEDS, SPREAD_ORACLE_FEEDS, SUPPORTED_CHAIN_IDS, TOKEN_METADATA, ZKP2P_ANDROID_REFERRER, ZKP2P_IOS_REFERRER, Zkp2pClient, apiConfirmPayPalForwarding, apiCreateSellerCredentialBundle, apiGetDepositBundle, apiGetOrderbook, apiGetOwnerDeposits, apiGetPayeeDetails, apiGetQuotesBestByPlatform, apiGetTakerTier, apiPostDepositDetails, apiRequestIdentityAttestation, apiUploadGoogleOAuthSellerCredential, apiValidatePayeeDetails, appendAttributionToCalldata, assertValidReferrerFeeConfig, compareEventCursorIdsByRecency, convertDepositsForLiquidity, convertIndexerDepositToEscrowView, convertIndexerIntentsToEscrowViews, createCompositeDepositId, createEncryptedBuyerTeeSessionMaterial, createPeerExtensionSdk, defaultIndexerEndpoint, encodePythAdapterConfig, encodeSpreadOracleAdapterConfig, encodeWithAttribution, fetchFulfillmentAndPayment as fetchIndexerFulfillmentAndPayment, getAttributionDataSuffix, getPeerExtensionState, getSpreadOracleConfig, isPeerExtensionAvailable, isValidReferrerFeeBps, isValidReferrerFeeRecipient, logger, openPeerExtensionInstallPage, parseReferrerFeeConfig, peerExtensionSdk, referrerFeeConfigToPreciseUnits, sendTransactionWithAttribution, setLogLevel, validateOracleFeedsOnChain };
|
|
8353
|
+
export { BASE_BUILDER_CODE, CHAINLINK_ORACLE_ADAPTER, CHAINLINK_ORACLE_FEEDS, ContractRouter, DEFAULT_ORACLE_MAX_STALENESS_SECONDS, IndexerClient, IndexerDepositService, IndexerRateManagerService, Zkp2pClient as OfframpClient, PAYMENT_PLATFORMS, PEER_EXTENSION_CHROME_URL, PLATFORM_METADATA, PYTH_CONTRACT_BASE, PYTH_ORACLE_ADAPTER, PYTH_ORACLE_FEEDS, SPREAD_ORACLE_FEEDS, SUPPORTED_CHAIN_IDS, TOKEN_METADATA, ZKP2P_ANDROID_REFERRER, ZKP2P_IOS_REFERRER, Zkp2pClient, apiCreateSellerCredentialBundle, apiGetDepositBundle, apiGetOrderbook, apiGetOwnerDeposits, apiGetPayeeDetails, apiGetQuotesBestByPlatform, apiGetTakerTier, apiPostDepositDetails, apiRequestIdentityAttestation, apiUploadGoogleOAuthSellerCredential, apiUploadSellerCredentialBundle, apiValidatePayeeDetails, appendAttributionToCalldata, assertValidReferrerFeeConfig, compareEventCursorIdsByRecency, convertDepositsForLiquidity, convertIndexerDepositToEscrowView, convertIndexerIntentsToEscrowViews, createCompositeDepositId, createEncryptedBuyerTeeSessionMaterial, createPeerExtensionSdk, defaultIndexerEndpoint, encodePythAdapterConfig, encodeSpreadOracleAdapterConfig, encodeWithAttribution, fetchFulfillmentAndPayment as fetchIndexerFulfillmentAndPayment, getAttributionDataSuffix, getPeerExtensionState, getSpreadOracleConfig, isPeerExtensionAvailable, isValidReferrerFeeBps, isValidReferrerFeeRecipient, logger, openPeerExtensionInstallPage, parseReferrerFeeConfig, peerExtensionSdk, referrerFeeConfigToPreciseUnits, sendTransactionWithAttribution, setLogLevel, validateOracleFeedsOnChain };
|
|
8546
8354
|
//# sourceMappingURL=index.mjs.map
|
|
8547
8355
|
//# sourceMappingURL=index.mjs.map
|