@reallyme/crypto 0.2.0 → 0.3.1

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 (46) hide show
  1. package/README.md +107 -17
  2. package/dist/aead.js +15 -8
  3. package/dist/aesKw.d.ts +7 -4
  4. package/dist/aesKw.js +69 -22
  5. package/dist/algorithms.d.ts +12 -4
  6. package/dist/algorithms.js +8 -2
  7. package/dist/argon2id.d.ts +1 -0
  8. package/dist/argon2id.js +13 -4
  9. package/dist/cryptoFacade.d.ts +33 -8
  10. package/dist/cryptoFacade.js +42 -29
  11. package/dist/hkdf.d.ts +1 -0
  12. package/dist/hkdf.js +5 -1
  13. package/dist/hmac.d.ts +3 -0
  14. package/dist/hmac.js +24 -3
  15. package/dist/hpke.d.ts +1 -2
  16. package/dist/hpke.js +33 -22
  17. package/dist/index.d.ts +9 -7
  18. package/dist/index.js +8 -6
  19. package/dist/jwk.d.ts +2 -1
  20. package/dist/jwk.js +104 -63
  21. package/dist/kmac.d.ts +11 -0
  22. package/dist/kmac.js +49 -0
  23. package/dist/mlDsa.js +22 -11
  24. package/dist/mlKem.d.ts +0 -3
  25. package/dist/mlKem.js +19 -37
  26. package/dist/operationResponse.d.ts +16 -0
  27. package/dist/operationResponse.js +46 -0
  28. package/dist/pbkdf2.d.ts +6 -8
  29. package/dist/pbkdf2.js +12 -12
  30. package/dist/proto/generated/reallyme/crypto/v1/crypto_pb.d.ts +1741 -328
  31. package/dist/proto/generated/reallyme/crypto/v1/crypto_pb.js +731 -344
  32. package/dist/proto.d.ts +6 -22
  33. package/dist/proto.js +124 -102
  34. package/dist/rsa.d.ts +2 -1
  35. package/dist/rsa.js +5 -1
  36. package/dist/slhDsa.js +21 -11
  37. package/dist/validateBytes.d.ts +6 -1
  38. package/dist/validateBytes.js +57 -3
  39. package/dist/wasm/reallyme_crypto_wasm.js +91 -134
  40. package/dist/wasm/reallyme_crypto_wasm_bg.wasm +0 -0
  41. package/dist/wasmModuleTypes.d.ts +7 -10
  42. package/dist/wasmProvider.d.ts +11 -13
  43. package/dist/wasmProvider.js +16 -19
  44. package/dist/xWing.d.ts +0 -5
  45. package/dist/xWing.js +20 -52
  46. package/package.json +15 -2
@@ -2,25 +2,79 @@
2
2
  //
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  import { ReallyMeCryptoError } from "./errors.js";
5
+ // Match the structured operation boundary so direct primitive facades cannot
6
+ // ask a provider to copy or allocate an attacker-controlled unbounded buffer.
7
+ export const MAX_CRYPTO_INPUT_LENGTH = 1_048_576;
5
8
  export const ensureByteArray = (value) => {
6
9
  if (!(value instanceof Uint8Array)) {
7
10
  throw new ReallyMeCryptoError("invalid-input");
8
11
  }
9
12
  };
13
+ export const ensureByteArrayAtMost = (value, maximumLength) => {
14
+ ensureByteArray(value);
15
+ if (value.length > maximumLength) {
16
+ throw new ReallyMeCryptoError("invalid-input");
17
+ }
18
+ };
10
19
  export const ensureBytes = (value, expectedLength) => {
11
20
  ensureByteArray(value);
12
21
  if (value.length !== expectedLength) {
13
22
  throw new ReallyMeCryptoError("invalid-input");
14
23
  }
15
24
  };
16
- export const readByteArrayProperty = (value, propertyName, expectedLength) => {
25
+ export const byteArraysOverlap = (left, right) => {
26
+ if (left.buffer !== right.buffer) {
27
+ return false;
28
+ }
29
+ const leftEnd = left.byteOffset + left.byteLength;
30
+ const rightEnd = right.byteOffset + right.byteLength;
31
+ return left.byteOffset < rightEnd && right.byteOffset < leftEnd;
32
+ };
33
+ export const ensureIndependentByteArray = (value, disallowedViews) => {
34
+ // A disjoint view into the same ArrayBuffer is still not independently
35
+ // owned: transferring or detaching the caller's buffer would invalidate the
36
+ // provider output too. Provider results must own separate backing storage.
37
+ if (disallowedViews.some((view) => value.buffer === view.buffer)) {
38
+ throw new ReallyMeCryptoError("provider-failure");
39
+ }
40
+ };
41
+ const readProviderByteArrayProperty = (value, propertyName) => {
17
42
  if (typeof value !== "object" || value === null) {
18
43
  throw new ReallyMeCryptoError("provider-failure");
19
44
  }
20
- const property = Reflect.get(value, propertyName);
45
+ let property;
46
+ try {
47
+ property = Reflect.get(value, propertyName);
48
+ }
49
+ catch (_error) {
50
+ throw new ReallyMeCryptoError("provider-failure");
51
+ }
21
52
  if (!(property instanceof Uint8Array)) {
22
53
  throw new ReallyMeCryptoError("provider-failure");
23
54
  }
24
- ensureBytes(property, expectedLength);
25
55
  return property;
26
56
  };
57
+ export const readIndependentByteArrayProperty = (value, propertyName, expectedLength, disallowedViews) => {
58
+ const property = readProviderByteArrayProperty(value, propertyName);
59
+ // Check ownership before cleanup so a malformed provider cannot make the
60
+ // validator erase a caller-owned input view.
61
+ ensureIndependentByteArray(property, disallowedViews);
62
+ if (property.length !== expectedLength) {
63
+ property.fill(0);
64
+ throw new ReallyMeCryptoError("provider-failure");
65
+ }
66
+ return property;
67
+ };
68
+ export const readIndependentProviderBytes = (value, expectedLength, disallowedViews) => {
69
+ if (!(value instanceof Uint8Array)) {
70
+ throw new ReallyMeCryptoError("provider-failure");
71
+ }
72
+ // Provider-owned secret outputs are cleared on malformed length, but only
73
+ // after proving the provider did not hand back a caller-owned buffer.
74
+ ensureIndependentByteArray(value, disallowedViews);
75
+ if (value.length !== expectedLength) {
76
+ value.fill(0);
77
+ throw new ReallyMeCryptoError("provider-failure");
78
+ }
79
+ return value;
80
+ };
@@ -32,6 +32,34 @@ export function aes128GcmSeal(key, nonce, aad, plaintext) {
32
32
  return takeFromExternrefTable0(ret[0]);
33
33
  }
34
34
 
35
+ /**
36
+ * Unwrap key material with AES-128-KW.
37
+ * @param {Uint8Array} kek
38
+ * @param {Uint8Array} wrapped_key
39
+ * @returns {Uint8Array}
40
+ */
41
+ export function aes128KwUnwrapKey(kek, wrapped_key) {
42
+ const ret = wasm.aes128KwUnwrapKey(kek, wrapped_key);
43
+ if (ret[2]) {
44
+ throw takeFromExternrefTable0(ret[1]);
45
+ }
46
+ return takeFromExternrefTable0(ret[0]);
47
+ }
48
+
49
+ /**
50
+ * Wrap key material with AES-128-KW.
51
+ * @param {Uint8Array} kek
52
+ * @param {Uint8Array} key_data
53
+ * @returns {Uint8Array}
54
+ */
55
+ export function aes128KwWrapKey(kek, key_data) {
56
+ const ret = wasm.aes128KwWrapKey(kek, key_data);
57
+ if (ret[2]) {
58
+ throw takeFromExternrefTable0(ret[1]);
59
+ }
60
+ return takeFromExternrefTable0(ret[0]);
61
+ }
62
+
35
63
  /**
36
64
  * Open and authenticate an AES-192-GCM `ciphertext || tag`.
37
65
  * @param {Uint8Array} key
@@ -64,6 +92,34 @@ export function aes192GcmSeal(key, nonce, aad, plaintext) {
64
92
  return takeFromExternrefTable0(ret[0]);
65
93
  }
66
94
 
95
+ /**
96
+ * Unwrap key material with AES-192-KW.
97
+ * @param {Uint8Array} kek
98
+ * @param {Uint8Array} wrapped_key
99
+ * @returns {Uint8Array}
100
+ */
101
+ export function aes192KwUnwrapKey(kek, wrapped_key) {
102
+ const ret = wasm.aes192KwUnwrapKey(kek, wrapped_key);
103
+ if (ret[2]) {
104
+ throw takeFromExternrefTable0(ret[1]);
105
+ }
106
+ return takeFromExternrefTable0(ret[0]);
107
+ }
108
+
109
+ /**
110
+ * Wrap key material with AES-192-KW.
111
+ * @param {Uint8Array} kek
112
+ * @param {Uint8Array} key_data
113
+ * @returns {Uint8Array}
114
+ */
115
+ export function aes192KwWrapKey(kek, key_data) {
116
+ const ret = wasm.aes192KwWrapKey(kek, key_data);
117
+ if (ret[2]) {
118
+ throw takeFromExternrefTable0(ret[1]);
119
+ }
120
+ return takeFromExternrefTable0(ret[0]);
121
+ }
122
+
67
123
  /**
68
124
  * Open and authenticate an AES-256-GCM `ciphertext || tag`.
69
125
  * @param {Uint8Array} key
@@ -129,7 +185,7 @@ export function aes256GcmSivSeal(key, nonce, aad, plaintext) {
129
185
  }
130
186
 
131
187
  /**
132
- * Unwrap an RFC 3394 AES-256-KW wrapped key.
188
+ * Unwrap key material with AES-256-KW.
133
189
  * @param {Uint8Array} kek
134
190
  * @param {Uint8Array} wrapped_key
135
191
  * @returns {Uint8Array}
@@ -143,7 +199,7 @@ export function aes256KwUnwrapKey(kek, wrapped_key) {
143
199
  }
144
200
 
145
201
  /**
146
- * Wrap key material with AES-256-KW and return the RFC 3394 wrapped key.
202
+ * Wrap key material with AES-256-KW.
147
203
  * @param {Uint8Array} kek
148
204
  * @param {Uint8Array} key_data
149
205
  * @returns {Uint8Array}
@@ -239,17 +295,15 @@ export function hpkeSealBase(suite, recipient_public_key, info, aad, plaintext)
239
295
  }
240
296
 
241
297
  /**
242
- * Deterministically seal one HPKE Base-mode message for conformance tests.
243
- * @param {number} suite
244
- * @param {Uint8Array} recipient_public_key
245
- * @param {Uint8Array} encapsulation_randomness
246
- * @param {Uint8Array} info
247
- * @param {Uint8Array} aad
248
- * @param {Uint8Array} plaintext
249
- * @returns {any}
298
+ * Derive key material with KMAC256.
299
+ * @param {Uint8Array} key
300
+ * @param {Uint8Array} context
301
+ * @param {Uint8Array} customization
302
+ * @param {number} output_length
303
+ * @returns {Uint8Array}
250
304
  */
251
- export function hpkeSealBaseDerand(suite, recipient_public_key, encapsulation_randomness, info, aad, plaintext) {
252
- const ret = wasm.hpkeSealBaseDerand(suite, recipient_public_key, encapsulation_randomness, info, aad, plaintext);
305
+ export function kmac256Derive(key, context, customization, output_length) {
306
+ const ret = wasm.kmac256Derive(key, context, customization, output_length);
253
307
  if (ret[2]) {
254
308
  throw takeFromExternrefTable0(ret[1]);
255
309
  }
@@ -452,20 +506,6 @@ export function mlKem1024Encapsulate(public_key) {
452
506
  return takeFromExternrefTable0(ret[0]);
453
507
  }
454
508
 
455
- /**
456
- * Deterministically encapsulate to an ML-KEM-1024 public key.
457
- * @param {Uint8Array} public_key
458
- * @param {Uint8Array} randomness
459
- * @returns {any}
460
- */
461
- export function mlKem1024EncapsulateDerand(public_key, randomness) {
462
- const ret = wasm.mlKem1024EncapsulateDerand(public_key, randomness);
463
- if (ret[2]) {
464
- throw takeFromExternrefTable0(ret[1]);
465
- }
466
- return takeFromExternrefTable0(ret[0]);
467
- }
468
-
469
509
  /**
470
510
  * Generate an ML-KEM-1024 keypair.
471
511
  * @returns {any}
@@ -518,20 +558,6 @@ export function mlKem512Encapsulate(public_key) {
518
558
  return takeFromExternrefTable0(ret[0]);
519
559
  }
520
560
 
521
- /**
522
- * Deterministically encapsulate to an ML-KEM-512 public key.
523
- * @param {Uint8Array} public_key
524
- * @param {Uint8Array} randomness
525
- * @returns {any}
526
- */
527
- export function mlKem512EncapsulateDerand(public_key, randomness) {
528
- const ret = wasm.mlKem512EncapsulateDerand(public_key, randomness);
529
- if (ret[2]) {
530
- throw takeFromExternrefTable0(ret[1]);
531
- }
532
- return takeFromExternrefTable0(ret[0]);
533
- }
534
-
535
561
  /**
536
562
  * Generate an ML-KEM-512 keypair.
537
563
  * @returns {any}
@@ -585,13 +611,11 @@ export function mlKem768Encapsulate(public_key) {
585
611
  }
586
612
 
587
613
  /**
588
- * Deterministically encapsulate to an ML-KEM-768 public key.
589
- * @param {Uint8Array} public_key
590
- * @param {Uint8Array} randomness
614
+ * Generate an ML-KEM-768 keypair.
591
615
  * @returns {any}
592
616
  */
593
- export function mlKem768EncapsulateDerand(public_key, randomness) {
594
- const ret = wasm.mlKem768EncapsulateDerand(public_key, randomness);
617
+ export function mlKem768GenerateKeypair() {
618
+ const ret = wasm.mlKem768GenerateKeypair();
595
619
  if (ret[2]) {
596
620
  throw takeFromExternrefTable0(ret[1]);
597
621
  }
@@ -599,15 +623,23 @@ export function mlKem768EncapsulateDerand(public_key, randomness) {
599
623
  }
600
624
 
601
625
  /**
602
- * Generate an ML-KEM-768 keypair.
603
- * @returns {any}
626
+ * Execute one generated binary protobuf request and return a binary `CryptoOperationResponse`.
627
+ * @param {Uint8Array} request
628
+ * @returns {Uint8Array}
604
629
  */
605
- export function mlKem768GenerateKeypair() {
606
- const ret = wasm.mlKem768GenerateKeypair();
607
- if (ret[2]) {
608
- throw takeFromExternrefTable0(ret[1]);
609
- }
610
- return takeFromExternrefTable0(ret[0]);
630
+ export function processOperationResponse(request) {
631
+ const ret = wasm.processOperationResponse(request);
632
+ return ret;
633
+ }
634
+
635
+ /**
636
+ * Execute one generated ProtoJSON request and return a binary `CryptoOperationResponse`.
637
+ * @param {Uint8Array} request_json
638
+ * @returns {Uint8Array}
639
+ */
640
+ export function processOperationResponseJson(request_json) {
641
+ const ret = wasm.processOperationResponseJson(request_json);
642
+ return ret;
611
643
  }
612
644
 
613
645
  /**
@@ -696,72 +728,6 @@ export function slhDsaSha2128sVerify(public_key, message, signature) {
696
728
  }
697
729
  }
698
730
 
699
- /**
700
- * Decapsulate an X-Wing-1024 ciphertext with a 32-byte secret seed.
701
- * @param {Uint8Array} ciphertext
702
- * @param {Uint8Array} secret_key
703
- * @returns {Uint8Array}
704
- */
705
- export function xWing1024Decapsulate(ciphertext, secret_key) {
706
- const ret = wasm.xWing1024Decapsulate(ciphertext, secret_key);
707
- if (ret[2]) {
708
- throw takeFromExternrefTable0(ret[1]);
709
- }
710
- return takeFromExternrefTable0(ret[0]);
711
- }
712
-
713
- /**
714
- * Derive an X-Wing-1024 public key from a 32-byte secret seed.
715
- * @param {Uint8Array} secret_key
716
- * @returns {any}
717
- */
718
- export function xWing1024DeriveKeypair(secret_key) {
719
- const ret = wasm.xWing1024DeriveKeypair(secret_key);
720
- if (ret[2]) {
721
- throw takeFromExternrefTable0(ret[1]);
722
- }
723
- return takeFromExternrefTable0(ret[0]);
724
- }
725
-
726
- /**
727
- * Randomly encapsulate to an X-Wing-1024 public key.
728
- * @param {Uint8Array} public_key
729
- * @returns {any}
730
- */
731
- export function xWing1024Encapsulate(public_key) {
732
- const ret = wasm.xWing1024Encapsulate(public_key);
733
- if (ret[2]) {
734
- throw takeFromExternrefTable0(ret[1]);
735
- }
736
- return takeFromExternrefTable0(ret[0]);
737
- }
738
-
739
- /**
740
- * Deterministically encapsulate to an X-Wing-1024 public key for conformance tests.
741
- * @param {Uint8Array} public_key
742
- * @param {Uint8Array} seed
743
- * @returns {any}
744
- */
745
- export function xWing1024EncapsulateDerand(public_key, seed) {
746
- const ret = wasm.xWing1024EncapsulateDerand(public_key, seed);
747
- if (ret[2]) {
748
- throw takeFromExternrefTable0(ret[1]);
749
- }
750
- return takeFromExternrefTable0(ret[0]);
751
- }
752
-
753
- /**
754
- * Generate a random X-Wing-1024 keypair for the TypeScript WASM provider.
755
- * @returns {any}
756
- */
757
- export function xWing1024GenerateKeypair() {
758
- const ret = wasm.xWing1024GenerateKeypair();
759
- if (ret[2]) {
760
- throw takeFromExternrefTable0(ret[1]);
761
- }
762
- return takeFromExternrefTable0(ret[0]);
763
- }
764
-
765
731
  /**
766
732
  * Decapsulate an X-Wing-768 ciphertext with a 32-byte secret seed.
767
733
  * @param {Uint8Array} ciphertext
@@ -802,20 +768,6 @@ export function xWing768Encapsulate(public_key) {
802
768
  return takeFromExternrefTable0(ret[0]);
803
769
  }
804
770
 
805
- /**
806
- * Deterministically encapsulate to an X-Wing-768 public key for conformance tests.
807
- * @param {Uint8Array} public_key
808
- * @param {Uint8Array} seed
809
- * @returns {any}
810
- */
811
- export function xWing768EncapsulateDerand(public_key, seed) {
812
- const ret = wasm.xWing768EncapsulateDerand(public_key, seed);
813
- if (ret[2]) {
814
- throw takeFromExternrefTable0(ret[1]);
815
- }
816
- return takeFromExternrefTable0(ret[0]);
817
- }
818
-
819
771
  /**
820
772
  * Generate a random X-Wing-768 keypair for the TypeScript WASM provider.
821
773
  * @returns {any}
@@ -887,7 +839,12 @@ function __wbg_get_imports() {
887
839
  const ret = Reflect.set(arg0, arg1, arg2);
888
840
  return ret;
889
841
  }, arguments); },
890
- __wbindgen_cast_0000000000000001: function(arg0, arg1) {
842
+ __wbindgen_cast_0000000000000001: function(arg0) {
843
+ // Cast intrinsic for `F64 -> Externref`.
844
+ const ret = arg0;
845
+ return ret;
846
+ },
847
+ __wbindgen_cast_0000000000000002: function(arg0, arg1) {
891
848
  // Cast intrinsic for `Ref(String) -> Externref`.
892
849
  const ret = getStringFromWasm0(arg0, arg1);
893
850
  return ret;
@@ -4,6 +4,8 @@ export type ReallyMeWasmInitOutput = Readonly<{
4
4
  export declare function initSync(module: {
5
5
  module: Uint8Array;
6
6
  }): ReallyMeWasmInitOutput;
7
+ export declare function processOperationResponse(request: Uint8Array): Uint8Array;
8
+ export declare function processOperationResponseJson(requestJson: Uint8Array): Uint8Array;
7
9
  export declare function aes128GcmOpen(key: Uint8Array, nonce: Uint8Array, aad: Uint8Array, ciphertextWithTag: Uint8Array): Uint8Array;
8
10
  export declare function aes128GcmSeal(key: Uint8Array, nonce: Uint8Array, aad: Uint8Array, plaintext: Uint8Array): Uint8Array;
9
11
  export declare function aes192GcmOpen(key: Uint8Array, nonce: Uint8Array, aad: Uint8Array, ciphertextWithTag: Uint8Array): Uint8Array;
@@ -12,26 +14,27 @@ export declare function aes256GcmOpen(key: Uint8Array, nonce: Uint8Array, aad: U
12
14
  export declare function aes256GcmSeal(key: Uint8Array, nonce: Uint8Array, aad: Uint8Array, plaintext: Uint8Array): Uint8Array;
13
15
  export declare function aes256GcmSivOpen(key: Uint8Array, nonce: Uint8Array, aad: Uint8Array, ciphertextWithTag: Uint8Array): Uint8Array;
14
16
  export declare function aes256GcmSivSeal(key: Uint8Array, nonce: Uint8Array, aad: Uint8Array, plaintext: Uint8Array): Uint8Array;
17
+ export declare function aes128KwUnwrapKey(wrappingKey: Uint8Array, wrappedKey: Uint8Array): Uint8Array;
18
+ export declare function aes128KwWrapKey(wrappingKey: Uint8Array, keyToWrap: Uint8Array): Uint8Array;
19
+ export declare function aes192KwUnwrapKey(wrappingKey: Uint8Array, wrappedKey: Uint8Array): Uint8Array;
20
+ export declare function aes192KwWrapKey(wrappingKey: Uint8Array, keyToWrap: Uint8Array): Uint8Array;
15
21
  export declare function aes256KwUnwrapKey(wrappingKey: Uint8Array, wrappedKey: Uint8Array): Uint8Array;
16
22
  export declare function aes256KwWrapKey(wrappingKey: Uint8Array, keyToWrap: Uint8Array): Uint8Array;
17
23
  export declare function argon2idDeriveKey(kdfVersion: number, secret: Uint8Array, salt: Uint8Array): Uint8Array;
24
+ export declare function kmac256Derive(key: Uint8Array, context: Uint8Array, customization: Uint8Array, outputLength: number): Uint8Array;
18
25
  export declare function hpkeOpenBase(suite: number, recipientSecretKey: Uint8Array, encapsulatedKey: Uint8Array, info: Uint8Array, aad: Uint8Array, ciphertext: Uint8Array): Uint8Array;
19
26
  export declare function hpkeSealBase(suite: number, recipientPublicKey: Uint8Array, info: Uint8Array, aad: Uint8Array, plaintext: Uint8Array): unknown;
20
- export declare function hpkeSealBaseDerand(suite: number, recipientPublicKey: Uint8Array, encapsulationRandomness: Uint8Array, info: Uint8Array, aad: Uint8Array, plaintext: Uint8Array): unknown;
21
27
  export declare function mlKem512GenerateKeypair(): unknown;
22
28
  export declare function mlKem512DeriveKeypair(secretKey: Uint8Array): unknown;
23
29
  export declare function mlKem512Encapsulate(publicKey: Uint8Array): unknown;
24
- export declare function mlKem512EncapsulateDerand(publicKey: Uint8Array, randomness: Uint8Array): unknown;
25
30
  export declare function mlKem512Decapsulate(ciphertext: Uint8Array, secretKey: Uint8Array): Uint8Array;
26
31
  export declare function mlKem768GenerateKeypair(): unknown;
27
32
  export declare function mlKem768DeriveKeypair(secretKey: Uint8Array): unknown;
28
33
  export declare function mlKem768Encapsulate(publicKey: Uint8Array): unknown;
29
- export declare function mlKem768EncapsulateDerand(publicKey: Uint8Array, randomness: Uint8Array): unknown;
30
34
  export declare function mlKem768Decapsulate(ciphertext: Uint8Array, secretKey: Uint8Array): Uint8Array;
31
35
  export declare function mlKem1024GenerateKeypair(): unknown;
32
36
  export declare function mlKem1024DeriveKeypair(secretKey: Uint8Array): unknown;
33
37
  export declare function mlKem1024Encapsulate(publicKey: Uint8Array): unknown;
34
- export declare function mlKem1024EncapsulateDerand(publicKey: Uint8Array, randomness: Uint8Array): unknown;
35
38
  export declare function mlKem1024Decapsulate(ciphertext: Uint8Array, secretKey: Uint8Array): Uint8Array;
36
39
  export declare function mlDsa44GenerateKeypair(): unknown;
37
40
  export declare function mlDsa44DeriveKeypair(secretKey: Uint8Array): unknown;
@@ -55,13 +58,7 @@ export declare function chacha20Poly1305Open(key: Uint8Array, nonce: Uint8Array,
55
58
  export declare function chacha20Poly1305Seal(key: Uint8Array, nonce: Uint8Array, aad: Uint8Array, plaintext: Uint8Array): Uint8Array;
56
59
  export declare function xchacha20Poly1305Open(key: Uint8Array, nonce: Uint8Array, aad: Uint8Array, ciphertextWithTag: Uint8Array): Uint8Array;
57
60
  export declare function xchacha20Poly1305Seal(key: Uint8Array, nonce: Uint8Array, aad: Uint8Array, plaintext: Uint8Array): Uint8Array;
58
- export declare function xWing1024Decapsulate(ciphertext: Uint8Array, secretKey: Uint8Array): Uint8Array;
59
- export declare function xWing1024DeriveKeypair(secretKey: Uint8Array): unknown;
60
- export declare function xWing1024Encapsulate(publicKey: Uint8Array): unknown;
61
- export declare function xWing1024EncapsulateDerand(publicKey: Uint8Array, seed: Uint8Array): unknown;
62
- export declare function xWing1024GenerateKeypair(): unknown;
63
61
  export declare function xWing768Decapsulate(ciphertext: Uint8Array, secretKey: Uint8Array): Uint8Array;
64
62
  export declare function xWing768DeriveKeypair(secretKey: Uint8Array): unknown;
65
63
  export declare function xWing768Encapsulate(publicKey: Uint8Array): unknown;
66
- export declare function xWing768EncapsulateDerand(publicKey: Uint8Array, seed: Uint8Array): unknown;
67
64
  export declare function xWing768GenerateKeypair(): unknown;
@@ -1,21 +1,24 @@
1
1
  type GenerateKeypairFn = () => unknown;
2
2
  type GenerateKeypairFromSeedFn = (seed: Uint8Array) => unknown;
3
3
  type Argon2idFn = (kdfVersion: number, secret: Uint8Array, salt: Uint8Array) => unknown;
4
+ type KmacFn = (key: Uint8Array, context: Uint8Array, customization: Uint8Array, outputLength: number) => unknown;
4
5
  type AeadFn = (key: Uint8Array, nonce: Uint8Array, aad: Uint8Array, text: Uint8Array) => unknown;
5
- type KeyWrapFn = (wrappingKey: Uint8Array, keyMaterial: Uint8Array) => unknown;
6
+ type TwoByteArraysFn = (first: Uint8Array, second: Uint8Array) => unknown;
7
+ type KeyWrapFn = TwoByteArraysFn;
6
8
  type SignatureSignFn = (secretKey: Uint8Array, message: Uint8Array) => unknown;
7
9
  type SignatureVerifyFn = (publicKey: Uint8Array, message: Uint8Array, signature: Uint8Array) => unknown;
8
10
  type RsaPkcs1v15VerifyFn = (publicKeyDer: Uint8Array, publicKeyEncoding: number, hashSuite: number, message: Uint8Array, signature: Uint8Array) => unknown;
9
11
  type RsaPssVerifyFn = (publicKeyDer: Uint8Array, publicKeyEncoding: number, messageHashSuite: number, mgf1HashSuite: number, saltLength: number, message: Uint8Array, signature: Uint8Array) => unknown;
10
12
  type HpkeOpenFn = (suite: number, recipientSecretKey: Uint8Array, encapsulatedKey: Uint8Array, info: Uint8Array, aad: Uint8Array, ciphertext: Uint8Array) => unknown;
11
13
  type HpkeSealFn = (suite: number, recipientPublicKey: Uint8Array, info: Uint8Array, aad: Uint8Array, plaintext: Uint8Array) => unknown;
12
- type HpkeSealDerandFn = (suite: number, recipientPublicKey: Uint8Array, encapsulationRandomness: Uint8Array, info: Uint8Array, aad: Uint8Array, plaintext: Uint8Array) => unknown;
13
14
  type DeriveKeypairFn = (secretKey: Uint8Array) => unknown;
14
15
  type SlhDsaDeriveKeypairFn = (skSeed: Uint8Array, skPrf: Uint8Array, pkSeed: Uint8Array) => unknown;
15
16
  type EncapsulateFn = (publicKey: Uint8Array) => unknown;
16
- type EncapsulateDerandFn = (publicKey: Uint8Array, seed: Uint8Array) => unknown;
17
17
  type DecapsulateFn = (ciphertext: Uint8Array, secretKey: Uint8Array) => unknown;
18
+ type BytesToBytesFn = (bytes: Uint8Array) => unknown;
18
19
  export type ReallyMeWasmProvider = Readonly<{
20
+ processOperationResponse: BytesToBytesFn;
21
+ processOperationResponseJson: BytesToBytesFn;
19
22
  aes128GcmSeal: AeadFn;
20
23
  aes128GcmOpen: AeadFn;
21
24
  aes192GcmSeal: AeadFn;
@@ -28,11 +31,15 @@ export type ReallyMeWasmProvider = Readonly<{
28
31
  chacha20Poly1305Open: AeadFn;
29
32
  xchacha20Poly1305Seal: AeadFn;
30
33
  xchacha20Poly1305Open: AeadFn;
34
+ aes128KwWrapKey: KeyWrapFn;
35
+ aes128KwUnwrapKey: KeyWrapFn;
36
+ aes192KwWrapKey: KeyWrapFn;
37
+ aes192KwUnwrapKey: KeyWrapFn;
31
38
  aes256KwWrapKey: KeyWrapFn;
32
39
  aes256KwUnwrapKey: KeyWrapFn;
33
40
  argon2idDeriveKey: Argon2idFn;
41
+ kmac256Derive: KmacFn;
34
42
  hpkeSealBase: HpkeSealFn;
35
- hpkeSealBaseDerand: HpkeSealDerandFn;
36
43
  hpkeOpenBase: HpkeOpenFn;
37
44
  mlDsa44GenerateKeypair: GenerateKeypairFn;
38
45
  mlDsa44DeriveKeypair: GenerateKeypairFromSeedFn;
@@ -49,17 +56,14 @@ export type ReallyMeWasmProvider = Readonly<{
49
56
  mlKem512GenerateKeypair: GenerateKeypairFn;
50
57
  mlKem512DeriveKeypair: GenerateKeypairFromSeedFn;
51
58
  mlKem512Encapsulate: EncapsulateFn;
52
- mlKem512EncapsulateDerand: EncapsulateDerandFn;
53
59
  mlKem512Decapsulate: DecapsulateFn;
54
60
  mlKem768GenerateKeypair: GenerateKeypairFn;
55
61
  mlKem768DeriveKeypair: GenerateKeypairFromSeedFn;
56
62
  mlKem768Encapsulate: EncapsulateFn;
57
- mlKem768EncapsulateDerand: EncapsulateDerandFn;
58
63
  mlKem768Decapsulate: DecapsulateFn;
59
64
  mlKem1024GenerateKeypair: GenerateKeypairFn;
60
65
  mlKem1024DeriveKeypair: GenerateKeypairFromSeedFn;
61
66
  mlKem1024Encapsulate: EncapsulateFn;
62
- mlKem1024EncapsulateDerand: EncapsulateDerandFn;
63
67
  mlKem1024Decapsulate: DecapsulateFn;
64
68
  slhDsaSha2128sGenerateKeypair: GenerateKeypairFn;
65
69
  slhDsaSha2128sDeriveKeypair: SlhDsaDeriveKeypairFn;
@@ -70,13 +74,7 @@ export type ReallyMeWasmProvider = Readonly<{
70
74
  xWing768GenerateKeypair: GenerateKeypairFn;
71
75
  xWing768DeriveKeypair: DeriveKeypairFn;
72
76
  xWing768Encapsulate: EncapsulateFn;
73
- xWing768EncapsulateDerand: EncapsulateDerandFn;
74
77
  xWing768Decapsulate: DecapsulateFn;
75
- xWing1024GenerateKeypair: GenerateKeypairFn;
76
- xWing1024DeriveKeypair: DeriveKeypairFn;
77
- xWing1024Encapsulate: EncapsulateFn;
78
- xWing1024EncapsulateDerand: EncapsulateDerandFn;
79
- xWing1024Decapsulate: DecapsulateFn;
80
78
  }>;
81
79
  export declare const createReallyMeWasmProvider: (module: unknown) => ReallyMeWasmProvider;
82
80
  export declare const installReallyMeWasmProvider: (module: unknown) => void;
@@ -25,15 +25,15 @@ const requireFunction = (module, name) => {
25
25
  };
26
26
  const wasmErrorCode = (error) => {
27
27
  switch (error) {
28
- case "invalid-input":
28
+ case 1 /* WasmErrorCode.InvalidInput */:
29
29
  return "invalid-input";
30
- case "invalid-signature":
30
+ case 2 /* WasmErrorCode.InvalidSignature */:
31
31
  return "invalid-signature";
32
- case "authentication-failed":
32
+ case 3 /* WasmErrorCode.AuthenticationFailed */:
33
33
  return "authentication-failed";
34
- case "unsupported-algorithm":
34
+ case 5 /* WasmErrorCode.UnsupportedAlgorithm */:
35
35
  return "unsupported-algorithm";
36
- case "provider-failure":
36
+ case 4 /* WasmErrorCode.ProviderFailure */:
37
37
  default:
38
38
  return "provider-failure";
39
39
  }
@@ -66,13 +66,13 @@ const argon2idFunction = (module, name) => {
66
66
  const callable = requireFunction(module, name);
67
67
  return (kdfVersion, secret, salt) => callable(kdfVersion, secret, salt);
68
68
  };
69
- const hpkeSealFunction = (module, name) => {
69
+ const kmacFunction = (module, name) => {
70
70
  const callable = requireFunction(module, name);
71
- return (suite, recipientPublicKey, info, aad, plaintext) => callable(suite, recipientPublicKey, info, aad, plaintext);
71
+ return (key, context, customization, outputLength) => callable(key, context, customization, outputLength);
72
72
  };
73
- const hpkeSealDerandFunction = (module, name) => {
73
+ const hpkeSealFunction = (module, name) => {
74
74
  const callable = requireFunction(module, name);
75
- return (suite, recipientPublicKey, encapsulationRandomness, info, aad, plaintext) => callable(suite, recipientPublicKey, encapsulationRandomness, info, aad, plaintext);
75
+ return (suite, recipientPublicKey, info, aad, plaintext) => callable(suite, recipientPublicKey, info, aad, plaintext);
76
76
  };
77
77
  const hpkeOpenFunction = (module, name) => {
78
78
  const callable = requireFunction(module, name);
@@ -89,6 +89,8 @@ const rsaPssVerifyFunction = (module, name) => {
89
89
  export const createReallyMeWasmProvider = (module) => {
90
90
  const providerModule = requireObject(module);
91
91
  return {
92
+ processOperationResponse: function1(providerModule, "processOperationResponse"),
93
+ processOperationResponseJson: function1(providerModule, "processOperationResponseJson"),
92
94
  aes128GcmSeal: function4(providerModule, "aes128GcmSeal"),
93
95
  aes128GcmOpen: function4(providerModule, "aes128GcmOpen"),
94
96
  aes192GcmSeal: function4(providerModule, "aes192GcmSeal"),
@@ -101,11 +103,15 @@ export const createReallyMeWasmProvider = (module) => {
101
103
  chacha20Poly1305Open: function4(providerModule, "chacha20Poly1305Open"),
102
104
  xchacha20Poly1305Seal: function4(providerModule, "xchacha20Poly1305Seal"),
103
105
  xchacha20Poly1305Open: function4(providerModule, "xchacha20Poly1305Open"),
106
+ aes128KwWrapKey: function2(providerModule, "aes128KwWrapKey"),
107
+ aes128KwUnwrapKey: function2(providerModule, "aes128KwUnwrapKey"),
108
+ aes192KwWrapKey: function2(providerModule, "aes192KwWrapKey"),
109
+ aes192KwUnwrapKey: function2(providerModule, "aes192KwUnwrapKey"),
104
110
  aes256KwWrapKey: function2(providerModule, "aes256KwWrapKey"),
105
111
  aes256KwUnwrapKey: function2(providerModule, "aes256KwUnwrapKey"),
106
112
  argon2idDeriveKey: argon2idFunction(providerModule, "argon2idDeriveKey"),
113
+ kmac256Derive: kmacFunction(providerModule, "kmac256Derive"),
107
114
  hpkeSealBase: hpkeSealFunction(providerModule, "hpkeSealBase"),
108
- hpkeSealBaseDerand: hpkeSealDerandFunction(providerModule, "hpkeSealBaseDerand"),
109
115
  hpkeOpenBase: hpkeOpenFunction(providerModule, "hpkeOpenBase"),
110
116
  mlDsa44GenerateKeypair: function0(providerModule, "mlDsa44GenerateKeypair"),
111
117
  mlDsa44DeriveKeypair: function1(providerModule, "mlDsa44DeriveKeypair"),
@@ -122,17 +128,14 @@ export const createReallyMeWasmProvider = (module) => {
122
128
  mlKem512GenerateKeypair: function0(providerModule, "mlKem512GenerateKeypair"),
123
129
  mlKem512DeriveKeypair: function1(providerModule, "mlKem512DeriveKeypair"),
124
130
  mlKem512Encapsulate: function1(providerModule, "mlKem512Encapsulate"),
125
- mlKem512EncapsulateDerand: function2(providerModule, "mlKem512EncapsulateDerand"),
126
131
  mlKem512Decapsulate: function2(providerModule, "mlKem512Decapsulate"),
127
132
  mlKem768GenerateKeypair: function0(providerModule, "mlKem768GenerateKeypair"),
128
133
  mlKem768DeriveKeypair: function1(providerModule, "mlKem768DeriveKeypair"),
129
134
  mlKem768Encapsulate: function1(providerModule, "mlKem768Encapsulate"),
130
- mlKem768EncapsulateDerand: function2(providerModule, "mlKem768EncapsulateDerand"),
131
135
  mlKem768Decapsulate: function2(providerModule, "mlKem768Decapsulate"),
132
136
  mlKem1024GenerateKeypair: function0(providerModule, "mlKem1024GenerateKeypair"),
133
137
  mlKem1024DeriveKeypair: function1(providerModule, "mlKem1024DeriveKeypair"),
134
138
  mlKem1024Encapsulate: function1(providerModule, "mlKem1024Encapsulate"),
135
- mlKem1024EncapsulateDerand: function2(providerModule, "mlKem1024EncapsulateDerand"),
136
139
  mlKem1024Decapsulate: function2(providerModule, "mlKem1024Decapsulate"),
137
140
  slhDsaSha2128sGenerateKeypair: function0(providerModule, "slhDsaSha2128sGenerateKeypair"),
138
141
  slhDsaSha2128sDeriveKeypair: deriveSlhDsaFunction3(providerModule, "slhDsaSha2128sDeriveKeypair"),
@@ -143,13 +146,7 @@ export const createReallyMeWasmProvider = (module) => {
143
146
  xWing768GenerateKeypair: function0(providerModule, "xWing768GenerateKeypair"),
144
147
  xWing768DeriveKeypair: function1(providerModule, "xWing768DeriveKeypair"),
145
148
  xWing768Encapsulate: function1(providerModule, "xWing768Encapsulate"),
146
- xWing768EncapsulateDerand: function2(providerModule, "xWing768EncapsulateDerand"),
147
149
  xWing768Decapsulate: function2(providerModule, "xWing768Decapsulate"),
148
- xWing1024GenerateKeypair: function0(providerModule, "xWing1024GenerateKeypair"),
149
- xWing1024DeriveKeypair: function1(providerModule, "xWing1024DeriveKeypair"),
150
- xWing1024Encapsulate: function1(providerModule, "xWing1024Encapsulate"),
151
- xWing1024EncapsulateDerand: function2(providerModule, "xWing1024EncapsulateDerand"),
152
- xWing1024Decapsulate: function2(providerModule, "xWing1024Decapsulate"),
153
150
  };
154
151
  };
155
152
  export const installReallyMeWasmProvider = (module) => {
package/dist/xWing.d.ts CHANGED
@@ -1,12 +1,9 @@
1
1
  import type { ReallyMeKemAlgorithm } from "./algorithms.js";
2
2
  import type { ReallyMeWasmProvider } from "./wasmProvider.js";
3
3
  export declare const X_WING_SECRET_KEY_LENGTH = 32;
4
- export declare const X_WING_ENCAPSULATION_SEED_LENGTH = 64;
5
4
  export declare const X_WING_SHARED_SECRET_LENGTH = 32;
6
5
  export declare const X_WING_768_PUBLIC_KEY_LENGTH = 1216;
7
6
  export declare const X_WING_768_CIPHERTEXT_LENGTH = 1120;
8
- export declare const X_WING_1024_PUBLIC_KEY_LENGTH = 1600;
9
- export declare const X_WING_1024_CIPHERTEXT_LENGTH = 1600;
10
7
  export type ReallyMeXWingKeyPair = Readonly<{
11
8
  publicKey: Uint8Array;
12
9
  secretKey: Uint8Array;
@@ -25,5 +22,3 @@ export declare const ReallyMeXWing: {
25
22
  readonly decapsulate: (algorithm: ReallyMeKemAlgorithm, ciphertext: Uint8Array, secretKey: Uint8Array) => Uint8Array;
26
23
  readonly decapsulateWithProvider: (provider: ReallyMeWasmProvider, algorithm: ReallyMeKemAlgorithm, ciphertext: Uint8Array, secretKey: Uint8Array) => Uint8Array;
27
24
  };
28
- export declare const encapsulateXWingDeterministicallyForTest: (algorithm: ReallyMeKemAlgorithm, publicKey: Uint8Array, seed: Uint8Array) => ReallyMeXWingEncapsulation;
29
- export declare const encapsulateXWingDeterministicallyWithProviderForTest: (provider: ReallyMeWasmProvider, algorithm: ReallyMeKemAlgorithm, publicKey: Uint8Array, seed: Uint8Array) => ReallyMeXWingEncapsulation;