@reallyme/crypto 0.1.8 → 0.3.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/LICENSE +201 -0
- package/README.md +148 -18
- package/dist/aead.d.ts +4 -0
- package/dist/aead.js +40 -16
- package/dist/aesKw.d.ts +8 -2
- package/dist/aesKw.js +69 -12
- package/dist/algorithms.d.ts +12 -4
- package/dist/algorithms.js +8 -2
- package/dist/argon2id.d.ts +3 -0
- package/dist/argon2id.js +18 -3
- package/dist/cryptoFacade.d.ts +66 -5
- package/dist/cryptoFacade.js +99 -38
- package/dist/errors.d.ts +1 -1
- 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 +4 -1
- package/dist/hpke.js +45 -14
- package/dist/index.d.ts +14 -13
- package/dist/index.js +12 -10
- package/dist/jwaConcatKdf.js +8 -4
- package/dist/jwk.d.ts +2 -1
- package/dist/jwk.js +158 -122
- package/dist/kmac.d.ts +11 -0
- package/dist/kmac.js +49 -0
- package/dist/memory.d.ts +8 -0
- package/dist/memory.js +13 -0
- package/dist/mlDsa.d.ts +5 -0
- package/dist/mlDsa.js +43 -9
- package/dist/mlKem.d.ts +5 -2
- package/dist/mlKem.js +37 -26
- package/dist/operationResponse.d.ts +16 -0
- package/dist/operationResponse.js +46 -0
- package/dist/p256Ecdh.js +5 -1
- package/dist/p384Ecdh.js +5 -1
- package/dist/p521Ecdh.js +5 -1
- package/dist/pbkdf2.d.ts +6 -8
- package/dist/pbkdf2.js +12 -12
- package/dist/proto/generated/reallyme/crypto/v1/crypto_pb.d.ts +2859 -128
- package/dist/proto/generated/reallyme/crypto/v1/crypto_pb.js +992 -132
- package/dist/proto.d.ts +99 -7
- package/dist/proto.js +741 -16
- package/dist/rsa.d.ts +4 -1
- package/dist/rsa.js +23 -16
- package/dist/slhDsa.d.ts +5 -0
- package/dist/slhDsa.js +40 -9
- package/dist/validateBytes.d.ts +7 -1
- package/dist/validateBytes.js +63 -3
- package/dist/wasm/reallyme_crypto_wasm.js +77 -365
- package/dist/wasm/reallyme_crypto_wasm_bg.wasm +0 -0
- package/dist/wasmModuleTypes.d.ts +9 -21
- package/dist/wasmProvider.d.ts +12 -29
- package/dist/wasmProvider.js +25 -43
- package/dist/xWing.d.ts +5 -4
- package/dist/xWing.js +40 -40
- package/package.json +20 -2
- package/dist/codecs.d.ts +0 -35
- package/dist/codecs.js +0 -216
- package/dist/proto/generated/reallyme/codec/v1/codec_pb.d.ts +0 -253
- package/dist/proto/generated/reallyme/codec/v1/codec_pb.js +0 -160
package/dist/wasmProvider.d.ts
CHANGED
|
@@ -1,26 +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
|
|
6
|
-
type
|
|
7
|
-
type BytesToObjectFn = (bytes: Uint8Array) => unknown;
|
|
8
|
-
type StringToBytesFn = (text: string) => unknown;
|
|
9
|
-
type StringToObjectFn = (text: string) => unknown;
|
|
10
|
-
type StringBytesToStringFn = (text: string, bytes: Uint8Array) => unknown;
|
|
6
|
+
type TwoByteArraysFn = (first: Uint8Array, second: Uint8Array) => unknown;
|
|
7
|
+
type KeyWrapFn = TwoByteArraysFn;
|
|
11
8
|
type SignatureSignFn = (secretKey: Uint8Array, message: Uint8Array) => unknown;
|
|
12
9
|
type SignatureVerifyFn = (publicKey: Uint8Array, message: Uint8Array, signature: Uint8Array) => unknown;
|
|
13
10
|
type RsaPkcs1v15VerifyFn = (publicKeyDer: Uint8Array, publicKeyEncoding: number, hashSuite: number, message: Uint8Array, signature: Uint8Array) => unknown;
|
|
14
11
|
type RsaPssVerifyFn = (publicKeyDer: Uint8Array, publicKeyEncoding: number, messageHashSuite: number, mgf1HashSuite: number, saltLength: number, message: Uint8Array, signature: Uint8Array) => unknown;
|
|
15
12
|
type HpkeOpenFn = (suite: number, recipientSecretKey: Uint8Array, encapsulatedKey: Uint8Array, info: Uint8Array, aad: Uint8Array, ciphertext: Uint8Array) => unknown;
|
|
16
13
|
type HpkeSealFn = (suite: number, recipientPublicKey: Uint8Array, info: Uint8Array, aad: Uint8Array, plaintext: Uint8Array) => unknown;
|
|
17
|
-
type HpkeSealDerandFn = (suite: number, recipientPublicKey: Uint8Array, encapsulationRandomness: Uint8Array, info: Uint8Array, aad: Uint8Array, plaintext: Uint8Array) => unknown;
|
|
18
14
|
type DeriveKeypairFn = (secretKey: Uint8Array) => unknown;
|
|
19
15
|
type SlhDsaDeriveKeypairFn = (skSeed: Uint8Array, skPrf: Uint8Array, pkSeed: Uint8Array) => unknown;
|
|
20
16
|
type EncapsulateFn = (publicKey: Uint8Array) => unknown;
|
|
21
|
-
type EncapsulateDerandFn = (publicKey: Uint8Array, seed: Uint8Array) => unknown;
|
|
22
17
|
type DecapsulateFn = (ciphertext: Uint8Array, secretKey: Uint8Array) => unknown;
|
|
18
|
+
type BytesToBytesFn = (bytes: Uint8Array) => unknown;
|
|
23
19
|
export type ReallyMeWasmProvider = Readonly<{
|
|
20
|
+
processOperationResponse: BytesToBytesFn;
|
|
21
|
+
processOperationResponseJson: BytesToBytesFn;
|
|
24
22
|
aes128GcmSeal: AeadFn;
|
|
25
23
|
aes128GcmOpen: AeadFn;
|
|
26
24
|
aes192GcmSeal: AeadFn;
|
|
@@ -33,22 +31,15 @@ export type ReallyMeWasmProvider = Readonly<{
|
|
|
33
31
|
chacha20Poly1305Open: AeadFn;
|
|
34
32
|
xchacha20Poly1305Seal: AeadFn;
|
|
35
33
|
xchacha20Poly1305Open: AeadFn;
|
|
34
|
+
aes128KwWrapKey: KeyWrapFn;
|
|
35
|
+
aes128KwUnwrapKey: KeyWrapFn;
|
|
36
|
+
aes192KwWrapKey: KeyWrapFn;
|
|
37
|
+
aes192KwUnwrapKey: KeyWrapFn;
|
|
36
38
|
aes256KwWrapKey: KeyWrapFn;
|
|
37
39
|
aes256KwUnwrapKey: KeyWrapFn;
|
|
38
40
|
argon2idDeriveKey: Argon2idFn;
|
|
39
|
-
|
|
40
|
-
base64urlDecode: StringToBytesFn;
|
|
41
|
-
multibaseBase64urlEncode: BytesToStringFn;
|
|
42
|
-
multibaseBase58btcEncode: BytesToStringFn;
|
|
43
|
-
multibaseDecode: StringToBytesFn;
|
|
44
|
-
multicodecPrefixForName: StringToObjectFn;
|
|
45
|
-
multicodecLookupPrefix: BytesToObjectFn;
|
|
46
|
-
multikeyEncode: StringBytesToStringFn;
|
|
47
|
-
multikeyParse: StringToObjectFn;
|
|
48
|
-
dagCborComputeCid: BytesToStringFn;
|
|
49
|
-
dagCborVerifyCid: StringBytesToStringFn;
|
|
41
|
+
kmac256Derive: KmacFn;
|
|
50
42
|
hpkeSealBase: HpkeSealFn;
|
|
51
|
-
hpkeSealBaseDerand: HpkeSealDerandFn;
|
|
52
43
|
hpkeOpenBase: HpkeOpenFn;
|
|
53
44
|
mlDsa44GenerateKeypair: GenerateKeypairFn;
|
|
54
45
|
mlDsa44DeriveKeypair: GenerateKeypairFromSeedFn;
|
|
@@ -65,17 +56,14 @@ export type ReallyMeWasmProvider = Readonly<{
|
|
|
65
56
|
mlKem512GenerateKeypair: GenerateKeypairFn;
|
|
66
57
|
mlKem512DeriveKeypair: GenerateKeypairFromSeedFn;
|
|
67
58
|
mlKem512Encapsulate: EncapsulateFn;
|
|
68
|
-
mlKem512EncapsulateDerand: EncapsulateDerandFn;
|
|
69
59
|
mlKem512Decapsulate: DecapsulateFn;
|
|
70
60
|
mlKem768GenerateKeypair: GenerateKeypairFn;
|
|
71
61
|
mlKem768DeriveKeypair: GenerateKeypairFromSeedFn;
|
|
72
62
|
mlKem768Encapsulate: EncapsulateFn;
|
|
73
|
-
mlKem768EncapsulateDerand: EncapsulateDerandFn;
|
|
74
63
|
mlKem768Decapsulate: DecapsulateFn;
|
|
75
64
|
mlKem1024GenerateKeypair: GenerateKeypairFn;
|
|
76
65
|
mlKem1024DeriveKeypair: GenerateKeypairFromSeedFn;
|
|
77
66
|
mlKem1024Encapsulate: EncapsulateFn;
|
|
78
|
-
mlKem1024EncapsulateDerand: EncapsulateDerandFn;
|
|
79
67
|
mlKem1024Decapsulate: DecapsulateFn;
|
|
80
68
|
slhDsaSha2128sGenerateKeypair: GenerateKeypairFn;
|
|
81
69
|
slhDsaSha2128sDeriveKeypair: SlhDsaDeriveKeypairFn;
|
|
@@ -86,14 +74,9 @@ export type ReallyMeWasmProvider = Readonly<{
|
|
|
86
74
|
xWing768GenerateKeypair: GenerateKeypairFn;
|
|
87
75
|
xWing768DeriveKeypair: DeriveKeypairFn;
|
|
88
76
|
xWing768Encapsulate: EncapsulateFn;
|
|
89
|
-
xWing768EncapsulateDerand: EncapsulateDerandFn;
|
|
90
77
|
xWing768Decapsulate: DecapsulateFn;
|
|
91
|
-
xWing1024GenerateKeypair: GenerateKeypairFn;
|
|
92
|
-
xWing1024DeriveKeypair: DeriveKeypairFn;
|
|
93
|
-
xWing1024Encapsulate: EncapsulateFn;
|
|
94
|
-
xWing1024EncapsulateDerand: EncapsulateDerandFn;
|
|
95
|
-
xWing1024Decapsulate: DecapsulateFn;
|
|
96
78
|
}>;
|
|
79
|
+
export declare const createReallyMeWasmProvider: (module: unknown) => ReallyMeWasmProvider;
|
|
97
80
|
export declare const installReallyMeWasmProvider: (module: unknown) => void;
|
|
98
81
|
export declare const requireReallyMeWasmProvider: () => ReallyMeWasmProvider;
|
|
99
82
|
export {};
|
package/dist/wasmProvider.js
CHANGED
|
@@ -25,13 +25,15 @@ const requireFunction = (module, name) => {
|
|
|
25
25
|
};
|
|
26
26
|
const wasmErrorCode = (error) => {
|
|
27
27
|
switch (error) {
|
|
28
|
-
case
|
|
28
|
+
case 1 /* WasmErrorCode.InvalidInput */:
|
|
29
29
|
return "invalid-input";
|
|
30
|
-
case
|
|
30
|
+
case 2 /* WasmErrorCode.InvalidSignature */:
|
|
31
31
|
return "invalid-signature";
|
|
32
|
-
case
|
|
32
|
+
case 3 /* WasmErrorCode.AuthenticationFailed */:
|
|
33
|
+
return "authentication-failed";
|
|
34
|
+
case 5 /* WasmErrorCode.UnsupportedAlgorithm */:
|
|
33
35
|
return "unsupported-algorithm";
|
|
34
|
-
case
|
|
36
|
+
case 4 /* WasmErrorCode.ProviderFailure */:
|
|
35
37
|
default:
|
|
36
38
|
return "provider-failure";
|
|
37
39
|
}
|
|
@@ -48,18 +50,6 @@ const function2 = (module, name) => {
|
|
|
48
50
|
const callable = requireFunction(module, name);
|
|
49
51
|
return (first, second) => callable(first, second);
|
|
50
52
|
};
|
|
51
|
-
const stringFunction1 = (module, name) => {
|
|
52
|
-
const callable = requireFunction(module, name);
|
|
53
|
-
return (text) => callable(text);
|
|
54
|
-
};
|
|
55
|
-
const bytesFunction1 = (module, name) => {
|
|
56
|
-
const callable = requireFunction(module, name);
|
|
57
|
-
return (bytes) => callable(bytes);
|
|
58
|
-
};
|
|
59
|
-
const stringBytesFunction2 = (module, name) => {
|
|
60
|
-
const callable = requireFunction(module, name);
|
|
61
|
-
return (text, bytes) => callable(text, bytes);
|
|
62
|
-
};
|
|
63
53
|
const function3 = (module, name) => {
|
|
64
54
|
const callable = requireFunction(module, name);
|
|
65
55
|
return (first, second, third) => callable(first, second, third);
|
|
@@ -76,13 +66,13 @@ const argon2idFunction = (module, name) => {
|
|
|
76
66
|
const callable = requireFunction(module, name);
|
|
77
67
|
return (kdfVersion, secret, salt) => callable(kdfVersion, secret, salt);
|
|
78
68
|
};
|
|
79
|
-
const
|
|
69
|
+
const kmacFunction = (module, name) => {
|
|
80
70
|
const callable = requireFunction(module, name);
|
|
81
|
-
return (
|
|
71
|
+
return (key, context, customization, outputLength) => callable(key, context, customization, outputLength);
|
|
82
72
|
};
|
|
83
|
-
const
|
|
73
|
+
const hpkeSealFunction = (module, name) => {
|
|
84
74
|
const callable = requireFunction(module, name);
|
|
85
|
-
return (suite, recipientPublicKey,
|
|
75
|
+
return (suite, recipientPublicKey, info, aad, plaintext) => callable(suite, recipientPublicKey, info, aad, plaintext);
|
|
86
76
|
};
|
|
87
77
|
const hpkeOpenFunction = (module, name) => {
|
|
88
78
|
const callable = requireFunction(module, name);
|
|
@@ -96,9 +86,11 @@ const rsaPssVerifyFunction = (module, name) => {
|
|
|
96
86
|
const callable = requireFunction(module, name);
|
|
97
87
|
return (publicKeyDer, publicKeyEncoding, messageHashSuite, mgf1HashSuite, saltLength, message, signature) => callable(publicKeyDer, publicKeyEncoding, messageHashSuite, mgf1HashSuite, saltLength, message, signature);
|
|
98
88
|
};
|
|
99
|
-
export const
|
|
89
|
+
export const createReallyMeWasmProvider = (module) => {
|
|
100
90
|
const providerModule = requireObject(module);
|
|
101
|
-
|
|
91
|
+
return {
|
|
92
|
+
processOperationResponse: function1(providerModule, "processOperationResponse"),
|
|
93
|
+
processOperationResponseJson: function1(providerModule, "processOperationResponseJson"),
|
|
102
94
|
aes128GcmSeal: function4(providerModule, "aes128GcmSeal"),
|
|
103
95
|
aes128GcmOpen: function4(providerModule, "aes128GcmOpen"),
|
|
104
96
|
aes192GcmSeal: function4(providerModule, "aes192GcmSeal"),
|
|
@@ -111,22 +103,15 @@ export const installReallyMeWasmProvider = (module) => {
|
|
|
111
103
|
chacha20Poly1305Open: function4(providerModule, "chacha20Poly1305Open"),
|
|
112
104
|
xchacha20Poly1305Seal: function4(providerModule, "xchacha20Poly1305Seal"),
|
|
113
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"),
|
|
114
110
|
aes256KwWrapKey: function2(providerModule, "aes256KwWrapKey"),
|
|
115
111
|
aes256KwUnwrapKey: function2(providerModule, "aes256KwUnwrapKey"),
|
|
116
112
|
argon2idDeriveKey: argon2idFunction(providerModule, "argon2idDeriveKey"),
|
|
117
|
-
|
|
118
|
-
base64urlDecode: stringFunction1(providerModule, "base64urlDecode"),
|
|
119
|
-
multibaseBase64urlEncode: bytesFunction1(providerModule, "multibaseBase64urlEncode"),
|
|
120
|
-
multibaseBase58btcEncode: bytesFunction1(providerModule, "multibaseBase58btcEncode"),
|
|
121
|
-
multibaseDecode: stringFunction1(providerModule, "multibaseDecode"),
|
|
122
|
-
multicodecPrefixForName: stringFunction1(providerModule, "multicodecPrefixForName"),
|
|
123
|
-
multicodecLookupPrefix: bytesFunction1(providerModule, "multicodecLookupPrefix"),
|
|
124
|
-
multikeyEncode: stringBytesFunction2(providerModule, "multikeyEncode"),
|
|
125
|
-
multikeyParse: stringFunction1(providerModule, "multikeyParse"),
|
|
126
|
-
dagCborComputeCid: bytesFunction1(providerModule, "dagCborComputeCid"),
|
|
127
|
-
dagCborVerifyCid: stringBytesFunction2(providerModule, "dagCborVerifyCid"),
|
|
113
|
+
kmac256Derive: kmacFunction(providerModule, "kmac256Derive"),
|
|
128
114
|
hpkeSealBase: hpkeSealFunction(providerModule, "hpkeSealBase"),
|
|
129
|
-
hpkeSealBaseDerand: hpkeSealDerandFunction(providerModule, "hpkeSealBaseDerand"),
|
|
130
115
|
hpkeOpenBase: hpkeOpenFunction(providerModule, "hpkeOpenBase"),
|
|
131
116
|
mlDsa44GenerateKeypair: function0(providerModule, "mlDsa44GenerateKeypair"),
|
|
132
117
|
mlDsa44DeriveKeypair: function1(providerModule, "mlDsa44DeriveKeypair"),
|
|
@@ -143,17 +128,14 @@ export const installReallyMeWasmProvider = (module) => {
|
|
|
143
128
|
mlKem512GenerateKeypair: function0(providerModule, "mlKem512GenerateKeypair"),
|
|
144
129
|
mlKem512DeriveKeypair: function1(providerModule, "mlKem512DeriveKeypair"),
|
|
145
130
|
mlKem512Encapsulate: function1(providerModule, "mlKem512Encapsulate"),
|
|
146
|
-
mlKem512EncapsulateDerand: function2(providerModule, "mlKem512EncapsulateDerand"),
|
|
147
131
|
mlKem512Decapsulate: function2(providerModule, "mlKem512Decapsulate"),
|
|
148
132
|
mlKem768GenerateKeypair: function0(providerModule, "mlKem768GenerateKeypair"),
|
|
149
133
|
mlKem768DeriveKeypair: function1(providerModule, "mlKem768DeriveKeypair"),
|
|
150
134
|
mlKem768Encapsulate: function1(providerModule, "mlKem768Encapsulate"),
|
|
151
|
-
mlKem768EncapsulateDerand: function2(providerModule, "mlKem768EncapsulateDerand"),
|
|
152
135
|
mlKem768Decapsulate: function2(providerModule, "mlKem768Decapsulate"),
|
|
153
136
|
mlKem1024GenerateKeypair: function0(providerModule, "mlKem1024GenerateKeypair"),
|
|
154
137
|
mlKem1024DeriveKeypair: function1(providerModule, "mlKem1024DeriveKeypair"),
|
|
155
138
|
mlKem1024Encapsulate: function1(providerModule, "mlKem1024Encapsulate"),
|
|
156
|
-
mlKem1024EncapsulateDerand: function2(providerModule, "mlKem1024EncapsulateDerand"),
|
|
157
139
|
mlKem1024Decapsulate: function2(providerModule, "mlKem1024Decapsulate"),
|
|
158
140
|
slhDsaSha2128sGenerateKeypair: function0(providerModule, "slhDsaSha2128sGenerateKeypair"),
|
|
159
141
|
slhDsaSha2128sDeriveKeypair: deriveSlhDsaFunction3(providerModule, "slhDsaSha2128sDeriveKeypair"),
|
|
@@ -164,15 +146,15 @@ export const installReallyMeWasmProvider = (module) => {
|
|
|
164
146
|
xWing768GenerateKeypair: function0(providerModule, "xWing768GenerateKeypair"),
|
|
165
147
|
xWing768DeriveKeypair: function1(providerModule, "xWing768DeriveKeypair"),
|
|
166
148
|
xWing768Encapsulate: function1(providerModule, "xWing768Encapsulate"),
|
|
167
|
-
xWing768EncapsulateDerand: function2(providerModule, "xWing768EncapsulateDerand"),
|
|
168
149
|
xWing768Decapsulate: function2(providerModule, "xWing768Decapsulate"),
|
|
169
|
-
xWing1024GenerateKeypair: function0(providerModule, "xWing1024GenerateKeypair"),
|
|
170
|
-
xWing1024DeriveKeypair: function1(providerModule, "xWing1024DeriveKeypair"),
|
|
171
|
-
xWing1024Encapsulate: function1(providerModule, "xWing1024Encapsulate"),
|
|
172
|
-
xWing1024EncapsulateDerand: function2(providerModule, "xWing1024EncapsulateDerand"),
|
|
173
|
-
xWing1024Decapsulate: function2(providerModule, "xWing1024Decapsulate"),
|
|
174
150
|
};
|
|
175
151
|
};
|
|
152
|
+
export const installReallyMeWasmProvider = (module) => {
|
|
153
|
+
if (installedProvider !== undefined) {
|
|
154
|
+
throw new ReallyMeCryptoError("provider-failure");
|
|
155
|
+
}
|
|
156
|
+
installedProvider = createReallyMeWasmProvider(module);
|
|
157
|
+
};
|
|
176
158
|
export const requireReallyMeWasmProvider = () => {
|
|
177
159
|
if (installedProvider === undefined) {
|
|
178
160
|
throw new ReallyMeCryptoError("provider-failure");
|
package/dist/xWing.d.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import type { ReallyMeKemAlgorithm } from "./algorithms.js";
|
|
2
|
+
import type { ReallyMeWasmProvider } from "./wasmProvider.js";
|
|
2
3
|
export declare const X_WING_SECRET_KEY_LENGTH = 32;
|
|
3
|
-
export declare const X_WING_ENCAPSULATION_SEED_LENGTH = 64;
|
|
4
4
|
export declare const X_WING_SHARED_SECRET_LENGTH = 32;
|
|
5
5
|
export declare const X_WING_768_PUBLIC_KEY_LENGTH = 1216;
|
|
6
6
|
export declare const X_WING_768_CIPHERTEXT_LENGTH = 1120;
|
|
7
|
-
export declare const X_WING_1024_PUBLIC_KEY_LENGTH = 1600;
|
|
8
|
-
export declare const X_WING_1024_CIPHERTEXT_LENGTH = 1600;
|
|
9
7
|
export type ReallyMeXWingKeyPair = Readonly<{
|
|
10
8
|
publicKey: Uint8Array;
|
|
11
9
|
secretKey: Uint8Array;
|
|
@@ -16,8 +14,11 @@ export type ReallyMeXWingEncapsulation = Readonly<{
|
|
|
16
14
|
}>;
|
|
17
15
|
export declare const ReallyMeXWing: {
|
|
18
16
|
readonly generateKeyPair: (algorithm: ReallyMeKemAlgorithm) => ReallyMeXWingKeyPair;
|
|
17
|
+
readonly generateKeyPairWithProvider: (provider: ReallyMeWasmProvider, algorithm: ReallyMeKemAlgorithm) => ReallyMeXWingKeyPair;
|
|
19
18
|
readonly deriveKeyPair: (algorithm: ReallyMeKemAlgorithm, secretKey: Uint8Array) => ReallyMeXWingKeyPair;
|
|
19
|
+
readonly deriveKeyPairWithProvider: (provider: ReallyMeWasmProvider, algorithm: ReallyMeKemAlgorithm, secretKey: Uint8Array) => ReallyMeXWingKeyPair;
|
|
20
20
|
readonly encapsulate: (algorithm: ReallyMeKemAlgorithm, publicKey: Uint8Array) => ReallyMeXWingEncapsulation;
|
|
21
|
+
readonly encapsulateWithProvider: (provider: ReallyMeWasmProvider, algorithm: ReallyMeKemAlgorithm, publicKey: Uint8Array) => ReallyMeXWingEncapsulation;
|
|
21
22
|
readonly decapsulate: (algorithm: ReallyMeKemAlgorithm, ciphertext: Uint8Array, secretKey: Uint8Array) => Uint8Array;
|
|
23
|
+
readonly decapsulateWithProvider: (provider: ReallyMeWasmProvider, algorithm: ReallyMeKemAlgorithm, ciphertext: Uint8Array, secretKey: Uint8Array) => Uint8Array;
|
|
22
24
|
};
|
|
23
|
-
export declare const encapsulateXWingDeterministicallyForTest: (algorithm: ReallyMeKemAlgorithm, publicKey: Uint8Array, seed: Uint8Array) => ReallyMeXWingEncapsulation;
|
package/dist/xWing.js
CHANGED
|
@@ -2,85 +2,85 @@
|
|
|
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) => {
|
|
12
|
+
return xWingSuiteWithProvider(algorithm, requireReallyMeWasmProvider());
|
|
13
|
+
};
|
|
14
|
+
const xWingSuiteWithProvider = (algorithm, provider) => {
|
|
15
15
|
switch (algorithm) {
|
|
16
16
|
case "ML-KEM-512":
|
|
17
17
|
case "ML-KEM-768":
|
|
18
18
|
case "ML-KEM-1024":
|
|
19
19
|
throw new ReallyMeCryptoError("unsupported-algorithm");
|
|
20
20
|
case "X-Wing-768": {
|
|
21
|
-
const provider = requireReallyMeWasmProvider();
|
|
22
21
|
return {
|
|
23
22
|
publicKeyLength: X_WING_768_PUBLIC_KEY_LENGTH,
|
|
24
23
|
ciphertextLength: X_WING_768_CIPHERTEXT_LENGTH,
|
|
25
24
|
generateKeypair: provider.xWing768GenerateKeypair,
|
|
26
25
|
deriveKeypair: provider.xWing768DeriveKeypair,
|
|
27
26
|
encapsulate: provider.xWing768Encapsulate,
|
|
28
|
-
encapsulateDerand: provider.xWing768EncapsulateDerand,
|
|
29
27
|
decapsulate: provider.xWing768Decapsulate,
|
|
30
28
|
};
|
|
31
29
|
}
|
|
32
|
-
case "X-Wing-1024": {
|
|
33
|
-
const provider = requireReallyMeWasmProvider();
|
|
34
|
-
return {
|
|
35
|
-
publicKeyLength: X_WING_1024_PUBLIC_KEY_LENGTH,
|
|
36
|
-
ciphertextLength: X_WING_1024_CIPHERTEXT_LENGTH,
|
|
37
|
-
generateKeypair: provider.xWing1024GenerateKeypair,
|
|
38
|
-
deriveKeypair: provider.xWing1024DeriveKeypair,
|
|
39
|
-
encapsulate: provider.xWing1024Encapsulate,
|
|
40
|
-
encapsulateDerand: provider.xWing1024EncapsulateDerand,
|
|
41
|
-
decapsulate: provider.xWing1024Decapsulate,
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
30
|
}
|
|
45
31
|
};
|
|
46
|
-
const readKeyPair = (value, suite) =>
|
|
47
|
-
publicKey
|
|
48
|
-
secretKey
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
+
};
|
|
54
45
|
export const ReallyMeXWing = {
|
|
55
46
|
generateKeyPair(algorithm) {
|
|
56
47
|
const suite = xWingSuite(algorithm);
|
|
57
48
|
return readKeyPair(suite.generateKeypair(), suite);
|
|
58
49
|
},
|
|
50
|
+
generateKeyPairWithProvider(provider, algorithm) {
|
|
51
|
+
const suite = xWingSuiteWithProvider(algorithm, provider);
|
|
52
|
+
return readKeyPair(suite.generateKeypair(), suite);
|
|
53
|
+
},
|
|
59
54
|
deriveKeyPair(algorithm, secretKey) {
|
|
60
55
|
ensureBytes(secretKey, X_WING_SECRET_KEY_LENGTH);
|
|
61
56
|
const suite = xWingSuite(algorithm);
|
|
62
|
-
return readKeyPair(suite.deriveKeypair(secretKey), suite);
|
|
57
|
+
return readKeyPair(suite.deriveKeypair(secretKey), suite, [secretKey]);
|
|
58
|
+
},
|
|
59
|
+
deriveKeyPairWithProvider(provider, algorithm, secretKey) {
|
|
60
|
+
ensureBytes(secretKey, X_WING_SECRET_KEY_LENGTH);
|
|
61
|
+
const suite = xWingSuiteWithProvider(algorithm, provider);
|
|
62
|
+
return readKeyPair(suite.deriveKeypair(secretKey), suite, [secretKey]);
|
|
63
63
|
},
|
|
64
64
|
encapsulate(algorithm, publicKey) {
|
|
65
65
|
const suite = xWingSuite(algorithm);
|
|
66
66
|
ensureBytes(publicKey, suite.publicKeyLength);
|
|
67
|
-
return readEncapsulation(suite.encapsulate(publicKey), suite);
|
|
67
|
+
return readEncapsulation(suite.encapsulate(publicKey), suite, [publicKey]);
|
|
68
|
+
},
|
|
69
|
+
encapsulateWithProvider(provider, algorithm, publicKey) {
|
|
70
|
+
const suite = xWingSuiteWithProvider(algorithm, provider);
|
|
71
|
+
ensureBytes(publicKey, suite.publicKeyLength);
|
|
72
|
+
return readEncapsulation(suite.encapsulate(publicKey), suite, [publicKey]);
|
|
68
73
|
},
|
|
69
74
|
decapsulate(algorithm, ciphertext, secretKey) {
|
|
70
75
|
const suite = xWingSuite(algorithm);
|
|
71
76
|
ensureBytes(ciphertext, suite.ciphertextLength);
|
|
72
77
|
ensureBytes(secretKey, X_WING_SECRET_KEY_LENGTH);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
ensureBytes(
|
|
78
|
-
|
|
78
|
+
return readSharedSecret(suite.decapsulate(ciphertext, secretKey), [ciphertext, secretKey]);
|
|
79
|
+
},
|
|
80
|
+
decapsulateWithProvider(provider, algorithm, ciphertext, secretKey) {
|
|
81
|
+
const suite = xWingSuiteWithProvider(algorithm, provider);
|
|
82
|
+
ensureBytes(ciphertext, suite.ciphertextLength);
|
|
83
|
+
ensureBytes(secretKey, X_WING_SECRET_KEY_LENGTH);
|
|
84
|
+
return readSharedSecret(suite.decapsulate(ciphertext, secretKey), [ciphertext, secretKey]);
|
|
79
85
|
},
|
|
80
|
-
};
|
|
81
|
-
export const encapsulateXWingDeterministicallyForTest = (algorithm, publicKey, seed) => {
|
|
82
|
-
const suite = xWingSuite(algorithm);
|
|
83
|
-
ensureBytes(publicKey, suite.publicKeyLength);
|
|
84
|
-
ensureBytes(seed, X_WING_ENCAPSULATION_SEED_LENGTH);
|
|
85
|
-
return readEncapsulation(suite.encapsulateDerand(publicKey, seed), suite);
|
|
86
86
|
};
|
package/package.json
CHANGED
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reallyme/crypto",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
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",
|
|
@@ -25,19 +38,24 @@
|
|
|
25
38
|
},
|
|
26
39
|
"files": [
|
|
27
40
|
"dist",
|
|
41
|
+
"LICENSE",
|
|
28
42
|
"README.md"
|
|
29
43
|
],
|
|
30
44
|
"scripts": {
|
|
31
45
|
"build": "node scripts/clean-dist.mjs && npm run build:wasm && tsc",
|
|
32
46
|
"build:ts": "tsc",
|
|
33
47
|
"build:wasm": "node scripts/build-wasm.mjs",
|
|
48
|
+
"pack:check": "node scripts/check-pack.mjs",
|
|
49
|
+
"prepack": "npm run build",
|
|
50
|
+
"prepublishOnly": "npm test && npm run pack:check",
|
|
34
51
|
"typecheck": "tsc --noEmit",
|
|
35
52
|
"test": "npm run build && node --test \"test/*.test.mjs\""
|
|
36
53
|
},
|
|
37
54
|
"dependencies": {
|
|
38
55
|
"@bufbuild/protobuf": "2.12.1",
|
|
39
56
|
"@noble/curves": "2.2.0",
|
|
40
|
-
"@noble/hashes": "2.2.0"
|
|
57
|
+
"@noble/hashes": "2.2.0",
|
|
58
|
+
"@reallyme/codec": "0.2.0"
|
|
41
59
|
},
|
|
42
60
|
"devDependencies": {
|
|
43
61
|
"typescript": "5.8.3"
|
package/dist/codecs.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export type ReallyMeMulticodecTag = "encryption" | "hash" | "key" | "multihash" | "multikey";
|
|
2
|
-
export type ReallyMeKeyMaterialKind = "not-key" | "public-key" | "private-key" | "symmetric-key";
|
|
3
|
-
export type ReallyMeMulticodecMetadata = Readonly<{
|
|
4
|
-
name: string;
|
|
5
|
-
alg: string;
|
|
6
|
-
tag: ReallyMeMulticodecTag;
|
|
7
|
-
keyMaterial: ReallyMeKeyMaterialKind;
|
|
8
|
-
prefix: Uint8Array;
|
|
9
|
-
expectedKeyLength?: number;
|
|
10
|
-
}>;
|
|
11
|
-
export type ReallyMeParsedMultikey = Readonly<{
|
|
12
|
-
codecName: string;
|
|
13
|
-
algorithmName: string;
|
|
14
|
-
publicKey: Uint8Array;
|
|
15
|
-
expectedPublicKeyLength?: number;
|
|
16
|
-
}>;
|
|
17
|
-
export type ReallyMeDagCborCidVerification = Readonly<{
|
|
18
|
-
valid: boolean;
|
|
19
|
-
expectedCid: string;
|
|
20
|
-
actualCid: string;
|
|
21
|
-
}>;
|
|
22
|
-
export declare const ReallyMeCodecs: {
|
|
23
|
-
readonly base64urlEncode: (bytes: Uint8Array) => string;
|
|
24
|
-
readonly base64urlDecode: (encoded: string) => Uint8Array;
|
|
25
|
-
readonly base64urlDecodeBytes: (encoded: Uint8Array) => Uint8Array;
|
|
26
|
-
readonly multibaseBase64urlEncode: (bytes: Uint8Array) => string;
|
|
27
|
-
readonly multibaseBase58btcEncode: (bytes: Uint8Array) => string;
|
|
28
|
-
readonly multibaseDecode: (encoded: string) => Uint8Array;
|
|
29
|
-
readonly multicodecPrefixForName: (codecName: string) => ReallyMeMulticodecMetadata;
|
|
30
|
-
readonly multicodecLookupPrefix: (bytes: Uint8Array) => ReallyMeMulticodecMetadata;
|
|
31
|
-
readonly multikeyEncode: (codecName: string, publicKey: Uint8Array) => string;
|
|
32
|
-
readonly multikeyParse: (multikey: string) => ReallyMeParsedMultikey;
|
|
33
|
-
readonly dagCborComputeCid: (bytes: Uint8Array) => string;
|
|
34
|
-
readonly dagCborVerifyCid: (cid: string, bytes: Uint8Array) => ReallyMeDagCborCidVerification;
|
|
35
|
-
};
|