quantum-coin-js-sdk 1.0.15 → 1.0.17

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
@@ -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,25 +10,20 @@
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "ethers": "^6.13.4",
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"
13
+ "quantum-coin-js-sdk": "^1.0.15"
21
14
  }
22
15
  },
23
16
  "node_modules/@adraffy/ens-normalize": {
24
17
  "version": "1.10.1",
25
18
  "resolved": "https://registry.npmjs.org/@adraffy/ens-normalize/-/ens-normalize-1.10.1.tgz",
26
- "integrity": "sha512-96Z2IP3mYmF1Xg2cDm8f1gWGf/HUVedQ3FMifV4kG/PQ4yEP51xDtRAEfhVNt5f/uzpNkZHwWQuUcu6D6K+Ekw=="
19
+ "integrity": "sha512-96Z2IP3mYmF1Xg2cDm8f1gWGf/HUVedQ3FMifV4kG/PQ4yEP51xDtRAEfhVNt5f/uzpNkZHwWQuUcu6D6K+Ekw==",
20
+ "license": "MIT"
27
21
  },
28
22
  "node_modules/@noble/curves": {
29
23
  "version": "1.2.0",
30
24
  "resolved": "https://registry.npmjs.org/@noble/curves/-/curves-1.2.0.tgz",
31
25
  "integrity": "sha512-oYclrNgRaM9SsBUBVbb8M6DTV7ZHRTKugureoYEncY5c65HOmRzvSiTE3y5CYaPYJA/GVkrhXEoF0M3Ya9PMnw==",
26
+ "license": "MIT",
32
27
  "dependencies": {
33
28
  "@noble/hashes": "1.3.2"
34
29
  },
@@ -40,6 +35,7 @@
40
35
  "version": "1.3.2",
41
36
  "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.2.tgz",
42
37
  "integrity": "sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ==",
38
+ "license": "MIT",
43
39
  "engines": {
44
40
  "node": ">= 16"
45
41
  },
@@ -51,6 +47,7 @@
51
47
  "version": "22.7.5",
52
48
  "resolved": "https://registry.npmjs.org/@types/node/-/node-22.7.5.tgz",
53
49
  "integrity": "sha512-jML7s2NAzMWc//QSJ1a3prpk78cOPchGvXJsC3C6R6PSMoooztvRVQEz89gmBTBY1SPMaqo5teB4uNHPdetShQ==",
50
+ "license": "MIT",
54
51
  "dependencies": {
55
52
  "undici-types": "~6.19.2"
56
53
  }
@@ -58,12 +55,13 @@
58
55
  "node_modules/aes-js": {
59
56
  "version": "4.0.0-beta.5",
60
57
  "resolved": "https://registry.npmjs.org/aes-js/-/aes-js-4.0.0-beta.5.tgz",
61
- "integrity": "sha512-G965FqalsNyrPqgEGON7nIx1e/OVENSgiEIzyC63haUMuvNnwIgIjMs52hlTCKhkBny7A2ORNlfY9Zu+jmGk1Q=="
58
+ "integrity": "sha512-G965FqalsNyrPqgEGON7nIx1e/OVENSgiEIzyC63haUMuvNnwIgIjMs52hlTCKhkBny7A2ORNlfY9Zu+jmGk1Q==",
59
+ "license": "MIT"
62
60
  },
63
61
  "node_modules/ethers": {
64
- "version": "6.13.4",
65
- "resolved": "https://registry.npmjs.org/ethers/-/ethers-6.13.4.tgz",
66
- "integrity": "sha512-21YtnZVg4/zKkCQPjrDj38B1r4nQvTZLopUGMLQ1ePU2zV/joCfDC3t3iKQjWRzjjjbzR+mdAIoikeBRNkdllA==",
62
+ "version": "6.14.4",
63
+ "resolved": "https://registry.npmjs.org/ethers/-/ethers-6.14.4.tgz",
64
+ "integrity": "sha512-Jm/dzRs2Z9iBrT6e9TvGxyb5YVKAPLlpna7hjxH7KH/++DSh2T/JVmQUv7iHI5E55hDbp/gEVvstWYXVxXFzsA==",
67
65
  "funding": [
68
66
  {
69
67
  "type": "individual",
@@ -74,6 +72,7 @@
74
72
  "url": "https://www.buymeacoffee.com/ricmoo"
75
73
  }
76
74
  ],
75
+ "license": "MIT",
77
76
  "dependencies": {
78
77
  "@adraffy/ens-normalize": "1.10.1",
79
78
  "@noble/curves": "1.2.0",
@@ -88,23 +87,44 @@
88
87
  }
89
88
  },
90
89
  "node_modules/quantum-coin-js-sdk": {
91
- "resolved": "..",
92
- "link": true
90
+ "version": "1.0.16",
91
+ "resolved": "https://registry.npmjs.org/quantum-coin-js-sdk/-/quantum-coin-js-sdk-1.0.16.tgz",
92
+ "integrity": "sha512-g8wll8GqEmk1lm9t1UFJTs5NDmpr8PPsHfDtakfrcKdaJTk6FFK6GMTn9HOO7ZzuX1RkBe+lrvNQtRpIb6VdNg==",
93
+ "license": "MIT",
94
+ "dependencies": {
95
+ "quantum-coin-pqc-js-sdk": "^1.0.0",
96
+ "seed-words": "^1.0.1"
97
+ }
98
+ },
99
+ "node_modules/quantum-coin-pqc-js-sdk": {
100
+ "version": "1.0.1",
101
+ "resolved": "https://registry.npmjs.org/quantum-coin-pqc-js-sdk/-/quantum-coin-pqc-js-sdk-1.0.1.tgz",
102
+ "integrity": "sha512-d837t+/wVt8SN6xp3RMAkHvClgrwo2VV254eIsz6do2HD1GmzXCH+vts9S4jILHo7wK0ro7SHRwzZLR9AEhOIw==",
103
+ "license": "MIT"
104
+ },
105
+ "node_modules/seed-words": {
106
+ "version": "1.0.1",
107
+ "resolved": "https://registry.npmjs.org/seed-words/-/seed-words-1.0.1.tgz",
108
+ "integrity": "sha512-wq9DqfEGXzvIdTatznyQo/9+SN8tM/FNV4H0sAPc6XcOSYdI3YhIL035OYwTld1m1Cn2vnMtNBQv1mBTaU1Qjg==",
109
+ "license": "MIT"
93
110
  },
94
111
  "node_modules/tslib": {
95
112
  "version": "2.7.0",
96
113
  "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.7.0.tgz",
97
- "integrity": "sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA=="
114
+ "integrity": "sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==",
115
+ "license": "0BSD"
98
116
  },
99
117
  "node_modules/undici-types": {
100
118
  "version": "6.19.8",
101
119
  "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz",
102
- "integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw=="
120
+ "integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==",
121
+ "license": "MIT"
103
122
  },
104
123
  "node_modules/ws": {
105
124
  "version": "8.17.1",
106
125
  "resolved": "https://registry.npmjs.org/ws/-/ws-8.17.1.tgz",
107
126
  "integrity": "sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ==",
127
+ "license": "MIT",
108
128
  "engines": {
109
129
  "node": ">=10.0.0"
110
130
  },
package/index.d.ts ADDED
@@ -0,0 +1,701 @@
1
+ /**
2
+ * The initialize function has to be called before attempting to invoke any other function. This function should be called only once.
3
+ *
4
+ * @async
5
+ * @function initialize
6
+ * @param {Config} clientConfig - A configuration represented by the Config class
7
+ * @return {Promise<boolean>} Returns a promise of type boolean; true if the initialization succeeded, else false.
8
+ */
9
+ export function initialize(clientConfig: Config): Promise<boolean>;
10
+ /**
11
+ * The serializeWallet function serializes a Wallet object to a JSON string. You should encrypt the string before saving it to disk or a database.
12
+ *
13
+ * @function serializeWallet
14
+ * @param {Wallet} wallet - A Wallet object representing the wallet to serialize.
15
+ * @return {string} Returns the Wallet in JSON string format. If the wallet is invalid, null is returned.
16
+ */
17
+ export function serializeWallet(wallet: Wallet): string;
18
+ /**
19
+ * The deserializeWallet function creates a Wallet object from a JSON string.
20
+ *
21
+ * @function deserializeWallet
22
+ * @param {string} walletJson - A Wallet object representing the wallet to deserialize.
23
+ * @return {Wallet} Returns the Wallet corresponding to the walletJson. If the wallet is invalid, null is returned.
24
+ */
25
+ export function deserializeWallet(walletJson: string): Wallet;
26
+ /**
27
+ * 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.
28
+ *
29
+ * @function serializeEncryptedWallet
30
+ * @param {Wallet} wallet - A Wallet object representing the wallet to serialize.
31
+ * @param {string} passphrase - A passphrase used to encrypt the wallet. It should atleast be 12 characters long.
32
+ * @return {string} Returns the Wallet in JSON string format. If the wallet is invalid, null is returned.
33
+ */
34
+ export function serializeEncryptedWallet(wallet: Wallet, passphrase: string): string;
35
+ /**
36
+ * 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.
37
+ *
38
+ * @function deserializeEncryptedWallet
39
+ * @param {string} walletJsonString - The json string from a wallet file.
40
+ * @param {string} passphrase - The passphrase used to encrypt the wallet.
41
+ * @return {Wallet} Returns a Wallet object. Returns null if opening the wallet fails.
42
+ */
43
+ export function deserializeEncryptedWallet(walletJsonString: string, passphrase: string): Wallet;
44
+ /**
45
+ * The verifyWallet function verifies whether a Wallet is valid or not. To mitigate spoofing and other attachs, it is highly recommended to verify a wallet, especially if it is from an untrusted source.
46
+ *
47
+ * @function verifyWallet
48
+ * @param {Wallet} wallet - A Wallet object representing the wallet to verify.
49
+ * @return {boolean} Returns true if the Wallet verification succeeded, else returns false.
50
+ */
51
+ export function verifyWallet(wallet: Wallet): boolean;
52
+ /**
53
+ * The newWallet function creates a new Wallet.
54
+ *
55
+ * @function newWallet
56
+ * @return {Wallet} Returns a Wallet object.
57
+ */
58
+ export function newWallet(): Wallet;
59
+ /**
60
+ * The sendCoins function posts a send-coin transaction to the blockchain.
61
+ * Since the gas fee for sending coins is fixed at 1000 coins, there is no option to set the gas fee explicitly.
62
+ * It may take many seconds after submitting a transaction before the transaction is returned by the getTransactionDetails function.
63
+ * Transactions are usually committed in less than 30 seconds.
64
+ *
65
+ * @async
66
+ * @function sendCoins
67
+ * @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.
68
+ * @param {string} toAddress - The address to which the coins should be sent.
69
+ * @param {string} coins - The string representing the number of coins (in ether) to send. To convert between ethers and wei, see https://docs.ethers.org/v4/api-utils.html#ether-strings-and-wei
70
+ * @param {number} nonce - The nonce of the account retrieved by invoking the getAccountDetails function. You have to carefully manage state of the nonce to avoid sending the coins multiple times, such as when retrying sendCoins after a network error.
71
+ * @return {Promise<SendResult>} Returns a promise of type SendResult.
72
+ */
73
+ export function sendCoins(wallet: Wallet, toAddress: string, coins: string, nonce: number): Promise<SendResult>;
74
+ /**
75
+ * The getAccountDetails function returns details of an account corresponding to the address.
76
+ *
77
+ * @async
78
+ * @function getAccountDetails
79
+ * @param {string} address - The address of the account of which the details have to be retrieved.
80
+ * @return {Promise<AccountDetailsResult>} Returns a promise of type AccountDetailsResult.
81
+ */
82
+ export function getAccountDetails(address: string): Promise<AccountDetailsResult>;
83
+ /**
84
+ * The getTransactionDetails function returns details of a transaction posted to the blockchain.
85
+ * Transactions may take a while to get registered in the blockchain. After a transaction is submitted, it may take a while before it is available for reading.
86
+ * Some transactions that have lower balance than the minimum required for gas fees may be discarded.
87
+ * In these cases, the transactions may not be returned when invoking the getTransactionDetails function.
88
+ * You should consider the transaction as succeeded only if the status field of the transactionReceipt object is 0x1 (success).
89
+ * The transactionReceipt field can be null unless the transaction is registered with the blockchain.
90
+ * @async
91
+ * @function getTransactionDetails
92
+ * @param {string} txnHash - The hash of the transaction to retrieve.
93
+ * @return {Promise<TransactionDetailsResult>} Returns a promise of type type TransactionDetailsResult.
94
+ */
95
+ export function getTransactionDetails(txnHash: string): Promise<TransactionDetailsResult>;
96
+ /**
97
+ * The isAddressValid function validates whether an address is valid or not. An address is of length 66 characters including 0x.
98
+ *
99
+ * @function isAddressValid
100
+ * @param {string} address - A string representing the address to validate.
101
+ * @return {boolean} Returns true if the address validation succeeded, else returns false.
102
+ */
103
+ export function isAddressValid(address: string): boolean;
104
+ /**
105
+ * The getLatestBlockDetails function returns details of the latest block of the blockchain.
106
+ *
107
+ * @async
108
+ * @function getLatestBlockDetails
109
+ * @return {Promise<LatestBlockDetailsResult>} Returns a promise of an object of type BlockDetailsResult.
110
+ */
111
+ export function getLatestBlockDetails(): Promise<LatestBlockDetailsResult>;
112
+ /**
113
+ * The signSendCoinTransaction function returns a signed transaction.
114
+ * Since the gas fee for sending coins is fixed at 1000 coins, there is no option to set the gas fee explicitly.
115
+ * 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.
116
+ * 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.
117
+ *
118
+ * @function signSendCoinTransaction
119
+ * @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.
120
+ * @param {string} toAddress - The address to which the coins should be sent.
121
+ * @param {string} coins - The string representing the number of coins (in ether) to send. To convert between ethers and wei, see https://docs.ethers.org/v4/api-utils.html#ether-strings-and-wei
122
+ * @param {number} nonce - The nonce of the account retrieved by invoking the getAccountDetails function. You have to carefully manage state of the nonce to avoid sending the coins multiple times, such as when retrying sendCoins after a network error.
123
+ * @return {SignResult} Returns a promise of type SignResult.
124
+ */
125
+ export function signSendCoinTransaction(wallet: Wallet, toAddress: string, coins: string, nonce: number): SignResult;
126
+ /**
127
+ * The listAccountTransactions function returns a list of transactions for a specific account.
128
+ * Transactions may take a while to get registered in the blockchain. After a transaction is submitted, it may take a while before it is available for listing.
129
+ * Some transactions that have lower balance than the minimum required for gas fees may be discarded.
130
+ * In these cases, the transactions may not be returned when invoking the listAccountTransactions function.
131
+ * You should consider the transaction as succeeded only if the status field AccountDetailsCompact object is 0x1 (success).
132
+ * Both transactions from and transactions to the address will be returned in the list.
133
+ * Use the getTransactionDetails function, passing the hash of the transaction to get detailed information about the transaction.
134
+ * @async
135
+ * @function listAccountTransactions
136
+ * @param {string} address - The address for which the transactions have to be listed.
137
+ * @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.
138
+ * @return {Promise<ListAccountTransactionsResponse>} Returns a promise of type type ListAccountTransactionsResponse.
139
+ */
140
+ export function listAccountTransactions(address: string, pageNumber: number): Promise<ListAccountTransactionsResponse>;
141
+ /**
142
+ * The postTransaction function posts a signed transaction to the blockchain.
143
+ * This method can be used in conjunction with the signSendCoinTransaction method to submit a transaction that was signed using a cold wallet (offline or disconnected or air-gapped wallet).
144
+ *
145
+ * @async
146
+ * @function postTransaction
147
+ * @param {string} txnData - A signed transaction string returned by the signSendCoinTransaction function.
148
+ * @return {Promise<SendResult>} Returns a promise of type SendResult. txnHash will be null in SendResult.
149
+ */
150
+ export function postTransaction(txnData: string): Promise<SendResult>;
151
+ /**
152
+ * @class
153
+ * @constructor
154
+ * @public
155
+ * @classdesc This is the configuration class required to initialize and interact with Quantum Coin blockchain
156
+ */
157
+ export class Config {
158
+ /**
159
+ * Creates a config class
160
+ * @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
161
+ * @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
162
+ * @param {number} chainId - The chain id of the blockchain. Mainnet chainId is 123123. Testnet T4 chainId is 310324.
163
+ * @param {string} readApiKey - Optional parameter if authorization is enabled for the relay service. API Key for authorization. Defaults to null which indicates no authorization.
164
+ * @param {string} writeApiKey - Optional parameter if authorization is enabled for the relay service. API Key for authorization. Defaults to null which indicates no authorization.
165
+ */
166
+ constructor(readUrl: string, writeUrl: string, chainId: number, readApiKey: string, writeApiKey: string);
167
+ /**
168
+ * The Read API URL pointing to a read relay. See https://github.com/quantumcoinproject/quantum-coin-go/tree/dogep/relay
169
+ * @type {string}
170
+ * @public
171
+ */
172
+ public readUrl: string;
173
+ /**
174
+ * The Read API URL pointing to a read relay. See https://github.com/quantumcoinproject/quantum-coin-go/tree/dogep/relay
175
+ * @type {string}
176
+ * @public
177
+ */
178
+ public writeUrl: string;
179
+ /**
180
+ * The chain id of the blockchain. Mainnet chainId is 123123. Testnet T4 chainId is 310324.
181
+ * @type {number}
182
+ * @public
183
+ */
184
+ public chainId: number;
185
+ /**
186
+ * API Key for authorization if authorization is enabled for the relay service. Defaults to null which indicates no authorization.
187
+ * @type {string}
188
+ * @public
189
+ */
190
+ public readApiKey: string;
191
+ /**
192
+ * API Key for authorization if authorization is enabled for the relay service. Defaults to null which indicates no authorization.
193
+ * @type {string}
194
+ * @public
195
+ */
196
+ public writeApiKey: string;
197
+ }
198
+ /**
199
+ * @class
200
+ * @constructor
201
+ * @public
202
+ * @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
203
+ */
204
+ export class Wallet {
205
+ /**
206
+ * Creates a Wallet class. The constructor does not verify the wallet. To verify a wallet, call the verifyWallet function explicitly.
207
+ * @param {string} address - Address of the wallet
208
+ * @param {number[]} privateKey - Private Key byte array of the wallet
209
+ * @param {number[]} publicKey - The chain id of the blockchain. Mainnet chainId is 123123. Testnet T4 chainId is 310324.
210
+ */
211
+ constructor(address: string, privateKey: number[], publicKey: number[]);
212
+ /**
213
+ * Address of the wallet. Is 66 bytes in length including 0x (if the wallet is valid).
214
+ * @type {string}
215
+ * @public
216
+ */
217
+ public address: string;
218
+ /**
219
+ * Private Key byte array of the wallet. Is 4064 bytes in length (if the wallet is valid).
220
+ * @type {{number[]}
221
+ * @public
222
+ */
223
+ public privateKey: {};
224
+ /**
225
+ * Public Key byte array of the wallet. Is 1408 bytes in length (if the wallet is valid).
226
+ * @type {{number[]}
227
+ * @public
228
+ */
229
+ public publicKey: {};
230
+ }
231
+ /**
232
+ * @class
233
+ * @constructor
234
+ * @public
235
+ * @classdesc This class represents a Block.
236
+ */
237
+ export class BlockDetails {
238
+ constructor(blockNumber: any);
239
+ /**
240
+ * Block Number of the block
241
+ * @type {number}
242
+ * @public
243
+ */
244
+ public blockNumber: number;
245
+ }
246
+ /**
247
+ * @class
248
+ * @constructor
249
+ * @public
250
+ * @classdesc This class represents a result from invoking the getLatestBlock function.
251
+ */
252
+ export class LatestBlockDetailsResult {
253
+ constructor(resultCode: any, blockDetails: any, response: any, requestId: any, err: any);
254
+ /**
255
+ * 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.
256
+ * @type {number}
257
+ * @public
258
+ */
259
+ public resultCode: number;
260
+ /**
261
+ * An object of type BlockDetails representing the block. This value is null if the value of resultCode is not 0.
262
+ * @type {BlockDetails}
263
+ * @public
264
+ */
265
+ public blockDetails: BlockDetails;
266
+ /**
267
+ * An object of representing the raw Response returned by the service. For details, see https://developer.mozilla.org/en-US/docs/Web/API/Response. This value can be null if the value of resultCode is not 0.
268
+ * @type {Object}
269
+ * @public
270
+ */
271
+ public response: any;
272
+ /**
273
+ * An unique id to represent the request. This can be null if request failed before it could be sent.
274
+ * @type {string}
275
+ * @public
276
+ */
277
+ public requestId: string;
278
+ /**
279
+ * 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.
280
+ * @type {Error}
281
+ * @public
282
+ */
283
+ public err: Error;
284
+ }
285
+ /**
286
+ * @class
287
+ * @constructor
288
+ * @public
289
+ * @classdesc This class represents an Account.
290
+ */
291
+ export class AccountDetails {
292
+ constructor(address: any, balance: any, nonce: any, blockNumber: any);
293
+ /**
294
+ * Address of the wallet. Is 66 bytes in length including 0x.
295
+ * @type {string}
296
+ * @public
297
+ */
298
+ public address: string;
299
+ /**
300
+ * Balance of the account in wei. To convert this to ethers, see https://docs.ethers.org/v4/api-utils.html#ether-strings-and-wei
301
+ * @type {string}
302
+ * @public
303
+ */
304
+ public balance: string;
305
+ /**
306
+ * A monotonically increasing number representing the nonce of the account. After each transaction from the account that gets registered in the blockchain, the nonce increases by 1.
307
+ * @type {number}
308
+ * @public
309
+ */
310
+ public nonce: number;
311
+ /**
312
+ * The block number as of which the Account details was retrieved.
313
+ * @type {number}
314
+ * @public
315
+ */
316
+ public blockNumber: number;
317
+ }
318
+ /**
319
+ * @class
320
+ * @constructor
321
+ * @public
322
+ * @classdesc This class represents a result from invoking the getAccountDetails function.
323
+ */
324
+ export class AccountDetailsResult {
325
+ constructor(resultCode: any, accountDetails: any, response: any, requestId: any, err: any);
326
+ /**
327
+ * 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.
328
+ * @type {number}
329
+ * @public
330
+ */
331
+ public resultCode: number;
332
+ /**
333
+ * An object of type AccountDetails representing the block. This value is null if the value of resultCode is not 0.
334
+ * @type {AccountDetails}
335
+ * @public
336
+ */
337
+ public accountDetails: AccountDetails;
338
+ /**
339
+ * An object of representing the raw Response returned by the service. For details, see https://developer.mozilla.org/en-US/docs/Web/API/Response. This value can be null if the value of resultCode is not 0.
340
+ * @type {Object}
341
+ * @public
342
+ */
343
+ public response: any;
344
+ /**
345
+ * An unique id to represent the request. This can be null if request failed before it could be sent.
346
+ * @type {string}
347
+ * @public
348
+ */
349
+ public requestId: string;
350
+ /**
351
+ * 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.
352
+ * @type {Error}
353
+ * @public
354
+ */
355
+ public err: Error;
356
+ }
357
+ /**
358
+ * @class
359
+ * @constructor
360
+ * @public
361
+ * @classdesc This class represents a result from invoking the sendCoins function.
362
+ */
363
+ export class SendResult {
364
+ constructor(resultCode: any, txnHash: any, response: any, requestId: any, err: any);
365
+ /**
366
+ * 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.
367
+ * @type {number}
368
+ * @public
369
+ */
370
+ public resultCode: number;
371
+ /**
372
+ * Hash of the Transaction, to uniquely identify it. Is 66 bytes in length including 0x. This value is null if the value of resultCode is not 0.
373
+ * @type {string}
374
+ * @public
375
+ */
376
+ public txnHash: string;
377
+ /**
378
+ * An object of representing the raw Response returned by the service. For details, see https://developer.mozilla.org/en-US/docs/Web/API/Response. This value can be null if the value of resultCode is not 0.
379
+ * @type {Object}
380
+ * @public
381
+ */
382
+ public response: any;
383
+ /**
384
+ * An unique id to represent the request. This can be null if request failed before it could be sent.
385
+ * @type {string}
386
+ * @public
387
+ */
388
+ public requestId: string;
389
+ /**
390
+ * 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.
391
+ * @type {Error}
392
+ * @public
393
+ */
394
+ public err: Error;
395
+ }
396
+ /**
397
+ * @class
398
+ * @constructor
399
+ * @public
400
+ * @classdesc This class represents a Receipt of a transaction that is registered in the blockchain. The transactionReceipt field can be null unless the transaction is registered with the blockchain.
401
+ * While the transaction is pending, this field will be null. You should consider the transaction as succeeded only if the status field's value is 0x1 (success).
402
+ */
403
+ export class TransactionReceipt {
404
+ /**
405
+ * A hexadecimal string representing the total amount of gas used when this transaction was executed in the block.
406
+ * @type {string}
407
+ * @public
408
+ */
409
+ public cumulativeGasUsed: string;
410
+ /**
411
+ * A hexadecimal string representing the sum of the base fee and tip paid per unit of gas.
412
+ * @type {string}
413
+ * @public
414
+ */
415
+ public effectiveGasPrice: string;
416
+ /**
417
+ * A hexadecimal string representing the amount of gas used by this specific transaction alone.
418
+ * @type {string}
419
+ * @public
420
+ */
421
+ public gasUsed: string;
422
+ /**
423
+ * A hexadecimal string representing either 0x1 (success) or 0x0 (failure). Failed transactions can also incur gas fee. You should consider the transaction as succeeded only if the status value is 0x1 (success).
424
+ * @type {string}
425
+ * @public
426
+ */
427
+ public status: string;
428
+ /**
429
+ * Hash of the Transaction, to uniquely identify it. Is 66 bytes in length including 0x.
430
+ * @type {string}
431
+ * @public
432
+ */
433
+ public hash: string;
434
+ /**
435
+ * A hexadecimal string representing the transaction type. 0x0 is DefaultFeeTxType.
436
+ * @type {string}
437
+ * @public
438
+ */
439
+ public type: string;
440
+ }
441
+ /**
442
+ * @class
443
+ * @constructor
444
+ * @public
445
+ * @classdesc This class represents details of a transaction. You should consider the transaction as succeeded only if the status field of the receipt object is 0x1 (success).
446
+ */
447
+ export class TransactionDetails {
448
+ /**
449
+ * A hexadecimal string representing the hash of the block that registered the transaction. This field can be null if the transaction was not registered in the blockchain.
450
+ * @type {string}
451
+ * @public
452
+ */
453
+ public blockHash: string;
454
+ /**
455
+ * The number of the block that registered the transaction. This field can be null if the transaction was not registered in the blockchain.
456
+ * @type {number}
457
+ * @public
458
+ */
459
+ public blockNumber: number;
460
+ /**
461
+ * A 66 character hexadecimal string representing the address the transaction is sent from.
462
+ * @type {string}
463
+ * @public
464
+ */
465
+ public from: string;
466
+ /**
467
+ * A hexadecimal string representing the gas provided for the transaction execution.
468
+ * @type {string}
469
+ * @public
470
+ */
471
+ public gas: string;
472
+ /**
473
+ * A hexadecimal string representing the gasPrice used for each paid gas, in Wei.
474
+ * @type {string}
475
+ * @public
476
+ */
477
+ public gasPrice: string;
478
+ /**
479
+ * A 66 character hexadecimal string representing the hash of the transaction.
480
+ * @type {string}
481
+ * @public
482
+ */
483
+ public hash: string;
484
+ /**
485
+ * A hexadecimal string representing the compiled code of a contract OR the hash of the invoked method signature and encoded parameters.
486
+ * @type {string}
487
+ * @public
488
+ */
489
+ public input: string;
490
+ /**
491
+ * A monotonically increasing number representing the nonce of the account. After each transaction from the account that gets registered in the blockchain, the nonce increases by 1.
492
+ * @type {number}
493
+ * @public
494
+ */
495
+ public nonce: number;
496
+ /**
497
+ * A 66 character hexadecimal string representing address the transaction is directed to.
498
+ * @type {string}
499
+ * @public
500
+ */
501
+ public to: string;
502
+ /**
503
+ * A hexadecimal string representing the value sent with this transaction. The value can be 0 for smart contract transactions, since it only represents the number of coins sent.
504
+ * @type {string}
505
+ * @public
506
+ */
507
+ public value: string;
508
+ /**
509
+ * The receipt of the transaction. This field will be null while the transaction is pending (not yet registered in the blockchain).
510
+ * @type {TransactionReceipt}
511
+ * @public
512
+ */
513
+ public receipt: TransactionReceipt;
514
+ }
515
+ /**
516
+ * @class
517
+ * @constructor
518
+ * @public
519
+ * @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).
520
+ */
521
+ export class TransactionDetailsResult {
522
+ constructor(resultCode: any, transactionDetails: any, response: any, requestId: any, err: any);
523
+ /**
524
+ * 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.
525
+ * @type {number}
526
+ * @public
527
+ */
528
+ public resultCode: number;
529
+ /**
530
+ * An object of type TransactionDetails representing the transaction. This value is null if the value of resultCode is not 0.
531
+ * @type {TransactionDetails}
532
+ * @public
533
+ */
534
+ public transactionDetails: TransactionDetails;
535
+ /**
536
+ * An object of representing the raw Response returned by the service. For details, see https://developer.mozilla.org/en-US/docs/Web/API/Response. This value can be null if the value of resultCode is not 0.
537
+ * @type {Object}
538
+ * @public
539
+ */
540
+ public response: any;
541
+ /**
542
+ * An unique id to represent the request. This can be null if request failed before it could be sent.
543
+ * @type {string}
544
+ * @public
545
+ */
546
+ public requestId: string;
547
+ /**
548
+ * 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.
549
+ * @type {Error}
550
+ * @public
551
+ */
552
+ public err: Error;
553
+ }
554
+ /**
555
+ * @class
556
+ * @constructor
557
+ * @public
558
+ * @classdesc This class represents a result from invoking the listAccountTransactionDetails function.
559
+ */
560
+ export class AccountTransactionsResult {
561
+ constructor(resultCode: any, listAccountTransactionsResponse: any, response: any, requestId: any, err: any);
562
+ /**
563
+ * 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.
564
+ * @type {number}
565
+ * @public
566
+ */
567
+ public resultCode: number;
568
+ /**
569
+ * An object of type ListAccountTransactionsResponse representing the list of transactions along with metadata. This value is null if the value of resultCode is not 0.
570
+ * @type {ListAccountTransactionsResponse}
571
+ * @public
572
+ */
573
+ public listAccountTransactionsResponse: ListAccountTransactionsResponse;
574
+ /**
575
+ * An object of representing the raw Response returned by the service. For details, see https://developer.mozilla.org/en-US/docs/Web/API/Response. This value can be null if the value of resultCode is not 0.
576
+ * @type {Object}
577
+ * @public
578
+ */
579
+ public response: any;
580
+ /**
581
+ * An unique id to represent the request. This can be null if request failed before it could be sent.
582
+ * @type {string}
583
+ * @public
584
+ */
585
+ public requestId: string;
586
+ /**
587
+ * 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.
588
+ * @type {Error}
589
+ * @public
590
+ */
591
+ public err: Error;
592
+ }
593
+ /**
594
+ * @class
595
+ * @constructor
596
+ * @public
597
+ * @classdesc This class represents a list of account transactions returned by the listAccountTransactionDetails function.
598
+ */
599
+ export class ListAccountTransactionsResponse {
600
+ /**
601
+ * The number of pages available for listing.
602
+ * @type {number}
603
+ * @public
604
+ */
605
+ public pageCount: number;
606
+ /**
607
+ * An array of type AccountTransactionCompact, containing the list of transactions. Can be null if no items are available.
608
+ * @type {(AccountTransactionCompact|Array)}
609
+ * @public
610
+ */
611
+ public items: (AccountTransactionCompact | any[]);
612
+ }
613
+ /**
614
+ * @class
615
+ * @constructor
616
+ * @public
617
+ * @classdesc This class represents a transaction of an account. You should consider the transaction as succeeded only if the status field is 0x1 (success).
618
+ */
619
+ export class AccountTransactionCompact {
620
+ /**
621
+ * The number of the block that registered the transaction. This field can be null if the transaction was not registered in the blockchain.
622
+ * @type {number}
623
+ * @public
624
+ */
625
+ public blockNumber: number;
626
+ /**
627
+ * A 66 character hexadecimal string representing the address the transaction is sent from.
628
+ * @type {string}
629
+ * @public
630
+ */
631
+ public from: string;
632
+ /**
633
+ * A 66 character hexadecimal string representing the hash of the transaction.
634
+ * @type {string}
635
+ * @public
636
+ */
637
+ public hash: string;
638
+ /**
639
+ * A 66 character hexadecimal string representing address the transaction is directed to.
640
+ * @type {string}
641
+ * @public
642
+ */
643
+ public to: string;
644
+ /**
645
+ * A hexadecimal string representing the value sent with this transaction. The value can be 0 for smart contract transactions, since it only represents the number of coins sent.
646
+ * @type {string}
647
+ * @public
648
+ */
649
+ public value: string;
650
+ /**
651
+ * A hexadecimal string representing either 0x1 (success) or 0x0 (failure). Failed transactions can also incur gas fee. You should consider the transaction as succeeded only if the status value is 0x1 (success).
652
+ * @type {string}
653
+ * @public
654
+ */
655
+ public status: string;
656
+ }
657
+ /**
658
+ * 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.
659
+ *
660
+ * @function newWalletSeed
661
+ * @return {array} Returns an array of seed words (48 words in total). Returns null if the operation failed.
662
+ */
663
+ export function newWalletSeed(): any[];
664
+ /**
665
+ * 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.
666
+ *
667
+ * @function openWalletFromSeedWords
668
+ * @param {array} seedWordList - An array of seed words. There should be 48 words in total.
669
+ * @return {Wallet} Returns a Wallet object. Returns null if the operation failed.
670
+ */
671
+ export function openWalletFromSeedWords(seedWordList: any[]): Wallet;
672
+ /**
673
+ * @class
674
+ * @constructor
675
+ * @public
676
+ * @classdesc This class represents a result from invoking the signSendCoinTransaction function.
677
+ */
678
+ declare class SignResult {
679
+ constructor(resultCode: any, txnHash: any, txnData: any);
680
+ /**
681
+ * 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.
682
+ * @type {number}
683
+ * @public
684
+ */
685
+ public resultCode: number;
686
+ /**
687
+ * Hash of the Transaction, to uniquely identify it. Is 66 bytes in length including 0x. This value is null if the value of resultCode is not 0.
688
+ * @type {string}
689
+ * @public
690
+ */
691
+ public txnHash: string;
692
+ /**
693
+ * A payload representing the signed transaction.
694
+ * To actually send a transaction, this payload can then be taken to to a different device that is connected to the blockchain relay and then sent using the postTransaction function.
695
+ * This value is null if the value of resultCode is not 0.
696
+ * @type {string}
697
+ * @public
698
+ */
699
+ public txnData: string;
700
+ }
701
+ export {};
package/index.js CHANGED
@@ -27,17 +27,19 @@
27
27
  *
28
28
  */
29
29
 
30
- var fs = require('fs');
31
- const path = require('path');
32
30
  var wasmexec = require('./wasm_exec');
33
31
  var pqc = require('quantum-coin-pqc-js-sdk');
34
32
  const crypto = require("crypto");
33
+ var seedwords = require('seed-words');
35
34
 
36
35
  var config = null;
37
36
  var isInitialized = false;
38
37
  const DEFAULT_GAS = 21000;
39
38
  const API_KEY_HEADER_NAME = "X-API-KEY";
40
39
  const REQUEST_ID_HEADER_NAME = "X-REQUEST-ID";
40
+ const CRYPTO_SEED_WORDS = 48
41
+ const CRYPTO_SEED_BYTES = 96
42
+ const CRYPTO_EXPANDED_SEED_BYTES = 160
41
43
 
42
44
  /**
43
45
  * @class
@@ -103,8 +105,8 @@ class Wallet {
103
105
  /**
104
106
  * Creates a Wallet class. The constructor does not verify the wallet. To verify a wallet, call the verifyWallet function explicitly.
105
107
  * @param {string} address - Address of the wallet
106
- * @param {byte[]} privateKey - Private Key byte array of the wallet
107
- * @param {byte[]} publicKey - The chain id of the blockchain. Mainnet chainId is 123123. Testnet T4 chainId is 310324.
108
+ * @param {number[]} privateKey - Private Key byte array of the wallet
109
+ * @param {number[]} publicKey - The chain id of the blockchain. Mainnet chainId is 123123. Testnet T4 chainId is 310324.
108
110
  */
109
111
  constructor(address, privateKey, publicKey) {
110
112
 
@@ -117,14 +119,14 @@ class Wallet {
117
119
 
118
120
  /**
119
121
  * Private Key byte array of the wallet. Is 4064 bytes in length (if the wallet is valid).
120
- * @type {{byte[]}
122
+ * @type {{number[]}
121
123
  * @public
122
124
  */
123
125
  this.privateKey = privateKey;
124
126
 
125
127
  /**
126
128
  * Public Key byte array of the wallet. Is 1408 bytes in length (if the wallet is valid).
127
- * @type {{byte[]}
129
+ * @type {{number[]}
128
130
  * @public
129
131
  */
130
132
  this.publicKey = publicKey;
@@ -186,7 +188,7 @@ class LatestBlockDetailsResult {
186
188
 
187
189
  /**
188
190
  * 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}
191
+ * @type {Error}
190
192
  * @public
191
193
  */
192
194
  this.err = err;
@@ -269,7 +271,7 @@ class AccountDetailsResult {
269
271
 
270
272
  /**
271
273
  * 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}
274
+ * @type {Error}
273
275
  * @public
274
276
  */
275
277
  this.err = err;
@@ -347,7 +349,7 @@ class SendResult {
347
349
 
348
350
  /**
349
351
  * 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}
352
+ * @type {Error}
351
353
  * @public
352
354
  */
353
355
  this.err = err;
@@ -534,7 +536,7 @@ class TransactionDetailsResult {
534
536
 
535
537
  /**
536
538
  * 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}
539
+ * @type {Error}
538
540
  * @public
539
541
  */
540
542
  this.err = err;
@@ -657,7 +659,7 @@ class AccountTransactionsResult {
657
659
 
658
660
  /**
659
661
  * 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}
662
+ * @type {Error}
661
663
  * @public
662
664
  */
663
665
  this.err = err;
@@ -704,8 +706,9 @@ async function initialize(clientConfig) {
704
706
  }
705
707
  await InitAccountsWebAssembly();
706
708
  config = clientConfig;
707
- isInitialized = true;
708
- return true;
709
+ isInitialized = await seedwords.initialize();
710
+
711
+ return isInitialized;
709
712
  }
710
713
 
711
714
  /**
@@ -752,6 +755,63 @@ function newWallet() {
752
755
  return walletRet;
753
756
  }
754
757
 
758
+ /**
759
+ * 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.
760
+ *
761
+ * @function newWalletSeed
762
+ * @return {array} Returns an array of seed words (48 words in total). Returns null if the operation failed.
763
+ */
764
+ function newWalletSeed() {
765
+ if (isInitialized === false) {
766
+ return -1000;
767
+ }
768
+
769
+ let seedArray = pqc.cryptoNewSeed();
770
+ if (seedArray === null || seedArray.length === null || seedArray.length !== CRYPTO_SEED_BYTES) {
771
+ return null;
772
+ }
773
+
774
+ let wordList = seedwords.getWordListFromSeedArray(seedArray);
775
+ if (wordList === null || wordList.length === null || wordList.length !== CRYPTO_SEED_WORDS) {
776
+ return null;
777
+ }
778
+
779
+ return wordList;
780
+ }
781
+
782
+ /**
783
+ * 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.
784
+ *
785
+ * @function openWalletFromSeedWords
786
+ * @param {array} seedWordList - An array of seed words. There should be 48 words in total.
787
+ * @return {Wallet} Returns a Wallet object. Returns null if the operation failed.
788
+ */
789
+ function openWalletFromSeedWords(seedWordList) {
790
+ if (isInitialized === false) {
791
+ return -1000;
792
+ }
793
+
794
+ if (seedWordList === null || seedWordList.length === null || seedWordList.length != CRYPTO_SEED_WORDS) {
795
+ return null;
796
+ }
797
+
798
+ let seedArray = seedwords.getSeedArrayFromWordList(seedWordList);
799
+
800
+ if (seedArray === null || seedArray.length === null || seedArray.length !== CRYPTO_SEED_BYTES) {
801
+ return null;
802
+ }
803
+
804
+ let expandedSeedArray = pqc.cryptoExpandSeed(seedArray);
805
+ if (expandedSeedArray === null || expandedSeedArray.length === null || expandedSeedArray.length !== CRYPTO_EXPANDED_SEED_BYTES) {
806
+ return null;
807
+ }
808
+
809
+ let keyPair = pqc.cryptoNewKeyPairFromSeed(expandedSeedArray);
810
+ let address = PublicKeyToAddress(keyPair.getPublicKey());
811
+ let walletRet = new Wallet(address, keyPair.getPrivateKey(), keyPair.getPublicKey());
812
+ return walletRet;
813
+ }
814
+
755
815
  /**
756
816
  * 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
817
  *
@@ -1076,7 +1136,7 @@ async function postTransaction(txnData) {
1076
1136
  *
1077
1137
  * @async
1078
1138
  * @function getLatestBlockDetails
1079
- * @return {Promise<BlockDetailsResult>} Returns a promise of an object of type BlockDetailsResult.
1139
+ * @return {Promise<LatestBlockDetailsResult>} Returns a promise of an object of type BlockDetailsResult.
1080
1140
  */
1081
1141
  async function getLatestBlockDetails() {
1082
1142
  if (isInitialized === false) {
@@ -1367,7 +1427,6 @@ async function listAccountTransactions(address, pageNumber) {
1367
1427
  }
1368
1428
 
1369
1429
  var url = config.readUrl + "/account/" + address + "/transactions/" + pageNumber;
1370
- console.log(url);
1371
1430
 
1372
1431
  try {
1373
1432
  const response = await fetch(url, {
@@ -1607,5 +1666,7 @@ module.exports = {
1607
1666
  TransactionDetailsResult,
1608
1667
  AccountTransactionsResult,
1609
1668
  ListAccountTransactionsResponse,
1610
- AccountTransactionCompact
1669
+ AccountTransactionCompact,
1670
+ newWalletSeed,
1671
+ openWalletFromSeedWords
1611
1672
  };
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "quantum-coin-js-sdk",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "description": "Quantum Coin - Q SDK in JavaScript",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
7
+ "test": "echo \"Error: no test specified\" && exit 1",
8
+ "build": "npx -p typescript tsc index.js --declaration --allowJs --emitDeclarationOnly && jsdoc2md index.js >README.md"
8
9
  },
9
10
  "repository": {
10
11
  "type": "git",
@@ -28,6 +29,7 @@
28
29
  },
29
30
  "homepage": "https://github.com/quantumcoinproject/quantum-coin-js-sdk#readme",
30
31
  "dependencies": {
31
- "quantum-coin-pqc-js-sdk": "^1.0.0"
32
+ "quantum-coin-pqc-js-sdk": "^1.0.0",
33
+ "seed-words": "^1.0.1"
32
34
  }
33
35
  }
package/wasm_exec.d.ts ADDED
File without changes