@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/codecs.js ADDED
@@ -0,0 +1,216 @@
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
+ const validTags = new Set([
7
+ "encryption",
8
+ "hash",
9
+ "key",
10
+ "multihash",
11
+ "multikey",
12
+ ]);
13
+ const validKeyMaterialKinds = new Set([
14
+ "not-key",
15
+ "public-key",
16
+ "private-key",
17
+ "symmetric-key",
18
+ ]);
19
+ const ensureStringInput = (value) => {
20
+ if (typeof value !== "string" || value.length === 0) {
21
+ throw new ReallyMeCryptoError("invalid-input");
22
+ }
23
+ };
24
+ const ensureBytesInput = (value) => {
25
+ if (!(value instanceof Uint8Array)) {
26
+ throw new ReallyMeCryptoError("invalid-input");
27
+ }
28
+ };
29
+ const requireObjectOutput = (value) => {
30
+ if (typeof value !== "object" || value === null) {
31
+ throw new ReallyMeCryptoError("provider-failure");
32
+ }
33
+ return value;
34
+ };
35
+ const readStringOutput = (value) => {
36
+ if (typeof value !== "string") {
37
+ throw new ReallyMeCryptoError("provider-failure");
38
+ }
39
+ return value;
40
+ };
41
+ const readBytesOutput = (value) => {
42
+ if (!(value instanceof Uint8Array)) {
43
+ throw new ReallyMeCryptoError("provider-failure");
44
+ }
45
+ return value;
46
+ };
47
+ const readStringProperty = (object, propertyName) => {
48
+ const property = Reflect.get(object, propertyName);
49
+ if (typeof property !== "string" || property.length === 0) {
50
+ throw new ReallyMeCryptoError("provider-failure");
51
+ }
52
+ return property;
53
+ };
54
+ const readBooleanProperty = (object, propertyName) => {
55
+ const property = Reflect.get(object, propertyName);
56
+ if (typeof property !== "boolean") {
57
+ throw new ReallyMeCryptoError("provider-failure");
58
+ }
59
+ return property;
60
+ };
61
+ const readBytesProperty = (object, propertyName) => {
62
+ const property = Reflect.get(object, propertyName);
63
+ if (!(property instanceof Uint8Array)) {
64
+ throw new ReallyMeCryptoError("provider-failure");
65
+ }
66
+ return property;
67
+ };
68
+ const readOptionalLengthProperty = (object, propertyName) => {
69
+ const property = Reflect.get(object, propertyName);
70
+ if (property === undefined) {
71
+ return undefined;
72
+ }
73
+ if (typeof property !== "number" || !Number.isSafeInteger(property) || property < 0) {
74
+ throw new ReallyMeCryptoError("provider-failure");
75
+ }
76
+ return property;
77
+ };
78
+ const readTagProperty = (object) => {
79
+ const tag = readStringProperty(object, "tag");
80
+ if (!validTags.has(tag)) {
81
+ throw new ReallyMeCryptoError("provider-failure");
82
+ }
83
+ switch (tag) {
84
+ case "encryption":
85
+ case "hash":
86
+ case "key":
87
+ case "multihash":
88
+ case "multikey":
89
+ return tag;
90
+ default:
91
+ throw new ReallyMeCryptoError("provider-failure");
92
+ }
93
+ };
94
+ const readKeyMaterialProperty = (object) => {
95
+ const keyMaterial = readStringProperty(object, "keyMaterial");
96
+ if (!validKeyMaterialKinds.has(keyMaterial)) {
97
+ throw new ReallyMeCryptoError("provider-failure");
98
+ }
99
+ switch (keyMaterial) {
100
+ case "not-key":
101
+ case "public-key":
102
+ case "private-key":
103
+ case "symmetric-key":
104
+ return keyMaterial;
105
+ default:
106
+ throw new ReallyMeCryptoError("provider-failure");
107
+ }
108
+ };
109
+ const readMulticodecMetadata = (value) => {
110
+ const object = requireObjectOutput(value);
111
+ const expectedKeyLength = readOptionalLengthProperty(object, "expectedKeyLength");
112
+ if (expectedKeyLength === undefined) {
113
+ return {
114
+ name: readStringProperty(object, "name"),
115
+ alg: readStringProperty(object, "alg"),
116
+ tag: readTagProperty(object),
117
+ keyMaterial: readKeyMaterialProperty(object),
118
+ prefix: readBytesProperty(object, "prefix"),
119
+ };
120
+ }
121
+ return {
122
+ name: readStringProperty(object, "name"),
123
+ alg: readStringProperty(object, "alg"),
124
+ tag: readTagProperty(object),
125
+ keyMaterial: readKeyMaterialProperty(object),
126
+ prefix: readBytesProperty(object, "prefix"),
127
+ expectedKeyLength,
128
+ };
129
+ };
130
+ const readParsedMultikey = (value) => {
131
+ const object = requireObjectOutput(value);
132
+ const expectedPublicKeyLength = readOptionalLengthProperty(object, "expectedPublicKeyLength");
133
+ if (expectedPublicKeyLength === undefined) {
134
+ return {
135
+ codecName: readStringProperty(object, "codecName"),
136
+ algorithmName: readStringProperty(object, "algorithmName"),
137
+ publicKey: readBytesProperty(object, "publicKey"),
138
+ };
139
+ }
140
+ return {
141
+ codecName: readStringProperty(object, "codecName"),
142
+ algorithmName: readStringProperty(object, "algorithmName"),
143
+ publicKey: readBytesProperty(object, "publicKey"),
144
+ expectedPublicKeyLength,
145
+ };
146
+ };
147
+ const readCidVerification = (value) => {
148
+ const object = requireObjectOutput(value);
149
+ return {
150
+ valid: readBooleanProperty(object, "valid"),
151
+ expectedCid: readStringProperty(object, "expectedCid"),
152
+ actualCid: readStringProperty(object, "actualCid"),
153
+ };
154
+ };
155
+ const asciiBytesToString = (bytes) => {
156
+ let value = "";
157
+ for (const byte of bytes) {
158
+ if (byte > 0x7f) {
159
+ throw new ReallyMeCryptoError("invalid-input");
160
+ }
161
+ value += String.fromCharCode(byte);
162
+ }
163
+ return value;
164
+ };
165
+ export const ReallyMeCodecs = {
166
+ base64urlEncode(bytes) {
167
+ ensureBytesInput(bytes);
168
+ return readStringOutput(requireReallyMeWasmProvider().base64urlEncode(bytes));
169
+ },
170
+ base64urlDecode(encoded) {
171
+ ensureStringInput(encoded);
172
+ return readBytesOutput(requireReallyMeWasmProvider().base64urlDecode(encoded));
173
+ },
174
+ base64urlDecodeBytes(encoded) {
175
+ ensureBytesInput(encoded);
176
+ return readBytesOutput(requireReallyMeWasmProvider().base64urlDecode(asciiBytesToString(encoded)));
177
+ },
178
+ multibaseBase64urlEncode(bytes) {
179
+ ensureBytesInput(bytes);
180
+ return readStringOutput(requireReallyMeWasmProvider().multibaseBase64urlEncode(bytes));
181
+ },
182
+ multibaseBase58btcEncode(bytes) {
183
+ ensureBytesInput(bytes);
184
+ return readStringOutput(requireReallyMeWasmProvider().multibaseBase58btcEncode(bytes));
185
+ },
186
+ multibaseDecode(encoded) {
187
+ ensureStringInput(encoded);
188
+ return readBytesOutput(requireReallyMeWasmProvider().multibaseDecode(encoded));
189
+ },
190
+ multicodecPrefixForName(codecName) {
191
+ ensureStringInput(codecName);
192
+ return readMulticodecMetadata(requireReallyMeWasmProvider().multicodecPrefixForName(codecName));
193
+ },
194
+ multicodecLookupPrefix(bytes) {
195
+ ensureBytesInput(bytes);
196
+ return readMulticodecMetadata(requireReallyMeWasmProvider().multicodecLookupPrefix(bytes));
197
+ },
198
+ multikeyEncode(codecName, publicKey) {
199
+ ensureStringInput(codecName);
200
+ ensureBytesInput(publicKey);
201
+ return readStringOutput(requireReallyMeWasmProvider().multikeyEncode(codecName, publicKey));
202
+ },
203
+ multikeyParse(multikey) {
204
+ ensureStringInput(multikey);
205
+ return readParsedMultikey(requireReallyMeWasmProvider().multikeyParse(multikey));
206
+ },
207
+ dagCborComputeCid(bytes) {
208
+ ensureBytesInput(bytes);
209
+ return readStringOutput(requireReallyMeWasmProvider().dagCborComputeCid(bytes));
210
+ },
211
+ dagCborVerifyCid(cid, bytes) {
212
+ ensureStringInput(cid);
213
+ ensureBytesInput(bytes);
214
+ return readCidVerification(requireReallyMeWasmProvider().dagCborVerifyCid(cid, bytes));
215
+ },
216
+ };
@@ -0,0 +1,51 @@
1
+ import type { ReallyMeAeadAlgorithm, ReallyMeHashAlgorithm, ReallyMeHpkeSuite, ReallyMeKdfAlgorithm, ReallyMeKemAlgorithm, ReallyMeKeyAgreementAlgorithm, ReallyMeKeyWrapAlgorithm, ReallyMeMacAlgorithm, ReallyMeSignatureAlgorithm } from "./algorithms.js";
2
+ import type { ReallyMeRsaPublicKeyDerEncoding } from "./rsa.js";
3
+ export type ReallyMeSignatureKeyPair = Readonly<{
4
+ publicKey: Uint8Array;
5
+ secretKey: Uint8Array;
6
+ }>;
7
+ export type ReallyMeKemKeyPair = Readonly<{
8
+ publicKey: Uint8Array;
9
+ secretKey: Uint8Array;
10
+ }>;
11
+ export type ReallyMeKeyAgreementKeyPair = Readonly<{
12
+ publicKey: Uint8Array;
13
+ secretKey: Uint8Array;
14
+ }>;
15
+ export type ReallyMeKemEncapsulation = Readonly<{
16
+ sharedSecret: Uint8Array;
17
+ ciphertext: Uint8Array;
18
+ }>;
19
+ export type ReallyMeHpkeSealedMessage = Readonly<{
20
+ encapsulatedKey: Uint8Array;
21
+ ciphertext: Uint8Array;
22
+ }>;
23
+ /**
24
+ * Generic package facade. Algorithm-specific objects remain available for
25
+ * callers that want direct provider access; this facade gives consumers a
26
+ * stable typed route that fails closed for not-yet-exposed algorithms.
27
+ */
28
+ export declare const ReallyMeCrypto: {
29
+ readonly hash: (algorithm: ReallyMeHashAlgorithm, bytes: Uint8Array) => Uint8Array;
30
+ readonly seal: (algorithm: ReallyMeAeadAlgorithm, key: Uint8Array, nonce: Uint8Array, aad: Uint8Array, plaintext: Uint8Array) => Uint8Array;
31
+ readonly open: (algorithm: ReallyMeAeadAlgorithm, key: Uint8Array, nonce: Uint8Array, aad: Uint8Array, ciphertextWithTag: Uint8Array) => Uint8Array;
32
+ readonly authenticate: (algorithm: ReallyMeMacAlgorithm, key: Uint8Array, message: Uint8Array) => Uint8Array;
33
+ readonly verifyMac: (algorithm: ReallyMeMacAlgorithm, tag: Uint8Array, key: Uint8Array, message: Uint8Array) => boolean;
34
+ readonly deriveKey: (algorithm: ReallyMeKdfAlgorithm, password: Uint8Array, salt: Uint8Array, iterations: number, outputLength: number) => Uint8Array;
35
+ readonly deriveHkdf: (algorithm: ReallyMeKdfAlgorithm, inputKeyMaterial: Uint8Array, salt: Uint8Array, info: Uint8Array, outputLength: number) => Uint8Array;
36
+ readonly wrapKey: (algorithm: ReallyMeKeyWrapAlgorithm, wrappingKey: Uint8Array, keyToWrap: Uint8Array) => Uint8Array;
37
+ readonly unwrapKey: (algorithm: ReallyMeKeyWrapAlgorithm, wrappingKey: Uint8Array, wrappedKey: Uint8Array) => Uint8Array;
38
+ readonly generateKeyPair: (algorithm: ReallyMeSignatureAlgorithm) => ReallyMeSignatureKeyPair;
39
+ readonly deriveKeyPair: (algorithm: ReallyMeSignatureAlgorithm, secretKey: Uint8Array) => ReallyMeSignatureKeyPair;
40
+ readonly sign: (algorithm: ReallyMeSignatureAlgorithm, message: Uint8Array, secretKey: Uint8Array) => Uint8Array;
41
+ readonly signBip340Schnorr: (message32: Uint8Array, secretKey: Uint8Array, auxRand32: Uint8Array) => Uint8Array;
42
+ readonly verify: (algorithm: ReallyMeSignatureAlgorithm, signature: Uint8Array, message: Uint8Array, publicKey: Uint8Array) => void;
43
+ readonly verifyRsa: (algorithm: ReallyMeSignatureAlgorithm, signature: Uint8Array, message: Uint8Array, publicKeyDer: Uint8Array, publicKeyEncoding: ReallyMeRsaPublicKeyDerEncoding) => void;
44
+ readonly deriveSharedSecret: (algorithm: ReallyMeKeyAgreementAlgorithm, publicKey: Uint8Array, secretKey: Uint8Array) => Uint8Array;
45
+ readonly deriveKeyAgreementKeyPair: (algorithm: ReallyMeKeyAgreementAlgorithm, secretKey: Uint8Array) => ReallyMeKeyAgreementKeyPair;
46
+ readonly generateKemKeyPair: (algorithm: ReallyMeKemAlgorithm) => ReallyMeKemKeyPair;
47
+ readonly encapsulate: (algorithm: ReallyMeKemAlgorithm, publicKey: Uint8Array) => ReallyMeKemEncapsulation;
48
+ readonly decapsulate: (algorithm: ReallyMeKemAlgorithm, ciphertext: Uint8Array, secretKey: Uint8Array) => Uint8Array;
49
+ readonly sealHpke: (suite: ReallyMeHpkeSuite, recipientPublicKey: Uint8Array, info: Uint8Array, aad: Uint8Array, plaintext: Uint8Array) => ReallyMeHpkeSealedMessage;
50
+ readonly openHpke: (suite: ReallyMeHpkeSuite, recipientSecretKey: Uint8Array, encapsulatedKey: Uint8Array, info: Uint8Array, aad: Uint8Array, ciphertext: Uint8Array) => Uint8Array;
51
+ };
@@ -0,0 +1,329 @@
1
+ // SPDX-FileCopyrightText: Copyright © 2026 ReallyMe LLC. All rights reserved
2
+ //
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ import { ReallyMeAead } from "./aead.js";
5
+ import { ReallyMeAesKw } from "./aesKw.js";
6
+ import { ReallyMeArgon2id } from "./argon2id.js";
7
+ import { ReallyMeBip340Schnorr } from "./bip340Schnorr.js";
8
+ import { ReallyMeDigest } from "./digest.js";
9
+ import { ReallyMeEd25519 } from "./ed25519.js";
10
+ import { ReallyMeCryptoError } from "./errors.js";
11
+ import { ReallyMeHkdf } from "./hkdf.js";
12
+ import { ReallyMeHmac } from "./hmac.js";
13
+ import { ReallyMeHpke } from "./hpke.js";
14
+ import { ReallyMeMlDsa } from "./mlDsa.js";
15
+ import { ReallyMeMlKem } from "./mlKem.js";
16
+ import { ReallyMeP256Ecdsa } from "./p256Ecdsa.js";
17
+ import { ReallyMeP256Ecdh } from "./p256Ecdh.js";
18
+ import { ReallyMeP384Ecdsa } from "./p384Ecdsa.js";
19
+ import { ReallyMeP521Ecdsa } from "./p521Ecdsa.js";
20
+ import { ReallyMePbkdf2 } from "./pbkdf2.js";
21
+ import { ReallyMeRsa } from "./rsa.js";
22
+ import { ReallyMeSecp256k1 } from "./secp256k1.js";
23
+ import { ReallyMeSlhDsa } from "./slhDsa.js";
24
+ import { ReallyMeX25519 } from "./x25519.js";
25
+ import { ReallyMeXWing } from "./xWing.js";
26
+ const SECP256K1_ECDSA = "ECDSA-secp256k1-SHA256";
27
+ const P256_ECDSA = "ECDSA-P256-SHA256";
28
+ const P384_ECDSA = "ECDSA-P384-SHA384";
29
+ const P521_ECDSA = "ECDSA-P521-SHA512";
30
+ const BIP340_SCHNORR = "BIP340-Schnorr-secp256k1-SHA256";
31
+ const ED25519 = "Ed25519";
32
+ /**
33
+ * Generic package facade. Algorithm-specific objects remain available for
34
+ * callers that want direct provider access; this facade gives consumers a
35
+ * stable typed route that fails closed for not-yet-exposed algorithms.
36
+ */
37
+ export const ReallyMeCrypto = {
38
+ hash(algorithm, bytes) {
39
+ switch (algorithm) {
40
+ case "SHA2-256":
41
+ return ReallyMeDigest.sha256(bytes);
42
+ case "SHA2-384":
43
+ return ReallyMeDigest.sha384(bytes);
44
+ case "SHA2-512":
45
+ return ReallyMeDigest.sha512(bytes);
46
+ case "SHA3-224":
47
+ return ReallyMeDigest.sha3_224(bytes);
48
+ case "SHA3-256":
49
+ return ReallyMeDigest.sha3_256(bytes);
50
+ case "SHA3-384":
51
+ return ReallyMeDigest.sha3_384(bytes);
52
+ case "SHA3-512":
53
+ return ReallyMeDigest.sha3_512(bytes);
54
+ default:
55
+ throw new ReallyMeCryptoError("unsupported-algorithm");
56
+ }
57
+ },
58
+ seal(algorithm, key, nonce, aad, plaintext) {
59
+ switch (algorithm) {
60
+ case "AES-256-GCM":
61
+ case "AES-256-GCM-SIV":
62
+ case "ChaCha20-Poly1305":
63
+ case "XChaCha20-Poly1305":
64
+ return ReallyMeAead.seal(algorithm, key, nonce, aad, plaintext);
65
+ default:
66
+ throw new ReallyMeCryptoError("unsupported-algorithm");
67
+ }
68
+ },
69
+ open(algorithm, key, nonce, aad, ciphertextWithTag) {
70
+ switch (algorithm) {
71
+ case "AES-256-GCM":
72
+ case "AES-256-GCM-SIV":
73
+ case "ChaCha20-Poly1305":
74
+ case "XChaCha20-Poly1305":
75
+ return ReallyMeAead.open(algorithm, key, nonce, aad, ciphertextWithTag);
76
+ default:
77
+ throw new ReallyMeCryptoError("unsupported-algorithm");
78
+ }
79
+ },
80
+ authenticate(algorithm, key, message) {
81
+ switch (algorithm) {
82
+ case "HMAC-SHA-256":
83
+ return ReallyMeHmac.authenticateSha256(key, message);
84
+ case "HMAC-SHA-512":
85
+ return ReallyMeHmac.authenticateSha512(key, message);
86
+ default:
87
+ throw new ReallyMeCryptoError("unsupported-algorithm");
88
+ }
89
+ },
90
+ verifyMac(algorithm, tag, key, message) {
91
+ switch (algorithm) {
92
+ case "HMAC-SHA-256":
93
+ return ReallyMeHmac.verifySha256(tag, key, message);
94
+ case "HMAC-SHA-512":
95
+ return ReallyMeHmac.verifySha512(tag, key, message);
96
+ default:
97
+ throw new ReallyMeCryptoError("unsupported-algorithm");
98
+ }
99
+ },
100
+ deriveKey(algorithm, password, salt, iterations, outputLength) {
101
+ switch (algorithm) {
102
+ case "Argon2id":
103
+ return ReallyMeArgon2id.deriveKey(iterations, password, salt);
104
+ case "PBKDF2-HMAC-SHA-256":
105
+ return ReallyMePbkdf2.deriveHmacSha256(password, salt, iterations, outputLength);
106
+ case "PBKDF2-HMAC-SHA-512":
107
+ return ReallyMePbkdf2.deriveHmacSha512(password, salt, iterations, outputLength);
108
+ case "HKDF-SHA256":
109
+ throw new ReallyMeCryptoError("unsupported-algorithm");
110
+ default:
111
+ throw new ReallyMeCryptoError("unsupported-algorithm");
112
+ }
113
+ },
114
+ deriveHkdf(algorithm, inputKeyMaterial, salt, info, outputLength) {
115
+ switch (algorithm) {
116
+ case "HKDF-SHA256":
117
+ return ReallyMeHkdf.deriveSha256(inputKeyMaterial, salt, info, outputLength);
118
+ case "Argon2id":
119
+ case "PBKDF2-HMAC-SHA-256":
120
+ case "PBKDF2-HMAC-SHA-512":
121
+ throw new ReallyMeCryptoError("unsupported-algorithm");
122
+ default:
123
+ throw new ReallyMeCryptoError("unsupported-algorithm");
124
+ }
125
+ },
126
+ wrapKey(algorithm, wrappingKey, keyToWrap) {
127
+ switch (algorithm) {
128
+ case "AES-256-KW":
129
+ return ReallyMeAesKw.wrapKey(wrappingKey, keyToWrap);
130
+ default:
131
+ throw new ReallyMeCryptoError("unsupported-algorithm");
132
+ }
133
+ },
134
+ unwrapKey(algorithm, wrappingKey, wrappedKey) {
135
+ switch (algorithm) {
136
+ case "AES-256-KW":
137
+ return ReallyMeAesKw.unwrapKey(wrappingKey, wrappedKey);
138
+ default:
139
+ throw new ReallyMeCryptoError("unsupported-algorithm");
140
+ }
141
+ },
142
+ generateKeyPair(algorithm) {
143
+ if (algorithm === ED25519) {
144
+ return ReallyMeEd25519.generateKeyPair();
145
+ }
146
+ switch (algorithm) {
147
+ case P256_ECDSA:
148
+ return ReallyMeP256Ecdsa.generateKeyPair();
149
+ case P384_ECDSA:
150
+ return ReallyMeP384Ecdsa.generateKeyPair();
151
+ case P521_ECDSA:
152
+ return ReallyMeP521Ecdsa.generateKeyPair();
153
+ case SECP256K1_ECDSA:
154
+ return ReallyMeSecp256k1.generateKeyPair();
155
+ case BIP340_SCHNORR:
156
+ return ReallyMeBip340Schnorr.generateKeyPair();
157
+ case "ML-DSA-44":
158
+ case "ML-DSA-65":
159
+ case "ML-DSA-87":
160
+ return ReallyMeMlDsa.generateKeyPair(algorithm);
161
+ case "SLH-DSA-SHA2-128s":
162
+ return ReallyMeSlhDsa.generateKeyPair(algorithm);
163
+ default:
164
+ throw new ReallyMeCryptoError("unsupported-algorithm");
165
+ }
166
+ },
167
+ deriveKeyPair(algorithm, secretKey) {
168
+ if (algorithm === ED25519) {
169
+ return ReallyMeEd25519.deriveKeyPair(secretKey);
170
+ }
171
+ switch (algorithm) {
172
+ case P256_ECDSA:
173
+ return ReallyMeP256Ecdsa.deriveKeyPair(secretKey);
174
+ case P384_ECDSA:
175
+ return ReallyMeP384Ecdsa.deriveKeyPair(secretKey);
176
+ case P521_ECDSA:
177
+ return ReallyMeP521Ecdsa.deriveKeyPair(secretKey);
178
+ case SECP256K1_ECDSA:
179
+ return ReallyMeSecp256k1.deriveKeyPair(secretKey);
180
+ case BIP340_SCHNORR:
181
+ return ReallyMeBip340Schnorr.deriveKeyPair(secretKey);
182
+ case "ML-DSA-44":
183
+ case "ML-DSA-65":
184
+ case "ML-DSA-87":
185
+ return ReallyMeMlDsa.deriveKeyPair(algorithm, secretKey);
186
+ default:
187
+ throw new ReallyMeCryptoError("unsupported-algorithm");
188
+ }
189
+ },
190
+ sign(algorithm, message, secretKey) {
191
+ if (algorithm === ED25519) {
192
+ return ReallyMeEd25519.sign(message, secretKey);
193
+ }
194
+ switch (algorithm) {
195
+ case P256_ECDSA:
196
+ return ReallyMeP256Ecdsa.sign(message, secretKey);
197
+ case P384_ECDSA:
198
+ return ReallyMeP384Ecdsa.sign(message, secretKey);
199
+ case P521_ECDSA:
200
+ return ReallyMeP521Ecdsa.sign(message, secretKey);
201
+ case SECP256K1_ECDSA:
202
+ return ReallyMeSecp256k1.sign(message, secretKey);
203
+ case "ML-DSA-44":
204
+ case "ML-DSA-65":
205
+ case "ML-DSA-87":
206
+ return ReallyMeMlDsa.sign(algorithm, message, secretKey);
207
+ case "SLH-DSA-SHA2-128s":
208
+ return ReallyMeSlhDsa.sign(algorithm, message, secretKey);
209
+ default:
210
+ throw new ReallyMeCryptoError("unsupported-algorithm");
211
+ }
212
+ },
213
+ signBip340Schnorr(message32, secretKey, auxRand32) {
214
+ return ReallyMeBip340Schnorr.sign(message32, secretKey, auxRand32);
215
+ },
216
+ verify(algorithm, signature, message, publicKey) {
217
+ if (algorithm === ED25519) {
218
+ ReallyMeEd25519.verify(signature, message, publicKey);
219
+ return;
220
+ }
221
+ switch (algorithm) {
222
+ case P256_ECDSA:
223
+ ReallyMeP256Ecdsa.verify(signature, message, publicKey);
224
+ return;
225
+ case P384_ECDSA:
226
+ ReallyMeP384Ecdsa.verify(signature, message, publicKey);
227
+ return;
228
+ case P521_ECDSA:
229
+ ReallyMeP521Ecdsa.verify(signature, message, publicKey);
230
+ return;
231
+ case SECP256K1_ECDSA:
232
+ ReallyMeSecp256k1.verify(signature, message, publicKey);
233
+ return;
234
+ case BIP340_SCHNORR:
235
+ ReallyMeBip340Schnorr.verify(signature, message, publicKey);
236
+ return;
237
+ case "ML-DSA-44":
238
+ case "ML-DSA-65":
239
+ case "ML-DSA-87":
240
+ ReallyMeMlDsa.verify(algorithm, signature, message, publicKey);
241
+ return;
242
+ case "SLH-DSA-SHA2-128s":
243
+ ReallyMeSlhDsa.verify(algorithm, signature, message, publicKey);
244
+ return;
245
+ default:
246
+ throw new ReallyMeCryptoError("unsupported-algorithm");
247
+ }
248
+ },
249
+ verifyRsa(algorithm, signature, message, publicKeyDer, publicKeyEncoding) {
250
+ ReallyMeRsa.verify(algorithm, signature, message, publicKeyDer, publicKeyEncoding);
251
+ },
252
+ deriveSharedSecret(algorithm, publicKey, secretKey) {
253
+ switch (algorithm) {
254
+ case "X25519":
255
+ return ReallyMeX25519.deriveSharedSecret(publicKey, secretKey);
256
+ case "P-256-ECDH":
257
+ return ReallyMeP256Ecdh.deriveSharedSecret(publicKey, secretKey);
258
+ default:
259
+ throw new ReallyMeCryptoError("unsupported-algorithm");
260
+ }
261
+ },
262
+ deriveKeyAgreementKeyPair(algorithm, secretKey) {
263
+ switch (algorithm) {
264
+ case "X25519":
265
+ return ReallyMeX25519.deriveKeyPair(secretKey);
266
+ case "P-256-ECDH":
267
+ return ReallyMeP256Ecdh.deriveKeyPair(secretKey);
268
+ default:
269
+ throw new ReallyMeCryptoError("unsupported-algorithm");
270
+ }
271
+ },
272
+ generateKemKeyPair(algorithm) {
273
+ switch (algorithm) {
274
+ case "X-Wing-768":
275
+ case "X-Wing-1024":
276
+ return ReallyMeXWing.generateKeyPair(algorithm);
277
+ case "ML-KEM-512":
278
+ case "ML-KEM-768":
279
+ case "ML-KEM-1024":
280
+ return ReallyMeMlKem.generateKeyPair(algorithm);
281
+ default:
282
+ throw new ReallyMeCryptoError("unsupported-algorithm");
283
+ }
284
+ },
285
+ encapsulate(algorithm, publicKey) {
286
+ switch (algorithm) {
287
+ case "X-Wing-768":
288
+ case "X-Wing-1024":
289
+ return ReallyMeXWing.encapsulate(algorithm, publicKey);
290
+ case "ML-KEM-512":
291
+ case "ML-KEM-768":
292
+ case "ML-KEM-1024":
293
+ return ReallyMeMlKem.encapsulate(algorithm, publicKey);
294
+ default:
295
+ throw new ReallyMeCryptoError("unsupported-algorithm");
296
+ }
297
+ },
298
+ decapsulate(algorithm, ciphertext, secretKey) {
299
+ switch (algorithm) {
300
+ case "X-Wing-768":
301
+ case "X-Wing-1024":
302
+ return ReallyMeXWing.decapsulate(algorithm, ciphertext, secretKey);
303
+ case "ML-KEM-512":
304
+ case "ML-KEM-768":
305
+ case "ML-KEM-1024":
306
+ return ReallyMeMlKem.decapsulate(algorithm, ciphertext, secretKey);
307
+ default:
308
+ throw new ReallyMeCryptoError("unsupported-algorithm");
309
+ }
310
+ },
311
+ sealHpke(suite, recipientPublicKey, info, aad, plaintext) {
312
+ switch (suite) {
313
+ case "DHKEM-P256-HKDF-SHA256-HKDF-SHA256-AES-256-GCM":
314
+ case "DHKEM-X25519-HKDF-SHA256-HKDF-SHA256-CHACHA20-POLY1305":
315
+ return ReallyMeHpke.sealBase(suite, recipientPublicKey, info, aad, plaintext);
316
+ default:
317
+ throw new ReallyMeCryptoError("unsupported-algorithm");
318
+ }
319
+ },
320
+ openHpke(suite, recipientSecretKey, encapsulatedKey, info, aad, ciphertext) {
321
+ switch (suite) {
322
+ case "DHKEM-P256-HKDF-SHA256-HKDF-SHA256-AES-256-GCM":
323
+ case "DHKEM-X25519-HKDF-SHA256-HKDF-SHA256-CHACHA20-POLY1305":
324
+ return ReallyMeHpke.openBase(suite, recipientSecretKey, encapsulatedKey, info, aad, ciphertext);
325
+ default:
326
+ throw new ReallyMeCryptoError("unsupported-algorithm");
327
+ }
328
+ },
329
+ };
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Small digest surface used by package tests and as the first package API
3
+ * slice while algorithm wrappers are added one at a time. Mirrors the Swift
4
+ * package's `ReallyMeDigest` and the Kotlin package's `ReallyMeDigest`.
5
+ */
6
+ export declare const ReallyMeDigest: {
7
+ readonly sha256: (bytes: Uint8Array) => Uint8Array;
8
+ readonly sha384: (bytes: Uint8Array) => Uint8Array;
9
+ readonly sha512: (bytes: Uint8Array) => Uint8Array;
10
+ readonly sha3_224: (bytes: Uint8Array) => Uint8Array;
11
+ readonly sha3_256: (bytes: Uint8Array) => Uint8Array;
12
+ readonly sha3_384: (bytes: Uint8Array) => Uint8Array;
13
+ readonly sha3_512: (bytes: Uint8Array) => Uint8Array;
14
+ };
package/dist/digest.js ADDED
@@ -0,0 +1,33 @@
1
+ // SPDX-FileCopyrightText: Copyright © 2026 ReallyMe LLC. All rights reserved
2
+ //
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ import { sha256 as nobleSha256, sha384 as nobleSha384, sha512 as nobleSha512 } from "@noble/hashes/sha2.js";
5
+ import { sha3_224 as nobleSha3_224, sha3_256 as nobleSha3_256, sha3_384 as nobleSha3_384, sha3_512 as nobleSha3_512, } from "@noble/hashes/sha3.js";
6
+ /**
7
+ * Small digest surface used by package tests and as the first package API
8
+ * slice while algorithm wrappers are added one at a time. Mirrors the Swift
9
+ * package's `ReallyMeDigest` and the Kotlin package's `ReallyMeDigest`.
10
+ */
11
+ export const ReallyMeDigest = {
12
+ sha256(bytes) {
13
+ return nobleSha256(bytes);
14
+ },
15
+ sha384(bytes) {
16
+ return nobleSha384(bytes);
17
+ },
18
+ sha512(bytes) {
19
+ return nobleSha512(bytes);
20
+ },
21
+ sha3_224(bytes) {
22
+ return nobleSha3_224(bytes);
23
+ },
24
+ sha3_256(bytes) {
25
+ return nobleSha3_256(bytes);
26
+ },
27
+ sha3_384(bytes) {
28
+ return nobleSha3_384(bytes);
29
+ },
30
+ sha3_512(bytes) {
31
+ return nobleSha3_512(bytes);
32
+ },
33
+ };
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Ed25519 signatures backed by @noble/curves — the same pinned implementation
3
+ * the TypeScript conformance lane proves vectors against.
4
+ *
5
+ * The workspace contract uses the plain Ed25519 variant: callers pass the full
6
+ * message, the provider signs that message directly, and signatures are the
7
+ * 64-byte RFC 8032 encoding. Ed25519 is deterministic, so the same key and
8
+ * message must produce the same bytes in every platform lane.
9
+ */
10
+ export declare const ED25519_SECRET_KEY_LENGTH = 32;
11
+ export declare const ED25519_PUBLIC_KEY_LENGTH = 32;
12
+ export declare const ED25519_SIGNATURE_LENGTH = 64;
13
+ export declare const ReallyMeEd25519: {
14
+ /** Generates a random Ed25519 keypair: 32-byte public key, 32-byte seed. */
15
+ readonly generateKeyPair: () => {
16
+ publicKey: Uint8Array;
17
+ secretKey: Uint8Array;
18
+ };
19
+ /** Derives the Ed25519 keypair from a 32-byte seed. */
20
+ readonly deriveKeyPair: (secretKey: Uint8Array) => {
21
+ publicKey: Uint8Array;
22
+ secretKey: Uint8Array;
23
+ };
24
+ /** Derives the 32-byte Ed25519 public key from a 32-byte seed. */
25
+ readonly derivePublicKey: (secretKey: Uint8Array) => Uint8Array;
26
+ /** Signs the full message using plain deterministic Ed25519. */
27
+ readonly sign: (message: Uint8Array, secretKey: Uint8Array) => Uint8Array;
28
+ /**
29
+ * Verifies a 64-byte Ed25519 signature against a 32-byte public key.
30
+ *
31
+ * Throws on malformed input shape, undecodable keys, or invalid signatures.
32
+ */
33
+ readonly verify: (signature: Uint8Array, message: Uint8Array, publicKey: Uint8Array) => void;
34
+ };