core-3nweb-client-lib 0.35.0 → 0.35.2

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.
@@ -121,7 +121,7 @@ declare namespace web3n.keys {
121
121
 
122
122
  interface Keyrings {
123
123
 
124
- introKeyToPublishOnASMailServer: IntroKeyOnASMailServer;
124
+ introKeyOnASMailServer: IntroKeyOnASMailServer;
125
125
 
126
126
  }
127
127
 
@@ -129,13 +129,13 @@ declare namespace web3n.keys {
129
129
 
130
130
  /**
131
131
  * Returns introductory key certificates chain that should be published on
132
- * ASMail server, and undefined, if there should be nothing on the server.
132
+ * ASMail server, and null, if there should be nothing on the server.
133
133
  */
134
- getCurrent(): Promise<PKeyCertChain|undefined>;
134
+ getCurrent(): Promise<PKeyCertChain|null>;
135
135
 
136
136
  remove(): Promise<void>;
137
137
 
138
- makeNew(): Promise<PKeyCertChain>;
138
+ makeAndPublishNew(): Promise<PKeyCertChain>;
139
139
 
140
140
  }
141
141
 
@@ -568,8 +568,8 @@ function callConfig(caller, objPath, method) {
568
568
  }
569
569
  function makeConfigCaller(caller, objPath) {
570
570
  return {
571
- getOnServer: callConfig(caller, objPath.concat('getOnServer'), 'getOnServer'),
572
- setOnServer: callConfig(caller, objPath.concat('setOnServer'), 'setOnServer')
571
+ getOnServer: callConfig(caller, objPath, 'getOnServer'),
572
+ setOnServer: callConfig(caller, objPath, 'setOnServer')
573
573
  };
574
574
  }
575
575
  Object.freeze(exports);
@@ -32,7 +32,10 @@ class ConfigOfASMailServer {
32
32
  makeCAP() {
33
33
  const w = {
34
34
  getOnServer: this.serverConfig.getParam.bind(this.serverConfig),
35
- setOnServer: this.serverConfig.setParam.bind(this.serverConfig)
35
+ setOnServer: async (param, value) => {
36
+ ensureParameterCanBeSetDirectly(param);
37
+ this.serverConfig.setParam(param, value);
38
+ }
36
39
  };
37
40
  return Object.freeze(w);
38
41
  }
@@ -40,4 +43,12 @@ class ConfigOfASMailServer {
40
43
  exports.ConfigOfASMailServer = ConfigOfASMailServer;
41
44
  Object.freeze(ConfigOfASMailServer.prototype);
42
45
  Object.freeze(ConfigOfASMailServer);
46
+ function ensureParameterCanBeSetDirectly(param) {
47
+ switch (param) {
48
+ case 'init-pub-key':
49
+ throw new Error(`Parameter ${param} can't be set directly to server`);
50
+ default:
51
+ return;
52
+ }
53
+ }
43
54
  Object.freeze(exports);
@@ -318,11 +318,7 @@ class Keyrings {
318
318
  }
319
319
  makeKeyringsCAP() {
320
320
  const w = {
321
- introKeyToPublishOnASMailServer: {
322
- getCurrent: async () => { throw new Error(`not implemented, yet`); },
323
- makeNew: async () => { throw new Error(`not implemented, yet`); },
324
- remove: async () => { throw new Error(`not implemented, yet`); }
325
- }
321
+ introKeyOnASMailServer: this.publishedKeys.makeIntroKeyCAP(),
326
322
  };
327
323
  return Object.freeze(w);
328
324
  }
@@ -22,13 +22,13 @@ const caller_side_wrap_1 = require("../../core-ipc/json-ipc-wrapping/caller-side
22
22
  const service_side_wrap_1 = require("../../core-ipc/json-ipc-wrapping/service-side-wrap");
23
23
  function exposeKeyringsCAP(cap) {
24
24
  return {
25
- introKeyToPublishOnASMailServer: exposeIntroKey(cap.introKeyToPublishOnASMailServer),
25
+ introKeyOnASMailServer: exposeIntroKey(cap.introKeyOnASMailServer),
26
26
  };
27
27
  }
28
28
  function exposeIntroKey(cap) {
29
29
  return {
30
30
  getCurrent: (0, service_side_wrap_1.wrapReqReplySrvMethod)(cap, 'getCurrent'),
31
- makeNew: (0, service_side_wrap_1.wrapReqReplySrvMethod)(cap, 'makeNew'),
31
+ makeAndPublishNew: (0, service_side_wrap_1.wrapReqReplySrvMethod)(cap, 'makeAndPublishNew'),
32
32
  remove: (0, service_side_wrap_1.wrapReqReplySrvMethod)(cap, 'remove'),
33
33
  };
34
34
  }
@@ -37,14 +37,14 @@ function callIntroKeyOnASMailServer(caller, objPath, method) {
37
37
  }
38
38
  function makeIntroKeyCaller(caller, objPath) {
39
39
  return {
40
- getCurrent: callIntroKeyOnASMailServer(caller, objPath.concat('getCurrent'), 'getCurrent'),
41
- makeNew: callIntroKeyOnASMailServer(caller, objPath.concat('makeNew'), 'makeNew'),
42
- remove: callIntroKeyOnASMailServer(caller, objPath.concat('remove'), 'remove'),
40
+ getCurrent: callIntroKeyOnASMailServer(caller, objPath, 'getCurrent'),
41
+ makeAndPublishNew: callIntroKeyOnASMailServer(caller, objPath, 'makeAndPublishNew'),
42
+ remove: callIntroKeyOnASMailServer(caller, objPath, 'remove'),
43
43
  };
44
44
  }
45
45
  function makeKeyringsCaller(caller, objPath) {
46
46
  return {
47
- introKeyToPublishOnASMailServer: makeIntroKeyCaller(caller, objPath.concat('introKeyOnASMailServer')),
47
+ introKeyOnASMailServer: makeIntroKeyCaller(caller, objPath.concat('introKeyOnASMailServer')),
48
48
  };
49
49
  }
50
50
  Object.freeze(exports);
@@ -2,7 +2,7 @@ import { ParamOnServer } from '../../lib-client/asmail/service-config';
2
2
  import { GetSigner } from '../id-manager';
3
3
  import { JWKeyPair, MsgKeyRole } from './common';
4
4
  type WritableFile = web3n.files.WritableFile;
5
- export type PKeyCertChain = web3n.keys.PKeyCertChain;
5
+ type IntroKeyCAP = web3n.keys.Keyrings['introKeyOnASMailServer'];
6
6
  export declare class PublishedIntroKey {
7
7
  private readonly getSigner;
8
8
  private pkeyOnServer;
@@ -18,11 +18,8 @@ export declare class PublishedIntroKey {
18
18
  private toFileJSON;
19
19
  private absorbRemoteChanges;
20
20
  private makeNewIntroKey;
21
- /**
22
- * This generates a new NaCl's box key pair, as a new introductory
23
- * published key.
24
- */
25
- update(): Promise<void>;
21
+ private update;
22
+ private retireCurrent;
26
23
  /**
27
24
  * This looks for a published key with a given key id. If it is found, an
28
25
  * object is returned with following fields:
@@ -39,5 +36,8 @@ export declare class PublishedIntroKey {
39
36
  pair: JWKeyPair;
40
37
  replacedAt?: number;
41
38
  } | undefined;
39
+ makeIntroKeyCAP(): IntroKeyCAP;
40
+ private getCurrent;
41
+ private removeCurrent;
42
42
  }
43
43
  export {};
@@ -26,7 +26,9 @@ class PublishedIntroKey {
26
26
  constructor(getSigner, pkeyOnServer) {
27
27
  this.getSigner = getSigner;
28
28
  this.pkeyOnServer = pkeyOnServer;
29
- this.published = {};
29
+ this.published = {
30
+ previous: []
31
+ };
30
32
  this.periodicExpiryCheck = undefined;
31
33
  this.fileProc = new file_based_json_1.JsonFileProc(this.onFileEvent.bind(this));
32
34
  Object.seal(this);
@@ -82,16 +84,10 @@ class PublishedIntroKey {
82
84
  return;
83
85
  }
84
86
  }
85
- // protected async initStruct(): Promise<void> {
86
- // const newPair = await this.makeNewIntroKey();
87
- // this.published = {
88
- // current: {
89
- // keyPair: newPair.pair,
90
- // certs: newPair.certs
91
- // }
92
- // };
93
- // }
94
87
  setFromJSON(json) {
88
+ if (!Array.isArray(json.previous)) { // migration part
89
+ json.previous = (json.previous ? [json.previous] : []);
90
+ }
95
91
  this.published = json;
96
92
  }
97
93
  toFileJSON() {
@@ -120,23 +116,26 @@ class PublishedIntroKey {
120
116
  pair.createdAt = Date.now();
121
117
  return { pair, certs };
122
118
  }
123
- /**
124
- * This generates a new NaCl's box key pair, as a new introductory
125
- * published key.
126
- */
127
119
  update() {
128
120
  return this.fileProc.order.startOrChain(async () => {
129
121
  const { certs, pair: keyPair } = await this.makeNewIntroKey();
130
122
  await this.pkeyOnServer.setOnServer(certs);
131
- if (this.published.current) {
132
- this.published.current.keyPair.retiredAt = keyPair.createdAt;
133
- this.published.previous = this.published.current.keyPair;
134
- }
123
+ this.retireCurrent(keyPair.createdAt);
135
124
  this.published.current = { keyPair, certs };
136
125
  await this.fileProc.save(this.toFileJSON(), false);
126
+ return certs;
137
127
  });
138
128
  }
139
129
  ;
130
+ retireCurrent(retiredAt) {
131
+ if (!this.published.current) {
132
+ return;
133
+ }
134
+ const current = this.published.current;
135
+ current.keyPair.retiredAt = retiredAt;
136
+ this.published.previous.push(current.keyPair);
137
+ this.published.current = undefined;
138
+ }
140
139
  /**
141
140
  * This looks for a published key with a given key id. If it is found, an
142
141
  * object is returned with following fields:
@@ -158,17 +157,39 @@ class PublishedIntroKey {
158
157
  };
159
158
  }
160
159
  // check previous key
161
- if (this.published.previous
162
- && (this.published.previous.skey.kid === kid)) {
160
+ const pair = this.published.previous.find(({ skey }) => (skey.kid === kid));
161
+ if (pair) {
163
162
  return {
164
163
  role: 'prev_published_intro',
165
- pair: this.published.previous,
166
- replacedAt: this.published.previous.retiredAt
164
+ pair,
165
+ replacedAt: pair.retiredAt
167
166
  };
168
167
  }
169
168
  // if nothing found, explicitly return undefined
170
169
  return;
171
170
  }
171
+ makeIntroKeyCAP() {
172
+ const w = {
173
+ getCurrent: this.getCurrent.bind(this),
174
+ makeAndPublishNew: this.update.bind(this),
175
+ remove: this.removeCurrent.bind(this)
176
+ };
177
+ return Object.freeze(w);
178
+ }
179
+ async getCurrent() {
180
+ var _a;
181
+ const certs = (_a = this.published.current) === null || _a === void 0 ? void 0 : _a.certs;
182
+ return (certs ? certs : null);
183
+ }
184
+ async removeCurrent() {
185
+ if (!this.published.current) {
186
+ return;
187
+ }
188
+ return this.fileProc.order.startOrChain(async () => {
189
+ await this.pkeyOnServer.setOnServer(null);
190
+ this.retireCurrent(Math.floor(Date.now() / 1000));
191
+ });
192
+ }
172
193
  }
173
194
  exports.PublishedIntroKey = PublishedIntroKey;
174
195
  Object.freeze(PublishedIntroKey.prototype);
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- Copyright (C) 2020 - 2021, 2023 - 2024 3NSoft Inc.
3
+ Copyright (C) 2020 - 2021, 2023 - 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
@@ -9,7 +9,8 @@ export interface ParamOnServer<P extends keyof ASMailConfigParams> {
9
9
  getFromServer: () => Promise<ASMailConfigParams[P] | null>;
10
10
  }
11
11
  export declare class MailConfigurator extends ServiceUser {
12
- constructor(userId: string, getSigner: IGetMailerIdSigner, mainUrlGetter: () => Promise<string>, net: NetClient);
12
+ private readonly sleepMillisAfterParamSetting;
13
+ constructor(userId: string, getSigner: IGetMailerIdSigner, mainUrlGetter: () => Promise<string>, net: NetClient, sleepMillisAfterParamSetting?: number);
13
14
  getParam<P extends keyof ASMailConfigParams>(param: P): Promise<ASMailConfigParams[P] | null>;
14
15
  setParam<P extends keyof ASMailConfigParams>(param: P, value: ASMailConfigParams[P] | null): Promise<void>;
15
16
  makeParamSetterAndGetter<P extends keyof ASMailConfigParams>(param: P): ParamOnServer<P>;
@@ -23,14 +23,16 @@ const request_utils_1 = require("../request-utils");
23
23
  const api = require("../../lib-common/service-api/asmail/config");
24
24
  const user_with_mid_session_1 = require("../user-with-mid-session");
25
25
  const service_locator_1 = require("../service-locator");
26
+ const sleep_1 = require("../../lib-common/processes/sleep");
26
27
  const configAccessParams = {
27
28
  login: api.midLogin.MID_URL_PART,
28
29
  logout: api.closeSession.URL_END,
29
30
  canBeRedirected: true
30
31
  };
31
32
  class MailConfigurator extends user_with_mid_session_1.ServiceUser {
32
- constructor(userId, getSigner, mainUrlGetter, net) {
33
+ constructor(userId, getSigner, mainUrlGetter, net, sleepMillisAfterParamSetting = 50) {
33
34
  super(userId, configAccessParams, getSigner, serviceUriGetter(net, mainUrlGetter), net);
35
+ this.sleepMillisAfterParamSetting = sleepMillisAfterParamSetting;
34
36
  Object.seal(this);
35
37
  }
36
38
  async getParam(param) {
@@ -54,6 +56,8 @@ class MailConfigurator extends user_with_mid_session_1.ServiceUser {
54
56
  if (rep.status !== api.PARAM_SC.ok) {
55
57
  throw (0, request_utils_1.makeException)(rep, 'Unexpected status');
56
58
  }
59
+ // wait to let possibly distributed system to propagate updates internally
60
+ await (0, sleep_1.sleep)(this.sleepMillisAfterParamSetting);
57
61
  }
58
62
  makeParamSetterAndGetter(param) {
59
63
  return {