core-3nweb-client-lib 0.44.11 → 0.45.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.
- package/build/core/asmail/msg/opener.js +1 -1
- package/build/core/asmail/msg/packer.js +1 -1
- package/build/core/index.d.ts +2 -2
- package/build/core/keyring/correspondent-keys.js +1 -1
- package/build/core/keyring/index.js +1 -1
- package/build/core/startup/sign-in.d.ts +1 -1
- package/build/core/startup/sign-up.d.ts +1 -1
- package/build/core/storage/index.d.ts +1 -1
- package/build/lib-client/key-derivation.d.ts +1 -1
- package/build/lib-client/xsp-fs/attrs.d.ts +3 -2
- package/build/lib-client/xsp-fs/attrs.js +7 -6
- package/build/lib-client/xsp-fs/folder-node.js +1 -1
- package/build/lib-client/xsp-fs/node-in-fs.js +1 -0
- package/build/lib-client/xsp-fs/node-persistence.js +1 -1
- package/build/lib-client/xsp-fs/xsp-payload-v2.js +1 -1
- package/build/tests/caps-api/asmail/specs/events.d.ts +2 -0
- package/build/tests/caps-api/asmail/specs/events.js +63 -0
- package/build/tests/caps-api/asmail/specs/send-to-wrong-address.d.ts +2 -0
- package/build/tests/caps-api/asmail/specs/send-to-wrong-address.js +68 -0
- package/build/tests/caps-api/asmail/specs/send-with-attacment-from-storage.d.ts +2 -0
- package/build/tests/caps-api/asmail/specs/send-with-attacment-from-storage.js +259 -0
- package/build/tests/caps-api/asmail/specs/send-without-attachments.d.ts +2 -0
- package/build/tests/caps-api/asmail/specs/send-without-attachments.js +90 -0
- package/build/tests/caps-api/asmail/test-utils.d.ts +12 -0
- package/build/tests/caps-api/asmail/test-utils.js +60 -0
- package/build/tests/caps-api/asmail.js +86 -0
- package/build/tests/caps-api/file-sink-checks/different-cases.d.ts +2 -0
- package/build/tests/caps-api/file-sink-checks/different-cases.js +47 -0
- package/build/tests/caps-api/file-sink-checks/splice.d.ts +2 -0
- package/build/tests/caps-api/file-sink-checks/splice.js +122 -0
- package/build/tests/caps-api/file-sink-checks/truncate.d.ts +2 -0
- package/build/tests/caps-api/file-sink-checks/truncate.js +122 -0
- package/build/tests/caps-api/fs-checks/local-to-synced-linking/link.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/local-to-synced-linking/link.js +82 -0
- package/build/tests/caps-api/fs-checks/local-to-synced-linking/reversed-linking.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/local-to-synced-linking/reversed-linking.js +50 -0
- package/build/tests/caps-api/fs-checks/not-versioned/deleteFile.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/deleteFile.js +73 -0
- package/build/tests/caps-api/fs-checks/not-versioned/deleteFolder.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/deleteFolder.js +75 -0
- package/build/tests/caps-api/fs-checks/not-versioned/getByteSink.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/getByteSink.js +96 -0
- package/build/tests/caps-api/fs-checks/not-versioned/getByteSource.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/getByteSource.js +67 -0
- package/build/tests/caps-api/fs-checks/not-versioned/getXAttr.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/getXAttr.js +77 -0
- package/build/tests/caps-api/fs-checks/not-versioned/link.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/link.js +115 -0
- package/build/tests/caps-api/fs-checks/not-versioned/listFolder.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/listFolder.js +129 -0
- package/build/tests/caps-api/fs-checks/not-versioned/listXAttrs.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/listXAttrs.js +73 -0
- package/build/tests/caps-api/fs-checks/not-versioned/makeFolder.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/makeFolder.js +95 -0
- package/build/tests/caps-api/fs-checks/not-versioned/move.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/move.js +127 -0
- package/build/tests/caps-api/fs-checks/not-versioned/readBytes.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/readBytes.js +80 -0
- package/build/tests/caps-api/fs-checks/not-versioned/readJSONFile.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/readJSONFile.js +59 -0
- package/build/tests/caps-api/fs-checks/not-versioned/readLink.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/readLink.js +39 -0
- package/build/tests/caps-api/fs-checks/not-versioned/readTxtFile.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/readTxtFile.js +54 -0
- package/build/tests/caps-api/fs-checks/not-versioned/readonlyFile.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/readonlyFile.js +55 -0
- package/build/tests/caps-api/fs-checks/not-versioned/readonlySubRoot.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/readonlySubRoot.js +55 -0
- package/build/tests/caps-api/fs-checks/not-versioned/select.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/select.js +119 -0
- package/build/tests/caps-api/fs-checks/not-versioned/stat.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/stat.js +96 -0
- package/build/tests/caps-api/fs-checks/not-versioned/updateXAttrs.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/updateXAttrs.js +126 -0
- package/build/tests/caps-api/fs-checks/not-versioned/writableFile.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/writableFile.js +79 -0
- package/build/tests/caps-api/fs-checks/not-versioned/writableSubRoot.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/writableSubRoot.js +90 -0
- package/build/tests/caps-api/fs-checks/not-versioned/writeBytes.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/writeBytes.js +137 -0
- package/build/tests/caps-api/fs-checks/not-versioned/writeJSONFile.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/writeJSONFile.js +101 -0
- package/build/tests/caps-api/fs-checks/not-versioned/writeTxtFile.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/writeTxtFile.js +100 -0
- package/build/tests/caps-api/fs-checks/sync-on-one-dev/startUpload.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/sync-on-one-dev/startUpload.js +187 -0
- package/build/tests/caps-api/fs-checks/sync-on-one-dev/stat.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/sync-on-one-dev/stat.js +70 -0
- package/build/tests/caps-api/fs-checks/sync-on-one-dev/status.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/sync-on-one-dev/status.js +53 -0
- package/build/tests/caps-api/fs-checks/sync-on-one-dev/upload.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/sync-on-one-dev/upload.js +194 -0
- package/build/tests/caps-api/fs-checks/sync-with-two-devs/conflicts.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/sync-with-two-devs/conflicts.js +396 -0
- package/build/tests/caps-api/fs-checks/sync-with-two-devs/update-propagation.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/sync-with-two-devs/update-propagation.js +229 -0
- package/build/tests/caps-api/fs-checks/test-utils.d.ts +34 -0
- package/build/tests/caps-api/fs-checks/test-utils.js +95 -0
- package/build/tests/caps-api/fs-checks/versioned/archiveCurrent.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/versioned/archiveCurrent.js +73 -0
- package/build/tests/caps-api/fs-checks/versioned/getByteSink.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/versioned/getByteSink.js +122 -0
- package/build/tests/caps-api/fs-checks/versioned/getByteSource.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/versioned/getByteSource.js +71 -0
- package/build/tests/caps-api/fs-checks/versioned/listFolder.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/versioned/listFolder.js +109 -0
- package/build/tests/caps-api/fs-checks/versioned/listVersions.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/versioned/listVersions.js +48 -0
- package/build/tests/caps-api/fs-checks/versioned/readBytes.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/versioned/readBytes.js +90 -0
- package/build/tests/caps-api/fs-checks/versioned/readJSONFile.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/versioned/readJSONFile.js +60 -0
- package/build/tests/caps-api/fs-checks/versioned/readTxtFile.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/versioned/readTxtFile.js +56 -0
- package/build/tests/caps-api/fs-checks/versioned/stat.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/versioned/stat.js +80 -0
- package/build/tests/caps-api/fs-checks/versioned/watchFile.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/versioned/watchFile.js +64 -0
- package/build/tests/caps-api/fs-checks/versioned/writeBytes.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/versioned/writeBytes.js +128 -0
- package/build/tests/caps-api/fs-checks/versioned/writeJSONFile.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/versioned/writeJSONFile.js +111 -0
- package/build/tests/caps-api/fs-checks/versioned/writeTxtFile.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/versioned/writeTxtFile.js +107 -0
- package/build/tests/caps-api/fs-checks/with-core-restarts/xattrs.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/with-core-restarts/xattrs.js +50 -0
- package/build/tests/caps-api/keyrings.js +69 -0
- package/build/tests/caps-api/mailerid.d.ts +1 -0
- package/build/tests/caps-api/mailerid.js +59 -0
- package/build/tests/caps-api/startup/signin-empty-cache.d.ts +1 -0
- package/build/tests/caps-api/startup/signin-empty-cache.js +108 -0
- package/build/tests/caps-api/startup/signin-with-cache.d.ts +1 -0
- package/build/tests/caps-api/startup/signin-with-cache.js +83 -0
- package/build/tests/caps-api/startup/signup-with-token.d.ts +1 -0
- package/build/tests/caps-api/startup/signup-with-token.js +53 -0
- package/build/tests/caps-api/startup/signup.d.ts +1 -0
- package/build/tests/caps-api/startup/signup.js +86 -0
- package/build/tests/caps-api/storage.d.ts +1 -0
- package/build/tests/caps-api/storage.js +225 -0
- package/build/tests/computer.3nweb.core/id-manager.d.ts +1 -0
- package/build/tests/computer.3nweb.core/id-manager.js +78 -0
- package/build/tests/computer.3nweb.core/inbox/msg-indexing.d.ts +1 -0
- package/build/tests/computer.3nweb.core/inbox/msg-indexing.js +145 -0
- package/build/tests/computer.3nweb.core/keyrings.d.ts +1 -0
- package/build/tests/computer.3nweb.core/keyrings.js +64 -0
- package/build/tests/computer.3nweb.core/test-utils.d.ts +21 -0
- package/build/tests/computer.3nweb.core/test-utils.js +92 -0
- package/build/tests/jasmine.d.ts +1 -0
- package/build/tests/jasmine.js +45 -0
- package/build/tests/libs-for-tests/bytes-equal.d.ts +1 -0
- package/build/tests/libs-for-tests/bytes-equal.js +32 -0
- package/build/tests/libs-for-tests/caps-ipc-wrap.d.ts +11 -0
- package/build/tests/libs-for-tests/caps-ipc-wrap.js +55 -0
- package/build/tests/libs-for-tests/core-runner.d.ts +39 -0
- package/build/tests/libs-for-tests/core-runner.js +231 -0
- package/build/tests/libs-for-tests/jasmine-utils.d.ts +13 -0
- package/build/tests/libs-for-tests/jasmine-utils.js +110 -0
- package/build/tests/libs-for-tests/json-equal.d.ts +1 -0
- package/build/tests/libs-for-tests/json-equal.js +78 -0
- package/build/tests/libs-for-tests/services-runner.d.ts +18 -0
- package/build/tests/libs-for-tests/services-runner.js +64 -0
- package/build/tests/libs-for-tests/setups.d.ts +51 -0
- package/build/tests/libs-for-tests/setups.js +305 -0
- package/build/tests/libs-for-tests/spec-module.d.ts +16 -0
- package/build/tests/libs-for-tests/spec-module.js +92 -0
- package/build/tests/libs-for-tests/startup.d.ts +1 -0
- package/build/tests/libs-for-tests/startup.js +29 -0
- package/build/tests/libs-for-tests/watching.d.ts +7 -0
- package/build/tests/libs-for-tests/watching.js +33 -0
- package/build/tests/units/canonical-address.d.ts +1 -0
- package/build/tests/units/canonical-address.js +41 -0
- package/build/tests/units/device-fs.d.ts +1 -0
- package/build/tests/units/device-fs.js +70 -0
- package/build/tests/units/folder-node-serialization.d.ts +1 -0
- package/build/tests/units/folder-node-serialization.js +74 -0
- package/build/tests/units/mid-sigs-NaCl-Ed.d.ts +1 -0
- package/build/tests/units/mid-sigs-NaCl-Ed.js +123 -0
- package/build/tests/units/number-line.d.ts +1 -0
- package/build/tests/units/number-line.js +63 -0
- package/build/tests/units/obj-folders.d.ts +1 -0
- package/build/tests/units/obj-folders.js +152 -0
- package/package.json +11 -3
- package/postinstall.js +1 -1
- package/build/cryptors.d.ts +0 -1
- package/build/cryptors.js +0 -34
- package/build/lib-client/cryptor/cryptor-in-worker.d.ts +0 -20
- package/build/lib-client/cryptor/cryptor-in-worker.js +0 -357
- package/build/lib-client/cryptor/cryptor-wasm.js +0 -1
- package/build/lib-client/cryptor/cryptor.d.ts +0 -30
- package/build/lib-client/cryptor/cryptor.js +0 -44
- package/build/lib-client/cryptor/cryptor.wasm +0 -0
- package/build/lib-client/cryptor/in-proc-js.d.ts +0 -2
- package/build/lib-client/cryptor/in-proc-js.js +0 -57
- package/build/lib-client/cryptor/in-proc-wasm.d.ts +0 -2
- package/build/lib-client/cryptor/in-proc-wasm.js +0 -176
- package/build/lib-client/cryptor/serialization-for-wasm.d.ts +0 -35
- package/build/lib-client/cryptor/serialization-for-wasm.js +0 -57
- package/build/lib-client/cryptor/wasm-mp1-modules.d.ts +0 -5
- package/build/lib-client/cryptor/wasm-mp1-modules.js +0 -78
- package/build/lib-client/cryptor/worker-js.js +0 -131
- package/build/lib-client/cryptor/worker-wasm.js +0 -37
- package/build/protos/cryptor.proto.js +0 -1804
- /package/build/lib-client/{cryptor/cryptor-work-labels.d.ts → cryptor-work-labels.d.ts} +0 -0
- /package/build/lib-client/{cryptor/cryptor-work-labels.js → cryptor-work-labels.js} +0 -0
- /package/build/{lib-client/cryptor/worker-js.d.ts → tests/caps-api/asmail.d.ts} +0 -0
- /package/build/{lib-client/cryptor/worker-wasm.d.ts → tests/caps-api/keyrings.d.ts} +0 -0
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { signing } from 'ecma-nacl';
|
|
2
|
-
import { LogError, LogWarning } from '../logging/log-to-file';
|
|
3
|
-
import { AsyncSBoxCryptor } from 'xsp-files';
|
|
4
|
-
export interface Cryptor {
|
|
5
|
-
scrypt(passwd: Uint8Array, salt: Uint8Array, logN: number, r: number, p: number, dkLen: number, progressCB: (p: number) => void): Promise<Uint8Array>;
|
|
6
|
-
sbox: AsyncSBoxCryptor;
|
|
7
|
-
box: {
|
|
8
|
-
generate_pubkey(sk: Uint8Array): Promise<Uint8Array>;
|
|
9
|
-
calc_dhshared_key(pk: Uint8Array, sk: Uint8Array): Promise<Uint8Array>;
|
|
10
|
-
};
|
|
11
|
-
signing: {
|
|
12
|
-
signature(m: Uint8Array, sk: Uint8Array): Promise<Uint8Array>;
|
|
13
|
-
verify(sig: Uint8Array, m: Uint8Array, pk: Uint8Array): Promise<boolean>;
|
|
14
|
-
generate_keypair(seed: Uint8Array): Promise<signing.Keypair>;
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
export type makeCryptor = (logErr: LogError, logWarning: LogWarning, maxThreads?: number) => {
|
|
18
|
-
cryptor: Cryptor;
|
|
19
|
-
close: () => Promise<void>;
|
|
20
|
-
};
|
|
21
|
-
export declare const makeInWorkerCryptor: makeCryptor;
|
|
22
|
-
export declare const makeInWorkerWasmCryptor: makeCryptor;
|
|
23
|
-
export declare function makeInProcessCryptor(): ReturnType<makeCryptor>;
|
|
24
|
-
export declare function makeInProcessWasmCryptor(): ReturnType<makeCryptor>;
|
|
25
|
-
type RuntimeException = web3n.RuntimeException;
|
|
26
|
-
export interface CryptorException extends RuntimeException {
|
|
27
|
-
type: 'cryptor';
|
|
28
|
-
failedCipherVerification?: true;
|
|
29
|
-
}
|
|
30
|
-
export {};
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
Copyright (C) 2016 - 2021 3NSoft Inc.
|
|
4
|
-
|
|
5
|
-
This program is free software: you can redistribute it and/or modify it under
|
|
6
|
-
the terms of the GNU General Public License as published by the Free Software
|
|
7
|
-
Foundation, either version 3 of the License, or (at your option) any later
|
|
8
|
-
version.
|
|
9
|
-
|
|
10
|
-
This program is distributed in the hope that it will be useful, but
|
|
11
|
-
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
13
|
-
See the GNU General Public License for more details.
|
|
14
|
-
|
|
15
|
-
You should have received a copy of the GNU General Public License along with
|
|
16
|
-
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
-
*/
|
|
18
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.makeInWorkerWasmCryptor = exports.makeInWorkerCryptor = void 0;
|
|
20
|
-
exports.makeInProcessCryptor = makeInProcessCryptor;
|
|
21
|
-
exports.makeInProcessWasmCryptor = makeInProcessWasmCryptor;
|
|
22
|
-
const makeInWorkerCryptor = (logErr, logWarning, maxThreads) => {
|
|
23
|
-
const mod = require('./cryptor-in-worker');
|
|
24
|
-
const makeInWorkerCryptor = mod.makeInWorkerCryptor;
|
|
25
|
-
return makeInWorkerCryptor(logErr, logWarning, maxThreads);
|
|
26
|
-
};
|
|
27
|
-
exports.makeInWorkerCryptor = makeInWorkerCryptor;
|
|
28
|
-
const makeInWorkerWasmCryptor = (logErr, logWarning, maxThreads) => {
|
|
29
|
-
const mod = require('./cryptor-in-worker');
|
|
30
|
-
const makeInWorkerWasmCryptor = mod.makeInWorkerWasmCryptor;
|
|
31
|
-
return makeInWorkerWasmCryptor(logErr, logWarning, maxThreads);
|
|
32
|
-
};
|
|
33
|
-
exports.makeInWorkerWasmCryptor = makeInWorkerWasmCryptor;
|
|
34
|
-
function makeInProcessCryptor() {
|
|
35
|
-
const mod = require('./in-proc-js');
|
|
36
|
-
const makeInProcessCryptor = mod.makeInProcessCryptor;
|
|
37
|
-
return { cryptor: makeInProcessCryptor(), close: async () => { } };
|
|
38
|
-
}
|
|
39
|
-
function makeInProcessWasmCryptor() {
|
|
40
|
-
const mod = require('./in-proc-wasm');
|
|
41
|
-
const makeInProcessWasmCryptor = mod.makeInProcessWasmCryptor;
|
|
42
|
-
return { cryptor: makeInProcessWasmCryptor(), close: async () => { } };
|
|
43
|
-
}
|
|
44
|
-
Object.freeze(exports);
|
|
Binary file
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
Copyright (C) 2020, 2022 3NSoft Inc.
|
|
4
|
-
|
|
5
|
-
This program is free software: you can redistribute it and/or modify it under
|
|
6
|
-
the terms of the GNU General Public License as published by the Free Software
|
|
7
|
-
Foundation, either version 3 of the License, or (at your option) any later
|
|
8
|
-
version.
|
|
9
|
-
|
|
10
|
-
This program is distributed in the hope that it will be useful, but
|
|
11
|
-
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
13
|
-
See the GNU General Public License for more details.
|
|
14
|
-
|
|
15
|
-
You should have received a copy of the GNU General Public License along with
|
|
16
|
-
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
-
*/
|
|
18
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.makeInProcessCryptor = makeInProcessCryptor;
|
|
20
|
-
const ecma_nacl_1 = require("ecma-nacl");
|
|
21
|
-
const cryptor_work_labels_1 = require("./cryptor-work-labels");
|
|
22
|
-
function onNextTick(f) {
|
|
23
|
-
return new Promise((resolve, reject) => process.nextTick(() => {
|
|
24
|
-
try {
|
|
25
|
-
resolve(f());
|
|
26
|
-
}
|
|
27
|
-
catch (err) {
|
|
28
|
-
reject(err);
|
|
29
|
-
}
|
|
30
|
-
}));
|
|
31
|
-
}
|
|
32
|
-
function makeInProcessCryptor() {
|
|
33
|
-
const arrFactory = ecma_nacl_1.arrays.makeFactory();
|
|
34
|
-
const workExecutor = new cryptor_work_labels_1.InProcAsyncExecutor();
|
|
35
|
-
return {
|
|
36
|
-
scrypt: (passwd, salt, logN, r, p, dkLen, progressCB) => onNextTick(() => (0, ecma_nacl_1.scrypt)(passwd, salt, logN, r, p, dkLen, progressCB, arrFactory)),
|
|
37
|
-
box: {
|
|
38
|
-
calc_dhshared_key: (pk, sk) => onNextTick(() => ecma_nacl_1.box.calc_dhshared_key(pk, sk, arrFactory)),
|
|
39
|
-
generate_pubkey: sk => onNextTick(() => ecma_nacl_1.box.generate_pubkey(sk, arrFactory))
|
|
40
|
-
},
|
|
41
|
-
sbox: {
|
|
42
|
-
canStartUnderWorkLabel: l => workExecutor.canStartUnderWorkLabel(l),
|
|
43
|
-
open: (c, n, k, workLabel) => workExecutor.execOpOnNextTick(workLabel, () => ecma_nacl_1.secret_box.open(c, n, k, arrFactory)),
|
|
44
|
-
pack: (m, n, k, workLabel) => workExecutor.execOpOnNextTick(workLabel, () => ecma_nacl_1.secret_box.pack(m, n, k, arrFactory)),
|
|
45
|
-
formatWN: {
|
|
46
|
-
open: (cn, k, workLabel) => workExecutor.execOpOnNextTick(workLabel, () => ecma_nacl_1.secret_box.formatWN.open(cn, k, arrFactory)),
|
|
47
|
-
pack: (m, n, k, workLabel) => workExecutor.execOpOnNextTick(workLabel, () => ecma_nacl_1.secret_box.formatWN.pack(m, n, k, arrFactory))
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
signing: {
|
|
51
|
-
generate_keypair: seed => onNextTick(() => ecma_nacl_1.signing.generate_keypair(seed, arrFactory)),
|
|
52
|
-
signature: (m, sk) => onNextTick(() => ecma_nacl_1.signing.signature(m, sk, arrFactory)),
|
|
53
|
-
verify: (sig, m, pk) => onNextTick(() => ecma_nacl_1.signing.verify(sig, m, pk, arrFactory))
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
Object.freeze(exports);
|
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
Copyright (C) 2021 - 2022 3NSoft Inc.
|
|
4
|
-
|
|
5
|
-
This program is free software: you can redistribute it and/or modify it under
|
|
6
|
-
the terms of the GNU General Public License as published by the Free Software
|
|
7
|
-
Foundation, either version 3 of the License, or (at your option) any later
|
|
8
|
-
version.
|
|
9
|
-
|
|
10
|
-
This program is distributed in the hope that it will be useful, but
|
|
11
|
-
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
13
|
-
See the GNU General Public License for more details.
|
|
14
|
-
|
|
15
|
-
You should have received a copy of the GNU General Public License along with
|
|
16
|
-
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
-
*/
|
|
18
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.makeInProcessWasmCryptor = makeInProcessWasmCryptor;
|
|
20
|
-
const wasm_mp1_modules_1 = require("./wasm-mp1-modules");
|
|
21
|
-
const fs_1 = require("fs");
|
|
22
|
-
const path_1 = require("path");
|
|
23
|
-
const protobuf_type_1 = require("../protobuf-type");
|
|
24
|
-
const cryptor_proto_1 = require("../../protos/cryptor.proto");
|
|
25
|
-
const deferred_1 = require("../../lib-common/processes/deferred");
|
|
26
|
-
const assert_1 = require("../../lib-common/assert");
|
|
27
|
-
const error_1 = require("../../lib-common/exceptions/error");
|
|
28
|
-
const cryptor_work_labels_1 = require("./cryptor-work-labels");
|
|
29
|
-
function wasmBytes() {
|
|
30
|
-
// There is a bug with electrons 12, 13, that doesn't let
|
|
31
|
-
// worker_thread read this file from asar pack, even though main thread
|
|
32
|
-
// makes call from here.
|
|
33
|
-
// Therefore, in case this runs from asar pack, we should switch to
|
|
34
|
-
// unpacked in path that is given to worker thread.
|
|
35
|
-
// Of course, asarUnpack should be used in electron-builder.
|
|
36
|
-
const asarInd = __dirname.indexOf('app.asar');
|
|
37
|
-
const dirWithThis = ((asarInd < 0) ?
|
|
38
|
-
__dirname : `${__dirname.substring(0, asarInd + 8)}.unpacked${__dirname.substring(asarInd + 8)}`);
|
|
39
|
-
const wasmPath = (0, path_1.join)(dirWithThis, 'cryptor.wasm');
|
|
40
|
-
try {
|
|
41
|
-
return (0, fs_1.readFileSync)(wasmPath);
|
|
42
|
-
}
|
|
43
|
-
catch (err) {
|
|
44
|
-
// chances are that error is due to wasm file not being packaged, so, we
|
|
45
|
-
// look for module with base64 form in a module, that must've been packed
|
|
46
|
-
const str = require('./cryptor-wasm.js').wasm;
|
|
47
|
-
return Buffer.from(str, 'base64');
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
function toArgs(...args) {
|
|
51
|
-
return args.map(val => ({ val }));
|
|
52
|
-
}
|
|
53
|
-
function toLocalErr(replyErr) {
|
|
54
|
-
if (replyErr.condition === 'cipher-verification') {
|
|
55
|
-
return { failedCipherVerification: true };
|
|
56
|
-
}
|
|
57
|
-
else if (replyErr.condition === 'signature-verification') {
|
|
58
|
-
return { failedSignatureVerification: true };
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
return new Error(`WASM cryptor ${replyErr.condition}: ${replyErr.message}`);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
const reqType = protobuf_type_1.ProtoType.for(cryptor_proto_1.cryptor.Request);
|
|
65
|
-
const replyType = protobuf_type_1.ProtoType.for(cryptor_proto_1.cryptor.Reply);
|
|
66
|
-
const boolValType = protobuf_type_1.ProtoType.for(cryptor_proto_1.cryptor.BoolVal);
|
|
67
|
-
const kpairType = protobuf_type_1.ProtoType.for(cryptor_proto_1.cryptor.Keypair);
|
|
68
|
-
function makeInProcessWasmCryptor() {
|
|
69
|
-
const wasmInstance = (0, wasm_mp1_modules_1.startWasmFrom)(wasmBytes());
|
|
70
|
-
let deferred = undefined;
|
|
71
|
-
let interimSink = undefined;
|
|
72
|
-
const execCounter = new cryptor_work_labels_1.ExecCounter(() => (deferred ? 0 : 1));
|
|
73
|
-
async function call(req, interim) {
|
|
74
|
-
// In LiquidCore on iOS call was able to get before completion of
|
|
75
|
-
// previous call, therefore, the following await loop is needed.
|
|
76
|
-
while (!!deferred) {
|
|
77
|
-
try {
|
|
78
|
-
await deferred.promise;
|
|
79
|
-
}
|
|
80
|
-
catch (err) { }
|
|
81
|
-
}
|
|
82
|
-
deferred = (0, deferred_1.defer)();
|
|
83
|
-
if (interim) {
|
|
84
|
-
interimSink = interim;
|
|
85
|
-
}
|
|
86
|
-
process.nextTick(() => {
|
|
87
|
-
try {
|
|
88
|
-
wasmInstance.sendMsgIntoWASM(reqType.pack(req));
|
|
89
|
-
}
|
|
90
|
-
catch (err) {
|
|
91
|
-
deferred === null || deferred === void 0 ? void 0 : deferred.reject(err);
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
return deferred.promise;
|
|
95
|
-
}
|
|
96
|
-
wasmInstance.setMsgListener(msg => {
|
|
97
|
-
(0, assert_1.assert)(!!deferred, `Deferred is expected to be available for this output from wasm`);
|
|
98
|
-
try {
|
|
99
|
-
const reply = replyType.unpack(msg);
|
|
100
|
-
if (reply.res) {
|
|
101
|
-
deferred.resolve(reply.res.val);
|
|
102
|
-
deferred = undefined;
|
|
103
|
-
interimSink = undefined;
|
|
104
|
-
}
|
|
105
|
-
else if (reply.err) {
|
|
106
|
-
deferred.reject((0, error_1.errWithCause)(toLocalErr(reply.err), `Error in cryptor`));
|
|
107
|
-
deferred = undefined;
|
|
108
|
-
interimSink = undefined;
|
|
109
|
-
}
|
|
110
|
-
else if (reply.interim) {
|
|
111
|
-
interimSink(reply.interim.val);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
catch (err) {
|
|
115
|
-
deferred.reject(err);
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
return {
|
|
119
|
-
scrypt: (passwd, salt, logN, r, p, dkLen, progressCB) => call({
|
|
120
|
-
func: 1,
|
|
121
|
-
scryptArgs: { passwd, salt, logN, r, p, dkLen }
|
|
122
|
-
}, bytes => progressCB(bytes[0])),
|
|
123
|
-
box: {
|
|
124
|
-
calc_dhshared_key: (pk, sk) => call({
|
|
125
|
-
func: 2,
|
|
126
|
-
byteArgs: toArgs(pk, sk)
|
|
127
|
-
}),
|
|
128
|
-
generate_pubkey: (sk) => call({
|
|
129
|
-
func: 3,
|
|
130
|
-
byteArgs: toArgs(sk)
|
|
131
|
-
})
|
|
132
|
-
},
|
|
133
|
-
sbox: {
|
|
134
|
-
canStartUnderWorkLabel: l => execCounter.canStartUnderWorkLabel(l),
|
|
135
|
-
open: (c, n, k, workLabel) => execCounter.wrapOpPromise(workLabel, call({
|
|
136
|
-
func: 4,
|
|
137
|
-
byteArgs: toArgs(c, n, k)
|
|
138
|
-
})),
|
|
139
|
-
pack: (m, n, k, workLabel) => execCounter.wrapOpPromise(workLabel, call({
|
|
140
|
-
func: 5,
|
|
141
|
-
byteArgs: toArgs(m, n, k)
|
|
142
|
-
})),
|
|
143
|
-
formatWN: {
|
|
144
|
-
open: (cn, k, workLabel) => execCounter.wrapOpPromise(workLabel, call({
|
|
145
|
-
func: 6,
|
|
146
|
-
byteArgs: toArgs(cn, k)
|
|
147
|
-
})),
|
|
148
|
-
pack: (m, n, k, workLabel) => execCounter.wrapOpPromise(workLabel, call({
|
|
149
|
-
func: 7,
|
|
150
|
-
byteArgs: toArgs(m, n, k)
|
|
151
|
-
}))
|
|
152
|
-
}
|
|
153
|
-
},
|
|
154
|
-
signing: {
|
|
155
|
-
generate_keypair: async (seed) => {
|
|
156
|
-
const rep = await call({
|
|
157
|
-
func: 8,
|
|
158
|
-
byteArgs: toArgs(seed)
|
|
159
|
-
});
|
|
160
|
-
return kpairType.unpack(rep);
|
|
161
|
-
},
|
|
162
|
-
signature: (m, sk) => call({
|
|
163
|
-
func: 9,
|
|
164
|
-
byteArgs: toArgs(m, sk)
|
|
165
|
-
}),
|
|
166
|
-
verify: async (sig, m, pk) => {
|
|
167
|
-
const rep = await call({
|
|
168
|
-
func: 10,
|
|
169
|
-
byteArgs: toArgs(sig, m, pk)
|
|
170
|
-
});
|
|
171
|
-
return boolValType.unpack(rep).val;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
Object.freeze(exports);
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { signing } from 'ecma-nacl';
|
|
2
|
-
export interface WasmScryptRequest {
|
|
3
|
-
func: 1;
|
|
4
|
-
scryptArgs: {
|
|
5
|
-
passwd: Uint8Array;
|
|
6
|
-
salt: Uint8Array;
|
|
7
|
-
logN: number;
|
|
8
|
-
r: number;
|
|
9
|
-
p: number;
|
|
10
|
-
dkLen: number;
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
export interface WasmBinArgsRequest {
|
|
14
|
-
func: 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10;
|
|
15
|
-
byteArgs: ByteArg[];
|
|
16
|
-
}
|
|
17
|
-
export interface ByteArg {
|
|
18
|
-
val: Uint8Array;
|
|
19
|
-
}
|
|
20
|
-
export declare function toArgs(...args: Uint8Array[]): ByteArg[];
|
|
21
|
-
export type WasmRequest = WasmScryptRequest | WasmBinArgsRequest;
|
|
22
|
-
export interface WasmReply {
|
|
23
|
-
res?: ByteArg;
|
|
24
|
-
interim?: ByteArg;
|
|
25
|
-
err?: ReplyError;
|
|
26
|
-
}
|
|
27
|
-
export interface ReplyError {
|
|
28
|
-
condition: 'cipher-verification' | 'signature-verification' | 'configuration-error' | 'message-passing-error';
|
|
29
|
-
message: string;
|
|
30
|
-
}
|
|
31
|
-
export declare function toLocalErr(replyErr: ReplyError): Error | web3n.EncryptionException;
|
|
32
|
-
export declare function packRequestToWASM(req: WasmRequest): Buffer;
|
|
33
|
-
export declare function unpackReplyFromWASM(replyBytes: Buffer): WasmReply;
|
|
34
|
-
export declare function unpackSigningKeyPair(bytes: Buffer): signing.Keypair;
|
|
35
|
-
export declare function unpackBoolVal(bytes: Buffer): boolean;
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
Copyright (C) 2021 - 2022 3NSoft Inc.
|
|
4
|
-
|
|
5
|
-
This program is free software: you can redistribute it and/or modify it under
|
|
6
|
-
the terms of the GNU General Public License as published by the Free Software
|
|
7
|
-
Foundation, either version 3 of the License, or (at your option) any later
|
|
8
|
-
version.
|
|
9
|
-
|
|
10
|
-
This program is distributed in the hope that it will be useful, but
|
|
11
|
-
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
13
|
-
See the GNU General Public License for more details.
|
|
14
|
-
|
|
15
|
-
You should have received a copy of the GNU General Public License along with
|
|
16
|
-
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
-
*/
|
|
18
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.toArgs = toArgs;
|
|
20
|
-
exports.toLocalErr = toLocalErr;
|
|
21
|
-
exports.packRequestToWASM = packRequestToWASM;
|
|
22
|
-
exports.unpackReplyFromWASM = unpackReplyFromWASM;
|
|
23
|
-
exports.unpackSigningKeyPair = unpackSigningKeyPair;
|
|
24
|
-
exports.unpackBoolVal = unpackBoolVal;
|
|
25
|
-
const protobuf_type_1 = require("../protobuf-type");
|
|
26
|
-
const cryptor_proto_1 = require("../../protos/cryptor.proto");
|
|
27
|
-
function toArgs(...args) {
|
|
28
|
-
return args.map(val => ({ val }));
|
|
29
|
-
}
|
|
30
|
-
function toLocalErr(replyErr) {
|
|
31
|
-
if (replyErr.condition === 'cipher-verification') {
|
|
32
|
-
return { failedCipherVerification: true };
|
|
33
|
-
}
|
|
34
|
-
else if (replyErr.condition === 'signature-verification') {
|
|
35
|
-
return { failedSignatureVerification: true };
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
return new Error(`WASM cryptor ${replyErr.condition}: ${replyErr.message}`);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
const wasmRequestProtoType = protobuf_type_1.ProtoType.for(cryptor_proto_1.cryptor.Request);
|
|
42
|
-
const wasmReplyProtoType = protobuf_type_1.ProtoType.for(cryptor_proto_1.cryptor.Reply);
|
|
43
|
-
function packRequestToWASM(req) {
|
|
44
|
-
return wasmRequestProtoType.pack(req);
|
|
45
|
-
}
|
|
46
|
-
function unpackReplyFromWASM(replyBytes) {
|
|
47
|
-
return wasmReplyProtoType.unpack(replyBytes);
|
|
48
|
-
}
|
|
49
|
-
const boolValType = protobuf_type_1.ProtoType.for(cryptor_proto_1.cryptor.BoolVal);
|
|
50
|
-
const kpairType = protobuf_type_1.ProtoType.for(cryptor_proto_1.cryptor.Keypair);
|
|
51
|
-
function unpackSigningKeyPair(bytes) {
|
|
52
|
-
return kpairType.unpack(bytes);
|
|
53
|
-
}
|
|
54
|
-
function unpackBoolVal(bytes) {
|
|
55
|
-
return boolValType.unpack(bytes).val;
|
|
56
|
-
}
|
|
57
|
-
Object.freeze(exports);
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
Copyright (C) 2021 3NSoft Inc.
|
|
4
|
-
|
|
5
|
-
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
|
6
|
-
|
|
7
|
-
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
8
|
-
|
|
9
|
-
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
10
|
-
*/
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.startWasmFrom = startWasmFrom;
|
|
13
|
-
class MP1 {
|
|
14
|
-
constructor(wasmBytes) {
|
|
15
|
-
this.sinkMsgFromWasmInstance = undefined;
|
|
16
|
-
this.msgWaitingWriteCB = undefined;
|
|
17
|
-
const module = new WebAssembly.Module(wasmBytes);
|
|
18
|
-
this.instance = new WebAssembly.Instance(module, this.makeImports());
|
|
19
|
-
this.mp1_accept_msg = this.getExportedFn('_3nweb_mp1_accept_msg');
|
|
20
|
-
Object.seal(this);
|
|
21
|
-
}
|
|
22
|
-
getExportedFn(fName) {
|
|
23
|
-
const fn = this.instance.exports[fName];
|
|
24
|
-
if (typeof fn !== 'function') {
|
|
25
|
-
throw Error(`WASM instance doesn't export function ${fName}`);
|
|
26
|
-
}
|
|
27
|
-
return fn;
|
|
28
|
-
}
|
|
29
|
-
makeImports() {
|
|
30
|
-
const env = {
|
|
31
|
-
_3nweb_mp1_send_out_msg: (ptr, len) => this.processMsgFromModule(ptr, len),
|
|
32
|
-
_3nweb_mp1_write_msg_into: (ptr) => this.writeMsgInCB(ptr),
|
|
33
|
-
};
|
|
34
|
-
return { env };
|
|
35
|
-
}
|
|
36
|
-
processMsgFromModule(ptr, len) {
|
|
37
|
-
if (!this.sinkMsgFromWasmInstance) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
const msgBuf = this.getWasmMemoryArea(ptr, len);
|
|
41
|
-
const msg = new Uint8Array(msgBuf.length);
|
|
42
|
-
msg.set(msgBuf);
|
|
43
|
-
this.sinkMsgFromWasmInstance(msg);
|
|
44
|
-
}
|
|
45
|
-
writeMsgInCB(ptr) {
|
|
46
|
-
const buf = this.getWasmMemoryArea(ptr, this.msgWaitingWriteCB.length);
|
|
47
|
-
buf.set(this.msgWaitingWriteCB);
|
|
48
|
-
this.msgWaitingWriteCB = undefined;
|
|
49
|
-
}
|
|
50
|
-
getWasmMemoryArea(ptr, len) {
|
|
51
|
-
const memBuf = this.instance.exports.memory.buffer;
|
|
52
|
-
return new Uint8Array(memBuf, ptr, len);
|
|
53
|
-
}
|
|
54
|
-
start() {
|
|
55
|
-
this.getExportedFn('_start')();
|
|
56
|
-
}
|
|
57
|
-
sendMsg(msg) {
|
|
58
|
-
this.msgWaitingWriteCB = msg;
|
|
59
|
-
// Note that following call to WASM expects it to call back imported
|
|
60
|
-
// function that actually copies bytes from this.msgWaitingWriteCB into
|
|
61
|
-
// then given memory area.
|
|
62
|
-
this.mp1_accept_msg(msg.length);
|
|
63
|
-
}
|
|
64
|
-
setMsgListener(listener) {
|
|
65
|
-
this.sinkMsgFromWasmInstance = listener;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
Object.freeze(MP1.prototype);
|
|
69
|
-
Object.freeze(MP1);
|
|
70
|
-
function startWasmFrom(wasmModuleBytes) {
|
|
71
|
-
let mp1 = new MP1(wasmModuleBytes);
|
|
72
|
-
mp1.start();
|
|
73
|
-
return {
|
|
74
|
-
sendMsgIntoWASM: msg => mp1.sendMsg(msg),
|
|
75
|
-
setMsgListener: listener => mp1.setMsgListener(listener)
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
Object.freeze(exports);
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
Copyright (C) 2020, 2026 3NSoft Inc.
|
|
4
|
-
|
|
5
|
-
This program is free software: you can redistribute it and/or modify it under
|
|
6
|
-
the terms of the GNU General Public License as published by the Free Software
|
|
7
|
-
Foundation, either version 3 of the License, or (at your option) any later
|
|
8
|
-
version.
|
|
9
|
-
|
|
10
|
-
This program is distributed in the hope that it will be useful, but
|
|
11
|
-
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
13
|
-
See the GNU General Public License for more details.
|
|
14
|
-
|
|
15
|
-
You should have received a copy of the GNU General Public License along with
|
|
16
|
-
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
-
*/
|
|
18
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
const worker_threads_1 = require("worker_threads");
|
|
20
|
-
const ecma_nacl_1 = require("ecma-nacl");
|
|
21
|
-
const error_1 = require("../../lib-common/exceptions/error");
|
|
22
|
-
const runtime_1 = require("../../lib-common/exceptions/runtime");
|
|
23
|
-
if (!worker_threads_1.parentPort) {
|
|
24
|
-
throw new Error(`Missing expected parentPort. Is this called within WebWorker process?`);
|
|
25
|
-
}
|
|
26
|
-
const arrFactory = ecma_nacl_1.arrays.makeFactory();
|
|
27
|
-
const wipe = ecma_nacl_1.arrays.wipe;
|
|
28
|
-
const funcs = {
|
|
29
|
-
'scrypt': args => {
|
|
30
|
-
const progressCB = (n) => {
|
|
31
|
-
const reply = { interim: n };
|
|
32
|
-
worker_threads_1.parentPort.postMessage(reply);
|
|
33
|
-
};
|
|
34
|
-
const res = (0, ecma_nacl_1.scrypt)(args[0], args[1], args[2], args[3], args[4], args[5], progressCB, arrFactory);
|
|
35
|
-
wipe(args[0]);
|
|
36
|
-
return { res };
|
|
37
|
-
// electron v.11.0.3 worker thread fails on memory move
|
|
38
|
-
// return { res, trans: transfer(res) };
|
|
39
|
-
},
|
|
40
|
-
'box.calc_dhshared_key': args => {
|
|
41
|
-
const res = ecma_nacl_1.box.calc_dhshared_key(args[0], args[1], arrFactory);
|
|
42
|
-
wipe(args[0], args[1]);
|
|
43
|
-
return { res };
|
|
44
|
-
// electron v.11.0.3 worker thread fails on memory move
|
|
45
|
-
// return { res, trans: transfer(res) };
|
|
46
|
-
},
|
|
47
|
-
'box.generate_pubkey': args => {
|
|
48
|
-
const res = ecma_nacl_1.box.generate_pubkey(args[0], arrFactory);
|
|
49
|
-
wipe(args[0]);
|
|
50
|
-
return { res };
|
|
51
|
-
// electron v.11.0.3 worker thread fails on memory move
|
|
52
|
-
// return { res, trans: transfer(res) };
|
|
53
|
-
},
|
|
54
|
-
'sbox.open': args => {
|
|
55
|
-
const res = ecma_nacl_1.secret_box.open(args[0], args[1], args[2], arrFactory);
|
|
56
|
-
wipe(args[2]);
|
|
57
|
-
return { res };
|
|
58
|
-
// electron v.11.0.3 worker thread fails on memory move
|
|
59
|
-
// return { res, trans: transfer(res) };
|
|
60
|
-
},
|
|
61
|
-
'sbox.pack': args => {
|
|
62
|
-
const res = ecma_nacl_1.secret_box.pack(args[0], args[1], args[2], arrFactory);
|
|
63
|
-
wipe(args[2]);
|
|
64
|
-
return { res };
|
|
65
|
-
// electron v.11.0.3 worker thread fails on memory move
|
|
66
|
-
// return { res, trans: transfer(res) };
|
|
67
|
-
},
|
|
68
|
-
'sbox.formatWN.open': args => {
|
|
69
|
-
const res = ecma_nacl_1.secret_box.formatWN.open(args[0], args[1], arrFactory);
|
|
70
|
-
wipe(args[1]);
|
|
71
|
-
return { res };
|
|
72
|
-
// electron v.11.0.3 worker thread fails on memory move
|
|
73
|
-
// return { res, trans: transfer(res) };
|
|
74
|
-
},
|
|
75
|
-
'sbox.formatWN.pack': args => {
|
|
76
|
-
const res = ecma_nacl_1.secret_box.formatWN.pack(args[0], args[1], args[2], arrFactory);
|
|
77
|
-
wipe(args[2]);
|
|
78
|
-
return { res };
|
|
79
|
-
// electron v.11.0.3 worker thread fails on memory move
|
|
80
|
-
// return { res, trans: transfer(res) };
|
|
81
|
-
},
|
|
82
|
-
'sign.generate_keypair': args => {
|
|
83
|
-
const pair = ecma_nacl_1.signing.generate_keypair(args[0], arrFactory);
|
|
84
|
-
wipe(args[0]);
|
|
85
|
-
return { res: pair };
|
|
86
|
-
// electron v.11.0.3 worker thread fails on memory move
|
|
87
|
-
// return { res: pair, trans: transfer(pair.pkey, pair.skey) };
|
|
88
|
-
},
|
|
89
|
-
'sign.signature': args => {
|
|
90
|
-
const res = ecma_nacl_1.signing.signature(args[0], args[1], arrFactory);
|
|
91
|
-
wipe(args[1]);
|
|
92
|
-
return { res };
|
|
93
|
-
// electron v.11.0.3 worker thread fails on memory move
|
|
94
|
-
// return { res, trans: transfer(res) };
|
|
95
|
-
},
|
|
96
|
-
'sign.verify': args => {
|
|
97
|
-
const ok = ecma_nacl_1.signing.verify(args[0], args[1], args[2], arrFactory);
|
|
98
|
-
return { res: ok };
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
function wrapError(err) {
|
|
102
|
-
const exc = {
|
|
103
|
-
runtimeException: true,
|
|
104
|
-
type: 'cryptor',
|
|
105
|
-
stack: (0, runtime_1.getStackHere)(1)
|
|
106
|
-
};
|
|
107
|
-
if (err.failedCipherVerification) {
|
|
108
|
-
exc.failedCipherVerification = true;
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
exc.message = `Error occured in cryptor worker thread`;
|
|
112
|
-
exc.cause = (0, error_1.stringifyErr)(err);
|
|
113
|
-
}
|
|
114
|
-
return exc;
|
|
115
|
-
}
|
|
116
|
-
worker_threads_1.parentPort.on('message', (msg) => {
|
|
117
|
-
const { args, func } = msg;
|
|
118
|
-
const code = funcs[func];
|
|
119
|
-
if (!code) {
|
|
120
|
-
throw new Error(`Function ${func} is unknown`);
|
|
121
|
-
}
|
|
122
|
-
try {
|
|
123
|
-
const { res, trans } = code(args);
|
|
124
|
-
const reply = { res };
|
|
125
|
-
worker_threads_1.parentPort.postMessage(reply, trans);
|
|
126
|
-
}
|
|
127
|
-
catch (err) {
|
|
128
|
-
const reply = { err: wrapError(err) };
|
|
129
|
-
worker_threads_1.parentPort.postMessage(reply);
|
|
130
|
-
}
|
|
131
|
-
});
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
Copyright (C) 2020 3NSoft Inc.
|
|
4
|
-
|
|
5
|
-
This program is free software: you can redistribute it and/or modify it under
|
|
6
|
-
the terms of the GNU General Public License as published by the Free Software
|
|
7
|
-
Foundation, either version 3 of the License, or (at your option) any later
|
|
8
|
-
version.
|
|
9
|
-
|
|
10
|
-
This program is distributed in the hope that it will be useful, but
|
|
11
|
-
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
13
|
-
See the GNU General Public License for more details.
|
|
14
|
-
|
|
15
|
-
You should have received a copy of the GNU General Public License along with
|
|
16
|
-
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
-
*/
|
|
18
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
const worker_threads_1 = require("worker_threads");
|
|
20
|
-
const path_1 = require("path");
|
|
21
|
-
const wasm_mp1_modules_1 = require("./wasm-mp1-modules");
|
|
22
|
-
const fs_1 = require("fs");
|
|
23
|
-
if (!worker_threads_1.parentPort) {
|
|
24
|
-
throw new Error(`Missing expected parentPort. Is this called within WebWorker process?`);
|
|
25
|
-
}
|
|
26
|
-
const wasmFName = 'cryptor.wasm';
|
|
27
|
-
const wasmModPath = (0, path_1.join)(worker_threads_1.workerData.loadDir, wasmFName);
|
|
28
|
-
const wasmInstance = (0, wasm_mp1_modules_1.startWasmFrom)((0, fs_1.readFileSync)(wasmModPath));
|
|
29
|
-
wasmInstance.setMsgListener(msg => worker_threads_1.parentPort.postMessage(msg));
|
|
30
|
-
worker_threads_1.parentPort.on('message', (msg) => {
|
|
31
|
-
try {
|
|
32
|
-
wasmInstance.sendMsgIntoWASM(msg);
|
|
33
|
-
}
|
|
34
|
-
catch (err) {
|
|
35
|
-
console.error(err);
|
|
36
|
-
}
|
|
37
|
-
});
|