core-3nweb-client-lib 0.49.6 → 0.49.8

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 (87) hide show
  1. package/build/api-defs/asmail.d.ts +1 -0
  2. package/build/api-defs/files.d.ts +11 -5
  3. package/build/core/asmail/delivery/common.d.ts +8 -28
  4. package/build/core/asmail/delivery/common.js +1 -47
  5. package/build/core/asmail/delivery/index.js +3 -3
  6. package/build/core/asmail/delivery/per-recipient-wip.js +3 -2
  7. package/build/core/asmail/inbox/index.d.ts +8 -32
  8. package/build/core/asmail/inbox/index.js +120 -170
  9. package/build/core/asmail/inbox/msg-indexing/dataset/v0/sql-db-v-none.d.ts +11 -0
  10. package/build/{lib-client/xsp-fs/util/for-arrays.js → core/asmail/inbox/msg-indexing/dataset/v0/sql-db-v-none.js} +7 -13
  11. package/build/core/asmail/inbox/msg-indexing/dataset/v1/logs.d.ts +33 -0
  12. package/build/core/asmail/inbox/msg-indexing/dataset/v1/logs.js +72 -0
  13. package/build/core/asmail/inbox/msg-indexing/dataset/v1/sql-db.d.ts +28 -0
  14. package/build/core/asmail/inbox/msg-indexing/dataset/v1/sql-db.js +477 -0
  15. package/build/core/asmail/inbox/msg-indexing/index.d.ts +12 -26
  16. package/build/core/asmail/inbox/msg-indexing/index.js +47 -68
  17. package/build/core/asmail/inbox/msg-on-disk.d.ts +0 -5
  18. package/build/core/asmail/inbox/msg-on-disk.js +2 -24
  19. package/build/core/asmail/index.js +8 -7
  20. package/build/core/asmail/msg/common.d.ts +0 -1
  21. package/build/core/asmail/msg/common.js +1 -1
  22. package/build/core/index.js +7 -4
  23. package/build/core/keyring/common.d.ts +1 -0
  24. package/build/core/keyring/common.js +2 -1
  25. package/build/core/keyring/index.d.ts +7 -44
  26. package/build/core/keyring/index.js +88 -222
  27. package/build/core/keyring/introductory-keys/published-intro-key.d.ts +17 -0
  28. package/build/core/keyring/introductory-keys/published-intro-key.js +190 -0
  29. package/build/core/keyring/peer-keys/dataset/v1/json-files.d.ts +105 -0
  30. package/build/core/keyring/peer-keys/dataset/v1/json-files.js +89 -0
  31. package/build/core/keyring/peer-keys/dataset/v2/logs.d.ts +43 -0
  32. package/build/core/keyring/peer-keys/dataset/v2/logs.js +116 -0
  33. package/build/core/keyring/peer-keys/dataset/v2/peer-keys-db.d.ts +73 -0
  34. package/build/core/keyring/peer-keys/dataset/v2/peer-keys-db.js +543 -0
  35. package/build/core/keyring/peer-keys/index.d.ts +24 -0
  36. package/build/core/keyring/peer-keys/index.js +208 -0
  37. package/build/core/storage/synced/obj-files.js +10 -3
  38. package/build/core/storage/synced/obj-status.d.ts +1 -1
  39. package/build/core/storage/synced/obj-status.js +8 -2
  40. package/build/core/storage/synced/storage.d.ts +4 -4
  41. package/build/core/storage/system-folders/apps-data.d.ts +0 -1
  42. package/build/core/storage/system-folders/apps-data.js +2 -6
  43. package/build/lib-client/asmail/recipient.d.ts +1 -0
  44. package/build/lib-client/asmail/recipient.js +11 -0
  45. package/build/lib-client/fs-utils/fs-sync-utils.d.ts +1 -1
  46. package/build/lib-client/fs-utils/fs-sync-utils.js +70 -13
  47. package/build/lib-client/xsp-fs/folder-node.js +13 -3
  48. package/build/lib-client/xsp-fs/fs.js +3 -1
  49. package/build/lib-client/xsp-fs/node-in-fs.d.ts +1 -0
  50. package/build/lib-client/xsp-fs/node-in-fs.js +7 -2
  51. package/build/lib-client/xsp-fs/node-persistence.js +1 -3
  52. package/build/lib-client/xsp-fs/xsp-payload-v2.js +1 -2
  53. package/build/lib-common/dataset-sync/per-device-json-array-logs.d.ts +58 -0
  54. package/build/lib-common/dataset-sync/per-device-json-array-logs.js +432 -0
  55. package/build/lib-common/dataset-sync/single-file.d.ts +10 -0
  56. package/build/lib-common/dataset-sync/single-file.js +77 -0
  57. package/build/lib-common/number-line.d.ts +10 -0
  58. package/build/lib-common/number-line.js +66 -0
  59. package/build/lib-common/objs-on-disk/obj-version-file.d.ts +1 -1
  60. package/build/lib-common/objs-on-disk/obj-version-file.js +3 -3
  61. package/build/lib-common/rng-def.d.ts +1 -0
  62. package/build/lib-common/rng-def.js +8 -0
  63. package/build/lib-sqlite-on-3nstorage/for-sqlite.d.ts +38 -0
  64. package/build/lib-sqlite-on-3nstorage/for-sqlite.js +162 -0
  65. package/build/lib-sqlite-on-3nstorage/index.d.ts +18 -5
  66. package/build/lib-sqlite-on-3nstorage/index.js +49 -26
  67. package/build/tests/caps-api/file-sink-checks/splice.js +72 -1
  68. package/build/tests/caps-api/fs-checks/sync-on-one-dev/upload.js +27 -1
  69. package/build/tests/caps-api/fs-checks/sync-with-two-devs/update-propagation.js +12 -3
  70. package/build/tests/computer.3nweb.core/inbox/msg-indexing.js +16 -12
  71. package/build/tests/computer.3nweb.core/keyrings.js +113 -28
  72. package/build/tests/jasmine.js +2 -2
  73. package/build/tests/units/number-line.js +9 -9
  74. package/package.json +2 -1
  75. package/build/core/asmail/inbox/msg-indexing/logs-n-entries.d.ts +0 -52
  76. package/build/core/asmail/inbox/msg-indexing/logs-n-entries.js +0 -333
  77. package/build/core/asmail/inbox/msg-indexing/sql-indexing.d.ts +0 -4
  78. package/build/core/asmail/inbox/msg-indexing/sql-indexing.js +0 -319
  79. package/build/core/keyring/correspondent-keys.d.ts +0 -149
  80. package/build/core/keyring/correspondent-keys.js +0 -403
  81. package/build/core/keyring/id-to-email-map.d.ts +0 -38
  82. package/build/core/keyring/id-to-email-map.js +0 -105
  83. package/build/core/keyring/keyring-storage.d.ts +0 -9
  84. package/build/core/keyring/keyring-storage.js +0 -54
  85. package/build/core/keyring/published-intro-key.d.ts +0 -45
  86. package/build/core/keyring/published-intro-key.js +0 -200
  87. package/build/lib-client/xsp-fs/util/for-arrays.d.ts +0 -1
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- Copyright (C) 2016 - 2019 3NSoft Inc.
3
+ Copyright (C) 2016 - 2019, 2026 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
@@ -27,7 +27,6 @@ const STATUS_FNAME = 'status.json';
27
27
  function makeInitMsgStatus(msgId, meta) {
28
28
  return {
29
29
  msgId,
30
- keyStatus: 'not-checked',
31
30
  onDisk: false,
32
31
  mainObjId: meta.extMeta.objIds[0],
33
32
  deliveryTS: meta.deliveryStart
@@ -75,8 +74,7 @@ class MsgOnDisk {
75
74
  throw new Error(`Obj ${objId} not present in message ${this.msgId}`);
76
75
  }
77
76
  const path = this.objFilePath(objId);
78
- const isOnDisk = !!(await fs.stat(path)
79
- .catch((exc) => {
77
+ const isOnDisk = !!(await fs.stat(path).catch((exc) => {
80
78
  if (exc.notFound) {
81
79
  return;
82
80
  }
@@ -95,26 +93,6 @@ class MsgOnDisk {
95
93
  get deliveryTS() {
96
94
  return this.status.deliveryTS;
97
95
  }
98
- get keyStatus() {
99
- return this.status.keyStatus;
100
- }
101
- updateMsgKeyStatus(newStatus) {
102
- return this.syncProc.startOrChain(async () => {
103
- if (this.status.keyStatus === 'not-checked') {
104
- this.status.keyStatus = newStatus;
105
- }
106
- else if (this.status.keyStatus === newStatus) {
107
- return;
108
- }
109
- else {
110
- throw Error(`Message has key status ${this.status.keyStatus}, and can't be updated to ${newStatus}`);
111
- }
112
- await this.saveStatusToDisk();
113
- });
114
- }
115
- async saveStatusToDisk() {
116
- await writeJSON(this.msgFolderPath, STATUS_FNAME, this.status);
117
- }
118
96
  }
119
97
  exports.MsgOnDisk = MsgOnDisk;
120
98
  Object.freeze(MsgOnDisk.prototype);
@@ -49,7 +49,7 @@ class ASMail {
49
49
  this.keyring = keyring;
50
50
  await this.setupSendingParams(syncedFS);
51
51
  await Promise.all([
52
- this.setupInbox(syncedFS, getSigner, getStorages, makeResolver),
52
+ this.setupInbox(syncedFS, localFS, getSigner, getStorages, makeResolver),
53
53
  this.setupDelivery(localFS, getSigner, makeResolver)
54
54
  ]);
55
55
  await (0, fs_sync_utils_1.uploadFolderChangesIfAny)(syncedFS);
@@ -61,7 +61,7 @@ class ASMail {
61
61
  }
62
62
  }
63
63
  async setupSendingParams(syncedFS) {
64
- const fs = await (0, fs_sync_utils_1.getOrMakeAndUploadFolderIn)(syncedFS, SEND_PARAMS_DATA_FOLDER);
64
+ const fs = await (0, fs_sync_utils_1.getOrMakeSyncedDirOnInit)(syncedFS, SEND_PARAMS_DATA_FOLDER);
65
65
  this.sendingParams = await sending_params_1.SendingParamsHolder.makeAndInit(fs, this.config.makeParamSetterAndGetter('anon-sender/invites'), this.random);
66
66
  }
67
67
  async setupDelivery(localFS, getSigner, makeResolver) {
@@ -75,8 +75,8 @@ class ASMail {
75
75
  midResolver: makeResolver('mailerid', this.logger.logError),
76
76
  correspondents: {
77
77
  needIntroKeyFor: this.keyring.needIntroKeyFor,
78
- generateKeysToSend: this.keyring.generateKeysToSend,
79
- nextCrypto: this.keyring.nextCrypto,
78
+ generateIntroKeysToSendMsg: this.keyring.generateIntroKeysToSendMsg,
79
+ getEstablishedKeysToSendMsg: this.keyring.getEstablishedKeysToSendMsg,
80
80
  paramsForSendingTo: this.sendingParams.otherSides.get,
81
81
  newParamsForSendingReplies: this.sendingParams.thisSide.getUpdated
82
82
  },
@@ -86,10 +86,11 @@ class ASMail {
86
86
  logWarning: this.logger.logWarning
87
87
  });
88
88
  }
89
- async setupInbox(syncedFS, getSigner, getStorages, makeResolver) {
89
+ async setupInbox(syncedFS, localFS, getSigner, getStorages, makeResolver) {
90
90
  const cachePath = this.inboxPathForUser(this.address);
91
- const inboxSyncedFS = await (0, fs_sync_utils_1.getOrMakeAndUploadFolderIn)(syncedFS, INBOX_DATA_FOLDER);
92
- this.inbox = await inbox_1.InboxOnServer.makeAndStart(cachePath, inboxSyncedFS, {
91
+ const inboxSyncedFS = await (0, fs_sync_utils_1.getOrMakeSyncedDirOnInit)(syncedFS, INBOX_DATA_FOLDER);
92
+ const inboxLocalFS = await localFS.writableSubRoot(INBOX_DATA_FOLDER);
93
+ this.inbox = await (0, inbox_1.makeInboxOnServer)(cachePath, inboxSyncedFS, inboxLocalFS, {
93
94
  address: this.address,
94
95
  cryptor: this.cryptor,
95
96
  random: this.random,
@@ -38,7 +38,6 @@ export interface MsgEnvelope {
38
38
  export interface SuggestedNextKeyPair {
39
39
  pids: string[];
40
40
  senderKid: string;
41
- isSenderIntroKey?: boolean;
42
41
  recipientPKey: JsonKeyShort;
43
42
  timestamp: number;
44
43
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- Copyright (C) 2015 - 2018, 2020, 2022 3NSoft Inc.
3
+ Copyright (C) 2015 - 2018, 2020, 2022, 2026 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
@@ -38,12 +38,12 @@ class Core {
38
38
  this.appDirs = appDirs;
39
39
  this.logger = logger;
40
40
  this.signUpUrl = signUpUrl;
41
+ this.keyrings = undefined;
41
42
  this.idManager = undefined;
42
43
  this.closingProc = undefined;
43
44
  this.isInitialized = false;
44
45
  this.cryptor = makeCryptor(this.logger.logError, this.logger.logWarning);
45
46
  this.storages = new storage_1.Storages(this.cryptor.cryptor.sbox, this.random, this.appDirs.storagePathFor);
46
- this.keyrings = new keyring_1.Keyrings(this.cryptor.cryptor.sbox, this.random, this.logger);
47
47
  this.asmail = new asmail_1.ASMail(this.cryptor.cryptor.sbox, this.random, this.makeNet, this.appDirs.inboxPathFor, this.logger);
48
48
  Object.seal(this);
49
49
  }
@@ -265,9 +265,10 @@ class Core {
265
265
  }
266
266
  }
267
267
  makeKeyringsCAP(requestedCAPs) {
268
+ var _a;
268
269
  if (requestedCAPs.keyrings
269
270
  && (requestedCAPs.keyrings === 'all')) {
270
- return this.keyrings.makeKeyringsCAP();
271
+ return (_a = this.keyrings) === null || _a === void 0 ? void 0 : _a.makeKeyringsCAP();
271
272
  }
272
273
  else {
273
274
  return undefined;
@@ -292,9 +293,10 @@ class Core {
292
293
  async close() {
293
294
  if (!this.closingProc) {
294
295
  this.closingProc = (async () => {
296
+ var _a;
295
297
  if (this.isInitialized) {
296
298
  await this.asmail.close();
297
- await this.keyrings.close();
299
+ await ((_a = this.keyrings) === null || _a === void 0 ? void 0 : _a.close());
298
300
  await this.storages.close();
299
301
  this.asmail = undefined;
300
302
  this.keyrings = undefined;
@@ -323,7 +325,8 @@ class Core {
323
325
  const asmailServerConfig = new config_1.ConfigOfASMailServer(address, getSigner, this.makeResolver('asmail', this.logger.logError), this.makeNet());
324
326
  emitBootEvent({ coreApp: constants_1.KEYRINGS_APP_NAME, message: `starting initialization` });
325
327
  const keyringsSyncedFS = await this.storages.makeSyncedFSForApp(constants_1.KEYRINGS_APP_NAME);
326
- await this.keyrings.init(keyringsSyncedFS, this.idManager.getSigner, asmailServerConfig.makeParamSetterAndGetter('init-pub-key'));
328
+ const keyringsLocalFS = await this.storages.makeLocalFSForApp(constants_1.KEYRINGS_APP_NAME);
329
+ this.keyrings = await (0, keyring_1.makeKeyrings)(this.cryptor.cryptor.sbox, this.random, this.logger, keyringsSyncedFS, keyringsLocalFS, this.idManager.getSigner, asmailServerConfig.makeParamSetterAndGetter('init-pub-key'));
327
330
  emitBootEvent({ coreApp: constants_1.KEYRINGS_APP_NAME, message: `✔️ initialized` });
328
331
  emitBootEvent({ coreApp: constants_1.ASMAIL_APP_NAME, message: `starting initialization` });
329
332
  const inboxSyncedFS = await this.storages.makeSyncedFSForApp(constants_1.ASMAIL_APP_NAME);
@@ -4,6 +4,7 @@ type JsonKeyShort = web3n.keys.JsonKeyShort;
4
4
  export type MsgKeyRole = 'suggested' | 'in_use' | 'old' | 'published_intro' | 'prev_published_intro' | 'introductory';
5
5
  export declare const KID_LENGTH = 16;
6
6
  export declare const PID_LENGTH = 2;
7
+ export declare const MIN_PERIOD_FOR_PAIR: number;
7
8
  export interface JWKeyPair {
8
9
  skey: JsonKey;
9
10
  pkey: JsonKey;
@@ -16,7 +16,7 @@
16
16
  this program. If not, see <http://www.gnu.org/licenses/>.
17
17
  */
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.KEY_USE = exports.PID_LENGTH = exports.KID_LENGTH = void 0;
19
+ exports.KEY_USE = exports.MIN_PERIOD_FOR_PAIR = exports.PID_LENGTH = exports.KID_LENGTH = void 0;
20
20
  exports.generateKeyPair = generateKeyPair;
21
21
  exports.generateSymmetricKey = generateSymmetricKey;
22
22
  exports.extractSKeyBytes = extractSKeyBytes;
@@ -31,6 +31,7 @@ const buffer_utils_1 = require("../../lib-common/buffer-utils");
31
31
  const rng_def_1 = require("../../lib-common/rng-def");
32
32
  exports.KID_LENGTH = 16;
33
33
  exports.PID_LENGTH = 2;
34
+ exports.MIN_PERIOD_FOR_PAIR = 15 * 60 * 1000;
34
35
  exports.KEY_USE = {
35
36
  PUBLIC: 'asmail-pub-key',
36
37
  SECRET: 'asmail-sec-key',
@@ -1,4 +1,3 @@
1
- import { IdToEmailMap } from './id-to-email-map';
2
1
  import { MsgKeyRole } from './common';
3
2
  import { AsyncSBoxCryptor } from 'xsp-files';
4
3
  import { ResourcesForSending } from '../asmail/delivery/common';
@@ -28,49 +27,13 @@ type SendingResources = ResourcesForSending['correspondents'];
28
27
  type ReceptionResources = ResourcesForReceiving['correspondents'];
29
28
  export interface KeyringForASMail {
30
29
  needIntroKeyFor: SendingResources['needIntroKeyFor'];
31
- generateKeysToSend: SendingResources['generateKeysToSend'];
32
- nextCrypto: SendingResources['nextCrypto'];
30
+ generateIntroKeysToSendMsg: SendingResources['generateIntroKeysToSendMsg'];
31
+ getEstablishedKeysToSendMsg: SendingResources['getEstablishedKeysToSendMsg'];
33
32
  decrypt: ReceptionResources['msgDecryptor'];
34
33
  close(): Promise<void>;
35
34
  }
36
- export interface KeyPairsStorage {
37
- pairIdToEmailMap: IdToEmailMap;
38
- saveChanges: () => void;
39
- }
40
- export declare class Keyrings {
41
- private readonly cryptor;
42
- private readonly random;
43
- private readonly logger;
44
- /**
45
- * This is a map from correspondents' canonical addresses to key objects.
46
- */
47
- private readonly corrKeys;
48
- readonly pairIdToEmailMap: IdToEmailMap;
49
- private readonly workLabel;
50
- private storage;
51
- private publishedKeys;
52
- constructor(cryptor: AsyncSBoxCryptor, random: AsyncRNG, logger: Logger);
53
- private readonly asKeyPairsStorage;
54
- private addCorrespondent;
55
- init(fs: WritableFS, getSigner: GetSigner, pkeyOnServer: ParamOnServer<'init-pub-key'>): Promise<void>;
56
- forASMail(): KeyringForASMail;
57
- private saveChanges;
58
- private needIntroKeyFor;
59
- private generateKeysToSend;
60
- private nextCrypto;
61
- private decryptMsgKeyWithIntroPair;
62
- private findEstablishedReceptionPairs;
63
- private decryptMsgKeyWithEstablishedPair;
64
- /**
65
- * This method updates message counts and a timestamp in a given reception
66
- * pair.
67
- * @param rp is a sending pair, in which changes should be done. Note this
68
- * must be a shared structure at this point, not a copy of a pair.
69
- * @param msgCount is a message count that should be added to the pair.
70
- */
71
- private updateReceivedMsgCountIn;
72
- private absorbSuggestedNextKeyPair;
73
- private decrypt;
74
- close(): Promise<void>;
75
- makeKeyringsCAP(): Service;
76
- }
35
+ export declare function makeKeyrings(cryptor: AsyncSBoxCryptor, random: AsyncRNG, logger: Logger, fs: WritableFS, localFS: WritableFS, getSigner: GetSigner, pkeyOnServer: ParamOnServer<'init-pub-key'>): Promise<{
36
+ close: () => Promise<void>;
37
+ makeKeyringsCAP: () => Service;
38
+ forASMail: () => KeyringForASMail;
39
+ }>;