@darkbio/crypto 0.1.7 → 0.2.0

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/xdsa.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { XdsaSecretKey as WasmSecretKey, XdsaPublicKey as WasmPublicKey, XdsaSignature as WasmSignature, XdsaFingerprint as WasmFingerprint } from './wasm/darkbio_crypto_wasm.js';
1
2
  import { Params } from './x509.js';
2
3
  /** Size of the secret key in bytes (64). */
3
4
  export declare const SECRET_KEY_SIZE = 64;
@@ -18,46 +19,49 @@ export declare function sizes(): Promise<{
18
19
  }>;
19
20
  /**
20
21
  * Fingerprint is a 32-byte unique identifier for an xDSA key.
22
+ * Backed by an opaque WASM handle.
21
23
  */
22
24
  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;
25
+ /** @internal */
26
+ readonly _wasm: WasmFingerprint;
27
+ /** @internal */
28
+ constructor(inner: WasmFingerprint);
29
+ /** Creates a fingerprint from a 32-byte array. */
30
+ static fromBytes(bytes: Uint8Array): Promise<Fingerprint>;
27
31
  /** Converts a fingerprint into a 32-byte array. */
28
32
  toBytes(): Uint8Array;
29
33
  }
30
34
  /**
31
35
  * Signature is a 3373-byte xDSA signature.
32
- * Format: ML-DSA (3309 bytes) || Ed25519 (64 bytes)
36
+ * Backed by an opaque WASM handle.
33
37
  */
34
38
  export declare class Signature {
35
- private readonly bytes;
36
- private constructor();
37
- /** Converts a 3373-byte array into a signature. */
38
- static fromBytes(bytes: Uint8Array): Signature;
39
+ /** @internal */
40
+ readonly _wasm: WasmSignature;
41
+ /** @internal */
42
+ constructor(inner: WasmSignature);
43
+ /** Creates a signature from a 3373-byte array. */
44
+ static fromBytes(bytes: Uint8Array): Promise<Signature>;
39
45
  /** Converts a signature into a 3373-byte array. */
40
46
  toBytes(): Uint8Array;
41
47
  }
42
48
  /**
43
- * PublicKey is an ML-DSA-65 public key paired with an Ed25519 public key for
49
+ * PublicKey contains a composite ML-DSA-65 + Ed25519 public key for
44
50
  * verifying quantum resistant digital signatures.
45
- * Format: ML-DSA (1952 bytes) || Ed25519 (32 bytes)
51
+ * Backed by an opaque WASM handle — key material stays in WASM memory.
46
52
  */
47
53
  export declare class PublicKey {
48
- private readonly bytes;
49
- private constructor();
50
- /** Converts a 1984-byte array into a public key. */
51
- static fromBytes(bytes: Uint8Array): PublicKey;
54
+ /** @internal */
55
+ readonly _wasm: WasmPublicKey;
56
+ /** @internal */
57
+ constructor(inner: WasmPublicKey);
58
+ /** Creates a public key from a 1984-byte array. */
59
+ static fromBytes(bytes: Uint8Array): Promise<PublicKey>;
52
60
  /** Parses a PEM string into a public key. */
53
61
  static fromPem(pem: string): Promise<PublicKey>;
54
62
  /**
55
63
  * Parses a public key from a PEM-encoded X.509 certificate.
56
64
  * Verifies the certificate signature against the provided signer.
57
- *
58
- * @param pem - PEM-encoded X.509 certificate
59
- * @param signer - The xDSA public key that signed this certificate
60
- * @returns The parsed public key and validity period (notBefore, notAfter as Unix timestamps)
61
65
  */
62
66
  static fromCertPem(pem: string, signer: PublicKey): Promise<{
63
67
  key: PublicKey;
@@ -67,10 +71,6 @@ export declare class PublicKey {
67
71
  /**
68
72
  * Parses a public key from a DER-encoded X.509 certificate.
69
73
  * Verifies the certificate signature against the provided signer.
70
- *
71
- * @param der - DER-encoded X.509 certificate
72
- * @param signer - The xDSA public key that signed this certificate
73
- * @returns The parsed public key and validity period (notBefore, notAfter as Unix timestamps)
74
74
  */
75
75
  static fromCertDer(der: Uint8Array, signer: PublicKey): Promise<{
76
76
  key: PublicKey;
@@ -87,33 +87,27 @@ export declare class PublicKey {
87
87
  verify(message: Uint8Array, signature: Signature): Promise<boolean>;
88
88
  /**
89
89
  * Generates a PEM-encoded X.509 certificate for this public key.
90
- *
91
- * @param signer - The xDSA secret key to sign the certificate
92
- * @param params - Certificate parameters (subject, issuer, validity, etc.)
93
- * @returns PEM-encoded X.509 certificate
94
90
  */
95
91
  toCertPem(signer: SecretKey, params: Params): Promise<string>;
96
92
  /**
97
93
  * Generates a DER-encoded X.509 certificate for this public key.
98
- *
99
- * @param signer - The xDSA secret key to sign the certificate
100
- * @param params - Certificate parameters (subject, issuer, validity, etc.)
101
- * @returns DER-encoded X.509 certificate
102
94
  */
103
95
  toCertDer(signer: SecretKey, params: Params): Promise<Uint8Array>;
104
96
  }
105
97
  /**
106
- * SecretKey is an ML-DSA-65 private key paired with an Ed25519 private key for
98
+ * SecretKey contains a composite ML-DSA-65 + Ed25519 private key for
107
99
  * creating quantum resistant digital signatures.
108
- * Format: ML-DSA seed (32 bytes) || Ed25519 seed (32 bytes)
100
+ * Backed by an opaque WASM handle — key material stays in WASM memory.
109
101
  */
110
102
  export declare class SecretKey {
111
- private readonly bytes;
112
- private constructor();
103
+ /** @internal */
104
+ readonly _wasm: WasmSecretKey;
105
+ /** @internal */
106
+ constructor(inner: WasmSecretKey);
113
107
  /** Creates a new, random private key. */
114
108
  static generate(): Promise<SecretKey>;
115
109
  /** Creates a private key from a 64-byte seed. */
116
- static fromBytes(bytes: Uint8Array): SecretKey;
110
+ static fromBytes(bytes: Uint8Array): Promise<SecretKey>;
117
111
  /** Parses a PEM string into a private key. */
118
112
  static fromPem(pem: string): Promise<SecretKey>;
119
113
  /** Converts a secret key into a 64-byte array. */
@@ -1 +1 @@
1
- {"version":3,"file":"xdsa.d.ts","sourceRoot":"","sources":["../src/xdsa.ts"],"names":[],"mappings":"AA0BA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAWxC,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;AAE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AAU,GAAG,OAAO,CAAC,SAAS,CAAC;IAK7D,8CAA8C;WACjC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAKrD,kDAAkD;IAClD,OAAO,IAAI,UAAU;IAIrB,kDAAkD;IAC5C,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC;IAK9B,0DAA0D;IACpD,SAAS,IAAI,OAAO,CAAC,SAAS,CAAC;IAKrC,wDAAwD;IAClD,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC;IAKzC,kDAAkD;IAC5C,IAAI,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC;CAIpD"}
package/dist/xhpke.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { XhpkeSecretKey as WasmSecretKey, XhpkePublicKey as WasmPublicKey, XhpkeFingerprint as WasmFingerprint, XhpkeSender as WasmSender, XhpkeReceiver as WasmReceiver } from './wasm/darkbio_crypto_wasm.js';
1
2
  import { PublicKey as XdsaPublicKey, SecretKey as XdsaSecretKey } from './xdsa.js';
2
3
  import { Params } from './x509.js';
3
4
  /** Size of the secret key seed in bytes (32). */
@@ -19,39 +20,34 @@ export declare function sizes(): Promise<{
19
20
  }>;
20
21
  /**
21
22
  * Fingerprint is a 32-byte unique identifier for an xHPKE key.
22
- * It is the SHA256 hash of the raw public key.
23
+ * Backed by an opaque WASM handle.
23
24
  */
24
25
  export declare class Fingerprint {
25
- private readonly bytes;
26
- private constructor();
27
- /** Converts a 32-byte array into a fingerprint. */
28
- static fromBytes(bytes: Uint8Array): Fingerprint;
26
+ /** @internal */
27
+ readonly _wasm: WasmFingerprint;
28
+ /** @internal */
29
+ constructor(inner: WasmFingerprint);
30
+ /** Creates a fingerprint from a 32-byte array. */
31
+ static fromBytes(bytes: Uint8Array): Promise<Fingerprint>;
29
32
  /** Converts a fingerprint into a 32-byte array. */
30
33
  toBytes(): Uint8Array;
31
34
  }
32
35
  /**
33
36
  * PublicKey contains an X-Wing public key for hybrid post-quantum encryption.
34
- * Uses X-Wing KEM (ML-KEM-768 + X25519) with HPKE Base mode.
37
+ * Backed by an opaque WASM handle — key material stays in WASM memory.
35
38
  */
36
39
  export declare class PublicKey {
37
- private readonly bytes;
38
- private constructor();
39
- /**
40
- * Converts a 1216-byte array into a public key.
41
- *
42
- * This validates the ML-KEM-768 component by checking that all polynomial
43
- * coefficients are in the valid range [0, 3329).
44
- */
45
- static fromBytes(bytes: Uint8Array): PublicKey;
40
+ /** @internal */
41
+ readonly _wasm: WasmPublicKey;
42
+ /** @internal */
43
+ constructor(inner: WasmPublicKey);
44
+ /** Creates a public key from a 1216-byte array. */
45
+ static fromBytes(bytes: Uint8Array): Promise<PublicKey>;
46
46
  /** Parses a PEM string into a public key. */
47
47
  static fromPem(pem: string): Promise<PublicKey>;
48
48
  /**
49
49
  * Parses a public key from a PEM-encoded X.509 certificate.
50
50
  * Verifies the certificate signature against the provided xDSA signer.
51
- *
52
- * @param pem - PEM-encoded X.509 certificate
53
- * @param signer - The xDSA public key that signed this certificate
54
- * @returns The parsed public key and validity period (notBefore, notAfter as Unix timestamps)
55
51
  */
56
52
  static fromCertPem(pem: string, signer: XdsaPublicKey): Promise<{
57
53
  key: PublicKey;
@@ -61,10 +57,6 @@ export declare class PublicKey {
61
57
  /**
62
58
  * Parses a public key from a DER-encoded X.509 certificate.
63
59
  * Verifies the certificate signature against the provided xDSA signer.
64
- *
65
- * @param der - DER-encoded X.509 certificate
66
- * @param signer - The xDSA public key that signed this certificate
67
- * @returns The parsed public key and validity period (notBefore, notAfter as Unix timestamps)
68
60
  */
69
61
  static fromCertDer(der: Uint8Array, signer: XdsaPublicKey): Promise<{
70
62
  key: PublicKey;
@@ -77,11 +69,18 @@ export declare class PublicKey {
77
69
  toPem(): Promise<string>;
78
70
  /** Returns a 256-bit unique identifier for this key (SHA256 of raw public key). */
79
71
  fingerprint(): Promise<Fingerprint>;
72
+ /**
73
+ * Creates an HPKE sender context for multi-message encryption to this
74
+ * public key. Returns a stateful Sender and the 1120-byte encapsulated
75
+ * key that must be transmitted to the recipient.
76
+ */
77
+ newSender(domain: Uint8Array): Promise<{
78
+ sender: Sender;
79
+ encapKey: Uint8Array;
80
+ }>;
80
81
  /**
81
82
  * Seal (encrypt) a message to this public key.
82
83
  *
83
- * Uses X-Wing KEM (ML-KEM-768 + X25519) with HPKE Base mode.
84
- *
85
84
  * @param msgToSeal - The message to encrypt
86
85
  * @param msgToAuth - Additional data to authenticate (but not encrypt)
87
86
  * @param domain - Application domain for context separation
@@ -91,33 +90,27 @@ export declare class PublicKey {
91
90
  /**
92
91
  * Generates a PEM-encoded X.509 certificate for this public key.
93
92
  * Note: HPKE certificates are always end-entity certificates.
94
- *
95
- * @param signer - The xDSA secret key to sign the certificate
96
- * @param params - Certificate parameters (subject, issuer, validity)
97
- * @returns PEM-encoded X.509 certificate
98
93
  */
99
94
  toCertPem(signer: XdsaSecretKey, params: Params): Promise<string>;
100
95
  /**
101
96
  * Generates a DER-encoded X.509 certificate for this public key.
102
97
  * Note: HPKE certificates are always end-entity certificates.
103
- *
104
- * @param signer - The xDSA secret key to sign the certificate
105
- * @param params - Certificate parameters (subject, issuer, validity)
106
- * @returns DER-encoded X.509 certificate
107
98
  */
108
99
  toCertDer(signer: XdsaSecretKey, params: Params): Promise<Uint8Array>;
109
100
  }
110
101
  /**
111
102
  * SecretKey contains an X-Wing private key for hybrid post-quantum encryption.
112
- * Uses X-Wing KEM (ML-KEM-768 + X25519) with HPKE Base mode.
103
+ * Backed by an opaque WASM handle — key material stays in WASM memory.
113
104
  */
114
105
  export declare class SecretKey {
115
- private readonly bytes;
116
- private constructor();
106
+ /** @internal */
107
+ readonly _wasm: WasmSecretKey;
108
+ /** @internal */
109
+ constructor(inner: WasmSecretKey);
117
110
  /** Creates a new, random private key. */
118
111
  static generate(): Promise<SecretKey>;
119
- /** Converts a 32-byte seed into a private key. */
120
- static fromBytes(bytes: Uint8Array): SecretKey;
112
+ /** Creates a private key from a 32-byte seed. */
113
+ static fromBytes(bytes: Uint8Array): Promise<SecretKey>;
121
114
  /** Parses a PEM string into a private key. */
122
115
  static fromPem(pem: string): Promise<SecretKey>;
123
116
  /** Converts a private key into a 32-byte seed. */
@@ -128,21 +121,40 @@ export declare class SecretKey {
128
121
  publicKey(): Promise<PublicKey>;
129
122
  /** Returns a 256-bit unique identifier for this key (SHA256 of raw public key). */
130
123
  fingerprint(): Promise<Fingerprint>;
124
+ /**
125
+ * Creates an HPKE receiver context for multi-message decryption.
126
+ */
127
+ newReceiver(encapKey: Uint8Array, domain: Uint8Array): Promise<Receiver>;
131
128
  /**
132
129
  * Open (decrypt) a sealed message with this secret key.
133
130
  *
134
- * Deconstructs the encapsulated key and ciphertext, verifying the
135
- * authenticity of the (unencrypted) message-to-auth.
136
- *
137
- * Note: X-Wing uses Base mode (no sender authentication). The sender's
138
- * identity cannot be verified from the ciphertext alone.
139
- *
140
131
  * @param sealed - The sealed data from `seal()`
141
132
  * @param msgToAuth - The same additional authenticated data used during sealing
142
133
  * @param domain - The same application domain used during sealing
143
134
  * @returns The decrypted message
144
- * @throws If decryption fails (wrong key, tampered data, or wrong AAD/domain)
145
135
  */
146
136
  open(sealed: Uint8Array, msgToAuth: Uint8Array, domain: Uint8Array): Promise<Uint8Array>;
147
137
  }
138
+ /**
139
+ * Sender is a stateful HPKE encryption context for multi-message
140
+ * communication. Created via `PublicKey.newSender()`.
141
+ */
142
+ export declare class Sender {
143
+ private readonly inner;
144
+ /** @internal */
145
+ constructor(inner: WasmSender);
146
+ /** Encrypts a message using the next nonce in the sequence. */
147
+ seal(msgToSeal: Uint8Array, msgToAuth: Uint8Array): Promise<Uint8Array>;
148
+ }
149
+ /**
150
+ * Receiver is a stateful HPKE decryption context for multi-message
151
+ * communication. Created via `SecretKey.newReceiver()`.
152
+ */
153
+ export declare class Receiver {
154
+ private readonly inner;
155
+ /** @internal */
156
+ constructor(inner: WasmReceiver);
157
+ /** Decrypts a message using the next nonce in the sequence. */
158
+ open(msgToOpen: Uint8Array, msgToAuth: Uint8Array): Promise<Uint8Array>;
159
+ }
148
160
  //# sourceMappingURL=xhpke.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"xhpke.d.ts","sourceRoot":"","sources":["../src/xhpke.ts"],"names":[],"mappings":"AA0BA,OAAO,EACL,SAAS,IAAI,aAAa,EAC1B,SAAS,IAAI,aAAa,EAC3B,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAWxC,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,MAAM,gBAAgB,KAAK,CAAC;AAEnC;;GAEG;AACH,wBAAsB,KAAK,IAAI,OAAO,CAAC;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC,CAQD;AAED;;;GAGG;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;;;;;OAKG;IACH,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS;IAO9C,6CAA6C;WAChC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAMrD;;;;;;;OAOG;WACU,WAAW,CACtB,GAAG,EAAE,MAAM,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C;CAIvB;AAED;;;GAGG;AACH,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAe;IAErC,gBAAgB;gBACJ,KAAK,EAAE,YAAY;IAI/B,+DAA+D;IACzD,IAAI,CACR,SAAS,EAAE,UAAU,EACrB,SAAS,EAAE,UAAU,GACpB,OAAO,CAAC,UAAU,CAAC;CAIvB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@darkbio/crypto",
3
- "version": "0.1.7",
3
+ "version": "0.2.0",
4
4
  "author": "Péter Szilágyi <peter@dark.bio>",
5
5
  "description": "Cryptography primitives and wrappers",
6
6
  "repository": {