quantum-coin-js-sdk 1.0.30 → 1.0.32

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
package/index.d.ts CHANGED
@@ -664,6 +664,15 @@ export class AccountTransactionCompact {
664
664
  * @return {array|number|null} Returns an array of seed words (32 or 36 words). Returns -1000 if not initialized, null on failure.
665
665
  */
666
666
  export function newWalletSeed(keyType: number | null): any[] | number | null;
667
+ /**
668
+ * The openWalletFromSeed function creates a wallet from a raw seed byte array.
669
+ * Determines the key scheme from the array length: 96 bytes (hybrideds), 72 bytes (hybrid5), or 64 bytes (hybrid).
670
+ *
671
+ * @function openWalletFromSeed
672
+ * @param {Array<number>|Uint8Array} seedArray - The raw seed bytes. Length 96, 72, or 64 depending on scheme.
673
+ * @return {Wallet|number} Returns a Wallet object. Returns -1000 if not initialized, null if the operation failed.
674
+ */
675
+ export function openWalletFromSeed(seedArray: Array<number> | Uint8Array): Wallet | number;
667
676
  /**
668
677
  * 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.
669
678
  * Supports 48 words (hybrideds), 36 words (hybrid5), or 32 words (hybrid) per seed length.
package/index.js CHANGED
@@ -1044,26 +1044,22 @@ function newWalletSeed(keyType) {
1044
1044
  }
1045
1045
 
1046
1046
  /**
1047
- * 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.
1048
- * Supports 48 words (hybrideds), 36 words (hybrid5), or 32 words (hybrid) per seed length.
1047
+ * The openWalletFromSeed function creates a wallet from a raw seed byte array.
1048
+ * Determines the key scheme from the array length: 96 bytes (hybrideds), 72 bytes (hybrid5), or 64 bytes (hybrid).
1049
1049
  *
1050
- * @function openWalletFromSeedWords
1051
- * @param {array} seedWordList - An array of seed words. Length 48, 36, or 32 depending on scheme.
1050
+ * @function openWalletFromSeed
1051
+ * @param {Array<number>|Uint8Array} seedArray - The raw seed bytes. Length 96, 72, or 64 depending on scheme.
1052
1052
  * @return {Wallet|number} Returns a Wallet object. Returns -1000 if not initialized, null if the operation failed.
1053
1053
  */
1054
- function openWalletFromSeedWords(seedWordList) {
1054
+ function openWalletFromSeed(seedArray) {
1055
1055
  if (isInitialized === false) {
1056
1056
  return -1000;
1057
1057
  }
1058
- if (seedWordList == null || typeof seedWordList.length !== 'number') {
1058
+ if (seedArray == null || typeof seedArray.length !== 'number') {
1059
1059
  return null;
1060
1060
  }
1061
- const len = seedWordList.length;
1062
- if (len !== SEED_WORD_LIST_LENGTH_HYBRIDEDS && len !== SEED_WORD_LIST_LENGTH_HYBRIDEDMLDSASLHDSA5 && len !== SEED_WORD_LIST_LENGTH_HYBRIDEDMLDSASLHDSA) {
1063
- return null;
1064
- }
1065
- const seedArray = seedwords.getSeedArrayFromWordList(seedWordList);
1066
- if (seedArray == null || seedArray.length == null) {
1061
+ const len = seedArray.length;
1062
+ if (len !== BASE_SEED_BYTES_HYBRIDEDS && len !== BASE_SEED_BYTES_HYBRIDEDMLDSASLHDSA5 && len !== BASE_SEED_BYTES_HYBRIDEDMLDSASLHDSA) {
1067
1063
  return null;
1068
1064
  }
1069
1065
  if (circl == null) {
@@ -1072,16 +1068,14 @@ function openWalletFromSeedWords(seedWordList) {
1072
1068
  let expandedRes;
1073
1069
  let keyPairRes;
1074
1070
  const seedU8 = seedArray instanceof Uint8Array ? seedArray : new Uint8Array(seedArray);
1075
- if (len === SEED_WORD_LIST_LENGTH_HYBRIDEDS) {
1076
- if (seedArray.length !== BASE_SEED_BYTES_HYBRIDEDS) return null;
1071
+ if (len === BASE_SEED_BYTES_HYBRIDEDS) {
1077
1072
  const ns = circl.hybrideds;
1078
1073
  if (!ns) return null;
1079
1074
  expandedRes = ns.expandSeed(seedU8);
1080
1075
  if (expandedRes && expandedRes.error) return null;
1081
1076
  if (!expandedRes || !expandedRes.result) return null;
1082
1077
  keyPairRes = ns.newKeyFromSeed(expandedRes.result);
1083
- } else if (len === SEED_WORD_LIST_LENGTH_HYBRIDEDMLDSASLHDSA5) {
1084
- if (seedArray.length !== BASE_SEED_BYTES_HYBRIDEDMLDSASLHDSA5) return null;
1078
+ } else if (len === BASE_SEED_BYTES_HYBRIDEDMLDSASLHDSA5) {
1085
1079
  const ns = circl.hybridedmldsaslhdsa5 || circl.hybridedmldsaslhds5;
1086
1080
  if (!ns) return null;
1087
1081
  expandedRes = ns.expandSeed(seedU8);
@@ -1089,7 +1083,6 @@ function openWalletFromSeedWords(seedWordList) {
1089
1083
  if (!expandedRes || !expandedRes.result) return null;
1090
1084
  keyPairRes = ns.newKeyFromSeed(expandedRes.result);
1091
1085
  } else {
1092
- if (seedArray.length !== BASE_SEED_BYTES_HYBRIDEDMLDSASLHDSA) return null;
1093
1086
  const ns = circl.hybridedmldsaslhdsa;
1094
1087
  if (!ns) return null;
1095
1088
  expandedRes = ns.expandSeed(seedU8);
@@ -1105,6 +1098,32 @@ function openWalletFromSeedWords(seedWordList) {
1105
1098
  return new Wallet(address, privateKey, publicKey);
1106
1099
  }
1107
1100
 
1101
+ /**
1102
+ * 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.
1103
+ * Supports 48 words (hybrideds), 36 words (hybrid5), or 32 words (hybrid) per seed length.
1104
+ *
1105
+ * @function openWalletFromSeedWords
1106
+ * @param {array} seedWordList - An array of seed words. Length 48, 36, or 32 depending on scheme.
1107
+ * @return {Wallet|number} Returns a Wallet object. Returns -1000 if not initialized, null if the operation failed.
1108
+ */
1109
+ function openWalletFromSeedWords(seedWordList) {
1110
+ if (isInitialized === false) {
1111
+ return -1000;
1112
+ }
1113
+ if (seedWordList == null || typeof seedWordList.length !== 'number') {
1114
+ return null;
1115
+ }
1116
+ const len = seedWordList.length;
1117
+ if (len !== SEED_WORD_LIST_LENGTH_HYBRIDEDS && len !== SEED_WORD_LIST_LENGTH_HYBRIDEDMLDSASLHDSA5 && len !== SEED_WORD_LIST_LENGTH_HYBRIDEDMLDSASLHDSA) {
1118
+ return null;
1119
+ }
1120
+ const seedArray = seedwords.getSeedArrayFromWordList(seedWordList);
1121
+ if (seedArray == null || seedArray.length == null) {
1122
+ return null;
1123
+ }
1124
+ return openWalletFromSeed(seedArray);
1125
+ }
1126
+
1108
1127
  /**
1109
1128
  * 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.
1110
1129
  *
@@ -2982,6 +3001,7 @@ module.exports = {
2982
3001
  ListAccountTransactionsResponse,
2983
3002
  AccountTransactionCompact,
2984
3003
  newWalletSeed,
3004
+ openWalletFromSeed,
2985
3005
  openWalletFromSeedWords,
2986
3006
  publicKeyFromSignature,
2987
3007
  publicKeyFromPrivateKey,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quantum-coin-js-sdk",
3
- "version": "1.0.30",
3
+ "version": "1.0.32",
4
4
  "description": "Quantum Coin - Q SDK in JavaScript",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -237,6 +237,90 @@ describe('non-transactional', () => {
237
237
  assert.equal(wallet.address.toLowerCase(), TEST_SEED_ADDRESS_36);
238
238
  });
239
239
 
240
+ // --- openWalletFromSeed tests (raw seed byte arrays) ---
241
+
242
+ // Hardcoded seed byte arrays derived from TEST_SEED_WORDS via seed-words.getSeedArrayFromWordList
243
+ const TEST_SEED_ARRAY_48 = [49,159,218,142,198,66,182,182,73,216,5,119,6,71,216,42,164,55,124,237,92,81,228,227,156,0,38,189,152,58,215,177,80,252,71,86,51,210,70,33,106,200,184,26,246,139,249,41,191,104,163,253,21,26,43,108,146,94,243,204,112,236,219,139,218,249,224,255,76,150,203,7,108,119,101,70,217,112,225,190,112,169,98,168,104,223,14,235,161,192,118,167,128,203,76,59];
244
+ const TEST_SEED_ARRAY_32 = [49,159,218,142,198,66,182,182,73,216,5,119,6,71,216,42,164,55,124,237,92,81,228,227,156,0,38,189,152,58,215,177,80,252,71,86,51,210,70,33,106,200,184,26,246,139,249,41,191,104,163,253,21,26,43,108,146,94,243,204,112,236,219,139];
245
+ const TEST_SEED_ARRAY_36 = [49,159,218,142,198,66,182,182,73,216,5,119,6,71,216,42,164,55,124,237,92,81,228,227,156,0,38,189,152,58,215,177,80,252,71,86,51,210,70,33,106,200,184,26,246,139,249,41,191,104,163,253,21,26,43,108,146,94,243,204,112,236,219,139,218,249,224,255,76,150,203,7];
246
+
247
+ test('openWalletFromSeed: 96-byte seed produces expected address (hybrideds)', () => {
248
+ assert.ok(isCirclAvailable(), 'CIRCL WASM must be loaded');
249
+ const wallet = qcsdk.openWalletFromSeed(TEST_SEED_ARRAY_48);
250
+ assert.ok(wallet, 'openWalletFromSeed should return a wallet for 96-byte seed');
251
+ assert.equal(wallet.address.toLowerCase(), TEST_SEED_ADDRESS);
252
+ assert.equal(qcsdk.verifyWallet(wallet), true);
253
+ assert.equal(qcsdk.isAddressValid(wallet.address), true);
254
+ });
255
+
256
+ test('openWalletFromSeed: 64-byte seed produces expected address (hybrid)', () => {
257
+ assert.ok(isCirclAvailable(), 'CIRCL WASM must be loaded');
258
+ const wallet = qcsdk.openWalletFromSeed(TEST_SEED_ARRAY_32);
259
+ assert.ok(wallet, 'openWalletFromSeed should return a wallet for 64-byte seed');
260
+ assert.equal(wallet.address.toLowerCase(), TEST_SEED_ADDRESS_32);
261
+ assert.equal(qcsdk.verifyWallet(wallet), true);
262
+ assert.equal(qcsdk.isAddressValid(wallet.address), true);
263
+ });
264
+
265
+ test('openWalletFromSeed: 72-byte seed produces expected address (hybrid5)', () => {
266
+ assert.ok(isCirclAvailable(), 'CIRCL WASM must be loaded');
267
+ const wallet = qcsdk.openWalletFromSeed(TEST_SEED_ARRAY_36);
268
+ assert.ok(wallet, 'openWalletFromSeed should return a wallet for 72-byte seed');
269
+ assert.equal(wallet.address.toLowerCase(), TEST_SEED_ADDRESS_36);
270
+ assert.equal(qcsdk.verifyWallet(wallet), true);
271
+ assert.equal(qcsdk.isAddressValid(wallet.address), true);
272
+ });
273
+
274
+ test('openWalletFromSeed: matches openWalletFromSeedWords for all three schemes', () => {
275
+ assert.ok(isCirclAvailable(), 'CIRCL WASM must be loaded');
276
+ for (const [seedArray, seedWords] of [
277
+ [TEST_SEED_ARRAY_48, TEST_SEED_WORDS],
278
+ [TEST_SEED_ARRAY_32, TEST_SEED_WORDS_32],
279
+ [TEST_SEED_ARRAY_36, TEST_SEED_WORDS_36],
280
+ ]) {
281
+ const fromSeed = qcsdk.openWalletFromSeed(seedArray);
282
+ const fromWords = qcsdk.openWalletFromSeedWords(seedWords);
283
+ assert.ok(fromSeed, 'openWalletFromSeed should return a wallet');
284
+ assert.ok(fromWords, 'openWalletFromSeedWords should return a wallet');
285
+ assert.equal(fromSeed.address.toLowerCase(), fromWords.address.toLowerCase());
286
+ }
287
+ });
288
+
289
+ test('openWalletFromSeed: accepts Uint8Array input', () => {
290
+ assert.ok(isCirclAvailable(), 'CIRCL WASM must be loaded');
291
+ const wallet = qcsdk.openWalletFromSeed(new Uint8Array(TEST_SEED_ARRAY_48));
292
+ assert.ok(wallet, 'openWalletFromSeed should accept Uint8Array');
293
+ assert.equal(wallet.address.toLowerCase(), TEST_SEED_ADDRESS);
294
+ });
295
+
296
+ test('openWalletFromSeed: null input returns null', () => {
297
+ assert.equal(qcsdk.openWalletFromSeed(null), null);
298
+ });
299
+
300
+ test('openWalletFromSeed: undefined input returns null', () => {
301
+ assert.equal(qcsdk.openWalletFromSeed(undefined), null);
302
+ });
303
+
304
+ test('openWalletFromSeed: empty array returns null', () => {
305
+ assert.equal(qcsdk.openWalletFromSeed([]), null);
306
+ });
307
+
308
+ test('openWalletFromSeed: wrong length array returns null', () => {
309
+ assert.equal(qcsdk.openWalletFromSeed([1, 2, 3, 4, 5]), null);
310
+ assert.equal(qcsdk.openWalletFromSeed(new Array(63).fill(0)), null);
311
+ assert.equal(qcsdk.openWalletFromSeed(new Array(65).fill(0)), null);
312
+ assert.equal(qcsdk.openWalletFromSeed(new Array(71).fill(0)), null);
313
+ assert.equal(qcsdk.openWalletFromSeed(new Array(73).fill(0)), null);
314
+ assert.equal(qcsdk.openWalletFromSeed(new Array(95).fill(0)), null);
315
+ assert.equal(qcsdk.openWalletFromSeed(new Array(97).fill(0)), null);
316
+ });
317
+
318
+ test('openWalletFromSeed: non-array input returns null', () => {
319
+ assert.equal(qcsdk.openWalletFromSeed('not an array'), null);
320
+ assert.equal(qcsdk.openWalletFromSeed(12345), null);
321
+ assert.equal(qcsdk.openWalletFromSeed({}), null);
322
+ });
323
+
240
324
  // Hardcoded encrypted wallet JSON (from openWalletFromSeedWords + serializeEncryptedWallet with SEED_WALLET_TEST_PASSPHRASE).
241
325
  // Deserialize and verify addresses match. Uses fixtures in tests/ (encrypted-48.json, encrypted-32.json, encrypted-36.json).
242
326
  test('seed words: deserializeEncryptedWallet from serialized 48/32/36 seed wallets — addresses match', () => {