core-3nweb-client-lib 0.34.1 → 0.35.0

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 (151) hide show
  1. package/build/api-defs/asmail.d.ts +70 -5
  2. package/build/api-defs/common-caps.d.ts +3 -0
  3. package/build/api-defs/keys.d.ts +154 -0
  4. package/build/api-defs/mailerid.d.ts +8 -0
  5. package/build/api-defs/web3n.d.ts +1 -0
  6. package/build/core/asmail/asmail-cap-ipc.js +20 -1
  7. package/build/core/asmail/config.d.ts +16 -0
  8. package/build/core/asmail/config.js +43 -0
  9. package/build/core/asmail/delivery/common.d.ts +2 -2
  10. package/build/core/asmail/delivery/common.js +2 -1
  11. package/build/core/asmail/delivery/index.d.ts +2 -1
  12. package/build/core/asmail/delivery/index.js +4 -1
  13. package/build/core/asmail/delivery/per-recipient-wip.js +1 -1
  14. package/build/core/asmail/inbox/attachments/fs.d.ts +1 -1
  15. package/build/core/asmail/inbox/attachments/fs.js +2 -2
  16. package/build/core/asmail/inbox/index.d.ts +6 -6
  17. package/build/core/asmail/inbox/index.js +1 -1
  18. package/build/core/asmail/inbox/msg-indexing/index.d.ts +1 -1
  19. package/build/core/asmail/inbox/msg-indexing/logs-n-entries.d.ts +1 -1
  20. package/build/core/asmail/index.d.ts +4 -4
  21. package/build/core/asmail/index.js +11 -22
  22. package/build/core/asmail/key-verification.d.ts +5 -4
  23. package/build/core/asmail/key-verification.js +20 -10
  24. package/build/core/asmail/msg/common.d.ts +5 -4
  25. package/build/core/asmail/msg/opener.d.ts +4 -4
  26. package/build/core/asmail/msg/opener.js +1 -1
  27. package/build/core/asmail/msg/packer.d.ts +3 -3
  28. package/build/core/asmail/msg/packer.js +2 -2
  29. package/build/core/asmail/sending-params/index.d.ts +7 -6
  30. package/build/core/asmail/sending-params/index.js +21 -12
  31. package/build/core/asmail/sending-params/invitations-anon.d.ts +35 -0
  32. package/build/core/asmail/sending-params/invitations-anon.js +164 -0
  33. package/build/core/asmail/sending-params/own-params.d.ts +10 -19
  34. package/build/core/asmail/sending-params/own-params.js +27 -20
  35. package/build/core/asmail/sending-params/params-from-others.d.ts +7 -11
  36. package/build/core/asmail/sending-params/params-from-others.js +32 -23
  37. package/build/core/id-manager/index.d.ts +1 -1
  38. package/build/core/id-manager/key-storage.d.ts +1 -1
  39. package/build/core/index.d.ts +3 -0
  40. package/build/core/index.js +39 -11
  41. package/build/core/{asmail/keyring → keyring}/common.d.ts +3 -1
  42. package/build/core/{asmail/keyring → keyring}/common.js +2 -2
  43. package/build/core/{asmail/keyring → keyring}/correspondent-keys.d.ts +5 -3
  44. package/build/core/{asmail/keyring → keyring}/correspondent-keys.js +5 -5
  45. package/build/core/keyring/index.d.ts +72 -0
  46. package/build/core/{asmail/keyring → keyring}/index.js +68 -59
  47. package/build/core/{asmail/keyring → keyring}/keyring-storage.js +1 -1
  48. package/build/core/keyring/keyrings-cap-ipc.d.ts +5 -0
  49. package/build/core/keyring/keyrings-cap-ipc.js +50 -0
  50. package/build/core/keyring/published-intro-key.d.ts +43 -0
  51. package/build/core/keyring/published-intro-key.js +176 -0
  52. package/build/core/startup/sign-up.d.ts +1 -1
  53. package/build/core/storage/common/constants.d.ts +4 -0
  54. package/build/core/storage/common/constants.js +24 -0
  55. package/build/core/storage/common/obj-info-file.js +1 -1
  56. package/build/core/storage/index.d.ts +7 -1
  57. package/build/core/storage/index.js +33 -3
  58. package/build/core/storage/local/obj-files.d.ts +1 -1
  59. package/build/core/storage/local/obj-status.d.ts +1 -1
  60. package/build/core/storage/local/obj-status.js +1 -1
  61. package/build/core/storage/local/storage.d.ts +1 -1
  62. package/build/core/storage/local/storage.js +2 -2
  63. package/build/core/storage/synced/downloader.d.ts +2 -2
  64. package/build/core/storage/synced/obj-files.d.ts +3 -3
  65. package/build/core/storage/synced/obj-files.js +1 -1
  66. package/build/core/storage/synced/obj-status.d.ts +1 -1
  67. package/build/core/storage/synced/obj-status.js +1 -1
  68. package/build/core/storage/synced/remote-events.d.ts +2 -2
  69. package/build/core/storage/synced/storage.d.ts +2 -2
  70. package/build/core/storage/synced/storage.js +5 -5
  71. package/build/core/storage/synced/upload-header-file.d.ts +1 -1
  72. package/build/core/storage/synced/upsyncer.d.ts +1 -1
  73. package/build/core/storage/synced/upsyncer.js +1 -1
  74. package/build/core-ipc/common-caps.js +4 -0
  75. package/build/lib-client/3nstorage/{service.d.ts → storage-owner.d.ts} +1 -4
  76. package/build/lib-client/3nstorage/{service.js → storage-owner.js} +21 -25
  77. package/build/lib-client/asmail/recipient.d.ts +0 -3
  78. package/build/lib-client/asmail/recipient.js +19 -17
  79. package/build/lib-client/asmail/service-config.d.ts +9 -5
  80. package/build/lib-client/asmail/service-config.js +42 -17
  81. package/build/lib-client/cryptor/cryptor-in-worker.js +1 -1
  82. package/build/lib-client/cryptor/cryptor-wasm.js +1 -1
  83. package/build/lib-client/cryptor/cryptor.wasm +0 -0
  84. package/build/lib-client/cryptor/in-proc-js.js +1 -1
  85. package/build/lib-client/cryptor/in-proc-wasm.js +1 -1
  86. package/build/lib-client/fs-utils/fs-sync-utils.js +1 -1
  87. package/build/lib-client/key-derivation.d.ts +2 -1
  88. package/build/lib-client/objs-on-disk/obj-folders.d.ts +1 -1
  89. package/build/lib-client/objs-on-disk/obj-on-disk.d.ts +1 -1
  90. package/build/lib-client/request-utils.js +4 -2
  91. package/build/lib-client/service-locator.d.ts +2 -1
  92. package/build/lib-client/user-with-mid-session.d.ts +6 -5
  93. package/build/lib-client/user-with-mid-session.js +4 -4
  94. package/build/lib-client/{3nstorage/xsp-fs → xsp-fs}/attrs.js +3 -3
  95. package/build/lib-client/{3nstorage/xsp-fs → xsp-fs}/common.d.ts +2 -2
  96. package/build/lib-client/{3nstorage → xsp-fs}/exceptions.d.ts +1 -1
  97. package/build/lib-client/{3nstorage/xsp-fs → xsp-fs}/file-node.d.ts +1 -1
  98. package/build/lib-client/{3nstorage/xsp-fs → xsp-fs}/file-node.js +4 -4
  99. package/build/lib-client/{3nstorage/xsp-fs → xsp-fs}/file.d.ts +1 -1
  100. package/build/lib-client/{3nstorage/xsp-fs → xsp-fs}/file.js +5 -5
  101. package/build/lib-client/{3nstorage/xsp-fs → xsp-fs}/folder-node-serialization.js +3 -3
  102. package/build/lib-client/{3nstorage/xsp-fs → xsp-fs}/folder-node.d.ts +1 -1
  103. package/build/lib-client/{3nstorage/xsp-fs → xsp-fs}/folder-node.js +9 -9
  104. package/build/lib-client/{3nstorage/xsp-fs → xsp-fs}/fs.d.ts +1 -1
  105. package/build/lib-client/{3nstorage/xsp-fs → xsp-fs}/fs.js +6 -6
  106. package/build/lib-client/{3nstorage/xsp-fs → xsp-fs}/link-node.d.ts +1 -1
  107. package/build/lib-client/{3nstorage/xsp-fs → xsp-fs}/link-node.js +2 -2
  108. package/build/lib-client/{3nstorage/xsp-fs → xsp-fs}/node-in-fs.js +6 -6
  109. package/build/lib-client/{3nstorage/xsp-fs → xsp-fs}/node-persistence.js +4 -4
  110. package/build/lib-client/{3nstorage → xsp-fs}/util/file-based-json.d.ts +10 -4
  111. package/build/lib-client/{3nstorage → xsp-fs}/util/file-based-json.js +33 -15
  112. package/build/lib-client/{3nstorage/xsp-fs → xsp-fs}/xsp-payload-v1.js +3 -3
  113. package/build/lib-client/{3nstorage/xsp-fs → xsp-fs}/xsp-payload-v2.js +5 -5
  114. package/build/lib-common/jwkeys.d.ts +6 -106
  115. package/build/lib-common/jwkeys.js +4 -6
  116. package/build/lib-common/mid-sigs-NaCl-Ed.d.ts +4 -1
  117. package/build/lib-common/service-api/asmail/config.d.ts +9 -30
  118. package/build/lib-common/service-api/asmail/config.js +4 -1
  119. package/build/lib-common/service-api/asmail/delivery.d.ts +5 -12
  120. package/build/lib-common/service-api/asmail/delivery.js +3 -0
  121. package/build/lib-common/service-api/mailer-id/login.d.ts +3 -6
  122. package/build/lib-common/service-api/mailer-id/provisioning.d.ts +6 -7
  123. package/build/lib-common/service-api/mailer-id/provisioning.js +3 -0
  124. package/build/lib-common/user-admin-api/signup.d.ts +2 -1
  125. package/build/raw-3nweb-clients.d.ts +1 -1
  126. package/build/raw-3nweb-clients.js +2 -2
  127. package/package.json +2 -2
  128. package/build/core/asmail/config/common.d.ts +0 -24
  129. package/build/core/asmail/config/common.js +0 -87
  130. package/build/core/asmail/config/index.d.ts +0 -47
  131. package/build/core/asmail/config/index.js +0 -69
  132. package/build/core/asmail/config/invitations-anon.d.ts +0 -13
  133. package/build/core/asmail/config/invitations-anon.js +0 -99
  134. package/build/core/asmail/config/published-intro-key.d.ts +0 -17
  135. package/build/core/asmail/config/published-intro-key.js +0 -104
  136. package/build/core/asmail/keyring/index.d.ts +0 -36
  137. /package/build/core/{asmail/keyring → keyring}/id-to-email-map.d.ts +0 -0
  138. /package/build/core/{asmail/keyring → keyring}/id-to-email-map.js +0 -0
  139. /package/build/core/{asmail/keyring → keyring}/keyring-storage.d.ts +0 -0
  140. /package/build/lib-client/{cryptor-work-labels.d.ts → cryptor/cryptor-work-labels.d.ts} +0 -0
  141. /package/build/lib-client/{cryptor-work-labels.js → cryptor/cryptor-work-labels.js} +0 -0
  142. /package/build/lib-client/{3nstorage/xsp-fs → xsp-fs}/attrs.d.ts +0 -0
  143. /package/build/lib-client/{3nstorage/xsp-fs → xsp-fs}/common.js +0 -0
  144. /package/build/lib-client/{3nstorage → xsp-fs}/exceptions.js +0 -0
  145. /package/build/lib-client/{3nstorage/xsp-fs → xsp-fs}/folder-node-serialization.d.ts +0 -0
  146. /package/build/lib-client/{3nstorage/xsp-fs → xsp-fs}/node-in-fs.d.ts +0 -0
  147. /package/build/lib-client/{3nstorage/xsp-fs → xsp-fs}/node-persistence.d.ts +0 -0
  148. /package/build/lib-client/{3nstorage → xsp-fs}/util/for-arrays.d.ts +0 -0
  149. /package/build/lib-client/{3nstorage → xsp-fs}/util/for-arrays.js +0 -0
  150. /package/build/lib-client/{3nstorage/xsp-fs → xsp-fs}/xsp-payload-v1.d.ts +0 -0
  151. /package/build/lib-client/{3nstorage/xsp-fs → xsp-fs}/xsp-payload-v2.d.ts +0 -0
@@ -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, 2025 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
@@ -19,14 +19,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
19
19
  exports.ASMail = void 0;
20
20
  const inbox_1 = require("./inbox");
21
21
  const error_1 = require("../../lib-common/exceptions/error");
22
- const keyring_1 = require("./keyring");
23
- const config_1 = require("./config");
24
22
  const delivery_1 = require("./delivery");
25
23
  const sending_params_1 = require("./sending-params");
26
24
  const fs_sync_utils_1 = require("../../lib-client/fs-utils/fs-sync-utils");
27
- const KEYRING_DATA_FOLDER = 'keyring';
28
25
  const INBOX_DATA_FOLDER = 'inbox';
29
- const CONFIG_DATA_FOLDER = 'config';
30
26
  const DELIVERY_DATA_FOLDER = 'delivery';
31
27
  const SEND_PARAMS_DATA_FOLDER = 'sending-params';
32
28
  class ASMail {
@@ -43,15 +39,13 @@ class ASMail {
43
39
  this.sendingParams = undefined;
44
40
  Object.seal(this);
45
41
  }
46
- async init(address, getSigner, syncedFS, localFS, getStorages, makeResolver) {
42
+ async init(address, getSigner, syncedFS, localFS, getStorages, makeResolver, config, keyring) {
47
43
  try {
48
44
  this.address = address;
49
45
  await (0, fs_sync_utils_1.getRemoteFolderChanges)(syncedFS);
50
- await this.setupConfig(getSigner, syncedFS, makeResolver('asmail'));
51
- await Promise.all([
52
- this.setupKeyring(syncedFS),
53
- this.setupSendingParams(syncedFS)
54
- ]);
46
+ this.config = config;
47
+ this.keyring = keyring;
48
+ await this.setupSendingParams(syncedFS);
55
49
  await Promise.all([
56
50
  this.setupInbox(syncedFS, getSigner, getStorages, makeResolver),
57
51
  this.setupDelivery(localFS, getSigner, makeResolver)
@@ -64,17 +58,9 @@ class ASMail {
64
58
  throw (0, error_1.errWithCause)(err, 'Failed to initialize ASMail');
65
59
  }
66
60
  }
67
- async setupConfig(getSigner, syncedFS, resolver) {
68
- const fs = await (0, fs_sync_utils_1.getOrMakeAndUploadFolderIn)(syncedFS, CONFIG_DATA_FOLDER);
69
- this.config = await config_1.ConfigOfASMailServer.makeAndStart(this.address, getSigner, resolver, this.makeNet(), fs);
70
- }
71
- async setupKeyring(syncedFS) {
72
- const fs = await (0, fs_sync_utils_1.getOrMakeAndUploadFolderIn)(syncedFS, KEYRING_DATA_FOLDER);
73
- this.keyring = await (0, keyring_1.makeAndKeyRing)(this.cryptor, fs, this.config.publishedKeys);
74
- }
75
61
  async setupSendingParams(syncedFS) {
76
62
  const fs = await (0, fs_sync_utils_1.getOrMakeAndUploadFolderIn)(syncedFS, SEND_PARAMS_DATA_FOLDER);
77
- this.sendingParams = await sending_params_1.SendingParamsHolder.makeAndStart(fs, this.config.anonSenderInvites);
63
+ this.sendingParams = await sending_params_1.SendingParamsHolder.makeAndInit(fs, this.config.makeParamSetterAndGetter('anon-sender/invites'));
78
64
  }
79
65
  async setupDelivery(localFS, getSigner, makeResolver) {
80
66
  const fs = await localFS.writableSubRoot(DELIVERY_DATA_FOLDER);
@@ -119,15 +105,18 @@ class ASMail {
119
105
  makeASMailCAP() {
120
106
  const w = {
121
107
  getUserId: async () => this.address,
122
- delivery: this.delivery.wrap(),
123
- inbox: this.inbox.wrap(),
108
+ delivery: this.delivery.makeCAP(),
109
+ inbox: this.inbox.makeCAP(),
110
+ config: this.config.makeCAP()
124
111
  };
125
112
  return Object.freeze(w);
126
113
  }
127
114
  ;
128
115
  async close() {
129
116
  await this.inbox.close();
117
+ await this.delivery.close();
130
118
  await this.keyring.close();
119
+ await this.sendingParams.close();
131
120
  }
132
121
  }
133
122
  exports.ASMail = ASMail;
@@ -1,7 +1,7 @@
1
- import { JsonKey } from '../../lib-common/jwkeys';
2
- import * as confApi from '../../lib-common/service-api/asmail/config';
3
1
  import { ServiceLocator } from '../../lib-client/service-locator';
4
2
  import { NetClient } from '../../lib-client/request-utils';
3
+ type JsonKey = web3n.keys.JsonKey;
4
+ type PKeyCertChain = web3n.keys.PKeyCertChain;
5
5
  /**
6
6
  * This returns a promise, resolvable to public key, when certificates'
7
7
  * verification is successful, and rejectable in all other cases.
@@ -11,7 +11,7 @@ import { NetClient } from '../../lib-client/request-utils';
11
11
  * It is an error, if certs contain a different address.
12
12
  * @param certs is an object with a MailerId certificates chain for a public key
13
13
  */
14
- export declare function checkAndExtractPKey(client: NetClient, resolver: ServiceLocator, address: string, certs: confApi.p.initPubKey.Certs): Promise<JsonKey>;
14
+ export declare function checkAndExtractPKey(client: NetClient, resolver: ServiceLocator, address: string, certs: PKeyCertChain): Promise<JsonKey>;
15
15
  /**
16
16
  * This returns a promise, resolvable to public key and related address, when
17
17
  * certificates' verification is successful, and rejectable in all other cases.
@@ -20,7 +20,8 @@ export declare function checkAndExtractPKey(client: NetClient, resolver: Service
20
20
  * @param certs is an object with a MailerId certificates chain for a public key
21
21
  * @param validAt is epoch in seconds (!), for which certificates must be valid
22
22
  */
23
- export declare function checkAndExtractPKeyWithAddress(client: NetClient, resolver: ServiceLocator, certs: confApi.p.initPubKey.Certs, validAt: number): Promise<{
23
+ export declare function checkAndExtractPKeyWithAddress(client: NetClient, resolver: ServiceLocator, certs: PKeyCertChain, validAt: number): Promise<{
24
24
  pkey: JsonKey;
25
25
  address: string;
26
26
  }>;
27
+ export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- Copyright (C) 2016 - 2017 3NSoft Inc.
3
+ Copyright (C) 2016 - 2017, 2025 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
@@ -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.checkAndExtractPKey = checkAndExtractPKey;
19
20
  exports.checkAndExtractPKeyWithAddress = checkAndExtractPKeyWithAddress;
@@ -34,13 +35,25 @@ async function checkAndExtractPKey(client, resolver, address, certs) {
34
35
  address = (0, canonical_address_1.toCanonicalAddress)(address);
35
36
  const validAt = Math.round(Date.now() / 1000);
36
37
  // get MailerId provider's info with a root certificate(s)
37
- const data = await (0, service_locator_1.getMailerIdInfoFor)(resolver, client, address);
38
- // TODO choose proper root certificate, as it may not be current one
39
- const rootAddr = data.domain;
40
- const rootCert = data.info.currentCert;
38
+ const { domain: rootAddr, rootCert } = await getRootCertForKey(certs.provCert.kid, resolver, client, address);
41
39
  const pkey = mid_sigs_NaCl_Ed_1.relyingParty.verifyPubKey(certs.pkeyCert, address, { user: certs.userCert, prov: certs.provCert, root: rootCert }, rootAddr, validAt);
42
40
  return pkey;
43
41
  }
42
+ async function getRootCertForKey(kid, resolver, client, address) {
43
+ const { domain, info: { currentCert, previousCerts } } = await (0, service_locator_1.getMailerIdInfoFor)(resolver, client, address);
44
+ let rootCert;
45
+ if (currentCert.kid === kid) {
46
+ rootCert = currentCert;
47
+ }
48
+ else {
49
+ const pastCert = previousCerts.find((cert) => (cert.kid === kid));
50
+ if (!pastCert) {
51
+ throw new Error(`Root cert for given key id is not found in server's reply.`);
52
+ }
53
+ rootCert = pastCert;
54
+ }
55
+ return { domain, rootCert };
56
+ }
44
57
  /**
45
58
  * This returns a promise, resolvable to public key and related address, when
46
59
  * certificates' verification is successful, and rejectable in all other cases.
@@ -62,10 +75,7 @@ async function checkAndExtractPKeyWithAddress(client, resolver, certs, validAt)
62
75
  throw (0, mid_sigs_NaCl_Ed_1.makeMalformedCertsException)(`Cannot read public key certificate`, err);
63
76
  }
64
77
  // get MailerId provider's info with a root certificate(s)
65
- const data = await (0, service_locator_1.getMailerIdInfoFor)(resolver, client, address);
66
- // TODO choose proper root certificate, as it may not be current one
67
- const rootAddr = data.domain;
68
- const rootCert = data.info.currentCert;
78
+ const { domain: rootAddr, rootCert } = await getRootCertForKey(certs.provCert.kid, resolver, client, address);
69
79
  const pkey = mid_sigs_NaCl_Ed_1.relyingParty.verifyPubKey(certs.pkeyCert, address, { user: certs.userCert, prov: certs.provCert, root: rootCert }, rootAddr, validAt);
70
80
  return { address, pkey };
71
81
  }
@@ -1,6 +1,6 @@
1
- import { JsonKeyShort } from '../../../lib-common/jwkeys';
2
- import { FolderInJSON } from '../../../lib-client/3nstorage/xsp-fs/common';
3
- import * as confApi from '../../../lib-common/service-api/asmail/config';
1
+ import { FolderInJSON } from '../../../lib-client/xsp-fs/common';
2
+ type JsonKeyShort = web3n.keys.JsonKeyShort;
3
+ type PKeyCertChain = web3n.keys.PKeyCertChain;
4
4
  /**
5
5
  * Metadata for message that uses established key pair.
6
6
  * It is an unencrypted part of a message.
@@ -67,7 +67,8 @@ export interface MainBody {
67
67
  */
68
68
  export interface FlowParams {
69
69
  msgCount: number;
70
- introCerts?: confApi.p.initPubKey.Certs;
70
+ introCerts?: PKeyCertChain;
71
71
  nextCrypto?: SuggestedNextKeyPair;
72
72
  nextSendingParams?: SendingParams;
73
73
  }
74
+ export {};
@@ -1,9 +1,9 @@
1
- import * as confApi from '../../../lib-common/service-api/asmail/config';
2
1
  import { MsgEnvelope, MainBody, SuggestedNextKeyPair, SendingParams } from './common';
3
2
  import { AsyncSBoxCryptor, ObjSource } from 'xsp-files';
4
- import { FolderInJSON } from '../../../lib-client/3nstorage/xsp-fs/common';
5
- import { MsgKeyRole } from '../keyring';
3
+ import { FolderInJSON } from '../../../lib-client/xsp-fs/common';
4
+ import { MsgKeyRole } from '../../keyring';
6
5
  export { SuggestedNextKeyPair } from './common';
6
+ type PKeyCertChain = web3n.keys.PKeyCertChain;
7
7
  export declare class OpenedMsg {
8
8
  msgId: string;
9
9
  private main;
@@ -17,7 +17,7 @@ export declare class OpenedMsg {
17
17
  get nextCrypto(): SuggestedNextKeyPair | undefined;
18
18
  get msgCount(): number;
19
19
  get nextSendingParams(): SendingParams | undefined;
20
- get introCryptoCerts(): confApi.p.initPubKey.Certs;
20
+ get introCryptoCerts(): PKeyCertChain;
21
21
  get attachmentsJSON(): FolderInJSON | undefined;
22
22
  }
23
23
  export declare function openMsg(msgId: string, mainObjId: string, mainObj: ObjSource, headerOfs: number, fKey: Uint8Array, cryptor: AsyncSBoxCryptor): Promise<OpenedMsg>;
@@ -21,7 +21,7 @@ exports.openMsg = openMsg;
21
21
  const buffer_utils_1 = require("../../../lib-common/buffer-utils");
22
22
  const error_1 = require("../../../lib-common/exceptions/error");
23
23
  const xsp_files_1 = require("xsp-files");
24
- const cryptor_work_labels_1 = require("../../../lib-client/cryptor-work-labels");
24
+ const cryptor_work_labels_1 = require("../../../lib-client/cryptor/cryptor-work-labels");
25
25
  class OpenedMsg {
26
26
  constructor(msgId, main) {
27
27
  this.msgId = msgId;
@@ -1,11 +1,11 @@
1
1
  import { AsyncSBoxCryptor, ObjSource } from 'xsp-files';
2
2
  import * as delivApi from '../../../lib-common/service-api/asmail/delivery';
3
- import { FolderInJSON } from '../../../lib-client/3nstorage/xsp-fs/common';
4
- import * as confApi from '../../../lib-common/service-api/asmail/config';
3
+ import { FolderInJSON } from '../../../lib-client/xsp-fs/common';
5
4
  import { MsgEnvelope, SuggestedNextKeyPair, SendingParams } from './common';
6
5
  import { Encryptor } from '../../../lib-common/async-cryptor-wrap';
7
6
  type FS = web3n.files.FS;
8
7
  type AttachmentsContainer = web3n.asmail.AttachmentsContainer;
8
+ type PKeyCertChain = web3n.keys.PKeyCertChain;
9
9
  /**
10
10
  * This contains complete information of ids and keys set in the message during
11
11
  * packing. This information can is used to continue message sending after app's
@@ -114,7 +114,7 @@ export declare class MsgPacker {
114
114
  * This value goes into flow parameters section that sits in encrypted main
115
115
  * part of the message.
116
116
  */
117
- setNewKeyInfo(recipientKid: string, senderPKey: string, pkeyCerts: confApi.p.initPubKey.Certs, msgCount: number): void;
117
+ setNewKeyInfo(recipientKid: string, senderPKey: string, pkeyCerts: PKeyCertChain, msgCount: number): void;
118
118
  setNextCrypto(pair: SuggestedNextKeyPair): void;
119
119
  setNextSendingParams(params: SendingParams): void;
120
120
  setAttachments(att: {
@@ -21,10 +21,10 @@ const ecma_nacl_1 = require("ecma-nacl");
21
21
  const xsp_files_1 = require("xsp-files");
22
22
  const random = require("../../../lib-common/random-node");
23
23
  const buffer_utils_1 = require("../../../lib-common/buffer-utils");
24
- const folder_node_serialization_1 = require("../../../lib-client/3nstorage/xsp-fs/folder-node-serialization");
24
+ const folder_node_serialization_1 = require("../../../lib-client/xsp-fs/folder-node-serialization");
25
25
  const json_utils_1 = require("../../../lib-common/json-utils");
26
26
  const attachments_container_1 = require("./attachments-container");
27
- const cryptor_work_labels_1 = require("../../../lib-client/cryptor-work-labels");
27
+ const cryptor_work_labels_1 = require("../../../lib-client/cryptor/cryptor-work-labels");
28
28
  function turnKeysToB64(obj) {
29
29
  obj.key = buffer_utils_1.base64.pack(obj.key);
30
30
  if (!obj.folder) {
@@ -1,21 +1,22 @@
1
1
  import { ResourcesForSending } from '../delivery/common';
2
- import { ConfigOfASMailServer } from '../config/index';
3
2
  import { ResourcesForReceiving } from '../inbox';
3
+ import { ParamOnServer } from '../../../lib-client/asmail/service-config';
4
4
  export { SendingParams } from './params-from-others';
5
5
  type WritableFS = web3n.files.WritableFS;
6
6
  type SendingResources = ResourcesForSending['correspondents'];
7
7
  type ReceptionResources = ResourcesForReceiving['correspondents'];
8
8
  export declare class SendingParamsHolder {
9
- private paramsFromOthers;
10
- private ownParams;
11
- thisSide: {
9
+ private readonly paramsFromOthers;
10
+ private readonly ownParams;
11
+ readonly thisSide: {
12
12
  getUpdated: SendingResources['newParamsForSendingReplies'];
13
13
  setAsUsed: ReceptionResources['markOwnSendingParamsAsUsed'];
14
14
  };
15
- otherSides: {
15
+ readonly otherSides: {
16
16
  get: SendingResources['paramsForSendingTo'];
17
17
  set: ReceptionResources['saveParamsForSendingTo'];
18
18
  };
19
19
  private constructor();
20
- static makeAndStart(fs: WritableFS, anonSenderInvites: ConfigOfASMailServer['anonSenderInvites']): Promise<SendingParamsHolder>;
20
+ static makeAndInit(fs: WritableFS, anonInvitesOnServer: ParamOnServer<'anon-sender/invites'>): Promise<SendingParamsHolder>;
21
+ close(): Promise<void>;
21
22
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- Copyright (C) 2017 - 2018 3NSoft Inc.
3
+ Copyright (C) 2017 - 2018, 2025 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
@@ -13,17 +13,20 @@
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.SendingParamsHolder = void 0;
19
20
  const params_from_others_1 = require("./params-from-others");
20
21
  const own_params_1 = require("./own-params");
22
+ const invitations_anon_1 = require("./invitations-anon");
21
23
  const PARAMS_FROM_OTHERS_FILE = 'params-from-others.json';
22
24
  const OWN_PARAMS_FILE = 'own-params.json';
25
+ const ANONYM_INVITES_FILE = 'anonymous-invites.json';
23
26
  class SendingParamsHolder {
24
- constructor(anonSenderInvites) {
25
- this.paramsFromOthers = new params_from_others_1.ParamsFromOthers();
26
- this.ownParams = new own_params_1.OwnSendingParams(anonSenderInvites);
27
+ constructor(paramsFromOthers, ownParams) {
28
+ this.paramsFromOthers = paramsFromOthers;
29
+ this.ownParams = ownParams;
27
30
  this.otherSides = {
28
31
  get: this.paramsFromOthers.getFor,
29
32
  set: this.paramsFromOthers.setFor
@@ -34,16 +37,22 @@ class SendingParamsHolder {
34
37
  };
35
38
  Object.freeze(this);
36
39
  }
37
- static async makeAndStart(fs, anonSenderInvites) {
38
- const h = new SendingParamsHolder(anonSenderInvites);
39
- await Promise.all([
40
+ static async makeAndInit(fs, anonInvitesOnServer) {
41
+ const [paramsFromOthers, ownParams] = await Promise.all([
40
42
  fs.writableFile(PARAMS_FROM_OTHERS_FILE)
41
- .then(f => h.paramsFromOthers.start(f)),
42
- fs.writableFile(OWN_PARAMS_FILE)
43
- .then(f => h.ownParams.start(f))
43
+ .then(f => params_from_others_1.ParamsFromOthers.makeAndInit(f)),
44
+ fs.writableFile(ANONYM_INVITES_FILE)
45
+ .then(async (anonInvitesFile) => {
46
+ const anonInvites = await invitations_anon_1.AnonymousInvites.makeAndInit(anonInvitesFile, anonInvitesOnServer);
47
+ return await own_params_1.OwnSendingParams.makeAndInit(await fs.writableFile(OWN_PARAMS_FILE), anonInvites);
48
+ })
44
49
  ]);
45
50
  await fs.close();
46
- return h;
51
+ return new SendingParamsHolder(paramsFromOthers, ownParams);
52
+ }
53
+ async close() {
54
+ await this.ownParams.close();
55
+ await this.paramsFromOthers.close();
47
56
  }
48
57
  }
49
58
  exports.SendingParamsHolder = SendingParamsHolder;
@@ -0,0 +1,35 @@
1
+ import { ParamOnServer } from '../../../lib-client/asmail/service-config';
2
+ type WritableFile = web3n.files.WritableFile;
3
+ interface InvitesJSON {
4
+ invites: {
5
+ [invite: string]: {
6
+ label: string;
7
+ msgMaxSize: number;
8
+ };
9
+ };
10
+ }
11
+ export declare class AnonymousInvites {
12
+ private readonly anonInvitesOnServer;
13
+ private invites;
14
+ private readonly fileProc;
15
+ private constructor();
16
+ static makeAndInit(file: WritableFile, anonInvitesOnServer: ParamOnServer<'anon-sender/invites'>): Promise<AnonymousInvites>;
17
+ private onFileEvent;
18
+ protected setFromJSON(json: InvitesJSON): void;
19
+ private toFileJSON;
20
+ private persist;
21
+ private absorbRemoteChanges;
22
+ private toServerParam;
23
+ private toServiceJSON;
24
+ private syncServiceSetting;
25
+ getAll(): Map<string, {
26
+ invite: string;
27
+ msgMaxSize: number;
28
+ }>;
29
+ create(label: string, msgMaxSize: number): Promise<string>;
30
+ private generateNewRandomInvite;
31
+ private findByLabel;
32
+ setMsgMaxSize(label: string, msgMaxSize: number): Promise<void>;
33
+ close(): Promise<void>;
34
+ }
35
+ export {};
@@ -0,0 +1,164 @@
1
+ "use strict";
2
+ /*
3
+ Copyright (C) 2015 - 2018, 2025 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.AnonymousInvites = void 0;
20
+ const random = require("../../../lib-common/random-node");
21
+ const file_based_json_1 = require("../../../lib-client/xsp-fs/util/file-based-json");
22
+ const json_utils_1 = require("../../../lib-common/json-utils");
23
+ const INVITE_TOKEN_LEN = 40;
24
+ class AnonymousInvites {
25
+ constructor(anonInvitesOnServer) {
26
+ this.anonInvitesOnServer = anonInvitesOnServer;
27
+ this.invites = {};
28
+ this.fileProc = new file_based_json_1.JsonFileProc(this.onFileEvent.bind(this));
29
+ Object.seal(this);
30
+ }
31
+ static async makeAndInit(file, anonInvitesOnServer) {
32
+ const anonInvites = new AnonymousInvites(anonInvitesOnServer);
33
+ await anonInvites.fileProc.start(file, () => anonInvites.toFileJSON());
34
+ await anonInvites.absorbRemoteChanges();
35
+ await anonInvites.syncServiceSetting();
36
+ return anonInvites;
37
+ }
38
+ async onFileEvent(ev) {
39
+ if (ev.src === 'local') {
40
+ return;
41
+ }
42
+ switch (ev.type) {
43
+ case 'file-change':
44
+ await this.fileProc.order.startOrChain(() => this.absorbRemoteChanges());
45
+ break;
46
+ case 'removed':
47
+ throw new Error(`Unexpected removal of file with parameter "anon-sender/invites"`);
48
+ default:
49
+ return;
50
+ }
51
+ }
52
+ setFromJSON(json) {
53
+ this.invites = json.invites;
54
+ }
55
+ toFileJSON() {
56
+ return {
57
+ invites: this.invites
58
+ };
59
+ }
60
+ async persist() {
61
+ await this.fileProc.order.startOrChain(async () => {
62
+ await this.anonInvitesOnServer.setOnServer(this.toServerParam());
63
+ await this.fileProc.save(this.toFileJSON(), false);
64
+ });
65
+ }
66
+ async absorbRemoteChanges() {
67
+ // XXX
68
+ // - check for changes: what is needed here from fileProc, and what is
69
+ // generic in absorbing remote changes to refactor it into JsonFileProc
70
+ // - absorb and sync, if needed: what can be in JsonFileProc
71
+ // Code from pre-v.sync:
72
+ // const { json } = await this.fileProc.get();
73
+ // this.setFromJSON(json);
74
+ }
75
+ toServerParam() {
76
+ const serverParam = {};
77
+ for (const [invite, { msgMaxSize }] of Object.entries(this.invites)) {
78
+ serverParam[invite] = msgMaxSize;
79
+ }
80
+ return serverParam;
81
+ }
82
+ toServiceJSON() {
83
+ const serverJSON = {};
84
+ Object.entries(this.invites)
85
+ .forEach(([invite, params]) => {
86
+ serverJSON[invite] = params.msgMaxSize;
87
+ });
88
+ return serverJSON;
89
+ }
90
+ async syncServiceSetting() {
91
+ // XXX we may have the following bug here:
92
+ // Device with older version of param gets to this point, and sets older
93
+ // value.
94
+ // To protect aginst this case, absorbing from file must ensure highest
95
+ // synced version is read.
96
+ const infoOnServer = await this.anonInvitesOnServer.getFromServer()
97
+ .catch((exc) => {
98
+ if (exc.type === 'http-connect') {
99
+ return;
100
+ }
101
+ else {
102
+ throw exc;
103
+ }
104
+ });
105
+ const currentVal = this.toServiceJSON();
106
+ if (!(0, json_utils_1.deepEqual)(infoOnServer, currentVal)) {
107
+ await this.anonInvitesOnServer.setOnServer(currentVal);
108
+ }
109
+ }
110
+ getAll() {
111
+ const byLabel = new Map();
112
+ Object.entries(this.invites)
113
+ .forEach(([invite, params]) => {
114
+ byLabel.set(params.label, { invite, msgMaxSize: params.msgMaxSize });
115
+ });
116
+ return byLabel;
117
+ }
118
+ ;
119
+ async create(label, msgMaxSize) {
120
+ const existingInvite = this.findByLabel(label);
121
+ if (existingInvite) {
122
+ throw new Error(`Anonymous sender invite already exists with label ${label}`);
123
+ }
124
+ const invite = await this.generateNewRandomInvite();
125
+ this.invites[invite] = { label, msgMaxSize };
126
+ try {
127
+ await this.persist();
128
+ return invite;
129
+ }
130
+ catch (exc) {
131
+ delete this.invites[invite];
132
+ throw exc;
133
+ }
134
+ }
135
+ ;
136
+ async generateNewRandomInvite() {
137
+ let invite;
138
+ do {
139
+ invite = await random.stringOfB64Chars(INVITE_TOKEN_LEN);
140
+ } while (this.invites[invite]);
141
+ return invite;
142
+ }
143
+ findByLabel(label) {
144
+ const found = Object.entries(this.invites)
145
+ .find(([_, params]) => (params.label === label));
146
+ return (found ? found[0] : undefined);
147
+ }
148
+ async setMsgMaxSize(label, msgMaxSize) {
149
+ const invite = this.findByLabel(label);
150
+ if (!invite) {
151
+ throw new Error(`There is no anonymous sender invite with label ${label}`);
152
+ }
153
+ this.invites[invite].msgMaxSize = msgMaxSize;
154
+ await this.persist();
155
+ }
156
+ ;
157
+ async close() {
158
+ await this.fileProc.close();
159
+ }
160
+ }
161
+ exports.AnonymousInvites = AnonymousInvites;
162
+ Object.freeze(AnonymousInvites.prototype);
163
+ Object.freeze(AnonymousInvites);
164
+ Object.freeze(exports);
@@ -1,37 +1,28 @@
1
- import { JsonFileProc } from '../../../lib-client/3nstorage/util/file-based-json';
2
- import { SendingParams } from '../msg/common';
3
- import { ConfigOfASMailServer } from '../config/index';
4
- import { SendingParamsHolder } from '../sending-params';
1
+ import { SendingParamsHolder } from './index';
2
+ import { AnonymousInvites } from './invitations-anon';
5
3
  type ExposedFuncs = SendingParamsHolder['thisSide'];
6
4
  type WritableFile = web3n.files.WritableFile;
7
5
  type FileEvent = web3n.files.FileEvent;
8
- interface ParamsForAcceptingMsgs {
9
- address: string;
10
- suggested?: SendingParams;
11
- inUse?: SendingParams;
12
- }
13
- interface PersistedJSON {
14
- default?: SendingParams;
15
- senderSpecific: ParamsForAcceptingMsgs[];
16
- }
17
6
  /**
18
7
  * Instance of this class keeps track of sending parameters, which user gives to
19
8
  * other correspondents for sending messages back. These parameters may have
20
9
  * invitation tokens, and this class uses config service to register tokens on
21
10
  * a server.
22
11
  */
23
- export declare class OwnSendingParams extends JsonFileProc<PersistedJSON> {
24
- private anonInvites;
25
- private params;
12
+ export declare class OwnSendingParams {
13
+ private readonly anonInvites;
14
+ private readonly params;
26
15
  private defaultParams;
27
- private changesProc;
28
- constructor(anonInvites: ConfigOfASMailServer['anonSenderInvites']);
29
- start(file: WritableFile): Promise<void>;
16
+ private readonly fileProc;
17
+ private constructor();
18
+ static makeAndInit(file: WritableFile, anonInvites: AnonymousInvites): Promise<OwnSendingParams>;
30
19
  private setDefaultParams;
20
+ private toFileJSON;
31
21
  private persist;
32
22
  private absorbChangesFromFile;
33
23
  protected onFileEvent(ev: FileEvent): Promise<void>;
34
24
  getFor: ExposedFuncs['getUpdated'];
35
25
  setAsInUse: ExposedFuncs['setAsUsed'];
26
+ close(): Promise<void>;
36
27
  }
37
28
  export {};