@ab-org/sdk-core 0.3.0-beta.4 → 0.3.0-beta.6

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.
@@ -1,89 +1,4 @@
1
- import { CubeSignerAuth, createCubistEvmWalletProvider } from './chunk-ADMEF7PF.js';
2
-
3
- // src/core/chains.ts
4
- var chainDescriptors = {
5
- AB_CORE: {
6
- chain: "AB_CORE",
7
- namespace: "ab-core",
8
- reference: "ab:core",
9
- label: "AB Core",
10
- rpcFamily: "custom",
11
- supportsSmartSessions: true,
12
- supportsAccountAbstraction: true
13
- },
14
- ETH: {
15
- chain: "ETH",
16
- namespace: "evm",
17
- reference: "eip155:1",
18
- label: "Ethereum",
19
- rpcFamily: "evm",
20
- evmChainId: 1,
21
- supportsSmartSessions: true,
22
- supportsAccountAbstraction: true
23
- },
24
- BSC: {
25
- chain: "BSC",
26
- namespace: "evm",
27
- reference: "eip155:56",
28
- label: "BNB Smart Chain",
29
- rpcFamily: "evm",
30
- evmChainId: 56,
31
- supportsSmartSessions: true,
32
- supportsAccountAbstraction: false
33
- },
34
- ETH_TENDERLY: {
35
- chain: "ETH_TENDERLY",
36
- namespace: "evm",
37
- reference: "eip155:3030",
38
- label: "Ethereum Tenderly",
39
- rpcFamily: "evm",
40
- evmChainId: 3030,
41
- supportsSmartSessions: true,
42
- supportsAccountAbstraction: true
43
- },
44
- BSC_TENDERLY: {
45
- chain: "BSC_TENDERLY",
46
- namespace: "evm",
47
- reference: "eip155:3131",
48
- label: "BNB Smart Chain Tenderly",
49
- rpcFamily: "evm",
50
- evmChainId: 3131,
51
- supportsSmartSessions: true,
52
- supportsAccountAbstraction: false
53
- },
54
- SOL: {
55
- chain: "SOL",
56
- namespace: "solana",
57
- reference: "solana:mainnet-beta",
58
- label: "Solana",
59
- rpcFamily: "solana",
60
- supportsSmartSessions: true,
61
- supportsAccountAbstraction: false
62
- }
63
- };
64
- var getChainDescriptor = (chain) => chainDescriptors[chain];
65
- var getAllChainDescriptors = () => Object.values(chainDescriptors);
66
- var normalizeEvmChainId = (value) => {
67
- if (typeof value === "number") return value;
68
- if (typeof value === "bigint") return Number(value);
69
- return Number(BigInt(value));
70
- };
71
- var getSupportedChainFromEvmChainId = (value) => {
72
- const chainId = normalizeEvmChainId(value);
73
- const descriptor = getAllChainDescriptors().find(
74
- (item) => item.namespace === "evm" && item.evmChainId === chainId
75
- );
76
- if (!descriptor) {
77
- throw new Error(`Unsupported EVM chainId: ${chainId}`);
78
- }
79
- return descriptor.chain;
80
- };
81
- var createChainContext = (walletChain, settlementChain = walletChain) => ({
82
- walletChain,
83
- walletChainDescriptor: getChainDescriptor(walletChain),
84
- settlementChain,
85
- settlementChainDescriptor: getChainDescriptor(settlementChain)
86
- });
1
+ import { CubeSignerAuth, createChainContext, createCubistEvmWalletProvider } from './chunk-V4LAUAGS.js';
87
2
 
88
3
  // src/core/capabilities.ts
89
4
  var SessionCapabilityError = class extends Error {
@@ -251,6 +166,15 @@ var CubistSocialProvider = class extends AbstractSocialProvider {
251
166
  /** Stash the login method so `connect()` can auto-retry. */
252
167
  this.lastLogin = null;
253
168
  this.auth = new CubeSignerAuth(config);
169
+ this.auth.onSessionDataUpdated = (sessionData) => {
170
+ if (this.lastCubeSignerSession) {
171
+ this.lastCubeSignerSession = {
172
+ ...this.lastCubeSignerSession,
173
+ sessionData
174
+ };
175
+ }
176
+ this.onSessionDataUpdated?.(sessionData);
177
+ };
254
178
  this.adapter = adapter;
255
179
  }
256
180
  async createWalletSession(method) {
@@ -258,12 +182,15 @@ var CubistSocialProvider = class extends AbstractSocialProvider {
258
182
  this.lastCubeSignerSession = session;
259
183
  const walletSession = await this.adapter.resolve(session);
260
184
  const capabilityPolicy = this.auth.defaultSessionPolicy ? createSessionCapabilityPolicy(this.auth.defaultSessionPolicy) : void 0;
185
+ const sessionExpMs = session.sessionData.session_exp ? session.sessionData.session_exp * 1e3 : void 0;
186
+ const expiresAt = capabilityPolicy?.expiresAt && sessionExpMs ? Math.min(capabilityPolicy.expiresAt, sessionExpMs) : capabilityPolicy?.expiresAt ?? sessionExpMs;
261
187
  return {
262
188
  ...walletSession,
263
189
  walletType: "social",
264
190
  authSource: method.type,
265
191
  sessionId: `${method.type}:${walletSession.address.toLowerCase()}`,
266
- expiresAt: capabilityPolicy?.expiresAt,
192
+ issuedAt: Date.now(),
193
+ expiresAt,
267
194
  capabilities: CUBIST_CAPABILITIES,
268
195
  sessionData: session.sessionData,
269
196
  chainContext: walletSession.chainContext ?? createChainContext(walletSession.chain),
@@ -334,6 +261,8 @@ var CubistSocialProvider = class extends AbstractSocialProvider {
334
261
  address: walletSession.address,
335
262
  chain: restoredChain
336
263
  });
264
+ const sessionExpMs = csSession.sessionData.session_exp ? csSession.sessionData.session_exp * 1e3 : void 0;
265
+ const expiresAt = persistedSession.expiresAt && sessionExpMs ? Math.min(persistedSession.expiresAt, sessionExpMs) : persistedSession.expiresAt ?? sessionExpMs;
337
266
  return this.setSession({
338
267
  ...walletSession,
339
268
  chain: restoredChain,
@@ -341,7 +270,8 @@ var CubistSocialProvider = class extends AbstractSocialProvider {
341
270
  walletType: persistedSession.walletType ?? "social",
342
271
  authSource: persistedSession.authSource,
343
272
  sessionId: persistedSession.sessionId,
344
- expiresAt: persistedSession.expiresAt,
273
+ issuedAt: persistedSession.issuedAt,
274
+ expiresAt,
345
275
  capabilities: CUBIST_CAPABILITIES,
346
276
  sessionData: csSession.sessionData,
347
277
  chainContext: createChainContext(restoredChain),
@@ -370,4 +300,4 @@ var CubistSocialProvider = class extends AbstractSocialProvider {
370
300
  }
371
301
  };
372
302
 
373
- export { AbstractProvider, AbstractSocialProvider, CUBIST_CAPABILITIES, CubistSocialProvider, SessionCapabilityError, assertSessionCapability, createChainContext, createSessionCapabilityPolicy, describeSessionCapabilityPolicy, getAllChainDescriptors, getChainDescriptor, getSupportedChainFromEvmChainId, isCapabilityPolicyExpired, isSessionExpired, sessionSupportsCapability };
303
+ export { AbstractProvider, AbstractSocialProvider, CUBIST_CAPABILITIES, CubistSocialProvider, SessionCapabilityError, assertSessionCapability, createSessionCapabilityPolicy, describeSessionCapabilityPolicy, isCapabilityPolicyExpired, isSessionExpired, sessionSupportsCapability };
@@ -1,3 +1,4 @@
1
+ import EventEmitter from 'eventemitter3';
1
2
  import { jwtDecode } from 'jwt-decode';
2
3
 
3
4
  var __typeError = (msg) => {
@@ -9,6 +10,265 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
9
10
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
10
11
  var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
11
12
 
13
+ // src/core/chains.ts
14
+ var chainDescriptors = {
15
+ AB_CORE: {
16
+ chain: "AB_CORE",
17
+ namespace: "ab-core",
18
+ reference: "ab:core",
19
+ label: "AB Core",
20
+ rpcFamily: "custom",
21
+ supportsSmartSessions: true,
22
+ supportsAccountAbstraction: true
23
+ },
24
+ ETH: {
25
+ chain: "ETH",
26
+ namespace: "evm",
27
+ reference: "eip155:1",
28
+ label: "Ethereum",
29
+ rpcFamily: "evm",
30
+ evmChainId: 1,
31
+ supportsSmartSessions: true,
32
+ supportsAccountAbstraction: true
33
+ },
34
+ BSC: {
35
+ chain: "BSC",
36
+ namespace: "evm",
37
+ reference: "eip155:56",
38
+ label: "BNB Smart Chain",
39
+ rpcFamily: "evm",
40
+ evmChainId: 56,
41
+ supportsSmartSessions: true,
42
+ supportsAccountAbstraction: false
43
+ },
44
+ ETH_TENDERLY: {
45
+ chain: "ETH_TENDERLY",
46
+ namespace: "evm",
47
+ reference: "eip155:3030",
48
+ label: "Ethereum Tenderly",
49
+ rpcFamily: "evm",
50
+ evmChainId: 3030,
51
+ supportsSmartSessions: true,
52
+ supportsAccountAbstraction: true
53
+ },
54
+ BSC_TENDERLY: {
55
+ chain: "BSC_TENDERLY",
56
+ namespace: "evm",
57
+ reference: "eip155:3131",
58
+ label: "BNB Smart Chain Tenderly",
59
+ rpcFamily: "evm",
60
+ evmChainId: 3131,
61
+ supportsSmartSessions: true,
62
+ supportsAccountAbstraction: false
63
+ },
64
+ SOL: {
65
+ chain: "SOL",
66
+ namespace: "solana",
67
+ reference: "solana:mainnet-beta",
68
+ label: "Solana",
69
+ rpcFamily: "solana",
70
+ supportsSmartSessions: true,
71
+ supportsAccountAbstraction: false
72
+ }
73
+ };
74
+ var getChainDescriptor = (chain) => chainDescriptors[chain];
75
+ var getAllChainDescriptors = () => Object.values(chainDescriptors);
76
+ var normalizeEvmChainId = (value) => {
77
+ if (typeof value === "number") return value;
78
+ if (typeof value === "bigint") return Number(value);
79
+ return Number(BigInt(value));
80
+ };
81
+ var getSupportedChainFromEvmChainId = (value) => {
82
+ const chainId = normalizeEvmChainId(value);
83
+ const descriptor = getAllChainDescriptors().find(
84
+ (item) => item.namespace === "evm" && item.evmChainId === chainId
85
+ );
86
+ if (!descriptor) {
87
+ throw new Error(`Unsupported EVM chainId: ${chainId}`);
88
+ }
89
+ return descriptor.chain;
90
+ };
91
+ var createChainContext = (walletChain, settlementChain = walletChain) => ({
92
+ walletChain,
93
+ walletChainDescriptor: getChainDescriptor(walletChain),
94
+ settlementChain,
95
+ settlementChainDescriptor: getChainDescriptor(settlementChain)
96
+ });
97
+ var STORAGE_KEY = "ab:wallet:session";
98
+ function getStorage() {
99
+ try {
100
+ return typeof localStorage !== "undefined" ? localStorage : null;
101
+ } catch {
102
+ return null;
103
+ }
104
+ }
105
+ function persistSession(session) {
106
+ const storage = getStorage();
107
+ if (!storage) return;
108
+ if (!session) {
109
+ storage.removeItem(STORAGE_KEY);
110
+ return;
111
+ }
112
+ const serializable = {
113
+ address: session.address,
114
+ chain: session.chain,
115
+ walletType: session.walletType,
116
+ authSource: session.authSource,
117
+ sessionId: session.sessionId,
118
+ issuedAt: session.issuedAt,
119
+ expiresAt: session.expiresAt
120
+ };
121
+ if (session.capabilities?.length) {
122
+ serializable.capabilities = session.capabilities;
123
+ }
124
+ if (session.sessionData !== void 0) {
125
+ serializable.sessionData = session.sessionData;
126
+ }
127
+ if (session.capabilityPolicy !== void 0) {
128
+ serializable.capabilityPolicy = session.capabilityPolicy;
129
+ }
130
+ if (session.userInfo !== void 0) {
131
+ serializable.userInfo = session.userInfo;
132
+ }
133
+ try {
134
+ storage.setItem(STORAGE_KEY, JSON.stringify(serializable));
135
+ } catch {
136
+ storage.removeItem(STORAGE_KEY);
137
+ }
138
+ }
139
+ function readPersistedSession() {
140
+ const storage = getStorage();
141
+ if (!storage) return null;
142
+ const raw = storage.getItem(STORAGE_KEY);
143
+ if (!raw) return null;
144
+ try {
145
+ return JSON.parse(raw);
146
+ } catch {
147
+ storage.removeItem(STORAGE_KEY);
148
+ return null;
149
+ }
150
+ }
151
+ var STALE_SESSION_ERROR_MESSAGE = "Session restored from cache. Reconnect your wallet for transactions.";
152
+ var USER_SESSION_EXPIRED_MESSAGE = "Session expired. Please reconnect your wallet and try again.";
153
+ function isStaleSessionError(error) {
154
+ return error instanceof Error && error.message.includes(STALE_SESSION_ERROR_MESSAGE);
155
+ }
156
+ var staleProvider = {
157
+ request() {
158
+ return Promise.reject(new Error(STALE_SESSION_ERROR_MESSAGE));
159
+ },
160
+ disconnect() {
161
+ return Promise.resolve();
162
+ }
163
+ };
164
+ var SessionStore = class {
165
+ constructor() {
166
+ this.state = {
167
+ session: null,
168
+ balance: null,
169
+ isConnecting: false
170
+ };
171
+ this.emitter = new EventEmitter();
172
+ this._pendingExpiredSession = null;
173
+ this._expiryTimerId = null;
174
+ this.tryRehydrate();
175
+ }
176
+ getState() {
177
+ return { ...this.state };
178
+ }
179
+ setConnecting(flag) {
180
+ this.state.isConnecting = flag;
181
+ this.emitter.emit("connecting:changed", flag);
182
+ }
183
+ setSession(session) {
184
+ this.state.session = session;
185
+ persistSession(session);
186
+ this.emitter.emit("session:changed", session);
187
+ }
188
+ rehydrateSession(session) {
189
+ this.state.session = session;
190
+ persistSession(session);
191
+ this.emitter.emit("session:changed", session);
192
+ this.emitter.emit("session:rehydrated", session);
193
+ }
194
+ clearSession() {
195
+ this.state.session = null;
196
+ this.state.balance = null;
197
+ persistSession(null);
198
+ this.emitter.emit("session:changed", null);
199
+ this.emitter.emit("balance:changed", null);
200
+ }
201
+ expireSession() {
202
+ const currentSession = this.state.session;
203
+ if (!currentSession) return;
204
+ this.clearSession();
205
+ this.emitter.emit("session:expired", currentSession);
206
+ }
207
+ revokeSession() {
208
+ const currentSession = this.state.session;
209
+ if (!currentSession) return;
210
+ this.clearSession();
211
+ this.emitter.emit("session:revoked", currentSession);
212
+ }
213
+ setBalance(balance) {
214
+ this.state.balance = balance;
215
+ this.emitter.emit("balance:changed", balance);
216
+ }
217
+ on(event, listener) {
218
+ this.emitter.on(event, listener);
219
+ return () => this.emitter.off(event, listener);
220
+ }
221
+ /**
222
+ * Emit `session:expired` for a session that was already expired at rehydration time.
223
+ * Call this after attaching listeners so the event is actually received.
224
+ */
225
+ flushPendingExpiry() {
226
+ const pending = this._pendingExpiredSession;
227
+ if (!pending) return;
228
+ this._pendingExpiredSession = null;
229
+ this.emitter.emit("session:expired", pending);
230
+ }
231
+ /**
232
+ * Start a periodic timer that checks whether the current session has expired.
233
+ * When `session.expiresAt <= Date.now()`, calls `expireSession()` which emits `session:expired`.
234
+ */
235
+ startExpiryTimer(intervalMs = 3e4) {
236
+ this.stopExpiryTimer();
237
+ if (typeof setInterval === "undefined") return;
238
+ this._expiryTimerId = setInterval(() => {
239
+ const session = this.state.session;
240
+ if (session?.expiresAt && session.expiresAt <= Date.now()) {
241
+ this.expireSession();
242
+ }
243
+ }, intervalMs);
244
+ }
245
+ stopExpiryTimer() {
246
+ if (this._expiryTimerId != null) {
247
+ clearInterval(this._expiryTimerId);
248
+ this._expiryTimerId = null;
249
+ }
250
+ }
251
+ tryRehydrate() {
252
+ const persisted = readPersistedSession();
253
+ if (!persisted) return;
254
+ if (persisted.expiresAt && persisted.expiresAt <= Date.now()) {
255
+ persistSession(null);
256
+ this._pendingExpiredSession = {
257
+ ...persisted,
258
+ provider: staleProvider,
259
+ chainContext: createChainContext(persisted.chain)
260
+ };
261
+ return;
262
+ }
263
+ this.state.session = {
264
+ ...persisted,
265
+ provider: staleProvider,
266
+ chainContext: createChainContext(persisted.chain)
267
+ };
268
+ }
269
+ };
270
+ var sessionStore = new SessionStore();
271
+
12
272
  // src/providers/social/cubistRuntime.ts
13
273
  var DEFAULT_EXPIRATION_BUFFER_SECS = 30;
14
274
  var DEFAULT_RETRY_ATTEMPTS = 3;
@@ -226,10 +486,7 @@ var MemorySessionManager = class {
226
486
  if (!isStale(__privateGet(this, _data))) {
227
487
  return __privateGet(this, _data).token;
228
488
  }
229
- __privateGet(this, _refreshing) ?? __privateSet(this, _refreshing, refreshSession(__privateGet(this, _data)).then(async (refreshed2) => {
230
- await this.store(refreshed2);
231
- return refreshed2;
232
- }).catch((error) => {
489
+ __privateGet(this, _refreshing) ?? __privateSet(this, _refreshing, this.refresh().catch((error) => {
233
490
  if (error instanceof Error && /\(401\)|\(403\)/.test(error.message) && typeof this.onInvalidToken === "function") {
234
491
  this.onInvalidToken();
235
492
  }
@@ -240,12 +497,27 @@ var MemorySessionManager = class {
240
497
  const refreshed = await __privateGet(this, _refreshing);
241
498
  return refreshed.token;
242
499
  }
500
+ async refresh() {
501
+ __privateGet(this, _refreshing) ?? __privateSet(this, _refreshing, refreshSession(__privateGet(this, _data)).then(async (refreshed) => {
502
+ await this.store(refreshed);
503
+ return refreshed;
504
+ }).catch((error) => {
505
+ if (error instanceof Error && /\(401\)|\(403\)/.test(error.message) && typeof this.onInvalidToken === "function") {
506
+ this.onInvalidToken();
507
+ }
508
+ throw error;
509
+ }).finally(() => {
510
+ __privateSet(this, _refreshing, void 0);
511
+ }));
512
+ return __privateGet(this, _refreshing);
513
+ }
243
514
  };
244
515
  _data = new WeakMap();
245
516
  _refreshing = new WeakMap();
246
- async function refreshSession(session1) {
247
- const secretB64Token = btoa(JSON.stringify(session1)).replace(/\s/g, "");
248
- const session = JSON.parse(atob(secretB64Token));
517
+ async function refreshSession(session) {
518
+ if (session === void 0 || session === null || !session.refresh_token) {
519
+ throw new Error("Session is undefined");
520
+ }
249
521
  const env = getPrimarySessionEnv(session);
250
522
  const payload = {
251
523
  epoch_num: session.session_info.epoch,
@@ -292,6 +564,12 @@ var _CubistApiClient = class _CubistApiClient {
292
564
  }
293
565
  return __privateGet(this, _sessionManager).retrieve();
294
566
  }
567
+ async refreshSessionData() {
568
+ if (typeof __privateGet(this, _sessionManager).refresh === "function") {
569
+ return __privateGet(this, _sessionManager).refresh();
570
+ }
571
+ return this.retrieveSessionData();
572
+ }
295
573
  withOrg(orgId) {
296
574
  return new _CubistApiClient(__privateGet(this, _sessionManager), __privateGet(this, _sessionMeta), orgId);
297
575
  }
@@ -551,6 +829,9 @@ var _CubeSignerClient = class _CubeSignerClient {
551
829
  async retrieveSessionData() {
552
830
  return __privateGet(this, _apiClient4).retrieveSessionData();
553
831
  }
832
+ async refreshSessionData() {
833
+ return __privateGet(this, _apiClient4).refreshSessionData();
834
+ }
554
835
  static async create(session, targetOrgId) {
555
836
  const created = typeof session === "string" || isSessionData(session) ? new MemorySessionManager(parseSessionLike(session)) : session;
556
837
  if (typeof session === "object" && session !== null && session.onInvalidToken && created instanceof MemorySessionManager) {
@@ -707,19 +988,97 @@ function resolveEnv(env) {
707
988
  function decodeJwtPayload(token) {
708
989
  return jwtDecode(token);
709
990
  }
710
- async function refreshCubeSignerSessionData(sessionData) {
711
- const client = await CubeSignerClient.create(sessionData);
712
- await client.sessionKeys();
713
- return await client.retrieveSessionData() ?? sessionData;
714
- }
991
+ var _refreshing2, _autoRefreshTimerId, _authLifetimeSecs;
992
+ var ManagedCubeSignerSession = class {
993
+ constructor(data, notifySessionDataUpdated, authLifetimeSecs) {
994
+ this.data = data;
995
+ this.notifySessionDataUpdated = notifySessionDataUpdated;
996
+ __privateAdd(this, _refreshing2);
997
+ __privateAdd(this, _autoRefreshTimerId, null);
998
+ __privateAdd(this, _authLifetimeSecs);
999
+ __privateSet(this, _authLifetimeSecs, authLifetimeSecs);
1000
+ }
1001
+ async metadata() {
1002
+ return {
1003
+ env: this.data.env,
1004
+ org_id: this.data.org_id,
1005
+ role_id: this.data.role_id,
1006
+ purpose: this.data.purpose,
1007
+ session_exp: this.data.session_exp,
1008
+ session_id: this.data.session_info.session_id,
1009
+ epoch: this.data.session_info.epoch
1010
+ };
1011
+ }
1012
+ async token() {
1013
+ if (!isStale(this.data)) {
1014
+ return this.data.token;
1015
+ }
1016
+ __privateGet(this, _refreshing2) ?? __privateSet(this, _refreshing2, this.refresh().catch((error) => {
1017
+ if (error instanceof Error && /\(401\)|\(403\)/.test(error.message) && typeof this.onInvalidToken === "function") {
1018
+ this.onInvalidToken();
1019
+ }
1020
+ throw error;
1021
+ }).finally(() => {
1022
+ __privateSet(this, _refreshing2, void 0);
1023
+ }));
1024
+ const refreshed = await __privateGet(this, _refreshing2);
1025
+ return refreshed.token;
1026
+ }
1027
+ async refresh() {
1028
+ __privateGet(this, _refreshing2) ?? __privateSet(this, _refreshing2, refreshSession(this.data).then(async (refreshed) => {
1029
+ await this.store(refreshed);
1030
+ return refreshed;
1031
+ }).catch((error) => {
1032
+ if (error instanceof Error && /\(401\)|\(403\)/.test(error.message) && typeof this.onInvalidToken === "function") {
1033
+ this.onInvalidToken();
1034
+ }
1035
+ throw error;
1036
+ }).finally(() => {
1037
+ __privateSet(this, _refreshing2, void 0);
1038
+ }));
1039
+ return __privateGet(this, _refreshing2);
1040
+ }
1041
+ async retrieve() {
1042
+ return this.data;
1043
+ }
1044
+ async store(data) {
1045
+ this.data = data;
1046
+ this.notifySessionDataUpdated(data);
1047
+ }
1048
+ /**
1049
+ * Start a periodic timer that proactively refreshes the auth token
1050
+ * when the remaining auth time drops below 1/3 of the total auth lifetime.
1051
+ */
1052
+ startAutoRefresh(intervalMs = 3e4) {
1053
+ this.stopAutoRefresh();
1054
+ if (typeof setInterval === "undefined") return;
1055
+ __privateSet(this, _autoRefreshTimerId, setInterval(() => {
1056
+ const remainingSecs = this.data.session_info.auth_token_exp - Date.now() / 1e3;
1057
+ if (remainingSecs < __privateGet(this, _authLifetimeSecs) / 3) {
1058
+ this.refresh().catch(() => {
1059
+ });
1060
+ }
1061
+ }, intervalMs));
1062
+ }
1063
+ stopAutoRefresh() {
1064
+ if (__privateGet(this, _autoRefreshTimerId) != null) {
1065
+ clearInterval(__privateGet(this, _autoRefreshTimerId));
1066
+ __privateSet(this, _autoRefreshTimerId, null);
1067
+ }
1068
+ }
1069
+ };
1070
+ _refreshing2 = new WeakMap();
1071
+ _autoRefreshTimerId = new WeakMap();
1072
+ _authLifetimeSecs = new WeakMap();
715
1073
  var CubeSignerAuth = class {
716
1074
  constructor(config) {
717
1075
  this._client = null;
718
1076
  this._sessionData = null;
1077
+ this._managedSession = null;
719
1078
  this.env = resolveEnv(config.env);
720
1079
  this.orgId = config.orgId;
721
1080
  this.scopes = config.scopes ?? ["sign:*", "manage:*"];
722
- this.lifetimes = config.lifetimes ?? { session: 60 * 60 * 24 * 30, auth: 60 * 60 * 24 * 30, refresh: 60 * 60 * 24 * 30 * 2 };
1081
+ this.lifetimes = config.lifetimes ?? { session: 60 * 60 * 24 * 30, auth: 60 * 60 * 24 * 30 };
723
1082
  this.defaultSessionPolicy = config.defaultSessionPolicy;
724
1083
  this.oidcLoginHooks = config.oidcLoginHooks;
725
1084
  }
@@ -763,6 +1122,8 @@ var CubeSignerAuth = class {
763
1122
  }
764
1123
  /* ── Sign-out ─────────────────────────────── */
765
1124
  async signOut() {
1125
+ this._managedSession?.stopAutoRefresh();
1126
+ this._managedSession = null;
766
1127
  if (this._client) {
767
1128
  try {
768
1129
  await this._client.revokeSession();
@@ -781,10 +1142,10 @@ var CubeSignerAuth = class {
781
1142
  if (this._client) {
782
1143
  await this.signOut();
783
1144
  }
784
- const client = await CubeSignerClient.create(sessionData);
1145
+ const managedSession = this.createManagedSession(sessionData);
1146
+ const client = await CubeSignerClient.create(managedSession);
785
1147
  this._client = client;
786
- this._sessionData = sessionData;
787
- return { client, sessionData };
1148
+ return { client, sessionData: this._sessionData ?? sessionData };
788
1149
  }
789
1150
  /* ── Private ──────────────────────────────── */
790
1151
  async authenticateWithOidcToken(oidcToken) {
@@ -845,11 +1206,31 @@ var CubeSignerAuth = class {
845
1206
  this.lifetimes
846
1207
  );
847
1208
  const sessionData = resp.data();
848
- const client = await CubeSignerClient.create(sessionData);
1209
+ const managedSession = this.createManagedSession(sessionData);
1210
+ const client = await CubeSignerClient.create(managedSession);
849
1211
  this._client = client;
850
- this._sessionData = sessionData;
1212
+ const currentSessionData = this._sessionData ?? sessionData;
851
1213
  const userInfo = this.parseOidcUserInfo(oidcToken);
852
- return { client, sessionData, userInfo };
1214
+ return { client, sessionData: currentSessionData, userInfo };
1215
+ }
1216
+ createManagedSession(sessionData) {
1217
+ this._managedSession?.stopAutoRefresh();
1218
+ this._sessionData = sessionData;
1219
+ const manager = new ManagedCubeSignerSession(
1220
+ sessionData,
1221
+ (nextSessionData) => {
1222
+ this._sessionData = nextSessionData;
1223
+ this.onSessionDataUpdated?.(nextSessionData);
1224
+ },
1225
+ this.lifetimes.auth ?? 60 * 60 * 24 * 30
1226
+ );
1227
+ manager.onInvalidToken = () => {
1228
+ manager.stopAutoRefresh();
1229
+ sessionStore.expireSession();
1230
+ };
1231
+ manager.startAutoRefresh();
1232
+ this._managedSession = manager;
1233
+ return manager;
853
1234
  }
854
1235
  parseOidcUserInfo(oidcToken) {
855
1236
  try {
@@ -1101,4 +1482,4 @@ var createCubistEvmWalletProvider = ({
1101
1482
  };
1102
1483
  };
1103
1484
 
1104
- export { CubeSignerAuth, createCubistEvmWalletProvider, refreshCubeSignerSessionData };
1485
+ export { CubeSignerAuth, STALE_SESSION_ERROR_MESSAGE, SessionStore, USER_SESSION_EXPIRED_MESSAGE, createChainContext, createCubistEvmWalletProvider, getAllChainDescriptors, getChainDescriptor, getSupportedChainFromEvmChainId, isStaleSessionError, sessionStore };
@@ -115,6 +115,7 @@ interface WalletSession {
115
115
  walletType?: WalletType;
116
116
  authSource?: WalletAuthSource;
117
117
  sessionId?: string;
118
+ issuedAt?: number;
118
119
  expiresAt?: number;
119
120
  capabilities?: WalletCapability[];
120
121
  sessionData?: unknown;
@@ -181,6 +182,7 @@ interface SessionManager {
181
182
  onInvalidToken?: () => void;
182
183
  metadata(): Promise<SessionMetadata>;
183
184
  token(): Promise<string>;
185
+ refresh?(): Promise<SessionData>;
184
186
  retrieve?(): Promise<SessionData>;
185
187
  store?(data: SessionData): Promise<void>;
186
188
  }
@@ -275,6 +277,7 @@ declare class CubistApiClient {
275
277
  get orgId(): string;
276
278
  get sessionMeta(): SessionMetadata;
277
279
  retrieveSessionData(): Promise<SessionData | null>;
280
+ refreshSessionData(): Promise<SessionData | null>;
278
281
  withOrg(orgId: string): CubistApiClient;
279
282
  sessionKeysList(): Promise<KeyInfo[]>;
280
283
  keyGetByMaterialId(keyType: string, materialId: string): Promise<KeyInfo>;
@@ -329,6 +332,7 @@ declare class CubeSignerClient {
329
332
  get env(): EnvInterface;
330
333
  get orgId(): string;
331
334
  retrieveSessionData(): Promise<SessionData | null>;
335
+ refreshSessionData(): Promise<SessionData | null>;
332
336
  static create(session: string | SessionData | SessionManager, targetOrgId?: string): Promise<CubeSignerClient>;
333
337
  static createOidcSession(env: EnvInterface, orgId: string, token: string, scopes: Array<Scope>, lifetimes?: RatchetConfig, mfaReceipt?: MfaReceipts, purpose?: string): Promise<CubeSignerResponse<SessionData>>;
334
338
  static proveOidcIdentity(env: EnvInterface, orgId: string, token: string): Promise<IdentityProof>;
@@ -359,7 +363,7 @@ interface CubeSignerConfig {
359
363
  orgId: string;
360
364
  /** Session scopes (default: `["sign:*", "manage:*"]`). */
361
365
  scopes?: string[];
362
- /** Session lifetimes (default: `{ session: 60 * 60 * 24 * 30, auth: 60 * 60 * 24 * 30, refresh: 60 * 60 * 24 * 30*2 }`). */
366
+ /** Session lifetimes (default: `{ session: 60 * 60 * 24 * 30, auth: 60 * 60 * 24 * 30 }`). */
363
367
  lifetimes?: RatchetConfig;
364
368
  /** Optional capability policy applied to smart-wallet sessions created from this auth flow. */
365
369
  defaultSessionPolicy?: Partial<SessionCapabilityPolicy>;
@@ -386,7 +390,6 @@ interface TwitterCodeExchangeParams {
386
390
  /** redirect_uri that was used in the authorization request. */
387
391
  redirectUri: string;
388
392
  }
389
- declare function refreshCubeSignerSessionData(sessionData: SessionData): Promise<SessionData>;
390
393
  declare class CubeSignerAuth {
391
394
  private readonly env;
392
395
  private readonly orgId;
@@ -394,8 +397,10 @@ declare class CubeSignerAuth {
394
397
  private readonly lifetimes;
395
398
  readonly defaultSessionPolicy?: Partial<SessionCapabilityPolicy>;
396
399
  private readonly oidcLoginHooks?;
400
+ onSessionDataUpdated?: (sessionData: SessionData) => void;
397
401
  private _client;
398
402
  private _sessionData;
403
+ private _managedSession;
399
404
  constructor(config: CubeSignerConfig);
400
405
  /** Currently authenticated client (null if not logged in). */
401
406
  get client(): CubeSignerClient | null;
@@ -436,7 +441,8 @@ declare class CubeSignerAuth {
436
441
  * Create a CubeSigner OIDC session from a generic OIDC id_token.
437
442
  */
438
443
  private createOidcSession;
444
+ private createManagedSession;
439
445
  private parseOidcUserInfo;
440
446
  }
441
447
 
442
- export { getChainDescriptor as A, type BalanceInfo as B, CubeSignerAuth as C, getSupportedChainFromEvmChainId as D, type EvmTransactionRequest as E, isCapabilityPolicyExpired as F, isSessionExpired as G, sessionSupportsCapability as H, type OidcLoginHooks as O, type ProviderCategory as P, type SessionCapabilityCheck as S, type TwitterCodeExchangeParams as T, type UserInfo as U, type WalletState as W, type CubeSignerConfig as a, type CubeSignerSession as b, type WalletSession as c, type WalletAdapter as d, type WalletConnectArgs as e, type WalletCapability as f, type WalletProviderRequest as g, type SupportedChain as h, type WalletProvider as i, type ChainContext as j, type SessionCapabilityPolicy as k, type ChainDescriptor as l, type ChainNamespace as m, type ChainRpcFamily as n, type EvmAccessListItem as o, type EvmQuantity as p, SessionCapabilityError as q, refreshCubeSignerSessionData as r, type SupportedToken as s, type WalletAuthSource as t, type WalletType as u, assertSessionCapability as v, createChainContext as w, createSessionCapabilityPolicy as x, describeSessionCapabilityPolicy as y, getAllChainDescriptors as z };
448
+ export { getSupportedChainFromEvmChainId as A, type BalanceInfo as B, CubeSignerAuth as C, isCapabilityPolicyExpired as D, type EvmTransactionRequest as E, isSessionExpired as F, sessionSupportsCapability as G, type SessionData as H, type OidcLoginHooks as O, type ProviderCategory as P, type SessionCapabilityCheck as S, type TwitterCodeExchangeParams as T, type UserInfo as U, type WalletState as W, type CubeSignerConfig as a, type CubeSignerSession as b, type WalletSession as c, type WalletAdapter as d, type WalletConnectArgs as e, type WalletCapability as f, type WalletProviderRequest as g, type SupportedChain as h, type WalletProvider as i, type ChainContext as j, type SessionCapabilityPolicy as k, type ChainDescriptor as l, type ChainNamespace as m, type ChainRpcFamily as n, type EvmAccessListItem as o, type EvmQuantity as p, SessionCapabilityError as q, type SupportedToken as r, type WalletAuthSource as s, type WalletType as t, assertSessionCapability as u, createChainContext as v, createSessionCapabilityPolicy as w, describeSessionCapabilityPolicy as x, getAllChainDescriptors as y, getChainDescriptor as z };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { W as WalletState, c as WalletSession, B as BalanceInfo, d as WalletAdapter, e as WalletConnectArgs, f as WalletCapability, g as WalletProviderRequest, E as EvmTransactionRequest, S as SessionCapabilityCheck, h as SupportedChain, i as WalletProvider, j as ChainContext, k as SessionCapabilityPolicy } from './cubeSignerAuth-C3n7VgB8.js';
2
- export { l as ChainDescriptor, m as ChainNamespace, n as ChainRpcFamily, C as CubeSignerAuth, a as CubeSignerConfig, b as CubeSignerSession, o as EvmAccessListItem, p as EvmQuantity, O as OidcLoginHooks, P as ProviderCategory, q as SessionCapabilityError, s as SupportedToken, T as TwitterCodeExchangeParams, U as UserInfo, t as WalletAuthSource, u as WalletType, v as assertSessionCapability, w as createChainContext, x as createSessionCapabilityPolicy, y as describeSessionCapabilityPolicy, z as getAllChainDescriptors, A as getChainDescriptor, D as getSupportedChainFromEvmChainId, F as isCapabilityPolicyExpired, G as isSessionExpired, r as refreshCubeSignerSessionData, H as sessionSupportsCapability } from './cubeSignerAuth-C3n7VgB8.js';
1
+ import { W as WalletState, c as WalletSession, B as BalanceInfo, d as WalletAdapter, e as WalletConnectArgs, f as WalletCapability, g as WalletProviderRequest, E as EvmTransactionRequest, S as SessionCapabilityCheck, h as SupportedChain, i as WalletProvider, j as ChainContext, k as SessionCapabilityPolicy } from './cubeSignerAuth-Cwnx1DZ1.js';
2
+ export { l as ChainDescriptor, m as ChainNamespace, n as ChainRpcFamily, C as CubeSignerAuth, a as CubeSignerConfig, b as CubeSignerSession, o as EvmAccessListItem, p as EvmQuantity, O as OidcLoginHooks, P as ProviderCategory, q as SessionCapabilityError, r as SupportedToken, T as TwitterCodeExchangeParams, U as UserInfo, s as WalletAuthSource, t as WalletType, u as assertSessionCapability, v as createChainContext, w as createSessionCapabilityPolicy, x as describeSessionCapabilityPolicy, y as getAllChainDescriptors, z as getChainDescriptor, A as getSupportedChainFromEvmChainId, D as isCapabilityPolicyExpired, F as isSessionExpired, G as sessionSupportsCapability } from './cubeSignerAuth-Cwnx1DZ1.js';
3
3
  import EventEmitter from 'eventemitter3';
4
- import { e as AbstractProvider } from './social-provider-B1XSe1Sr.js';
5
- export { A as AbstractSocialProvider, C as CUBIST_CAPABILITIES, a as CubistLoginMethod, b as CubistSessionAdapter, c as CubistSocialProvider, S as SocialConnectArgs, d as SocialLoginOptions } from './social-provider-B1XSe1Sr.js';
4
+ import { e as AbstractProvider } from './social-provider-DIuMlnXm.js';
5
+ export { A as AbstractSocialProvider, C as CUBIST_CAPABILITIES, a as CubistLoginMethod, b as CubistSessionAdapter, c as CubistSocialProvider, S as SocialConnectArgs, d as SocialLoginOptions } from './social-provider-DIuMlnXm.js';
6
6
 
7
7
  declare const EVM_TRANSACTION_SIGNING_UNSUPPORTED = "EVM_TRANSACTION_SIGNING_UNSUPPORTED";
8
8
  declare class EvmTransactionSigningUnsupportedError extends Error {
@@ -28,6 +28,8 @@ type WalletEvents = {
28
28
  declare class SessionStore {
29
29
  private state;
30
30
  private emitter;
31
+ private _pendingExpiredSession;
32
+ private _expiryTimerId;
31
33
  constructor();
32
34
  getState(): WalletState;
33
35
  setConnecting(flag: boolean): void;
@@ -38,6 +40,17 @@ declare class SessionStore {
38
40
  revokeSession(): void;
39
41
  setBalance(balance: BalanceInfo | null): void;
40
42
  on<T extends keyof WalletEvents>(event: T, listener: (...args: WalletEvents[T]) => void): () => EventEmitter<WalletEvents, any>;
43
+ /**
44
+ * Emit `session:expired` for a session that was already expired at rehydration time.
45
+ * Call this after attaching listeners so the event is actually received.
46
+ */
47
+ flushPendingExpiry(): void;
48
+ /**
49
+ * Start a periodic timer that checks whether the current session has expired.
50
+ * When `session.expiresAt <= Date.now()`, calls `expireSession()` which emits `session:expired`.
51
+ */
52
+ startExpiryTimer(intervalMs?: number): void;
53
+ stopExpiryTimer(): void;
41
54
  private tryRehydrate;
42
55
  }
43
56
  declare const sessionStore: SessionStore;
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { createChainContext, AbstractProvider, getSupportedChainFromEvmChainId, assertSessionCapability } from './chunk-SBOQGPRF.js';
2
- export { AbstractProvider, AbstractSocialProvider, CUBIST_CAPABILITIES, CubistSocialProvider, SessionCapabilityError, assertSessionCapability, createChainContext, createSessionCapabilityPolicy, describeSessionCapabilityPolicy, getAllChainDescriptors, getChainDescriptor, getSupportedChainFromEvmChainId, isCapabilityPolicyExpired, isSessionExpired, sessionSupportsCapability } from './chunk-SBOQGPRF.js';
3
- export { CubeSignerAuth, refreshCubeSignerSessionData } from './chunk-ADMEF7PF.js';
4
- import EventEmitter from 'eventemitter3';
1
+ import { AbstractProvider, assertSessionCapability } from './chunk-K63POESF.js';
2
+ export { AbstractProvider, AbstractSocialProvider, CUBIST_CAPABILITIES, CubistSocialProvider, SessionCapabilityError, assertSessionCapability, createSessionCapabilityPolicy, describeSessionCapabilityPolicy, isCapabilityPolicyExpired, isSessionExpired, sessionSupportsCapability } from './chunk-K63POESF.js';
3
+ import { sessionStore, getSupportedChainFromEvmChainId, createChainContext, isStaleSessionError, USER_SESSION_EXPIRED_MESSAGE } from './chunk-V4LAUAGS.js';
4
+ export { CubeSignerAuth, STALE_SESSION_ERROR_MESSAGE, SessionStore, USER_SESSION_EXPIRED_MESSAGE, createChainContext, getAllChainDescriptors, getChainDescriptor, getSupportedChainFromEvmChainId, isStaleSessionError, sessionStore } from './chunk-V4LAUAGS.js';
5
5
 
6
6
  // src/core/errors.ts
7
7
  var EVM_TRANSACTION_SIGNING_UNSUPPORTED = "EVM_TRANSACTION_SIGNING_UNSUPPORTED";
@@ -47,142 +47,6 @@ var normalizeEvmTransactionSigningError = (providerName, error) => {
47
47
  }
48
48
  return error instanceof Error ? error : new Error(String(error));
49
49
  };
50
- var STORAGE_KEY = "ab:wallet:session";
51
- function getStorage() {
52
- try {
53
- return typeof localStorage !== "undefined" ? localStorage : null;
54
- } catch {
55
- return null;
56
- }
57
- }
58
- function persistSession(session) {
59
- const storage = getStorage();
60
- if (!storage) return;
61
- if (!session) {
62
- storage.removeItem(STORAGE_KEY);
63
- return;
64
- }
65
- const serializable = {
66
- address: session.address,
67
- chain: session.chain,
68
- walletType: session.walletType,
69
- authSource: session.authSource,
70
- sessionId: session.sessionId,
71
- expiresAt: session.expiresAt
72
- };
73
- if (session.capabilities?.length) {
74
- serializable.capabilities = session.capabilities;
75
- }
76
- if (session.sessionData !== void 0) {
77
- serializable.sessionData = session.sessionData;
78
- }
79
- if (session.capabilityPolicy !== void 0) {
80
- serializable.capabilityPolicy = session.capabilityPolicy;
81
- }
82
- if (session.userInfo !== void 0) {
83
- serializable.userInfo = session.userInfo;
84
- }
85
- try {
86
- storage.setItem(STORAGE_KEY, JSON.stringify(serializable));
87
- } catch {
88
- storage.removeItem(STORAGE_KEY);
89
- }
90
- }
91
- function readPersistedSession() {
92
- const storage = getStorage();
93
- if (!storage) return null;
94
- const raw = storage.getItem(STORAGE_KEY);
95
- if (!raw) return null;
96
- try {
97
- return JSON.parse(raw);
98
- } catch {
99
- storage.removeItem(STORAGE_KEY);
100
- return null;
101
- }
102
- }
103
- var STALE_SESSION_ERROR_MESSAGE = "Session restored from cache. Reconnect your wallet for transactions.";
104
- var USER_SESSION_EXPIRED_MESSAGE = "Session expired. Please reconnect your wallet and try again.";
105
- function isStaleSessionError(error) {
106
- return error instanceof Error && error.message.includes(STALE_SESSION_ERROR_MESSAGE);
107
- }
108
- var staleProvider = {
109
- request() {
110
- return Promise.reject(new Error(STALE_SESSION_ERROR_MESSAGE));
111
- },
112
- disconnect() {
113
- return Promise.resolve();
114
- }
115
- };
116
- var SessionStore = class {
117
- constructor() {
118
- this.state = {
119
- session: null,
120
- balance: null,
121
- isConnecting: false
122
- };
123
- this.emitter = new EventEmitter();
124
- this.tryRehydrate();
125
- }
126
- getState() {
127
- return { ...this.state };
128
- }
129
- setConnecting(flag) {
130
- this.state.isConnecting = flag;
131
- this.emitter.emit("connecting:changed", flag);
132
- }
133
- setSession(session) {
134
- this.state.session = session;
135
- persistSession(session);
136
- this.emitter.emit("session:changed", session);
137
- }
138
- rehydrateSession(session) {
139
- this.state.session = session;
140
- persistSession(session);
141
- this.emitter.emit("session:changed", session);
142
- this.emitter.emit("session:rehydrated", session);
143
- }
144
- clearSession() {
145
- this.state.session = null;
146
- this.state.balance = null;
147
- persistSession(null);
148
- this.emitter.emit("session:changed", null);
149
- this.emitter.emit("balance:changed", null);
150
- }
151
- expireSession() {
152
- const currentSession = this.state.session;
153
- if (!currentSession) return;
154
- this.clearSession();
155
- this.emitter.emit("session:expired", currentSession);
156
- }
157
- revokeSession() {
158
- const currentSession = this.state.session;
159
- if (!currentSession) return;
160
- this.clearSession();
161
- this.emitter.emit("session:revoked", currentSession);
162
- }
163
- setBalance(balance) {
164
- this.state.balance = balance;
165
- this.emitter.emit("balance:changed", balance);
166
- }
167
- on(event, listener) {
168
- this.emitter.on(event, listener);
169
- return () => this.emitter.off(event, listener);
170
- }
171
- tryRehydrate() {
172
- const persisted = readPersistedSession();
173
- if (!persisted) return;
174
- if (persisted.expiresAt && persisted.expiresAt <= Date.now()) {
175
- persistSession(null);
176
- return;
177
- }
178
- this.state.session = {
179
- ...persisted,
180
- provider: staleProvider,
181
- chainContext: createChainContext(persisted.chain)
182
- };
183
- }
184
- };
185
- var sessionStore = new SessionStore();
186
50
 
187
51
  // src/core/walletExecution.ts
188
52
  var requireSession = (session) => {
@@ -288,8 +152,24 @@ var createWalletExecutionController = () => ({
288
152
  });
289
153
 
290
154
  // src/core/walletConnector.ts
155
+ function attachSessionDataSync(adapter) {
156
+ const socialAdapter = adapter;
157
+ if (!("onSessionDataUpdated" in socialAdapter)) {
158
+ return;
159
+ }
160
+ const previousHandler = socialAdapter.onSessionDataUpdated;
161
+ socialAdapter.onSessionDataUpdated = (sessionData) => {
162
+ previousHandler?.(sessionData);
163
+ const current = sessionStore.getState().session;
164
+ if (!current) return;
165
+ sessionStore.setSession({
166
+ ...current,
167
+ sessionData
168
+ });
169
+ };
170
+ }
291
171
  var ADAPTER_STORAGE_KEY = "ab:wallet:adapterId";
292
- function getStorage2() {
172
+ function getStorage() {
293
173
  try {
294
174
  return typeof localStorage !== "undefined" ? localStorage : null;
295
175
  } catch {
@@ -297,7 +177,7 @@ function getStorage2() {
297
177
  }
298
178
  }
299
179
  function persistAdapterId(adapterId) {
300
- const storage = getStorage2();
180
+ const storage = getStorage();
301
181
  if (!storage) return;
302
182
  if (!adapterId) {
303
183
  storage.removeItem(ADAPTER_STORAGE_KEY);
@@ -306,7 +186,7 @@ function persistAdapterId(adapterId) {
306
186
  }
307
187
  }
308
188
  function readPersistedAdapterId() {
309
- const storage = getStorage2();
189
+ const storage = getStorage();
310
190
  if (!storage) return null;
311
191
  return storage.getItem(ADAPTER_STORAGE_KEY);
312
192
  }
@@ -349,6 +229,7 @@ var WalletConnector = class {
349
229
  this.currentAdapterId = adapter.id;
350
230
  persistAdapterId(adapter.id);
351
231
  sessionStore.setSession(session);
232
+ attachSessionDataSync(adapter);
352
233
  sessionStore.setBalance(null);
353
234
  return session;
354
235
  } finally {
@@ -390,6 +271,7 @@ var WalletConnector = class {
390
271
  this.currentAdapterId = adapterId;
391
272
  persistAdapterId(adapterId);
392
273
  sessionStore.rehydrateSession(session);
274
+ attachSessionDataSync(adapter);
393
275
  return session;
394
276
  } catch {
395
277
  return null;
@@ -1146,4 +1028,4 @@ function createDefaultInjectedWalletRegistry() {
1146
1028
  }));
1147
1029
  }
1148
1030
 
1149
- export { BitgetProvider, BraveWalletProvider, CoinbaseWalletProvider, EVM_TRANSACTION_SIGNING_UNSUPPORTED, EvmTransactionSigningUnsupportedError, InjectedEvmProvider, MetaMaskProvider, OKXProvider, PhantomProvider, RabbyProvider, RainbowProvider, STALE_SESSION_ERROR_MESSAGE, SessionStore, TrustWalletProvider, USER_SESSION_EXPIRED_MESSAGE, WalletConnector, ZerionProvider, createAccountController, createDefaultInjectedWalletRegistry, createWalletConnectController, createWalletExecutionClient, createWalletExecutionController, discoverEIP6963Providers, findEIP6963Provider, findInjectedProvider, getWalletExecutionCapabilities, isStaleSessionError, isUnsupportedEvmTransactionSigningError, normalizeEvmTransactionSigningError, sessionStore, switchToFallbackFundingChain };
1031
+ export { BitgetProvider, BraveWalletProvider, CoinbaseWalletProvider, EVM_TRANSACTION_SIGNING_UNSUPPORTED, EvmTransactionSigningUnsupportedError, InjectedEvmProvider, MetaMaskProvider, OKXProvider, PhantomProvider, RabbyProvider, RainbowProvider, TrustWalletProvider, WalletConnector, ZerionProvider, createAccountController, createDefaultInjectedWalletRegistry, createWalletConnectController, createWalletExecutionClient, createWalletExecutionController, discoverEIP6963Providers, findEIP6963Provider, findInjectedProvider, getWalletExecutionCapabilities, isUnsupportedEvmTransactionSigningError, normalizeEvmTransactionSigningError, switchToFallbackFundingChain };
@@ -1,5 +1,5 @@
1
- import { b as CubeSignerSession, h as SupportedChain, i as WalletProvider } from './cubeSignerAuth-C3n7VgB8.js';
2
- export { C as CubeSignerAuth, a as CubeSignerConfig, O as OidcLoginHooks, T as TwitterCodeExchangeParams, r as refreshCubeSignerSessionData } from './cubeSignerAuth-C3n7VgB8.js';
1
+ import { b as CubeSignerSession, h as SupportedChain, i as WalletProvider } from './cubeSignerAuth-Cwnx1DZ1.js';
2
+ export { C as CubeSignerAuth, a as CubeSignerConfig, O as OidcLoginHooks, T as TwitterCodeExchangeParams } from './cubeSignerAuth-Cwnx1DZ1.js';
3
3
 
4
4
  interface CreateCubistEvmWalletProviderArgs {
5
5
  session: CubeSignerSession;
@@ -1 +1 @@
1
- export { CubeSignerAuth, createCubistEvmWalletProvider, refreshCubeSignerSessionData } from './chunk-ADMEF7PF.js';
1
+ export { CubeSignerAuth, createCubistEvmWalletProvider } from './chunk-V4LAUAGS.js';
@@ -1,4 +1,4 @@
1
- import { d as WalletAdapter, P as ProviderCategory, c as WalletSession, e as WalletConnectArgs, i as WalletProvider, f as WalletCapability, T as TwitterCodeExchangeParams, b as CubeSignerSession, a as CubeSignerConfig, C as CubeSignerAuth } from './cubeSignerAuth-C3n7VgB8.js';
1
+ import { d as WalletAdapter, P as ProviderCategory, c as WalletSession, e as WalletConnectArgs, i as WalletProvider, f as WalletCapability, T as TwitterCodeExchangeParams, b as CubeSignerSession, H as SessionData, a as CubeSignerConfig, C as CubeSignerAuth } from './cubeSignerAuth-Cwnx1DZ1.js';
2
2
 
3
3
  declare abstract class AbstractProvider implements WalletAdapter {
4
4
  abstract readonly id: string;
@@ -53,6 +53,7 @@ declare const CUBIST_CAPABILITIES: WalletCapability[];
53
53
  declare class CubistSocialProvider extends AbstractSocialProvider {
54
54
  readonly id = "cubist";
55
55
  readonly title = "Cubist Social Wallet";
56
+ onSessionDataUpdated?: (sessionData: SessionData) => void;
56
57
  private auth;
57
58
  private adapter;
58
59
  private lastCubeSignerSession;
@@ -1,2 +1,2 @@
1
- export { A as AbstractSocialProvider, C as CUBIST_CAPABILITIES, a as CubistLoginMethod, b as CubistSessionAdapter, c as CubistSocialProvider, S as SocialConnectArgs, d as SocialLoginOptions } from './social-provider-B1XSe1Sr.js';
2
- import './cubeSignerAuth-C3n7VgB8.js';
1
+ export { A as AbstractSocialProvider, C as CUBIST_CAPABILITIES, a as CubistLoginMethod, b as CubistSessionAdapter, c as CubistSocialProvider, S as SocialConnectArgs, d as SocialLoginOptions } from './social-provider-DIuMlnXm.js';
2
+ import './cubeSignerAuth-Cwnx1DZ1.js';
@@ -1,2 +1,2 @@
1
- export { AbstractSocialProvider, CUBIST_CAPABILITIES, CubistSocialProvider } from './chunk-SBOQGPRF.js';
2
- import './chunk-ADMEF7PF.js';
1
+ export { AbstractSocialProvider, CUBIST_CAPABILITIES, CubistSocialProvider } from './chunk-K63POESF.js';
2
+ import './chunk-V4LAUAGS.js';
package/dist/social.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { C as CubeSignerAuth, a as CubeSignerConfig, b as CubeSignerSession, O as OidcLoginHooks, T as TwitterCodeExchangeParams, r as refreshCubeSignerSessionData } from './cubeSignerAuth-C3n7VgB8.js';
1
+ export { C as CubeSignerAuth, a as CubeSignerConfig, b as CubeSignerSession, O as OidcLoginHooks, T as TwitterCodeExchangeParams } from './cubeSignerAuth-Cwnx1DZ1.js';
2
2
  export { createCubistEvmWalletProvider } from './social-auth.js';
3
- export { A as AbstractSocialProvider, C as CUBIST_CAPABILITIES, a as CubistLoginMethod, b as CubistSessionAdapter, c as CubistSocialProvider, S as SocialConnectArgs, d as SocialLoginOptions } from './social-provider-B1XSe1Sr.js';
3
+ export { A as AbstractSocialProvider, C as CUBIST_CAPABILITIES, a as CubistLoginMethod, b as CubistSessionAdapter, c as CubistSocialProvider, S as SocialConnectArgs, d as SocialLoginOptions } from './social-provider-DIuMlnXm.js';
package/dist/social.js CHANGED
@@ -1,2 +1,2 @@
1
- export { AbstractSocialProvider, CUBIST_CAPABILITIES, CubistSocialProvider } from './chunk-SBOQGPRF.js';
2
- export { CubeSignerAuth, createCubistEvmWalletProvider, refreshCubeSignerSessionData } from './chunk-ADMEF7PF.js';
1
+ export { AbstractSocialProvider, CUBIST_CAPABILITIES, CubistSocialProvider } from './chunk-K63POESF.js';
2
+ export { CubeSignerAuth, createCubistEvmWalletProvider } from './chunk-V4LAUAGS.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ab-org/sdk-core",
3
- "version": "0.3.0-beta.4",
3
+ "version": "0.3.0-beta.6",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist/**/*",
@@ -37,7 +37,7 @@
37
37
  "devDependencies": {
38
38
  "typescript": "^5.5.4",
39
39
  "tsup": "^8.5.1",
40
- "@ab-org/wallet-utils": "0.0.7"
40
+ "@ab-org/wallet-utils": "0.1.0-beta.1"
41
41
  },
42
42
  "scripts": {
43
43
  "build": "pnpm exec tsup",