@reallyme/crypto 0.1.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.
Files changed (75) hide show
  1. package/README.md +140 -0
  2. package/dist/aead.d.ts +9 -0
  3. package/dist/aead.js +62 -0
  4. package/dist/aesKw.d.ts +10 -0
  5. package/dist/aesKw.js +45 -0
  6. package/dist/algorithms.d.ts +18 -0
  7. package/dist/algorithms.js +64 -0
  8. package/dist/argon2id.d.ts +8 -0
  9. package/dist/argon2id.js +40 -0
  10. package/dist/bip340Schnorr.d.ts +26 -0
  11. package/dist/bip340Schnorr.js +72 -0
  12. package/dist/codecs.d.ts +35 -0
  13. package/dist/codecs.js +216 -0
  14. package/dist/cryptoFacade.d.ts +51 -0
  15. package/dist/cryptoFacade.js +329 -0
  16. package/dist/digest.d.ts +14 -0
  17. package/dist/digest.js +33 -0
  18. package/dist/ed25519.d.ts +34 -0
  19. package/dist/ed25519.js +78 -0
  20. package/dist/encodeEcdsaDer.d.ts +2 -0
  21. package/dist/encodeEcdsaDer.js +141 -0
  22. package/dist/errors.d.ts +10 -0
  23. package/dist/errors.js +11 -0
  24. package/dist/hkdf.d.ts +7 -0
  25. package/dist/hkdf.js +27 -0
  26. package/dist/hmac.d.ts +9 -0
  27. package/dist/hmac.js +50 -0
  28. package/dist/hpke.d.ts +15 -0
  29. package/dist/hpke.js +59 -0
  30. package/dist/index.d.ts +41 -0
  31. package/dist/index.js +31 -0
  32. package/dist/jwk.d.ts +42 -0
  33. package/dist/jwk.js +289 -0
  34. package/dist/mlDsa.d.ts +18 -0
  35. package/dist/mlDsa.js +85 -0
  36. package/dist/mlKem.d.ts +25 -0
  37. package/dist/mlKem.js +95 -0
  38. package/dist/p256Ecdh.d.ts +22 -0
  39. package/dist/p256Ecdh.js +53 -0
  40. package/dist/p256Ecdsa.d.ts +25 -0
  41. package/dist/p256Ecdsa.js +85 -0
  42. package/dist/p384Ecdsa.d.ts +23 -0
  43. package/dist/p384Ecdsa.js +83 -0
  44. package/dist/p521Ecdsa.d.ts +23 -0
  45. package/dist/p521Ecdsa.js +83 -0
  46. package/dist/pbkdf2.d.ts +28 -0
  47. package/dist/pbkdf2.js +57 -0
  48. package/dist/proto/generated/reallyme/crypto/v1/crypto_pb.d.ts +618 -0
  49. package/dist/proto/generated/reallyme/crypto/v1/crypto_pb.js +523 -0
  50. package/dist/proto.d.ts +25 -0
  51. package/dist/proto.js +342 -0
  52. package/dist/providerCatalog.d.ts +9 -0
  53. package/dist/providerCatalog.js +15 -0
  54. package/dist/rsa.d.ts +13 -0
  55. package/dist/rsa.js +102 -0
  56. package/dist/secp256k1.d.ts +47 -0
  57. package/dist/secp256k1.js +106 -0
  58. package/dist/slhDsa.d.ts +15 -0
  59. package/dist/slhDsa.js +54 -0
  60. package/dist/validateBytes.d.ts +2 -0
  61. package/dist/validateBytes.js +20 -0
  62. package/dist/verifySignature.d.ts +1 -0
  63. package/dist/verifySignature.js +9 -0
  64. package/dist/wasm/LICENSE +201 -0
  65. package/dist/wasm/reallyme_crypto_wasm.js +1319 -0
  66. package/dist/wasm/reallyme_crypto_wasm_bg.wasm +0 -0
  67. package/dist/wasmModuleTypes.d.ts +72 -0
  68. package/dist/wasmModuleTypes.js +4 -0
  69. package/dist/wasmProvider.d.ts +94 -0
  70. package/dist/wasmProvider.js +173 -0
  71. package/dist/x25519.d.ts +28 -0
  72. package/dist/x25519.js +66 -0
  73. package/dist/xWing.d.ts +23 -0
  74. package/dist/xWing.js +86 -0
  75. package/package.json +48 -0
package/dist/proto.js ADDED
@@ -0,0 +1,342 @@
1
+ // SPDX-FileCopyrightText: Copyright © 2026 ReallyMe LLC. All rights reserved
2
+ //
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ import { ReallyMeCryptoError } from "./errors.js";
5
+ export { AeadAlgorithm, AeadAlgorithmSchema, CryptoAlgorithmFamily, CryptoAlgorithmIdentifierSchema, CryptoAlgorithmFamilySchema, HashAlgorithm, HashAlgorithmSchema, HpkeSuite, HpkeSuiteSchema, JsonWebKeySchema, JsonWebKeySetSchema, KdfAlgorithm, KdfAlgorithmSchema, KemAlgorithm, KemAlgorithmSchema, KeyAgreementAlgorithm, KeyAgreementAlgorithmSchema, KeyWrapAlgorithm, KeyWrapAlgorithmSchema, MacAlgorithm, MacAlgorithmSchema, MulticodecKeyAlgorithm, MulticodecKeyAlgorithmSchema, SignatureAlgorithm, SignatureAlgorithmSchema, file_reallyme_crypto_v1_crypto, } from "./proto/generated/reallyme/crypto/v1/crypto_pb.js";
6
+ import { AeadAlgorithm, HashAlgorithm, HpkeSuite, KdfAlgorithm, KemAlgorithm, KeyAgreementAlgorithm, KeyWrapAlgorithm, MacAlgorithm, MulticodecKeyAlgorithm, 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_256_GCM:
130
+ return "AES-256-GCM";
131
+ case AeadAlgorithm.AES_256_GCM_SIV:
132
+ return "AES-256-GCM-SIV";
133
+ case AeadAlgorithm.CHACHA20_POLY1305:
134
+ return "ChaCha20-Poly1305";
135
+ case AeadAlgorithm.XCHACHA20_POLY1305:
136
+ return "XChaCha20-Poly1305";
137
+ default:
138
+ throw new ReallyMeCryptoError("unsupported-algorithm");
139
+ }
140
+ };
141
+ export const aeadAlgorithmToProto = (value) => {
142
+ switch (value) {
143
+ case "AES-256-GCM":
144
+ return AeadAlgorithm.AES_256_GCM;
145
+ case "AES-256-GCM-SIV":
146
+ return AeadAlgorithm.AES_256_GCM_SIV;
147
+ case "ChaCha20-Poly1305":
148
+ return AeadAlgorithm.CHACHA20_POLY1305;
149
+ case "XChaCha20-Poly1305":
150
+ return AeadAlgorithm.XCHACHA20_POLY1305;
151
+ }
152
+ };
153
+ export const kemAlgorithmFromProto = (value) => {
154
+ switch (value) {
155
+ case KemAlgorithm.ML_KEM_512:
156
+ return "ML-KEM-512";
157
+ case KemAlgorithm.ML_KEM_768:
158
+ return "ML-KEM-768";
159
+ case KemAlgorithm.ML_KEM_1024:
160
+ return "ML-KEM-1024";
161
+ case KemAlgorithm.X_WING_768:
162
+ return "X-Wing-768";
163
+ case KemAlgorithm.X_WING_1024:
164
+ return "X-Wing-1024";
165
+ default:
166
+ throw new ReallyMeCryptoError("unsupported-algorithm");
167
+ }
168
+ };
169
+ export const kemAlgorithmToProto = (value) => {
170
+ switch (value) {
171
+ case "ML-KEM-512":
172
+ return KemAlgorithm.ML_KEM_512;
173
+ case "ML-KEM-768":
174
+ return KemAlgorithm.ML_KEM_768;
175
+ case "ML-KEM-1024":
176
+ return KemAlgorithm.ML_KEM_1024;
177
+ case "X-Wing-768":
178
+ return KemAlgorithm.X_WING_768;
179
+ case "X-Wing-1024":
180
+ return KemAlgorithm.X_WING_1024;
181
+ }
182
+ };
183
+ export const keyAgreementAlgorithmFromProto = (value) => {
184
+ switch (value) {
185
+ case KeyAgreementAlgorithm.X25519:
186
+ return "X25519";
187
+ case KeyAgreementAlgorithm.P256_ECDH:
188
+ return "P-256-ECDH";
189
+ default:
190
+ throw new ReallyMeCryptoError("unsupported-algorithm");
191
+ }
192
+ };
193
+ export const keyAgreementAlgorithmToProto = (value) => {
194
+ switch (value) {
195
+ case "X25519":
196
+ return KeyAgreementAlgorithm.X25519;
197
+ case "P-256-ECDH":
198
+ return KeyAgreementAlgorithm.P256_ECDH;
199
+ }
200
+ };
201
+ export const macAlgorithmFromProto = (value) => {
202
+ switch (value) {
203
+ case MacAlgorithm.HMAC_SHA256:
204
+ return "HMAC-SHA-256";
205
+ case MacAlgorithm.HMAC_SHA512:
206
+ return "HMAC-SHA-512";
207
+ default:
208
+ throw new ReallyMeCryptoError("unsupported-algorithm");
209
+ }
210
+ };
211
+ export const macAlgorithmToProto = (value) => {
212
+ switch (value) {
213
+ case "HMAC-SHA-256":
214
+ return MacAlgorithm.HMAC_SHA256;
215
+ case "HMAC-SHA-512":
216
+ return MacAlgorithm.HMAC_SHA512;
217
+ }
218
+ };
219
+ export const kdfAlgorithmFromProto = (value) => {
220
+ switch (value) {
221
+ case KdfAlgorithm.HKDF_SHA256:
222
+ return "HKDF-SHA256";
223
+ case KdfAlgorithm.ARGON2ID:
224
+ return "Argon2id";
225
+ case KdfAlgorithm.PBKDF2_HMAC_SHA256:
226
+ return "PBKDF2-HMAC-SHA-256";
227
+ case KdfAlgorithm.PBKDF2_HMAC_SHA512:
228
+ return "PBKDF2-HMAC-SHA-512";
229
+ default:
230
+ throw new ReallyMeCryptoError("unsupported-algorithm");
231
+ }
232
+ };
233
+ export const kdfAlgorithmToProto = (value) => {
234
+ switch (value) {
235
+ case "HKDF-SHA256":
236
+ return KdfAlgorithm.HKDF_SHA256;
237
+ case "Argon2id":
238
+ return KdfAlgorithm.ARGON2ID;
239
+ case "PBKDF2-HMAC-SHA-256":
240
+ return KdfAlgorithm.PBKDF2_HMAC_SHA256;
241
+ case "PBKDF2-HMAC-SHA-512":
242
+ return KdfAlgorithm.PBKDF2_HMAC_SHA512;
243
+ }
244
+ };
245
+ export const keyWrapAlgorithmFromProto = (value) => {
246
+ switch (value) {
247
+ case KeyWrapAlgorithm.AES_256_KW:
248
+ return "AES-256-KW";
249
+ default:
250
+ throw new ReallyMeCryptoError("unsupported-algorithm");
251
+ }
252
+ };
253
+ export const keyWrapAlgorithmToProto = (value) => {
254
+ switch (value) {
255
+ case "AES-256-KW":
256
+ return KeyWrapAlgorithm.AES_256_KW;
257
+ }
258
+ };
259
+ export const hpkeSuiteFromProto = (value) => {
260
+ switch (value) {
261
+ case HpkeSuite.DHKEM_P256_HKDF_SHA256_HKDF_SHA256_AES_256_GCM:
262
+ return "DHKEM-P256-HKDF-SHA256-HKDF-SHA256-AES-256-GCM";
263
+ case HpkeSuite.DHKEM_X25519_HKDF_SHA256_HKDF_SHA256_CHACHA20_POLY1305:
264
+ return "DHKEM-X25519-HKDF-SHA256-HKDF-SHA256-CHACHA20-POLY1305";
265
+ default:
266
+ throw new ReallyMeCryptoError("unsupported-algorithm");
267
+ }
268
+ };
269
+ export const hpkeSuiteToProto = (value) => {
270
+ switch (value) {
271
+ case "DHKEM-P256-HKDF-SHA256-HKDF-SHA256-AES-256-GCM":
272
+ return HpkeSuite.DHKEM_P256_HKDF_SHA256_HKDF_SHA256_AES_256_GCM;
273
+ case "DHKEM-X25519-HKDF-SHA256-HKDF-SHA256-CHACHA20-POLY1305":
274
+ return HpkeSuite.DHKEM_X25519_HKDF_SHA256_HKDF_SHA256_CHACHA20_POLY1305;
275
+ }
276
+ };
277
+ export const multicodecKeyAlgorithmFromProto = (value) => {
278
+ switch (value) {
279
+ case MulticodecKeyAlgorithm.ED25519_PUB:
280
+ return "ed25519-pub";
281
+ case MulticodecKeyAlgorithm.X25519_PUB:
282
+ return "x25519-pub";
283
+ case MulticodecKeyAlgorithm.SECP256K1_PUB:
284
+ return "secp256k1-pub";
285
+ case MulticodecKeyAlgorithm.P256_PUB:
286
+ return "p256-pub";
287
+ case MulticodecKeyAlgorithm.P384_PUB:
288
+ return "p384-pub";
289
+ case MulticodecKeyAlgorithm.P521_PUB:
290
+ return "p521-pub";
291
+ case MulticodecKeyAlgorithm.ED448_PUB:
292
+ return "ed448-pub";
293
+ case MulticodecKeyAlgorithm.RSA_PUB:
294
+ return "rsa-pub";
295
+ case MulticodecKeyAlgorithm.ML_KEM_512_PUB:
296
+ return "mlkem-512-pub";
297
+ case MulticodecKeyAlgorithm.ML_KEM_768_PUB:
298
+ return "mlkem-768-pub";
299
+ case MulticodecKeyAlgorithm.ML_KEM_1024_PUB:
300
+ return "mlkem-1024-pub";
301
+ case MulticodecKeyAlgorithm.ML_DSA_44_PUB:
302
+ return "mldsa-44-pub";
303
+ case MulticodecKeyAlgorithm.ML_DSA_65_PUB:
304
+ return "mldsa-65-pub";
305
+ case MulticodecKeyAlgorithm.ML_DSA_87_PUB:
306
+ return "mldsa-87-pub";
307
+ default:
308
+ throw new ReallyMeCryptoError("unsupported-algorithm");
309
+ }
310
+ };
311
+ export const multicodecKeyAlgorithmToProto = (value) => {
312
+ switch (value) {
313
+ case "ed25519-pub":
314
+ return MulticodecKeyAlgorithm.ED25519_PUB;
315
+ case "x25519-pub":
316
+ return MulticodecKeyAlgorithm.X25519_PUB;
317
+ case "secp256k1-pub":
318
+ return MulticodecKeyAlgorithm.SECP256K1_PUB;
319
+ case "p256-pub":
320
+ return MulticodecKeyAlgorithm.P256_PUB;
321
+ case "p384-pub":
322
+ return MulticodecKeyAlgorithm.P384_PUB;
323
+ case "p521-pub":
324
+ return MulticodecKeyAlgorithm.P521_PUB;
325
+ case "ed448-pub":
326
+ return MulticodecKeyAlgorithm.ED448_PUB;
327
+ case "rsa-pub":
328
+ return MulticodecKeyAlgorithm.RSA_PUB;
329
+ case "mlkem-512-pub":
330
+ return MulticodecKeyAlgorithm.ML_KEM_512_PUB;
331
+ case "mlkem-768-pub":
332
+ return MulticodecKeyAlgorithm.ML_KEM_768_PUB;
333
+ case "mlkem-1024-pub":
334
+ return MulticodecKeyAlgorithm.ML_KEM_1024_PUB;
335
+ case "mldsa-44-pub":
336
+ return MulticodecKeyAlgorithm.ML_DSA_44_PUB;
337
+ case "mldsa-65-pub":
338
+ return MulticodecKeyAlgorithm.ML_DSA_65_PUB;
339
+ case "mldsa-87-pub":
340
+ return MulticodecKeyAlgorithm.ML_DSA_87_PUB;
341
+ }
342
+ };
@@ -0,0 +1,9 @@
1
+ /** Providers compiled into the TypeScript package. */
2
+ export declare const REALLYME_CRYPTO_PROVIDERS: readonly ["@noble/curves", "@noble/hashes", "ReallyMe Rust WASM"];
3
+ export type ReallyMeCryptoProvider = (typeof REALLYME_CRYPTO_PROVIDERS)[number];
4
+ /**
5
+ * Compile-time provider catalog used by package consumers and conformance
6
+ * tests to assert that TypeScript crypto is backed by explicit provider
7
+ * packages.
8
+ */
9
+ export declare const compiledProviders: readonly ReallyMeCryptoProvider[];
@@ -0,0 +1,15 @@
1
+ // SPDX-FileCopyrightText: Copyright © 2026 ReallyMe LLC. All rights reserved
2
+ //
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ /** Providers compiled into the TypeScript package. */
5
+ export const REALLYME_CRYPTO_PROVIDERS = [
6
+ "@noble/curves",
7
+ "@noble/hashes",
8
+ "ReallyMe Rust WASM",
9
+ ];
10
+ /**
11
+ * Compile-time provider catalog used by package consumers and conformance
12
+ * tests to assert that TypeScript crypto is backed by explicit provider
13
+ * packages.
14
+ */
15
+ export const compiledProviders = REALLYME_CRYPTO_PROVIDERS;
package/dist/rsa.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import type { ReallyMeSignatureAlgorithm } from "./algorithms.js";
2
+ export type ReallyMeRsaPublicKeyDerEncoding = "PKCS1" | "SPKI";
3
+ export declare const RSA_PUBLIC_KEY_DER_MAX_LENGTH = 4096;
4
+ export declare const RSA_SIGNATURE_MAX_LENGTH = 1024;
5
+ /**
6
+ * RSA signature verification through the ReallyMe Rust WASM provider.
7
+ *
8
+ * RSA is verification-only in this SDK. It exists for X.509, eMRTD passive
9
+ * authentication, and legacy interoperability; no RSA signing API is exposed.
10
+ */
11
+ export declare const ReallyMeRsa: {
12
+ readonly verify: (algorithm: ReallyMeSignatureAlgorithm, signature: Uint8Array, message: Uint8Array, publicKeyDer: Uint8Array, publicKeyEncoding: ReallyMeRsaPublicKeyDerEncoding) => void;
13
+ };
package/dist/rsa.js ADDED
@@ -0,0 +1,102 @@
1
+ // SPDX-FileCopyrightText: Copyright © 2026 ReallyMe LLC. All rights reserved
2
+ //
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ import { ReallyMeCryptoError } from "./errors.js";
5
+ import { requireReallyMeWasmProvider } from "./wasmProvider.js";
6
+ export const RSA_PUBLIC_KEY_DER_MAX_LENGTH = 4_096;
7
+ export const RSA_SIGNATURE_MAX_LENGTH = 1_024;
8
+ const RSA_HASH_SHA1 = 1;
9
+ const RSA_HASH_SHA256 = 2;
10
+ const RSA_HASH_SHA384 = 3;
11
+ const RSA_HASH_SHA512 = 4;
12
+ const RSA_PUBLIC_KEY_ENCODING_PKCS1_DER = 1;
13
+ const RSA_PUBLIC_KEY_ENCODING_SPKI_DER = 2;
14
+ const validateBytes = (bytes, maxLength) => {
15
+ if (bytes.length === 0 || bytes.length > maxLength) {
16
+ throw new ReallyMeCryptoError("invalid-input");
17
+ }
18
+ };
19
+ const encodingId = (encoding) => {
20
+ switch (encoding) {
21
+ case "PKCS1":
22
+ return RSA_PUBLIC_KEY_ENCODING_PKCS1_DER;
23
+ case "SPKI":
24
+ return RSA_PUBLIC_KEY_ENCODING_SPKI_DER;
25
+ default:
26
+ throw new ReallyMeCryptoError("invalid-input");
27
+ }
28
+ };
29
+ const pkcs1v15Suite = (algorithm) => {
30
+ switch (algorithm) {
31
+ case "RSA-PKCS1v15-SHA1":
32
+ return { hashSuite: RSA_HASH_SHA1 };
33
+ case "RSA-PKCS1v15-SHA256":
34
+ return { hashSuite: RSA_HASH_SHA256 };
35
+ case "RSA-PKCS1v15-SHA384":
36
+ return { hashSuite: RSA_HASH_SHA384 };
37
+ case "RSA-PKCS1v15-SHA512":
38
+ return { hashSuite: RSA_HASH_SHA512 };
39
+ default:
40
+ return undefined;
41
+ }
42
+ };
43
+ const pssSuite = (algorithm) => {
44
+ switch (algorithm) {
45
+ case "RSA-PSS-SHA1-MGF1-SHA1":
46
+ return {
47
+ messageHashSuite: RSA_HASH_SHA1,
48
+ mgf1HashSuite: RSA_HASH_SHA1,
49
+ saltLength: 20,
50
+ };
51
+ case "RSA-PSS-SHA256-MGF1-SHA256":
52
+ return {
53
+ messageHashSuite: RSA_HASH_SHA256,
54
+ mgf1HashSuite: RSA_HASH_SHA256,
55
+ saltLength: 32,
56
+ };
57
+ case "RSA-PSS-SHA384-MGF1-SHA384":
58
+ return {
59
+ messageHashSuite: RSA_HASH_SHA384,
60
+ mgf1HashSuite: RSA_HASH_SHA384,
61
+ saltLength: 48,
62
+ };
63
+ case "RSA-PSS-SHA512-MGF1-SHA512":
64
+ return {
65
+ messageHashSuite: RSA_HASH_SHA512,
66
+ mgf1HashSuite: RSA_HASH_SHA512,
67
+ saltLength: 64,
68
+ };
69
+ default:
70
+ return undefined;
71
+ }
72
+ };
73
+ const readVoid = (value) => {
74
+ if (value !== undefined) {
75
+ throw new ReallyMeCryptoError("provider-failure");
76
+ }
77
+ };
78
+ /**
79
+ * RSA signature verification through the ReallyMe Rust WASM provider.
80
+ *
81
+ * RSA is verification-only in this SDK. It exists for X.509, eMRTD passive
82
+ * authentication, and legacy interoperability; no RSA signing API is exposed.
83
+ */
84
+ export const ReallyMeRsa = {
85
+ verify(algorithm, signature, message, publicKeyDer, publicKeyEncoding) {
86
+ validateBytes(publicKeyDer, RSA_PUBLIC_KEY_DER_MAX_LENGTH);
87
+ validateBytes(signature, RSA_SIGNATURE_MAX_LENGTH);
88
+ const encoding = encodingId(publicKeyEncoding);
89
+ const pkcs1 = pkcs1v15Suite(algorithm);
90
+ const provider = requireReallyMeWasmProvider();
91
+ if (pkcs1 !== undefined) {
92
+ readVoid(provider.rsaVerifyPkcs1v15(publicKeyDer, encoding, pkcs1.hashSuite, message, signature));
93
+ return;
94
+ }
95
+ const pss = pssSuite(algorithm);
96
+ if (pss !== undefined) {
97
+ readVoid(provider.rsaVerifyPss(publicKeyDer, encoding, pss.messageHashSuite, pss.mgf1HashSuite, pss.saltLength, message, signature));
98
+ return;
99
+ }
100
+ throw new ReallyMeCryptoError("unsupported-algorithm");
101
+ },
102
+ };
@@ -0,0 +1,47 @@
1
+ /**
2
+ * secp256k1 ECDSA backed by @noble/curves — the same pinned implementation
3
+ * the TypeScript conformance lane proves vectors against.
4
+ *
5
+ * The API follows the workspace secp256k1 contract exactly, so signatures
6
+ * interoperate byte-for-byte with the Rust, Swift, and Kotlin lanes:
7
+ *
8
+ * - Secret keys are 32 bytes; public keys are 33-byte compressed SEC1.
9
+ * - `sign` hashes the full message internally with SHA-256 (callers pass the
10
+ * message, not a digest), derives the nonce deterministically (RFC 6979),
11
+ * and emits the 64-byte compact `r ‖ s` form normalized to low-S
12
+ * (BIP 0062).
13
+ * - `verify` accepts only the 64-byte compact form, rejects the malleated
14
+ * high-S twin, and throws `invalid-signature` for a well-formed-but-wrong
15
+ * signature so callers cannot accidentally ignore a failed check.
16
+ */
17
+ export declare const SECP256K1_SECRET_KEY_LENGTH = 32;
18
+ export declare const SECP256K1_COMPRESSED_PUBLIC_KEY_LENGTH = 33;
19
+ export declare const SECP256K1_SIGNATURE_LENGTH = 64;
20
+ export declare const ReallyMeSecp256k1: {
21
+ /** Generates a random keypair: 33-byte compressed public, 32-byte secret. */
22
+ readonly generateKeyPair: () => {
23
+ publicKey: Uint8Array;
24
+ secretKey: Uint8Array;
25
+ };
26
+ /** Derives the secp256k1 ECDSA keypair from a 32-byte secret scalar. */
27
+ readonly deriveKeyPair: (secretKey: Uint8Array) => {
28
+ publicKey: Uint8Array;
29
+ secretKey: Uint8Array;
30
+ };
31
+ /** Derives the 33-byte compressed SEC1 public key for a 32-byte secret. */
32
+ readonly derivePublicKey: (secretKey: Uint8Array) => Uint8Array;
33
+ /**
34
+ * Signs `message` with deterministic (RFC 6979) ECDSA over
35
+ * SHA-256(message), returning the 64-byte compact low-S signature.
36
+ */
37
+ readonly sign: (message: Uint8Array, secretKey: Uint8Array) => Uint8Array;
38
+ /**
39
+ * Verifies a 64-byte compact signature over SHA-256(message) against a
40
+ * 33-byte compressed SEC1 public key.
41
+ *
42
+ * Throws on malformed input (wrong lengths, undecodable key); returns
43
+ * Throws for a signature that does not verify, including the malleated
44
+ * high-S twin (BIP 0062), which every workspace lane rejects.
45
+ */
46
+ readonly verify: (signature: Uint8Array, message: Uint8Array, publicKey: Uint8Array) => void;
47
+ };
@@ -0,0 +1,106 @@
1
+ // SPDX-FileCopyrightText: Copyright © 2026 ReallyMe LLC. All rights reserved
2
+ //
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ import { secp256k1 } from "@noble/curves/secp256k1.js";
5
+ import { sha256 } from "@noble/hashes/sha2.js";
6
+ import { ReallyMeCryptoError } from "./errors.js";
7
+ /**
8
+ * secp256k1 ECDSA backed by @noble/curves — the same pinned implementation
9
+ * the TypeScript conformance lane proves vectors against.
10
+ *
11
+ * The API follows the workspace secp256k1 contract exactly, so signatures
12
+ * interoperate byte-for-byte with the Rust, Swift, and Kotlin lanes:
13
+ *
14
+ * - Secret keys are 32 bytes; public keys are 33-byte compressed SEC1.
15
+ * - `sign` hashes the full message internally with SHA-256 (callers pass the
16
+ * message, not a digest), derives the nonce deterministically (RFC 6979),
17
+ * and emits the 64-byte compact `r ‖ s` form normalized to low-S
18
+ * (BIP 0062).
19
+ * - `verify` accepts only the 64-byte compact form, rejects the malleated
20
+ * high-S twin, and throws `invalid-signature` for a well-formed-but-wrong
21
+ * signature so callers cannot accidentally ignore a failed check.
22
+ */
23
+ export const SECP256K1_SECRET_KEY_LENGTH = 32;
24
+ export const SECP256K1_COMPRESSED_PUBLIC_KEY_LENGTH = 33;
25
+ export const SECP256K1_SIGNATURE_LENGTH = 64;
26
+ export const ReallyMeSecp256k1 = {
27
+ /** Generates a random keypair: 33-byte compressed public, 32-byte secret. */
28
+ generateKeyPair() {
29
+ const secretKey = secp256k1.utils.randomSecretKey();
30
+ return {
31
+ publicKey: secp256k1.getPublicKey(secretKey, true),
32
+ secretKey,
33
+ };
34
+ },
35
+ /** Derives the secp256k1 ECDSA keypair from a 32-byte secret scalar. */
36
+ deriveKeyPair(secretKey) {
37
+ return {
38
+ publicKey: this.derivePublicKey(secretKey),
39
+ secretKey: secretKey.slice(),
40
+ };
41
+ },
42
+ /** Derives the 33-byte compressed SEC1 public key for a 32-byte secret. */
43
+ derivePublicKey(secretKey) {
44
+ if (secretKey.length !== SECP256K1_SECRET_KEY_LENGTH) {
45
+ throw new ReallyMeCryptoError("invalid-input");
46
+ }
47
+ try {
48
+ return secp256k1.getPublicKey(secretKey, true);
49
+ }
50
+ catch {
51
+ throw new ReallyMeCryptoError("invalid-input");
52
+ }
53
+ },
54
+ /**
55
+ * Signs `message` with deterministic (RFC 6979) ECDSA over
56
+ * SHA-256(message), returning the 64-byte compact low-S signature.
57
+ */
58
+ sign(message, secretKey) {
59
+ if (secretKey.length !== SECP256K1_SECRET_KEY_LENGTH) {
60
+ throw new ReallyMeCryptoError("invalid-input");
61
+ }
62
+ try {
63
+ // Hash exactly once ourselves; prehash: false stops noble from
64
+ // hashing the digest a second time.
65
+ return secp256k1.sign(sha256(message), secretKey, {
66
+ lowS: true,
67
+ prehash: false,
68
+ });
69
+ }
70
+ catch {
71
+ throw new ReallyMeCryptoError("invalid-input");
72
+ }
73
+ },
74
+ /**
75
+ * Verifies a 64-byte compact signature over SHA-256(message) against a
76
+ * 33-byte compressed SEC1 public key.
77
+ *
78
+ * Throws on malformed input (wrong lengths, undecodable key); returns
79
+ * Throws for a signature that does not verify, including the malleated
80
+ * high-S twin (BIP 0062), which every workspace lane rejects.
81
+ */
82
+ verify(signature, message, publicKey) {
83
+ if (signature.length !== SECP256K1_SIGNATURE_LENGTH ||
84
+ publicKey.length !== SECP256K1_COMPRESSED_PUBLIC_KEY_LENGTH) {
85
+ throw new ReallyMeCryptoError("invalid-input");
86
+ }
87
+ try {
88
+ secp256k1.Point.fromBytes(publicKey);
89
+ }
90
+ catch {
91
+ throw new ReallyMeCryptoError("invalid-input");
92
+ }
93
+ try {
94
+ const valid = secp256k1.verify(signature, sha256(message), publicKey, {
95
+ lowS: true,
96
+ prehash: false,
97
+ });
98
+ if (!valid) {
99
+ throw new ReallyMeCryptoError("invalid-signature");
100
+ }
101
+ }
102
+ catch {
103
+ throw new ReallyMeCryptoError("invalid-signature");
104
+ }
105
+ },
106
+ };
@@ -0,0 +1,15 @@
1
+ import type { ReallyMeSignatureAlgorithm } from "./algorithms.js";
2
+ export declare const SLH_DSA_SHA2_128S_PUBLIC_KEY_LENGTH = 32;
3
+ export declare const SLH_DSA_SHA2_128S_SECRET_KEY_LENGTH = 64;
4
+ export declare const SLH_DSA_SHA2_128S_SIGNATURE_LENGTH = 7856;
5
+ export declare const SLH_DSA_SHA2_128S_KEYGEN_SEED_LENGTH = 16;
6
+ export type ReallyMeSlhDsaKeyPair = Readonly<{
7
+ publicKey: Uint8Array;
8
+ secretKey: Uint8Array;
9
+ }>;
10
+ export declare const ReallyMeSlhDsa: {
11
+ readonly generateKeyPair: (algorithm: ReallyMeSignatureAlgorithm) => ReallyMeSlhDsaKeyPair;
12
+ readonly sign: (algorithm: ReallyMeSignatureAlgorithm, message: Uint8Array, secretKey: Uint8Array) => Uint8Array;
13
+ readonly verify: (algorithm: ReallyMeSignatureAlgorithm, signature: Uint8Array, message: Uint8Array, publicKey: Uint8Array) => void;
14
+ };
15
+ export declare const deriveSlhDsaSha2128sKeypairForTest: (skSeed: Uint8Array, skPrf: Uint8Array, pkSeed: Uint8Array) => ReallyMeSlhDsaKeyPair;