@ab-org/sdk-core 0.1.1 → 0.1.2-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,172 +1,7 @@
1
+ import { AbstractProvider, getSupportedChainFromEvmChainId, createChainContext, assertSessionCapability } from './chunk-MVZIAM4H.js';
2
+ export { AbstractProvider, AbstractSocialProvider, CubistSocialProvider, SessionCapabilityError, assertSessionCapability, createChainContext, createSessionCapabilityPolicy, describeSessionCapabilityPolicy, getAllChainDescriptors, getChainDescriptor, getSupportedChainFromEvmChainId, isCapabilityPolicyExpired, isSessionExpired, sessionSupportsCapability } from './chunk-MVZIAM4H.js';
3
+ export { CubeSignerAuth } from './chunk-5HURLKIK.js';
1
4
  import EventEmitter from 'eventemitter3';
2
- import { CubeSignerClient, MemorySessionManager, envs, EvmSigner } from '@cubist-labs/cubesigner-sdk';
3
-
4
- // src/core/chains.ts
5
- var chainDescriptors = {
6
- AB_CORE: {
7
- chain: "AB_CORE",
8
- namespace: "ab-core",
9
- reference: "ab:core",
10
- label: "AB Core",
11
- rpcFamily: "custom",
12
- supportsSmartSessions: true,
13
- supportsAccountAbstraction: true
14
- },
15
- ETH: {
16
- chain: "ETH",
17
- namespace: "evm",
18
- reference: "eip155:1",
19
- label: "Ethereum",
20
- rpcFamily: "evm",
21
- evmChainId: 1,
22
- supportsSmartSessions: true,
23
- supportsAccountAbstraction: true
24
- },
25
- BSC: {
26
- chain: "BSC",
27
- namespace: "evm",
28
- reference: "eip155:56",
29
- label: "BNB Smart Chain",
30
- rpcFamily: "evm",
31
- evmChainId: 56,
32
- supportsSmartSessions: true,
33
- supportsAccountAbstraction: false
34
- },
35
- ETH_TENDERLY: {
36
- chain: "ETH_TENDERLY",
37
- namespace: "evm",
38
- reference: "eip155:3030",
39
- label: "Ethereum Tenderly",
40
- rpcFamily: "evm",
41
- evmChainId: 3030,
42
- supportsSmartSessions: true,
43
- supportsAccountAbstraction: true
44
- },
45
- BSC_TENDERLY: {
46
- chain: "BSC_TENDERLY",
47
- namespace: "evm",
48
- reference: "eip155:3131",
49
- label: "BNB Smart Chain Tenderly",
50
- rpcFamily: "evm",
51
- evmChainId: 3131,
52
- supportsSmartSessions: true,
53
- supportsAccountAbstraction: false
54
- },
55
- SOL: {
56
- chain: "SOL",
57
- namespace: "solana",
58
- reference: "solana:mainnet-beta",
59
- label: "Solana",
60
- rpcFamily: "solana",
61
- supportsSmartSessions: true,
62
- supportsAccountAbstraction: false
63
- }
64
- };
65
- var getChainDescriptor = (chain) => chainDescriptors[chain];
66
- var getAllChainDescriptors = () => Object.values(chainDescriptors);
67
- var normalizeEvmChainId = (value) => {
68
- if (typeof value === "number") return value;
69
- if (typeof value === "bigint") return Number(value);
70
- return Number(BigInt(value));
71
- };
72
- var getSupportedChainFromEvmChainId = (value) => {
73
- const chainId = normalizeEvmChainId(value);
74
- const descriptor = getAllChainDescriptors().find(
75
- (item) => item.namespace === "evm" && item.evmChainId === chainId
76
- );
77
- if (!descriptor) {
78
- throw new Error(`Unsupported EVM chainId: ${chainId}`);
79
- }
80
- return descriptor.chain;
81
- };
82
- var createChainContext = (walletChain, settlementChain = walletChain) => ({
83
- walletChain,
84
- walletChainDescriptor: getChainDescriptor(walletChain),
85
- settlementChain,
86
- settlementChainDescriptor: getChainDescriptor(settlementChain)
87
- });
88
-
89
- // src/core/capabilities.ts
90
- var SessionCapabilityError = class extends Error {
91
- constructor(message) {
92
- super(message);
93
- this.name = "SessionCapabilityError";
94
- }
95
- };
96
- var toBigIntAmount = (value) => {
97
- if (typeof value === "bigint") return value;
98
- if (typeof value === "number") return BigInt(value);
99
- return BigInt(value);
100
- };
101
- var createSessionCapabilityPolicy = (input = {}) => ({
102
- id: input.id ?? `cap:${Date.now()}`,
103
- appId: input.appId,
104
- origin: input.origin,
105
- expiresAt: input.expiresAt,
106
- methods: input.methods,
107
- chains: input.chains,
108
- tokens: input.tokens,
109
- maxAmount: input.maxAmount,
110
- revocable: input.revocable ?? true,
111
- metadata: input.metadata
112
- });
113
- var isSessionExpired = (session, now = Date.now()) => Boolean(session?.expiresAt && session.expiresAt <= now);
114
- var isCapabilityPolicyExpired = (policy, now = Date.now()) => Boolean(policy?.expiresAt && policy.expiresAt <= now);
115
- var sessionSupportsCapability = (session, capability) => {
116
- const capabilities = session?.capabilities;
117
- if (!capabilities || capabilities.length === 0) return true;
118
- return capabilities.includes(capability);
119
- };
120
- var describeSessionCapabilityPolicy = (policy) => {
121
- if (!policy) return [];
122
- const lines = [];
123
- if (policy.origin) lines.push(`Origin: ${policy.origin}`);
124
- if (policy.appId) lines.push(`App: ${policy.appId}`);
125
- if (policy.methods?.length) lines.push(`Methods: ${policy.methods.join(", ")}`);
126
- if (policy.chains?.length) lines.push(`Chains: ${policy.chains.join(", ")}`);
127
- if (policy.tokens?.length) lines.push(`Tokens: ${policy.tokens.join(", ")}`);
128
- if (policy.maxAmount) lines.push(`Max amount: ${policy.maxAmount}`);
129
- if (policy.expiresAt) lines.push(`Expires at: ${new Date(policy.expiresAt).toISOString()}`);
130
- return lines;
131
- };
132
- var assertSessionCapability = (session, check) => {
133
- const now = check.now ?? Date.now();
134
- if (isSessionExpired(session, now)) {
135
- throw new SessionCapabilityError("Wallet session has expired");
136
- }
137
- const policy = session.capabilityPolicy;
138
- if (isCapabilityPolicyExpired(policy, now)) {
139
- throw new SessionCapabilityError("Capability session has expired");
140
- }
141
- if (!sessionSupportsCapability(session, check.capability)) {
142
- throw new SessionCapabilityError(
143
- `Wallet session does not support capability "${check.capability}"`
144
- );
145
- }
146
- if (!policy) return;
147
- if (policy.appId && check.appId && policy.appId !== check.appId) {
148
- throw new SessionCapabilityError("Capability session is scoped to a different app");
149
- }
150
- if (policy.origin && check.origin && policy.origin !== check.origin) {
151
- throw new SessionCapabilityError("Capability session is scoped to a different origin");
152
- }
153
- if (policy.methods?.length && !policy.methods.includes(check.capability)) {
154
- throw new SessionCapabilityError(
155
- `Capability "${check.capability}" is not allowed for this session`
156
- );
157
- }
158
- if (check.chain && policy.chains?.length && !policy.chains.includes(check.chain)) {
159
- throw new SessionCapabilityError(`Chain "${check.chain}" is not allowed for this session`);
160
- }
161
- if (check.token && policy.tokens?.length && !policy.tokens.includes(check.token)) {
162
- throw new SessionCapabilityError(`Token "${check.token}" is not allowed for this session`);
163
- }
164
- if (policy.maxAmount && check.amount !== void 0) {
165
- if (toBigIntAmount(check.amount) > toBigIntAmount(policy.maxAmount)) {
166
- throw new SessionCapabilityError("Requested amount exceeds the capability session limit");
167
- }
168
- }
169
- };
170
5
 
171
6
  // src/core/errors.ts
172
7
  var EVM_TRANSACTION_SIGNING_UNSUPPORTED = "EVM_TRANSACTION_SIGNING_UNSUPPORTED";
@@ -616,38 +451,6 @@ var createAccountController = () => {
616
451
  };
617
452
  };
618
453
 
619
- // src/providers/base.ts
620
- var AbstractProvider = class {
621
- constructor() {
622
- this.currentSession = null;
623
- }
624
- async disconnect() {
625
- this.clearSession();
626
- }
627
- setSession(session) {
628
- this.currentSession = session;
629
- return session;
630
- }
631
- clearSession() {
632
- this.currentSession = null;
633
- }
634
- get session() {
635
- return this.currentSession;
636
- }
637
- requireSession(message = `${this.title} session missing`) {
638
- if (!this.currentSession) {
639
- throw new Error(message);
640
- }
641
- return this.currentSession;
642
- }
643
- getProvider() {
644
- return this.currentSession?.provider ?? null;
645
- }
646
- async reconnect(_persistedSession) {
647
- return null;
648
- }
649
- };
650
-
651
454
  // ../wallet-utils/dist/index.js
652
455
  var __defProp = Object.defineProperty;
653
456
  var __export = (target, all) => {
@@ -831,7 +634,6 @@ function getEnv(key) {
831
634
  }
832
635
  } catch {
833
636
  }
834
- console.error(`${key} is not set.`);
835
637
  return "";
836
638
  }
837
639
  var TENDERLY_BSC_3131 = {
@@ -920,6 +722,7 @@ getFundingTokenAddress(DEFAULT_FUNDING_CHAIN_ID);
920
722
  google: getEnv("GOOGLE_CLIENT_ID"),
921
723
  x: getEnv("X_CLIENT_ID")
922
724
  });
725
+ new TextEncoder();
923
726
 
924
727
  // src/providers/plugin/injectedEvmProvider.ts
925
728
  var injectedWalletCapabilities = [
@@ -1313,464 +1116,4 @@ function createDefaultInjectedWalletRegistry() {
1313
1116
  }));
1314
1117
  }
1315
1118
 
1316
- // src/providers/social/baseSocialProvider.ts
1317
- var AbstractSocialProvider = class extends AbstractProvider {
1318
- constructor() {
1319
- super(...arguments);
1320
- this.category = "social";
1321
- }
1322
- async connect(args) {
1323
- await this.signIn(args?.options, args?.payload);
1324
- return this.requireSession();
1325
- }
1326
- };
1327
- function resolveEnv(env) {
1328
- return typeof env === "string" ? envs[env] : env;
1329
- }
1330
- var CubeSignerAuth = class {
1331
- constructor(config) {
1332
- this._client = null;
1333
- this._sessionData = null;
1334
- this.env = resolveEnv(config.env);
1335
- this.orgId = config.orgId;
1336
- this.scopes = config.scopes ?? ["sign:*", "manage:*"];
1337
- this.defaultSessionPolicy = config.defaultSessionPolicy;
1338
- this.oidcLoginHooks = config.oidcLoginHooks;
1339
- }
1340
- /** Currently authenticated client (null if not logged in). */
1341
- get client() {
1342
- return this._client;
1343
- }
1344
- get currentSession() {
1345
- if (!this._client || !this._sessionData) return null;
1346
- return {
1347
- client: this._client,
1348
- sessionData: this._sessionData
1349
- };
1350
- }
1351
- /* ── Google ───────────────────────────────── */
1352
- /**
1353
- * Login with a Google ID token (JWT).
1354
- * The token is used directly as the OIDC credential.
1355
- */
1356
- async loginWithGoogle(idToken) {
1357
- return this.authenticateWithOidcToken(idToken);
1358
- }
1359
- /* ── Twitter / X ──────────────────────────── */
1360
- /**
1361
- * Login with a Twitter OAuth 2.0 authorization code.
1362
- *
1363
- * 1. Exchange the code for an OIDC `id_token` via CubeSigner's
1364
- * `/v0/org/{org_id}/oauth2/twitter` endpoint.
1365
- * 2. Create a CubeSigner session with that token.
1366
- */
1367
- async loginWithTwitter(params) {
1368
- const idToken = await this.exchangeTwitterCode(params);
1369
- return this.authenticateWithOidcToken(idToken);
1370
- }
1371
- /* ── Sign-out ─────────────────────────────── */
1372
- async signOut() {
1373
- if (this._client) {
1374
- try {
1375
- await this._client.revokeSession();
1376
- } catch {
1377
- }
1378
- this._client = null;
1379
- this._sessionData = null;
1380
- }
1381
- }
1382
- /* ── Session restore ────────────────────── */
1383
- /**
1384
- * Restore a CubeSigner session from previously persisted SessionData.
1385
- * Useful for reconnecting after page reload without re-authentication.
1386
- */
1387
- async restoreSession(sessionData) {
1388
- if (this._client) {
1389
- await this.signOut();
1390
- }
1391
- const client = await CubeSignerClient.create(
1392
- new MemorySessionManager(sessionData)
1393
- );
1394
- this._client = client;
1395
- this._sessionData = sessionData;
1396
- return { client, sessionData };
1397
- }
1398
- /* ── Private ──────────────────────────────── */
1399
- async authenticateWithOidcToken(oidcToken) {
1400
- if (this._client) {
1401
- await this.signOut();
1402
- }
1403
- const hooks = this.oidcLoginHooks;
1404
- if (hooks) {
1405
- const proof = await CubeSignerClient.proveOidcIdentity(
1406
- this.env,
1407
- this.orgId,
1408
- oidcToken
1409
- );
1410
- if (!proof.user_info?.initialized) {
1411
- await hooks.registerUser(oidcToken);
1412
- }
1413
- }
1414
- return this.createOidcSession(oidcToken);
1415
- }
1416
- /**
1417
- * Exchange a Twitter authorization code for an OIDC id_token
1418
- * via CubeSigner's dedicated endpoint.
1419
- *
1420
- * `POST {SignerApiRoot}/v0/org/{org_id}/oauth2/twitter`
1421
- */
1422
- async exchangeTwitterCode(params) {
1423
- const url = `${this.env.SignerApiRoot}/v0/org/${this.orgId}/oauth2/twitter`;
1424
- const res = await fetch(url, {
1425
- method: "POST",
1426
- headers: { "Content-Type": "application/json" },
1427
- body: JSON.stringify({
1428
- code: params.code,
1429
- code_verifier: params.codeVerifier,
1430
- redirect_uri: params.redirectUri
1431
- })
1432
- });
1433
- if (!res.ok) {
1434
- const text = await res.text().catch(() => "");
1435
- throw new Error(
1436
- `Twitter code exchange failed (${res.status}): ${text}`
1437
- );
1438
- }
1439
- const data = await res.json();
1440
- if (!data.id_token) {
1441
- throw new Error("CubeSigner twitter exchange did not return id_token");
1442
- }
1443
- return data.id_token;
1444
- }
1445
- /**
1446
- * Create a CubeSigner OIDC session from a generic OIDC id_token.
1447
- */
1448
- async createOidcSession(oidcToken) {
1449
- const resp = await CubeSignerClient.createOidcSession(
1450
- this.env,
1451
- this.orgId,
1452
- oidcToken,
1453
- this.scopes
1454
- );
1455
- const sessionData = resp.data();
1456
- const client = await CubeSignerClient.create(
1457
- new MemorySessionManager(sessionData)
1458
- );
1459
- this._client = client;
1460
- this._sessionData = sessionData;
1461
- return { client, sessionData };
1462
- }
1463
- };
1464
- var evmChainIdMap = {
1465
- ETH: 1,
1466
- BSC: 56
1467
- };
1468
- var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
1469
- var toBigIntQuantity = (value) => {
1470
- if (typeof value === "bigint") return value;
1471
- if (typeof value === "number") {
1472
- if (!Number.isInteger(value) || value < 0) {
1473
- throw new Error(`Invalid EVM quantity number: ${value}`);
1474
- }
1475
- return BigInt(value);
1476
- }
1477
- const trimmed = value.trim();
1478
- if (!trimmed) {
1479
- throw new Error("EVM quantity cannot be empty");
1480
- }
1481
- if (/^0x[0-9a-fA-F]+$/.test(trimmed) || /^\d+$/.test(trimmed)) {
1482
- return BigInt(trimmed);
1483
- }
1484
- throw new Error(`Invalid EVM quantity string: ${value}`);
1485
- };
1486
- var toHexQuantity = (value) => {
1487
- if (value === void 0) return void 0;
1488
- return `0x${toBigIntQuantity(value).toString(16)}`;
1489
- };
1490
- var normalizeAccessList = (accessList) => {
1491
- if (!accessList) return void 0;
1492
- return accessList.map((item) => ({
1493
- address: item.address,
1494
- storageKeys: item.storageKeys
1495
- }));
1496
- };
1497
- var textEncoder = new TextEncoder();
1498
- var resolveTransactionType = (transaction) => {
1499
- if (transaction.type !== void 0) {
1500
- const normalized = toHexQuantity(transaction.type);
1501
- if (normalized === "0x0" || normalized === "0x1" || normalized === "0x2") {
1502
- return normalized;
1503
- }
1504
- throw new Error(`Unsupported EVM transaction type for Cubist: ${normalized}`);
1505
- }
1506
- if (transaction.maxFeePerGas !== void 0 || transaction.maxPriorityFeePerGas !== void 0) {
1507
- return "0x2";
1508
- }
1509
- if (transaction.accessList?.length) {
1510
- return "0x1";
1511
- }
1512
- return "0x0";
1513
- };
1514
- var toCubistSignRequest = (address, chain, transaction) => {
1515
- const resolvedChainId = (transaction.chainId !== void 0 ? Number(toBigIntQuantity(transaction.chainId)) : void 0) ?? evmChainIdMap[chain];
1516
- if (!resolvedChainId) {
1517
- throw new Error("Cubist signing requires an EVM chainId");
1518
- }
1519
- const type = resolveTransactionType(transaction);
1520
- const commonFields = {
1521
- from: transaction.from ?? address,
1522
- to: transaction.to,
1523
- data: transaction.data,
1524
- gas: toHexQuantity(transaction.gas),
1525
- nonce: toHexQuantity(transaction.nonce),
1526
- value: toHexQuantity(transaction.value)
1527
- };
1528
- const accessList = normalizeAccessList(transaction.accessList);
1529
- const tx = type === "0x2" ? {
1530
- ...commonFields,
1531
- type,
1532
- ...accessList ? { accessList } : {},
1533
- maxFeePerGas: toHexQuantity(transaction.maxFeePerGas),
1534
- maxPriorityFeePerGas: toHexQuantity(transaction.maxPriorityFeePerGas)
1535
- } : type === "0x1" ? {
1536
- ...commonFields,
1537
- type,
1538
- ...accessList ? { accessList } : {},
1539
- gasPrice: toHexQuantity(transaction.gasPrice)
1540
- } : {
1541
- ...commonFields,
1542
- type,
1543
- gasPrice: toHexQuantity(transaction.gasPrice)
1544
- };
1545
- return {
1546
- chain_id: resolvedChainId,
1547
- tx
1548
- };
1549
- };
1550
- var getTransactionParam = (params) => {
1551
- const candidate = params?.[0];
1552
- if (!isRecord(candidate)) {
1553
- throw new Error("eth_signTransaction requires a transaction object");
1554
- }
1555
- return candidate;
1556
- };
1557
- var toHexBytes = (value) => {
1558
- if (/^0x[0-9a-fA-F]*$/.test(value)) return value;
1559
- return `0x${Array.from(textEncoder.encode(value)).map((byte) => byte.toString(16).padStart(2, "0")).join("")}`;
1560
- };
1561
- var getMessageParam = (address, params) => {
1562
- const [first, second] = params ?? [];
1563
- if (typeof second === "string" && second.toLowerCase() === address.toLowerCase()) {
1564
- return String(first ?? "");
1565
- }
1566
- if (typeof first === "string" && first.toLowerCase() === address.toLowerCase()) {
1567
- return String(second ?? "");
1568
- }
1569
- return String(first ?? "");
1570
- };
1571
- var getTypedDataParam = (address, params) => {
1572
- const [first, second] = params ?? [];
1573
- if (typeof first === "string" && first.toLowerCase() === address.toLowerCase()) {
1574
- return typeof second === "string" ? JSON.parse(second) : second ?? {};
1575
- }
1576
- return typeof second === "string" ? JSON.parse(second) : second ?? first ?? {};
1577
- };
1578
- var createCubistEvmWalletProvider = ({
1579
- session,
1580
- address,
1581
- chain
1582
- }) => {
1583
- const signer = new EvmSigner(address, session.client);
1584
- return {
1585
- async request(payload) {
1586
- switch (payload.method) {
1587
- case "eth_accounts":
1588
- case "eth_requestAccounts":
1589
- return [address];
1590
- case "eth_chainId": {
1591
- const chainId = evmChainIdMap[chain];
1592
- return `0x${chainId.toString(16)}`;
1593
- }
1594
- case "eth_signTransaction": {
1595
- const transaction = getTransactionParam(payload.params);
1596
- const signRequest = toCubistSignRequest(address, chain, transaction);
1597
- return await signer.signTransaction(signRequest);
1598
- }
1599
- case "personal_sign": {
1600
- const message = getMessageParam(address, payload.params);
1601
- return await signer.signEip191({
1602
- data: toHexBytes(message)
1603
- });
1604
- }
1605
- case "eth_signTypedData_v4": {
1606
- const typedData = getTypedDataParam(address, payload.params);
1607
- const domain = typedData.domain;
1608
- const chainId = domain?.chainId !== void 0 ? Number(toBigIntQuantity(domain.chainId)) : evmChainIdMap[chain];
1609
- if (!chainId) {
1610
- throw new Error("CubistProvider: typed data signing requires an EVM chainId");
1611
- }
1612
- return await signer.signEip712({
1613
- chain_id: chainId,
1614
- typed_data: typedData
1615
- });
1616
- }
1617
- default:
1618
- throw new Error(`CubistProvider: unsupported RPC method "${payload.method}"`);
1619
- }
1620
- },
1621
- async disconnect() {
1622
- await session.client.revokeSession();
1623
- }
1624
- };
1625
- };
1626
-
1627
- // src/providers/social/cubistProvider.ts
1628
- var defaultAdapter = {
1629
- async resolve(session) {
1630
- const keys = await session.client.sessionKeys();
1631
- const evmKey = keys.find((k) => k.cached.key_type === "SecpEthAddr");
1632
- if (!evmKey) throw new Error("No EVM key found in CubeSigner session");
1633
- const address = evmKey.materialId;
1634
- const chain = "ETH";
1635
- const provider = createCubistEvmWalletProvider({
1636
- session,
1637
- address,
1638
- chain
1639
- });
1640
- return {
1641
- address,
1642
- chain,
1643
- provider,
1644
- chainContext: createChainContext(chain)
1645
- };
1646
- }
1647
- };
1648
- var cubistCapabilities = [
1649
- "eth_accounts",
1650
- "eth_requestAccounts",
1651
- "eth_chainId",
1652
- "eth_signTransaction",
1653
- "personal_sign",
1654
- "eth_signTypedData_v4",
1655
- "wallet_disconnect",
1656
- "wallet_rehydrate"
1657
- ];
1658
- var CubistSocialProvider = class extends AbstractSocialProvider {
1659
- constructor(config, adapter = defaultAdapter) {
1660
- super();
1661
- this.id = "cubist";
1662
- this.title = "Cubist Social Wallet";
1663
- this.lastCubeSignerSession = null;
1664
- /** Stash the login method so `connect()` can auto-retry. */
1665
- this.lastLogin = null;
1666
- this.auth = new CubeSignerAuth(config);
1667
- this.adapter = adapter;
1668
- }
1669
- async createWalletSession(method) {
1670
- const session = method.type === "google" ? await this.auth.loginWithGoogle(method.idToken) : await this.auth.loginWithTwitter(method.params);
1671
- this.lastCubeSignerSession = session;
1672
- const walletSession = await this.adapter.resolve(session);
1673
- const capabilityPolicy = this.auth.defaultSessionPolicy ? createSessionCapabilityPolicy(this.auth.defaultSessionPolicy) : void 0;
1674
- return {
1675
- ...walletSession,
1676
- walletType: "social",
1677
- authSource: method.type,
1678
- sessionId: `${method.type}:${walletSession.address.toLowerCase()}`,
1679
- expiresAt: capabilityPolicy?.expiresAt,
1680
- capabilities: cubistCapabilities,
1681
- sessionData: session.sessionData,
1682
- chainContext: walletSession.chainContext ?? createChainContext(walletSession.chain),
1683
- capabilityPolicy
1684
- };
1685
- }
1686
- async authenticate(method) {
1687
- const walletSession = await this.createWalletSession(method);
1688
- this.lastLogin = method;
1689
- this.setSession(walletSession);
1690
- }
1691
- getResolvedLoginMethod(payload) {
1692
- const method = payload ?? this.lastLogin;
1693
- if (!method) {
1694
- throw new Error(
1695
- "CubistSocialProvider.signIn requires a login method. Use signInWith(method) first."
1696
- );
1697
- }
1698
- return method;
1699
- }
1700
- /**
1701
- * Preferred explicit sign-in entrypoint.
1702
- */
1703
- async signInWith(method, _options) {
1704
- await this.authenticate(method);
1705
- }
1706
- /**
1707
- * Backward-compatible abstract implementation.
1708
- *
1709
- * - If `payload` is provided, it is treated as the login method.
1710
- * - Otherwise reuses the previously cached login method if available.
1711
- */
1712
- async signIn(_options, payload) {
1713
- await this.authenticate(this.getResolvedLoginMethod(payload));
1714
- }
1715
- /**
1716
- * Explicit connect flow that both authenticates and returns the wallet session.
1717
- */
1718
- async connectWith(method, options) {
1719
- return this.connect({ options, payload: method });
1720
- }
1721
- async connect(args) {
1722
- if (args?.payload !== void 0 || args?.options !== void 0) {
1723
- await this.signIn(args.options, args.payload);
1724
- return this.requireSession("Cubist session missing after sign-in");
1725
- }
1726
- if (this.session) {
1727
- return this.session;
1728
- }
1729
- if (!this.lastLogin) {
1730
- throw new Error("Cubist session missing \u2014 call signInWith(method) first");
1731
- }
1732
- await this.signIn();
1733
- return this.requireSession("Cubist session missing after sign-in");
1734
- }
1735
- async reconnect(persistedSession) {
1736
- if (!persistedSession.sessionData) return null;
1737
- try {
1738
- const csSession = await this.auth.restoreSession(
1739
- persistedSession.sessionData
1740
- );
1741
- this.lastCubeSignerSession = csSession;
1742
- const walletSession = await this.adapter.resolve(csSession);
1743
- return this.setSession({
1744
- ...walletSession,
1745
- walletType: persistedSession.walletType ?? "social",
1746
- authSource: persistedSession.authSource,
1747
- sessionId: persistedSession.sessionId,
1748
- expiresAt: persistedSession.expiresAt,
1749
- capabilities: cubistCapabilities,
1750
- sessionData: csSession.sessionData,
1751
- chainContext: walletSession.chainContext ?? createChainContext(walletSession.chain),
1752
- capabilityPolicy: persistedSession.capabilityPolicy
1753
- });
1754
- } catch {
1755
- return null;
1756
- }
1757
- }
1758
- async signOut() {
1759
- await this.auth.signOut();
1760
- this.clearSession();
1761
- this.lastLogin = null;
1762
- this.lastCubeSignerSession = null;
1763
- }
1764
- async disconnect() {
1765
- await this.signOut();
1766
- }
1767
- /** Direct access to the underlying CubeSignerAuth for advanced use-cases. */
1768
- get cubeSignerAuth() {
1769
- return this.auth;
1770
- }
1771
- get cubeSignerSession() {
1772
- return this.lastCubeSignerSession ?? this.auth.currentSession;
1773
- }
1774
- };
1775
-
1776
- export { AbstractProvider, AbstractSocialProvider, BitgetProvider, BraveWalletProvider, CoinbaseWalletProvider, CubeSignerAuth, CubistSocialProvider, EVM_TRANSACTION_SIGNING_UNSUPPORTED, EvmTransactionSigningUnsupportedError, InjectedEvmProvider, MetaMaskProvider, OKXProvider, PhantomProvider, RabbyProvider, RainbowProvider, SessionCapabilityError, SessionStore, TrustWalletProvider, WalletConnector, ZerionProvider, assertSessionCapability, createAccountController, createChainContext, createDefaultInjectedWalletRegistry, createSessionCapabilityPolicy, createWalletConnectController, createWalletExecutionClient, createWalletExecutionController, describeSessionCapabilityPolicy, discoverEIP6963Providers, findEIP6963Provider, findInjectedProvider, getAllChainDescriptors, getChainDescriptor, getSupportedChainFromEvmChainId, getWalletExecutionCapabilities, isCapabilityPolicyExpired, isSessionExpired, isUnsupportedEvmTransactionSigningError, normalizeEvmTransactionSigningError, sessionStore, sessionSupportsCapability, switchToFallbackFundingChain };
1119
+ export { BitgetProvider, BraveWalletProvider, CoinbaseWalletProvider, EVM_TRANSACTION_SIGNING_UNSUPPORTED, EvmTransactionSigningUnsupportedError, InjectedEvmProvider, MetaMaskProvider, OKXProvider, PhantomProvider, RabbyProvider, RainbowProvider, SessionStore, TrustWalletProvider, WalletConnector, ZerionProvider, createAccountController, createDefaultInjectedWalletRegistry, createWalletConnectController, createWalletExecutionClient, createWalletExecutionController, discoverEIP6963Providers, findEIP6963Provider, findInjectedProvider, getWalletExecutionCapabilities, isUnsupportedEvmTransactionSigningError, normalizeEvmTransactionSigningError, sessionStore, switchToFallbackFundingChain };
@@ -0,0 +1,11 @@
1
+ import { b as CubeSignerSession, h as SupportedChain, i as WalletProvider } from './cubeSignerAuth-DrPc9FeB.js';
2
+ export { C as CubeSignerAuth, a as CubeSignerConfig, O as OidcLoginHooks, T as TwitterCodeExchangeParams } from './cubeSignerAuth-DrPc9FeB.js';
3
+
4
+ interface CreateCubistEvmWalletProviderArgs {
5
+ session: CubeSignerSession;
6
+ address: string;
7
+ chain: SupportedChain;
8
+ }
9
+ declare const createCubistEvmWalletProvider: ({ session, address, chain, }: CreateCubistEvmWalletProviderArgs) => WalletProvider;
10
+
11
+ export { CubeSignerSession, createCubistEvmWalletProvider };