@tomo-inc/cubist-wallet-sdk 0.0.11 → 0.0.16

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.cjs CHANGED
@@ -421,8 +421,40 @@ var CubeMfaService = class _CubeMfaService {
421
421
  const verifyStatus = receipt !== null ? "approved" : "pending";
422
422
  return { ...mfaInfo, verifyStatus, mfaRequired };
423
423
  }
424
- async answerRegister(code) {
424
+ async answerRegister(code, challengeId) {
425
425
  const challenge = this.registerChallenge;
426
+ if (!challenge && challengeId) {
427
+ try {
428
+ if (this.apiClient && typeof this.apiClient.userTotpResetComplete === "function") {
429
+ const result = await this.apiClient.userTotpResetComplete(challengeId, code);
430
+ let receipt = null;
431
+ if (result) {
432
+ if (typeof result.data === "function") {
433
+ receipt = result.data();
434
+ } else if (result.data) {
435
+ receipt = result.data;
436
+ } else if (result.status === "ok" || result.success) {
437
+ receipt = { challengeId, completed: true, ...result };
438
+ } else {
439
+ receipt = result;
440
+ }
441
+ }
442
+ return {
443
+ success: true,
444
+ data: receipt || { challengeId, completed: true }
445
+ };
446
+ }
447
+ throw new Error(
448
+ "challenge is required. Please ensure registerTotp was called in the same instance, or provide the challenge object."
449
+ );
450
+ } catch (error) {
451
+ return {
452
+ success: false,
453
+ message: error?.message || "answer error",
454
+ error
455
+ };
456
+ }
457
+ }
426
458
  if (!challenge) {
427
459
  throw new Error("challenge is required");
428
460
  }
@@ -441,7 +473,7 @@ var CubeMfaService = class _CubeMfaService {
441
473
  };
442
474
  }
443
475
  }
444
- async executeBizWithMfa(bizType, mfaInfo) {
476
+ async executeBizWithMfa(bizType, mfaInfo, useLocalMethods = false) {
445
477
  if (!bizType) {
446
478
  throw new Error("bizType is required");
447
479
  }
@@ -451,7 +483,7 @@ var CubeMfaService = class _CubeMfaService {
451
483
  if (!mfaInfo?.id) {
452
484
  throw new Error("mfa not exists, please create mfa first");
453
485
  }
454
- const { success, data: receipt } = await this.approvalMfa(mfaInfo?.id || "") || {};
486
+ const { success, data: receipt } = await this.approvalMfa(mfaInfo?.id || "", useLocalMethods) || {};
455
487
  if (!success) {
456
488
  return {
457
489
  success: false,
@@ -468,7 +500,7 @@ var CubeMfaService = class _CubeMfaService {
468
500
  }
469
501
  if (bizType === "addFido") {
470
502
  const name = mfaInfo.request?.body?.name;
471
- const res = await this.addFido(name, receipt);
503
+ const res = useLocalMethods ? await this.addFidoLocal(name, receipt) : await this.addFido(name, receipt);
472
504
  return {
473
505
  success: !!res,
474
506
  message: !res ? "addFido error" : "",
@@ -536,11 +568,11 @@ var CubeMfaService = class _CubeMfaService {
536
568
  message: "bizType is not supported"
537
569
  };
538
570
  }
539
- async approvalMfa(mfaId) {
571
+ async approvalMfa(mfaId, useLocalMethods = false) {
540
572
  const apis = {
541
573
  totp: "approvalTotp",
542
574
  emailOtp: "approvalEmailOtp",
543
- fido: "approvalFido"
575
+ fido: useLocalMethods ? "approvalFidoLocal" : "approvalFido"
544
576
  };
545
577
  const mfaType = this.mfaType;
546
578
  if (!mfaType || !apis[mfaType]) {
@@ -559,7 +591,11 @@ var CubeMfaService = class _CubeMfaService {
559
591
  receipt = await this.approvalEmailOtp(mfaId);
560
592
  break;
561
593
  case "fido":
562
- receipt = await this.approvalFido(mfaId);
594
+ if (useLocalMethods) {
595
+ receipt = await this.approvalFidoLocal(mfaId);
596
+ } else {
597
+ receipt = await this.approvalFido(mfaId);
598
+ }
563
599
  break;
564
600
  default:
565
601
  return {
@@ -1025,6 +1061,10 @@ var CubeAccountService = class _CubeAccountService {
1025
1061
  return cubeIdentity;
1026
1062
  }
1027
1063
  //login + reg new user by wallet-api
1064
+ setJwtToken(jwtToken) {
1065
+ this.jwtToken = jwtToken;
1066
+ this.config = { ...this.config, jwtToken };
1067
+ }
1028
1068
  async loginOrRegister(oidcToken, options) {
1029
1069
  this.config = { ...this.config, oidcToken };
1030
1070
  const cubeIdentity = await this.getCubeIdentity();
@@ -1228,7 +1268,12 @@ var CubeConnect = async (config) => {
1228
1268
  if (!config.oidcToken) {
1229
1269
  throw new Error("oidcToken is required");
1230
1270
  }
1231
- await cubeAccount.loginOrRegister(config.oidcToken);
1271
+ if (config.jwtToken) {
1272
+ console.log("[CubeConnect] Using existing jwtToken, skipping loginOrRegister");
1273
+ cubeAccount.setJwtToken(config.jwtToken);
1274
+ } else {
1275
+ await cubeAccount.loginOrRegister(config.oidcToken);
1276
+ }
1232
1277
  await cubeAccount.init(config.oidcToken);
1233
1278
  const cubeMfaService = cubeAccount.cubeMfaService;
1234
1279
  const cubeExportService = cubeAccount.cubeExportService;
package/dist/index.d.cts CHANGED
@@ -286,9 +286,9 @@ declare class CubeMfaService {
286
286
  setMfaType(mfaType: MfaType): void;
287
287
  setMfaAnswer(mfaAnswer: MfaAnswer): void;
288
288
  getMfaInfo(bizType?: BizType): Promise<MfaInfo | null>;
289
- answerRegister(code: string): Promise<CubeRes>;
290
- executeBizWithMfa(bizType: BizType, mfaInfo?: MfaInfo | null): Promise<CubeRes>;
291
- approvalMfa(mfaId: string): Promise<CubeRes>;
289
+ answerRegister(code: string, challengeId?: string): Promise<CubeRes>;
290
+ executeBizWithMfa(bizType: BizType, mfaInfo?: MfaInfo | null, useLocalMethods?: boolean): Promise<CubeRes>;
291
+ approvalMfa(mfaId: string, useLocalMethods?: boolean): Promise<CubeRes>;
292
292
  private getPasskeyConfig;
293
293
  passkeyClear(): void;
294
294
  addFido(fidoName: string, receipt?: MfaReceipt): Promise<any>;
@@ -370,6 +370,7 @@ declare class CubeAccountService {
370
370
  constructor(config: CubeConfig);
371
371
  static getInstance(config?: CubeConfig): CubeAccountService;
372
372
  getCubeIdentity(): Promise<CubeIdentity | null>;
373
+ setJwtToken(jwtToken: string): void;
373
374
  loginOrRegister(oidcToken: string, options?: any): Promise<LoginRes>;
374
375
  updateUserInfo(userInfo: {
375
376
  nickname: string;
package/dist/index.d.ts CHANGED
@@ -286,9 +286,9 @@ declare class CubeMfaService {
286
286
  setMfaType(mfaType: MfaType): void;
287
287
  setMfaAnswer(mfaAnswer: MfaAnswer): void;
288
288
  getMfaInfo(bizType?: BizType): Promise<MfaInfo | null>;
289
- answerRegister(code: string): Promise<CubeRes>;
290
- executeBizWithMfa(bizType: BizType, mfaInfo?: MfaInfo | null): Promise<CubeRes>;
291
- approvalMfa(mfaId: string): Promise<CubeRes>;
289
+ answerRegister(code: string, challengeId?: string): Promise<CubeRes>;
290
+ executeBizWithMfa(bizType: BizType, mfaInfo?: MfaInfo | null, useLocalMethods?: boolean): Promise<CubeRes>;
291
+ approvalMfa(mfaId: string, useLocalMethods?: boolean): Promise<CubeRes>;
292
292
  private getPasskeyConfig;
293
293
  passkeyClear(): void;
294
294
  addFido(fidoName: string, receipt?: MfaReceipt): Promise<any>;
@@ -370,6 +370,7 @@ declare class CubeAccountService {
370
370
  constructor(config: CubeConfig);
371
371
  static getInstance(config?: CubeConfig): CubeAccountService;
372
372
  getCubeIdentity(): Promise<CubeIdentity | null>;
373
+ setJwtToken(jwtToken: string): void;
373
374
  loginOrRegister(oidcToken: string, options?: any): Promise<LoginRes>;
374
375
  updateUserInfo(userInfo: {
375
376
  nickname: string;
package/dist/index.js CHANGED
@@ -414,8 +414,40 @@ var CubeMfaService = class _CubeMfaService {
414
414
  const verifyStatus = receipt !== null ? "approved" : "pending";
415
415
  return { ...mfaInfo, verifyStatus, mfaRequired };
416
416
  }
417
- async answerRegister(code) {
417
+ async answerRegister(code, challengeId) {
418
418
  const challenge = this.registerChallenge;
419
+ if (!challenge && challengeId) {
420
+ try {
421
+ if (this.apiClient && typeof this.apiClient.userTotpResetComplete === "function") {
422
+ const result = await this.apiClient.userTotpResetComplete(challengeId, code);
423
+ let receipt = null;
424
+ if (result) {
425
+ if (typeof result.data === "function") {
426
+ receipt = result.data();
427
+ } else if (result.data) {
428
+ receipt = result.data;
429
+ } else if (result.status === "ok" || result.success) {
430
+ receipt = { challengeId, completed: true, ...result };
431
+ } else {
432
+ receipt = result;
433
+ }
434
+ }
435
+ return {
436
+ success: true,
437
+ data: receipt || { challengeId, completed: true }
438
+ };
439
+ }
440
+ throw new Error(
441
+ "challenge is required. Please ensure registerTotp was called in the same instance, or provide the challenge object."
442
+ );
443
+ } catch (error) {
444
+ return {
445
+ success: false,
446
+ message: error?.message || "answer error",
447
+ error
448
+ };
449
+ }
450
+ }
419
451
  if (!challenge) {
420
452
  throw new Error("challenge is required");
421
453
  }
@@ -434,7 +466,7 @@ var CubeMfaService = class _CubeMfaService {
434
466
  };
435
467
  }
436
468
  }
437
- async executeBizWithMfa(bizType, mfaInfo) {
469
+ async executeBizWithMfa(bizType, mfaInfo, useLocalMethods = false) {
438
470
  if (!bizType) {
439
471
  throw new Error("bizType is required");
440
472
  }
@@ -444,7 +476,7 @@ var CubeMfaService = class _CubeMfaService {
444
476
  if (!mfaInfo?.id) {
445
477
  throw new Error("mfa not exists, please create mfa first");
446
478
  }
447
- const { success, data: receipt } = await this.approvalMfa(mfaInfo?.id || "") || {};
479
+ const { success, data: receipt } = await this.approvalMfa(mfaInfo?.id || "", useLocalMethods) || {};
448
480
  if (!success) {
449
481
  return {
450
482
  success: false,
@@ -461,7 +493,7 @@ var CubeMfaService = class _CubeMfaService {
461
493
  }
462
494
  if (bizType === "addFido") {
463
495
  const name = mfaInfo.request?.body?.name;
464
- const res = await this.addFido(name, receipt);
496
+ const res = useLocalMethods ? await this.addFidoLocal(name, receipt) : await this.addFido(name, receipt);
465
497
  return {
466
498
  success: !!res,
467
499
  message: !res ? "addFido error" : "",
@@ -529,11 +561,11 @@ var CubeMfaService = class _CubeMfaService {
529
561
  message: "bizType is not supported"
530
562
  };
531
563
  }
532
- async approvalMfa(mfaId) {
564
+ async approvalMfa(mfaId, useLocalMethods = false) {
533
565
  const apis = {
534
566
  totp: "approvalTotp",
535
567
  emailOtp: "approvalEmailOtp",
536
- fido: "approvalFido"
568
+ fido: useLocalMethods ? "approvalFidoLocal" : "approvalFido"
537
569
  };
538
570
  const mfaType = this.mfaType;
539
571
  if (!mfaType || !apis[mfaType]) {
@@ -552,7 +584,11 @@ var CubeMfaService = class _CubeMfaService {
552
584
  receipt = await this.approvalEmailOtp(mfaId);
553
585
  break;
554
586
  case "fido":
555
- receipt = await this.approvalFido(mfaId);
587
+ if (useLocalMethods) {
588
+ receipt = await this.approvalFidoLocal(mfaId);
589
+ } else {
590
+ receipt = await this.approvalFido(mfaId);
591
+ }
556
592
  break;
557
593
  default:
558
594
  return {
@@ -1018,6 +1054,10 @@ var CubeAccountService = class _CubeAccountService {
1018
1054
  return cubeIdentity;
1019
1055
  }
1020
1056
  //login + reg new user by wallet-api
1057
+ setJwtToken(jwtToken) {
1058
+ this.jwtToken = jwtToken;
1059
+ this.config = { ...this.config, jwtToken };
1060
+ }
1021
1061
  async loginOrRegister(oidcToken, options) {
1022
1062
  this.config = { ...this.config, oidcToken };
1023
1063
  const cubeIdentity = await this.getCubeIdentity();
@@ -1221,7 +1261,12 @@ var CubeConnect = async (config) => {
1221
1261
  if (!config.oidcToken) {
1222
1262
  throw new Error("oidcToken is required");
1223
1263
  }
1224
- await cubeAccount.loginOrRegister(config.oidcToken);
1264
+ if (config.jwtToken) {
1265
+ console.log("[CubeConnect] Using existing jwtToken, skipping loginOrRegister");
1266
+ cubeAccount.setJwtToken(config.jwtToken);
1267
+ } else {
1268
+ await cubeAccount.loginOrRegister(config.oidcToken);
1269
+ }
1225
1270
  await cubeAccount.init(config.oidcToken);
1226
1271
  const cubeMfaService = cubeAccount.cubeMfaService;
1227
1272
  const cubeExportService = cubeAccount.cubeExportService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomo-inc/cubist-wallet-sdk",
3
- "version": "0.0.11",
3
+ "version": "0.0.16",
4
4
  "author": "tomo.inc",
5
5
  "license": "MIT",
6
6
  "private": false,
@@ -20,7 +20,7 @@
20
20
  "axios": "^1.11.0",
21
21
  "crypto-js": "^4.2.0",
22
22
  "@tomo-inc/cubist-sig-sdk": "1.1.0",
23
- "@tomo-inc/wallet-utils": "0.0.9"
23
+ "@tomo-inc/wallet-utils": "0.0.13"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@types/crypto-js": "^4.2.2",
package/project.json CHANGED
@@ -3,6 +3,13 @@
3
3
  "sourceRoot": "packages/cubist-wallet-sdk/src",
4
4
  "projectType": "library",
5
5
  "targets": {
6
+ "version:up": {
7
+ "executor": "nx:run-commands",
8
+ "options": {
9
+ "cwd": "packages/cubist-wallet-sdk",
10
+ "command": "npm version patch --no-git-tag-version"
11
+ }
12
+ },
6
13
  "build": {
7
14
  "executor": "nx:run-commands",
8
15
  "outputs": ["{projectRoot}/dist"],
@@ -53,6 +60,14 @@
53
60
  "command": "vitest",
54
61
  "cwd": "packages/cubist-wallet-sdk"
55
62
  }
63
+ },
64
+ "publish": {
65
+ "executor": "nx:run-commands",
66
+ "dependsOn": ["build"],
67
+ "options": {
68
+ "command": "pnpm publish --access public --no-git-checks --tag ${NPM_TAG:-latest}",
69
+ "cwd": "packages/cubist-wallet-sdk"
70
+ }
56
71
  }
57
72
  },
58
73
  "tags": ["npm:private", "scope:cubist-wallet-sdk", "type:library"]
@@ -101,6 +101,11 @@ export class CubeAccountService {
101
101
  }
102
102
 
103
103
  //login + reg new user by wallet-api
104
+ public setJwtToken(jwtToken: string): void {
105
+ this.jwtToken = jwtToken;
106
+ this.config = { ...this.config, jwtToken };
107
+ }
108
+
104
109
  public async loginOrRegister(oidcToken: string, options?: any): Promise<LoginRes> {
105
110
  this.config = { ...this.config, oidcToken };
106
111
  const cubeIdentity = await this.getCubeIdentity();
@@ -8,7 +8,13 @@ export const CubeConnect = async (config: CubeConfig) => {
8
8
  throw new Error("oidcToken is required");
9
9
  }
10
10
 
11
- await cubeAccount.loginOrRegister(config.oidcToken);
11
+ if (config.jwtToken) {
12
+ console.log("[CubeConnect] Using existing jwtToken, skipping loginOrRegister");
13
+ cubeAccount.setJwtToken(config.jwtToken);
14
+ } else {
15
+ await cubeAccount.loginOrRegister(config.oidcToken);
16
+ }
17
+
12
18
  await cubeAccount.init(config.oidcToken);
13
19
 
14
20
  const cubeMfaService = cubeAccount.cubeMfaService;
package/src/cube-mfa.ts CHANGED
@@ -102,11 +102,48 @@ export class CubeMfaService {
102
102
  return { ...mfaInfo, verifyStatus, mfaRequired };
103
103
  }
104
104
 
105
- public async answerRegister(code: string): Promise<CubeRes> {
105
+ public async answerRegister(code: string, challengeId?: string): Promise<CubeRes> {
106
106
  const challenge = this.registerChallenge;
107
+
108
+ if (!challenge && challengeId) {
109
+ try {
110
+ if (this.apiClient && typeof this.apiClient.userTotpResetComplete === "function") {
111
+ const result = await this.apiClient.userTotpResetComplete(challengeId, code);
112
+ let receipt = null;
113
+ if (result) {
114
+ if (typeof result.data === "function") {
115
+ receipt = result.data();
116
+ } else if (result.data) {
117
+ receipt = result.data;
118
+ } else if (result.status === "ok" || result.success) {
119
+ receipt = { challengeId, completed: true, ...result };
120
+ } else {
121
+ receipt = result;
122
+ }
123
+ }
124
+
125
+ return {
126
+ success: true,
127
+ data: receipt || { challengeId, completed: true },
128
+ };
129
+ }
130
+
131
+ throw new Error(
132
+ "challenge is required. Please ensure registerTotp was called in the same instance, or provide the challenge object.",
133
+ );
134
+ } catch (error: any) {
135
+ return {
136
+ success: false,
137
+ message: error?.message || "answer error",
138
+ error,
139
+ };
140
+ }
141
+ }
142
+
107
143
  if (!challenge) {
108
144
  throw new Error("challenge is required");
109
145
  }
146
+
110
147
  try {
111
148
  const receipt = (await challenge.answer(code)) || null;
112
149
  this.registerChallenge = null;
@@ -123,7 +160,11 @@ export class CubeMfaService {
123
160
  }
124
161
  }
125
162
 
126
- public async executeBizWithMfa(bizType: BizType, mfaInfo?: MfaInfo | null): Promise<CubeRes> {
163
+ public async executeBizWithMfa(
164
+ bizType: BizType,
165
+ mfaInfo?: MfaInfo | null,
166
+ useLocalMethods = false,
167
+ ): Promise<CubeRes> {
127
168
  if (!bizType) {
128
169
  throw new Error("bizType is required");
129
170
  }
@@ -134,7 +175,7 @@ export class CubeMfaService {
134
175
  throw new Error("mfa not exists, please create mfa first");
135
176
  }
136
177
 
137
- const { success, data: receipt } = (await this.approvalMfa(mfaInfo?.id || "")) || {};
178
+ const { success, data: receipt } = (await this.approvalMfa(mfaInfo?.id || "", useLocalMethods)) || {};
138
179
  if (!success) {
139
180
  return {
140
181
  success: false,
@@ -153,7 +194,8 @@ export class CubeMfaService {
153
194
 
154
195
  if (bizType === "addFido") {
155
196
  const name = mfaInfo.request?.body?.name;
156
- const res = await this.addFido(name, receipt);
197
+ // Use addFidoLocal when useLocalMethods is true to avoid opening a new window
198
+ const res = useLocalMethods ? await this.addFidoLocal(name, receipt) : await this.addFido(name, receipt);
157
199
  return {
158
200
  success: !!res,
159
201
  message: !res ? "addFido error" : "",
@@ -229,11 +271,11 @@ export class CubeMfaService {
229
271
  };
230
272
  }
231
273
 
232
- public async approvalMfa(mfaId: string): Promise<CubeRes> {
274
+ public async approvalMfa(mfaId: string, useLocalMethods = false): Promise<CubeRes> {
233
275
  const apis = {
234
276
  totp: "approvalTotp",
235
277
  emailOtp: "approvalEmailOtp",
236
- fido: "approvalFido",
278
+ fido: useLocalMethods ? "approvalFidoLocal" : "approvalFido",
237
279
  };
238
280
  const mfaType: MfaType = this.mfaType;
239
281
 
@@ -253,7 +295,11 @@ export class CubeMfaService {
253
295
  receipt = await this.approvalEmailOtp(mfaId);
254
296
  break;
255
297
  case "fido":
256
- receipt = await this.approvalFido(mfaId);
298
+ if (useLocalMethods) {
299
+ receipt = await this.approvalFidoLocal(mfaId);
300
+ } else {
301
+ receipt = await this.approvalFido(mfaId);
302
+ }
257
303
  break;
258
304
  default:
259
305
  return {