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