core-3nweb-client-lib 0.27.3 → 0.27.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/build/api-defs/files.d.ts +92 -29
- package/build/core/asmail/config/index.d.ts +2 -2
- package/build/core/asmail/config/index.js +2 -2
- package/build/core/asmail/config/invitations-anon.d.ts +10 -24
- package/build/core/asmail/config/invitations-anon.js +43 -31
- package/build/core/asmail/config/published-intro-key.d.ts +11 -22
- package/build/core/asmail/config/published-intro-key.js +47 -38
- package/build/core/asmail/delivery/per-recipient-wip.js +2 -2
- package/build/core/asmail/inbox/inbox-events.js +10 -5
- package/build/core/asmail/inbox/index.d.ts +3 -2
- package/build/core/asmail/inbox/index.js +15 -11
- package/build/core/asmail/inbox/msg-indexing.d.ts +17 -64
- package/build/core/asmail/inbox/msg-indexing.js +440 -311
- package/build/core/asmail/inbox/msg-on-disk.js +2 -1
- package/build/core/asmail/index.d.ts +1 -1
- package/build/core/asmail/index.js +5 -4
- package/build/core/asmail/keyring/correspondent-keys.d.ts +2 -2
- package/build/core/asmail/keyring/correspondent-keys.js +4 -2
- package/build/core/asmail/keyring/index.d.ts +10 -33
- package/build/core/asmail/keyring/index.js +88 -75
- package/build/core/asmail/msg/opener.js +4 -3
- package/build/core/asmail/msg/packer.d.ts +1 -0
- package/build/core/asmail/msg/packer.js +8 -4
- package/build/core/index.js +3 -5
- package/build/core/sign-in.js +1 -1
- package/build/core/storage/local/obj-files.js +2 -1
- package/build/core/storage/synced/obj-files.d.ts +2 -0
- package/build/core/storage/synced/obj-files.js +18 -1
- package/build/core/storage/synced/obj-status.d.ts +1 -0
- package/build/core/storage/synced/obj-status.js +10 -0
- package/build/core/storage/synced/storage.js +7 -23
- package/build/core/storage/synced/upload-header-file.js +4 -2
- package/build/core/storage/synced/upsyncer.js +3 -5
- package/build/ipc-via-protobuf/asmail-cap.js +14 -15
- package/build/ipc-via-protobuf/bytes.js +42 -18
- package/build/ipc-via-protobuf/file.d.ts +7 -0
- package/build/ipc-via-protobuf/file.js +103 -66
- package/build/ipc-via-protobuf/fs.js +127 -105
- package/build/ipc-via-protobuf/mailerid.js +2 -2
- package/build/ipc-via-protobuf/protobuf-msg.d.ts +1 -0
- package/build/ipc-via-protobuf/protobuf-msg.js +5 -1
- package/build/ipc-via-protobuf/startup-cap.js +8 -8
- package/build/ipc-via-protobuf/storage-cap.js +4 -4
- package/build/lib-client/3nstorage/xsp-fs/common.js +2 -0
- package/build/lib-client/3nstorage/xsp-fs/file-node.d.ts +5 -10
- package/build/lib-client/3nstorage/xsp-fs/file-node.js +26 -45
- package/build/lib-client/3nstorage/xsp-fs/file.d.ts +8 -7
- package/build/lib-client/3nstorage/xsp-fs/file.js +12 -18
- package/build/lib-client/3nstorage/xsp-fs/folder-node.d.ts +6 -1
- package/build/lib-client/3nstorage/xsp-fs/folder-node.js +20 -8
- package/build/lib-client/3nstorage/xsp-fs/fs.d.ts +19 -18
- package/build/lib-client/3nstorage/xsp-fs/fs.js +18 -19
- package/build/lib-client/3nstorage/xsp-fs/node-in-fs.d.ts +13 -4
- package/build/lib-client/3nstorage/xsp-fs/node-in-fs.js +63 -8
- package/build/lib-client/3nstorage/xsp-fs/node-persistence.d.ts +1 -0
- package/build/lib-client/3nstorage/xsp-fs/node-persistence.js +7 -5
- package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v1.js +3 -4
- package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v2.js +20 -15
- package/build/lib-client/cryptor/cryptor-in-worker.js +37 -47
- package/build/lib-client/cryptor/cryptor-wasm.js +1 -1
- package/build/lib-client/cryptor/cryptor.wasm +0 -0
- package/build/lib-client/cryptor/in-proc-js.js +15 -12
- package/build/lib-client/cryptor/in-proc-wasm.js +11 -8
- package/build/lib-client/cryptor/serialization-for-wasm.d.ts +36 -0
- package/build/lib-client/cryptor/serialization-for-wasm.js +58 -0
- package/build/lib-client/cryptor-work-labels.d.ts +26 -0
- package/build/lib-client/cryptor-work-labels.js +152 -0
- package/build/lib-client/fs-sync-utils.d.ts +7 -1
- package/build/lib-client/fs-sync-utils.js +18 -7
- package/build/lib-client/local-files/dev-file-src.d.ts +2 -1
- package/build/lib-client/local-files/dev-file-src.js +5 -1
- package/build/lib-client/local-files/device-fs.js +2 -1
- package/build/lib-client/objs-on-disk/obj-on-disk.d.ts +5 -2
- package/build/lib-client/objs-on-disk/obj-on-disk.js +21 -2
- package/build/lib-client/request-utils.js +14 -14
- package/build/lib-common/async-cryptor-wrap.d.ts +9 -9
- package/build/lib-common/async-cryptor-wrap.js +13 -13
- package/build/lib-common/byte-streaming/pipe.d.ts +1 -1
- package/build/lib-common/byte-streaming/pipe.js +3 -3
- package/build/lib-common/byte-streaming/wrapping.js +4 -2
- package/build/lib-common/json-utils.js +0 -3
- package/build/lib-common/objs-on-disk/file-layout.js +1 -1
- package/build/lib-common/processes/synced.js +0 -184
- package/build/lib-sqlite-on-3nstorage/index.d.ts +32 -0
- package/build/lib-sqlite-on-3nstorage/index.js +117 -0
- package/build/lib-sqlite-on-3nstorage/sqljs.d.ts +279 -0
- package/build/lib-sqlite-on-3nstorage/sqljs.js +223 -0
- package/build/protos/asmail.proto.js +10145 -5923
- package/build/protos/bytes.proto.js +731 -204
- package/build/protos/common.proto.js +192 -44
- package/build/protos/cryptor.proto.js +184 -61
- package/build/protos/file.proto.js +2388 -502
- package/build/protos/fs.proto.js +9894 -6046
- package/build/protos/ipc.proto.js +244 -61
- package/build/protos/logger.proto.js +219 -53
- package/build/protos/mailerid.proto.js +230 -50
- package/build/protos/startup.proto.js +341 -77
- package/build/protos/storage.proto.js +276 -62
- package/package.json +8 -7
- package/protos/bytes.proto +13 -4
- package/protos/file.proto +27 -8
- package/protos/fs.proto +31 -14
|
Binary file
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2020 3NSoft Inc.
|
|
3
|
+
Copyright (C) 2020, 2022 3NSoft Inc.
|
|
4
4
|
|
|
5
5
|
This program is free software: you can redistribute it and/or modify it under
|
|
6
6
|
the terms of the GNU General Public License as published by the Free Software
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.makeInProcessCryptor = void 0;
|
|
20
20
|
const ecma_nacl_1 = require("ecma-nacl");
|
|
21
|
-
|
|
21
|
+
const cryptor_work_labels_1 = require("../cryptor-work-labels");
|
|
22
|
+
function onNextTick(f) {
|
|
22
23
|
return new Promise((resolve, reject) => process.nextTick(() => {
|
|
23
24
|
try {
|
|
24
25
|
resolve(f());
|
|
@@ -30,24 +31,26 @@ function inNextTick(f) {
|
|
|
30
31
|
}
|
|
31
32
|
function makeInProcessCryptor() {
|
|
32
33
|
const arrFactory = ecma_nacl_1.arrays.makeFactory();
|
|
34
|
+
const workExecutor = new cryptor_work_labels_1.InProcAsyncExecutor();
|
|
33
35
|
return {
|
|
34
|
-
scrypt: (passwd, salt, logN, r, p, dkLen, progressCB) =>
|
|
36
|
+
scrypt: (passwd, salt, logN, r, p, dkLen, progressCB) => onNextTick(() => (0, ecma_nacl_1.scrypt)(passwd, salt, logN, r, p, dkLen, progressCB, arrFactory)),
|
|
35
37
|
box: {
|
|
36
|
-
calc_dhshared_key: (pk, sk) =>
|
|
37
|
-
generate_pubkey: sk =>
|
|
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))
|
|
38
40
|
},
|
|
39
41
|
sbox: {
|
|
40
|
-
|
|
41
|
-
|
|
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)),
|
|
42
45
|
formatWN: {
|
|
43
|
-
open: (cn, k) =>
|
|
44
|
-
pack: (m, n, k) =>
|
|
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))
|
|
45
48
|
}
|
|
46
49
|
},
|
|
47
50
|
signing: {
|
|
48
|
-
generate_keypair: seed =>
|
|
49
|
-
signature: (m, sk) =>
|
|
50
|
-
verify: (sig, m, pk) =>
|
|
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))
|
|
51
54
|
}
|
|
52
55
|
};
|
|
53
56
|
}
|
|
@@ -25,6 +25,7 @@ const cryptor_proto_1 = require("../../protos/cryptor.proto");
|
|
|
25
25
|
const deferred_1 = require("../../lib-common/processes/deferred");
|
|
26
26
|
const assert_1 = require("../../lib-common/assert");
|
|
27
27
|
const error_1 = require("../../lib-common/exceptions/error");
|
|
28
|
+
const cryptor_work_labels_1 = require("../cryptor-work-labels");
|
|
28
29
|
function wasmBytes() {
|
|
29
30
|
// There is a bug with electrons 12, 13, that doesn't let
|
|
30
31
|
// worker_thread read this file from asar pack, even though main thread
|
|
@@ -68,6 +69,7 @@ function makeInProcessWasmCryptor() {
|
|
|
68
69
|
const wasmInstance = (0, wasm_mp1_modules_1.startWasmFrom)(wasmBytes());
|
|
69
70
|
let deferred = undefined;
|
|
70
71
|
let interimSink = undefined;
|
|
72
|
+
const execCounter = new cryptor_work_labels_1.ExecCounter(() => (deferred ? 0 : 1));
|
|
71
73
|
async function call(req, interim) {
|
|
72
74
|
// In LiquidCore on iOS call was able to get before completion of
|
|
73
75
|
// previous call, therefore, the following await loop is needed.
|
|
@@ -129,23 +131,24 @@ function makeInProcessWasmCryptor() {
|
|
|
129
131
|
})
|
|
130
132
|
},
|
|
131
133
|
sbox: {
|
|
132
|
-
|
|
134
|
+
canStartUnderWorkLabel: l => execCounter.canStartUnderWorkLabel(l),
|
|
135
|
+
open: (c, n, k, workLabel) => execCounter.wrapOpPromise(workLabel, call({
|
|
133
136
|
func: 4,
|
|
134
137
|
byteArgs: toArgs(c, n, k)
|
|
135
|
-
}),
|
|
136
|
-
pack: (m, n, k) => call({
|
|
138
|
+
})),
|
|
139
|
+
pack: (m, n, k, workLabel) => execCounter.wrapOpPromise(workLabel, call({
|
|
137
140
|
func: 5,
|
|
138
141
|
byteArgs: toArgs(m, n, k)
|
|
139
|
-
}),
|
|
142
|
+
})),
|
|
140
143
|
formatWN: {
|
|
141
|
-
open: (cn, k) => call({
|
|
144
|
+
open: (cn, k, workLabel) => execCounter.wrapOpPromise(workLabel, call({
|
|
142
145
|
func: 6,
|
|
143
146
|
byteArgs: toArgs(cn, k)
|
|
144
|
-
}),
|
|
145
|
-
pack: (m, n, k) => call({
|
|
147
|
+
})),
|
|
148
|
+
pack: (m, n, k, workLabel) => execCounter.wrapOpPromise(workLabel, call({
|
|
146
149
|
func: 7,
|
|
147
150
|
byteArgs: toArgs(m, n, k)
|
|
148
|
-
})
|
|
151
|
+
}))
|
|
149
152
|
}
|
|
150
153
|
},
|
|
151
154
|
signing: {
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { signing } from 'ecma-nacl';
|
|
3
|
+
export interface WasmScryptRequest {
|
|
4
|
+
func: 1;
|
|
5
|
+
scryptArgs: {
|
|
6
|
+
passwd: Uint8Array;
|
|
7
|
+
salt: Uint8Array;
|
|
8
|
+
logN: number;
|
|
9
|
+
r: number;
|
|
10
|
+
p: number;
|
|
11
|
+
dkLen: number;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export interface WasmBinArgsRequest {
|
|
15
|
+
func: 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10;
|
|
16
|
+
byteArgs: ByteArg[];
|
|
17
|
+
}
|
|
18
|
+
export interface ByteArg {
|
|
19
|
+
val: Uint8Array;
|
|
20
|
+
}
|
|
21
|
+
export declare function toArgs(...args: Uint8Array[]): ByteArg[];
|
|
22
|
+
export declare type WasmRequest = WasmScryptRequest | WasmBinArgsRequest;
|
|
23
|
+
export interface WasmReply {
|
|
24
|
+
res?: ByteArg;
|
|
25
|
+
interim?: ByteArg;
|
|
26
|
+
err?: ReplyError;
|
|
27
|
+
}
|
|
28
|
+
export interface ReplyError {
|
|
29
|
+
condition: 'cipher-verification' | 'signature-verification' | 'configuration-error' | 'message-passing-error';
|
|
30
|
+
message: string;
|
|
31
|
+
}
|
|
32
|
+
export declare function toLocalErr(replyErr: ReplyError): Error | web3n.EncryptionException;
|
|
33
|
+
export declare function packRequestToWASM(req: WasmRequest): Buffer;
|
|
34
|
+
export declare function unpackReplyFromWASM(replyBytes: Buffer): WasmReply;
|
|
35
|
+
export declare function unpackSigningKeyPair(bytes: Buffer): signing.Keypair;
|
|
36
|
+
export declare function unpackBoolVal(bytes: Buffer): boolean;
|
|
@@ -0,0 +1,58 @@
|
|
|
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.unpackBoolVal = exports.unpackSigningKeyPair = exports.unpackReplyFromWASM = exports.packRequestToWASM = exports.toLocalErr = exports.toArgs = void 0;
|
|
20
|
+
const protobuf_type_1 = require("../protobuf-type");
|
|
21
|
+
const cryptor_proto_1 = require("../../protos/cryptor.proto");
|
|
22
|
+
function toArgs(...args) {
|
|
23
|
+
return args.map(val => ({ val }));
|
|
24
|
+
}
|
|
25
|
+
exports.toArgs = toArgs;
|
|
26
|
+
function toLocalErr(replyErr) {
|
|
27
|
+
if (replyErr.condition === 'cipher-verification') {
|
|
28
|
+
return { failedCipherVerification: true };
|
|
29
|
+
}
|
|
30
|
+
else if (replyErr.condition === 'signature-verification') {
|
|
31
|
+
return { failedSignatureVerification: true };
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
return new Error(`WASM cryptor ${replyErr.condition}: ${replyErr.message}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.toLocalErr = toLocalErr;
|
|
38
|
+
const wasmRequestProtoType = protobuf_type_1.ProtoType.for(cryptor_proto_1.cryptor.Request);
|
|
39
|
+
const wasmReplyProtoType = protobuf_type_1.ProtoType.for(cryptor_proto_1.cryptor.Reply);
|
|
40
|
+
function packRequestToWASM(req) {
|
|
41
|
+
return wasmRequestProtoType.pack(req);
|
|
42
|
+
}
|
|
43
|
+
exports.packRequestToWASM = packRequestToWASM;
|
|
44
|
+
function unpackReplyFromWASM(replyBytes) {
|
|
45
|
+
return wasmReplyProtoType.unpack(replyBytes);
|
|
46
|
+
}
|
|
47
|
+
exports.unpackReplyFromWASM = unpackReplyFromWASM;
|
|
48
|
+
const boolValType = protobuf_type_1.ProtoType.for(cryptor_proto_1.cryptor.BoolVal);
|
|
49
|
+
const kpairType = protobuf_type_1.ProtoType.for(cryptor_proto_1.cryptor.Keypair);
|
|
50
|
+
function unpackSigningKeyPair(bytes) {
|
|
51
|
+
return kpairType.unpack(bytes);
|
|
52
|
+
}
|
|
53
|
+
exports.unpackSigningKeyPair = unpackSigningKeyPair;
|
|
54
|
+
function unpackBoolVal(bytes) {
|
|
55
|
+
return boolValType.unpack(bytes).val;
|
|
56
|
+
}
|
|
57
|
+
exports.unpackBoolVal = unpackBoolVal;
|
|
58
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare namespace cryptoWorkLabels {
|
|
2
|
+
type LabelType = 'asmail' | 'storage';
|
|
3
|
+
function makeFor(type: LabelType, id: string): number;
|
|
4
|
+
function typeOf(label: number): LabelType | undefined;
|
|
5
|
+
function makeForNonce(type: LabelType, n: Uint8Array): number;
|
|
6
|
+
function makeRandom(type: LabelType): number;
|
|
7
|
+
}
|
|
8
|
+
export declare abstract class LabeledWorkQueues {
|
|
9
|
+
private readonly workQueues;
|
|
10
|
+
protected addToWorkQueue(workLabel: number): void;
|
|
11
|
+
protected removeFromWorkQueue(workLabel: number): void;
|
|
12
|
+
protected abstract idleWorkers(): number;
|
|
13
|
+
canStartUnderWorkLabel(workLabel: number): number;
|
|
14
|
+
wrapOpPromise<T>(workLabel: number, workOp: Promise<T>): Promise<T>;
|
|
15
|
+
}
|
|
16
|
+
export declare class InProcAsyncExecutor extends LabeledWorkQueues {
|
|
17
|
+
private readonly maxOfRunning;
|
|
18
|
+
private opsInExec;
|
|
19
|
+
constructor(maxOfRunning?: number);
|
|
20
|
+
idleWorkers(): number;
|
|
21
|
+
execOpOnNextTick<T>(workLabel: number, op: () => T): Promise<T>;
|
|
22
|
+
}
|
|
23
|
+
export declare class ExecCounter extends LabeledWorkQueues {
|
|
24
|
+
protected readonly idleWorkers: () => number;
|
|
25
|
+
constructor(idleWorkers: () => number);
|
|
26
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright (C) 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.ExecCounter = exports.InProcAsyncExecutor = exports.LabeledWorkQueues = exports.cryptoWorkLabels = void 0;
|
|
20
|
+
var cryptoWorkLabels;
|
|
21
|
+
(function (cryptoWorkLabels) {
|
|
22
|
+
function makeFor(type, id) {
|
|
23
|
+
const low = charsToNumber(id, 0, 5);
|
|
24
|
+
const high = labelToHighNum(type) + charsToNumber(id, 0, 3) & 0x1ffff;
|
|
25
|
+
return (low + (high * 0x100000000));
|
|
26
|
+
}
|
|
27
|
+
cryptoWorkLabels.makeFor = makeFor;
|
|
28
|
+
function labelToHighNum(type) {
|
|
29
|
+
switch (type) {
|
|
30
|
+
case 'storage':
|
|
31
|
+
return 1 << 17;
|
|
32
|
+
case 'asmail':
|
|
33
|
+
return 2 << 17;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function typeOf(label) {
|
|
37
|
+
switch ((label / 0x100000000) >> 17) {
|
|
38
|
+
case 1:
|
|
39
|
+
return 'storage';
|
|
40
|
+
case 2:
|
|
41
|
+
return 'asmail';
|
|
42
|
+
default:
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
cryptoWorkLabels.typeOf = typeOf;
|
|
47
|
+
function charsToNumber(s, start, len) {
|
|
48
|
+
const rounds = Math.max(Math.min(s.length - start, len), 0);
|
|
49
|
+
let num = 0;
|
|
50
|
+
for (let i = 0; i < rounds; i += 1) {
|
|
51
|
+
num ^= s.charCodeAt(i) << (i * 7);
|
|
52
|
+
}
|
|
53
|
+
return num;
|
|
54
|
+
}
|
|
55
|
+
function makeForNonce(type, n) {
|
|
56
|
+
const low = n[0] + (n[1] << 8) + (n[2] << 16) + (n[3] << 24);
|
|
57
|
+
const high = labelToHighNum(type) +
|
|
58
|
+
(n[4] + (n[5] << 8) + (n[6] << 16)) & 0x1ffff;
|
|
59
|
+
return (low + (high * 0x100000000));
|
|
60
|
+
}
|
|
61
|
+
cryptoWorkLabels.makeForNonce = makeForNonce;
|
|
62
|
+
function makeRandom(type) {
|
|
63
|
+
const low = (Math.random() * 0xffffffff) & 0xffffffff;
|
|
64
|
+
const high = labelToHighNum(type) +
|
|
65
|
+
(Math.random() * 0x1ffff) & 0x1ffff;
|
|
66
|
+
return (low + (high * 0x100000000));
|
|
67
|
+
}
|
|
68
|
+
cryptoWorkLabels.makeRandom = makeRandom;
|
|
69
|
+
})(cryptoWorkLabels = exports.cryptoWorkLabels || (exports.cryptoWorkLabels = {}));
|
|
70
|
+
Object.freeze(cryptoWorkLabels);
|
|
71
|
+
class LabeledWorkQueues {
|
|
72
|
+
constructor() {
|
|
73
|
+
this.workQueues = new Map();
|
|
74
|
+
}
|
|
75
|
+
addToWorkQueue(workLabel) {
|
|
76
|
+
const inQueue = this.workQueues.get(workLabel);
|
|
77
|
+
this.workQueues.set(workLabel, (inQueue ? inQueue + 1 : 1));
|
|
78
|
+
}
|
|
79
|
+
removeFromWorkQueue(workLabel) {
|
|
80
|
+
const inQueue = this.workQueues.get(workLabel);
|
|
81
|
+
if (inQueue && (inQueue > 1)) {
|
|
82
|
+
this.workQueues.set(workLabel, inQueue - 1);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
this.workQueues.delete(workLabel);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
canStartUnderWorkLabel(workLabel) {
|
|
89
|
+
const maxIdle = this.idleWorkers() - this.workQueues.size;
|
|
90
|
+
if (maxIdle <= 0) {
|
|
91
|
+
return (this.workQueues.has(workLabel) ? 0 : 1);
|
|
92
|
+
}
|
|
93
|
+
const inQueue = this.workQueues.get(workLabel);
|
|
94
|
+
return (inQueue ? Math.max(0, inQueue) : maxIdle);
|
|
95
|
+
}
|
|
96
|
+
async wrapOpPromise(workLabel, workOp) {
|
|
97
|
+
this.addToWorkQueue(workLabel);
|
|
98
|
+
try {
|
|
99
|
+
return await workOp;
|
|
100
|
+
}
|
|
101
|
+
finally {
|
|
102
|
+
this.removeFromWorkQueue(workLabel);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
exports.LabeledWorkQueues = LabeledWorkQueues;
|
|
107
|
+
Object.freeze(LabeledWorkQueues.prototype);
|
|
108
|
+
Object.freeze(LabeledWorkQueues);
|
|
109
|
+
class InProcAsyncExecutor extends LabeledWorkQueues {
|
|
110
|
+
constructor(maxOfRunning = 1) {
|
|
111
|
+
super();
|
|
112
|
+
this.maxOfRunning = maxOfRunning;
|
|
113
|
+
this.opsInExec = 0;
|
|
114
|
+
Object.seal(this);
|
|
115
|
+
}
|
|
116
|
+
idleWorkers() {
|
|
117
|
+
return Math.max((this.maxOfRunning - this.opsInExec), 0);
|
|
118
|
+
}
|
|
119
|
+
async execOpOnNextTick(workLabel, op) {
|
|
120
|
+
this.opsInExec += 1;
|
|
121
|
+
try {
|
|
122
|
+
return await this.wrapOpPromise(workLabel, onNextTick(op));
|
|
123
|
+
}
|
|
124
|
+
finally {
|
|
125
|
+
this.opsInExec -= 1;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
exports.InProcAsyncExecutor = InProcAsyncExecutor;
|
|
130
|
+
Object.freeze(InProcAsyncExecutor.prototype);
|
|
131
|
+
Object.freeze(InProcAsyncExecutor);
|
|
132
|
+
class ExecCounter extends LabeledWorkQueues {
|
|
133
|
+
constructor(idleWorkers) {
|
|
134
|
+
super();
|
|
135
|
+
this.idleWorkers = idleWorkers;
|
|
136
|
+
Object.seal(this);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
exports.ExecCounter = ExecCounter;
|
|
140
|
+
Object.freeze(ExecCounter.prototype);
|
|
141
|
+
Object.freeze(ExecCounter);
|
|
142
|
+
async function onNextTick(action) {
|
|
143
|
+
return new Promise((resolve, reject) => process.nextTick(() => {
|
|
144
|
+
try {
|
|
145
|
+
resolve(action());
|
|
146
|
+
}
|
|
147
|
+
catch (err) {
|
|
148
|
+
reject(err);
|
|
149
|
+
}
|
|
150
|
+
}));
|
|
151
|
+
}
|
|
152
|
+
Object.freeze(exports);
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
+
import { Observable } from "rxjs";
|
|
1
2
|
declare type WritableFS = web3n.files.WritableFS;
|
|
2
|
-
|
|
3
|
+
declare type ReadonlyFS = web3n.files.ReadonlyFS;
|
|
4
|
+
declare type RemoteEvent = web3n.files.RemoteEvent;
|
|
5
|
+
declare type FileEvent = web3n.files.FileEvent;
|
|
6
|
+
declare type FolderEvent = web3n.files.FolderEvent;
|
|
7
|
+
export declare function getRemoteFolderChanges(fs: WritableFS, forceServerCheck?: boolean): Promise<void>;
|
|
3
8
|
export declare function getOrMakeAndUploadFolderIn(fs: WritableFS, folder: string): Promise<WritableFS>;
|
|
4
9
|
export declare function uploadFolderChangesIfAny(fs: WritableFS): Promise<void>;
|
|
10
|
+
export declare function observableFromTreeEvents(fs: ReadonlyFS, rootPath: string): Observable<RemoteEvent | FileEvent | FolderEvent>;
|
|
5
11
|
export {};
|
|
@@ -16,11 +16,18 @@
|
|
|
16
16
|
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.uploadFolderChangesIfAny = exports.getOrMakeAndUploadFolderIn = exports.getRemoteFolderChanges = void 0;
|
|
19
|
+
exports.observableFromTreeEvents = exports.uploadFolderChangesIfAny = exports.getOrMakeAndUploadFolderIn = exports.getRemoteFolderChanges = void 0;
|
|
20
|
+
const rxjs_1 = require("rxjs");
|
|
20
21
|
const exceptions_1 = require("./3nstorage/exceptions");
|
|
21
|
-
async function getRemoteFolderChanges(fs) {
|
|
22
|
-
|
|
22
|
+
async function getRemoteFolderChanges(fs, forceServerCheck = false) {
|
|
23
|
+
if (forceServerCheck) {
|
|
24
|
+
await fs.v.sync.updateStatusInfo('');
|
|
25
|
+
}
|
|
26
|
+
let { state } = await fs.v.sync.status('');
|
|
23
27
|
if (state === 'behind') {
|
|
28
|
+
if (!forceServerCheck) {
|
|
29
|
+
await fs.v.sync.updateStatusInfo('');
|
|
30
|
+
}
|
|
24
31
|
await fs.v.sync.adoptRemote('');
|
|
25
32
|
}
|
|
26
33
|
else if (state === 'conflicting') {
|
|
@@ -51,11 +58,15 @@ async function getOrMakeAndUploadFolderIn(fs, folder) {
|
|
|
51
58
|
}
|
|
52
59
|
exports.getOrMakeAndUploadFolderIn = getOrMakeAndUploadFolderIn;
|
|
53
60
|
async function uploadFolderChangesIfAny(fs) {
|
|
54
|
-
const { state } = await fs.v.sync.
|
|
55
|
-
if (
|
|
56
|
-
|
|
61
|
+
const { state } = await fs.v.sync.status('');
|
|
62
|
+
if (state === 'unsynced') {
|
|
63
|
+
await fs.v.sync.updateStatusInfo('');
|
|
64
|
+
await fs.v.sync.upload('');
|
|
57
65
|
}
|
|
58
|
-
await fs.v.sync.upload('');
|
|
59
66
|
}
|
|
60
67
|
exports.uploadFolderChangesIfAny = uploadFolderChangesIfAny;
|
|
68
|
+
function observableFromTreeEvents(fs, rootPath) {
|
|
69
|
+
return new rxjs_1.Observable(obs => fs.watchTree(rootPath, undefined, obs));
|
|
70
|
+
}
|
|
71
|
+
exports.observableFromTreeEvents = observableFromTreeEvents;
|
|
61
72
|
Object.freeze(exports);
|
|
@@ -12,7 +12,8 @@ export declare class DevFileByteSource implements ByteSource {
|
|
|
12
12
|
size: number;
|
|
13
13
|
isEndless: boolean;
|
|
14
14
|
}>;
|
|
15
|
-
|
|
15
|
+
readNext(len: number): Promise<Uint8Array | undefined>;
|
|
16
16
|
seek(offset: number): Promise<void>;
|
|
17
|
+
readAt(pos: number, len: number): Promise<Uint8Array | undefined>;
|
|
17
18
|
getPosition(): Promise<number>;
|
|
18
19
|
}
|
|
@@ -34,7 +34,7 @@ class DevFileByteSource {
|
|
|
34
34
|
async getSize() {
|
|
35
35
|
return { size: this.size, isEndless: false };
|
|
36
36
|
}
|
|
37
|
-
async
|
|
37
|
+
async readNext(len) {
|
|
38
38
|
if (this.offset >= this.size) {
|
|
39
39
|
return;
|
|
40
40
|
}
|
|
@@ -68,6 +68,10 @@ class DevFileByteSource {
|
|
|
68
68
|
}
|
|
69
69
|
this.offset = offset;
|
|
70
70
|
}
|
|
71
|
+
async readAt(pos, len) {
|
|
72
|
+
await this.seek(pos);
|
|
73
|
+
return await this.readNext(len);
|
|
74
|
+
}
|
|
71
75
|
async getPosition() {
|
|
72
76
|
return this.offset;
|
|
73
77
|
}
|
|
@@ -38,10 +38,13 @@ export declare class ObjOnDisk {
|
|
|
38
38
|
diff: DiffInfo;
|
|
39
39
|
newSegsPackOrder: FiniteChunk[];
|
|
40
40
|
};
|
|
41
|
+
private segsThatNeedDownload;
|
|
42
|
+
doesFileNeedDownload(): boolean;
|
|
43
|
+
downloadMissingSections(): Promise<void>;
|
|
41
44
|
}
|
|
42
45
|
export interface ObjDownloader {
|
|
43
|
-
getLayoutWithHeaderAndFirstSegs(objId: ObjId, version: number)
|
|
44
|
-
getSegs(objId: ObjId, version: number, start: number, end: number)
|
|
46
|
+
getLayoutWithHeaderAndFirstSegs: (objId: ObjId, version: number) => Promise<InitDownloadParts>;
|
|
47
|
+
getSegs: (objId: ObjId, version: number, start: number, end: number) => Promise<Uint8Array>;
|
|
45
48
|
}
|
|
46
49
|
export interface InitDownloadParts {
|
|
47
50
|
layout: Layout;
|
|
@@ -192,6 +192,20 @@ class ObjOnDisk {
|
|
|
192
192
|
diffFromBase() {
|
|
193
193
|
return this.objFile.diffFromBase();
|
|
194
194
|
}
|
|
195
|
+
segsThatNeedDownload() {
|
|
196
|
+
const totalLen = this.objFile.getTotalSegsLen();
|
|
197
|
+
const allSegs = this.objFile.segsLocations(0, totalLen);
|
|
198
|
+
return allSegs.filter(({ type }) => (type === 'new'));
|
|
199
|
+
}
|
|
200
|
+
doesFileNeedDownload() {
|
|
201
|
+
return (this.segsThatNeedDownload().length === 0);
|
|
202
|
+
}
|
|
203
|
+
async downloadMissingSections() {
|
|
204
|
+
const needDownload = this.segsThatNeedDownload();
|
|
205
|
+
for (const chunk of needDownload) {
|
|
206
|
+
await this.downloadAndSaveSegsChunk(chunk);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
195
209
|
}
|
|
196
210
|
exports.ObjOnDisk = ObjOnDisk;
|
|
197
211
|
Object.freeze(ObjOnDisk.prototype);
|
|
@@ -203,7 +217,7 @@ class ByteSourceFromObjOnDisk {
|
|
|
203
217
|
this.segsPointer = 0;
|
|
204
218
|
Object.seal(this);
|
|
205
219
|
}
|
|
206
|
-
async
|
|
220
|
+
async readNext(len) {
|
|
207
221
|
(0, assert_1.assert)((Number.isInteger(len) && (len >= 0)) || (len === undefined), 'Illegal length parameter given: ' + len);
|
|
208
222
|
const start = this.segsPointer;
|
|
209
223
|
if (len === undefined) {
|
|
@@ -223,7 +237,8 @@ class ByteSourceFromObjOnDisk {
|
|
|
223
237
|
async getSize() {
|
|
224
238
|
const size = this.totalSegsLen();
|
|
225
239
|
return ((typeof size === 'number') ?
|
|
226
|
-
{ size, isEndless: false } :
|
|
240
|
+
{ size, isEndless: false } :
|
|
241
|
+
{ size: 0, isEndless: true });
|
|
227
242
|
}
|
|
228
243
|
async seek(offset) {
|
|
229
244
|
(0, assert_1.assert)(Number.isInteger(offset) && (offset >= 0), 'Illegal offset is given to seek: ' + offset);
|
|
@@ -235,6 +250,10 @@ class ByteSourceFromObjOnDisk {
|
|
|
235
250
|
this.segsPointer = Math.min(offset, segsLen);
|
|
236
251
|
}
|
|
237
252
|
}
|
|
253
|
+
async readAt(pos, len) {
|
|
254
|
+
await this.seek(pos);
|
|
255
|
+
return await this.readNext(len);
|
|
256
|
+
}
|
|
238
257
|
async getPosition() {
|
|
239
258
|
return this.segsPointer;
|
|
240
259
|
}
|
|
@@ -72,7 +72,7 @@ function formHttpsReqOpts(opts, contentType, reqBody) {
|
|
|
72
72
|
return netReqOpts;
|
|
73
73
|
}
|
|
74
74
|
exports.formHttpsReqOpts = formHttpsReqOpts;
|
|
75
|
-
function attachRequestReaders(clReq, opts) {
|
|
75
|
+
async function attachRequestReaders(clReq, opts) {
|
|
76
76
|
// XXX do something for timeouts, that doesn't break good long connections
|
|
77
77
|
// const timeout = (opts.timeout ? opts.timeout : DEFAULT_TIMEOUT);
|
|
78
78
|
// note that we attach reading of body to response as close as possible to
|
|
@@ -80,23 +80,23 @@ function attachRequestReaders(clReq, opts) {
|
|
|
80
80
|
// next tick occurs in between.
|
|
81
81
|
const response$ = (0, rxjs_1.fromEvent)(clReq, 'response', (res) => ({ res, resBodyPromise: readAllBytesFrom(res) }))
|
|
82
82
|
.pipe((0, operators_1.take)(1));
|
|
83
|
-
const err$ = (0, rxjs_1.fromEvent)(clReq, 'error')
|
|
84
|
-
.pipe((0, operators_1.map)(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
83
|
+
const err$ = (0, rxjs_1.fromEvent)(clReq, 'error', e => (0, http_1.makeConnectionException)(opts.url, opts.method, 'Cannot connect', e))
|
|
84
|
+
.pipe((0, operators_1.map)(exc => { throw exc; }), (0, operators_1.takeUntil)(response$));
|
|
85
|
+
try {
|
|
86
|
+
const reply = await (0, rxjs_1.lastValueFrom)((0, rxjs_1.merge)(response$, err$)
|
|
87
|
+
.pipe((0, operators_1.mergeMap)(async (resAndBodyProm) => {
|
|
88
|
+
const { res, resBodyPromise } = resAndBodyProm;
|
|
89
|
+
const resBody = await resBodyPromise;
|
|
90
|
+
return { res, resBody };
|
|
91
|
+
}, 1)));
|
|
92
|
+
return reply;
|
|
93
|
+
}
|
|
94
|
+
catch (exc) {
|
|
95
95
|
if (exc.cause === TIMEOUT_FLAG) {
|
|
96
96
|
clReq.abort();
|
|
97
97
|
}
|
|
98
98
|
throw exc;
|
|
99
|
-
}
|
|
99
|
+
}
|
|
100
100
|
}
|
|
101
101
|
const TIMEOUT_FLAG = 'Request Timeout';
|
|
102
102
|
function isTimeoutErr(err, opts, currentAttempt) {
|
|
@@ -41,6 +41,7 @@ export interface Decryptor {
|
|
|
41
41
|
* This returns an encryptor that packs bytes according to "with-nonce" format,
|
|
42
42
|
* keeping track and automatically advancing nonce.
|
|
43
43
|
* @param cryptor is an async cryptor that will be used by created encryptor.
|
|
44
|
+
* @param workLabel
|
|
44
45
|
* @param key for new encryptor.
|
|
45
46
|
* Note that key will be copied, thus, if given array shall never be used
|
|
46
47
|
* anywhere, it should be wiped after this call.
|
|
@@ -51,16 +52,15 @@ export interface Decryptor {
|
|
|
51
52
|
* @param delta is a number between 1 and 255 inclusive, used to advance nonce.
|
|
52
53
|
* When missing, it defaults to one.
|
|
53
54
|
*/
|
|
54
|
-
export declare function makeEncryptor(cryptor: AsyncSBoxCryptor, key: Uint8Array, nextNonce: Uint8Array, delta?: number): Encryptor;
|
|
55
|
+
export declare function makeEncryptor(cryptor: AsyncSBoxCryptor, workLabel: number, key: Uint8Array, nextNonce: Uint8Array, delta?: number): Encryptor;
|
|
55
56
|
/**
|
|
56
|
-
*
|
|
57
|
+
* @param cryptor
|
|
58
|
+
* @param workLabel
|
|
57
59
|
* @param key for new decryptor.
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* Note that key will be copied, thus, if given array shall never be used anywhere,
|
|
61
|
-
* it should be wiped after this call.
|
|
60
|
+
* Note that key will be copied, thus, if given array shall never be used
|
|
61
|
+
* anywhere, it should be wiped after this call.
|
|
62
62
|
* @return a frozen object with pack & open and destroy functions.
|
|
63
63
|
*/
|
|
64
|
-
export declare function makeDecryptor(cryptor: AsyncSBoxCryptor, key: Uint8Array): Decryptor;
|
|
65
|
-
export declare function makeDecryptorForKeyPair(cryptor: AsyncSBoxCryptor, pkey: Uint8Array, skey: Uint8Array): Decryptor;
|
|
66
|
-
export declare function makeEncryptorWithKeyPair(cryptor: AsyncSBoxCryptor, pkey: Uint8Array, skey: Uint8Array, nextNonce: Uint8Array, delta?: number): Encryptor;
|
|
64
|
+
export declare function makeDecryptor(cryptor: AsyncSBoxCryptor, workLabel: number, key: Uint8Array): Decryptor;
|
|
65
|
+
export declare function makeDecryptorForKeyPair(cryptor: AsyncSBoxCryptor, workLabel: number, pkey: Uint8Array, skey: Uint8Array): Decryptor;
|
|
66
|
+
export declare function makeEncryptorWithKeyPair(cryptor: AsyncSBoxCryptor, workLabel: number, pkey: Uint8Array, skey: Uint8Array, nextNonce: Uint8Array, delta?: number): Encryptor;
|