@zkp2p/sdk 0.4.3 → 0.5.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/dist/index.mjs CHANGED
@@ -1381,6 +1381,7 @@ var IntentOperations = class {
1381
1381
  paymentProof,
1382
1382
  data: encodeAddressAsBytes(attestation.responseObject.signer)
1383
1383
  });
1384
+ params.callbacks?.onAttestationComplete?.(attestation);
1384
1385
  }
1385
1386
  const args = [
1386
1387
  {
@@ -3346,6 +3347,7 @@ var INTENT_FULFILLMENTS_QUERY = (
3346
3347
  query GetFulfilledIntents($intentHashes: [String!]) {
3347
3348
  Orchestrator_V21_IntentFulfilled(where: { intentHash: { _in: $intentHashes } }) {
3348
3349
  intentHash
3350
+ amount
3349
3351
  isManualRelease
3350
3352
  fundsTransferredTo
3351
3353
  }
@@ -5381,6 +5383,58 @@ async function apiGetDepositBundle(params, optsOrBaseApiUrl, timeoutMs, apiKey)
5381
5383
  });
5382
5384
  return response.responseObject;
5383
5385
  }
5386
+
5387
+ // src/sellerCredentials.ts
5388
+ function normalizeBaseApiUrl(value) {
5389
+ return (value?.trim().replace(/\/+$/u, "") || DEFAULT_BASE_API_URL).replace(/\/v1$/u, "");
5390
+ }
5391
+ function assertBundlePlatformMatches(params) {
5392
+ if (params.bundle.platform.toLowerCase() !== params.platform) {
5393
+ throw new Error("Seller credential bundle platform does not match upload platform");
5394
+ }
5395
+ }
5396
+ async function apiUploadSellerCredentialBundle(params, baseApiUrl, timeoutMs) {
5397
+ assertBundlePlatformMatches(params);
5398
+ const normalizedBaseApiUrl = normalizeBaseApiUrl(baseApiUrl);
5399
+ if (params.platform === "wise") {
5400
+ return apiUploadSellerCredential(
5401
+ params.platform,
5402
+ params.bundle.payeeIdHash,
5403
+ params.bundle,
5404
+ normalizedBaseApiUrl,
5405
+ timeoutMs
5406
+ );
5407
+ }
5408
+ const registeredPayeePayload = {
5409
+ offchainId: params.offchainId,
5410
+ processorName: params.platform
5411
+ };
5412
+ if (params.telegramUsername !== void 0) {
5413
+ registeredPayeePayload.telegramUsername = params.telegramUsername;
5414
+ }
5415
+ if (params.metadata !== void 0) {
5416
+ registeredPayeePayload.metadata = params.metadata;
5417
+ }
5418
+ const registeredPayeeResponse = await apiPostDepositDetails(
5419
+ registeredPayeePayload,
5420
+ normalizedBaseApiUrl,
5421
+ timeoutMs
5422
+ );
5423
+ if (!registeredPayeeResponse.success || !registeredPayeeResponse.responseObject) {
5424
+ throw new Error(registeredPayeeResponse.message || "Failed to register seller payee details");
5425
+ }
5426
+ const registeredPayee = registeredPayeeResponse.responseObject;
5427
+ if (registeredPayee.hashedOnchainId.toLowerCase() !== params.bundle.payeeIdHash.toLowerCase()) {
5428
+ throw new Error("Seller credential payee hash does not match registered payee details");
5429
+ }
5430
+ return apiUploadSellerCredential(
5431
+ params.platform,
5432
+ registeredPayee.hashedOnchainId,
5433
+ params.bundle,
5434
+ normalizedBaseApiUrl,
5435
+ timeoutMs
5436
+ );
5437
+ }
5384
5438
  var formatTokenAmountForDisplay = (amount, decimals) => {
5385
5439
  const formatted = formatUnits(amount, decimals);
5386
5440
  if (!formatted.includes(".")) {
@@ -7268,7 +7322,9 @@ var Zkp2pClient = class {
7268
7322
  * { limit: 50, orderBy: 'remainingDeposits', orderDirection: 'desc' }
7269
7323
  * );
7270
7324
  *
7271
- * // Get historical fulfillment data
7325
+ * // Get historical fulfillment event data. Use `amount` for net USDC
7326
+ * // transferred to the taker; use getIntentFulfillmentAmounts() when you
7327
+ * // also need gross released USDC.
7272
7328
  * const fulfillments = await client.indexer.getFulfilledIntentEvents(['0x...']);
7273
7329
  * ```
7274
7330
  */
@@ -7330,13 +7386,15 @@ var Zkp2pClient = class {
7330
7386
  return service.fetchExpiredIntents(params);
7331
7387
  },
7332
7388
  /**
7333
- * Fetches fulfillment events for completed intents.
7389
+ * Fetches fulfillment events for completed intents. `amount` is the net
7390
+ * USDC transferred to the taker after protocol/referrer fees.
7334
7391
  */
7335
7392
  getFulfilledIntentEvents: (intentHashes) => {
7336
7393
  return service.fetchFulfilledIntentEvents(intentHashes);
7337
7394
  },
7338
7395
  /**
7339
- * Fetches gross and net fulfillment amounts for an intent.
7396
+ * Fetches gross and net fulfillment amounts for an intent. Use
7397
+ * `takerAmountNetFees` as the buyer/taker received USDC amount.
7340
7398
  */
7341
7399
  getIntentFulfillmentAmounts: (intentHash) => {
7342
7400
  return service.fetchIntentFulfillmentAmounts(intentHash);
@@ -7954,14 +8012,14 @@ var Zkp2pClient = class {
7954
8012
  const attestationServiceUrl = this.stripTrailingSlash(
7955
8013
  opts?.attestationServiceUrl ?? this.defaultAttestationServiceForBaseApiUrl(baseApiUrl)
7956
8014
  );
7957
- const createBundle = (uploadPayload2) => opts?.attestationRuntime ? apiCreateSellerCredentialBundle(
7958
- uploadPayload2,
8015
+ const createBundle = (uploadPayload) => opts?.attestationRuntime ? apiCreateSellerCredentialBundle(
8016
+ uploadPayload,
7959
8017
  attestationServiceUrl,
7960
8018
  params.platform,
7961
8019
  timeoutMs,
7962
8020
  opts.attestationRuntime
7963
8021
  ) : apiCreateSellerCredentialBundle(
7964
- uploadPayload2,
8022
+ uploadPayload,
7965
8023
  attestationServiceUrl,
7966
8024
  params.platform,
7967
8025
  timeoutMs
@@ -7973,51 +8031,42 @@ var Zkp2pClient = class {
7973
8031
  if (!bundleResponse2.success || !bundleResponse2.responseObject) {
7974
8032
  throw new Error(bundleResponse2.message || "Failed to create seller credential bundle");
7975
8033
  }
7976
- return apiUploadSellerCredential(
7977
- params.platform,
7978
- bundleResponse2.responseObject.payeeIdHash,
7979
- bundleResponse2.responseObject,
7980
- baseApiUrl,
7981
- timeoutMs
8034
+ return this.uploadSellerCredentialBundle(
8035
+ {
8036
+ bundle: bundleResponse2.responseObject,
8037
+ platform: params.platform
8038
+ },
8039
+ { baseApiUrl, timeoutMs }
7982
8040
  );
7983
8041
  }
7984
- const registeredPayeePayload = {
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 = {
8042
+ const bundlePayload = {
8003
8043
  payeeId: params.payeeId,
8004
8044
  sessionMaterial: params.sessionMaterial
8005
8045
  };
8006
- const bundleResponse = await createBundle(uploadPayload);
8046
+ const bundleResponse = await createBundle(bundlePayload);
8007
8047
  if (!bundleResponse.success || !bundleResponse.responseObject) {
8008
8048
  throw new Error(bundleResponse.message || "Failed to create seller credential bundle");
8009
8049
  }
8010
- const registeredPayee = registeredPayeeResponse.responseObject;
8011
- if (registeredPayee.hashedOnchainId.toLowerCase() !== bundleResponse.responseObject.payeeIdHash.toLowerCase()) {
8012
- throw new Error("Seller credential payee hash does not match registered payee details");
8013
- }
8014
- return apiUploadSellerCredential(
8015
- params.platform,
8016
- registeredPayee.hashedOnchainId,
8017
- bundleResponse.responseObject,
8018
- baseApiUrl,
8019
- timeoutMs
8050
+ return this.uploadSellerCredentialBundle(
8051
+ {
8052
+ bundle: bundleResponse.responseObject,
8053
+ offchainId: params.offchainId,
8054
+ platform: params.platform,
8055
+ ...params.telegramUsername !== void 0 ? { telegramUsername: params.telegramUsername } : {},
8056
+ ...params.metadata !== void 0 ? { metadata: params.metadata } : {}
8057
+ },
8058
+ { baseApiUrl, timeoutMs }
8059
+ );
8060
+ }
8061
+ /**
8062
+ * Store an already-encrypted seller credential bundle with curator.
8063
+ */
8064
+ async uploadSellerCredentialBundle(params, opts) {
8065
+ const baseApiUrl = this.stripTrailingSlash(
8066
+ opts?.baseApiUrl ?? this.baseApiUrl ?? DEFAULT_BASE_API_URL
8020
8067
  );
8068
+ const timeoutMs = opts?.timeoutMs ?? this.apiTimeoutMs;
8069
+ return apiUploadSellerCredentialBundle(params, baseApiUrl, timeoutMs);
8021
8070
  }
8022
8071
  /**
8023
8072
  * Confirms the PayPal Gmail-forwarding setup for an existing maker payee hash.
@@ -8316,189 +8365,13 @@ var getPeerExtensionState = async (options) => {
8316
8365
  return "needs_connection";
8317
8366
  }
8318
8367
  };
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
8368
  var createPeerExtensionSdk = (options = {}) => ({
8490
8369
  isAvailable: () => isPeerExtensionAvailable(options),
8491
8370
  requestConnection: () => requirePeer(options).requestConnection(),
8492
8371
  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
8372
  getVersion: () => requirePeer(options).getVersion(),
8373
+ authenticate: (params) => requirePeer(options).authenticate(params),
8374
+ onMetadataMessage: (callback) => requirePeer(options).onMetadataMessage(callback),
8502
8375
  openInstallPage: () => openPeerExtensionInstallPage(options),
8503
8376
  getState: () => getPeerExtensionState(options)
8504
8377
  });
@@ -8542,6 +8415,6 @@ var logger = {
8542
8415
  }
8543
8416
  };
8544
8417
 
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 };
8418
+ 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, 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
8419
  //# sourceMappingURL=index.mjs.map
8547
8420
  //# sourceMappingURL=index.mjs.map