@zkp2p/sdk 0.11.0-rc.5 → 0.11.0-rc.6

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
@@ -55606,12 +55606,15 @@ var ContractRouter = class {
55606
55606
  this.escrowV2Address ?? this.escrowAddress,
55607
55607
  primaryOrchestratorAddress
55608
55608
  );
55609
+ const pairedOrchestratorAddresses = this.orchestratorAddresses.filter(
55610
+ (address) => !isSameAddress(address, this.orchestratorV3Address)
55611
+ );
55609
55612
  const configuredPairCount = Math.min(
55610
55613
  this.escrowAddresses.length,
55611
- this.orchestratorAddresses.length
55614
+ pairedOrchestratorAddresses.length
55612
55615
  );
55613
55616
  for (let index = 0; index < configuredPairCount; index += 1) {
55614
- addEscrowOrchestratorPair(this.escrowAddresses[index], this.orchestratorAddresses[index]);
55617
+ addEscrowOrchestratorPair(this.escrowAddresses[index], pairedOrchestratorAddresses[index]);
55615
55618
  }
55616
55619
  const resolveOrchestratorAbi = (address) => this.getOrchestratorContextByAddress(address)?.abi ?? (isSameAddress(address, this.orchestratorV3Address) ? this.orchestratorV3Abi : isSameAddress(address, this.orchestratorV2Address) ? this.orchestratorV2Abi ?? this.orchestratorAbi : this.orchestratorAbi ?? this.orchestratorV2Abi);
55617
55620
  const uniqueOrchestratorAddresses = /* @__PURE__ */ new Set();
@@ -56990,8 +56993,8 @@ var IntentOperations = class {
56990
56993
  return this.config.getRuntimeEnv() === "staging" ? "https://attestation-service-staging.zkp2p.xyz" : "https://attestation-service.zkp2p.xyz";
56991
56994
  }
56992
56995
  async getFulfillIntentInputs(intentHash, options) {
56993
- const isCurrentOrchestrator = !options?.orchestratorAddress || options.orchestratorAddress.toLowerCase() === this.config.getOrchestratorV2Address()?.toLowerCase();
56994
- if (isCurrentOrchestrator) {
56996
+ const isProtocolViewerOrchestrator = !options?.orchestratorAddress || options.orchestratorAddress.toLowerCase() === this.config.getOrchestratorV2Address()?.toLowerCase() || options.orchestratorAddress.toLowerCase() === this.config.getOrchestratorV3Address()?.toLowerCase();
56997
+ if (isProtocolViewerOrchestrator) {
56995
56998
  try {
56996
56999
  if (this.config.getProtocolViewerAddress() && this.config.getProtocolViewerAbi()) {
56997
57000
  const view = await this.config.host.getPvIntent(intentHash);
@@ -57708,7 +57711,7 @@ var ProtocolViewerReader = class {
57708
57711
  return left.intent.timestamp < right.intent.timestamp ? -1 : 1;
57709
57712
  });
57710
57713
  }
57711
- async getPvIntent(intentHash) {
57714
+ async getPvIntentWithContext(intentHash) {
57712
57715
  const protocolViewerEntries = this.config.getProtocolViewerEntries();
57713
57716
  if (protocolViewerEntries.length === 0) {
57714
57717
  throw new Error("ProtocolViewer not available for this network");
@@ -57739,7 +57742,7 @@ var ProtocolViewerReader = class {
57739
57742
  });
57740
57743
  const parsed = parseIntentView2(raw);
57741
57744
  if (this.config.host.isProtocolViewerIntentPopulated(parsed)) {
57742
- return parsed;
57745
+ return { view: parsed, context };
57743
57746
  }
57744
57747
  lastError = new Error("Intent not found");
57745
57748
  } catch (readError) {
@@ -57756,7 +57759,7 @@ var ProtocolViewerReader = class {
57756
57759
  });
57757
57760
  const parsed = parseIntentView2(raw);
57758
57761
  if (this.config.host.isProtocolViewerIntentPopulated(parsed)) {
57759
- return parsed;
57762
+ return { view: parsed };
57760
57763
  }
57761
57764
  lastError = new Error("Intent not found");
57762
57765
  } catch (readError) {
@@ -57766,6 +57769,9 @@ var ProtocolViewerReader = class {
57766
57769
  }
57767
57770
  throw lastError ?? new Error("Intent not found");
57768
57771
  }
57772
+ async getPvIntent(intentHash) {
57773
+ return (await this.getPvIntentWithContext(intentHash)).view;
57774
+ }
57769
57775
  };
57770
57776
 
57771
57777
  // src/adapters/api.ts
@@ -63392,13 +63398,12 @@ var Zkp2pClient = class {
63392
63398
  throw new Error(`Failed to resolve intent routing for ${intentHash}: ${message}`);
63393
63399
  }
63394
63400
  }
63395
- async lookupIntentEscrowOnchain(intentHash) {
63396
- try {
63397
- const view = await this.getPvIntent(intentHash);
63398
- return this.normalizeAddress(view.intent.escrow);
63399
- } catch {
63400
- return void 0;
63401
- }
63401
+ async lookupIntentRoutingOnchain(intentHash) {
63402
+ const result = await this._pvReader.getPvIntentWithContext(intentHash);
63403
+ return {
63404
+ orchestratorAddress: this.normalizeAddress(result.context?.orchestrator),
63405
+ escrowAddress: this.normalizeAddress(result.context?.escrow) ?? this.normalizeAddress(result.view.intent.escrow)
63406
+ };
63402
63407
  }
63403
63408
  warnOrchestratorFallback(intentHash, source, error) {
63404
63409
  const message = error instanceof Error ? error.message : "Unknown routing error";
@@ -63410,31 +63415,22 @@ var Zkp2pClient = class {
63410
63415
  const explicit = this.getOrchestratorContextByAddress(options?.orchestratorAddress);
63411
63416
  if (explicit) return explicit;
63412
63417
  if (options?.orchestratorAddress) {
63413
- const addr = options.orchestratorAddress;
63414
- const abi = this.orchestratorV2Abi ?? this.orchestratorAbi;
63415
- if (!abi) throw new Error("Orchestrator not available");
63416
- return { address: addr, abi, version: "v2" };
63418
+ throw new Error(`Unsupported orchestrator address: ${options.orchestratorAddress}`);
63417
63419
  }
63418
63420
  if (options?.intentHash) {
63419
63421
  try {
63420
63422
  const routing = await this.lookupIntentRouting(options.intentHash);
63421
63423
  const fromIntent = this.getOrchestratorContextByAddress(routing.orchestratorAddress);
63422
63424
  if (fromIntent) return fromIntent;
63423
- if (routing.escrowAddress) {
63424
- const fromIntentEscrow = this.resolveOrchestratorForEscrow(routing.escrowAddress);
63425
- if (fromIntentEscrow) return fromIntentEscrow;
63426
- }
63427
63425
  } catch (error) {
63428
63426
  this.warnOrchestratorFallback(options.intentHash, "Indexer intent routing lookup", error);
63429
63427
  }
63430
63428
  try {
63431
- const onchainEscrow = await this.lookupIntentEscrowOnchain(options.intentHash);
63432
- if (onchainEscrow) {
63433
- const fromOnchainEscrow = this.resolveOrchestratorForEscrow(onchainEscrow);
63434
- if (fromOnchainEscrow) return fromOnchainEscrow;
63435
- }
63429
+ const routing = await this.lookupIntentRoutingOnchain(options.intentHash);
63430
+ const fromIntent = this.getOrchestratorContextByAddress(routing.orchestratorAddress);
63431
+ if (fromIntent) return fromIntent;
63436
63432
  } catch (error) {
63437
- this.warnOrchestratorFallback(options.intentHash, "On-chain intent escrow lookup", error);
63433
+ this.warnOrchestratorFallback(options.intentHash, "On-chain intent routing lookup", error);
63438
63434
  }
63439
63435
  }
63440
63436
  if (options?.escrowAddress) {
@@ -63442,19 +63438,9 @@ var Zkp2pClient = class {
63442
63438
  if (fromEscrow) return fromEscrow;
63443
63439
  }
63444
63440
  if (options?.intentHash) {
63445
- const primaryAddress = this.orchestratorV2Address ?? this.orchestratorAddress;
63446
- const primaryContext = this.getOrchestratorContextByAddress(primaryAddress);
63447
- if (primaryContext) return primaryContext;
63448
- if (primaryAddress) {
63449
- const primaryAbi = this.orchestratorV2Abi ?? this.orchestratorAbi;
63450
- if (primaryAbi) {
63451
- return {
63452
- address: primaryAddress,
63453
- abi: primaryAbi,
63454
- version: "v2"
63455
- };
63456
- }
63457
- }
63441
+ throw new Error(
63442
+ `Unable to resolve orchestrator for intent ${options.intentHash}; indexer and on-chain routing did not identify a configured orchestrator`
63443
+ );
63458
63444
  }
63459
63445
  const fallback = this.resolveOrchestratorForEscrow();
63460
63446
  if (fallback) return fallback;