@sebastienrousseau/crypto-edge 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.
- package/dist/detect.d.ts.map +1 -1
- package/dist/detect.js +16 -7
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/streaming.d.ts +17 -0
- package/dist/streaming.d.ts.map +1 -0
- package/dist/streaming.js +80 -0
- package/package.json +3 -3
package/dist/detect.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detect.d.ts","sourceRoot":"","sources":["../src/detect.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"detect.d.ts","sourceRoot":"","sources":["../src/detect.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAkDhE,wBAAgB,aAAa,IAAI,WAAW,CAuB3C;AAmBD,wBAAgB,eAAe,IAAI,mBAAmB,CAwCrD;AAgBD,wBAAgB,qBAAqB,IAAI,OAAO,CAG/C"}
|
package/dist/detect.js
CHANGED
|
@@ -4,10 +4,21 @@ exports.detectRuntime = detectRuntime;
|
|
|
4
4
|
exports.getCapabilities = getCapabilities;
|
|
5
5
|
exports.isEdgeCryptoAvailable = isEdgeCryptoAvailable;
|
|
6
6
|
const g = globalThis;
|
|
7
|
-
function
|
|
8
|
-
|
|
7
|
+
function isCloudflareWorkers() {
|
|
8
|
+
return (typeof g.navigator !== "undefined" &&
|
|
9
9
|
typeof g.navigator.userAgent === "string" &&
|
|
10
|
-
g.navigator.userAgent.includes("Cloudflare-Workers"))
|
|
10
|
+
g.navigator.userAgent.includes("Cloudflare-Workers"));
|
|
11
|
+
}
|
|
12
|
+
function isNodeRuntime() {
|
|
13
|
+
return (typeof g.process !== "undefined" &&
|
|
14
|
+
typeof g.process.versions === "object" &&
|
|
15
|
+
typeof g.process.versions.node === "string");
|
|
16
|
+
}
|
|
17
|
+
function isBrowserEnvironment() {
|
|
18
|
+
return typeof g.window !== "undefined" && typeof g.document !== "undefined";
|
|
19
|
+
}
|
|
20
|
+
function detectRuntime() {
|
|
21
|
+
if (isCloudflareWorkers()) {
|
|
11
22
|
return "cloudflare-workers";
|
|
12
23
|
}
|
|
13
24
|
if (typeof g.EdgeRuntime === "string") {
|
|
@@ -19,12 +30,10 @@ function detectRuntime() {
|
|
|
19
30
|
if (typeof g.Bun !== "undefined") {
|
|
20
31
|
return "bun";
|
|
21
32
|
}
|
|
22
|
-
if (
|
|
33
|
+
if (isBrowserEnvironment()) {
|
|
23
34
|
return "browser";
|
|
24
35
|
}
|
|
25
|
-
if (
|
|
26
|
-
typeof g.process.versions === "object" &&
|
|
27
|
-
typeof g.process.versions.node === "string") {
|
|
36
|
+
if (isNodeRuntime()) {
|
|
28
37
|
return "node";
|
|
29
38
|
}
|
|
30
39
|
return "unknown";
|
package/dist/index.d.ts
CHANGED
|
@@ -2,4 +2,6 @@ export type { EdgeRuntime, RuntimeCapabilities, EdgeHashAlgorithm, EdgeKeyAlgori
|
|
|
2
2
|
export { detectRuntime, getCapabilities, isEdgeCryptoAvailable, } from "./detect";
|
|
3
3
|
export { hash, encrypt, decrypt, sign, verify, generateKey, toHex, toBytes, randomBytes, concat, } from "./webcrypto";
|
|
4
4
|
export { installPolyfills, TextEncoderPolyfill, TextDecoderPolyfill, btoaPolyfill, atobPolyfill, _resetPolyfillState, } from "./polyfill";
|
|
5
|
+
export type { EdgePqRecipientPublicKeys, EdgePqRecipientSecretKeys, } from "./streaming";
|
|
6
|
+
export { createEdgePqEncryptStream, createEdgePqDecryptStream, encryptEdgeResponse, decryptEdgeRequest, createDecryptedEdgeRequest, } from "./streaming";
|
|
5
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA6BA,YAAY,EACV,WAAW,EACX,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,aAAa,EACb,eAAe,EACf,qBAAqB,GACtB,MAAM,UAAU,CAAC;AAGlB,OAAO,EACL,IAAI,EACJ,OAAO,EACP,OAAO,EACP,IAAI,EACJ,MAAM,EACN,WAAW,EACX,KAAK,EACL,OAAO,EACP,WAAW,EACX,MAAM,GACP,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,YAAY,EACZ,YAAY,EACZ,mBAAmB,GACpB,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA6BA,YAAY,EACV,WAAW,EACX,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,aAAa,EACb,eAAe,EACf,qBAAqB,GACtB,MAAM,UAAU,CAAC;AAGlB,OAAO,EACL,IAAI,EACJ,OAAO,EACP,OAAO,EACP,IAAI,EACJ,MAAM,EACN,WAAW,EACX,KAAK,EACL,OAAO,EACP,WAAW,EACX,MAAM,GACP,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,YAAY,EACZ,YAAY,EACZ,mBAAmB,GACpB,MAAM,YAAY,CAAC;AAGpB,YAAY,EACV,yBAAyB,EACzB,yBAAyB,GAC1B,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,yBAAyB,EACzB,yBAAyB,EACzB,mBAAmB,EACnB,kBAAkB,EAClB,0BAA0B,GAC3B,MAAM,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports._resetPolyfillState = exports.atobPolyfill = exports.btoaPolyfill = exports.TextDecoderPolyfill = exports.TextEncoderPolyfill = exports.installPolyfills = exports.concat = exports.randomBytes = exports.toBytes = exports.toHex = exports.generateKey = exports.verify = exports.sign = exports.decrypt = exports.encrypt = exports.hash = exports.isEdgeCryptoAvailable = exports.getCapabilities = exports.detectRuntime = void 0;
|
|
3
|
+
exports.createDecryptedEdgeRequest = exports.decryptEdgeRequest = exports.encryptEdgeResponse = exports.createEdgePqDecryptStream = exports.createEdgePqEncryptStream = exports._resetPolyfillState = exports.atobPolyfill = exports.btoaPolyfill = exports.TextDecoderPolyfill = exports.TextEncoderPolyfill = exports.installPolyfills = exports.concat = exports.randomBytes = exports.toBytes = exports.toHex = exports.generateKey = exports.verify = exports.sign = exports.decrypt = exports.encrypt = exports.hash = exports.isEdgeCryptoAvailable = exports.getCapabilities = exports.detectRuntime = void 0;
|
|
4
4
|
var detect_1 = require("./detect");
|
|
5
5
|
Object.defineProperty(exports, "detectRuntime", { enumerable: true, get: function () { return detect_1.detectRuntime; } });
|
|
6
6
|
Object.defineProperty(exports, "getCapabilities", { enumerable: true, get: function () { return detect_1.getCapabilities; } });
|
|
@@ -23,4 +23,10 @@ Object.defineProperty(exports, "TextDecoderPolyfill", { enumerable: true, get: f
|
|
|
23
23
|
Object.defineProperty(exports, "btoaPolyfill", { enumerable: true, get: function () { return polyfill_1.btoaPolyfill; } });
|
|
24
24
|
Object.defineProperty(exports, "atobPolyfill", { enumerable: true, get: function () { return polyfill_1.atobPolyfill; } });
|
|
25
25
|
Object.defineProperty(exports, "_resetPolyfillState", { enumerable: true, get: function () { return polyfill_1._resetPolyfillState; } });
|
|
26
|
+
var streaming_1 = require("./streaming");
|
|
27
|
+
Object.defineProperty(exports, "createEdgePqEncryptStream", { enumerable: true, get: function () { return streaming_1.createEdgePqEncryptStream; } });
|
|
28
|
+
Object.defineProperty(exports, "createEdgePqDecryptStream", { enumerable: true, get: function () { return streaming_1.createEdgePqDecryptStream; } });
|
|
29
|
+
Object.defineProperty(exports, "encryptEdgeResponse", { enumerable: true, get: function () { return streaming_1.encryptEdgeResponse; } });
|
|
30
|
+
Object.defineProperty(exports, "decryptEdgeRequest", { enumerable: true, get: function () { return streaming_1.decryptEdgeRequest; } });
|
|
31
|
+
Object.defineProperty(exports, "createDecryptedEdgeRequest", { enumerable: true, get: function () { return streaming_1.createDecryptedEdgeRequest; } });
|
|
26
32
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type CryptoTransformStream } from "@sebastienrousseau/crypto-lib/streaming";
|
|
2
|
+
export interface EdgePqRecipientPublicKeys {
|
|
3
|
+
recipientX25519Public: string | Uint8Array;
|
|
4
|
+
recipientMlKemPublic: string | Uint8Array;
|
|
5
|
+
chunkSize?: number | undefined;
|
|
6
|
+
}
|
|
7
|
+
export interface EdgePqRecipientSecretKeys {
|
|
8
|
+
recipientX25519Secret: string | Uint8Array;
|
|
9
|
+
recipientMlKemSecret: string | Uint8Array;
|
|
10
|
+
chunkSize?: number | undefined;
|
|
11
|
+
}
|
|
12
|
+
export declare function createEdgePqEncryptStream(recipient: EdgePqRecipientPublicKeys): CryptoTransformStream<Uint8Array, Uint8Array>;
|
|
13
|
+
export declare function createEdgePqDecryptStream(recipient: EdgePqRecipientSecretKeys): CryptoTransformStream<Uint8Array, Uint8Array>;
|
|
14
|
+
export declare function encryptEdgeResponse(response: Response, recipient: EdgePqRecipientPublicKeys, init?: ResponseInit | undefined): Response;
|
|
15
|
+
export declare function decryptEdgeRequest(request: Request, recipient: EdgePqRecipientSecretKeys): Promise<Uint8Array>;
|
|
16
|
+
export declare function createDecryptedEdgeRequest(request: Request, recipient: EdgePqRecipientSecretKeys): Request;
|
|
17
|
+
//# sourceMappingURL=streaming.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["../src/streaming.ts"],"names":[],"mappings":"AAaA,OAAO,EAKL,KAAK,qBAAqB,EAC3B,MAAM,yCAAyC,CAAC;AAIjD,MAAM,WAAW,yBAAyB;IAExC,qBAAqB,EAAE,MAAM,GAAG,UAAU,CAAC;IAE3C,oBAAoB,EAAE,MAAM,GAAG,UAAU,CAAC;IAE1C,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAChC;AAGD,MAAM,WAAW,yBAAyB;IAExC,qBAAqB,EAAE,MAAM,GAAG,UAAU,CAAC;IAE3C,oBAAoB,EAAE,MAAM,GAAG,UAAU,CAAC;IAE1C,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAChC;AAQD,wBAAgB,yBAAyB,CACvC,SAAS,EAAE,yBAAyB,GACnC,qBAAqB,CAAC,UAAU,EAAE,UAAU,CAAC,CAM/C;AAQD,wBAAgB,yBAAyB,CACvC,SAAS,EAAE,yBAAyB,GACnC,qBAAqB,CAAC,UAAU,EAAE,UAAU,CAAC,CAM/C;AAmBD,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,yBAAyB,EACpC,IAAI,CAAC,EAAE,YAAY,GAAG,SAAS,GAC9B,QAAQ,CA+BV;AAYD,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,yBAAyB,GACnC,OAAO,CAAC,UAAU,CAAC,CAarB;AAYD,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,yBAAyB,GACnC,OAAO,CAgBT"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createEdgePqEncryptStream = createEdgePqEncryptStream;
|
|
4
|
+
exports.createEdgePqDecryptStream = createEdgePqDecryptStream;
|
|
5
|
+
exports.encryptEdgeResponse = encryptEdgeResponse;
|
|
6
|
+
exports.decryptEdgeRequest = decryptEdgeRequest;
|
|
7
|
+
exports.createDecryptedEdgeRequest = createDecryptedEdgeRequest;
|
|
8
|
+
const streaming_1 = require("@sebastienrousseau/crypto-lib/streaming");
|
|
9
|
+
const crypto_lib_1 = require("@sebastienrousseau/crypto-lib");
|
|
10
|
+
function createEdgePqEncryptStream(recipient) {
|
|
11
|
+
return (0, streaming_1.createPqEncryptStream)({
|
|
12
|
+
recipientX25519Public: recipient.recipientX25519Public,
|
|
13
|
+
recipientMlKemPublic: recipient.recipientMlKemPublic,
|
|
14
|
+
chunkSize: recipient.chunkSize,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
function createEdgePqDecryptStream(recipient) {
|
|
18
|
+
return (0, streaming_1.createPqDecryptStream)({
|
|
19
|
+
recipientX25519Secret: recipient.recipientX25519Secret,
|
|
20
|
+
recipientMlKemSecret: recipient.recipientMlKemSecret,
|
|
21
|
+
chunkSize: recipient.chunkSize,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
function buildEncryptedHeaders(baseHeaders) {
|
|
25
|
+
const headers = new Headers(baseHeaders);
|
|
26
|
+
headers.set("content-type", "application/octet-stream");
|
|
27
|
+
return headers;
|
|
28
|
+
}
|
|
29
|
+
function encryptEdgeResponse(response, recipient, init) {
|
|
30
|
+
const headers = buildEncryptedHeaders(init?.headers ?? response.headers);
|
|
31
|
+
const status = init?.status ?? response.status;
|
|
32
|
+
const statusText = init?.statusText ?? response.statusText;
|
|
33
|
+
if (!response.body) {
|
|
34
|
+
const emptyResult = (0, streaming_1.streamPqEncrypt)({
|
|
35
|
+
recipientX25519Public: recipient.recipientX25519Public,
|
|
36
|
+
recipientMlKemPublic: recipient.recipientMlKemPublic,
|
|
37
|
+
plaintext: new Uint8Array(0),
|
|
38
|
+
chunkSize: recipient.chunkSize,
|
|
39
|
+
});
|
|
40
|
+
return new Response(emptyResult.ciphertext, {
|
|
41
|
+
status,
|
|
42
|
+
statusText,
|
|
43
|
+
headers,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
const encryptStream = createEdgePqEncryptStream(recipient);
|
|
47
|
+
const encryptedBody = response.body.pipeThrough(encryptStream);
|
|
48
|
+
return new Response(encryptedBody, {
|
|
49
|
+
status,
|
|
50
|
+
statusText,
|
|
51
|
+
headers,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
async function decryptEdgeRequest(request, recipient) {
|
|
55
|
+
const buffer = await request.arrayBuffer();
|
|
56
|
+
const ciphertext = new Uint8Array(buffer);
|
|
57
|
+
try {
|
|
58
|
+
return (0, streaming_1.streamPqDecrypt)({
|
|
59
|
+
recipientX25519Secret: recipient.recipientX25519Secret,
|
|
60
|
+
recipientMlKemSecret: recipient.recipientMlKemSecret,
|
|
61
|
+
ciphertext,
|
|
62
|
+
chunkSize: recipient.chunkSize,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
(0, crypto_lib_1.wipeMemory)(ciphertext);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function createDecryptedEdgeRequest(request, recipient) {
|
|
70
|
+
if (!request.body) {
|
|
71
|
+
return new Request(request);
|
|
72
|
+
}
|
|
73
|
+
const decryptStream = createEdgePqDecryptStream(recipient);
|
|
74
|
+
const decryptedBody = request.body.pipeThrough(decryptStream);
|
|
75
|
+
return new Request(request, {
|
|
76
|
+
body: decryptedBody,
|
|
77
|
+
duplex: "half",
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=streaming.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sebastienrousseau/crypto-edge",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.25",
|
|
4
4
|
"description": "Edge and serverless runtime adapter for crypto-lib -- runs on Cloudflare Workers, Vercel Edge, Deno, Bun, and browsers.",
|
|
5
5
|
"author": "Sebastien Rousseau <sebastienrousseau@users.noreply.github.com>",
|
|
6
6
|
"license": "MIT OR Apache-2.0",
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
"dist/**/*.d.ts.map"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@sebastienrousseau/crypto-lib": "0.0.
|
|
37
|
+
"@sebastienrousseau/crypto-lib": "0.0.25"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@sebastienrousseau/mocha-config": "^0.0.
|
|
40
|
+
"@sebastienrousseau/mocha-config": "^0.0.7",
|
|
41
41
|
"@types/chai": "^5.2.3",
|
|
42
42
|
"@types/chai-as-promised": "^8.0.2",
|
|
43
43
|
"@types/mocha": "^10.0.10",
|