quantum-coin-js-sdk 1.0.19 → 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 +21 -7
- package/example/example-misc.js +45 -5
- package/example/package-lock.json +9 -2
- package/example/package.json +2 -1
- package/index.d.ts +14 -5
- package/index.js +35 -24
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -108,9 +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
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>
|
|
114
115
|
|
|
115
116
|
<a name="module_quantum-coin-js-sdk..Config"></a>
|
|
116
117
|
|
|
@@ -1004,11 +1005,11 @@ The sendCoins function posts a send-coin transaction to the blockchain.
|
|
|
1004
1005
|
|
|
1005
1006
|
<a name="module_quantum-coin-js-sdk..publicKeyFromSignature"></a>
|
|
1006
1007
|
|
|
1007
|
-
### quantum-coin-js-sdk~publicKeyFromSignature(digest, signature) ⇒ <code>
|
|
1008
|
+
### quantum-coin-js-sdk~publicKeyFromSignature(digest, signature) ⇒ <code>string</code>
|
|
1008
1009
|
The publicKeyFromSignature extracts the public key from a signature.
|
|
1009
1010
|
|
|
1010
1011
|
**Kind**: inner method of [<code>quantum-coin-js-sdk</code>](#module_quantum-coin-js-sdk)
|
|
1011
|
-
**Returns**: <code>
|
|
1012
|
+
**Returns**: <code>string</code> - - Returns the public key as a hex string. Returns null if the operation failed.
|
|
1012
1013
|
|
|
1013
1014
|
| Param | Type | Description |
|
|
1014
1015
|
| --- | --- | --- |
|
|
@@ -1017,11 +1018,11 @@ The publicKeyFromSignature extracts the public key from a signature.
|
|
|
1017
1018
|
|
|
1018
1019
|
<a name="module_quantum-coin-js-sdk..publicKeyFromPrivateKey"></a>
|
|
1019
1020
|
|
|
1020
|
-
### quantum-coin-js-sdk~publicKeyFromPrivateKey(privateKey) ⇒ <code>
|
|
1021
|
+
### quantum-coin-js-sdk~publicKeyFromPrivateKey(privateKey) ⇒ <code>string</code>
|
|
1021
1022
|
The publicKeyFromPrivateKey extracts the public key from a private key.
|
|
1022
1023
|
|
|
1023
1024
|
**Kind**: inner method of [<code>quantum-coin-js-sdk</code>](#module_quantum-coin-js-sdk)
|
|
1024
|
-
**Returns**: <code>
|
|
1025
|
+
**Returns**: <code>string</code> - - Returns the public key as a hex string. Returns null if the operation failed.
|
|
1025
1026
|
|
|
1026
1027
|
| Param | Type | Description |
|
|
1027
1028
|
| --- | --- | --- |
|
|
@@ -1033,9 +1034,22 @@ The publicKeyFromPrivateKey extracts the public key from a private key.
|
|
|
1033
1034
|
The addressFromPublicKey returns the address corresponding to the public key.
|
|
1034
1035
|
|
|
1035
1036
|
**Kind**: inner method of [<code>quantum-coin-js-sdk</code>](#module_quantum-coin-js-sdk)
|
|
1036
|
-
**Returns**: <code>string</code> - - Returns
|
|
1037
|
+
**Returns**: <code>string</code> - - Returns the address corresponding to the public key as a hex string. Returns null if the operation failed.
|
|
1037
1038
|
|
|
1038
1039
|
| Param | Type | Description |
|
|
1039
1040
|
| --- | --- | --- |
|
|
1040
1041
|
| publicKey | <code>Array.<number></code> | An array of bytes containing the public key. |
|
|
1041
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
|
+
}
|
|
@@ -10,11 +10,12 @@
|
|
|
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.
|
|
18
|
+
"version": "1.0.20",
|
|
18
19
|
"license": "MIT",
|
|
19
20
|
"dependencies": {
|
|
20
21
|
"quantum-coin-pqc-js-sdk": "^1.0.0",
|
|
@@ -98,6 +99,12 @@
|
|
|
98
99
|
"resolved": "..",
|
|
99
100
|
"link": true
|
|
100
101
|
},
|
|
102
|
+
"node_modules/quantum-coin-pqc-js-sdk": {
|
|
103
|
+
"version": "1.0.5",
|
|
104
|
+
"resolved": "https://registry.npmjs.org/quantum-coin-pqc-js-sdk/-/quantum-coin-pqc-js-sdk-1.0.5.tgz",
|
|
105
|
+
"integrity": "sha512-9P1YDkca5CqrO7++TnGJZzPvYlBjYARopHgxYbDcEHgPicP7+tA8zD+DE1BooHp7sLEWF9ObklMj6AdaDUjDVw==",
|
|
106
|
+
"license": "MIT"
|
|
107
|
+
},
|
|
101
108
|
"node_modules/tslib": {
|
|
102
109
|
"version": "2.7.0",
|
|
103
110
|
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.7.0.tgz",
|
package/example/package.json
CHANGED
package/index.d.ts
CHANGED
|
@@ -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 {
|
|
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
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
|
|
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
|