wallaby-cash 2.0.1-native.2 → 2.0.1-native.3

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.js CHANGED
@@ -8,8 +8,9 @@ const log = require('loglevel');
8
8
  const cryptoJs = require('crypto-js');
9
9
  const jwtDecode = require('jwt-decode');
10
10
  const lodash = require('lodash');
11
+ const jsBase64 = require('js-base64');
11
12
  const WebAuthn = require('@simplewebauthn/browser');
12
- const reactNativePasskey = require('react-native-passkey');
13
+ const addressValidator = require('@wallaby-cash/address-validator');
13
14
 
14
15
  const _interopDefaultCompat = e => e && typeof e === 'object' && 'default' in e ? e : { default: e };
15
16
 
@@ -211,6 +212,7 @@ exports.BlockchainName = void 0;
211
212
  BlockchainName["Avalanche"] = "AVALANCHE";
212
213
  BlockchainName["Bitcoin"] = "BITCOIN";
213
214
  BlockchainName["Ethereum"] = "ETHEREUM";
215
+ BlockchainName["Injective"] = "INJECTIVE";
214
216
  BlockchainName["Polygon"] = "POLYGON";
215
217
  BlockchainName["Bsc"] = "BSC";
216
218
  BlockchainName["Base"] = "BASE";
@@ -284,6 +286,39 @@ exports.LocalStorageItems = void 0;
284
286
  LocalStorageItems["PasskeyCredentialId"] = "pass-key-credential-id";
285
287
  LocalStorageItems["PasskeyClientDataObject"] = "passkey-client-data";
286
288
  })(exports.LocalStorageItems || (exports.LocalStorageItems = {}));
289
+ exports.LegacyKeyNames = void 0;
290
+ (function (LegacyKeyNames) {
291
+ LegacyKeyNames["EncryptedPrivateKey"] = "encryptedPrivateKey";
292
+ LegacyKeyNames["WallabyAuthPubKey"] = "wallabyAuthPubKey";
293
+ LegacyKeyNames["EncryptedAlgorandSeed"] = "encryptedAlgorandSeed";
294
+ LegacyKeyNames["EncryptedSeed"] = "encryptedSeed";
295
+ LegacyKeyNames["ClientAuthToken"] = "republic_jwt";
296
+ LegacyKeyNames["AccessToken"] = "accessToken";
297
+ })(exports.LegacyKeyNames || (exports.LegacyKeyNames = {}));
298
+ exports.V1KeyNames = void 0;
299
+ (function (V1KeyNames) {
300
+ V1KeyNames["AccessToken"] = "access-token";
301
+ V1KeyNames["EncryptedStandardSeedPhrase"] = "encrypted-standard-seedPhrase";
302
+ V1KeyNames["EncryptedAlgorandSeedPhrase"] = "encrypted-algorand-seedPhrase";
303
+ V1KeyNames["EncryptedDevicePrivateKey"] = "encrypted-private-key";
304
+ V1KeyNames["ClientAuthPublicKey"] = "client-auth-pub-key";
305
+ V1KeyNames["WallabyAuthPubKey"] = "wallaby-auth-pub-key";
306
+ V1KeyNames["ClientAuthToken"] = "republic-jwt";
307
+ })(exports.V1KeyNames || (exports.V1KeyNames = {}));
308
+ exports.V2KeyNames = void 0;
309
+ (function (V2KeyNames) {
310
+ V2KeyNames["AccessToken"] = "access-token";
311
+ V2KeyNames["BackupDeviceKeyShare"] = "backup-device-key-share";
312
+ V2KeyNames["ClientAuthPublicKey"] = "client-auth-pub-key";
313
+ V2KeyNames["ClientAuthToken"] = "republic-jwt";
314
+ V2KeyNames["EncryptedDevicePrivateKey"] = "encrypted-private-key";
315
+ V2KeyNames["EncryptedStandardSeedPhrase"] = "encrypted-standard-seedPhrase";
316
+ V2KeyNames["PasskeyCredential"] = "pass-key-credential";
317
+ V2KeyNames["PasskeyCredentialId"] = "pass-key-credential-id";
318
+ V2KeyNames["PasskeyClientDataObject"] = "passkey-client-data";
319
+ V2KeyNames["PrimaryDeviceKeyShare"] = "primary-device-key-share";
320
+ V2KeyNames["WallabyAuthPubKey"] = "wallaby-auth-pub-key";
321
+ })(exports.V2KeyNames || (exports.V2KeyNames = {}));
287
322
 
288
323
  exports.ErrorResponseCodes = void 0;
289
324
  (function (ErrorResponseCodes) {
@@ -559,17 +594,17 @@ var browser$1 = {
559
594
  uptime: uptime
560
595
  };
561
596
 
562
- if (browser$1.env.NODE_ENV === 'production') {
563
- log__default.default.setLevel('silent');
597
+ if (browser$1.env.ENABLE_DEVELOPMENT_LOGGING && browser$1.env.NODE_ENV !== 'production') {
598
+ log__default.default.setLevel('trace');
564
599
  }
565
600
  else {
566
- log__default.default.setLevel('trace');
601
+ log__default.default.setLevel('silent');
567
602
  }
568
603
  var logger = log__default.default;
569
604
 
570
605
  var _a;
571
606
  /**
572
- * The default environment will be set to NODE_ENV if environment is not set in config.
607
+ * The default environment will be set to 'development' if environment is not set in config.
573
608
  * For production builds, it is recommended to set NODE_ENV to 'production'.
574
609
  */
575
610
  var defaultEnvironment = (_a = browser$1.env.NODE_ENV) !== null && _a !== void 0 ? _a : 'development';
@@ -4298,35 +4333,52 @@ var hash = {
4298
4333
  var StorageService = /** @class */ (function () {
4299
4334
  function StorageService(_a) {
4300
4335
  var deviceStorage = _a.deviceStorage, userId = _a.userId, environment = _a.environment;
4336
+ var _b;
4301
4337
  this.userId = userId;
4302
4338
  this.environment = environment !== null && environment !== void 0 ? environment : defaultEnvironment;
4339
+ this.shortenedEnv = (_b = this.environment.slice(0, 1)) !== null && _b !== void 0 ? _b : 'd'; // d for development
4303
4340
  this.deviceStorage = deviceStorage;
4304
4341
  }
4305
- StorageService.prototype.fetch = function (key) {
4342
+ StorageService.prototype.getFromDeviceStorage = function (key) {
4306
4343
  return __awaiter(this, void 0, void 0, function () {
4307
- var item, _a;
4308
- return __generator(this, function (_b) {
4309
- switch (_b.label) {
4344
+ return __generator(this, function (_a) {
4345
+ switch (_a.label) {
4310
4346
  case 0:
4311
- _a = key;
4312
- switch (_a) {
4313
- case exports.LocalStorageItems.EncryptedStandardSeedPhrase: return [3 /*break*/, 1];
4314
- case exports.LocalStorageItems.EncryptedAlgorandSeedPhrase: return [3 /*break*/, 3];
4315
- }
4316
- return [3 /*break*/, 5];
4317
- case 1: return [4 /*yield*/, this.getItem("".concat(this.environment, "-encrypted-").concat(exports.SeedPhraseType.Standard, "-seedPhrase-").concat(this.userId))];
4318
- case 2:
4319
- item = _b.sent();
4320
- return [3 /*break*/, 7];
4321
- case 3: return [4 /*yield*/, this.getItem("".concat(this.environment, "-encrypted-").concat(exports.SeedPhraseType.Algorand, "-seedPhrase-").concat(this.userId))];
4322
- case 4:
4323
- item = _b.sent();
4324
- return [3 /*break*/, 7];
4325
- case 5: return [4 /*yield*/, this.getItem("".concat(this.environment, "-").concat(key, "-").concat(this.userId))];
4326
- case 6:
4327
- item = _b.sent();
4328
- return [3 /*break*/, 7];
4329
- case 7:
4347
+ if (!this.deviceStorage.getItem) return [3 /*break*/, 1];
4348
+ return [2 /*return*/, this.deviceStorage.getItem(key)];
4349
+ case 1:
4350
+ if (!this.deviceStorage.getItemAsync) return [3 /*break*/, 3];
4351
+ return [4 /*yield*/, this.deviceStorage.getItemAsync(key)];
4352
+ case 2: return [2 /*return*/, _a.sent()];
4353
+ case 3: return [2 /*return*/, null];
4354
+ }
4355
+ });
4356
+ });
4357
+ };
4358
+ StorageService.prototype.setInDeviceStorage = function (key, value) {
4359
+ return __awaiter(this, void 0, void 0, function () {
4360
+ return __generator(this, function (_a) {
4361
+ switch (_a.label) {
4362
+ case 0:
4363
+ if (!this.deviceStorage.setItem) return [3 /*break*/, 1];
4364
+ return [2 /*return*/, this.deviceStorage.setItem(key, value)];
4365
+ case 1:
4366
+ if (!this.deviceStorage.setItemAsync) return [3 /*break*/, 3];
4367
+ return [4 /*yield*/, this.deviceStorage.setItemAsync(key, value)];
4368
+ case 2: return [2 /*return*/, _a.sent()];
4369
+ case 3: return [2 /*return*/];
4370
+ }
4371
+ });
4372
+ });
4373
+ };
4374
+ StorageService.prototype.fetch = function (key) {
4375
+ return __awaiter(this, void 0, void 0, function () {
4376
+ var item;
4377
+ return __generator(this, function (_a) {
4378
+ switch (_a.label) {
4379
+ case 0: return [4 /*yield*/, this.getItem("wsdk:v2:".concat(this.shortenedEnv, ":").concat(key, ":").concat(this.userId))];
4380
+ case 1:
4381
+ item = _a.sent();
4330
4382
  if (!item) {
4331
4383
  logger.debug("Item with key ".concat(key, " was not found in storage."));
4332
4384
  return [2 /*return*/, undefined];
@@ -4338,29 +4390,10 @@ var StorageService = /** @class */ (function () {
4338
4390
  };
4339
4391
  StorageService.prototype.save = function (key, value) {
4340
4392
  return __awaiter(this, void 0, void 0, function () {
4341
- var _a;
4342
- return __generator(this, function (_b) {
4343
- switch (_b.label) {
4344
- case 0:
4345
- _a = key;
4346
- switch (_a) {
4347
- case exports.LocalStorageItems.EncryptedStandardSeedPhrase: return [3 /*break*/, 1];
4348
- case exports.LocalStorageItems.EncryptedAlgorandSeedPhrase: return [3 /*break*/, 3];
4349
- }
4350
- return [3 /*break*/, 5];
4351
- case 1: return [4 /*yield*/, this.setItem("".concat(this.environment, "-encrypted-").concat(exports.SeedPhraseType.Standard, "-seedPhrase-").concat(this.userId), value)];
4352
- case 2:
4353
- _b.sent();
4354
- return [3 /*break*/, 7];
4355
- case 3: return [4 /*yield*/, this.setItem("".concat(this.environment, "-encrypted-").concat(exports.SeedPhraseType.Algorand, "-seedPhrase-").concat(this.userId), value)];
4356
- case 4:
4357
- _b.sent();
4358
- return [3 /*break*/, 7];
4359
- case 5: return [4 /*yield*/, this.setItem("".concat(this.environment, "-").concat(key, "-").concat(this.userId), value)];
4360
- case 6:
4361
- _b.sent();
4362
- return [3 /*break*/, 7];
4363
- case 7: return [2 /*return*/];
4393
+ return __generator(this, function (_a) {
4394
+ switch (_a.label) {
4395
+ case 0: return [4 /*yield*/, this.setItem("wsdk:v2:".concat(this.shortenedEnv, ":").concat(key, ":").concat(this.userId), value)];
4396
+ case 1: return [2 /*return*/, _a.sent()];
4364
4397
  }
4365
4398
  });
4366
4399
  });
@@ -4369,45 +4402,21 @@ var StorageService = /** @class */ (function () {
4369
4402
  return __awaiter(this, void 0, void 0, function () {
4370
4403
  var _this = this;
4371
4404
  return __generator(this, function (_a) {
4372
- data.forEach(function (item) { return __awaiter(_this, void 0, void 0, function () {
4373
- return __generator(this, function (_a) {
4374
- switch (_a.label) {
4375
- case 0: return [4 /*yield*/, this.save(item.key, item.value)];
4376
- case 1:
4377
- _a.sent();
4378
- return [2 /*return*/];
4379
- }
4380
- });
4381
- }); });
4382
- return [2 /*return*/];
4405
+ switch (_a.label) {
4406
+ case 0: return [4 /*yield*/, Promise.all(data.map(function (item) { return _this.save(item.key, item.value); }))];
4407
+ case 1:
4408
+ _a.sent();
4409
+ return [2 /*return*/];
4410
+ }
4383
4411
  });
4384
4412
  });
4385
4413
  };
4386
4414
  StorageService.prototype.delete = function (key) {
4387
4415
  return __awaiter(this, void 0, void 0, function () {
4388
- var _a;
4389
- return __generator(this, function (_b) {
4390
- switch (_b.label) {
4391
- case 0:
4392
- _a = key;
4393
- switch (_a) {
4394
- case exports.LocalStorageItems.EncryptedStandardSeedPhrase: return [3 /*break*/, 1];
4395
- case exports.LocalStorageItems.EncryptedAlgorandSeedPhrase: return [3 /*break*/, 3];
4396
- }
4397
- return [3 /*break*/, 5];
4398
- case 1: return [4 /*yield*/, this.removeItem("".concat(this.environment, "-encrypted-").concat(exports.SeedPhraseType.Standard, "-seedPhrase-").concat(this.userId))];
4399
- case 2:
4400
- _b.sent();
4401
- return [3 /*break*/, 7];
4402
- case 3: return [4 /*yield*/, this.removeItem("".concat(this.environment, "-encrypted-").concat(exports.SeedPhraseType.Algorand, "-seedPhrase-").concat(this.userId))];
4403
- case 4:
4404
- _b.sent();
4405
- return [3 /*break*/, 7];
4406
- case 5: return [4 /*yield*/, this.removeItem("".concat(this.environment, "-").concat(key, "-").concat(this.userId))];
4407
- case 6:
4408
- _b.sent();
4409
- return [3 /*break*/, 7];
4410
- case 7: return [2 /*return*/];
4416
+ return __generator(this, function (_a) {
4417
+ switch (_a.label) {
4418
+ case 0: return [4 /*yield*/, this.removeItem("wsdk:v2:".concat(this.shortenedEnv, ":").concat(key, ":").concat(this.userId))];
4419
+ case 1: return [2 /*return*/, _a.sent()];
4411
4420
  }
4412
4421
  });
4413
4422
  });
@@ -4443,6 +4452,46 @@ var StorageService = /** @class */ (function () {
4443
4452
  }
4444
4453
  throw new Error('removeItem function is not defined');
4445
4454
  };
4455
+ StorageService.prototype.checkPrivateKeyExists = function () {
4456
+ return __awaiter(this, void 0, void 0, function () {
4457
+ return __generator(this, function (_a) {
4458
+ switch (_a.label) {
4459
+ case 0: return [4 /*yield*/, this.fetch(exports.LocalStorageItems.EncryptedDevicePrivateKey)];
4460
+ case 1: return [2 /*return*/, !!(_a.sent())];
4461
+ }
4462
+ });
4463
+ });
4464
+ };
4465
+ StorageService.prototype.checkPrimaryKeyShareExists = function () {
4466
+ return __awaiter(this, void 0, void 0, function () {
4467
+ return __generator(this, function (_a) {
4468
+ switch (_a.label) {
4469
+ case 0: return [4 /*yield*/, this.fetch(exports.LocalStorageItems.PrimaryDeviceKeyShare)];
4470
+ case 1: return [2 /*return*/, !!(_a.sent())];
4471
+ }
4472
+ });
4473
+ });
4474
+ };
4475
+ StorageService.prototype.checkBackupKeyShareExists = function () {
4476
+ return __awaiter(this, void 0, void 0, function () {
4477
+ return __generator(this, function (_a) {
4478
+ switch (_a.label) {
4479
+ case 0: return [4 /*yield*/, this.fetch(exports.LocalStorageItems.BackupDeviceKeyShare)];
4480
+ case 1: return [2 /*return*/, !!(_a.sent())];
4481
+ }
4482
+ });
4483
+ });
4484
+ };
4485
+ StorageService.prototype.checkSeedPhraseExists = function () {
4486
+ return __awaiter(this, void 0, void 0, function () {
4487
+ return __generator(this, function (_a) {
4488
+ switch (_a.label) {
4489
+ case 0: return [4 /*yield*/, this.fetch(exports.LocalStorageItems.EncryptedStandardSeedPhrase)];
4490
+ case 1: return [2 /*return*/, !!(_a.sent())];
4491
+ }
4492
+ });
4493
+ });
4494
+ };
4446
4495
  /**
4447
4496
  *
4448
4497
  * Stores Wallaby auth public key to local storage
@@ -4539,7 +4588,6 @@ var StorageService = /** @class */ (function () {
4539
4588
  /**
4540
4589
  *
4541
4590
  * Fetches encrypted private key from local storage
4542
- * @param userId
4543
4591
  */
4544
4592
  StorageService.prototype.getEncryptedPrivateKey = function () {
4545
4593
  return __awaiter(this, void 0, void 0, function () {
@@ -4795,17 +4843,15 @@ var StorageService = /** @class */ (function () {
4795
4843
  this.removeItem("encryptedSeed_".concat(this.userId)),
4796
4844
  this.removeItem("encryptedAlgorandSeed_".concat(this.userId)),
4797
4845
  this.removeItem("accessToken_".concat(this.userId)),
4798
- this.delete(exports.LocalStorageItems.AccessToken),
4799
- this.delete(exports.LocalStorageItems.ClientAuthPublicKey),
4800
- // this.delete(LocalStorageItems.ClientAuthToken),
4801
- this.delete(exports.LocalStorageItems.EncryptedAlgorandSeedPhrase),
4802
- this.delete(exports.LocalStorageItems.EncryptedStandardSeedPhrase),
4803
- this.delete(exports.LocalStorageItems.EncryptedKeyShares),
4804
- this.delete(exports.LocalStorageItems.EncryptedShare),
4805
- this.delete(exports.LocalStorageItems.PrimaryDeviceKeyShare),
4806
- this.delete(exports.LocalStorageItems.BackupDeviceKeyShare),
4807
- this.delete(exports.LocalStorageItems.EncryptedDevicePrivateKey),
4808
- this.delete(exports.LocalStorageItems.WallabyAuthPubKey),
4846
+ this.delete(exports.V2KeyNames.AccessToken),
4847
+ this.delete(exports.V2KeyNames.ClientAuthPublicKey),
4848
+ // this.delete(V2KeyNames.ClientAuthToken),
4849
+ this.delete(exports.V1KeyNames.EncryptedAlgorandSeedPhrase),
4850
+ this.delete(exports.V2KeyNames.EncryptedStandardSeedPhrase),
4851
+ this.delete(exports.V2KeyNames.PrimaryDeviceKeyShare),
4852
+ this.delete(exports.V2KeyNames.BackupDeviceKeyShare),
4853
+ this.delete(exports.V2KeyNames.EncryptedDevicePrivateKey),
4854
+ this.delete(exports.V2KeyNames.WallabyAuthPubKey),
4809
4855
  ])];
4810
4856
  case 1:
4811
4857
  _a.sent();
@@ -4889,15 +4935,10 @@ function jwtHasExpired(jwt) {
4889
4935
  return millisecondsToJWTTimeout(jwt) <= 0;
4890
4936
  }
4891
4937
  function jwtHasSameUser(jwt, userId) {
4892
- if (!jwt) {
4938
+ if (!jwt || !userId) {
4893
4939
  return false;
4894
4940
  }
4895
4941
  var jwtDecoded = jwtDecode.jwtDecode(jwt);
4896
- console.log('jwtDecoded', {
4897
- jwtDecoded: jwtDecoded,
4898
- userId: userId,
4899
- jwt: jwt,
4900
- });
4901
4942
  return jwtDecoded.externalUserId === userId;
4902
4943
  }
4903
4944
  function jwtIsSecure(jwt) {
@@ -4920,23 +4961,32 @@ function millisecondsToJWTTimeout(jwt) {
4920
4961
 
4921
4962
  var Base = /** @class */ (function () {
4922
4963
  function Base(config) {
4923
- var _a;
4924
4964
  this.apiKey = config.apiKey;
4925
4965
  this.baseUrl = config.baseUrl;
4926
4966
  this.userId = config.userId;
4927
- this.clientAuthToken = (_a = config.clientAuthToken) !== null && _a !== void 0 ? _a : config === null || config === void 0 ? void 0 : config.jwt;
4928
4967
  this.options = config.options;
4968
+ this._initializeClientAuthToken(config.clientAuthToken);
4929
4969
  this.request = this.request.bind(this);
4930
- if (!jwtHasSameUser(this.clientAuthToken, this.userId)) {
4970
+ }
4971
+ Object.defineProperty(Base.prototype, "setClientAuthToken", {
4972
+ set: function (token) {
4973
+ this._initializeClientAuthToken(token);
4974
+ },
4975
+ enumerable: false,
4976
+ configurable: true
4977
+ });
4978
+ Base.prototype._initializeClientAuthToken = function (token) {
4979
+ if (!jwtHasSameUser(token, this.userId)) {
4931
4980
  throw new Error('Client auth token does not match the user id. Blocking API call.');
4932
4981
  }
4933
- if (jwtIsSecure(this.clientAuthToken)) {
4982
+ this.clientAuthToken = token;
4983
+ if (jwtIsSecure(token)) {
4934
4984
  this.deviceAuthType = exports.AuthType.Password;
4935
4985
  }
4936
4986
  else {
4937
4987
  this.deviceAuthType = exports.AuthType.Passkey;
4938
4988
  }
4939
- }
4989
+ };
4940
4990
  Object.defineProperty(Base.prototype, "deviceStorage", {
4941
4991
  /**
4942
4992
  * This library uses `localStorage` as the default storage.
@@ -5027,7 +5077,7 @@ var Base = /** @class */ (function () {
5027
5077
  if (options === null || options === void 0 ? void 0 : options.queryParams) {
5028
5078
  url += "?".concat(objectToQueryParams(options.queryParams));
5029
5079
  }
5030
- return [4 /*yield*/, this.getRequestHeaders()];
5080
+ return [4 /*yield*/, this._getRequestHeaders()];
5031
5081
  case 1:
5032
5082
  headers = _p.sent();
5033
5083
  if ((_b = this.options) === null || _b === void 0 ? void 0 : _b.headers) {
@@ -5039,15 +5089,15 @@ var Base = /** @class */ (function () {
5039
5089
  headers: headers,
5040
5090
  });
5041
5091
  http.interceptors.response.use(function (response) { return response; }, function (error) {
5042
- var _a, _b, _c, _d, _e;
5092
+ var _a, _b, _c, _d, _e, _f;
5043
5093
  if ((_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.data) {
5044
- logger.info('SDK::Base::Interceptor::error.response.data', (_b = error === null || error === void 0 ? void 0 : error.response) === null || _b === void 0 ? void 0 : _b.data);
5094
+ logger.debug('SDK::Base::Interceptor::error.response.data', (_b = error === null || error === void 0 ? void 0 : error.response) === null || _b === void 0 ? void 0 : _b.data);
5045
5095
  if (((_c = error === null || error === void 0 ? void 0 : error.response) === null || _c === void 0 ? void 0 : _c.data.errorCode) && ((_d = error === null || error === void 0 ? void 0 : error.response) === null || _d === void 0 ? void 0 : _d.data.errorCode) !== exports.ErrorResponseCodes.user_already_exists) {
5046
5096
  return Promise.reject((_e = error === null || error === void 0 ? void 0 : error.response) === null || _e === void 0 ? void 0 : _e.data);
5047
5097
  }
5048
5098
  }
5049
5099
  logger.error('SDK::Base::Interceptor::error', error);
5050
- return Promise.reject(error);
5100
+ return Promise.reject((_f = error === null || error === void 0 ? void 0 : error.response) === null || _f === void 0 ? void 0 : _f.data);
5051
5101
  });
5052
5102
  _a = route.method;
5053
5103
  switch (_a) {
@@ -5062,7 +5112,7 @@ var Base = /** @class */ (function () {
5062
5112
  return [4 /*yield*/, http.get(url)];
5063
5113
  case 3:
5064
5114
  result = _p.sent();
5065
- logger.info('SDK::Base::RequestMethod.Get::result.data', result === null || result === void 0 ? void 0 : result.data);
5115
+ logger.debug('SDK::Base::RequestMethod.Get::result.data', result === null || result === void 0 ? void 0 : result.data);
5066
5116
  return [2 /*return*/, result === null || result === void 0 ? void 0 : result.data];
5067
5117
  case 4:
5068
5118
  error_1 = _p.sent();
@@ -5076,7 +5126,7 @@ var Base = /** @class */ (function () {
5076
5126
  return [4 /*yield*/, http.post(url, JSON.stringify(options === null || options === void 0 ? void 0 : options.payload))];
5077
5127
  case 6:
5078
5128
  result = _p.sent();
5079
- logger.info('SDK::Base::RequestMethod.Post::result.data', result === null || result === void 0 ? void 0 : result.data);
5129
+ logger.debug('SDK::Base::RequestMethod.Post::result.data', result === null || result === void 0 ? void 0 : result.data);
5080
5130
  return [2 /*return*/, result === null || result === void 0 ? void 0 : result.data];
5081
5131
  case 7:
5082
5132
  error_2 = _p.sent();
@@ -5094,7 +5144,7 @@ var Base = /** @class */ (function () {
5094
5144
  return [4 /*yield*/, http.put(url, (_j = JSON.stringify(options === null || options === void 0 ? void 0 : options.payload)) !== null && _j !== void 0 ? _j : null)];
5095
5145
  case 9:
5096
5146
  result = _p.sent();
5097
- logger.info('SDK::Base::RequestMethod.Put::result.data', result.data);
5147
+ logger.debug('SDK::Base::RequestMethod.Put::result.data', result.data);
5098
5148
  return [2 /*return*/, result === null || result === void 0 ? void 0 : result.data];
5099
5149
  case 10:
5100
5150
  error_3 = _p.sent();
@@ -5108,7 +5158,7 @@ var Base = /** @class */ (function () {
5108
5158
  return [4 /*yield*/, http.delete(url)];
5109
5159
  case 12:
5110
5160
  result = _p.sent();
5111
- logger.info('SDK::Base::RequestMethod.Delete::result.data', result.data);
5161
+ logger.debug('SDK::Base::RequestMethod.Delete::result.data', result.data);
5112
5162
  return [2 /*return*/, result === null || result === void 0 ? void 0 : result.data];
5113
5163
  case 13:
5114
5164
  error_4 = _p.sent();
@@ -5128,7 +5178,7 @@ var Base = /** @class */ (function () {
5128
5178
  });
5129
5179
  });
5130
5180
  };
5131
- Base.prototype.getRequestHeaders = function () {
5181
+ Base.prototype._getRequestHeaders = function () {
5132
5182
  return __awaiter(this, void 0, void 0, function () {
5133
5183
  var accessToken, headers;
5134
5184
  return __generator(this, function (_a) {
@@ -5251,6 +5301,11 @@ var WalletRoutes = {
5251
5301
  method: exports.RequestMethod.Post,
5252
5302
  requiresAccessToken: true,
5253
5303
  },
5304
+ generateWalletAddresses: {
5305
+ fullPath: '/wallets/generate-wallet-addresses',
5306
+ method: exports.RequestMethod.Post,
5307
+ requiresAccessToken: true,
5308
+ },
5254
5309
  updateAsset: {
5255
5310
  fullPath: '/wallets/asset/update',
5256
5311
  method: exports.RequestMethod.Put,
@@ -5312,6 +5367,11 @@ var AuthRoutes = {
5312
5367
  method: exports.RequestMethod.Get,
5313
5368
  requiresAccessToken: true,
5314
5369
  },
5370
+ getPasskeyCredentials: {
5371
+ fullPath: '/auth/passkey-credentials',
5372
+ method: exports.RequestMethod.Get,
5373
+ requiresAccessToken: true,
5374
+ },
5315
5375
  };
5316
5376
 
5317
5377
  var SystemRoutes = {
@@ -5348,6 +5408,39 @@ var SystemRoutes = {
5348
5408
  },
5349
5409
  };
5350
5410
 
5411
+ var TransactionsRoutes = {
5412
+ transfer: {
5413
+ fullPath: '/transactions/transfer',
5414
+ method: exports.RequestMethod.Post,
5415
+ requiresAccessToken: true,
5416
+ },
5417
+ transferWithShares: {
5418
+ fullPath: '/transactions/transfer-with-shares',
5419
+ method: exports.RequestMethod.Post,
5420
+ requiresAccessToken: true,
5421
+ },
5422
+ createAllowance: {
5423
+ fullPath: '/transactions/create-allowance',
5424
+ method: exports.RequestMethod.Post,
5425
+ requiresAccessToken: true,
5426
+ },
5427
+ estimateFee: {
5428
+ fullPath: '/transactions/estimate-fee',
5429
+ method: exports.RequestMethod.Get,
5430
+ requiresAccessToken: true,
5431
+ },
5432
+ getTransaction: {
5433
+ fullPath: '/transactions/status',
5434
+ method: exports.RequestMethod.Get,
5435
+ requiresAccessToken: true,
5436
+ },
5437
+ getTransactions: {
5438
+ fullPath: '/query/transactions',
5439
+ method: exports.RequestMethod.Get,
5440
+ requiresAccessToken: true,
5441
+ },
5442
+ };
5443
+
5351
5444
  // Common prologue and epilogue for sync/async functions
5352
5445
  function pbkdf2Init(hash, _password, _salt, _opts) {
5353
5446
  hash$1(hash);
@@ -5484,8 +5577,6 @@ var Cipher = /** @class */ (function () {
5484
5577
  if (typeof cipherText === 'string') {
5485
5578
  cipherText = JSON.parse(cipherText);
5486
5579
  }
5487
- console.log('SDK::CipherService::decrypt::cipherText', cipherText);
5488
- console.log('SDK::CipherService::decrypt::decryptionKey', decryptionKey);
5489
5580
  return [4 /*yield*/, decryptWithPrivateKey(decryptionKey, cipherText)];
5490
5581
  case 1:
5491
5582
  decrypted = _c.sent();
@@ -5512,7 +5603,6 @@ var Cipher = /** @class */ (function () {
5512
5603
  switch (_b.label) {
5513
5604
  case 0:
5514
5605
  _b.trys.push([0, 6, , 7]);
5515
- console.log('SDK::CipherService::getCredentialsKeyPair::options', options);
5516
5606
  derivedKeyPair = void 0;
5517
5607
  _a = options.authType;
5518
5608
  switch (_a) {
@@ -5573,7 +5663,7 @@ var Cipher = /** @class */ (function () {
5573
5663
  };
5574
5664
  /**
5575
5665
  *
5576
- * @description Prepares the stored data for transport by decrypting it and then encrypting it with the Wallaby public key.
5666
+ * @description Prepares the stored data for transport by double decrypting it and then encrypting it with the Wallaby public key.
5577
5667
  * @param { Encrypted } storedEncryptedData - The encrypted data to be decrypted.
5578
5668
  * @param { Encrypted } encryptedDevicePrivateKey - The encrypted device private key.
5579
5669
  * @param { string } wallabyPublicKey - The public key to encrypt the data with.
@@ -5623,14 +5713,12 @@ var Cipher = /** @class */ (function () {
5623
5713
  })];
5624
5714
  case 1:
5625
5715
  encryptedOnceData = _c.sent();
5626
- console.log('SDK::prepareDecryptedDataForStorage::encryptedOnceData', encryptedOnceData);
5627
5716
  return [4 /*yield*/, this.encrypt({
5628
5717
  data: JSON.stringify(encryptedOnceData),
5629
5718
  encryptionKey: credentialsKeyPair.publicKey,
5630
5719
  })];
5631
5720
  case 2:
5632
5721
  encryptedTwiceData = _c.sent();
5633
- console.log('SDK::prepareDecryptedDataForStorage::encryptedTwiceData', encryptedTwiceData);
5634
5722
  return [2 /*return*/, encryptedTwiceData];
5635
5723
  case 3:
5636
5724
  error_4 = _c.sent();
@@ -5668,14 +5756,12 @@ var Cipher = /** @class */ (function () {
5668
5756
  })];
5669
5757
  case 2:
5670
5758
  encryptedOnceData = _c.sent();
5671
- console.log('SDK::prepareTransportDataForStorage::encryptedOnceData', encryptedOnceData);
5672
5759
  return [4 /*yield*/, this.encrypt({
5673
5760
  data: JSON.stringify(encryptedOnceData),
5674
5761
  encryptionKey: credentialsKeyPair.publicKey,
5675
5762
  })];
5676
5763
  case 3:
5677
5764
  encryptedTwiceData = _c.sent();
5678
- console.log('SDK::prepareTransportDataForStorage::encryptedTwiceData', encryptedTwiceData);
5679
5765
  return [2 /*return*/, encryptedTwiceData];
5680
5766
  case 4:
5681
5767
  error_5 = _c.sent();
@@ -5705,7 +5791,6 @@ var Cipher = /** @class */ (function () {
5705
5791
  return [4 /*yield*/, this.getCredentialsKeyPair(options)];
5706
5792
  case 1:
5707
5793
  cryptoKeyPair = _c.sent();
5708
- console.log('SDK::CipherService::displayDataFromServer::cryptoKeyPair', cryptoKeyPair);
5709
5794
  return [4 /*yield*/, this.decrypt({
5710
5795
  cipherText: encryptedDevicePrivateKey,
5711
5796
  decryptionKey: cryptoKeyPair.privateKey,
@@ -5715,14 +5800,12 @@ var Cipher = /** @class */ (function () {
5715
5800
  if (!decryptedDevicePrivateKey) {
5716
5801
  throw new Error('Data could not be decrypted');
5717
5802
  }
5718
- console.log('SDK::CipherService::displayDataFromServer::decryptedDevicePrivateKey', decryptedDevicePrivateKey);
5719
5803
  return [4 /*yield*/, this.decrypt({
5720
5804
  cipherText: encryptedData,
5721
5805
  decryptionKey: decryptedDevicePrivateKey,
5722
5806
  })];
5723
5807
  case 3:
5724
5808
  decryptedData = _c.sent();
5725
- console.log('SDK::CipherService::displayDataFromServer::decryptedData', decryptedData);
5726
5809
  return [2 /*return*/, decryptedData];
5727
5810
  case 4:
5728
5811
  error_6 = _c.sent();
@@ -5776,7 +5859,6 @@ var Cipher = /** @class */ (function () {
5776
5859
  })];
5777
5860
  case 4:
5778
5861
  decryptedTwiceData = _c.sent();
5779
- console.log('decryptedTwiceData', decryptedTwiceData);
5780
5862
  if (!decryptedTwiceData) {
5781
5863
  throw new Error('Data could not be decrypted');
5782
5864
  }
@@ -5802,23 +5884,18 @@ var Cipher = /** @class */ (function () {
5802
5884
  switch (_c.label) {
5803
5885
  case 0:
5804
5886
  _c.trys.push([0, 3, , 4]);
5805
- console.log('SDK::CipherService::flipEncryptedData::cipherText', cipherText);
5806
- console.log('SDK::CipherService::flipEncryptedData::decryptionKey', decryptionKey);
5807
- console.log('SDK::CipherService::flipEncryptedData::encryptionKey', encryptionKey);
5808
5887
  return [4 /*yield*/, this.decrypt({
5809
5888
  cipherText: cipherText,
5810
5889
  decryptionKey: decryptionKey,
5811
5890
  })];
5812
5891
  case 1:
5813
5892
  decryptedData = _c.sent();
5814
- console.log('SDK::CipherService::flipEncryptedData::decryptedData', decryptedData);
5815
5893
  return [4 /*yield*/, this.encrypt({
5816
5894
  data: decryptedData,
5817
5895
  encryptionKey: encryptionKey,
5818
5896
  })];
5819
5897
  case 2:
5820
5898
  rewrappedData = _c.sent();
5821
- console.log('SDK::CipherService::flipEncryptedData::rewrappedData', rewrappedData);
5822
5899
  if (!rewrappedData) {
5823
5900
  throw new Error('Failed to rewrap seed phrase with Wallaby public key');
5824
5901
  }
@@ -5844,7 +5921,6 @@ var Cipher = /** @class */ (function () {
5844
5921
  var inputKeyMaterial = _b.inputKeyMaterial;
5845
5922
  return __generator(this, function (_c) {
5846
5923
  identityFromInputKey = createIdentity(inputKeyMaterial);
5847
- console.log('SDK::CipherService::deriveKeyPairFromPasskey::identityFromInputKey', identityFromInputKey);
5848
5924
  return [2 /*return*/, identityFromInputKey];
5849
5925
  });
5850
5926
  });
@@ -5862,7 +5938,6 @@ var Cipher = /** @class */ (function () {
5862
5938
  return __generator(this, function (_c) {
5863
5939
  encryptionKey = pbkdf2Sync(utf8ToBytes$2(password), utf8ToBytes$2(salt), PBKDF2_ITERATIONS, DEFAULT_ENTROPY_BYTES$1, 'sha256');
5864
5940
  encryptionKeyPair = createIdentity(encryptionKey);
5865
- console.log('SDK::CipherService::deriveKeyPairFromPassword::encryptionKeyPair', encryptionKeyPair);
5866
5941
  return [2 /*return*/, encryptionKeyPair];
5867
5942
  });
5868
5943
  });
@@ -5870,6 +5945,17 @@ var Cipher = /** @class */ (function () {
5870
5945
  return Cipher;
5871
5946
  }());
5872
5947
 
5948
+ var decodeBase64URL = function (base64url) {
5949
+ var base64 = base64url.replace(/-/g, '+').replace(/_/g, '/');
5950
+ var padded = base64.padEnd(base64.length + ((4 - (base64.length % 4)) % 4), '=');
5951
+ var binary = jsBase64.atob(padded);
5952
+ var bytes = new Uint8Array(binary.length);
5953
+ for (var i = 0; i < binary.length; i++) {
5954
+ bytes[i] = binary.charCodeAt(i);
5955
+ }
5956
+ return bytes;
5957
+ };
5958
+
5873
5959
  var UnknownError = {
5874
5960
  error: 'UnknownError',
5875
5961
  message: 'An unknown error occurred',
@@ -5988,153 +6074,74 @@ var PasskeyErrorCodes = [
5988
6074
  PassthroughSeeCausePropertyError,
5989
6075
  ];
5990
6076
 
6077
+ /**
6078
+ * Web Authenticator Implementation
6079
+ *
6080
+ * This file contains the web-specific authenticator logic using WebAuthn.
6081
+ * It's automatically picked up by web bundlers (webpack, Rollup, etc.) when importing './authenticator'
6082
+ *
6083
+ * React Native will use authenticator.native.ts instead due to the .native.ts extension.
6084
+ */
5991
6085
  var Authenticator = /** @class */ (function () {
5992
6086
  function Authenticator() {
5993
- // This should be defined in a react-native environment.
5994
- // eslint-disable-next-line @typescript-eslint/no-require-imports
5995
- var ReactNative = require('react-native');
5996
- if (ReactNative && ReactNative.Platform && ReactNative.Platform.OS) {
5997
- this.platform = ReactNative.Platform.OS;
5998
- }
5999
- else if (typeof window !== 'undefined') {
6000
- this.platform = 'web';
6001
- }
6002
- else if (browser$1 && browser$1.platform === 'darwin') {
6003
- this.platform = 'macos';
6004
- }
6005
- else {
6006
- this.platform = 'unknown';
6007
- }
6087
+ // Web environment - no additional setup needed
6008
6088
  }
6009
6089
  Authenticator.prototype.register = function (_a) {
6010
6090
  return __awaiter(this, arguments, void 0, function (_b) {
6011
- var _c, response, error_1, passkeyMappedPayload, response, registrationResponse, error_2;
6091
+ var response, error_1;
6012
6092
  var optionsJSON = _b.optionsJSON;
6013
- return __generator(this, function (_d) {
6014
- switch (_d.label) {
6093
+ return __generator(this, function (_c) {
6094
+ switch (_c.label) {
6015
6095
  case 0:
6016
- _c = this.platform;
6017
- switch (_c) {
6018
- case 'web': return [3 /*break*/, 1];
6019
- case 'android': return [3 /*break*/, 5];
6020
- case 'ios': return [3 /*break*/, 5];
6021
- }
6022
- return [3 /*break*/, 9];
6023
- case 1:
6024
- _d.trys.push([1, 3, , 4]);
6096
+ _c.trys.push([0, 2, , 3]);
6025
6097
  if (!window || !window.navigator.credentials) {
6026
6098
  throw new Error('WebAuthn is not supported in this browser.');
6027
6099
  }
6028
6100
  return [4 /*yield*/, WebAuthn__namespace.startRegistration({ optionsJSON: optionsJSON })];
6029
- case 2:
6030
- response = _d.sent();
6101
+ case 1:
6102
+ response = _c.sent();
6031
6103
  return [2 /*return*/, response];
6032
- case 3:
6033
- error_1 = _d.sent();
6104
+ case 2:
6105
+ error_1 = _c.sent();
6034
6106
  this.handlePasskeyError(error_1);
6035
- return [3 /*break*/, 4];
6036
- case 4: return [3 /*break*/, 9];
6037
- case 5:
6038
- _d.trys.push([5, 7, , 8]);
6039
- if (!reactNativePasskey.Passkey.isSupported()) {
6040
- if (this.platform === 'android') {
6041
- throw new Error(AndroidVersionNotSupportedError.error);
6042
- }
6043
- else {
6044
- throw new Error(IOSVersionNotSupportedError.error);
6045
- }
6046
- }
6047
- // Those checks are only to satisfy the type conversion to `PasskeyCreateRequest`
6048
- if (!optionsJSON || !optionsJSON.rp || !optionsJSON.user || !optionsJSON.extensions) {
6049
- throw new Error('Invalid passkey options. Required fields are missing.');
6050
- }
6051
- passkeyMappedPayload = this.mapPasskeyCreationPayload(optionsJSON);
6052
- return [4 /*yield*/, reactNativePasskey.Passkey.create(passkeyMappedPayload)];
6053
- case 6:
6054
- response = _d.sent();
6055
- registrationResponse = this.mapPasskeyCreationResponse(response);
6056
- return [2 /*return*/, registrationResponse];
6057
- case 7:
6058
- error_2 = _d.sent();
6059
- this.handlePasskeyError(error_2);
6060
- return [3 /*break*/, 8];
6061
- case 8: return [3 /*break*/, 9];
6062
- case 9:
6063
- // This should never be reached, but TypeScript needs a return statement.
6064
- throw new Error('Unsupported client type or unhandled error.');
6107
+ throw error_1; // This will never be reached due to handlePasskeyError throwing, but satisfies TypeScript
6108
+ case 3: return [2 /*return*/];
6065
6109
  }
6066
6110
  });
6067
6111
  });
6068
6112
  };
6069
6113
  Authenticator.prototype.authenticate = function (_a) {
6070
6114
  return __awaiter(this, arguments, void 0, function (_b) {
6071
- var _c, response, error_3, passkeyMappedPayload, response, registrationResponse, error_4, error_5;
6115
+ var response, error_2;
6072
6116
  var optionsJSON = _b.optionsJSON;
6073
- return __generator(this, function (_d) {
6074
- switch (_d.label) {
6117
+ return __generator(this, function (_c) {
6118
+ switch (_c.label) {
6075
6119
  case 0:
6076
- _d.trys.push([0, 10, , 11]);
6077
- _c = this.platform;
6078
- switch (_c) {
6079
- case 'web': return [3 /*break*/, 1];
6080
- case 'android': return [3 /*break*/, 5];
6081
- case 'ios': return [3 /*break*/, 5];
6082
- }
6083
- return [3 /*break*/, 9];
6084
- case 1:
6085
- _d.trys.push([1, 3, , 4]);
6120
+ _c.trys.push([0, 2, , 3]);
6086
6121
  if (!window || !window.navigator.credentials) {
6087
6122
  throw new Error('WebAuthn is not supported in this browser.');
6088
6123
  }
6089
6124
  return [4 /*yield*/, WebAuthn__namespace.startAuthentication({ optionsJSON: optionsJSON })];
6090
- case 2:
6091
- response = _d.sent();
6125
+ case 1:
6126
+ response = _c.sent();
6092
6127
  return [2 /*return*/, response];
6093
- case 3:
6094
- error_3 = _d.sent();
6095
- this.handlePasskeyError(error_3);
6096
- return [3 /*break*/, 4];
6097
- case 4: return [3 /*break*/, 9];
6098
- case 5:
6099
- _d.trys.push([5, 7, , 8]);
6100
- if (!reactNativePasskey.Passkey.isSupported()) {
6101
- if (this.platform === 'android') {
6102
- throw new Error(AndroidVersionNotSupportedError.error);
6103
- }
6104
- else {
6105
- throw new Error(IOSVersionNotSupportedError.error);
6106
- }
6107
- }
6108
- passkeyMappedPayload = this.mapPasskeyAuthenticationPayload(optionsJSON);
6109
- return [4 /*yield*/, reactNativePasskey.Passkey.get(passkeyMappedPayload)];
6110
- case 6:
6111
- response = _d.sent();
6112
- registrationResponse = this.mapPasskeyAuthenticationResponse(response);
6113
- return [2 /*return*/, registrationResponse];
6114
- case 7:
6115
- error_4 = _d.sent();
6116
- this.handlePasskeyError(error_4);
6117
- return [3 /*break*/, 8];
6118
- case 8: return [3 /*break*/, 9];
6119
- case 9: return [3 /*break*/, 11];
6120
- case 10:
6121
- error_5 = _d.sent();
6122
- this.handlePasskeyError(error_5);
6123
- return [3 /*break*/, 11];
6124
- case 11:
6125
- // This should never be reached, but TypeScript needs a return statement.
6126
- throw new Error('Unknown client type or unhandled error.');
6128
+ case 2:
6129
+ error_2 = _c.sent();
6130
+ this.handlePasskeyError(error_2);
6131
+ throw error_2; // This will never be reached due to handlePasskeyError throwing, but satisfies TypeScript
6132
+ case 3: return [2 /*return*/];
6127
6133
  }
6128
6134
  });
6129
6135
  });
6130
6136
  };
6131
6137
  /**
6132
- *
6133
6138
  * @description Handles the passkey error and throws a user-friendly error message.
6134
- * @param {WebAuthnError | PasskeyError | Error | any} error
6139
+ * @param {WebAuthnError | Error | any} error
6135
6140
  * @returns {Error} The error message.
6136
6141
  */
6137
6142
  Authenticator.prototype.handlePasskeyError = function (error) {
6143
+ logger.error('SDK::Authenticator::handlePasskeyError', error);
6144
+ console.error('SDK::Authenticator::handlePasskeyError', error);
6138
6145
  if (error instanceof WebAuthn__namespace.WebAuthnError) {
6139
6146
  return this.throwPasskeyError(error.code);
6140
6147
  }
@@ -6153,107 +6160,13 @@ var Authenticator = /** @class */ (function () {
6153
6160
  };
6154
6161
  Authenticator.prototype.throwPasskeyError = function (errorCode) {
6155
6162
  var _a;
6163
+ console.error('SDK::Authenticator::throwPasskeyError', errorCode);
6156
6164
  var errorToThrow = PasskeyErrorCodes.find(function (error) {
6157
6165
  return error.error === errorCode;
6158
6166
  });
6159
6167
  logger.error('SDK::Authenticator::error', errorToThrow);
6160
6168
  throw new Error((_a = errorToThrow === null || errorToThrow === void 0 ? void 0 : errorToThrow.message) !== null && _a !== void 0 ? _a : UnknownError.message);
6161
6169
  };
6162
- Authenticator.prototype.mapPasskeyCreationPayload = function (optionsJSON) {
6163
- var _a, _b, _c, _d;
6164
- var authenticatorSelection = optionsJSON.authenticatorSelection;
6165
- var requestedExtensions = optionsJSON.extensions;
6166
- if (!((_b = (_a = requestedExtensions.prf) === null || _a === void 0 ? void 0 : _a.eval) === null || _b === void 0 ? void 0 : _b.first)) {
6167
- throw new Error('Invalid passkey options. Required fields are missing.');
6168
- }
6169
- var prfFirstSalt = new Uint8Array(ArrayBuffer.isView(requestedExtensions.prf.eval.first)
6170
- ? requestedExtensions.prf.eval.first.buffer
6171
- : requestedExtensions.prf.eval.first);
6172
- return {
6173
- user: {
6174
- id: optionsJSON.user.id,
6175
- name: optionsJSON.user.name,
6176
- displayName: optionsJSON.user.displayName,
6177
- },
6178
- rp: {
6179
- id: (_c = optionsJSON.rp.id) !== null && _c !== void 0 ? _c : '',
6180
- name: optionsJSON.rp.name,
6181
- },
6182
- extensions: {
6183
- largeBlob: { supported: false },
6184
- prf: {
6185
- eval: {
6186
- first: prfFirstSalt,
6187
- },
6188
- },
6189
- },
6190
- authenticatorSelection: {
6191
- authenticatorAttachment: authenticatorSelection === null || authenticatorSelection === void 0 ? void 0 : authenticatorSelection.authenticatorAttachment,
6192
- requireResidentKey: (_d = authenticatorSelection === null || authenticatorSelection === void 0 ? void 0 : authenticatorSelection.requireResidentKey) !== null && _d !== void 0 ? _d : false,
6193
- residentKey: authenticatorSelection === null || authenticatorSelection === void 0 ? void 0 : authenticatorSelection.residentKey,
6194
- userVerification: authenticatorSelection === null || authenticatorSelection === void 0 ? void 0 : authenticatorSelection.userVerification,
6195
- },
6196
- challenge: optionsJSON.challenge,
6197
- pubKeyCredParams: optionsJSON.pubKeyCredParams.map(function (param) { return ({
6198
- type: param.type,
6199
- alg: param.alg,
6200
- }); }),
6201
- };
6202
- };
6203
- Authenticator.prototype.mapPasskeyCreationResponse = function (response) {
6204
- var _a, _b, _c;
6205
- return {
6206
- id: response.id, // ensure this is Base64URLString
6207
- rawId: response.rawId, // ensure this is Base64URLString
6208
- type: ((_a = response.type) !== null && _a !== void 0 ? _a : 'public-key'),
6209
- response: response.response,
6210
- // this should satisfy the expected extension response.
6211
- clientExtensionResults: {
6212
- credProps: { rk: false },
6213
- prf: (_c = (_b = response.extensions) === null || _b === void 0 ? void 0 : _b.clientExtensionResults) === null || _c === void 0 ? void 0 : _c.prf,
6214
- },
6215
- };
6216
- };
6217
- Authenticator.prototype.mapPasskeyAuthenticationResponse = function (response) {
6218
- var _a, _b;
6219
- return {
6220
- id: response.id, // ensure this is Base64URLString
6221
- rawId: response.rawId, // ensure this is Base64URLString
6222
- type: ((_a = response.type) !== null && _a !== void 0 ? _a : 'public-key'),
6223
- response: response.response,
6224
- // this should satisfy the expected extension response.
6225
- clientExtensionResults: {
6226
- credProps: { rk: false },
6227
- prf: (_b = response === null || response === void 0 ? void 0 : response.clientExtensionResults) === null || _b === void 0 ? void 0 : _b.prf,
6228
- },
6229
- };
6230
- };
6231
- Authenticator.prototype.mapPasskeyAuthenticationPayload = function (optionsJSON) {
6232
- var _a, _b, _c, _d;
6233
- var requestedExtensions = optionsJSON.extensions;
6234
- if (!((_b = (_a = requestedExtensions.prf) === null || _a === void 0 ? void 0 : _a.eval) === null || _b === void 0 ? void 0 : _b.first)) {
6235
- throw new Error('Invalid passkey options. Required fields are missing.');
6236
- }
6237
- var prfFirstSalt = new Uint8Array(ArrayBuffer.isView(requestedExtensions.prf.eval.first)
6238
- ? requestedExtensions.prf.eval.first.buffer
6239
- : requestedExtensions.prf.eval.first);
6240
- return {
6241
- rpId: (_c = optionsJSON.rpId) !== null && _c !== void 0 ? _c : '',
6242
- challenge: optionsJSON.challenge,
6243
- allowCredentials: (_d = optionsJSON.allowCredentials) === null || _d === void 0 ? void 0 : _d.map(function (credential) { return ({
6244
- id: credential.id,
6245
- type: 'public-key',
6246
- transports: [AuthenticatorTransport.internal],
6247
- }); }),
6248
- extensions: {
6249
- prf: {
6250
- eval: {
6251
- first: prfFirstSalt,
6252
- },
6253
- },
6254
- },
6255
- };
6256
- };
6257
6170
  return Authenticator;
6258
6171
  }());
6259
6172
 
@@ -6265,12 +6178,52 @@ var PasskeyService = /** @class */ (function () {
6265
6178
  this.request = request;
6266
6179
  this.authenticator = new Authenticator();
6267
6180
  }
6268
- /**
6269
- * @description Adds a new passkey to the user's account on that device.
6270
- * @param { AsymmetricKeyPair } deviceKeyPair
6271
- * @param { SignatureMessageResponse } challengeResponse
6272
- * @returns { AuthResponse } The authentication response containing the access token and user information.
6273
- */
6181
+ PasskeyService.prototype.preparePasskeyRequestOptions = function (options) {
6182
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
6183
+ var prfExtensionEvaluation = ((_c = (_b = (_a = options === null || options === void 0 ? void 0 : options.extensions) === null || _a === void 0 ? void 0 : _a.prf) === null || _b === void 0 ? void 0 : _b.eval) === null || _c === void 0 ? void 0 : _c.base64)
6184
+ ? decodeBase64URL((_f = (_e = (_d = options === null || options === void 0 ? void 0 : options.extensions) === null || _d === void 0 ? void 0 : _d.prf) === null || _e === void 0 ? void 0 : _e.eval) === null || _f === void 0 ? void 0 : _f.base64)
6185
+ : ((_j = (_h = (_g = options === null || options === void 0 ? void 0 : options.extensions) === null || _g === void 0 ? void 0 : _g.prf) === null || _h === void 0 ? void 0 : _h.eval) === null || _j === void 0 ? void 0 : _j.first) instanceof ArrayBuffer
6186
+ ? new Uint8Array((_m = (_l = (_k = options === null || options === void 0 ? void 0 : options.extensions) === null || _k === void 0 ? void 0 : _k.prf) === null || _l === void 0 ? void 0 : _l.eval) === null || _m === void 0 ? void 0 : _m.first)
6187
+ : typeof ((_q = (_p = (_o = options === null || options === void 0 ? void 0 : options.extensions) === null || _o === void 0 ? void 0 : _o.prf) === null || _p === void 0 ? void 0 : _p.eval) === null || _q === void 0 ? void 0 : _q.first) === 'object'
6188
+ ? new Uint8Array(Object.values((_t = (_s = (_r = options === null || options === void 0 ? void 0 : options.extensions) === null || _r === void 0 ? void 0 : _r.prf) === null || _s === void 0 ? void 0 : _s.eval) === null || _t === void 0 ? void 0 : _t.first))
6189
+ : undefined;
6190
+ if (!prfExtensionEvaluation) {
6191
+ throw new Error('Passkey extension cannot be used at this time.');
6192
+ }
6193
+ var parsedOptions = __assign(__assign({}, options), { extensions: {
6194
+ prf: {
6195
+ eval: {
6196
+ first: prfExtensionEvaluation,
6197
+ },
6198
+ },
6199
+ } });
6200
+ // While the authenticator still works with the prf and would return the response (if any),
6201
+ // the library `@simplewebauthn/browser` does not support the prf extension in its type intentionally.
6202
+ // > "Using the prf extension does not fall under the simple use of webauthn."
6203
+ return parsedOptions;
6204
+ };
6205
+ PasskeyService.prototype.preparePasskeyCreationOptions = function (options) {
6206
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
6207
+ var prfExtensionEvaluation = ((_c = (_b = (_a = options === null || options === void 0 ? void 0 : options.extensions) === null || _a === void 0 ? void 0 : _a.prf) === null || _b === void 0 ? void 0 : _b.eval) === null || _c === void 0 ? void 0 : _c.base64)
6208
+ ? decodeBase64URL((_f = (_e = (_d = options === null || options === void 0 ? void 0 : options.extensions) === null || _d === void 0 ? void 0 : _d.prf) === null || _e === void 0 ? void 0 : _e.eval) === null || _f === void 0 ? void 0 : _f.base64)
6209
+ : ((_j = (_h = (_g = options === null || options === void 0 ? void 0 : options.extensions) === null || _g === void 0 ? void 0 : _g.prf) === null || _h === void 0 ? void 0 : _h.eval) === null || _j === void 0 ? void 0 : _j.first) instanceof ArrayBuffer
6210
+ ? new Uint8Array((_m = (_l = (_k = options === null || options === void 0 ? void 0 : options.extensions) === null || _k === void 0 ? void 0 : _k.prf) === null || _l === void 0 ? void 0 : _l.eval) === null || _m === void 0 ? void 0 : _m.first)
6211
+ : typeof ((_q = (_p = (_o = options === null || options === void 0 ? void 0 : options.extensions) === null || _o === void 0 ? void 0 : _o.prf) === null || _p === void 0 ? void 0 : _p.eval) === null || _q === void 0 ? void 0 : _q.first) === 'object'
6212
+ ? new Uint8Array(Object.values((_t = (_s = (_r = options === null || options === void 0 ? void 0 : options.extensions) === null || _r === void 0 ? void 0 : _r.prf) === null || _s === void 0 ? void 0 : _s.eval) === null || _t === void 0 ? void 0 : _t.first))
6213
+ : undefined;
6214
+ var parsedOptions = __assign(__assign({}, options), { extensions: __assign(__assign({}, options === null || options === void 0 ? void 0 : options.extensions), { prf: {
6215
+ eval: {
6216
+ first: prfExtensionEvaluation,
6217
+ },
6218
+ } }) });
6219
+ return parsedOptions;
6220
+ };
6221
+ /**
6222
+ * @description Adds a new passkey to the user's account on that device.
6223
+ * @param { AsymmetricKeyPair } deviceKeyPair
6224
+ * @param { SignatureMessageResponse } challengeResponse
6225
+ * @returns { AuthResponse } The authentication response containing the access token and user information.
6226
+ */
6274
6227
  PasskeyService.prototype.addNewPasskey = function (_a) {
6275
6228
  return __awaiter(this, arguments, void 0, function (_b) {
6276
6229
  var passkeyCredential, credentialsKeyPair, singInResponse, encryptedNewDevicePrivateKey, error_1;
@@ -6341,21 +6294,20 @@ var PasskeyService = /** @class */ (function () {
6341
6294
  */
6342
6295
  PasskeyService.prototype.authenticate = function (_a) {
6343
6296
  return __awaiter(this, arguments, void 0, function (_b) {
6344
- var extensions, firstSalt, updatedOptions, passkeyCredential, credentialsKeyPair, decryptedDevicePrivateKey, signatureMessage, _c, signature, message, singInResponse, error_2;
6345
- var _d, _e;
6297
+ var parsedOptions, updatedOptions, passkeyCredential, credentialsKeyPair, decryptedDevicePrivateKey, _c, signature, message, singInResponse, error_2;
6298
+ var _d, _e, _f;
6346
6299
  var deviceKeyPair = _b.deviceKeyPair, challengeResponse = _b.challengeResponse;
6347
- return __generator(this, function (_f) {
6348
- switch (_f.label) {
6300
+ return __generator(this, function (_g) {
6301
+ switch (_g.label) {
6349
6302
  case 0:
6350
- _f.trys.push([0, 8, , 9]);
6303
+ _g.trys.push([0, 7, , 8]);
6351
6304
  if (!challengeResponse || !challengeResponse.options) {
6352
6305
  throw new Error('Passkey challenge could not be retrieved, please try again later.');
6353
6306
  }
6354
- extensions = challengeResponse.options.extensions;
6355
- firstSalt = new Uint8Array((_e = (_d = extensions.prf) === null || _d === void 0 ? void 0 : _d.eval) === null || _e === void 0 ? void 0 : _e.first);
6356
- updatedOptions = __assign(__assign({}, challengeResponse.options), { extensions: __assign(__assign({}, lodash.omit(extensions, 'credProps')), { prf: {
6307
+ parsedOptions = this.preparePasskeyRequestOptions(challengeResponse.options);
6308
+ updatedOptions = __assign(__assign({}, challengeResponse.options), { extensions: __assign(__assign({}, lodash.omit(parsedOptions.extensions, 'credProps')), { prf: {
6357
6309
  eval: {
6358
- first: firstSalt,
6310
+ first: (_f = (_e = (_d = parsedOptions.extensions) === null || _d === void 0 ? void 0 : _d.prf) === null || _e === void 0 ? void 0 : _e.eval) === null || _f === void 0 ? void 0 : _f.first,
6359
6311
  },
6360
6312
  } }) });
6361
6313
  console.log('PasskeyService::authenticate: updatedOptions', updatedOptions);
@@ -6363,28 +6315,22 @@ var PasskeyService = /** @class */ (function () {
6363
6315
  optionsJSON: updatedOptions,
6364
6316
  })];
6365
6317
  case 1:
6366
- passkeyCredential = _f.sent();
6318
+ passkeyCredential = _g.sent();
6367
6319
  return [4 /*yield*/, this.handleCredentialsCreationFromPrfExtension(passkeyCredential)];
6368
6320
  case 2:
6369
- credentialsKeyPair = _f.sent();
6321
+ credentialsKeyPair = _g.sent();
6370
6322
  return [4 /*yield*/, this.cipher.decrypt({
6371
6323
  cipherText: deviceKeyPair.encryptedDevicePrivateKey,
6372
6324
  decryptionKey: credentialsKeyPair.privateKey,
6373
6325
  })];
6374
6326
  case 3:
6375
- decryptedDevicePrivateKey = _f.sent();
6376
- return [4 /*yield*/, this.request(AuthRoutes.signatureMessage, {
6377
- method: AuthRoutes.signatureMessage.method,
6378
- payload: { clientAuthPubKey: deviceKeyPair.publicKey },
6379
- })];
6380
- case 4:
6381
- signatureMessage = _f.sent();
6327
+ decryptedDevicePrivateKey = _g.sent();
6382
6328
  return [4 /*yield*/, this.cipher.sign({
6383
- message: signatureMessage.message,
6329
+ message: challengeResponse.message,
6384
6330
  signingKey: decryptedDevicePrivateKey,
6385
6331
  })];
6386
- case 5:
6387
- _c = _f.sent(), signature = _c.signature, message = _c.message;
6332
+ case 4:
6333
+ _c = _g.sent(), signature = _c.signature, message = _c.message;
6388
6334
  return [4 /*yield*/, this.request(AuthRoutes.signIn, {
6389
6335
  method: AuthRoutes.signIn.method,
6390
6336
  payload: {
@@ -6395,8 +6341,8 @@ var PasskeyService = /** @class */ (function () {
6395
6341
  passkeyChallengeResponse: passkeyCredential,
6396
6342
  },
6397
6343
  })];
6398
- case 6:
6399
- singInResponse = _f.sent();
6344
+ case 5:
6345
+ singInResponse = _g.sent();
6400
6346
  if (!singInResponse || singInResponse.error) {
6401
6347
  throw new Error('Passkey authentication failed. Please try again.');
6402
6348
  }
@@ -6405,13 +6351,13 @@ var PasskeyService = /** @class */ (function () {
6405
6351
  deviceKeyPair: deviceKeyPair,
6406
6352
  passkeyCredential: passkeyCredential,
6407
6353
  })];
6408
- case 7:
6409
- _f.sent();
6354
+ case 6:
6355
+ _g.sent();
6410
6356
  return [2 /*return*/, __assign(__assign({}, singInResponse), { prfValue: credentialsKeyPair.prfValue })];
6411
- case 8:
6412
- error_2 = _f.sent();
6357
+ case 7:
6358
+ error_2 = _g.sent();
6413
6359
  throw this.authenticator.handlePasskeyError(error_2);
6414
- case 9: return [2 /*return*/];
6360
+ case 8: return [2 /*return*/];
6415
6361
  }
6416
6362
  });
6417
6363
  });
@@ -6425,13 +6371,13 @@ var PasskeyService = /** @class */ (function () {
6425
6371
  */
6426
6372
  PasskeyService.prototype.register = function (_a) {
6427
6373
  return __awaiter(this, arguments, void 0, function (_b) {
6428
- var _c, signature, message, extensions, firstSalt, updatedOptions, passkeyCredential, credentialsKeyPair, singUpResponse, encryptedNewDevicePrivateKey, error_3;
6429
- var _d, _e, _f;
6374
+ var _c, signature, message, parsedOptions, updatedOptions, passkeyCredential, credentialsKeyPair, singUpResponse, encryptedNewDevicePrivateKey, error_3;
6375
+ var _d, _e, _f, _g;
6430
6376
  var deviceKeyPair = _b.deviceKeyPair, challengeResponse = _b.challengeResponse;
6431
- return __generator(this, function (_g) {
6432
- switch (_g.label) {
6377
+ return __generator(this, function (_h) {
6378
+ switch (_h.label) {
6433
6379
  case 0:
6434
- _g.trys.push([0, 7, , 8]);
6380
+ _h.trys.push([0, 7, , 8]);
6435
6381
  if (!challengeResponse || !challengeResponse.options)
6436
6382
  throw new Error('Passkey challenge could not be retrieved, please try again later.');
6437
6383
  return [4 /*yield*/, this.cipher.sign({
@@ -6439,25 +6385,24 @@ var PasskeyService = /** @class */ (function () {
6439
6385
  signingKey: deviceKeyPair.privateKey,
6440
6386
  })];
6441
6387
  case 1:
6442
- _c = _g.sent(), signature = _c.signature, message = _c.message;
6443
- extensions = challengeResponse.options.extensions;
6444
- firstSalt = new Uint8Array((_e = (_d = extensions.prf) === null || _d === void 0 ? void 0 : _d.eval) === null || _e === void 0 ? void 0 : _e.first);
6445
- updatedOptions = __assign(__assign({}, challengeResponse.options), { extensions: __assign(__assign({}, extensions), { prf: {
6388
+ _c = _h.sent(), signature = _c.signature, message = _c.message;
6389
+ parsedOptions = this.preparePasskeyCreationOptions(challengeResponse.options);
6390
+ updatedOptions = __assign(__assign({}, challengeResponse.options), { extensions: __assign(__assign({}, parsedOptions.extensions), { prf: {
6446
6391
  eval: {
6447
- first: firstSalt,
6392
+ first: (_f = (_e = (_d = parsedOptions.extensions) === null || _d === void 0 ? void 0 : _d.prf) === null || _e === void 0 ? void 0 : _e.eval) === null || _f === void 0 ? void 0 : _f.first,
6448
6393
  },
6449
6394
  } }) });
6450
6395
  return [4 /*yield*/, this.authenticator.register({
6451
6396
  optionsJSON: updatedOptions,
6452
6397
  })];
6453
6398
  case 2:
6454
- passkeyCredential = _g.sent();
6455
- if (!((_f = passkeyCredential.clientExtensionResults.prf) === null || _f === void 0 ? void 0 : _f.enabled)) {
6399
+ passkeyCredential = _h.sent();
6400
+ if (!((_g = passkeyCredential.clientExtensionResults.prf) === null || _g === void 0 ? void 0 : _g.enabled)) {
6456
6401
  throw new Error('Device is not compatible with this feature. Try using a different authentication method.');
6457
6402
  }
6458
6403
  return [4 /*yield*/, this.handleCredentialsCreationFromPrfExtension(passkeyCredential)];
6459
6404
  case 3:
6460
- credentialsKeyPair = _g.sent();
6405
+ credentialsKeyPair = _h.sent();
6461
6406
  return [4 /*yield*/, this.request(AuthRoutes.signUp, {
6462
6407
  method: AuthRoutes.signUp.method,
6463
6408
  payload: {
@@ -6469,7 +6414,7 @@ var PasskeyService = /** @class */ (function () {
6469
6414
  },
6470
6415
  })];
6471
6416
  case 4:
6472
- singUpResponse = _g.sent();
6417
+ singUpResponse = _h.sent();
6473
6418
  if (!singUpResponse || singUpResponse.error) {
6474
6419
  throw new Error('Passkey authentication failed. Please try again.');
6475
6420
  }
@@ -6478,7 +6423,7 @@ var PasskeyService = /** @class */ (function () {
6478
6423
  encryptionKey: credentialsKeyPair.publicKey,
6479
6424
  })];
6480
6425
  case 5:
6481
- encryptedNewDevicePrivateKey = _g.sent();
6426
+ encryptedNewDevicePrivateKey = _h.sent();
6482
6427
  if (!encryptedNewDevicePrivateKey) {
6483
6428
  throw new Error('Failed to encrypt the device private key.');
6484
6429
  }
@@ -6491,10 +6436,10 @@ var PasskeyService = /** @class */ (function () {
6491
6436
  passkeyCredential: passkeyCredential,
6492
6437
  })];
6493
6438
  case 6:
6494
- _g.sent();
6439
+ _h.sent();
6495
6440
  return [2 /*return*/, __assign(__assign({}, singUpResponse), { prfValue: credentialsKeyPair.prfValue })];
6496
6441
  case 7:
6497
- error_3 = _g.sent();
6442
+ error_3 = _h.sent();
6498
6443
  throw this.authenticator.handlePasskeyError(error_3);
6499
6444
  case 8: return [2 /*return*/];
6500
6445
  }
@@ -6611,7 +6556,6 @@ var PasskeyService = /** @class */ (function () {
6611
6556
  case 0:
6612
6557
  _e.trys.push([0, 2, , 3]);
6613
6558
  extensions = passkeyCredential.clientExtensionResults;
6614
- logger.debug('extensions', extensions);
6615
6559
  if (!extensions || (!((_a = extensions.prf) === null || _a === void 0 ? void 0 : _a.enabled) && !((_c = (_b = extensions.prf) === null || _b === void 0 ? void 0 : _b.results) === null || _c === void 0 ? void 0 : _c.first))) {
6616
6560
  throw new Error('Device is not compatible with this feature. Try using a different authentication method.');
6617
6561
  }
@@ -6723,7 +6667,7 @@ var AuthService = /** @class */ (function (_super) {
6723
6667
  * @description
6724
6668
  * It registers the client's device public key with Wallaby server and gets back a random message string.
6725
6669
  * The random string will be hashed and signed by the client's device private key and sent back to Wallaby for verification.
6726
- * @param { publicKey: string; privateKey: string } deviceAuthKeys the device key pair to register with wallaby.
6670
+ * @param { AsymmetricKeyPair } deviceAuthKeys the device key pair to register with wallaby.
6727
6671
  * @returns the messaged, the hash, and the signature using the passed private key.
6728
6672
  */
6729
6673
  AuthService.prototype.getSignature = function (deviceAuthKeys) {
@@ -6842,11 +6786,9 @@ var AuthService = /** @class */ (function (_super) {
6842
6786
  case exports.AuthType.Password: return [3 /*break*/, 3];
6843
6787
  }
6844
6788
  return [3 /*break*/, 6];
6845
- case 1:
6846
- logger.log('SDK::AuthService::signIn::passkey');
6847
- return [4 /*yield*/, this.handleSignInWithPasskey({
6848
- input: input,
6849
- })];
6789
+ case 1: return [4 /*yield*/, this.handleSignInWithPasskey({
6790
+ input: input,
6791
+ })];
6850
6792
  case 2:
6851
6793
  authentication = _b.sent();
6852
6794
  if (!authentication) {
@@ -6975,7 +6917,6 @@ var AuthService = /** @class */ (function (_super) {
6975
6917
  return [4 /*yield*/, this.storageService.save(exports.LocalStorageItems.ClientAuthPublicKey, devicePublicKey)];
6976
6918
  case 4:
6977
6919
  _c.sent();
6978
- logger.debug('SDK::AuthService::handleSignInWithPass::input', input);
6979
6920
  return [4 /*yield*/, this.getSignature(deviceKeyPair)];
6980
6921
  case 5:
6981
6922
  signatureMessage = _c.sent();
@@ -7197,7 +7138,7 @@ var AuthService = /** @class */ (function (_super) {
7197
7138
  * Signs up the user using the password encryption mechanism.
7198
7139
  * @param { SignatureMessageResponse } signatureMessage - signature message response from `this.getSignature`.
7199
7140
  * @param { AuthenticationRequest } input - The authentication request containing user details and encryption mechanism.
7200
- * @param { publicKey: string; privateKey: string } deviceAuthKeys - The device key pair to register with Wallaby.
7141
+ * @param { AsymmetricKeyPair } deviceAuthKeys - The device key pair to register with Wallaby.
7201
7142
  * @returns {Promise<AuthResponse>} - The authentication response containing user details and access token.
7202
7143
  * @throws Throws an error if the passkey creation fails.
7203
7144
  */
@@ -7212,7 +7153,6 @@ var AuthService = /** @class */ (function (_super) {
7212
7153
  if (!input.password) {
7213
7154
  throw new Error('Password is required.');
7214
7155
  }
7215
- logger.log('SDK::AuthService::handleSignUpWithPassword::deviceKeyPair', deviceKeyPair);
7216
7156
  return [4 /*yield*/, this.request(AuthRoutes.signUp, {
7217
7157
  method: AuthRoutes.signUp.method,
7218
7158
  payload: {
@@ -7244,7 +7184,6 @@ var AuthService = /** @class */ (function (_super) {
7244
7184
  })];
7245
7185
  case 2:
7246
7186
  encryptedDevicePrivKey = _b.sent();
7247
- logger.log('SDK::AuthService::handlePasskeyRegistration::deviceKeyPair', deviceKeyPair);
7248
7187
  if (encryptedDevicePrivKey) {
7249
7188
  this.storageService.saveInBulk([
7250
7189
  {
@@ -7279,6 +7218,42 @@ var AuthService = /** @class */ (function (_super) {
7279
7218
  });
7280
7219
  });
7281
7220
  };
7221
+ AuthService.prototype.getPasskeyCredentials = function () {
7222
+ return __awaiter(this, void 0, void 0, function () {
7223
+ var response, error_7;
7224
+ return __generator(this, function (_a) {
7225
+ switch (_a.label) {
7226
+ case 0:
7227
+ _a.trys.push([0, 2, , 3]);
7228
+ return [4 /*yield*/, this.request(AuthRoutes.getPasskeyCredentials, {
7229
+ method: AuthRoutes.getPasskeyCredentials.method,
7230
+ payload: {},
7231
+ })];
7232
+ case 1:
7233
+ response = _a.sent();
7234
+ if (!response)
7235
+ throw new Error('Error fetching passkey credentials.');
7236
+ if (response.error)
7237
+ throw new Error(response.error);
7238
+ if (!response.credentials.length)
7239
+ throw new Error('No passkey credentials found for this user.');
7240
+ return [2 /*return*/, response.credentials];
7241
+ case 2:
7242
+ error_7 = _a.sent();
7243
+ logger.error('SDK::AuthService::getPasskeyCredentials::error', error_7);
7244
+ // Handle both string errors and error objects
7245
+ if (typeof error_7 === 'string') {
7246
+ throw new Error(error_7);
7247
+ }
7248
+ if (error_7 && typeof error_7 === 'object' && 'message' in error_7) {
7249
+ throw new Error(error_7.message);
7250
+ }
7251
+ throw error_7;
7252
+ case 3: return [2 /*return*/];
7253
+ }
7254
+ });
7255
+ });
7256
+ };
7282
7257
  return AuthService;
7283
7258
  }(Base));
7284
7259
 
@@ -7305,10 +7280,6 @@ var WalletHandlersService = /** @class */ (function (_super) {
7305
7280
  })];
7306
7281
  case 1:
7307
7282
  _a = _g.sent(), signature = _a.signature, message = _a.message;
7308
- logger.info('SDK::handleImportWallet::signature', {
7309
- signature: signature,
7310
- message: message,
7311
- });
7312
7283
  if ((importWalletInput.returnWalletOption === exports.ReturnWalletOption.ReturnOnlyEncryptedShares ||
7313
7284
  importWalletInput.returnWalletOption === exports.ReturnWalletOption.ReturnBothEncryptedSharesAndSeed) &&
7314
7285
  !importWalletInput.keyShareOptions) {
@@ -7625,6 +7596,16 @@ var WalletHandlersService = /** @class */ (function (_super) {
7625
7596
  });
7626
7597
  });
7627
7598
  };
7599
+ /**
7600
+ *
7601
+ * @param encryptedKeyShares - Encrypted key shares that are encrypted with the wallabyAuthPublicKey.
7602
+ * @param walletId - The ID of the wallet for which the seed phrase is being constructed.
7603
+ * @param deviceAuthKeys - The device authentication key pair used to sign the request.
7604
+ * @description This function constructs the seed phrase from encrypted key shares.
7605
+ * It retrieves the seed phrase by sending a request to the Wallaby API with the encrypted key shares.
7606
+ * The shares should be encrypted with the wallabyAuthPublicKey before passing them into this function.
7607
+ * @returns The function returns the encrypted seed phrase wrapped with client device public key.
7608
+ */
7628
7609
  WalletHandlersService.prototype.handleConstructingSeedPhraseFromShares = function (_a) {
7629
7610
  return __awaiter(this, arguments, void 0, function (_b) {
7630
7611
  var _c, signature, message, retrieveSeedPhraseResponse, error_7;
@@ -7685,6 +7666,70 @@ var WalletService = /** @class */ (function (_super) {
7685
7666
  _this.userId = config.userId;
7686
7667
  return _this;
7687
7668
  }
7669
+ /**
7670
+ * @public
7671
+ * @returns {boolean} Returns true if the device has a seed phrase.
7672
+ */
7673
+ WalletService.prototype.hasSeedPhraseOnDevice = function () {
7674
+ return __awaiter(this, void 0, void 0, function () {
7675
+ return __generator(this, function (_a) {
7676
+ switch (_a.label) {
7677
+ case 0: return [4 /*yield*/, this.storageService.checkSeedPhraseExists()];
7678
+ case 1: return [2 /*return*/, _a.sent()];
7679
+ }
7680
+ });
7681
+ });
7682
+ };
7683
+ /**
7684
+ * @public
7685
+ * @returns {boolean} Returns true if the device has a primary key share.
7686
+ */
7687
+ WalletService.prototype.hasPrimaryKeyShareOnDevice = function () {
7688
+ return __awaiter(this, void 0, void 0, function () {
7689
+ return __generator(this, function (_a) {
7690
+ switch (_a.label) {
7691
+ case 0: return [4 /*yield*/, this.storageService.checkPrimaryKeyShareExists()];
7692
+ case 1: return [2 /*return*/, _a.sent()];
7693
+ }
7694
+ });
7695
+ });
7696
+ };
7697
+ /**
7698
+ * @public
7699
+ * @returns {boolean} Returns true if the device has a backup key share.
7700
+ */
7701
+ WalletService.prototype.hasBackupKeyShareOnDevice = function () {
7702
+ return __awaiter(this, void 0, void 0, function () {
7703
+ return __generator(this, function (_a) {
7704
+ switch (_a.label) {
7705
+ case 0: return [4 /*yield*/, this.storageService.checkBackupKeyShareExists()];
7706
+ case 1: return [2 /*return*/, _a.sent()];
7707
+ }
7708
+ });
7709
+ });
7710
+ };
7711
+ /**
7712
+ * @public
7713
+ * @returns {boolean} Returns true if the device has a wallet (either seed phrase or primary key share).
7714
+ */
7715
+ WalletService.prototype.hasWalletOnDevice = function () {
7716
+ return __awaiter(this, void 0, void 0, function () {
7717
+ var _a;
7718
+ return __generator(this, function (_b) {
7719
+ switch (_b.label) {
7720
+ case 0: return [4 /*yield*/, this.hasSeedPhraseOnDevice()];
7721
+ case 1:
7722
+ _a = (_b.sent());
7723
+ if (_a) return [3 /*break*/, 3];
7724
+ return [4 /*yield*/, this.hasPrimaryKeyShareOnDevice()];
7725
+ case 2:
7726
+ _a = (_b.sent());
7727
+ _b.label = 3;
7728
+ case 3: return [2 /*return*/, _a];
7729
+ }
7730
+ });
7731
+ });
7732
+ };
7688
7733
  /**
7689
7734
  *
7690
7735
  * @public
@@ -7998,7 +8043,6 @@ var WalletService = /** @class */ (function (_super) {
7998
8043
  throw new Error('Failed to decrypt device private key');
7999
8044
  }
8000
8045
  clientAuthPubKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
8001
- logger.info('SDK::WalletService::import::clientAuthPubKey', clientAuthPubKey);
8002
8046
  return [4 /*yield*/, this.handlers.handleImportWallet({
8003
8047
  publicKey: clientAuthPubKey,
8004
8048
  privateKey: decryptedDevicePrivateKey,
@@ -8017,12 +8061,14 @@ var WalletService = /** @class */ (function (_super) {
8017
8061
  };
8018
8062
  WalletService.prototype.recover = function (input) {
8019
8063
  return __awaiter(this, void 0, void 0, function () {
8020
- var deviceAuthKeyPair, credentialsKeyPair, encryptedSeedPhrase, recoverWithSeedPhraseResponse, encryptedShares, encryptedSeed, error_4;
8021
- var _a, _b;
8022
- return __generator(this, function (_c) {
8023
- switch (_c.label) {
8064
+ var wallabyPublicKey_1, deviceAuthKeyPair, credentialsKeyPair, recoverWithSeedPhraseResponse, encryptedSeedPhrase, encryptedShares, encryptedSeed, wallabyBoundRecoverySeedPhrase, error_4;
8065
+ var _this = this;
8066
+ var _a, _b, _c;
8067
+ return __generator(this, function (_d) {
8068
+ switch (_d.label) {
8024
8069
  case 0:
8025
- _c.trys.push([0, 15, , 16]);
8070
+ _d.trys.push([0, 22, , 23]);
8071
+ wallabyPublicKey_1 = input.authenticationOptions.user.wallabyAuthPubKey;
8026
8072
  deviceAuthKeyPair = createIdentity();
8027
8073
  return [4 /*yield*/, this.cipher.getCredentialsKeyPair({
8028
8074
  authType: this.deviceAuthType,
@@ -8031,35 +8077,36 @@ var WalletService = /** @class */ (function (_super) {
8031
8077
  prfValue: input.authenticationOptions.prfValue,
8032
8078
  })];
8033
8079
  case 1:
8034
- credentialsKeyPair = _c.sent();
8080
+ credentialsKeyPair = _d.sent();
8035
8081
  return [4 /*yield*/, this.authService.storeDeviceKeyPair({
8036
8082
  deviceAuthKeyPair: deviceAuthKeyPair,
8037
8083
  credentialsKeyPair: credentialsKeyPair,
8038
8084
  })];
8039
8085
  case 2:
8040
- _c.sent();
8086
+ _d.sent();
8087
+ recoverWithSeedPhraseResponse = void 0;
8041
8088
  if (!input.seedPhrase) return [3 /*break*/, 10];
8042
- return [4 /*yield*/, encryptWithPublicKey(input.wallabyAuthPubKey, input.seedPhrase)];
8089
+ return [4 /*yield*/, encryptWithPublicKey(wallabyPublicKey_1, input.seedPhrase)];
8043
8090
  case 3:
8044
- encryptedSeedPhrase = _c.sent();
8091
+ encryptedSeedPhrase = _d.sent();
8045
8092
  return [4 /*yield*/, this.handlers.handleRecoverFromSeedPhrase({
8046
8093
  encryptedSeedPhrase: encryptedSeedPhrase,
8047
8094
  deviceAuthKeys: { publicKey: deviceAuthKeyPair.publicKey, privateKey: deviceAuthKeyPair.privateKey },
8048
8095
  })];
8049
8096
  case 4:
8050
- recoverWithSeedPhraseResponse = _c.sent();
8051
- if (!recoverWithSeedPhraseResponse.encryptedSeed) return [3 /*break*/, 6];
8097
+ recoverWithSeedPhraseResponse = _d.sent();
8098
+ if (!(input.seedPhrase && input.returnWalletOption !== exports.ReturnWalletOption.ReturnOnlyEncryptedShares)) return [3 /*break*/, 6];
8052
8099
  // will take care of encrypting and storing the seed phrase if needed.
8053
8100
  return [4 /*yield*/, this.handlers.handleSeedPhraseFromResponse({
8054
- encryptedSeed: recoverWithSeedPhraseResponse.encryptedSeed,
8101
+ encryptedSeed: encryptWithPublicKey(deviceAuthKeyPair.publicKey, input.seedPhrase), // usually this comes back from the API wrapped with the device pub.
8055
8102
  devicePrivateKey: deviceAuthKeyPair.privateKey,
8056
8103
  credentialsKeyPair: credentialsKeyPair,
8057
8104
  storeSeedPhrase: input.storeSeedPhrase,
8058
8105
  })];
8059
8106
  case 5:
8060
8107
  // will take care of encrypting and storing the seed phrase if needed.
8061
- _c.sent();
8062
- _c.label = 6;
8108
+ _d.sent();
8109
+ _d.label = 6;
8063
8110
  case 6:
8064
8111
  if (!((_a = recoverWithSeedPhraseResponse.shares) === null || _a === void 0 ? void 0 : _a.length)) return [3 /*break*/, 8];
8065
8112
  return [4 /*yield*/, this.handlers.handleKeySharesFromResponse({
@@ -8068,21 +8115,37 @@ var WalletService = /** @class */ (function (_super) {
8068
8115
  credentialsKeyPair: credentialsKeyPair,
8069
8116
  })];
8070
8117
  case 7:
8071
- _c.sent();
8072
- _c.label = 8;
8118
+ _d.sent();
8119
+ _d.label = 8;
8073
8120
  case 8: return [4 /*yield*/, this.authService.storeDeviceKeyPair({
8074
8121
  deviceAuthKeyPair: deviceAuthKeyPair,
8075
8122
  credentialsKeyPair: credentialsKeyPair,
8076
8123
  })];
8077
8124
  case 9:
8078
- _c.sent();
8125
+ _d.sent();
8079
8126
  return [2 /*return*/, recoverWithSeedPhraseResponse];
8080
8127
  case 10:
8081
- if (!input.decryptedShares) return [3 /*break*/, 13];
8082
- encryptedShares = (_b = input.decryptedShares) === null || _b === void 0 ? void 0 : _b.map(function (decryptedShare) {
8083
- return encryptWithPublicKey(input.wallabyAuthPubKey, decryptedShare);
8084
- });
8085
- if (!encryptedShares) {
8128
+ if (!input.decryptedShares) return [3 /*break*/, 20];
8129
+ return [4 /*yield*/, Promise.all((_b = input.decryptedShares) === null || _b === void 0 ? void 0 : _b.map(function (decryptedShare) { return __awaiter(_this, void 0, void 0, function () {
8130
+ var encrypted;
8131
+ return __generator(this, function (_a) {
8132
+ switch (_a.label) {
8133
+ case 0: return [4 /*yield*/, this.cipher.encrypt({
8134
+ data: decryptedShare,
8135
+ encryptionKey: wallabyPublicKey_1,
8136
+ })];
8137
+ case 1:
8138
+ encrypted = _a.sent();
8139
+ if (!encrypted) {
8140
+ throw new Error('Failed to encrypt share');
8141
+ }
8142
+ return [2 /*return*/, encrypted];
8143
+ }
8144
+ });
8145
+ }); }))];
8146
+ case 11:
8147
+ encryptedShares = _d.sent();
8148
+ if (!encryptedShares.length) {
8086
8149
  throw new Error('Decrypted shares are required');
8087
8150
  }
8088
8151
  return [4 /*yield*/, this.handlers.handleConstructingSeedPhraseFromShares({
@@ -8090,24 +8153,57 @@ var WalletService = /** @class */ (function (_super) {
8090
8153
  deviceAuthKeys: deviceAuthKeyPair,
8091
8154
  walletId: input.walletId,
8092
8155
  })];
8093
- case 11:
8094
- encryptedSeed = _c.sent();
8156
+ case 12:
8157
+ encryptedSeed = _d.sent();
8158
+ return [4 /*yield*/, this.cipher.flipEncryptedData({
8159
+ cipherText: encryptedSeed,
8160
+ decryptionKey: deviceAuthKeyPair.privateKey,
8161
+ encryptionKey: wallabyPublicKey_1,
8162
+ })];
8163
+ case 13:
8164
+ wallabyBoundRecoverySeedPhrase = _d.sent();
8165
+ return [4 /*yield*/, this.handlers.handleRecoverFromSeedPhrase({
8166
+ encryptedSeedPhrase: wallabyBoundRecoverySeedPhrase,
8167
+ deviceAuthKeys: { publicKey: deviceAuthKeyPair.publicKey, privateKey: deviceAuthKeyPair.privateKey },
8168
+ })];
8169
+ case 14:
8170
+ recoverWithSeedPhraseResponse = _d.sent();
8171
+ if (!recoverWithSeedPhraseResponse.encryptedSeed) return [3 /*break*/, 16];
8172
+ // will take care of encrypting and storing the seed phrase if needed.
8095
8173
  return [4 /*yield*/, this.handlers.handleSeedPhraseFromResponse({
8096
- encryptedSeed: encryptedSeed,
8174
+ encryptedSeed: recoverWithSeedPhraseResponse.encryptedSeed,
8097
8175
  devicePrivateKey: deviceAuthKeyPair.privateKey,
8098
8176
  credentialsKeyPair: credentialsKeyPair,
8099
8177
  storeSeedPhrase: input.storeSeedPhrase,
8100
8178
  })];
8101
- case 12:
8102
- _c.sent();
8103
- return [3 /*break*/, 14];
8104
- case 13: throw new Error('Decrypted seed phrase or shares are required to recover the wallet.');
8105
- case 14: return [2 /*return*/, { standardSeedPhrase: input.seedPhrase }];
8106
8179
  case 15:
8107
- error_4 = _c.sent();
8180
+ // will take care of encrypting and storing the seed phrase if needed.
8181
+ _d.sent();
8182
+ _d.label = 16;
8183
+ case 16:
8184
+ if (!((_c = recoverWithSeedPhraseResponse.shares) === null || _c === void 0 ? void 0 : _c.length)) return [3 /*break*/, 18];
8185
+ return [4 /*yield*/, this.handlers.handleKeySharesFromResponse({
8186
+ keyShares: recoverWithSeedPhraseResponse.shares,
8187
+ devicePrivateKey: deviceAuthKeyPair.privateKey,
8188
+ credentialsKeyPair: credentialsKeyPair,
8189
+ })];
8190
+ case 17:
8191
+ _d.sent();
8192
+ _d.label = 18;
8193
+ case 18: return [4 /*yield*/, this.authService.storeDeviceKeyPair({
8194
+ deviceAuthKeyPair: deviceAuthKeyPair,
8195
+ credentialsKeyPair: credentialsKeyPair,
8196
+ })];
8197
+ case 19:
8198
+ _d.sent();
8199
+ return [2 /*return*/, recoverWithSeedPhraseResponse];
8200
+ case 20: throw new Error('Decrypted seed phrase or shares are required to recover the wallet.');
8201
+ case 21: return [3 /*break*/, 23];
8202
+ case 22:
8203
+ error_4 = _d.sent();
8108
8204
  logger.error('SDK::Wallet::recover::error', error_4);
8109
8205
  return [2 /*return*/, Promise.reject(error_4)];
8110
- case 16: return [2 /*return*/];
8206
+ case 23: return [2 /*return*/];
8111
8207
  }
8112
8208
  });
8113
8209
  });
@@ -8186,51 +8282,132 @@ var WalletService = /** @class */ (function (_super) {
8186
8282
  */
8187
8283
  WalletService.prototype.changePassword = function (_a) {
8188
8284
  return __awaiter(this, arguments, void 0, function (_b) {
8189
- var decryptedDevicePrivateKey, clientSalt, decryptedSeedPhrase, error_6;
8285
+ var encryptedDevicePrivateKeyString, encryptedSeedPhraseString, encryptedPrimaryShareString, encryptedBackupShareString, clientSalt, oldCredentialsKeyPair, newCredentialsKeyPair, reWrappedDevicePrivateKey, parsedSeed, reWrappedSeedPhrase, parsedPrimaryShare, reWrappedPrimaryShare, parsedBackupShare, reWrappedBackupShare, error_6;
8190
8286
  var oldPassword = _b.oldPassword, newPassword = _b.newPassword;
8191
8287
  return __generator(this, function (_c) {
8192
8288
  switch (_c.label) {
8193
8289
  case 0:
8194
- _c.trys.push([0, 6, , 7]);
8195
- return [4 /*yield*/, this.storageService.getDecryptedPrivateKey(oldPassword)];
8290
+ _c.trys.push([0, 19, , 20]);
8291
+ return [4 /*yield*/, this.storageService.fetch(exports.LocalStorageItems.EncryptedDevicePrivateKey)];
8196
8292
  case 1:
8197
- decryptedDevicePrivateKey = _c.sent();
8198
- if (!decryptedDevicePrivateKey) {
8199
- throw new Error('Password is not valid, device private key could not be decrypted.');
8293
+ encryptedDevicePrivateKeyString = _c.sent();
8294
+ return [4 /*yield*/, this.storageService.fetch(exports.LocalStorageItems.EncryptedStandardSeedPhrase)];
8295
+ case 2:
8296
+ encryptedSeedPhraseString = _c.sent();
8297
+ return [4 /*yield*/, this.storageService.fetch(exports.LocalStorageItems.PrimaryDeviceKeyShare)];
8298
+ case 3:
8299
+ encryptedPrimaryShareString = _c.sent();
8300
+ return [4 /*yield*/, this.storageService.fetch(exports.LocalStorageItems.BackupDeviceKeyShare)];
8301
+ case 4:
8302
+ encryptedBackupShareString = _c.sent();
8303
+ // Ensure at least the device private key is present. Other items are optional.
8304
+ if (!encryptedDevicePrivateKeyString) {
8305
+ throw new Error('Could not locate client keys on this device.');
8200
8306
  }
8201
8307
  return [4 /*yield*/, this.authService.getUserSalt()];
8202
- case 2:
8308
+ case 5:
8203
8309
  clientSalt = _c.sent();
8204
- return [4 /*yield*/, this.storageService.getDecryptedSeedPhrase({
8310
+ return [4 /*yield*/, this.cipher.getCredentialsKeyPair({
8311
+ authType: this.deviceAuthType,
8205
8312
  password: oldPassword,
8206
- seedPhraseType: exports.SeedPhraseType.Standard,
8207
- getUserSalt: this.authService.getUserSalt,
8208
8313
  salt: clientSalt,
8209
8314
  })];
8210
- case 3:
8211
- decryptedSeedPhrase = _c.sent();
8212
- if (!decryptedSeedPhrase) {
8213
- throw new Error('Password is not valid, seed phrase could not be decrypted, please recover the wallet.');
8315
+ case 6:
8316
+ oldCredentialsKeyPair = _c.sent();
8317
+ if (!oldCredentialsKeyPair || !oldCredentialsKeyPair.privateKey) {
8318
+ throw new Error('Could not derive keys from old password. Please make sure the password is correct.');
8214
8319
  }
8215
- return [4 /*yield*/, this.storageService.setEncryptedPrivateKey(decryptedDevicePrivateKey, newPassword)];
8216
- case 4:
8217
- _c.sent();
8218
- return [4 /*yield*/, this.storageService.setEncryptedSeedPhrase({
8219
- decryptedSeedPhrase: decryptedSeedPhrase,
8220
- seedPhraseType: exports.SeedPhraseType.Standard,
8320
+ return [4 /*yield*/, this.cipher.getCredentialsKeyPair({
8321
+ authType: this.deviceAuthType,
8221
8322
  password: newPassword,
8222
- deviceAuthPublicKey: publicKeyByPrivateKey(decryptedDevicePrivateKey),
8223
- getUserSalt: this.authService.getUserSalt,
8224
8323
  salt: clientSalt,
8225
8324
  })];
8226
- case 5:
8325
+ case 7:
8326
+ newCredentialsKeyPair = _c.sent();
8327
+ if (!newCredentialsKeyPair || !newCredentialsKeyPair.publicKey) {
8328
+ throw new Error('Could not derive keys for new password.');
8329
+ }
8330
+ return [4 /*yield*/, this.cipher.flipEncryptedData({
8331
+ cipherText: JSON.parse(encryptedDevicePrivateKeyString),
8332
+ decryptionKey: oldCredentialsKeyPair.privateKey,
8333
+ encryptionKey: newCredentialsKeyPair.publicKey, // Corrected to use publicKey for encryption
8334
+ })];
8335
+ case 8:
8336
+ reWrappedDevicePrivateKey = _c.sent();
8337
+ if (!reWrappedDevicePrivateKey) {
8338
+ throw new Error('Failed to rewrap device private key');
8339
+ }
8340
+ return [4 /*yield*/, this.storageService.save(exports.LocalStorageItems.EncryptedDevicePrivateKey, JSON.stringify(reWrappedDevicePrivateKey))];
8341
+ case 9:
8227
8342
  _c.sent();
8228
- return [2 /*return*/, true];
8229
- case 6:
8343
+ if (!encryptedSeedPhraseString) return [3 /*break*/, 12];
8344
+ parsedSeed = safeJsonParse(encryptedSeedPhraseString);
8345
+ if (!parsedSeed) {
8346
+ throw new Error('Encrypted seed phrase could not be parsed');
8347
+ }
8348
+ return [4 /*yield*/, this.cipher.flipEncryptedData({
8349
+ cipherText: parsedSeed,
8350
+ decryptionKey: oldCredentialsKeyPair.privateKey,
8351
+ encryptionKey: newCredentialsKeyPair.publicKey,
8352
+ })];
8353
+ case 10:
8354
+ reWrappedSeedPhrase = _c.sent();
8355
+ if (!reWrappedSeedPhrase) {
8356
+ throw new Error('Failed to rewrap seed phrase');
8357
+ }
8358
+ return [4 /*yield*/, this.storageService.save(exports.LocalStorageItems.EncryptedStandardSeedPhrase, JSON.stringify(reWrappedSeedPhrase))];
8359
+ case 11:
8360
+ _c.sent();
8361
+ _c.label = 12;
8362
+ case 12:
8363
+ if (!encryptedPrimaryShareString) return [3 /*break*/, 15];
8364
+ parsedPrimaryShare = safeJsonParse(encryptedPrimaryShareString);
8365
+ if (!parsedPrimaryShare) {
8366
+ throw new Error('Encrypted primary share could not be parsed');
8367
+ }
8368
+ return [4 /*yield*/, this.cipher.flipEncryptedData({
8369
+ cipherText: parsedPrimaryShare,
8370
+ decryptionKey: oldCredentialsKeyPair.privateKey,
8371
+ encryptionKey: newCredentialsKeyPair.publicKey,
8372
+ })];
8373
+ case 13:
8374
+ reWrappedPrimaryShare = _c.sent();
8375
+ if (!reWrappedPrimaryShare) {
8376
+ throw new Error('Failed to rewrap primary share');
8377
+ }
8378
+ return [4 /*yield*/, this.storageService.save(exports.LocalStorageItems.PrimaryDeviceKeyShare, JSON.stringify(reWrappedPrimaryShare))];
8379
+ case 14:
8380
+ _c.sent();
8381
+ _c.label = 15;
8382
+ case 15:
8383
+ if (!encryptedBackupShareString) return [3 /*break*/, 18];
8384
+ parsedBackupShare = safeJsonParse(encryptedBackupShareString);
8385
+ if (!parsedBackupShare) {
8386
+ throw new Error('Encrypted backup share could not be parsed');
8387
+ }
8388
+ return [4 /*yield*/, this.cipher.flipEncryptedData({
8389
+ cipherText: parsedBackupShare,
8390
+ decryptionKey: oldCredentialsKeyPair.privateKey,
8391
+ encryptionKey: newCredentialsKeyPair.publicKey,
8392
+ })];
8393
+ case 16:
8394
+ reWrappedBackupShare = _c.sent();
8395
+ if (!reWrappedBackupShare) {
8396
+ throw new Error('Failed to rewrap backup share');
8397
+ }
8398
+ return [4 /*yield*/, this.storageService.save(exports.LocalStorageItems.BackupDeviceKeyShare, JSON.stringify(reWrappedBackupShare))];
8399
+ case 17:
8400
+ _c.sent();
8401
+ _c.label = 18;
8402
+ case 18: return [2 /*return*/, true];
8403
+ case 19:
8230
8404
  error_6 = _c.sent();
8231
8405
  logger.error('SDK::Wallet::changePassword::error', error_6);
8232
- return [2 /*return*/, Promise.reject(false)];
8233
- case 7: return [2 /*return*/];
8406
+ if (error_6 instanceof Error) {
8407
+ return [2 /*return*/, Promise.reject(error_6)];
8408
+ }
8409
+ return [2 /*return*/, Promise.reject(new Error(String(error_6)))];
8410
+ case 20: return [2 /*return*/];
8234
8411
  }
8235
8412
  });
8236
8413
  });
@@ -8314,7 +8491,6 @@ var WalletService = /** @class */ (function (_super) {
8314
8491
  throw new Error('Failed to decrypt device private key');
8315
8492
  }
8316
8493
  clientAuthPubKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
8317
- logger.info('SDK::Wallet::getAlgorandSeedPhrase::clientAuthPubKey', clientAuthPubKey);
8318
8494
  reference = uuid.v4();
8319
8495
  return [4 /*yield*/, this.authService.getSignature({
8320
8496
  publicKey: clientAuthPubKey,
@@ -8322,7 +8498,6 @@ var WalletService = /** @class */ (function (_super) {
8322
8498
  })];
8323
8499
  case 9:
8324
8500
  signatureMessage = _b.sent();
8325
- logger.info('SDK::Wallet::getAlgorandSeedPhrase::signatureMessage', signatureMessage);
8326
8501
  message = signatureMessage.message, signature = signatureMessage.signature;
8327
8502
  return [4 /*yield*/, this.request(WalletRoutes.convertMnemonicSeedPhrase, {
8328
8503
  method: WalletRoutes.convertMnemonicSeedPhrase.method,
@@ -8531,9 +8706,283 @@ var WalletService = /** @class */ (function (_super) {
8531
8706
  });
8532
8707
  });
8533
8708
  };
8534
- return WalletService;
8535
- }(Base));
8536
-
8709
+ WalletService.prototype.generateWalletAddresses = function (input) {
8710
+ return __awaiter(this, void 0, void 0, function () {
8711
+ var walletId, storedSeedPhrase, primaryKeyShare, devicePrivateKey, transportSeed, transportKeyShare, parsedDevicePrivateKey, parsedStoredSeedPhrase, parsedPrimaryKeyShare, derivedCredentialsKeyPair, decryptedDevicePrivateKey, devicePublicKey, _a, signature, message, response, error_9;
8712
+ return __generator(this, function (_b) {
8713
+ switch (_b.label) {
8714
+ case 0:
8715
+ walletId = input.walletId;
8716
+ if (!walletId) {
8717
+ throw new Error('Missing required parameters');
8718
+ }
8719
+ _b.label = 1;
8720
+ case 1:
8721
+ _b.trys.push([1, 14, , 15]);
8722
+ return [4 /*yield*/, this.storageService.fetch(exports.LocalStorageItems.EncryptedStandardSeedPhrase)];
8723
+ case 2:
8724
+ storedSeedPhrase = _b.sent();
8725
+ return [4 /*yield*/, this.storageService.fetch(exports.LocalStorageItems.PrimaryDeviceKeyShare)];
8726
+ case 3:
8727
+ primaryKeyShare = _b.sent();
8728
+ return [4 /*yield*/, this.storageService.fetch(exports.LocalStorageItems.EncryptedDevicePrivateKey)];
8729
+ case 4:
8730
+ devicePrivateKey = _b.sent();
8731
+ transportSeed = undefined;
8732
+ transportKeyShare = undefined;
8733
+ if (!devicePrivateKey) {
8734
+ throw new Error('Missing device private key on this device, please recover your wallet first.');
8735
+ }
8736
+ parsedDevicePrivateKey = safeJsonParse(devicePrivateKey);
8737
+ if (!parsedDevicePrivateKey) {
8738
+ throw new Error('Failed to parse stored seed or primary key share');
8739
+ }
8740
+ if (!storedSeedPhrase) return [3 /*break*/, 6];
8741
+ parsedStoredSeedPhrase = safeJsonParse(storedSeedPhrase);
8742
+ if (!parsedStoredSeedPhrase) {
8743
+ throw new Error('Failed to parse stored seed phrase');
8744
+ }
8745
+ return [4 /*yield*/, this.cipher.prepareStoredDataForTransport({
8746
+ storedEncryptedData: parsedStoredSeedPhrase,
8747
+ encryptedDevicePrivateKey: parsedDevicePrivateKey,
8748
+ wallabyPublicKey: input.authenticationOptions.user.wallabyAuthPubKey,
8749
+ options: {
8750
+ authType: this.deviceAuthType,
8751
+ password: input.authenticationOptions.password,
8752
+ salt: input.authenticationOptions.clientSalt,
8753
+ prfValue: input.authenticationOptions.prfValue,
8754
+ },
8755
+ })];
8756
+ case 5:
8757
+ transportSeed = _b.sent();
8758
+ return [3 /*break*/, 9];
8759
+ case 6:
8760
+ if (!primaryKeyShare) return [3 /*break*/, 8];
8761
+ parsedPrimaryKeyShare = safeJsonParse(primaryKeyShare);
8762
+ if (!parsedPrimaryKeyShare) {
8763
+ throw new Error('Failed to parse primary key share');
8764
+ }
8765
+ return [4 /*yield*/, this.cipher.prepareStoredDataForTransport({
8766
+ storedEncryptedData: parsedPrimaryKeyShare,
8767
+ encryptedDevicePrivateKey: parsedDevicePrivateKey,
8768
+ wallabyPublicKey: input.authenticationOptions.user.wallabyAuthPubKey,
8769
+ options: {
8770
+ authType: this.deviceAuthType,
8771
+ password: input.authenticationOptions.password,
8772
+ salt: input.authenticationOptions.clientSalt,
8773
+ prfValue: input.authenticationOptions.prfValue,
8774
+ },
8775
+ })];
8776
+ case 7:
8777
+ transportKeyShare = _b.sent();
8778
+ return [3 /*break*/, 9];
8779
+ case 8: throw new Error('Missing stored seed phrase or primary key share on this device, please recover your wallet first.');
8780
+ case 9: return [4 /*yield*/, this.cipher.getCredentialsKeyPair({
8781
+ authType: this.deviceAuthType,
8782
+ password: input.authenticationOptions.password,
8783
+ salt: input.authenticationOptions.clientSalt,
8784
+ prfValue: input.authenticationOptions.prfValue,
8785
+ })];
8786
+ case 10:
8787
+ derivedCredentialsKeyPair = _b.sent();
8788
+ return [4 /*yield*/, this.cipher.decrypt({
8789
+ cipherText: parsedDevicePrivateKey,
8790
+ decryptionKey: derivedCredentialsKeyPair.privateKey,
8791
+ })];
8792
+ case 11:
8793
+ decryptedDevicePrivateKey = _b.sent();
8794
+ devicePublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
8795
+ return [4 /*yield*/, this.authService.getSignature({
8796
+ privateKey: decryptedDevicePrivateKey,
8797
+ publicKey: devicePublicKey,
8798
+ })];
8799
+ case 12:
8800
+ _a = _b.sent(), signature = _a.signature, message = _a.message;
8801
+ return [4 /*yield*/, this.request(WalletRoutes.generateWalletAddresses, {
8802
+ method: WalletRoutes.generateWalletAddresses.method,
8803
+ payload: {
8804
+ walletId: walletId,
8805
+ signature: signature,
8806
+ message: message,
8807
+ clientAuthPubKey: devicePublicKey,
8808
+ encryptedSeed: transportSeed !== null && transportSeed !== void 0 ? transportSeed : undefined,
8809
+ encryptedShares: transportKeyShare ? [transportKeyShare] : undefined,
8810
+ },
8811
+ })];
8812
+ case 13:
8813
+ response = _b.sent();
8814
+ if (!response || response.errors) {
8815
+ throw new Error(response.errors);
8816
+ }
8817
+ return [2 /*return*/, response];
8818
+ case 14:
8819
+ error_9 = _b.sent();
8820
+ logger.error('SDK::Wallet::generateWalletAddresses::error', error_9);
8821
+ return [2 /*return*/, Promise.reject(error_9)];
8822
+ case 15: return [2 /*return*/];
8823
+ }
8824
+ });
8825
+ });
8826
+ };
8827
+ /**
8828
+ * Detects and migrates legacy/v1 storage items to v2 format.
8829
+ * This function should be called in methods that use password as input when v2 items are missing.
8830
+ * It will look for legacy storage items first, then v1 if legacy not found,
8831
+ * decrypt them using appropriate decryption methods, and call wallet.recover() to create new v2 keys.
8832
+ */
8833
+ WalletService.prototype.handleUpdateToV2 = function (_a) {
8834
+ return __awaiter(this, arguments, void 0, function (_b) {
8835
+ var v2EncryptedDevicePrivateKey, v2EncryptedSeed, v2EncryptedPrimaryDeviceShare, clientSalt_1, legacySeedPhrase_1, legacyPrivateKey, legacyEncryptedSeed, legacyEncryptedPrivateKey, decryptedPrivateKey, decryptedOnceSeed, parsedDecryptedSeed, v1EncryptedSeed, v1EncryptedPrivateKey, error_10, error_11;
8836
+ var _this = this;
8837
+ var password = _b.password, walletId = _b.walletId;
8838
+ return __generator(this, function (_c) {
8839
+ switch (_c.label) {
8840
+ case 0:
8841
+ _c.trys.push([0, 19, , 20]);
8842
+ logger.info('SDK::WalletService::handleUpdateToV2::starting migration check');
8843
+ return [4 /*yield*/, this.storageService.fetch(exports.LocalStorageItems.EncryptedDevicePrivateKey)];
8844
+ case 1:
8845
+ v2EncryptedDevicePrivateKey = _c.sent();
8846
+ return [4 /*yield*/, this.storageService.fetch(exports.LocalStorageItems.EncryptedStandardSeedPhrase)];
8847
+ case 2:
8848
+ v2EncryptedSeed = _c.sent();
8849
+ return [4 /*yield*/, this.storageService.fetch(exports.LocalStorageItems.PrimaryDeviceKeyShare)];
8850
+ case 3:
8851
+ v2EncryptedPrimaryDeviceShare = _c.sent();
8852
+ if (v2EncryptedDevicePrivateKey && v2EncryptedSeed && v2EncryptedPrimaryDeviceShare) {
8853
+ logger.info('SDK::WalletService::handleUpdateToV2::V2 items already exist, no migration needed');
8854
+ // we don't need to throw any errors, just continue with rest of flow.
8855
+ return [2 /*return*/];
8856
+ }
8857
+ if (!password) {
8858
+ throw new Error('Password is required for migration to v2 storage format');
8859
+ }
8860
+ return [4 /*yield*/, this.authService.getUserSalt()];
8861
+ case 4:
8862
+ clientSalt_1 = _c.sent();
8863
+ legacyPrivateKey = void 0;
8864
+ return [4 /*yield*/, this.storageService.getFromDeviceStorage("".concat(exports.LegacyKeyNames.EncryptedSeed, "_").concat(this.userId))];
8865
+ case 5:
8866
+ legacyEncryptedSeed = _c.sent();
8867
+ return [4 /*yield*/, this.storageService.getFromDeviceStorage("".concat(exports.LegacyKeyNames.EncryptedPrivateKey, "_").concat(this.userId))];
8868
+ case 6:
8869
+ legacyEncryptedPrivateKey = _c.sent();
8870
+ if (!(legacyEncryptedSeed && legacyEncryptedPrivateKey)) return [3 /*break*/, 7];
8871
+ logger.info('SDK::WalletService::handleUpdateToV2::Found legacy storage items, attempting migration');
8872
+ try {
8873
+ decryptedPrivateKey = cryptoJs.AES.decrypt(legacyEncryptedPrivateKey, "".concat(clientSalt_1).concat(password));
8874
+ decryptedOnceSeed = cryptoJs.AES.decrypt(legacyEncryptedSeed, "".concat(clientSalt_1).concat(password));
8875
+ parsedDecryptedSeed = safeJsonParse(decryptedOnceSeed.toString(cryptoJs.enc.Utf8));
8876
+ if (!parsedDecryptedSeed) {
8877
+ throw new Error('Failed to parse legacy decrypted data');
8878
+ }
8879
+ legacyPrivateKey = decryptedPrivateKey.toString(cryptoJs.enc.Utf8);
8880
+ legacySeedPhrase_1 = decryptWithPrivateKey(legacyPrivateKey, parsedDecryptedSeed);
8881
+ if (!legacySeedPhrase_1 || !legacyPrivateKey) {
8882
+ throw new Error('Failed to decrypt legacy items with provided password');
8883
+ }
8884
+ logger.info('SDK::WalletService::handleUpdateToV2::Successfully decrypted legacy items');
8885
+ }
8886
+ catch (error) {
8887
+ logger.error('SDK::WalletService::handleUpdateToV2::Failed to decrypt legacy items', error);
8888
+ throw new Error('Could not decrypt legacy storage items. Please verify your password.');
8889
+ }
8890
+ return [3 /*break*/, 16];
8891
+ case 7: return [4 /*yield*/, this.storageService.getEncryptedSeedPhrase(exports.SeedPhraseType.Standard)];
8892
+ case 8:
8893
+ v1EncryptedSeed = _c.sent();
8894
+ return [4 /*yield*/, this.storageService.getEncryptedPrivateKey()];
8895
+ case 9:
8896
+ v1EncryptedPrivateKey = _c.sent();
8897
+ if (!(v1EncryptedSeed && v1EncryptedPrivateKey)) return [3 /*break*/, 15];
8898
+ logger.info('SDK::WalletService::handleUpdateToV2::Found V1 storage items, attempting migration');
8899
+ _c.label = 10;
8900
+ case 10:
8901
+ _c.trys.push([10, 13, , 14]);
8902
+ return [4 /*yield*/, this.storageService.getDecryptedSeedPhrase({
8903
+ password: password,
8904
+ seedPhraseType: exports.SeedPhraseType.Standard,
8905
+ getUserSalt: function () { return __awaiter(_this, void 0, void 0, function () { var _a; return __generator(this, function (_b) {
8906
+ switch (_b.label) {
8907
+ case 0:
8908
+ _a = clientSalt_1;
8909
+ if (_a) return [3 /*break*/, 2];
8910
+ return [4 /*yield*/, this.authService.getUserSalt()];
8911
+ case 1:
8912
+ _a = (_b.sent());
8913
+ _b.label = 2;
8914
+ case 2: return [2 /*return*/, _a];
8915
+ }
8916
+ }); }); },
8917
+ })];
8918
+ case 11:
8919
+ // Decrypt V1 items using storage service method (handles double encryption)
8920
+ legacySeedPhrase_1 = _c.sent();
8921
+ return [4 /*yield*/, this.storageService.getDecryptedPrivateKey(password)];
8922
+ case 12:
8923
+ // For V1 format, private key is encrypted with just the password (not salt+password like legacy)
8924
+ legacyPrivateKey = _c.sent();
8925
+ if (!legacySeedPhrase_1 || !legacyPrivateKey) {
8926
+ throw new Error('Failed to decrypt V1 items with provided password');
8927
+ }
8928
+ logger.info('SDK::WalletService::handleUpdateToV2::Successfully decrypted V1 items');
8929
+ return [3 /*break*/, 14];
8930
+ case 13:
8931
+ error_10 = _c.sent();
8932
+ logger.error('SDK::WalletService::handleUpdateToV2::Failed to decrypt V1 items', error_10);
8933
+ throw new Error('Could not decrypt V1 storage items. Please verify your password.');
8934
+ case 14: return [3 /*break*/, 16];
8935
+ case 15:
8936
+ logger.info('SDK::WalletService::handleUpdateToV2::No legacy or V1 items found to migrate');
8937
+ throw new Error('No legacy or V1 storage items found. Please recover your wallet using the seed phrase.');
8938
+ case 16:
8939
+ if (!legacySeedPhrase_1) return [3 /*break*/, 18];
8940
+ logger.info('SDK::WalletService::handleUpdateToV2::Initiating wallet recovery for V2 migration');
8941
+ logger.info('SDK::WalletService::handleUpdateToV2::Migration data prepared');
8942
+ logger.info('SDK::WalletService::handleUpdateToV2::Seed phrase available:', !!legacySeedPhrase_1);
8943
+ return [4 /*yield*/, this.authService.signIn({ password: password }).then(function (authResponse) { return __awaiter(_this, void 0, void 0, function () {
8944
+ return __generator(this, function (_a) {
8945
+ switch (_a.label) {
8946
+ case 0: return [4 /*yield*/, this.recover({
8947
+ authenticationOptions: __assign(__assign({}, authResponse), { password: password }),
8948
+ walletId: walletId,
8949
+ seedPhrase: legacySeedPhrase_1,
8950
+ storeSeedPhrase: true,
8951
+ returnWalletOption: exports.ReturnWalletOption.ReturnOnlyEncryptedSeedPhrase,
8952
+ })];
8953
+ case 1:
8954
+ _a.sent();
8955
+ logger.info('SDK::WalletService::handleUpdateToV2::Migration completed successfully');
8956
+ return [2 /*return*/];
8957
+ }
8958
+ });
8959
+ }); })];
8960
+ case 17: return [2 /*return*/, _c.sent()];
8961
+ case 18: return [3 /*break*/, 20];
8962
+ case 19:
8963
+ error_11 = _c.sent();
8964
+ logger.error('SDK::WalletService::handleUpdateToV2::Migration failed', error_11);
8965
+ throw error_11;
8966
+ case 20: return [2 /*return*/];
8967
+ }
8968
+ });
8969
+ });
8970
+ };
8971
+ WalletService.prototype.clearDevice = function () {
8972
+ return __awaiter(this, void 0, void 0, function () {
8973
+ return __generator(this, function (_a) {
8974
+ switch (_a.label) {
8975
+ case 0: return [4 /*yield*/, this.storageService.clearLocalStorage()];
8976
+ case 1:
8977
+ _a.sent();
8978
+ return [2 /*return*/];
8979
+ }
8980
+ });
8981
+ });
8982
+ };
8983
+ return WalletService;
8984
+ }(Base));
8985
+
8537
8986
  /**
8538
8987
  * Sanitizes a Sui object ID by removing any part of the string after '::'.
8539
8988
  *
@@ -8558,8 +9007,35 @@ var WalletDataService = /** @class */ (function (_super) {
8558
9007
  function WalletDataService(config) {
8559
9008
  var _this = _super.call(this, config) || this;
8560
9009
  _this.userId = config.userId;
9010
+ _this.walletService = new WalletService(config);
8561
9011
  return _this;
8562
9012
  }
9013
+ /**
9014
+ * @description Validates the wallet address info for a given blockchain.
9015
+ * @param { WalletAddressInfo } walletAddressInfo The wallet address info object containing addresses for different blockchains.
9016
+ * @param { BlockchainName } blockchainName The name of the blockchain to validate against.
9017
+ * @returns { boolean } Returns true if the wallet address info is valid for the given blockchain, otherwise throws an error.
9018
+ */
9019
+ WalletDataService.prototype.validateWalletAddressInfo = function (walletAddressInfo, blockchainName) {
9020
+ switch (blockchainName) {
9021
+ case exports.BlockchainName.Avalanche:
9022
+ case exports.BlockchainName.Ethereum:
9023
+ case exports.BlockchainName.Bsc:
9024
+ case exports.BlockchainName.Base:
9025
+ case exports.BlockchainName.Polygon:
9026
+ return !!walletAddressInfo.evmAddress && addressValidator.isEvmAddress(walletAddressInfo.evmAddress);
9027
+ case exports.BlockchainName.Bitcoin:
9028
+ return !!walletAddressInfo.btcAddress && addressValidator.isBtcAddress(walletAddressInfo.btcAddress);
9029
+ case exports.BlockchainName.Algorand:
9030
+ return !!walletAddressInfo.algoAddress && addressValidator.isAlgoAddress(walletAddressInfo.algoAddress);
9031
+ case exports.BlockchainName.Sui:
9032
+ return !!walletAddressInfo.suiAddress && addressValidator.isSUIAddress(walletAddressInfo.suiAddress);
9033
+ case exports.BlockchainName.Injective:
9034
+ return !!walletAddressInfo.injAddress && addressValidator.isInjectiveAddress(walletAddressInfo.injAddress);
9035
+ default:
9036
+ throw new Error("Unsupported blockchain: ".concat(blockchainName));
9037
+ }
9038
+ };
8563
9039
  /**
8564
9040
  *
8565
9041
  * @public
@@ -8592,7 +9068,7 @@ var WalletDataService = /** @class */ (function (_super) {
8592
9068
  return [2 /*return*/, response];
8593
9069
  case 2:
8594
9070
  error_1 = _c.sent();
8595
- logger.error('SDK::Wallet::getTokenBalance::error', error_1);
9071
+ logger.error('SDK::WalletDataService::getTokenBalance::error', error_1);
8596
9072
  return [2 /*return*/, Promise.reject(error_1)];
8597
9073
  case 3: return [2 /*return*/];
8598
9074
  }
@@ -8631,7 +9107,7 @@ var WalletDataService = /** @class */ (function (_super) {
8631
9107
  return [2 /*return*/, response];
8632
9108
  case 2:
8633
9109
  error_2 = _a.sent();
8634
- logger.error('SDK::Wallet::getTokenBalance::error', error_2);
9110
+ logger.error('SDK::WalletDataService::getTokenBalance::error', error_2);
8635
9111
  return [2 /*return*/, Promise.reject(error_2)];
8636
9112
  case 3: return [2 /*return*/];
8637
9113
  }
@@ -8667,7 +9143,7 @@ var WalletDataService = /** @class */ (function (_super) {
8667
9143
  return [2 /*return*/, response];
8668
9144
  case 2:
8669
9145
  error_3 = _c.sent();
8670
- logger.error('SDK::Wallet::getTokenBalance::error', error_3);
9146
+ logger.error('SDK::WalletDataService::getTokenBalance::error', error_3);
8671
9147
  return [2 /*return*/, Promise.reject(error_3)];
8672
9148
  case 3: return [2 /*return*/];
8673
9149
  }
@@ -8689,7 +9165,6 @@ var WalletDataService = /** @class */ (function (_super) {
8689
9165
  switch (_c.label) {
8690
9166
  case 0:
8691
9167
  _c.trys.push([0, 2, , 3]);
8692
- console.log('SDK::Wallet::getUserAssets::userId', userId);
8693
9168
  if (!userId)
8694
9169
  throw new Error('Missing required parameters');
8695
9170
  return [4 /*yield*/, this.request(WalletRoutes.getUserAssets, {
@@ -8707,7 +9182,7 @@ var WalletDataService = /** @class */ (function (_super) {
8707
9182
  return [2 /*return*/, response];
8708
9183
  case 2:
8709
9184
  error_4 = _c.sent();
8710
- logger.error('SDK::Wallet::getUserAssets::error', error_4);
9185
+ logger.error('SDK::WalletDataService::getUserAssets::error', error_4);
8711
9186
  return [2 /*return*/, Promise.reject(error_4)];
8712
9187
  case 3: return [2 /*return*/];
8713
9188
  }
@@ -8743,7 +9218,7 @@ var WalletDataService = /** @class */ (function (_super) {
8743
9218
  return [2 /*return*/, response];
8744
9219
  case 2:
8745
9220
  error_5 = _c.sent();
8746
- logger.error('SDK::Wallet::getUserWallets::error', error_5);
9221
+ logger.error('SDK::WalletDataService::getUserWallets::error', error_5);
8747
9222
  return [2 /*return*/, Promise.reject(error_5)];
8748
9223
  case 3: return [2 /*return*/];
8749
9224
  }
@@ -8780,7 +9255,7 @@ var WalletDataService = /** @class */ (function (_super) {
8780
9255
  return [2 /*return*/, response];
8781
9256
  case 2:
8782
9257
  error_6 = _c.sent();
8783
- logger.error('SDK::Wallet::getWalletAssets::error', error_6);
9258
+ logger.error('SDK::WalletDataService::getWalletAssets::error', error_6);
8784
9259
  return [2 /*return*/, Promise.reject(error_6)];
8785
9260
  case 3: return [2 /*return*/];
8786
9261
  }
@@ -8833,19 +9308,62 @@ var WalletDataService = /** @class */ (function (_super) {
8833
9308
  })];
8834
9309
  case 1:
8835
9310
  response = _c.sent();
8836
- if (!response || response.errors) {
8837
- throw new Error(response.errors);
9311
+ if (!response || response.error) {
9312
+ throw new Error(response === null || response === void 0 ? void 0 : response.error);
8838
9313
  }
8839
9314
  return [2 /*return*/, response];
8840
9315
  case 2:
8841
9316
  error_7 = _c.sent();
8842
- logger.error('SDK::Wallet::addTokenToWallet::error', error_7);
8843
- return [2 /*return*/, Promise.reject(error_7)];
9317
+ logger.error('SDK::WalletDataService::addTokenToWallet::error', error_7);
9318
+ throw error_7;
8844
9319
  case 3: return [2 /*return*/];
8845
9320
  }
8846
9321
  });
8847
9322
  });
8848
9323
  };
9324
+ WalletDataService.prototype.addNewChainAndTokenToWallet = function (input) {
9325
+ return __awaiter(this, void 0, void 0, function () {
9326
+ var authenticationOptions, walletId, userId, assetConfigId, blockchainName, addressInfo, addressInfoIsPresentForBlockchain, response, error_8;
9327
+ return __generator(this, function (_a) {
9328
+ switch (_a.label) {
9329
+ case 0:
9330
+ authenticationOptions = input.authenticationOptions, walletId = input.walletId, userId = input.userId, assetConfigId = input.assetConfigId, blockchainName = input.blockchainName;
9331
+ if (!authenticationOptions || !walletId || !userId || !assetConfigId || !blockchainName) {
9332
+ throw new Error('Missing required parameters');
9333
+ }
9334
+ _a.label = 1;
9335
+ case 1:
9336
+ _a.trys.push([1, 6, , 7]);
9337
+ return [4 /*yield*/, this.walletService.generateWalletAddresses({
9338
+ walletId: input.walletId,
9339
+ authenticationOptions: input.authenticationOptions,
9340
+ })];
9341
+ case 2:
9342
+ addressInfo = _a.sent();
9343
+ addressInfoIsPresentForBlockchain = this.validateWalletAddressInfo(addressInfo.walletAddressInfo, blockchainName);
9344
+ if (!addressInfoIsPresentForBlockchain) return [3 /*break*/, 4];
9345
+ return [4 /*yield*/, this.addTokenToWallet({
9346
+ assetConfigId: assetConfigId,
9347
+ walletId: walletId,
9348
+ userId: userId,
9349
+ })];
9350
+ case 3:
9351
+ response = _a.sent();
9352
+ if (!response || response.error) {
9353
+ throw new Error(response === null || response === void 0 ? void 0 : response.error);
9354
+ }
9355
+ return [2 /*return*/, response];
9356
+ case 4: throw new Error("Wallet address is not present for blockchain: ".concat(blockchainName));
9357
+ case 5: return [3 /*break*/, 7];
9358
+ case 6:
9359
+ error_8 = _a.sent();
9360
+ logger.error('SDK::WalletDataService::addNewChainAndTokenToWallet::error', error_8);
9361
+ throw error_8;
9362
+ case 7: return [2 /*return*/];
9363
+ }
9364
+ });
9365
+ });
9366
+ };
8849
9367
  /**
8850
9368
  * Updates a wallet asset.
8851
9369
  *
@@ -8861,7 +9379,7 @@ var WalletDataService = /** @class */ (function (_super) {
8861
9379
  */
8862
9380
  WalletDataService.prototype.updateAsset = function (_a) {
8863
9381
  return __awaiter(this, void 0, void 0, function () {
8864
- var response, error_8;
9382
+ var response, error_9;
8865
9383
  var assetConfigId = _a.assetConfigId, walletId = _a.walletId, assetConfig = __rest(_a, ["assetConfigId", "walletId"]);
8866
9384
  return __generator(this, function (_b) {
8867
9385
  switch (_b.label) {
@@ -8881,9 +9399,9 @@ var WalletDataService = /** @class */ (function (_super) {
8881
9399
  }
8882
9400
  return [2 /*return*/, response];
8883
9401
  case 2:
8884
- error_8 = _b.sent();
8885
- logger.error('SDK::Wallet::updateAsset::error', error_8);
8886
- return [2 /*return*/, Promise.reject(error_8)];
9402
+ error_9 = _b.sent();
9403
+ logger.error('SDK::WalletDataService::updateAsset::error', error_9);
9404
+ return [2 /*return*/, Promise.reject(error_9)];
8887
9405
  case 3: return [2 /*return*/];
8888
9406
  }
8889
9407
  });
@@ -8934,6 +9452,7 @@ var Utils = /** @class */ (function (_super) {
8934
9452
  }
8935
9453
  };
8936
9454
  _this.auth = new AuthService(config);
9455
+ _this.cipher = new Cipher();
8937
9456
  return _this;
8938
9457
  }
8939
9458
  /**
@@ -9020,27 +9539,49 @@ var Utils = /** @class */ (function (_super) {
9020
9539
  };
9021
9540
  Utils.prototype.validatePassword = function (_a) {
9022
9541
  return __awaiter(this, arguments, void 0, function (_b) {
9023
- var privateKey, encryptedSeedPhrase, decryptedPrivateKey;
9024
- var _c;
9542
+ var privateKey, encryptedSeedPhrase, salt, credentialsKeyPair, decryptedPrivateKey, error_2;
9025
9543
  var password = _b.password;
9026
- return __generator(this, function (_d) {
9027
- switch (_d.label) {
9544
+ return __generator(this, function (_c) {
9545
+ switch (_c.label) {
9028
9546
  case 0: return [4 /*yield*/, this.storageService.fetch(exports.LocalStorageItems.EncryptedDevicePrivateKey)];
9029
9547
  case 1:
9030
- privateKey = _d.sent();
9548
+ privateKey = _c.sent();
9031
9549
  return [4 /*yield*/, this.storageService.fetch(exports.LocalStorageItems.EncryptedStandardSeedPhrase)];
9032
9550
  case 2:
9033
- encryptedSeedPhrase = _d.sent();
9551
+ encryptedSeedPhrase = _c.sent();
9034
9552
  if (!privateKey || !encryptedSeedPhrase) {
9035
- return [2 /*return*/, { valid: false, message: 'Could not locate client keys or seedPhrase' }];
9553
+ return [2 /*return*/, { valid: false, message: 'Could not locate client keys or seed phrase on this device.' }];
9036
9554
  }
9037
- decryptedPrivateKey = (_c = cryptoJs.AES.decrypt(privateKey, password).toString(cryptoJs.enc.Utf8)) !== null && _c !== void 0 ? _c : undefined;
9555
+ _c.label = 3;
9556
+ case 3:
9557
+ _c.trys.push([3, 7, , 8]);
9558
+ return [4 /*yield*/, this.auth.getUserSalt()];
9559
+ case 4:
9560
+ salt = _c.sent();
9561
+ return [4 /*yield*/, this.cipher.getCredentialsKeyPair({
9562
+ authType: exports.AuthType.Password,
9563
+ password: password,
9564
+ salt: salt,
9565
+ })];
9566
+ case 5:
9567
+ credentialsKeyPair = _c.sent();
9568
+ return [4 /*yield*/, this.cipher.decrypt({
9569
+ cipherText: JSON.parse(privateKey),
9570
+ decryptionKey: credentialsKeyPair.privateKey,
9571
+ })];
9572
+ case 6:
9573
+ decryptedPrivateKey = _c.sent();
9038
9574
  if (decryptedPrivateKey) {
9039
9575
  return [2 /*return*/, { valid: true }];
9040
9576
  }
9041
9577
  else {
9042
- return [2 /*return*/, { valid: false, message: 'password is incorrect' }];
9578
+ return [2 /*return*/, { valid: false, message: 'Password is incorrect' }];
9043
9579
  }
9580
+ case 7:
9581
+ error_2 = _c.sent();
9582
+ logger.error('SDK::Utils::validatePassword::error', error_2);
9583
+ return [2 /*return*/, { valid: false, message: 'Password is incorrect.' }];
9584
+ case 8: return [2 /*return*/];
9044
9585
  }
9045
9586
  });
9046
9587
  });
@@ -9568,39 +10109,6 @@ var System = /** @class */ (function (_super) {
9568
10109
  return System;
9569
10110
  }(Base));
9570
10111
 
9571
- var TransactionsRoutes = {
9572
- transfer: {
9573
- fullPath: '/transactions/transfer',
9574
- method: exports.RequestMethod.Post,
9575
- requiresAccessToken: true,
9576
- },
9577
- transferWithShares: {
9578
- fullPath: '/transactions/transfer-with-shares',
9579
- method: exports.RequestMethod.Post,
9580
- requiresAccessToken: true,
9581
- },
9582
- createAllowance: {
9583
- fullPath: '/transactions/create-allowance',
9584
- method: exports.RequestMethod.Post,
9585
- requiresAccessToken: true,
9586
- },
9587
- estimateFee: {
9588
- fullPath: '/transactions/estimate-fee',
9589
- method: exports.RequestMethod.Get,
9590
- requiresAccessToken: true,
9591
- },
9592
- getTransaction: {
9593
- fullPath: '/transactions/status',
9594
- method: exports.RequestMethod.Get,
9595
- requiresAccessToken: true,
9596
- },
9597
- getTransactions: {
9598
- fullPath: '/query/transactions',
9599
- method: exports.RequestMethod.Get,
9600
- requiresAccessToken: true,
9601
- },
9602
- };
9603
-
9604
10112
  var Transactions = /** @class */ (function (_super) {
9605
10113
  __extends(Transactions, _super);
9606
10114
  function Transactions(config) {
@@ -9658,86 +10166,6 @@ var Transactions = /** @class */ (function (_super) {
9658
10166
  });
9659
10167
  });
9660
10168
  };
9661
- Transactions.prototype.submit = function (transactionRequest) {
9662
- return __awaiter(this, void 0, void 0, function () {
9663
- var encryptedDevicePrivateKey, encryptedSeedPhrase, credentialsKeyPair, decryptedDevicePrivateKey, deviceAuthPublicKey, signatureMessage, readyForTransportSeedPhrase, message, signature, response;
9664
- var _a;
9665
- return __generator(this, function (_b) {
9666
- switch (_b.label) {
9667
- case 0: return [4 /*yield*/, this.storageService.fetch(exports.LocalStorageItems.EncryptedDevicePrivateKey)];
9668
- case 1:
9669
- encryptedDevicePrivateKey = _b.sent();
9670
- return [4 /*yield*/, this.storageService.fetch(exports.LocalStorageItems.EncryptedStandardSeedPhrase)];
9671
- case 2:
9672
- encryptedSeedPhrase = _b.sent();
9673
- if (!encryptedDevicePrivateKey) {
9674
- throw new Error('No private key was found on this device');
9675
- }
9676
- if (!encryptedSeedPhrase) {
9677
- throw new Error('Seed phrase was not found on this device. Please recover your wallet.');
9678
- }
9679
- return [4 /*yield*/, this.cipher.getCredentialsKeyPair({
9680
- password: transactionRequest.password,
9681
- salt: this.userId,
9682
- prfValue: transactionRequest.prfValue,
9683
- authType: this.deviceAuthType,
9684
- })];
9685
- case 3:
9686
- credentialsKeyPair = _b.sent();
9687
- if (!credentialsKeyPair) {
9688
- throw new Error('Credentials are wrong, please pass the correct credentials.');
9689
- }
9690
- return [4 /*yield*/, this.cipher.decrypt({
9691
- cipherText: JSON.parse(encryptedDevicePrivateKey),
9692
- decryptionKey: (_a = credentialsKeyPair === null || credentialsKeyPair === void 0 ? void 0 : credentialsKeyPair.privateKey) !== null && _a !== void 0 ? _a : '',
9693
- })];
9694
- case 4:
9695
- decryptedDevicePrivateKey = _b.sent();
9696
- deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
9697
- return [4 /*yield*/, this.authService.getSignature({
9698
- publicKey: deviceAuthPublicKey,
9699
- privateKey: decryptedDevicePrivateKey,
9700
- })];
9701
- case 5:
9702
- signatureMessage = _b.sent();
9703
- return [4 /*yield*/, this.cipher.prepareStoredDataForTransport({
9704
- storedEncryptedData: JSON.parse(encryptedSeedPhrase),
9705
- encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
9706
- wallabyPublicKey: transactionRequest.wallabyAuthPublicKey,
9707
- options: {
9708
- authType: this.deviceAuthType,
9709
- password: transactionRequest.password,
9710
- prfValue: transactionRequest.prfValue,
9711
- },
9712
- })];
9713
- case 6:
9714
- readyForTransportSeedPhrase = _b.sent();
9715
- message = signatureMessage.message, signature = signatureMessage.signature;
9716
- return [4 /*yield*/, this.request(TransactionsRoutes.transfer, {
9717
- method: TransactionsRoutes.transfer.method,
9718
- payload: {
9719
- message: message,
9720
- signature: signature,
9721
- clientAuthPubKey: deviceAuthPublicKey,
9722
- encryptedSeed: readyForTransportSeedPhrase,
9723
- originAddress: transactionRequest.originAddress,
9724
- recipientAddress: transactionRequest.recipientAddress,
9725
- amount: transactionRequest.amount,
9726
- transactionType: transactionRequest.transactionType,
9727
- reference: uuid.v4(),
9728
- memo: "".concat(transactionRequest.originAddress, " is ").concat(transactionRequest.transactionType, "ing to ").concat(transactionRequest.recipientAddress),
9729
- },
9730
- })];
9731
- case 7:
9732
- response = _b.sent();
9733
- if (response.error) {
9734
- throw new Error(response.error);
9735
- }
9736
- return [2 /*return*/, response];
9737
- }
9738
- });
9739
- });
9740
- };
9741
10169
  /**
9742
10170
  *
9743
10171
  * @public
@@ -9830,88 +10258,47 @@ var Transactions = /** @class */ (function (_super) {
9830
10258
  */
9831
10259
  Transactions.prototype.transfer = function (_a) {
9832
10260
  return __awaiter(this, arguments, void 0, function (_b) {
9833
- var password, prfValue, user, encryptedDevicePrivateKey, credentialsKeyPair, decryptedDevicePrivateKey, deviceAuthPublicKey, signatureMessage, sharesEncryptedWithWallabyPubKey, primaryKeyShare, parsedPrimaryShare, readyForTransportShare, message, signature, response, error_4;
10261
+ var _c, deviceAuthPublicKey, signatureMessage, readyForTransportSeedPhrase, sharesEncryptedWithWallabyPubKey, hasShares, transferResponse, error_4;
9834
10262
  var originAddress = _b.originAddress, recipientAddress = _b.recipientAddress, amount = _b.amount, assetId = _b.assetId, reference = _b.reference, authenticationOptions = _b.authenticationOptions, memo = _b.memo;
9835
- return __generator(this, function (_c) {
9836
- switch (_c.label) {
10263
+ return __generator(this, function (_d) {
10264
+ switch (_d.label) {
9837
10265
  case 0:
9838
- _c.trys.push([0, 8, , 9]);
9839
- password = authenticationOptions.password, prfValue = authenticationOptions.prfValue, user = authenticationOptions.user;
9840
- return [4 /*yield*/, this.storageService.fetch(exports.LocalStorageItems.EncryptedDevicePrivateKey)];
10266
+ _d.trys.push([0, 7, , 8]);
10267
+ return [4 /*yield*/, this.prepareTransactionAuth(authenticationOptions)];
9841
10268
  case 1:
9842
- encryptedDevicePrivateKey = _c.sent();
9843
- if (!encryptedDevicePrivateKey) {
9844
- throw new Error('No private key was found on this device');
9845
- }
9846
- return [4 /*yield*/, this.cipher.getCredentialsKeyPair({
9847
- authType: this.deviceAuthType,
9848
- password: password,
9849
- prfValue: prfValue,
9850
- salt: user.clientSalt,
10269
+ _c = _d.sent(), deviceAuthPublicKey = _c.deviceAuthPublicKey, signatureMessage = _c.signatureMessage, readyForTransportSeedPhrase = _c.readyForTransportSeedPhrase, sharesEncryptedWithWallabyPubKey = _c.sharesEncryptedWithWallabyPubKey, hasShares = _c.hasShares;
10270
+ transferResponse = void 0;
10271
+ if (!readyForTransportSeedPhrase) return [3 /*break*/, 3];
10272
+ return [4 /*yield*/, this.request(TransactionsRoutes.transfer, {
10273
+ method: TransactionsRoutes.transfer.method,
10274
+ payload: __assign(__assign({}, signatureMessage), { clientAuthPubKey: deviceAuthPublicKey, encryptedSeed: readyForTransportSeedPhrase, originAddress: originAddress, recipientAddress: recipientAddress, assetId: assetId, amount: amount, reference: reference || uuid.v4(), memo: memo }),
9851
10275
  })];
9852
10276
  case 2:
9853
- credentialsKeyPair = _c.sent();
9854
- return [4 /*yield*/, this.cipher.decrypt({
9855
- cipherText: JSON.parse(encryptedDevicePrivateKey),
9856
- decryptionKey: credentialsKeyPair.privateKey,
9857
- })];
10277
+ transferResponse = _d.sent();
10278
+ return [3 /*break*/, 6];
9858
10279
  case 3:
9859
- decryptedDevicePrivateKey = _c.sent();
9860
- deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
9861
- return [4 /*yield*/, this.authService.getSignature({
9862
- publicKey: deviceAuthPublicKey,
9863
- privateKey: decryptedDevicePrivateKey,
9864
- })];
9865
- case 4:
9866
- signatureMessage = _c.sent();
9867
- sharesEncryptedWithWallabyPubKey = [];
9868
- return [4 /*yield*/, this.storageService.fetch(exports.LocalStorageItems.PrimaryDeviceKeyShare)];
9869
- case 5:
9870
- primaryKeyShare = _c.sent();
9871
- parsedPrimaryShare = safeJsonParse(primaryKeyShare !== null && primaryKeyShare !== void 0 ? primaryKeyShare : '');
9872
- if (!parsedPrimaryShare)
9873
- throw new Error('Your device does not have a primary operating share.');
9874
- return [4 /*yield*/, this.cipher.prepareStoredDataForTransport({
9875
- storedEncryptedData: parsedPrimaryShare,
9876
- encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
9877
- wallabyPublicKey: user.wallabyAuthPubKey,
9878
- options: {
9879
- authType: this.deviceAuthType,
9880
- password: password,
9881
- prfValue: prfValue,
9882
- salt: user.clientSalt,
9883
- },
9884
- })];
9885
- case 6:
9886
- readyForTransportShare = _c.sent();
9887
- sharesEncryptedWithWallabyPubKey.push(readyForTransportShare);
9888
- message = signatureMessage.message, signature = signatureMessage.signature;
10280
+ if (!hasShares) return [3 /*break*/, 5];
9889
10281
  return [4 /*yield*/, this.request(TransactionsRoutes.transferWithShares, {
9890
10282
  method: TransactionsRoutes.transferWithShares.method,
9891
- payload: {
9892
- message: message,
9893
- signature: signature,
9894
- clientAuthPubKey: deviceAuthPublicKey,
9895
- encryptedShares: sharesEncryptedWithWallabyPubKey,
9896
- originAddress: originAddress,
9897
- recipientAddress: recipientAddress,
9898
- assetId: assetId,
9899
- amount: amount,
9900
- reference: reference,
9901
- memo: memo,
9902
- },
10283
+ payload: __assign(__assign({}, signatureMessage), { clientAuthPubKey: deviceAuthPublicKey, encryptedShares: sharesEncryptedWithWallabyPubKey, encryptedSeed: readyForTransportSeedPhrase, originAddress: originAddress, recipientAddress: recipientAddress, assetId: assetId, amount: amount, reference: reference || uuid.v4(), memo: memo }),
9903
10284
  })];
9904
- case 7:
9905
- response = _c.sent();
9906
- if (response.error) {
9907
- throw new Error(response.error);
10285
+ case 4:
10286
+ transferResponse = _d.sent();
10287
+ return [3 /*break*/, 6];
10288
+ case 5: throw new Error('No valid authentication method found');
10289
+ case 6:
10290
+ if (!transferResponse || transferResponse.error) {
10291
+ throw new Error(transferResponse === null || transferResponse === void 0 ? void 0 : transferResponse.error);
9908
10292
  }
9909
- return [2 /*return*/, response];
9910
- case 8:
9911
- error_4 = _c.sent();
9912
- logger.error('SDK::Transactions::transferWithShares::error', error_4);
9913
- return [2 /*return*/, Promise.reject(error_4)];
9914
- case 9: return [2 /*return*/];
10293
+ if (!transferResponse.transaction) {
10294
+ throw new Error('Invalid response: missing transaction data');
10295
+ }
10296
+ return [2 /*return*/, transferResponse];
10297
+ case 7:
10298
+ error_4 = _d.sent();
10299
+ logger.error('SDK::Transactions::transfer::error', error_4);
10300
+ throw error_4;
10301
+ case 8: return [2 /*return*/];
9915
10302
  }
9916
10303
  });
9917
10304
  });
@@ -9933,25 +10320,76 @@ var Transactions = /** @class */ (function (_super) {
9933
10320
  */
9934
10321
  Transactions.prototype.createAllowance = function (_a) {
9935
10322
  return __awaiter(this, arguments, void 0, function (_b) {
9936
- var encryptedDevicePrivateKey, password, prfValue, user, credentialsKeyPair, decryptedDevicePrivateKey, deviceAuthPublicKey, signatureMessage, encryptedSeedPhrase, seedPhraseEncryptedWithWallabyPubKey, message, signature, response, error_5;
10323
+ var _c, deviceAuthPublicKey, signatureMessage, readyForTransportSeedPhrase, message, signature, response, error_5;
9937
10324
  var authenticationOptions = _b.authenticationOptions, ownerAddress = _b.ownerAddress, spenderAddress = _b.spenderAddress, amount = _b.amount, assetId = _b.assetId, suiObjectId = _b.suiObjectId, contractAddress = _b.contractAddress, chainName = _b.chainName, assetSymbol = _b.assetSymbol, reference = _b.reference, memo = _b.memo;
9938
- return __generator(this, function (_c) {
9939
- switch (_c.label) {
10325
+ return __generator(this, function (_d) {
10326
+ switch (_d.label) {
9940
10327
  case 0:
9941
- _c.trys.push([0, 8, , 9]);
10328
+ _d.trys.push([0, 3, , 4]);
9942
10329
  if (!suiObjectId && !contractAddress && !assetId && !assetSymbol && !chainName) {
9943
10330
  throw new Error("AssetId, asset symbol, chain name or contract address must be provided.");
9944
10331
  }
9945
10332
  if ((assetSymbol && !chainName) || (!assetSymbol && chainName)) {
9946
10333
  throw new Error("Asset symbol and chain name must be provided when asset is not in user wallet.");
9947
10334
  }
10335
+ return [4 /*yield*/, this.prepareTransactionAuth(authenticationOptions)];
10336
+ case 1:
10337
+ _c = _d.sent(), deviceAuthPublicKey = _c.deviceAuthPublicKey, signatureMessage = _c.signatureMessage, readyForTransportSeedPhrase = _c.readyForTransportSeedPhrase;
10338
+ message = signatureMessage.message, signature = signatureMessage.signature;
10339
+ // Create allowance only supports seed phrase for now, but we could extend it to support shares
10340
+ if (!readyForTransportSeedPhrase) {
10341
+ throw new Error('Create allowance requires a seed phrase. Key shares are not yet supported for this operation.');
10342
+ }
10343
+ return [4 /*yield*/, this.request(TransactionsRoutes.createAllowance, {
10344
+ method: TransactionsRoutes.createAllowance.method,
10345
+ payload: {
10346
+ message: message,
10347
+ signature: signature,
10348
+ clientAuthPubKey: deviceAuthPublicKey,
10349
+ encryptedSeed: readyForTransportSeedPhrase,
10350
+ ownerAddress: ownerAddress,
10351
+ spenderAddress: spenderAddress,
10352
+ chainName: chainName,
10353
+ assetSymbol: assetSymbol,
10354
+ amount: amount,
10355
+ assetId: assetId,
10356
+ contractAddress: contractAddress !== null && contractAddress !== void 0 ? contractAddress : suiObjectId,
10357
+ reference: reference,
10358
+ memo: memo,
10359
+ },
10360
+ })];
10361
+ case 2:
10362
+ response = _d.sent();
10363
+ if (response.error) {
10364
+ throw new Error(response.error);
10365
+ }
10366
+ return [2 /*return*/, response];
10367
+ case 3:
10368
+ error_5 = _d.sent();
10369
+ logger.error('SDK::Transactions::createAllowance::error', error_5);
10370
+ throw error_5;
10371
+ case 4: return [2 /*return*/];
10372
+ }
10373
+ });
10374
+ });
10375
+ };
10376
+ /**
10377
+ * Prepares authentication data and encrypted payload for transaction requests
10378
+ * @private
10379
+ */
10380
+ Transactions.prototype.prepareTransactionAuth = function (authenticationOptions) {
10381
+ return __awaiter(this, void 0, void 0, function () {
10382
+ var password, prfValue, user, encryptedDevicePrivateKey, credentialsKeyPair, decryptedDevicePrivateKey, deviceAuthPublicKey, signatureMessage, sharesEncryptedWithWallabyPubKey, readyForTransportSeedPhrase, primaryKeyShare, parsedPrimaryShare, encryptedSeedPhrase, parsedSeedPhrase, readyForTransportShare;
10383
+ return __generator(this, function (_a) {
10384
+ switch (_a.label) {
10385
+ case 0:
10386
+ password = authenticationOptions.password, prfValue = authenticationOptions.prfValue, user = authenticationOptions.user;
9948
10387
  return [4 /*yield*/, this.storageService.fetch(exports.LocalStorageItems.EncryptedDevicePrivateKey)];
9949
10388
  case 1:
9950
- encryptedDevicePrivateKey = _c.sent();
10389
+ encryptedDevicePrivateKey = _a.sent();
9951
10390
  if (!encryptedDevicePrivateKey) {
9952
10391
  throw new Error('No private key was found on this device');
9953
10392
  }
9954
- password = authenticationOptions.password, prfValue = authenticationOptions.prfValue, user = authenticationOptions.user;
9955
10393
  return [4 /*yield*/, this.cipher.getCredentialsKeyPair({
9956
10394
  authType: this.deviceAuthType,
9957
10395
  password: password,
@@ -9959,13 +10397,13 @@ var Transactions = /** @class */ (function (_super) {
9959
10397
  salt: user.clientSalt,
9960
10398
  })];
9961
10399
  case 2:
9962
- credentialsKeyPair = _c.sent();
10400
+ credentialsKeyPair = _a.sent();
9963
10401
  return [4 /*yield*/, this.cipher.decrypt({
9964
10402
  cipherText: JSON.parse(encryptedDevicePrivateKey),
9965
10403
  decryptionKey: credentialsKeyPair.privateKey,
9966
10404
  })];
9967
10405
  case 3:
9968
- decryptedDevicePrivateKey = _c.sent();
10406
+ decryptedDevicePrivateKey = _a.sent();
9969
10407
  if (!decryptedDevicePrivateKey) {
9970
10408
  throw new Error('Credentials are wrong, please pass the correct credentials.');
9971
10409
  }
@@ -9975,15 +10413,23 @@ var Transactions = /** @class */ (function (_super) {
9975
10413
  privateKey: decryptedDevicePrivateKey,
9976
10414
  })];
9977
10415
  case 4:
9978
- signatureMessage = _c.sent();
9979
- return [4 /*yield*/, this.storageService.fetch(exports.LocalStorageItems.EncryptedStandardSeedPhrase)];
10416
+ signatureMessage = _a.sent();
10417
+ sharesEncryptedWithWallabyPubKey = [];
10418
+ readyForTransportSeedPhrase = undefined;
10419
+ return [4 /*yield*/, this.storageService.fetch(exports.LocalStorageItems.PrimaryDeviceKeyShare)];
9980
10420
  case 5:
9981
- encryptedSeedPhrase = _c.sent();
9982
- if (!encryptedSeedPhrase) {
9983
- throw new Error('Seed phrase were not found on this device.');
10421
+ primaryKeyShare = _a.sent();
10422
+ parsedPrimaryShare = safeJsonParse(primaryKeyShare !== null && primaryKeyShare !== void 0 ? primaryKeyShare : '');
10423
+ if (!!parsedPrimaryShare) return [3 /*break*/, 8];
10424
+ return [4 /*yield*/, this.storageService.fetch(exports.LocalStorageItems.EncryptedStandardSeedPhrase)];
10425
+ case 6:
10426
+ encryptedSeedPhrase = _a.sent();
10427
+ parsedSeedPhrase = safeJsonParse(encryptedSeedPhrase !== null && encryptedSeedPhrase !== void 0 ? encryptedSeedPhrase : '');
10428
+ if (!parsedSeedPhrase) {
10429
+ throw new Error('Your device does not have a seed phrase or an operating share to sign the transaction.');
9984
10430
  }
9985
10431
  return [4 /*yield*/, this.cipher.prepareStoredDataForTransport({
9986
- storedEncryptedData: JSON.parse(encryptedSeedPhrase),
10432
+ storedEncryptedData: parsedSeedPhrase,
9987
10433
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
9988
10434
  wallabyPublicKey: user.wallabyAuthPubKey,
9989
10435
  options: {
@@ -9993,38 +10439,31 @@ var Transactions = /** @class */ (function (_super) {
9993
10439
  salt: user.clientSalt,
9994
10440
  },
9995
10441
  })];
9996
- case 6:
9997
- seedPhraseEncryptedWithWallabyPubKey = _c.sent();
9998
- message = signatureMessage.message, signature = signatureMessage.signature;
9999
- return [4 /*yield*/, this.request(TransactionsRoutes.createAllowance, {
10000
- method: TransactionsRoutes.createAllowance.method,
10001
- payload: {
10002
- message: message,
10003
- signature: signature,
10004
- clientAuthPubKey: deviceAuthPublicKey,
10005
- encryptedSeed: seedPhraseEncryptedWithWallabyPubKey,
10006
- ownerAddress: ownerAddress,
10007
- spenderAddress: spenderAddress,
10008
- chainName: chainName,
10009
- assetSymbol: assetSymbol,
10010
- amount: amount,
10011
- assetId: assetId,
10012
- contractAddress: contractAddress !== null && contractAddress !== void 0 ? contractAddress : suiObjectId,
10013
- reference: reference,
10014
- memo: memo,
10015
- },
10016
- })];
10017
10442
  case 7:
10018
- response = _c.sent();
10019
- if (response.error) {
10020
- throw new Error(response.error);
10021
- }
10022
- return [2 /*return*/, response];
10023
- case 8:
10024
- error_5 = _c.sent();
10025
- logger.error('SDK::Transactions::createAllowance::error', error_5);
10026
- return [2 /*return*/, Promise.reject(error_5)];
10027
- case 9: return [2 /*return*/];
10443
+ readyForTransportSeedPhrase = _a.sent();
10444
+ return [3 /*break*/, 10];
10445
+ case 8: return [4 /*yield*/, this.cipher.prepareStoredDataForTransport({
10446
+ storedEncryptedData: parsedPrimaryShare,
10447
+ encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
10448
+ wallabyPublicKey: user.wallabyAuthPubKey,
10449
+ options: {
10450
+ authType: this.deviceAuthType,
10451
+ password: password,
10452
+ prfValue: prfValue,
10453
+ salt: user.clientSalt,
10454
+ },
10455
+ })];
10456
+ case 9:
10457
+ readyForTransportShare = _a.sent();
10458
+ sharesEncryptedWithWallabyPubKey.push(readyForTransportShare);
10459
+ _a.label = 10;
10460
+ case 10: return [2 /*return*/, {
10461
+ deviceAuthPublicKey: deviceAuthPublicKey,
10462
+ signatureMessage: signatureMessage,
10463
+ readyForTransportSeedPhrase: readyForTransportSeedPhrase,
10464
+ sharesEncryptedWithWallabyPubKey: sharesEncryptedWithWallabyPubKey,
10465
+ hasShares: sharesEncryptedWithWallabyPubKey.length > 0,
10466
+ }];
10028
10467
  }
10029
10468
  });
10030
10469
  });