quantum-coin-js-sdk 1.0.19 → 1.0.21

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
Binary file
@@ -1,5 +1,6 @@
1
1
  const qcsdk = require('quantum-coin-js-sdk');
2
2
  const ethers = require('ethers');
3
+ const pqc = require("quantum-coin-pqc-js-sdk");
3
4
 
4
5
  var clientConfigVal = new qcsdk.Config("https://sdk.readrelay.quantumcoinapi.com", "https://sdk.writerelay.quantumcoinapi.com", 123123, "", ""); //Mainnet
5
6
 
@@ -39,12 +40,33 @@ qcsdk.initialize(clientConfigVal).then((initResult) => {
39
40
  console.log("walletExample.privateKey length " + walletExample.privateKey.length);
40
41
  let publicKey2 = qcsdk.publicKeyFromPrivateKey(walletExample.privateKey);
41
42
  console.log("publicKeyFromPrivateKey publicKey length: " + publicKey2.length);
42
- if (publicKey2.length !== walletExample.publicKey.length) {
43
- throw new Error("public key length compare failed");
43
+ let publicKey2Bytes = hexToBytes(publicKey2);
44
+ if (publicKey2Bytes.length !== walletExample.publicKey.length) {
45
+ throw new Error("public key length compare failed S");
44
46
  }
45
- for (i = 0; i < publicKey2.length; i++) {
46
- if (publicKey2[i] !== walletExample.publicKey[i]) {
47
- throw new Error("public key compare failed");
47
+ for (let i = 0; i < publicKey2Bytes.length; i++) {
48
+ if (publicKey2Bytes[i] !== walletExample.publicKey[i]) {
49
+ throw new Error("public key compare failed A");
50
+ }
51
+ }
52
+
53
+ let utf8Encode = new TextEncoder();
54
+ let message = utf8Encode.encode("verifyverifyverifyverifyverifyok");
55
+
56
+ let quantumSig = pqc.cryptoSign(message, walletExample.privateKey);
57
+ let combinedSignatureHex = qcsdk.combinePublicKeySignature(walletExample.publicKey, quantumSig);
58
+ if (combinedSignatureHex === null) {
59
+ throw new Error("combinePublicKeySignature combine failed");
60
+ }
61
+ let combinedSignatureBytes = hexToBytes(combinedSignatureHex);
62
+ let publicKeySigHex = qcsdk.publicKeyFromSignature(message, combinedSignatureBytes);
63
+ let publicKeySigBytes = hexToBytes(publicKeySigHex);
64
+ if (publicKeySigBytes.length !== walletExample.publicKey.length) {
65
+ throw new Error("public key length compare failed B");
66
+ }
67
+ for (let i = 0; i < publicKeySigBytes.length; i++) {
68
+ if (publicKeySigBytes[i] !== walletExample.publicKey[i]) {
69
+ throw new Error("public key compare failed B");
48
70
  }
49
71
  }
50
72
 
@@ -55,3 +77,21 @@ function base64ToBytes(base64) {
55
77
  return Uint8Array.from(binString, (m) => m.codePointAt(0));
56
78
  }
57
79
 
80
+ // Convert a hex string to a byte array
81
+ function hexToBytes(hex) {
82
+ let bytes = [];
83
+ for (let c = 0; c < hex.length; c += 2)
84
+ bytes.push(parseInt(hex.substr(c, 2), 16));
85
+ return bytes;
86
+ }
87
+
88
+ // Convert a byte array to a hex string
89
+ function bytesToHex(bytes) {
90
+ let hex = [];
91
+ for (let i = 0; i < bytes.length; i++) {
92
+ let current = bytes[i] < 0 ? bytes[i] + 256 : bytes[i];
93
+ hex.push((current >>> 4).toString(16));
94
+ hex.push((current & 0xF).toString(16));
95
+ }
96
+ return hex.join("");
97
+ }
@@ -0,0 +1,43 @@
1
+ const qcsdk = require('quantum-coin-js-sdk');
2
+
3
+ var clientConfigVal = new qcsdk.Config("https://sdk.readrelay.quantumcoinapi.com", "https://sdk.writerelay.quantumcoinapi.com", 123123, "", ""); //Mainnet
4
+
5
+
6
+ //Initialize the client configuration
7
+ //var clientConfigVal = new qcsdk.Config("https://t4-relayread.quantumcoin.org", "https://t4-relaywrite.quantumcoin.org", 310324, "", ""); //Testnet T4
8
+ //Testnet T4 Block Explorer: https://t4.scan.quantumcoin.org
9
+
10
+ //For mainnet, use the following configuration
11
+ //var clientConfigVal = new qcsdk.Config("https://sdk.readrelay.quantumcoinapi.com", "https://sdk.writerelay.quantumcoinapi.com", 123123, "", ""); //Mainnet
12
+ //Mainnet Block Explorer: https://scan.quantumcoin.org
13
+
14
+ //Local testing configuration
15
+ //var clientConfigVal = new qcsdk.Config("http://127.0.0.1:9090", "http://127.0.0.1:9091", 123123, "", ""); //local testing
16
+ //Mainnet Block Explorer: https://scan.quantumcoin.org
17
+
18
+
19
+ //Initialize the SDK
20
+ qcsdk.initialize(clientConfigVal).then((initResult) => {
21
+ if (initResult === false) {
22
+ console.error("Initialize failed");
23
+ return;
24
+ }
25
+
26
+ let examplePassphrase = "helloworld123";
27
+
28
+ //Save to an encrypted wallet that can then be restored into an external wallet application such as Desktop/Web/CLI/Mobile wallet
29
+ let walletObj2 = qcsdk.newWallet();
30
+ let walletEncryptedJson2 = qcsdk.serializeEncryptedWallet(walletObj2, examplePassphrase);
31
+ if (walletEncryptedJson2 === null) {
32
+ throw new Error("serializeEncryptedWallet failed");
33
+ }
34
+ let walletEncryptedJson3 = qcsdk.serializeEncryptedWallet(walletObj2, examplePassphrase);
35
+ if (walletEncryptedJson3 === null) {
36
+ throw new Error("serializeEncryptedWallet failed");
37
+ }
38
+ console.log("Serialized wallet A: " + walletEncryptedJson2); //just an example for demonstration, do not actually log to console
39
+ console.log("Serialized wallet B: " + walletEncryptedJson3); //just an example for demonstration, do not actually log to console
40
+
41
+
42
+ });
43
+
@@ -10,13 +10,15 @@
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "ethers": "^6.13.4",
13
- "quantum-coin-js-sdk": "file:.."
13
+ "quantum-coin-js-sdk": "file:..",
14
+ "quantum-coin-pqc-js-sdk": "^1.0.5"
14
15
  }
15
16
  },
16
17
  "..": {
17
- "version": "1.0.19",
18
+ "version": "1.0.21",
18
19
  "license": "MIT",
19
20
  "dependencies": {
21
+ "jsdoc-to-markdown": "^9.1.2",
20
22
  "quantum-coin-pqc-js-sdk": "^1.0.0",
21
23
  "seed-words": "^1.0.1"
22
24
  }
@@ -98,6 +100,12 @@
98
100
  "resolved": "..",
99
101
  "link": true
100
102
  },
103
+ "node_modules/quantum-coin-pqc-js-sdk": {
104
+ "version": "1.0.5",
105
+ "resolved": "https://registry.npmjs.org/quantum-coin-pqc-js-sdk/-/quantum-coin-pqc-js-sdk-1.0.5.tgz",
106
+ "integrity": "sha512-9P1YDkca5CqrO7++TnGJZzPvYlBjYARopHgxYbDcEHgPicP7+tA8zD+DE1BooHp7sLEWF9ObklMj6AdaDUjDVw==",
107
+ "license": "MIT"
108
+ },
101
109
  "node_modules/tslib": {
102
110
  "version": "2.7.0",
103
111
  "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.7.0.tgz",
@@ -10,6 +10,7 @@
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "ethers": "^6.13.4",
13
- "quantum-coin-js-sdk": "^1.0.19"
13
+ "quantum-coin-js-sdk": "file:..",
14
+ "quantum-coin-pqc-js-sdk": "^1.0.5"
14
15
  }
15
16
  }
package/index.d.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * @async
5
5
  * @function initialize
6
- * @param {Config} clientConfig - A configuration represented by the Config class
6
+ * @param {Config} clientConfig - A configuration represented by the Config class. A default configuration is used, if not specified.
7
7
  * @return {Promise<boolean>} Returns a promise of type boolean; true if the initialization succeeded, else false.
8
8
  */
9
9
  export function initialize(clientConfig: Config): Promise<boolean>;
@@ -675,25 +675,34 @@ export function openWalletFromSeedWords(seedWordList: any[]): Wallet;
675
675
  * @function publicKeyFromSignature
676
676
  * @param {number[]} digest - An array of bytes containing the digestHash. Should be of length 32.
677
677
  * @param {number[]} signature - An array of bytes containing the signature.
678
- * @return {number[]} - Returns a byte array containing the public key. Returns null if the operation failed.
678
+ * @return {string} - Returns the public key as a hex string. Returns null if the operation failed.
679
679
  */
680
- export function publicKeyFromSignature(digest: number[], signature: number[]): number[];
680
+ export function publicKeyFromSignature(digest: number[], signature: number[]): string;
681
681
  /**
682
682
  * The publicKeyFromPrivateKey extracts the public key from a private key.
683
683
  *
684
684
  * @function publicKeyFromPrivateKey
685
685
  * @param {number[]} privateKey - An array of bytes containing the privateKey.
686
- * @return {number[]} - Returns a byte array containing the public key. Returns null if the operation failed.
686
+ * @return {string} - Returns the public key as a hex string. Returns null if the operation failed.
687
687
  */
688
- export function publicKeyFromPrivateKey(privateKey: number[]): number[];
688
+ export function publicKeyFromPrivateKey(privateKey: number[]): string;
689
689
  /**
690
690
  * The addressFromPublicKey returns the address corresponding to the public key.
691
691
  *
692
692
  * @function addressFromPublicKey
693
693
  * @param {number[]} publicKey - An array of bytes containing the public key.
694
- * @return {string} - Returns a hex string corresponding to the public key. Returns null if the operation failed.
694
+ * @return {string} - Returns the address corresponding to the public key as a hex string. Returns null if the operation failed.
695
695
  */
696
696
  export function addressFromPublicKey(publicKey: number[]): string;
697
+ /**
698
+ * The combinePublicKeySignature combines the public key and signature.
699
+ *
700
+ * @function combinePublicKeySignature
701
+ * @param {number[]} publicKey - An array of bytes containing the public key.
702
+ * @param {number[]} signature - An array of bytes containing the signature.
703
+ * @return {string} - Returns a hex string corresponding to combined signature. Returns null if the operation failed.
704
+ */
705
+ export function combinePublicKeySignature(publicKey: number[], signature: number[]): string;
697
706
  /**
698
707
  * @class
699
708
  * @constructor