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.esm.js CHANGED
@@ -4,8 +4,9 @@ import log from 'loglevel';
4
4
  import { AES, enc } from 'crypto-js';
5
5
  import { jwtDecode } from 'jwt-decode';
6
6
  import { omit } from 'lodash';
7
+ import { atob } from 'js-base64';
7
8
  import * as WebAuthn from '@simplewebauthn/browser';
8
- import { Passkey } from 'react-native-passkey';
9
+ import { isInjectiveAddress, isSUIAddress, isAlgoAddress, isBtcAddress, isEvmAddress } from '@wallaby-cash/address-validator';
9
10
 
10
11
  /******************************************************************************
11
12
  Copyright (c) Microsoft Corporation.
@@ -183,6 +184,7 @@ var BlockchainName;
183
184
  BlockchainName["Avalanche"] = "AVALANCHE";
184
185
  BlockchainName["Bitcoin"] = "BITCOIN";
185
186
  BlockchainName["Ethereum"] = "ETHEREUM";
187
+ BlockchainName["Injective"] = "INJECTIVE";
186
188
  BlockchainName["Polygon"] = "POLYGON";
187
189
  BlockchainName["Bsc"] = "BSC";
188
190
  BlockchainName["Base"] = "BASE";
@@ -256,6 +258,39 @@ var LocalStorageItems;
256
258
  LocalStorageItems["PasskeyCredentialId"] = "pass-key-credential-id";
257
259
  LocalStorageItems["PasskeyClientDataObject"] = "passkey-client-data";
258
260
  })(LocalStorageItems || (LocalStorageItems = {}));
261
+ var LegacyKeyNames;
262
+ (function (LegacyKeyNames) {
263
+ LegacyKeyNames["EncryptedPrivateKey"] = "encryptedPrivateKey";
264
+ LegacyKeyNames["WallabyAuthPubKey"] = "wallabyAuthPubKey";
265
+ LegacyKeyNames["EncryptedAlgorandSeed"] = "encryptedAlgorandSeed";
266
+ LegacyKeyNames["EncryptedSeed"] = "encryptedSeed";
267
+ LegacyKeyNames["ClientAuthToken"] = "republic_jwt";
268
+ LegacyKeyNames["AccessToken"] = "accessToken";
269
+ })(LegacyKeyNames || (LegacyKeyNames = {}));
270
+ var V1KeyNames;
271
+ (function (V1KeyNames) {
272
+ V1KeyNames["AccessToken"] = "access-token";
273
+ V1KeyNames["EncryptedStandardSeedPhrase"] = "encrypted-standard-seedPhrase";
274
+ V1KeyNames["EncryptedAlgorandSeedPhrase"] = "encrypted-algorand-seedPhrase";
275
+ V1KeyNames["EncryptedDevicePrivateKey"] = "encrypted-private-key";
276
+ V1KeyNames["ClientAuthPublicKey"] = "client-auth-pub-key";
277
+ V1KeyNames["WallabyAuthPubKey"] = "wallaby-auth-pub-key";
278
+ V1KeyNames["ClientAuthToken"] = "republic-jwt";
279
+ })(V1KeyNames || (V1KeyNames = {}));
280
+ var V2KeyNames;
281
+ (function (V2KeyNames) {
282
+ V2KeyNames["AccessToken"] = "access-token";
283
+ V2KeyNames["BackupDeviceKeyShare"] = "backup-device-key-share";
284
+ V2KeyNames["ClientAuthPublicKey"] = "client-auth-pub-key";
285
+ V2KeyNames["ClientAuthToken"] = "republic-jwt";
286
+ V2KeyNames["EncryptedDevicePrivateKey"] = "encrypted-private-key";
287
+ V2KeyNames["EncryptedStandardSeedPhrase"] = "encrypted-standard-seedPhrase";
288
+ V2KeyNames["PasskeyCredential"] = "pass-key-credential";
289
+ V2KeyNames["PasskeyCredentialId"] = "pass-key-credential-id";
290
+ V2KeyNames["PasskeyClientDataObject"] = "passkey-client-data";
291
+ V2KeyNames["PrimaryDeviceKeyShare"] = "primary-device-key-share";
292
+ V2KeyNames["WallabyAuthPubKey"] = "wallaby-auth-pub-key";
293
+ })(V2KeyNames || (V2KeyNames = {}));
259
294
 
260
295
  var ErrorResponseCodes;
261
296
  (function (ErrorResponseCodes) {
@@ -531,17 +566,17 @@ var browser$1 = {
531
566
  uptime: uptime
532
567
  };
533
568
 
534
- if (browser$1.env.NODE_ENV === 'production') {
535
- log.setLevel('silent');
569
+ if (browser$1.env.ENABLE_DEVELOPMENT_LOGGING && browser$1.env.NODE_ENV !== 'production') {
570
+ log.setLevel('trace');
536
571
  }
537
572
  else {
538
- log.setLevel('trace');
573
+ log.setLevel('silent');
539
574
  }
540
575
  var logger = log;
541
576
 
542
577
  var _a;
543
578
  /**
544
- * The default environment will be set to NODE_ENV if environment is not set in config.
579
+ * The default environment will be set to 'development' if environment is not set in config.
545
580
  * For production builds, it is recommended to set NODE_ENV to 'production'.
546
581
  */
547
582
  var defaultEnvironment = (_a = browser$1.env.NODE_ENV) !== null && _a !== void 0 ? _a : 'development';
@@ -4270,35 +4305,52 @@ var hash = {
4270
4305
  var StorageService = /** @class */ (function () {
4271
4306
  function StorageService(_a) {
4272
4307
  var deviceStorage = _a.deviceStorage, userId = _a.userId, environment = _a.environment;
4308
+ var _b;
4273
4309
  this.userId = userId;
4274
4310
  this.environment = environment !== null && environment !== void 0 ? environment : defaultEnvironment;
4311
+ this.shortenedEnv = (_b = this.environment.slice(0, 1)) !== null && _b !== void 0 ? _b : 'd'; // d for development
4275
4312
  this.deviceStorage = deviceStorage;
4276
4313
  }
4277
- StorageService.prototype.fetch = function (key) {
4314
+ StorageService.prototype.getFromDeviceStorage = function (key) {
4278
4315
  return __awaiter(this, void 0, void 0, function () {
4279
- var item, _a;
4280
- return __generator(this, function (_b) {
4281
- switch (_b.label) {
4316
+ return __generator(this, function (_a) {
4317
+ switch (_a.label) {
4282
4318
  case 0:
4283
- _a = key;
4284
- switch (_a) {
4285
- case LocalStorageItems.EncryptedStandardSeedPhrase: return [3 /*break*/, 1];
4286
- case LocalStorageItems.EncryptedAlgorandSeedPhrase: return [3 /*break*/, 3];
4287
- }
4288
- return [3 /*break*/, 5];
4289
- case 1: return [4 /*yield*/, this.getItem("".concat(this.environment, "-encrypted-").concat(SeedPhraseType.Standard, "-seedPhrase-").concat(this.userId))];
4290
- case 2:
4291
- item = _b.sent();
4292
- return [3 /*break*/, 7];
4293
- case 3: return [4 /*yield*/, this.getItem("".concat(this.environment, "-encrypted-").concat(SeedPhraseType.Algorand, "-seedPhrase-").concat(this.userId))];
4294
- case 4:
4295
- item = _b.sent();
4296
- return [3 /*break*/, 7];
4297
- case 5: return [4 /*yield*/, this.getItem("".concat(this.environment, "-").concat(key, "-").concat(this.userId))];
4298
- case 6:
4299
- item = _b.sent();
4300
- return [3 /*break*/, 7];
4301
- case 7:
4319
+ if (!this.deviceStorage.getItem) return [3 /*break*/, 1];
4320
+ return [2 /*return*/, this.deviceStorage.getItem(key)];
4321
+ case 1:
4322
+ if (!this.deviceStorage.getItemAsync) return [3 /*break*/, 3];
4323
+ return [4 /*yield*/, this.deviceStorage.getItemAsync(key)];
4324
+ case 2: return [2 /*return*/, _a.sent()];
4325
+ case 3: return [2 /*return*/, null];
4326
+ }
4327
+ });
4328
+ });
4329
+ };
4330
+ StorageService.prototype.setInDeviceStorage = function (key, value) {
4331
+ return __awaiter(this, void 0, void 0, function () {
4332
+ return __generator(this, function (_a) {
4333
+ switch (_a.label) {
4334
+ case 0:
4335
+ if (!this.deviceStorage.setItem) return [3 /*break*/, 1];
4336
+ return [2 /*return*/, this.deviceStorage.setItem(key, value)];
4337
+ case 1:
4338
+ if (!this.deviceStorage.setItemAsync) return [3 /*break*/, 3];
4339
+ return [4 /*yield*/, this.deviceStorage.setItemAsync(key, value)];
4340
+ case 2: return [2 /*return*/, _a.sent()];
4341
+ case 3: return [2 /*return*/];
4342
+ }
4343
+ });
4344
+ });
4345
+ };
4346
+ StorageService.prototype.fetch = function (key) {
4347
+ return __awaiter(this, void 0, void 0, function () {
4348
+ var item;
4349
+ return __generator(this, function (_a) {
4350
+ switch (_a.label) {
4351
+ case 0: return [4 /*yield*/, this.getItem("wsdk:v2:".concat(this.shortenedEnv, ":").concat(key, ":").concat(this.userId))];
4352
+ case 1:
4353
+ item = _a.sent();
4302
4354
  if (!item) {
4303
4355
  logger.debug("Item with key ".concat(key, " was not found in storage."));
4304
4356
  return [2 /*return*/, undefined];
@@ -4310,29 +4362,10 @@ var StorageService = /** @class */ (function () {
4310
4362
  };
4311
4363
  StorageService.prototype.save = function (key, value) {
4312
4364
  return __awaiter(this, void 0, void 0, function () {
4313
- var _a;
4314
- return __generator(this, function (_b) {
4315
- switch (_b.label) {
4316
- case 0:
4317
- _a = key;
4318
- switch (_a) {
4319
- case LocalStorageItems.EncryptedStandardSeedPhrase: return [3 /*break*/, 1];
4320
- case LocalStorageItems.EncryptedAlgorandSeedPhrase: return [3 /*break*/, 3];
4321
- }
4322
- return [3 /*break*/, 5];
4323
- case 1: return [4 /*yield*/, this.setItem("".concat(this.environment, "-encrypted-").concat(SeedPhraseType.Standard, "-seedPhrase-").concat(this.userId), value)];
4324
- case 2:
4325
- _b.sent();
4326
- return [3 /*break*/, 7];
4327
- case 3: return [4 /*yield*/, this.setItem("".concat(this.environment, "-encrypted-").concat(SeedPhraseType.Algorand, "-seedPhrase-").concat(this.userId), value)];
4328
- case 4:
4329
- _b.sent();
4330
- return [3 /*break*/, 7];
4331
- case 5: return [4 /*yield*/, this.setItem("".concat(this.environment, "-").concat(key, "-").concat(this.userId), value)];
4332
- case 6:
4333
- _b.sent();
4334
- return [3 /*break*/, 7];
4335
- case 7: return [2 /*return*/];
4365
+ return __generator(this, function (_a) {
4366
+ switch (_a.label) {
4367
+ case 0: return [4 /*yield*/, this.setItem("wsdk:v2:".concat(this.shortenedEnv, ":").concat(key, ":").concat(this.userId), value)];
4368
+ case 1: return [2 /*return*/, _a.sent()];
4336
4369
  }
4337
4370
  });
4338
4371
  });
@@ -4341,45 +4374,21 @@ var StorageService = /** @class */ (function () {
4341
4374
  return __awaiter(this, void 0, void 0, function () {
4342
4375
  var _this = this;
4343
4376
  return __generator(this, function (_a) {
4344
- data.forEach(function (item) { return __awaiter(_this, void 0, void 0, function () {
4345
- return __generator(this, function (_a) {
4346
- switch (_a.label) {
4347
- case 0: return [4 /*yield*/, this.save(item.key, item.value)];
4348
- case 1:
4349
- _a.sent();
4350
- return [2 /*return*/];
4351
- }
4352
- });
4353
- }); });
4354
- return [2 /*return*/];
4377
+ switch (_a.label) {
4378
+ case 0: return [4 /*yield*/, Promise.all(data.map(function (item) { return _this.save(item.key, item.value); }))];
4379
+ case 1:
4380
+ _a.sent();
4381
+ return [2 /*return*/];
4382
+ }
4355
4383
  });
4356
4384
  });
4357
4385
  };
4358
4386
  StorageService.prototype.delete = function (key) {
4359
4387
  return __awaiter(this, void 0, void 0, function () {
4360
- var _a;
4361
- return __generator(this, function (_b) {
4362
- switch (_b.label) {
4363
- case 0:
4364
- _a = key;
4365
- switch (_a) {
4366
- case LocalStorageItems.EncryptedStandardSeedPhrase: return [3 /*break*/, 1];
4367
- case LocalStorageItems.EncryptedAlgorandSeedPhrase: return [3 /*break*/, 3];
4368
- }
4369
- return [3 /*break*/, 5];
4370
- case 1: return [4 /*yield*/, this.removeItem("".concat(this.environment, "-encrypted-").concat(SeedPhraseType.Standard, "-seedPhrase-").concat(this.userId))];
4371
- case 2:
4372
- _b.sent();
4373
- return [3 /*break*/, 7];
4374
- case 3: return [4 /*yield*/, this.removeItem("".concat(this.environment, "-encrypted-").concat(SeedPhraseType.Algorand, "-seedPhrase-").concat(this.userId))];
4375
- case 4:
4376
- _b.sent();
4377
- return [3 /*break*/, 7];
4378
- case 5: return [4 /*yield*/, this.removeItem("".concat(this.environment, "-").concat(key, "-").concat(this.userId))];
4379
- case 6:
4380
- _b.sent();
4381
- return [3 /*break*/, 7];
4382
- case 7: return [2 /*return*/];
4388
+ return __generator(this, function (_a) {
4389
+ switch (_a.label) {
4390
+ case 0: return [4 /*yield*/, this.removeItem("wsdk:v2:".concat(this.shortenedEnv, ":").concat(key, ":").concat(this.userId))];
4391
+ case 1: return [2 /*return*/, _a.sent()];
4383
4392
  }
4384
4393
  });
4385
4394
  });
@@ -4415,6 +4424,46 @@ var StorageService = /** @class */ (function () {
4415
4424
  }
4416
4425
  throw new Error('removeItem function is not defined');
4417
4426
  };
4427
+ StorageService.prototype.checkPrivateKeyExists = function () {
4428
+ return __awaiter(this, void 0, void 0, function () {
4429
+ return __generator(this, function (_a) {
4430
+ switch (_a.label) {
4431
+ case 0: return [4 /*yield*/, this.fetch(LocalStorageItems.EncryptedDevicePrivateKey)];
4432
+ case 1: return [2 /*return*/, !!(_a.sent())];
4433
+ }
4434
+ });
4435
+ });
4436
+ };
4437
+ StorageService.prototype.checkPrimaryKeyShareExists = function () {
4438
+ return __awaiter(this, void 0, void 0, function () {
4439
+ return __generator(this, function (_a) {
4440
+ switch (_a.label) {
4441
+ case 0: return [4 /*yield*/, this.fetch(LocalStorageItems.PrimaryDeviceKeyShare)];
4442
+ case 1: return [2 /*return*/, !!(_a.sent())];
4443
+ }
4444
+ });
4445
+ });
4446
+ };
4447
+ StorageService.prototype.checkBackupKeyShareExists = function () {
4448
+ return __awaiter(this, void 0, void 0, function () {
4449
+ return __generator(this, function (_a) {
4450
+ switch (_a.label) {
4451
+ case 0: return [4 /*yield*/, this.fetch(LocalStorageItems.BackupDeviceKeyShare)];
4452
+ case 1: return [2 /*return*/, !!(_a.sent())];
4453
+ }
4454
+ });
4455
+ });
4456
+ };
4457
+ StorageService.prototype.checkSeedPhraseExists = function () {
4458
+ return __awaiter(this, void 0, void 0, function () {
4459
+ return __generator(this, function (_a) {
4460
+ switch (_a.label) {
4461
+ case 0: return [4 /*yield*/, this.fetch(LocalStorageItems.EncryptedStandardSeedPhrase)];
4462
+ case 1: return [2 /*return*/, !!(_a.sent())];
4463
+ }
4464
+ });
4465
+ });
4466
+ };
4418
4467
  /**
4419
4468
  *
4420
4469
  * Stores Wallaby auth public key to local storage
@@ -4511,7 +4560,6 @@ var StorageService = /** @class */ (function () {
4511
4560
  /**
4512
4561
  *
4513
4562
  * Fetches encrypted private key from local storage
4514
- * @param userId
4515
4563
  */
4516
4564
  StorageService.prototype.getEncryptedPrivateKey = function () {
4517
4565
  return __awaiter(this, void 0, void 0, function () {
@@ -4767,17 +4815,15 @@ var StorageService = /** @class */ (function () {
4767
4815
  this.removeItem("encryptedSeed_".concat(this.userId)),
4768
4816
  this.removeItem("encryptedAlgorandSeed_".concat(this.userId)),
4769
4817
  this.removeItem("accessToken_".concat(this.userId)),
4770
- this.delete(LocalStorageItems.AccessToken),
4771
- this.delete(LocalStorageItems.ClientAuthPublicKey),
4772
- // this.delete(LocalStorageItems.ClientAuthToken),
4773
- this.delete(LocalStorageItems.EncryptedAlgorandSeedPhrase),
4774
- this.delete(LocalStorageItems.EncryptedStandardSeedPhrase),
4775
- this.delete(LocalStorageItems.EncryptedKeyShares),
4776
- this.delete(LocalStorageItems.EncryptedShare),
4777
- this.delete(LocalStorageItems.PrimaryDeviceKeyShare),
4778
- this.delete(LocalStorageItems.BackupDeviceKeyShare),
4779
- this.delete(LocalStorageItems.EncryptedDevicePrivateKey),
4780
- this.delete(LocalStorageItems.WallabyAuthPubKey),
4818
+ this.delete(V2KeyNames.AccessToken),
4819
+ this.delete(V2KeyNames.ClientAuthPublicKey),
4820
+ // this.delete(V2KeyNames.ClientAuthToken),
4821
+ this.delete(V1KeyNames.EncryptedAlgorandSeedPhrase),
4822
+ this.delete(V2KeyNames.EncryptedStandardSeedPhrase),
4823
+ this.delete(V2KeyNames.PrimaryDeviceKeyShare),
4824
+ this.delete(V2KeyNames.BackupDeviceKeyShare),
4825
+ this.delete(V2KeyNames.EncryptedDevicePrivateKey),
4826
+ this.delete(V2KeyNames.WallabyAuthPubKey),
4781
4827
  ])];
4782
4828
  case 1:
4783
4829
  _a.sent();
@@ -4861,15 +4907,10 @@ function jwtHasExpired(jwt) {
4861
4907
  return millisecondsToJWTTimeout(jwt) <= 0;
4862
4908
  }
4863
4909
  function jwtHasSameUser(jwt, userId) {
4864
- if (!jwt) {
4910
+ if (!jwt || !userId) {
4865
4911
  return false;
4866
4912
  }
4867
4913
  var jwtDecoded = jwtDecode(jwt);
4868
- console.log('jwtDecoded', {
4869
- jwtDecoded: jwtDecoded,
4870
- userId: userId,
4871
- jwt: jwt,
4872
- });
4873
4914
  return jwtDecoded.externalUserId === userId;
4874
4915
  }
4875
4916
  function jwtIsSecure(jwt) {
@@ -4892,23 +4933,32 @@ function millisecondsToJWTTimeout(jwt) {
4892
4933
 
4893
4934
  var Base = /** @class */ (function () {
4894
4935
  function Base(config) {
4895
- var _a;
4896
4936
  this.apiKey = config.apiKey;
4897
4937
  this.baseUrl = config.baseUrl;
4898
4938
  this.userId = config.userId;
4899
- this.clientAuthToken = (_a = config.clientAuthToken) !== null && _a !== void 0 ? _a : config === null || config === void 0 ? void 0 : config.jwt;
4900
4939
  this.options = config.options;
4940
+ this._initializeClientAuthToken(config.clientAuthToken);
4901
4941
  this.request = this.request.bind(this);
4902
- if (!jwtHasSameUser(this.clientAuthToken, this.userId)) {
4942
+ }
4943
+ Object.defineProperty(Base.prototype, "setClientAuthToken", {
4944
+ set: function (token) {
4945
+ this._initializeClientAuthToken(token);
4946
+ },
4947
+ enumerable: false,
4948
+ configurable: true
4949
+ });
4950
+ Base.prototype._initializeClientAuthToken = function (token) {
4951
+ if (!jwtHasSameUser(token, this.userId)) {
4903
4952
  throw new Error('Client auth token does not match the user id. Blocking API call.');
4904
4953
  }
4905
- if (jwtIsSecure(this.clientAuthToken)) {
4954
+ this.clientAuthToken = token;
4955
+ if (jwtIsSecure(token)) {
4906
4956
  this.deviceAuthType = AuthType.Password;
4907
4957
  }
4908
4958
  else {
4909
4959
  this.deviceAuthType = AuthType.Passkey;
4910
4960
  }
4911
- }
4961
+ };
4912
4962
  Object.defineProperty(Base.prototype, "deviceStorage", {
4913
4963
  /**
4914
4964
  * This library uses `localStorage` as the default storage.
@@ -4999,7 +5049,7 @@ var Base = /** @class */ (function () {
4999
5049
  if (options === null || options === void 0 ? void 0 : options.queryParams) {
5000
5050
  url += "?".concat(objectToQueryParams(options.queryParams));
5001
5051
  }
5002
- return [4 /*yield*/, this.getRequestHeaders()];
5052
+ return [4 /*yield*/, this._getRequestHeaders()];
5003
5053
  case 1:
5004
5054
  headers = _p.sent();
5005
5055
  if ((_b = this.options) === null || _b === void 0 ? void 0 : _b.headers) {
@@ -5011,15 +5061,15 @@ var Base = /** @class */ (function () {
5011
5061
  headers: headers,
5012
5062
  });
5013
5063
  http.interceptors.response.use(function (response) { return response; }, function (error) {
5014
- var _a, _b, _c, _d, _e;
5064
+ var _a, _b, _c, _d, _e, _f;
5015
5065
  if ((_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.data) {
5016
- 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);
5066
+ 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);
5017
5067
  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) !== ErrorResponseCodes.user_already_exists) {
5018
5068
  return Promise.reject((_e = error === null || error === void 0 ? void 0 : error.response) === null || _e === void 0 ? void 0 : _e.data);
5019
5069
  }
5020
5070
  }
5021
5071
  logger.error('SDK::Base::Interceptor::error', error);
5022
- return Promise.reject(error);
5072
+ return Promise.reject((_f = error === null || error === void 0 ? void 0 : error.response) === null || _f === void 0 ? void 0 : _f.data);
5023
5073
  });
5024
5074
  _a = route.method;
5025
5075
  switch (_a) {
@@ -5034,7 +5084,7 @@ var Base = /** @class */ (function () {
5034
5084
  return [4 /*yield*/, http.get(url)];
5035
5085
  case 3:
5036
5086
  result = _p.sent();
5037
- logger.info('SDK::Base::RequestMethod.Get::result.data', result === null || result === void 0 ? void 0 : result.data);
5087
+ logger.debug('SDK::Base::RequestMethod.Get::result.data', result === null || result === void 0 ? void 0 : result.data);
5038
5088
  return [2 /*return*/, result === null || result === void 0 ? void 0 : result.data];
5039
5089
  case 4:
5040
5090
  error_1 = _p.sent();
@@ -5048,7 +5098,7 @@ var Base = /** @class */ (function () {
5048
5098
  return [4 /*yield*/, http.post(url, JSON.stringify(options === null || options === void 0 ? void 0 : options.payload))];
5049
5099
  case 6:
5050
5100
  result = _p.sent();
5051
- logger.info('SDK::Base::RequestMethod.Post::result.data', result === null || result === void 0 ? void 0 : result.data);
5101
+ logger.debug('SDK::Base::RequestMethod.Post::result.data', result === null || result === void 0 ? void 0 : result.data);
5052
5102
  return [2 /*return*/, result === null || result === void 0 ? void 0 : result.data];
5053
5103
  case 7:
5054
5104
  error_2 = _p.sent();
@@ -5066,7 +5116,7 @@ var Base = /** @class */ (function () {
5066
5116
  return [4 /*yield*/, http.put(url, (_j = JSON.stringify(options === null || options === void 0 ? void 0 : options.payload)) !== null && _j !== void 0 ? _j : null)];
5067
5117
  case 9:
5068
5118
  result = _p.sent();
5069
- logger.info('SDK::Base::RequestMethod.Put::result.data', result.data);
5119
+ logger.debug('SDK::Base::RequestMethod.Put::result.data', result.data);
5070
5120
  return [2 /*return*/, result === null || result === void 0 ? void 0 : result.data];
5071
5121
  case 10:
5072
5122
  error_3 = _p.sent();
@@ -5080,7 +5130,7 @@ var Base = /** @class */ (function () {
5080
5130
  return [4 /*yield*/, http.delete(url)];
5081
5131
  case 12:
5082
5132
  result = _p.sent();
5083
- logger.info('SDK::Base::RequestMethod.Delete::result.data', result.data);
5133
+ logger.debug('SDK::Base::RequestMethod.Delete::result.data', result.data);
5084
5134
  return [2 /*return*/, result === null || result === void 0 ? void 0 : result.data];
5085
5135
  case 13:
5086
5136
  error_4 = _p.sent();
@@ -5100,7 +5150,7 @@ var Base = /** @class */ (function () {
5100
5150
  });
5101
5151
  });
5102
5152
  };
5103
- Base.prototype.getRequestHeaders = function () {
5153
+ Base.prototype._getRequestHeaders = function () {
5104
5154
  return __awaiter(this, void 0, void 0, function () {
5105
5155
  var accessToken, headers;
5106
5156
  return __generator(this, function (_a) {
@@ -5223,6 +5273,11 @@ var WalletRoutes = {
5223
5273
  method: RequestMethod.Post,
5224
5274
  requiresAccessToken: true,
5225
5275
  },
5276
+ generateWalletAddresses: {
5277
+ fullPath: '/wallets/generate-wallet-addresses',
5278
+ method: RequestMethod.Post,
5279
+ requiresAccessToken: true,
5280
+ },
5226
5281
  updateAsset: {
5227
5282
  fullPath: '/wallets/asset/update',
5228
5283
  method: RequestMethod.Put,
@@ -5284,6 +5339,11 @@ var AuthRoutes = {
5284
5339
  method: RequestMethod.Get,
5285
5340
  requiresAccessToken: true,
5286
5341
  },
5342
+ getPasskeyCredentials: {
5343
+ fullPath: '/auth/passkey-credentials',
5344
+ method: RequestMethod.Get,
5345
+ requiresAccessToken: true,
5346
+ },
5287
5347
  };
5288
5348
 
5289
5349
  var SystemRoutes = {
@@ -5320,6 +5380,39 @@ var SystemRoutes = {
5320
5380
  },
5321
5381
  };
5322
5382
 
5383
+ var TransactionsRoutes = {
5384
+ transfer: {
5385
+ fullPath: '/transactions/transfer',
5386
+ method: RequestMethod.Post,
5387
+ requiresAccessToken: true,
5388
+ },
5389
+ transferWithShares: {
5390
+ fullPath: '/transactions/transfer-with-shares',
5391
+ method: RequestMethod.Post,
5392
+ requiresAccessToken: true,
5393
+ },
5394
+ createAllowance: {
5395
+ fullPath: '/transactions/create-allowance',
5396
+ method: RequestMethod.Post,
5397
+ requiresAccessToken: true,
5398
+ },
5399
+ estimateFee: {
5400
+ fullPath: '/transactions/estimate-fee',
5401
+ method: RequestMethod.Get,
5402
+ requiresAccessToken: true,
5403
+ },
5404
+ getTransaction: {
5405
+ fullPath: '/transactions/status',
5406
+ method: RequestMethod.Get,
5407
+ requiresAccessToken: true,
5408
+ },
5409
+ getTransactions: {
5410
+ fullPath: '/query/transactions',
5411
+ method: RequestMethod.Get,
5412
+ requiresAccessToken: true,
5413
+ },
5414
+ };
5415
+
5323
5416
  // Common prologue and epilogue for sync/async functions
5324
5417
  function pbkdf2Init(hash, _password, _salt, _opts) {
5325
5418
  hash$1(hash);
@@ -5456,8 +5549,6 @@ var Cipher = /** @class */ (function () {
5456
5549
  if (typeof cipherText === 'string') {
5457
5550
  cipherText = JSON.parse(cipherText);
5458
5551
  }
5459
- console.log('SDK::CipherService::decrypt::cipherText', cipherText);
5460
- console.log('SDK::CipherService::decrypt::decryptionKey', decryptionKey);
5461
5552
  return [4 /*yield*/, decryptWithPrivateKey(decryptionKey, cipherText)];
5462
5553
  case 1:
5463
5554
  decrypted = _c.sent();
@@ -5484,7 +5575,6 @@ var Cipher = /** @class */ (function () {
5484
5575
  switch (_b.label) {
5485
5576
  case 0:
5486
5577
  _b.trys.push([0, 6, , 7]);
5487
- console.log('SDK::CipherService::getCredentialsKeyPair::options', options);
5488
5578
  derivedKeyPair = void 0;
5489
5579
  _a = options.authType;
5490
5580
  switch (_a) {
@@ -5545,7 +5635,7 @@ var Cipher = /** @class */ (function () {
5545
5635
  };
5546
5636
  /**
5547
5637
  *
5548
- * @description Prepares the stored data for transport by decrypting it and then encrypting it with the Wallaby public key.
5638
+ * @description Prepares the stored data for transport by double decrypting it and then encrypting it with the Wallaby public key.
5549
5639
  * @param { Encrypted } storedEncryptedData - The encrypted data to be decrypted.
5550
5640
  * @param { Encrypted } encryptedDevicePrivateKey - The encrypted device private key.
5551
5641
  * @param { string } wallabyPublicKey - The public key to encrypt the data with.
@@ -5595,14 +5685,12 @@ var Cipher = /** @class */ (function () {
5595
5685
  })];
5596
5686
  case 1:
5597
5687
  encryptedOnceData = _c.sent();
5598
- console.log('SDK::prepareDecryptedDataForStorage::encryptedOnceData', encryptedOnceData);
5599
5688
  return [4 /*yield*/, this.encrypt({
5600
5689
  data: JSON.stringify(encryptedOnceData),
5601
5690
  encryptionKey: credentialsKeyPair.publicKey,
5602
5691
  })];
5603
5692
  case 2:
5604
5693
  encryptedTwiceData = _c.sent();
5605
- console.log('SDK::prepareDecryptedDataForStorage::encryptedTwiceData', encryptedTwiceData);
5606
5694
  return [2 /*return*/, encryptedTwiceData];
5607
5695
  case 3:
5608
5696
  error_4 = _c.sent();
@@ -5640,14 +5728,12 @@ var Cipher = /** @class */ (function () {
5640
5728
  })];
5641
5729
  case 2:
5642
5730
  encryptedOnceData = _c.sent();
5643
- console.log('SDK::prepareTransportDataForStorage::encryptedOnceData', encryptedOnceData);
5644
5731
  return [4 /*yield*/, this.encrypt({
5645
5732
  data: JSON.stringify(encryptedOnceData),
5646
5733
  encryptionKey: credentialsKeyPair.publicKey,
5647
5734
  })];
5648
5735
  case 3:
5649
5736
  encryptedTwiceData = _c.sent();
5650
- console.log('SDK::prepareTransportDataForStorage::encryptedTwiceData', encryptedTwiceData);
5651
5737
  return [2 /*return*/, encryptedTwiceData];
5652
5738
  case 4:
5653
5739
  error_5 = _c.sent();
@@ -5677,7 +5763,6 @@ var Cipher = /** @class */ (function () {
5677
5763
  return [4 /*yield*/, this.getCredentialsKeyPair(options)];
5678
5764
  case 1:
5679
5765
  cryptoKeyPair = _c.sent();
5680
- console.log('SDK::CipherService::displayDataFromServer::cryptoKeyPair', cryptoKeyPair);
5681
5766
  return [4 /*yield*/, this.decrypt({
5682
5767
  cipherText: encryptedDevicePrivateKey,
5683
5768
  decryptionKey: cryptoKeyPair.privateKey,
@@ -5687,14 +5772,12 @@ var Cipher = /** @class */ (function () {
5687
5772
  if (!decryptedDevicePrivateKey) {
5688
5773
  throw new Error('Data could not be decrypted');
5689
5774
  }
5690
- console.log('SDK::CipherService::displayDataFromServer::decryptedDevicePrivateKey', decryptedDevicePrivateKey);
5691
5775
  return [4 /*yield*/, this.decrypt({
5692
5776
  cipherText: encryptedData,
5693
5777
  decryptionKey: decryptedDevicePrivateKey,
5694
5778
  })];
5695
5779
  case 3:
5696
5780
  decryptedData = _c.sent();
5697
- console.log('SDK::CipherService::displayDataFromServer::decryptedData', decryptedData);
5698
5781
  return [2 /*return*/, decryptedData];
5699
5782
  case 4:
5700
5783
  error_6 = _c.sent();
@@ -5748,7 +5831,6 @@ var Cipher = /** @class */ (function () {
5748
5831
  })];
5749
5832
  case 4:
5750
5833
  decryptedTwiceData = _c.sent();
5751
- console.log('decryptedTwiceData', decryptedTwiceData);
5752
5834
  if (!decryptedTwiceData) {
5753
5835
  throw new Error('Data could not be decrypted');
5754
5836
  }
@@ -5774,23 +5856,18 @@ var Cipher = /** @class */ (function () {
5774
5856
  switch (_c.label) {
5775
5857
  case 0:
5776
5858
  _c.trys.push([0, 3, , 4]);
5777
- console.log('SDK::CipherService::flipEncryptedData::cipherText', cipherText);
5778
- console.log('SDK::CipherService::flipEncryptedData::decryptionKey', decryptionKey);
5779
- console.log('SDK::CipherService::flipEncryptedData::encryptionKey', encryptionKey);
5780
5859
  return [4 /*yield*/, this.decrypt({
5781
5860
  cipherText: cipherText,
5782
5861
  decryptionKey: decryptionKey,
5783
5862
  })];
5784
5863
  case 1:
5785
5864
  decryptedData = _c.sent();
5786
- console.log('SDK::CipherService::flipEncryptedData::decryptedData', decryptedData);
5787
5865
  return [4 /*yield*/, this.encrypt({
5788
5866
  data: decryptedData,
5789
5867
  encryptionKey: encryptionKey,
5790
5868
  })];
5791
5869
  case 2:
5792
5870
  rewrappedData = _c.sent();
5793
- console.log('SDK::CipherService::flipEncryptedData::rewrappedData', rewrappedData);
5794
5871
  if (!rewrappedData) {
5795
5872
  throw new Error('Failed to rewrap seed phrase with Wallaby public key');
5796
5873
  }
@@ -5816,7 +5893,6 @@ var Cipher = /** @class */ (function () {
5816
5893
  var inputKeyMaterial = _b.inputKeyMaterial;
5817
5894
  return __generator(this, function (_c) {
5818
5895
  identityFromInputKey = createIdentity(inputKeyMaterial);
5819
- console.log('SDK::CipherService::deriveKeyPairFromPasskey::identityFromInputKey', identityFromInputKey);
5820
5896
  return [2 /*return*/, identityFromInputKey];
5821
5897
  });
5822
5898
  });
@@ -5834,7 +5910,6 @@ var Cipher = /** @class */ (function () {
5834
5910
  return __generator(this, function (_c) {
5835
5911
  encryptionKey = pbkdf2Sync(utf8ToBytes$2(password), utf8ToBytes$2(salt), PBKDF2_ITERATIONS, DEFAULT_ENTROPY_BYTES$1, 'sha256');
5836
5912
  encryptionKeyPair = createIdentity(encryptionKey);
5837
- console.log('SDK::CipherService::deriveKeyPairFromPassword::encryptionKeyPair', encryptionKeyPair);
5838
5913
  return [2 /*return*/, encryptionKeyPair];
5839
5914
  });
5840
5915
  });
@@ -5842,6 +5917,17 @@ var Cipher = /** @class */ (function () {
5842
5917
  return Cipher;
5843
5918
  }());
5844
5919
 
5920
+ var decodeBase64URL = function (base64url) {
5921
+ var base64 = base64url.replace(/-/g, '+').replace(/_/g, '/');
5922
+ var padded = base64.padEnd(base64.length + ((4 - (base64.length % 4)) % 4), '=');
5923
+ var binary = atob(padded);
5924
+ var bytes = new Uint8Array(binary.length);
5925
+ for (var i = 0; i < binary.length; i++) {
5926
+ bytes[i] = binary.charCodeAt(i);
5927
+ }
5928
+ return bytes;
5929
+ };
5930
+
5845
5931
  var UnknownError = {
5846
5932
  error: 'UnknownError',
5847
5933
  message: 'An unknown error occurred',
@@ -5960,153 +6046,74 @@ var PasskeyErrorCodes = [
5960
6046
  PassthroughSeeCausePropertyError,
5961
6047
  ];
5962
6048
 
6049
+ /**
6050
+ * Web Authenticator Implementation
6051
+ *
6052
+ * This file contains the web-specific authenticator logic using WebAuthn.
6053
+ * It's automatically picked up by web bundlers (webpack, Rollup, etc.) when importing './authenticator'
6054
+ *
6055
+ * React Native will use authenticator.native.ts instead due to the .native.ts extension.
6056
+ */
5963
6057
  var Authenticator = /** @class */ (function () {
5964
6058
  function Authenticator() {
5965
- // This should be defined in a react-native environment.
5966
- // eslint-disable-next-line @typescript-eslint/no-require-imports
5967
- var ReactNative = require('react-native');
5968
- if (ReactNative && ReactNative.Platform && ReactNative.Platform.OS) {
5969
- this.platform = ReactNative.Platform.OS;
5970
- }
5971
- else if (typeof window !== 'undefined') {
5972
- this.platform = 'web';
5973
- }
5974
- else if (browser$1 && browser$1.platform === 'darwin') {
5975
- this.platform = 'macos';
5976
- }
5977
- else {
5978
- this.platform = 'unknown';
5979
- }
6059
+ // Web environment - no additional setup needed
5980
6060
  }
5981
6061
  Authenticator.prototype.register = function (_a) {
5982
6062
  return __awaiter(this, arguments, void 0, function (_b) {
5983
- var _c, response, error_1, passkeyMappedPayload, response, registrationResponse, error_2;
6063
+ var response, error_1;
5984
6064
  var optionsJSON = _b.optionsJSON;
5985
- return __generator(this, function (_d) {
5986
- switch (_d.label) {
6065
+ return __generator(this, function (_c) {
6066
+ switch (_c.label) {
5987
6067
  case 0:
5988
- _c = this.platform;
5989
- switch (_c) {
5990
- case 'web': return [3 /*break*/, 1];
5991
- case 'android': return [3 /*break*/, 5];
5992
- case 'ios': return [3 /*break*/, 5];
5993
- }
5994
- return [3 /*break*/, 9];
5995
- case 1:
5996
- _d.trys.push([1, 3, , 4]);
6068
+ _c.trys.push([0, 2, , 3]);
5997
6069
  if (!window || !window.navigator.credentials) {
5998
6070
  throw new Error('WebAuthn is not supported in this browser.');
5999
6071
  }
6000
6072
  return [4 /*yield*/, WebAuthn.startRegistration({ optionsJSON: optionsJSON })];
6001
- case 2:
6002
- response = _d.sent();
6073
+ case 1:
6074
+ response = _c.sent();
6003
6075
  return [2 /*return*/, response];
6004
- case 3:
6005
- error_1 = _d.sent();
6076
+ case 2:
6077
+ error_1 = _c.sent();
6006
6078
  this.handlePasskeyError(error_1);
6007
- return [3 /*break*/, 4];
6008
- case 4: return [3 /*break*/, 9];
6009
- case 5:
6010
- _d.trys.push([5, 7, , 8]);
6011
- if (!Passkey.isSupported()) {
6012
- if (this.platform === 'android') {
6013
- throw new Error(AndroidVersionNotSupportedError.error);
6014
- }
6015
- else {
6016
- throw new Error(IOSVersionNotSupportedError.error);
6017
- }
6018
- }
6019
- // Those checks are only to satisfy the type conversion to `PasskeyCreateRequest`
6020
- if (!optionsJSON || !optionsJSON.rp || !optionsJSON.user || !optionsJSON.extensions) {
6021
- throw new Error('Invalid passkey options. Required fields are missing.');
6022
- }
6023
- passkeyMappedPayload = this.mapPasskeyCreationPayload(optionsJSON);
6024
- return [4 /*yield*/, Passkey.create(passkeyMappedPayload)];
6025
- case 6:
6026
- response = _d.sent();
6027
- registrationResponse = this.mapPasskeyCreationResponse(response);
6028
- return [2 /*return*/, registrationResponse];
6029
- case 7:
6030
- error_2 = _d.sent();
6031
- this.handlePasskeyError(error_2);
6032
- return [3 /*break*/, 8];
6033
- case 8: return [3 /*break*/, 9];
6034
- case 9:
6035
- // This should never be reached, but TypeScript needs a return statement.
6036
- throw new Error('Unsupported client type or unhandled error.');
6079
+ throw error_1; // This will never be reached due to handlePasskeyError throwing, but satisfies TypeScript
6080
+ case 3: return [2 /*return*/];
6037
6081
  }
6038
6082
  });
6039
6083
  });
6040
6084
  };
6041
6085
  Authenticator.prototype.authenticate = function (_a) {
6042
6086
  return __awaiter(this, arguments, void 0, function (_b) {
6043
- var _c, response, error_3, passkeyMappedPayload, response, registrationResponse, error_4, error_5;
6087
+ var response, error_2;
6044
6088
  var optionsJSON = _b.optionsJSON;
6045
- return __generator(this, function (_d) {
6046
- switch (_d.label) {
6089
+ return __generator(this, function (_c) {
6090
+ switch (_c.label) {
6047
6091
  case 0:
6048
- _d.trys.push([0, 10, , 11]);
6049
- _c = this.platform;
6050
- switch (_c) {
6051
- case 'web': return [3 /*break*/, 1];
6052
- case 'android': return [3 /*break*/, 5];
6053
- case 'ios': return [3 /*break*/, 5];
6054
- }
6055
- return [3 /*break*/, 9];
6056
- case 1:
6057
- _d.trys.push([1, 3, , 4]);
6092
+ _c.trys.push([0, 2, , 3]);
6058
6093
  if (!window || !window.navigator.credentials) {
6059
6094
  throw new Error('WebAuthn is not supported in this browser.');
6060
6095
  }
6061
6096
  return [4 /*yield*/, WebAuthn.startAuthentication({ optionsJSON: optionsJSON })];
6062
- case 2:
6063
- response = _d.sent();
6097
+ case 1:
6098
+ response = _c.sent();
6064
6099
  return [2 /*return*/, response];
6065
- case 3:
6066
- error_3 = _d.sent();
6067
- this.handlePasskeyError(error_3);
6068
- return [3 /*break*/, 4];
6069
- case 4: return [3 /*break*/, 9];
6070
- case 5:
6071
- _d.trys.push([5, 7, , 8]);
6072
- if (!Passkey.isSupported()) {
6073
- if (this.platform === 'android') {
6074
- throw new Error(AndroidVersionNotSupportedError.error);
6075
- }
6076
- else {
6077
- throw new Error(IOSVersionNotSupportedError.error);
6078
- }
6079
- }
6080
- passkeyMappedPayload = this.mapPasskeyAuthenticationPayload(optionsJSON);
6081
- return [4 /*yield*/, Passkey.get(passkeyMappedPayload)];
6082
- case 6:
6083
- response = _d.sent();
6084
- registrationResponse = this.mapPasskeyAuthenticationResponse(response);
6085
- return [2 /*return*/, registrationResponse];
6086
- case 7:
6087
- error_4 = _d.sent();
6088
- this.handlePasskeyError(error_4);
6089
- return [3 /*break*/, 8];
6090
- case 8: return [3 /*break*/, 9];
6091
- case 9: return [3 /*break*/, 11];
6092
- case 10:
6093
- error_5 = _d.sent();
6094
- this.handlePasskeyError(error_5);
6095
- return [3 /*break*/, 11];
6096
- case 11:
6097
- // This should never be reached, but TypeScript needs a return statement.
6098
- throw new Error('Unknown client type or unhandled error.');
6100
+ case 2:
6101
+ error_2 = _c.sent();
6102
+ this.handlePasskeyError(error_2);
6103
+ throw error_2; // This will never be reached due to handlePasskeyError throwing, but satisfies TypeScript
6104
+ case 3: return [2 /*return*/];
6099
6105
  }
6100
6106
  });
6101
6107
  });
6102
6108
  };
6103
6109
  /**
6104
- *
6105
6110
  * @description Handles the passkey error and throws a user-friendly error message.
6106
- * @param {WebAuthnError | PasskeyError | Error | any} error
6111
+ * @param {WebAuthnError | Error | any} error
6107
6112
  * @returns {Error} The error message.
6108
6113
  */
6109
6114
  Authenticator.prototype.handlePasskeyError = function (error) {
6115
+ logger.error('SDK::Authenticator::handlePasskeyError', error);
6116
+ console.error('SDK::Authenticator::handlePasskeyError', error);
6110
6117
  if (error instanceof WebAuthn.WebAuthnError) {
6111
6118
  return this.throwPasskeyError(error.code);
6112
6119
  }
@@ -6125,107 +6132,13 @@ var Authenticator = /** @class */ (function () {
6125
6132
  };
6126
6133
  Authenticator.prototype.throwPasskeyError = function (errorCode) {
6127
6134
  var _a;
6135
+ console.error('SDK::Authenticator::throwPasskeyError', errorCode);
6128
6136
  var errorToThrow = PasskeyErrorCodes.find(function (error) {
6129
6137
  return error.error === errorCode;
6130
6138
  });
6131
6139
  logger.error('SDK::Authenticator::error', errorToThrow);
6132
6140
  throw new Error((_a = errorToThrow === null || errorToThrow === void 0 ? void 0 : errorToThrow.message) !== null && _a !== void 0 ? _a : UnknownError.message);
6133
6141
  };
6134
- Authenticator.prototype.mapPasskeyCreationPayload = function (optionsJSON) {
6135
- var _a, _b, _c, _d;
6136
- var authenticatorSelection = optionsJSON.authenticatorSelection;
6137
- var requestedExtensions = optionsJSON.extensions;
6138
- if (!((_b = (_a = requestedExtensions.prf) === null || _a === void 0 ? void 0 : _a.eval) === null || _b === void 0 ? void 0 : _b.first)) {
6139
- throw new Error('Invalid passkey options. Required fields are missing.');
6140
- }
6141
- var prfFirstSalt = new Uint8Array(ArrayBuffer.isView(requestedExtensions.prf.eval.first)
6142
- ? requestedExtensions.prf.eval.first.buffer
6143
- : requestedExtensions.prf.eval.first);
6144
- return {
6145
- user: {
6146
- id: optionsJSON.user.id,
6147
- name: optionsJSON.user.name,
6148
- displayName: optionsJSON.user.displayName,
6149
- },
6150
- rp: {
6151
- id: (_c = optionsJSON.rp.id) !== null && _c !== void 0 ? _c : '',
6152
- name: optionsJSON.rp.name,
6153
- },
6154
- extensions: {
6155
- largeBlob: { supported: false },
6156
- prf: {
6157
- eval: {
6158
- first: prfFirstSalt,
6159
- },
6160
- },
6161
- },
6162
- authenticatorSelection: {
6163
- authenticatorAttachment: authenticatorSelection === null || authenticatorSelection === void 0 ? void 0 : authenticatorSelection.authenticatorAttachment,
6164
- requireResidentKey: (_d = authenticatorSelection === null || authenticatorSelection === void 0 ? void 0 : authenticatorSelection.requireResidentKey) !== null && _d !== void 0 ? _d : false,
6165
- residentKey: authenticatorSelection === null || authenticatorSelection === void 0 ? void 0 : authenticatorSelection.residentKey,
6166
- userVerification: authenticatorSelection === null || authenticatorSelection === void 0 ? void 0 : authenticatorSelection.userVerification,
6167
- },
6168
- challenge: optionsJSON.challenge,
6169
- pubKeyCredParams: optionsJSON.pubKeyCredParams.map(function (param) { return ({
6170
- type: param.type,
6171
- alg: param.alg,
6172
- }); }),
6173
- };
6174
- };
6175
- Authenticator.prototype.mapPasskeyCreationResponse = function (response) {
6176
- var _a, _b, _c;
6177
- return {
6178
- id: response.id, // ensure this is Base64URLString
6179
- rawId: response.rawId, // ensure this is Base64URLString
6180
- type: ((_a = response.type) !== null && _a !== void 0 ? _a : 'public-key'),
6181
- response: response.response,
6182
- // this should satisfy the expected extension response.
6183
- clientExtensionResults: {
6184
- credProps: { rk: false },
6185
- prf: (_c = (_b = response.extensions) === null || _b === void 0 ? void 0 : _b.clientExtensionResults) === null || _c === void 0 ? void 0 : _c.prf,
6186
- },
6187
- };
6188
- };
6189
- Authenticator.prototype.mapPasskeyAuthenticationResponse = function (response) {
6190
- var _a, _b;
6191
- return {
6192
- id: response.id, // ensure this is Base64URLString
6193
- rawId: response.rawId, // ensure this is Base64URLString
6194
- type: ((_a = response.type) !== null && _a !== void 0 ? _a : 'public-key'),
6195
- response: response.response,
6196
- // this should satisfy the expected extension response.
6197
- clientExtensionResults: {
6198
- credProps: { rk: false },
6199
- prf: (_b = response === null || response === void 0 ? void 0 : response.clientExtensionResults) === null || _b === void 0 ? void 0 : _b.prf,
6200
- },
6201
- };
6202
- };
6203
- Authenticator.prototype.mapPasskeyAuthenticationPayload = function (optionsJSON) {
6204
- var _a, _b, _c, _d;
6205
- var requestedExtensions = optionsJSON.extensions;
6206
- if (!((_b = (_a = requestedExtensions.prf) === null || _a === void 0 ? void 0 : _a.eval) === null || _b === void 0 ? void 0 : _b.first)) {
6207
- throw new Error('Invalid passkey options. Required fields are missing.');
6208
- }
6209
- var prfFirstSalt = new Uint8Array(ArrayBuffer.isView(requestedExtensions.prf.eval.first)
6210
- ? requestedExtensions.prf.eval.first.buffer
6211
- : requestedExtensions.prf.eval.first);
6212
- return {
6213
- rpId: (_c = optionsJSON.rpId) !== null && _c !== void 0 ? _c : '',
6214
- challenge: optionsJSON.challenge,
6215
- allowCredentials: (_d = optionsJSON.allowCredentials) === null || _d === void 0 ? void 0 : _d.map(function (credential) { return ({
6216
- id: credential.id,
6217
- type: 'public-key',
6218
- transports: [AuthenticatorTransport.internal],
6219
- }); }),
6220
- extensions: {
6221
- prf: {
6222
- eval: {
6223
- first: prfFirstSalt,
6224
- },
6225
- },
6226
- },
6227
- };
6228
- };
6229
6142
  return Authenticator;
6230
6143
  }());
6231
6144
 
@@ -6237,12 +6150,52 @@ var PasskeyService = /** @class */ (function () {
6237
6150
  this.request = request;
6238
6151
  this.authenticator = new Authenticator();
6239
6152
  }
6240
- /**
6241
- * @description Adds a new passkey to the user's account on that device.
6242
- * @param { AsymmetricKeyPair } deviceKeyPair
6243
- * @param { SignatureMessageResponse } challengeResponse
6244
- * @returns { AuthResponse } The authentication response containing the access token and user information.
6245
- */
6153
+ PasskeyService.prototype.preparePasskeyRequestOptions = function (options) {
6154
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
6155
+ 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)
6156
+ ? 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)
6157
+ : ((_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
6158
+ ? 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)
6159
+ : 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'
6160
+ ? 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))
6161
+ : undefined;
6162
+ if (!prfExtensionEvaluation) {
6163
+ throw new Error('Passkey extension cannot be used at this time.');
6164
+ }
6165
+ var parsedOptions = __assign(__assign({}, options), { extensions: {
6166
+ prf: {
6167
+ eval: {
6168
+ first: prfExtensionEvaluation,
6169
+ },
6170
+ },
6171
+ } });
6172
+ // While the authenticator still works with the prf and would return the response (if any),
6173
+ // the library `@simplewebauthn/browser` does not support the prf extension in its type intentionally.
6174
+ // > "Using the prf extension does not fall under the simple use of webauthn."
6175
+ return parsedOptions;
6176
+ };
6177
+ PasskeyService.prototype.preparePasskeyCreationOptions = function (options) {
6178
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
6179
+ 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)
6180
+ ? 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)
6181
+ : ((_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
6182
+ ? 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)
6183
+ : 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'
6184
+ ? 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))
6185
+ : undefined;
6186
+ var parsedOptions = __assign(__assign({}, options), { extensions: __assign(__assign({}, options === null || options === void 0 ? void 0 : options.extensions), { prf: {
6187
+ eval: {
6188
+ first: prfExtensionEvaluation,
6189
+ },
6190
+ } }) });
6191
+ return parsedOptions;
6192
+ };
6193
+ /**
6194
+ * @description Adds a new passkey to the user's account on that device.
6195
+ * @param { AsymmetricKeyPair } deviceKeyPair
6196
+ * @param { SignatureMessageResponse } challengeResponse
6197
+ * @returns { AuthResponse } The authentication response containing the access token and user information.
6198
+ */
6246
6199
  PasskeyService.prototype.addNewPasskey = function (_a) {
6247
6200
  return __awaiter(this, arguments, void 0, function (_b) {
6248
6201
  var passkeyCredential, credentialsKeyPair, singInResponse, encryptedNewDevicePrivateKey, error_1;
@@ -6313,21 +6266,20 @@ var PasskeyService = /** @class */ (function () {
6313
6266
  */
6314
6267
  PasskeyService.prototype.authenticate = function (_a) {
6315
6268
  return __awaiter(this, arguments, void 0, function (_b) {
6316
- var extensions, firstSalt, updatedOptions, passkeyCredential, credentialsKeyPair, decryptedDevicePrivateKey, signatureMessage, _c, signature, message, singInResponse, error_2;
6317
- var _d, _e;
6269
+ var parsedOptions, updatedOptions, passkeyCredential, credentialsKeyPair, decryptedDevicePrivateKey, _c, signature, message, singInResponse, error_2;
6270
+ var _d, _e, _f;
6318
6271
  var deviceKeyPair = _b.deviceKeyPair, challengeResponse = _b.challengeResponse;
6319
- return __generator(this, function (_f) {
6320
- switch (_f.label) {
6272
+ return __generator(this, function (_g) {
6273
+ switch (_g.label) {
6321
6274
  case 0:
6322
- _f.trys.push([0, 8, , 9]);
6275
+ _g.trys.push([0, 7, , 8]);
6323
6276
  if (!challengeResponse || !challengeResponse.options) {
6324
6277
  throw new Error('Passkey challenge could not be retrieved, please try again later.');
6325
6278
  }
6326
- extensions = challengeResponse.options.extensions;
6327
- firstSalt = new Uint8Array((_e = (_d = extensions.prf) === null || _d === void 0 ? void 0 : _d.eval) === null || _e === void 0 ? void 0 : _e.first);
6328
- updatedOptions = __assign(__assign({}, challengeResponse.options), { extensions: __assign(__assign({}, omit(extensions, 'credProps')), { prf: {
6279
+ parsedOptions = this.preparePasskeyRequestOptions(challengeResponse.options);
6280
+ updatedOptions = __assign(__assign({}, challengeResponse.options), { extensions: __assign(__assign({}, omit(parsedOptions.extensions, 'credProps')), { prf: {
6329
6281
  eval: {
6330
- first: firstSalt,
6282
+ 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,
6331
6283
  },
6332
6284
  } }) });
6333
6285
  console.log('PasskeyService::authenticate: updatedOptions', updatedOptions);
@@ -6335,28 +6287,22 @@ var PasskeyService = /** @class */ (function () {
6335
6287
  optionsJSON: updatedOptions,
6336
6288
  })];
6337
6289
  case 1:
6338
- passkeyCredential = _f.sent();
6290
+ passkeyCredential = _g.sent();
6339
6291
  return [4 /*yield*/, this.handleCredentialsCreationFromPrfExtension(passkeyCredential)];
6340
6292
  case 2:
6341
- credentialsKeyPair = _f.sent();
6293
+ credentialsKeyPair = _g.sent();
6342
6294
  return [4 /*yield*/, this.cipher.decrypt({
6343
6295
  cipherText: deviceKeyPair.encryptedDevicePrivateKey,
6344
6296
  decryptionKey: credentialsKeyPair.privateKey,
6345
6297
  })];
6346
6298
  case 3:
6347
- decryptedDevicePrivateKey = _f.sent();
6348
- return [4 /*yield*/, this.request(AuthRoutes.signatureMessage, {
6349
- method: AuthRoutes.signatureMessage.method,
6350
- payload: { clientAuthPubKey: deviceKeyPair.publicKey },
6351
- })];
6352
- case 4:
6353
- signatureMessage = _f.sent();
6299
+ decryptedDevicePrivateKey = _g.sent();
6354
6300
  return [4 /*yield*/, this.cipher.sign({
6355
- message: signatureMessage.message,
6301
+ message: challengeResponse.message,
6356
6302
  signingKey: decryptedDevicePrivateKey,
6357
6303
  })];
6358
- case 5:
6359
- _c = _f.sent(), signature = _c.signature, message = _c.message;
6304
+ case 4:
6305
+ _c = _g.sent(), signature = _c.signature, message = _c.message;
6360
6306
  return [4 /*yield*/, this.request(AuthRoutes.signIn, {
6361
6307
  method: AuthRoutes.signIn.method,
6362
6308
  payload: {
@@ -6367,8 +6313,8 @@ var PasskeyService = /** @class */ (function () {
6367
6313
  passkeyChallengeResponse: passkeyCredential,
6368
6314
  },
6369
6315
  })];
6370
- case 6:
6371
- singInResponse = _f.sent();
6316
+ case 5:
6317
+ singInResponse = _g.sent();
6372
6318
  if (!singInResponse || singInResponse.error) {
6373
6319
  throw new Error('Passkey authentication failed. Please try again.');
6374
6320
  }
@@ -6377,13 +6323,13 @@ var PasskeyService = /** @class */ (function () {
6377
6323
  deviceKeyPair: deviceKeyPair,
6378
6324
  passkeyCredential: passkeyCredential,
6379
6325
  })];
6380
- case 7:
6381
- _f.sent();
6326
+ case 6:
6327
+ _g.sent();
6382
6328
  return [2 /*return*/, __assign(__assign({}, singInResponse), { prfValue: credentialsKeyPair.prfValue })];
6383
- case 8:
6384
- error_2 = _f.sent();
6329
+ case 7:
6330
+ error_2 = _g.sent();
6385
6331
  throw this.authenticator.handlePasskeyError(error_2);
6386
- case 9: return [2 /*return*/];
6332
+ case 8: return [2 /*return*/];
6387
6333
  }
6388
6334
  });
6389
6335
  });
@@ -6397,13 +6343,13 @@ var PasskeyService = /** @class */ (function () {
6397
6343
  */
6398
6344
  PasskeyService.prototype.register = function (_a) {
6399
6345
  return __awaiter(this, arguments, void 0, function (_b) {
6400
- var _c, signature, message, extensions, firstSalt, updatedOptions, passkeyCredential, credentialsKeyPair, singUpResponse, encryptedNewDevicePrivateKey, error_3;
6401
- var _d, _e, _f;
6346
+ var _c, signature, message, parsedOptions, updatedOptions, passkeyCredential, credentialsKeyPair, singUpResponse, encryptedNewDevicePrivateKey, error_3;
6347
+ var _d, _e, _f, _g;
6402
6348
  var deviceKeyPair = _b.deviceKeyPair, challengeResponse = _b.challengeResponse;
6403
- return __generator(this, function (_g) {
6404
- switch (_g.label) {
6349
+ return __generator(this, function (_h) {
6350
+ switch (_h.label) {
6405
6351
  case 0:
6406
- _g.trys.push([0, 7, , 8]);
6352
+ _h.trys.push([0, 7, , 8]);
6407
6353
  if (!challengeResponse || !challengeResponse.options)
6408
6354
  throw new Error('Passkey challenge could not be retrieved, please try again later.');
6409
6355
  return [4 /*yield*/, this.cipher.sign({
@@ -6411,25 +6357,24 @@ var PasskeyService = /** @class */ (function () {
6411
6357
  signingKey: deviceKeyPair.privateKey,
6412
6358
  })];
6413
6359
  case 1:
6414
- _c = _g.sent(), signature = _c.signature, message = _c.message;
6415
- extensions = challengeResponse.options.extensions;
6416
- firstSalt = new Uint8Array((_e = (_d = extensions.prf) === null || _d === void 0 ? void 0 : _d.eval) === null || _e === void 0 ? void 0 : _e.first);
6417
- updatedOptions = __assign(__assign({}, challengeResponse.options), { extensions: __assign(__assign({}, extensions), { prf: {
6360
+ _c = _h.sent(), signature = _c.signature, message = _c.message;
6361
+ parsedOptions = this.preparePasskeyCreationOptions(challengeResponse.options);
6362
+ updatedOptions = __assign(__assign({}, challengeResponse.options), { extensions: __assign(__assign({}, parsedOptions.extensions), { prf: {
6418
6363
  eval: {
6419
- first: firstSalt,
6364
+ 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,
6420
6365
  },
6421
6366
  } }) });
6422
6367
  return [4 /*yield*/, this.authenticator.register({
6423
6368
  optionsJSON: updatedOptions,
6424
6369
  })];
6425
6370
  case 2:
6426
- passkeyCredential = _g.sent();
6427
- if (!((_f = passkeyCredential.clientExtensionResults.prf) === null || _f === void 0 ? void 0 : _f.enabled)) {
6371
+ passkeyCredential = _h.sent();
6372
+ if (!((_g = passkeyCredential.clientExtensionResults.prf) === null || _g === void 0 ? void 0 : _g.enabled)) {
6428
6373
  throw new Error('Device is not compatible with this feature. Try using a different authentication method.');
6429
6374
  }
6430
6375
  return [4 /*yield*/, this.handleCredentialsCreationFromPrfExtension(passkeyCredential)];
6431
6376
  case 3:
6432
- credentialsKeyPair = _g.sent();
6377
+ credentialsKeyPair = _h.sent();
6433
6378
  return [4 /*yield*/, this.request(AuthRoutes.signUp, {
6434
6379
  method: AuthRoutes.signUp.method,
6435
6380
  payload: {
@@ -6441,7 +6386,7 @@ var PasskeyService = /** @class */ (function () {
6441
6386
  },
6442
6387
  })];
6443
6388
  case 4:
6444
- singUpResponse = _g.sent();
6389
+ singUpResponse = _h.sent();
6445
6390
  if (!singUpResponse || singUpResponse.error) {
6446
6391
  throw new Error('Passkey authentication failed. Please try again.');
6447
6392
  }
@@ -6450,7 +6395,7 @@ var PasskeyService = /** @class */ (function () {
6450
6395
  encryptionKey: credentialsKeyPair.publicKey,
6451
6396
  })];
6452
6397
  case 5:
6453
- encryptedNewDevicePrivateKey = _g.sent();
6398
+ encryptedNewDevicePrivateKey = _h.sent();
6454
6399
  if (!encryptedNewDevicePrivateKey) {
6455
6400
  throw new Error('Failed to encrypt the device private key.');
6456
6401
  }
@@ -6463,10 +6408,10 @@ var PasskeyService = /** @class */ (function () {
6463
6408
  passkeyCredential: passkeyCredential,
6464
6409
  })];
6465
6410
  case 6:
6466
- _g.sent();
6411
+ _h.sent();
6467
6412
  return [2 /*return*/, __assign(__assign({}, singUpResponse), { prfValue: credentialsKeyPair.prfValue })];
6468
6413
  case 7:
6469
- error_3 = _g.sent();
6414
+ error_3 = _h.sent();
6470
6415
  throw this.authenticator.handlePasskeyError(error_3);
6471
6416
  case 8: return [2 /*return*/];
6472
6417
  }
@@ -6583,7 +6528,6 @@ var PasskeyService = /** @class */ (function () {
6583
6528
  case 0:
6584
6529
  _e.trys.push([0, 2, , 3]);
6585
6530
  extensions = passkeyCredential.clientExtensionResults;
6586
- logger.debug('extensions', extensions);
6587
6531
  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))) {
6588
6532
  throw new Error('Device is not compatible with this feature. Try using a different authentication method.');
6589
6533
  }
@@ -6695,7 +6639,7 @@ var AuthService = /** @class */ (function (_super) {
6695
6639
  * @description
6696
6640
  * It registers the client's device public key with Wallaby server and gets back a random message string.
6697
6641
  * The random string will be hashed and signed by the client's device private key and sent back to Wallaby for verification.
6698
- * @param { publicKey: string; privateKey: string } deviceAuthKeys the device key pair to register with wallaby.
6642
+ * @param { AsymmetricKeyPair } deviceAuthKeys the device key pair to register with wallaby.
6699
6643
  * @returns the messaged, the hash, and the signature using the passed private key.
6700
6644
  */
6701
6645
  AuthService.prototype.getSignature = function (deviceAuthKeys) {
@@ -6814,11 +6758,9 @@ var AuthService = /** @class */ (function (_super) {
6814
6758
  case AuthType.Password: return [3 /*break*/, 3];
6815
6759
  }
6816
6760
  return [3 /*break*/, 6];
6817
- case 1:
6818
- logger.log('SDK::AuthService::signIn::passkey');
6819
- return [4 /*yield*/, this.handleSignInWithPasskey({
6820
- input: input,
6821
- })];
6761
+ case 1: return [4 /*yield*/, this.handleSignInWithPasskey({
6762
+ input: input,
6763
+ })];
6822
6764
  case 2:
6823
6765
  authentication = _b.sent();
6824
6766
  if (!authentication) {
@@ -6947,7 +6889,6 @@ var AuthService = /** @class */ (function (_super) {
6947
6889
  return [4 /*yield*/, this.storageService.save(LocalStorageItems.ClientAuthPublicKey, devicePublicKey)];
6948
6890
  case 4:
6949
6891
  _c.sent();
6950
- logger.debug('SDK::AuthService::handleSignInWithPass::input', input);
6951
6892
  return [4 /*yield*/, this.getSignature(deviceKeyPair)];
6952
6893
  case 5:
6953
6894
  signatureMessage = _c.sent();
@@ -7169,7 +7110,7 @@ var AuthService = /** @class */ (function (_super) {
7169
7110
  * Signs up the user using the password encryption mechanism.
7170
7111
  * @param { SignatureMessageResponse } signatureMessage - signature message response from `this.getSignature`.
7171
7112
  * @param { AuthenticationRequest } input - The authentication request containing user details and encryption mechanism.
7172
- * @param { publicKey: string; privateKey: string } deviceAuthKeys - The device key pair to register with Wallaby.
7113
+ * @param { AsymmetricKeyPair } deviceAuthKeys - The device key pair to register with Wallaby.
7173
7114
  * @returns {Promise<AuthResponse>} - The authentication response containing user details and access token.
7174
7115
  * @throws Throws an error if the passkey creation fails.
7175
7116
  */
@@ -7184,7 +7125,6 @@ var AuthService = /** @class */ (function (_super) {
7184
7125
  if (!input.password) {
7185
7126
  throw new Error('Password is required.');
7186
7127
  }
7187
- logger.log('SDK::AuthService::handleSignUpWithPassword::deviceKeyPair', deviceKeyPair);
7188
7128
  return [4 /*yield*/, this.request(AuthRoutes.signUp, {
7189
7129
  method: AuthRoutes.signUp.method,
7190
7130
  payload: {
@@ -7216,7 +7156,6 @@ var AuthService = /** @class */ (function (_super) {
7216
7156
  })];
7217
7157
  case 2:
7218
7158
  encryptedDevicePrivKey = _b.sent();
7219
- logger.log('SDK::AuthService::handlePasskeyRegistration::deviceKeyPair', deviceKeyPair);
7220
7159
  if (encryptedDevicePrivKey) {
7221
7160
  this.storageService.saveInBulk([
7222
7161
  {
@@ -7251,6 +7190,42 @@ var AuthService = /** @class */ (function (_super) {
7251
7190
  });
7252
7191
  });
7253
7192
  };
7193
+ AuthService.prototype.getPasskeyCredentials = function () {
7194
+ return __awaiter(this, void 0, void 0, function () {
7195
+ var response, error_7;
7196
+ return __generator(this, function (_a) {
7197
+ switch (_a.label) {
7198
+ case 0:
7199
+ _a.trys.push([0, 2, , 3]);
7200
+ return [4 /*yield*/, this.request(AuthRoutes.getPasskeyCredentials, {
7201
+ method: AuthRoutes.getPasskeyCredentials.method,
7202
+ payload: {},
7203
+ })];
7204
+ case 1:
7205
+ response = _a.sent();
7206
+ if (!response)
7207
+ throw new Error('Error fetching passkey credentials.');
7208
+ if (response.error)
7209
+ throw new Error(response.error);
7210
+ if (!response.credentials.length)
7211
+ throw new Error('No passkey credentials found for this user.');
7212
+ return [2 /*return*/, response.credentials];
7213
+ case 2:
7214
+ error_7 = _a.sent();
7215
+ logger.error('SDK::AuthService::getPasskeyCredentials::error', error_7);
7216
+ // Handle both string errors and error objects
7217
+ if (typeof error_7 === 'string') {
7218
+ throw new Error(error_7);
7219
+ }
7220
+ if (error_7 && typeof error_7 === 'object' && 'message' in error_7) {
7221
+ throw new Error(error_7.message);
7222
+ }
7223
+ throw error_7;
7224
+ case 3: return [2 /*return*/];
7225
+ }
7226
+ });
7227
+ });
7228
+ };
7254
7229
  return AuthService;
7255
7230
  }(Base));
7256
7231
 
@@ -7277,10 +7252,6 @@ var WalletHandlersService = /** @class */ (function (_super) {
7277
7252
  })];
7278
7253
  case 1:
7279
7254
  _a = _g.sent(), signature = _a.signature, message = _a.message;
7280
- logger.info('SDK::handleImportWallet::signature', {
7281
- signature: signature,
7282
- message: message,
7283
- });
7284
7255
  if ((importWalletInput.returnWalletOption === ReturnWalletOption.ReturnOnlyEncryptedShares ||
7285
7256
  importWalletInput.returnWalletOption === ReturnWalletOption.ReturnBothEncryptedSharesAndSeed) &&
7286
7257
  !importWalletInput.keyShareOptions) {
@@ -7597,6 +7568,16 @@ var WalletHandlersService = /** @class */ (function (_super) {
7597
7568
  });
7598
7569
  });
7599
7570
  };
7571
+ /**
7572
+ *
7573
+ * @param encryptedKeyShares - Encrypted key shares that are encrypted with the wallabyAuthPublicKey.
7574
+ * @param walletId - The ID of the wallet for which the seed phrase is being constructed.
7575
+ * @param deviceAuthKeys - The device authentication key pair used to sign the request.
7576
+ * @description This function constructs the seed phrase from encrypted key shares.
7577
+ * It retrieves the seed phrase by sending a request to the Wallaby API with the encrypted key shares.
7578
+ * The shares should be encrypted with the wallabyAuthPublicKey before passing them into this function.
7579
+ * @returns The function returns the encrypted seed phrase wrapped with client device public key.
7580
+ */
7600
7581
  WalletHandlersService.prototype.handleConstructingSeedPhraseFromShares = function (_a) {
7601
7582
  return __awaiter(this, arguments, void 0, function (_b) {
7602
7583
  var _c, signature, message, retrieveSeedPhraseResponse, error_7;
@@ -7657,6 +7638,70 @@ var WalletService = /** @class */ (function (_super) {
7657
7638
  _this.userId = config.userId;
7658
7639
  return _this;
7659
7640
  }
7641
+ /**
7642
+ * @public
7643
+ * @returns {boolean} Returns true if the device has a seed phrase.
7644
+ */
7645
+ WalletService.prototype.hasSeedPhraseOnDevice = function () {
7646
+ return __awaiter(this, void 0, void 0, function () {
7647
+ return __generator(this, function (_a) {
7648
+ switch (_a.label) {
7649
+ case 0: return [4 /*yield*/, this.storageService.checkSeedPhraseExists()];
7650
+ case 1: return [2 /*return*/, _a.sent()];
7651
+ }
7652
+ });
7653
+ });
7654
+ };
7655
+ /**
7656
+ * @public
7657
+ * @returns {boolean} Returns true if the device has a primary key share.
7658
+ */
7659
+ WalletService.prototype.hasPrimaryKeyShareOnDevice = function () {
7660
+ return __awaiter(this, void 0, void 0, function () {
7661
+ return __generator(this, function (_a) {
7662
+ switch (_a.label) {
7663
+ case 0: return [4 /*yield*/, this.storageService.checkPrimaryKeyShareExists()];
7664
+ case 1: return [2 /*return*/, _a.sent()];
7665
+ }
7666
+ });
7667
+ });
7668
+ };
7669
+ /**
7670
+ * @public
7671
+ * @returns {boolean} Returns true if the device has a backup key share.
7672
+ */
7673
+ WalletService.prototype.hasBackupKeyShareOnDevice = 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.checkBackupKeyShareExists()];
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 wallet (either seed phrase or primary key share).
7686
+ */
7687
+ WalletService.prototype.hasWalletOnDevice = function () {
7688
+ return __awaiter(this, void 0, void 0, function () {
7689
+ var _a;
7690
+ return __generator(this, function (_b) {
7691
+ switch (_b.label) {
7692
+ case 0: return [4 /*yield*/, this.hasSeedPhraseOnDevice()];
7693
+ case 1:
7694
+ _a = (_b.sent());
7695
+ if (_a) return [3 /*break*/, 3];
7696
+ return [4 /*yield*/, this.hasPrimaryKeyShareOnDevice()];
7697
+ case 2:
7698
+ _a = (_b.sent());
7699
+ _b.label = 3;
7700
+ case 3: return [2 /*return*/, _a];
7701
+ }
7702
+ });
7703
+ });
7704
+ };
7660
7705
  /**
7661
7706
  *
7662
7707
  * @public
@@ -7970,7 +8015,6 @@ var WalletService = /** @class */ (function (_super) {
7970
8015
  throw new Error('Failed to decrypt device private key');
7971
8016
  }
7972
8017
  clientAuthPubKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
7973
- logger.info('SDK::WalletService::import::clientAuthPubKey', clientAuthPubKey);
7974
8018
  return [4 /*yield*/, this.handlers.handleImportWallet({
7975
8019
  publicKey: clientAuthPubKey,
7976
8020
  privateKey: decryptedDevicePrivateKey,
@@ -7989,12 +8033,14 @@ var WalletService = /** @class */ (function (_super) {
7989
8033
  };
7990
8034
  WalletService.prototype.recover = function (input) {
7991
8035
  return __awaiter(this, void 0, void 0, function () {
7992
- var deviceAuthKeyPair, credentialsKeyPair, encryptedSeedPhrase, recoverWithSeedPhraseResponse, encryptedShares, encryptedSeed, error_4;
7993
- var _a, _b;
7994
- return __generator(this, function (_c) {
7995
- switch (_c.label) {
8036
+ var wallabyPublicKey_1, deviceAuthKeyPair, credentialsKeyPair, recoverWithSeedPhraseResponse, encryptedSeedPhrase, encryptedShares, encryptedSeed, wallabyBoundRecoverySeedPhrase, error_4;
8037
+ var _this = this;
8038
+ var _a, _b, _c;
8039
+ return __generator(this, function (_d) {
8040
+ switch (_d.label) {
7996
8041
  case 0:
7997
- _c.trys.push([0, 15, , 16]);
8042
+ _d.trys.push([0, 22, , 23]);
8043
+ wallabyPublicKey_1 = input.authenticationOptions.user.wallabyAuthPubKey;
7998
8044
  deviceAuthKeyPair = createIdentity();
7999
8045
  return [4 /*yield*/, this.cipher.getCredentialsKeyPair({
8000
8046
  authType: this.deviceAuthType,
@@ -8003,35 +8049,36 @@ var WalletService = /** @class */ (function (_super) {
8003
8049
  prfValue: input.authenticationOptions.prfValue,
8004
8050
  })];
8005
8051
  case 1:
8006
- credentialsKeyPair = _c.sent();
8052
+ credentialsKeyPair = _d.sent();
8007
8053
  return [4 /*yield*/, this.authService.storeDeviceKeyPair({
8008
8054
  deviceAuthKeyPair: deviceAuthKeyPair,
8009
8055
  credentialsKeyPair: credentialsKeyPair,
8010
8056
  })];
8011
8057
  case 2:
8012
- _c.sent();
8058
+ _d.sent();
8059
+ recoverWithSeedPhraseResponse = void 0;
8013
8060
  if (!input.seedPhrase) return [3 /*break*/, 10];
8014
- return [4 /*yield*/, encryptWithPublicKey(input.wallabyAuthPubKey, input.seedPhrase)];
8061
+ return [4 /*yield*/, encryptWithPublicKey(wallabyPublicKey_1, input.seedPhrase)];
8015
8062
  case 3:
8016
- encryptedSeedPhrase = _c.sent();
8063
+ encryptedSeedPhrase = _d.sent();
8017
8064
  return [4 /*yield*/, this.handlers.handleRecoverFromSeedPhrase({
8018
8065
  encryptedSeedPhrase: encryptedSeedPhrase,
8019
8066
  deviceAuthKeys: { publicKey: deviceAuthKeyPair.publicKey, privateKey: deviceAuthKeyPair.privateKey },
8020
8067
  })];
8021
8068
  case 4:
8022
- recoverWithSeedPhraseResponse = _c.sent();
8023
- if (!recoverWithSeedPhraseResponse.encryptedSeed) return [3 /*break*/, 6];
8069
+ recoverWithSeedPhraseResponse = _d.sent();
8070
+ if (!(input.seedPhrase && input.returnWalletOption !== ReturnWalletOption.ReturnOnlyEncryptedShares)) return [3 /*break*/, 6];
8024
8071
  // will take care of encrypting and storing the seed phrase if needed.
8025
8072
  return [4 /*yield*/, this.handlers.handleSeedPhraseFromResponse({
8026
- encryptedSeed: recoverWithSeedPhraseResponse.encryptedSeed,
8073
+ encryptedSeed: encryptWithPublicKey(deviceAuthKeyPair.publicKey, input.seedPhrase), // usually this comes back from the API wrapped with the device pub.
8027
8074
  devicePrivateKey: deviceAuthKeyPair.privateKey,
8028
8075
  credentialsKeyPair: credentialsKeyPair,
8029
8076
  storeSeedPhrase: input.storeSeedPhrase,
8030
8077
  })];
8031
8078
  case 5:
8032
8079
  // will take care of encrypting and storing the seed phrase if needed.
8033
- _c.sent();
8034
- _c.label = 6;
8080
+ _d.sent();
8081
+ _d.label = 6;
8035
8082
  case 6:
8036
8083
  if (!((_a = recoverWithSeedPhraseResponse.shares) === null || _a === void 0 ? void 0 : _a.length)) return [3 /*break*/, 8];
8037
8084
  return [4 /*yield*/, this.handlers.handleKeySharesFromResponse({
@@ -8040,21 +8087,37 @@ var WalletService = /** @class */ (function (_super) {
8040
8087
  credentialsKeyPair: credentialsKeyPair,
8041
8088
  })];
8042
8089
  case 7:
8043
- _c.sent();
8044
- _c.label = 8;
8090
+ _d.sent();
8091
+ _d.label = 8;
8045
8092
  case 8: return [4 /*yield*/, this.authService.storeDeviceKeyPair({
8046
8093
  deviceAuthKeyPair: deviceAuthKeyPair,
8047
8094
  credentialsKeyPair: credentialsKeyPair,
8048
8095
  })];
8049
8096
  case 9:
8050
- _c.sent();
8097
+ _d.sent();
8051
8098
  return [2 /*return*/, recoverWithSeedPhraseResponse];
8052
8099
  case 10:
8053
- if (!input.decryptedShares) return [3 /*break*/, 13];
8054
- encryptedShares = (_b = input.decryptedShares) === null || _b === void 0 ? void 0 : _b.map(function (decryptedShare) {
8055
- return encryptWithPublicKey(input.wallabyAuthPubKey, decryptedShare);
8056
- });
8057
- if (!encryptedShares) {
8100
+ if (!input.decryptedShares) return [3 /*break*/, 20];
8101
+ 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 () {
8102
+ var encrypted;
8103
+ return __generator(this, function (_a) {
8104
+ switch (_a.label) {
8105
+ case 0: return [4 /*yield*/, this.cipher.encrypt({
8106
+ data: decryptedShare,
8107
+ encryptionKey: wallabyPublicKey_1,
8108
+ })];
8109
+ case 1:
8110
+ encrypted = _a.sent();
8111
+ if (!encrypted) {
8112
+ throw new Error('Failed to encrypt share');
8113
+ }
8114
+ return [2 /*return*/, encrypted];
8115
+ }
8116
+ });
8117
+ }); }))];
8118
+ case 11:
8119
+ encryptedShares = _d.sent();
8120
+ if (!encryptedShares.length) {
8058
8121
  throw new Error('Decrypted shares are required');
8059
8122
  }
8060
8123
  return [4 /*yield*/, this.handlers.handleConstructingSeedPhraseFromShares({
@@ -8062,24 +8125,57 @@ var WalletService = /** @class */ (function (_super) {
8062
8125
  deviceAuthKeys: deviceAuthKeyPair,
8063
8126
  walletId: input.walletId,
8064
8127
  })];
8065
- case 11:
8066
- encryptedSeed = _c.sent();
8128
+ case 12:
8129
+ encryptedSeed = _d.sent();
8130
+ return [4 /*yield*/, this.cipher.flipEncryptedData({
8131
+ cipherText: encryptedSeed,
8132
+ decryptionKey: deviceAuthKeyPair.privateKey,
8133
+ encryptionKey: wallabyPublicKey_1,
8134
+ })];
8135
+ case 13:
8136
+ wallabyBoundRecoverySeedPhrase = _d.sent();
8137
+ return [4 /*yield*/, this.handlers.handleRecoverFromSeedPhrase({
8138
+ encryptedSeedPhrase: wallabyBoundRecoverySeedPhrase,
8139
+ deviceAuthKeys: { publicKey: deviceAuthKeyPair.publicKey, privateKey: deviceAuthKeyPair.privateKey },
8140
+ })];
8141
+ case 14:
8142
+ recoverWithSeedPhraseResponse = _d.sent();
8143
+ if (!recoverWithSeedPhraseResponse.encryptedSeed) return [3 /*break*/, 16];
8144
+ // will take care of encrypting and storing the seed phrase if needed.
8067
8145
  return [4 /*yield*/, this.handlers.handleSeedPhraseFromResponse({
8068
- encryptedSeed: encryptedSeed,
8146
+ encryptedSeed: recoverWithSeedPhraseResponse.encryptedSeed,
8069
8147
  devicePrivateKey: deviceAuthKeyPair.privateKey,
8070
8148
  credentialsKeyPair: credentialsKeyPair,
8071
8149
  storeSeedPhrase: input.storeSeedPhrase,
8072
8150
  })];
8073
- case 12:
8074
- _c.sent();
8075
- return [3 /*break*/, 14];
8076
- case 13: throw new Error('Decrypted seed phrase or shares are required to recover the wallet.');
8077
- case 14: return [2 /*return*/, { standardSeedPhrase: input.seedPhrase }];
8078
8151
  case 15:
8079
- error_4 = _c.sent();
8152
+ // will take care of encrypting and storing the seed phrase if needed.
8153
+ _d.sent();
8154
+ _d.label = 16;
8155
+ case 16:
8156
+ if (!((_c = recoverWithSeedPhraseResponse.shares) === null || _c === void 0 ? void 0 : _c.length)) return [3 /*break*/, 18];
8157
+ return [4 /*yield*/, this.handlers.handleKeySharesFromResponse({
8158
+ keyShares: recoverWithSeedPhraseResponse.shares,
8159
+ devicePrivateKey: deviceAuthKeyPair.privateKey,
8160
+ credentialsKeyPair: credentialsKeyPair,
8161
+ })];
8162
+ case 17:
8163
+ _d.sent();
8164
+ _d.label = 18;
8165
+ case 18: return [4 /*yield*/, this.authService.storeDeviceKeyPair({
8166
+ deviceAuthKeyPair: deviceAuthKeyPair,
8167
+ credentialsKeyPair: credentialsKeyPair,
8168
+ })];
8169
+ case 19:
8170
+ _d.sent();
8171
+ return [2 /*return*/, recoverWithSeedPhraseResponse];
8172
+ case 20: throw new Error('Decrypted seed phrase or shares are required to recover the wallet.');
8173
+ case 21: return [3 /*break*/, 23];
8174
+ case 22:
8175
+ error_4 = _d.sent();
8080
8176
  logger.error('SDK::Wallet::recover::error', error_4);
8081
8177
  return [2 /*return*/, Promise.reject(error_4)];
8082
- case 16: return [2 /*return*/];
8178
+ case 23: return [2 /*return*/];
8083
8179
  }
8084
8180
  });
8085
8181
  });
@@ -8158,51 +8254,132 @@ var WalletService = /** @class */ (function (_super) {
8158
8254
  */
8159
8255
  WalletService.prototype.changePassword = function (_a) {
8160
8256
  return __awaiter(this, arguments, void 0, function (_b) {
8161
- var decryptedDevicePrivateKey, clientSalt, decryptedSeedPhrase, error_6;
8257
+ var encryptedDevicePrivateKeyString, encryptedSeedPhraseString, encryptedPrimaryShareString, encryptedBackupShareString, clientSalt, oldCredentialsKeyPair, newCredentialsKeyPair, reWrappedDevicePrivateKey, parsedSeed, reWrappedSeedPhrase, parsedPrimaryShare, reWrappedPrimaryShare, parsedBackupShare, reWrappedBackupShare, error_6;
8162
8258
  var oldPassword = _b.oldPassword, newPassword = _b.newPassword;
8163
8259
  return __generator(this, function (_c) {
8164
8260
  switch (_c.label) {
8165
8261
  case 0:
8166
- _c.trys.push([0, 6, , 7]);
8167
- return [4 /*yield*/, this.storageService.getDecryptedPrivateKey(oldPassword)];
8262
+ _c.trys.push([0, 19, , 20]);
8263
+ return [4 /*yield*/, this.storageService.fetch(LocalStorageItems.EncryptedDevicePrivateKey)];
8168
8264
  case 1:
8169
- decryptedDevicePrivateKey = _c.sent();
8170
- if (!decryptedDevicePrivateKey) {
8171
- throw new Error('Password is not valid, device private key could not be decrypted.');
8265
+ encryptedDevicePrivateKeyString = _c.sent();
8266
+ return [4 /*yield*/, this.storageService.fetch(LocalStorageItems.EncryptedStandardSeedPhrase)];
8267
+ case 2:
8268
+ encryptedSeedPhraseString = _c.sent();
8269
+ return [4 /*yield*/, this.storageService.fetch(LocalStorageItems.PrimaryDeviceKeyShare)];
8270
+ case 3:
8271
+ encryptedPrimaryShareString = _c.sent();
8272
+ return [4 /*yield*/, this.storageService.fetch(LocalStorageItems.BackupDeviceKeyShare)];
8273
+ case 4:
8274
+ encryptedBackupShareString = _c.sent();
8275
+ // Ensure at least the device private key is present. Other items are optional.
8276
+ if (!encryptedDevicePrivateKeyString) {
8277
+ throw new Error('Could not locate client keys on this device.');
8172
8278
  }
8173
8279
  return [4 /*yield*/, this.authService.getUserSalt()];
8174
- case 2:
8280
+ case 5:
8175
8281
  clientSalt = _c.sent();
8176
- return [4 /*yield*/, this.storageService.getDecryptedSeedPhrase({
8282
+ return [4 /*yield*/, this.cipher.getCredentialsKeyPair({
8283
+ authType: this.deviceAuthType,
8177
8284
  password: oldPassword,
8178
- seedPhraseType: SeedPhraseType.Standard,
8179
- getUserSalt: this.authService.getUserSalt,
8180
8285
  salt: clientSalt,
8181
8286
  })];
8182
- case 3:
8183
- decryptedSeedPhrase = _c.sent();
8184
- if (!decryptedSeedPhrase) {
8185
- throw new Error('Password is not valid, seed phrase could not be decrypted, please recover the wallet.');
8287
+ case 6:
8288
+ oldCredentialsKeyPair = _c.sent();
8289
+ if (!oldCredentialsKeyPair || !oldCredentialsKeyPair.privateKey) {
8290
+ throw new Error('Could not derive keys from old password. Please make sure the password is correct.');
8186
8291
  }
8187
- return [4 /*yield*/, this.storageService.setEncryptedPrivateKey(decryptedDevicePrivateKey, newPassword)];
8188
- case 4:
8189
- _c.sent();
8190
- return [4 /*yield*/, this.storageService.setEncryptedSeedPhrase({
8191
- decryptedSeedPhrase: decryptedSeedPhrase,
8192
- seedPhraseType: SeedPhraseType.Standard,
8292
+ return [4 /*yield*/, this.cipher.getCredentialsKeyPair({
8293
+ authType: this.deviceAuthType,
8193
8294
  password: newPassword,
8194
- deviceAuthPublicKey: publicKeyByPrivateKey(decryptedDevicePrivateKey),
8195
- getUserSalt: this.authService.getUserSalt,
8196
8295
  salt: clientSalt,
8197
8296
  })];
8198
- case 5:
8297
+ case 7:
8298
+ newCredentialsKeyPair = _c.sent();
8299
+ if (!newCredentialsKeyPair || !newCredentialsKeyPair.publicKey) {
8300
+ throw new Error('Could not derive keys for new password.');
8301
+ }
8302
+ return [4 /*yield*/, this.cipher.flipEncryptedData({
8303
+ cipherText: JSON.parse(encryptedDevicePrivateKeyString),
8304
+ decryptionKey: oldCredentialsKeyPair.privateKey,
8305
+ encryptionKey: newCredentialsKeyPair.publicKey, // Corrected to use publicKey for encryption
8306
+ })];
8307
+ case 8:
8308
+ reWrappedDevicePrivateKey = _c.sent();
8309
+ if (!reWrappedDevicePrivateKey) {
8310
+ throw new Error('Failed to rewrap device private key');
8311
+ }
8312
+ return [4 /*yield*/, this.storageService.save(LocalStorageItems.EncryptedDevicePrivateKey, JSON.stringify(reWrappedDevicePrivateKey))];
8313
+ case 9:
8199
8314
  _c.sent();
8200
- return [2 /*return*/, true];
8201
- case 6:
8315
+ if (!encryptedSeedPhraseString) return [3 /*break*/, 12];
8316
+ parsedSeed = safeJsonParse(encryptedSeedPhraseString);
8317
+ if (!parsedSeed) {
8318
+ throw new Error('Encrypted seed phrase could not be parsed');
8319
+ }
8320
+ return [4 /*yield*/, this.cipher.flipEncryptedData({
8321
+ cipherText: parsedSeed,
8322
+ decryptionKey: oldCredentialsKeyPair.privateKey,
8323
+ encryptionKey: newCredentialsKeyPair.publicKey,
8324
+ })];
8325
+ case 10:
8326
+ reWrappedSeedPhrase = _c.sent();
8327
+ if (!reWrappedSeedPhrase) {
8328
+ throw new Error('Failed to rewrap seed phrase');
8329
+ }
8330
+ return [4 /*yield*/, this.storageService.save(LocalStorageItems.EncryptedStandardSeedPhrase, JSON.stringify(reWrappedSeedPhrase))];
8331
+ case 11:
8332
+ _c.sent();
8333
+ _c.label = 12;
8334
+ case 12:
8335
+ if (!encryptedPrimaryShareString) return [3 /*break*/, 15];
8336
+ parsedPrimaryShare = safeJsonParse(encryptedPrimaryShareString);
8337
+ if (!parsedPrimaryShare) {
8338
+ throw new Error('Encrypted primary share could not be parsed');
8339
+ }
8340
+ return [4 /*yield*/, this.cipher.flipEncryptedData({
8341
+ cipherText: parsedPrimaryShare,
8342
+ decryptionKey: oldCredentialsKeyPair.privateKey,
8343
+ encryptionKey: newCredentialsKeyPair.publicKey,
8344
+ })];
8345
+ case 13:
8346
+ reWrappedPrimaryShare = _c.sent();
8347
+ if (!reWrappedPrimaryShare) {
8348
+ throw new Error('Failed to rewrap primary share');
8349
+ }
8350
+ return [4 /*yield*/, this.storageService.save(LocalStorageItems.PrimaryDeviceKeyShare, JSON.stringify(reWrappedPrimaryShare))];
8351
+ case 14:
8352
+ _c.sent();
8353
+ _c.label = 15;
8354
+ case 15:
8355
+ if (!encryptedBackupShareString) return [3 /*break*/, 18];
8356
+ parsedBackupShare = safeJsonParse(encryptedBackupShareString);
8357
+ if (!parsedBackupShare) {
8358
+ throw new Error('Encrypted backup share could not be parsed');
8359
+ }
8360
+ return [4 /*yield*/, this.cipher.flipEncryptedData({
8361
+ cipherText: parsedBackupShare,
8362
+ decryptionKey: oldCredentialsKeyPair.privateKey,
8363
+ encryptionKey: newCredentialsKeyPair.publicKey,
8364
+ })];
8365
+ case 16:
8366
+ reWrappedBackupShare = _c.sent();
8367
+ if (!reWrappedBackupShare) {
8368
+ throw new Error('Failed to rewrap backup share');
8369
+ }
8370
+ return [4 /*yield*/, this.storageService.save(LocalStorageItems.BackupDeviceKeyShare, JSON.stringify(reWrappedBackupShare))];
8371
+ case 17:
8372
+ _c.sent();
8373
+ _c.label = 18;
8374
+ case 18: return [2 /*return*/, true];
8375
+ case 19:
8202
8376
  error_6 = _c.sent();
8203
8377
  logger.error('SDK::Wallet::changePassword::error', error_6);
8204
- return [2 /*return*/, Promise.reject(false)];
8205
- case 7: return [2 /*return*/];
8378
+ if (error_6 instanceof Error) {
8379
+ return [2 /*return*/, Promise.reject(error_6)];
8380
+ }
8381
+ return [2 /*return*/, Promise.reject(new Error(String(error_6)))];
8382
+ case 20: return [2 /*return*/];
8206
8383
  }
8207
8384
  });
8208
8385
  });
@@ -8286,7 +8463,6 @@ var WalletService = /** @class */ (function (_super) {
8286
8463
  throw new Error('Failed to decrypt device private key');
8287
8464
  }
8288
8465
  clientAuthPubKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
8289
- logger.info('SDK::Wallet::getAlgorandSeedPhrase::clientAuthPubKey', clientAuthPubKey);
8290
8466
  reference = v4();
8291
8467
  return [4 /*yield*/, this.authService.getSignature({
8292
8468
  publicKey: clientAuthPubKey,
@@ -8294,7 +8470,6 @@ var WalletService = /** @class */ (function (_super) {
8294
8470
  })];
8295
8471
  case 9:
8296
8472
  signatureMessage = _b.sent();
8297
- logger.info('SDK::Wallet::getAlgorandSeedPhrase::signatureMessage', signatureMessage);
8298
8473
  message = signatureMessage.message, signature = signatureMessage.signature;
8299
8474
  return [4 /*yield*/, this.request(WalletRoutes.convertMnemonicSeedPhrase, {
8300
8475
  method: WalletRoutes.convertMnemonicSeedPhrase.method,
@@ -8503,9 +8678,283 @@ var WalletService = /** @class */ (function (_super) {
8503
8678
  });
8504
8679
  });
8505
8680
  };
8506
- return WalletService;
8507
- }(Base));
8508
-
8681
+ WalletService.prototype.generateWalletAddresses = function (input) {
8682
+ return __awaiter(this, void 0, void 0, function () {
8683
+ var walletId, storedSeedPhrase, primaryKeyShare, devicePrivateKey, transportSeed, transportKeyShare, parsedDevicePrivateKey, parsedStoredSeedPhrase, parsedPrimaryKeyShare, derivedCredentialsKeyPair, decryptedDevicePrivateKey, devicePublicKey, _a, signature, message, response, error_9;
8684
+ return __generator(this, function (_b) {
8685
+ switch (_b.label) {
8686
+ case 0:
8687
+ walletId = input.walletId;
8688
+ if (!walletId) {
8689
+ throw new Error('Missing required parameters');
8690
+ }
8691
+ _b.label = 1;
8692
+ case 1:
8693
+ _b.trys.push([1, 14, , 15]);
8694
+ return [4 /*yield*/, this.storageService.fetch(LocalStorageItems.EncryptedStandardSeedPhrase)];
8695
+ case 2:
8696
+ storedSeedPhrase = _b.sent();
8697
+ return [4 /*yield*/, this.storageService.fetch(LocalStorageItems.PrimaryDeviceKeyShare)];
8698
+ case 3:
8699
+ primaryKeyShare = _b.sent();
8700
+ return [4 /*yield*/, this.storageService.fetch(LocalStorageItems.EncryptedDevicePrivateKey)];
8701
+ case 4:
8702
+ devicePrivateKey = _b.sent();
8703
+ transportSeed = undefined;
8704
+ transportKeyShare = undefined;
8705
+ if (!devicePrivateKey) {
8706
+ throw new Error('Missing device private key on this device, please recover your wallet first.');
8707
+ }
8708
+ parsedDevicePrivateKey = safeJsonParse(devicePrivateKey);
8709
+ if (!parsedDevicePrivateKey) {
8710
+ throw new Error('Failed to parse stored seed or primary key share');
8711
+ }
8712
+ if (!storedSeedPhrase) return [3 /*break*/, 6];
8713
+ parsedStoredSeedPhrase = safeJsonParse(storedSeedPhrase);
8714
+ if (!parsedStoredSeedPhrase) {
8715
+ throw new Error('Failed to parse stored seed phrase');
8716
+ }
8717
+ return [4 /*yield*/, this.cipher.prepareStoredDataForTransport({
8718
+ storedEncryptedData: parsedStoredSeedPhrase,
8719
+ encryptedDevicePrivateKey: parsedDevicePrivateKey,
8720
+ wallabyPublicKey: input.authenticationOptions.user.wallabyAuthPubKey,
8721
+ options: {
8722
+ authType: this.deviceAuthType,
8723
+ password: input.authenticationOptions.password,
8724
+ salt: input.authenticationOptions.clientSalt,
8725
+ prfValue: input.authenticationOptions.prfValue,
8726
+ },
8727
+ })];
8728
+ case 5:
8729
+ transportSeed = _b.sent();
8730
+ return [3 /*break*/, 9];
8731
+ case 6:
8732
+ if (!primaryKeyShare) return [3 /*break*/, 8];
8733
+ parsedPrimaryKeyShare = safeJsonParse(primaryKeyShare);
8734
+ if (!parsedPrimaryKeyShare) {
8735
+ throw new Error('Failed to parse primary key share');
8736
+ }
8737
+ return [4 /*yield*/, this.cipher.prepareStoredDataForTransport({
8738
+ storedEncryptedData: parsedPrimaryKeyShare,
8739
+ encryptedDevicePrivateKey: parsedDevicePrivateKey,
8740
+ wallabyPublicKey: input.authenticationOptions.user.wallabyAuthPubKey,
8741
+ options: {
8742
+ authType: this.deviceAuthType,
8743
+ password: input.authenticationOptions.password,
8744
+ salt: input.authenticationOptions.clientSalt,
8745
+ prfValue: input.authenticationOptions.prfValue,
8746
+ },
8747
+ })];
8748
+ case 7:
8749
+ transportKeyShare = _b.sent();
8750
+ return [3 /*break*/, 9];
8751
+ case 8: throw new Error('Missing stored seed phrase or primary key share on this device, please recover your wallet first.');
8752
+ case 9: return [4 /*yield*/, this.cipher.getCredentialsKeyPair({
8753
+ authType: this.deviceAuthType,
8754
+ password: input.authenticationOptions.password,
8755
+ salt: input.authenticationOptions.clientSalt,
8756
+ prfValue: input.authenticationOptions.prfValue,
8757
+ })];
8758
+ case 10:
8759
+ derivedCredentialsKeyPair = _b.sent();
8760
+ return [4 /*yield*/, this.cipher.decrypt({
8761
+ cipherText: parsedDevicePrivateKey,
8762
+ decryptionKey: derivedCredentialsKeyPair.privateKey,
8763
+ })];
8764
+ case 11:
8765
+ decryptedDevicePrivateKey = _b.sent();
8766
+ devicePublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
8767
+ return [4 /*yield*/, this.authService.getSignature({
8768
+ privateKey: decryptedDevicePrivateKey,
8769
+ publicKey: devicePublicKey,
8770
+ })];
8771
+ case 12:
8772
+ _a = _b.sent(), signature = _a.signature, message = _a.message;
8773
+ return [4 /*yield*/, this.request(WalletRoutes.generateWalletAddresses, {
8774
+ method: WalletRoutes.generateWalletAddresses.method,
8775
+ payload: {
8776
+ walletId: walletId,
8777
+ signature: signature,
8778
+ message: message,
8779
+ clientAuthPubKey: devicePublicKey,
8780
+ encryptedSeed: transportSeed !== null && transportSeed !== void 0 ? transportSeed : undefined,
8781
+ encryptedShares: transportKeyShare ? [transportKeyShare] : undefined,
8782
+ },
8783
+ })];
8784
+ case 13:
8785
+ response = _b.sent();
8786
+ if (!response || response.errors) {
8787
+ throw new Error(response.errors);
8788
+ }
8789
+ return [2 /*return*/, response];
8790
+ case 14:
8791
+ error_9 = _b.sent();
8792
+ logger.error('SDK::Wallet::generateWalletAddresses::error', error_9);
8793
+ return [2 /*return*/, Promise.reject(error_9)];
8794
+ case 15: return [2 /*return*/];
8795
+ }
8796
+ });
8797
+ });
8798
+ };
8799
+ /**
8800
+ * Detects and migrates legacy/v1 storage items to v2 format.
8801
+ * This function should be called in methods that use password as input when v2 items are missing.
8802
+ * It will look for legacy storage items first, then v1 if legacy not found,
8803
+ * decrypt them using appropriate decryption methods, and call wallet.recover() to create new v2 keys.
8804
+ */
8805
+ WalletService.prototype.handleUpdateToV2 = function (_a) {
8806
+ return __awaiter(this, arguments, void 0, function (_b) {
8807
+ var v2EncryptedDevicePrivateKey, v2EncryptedSeed, v2EncryptedPrimaryDeviceShare, clientSalt_1, legacySeedPhrase_1, legacyPrivateKey, legacyEncryptedSeed, legacyEncryptedPrivateKey, decryptedPrivateKey, decryptedOnceSeed, parsedDecryptedSeed, v1EncryptedSeed, v1EncryptedPrivateKey, error_10, error_11;
8808
+ var _this = this;
8809
+ var password = _b.password, walletId = _b.walletId;
8810
+ return __generator(this, function (_c) {
8811
+ switch (_c.label) {
8812
+ case 0:
8813
+ _c.trys.push([0, 19, , 20]);
8814
+ logger.info('SDK::WalletService::handleUpdateToV2::starting migration check');
8815
+ return [4 /*yield*/, this.storageService.fetch(LocalStorageItems.EncryptedDevicePrivateKey)];
8816
+ case 1:
8817
+ v2EncryptedDevicePrivateKey = _c.sent();
8818
+ return [4 /*yield*/, this.storageService.fetch(LocalStorageItems.EncryptedStandardSeedPhrase)];
8819
+ case 2:
8820
+ v2EncryptedSeed = _c.sent();
8821
+ return [4 /*yield*/, this.storageService.fetch(LocalStorageItems.PrimaryDeviceKeyShare)];
8822
+ case 3:
8823
+ v2EncryptedPrimaryDeviceShare = _c.sent();
8824
+ if (v2EncryptedDevicePrivateKey && v2EncryptedSeed && v2EncryptedPrimaryDeviceShare) {
8825
+ logger.info('SDK::WalletService::handleUpdateToV2::V2 items already exist, no migration needed');
8826
+ // we don't need to throw any errors, just continue with rest of flow.
8827
+ return [2 /*return*/];
8828
+ }
8829
+ if (!password) {
8830
+ throw new Error('Password is required for migration to v2 storage format');
8831
+ }
8832
+ return [4 /*yield*/, this.authService.getUserSalt()];
8833
+ case 4:
8834
+ clientSalt_1 = _c.sent();
8835
+ legacyPrivateKey = void 0;
8836
+ return [4 /*yield*/, this.storageService.getFromDeviceStorage("".concat(LegacyKeyNames.EncryptedSeed, "_").concat(this.userId))];
8837
+ case 5:
8838
+ legacyEncryptedSeed = _c.sent();
8839
+ return [4 /*yield*/, this.storageService.getFromDeviceStorage("".concat(LegacyKeyNames.EncryptedPrivateKey, "_").concat(this.userId))];
8840
+ case 6:
8841
+ legacyEncryptedPrivateKey = _c.sent();
8842
+ if (!(legacyEncryptedSeed && legacyEncryptedPrivateKey)) return [3 /*break*/, 7];
8843
+ logger.info('SDK::WalletService::handleUpdateToV2::Found legacy storage items, attempting migration');
8844
+ try {
8845
+ decryptedPrivateKey = AES.decrypt(legacyEncryptedPrivateKey, "".concat(clientSalt_1).concat(password));
8846
+ decryptedOnceSeed = AES.decrypt(legacyEncryptedSeed, "".concat(clientSalt_1).concat(password));
8847
+ parsedDecryptedSeed = safeJsonParse(decryptedOnceSeed.toString(enc.Utf8));
8848
+ if (!parsedDecryptedSeed) {
8849
+ throw new Error('Failed to parse legacy decrypted data');
8850
+ }
8851
+ legacyPrivateKey = decryptedPrivateKey.toString(enc.Utf8);
8852
+ legacySeedPhrase_1 = decryptWithPrivateKey(legacyPrivateKey, parsedDecryptedSeed);
8853
+ if (!legacySeedPhrase_1 || !legacyPrivateKey) {
8854
+ throw new Error('Failed to decrypt legacy items with provided password');
8855
+ }
8856
+ logger.info('SDK::WalletService::handleUpdateToV2::Successfully decrypted legacy items');
8857
+ }
8858
+ catch (error) {
8859
+ logger.error('SDK::WalletService::handleUpdateToV2::Failed to decrypt legacy items', error);
8860
+ throw new Error('Could not decrypt legacy storage items. Please verify your password.');
8861
+ }
8862
+ return [3 /*break*/, 16];
8863
+ case 7: return [4 /*yield*/, this.storageService.getEncryptedSeedPhrase(SeedPhraseType.Standard)];
8864
+ case 8:
8865
+ v1EncryptedSeed = _c.sent();
8866
+ return [4 /*yield*/, this.storageService.getEncryptedPrivateKey()];
8867
+ case 9:
8868
+ v1EncryptedPrivateKey = _c.sent();
8869
+ if (!(v1EncryptedSeed && v1EncryptedPrivateKey)) return [3 /*break*/, 15];
8870
+ logger.info('SDK::WalletService::handleUpdateToV2::Found V1 storage items, attempting migration');
8871
+ _c.label = 10;
8872
+ case 10:
8873
+ _c.trys.push([10, 13, , 14]);
8874
+ return [4 /*yield*/, this.storageService.getDecryptedSeedPhrase({
8875
+ password: password,
8876
+ seedPhraseType: SeedPhraseType.Standard,
8877
+ getUserSalt: function () { return __awaiter(_this, void 0, void 0, function () { var _a; return __generator(this, function (_b) {
8878
+ switch (_b.label) {
8879
+ case 0:
8880
+ _a = clientSalt_1;
8881
+ if (_a) return [3 /*break*/, 2];
8882
+ return [4 /*yield*/, this.authService.getUserSalt()];
8883
+ case 1:
8884
+ _a = (_b.sent());
8885
+ _b.label = 2;
8886
+ case 2: return [2 /*return*/, _a];
8887
+ }
8888
+ }); }); },
8889
+ })];
8890
+ case 11:
8891
+ // Decrypt V1 items using storage service method (handles double encryption)
8892
+ legacySeedPhrase_1 = _c.sent();
8893
+ return [4 /*yield*/, this.storageService.getDecryptedPrivateKey(password)];
8894
+ case 12:
8895
+ // For V1 format, private key is encrypted with just the password (not salt+password like legacy)
8896
+ legacyPrivateKey = _c.sent();
8897
+ if (!legacySeedPhrase_1 || !legacyPrivateKey) {
8898
+ throw new Error('Failed to decrypt V1 items with provided password');
8899
+ }
8900
+ logger.info('SDK::WalletService::handleUpdateToV2::Successfully decrypted V1 items');
8901
+ return [3 /*break*/, 14];
8902
+ case 13:
8903
+ error_10 = _c.sent();
8904
+ logger.error('SDK::WalletService::handleUpdateToV2::Failed to decrypt V1 items', error_10);
8905
+ throw new Error('Could not decrypt V1 storage items. Please verify your password.');
8906
+ case 14: return [3 /*break*/, 16];
8907
+ case 15:
8908
+ logger.info('SDK::WalletService::handleUpdateToV2::No legacy or V1 items found to migrate');
8909
+ throw new Error('No legacy or V1 storage items found. Please recover your wallet using the seed phrase.');
8910
+ case 16:
8911
+ if (!legacySeedPhrase_1) return [3 /*break*/, 18];
8912
+ logger.info('SDK::WalletService::handleUpdateToV2::Initiating wallet recovery for V2 migration');
8913
+ logger.info('SDK::WalletService::handleUpdateToV2::Migration data prepared');
8914
+ logger.info('SDK::WalletService::handleUpdateToV2::Seed phrase available:', !!legacySeedPhrase_1);
8915
+ return [4 /*yield*/, this.authService.signIn({ password: password }).then(function (authResponse) { return __awaiter(_this, void 0, void 0, function () {
8916
+ return __generator(this, function (_a) {
8917
+ switch (_a.label) {
8918
+ case 0: return [4 /*yield*/, this.recover({
8919
+ authenticationOptions: __assign(__assign({}, authResponse), { password: password }),
8920
+ walletId: walletId,
8921
+ seedPhrase: legacySeedPhrase_1,
8922
+ storeSeedPhrase: true,
8923
+ returnWalletOption: ReturnWalletOption.ReturnOnlyEncryptedSeedPhrase,
8924
+ })];
8925
+ case 1:
8926
+ _a.sent();
8927
+ logger.info('SDK::WalletService::handleUpdateToV2::Migration completed successfully');
8928
+ return [2 /*return*/];
8929
+ }
8930
+ });
8931
+ }); })];
8932
+ case 17: return [2 /*return*/, _c.sent()];
8933
+ case 18: return [3 /*break*/, 20];
8934
+ case 19:
8935
+ error_11 = _c.sent();
8936
+ logger.error('SDK::WalletService::handleUpdateToV2::Migration failed', error_11);
8937
+ throw error_11;
8938
+ case 20: return [2 /*return*/];
8939
+ }
8940
+ });
8941
+ });
8942
+ };
8943
+ WalletService.prototype.clearDevice = function () {
8944
+ return __awaiter(this, void 0, void 0, function () {
8945
+ return __generator(this, function (_a) {
8946
+ switch (_a.label) {
8947
+ case 0: return [4 /*yield*/, this.storageService.clearLocalStorage()];
8948
+ case 1:
8949
+ _a.sent();
8950
+ return [2 /*return*/];
8951
+ }
8952
+ });
8953
+ });
8954
+ };
8955
+ return WalletService;
8956
+ }(Base));
8957
+
8509
8958
  /**
8510
8959
  * Sanitizes a Sui object ID by removing any part of the string after '::'.
8511
8960
  *
@@ -8530,8 +8979,35 @@ var WalletDataService = /** @class */ (function (_super) {
8530
8979
  function WalletDataService(config) {
8531
8980
  var _this = _super.call(this, config) || this;
8532
8981
  _this.userId = config.userId;
8982
+ _this.walletService = new WalletService(config);
8533
8983
  return _this;
8534
8984
  }
8985
+ /**
8986
+ * @description Validates the wallet address info for a given blockchain.
8987
+ * @param { WalletAddressInfo } walletAddressInfo The wallet address info object containing addresses for different blockchains.
8988
+ * @param { BlockchainName } blockchainName The name of the blockchain to validate against.
8989
+ * @returns { boolean } Returns true if the wallet address info is valid for the given blockchain, otherwise throws an error.
8990
+ */
8991
+ WalletDataService.prototype.validateWalletAddressInfo = function (walletAddressInfo, blockchainName) {
8992
+ switch (blockchainName) {
8993
+ case BlockchainName.Avalanche:
8994
+ case BlockchainName.Ethereum:
8995
+ case BlockchainName.Bsc:
8996
+ case BlockchainName.Base:
8997
+ case BlockchainName.Polygon:
8998
+ return !!walletAddressInfo.evmAddress && isEvmAddress(walletAddressInfo.evmAddress);
8999
+ case BlockchainName.Bitcoin:
9000
+ return !!walletAddressInfo.btcAddress && isBtcAddress(walletAddressInfo.btcAddress);
9001
+ case BlockchainName.Algorand:
9002
+ return !!walletAddressInfo.algoAddress && isAlgoAddress(walletAddressInfo.algoAddress);
9003
+ case BlockchainName.Sui:
9004
+ return !!walletAddressInfo.suiAddress && isSUIAddress(walletAddressInfo.suiAddress);
9005
+ case BlockchainName.Injective:
9006
+ return !!walletAddressInfo.injAddress && isInjectiveAddress(walletAddressInfo.injAddress);
9007
+ default:
9008
+ throw new Error("Unsupported blockchain: ".concat(blockchainName));
9009
+ }
9010
+ };
8535
9011
  /**
8536
9012
  *
8537
9013
  * @public
@@ -8564,7 +9040,7 @@ var WalletDataService = /** @class */ (function (_super) {
8564
9040
  return [2 /*return*/, response];
8565
9041
  case 2:
8566
9042
  error_1 = _c.sent();
8567
- logger.error('SDK::Wallet::getTokenBalance::error', error_1);
9043
+ logger.error('SDK::WalletDataService::getTokenBalance::error', error_1);
8568
9044
  return [2 /*return*/, Promise.reject(error_1)];
8569
9045
  case 3: return [2 /*return*/];
8570
9046
  }
@@ -8603,7 +9079,7 @@ var WalletDataService = /** @class */ (function (_super) {
8603
9079
  return [2 /*return*/, response];
8604
9080
  case 2:
8605
9081
  error_2 = _a.sent();
8606
- logger.error('SDK::Wallet::getTokenBalance::error', error_2);
9082
+ logger.error('SDK::WalletDataService::getTokenBalance::error', error_2);
8607
9083
  return [2 /*return*/, Promise.reject(error_2)];
8608
9084
  case 3: return [2 /*return*/];
8609
9085
  }
@@ -8639,7 +9115,7 @@ var WalletDataService = /** @class */ (function (_super) {
8639
9115
  return [2 /*return*/, response];
8640
9116
  case 2:
8641
9117
  error_3 = _c.sent();
8642
- logger.error('SDK::Wallet::getTokenBalance::error', error_3);
9118
+ logger.error('SDK::WalletDataService::getTokenBalance::error', error_3);
8643
9119
  return [2 /*return*/, Promise.reject(error_3)];
8644
9120
  case 3: return [2 /*return*/];
8645
9121
  }
@@ -8661,7 +9137,6 @@ var WalletDataService = /** @class */ (function (_super) {
8661
9137
  switch (_c.label) {
8662
9138
  case 0:
8663
9139
  _c.trys.push([0, 2, , 3]);
8664
- console.log('SDK::Wallet::getUserAssets::userId', userId);
8665
9140
  if (!userId)
8666
9141
  throw new Error('Missing required parameters');
8667
9142
  return [4 /*yield*/, this.request(WalletRoutes.getUserAssets, {
@@ -8679,7 +9154,7 @@ var WalletDataService = /** @class */ (function (_super) {
8679
9154
  return [2 /*return*/, response];
8680
9155
  case 2:
8681
9156
  error_4 = _c.sent();
8682
- logger.error('SDK::Wallet::getUserAssets::error', error_4);
9157
+ logger.error('SDK::WalletDataService::getUserAssets::error', error_4);
8683
9158
  return [2 /*return*/, Promise.reject(error_4)];
8684
9159
  case 3: return [2 /*return*/];
8685
9160
  }
@@ -8715,7 +9190,7 @@ var WalletDataService = /** @class */ (function (_super) {
8715
9190
  return [2 /*return*/, response];
8716
9191
  case 2:
8717
9192
  error_5 = _c.sent();
8718
- logger.error('SDK::Wallet::getUserWallets::error', error_5);
9193
+ logger.error('SDK::WalletDataService::getUserWallets::error', error_5);
8719
9194
  return [2 /*return*/, Promise.reject(error_5)];
8720
9195
  case 3: return [2 /*return*/];
8721
9196
  }
@@ -8752,7 +9227,7 @@ var WalletDataService = /** @class */ (function (_super) {
8752
9227
  return [2 /*return*/, response];
8753
9228
  case 2:
8754
9229
  error_6 = _c.sent();
8755
- logger.error('SDK::Wallet::getWalletAssets::error', error_6);
9230
+ logger.error('SDK::WalletDataService::getWalletAssets::error', error_6);
8756
9231
  return [2 /*return*/, Promise.reject(error_6)];
8757
9232
  case 3: return [2 /*return*/];
8758
9233
  }
@@ -8805,19 +9280,62 @@ var WalletDataService = /** @class */ (function (_super) {
8805
9280
  })];
8806
9281
  case 1:
8807
9282
  response = _c.sent();
8808
- if (!response || response.errors) {
8809
- throw new Error(response.errors);
9283
+ if (!response || response.error) {
9284
+ throw new Error(response === null || response === void 0 ? void 0 : response.error);
8810
9285
  }
8811
9286
  return [2 /*return*/, response];
8812
9287
  case 2:
8813
9288
  error_7 = _c.sent();
8814
- logger.error('SDK::Wallet::addTokenToWallet::error', error_7);
8815
- return [2 /*return*/, Promise.reject(error_7)];
9289
+ logger.error('SDK::WalletDataService::addTokenToWallet::error', error_7);
9290
+ throw error_7;
8816
9291
  case 3: return [2 /*return*/];
8817
9292
  }
8818
9293
  });
8819
9294
  });
8820
9295
  };
9296
+ WalletDataService.prototype.addNewChainAndTokenToWallet = function (input) {
9297
+ return __awaiter(this, void 0, void 0, function () {
9298
+ var authenticationOptions, walletId, userId, assetConfigId, blockchainName, addressInfo, addressInfoIsPresentForBlockchain, response, error_8;
9299
+ return __generator(this, function (_a) {
9300
+ switch (_a.label) {
9301
+ case 0:
9302
+ authenticationOptions = input.authenticationOptions, walletId = input.walletId, userId = input.userId, assetConfigId = input.assetConfigId, blockchainName = input.blockchainName;
9303
+ if (!authenticationOptions || !walletId || !userId || !assetConfigId || !blockchainName) {
9304
+ throw new Error('Missing required parameters');
9305
+ }
9306
+ _a.label = 1;
9307
+ case 1:
9308
+ _a.trys.push([1, 6, , 7]);
9309
+ return [4 /*yield*/, this.walletService.generateWalletAddresses({
9310
+ walletId: input.walletId,
9311
+ authenticationOptions: input.authenticationOptions,
9312
+ })];
9313
+ case 2:
9314
+ addressInfo = _a.sent();
9315
+ addressInfoIsPresentForBlockchain = this.validateWalletAddressInfo(addressInfo.walletAddressInfo, blockchainName);
9316
+ if (!addressInfoIsPresentForBlockchain) return [3 /*break*/, 4];
9317
+ return [4 /*yield*/, this.addTokenToWallet({
9318
+ assetConfigId: assetConfigId,
9319
+ walletId: walletId,
9320
+ userId: userId,
9321
+ })];
9322
+ case 3:
9323
+ response = _a.sent();
9324
+ if (!response || response.error) {
9325
+ throw new Error(response === null || response === void 0 ? void 0 : response.error);
9326
+ }
9327
+ return [2 /*return*/, response];
9328
+ case 4: throw new Error("Wallet address is not present for blockchain: ".concat(blockchainName));
9329
+ case 5: return [3 /*break*/, 7];
9330
+ case 6:
9331
+ error_8 = _a.sent();
9332
+ logger.error('SDK::WalletDataService::addNewChainAndTokenToWallet::error', error_8);
9333
+ throw error_8;
9334
+ case 7: return [2 /*return*/];
9335
+ }
9336
+ });
9337
+ });
9338
+ };
8821
9339
  /**
8822
9340
  * Updates a wallet asset.
8823
9341
  *
@@ -8833,7 +9351,7 @@ var WalletDataService = /** @class */ (function (_super) {
8833
9351
  */
8834
9352
  WalletDataService.prototype.updateAsset = function (_a) {
8835
9353
  return __awaiter(this, void 0, void 0, function () {
8836
- var response, error_8;
9354
+ var response, error_9;
8837
9355
  var assetConfigId = _a.assetConfigId, walletId = _a.walletId, assetConfig = __rest(_a, ["assetConfigId", "walletId"]);
8838
9356
  return __generator(this, function (_b) {
8839
9357
  switch (_b.label) {
@@ -8853,9 +9371,9 @@ var WalletDataService = /** @class */ (function (_super) {
8853
9371
  }
8854
9372
  return [2 /*return*/, response];
8855
9373
  case 2:
8856
- error_8 = _b.sent();
8857
- logger.error('SDK::Wallet::updateAsset::error', error_8);
8858
- return [2 /*return*/, Promise.reject(error_8)];
9374
+ error_9 = _b.sent();
9375
+ logger.error('SDK::WalletDataService::updateAsset::error', error_9);
9376
+ return [2 /*return*/, Promise.reject(error_9)];
8859
9377
  case 3: return [2 /*return*/];
8860
9378
  }
8861
9379
  });
@@ -8906,6 +9424,7 @@ var Utils = /** @class */ (function (_super) {
8906
9424
  }
8907
9425
  };
8908
9426
  _this.auth = new AuthService(config);
9427
+ _this.cipher = new Cipher();
8909
9428
  return _this;
8910
9429
  }
8911
9430
  /**
@@ -8992,27 +9511,49 @@ var Utils = /** @class */ (function (_super) {
8992
9511
  };
8993
9512
  Utils.prototype.validatePassword = function (_a) {
8994
9513
  return __awaiter(this, arguments, void 0, function (_b) {
8995
- var privateKey, encryptedSeedPhrase, decryptedPrivateKey;
8996
- var _c;
9514
+ var privateKey, encryptedSeedPhrase, salt, credentialsKeyPair, decryptedPrivateKey, error_2;
8997
9515
  var password = _b.password;
8998
- return __generator(this, function (_d) {
8999
- switch (_d.label) {
9516
+ return __generator(this, function (_c) {
9517
+ switch (_c.label) {
9000
9518
  case 0: return [4 /*yield*/, this.storageService.fetch(LocalStorageItems.EncryptedDevicePrivateKey)];
9001
9519
  case 1:
9002
- privateKey = _d.sent();
9520
+ privateKey = _c.sent();
9003
9521
  return [4 /*yield*/, this.storageService.fetch(LocalStorageItems.EncryptedStandardSeedPhrase)];
9004
9522
  case 2:
9005
- encryptedSeedPhrase = _d.sent();
9523
+ encryptedSeedPhrase = _c.sent();
9006
9524
  if (!privateKey || !encryptedSeedPhrase) {
9007
- return [2 /*return*/, { valid: false, message: 'Could not locate client keys or seedPhrase' }];
9525
+ return [2 /*return*/, { valid: false, message: 'Could not locate client keys or seed phrase on this device.' }];
9008
9526
  }
9009
- decryptedPrivateKey = (_c = AES.decrypt(privateKey, password).toString(enc.Utf8)) !== null && _c !== void 0 ? _c : undefined;
9527
+ _c.label = 3;
9528
+ case 3:
9529
+ _c.trys.push([3, 7, , 8]);
9530
+ return [4 /*yield*/, this.auth.getUserSalt()];
9531
+ case 4:
9532
+ salt = _c.sent();
9533
+ return [4 /*yield*/, this.cipher.getCredentialsKeyPair({
9534
+ authType: AuthType.Password,
9535
+ password: password,
9536
+ salt: salt,
9537
+ })];
9538
+ case 5:
9539
+ credentialsKeyPair = _c.sent();
9540
+ return [4 /*yield*/, this.cipher.decrypt({
9541
+ cipherText: JSON.parse(privateKey),
9542
+ decryptionKey: credentialsKeyPair.privateKey,
9543
+ })];
9544
+ case 6:
9545
+ decryptedPrivateKey = _c.sent();
9010
9546
  if (decryptedPrivateKey) {
9011
9547
  return [2 /*return*/, { valid: true }];
9012
9548
  }
9013
9549
  else {
9014
- return [2 /*return*/, { valid: false, message: 'password is incorrect' }];
9550
+ return [2 /*return*/, { valid: false, message: 'Password is incorrect' }];
9015
9551
  }
9552
+ case 7:
9553
+ error_2 = _c.sent();
9554
+ logger.error('SDK::Utils::validatePassword::error', error_2);
9555
+ return [2 /*return*/, { valid: false, message: 'Password is incorrect.' }];
9556
+ case 8: return [2 /*return*/];
9016
9557
  }
9017
9558
  });
9018
9559
  });
@@ -9540,39 +10081,6 @@ var System = /** @class */ (function (_super) {
9540
10081
  return System;
9541
10082
  }(Base));
9542
10083
 
9543
- var TransactionsRoutes = {
9544
- transfer: {
9545
- fullPath: '/transactions/transfer',
9546
- method: RequestMethod.Post,
9547
- requiresAccessToken: true,
9548
- },
9549
- transferWithShares: {
9550
- fullPath: '/transactions/transfer-with-shares',
9551
- method: RequestMethod.Post,
9552
- requiresAccessToken: true,
9553
- },
9554
- createAllowance: {
9555
- fullPath: '/transactions/create-allowance',
9556
- method: RequestMethod.Post,
9557
- requiresAccessToken: true,
9558
- },
9559
- estimateFee: {
9560
- fullPath: '/transactions/estimate-fee',
9561
- method: RequestMethod.Get,
9562
- requiresAccessToken: true,
9563
- },
9564
- getTransaction: {
9565
- fullPath: '/transactions/status',
9566
- method: RequestMethod.Get,
9567
- requiresAccessToken: true,
9568
- },
9569
- getTransactions: {
9570
- fullPath: '/query/transactions',
9571
- method: RequestMethod.Get,
9572
- requiresAccessToken: true,
9573
- },
9574
- };
9575
-
9576
10084
  var Transactions = /** @class */ (function (_super) {
9577
10085
  __extends(Transactions, _super);
9578
10086
  function Transactions(config) {
@@ -9630,86 +10138,6 @@ var Transactions = /** @class */ (function (_super) {
9630
10138
  });
9631
10139
  });
9632
10140
  };
9633
- Transactions.prototype.submit = function (transactionRequest) {
9634
- return __awaiter(this, void 0, void 0, function () {
9635
- var encryptedDevicePrivateKey, encryptedSeedPhrase, credentialsKeyPair, decryptedDevicePrivateKey, deviceAuthPublicKey, signatureMessage, readyForTransportSeedPhrase, message, signature, response;
9636
- var _a;
9637
- return __generator(this, function (_b) {
9638
- switch (_b.label) {
9639
- case 0: return [4 /*yield*/, this.storageService.fetch(LocalStorageItems.EncryptedDevicePrivateKey)];
9640
- case 1:
9641
- encryptedDevicePrivateKey = _b.sent();
9642
- return [4 /*yield*/, this.storageService.fetch(LocalStorageItems.EncryptedStandardSeedPhrase)];
9643
- case 2:
9644
- encryptedSeedPhrase = _b.sent();
9645
- if (!encryptedDevicePrivateKey) {
9646
- throw new Error('No private key was found on this device');
9647
- }
9648
- if (!encryptedSeedPhrase) {
9649
- throw new Error('Seed phrase was not found on this device. Please recover your wallet.');
9650
- }
9651
- return [4 /*yield*/, this.cipher.getCredentialsKeyPair({
9652
- password: transactionRequest.password,
9653
- salt: this.userId,
9654
- prfValue: transactionRequest.prfValue,
9655
- authType: this.deviceAuthType,
9656
- })];
9657
- case 3:
9658
- credentialsKeyPair = _b.sent();
9659
- if (!credentialsKeyPair) {
9660
- throw new Error('Credentials are wrong, please pass the correct credentials.');
9661
- }
9662
- return [4 /*yield*/, this.cipher.decrypt({
9663
- cipherText: JSON.parse(encryptedDevicePrivateKey),
9664
- decryptionKey: (_a = credentialsKeyPair === null || credentialsKeyPair === void 0 ? void 0 : credentialsKeyPair.privateKey) !== null && _a !== void 0 ? _a : '',
9665
- })];
9666
- case 4:
9667
- decryptedDevicePrivateKey = _b.sent();
9668
- deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
9669
- return [4 /*yield*/, this.authService.getSignature({
9670
- publicKey: deviceAuthPublicKey,
9671
- privateKey: decryptedDevicePrivateKey,
9672
- })];
9673
- case 5:
9674
- signatureMessage = _b.sent();
9675
- return [4 /*yield*/, this.cipher.prepareStoredDataForTransport({
9676
- storedEncryptedData: JSON.parse(encryptedSeedPhrase),
9677
- encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
9678
- wallabyPublicKey: transactionRequest.wallabyAuthPublicKey,
9679
- options: {
9680
- authType: this.deviceAuthType,
9681
- password: transactionRequest.password,
9682
- prfValue: transactionRequest.prfValue,
9683
- },
9684
- })];
9685
- case 6:
9686
- readyForTransportSeedPhrase = _b.sent();
9687
- message = signatureMessage.message, signature = signatureMessage.signature;
9688
- return [4 /*yield*/, this.request(TransactionsRoutes.transfer, {
9689
- method: TransactionsRoutes.transfer.method,
9690
- payload: {
9691
- message: message,
9692
- signature: signature,
9693
- clientAuthPubKey: deviceAuthPublicKey,
9694
- encryptedSeed: readyForTransportSeedPhrase,
9695
- originAddress: transactionRequest.originAddress,
9696
- recipientAddress: transactionRequest.recipientAddress,
9697
- amount: transactionRequest.amount,
9698
- transactionType: transactionRequest.transactionType,
9699
- reference: v4(),
9700
- memo: "".concat(transactionRequest.originAddress, " is ").concat(transactionRequest.transactionType, "ing to ").concat(transactionRequest.recipientAddress),
9701
- },
9702
- })];
9703
- case 7:
9704
- response = _b.sent();
9705
- if (response.error) {
9706
- throw new Error(response.error);
9707
- }
9708
- return [2 /*return*/, response];
9709
- }
9710
- });
9711
- });
9712
- };
9713
10141
  /**
9714
10142
  *
9715
10143
  * @public
@@ -9802,88 +10230,47 @@ var Transactions = /** @class */ (function (_super) {
9802
10230
  */
9803
10231
  Transactions.prototype.transfer = function (_a) {
9804
10232
  return __awaiter(this, arguments, void 0, function (_b) {
9805
- var password, prfValue, user, encryptedDevicePrivateKey, credentialsKeyPair, decryptedDevicePrivateKey, deviceAuthPublicKey, signatureMessage, sharesEncryptedWithWallabyPubKey, primaryKeyShare, parsedPrimaryShare, readyForTransportShare, message, signature, response, error_4;
10233
+ var _c, deviceAuthPublicKey, signatureMessage, readyForTransportSeedPhrase, sharesEncryptedWithWallabyPubKey, hasShares, transferResponse, error_4;
9806
10234
  var originAddress = _b.originAddress, recipientAddress = _b.recipientAddress, amount = _b.amount, assetId = _b.assetId, reference = _b.reference, authenticationOptions = _b.authenticationOptions, memo = _b.memo;
9807
- return __generator(this, function (_c) {
9808
- switch (_c.label) {
10235
+ return __generator(this, function (_d) {
10236
+ switch (_d.label) {
9809
10237
  case 0:
9810
- _c.trys.push([0, 8, , 9]);
9811
- password = authenticationOptions.password, prfValue = authenticationOptions.prfValue, user = authenticationOptions.user;
9812
- return [4 /*yield*/, this.storageService.fetch(LocalStorageItems.EncryptedDevicePrivateKey)];
10238
+ _d.trys.push([0, 7, , 8]);
10239
+ return [4 /*yield*/, this.prepareTransactionAuth(authenticationOptions)];
9813
10240
  case 1:
9814
- encryptedDevicePrivateKey = _c.sent();
9815
- if (!encryptedDevicePrivateKey) {
9816
- throw new Error('No private key was found on this device');
9817
- }
9818
- return [4 /*yield*/, this.cipher.getCredentialsKeyPair({
9819
- authType: this.deviceAuthType,
9820
- password: password,
9821
- prfValue: prfValue,
9822
- salt: user.clientSalt,
10241
+ _c = _d.sent(), deviceAuthPublicKey = _c.deviceAuthPublicKey, signatureMessage = _c.signatureMessage, readyForTransportSeedPhrase = _c.readyForTransportSeedPhrase, sharesEncryptedWithWallabyPubKey = _c.sharesEncryptedWithWallabyPubKey, hasShares = _c.hasShares;
10242
+ transferResponse = void 0;
10243
+ if (!readyForTransportSeedPhrase) return [3 /*break*/, 3];
10244
+ return [4 /*yield*/, this.request(TransactionsRoutes.transfer, {
10245
+ method: TransactionsRoutes.transfer.method,
10246
+ payload: __assign(__assign({}, signatureMessage), { clientAuthPubKey: deviceAuthPublicKey, encryptedSeed: readyForTransportSeedPhrase, originAddress: originAddress, recipientAddress: recipientAddress, assetId: assetId, amount: amount, reference: reference || v4(), memo: memo }),
9823
10247
  })];
9824
10248
  case 2:
9825
- credentialsKeyPair = _c.sent();
9826
- return [4 /*yield*/, this.cipher.decrypt({
9827
- cipherText: JSON.parse(encryptedDevicePrivateKey),
9828
- decryptionKey: credentialsKeyPair.privateKey,
9829
- })];
10249
+ transferResponse = _d.sent();
10250
+ return [3 /*break*/, 6];
9830
10251
  case 3:
9831
- decryptedDevicePrivateKey = _c.sent();
9832
- deviceAuthPublicKey = publicKeyByPrivateKey(decryptedDevicePrivateKey);
9833
- return [4 /*yield*/, this.authService.getSignature({
9834
- publicKey: deviceAuthPublicKey,
9835
- privateKey: decryptedDevicePrivateKey,
9836
- })];
9837
- case 4:
9838
- signatureMessage = _c.sent();
9839
- sharesEncryptedWithWallabyPubKey = [];
9840
- return [4 /*yield*/, this.storageService.fetch(LocalStorageItems.PrimaryDeviceKeyShare)];
9841
- case 5:
9842
- primaryKeyShare = _c.sent();
9843
- parsedPrimaryShare = safeJsonParse(primaryKeyShare !== null && primaryKeyShare !== void 0 ? primaryKeyShare : '');
9844
- if (!parsedPrimaryShare)
9845
- throw new Error('Your device does not have a primary operating share.');
9846
- return [4 /*yield*/, this.cipher.prepareStoredDataForTransport({
9847
- storedEncryptedData: parsedPrimaryShare,
9848
- encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
9849
- wallabyPublicKey: user.wallabyAuthPubKey,
9850
- options: {
9851
- authType: this.deviceAuthType,
9852
- password: password,
9853
- prfValue: prfValue,
9854
- salt: user.clientSalt,
9855
- },
9856
- })];
9857
- case 6:
9858
- readyForTransportShare = _c.sent();
9859
- sharesEncryptedWithWallabyPubKey.push(readyForTransportShare);
9860
- message = signatureMessage.message, signature = signatureMessage.signature;
10252
+ if (!hasShares) return [3 /*break*/, 5];
9861
10253
  return [4 /*yield*/, this.request(TransactionsRoutes.transferWithShares, {
9862
10254
  method: TransactionsRoutes.transferWithShares.method,
9863
- payload: {
9864
- message: message,
9865
- signature: signature,
9866
- clientAuthPubKey: deviceAuthPublicKey,
9867
- encryptedShares: sharesEncryptedWithWallabyPubKey,
9868
- originAddress: originAddress,
9869
- recipientAddress: recipientAddress,
9870
- assetId: assetId,
9871
- amount: amount,
9872
- reference: reference,
9873
- memo: memo,
9874
- },
10255
+ payload: __assign(__assign({}, signatureMessage), { clientAuthPubKey: deviceAuthPublicKey, encryptedShares: sharesEncryptedWithWallabyPubKey, encryptedSeed: readyForTransportSeedPhrase, originAddress: originAddress, recipientAddress: recipientAddress, assetId: assetId, amount: amount, reference: reference || v4(), memo: memo }),
9875
10256
  })];
9876
- case 7:
9877
- response = _c.sent();
9878
- if (response.error) {
9879
- throw new Error(response.error);
10257
+ case 4:
10258
+ transferResponse = _d.sent();
10259
+ return [3 /*break*/, 6];
10260
+ case 5: throw new Error('No valid authentication method found');
10261
+ case 6:
10262
+ if (!transferResponse || transferResponse.error) {
10263
+ throw new Error(transferResponse === null || transferResponse === void 0 ? void 0 : transferResponse.error);
9880
10264
  }
9881
- return [2 /*return*/, response];
9882
- case 8:
9883
- error_4 = _c.sent();
9884
- logger.error('SDK::Transactions::transferWithShares::error', error_4);
9885
- return [2 /*return*/, Promise.reject(error_4)];
9886
- case 9: return [2 /*return*/];
10265
+ if (!transferResponse.transaction) {
10266
+ throw new Error('Invalid response: missing transaction data');
10267
+ }
10268
+ return [2 /*return*/, transferResponse];
10269
+ case 7:
10270
+ error_4 = _d.sent();
10271
+ logger.error('SDK::Transactions::transfer::error', error_4);
10272
+ throw error_4;
10273
+ case 8: return [2 /*return*/];
9887
10274
  }
9888
10275
  });
9889
10276
  });
@@ -9905,25 +10292,76 @@ var Transactions = /** @class */ (function (_super) {
9905
10292
  */
9906
10293
  Transactions.prototype.createAllowance = function (_a) {
9907
10294
  return __awaiter(this, arguments, void 0, function (_b) {
9908
- var encryptedDevicePrivateKey, password, prfValue, user, credentialsKeyPair, decryptedDevicePrivateKey, deviceAuthPublicKey, signatureMessage, encryptedSeedPhrase, seedPhraseEncryptedWithWallabyPubKey, message, signature, response, error_5;
10295
+ var _c, deviceAuthPublicKey, signatureMessage, readyForTransportSeedPhrase, message, signature, response, error_5;
9909
10296
  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;
9910
- return __generator(this, function (_c) {
9911
- switch (_c.label) {
10297
+ return __generator(this, function (_d) {
10298
+ switch (_d.label) {
9912
10299
  case 0:
9913
- _c.trys.push([0, 8, , 9]);
10300
+ _d.trys.push([0, 3, , 4]);
9914
10301
  if (!suiObjectId && !contractAddress && !assetId && !assetSymbol && !chainName) {
9915
10302
  throw new Error("AssetId, asset symbol, chain name or contract address must be provided.");
9916
10303
  }
9917
10304
  if ((assetSymbol && !chainName) || (!assetSymbol && chainName)) {
9918
10305
  throw new Error("Asset symbol and chain name must be provided when asset is not in user wallet.");
9919
10306
  }
10307
+ return [4 /*yield*/, this.prepareTransactionAuth(authenticationOptions)];
10308
+ case 1:
10309
+ _c = _d.sent(), deviceAuthPublicKey = _c.deviceAuthPublicKey, signatureMessage = _c.signatureMessage, readyForTransportSeedPhrase = _c.readyForTransportSeedPhrase;
10310
+ message = signatureMessage.message, signature = signatureMessage.signature;
10311
+ // Create allowance only supports seed phrase for now, but we could extend it to support shares
10312
+ if (!readyForTransportSeedPhrase) {
10313
+ throw new Error('Create allowance requires a seed phrase. Key shares are not yet supported for this operation.');
10314
+ }
10315
+ return [4 /*yield*/, this.request(TransactionsRoutes.createAllowance, {
10316
+ method: TransactionsRoutes.createAllowance.method,
10317
+ payload: {
10318
+ message: message,
10319
+ signature: signature,
10320
+ clientAuthPubKey: deviceAuthPublicKey,
10321
+ encryptedSeed: readyForTransportSeedPhrase,
10322
+ ownerAddress: ownerAddress,
10323
+ spenderAddress: spenderAddress,
10324
+ chainName: chainName,
10325
+ assetSymbol: assetSymbol,
10326
+ amount: amount,
10327
+ assetId: assetId,
10328
+ contractAddress: contractAddress !== null && contractAddress !== void 0 ? contractAddress : suiObjectId,
10329
+ reference: reference,
10330
+ memo: memo,
10331
+ },
10332
+ })];
10333
+ case 2:
10334
+ response = _d.sent();
10335
+ if (response.error) {
10336
+ throw new Error(response.error);
10337
+ }
10338
+ return [2 /*return*/, response];
10339
+ case 3:
10340
+ error_5 = _d.sent();
10341
+ logger.error('SDK::Transactions::createAllowance::error', error_5);
10342
+ throw error_5;
10343
+ case 4: return [2 /*return*/];
10344
+ }
10345
+ });
10346
+ });
10347
+ };
10348
+ /**
10349
+ * Prepares authentication data and encrypted payload for transaction requests
10350
+ * @private
10351
+ */
10352
+ Transactions.prototype.prepareTransactionAuth = function (authenticationOptions) {
10353
+ return __awaiter(this, void 0, void 0, function () {
10354
+ var password, prfValue, user, encryptedDevicePrivateKey, credentialsKeyPair, decryptedDevicePrivateKey, deviceAuthPublicKey, signatureMessage, sharesEncryptedWithWallabyPubKey, readyForTransportSeedPhrase, primaryKeyShare, parsedPrimaryShare, encryptedSeedPhrase, parsedSeedPhrase, readyForTransportShare;
10355
+ return __generator(this, function (_a) {
10356
+ switch (_a.label) {
10357
+ case 0:
10358
+ password = authenticationOptions.password, prfValue = authenticationOptions.prfValue, user = authenticationOptions.user;
9920
10359
  return [4 /*yield*/, this.storageService.fetch(LocalStorageItems.EncryptedDevicePrivateKey)];
9921
10360
  case 1:
9922
- encryptedDevicePrivateKey = _c.sent();
10361
+ encryptedDevicePrivateKey = _a.sent();
9923
10362
  if (!encryptedDevicePrivateKey) {
9924
10363
  throw new Error('No private key was found on this device');
9925
10364
  }
9926
- password = authenticationOptions.password, prfValue = authenticationOptions.prfValue, user = authenticationOptions.user;
9927
10365
  return [4 /*yield*/, this.cipher.getCredentialsKeyPair({
9928
10366
  authType: this.deviceAuthType,
9929
10367
  password: password,
@@ -9931,13 +10369,13 @@ var Transactions = /** @class */ (function (_super) {
9931
10369
  salt: user.clientSalt,
9932
10370
  })];
9933
10371
  case 2:
9934
- credentialsKeyPair = _c.sent();
10372
+ credentialsKeyPair = _a.sent();
9935
10373
  return [4 /*yield*/, this.cipher.decrypt({
9936
10374
  cipherText: JSON.parse(encryptedDevicePrivateKey),
9937
10375
  decryptionKey: credentialsKeyPair.privateKey,
9938
10376
  })];
9939
10377
  case 3:
9940
- decryptedDevicePrivateKey = _c.sent();
10378
+ decryptedDevicePrivateKey = _a.sent();
9941
10379
  if (!decryptedDevicePrivateKey) {
9942
10380
  throw new Error('Credentials are wrong, please pass the correct credentials.');
9943
10381
  }
@@ -9947,15 +10385,23 @@ var Transactions = /** @class */ (function (_super) {
9947
10385
  privateKey: decryptedDevicePrivateKey,
9948
10386
  })];
9949
10387
  case 4:
9950
- signatureMessage = _c.sent();
9951
- return [4 /*yield*/, this.storageService.fetch(LocalStorageItems.EncryptedStandardSeedPhrase)];
10388
+ signatureMessage = _a.sent();
10389
+ sharesEncryptedWithWallabyPubKey = [];
10390
+ readyForTransportSeedPhrase = undefined;
10391
+ return [4 /*yield*/, this.storageService.fetch(LocalStorageItems.PrimaryDeviceKeyShare)];
9952
10392
  case 5:
9953
- encryptedSeedPhrase = _c.sent();
9954
- if (!encryptedSeedPhrase) {
9955
- throw new Error('Seed phrase were not found on this device.');
10393
+ primaryKeyShare = _a.sent();
10394
+ parsedPrimaryShare = safeJsonParse(primaryKeyShare !== null && primaryKeyShare !== void 0 ? primaryKeyShare : '');
10395
+ if (!!parsedPrimaryShare) return [3 /*break*/, 8];
10396
+ return [4 /*yield*/, this.storageService.fetch(LocalStorageItems.EncryptedStandardSeedPhrase)];
10397
+ case 6:
10398
+ encryptedSeedPhrase = _a.sent();
10399
+ parsedSeedPhrase = safeJsonParse(encryptedSeedPhrase !== null && encryptedSeedPhrase !== void 0 ? encryptedSeedPhrase : '');
10400
+ if (!parsedSeedPhrase) {
10401
+ throw new Error('Your device does not have a seed phrase or an operating share to sign the transaction.');
9956
10402
  }
9957
10403
  return [4 /*yield*/, this.cipher.prepareStoredDataForTransport({
9958
- storedEncryptedData: JSON.parse(encryptedSeedPhrase),
10404
+ storedEncryptedData: parsedSeedPhrase,
9959
10405
  encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
9960
10406
  wallabyPublicKey: user.wallabyAuthPubKey,
9961
10407
  options: {
@@ -9965,38 +10411,31 @@ var Transactions = /** @class */ (function (_super) {
9965
10411
  salt: user.clientSalt,
9966
10412
  },
9967
10413
  })];
9968
- case 6:
9969
- seedPhraseEncryptedWithWallabyPubKey = _c.sent();
9970
- message = signatureMessage.message, signature = signatureMessage.signature;
9971
- return [4 /*yield*/, this.request(TransactionsRoutes.createAllowance, {
9972
- method: TransactionsRoutes.createAllowance.method,
9973
- payload: {
9974
- message: message,
9975
- signature: signature,
9976
- clientAuthPubKey: deviceAuthPublicKey,
9977
- encryptedSeed: seedPhraseEncryptedWithWallabyPubKey,
9978
- ownerAddress: ownerAddress,
9979
- spenderAddress: spenderAddress,
9980
- chainName: chainName,
9981
- assetSymbol: assetSymbol,
9982
- amount: amount,
9983
- assetId: assetId,
9984
- contractAddress: contractAddress !== null && contractAddress !== void 0 ? contractAddress : suiObjectId,
9985
- reference: reference,
9986
- memo: memo,
9987
- },
9988
- })];
9989
10414
  case 7:
9990
- response = _c.sent();
9991
- if (response.error) {
9992
- throw new Error(response.error);
9993
- }
9994
- return [2 /*return*/, response];
9995
- case 8:
9996
- error_5 = _c.sent();
9997
- logger.error('SDK::Transactions::createAllowance::error', error_5);
9998
- return [2 /*return*/, Promise.reject(error_5)];
9999
- case 9: return [2 /*return*/];
10415
+ readyForTransportSeedPhrase = _a.sent();
10416
+ return [3 /*break*/, 10];
10417
+ case 8: return [4 /*yield*/, this.cipher.prepareStoredDataForTransport({
10418
+ storedEncryptedData: parsedPrimaryShare,
10419
+ encryptedDevicePrivateKey: JSON.parse(encryptedDevicePrivateKey),
10420
+ wallabyPublicKey: user.wallabyAuthPubKey,
10421
+ options: {
10422
+ authType: this.deviceAuthType,
10423
+ password: password,
10424
+ prfValue: prfValue,
10425
+ salt: user.clientSalt,
10426
+ },
10427
+ })];
10428
+ case 9:
10429
+ readyForTransportShare = _a.sent();
10430
+ sharesEncryptedWithWallabyPubKey.push(readyForTransportShare);
10431
+ _a.label = 10;
10432
+ case 10: return [2 /*return*/, {
10433
+ deviceAuthPublicKey: deviceAuthPublicKey,
10434
+ signatureMessage: signatureMessage,
10435
+ readyForTransportSeedPhrase: readyForTransportSeedPhrase,
10436
+ sharesEncryptedWithWallabyPubKey: sharesEncryptedWithWallabyPubKey,
10437
+ hasShares: sharesEncryptedWithWallabyPubKey.length > 0,
10438
+ }];
10000
10439
  }
10001
10440
  });
10002
10441
  });
@@ -10031,5 +10470,5 @@ var Wallaby = /** @class */ (function () {
10031
10470
  return Wallaby;
10032
10471
  }());
10033
10472
 
10034
- export { AddressType, ApiKeyStatus, AssetConfigStatus, AssetType, AuthType, BlockchainName, BlockchainSlip44, BlockchainStatus, ErrorResponseCodes, KeyTypeName, LocalStorageItems, OwnershipType, PasskeyChallengeType, PublicKeyCredentialAlgorithm, RequestMethod, ReturnWalletOption, SeedPhraseType, TokenStandard, TransportEnum, UserAssetSource, Wallaby, WalletOwnershipType, createIdentity, decryptWithPrivateKey, encryptWithPublicKey, hash, keccak256, publicKeyByPrivateKey, recoverPublicKey, sign };
10473
+ export { AddressType, ApiKeyStatus, AssetConfigStatus, AssetType, AuthType, BlockchainName, BlockchainSlip44, BlockchainStatus, ErrorResponseCodes, KeyTypeName, LegacyKeyNames, LocalStorageItems, OwnershipType, PasskeyChallengeType, PublicKeyCredentialAlgorithm, RequestMethod, ReturnWalletOption, SeedPhraseType, TokenStandard, TransportEnum, UserAssetSource, V1KeyNames, V2KeyNames, Wallaby, WalletOwnershipType, createIdentity, decryptWithPrivateKey, encryptWithPublicKey, hash, keccak256, publicKeyByPrivateKey, recoverPublicKey, sign };
10035
10474
  //# sourceMappingURL=index.esm.js.map