quantum-coin-js-sdk 1.0.13 → 1.0.15

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/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
+ .idea
1
2
  .vs/
2
3
  node_modules/
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Quantum Coin Community
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,30 @@
1
+ License for file wasm_exec.js
2
+ https://github.com/golang/go/blob/master/LICENSE
3
+
4
+ Copyright 2009 The Go Authors.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are
8
+ met:
9
+
10
+ * Redistributions of source code must retain the above copyright
11
+ notice, this list of conditions and the following disclaimer.
12
+ * Redistributions in binary form must reproduce the above
13
+ copyright notice, this list of conditions and the following disclaimer
14
+ in the documentation and/or other materials provided with the
15
+ distribution.
16
+ * Neither the name of Google LLC nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md CHANGED
Binary file
@@ -1,12 +1,19 @@
1
1
  const qcsdk = require('quantum-coin-js-sdk');
2
2
  const ethers = require('ethers');
3
3
 
4
+ var clientConfigVal = new qcsdk.Config("https://sdk.readrelay.quantumcoinapi.com", "https://sdk.writerelay.quantumcoinapi.com", 123123, "", ""); //Mainnet
5
+
6
+
4
7
  //Initialize the client configuration
5
- var clientConfigVal = new qcsdk.Config("https://t4-relayread.quantumcoin.org", "https://t4-relaywrite.quantumcoin.org", 310324, "", ""); //Testnet T4
8
+ //var clientConfigVal = new qcsdk.Config("https://t4-relayread.quantumcoin.org", "https://t4-relaywrite.quantumcoin.org", 310324, "", ""); //Testnet T4
6
9
  //Testnet T4 Block Explorer: https://t4.scan.quantumcoin.org
7
10
 
8
11
  //For mainnet, use the following configuration
9
- //var clientConfigVal = new qcsdk.Config("https://relayread.quantumcoin.org", "https://relaywrite.quantumcoin.org", 123123, "", ""); //Mainnet
12
+ //var clientConfigVal = new qcsdk.Config("https://sdk.readrelay.quantumcoinapi.com", "https://sdk.writerelay.quantumcoinapi.com", 123123, "", ""); //Mainnet
13
+ //Mainnet Block Explorer: https://scan.quantumcoin.org
14
+
15
+ //Local testing configuration
16
+ //var clientConfigVal = new qcsdk.Config("http://127.0.0.1:9090", "http://127.0.0.1:9091", 123123, "", ""); //local testing
10
17
  //Mainnet Block Explorer: https://scan.quantumcoin.org
11
18
 
12
19
 
@@ -27,7 +34,11 @@ qcsdk.initialize(clientConfigVal).then((initResult) => {
27
34
  console.error("Initialize failed");
28
35
  return;
29
36
  }
30
- console.log("Initialize succeeded");
37
+ console.log("Initialize succeeded");
38
+
39
+ console.log("isAddressValid (expected true)" + qcsdk.isAddressValid("0x6f605c4142f1cb037f967101a5b28ccd00b27cce4516190356baaf284d20e667")); //should print true
40
+ console.log("isAddressValid (expected true)" + qcsdk.isAddressValid("0X6F605C4142F1CB037F967101A5B28CCD00B27CCE4516190356BAAF284D20E667")); //should print true
41
+
31
42
 
32
43
  //Get the account details
33
44
  let address = "0x0000000000000000000000000000000000000000000000000000000000001000"; //Just an example address https://t4.scan.quantumcoin.org/account/0x0000000000000000000000000000000000000000000000000000000000001000
@@ -117,7 +128,7 @@ qcsdk.initialize(clientConfigVal).then((initResult) => {
117
128
 
118
129
  //Get the latest block details
119
130
  console.log("getLatestBlockDetails");
120
- qcsdk.getLatestBlockDetails(address).then((latestBlockDetailsResult) => {
131
+ qcsdk.getLatestBlockDetails().then((latestBlockDetailsResult) => {
121
132
  if (latestBlockDetailsResult === null) {
122
133
  console.error(" getLatestBlockDetails failed : latestBlockDetailsResult is null");
123
134
  return;
@@ -239,6 +250,7 @@ qcsdk.initialize(clientConfigVal).then((initResult) => {
239
250
  console.log(" Account address: " + address);
240
251
  console.log(" Page Count: " + accountTransactionsResult.listAccountTransactionsResponse.pageCount);
241
252
  console.log(" Number of transactions returned: " + txnList.length);
253
+
242
254
  for (const txn of txnList) {
243
255
  console.log(" Transaction Hash: " + txn.hash);
244
256
  console.log(" From Address: " + txn.from);
@@ -251,9 +263,23 @@ qcsdk.initialize(clientConfigVal).then((initResult) => {
251
263
  console.log(" Status: " + txn.status);
252
264
  console.log(" Block Number: " + txn.blockNumber);
253
265
  }
266
+
267
+ let pageCount = accountTransactionsResult.listAccountTransactionsResponse.pageCount;
268
+
269
+ //Enumerate and list all the pages
270
+ for (i = 1; i <= pageCount; i++) {
271
+ let pageNumber = i;
272
+ qcsdk.listAccountTransactions(address, pageNumber).then((txnListResult) => {
273
+ let txnList = txnListResult.listAccountTransactionsResponse.items;
274
+ for (const txn of txnList) {
275
+ console.log(" Transaction Hash: " + txn.hash + " pageNumber = " + pageNumber);
276
+ }
277
+ });
278
+ }
254
279
  });
255
280
 
256
- //Offline sign a transaction from existing wallet. This is typically called from an offline device hosting a cold storage wallet
281
+ //Offline sign a transaction from existing wallet. This is typically called from an offline device hosting a cold storage wallet.
282
+ //Another usecase is to first store the signed transaction in a database and then later submit it using the postTransaction function.
257
283
  let walletJsonExample = '{"address":"0xAB035828c5A9d240bB97c6136E4299150829c8dEa12908E85351e9dF6C379BB7","privateKey":"M4a/VQGhosseluM6qQv1QSbWS2GIKRiZS8up1pX5z5EkRlRxoGt6SRoUkjBfUfr8ro35Y2Pcs7HxNWnmVbCCZvipadwa+YZHvraA1kWOn/G5MOOULp2tziYbj6ZpSiqf6agTq7IDE+gn2Cgc4x3PxgM2vHXMffpSAYC0aK3ix2ZIXlsqignmdtfbL8erR9NLTqBE+mjRLxriimnb+2z3Z503ycwWEKexRcK9pGNmovgRLlMf5DoD9viNDe/2fXkw3DhoIBQIxJggoBAsCjcyxLhwIylxoiBpRKRFCYKNHCGR0yKFyjKJJIGFAbQkgwYqASAqhBIJApkMwCIIgsA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1EtinKXpJ3lQec6jn+p2nFk3MlNPKw90cLRHg6QmllYVP4O+4ekNnvAVgNNs29Otf1Rh+3qfAKCSZdFged3fXgvTFigQD5tE+AFg9GNIkfnrZfq8G29OWKvbOlqNmogKOHQSHpcUODPiv/DwpbA9O04hCHoCIINZ0b8PxZNXaC/6+e2B6AkBMCnl9TZic4bNo+vs63ydTiuvJMSpWkbt2lnrJ7iKpiSAJ17ZBsXyZQCZ1+Zwe+HEBrA0hW02xVqy+dm3D0d1fnF5D+LdaUrH6UgaUy1bYI4KVq+LTOk2dC4nKkhVlYdG2JLtu16Olq/mpbLY/WeS3svKchXo69oq4lTogVxmc5DCl2gMHqVdK+v/4A7ObhCMftGKSD9BxXurBIhP5CQlYsEVO1tOagm0p7DcAI1O5QeKOCXgL1IrwNuW5gkuRM1MUyvKwnIl8FDBOVvzZRKfBSwAum4CEn6T+ja064ldZDigVACIWl9P9m9zmLXblWcZCi9e8ym+dg=="}';
258
284
  let walletExample = qcsdk.deserializeWallet(walletJsonExample);
259
285
 
@@ -286,5 +312,49 @@ qcsdk.initialize(clientConfigVal).then((initResult) => {
286
312
 
287
313
  console.log(" postTransaction succeeded. This does not necessarily mean that the transaction has succeded. txnHash " + sendResult.txnHash);
288
314
  });
315
+
316
+ //Open example wallet created using external wallet application such as Desktop/Web/CLI/Mobile wallet
317
+ const walletEncryptedJson1 = "{\"address\":\"1a846abe71c8b989e8337c55d608be81c28ab3b2e40c83eaa2a68d516049aec6\",\"crypto\":{\"cipher\":\"aes-256-ctr\",\"ciphertext\":\"ab7e620dd66cb55ac201b9c6796de92bbb06f3681b5932eabe099871f1f7d79acabe30921a39ad13bfe74f42c515734882b6723760142aa3e26e011df514a534ae47bd15d86badd9c6f17c48d4c892711d54d441ee3a0ee0e5b060f816e79c7badd13ff4c235934b1986774223ecf6e8761388969bb239c759b54c8c70e6a2e27c93a4b70129c8159f461d271ae8f3573414c78b88e4d0abfa6365ed45456636d4ed971c7a0c6b84e6f0c2621e819268b135e2bcc169a54d1847b39e6ba2ae8ec969b69f330b7db9e785ed02204d5a1185915ae5338b0f40ef2a7f4d5aaf7563d502135e57f4eb89d5ec1efa5c77e374969d6cd85be625a2ed1225d68ecdd84067bfc69adb83ecd5c6050472eca28a5a646fcdd28077165c629975bec8a79fe1457cb53389b788b25e1f8eff8b2ca326d7dfcaba3f8839225a08057c018a458891fd2caa0d2b27632cffd80f592147ccec9a10dc8a08a48fb55047bff5cf85cda39eb089096bef63842fc3686412f298a54a9e4b0bf4ad36907ba373cbd6d32e7ac494af371da5aa9d38a3463220865114c4adc5e4ac258ba9c6af9fa2ddfd1aec2e16887e4b3977c69561df8599ac9d411c9dd2a4d57f92ea4e5c02aae3f49fb3bc83e16673e6c2dbe96bb181c8dfd0f9757ade2e4ff27215a836058c5ffeab042f6f97c7c02339f76a6284680e01b4bb733690eb3347fbfcc26614b8bf755f9dfce3fea9d4e4d15b164983201732c2e87593a86bca6da6972e128490338f76ae68135888070f4e59e90db54d23834769bdbda9769213faf5357f9167a224523975a946367b68f0cec98658575609f58bfd329e420a921c06713326e4cb20a0df1d77f37e78a320a637a96c604ca3fa89e24beb42313751b8f09b14f9c14c77e4fd13fc6382505d27c771bca0d821ec7c3765acffa99d83c50140a56b0b28101c762bd682fe55cb6f23cbeb3f421d7b36021010e45ac27160dd7ead99c864a1b550c7edb1246950fe32dcc049799f9085287f0a747a6ef7a023df46a23a22f3e833bbf8d404f84344870492658256ee1dfc40fda33bb8d48fc72d4520ba9fc820c9123104a045206809037709f2a5f6723fa77d6bac5a573823d4ec3a7f1cb786a52ee2697e622e5d75962fa554d1024a6c355e21f33a63b2b72e6c4742a8b1c373aa532b40518c38c90b5373c2eb8c9d7be2a9e16047a3ee09dc9a6849deac5183ace6cfe91a9bef2ffc0a7df6ccebfd4c858c84b0e0355650d7466971e66f1e3883013e5ad1be33199b1d110b79070ac1b745ccb14cf63a08f8cca3a21c9525e626ff5f0c34746e10750fb742ad51f11f2acae3676c2111853d7250d01b77821a6ba9e04400ba2c543ca9f2d701ae6f47bfad14ffe3039ee9e71f7b2401359ade9938750ddb9c5a8b018a7929ed8d0e717ff1861446ce17535e9b17c187711190aae3388bd9490837a636c25ed4d42d7079ad1a51e13292c683d5d012abcf46965c534b83ab53f2c1f0cf5830ef7582e06863a33c19a70511df632885d63245965047ea96b56f1af5b3b94a54999f784fb9574fdfcd7c1230e07a2aaa04acd3097b2b9f8ddba05ae9734491deb5c1a513c76ed276cb78bbf4839dae3156d76af444a5805129d5df791167a9c8576a1d7f760b2d2797c4658669608706fbd0ace1be2346f74862dfc9ef518e55632e43c043186e5d070deb34d12fb9e5aba84e5cb50213dc88efd39cc35bf42455aa82d5e3b707b3140be3b8623b34fdd81d08615c188ae8438a13881fdf6bf32f2cb9ff5fa625561040c6b71d4b8eccc90bc3b99650d28dd1ee63773e49664e3d48c484996b290943635a6f2eb1ce9796d3fa144a3f00ef82faaa32d6a413668f7b521517cb68b2b017fcf56c79326fa5e4060e643631ca3f0a0dc0ed718798b6f46b130d437c33f64039e887324b6f5e604b1669d613923794edbf04b1b3caea54793b52b44b170173a4f25c7ecef3b71e2aad76e556b1cb9f1d637ec52ececfa950dd31dbb6a60828a3ad34c1beffe09eb4785786d63bad10a0b0f66ea88c57380f38ea85f018dbd7f538cf1ee7624095b9a01ec5edd528f281168af020609e651ff316aa1320a710134ddfca600cc72174dcdb846d2aa29916488aa1b537b66da92e61af526debef4eb38c984569eaf549ff2129449269b492d030cd74d885f6f5785881cc4804b4a8a09ba4ff7aefe9074ac7d0c4f05d51fe4cc0ff7388a772092b9d02d70e5433a5cf3e02f46a6bd6b818d59a07ce3b9fbbf8b5faba74563bcc5240930c2d406c9aaee3e3ce0429bf68ac2b0a57adb09414cff50817d2a48fb9fa624ab863cb0c31a8b8dc5eaf6fa68cc1d7c6c685c5a33edd5c8933b9e8ab628ee428d0743699b2ff17f25586c7ce959280bb0b8c5342251f0a30b53dbc7bf1ee426ac9619c3560f811f2268ee37f189794e2e4b3db3a2fb2e34b649e504fb467438abfd1082619cc4a0b30d66beb831077812e418d2e2148db10cf4d4a29101ca52ec445b8d83519dd7de85a98e0beae9ee537096d3f1a55a7a80cdfa93d25f07c9f98e8af18cde19ec1f99c5dd4588b717a5039ddb7f177717caf0d0fd45420a70dbd6d3146890d9e450d5224146db4c33b779e3c3a04b976c052bad042ac57dd38be45407808c0fb0d7e2a8819e6cd53c6739e6612996ddaa6f066552590aa0343bc1e62b298ff2514a0cef8be21956c2e942816f7a3a3a0935eaf9b37251409ce444c986c3817e82835555fe18239f3ae33469d7965c2bde9991fde556bd07af01df52bbde0c35bb4ef48e3b5d0db53f8ca4ed35b83f760f0a1bc4ed9f86e85d6039a17df373c85402ef956f01db00eb39c4b74bd0660d29ee746714d9780d738e05c6cca414ce3d7b40dda8036a9eea9ab1388805f913eb19bdd3f09d9e161eaa50231bd9caba61971f194332dd28c696a60458c1c6c2cc5da8b1192611c7c553e9e12fe48ce46bbb891be8bb118721c86222e671ddd1da8f0ccb2b68e02f2014b4925e904e88369aaf7466bd7033a60c265d45955944916ecbdb84bf1b522b01b0149c632e04c568a7eb627c5bb90ece052ebcf79166c28b30d23fe52da0a5ab5dea83ca479a3e3b7a9cfbbfea04dbe6137c19d067317c2ec427a8c75a6b06bec6dcd5d5c0edc9aa80b9003b8e17c088b2f3db327d3e42630d82d20120240c3ba56232280787da4aabbf5bc95a864029f00710e195f2a76460a0317d10b552fe1bea097e41d49756c680a41d6ac186e62169b6b6cd7776ea84618b5b752328a5bacaa10aa122ff9b2698b43efe73d852a899db644863c8c9bc8068ea86ea843fd6fe36272b91cdc5d5317083ef3fd1e5462a0b0d0604dc57b3bbfceb0fca4cd349625dd7b25166af30efe5ee6a0af953a74d65f4736c59918ee55a3b0d9d9d42e04c7f8a77e479109f740e20c464d5d7e3d16805f47b61f403ff7f408c9e850d9baacd8067e544536a4953480b0f9ee9cd45f41ebd67b51f78788a6470cb1e5ca72ca346ce8a50d0ca0c921d5576a4455a1afb6d0bc688004712ee122cacdb29c51e84893324c27fa4a3f1917edf5352272b4c97579a6152e4b77663d0ab532915f2eeb6a862de8b696452321b660c3f2449673d086e95a7af28845a5259b763e0fcd09f72acf7b6c811066263060e5aa5b24658e880a01fd56bda4dad5ab604e129290f7d5489728f2a40968c6168b21cebbbcd11727cc9e9160c4e92e04387d3b0d62aab06a61f26daedd9fed11816ef2180172a47f47184ac4032b88758c98a2e0fb200f70e93ba695f5ebb7a1029610ad360d3b7fa1b4640b9dc674d3625eef786da93dff19bc7991b5d6193a3896664763fde479b5dfc04812111a80782854f2cf68ca7d82765cc9eb40fba4b44640710ed6e653abf9f07b466333f4fd22784d53cf40e17120f42caa841eaa24056b237827b0f47f7257c103c35027e9f503e5acfd023e7357b600d3084d361d5ee65ba319b45c153212a54e6fed85af7e43e0a926ebcbc2edf8de7e2ec9528f00bec262ad04d5c9dafccaea06a24748d28bf1799bae0e895543084539c50b5aaa4fb50d7431d6f0c8cee2a54aaf7ee7919b55bf40adb688632e5dbe273cea09e97b19c3d8e1f4de000deb66fa1942ad03a62d3252f51992244366c156000b49c297167a6cbdedea7ebae139d295f0ad298e0864249b905b7eb812886ec70ecdb286702274b5b8574149bf3866f9e46b997ff5ed622b169a0eb071347f18d530db1663906a28f4544ee4e004ab87b65476af30ede118052ff052b8dc986ca2c93dd5d4943266a579c7698ea014f688b3e8063a107feb162d392e2177b01bff77fb5abe5feebd0607158049a5a093325b7c9ee6b4dfa7a9f65c7c2fb628920d3603a1c2dad979eaa047cd661a268af1078c9788d720e64e4ce9d12e68de1e417ef2f293323681e1071f9220e1ee43d2e29d111b870ce3439f5100ecd4551ab65ee74aa1667e564957e9bc0ae1ea193980da2a0ec2698073388c85bec25ef447f0d5e93a5203fa44dff268e5cb799ed3b66e63d5e07b487e7534f24934c73a62a243e0151843a0fd3807711a101eaa7fc71f0ba68aebb9534d57cba41b094eebfb4c31cca8eddfa426f676aa347be8a7023a4e91ddb154b35cd4d5f7dbc2e5db491de99f33fc2cff2d57029ac950e1ccd681980af6a4e8969dfe39b3c7bfcbcf8fac92f1e6ec9fe572bfa6a7d65860eab2ed10ac01a71290b52e3148e84b7376a8605cd2bb0e8681ffc54691ce087685e33921bd44d36c78291713dce17569570f62137e6904f0d68cf53aa2ec395c389a75141f08114fb293ea63950e4ffee55ec6fc83cf44876b8e7f25cdd393ff87b9eda6eb746085b61a6900de191f0ce2cb388d61ece52e78bc47368194e8e00277e0d1631e6b9d4626ef76f8522582ccd5a40be3febc699bb510acc6271d55ff0f4cf3bb7669855a72efd9ca3e1056a2fe592a5bc877cce2b1f63b58383971da87873d2d1349cf5881242cdce4e7e2c5c514755746a0e0a7c2a6d9701cde005ae3420beb17c379a3516662253554f51f0423bb1844b0b90c54ed8177ceb0e1036a6609d836e748ca06c40ca64befadc6443ec286a0ce464678e8d11eb455f7bb305acebf6cb1f50e394a9bfeb752df1687831bac9cdd811f4f112ef6658d0f8799a866374ff96c5e2b79f30e7a74f8a2bc9ed1f88f01f30e30cb78ffb2bff10108f35e910ee3be4463e9e6f0ed910e8d598326e71dfa2277ffe5579d7fe9b6018bfe295b25219eae07b3b0270665c3fa00c3e0d180812b5cd62925585de84a7c48a9a86dba96544a251654d1966e082432dc85b6149cf21e91a46020ec32b66d28ba3b6a90c0617bc6fdd55aea819af2bcf84864ad60c28fe3c9f8339d0aee68b39d97f63b6e082835d86119cf9b9fdc8b827c847ce40aa10e1577a710132316845e825345e95bdf94d0c66ec65a6c4319fce4792313663b5f7a651a6710783e6ab71608ac6cbbf3af6911adf596ccf7c172b9bd5bceb6db379967b32b143bdd11d2ee12ddf64ecef6391e0f8570e6cddd3db95204919362b89b739fa94e7c1bfde799fd5e22aa25ca6ca42e30c08e23aae2385d99ebab441072a880dcefdab74a4c9bd39d363f6d1933d59400fca161d432aa00f23b1b1c19a154be8989699d549b66d44e39896f5523443bc6ddf4a65e91f1f3fb7b52318869a05856a4fc92f3694c81ed833c972fb918f7e5\",\"cipherparams\":{\"iv\":\"8c46d6162cd4c765759aedcbce2a5874\"},\"kdf\":\"scrypt\",\"kdfparams\":{\"dklen\":32,\"n\":262144,\"p\":1,\"r\":8,\"salt\":\"82fb6cdc6917609135277badacf15baa31899d08b71a5a0fa33167167c161537\"},\"mac\":\"9187b17f7eca48e6b8c586b0cd790dbe0feb876ac8385f93faa7d5e22a3c8fc7\"},\"id\":\"92caf6ee-2d43-48c0-859e-ffa1e0e23312\",\"version\":3}";
318
+ const examplePassphrase = "QuantumCoinExample123!";
319
+ let walletObj1 = qcsdk.deserializeEncryptedWallet(walletEncryptedJson1, examplePassphrase);
320
+ if (walletObj1 === null) {
321
+ throw new Error("deserializeEncryptedWallet failed");
322
+ }
323
+ if (walletObj1.address.toLowerCase() !== "0x1a846ABE71C8B989e8337c55d608Be81C28Ab3b2e40c83eaA2A68D516049AeC6".toLowerCase()) {
324
+ throw new Error("deserializeEncryptedWallet address check failed");
325
+ }
326
+ console.log("wallet address from deserializeEncryptedWallet is " + walletObj1.address);
327
+
328
+ //Save to an encrypted wallet that can then be restored into an external wallet application such as Desktop/Web/CLI/Mobile wallet
329
+ let walletObj2 = qcsdk.newWallet();
330
+ let walletEncryptedJson2 = qcsdk.serializeEncryptedWallet(walletObj2, examplePassphrase);
331
+ if (walletEncryptedJson2 === null) {
332
+ throw new Error("serializeEncryptedWallet failed");
333
+ }
334
+ console.log("Serialized wallet: " + walletEncryptedJson2); //just an example for demonstration, do not actually log to console
335
+
336
+ //Try opening the same wallet again
337
+ let walletObj3 = qcsdk.deserializeEncryptedWallet(walletEncryptedJson2, examplePassphrase);
338
+ if (walletObj3 === null) {
339
+ throw new Error("deserializeEncryptedWallet failed");
340
+ }
341
+
342
+ if (walletObj2.address.toLowerCase() !== walletObj3.address.toLowerCase()) {
343
+ throw new Error("deserializeEncryptedWallet address check failed");
344
+ }
345
+
346
+ //Sign a transaction from a deserialized wallet (1)
347
+ qcsdk.signSendCoinTransaction(walletObj1, toAddressExample, coinsExample, nonceExample).then((signResult) => {
348
+ console.log("signSendCoinTransaction walletObj1 resultCode: " + signResult.resultCode);
349
+ console.log("signSendCoinTransaction walletObj1 hash: " + signResult.txnHash);
350
+ console.log("signSendCoinTransaction walletObj1 txnData: " + signResult.txnData); //txnData is to be sent to postTransaction
351
+ });
352
+
353
+ //Sign a transaction from a deserialized wallet (3)
354
+ qcsdk.signSendCoinTransaction(walletObj1, toAddressExample, coinsExample, nonceExample).then((signResult) => {
355
+ console.log("signSendCoinTransaction walletObj3 resultCode: " + signResult.resultCode);
356
+ console.log("signSendCoinTransaction walletObj3 hash: " + signResult.txnHash);
357
+ console.log("signSendCoinTransaction walletObj3 txnData: " + signResult.txnData); //txnData is to be sent to postTransaction
358
+ });
289
359
  });
290
360
 
@@ -10,7 +10,14 @@
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "ethers": "^6.13.4",
13
- "quantum-coin-js-sdk": "^1.0.6"
13
+ "quantum-coin-js-sdk": "file:.."
14
+ }
15
+ },
16
+ "..": {
17
+ "version": "1.0.15",
18
+ "license": "MIT",
19
+ "dependencies": {
20
+ "quantum-coin-pqc-js-sdk": "^1.0.0"
14
21
  }
15
22
  },
16
23
  "node_modules/@adraffy/ens-normalize": {
@@ -81,17 +88,8 @@
81
88
  }
82
89
  },
83
90
  "node_modules/quantum-coin-js-sdk": {
84
- "version": "1.0.12",
85
- "resolved": "https://registry.npmjs.org/quantum-coin-js-sdk/-/quantum-coin-js-sdk-1.0.12.tgz",
86
- "integrity": "sha512-6tL2h49j4Lqb4+80/V28pdulj9/fC9LNeolzxw3AujvZUClj3b5XUF9i2cWOmxTsHF3IGN4qSDghITXoKbhTag==",
87
- "dependencies": {
88
- "quantum-coin-pqc-js-sdk": "^1.0.0"
89
- }
90
- },
91
- "node_modules/quantum-coin-pqc-js-sdk": {
92
- "version": "1.0.0",
93
- "resolved": "https://registry.npmjs.org/quantum-coin-pqc-js-sdk/-/quantum-coin-pqc-js-sdk-1.0.0.tgz",
94
- "integrity": "sha512-SPRDhX6JHV0VJmIWB20S9YTH3oCQww7YoMjgt/4Ftt0U8yNVmUQOL79b/cknMPDd/zMZLAedmd3z8hs+Z8shig=="
91
+ "resolved": "..",
92
+ "link": true
95
93
  },
96
94
  "node_modules/tslib": {
97
95
  "version": "2.7.0",
@@ -10,6 +10,6 @@
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "ethers": "^6.13.4",
13
- "quantum-coin-js-sdk": "^1.0.6"
13
+ "quantum-coin-js-sdk": "^1.0.15"
14
14
  }
15
15
  }
package/index.js CHANGED
@@ -6,6 +6,9 @@
6
6
  * @description Quantum Coin JS SDK provides functionality to interact with the Quantum Coin Blockchain using the Relay APIs.
7
7
  * {@link https://github.com/quantumcoinproject/quantum-coin-js-sdk/tree/main/example|Example Project}
8
8
  * @example
9
+ *
10
+ * Requires Node.js version v20.18.1 or higher
11
+ *
9
12
  * Installation:
10
13
  * npm install quantum-coin-js-sdk --save
11
14
  *
@@ -13,7 +16,7 @@
13
16
  * var qcsdk = require('quantum-coin-js-sdk');
14
17
  *
15
18
  * //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
19
+ * var clientConfigVal = new qcsdk.Config("https://sdk.readrelay.quantumcoinapi.com", "https://sdk.writerelay.quantumcoinapi.com", 123123, "", ""); //TMainnet Block Explorer: https://QuantumScan.com
17
20
  *
18
21
  * qcsdk.initialize(clientConfigVal).then((initResult) => {
19
22
  *
@@ -45,8 +48,8 @@ const REQUEST_ID_HEADER_NAME = "X-REQUEST-ID";
45
48
  class Config {
46
49
  /**
47
50
  * Creates a config class
48
- * @param {string} readUrl - The Read API URL pointing to a read relay. See https://github.com/DogeProtocol/go-dp/tree/dogep/relay. The following URLs are community maintained. Please use your own relay service. Mainnet: https://relayread.quantumcoin.org Testnet T4: https://t4-relayread.quantumcoin.org
49
- * @param {string} writeUrl - The Write API URL pointing to a write relay. See https://github.com/DogeProtocol/go-dp/tree/dogep/relay. The following URLs are community maintained. Please use your own relay service. Mainnet: https://relaywrite.quantumcoin.org Testnet T4: https://t4-relaywrite.quantumcoin.org
51
+ * @param {string} readUrl - The Read API URL pointing to a read relay. See https://github.com/quantumcoinproject/quantum-coin-go/tree/dogep/relay. The following URLs are community maintained. Please use your own relay service. Mainnet: https://sdk.readrelay.quantumcoinapi.com
52
+ * @param {string} writeUrl - The Write API URL pointing to a write relay. See https://github.com/quantumcoinproject/quantum-coin-go/tree/dogep/relay. The following URLs are community maintained. Please use your own relay service. Mainnet: https://sdk.writerelay.quantumcoinapi.com
50
53
  * @param {number} chainId - The chain id of the blockchain. Mainnet chainId is 123123. Testnet T4 chainId is 310324.
51
54
  * @param {string} readApiKey - Optional parameter if authorization is enabled for the relay service. API Key for authorization. Defaults to null which indicates no authorization.
52
55
  * @param {string} writeApiKey - Optional parameter if authorization is enabled for the relay service. API Key for authorization. Defaults to null which indicates no authorization.
@@ -54,14 +57,14 @@ class Config {
54
57
 
55
58
  constructor(readUrl, writeUrl, chainId, readApiKey, writeApiKey) {
56
59
  /**
57
- * The Read API URL pointing to a read relay. See https://github.com/DogeProtocol/go-dp/tree/dogep/relay
60
+ * The Read API URL pointing to a read relay. See https://github.com/quantumcoinproject/quantum-coin-go/tree/dogep/relay
58
61
  * @type {string}
59
62
  * @public
60
63
  */
61
64
  this.readUrl = readUrl;
62
65
 
63
66
  /**
64
- * The Read API URL pointing to a read relay. See https://github.com/DogeProtocol/go-dp/tree/dogep/relay
67
+ * The Read API URL pointing to a read relay. See https://github.com/quantumcoinproject/quantum-coin-go/tree/dogep/relay
65
68
  * @type {string}
66
69
  * @public
67
70
  */
@@ -94,7 +97,7 @@ class Config {
94
97
  * @class
95
98
  * @constructor
96
99
  * @public
97
- * @classdesc This class represents a Wallet. Use the verifyWallet function to verify if a wallet is valid. Verifying the wallet is highly recommended, especially if it comes from an untrusted source. For more details on the underlying cryptography of the Wallet, see https://github.com/DogeProtocol/hybrid-pqc
100
+ * @classdesc This class represents a Wallet. Use the verifyWallet function to verify if a wallet is valid. Verifying the wallet is highly recommended, especially if it comes from an untrusted source. For more details on the underlying cryptography of the Wallet, see https://github.com/QuantumCoinProject/hybrid-pqc
98
101
  */
99
102
  class Wallet {
100
103
  /**
@@ -152,7 +155,7 @@ class BlockDetails {
152
155
  * @classdesc This class represents a result from invoking the getLatestBlock function.
153
156
  */
154
157
  class LatestBlockDetailsResult {
155
- constructor(resultCode, blockDetails, response, requestId) {
158
+ constructor(resultCode, blockDetails, response, requestId, err) {
156
159
  /**
157
160
  * Represents the result of the operation. A value of 0 represents that the operation succeeded. Any other value indicates the operation failed. See the result code section for more details.
158
161
  * @type {number}
@@ -180,6 +183,13 @@ class LatestBlockDetailsResult {
180
183
  * @public
181
184
  */
182
185
  this.requestId = requestId;
186
+
187
+ /**
188
+ * An error object if the operation resulted in an error and there was no response. This property is defined only if the resultCode is -10000.
189
+ * @type {error}
190
+ * @public
191
+ */
192
+ this.err = err;
183
193
  }
184
194
  }
185
195
 
@@ -228,7 +238,7 @@ class AccountDetails {
228
238
  * @classdesc This class represents a result from invoking the getAccountDetails function.
229
239
  */
230
240
  class AccountDetailsResult {
231
- constructor(resultCode, accountDetails, response, requestId) {
241
+ constructor(resultCode, accountDetails, response, requestId, err) {
232
242
  /**
233
243
  * Represents the result of the operation. A value of 0 represents that the operation succeeded. Any other value indicates the operation failed. See the result code section for more details.
234
244
  * @type {number}
@@ -256,6 +266,13 @@ class AccountDetailsResult {
256
266
  * @public
257
267
  */
258
268
  this.requestId = requestId;
269
+
270
+ /**
271
+ * An error object if the operation resulted in an error and there was no response. This property is defined only if the resultCode is -10000.
272
+ * @type {error}
273
+ * @public
274
+ */
275
+ this.err = err;
259
276
  }
260
277
  }
261
278
 
@@ -299,7 +316,7 @@ class SignResult {
299
316
  * @classdesc This class represents a result from invoking the sendCoins function.
300
317
  */
301
318
  class SendResult {
302
- constructor(resultCode, txnHash, response, requestId) {
319
+ constructor(resultCode, txnHash, response, requestId, err) {
303
320
  /**
304
321
  * Represents the result of the operation. A value of 0 represents that the operation succeeded. Any other value indicates the operation failed. See the result code section for more details.
305
322
  * @type {number}
@@ -327,6 +344,13 @@ class SendResult {
327
344
  * @public
328
345
  */
329
346
  this.requestId = requestId;
347
+
348
+ /**
349
+ * An error object if the operation resulted in an error and there was no response. This property is defined only if the resultCode is -10000.
350
+ * @type {error}
351
+ * @public
352
+ */
353
+ this.err = err;
330
354
  }
331
355
  }
332
356
 
@@ -478,7 +502,7 @@ class TransactionDetails {
478
502
  * @classdesc This class represents a result from invoking the getTransactionDetails function. If transactions get discarded by the blockchain, for reasons such as due to lower than minimum gas fees or invalid nonce, the resultCode will always contain a non-zero value (failure).
479
503
  */
480
504
  class TransactionDetailsResult {
481
- constructor(resultCode, transactionDetails, response, requestId) {
505
+ constructor(resultCode, transactionDetails, response, requestId, err) {
482
506
  /**
483
507
  * Represents the result of the operation. A value of 0 represents that the operation succeeded. Any other value indicates the operation failed. See the result code section for more details.
484
508
  * @type {number}
@@ -507,6 +531,13 @@ class TransactionDetailsResult {
507
531
  * @public
508
532
  */
509
533
  this.requestId = requestId;
534
+
535
+ /**
536
+ * An error object if the operation resulted in an error and there was no response. This property is defined only if the resultCode is -10000.
537
+ * @type {error}
538
+ * @public
539
+ */
540
+ this.err = err;
510
541
  }
511
542
  }
512
543
 
@@ -595,7 +626,7 @@ class ListAccountTransactionsResponse {
595
626
  * @classdesc This class represents a result from invoking the listAccountTransactionDetails function.
596
627
  */
597
628
  class AccountTransactionsResult {
598
- constructor(resultCode, listAccountTransactionsResponse, response, requestId) {
629
+ constructor(resultCode, listAccountTransactionsResponse, response, requestId, err) {
599
630
  /**
600
631
  * Represents the result of the operation. A value of 0 represents that the operation succeeded. Any other value indicates the operation failed. See the result code section for more details.
601
632
  * @type {number}
@@ -623,6 +654,13 @@ class AccountTransactionsResult {
623
654
  * @public
624
655
  */
625
656
  this.requestId = requestId;
657
+
658
+ /**
659
+ * An error object if the operation resulted in an error and there was no response. This property is defined only if the resultCode is -10000.
660
+ * @type {error}
661
+ * @public
662
+ */
663
+ this.err = err;
626
664
  }
627
665
  }
628
666
 
@@ -714,6 +752,116 @@ function newWallet() {
714
752
  return walletRet;
715
753
  }
716
754
 
755
+ /**
756
+ * The deserializeEncryptedWallet function opens a wallet backed-up using an application such as the Desktop/Mobile/CLI/Web wallet. This function can take upto a minute or so to execute. You should open wallets only from trusted sources.
757
+ *
758
+ * @function deserializeEncryptedWallet
759
+ * @param {string} walletJsonString - The json string from a wallet file.
760
+ * @param {string} passphrase - The passphrase used to encrypt the wallet.
761
+ * @return {Wallet} Returns a Wallet object. Returns null if opening the wallet fails.
762
+ */
763
+ function deserializeEncryptedWallet(walletJsonString, passphrase) {
764
+ if (isInitialized === false) {
765
+ return -1000;
766
+ }
767
+
768
+ if (walletJsonString == null || passphrase == null) {
769
+ return null;
770
+ }
771
+
772
+ if (typeof walletJsonString === 'string' || walletJsonString instanceof String) {
773
+
774
+ } else {
775
+ return null;
776
+ }
777
+
778
+ if (typeof passphrase === 'string' || passphrase instanceof String) {
779
+
780
+ } else {
781
+ return null;
782
+ }
783
+
784
+ let walletJsonObj = JSON.parse(walletJsonString);
785
+
786
+ if (walletJsonObj == null) {
787
+ return null;
788
+ }
789
+
790
+ if (walletJsonObj.address == null) {
791
+ return null;
792
+ }
793
+
794
+ let keyPairString = JsonToWalletKeyPair(walletJsonString, passphrase);
795
+ if (keyPairString == null) {
796
+ return null;
797
+ }
798
+
799
+ let keyPairSplit = keyPairString.split(",");
800
+ if (keyPairSplit.length < 2) {
801
+ return null;
802
+ }
803
+
804
+ let privateKeyArray = base64ToBytes(keyPairSplit[0]);
805
+ let publicKeyArray = base64ToBytes(keyPairSplit[1]);
806
+ let address = PublicKeyToAddress(publicKeyArray);
807
+ if (address == null) {
808
+ return null;
809
+ }
810
+
811
+ if (typeof address === 'string' || address instanceof String) {
812
+
813
+ } else {
814
+ return null;
815
+ }
816
+
817
+ let addressCheck = "0x" + walletJsonObj.address.toLowerCase();
818
+ if (addressCheck != address.toLowerCase()) {
819
+ return null;
820
+ }
821
+
822
+ let wallet = new Wallet(address, privateKeyArray, publicKeyArray);
823
+
824
+ return wallet;
825
+ }
826
+
827
+ /**
828
+ * The serializeEncryptedWallet function encrypts and serializes a Wallet object to a JSON string readable by the Desktop/Mobile/Web/CLI wallet applications. You can save this string to a file and open the file in one of these wallet applications. You may also open this string using the deserializeEncryptedWallet function. If you loose the passphrase, you will be unable to open the wallet. This function can take upto a minute or so to execute.
829
+ *
830
+ * @function serializeEncryptedWallet
831
+ * @param {Wallet} wallet - A Wallet object representing the wallet to serialize.
832
+ * @param {string} passphrase - A passphrase used to encrypt the wallet. It should atleast be 12 characters long.
833
+ * @return {string} Returns the Wallet in JSON string format. If the wallet is invalid, null is returned.
834
+ */
835
+ function serializeEncryptedWallet(wallet, passphrase) {
836
+ if(verifyWallet(wallet) === false) {
837
+ return null;
838
+ }
839
+
840
+ if (passphrase == null) {
841
+ return null;
842
+ }
843
+
844
+ if (typeof passphrase === 'string' || passphrase instanceof String) {
845
+
846
+ } else {
847
+ return null;
848
+ }
849
+
850
+ if (passphrase.length < 12) {
851
+ return null;
852
+ }
853
+
854
+ let walletJsonString = KeyPairToWalletJson(wallet.privateKey, wallet.publicKey, passphrase);
855
+
856
+ let walletJson = JSON.parse(walletJsonString);
857
+ let addressCheck = "0x" + walletJson.address;
858
+ if (addressCheck.toLowerCase() != wallet.address.toLowerCase()) {
859
+ return null;
860
+ }
861
+
862
+ return walletJsonString;
863
+ }
864
+
717
865
  function base64ToBytes(base64) {
718
866
  const binString = atob(base64);
719
867
  return Uint8Array.from(binString, (m) => m.codePointAt(0));
@@ -902,21 +1050,25 @@ async function postTransaction(txnData) {
902
1050
 
903
1051
  let txnDataJson = JSON.stringify({ txnData: txnData });
904
1052
 
905
- const response = await fetch(url, {
906
- method: 'POST',
907
- headers: reqHeaders,
908
- body: txnDataJson
909
- });
1053
+ try {
1054
+ const response = await fetch(url, {
1055
+ method: 'POST',
1056
+ headers: reqHeaders,
1057
+ body: txnDataJson
1058
+ });
910
1059
 
911
- if (response == null) {
912
- return new SendResult(-601, null, null, requestId);
913
- }
1060
+ if (response == null) {
1061
+ return new SendResult(-601, null, null, requestId);
1062
+ }
914
1063
 
915
- if (response.status == 200 || response.status == 204) {
916
- return new SendResult(0, null, response, requestId);
917
- }
1064
+ if (response.status == 200 || response.status == 204) {
1065
+ return new SendResult(0, null, response, requestId);
1066
+ }
918
1067
 
919
- return new SendResult(-602, null, response, requestId);
1068
+ return new SendResult(-602, null, response, requestId);
1069
+ } catch(error) {
1070
+ return new SendResult(-10000, null, null, requestId, error);
1071
+ }
920
1072
  }
921
1073
 
922
1074
  /**
@@ -943,38 +1095,42 @@ async function getLatestBlockDetails() {
943
1095
 
944
1096
  var url = config.readUrl + "/latestblock";
945
1097
 
946
- const response = await fetch(url, {
947
- headers: reqHeaders,
948
- });
1098
+ try {
1099
+ const response = await fetch(url, {
1100
+ headers: reqHeaders,
1101
+ });
1102
+
1103
+ if (response == null) {
1104
+ return new LatestBlockDetailsResult(-100, null, response, requestId);
1105
+ }
1106
+ if (response.status !== 200) {
1107
+ return new LatestBlockDetailsResult(-101, null, response, requestId);
1108
+ }
949
1109
 
950
- if (response == null) {
951
- return new LatestBlockDetailsResult(-100, null, response, requestId);
952
- }
953
- if (response.status !== 200) {
954
- return new LatestBlockDetailsResult(-101, null, response, requestId);
955
- }
1110
+ const jsonObj = await response.json();
1111
+ if (jsonObj == null) {
1112
+ return new LatestBlockDetailsResult(-102, null, response, requestId);
1113
+ }
1114
+ const result = jsonObj.result;
956
1115
 
957
- const jsonObj = await response.json();
958
- if (jsonObj == null) {
959
- return new LatestBlockDetailsResult(-102, null, response, requestId);
960
- }
961
- const result = jsonObj.result;
1116
+ if (result == null) {
1117
+ return new LatestBlockDetailsResult(-103, null, response, requestId);
1118
+ }
962
1119
 
963
- if (result == null) {
964
- return new LatestBlockDetailsResult(-103, null, response, requestId);
965
- }
1120
+ if (result.blockNumber == null) {
1121
+ return new LatestBlockDetailsResult(-104, null, response, requestId);
1122
+ }
966
1123
 
967
- if (result.blockNumber == null) {
968
- return new LatestBlockDetailsResult(-104, null, response, requestId);
969
- }
1124
+ let blockNumber = parseInt(result.blockNumber);
1125
+ if (Number.isInteger(blockNumber) == false) {
1126
+ return new LatestBlockDetailsResult(-105, null, response, requestId);
1127
+ }
970
1128
 
971
- let blockNumber = parseInt(result.blockNumber);
972
- if (Number.isInteger(blockNumber) == false) {
973
- return new LatestBlockDetailsResult(-105, null, response, requestId);
1129
+ var blockDetails = new BlockDetails(blockNumber);
1130
+ return new LatestBlockDetailsResult(0, blockDetails, response, requestId);
1131
+ } catch (error) {
1132
+ return new LatestBlockDetailsResult(-10000, null, null, requestId, error);
974
1133
  }
975
-
976
- var blockDetails = new BlockDetails(blockNumber);
977
- return new LatestBlockDetailsResult(0, blockDetails, response, requestId);
978
1134
  }
979
1135
 
980
1136
  /**
@@ -1009,63 +1165,67 @@ async function getAccountDetails(address) {
1009
1165
  reqHeaders.append(API_KEY_HEADER_NAME, config.readApiKey);
1010
1166
  }
1011
1167
 
1012
-
1013
1168
  var url = config.readUrl + "/account/" + address;
1014
1169
 
1015
- const response = await fetch(url, {
1016
- headers: reqHeaders,
1017
- });
1170
+ try {
1171
+ const response = await fetch(url, {
1172
+ headers: reqHeaders,
1173
+ });
1018
1174
 
1019
- if(response == null) {
1020
- return new AccountDetailsResult(-202, null, response, requestId);
1021
- }
1022
- if (response.status !== 200) {
1023
- return new AccountDetailsResult(-203, null, response, requestId);
1024
- }
1175
+ if(response == null) {
1176
+ return new AccountDetailsResult(-202, null, response, requestId);
1177
+ }
1178
+ if (response.status !== 200) {
1179
+ return new AccountDetailsResult(-203, null, response, requestId);
1180
+ }
1025
1181
 
1026
- const jsonObj = await response.json();
1027
- if (jsonObj == null) {
1028
- return new AccountDetailsResult(-204, null, response, requestId);
1029
- }
1030
- const result = jsonObj.result;
1182
+ const jsonObj = await response.json();
1183
+ if (jsonObj == null) {
1184
+ return new AccountDetailsResult(-204, null, response, requestId);
1185
+ }
1186
+ const result = jsonObj.result;
1031
1187
 
1032
- if (result == null) {
1033
- return new AccountDetailsResult(-205, null, response, requestId);
1034
- }
1188
+ if (result == null) {
1189
+ return new AccountDetailsResult(-205, null, response, requestId);
1190
+ }
1035
1191
 
1036
- if(result.blockNumber == null) {
1037
- return new AccountDetailsResult(-206, null, response, requestId);
1038
- }
1192
+ if(result.blockNumber == null) {
1193
+ return new AccountDetailsResult(-206, null, response, requestId);
1194
+ }
1039
1195
 
1040
- let blockNumber = parseInt(result.blockNumber);
1041
- if (Number.isInteger(blockNumber) == false) {
1042
- return new AccountDetailsResult(-207, null, response, requestId);
1043
- }
1196
+ let blockNumber = parseInt(result.blockNumber);
1197
+ if (Number.isInteger(blockNumber) == false) {
1198
+ return new AccountDetailsResult(-207, null, response, requestId);
1199
+ }
1044
1200
 
1045
- if (result.nonce === null) {
1046
- nonce = 0;
1047
- } else {
1048
- let tempNonce = parseInt(result.nonce);
1049
- if (Number.isInteger(tempNonce) == true) {
1050
- nonce = tempNonce;
1051
- if (nonce < 0) {
1052
- return new AccountDetailsResult(-208, null, response, requestId);
1053
- }
1201
+ if (result.nonce === null) {
1202
+ nonce = 0;
1054
1203
  } else {
1055
- return new AccountDetailsResult(-209, null, response, requestId);
1204
+ let tempNonce = parseInt(result.nonce);
1205
+ if (Number.isInteger(tempNonce) == true) {
1206
+ nonce = tempNonce;
1207
+ if (nonce < 0) {
1208
+ return new AccountDetailsResult(-208, null, response, requestId);
1209
+ }
1210
+ } else {
1211
+ return new AccountDetailsResult(-209, null, response, requestId);
1212
+ }
1056
1213
  }
1057
- }
1058
1214
 
1059
- if (result.balance != null) {
1060
- if (isLargeNumber(result.balance) == false) {
1061
- return new AccountDetailsResult(-210, null, response, requestId);
1062
- } else {
1063
- balance = result.balance;
1215
+ if (result.balance != null) {
1216
+ if (isLargeNumber(result.balance) == false) {
1217
+ return new AccountDetailsResult(-210, null, response, requestId);
1218
+ } else {
1219
+ balance = result.balance;
1220
+ }
1064
1221
  }
1065
- }
1066
1222
 
1067
- var accountDetails = new AccountDetails(address, balance, nonce, blockNumber);
1068
- return new AccountDetailsResult(0, accountDetails, response, requestId);
1223
+ var accountDetails = new AccountDetails(address, balance, nonce, blockNumber);
1224
+ return new AccountDetailsResult(0, accountDetails, response, requestId);
1225
+
1226
+ } catch (error) {
1227
+ return new AccountDetailsResult(0, null, null, requestId, error);
1228
+ }
1069
1229
  }
1070
1230
 
1071
1231
  /**
@@ -1104,60 +1264,64 @@ async function getTransactionDetails(txnHash) {
1104
1264
 
1105
1265
  var url = config.readUrl + "/transaction/" + txnHash;
1106
1266
 
1107
- const response = await fetch(url, {
1108
- headers: reqHeaders,
1109
- });
1267
+ try {
1268
+ const response = await fetch(url, {
1269
+ headers: reqHeaders,
1270
+ });
1110
1271
 
1111
- if (response == null) {
1112
- return new TransactionDetailsResult(-302, null, response, requestId);
1113
- }
1114
- if (response.status !== 200) {
1115
- return new TransactionDetailsResult(-303, null, response, requestId);
1116
- }
1272
+ if (response == null) {
1273
+ return new TransactionDetailsResult(-302, null, response, requestId);
1274
+ }
1275
+ if (response.status !== 200) {
1276
+ return new TransactionDetailsResult(-303, null, response, requestId);
1277
+ }
1117
1278
 
1118
- const jsonObj = await response.json();
1119
- if (jsonObj == null) {
1120
- return new TransactionDetailsResult(-304, null, response, requestId);
1121
- }
1122
- const result = jsonObj.result;
1279
+ const jsonObj = await response.json();
1280
+ if (jsonObj == null) {
1281
+ return new TransactionDetailsResult(-304, null, response, requestId);
1282
+ }
1283
+ const result = jsonObj.result;
1123
1284
 
1124
- if (result == null) {
1125
- return new TransactionDetailsResult(-305, null, response, requestId);
1126
- }
1285
+ if (result == null) {
1286
+ return new TransactionDetailsResult(-305, null, response, requestId);
1287
+ }
1127
1288
 
1128
- var transactionDetails = new TransactionDetails();
1289
+ var transactionDetails = new TransactionDetails();
1129
1290
 
1130
- if (result.blockNumber !== null) {
1131
- let tempBlockNumber = parseInt(result.blockNumber);
1132
- if (Number.isInteger(tempBlockNumber) == true) {
1133
- transactionDetails.blockNumber = tempBlockNumber;
1134
- }
1135
- if (tempBlockNumber < 0) {
1136
- return new TransactionDetailsResult(-306, null, response, requestId);
1291
+ if (result.blockNumber !== null) {
1292
+ let tempBlockNumber = parseInt(result.blockNumber);
1293
+ if (Number.isInteger(tempBlockNumber) == true) {
1294
+ transactionDetails.blockNumber = tempBlockNumber;
1295
+ }
1296
+ if (tempBlockNumber < 0) {
1297
+ return new TransactionDetailsResult(-306, null, response, requestId);
1298
+ }
1137
1299
  }
1138
- }
1139
1300
 
1140
- transactionDetails.blockHash = result.blockHash;
1141
- transactionDetails.from = result.from;
1142
- transactionDetails.gas = result.gas;
1143
- transactionDetails.gasPrice = result.gasPrice;
1144
- transactionDetails.hash = result.hash;
1145
- transactionDetails.input = result.input;
1146
- transactionDetails.nonce = result.nonce;
1147
- transactionDetails.to = result.to;
1148
- transactionDetails.value = result.value;
1149
-
1150
- if(result.receipt !== null) {
1151
- transactionDetails.receipt = new TransactionReceipt();
1152
- transactionDetails.receipt.cumulativeGasUsed = result.receipt.cumulativeGasUsed;
1153
- transactionDetails.receipt.effectiveGasPrice = result.receipt.effectiveGasPrice;
1154
- transactionDetails.receipt.gasUsed = result.receipt.gasUsed;
1155
- transactionDetails.receipt.status = result.receipt.status;
1156
- transactionDetails.receipt.hash = result.receipt.hash;
1157
- transactionDetails.receipt.type = result.receipt.type;
1158
- }
1301
+ transactionDetails.blockHash = result.blockHash;
1302
+ transactionDetails.from = result.from;
1303
+ transactionDetails.gas = result.gas;
1304
+ transactionDetails.gasPrice = result.gasPrice;
1305
+ transactionDetails.hash = result.hash;
1306
+ transactionDetails.input = result.input;
1307
+ transactionDetails.nonce = result.nonce;
1308
+ transactionDetails.to = result.to;
1309
+ transactionDetails.value = result.value;
1310
+
1311
+ if(result.receipt !== null) {
1312
+ transactionDetails.receipt = new TransactionReceipt();
1313
+ transactionDetails.receipt.cumulativeGasUsed = result.receipt.cumulativeGasUsed;
1314
+ transactionDetails.receipt.effectiveGasPrice = result.receipt.effectiveGasPrice;
1315
+ transactionDetails.receipt.gasUsed = result.receipt.gasUsed;
1316
+ transactionDetails.receipt.status = result.receipt.status;
1317
+ transactionDetails.receipt.hash = result.receipt.hash;
1318
+ transactionDetails.receipt.type = result.receipt.type;
1319
+ }
1159
1320
 
1160
- return new TransactionDetailsResult(0, transactionDetails, response, requestId);
1321
+ return new TransactionDetailsResult(0, transactionDetails, response, requestId);
1322
+ } catch (error) {
1323
+ return new TransactionDetailsResult(0, null, null, requestId, error);
1324
+ }
1161
1325
  }
1162
1326
 
1163
1327
  /**
@@ -1171,7 +1335,7 @@ async function getTransactionDetails(txnHash) {
1171
1335
  * @async
1172
1336
  * @function listAccountTransactions
1173
1337
  * @param {string} address - The address for which the transactions have to be listed.
1174
- * @param {number} pageNumber - The page number for which the transactions has to be listed for the account. Pass 0 to list the latest page.
1338
+ * @param {number} pageNumber - The page number for which the transactions has to be listed for the account. Pass 0 to list the latest page. Pass 1 to list the oldest page. A maximum of 20 transactions are returned in each page. The response of this API includes a field that shows the pageCount (total number of pages available). You can pass any number between 1 to pageCount to get the corresponding page.
1175
1339
  * @return {Promise<ListAccountTransactionsResponse>} Returns a promise of type type ListAccountTransactionsResponse.
1176
1340
  */
1177
1341
  async function listAccountTransactions(address, pageNumber) {
@@ -1205,58 +1369,64 @@ async function listAccountTransactions(address, pageNumber) {
1205
1369
  var url = config.readUrl + "/account/" + address + "/transactions/" + pageNumber;
1206
1370
  console.log(url);
1207
1371
 
1208
- const response = await fetch(url, {
1209
- headers: reqHeaders,
1210
- });
1372
+ try {
1373
+ const response = await fetch(url, {
1374
+ headers: reqHeaders,
1375
+ });
1211
1376
 
1212
- if (response === null) {
1213
- return new AccountTransactionsResult(-703, null, response, requestId);
1214
- }
1215
- if (response.status !== 200) {
1216
- return new AccountTransactionsResult(-704, null, response, requestId);
1217
- }
1377
+ if (response === null) {
1378
+ return new AccountTransactionsResult(-703, null, response, requestId);
1379
+ }
1380
+ if (response.status !== 200) {
1381
+ return new AccountTransactionsResult(-704, null, response, requestId);
1382
+ }
1218
1383
 
1219
- const jsonObj = await response.json();
1384
+ const jsonObj = await response.json();
1220
1385
 
1221
- if (jsonObj === null) {
1222
- return new AccountTransactionsResult(-705, null, response, requestId);
1223
- }
1224
- const result = jsonObj;
1386
+ if (jsonObj === null) {
1387
+ return new AccountTransactionsResult(-705, null, response, requestId);
1388
+ }
1389
+ const result = jsonObj;
1225
1390
 
1226
- if (result.pageCount === null) {
1227
- return new AccountTransactionsResult(-706, null, response, requestId);
1228
- }
1391
+ if (result.pageCount === null) {
1392
+ return new AccountTransactionsResult(-706, null, response, requestId);
1393
+ }
1229
1394
 
1230
- var listAccountDetailsResponse = new ListAccountTransactionsResponse();
1395
+ var listAccountDetailsResponse = new ListAccountTransactionsResponse();
1231
1396
 
1232
- let tempPageCount = parseInt(result.pageCount);
1233
- if (Number.isInteger(tempPageCount) === true) {
1234
- listAccountDetailsResponse.pageCount = tempPageCount;
1235
- }
1397
+ let tempPageCount = parseInt(result.pageCount);
1398
+ if (Number.isInteger(tempPageCount) === true) {
1399
+ listAccountDetailsResponse.pageCount = tempPageCount;
1400
+ }
1236
1401
 
1237
- if (result.items !== null) {
1238
- if (Array.isArray(result.items) === false) {
1239
- return new AccountTransactionsResult(-707, null, response, requestId);
1402
+ if (result.items !== null) {
1403
+ if (Array.isArray(result.items) === false) {
1404
+ return new AccountTransactionsResult(-707, null, response, requestId);
1405
+ }
1406
+ listAccountDetailsResponse.items = new Array();
1407
+ for (const item of result.items) {
1408
+ let txn = new AccountTransactionCompact();
1409
+ txn.blockNumber = item.blockNumber;
1410
+ txn.from = item.from;
1411
+ txn.hash = item.hash;
1412
+ txn.to = item.to;
1413
+ txn.value = item.value;
1414
+ txn.status = item.status;
1415
+ listAccountDetailsResponse.items.push(txn);
1416
+ }
1240
1417
  }
1241
- listAccountDetailsResponse.items = new Array();
1242
- for (const item of result.items) {
1243
- let txn = new AccountTransactionCompact();
1244
- txn.blockNumber = item.blockNumber;
1245
- txn.from = item.from;
1246
- txn.hash = item.hash;
1247
- txn.to = item.to;
1248
- txn.value = item.value;
1249
- txn.status = item.status;
1250
- listAccountDetailsResponse.items.push(txn);
1251
- }
1252
- }
1253
-
1254
- return new AccountTransactionsResult(0, listAccountDetailsResponse, response, requestId);
1418
+
1419
+ return new AccountTransactionsResult(0, listAccountDetailsResponse, response, requestId);
1420
+ } catch (error) {
1421
+ return new AccountTransactionsResult(0, null, null, requestId, error);
1422
+ }
1255
1423
  }
1256
1424
 
1257
1425
  /**
1258
1426
  * The signSendCoinTransaction function returns a signed transaction.
1427
+ * Since the gas fee for sending coins is fixed at 1000 coins, there is no option to set the gas fee explicitly.
1259
1428
  * This function is useful for offline (cold storage) wallets, where you can sign a transaction offline and then use the postTransaction function to post it on a connected device.
1429
+ * Another usecase for this function is when you want to first store a signed transaction to a database, then queue it and finally submit the transaction by calling the postTransaction function.
1260
1430
  *
1261
1431
  * @function signSendCoinTransaction
1262
1432
  * @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.
@@ -1324,6 +1494,7 @@ async function signSendCoinTransaction(wallet, toAddress, coins, nonce) {
1324
1494
 
1325
1495
  /**
1326
1496
  * The sendCoins function posts a send-coin transaction to the blockchain.
1497
+ * Since the gas fee for sending coins is fixed at 1000 coins, there is no option to set the gas fee explicitly.
1327
1498
  * It may take many seconds after submitting a transaction before the transaction is returned by the getTransactionDetails function.
1328
1499
  * Transactions are usually committed in less than 30 seconds.
1329
1500
  *
@@ -1412,6 +1583,8 @@ module.exports = {
1412
1583
  initialize,
1413
1584
  serializeWallet,
1414
1585
  deserializeWallet,
1586
+ serializeEncryptedWallet,
1587
+ deserializeEncryptedWallet,
1415
1588
  verifyWallet,
1416
1589
  newWallet,
1417
1590
  sendCoins,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quantum-coin-js-sdk",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
4
4
  "description": "Quantum Coin - Q SDK in JavaScript",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/wasm_exec.js CHANGED
@@ -1,6 +1,32 @@
1
- // Copyright 2018 The Go Authors. All rights reserved.
2
- // Use of this source code is governed by a BSD-style
3
- // license that can be found in the LICENSE file.
1
+ /*
2
+ Copyright 2009 The Go Authors.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are
6
+ met:
7
+
8
+ * Redistributions of source code must retain the above copyright
9
+ notice, this list of conditions and the following disclaimer.
10
+ * Redistributions in binary form must reproduce the above
11
+ copyright notice, this list of conditions and the following disclaimer
12
+ in the documentation and/or other materials provided with the
13
+ distribution.
14
+ * Neither the name of Google LLC nor the names of its
15
+ contributors may be used to endorse or promote products derived from
16
+ this software without specific prior written permission.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
+ */
4
30
 
5
31
  "use strict";
6
32
 
@@ -558,4 +584,4 @@
558
584
  };
559
585
  }
560
586
  }
561
- })();
587
+ })();