@ricsam/quickjs-crypto 0.2.13 → 0.2.15

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 ADDED
@@ -0,0 +1,75 @@
1
+ # @ricsam/quickjs-crypto
2
+
3
+ Web Crypto API implementation providing cryptographic operations.
4
+
5
+ ```typescript
6
+ import { setupCrypto } from "@ricsam/quickjs-crypto";
7
+
8
+ const handle = setupCrypto(context);
9
+ ```
10
+
11
+ **Injected Globals:**
12
+ - `crypto.getRandomValues(array)` - Fill a TypedArray with random bytes
13
+ - `crypto.randomUUID()` - Generate a random UUID v4
14
+ - `crypto.subtle` - SubtleCrypto interface for cryptographic operations
15
+
16
+ **Usage in QuickJS:**
17
+
18
+ ```javascript
19
+ // Generate random bytes
20
+ const bytes = new Uint8Array(16);
21
+ crypto.getRandomValues(bytes);
22
+
23
+ // Generate UUID
24
+ const uuid = crypto.randomUUID();
25
+ console.log(uuid); // "550e8400-e29b-41d4-a716-446655440000"
26
+
27
+ // Hash data with SHA-256
28
+ const data = new TextEncoder().encode("Hello, World!");
29
+ const hash = await crypto.subtle.digest("SHA-256", data);
30
+
31
+ // Generate encryption key
32
+ const key = await crypto.subtle.generateKey(
33
+ { name: "AES-GCM", length: 256 },
34
+ true,
35
+ ["encrypt", "decrypt"]
36
+ );
37
+
38
+ // Encrypt data
39
+ const iv = crypto.getRandomValues(new Uint8Array(12));
40
+ const encrypted = await crypto.subtle.encrypt(
41
+ { name: "AES-GCM", iv },
42
+ key,
43
+ data
44
+ );
45
+
46
+ // Decrypt data
47
+ const decrypted = await crypto.subtle.decrypt(
48
+ { name: "AES-GCM", iv },
49
+ key,
50
+ encrypted
51
+ );
52
+ ```
53
+
54
+ #### SubtleCrypto Methods
55
+
56
+ | Method | Description |
57
+ |--------|-------------|
58
+ | `digest` | Generate hash (SHA-256, SHA-384, SHA-512) |
59
+ | `generateKey` | Generate symmetric or asymmetric keys |
60
+ | `sign` / `verify` | Sign and verify data (HMAC, ECDSA) |
61
+ | `encrypt` / `decrypt` | Encrypt and decrypt data (AES-GCM, AES-CBC) |
62
+ | `importKey` / `exportKey` | Import/export keys (raw, jwk, pkcs8, spki) |
63
+ | `deriveBits` / `deriveKey` | Derive keys (PBKDF2, ECDH) |
64
+ | `wrapKey` / `unwrapKey` | Wrap/unwrap keys for secure transport |
65
+
66
+ **Supported Algorithms:**
67
+ - **Encryption**: AES-GCM, AES-CBC
68
+ - **Signing**: HMAC, ECDSA
69
+ - **Hashing**: SHA-256, SHA-384, SHA-512
70
+ - **Key Derivation**: PBKDF2, ECDH
71
+ - **Asymmetric**: ECDSA (P-256, P-384, P-521), RSA-OAEP
72
+
73
+ > **Note**: Cryptographic operations are delegated to the host's native `crypto.subtle` implementation, ensuring secure and performant cryptography.
74
+
75
+ **See also:** [MDN Web Crypto API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API)
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@ricsam/quickjs-crypto",
3
- "version": "0.2.13",
3
+ "version": "0.2.15",
4
4
  "type": "commonjs"
5
5
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@ricsam/quickjs-crypto",
3
- "version": "0.2.13",
3
+ "version": "0.2.15",
4
4
  "type": "module"
5
5
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ricsam/quickjs-crypto",
3
- "version": "0.2.13",
3
+ "version": "0.2.15",
4
4
  "main": "./dist/cjs/index.cjs",
5
5
  "types": "./dist/types/index.d.ts",
6
6
  "exports": {
@@ -19,7 +19,7 @@
19
19
  "typecheck": "tsc --noEmit"
20
20
  },
21
21
  "dependencies": {
22
- "@ricsam/quickjs-core": "^0.2.13",
22
+ "@ricsam/quickjs-core": "^0.2.15",
23
23
  "quickjs-emscripten": "^0.31.0"
24
24
  },
25
25
  "peerDependencies": {