core-3nweb-client-lib 0.26.0 → 0.27.1

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.
Files changed (199) hide show
  1. package/build/api-defs/asmail.d.ts +1 -1
  2. package/build/api-defs/files.d.ts +278 -69
  3. package/build/core/app-files.js +7 -7
  4. package/build/core/asmail/config/common.js +2 -2
  5. package/build/core/asmail/config/index.js +2 -2
  6. package/build/core/asmail/config/published-intro-key.js +1 -1
  7. package/build/core/asmail/delivery/common.js +7 -7
  8. package/build/core/asmail/delivery/index.js +5 -5
  9. package/build/core/asmail/delivery/msg.js +4 -4
  10. package/build/core/asmail/delivery/per-recipient-wip.js +1 -1
  11. package/build/core/asmail/inbox/attachments/fs.js +5 -1
  12. package/build/core/asmail/inbox/cached-msgs.js +1 -1
  13. package/build/core/asmail/inbox/inbox-events.js +4 -4
  14. package/build/core/asmail/inbox/index.js +10 -10
  15. package/build/core/asmail/inbox/msg-downloader.js +1 -1
  16. package/build/core/asmail/inbox/msg-indexing.js +1 -1
  17. package/build/core/asmail/inbox/msg-on-disk.js +5 -5
  18. package/build/core/asmail/index.d.ts +3 -3
  19. package/build/core/asmail/index.js +13 -8
  20. package/build/core/asmail/key-verification.js +5 -5
  21. package/build/core/asmail/keyring/common.js +7 -6
  22. package/build/core/asmail/keyring/correspondent-keys.js +8 -7
  23. package/build/core/asmail/keyring/id-to-email-map.js +2 -1
  24. package/build/core/asmail/keyring/index.d.ts +7 -8
  25. package/build/core/asmail/keyring/index.js +15 -14
  26. package/build/core/asmail/keyring/keyring-storage.js +2 -1
  27. package/build/core/asmail/msg/opener.js +3 -3
  28. package/build/core/asmail/msg/packer.js +13 -13
  29. package/build/core/asmail/sending-params/own-params.js +2 -2
  30. package/build/core/asmail/sending-params/params-from-others.js +1 -1
  31. package/build/core/id-manager.js +6 -3
  32. package/build/core/index.d.ts +2 -1
  33. package/build/core/index.js +14 -14
  34. package/build/core/sign-in.js +5 -5
  35. package/build/core/sign-up.js +9 -9
  36. package/build/core/storage/common/json-saving.js +2 -2
  37. package/build/core/storage/common/obj-info-file.d.ts +12 -4
  38. package/build/core/storage/common/obj-info-file.js +66 -34
  39. package/build/core/storage/common/utils.d.ts +2 -0
  40. package/build/core/storage/common/utils.js +32 -0
  41. package/build/core/storage/index.d.ts +3 -17
  42. package/build/core/storage/index.js +56 -76
  43. package/build/core/storage/local/obj-files-gc.d.ts +2 -0
  44. package/build/core/storage/local/obj-files-gc.js +49 -37
  45. package/build/core/storage/local/obj-files.d.ts +4 -7
  46. package/build/core/storage/local/obj-files.js +7 -10
  47. package/build/core/storage/local/obj-status.d.ts +12 -6
  48. package/build/core/storage/local/obj-status.js +24 -9
  49. package/build/core/storage/local/storage.d.ts +9 -6
  50. package/build/core/storage/local/storage.js +29 -18
  51. package/build/core/storage/synced/downloader.js +1 -1
  52. package/build/core/storage/synced/obj-files-gc.d.ts +5 -1
  53. package/build/core/storage/synced/obj-files-gc.js +91 -37
  54. package/build/core/storage/synced/obj-files.d.ts +42 -36
  55. package/build/core/storage/synced/obj-files.js +178 -147
  56. package/build/core/storage/synced/obj-status.d.ts +87 -85
  57. package/build/core/storage/synced/obj-status.js +463 -259
  58. package/build/core/storage/synced/remote-events.d.ts +11 -12
  59. package/build/core/storage/synced/remote-events.js +73 -56
  60. package/build/core/storage/synced/storage.d.ts +18 -9
  61. package/build/core/storage/synced/storage.js +108 -48
  62. package/build/core/storage/synced/upload-header-file.d.ts +4 -0
  63. package/build/core/storage/synced/upload-header-file.js +64 -0
  64. package/build/core/storage/synced/upsyncer.d.ts +12 -7
  65. package/build/core/storage/synced/upsyncer.js +204 -280
  66. package/build/core/storage/system-folders/apps-data.d.ts +16 -0
  67. package/build/core/storage/system-folders/apps-data.js +110 -0
  68. package/build/core/storage/system-folders/index.d.ts +18 -0
  69. package/build/core/storage/system-folders/index.js +77 -0
  70. package/build/core-ipc/common-caps.js +3 -3
  71. package/build/core-ipc/generic.js +8 -8
  72. package/build/core-ipc/startup-caps.js +2 -2
  73. package/build/cryptors.js +6 -2
  74. package/build/ipc-via-protobuf/asmail-cap.js +58 -57
  75. package/build/ipc-via-protobuf/bytes.js +16 -17
  76. package/build/ipc-via-protobuf/connector-clients-side.d.ts +3 -0
  77. package/build/ipc-via-protobuf/connector-clients-side.js +61 -24
  78. package/build/ipc-via-protobuf/connector-services-side.js +10 -10
  79. package/build/ipc-via-protobuf/connector.js +4 -4
  80. package/build/ipc-via-protobuf/file.d.ts +48 -12
  81. package/build/ipc-via-protobuf/file.js +474 -126
  82. package/build/ipc-via-protobuf/fs.d.ts +8 -0
  83. package/build/ipc-via-protobuf/fs.js +577 -142
  84. package/build/ipc-via-protobuf/log-cap.js +2 -2
  85. package/build/ipc-via-protobuf/mailerid.js +3 -3
  86. package/build/ipc-via-protobuf/protobuf-msg.d.ts +1 -0
  87. package/build/ipc-via-protobuf/protobuf-msg.js +11 -7
  88. package/build/ipc-via-protobuf/startup-cap.js +21 -21
  89. package/build/ipc-via-protobuf/storage-cap.js +12 -12
  90. package/build/ipc.js +7 -2
  91. package/build/lib-client/3nstorage/exceptions.d.ts +3 -0
  92. package/build/lib-client/3nstorage/exceptions.js +13 -1
  93. package/build/lib-client/3nstorage/service.d.ts +15 -2
  94. package/build/lib-client/3nstorage/service.js +104 -38
  95. package/build/lib-client/3nstorage/util/file-based-json.d.ts +2 -1
  96. package/build/lib-client/3nstorage/util/file-based-json.js +1 -1
  97. package/build/lib-client/3nstorage/xsp-fs/attrs.js +17 -17
  98. package/build/lib-client/3nstorage/xsp-fs/common.d.ts +42 -18
  99. package/build/lib-client/3nstorage/xsp-fs/common.js +29 -19
  100. package/build/lib-client/3nstorage/xsp-fs/file-node.d.ts +1 -0
  101. package/build/lib-client/3nstorage/xsp-fs/file-node.js +17 -13
  102. package/build/lib-client/3nstorage/xsp-fs/file.d.ts +31 -6
  103. package/build/lib-client/3nstorage/xsp-fs/file.js +73 -25
  104. package/build/lib-client/3nstorage/xsp-fs/folder-node-serialization.js +4 -4
  105. package/build/lib-client/3nstorage/xsp-fs/folder-node.d.ts +24 -11
  106. package/build/lib-client/3nstorage/xsp-fs/folder-node.js +575 -179
  107. package/build/lib-client/3nstorage/xsp-fs/fs.d.ts +35 -4
  108. package/build/lib-client/3nstorage/xsp-fs/fs.js +231 -110
  109. package/build/lib-client/3nstorage/xsp-fs/link-node.d.ts +1 -0
  110. package/build/lib-client/3nstorage/xsp-fs/link-node.js +7 -2
  111. package/build/lib-client/3nstorage/xsp-fs/node-in-fs.d.ts +30 -24
  112. package/build/lib-client/3nstorage/xsp-fs/node-in-fs.js +229 -123
  113. package/build/lib-client/3nstorage/xsp-fs/node-persistence.d.ts +1 -1
  114. package/build/lib-client/3nstorage/xsp-fs/node-persistence.js +17 -18
  115. package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v1.js +3 -3
  116. package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v2.js +53 -53
  117. package/build/lib-client/3nweb-signup.js +4 -4
  118. package/build/lib-client/asmail/recipient.js +15 -15
  119. package/build/lib-client/asmail/sender.js +22 -22
  120. package/build/lib-client/asmail/service-config.js +3 -3
  121. package/build/lib-client/cryptor/cryptor-in-worker.js +18 -16
  122. package/build/lib-client/cryptor/cryptor-wasm.js +1 -1
  123. package/build/lib-client/cryptor/cryptor.js +4 -2
  124. package/build/lib-client/cryptor/cryptor.wasm +0 -0
  125. package/build/lib-client/cryptor/in-proc-js.js +1 -1
  126. package/build/lib-client/cryptor/in-proc-wasm.js +6 -6
  127. package/build/lib-client/cryptor/worker-js.js +2 -2
  128. package/build/lib-client/cryptor/worker-wasm.js +2 -2
  129. package/build/lib-client/files-select.js +1 -1
  130. package/build/lib-client/files.d.ts +1 -1
  131. package/build/lib-client/files.js +71 -6
  132. package/build/lib-client/fs-collection.js +1 -1
  133. package/build/lib-client/fs-sync-utils.d.ts +5 -0
  134. package/build/lib-client/fs-sync-utils.js +61 -0
  135. package/build/lib-client/fs-view.d.ts +14 -0
  136. package/build/lib-client/fs-view.js +33 -0
  137. package/build/lib-client/key-derivation.js +1 -1
  138. package/build/lib-client/local-files/dev-file-sink.js +9 -9
  139. package/build/lib-client/local-files/dev-file-src.js +2 -2
  140. package/build/lib-client/local-files/device-fs.d.ts +1 -1
  141. package/build/lib-client/local-files/device-fs.js +56 -54
  142. package/build/lib-client/logging/log-to-file.d.ts +1 -1
  143. package/build/lib-client/logging/log-to-file.js +7 -7
  144. package/build/lib-client/mailer-id/login.js +7 -7
  145. package/build/lib-client/mailer-id/provisioner.js +12 -12
  146. package/build/lib-client/objs-on-disk/file-writing-proc.js +3 -3
  147. package/build/lib-client/objs-on-disk/obj-folders.js +31 -31
  148. package/build/lib-client/objs-on-disk/obj-on-disk.d.ts +13 -2
  149. package/build/lib-client/objs-on-disk/obj-on-disk.js +24 -9
  150. package/build/lib-client/request-utils.d.ts +1 -0
  151. package/build/lib-client/request-utils.js +13 -13
  152. package/build/lib-client/server-events.d.ts +3 -3
  153. package/build/lib-client/server-events.js +9 -8
  154. package/build/lib-client/service-locator.js +10 -10
  155. package/build/lib-client/user-with-mid-session.js +7 -7
  156. package/build/lib-client/user-with-pkl-session.js +25 -25
  157. package/build/lib-client/ws-utils.js +2 -2
  158. package/build/lib-common/async-cryptor-wrap.js +4 -4
  159. package/build/lib-common/async-fs-node.d.ts +5 -3
  160. package/build/lib-common/async-fs-node.js +16 -16
  161. package/build/lib-common/byte-streaming/pipe.js +1 -1
  162. package/build/lib-common/byte-streaming/wrapping.js +13 -13
  163. package/build/lib-common/canonical-address.js +1 -1
  164. package/build/lib-common/exceptions/error.d.ts +1 -0
  165. package/build/lib-common/exceptions/error.js +7 -6
  166. package/build/lib-common/exceptions/file.js +4 -0
  167. package/build/lib-common/ipc/ws-ipc.js +2 -2
  168. package/build/lib-common/mid-sigs-NaCl-Ed.js +14 -14
  169. package/build/lib-common/objs-on-disk/file-layout.d.ts +19 -0
  170. package/build/lib-common/objs-on-disk/file-layout.js +130 -12
  171. package/build/lib-common/objs-on-disk/obj-file.d.ts +13 -2
  172. package/build/lib-common/objs-on-disk/obj-file.js +96 -35
  173. package/build/lib-common/objs-on-disk/utils.d.ts +1 -0
  174. package/build/lib-common/objs-on-disk/utils.js +3 -3
  175. package/build/lib-common/objs-on-disk/v1-obj-file-format.js +14 -14
  176. package/build/lib-common/processes/labelled-exec-pools.d.ts +1 -1
  177. package/build/lib-common/processes/labelled-exec-pools.js +1 -1
  178. package/build/lib-common/processes/pressure.js +2 -2
  179. package/build/lib-common/processes/synced.js +1 -1
  180. package/build/lib-common/processes/timeout.js +2 -2
  181. package/build/lib-common/random-node.js +7 -7
  182. package/build/lib-common/service-api/3nstorage/owner.d.ts +95 -39
  183. package/build/lib-common/service-api/3nstorage/owner.js +82 -40
  184. package/build/lib-common/service-api/asmail/delivery.js +2 -2
  185. package/build/lib-common/service-api/asmail/retrieval.js +1 -1
  186. package/build/lib-common/timed-cache.d.ts +1 -0
  187. package/build/lib-common/timed-non-weak-cache.d.ts +1 -0
  188. package/build/lib-common/timed-non-weak-cache.js +11 -0
  189. package/build/lib-common/utils-for-observables.js +4 -4
  190. package/build/lib-common/weak-cache.d.ts +1 -0
  191. package/build/lib-common/weak-cache.js +12 -1
  192. package/build/lib-index.d.ts +2 -1
  193. package/build/lib-index.js +10 -7
  194. package/build/protos/asmail.proto.js +12955 -7496
  195. package/build/protos/file.proto.js +4867 -2744
  196. package/build/protos/fs.proto.js +9227 -3768
  197. package/package.json +6 -5
  198. package/protos/file.proto +91 -19
  199. package/protos/fs.proto +107 -8
@@ -51,8 +51,8 @@ class Delivery {
51
51
  */
52
52
  this.queuedDelivery = [];
53
53
  this.allDeliveries = new rxjs_1.Subject();
54
- this.allDeliveries$ = this.allDeliveries.asObservable().pipe(operators_1.share());
55
- file_1.ensureCorrectFS(fs, 'local', true);
54
+ this.allDeliveries$ = this.allDeliveries.asObservable().pipe((0, operators_1.share)());
55
+ (0, file_1.ensureCorrectFS)(fs, 'local', true);
56
56
  this.r.notifyMsgProgress =
57
57
  (id, progress) => this.allDeliveries.next({ id, progress });
58
58
  Object.freeze(this.r);
@@ -114,18 +114,18 @@ class Delivery {
114
114
  }
115
115
  if (msg.isDone()) {
116
116
  if (observer.next) {
117
- observer.next(json_utils_1.copy(msg.progress));
117
+ observer.next((0, json_utils_1.copy)(msg.progress));
118
118
  }
119
119
  if (observer.complete) {
120
120
  observer.complete();
121
121
  }
122
122
  return () => { };
123
123
  }
124
- const subToProgress = msg.progress$.subscribe(utils_for_observables_1.toRxObserver(observer));
124
+ const subToProgress = msg.progress$.subscribe((0, utils_for_observables_1.toRxObserver)(observer));
125
125
  return () => { subToProgress.unsubscribe(); };
126
126
  }
127
127
  observeAllDeliveries(observer) {
128
- const subToProgress = this.allDeliveries$.subscribe(utils_for_observables_1.toRxObserver(observer));
128
+ const subToProgress = this.allDeliveries$.subscribe((0, utils_for_observables_1.toRxObserver)(observer));
129
129
  return () => subToProgress.unsubscribe();
130
130
  }
131
131
  async preFlight(recipient) {
@@ -37,7 +37,7 @@ function checkIfAllRecipientsDone(progress) {
37
37
  return true;
38
38
  }
39
39
  async function estimatedPackedSize(msgToSend, attachments) {
40
- let totalSize = common_1.estimatePackedSizeOf(buffer_utils_1.utf8.pack(JSON.stringify(msgToSend)).length);
40
+ let totalSize = (0, common_1.estimatePackedSizeOf)(buffer_utils_1.utf8.pack(JSON.stringify(msgToSend)).length);
41
41
  if (attachments) {
42
42
  totalSize += await attachments.estimatedPackedSize();
43
43
  }
@@ -127,8 +127,8 @@ class Msg {
127
127
  this.progress.allDone = true;
128
128
  saveProgress = true;
129
129
  }
130
- this.r.notifyMsgProgress(this.id, json_utils_1.copy(this.progress));
131
- this.progressPublisher.next(json_utils_1.copy(this.progress));
130
+ this.r.notifyMsgProgress(this.id, (0, json_utils_1.copy)(this.progress));
131
+ this.progressPublisher.next((0, json_utils_1.copy)(this.progress));
132
132
  if (saveProgress) {
133
133
  this.progressSavingProc.startOrChain(async () => {
134
134
  await this.msgFS.writeJSONFile(PROGRESS_INFO_FILE_NAME, this.progress, {});
@@ -198,7 +198,7 @@ class Msg {
198
198
  throw new Error(`Message delivery has already completed.`);
199
199
  }
200
200
  if (!this.completionPromise) {
201
- this.completionPromise = deferred_1.defer();
201
+ this.completionPromise = (0, deferred_1.defer)();
202
202
  }
203
203
  return this.completionPromise.promise;
204
204
  }
@@ -205,7 +205,7 @@ class WIP {
205
205
  return;
206
206
  }
207
207
  const certs = await this.sender.getRecipientsInitPubKey();
208
- return key_verification_1.checkAndExtractPKey(this.sender.net, this.msg.r.midResolver, recipient, certs).catch(err => {
208
+ return (0, key_verification_1.checkAndExtractPKey)(this.sender.net, this.msg.r.midResolver, recipient, certs).catch(err => {
209
209
  const exc = {
210
210
  runtimeException: true,
211
211
  type: 'asmail-delivery',
@@ -27,6 +27,7 @@ class AttachmentStore {
27
27
  this.type = 'asmail-msg';
28
28
  this.versioned = false;
29
29
  this.nodes = new common_1.NodesContainer();
30
+ this.connect = undefined;
30
31
  Object.seal(this);
31
32
  }
32
33
  getNodeEvents() {
@@ -43,10 +44,13 @@ class AttachmentStore {
43
44
  throw new Error(`Attachment's storage cannot link to ${type} storage.`);
44
45
  }
45
46
  }
47
+ status() {
48
+ throw new Error(`Attachment's storage is not versioned`);
49
+ }
46
50
  generateNewObjId() {
47
51
  throw new Error(`Attachment's storage is readonly.`);
48
52
  }
49
- getObj(objId) {
53
+ getObjSrc(objId) {
50
54
  if (typeof objId !== 'string') {
51
55
  throw new Error(`Attachment's storage uses only string objId's, while given parameter is: ${objId}`);
52
56
  }
@@ -26,7 +26,7 @@ class CachedMessages {
26
26
  this.folders = folders;
27
27
  this.downloader = downloader;
28
28
  this.syncProc = new synced_1.NamedProcs();
29
- this.msgFiles = timed_cache_1.makeTimedCache(60 * 1000);
29
+ this.msgFiles = (0, timed_cache_1.makeTimedCache)(60 * 1000);
30
30
  Object.freeze(this);
31
31
  }
32
32
  static async makeFor(path, downloader, logError) {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- Copyright (C) 2017, 2019 3NSoft Inc.
3
+ Copyright (C) 2017, 2019, 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
@@ -30,16 +30,16 @@ class InboxEvents {
30
30
  constructor(msgReceiver, getMsg, logError) {
31
31
  const serverEvents = new server_events_1.ServerEvents(() => msgReceiver.openEventSource(), SERVER_EVENTS_RESTART_WAIT_SECS);
32
32
  this.newMsg$ = serverEvents.observe(retrieval_1.msgRecievedCompletely.EVENT_NAME)
33
- .pipe(operators_1.mergeMap(ev => getMsg(ev.msgId)
33
+ .pipe((0, operators_1.mergeMap)(ev => getMsg(ev.msgId)
34
34
  .catch(async (err) => {
35
35
  // TODO should more error handling logic be added here?
36
36
  await logError(err, `Cannot get message ${ev.msgId}`);
37
- })), operators_1.filter(msg => !!msg), operators_1.share());
37
+ })), (0, operators_1.filter)(msg => !!msg), (0, operators_1.share)());
38
38
  Object.seal(this);
39
39
  }
40
40
  subscribe(event, observer) {
41
41
  if (event === 'message') {
42
- const subscription = this.newMsg$.subscribe(utils_for_observables_1.toRxObserver(observer));
42
+ const subscription = this.newMsg$.subscribe((0, utils_for_observables_1.toRxObserver)(observer));
43
43
  return () => subscription.unsubscribe();
44
44
  }
45
45
  else {
@@ -49,13 +49,13 @@ class InboxOnServer {
49
49
  this.index = index;
50
50
  this.logError = logError;
51
51
  this.procs = new synced_1.NamedProcs();
52
- this.recentlyOpenedMsgs = timed_cache_1.makeTimedCache(60 * 1000);
52
+ this.recentlyOpenedMsgs = (0, timed_cache_1.makeTimedCache)(60 * 1000);
53
53
  this.inboxEvents = new inbox_events_1.InboxEvents(this.msgReceiver, this.getMsg.bind(this), this.logError);
54
54
  Object.seal(this);
55
55
  }
56
56
  static async makeAndStart(cachePath, fs, r) {
57
57
  try {
58
- file_1.ensureCorrectFS(fs, 'synced', true);
58
+ (0, file_1.ensureCorrectFS)(fs, 'synced', true);
59
59
  const msgReceiver = new recipient_1.MailRecipient(r.address, r.getSigner, () => r.asmailResolver(r.address), r.makeNet());
60
60
  const downloader = new msg_downloader_1.MsgDownloader(msgReceiver);
61
61
  const cache = await cached_msgs_1.CachedMessages.makeFor(cachePath, downloader, r.logError);
@@ -63,7 +63,7 @@ class InboxOnServer {
63
63
  return new InboxOnServer(r.correspondents, msgReceiver, r.getStorages, r.cryptor, downloader, cache, index, r.logError);
64
64
  }
65
65
  catch (err) {
66
- throw error_1.errWithCause(err, 'Failed to initialize Inbox');
66
+ throw (0, error_1.errWithCause)(err, 'Failed to initialize Inbox');
67
67
  }
68
68
  }
69
69
  wrap() {
@@ -122,12 +122,12 @@ class InboxOnServer {
122
122
  mainObjSrc = await msgOnDisk.getMsgObj(mainObjId);
123
123
  }
124
124
  const fKey = buffer_utils_1.base64.open(mainObjFileKey);
125
- const openedMsg = await opener_1.openMsg(msgId, mainObjId, mainObjSrc, msgKeyPackLen, fKey, this.cryptor);
125
+ const openedMsg = await (0, opener_1.openMsg)(msgId, mainObjId, mainObjSrc, msgKeyPackLen, fKey, this.cryptor);
126
126
  fKey.fill(0);
127
127
  return openedMsg;
128
128
  };
129
129
  const checkMidKeyCerts = (certs) => {
130
- return key_verification_1.checkAndExtractPKeyWithAddress(this.msgReceiver.getNet(), this.r.midResolver, certs, Math.round(msgOnDisk.deliveryTS / 1000));
130
+ return (0, key_verification_1.checkAndExtractPKeyWithAddress)(this.msgReceiver.getNet(), this.r.midResolver, certs, Math.round(msgOnDisk.deliveryTS / 1000));
131
131
  };
132
132
  const decrOut = await this.r.msgDecryptor(meta.extMeta, getMainObjHeader, getOpenedMsg, checkMidKeyCerts);
133
133
  if (decrOut) {
@@ -183,7 +183,7 @@ class InboxOnServer {
183
183
  // if sender authenticated to server, check that it matches address,
184
184
  // recovered from message decryption
185
185
  if (meta.authSender &&
186
- !canonical_address_1.areAddressesEqual(meta.authSender, decrInfo.correspondent)) {
186
+ !(0, canonical_address_1.areAddressesEqual)(meta.authSender, decrInfo.correspondent)) {
187
187
  throw new Error(`Sender authenticated to server as ${meta.authSender}, while decrypting key is associated with ${decrInfo.correspondent}`);
188
188
  }
189
189
  }
@@ -252,7 +252,7 @@ class InboxOnServer {
252
252
  // this.index.remove(msgInfo),
253
253
  // this.removeMsgFromServerAndCache(msgId)
254
254
  // ]);
255
- throw recipient_1.makeMsgNotFoundException(msgId);
255
+ throw (0, recipient_1.makeMsgNotFoundException)(msgId);
256
256
  }
257
257
  else if (msgOnDisk.keyStatus === 'not-checked') {
258
258
  await this.startCachingAndAddKeyToIndex(msgId);
@@ -265,9 +265,9 @@ class InboxOnServer {
265
265
  const mainObj = await msgOnDisk.getMsgObj(mainObjId);
266
266
  const msgKey = await this.index.fKeyFor({ msgId, deliveryTS: meta.deliveryCompletion });
267
267
  if (!msgKey) {
268
- throw recipient_1.makeMsgNotFoundException(msgId);
268
+ throw (0, recipient_1.makeMsgNotFoundException)(msgId);
269
269
  }
270
- msg = await opener_1.openMsg(msgId, mainObjId, mainObj, msgKey.mainObjHeaderOfs, msgKey.msgKey, this.cryptor);
270
+ msg = await (0, opener_1.openMsg)(msgId, mainObjId, mainObj, msgKey.mainObjHeaderOfs, msgKey.msgKey, this.cryptor);
271
271
  msg.setMsgKeyRole(msgKey.msgKeyRole);
272
272
  return this.msgToUIForm(msg, msgOnDisk.deliveryTS, msgOnDisk);
273
273
  });
@@ -297,7 +297,7 @@ class InboxOnServer {
297
297
  }
298
298
  const attachments = msg.attachmentsJSON;
299
299
  if (attachments) {
300
- m.attachments = fs_1.fsForAttachments(msgOnDisk, attachments, this.storages, this.cryptor);
300
+ m.attachments = (0, fs_1.fsForAttachments)(msgOnDisk, attachments, this.storages, this.cryptor);
301
301
  }
302
302
  return m;
303
303
  }
@@ -76,7 +76,7 @@ class MsgDownloader {
76
76
  chunks.push(chunk);
77
77
  ofs += chunk.length;
78
78
  }
79
- return buffer_utils_1.joinByteArrs(chunks);
79
+ return (0, buffer_utils_1.joinByteArrs)(chunks);
80
80
  }
81
81
  });
82
82
  }
@@ -97,7 +97,7 @@ class MsgIndex {
97
97
  constructor(files) {
98
98
  this.files = files;
99
99
  this.latest = undefined;
100
- this.cached = timed_cache_1.makeTimedCache(10 * 60 * 1000);
100
+ this.cached = (0, timed_cache_1.makeTimedCache)(10 * 60 * 1000);
101
101
  this.fileTSs = undefined;
102
102
  this.fileProc = new synced_1.SingleProc();
103
103
  Object.seal(this);
@@ -63,7 +63,7 @@ class MsgOnDisk {
63
63
  return readJSON(this.msgFolderPath, META_FNAME, this.msgId);
64
64
  }
65
65
  objFilePath(objId) {
66
- return path_1.join(this.msgFolderPath, objId);
66
+ return (0, path_1.join)(this.msgFolderPath, objId);
67
67
  }
68
68
  async getObjFile(objId) {
69
69
  let file = this.objs.get(objId);
@@ -79,7 +79,7 @@ class MsgOnDisk {
79
79
  if (exc.notFound) {
80
80
  return;
81
81
  }
82
- throw error_1.errWithCause(exc, `Cannot stat message obj at ${path}`);
82
+ throw (0, error_1.errWithCause)(exc, `Cannot stat message obj at ${path}`);
83
83
  }));
84
84
  file = (isOnDisk ?
85
85
  await obj_on_disk_1.ObjOnDisk.forExistingFile(objId, 0, path, this.objDownloader) :
@@ -119,16 +119,16 @@ exports.MsgOnDisk = MsgOnDisk;
119
119
  Object.freeze(MsgOnDisk.prototype);
120
120
  Object.freeze(MsgOnDisk);
121
121
  async function readJSON(msgFolderPath, fname, msgId) {
122
- const path = path_1.join(msgFolderPath, fname);
122
+ const path = (0, path_1.join)(msgFolderPath, fname);
123
123
  try {
124
124
  return JSON.parse(await fs.readFile(path, { flag: 'r', encoding: 'utf8' }));
125
125
  }
126
126
  catch (err) {
127
- throw error_1.errWithCause(err, `Can't read file ${fname} of message ${msgId}`);
127
+ throw (0, error_1.errWithCause)(err, `Can't read file ${fname} of message ${msgId}`);
128
128
  }
129
129
  }
130
130
  async function writeJSON(msgFolderPath, fname, json, exclusive = false) {
131
- const path = path_1.join(msgFolderPath, fname);
131
+ const path = (0, path_1.join)(msgFolderPath, fname);
132
132
  await fs.writeFile(path, JSON.stringify(json), { flag: (exclusive ? 'wx' : 'w') });
133
133
  }
134
134
  function objIdsFromMeta(meta) {
@@ -2,15 +2,14 @@ import { InboxPathForUser } from '../app-files';
2
2
  import { StorageGetter } from '../../lib-client/3nstorage/xsp-fs/common';
3
3
  import { GetSigner } from '../id-manager';
4
4
  import { AsyncSBoxCryptor } from 'xsp-files';
5
- import { NetClient } from '../../lib-client/request-utils';
6
5
  import { Logger } from '../../lib-client/logging/log-to-file';
7
6
  import { ServiceLocatorMaker } from '../../lib-client/service-locator';
7
+ import { MakeNet } from '..';
8
8
  declare type WritableFS = web3n.files.WritableFS;
9
9
  declare type Service = web3n.asmail.Service;
10
10
  export declare type MailCAPMaker = () => Service;
11
11
  export declare class ASMail {
12
12
  private readonly cryptor;
13
- private readonly makeNet;
14
13
  private readonly inboxPathForUser;
15
14
  private readonly logger;
16
15
  private keyring;
@@ -19,7 +18,8 @@ export declare class ASMail {
19
18
  private delivery;
20
19
  private config;
21
20
  private sendingParams;
22
- constructor(cryptor: AsyncSBoxCryptor, makeNet: () => NetClient, inboxPathForUser: InboxPathForUser, logger: Logger);
21
+ private readonly makeNet;
22
+ constructor(cryptor: AsyncSBoxCryptor, makeNet: MakeNet, inboxPathForUser: InboxPathForUser, logger: Logger);
23
23
  init(address: string, getSigner: GetSigner, syncedFS: WritableFS, localFS: WritableFS, getStorages: StorageGetter, makeResolver: ServiceLocatorMaker): Promise<void>;
24
24
  private setupConfig;
25
25
  private setupKeyring;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- Copyright (C) 2015 - 2018, 2020 - 2021 3NSoft Inc.
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
@@ -23,6 +23,7 @@ const keyring_1 = require("./keyring");
23
23
  const config_1 = require("./config");
24
24
  const delivery_1 = require("./delivery");
25
25
  const sending_params_1 = require("./sending-params");
26
+ const fs_sync_utils_1 = require("../../lib-client/fs-sync-utils");
26
27
  const KEYRING_DATA_FOLDER = 'keyring';
27
28
  const INBOX_DATA_FOLDER = 'inbox';
28
29
  const CONFIG_DATA_FOLDER = 'config';
@@ -31,7 +32,6 @@ const SEND_PARAMS_DATA_FOLDER = 'sending-params';
31
32
  class ASMail {
32
33
  constructor(cryptor, makeNet, inboxPathForUser, logger) {
33
34
  this.cryptor = cryptor;
34
- this.makeNet = makeNet;
35
35
  this.inboxPathForUser = inboxPathForUser;
36
36
  this.logger = logger;
37
37
  this.keyring = undefined;
@@ -40,11 +40,13 @@ class ASMail {
40
40
  this.delivery = undefined;
41
41
  this.config = undefined;
42
42
  this.sendingParams = undefined;
43
+ this.makeNet = () => makeNet();
43
44
  Object.seal(this);
44
45
  }
45
46
  async init(address, getSigner, syncedFS, localFS, getStorages, makeResolver) {
46
47
  try {
47
48
  this.address = address;
49
+ await (0, fs_sync_utils_1.getRemoteFolderChanges)(syncedFS);
48
50
  await this.setupConfig(getSigner, syncedFS, makeResolver('asmail'));
49
51
  await Promise.all([
50
52
  this.setupKeyring(syncedFS),
@@ -54,23 +56,24 @@ class ASMail {
54
56
  this.setupInbox(syncedFS, getSigner, getStorages, makeResolver),
55
57
  this.setupDelivery(localFS, getSigner, makeResolver)
56
58
  ]);
59
+ await (0, fs_sync_utils_1.uploadFolderChangesIfAny)(syncedFS);
57
60
  await syncedFS.close();
58
61
  await localFS.close();
59
62
  }
60
63
  catch (err) {
61
- throw error_1.errWithCause(err, 'Failed to initialize ASMail');
64
+ throw (0, error_1.errWithCause)(err, 'Failed to initialize ASMail');
62
65
  }
63
66
  }
64
67
  async setupConfig(getSigner, syncedFS, resolver) {
65
- const fs = await syncedFS.writableSubRoot(CONFIG_DATA_FOLDER);
68
+ const fs = await (0, fs_sync_utils_1.getOrMakeAndUploadFolderIn)(syncedFS, CONFIG_DATA_FOLDER);
66
69
  this.config = await config_1.ConfigOfASMailServer.makeAndStart(this.address, getSigner, resolver, this.makeNet(), fs);
67
70
  }
68
71
  async setupKeyring(syncedFS) {
69
- const fs = await syncedFS.writableSubRoot(KEYRING_DATA_FOLDER);
72
+ const fs = await (0, fs_sync_utils_1.getOrMakeAndUploadFolderIn)(syncedFS, KEYRING_DATA_FOLDER);
70
73
  this.keyring = await keyring_1.KeyRing.makeAndStart(this.cryptor, fs, this.config.publishedKeys);
71
74
  }
72
75
  async setupSendingParams(syncedFS) {
73
- const fs = await syncedFS.writableSubRoot(SEND_PARAMS_DATA_FOLDER);
76
+ const fs = await (0, fs_sync_utils_1.getOrMakeAndUploadFolderIn)(syncedFS, SEND_PARAMS_DATA_FOLDER);
74
77
  this.sendingParams = await sending_params_1.SendingParamsHolder.makeAndStart(fs, this.config.anonSenderInvites);
75
78
  }
76
79
  async setupDelivery(localFS, getSigner, makeResolver) {
@@ -96,7 +99,7 @@ class ASMail {
96
99
  }
97
100
  async setupInbox(syncedFS, getSigner, getStorages, makeResolver) {
98
101
  const cachePath = this.inboxPathForUser(this.address);
99
- const inboxFS = await syncedFS.writableSubRoot(INBOX_DATA_FOLDER);
102
+ const inboxFS = await (0, fs_sync_utils_1.getOrMakeAndUploadFolderIn)(syncedFS, INBOX_DATA_FOLDER);
100
103
  this.inbox = await inbox_1.InboxOnServer.makeAndStart(cachePath, inboxFS, {
101
104
  address: this.address,
102
105
  cryptor: this.cryptor,
@@ -117,7 +120,7 @@ class ASMail {
117
120
  const w = {
118
121
  getUserId: async () => this.address,
119
122
  delivery: this.delivery.wrap(),
120
- inbox: this.inbox.wrap()
123
+ inbox: this.inbox.wrap(),
121
124
  };
122
125
  return Object.freeze(w);
123
126
  }
@@ -127,4 +130,6 @@ class ASMail {
127
130
  }
128
131
  }
129
132
  exports.ASMail = ASMail;
133
+ Object.freeze(ASMail.prototype);
134
+ Object.freeze(ASMail);
130
135
  Object.freeze(exports);
@@ -30,10 +30,10 @@ const service_locator_1 = require("../../lib-client/service-locator");
30
30
  * @param certs is an object with a MailerId certificates chain for a public key
31
31
  */
32
32
  async function checkAndExtractPKey(client, resolver, address, certs) {
33
- address = canonical_address_1.toCanonicalAddress(address);
33
+ address = (0, canonical_address_1.toCanonicalAddress)(address);
34
34
  const validAt = Math.round(Date.now() / 1000);
35
35
  // get MailerId provider's info with a root certificate(s)
36
- const data = await service_locator_1.getMailerIdInfoFor(resolver, client, address);
36
+ const data = await (0, service_locator_1.getMailerIdInfoFor)(resolver, client, address);
37
37
  // TODO choose proper root certificate, as it may not be current one
38
38
  const rootAddr = data.domain;
39
39
  const rootCert = data.info.currentCert;
@@ -56,13 +56,13 @@ async function checkAndExtractPKeyWithAddress(client, resolver, certs, validAt)
56
56
  // address here comes from certificates; we return it for further checks
57
57
  let address;
58
58
  try {
59
- address = jwkeys_1.getKeyCert(certs.pkeyCert).cert.principal.address;
59
+ address = (0, jwkeys_1.getKeyCert)(certs.pkeyCert).cert.principal.address;
60
60
  }
61
61
  catch (err) {
62
- throw mid_sigs_NaCl_Ed_1.makeMalformedCertsException(`Cannot read public key certificate`, err);
62
+ throw (0, mid_sigs_NaCl_Ed_1.makeMalformedCertsException)(`Cannot read public key certificate`, err);
63
63
  }
64
64
  // get MailerId provider's info with a root certificate(s)
65
- const data = await service_locator_1.getMailerIdInfoFor(resolver, client, address);
65
+ const data = await (0, service_locator_1.getMailerIdInfoFor)(resolver, client, address);
66
66
  // TODO choose proper root certificate, as it may not be current one
67
67
  const rootAddr = data.domain;
68
68
  const rootCert = data.info.currentCert;
@@ -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.msgKeyPackSizeFor = exports.extractKeyBytes = exports.extractPKeyBytes = exports.extractSKeyBytes = exports.generateSymmetricKey = exports.generateKeyPair = exports.KEY_USE = exports.PID_LENGTH = exports.KID_LENGTH = void 0;
19
20
  /**
@@ -21,7 +22,7 @@ exports.msgKeyPackSizeFor = exports.extractKeyBytes = exports.extractPKeyBytes =
21
22
  */
22
23
  const ecma_nacl_1 = require("ecma-nacl");
23
24
  const buffer_utils_1 = require("../../../lib-common/buffer-utils");
24
- const random = require("../../../lib-common/random-node");
25
+ const random_node_1 = require("../../../lib-common/random-node");
25
26
  exports.KID_LENGTH = 16;
26
27
  exports.PID_LENGTH = 2;
27
28
  exports.KEY_USE = {
@@ -37,9 +38,9 @@ Object.freeze(exports.KEY_USE);
37
38
  * Key ids are the same in this intimate pair.
38
39
  */
39
40
  async function generateKeyPair() {
40
- const skeyBytes = await random.bytes(ecma_nacl_1.box.KEY_LENGTH);
41
+ const skeyBytes = await (0, random_node_1.bytes)(ecma_nacl_1.box.KEY_LENGTH);
41
42
  const pkeyBytes = ecma_nacl_1.box.generate_pubkey(skeyBytes);
42
- const kid = await random.stringOfB64Chars(exports.KID_LENGTH);
43
+ const kid = await (0, random_node_1.stringOfB64Chars)(exports.KID_LENGTH);
43
44
  const skey = {
44
45
  use: exports.KEY_USE.SECRET,
45
46
  alg: ecma_nacl_1.box.JWK_ALG_NAME,
@@ -66,9 +67,9 @@ exports.generateKeyPair = generateKeyPair;
66
67
  async function generateSymmetricKey() {
67
68
  return {
68
69
  use: exports.KEY_USE.SYMMETRIC,
69
- k: buffer_utils_1.base64.pack(await random.bytes(ecma_nacl_1.secret_box.KEY_LENGTH)),
70
+ k: buffer_utils_1.base64.pack(await (0, random_node_1.bytes)(ecma_nacl_1.secret_box.KEY_LENGTH)),
70
71
  alg: ecma_nacl_1.secret_box.JWK_ALG_NAME,
71
- kid: await random.stringOfB64Chars(exports.KID_LENGTH)
72
+ kid: await (0, random_node_1.stringOfB64Chars)(exports.KID_LENGTH)
72
73
  };
73
74
  }
74
75
  exports.generateSymmetricKey = generateSymmetricKey;
@@ -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.CorrespondentKeys = exports.msgMasterDecryptor = void 0;
19
20
  /**
@@ -34,15 +35,15 @@ function generatePids() {
34
35
  }
35
36
  function msgMasterDecryptor(cryptor, skey, pkey) {
36
37
  const msgMasterKey = calcMsgMasterKey(skey, pkey);
37
- const masterDecr = async_cryptor_wrap_1.makeDecryptor(cryptor, msgMasterKey);
38
+ const masterDecr = (0, async_cryptor_wrap_1.makeDecryptor)(cryptor, msgMasterKey);
38
39
  msgMasterKey.fill(0);
39
40
  return masterDecr;
40
41
  }
41
42
  exports.msgMasterDecryptor = msgMasterDecryptor;
42
43
  function calcMsgMasterKey(skey, pkey) {
43
44
  if (skey.alg === ecma_nacl_1.box.JWK_ALG_NAME) {
44
- const sk = common_1.extractSKeyBytes(skey);
45
- const pk = common_1.extractKeyBytes(pkey);
45
+ const sk = (0, common_1.extractSKeyBytes)(skey);
46
+ const pk = (0, common_1.extractKeyBytes)(pkey);
46
47
  const dhShared = ecma_nacl_1.box.calc_dhshared_key(pk, sk);
47
48
  sk.fill(0);
48
49
  pk.fill(0);
@@ -126,7 +127,7 @@ class CorrespondentKeys {
126
127
  // generate new suggested pair
127
128
  const corrPKey = this.keys.sendingPair.recipientPKey;
128
129
  const isSenderIntroKey = (this.keys.sendingPair.type === 'intro');
129
- const recipientKey = await common_1.generateKeyPair();
130
+ const recipientKey = await (0, common_1.generateKeyPair)();
130
131
  const msgMasterKey = calcMsgMasterKeyB64(recipientKey.skey, corrPKey);
131
132
  const pair = {
132
133
  pids: generatePids(),
@@ -249,7 +250,7 @@ class CorrespondentKeys {
249
250
  };
250
251
  }
251
252
  catch (err) {
252
- throw error_1.errWithCause(err, "Public key in a given pair cannot be used");
253
+ throw (0, error_1.errWithCause)(err, "Public key in a given pair cannot be used");
253
254
  }
254
255
  }
255
256
  /**
@@ -294,7 +295,7 @@ class CorrespondentKeys {
294
295
  let msgMasterKey;
295
296
  let msgCount;
296
297
  if (p.type === 'intro') {
297
- const senderKey = await common_1.generateKeyPair();
298
+ const senderKey = await (0, common_1.generateKeyPair)();
298
299
  msgMasterKey = calcMsgMasterKey(senderKey.skey, p.recipientPKey);
299
300
  currentPair = {
300
301
  senderPKey: senderKey.pkey,
@@ -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.IdToEmailMap = void 0;
19
20
  /**
@@ -1,4 +1,3 @@
1
- import { CorrespondentKeys } from './correspondent-keys';
2
1
  import { IdToEmailMap } from './id-to-email-map';
3
2
  import { MsgKeyRole } from './common';
4
3
  import { AsyncSBoxCryptor } from 'xsp-files';
@@ -27,13 +26,13 @@ declare type WritableFS = web3n.files.WritableFS;
27
26
  declare type SendingResources = ResourcesForSending['correspondents'];
28
27
  declare type ReceptionResources = ResourcesForReceiving['correspondents'];
29
28
  export declare class KeyRing {
30
- private cryptor;
31
- private publishedKeys;
29
+ private readonly cryptor;
30
+ private readonly publishedKeys;
32
31
  /**
33
32
  * This is a map from correspondents' canonical addresses to key objects.
34
33
  */
35
- corrKeys: Map<string, CorrespondentKeys>;
36
- pairIdToEmailMap: IdToEmailMap;
34
+ private readonly corrKeys;
35
+ readonly pairIdToEmailMap: IdToEmailMap;
37
36
  private storage;
38
37
  constructor(cryptor: AsyncSBoxCryptor, publishedKeys: ConfigOfASMailServer['publishedKeys']);
39
38
  private addCorrespondent;
@@ -41,8 +40,8 @@ export declare class KeyRing {
41
40
  static makeAndStart(cryptor: AsyncSBoxCryptor, fs: WritableFS, publishedKeys: ConfigOfASMailServer['publishedKeys']): Promise<KeyRing>;
42
41
  saveChanges(): void;
43
42
  needIntroKeyFor: SendingResources['needIntroKeyFor'];
44
- generateKeysToSend: SendingResources['generateKeysToSend'];
45
- nextCrypto: SendingResources['nextCrypto'];
43
+ readonly generateKeysToSend: SendingResources['generateKeysToSend'];
44
+ readonly nextCrypto: SendingResources['nextCrypto'];
46
45
  private decryptMsgKeyWithIntroPair;
47
46
  private findEstablishedReceptionPairs;
48
47
  private decryptMsgKeyWithEstablishedPair;
@@ -55,6 +54,6 @@ export declare class KeyRing {
55
54
  */
56
55
  private updateReceivedMsgCountIn;
57
56
  private absorbSuggestedNextKeyPair;
58
- decrypt: ReceptionResources['msgDecryptor'];
57
+ readonly decrypt: ReceptionResources['msgDecryptor'];
59
58
  close(): Promise<void>;
60
59
  }