wallaby-cash 1.7.7 → 1.7.8

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
@@ -5238,6 +5238,11 @@ var WalletRoutes = {
5238
5238
  method: exports.RequestMethod.Get,
5239
5239
  requiresAccessToken: true,
5240
5240
  },
5241
+ addTokenToWallet: {
5242
+ fullPath: '/users/assets/add',
5243
+ method: exports.RequestMethod.Post,
5244
+ requiresAccessToken: true,
5245
+ },
5241
5246
  getUserWallets: {
5242
5247
  fullPath: function (_a) {
5243
5248
  var userId = _a.userId;
@@ -5323,6 +5328,11 @@ var SystemRoutes = {
5323
5328
  method: exports.RequestMethod.Get,
5324
5329
  requiresAccessToken: false,
5325
5330
  },
5331
+ fetchTokenInfo: {
5332
+ fullPath: function () { return "/query/fetch-token-info"; },
5333
+ method: exports.RequestMethod.Get,
5334
+ requiresAccessToken: false,
5335
+ },
5326
5336
  };
5327
5337
 
5328
5338
  var Auth = /** @class */ (function (_super) {
@@ -5640,6 +5650,25 @@ var Auth = /** @class */ (function (_super) {
5640
5650
  return Auth;
5641
5651
  }(Base));
5642
5652
 
5653
+ /**
5654
+ * Sanitizes a Sui object ID by removing any part of the string after '::'.
5655
+ *
5656
+ * @param objectId - The Sui object ID to sanitize. Example input: "0xc91acfb75009c5ff2fd57c54f3caaee12ad1fbe997681334adc0b574fc277a07::icorgi::ICORGI"
5657
+ * @returns The sanitized Sui object ID. Example output: "0xc91acfb75009c5ff2fd57c54f3caaee12ad1fbe997681334adc0b574fc277a07"
5658
+ */
5659
+ var sanitizeSuiObjectId = function (objectId) {
5660
+ if (!objectId) {
5661
+ throw new Error('Sui object ID is required');
5662
+ }
5663
+ if (!objectId.startsWith('0x')) {
5664
+ throw new Error('Invalid Sui object ID');
5665
+ }
5666
+ if (!objectId.includes('::')) {
5667
+ return objectId;
5668
+ }
5669
+ return objectId.split('::')[0];
5670
+ };
5671
+
5643
5672
  var Wallet = /** @class */ (function (_super) {
5644
5673
  __extends(Wallet, _super);
5645
5674
  function Wallet(config) {
@@ -6413,9 +6442,54 @@ var Wallet = /** @class */ (function (_super) {
6413
6442
  });
6414
6443
  });
6415
6444
  };
6445
+ Wallet.prototype.addTokenToWallet = function (_a) {
6446
+ return __awaiter(this, arguments, void 0, function (_b) {
6447
+ var contractAddress, response, error_16;
6448
+ var assetConfigId = _b.assetConfigId, walletId = _b.walletId, userId = _b.userId, config = _b.config;
6449
+ return __generator(this, function (_c) {
6450
+ switch (_c.label) {
6451
+ case 0:
6452
+ _c.trys.push([0, 2, , 3]);
6453
+ if (!assetConfigId || !walletId || !userId || !config) {
6454
+ throw new Error('Missing required parameters');
6455
+ }
6456
+ if (!assetConfigId && !config) {
6457
+ throw new Error('Either assetConfigId or config is required');
6458
+ }
6459
+ contractAddress = config.contractAddress;
6460
+ if (config.chainName === exports.BlockchainName.Sui) {
6461
+ if (!config.suiObjectId || !!config.contractAddress) {
6462
+ throw new Error('`suiObjectId` instead of `contractAddress` is required for Sui chain');
6463
+ }
6464
+ contractAddress = sanitizeSuiObjectId(config.suiObjectId);
6465
+ }
6466
+ return [4 /*yield*/, this.request(WalletRoutes.addTokenToWallet, {
6467
+ method: WalletRoutes.addTokenToWallet.method,
6468
+ payload: {
6469
+ assetConfigId: assetConfigId,
6470
+ walletId: walletId,
6471
+ userId: userId,
6472
+ config: __assign(__assign({}, config), { contractAddress: contractAddress }),
6473
+ },
6474
+ })];
6475
+ case 1:
6476
+ response = _c.sent();
6477
+ if (!response || response.errors) {
6478
+ throw new Error(response.errors);
6479
+ }
6480
+ return [2 /*return*/, response];
6481
+ case 2:
6482
+ error_16 = _c.sent();
6483
+ logger('SDK::Wallet::addTokenToWallet::error', error_16);
6484
+ return [2 /*return*/, Promise.reject(error_16)];
6485
+ case 3: return [2 /*return*/];
6486
+ }
6487
+ });
6488
+ });
6489
+ };
6416
6490
  Wallet.prototype.initRecoveryFlow = function (_a) {
6417
6491
  return __awaiter(this, arguments, void 0, function (_b) {
6418
- var initRecovery, error_16;
6492
+ var initRecovery, error_17;
6419
6493
  var clientAuthPubKey = _b.clientAuthPubKey;
6420
6494
  return __generator(this, function (_c) {
6421
6495
  switch (_c.label) {
@@ -6435,9 +6509,9 @@ var Wallet = /** @class */ (function (_super) {
6435
6509
  }
6436
6510
  return [2 /*return*/, { signatureMessage: initRecovery.signatureMessage, wallabyAuthPubKey: initRecovery.wallabyAuthPubKey }];
6437
6511
  case 2:
6438
- error_16 = _c.sent();
6439
- logger('SDK::Wallet::initRecoveryFlow::error', error_16);
6440
- return [2 /*return*/, Promise.reject(error_16)];
6512
+ error_17 = _c.sent();
6513
+ logger('SDK::Wallet::initRecoveryFlow::error', error_17);
6514
+ return [2 /*return*/, Promise.reject(error_17)];
6441
6515
  case 3: return [2 /*return*/];
6442
6516
  }
6443
6517
  });
@@ -6957,6 +7031,95 @@ var System = /** @class */ (function (_super) {
6957
7031
  });
6958
7032
  });
6959
7033
  };
7034
+ /**
7035
+ * Validates the contract address or SUI object ID for a given blockchain.
7036
+ *
7037
+ * @public
7038
+ * @param {BlockchainName} blockchain - The name of the blockchain.
7039
+ * @param {string} contractAddress - The contract address (optional for SUI blockchain).
7040
+ * @param {string} suiObjectId - The SUI object ID (optional for SUI blockchain).
7041
+ *
7042
+ * @returns {string} The validated contract address or SUI object ID.
7043
+ *
7044
+ * @throws Will throw an error if both `contractAddress` and `suiObjectId` are provided for SUI blockchain.
7045
+ * @throws Will throw an error if neither `contractAddress` nor `suiObjectId` are provided for SUI blockchain.
7046
+ * @throws Will throw an error if `contractAddress` is not provided for non-SUI blockchains.
7047
+ * @throws Will throw an error if the blockchain is not supported.
7048
+ */
7049
+ System.prototype.validateContractAddress = function (_a) {
7050
+ var blockchain = _a.blockchain, contractAddress = _a.contractAddress, suiObjectId = _a.suiObjectId;
7051
+ switch (blockchain) {
7052
+ case exports.BlockchainName.Algorand:
7053
+ case exports.BlockchainName.Bitcoin:
7054
+ throw new Error('This blockchain is not supported');
7055
+ case exports.BlockchainName.Sui:
7056
+ if (suiObjectId && contractAddress) {
7057
+ throw new Error('You can only provide either suiObjectId or contractAddress');
7058
+ }
7059
+ if (contractAddress) {
7060
+ throw new Error('You can only provide suiObjectId for SUI blockchain');
7061
+ }
7062
+ if (!suiObjectId) {
7063
+ throw new Error('You must provide suiObjectId for SUI blockchain');
7064
+ }
7065
+ return sanitizeSuiObjectId(suiObjectId);
7066
+ default:
7067
+ if (!contractAddress) {
7068
+ throw new Error('You must provide contractAddress for non-SUI blockchains');
7069
+ }
7070
+ return contractAddress;
7071
+ }
7072
+ };
7073
+ /**
7074
+ * Fetches token information for a given blockchain and contract address or SUI object ID.
7075
+ *
7076
+ * @public
7077
+ * @param {BlockchainName} blockchain - The name of the blockchain.
7078
+ * @param {string} contractAddress - The contract address of the token (optional for non-SUI blockchains).
7079
+ * @param {string} suiObjectId - The SUI object ID of the token (optional for SUI blockchain).
7080
+ *
7081
+ * @returns {Promise<{ decimals: number; symbol: string; name: string; tokenContractAddress: string }>} A promise that resolves to an object containing token information.
7082
+ *
7083
+ * @throws Will throw an error if both `contractAddress` and `suiObjectId` are provided for SUI blockchain.
7084
+ * @throws Will throw an error if neither `contractAddress` nor `suiObjectId` are provided for SUI blockchain.
7085
+ * @throws Will throw an error if `contractAddress` is not provided for non-SUI blockchains.
7086
+ * @throws Will throw an error if the response is invalid or contains an error.
7087
+ */
7088
+ System.prototype.fetchTokenInfo = function (_a) {
7089
+ return __awaiter(this, arguments, void 0, function (_b) {
7090
+ var validatedContractAddress, response, error_2;
7091
+ var blockchain = _b.blockchain, contractAddress = _b.contractAddress, suiObjectId = _b.suiObjectId;
7092
+ return __generator(this, function (_c) {
7093
+ switch (_c.label) {
7094
+ case 0:
7095
+ _c.trys.push([0, 2, , 3]);
7096
+ validatedContractAddress = this.validateContractAddress({
7097
+ blockchain: blockchain,
7098
+ contractAddress: contractAddress,
7099
+ suiObjectId: suiObjectId,
7100
+ });
7101
+ return [4 /*yield*/, this.request(SystemRoutes.fetchTokenInfo, {
7102
+ method: SystemRoutes.fetchTokenInfo.method,
7103
+ queryParams: {
7104
+ chainName: blockchain,
7105
+ tokenContractAddress: validatedContractAddress,
7106
+ },
7107
+ })];
7108
+ case 1:
7109
+ response = _c.sent();
7110
+ if (!response || response.error) {
7111
+ throw new Error(response);
7112
+ }
7113
+ return [2 /*return*/, response];
7114
+ case 2:
7115
+ error_2 = _c.sent();
7116
+ logger('SDK::Wallet::fetchTokenInfo::error', error_2);
7117
+ return [2 /*return*/, Promise.reject(error_2)];
7118
+ case 3: return [2 /*return*/];
7119
+ }
7120
+ });
7121
+ });
7122
+ };
6960
7123
  /**
6961
7124
  * @public
6962
7125
  * Get all supported assets configuration
@@ -6965,7 +7128,7 @@ var System = /** @class */ (function (_super) {
6965
7128
  */
6966
7129
  System.prototype.getSupportedTokens = function () {
6967
7130
  return __awaiter(this, void 0, void 0, function () {
6968
- var response, error_2;
7131
+ var response, error_3;
6969
7132
  return __generator(this, function (_a) {
6970
7133
  switch (_a.label) {
6971
7134
  case 0:
@@ -6981,9 +7144,9 @@ var System = /** @class */ (function (_super) {
6981
7144
  }
6982
7145
  return [2 /*return*/, response.assets];
6983
7146
  case 2:
6984
- error_2 = _a.sent();
6985
- logger('SDK::System::getSupportedTokens::error', error_2);
6986
- return [2 /*return*/, Promise.reject(error_2)];
7147
+ error_3 = _a.sent();
7148
+ logger('SDK::System::getSupportedTokens::error', error_3);
7149
+ return [2 /*return*/, Promise.reject(error_3)];
6987
7150
  case 3: return [2 /*return*/];
6988
7151
  }
6989
7152
  });
@@ -6996,7 +7159,7 @@ var System = /** @class */ (function (_super) {
6996
7159
  */
6997
7160
  System.prototype.getUserData = function (userId) {
6998
7161
  return __awaiter(this, void 0, void 0, function () {
6999
- var response, error_3;
7162
+ var response, error_4;
7000
7163
  return __generator(this, function (_a) {
7001
7164
  switch (_a.label) {
7002
7165
  case 0:
@@ -7012,9 +7175,9 @@ var System = /** @class */ (function (_super) {
7012
7175
  }
7013
7176
  return [2 /*return*/, response.user];
7014
7177
  case 2:
7015
- error_3 = _a.sent();
7016
- logger('SDK::System::getUserData::error', error_3);
7017
- return [2 /*return*/, Promise.reject(error_3)];
7178
+ error_4 = _a.sent();
7179
+ logger('SDK::System::getUserData::error', error_4);
7180
+ return [2 /*return*/, Promise.reject(error_4)];
7018
7181
  case 3: return [2 /*return*/];
7019
7182
  }
7020
7183
  });
@@ -7028,7 +7191,7 @@ var System = /** @class */ (function (_super) {
7028
7191
  */
7029
7192
  System.prototype.getUserByExternalUserId = function (externalUserId) {
7030
7193
  return __awaiter(this, void 0, void 0, function () {
7031
- var response, error_4;
7194
+ var response, error_5;
7032
7195
  return __generator(this, function (_a) {
7033
7196
  switch (_a.label) {
7034
7197
  case 0:
@@ -7044,9 +7207,9 @@ var System = /** @class */ (function (_super) {
7044
7207
  }
7045
7208
  return [2 /*return*/, response.user];
7046
7209
  case 2:
7047
- error_4 = _a.sent();
7048
- logger('SDK::System::getUserByExternalUserId::error', error_4);
7049
- return [2 /*return*/, Promise.reject(error_4)];
7210
+ error_5 = _a.sent();
7211
+ logger('SDK::System::getUserByExternalUserId::error', error_5);
7212
+ return [2 /*return*/, Promise.reject(error_5)];
7050
7213
  case 3: return [2 /*return*/];
7051
7214
  }
7052
7215
  });
@@ -7153,7 +7316,7 @@ var Transactions = /** @class */ (function (_super) {
7153
7316
  */
7154
7317
  Transactions.prototype.transfer = function (_a) {
7155
7318
  return __awaiter(this, arguments, void 0, function (_b) {
7156
- var signatureMessage, transportSeedphrase, message, signature, clientAuthPubKey, response, error_2;
7319
+ var signatureMessage, transportSeedPhrase, message, signature, clientAuthPubKey, response, error_2;
7157
7320
  var originAddress = _b.originAddress, recipientAddress = _b.recipientAddress, amount = _b.amount, assetId = _b.assetId, reference = _b.reference, memo = _b.memo, password = _b.password;
7158
7321
  return __generator(this, function (_c) {
7159
7322
  switch (_c.label) {
@@ -7164,7 +7327,7 @@ var Transactions = /** @class */ (function (_super) {
7164
7327
  signatureMessage = _c.sent();
7165
7328
  return [4 /*yield*/, this.utils.prepSeedPhraseForTransport({ password: password })];
7166
7329
  case 2:
7167
- transportSeedphrase = _c.sent();
7330
+ transportSeedPhrase = _c.sent();
7168
7331
  message = signatureMessage.message, signature = signatureMessage.signature, clientAuthPubKey = signatureMessage.clientAuthPubKey;
7169
7332
  return [4 /*yield*/, this.request(TransactionsRoutes.transfer, {
7170
7333
  method: TransactionsRoutes.transfer.method,
@@ -7172,7 +7335,7 @@ var Transactions = /** @class */ (function (_super) {
7172
7335
  message: message,
7173
7336
  signature: signature,
7174
7337
  clientAuthPubKey: clientAuthPubKey,
7175
- encryptedSeed: transportSeedphrase,
7338
+ encryptedSeed: transportSeedPhrase,
7176
7339
  originAddress: originAddress,
7177
7340
  recipientAddress: recipientAddress,
7178
7341
  assetId: assetId,
@@ -7283,6 +7446,7 @@ var Transactions = /** @class */ (function (_super) {
7283
7446
  * @param {string} amount
7284
7447
  * @param {string} assetId
7285
7448
  * @param {string} contractAddress
7449
+ * @param {string} suiObjectId
7286
7450
  * @param {string} reference
7287
7451
  * @param {string} memo
7288
7452
  * @returns {CreateAllowanceResponse}
@@ -7290,18 +7454,21 @@ var Transactions = /** @class */ (function (_super) {
7290
7454
  */
7291
7455
  Transactions.prototype.createAllowance = function (_a) {
7292
7456
  return __awaiter(this, arguments, void 0, function (_b) {
7293
- var signatureMessage, transportSeedphrase, message, signature, clientAuthPubKey, response, error_5;
7294
- var password = _b.password, ownerAddress = _b.ownerAddress, spenderAddress = _b.spenderAddress, amount = _b.amount, assetId = _b.assetId, contractAddress = _b.contractAddress, reference = _b.reference, memo = _b.memo;
7457
+ var signatureMessage, transportSeedPhrase, message, signature, clientAuthPubKey, response, error_5;
7458
+ 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;
7295
7459
  return __generator(this, function (_c) {
7296
7460
  switch (_c.label) {
7297
7461
  case 0:
7298
7462
  _c.trys.push([0, 4, , 5]);
7463
+ if (!suiObjectId || !contractAddress || (!!suiObjectId && !!contractAddress)) {
7464
+ throw new Error('Either `suiObjectId` or `contractAddress` are required for this transaction.');
7465
+ }
7299
7466
  return [4 /*yield*/, this.auth.signatureMessage({ password: password })];
7300
7467
  case 1:
7301
7468
  signatureMessage = _c.sent();
7302
7469
  return [4 /*yield*/, this.utils.prepSeedPhraseForTransport({ password: password })];
7303
7470
  case 2:
7304
- transportSeedphrase = _c.sent();
7471
+ transportSeedPhrase = _c.sent();
7305
7472
  message = signatureMessage.message, signature = signatureMessage.signature, clientAuthPubKey = signatureMessage.clientAuthPubKey;
7306
7473
  return [4 /*yield*/, this.request(TransactionsRoutes.createAllowance, {
7307
7474
  method: TransactionsRoutes.createAllowance.method,
@@ -7309,12 +7476,12 @@ var Transactions = /** @class */ (function (_super) {
7309
7476
  message: message,
7310
7477
  signature: signature,
7311
7478
  clientAuthPubKey: clientAuthPubKey,
7312
- encryptedSeed: transportSeedphrase,
7479
+ encryptedSeed: transportSeedPhrase,
7313
7480
  ownerAddress: ownerAddress,
7314
7481
  spenderAddress: spenderAddress,
7315
7482
  amount: amount,
7316
7483
  assetId: assetId,
7317
- contractAddress: contractAddress,
7484
+ contractAddress: contractAddress !== null && contractAddress !== void 0 ? contractAddress : suiObjectId,
7318
7485
  reference: reference,
7319
7486
  memo: memo,
7320
7487
  },