@hpke/hybridkem-x-wing 0.1.0 → 0.4.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/README.md CHANGED
@@ -22,57 +22,46 @@ Documentation: [jsr.io](https://jsr.io/@hpke/hybridkem-x-wing/doc) |
22
22
  - [Node.js](#nodejs)
23
23
  - [Deno](#deno)
24
24
  - [Web Browsers](#web-browsers)
25
- - [Cloudflare Workers](#cloudflare-workers)
26
25
  - [Usage](#usage)
27
26
  - [Contributing](#contributing)
28
27
 
29
28
  ## Installation
30
29
 
30
+ `@hpke/hybridkem-x-wing` needs to be used with
31
+ [@hpke/core](https://github.com/dajiaji/hpke-js/blob/main/packages/core/README.md),
32
+ which can be installed in the same manner as desribed below.
33
+
31
34
  ### Node.js
32
35
 
33
- Using npm:
36
+ You can install the package with npm, yarn or pnpm.
34
37
 
35
38
  ```sh
39
+ # Using npm:
36
40
  npm install @hpke/hybridkem-x-wing
37
- ```
38
-
39
- Using yarn:
40
-
41
- ```sh
42
41
  yarn add @hpke/hybridkem-x-wing
42
+ pnpm install @hpke/hybridkem-x-wing
43
+ # Using jsr:
44
+ npx jsr add @hpke/hybridkem-x-wing
45
+ yarn dlx jsr add @hpke/hybridkem-x-wing
46
+ pnpm dlx jsr add @@hpke/hybridkem-x-wing
43
47
  ```
44
48
 
45
- ### Deno
46
-
47
- Starting from version 1.3.0, hpke-js packages are available from the JSR
48
- registry. From this version onwards, please use JSR import instead of HTTPS
49
- import in Deno.
50
-
51
- **JSR imoprt (recommended on `>=1.3.0`):**
52
-
53
- Add hpke-js packages using the commands below:
54
-
55
- ```sh
56
- deno add @hpke/core
57
- deno add @hpke/hybridkem-x-wing
58
- ```
49
+ The above manner can be used with other JavaScript runtimes that support npm,
50
+ such as Cloudflare Workers and Bun.
59
51
 
60
52
  Then, you can use the module from code like this:
61
53
 
62
54
  ```ts
63
- import { Aes128Gcm, CipherSuite, HkdfSha256 } from "@hpke/core";
64
- import { HybridkemXWing } from "@hpke/hybridkem-x-wing";
55
+ import { Aes256Gcm, CipherSuite, HkdfSha256 } from "@hpke/core";
56
+ import { XWing } from "@hpke/hybridkem-x-wing";
65
57
  ```
66
58
 
67
- **HTTPS imoprt (deprecated):**
59
+ ### Deno
68
60
 
69
- ```ts
70
- import {
71
- Aes128Gcm,
72
- CipherSuite,
73
- HkdfSha256,
74
- } from "https://deno.land/x/hpke/core/mod.ts";
75
- import { HybridkemXWing } from "https://deno.land/x/hpke/x/hybridkem-x-wing/mod.ts";
61
+ For Deno, it is recommended to use the jsr.io registry.
62
+
63
+ ```sh
64
+ deno add jsr:@hpke/hybridkem-x-wing
76
65
  ```
77
66
 
78
67
  ### Web Browsers
@@ -85,15 +74,23 @@ Using esm.sh:
85
74
  ```html
86
75
  <!-- use a specific version -->
87
76
  <script type="module">
88
- import * as hpke from "https://esm.sh/@hpke/core@<SEMVER>";
89
- import * as kyber from "https://esm.sh/@hpke/hybridkem-x-wing@<SEMVER>";
77
+ import {
78
+ Aes256Gcm,
79
+ CipherSuite,
80
+ HkdfSha256,
81
+ } from "https://esm.sh/@hpke/core@<SEMVER>";
82
+ import { XWing } from "https://esm.sh/@hpke/hybridkem-x-wing@<SEMVER>";
90
83
  // ...
91
84
  </script>
92
85
 
93
86
  <!-- use the latest stable version -->
94
87
  <script type="module">
95
- import * as hpke from "https://esm.sh/@hpke/core";
96
- import * as kyber from "https://esm.sh/@hpke/hybridkem-x-wing";
88
+ import {
89
+ Aes256Gcm,
90
+ CipherSuite,
91
+ HkdfSha256,
92
+ } from "https://esm.sh/@hpke/core";
93
+ import { XWing } from "https://esm.sh/@hpke/hybridkem-x-wing";
97
94
  // ...
98
95
  </script>
99
96
  ```
@@ -103,22 +100,16 @@ Using unpkg:
103
100
  ```html
104
101
  <!-- use a specific version -->
105
102
  <script type="module">
106
- import * as hpke from "https://unpkg.com/@hpke/core@<SEMVER>/esm/mod.js";
107
- import * as kyber from "https://unpkg.com/@hpke/hybridkem-x-wing@<SEMVER>/esm/mod.js";
103
+ import {
104
+ Aes256Gcm,
105
+ CipherSuite,
106
+ HkdfSha256,
107
+ } from "https://unpkg.com/@hpke/core@<SEMVER>/esm/mod.js";
108
+ import { XWing } from "https://unpkg.com/@hpke/hybridkem-x-wing@<SEMVER>/esm/mod.js";
108
109
  // ...
109
110
  </script>
110
111
  ```
111
112
 
112
- ### Cloudflare Workers
113
-
114
- ```sh
115
- git clone git@github.com:dajiaji/hpke-js.git
116
- cd hpke-js/x/hybridkem-x-wing
117
- npm install -g esbuild
118
- deno task dnt
119
- deno task minify > $YOUR_SRC_PATH/hpke-hybridkem-x-wing.js
120
- ```
121
-
122
113
  ## Usage
123
114
 
124
115
  This section shows some typical usage examples.
@@ -126,34 +117,34 @@ This section shows some typical usage examples.
126
117
  ### Node.js
127
118
 
128
119
  ```js
129
- import { Aes128Gcm, CipherSuite, HkdfSha256 } from "@hpke/core";
130
- import { HybridkemXWing } from "@hpke/hybridkem-x-wing";
131
- // const { HybridkemXWing } = require("@hpke/hybridkem-x-wing");
120
+ import { Aes256Gcm, CipherSuite, HkdfSha256 } from "@hpke/core";
121
+ import { XWing } from "@hpke/hybridkem-x-wing";
132
122
 
133
123
  async function doHpke() {
134
124
  // setup
135
125
  const suite = new CipherSuite({
136
- kem: new HybridkemXWing(),
126
+ kem: new XWing(),
137
127
  kdf: new HkdfSha256(),
138
- aead: new Aes128Gcm(),
128
+ aead: new Aes256Gcm(),
139
129
  });
140
130
 
141
131
  const rkp = await suite.kem.generateKeyPair();
142
132
 
133
+ // Note that the `ct` (ciphertext) resulting from X-Wing Encapsulate() is set to `sender.enc`.
143
134
  const sender = await suite.createSenderContext({
144
135
  recipientPublicKey: rkp.publicKey,
145
136
  });
146
137
 
147
138
  // encrypt
148
- const ct = await sender.seal(new TextEncoder().encode("Hello world!"));
139
+ const encrypted = await sender.seal(new TextEncoder().encode("Hello world!"));
149
140
 
150
141
  const recipient = await suite.createRecipientContext({
151
142
  recipientKey: rkp.privateKey,
152
- enc: sender.enc,
143
+ enc: sender.enc, // == `ct` (ciphertext) in the context of X-Wing
153
144
  });
154
145
 
155
146
  // decrypt
156
- const pt = await recipient.open(ct);
147
+ const pt = await recipient.open(encrypted);
157
148
 
158
149
  // Hello world!
159
150
  console.log(new TextDecoder().decode(pt));
@@ -169,33 +160,34 @@ try {
169
160
  ### Deno
170
161
 
171
162
  ```ts
172
- import { Aes128Gcm, CipherSuite, HkdfSha256 } from "@hpke/core";
173
- import { HybridkemXWing } from "@hpke/hybridkem-x-wing";
163
+ import { Aes256Gcm, CipherSuite, HkdfSha256 } from "@hpke/core";
164
+ import { XWing } from "@hpke/hybridkem-x-wing";
174
165
 
175
166
  async function doHpke() {
176
167
  // setup
177
168
  const suite = new CipherSuite({
178
- kem: new HybridkemXWing(),
169
+ kem: new XWing(),
179
170
  kdf: new HkdfSha256(),
180
- aead: new Aes128Gcm(),
171
+ aead: new Aes256Gcm(),
181
172
  });
182
173
 
183
174
  const rkp = await suite.kem.generateKeyPair();
184
175
 
176
+ // Note that the `ct` (ciphertext) resulting from X-Wing::Encapsulate() is set to `sender.enc`.
185
177
  const sender = await suite.createSenderContext({
186
178
  recipientPublicKey: rkp.publicKey,
187
179
  });
188
180
 
189
181
  // encrypt
190
- const ct = await sender.seal(new TextEncoder().encode("Hello world!"));
182
+ const encrypted = await sender.seal(new TextEncoder().encode("Hello world!"));
191
183
 
192
184
  const recipient = await suite.createRecipientContext({
193
185
  recipientKey: rkp.privateKey,
194
- enc: sender.enc,
186
+ enc: sender.enc, // == `ct` (ciphertext) in the context of X-Wing
195
187
  });
196
188
 
197
189
  // decrypt
198
- const pt = await recipient.open(ct);
190
+ const pt = await recipient.open(encrypted);
199
191
 
200
192
  // Hello world!
201
193
  console.log(new TextDecoder().decode(pt));
@@ -208,7 +200,7 @@ try {
208
200
  }
209
201
  ```
210
202
 
211
- ### Browsers
203
+ ### Web Browsers
212
204
 
213
205
  ```html
214
206
  <html>
@@ -216,35 +208,38 @@ try {
216
208
  <body>
217
209
  <script type="module">
218
210
  import {
219
- Aes128Gcm,
211
+ Aes256Gcm,
220
212
  CipherSuite,
221
213
  HkdfSha256,
222
- } from "https://esm.sh/@hpke/core@<SEMVER>";
223
- import { HybridkemXWing } from "https://esm.sh/@hpke/hybridkem-x-wing@<SEMVER>";
214
+ } from "https://esm.sh/@hpke/core";
215
+ import { XWing } from "https://esm.sh/@hpke/hybridkem-x-wing";
224
216
 
225
217
  globalThis.doHpke = async () => {
226
218
  try {
227
219
  const suite = new CipherSuite({
228
- kem: new HybridkemXWing(),
220
+ kem: new XWing(),
229
221
  kdf: new HkdfSha256(),
230
- aead: new Aes128Gcm(),
222
+ aead: new Aes256Gcm(),
231
223
  });
232
224
 
233
225
  const rkp = await suite.kem.generateKeyPair();
234
226
 
227
+ // Note that the `ct` resulting from X-Wing::Encapsulate() is set to `sender.enc`.
235
228
  const sender = await suite.createSenderContext({
236
229
  recipientPublicKey: rkp.publicKey,
237
230
  });
238
231
  // encrypt
239
- const ct = await sender.seal(new TextEncoder().encode("Hello world!"));
232
+ const encrypted = await sender.seal(
233
+ new TextEncoder().encode("Hello world!"),
234
+ );
240
235
 
241
236
  const recipient = await suite.createRecipientContext({
242
237
  recipientKey: rkp.privateKey, // rkp (CryptoKeyPair) is also acceptable.
243
- enc: sender.enc,
238
+ enc: sender.enc, // == `ct` (ciphertext) in the context of X-Wing
244
239
  });
245
240
 
246
241
  // decrypt
247
- const pt = await recipient.open(ct);
242
+ const pt = await recipient.open(encrypted);
248
243
 
249
244
  // Hello world!
250
245
  alert(new TextDecoder().decode(pt));
package/esm/mod.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { HybridkemXWing } from "./src/hybridkemXWing.js";
1
+ export { XWing } from "./src/xWing.js";
2
2
  //# sourceMappingURL=mod.d.ts.map
package/esm/mod.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC"}
package/esm/mod.js CHANGED
@@ -1 +1 @@
1
- export { HybridkemXWing } from "./src/hybridkemXWing.js";
1
+ export { XWing } from "./src/xWing.js";
@@ -15,15 +15,15 @@ import { X25519 } from "@hpke/dhkem-x25519";
15
15
  *
16
16
  * ```ts
17
17
  * import { Aes128Gcm, CipherSuite, HkdfSha256 } from "@hpke/core";
18
- * import { HybridkemXWing } from "@hpke/hybridkem-x-wing";
18
+ * import { XWing } from "@hpke/hybridkem-x-wing";
19
19
  * const suite = new CipherSuite({
20
- * kem: new HybridkemXWing(),
20
+ * kem: new XWing(),
21
21
  * kdf: new HkdfSha256(),
22
22
  * aead: new Aes128Gcm(),
23
23
  * });
24
24
  * ```
25
25
  */
26
- export declare class HybridkemXWing implements KemInterface {
26
+ export declare class XWing implements KemInterface {
27
27
  readonly id: KemId;
28
28
  readonly name: string;
29
29
  readonly secretSize: number;
@@ -63,10 +63,26 @@ export declare class HybridkemXWing implements KemInterface {
63
63
  */
64
64
  deriveKeyPair(ikm: ArrayBuffer): Promise<CryptoKeyPair>;
65
65
  importKey(_format: "raw" | "jwk", _key: ArrayBuffer | JsonWebKey, _isPublic?: boolean): Promise<CryptoKey>;
66
+ /**
67
+ * Encapsulates the shared secret and the `ct` (ciphertext) as `enc`.
68
+ * @param params The parameters for encapsulation.
69
+ * @returns {Promise<{ sharedSecret: ArrayBuffer; enc: ArrayBuffer }>} A promise that resolves with the `ss` (shared secret) as `sharedSecret` and the `ct` (ciphertext) as `enc`.
70
+ * @throws {InvalidParamError} Thrown if the length of the `ekm` is not 64 bytes.
71
+ * @throws {EncapError} Thrown if the shared secret cannot be encapsulated.
72
+ */
66
73
  encap(params: SenderContextParams): Promise<{
67
74
  sharedSecret: ArrayBuffer;
68
75
  enc: ArrayBuffer;
69
76
  }>;
77
+ /**
78
+ * Decapsulates the `ss` (shared secret) from the `enc` and the recipient's private key.
79
+ * The `enc` is the same as the `ct` (ciphertext) resulting from `X-Wing::Encapsulate(),
80
+ * which is executed under the `encap()`.
81
+ * @param params The parameters for decapsulation.
82
+ * @returns {Promise<ArrayBuffer>} A promise that resolves with the shared secret.
83
+ * @throws {InvalidParamError} Thrown if the length of the `enc` is not 1120 bytes.
84
+ * @throws {DecapError} Thrown if the shared secret cannot be decapsulated.
85
+ */
70
86
  decap(params: RecipientContextParams): Promise<ArrayBuffer>;
71
87
  /**
72
88
  * Sets up the MlKemBase instance by loading the necessary crypto library.
@@ -91,4 +107,4 @@ export declare class HybridkemXWing implements KemInterface {
91
107
  private _serializePrivateKey;
92
108
  private _deserializePrivateKey;
93
109
  }
94
- //# sourceMappingURL=hybridkemXWing.d.ts.map
110
+ //# sourceMappingURL=xWing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xWing.d.ts","sourceRoot":"","sources":["../../src/src/xWing.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEjC,OAAO,KAAK,EACV,YAAY,EACZ,sBAAsB,EACtB,mBAAmB,EACpB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAQL,KAAK,EAKN,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAc,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAwCxD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,KAAM,YAAW,YAAY;IACxC,SAAgB,EAAE,EAAE,KAAK,CAAe;IACxC,SAAgB,IAAI,EAAE,MAAM,CAAY;IACxC,SAAgB,UAAU,EAAE,MAAM,CAAM;IACxC,SAAgB,OAAO,EAAE,MAAM,CAAQ;IACvC,SAAgB,aAAa,EAAE,MAAM,CAAQ;IAC7C,SAAgB,cAAc,EAAE,MAAM,CAAM;IAC5C,SAAgB,IAAI,EA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15,7 @@ const X25519_BASE = new Uint8Array([
15
15
  // "/^\",
16
16
  // );
17
17
  // deno-fmt-ignore
18
- const XWING_LABEL = new Uint8Array([46, 47, 47, 94, 92]);
18
+ const XWING_LABEL = new Uint8Array([92, 46, 47, 47, 94, 92]);
19
19
  function emitNotSupported() {
20
20
  return new Promise((_resolve, reject) => {
21
21
  reject(new NotSupportedError("Not supported"));
@@ -43,21 +43,21 @@ function combiner(ssM, ssX, ctX, pkX) {
43
43
  *
44
44
  * ```ts
45
45
  * import { Aes128Gcm, CipherSuite, HkdfSha256 } from "@hpke/core";
46
- * import { HybridkemXWing } from "@hpke/hybridkem-x-wing";
46
+ * import { XWing } from "@hpke/hybridkem-x-wing";
47
47
  * const suite = new CipherSuite({
48
- * kem: new HybridkemXWing(),
48
+ * kem: new XWing(),
49
49
  * kdf: new HkdfSha256(),
50
50
  * aead: new Aes128Gcm(),
51
51
  * });
52
52
  * ```
53
53
  */
54
- export class HybridkemXWing {
54
+ export class XWing {
55
55
  constructor() {
56
56
  Object.defineProperty(this, "id", {
57
57
  enumerable: true,
58
58
  configurable: true,
59
59
  writable: true,
60
- value: KemId.HybridkemXWing
60
+ value: KemId.XWing
61
61
  });
62
62
  Object.defineProperty(this, "name", {
63
63
  enumerable: true,
@@ -233,6 +233,13 @@ export class HybridkemXWing {
233
233
  // }
234
234
  // return await this.deserializePrivateKey(key as ArrayBuffer);
235
235
  }
236
+ /**
237
+ * Encapsulates the shared secret and the `ct` (ciphertext) as `enc`.
238
+ * @param params The parameters for encapsulation.
239
+ * @returns {Promise<{ sharedSecret: ArrayBuffer; enc: ArrayBuffer }>} A promise that resolves with the `ss` (shared secret) as `sharedSecret` and the `ct` (ciphertext) as `enc`.
240
+ * @throws {InvalidParamError} Thrown if the length of the `ekm` is not 64 bytes.
241
+ * @throws {EncapError} Thrown if the shared secret cannot be encapsulated.
242
+ */
236
243
  async encap(params) {
237
244
  let ekm = undefined;
238
245
  if (params.ekm !== undefined && !isCryptoKeyPair(params.ekm)) {
@@ -277,6 +284,15 @@ export class HybridkemXWing {
277
284
  throw new EncapError(e);
278
285
  }
279
286
  }
287
+ /**
288
+ * Decapsulates the `ss` (shared secret) from the `enc` and the recipient's private key.
289
+ * The `enc` is the same as the `ct` (ciphertext) resulting from `X-Wing::Encapsulate(),
290
+ * which is executed under the `encap()`.
291
+ * @param params The parameters for decapsulation.
292
+ * @returns {Promise<ArrayBuffer>} A promise that resolves with the shared secret.
293
+ * @throws {InvalidParamError} Thrown if the length of the `enc` is not 1120 bytes.
294
+ * @throws {DecapError} Thrown if the shared secret cannot be decapsulated.
295
+ */
280
296
  async decap(params) {
281
297
  const rSk = isCryptoKeyPair(params.recipientKey)
282
298
  ? params.recipientKey.privateKey
@@ -1 +1 @@
1
- {"version":3,"file":"testVectors.d.ts","sourceRoot":"","sources":["../../src/test/testVectors.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,UAAU,CAY1C,CAAC"}
1
+ {"version":3,"file":"testVectors.d.ts","sourceRoot":"","sources":["../../src/test/testVectors.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,UAAU,CAkC1C,CAAC"}
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "@hpke/hybridkem-x-wing",
3
- "version": "0.1.0",
4
- "description": "A Hybrid Public Key Encryption (HPKE) module extension for a hybrid post-quantum KEM, X25519Kyber768Draft00",
3
+ "version": "0.4.0",
4
+ "description": "A Hybrid Public Key Encryption (HPKE) module extension for X-Wing: general-purpose hybrid post-quantum KEM.",
5
5
  "keywords": [
6
6
  "hpke",
7
- "rfc9180",
8
- "kem",
7
+ "ml-kem",
9
8
  "kyber",
10
9
  "x25519",
11
10
  "post-quantum",
11
+ "pqc",
12
+ "x-wing",
12
13
  "security",
13
14
  "encryption"
14
15
  ],
@@ -40,15 +41,15 @@
40
41
  "node": ">=16.0.0"
41
42
  },
42
43
  "dependencies": {
43
- "@hpke/common": "^1.4.3",
44
- "@hpke/dhkem-x25519": "^1.4.3",
45
- "@noble/hashes": "^1.4.0",
46
- "mlkem": "^2.2.0"
44
+ "@hpke/common": "^1.6.1",
45
+ "@hpke/dhkem-x25519": "^1.6.0",
46
+ "@noble/hashes": "^1.5.0",
47
+ "mlkem": "^2.3.0"
47
48
  },
48
49
  "devDependencies": {
49
50
  "@types/node": "^20.9.0",
50
51
  "picocolors": "^1.0.0",
51
- "@hpke/core": "^1.4.3",
52
+ "@hpke/core": "^1.6.0",
52
53
  "@deno/shim-deno": "~0.18.0"
53
54
  },
54
55
  "_generatedBy": "dnt@dev"
package/script/mod.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { HybridkemXWing } from "./src/hybridkemXWing.js";
1
+ export { XWing } from "./src/xWing.js";
2
2
  //# sourceMappingURL=mod.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC"}
package/script/mod.js CHANGED
@@ -4,12 +4,12 @@
4
4
  if (v !== undefined) module.exports = v;
5
5
  }
6
6
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "./src/hybridkemXWing.js"], factory);
7
+ define(["require", "exports", "./src/xWing.js"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.HybridkemXWing = void 0;
13
- var hybridkemXWing_js_1 = require("./src/hybridkemXWing.js");
14
- Object.defineProperty(exports, "HybridkemXWing", { enumerable: true, get: function () { return hybridkemXWing_js_1.HybridkemXWing; } });
12
+ exports.XWing = void 0;
13
+ var xWing_js_1 = require("./src/xWing.js");
14
+ Object.defineProperty(exports, "XWing", { enumerable: true, get: function () { return xWing_js_1.XWing; } });
15
15
  });
@@ -15,15 +15,15 @@ import { X25519 } from "@hpke/dhkem-x25519";
15
15
  *
16
16
  * ```ts
17
17
  * import { Aes128Gcm, CipherSuite, HkdfSha256 } from "@hpke/core";
18
- * import { HybridkemXWing } from "@hpke/hybridkem-x-wing";
18
+ * import { XWing } from "@hpke/hybridkem-x-wing";
19
19
  * const suite = new CipherSuite({
20
- * kem: new HybridkemXWing(),
20
+ * kem: new XWing(),
21
21
  * kdf: new HkdfSha256(),
22
22
  * aead: new Aes128Gcm(),
23
23
  * });
24
24
  * ```
25
25
  */
26
- export declare class HybridkemXWing implements KemInterface {
26
+ export declare class XWing implements KemInterface {
27
27
  readonly id: KemId;
28
28
  readonly name: string;
29
29
  readonly secretSize: number;
@@ -63,10 +63,26 @@ export declare class HybridkemXWing implements KemInterface {
63
63
  */
64
64
  deriveKeyPair(ikm: ArrayBuffer): Promise<CryptoKeyPair>;
65
65
  importKey(_format: "raw" | "jwk", _key: ArrayBuffer | JsonWebKey, _isPublic?: boolean): Promise<CryptoKey>;
66
+ /**
67
+ * Encapsulates the shared secret and the `ct` (ciphertext) as `enc`.
68
+ * @param params The parameters for encapsulation.
69
+ * @returns {Promise<{ sharedSecret: ArrayBuffer; enc: ArrayBuffer }>} A promise that resolves with the `ss` (shared secret) as `sharedSecret` and the `ct` (ciphertext) as `enc`.
70
+ * @throws {InvalidParamError} Thrown if the length of the `ekm` is not 64 bytes.
71
+ * @throws {EncapError} Thrown if the shared secret cannot be encapsulated.
72
+ */
66
73
  encap(params: SenderContextParams): Promise<{
67
74
  sharedSecret: ArrayBuffer;
68
75
  enc: ArrayBuffer;
69
76
  }>;
77
+ /**
78
+ * Decapsulates the `ss` (shared secret) from the `enc` and the recipient's private key.
79
+ * The `enc` is the same as the `ct` (ciphertext) resulting from `X-Wing::Encapsulate(),
80
+ * which is executed under the `encap()`.
81
+ * @param params The parameters for decapsulation.
82
+ * @returns {Promise<ArrayBuffer>} A promise that resolves with the shared secret.
83
+ * @throws {InvalidParamError} Thrown if the length of the `enc` is not 1120 bytes.
84
+ * @throws {DecapError} Thrown if the shared secret cannot be decapsulated.
85
+ */
70
86
  decap(params: RecipientContextParams): Promise<ArrayBuffer>;
71
87
  /**
72
88
  * Sets up the MlKemBase instance by loading the necessary crypto library.
@@ -91,4 +107,4 @@ export declare class HybridkemXWing implements KemInterface {
91
107
  private _serializePrivateKey;
92
108
  private _deserializePrivateKey;
93
109
  }
94
- //# sourceMappingURL=hybridkemXWing.d.ts.map
110
+ //# sourceMappingURL=xWing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xWing.d.ts","sourceRoot":"","sources":["../../src/src/xWing.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEjC,OAAO,KAAK,EACV,YAAY,EACZ,sBAAsB,EACtB,mBAAmB,EACpB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAQL,KAAK,EAKN,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAc,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAwCxD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,KAAM,YAAW,YAAY;IACxC,SAAgB,EAAE,EAAE,KAAK,CAAe;IACxC,SAA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;YACW,MAAM;IAOpB;;;;OAIG;YACW,sBAAsB;IAOpC;;;;OAIG;YACW,uBAAuB;IAUrC,OAAO,CAAC,mBAAmB;IAe3B,OAAO,CAAC,qBAAqB;IAS7B,OAAO,CAAC,oBAAoB;IAe5B,OAAO,CAAC,sBAAsB;CAU/B"}
@@ -9,7 +9,7 @@
9
9
  })(function (require, exports) {
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.HybridkemXWing = void 0;
12
+ exports.XWing = void 0;
13
13
  const sha3_1 = require("@noble/hashes/sha3");
14
14
  // @ts-ignore: Unreachable code error
15
15
  const mlkem_1 = require("mlkem");
@@ -27,7 +27,7 @@
27
27
  // "/^\",
28
28
  // );
29
29
  // deno-fmt-ignore
30
- const XWING_LABEL = new Uint8Array([46, 47, 47, 94, 92]);
30
+ const XWING_LABEL = new Uint8Array([92, 46, 47, 47, 94, 92]);
31
31
  function emitNotSupported() {
32
32
  return new Promise((_resolve, reject) => {
33
33
  reject(new common_1.NotSupportedError("Not supported"));
@@ -55,21 +55,21 @@
55
55
  *
56
56
  * ```ts
57
57
  * import { Aes128Gcm, CipherSuite, HkdfSha256 } from "@hpke/core";
58
- * import { HybridkemXWing } from "@hpke/hybridkem-x-wing";
58
+ * import { XWing } from "@hpke/hybridkem-x-wing";
59
59
  * const suite = new CipherSuite({
60
- * kem: new HybridkemXWing(),
60
+ * kem: new XWing(),
61
61
  * kdf: new HkdfSha256(),
62
62
  * aead: new Aes128Gcm(),
63
63
  * });
64
64
  * ```
65
65
  */
66
- class HybridkemXWing {
66
+ class XWing {
67
67
  constructor() {
68
68
  Object.defineProperty(this, "id", {
69
69
  enumerable: true,
70
70
  configurable: true,
71
71
  writable: true,
72
- value: common_1.KemId.HybridkemXWing
72
+ value: common_1.KemId.XWing
73
73
  });
74
74
  Object.defineProperty(this, "name", {
75
75
  enumerable: true,
@@ -245,6 +245,13 @@
245
245
  // }
246
246
  // return await this.deserializePrivateKey(key as ArrayBuffer);
247
247
  }
248
+ /**
249
+ * Encapsulates the shared secret and the `ct` (ciphertext) as `enc`.
250
+ * @param params The parameters for encapsulation.
251
+ * @returns {Promise<{ sharedSecret: ArrayBuffer; enc: ArrayBuffer }>} A promise that resolves with the `ss` (shared secret) as `sharedSecret` and the `ct` (ciphertext) as `enc`.
252
+ * @throws {InvalidParamError} Thrown if the length of the `ekm` is not 64 bytes.
253
+ * @throws {EncapError} Thrown if the shared secret cannot be encapsulated.
254
+ */
248
255
  async encap(params) {
249
256
  let ekm = undefined;
250
257
  if (params.ekm !== undefined && !(0, common_1.isCryptoKeyPair)(params.ekm)) {
@@ -289,6 +296,15 @@
289
296
  throw new common_1.EncapError(e);
290
297
  }
291
298
  }
299
+ /**
300
+ * Decapsulates the `ss` (shared secret) from the `enc` and the recipient's private key.
301
+ * The `enc` is the same as the `ct` (ciphertext) resulting from `X-Wing::Encapsulate(),
302
+ * which is executed under the `encap()`.
303
+ * @param params The parameters for decapsulation.
304
+ * @returns {Promise<ArrayBuffer>} A promise that resolves with the shared secret.
305
+ * @throws {InvalidParamError} Thrown if the length of the `enc` is not 1120 bytes.
306
+ * @throws {DecapError} Thrown if the shared secret cannot be decapsulated.
307
+ */
292
308
  async decap(params) {
293
309
  const rSk = (0, common_1.isCryptoKeyPair)(params.recipientKey)
294
310
  ? params.recipientKey.privateKey
@@ -391,5 +407,5 @@
391
407
  });
392
408
  }
393
409
  }
394
- exports.HybridkemXWing = HybridkemXWing;
410
+ exports.XWing = XWing;
395
411
  });
@@ -1 +1 @@
1
- {"version":3,"file":"testVectors.d.ts","sourceRoot":"","sources":["../../src/test/testVectors.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,UAAU,CAY1C,CAAC"}
1
+ {"version":3,"file":"testVectors.d.ts","sourceRoot":"","sources":["../../src/test/testVectors.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,UAAU,CAkC1C,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"hybridkemXWing.d.ts","sourceRoot":"","sources":["../../src/src/hybridkemXWing.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEjC,OAAO,KAAK,EACV,YAAY,EACZ,sBAAsB,EACtB,mBAAmB,EACpB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAQL,KAAK,EAKN,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAc,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAwCxD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,cAAe,YAAW,YAAY;IACjD,SAAgB,EAAE,EAAE,KAAK,CAAwB;IACjD,SAAgB,IAAI,EAAE,MAAM,CAAY;IACxC,SAAgB,UAAU,EAAE,MAAM,CAAM;IACxC,SAAgB,OAAO,EAAE,MAAM,CAAQ;IACvC,SAAgB,aAAa,EAAE,MAAM,CAAQ;IAC7C,SAAgB,cAAc,EAAE,MAAM,CAAM;IAC5C,SAAgB,IAAI,EAAE,OAAO,CAAS;IACtC,SAAS,CAAC,EAAE,EAAE,QAAQ,CAAC;IACvB,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC;IAC1B,OAAO,CAAC,IAAI,CAAiC;;IAOhC,kBAAkB,CAAC,GAAG,EAAE,SAAS,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