@reallyme/crypto 0.3.9 → 0.3.11
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 +10 -11
- package/dist/aead.js +1 -1
- package/dist/aesKw.js +1 -1
- package/dist/algorithms.js +1 -1
- package/dist/argon2id.js +1 -1
- package/dist/bip340Schnorr.js +1 -1
- package/dist/cryptoFacade.d.ts +60 -81
- package/dist/cryptoFacade.js +12 -408
- package/dist/cryptoFacadeAsymmetric.d.ts +20 -0
- package/dist/cryptoFacadeAsymmetric.js +252 -0
- package/dist/cryptoFacadeSymmetric.d.ts +27 -0
- package/dist/cryptoFacadeSymmetric.js +166 -0
- package/dist/digest.js +1 -1
- package/dist/ed25519.d.ts +2 -0
- package/dist/ed25519.js +45 -4
- package/dist/encodeEcdsaDer.js +1 -1
- package/dist/errors.js +1 -1
- package/dist/hkdf.js +1 -1
- package/dist/hmac.d.ts +3 -3
- package/dist/hmac.js +8 -5
- package/dist/hpke.d.ts +1 -1
- package/dist/hpke.js +4 -2
- package/dist/index.js +1 -1
- package/dist/jwaConcatKdf.js +1 -1
- package/dist/jwk.js +46 -11
- package/dist/kmac.js +1 -1
- package/dist/memory.js +1 -1
- package/dist/mlDsa.js +1 -1
- package/dist/mlKem.js +1 -1
- package/dist/operationResponse.js +1 -1
- package/dist/p256Ecdh.js +1 -1
- package/dist/p256Ecdsa.js +1 -1
- package/dist/p384Ecdh.js +1 -1
- package/dist/p384Ecdsa.js +1 -1
- package/dist/p521Ecdh.js +1 -1
- package/dist/p521Ecdsa.js +1 -1
- package/dist/pbkdf2.js +12 -4
- package/dist/proto/generated/reallyme/crypto/v1/crypto_pb.js +1 -1
- package/dist/proto.d.ts +8 -117
- package/dist/proto.js +6 -1085
- package/dist/protoAlgorithms.d.ts +21 -0
- package/dist/protoAlgorithms.js +323 -0
- package/dist/protoErrors.d.ts +27 -0
- package/dist/protoErrors.js +275 -0
- package/dist/protoIdentifiers.d.ts +14 -0
- package/dist/protoIdentifiers.js +112 -0
- package/dist/protoJwk.d.ts +10 -0
- package/dist/protoJwk.js +204 -0
- package/dist/protoValues.d.ts +63 -0
- package/dist/protoValues.js +228 -0
- package/dist/providerCatalog.js +1 -1
- package/dist/rsa.js +1 -1
- package/dist/secp256k1.js +1 -1
- package/dist/slhDsa.js +1 -1
- package/dist/validateBytes.js +1 -1
- package/dist/verifyBundledWasmModule.d.ts +63 -0
- package/dist/verifyBundledWasmModule.js +80 -0
- package/dist/wasm/reallyme_crypto_wasm.d.ts +383 -0
- package/dist/wasm/reallyme_crypto_wasm.js +8 -8
- package/dist/wasm/reallyme_crypto_wasm_bg.wasm +0 -0
- package/dist/wasmModuleTypes.js +1 -1
- package/dist/wasmProvider.d.ts +5 -0
- package/dist/wasmProvider.js +61 -3
- package/dist/x25519.js +1 -1
- package/dist/xWing.js +1 -1
- package/package.json +6 -5
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ReallyMeAeadAlgorithm, ReallyMeHashAlgorithm, ReallyMeHpkeSuite, ReallyMeKdfAlgorithm, ReallyMeKemAlgorithm, ReallyMeKeyAgreementAlgorithm, ReallyMeKeyWrapAlgorithm, ReallyMeMacAlgorithm, ReallyMeSignatureAlgorithm } from "./algorithms.js";
|
|
2
|
+
import { AeadAlgorithm, HashAlgorithm, KdfAlgorithm, KemAlgorithm, KeyAgreementAlgorithm, KeyWrapAlgorithm, MacAlgorithm, SignatureAlgorithm } from "./proto/generated/reallyme/crypto/v1/crypto_pb.js";
|
|
3
|
+
import type { HpkeSuiteIdentifier } from "./proto/generated/reallyme/crypto/v1/crypto_pb.js";
|
|
4
|
+
export declare const signatureAlgorithmFromProto: (value: SignatureAlgorithm) => ReallyMeSignatureAlgorithm;
|
|
5
|
+
export declare const signatureAlgorithmToProto: (value: ReallyMeSignatureAlgorithm) => SignatureAlgorithm;
|
|
6
|
+
export declare const hashAlgorithmFromProto: (value: HashAlgorithm) => ReallyMeHashAlgorithm;
|
|
7
|
+
export declare const hashAlgorithmToProto: (value: ReallyMeHashAlgorithm) => HashAlgorithm;
|
|
8
|
+
export declare const aeadAlgorithmFromProto: (value: AeadAlgorithm) => ReallyMeAeadAlgorithm;
|
|
9
|
+
export declare const aeadAlgorithmToProto: (value: ReallyMeAeadAlgorithm) => AeadAlgorithm;
|
|
10
|
+
export declare const kemAlgorithmFromProto: (value: KemAlgorithm) => ReallyMeKemAlgorithm;
|
|
11
|
+
export declare const kemAlgorithmToProto: (value: ReallyMeKemAlgorithm) => KemAlgorithm;
|
|
12
|
+
export declare const keyAgreementAlgorithmFromProto: (value: KeyAgreementAlgorithm) => ReallyMeKeyAgreementAlgorithm;
|
|
13
|
+
export declare const keyAgreementAlgorithmToProto: (value: ReallyMeKeyAgreementAlgorithm) => KeyAgreementAlgorithm;
|
|
14
|
+
export declare const macAlgorithmFromProto: (value: MacAlgorithm) => ReallyMeMacAlgorithm;
|
|
15
|
+
export declare const macAlgorithmToProto: (value: ReallyMeMacAlgorithm) => MacAlgorithm;
|
|
16
|
+
export declare const kdfAlgorithmFromProto: (value: KdfAlgorithm) => ReallyMeKdfAlgorithm;
|
|
17
|
+
export declare const kdfAlgorithmToProto: (value: ReallyMeKdfAlgorithm) => KdfAlgorithm;
|
|
18
|
+
export declare const keyWrapAlgorithmFromProto: (value: KeyWrapAlgorithm) => ReallyMeKeyWrapAlgorithm;
|
|
19
|
+
export declare const keyWrapAlgorithmToProto: (value: ReallyMeKeyWrapAlgorithm) => KeyWrapAlgorithm;
|
|
20
|
+
export declare const hpkeSuiteFromProto: (value: HpkeSuiteIdentifier) => ReallyMeHpkeSuite;
|
|
21
|
+
export declare const hpkeSuiteToProto: (value: ReallyMeHpkeSuite) => HpkeSuiteIdentifier;
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 ReallyMe LLC
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
4
|
+
import { create } from "@bufbuild/protobuf";
|
|
5
|
+
import { ReallyMeCryptoError } from "./errors.js";
|
|
6
|
+
import { AeadAlgorithm, HashAlgorithm, HpkeAeadId, HpkeKdfId, HpkeKemId, HpkeSuiteIdentifierSchema, KdfAlgorithm, KemAlgorithm, KeyAgreementAlgorithm, KeyWrapAlgorithm, MacAlgorithm, SignatureAlgorithm, } from "./proto/generated/reallyme/crypto/v1/crypto_pb.js";
|
|
7
|
+
export const signatureAlgorithmFromProto = (value) => {
|
|
8
|
+
switch (value) {
|
|
9
|
+
case SignatureAlgorithm.ED25519:
|
|
10
|
+
return "Ed25519";
|
|
11
|
+
case SignatureAlgorithm.ECDSA_P256_SHA256:
|
|
12
|
+
return "ECDSA-P256-SHA256";
|
|
13
|
+
case SignatureAlgorithm.ECDSA_P384_SHA384:
|
|
14
|
+
return "ECDSA-P384-SHA384";
|
|
15
|
+
case SignatureAlgorithm.ECDSA_P521_SHA512:
|
|
16
|
+
return "ECDSA-P521-SHA512";
|
|
17
|
+
case SignatureAlgorithm.ECDSA_SECP256K1_SHA256:
|
|
18
|
+
return "ECDSA-secp256k1-SHA256";
|
|
19
|
+
case SignatureAlgorithm.BIP340_SCHNORR_SECP256K1_SHA256:
|
|
20
|
+
return "BIP340-Schnorr-secp256k1-SHA256";
|
|
21
|
+
case SignatureAlgorithm.RSA_PKCS1V15_SHA1:
|
|
22
|
+
return "RSA-PKCS1v15-SHA1";
|
|
23
|
+
case SignatureAlgorithm.RSA_PKCS1V15_SHA256:
|
|
24
|
+
return "RSA-PKCS1v15-SHA256";
|
|
25
|
+
case SignatureAlgorithm.RSA_PKCS1V15_SHA384:
|
|
26
|
+
return "RSA-PKCS1v15-SHA384";
|
|
27
|
+
case SignatureAlgorithm.RSA_PKCS1V15_SHA512:
|
|
28
|
+
return "RSA-PKCS1v15-SHA512";
|
|
29
|
+
case SignatureAlgorithm.RSA_PSS_SHA1_MGF1_SHA1:
|
|
30
|
+
return "RSA-PSS-SHA1-MGF1-SHA1";
|
|
31
|
+
case SignatureAlgorithm.RSA_PSS_SHA256_MGF1_SHA256:
|
|
32
|
+
return "RSA-PSS-SHA256-MGF1-SHA256";
|
|
33
|
+
case SignatureAlgorithm.RSA_PSS_SHA384_MGF1_SHA384:
|
|
34
|
+
return "RSA-PSS-SHA384-MGF1-SHA384";
|
|
35
|
+
case SignatureAlgorithm.RSA_PSS_SHA512_MGF1_SHA512:
|
|
36
|
+
return "RSA-PSS-SHA512-MGF1-SHA512";
|
|
37
|
+
case SignatureAlgorithm.ML_DSA_44:
|
|
38
|
+
return "ML-DSA-44";
|
|
39
|
+
case SignatureAlgorithm.ML_DSA_65:
|
|
40
|
+
return "ML-DSA-65";
|
|
41
|
+
case SignatureAlgorithm.ML_DSA_87:
|
|
42
|
+
return "ML-DSA-87";
|
|
43
|
+
case SignatureAlgorithm.SLH_DSA_SHA2_128S:
|
|
44
|
+
return "SLH-DSA-SHA2-128s";
|
|
45
|
+
default:
|
|
46
|
+
throw new ReallyMeCryptoError("unsupported-algorithm");
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
export const signatureAlgorithmToProto = (value) => {
|
|
50
|
+
switch (value) {
|
|
51
|
+
case "Ed25519":
|
|
52
|
+
return SignatureAlgorithm.ED25519;
|
|
53
|
+
case "ECDSA-P256-SHA256":
|
|
54
|
+
return SignatureAlgorithm.ECDSA_P256_SHA256;
|
|
55
|
+
case "ECDSA-P384-SHA384":
|
|
56
|
+
return SignatureAlgorithm.ECDSA_P384_SHA384;
|
|
57
|
+
case "ECDSA-P521-SHA512":
|
|
58
|
+
return SignatureAlgorithm.ECDSA_P521_SHA512;
|
|
59
|
+
case "ECDSA-secp256k1-SHA256":
|
|
60
|
+
return SignatureAlgorithm.ECDSA_SECP256K1_SHA256;
|
|
61
|
+
case "BIP340-Schnorr-secp256k1-SHA256":
|
|
62
|
+
return SignatureAlgorithm.BIP340_SCHNORR_SECP256K1_SHA256;
|
|
63
|
+
case "RSA-PKCS1v15-SHA1":
|
|
64
|
+
return SignatureAlgorithm.RSA_PKCS1V15_SHA1;
|
|
65
|
+
case "RSA-PKCS1v15-SHA256":
|
|
66
|
+
return SignatureAlgorithm.RSA_PKCS1V15_SHA256;
|
|
67
|
+
case "RSA-PKCS1v15-SHA384":
|
|
68
|
+
return SignatureAlgorithm.RSA_PKCS1V15_SHA384;
|
|
69
|
+
case "RSA-PKCS1v15-SHA512":
|
|
70
|
+
return SignatureAlgorithm.RSA_PKCS1V15_SHA512;
|
|
71
|
+
case "RSA-PSS-SHA1-MGF1-SHA1":
|
|
72
|
+
return SignatureAlgorithm.RSA_PSS_SHA1_MGF1_SHA1;
|
|
73
|
+
case "RSA-PSS-SHA256-MGF1-SHA256":
|
|
74
|
+
return SignatureAlgorithm.RSA_PSS_SHA256_MGF1_SHA256;
|
|
75
|
+
case "RSA-PSS-SHA384-MGF1-SHA384":
|
|
76
|
+
return SignatureAlgorithm.RSA_PSS_SHA384_MGF1_SHA384;
|
|
77
|
+
case "RSA-PSS-SHA512-MGF1-SHA512":
|
|
78
|
+
return SignatureAlgorithm.RSA_PSS_SHA512_MGF1_SHA512;
|
|
79
|
+
case "ML-DSA-44":
|
|
80
|
+
return SignatureAlgorithm.ML_DSA_44;
|
|
81
|
+
case "ML-DSA-65":
|
|
82
|
+
return SignatureAlgorithm.ML_DSA_65;
|
|
83
|
+
case "ML-DSA-87":
|
|
84
|
+
return SignatureAlgorithm.ML_DSA_87;
|
|
85
|
+
case "SLH-DSA-SHA2-128s":
|
|
86
|
+
return SignatureAlgorithm.SLH_DSA_SHA2_128S;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
export const hashAlgorithmFromProto = (value) => {
|
|
90
|
+
switch (value) {
|
|
91
|
+
case HashAlgorithm.SHA2_256:
|
|
92
|
+
return "SHA2-256";
|
|
93
|
+
case HashAlgorithm.SHA2_384:
|
|
94
|
+
return "SHA2-384";
|
|
95
|
+
case HashAlgorithm.SHA2_512:
|
|
96
|
+
return "SHA2-512";
|
|
97
|
+
case HashAlgorithm.SHA3_224:
|
|
98
|
+
return "SHA3-224";
|
|
99
|
+
case HashAlgorithm.SHA3_256:
|
|
100
|
+
return "SHA3-256";
|
|
101
|
+
case HashAlgorithm.SHA3_384:
|
|
102
|
+
return "SHA3-384";
|
|
103
|
+
case HashAlgorithm.SHA3_512:
|
|
104
|
+
return "SHA3-512";
|
|
105
|
+
default:
|
|
106
|
+
throw new ReallyMeCryptoError("unsupported-algorithm");
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
export const hashAlgorithmToProto = (value) => {
|
|
110
|
+
switch (value) {
|
|
111
|
+
case "SHA2-256":
|
|
112
|
+
return HashAlgorithm.SHA2_256;
|
|
113
|
+
case "SHA2-384":
|
|
114
|
+
return HashAlgorithm.SHA2_384;
|
|
115
|
+
case "SHA2-512":
|
|
116
|
+
return HashAlgorithm.SHA2_512;
|
|
117
|
+
case "SHA3-224":
|
|
118
|
+
return HashAlgorithm.SHA3_224;
|
|
119
|
+
case "SHA3-256":
|
|
120
|
+
return HashAlgorithm.SHA3_256;
|
|
121
|
+
case "SHA3-384":
|
|
122
|
+
return HashAlgorithm.SHA3_384;
|
|
123
|
+
case "SHA3-512":
|
|
124
|
+
return HashAlgorithm.SHA3_512;
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
export const aeadAlgorithmFromProto = (value) => {
|
|
128
|
+
switch (value) {
|
|
129
|
+
case AeadAlgorithm.AES_128_GCM:
|
|
130
|
+
return "AES-128-GCM";
|
|
131
|
+
case AeadAlgorithm.AES_192_GCM:
|
|
132
|
+
return "AES-192-GCM";
|
|
133
|
+
case AeadAlgorithm.AES_256_GCM:
|
|
134
|
+
return "AES-256-GCM";
|
|
135
|
+
case AeadAlgorithm.AES_256_GCM_SIV:
|
|
136
|
+
return "AES-256-GCM-SIV";
|
|
137
|
+
case AeadAlgorithm.CHACHA20_POLY1305:
|
|
138
|
+
return "ChaCha20-Poly1305";
|
|
139
|
+
case AeadAlgorithm.XCHACHA20_POLY1305:
|
|
140
|
+
return "XChaCha20-Poly1305";
|
|
141
|
+
default:
|
|
142
|
+
throw new ReallyMeCryptoError("unsupported-algorithm");
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
export const aeadAlgorithmToProto = (value) => {
|
|
146
|
+
switch (value) {
|
|
147
|
+
case "AES-128-GCM":
|
|
148
|
+
return AeadAlgorithm.AES_128_GCM;
|
|
149
|
+
case "AES-192-GCM":
|
|
150
|
+
return AeadAlgorithm.AES_192_GCM;
|
|
151
|
+
case "AES-256-GCM":
|
|
152
|
+
return AeadAlgorithm.AES_256_GCM;
|
|
153
|
+
case "AES-256-GCM-SIV":
|
|
154
|
+
return AeadAlgorithm.AES_256_GCM_SIV;
|
|
155
|
+
case "ChaCha20-Poly1305":
|
|
156
|
+
return AeadAlgorithm.CHACHA20_POLY1305;
|
|
157
|
+
case "XChaCha20-Poly1305":
|
|
158
|
+
return AeadAlgorithm.XCHACHA20_POLY1305;
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
export const kemAlgorithmFromProto = (value) => {
|
|
162
|
+
switch (value) {
|
|
163
|
+
case KemAlgorithm.ML_KEM_512:
|
|
164
|
+
return "ML-KEM-512";
|
|
165
|
+
case KemAlgorithm.ML_KEM_768:
|
|
166
|
+
return "ML-KEM-768";
|
|
167
|
+
case KemAlgorithm.ML_KEM_1024:
|
|
168
|
+
return "ML-KEM-1024";
|
|
169
|
+
case KemAlgorithm.X_WING_768:
|
|
170
|
+
return "X-Wing-768";
|
|
171
|
+
default:
|
|
172
|
+
throw new ReallyMeCryptoError("unsupported-algorithm");
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
export const kemAlgorithmToProto = (value) => {
|
|
176
|
+
switch (value) {
|
|
177
|
+
case "ML-KEM-512":
|
|
178
|
+
return KemAlgorithm.ML_KEM_512;
|
|
179
|
+
case "ML-KEM-768":
|
|
180
|
+
return KemAlgorithm.ML_KEM_768;
|
|
181
|
+
case "ML-KEM-1024":
|
|
182
|
+
return KemAlgorithm.ML_KEM_1024;
|
|
183
|
+
case "X-Wing-768":
|
|
184
|
+
return KemAlgorithm.X_WING_768;
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
export const keyAgreementAlgorithmFromProto = (value) => {
|
|
188
|
+
switch (value) {
|
|
189
|
+
case KeyAgreementAlgorithm.X25519:
|
|
190
|
+
return "X25519";
|
|
191
|
+
case KeyAgreementAlgorithm.P256_ECDH:
|
|
192
|
+
return "P-256-ECDH";
|
|
193
|
+
case KeyAgreementAlgorithm.P384_ECDH:
|
|
194
|
+
return "P-384-ECDH";
|
|
195
|
+
case KeyAgreementAlgorithm.P521_ECDH:
|
|
196
|
+
return "P-521-ECDH";
|
|
197
|
+
default:
|
|
198
|
+
throw new ReallyMeCryptoError("unsupported-algorithm");
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
export const keyAgreementAlgorithmToProto = (value) => {
|
|
202
|
+
switch (value) {
|
|
203
|
+
case "X25519":
|
|
204
|
+
return KeyAgreementAlgorithm.X25519;
|
|
205
|
+
case "P-256-ECDH":
|
|
206
|
+
return KeyAgreementAlgorithm.P256_ECDH;
|
|
207
|
+
case "P-384-ECDH":
|
|
208
|
+
return KeyAgreementAlgorithm.P384_ECDH;
|
|
209
|
+
case "P-521-ECDH":
|
|
210
|
+
return KeyAgreementAlgorithm.P521_ECDH;
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
export const macAlgorithmFromProto = (value) => {
|
|
214
|
+
switch (value) {
|
|
215
|
+
case MacAlgorithm.HMAC_SHA256:
|
|
216
|
+
return "HMAC-SHA-256";
|
|
217
|
+
case MacAlgorithm.HMAC_SHA384:
|
|
218
|
+
return "HMAC-SHA-384";
|
|
219
|
+
case MacAlgorithm.HMAC_SHA512:
|
|
220
|
+
return "HMAC-SHA-512";
|
|
221
|
+
default:
|
|
222
|
+
throw new ReallyMeCryptoError("unsupported-algorithm");
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
export const macAlgorithmToProto = (value) => {
|
|
226
|
+
switch (value) {
|
|
227
|
+
case "HMAC-SHA-256":
|
|
228
|
+
return MacAlgorithm.HMAC_SHA256;
|
|
229
|
+
case "HMAC-SHA-384":
|
|
230
|
+
return MacAlgorithm.HMAC_SHA384;
|
|
231
|
+
case "HMAC-SHA-512":
|
|
232
|
+
return MacAlgorithm.HMAC_SHA512;
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
export const kdfAlgorithmFromProto = (value) => {
|
|
236
|
+
switch (value) {
|
|
237
|
+
case KdfAlgorithm.HKDF_SHA256:
|
|
238
|
+
return "HKDF-SHA256";
|
|
239
|
+
case KdfAlgorithm.HKDF_SHA384:
|
|
240
|
+
return "HKDF-SHA384";
|
|
241
|
+
case KdfAlgorithm.KMAC_256:
|
|
242
|
+
return "KMAC256";
|
|
243
|
+
case KdfAlgorithm.ARGON2ID:
|
|
244
|
+
return "Argon2id";
|
|
245
|
+
case KdfAlgorithm.PBKDF2_HMAC_SHA256:
|
|
246
|
+
return "PBKDF2-HMAC-SHA-256";
|
|
247
|
+
case KdfAlgorithm.PBKDF2_HMAC_SHA512:
|
|
248
|
+
return "PBKDF2-HMAC-SHA-512";
|
|
249
|
+
case KdfAlgorithm.JWA_CONCAT_KDF_SHA256:
|
|
250
|
+
return "JWA-CONCAT-KDF-SHA256";
|
|
251
|
+
default:
|
|
252
|
+
throw new ReallyMeCryptoError("unsupported-algorithm");
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
export const kdfAlgorithmToProto = (value) => {
|
|
256
|
+
switch (value) {
|
|
257
|
+
case "HKDF-SHA256":
|
|
258
|
+
return KdfAlgorithm.HKDF_SHA256;
|
|
259
|
+
case "HKDF-SHA384":
|
|
260
|
+
return KdfAlgorithm.HKDF_SHA384;
|
|
261
|
+
case "KMAC256":
|
|
262
|
+
return KdfAlgorithm.KMAC_256;
|
|
263
|
+
case "Argon2id":
|
|
264
|
+
return KdfAlgorithm.ARGON2ID;
|
|
265
|
+
case "PBKDF2-HMAC-SHA-256":
|
|
266
|
+
return KdfAlgorithm.PBKDF2_HMAC_SHA256;
|
|
267
|
+
case "PBKDF2-HMAC-SHA-512":
|
|
268
|
+
return KdfAlgorithm.PBKDF2_HMAC_SHA512;
|
|
269
|
+
case "JWA-CONCAT-KDF-SHA256":
|
|
270
|
+
return KdfAlgorithm.JWA_CONCAT_KDF_SHA256;
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
export const keyWrapAlgorithmFromProto = (value) => {
|
|
274
|
+
switch (value) {
|
|
275
|
+
case KeyWrapAlgorithm.AES_128_KW:
|
|
276
|
+
return "AES-128-KW";
|
|
277
|
+
case KeyWrapAlgorithm.AES_192_KW:
|
|
278
|
+
return "AES-192-KW";
|
|
279
|
+
case KeyWrapAlgorithm.AES_256_KW:
|
|
280
|
+
return "AES-256-KW";
|
|
281
|
+
default:
|
|
282
|
+
throw new ReallyMeCryptoError("unsupported-algorithm");
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
export const keyWrapAlgorithmToProto = (value) => {
|
|
286
|
+
switch (value) {
|
|
287
|
+
case "AES-128-KW":
|
|
288
|
+
return KeyWrapAlgorithm.AES_128_KW;
|
|
289
|
+
case "AES-192-KW":
|
|
290
|
+
return KeyWrapAlgorithm.AES_192_KW;
|
|
291
|
+
case "AES-256-KW":
|
|
292
|
+
return KeyWrapAlgorithm.AES_256_KW;
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
export const hpkeSuiteFromProto = (value) => {
|
|
296
|
+
if (value.kem === HpkeKemId.DHKEM_P256_HKDF_SHA256 &&
|
|
297
|
+
value.kdf === HpkeKdfId.HKDF_SHA256 &&
|
|
298
|
+
value.aead === HpkeAeadId.AES_256_GCM) {
|
|
299
|
+
return "DHKEM-P256-HKDF-SHA256-HKDF-SHA256-AES-256-GCM";
|
|
300
|
+
}
|
|
301
|
+
if (value.kem === HpkeKemId.DHKEM_X25519_HKDF_SHA256 &&
|
|
302
|
+
value.kdf === HpkeKdfId.HKDF_SHA256 &&
|
|
303
|
+
value.aead === HpkeAeadId.CHACHA20_POLY1305) {
|
|
304
|
+
return "DHKEM-X25519-HKDF-SHA256-HKDF-SHA256-CHACHA20-POLY1305";
|
|
305
|
+
}
|
|
306
|
+
throw new ReallyMeCryptoError("unsupported-algorithm");
|
|
307
|
+
};
|
|
308
|
+
export const hpkeSuiteToProto = (value) => {
|
|
309
|
+
switch (value) {
|
|
310
|
+
case "DHKEM-P256-HKDF-SHA256-HKDF-SHA256-AES-256-GCM":
|
|
311
|
+
return create(HpkeSuiteIdentifierSchema, {
|
|
312
|
+
kem: HpkeKemId.DHKEM_P256_HKDF_SHA256,
|
|
313
|
+
kdf: HpkeKdfId.HKDF_SHA256,
|
|
314
|
+
aead: HpkeAeadId.AES_256_GCM,
|
|
315
|
+
});
|
|
316
|
+
case "DHKEM-X25519-HKDF-SHA256-HKDF-SHA256-CHACHA20-POLY1305":
|
|
317
|
+
return create(HpkeSuiteIdentifierSchema, {
|
|
318
|
+
kem: HpkeKemId.DHKEM_X25519_HKDF_SHA256,
|
|
319
|
+
kdf: HpkeKdfId.HKDF_SHA256,
|
|
320
|
+
aead: HpkeAeadId.CHACHA20_POLY1305,
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ReallyMeCryptoError } from "./errors.js";
|
|
2
|
+
import { CryptoErrorReason } from "./proto/generated/reallyme/crypto/v1/crypto_pb.js";
|
|
3
|
+
import type { CryptoError } from "./proto/generated/reallyme/crypto/v1/crypto_pb.js";
|
|
4
|
+
export type ReallyMeCryptoWireErrorBranch = "primitive" | "provider" | "backend";
|
|
5
|
+
export type ReallyMeCryptoWireError = Readonly<{
|
|
6
|
+
branch: ReallyMeCryptoWireErrorBranch;
|
|
7
|
+
reason: CryptoErrorReason;
|
|
8
|
+
reasonCode?: number;
|
|
9
|
+
}>;
|
|
10
|
+
export type ReallyMeCryptoWireErrorValidationCode = "unspecified-reason" | "branch-reason-mismatch" | "reason-code-out-of-range";
|
|
11
|
+
export type ReallyMeCryptoWireErrorValidationResult = Readonly<{
|
|
12
|
+
ok: true;
|
|
13
|
+
value: ReallyMeCryptoWireError;
|
|
14
|
+
}> | Readonly<{
|
|
15
|
+
ok: false;
|
|
16
|
+
error: ReallyMeCryptoWireErrorValidationCode;
|
|
17
|
+
}>;
|
|
18
|
+
export declare const cryptoWireErrorToProto: (error: ReallyMeCryptoWireError) => CryptoError;
|
|
19
|
+
export declare const cryptoWireErrorFromProto: (value: CryptoError) => ReallyMeCryptoWireError;
|
|
20
|
+
export declare const cryptoWireErrorToProtoBytes: (error: ReallyMeCryptoWireError) => Uint8Array;
|
|
21
|
+
export declare const cryptoWireErrorFromProtoBytes: (bytes: Uint8Array) => ReallyMeCryptoWireError;
|
|
22
|
+
export declare const cryptoWireErrorTryNew: (branch: ReallyMeCryptoWireErrorBranch, reason: CryptoErrorReason) => ReallyMeCryptoWireErrorValidationResult;
|
|
23
|
+
export declare const cryptoWireErrorToFacadeError: (error: ReallyMeCryptoWireError) => ReallyMeCryptoError;
|
|
24
|
+
export declare const cryptoErrorToProto: (error: ReallyMeCryptoError) => CryptoError;
|
|
25
|
+
export declare const cryptoErrorToProtoBytes: (error: ReallyMeCryptoError) => Uint8Array;
|
|
26
|
+
export declare const cryptoErrorFromProto: (value: CryptoError) => ReallyMeCryptoError;
|
|
27
|
+
export declare const cryptoErrorFromProtoBytes: (bytes: Uint8Array) => ReallyMeCryptoError;
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2026 ReallyMe LLC
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
4
|
+
import { create, fromBinary, toBinary } from "@bufbuild/protobuf";
|
|
5
|
+
import { ReallyMeCryptoError } from "./errors.js";
|
|
6
|
+
import { CryptoBackendErrorSchema, CryptoErrorReason, CryptoErrorSchema, CryptoPrimitiveErrorSchema, CryptoProviderErrorSchema, } from "./proto/generated/reallyme/crypto/v1/crypto_pb.js";
|
|
7
|
+
const cryptoErrorReasonToFacadeError = (reason) => {
|
|
8
|
+
switch (reason) {
|
|
9
|
+
case CryptoErrorReason.PRIMITIVE_INVALID_SIGNATURE:
|
|
10
|
+
case CryptoErrorReason.PRIMITIVE_VERIFICATION_FAILED:
|
|
11
|
+
return new ReallyMeCryptoError("invalid-signature");
|
|
12
|
+
case CryptoErrorReason.PROVIDER_UNSUPPORTED_ALGORITHM:
|
|
13
|
+
case CryptoErrorReason.PROVIDER_UNSUPPORTED_BACKEND:
|
|
14
|
+
return new ReallyMeCryptoError("unsupported-algorithm");
|
|
15
|
+
case CryptoErrorReason.PROVIDER_UNAVAILABLE:
|
|
16
|
+
case CryptoErrorReason.PROVIDER_RANDOMNESS_UNAVAILABLE:
|
|
17
|
+
case CryptoErrorReason.PROVIDER_KEY_EXISTS:
|
|
18
|
+
case CryptoErrorReason.PROVIDER_KEY_NOT_FOUND:
|
|
19
|
+
case CryptoErrorReason.PROVIDER_ACCESS_DENIED:
|
|
20
|
+
case CryptoErrorReason.PROVIDER_USER_AUTHENTICATION_REQUIRED:
|
|
21
|
+
case CryptoErrorReason.PROVIDER_USER_CANCELED:
|
|
22
|
+
case CryptoErrorReason.PROVIDER_HARDWARE_UNAVAILABLE:
|
|
23
|
+
case CryptoErrorReason.PROVIDER_HARDWARE_REJECTED_KEY:
|
|
24
|
+
case CryptoErrorReason.BACKEND_INVALID_STATE:
|
|
25
|
+
case CryptoErrorReason.BACKEND_INTERNAL:
|
|
26
|
+
return new ReallyMeCryptoError("provider-failure");
|
|
27
|
+
case CryptoErrorReason.PRIMITIVE_INVALID_PARAMETER:
|
|
28
|
+
case CryptoErrorReason.PRIMITIVE_INVALID_LENGTH:
|
|
29
|
+
case CryptoErrorReason.PRIMITIVE_INVALID_KEY:
|
|
30
|
+
case CryptoErrorReason.PRIMITIVE_INVALID_PUBLIC_KEY:
|
|
31
|
+
case CryptoErrorReason.PRIMITIVE_INVALID_PRIVATE_KEY:
|
|
32
|
+
case CryptoErrorReason.PRIMITIVE_INVALID_NONCE:
|
|
33
|
+
case CryptoErrorReason.PRIMITIVE_INVALID_SALT:
|
|
34
|
+
case CryptoErrorReason.PRIMITIVE_INVALID_PASSWORD:
|
|
35
|
+
case CryptoErrorReason.PRIMITIVE_INVALID_ENCODING:
|
|
36
|
+
case CryptoErrorReason.PRIMITIVE_INVALID_SHARED_SECRET:
|
|
37
|
+
case CryptoErrorReason.PRIMITIVE_MALFORMED_CIPHERTEXT:
|
|
38
|
+
case CryptoErrorReason.PRIMITIVE_INVALID_TAG:
|
|
39
|
+
case CryptoErrorReason.PRIMITIVE_MALFORMED_PROTOBUF:
|
|
40
|
+
case CryptoErrorReason.PRIMITIVE_MALFORMED_JSON:
|
|
41
|
+
case CryptoErrorReason.PRIMITIVE_RESOURCE_LIMIT_EXCEEDED:
|
|
42
|
+
case CryptoErrorReason.PRIMITIVE_MISSING_OPERATION:
|
|
43
|
+
return new ReallyMeCryptoError("invalid-input");
|
|
44
|
+
case CryptoErrorReason.PRIMITIVE_AUTHENTICATION_FAILED:
|
|
45
|
+
return new ReallyMeCryptoError("authentication-failed");
|
|
46
|
+
default:
|
|
47
|
+
return new ReallyMeCryptoError("invalid-input");
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const invalidInputReasons = new Set([
|
|
51
|
+
CryptoErrorReason.PRIMITIVE_INVALID_PARAMETER,
|
|
52
|
+
CryptoErrorReason.PRIMITIVE_INVALID_LENGTH,
|
|
53
|
+
CryptoErrorReason.PRIMITIVE_INVALID_KEY,
|
|
54
|
+
CryptoErrorReason.PRIMITIVE_INVALID_PUBLIC_KEY,
|
|
55
|
+
CryptoErrorReason.PRIMITIVE_INVALID_PRIVATE_KEY,
|
|
56
|
+
CryptoErrorReason.PRIMITIVE_INVALID_NONCE,
|
|
57
|
+
CryptoErrorReason.PRIMITIVE_INVALID_SALT,
|
|
58
|
+
CryptoErrorReason.PRIMITIVE_INVALID_PASSWORD,
|
|
59
|
+
CryptoErrorReason.PRIMITIVE_INVALID_ENCODING,
|
|
60
|
+
CryptoErrorReason.PRIMITIVE_INVALID_SHARED_SECRET,
|
|
61
|
+
CryptoErrorReason.PRIMITIVE_MALFORMED_CIPHERTEXT,
|
|
62
|
+
CryptoErrorReason.PRIMITIVE_INVALID_TAG,
|
|
63
|
+
CryptoErrorReason.PRIMITIVE_MALFORMED_PROTOBUF,
|
|
64
|
+
CryptoErrorReason.PRIMITIVE_MALFORMED_JSON,
|
|
65
|
+
CryptoErrorReason.PRIMITIVE_RESOURCE_LIMIT_EXCEEDED,
|
|
66
|
+
CryptoErrorReason.PRIMITIVE_MISSING_OPERATION,
|
|
67
|
+
]);
|
|
68
|
+
export const cryptoWireErrorToProto = (error) => {
|
|
69
|
+
switch (error.branch) {
|
|
70
|
+
case "primitive":
|
|
71
|
+
return create(CryptoErrorSchema, {
|
|
72
|
+
error: {
|
|
73
|
+
case: "primitive",
|
|
74
|
+
value: create(CryptoPrimitiveErrorSchema, {
|
|
75
|
+
reason: error.reason,
|
|
76
|
+
}),
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
case "provider":
|
|
80
|
+
return create(CryptoErrorSchema, {
|
|
81
|
+
error: {
|
|
82
|
+
case: "provider",
|
|
83
|
+
value: create(CryptoProviderErrorSchema, {
|
|
84
|
+
reason: error.reason,
|
|
85
|
+
}),
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
case "backend":
|
|
89
|
+
return create(CryptoErrorSchema, {
|
|
90
|
+
error: {
|
|
91
|
+
case: "backend",
|
|
92
|
+
value: create(CryptoBackendErrorSchema, {
|
|
93
|
+
reason: error.reason,
|
|
94
|
+
}),
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
export const cryptoWireErrorFromProto = (value) => {
|
|
100
|
+
switch (value.error.case) {
|
|
101
|
+
case "primitive":
|
|
102
|
+
return strictCryptoWireError("primitive", value.error.value.reason);
|
|
103
|
+
case "provider":
|
|
104
|
+
return strictCryptoWireError("provider", value.error.value.reason);
|
|
105
|
+
case "backend":
|
|
106
|
+
return strictCryptoWireError("backend", value.error.value.reason);
|
|
107
|
+
default:
|
|
108
|
+
return malformedCryptoErrorEnvelope();
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
export const cryptoWireErrorToProtoBytes = (error) => toBinary(CryptoErrorSchema, cryptoWireErrorToProto(error));
|
|
112
|
+
export const cryptoWireErrorFromProtoBytes = (bytes) => {
|
|
113
|
+
try {
|
|
114
|
+
return cryptoWireErrorFromProto(fromBinary(CryptoErrorSchema, bytes));
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
return malformedCryptoErrorEnvelope();
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
const strictCryptoWireError = (branch, reason) => {
|
|
121
|
+
const result = cryptoWireErrorTryNew(branch, reason);
|
|
122
|
+
return result.ok ? result.value : malformedCryptoErrorEnvelope();
|
|
123
|
+
};
|
|
124
|
+
export const cryptoWireErrorTryNew = (branch, reason) => {
|
|
125
|
+
if (reason === CryptoErrorReason.UNSPECIFIED) {
|
|
126
|
+
return { ok: false, error: "unspecified-reason" };
|
|
127
|
+
}
|
|
128
|
+
if (knownCryptoErrorReasons.has(reason) && !cryptoErrorReasonMatchesBranch(branch, reason)) {
|
|
129
|
+
return { ok: false, error: "branch-reason-mismatch" };
|
|
130
|
+
}
|
|
131
|
+
if (!cryptoErrorReasonCodeMatchesBranch(branch, reason)) {
|
|
132
|
+
return { ok: false, error: "reason-code-out-of-range" };
|
|
133
|
+
}
|
|
134
|
+
return { ok: true, value: { branch, reason, reasonCode: reason } };
|
|
135
|
+
};
|
|
136
|
+
const malformedCryptoErrorEnvelope = () => ({
|
|
137
|
+
branch: "primitive",
|
|
138
|
+
reason: CryptoErrorReason.PRIMITIVE_MALFORMED_PROTOBUF,
|
|
139
|
+
reasonCode: CryptoErrorReason.PRIMITIVE_MALFORMED_PROTOBUF,
|
|
140
|
+
});
|
|
141
|
+
const cryptoErrorReasonCodeMatchesBranch = (branch, reasonCode) => {
|
|
142
|
+
switch (branch) {
|
|
143
|
+
case "primitive":
|
|
144
|
+
return reasonCode >= 100 && reasonCode <= 199;
|
|
145
|
+
case "provider":
|
|
146
|
+
return reasonCode >= 200 && reasonCode <= 299;
|
|
147
|
+
case "backend":
|
|
148
|
+
return reasonCode >= 300 && reasonCode <= 399;
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
const cryptoErrorReasonMatchesBranch = (branch, reason) => {
|
|
152
|
+
switch (branch) {
|
|
153
|
+
case "primitive":
|
|
154
|
+
return primitiveCryptoErrorReasons.has(reason);
|
|
155
|
+
case "provider":
|
|
156
|
+
return providerCryptoErrorReasons.has(reason);
|
|
157
|
+
case "backend":
|
|
158
|
+
return backendCryptoErrorReasons.has(reason);
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
const primitiveCryptoErrorReasons = new Set([
|
|
162
|
+
CryptoErrorReason.PRIMITIVE_INVALID_PARAMETER,
|
|
163
|
+
CryptoErrorReason.PRIMITIVE_INVALID_LENGTH,
|
|
164
|
+
CryptoErrorReason.PRIMITIVE_INVALID_KEY,
|
|
165
|
+
CryptoErrorReason.PRIMITIVE_INVALID_PUBLIC_KEY,
|
|
166
|
+
CryptoErrorReason.PRIMITIVE_INVALID_PRIVATE_KEY,
|
|
167
|
+
CryptoErrorReason.PRIMITIVE_INVALID_NONCE,
|
|
168
|
+
CryptoErrorReason.PRIMITIVE_INVALID_SALT,
|
|
169
|
+
CryptoErrorReason.PRIMITIVE_INVALID_PASSWORD,
|
|
170
|
+
CryptoErrorReason.PRIMITIVE_INVALID_ENCODING,
|
|
171
|
+
CryptoErrorReason.PRIMITIVE_INVALID_SIGNATURE,
|
|
172
|
+
CryptoErrorReason.PRIMITIVE_VERIFICATION_FAILED,
|
|
173
|
+
CryptoErrorReason.PRIMITIVE_AUTHENTICATION_FAILED,
|
|
174
|
+
CryptoErrorReason.PRIMITIVE_MALFORMED_CIPHERTEXT,
|
|
175
|
+
CryptoErrorReason.PRIMITIVE_INVALID_TAG,
|
|
176
|
+
CryptoErrorReason.PRIMITIVE_INVALID_SHARED_SECRET,
|
|
177
|
+
CryptoErrorReason.PRIMITIVE_MALFORMED_PROTOBUF,
|
|
178
|
+
CryptoErrorReason.PRIMITIVE_MALFORMED_JSON,
|
|
179
|
+
CryptoErrorReason.PRIMITIVE_RESOURCE_LIMIT_EXCEEDED,
|
|
180
|
+
CryptoErrorReason.PRIMITIVE_MISSING_OPERATION,
|
|
181
|
+
]);
|
|
182
|
+
const providerCryptoErrorReasons = new Set([
|
|
183
|
+
CryptoErrorReason.PROVIDER_UNSUPPORTED_ALGORITHM,
|
|
184
|
+
CryptoErrorReason.PROVIDER_UNSUPPORTED_BACKEND,
|
|
185
|
+
CryptoErrorReason.PROVIDER_UNAVAILABLE,
|
|
186
|
+
CryptoErrorReason.PROVIDER_RANDOMNESS_UNAVAILABLE,
|
|
187
|
+
CryptoErrorReason.PROVIDER_KEY_EXISTS,
|
|
188
|
+
CryptoErrorReason.PROVIDER_KEY_NOT_FOUND,
|
|
189
|
+
CryptoErrorReason.PROVIDER_ACCESS_DENIED,
|
|
190
|
+
CryptoErrorReason.PROVIDER_USER_AUTHENTICATION_REQUIRED,
|
|
191
|
+
CryptoErrorReason.PROVIDER_USER_CANCELED,
|
|
192
|
+
CryptoErrorReason.PROVIDER_HARDWARE_UNAVAILABLE,
|
|
193
|
+
CryptoErrorReason.PROVIDER_HARDWARE_REJECTED_KEY,
|
|
194
|
+
]);
|
|
195
|
+
const backendCryptoErrorReasons = new Set([
|
|
196
|
+
CryptoErrorReason.BACKEND_INVALID_STATE,
|
|
197
|
+
CryptoErrorReason.BACKEND_INTERNAL,
|
|
198
|
+
]);
|
|
199
|
+
const knownCryptoErrorReasons = new Set([
|
|
200
|
+
...primitiveCryptoErrorReasons,
|
|
201
|
+
...providerCryptoErrorReasons,
|
|
202
|
+
...backendCryptoErrorReasons,
|
|
203
|
+
]);
|
|
204
|
+
export const cryptoWireErrorToFacadeError = (error) => {
|
|
205
|
+
if (!knownCryptoErrorReasons.has(error.reason)) {
|
|
206
|
+
return new ReallyMeCryptoError("provider-failure");
|
|
207
|
+
}
|
|
208
|
+
const facadeError = cryptoErrorReasonToFacadeError(error.reason);
|
|
209
|
+
if (facadeError.code !== "invalid-input" || invalidInputReasons.has(error.reason)) {
|
|
210
|
+
return facadeError;
|
|
211
|
+
}
|
|
212
|
+
switch (error.branch) {
|
|
213
|
+
case "primitive":
|
|
214
|
+
return facadeError;
|
|
215
|
+
case "provider":
|
|
216
|
+
case "backend":
|
|
217
|
+
return new ReallyMeCryptoError("provider-failure");
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
export const cryptoErrorToProto = (error) => {
|
|
221
|
+
switch (error.code) {
|
|
222
|
+
case "invalid-input":
|
|
223
|
+
return create(CryptoErrorSchema, {
|
|
224
|
+
error: {
|
|
225
|
+
case: "primitive",
|
|
226
|
+
value: create(CryptoPrimitiveErrorSchema, {
|
|
227
|
+
reason: CryptoErrorReason.PRIMITIVE_INVALID_PARAMETER,
|
|
228
|
+
}),
|
|
229
|
+
},
|
|
230
|
+
});
|
|
231
|
+
case "invalid-signature":
|
|
232
|
+
return create(CryptoErrorSchema, {
|
|
233
|
+
error: {
|
|
234
|
+
case: "primitive",
|
|
235
|
+
value: create(CryptoPrimitiveErrorSchema, {
|
|
236
|
+
reason: CryptoErrorReason.PRIMITIVE_INVALID_SIGNATURE,
|
|
237
|
+
}),
|
|
238
|
+
},
|
|
239
|
+
});
|
|
240
|
+
case "authentication-failed":
|
|
241
|
+
return create(CryptoErrorSchema, {
|
|
242
|
+
error: {
|
|
243
|
+
case: "primitive",
|
|
244
|
+
value: create(CryptoPrimitiveErrorSchema, {
|
|
245
|
+
reason: CryptoErrorReason.PRIMITIVE_AUTHENTICATION_FAILED,
|
|
246
|
+
}),
|
|
247
|
+
},
|
|
248
|
+
});
|
|
249
|
+
case "provider-failure":
|
|
250
|
+
return create(CryptoErrorSchema, {
|
|
251
|
+
error: {
|
|
252
|
+
case: "backend",
|
|
253
|
+
value: create(CryptoBackendErrorSchema, {
|
|
254
|
+
reason: CryptoErrorReason.BACKEND_INTERNAL,
|
|
255
|
+
}),
|
|
256
|
+
},
|
|
257
|
+
});
|
|
258
|
+
case "unsupported-algorithm":
|
|
259
|
+
return create(CryptoErrorSchema, {
|
|
260
|
+
error: {
|
|
261
|
+
case: "provider",
|
|
262
|
+
value: create(CryptoProviderErrorSchema, {
|
|
263
|
+
reason: CryptoErrorReason.PROVIDER_UNSUPPORTED_ALGORITHM,
|
|
264
|
+
}),
|
|
265
|
+
},
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
export const cryptoErrorToProtoBytes = (error) => toBinary(CryptoErrorSchema, cryptoErrorToProto(error));
|
|
270
|
+
export const cryptoErrorFromProto = (value) => {
|
|
271
|
+
return cryptoWireErrorToFacadeError(cryptoWireErrorFromProto(value));
|
|
272
|
+
};
|
|
273
|
+
export const cryptoErrorFromProtoBytes = (bytes) => {
|
|
274
|
+
return cryptoWireErrorToFacadeError(cryptoWireErrorFromProtoBytes(bytes));
|
|
275
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ReallyMeHpkeSuite, ReallyMeKemAlgorithm, ReallyMeKeyAgreementAlgorithm, ReallyMeSignatureAlgorithm } from "./algorithms.js";
|
|
2
|
+
import { MulticodecKeyAlgorithm } from "./proto/generated/reallyme/crypto/v1/crypto_pb.js";
|
|
3
|
+
import type { CryptoAlgorithmIdentifier } from "./proto/generated/reallyme/crypto/v1/crypto_pb.js";
|
|
4
|
+
export type ReallyMeMulticodecKeyAlgorithm = "ed25519-pub" | "x25519-pub" | "secp256k1-pub" | "p256-pub" | "p384-pub" | "p521-pub" | "ed448-pub" | "rsa-pub" | "mlkem-512-pub" | "mlkem-768-pub" | "mlkem-1024-pub" | "mldsa-44-pub" | "mldsa-65-pub" | "mldsa-87-pub";
|
|
5
|
+
export declare const signatureAlgorithmIdentifierToProto: (value: ReallyMeSignatureAlgorithm) => CryptoAlgorithmIdentifier;
|
|
6
|
+
export declare const keyAgreementAlgorithmIdentifierToProto: (value: ReallyMeKeyAgreementAlgorithm) => CryptoAlgorithmIdentifier;
|
|
7
|
+
export declare const kemAlgorithmIdentifierToProto: (value: ReallyMeKemAlgorithm) => CryptoAlgorithmIdentifier;
|
|
8
|
+
export declare const hpkeSuiteIdentifierToProto: (value: ReallyMeHpkeSuite) => CryptoAlgorithmIdentifier;
|
|
9
|
+
export declare const signatureAlgorithmFromIdentifier: (value: CryptoAlgorithmIdentifier | undefined) => ReallyMeSignatureAlgorithm;
|
|
10
|
+
export declare const keyAgreementAlgorithmFromIdentifier: (value: CryptoAlgorithmIdentifier | undefined) => ReallyMeKeyAgreementAlgorithm;
|
|
11
|
+
export declare const kemAlgorithmFromIdentifier: (value: CryptoAlgorithmIdentifier | undefined) => ReallyMeKemAlgorithm;
|
|
12
|
+
export declare const hpkeSuiteFromIdentifier: (value: CryptoAlgorithmIdentifier | undefined) => ReallyMeHpkeSuite;
|
|
13
|
+
export declare const multicodecKeyAlgorithmFromProto: (value: MulticodecKeyAlgorithm) => ReallyMeMulticodecKeyAlgorithm;
|
|
14
|
+
export declare const multicodecKeyAlgorithmToProto: (value: ReallyMeMulticodecKeyAlgorithm) => MulticodecKeyAlgorithm;
|