@reactmore/crypto-wallet-sdk 1.2.0 → 1.3.1

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.
@@ -825,38 +825,50 @@ var EvmWallet = /*#__PURE__*/function (_BaseWallet) {
825
825
  }();
826
826
  _proto.generateWallet = /*#__PURE__*/function () {
827
827
  var _generateWallet = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(_ref2) {
828
- var mnemonic, derivationPath, hdPath, getMnemonic, derivePrivateKey, _yield$this$wallet$ge, address, publicKey, _t2;
828
+ var mnemonic, privateKey, derivationPath, hdPath, derivePrivateKey, _yield$this$wallet$ge, address, publicKey;
829
829
  return _regenerator().w(function (_context2) {
830
830
  while (1) switch (_context2.n) {
831
831
  case 0:
832
- mnemonic = _ref2.mnemonic, derivationPath = _ref2.derivationPath;
832
+ mnemonic = _ref2.mnemonic, privateKey = _ref2.privateKey, derivationPath = _ref2.derivationPath;
833
833
  hdPath = derivationPath || "m/44'/60'/0'/0/0";
834
- if (!(mnemonic != null)) {
834
+ if (!(mnemonic && privateKey)) {
835
835
  _context2.n = 1;
836
836
  break;
837
837
  }
838
- _t2 = mnemonic;
839
- _context2.n = 3;
840
- break;
838
+ throw new Error("Provide either mnemonic or privateKey, not both");
841
839
  case 1:
842
- _context2.n = 2;
843
- return this.generateMnemonic(12);
840
+ if (!privateKey) {
841
+ _context2.n = 2;
842
+ break;
843
+ }
844
+ derivePrivateKey = privateKey;
845
+ _context2.n = 6;
846
+ break;
844
847
  case 2:
845
- _t2 = _context2.v;
846
- case 3:
847
- getMnemonic = _t2;
848
- _context2.n = 4;
848
+ if (!mnemonic) {
849
+ _context2.n = 4;
850
+ break;
851
+ }
852
+ _context2.n = 3;
849
853
  return this.wallet.getDerivedPrivateKey({
850
- mnemonic: getMnemonic,
854
+ mnemonic: mnemonic,
851
855
  hdPath: hdPath
852
856
  });
853
- case 4:
857
+ case 3:
854
858
  derivePrivateKey = _context2.v;
859
+ _context2.n = 6;
860
+ break;
861
+ case 4:
855
862
  _context2.n = 5;
863
+ return this.wallet.getRandomPrivateKey();
864
+ case 5:
865
+ derivePrivateKey = _context2.v;
866
+ case 6:
867
+ _context2.n = 7;
856
868
  return this.wallet.getNewAddress({
857
869
  privateKey: derivePrivateKey
858
870
  });
859
- case 5:
871
+ case 7:
860
872
  _yield$this$wallet$ge = _context2.v;
861
873
  address = _yield$this$wallet$ge.address;
862
874
  publicKey = _yield$this$wallet$ge.publicKey;
@@ -926,7 +938,7 @@ var EvmWallet = /*#__PURE__*/function (_BaseWallet) {
926
938
  }();
927
939
  _proto.transfer = /*#__PURE__*/function () {
928
940
  var _transfer = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(_ref4) {
929
- var privateKey, contractAddress, rpcUrl, args, _yield$this$getContra2, contract, providerInstance, gasFeeData, nonce, recipientAddress, prio, max, value, gasLimit, decimals, noFeeProvided, estimate, fee, signParams, signedTx, broadcast, _t3;
941
+ var privateKey, contractAddress, rpcUrl, args, _yield$this$getContra2, contract, providerInstance, gasFeeData, nonce, signer, recipientAddress, prio, max, txTo, txData, txValue, gasLimit, decimals, amount, noFeeProvided, estimate, fee, signParams, signedTx, broadcast, _t2, _t3, _t4, _t5, _t6;
930
942
  return _regenerator().w(function (_context4) {
931
943
  while (1) switch (_context4.n) {
932
944
  case 0:
@@ -943,6 +955,7 @@ var EvmWallet = /*#__PURE__*/function (_BaseWallet) {
943
955
  providerInstance = _yield$this$getContra2.providerInstance;
944
956
  gasFeeData = _yield$this$getContra2.gasFeeData;
945
957
  nonce = _yield$this$getContra2.nonce;
958
+ signer = _yield$this$getContra2.signer;
946
959
  _context4.n = 2;
947
960
  return this.wallet.validAddress({
948
961
  address: args.recipientAddress
@@ -953,7 +966,7 @@ var EvmWallet = /*#__PURE__*/function (_BaseWallet) {
953
966
  _context4.n = 3;
954
967
  break;
955
968
  }
956
- throw new Error("address not valid");
969
+ throw new Error("recipient address not valid");
957
970
  case 3:
958
971
  if (!(args.maxPriorityFeePerGas && args.maxFeePerGas)) {
959
972
  _context4.n = 4;
@@ -971,10 +984,10 @@ var EvmWallet = /*#__PURE__*/function (_BaseWallet) {
971
984
  _context4.n = 5;
972
985
  break;
973
986
  }
974
- throw new Error("Cannot use gasPrice with EIP-1559 fee fields");
987
+ throw new Error("Cannot mix gasPrice with EIP-1559 fields");
975
988
  case 5:
976
989
  if (!contractAddress) {
977
- _context4.n = 11;
990
+ _context4.n = 12;
978
991
  break;
979
992
  }
980
993
  if (contract) {
@@ -987,93 +1000,97 @@ var EvmWallet = /*#__PURE__*/function (_BaseWallet) {
987
1000
  return contract.decimals();
988
1001
  case 7:
989
1002
  decimals = _context4.v;
990
- value = parseAmount(args.amount.toString(), decimals);
1003
+ amount = parseAmount(args.amount.toString(), decimals);
1004
+ txData = contract["interface"].encodeFunctionData("transfer", [args.recipientAddress, amount]);
1005
+ txTo = contractAddress;
1006
+ txValue = 0n;
991
1007
  if (!args.gasLimit) {
992
1008
  _context4.n = 8;
993
1009
  break;
994
1010
  }
995
- _t3 = BigInt(args.gasLimit);
996
- _context4.n = 10;
1011
+ _t2 = BigInt(args.gasLimit);
1012
+ _context4.n = 11;
997
1013
  break;
998
1014
  case 8:
1015
+ _t3 = providerInstance;
999
1016
  _context4.n = 9;
1000
- return contract.transfer.estimateGas(args.recipientAddress, value);
1017
+ return signer.getAddress();
1001
1018
  case 9:
1002
- _t3 = _context4.v;
1019
+ _t4 = _context4.v;
1020
+ _t5 = contractAddress;
1021
+ _t6 = txData;
1022
+ _context4.n = 10;
1023
+ return _t3.estimateGas.call(_t3, {
1024
+ from: _t4,
1025
+ to: _t5,
1026
+ data: _t6
1027
+ });
1003
1028
  case 10:
1004
- gasLimit = _t3;
1005
- _context4.n = 12;
1006
- break;
1029
+ _t2 = _context4.v;
1007
1030
  case 11:
1008
- value = parseEther(args.amount.toString());
1009
- gasLimit = args.gasLimit ? BigInt(args.gasLimit) : 21000n;
1031
+ gasLimit = _t2;
1032
+ _context4.n = 13;
1033
+ break;
1010
1034
  case 12:
1011
- // DEFAULT FEE
1035
+ // ===== NATIVE TRANSFER =====
1036
+ txTo = args.recipientAddress;
1037
+ txValue = parseEther(args.amount.toString());
1038
+ txData = args.data ? ethers.ethers.hexlify(ethers.ethers.toUtf8Bytes(args.data)) : '0x';
1039
+ gasLimit = args.gasLimit ? BigInt(args.gasLimit) : 21000n;
1040
+ case 13:
1041
+ // =========================
1042
+ // AUTO ESTIMATE FEE
1043
+ // =========================
1012
1044
  noFeeProvided = !args.gasPrice && !args.maxFeePerGas && !args.maxPriorityFeePerGas;
1013
- if (!noFeeProvided) {
1014
- _context4.n = 17;
1045
+ if (!(noFeeProvided && !contractAddress)) {
1046
+ _context4.n = 16;
1015
1047
  break;
1016
1048
  }
1017
- _context4.n = 13;
1049
+ _context4.n = 14;
1018
1050
  return this.estimateGas({
1019
1051
  rpcUrl: rpcUrl != null ? rpcUrl : this.config.rpcUrl,
1020
- recipientAddress: args.recipientAddress,
1052
+ recipientAddress: txTo,
1021
1053
  amount: args.amount.toString(),
1022
- data: args.data
1054
+ data: txData !== '0x' ? txData : undefined
1023
1055
  });
1024
- case 13:
1056
+ case 14:
1025
1057
  estimate = _context4.v;
1026
1058
  gasLimit = BigInt(estimate.gasLimit);
1027
- // ===== LEGACY =====
1028
1059
  if (!(estimate.model === "LEGACY")) {
1029
1060
  _context4.n = 15;
1030
1061
  break;
1031
1062
  }
1032
- if (estimate.gasPrice) {
1033
- _context4.n = 14;
1034
- break;
1035
- }
1036
- throw new Error("LEGACY estimate missing gasPrice");
1037
- case 14:
1038
- args.gasPrice = estimate.gasPrice; // wei
1063
+ args.gasPrice = estimate.gasPrice;
1039
1064
  return _context4.a(2, this.transfer(_extends({
1040
1065
  privateKey: privateKey,
1041
1066
  contractAddress: contractAddress,
1042
1067
  rpcUrl: rpcUrl
1043
1068
  }, args)));
1044
1069
  case 15:
1045
- // ===== EIP-1559 =====
1046
1070
  fee = estimate.fees.regular;
1047
- if (!(!(fee != null && fee.maxFeePerGas) || !(fee != null && fee.maxPriorityFeePerGas))) {
1048
- _context4.n = 16;
1049
- break;
1050
- }
1051
- throw new Error("EIP1559 estimate missing fee fields");
1052
- case 16:
1053
1071
  args.maxFeePerGas = fee.maxFeePerGas;
1054
1072
  args.maxPriorityFeePerGas = fee.maxPriorityFeePerGas;
1055
- case 17:
1056
- _context4.n = 18;
1073
+ case 16:
1074
+ _context4.n = 17;
1057
1075
  return this.buildSignParams({
1058
- args: _extends({}, args, {
1059
- privateKey: privateKey,
1060
- gasLimit: gasLimit
1061
- }),
1076
+ privateKey: privateKey,
1062
1077
  nonce: nonce,
1063
1078
  gasFeeData: gasFeeData,
1064
- recipientAddress: recipientAddress,
1065
- value: value,
1066
- contractAddress: contractAddress
1079
+ txTo: txTo,
1080
+ txData: txData,
1081
+ txValue: txValue,
1082
+ gasLimit: gasLimit,
1083
+ args: args
1067
1084
  });
1068
- case 18:
1085
+ case 17:
1069
1086
  signParams = _context4.v;
1070
- _context4.n = 19;
1087
+ _context4.n = 18;
1071
1088
  return this.wallet.signTransaction(signParams);
1072
- case 19:
1089
+ case 18:
1073
1090
  signedTx = _context4.v;
1074
- _context4.n = 20;
1091
+ _context4.n = 19;
1075
1092
  return providerInstance.broadcastTransaction(signedTx);
1076
- case 20:
1093
+ case 19:
1077
1094
  broadcast = _context4.v;
1078
1095
  return _context4.a(2, successResponse(_extends({}, broadcast)));
1079
1096
  }
@@ -1086,7 +1103,7 @@ var EvmWallet = /*#__PURE__*/function (_BaseWallet) {
1086
1103
  }();
1087
1104
  _proto.getTransaction = /*#__PURE__*/function () {
1088
1105
  var _getTransaction = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(_ref5) {
1089
- var hash, rpcUrl, withReceipt, _yield$this$getContra3, providerInstance, _yield$Promise$all, _tx, receipt, memo, tx, _t4;
1106
+ var hash, rpcUrl, withReceipt, _yield$this$getContra3, providerInstance, _yield$Promise$all, _tx, receipt, memo, tx, _t7;
1090
1107
  return _regenerator().w(function (_context5) {
1091
1108
  while (1) switch (_context5.p = _context5.n) {
1092
1109
  case 0:
@@ -1125,8 +1142,8 @@ var EvmWallet = /*#__PURE__*/function (_BaseWallet) {
1125
1142
  }));
1126
1143
  case 6:
1127
1144
  _context5.p = 6;
1128
- _t4 = _context5.v;
1129
- throw _t4;
1145
+ _t7 = _context5.v;
1146
+ throw _t7;
1130
1147
  case 7:
1131
1148
  return _context5.a(2);
1132
1149
  }
@@ -1186,7 +1203,7 @@ var EvmWallet = /*#__PURE__*/function (_BaseWallet) {
1186
1203
  _proto.smartContractCall = /*#__PURE__*/function () {
1187
1204
  var _smartContractCall = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(args) {
1188
1205
  var _args$rpcUrl;
1189
- var _yield$this$getContra5, contract, gasFeeData, nonce, tx, overrides, _t5;
1206
+ var _yield$this$getContra5, contract, gasFeeData, nonce, tx, overrides, _t8;
1190
1207
  return _regenerator().w(function (_context7) {
1191
1208
  while (1) switch (_context7.p = _context7.n) {
1192
1209
  case 0:
@@ -1237,8 +1254,8 @@ var EvmWallet = /*#__PURE__*/function (_BaseWallet) {
1237
1254
  }));
1238
1255
  case 7:
1239
1256
  _context7.p = 7;
1240
- _t5 = _context7.v;
1241
- throw _t5;
1257
+ _t8 = _context7.v;
1258
+ throw _t8;
1242
1259
  case 8:
1243
1260
  return _context7.a(2);
1244
1261
  }
@@ -1251,7 +1268,7 @@ var EvmWallet = /*#__PURE__*/function (_BaseWallet) {
1251
1268
  }();
1252
1269
  _proto.estimateGas = /*#__PURE__*/function () {
1253
1270
  var _estimateGas = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(_ref7) {
1254
- var rpcUrl, recipientAddress, amount, data, _yield$this$getContra6, providerInstance, _block$baseFeePerGas, _feeData$maxPriorityF, network, chainId, tx, _yield$Promise$all3, feeData, gasLimit, gasPrice, maxFeePerGas, maxPriorityFeePerGas, applyMultiplier, isEip1559, baseGasPrice, regularGasPrice, expressGasPrice, instantGasPrice, _regularFee, _expressFee, _instantFee, baseFee, priorityFee, block, regularPriority, regularMaxFee, expressPriority, expressMaxFee, instantPriority, instantMaxFee, MAX_GAS_GWEI, cap, regularFee, expressFee, instantFee, _t6;
1271
+ var rpcUrl, recipientAddress, amount, data, _yield$this$getContra6, providerInstance, _block$baseFeePerGas, _feeData$maxPriorityF, network, chainId, tx, _yield$Promise$all3, feeData, gasLimit, gasPrice, maxFeePerGas, maxPriorityFeePerGas, applyMultiplier, isEip1559, baseGasPrice, regularGasPrice, expressGasPrice, instantGasPrice, _regularFee, _expressFee, _instantFee, baseFee, priorityFee, block, regularPriority, regularMaxFee, expressPriority, expressMaxFee, instantPriority, instantMaxFee, MAX_GAS_GWEI, cap, regularFee, expressFee, instantFee, _t9;
1255
1272
  return _regenerator().w(function (_context8) {
1256
1273
  while (1) switch (_context8.p = _context8.n) {
1257
1274
  case 0:
@@ -1354,8 +1371,8 @@ var EvmWallet = /*#__PURE__*/function (_BaseWallet) {
1354
1371
  }));
1355
1372
  case 7:
1356
1373
  _context8.p = 7;
1357
- _t6 = _context8.v;
1358
- throw _t6;
1374
+ _t9 = _context8.v;
1375
+ throw _t9;
1359
1376
  case 8:
1360
1377
  return _context8.a(2);
1361
1378
  }
@@ -1368,56 +1385,57 @@ var EvmWallet = /*#__PURE__*/function (_BaseWallet) {
1368
1385
  }();
1369
1386
  _proto.buildSignParams = /*#__PURE__*/function () {
1370
1387
  var _buildSignParams = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(_ref8) {
1371
- var args, nonce, gasFeeData, recipientAddress, value, contractAddress, txBase, _t7, _t8, _t9, _t0, _t1, _t10, _t11, _t12;
1388
+ var _args$nonce, _args$maxPriorityFeeP, _args$maxFeePerGas;
1389
+ var privateKey, nonce, gasFeeData, txTo, txData, txValue, gasLimit, args, txBase, _t0, _t1, _t10, _t11, _t12, _t13, _t14;
1372
1390
  return _regenerator().w(function (_context9) {
1373
1391
  while (1) switch (_context9.n) {
1374
1392
  case 0:
1375
- args = _ref8.args, nonce = _ref8.nonce, gasFeeData = _ref8.gasFeeData, recipientAddress = _ref8.recipientAddress, value = _ref8.value, contractAddress = _ref8.contractAddress;
1376
- _t7 = _extends;
1377
- _t8 = recipientAddress.address;
1378
- _t9 = cryptoLib.BigNumber(value.toString());
1379
- _t0 = args.data ? ethers.ethers.hexlify(ethers.ethers.toUtf8Bytes(args.data)) : '0x';
1380
- _t1 = args.nonce;
1381
- if (_t1) {
1382
- _context9.n = 2;
1393
+ privateKey = _ref8.privateKey, nonce = _ref8.nonce, gasFeeData = _ref8.gasFeeData, txTo = _ref8.txTo, txData = _ref8.txData, txValue = _ref8.txValue, gasLimit = _ref8.gasLimit, args = _ref8.args;
1394
+ _t0 = txTo;
1395
+ _t1 = cryptoLib.BigNumber(txValue.toString());
1396
+ _t10 = txData;
1397
+ if (!((_args$nonce = args.nonce) != null)) {
1398
+ _context9.n = 1;
1383
1399
  break;
1384
1400
  }
1385
- _context9.n = 1;
1386
- return nonce;
1401
+ _t11 = _args$nonce;
1402
+ _context9.n = 3;
1403
+ break;
1387
1404
  case 1:
1388
- _t1 = _context9.v;
1405
+ _context9.n = 2;
1406
+ return nonce;
1389
1407
  case 2:
1390
- _t10 = _t1;
1391
- _t11 = args.gasLimit ? cryptoLib.BigNumber(args.gasLimit) : cryptoLib.BigNumber(21000);
1392
- _t12 = Number(this.currentChain.id);
1393
- txBase = _t7({
1394
- to: _t8,
1395
- value: _t9,
1396
- data: _t0,
1397
- nonce: _t10,
1398
- gasLimit: _t11,
1399
- chainId: _t12
1400
- }, contractAddress ? {
1401
- contractAddress: contractAddress
1402
- } : {});
1408
+ _t11 = _context9.v;
1409
+ case 3:
1410
+ _t12 = _t11;
1411
+ _t13 = cryptoLib.BigNumber(gasLimit.toString());
1412
+ _t14 = Number(this.currentChain.id);
1413
+ txBase = {
1414
+ to: _t0,
1415
+ value: _t1,
1416
+ data: _t10,
1417
+ nonce: _t12,
1418
+ gasLimit: _t13,
1419
+ chainId: _t14
1420
+ };
1403
1421
  if (!args.gasPrice) {
1404
- _context9.n = 3;
1422
+ _context9.n = 4;
1405
1423
  break;
1406
1424
  }
1407
1425
  return _context9.a(2, {
1408
- privateKey: args.privateKey,
1426
+ privateKey: privateKey,
1409
1427
  data: _extends({}, txBase, {
1410
1428
  gasPrice: cryptoLib.BigNumber(parseGwei(args.gasPrice).toString()),
1411
1429
  type: 0
1412
1430
  })
1413
1431
  });
1414
- case 3:
1432
+ case 4:
1415
1433
  return _context9.a(2, {
1416
- privateKey: args.privateKey,
1434
+ privateKey: privateKey,
1417
1435
  data: _extends({}, txBase, {
1418
1436
  type: 2,
1419
- maxPriorityFeePerGas: cryptoLib.BigNumber(args.maxPriorityFeePerGas ? args.maxPriorityFeePerGas : gasFeeData.maxPriorityFeePerGas.toString()),
1420
- maxFeePerGas: cryptoLib.BigNumber(args.maxFeePerGas ? args.maxFeePerGas : gasFeeData.maxFeePerGas.toString())
1437
+ maxPriorityFeePerGas: cryptoLib.BigNumber((_args$maxPriorityFeeP = args.maxPriorityFeePerGas) != null ? _args$maxPriorityFeeP : gasFeeData.maxPriorityFeePerGas.toString()),
1438
+ maxFeePerGas: cryptoLib.BigNumber((_args$maxFeePerGas = args.maxFeePerGas) != null ? _args$maxFeePerGas : gasFeeData.maxFeePerGas.toString())
1421
1439
  })
1422
1440
  });
1423
1441
  }