quantum-coin-js-sdk 1.0.18 → 1.0.20
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 +33 -6
- package/example/example-misc.js +45 -5
- package/example/example.js +8 -0
- package/example/package-lock.json +12 -15
- package/example/package.json +2 -1
- package/index.d.ts +21 -4
- package/index.js +51 -20
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -108,8 +108,10 @@ Requires Node.js version v20.18.1 or higher
|
|
|
108
108
|
* [~listAccountTransactions(address, pageNumber)](#module_quantum-coin-js-sdk..listAccountTransactions) ⇒ <code>Promise.<ListAccountTransactionsResponse></code>
|
|
109
109
|
* [~signSendCoinTransaction(wallet, toAddress, coins, nonce)](#module_quantum-coin-js-sdk..signSendCoinTransaction) ⇒ <code>SignResult</code>
|
|
110
110
|
* [~sendCoins(wallet, toAddress, coins, nonce)](#module_quantum-coin-js-sdk..sendCoins) ⇒ <code>Promise.<SendResult></code>
|
|
111
|
-
* [~publicKeyFromSignature(digest, signature)](#module_quantum-coin-js-sdk..publicKeyFromSignature) ⇒ <code>
|
|
112
|
-
* [~publicKeyFromPrivateKey(privateKey)](#module_quantum-coin-js-sdk..publicKeyFromPrivateKey) ⇒ <code>
|
|
111
|
+
* [~publicKeyFromSignature(digest, signature)](#module_quantum-coin-js-sdk..publicKeyFromSignature) ⇒ <code>string</code>
|
|
112
|
+
* [~publicKeyFromPrivateKey(privateKey)](#module_quantum-coin-js-sdk..publicKeyFromPrivateKey) ⇒ <code>string</code>
|
|
113
|
+
* [~addressFromPublicKey(publicKey)](#module_quantum-coin-js-sdk..addressFromPublicKey) ⇒ <code>string</code>
|
|
114
|
+
* [~combinePublicKeySignature(publicKey, signature)](#module_quantum-coin-js-sdk..combinePublicKeySignature) ⇒ <code>string</code>
|
|
113
115
|
|
|
114
116
|
<a name="module_quantum-coin-js-sdk..Config"></a>
|
|
115
117
|
|
|
@@ -1003,11 +1005,11 @@ The sendCoins function posts a send-coin transaction to the blockchain.
|
|
|
1003
1005
|
|
|
1004
1006
|
<a name="module_quantum-coin-js-sdk..publicKeyFromSignature"></a>
|
|
1005
1007
|
|
|
1006
|
-
### quantum-coin-js-sdk~publicKeyFromSignature(digest, signature) ⇒ <code>
|
|
1008
|
+
### quantum-coin-js-sdk~publicKeyFromSignature(digest, signature) ⇒ <code>string</code>
|
|
1007
1009
|
The publicKeyFromSignature extracts the public key from a signature.
|
|
1008
1010
|
|
|
1009
1011
|
**Kind**: inner method of [<code>quantum-coin-js-sdk</code>](#module_quantum-coin-js-sdk)
|
|
1010
|
-
**Returns**: <code>
|
|
1012
|
+
**Returns**: <code>string</code> - - Returns the public key as a hex string. Returns null if the operation failed.
|
|
1011
1013
|
|
|
1012
1014
|
| Param | Type | Description |
|
|
1013
1015
|
| --- | --- | --- |
|
|
@@ -1016,13 +1018,38 @@ The publicKeyFromSignature extracts the public key from a signature.
|
|
|
1016
1018
|
|
|
1017
1019
|
<a name="module_quantum-coin-js-sdk..publicKeyFromPrivateKey"></a>
|
|
1018
1020
|
|
|
1019
|
-
### quantum-coin-js-sdk~publicKeyFromPrivateKey(privateKey) ⇒ <code>
|
|
1021
|
+
### quantum-coin-js-sdk~publicKeyFromPrivateKey(privateKey) ⇒ <code>string</code>
|
|
1020
1022
|
The publicKeyFromPrivateKey extracts the public key from a private key.
|
|
1021
1023
|
|
|
1022
1024
|
**Kind**: inner method of [<code>quantum-coin-js-sdk</code>](#module_quantum-coin-js-sdk)
|
|
1023
|
-
**Returns**: <code>
|
|
1025
|
+
**Returns**: <code>string</code> - - Returns the public key as a hex string. Returns null if the operation failed.
|
|
1024
1026
|
|
|
1025
1027
|
| Param | Type | Description |
|
|
1026
1028
|
| --- | --- | --- |
|
|
1027
1029
|
| privateKey | <code>Array.<number></code> | An array of bytes containing the privateKey. |
|
|
1028
1030
|
|
|
1031
|
+
<a name="module_quantum-coin-js-sdk..addressFromPublicKey"></a>
|
|
1032
|
+
|
|
1033
|
+
### quantum-coin-js-sdk~addressFromPublicKey(publicKey) ⇒ <code>string</code>
|
|
1034
|
+
The addressFromPublicKey returns the address corresponding to the public key.
|
|
1035
|
+
|
|
1036
|
+
**Kind**: inner method of [<code>quantum-coin-js-sdk</code>](#module_quantum-coin-js-sdk)
|
|
1037
|
+
**Returns**: <code>string</code> - - Returns the address corresponding to the public key as a hex string. Returns null if the operation failed.
|
|
1038
|
+
|
|
1039
|
+
| Param | Type | Description |
|
|
1040
|
+
| --- | --- | --- |
|
|
1041
|
+
| publicKey | <code>Array.<number></code> | An array of bytes containing the public key. |
|
|
1042
|
+
|
|
1043
|
+
<a name="module_quantum-coin-js-sdk..combinePublicKeySignature"></a>
|
|
1044
|
+
|
|
1045
|
+
### quantum-coin-js-sdk~combinePublicKeySignature(publicKey, signature) ⇒ <code>string</code>
|
|
1046
|
+
The combinePublicKeySignature combines the public key and signature.
|
|
1047
|
+
|
|
1048
|
+
**Kind**: inner method of [<code>quantum-coin-js-sdk</code>](#module_quantum-coin-js-sdk)
|
|
1049
|
+
**Returns**: <code>string</code> - - Returns a hex string corresponding to combined signature. Returns null if the operation failed.
|
|
1050
|
+
|
|
1051
|
+
| Param | Type | Description |
|
|
1052
|
+
| --- | --- | --- |
|
|
1053
|
+
| publicKey | <code>Array.<number></code> | An array of bytes containing the public key. |
|
|
1054
|
+
| signature | <code>Array.<number></code> | An array of bytes containing the signature. |
|
|
1055
|
+
|
package/example/example-misc.js
CHANGED
|
@@ -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
|
-
|
|
43
|
-
|
|
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 <
|
|
46
|
-
if (
|
|
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
|
+
}
|
package/example/example.js
CHANGED
|
@@ -172,6 +172,14 @@ qcsdk.initialize(clientConfigVal).then((initResult) => {
|
|
|
172
172
|
console.log("isAddressValid (expected true)" + qcsdk.isAddressValid(wallet1.address)); //should print true
|
|
173
173
|
console.log("isAddressValid (expected false)" + qcsdk.isAddressValid("asfasdfasdfs")); //should print false
|
|
174
174
|
|
|
175
|
+
//Retrieve address from public key
|
|
176
|
+
let addressTemp = qcsdk.addressFromPublicKey(wallet2.publicKey);
|
|
177
|
+
console.log("addressFromPublicKey: " + addressTemp);
|
|
178
|
+
if (addressTemp !== wallet2.address) {
|
|
179
|
+
throw new Error("addressFromPublicKey doesn't match: " + addressTemp + " " + wallet2.publicKey);
|
|
180
|
+
}
|
|
181
|
+
return;
|
|
182
|
+
|
|
175
183
|
//Send coins
|
|
176
184
|
//First get account details nonce
|
|
177
185
|
console.log("sendCoins getAccountDetails " + address);
|
|
@@ -10,7 +10,16 @@
|
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"ethers": "^6.13.4",
|
|
13
|
-
"quantum-coin-js-sdk": "
|
|
13
|
+
"quantum-coin-js-sdk": "file:..",
|
|
14
|
+
"quantum-coin-pqc-js-sdk": "^1.0.5"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"..": {
|
|
18
|
+
"version": "1.0.20",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"quantum-coin-pqc-js-sdk": "^1.0.0",
|
|
22
|
+
"seed-words": "^1.0.1"
|
|
14
23
|
}
|
|
15
24
|
},
|
|
16
25
|
"node_modules/@adraffy/ens-normalize": {
|
|
@@ -87,14 +96,8 @@
|
|
|
87
96
|
}
|
|
88
97
|
},
|
|
89
98
|
"node_modules/quantum-coin-js-sdk": {
|
|
90
|
-
"
|
|
91
|
-
"
|
|
92
|
-
"integrity": "sha512-PhpNkNDXOmBHOyyakeUUsj8rBnJ/Tr3ZXmpgd6M8n7qvo1vsoiuBjSWEIJR2YvsIiPOpRCIJqq8E59sCJ9+1Zg==",
|
|
93
|
-
"license": "MIT",
|
|
94
|
-
"dependencies": {
|
|
95
|
-
"quantum-coin-pqc-js-sdk": "^1.0.0",
|
|
96
|
-
"seed-words": "^1.0.1"
|
|
97
|
-
}
|
|
99
|
+
"resolved": "..",
|
|
100
|
+
"link": true
|
|
98
101
|
},
|
|
99
102
|
"node_modules/quantum-coin-pqc-js-sdk": {
|
|
100
103
|
"version": "1.0.5",
|
|
@@ -102,12 +105,6 @@
|
|
|
102
105
|
"integrity": "sha512-9P1YDkca5CqrO7++TnGJZzPvYlBjYARopHgxYbDcEHgPicP7+tA8zD+DE1BooHp7sLEWF9ObklMj6AdaDUjDVw==",
|
|
103
106
|
"license": "MIT"
|
|
104
107
|
},
|
|
105
|
-
"node_modules/seed-words": {
|
|
106
|
-
"version": "1.0.2",
|
|
107
|
-
"resolved": "https://registry.npmjs.org/seed-words/-/seed-words-1.0.2.tgz",
|
|
108
|
-
"integrity": "sha512-ia58deuPjcR8DpJ8uIgZ7gqDnIWD8vnjb4jX/sEsIDcuQaH/AJj9J8L3DXkUHfUGqAq9Y6pVMuG90t3XUJH90g==",
|
|
109
|
-
"license": "MIT"
|
|
110
|
-
},
|
|
111
108
|
"node_modules/tslib": {
|
|
112
109
|
"version": "2.7.0",
|
|
113
110
|
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.7.0.tgz",
|
package/example/package.json
CHANGED
package/index.d.ts
CHANGED
|
@@ -675,17 +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 {
|
|
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[]):
|
|
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 {
|
|
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[]):
|
|
688
|
+
export function publicKeyFromPrivateKey(privateKey: number[]): string;
|
|
689
|
+
/**
|
|
690
|
+
* The addressFromPublicKey returns the address corresponding to the public key.
|
|
691
|
+
*
|
|
692
|
+
* @function addressFromPublicKey
|
|
693
|
+
* @param {number[]} publicKey - An array of bytes containing the public key.
|
|
694
|
+
* @return {string} - Returns the address corresponding to the public key as a hex string. Returns null if the operation failed.
|
|
695
|
+
*/
|
|
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;
|
|
689
706
|
/**
|
|
690
707
|
* @class
|
|
691
708
|
* @constructor
|