@owney/sdk 0.6.6-beta.3 → 0.6.6-beta.4

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
@@ -583,6 +583,25 @@ var clearSession = (address, chainId) => {
583
583
  } catch {
584
584
  }
585
585
  };
586
+ var SESSION_KEY_PREFIX = "owney.zyfai.sessionkey";
587
+ var buildSessionKeyKey = (address, chainId) => `${SESSION_KEY_PREFIX}:${address.toLowerCase()}:${chainId}`;
588
+ var wasSessionKeyActivated = (address, chainId) => {
589
+ const store = storage();
590
+ if (!store) return false;
591
+ try {
592
+ return store.getItem(buildSessionKeyKey(address, chainId)) === "1";
593
+ } catch {
594
+ return false;
595
+ }
596
+ };
597
+ var markSessionKeyActivated = (address, chainId) => {
598
+ const store = storage();
599
+ if (!store) return;
600
+ try {
601
+ store.setItem(buildSessionKeyKey(address, chainId), "1");
602
+ } catch {
603
+ }
604
+ };
586
605
 
587
606
  // src/agents/zyfai/autoSelect.ts
588
607
  function buildAutoSelectUpdate(current, asset) {
@@ -836,7 +855,7 @@ var ZyfaiAgent = class {
836
855
  const wallet = await this.sdk.getSmartWalletAddress(address, validChainId);
837
856
  this.smartWalletCache.set(`${address}_${validChainId}`, wallet.address);
838
857
  if (!wallet.isDeployed) {
839
- await this.sdk.deploySafe(address, validChainId, "aggressive", true);
858
+ await this.sdk.deploySafe(address, validChainId, "aggressive", false);
840
859
  try {
841
860
  if (validChainId === 42161) {
842
861
  await this.sdk.updateUserProfile({
@@ -854,10 +873,33 @@ var ZyfaiAgent = class {
854
873
  );
855
874
  }
856
875
  }
857
- const user = await this.sdk.getUserDetails();
858
- if (!user.hasActiveSessionKey) {
859
- await this.sdk.createSessionKey(address, validChainId);
860
- }
876
+ await this.ensureSessionKey(address, validChainId);
877
+ }
878
+ /**
879
+ * Ensures a session key is active for THIS chain.
880
+ *
881
+ * The Zyfai SDK tracks session-key state with a single global boolean — the
882
+ * in-memory `hasActiveSessionKey` and the `/users/me` field of the same name
883
+ * are neither chain-scoped. Once a key is activated on one chain, both
884
+ * `getUserDetails()` and the SDK's own `createSessionKey` guard report
885
+ * "active" on every other chain, so a deposit on a freshly-used chain runs
886
+ * without a valid session key and reverts. See [[zyfai-per-chain-session-key]].
887
+ *
888
+ * We keep our own per-(address, chainId) record of activated chains (in
889
+ * localStorage). On a miss we clear the SDK's global guard so
890
+ * `createSessionKey` actually signs and activates for THIS chain.
891
+ *
892
+ * Cost: on a chain we've never recorded (e.g. a key created on another device
893
+ * or a prior app version), this forces one `createSessionKey` — an extra
894
+ * wallet signature, idempotent on the backend. A prompt-free variant would
895
+ * read the session-validator module state on-chain instead of self-tracking.
896
+ */
897
+ async ensureSessionKey(address, chainId) {
898
+ if (wasSessionKeyActivated(address, chainId)) return;
899
+ const internals = this.sdk;
900
+ internals.hasActiveSessionKey = false;
901
+ await this.sdk.createSessionKey(address, chainId);
902
+ markSessionKeyActivated(address, chainId);
861
903
  }
862
904
  /** Connect + resolve smart wallet address for read operations. */
863
905
  async resolveSmartWallet(state, chainId) {
@@ -1007,9 +1049,7 @@ var ZyfaiAgent = class {
1007
1049
  await this.connectAuth(state, chainId);
1008
1050
  const validChainId = isValidChainId(chainId);
1009
1051
  const raw = await this.sdk.getUserDetails();
1010
- if (!raw.hasActiveSessionKey) {
1011
- await this.sdk.createSessionKey(this.getAddress(), validChainId);
1012
- }
1052
+ await this.ensureSessionKey(this.getAddress(), validChainId);
1013
1053
  return mapUserProfile(raw, this.connectedAddress);
1014
1054
  }
1015
1055
  async ensureAutoSelectProtocols(state, chainId, asset) {
package/dist/index.js CHANGED
@@ -551,6 +551,25 @@ var clearSession = (address, chainId) => {
551
551
  } catch {
552
552
  }
553
553
  };
554
+ var SESSION_KEY_PREFIX = "owney.zyfai.sessionkey";
555
+ var buildSessionKeyKey = (address, chainId) => `${SESSION_KEY_PREFIX}:${address.toLowerCase()}:${chainId}`;
556
+ var wasSessionKeyActivated = (address, chainId) => {
557
+ const store = storage();
558
+ if (!store) return false;
559
+ try {
560
+ return store.getItem(buildSessionKeyKey(address, chainId)) === "1";
561
+ } catch {
562
+ return false;
563
+ }
564
+ };
565
+ var markSessionKeyActivated = (address, chainId) => {
566
+ const store = storage();
567
+ if (!store) return;
568
+ try {
569
+ store.setItem(buildSessionKeyKey(address, chainId), "1");
570
+ } catch {
571
+ }
572
+ };
554
573
 
555
574
  // src/agents/zyfai/autoSelect.ts
556
575
  function buildAutoSelectUpdate(current, asset) {
@@ -804,7 +823,7 @@ var ZyfaiAgent = class {
804
823
  const wallet = await this.sdk.getSmartWalletAddress(address, validChainId);
805
824
  this.smartWalletCache.set(`${address}_${validChainId}`, wallet.address);
806
825
  if (!wallet.isDeployed) {
807
- await this.sdk.deploySafe(address, validChainId, "aggressive", true);
826
+ await this.sdk.deploySafe(address, validChainId, "aggressive", false);
808
827
  try {
809
828
  if (validChainId === 42161) {
810
829
  await this.sdk.updateUserProfile({
@@ -822,10 +841,33 @@ var ZyfaiAgent = class {
822
841
  );
823
842
  }
824
843
  }
825
- const user = await this.sdk.getUserDetails();
826
- if (!user.hasActiveSessionKey) {
827
- await this.sdk.createSessionKey(address, validChainId);
828
- }
844
+ await this.ensureSessionKey(address, validChainId);
845
+ }
846
+ /**
847
+ * Ensures a session key is active for THIS chain.
848
+ *
849
+ * The Zyfai SDK tracks session-key state with a single global boolean — the
850
+ * in-memory `hasActiveSessionKey` and the `/users/me` field of the same name
851
+ * are neither chain-scoped. Once a key is activated on one chain, both
852
+ * `getUserDetails()` and the SDK's own `createSessionKey` guard report
853
+ * "active" on every other chain, so a deposit on a freshly-used chain runs
854
+ * without a valid session key and reverts. See [[zyfai-per-chain-session-key]].
855
+ *
856
+ * We keep our own per-(address, chainId) record of activated chains (in
857
+ * localStorage). On a miss we clear the SDK's global guard so
858
+ * `createSessionKey` actually signs and activates for THIS chain.
859
+ *
860
+ * Cost: on a chain we've never recorded (e.g. a key created on another device
861
+ * or a prior app version), this forces one `createSessionKey` — an extra
862
+ * wallet signature, idempotent on the backend. A prompt-free variant would
863
+ * read the session-validator module state on-chain instead of self-tracking.
864
+ */
865
+ async ensureSessionKey(address, chainId) {
866
+ if (wasSessionKeyActivated(address, chainId)) return;
867
+ const internals = this.sdk;
868
+ internals.hasActiveSessionKey = false;
869
+ await this.sdk.createSessionKey(address, chainId);
870
+ markSessionKeyActivated(address, chainId);
829
871
  }
830
872
  /** Connect + resolve smart wallet address for read operations. */
831
873
  async resolveSmartWallet(state, chainId) {
@@ -975,9 +1017,7 @@ var ZyfaiAgent = class {
975
1017
  await this.connectAuth(state, chainId);
976
1018
  const validChainId = isValidChainId(chainId);
977
1019
  const raw = await this.sdk.getUserDetails();
978
- if (!raw.hasActiveSessionKey) {
979
- await this.sdk.createSessionKey(this.getAddress(), validChainId);
980
- }
1020
+ await this.ensureSessionKey(this.getAddress(), validChainId);
981
1021
  return mapUserProfile(raw, this.connectedAddress);
982
1022
  }
983
1023
  async ensureAutoSelectProtocols(state, chainId, asset) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owney/sdk",
3
- "version": "0.6.6-beta.3",
3
+ "version": "0.6.6-beta.4",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",