@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.
- package/README.md +107 -17
- package/dist/aead.js +15 -8
- package/dist/aesKw.d.ts +7 -4
- package/dist/aesKw.js +69 -22
- package/dist/algorithms.d.ts +12 -4
- package/dist/algorithms.js +8 -2
- package/dist/argon2id.d.ts +1 -0
- package/dist/argon2id.js +13 -4
- package/dist/cryptoFacade.d.ts +33 -8
- package/dist/cryptoFacade.js +42 -29
- package/dist/hkdf.d.ts +1 -0
- package/dist/hkdf.js +5 -1
- package/dist/hmac.d.ts +3 -0
- package/dist/hmac.js +24 -3
- package/dist/hpke.d.ts +1 -2
- package/dist/hpke.js +33 -22
- package/dist/index.d.ts +9 -7
- package/dist/index.js +8 -6
- package/dist/jwk.d.ts +2 -1
- package/dist/jwk.js +104 -63
- package/dist/kmac.d.ts +11 -0
- package/dist/kmac.js +49 -0
- package/dist/mlDsa.js +22 -11
- package/dist/mlKem.d.ts +0 -3
- package/dist/mlKem.js +19 -37
- package/dist/operationResponse.d.ts +16 -0
- package/dist/operationResponse.js +46 -0
- package/dist/pbkdf2.d.ts +6 -8
- package/dist/pbkdf2.js +12 -12
- package/dist/proto/generated/reallyme/crypto/v1/crypto_pb.d.ts +1741 -328
- package/dist/proto/generated/reallyme/crypto/v1/crypto_pb.js +731 -344
- package/dist/proto.d.ts +6 -22
- package/dist/proto.js +124 -102
- package/dist/rsa.d.ts +2 -1
- package/dist/rsa.js +5 -1
- package/dist/slhDsa.js +21 -11
- package/dist/validateBytes.d.ts +6 -1
- package/dist/validateBytes.js +57 -3
- package/dist/wasm/reallyme_crypto_wasm.js +91 -134
- package/dist/wasm/reallyme_crypto_wasm_bg.wasm +0 -0
- package/dist/wasmModuleTypes.d.ts +7 -10
- package/dist/wasmProvider.d.ts +11 -13
- package/dist/wasmProvider.js +16 -19
- package/dist/xWing.d.ts +0 -5
- package/dist/xWing.js +20 -52
- package/package.json +15 -2
package/dist/xWing.js
CHANGED
|
@@ -2,15 +2,12 @@
|
|
|
2
2
|
//
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
import { ReallyMeCryptoError } from "./errors.js";
|
|
5
|
-
import { ensureBytes,
|
|
5
|
+
import { ensureBytes, readIndependentByteArrayProperty, readIndependentProviderBytes, } from "./validateBytes.js";
|
|
6
6
|
import { requireReallyMeWasmProvider } from "./wasmProvider.js";
|
|
7
7
|
export const X_WING_SECRET_KEY_LENGTH = 32;
|
|
8
|
-
export const X_WING_ENCAPSULATION_SEED_LENGTH = 64;
|
|
9
8
|
export const X_WING_SHARED_SECRET_LENGTH = 32;
|
|
10
9
|
export const X_WING_768_PUBLIC_KEY_LENGTH = 1_216;
|
|
11
10
|
export const X_WING_768_CIPHERTEXT_LENGTH = 1_120;
|
|
12
|
-
export const X_WING_1024_PUBLIC_KEY_LENGTH = 1_600;
|
|
13
|
-
export const X_WING_1024_CIPHERTEXT_LENGTH = 1_600;
|
|
14
11
|
const xWingSuite = (algorithm) => {
|
|
15
12
|
return xWingSuiteWithProvider(algorithm, requireReallyMeWasmProvider());
|
|
16
13
|
};
|
|
@@ -27,31 +24,24 @@ const xWingSuiteWithProvider = (algorithm, provider) => {
|
|
|
27
24
|
generateKeypair: provider.xWing768GenerateKeypair,
|
|
28
25
|
deriveKeypair: provider.xWing768DeriveKeypair,
|
|
29
26
|
encapsulate: provider.xWing768Encapsulate,
|
|
30
|
-
encapsulateDerand: provider.xWing768EncapsulateDerand,
|
|
31
27
|
decapsulate: provider.xWing768Decapsulate,
|
|
32
28
|
};
|
|
33
29
|
}
|
|
34
|
-
case "X-Wing-1024": {
|
|
35
|
-
return {
|
|
36
|
-
publicKeyLength: X_WING_1024_PUBLIC_KEY_LENGTH,
|
|
37
|
-
ciphertextLength: X_WING_1024_CIPHERTEXT_LENGTH,
|
|
38
|
-
generateKeypair: provider.xWing1024GenerateKeypair,
|
|
39
|
-
deriveKeypair: provider.xWing1024DeriveKeypair,
|
|
40
|
-
encapsulate: provider.xWing1024Encapsulate,
|
|
41
|
-
encapsulateDerand: provider.xWing1024EncapsulateDerand,
|
|
42
|
-
decapsulate: provider.xWing1024Decapsulate,
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
30
|
}
|
|
46
31
|
};
|
|
47
|
-
const readKeyPair = (value, suite) =>
|
|
48
|
-
publicKey
|
|
49
|
-
secretKey
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
32
|
+
const readKeyPair = (value, suite, inputs = []) => {
|
|
33
|
+
const publicKey = readIndependentByteArrayProperty(value, "publicKey", suite.publicKeyLength, inputs);
|
|
34
|
+
const secretKey = readIndependentByteArrayProperty(value, "secretKey", X_WING_SECRET_KEY_LENGTH, [...inputs, publicKey]);
|
|
35
|
+
return { publicKey, secretKey };
|
|
36
|
+
};
|
|
37
|
+
const readEncapsulation = (value, suite, inputs) => {
|
|
38
|
+
const ciphertext = readIndependentByteArrayProperty(value, "ciphertext", suite.ciphertextLength, inputs);
|
|
39
|
+
const sharedSecret = readIndependentByteArrayProperty(value, "sharedSecret", X_WING_SHARED_SECRET_LENGTH, [...inputs, ciphertext]);
|
|
40
|
+
return { ciphertext, sharedSecret };
|
|
41
|
+
};
|
|
42
|
+
const readSharedSecret = (value, inputs) => {
|
|
43
|
+
return readIndependentProviderBytes(value, X_WING_SHARED_SECRET_LENGTH, inputs);
|
|
44
|
+
};
|
|
55
45
|
export const ReallyMeXWing = {
|
|
56
46
|
generateKeyPair(algorithm) {
|
|
57
47
|
const suite = xWingSuite(algorithm);
|
|
@@ -64,55 +54,33 @@ export const ReallyMeXWing = {
|
|
|
64
54
|
deriveKeyPair(algorithm, secretKey) {
|
|
65
55
|
ensureBytes(secretKey, X_WING_SECRET_KEY_LENGTH);
|
|
66
56
|
const suite = xWingSuite(algorithm);
|
|
67
|
-
return readKeyPair(suite.deriveKeypair(secretKey), suite);
|
|
57
|
+
return readKeyPair(suite.deriveKeypair(secretKey), suite, [secretKey]);
|
|
68
58
|
},
|
|
69
59
|
deriveKeyPairWithProvider(provider, algorithm, secretKey) {
|
|
70
60
|
ensureBytes(secretKey, X_WING_SECRET_KEY_LENGTH);
|
|
71
61
|
const suite = xWingSuiteWithProvider(algorithm, provider);
|
|
72
|
-
return readKeyPair(suite.deriveKeypair(secretKey), suite);
|
|
62
|
+
return readKeyPair(suite.deriveKeypair(secretKey), suite, [secretKey]);
|
|
73
63
|
},
|
|
74
64
|
encapsulate(algorithm, publicKey) {
|
|
75
65
|
const suite = xWingSuite(algorithm);
|
|
76
66
|
ensureBytes(publicKey, suite.publicKeyLength);
|
|
77
|
-
return readEncapsulation(suite.encapsulate(publicKey), suite);
|
|
67
|
+
return readEncapsulation(suite.encapsulate(publicKey), suite, [publicKey]);
|
|
78
68
|
},
|
|
79
69
|
encapsulateWithProvider(provider, algorithm, publicKey) {
|
|
80
70
|
const suite = xWingSuiteWithProvider(algorithm, provider);
|
|
81
71
|
ensureBytes(publicKey, suite.publicKeyLength);
|
|
82
|
-
return readEncapsulation(suite.encapsulate(publicKey), suite);
|
|
72
|
+
return readEncapsulation(suite.encapsulate(publicKey), suite, [publicKey]);
|
|
83
73
|
},
|
|
84
74
|
decapsulate(algorithm, ciphertext, secretKey) {
|
|
85
75
|
const suite = xWingSuite(algorithm);
|
|
86
76
|
ensureBytes(ciphertext, suite.ciphertextLength);
|
|
87
77
|
ensureBytes(secretKey, X_WING_SECRET_KEY_LENGTH);
|
|
88
|
-
|
|
89
|
-
if (!(sharedSecret instanceof Uint8Array)) {
|
|
90
|
-
throw new ReallyMeCryptoError("provider-failure");
|
|
91
|
-
}
|
|
92
|
-
ensureBytes(sharedSecret, X_WING_SHARED_SECRET_LENGTH);
|
|
93
|
-
return sharedSecret;
|
|
78
|
+
return readSharedSecret(suite.decapsulate(ciphertext, secretKey), [ciphertext, secretKey]);
|
|
94
79
|
},
|
|
95
80
|
decapsulateWithProvider(provider, algorithm, ciphertext, secretKey) {
|
|
96
81
|
const suite = xWingSuiteWithProvider(algorithm, provider);
|
|
97
82
|
ensureBytes(ciphertext, suite.ciphertextLength);
|
|
98
83
|
ensureBytes(secretKey, X_WING_SECRET_KEY_LENGTH);
|
|
99
|
-
|
|
100
|
-
if (!(sharedSecret instanceof Uint8Array)) {
|
|
101
|
-
throw new ReallyMeCryptoError("provider-failure");
|
|
102
|
-
}
|
|
103
|
-
ensureBytes(sharedSecret, X_WING_SHARED_SECRET_LENGTH);
|
|
104
|
-
return sharedSecret;
|
|
84
|
+
return readSharedSecret(suite.decapsulate(ciphertext, secretKey), [ciphertext, secretKey]);
|
|
105
85
|
},
|
|
106
86
|
};
|
|
107
|
-
export const encapsulateXWingDeterministicallyForTest = (algorithm, publicKey, seed) => {
|
|
108
|
-
const suite = xWingSuite(algorithm);
|
|
109
|
-
ensureBytes(publicKey, suite.publicKeyLength);
|
|
110
|
-
ensureBytes(seed, X_WING_ENCAPSULATION_SEED_LENGTH);
|
|
111
|
-
return readEncapsulation(suite.encapsulateDerand(publicKey, seed), suite);
|
|
112
|
-
};
|
|
113
|
-
export const encapsulateXWingDeterministicallyWithProviderForTest = (provider, algorithm, publicKey, seed) => {
|
|
114
|
-
const suite = xWingSuiteWithProvider(algorithm, provider);
|
|
115
|
-
ensureBytes(publicKey, suite.publicKeyLength);
|
|
116
|
-
ensureBytes(seed, X_WING_ENCAPSULATION_SEED_LENGTH);
|
|
117
|
-
return readEncapsulation(suite.encapsulateDerand(publicKey, seed), suite);
|
|
118
|
-
};
|
package/package.json
CHANGED
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reallyme/crypto",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "ReallyMe crypto SDK for TypeScript/JavaScript with an explicit, pinned provider set.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/reallyme/crypto.git",
|
|
9
|
+
"directory": "packages/ts"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/reallyme/crypto#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/reallyme/crypto/issues"
|
|
14
|
+
},
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public",
|
|
17
|
+
"registry": "https://registry.npmjs.org/"
|
|
18
|
+
},
|
|
6
19
|
"type": "module",
|
|
7
20
|
"main": "./dist/index.js",
|
|
8
21
|
"types": "./dist/index.d.ts",
|
|
@@ -42,7 +55,7 @@
|
|
|
42
55
|
"@bufbuild/protobuf": "2.12.1",
|
|
43
56
|
"@noble/curves": "2.2.0",
|
|
44
57
|
"@noble/hashes": "2.2.0",
|
|
45
|
-
"@reallyme/codec": "0.
|
|
58
|
+
"@reallyme/codec": "0.2.0"
|
|
46
59
|
},
|
|
47
60
|
"devDependencies": {
|
|
48
61
|
"typescript": "5.8.3"
|