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

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,23 @@ 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
+ if (jwtDecoded.externalUserId !== userId) {
4842
+ return false;
4843
+ }
4844
+ return true;
4845
+ }
4846
+ function jwtIsSecure(jwt) {
4847
+ var jwtDecoded = jwtDecode.jwtDecode(jwt);
4848
+ if (!jwtDecoded.mfaVerified) {
4849
+ return false;
4850
+ }
4851
+ return true;
4852
+ }
4822
4853
  /**
4823
4854
  * Calculates the remaining time in milliseconds until a given JWT expires.
4824
4855
  *
@@ -4841,6 +4872,16 @@ var Base = /** @class */ (function () {
4841
4872
  this.userId = config.userId;
4842
4873
  this.clientAuthToken = (_a = config.clientAuthToken) !== null && _a !== void 0 ? _a : config === null || config === void 0 ? void 0 : config.jwt;
4843
4874
  this.options = config.options;
4875
+ this.request = this.request.bind(this);
4876
+ if (!jwtHasSameUser(this.clientAuthToken, this.userId)) {
4877
+ throw new Error('Client auth token does not match the user id. Blocking API call.');
4878
+ }
4879
+ if (!isTest && jwtIsSecure(this.clientAuthToken)) {
4880
+ this.deviceAuthType = exports.AuthType.Passkey;
4881
+ }
4882
+ else {
4883
+ this.deviceAuthType = exports.AuthType.Mfa;
4884
+ }
4844
4885
  }
4845
4886
  Object.defineProperty(Base.prototype, "deviceStorage", {
4846
4887
  /**
@@ -4868,7 +4909,7 @@ var Base = /** @class */ (function () {
4868
4909
  * @protected
4869
4910
  */
4870
4911
  get: function () {
4871
- return this.storageService.loadDeviceInformation();
4912
+ return __assign(__assign({}, this.storageService.loadDeviceInformation()), { deviceAuthType: this.deviceAuthType });
4872
4913
  },
4873
4914
  enumerable: false,
4874
4915
  configurable: true
@@ -4878,13 +4919,13 @@ var Base = /** @class */ (function () {
4878
4919
  * @private
4879
4920
  */
4880
4921
  get: function () {
4881
- var _a, _b, _c, _d, _e;
4922
+ var _a, _b, _c, _d, _e, _f, _g;
4882
4923
  return {
4883
4924
  apiKey: this.apiKey,
4884
4925
  baseUrl: this.baseUrl,
4885
4926
  environment: (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.environment) !== null && _b !== void 0 ? _b : defaultEnvironment,
4886
4927
  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,
4928
+ 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
4929
  };
4889
4930
  },
4890
4931
  enumerable: false,
@@ -5382,6 +5423,7 @@ var Cipher = /** @class */ (function () {
5382
5423
  if (typeof cipherText === 'string') {
5383
5424
  cipherText = JSON.parse(cipherText);
5384
5425
  }
5426
+ console.log('SDK::CipherService::decrypt::cipherText', cipherText);
5385
5427
  return [4 /*yield*/, decryptWithPrivateKey(decryptionKey, cipherText)];
5386
5428
  case 1:
5387
5429
  decrypted = _c.sent();
@@ -5866,10 +5908,10 @@ var AuthService = /** @class */ (function (_super) {
5866
5908
  case 1:
5867
5909
  signatureMessageResponse = _b.sent();
5868
5910
  authentication = void 0;
5869
- _a = input.encryptionMechanism;
5911
+ _a = this.deviceAuthType;
5870
5912
  switch (_a) {
5871
- case exports.EncryptionMechanism.Passkey: return [3 /*break*/, 2];
5872
- case exports.EncryptionMechanism.Password: return [3 /*break*/, 4];
5913
+ case exports.AuthType.Passkey: return [3 /*break*/, 2];
5914
+ case exports.AuthType.Mfa: return [3 /*break*/, 4];
5873
5915
  }
5874
5916
  return [3 /*break*/, 6];
5875
5917
  case 2: return [4 /*yield*/, this.handleSignUpWithPasskey({
@@ -5911,10 +5953,10 @@ var AuthService = /** @class */ (function (_super) {
5911
5953
  return __generator(this, function (_b) {
5912
5954
  switch (_b.label) {
5913
5955
  case 0:
5914
- _a = input.encryptionMechanism;
5956
+ _a = this.deviceAuthType;
5915
5957
  switch (_a) {
5916
- case exports.EncryptionMechanism.Passkey: return [3 /*break*/, 1];
5917
- case exports.EncryptionMechanism.Password: return [3 /*break*/, 3];
5958
+ case exports.AuthType.Passkey: return [3 /*break*/, 1];
5959
+ case exports.AuthType.Mfa: return [3 /*break*/, 3];
5918
5960
  }
5919
5961
  return [3 /*break*/, 6];
5920
5962
  case 1:
@@ -6181,7 +6223,7 @@ var AuthService = /** @class */ (function (_super) {
6181
6223
  _e.label = 10;
6182
6224
  case 10: return [4 /*yield*/, this.request(AuthRoutes.signatureMessage, {
6183
6225
  method: AuthRoutes.signatureMessage.method,
6184
- payload: { clientAuthPubKey: devicePublicKey },
6226
+ payload: { clientAuthPubKey: devicePublicKey, },
6185
6227
  })];
6186
6228
  case 11:
6187
6229
  response = _e.sent();