quantum-coin-js-sdk 1.0.15 → 1.0.16
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 +0 -0
- package/example/example.js +37 -0
- package/example/package-lock.json +22 -10
- package/index.js +67 -4
- package/package.json +3 -2
package/README.md
CHANGED
|
Binary file
|
package/example/example.js
CHANGED
|
@@ -356,5 +356,42 @@ qcsdk.initialize(clientConfigVal).then((initResult) => {
|
|
|
356
356
|
console.log("signSendCoinTransaction walletObj3 hash: " + signResult.txnHash);
|
|
357
357
|
console.log("signSendCoinTransaction walletObj3 txnData: " + signResult.txnData); //txnData is to be sent to postTransaction
|
|
358
358
|
});
|
|
359
|
+
|
|
360
|
+
//Create a new seed word list
|
|
361
|
+
let seedWords = qcsdk.newWalletSeed();
|
|
362
|
+
if (seedWords === null) {
|
|
363
|
+
console.error("newWalletSeed failed");
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
console.log ("SeedWords: " + seedWords);
|
|
367
|
+
|
|
368
|
+
//Open a wallet from seed words
|
|
369
|
+
let seedWallet = qcsdk.openWalletFromSeedWords(seedWords);
|
|
370
|
+
if (seedWallet === null) {
|
|
371
|
+
console.error("openWalletFromSeedWords failed");
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
console.log("seedWallet address: " + seedWallet.address);
|
|
375
|
+
|
|
376
|
+
//Open a wallet from seed words static
|
|
377
|
+
let seedWordList = "servetize,redmation,suaveton,dreadtolk,rondial,pondicle,miscoil,teaguery,dylodecid,portnel,mantical,slapware,sluthike,tactise,crierial,tajluvki,pranicum,sockcup,stacksong,duerling,genogram,peasate,pulubly,skimpop,feldtail,saprostal,crabrock,radiment,dolocsin,strigemen,juryeuk,fextial,merunized,tangienti,stylocyte,plumvieve,bobstike,nosecrown,acudemy,gripstick,lacreous,marculade,sporculum,outslope,bioburden,trompong,sidelay,finchage";
|
|
378
|
+
let seedWordArray = seedWordList.split(",");
|
|
379
|
+
let seedWallet2 = qcsdk.openWalletFromSeedWords(seedWordArray);
|
|
380
|
+
if (seedWallet2 === null) {
|
|
381
|
+
console.error("openWalletFromSeedWords failed");
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
if (seedWallet2.address !== "0xc7C24aE0Db614F1638C5161e823A539a0293238366d4EaF29A63316D631e964F") {
|
|
385
|
+
console.error("seedWallet2 check failed");
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
console.log("seedWallet2 address: " + seedWallet2.address);
|
|
389
|
+
|
|
390
|
+
//Sign a transaction from a wallet created from seed words
|
|
391
|
+
qcsdk.signSendCoinTransaction(seedWallet, toAddressExample, coinsExample, nonceExample).then((signResult) => {
|
|
392
|
+
console.log("signSendCoinTransaction seedWallet resultCode: " + signResult.resultCode);
|
|
393
|
+
console.log("signSendCoinTransaction seedWallet hash: " + signResult.txnHash);
|
|
394
|
+
console.log("signSendCoinTransaction seedWallet txnData: " + signResult.txnData); //txnData is to be sent to postTransaction
|
|
395
|
+
});
|
|
359
396
|
});
|
|
360
397
|
|
|
@@ -10,14 +10,7 @@
|
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"ethers": "^6.13.4",
|
|
13
|
-
"quantum-coin-js-sdk": "
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
"..": {
|
|
17
|
-
"version": "1.0.15",
|
|
18
|
-
"license": "MIT",
|
|
19
|
-
"dependencies": {
|
|
20
|
-
"quantum-coin-pqc-js-sdk": "^1.0.0"
|
|
13
|
+
"quantum-coin-js-sdk": "^1.0.15"
|
|
21
14
|
}
|
|
22
15
|
},
|
|
23
16
|
"node_modules/@adraffy/ens-normalize": {
|
|
@@ -88,8 +81,19 @@
|
|
|
88
81
|
}
|
|
89
82
|
},
|
|
90
83
|
"node_modules/quantum-coin-js-sdk": {
|
|
91
|
-
"
|
|
92
|
-
"
|
|
84
|
+
"version": "1.0.15",
|
|
85
|
+
"resolved": "https://registry.npmjs.org/quantum-coin-js-sdk/-/quantum-coin-js-sdk-1.0.15.tgz",
|
|
86
|
+
"integrity": "sha512-IeWUSrJ0NPLmsLCa1Eg4WYYRNlpqZWzAkHpb5kOcR5Qn9WVjjN5ZZi7LQlAjstXR8GmZ56biy5w4EMa2nM/azQ==",
|
|
87
|
+
"license": "MIT",
|
|
88
|
+
"dependencies": {
|
|
89
|
+
"quantum-coin-pqc-js-sdk": "^1.0.0"
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
"node_modules/quantum-coin-pqc-js-sdk": {
|
|
93
|
+
"version": "1.0.1",
|
|
94
|
+
"resolved": "https://registry.npmjs.org/quantum-coin-pqc-js-sdk/-/quantum-coin-pqc-js-sdk-1.0.1.tgz",
|
|
95
|
+
"integrity": "sha512-d837t+/wVt8SN6xp3RMAkHvClgrwo2VV254eIsz6do2HD1GmzXCH+vts9S4jILHo7wK0ro7SHRwzZLR9AEhOIw==",
|
|
96
|
+
"license": "MIT"
|
|
93
97
|
},
|
|
94
98
|
"node_modules/tslib": {
|
|
95
99
|
"version": "2.7.0",
|
|
@@ -120,6 +124,14 @@
|
|
|
120
124
|
"optional": true
|
|
121
125
|
}
|
|
122
126
|
}
|
|
127
|
+
},
|
|
128
|
+
"quantum-coin-js-sdk": {
|
|
129
|
+
"version": "1.0.15",
|
|
130
|
+
"extraneous": true,
|
|
131
|
+
"license": "MIT",
|
|
132
|
+
"dependencies": {
|
|
133
|
+
"quantum-coin-pqc-js-sdk": "^1.0.0"
|
|
134
|
+
}
|
|
123
135
|
}
|
|
124
136
|
}
|
|
125
137
|
}
|
package/index.js
CHANGED
|
@@ -32,12 +32,16 @@ const path = require('path');
|
|
|
32
32
|
var wasmexec = require('./wasm_exec');
|
|
33
33
|
var pqc = require('quantum-coin-pqc-js-sdk');
|
|
34
34
|
const crypto = require("crypto");
|
|
35
|
+
var seedwords = require('seed-words');
|
|
35
36
|
|
|
36
37
|
var config = null;
|
|
37
38
|
var isInitialized = false;
|
|
38
39
|
const DEFAULT_GAS = 21000;
|
|
39
40
|
const API_KEY_HEADER_NAME = "X-API-KEY";
|
|
40
41
|
const REQUEST_ID_HEADER_NAME = "X-REQUEST-ID";
|
|
42
|
+
const CRYPTO_SEED_WORDS = 48
|
|
43
|
+
const CRYPTO_SEED_BYTES = 96
|
|
44
|
+
const CRYPTO_EXPANDED_SEED_BYTES = 160
|
|
41
45
|
|
|
42
46
|
/**
|
|
43
47
|
* @class
|
|
@@ -704,8 +708,9 @@ async function initialize(clientConfig) {
|
|
|
704
708
|
}
|
|
705
709
|
await InitAccountsWebAssembly();
|
|
706
710
|
config = clientConfig;
|
|
707
|
-
isInitialized =
|
|
708
|
-
|
|
711
|
+
isInitialized = await seedwords.initialize();
|
|
712
|
+
|
|
713
|
+
return isInitialized;
|
|
709
714
|
}
|
|
710
715
|
|
|
711
716
|
/**
|
|
@@ -752,6 +757,63 @@ function newWallet() {
|
|
|
752
757
|
return walletRet;
|
|
753
758
|
}
|
|
754
759
|
|
|
760
|
+
/**
|
|
761
|
+
* The newWalletSeed function creates a new Wallet seed word list. The return array can then be passed to the openWalletFromSeedWords function to create a new wallet.
|
|
762
|
+
*
|
|
763
|
+
* @function newWalletSeed
|
|
764
|
+
* @return {array} Returns an array of seed words (48 words in total). Returns null if the operation failed.
|
|
765
|
+
*/
|
|
766
|
+
function newWalletSeed() {
|
|
767
|
+
if (isInitialized === false) {
|
|
768
|
+
return -1000;
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
let seedArray = pqc.cryptoNewSeed();
|
|
772
|
+
if (seedArray === null || seedArray.length === null || seedArray.length !== CRYPTO_SEED_BYTES) {
|
|
773
|
+
return null;
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
let wordList = seedwords.getWordListFromSeedArray(seedArray);
|
|
777
|
+
if (wordList === null || wordList.length === null || wordList.length !== CRYPTO_SEED_WORDS) {
|
|
778
|
+
return null;
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
return wordList;
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
/**
|
|
785
|
+
* The openWalletFromSeedWords function creates a wallet from a seed word list. The seed word list is available for wallets created from Desktop/Web/Mobile wallets.
|
|
786
|
+
*
|
|
787
|
+
* @function openWalletFromSeedWords
|
|
788
|
+
* @param {array} seedWordList - An array of seed words. There should be 48 words in total.
|
|
789
|
+
* @return {Wallet} Returns a Wallet object. Returns null if the operation failed.
|
|
790
|
+
*/
|
|
791
|
+
function openWalletFromSeedWords(seedWordList) {
|
|
792
|
+
if (isInitialized === false) {
|
|
793
|
+
return -1000;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
if (seedWordList === null || seedWordList.length === null || seedWordList.length != CRYPTO_SEED_WORDS) {
|
|
797
|
+
return null;
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
let seedArray = seedwords.getSeedArrayFromWordList(seedWordList);
|
|
801
|
+
|
|
802
|
+
if (seedArray === null || seedArray.length === null || seedArray.length !== CRYPTO_SEED_BYTES) {
|
|
803
|
+
return null;
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
let expandedSeedArray = pqc.cryptoExpandSeed(seedArray);
|
|
807
|
+
if (expandedSeedArray === null || expandedSeedArray.length === null || expandedSeedArray.length !== CRYPTO_EXPANDED_SEED_BYTES) {
|
|
808
|
+
return null;
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
let keyPair = pqc.cryptoNewKeyPairFromSeed(expandedSeedArray);
|
|
812
|
+
let address = PublicKeyToAddress(keyPair.getPublicKey());
|
|
813
|
+
let walletRet = new Wallet(address, keyPair.getPrivateKey(), keyPair.getPublicKey());
|
|
814
|
+
return walletRet;
|
|
815
|
+
}
|
|
816
|
+
|
|
755
817
|
/**
|
|
756
818
|
* 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
819
|
*
|
|
@@ -1367,7 +1429,6 @@ async function listAccountTransactions(address, pageNumber) {
|
|
|
1367
1429
|
}
|
|
1368
1430
|
|
|
1369
1431
|
var url = config.readUrl + "/account/" + address + "/transactions/" + pageNumber;
|
|
1370
|
-
console.log(url);
|
|
1371
1432
|
|
|
1372
1433
|
try {
|
|
1373
1434
|
const response = await fetch(url, {
|
|
@@ -1607,5 +1668,7 @@ module.exports = {
|
|
|
1607
1668
|
TransactionDetailsResult,
|
|
1608
1669
|
AccountTransactionsResult,
|
|
1609
1670
|
ListAccountTransactionsResponse,
|
|
1610
|
-
AccountTransactionCompact
|
|
1671
|
+
AccountTransactionCompact,
|
|
1672
|
+
newWalletSeed,
|
|
1673
|
+
openWalletFromSeedWords
|
|
1611
1674
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "quantum-coin-js-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.16",
|
|
4
4
|
"description": "Quantum Coin - Q SDK in JavaScript",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://github.com/quantumcoinproject/quantum-coin-js-sdk#readme",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"quantum-coin-pqc-js-sdk": "^1.0.0"
|
|
31
|
+
"quantum-coin-pqc-js-sdk": "^1.0.0",
|
|
32
|
+
"seed-words": "^1.0.1"
|
|
32
33
|
}
|
|
33
34
|
}
|