core-3nweb-client-lib 0.49.3 → 0.49.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.
|
@@ -154,6 +154,11 @@ class Delivery {
|
|
|
154
154
|
}
|
|
155
155
|
const attachments = common_1.Attachments.fromMsg(msgToSend);
|
|
156
156
|
const localMeta = opts === null || opts === void 0 ? void 0 : opts.localMeta;
|
|
157
|
+
// DEBUG log
|
|
158
|
+
console.log(`\n adding message ${msgToSend.attachments ? `with attachments: ${JSON.stringify({
|
|
159
|
+
files: msgToSend.attachments.files ? Object.keys(msgToSend.attachments.files).length : 0,
|
|
160
|
+
folders: msgToSend.attachments.folders ? Object.keys(msgToSend.attachments.folders).length : 0
|
|
161
|
+
})}` : `without attachments in outgoing msg object.`}`);
|
|
157
162
|
// save msg, in case delivery should be restarted
|
|
158
163
|
const msgFS = await this.makeFSForNewMsg(id);
|
|
159
164
|
const msg = await msg_1.Msg.forNew(id, msgFS, msgToSend, sender, recipients, this.r, attachments, localMeta, opts === null || opts === void 0 ? void 0 : opts.retryRecipient);
|
|
@@ -65,7 +65,6 @@ class Msg {
|
|
|
65
65
|
this.msgFS = msgFS;
|
|
66
66
|
this.sendingProc = new synced_1.SingleProc();
|
|
67
67
|
this.completionPromise = undefined;
|
|
68
|
-
// private readonly progressSavingProc = new SingleProc();
|
|
69
68
|
this.cancelled = false;
|
|
70
69
|
this.sender = undefined;
|
|
71
70
|
this.recipients = undefined;
|
|
@@ -128,7 +127,11 @@ class Msg {
|
|
|
128
127
|
await this.msgFS.writeJSONFile(MAIN_OBJ_FILE_NAME, main, { create: true, exclusive: true });
|
|
129
128
|
await this.msgFS.writeJSONFile(PROGRESS_INFO_FILE_NAME, this.progress, { create: true, exclusive: true });
|
|
130
129
|
if (this.attachments) {
|
|
131
|
-
|
|
130
|
+
console.log(`Linking attachments ...`);
|
|
131
|
+
await this.attachments.linkIn(this.msgFS)
|
|
132
|
+
.then(
|
|
133
|
+
// DEBUG log
|
|
134
|
+
() => console.log(` .... msg attachments linked while delivery`), err => console.error(`linking attachments error:`, err));
|
|
132
135
|
}
|
|
133
136
|
}
|
|
134
137
|
notifyOfChangesInProgress(saveProgress, saveWIPs) {
|
|
@@ -189,6 +192,8 @@ class Msg {
|
|
|
189
192
|
msg.setSection('Cc', this.msgToSend.carbonCopy);
|
|
190
193
|
msg.setSection('To', this.msgToSend.recipients);
|
|
191
194
|
if (this.attachments) {
|
|
195
|
+
// DEBUG log
|
|
196
|
+
console.log(`setting attachment on messages packer`);
|
|
192
197
|
await msg.setAttachments(this.attachments);
|
|
193
198
|
}
|
|
194
199
|
return msg;
|
|
@@ -164,6 +164,8 @@ class WIP {
|
|
|
164
164
|
async getRecipientKeyAndEncrypt() {
|
|
165
165
|
const recipient = this.sender.recipient;
|
|
166
166
|
const introPKeyFromServer = await this.getIntroKeyIfRecipientIsUnknown(recipient);
|
|
167
|
+
// DEBUG log
|
|
168
|
+
console.log(`\n wip.getRecipientKeyAndEncrypt()`);
|
|
167
169
|
this.packer = await this.msg.msgPacker();
|
|
168
170
|
// get crypto parts for encrypting this message
|
|
169
171
|
const { currentPair, encryptor, msgCount } = await this.msg.r.correspondents.generateKeysToSend(recipient, introPKeyFromServer);
|
|
@@ -191,7 +193,7 @@ class WIP {
|
|
|
191
193
|
this.packer.setNextSendingParams(nextSendingParams);
|
|
192
194
|
}
|
|
193
195
|
// pack the message
|
|
194
|
-
this.state.pack =
|
|
196
|
+
this.state.pack = this.packer.pack();
|
|
195
197
|
// initialize uploads info
|
|
196
198
|
this.state.objUploads = new Array(this.state.pack.meta.objIds.length);
|
|
197
199
|
this.state.objUploads.fill(null);
|
|
@@ -4,6 +4,7 @@ import { FolderInJSON } from '../../../lib-client/xsp-fs/common';
|
|
|
4
4
|
import { MsgEnvelope, SuggestedNextKeyPair, SendingParams } from './common';
|
|
5
5
|
import { Encryptor } from '../../../lib-common/async-cryptor-wrap';
|
|
6
6
|
import { AsyncRNG } from '../../../lib-common/rng-def';
|
|
7
|
+
import type { Attachments } from '../delivery/common';
|
|
7
8
|
type FS = web3n.files.FS;
|
|
8
9
|
type AttachmentsContainer = web3n.asmail.AttachmentsContainer;
|
|
9
10
|
type PKeyCertChain = web3n.keys.PKeyCertChain;
|
|
@@ -119,16 +120,13 @@ export declare class MsgPacker {
|
|
|
119
120
|
setNewKeyInfo(recipientKid: string, senderPKey: string, pkeyCerts: PKeyCertChain, msgCount: number): void;
|
|
120
121
|
setNextCrypto(pair: SuggestedNextKeyPair): void;
|
|
121
122
|
setNextSendingParams(params: SendingParams): void;
|
|
122
|
-
setAttachments(
|
|
123
|
-
fs: FS | undefined;
|
|
124
|
-
container: AttachmentsContainer | undefined;
|
|
125
|
-
}): Promise<void>;
|
|
123
|
+
setAttachments({ fs, container }: Attachments): Promise<void>;
|
|
126
124
|
private throwupOnMissingParts;
|
|
127
125
|
getSrcForMainObj(msgKeyEnc: Encryptor, cryptor: AsyncSBoxCryptor): Promise<ObjSource>;
|
|
128
126
|
private getFileByteSrc;
|
|
129
127
|
getNewSrcForObj(objId: string, cryptor: AsyncSBoxCryptor): Promise<ObjSource>;
|
|
130
128
|
getRestartedSrcForObj(objId: string, header: Uint8Array, offset: number, cryptor: AsyncSBoxCryptor): Promise<ObjSource>;
|
|
131
129
|
private getSrcForNonMainObj;
|
|
132
|
-
pack():
|
|
130
|
+
pack(): PackJSON;
|
|
133
131
|
}
|
|
134
132
|
export {};
|
|
@@ -238,9 +238,7 @@ class MsgPacker {
|
|
|
238
238
|
if (this.meta) {
|
|
239
239
|
throw new Error("Message metadata has already been set.");
|
|
240
240
|
}
|
|
241
|
-
this.meta = {
|
|
242
|
-
pid: pid,
|
|
243
|
-
};
|
|
241
|
+
this.meta = { pid };
|
|
244
242
|
this.main['Flow Params'].msgCount = msgCount;
|
|
245
243
|
Object.freeze(this.meta);
|
|
246
244
|
}
|
|
@@ -283,7 +281,7 @@ class MsgPacker {
|
|
|
283
281
|
setNextSendingParams(params) {
|
|
284
282
|
this.main['Flow Params'].nextSendingParams = params;
|
|
285
283
|
}
|
|
286
|
-
async setAttachments(
|
|
284
|
+
async setAttachments({ fs, container }) {
|
|
287
285
|
this.throwIfAlreadyPacked();
|
|
288
286
|
if (this.hasAttachments) {
|
|
289
287
|
throw new Error(`Attachments are already set.`);
|
|
@@ -292,29 +290,29 @@ class MsgPacker {
|
|
|
292
290
|
const attachments = { nodes: {}, ctime: Date.now() };
|
|
293
291
|
// populate attachments json
|
|
294
292
|
const path = { start: 'attachments', path: [] };
|
|
295
|
-
if (
|
|
296
|
-
for (const f of (0, attachments_container_1.iterFilesIn)(
|
|
293
|
+
if (container && !(0, attachments_container_1.isContainerEmpty)(container)) {
|
|
294
|
+
for (const f of (0, attachments_container_1.iterFilesIn)(container)) {
|
|
297
295
|
const filePath = appendedPath(path, f.fileName);
|
|
298
|
-
this.addFileInto(attachments, f.fileName, filePath);
|
|
296
|
+
await this.addFileInto(attachments, f.fileName, filePath);
|
|
299
297
|
}
|
|
300
|
-
for (const f of (0, attachments_container_1.iterFoldersIn)(
|
|
298
|
+
for (const f of (0, attachments_container_1.iterFoldersIn)(container)) {
|
|
301
299
|
const fsPath = appendedPath(path, f.folderName);
|
|
302
300
|
await this.addFolderInto(attachments, f.folderName, f.folder, fsPath);
|
|
303
301
|
}
|
|
304
|
-
this.attachmentsCont =
|
|
302
|
+
this.attachmentsCont = container;
|
|
305
303
|
this.hasAttachments = true;
|
|
306
304
|
}
|
|
307
|
-
else if (
|
|
308
|
-
const list = await
|
|
305
|
+
else if (fs) {
|
|
306
|
+
const list = await fs.listFolder('.');
|
|
309
307
|
if (list.length > 0) {
|
|
310
308
|
for (const entry of list) {
|
|
311
309
|
const fName = entry.name;
|
|
312
310
|
const fPath = appendedPath(path, fName);
|
|
313
311
|
if (entry.isFile) {
|
|
314
|
-
this.addFileInto(attachments, fName, fPath);
|
|
312
|
+
await this.addFileInto(attachments, fName, fPath);
|
|
315
313
|
}
|
|
316
314
|
else if (entry.isFolder) {
|
|
317
|
-
const f = await
|
|
315
|
+
const f = await fs.readonlySubRoot(fName);
|
|
318
316
|
await this.addFolderInto(attachments, fName, f, fPath);
|
|
319
317
|
}
|
|
320
318
|
else {
|
|
@@ -322,7 +320,7 @@ class MsgPacker {
|
|
|
322
320
|
continue;
|
|
323
321
|
}
|
|
324
322
|
}
|
|
325
|
-
this.attachmentsFS =
|
|
323
|
+
this.attachmentsFS = fs;
|
|
326
324
|
this.hasAttachments = true;
|
|
327
325
|
}
|
|
328
326
|
}
|
|
@@ -333,6 +331,8 @@ class MsgPacker {
|
|
|
333
331
|
if (this.hasAttachments) {
|
|
334
332
|
this.main['Attachments'] = attachments;
|
|
335
333
|
}
|
|
334
|
+
// DEBUG log
|
|
335
|
+
console.log(` message packer allObjs has ${this.allObjs.size} items`);
|
|
336
336
|
}
|
|
337
337
|
throwupOnMissingParts() {
|
|
338
338
|
if (!this.meta) {
|
|
@@ -341,8 +341,7 @@ class MsgPacker {
|
|
|
341
341
|
if (!this.wasBodySet) {
|
|
342
342
|
throw new Error("Message Body is not set.");
|
|
343
343
|
}
|
|
344
|
-
if (this.meta.senderPKey &&
|
|
345
|
-
!this.main['Flow Params'].introCerts) {
|
|
344
|
+
if (this.meta.senderPKey && !this.main['Flow Params'].introCerts) {
|
|
346
345
|
throw new Error("Sender's key certification is missing.");
|
|
347
346
|
}
|
|
348
347
|
}
|
|
@@ -365,16 +364,14 @@ class MsgPacker {
|
|
|
365
364
|
if (this.attachmentsCont) {
|
|
366
365
|
const fName = path.path[0];
|
|
367
366
|
if (path.path.length === 1) {
|
|
368
|
-
const file = (this.attachmentsCont.files ?
|
|
369
|
-
this.attachmentsCont.files[fName] : undefined);
|
|
367
|
+
const file = (this.attachmentsCont.files ? this.attachmentsCont.files[fName] : undefined);
|
|
370
368
|
if (!file) {
|
|
371
369
|
throw new Error(`File ${fName} is not found in attachments.`);
|
|
372
370
|
}
|
|
373
371
|
return file.getByteSource();
|
|
374
372
|
}
|
|
375
373
|
else {
|
|
376
|
-
const fs = (this.attachmentsCont.folders ?
|
|
377
|
-
this.attachmentsCont.folders[fName] : undefined);
|
|
374
|
+
const fs = (this.attachmentsCont.folders ? this.attachmentsCont.folders[fName] : undefined);
|
|
378
375
|
if (!fs) {
|
|
379
376
|
throw new Error(`Folder ${fName} is not found in attachments.`);
|
|
380
377
|
}
|
|
@@ -440,7 +437,7 @@ class MsgPacker {
|
|
|
440
437
|
}
|
|
441
438
|
return src;
|
|
442
439
|
}
|
|
443
|
-
|
|
440
|
+
pack() {
|
|
444
441
|
if (this.readyPack) {
|
|
445
442
|
return this.readyPack;
|
|
446
443
|
}
|