@witnium-tech/witniumchain 0.12.1 → 0.12.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/dist/index.d.mts CHANGED
@@ -12044,7 +12044,6 @@ declare class WitniumchainClient {
12044
12044
  private refreshToken;
12045
12045
  private hasRefreshCookie;
12046
12046
  private readonly oauthClientId;
12047
- private pendingLogins;
12048
12047
  private readonly verifierStorage;
12049
12048
  private discoveryCache;
12050
12049
  private refreshInFlight;
package/dist/index.d.ts CHANGED
@@ -12044,7 +12044,6 @@ declare class WitniumchainClient {
12044
12044
  private refreshToken;
12045
12045
  private hasRefreshCookie;
12046
12046
  private readonly oauthClientId;
12047
- private pendingLogins;
12048
12047
  private readonly verifierStorage;
12049
12048
  private discoveryCache;
12050
12049
  private refreshInFlight;
package/dist/index.js CHANGED
@@ -94,11 +94,6 @@ var WitniumchainClient = class {
94
94
  // refresh might work even when the in-memory refresh token is undefined.
95
95
  hasRefreshCookie = false;
96
96
  oauthClientId;
97
- // The redirect URI the most recent `beginOAuthLogin` issued, alongside the
98
- // PKCE verifier. `completeOAuthLogin` reads it back so the token-exchange
99
- // request matches the original /auth request (RFC 6749 §4.1.3 requires
100
- // redirect_uri at /token to equal the one at /auth). Keyed by state.
101
- pendingLogins = /* @__PURE__ */ new Map();
102
97
  verifierStorage;
103
98
  // Cache of the parsed OIDC discovery document keyed by issuer URL. Saves a
104
99
  // round trip on every OAuth call after the first. oidc-provider's discovery
@@ -566,7 +561,9 @@ var WitniumchainClient = class {
566
561
  // Routing: every method here passes `service: 'chain'` to `req()`. Calls
567
562
  // throw at call time if `chainBaseUrl` wasn't configured.
568
563
  //
569
- // Auth: BearerJWT. The accounts-issued OAuth access token already carries
564
+ // Auth: the contract, witness, transaction and wallet reads are public on
565
+ // chain-api (anyone can check a witness), so they send no credential. The
566
+ // dashboard reads are BearerJWT: the accounts-issued token already carries
570
567
  // `aud=https://api.witniumchain.com`, so the same `accessToken` works
571
568
  // unchanged against both services.
572
569
  //
@@ -580,49 +577,49 @@ var WitniumchainClient = class {
580
577
  return this.req(
581
578
  "GET",
582
579
  `/v5/contracts/${encodeURIComponent(contractAddress)}/info`,
583
- { auth: "BearerJWT", service: "chain" }
580
+ { auth: "Public", service: "chain" }
584
581
  );
585
582
  }
586
583
  getContractVerification(contractAddress) {
587
584
  return this.req(
588
585
  "GET",
589
586
  `/v5/contracts/${encodeURIComponent(contractAddress)}/verify`,
590
- { auth: "BearerJWT", service: "chain" }
587
+ { auth: "Public", service: "chain" }
591
588
  );
592
589
  }
593
590
  listWitnessesV5(contractAddress, params) {
594
591
  return this.req(
595
592
  "GET",
596
593
  `/v5/contracts/${encodeURIComponent(contractAddress)}/witnesses`,
597
- { auth: "BearerJWT", service: "chain", query: params }
594
+ { auth: "Public", service: "chain", query: params }
598
595
  );
599
596
  }
600
597
  getWitnessV5(contractAddress, witnessId) {
601
598
  return this.req(
602
599
  "GET",
603
600
  `/v5/contracts/${encodeURIComponent(contractAddress)}/witnesses/${encodeURIComponent(witnessId)}`,
604
- { auth: "BearerJWT", service: "chain" }
601
+ { auth: "Public", service: "chain" }
605
602
  );
606
603
  }
607
604
  getContractTransaction(contractAddress, txHash) {
608
605
  return this.req(
609
606
  "GET",
610
607
  `/v5/contracts/${encodeURIComponent(contractAddress)}/transactions/${encodeURIComponent(txHash)}`,
611
- { auth: "BearerJWT", service: "chain" }
608
+ { auth: "Public", service: "chain" }
612
609
  );
613
610
  }
614
611
  getTransaction(txHash) {
615
612
  return this.req(
616
613
  "GET",
617
614
  `/v5/transactions/${encodeURIComponent(txHash)}`,
618
- { auth: "BearerJWT", service: "chain" }
615
+ { auth: "Public", service: "chain" }
619
616
  );
620
617
  }
621
618
  getWalletBalance(address) {
622
619
  return this.req(
623
620
  "GET",
624
621
  `/v5/wallets/${encodeURIComponent(address)}/balance`,
625
- { auth: "BearerJWT", service: "chain" }
622
+ { auth: "Public", service: "chain" }
626
623
  );
627
624
  }
628
625
  getDashboardContract() {
@@ -702,8 +699,9 @@ var WitniumchainClient = class {
702
699
  url.searchParams.set("code_challenge", challenge);
703
700
  url.searchParams.set("code_challenge_method", "S256");
704
701
  if (args.prompt) url.searchParams.set("prompt", args.prompt);
705
- this.verifierStorageOrDefault().set(state, verifier);
706
- this.pendingLogins.set(state, { redirectUri: args.redirectUri });
702
+ const storage = this.verifierStorageOrDefault();
703
+ storage.set(state, verifier);
704
+ storage.set(redirectUriKey(state), args.redirectUri);
707
705
  return { authorizationUrl: url.toString(), state };
708
706
  }
709
707
  /**
@@ -756,24 +754,24 @@ var WitniumchainClient = class {
756
754
  message: "WitniumchainClient: no PKCE verifier stored for this `state`. The login flow either was not started in this tab, was already completed, or the sessionStorage entry was cleared."
757
755
  });
758
756
  }
759
- const pending = this.pendingLogins.get(state);
760
- if (!pending) {
757
+ const redirectUri = storage.get(redirectUriKey(state));
758
+ if (!redirectUri) {
761
759
  storage.remove(state);
762
760
  throw new WitniumchainApiError({
763
761
  status: 0,
764
- message: "WitniumchainClient: PKCE verifier exists but the redirectUri for this `state` was not found in client memory (the client instance was replaced between beginOAuthLogin and completeOAuthLogin)."
762
+ message: "WitniumchainClient: PKCE verifier exists but the redirectUri stored with it for this `state` is missing."
765
763
  });
766
764
  }
767
765
  const discovery = await this.fetchDiscovery();
768
766
  const form = new URLSearchParams();
769
767
  form.set("grant_type", "authorization_code");
770
768
  form.set("code", code);
771
- form.set("redirect_uri", pending.redirectUri);
769
+ form.set("redirect_uri", redirectUri);
772
770
  form.set("client_id", this.oauthClientId);
773
771
  form.set("code_verifier", verifier);
774
772
  const tokens = await this.postTokenEndpoint(discovery.token_endpoint, form);
775
773
  storage.remove(state);
776
- this.pendingLogins.delete(state);
774
+ storage.remove(redirectUriKey(state));
777
775
  return this.persistTokenResponse(tokens);
778
776
  }
779
777
  /**
@@ -923,7 +921,6 @@ var WitniumchainClient = class {
923
921
  */
924
922
  signOut() {
925
923
  this.invalidateCredentials();
926
- this.pendingLogins.clear();
927
924
  }
928
925
  // ────────────────────────────────────────────────────────────────────────
929
926
  // Internal: OAuth flow helpers
@@ -1504,6 +1501,9 @@ var MfaRecoveryCodes = class {
1504
1501
  return this.client.regenerateRecoveryCodes(proof);
1505
1502
  }
1506
1503
  };
1504
+ function redirectUriKey(state) {
1505
+ return `${state}.redirect_uri`;
1506
+ }
1507
1507
  function sleep(ms) {
1508
1508
  return new Promise((resolve) => setTimeout(resolve, ms));
1509
1509
  }