@ab-org/sdk-core 0.1.0 → 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/README.md +29 -0
- package/dist/chunk-5HURLKIK.js +1005 -0
- package/dist/chunk-MVZIAM4H.js +363 -0
- package/dist/cubeSignerAuth-DrPc9FeB.d.ts +426 -0
- package/dist/index.d.ts +237 -16
- package/dist/index.js +1119 -16
- package/dist/social-auth.d.ts +11 -0
- package/dist/social-auth.js +1 -0
- package/dist/social-provider-Bq58TBRt.d.ts +88 -0
- package/dist/social-provider.d.ts +2 -0
- package/dist/social-provider.js +2 -0
- package/dist/social.d.ts +3 -0
- package/dist/social.js +2 -0
- package/package.json +24 -6
- package/dist/core/capabilities.d.ts +0 -32
- package/dist/core/capabilities.js +0 -88
- package/dist/core/chains.d.ts +0 -23
- package/dist/core/chains.js +0 -83
- package/dist/core/errors.d.ts +0 -9
- package/dist/core/errors.js +0 -51
- package/dist/core/sessionStore.d.ts +0 -26
- package/dist/core/sessionStore.js +0 -129
- package/dist/core/types.d.ts +0 -75
- package/dist/core/types.js +0 -1
- package/dist/core/walletConnector.d.ts +0 -29
- package/dist/core/walletConnector.js +0 -153
- package/dist/core/walletExecution.d.ts +0 -22
- package/dist/core/walletExecution.js +0 -89
- package/dist/hooks/useAccount.d.ts +0 -11
- package/dist/hooks/useAccount.js +0 -32
- package/dist/hooks/useWalletConnect.d.ts +0 -16
- package/dist/hooks/useWalletConnect.js +0 -24
- package/dist/providers/base.d.ts +0 -15
- package/dist/providers/base.js +0 -30
- package/dist/providers/plugin/injectedEvmProvider.d.ts +0 -112
- package/dist/providers/plugin/injectedEvmProvider.js +0 -352
- package/dist/providers/plugin/injectedWalletRegistry.d.ts +0 -9
- package/dist/providers/plugin/injectedWalletRegistry.js +0 -34
- package/dist/providers/plugin/metamaskProvider.d.ts +0 -1
- package/dist/providers/plugin/metamaskProvider.js +0 -1
- package/dist/providers/social/baseSocialProvider.d.ts +0 -21
- package/dist/providers/social/baseSocialProvider.js +0 -11
- package/dist/providers/social/cubeSignerAuth.d.ts +0 -89
- package/dist/providers/social/cubeSignerAuth.js +0 -128
- package/dist/providers/social/cubistEvmWalletProvider.d.ts +0 -9
- package/dist/providers/social/cubistEvmWalletProvider.js +0 -175
- package/dist/providers/social/cubistProvider.d.ts +0 -52
- package/dist/providers/social/cubistProvider.js +0 -160
|
@@ -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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,237 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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-DrPc9FeB.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, 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-DrPc9FeB.js';
|
|
3
|
+
import EventEmitter from 'eventemitter3';
|
|
4
|
+
import { d as AbstractProvider } from './social-provider-Bq58TBRt.js';
|
|
5
|
+
export { A as AbstractSocialProvider, C as CubistLoginMethod, a as CubistSessionAdapter, b as CubistSocialProvider, S as SocialConnectArgs, c as SocialLoginOptions } from './social-provider-Bq58TBRt.js';
|
|
6
|
+
|
|
7
|
+
declare const EVM_TRANSACTION_SIGNING_UNSUPPORTED = "EVM_TRANSACTION_SIGNING_UNSUPPORTED";
|
|
8
|
+
declare class EvmTransactionSigningUnsupportedError extends Error {
|
|
9
|
+
readonly providerName: string;
|
|
10
|
+
readonly cause?: unknown | undefined;
|
|
11
|
+
readonly code = "EVM_TRANSACTION_SIGNING_UNSUPPORTED";
|
|
12
|
+
constructor(providerName: string, cause?: unknown | undefined);
|
|
13
|
+
}
|
|
14
|
+
declare const isUnsupportedEvmTransactionSigningError: (error: unknown) => boolean;
|
|
15
|
+
declare const normalizeEvmTransactionSigningError: (providerName: string, error: unknown) => Error;
|
|
16
|
+
|
|
17
|
+
type WalletEvents = {
|
|
18
|
+
"session:changed": [WalletSession | null];
|
|
19
|
+
"session:rehydrated": [WalletSession];
|
|
20
|
+
"session:expired": [WalletSession];
|
|
21
|
+
"session:revoked": [WalletSession];
|
|
22
|
+
"balance:changed": [BalanceInfo | null];
|
|
23
|
+
"connecting:changed": [boolean];
|
|
24
|
+
};
|
|
25
|
+
declare class SessionStore {
|
|
26
|
+
private state;
|
|
27
|
+
private emitter;
|
|
28
|
+
constructor();
|
|
29
|
+
getState(): WalletState;
|
|
30
|
+
setConnecting(flag: boolean): void;
|
|
31
|
+
setSession(session: WalletSession | null): void;
|
|
32
|
+
rehydrateSession(session: WalletSession): void;
|
|
33
|
+
clearSession(): void;
|
|
34
|
+
expireSession(): void;
|
|
35
|
+
revokeSession(): void;
|
|
36
|
+
setBalance(balance: BalanceInfo | null): void;
|
|
37
|
+
on<T extends keyof WalletEvents>(event: T, listener: (...args: WalletEvents[T]) => void): () => EventEmitter<WalletEvents, any>;
|
|
38
|
+
private tryRehydrate;
|
|
39
|
+
}
|
|
40
|
+
declare const sessionStore: SessionStore;
|
|
41
|
+
|
|
42
|
+
declare class WalletConnector {
|
|
43
|
+
private adapters;
|
|
44
|
+
private currentAdapterId;
|
|
45
|
+
constructor(adapters: WalletAdapter[]);
|
|
46
|
+
private getAdapterById;
|
|
47
|
+
private getCurrentAdapter;
|
|
48
|
+
private clearActiveSession;
|
|
49
|
+
private requireActiveSession;
|
|
50
|
+
connect(adapterId: string, args?: WalletConnectArgs): Promise<WalletSession>;
|
|
51
|
+
disconnect(): Promise<void>;
|
|
52
|
+
rehydrateSession(adapterId: string, session: WalletSession): WalletSession;
|
|
53
|
+
/**
|
|
54
|
+
* Attempt to silently reconnect a wallet whose session was rehydrated
|
|
55
|
+
* from localStorage. Uses the adapter's `reconnect()` if available,
|
|
56
|
+
* falling back to `connect()` for backward compatibility.
|
|
57
|
+
*
|
|
58
|
+
* Returns the restored session on success, or `null` if reconnection
|
|
59
|
+
* is not possible (e.g. wallet extension removed, social session expired).
|
|
60
|
+
*/
|
|
61
|
+
tryAutoReconnect(): Promise<WalletSession | null>;
|
|
62
|
+
supportsCapability(capability: WalletCapability): boolean;
|
|
63
|
+
requestCurrentProvider<T = unknown>(payload: WalletProviderRequest): Promise<T>;
|
|
64
|
+
sendEvmTransaction(transaction: EvmTransactionRequest): Promise<string>;
|
|
65
|
+
signEvmTransaction(transaction: EvmTransactionRequest): Promise<string>;
|
|
66
|
+
signMessage(message: string): Promise<string>;
|
|
67
|
+
signTypedData(typedData: Record<string, unknown>): Promise<string>;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
interface WalletExecutionClient {
|
|
71
|
+
readonly session: WalletSession;
|
|
72
|
+
readonly capabilities: WalletCapability[];
|
|
73
|
+
supports(capability: WalletCapability): boolean;
|
|
74
|
+
sendTransaction(transaction: EvmTransactionRequest, check?: Omit<SessionCapabilityCheck, "capability">): Promise<string>;
|
|
75
|
+
signTransaction(transaction: EvmTransactionRequest, check?: Omit<SessionCapabilityCheck, "capability">): Promise<string>;
|
|
76
|
+
signMessage(message: string, check?: Omit<SessionCapabilityCheck, "capability">): Promise<string>;
|
|
77
|
+
signTypedData(typedData: Record<string, unknown>, check?: Omit<SessionCapabilityCheck, "capability">): Promise<string>;
|
|
78
|
+
}
|
|
79
|
+
declare const getWalletExecutionCapabilities: (session?: WalletSession | null) => WalletCapability[];
|
|
80
|
+
declare const createWalletExecutionClient: (session?: WalletSession | null) => WalletExecutionClient;
|
|
81
|
+
declare const createWalletExecutionController: () => {
|
|
82
|
+
readonly session: WalletSession | null;
|
|
83
|
+
readonly capabilities: string[];
|
|
84
|
+
supports(capability: WalletCapability): boolean;
|
|
85
|
+
sendTransaction(transaction: EvmTransactionRequest, check?: Omit<SessionCapabilityCheck, "capability">): Promise<string>;
|
|
86
|
+
signTransaction(transaction: EvmTransactionRequest, check?: Omit<SessionCapabilityCheck, "capability">): Promise<string>;
|
|
87
|
+
signMessage(message: string, check?: Omit<SessionCapabilityCheck, "capability">): Promise<string>;
|
|
88
|
+
signTypedData(typedData: Record<string, unknown>, check?: Omit<SessionCapabilityCheck, "capability">): Promise<string>;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
interface WalletConnectControllerOptions {
|
|
92
|
+
connector: WalletConnector;
|
|
93
|
+
defaultAdapterId?: string;
|
|
94
|
+
}
|
|
95
|
+
declare const createWalletConnectController: ({ connector, defaultAdapterId, }: WalletConnectControllerOptions) => {
|
|
96
|
+
readonly openModal: (adapterId?: string | undefined, args?: WalletConnectArgs) => Promise<void>;
|
|
97
|
+
readonly disconnect: () => Promise<void>;
|
|
98
|
+
readonly rehydrate: (adapterId: string, session: WalletSession) => WalletSession;
|
|
99
|
+
readonly tryAutoReconnect: () => Promise<WalletSession | null>;
|
|
100
|
+
readonly supports: (capability: WalletCapability) => boolean;
|
|
101
|
+
readonly isConnected: boolean;
|
|
102
|
+
readonly isConnecting: boolean;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
declare const createAccountController: () => {
|
|
106
|
+
readonly session: WalletSession | null;
|
|
107
|
+
readonly address: string | null;
|
|
108
|
+
readonly chain: SupportedChain | null;
|
|
109
|
+
readonly balance: BalanceInfo | null;
|
|
110
|
+
readonly isConnected: boolean;
|
|
111
|
+
readonly currentProvider: WalletProvider | null;
|
|
112
|
+
readonly chainContext: ChainContext | null;
|
|
113
|
+
readonly capabilities: string[];
|
|
114
|
+
readonly capabilityPolicy: SessionCapabilityPolicy | null;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
interface InjectedEthereumProvider extends WalletProvider {
|
|
118
|
+
request<T = unknown>(args: {
|
|
119
|
+
method: string;
|
|
120
|
+
params?: unknown[];
|
|
121
|
+
}): Promise<T>;
|
|
122
|
+
providers?: InjectedEthereumProvider[];
|
|
123
|
+
isMetaMask?: boolean;
|
|
124
|
+
isCoinbaseWallet?: boolean;
|
|
125
|
+
isTrust?: boolean;
|
|
126
|
+
isTrustWallet?: boolean;
|
|
127
|
+
isPhantom?: boolean;
|
|
128
|
+
isRabby?: boolean;
|
|
129
|
+
isOkxWallet?: boolean;
|
|
130
|
+
isBitKeep?: boolean;
|
|
131
|
+
isRainbow?: boolean;
|
|
132
|
+
isZerion?: boolean;
|
|
133
|
+
isBraveWallet?: boolean;
|
|
134
|
+
isBitget?: boolean;
|
|
135
|
+
}
|
|
136
|
+
interface EIP6963ProviderInfo {
|
|
137
|
+
uuid: string;
|
|
138
|
+
name: string;
|
|
139
|
+
icon: string;
|
|
140
|
+
rdns: string;
|
|
141
|
+
}
|
|
142
|
+
interface EIP6963ProviderDetail {
|
|
143
|
+
info: EIP6963ProviderInfo;
|
|
144
|
+
provider: InjectedEthereumProvider;
|
|
145
|
+
}
|
|
146
|
+
declare global {
|
|
147
|
+
interface Window {
|
|
148
|
+
ethereum?: InjectedEthereumProvider;
|
|
149
|
+
okxwallet?: InjectedEthereumProvider | {
|
|
150
|
+
ethereum?: InjectedEthereumProvider;
|
|
151
|
+
};
|
|
152
|
+
coinbaseWalletExtension?: InjectedEthereumProvider;
|
|
153
|
+
trustwallet?: InjectedEthereumProvider | {
|
|
154
|
+
ethereum?: InjectedEthereumProvider;
|
|
155
|
+
};
|
|
156
|
+
phantom?: {
|
|
157
|
+
ethereum?: InjectedEthereumProvider;
|
|
158
|
+
};
|
|
159
|
+
rabby?: InjectedEthereumProvider;
|
|
160
|
+
bitkeep?: InjectedEthereumProvider | {
|
|
161
|
+
ethereum?: InjectedEthereumProvider;
|
|
162
|
+
};
|
|
163
|
+
rainbow?: {
|
|
164
|
+
ethereum?: InjectedEthereumProvider;
|
|
165
|
+
};
|
|
166
|
+
zerionWallet?: InjectedEthereumProvider;
|
|
167
|
+
bitget?: InjectedEthereumProvider | {
|
|
168
|
+
ethereum?: InjectedEthereumProvider;
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
declare function discoverEIP6963Providers(): EIP6963ProviderDetail[];
|
|
173
|
+
declare function findInjectedProvider(predicate: (provider: InjectedEthereumProvider) => boolean): InjectedEthereumProvider | undefined;
|
|
174
|
+
declare function findEIP6963Provider(predicate: (detail: EIP6963ProviderDetail) => boolean): InjectedEthereumProvider | undefined;
|
|
175
|
+
interface InjectedWalletConfig {
|
|
176
|
+
id: string;
|
|
177
|
+
title: string;
|
|
178
|
+
resolveProvider: () => InjectedEthereumProvider | undefined;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Force wallet to the default funding chain (e.g. 3131). If the chain is missing (4902), add it then switch.
|
|
182
|
+
* Call after external wallet connect so subsequent business runs on the configured funding network.
|
|
183
|
+
*/
|
|
184
|
+
declare function switchToFallbackFundingChain(provider: InjectedEthereumProvider): Promise<void>;
|
|
185
|
+
declare class InjectedEvmProvider extends AbstractProvider {
|
|
186
|
+
private config;
|
|
187
|
+
private injected?;
|
|
188
|
+
readonly id: string;
|
|
189
|
+
readonly title: string;
|
|
190
|
+
readonly category: "plugin";
|
|
191
|
+
constructor(config: InjectedWalletConfig, injected?: InjectedEthereumProvider | undefined);
|
|
192
|
+
isAvailable(): boolean;
|
|
193
|
+
protected get client(): InjectedEthereumProvider;
|
|
194
|
+
connect(_args?: WalletConnectArgs): Promise<WalletSession>;
|
|
195
|
+
reconnect(_persistedSession: WalletSession): Promise<WalletSession | null>;
|
|
196
|
+
}
|
|
197
|
+
declare class MetaMaskProvider extends InjectedEvmProvider {
|
|
198
|
+
constructor(injected?: InjectedEthereumProvider);
|
|
199
|
+
}
|
|
200
|
+
declare class OKXProvider extends InjectedEvmProvider {
|
|
201
|
+
constructor(injected?: InjectedEthereumProvider);
|
|
202
|
+
}
|
|
203
|
+
declare class CoinbaseWalletProvider extends InjectedEvmProvider {
|
|
204
|
+
constructor(injected?: InjectedEthereumProvider);
|
|
205
|
+
}
|
|
206
|
+
declare class TrustWalletProvider extends InjectedEvmProvider {
|
|
207
|
+
constructor(injected?: InjectedEthereumProvider);
|
|
208
|
+
}
|
|
209
|
+
declare class PhantomProvider extends InjectedEvmProvider {
|
|
210
|
+
constructor(injected?: InjectedEthereumProvider);
|
|
211
|
+
}
|
|
212
|
+
declare class RabbyProvider extends InjectedEvmProvider {
|
|
213
|
+
constructor(injected?: InjectedEthereumProvider);
|
|
214
|
+
}
|
|
215
|
+
declare class RainbowProvider extends InjectedEvmProvider {
|
|
216
|
+
constructor(injected?: InjectedEthereumProvider);
|
|
217
|
+
}
|
|
218
|
+
declare class ZerionProvider extends InjectedEvmProvider {
|
|
219
|
+
constructor(injected?: InjectedEthereumProvider);
|
|
220
|
+
}
|
|
221
|
+
declare class BraveWalletProvider extends InjectedEvmProvider {
|
|
222
|
+
constructor(injected?: InjectedEthereumProvider);
|
|
223
|
+
}
|
|
224
|
+
declare class BitgetProvider extends InjectedEvmProvider {
|
|
225
|
+
constructor(injected?: InjectedEthereumProvider);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
interface InjectedWalletRegistryItem {
|
|
229
|
+
id: string;
|
|
230
|
+
title: string;
|
|
231
|
+
installUrl?: string;
|
|
232
|
+
provider: InjectedEvmProvider;
|
|
233
|
+
installed: boolean;
|
|
234
|
+
}
|
|
235
|
+
declare function createDefaultInjectedWalletRegistry(): InjectedWalletRegistryItem[];
|
|
236
|
+
|
|
237
|
+
export { AbstractProvider, BalanceInfo, BitgetProvider, BraveWalletProvider, ChainContext, CoinbaseWalletProvider, type EIP6963ProviderDetail, type EIP6963ProviderInfo, EVM_TRANSACTION_SIGNING_UNSUPPORTED, EvmTransactionRequest, EvmTransactionSigningUnsupportedError, type InjectedEthereumProvider, InjectedEvmProvider, type InjectedWalletConfig, type InjectedWalletRegistryItem, MetaMaskProvider, OKXProvider, PhantomProvider, RabbyProvider, RainbowProvider, SessionCapabilityCheck, SessionCapabilityPolicy, SessionStore, SupportedChain, TrustWalletProvider, WalletAdapter, WalletCapability, WalletConnectArgs, type WalletConnectControllerOptions, WalletConnector, type WalletEvents, type WalletExecutionClient, WalletProvider, WalletProviderRequest, WalletSession, WalletState, ZerionProvider, createAccountController, createDefaultInjectedWalletRegistry, createWalletConnectController, createWalletExecutionClient, createWalletExecutionController, discoverEIP6963Providers, findEIP6963Provider, findInjectedProvider, getWalletExecutionCapabilities, isUnsupportedEvmTransactionSigningError, normalizeEvmTransactionSigningError, sessionStore, switchToFallbackFundingChain };
|