@substrate-system/crypto-stream 0.0.33
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/LICENSE +99 -0
- package/README.md +366 -0
- package/dist/concat-streams.cjs +59 -0
- package/dist/ece.cjs +375 -0
- package/dist/extract-transformer.cjs +55 -0
- package/dist/index.cjs +28 -0
- package/dist/keychain.cjs +344 -0
- package/dist/slice-transformer.cjs +75 -0
- package/dist/src/concat-streams.d.ts +9 -0
- package/dist/src/concat-streams.d.ts.map +1 -0
- package/dist/src/concat-streams.js +46 -0
- package/dist/src/concat-streams.js.map +1 -0
- package/dist/src/ece.d.ts +66 -0
- package/dist/src/ece.d.ts.map +1 -0
- package/dist/src/ece.js +373 -0
- package/dist/src/ece.js.map +1 -0
- package/dist/src/extract-transformer.d.ts +18 -0
- package/dist/src/extract-transformer.d.ts.map +1 -0
- package/dist/src/extract-transformer.js +40 -0
- package/dist/src/extract-transformer.js.map +1 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +3 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/keychain.d.ts +103 -0
- package/dist/src/keychain.d.ts.map +1 -0
- package/dist/src/keychain.js +267 -0
- package/dist/src/keychain.js.map +1 -0
- package/dist/src/slice-transformer.d.ts +19 -0
- package/dist/src/slice-transformer.d.ts.map +1 -0
- package/dist/src/slice-transformer.js +58 -0
- package/dist/src/slice-transformer.js.map +1 -0
- package/dist/src/transform-stream.d.ts +11 -0
- package/dist/src/transform-stream.d.ts.map +1 -0
- package/dist/src/transform-stream.js +136 -0
- package/dist/src/transform-stream.js.map +1 -0
- package/dist/src/util.d.ts +27 -0
- package/dist/src/util.d.ts.map +1 -0
- package/dist/src/util.js +49 -0
- package/dist/src/util.js.map +1 -0
- package/dist/transform-stream.cjs +159 -0
- package/dist/util.cjs +57 -0
- package/package.json +86 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var transform_stream_exports = {};
|
|
21
|
+
__export(transform_stream_exports, {
|
|
22
|
+
transformStream: () => transformStream
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(transform_stream_exports);
|
|
25
|
+
function transformStream(sourceReadable, transformer) {
|
|
26
|
+
let transformedReadable;
|
|
27
|
+
let done;
|
|
28
|
+
if (typeof TransformStream !== "undefined") {
|
|
29
|
+
const transform = new TransformStream(transformer);
|
|
30
|
+
done = sourceReadable.pipeTo(transform.writable);
|
|
31
|
+
transformedReadable = transform.readable;
|
|
32
|
+
} else {
|
|
33
|
+
let resolveDone;
|
|
34
|
+
let rejectDone;
|
|
35
|
+
done = new Promise((resolve, reject) => {
|
|
36
|
+
resolveDone = resolve;
|
|
37
|
+
rejectDone = reject;
|
|
38
|
+
});
|
|
39
|
+
const transformSource = new TransformStreamSource(
|
|
40
|
+
sourceReadable,
|
|
41
|
+
transformer,
|
|
42
|
+
{
|
|
43
|
+
resolveDone,
|
|
44
|
+
rejectDone
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
transformedReadable = new ReadableStream(transformSource);
|
|
48
|
+
}
|
|
49
|
+
done.catch(() => {
|
|
50
|
+
});
|
|
51
|
+
return {
|
|
52
|
+
readable: transformedReadable,
|
|
53
|
+
done
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
__name(transformStream, "transformStream");
|
|
57
|
+
class TransformStreamSource {
|
|
58
|
+
static {
|
|
59
|
+
__name(this, "TransformStreamSource");
|
|
60
|
+
}
|
|
61
|
+
readable;
|
|
62
|
+
transformer;
|
|
63
|
+
resolveDone;
|
|
64
|
+
rejectDone;
|
|
65
|
+
reader;
|
|
66
|
+
progressMade;
|
|
67
|
+
wrappedController;
|
|
68
|
+
type = "bytes";
|
|
69
|
+
constructor(readable, transformer, {
|
|
70
|
+
resolveDone,
|
|
71
|
+
rejectDone
|
|
72
|
+
}) {
|
|
73
|
+
this.readable = readable;
|
|
74
|
+
this.transformer = transformer;
|
|
75
|
+
this.resolveDone = resolveDone;
|
|
76
|
+
this.rejectDone = rejectDone;
|
|
77
|
+
this.reader = readable.getReader();
|
|
78
|
+
this.progressMade = false;
|
|
79
|
+
this.wrappedController = null;
|
|
80
|
+
}
|
|
81
|
+
// async start (controller:ReadableStreamController<T>) {
|
|
82
|
+
async start(controller) {
|
|
83
|
+
this.wrappedController = {
|
|
84
|
+
desiredSize: controller.desiredSize,
|
|
85
|
+
enqueue: /* @__PURE__ */ __name((value) => {
|
|
86
|
+
this.progressMade = true;
|
|
87
|
+
controller.enqueue(value);
|
|
88
|
+
}, "enqueue"),
|
|
89
|
+
error: /* @__PURE__ */ __name((reason) => {
|
|
90
|
+
this.progressMade = true;
|
|
91
|
+
if (!(reason instanceof Error)) {
|
|
92
|
+
reason = new Error(`stream errored; reason: ${reason}`);
|
|
93
|
+
}
|
|
94
|
+
controller.error(reason);
|
|
95
|
+
this.reader.cancel(reason).catch(() => {
|
|
96
|
+
});
|
|
97
|
+
this.rejectDone(reason);
|
|
98
|
+
}, "error"),
|
|
99
|
+
terminate: /* @__PURE__ */ __name(() => {
|
|
100
|
+
this.progressMade = true;
|
|
101
|
+
controller.close();
|
|
102
|
+
this.reader.cancel(new Error("stream terminated")).catch(() => {
|
|
103
|
+
});
|
|
104
|
+
this.resolveDone();
|
|
105
|
+
}, "terminate")
|
|
106
|
+
};
|
|
107
|
+
if (this.transformer.start) {
|
|
108
|
+
try {
|
|
109
|
+
await this.transformer.start(this.wrappedController);
|
|
110
|
+
} catch (err) {
|
|
111
|
+
this.rejectDone(err);
|
|
112
|
+
throw err;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async pull(controller) {
|
|
117
|
+
this.progressMade = false;
|
|
118
|
+
while (!this.progressMade) {
|
|
119
|
+
try {
|
|
120
|
+
const data = await this.reader.read();
|
|
121
|
+
if (!this.wrappedController) {
|
|
122
|
+
throw new Error("not this.wrappedController");
|
|
123
|
+
}
|
|
124
|
+
if (data.done) {
|
|
125
|
+
if (this.transformer.flush) {
|
|
126
|
+
await this.transformer.flush(this.wrappedController);
|
|
127
|
+
}
|
|
128
|
+
controller.close();
|
|
129
|
+
this.resolveDone();
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (this.transformer.transform) {
|
|
133
|
+
await this.transformer.transform(
|
|
134
|
+
data.value,
|
|
135
|
+
this.wrappedController
|
|
136
|
+
);
|
|
137
|
+
} else {
|
|
138
|
+
if (!this.wrappedController) {
|
|
139
|
+
throw new Error("not wrapped controller");
|
|
140
|
+
}
|
|
141
|
+
this.wrappedController.enqueue(data.value);
|
|
142
|
+
}
|
|
143
|
+
} catch (err) {
|
|
144
|
+
this.rejectDone(err);
|
|
145
|
+
this.reader.cancel(err).catch(() => {
|
|
146
|
+
});
|
|
147
|
+
throw err;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
async cancel(reason) {
|
|
152
|
+
await this.reader.cancel(reason);
|
|
153
|
+
if (reason instanceof Error) {
|
|
154
|
+
this.rejectDone(reason);
|
|
155
|
+
} else {
|
|
156
|
+
this.rejectDone(new Error(`stream cancelled; reason: ${reason}`));
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
package/dist/util.cjs
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var util_exports = {};
|
|
21
|
+
__export(util_exports, {
|
|
22
|
+
asBufferSource: () => asBufferSource,
|
|
23
|
+
generateSalt: () => generateSalt,
|
|
24
|
+
joinBufs: () => joinBufs,
|
|
25
|
+
randomBuf: () => randomBuf
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(util_exports);
|
|
28
|
+
var import_one_webcrypto = require("@substrate-system/one-webcrypto");
|
|
29
|
+
function generateSalt(len) {
|
|
30
|
+
const salt = new Uint8Array(len);
|
|
31
|
+
import_one_webcrypto.webcrypto.getRandomValues(salt);
|
|
32
|
+
return salt;
|
|
33
|
+
}
|
|
34
|
+
__name(generateSalt, "generateSalt");
|
|
35
|
+
function randomBuf(length) {
|
|
36
|
+
return import_one_webcrypto.webcrypto.getRandomValues(new Uint8Array(length));
|
|
37
|
+
}
|
|
38
|
+
__name(randomBuf, "randomBuf");
|
|
39
|
+
function joinBufs(fst, snd) {
|
|
40
|
+
const view1 = new Uint8Array(fst);
|
|
41
|
+
const view2 = new Uint8Array(snd);
|
|
42
|
+
const joined = new Uint8Array(view1.length + view2.length);
|
|
43
|
+
joined.set(view1);
|
|
44
|
+
joined.set(view2, view1.length);
|
|
45
|
+
return joined;
|
|
46
|
+
}
|
|
47
|
+
__name(joinBufs, "joinBufs");
|
|
48
|
+
function asBufferSource(data) {
|
|
49
|
+
if (data instanceof ArrayBuffer) {
|
|
50
|
+
return new Uint8Array(data);
|
|
51
|
+
}
|
|
52
|
+
if (data.buffer instanceof ArrayBuffer) {
|
|
53
|
+
return data;
|
|
54
|
+
}
|
|
55
|
+
return new Uint8Array(data);
|
|
56
|
+
}
|
|
57
|
+
__name(asBufferSource, "asBufferSource");
|
package/package.json
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@substrate-system/crypto-stream",
|
|
3
|
+
"description": "Streaming encryption for the browser",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"version": "0.0.33",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"./dist/*"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"lint": "eslint \"./**/*.{ts,js}\"",
|
|
12
|
+
"test": "esbuild --format=esm --platform=node --sourcemap --bundle test/index.ts | node --input-type=module | tap-spec",
|
|
13
|
+
"test:electron": "esbuild --bundle test/index.ts | tape-run | tap-spec",
|
|
14
|
+
"test-tape-run": "cat test/index.html | tape-run --input=html --static=test | tap-spec",
|
|
15
|
+
"build": "mkdir -p ./dist && rm -rf ./dist/* && tsc --project tsconfig.build.json",
|
|
16
|
+
"build:cjs": "esbuild src/*.ts --format=cjs --tsconfig=tsconfig.build.json --keep-names --outdir=./dist --out-extension:.js=.cjs",
|
|
17
|
+
"start": "vite",
|
|
18
|
+
"toc": "markdown-toc --maxdepth 3 -i README.md",
|
|
19
|
+
"build-docs": "typedoc ./src/index.ts",
|
|
20
|
+
"preversion": "npm run lint",
|
|
21
|
+
"version": "npm run toc && auto-changelog -p --template keepachangelog --breaking-pattern 'BREAKING CHANGE:' && git add CHANGELOG.md README.md",
|
|
22
|
+
"postversion": "git push --follow-tags && npm publish",
|
|
23
|
+
"prepublishOnly": "npm run build && npm run build:cjs"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@substrate-system/one-webcrypto": "^1.1.6",
|
|
27
|
+
"uint8arrays": "^6.1.1"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@preact/preset-vite": "^2.10.5",
|
|
31
|
+
"@preact/signals": "^2.9.1",
|
|
32
|
+
"@substrate-system/debug": "^0.9.64",
|
|
33
|
+
"@substrate-system/tapzero": "^0.10.16",
|
|
34
|
+
"@typescript-eslint/eslint-plugin": "^8.61.0",
|
|
35
|
+
"@typescript-eslint/parser": "^8.61.0",
|
|
36
|
+
"auto-changelog": "^2.6.0",
|
|
37
|
+
"esbuild": "^0.28.1",
|
|
38
|
+
"eslint": "^8.57.0",
|
|
39
|
+
"eslint-config-standard": "^17.1.0",
|
|
40
|
+
"htm": "^3.1.1",
|
|
41
|
+
"markdown-toc": "^1.2.0",
|
|
42
|
+
"postcss-nesting": "^14.0.0",
|
|
43
|
+
"preact": "^10.29.2",
|
|
44
|
+
"tap-spec": "^5.0.0",
|
|
45
|
+
"tape-run": "^11.0.0",
|
|
46
|
+
"typedoc": "^0.28.19",
|
|
47
|
+
"typescript": "^6.0.3",
|
|
48
|
+
"vite": "^8.0.16"
|
|
49
|
+
},
|
|
50
|
+
"exports": {
|
|
51
|
+
".": {
|
|
52
|
+
"import": "./dist/index.js",
|
|
53
|
+
"require": "./dist/index.cjs"
|
|
54
|
+
},
|
|
55
|
+
"./*": {
|
|
56
|
+
"import": [
|
|
57
|
+
"./dist/*.js",
|
|
58
|
+
"./dist/*"
|
|
59
|
+
],
|
|
60
|
+
"require": [
|
|
61
|
+
"./dist/*.cjs",
|
|
62
|
+
"./dist/*"
|
|
63
|
+
]
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
"author": "nichoth <nichoth@gmail.com> (https://nichoth.com)",
|
|
67
|
+
"directories": {
|
|
68
|
+
"example": "example",
|
|
69
|
+
"test": "test"
|
|
70
|
+
},
|
|
71
|
+
"repository": {
|
|
72
|
+
"type": "git",
|
|
73
|
+
"url": "git+https://github.com/mycelial-systems/crypto-stream.git"
|
|
74
|
+
},
|
|
75
|
+
"keywords": [
|
|
76
|
+
"cryptography",
|
|
77
|
+
"encryption",
|
|
78
|
+
"stream",
|
|
79
|
+
"browser"
|
|
80
|
+
],
|
|
81
|
+
"bugs": {
|
|
82
|
+
"url": "https://github.com/mycelial-systems/crypto-stream/issues"
|
|
83
|
+
},
|
|
84
|
+
"homepage": "https://github.com/mycelial-systems/crypto-stream",
|
|
85
|
+
"license": "SEE LICENSE IN LICENSE"
|
|
86
|
+
}
|