@zkp2p/sdk 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -42374,6 +42374,20 @@ init_errors();
42374
42374
  function headers() {
42375
42375
  return { "Content-Type": "application/json" };
42376
42376
  }
42377
+ function normalizeOptionalString(value) {
42378
+ if (typeof value !== "string") {
42379
+ return null;
42380
+ }
42381
+ const normalized = value.trim();
42382
+ return normalized.length > 0 ? normalized : null;
42383
+ }
42384
+ function normalizeBaseUrl(value, label) {
42385
+ const normalized = normalizeOptionalString(value)?.replace(/\/+$/u, "");
42386
+ if (!normalized) {
42387
+ throw new Error(`${label} is required for buyer TEE session encryption.`);
42388
+ }
42389
+ return normalized;
42390
+ }
42377
42391
  function isPayeeBoundSellerCredentialUploadInput(payload) {
42378
42392
  return typeof payload.payeeId === "string";
42379
42393
  }
@@ -42438,6 +42452,51 @@ async function apiCreatePaymentAttestation(payload, attestationServiceUrl, platf
42438
42452
  return res.json();
42439
42453
  });
42440
42454
  }
42455
+ async function apiVerifyBuyerTeePayment(payload, attestationServiceUrl, platform, actionType) {
42456
+ return withRetry(async () => {
42457
+ let res;
42458
+ try {
42459
+ const endpoint = `/buyer/verify/${encodeURIComponent(platform)}/${encodeURIComponent(
42460
+ actionType
42461
+ )}`;
42462
+ res = await fetch(`${attestationServiceUrl}${endpoint}`, {
42463
+ method: "POST",
42464
+ headers: headers(),
42465
+ body: JSON.stringify(payload)
42466
+ });
42467
+ } catch (error) {
42468
+ throw new exports.NetworkError("Failed to connect to Attestation Service", {
42469
+ endpoint: `/buyer/verify/${platform}/${actionType}`,
42470
+ error
42471
+ });
42472
+ }
42473
+ if (!res.ok) {
42474
+ const errorText = await res.text();
42475
+ throw parseAPIError(res, errorText);
42476
+ }
42477
+ return res.json();
42478
+ });
42479
+ }
42480
+ async function createEncryptedBuyerTeeSessionMaterial({
42481
+ actionType,
42482
+ attestationRuntime,
42483
+ attestationServiceUrl,
42484
+ platform,
42485
+ sessionMaterial,
42486
+ timeoutMs
42487
+ }) {
42488
+ const params = {
42489
+ actionType,
42490
+ attestationServiceUrl: normalizeBaseUrl(attestationServiceUrl, "Attestation Service URL"),
42491
+ platform,
42492
+ sessionMaterial,
42493
+ ...timeoutMs == null ? {} : { timeoutMs },
42494
+ ...attestationRuntime?.fetch ? { fetch: attestationRuntime.fetch } : {},
42495
+ ...attestationRuntime?.subtle ? { subtle: attestationRuntime.subtle } : {},
42496
+ ...attestationRuntime?.getRandomValues ? { getRandomValues: attestationRuntime.getRandomValues } : {}
42497
+ };
42498
+ return zkp2pAttestation.createEncryptedBuyerTeeSessionMaterial(params);
42499
+ }
42441
42500
  async function apiCreateSellerCredentialBundle(payload, attestationServiceUrl, platform, timeoutMs, attestationRuntime) {
42442
42501
  return withRetry(
42443
42502
  async () => {
@@ -42492,12 +42551,13 @@ function encodePaymentAttestation(attestation) {
42492
42551
  const dataHash = td.dataHash;
42493
42552
  const signatures = [resp.signature];
42494
42553
  const encodedPaymentDetails = resp.encodedPaymentDetails;
42554
+ const metadata = typeof resp.metadata === "string" && resp.metadata.length > 0 ? resp.metadata : "0x";
42495
42555
  if (!intentHash || !releaseAmount || !dataHash || !encodedPaymentDetails) {
42496
42556
  throw new Error("Attestation response missing required fields");
42497
42557
  }
42498
42558
  return abiCoder.encode(
42499
42559
  ["tuple(bytes32,uint256,bytes32,bytes[],bytes,bytes)"],
42500
- [[intentHash, releaseAmount, dataHash, signatures, encodedPaymentDetails, "0x"]]
42560
+ [[intentHash, releaseAmount, dataHash, signatures, encodedPaymentDetails, metadata]]
42501
42561
  );
42502
42562
  }
42503
42563
 
@@ -42906,6 +42966,7 @@ var PLATFORM_ATTESTATION_CONFIG = {
42906
42966
  chime: { actionType: "transfer_chime", actionPlatform: "chime" },
42907
42967
  luxon: { actionType: "transfer_luxon", actionPlatform: "luxon" },
42908
42968
  n26: { actionType: "transfer_n26", actionPlatform: "n26" },
42969
+ alipay: { actionType: "transfer_alipay", actionPlatform: "alipay" },
42909
42970
  "zelle-chase": { actionType: "transfer_zelle", actionPlatform: "chase" },
42910
42971
  "zelle-bofa": { actionType: "transfer_zelle", actionPlatform: "bankofamerica" },
42911
42972
  "zelle-citi": { actionType: "transfer_zelle", actionPlatform: "citi" }
@@ -43206,6 +43267,8 @@ var IntentOperations = class {
43206
43267
  paymentProof = precomputed.paymentProof;
43207
43268
  verificationData = precomputed.verificationData;
43208
43269
  } else {
43270
+ const { proof } = params;
43271
+ const buyerTeeProof = parseBuyerTeePaymentProofInput(proof);
43209
43272
  const attestationServiceUrl = params.attestationServiceUrl ?? this.defaultAttestationService();
43210
43273
  const inputs = await this.config.host.getFulfillIntentInputs(intentHash, {
43211
43274
  orchestratorAddress: orchestratorContext.address
@@ -43220,24 +43283,33 @@ var IntentOperations = class {
43220
43283
  throw new Error("Unknown paymentMethodHash for this network/env; update SDK catalogs.");
43221
43284
  }
43222
43285
  const platformConfig = resolvePlatformAttestationConfig(platformName);
43223
- const zkTlsProof = typeof params.proof === "string" ? params.proof : serializeProofInput(params.proof);
43224
- const payload = {
43225
- proofType: "reclaim",
43226
- proof: zkTlsProof,
43227
- chainId: this.config.getChainId(),
43228
- intent: {
43229
- intentHash,
43230
- amount: inputs.amount,
43231
- timestampMs: inputs.intentTimestampMs,
43232
- paymentMethod: paymentMethodHash,
43233
- fiatCurrency: inputs.fiatCurrency,
43234
- conversionRate: inputs.conversionRate,
43235
- payeeDetails: inputs.payeeDetails,
43236
- timestampBufferMs: params.timestampBufferMs ?? "300000"
43237
- }
43286
+ const intent = {
43287
+ intentHash,
43288
+ amount: inputs.amount,
43289
+ timestampMs: inputs.intentTimestampMs,
43290
+ paymentMethod: paymentMethodHash,
43291
+ fiatCurrency: inputs.fiatCurrency,
43292
+ conversionRate: inputs.conversionRate,
43293
+ payeeDetails: inputs.payeeDetails,
43294
+ timestampBufferMs: params.timestampBufferMs ?? "300000"
43238
43295
  };
43239
- const attestation = await apiCreatePaymentAttestation(
43240
- payload,
43296
+ const attestation = buyerTeeProof ? await apiVerifyBuyerTeePayment(
43297
+ {
43298
+ encryptedSessionMaterial: buyerTeeProof.encryptedSessionMaterial,
43299
+ params: buyerTeeProof.params,
43300
+ chainId: this.config.getChainId(),
43301
+ intent
43302
+ },
43303
+ attestationServiceUrl,
43304
+ platformConfig.actionPlatform,
43305
+ platformConfig.actionType
43306
+ ) : await apiCreatePaymentAttestation(
43307
+ {
43308
+ proofType: "reclaim",
43309
+ proof: typeof proof === "string" ? proof : serializeProofInput(proof),
43310
+ chainId: this.config.getChainId(),
43311
+ intent
43312
+ },
43241
43313
  attestationServiceUrl,
43242
43314
  platformConfig.actionPlatform,
43243
43315
  platformConfig.actionType
@@ -43355,6 +43427,27 @@ function serializeProofInput(proof) {
43355
43427
  (_key, value) => typeof value === "bigint" ? value.toString() : value
43356
43428
  );
43357
43429
  }
43430
+ function isRecord(value) {
43431
+ return typeof value === "object" && value !== null && !Array.isArray(value);
43432
+ }
43433
+ function isBuyerTeeParams(value) {
43434
+ return isRecord(value) && Object.values(value).every(
43435
+ (entry) => typeof entry === "string" || typeof entry === "number" || typeof entry === "boolean"
43436
+ );
43437
+ }
43438
+ function parseBuyerTeePaymentProofInput(proof) {
43439
+ if (!isRecord(proof) || proof.proofType !== "buyerTee") {
43440
+ return null;
43441
+ }
43442
+ if (typeof proof.encryptedSessionMaterial !== "string" || !isBuyerTeeParams(proof.params)) {
43443
+ throw new Error("Buyer TEE proof requires encryptedSessionMaterial and params.");
43444
+ }
43445
+ return {
43446
+ proofType: "buyerTee",
43447
+ encryptedSessionMaterial: proof.encryptedSessionMaterial,
43448
+ params: proof.params
43449
+ };
43450
+ }
43358
43451
  function normalizeSignalIntentReferralFees(params) {
43359
43452
  if (params.referralFees) {
43360
43453
  return params.referralFees.map((referralFee) => ({
@@ -47132,6 +47225,19 @@ async function apiUploadSellerCredential(processorName, payeeDetails, bundle, ba
47132
47225
  timeoutMs
47133
47226
  });
47134
47227
  }
47228
+ async function apiConfirmPayPalForwarding(payeeDetails, body, baseApiUrl, opts) {
47229
+ const endpoint = `/v2/makers/paypal/${encodeURIComponent(
47230
+ payeeDetails
47231
+ )}/seller-credential/forwarding-confirmation`;
47232
+ return apiFetch({
47233
+ url: `${withApiBase(baseApiUrl)}${endpoint}`,
47234
+ method: "POST",
47235
+ body,
47236
+ apiKey: opts?.apiKey,
47237
+ authToken: opts?.authToken,
47238
+ timeoutMs: opts?.timeoutMs
47239
+ });
47240
+ }
47135
47241
  async function apiGetSellerCredentialStatus(processorName, payeeDetails, baseApiUrl, timeoutMs) {
47136
47242
  const endpoint = `/v2/makers/${encodeURIComponent(processorName)}/${encodeURIComponent(
47137
47243
  payeeDetails
@@ -47234,6 +47340,11 @@ var applyReferrerFeeDisplayFieldsToTokenAmount = (tokenAmount, referrerFeeConfig
47234
47340
  }
47235
47341
  };
47236
47342
  var applyReferrerFeeDisplayFieldsToQuote = (quote, referrerFeeConfig, decimals) => {
47343
+ const enrichedQuote = quote;
47344
+ const hasCuratorReferrerFeeFields = enrichedQuote.referrerFeeAmount != null || enrichedQuote.referrerFeeBps != null;
47345
+ if (hasCuratorReferrerFeeFields) {
47346
+ return enrichedQuote;
47347
+ }
47237
47348
  const signalIntentAmount = quote.signalIntentAmount ?? quote.intent?.amount ?? quote.tokenAmount;
47238
47349
  const adjusted = applyReferrerFeeDisplayFieldsToTokenAmount(
47239
47350
  quote.tokenAmount,
@@ -48203,7 +48314,7 @@ var Zkp2pClient = class {
48203
48314
  * ```
48204
48315
  *
48205
48316
  * @param params.intentHash - The intent hash to fulfill (0x-prefixed, 32 bytes)
48206
- * @param params.proof - Payment proof from Reclaim (object or JSON string)
48317
+ * @param params.proof - Payment proof from Reclaim (object or JSON string) or buyer TEE proof input
48207
48318
  * @param params.timestampBufferMs - Allowed timestamp variance (default: 300000ms)
48208
48319
  * @param params.attestationServiceUrl - Override attestation service URL
48209
48320
  * @param params.postIntentHookData - Data to pass to post-intent hook
@@ -49839,6 +49950,32 @@ var Zkp2pClient = class {
49839
49950
  timeoutMs
49840
49951
  );
49841
49952
  }
49953
+ /**
49954
+ * Confirms the PayPal Gmail-forwarding setup for an existing maker payee hash.
49955
+ *
49956
+ * Uses curator's `/forwarding-confirmation` route and forwards both API key and
49957
+ * bearer token so either auth strategy can satisfy the hybrid gate. The endpoint
49958
+ * is rate-limited server-side; callers should surface retry guidance from APIError.
49959
+ */
49960
+ async confirmPayPalForwarding(params, opts) {
49961
+ const baseApiUrl = this.stripTrailingSlash(
49962
+ opts?.baseApiUrl ?? this.baseApiUrl ?? DEFAULT_BASE_API_URL
49963
+ );
49964
+ const timeoutMs = opts?.timeoutMs ?? this.apiTimeoutMs;
49965
+ return apiConfirmPayPalForwarding(
49966
+ params.payeeDetails,
49967
+ {
49968
+ payeeEmail: params.payeeEmail,
49969
+ forwardingInitiatorEmail: params.forwardingInitiatorEmail
49970
+ },
49971
+ baseApiUrl,
49972
+ {
49973
+ apiKey: this.apiKey,
49974
+ authToken: this.authorizationToken,
49975
+ timeoutMs
49976
+ }
49977
+ );
49978
+ }
49842
49979
  /**
49843
49980
  * Status is a coarse curator-owned signal (`active` / `inactive` / `missing`) and intentionally
49844
49981
  * omits low-level diagnostics. Curator may still re-probe stale credentials during verify, so callers
@@ -50077,7 +50214,7 @@ var assertObjectInput = (params) => {
50077
50214
  }
50078
50215
  return params;
50079
50216
  };
50080
- var normalizeOptionalString = (value, label) => {
50217
+ var normalizeOptionalString2 = (value, label) => {
50081
50218
  if (value === void 0) {
50082
50219
  return void 0;
50083
50220
  }
@@ -50091,7 +50228,7 @@ var normalizeOptionalString = (value, label) => {
50091
50228
  return trimmed;
50092
50229
  };
50093
50230
  var normalizeOptionalUrl = (value, label) => {
50094
- const trimmed = normalizeOptionalString(value, label);
50231
+ const trimmed = normalizeOptionalString2(value, label);
50095
50232
  if (trimmed === void 0) {
50096
50233
  return void 0;
50097
50234
  }
@@ -50218,20 +50355,20 @@ var buildOnrampQueryString = (params) => {
50218
50355
  searchParams.set(key, value);
50219
50356
  }
50220
50357
  };
50221
- setParam("referrer", normalizeOptionalString(validated.referrer, "referrer"));
50358
+ setParam("referrer", normalizeOptionalString2(validated.referrer, "referrer"));
50222
50359
  setParam("referrerLogo", normalizeOptionalUrl(validated.referrerLogo, "referrerLogo"));
50223
- setParam("inputCurrency", normalizeOptionalString(validated.inputCurrency, "inputCurrency"));
50360
+ setParam("inputCurrency", normalizeOptionalString2(validated.inputCurrency, "inputCurrency"));
50224
50361
  setParam("inputAmount", normalizeFiatAmount(validated.inputAmount));
50225
50362
  setParam(
50226
50363
  "paymentPlatform",
50227
- normalizeOptionalString(validated.paymentPlatform, "paymentPlatform")
50364
+ normalizeOptionalString2(validated.paymentPlatform, "paymentPlatform")
50228
50365
  );
50229
50366
  setParam("depositId", normalizeIntegerParam(validated.depositId, "depositId"));
50230
- setParam("toToken", normalizeOptionalString(validated.toToken, "toToken"));
50367
+ setParam("toToken", normalizeOptionalString2(validated.toToken, "toToken"));
50231
50368
  setParam("amountUsdc", normalizeUsdcAmount(validated.amountUsdc));
50232
50369
  setParam(
50233
50370
  "recipientAddress",
50234
- normalizeOptionalString(validated.recipientAddress, "recipientAddress")
50371
+ normalizeOptionalString2(validated.recipientAddress, "recipientAddress")
50235
50372
  );
50236
50373
  setParam("intentHash", normalizeIntentHash(validated.intentHash));
50237
50374
  return searchParams.toString();
@@ -50351,6 +50488,7 @@ exports.ZERO_RATE_MANAGER_ID = ZERO_RATE_MANAGER_ID;
50351
50488
  exports.ZKP2P_ANDROID_REFERRER = ZKP2P_ANDROID_REFERRER;
50352
50489
  exports.ZKP2P_IOS_REFERRER = ZKP2P_IOS_REFERRER;
50353
50490
  exports.Zkp2pClient = Zkp2pClient;
50491
+ exports.apiConfirmPayPalForwarding = apiConfirmPayPalForwarding;
50354
50492
  exports.apiCreateSellerCredentialBundle = apiCreateSellerCredentialBundle;
50355
50493
  exports.apiGetDepositBundle = apiGetDepositBundle;
50356
50494
  exports.apiGetOrderbook = apiGetOrderbook;
@@ -50369,6 +50507,7 @@ exports.convertDepositsForLiquidity = convertDepositsForLiquidity;
50369
50507
  exports.convertIndexerDepositToEscrowView = convertIndexerDepositToEscrowView;
50370
50508
  exports.convertIndexerIntentsToEscrowViews = convertIndexerIntentsToEscrowViews;
50371
50509
  exports.createCompositeDepositId = createCompositeDepositId;
50510
+ exports.createEncryptedBuyerTeeSessionMaterial = createEncryptedBuyerTeeSessionMaterial;
50372
50511
  exports.createPeerExtensionSdk = createPeerExtensionSdk;
50373
50512
  exports.defaultIndexerEndpoint = defaultIndexerEndpoint;
50374
50513
  exports.encodePythAdapterConfig = encodePythAdapterConfig;