@ab-org/sdk-core 0.3.0-beta.3 → 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.
- package/dist/{chunk-AOCUWKMU.js → chunk-K63POESF.js} +23 -91
- package/dist/{chunk-VOUTMV6J.js → chunk-V4LAUAGS.js} +420 -20
- package/dist/{cubeSignerAuth-2hpyKGgW.d.ts → cubeSignerAuth-Cwnx1DZ1.d.ts} +19 -3
- package/dist/index.d.ts +17 -4
- package/dist/index.js +26 -141
- package/dist/social-auth.d.ts +2 -2
- package/dist/social-auth.js +1 -1
- package/dist/{social-provider-QTza4QD-.d.ts → social-provider-DIuMlnXm.d.ts} +2 -1
- package/dist/social-provider.d.ts +2 -2
- package/dist/social-provider.js +2 -2
- package/dist/social.d.ts +2 -2
- package/dist/social.js +2 -2
- package/package.json +4 -3
|
@@ -1,89 +1,4 @@
|
|
|
1
|
-
import { CubeSignerAuth, createCubistEvmWalletProvider } from './chunk-
|
|
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,16 +182,20 @@ 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
|
-
|
|
192
|
+
issuedAt: Date.now(),
|
|
193
|
+
expiresAt,
|
|
267
194
|
capabilities: CUBIST_CAPABILITIES,
|
|
268
195
|
sessionData: session.sessionData,
|
|
269
196
|
chainContext: walletSession.chainContext ?? createChainContext(walletSession.chain),
|
|
270
|
-
capabilityPolicy
|
|
197
|
+
capabilityPolicy,
|
|
198
|
+
userInfo: session.userInfo
|
|
271
199
|
};
|
|
272
200
|
}
|
|
273
201
|
async authenticate(method) {
|
|
@@ -333,6 +261,8 @@ var CubistSocialProvider = class extends AbstractSocialProvider {
|
|
|
333
261
|
address: walletSession.address,
|
|
334
262
|
chain: restoredChain
|
|
335
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;
|
|
336
266
|
return this.setSession({
|
|
337
267
|
...walletSession,
|
|
338
268
|
chain: restoredChain,
|
|
@@ -340,11 +270,13 @@ var CubistSocialProvider = class extends AbstractSocialProvider {
|
|
|
340
270
|
walletType: persistedSession.walletType ?? "social",
|
|
341
271
|
authSource: persistedSession.authSource,
|
|
342
272
|
sessionId: persistedSession.sessionId,
|
|
343
|
-
|
|
273
|
+
issuedAt: persistedSession.issuedAt,
|
|
274
|
+
expiresAt,
|
|
344
275
|
capabilities: CUBIST_CAPABILITIES,
|
|
345
276
|
sessionData: csSession.sessionData,
|
|
346
277
|
chainContext: createChainContext(restoredChain),
|
|
347
|
-
capabilityPolicy: persistedSession.capabilityPolicy
|
|
278
|
+
capabilityPolicy: persistedSession.capabilityPolicy,
|
|
279
|
+
userInfo: persistedSession.userInfo ?? csSession.userInfo
|
|
348
280
|
});
|
|
349
281
|
} catch {
|
|
350
282
|
return null;
|
|
@@ -368,4 +300,4 @@ var CubistSocialProvider = class extends AbstractSocialProvider {
|
|
|
368
300
|
}
|
|
369
301
|
};
|
|
370
302
|
|
|
371
|
-
export { AbstractProvider, AbstractSocialProvider, CUBIST_CAPABILITIES, CubistSocialProvider, SessionCapabilityError, assertSessionCapability,
|
|
303
|
+
export { AbstractProvider, AbstractSocialProvider, CUBIST_CAPABILITIES, CubistSocialProvider, SessionCapabilityError, assertSessionCapability, createSessionCapabilityPolicy, describeSessionCapabilityPolicy, isCapabilityPolicyExpired, isSessionExpired, sessionSupportsCapability };
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import EventEmitter from 'eventemitter3';
|
|
2
|
+
import { jwtDecode } from 'jwt-decode';
|
|
3
|
+
|
|
1
4
|
var __typeError = (msg) => {
|
|
2
5
|
throw TypeError(msg);
|
|
3
6
|
};
|
|
@@ -7,6 +10,265 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
|
|
|
7
10
|
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
|
|
8
11
|
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
9
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
|
+
|
|
10
272
|
// src/providers/social/cubistRuntime.ts
|
|
11
273
|
var DEFAULT_EXPIRATION_BUFFER_SECS = 30;
|
|
12
274
|
var DEFAULT_RETRY_ATTEMPTS = 3;
|
|
@@ -224,10 +486,7 @@ var MemorySessionManager = class {
|
|
|
224
486
|
if (!isStale(__privateGet(this, _data))) {
|
|
225
487
|
return __privateGet(this, _data).token;
|
|
226
488
|
}
|
|
227
|
-
__privateGet(this, _refreshing) ?? __privateSet(this, _refreshing,
|
|
228
|
-
await this.store(refreshed2);
|
|
229
|
-
return refreshed2;
|
|
230
|
-
}).catch((error) => {
|
|
489
|
+
__privateGet(this, _refreshing) ?? __privateSet(this, _refreshing, this.refresh().catch((error) => {
|
|
231
490
|
if (error instanceof Error && /\(401\)|\(403\)/.test(error.message) && typeof this.onInvalidToken === "function") {
|
|
232
491
|
this.onInvalidToken();
|
|
233
492
|
}
|
|
@@ -238,12 +497,27 @@ var MemorySessionManager = class {
|
|
|
238
497
|
const refreshed = await __privateGet(this, _refreshing);
|
|
239
498
|
return refreshed.token;
|
|
240
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
|
+
}
|
|
241
514
|
};
|
|
242
515
|
_data = new WeakMap();
|
|
243
516
|
_refreshing = new WeakMap();
|
|
244
|
-
async function refreshSession(
|
|
245
|
-
|
|
246
|
-
|
|
517
|
+
async function refreshSession(session) {
|
|
518
|
+
if (session === void 0 || session === null || !session.refresh_token) {
|
|
519
|
+
throw new Error("Session is undefined");
|
|
520
|
+
}
|
|
247
521
|
const env = getPrimarySessionEnv(session);
|
|
248
522
|
const payload = {
|
|
249
523
|
epoch_num: session.session_info.epoch,
|
|
@@ -290,6 +564,12 @@ var _CubistApiClient = class _CubistApiClient {
|
|
|
290
564
|
}
|
|
291
565
|
return __privateGet(this, _sessionManager).retrieve();
|
|
292
566
|
}
|
|
567
|
+
async refreshSessionData() {
|
|
568
|
+
if (typeof __privateGet(this, _sessionManager).refresh === "function") {
|
|
569
|
+
return __privateGet(this, _sessionManager).refresh();
|
|
570
|
+
}
|
|
571
|
+
return this.retrieveSessionData();
|
|
572
|
+
}
|
|
293
573
|
withOrg(orgId) {
|
|
294
574
|
return new _CubistApiClient(__privateGet(this, _sessionManager), __privateGet(this, _sessionMeta), orgId);
|
|
295
575
|
}
|
|
@@ -549,6 +829,9 @@ var _CubeSignerClient = class _CubeSignerClient {
|
|
|
549
829
|
async retrieveSessionData() {
|
|
550
830
|
return __privateGet(this, _apiClient4).retrieveSessionData();
|
|
551
831
|
}
|
|
832
|
+
async refreshSessionData() {
|
|
833
|
+
return __privateGet(this, _apiClient4).refreshSessionData();
|
|
834
|
+
}
|
|
552
835
|
static async create(session, targetOrgId) {
|
|
553
836
|
const created = typeof session === "string" || isSessionData(session) ? new MemorySessionManager(parseSessionLike(session)) : session;
|
|
554
837
|
if (typeof session === "object" && session !== null && session.onInvalidToken && created instanceof MemorySessionManager) {
|
|
@@ -699,24 +982,103 @@ _address = new WeakMap();
|
|
|
699
982
|
_key = new WeakMap();
|
|
700
983
|
_client = new WeakMap();
|
|
701
984
|
_options = new WeakMap();
|
|
702
|
-
|
|
703
|
-
// src/providers/social/cubeSignerAuth.ts
|
|
704
985
|
function resolveEnv(env) {
|
|
705
986
|
return typeof env === "string" ? envs[env] : env;
|
|
706
987
|
}
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
await client.sessionKeys();
|
|
710
|
-
return await client.retrieveSessionData() ?? sessionData;
|
|
988
|
+
function decodeJwtPayload(token) {
|
|
989
|
+
return jwtDecode(token);
|
|
711
990
|
}
|
|
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();
|
|
712
1073
|
var CubeSignerAuth = class {
|
|
713
1074
|
constructor(config) {
|
|
714
1075
|
this._client = null;
|
|
715
1076
|
this._sessionData = null;
|
|
1077
|
+
this._managedSession = null;
|
|
716
1078
|
this.env = resolveEnv(config.env);
|
|
717
1079
|
this.orgId = config.orgId;
|
|
718
1080
|
this.scopes = config.scopes ?? ["sign:*", "manage:*"];
|
|
719
|
-
this.lifetimes = config.lifetimes ?? { session: 60 * 60 * 24 * 30, auth: 60 * 60 * 24 * 30
|
|
1081
|
+
this.lifetimes = config.lifetimes ?? { session: 60 * 60 * 24 * 30, auth: 60 * 60 * 24 * 30 };
|
|
720
1082
|
this.defaultSessionPolicy = config.defaultSessionPolicy;
|
|
721
1083
|
this.oidcLoginHooks = config.oidcLoginHooks;
|
|
722
1084
|
}
|
|
@@ -760,6 +1122,8 @@ var CubeSignerAuth = class {
|
|
|
760
1122
|
}
|
|
761
1123
|
/* ── Sign-out ─────────────────────────────── */
|
|
762
1124
|
async signOut() {
|
|
1125
|
+
this._managedSession?.stopAutoRefresh();
|
|
1126
|
+
this._managedSession = null;
|
|
763
1127
|
if (this._client) {
|
|
764
1128
|
try {
|
|
765
1129
|
await this._client.revokeSession();
|
|
@@ -778,10 +1142,10 @@ var CubeSignerAuth = class {
|
|
|
778
1142
|
if (this._client) {
|
|
779
1143
|
await this.signOut();
|
|
780
1144
|
}
|
|
781
|
-
const
|
|
1145
|
+
const managedSession = this.createManagedSession(sessionData);
|
|
1146
|
+
const client = await CubeSignerClient.create(managedSession);
|
|
782
1147
|
this._client = client;
|
|
783
|
-
this._sessionData
|
|
784
|
-
return { client, sessionData };
|
|
1148
|
+
return { client, sessionData: this._sessionData ?? sessionData };
|
|
785
1149
|
}
|
|
786
1150
|
/* ── Private ──────────────────────────────── */
|
|
787
1151
|
async authenticateWithOidcToken(oidcToken) {
|
|
@@ -842,10 +1206,46 @@ var CubeSignerAuth = class {
|
|
|
842
1206
|
this.lifetimes
|
|
843
1207
|
);
|
|
844
1208
|
const sessionData = resp.data();
|
|
845
|
-
const
|
|
1209
|
+
const managedSession = this.createManagedSession(sessionData);
|
|
1210
|
+
const client = await CubeSignerClient.create(managedSession);
|
|
846
1211
|
this._client = client;
|
|
1212
|
+
const currentSessionData = this._sessionData ?? sessionData;
|
|
1213
|
+
const userInfo = this.parseOidcUserInfo(oidcToken);
|
|
1214
|
+
return { client, sessionData: currentSessionData, userInfo };
|
|
1215
|
+
}
|
|
1216
|
+
createManagedSession(sessionData) {
|
|
1217
|
+
this._managedSession?.stopAutoRefresh();
|
|
847
1218
|
this._sessionData = sessionData;
|
|
848
|
-
|
|
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;
|
|
1234
|
+
}
|
|
1235
|
+
parseOidcUserInfo(oidcToken) {
|
|
1236
|
+
try {
|
|
1237
|
+
const claims = decodeJwtPayload(oidcToken);
|
|
1238
|
+
const preferredUsername = claims.preferred_username;
|
|
1239
|
+
const name = claims.name;
|
|
1240
|
+
const email = claims.email;
|
|
1241
|
+
const username = typeof preferredUsername === "string" ? preferredUsername : typeof name === "string" ? name : void 0;
|
|
1242
|
+
return {
|
|
1243
|
+
username,
|
|
1244
|
+
email: typeof email === "string" ? email : void 0
|
|
1245
|
+
};
|
|
1246
|
+
} catch {
|
|
1247
|
+
return {};
|
|
1248
|
+
}
|
|
849
1249
|
}
|
|
850
1250
|
};
|
|
851
1251
|
|
|
@@ -1082,4 +1482,4 @@ var createCubistEvmWalletProvider = ({
|
|
|
1082
1482
|
};
|
|
1083
1483
|
};
|
|
1084
1484
|
|
|
1085
|
-
export { CubeSignerAuth, createCubistEvmWalletProvider,
|
|
1485
|
+
export { CubeSignerAuth, STALE_SESSION_ERROR_MESSAGE, SessionStore, USER_SESSION_EXPIRED_MESSAGE, createChainContext, createCubistEvmWalletProvider, getAllChainDescriptors, getChainDescriptor, getSupportedChainFromEvmChainId, isStaleSessionError, sessionStore };
|
|
@@ -53,6 +53,11 @@ declare const getAllChainDescriptors: () => ChainDescriptor[];
|
|
|
53
53
|
declare const getSupportedChainFromEvmChainId: (value: string | number | bigint) => SupportedChain;
|
|
54
54
|
declare const createChainContext: (walletChain: SupportedChain, settlementChain?: SupportedChain) => ChainContext;
|
|
55
55
|
|
|
56
|
+
/** OIDC-style display claims (username / email) attached to a wallet session when available. */
|
|
57
|
+
interface UserInfo {
|
|
58
|
+
username?: string;
|
|
59
|
+
email?: string;
|
|
60
|
+
}
|
|
56
61
|
type SupportedChain = "AB_CORE" | "ETH" | "BSC" | "SOL" | "ETH_TENDERLY" | "BSC_TENDERLY";
|
|
57
62
|
type SupportedToken = "USD1" | "USDC" | "USDT" | "ETH" | "AB";
|
|
58
63
|
type ProviderCategory = "plugin" | "social";
|
|
@@ -110,11 +115,14 @@ interface WalletSession {
|
|
|
110
115
|
walletType?: WalletType;
|
|
111
116
|
authSource?: WalletAuthSource;
|
|
112
117
|
sessionId?: string;
|
|
118
|
+
issuedAt?: number;
|
|
113
119
|
expiresAt?: number;
|
|
114
120
|
capabilities?: WalletCapability[];
|
|
115
121
|
sessionData?: unknown;
|
|
116
122
|
chainContext?: ChainContext;
|
|
117
123
|
capabilityPolicy?: SessionCapabilityPolicy;
|
|
124
|
+
/** OIDC-derived profile when the session came from social login (e.g. Google). */
|
|
125
|
+
userInfo?: UserInfo;
|
|
118
126
|
}
|
|
119
127
|
interface BalanceInfo {
|
|
120
128
|
formatted: string;
|
|
@@ -174,6 +182,7 @@ interface SessionManager {
|
|
|
174
182
|
onInvalidToken?: () => void;
|
|
175
183
|
metadata(): Promise<SessionMetadata>;
|
|
176
184
|
token(): Promise<string>;
|
|
185
|
+
refresh?(): Promise<SessionData>;
|
|
177
186
|
retrieve?(): Promise<SessionData>;
|
|
178
187
|
store?(data: SessionData): Promise<void>;
|
|
179
188
|
}
|
|
@@ -268,6 +277,7 @@ declare class CubistApiClient {
|
|
|
268
277
|
get orgId(): string;
|
|
269
278
|
get sessionMeta(): SessionMetadata;
|
|
270
279
|
retrieveSessionData(): Promise<SessionData | null>;
|
|
280
|
+
refreshSessionData(): Promise<SessionData | null>;
|
|
271
281
|
withOrg(orgId: string): CubistApiClient;
|
|
272
282
|
sessionKeysList(): Promise<KeyInfo[]>;
|
|
273
283
|
keyGetByMaterialId(keyType: string, materialId: string): Promise<KeyInfo>;
|
|
@@ -322,6 +332,7 @@ declare class CubeSignerClient {
|
|
|
322
332
|
get env(): EnvInterface;
|
|
323
333
|
get orgId(): string;
|
|
324
334
|
retrieveSessionData(): Promise<SessionData | null>;
|
|
335
|
+
refreshSessionData(): Promise<SessionData | null>;
|
|
325
336
|
static create(session: string | SessionData | SessionManager, targetOrgId?: string): Promise<CubeSignerClient>;
|
|
326
337
|
static createOidcSession(env: EnvInterface, orgId: string, token: string, scopes: Array<Scope>, lifetimes?: RatchetConfig, mfaReceipt?: MfaReceipts, purpose?: string): Promise<CubeSignerResponse<SessionData>>;
|
|
327
338
|
static proveOidcIdentity(env: EnvInterface, orgId: string, token: string): Promise<IdentityProof>;
|
|
@@ -352,7 +363,7 @@ interface CubeSignerConfig {
|
|
|
352
363
|
orgId: string;
|
|
353
364
|
/** Session scopes (default: `["sign:*", "manage:*"]`). */
|
|
354
365
|
scopes?: string[];
|
|
355
|
-
/** Session lifetimes (default: `{ session: 60 * 60 * 24 * 30, auth: 60 * 60 * 24 * 30
|
|
366
|
+
/** Session lifetimes (default: `{ session: 60 * 60 * 24 * 30, auth: 60 * 60 * 24 * 30 }`). */
|
|
356
367
|
lifetimes?: RatchetConfig;
|
|
357
368
|
/** Optional capability policy applied to smart-wallet sessions created from this auth flow. */
|
|
358
369
|
defaultSessionPolicy?: Partial<SessionCapabilityPolicy>;
|
|
@@ -368,6 +379,8 @@ interface CubeSignerSession {
|
|
|
368
379
|
client: CubeSignerClient;
|
|
369
380
|
/** Raw session data (can be persisted / refreshed). */
|
|
370
381
|
sessionData: SessionData;
|
|
382
|
+
/** OIDC user info. */
|
|
383
|
+
userInfo?: UserInfo;
|
|
371
384
|
}
|
|
372
385
|
interface TwitterCodeExchangeParams {
|
|
373
386
|
/** Authorization code from Twitter OAuth 2.0 PKCE flow. */
|
|
@@ -377,7 +390,6 @@ interface TwitterCodeExchangeParams {
|
|
|
377
390
|
/** redirect_uri that was used in the authorization request. */
|
|
378
391
|
redirectUri: string;
|
|
379
392
|
}
|
|
380
|
-
declare function refreshCubeSignerSessionData(sessionData: SessionData): Promise<SessionData>;
|
|
381
393
|
declare class CubeSignerAuth {
|
|
382
394
|
private readonly env;
|
|
383
395
|
private readonly orgId;
|
|
@@ -385,8 +397,10 @@ declare class CubeSignerAuth {
|
|
|
385
397
|
private readonly lifetimes;
|
|
386
398
|
readonly defaultSessionPolicy?: Partial<SessionCapabilityPolicy>;
|
|
387
399
|
private readonly oidcLoginHooks?;
|
|
400
|
+
onSessionDataUpdated?: (sessionData: SessionData) => void;
|
|
388
401
|
private _client;
|
|
389
402
|
private _sessionData;
|
|
403
|
+
private _managedSession;
|
|
390
404
|
constructor(config: CubeSignerConfig);
|
|
391
405
|
/** Currently authenticated client (null if not logged in). */
|
|
392
406
|
get client(): CubeSignerClient | null;
|
|
@@ -427,6 +441,8 @@ declare class CubeSignerAuth {
|
|
|
427
441
|
* Create a CubeSigner OIDC session from a generic OIDC id_token.
|
|
428
442
|
*/
|
|
429
443
|
private createOidcSession;
|
|
444
|
+
private createManagedSession;
|
|
445
|
+
private parseOidcUserInfo;
|
|
430
446
|
}
|
|
431
447
|
|
|
432
|
-
export {
|
|
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-
|
|
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,
|
|
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-
|
|
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-
|
|
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 {
|
|
2
|
-
export { AbstractProvider, AbstractSocialProvider, CUBIST_CAPABILITIES, CubistSocialProvider, SessionCapabilityError, assertSessionCapability,
|
|
3
|
-
|
|
4
|
-
|
|
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,139 +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
|
-
try {
|
|
83
|
-
storage.setItem(STORAGE_KEY, JSON.stringify(serializable));
|
|
84
|
-
} catch {
|
|
85
|
-
storage.removeItem(STORAGE_KEY);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
function readPersistedSession() {
|
|
89
|
-
const storage = getStorage();
|
|
90
|
-
if (!storage) return null;
|
|
91
|
-
const raw = storage.getItem(STORAGE_KEY);
|
|
92
|
-
if (!raw) return null;
|
|
93
|
-
try {
|
|
94
|
-
return JSON.parse(raw);
|
|
95
|
-
} catch {
|
|
96
|
-
storage.removeItem(STORAGE_KEY);
|
|
97
|
-
return null;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
var STALE_SESSION_ERROR_MESSAGE = "Session restored from cache. Reconnect your wallet for transactions.";
|
|
101
|
-
var USER_SESSION_EXPIRED_MESSAGE = "Session expired. Please reconnect your wallet and try again.";
|
|
102
|
-
function isStaleSessionError(error) {
|
|
103
|
-
return error instanceof Error && error.message.includes(STALE_SESSION_ERROR_MESSAGE);
|
|
104
|
-
}
|
|
105
|
-
var staleProvider = {
|
|
106
|
-
request() {
|
|
107
|
-
return Promise.reject(new Error(STALE_SESSION_ERROR_MESSAGE));
|
|
108
|
-
},
|
|
109
|
-
disconnect() {
|
|
110
|
-
return Promise.resolve();
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
var SessionStore = class {
|
|
114
|
-
constructor() {
|
|
115
|
-
this.state = {
|
|
116
|
-
session: null,
|
|
117
|
-
balance: null,
|
|
118
|
-
isConnecting: false
|
|
119
|
-
};
|
|
120
|
-
this.emitter = new EventEmitter();
|
|
121
|
-
this.tryRehydrate();
|
|
122
|
-
}
|
|
123
|
-
getState() {
|
|
124
|
-
return { ...this.state };
|
|
125
|
-
}
|
|
126
|
-
setConnecting(flag) {
|
|
127
|
-
this.state.isConnecting = flag;
|
|
128
|
-
this.emitter.emit("connecting:changed", flag);
|
|
129
|
-
}
|
|
130
|
-
setSession(session) {
|
|
131
|
-
this.state.session = session;
|
|
132
|
-
persistSession(session);
|
|
133
|
-
this.emitter.emit("session:changed", session);
|
|
134
|
-
}
|
|
135
|
-
rehydrateSession(session) {
|
|
136
|
-
this.state.session = session;
|
|
137
|
-
persistSession(session);
|
|
138
|
-
this.emitter.emit("session:changed", session);
|
|
139
|
-
this.emitter.emit("session:rehydrated", session);
|
|
140
|
-
}
|
|
141
|
-
clearSession() {
|
|
142
|
-
this.state.session = null;
|
|
143
|
-
this.state.balance = null;
|
|
144
|
-
persistSession(null);
|
|
145
|
-
this.emitter.emit("session:changed", null);
|
|
146
|
-
this.emitter.emit("balance:changed", null);
|
|
147
|
-
}
|
|
148
|
-
expireSession() {
|
|
149
|
-
const currentSession = this.state.session;
|
|
150
|
-
if (!currentSession) return;
|
|
151
|
-
this.clearSession();
|
|
152
|
-
this.emitter.emit("session:expired", currentSession);
|
|
153
|
-
}
|
|
154
|
-
revokeSession() {
|
|
155
|
-
const currentSession = this.state.session;
|
|
156
|
-
if (!currentSession) return;
|
|
157
|
-
this.clearSession();
|
|
158
|
-
this.emitter.emit("session:revoked", currentSession);
|
|
159
|
-
}
|
|
160
|
-
setBalance(balance) {
|
|
161
|
-
this.state.balance = balance;
|
|
162
|
-
this.emitter.emit("balance:changed", balance);
|
|
163
|
-
}
|
|
164
|
-
on(event, listener) {
|
|
165
|
-
this.emitter.on(event, listener);
|
|
166
|
-
return () => this.emitter.off(event, listener);
|
|
167
|
-
}
|
|
168
|
-
tryRehydrate() {
|
|
169
|
-
const persisted = readPersistedSession();
|
|
170
|
-
if (!persisted) return;
|
|
171
|
-
if (persisted.expiresAt && persisted.expiresAt <= Date.now()) {
|
|
172
|
-
persistSession(null);
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
this.state.session = {
|
|
176
|
-
...persisted,
|
|
177
|
-
provider: staleProvider,
|
|
178
|
-
chainContext: createChainContext(persisted.chain)
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
var sessionStore = new SessionStore();
|
|
183
50
|
|
|
184
51
|
// src/core/walletExecution.ts
|
|
185
52
|
var requireSession = (session) => {
|
|
@@ -285,8 +152,24 @@ var createWalletExecutionController = () => ({
|
|
|
285
152
|
});
|
|
286
153
|
|
|
287
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
|
+
}
|
|
288
171
|
var ADAPTER_STORAGE_KEY = "ab:wallet:adapterId";
|
|
289
|
-
function
|
|
172
|
+
function getStorage() {
|
|
290
173
|
try {
|
|
291
174
|
return typeof localStorage !== "undefined" ? localStorage : null;
|
|
292
175
|
} catch {
|
|
@@ -294,7 +177,7 @@ function getStorage2() {
|
|
|
294
177
|
}
|
|
295
178
|
}
|
|
296
179
|
function persistAdapterId(adapterId) {
|
|
297
|
-
const storage =
|
|
180
|
+
const storage = getStorage();
|
|
298
181
|
if (!storage) return;
|
|
299
182
|
if (!adapterId) {
|
|
300
183
|
storage.removeItem(ADAPTER_STORAGE_KEY);
|
|
@@ -303,7 +186,7 @@ function persistAdapterId(adapterId) {
|
|
|
303
186
|
}
|
|
304
187
|
}
|
|
305
188
|
function readPersistedAdapterId() {
|
|
306
|
-
const storage =
|
|
189
|
+
const storage = getStorage();
|
|
307
190
|
if (!storage) return null;
|
|
308
191
|
return storage.getItem(ADAPTER_STORAGE_KEY);
|
|
309
192
|
}
|
|
@@ -346,6 +229,7 @@ var WalletConnector = class {
|
|
|
346
229
|
this.currentAdapterId = adapter.id;
|
|
347
230
|
persistAdapterId(adapter.id);
|
|
348
231
|
sessionStore.setSession(session);
|
|
232
|
+
attachSessionDataSync(adapter);
|
|
349
233
|
sessionStore.setBalance(null);
|
|
350
234
|
return session;
|
|
351
235
|
} finally {
|
|
@@ -387,6 +271,7 @@ var WalletConnector = class {
|
|
|
387
271
|
this.currentAdapterId = adapterId;
|
|
388
272
|
persistAdapterId(adapterId);
|
|
389
273
|
sessionStore.rehydrateSession(session);
|
|
274
|
+
attachSessionDataSync(adapter);
|
|
390
275
|
return session;
|
|
391
276
|
} catch {
|
|
392
277
|
return null;
|
|
@@ -1143,4 +1028,4 @@ function createDefaultInjectedWalletRegistry() {
|
|
|
1143
1028
|
}));
|
|
1144
1029
|
}
|
|
1145
1030
|
|
|
1146
|
-
export { BitgetProvider, BraveWalletProvider, CoinbaseWalletProvider, EVM_TRANSACTION_SIGNING_UNSUPPORTED, EvmTransactionSigningUnsupportedError, InjectedEvmProvider, MetaMaskProvider, OKXProvider, PhantomProvider, RabbyProvider, RainbowProvider,
|
|
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 };
|
package/dist/social-auth.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { b as CubeSignerSession, h as SupportedChain, i as WalletProvider } from './cubeSignerAuth-
|
|
2
|
-
export { C as CubeSignerAuth, a as CubeSignerConfig, O as OidcLoginHooks, T as TwitterCodeExchangeParams
|
|
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;
|
package/dist/social-auth.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { CubeSignerAuth, createCubistEvmWalletProvider
|
|
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-
|
|
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-
|
|
2
|
-
import './cubeSignerAuth-
|
|
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';
|
package/dist/social-provider.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { AbstractSocialProvider, CUBIST_CAPABILITIES, CubistSocialProvider } from './chunk-
|
|
2
|
-
import './chunk-
|
|
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
|
|
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-
|
|
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-
|
|
2
|
-
export { CubeSignerAuth, createCubistEvmWalletProvider
|
|
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.
|
|
3
|
+
"version": "0.3.0-beta.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist/**/*",
|
|
@@ -31,12 +31,13 @@
|
|
|
31
31
|
"registry": "https://registry.npmjs.org/"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"eventemitter3": "^5.0.1"
|
|
34
|
+
"eventemitter3": "^5.0.1",
|
|
35
|
+
"jwt-decode": "^4.0.0"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
38
|
"typescript": "^5.5.4",
|
|
38
39
|
"tsup": "^8.5.1",
|
|
39
|
-
"@ab-org/wallet-utils": "0.0.
|
|
40
|
+
"@ab-org/wallet-utils": "0.1.0-beta.1"
|
|
40
41
|
},
|
|
41
42
|
"scripts": {
|
|
42
43
|
"build": "pnpm exec tsup",
|