@tomo-inc/cubist-wallet-sdk 0.0.6 → 0.0.8

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,422 @@
1
+ import { CubeSignerClient as CubeSignerClient$1, SessionData } from '@cubist-labs/cubesigner-sdk';
2
+ export { SessionData } from '@cubist-labs/cubesigner-sdk';
3
+ import { TomoStage, CubeStage } from '@tomo-inc/wallet-utils';
4
+ import { TypedData } from '@tomo-inc/cubist-sig-sdk';
5
+
6
+ type MfaType = "fido" | "emailOtp" | "totp";
7
+ type SeedPhrase = any;
8
+ interface MfaInfo {
9
+ success?: boolean;
10
+ message?: string;
11
+ data?: any;
12
+ error?: string;
13
+ id: string;
14
+ name: string;
15
+ type: MfaType;
16
+ status: {
17
+ allowed_approvers: string[];
18
+ allowed_mfa_types: string[];
19
+ approved_by: any;
20
+ count: number;
21
+ num_auth_factors: 1;
22
+ };
23
+ created_at: number;
24
+ created_by: string;
25
+ expires_at: number;
26
+ provenance: string;
27
+ receipt: any;
28
+ related_ids: string[];
29
+ request: {
30
+ body: any;
31
+ method: "DELETE" | "POST" | "PUT" | "DELETE" | "GET";
32
+ path: string;
33
+ };
34
+ verifyStatus?: "pending" | "approved" | "rejected";
35
+ mfaRequired?: {
36
+ fido: boolean;
37
+ totp: boolean;
38
+ emailOtp: boolean | number;
39
+ emailOtpRemainTime: number;
40
+ } | null;
41
+ }
42
+ type BizType = "createSession" | "addFido" | "deleteFido" | "registerTotp" | "registerEmailOtp" | "deleteTotp" | "initExport" | "completeExport";
43
+ interface MfaReceipt {
44
+ mfaId: string;
45
+ mfaConf: string;
46
+ mfaOrgId: string;
47
+ }
48
+ type MfaRequest = any;
49
+ interface MfaAnswer {
50
+ totpCode?: string;
51
+ email?: string;
52
+ emailCode?: string;
53
+ }
54
+ interface MfaVerifyResult {
55
+ success: boolean;
56
+ receipt: any;
57
+ error?: any;
58
+ }
59
+ interface MfaFinishResult {
60
+ success: boolean;
61
+ error?: any;
62
+ }
63
+ type AccountType = "google" | "x" | "email";
64
+ interface CubeAccount {
65
+ userId: string;
66
+ name: string;
67
+ email: string;
68
+ otpEmail: string;
69
+ accountType: AccountType;
70
+ }
71
+ interface MfaConfig {
72
+ noMfa: boolean;
73
+ hasMfa: boolean;
74
+ account: CubeAccount;
75
+ emailOtp: {
76
+ data: string;
77
+ enabled: boolean;
78
+ };
79
+ fido: {
80
+ data: FidoKey[];
81
+ enabled: boolean;
82
+ };
83
+ totp: {
84
+ data: any;
85
+ enabled: boolean;
86
+ };
87
+ }
88
+ type OidcSessionResp = any;
89
+ type CubeSignerClient = any;
90
+ type ApiClient = any;
91
+ interface CubeUserInfo {
92
+ user_id: string;
93
+ mfa: FidoKey[];
94
+ name?: string;
95
+ email?: string;
96
+ org_ids?: string[];
97
+ orgs?: any[];
98
+ verified_email?: {
99
+ email?: string;
100
+ updated_at?: number;
101
+ };
102
+ }
103
+ interface TotpInfo {
104
+ id: string;
105
+ url: string;
106
+ secret: string;
107
+ issuer: string;
108
+ }
109
+ interface FidoKey {
110
+ type: string;
111
+ id: string;
112
+ name: string;
113
+ updated_at: string;
114
+ status: string;
115
+ user_id: string;
116
+ discoverable: boolean;
117
+ created_at: number;
118
+ last_used_at: number;
119
+ aaguid: string;
120
+ }
121
+ interface CubeIdentity {
122
+ id: string;
123
+ preferred_username?: string;
124
+ aud?: any;
125
+ email?: string;
126
+ identity?: {
127
+ iss: string;
128
+ sub: string;
129
+ };
130
+ user_info?: {
131
+ user_id?: string;
132
+ initialized?: boolean;
133
+ configured_mfa?: any[];
134
+ };
135
+ exp_epoch?: number;
136
+ }
137
+ interface SeedPhraseExportInfo {
138
+ ready: boolean;
139
+ keyId?: string;
140
+ lastTime?: number;
141
+ duration?: number;
142
+ valid_epoch?: number;
143
+ exp_epoch?: number;
144
+ }
145
+ interface CubeRes {
146
+ success: boolean;
147
+ error?: any;
148
+ data?: any;
149
+ message?: string;
150
+ }
151
+ interface Mfa {
152
+ created_at?: number;
153
+ created_by: string;
154
+ expires_at: number;
155
+ id: string;
156
+ not_valid_until?: number;
157
+ provenance: "EditPolicy" | "Key" | "Role" | "KeyInRole" | "User";
158
+ receipt?: {
159
+ confirmation: string;
160
+ final_approver: string;
161
+ timestamp: number;
162
+ };
163
+ related_ids?: string[];
164
+ request: {
165
+ body?: Record<string, unknown>;
166
+ method: string;
167
+ path: string;
168
+ };
169
+ status: {
170
+ allowed_approvers: string[];
171
+ allowed_mfa_types?: string[];
172
+ approved_by: {
173
+ [key: string]: object;
174
+ };
175
+ count: number;
176
+ num_auth_factors: number;
177
+ request_comparer?: "Eq" | {
178
+ EvmTx: {
179
+ grace?: number;
180
+ ignore_gas?: boolean;
181
+ ignore_nonce?: boolean;
182
+ };
183
+ } | {
184
+ SolanaTx: {
185
+ ignore_blockhash?: boolean;
186
+ };
187
+ };
188
+ };
189
+ }
190
+ interface UserToken {
191
+ accessToken: string;
192
+ refreshToken: string;
193
+ expireTime: number;
194
+ }
195
+ interface User {
196
+ userId: string;
197
+ userID?: string;
198
+ accountID?: string;
199
+ tenantID?: string;
200
+ username?: string;
201
+ nickname: string;
202
+ avatar: string;
203
+ freePasswordAuth?: string;
204
+ forbidden?: boolean;
205
+ deleted?: boolean;
206
+ }
207
+ interface UserAddressType {
208
+ bitcoinP2pkhAddress: string;
209
+ bitcoinP2trAddress: string;
210
+ bitcoinP2shAddress: string;
211
+ bitcoinP2wpkhAddress: string;
212
+ ethereumAddress: string;
213
+ solanaAddress: string;
214
+ tronAddress: string;
215
+ tonAddressTest: string;
216
+ tonAddress: string;
217
+ tonPublicKey: string;
218
+ suiAddress: string;
219
+ }
220
+ interface LoginRes {
221
+ userToken?: UserToken;
222
+ user: User;
223
+ accountBaseInfo: any;
224
+ accountWallet: any;
225
+ walletId?: string;
226
+ }
227
+ declare enum LoginError {
228
+ FIDO_NOT_ALLOWED = "NotAllowedError",
229
+ MFA_NOT_APPROVED = "MFA not approved yet",
230
+ MFA_REQUIRED = "MFA should not be required after approval",
231
+ OIDC_TOKEN_NOT_FOUND = "Oidc token not found",
232
+ CUBE_IDENTITY_NOT_FOUND = "Cube identity not found",
233
+ CUBE_USER_INFO_NOT_FOUND = "Cube user info not found",
234
+ OIDC_TOKEN_EXPIRED = "ExpiredSignature",
235
+ FAILED_OPEN_POPUP = "Failed to open popup window",
236
+ OAUTH_LOGIN_TIMEOUT = "OAuth login timeout",
237
+ USER_CANCELLED_LOGIN = "User cancelled login"
238
+ }
239
+ interface CubeConfig {
240
+ rpId?: string;
241
+ tomoStage: TomoStage;
242
+ cubeSalt?: string;
243
+ cubeStage?: CubeStage;
244
+ tomoClientId: string;
245
+ jwtToken?: string;
246
+ oidcToken?: string;
247
+ name?: string;
248
+ logo?: string;
249
+ }
250
+ interface CubeConnectResult {
251
+ walletId: string;
252
+ session: object;
253
+ accountWallet: Record<string, any>;
254
+ token: object;
255
+ user: Record<string, any>;
256
+ }
257
+
258
+ declare class CubeMfaService {
259
+ private static instance;
260
+ private cubeAccountService;
261
+ cubeSignerClient: CubeSignerClient$1 | null;
262
+ apiClient: ApiClient;
263
+ private mfaType;
264
+ private mfaAnswer;
265
+ private mfaChallenge;
266
+ private registerChallenge;
267
+ constructor();
268
+ static getInstance(): CubeMfaService;
269
+ init(cubeAccountService: CubeAccountService): this;
270
+ setMfaType(mfaType: MfaType): void;
271
+ setMfaAnswer(mfaAnswer: MfaAnswer): void;
272
+ getMfaInfo(bizType?: BizType): Promise<MfaInfo | null>;
273
+ answerRegister(code: string): Promise<CubeRes>;
274
+ executeBizWithMfa(bizType: BizType, mfaInfo?: MfaInfo | null): Promise<CubeRes>;
275
+ approvalMfa(mfaId: string): Promise<CubeRes>;
276
+ private getPasskeyConfig;
277
+ passkeyClear(): void;
278
+ addFido(fidoName: string, receipt?: MfaReceipt): Promise<any>;
279
+ addFidoLocal(fidoName: string, receipt?: MfaReceipt): Promise<MfaInfo | null | boolean>;
280
+ deleteFido(fidoId: string, receipt?: MfaReceipt): Promise<MfaInfo | null>;
281
+ approvalFido(mfaId: string): Promise<MfaReceipt>;
282
+ approvalFidoLocal(mfaId: string): Promise<MfaReceipt>;
283
+ registerTotp(issuer: string, receipt?: MfaReceipt): Promise<MfaInfo | TotpInfo | null>;
284
+ deleteTotp(receipt?: MfaReceipt): Promise<MfaInfo | null>;
285
+ approvalTotp(mfaId: string): Promise<MfaReceipt>;
286
+ registerEmailOtp(email: string, receipt?: MfaReceipt): Promise<MfaInfo | null>;
287
+ approvalEmailOtp(mfaId: string): Promise<MfaReceipt | null>;
288
+ sendEmailCode(mfaId: string): Promise<boolean>;
289
+ }
290
+
291
+ declare class CubeSignService {
292
+ private static instance;
293
+ private cubeSession;
294
+ private services;
295
+ init({ cubeSession }: {
296
+ cubeSession: any;
297
+ }): Promise<void>;
298
+ static getInstance(): CubeSignService;
299
+ /**
300
+ * Get specific services by chainType and address
301
+ * @param chainType Chain type (EVM, TRON, SOL, DOGE)
302
+ * @param address Wallet address
303
+ * @returns The matching services object or null if not found
304
+ */
305
+ getServiceByChainAndAddress(chainType: string, address: string): Promise<any>;
306
+ /**
307
+ * Build key ID from chainType and address following the pattern in the services data
308
+ * @param chainType Chain type
309
+ * @param address Wallet address
310
+ * @returns Key ID string
311
+ */
312
+ private buildKeyId;
313
+ /**
314
+ * Unified transaction signing method for all supported chains
315
+ * @param chainType Chain type (EVM, SOL, DOGE, TRON, BTC)
316
+ * @param address User's wallet address
317
+ * @param params Signing parameters specific to each chain (always JSON stringified from social account)
318
+ * @returns Signed transaction
319
+ */
320
+ signTransaction(chainType: string, address: string, params: any): Promise<string>;
321
+ /**
322
+ * Unified message signing method for all supported chains
323
+ * @param chainType Chain type (EVM, SOL, DOGE, TRON)
324
+ * @param address User's wallet address
325
+ * @param message Message to be signed
326
+ * @returns Message signature
327
+ */
328
+ signMessage(chainType: string, address: string, message: string): Promise<string>;
329
+ /**
330
+ * Unified typed data signing method (supports EVM and TRON)
331
+ * @param chainType Chain type (EVM, TRON)
332
+ * @param address User's wallet address
333
+ * @param typedData Typed data to be signed
334
+ * @returns Typed data signature
335
+ */
336
+ signTypedData(chainType: string, address: string, typedData: TypedData): Promise<string>;
337
+ }
338
+
339
+ declare class CubeAccountService {
340
+ config: CubeConfig;
341
+ private static instance;
342
+ private jwtToken;
343
+ accountData: any;
344
+ cubeUserInfo: CubeUserInfo | null;
345
+ cubeIdentity: CubeIdentity | null;
346
+ private cubeSession;
347
+ cubeSignerClient: CubeSignerClient$1 | null;
348
+ apiClient: ApiClient | null;
349
+ cubeMfaService: CubeMfaService | null;
350
+ cubeExportService: CubeExportService | null;
351
+ accountWallet: any;
352
+ cubeEnv: any;
353
+ cubeOrgId: string;
354
+ constructor(config: CubeConfig);
355
+ static getInstance(config?: CubeConfig): CubeAccountService;
356
+ getCubeIdentity(): Promise<CubeIdentity | null>;
357
+ loginOrRegister(oidcToken: string, options?: any): Promise<LoginRes>;
358
+ updateUserInfo(userInfo: {
359
+ nickname: string;
360
+ avatar: `https://${string}`;
361
+ }): Promise<boolean>;
362
+ createSessionByOidcToken(oidcToken: string): Promise<boolean>;
363
+ createSession(receipt?: MfaReceipt): Promise<MfaInfo | null | SessionData>;
364
+ refreshSession(): Promise<boolean>;
365
+ getCubeSession(): SessionData | null;
366
+ private setCubeSession;
367
+ sessionRevoke(): void;
368
+ private refreshCubeClient;
369
+ private createCubeSignerClient;
370
+ getOidcClient(receipt?: MfaReceipt): Promise<any>;
371
+ private autoLogin;
372
+ init(oidcToken?: string): Promise<boolean>;
373
+ initSubServices(): Promise<void>;
374
+ initCubeSignService(): Promise<CubeSignService>;
375
+ getCubeUserInfo(): Promise<CubeUserInfo | null>;
376
+ getMfaConfig(): Promise<MfaConfig>;
377
+ }
378
+
379
+ declare class CubeExportService {
380
+ private static instance;
381
+ private cubeAccountService;
382
+ private cubeSignerClient;
383
+ private seedPhraseKey;
384
+ private exportKey;
385
+ constructor();
386
+ static getInstance(): CubeExportService;
387
+ init(cubeAccountService: CubeAccountService): this;
388
+ getExportKey(): Promise<string>;
389
+ getExportInfo(): Promise<SeedPhraseExportInfo | null>;
390
+ initExport(receipt?: MfaReceipt): Promise<MfaInfo | null>;
391
+ completeExport(receipt?: MfaReceipt): Promise<MfaInfo | SeedPhrase | null>;
392
+ deleteExport(): Promise<CubeRes>;
393
+ }
394
+
395
+ declare const CubeConnect: (config: CubeConfig) => Promise<{
396
+ cubeAccount: CubeAccountService;
397
+ cubeMfa: CubeMfaService | null;
398
+ cubeExport: CubeExportService | null;
399
+ }>;
400
+
401
+ declare const SEED_PHRASE_EXPORT_DURATION = 48;
402
+ declare const EXPORT_TIME_FORMAT = "yyyy-MM-dd hh:mm:ss";
403
+ declare const OIDC_TOKEN_LIFETIME: number;
404
+ declare const CUBE_LIFETIME: {
405
+ auth: number;
406
+ refresh: number;
407
+ };
408
+ declare const CUBE_SCOPES: string[];
409
+ declare const EXPORT_KEY_PREFIX = "Key#Mnemonic_";
410
+ declare const ISS_MAP: Record<string, AccountType>;
411
+ declare const CUBE_SALTS: {
412
+ prod: string;
413
+ pre: string;
414
+ dev: string;
415
+ };
416
+ declare const getMfaInfoConfig: (cubeStage: CubeStage) => Record<BizType, {
417
+ method: string;
418
+ path: string;
419
+ _allowed_mfa_types: string[];
420
+ }>;
421
+
422
+ export { type AccountType, type ApiClient, type BizType, CUBE_LIFETIME, CUBE_SALTS, CUBE_SCOPES, type CubeAccount, CubeAccountService, type CubeConfig, CubeConnect, type CubeConnectResult, CubeExportService, type CubeIdentity, CubeMfaService, type CubeRes, CubeSignService, type CubeSignerClient, type CubeUserInfo, EXPORT_KEY_PREFIX, EXPORT_TIME_FORMAT, type FidoKey, ISS_MAP, LoginError, type LoginRes, type Mfa, type MfaAnswer, type MfaConfig, type MfaFinishResult, type MfaInfo, type MfaReceipt, type MfaRequest, type MfaType, type MfaVerifyResult, OIDC_TOKEN_LIFETIME, type OidcSessionResp, SEED_PHRASE_EXPORT_DURATION, type SeedPhrase, type SeedPhraseExportInfo, type TotpInfo, type User, type UserAddressType, type UserToken, getMfaInfoConfig };