wallaby-cash 2.0.1-alpha.22 → 2.0.1-alpha.24

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/base.d.ts CHANGED
@@ -1,13 +1,13 @@
1
- import { WallabyConfig, RequestOptions, RequestRoute, WallabyConfigOptions } from './types';
1
+ import { WallabyConfig, RequestOptions, RequestRoute, WallabyConfigOptions, AuthType } from './types';
2
2
  import { StorageService } from './lib/utils/storage.service';
3
3
  import { LocalStorage } from './types/storage';
4
4
  export declare abstract class Base {
5
5
  private apiKey;
6
6
  private baseUrl;
7
- private jwt?;
8
7
  private clientAuthToken;
9
- userId: string;
10
- options?: WallabyConfigOptions;
8
+ protected userId: string;
9
+ protected options?: WallabyConfigOptions;
10
+ protected deviceAuthType: AuthType;
11
11
  constructor(config: WallabyConfig);
12
12
  /**
13
13
  * This library uses `localStorage` as the default storage.
@@ -20,7 +20,13 @@ export declare abstract class Base {
20
20
  /**
21
21
  * @protected
22
22
  */
23
- protected get device(): Promise<import("./types").DeviceInformation>;
23
+ protected get device(): {
24
+ deviceAuthType: AuthType;
25
+ then<TResult1 = import("./types").DeviceInformation, TResult2 = never>(onfulfilled?: ((value: import("./types").DeviceInformation) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): Promise<TResult1 | TResult2>;
26
+ catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null | undefined): Promise<import("./types").DeviceInformation | TResult>;
27
+ finally(onfinally?: (() => void) | null | undefined): Promise<import("./types").DeviceInformation>;
28
+ [Symbol.toStringTag]: string;
29
+ };
24
30
  /**
25
31
  * @private
26
32
  */
package/dist/index.cjs.js CHANGED
@@ -113,6 +113,11 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
113
113
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
114
114
  };
115
115
 
116
+ exports.PasskeyChallengeType = void 0;
117
+ (function (PasskeyChallengeType) {
118
+ PasskeyChallengeType["REGISTRATION"] = "webauthn.create";
119
+ PasskeyChallengeType["AUTHENTICATION"] = "webauthn.get";
120
+ })(exports.PasskeyChallengeType || (exports.PasskeyChallengeType = {}));
116
121
  exports.PublicKeyCredentialAlgorithm = void 0;
117
122
  (function (PublicKeyCredentialAlgorithm) {
118
123
  PublicKeyCredentialAlgorithm[PublicKeyCredentialAlgorithm["RS256"] = -257] = "RS256";
@@ -234,6 +239,12 @@ exports.WalletOwnershipType = void 0;
234
239
  WalletOwnershipType["MultiOwner"] = "MULTI_OWNER";
235
240
  })(exports.WalletOwnershipType || (exports.WalletOwnershipType = {}));
236
241
 
242
+ exports.AuthType = void 0;
243
+ (function (AuthType) {
244
+ AuthType["Mfa"] = "mfa";
245
+ AuthType["Passkey"] = "passkey";
246
+ })(exports.AuthType || (exports.AuthType = {}));
247
+
237
248
  /** Most react native storage engines are async.
238
249
  * Explicitly setting these types will make it compatible with Expo Secure Store and React Native Async
239
250
  * Storage and RNSecureStorage for now. See:
@@ -4724,13 +4735,13 @@ var StorageService = /** @class */ (function () {
4724
4735
  this.removeItem("accessToken_".concat(this.userId)),
4725
4736
  this.delete(exports.LocalStorageItems.AccessToken),
4726
4737
  this.delete(exports.LocalStorageItems.ClientAuthPublicKey),
4727
- this.delete(exports.LocalStorageItems.ClientAuthToken),
4738
+ // this.delete(LocalStorageItems.ClientAuthToken),
4739
+ this.delete(exports.LocalStorageItems.EncryptedAlgorandSeedPhrase),
4728
4740
  this.delete(exports.LocalStorageItems.EncryptedStandardSeedPhrase),
4729
4741
  this.delete(exports.LocalStorageItems.EncryptedKeyShares),
4730
4742
  this.delete(exports.LocalStorageItems.EncryptedShare),
4731
4743
  this.delete(exports.LocalStorageItems.PrimaryDeviceKeyShare),
4732
4744
  this.delete(exports.LocalStorageItems.BackupDeviceKeyShare),
4733
- this.delete(exports.LocalStorageItems.EncryptedAlgorandSeedPhrase),
4734
4745
  this.delete(exports.LocalStorageItems.EncryptedDevicePrivateKey),
4735
4746
  this.delete(exports.LocalStorageItems.WallabyAuthPubKey),
4736
4747
  ])];
@@ -4743,47 +4754,50 @@ var StorageService = /** @class */ (function () {
4743
4754
  };
4744
4755
  StorageService.prototype.loadDeviceInformation = function () {
4745
4756
  return __awaiter(this, void 0, void 0, function () {
4746
- var _a, _b, _c, _d;
4747
- var _e;
4748
- return __generator(this, function (_f) {
4749
- switch (_f.label) {
4757
+ var _a, _b;
4758
+ var _c, _d, _e, _f;
4759
+ var _g, _h;
4760
+ return __generator(this, function (_j) {
4761
+ switch (_j.label) {
4750
4762
  case 0:
4751
- _a = {};
4752
- _b = {};
4763
+ _c = {};
4764
+ _d = {};
4753
4765
  return [4 /*yield*/, this.fetch(exports.LocalStorageItems.AccessToken)];
4754
4766
  case 1:
4755
- _b.accessToken = _f.sent();
4767
+ _d.accessToken = _j.sent();
4756
4768
  return [4 /*yield*/, this.fetch(exports.LocalStorageItems.ClientAuthToken)];
4757
4769
  case 2:
4758
- _a.authTokens = (_b.clientAuthToken = _f.sent(),
4759
- _b);
4760
- _c = {
4770
+ _c.authTokens = (_d.clientAuthToken = _j.sent(),
4771
+ _d);
4772
+ _b = (_a = JSON).parse;
4773
+ return [4 /*yield*/, this.fetch(exports.LocalStorageItems.PrimaryDeviceKeyShare)];
4774
+ case 3:
4775
+ _c.deviceKeyShare = _b.apply(_a, [(_g = _j.sent()) !== null && _g !== void 0 ? _g : '']);
4776
+ _e = {
4761
4777
  clientUserId: this.userId
4762
4778
  };
4763
4779
  return [4 /*yield*/, this.fetch(exports.LocalStorageItems.EncryptedStandardSeedPhrase)];
4764
- case 3:
4765
- _c.encryptedStandardSeedPhrase = _f.sent();
4766
- return [4 /*yield*/, this.fetch(exports.LocalStorageItems.EncryptedAlgorandSeedPhrase)];
4767
4780
  case 4:
4768
- _a.user = (
4769
- // encryptedKeyShare: await this.fetch(LocalStorageItems.EncryptedKeyShares),
4770
- _c.encryptedAlgorandSeedPhrase = _f.sent(),
4771
- _c.wallabyUserId = undefined,
4772
- _c);
4773
- _d = {
4781
+ _e.encryptedStandardSeedPhrase = _j.sent();
4782
+ return [4 /*yield*/, this.fetch(exports.LocalStorageItems.EncryptedAlgorandSeedPhrase)];
4783
+ case 5:
4784
+ _c.user = (_e.encryptedAlgorandSeedPhrase = _j.sent(),
4785
+ _e.wallabyUserId = undefined,
4786
+ _e);
4787
+ _f = {
4774
4788
  // Initially these are undefined, because we don't have the decrypted private key yet, and for that we need the password.
4775
4789
  deviceAuthPrivateKey: undefined,
4776
4790
  deviceAuthPublicKey: undefined
4777
4791
  };
4778
4792
  return [4 /*yield*/, this.fetch(exports.LocalStorageItems.EncryptedDevicePrivateKey)];
4779
- case 5:
4780
- _d.deviceEncryptedPrivateKey = _f.sent();
4793
+ case 6:
4794
+ _f.deviceEncryptedPrivateKey = _j.sent();
4781
4795
  return [4 /*yield*/, this.fetch(exports.LocalStorageItems.WallabyAuthPubKey)];
4782
- case 6: return [2 /*return*/, (_a.credentials = (_d.wallabyPublicKey = _f.sent(),
4783
- _d),
4796
+ case 7: return [2 /*return*/, (_c.credentials = (_f.wallabyPublicKey = _j.sent(),
4797
+ _f),
4784
4798
  // hostname: window ? window?.location?.hostname : 'wallaby.cash',
4785
- _a.hostname = typeof window === 'undefined' ? 'republic.com' : (_e = window === null || window === void 0 ? void 0 : window.location) === null || _e === void 0 ? void 0 : _e.hostname,
4786
- _a)];
4799
+ _c.hostname = typeof window === 'undefined' ? 'republic.com' : (_h = window === null || window === void 0 ? void 0 : window.location) === null || _h === void 0 ? void 0 : _h.hostname,
4800
+ _c)];
4787
4801
  }
4788
4802
  });
4789
4803
  });
@@ -4819,6 +4833,28 @@ function jwtHasExpired(jwt) {
4819
4833
  }
4820
4834
  return millisecondsToJWTTimeout(jwt) <= 0;
4821
4835
  }
4836
+ function jwtHasSameUser(jwt, userId) {
4837
+ if (!jwt) {
4838
+ return false;
4839
+ }
4840
+ var jwtDecoded = jwtDecode.jwtDecode(jwt);
4841
+ console.log('jwtDecoded', {
4842
+ jwtDecoded: jwtDecoded,
4843
+ userId: userId,
4844
+ jwt: jwt,
4845
+ });
4846
+ if (jwtDecoded.externalUserId !== userId) {
4847
+ return true;
4848
+ }
4849
+ return true;
4850
+ }
4851
+ function jwtIsSecure(jwt) {
4852
+ var jwtDecoded = jwtDecode.jwtDecode(jwt);
4853
+ if (!jwtDecoded.mfaVerified) {
4854
+ return false;
4855
+ }
4856
+ return true;
4857
+ }
4822
4858
  /**
4823
4859
  * Calculates the remaining time in milliseconds until a given JWT expires.
4824
4860
  *
@@ -4841,6 +4877,16 @@ var Base = /** @class */ (function () {
4841
4877
  this.userId = config.userId;
4842
4878
  this.clientAuthToken = (_a = config.clientAuthToken) !== null && _a !== void 0 ? _a : config === null || config === void 0 ? void 0 : config.jwt;
4843
4879
  this.options = config.options;
4880
+ this.request = this.request.bind(this);
4881
+ if (!jwtHasSameUser(this.clientAuthToken, this.userId)) {
4882
+ throw new Error('Client auth token does not match the user id. Blocking API call.');
4883
+ }
4884
+ if (!isTest && jwtIsSecure(this.clientAuthToken)) {
4885
+ this.deviceAuthType = exports.AuthType.Passkey;
4886
+ }
4887
+ else {
4888
+ this.deviceAuthType = exports.AuthType.Mfa;
4889
+ }
4844
4890
  }
4845
4891
  Object.defineProperty(Base.prototype, "deviceStorage", {
4846
4892
  /**
@@ -4868,7 +4914,7 @@ var Base = /** @class */ (function () {
4868
4914
  * @protected
4869
4915
  */
4870
4916
  get: function () {
4871
- return this.storageService.loadDeviceInformation();
4917
+ return __assign(__assign({}, this.storageService.loadDeviceInformation()), { deviceAuthType: this.deviceAuthType });
4872
4918
  },
4873
4919
  enumerable: false,
4874
4920
  configurable: true
@@ -4878,13 +4924,13 @@ var Base = /** @class */ (function () {
4878
4924
  * @private
4879
4925
  */
4880
4926
  get: function () {
4881
- var _a, _b, _c, _d, _e;
4927
+ var _a, _b, _c, _d, _e, _f, _g;
4882
4928
  return {
4883
4929
  apiKey: this.apiKey,
4884
4930
  baseUrl: this.baseUrl,
4885
4931
  environment: (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.environment) !== null && _b !== void 0 ? _b : defaultEnvironment,
4886
4932
  network: (_d = (_c = this.options) === null || _c === void 0 ? void 0 : _c.network) !== null && _d !== void 0 ? _d : defaultNetwork,
4887
- hostname: (_e = this.options) === null || _e === void 0 ? void 0 : _e.hostname,
4933
+ hostname: (_f = (_e = this.options) === null || _e === void 0 ? void 0 : _e.hostname) !== null && _f !== void 0 ? _f : (_g = window === null || window === void 0 ? void 0 : window.location) === null || _g === void 0 ? void 0 : _g.hostname,
4888
4934
  };
4889
4935
  },
4890
4936
  enumerable: false,
@@ -5382,6 +5428,7 @@ var Cipher = /** @class */ (function () {
5382
5428
  if (typeof cipherText === 'string') {
5383
5429
  cipherText = JSON.parse(cipherText);
5384
5430
  }
5431
+ console.log('SDK::CipherService::decrypt::cipherText', cipherText);
5385
5432
  return [4 /*yield*/, decryptWithPrivateKey(decryptionKey, cipherText)];
5386
5433
  case 1:
5387
5434
  decrypted = _c.sent();
@@ -5866,10 +5913,10 @@ var AuthService = /** @class */ (function (_super) {
5866
5913
  case 1:
5867
5914
  signatureMessageResponse = _b.sent();
5868
5915
  authentication = void 0;
5869
- _a = input.encryptionMechanism;
5916
+ _a = this.deviceAuthType;
5870
5917
  switch (_a) {
5871
- case exports.EncryptionMechanism.Passkey: return [3 /*break*/, 2];
5872
- case exports.EncryptionMechanism.Password: return [3 /*break*/, 4];
5918
+ case exports.AuthType.Passkey: return [3 /*break*/, 2];
5919
+ case exports.AuthType.Mfa: return [3 /*break*/, 4];
5873
5920
  }
5874
5921
  return [3 /*break*/, 6];
5875
5922
  case 2: return [4 /*yield*/, this.handleSignUpWithPasskey({
@@ -5911,10 +5958,10 @@ var AuthService = /** @class */ (function (_super) {
5911
5958
  return __generator(this, function (_b) {
5912
5959
  switch (_b.label) {
5913
5960
  case 0:
5914
- _a = input.encryptionMechanism;
5961
+ _a = this.deviceAuthType;
5915
5962
  switch (_a) {
5916
- case exports.EncryptionMechanism.Passkey: return [3 /*break*/, 1];
5917
- case exports.EncryptionMechanism.Password: return [3 /*break*/, 3];
5963
+ case exports.AuthType.Passkey: return [3 /*break*/, 1];
5964
+ case exports.AuthType.Mfa: return [3 /*break*/, 3];
5918
5965
  }
5919
5966
  return [3 /*break*/, 6];
5920
5967
  case 1:
@@ -6181,7 +6228,7 @@ var AuthService = /** @class */ (function (_super) {
6181
6228
  _e.label = 10;
6182
6229
  case 10: return [4 /*yield*/, this.request(AuthRoutes.signatureMessage, {
6183
6230
  method: AuthRoutes.signatureMessage.method,
6184
- payload: { clientAuthPubKey: devicePublicKey },
6231
+ payload: { clientAuthPubKey: devicePublicKey, },
6185
6232
  })];
6186
6233
  case 11:
6187
6234
  response = _e.sent();