@sebastienrousseau/crypto-react 0.0.9 → 0.0.25

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.
@@ -0,0 +1,22 @@
1
+ import { type CryptoTransformStream } from "@sebastienrousseau/crypto-lib/streaming";
2
+ export interface PqRecipientPublicKeys {
3
+ x25519PublicKey: string | Uint8Array;
4
+ mlKemPublicKey: string | Uint8Array;
5
+ }
6
+ export interface PqRecipientSecretKeys {
7
+ x25519SecretKey: string | Uint8Array;
8
+ mlKemSecretKey: string | Uint8Array;
9
+ }
10
+ export interface UsePqStreamResult {
11
+ encrypt: (plaintext: string | Uint8Array, keys: PqRecipientPublicKeys, chunkSize?: number) => Promise<Uint8Array>;
12
+ decrypt: (ciphertext: Uint8Array, keys: PqRecipientSecretKeys, chunkSize?: number) => Promise<Uint8Array>;
13
+ createEncryptStream: (keys: PqRecipientPublicKeys, chunkSize?: number) => CryptoTransformStream<Uint8Array, Uint8Array>;
14
+ createDecryptStream: (keys: PqRecipientSecretKeys, chunkSize?: number) => CryptoTransformStream<Uint8Array, Uint8Array>;
15
+ ciphertext: Uint8Array | null;
16
+ plaintext: Uint8Array | null;
17
+ chunkCount: number | null;
18
+ isProcessing: boolean;
19
+ clear: () => void;
20
+ }
21
+ export declare function usePqStream(): UsePqStreamResult;
22
+ //# sourceMappingURL=usePqStream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePqStream.d.ts","sourceRoot":"","sources":["../../src/hooks/usePqStream.ts"],"names":[],"mappings":"AAIA,OAAO,EAKL,KAAK,qBAAqB,EAC3B,MAAM,yCAAyC,CAAC;AAGjD,MAAM,WAAW,qBAAqB;IAEpC,eAAe,EAAE,MAAM,GAAG,UAAU,CAAC;IAErC,cAAc,EAAE,MAAM,GAAG,UAAU,CAAC;CACrC;AAGD,MAAM,WAAW,qBAAqB;IAEpC,eAAe,EAAE,MAAM,GAAG,UAAU,CAAC;IAErC,cAAc,EAAE,MAAM,GAAG,UAAU,CAAC;CACrC;AAGD,MAAM,WAAW,iBAAiB;IAEhC,OAAO,EAAE,CACP,SAAS,EAAE,MAAM,GAAG,UAAU,EAC9B,IAAI,EAAE,qBAAqB,EAC3B,SAAS,CAAC,EAAE,MAAM,KACf,OAAO,CAAC,UAAU,CAAC,CAAC;IAEzB,OAAO,EAAE,CACP,UAAU,EAAE,UAAU,EACtB,IAAI,EAAE,qBAAqB,EAC3B,SAAS,CAAC,EAAE,MAAM,KACf,OAAO,CAAC,UAAU,CAAC,CAAC;IAEzB,mBAAmB,EAAE,CACnB,IAAI,EAAE,qBAAqB,EAC3B,SAAS,CAAC,EAAE,MAAM,KACf,qBAAqB,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAEnD,mBAAmB,EAAE,CACnB,IAAI,EAAE,qBAAqB,EAC3B,SAAS,CAAC,EAAE,MAAM,KACf,qBAAqB,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAEnD,UAAU,EAAE,UAAU,GAAG,IAAI,CAAC;IAE9B,SAAS,EAAE,UAAU,GAAG,IAAI,CAAC;IAE7B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAE1B,YAAY,EAAE,OAAO,CAAC;IAEtB,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AA6DD,wBAAgB,WAAW,IAAI,iBAAiB,CAsD/C"}
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.usePqStream = usePqStream;
4
+ const react_1 = require("react");
5
+ const streaming_1 = require("@sebastienrousseau/crypto-lib/streaming");
6
+ function toUint8Array(input) {
7
+ return typeof input === "string" ? new TextEncoder().encode(input) : input;
8
+ }
9
+ function executePqEncrypt(pt, keys, chunkSize) {
10
+ const rawPt = toUint8Array(pt);
11
+ const res = (0, streaming_1.streamPqEncrypt)({
12
+ recipientX25519Public: keys.x25519PublicKey,
13
+ recipientMlKemPublic: keys.mlKemPublicKey,
14
+ plaintext: rawPt,
15
+ chunkSize,
16
+ });
17
+ const sz = chunkSize ?? 65536;
18
+ const chunkCount = Math.max(1, Math.ceil(rawPt.length / sz));
19
+ return { ciphertext: res.ciphertext, chunkCount };
20
+ }
21
+ function executePqDecrypt(ct, keys, chunkSize) {
22
+ return (0, streaming_1.streamPqDecrypt)({
23
+ recipientX25519Secret: keys.x25519SecretKey,
24
+ recipientMlKemSecret: keys.mlKemSecretKey,
25
+ ciphertext: ct,
26
+ chunkSize,
27
+ });
28
+ }
29
+ function createPqEncStream(k, sz) {
30
+ return (0, streaming_1.createPqEncryptStream)({
31
+ recipientX25519Public: k.x25519PublicKey,
32
+ recipientMlKemPublic: k.mlKemPublicKey,
33
+ chunkSize: sz,
34
+ });
35
+ }
36
+ function createPqDecStream(k, sz) {
37
+ return (0, streaming_1.createPqDecryptStream)({
38
+ recipientX25519Secret: k.x25519SecretKey,
39
+ recipientMlKemSecret: k.mlKemSecretKey,
40
+ chunkSize: sz,
41
+ });
42
+ }
43
+ function usePqStream() {
44
+ const [ciphertext, setCiphertext] = (0, react_1.useState)(null);
45
+ const [plaintext, setPlaintext] = (0, react_1.useState)(null);
46
+ const [chunkCount, setChunkCount] = (0, react_1.useState)(null);
47
+ const [isProcessing, setIsProcessing] = (0, react_1.useState)(false);
48
+ const encrypt = (0, react_1.useCallback)(async (pt, keys, sz) => {
49
+ setIsProcessing(true);
50
+ try {
51
+ const res = executePqEncrypt(pt, keys, sz);
52
+ setCiphertext(res.ciphertext);
53
+ setChunkCount(res.chunkCount);
54
+ return res.ciphertext;
55
+ }
56
+ finally {
57
+ setIsProcessing(false);
58
+ }
59
+ }, []);
60
+ const decrypt = (0, react_1.useCallback)(async (ct, keys, sz) => {
61
+ setIsProcessing(true);
62
+ try {
63
+ const res = executePqDecrypt(ct, keys, sz);
64
+ setPlaintext(res);
65
+ return res;
66
+ }
67
+ finally {
68
+ setIsProcessing(false);
69
+ }
70
+ }, []);
71
+ return {
72
+ encrypt,
73
+ decrypt,
74
+ createEncryptStream: createPqEncStream,
75
+ createDecryptStream: createPqDecStream,
76
+ ciphertext,
77
+ plaintext,
78
+ chunkCount,
79
+ isProcessing,
80
+ clear: () => {
81
+ setCiphertext(null);
82
+ setPlaintext(null);
83
+ setChunkCount(null);
84
+ },
85
+ };
86
+ }
87
+ //# sourceMappingURL=usePqStream.js.map
package/dist/index.d.ts CHANGED
@@ -3,4 +3,5 @@ export { useKeypair, type UseKeypairResult } from "./hooks/useKeypair";
3
3
  export { useEncrypt, type UseEncryptResult } from "./hooks/useEncrypt";
4
4
  export { useHash, type UseHashResult } from "./hooks/useHash";
5
5
  export { useSignature, type UseSignatureResult } from "./hooks/useSignature";
6
+ export { usePqStream, type UsePqStreamResult, type PqRecipientPublicKeys, type PqRecipientSecretKeys, } from "./hooks/usePqStream";
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,GACzB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,UAAU,EAAE,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAAE,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,KAAK,kBAAkB,EAAE,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,GACzB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,UAAU,EAAE,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAAE,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,KAAK,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EACL,WAAW,EACX,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,GAC3B,MAAM,qBAAqB,CAAC"}
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useSignature = exports.useHash = exports.useEncrypt = exports.useKeypair = exports.useCryptoContext = exports.CryptoProvider = void 0;
3
+ exports.usePqStream = exports.useSignature = exports.useHash = exports.useEncrypt = exports.useKeypair = exports.useCryptoContext = exports.CryptoProvider = void 0;
4
4
  var provider_1 = require("./provider");
5
5
  Object.defineProperty(exports, "CryptoProvider", { enumerable: true, get: function () { return provider_1.CryptoProvider; } });
6
6
  Object.defineProperty(exports, "useCryptoContext", { enumerable: true, get: function () { return provider_1.useCryptoContext; } });
@@ -12,4 +12,6 @@ var useHash_1 = require("./hooks/useHash");
12
12
  Object.defineProperty(exports, "useHash", { enumerable: true, get: function () { return useHash_1.useHash; } });
13
13
  var useSignature_1 = require("./hooks/useSignature");
14
14
  Object.defineProperty(exports, "useSignature", { enumerable: true, get: function () { return useSignature_1.useSignature; } });
15
+ var usePqStream_1 = require("./hooks/usePqStream");
16
+ Object.defineProperty(exports, "usePqStream", { enumerable: true, get: function () { return usePqStream_1.usePqStream; } });
15
17
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sebastienrousseau/crypto-react",
3
- "version": "0.0.9",
3
+ "version": "0.0.25",
4
4
  "description": "React hooks for client-side cryptography -- key generation, encryption, signing, and hashing in a single import.",
5
5
  "author": "Sebastien Rousseau <sebastienrousseau@users.noreply.github.com>",
6
6
  "license": "MIT OR Apache-2.0",
@@ -34,13 +34,13 @@
34
34
  "dist/**/*.d.ts.map"
35
35
  ],
36
36
  "dependencies": {
37
- "@sebastienrousseau/crypto-lib": "0.0.9"
37
+ "@sebastienrousseau/crypto-lib": "0.0.25"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "react": "^19.3.0"
41
41
  },
42
42
  "devDependencies": {
43
- "@sebastienrousseau/mocha-config": "^0.0.5",
43
+ "@sebastienrousseau/mocha-config": "^0.0.7",
44
44
  "@types/chai": "^5.2.3",
45
45
  "@types/chai-as-promised": "^8.0.2",
46
46
  "@types/mocha": "^10.0.10",