quantum-coin-js-sdk 1.0.6 → 1.0.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/README.md CHANGED
@@ -5,7 +5,7 @@ Quantum Coin JS SDK provides functionality to interact with the Quantum Coin Blo
5
5
 
6
6
  **Example**
7
7
  ```js
8
- Installation:
8
+ Installation:
9
9
 
10
10
 
11
11
  ```
12
12
 
13
13
  * [quantum-coin-js-sdk](#module_quantum-coin-js-sdk)
@@ -77,8 +77,8 @@ Installation:
77
77
  * [~getLatestBlockDetails()](#module_quantum-coin-js-sdk..getLatestBlockDetails) ⇒ <code>Promise.&lt;BlockDetailsResult&gt;</code>
78
78
  * [~getAccountDetails(address)](#module_quantum-coin-js-sdk..getAccountDetails) ⇒ <code>Promise.&lt;AccountDetailsResult&gt;</code>
79
79
  * [~getTransactionDetails(txnHash)](#module_quantum-coin-js-sdk..getTransactionDetails) ⇒ <code>Promise.&lt;TransactionDetailsResult&gt;</code>
80
- * [~signSendCoinTransaction(wallet, toAddress, coinsInWei, nonce)](#module_quantum-coin-js-sdk..signSendCoinTransaction) ⇒ <code>SignResult</code>
81
- * [~sendCoins(wallet, toAddress, coinsInWei, nonce)](#module_quantum-coin-js-sdk..sendCoins) ⇒ <code>Promise.&lt;SendResult&gt;</code>
80
+ * [~signSendCoinTransaction(wallet, toAddress, coins, nonce)](#module_quantum-coin-js-sdk..signSendCoinTransaction) ⇒ <code>SignResult</code>
81
+ * [~sendCoins(wallet, toAddress, coins, nonce)](#module_quantum-coin-js-sdk..sendCoins) ⇒ <code>Promise.&lt;SendResult&gt;</code>
82
82
 
83
83
  <a name="module_quantum-coin-js-sdk..Config"></a>
84
84
 
@@ -647,7 +647,7 @@ The deserializeWallet function creates a Wallet object from a JSON string.
647
647
  The postTransaction function posts a signed transaction to the blockchain.
648
648
 
649
649
  **Kind**: inner method of [<code>quantum-coin-js-sdk</code>](#module_quantum-coin-js-sdk)
650
- **Returns**: <code>Promise.&lt;SendResult&gt;</code> - Returns a promise of type SendResult.
650
+ **Returns**: <code>Promise.&lt;SendResult&gt;</code> - Returns a promise of type SendResult. txnHash will be null in SendResult.
651
651
 
652
652
  | Param | Type | Description |
653
653
  | --- | --- | --- |
@@ -686,7 +686,7 @@ The getTransactionDetails function returns details of a transaction posted to th
686
686
 
687
687
  <a name="module_quantum-coin-js-sdk..signSendCoinTransaction"></a>
688
688
 
689
- ### quantum-coin-js-sdk~signSendCoinTransaction(wallet, toAddress, coinsInWei, nonce) ⇒ <code>SignResult</code>
689
+ ### quantum-coin-js-sdk~signSendCoinTransaction(wallet, toAddress, coins, nonce) ⇒ <code>SignResult</code>
690
690
  The signSendCoinTransaction function returns a signed transaction.
691
691
 
692
692
  **Kind**: inner method of [<code>quantum-coin-js-sdk</code>](#module_quantum-coin-js-sdk)
@@ -696,12 +696,12 @@ The signSendCoinTransaction function returns a signed transaction.
696
696
  | --- | --- | --- |
697
697
  | wallet | <code>Wallet</code> | A Wallet object from which the transaction has to be sent. The address corresponding to the Wallet should have enough coins to cover gas fees as well. A minimum of 1000 coins (1000000000000000000000 wei) are required for gas fees. |
698
698
  | toAddress | <code>string</code> | The address to which the coins should be sent. |
699
- | coinsInWei | <code>string</code> | The string representing the number of coins (in wei) to send. To convert between ethers and wei, see https://docs.ethers.org/v4/api-utils.html#ether-strings-and-wei |
699
+ | coins | <code>string</code> | The string representing the number of coins (in ether) to send. To convert between ethers and wei, see https://docs.ethers.org/v4/api-utils.html#ether-strings-and-wei |
700
700
  | nonce | <code>number</code> | The nonce of the account retrieved by invoking the getAccountDetails function. You have to carefully manage state of the nonce to avoid sending the coins multiple times, such as when retrying sendCoins after a network error. |
701
701
 
702
702
  <a name="module_quantum-coin-js-sdk..sendCoins"></a>
703
703
 
704
- ### quantum-coin-js-sdk~sendCoins(wallet, toAddress, coinsInWei, nonce) ⇒ <code>Promise.&lt;SendResult&gt;</code>
704
+ ### quantum-coin-js-sdk~sendCoins(wallet, toAddress, coins, nonce) ⇒ <code>Promise.&lt;SendResult&gt;</code>
705
705
  The sendCoins function posts a send-coin transaction to the blockchain.
706
706
 
707
707
  **Kind**: inner method of [<code>quantum-coin-js-sdk</code>](#module_quantum-coin-js-sdk)
@@ -711,6 +711,6 @@ The sendCoins function posts a send-coin transaction to the blockchain.
711
711
  | --- | --- | --- |
712
712
  | wallet | <code>Wallet</code> | A Wallet object from which the transaction has to be sent. The address corresponding to the Wallet should have enough coins to cover gas fees as well. A minimum of 1000 coins (1000000000000000000000 wei) are required for gas fees. |
713
713
  | toAddress | <code>string</code> | The address to which the coins should be sent. |
714
- | coinsInWei | <code>string</code> | The string representing the number of coins (in wei) to send. To convert between ethers and wei, see https://docs.ethers.org/v4/api-utils.html#ether-strings-and-wei |
714
+ | coins | <code>string</code> | The string representing the number of coins (in ether) to send. To convert between ethers and wei, see https://docs.ethers.org/v4/api-utils.html#ether-strings-and-wei |
715
715
  | nonce | <code>number</code> | The nonce of the account retrieved by invoking the getAccountDetails function. You have to carefully manage state of the nonce to avoid sending the coins multiple times, such as when retrying sendCoins after a network error. |
716
716
 
package/example/README.md CHANGED
@@ -1,3 +1,9 @@
1
1
  ## Quantum Coin SDK Example
2
2
 
3
3
  Example for using Quantum Coin SDK
4
+
5
+ To run the project:
6
+
7
+ npm install
8
+
9
+ node example.js
@@ -1,4 +1,4 @@
1
- const qcsdk = require('qc-sdk');
1
+ const qcsdk = require('quantum-coin-js-sdk');
2
2
  const ethers = require('ethers');
3
3
 
4
4
  //Initialize the client configuration
@@ -17,7 +17,6 @@ qcsdk.initialize(clientConfigVal).then((initResult) => {
17
17
  }
18
18
  console.log("Initialize succeeded");
19
19
 
20
-
21
20
  //Get the account details
22
21
  let address = "0x0000000000000000000000000000000000000000000000000000000000001000"; //Just an example address https://t4.scan.quantumcoin.org/account/0x0000000000000000000000000000000000000000000000000000000000001000
23
22
 
@@ -171,9 +170,10 @@ qcsdk.initialize(clientConfigVal).then((initResult) => {
171
170
 
172
171
  var toAddress = "0x8293cd9b6ac502d2fe077b0c157dad39f36a5e546525b053151dced633634612";
173
172
  var nonce = accountDetailsResult.accountDetails.nonce;
174
- var coinsInWei = "1000";
173
+ var coins = "10"; //in ethers and not in wei
175
174
 
176
- qcsdk.sendCoins(wallet2, toAddress, coinsInWei, nonce).then((sendResult) => {
175
+ console.log("Sending coins (wei) " + coins);
176
+ qcsdk.sendCoins(wallet2, toAddress, coins, nonce).then((sendResult) => { //carefully manage state of nonce when retrying on errors
177
177
  if (sendResult === null) {
178
178
  console.error(" sendCoins failed : sendResult is null");
179
179
  return;
@@ -10,7 +10,7 @@
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "ethers": "^6.13.4",
13
- "qc-sdk": "^1.0.2"
13
+ "quantum-coin-js-sdk": "^1.0.6"
14
14
  }
15
15
  },
16
16
  "node_modules/@adraffy/ens-normalize": {
@@ -85,10 +85,10 @@
85
85
  "resolved": "https://registry.npmjs.org/pqc-js-sdk/-/pqc-js-sdk-1.0.0.tgz",
86
86
  "integrity": "sha512-7Q5YlFvaXoP+MK+yn4KH4MYvJDkyGoGUU/zKYsRxR1mVqddqGUsGvz2JTsfH5B/Gkk97gMMh3PQ7MmkM8iJA5Q=="
87
87
  },
88
- "node_modules/qc-sdk": {
89
- "version": "1.0.4",
90
- "resolved": "https://registry.npmjs.org/qc-sdk/-/qc-sdk-1.0.4.tgz",
91
- "integrity": "sha512-Nj3DAF4JkyJ2XPjToY5l/i5yBUOxY5Cs4boDeqmFOwvt3qXldCS5fTAOBBpDKQLFYJOnI/CmfRt5hnskIP0GIg==",
88
+ "node_modules/quantum-coin-js-sdk": {
89
+ "version": "1.0.7",
90
+ "resolved": "https://registry.npmjs.org/quantum-coin-js-sdk/-/quantum-coin-js-sdk-1.0.7.tgz",
91
+ "integrity": "sha512-rHdSm7Xa3YGy5m/8YSin5EYJcE8ZnWtAFhcmsI3o56r+58c7ARwmcHaqJMMazmgenUC5AyxlUIrOjwzJFGAOuw==",
92
92
  "dependencies": {
93
93
  "pqc-js-sdk": "^1.0.0"
94
94
  }
@@ -10,6 +10,6 @@
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "ethers": "^6.13.4",
13
- "qc-sdk": "^1.0.2"
13
+ "quantum-coin-js-sdk": "^1.0.6"
14
14
  }
15
15
  }
package/index.js CHANGED
@@ -9,10 +9,19 @@
9
9
  * Installation:
10
10
  * npm install quantum-coin-js-sdk --save
11
11
  *
12
- * Adding reference:
12
+ * //Adding reference:
13
13
  * var qcsdk = require('quantum-coin-js-sdk');
14
14
  *
15
+ * //Initialize the SDK first before invoking any other function
16
+ * var clientConfigVal = new qcsdk.Config("https://t4-relayread.quantumcoin.org", "https://t4-relaywrite.quantumcoin.org", 310324, "", ""); //Testnet T4 Block Explorer: https://t4.scan.quantumcoin.org
17
+ *
18
+ * qcsdk.initialize(clientConfigVal).then((initResult) => {
19
+ *
20
+ * }
21
+ *
15
22
  * Example Project: https://github.com/quantumcoinproject/quantum-coin-js-sdk/tree/main/example
23
+ *
24
+ *
16
25
  */
17
26
 
18
27
  var fs = require('fs');
@@ -475,8 +484,14 @@ class TransactionDetailsResult {
475
484
  }
476
485
 
477
486
  function isLargeNumber(val) {
478
- var rgx = /^([0-9]+([.][0-9]*)?|[.][0-9]+)$/;
479
- return Boolean(val.match(rgx));
487
+ if (val === null) {
488
+ return false;
489
+ }
490
+ if (typeof val === 'string' || val instanceof String) {
491
+ var rgx = /^([0-9]+([.][0-9]*)?|[.][0-9]+)$/;
492
+ return Boolean(val.match(rgx));
493
+ }
494
+ return false;
480
495
  }
481
496
 
482
497
  async function InitAccountsWebAssembly() {
@@ -720,7 +735,7 @@ function transactionGetData(fromaddress, nonce, toaddress, amount, gas, chainid,
720
735
  * @async
721
736
  * @function postTransaction
722
737
  * @param {string} txnData - A signed transaction string returned by the signSendCoinTransaction function.
723
- * @return {Promise<SendResult>} Returns a promise of type SendResult.
738
+ * @return {Promise<SendResult>} Returns a promise of type SendResult. txnHash will be null in SendResult.
724
739
  */
725
740
  async function postTransaction(txnData) {
726
741
  if (isInitialized === false) {
@@ -1008,16 +1023,16 @@ async function getTransactionDetails(txnHash) {
1008
1023
  * @function signSendCoinTransaction
1009
1024
  * @param {Wallet} wallet - A Wallet object from which the transaction has to be sent. The address corresponding to the Wallet should have enough coins to cover gas fees as well. A minimum of 1000 coins (1000000000000000000000 wei) are required for gas fees.
1010
1025
  * @param {string} toAddress - The address to which the coins should be sent.
1011
- * @param {string} coinsInWei - The string representing the number of coins (in wei) to send. To convert between ethers and wei, see https://docs.ethers.org/v4/api-utils.html#ether-strings-and-wei
1026
+ * @param {string} coins - The string representing the number of coins (in ether) to send. To convert between ethers and wei, see https://docs.ethers.org/v4/api-utils.html#ether-strings-and-wei
1012
1027
  * @param {number} nonce - The nonce of the account retrieved by invoking the getAccountDetails function. You have to carefully manage state of the nonce to avoid sending the coins multiple times, such as when retrying sendCoins after a network error.
1013
1028
  * @return {SignResult} Returns a promise of type SignResult.
1014
1029
  */
1015
- async function signSendCoinTransaction(wallet, toAddress, coinsInWei) {
1030
+ async function signSendCoinTransaction(wallet, toAddress, coins, nonce) {
1016
1031
  if (isInitialized === false) {
1017
1032
  return -1000;
1018
1033
  }
1019
1034
 
1020
- if (wallet == null || toAddress == null || coinsInWei == null || nonce == null) {
1035
+ if (wallet == null || toAddress == null || coins == null || nonce == null) {
1021
1036
  return new SignResult(-500, null, null);
1022
1037
  }
1023
1038
 
@@ -1029,7 +1044,7 @@ async function signSendCoinTransaction(wallet, toAddress, coinsInWei) {
1029
1044
  return new SignResult(-502, null, null);
1030
1045
  }
1031
1046
 
1032
- if (isLargeNumber(coinsInWei) == false) {
1047
+ if (isLargeNumber(coins) == false) {
1033
1048
  return new SignResult(-503, null, null);
1034
1049
  }
1035
1050
 
@@ -1044,7 +1059,7 @@ async function signSendCoinTransaction(wallet, toAddress, coinsInWei) {
1044
1059
 
1045
1060
  const contractData = null;
1046
1061
 
1047
- var txSigningHash = transactionGetSigningHash(wallet.address, nonce, toAddress, coinsInWei, DEFAULT_GAS, config.chainId, contractData)
1062
+ var txSigningHash = transactionGetSigningHash(wallet.address, nonce, toAddress, coins, DEFAULT_GAS, config.chainId, contractData)
1048
1063
  if (txSigningHash == null) {
1049
1064
  return new SignResult(-506, null, null);
1050
1065
  }
@@ -1056,17 +1071,17 @@ async function signSendCoinTransaction(wallet, toAddress, coinsInWei) {
1056
1071
  return new SignResult(-507, null, null);
1057
1072
  }
1058
1073
 
1059
- var txHashHex = transactionGetTransactionHash(wallet.address, nonce, toAddress, coinsInWei, DEFAULT_GAS, config.chainId, contractData, wallet.publicKey, quantumSig);
1074
+ var txHashHex = transactionGetTransactionHash(wallet.address, nonce, toAddress, coins, DEFAULT_GAS, config.chainId, contractData, wallet.publicKey, quantumSig);
1060
1075
  if (txHashHex == null) {
1061
- return new SendResult(-508, null, null);
1076
+ return new SignResult(-508, null, null);
1062
1077
  }
1063
1078
 
1064
- var txnData = transactionGetData(wallet.address, nonce, toAddress, coinsInWei, DEFAULT_GAS, config.chainId, contractData, wallet.publicKey, quantumSig);
1079
+ var txnData = transactionGetData(wallet.address, nonce, toAddress, coins, DEFAULT_GAS, config.chainId, contractData, wallet.publicKey, quantumSig);
1065
1080
  if (txnData == null) {
1066
- return new SendResult(-509, null, null);
1081
+ return new SignResult(-509, null, null);
1067
1082
  }
1068
1083
 
1069
- return new SendResult(0, txHashHex, txnData);
1084
+ return new SignResult(0, txHashHex, txnData);
1070
1085
  }
1071
1086
 
1072
1087
  /**
@@ -1078,16 +1093,16 @@ async function signSendCoinTransaction(wallet, toAddress, coinsInWei) {
1078
1093
  * @function sendCoins
1079
1094
  * @param {Wallet} wallet - A Wallet object from which the transaction has to be sent. The address corresponding to the Wallet should have enough coins to cover gas fees as well. A minimum of 1000 coins (1000000000000000000000 wei) are required for gas fees.
1080
1095
  * @param {string} toAddress - The address to which the coins should be sent.
1081
- * @param {string} coinsInWei - The string representing the number of coins (in wei) to send. To convert between ethers and wei, see https://docs.ethers.org/v4/api-utils.html#ether-strings-and-wei
1096
+ * @param {string} coins - The string representing the number of coins (in ether) to send. To convert between ethers and wei, see https://docs.ethers.org/v4/api-utils.html#ether-strings-and-wei
1082
1097
  * @param {number} nonce - The nonce of the account retrieved by invoking the getAccountDetails function. You have to carefully manage state of the nonce to avoid sending the coins multiple times, such as when retrying sendCoins after a network error.
1083
1098
  * @return {Promise<SendResult>} Returns a promise of type SendResult.
1084
1099
  */
1085
- async function sendCoins(wallet, toAddress, coinsInWei, nonce) {
1100
+ async function sendCoins(wallet, toAddress, coins, nonce) {
1086
1101
  if (isInitialized === false) {
1087
1102
  return -1000;
1088
1103
  }
1089
1104
 
1090
- if (wallet == null || toAddress == null || coinsInWei == null || nonce == null) {
1105
+ if (wallet == null || toAddress == null || coins == null || nonce == null) {
1091
1106
  return new SendResult(-1, null, null);
1092
1107
  }
1093
1108
 
@@ -1099,7 +1114,7 @@ async function sendCoins(wallet, toAddress, coinsInWei, nonce) {
1099
1114
  return new SendResult(-3, null, null);
1100
1115
  }
1101
1116
 
1102
- if (isLargeNumber(coinsInWei) == false) {
1117
+ if (isLargeNumber(coins) == false) {
1103
1118
  return new SendResult(-4, null, null);
1104
1119
  }
1105
1120
 
@@ -1123,7 +1138,7 @@ async function sendCoins(wallet, toAddress, coinsInWei, nonce) {
1123
1138
 
1124
1139
  const contractData = null;
1125
1140
 
1126
- var txSigningHash = transactionGetSigningHash(wallet.address, nonce, toAddress, coinsInWei, DEFAULT_GAS, config.chainId, contractData)
1141
+ var txSigningHash = transactionGetSigningHash(wallet.address, nonce, toAddress, coins, DEFAULT_GAS, config.chainId, contractData)
1127
1142
  if (txSigningHash == null) {
1128
1143
  return new SendResult(-9, null, null);
1129
1144
  }
@@ -1135,12 +1150,12 @@ async function sendCoins(wallet, toAddress, coinsInWei, nonce) {
1135
1150
  return new SendResult(-10, null, null);
1136
1151
  }
1137
1152
 
1138
- var txHashHex = transactionGetTransactionHash(wallet.address, nonce, toAddress, coinsInWei, DEFAULT_GAS, config.chainId, contractData, wallet.publicKey, quantumSig);
1153
+ var txHashHex = transactionGetTransactionHash(wallet.address, nonce, toAddress, coins, DEFAULT_GAS, config.chainId, contractData, wallet.publicKey, quantumSig);
1139
1154
  if (txHashHex == null) {
1140
1155
  return new SendResult(-11, null, null);
1141
1156
  }
1142
1157
 
1143
- var txnData = transactionGetData(wallet.address, nonce, toAddress, coinsInWei, DEFAULT_GAS, config.chainId, contractData, wallet.publicKey, quantumSig);
1158
+ var txnData = transactionGetData(wallet.address, nonce, toAddress, coins, DEFAULT_GAS, config.chainId, contractData, wallet.publicKey, quantumSig);
1144
1159
  if (txnData == null) {
1145
1160
  return new SendResult(-12, null, null);
1146
1161
  }
@@ -1175,4 +1190,3 @@ module.exports = {
1175
1190
  TransactionDetails,
1176
1191
  TransactionDetailsResult,
1177
1192
  };
1178
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quantum-coin-js-sdk",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "Quantum Coin SDK in JavaScript",
5
5
  "main": "index.js",
6
6
  "scripts": {