@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.
@@ -0,0 +1,426 @@
1
+ type WalletCapability = "eth_accounts" | "eth_requestAccounts" | "eth_chainId" | "eth_signTransaction" | "eth_sendTransaction" | "personal_sign" | "eth_signTypedData_v4" | "wallet_disconnect" | "wallet_rehydrate" | string;
2
+ interface SessionCapabilityPolicy {
3
+ id: string;
4
+ appId?: string;
5
+ origin?: string;
6
+ expiresAt?: number;
7
+ methods?: WalletCapability[];
8
+ chains?: SupportedChain[];
9
+ tokens?: SupportedToken[];
10
+ maxAmount?: string;
11
+ revocable?: boolean;
12
+ metadata?: Record<string, unknown>;
13
+ }
14
+ interface SessionCapabilityCheck {
15
+ capability: WalletCapability;
16
+ chain?: SupportedChain;
17
+ token?: SupportedToken;
18
+ amount?: string | number | bigint;
19
+ appId?: string;
20
+ origin?: string;
21
+ now?: number;
22
+ }
23
+ declare class SessionCapabilityError extends Error {
24
+ constructor(message: string);
25
+ }
26
+ declare const createSessionCapabilityPolicy: (input?: Partial<SessionCapabilityPolicy>) => SessionCapabilityPolicy;
27
+ declare const isSessionExpired: (session: Pick<WalletSession, "expiresAt"> | null | undefined, now?: number) => boolean;
28
+ declare const isCapabilityPolicyExpired: (policy: SessionCapabilityPolicy | null | undefined, now?: number) => boolean;
29
+ declare const sessionSupportsCapability: (session: Pick<WalletSession, "capabilities"> | null | undefined, capability: WalletCapability) => boolean;
30
+ declare const describeSessionCapabilityPolicy: (policy: SessionCapabilityPolicy | null | undefined) => string[];
31
+ declare const assertSessionCapability: (session: WalletSession, check: SessionCapabilityCheck) => void;
32
+
33
+ type ChainNamespace = "evm" | "solana" | "ab-core";
34
+ type ChainRpcFamily = "evm" | "solana" | "custom";
35
+ interface ChainDescriptor {
36
+ chain: SupportedChain;
37
+ namespace: ChainNamespace;
38
+ reference: string;
39
+ label: string;
40
+ rpcFamily: ChainRpcFamily;
41
+ evmChainId?: number;
42
+ supportsSmartSessions: boolean;
43
+ supportsAccountAbstraction: boolean;
44
+ }
45
+ interface ChainContext {
46
+ walletChain: SupportedChain;
47
+ walletChainDescriptor: ChainDescriptor;
48
+ settlementChain: SupportedChain;
49
+ settlementChainDescriptor: ChainDescriptor;
50
+ }
51
+ declare const getChainDescriptor: (chain: SupportedChain) => ChainDescriptor;
52
+ declare const getAllChainDescriptors: () => ChainDescriptor[];
53
+ declare const getSupportedChainFromEvmChainId: (value: string | number | bigint) => SupportedChain;
54
+ declare const createChainContext: (walletChain: SupportedChain, settlementChain?: SupportedChain) => ChainContext;
55
+
56
+ type SupportedChain = "AB_CORE" | "ETH" | "BSC" | "SOL" | "ETH_TENDERLY" | "BSC_TENDERLY";
57
+ type SupportedToken = "USD1" | "USDC" | "USDT" | "ETH" | "AB";
58
+ type ProviderCategory = "plugin" | "social";
59
+ type WalletType = "injected" | "social" | "smart";
60
+ type WalletAuthSource = "google" | "twitter" | "wallet" | "session";
61
+ type EvmQuantity = string | number | bigint;
62
+ interface EvmAccessListItem {
63
+ address: string;
64
+ storageKeys?: string[];
65
+ }
66
+ interface EvmTransactionRequest {
67
+ from?: string;
68
+ to?: string;
69
+ data?: string;
70
+ gas?: EvmQuantity;
71
+ gasPrice?: EvmQuantity;
72
+ maxFeePerGas?: EvmQuantity;
73
+ maxPriorityFeePerGas?: EvmQuantity;
74
+ nonce?: EvmQuantity;
75
+ value?: EvmQuantity;
76
+ type?: EvmQuantity;
77
+ chainId?: EvmQuantity;
78
+ accessList?: EvmAccessListItem[];
79
+ }
80
+ interface WalletProviderRequest {
81
+ method: string;
82
+ params?: unknown[];
83
+ }
84
+ interface WalletProvider {
85
+ request<T = unknown>(payload: WalletProviderRequest): Promise<T>;
86
+ disconnect(): Promise<void>;
87
+ }
88
+ interface WalletConnectArgs {
89
+ options?: unknown;
90
+ payload?: unknown;
91
+ }
92
+ interface WalletAdapter {
93
+ id: string;
94
+ title: string;
95
+ icon?: string;
96
+ category?: ProviderCategory;
97
+ connect(args?: WalletConnectArgs): Promise<WalletSession>;
98
+ disconnect(): Promise<void>;
99
+ getProvider(): WalletProvider | null;
100
+ /**
101
+ * Silently restore a wallet session from persisted data without user interaction.
102
+ * Returns a fresh session if the wallet can be reconnected, or null otherwise.
103
+ */
104
+ reconnect?(persistedSession: WalletSession): Promise<WalletSession | null>;
105
+ }
106
+ interface WalletSession {
107
+ address: string;
108
+ chain: SupportedChain;
109
+ provider: WalletProvider;
110
+ walletType?: WalletType;
111
+ authSource?: WalletAuthSource;
112
+ sessionId?: string;
113
+ expiresAt?: number;
114
+ capabilities?: WalletCapability[];
115
+ sessionData?: unknown;
116
+ chainContext?: ChainContext;
117
+ capabilityPolicy?: SessionCapabilityPolicy;
118
+ }
119
+ interface BalanceInfo {
120
+ formatted: string;
121
+ symbol: SupportedToken;
122
+ wei: bigint;
123
+ }
124
+ interface WalletState {
125
+ session: WalletSession | null;
126
+ balance: BalanceInfo | null;
127
+ isConnecting: boolean;
128
+ }
129
+
130
+ type Environment = "prod" | "gamma" | "beta";
131
+ interface EnvInterface {
132
+ Region?: string;
133
+ SignerApiRoot: string;
134
+ OrgEventsTopicArn: string;
135
+ }
136
+ type Scope = string;
137
+ type MfaVote = "approve" | "reject";
138
+ interface RatchetConfig {
139
+ session?: number;
140
+ auth?: number;
141
+ refresh?: number;
142
+ grace?: number;
143
+ }
144
+ interface ClientSessionInfo {
145
+ session_id: string;
146
+ epoch: number;
147
+ epoch_token: string;
148
+ auth_token_exp: number;
149
+ refresh_token_exp: number;
150
+ refresh_token?: string;
151
+ auth_token?: string;
152
+ [key: string]: unknown;
153
+ }
154
+ interface SessionData {
155
+ org_id: string;
156
+ role_id?: string | null;
157
+ purpose?: string | null;
158
+ token: string;
159
+ refresh_token: string;
160
+ session_info: ClientSessionInfo;
161
+ session_exp: number | null | undefined;
162
+ env: Record<string, EnvInterface>;
163
+ }
164
+ interface SessionMetadata {
165
+ env: Record<string, EnvInterface>;
166
+ org_id: string;
167
+ role_id?: string | null;
168
+ purpose?: string | null;
169
+ session_exp: number | null | undefined;
170
+ session_id: string;
171
+ epoch: number;
172
+ }
173
+ interface SessionManager {
174
+ onInvalidToken?: () => void;
175
+ metadata(): Promise<SessionMetadata>;
176
+ token(): Promise<string>;
177
+ retrieve?(): Promise<SessionData>;
178
+ store?(data: SessionData): Promise<void>;
179
+ }
180
+ interface IdentityProof {
181
+ user_info?: {
182
+ initialized?: boolean;
183
+ [key: string]: unknown;
184
+ };
185
+ [key: string]: unknown;
186
+ }
187
+ interface KeyInfo {
188
+ key_id: string;
189
+ material_id: string;
190
+ public_key: string;
191
+ key_type: string;
192
+ [key: string]: unknown;
193
+ }
194
+ interface EvmSignRequest {
195
+ chain_id: number;
196
+ tx: Record<string, unknown>;
197
+ }
198
+ interface EvmSignResponse {
199
+ rlp_signed_tx: string;
200
+ [key: string]: unknown;
201
+ }
202
+ interface Eip191SignRequest {
203
+ data: string;
204
+ metadata?: unknown;
205
+ }
206
+ interface Eip712SignRequest {
207
+ chain_id: number;
208
+ typed_data: Record<string, unknown>;
209
+ metadata?: unknown;
210
+ }
211
+ interface Eip191Or712SignResponse {
212
+ signature: string;
213
+ [key: string]: unknown;
214
+ }
215
+ interface MfaIdAndConf {
216
+ id: string;
217
+ confirmation: string;
218
+ }
219
+ interface ManyMfaReceipts {
220
+ orgId: string;
221
+ receipts: MfaIdAndConf[];
222
+ }
223
+ interface SingleMfaReceipt {
224
+ mfaId: string;
225
+ mfaOrgId: string;
226
+ mfaConf: string;
227
+ }
228
+ type MfaReceipts = ManyMfaReceipts | SingleMfaReceipt;
229
+ interface MfaRequestInfo {
230
+ id: string;
231
+ org_id?: string;
232
+ receipt?: {
233
+ confirmation?: string;
234
+ [key: string]: unknown;
235
+ } | null;
236
+ request: {
237
+ path: string;
238
+ body?: unknown;
239
+ [key: string]: unknown;
240
+ };
241
+ [key: string]: unknown;
242
+ }
243
+ interface AcceptedMfaSession {
244
+ token: string;
245
+ refresh_token: string;
246
+ expiration: number | null | undefined;
247
+ session_info: ClientSessionInfo;
248
+ }
249
+ interface AcceptedMfaRequired {
250
+ id?: string;
251
+ ids?: string[];
252
+ org_id: string;
253
+ session?: AcceptedMfaSession;
254
+ }
255
+ interface AcceptedResponse {
256
+ accepted?: {
257
+ MfaRequired?: AcceptedMfaRequired;
258
+ [key: string]: unknown;
259
+ };
260
+ [key: string]: unknown;
261
+ }
262
+ type Response<U> = U | AcceptedResponse;
263
+ type RequestFn<U> = (headers?: HeadersInit) => Promise<Response<U>>;
264
+ declare class CubistApiClient {
265
+ #private;
266
+ constructor(sessionManager: SessionManager, sessionMeta: SessionMetadata, targetOrgId?: string);
267
+ get env(): EnvInterface;
268
+ get orgId(): string;
269
+ get sessionMeta(): SessionMetadata;
270
+ withOrg(orgId: string): CubistApiClient;
271
+ sessionKeysList(): Promise<KeyInfo[]>;
272
+ keyGetByMaterialId(keyType: string, materialId: string): Promise<KeyInfo>;
273
+ sessionRevoke(sessionId?: string): Promise<void>;
274
+ mfaGet(mfaId: string): Promise<MfaRequestInfo>;
275
+ mfaVoteCs(mfaId: string, mfaVote: MfaVote): Promise<MfaRequestInfo>;
276
+ signEvm(key: Key | string, req: EvmSignRequest, mfaReceipt?: MfaReceipts): Promise<CubeSignerResponse<EvmSignResponse>>;
277
+ signEip191(key: Key | string, req: Eip191SignRequest, mfaReceipt?: MfaReceipts): Promise<CubeSignerResponse<Eip191Or712SignResponse>>;
278
+ signEip712(key: Key | string, req: Eip712SignRequest, mfaReceipt?: MfaReceipts): Promise<CubeSignerResponse<Eip191Or712SignResponse>>;
279
+ }
280
+ declare class Key {
281
+ #private;
282
+ readonly id: string;
283
+ readonly materialId: string;
284
+ readonly publicKey: string;
285
+ cached: KeyInfo;
286
+ constructor(client: CubeSignerClient | CubistApiClient, data: KeyInfo);
287
+ signEvm(req: EvmSignRequest, mfaReceipt?: MfaReceipts): Promise<CubeSignerResponse<EvmSignResponse>>;
288
+ signEip191(req: Eip191SignRequest, mfaReceipt?: MfaReceipts): Promise<CubeSignerResponse<Eip191Or712SignResponse>>;
289
+ signEip712(req: Eip712SignRequest, mfaReceipt?: MfaReceipts): Promise<CubeSignerResponse<Eip191Or712SignResponse>>;
290
+ }
291
+ declare class MfaRequest {
292
+ #private;
293
+ constructor(apiClient: CubistApiClient, data: string | MfaRequestInfo);
294
+ get id(): string;
295
+ fetch(): Promise<MfaRequestInfo>;
296
+ receipt(): Promise<SingleMfaReceipt | undefined>;
297
+ approve(): Promise<MfaRequest>;
298
+ }
299
+ declare class OrgClient {
300
+ #private;
301
+ constructor(apiClient: CubistApiClient);
302
+ get id(): string;
303
+ getMfaRequest(mfaId: string): MfaRequest;
304
+ }
305
+ declare class CubeSignerResponse<U> {
306
+ #private;
307
+ protected constructor(env: EnvInterface, requestFn: RequestFn<U>, resp: Response<U>);
308
+ static create<U>(env: EnvInterface, requestFn: RequestFn<U>, mfaReceipt?: MfaReceipts): Promise<CubeSignerResponse<U>>;
309
+ mfaId(): string | undefined;
310
+ mfaIds(): string[];
311
+ requiresMfa(): boolean;
312
+ mfaClient(): Promise<CubeSignerClient | undefined>;
313
+ data(): U;
314
+ approve(client: CubeSignerClient): Promise<CubeSignerResponse<U>>;
315
+ execWithMfaApproval(mfaReceipt: MfaReceipts): Promise<CubeSignerResponse<U>>;
316
+ }
317
+ declare class CubeSignerClient {
318
+ #private;
319
+ constructor(apiClient: CubistApiClient);
320
+ get apiClient(): CubistApiClient;
321
+ get env(): EnvInterface;
322
+ get orgId(): string;
323
+ static create(session: string | SessionData | SessionManager, targetOrgId?: string): Promise<CubeSignerClient>;
324
+ static createOidcSession(env: EnvInterface, orgId: string, token: string, scopes: Array<Scope>, lifetimes?: RatchetConfig, mfaReceipt?: MfaReceipts, purpose?: string): Promise<CubeSignerResponse<SessionData>>;
325
+ static proveOidcIdentity(env: EnvInterface, orgId: string, token: string): Promise<IdentityProof>;
326
+ org(): OrgClient;
327
+ getOrg(orgId: string): OrgClient;
328
+ sessionKeys(): Promise<Key[]>;
329
+ getKeyByMaterialId(keyType: string, materialId: string): Promise<Key>;
330
+ revokeSession(): Promise<void>;
331
+ }
332
+
333
+ /**
334
+ * Hook for OIDC login when user does not yet exist in CubeSigner.
335
+ * Before creating a session, we call CubeSigner SDK's proof (proveOidcIdentity) to check
336
+ * if the user exists. If proof fails (e.g. user not registered), this is invoked so the
337
+ * caller can register the user on their backend; then login proceeds.
338
+ */
339
+ interface OidcLoginHooks {
340
+ /**
341
+ * Register the user on your backend when CubeSigner proof indicates the user does not exist.
342
+ * Called with the same OIDC token; after this resolves, OIDC session creation continues.
343
+ */
344
+ registerUser(oidcToken: string): Promise<void>;
345
+ }
346
+ interface CubeSignerConfig {
347
+ /** CubeSigner environment name or custom env object. */
348
+ env: Environment | EnvInterface;
349
+ /** Organization ID. */
350
+ orgId: string;
351
+ /** Session scopes (default: `["sign:*", "manage:*"]`). */
352
+ scopes?: string[];
353
+ /** Optional capability policy applied to smart-wallet sessions created from this auth flow. */
354
+ defaultSessionPolicy?: Partial<SessionCapabilityPolicy>;
355
+ /**
356
+ * Optional OIDC login hook. When provided, OIDC login will call CubeSigner SDK's
357
+ * proveOidcIdentity first; if the user does not exist (proof fails), registerUser is
358
+ * called, then login proceeds. If omitted, login uses the OIDC token directly.
359
+ */
360
+ oidcLoginHooks?: OidcLoginHooks;
361
+ }
362
+ interface CubeSignerSession {
363
+ /** Authenticated CubeSigner client — use it for signing, key management, etc. */
364
+ client: CubeSignerClient;
365
+ /** Raw session data (can be persisted / refreshed). */
366
+ sessionData: SessionData;
367
+ }
368
+ interface TwitterCodeExchangeParams {
369
+ /** Authorization code from Twitter OAuth 2.0 PKCE flow. */
370
+ code: string;
371
+ /** PKCE code_verifier that was generated for the auth request. */
372
+ codeVerifier: string;
373
+ /** redirect_uri that was used in the authorization request. */
374
+ redirectUri: string;
375
+ }
376
+ declare class CubeSignerAuth {
377
+ private readonly env;
378
+ private readonly orgId;
379
+ private readonly scopes;
380
+ readonly defaultSessionPolicy?: Partial<SessionCapabilityPolicy>;
381
+ private readonly oidcLoginHooks?;
382
+ private _client;
383
+ private _sessionData;
384
+ constructor(config: CubeSignerConfig);
385
+ /** Currently authenticated client (null if not logged in). */
386
+ get client(): CubeSignerClient | null;
387
+ get currentSession(): CubeSignerSession | null;
388
+ /**
389
+ * Login with a Google ID token (JWT).
390
+ * The token is used directly as the OIDC credential.
391
+ */
392
+ loginWithGoogle(idToken: string): Promise<CubeSignerSession>;
393
+ /**
394
+ * Login with a generic OIDC ID token.
395
+ * Useful when the caller already finished the upstream provider flow.
396
+ */
397
+ loginWithOidcToken(idToken: string): Promise<CubeSignerSession>;
398
+ /**
399
+ * Login with a Twitter OAuth 2.0 authorization code.
400
+ *
401
+ * 1. Exchange the code for an OIDC `id_token` via CubeSigner's
402
+ * `/v0/org/{org_id}/oauth2/twitter` endpoint.
403
+ * 2. Create a CubeSigner session with that token.
404
+ */
405
+ loginWithTwitter(params: TwitterCodeExchangeParams): Promise<CubeSignerSession>;
406
+ signOut(): Promise<void>;
407
+ /**
408
+ * Restore a CubeSigner session from previously persisted SessionData.
409
+ * Useful for reconnecting after page reload without re-authentication.
410
+ */
411
+ restoreSession(sessionData: SessionData): Promise<CubeSignerSession>;
412
+ private authenticateWithOidcToken;
413
+ /**
414
+ * Exchange a Twitter authorization code for an OIDC id_token
415
+ * via CubeSigner's dedicated endpoint.
416
+ *
417
+ * `POST {SignerApiRoot}/v0/org/{org_id}/oauth2/twitter`
418
+ */
419
+ private exchangeTwitterCode;
420
+ /**
421
+ * Create a CubeSigner OIDC session from a generic OIDC id_token.
422
+ */
423
+ private createOidcSession;
424
+ }
425
+
426
+ 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 OidcLoginHooks as O, type ProviderCategory as P, type SessionCapabilityCheck as S, type TwitterCodeExchangeParams as T, 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 };