@darkbio/crypto 0.1.1 → 0.1.4

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/dist/rand.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Generate cryptographically secure random bytes.
3
+ *
4
+ * @param bytes - Number of random bytes to generate
5
+ * @returns A Uint8Array containing the random bytes
6
+ */
7
+ export declare function generate(bytes: number): Promise<Uint8Array>;
8
+ //# sourceMappingURL=rand.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rand.d.ts","sourceRoot":"","sources":["../src/rand.ts"],"names":[],"mappings":"AAiBA;;;;;GAKG;AACH,wBAAsB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAGjE"}
package/dist/xdsa.d.ts ADDED
@@ -0,0 +1,87 @@
1
+ /** Size of the secret key in bytes (64). */
2
+ export declare const SECRET_KEY_SIZE = 64;
3
+ /** Size of the public key in bytes (1984). */
4
+ export declare const PUBLIC_KEY_SIZE = 1984;
5
+ /** Size of a signature in bytes (3373). */
6
+ export declare const SIGNATURE_SIZE = 3373;
7
+ /** Size of a fingerprint in bytes (32). */
8
+ export declare const FINGERPRINT_SIZE = 32;
9
+ /**
10
+ * Get the size constants (requires WASM initialization).
11
+ */
12
+ export declare function sizes(): Promise<{
13
+ secretKey: number;
14
+ publicKey: number;
15
+ signature: number;
16
+ fingerprint: number;
17
+ }>;
18
+ /**
19
+ * Fingerprint is a 32-byte unique identifier for an xDSA key.
20
+ */
21
+ export declare class Fingerprint {
22
+ private readonly bytes;
23
+ private constructor();
24
+ /** Converts a 32-byte array into a fingerprint. */
25
+ static fromBytes(bytes: Uint8Array): Fingerprint;
26
+ /** Converts a fingerprint into a 32-byte array. */
27
+ toBytes(): Uint8Array;
28
+ }
29
+ /**
30
+ * Signature is a 3373-byte xDSA signature.
31
+ * Format: ML-DSA (3309 bytes) || Ed25519 (64 bytes)
32
+ */
33
+ export declare class Signature {
34
+ private readonly bytes;
35
+ private constructor();
36
+ /** Converts a 3373-byte array into a signature. */
37
+ static fromBytes(bytes: Uint8Array): Signature;
38
+ /** Converts a signature into a 3373-byte array. */
39
+ toBytes(): Uint8Array;
40
+ }
41
+ /**
42
+ * PublicKey is an ML-DSA-65 public key paired with an Ed25519 public key for
43
+ * verifying quantum resistant digital signatures.
44
+ * Format: ML-DSA (1952 bytes) || Ed25519 (32 bytes)
45
+ */
46
+ export declare class PublicKey {
47
+ private readonly bytes;
48
+ private constructor();
49
+ /** Converts a 1984-byte array into a public key. */
50
+ static fromBytes(bytes: Uint8Array): PublicKey;
51
+ /** Parses a PEM string into a public key. */
52
+ static fromPem(pem: string): Promise<PublicKey>;
53
+ /** Converts a public key into a 1984-byte array. */
54
+ toBytes(): Uint8Array;
55
+ /** Serializes a public key into a PEM string. */
56
+ toPem(): Promise<string>;
57
+ /** Returns a 256-bit unique identifier for this key. */
58
+ fingerprint(): Promise<Fingerprint>;
59
+ /** Verifies a digital signature of the message. */
60
+ verify(message: Uint8Array, signature: Signature): Promise<boolean>;
61
+ }
62
+ /**
63
+ * SecretKey is an ML-DSA-65 private key paired with an Ed25519 private key for
64
+ * creating quantum resistant digital signatures.
65
+ * Format: ML-DSA seed (32 bytes) || Ed25519 seed (32 bytes)
66
+ */
67
+ export declare class SecretKey {
68
+ private readonly bytes;
69
+ private constructor();
70
+ /** Creates a new, random private key. */
71
+ static generate(): Promise<SecretKey>;
72
+ /** Creates a private key from a 64-byte seed. */
73
+ static fromBytes(bytes: Uint8Array): SecretKey;
74
+ /** Parses a PEM string into a private key. */
75
+ static fromPem(pem: string): Promise<SecretKey>;
76
+ /** Converts a secret key into a 64-byte array. */
77
+ toBytes(): Uint8Array;
78
+ /** Serializes a private key into a PEM string. */
79
+ toPem(): Promise<string>;
80
+ /** Retrieves the public counterpart of the secret key. */
81
+ publicKey(): Promise<PublicKey>;
82
+ /** Returns a 256-bit unique identifier for this key. */
83
+ fingerprint(): Promise<Fingerprint>;
84
+ /** Creates a digital signature of the message. */
85
+ sign(message: Uint8Array): Promise<Signature>;
86
+ }
87
+ //# sourceMappingURL=xdsa.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xdsa.d.ts","sourceRoot":"","sources":["../src/xdsa.ts"],"names":[],"mappings":"AA+BA,4CAA4C;AAC5C,eAAO,MAAM,eAAe,KAAK,CAAC;AAElC,8CAA8C;AAC9C,eAAO,MAAM,eAAe,OAAO,CAAC;AAEpC,2CAA2C;AAC3C,eAAO,MAAM,cAAc,OAAO,CAAC;AAEnC,2CAA2C;AAC3C,eAAO,MAAM,gBAAgB,KAAK,CAAC;AAEnC;;GAEG;AACH,wBAAsB,KAAK,IAAI,OAAO,CAAC;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC,CAQD;AAED;;GAEG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAa;IAEnC,OAAO;IAIP,mDAAmD;IACnD,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW;IAOhD,mDAAmD;IACnD,OAAO,IAAI,UAAU;CAGtB;AAED;;;GAGG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAa;IAEnC,OAAO;IAIP,mDAAmD;IACnD,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS;IAO9C,mDAAmD;IACnD,OAAO,IAAI,UAAU;CAGtB;AAED;;;;GAIG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAa;IAEnC,OAAO;IAIP,oDAAoD;IACpD,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS;IAO9C,6CAA6C;WAChC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAMrD,oDAAoD;IACpD,OAAO,IAAI,UAAU;IAIrB,iDAAiD;IAC3C,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC;IAK9B,wDAAwD;IAClD,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC;IAMzC,mDAAmD;IAC7C,MAAM,CAAC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC;CAI1E;AAED;;;;GAIG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAa;IAEnC,OAAO;IAIP,yCAAyC;WAC5B,QAAQ,IAAI,OAAO,CAAC,SAAS,CAAC;IAM3C,iDAAiD;IACjD,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS;IAO9C,8CAA8C;WACjC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAMrD,kDAAkD;IAClD,OAAO,IAAI,UAAU;IAIrB,kDAAkD;IAC5C,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC;IAK9B,0DAA0D;IACpD,SAAS,IAAI,OAAO,CAAC,SAAS,CAAC;IAMrC,wDAAwD;IAClD,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC;IAKzC,kDAAkD;IAC5C,IAAI,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC;CAKpD"}
@@ -0,0 +1,102 @@
1
+ /** Size of the secret key seed in bytes (32). */
2
+ export declare const SECRET_KEY_SIZE = 32;
3
+ /** Size of the public key in bytes (1216). */
4
+ export declare const PUBLIC_KEY_SIZE = 1216;
5
+ /** Size of the encapsulated key in bytes (1120). */
6
+ export declare const ENCAP_KEY_SIZE = 1120;
7
+ /** Size of a fingerprint in bytes (32). */
8
+ export declare const FINGERPRINT_SIZE = 32;
9
+ /**
10
+ * Get the size constants (requires WASM initialization).
11
+ */
12
+ export declare function sizes(): Promise<{
13
+ secretKey: number;
14
+ publicKey: number;
15
+ encapKey: number;
16
+ fingerprint: number;
17
+ }>;
18
+ /**
19
+ * Fingerprint is a 32-byte unique identifier for an xHPKE key.
20
+ * It is the SHA256 hash of the raw public key.
21
+ */
22
+ export declare class Fingerprint {
23
+ private readonly bytes;
24
+ private constructor();
25
+ /** Converts a 32-byte array into a fingerprint. */
26
+ static fromBytes(bytes: Uint8Array): Fingerprint;
27
+ /** Converts a fingerprint into a 32-byte array. */
28
+ toBytes(): Uint8Array;
29
+ }
30
+ /**
31
+ * PublicKey contains an X-Wing public key for hybrid post-quantum encryption.
32
+ * Uses X-Wing KEM (ML-KEM-768 + X25519) with HPKE Base mode.
33
+ */
34
+ export declare class PublicKey {
35
+ private readonly bytes;
36
+ private constructor();
37
+ /**
38
+ * Converts a 1216-byte array into a public key.
39
+ *
40
+ * This validates the ML-KEM-768 component by checking that all polynomial
41
+ * coefficients are in the valid range [0, 3329).
42
+ */
43
+ static fromBytes(bytes: Uint8Array): PublicKey;
44
+ /** Parses a PEM string into a public key. */
45
+ static fromPem(pem: string): Promise<PublicKey>;
46
+ /** Converts a public key into a 1216-byte array. */
47
+ toBytes(): Uint8Array;
48
+ /** Serializes a public key into a PEM string. */
49
+ toPem(): Promise<string>;
50
+ /** Returns a 256-bit unique identifier for this key (SHA256 of raw public key). */
51
+ fingerprint(): Promise<Fingerprint>;
52
+ /**
53
+ * Seal (encrypt) a message to this public key.
54
+ *
55
+ * Uses X-Wing KEM (ML-KEM-768 + X25519) with HPKE Base mode.
56
+ *
57
+ * @param msgToSeal - The message to encrypt
58
+ * @param msgToAuth - Additional data to authenticate (but not encrypt)
59
+ * @param domain - Application domain for context separation
60
+ * @returns Sealed data (encapsulated key + ciphertext)
61
+ */
62
+ seal(msgToSeal: Uint8Array, msgToAuth: Uint8Array, domain: Uint8Array): Promise<Uint8Array>;
63
+ }
64
+ /**
65
+ * SecretKey contains an X-Wing private key for hybrid post-quantum encryption.
66
+ * Uses X-Wing KEM (ML-KEM-768 + X25519) with HPKE Base mode.
67
+ */
68
+ export declare class SecretKey {
69
+ private readonly bytes;
70
+ private constructor();
71
+ /** Creates a new, random private key. */
72
+ static generate(): Promise<SecretKey>;
73
+ /** Converts a 32-byte seed into a private key. */
74
+ static fromBytes(bytes: Uint8Array): SecretKey;
75
+ /** Parses a PEM string into a private key. */
76
+ static fromPem(pem: string): Promise<SecretKey>;
77
+ /** Converts a private key into a 32-byte seed. */
78
+ toBytes(): Uint8Array;
79
+ /** Serializes a private key into a PEM string. */
80
+ toPem(): Promise<string>;
81
+ /** Retrieves the public counterpart of the secret key. */
82
+ publicKey(): Promise<PublicKey>;
83
+ /** Returns a 256-bit unique identifier for this key (SHA256 of raw public key). */
84
+ fingerprint(): Promise<Fingerprint>;
85
+ /**
86
+ * Open (decrypt) a sealed message with this secret key.
87
+ *
88
+ * Deconstructs the encapsulated key and ciphertext, verifying the
89
+ * authenticity of the (unencrypted) message-to-auth.
90
+ *
91
+ * Note: X-Wing uses Base mode (no sender authentication). The sender's
92
+ * identity cannot be verified from the ciphertext alone.
93
+ *
94
+ * @param sealed - The sealed data from `seal()`
95
+ * @param msgToAuth - The same additional authenticated data used during sealing
96
+ * @param domain - The same application domain used during sealing
97
+ * @returns The decrypted message
98
+ * @throws If decryption fails (wrong key, tampered data, or wrong AAD/domain)
99
+ */
100
+ open(sealed: Uint8Array, msgToAuth: Uint8Array, domain: Uint8Array): Promise<Uint8Array>;
101
+ }
102
+ //# sourceMappingURL=xhpke.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xhpke.d.ts","sourceRoot":"","sources":["../src/xhpke.ts"],"names":[],"mappings":"AA+BA,iDAAiD;AACjD,eAAO,MAAM,eAAe,KAAK,CAAC;AAElC,8CAA8C;AAC9C,eAAO,MAAM,eAAe,OAAO,CAAC;AAEpC,oDAAoD;AACpD,eAAO,MAAM,cAAc,OAAO,CAAC;AAEnC,2CAA2C;AAC3C,eAAO,MA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AAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAMrD,kDAAkD;IAClD,OAAO,IAAI,UAAU;IAIrB,kDAAkD;IAC5C,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC;IAK9B,0DAA0D;IACpD,SAAS,IAAI,OAAO,CAAC,SAAS,CAAC;IAMrC,mFAAmF;IAC7E,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC;IAKzC;;;;;;;;;;;;;;OAcG;IACG,IAAI,CACR,MAAM,EAAE,UAAU,EAClB,SAAS,EAAE,UAAU,EACrB,MAAM,EAAE,UAAU,GACjB,OAAO,CAAC,UAAU,CAAC;CAIvB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@darkbio/crypto",
3
- "version": "0.1.1",
3
+ "version": "0.1.4",
4
4
  "author": "Péter Szilágyi <peter@dark.bio>",
5
5
  "description": "Cryptography primitives and wrappers",
6
6
  "repository": {
@@ -36,6 +36,7 @@
36
36
  "playwright": "^1.50.0",
37
37
  "typescript": "^5.7.0",
38
38
  "vite": "^6.0.0",
39
+ "vite-plugin-dts": "^4.5.4",
39
40
  "vitest": "^3.0.0"
40
41
  },
41
42
  "keywords": [