@oasisprotocol/privana-sdk 0.5.11 → 0.6.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.
@@ -245,12 +245,21 @@ var SIWE_MESSAGE_VALIDITY_MS = 24 * 60 * 60 * 1e3;
245
245
  function buildSiweStatement(chainId) {
246
246
  return `Sign in to Privana on chain ${chainId}`;
247
247
  }
248
+ function pickSiweDomain(response) {
249
+ const allowed = response.domains;
250
+ if (!allowed?.length) throw new Error("SIWE domain response contains no domains");
251
+ const primary = allowed[0];
252
+ if (typeof window === "undefined" || !window.location?.host) return primary;
253
+ const host = window.location.host.toLowerCase();
254
+ return allowed.some((domain) => domain.toLowerCase() === host) ? host : primary;
255
+ }
248
256
  async function buildSiweLoginMessage(api, params) {
249
257
  const { address, chainId, apiUrl } = params;
250
- const [{ domain }, { nonce }] = await Promise.all([
258
+ const [domainResponse, { nonce }] = await Promise.all([
251
259
  api.getSiweDomain(),
252
260
  api.getSiweNonce(address)
253
261
  ]);
262
+ const domain = pickSiweDomain(domainResponse);
254
263
  const issuedAt = /* @__PURE__ */ new Date();
255
264
  const expirationTime = new Date(issuedAt.getTime() + SIWE_MESSAGE_VALIDITY_MS);
256
265
  const uri = typeof window !== "undefined" && window.location.origin ? window.location.origin : apiUrl;
@@ -584,7 +593,7 @@ var PrivanaClient = class _PrivanaClient {
584
593
  return this.http.get(`/v1/accounting/withdraw/${index}`);
585
594
  }
586
595
  async getSiweDomain() {
587
- return this.http.get("/v1/accounting/auth/domain");
596
+ return this.http.get("/v1/accounting/auth/domains");
588
597
  }
589
598
  async getSiweNonce(userAddress) {
590
599
  const user = normalizeAddress(userAddress);
@@ -6163,5 +6172,5 @@ exports.useSafePrivanaContext = useSafePrivanaContext;
6163
6172
  exports.useSiweAuth = useSiweAuth;
6164
6173
  exports.useTransakOnRamp = useTransakOnRamp;
6165
6174
  exports.waitForTransactionReceipt = waitForTransactionReceipt;
6166
- //# sourceMappingURL=chunk-4RHSKIPZ.cjs.map
6167
- //# sourceMappingURL=chunk-4RHSKIPZ.cjs.map
6175
+ //# sourceMappingURL=chunk-VNECVPMU.cjs.map
6176
+ //# sourceMappingURL=chunk-VNECVPMU.cjs.map