wallaby-cash 1.7.23 → 1.7.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -3861,6 +3861,54 @@ exports.SeedPhraseType = void 0;
3861
3861
  SeedPhraseType["Algorand"] = "algorand";
3862
3862
  })(exports.SeedPhraseType || (exports.SeedPhraseType = {}));
3863
3863
 
3864
+ exports.ErrorResponseCodes = void 0;
3865
+ (function (ErrorResponseCodes) {
3866
+ // Request Payload
3867
+ ErrorResponseCodes["request_payload_missing"] = "request_payload_missing";
3868
+ ErrorResponseCodes["request_payload_wrong_format"] = "request_payload_wrong_format";
3869
+ // Auth API Key
3870
+ ErrorResponseCodes["auth_api_key_invalid"] = "auth_api_key_invalid";
3871
+ ErrorResponseCodes["auth_api_key_not_active"] = "auth_api_key_not_active";
3872
+ ErrorResponseCodes["auth_api_key_pub_key_not_set"] = "auth_api_key_pub_key_not_set";
3873
+ ErrorResponseCodes["auth_api_key_not_provided"] = "auth_api_key_not_provided";
3874
+ ErrorResponseCodes["auth_api_key_not_found"] = "auth_api_key_not_found";
3875
+ // Auth Origin
3876
+ ErrorResponseCodes["auth_origin_not_allowed"] = "auth_origin_not_allowed";
3877
+ // Auth API JWT
3878
+ ErrorResponseCodes["auth_api_jwt_invalid"] = "auth_api_jwt_invalid";
3879
+ ErrorResponseCodes["auth_api_jwt_not_active"] = "auth_api_jwt_not_active";
3880
+ ErrorResponseCodes["auth_api_jwt_not_provided"] = "auth_api_jwt_not_provided";
3881
+ // Auth Client JWT
3882
+ ErrorResponseCodes["auth_client_jwt_invalid"] = "auth_client_jwt_invalid";
3883
+ ErrorResponseCodes["auth_client_jwt_missing_external_id_payload"] = "auth_client_jwt_missing_external_id_payload";
3884
+ ErrorResponseCodes["auth_client_jwt_missing_exp_payload"] = "auth_client_jwt_missing_exp_payload";
3885
+ ErrorResponseCodes["auth_client_jwt_external_id_not_match"] = "auth_client_jwt_external_id_not_match";
3886
+ ErrorResponseCodes["auth_client_jwt_expired"] = "auth_client_jwt_expired";
3887
+ ErrorResponseCodes["auth_client_jwt_not_provided"] = "auth_client_jwt_not_provided";
3888
+ // Auth Client Transport keys
3889
+ ErrorResponseCodes["auth_client_pub_key_and_message_not_match"] = "auth_client_pub_key_and_message_not_match";
3890
+ ErrorResponseCodes["auth_client_pub_key_and_message_expired"] = "auth_client_pub_key_and_message_expired";
3891
+ ErrorResponseCodes["auth_client_pub_key_and_message_signature_failed"] = "auth_client_pub_key_and_message_signature_failed";
3892
+ ErrorResponseCodes["auth_client_pub_key_not_found"] = "auth_client_pub_key_not_found";
3893
+ // Auth User's Permission
3894
+ ErrorResponseCodes["auth_user_not_allowed_to_perform_the_action"] = "auth_user_not_allowed_to_perform_the_action";
3895
+ ErrorResponseCodes["multisig_participant_not_found"] = "multisig_participant_not_found";
3896
+ // Wallet
3897
+ ErrorResponseCodes["wallet_not_found"] = "wallet_not_found";
3898
+ // Asset
3899
+ ErrorResponseCodes["asset_not_found"] = "asset_not_found";
3900
+ // Seedphrase
3901
+ ErrorResponseCodes["seedphrase_could_not_be_decrypted"] = "seedphrase_could_not_be_decrypted";
3902
+ // User
3903
+ ErrorResponseCodes["user_already_exists"] = "user_already_exists";
3904
+ ErrorResponseCodes["user_not_found"] = "user_not_found";
3905
+ // OTP
3906
+ ErrorResponseCodes["otp_code_invalid"] = "otp_code_invalid";
3907
+ ErrorResponseCodes["otp_code_expired"] = "otp_code_expired";
3908
+ // Merchant
3909
+ ErrorResponseCodes["merchant_not_found"] = "merchant_not_found";
3910
+ })(exports.ErrorResponseCodes || (exports.ErrorResponseCodes = {}));
3911
+
3864
3912
  const global$1 = (typeof global !== "undefined" ? global :
3865
3913
  typeof self !== "undefined" ? self :
3866
3914
  typeof window !== "undefined" ? window : {});
@@ -5011,36 +5059,47 @@ var Auth = /** @class */ (function (_super) {
5011
5059
  * Authenticates a user by either signing them in or signing them up based on the presence of existing credentials.
5012
5060
  *
5013
5061
  * @param { string } password - The user's password.
5062
+ * @param { string } [wallabyUserId] - The user's Wallaby ID if available
5014
5063
  * @returns {Promise<AuthResponse>} - A promise that resolves to the authentication response.
5015
5064
  */
5016
5065
  Auth.prototype.authenticate = function (_a) {
5017
5066
  return __awaiter(this, arguments, void 0, function (_b) {
5018
- var wallabyAuthPubKey, wallabyAccessToken, hasAccount, authentication;
5019
- var password = _b.password;
5020
- return __generator(this, function (_c) {
5021
- switch (_c.label) {
5067
+ var _c, credentials, authTokens, wallabyAuthPubKey, wallabyAccessToken, hasAccount, authentication, user, accessToken;
5068
+ var _this = this;
5069
+ var password = _b.password, wallabyUserId = _b.wallabyUserId;
5070
+ return __generator(this, function (_d) {
5071
+ switch (_d.label) {
5022
5072
  case 0: return [4 /*yield*/, this.device];
5023
5073
  case 1:
5024
- wallabyAuthPubKey = (_c.sent()).credentials.wallabyPublicKey;
5025
- return [4 /*yield*/, this.device];
5026
- case 2:
5027
- wallabyAccessToken = (_c.sent()).authTokens.accessToken;
5028
- hasAccount = !!wallabyAccessToken || !!wallabyAuthPubKey;
5029
- if (!hasAccount) return [3 /*break*/, 4];
5074
+ _c = _d.sent(), credentials = _c.credentials, authTokens = _c.authTokens;
5075
+ wallabyAuthPubKey = credentials.wallabyPublicKey;
5076
+ wallabyAccessToken = authTokens.accessToken;
5077
+ hasAccount = !!wallabyAccessToken || !!wallabyAuthPubKey || !!wallabyUserId;
5078
+ if (!hasAccount) return [3 /*break*/, 3];
5030
5079
  return [4 /*yield*/, this.signIn({ password: password })];
5031
- case 3:
5032
- authentication = _c.sent();
5033
- return [3 /*break*/, 6];
5034
- case 4: return [4 /*yield*/, this.signUp({ password: password })];
5080
+ case 2:
5081
+ authentication = _d.sent();
5082
+ return [3 /*break*/, 5];
5083
+ case 3: return [4 /*yield*/, this.signUp({ password: password }).catch(function (error) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
5084
+ switch (_a.label) {
5085
+ case 0: return [4 /*yield*/, this.handleSignUpError(error, password)];
5086
+ case 1: return [2 /*return*/, _a.sent()];
5087
+ }
5088
+ }); }); })];
5089
+ case 4:
5090
+ authentication = _d.sent();
5091
+ _d.label = 5;
5035
5092
  case 5:
5036
- authentication = _c.sent();
5037
- wallabyAuthPubKey = authentication === null || authentication === void 0 ? void 0 : authentication.user.wallabyAuthPubKey;
5038
- wallabyAccessToken = authentication === null || authentication === void 0 ? void 0 : authentication.accessToken;
5039
- _c.label = 6;
5040
- case 6:
5041
5093
  if (!authentication) {
5042
- throw new Error('Authentication failed, please try again.');
5094
+ throw new Error('Authentication failed: Unable to sign in or sign up. Please check your credentials and try again.');
5043
5095
  }
5096
+ user = authentication.user, accessToken = authentication.accessToken;
5097
+ return [4 /*yield*/, this.device];
5098
+ case 6:
5099
+ (_d.sent()).credentials.wallabyPublicKey = user.wallabyAuthPubKey;
5100
+ return [4 /*yield*/, this.device];
5101
+ case 7:
5102
+ (_d.sent()).authTokens.accessToken = accessToken;
5044
5103
  return [2 /*return*/, authentication];
5045
5104
  }
5046
5105
  });
@@ -5311,6 +5370,33 @@ var Auth = /** @class */ (function (_super) {
5311
5370
  });
5312
5371
  });
5313
5372
  };
5373
+ Auth.prototype.handleSignUpError = function (error, password) {
5374
+ return __awaiter(this, void 0, void 0, function () {
5375
+ var userAlreadyExists, signInError_1;
5376
+ var _a;
5377
+ return __generator(this, function (_b) {
5378
+ switch (_b.label) {
5379
+ case 0:
5380
+ userAlreadyExists = (error === null || error === void 0 ? void 0 : error.errorCode) === exports.ErrorResponseCodes.user_already_exists || ((_a = error === null || error === void 0 ? void 0 : error.message) === null || _a === void 0 ? void 0 : _a.match(/User already exists/i));
5381
+ if (!userAlreadyExists) return [3 /*break*/, 5];
5382
+ _b.label = 1;
5383
+ case 1:
5384
+ _b.trys.push([1, 3, , 4]);
5385
+ return [4 /*yield*/, this.signIn({ password: password })];
5386
+ case 2: return [2 /*return*/, _b.sent()];
5387
+ case 3:
5388
+ signInError_1 = _b.sent();
5389
+ logger.error('SDK::Auth::handleSignUpError::secondAttemptToSignIn::error', signInError_1);
5390
+ throw signInError_1;
5391
+ case 4: return [3 /*break*/, 6];
5392
+ case 5:
5393
+ logger.error('SDK::Auth::handleSignUpError::error', error);
5394
+ throw error;
5395
+ case 6: return [2 /*return*/];
5396
+ }
5397
+ });
5398
+ });
5399
+ };
5314
5400
  return Auth;
5315
5401
  }(Base));
5316
5402
 
@@ -5500,12 +5586,12 @@ var Wallet = /** @class */ (function (_super) {
5500
5586
  Wallet.prototype.create = function (_a) {
5501
5587
  return __awaiter(this, arguments, void 0, function (_b) {
5502
5588
  var authentication, signatureMessage, wallabyAuthPubKey, message, signature, clientAuthPubKey, decryptedClientAuthPrivKey, response, decryptedSeedPhrase, encryptedSeedPhraseWithWallabyKey, mnemonicSeedPhrase, convertedEncryptedSeed, decryptedMnemonicSeedPhrase, error_5;
5503
- var password = _b.password;
5589
+ var password = _b.password, wallabyUserId = _b.wallabyUserId;
5504
5590
  return __generator(this, function (_c) {
5505
5591
  switch (_c.label) {
5506
5592
  case 0:
5507
5593
  _c.trys.push([0, 9, , 10]);
5508
- return [4 /*yield*/, this.auth.authenticate({ password: password })];
5594
+ return [4 /*yield*/, this.auth.authenticate({ password: password, wallabyUserId: wallabyUserId })];
5509
5595
  case 1:
5510
5596
  authentication = _c.sent();
5511
5597
  return [4 /*yield*/, this.auth.signatureMessage({ password: password })];
@@ -5660,18 +5746,19 @@ var Wallet = /** @class */ (function (_super) {
5660
5746
  * Import an existing wallet, returns asset list and encrypted seedPhrase
5661
5747
  * @param {string} password The user's chosen password
5662
5748
  * @param {string} seedPhrase The user's seed phrase
5749
+ * @param {string} [wallabyUserId] The user's wallaby user ID if available
5663
5750
  * @returns {ImportWalletResponse} The wallet has been imported successfully
5664
5751
  * The return includes the wallet, wallet assets, and the encrypted seedphrase
5665
5752
  */
5666
5753
  Wallet.prototype.import = function (_a) {
5667
5754
  return __awaiter(this, arguments, void 0, function (_b) {
5668
5755
  var authentication, signatureMessage, message, signature, clientAuthPubKey, encryptedSeedphraseWithWallabyKey, response, error_7;
5669
- var password = _b.password, seedPhrase = _b.seedPhrase;
5756
+ var password = _b.password, seedPhrase = _b.seedPhrase, wallabyUserId = _b.wallabyUserId;
5670
5757
  return __generator(this, function (_c) {
5671
5758
  switch (_c.label) {
5672
5759
  case 0:
5673
5760
  _c.trys.push([0, 6, , 7]);
5674
- return [4 /*yield*/, this.auth.authenticate({ password: password })];
5761
+ return [4 /*yield*/, this.auth.authenticate({ password: password, wallabyUserId: wallabyUserId })];
5675
5762
  case 1:
5676
5763
  authentication = _c.sent();
5677
5764
  return [4 /*yield*/, this.auth.signatureMessage({ password: password })];
@@ -7226,13 +7313,16 @@ var Transactions = /** @class */ (function (_super) {
7226
7313
  Transactions.prototype.createAllowance = function (_a) {
7227
7314
  return __awaiter(this, arguments, void 0, function (_b) {
7228
7315
  var signatureMessage, transportSeedPhrase, message, signature, clientAuthPubKey, response, error_5;
7229
- var password = _b.password, ownerAddress = _b.ownerAddress, spenderAddress = _b.spenderAddress, amount = _b.amount, assetId = _b.assetId, suiObjectId = _b.suiObjectId, contractAddress = _b.contractAddress, reference = _b.reference, memo = _b.memo;
7316
+ var password = _b.password, 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;
7230
7317
  return __generator(this, function (_c) {
7231
7318
  switch (_c.label) {
7232
7319
  case 0:
7233
7320
  _c.trys.push([0, 4, , 5]);
7234
- if ((!suiObjectId && !contractAddress) || (!!suiObjectId && !!contractAddress)) {
7235
- throw new Error('Either `suiObjectId` or `contractAddress` are required for this transaction.');
7321
+ if (!suiObjectId && !contractAddress && !assetId && !assetSymbol && !chainName) {
7322
+ throw new Error("AssetId, asset symbol, chain name or contract address must be provided.");
7323
+ }
7324
+ if ((assetSymbol && !chainName) || (!assetSymbol && chainName)) {
7325
+ throw new Error("Asset symbol and chain name must be provided when asset is not in user wallet.");
7236
7326
  }
7237
7327
  return [4 /*yield*/, this.auth.signatureMessage({ password: password })];
7238
7328
  case 1:
@@ -7250,6 +7340,8 @@ var Transactions = /** @class */ (function (_super) {
7250
7340
  encryptedSeed: transportSeedPhrase,
7251
7341
  ownerAddress: ownerAddress,
7252
7342
  spenderAddress: spenderAddress,
7343
+ chainName: chainName,
7344
+ assetSymbol: assetSymbol,
7253
7345
  amount: amount,
7254
7346
  assetId: assetId,
7255
7347
  contractAddress: contractAddress !== null && contractAddress !== void 0 ? contractAddress : suiObjectId,