@owney/sdk 0.6.7 → 0.6.8-beta.1
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 +97 -19
- package/dist/index.d.cts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +97 -19
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -535,7 +535,8 @@ var storage = () => {
|
|
|
535
535
|
return null;
|
|
536
536
|
}
|
|
537
537
|
};
|
|
538
|
-
var buildKey = (address
|
|
538
|
+
var buildKey = (address) => `${KEY_PREFIX}:${address.toLowerCase()}`;
|
|
539
|
+
var legacyKeyPrefix = (address) => `${KEY_PREFIX}:${address.toLowerCase()}:`;
|
|
539
540
|
var isJwtExpired = (token) => {
|
|
540
541
|
const parts = token.split(".");
|
|
541
542
|
if (parts.length !== 3) return false;
|
|
@@ -552,9 +553,37 @@ var isJwtExpired = (token) => {
|
|
|
552
553
|
};
|
|
553
554
|
var memorySessions = /* @__PURE__ */ new Map();
|
|
554
555
|
var isFreshSession = (session) => !!session && !!session.token && !isJwtExpired(session.token);
|
|
555
|
-
var
|
|
556
|
+
var readLegacySession = (store, address) => {
|
|
557
|
+
if (!store) return null;
|
|
558
|
+
const prefix = legacyKeyPrefix(address);
|
|
559
|
+
const legacyKeys = [];
|
|
560
|
+
try {
|
|
561
|
+
for (let i = 0; i < store.length; i++) {
|
|
562
|
+
const key = store.key(i);
|
|
563
|
+
if (key?.startsWith(prefix)) legacyKeys.push(key);
|
|
564
|
+
}
|
|
565
|
+
} catch {
|
|
566
|
+
return null;
|
|
567
|
+
}
|
|
568
|
+
let adopted = null;
|
|
569
|
+
for (const key of legacyKeys) {
|
|
570
|
+
if (!adopted) {
|
|
571
|
+
try {
|
|
572
|
+
const parsed = JSON.parse(store.getItem(key) ?? "");
|
|
573
|
+
if (isFreshSession(parsed)) adopted = parsed;
|
|
574
|
+
} catch {
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
try {
|
|
578
|
+
store.removeItem(key);
|
|
579
|
+
} catch {
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
return adopted;
|
|
583
|
+
};
|
|
584
|
+
var readSession = (address, _chainId) => {
|
|
556
585
|
if (typeof window === "undefined") return null;
|
|
557
|
-
const key = buildKey(address
|
|
586
|
+
const key = buildKey(address);
|
|
558
587
|
const store = storage();
|
|
559
588
|
let raw = null;
|
|
560
589
|
try {
|
|
@@ -575,14 +604,19 @@ var readSession = (address, chainId) => {
|
|
|
575
604
|
}
|
|
576
605
|
return null;
|
|
577
606
|
}
|
|
607
|
+
const legacy = readLegacySession(store, address);
|
|
608
|
+
if (legacy) {
|
|
609
|
+
writeSession(address, _chainId, legacy);
|
|
610
|
+
return legacy;
|
|
611
|
+
}
|
|
578
612
|
const cached = memorySessions.get(key);
|
|
579
613
|
if (isFreshSession(cached)) return cached;
|
|
580
614
|
if (cached) memorySessions.delete(key);
|
|
581
615
|
return null;
|
|
582
616
|
};
|
|
583
|
-
var writeSession = (address,
|
|
617
|
+
var writeSession = (address, _chainId, session) => {
|
|
584
618
|
if (typeof window === "undefined") return;
|
|
585
|
-
const key = buildKey(address
|
|
619
|
+
const key = buildKey(address);
|
|
586
620
|
memorySessions.set(key, session);
|
|
587
621
|
const store = storage();
|
|
588
622
|
try {
|
|
@@ -590,14 +624,15 @@ var writeSession = (address, chainId, session) => {
|
|
|
590
624
|
} catch {
|
|
591
625
|
}
|
|
592
626
|
};
|
|
593
|
-
var clearSession = (address,
|
|
594
|
-
const key = buildKey(address
|
|
627
|
+
var clearSession = (address, _chainId) => {
|
|
628
|
+
const key = buildKey(address);
|
|
595
629
|
memorySessions.delete(key);
|
|
596
630
|
const store = storage();
|
|
597
631
|
try {
|
|
598
632
|
store?.removeItem(key);
|
|
599
633
|
} catch {
|
|
600
634
|
}
|
|
635
|
+
readLegacySession(store, address);
|
|
601
636
|
};
|
|
602
637
|
|
|
603
638
|
// src/agents/zyfai/autoSelect.ts
|
|
@@ -686,11 +721,15 @@ var ZyfaiAgent = class {
|
|
|
686
721
|
// successful decode is cached forever; failures are NOT cached so a transient
|
|
687
722
|
// RPC error retries on the next fetch.
|
|
688
723
|
withdrawAmountCache = /* @__PURE__ */ new Map();
|
|
689
|
-
constructor(apiKey, rpcUrls) {
|
|
724
|
+
constructor(apiKey, rpcUrls, referralSource) {
|
|
690
725
|
this.rpcUrls = rpcUrls ?? DEFAULT_ZYFAI_RPC_URLS;
|
|
691
726
|
this.sdk = new import_sdk.ZyfaiSDK({
|
|
692
727
|
apiKey,
|
|
693
|
-
rpcUrls: this.rpcUrls
|
|
728
|
+
rpcUrls: this.rpcUrls,
|
|
729
|
+
// Forwarded to /auth/login by the SDK's own SIWE handshake, so
|
|
730
|
+
// attribution survives without the AppKit SIWX config (which carried it
|
|
731
|
+
// via `createOwneySIWX({ referralSource })` when apps used the modal).
|
|
732
|
+
referralSource
|
|
694
733
|
});
|
|
695
734
|
this.installAuthCache();
|
|
696
735
|
}
|
|
@@ -1687,6 +1726,7 @@ var OwneySDK = class {
|
|
|
1687
1726
|
apiKey;
|
|
1688
1727
|
zyfaiRpcUrls;
|
|
1689
1728
|
routingApiBaseUrl;
|
|
1729
|
+
referralSource;
|
|
1690
1730
|
cachedSponsoredCallback = null;
|
|
1691
1731
|
cachedWethSponsoredCallback = null;
|
|
1692
1732
|
initializingAgentsPromise = null;
|
|
@@ -1694,6 +1734,7 @@ var OwneySDK = class {
|
|
|
1694
1734
|
this.apiKey = config.apiKey;
|
|
1695
1735
|
this.zyfaiRpcUrls = config.zyfaiRpcUrls;
|
|
1696
1736
|
this.routingApiBaseUrl = config.routingApiBaseUrl;
|
|
1737
|
+
this.referralSource = config.referralSource;
|
|
1697
1738
|
}
|
|
1698
1739
|
/**
|
|
1699
1740
|
* Establish connection state for all subsequent SDK calls.
|
|
@@ -1877,7 +1918,7 @@ var OwneySDK = class {
|
|
|
1877
1918
|
}
|
|
1878
1919
|
createAgent(agentId, key) {
|
|
1879
1920
|
if (agentId === "zyfai") {
|
|
1880
|
-
return new ZyfaiAgent(key, this.zyfaiRpcUrls);
|
|
1921
|
+
return new ZyfaiAgent(key, this.zyfaiRpcUrls, this.referralSource);
|
|
1881
1922
|
}
|
|
1882
1923
|
return null;
|
|
1883
1924
|
}
|
|
@@ -2763,11 +2804,39 @@ var storage2 = () => {
|
|
|
2763
2804
|
return null;
|
|
2764
2805
|
}
|
|
2765
2806
|
};
|
|
2766
|
-
var buildKey2 = (address
|
|
2807
|
+
var buildKey2 = (address) => `${KEY_PREFIX2}:${address.toLowerCase()}`;
|
|
2808
|
+
var legacyKeyPrefix2 = (address) => `${KEY_PREFIX2}:${address.toLowerCase()}:`;
|
|
2767
2809
|
var memorySiwxSessions = /* @__PURE__ */ new Map();
|
|
2810
|
+
var readLegacySiwxSession = (store, address) => {
|
|
2811
|
+
if (!store) return null;
|
|
2812
|
+
const prefix = legacyKeyPrefix2(address);
|
|
2813
|
+
const legacyKeys = [];
|
|
2814
|
+
try {
|
|
2815
|
+
for (let i = 0; i < store.length; i++) {
|
|
2816
|
+
const key = store.key(i);
|
|
2817
|
+
if (key?.startsWith(prefix)) legacyKeys.push(key);
|
|
2818
|
+
}
|
|
2819
|
+
} catch {
|
|
2820
|
+
return null;
|
|
2821
|
+
}
|
|
2822
|
+
let adopted = null;
|
|
2823
|
+
for (const key of legacyKeys) {
|
|
2824
|
+
if (!adopted) {
|
|
2825
|
+
try {
|
|
2826
|
+
adopted = JSON.parse(store.getItem(key) ?? "");
|
|
2827
|
+
} catch {
|
|
2828
|
+
}
|
|
2829
|
+
}
|
|
2830
|
+
try {
|
|
2831
|
+
store.removeItem(key);
|
|
2832
|
+
} catch {
|
|
2833
|
+
}
|
|
2834
|
+
}
|
|
2835
|
+
return adopted;
|
|
2836
|
+
};
|
|
2768
2837
|
var readSiwxSession = (address, chainId) => {
|
|
2769
2838
|
if (typeof window === "undefined") return null;
|
|
2770
|
-
const key = buildKey2(address
|
|
2839
|
+
const key = buildKey2(address);
|
|
2771
2840
|
const store = storage2();
|
|
2772
2841
|
let raw = null;
|
|
2773
2842
|
try {
|
|
@@ -2787,11 +2856,16 @@ var readSiwxSession = (address, chainId) => {
|
|
|
2787
2856
|
return null;
|
|
2788
2857
|
}
|
|
2789
2858
|
}
|
|
2859
|
+
const legacy = readLegacySiwxSession(store, address);
|
|
2860
|
+
if (legacy) {
|
|
2861
|
+
writeSiwxSession(address, chainId, legacy);
|
|
2862
|
+
return legacy;
|
|
2863
|
+
}
|
|
2790
2864
|
return memorySiwxSessions.get(key) ?? null;
|
|
2791
2865
|
};
|
|
2792
|
-
var writeSiwxSession = (address,
|
|
2866
|
+
var writeSiwxSession = (address, _chainId, session) => {
|
|
2793
2867
|
if (typeof window === "undefined") return;
|
|
2794
|
-
const key = buildKey2(address
|
|
2868
|
+
const key = buildKey2(address);
|
|
2795
2869
|
memorySiwxSessions.set(key, session);
|
|
2796
2870
|
const store = storage2();
|
|
2797
2871
|
try {
|
|
@@ -2799,14 +2873,15 @@ var writeSiwxSession = (address, chainId, session) => {
|
|
|
2799
2873
|
} catch {
|
|
2800
2874
|
}
|
|
2801
2875
|
};
|
|
2802
|
-
var clearSiwxSession = (address,
|
|
2803
|
-
const key = buildKey2(address
|
|
2876
|
+
var clearSiwxSession = (address, _chainId) => {
|
|
2877
|
+
const key = buildKey2(address);
|
|
2804
2878
|
memorySiwxSessions.delete(key);
|
|
2805
2879
|
const store = storage2();
|
|
2806
2880
|
try {
|
|
2807
2881
|
store?.removeItem(key);
|
|
2808
2882
|
} catch {
|
|
2809
2883
|
}
|
|
2884
|
+
readLegacySiwxSession(store, address);
|
|
2810
2885
|
};
|
|
2811
2886
|
|
|
2812
2887
|
// src/agents/zyfai/zyfai.siwx.ts
|
|
@@ -2870,9 +2945,12 @@ function buildSIWXConfig(deps) {
|
|
|
2870
2945
|
}
|
|
2871
2946
|
if (!stored) return [];
|
|
2872
2947
|
const session = {
|
|
2873
|
-
// `stored.data
|
|
2874
|
-
//
|
|
2875
|
-
|
|
2948
|
+
// `stored.data` is kept AppKit-free in the cache, so narrow at the
|
|
2949
|
+
// boundary. Echo the REQUESTED chain rather than the one originally
|
|
2950
|
+
// signed: the Zyfai JWT is account-scoped (no chain claim), so one
|
|
2951
|
+
// signature is valid for every chain, and AppKit would otherwise treat
|
|
2952
|
+
// the session as not covering the active network and re-prompt.
|
|
2953
|
+
data: { ...stored.data, chainId },
|
|
2876
2954
|
message: stored.message,
|
|
2877
2955
|
signature: stored.signature
|
|
2878
2956
|
};
|
package/dist/index.d.cts
CHANGED
|
@@ -15,6 +15,12 @@ interface OwneySDKConfig {
|
|
|
15
15
|
* e.g. "http://localhost:3000", when testing sponsor changes.
|
|
16
16
|
*/
|
|
17
17
|
routingApiBaseUrl?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Optional attribution tag forwarded to Zyfai's /auth/login when the SDK
|
|
20
|
+
* authenticates (e.g. "delos"). Replaces the equivalent option on
|
|
21
|
+
* `createOwneySIWX` for apps that don't use the AppKit SIWX modal.
|
|
22
|
+
*/
|
|
23
|
+
referralSource?: string;
|
|
18
24
|
}
|
|
19
25
|
interface ConnectionState {
|
|
20
26
|
provider: any;
|
|
@@ -313,6 +319,7 @@ declare class OwneySDK {
|
|
|
313
319
|
private apiKey;
|
|
314
320
|
private zyfaiRpcUrls?;
|
|
315
321
|
private routingApiBaseUrl?;
|
|
322
|
+
private referralSource?;
|
|
316
323
|
private cachedSponsoredCallback;
|
|
317
324
|
private cachedWethSponsoredCallback;
|
|
318
325
|
private initializingAgentsPromise;
|
package/dist/index.d.ts
CHANGED
|
@@ -15,6 +15,12 @@ interface OwneySDKConfig {
|
|
|
15
15
|
* e.g. "http://localhost:3000", when testing sponsor changes.
|
|
16
16
|
*/
|
|
17
17
|
routingApiBaseUrl?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Optional attribution tag forwarded to Zyfai's /auth/login when the SDK
|
|
20
|
+
* authenticates (e.g. "delos"). Replaces the equivalent option on
|
|
21
|
+
* `createOwneySIWX` for apps that don't use the AppKit SIWX modal.
|
|
22
|
+
*/
|
|
23
|
+
referralSource?: string;
|
|
18
24
|
}
|
|
19
25
|
interface ConnectionState {
|
|
20
26
|
provider: any;
|
|
@@ -313,6 +319,7 @@ declare class OwneySDK {
|
|
|
313
319
|
private apiKey;
|
|
314
320
|
private zyfaiRpcUrls?;
|
|
315
321
|
private routingApiBaseUrl?;
|
|
322
|
+
private referralSource?;
|
|
316
323
|
private cachedSponsoredCallback;
|
|
317
324
|
private cachedWethSponsoredCallback;
|
|
318
325
|
private initializingAgentsPromise;
|
package/dist/index.js
CHANGED
|
@@ -503,7 +503,8 @@ var storage = () => {
|
|
|
503
503
|
return null;
|
|
504
504
|
}
|
|
505
505
|
};
|
|
506
|
-
var buildKey = (address
|
|
506
|
+
var buildKey = (address) => `${KEY_PREFIX}:${address.toLowerCase()}`;
|
|
507
|
+
var legacyKeyPrefix = (address) => `${KEY_PREFIX}:${address.toLowerCase()}:`;
|
|
507
508
|
var isJwtExpired = (token) => {
|
|
508
509
|
const parts = token.split(".");
|
|
509
510
|
if (parts.length !== 3) return false;
|
|
@@ -520,9 +521,37 @@ var isJwtExpired = (token) => {
|
|
|
520
521
|
};
|
|
521
522
|
var memorySessions = /* @__PURE__ */ new Map();
|
|
522
523
|
var isFreshSession = (session) => !!session && !!session.token && !isJwtExpired(session.token);
|
|
523
|
-
var
|
|
524
|
+
var readLegacySession = (store, address) => {
|
|
525
|
+
if (!store) return null;
|
|
526
|
+
const prefix = legacyKeyPrefix(address);
|
|
527
|
+
const legacyKeys = [];
|
|
528
|
+
try {
|
|
529
|
+
for (let i = 0; i < store.length; i++) {
|
|
530
|
+
const key = store.key(i);
|
|
531
|
+
if (key?.startsWith(prefix)) legacyKeys.push(key);
|
|
532
|
+
}
|
|
533
|
+
} catch {
|
|
534
|
+
return null;
|
|
535
|
+
}
|
|
536
|
+
let adopted = null;
|
|
537
|
+
for (const key of legacyKeys) {
|
|
538
|
+
if (!adopted) {
|
|
539
|
+
try {
|
|
540
|
+
const parsed = JSON.parse(store.getItem(key) ?? "");
|
|
541
|
+
if (isFreshSession(parsed)) adopted = parsed;
|
|
542
|
+
} catch {
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
try {
|
|
546
|
+
store.removeItem(key);
|
|
547
|
+
} catch {
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
return adopted;
|
|
551
|
+
};
|
|
552
|
+
var readSession = (address, _chainId) => {
|
|
524
553
|
if (typeof window === "undefined") return null;
|
|
525
|
-
const key = buildKey(address
|
|
554
|
+
const key = buildKey(address);
|
|
526
555
|
const store = storage();
|
|
527
556
|
let raw = null;
|
|
528
557
|
try {
|
|
@@ -543,14 +572,19 @@ var readSession = (address, chainId) => {
|
|
|
543
572
|
}
|
|
544
573
|
return null;
|
|
545
574
|
}
|
|
575
|
+
const legacy = readLegacySession(store, address);
|
|
576
|
+
if (legacy) {
|
|
577
|
+
writeSession(address, _chainId, legacy);
|
|
578
|
+
return legacy;
|
|
579
|
+
}
|
|
546
580
|
const cached = memorySessions.get(key);
|
|
547
581
|
if (isFreshSession(cached)) return cached;
|
|
548
582
|
if (cached) memorySessions.delete(key);
|
|
549
583
|
return null;
|
|
550
584
|
};
|
|
551
|
-
var writeSession = (address,
|
|
585
|
+
var writeSession = (address, _chainId, session) => {
|
|
552
586
|
if (typeof window === "undefined") return;
|
|
553
|
-
const key = buildKey(address
|
|
587
|
+
const key = buildKey(address);
|
|
554
588
|
memorySessions.set(key, session);
|
|
555
589
|
const store = storage();
|
|
556
590
|
try {
|
|
@@ -558,14 +592,15 @@ var writeSession = (address, chainId, session) => {
|
|
|
558
592
|
} catch {
|
|
559
593
|
}
|
|
560
594
|
};
|
|
561
|
-
var clearSession = (address,
|
|
562
|
-
const key = buildKey(address
|
|
595
|
+
var clearSession = (address, _chainId) => {
|
|
596
|
+
const key = buildKey(address);
|
|
563
597
|
memorySessions.delete(key);
|
|
564
598
|
const store = storage();
|
|
565
599
|
try {
|
|
566
600
|
store?.removeItem(key);
|
|
567
601
|
} catch {
|
|
568
602
|
}
|
|
603
|
+
readLegacySession(store, address);
|
|
569
604
|
};
|
|
570
605
|
|
|
571
606
|
// src/agents/zyfai/autoSelect.ts
|
|
@@ -654,11 +689,15 @@ var ZyfaiAgent = class {
|
|
|
654
689
|
// successful decode is cached forever; failures are NOT cached so a transient
|
|
655
690
|
// RPC error retries on the next fetch.
|
|
656
691
|
withdrawAmountCache = /* @__PURE__ */ new Map();
|
|
657
|
-
constructor(apiKey, rpcUrls) {
|
|
692
|
+
constructor(apiKey, rpcUrls, referralSource) {
|
|
658
693
|
this.rpcUrls = rpcUrls ?? DEFAULT_ZYFAI_RPC_URLS;
|
|
659
694
|
this.sdk = new ZyfaiSDK({
|
|
660
695
|
apiKey,
|
|
661
|
-
rpcUrls: this.rpcUrls
|
|
696
|
+
rpcUrls: this.rpcUrls,
|
|
697
|
+
// Forwarded to /auth/login by the SDK's own SIWE handshake, so
|
|
698
|
+
// attribution survives without the AppKit SIWX config (which carried it
|
|
699
|
+
// via `createOwneySIWX({ referralSource })` when apps used the modal).
|
|
700
|
+
referralSource
|
|
662
701
|
});
|
|
663
702
|
this.installAuthCache();
|
|
664
703
|
}
|
|
@@ -1659,6 +1698,7 @@ var OwneySDK = class {
|
|
|
1659
1698
|
apiKey;
|
|
1660
1699
|
zyfaiRpcUrls;
|
|
1661
1700
|
routingApiBaseUrl;
|
|
1701
|
+
referralSource;
|
|
1662
1702
|
cachedSponsoredCallback = null;
|
|
1663
1703
|
cachedWethSponsoredCallback = null;
|
|
1664
1704
|
initializingAgentsPromise = null;
|
|
@@ -1666,6 +1706,7 @@ var OwneySDK = class {
|
|
|
1666
1706
|
this.apiKey = config.apiKey;
|
|
1667
1707
|
this.zyfaiRpcUrls = config.zyfaiRpcUrls;
|
|
1668
1708
|
this.routingApiBaseUrl = config.routingApiBaseUrl;
|
|
1709
|
+
this.referralSource = config.referralSource;
|
|
1669
1710
|
}
|
|
1670
1711
|
/**
|
|
1671
1712
|
* Establish connection state for all subsequent SDK calls.
|
|
@@ -1849,7 +1890,7 @@ var OwneySDK = class {
|
|
|
1849
1890
|
}
|
|
1850
1891
|
createAgent(agentId, key) {
|
|
1851
1892
|
if (agentId === "zyfai") {
|
|
1852
|
-
return new ZyfaiAgent(key, this.zyfaiRpcUrls);
|
|
1893
|
+
return new ZyfaiAgent(key, this.zyfaiRpcUrls, this.referralSource);
|
|
1853
1894
|
}
|
|
1854
1895
|
return null;
|
|
1855
1896
|
}
|
|
@@ -2735,11 +2776,39 @@ var storage2 = () => {
|
|
|
2735
2776
|
return null;
|
|
2736
2777
|
}
|
|
2737
2778
|
};
|
|
2738
|
-
var buildKey2 = (address
|
|
2779
|
+
var buildKey2 = (address) => `${KEY_PREFIX2}:${address.toLowerCase()}`;
|
|
2780
|
+
var legacyKeyPrefix2 = (address) => `${KEY_PREFIX2}:${address.toLowerCase()}:`;
|
|
2739
2781
|
var memorySiwxSessions = /* @__PURE__ */ new Map();
|
|
2782
|
+
var readLegacySiwxSession = (store, address) => {
|
|
2783
|
+
if (!store) return null;
|
|
2784
|
+
const prefix = legacyKeyPrefix2(address);
|
|
2785
|
+
const legacyKeys = [];
|
|
2786
|
+
try {
|
|
2787
|
+
for (let i = 0; i < store.length; i++) {
|
|
2788
|
+
const key = store.key(i);
|
|
2789
|
+
if (key?.startsWith(prefix)) legacyKeys.push(key);
|
|
2790
|
+
}
|
|
2791
|
+
} catch {
|
|
2792
|
+
return null;
|
|
2793
|
+
}
|
|
2794
|
+
let adopted = null;
|
|
2795
|
+
for (const key of legacyKeys) {
|
|
2796
|
+
if (!adopted) {
|
|
2797
|
+
try {
|
|
2798
|
+
adopted = JSON.parse(store.getItem(key) ?? "");
|
|
2799
|
+
} catch {
|
|
2800
|
+
}
|
|
2801
|
+
}
|
|
2802
|
+
try {
|
|
2803
|
+
store.removeItem(key);
|
|
2804
|
+
} catch {
|
|
2805
|
+
}
|
|
2806
|
+
}
|
|
2807
|
+
return adopted;
|
|
2808
|
+
};
|
|
2740
2809
|
var readSiwxSession = (address, chainId) => {
|
|
2741
2810
|
if (typeof window === "undefined") return null;
|
|
2742
|
-
const key = buildKey2(address
|
|
2811
|
+
const key = buildKey2(address);
|
|
2743
2812
|
const store = storage2();
|
|
2744
2813
|
let raw = null;
|
|
2745
2814
|
try {
|
|
@@ -2759,11 +2828,16 @@ var readSiwxSession = (address, chainId) => {
|
|
|
2759
2828
|
return null;
|
|
2760
2829
|
}
|
|
2761
2830
|
}
|
|
2831
|
+
const legacy = readLegacySiwxSession(store, address);
|
|
2832
|
+
if (legacy) {
|
|
2833
|
+
writeSiwxSession(address, chainId, legacy);
|
|
2834
|
+
return legacy;
|
|
2835
|
+
}
|
|
2762
2836
|
return memorySiwxSessions.get(key) ?? null;
|
|
2763
2837
|
};
|
|
2764
|
-
var writeSiwxSession = (address,
|
|
2838
|
+
var writeSiwxSession = (address, _chainId, session) => {
|
|
2765
2839
|
if (typeof window === "undefined") return;
|
|
2766
|
-
const key = buildKey2(address
|
|
2840
|
+
const key = buildKey2(address);
|
|
2767
2841
|
memorySiwxSessions.set(key, session);
|
|
2768
2842
|
const store = storage2();
|
|
2769
2843
|
try {
|
|
@@ -2771,14 +2845,15 @@ var writeSiwxSession = (address, chainId, session) => {
|
|
|
2771
2845
|
} catch {
|
|
2772
2846
|
}
|
|
2773
2847
|
};
|
|
2774
|
-
var clearSiwxSession = (address,
|
|
2775
|
-
const key = buildKey2(address
|
|
2848
|
+
var clearSiwxSession = (address, _chainId) => {
|
|
2849
|
+
const key = buildKey2(address);
|
|
2776
2850
|
memorySiwxSessions.delete(key);
|
|
2777
2851
|
const store = storage2();
|
|
2778
2852
|
try {
|
|
2779
2853
|
store?.removeItem(key);
|
|
2780
2854
|
} catch {
|
|
2781
2855
|
}
|
|
2856
|
+
readLegacySiwxSession(store, address);
|
|
2782
2857
|
};
|
|
2783
2858
|
|
|
2784
2859
|
// src/agents/zyfai/zyfai.siwx.ts
|
|
@@ -2842,9 +2917,12 @@ function buildSIWXConfig(deps) {
|
|
|
2842
2917
|
}
|
|
2843
2918
|
if (!stored) return [];
|
|
2844
2919
|
const session = {
|
|
2845
|
-
// `stored.data
|
|
2846
|
-
//
|
|
2847
|
-
|
|
2920
|
+
// `stored.data` is kept AppKit-free in the cache, so narrow at the
|
|
2921
|
+
// boundary. Echo the REQUESTED chain rather than the one originally
|
|
2922
|
+
// signed: the Zyfai JWT is account-scoped (no chain claim), so one
|
|
2923
|
+
// signature is valid for every chain, and AppKit would otherwise treat
|
|
2924
|
+
// the session as not covering the active network and re-prompt.
|
|
2925
|
+
data: { ...stored.data, chainId },
|
|
2848
2926
|
message: stored.message,
|
|
2849
2927
|
signature: stored.signature
|
|
2850
2928
|
};
|