@gvnrdao/dh-sdk 0.0.308 → 0.0.309

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.js CHANGED
@@ -6507,7 +6507,7 @@ async function generateExtendAuthorization(positionId, newTerm, chainId, signerO
6507
6507
  var import_ethers4 = require("ethers");
6508
6508
  function buildLoginDomain(chainId) {
6509
6509
  return {
6510
- name: "Diamond Hands lit-ops-server",
6510
+ name: "Diamond Hands",
6511
6511
  version: "1",
6512
6512
  chainId
6513
6513
  };
@@ -6622,6 +6622,8 @@ function createDefaultSessionStore() {
6622
6622
 
6623
6623
  // src/utils/server-session.ts
6624
6624
  var REFRESH_LEEWAY_SECONDS = 30;
6625
+ var LOGIN_RETRY_BASE_MS = 3e4;
6626
+ var LOGIN_RETRY_MAX_MS = 5 * 6e4;
6625
6627
  var ServerLoginError = class extends Error {
6626
6628
  constructor(message, status) {
6627
6629
  super(message);
@@ -6642,6 +6644,11 @@ var ServerSession = class {
6642
6644
  fetchImpl;
6643
6645
  cached = null;
6644
6646
  inFlight = null;
6647
+ /**
6648
+ * Set when a prompted login failed; suppresses further prompts until `until`.
6649
+ * `error` is replayed to callers so they still see the real failure reason.
6650
+ */
6651
+ promptBackoff = null;
6645
6652
  /**
6646
6653
  * Bumped by `clearPersisted()` (logout / disconnect). An in-flight
6647
6654
  * `getOrRefresh()` captures this at start and refuses to write its freshly
@@ -6716,6 +6723,7 @@ var ServerSession = class {
6716
6723
  this.generation += 1;
6717
6724
  this.cached = null;
6718
6725
  this.inFlight = null;
6726
+ this.promptBackoff = null;
6719
6727
  if (!this.store)
6720
6728
  return;
6721
6729
  try {
@@ -6812,19 +6820,39 @@ var ServerSession = class {
6812
6820
  this.inFlight = (async () => {
6813
6821
  try {
6814
6822
  const existing = await this.tryResolveSilently(gen);
6815
- if (existing)
6823
+ if (existing) {
6824
+ this.promptBackoff = null;
6816
6825
  return existing;
6826
+ }
6827
+ if (this.promptBackoff && this.now() * 1e3 < this.promptBackoff.until) {
6828
+ throw this.promptBackoff.error;
6829
+ }
6817
6830
  this.onSignaturePrompt?.();
6818
- const payload = await buildSignedLoginPayload(
6819
- this.signer,
6820
- this.chainId,
6821
- this.serviceEndpoint
6822
- );
6823
- const session = await this.login(payload);
6824
- if (notCleared()) {
6825
- this.persist(payload, session);
6826
- this.cached = session;
6831
+ let session;
6832
+ try {
6833
+ const payload = await buildSignedLoginPayload(
6834
+ this.signer,
6835
+ this.chainId,
6836
+ this.serviceEndpoint
6837
+ );
6838
+ session = await this.login(payload);
6839
+ if (notCleared()) {
6840
+ this.persist(payload, session);
6841
+ this.cached = session;
6842
+ }
6843
+ } catch (error) {
6844
+ const failures = (this.promptBackoff?.failures ?? 0) + 1;
6845
+ this.promptBackoff = {
6846
+ failures,
6847
+ error,
6848
+ until: this.now() * 1e3 + Math.min(
6849
+ LOGIN_RETRY_BASE_MS * 2 ** (failures - 1),
6850
+ LOGIN_RETRY_MAX_MS
6851
+ )
6852
+ };
6853
+ throw error;
6827
6854
  }
6855
+ this.promptBackoff = null;
6828
6856
  return session;
6829
6857
  } finally {
6830
6858
  if (notCleared())
package/dist/index.mjs CHANGED
@@ -6426,7 +6426,7 @@ async function generateExtendAuthorization(positionId, newTerm, chainId, signerO
6426
6426
  import { hexlify, randomBytes } from "ethers";
6427
6427
  function buildLoginDomain(chainId) {
6428
6428
  return {
6429
- name: "Diamond Hands lit-ops-server",
6429
+ name: "Diamond Hands",
6430
6430
  version: "1",
6431
6431
  chainId
6432
6432
  };
@@ -6541,6 +6541,8 @@ function createDefaultSessionStore() {
6541
6541
 
6542
6542
  // src/utils/server-session.ts
6543
6543
  var REFRESH_LEEWAY_SECONDS = 30;
6544
+ var LOGIN_RETRY_BASE_MS = 3e4;
6545
+ var LOGIN_RETRY_MAX_MS = 5 * 6e4;
6544
6546
  var ServerLoginError = class extends Error {
6545
6547
  constructor(message, status) {
6546
6548
  super(message);
@@ -6561,6 +6563,11 @@ var ServerSession = class {
6561
6563
  fetchImpl;
6562
6564
  cached = null;
6563
6565
  inFlight = null;
6566
+ /**
6567
+ * Set when a prompted login failed; suppresses further prompts until `until`.
6568
+ * `error` is replayed to callers so they still see the real failure reason.
6569
+ */
6570
+ promptBackoff = null;
6564
6571
  /**
6565
6572
  * Bumped by `clearPersisted()` (logout / disconnect). An in-flight
6566
6573
  * `getOrRefresh()` captures this at start and refuses to write its freshly
@@ -6635,6 +6642,7 @@ var ServerSession = class {
6635
6642
  this.generation += 1;
6636
6643
  this.cached = null;
6637
6644
  this.inFlight = null;
6645
+ this.promptBackoff = null;
6638
6646
  if (!this.store)
6639
6647
  return;
6640
6648
  try {
@@ -6731,19 +6739,39 @@ var ServerSession = class {
6731
6739
  this.inFlight = (async () => {
6732
6740
  try {
6733
6741
  const existing = await this.tryResolveSilently(gen);
6734
- if (existing)
6742
+ if (existing) {
6743
+ this.promptBackoff = null;
6735
6744
  return existing;
6745
+ }
6746
+ if (this.promptBackoff && this.now() * 1e3 < this.promptBackoff.until) {
6747
+ throw this.promptBackoff.error;
6748
+ }
6736
6749
  this.onSignaturePrompt?.();
6737
- const payload = await buildSignedLoginPayload(
6738
- this.signer,
6739
- this.chainId,
6740
- this.serviceEndpoint
6741
- );
6742
- const session = await this.login(payload);
6743
- if (notCleared()) {
6744
- this.persist(payload, session);
6745
- this.cached = session;
6750
+ let session;
6751
+ try {
6752
+ const payload = await buildSignedLoginPayload(
6753
+ this.signer,
6754
+ this.chainId,
6755
+ this.serviceEndpoint
6756
+ );
6757
+ session = await this.login(payload);
6758
+ if (notCleared()) {
6759
+ this.persist(payload, session);
6760
+ this.cached = session;
6761
+ }
6762
+ } catch (error) {
6763
+ const failures = (this.promptBackoff?.failures ?? 0) + 1;
6764
+ this.promptBackoff = {
6765
+ failures,
6766
+ error,
6767
+ until: this.now() * 1e3 + Math.min(
6768
+ LOGIN_RETRY_BASE_MS * 2 ** (failures - 1),
6769
+ LOGIN_RETRY_MAX_MS
6770
+ )
6771
+ };
6772
+ throw error;
6746
6773
  }
6774
+ this.promptBackoff = null;
6747
6775
  return session;
6748
6776
  } finally {
6749
6777
  if (notCleared())
@@ -60,6 +60,11 @@ export declare class ServerSession {
60
60
  private readonly fetchImpl;
61
61
  private cached;
62
62
  private inFlight;
63
+ /**
64
+ * Set when a prompted login failed; suppresses further prompts until `until`.
65
+ * `error` is replayed to callers so they still see the real failure reason.
66
+ */
67
+ private promptBackoff;
63
68
  /**
64
69
  * Bumped by `clearPersisted()` (logout / disconnect). An in-flight
65
70
  * `getOrRefresh()` captures this at start and refuses to write its freshly
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gvnrdao/dh-sdk",
3
- "version": "0.0.308",
3
+ "version": "0.0.309",
4
4
  "description": "TypeScript SDK for Diamond Hands Protocol - Bitcoin-backed lending with LIT Protocol PKPs",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",