core-3nweb-client-lib 0.26.1 → 0.27.3
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/asmail.d.ts +1 -1
- package/build/api-defs/files.d.ts +281 -75
- package/build/core/app-files.js +7 -7
- package/build/core/asmail/config/common.js +2 -2
- package/build/core/asmail/config/index.js +2 -2
- package/build/core/asmail/config/published-intro-key.js +1 -1
- package/build/core/asmail/delivery/common.js +7 -7
- package/build/core/asmail/delivery/index.js +5 -5
- package/build/core/asmail/delivery/msg.js +4 -4
- package/build/core/asmail/delivery/per-recipient-wip.js +1 -1
- package/build/core/asmail/inbox/attachments/fs.d.ts +2 -1
- package/build/core/asmail/inbox/attachments/fs.js +9 -4
- package/build/core/asmail/inbox/cached-msgs.js +1 -1
- package/build/core/asmail/inbox/inbox-events.js +4 -4
- package/build/core/asmail/inbox/index.js +10 -10
- package/build/core/asmail/inbox/msg-downloader.js +1 -1
- package/build/core/asmail/inbox/msg-indexing.js +1 -1
- package/build/core/asmail/inbox/msg-on-disk.js +5 -5
- package/build/core/asmail/index.d.ts +3 -3
- package/build/core/asmail/index.js +13 -8
- package/build/core/asmail/key-verification.js +5 -5
- package/build/core/asmail/keyring/common.js +7 -6
- package/build/core/asmail/keyring/correspondent-keys.js +8 -7
- package/build/core/asmail/keyring/id-to-email-map.js +2 -1
- package/build/core/asmail/keyring/index.d.ts +7 -8
- package/build/core/asmail/keyring/index.js +15 -14
- package/build/core/asmail/keyring/keyring-storage.js +2 -1
- package/build/core/asmail/msg/opener.js +3 -3
- package/build/core/asmail/msg/packer.js +13 -13
- package/build/core/asmail/sending-params/own-params.js +2 -2
- package/build/core/asmail/sending-params/params-from-others.js +1 -1
- package/build/core/id-manager/index.d.ts +43 -0
- package/build/core/{id-manager.js → id-manager/index.js} +36 -114
- package/build/core/id-manager/key-storage.d.ts +21 -0
- package/build/core/id-manager/key-storage.js +96 -0
- package/build/core/index.d.ts +2 -1
- package/build/core/index.js +31 -33
- package/build/core/sign-in.d.ts +1 -2
- package/build/core/sign-in.js +8 -17
- package/build/core/sign-up.d.ts +2 -0
- package/build/core/sign-up.js +11 -10
- package/build/core/storage/common/json-saving.js +2 -2
- package/build/core/storage/common/obj-info-file.d.ts +12 -4
- package/build/core/storage/common/obj-info-file.js +66 -34
- package/build/core/storage/common/utils.d.ts +2 -0
- package/build/core/storage/common/utils.js +32 -0
- package/build/core/storage/index.d.ts +5 -17
- package/build/core/storage/index.js +78 -119
- package/build/core/storage/local/obj-files-gc.d.ts +2 -0
- package/build/core/storage/local/obj-files-gc.js +49 -37
- package/build/core/storage/local/obj-files.d.ts +4 -7
- package/build/core/storage/local/obj-files.js +7 -10
- package/build/core/storage/local/obj-status.d.ts +12 -6
- package/build/core/storage/local/obj-status.js +24 -9
- package/build/core/storage/local/storage.d.ts +10 -7
- package/build/core/storage/local/storage.js +29 -18
- package/build/core/storage/synced/downloader.js +1 -1
- package/build/core/storage/synced/obj-files-gc.d.ts +1 -0
- package/build/core/storage/synced/obj-files-gc.js +76 -39
- package/build/core/storage/synced/obj-files.d.ts +50 -36
- package/build/core/storage/synced/obj-files.js +201 -162
- package/build/core/storage/synced/obj-status.d.ts +99 -86
- package/build/core/storage/synced/obj-status.js +520 -251
- package/build/core/storage/synced/remote-events.d.ts +11 -12
- package/build/core/storage/synced/remote-events.js +73 -56
- package/build/core/storage/synced/storage.d.ts +24 -10
- package/build/core/storage/synced/storage.js +147 -47
- package/build/core/storage/synced/upload-header-file.d.ts +4 -0
- package/build/core/storage/synced/upload-header-file.js +64 -0
- package/build/core/storage/synced/upsyncer.d.ts +12 -7
- package/build/core/storage/synced/upsyncer.js +210 -280
- package/build/core/storage/system-folders/apps-data.d.ts +16 -0
- package/build/core/storage/system-folders/apps-data.js +110 -0
- package/build/core/storage/system-folders/index.d.ts +18 -0
- package/build/core/storage/system-folders/index.js +77 -0
- package/build/core-ipc/common-caps.js +3 -3
- package/build/core-ipc/generic.js +8 -8
- package/build/core-ipc/startup-caps.js +2 -2
- package/build/cryptors.js +6 -2
- package/build/ipc-via-protobuf/asmail-cap.js +58 -57
- package/build/ipc-via-protobuf/bytes.js +16 -17
- package/build/ipc-via-protobuf/connector-clients-side.d.ts +1 -0
- package/build/ipc-via-protobuf/connector-clients-side.js +14 -15
- package/build/ipc-via-protobuf/connector-services-side.js +10 -10
- package/build/ipc-via-protobuf/connector.js +4 -4
- package/build/ipc-via-protobuf/file.d.ts +48 -12
- package/build/ipc-via-protobuf/file.js +474 -126
- package/build/ipc-via-protobuf/fs.d.ts +8 -0
- package/build/ipc-via-protobuf/fs.js +577 -142
- package/build/ipc-via-protobuf/log-cap.js +2 -2
- package/build/ipc-via-protobuf/mailerid.js +3 -3
- package/build/ipc-via-protobuf/protobuf-msg.d.ts +1 -0
- package/build/ipc-via-protobuf/protobuf-msg.js +11 -7
- package/build/ipc-via-protobuf/startup-cap.js +21 -21
- package/build/ipc-via-protobuf/storage-cap.js +12 -12
- package/build/ipc.js +7 -2
- package/build/lib-client/3nstorage/exceptions.d.ts +16 -1
- package/build/lib-client/3nstorage/exceptions.js +21 -3
- package/build/lib-client/3nstorage/service.d.ts +21 -3
- package/build/lib-client/3nstorage/service.js +128 -46
- package/build/lib-client/3nstorage/util/file-based-json.d.ts +2 -1
- package/build/lib-client/3nstorage/util/file-based-json.js +3 -2
- package/build/lib-client/3nstorage/util/for-arrays.d.ts +1 -0
- package/build/lib-client/3nstorage/util/for-arrays.js +32 -0
- package/build/lib-client/3nstorage/xsp-fs/attrs.js +17 -17
- package/build/lib-client/3nstorage/xsp-fs/common.d.ts +44 -19
- package/build/lib-client/3nstorage/xsp-fs/common.js +30 -19
- package/build/lib-client/3nstorage/xsp-fs/file-node.d.ts +1 -0
- package/build/lib-client/3nstorage/xsp-fs/file-node.js +17 -13
- package/build/lib-client/3nstorage/xsp-fs/file.d.ts +31 -6
- package/build/lib-client/3nstorage/xsp-fs/file.js +73 -25
- package/build/lib-client/3nstorage/xsp-fs/folder-node-serialization.js +4 -4
- package/build/lib-client/3nstorage/xsp-fs/folder-node.d.ts +32 -13
- package/build/lib-client/3nstorage/xsp-fs/folder-node.js +752 -192
- package/build/lib-client/3nstorage/xsp-fs/fs.d.ts +35 -4
- package/build/lib-client/3nstorage/xsp-fs/fs.js +236 -119
- package/build/lib-client/3nstorage/xsp-fs/link-node.d.ts +1 -0
- package/build/lib-client/3nstorage/xsp-fs/link-node.js +7 -2
- package/build/lib-client/3nstorage/xsp-fs/node-in-fs.d.ts +30 -29
- package/build/lib-client/3nstorage/xsp-fs/node-in-fs.js +232 -127
- package/build/lib-client/3nstorage/xsp-fs/node-persistence.d.ts +1 -1
- package/build/lib-client/3nstorage/xsp-fs/node-persistence.js +17 -18
- package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v1.js +3 -3
- package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v2.js +53 -53
- package/build/lib-client/3nweb-signup.js +4 -4
- package/build/lib-client/asmail/recipient.js +15 -15
- package/build/lib-client/asmail/sender.js +22 -22
- package/build/lib-client/asmail/service-config.js +3 -3
- package/build/lib-client/cryptor/cryptor-in-worker.js +18 -16
- package/build/lib-client/cryptor/cryptor-wasm.js +1 -1
- package/build/lib-client/cryptor/cryptor.js +4 -2
- package/build/lib-client/cryptor/cryptor.wasm +0 -0
- package/build/lib-client/cryptor/in-proc-js.js +1 -1
- package/build/lib-client/cryptor/in-proc-wasm.js +6 -6
- package/build/lib-client/cryptor/worker-js.js +2 -2
- package/build/lib-client/cryptor/worker-wasm.js +2 -2
- package/build/lib-client/files-select.js +1 -1
- package/build/lib-client/files.d.ts +1 -1
- package/build/lib-client/files.js +71 -6
- package/build/lib-client/fs-collection.js +1 -1
- package/build/lib-client/fs-sync-utils.d.ts +5 -0
- package/build/lib-client/fs-sync-utils.js +61 -0
- package/build/lib-client/fs-view.d.ts +14 -0
- package/build/lib-client/fs-view.js +33 -0
- package/build/lib-client/key-derivation.js +1 -1
- package/build/lib-client/local-files/dev-file-sink.js +9 -9
- package/build/lib-client/local-files/dev-file-src.js +2 -2
- package/build/lib-client/local-files/device-fs.d.ts +1 -1
- package/build/lib-client/local-files/device-fs.js +56 -54
- package/build/lib-client/logging/log-to-file.d.ts +1 -1
- package/build/lib-client/logging/log-to-file.js +7 -7
- package/build/lib-client/mailer-id/login.js +7 -7
- package/build/lib-client/mailer-id/provisioner.js +12 -12
- package/build/lib-client/objs-on-disk/file-writing-proc.js +3 -3
- package/build/lib-client/objs-on-disk/obj-folders.js +31 -31
- package/build/lib-client/objs-on-disk/obj-on-disk.d.ts +13 -2
- package/build/lib-client/objs-on-disk/obj-on-disk.js +24 -9
- package/build/lib-client/request-utils.d.ts +1 -0
- package/build/lib-client/request-utils.js +13 -13
- package/build/lib-client/server-events.d.ts +3 -3
- package/build/lib-client/server-events.js +9 -8
- package/build/lib-client/service-locator.js +10 -10
- package/build/lib-client/user-with-mid-session.d.ts +2 -1
- package/build/lib-client/user-with-mid-session.js +14 -8
- package/build/lib-client/user-with-pkl-session.js +25 -25
- package/build/lib-client/ws-utils.js +2 -2
- package/build/lib-common/async-cryptor-wrap.js +4 -4
- package/build/lib-common/async-fs-node.d.ts +5 -3
- package/build/lib-common/async-fs-node.js +17 -17
- package/build/lib-common/byte-streaming/pipe.js +1 -1
- package/build/lib-common/byte-streaming/wrapping.js +13 -13
- package/build/lib-common/canonical-address.js +1 -1
- package/build/lib-common/exceptions/error.d.ts +1 -0
- package/build/lib-common/exceptions/error.js +7 -6
- package/build/lib-common/exceptions/file.d.ts +4 -2
- package/build/lib-common/exceptions/file.js +24 -54
- package/build/lib-common/ipc/generic-ipc.js +5 -4
- package/build/lib-common/ipc/ws-ipc.js +2 -2
- package/build/lib-common/mid-sigs-NaCl-Ed.js +14 -14
- package/build/lib-common/objs-on-disk/file-layout.d.ts +19 -0
- package/build/lib-common/objs-on-disk/file-layout.js +130 -12
- package/build/lib-common/objs-on-disk/obj-file.d.ts +13 -2
- package/build/lib-common/objs-on-disk/obj-file.js +96 -35
- package/build/lib-common/objs-on-disk/utils.d.ts +1 -0
- package/build/lib-common/objs-on-disk/utils.js +3 -3
- package/build/lib-common/objs-on-disk/v1-obj-file-format.js +14 -14
- package/build/lib-common/processes/labelled-exec-pools.d.ts +1 -1
- package/build/lib-common/processes/labelled-exec-pools.js +1 -1
- package/build/lib-common/processes/pressure.js +2 -2
- package/build/lib-common/processes/synced.js +1 -1
- package/build/lib-common/processes/timeout.js +2 -2
- package/build/lib-common/random-node.js +7 -7
- package/build/lib-common/service-api/3nstorage/owner.d.ts +101 -42
- package/build/lib-common/service-api/3nstorage/owner.js +83 -40
- package/build/lib-common/service-api/asmail/delivery.js +2 -2
- package/build/lib-common/service-api/asmail/retrieval.js +1 -1
- package/build/lib-common/timed-cache.d.ts +1 -0
- package/build/lib-common/timed-non-weak-cache.d.ts +1 -0
- package/build/lib-common/timed-non-weak-cache.js +11 -0
- package/build/lib-common/utils-for-observables.js +4 -4
- package/build/lib-common/weak-cache.d.ts +1 -0
- package/build/lib-common/weak-cache.js +12 -1
- package/build/lib-index.d.ts +2 -1
- package/build/lib-index.js +10 -7
- package/build/protos/asmail.proto.js +12955 -7496
- package/build/protos/file.proto.js +4867 -2744
- package/build/protos/fs.proto.js +9227 -3768
- package/package.json +7 -5
- package/protos/file.proto +91 -19
- package/protos/fs.proto +107 -8
- package/build/core/id-manager.d.ts +0 -46
|
@@ -13,9 +13,10 @@
|
|
|
13
13
|
See the GNU General Public License for more details.
|
|
14
14
|
|
|
15
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/>.
|
|
16
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
17
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.KeyRing = void 0;
|
|
19
|
+
exports.KeyRing = exports.KEY_USE = void 0;
|
|
19
20
|
const correspondent_keys_1 = require("./correspondent-keys");
|
|
20
21
|
const id_to_email_map_1 = require("./id-to-email-map");
|
|
21
22
|
const common_1 = require("./common");
|
|
@@ -39,11 +40,11 @@ class KeyRing {
|
|
|
39
40
|
this.pairIdToEmailMap = new id_to_email_map_1.IdToEmailMap();
|
|
40
41
|
this.storage = undefined;
|
|
41
42
|
this.needIntroKeyFor = (address) => {
|
|
42
|
-
address = canonical_address_1.toCanonicalAddress(address);
|
|
43
|
+
address = (0, canonical_address_1.toCanonicalAddress)(address);
|
|
43
44
|
return !this.corrKeys.has(address);
|
|
44
45
|
};
|
|
45
46
|
this.generateKeysToSend = async (address, introPKeyFromServer) => {
|
|
46
|
-
address = canonical_address_1.toCanonicalAddress(address);
|
|
47
|
+
address = (0, canonical_address_1.toCanonicalAddress)(address);
|
|
47
48
|
let ck = this.corrKeys.get(address);
|
|
48
49
|
if (!ck) {
|
|
49
50
|
if (!introPKeyFromServer) {
|
|
@@ -54,12 +55,12 @@ class KeyRing {
|
|
|
54
55
|
const { msgMasterKey, currentPair, msgCount } = await ck.getSendingPair(introPKeyFromServer);
|
|
55
56
|
// prepare message encryptor
|
|
56
57
|
const nextNonce = await random.bytes(xsp_files_1.NONCE_LENGTH);
|
|
57
|
-
const encryptor = async_cryptor_wrap_1.makeEncryptor(this.cryptor, msgMasterKey, nextNonce);
|
|
58
|
+
const encryptor = (0, async_cryptor_wrap_1.makeEncryptor)(this.cryptor, msgMasterKey, nextNonce);
|
|
58
59
|
msgMasterKey.fill(0);
|
|
59
60
|
return { encryptor, currentPair, msgCount };
|
|
60
61
|
};
|
|
61
62
|
this.nextCrypto = async (address) => {
|
|
62
|
-
address = canonical_address_1.toCanonicalAddress(address);
|
|
63
|
+
address = (0, canonical_address_1.toCanonicalAddress)(address);
|
|
63
64
|
let ck = this.corrKeys.get(address);
|
|
64
65
|
if (!ck) {
|
|
65
66
|
throw new Error(`No correspondent keys found for ${address}`);
|
|
@@ -91,11 +92,11 @@ class KeyRing {
|
|
|
91
92
|
if (pkey.k !== msgMeta.senderPKey) {
|
|
92
93
|
throw new Error(`Key certificates in the message are not for a key that encrypted this message.`);
|
|
93
94
|
}
|
|
94
|
-
decrInfo.correspondent = canonical_address_1.toCanonicalAddress(address);
|
|
95
|
+
decrInfo.correspondent = (0, canonical_address_1.toCanonicalAddress)(address);
|
|
95
96
|
}
|
|
96
97
|
// check that sender is the same as the trusted correspondent
|
|
97
98
|
const sender = openedMsg.sender;
|
|
98
|
-
if (!sender || !canonical_address_1.areAddressesEqual(sender, decrInfo.correspondent)) {
|
|
99
|
+
if (!sender || !(0, canonical_address_1.areAddressesEqual)(sender, decrInfo.correspondent)) {
|
|
99
100
|
throw new Error(`Mismatch between message sender field '${sender}', and address '${decrInfo.correspondent}', associated with decrypting key.`);
|
|
100
101
|
}
|
|
101
102
|
// update received msg counts and a time stamp
|
|
@@ -137,7 +138,7 @@ class KeyRing {
|
|
|
137
138
|
if (this.storage) {
|
|
138
139
|
throw new Error("Keyring has already been initialized.");
|
|
139
140
|
}
|
|
140
|
-
this.storage = keyring_storage_1.makeKeyringStorage(fs);
|
|
141
|
+
this.storage = (0, keyring_storage_1.makeKeyringStorage)(fs);
|
|
141
142
|
await this.storage.start();
|
|
142
143
|
const serialForm = await this.storage.load();
|
|
143
144
|
if (serialForm) {
|
|
@@ -175,11 +176,11 @@ class KeyRing {
|
|
|
175
176
|
return;
|
|
176
177
|
}
|
|
177
178
|
const h = await getMainObjHeader();
|
|
178
|
-
const msgKeyPackLen = common_1.msgKeyPackSizeFor(recipKey.pair.skey.alg);
|
|
179
|
+
const msgKeyPackLen = (0, common_1.msgKeyPackSizeFor)(recipKey.pair.skey.alg);
|
|
179
180
|
if (h.length < msgKeyPackLen) {
|
|
180
181
|
return;
|
|
181
182
|
}
|
|
182
|
-
const masterDecr = correspondent_keys_1.msgMasterDecryptor(this.cryptor, recipKey.pair.skey, { kid: '', k: senderPKey });
|
|
183
|
+
const masterDecr = (0, correspondent_keys_1.msgMasterDecryptor)(this.cryptor, recipKey.pair.skey, { kid: '', k: senderPKey });
|
|
183
184
|
try {
|
|
184
185
|
const mainObjFileKey = await masterDecr.open(h.subarray(0, msgKeyPackLen));
|
|
185
186
|
const info = {
|
|
@@ -232,7 +233,7 @@ class KeyRing {
|
|
|
232
233
|
const h = await getMainObjHeader();
|
|
233
234
|
for (const { correspondent, pair, role } of pairs) {
|
|
234
235
|
const masterKey = buffer_utils_1.base64.open(pair.msgMasterKey);
|
|
235
|
-
const masterDecr = async_cryptor_wrap_1.makeDecryptor(this.cryptor, masterKey);
|
|
236
|
+
const masterDecr = (0, async_cryptor_wrap_1.makeDecryptor)(this.cryptor, masterKey);
|
|
236
237
|
masterKey.fill(0);
|
|
237
238
|
try {
|
|
238
239
|
const msgKeyPackLen = msgKeyPackLenForPair(pair);
|
|
@@ -278,7 +279,7 @@ class KeyRing {
|
|
|
278
279
|
if (!rp.receivedMsgs) {
|
|
279
280
|
rp.receivedMsgs = { counts: [], lastTS };
|
|
280
281
|
}
|
|
281
|
-
common_2.addToNumberLineSegments(rp.receivedMsgs.counts, msgCount);
|
|
282
|
+
(0, common_2.addToNumberLineSegments)(rp.receivedMsgs.counts, msgCount);
|
|
282
283
|
rp.receivedMsgs.lastTS = lastTS;
|
|
283
284
|
this.saveChanges();
|
|
284
285
|
}
|
|
@@ -308,6 +309,6 @@ exports.KeyRing = KeyRing;
|
|
|
308
309
|
Object.freeze(KeyRing.prototype);
|
|
309
310
|
Object.freeze(KeyRing);
|
|
310
311
|
function msgKeyPackLenForPair(p) {
|
|
311
|
-
return common_1.msgKeyPackSizeFor(p.recipientKey.skey.alg);
|
|
312
|
+
return (0, common_1.msgKeyPackSizeFor)(p.recipientKey.skey.alg);
|
|
312
313
|
}
|
|
313
314
|
Object.freeze(exports);
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
See the GNU General Public License for more details.
|
|
14
14
|
|
|
15
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/>.
|
|
16
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
17
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
19
|
exports.makeKeyringStorage = void 0;
|
|
19
20
|
const synced_1 = require("../../../lib-common/processes/synced");
|
|
@@ -77,8 +77,8 @@ Object.freeze(OpenedMsg);
|
|
|
77
77
|
async function openMsg(msgId, mainObjId, mainObj, headerOfs, fKey, cryptor) {
|
|
78
78
|
try {
|
|
79
79
|
const header = await mainObj.readHeader();
|
|
80
|
-
const segReader = await xsp_files_1.makeSegmentsReader(fKey, xsp_files_1.idToHeaderNonce(mainObjId), 0, header.subarray(headerOfs), cryptor);
|
|
81
|
-
const byteSrc = await xsp_files_1.makeDecryptedByteSource(mainObj.segSrc, segReader);
|
|
80
|
+
const segReader = await (0, xsp_files_1.makeSegmentsReader)(fKey, (0, xsp_files_1.idToHeaderNonce)(mainObjId), 0, header.subarray(headerOfs), cryptor);
|
|
81
|
+
const byteSrc = await (0, xsp_files_1.makeDecryptedByteSource)(mainObj.segSrc, segReader);
|
|
82
82
|
const bytes = await byteSrc.read(undefined);
|
|
83
83
|
if (!bytes) {
|
|
84
84
|
throw new Error(`End of bytes is reached too soon`);
|
|
@@ -87,7 +87,7 @@ async function openMsg(msgId, mainObjId, mainObj, headerOfs, fKey, cryptor) {
|
|
|
87
87
|
return new OpenedMsg(msgId, jsonOfMain);
|
|
88
88
|
}
|
|
89
89
|
catch (err) {
|
|
90
|
-
throw error_1.errWithCause(err, `Cannot open main object of message ${msgId}`);
|
|
90
|
+
throw (0, error_1.errWithCause)(err, `Cannot open main object of message ${msgId}`);
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
exports.openMsg = openMsg;
|
|
@@ -97,7 +97,7 @@ class MsgPacker {
|
|
|
97
97
|
const packer = new MsgPacker(segSizeIn256bs);
|
|
98
98
|
packer.readyPack = p;
|
|
99
99
|
packer.mainObjId = p.meta.objIds[0];
|
|
100
|
-
Object.values(json_utils_1.copy(p.objs))
|
|
100
|
+
Object.values((0, json_utils_1.copy)(p.objs))
|
|
101
101
|
.forEach(obj => {
|
|
102
102
|
packer.allObjs.set(obj.id, obj);
|
|
103
103
|
turnKeyStingsToBytes(obj);
|
|
@@ -286,12 +286,12 @@ class MsgPacker {
|
|
|
286
286
|
const attachments = { nodes: {}, ctime: Date.now() };
|
|
287
287
|
// populate attachments json
|
|
288
288
|
const path = { start: 'attachments', path: [] };
|
|
289
|
-
if (att.container && !attachments_container_1.isContainerEmpty(att.container)) {
|
|
290
|
-
for (const f of attachments_container_1.iterFilesIn(att.container)) {
|
|
289
|
+
if (att.container && !(0, attachments_container_1.isContainerEmpty)(att.container)) {
|
|
290
|
+
for (const f of (0, attachments_container_1.iterFilesIn)(att.container)) {
|
|
291
291
|
const filePath = appendedPath(path, f.fileName);
|
|
292
292
|
this.addFileInto(attachments, f.fileName, filePath);
|
|
293
293
|
}
|
|
294
|
-
for (const f of attachments_container_1.iterFoldersIn(att.container)) {
|
|
294
|
+
for (const f of (0, attachments_container_1.iterFoldersIn)(att.container)) {
|
|
295
295
|
const fsPath = appendedPath(path, f.folderName);
|
|
296
296
|
await this.addFolderInto(attachments, f.folderName, f.folder, fsPath);
|
|
297
297
|
}
|
|
@@ -347,7 +347,7 @@ class MsgPacker {
|
|
|
347
347
|
}
|
|
348
348
|
const msgKeyPack = await msgKeyEnc.pack(obj.key);
|
|
349
349
|
const bytes = buffer_utils_1.utf8.pack(JSON.stringify(obj.json));
|
|
350
|
-
const segWriter = await xsp_files_1.makeSegmentsWriter(obj.key, xsp_files_1.idToHeaderNonce(obj.id), 0, { type: 'new', segSize: this.segSizeIn256bs, payloadFormat: 1 }, random.bytes, cryptor);
|
|
350
|
+
const segWriter = await (0, xsp_files_1.makeSegmentsWriter)(obj.key, (0, xsp_files_1.idToHeaderNonce)(obj.id), 0, { type: 'new', segSize: this.segSizeIn256bs, payloadFormat: 1 }, random.bytes, cryptor);
|
|
351
351
|
// make source that inserts message key pack into header
|
|
352
352
|
return makeMainObjSrc(msgKeyPack, bytes, segWriter);
|
|
353
353
|
}
|
|
@@ -410,24 +410,24 @@ class MsgPacker {
|
|
|
410
410
|
// make object segments writer
|
|
411
411
|
let segWriter;
|
|
412
412
|
if (header) {
|
|
413
|
-
segWriter = await xsp_files_1.makeSegmentsWriter(obj.key, xsp_files_1.idToHeaderNonce(obj.id), 0, { type: 'restart', header }, random.bytes, cryptor);
|
|
413
|
+
segWriter = await (0, xsp_files_1.makeSegmentsWriter)(obj.key, (0, xsp_files_1.idToHeaderNonce)(obj.id), 0, { type: 'restart', header }, random.bytes, cryptor);
|
|
414
414
|
}
|
|
415
415
|
else {
|
|
416
|
-
segWriter = await xsp_files_1.makeSegmentsWriter(obj.key, xsp_files_1.idToHeaderNonce(obj.id), 0, { type: 'new', segSize: this.segSizeIn256bs, payloadFormat: 1 }, random.bytes, cryptor);
|
|
416
|
+
segWriter = await (0, xsp_files_1.makeSegmentsWriter)(obj.key, (0, xsp_files_1.idToHeaderNonce)(obj.id), 0, { type: 'new', segSize: this.segSizeIn256bs, payloadFormat: 1 }, random.bytes, cryptor);
|
|
417
417
|
}
|
|
418
418
|
// make object source
|
|
419
419
|
let src;
|
|
420
420
|
if (obj.json) {
|
|
421
421
|
const bytes = buffer_utils_1.utf8.pack(JSON.stringify(obj.json));
|
|
422
|
-
src = await xsp_files_1.makeObjSourceFromArrays(bytes, segWriter);
|
|
422
|
+
src = await (0, xsp_files_1.makeObjSourceFromArrays)(bytes, segWriter);
|
|
423
423
|
}
|
|
424
424
|
else if (obj.file) {
|
|
425
425
|
const byteSrc = fileSrcToByteSrc(await this.getFileByteSrc(obj.file));
|
|
426
|
-
src = await xsp_files_1.makeEncryptingObjSource(byteSrc, segWriter);
|
|
426
|
+
src = await (0, xsp_files_1.makeEncryptingObjSource)(byteSrc, segWriter);
|
|
427
427
|
}
|
|
428
428
|
else if (obj.folder) {
|
|
429
|
-
const folderBytes = folder_node_serialization_1.serializeFolderInfo(obj.folder);
|
|
430
|
-
src = await xsp_files_1.makeObjSourceFromArrays(folderBytes, segWriter);
|
|
429
|
+
const folderBytes = (0, folder_node_serialization_1.serializeFolderInfo)(obj.folder);
|
|
430
|
+
src = await (0, xsp_files_1.makeObjSourceFromArrays)(folderBytes, segWriter);
|
|
431
431
|
}
|
|
432
432
|
else {
|
|
433
433
|
throw new Error(`Object ${objId} is broken`);
|
|
@@ -443,7 +443,7 @@ class MsgPacker {
|
|
|
443
443
|
meta.objIds = [];
|
|
444
444
|
const objs = {};
|
|
445
445
|
for (const objEntry of this.allObjs) {
|
|
446
|
-
const obj = json_utils_1.copy(objEntry[1]);
|
|
446
|
+
const obj = (0, json_utils_1.copy)(objEntry[1]);
|
|
447
447
|
turnKeysToB64(obj);
|
|
448
448
|
objs[objEntry[0]] = obj;
|
|
449
449
|
if (objEntry[0] !== this.mainObjId) {
|
|
@@ -460,7 +460,7 @@ exports.MsgPacker = MsgPacker;
|
|
|
460
460
|
Object.freeze(MsgPacker.prototype);
|
|
461
461
|
Object.freeze(MsgPacker);
|
|
462
462
|
async function makeMainObjSrc(msgKeyPack, content, segWriter) {
|
|
463
|
-
const src = await xsp_files_1.makeObjSourceFromArrays(content, segWriter);
|
|
463
|
+
const src = await (0, xsp_files_1.makeObjSourceFromArrays)(content, segWriter);
|
|
464
464
|
const wrap = {
|
|
465
465
|
version: src.version,
|
|
466
466
|
segSrc: src.segSrc,
|
|
@@ -51,7 +51,7 @@ class OwnSendingParams extends file_based_json_1.JsonFileProc {
|
|
|
51
51
|
}
|
|
52
52
|
p = {
|
|
53
53
|
address,
|
|
54
|
-
suggested: json_utils_1.copy(this.defaultParams)
|
|
54
|
+
suggested: (0, json_utils_1.copy)(this.defaultParams)
|
|
55
55
|
};
|
|
56
56
|
p.suggested.timestamp = Date.now();
|
|
57
57
|
this.params.set(p.address, p);
|
|
@@ -116,7 +116,7 @@ class OwnSendingParams extends file_based_json_1.JsonFileProc {
|
|
|
116
116
|
this.defaultParams = json.default;
|
|
117
117
|
}
|
|
118
118
|
async onFileEvent(ev) {
|
|
119
|
-
if (
|
|
119
|
+
if (ev.src === 'local') {
|
|
120
120
|
return;
|
|
121
121
|
}
|
|
122
122
|
if (ev.type === 'removed') {
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { user as mid } from '../../lib-common/mid-sigs-NaCl-Ed';
|
|
2
|
+
import { JsonKey } from '../../lib-common/jwkeys';
|
|
3
|
+
import { GenerateKey } from '../sign-in';
|
|
4
|
+
import { LogError, LogWarning } from '../../lib-client/logging/log-to-file';
|
|
5
|
+
import { NetClient } from '../../lib-client/request-utils';
|
|
6
|
+
import { ServiceLocator } from '../../lib-client/service-locator';
|
|
7
|
+
declare type WritableFS = web3n.files.WritableFS;
|
|
8
|
+
/**
|
|
9
|
+
* This function completes provisioning process, returning a promise, resolvable
|
|
10
|
+
* to either true, when all is done, or to false, when challenge reply is not
|
|
11
|
+
* accepted by the server.
|
|
12
|
+
*/
|
|
13
|
+
export interface CompleteProvisioning {
|
|
14
|
+
keyParams: any;
|
|
15
|
+
complete(defaultSKey: Uint8Array): Promise<boolean>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* This returns a promise, resolvable to mailerId signer.
|
|
19
|
+
*/
|
|
20
|
+
export declare type GetSigner = () => Promise<mid.MailerIdSigner>;
|
|
21
|
+
export declare type SetupManagerStorage = (fs: WritableFS, keysToSave?: JsonKey[]) => Promise<void>;
|
|
22
|
+
export declare class IdManager {
|
|
23
|
+
private readonly store;
|
|
24
|
+
private readonly makeNet;
|
|
25
|
+
private readonly midServiceFor;
|
|
26
|
+
private address;
|
|
27
|
+
private signer;
|
|
28
|
+
private provisioningProc;
|
|
29
|
+
private constructor();
|
|
30
|
+
static initWithoutStore(address: string, resolver: ServiceLocator, makeNet: () => NetClient, logError: LogError, logWarning: LogWarning): Promise<((midLoginKey: GenerateKey | Uint8Array) => Promise<{
|
|
31
|
+
idManager: IdManager;
|
|
32
|
+
setupManagerStorage: SetupManagerStorage;
|
|
33
|
+
} | undefined>) | undefined>;
|
|
34
|
+
static initFromCachedStore(address: string, fs: WritableFS, resolver: ServiceLocator, makeNet: () => NetClient, logError: LogError, logWarning: LogWarning): Promise<IdManager | undefined>;
|
|
35
|
+
private startProvisionWithoutSavedKey;
|
|
36
|
+
private provisionUsingSavedKey;
|
|
37
|
+
getId(): string;
|
|
38
|
+
getSigner: GetSigner;
|
|
39
|
+
isProvisionedAndValid(): boolean;
|
|
40
|
+
makeMailerIdCAP(): Service;
|
|
41
|
+
}
|
|
42
|
+
declare type Service = web3n.mailerid.Service;
|
|
43
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2015 - 2018, 2020 -
|
|
3
|
+
Copyright (C) 2015 - 2018, 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,24 +18,21 @@
|
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.IdManager = void 0;
|
|
20
20
|
const ecma_nacl_1 = require("ecma-nacl");
|
|
21
|
-
const provisioner_1 = require("
|
|
22
|
-
const jwkeys_1 = require("
|
|
23
|
-
const synced_1 = require("
|
|
24
|
-
const login_1 = require("
|
|
21
|
+
const provisioner_1 = require("../../lib-client/mailer-id/provisioner");
|
|
22
|
+
const jwkeys_1 = require("../../lib-common/jwkeys");
|
|
23
|
+
const synced_1 = require("../../lib-common/processes/synced");
|
|
24
|
+
const login_1 = require("../../lib-client/mailer-id/login");
|
|
25
|
+
const key_storage_1 = require("./key-storage");
|
|
25
26
|
const CERTIFICATE_DURATION_SECONDS = 16 * 60 * 60;
|
|
26
27
|
const ASSERTION_VALIDITY = 15 * 60;
|
|
27
28
|
const MIN_SECS_LEFT_ASSUMED_OK = 10 * 60;
|
|
28
|
-
const LOGIN_KEY_FILE_NAME = 'login-keys';
|
|
29
29
|
class IdManager {
|
|
30
|
-
constructor(makeNet, midServiceFor,
|
|
30
|
+
constructor(store, makeNet, midServiceFor, address) {
|
|
31
|
+
this.store = store;
|
|
31
32
|
this.makeNet = makeNet;
|
|
32
33
|
this.midServiceFor = midServiceFor;
|
|
33
|
-
this.logError = logError;
|
|
34
|
-
this.logWarning = logWarning;
|
|
35
34
|
this.address = address;
|
|
36
35
|
this.signer = undefined;
|
|
37
|
-
this.localFS = undefined;
|
|
38
|
-
this.syncedFS = undefined;
|
|
39
36
|
this.provisioningProc = new synced_1.SingleProc();
|
|
40
37
|
this.getSigner = async () => {
|
|
41
38
|
if (!this.address) {
|
|
@@ -46,114 +43,46 @@ class IdManager {
|
|
|
46
43
|
}
|
|
47
44
|
return this.signer;
|
|
48
45
|
};
|
|
49
|
-
if (localFS) {
|
|
50
|
-
this.localFS = localFS;
|
|
51
|
-
}
|
|
52
46
|
Object.seal(this);
|
|
53
47
|
}
|
|
54
|
-
static async initInOneStepWithoutStore(address, midLoginKey, resolver, makeNet, logError, logWarning) {
|
|
55
|
-
const stepTwo = await IdManager.initWithoutStore(address, resolver, makeNet, logError, logWarning);
|
|
56
|
-
if (!stepTwo) {
|
|
57
|
-
throw new Error(`MailerId server doesn't recognize identity ${address}`);
|
|
58
|
-
}
|
|
59
|
-
return stepTwo(midLoginKey);
|
|
60
|
-
}
|
|
61
48
|
static async initWithoutStore(address, resolver, makeNet, logError, logWarning) {
|
|
62
|
-
const
|
|
63
|
-
const
|
|
64
|
-
|
|
49
|
+
const { store, setupManagerStorage } = key_storage_1.IdKeysStorage.makeWithoutStorage(logError, logWarning);
|
|
50
|
+
const idManager = new IdManager(store, makeNet, resolver, address);
|
|
51
|
+
const provisioning = await idManager.startProvisionWithoutSavedKey(address);
|
|
52
|
+
if (!provisioning) {
|
|
65
53
|
return;
|
|
66
54
|
}
|
|
67
55
|
return async (midLoginKey) => {
|
|
68
56
|
const key = ((typeof midLoginKey === 'function') ?
|
|
69
|
-
await midLoginKey(
|
|
57
|
+
await midLoginKey(provisioning.keyParams) :
|
|
70
58
|
midLoginKey);
|
|
71
|
-
const isDone = await
|
|
59
|
+
const isDone = await provisioning.complete(key);
|
|
72
60
|
key.fill(0);
|
|
73
|
-
|
|
61
|
+
if (!isDone) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
idManager,
|
|
66
|
+
setupManagerStorage: (fs, keys) => setupManagerStorage(fs, (keys ? {
|
|
67
|
+
address: idManager.address,
|
|
68
|
+
keys
|
|
69
|
+
} : undefined))
|
|
70
|
+
};
|
|
74
71
|
};
|
|
75
72
|
}
|
|
76
|
-
static async
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
throw new Error(`Expected local storage is typed as ${localFS.type}`);
|
|
80
|
-
}
|
|
81
|
-
idMan.localFS = localFS;
|
|
73
|
+
static async initFromCachedStore(address, fs, resolver, makeNet, logError, logWarning) {
|
|
74
|
+
const store = key_storage_1.IdKeysStorage.makeWithStorage(fs, logError, logWarning);
|
|
75
|
+
const idManager = new IdManager(store, makeNet, resolver, address);
|
|
82
76
|
try {
|
|
83
|
-
await
|
|
77
|
+
await idManager.provisionUsingSavedKey();
|
|
78
|
+
return idManager;
|
|
84
79
|
}
|
|
85
80
|
catch (err) {
|
|
86
81
|
await logError(err, `Can't initialize id manager from local store`);
|
|
87
82
|
return;
|
|
88
83
|
}
|
|
89
|
-
return idMan;
|
|
90
|
-
}
|
|
91
|
-
async ensureLocalCacheOfKeys() {
|
|
92
|
-
if (!this.localFS || !this.syncedFS) {
|
|
93
|
-
throw new Error(`Id manager's storages are not set.`);
|
|
94
|
-
}
|
|
95
|
-
const keysCached = await this.localFS.checkFilePresence(LOGIN_KEY_FILE_NAME);
|
|
96
|
-
if (keysCached) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
try {
|
|
100
|
-
const bytes = await this.syncedFS.readBytes(LOGIN_KEY_FILE_NAME);
|
|
101
|
-
await this.localFS.writeBytes(LOGIN_KEY_FILE_NAME, bytes);
|
|
102
|
-
bytes.fill(0);
|
|
103
|
-
}
|
|
104
|
-
catch (err) {
|
|
105
|
-
await this.logError(err, `Fail to ensure local cache of MailerId login keys.`);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
async getSavedKey() {
|
|
109
|
-
if (!this.localFS) {
|
|
110
|
-
throw new Error(`Id manager's local storage is not set.`);
|
|
111
|
-
}
|
|
112
|
-
const json = await this.localFS.readJSONFile(LOGIN_KEY_FILE_NAME).catch(notFoundOrReThrow);
|
|
113
|
-
if (json) {
|
|
114
|
-
return json.keys[0];
|
|
115
|
-
}
|
|
116
|
-
if (this.syncedFS) {
|
|
117
|
-
const json = await this.syncedFS.readJSONFile(LOGIN_KEY_FILE_NAME).catch(notFoundOrReThrow);
|
|
118
|
-
if (json) {
|
|
119
|
-
await this.ensureLocalCacheOfKeys();
|
|
120
|
-
return json.keys[0];
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
await this.logWarning(`IdManager: there is no login MailerId login keys`);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
async setStorages(localFS, syncedFS, keysToSave) {
|
|
129
|
-
if (localFS) {
|
|
130
|
-
if (localFS.type !== 'local') {
|
|
131
|
-
throw new Error(`Expected local storage is typed as ${localFS.type}`);
|
|
132
|
-
}
|
|
133
|
-
this.localFS = localFS;
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
if (!this.localFS) {
|
|
137
|
-
throw new Error(`Local storage is not given`);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
if (syncedFS.type !== 'synced') {
|
|
141
|
-
throw new Error(`Expected synced storage is typed as ${syncedFS.type}`);
|
|
142
|
-
}
|
|
143
|
-
this.syncedFS = syncedFS;
|
|
144
|
-
if (keysToSave) {
|
|
145
|
-
const json = {
|
|
146
|
-
address: this.address,
|
|
147
|
-
keys: keysToSave
|
|
148
|
-
};
|
|
149
|
-
await this.localFS.writeJSONFile(LOGIN_KEY_FILE_NAME, json);
|
|
150
|
-
await this.syncedFS.writeJSONFile(LOGIN_KEY_FILE_NAME, json);
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
await this.ensureLocalCacheOfKeys();
|
|
154
|
-
}
|
|
155
84
|
}
|
|
156
|
-
async
|
|
85
|
+
async startProvisionWithoutSavedKey(address) {
|
|
157
86
|
const midUrl = await this.midServiceFor(address);
|
|
158
87
|
const provisioner = new provisioner_1.MailerIdProvisioner(address, midUrl, this.makeNet());
|
|
159
88
|
try {
|
|
@@ -199,11 +128,11 @@ class IdManager {
|
|
|
199
128
|
proc = this.provisioningProc.start(async () => {
|
|
200
129
|
const midUrl = await this.midServiceFor(this.address);
|
|
201
130
|
const provisioner = new provisioner_1.MailerIdProvisioner(this.address, midUrl, this.makeNet());
|
|
202
|
-
const key = await this.getSavedKey();
|
|
131
|
+
const key = await this.store.getSavedKey();
|
|
203
132
|
if (!key) {
|
|
204
133
|
throw new Error(`No saved MailerId login key can be found`);
|
|
205
134
|
}
|
|
206
|
-
const skey = jwkeys_1.keyFromJson(key, jwkeys_1.use.MID_PKLOGIN, ecma_nacl_1.box.JWK_ALG_NAME, ecma_nacl_1.box.KEY_LENGTH);
|
|
135
|
+
const skey = (0, jwkeys_1.keyFromJson)(key, jwkeys_1.use.MID_PKLOGIN, ecma_nacl_1.box.JWK_ALG_NAME, ecma_nacl_1.box.KEY_LENGTH);
|
|
207
136
|
const provisioning = await provisioner.provisionSigner(skey.kid);
|
|
208
137
|
this.signer = await provisioning.complete(() => {
|
|
209
138
|
const dhshared = ecma_nacl_1.box.calc_dhshared_key(provisioning.serverPKey, skey.k);
|
|
@@ -242,21 +171,14 @@ class IdManager {
|
|
|
242
171
|
}
|
|
243
172
|
}
|
|
244
173
|
exports.IdManager = IdManager;
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
* exception, and re-throws all other exceptions/errors.
|
|
248
|
-
*/
|
|
249
|
-
function notFoundOrReThrow(exc) {
|
|
250
|
-
if (!exc.notFound) {
|
|
251
|
-
throw exc;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
174
|
+
Object.freeze(IdManager.prototype);
|
|
175
|
+
Object.freeze(IdManager);
|
|
254
176
|
async function doMidLogin(loginUrl, userId, net, signer) {
|
|
255
|
-
const { sessionId, redirect } = await login_1.startMidSession(userId, net, loginUrl);
|
|
177
|
+
const { sessionId, redirect } = await (0, login_1.startMidSession)(userId, net, loginUrl);
|
|
256
178
|
if (!sessionId) {
|
|
257
179
|
throw Error(`Unexpected redirect of MailerId login from ${loginUrl} to ${redirect}`);
|
|
258
180
|
}
|
|
259
|
-
await login_1.authenticateMidSession(sessionId, signer, net, loginUrl);
|
|
181
|
+
await (0, login_1.authenticateMidSession)(sessionId, signer, net, loginUrl);
|
|
260
182
|
return sessionId;
|
|
261
183
|
}
|
|
262
184
|
Object.freeze(exports);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { LogError, LogWarning } from "../../lib-client/logging/log-to-file";
|
|
2
|
+
import { JsonKey } from "../../lib-common/jwkeys";
|
|
3
|
+
declare type WritableFS = web3n.files.WritableFS;
|
|
4
|
+
export interface LoginKeysJSON {
|
|
5
|
+
address: string;
|
|
6
|
+
keys: JsonKey[];
|
|
7
|
+
}
|
|
8
|
+
export declare class IdKeysStorage {
|
|
9
|
+
private readonly logError;
|
|
10
|
+
private readonly logWarning;
|
|
11
|
+
private fs;
|
|
12
|
+
private constructor();
|
|
13
|
+
static makeWithStorage(fs: WritableFS, logError: LogError, logWarning: LogWarning): IdKeysStorage;
|
|
14
|
+
static makeWithoutStorage(logError: LogError, logWarning: LogWarning): {
|
|
15
|
+
store: IdKeysStorage;
|
|
16
|
+
setupManagerStorage: (fs: WritableFS, keysToSave?: LoginKeysJSON) => Promise<void>;
|
|
17
|
+
};
|
|
18
|
+
getSavedKey(): Promise<JsonKey | undefined>;
|
|
19
|
+
private setStorageFS;
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,96 @@
|
|
|
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.IdKeysStorage = void 0;
|
|
20
|
+
const assert_1 = require("../../lib-common/assert");
|
|
21
|
+
const error_1 = require("../../lib-common/exceptions/error");
|
|
22
|
+
const LOGIN_KEY_FILE_NAME = 'login-keys';
|
|
23
|
+
class IdKeysStorage {
|
|
24
|
+
constructor(logError, logWarning, fs) {
|
|
25
|
+
this.logError = logError;
|
|
26
|
+
this.logWarning = logWarning;
|
|
27
|
+
this.fs = undefined;
|
|
28
|
+
if (fs) {
|
|
29
|
+
(0, assert_1.assert)(fs.type === 'synced');
|
|
30
|
+
this.fs = fs;
|
|
31
|
+
}
|
|
32
|
+
Object.seal(this);
|
|
33
|
+
}
|
|
34
|
+
static makeWithStorage(fs, logError, logWarning) {
|
|
35
|
+
return new IdKeysStorage(logError, logWarning, fs);
|
|
36
|
+
}
|
|
37
|
+
static makeWithoutStorage(logError, logWarning) {
|
|
38
|
+
const store = new IdKeysStorage(logError, logWarning);
|
|
39
|
+
return {
|
|
40
|
+
store,
|
|
41
|
+
setupManagerStorage: (fs, keys) => store.setStorageFS(fs, keys)
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
async getSavedKey() {
|
|
45
|
+
var _a, _b;
|
|
46
|
+
if (!((_b = (_a = this.fs) === null || _a === void 0 ? void 0 : _a.v) === null || _b === void 0 ? void 0 : _b.sync)) {
|
|
47
|
+
throw new Error(`Id manager's storages are not set.`);
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
const json = await this.fs.readJSONFile(LOGIN_KEY_FILE_NAME);
|
|
51
|
+
return json.keys[0];
|
|
52
|
+
}
|
|
53
|
+
catch (exc) {
|
|
54
|
+
if (!exc.notFound) {
|
|
55
|
+
throw exc;
|
|
56
|
+
}
|
|
57
|
+
await this.fs.v.sync.updateStatusInfo('');
|
|
58
|
+
await this.fs.v.sync.adoptRemote('');
|
|
59
|
+
if (await this.fs.checkFilePresence(LOGIN_KEY_FILE_NAME)) {
|
|
60
|
+
return this.getSavedKey();
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
await this.logWarning(`IdManager: no saved login MailerId keys`);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async setStorageFS(fs, keysToSave) {
|
|
69
|
+
(0, assert_1.assert)(!this.fs);
|
|
70
|
+
(0, assert_1.assert)(fs.type === 'synced');
|
|
71
|
+
this.fs = fs;
|
|
72
|
+
if (keysToSave) {
|
|
73
|
+
await this.fs.writeJSONFile(LOGIN_KEY_FILE_NAME, keysToSave);
|
|
74
|
+
// XXX must add work with not-online condition
|
|
75
|
+
await this.fs.v.sync.upload(LOGIN_KEY_FILE_NAME);
|
|
76
|
+
await this.fs.v.sync.upload('');
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
try {
|
|
80
|
+
await this.fs.readJSONFile(LOGIN_KEY_FILE_NAME);
|
|
81
|
+
}
|
|
82
|
+
catch (exc) {
|
|
83
|
+
throw (0, error_1.errWithCause)(exc, `Fail expection read of login MailerId keys from the storage`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.IdKeysStorage = IdKeysStorage;
|
|
89
|
+
Object.freeze(IdKeysStorage.prototype);
|
|
90
|
+
Object.freeze(IdKeysStorage);
|
|
91
|
+
function notFoundOrReThrow(exc) {
|
|
92
|
+
if (!exc.notFound) {
|
|
93
|
+
throw exc;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
Object.freeze(exports);
|
package/build/core/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export interface CoreConf {
|
|
|
8
8
|
dataDir: string;
|
|
9
9
|
signUpUrl: string;
|
|
10
10
|
}
|
|
11
|
+
export declare type MakeNet = () => NetClient;
|
|
11
12
|
export declare class Core {
|
|
12
13
|
private readonly makeNet;
|
|
13
14
|
private readonly makeResolver;
|
|
@@ -21,7 +22,7 @@ export declare class Core {
|
|
|
21
22
|
private isInitialized;
|
|
22
23
|
private closingProc;
|
|
23
24
|
private constructor();
|
|
24
|
-
static make(conf: CoreConf, makeNet:
|
|
25
|
+
static make(conf: CoreConf, makeNet: MakeNet, makeResolver: ServiceLocatorMaker, makeCryptor: makeCryptor): Core;
|
|
25
26
|
start(): {
|
|
26
27
|
capsForStartup: web3n.startup.W3N;
|
|
27
28
|
coreInit: Promise<string>;
|