quantumcoin 7.0.6 → 7.0.8

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.
@@ -388,5 +388,177 @@ describe("Address + Wallet (offline)", () => {
388
388
  assert.equal(await qc.resolveAddress(wallet), wallet.address.toLowerCase());
389
389
  assert.equal(await qc.resolveAddress(Promise.resolve(wallet.address)), wallet.address.toLowerCase());
390
390
  });
391
+
392
+ // ---------------------------------------------------------------------------
393
+ // createRandom with keyType
394
+ // ---------------------------------------------------------------------------
395
+
396
+ it("createRandom(null, null) creates wallet with explicit null keyType", async () => {
397
+ await Initialize(null);
398
+ const w = qc.Wallet.createRandom(null, null);
399
+ assert.equal(qc.isAddress(w.address), true);
400
+ });
401
+
402
+ it("createRandom(null, 3) creates wallet with keyType 3 and sign/verify roundtrip", async () => {
403
+ await Initialize(null);
404
+ const w = qc.Wallet.createRandom(null, 3);
405
+ assert.equal(qc.isAddress(w.address), true);
406
+ const sig = w.signMessageSync("kt3 test");
407
+ assert.ok(sig.startsWith("0x"));
408
+ assert.equal(qc.verifyMessage("kt3 test", sig), w.address.toLowerCase());
409
+ });
410
+
411
+ it("createRandom(null, 5) creates wallet with keyType 5 and sign/verify roundtrip", async () => {
412
+ await Initialize(null);
413
+ const w = qc.Wallet.createRandom(null, 5);
414
+ assert.equal(qc.isAddress(w.address), true);
415
+ const sig = w.signMessageSync("kt5 test");
416
+ assert.ok(sig.startsWith("0x"));
417
+ assert.equal(qc.verifyMessage("kt5 test", sig), w.address.toLowerCase());
418
+ });
419
+
420
+ it("createRandom(null, 3) signTransaction works offline", async () => {
421
+ await Initialize(null);
422
+ const w = qc.Wallet.createRandom(null, 3);
423
+ const to = qc.Wallet.createRandom().address;
424
+ const raw = await w.signTransaction({ to, value: 0n, gasLimit: 21000, nonce: 0, chainId: 123123 });
425
+ assert.ok(typeof raw === "string" && raw.startsWith("0x"));
426
+ });
427
+
428
+ it("createRandom(null, 5) signTransaction works offline", async () => {
429
+ await Initialize(null);
430
+ const w = qc.Wallet.createRandom(null, 5);
431
+ const to = qc.Wallet.createRandom().address;
432
+ const raw = await w.signTransaction({ to, value: 0n, gasLimit: 21000, nonce: 0, chainId: 123123 });
433
+ assert.ok(typeof raw === "string" && raw.startsWith("0x"));
434
+ });
435
+
436
+ it("createRandom(null, 3) encryptSync + fromEncryptedJsonSync roundtrip", async () => {
437
+ await Initialize(null);
438
+ const w = qc.Wallet.createRandom(null, 3);
439
+ const json = w.encryptSync("testPassword123!");
440
+ const w2 = qc.Wallet.fromEncryptedJsonSync(json, "testPassword123!");
441
+ assert.equal(w2.address, w.address);
442
+ });
443
+
444
+ it("createRandom(null, 5) encryptSync + fromEncryptedJsonSync roundtrip", async () => {
445
+ await Initialize(null);
446
+ const w = qc.Wallet.createRandom(null, 5);
447
+ const json = w.encryptSync("testPassword123!");
448
+ const w2 = qc.Wallet.fromEncryptedJsonSync(json, "testPassword123!");
449
+ assert.equal(w2.address, w.address);
450
+ });
451
+
452
+ it("createRandom rejects invalid keyType values", async () => {
453
+ await Initialize(null);
454
+ assert.throws(() => qc.Wallet.createRandom(null, 1), /keyType must be null, 3, or 5/);
455
+ assert.throws(() => qc.Wallet.createRandom(null, 2), /keyType must be null, 3, or 5/);
456
+ assert.throws(() => qc.Wallet.createRandom(null, 4), /keyType must be null, 3, or 5/);
457
+ assert.throws(() => qc.Wallet.createRandom(null, "3"), /keyType must be null, 3, or 5/);
458
+ assert.throws(() => qc.Wallet.createRandom(null, true), /keyType must be null, 3, or 5/);
459
+ });
460
+
461
+ // ---------------------------------------------------------------------------
462
+ // createRandomSeed
463
+ // ---------------------------------------------------------------------------
464
+
465
+ it("createRandomSeed() returns 32-word array (default keyType)", async () => {
466
+ await Initialize(null);
467
+ const words = qc.Wallet.createRandomSeed();
468
+ assert.equal(Array.isArray(words), true);
469
+ assert.equal(words.length, 32);
470
+ assert.ok(words.every((w) => typeof w === "string" && w.length > 0));
471
+ });
472
+
473
+ it("createRandomSeed(3) returns 32-word array", async () => {
474
+ await Initialize(null);
475
+ const words = qc.Wallet.createRandomSeed(3);
476
+ assert.equal(words.length, 32);
477
+ });
478
+
479
+ it("createRandomSeed(5) returns 36-word array", async () => {
480
+ await Initialize(null);
481
+ const words = qc.Wallet.createRandomSeed(5);
482
+ assert.equal(words.length, 36);
483
+ });
484
+
485
+ it("createRandomSeed roundtrip via fromPhrase produces valid signing wallet", async () => {
486
+ await Initialize(null);
487
+ const words = qc.Wallet.createRandomSeed(3);
488
+ const w = qc.Wallet.fromPhrase(words);
489
+ assert.equal(qc.isAddress(w.address), true);
490
+ const sig = w.signMessageSync("seed roundtrip");
491
+ assert.equal(qc.verifyMessage("seed roundtrip", sig), w.address.toLowerCase());
492
+ });
493
+
494
+ it("createRandomSeed rejects invalid keyType", async () => {
495
+ await Initialize(null);
496
+ assert.throws(() => qc.Wallet.createRandomSeed(1), /keyType must be null, 3, or 5/);
497
+ assert.throws(() => qc.Wallet.createRandomSeed(2), /keyType must be null, 3, or 5/);
498
+ assert.throws(() => qc.Wallet.createRandomSeed(4), /keyType must be null, 3, or 5/);
499
+ });
500
+
501
+ // ---------------------------------------------------------------------------
502
+ // fromSeed
503
+ // ---------------------------------------------------------------------------
504
+
505
+ it("fromSeed roundtrip: createRandomSeed(3) -> fromPhrase -> fromSeed produces same address", async () => {
506
+ await Initialize(null);
507
+ const seedwords = require("seed-words");
508
+ const words = qc.Wallet.createRandomSeed(3);
509
+ const seedArr = seedwords.getSeedArrayFromWordList(words);
510
+ assert.equal(seedArr.length, 64);
511
+ const wFromWords = qc.Wallet.fromPhrase(words);
512
+ const wFromSeed = qc.Wallet.fromSeed(Array.from(seedArr));
513
+ assert.equal(wFromSeed.address, wFromWords.address);
514
+ });
515
+
516
+ it("fromSeed roundtrip: createRandomSeed(5) -> fromPhrase -> fromSeed produces same address", async () => {
517
+ await Initialize(null);
518
+ const seedwords = require("seed-words");
519
+ const words = qc.Wallet.createRandomSeed(5);
520
+ const seedArr = seedwords.getSeedArrayFromWordList(words);
521
+ assert.equal(seedArr.length, 72);
522
+ const wFromWords = qc.Wallet.fromPhrase(words);
523
+ const wFromSeed = qc.Wallet.fromSeed(Array.from(seedArr));
524
+ assert.equal(wFromSeed.address, wFromWords.address);
525
+ });
526
+
527
+ it("fromSeed rejects non-array input", async () => {
528
+ await Initialize(null);
529
+ assert.throws(() => qc.Wallet.fromSeed("not an array"), /seed must be an array/);
530
+ assert.throws(() => qc.Wallet.fromSeed(12345), /seed must be an array/);
531
+ assert.throws(() => qc.Wallet.fromSeed(null), /seed must be an array/);
532
+ });
533
+
534
+ it("fromSeed rejects wrong-length arrays", async () => {
535
+ await Initialize(null);
536
+ assert.throws(() => qc.Wallet.fromSeed(new Array(32).fill(0)), /seed must be 64, 72, or 96 bytes/);
537
+ assert.throws(() => qc.Wallet.fromSeed(new Array(48).fill(0)), /seed must be 64, 72, or 96 bytes/);
538
+ assert.throws(() => qc.Wallet.fromSeed(new Array(100).fill(0)), /seed must be 64, 72, or 96 bytes/);
539
+ assert.throws(() => qc.Wallet.fromSeed([]), /seed must be 64, 72, or 96 bytes/);
540
+ });
541
+
542
+ // ---------------------------------------------------------------------------
543
+ // Hardcoded fromSeed test vectors
544
+ // ---------------------------------------------------------------------------
545
+
546
+ it("fromSeed with hardcoded 64-byte seed (keyType 3) produces expected address", async () => {
547
+ await Initialize(null);
548
+ const seed3 = [51,214,149,165,206,96,227,5,173,247,83,219,210,2,221,2,4,48,117,55,88,109,241,204,31,62,23,128,47,21,168,247,28,118,30,185,229,255,17,27,34,107,225,138,254,156,55,9,253,255,142,148,234,189,232,43,173,84,159,108,8,35,58,77];
549
+ const addr3 = "0x2ceeaE376719215f1597d144Ee1549AB64f1Eb8D49f1f84D9F3a526400d1a4F6".toLowerCase();
550
+ const w = qc.Wallet.fromSeed(seed3);
551
+ assert.equal(w.address, addr3);
552
+ assert.equal(qc.isAddress(w.address), true);
553
+ });
554
+
555
+ it("fromSeed with hardcoded 72-byte seed (keyType 5) produces expected address", async () => {
556
+ await Initialize(null);
557
+ const seed5 = [58,255,242,97,43,252,180,220,51,164,15,238,50,215,248,10,29,19,152,124,211,29,41,81,233,103,152,244,59,239,145,216,189,77,244,198,230,165,109,191,18,12,199,252,232,42,197,9,237,237,237,93,254,89,177,192,7,178,95,70,174,88,126,130,89,205,140,175,7,142,191,84];
558
+ const addr5 = "0xeB12DF9517F867749056fE02EbCba67c9D84a97A6f4eDc6DA6555Ff4A30b9538".toLowerCase();
559
+ const w = qc.Wallet.fromSeed(seed5);
560
+ assert.equal(w.address, addr5);
561
+ assert.equal(qc.isAddress(w.address), true);
562
+ });
391
563
  });
392
564
 
@@ -376,4 +376,174 @@ describe("Address + Wallet (offline)", () => {
376
376
  assert.equal(await qc.resolveAddress(wallet), wallet.address.toLowerCase());
377
377
  assert.equal(await qc.resolveAddress(Promise.resolve(wallet.address)), wallet.address.toLowerCase());
378
378
  });
379
+
380
+ // ---------------------------------------------------------------------------
381
+ // createRandom with keyType
382
+ // ---------------------------------------------------------------------------
383
+
384
+ it("createRandom(null, null) creates wallet with explicit null keyType", async () => {
385
+ await Initialize(null);
386
+ const w = qc.Wallet.createRandom(undefined, null);
387
+ assert.equal(qc.isAddress(w.address), true);
388
+ });
389
+
390
+ it("createRandom(null, 3) creates wallet with keyType 3 and sign/verify roundtrip", async () => {
391
+ await Initialize(null);
392
+ const w = qc.Wallet.createRandom(undefined, 3);
393
+ assert.equal(qc.isAddress(w.address), true);
394
+ const sig = w.signMessageSync("kt3 test");
395
+ assert.ok(sig.startsWith("0x"));
396
+ assert.equal(qc.verifyMessage("kt3 test", sig), w.address.toLowerCase());
397
+ });
398
+
399
+ it("createRandom(null, 5) creates wallet with keyType 5 and sign/verify roundtrip", async () => {
400
+ await Initialize(null);
401
+ const w = qc.Wallet.createRandom(undefined, 5);
402
+ assert.equal(qc.isAddress(w.address), true);
403
+ const sig = w.signMessageSync("kt5 test");
404
+ assert.ok(sig.startsWith("0x"));
405
+ assert.equal(qc.verifyMessage("kt5 test", sig), w.address.toLowerCase());
406
+ });
407
+
408
+ it("createRandom(null, 3) signTransaction works offline", async () => {
409
+ await Initialize(null);
410
+ const w = qc.Wallet.createRandom(undefined, 3);
411
+ const to = qc.Wallet.createRandom().address;
412
+ const raw = await w.signTransaction({ to, value: 0n, gasLimit: 21000, nonce: 0, chainId: 123123 });
413
+ assert.ok(typeof raw === "string" && raw.startsWith("0x"));
414
+ });
415
+
416
+ it("createRandom(null, 5) signTransaction works offline", async () => {
417
+ await Initialize(null);
418
+ const w = qc.Wallet.createRandom(undefined, 5);
419
+ const to = qc.Wallet.createRandom().address;
420
+ const raw = await w.signTransaction({ to, value: 0n, gasLimit: 21000, nonce: 0, chainId: 123123 });
421
+ assert.ok(typeof raw === "string" && raw.startsWith("0x"));
422
+ });
423
+
424
+ it("createRandom(null, 3) encryptSync + fromEncryptedJsonSync roundtrip", async () => {
425
+ await Initialize(null);
426
+ const w = qc.Wallet.createRandom(undefined, 3);
427
+ const json = w.encryptSync("testPassword123!");
428
+ const w2 = qc.Wallet.fromEncryptedJsonSync(json, "testPassword123!");
429
+ assert.equal(w2.address, w.address);
430
+ });
431
+
432
+ it("createRandom(null, 5) encryptSync + fromEncryptedJsonSync roundtrip", async () => {
433
+ await Initialize(null);
434
+ const w = qc.Wallet.createRandom(undefined, 5);
435
+ const json = w.encryptSync("testPassword123!");
436
+ const w2 = qc.Wallet.fromEncryptedJsonSync(json, "testPassword123!");
437
+ assert.equal(w2.address, w.address);
438
+ });
439
+
440
+ it("createRandom rejects invalid keyType values", async () => {
441
+ await Initialize(null);
442
+ assert.throws(() => qc.Wallet.createRandom(undefined, 1), /keyType must be null, 3, or 5/);
443
+ assert.throws(() => qc.Wallet.createRandom(undefined, 2), /keyType must be null, 3, or 5/);
444
+ assert.throws(() => qc.Wallet.createRandom(undefined, 4), /keyType must be null, 3, or 5/);
445
+ });
446
+
447
+ // ---------------------------------------------------------------------------
448
+ // createRandomSeed
449
+ // ---------------------------------------------------------------------------
450
+
451
+ it("createRandomSeed() returns 32-word array (default keyType)", async () => {
452
+ await Initialize(null);
453
+ const words = qc.Wallet.createRandomSeed();
454
+ assert.equal(Array.isArray(words), true);
455
+ assert.equal(words.length, 32);
456
+ assert.ok(words.every((w: string) => typeof w === "string" && w.length > 0));
457
+ });
458
+
459
+ it("createRandomSeed(3) returns 32-word array", async () => {
460
+ await Initialize(null);
461
+ const words = qc.Wallet.createRandomSeed(3);
462
+ assert.equal(words.length, 32);
463
+ });
464
+
465
+ it("createRandomSeed(5) returns 36-word array", async () => {
466
+ await Initialize(null);
467
+ const words = qc.Wallet.createRandomSeed(5);
468
+ assert.equal(words.length, 36);
469
+ });
470
+
471
+ it("createRandomSeed roundtrip via fromPhrase produces valid signing wallet", async () => {
472
+ await Initialize(null);
473
+ const words = qc.Wallet.createRandomSeed(3);
474
+ const w = qc.Wallet.fromPhrase(words);
475
+ assert.equal(qc.isAddress(w.address), true);
476
+ const sig = w.signMessageSync("seed roundtrip");
477
+ assert.equal(qc.verifyMessage("seed roundtrip", sig), w.address.toLowerCase());
478
+ });
479
+
480
+ it("createRandomSeed rejects invalid keyType", async () => {
481
+ await Initialize(null);
482
+ assert.throws(() => qc.Wallet.createRandomSeed(1), /keyType must be null, 3, or 5/);
483
+ assert.throws(() => qc.Wallet.createRandomSeed(2), /keyType must be null, 3, or 5/);
484
+ assert.throws(() => qc.Wallet.createRandomSeed(4), /keyType must be null, 3, or 5/);
485
+ });
486
+
487
+ // ---------------------------------------------------------------------------
488
+ // fromSeed
489
+ // ---------------------------------------------------------------------------
490
+
491
+ it("fromSeed roundtrip: createRandomSeed(3) -> fromPhrase -> fromSeed produces same address", async () => {
492
+ await Initialize(null);
493
+ const seedwords = require("seed-words");
494
+ const words = qc.Wallet.createRandomSeed(3);
495
+ const seedArr = seedwords.getSeedArrayFromWordList(words);
496
+ assert.equal(seedArr.length, 64);
497
+ const wFromWords = qc.Wallet.fromPhrase(words);
498
+ const wFromSeed = qc.Wallet.fromSeed(Array.from(seedArr));
499
+ assert.equal(wFromSeed.address, wFromWords.address);
500
+ });
501
+
502
+ it("fromSeed roundtrip: createRandomSeed(5) -> fromPhrase -> fromSeed produces same address", async () => {
503
+ await Initialize(null);
504
+ const seedwords = require("seed-words");
505
+ const words = qc.Wallet.createRandomSeed(5);
506
+ const seedArr = seedwords.getSeedArrayFromWordList(words);
507
+ assert.equal(seedArr.length, 72);
508
+ const wFromWords = qc.Wallet.fromPhrase(words);
509
+ const wFromSeed = qc.Wallet.fromSeed(Array.from(seedArr));
510
+ assert.equal(wFromSeed.address, wFromWords.address);
511
+ });
512
+
513
+ it("fromSeed rejects non-array input", async () => {
514
+ await Initialize(null);
515
+ assert.throws(() => qc.Wallet.fromSeed("not an array" as any), /seed must be an array/);
516
+ assert.throws(() => qc.Wallet.fromSeed(12345 as any), /seed must be an array/);
517
+ assert.throws(() => qc.Wallet.fromSeed(null as any), /seed must be an array/);
518
+ });
519
+
520
+ it("fromSeed rejects wrong-length arrays", async () => {
521
+ await Initialize(null);
522
+ assert.throws(() => qc.Wallet.fromSeed(new Array(32).fill(0)), /seed must be 64, 72, or 96 bytes/);
523
+ assert.throws(() => qc.Wallet.fromSeed(new Array(48).fill(0)), /seed must be 64, 72, or 96 bytes/);
524
+ assert.throws(() => qc.Wallet.fromSeed(new Array(100).fill(0)), /seed must be 64, 72, or 96 bytes/);
525
+ assert.throws(() => qc.Wallet.fromSeed([]), /seed must be 64, 72, or 96 bytes/);
526
+ });
527
+
528
+ // ---------------------------------------------------------------------------
529
+ // Hardcoded fromSeed test vectors
530
+ // ---------------------------------------------------------------------------
531
+
532
+ it("fromSeed with hardcoded 64-byte seed (keyType 3) produces expected address", async () => {
533
+ await Initialize(null);
534
+ const seed3 = [51,214,149,165,206,96,227,5,173,247,83,219,210,2,221,2,4,48,117,55,88,109,241,204,31,62,23,128,47,21,168,247,28,118,30,185,229,255,17,27,34,107,225,138,254,156,55,9,253,255,142,148,234,189,232,43,173,84,159,108,8,35,58,77];
535
+ const addr3 = "0x2ceeaE376719215f1597d144Ee1549AB64f1Eb8D49f1f84D9F3a526400d1a4F6".toLowerCase();
536
+ const w = qc.Wallet.fromSeed(seed3);
537
+ assert.equal(w.address, addr3);
538
+ assert.equal(qc.isAddress(w.address), true);
539
+ });
540
+
541
+ it("fromSeed with hardcoded 72-byte seed (keyType 5) produces expected address", async () => {
542
+ await Initialize(null);
543
+ const seed5 = [58,255,242,97,43,252,180,220,51,164,15,238,50,215,248,10,29,19,152,124,211,29,41,81,233,103,152,244,59,239,145,216,189,77,244,198,230,165,109,191,18,12,199,252,232,42,197,9,237,237,237,93,254,89,177,192,7,178,95,70,174,88,126,130,89,205,140,175,7,142,191,84];
544
+ const addr5 = "0xeB12DF9517F867749056fE02EbCba67c9D84a97A6f4eDc6DA6555Ff4A30b9538".toLowerCase();
545
+ const w = qc.Wallet.fromSeed(seed5);
546
+ assert.equal(w.address, addr5);
547
+ assert.equal(qc.isAddress(w.address), true);
548
+ });
379
549
  });