@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/constants.ts DELETED
@@ -1,16 +0,0 @@
1
- // Reference: Node.js lib/internal/crypto/util.js — crypto constants
2
- // Subset of Node.js crypto constants relevant to the GJS implementation
3
-
4
- export const constants = {
5
- // RSA padding modes (stubs for compatibility)
6
- RSA_PKCS1_PADDING: 1,
7
- RSA_NO_PADDING: 3,
8
- RSA_PKCS1_OAEP_PADDING: 4,
9
- RSA_PKCS1_PSS_PADDING: 6,
10
-
11
- // DiffieHellman error codes
12
- DH_CHECK_P_NOT_SAFE_PRIME: 2,
13
- DH_CHECK_P_NOT_PRIME: 1,
14
- DH_UNABLE_TO_CHECK_GENERATOR: 4,
15
- DH_NOT_SUITABLE_GENERATOR: 8,
16
- } as const;
@@ -1,64 +0,0 @@
1
- // Crypto utilities for GJS — original implementation
2
- // Centralizes algorithm normalization, digest/block sizes, and common helpers
3
- // used across hash, hmac, pbkdf2, hkdf, mgf1, rsa-pss, rsa-oaep, ecdsa, and sign modules.
4
-
5
- import { Buffer } from 'node:buffer';
6
-
7
- /**
8
- * Normalize a hash algorithm name to lowercase without hyphens.
9
- * e.g. "SHA-256" → "sha256", "MD5" → "md5"
10
- */
11
- export function normalizeAlgorithm(algorithm: string): string {
12
- return algorithm.toLowerCase().replace(/-/g, '');
13
- }
14
-
15
- /** Hash digest output sizes in bytes. */
16
- export const DIGEST_SIZES: Record<string, number> = {
17
- md5: 16,
18
- sha1: 20,
19
- sha256: 32,
20
- sha384: 48,
21
- sha512: 64,
22
- };
23
-
24
- /** Hash block sizes in bytes (used for HMAC key padding). */
25
- export const BLOCK_SIZES: Record<string, number> = {
26
- md5: 64,
27
- sha1: 64,
28
- sha256: 64,
29
- sha384: 128,
30
- sha512: 128,
31
- };
32
-
33
- /** Set of supported hash algorithm names (normalized). */
34
- export const SUPPORTED_ALGORITHMS = new Set(['md5', 'sha1', 'sha256', 'sha384', 'sha512']);
35
-
36
- /**
37
- * Get hash digest size in bytes for a given algorithm.
38
- * Accepts unnormalized names (e.g. "SHA-256").
39
- */
40
- export function hashSize(algo: string): number {
41
- const normalized = normalizeAlgorithm(algo);
42
- const size = DIGEST_SIZES[normalized];
43
- if (size === undefined) {
44
- throw new Error(`Unknown hash algorithm: ${algo}`);
45
- }
46
- return size;
47
- }
48
-
49
- /**
50
- * Convert various input types to Buffer.
51
- * Handles string, Buffer, Uint8Array, DataView, and ArrayBuffer.
52
- */
53
- export function toBuffer(input: string | Buffer | Uint8Array | DataView | ArrayBuffer, encoding?: string): Buffer {
54
- if (typeof input === 'string') {
55
- return Buffer.from(input, (encoding as BufferEncoding) || 'utf8');
56
- }
57
- if (input instanceof DataView) {
58
- return Buffer.from(input.buffer, input.byteOffset, input.byteLength);
59
- }
60
- if (input instanceof ArrayBuffer) {
61
- return Buffer.from(input);
62
- }
63
- return Buffer.from(input);
64
- }
package/src/dh.spec.ts DELETED
@@ -1,111 +0,0 @@
1
- // Ported from refs/node-test/parallel/test-crypto-dh.js
2
- // Original: MIT license, Copyright (c) Node.js contributors
3
-
4
- import { describe, it, expect } from '@gjsify/unit';
5
- import { createDiffieHellman, getDiffieHellman } from 'node:crypto';
6
- import { Buffer } from 'node:buffer';
7
-
8
- export default async () => {
9
-
10
- await describe('crypto.createDiffieHellman', async () => {
11
- await it('should be a function', async () => {
12
- expect(typeof createDiffieHellman).toBe('function');
13
- });
14
-
15
- await it('should create DH with prime buffer', async () => {
16
- // Use a predefined group prime instead of generating (Node.js rejects small primes)
17
- const dh = getDiffieHellman('modp14');
18
- expect(dh).toBeDefined();
19
- expect(typeof dh.generateKeys).toBe('function');
20
- });
21
-
22
- await it('should generate keys', async () => {
23
- const dh = getDiffieHellman('modp14');
24
- const keys = dh.generateKeys();
25
- expect(keys).toBeDefined();
26
- expect(Buffer.isBuffer(keys)).toBe(true);
27
- expect(keys.length).toBeGreaterThan(0);
28
- });
29
-
30
- await it('should get prime and generator', async () => {
31
- const dh = getDiffieHellman('modp14');
32
- dh.generateKeys();
33
- const prime = dh.getPrime();
34
- const generator = dh.getGenerator();
35
- expect(Buffer.isBuffer(prime)).toBe(true);
36
- expect(Buffer.isBuffer(generator)).toBe(true);
37
- expect(prime.length).toBeGreaterThan(0);
38
- expect(generator.length).toBeGreaterThan(0);
39
- });
40
-
41
- await it('should compute shared secret', async () => {
42
- const alice = createDiffieHellman(512);
43
- alice.generateKeys();
44
-
45
- const bob = createDiffieHellman(alice.getPrime(), alice.getGenerator());
46
- bob.generateKeys();
47
-
48
- const aliceSecret = alice.computeSecret(bob.getPublicKey());
49
- const bobSecret = bob.computeSecret(alice.getPublicKey());
50
-
51
- expect(aliceSecret.toString('hex')).toBe(bobSecret.toString('hex'));
52
- });
53
-
54
- await it('should support hex encoding for keys', async () => {
55
- const dh = getDiffieHellman('modp5');
56
- dh.generateKeys();
57
-
58
- const pubHex = dh.getPublicKey('hex');
59
- const privHex = dh.getPrivateKey('hex');
60
- expect(typeof pubHex).toBe('string');
61
- expect(typeof privHex).toBe('string');
62
- expect(pubHex.length).toBeGreaterThan(0);
63
- expect(privHex.length).toBeGreaterThan(0);
64
- });
65
-
66
- await it('should create DH from prime buffer', async () => {
67
- const source = getDiffieHellman('modp5');
68
- const primeBuf = source.getPrime();
69
-
70
- const dh = createDiffieHellman(primeBuf);
71
- dh.generateKeys();
72
- expect(dh.getPrime('hex')).toBe(primeBuf.toString('hex'));
73
- });
74
- });
75
-
76
- await describe('crypto.getDiffieHellman', async () => {
77
- await it('should be a function', async () => {
78
- expect(typeof getDiffieHellman).toBe('function');
79
- });
80
-
81
- await it('should return a DH object for modp14', async () => {
82
- const dh = getDiffieHellman('modp14');
83
- expect(dh).toBeDefined();
84
- expect(typeof dh.generateKeys).toBe('function');
85
- });
86
-
87
- await it('should compute shared secret with predefined group', async () => {
88
- const alice = getDiffieHellman('modp14');
89
- alice.generateKeys();
90
-
91
- const bob = getDiffieHellman('modp14');
92
- bob.generateKeys();
93
-
94
- const aliceSecret = alice.computeSecret(bob.getPublicKey());
95
- const bobSecret = bob.computeSecret(alice.getPublicKey());
96
-
97
- expect(aliceSecret.toString('hex')).toBe(bobSecret.toString('hex'));
98
- });
99
-
100
- await it('should support modp5', async () => {
101
- const dh = getDiffieHellman('modp5');
102
- dh.generateKeys();
103
- const pub = dh.getPublicKey();
104
- expect(pub.length).toBeGreaterThan(0);
105
- });
106
-
107
- await it('should throw for unknown group', async () => {
108
- expect(() => getDiffieHellman('modp999')).toThrow();
109
- });
110
- });
111
- };