@zkp2p/sdk 0.4.0-rc.4 → 0.4.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.cjs CHANGED
@@ -42284,15 +42284,19 @@ init_errors();
42284
42284
  init_errors();
42285
42285
  function parseAPIError(response, responseText) {
42286
42286
  let message = `Request failed: ${response.statusText}`;
42287
+ let parsedBody;
42287
42288
  try {
42288
- const parsed = responseText ? JSON.parse(responseText) : void 0;
42289
- if (parsed && (parsed.error || parsed.message)) {
42290
- message = parsed.error || parsed.message;
42289
+ parsedBody = responseText ? JSON.parse(responseText) : void 0;
42290
+ if (parsedBody && typeof parsedBody === "object") {
42291
+ const body = parsedBody;
42292
+ if (body.error || body.message) {
42293
+ message = body.error || body.message;
42294
+ }
42291
42295
  }
42292
42296
  } catch {
42293
42297
  if (responseText && responseText.length < 200) message = responseText;
42294
42298
  }
42295
- return new exports.APIError(message, response.status, { url: response.url });
42299
+ return new exports.APIError(message, response.status, { url: response.url, responseBody: parsedBody });
42296
42300
  }
42297
42301
  async function withRetry(fn, maxRetries = 3, delayMs = 1e3, timeoutMs) {
42298
42302
  let lastErr;
@@ -42370,6 +42374,47 @@ init_errors();
42370
42374
  function headers() {
42371
42375
  return { "Content-Type": "application/json" };
42372
42376
  }
42377
+ function isPayeeBoundSellerCredentialUploadInput(payload) {
42378
+ return typeof payload.payeeId === "string";
42379
+ }
42380
+ function isWiseCredentialUploadInput(payload) {
42381
+ return typeof payload.sessionMaterial?.apiToken === "string";
42382
+ }
42383
+ async function createEncryptedSellerCredentialUploadForPlatform({
42384
+ attestationServiceUrl,
42385
+ attestationRuntime,
42386
+ payload,
42387
+ platform,
42388
+ timeoutMs
42389
+ }) {
42390
+ if (platform === "wise") {
42391
+ if (!isWiseCredentialUploadInput(payload)) {
42392
+ throw new Error("apiToken is required for wise seller credential uploads");
42393
+ }
42394
+ return zkp2pAttestation.createEncryptedSellerCredentialUpload({
42395
+ attestationServiceUrl,
42396
+ platform: "wise",
42397
+ sessionMaterial: payload.sessionMaterial,
42398
+ ...typeof timeoutMs === "number" ? { timeoutMs } : {},
42399
+ ...attestationRuntime?.fetch ? { fetch: attestationRuntime.fetch } : {},
42400
+ ...attestationRuntime?.subtle ? { subtle: attestationRuntime.subtle } : {},
42401
+ ...attestationRuntime?.getRandomValues ? { getRandomValues: attestationRuntime.getRandomValues } : {}
42402
+ });
42403
+ }
42404
+ if (!isPayeeBoundSellerCredentialUploadInput(payload)) {
42405
+ throw new Error(`payeeId is required for ${platform} seller credential uploads`);
42406
+ }
42407
+ return zkp2pAttestation.createEncryptedSellerCredentialUpload({
42408
+ attestationServiceUrl,
42409
+ platform,
42410
+ payeeId: payload.payeeId,
42411
+ sessionMaterial: payload.sessionMaterial,
42412
+ ...typeof timeoutMs === "number" ? { timeoutMs } : {},
42413
+ ...attestationRuntime?.fetch ? { fetch: attestationRuntime.fetch } : {},
42414
+ ...attestationRuntime?.subtle ? { subtle: attestationRuntime.subtle } : {},
42415
+ ...attestationRuntime?.getRandomValues ? { getRandomValues: attestationRuntime.getRandomValues } : {}
42416
+ });
42417
+ }
42373
42418
  async function apiCreatePaymentAttestation(payload, attestationServiceUrl, platform, actionType) {
42374
42419
  return withRetry(async () => {
42375
42420
  let res;
@@ -42397,14 +42442,12 @@ async function apiCreateSellerCredentialBundle(payload, attestationServiceUrl, p
42397
42442
  return withRetry(
42398
42443
  async () => {
42399
42444
  const requestFetch = attestationRuntime?.fetch ?? fetch;
42400
- const encryptedUpload = await zkp2pAttestation.createEncryptedSellerCredentialUpload({
42445
+ const encryptedUpload = await createEncryptedSellerCredentialUploadForPlatform({
42401
42446
  attestationServiceUrl,
42402
- payeeId: payload.payeeId,
42403
- sessionMaterial: payload.sessionMaterial,
42404
- ...typeof timeoutMs === "number" ? { timeoutMs } : {},
42405
- ...attestationRuntime?.fetch ? { fetch: attestationRuntime.fetch } : {},
42406
- ...attestationRuntime?.subtle ? { subtle: attestationRuntime.subtle } : {},
42407
- ...attestationRuntime?.getRandomValues ? { getRandomValues: attestationRuntime.getRandomValues } : {}
42447
+ attestationRuntime,
42448
+ payload,
42449
+ platform,
42450
+ timeoutMs
42408
42451
  });
42409
42452
  let res;
42410
42453
  try {
@@ -47100,10 +47143,16 @@ async function apiGetSellerCredentialStatus(processorName, payeeDetails, baseApi
47100
47143
  });
47101
47144
  }
47102
47145
  async function apiVerifySellerPayment(platform, req, baseApiUrl, timeoutMs, apiKey, authToken) {
47146
+ const body = {
47147
+ txId: req.txId,
47148
+ chainId: req.chainId,
47149
+ intent: req.intent,
47150
+ ...req.metadata !== void 0 ? { metadata: req.metadata } : {}
47151
+ };
47103
47152
  return apiFetch({
47104
47153
  url: `${withApiBase(baseApiUrl)}/v2/verify/seller/${encodeURIComponent(platform)}`,
47105
47154
  method: "POST",
47106
- body: req,
47155
+ body,
47107
47156
  apiKey,
47108
47157
  authToken,
47109
47158
  timeoutMs
@@ -49712,8 +49761,10 @@ var Zkp2pClient = class {
49712
49761
  * seller-automated-release availability is governed by curator's probe/revalidation state
49713
49762
  * rather than these timestamps.
49714
49763
  *
49715
- * Register or recover the payee maker row, create a signed seller credential bundle with
49716
- * attestation-service, and store it via curator's platform plus hashed payee-details route.
49764
+ * Create a signed seller credential bundle with attestation-service and store it via
49765
+ * curator's platform plus hashed payee-details route. Session-cookie platforms register
49766
+ * or recover the payee maker row before upload; Wise derives the payee hash inside the enclave
49767
+ * from the submitted Personal API Token.
49717
49768
  */
49718
49769
  async uploadSellerCredential(params, opts) {
49719
49770
  const baseApiUrl = this.stripTrailingSlash(
@@ -49723,6 +49774,33 @@ var Zkp2pClient = class {
49723
49774
  const attestationServiceUrl = this.stripTrailingSlash(
49724
49775
  opts?.attestationServiceUrl ?? this.defaultAttestationServiceForBaseApiUrl(baseApiUrl)
49725
49776
  );
49777
+ const createBundle = (uploadPayload2) => opts?.attestationRuntime ? apiCreateSellerCredentialBundle(
49778
+ uploadPayload2,
49779
+ attestationServiceUrl,
49780
+ params.platform,
49781
+ timeoutMs,
49782
+ opts.attestationRuntime
49783
+ ) : apiCreateSellerCredentialBundle(
49784
+ uploadPayload2,
49785
+ attestationServiceUrl,
49786
+ params.platform,
49787
+ timeoutMs
49788
+ );
49789
+ if (params.platform === "wise") {
49790
+ const bundleResponse2 = await createBundle({
49791
+ sessionMaterial: params.sessionMaterial
49792
+ });
49793
+ if (!bundleResponse2.success || !bundleResponse2.responseObject) {
49794
+ throw new Error(bundleResponse2.message || "Failed to create seller credential bundle");
49795
+ }
49796
+ return apiUploadSellerCredential(
49797
+ params.platform,
49798
+ bundleResponse2.responseObject.payeeIdHash,
49799
+ bundleResponse2.responseObject,
49800
+ baseApiUrl,
49801
+ timeoutMs
49802
+ );
49803
+ }
49726
49804
  const registeredPayeePayload = {
49727
49805
  offchainId: params.offchainId,
49728
49806
  processorName: params.platform
@@ -49745,18 +49823,7 @@ var Zkp2pClient = class {
49745
49823
  payeeId: params.payeeId,
49746
49824
  sessionMaterial: params.sessionMaterial
49747
49825
  };
49748
- const bundleResponse = opts?.attestationRuntime ? await apiCreateSellerCredentialBundle(
49749
- uploadPayload,
49750
- attestationServiceUrl,
49751
- params.platform,
49752
- timeoutMs,
49753
- opts.attestationRuntime
49754
- ) : await apiCreateSellerCredentialBundle(
49755
- uploadPayload,
49756
- attestationServiceUrl,
49757
- params.platform,
49758
- timeoutMs
49759
- );
49826
+ const bundleResponse = await createBundle(uploadPayload);
49760
49827
  if (!bundleResponse.success || !bundleResponse.responseObject) {
49761
49828
  throw new Error(bundleResponse.message || "Failed to create seller credential bundle");
49762
49829
  }
@@ -49810,7 +49877,8 @@ var Zkp2pClient = class {
49810
49877
  {
49811
49878
  txId: params.txId,
49812
49879
  chainId: params.chainId,
49813
- intent: params.intent
49880
+ intent: params.intent,
49881
+ ...params.metadata !== void 0 ? { metadata: params.metadata } : {}
49814
49882
  },
49815
49883
  baseApiUrl,
49816
49884
  timeoutMs,