@reallyme/crypto 0.4.2 → 0.4.5

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/dist/rsa.js CHANGED
@@ -3,7 +3,7 @@
3
3
  // SPDX-License-Identifier: MIT OR Apache-2.0
4
4
  import { ReallyMeCryptoError } from "./errors.js";
5
5
  import { ensureByteArray, ensureByteArrayAtMost, MAX_CRYPTO_INPUT_LENGTH, } from "./validateBytes.js";
6
- import { requireReallyMeWasmProvider } from "./wasmProvider.js";
6
+ import { requireReallyMeWasmProvider, requireTrustedReallyMeWasmProvider } from "./wasmProvider.js";
7
7
  export const RSA_PUBLIC_KEY_DER_MAX_LENGTH = 4_096;
8
8
  export const RSA_SIGNATURE_MAX_LENGTH = 1_024;
9
9
  const RSA_HASH_SHA1 = 1;
@@ -78,6 +78,7 @@ const readVoid = (value) => {
78
78
  }
79
79
  };
80
80
  const verifyWithProvider = (provider, algorithm, signature, message, publicKeyDer, publicKeyEncoding) => {
81
+ requireTrustedReallyMeWasmProvider(provider);
81
82
  validateBytes(publicKeyDer, RSA_PUBLIC_KEY_DER_MAX_LENGTH);
82
83
  validateBytes(signature, RSA_SIGNATURE_MAX_LENGTH);
83
84
  ensureByteArrayAtMost(message, MAX_CRYPTO_INPUT_LENGTH);
package/dist/slhDsa.js CHANGED
@@ -3,7 +3,7 @@
3
3
  // SPDX-License-Identifier: MIT OR Apache-2.0
4
4
  import { ReallyMeCryptoError } from "./errors.js";
5
5
  import { ensureByteArrayAtMost, ensureBytes, ensureIndependentByteArray, MAX_CRYPTO_INPUT_LENGTH, readIndependentByteArrayProperty, } from "./validateBytes.js";
6
- import { requireReallyMeWasmProvider } from "./wasmProvider.js";
6
+ import { requireReallyMeWasmProvider, requireTrustedReallyMeWasmProvider } from "./wasmProvider.js";
7
7
  export const SLH_DSA_SHA2_128S_PUBLIC_KEY_LENGTH = 32;
8
8
  export const SLH_DSA_SHA2_128S_SECRET_KEY_LENGTH = 64;
9
9
  export const SLH_DSA_SHA2_128S_SIGNATURE_LENGTH = 7_856;
@@ -41,6 +41,7 @@ export const ReallyMeSlhDsa = {
41
41
  return readKeyPair(requireReallyMeWasmProvider().slhDsaSha2128sGenerateKeypair());
42
42
  },
43
43
  generateKeyPairWithProvider(provider, algorithm) {
44
+ requireTrustedReallyMeWasmProvider(provider);
44
45
  assertSlhDsa(algorithm);
45
46
  return readKeyPair(provider.slhDsaSha2128sGenerateKeypair());
46
47
  },
@@ -51,6 +52,7 @@ export const ReallyMeSlhDsa = {
51
52
  return readSignature(requireReallyMeWasmProvider().slhDsaSha2128sSign(secretKey, message), [secretKey, message]);
52
53
  },
53
54
  signWithProvider(provider, algorithm, message, secretKey) {
55
+ requireTrustedReallyMeWasmProvider(provider);
54
56
  assertSlhDsa(algorithm);
55
57
  ensureByteArrayAtMost(message, MAX_CRYPTO_INPUT_LENGTH);
56
58
  ensureBytes(secretKey, SLH_DSA_SHA2_128S_SECRET_KEY_LENGTH);
@@ -64,6 +66,7 @@ export const ReallyMeSlhDsa = {
64
66
  readVoid(requireReallyMeWasmProvider().slhDsaSha2128sVerify(publicKey, message, signature));
65
67
  },
66
68
  verifyWithProvider(provider, algorithm, signature, message, publicKey) {
69
+ requireTrustedReallyMeWasmProvider(provider);
67
70
  assertSlhDsa(algorithm);
68
71
  ensureByteArrayAtMost(message, MAX_CRYPTO_INPUT_LENGTH);
69
72
  ensureBytes(publicKey, SLH_DSA_SHA2_128S_PUBLIC_KEY_LENGTH);
@@ -78,6 +81,7 @@ export const deriveSlhDsaSha2128sKeypairForTest = (skSeed, skPrf, pkSeed) => {
78
81
  return readKeyPair(requireReallyMeWasmProvider().slhDsaSha2128sDeriveKeypair(skSeed, skPrf, pkSeed), [skSeed, skPrf, pkSeed]);
79
82
  };
80
83
  export const deriveSlhDsaSha2128sKeypairWithProviderForTest = (provider, skSeed, skPrf, pkSeed) => {
84
+ requireTrustedReallyMeWasmProvider(provider);
81
85
  ensureBytes(skSeed, SLH_DSA_SHA2_128S_KEYGEN_SEED_LENGTH);
82
86
  ensureBytes(skPrf, SLH_DSA_SHA2_128S_KEYGEN_SEED_LENGTH);
83
87
  ensureBytes(pkSeed, SLH_DSA_SHA2_128S_KEYGEN_SEED_LENGTH);
@@ -6,3 +6,4 @@ export declare const byteArraysOverlap: (left: Uint8Array, right: Uint8Array) =>
6
6
  export declare const ensureIndependentByteArray: (value: Uint8Array, disallowedViews: ReadonlyArray<Uint8Array>) => void;
7
7
  export declare const readIndependentByteArrayProperty: (value: unknown, propertyName: string, expectedLength: number, disallowedViews: ReadonlyArray<Uint8Array>) => Uint8Array;
8
8
  export declare const readIndependentProviderBytes: (value: unknown, expectedLength: number, disallowedViews: ReadonlyArray<Uint8Array>) => Uint8Array;
9
+ export declare const readIndependentProviderBytesInRange: (value: unknown, minimumLength: number, maximumLength: number, disallowedViews: ReadonlyArray<Uint8Array>) => Uint8Array;
@@ -82,13 +82,16 @@ export const readIndependentByteArrayProperty = (value, propertyName, expectedLe
82
82
  return property;
83
83
  };
84
84
  export const readIndependentProviderBytes = (value, expectedLength, disallowedViews) => {
85
+ return readIndependentProviderBytesInRange(value, expectedLength, expectedLength, disallowedViews);
86
+ };
87
+ export const readIndependentProviderBytesInRange = (value, minimumLength, maximumLength, disallowedViews) => {
85
88
  if (!(value instanceof Uint8Array)) {
86
89
  throw new ReallyMeCryptoError("provider-failure");
87
90
  }
88
91
  // Provider-owned secret outputs are cleared on malformed length, but only
89
92
  // after proving the provider did not hand back a caller-owned buffer.
90
93
  ensureIndependentByteArray(value, disallowedViews);
91
- if (value.length !== expectedLength) {
94
+ if (value.length < minimumLength || value.length > maximumLength) {
92
95
  value.fill(0);
93
96
  throw new ReallyMeCryptoError("provider-failure");
94
97
  }
@@ -0,0 +1 @@
1
+ export declare function ensureStandardSec1PublicKey(value: unknown, compressedLength: number, uncompressedLength: number): asserts value is Uint8Array;
@@ -0,0 +1,23 @@
1
+ // SPDX-FileCopyrightText: 2026 ReallyMe Technologies Limited
2
+ //
3
+ // SPDX-License-Identifier: MIT OR Apache-2.0
4
+ import { ReallyMeCryptoError } from "./errors.js";
5
+ import { ensureByteArray } from "./validateBytes.js";
6
+ const SEC1_COMPRESSED_EVEN_PREFIX = 0x02;
7
+ const SEC1_COMPRESSED_ODD_PREFIX = 0x03;
8
+ const SEC1_UNCOMPRESSED_PREFIX = 0x04;
9
+ // Keep accepted representations independent of a provider's point parser.
10
+ // The caller must still validate curve membership after this shape check.
11
+ export function ensureStandardSec1PublicKey(value, compressedLength, uncompressedLength) {
12
+ ensureByteArray(value);
13
+ const prefix = value[0];
14
+ const compressed = value.length === compressedLength &&
15
+ (prefix === SEC1_COMPRESSED_EVEN_PREFIX || prefix === SEC1_COMPRESSED_ODD_PREFIX);
16
+ const uncompressed = value.length === uncompressedLength && prefix === SEC1_UNCOMPRESSED_PREFIX;
17
+ // Admit only standard SEC1 shapes. Curve membership and non-identity checks
18
+ // remain with the provider so accepting uncompressed keys does not also
19
+ // admit hybrid tags, compact aliases, or points on a different curve.
20
+ if (!compressed && !uncompressed) {
21
+ throw new ReallyMeCryptoError("invalid-input");
22
+ }
23
+ }
@@ -1,4 +1,4 @@
1
- import { processOperationResponse, processOperationResponseJson, aes128GcmSeal, aes128GcmOpen, aes192GcmSeal, aes192GcmOpen, aes256GcmSeal, aes256GcmOpen, aes256GcmSivSeal, aes256GcmSivOpen, chacha20Poly1305Seal, chacha20Poly1305Open, xchacha20Poly1305Seal, xchacha20Poly1305Open, aes128KwWrapKey, aes128KwUnwrapKey, aes192KwWrapKey, aes192KwUnwrapKey, aes256KwWrapKey, aes256KwUnwrapKey, argon2idDeriveKey, kmac256Derive, hpkeSealBase, hpkeOpenBase, mlDsa44GenerateKeypair, mlDsa44DeriveKeypair, mlDsa44Sign, mlDsa44Verify, mlDsa65GenerateKeypair, mlDsa65DeriveKeypair, mlDsa65Sign, mlDsa65Verify, mlDsa87GenerateKeypair, mlDsa87DeriveKeypair, mlDsa87Sign, mlDsa87Verify, mlKem512GenerateKeypair, mlKem512DeriveKeypair, mlKem512Encapsulate, mlKem512Decapsulate, mlKem768GenerateKeypair, mlKem768DeriveKeypair, mlKem768Encapsulate, mlKem768Decapsulate, mlKem1024GenerateKeypair, mlKem1024DeriveKeypair, mlKem1024Encapsulate, mlKem1024Decapsulate, slhDsaSha2128sGenerateKeypair, slhDsaSha2128sDeriveKeypair, slhDsaSha2128sSign, slhDsaSha2128sVerify, rsaVerifyPkcs1v15, rsaVerifyPss, xWing768GenerateKeypair, xWing768DeriveKeypair, xWing768Encapsulate, xWing768Decapsulate } from "../dist/wasm/reallyme_crypto_wasm.js";
1
+ import { processOperationResponse, processOperationResponseJson, aes128GcmSeal, aes128GcmOpen, aes192GcmSeal, aes192GcmOpen, aes256GcmSeal, aes256GcmOpen, aes256GcmSivSeal, aes256GcmSivOpen, chacha20Poly1305Seal, chacha20Poly1305Open, xchacha20Poly1305Seal, xchacha20Poly1305Open, aes128KwWrapKey, aes128KwUnwrapKey, aes192KwWrapKey, aes192KwUnwrapKey, aes256KwWrapKey, aes256KwUnwrapKey, argon2idDeriveKey, kmac256Derive, hpkeSealBase, hpkeOpenBase, mlDsa44GenerateKeypair, mlDsa44DeriveKeypair, mlDsa44Sign, mlDsa44Verify, mlDsa65GenerateKeypair, mlDsa65DeriveKeypair, mlDsa65Sign, mlDsa65Verify, mlDsa87GenerateKeypair, mlDsa87DeriveKeypair, mlDsa87Sign, mlDsa87Verify, mlKem512GenerateKeypair, mlKem512DeriveKeypair, mlKem512Encapsulate, mlKem512Decapsulate, mlKem768GenerateKeypair, mlKem768DeriveKeypair, mlKem768Encapsulate, mlKem768Decapsulate, mlKem1024GenerateKeypair, mlKem1024DeriveKeypair, mlKem1024Encapsulate, mlKem1024Decapsulate, slhDsaSha2128sGenerateKeypair, slhDsaSha2128sDeriveKeypair, slhDsaSha2128sSign, slhDsaSha2128sVerify, rsaVerifyPkcs1v15, rsaVerifyPss, xWing768GenerateKeypair, xWing768DeriveKeypair, xWing768Encapsulate, xWing768Decapsulate } from "./wasm/reallyme_crypto_wasm.js";
2
2
  export declare const bundledWasmFunctions: Readonly<{
3
3
  processOperationResponse: typeof processOperationResponse;
4
4
  processOperationResponseJson: typeof processOperationResponseJson;
@@ -1,7 +1,7 @@
1
1
  // SPDX-FileCopyrightText: 2026 ReallyMe Technologies Limited
2
2
  //
3
3
  // SPDX-License-Identifier: MIT OR Apache-2.0
4
- import { processOperationResponse, processOperationResponseJson, aes128GcmSeal, aes128GcmOpen, aes192GcmSeal, aes192GcmOpen, aes256GcmSeal, aes256GcmOpen, aes256GcmSivSeal, aes256GcmSivOpen, chacha20Poly1305Seal, chacha20Poly1305Open, xchacha20Poly1305Seal, xchacha20Poly1305Open, aes128KwWrapKey, aes128KwUnwrapKey, aes192KwWrapKey, aes192KwUnwrapKey, aes256KwWrapKey, aes256KwUnwrapKey, argon2idDeriveKey, kmac256Derive, hpkeSealBase, hpkeOpenBase, mlDsa44GenerateKeypair, mlDsa44DeriveKeypair, mlDsa44Sign, mlDsa44Verify, mlDsa65GenerateKeypair, mlDsa65DeriveKeypair, mlDsa65Sign, mlDsa65Verify, mlDsa87GenerateKeypair, mlDsa87DeriveKeypair, mlDsa87Sign, mlDsa87Verify, mlKem512GenerateKeypair, mlKem512DeriveKeypair, mlKem512Encapsulate, mlKem512Decapsulate, mlKem768GenerateKeypair, mlKem768DeriveKeypair, mlKem768Encapsulate, mlKem768Decapsulate, mlKem1024GenerateKeypair, mlKem1024DeriveKeypair, mlKem1024Encapsulate, mlKem1024Decapsulate, slhDsaSha2128sGenerateKeypair, slhDsaSha2128sDeriveKeypair, slhDsaSha2128sSign, slhDsaSha2128sVerify, rsaVerifyPkcs1v15, rsaVerifyPss, xWing768GenerateKeypair, xWing768DeriveKeypair, xWing768Encapsulate, xWing768Decapsulate, } from "../dist/wasm/reallyme_crypto_wasm.js";
4
+ import { processOperationResponse, processOperationResponseJson, aes128GcmSeal, aes128GcmOpen, aes192GcmSeal, aes192GcmOpen, aes256GcmSeal, aes256GcmOpen, aes256GcmSivSeal, aes256GcmSivOpen, chacha20Poly1305Seal, chacha20Poly1305Open, xchacha20Poly1305Seal, xchacha20Poly1305Open, aes128KwWrapKey, aes128KwUnwrapKey, aes192KwWrapKey, aes192KwUnwrapKey, aes256KwWrapKey, aes256KwUnwrapKey, argon2idDeriveKey, kmac256Derive, hpkeSealBase, hpkeOpenBase, mlDsa44GenerateKeypair, mlDsa44DeriveKeypair, mlDsa44Sign, mlDsa44Verify, mlDsa65GenerateKeypair, mlDsa65DeriveKeypair, mlDsa65Sign, mlDsa65Verify, mlDsa87GenerateKeypair, mlDsa87DeriveKeypair, mlDsa87Sign, mlDsa87Verify, mlKem512GenerateKeypair, mlKem512DeriveKeypair, mlKem512Encapsulate, mlKem512Decapsulate, mlKem768GenerateKeypair, mlKem768DeriveKeypair, mlKem768Encapsulate, mlKem768Decapsulate, mlKem1024GenerateKeypair, mlKem1024DeriveKeypair, mlKem1024Encapsulate, mlKem1024Decapsulate, slhDsaSha2128sGenerateKeypair, slhDsaSha2128sDeriveKeypair, slhDsaSha2128sSign, slhDsaSha2128sVerify, rsaVerifyPkcs1v15, rsaVerifyPss, xWing768GenerateKeypair, xWing768DeriveKeypair, xWing768Encapsulate, xWing768Decapsulate, } from "./wasm/reallyme_crypto_wasm.js";
5
5
  export const bundledWasmFunctions = Object.freeze({
6
6
  processOperationResponse,
7
7
  processOperationResponseJson,
package/dist/xWing.js CHANGED
@@ -3,7 +3,7 @@
3
3
  // SPDX-License-Identifier: MIT OR Apache-2.0
4
4
  import { ReallyMeCryptoError } from "./errors.js";
5
5
  import { ensureBytes, readIndependentByteArrayProperty, readIndependentProviderBytes, } from "./validateBytes.js";
6
- import { requireReallyMeWasmProvider } from "./wasmProvider.js";
6
+ import { requireReallyMeWasmProvider, requireTrustedReallyMeWasmProvider } from "./wasmProvider.js";
7
7
  export const X_WING_SECRET_KEY_LENGTH = 32;
8
8
  export const X_WING_SHARED_SECRET_LENGTH = 32;
9
9
  export const X_WING_768_PUBLIC_KEY_LENGTH = 1_216;
@@ -12,6 +12,7 @@ const xWingSuite = (algorithm) => {
12
12
  return xWingSuiteWithProvider(algorithm, requireReallyMeWasmProvider());
13
13
  };
14
14
  const xWingSuiteWithProvider = (algorithm, provider) => {
15
+ requireTrustedReallyMeWasmProvider(provider);
15
16
  switch (algorithm) {
16
17
  case "ML-KEM-512":
17
18
  case "ML-KEM-768":
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reallyme/crypto",
3
- "version": "0.4.2",
3
+ "version": "0.4.5",
4
4
  "description": "ReallyMe crypto SDK for TypeScript/JavaScript with an explicit, pinned provider set.",
5
5
  "license": "MIT OR Apache-2.0",
6
6
  "repository": {
@@ -46,7 +46,7 @@
46
46
  "build:ts": "tsc",
47
47
  "build:wasm": "node scripts/build-wasm.mjs",
48
48
  "pack:check": "node scripts/check-pack.mjs",
49
- "prepack": "npm run build",
49
+ "prepack": "npm run build && node scripts/check-pack.mjs --use-built",
50
50
  "prepublishOnly": "npm test && npm run pack:check",
51
51
  "typecheck": "npm run build:wasm && tsc --noEmit",
52
52
  "test": "npm run build && node --test \"test/*.test.mjs\"",
@@ -56,10 +56,11 @@
56
56
  "@bufbuild/protobuf": "2.17.0",
57
57
  "@noble/curves": "2.4.0",
58
58
  "@noble/hashes": "2.4.0",
59
- "@reallyme/codec": "0.4.3"
59
+ "@reallyme/codec": "0.4.5"
60
60
  },
61
61
  "devDependencies": {
62
- "typescript": "7.0.2"
62
+ "typescript": "7.0.2",
63
+ "@bufbuild/protoc-gen-es": "2.17.0"
63
64
  },
64
65
  "engines": {
65
66
  "node": ">=20.19.0"