@gjsify/crypto 0.3.21 → 0.4.3

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.
Files changed (63) hide show
  1. package/lib/esm/_virtual/_rolldown/runtime.js +1 -0
  2. package/lib/esm/asn1.js +1 -1
  3. package/lib/esm/bigint-math.js +1 -1
  4. package/lib/esm/cipher.js +1 -1
  5. package/lib/esm/crypto-utils.js +1 -1
  6. package/lib/esm/dh.js +1 -1
  7. package/lib/esm/ecdh.js +1 -1
  8. package/lib/esm/ecdsa.js +1 -1
  9. package/lib/esm/hash.js +1 -1
  10. package/lib/esm/hkdf.js +1 -1
  11. package/lib/esm/hmac.js +1 -1
  12. package/lib/esm/index.js +1 -1
  13. package/lib/esm/key-object.js +1 -1
  14. package/lib/esm/mgf1.js +1 -1
  15. package/lib/esm/pbkdf2.js +1 -1
  16. package/lib/esm/public-encrypt.js +1 -1
  17. package/lib/esm/random.js +1 -1
  18. package/lib/esm/rsa-oaep.js +1 -1
  19. package/lib/esm/rsa-pss.js +1 -1
  20. package/lib/esm/scrypt.js +1 -1
  21. package/lib/esm/sign.js +1 -1
  22. package/lib/esm/timing-safe-equal.js +1 -1
  23. package/lib/esm/x509.js +1 -1
  24. package/package.json +46 -43
  25. package/src/asn1.ts +0 -797
  26. package/src/bigint-math.ts +0 -45
  27. package/src/cipher.spec.ts +0 -332
  28. package/src/cipher.ts +0 -952
  29. package/src/constants.ts +0 -16
  30. package/src/crypto-utils.ts +0 -64
  31. package/src/dh.spec.ts +0 -111
  32. package/src/dh.ts +0 -761
  33. package/src/ecdh.spec.ts +0 -120
  34. package/src/ecdh.ts +0 -624
  35. package/src/ecdsa.ts +0 -243
  36. package/src/extended.spec.ts +0 -444
  37. package/src/gcm.spec.ts +0 -141
  38. package/src/hash.spec.ts +0 -86
  39. package/src/hash.ts +0 -119
  40. package/src/hkdf.ts +0 -99
  41. package/src/hmac.spec.ts +0 -64
  42. package/src/hmac.ts +0 -123
  43. package/src/index.ts +0 -93
  44. package/src/key-object.spec.ts +0 -205
  45. package/src/key-object.ts +0 -401
  46. package/src/mgf1.ts +0 -37
  47. package/src/pbkdf2.spec.ts +0 -76
  48. package/src/pbkdf2.ts +0 -106
  49. package/src/public-encrypt.ts +0 -288
  50. package/src/random.spec.ts +0 -133
  51. package/src/random.ts +0 -183
  52. package/src/rsa-oaep.ts +0 -167
  53. package/src/rsa-pss.ts +0 -190
  54. package/src/scrypt.spec.ts +0 -90
  55. package/src/scrypt.ts +0 -191
  56. package/src/sign.spec.ts +0 -160
  57. package/src/sign.ts +0 -319
  58. package/src/test.mts +0 -19
  59. package/src/timing-safe-equal.ts +0 -21
  60. package/src/x509.spec.ts +0 -211
  61. package/src/x509.ts +0 -262
  62. package/tsconfig.json +0 -29
  63. package/tsconfig.tsbuildinfo +0 -1
package/src/ecdh.spec.ts DELETED
@@ -1,120 +0,0 @@
1
- // Ported from refs/node-test/parallel/test-crypto-ecdh.js
2
- // Original: MIT license, Copyright (c) Node.js contributors
3
-
4
- import { describe, it, expect } from '@gjsify/unit';
5
- import { createECDH, getCurves } from 'node:crypto';
6
- import { Buffer } from 'node:buffer';
7
-
8
- export default async () => {
9
-
10
- await describe('crypto.getCurves', async () => {
11
- await it('should return an array', async () => {
12
- const curves = getCurves();
13
- expect(Array.isArray(curves)).toBe(true);
14
- });
15
-
16
- await it('should contain common curves', async () => {
17
- const curves = getCurves();
18
- expect(curves).toContain('secp256k1');
19
- expect(curves).toContain('prime256v1');
20
- expect(curves).toContain('secp384r1');
21
- expect(curves).toContain('secp521r1');
22
- });
23
- });
24
-
25
- await describe('crypto.createECDH', async () => {
26
- await it('should be a function', async () => {
27
- expect(typeof createECDH).toBe('function');
28
- });
29
-
30
- await it('should create an ECDH instance', async () => {
31
- const ecdh = createECDH('secp256k1');
32
- expect(ecdh).toBeDefined();
33
- expect(typeof ecdh.generateKeys).toBe('function');
34
- });
35
-
36
- await it('should generate keys for secp256k1', async () => {
37
- const ecdh = createECDH('secp256k1');
38
- const pub = ecdh.generateKeys();
39
- expect(Buffer.isBuffer(pub)).toBe(true);
40
- // Uncompressed public key: 0x04 + 32 bytes X + 32 bytes Y = 65 bytes
41
- expect(pub.length).toBe(65);
42
- expect(pub[0]).toBe(0x04);
43
- });
44
-
45
- await it('should generate keys for prime256v1', async () => {
46
- const ecdh = createECDH('prime256v1');
47
- const pub = ecdh.generateKeys();
48
- expect(Buffer.isBuffer(pub)).toBe(true);
49
- expect(pub.length).toBe(65);
50
- expect(pub[0]).toBe(0x04);
51
- });
52
-
53
- await it('should compute shared secret for secp256k1', async () => {
54
- const alice = createECDH('secp256k1');
55
- alice.generateKeys();
56
-
57
- const bob = createECDH('secp256k1');
58
- bob.generateKeys();
59
-
60
- const aliceSecret = alice.computeSecret(bob.getPublicKey());
61
- const bobSecret = bob.computeSecret(alice.getPublicKey());
62
-
63
- expect(aliceSecret.toString('hex')).toBe(bobSecret.toString('hex'));
64
- expect(aliceSecret.length).toBe(32);
65
- });
66
-
67
- await it('should compute shared secret for prime256v1', async () => {
68
- const alice = createECDH('prime256v1');
69
- alice.generateKeys();
70
-
71
- const bob = createECDH('prime256v1');
72
- bob.generateKeys();
73
-
74
- const aliceSecret = alice.computeSecret(bob.getPublicKey());
75
- const bobSecret = bob.computeSecret(alice.getPublicKey());
76
-
77
- expect(aliceSecret.toString('hex')).toBe(bobSecret.toString('hex'));
78
- expect(aliceSecret.length).toBe(32);
79
- });
80
-
81
- await it('should get/set private key', async () => {
82
- const ecdh = createECDH('secp256k1');
83
- ecdh.generateKeys();
84
- const priv = ecdh.getPrivateKey();
85
- expect(Buffer.isBuffer(priv)).toBe(true);
86
- // Node's native createECDH().getPrivateKey() uses OpenSSL's BN_bn2bin,
87
- // which strips leading zero bytes — ~1/256 of random 32-byte keys come
88
- // back shorter. Accept anything up to the curve byte length.
89
- expect(priv.length).toBeGreaterThan(0);
90
- expect(priv.length).toBeLessThan(33);
91
-
92
- const ecdh2 = createECDH('secp256k1');
93
- ecdh2.setPrivateKey(priv);
94
- expect(ecdh2.getPrivateKey('hex')).toBe(priv.toString('hex'));
95
- });
96
-
97
- await it('should support compressed public key format', async () => {
98
- const ecdh = createECDH('secp256k1');
99
- ecdh.generateKeys();
100
-
101
- const compressed = ecdh.getPublicKey(null, 'compressed');
102
- expect(Buffer.isBuffer(compressed)).toBe(true);
103
- expect(compressed.length).toBe(33);
104
- expect(compressed[0] === 0x02 || compressed[0] === 0x03).toBe(true);
105
- });
106
-
107
- await it('should support hex encoding', async () => {
108
- const ecdh = createECDH('secp256k1');
109
- ecdh.generateKeys();
110
-
111
- const pubHex = ecdh.getPublicKey('hex');
112
- expect(typeof pubHex).toBe('string');
113
- expect(pubHex.length).toBe(130); // 65 bytes * 2 hex chars
114
- });
115
-
116
- await it('should throw for unknown curve', async () => {
117
- expect(() => createECDH('nonexistent-curve')).toThrow();
118
- });
119
- });
120
- };