core-3nweb-client-lib 0.27.3 → 0.27.4
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.
- package/build/api-defs/files.d.ts +52 -19
- package/build/core/asmail/config/index.d.ts +2 -2
- package/build/core/asmail/config/index.js +2 -2
- package/build/core/asmail/config/invitations-anon.d.ts +10 -24
- package/build/core/asmail/config/invitations-anon.js +43 -31
- package/build/core/asmail/config/published-intro-key.d.ts +11 -22
- package/build/core/asmail/config/published-intro-key.js +47 -38
- package/build/core/asmail/inbox/index.js +1 -1
- package/build/core/asmail/index.d.ts +1 -1
- package/build/core/asmail/index.js +2 -2
- package/build/core/asmail/keyring/correspondent-keys.d.ts +2 -2
- package/build/core/asmail/keyring/correspondent-keys.js +1 -1
- package/build/core/asmail/keyring/index.d.ts +9 -29
- package/build/core/asmail/keyring/index.js +82 -69
- package/build/core/index.js +1 -2
- package/build/core/sign-in.js +1 -1
- package/build/core/storage/synced/obj-files.d.ts +2 -0
- package/build/core/storage/synced/obj-files.js +18 -1
- package/build/core/storage/synced/obj-status.d.ts +1 -0
- package/build/core/storage/synced/obj-status.js +10 -0
- package/build/core/storage/synced/storage.js +4 -21
- package/build/ipc-via-protobuf/file.d.ts +7 -0
- package/build/ipc-via-protobuf/file.js +60 -27
- package/build/ipc-via-protobuf/fs.js +55 -38
- package/build/lib-client/3nstorage/xsp-fs/file-node.d.ts +5 -10
- package/build/lib-client/3nstorage/xsp-fs/file-node.js +43 -45
- package/build/lib-client/3nstorage/xsp-fs/file.d.ts +7 -6
- package/build/lib-client/3nstorage/xsp-fs/file.js +12 -18
- package/build/lib-client/3nstorage/xsp-fs/folder-node.d.ts +5 -0
- package/build/lib-client/3nstorage/xsp-fs/folder-node.js +7 -1
- package/build/lib-client/3nstorage/xsp-fs/fs.d.ts +18 -17
- package/build/lib-client/3nstorage/xsp-fs/fs.js +17 -18
- package/build/lib-client/3nstorage/xsp-fs/node-in-fs.d.ts +11 -2
- package/build/lib-client/3nstorage/xsp-fs/node-in-fs.js +56 -5
- package/build/lib-client/cryptor/cryptor-wasm.js +1 -1
- package/build/lib-client/cryptor/cryptor.wasm +0 -0
- package/build/lib-client/objs-on-disk/obj-on-disk.d.ts +5 -2
- package/build/lib-client/objs-on-disk/obj-on-disk.js +16 -1
- package/build/lib-common/objs-on-disk/file-layout.js +1 -1
- package/build/protos/asmail.proto.js +5943 -4348
- package/build/protos/file.proto.js +874 -0
- package/build/protos/fs.proto.js +7014 -5419
- package/package.json +1 -1
- package/protos/file.proto +23 -7
- package/protos/fs.proto +27 -13
|
@@ -420,9 +420,13 @@ declare namespace web3n.files {
|
|
|
420
420
|
|
|
421
421
|
interface ReadonlyFileVersionedAPI {
|
|
422
422
|
|
|
423
|
-
getXAttr(
|
|
423
|
+
getXAttr(
|
|
424
|
+
xaName: string, flags?: VersionedReadFlags
|
|
425
|
+
): Promise<{ attr: any; version: number; }>;
|
|
424
426
|
|
|
425
|
-
listXAttrs(
|
|
427
|
+
listXAttrs(
|
|
428
|
+
flags?: VersionedReadFlags
|
|
429
|
+
): Promise<{ lst: string[]; version: number; }>;
|
|
426
430
|
|
|
427
431
|
/**
|
|
428
432
|
* This returns a promise, resolvable to either non-empty byte array, or
|
|
@@ -433,34 +437,51 @@ declare namespace web3n.files {
|
|
|
433
437
|
* @param end optional parameter, setting an end of read. If end is
|
|
434
438
|
* greater than file length, all available bytes are read. If parameter
|
|
435
439
|
* is missing, read will be done to file's end.
|
|
440
|
+
* @param flags are optional flags to read archived or remote versions.
|
|
436
441
|
*/
|
|
437
442
|
readBytes(
|
|
438
|
-
start?: number, end?: number
|
|
443
|
+
start?: number, end?: number, flags?: VersionedReadFlags
|
|
439
444
|
): Promise<{ bytes: Uint8Array|undefined; version: number; }>;
|
|
440
445
|
|
|
441
446
|
/**
|
|
442
447
|
* This returns a promise, resolvable to text, read from file, assuming
|
|
443
448
|
* utf8 encoding.
|
|
449
|
+
* @param flags are optional flags to read archived or remote versions.
|
|
444
450
|
*/
|
|
445
|
-
readTxt(
|
|
451
|
+
readTxt(
|
|
452
|
+
flags?: VersionedReadFlags
|
|
453
|
+
): Promise<{ txt: string; version: number; }>;
|
|
446
454
|
|
|
447
455
|
/**
|
|
448
456
|
* This returns a promise, resolvable to json, read from file
|
|
457
|
+
* @param flags are optional flags to read archived or remote versions.
|
|
449
458
|
*/
|
|
450
|
-
readJSON<T>(
|
|
459
|
+
readJSON<T>(
|
|
460
|
+
flags?: VersionedReadFlags
|
|
461
|
+
): Promise<{ json: T; version: number; }>;
|
|
451
462
|
|
|
452
463
|
/**
|
|
453
464
|
* This returns a promise, resolvable to bytes source with seek, which
|
|
454
465
|
* allows random reads, and a file version
|
|
466
|
+
* @param flags are optional flags to read archived or remote versions.
|
|
455
467
|
*/
|
|
456
|
-
getByteSource(
|
|
468
|
+
getByteSource(
|
|
469
|
+
flags?: VersionedReadFlags
|
|
470
|
+
): Promise<{ src: FileByteSource; version: number; }>;
|
|
457
471
|
|
|
458
|
-
listVersions(
|
|
472
|
+
listVersions(
|
|
473
|
+
flags?: VersionedReadFlags
|
|
474
|
+
): Promise<{ current?: number; archived?: number[]; }>;
|
|
459
475
|
|
|
460
476
|
sync?: ReadonlyFileSyncAPI;
|
|
461
477
|
|
|
462
478
|
}
|
|
463
479
|
|
|
480
|
+
interface VersionedReadFlags {
|
|
481
|
+
archivedVersion?: number;
|
|
482
|
+
remoteVersion?: number;
|
|
483
|
+
}
|
|
484
|
+
|
|
464
485
|
interface WritableFileVersionedAPI extends ReadonlyFileVersionedAPI {
|
|
465
486
|
|
|
466
487
|
/**
|
|
@@ -972,7 +993,7 @@ declare namespace web3n.files {
|
|
|
972
993
|
|
|
973
994
|
}
|
|
974
995
|
|
|
975
|
-
interface
|
|
996
|
+
interface VersionedFileWriteFlags extends FileFlags {
|
|
976
997
|
|
|
977
998
|
/**
|
|
978
999
|
* currentVersion flag is optional. This flag is applicable to existing
|
|
@@ -986,33 +1007,42 @@ declare namespace web3n.files {
|
|
|
986
1007
|
interface ReadonlyFSVersionedAPI {
|
|
987
1008
|
|
|
988
1009
|
getXAttr(
|
|
989
|
-
path: string, xaName: string
|
|
1010
|
+
path: string, xaName: string, flags?: VersionedReadFlags
|
|
990
1011
|
): Promise<{ attr: any; version: number; }>;
|
|
991
1012
|
|
|
992
|
-
listXAttrs(
|
|
1013
|
+
listXAttrs(
|
|
1014
|
+
path: string, flags?: VersionedReadFlags
|
|
1015
|
+
): Promise<{ lst: string[]; version: number; }>;
|
|
993
1016
|
|
|
994
1017
|
/**
|
|
995
1018
|
* This returns a promise, resolvable to a list of informational objects
|
|
996
1019
|
* for entries in the folder, and a folder's version.
|
|
997
1020
|
* @param path of a folder that should be listed
|
|
1021
|
+
* @param flags are optional flags to read archived or remote versions.
|
|
998
1022
|
*/
|
|
999
1023
|
listFolder(
|
|
1000
|
-
path: string
|
|
1024
|
+
path: string, flags?: VersionedReadFlags
|
|
1001
1025
|
): Promise<{ lst: ListingEntry[]; version: number; }>;
|
|
1002
1026
|
|
|
1003
1027
|
/**
|
|
1004
1028
|
* This returns a promise, resolvable to json, read from file, and a
|
|
1005
1029
|
* version of file.
|
|
1006
1030
|
* @param path of a file from which to read json
|
|
1031
|
+
* @param flags are optional flags to read archived or remote versions.
|
|
1007
1032
|
*/
|
|
1008
|
-
readJSONFile<T>(
|
|
1033
|
+
readJSONFile<T>(
|
|
1034
|
+
path: string, flags?: VersionedReadFlags
|
|
1035
|
+
): Promise<{ json: T; version: number; }>;
|
|
1009
1036
|
|
|
1010
1037
|
/**
|
|
1011
1038
|
* This returns a promise, resolvable to text, read from file, assuming
|
|
1012
1039
|
* utf8 encoding, and version of file.
|
|
1013
1040
|
* @param path of a file from which to read text
|
|
1041
|
+
* @param flags are optional flags to read archived or remote versions.
|
|
1014
1042
|
*/
|
|
1015
|
-
readTxtFile(
|
|
1043
|
+
readTxtFile(
|
|
1044
|
+
path: string, flags?: VersionedReadFlags
|
|
1045
|
+
): Promise<{ txt: string; version: number; }>;
|
|
1016
1046
|
|
|
1017
1047
|
/**
|
|
1018
1048
|
* This returns a promise, resolvable to bytes, that is either non-empty
|
|
@@ -1024,18 +1054,21 @@ declare namespace web3n.files {
|
|
|
1024
1054
|
* @param end optional parameter, setting an end of read. If end is
|
|
1025
1055
|
* greater than file length, all available bytes are read. If parameter
|
|
1026
1056
|
* is missing, read will be done to file's end.
|
|
1057
|
+
* @param flags are optional flags to read archived or remote versions.
|
|
1027
1058
|
*/
|
|
1028
1059
|
readBytes(
|
|
1029
|
-
path: string, start?: number, end?: number
|
|
1060
|
+
path: string, start?: number, end?: number,
|
|
1061
|
+
flags?: VersionedReadFlags
|
|
1030
1062
|
): Promise<{ bytes: Uint8Array|undefined; version: number; }>;
|
|
1031
1063
|
|
|
1032
1064
|
/**
|
|
1033
1065
|
* This returns a promise, resolvable to bytes source with seek, which
|
|
1034
1066
|
* allows random reads, and a file version
|
|
1035
1067
|
* @param path of a file from which to read bytes
|
|
1068
|
+
* @param flags are optional flags to read archived or remote versions.
|
|
1036
1069
|
*/
|
|
1037
1070
|
getByteSource(
|
|
1038
|
-
path: string
|
|
1071
|
+
path: string, flags?: VersionedReadFlags
|
|
1039
1072
|
): Promise<{ src: FileByteSource; version: number; }>;
|
|
1040
1073
|
|
|
1041
1074
|
listVersions(
|
|
@@ -1065,7 +1098,7 @@ declare namespace web3n.files {
|
|
|
1065
1098
|
* exclusive=false.
|
|
1066
1099
|
*/
|
|
1067
1100
|
writeJSONFile(
|
|
1068
|
-
path: string, json: any, flags?:
|
|
1101
|
+
path: string, json: any, flags?: VersionedFileWriteFlags
|
|
1069
1102
|
): Promise<number>;
|
|
1070
1103
|
|
|
1071
1104
|
/**
|
|
@@ -1077,7 +1110,7 @@ declare namespace web3n.files {
|
|
|
1077
1110
|
* exclusive=false.
|
|
1078
1111
|
*/
|
|
1079
1112
|
writeTxtFile(
|
|
1080
|
-
path: string, txt: string, flags?:
|
|
1113
|
+
path: string, txt: string, flags?: VersionedFileWriteFlags
|
|
1081
1114
|
): Promise<number>;
|
|
1082
1115
|
|
|
1083
1116
|
/**
|
|
@@ -1089,7 +1122,7 @@ declare namespace web3n.files {
|
|
|
1089
1122
|
* exclusive=false.
|
|
1090
1123
|
*/
|
|
1091
1124
|
writeBytes(
|
|
1092
|
-
path: string, bytes: Uint8Array, flags?:
|
|
1125
|
+
path: string, bytes: Uint8Array, flags?: VersionedFileWriteFlags
|
|
1093
1126
|
): Promise<number>;
|
|
1094
1127
|
|
|
1095
1128
|
/**
|
|
@@ -1100,7 +1133,7 @@ declare namespace web3n.files {
|
|
|
1100
1133
|
* exclusive=false, truncate=true.
|
|
1101
1134
|
*/
|
|
1102
1135
|
getByteSink(
|
|
1103
|
-
path: string, flags?:
|
|
1136
|
+
path: string, flags?: VersionedFileWriteFlags
|
|
1104
1137
|
): Promise<{ sink: FileByteSink; version: number; }>;
|
|
1105
1138
|
|
|
1106
1139
|
archiveCurrent(path: string, version?: number): Promise<number>;
|
|
@@ -35,11 +35,11 @@ export declare class ConfigOfASMailServer {
|
|
|
35
35
|
* @param kid
|
|
36
36
|
* @return if key is found, object with following fields is returned:
|
|
37
37
|
*/
|
|
38
|
-
find: (kid: string) =>
|
|
38
|
+
find: (kid: string) => {
|
|
39
39
|
role: MsgKeyRole;
|
|
40
40
|
pair: JWKeyPair;
|
|
41
41
|
replacedAt?: number;
|
|
42
|
-
};
|
|
42
|
+
} | undefined;
|
|
43
43
|
};
|
|
44
44
|
private constructor();
|
|
45
45
|
static makeAndStart(address: string, getSigner: GetSigner, resolver: ServiceLocator, net: NetClient, fs: WritableFS): Promise<ConfigOfASMailServer>;
|
|
@@ -30,8 +30,8 @@ const INTRO_KEY_FILE = 'introductory-key.json';
|
|
|
30
30
|
class ConfigOfASMailServer {
|
|
31
31
|
constructor(address, getSigner, resolver, net) {
|
|
32
32
|
const serviceConf = new service_config_1.MailConfigurator(address, getSigner, () => resolver(serviceConf.userId), net);
|
|
33
|
-
this.anonInvites =
|
|
34
|
-
this.publishedIntroKeys =
|
|
33
|
+
this.anonInvites = (0, invitations_anon_1.makeInvites)(serviceConf);
|
|
34
|
+
this.publishedIntroKeys = (0, published_intro_key_1.makePublishedIntroKey)(getSigner, serviceConf);
|
|
35
35
|
this.anonSenderInvites = {
|
|
36
36
|
getAll: this.anonInvites.getAll,
|
|
37
37
|
create: this.anonInvites.create,
|
|
@@ -1,27 +1,13 @@
|
|
|
1
1
|
import { MailConfigurator } from '../../../lib-client/asmail/service-config';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
declare type ExposedFuncs = ConfigOfASMailServer['anonSenderInvites'];
|
|
14
|
-
export declare class Invites extends ParamOnFileAndServer<InvitesJSON, api.InvitesList> {
|
|
15
|
-
private invites;
|
|
16
|
-
constructor(serviceConf: MailConfigurator);
|
|
17
|
-
protected initStruct(): Promise<void>;
|
|
18
|
-
protected setFromJSON(json: InvitesJSON): void;
|
|
19
|
-
protected toFileJSON(): InvitesJSON;
|
|
20
|
-
protected toServiceJSON(): api.InvitesList;
|
|
21
|
-
getAll: ExposedFuncs['getAll'];
|
|
22
|
-
create: ExposedFuncs['create'];
|
|
23
|
-
private generateNewRandomInvite;
|
|
24
|
-
private findByLabel;
|
|
25
|
-
setMsgMaxSize: ExposedFuncs['setMsgMaxSize'];
|
|
2
|
+
declare type WritableFile = web3n.files.WritableFile;
|
|
3
|
+
export interface Invites {
|
|
4
|
+
getAll: () => Map<string, {
|
|
5
|
+
invite: string;
|
|
6
|
+
msgMaxSize: number;
|
|
7
|
+
}>;
|
|
8
|
+
create: (label: string, msgMaxSize: number) => Promise<string>;
|
|
9
|
+
setMsgMaxSize: (label: string, msgMaxSize: number) => Promise<void>;
|
|
10
|
+
start: (file: WritableFile) => Promise<void>;
|
|
26
11
|
}
|
|
12
|
+
export declare function makeInvites(serviceConf: MailConfigurator): Invites;
|
|
27
13
|
export {};
|
|
@@ -15,41 +15,25 @@
|
|
|
15
15
|
You should have received a copy of the GNU General Public License along with
|
|
16
16
|
this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.
|
|
18
|
+
exports.makeInvites = void 0;
|
|
19
19
|
const random = require("../../../lib-common/random-node");
|
|
20
20
|
const api = require("../../../lib-common/service-api/asmail/config");
|
|
21
21
|
const common_1 = require("./common");
|
|
22
22
|
const INVITE_TOKEN_LEN = 40;
|
|
23
|
-
|
|
23
|
+
function makeInvites(serviceConf) {
|
|
24
|
+
const invites = new InvitesData(serviceConf);
|
|
25
|
+
return {
|
|
26
|
+
create: invites.create.bind(invites),
|
|
27
|
+
getAll: invites.getAll.bind(invites),
|
|
28
|
+
setMsgMaxSize: invites.setMsgMaxSize.bind(invites),
|
|
29
|
+
start: invites.start.bind(invites)
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
exports.makeInvites = makeInvites;
|
|
33
|
+
class InvitesData extends common_1.ParamOnFileAndServer {
|
|
24
34
|
constructor(serviceConf) {
|
|
25
35
|
super(api.p.anonSenderInvites.URL_END, serviceConf);
|
|
26
36
|
this.invites = {};
|
|
27
|
-
this.getAll = () => {
|
|
28
|
-
const byLabel = new Map();
|
|
29
|
-
Object.entries(this.invites)
|
|
30
|
-
.forEach(([invite, params]) => {
|
|
31
|
-
byLabel.set(params.label, { invite, msgMaxSize: params.msgMaxSize });
|
|
32
|
-
});
|
|
33
|
-
return byLabel;
|
|
34
|
-
};
|
|
35
|
-
this.create = async (label, msgMaxSize) => {
|
|
36
|
-
const existingInvite = this.findByLabel(label);
|
|
37
|
-
if (existingInvite) {
|
|
38
|
-
throw new Error(`Anonymous sender invite already exists with label ${label}`);
|
|
39
|
-
}
|
|
40
|
-
const invite = await this.generateNewRandomInvite();
|
|
41
|
-
this.invites[invite] = { label, msgMaxSize };
|
|
42
|
-
await this.save();
|
|
43
|
-
return invite;
|
|
44
|
-
};
|
|
45
|
-
this.setMsgMaxSize = async (label, msgMaxSize) => {
|
|
46
|
-
const invite = this.findByLabel(label);
|
|
47
|
-
if (!invite) {
|
|
48
|
-
throw new Error(`There is no anonymous sender invite with label ${label}`);
|
|
49
|
-
}
|
|
50
|
-
this.invites[invite].msgMaxSize = msgMaxSize;
|
|
51
|
-
await this.save();
|
|
52
|
-
};
|
|
53
37
|
Object.seal(this);
|
|
54
38
|
}
|
|
55
39
|
async initStruct() { }
|
|
@@ -69,6 +53,26 @@ class Invites extends common_1.ParamOnFileAndServer {
|
|
|
69
53
|
});
|
|
70
54
|
return serverJSON;
|
|
71
55
|
}
|
|
56
|
+
getAll() {
|
|
57
|
+
const byLabel = new Map();
|
|
58
|
+
Object.entries(this.invites)
|
|
59
|
+
.forEach(([invite, params]) => {
|
|
60
|
+
byLabel.set(params.label, { invite, msgMaxSize: params.msgMaxSize });
|
|
61
|
+
});
|
|
62
|
+
return byLabel;
|
|
63
|
+
}
|
|
64
|
+
;
|
|
65
|
+
async create(label, msgMaxSize) {
|
|
66
|
+
const existingInvite = this.findByLabel(label);
|
|
67
|
+
if (existingInvite) {
|
|
68
|
+
throw new Error(`Anonymous sender invite already exists with label ${label}`);
|
|
69
|
+
}
|
|
70
|
+
const invite = await this.generateNewRandomInvite();
|
|
71
|
+
this.invites[invite] = { label, msgMaxSize };
|
|
72
|
+
await this.save();
|
|
73
|
+
return invite;
|
|
74
|
+
}
|
|
75
|
+
;
|
|
72
76
|
async generateNewRandomInvite() {
|
|
73
77
|
let invite;
|
|
74
78
|
do {
|
|
@@ -81,8 +85,16 @@ class Invites extends common_1.ParamOnFileAndServer {
|
|
|
81
85
|
.find(([_, params]) => (params.label === label));
|
|
82
86
|
return (found ? found[0] : undefined);
|
|
83
87
|
}
|
|
88
|
+
async setMsgMaxSize(label, msgMaxSize) {
|
|
89
|
+
const invite = this.findByLabel(label);
|
|
90
|
+
if (!invite) {
|
|
91
|
+
throw new Error(`There is no anonymous sender invite with label ${label}`);
|
|
92
|
+
}
|
|
93
|
+
this.invites[invite].msgMaxSize = msgMaxSize;
|
|
94
|
+
await this.save();
|
|
95
|
+
}
|
|
96
|
+
;
|
|
84
97
|
}
|
|
85
|
-
|
|
86
|
-
Object.freeze(
|
|
87
|
-
Object.freeze(Invites);
|
|
98
|
+
Object.freeze(InvitesData.prototype);
|
|
99
|
+
Object.freeze(InvitesData);
|
|
88
100
|
Object.freeze(exports);
|
|
@@ -1,28 +1,17 @@
|
|
|
1
1
|
import { MailConfigurator } from '../../../lib-client/asmail/service-config';
|
|
2
2
|
import * as api from '../../../lib-common/service-api/asmail/config';
|
|
3
3
|
import { GetSigner } from '../../id-manager';
|
|
4
|
-
import { JWKeyPair } from '../keyring/common';
|
|
5
|
-
|
|
6
|
-
import { ConfigOfASMailServer } from '../config';
|
|
4
|
+
import { JWKeyPair, MsgKeyRole } from '../keyring/common';
|
|
5
|
+
declare type WritableFile = web3n.files.WritableFile;
|
|
7
6
|
export declare type Certs = api.p.initPubKey.Certs;
|
|
8
|
-
interface
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export declare class PublishedIntroKey extends ParamOnFileAndServer<PublishedIntroKeysJSON, Certs> {
|
|
17
|
-
private getSigner;
|
|
18
|
-
private published;
|
|
19
|
-
constructor(getSigner: GetSigner, serviceConf: MailConfigurator);
|
|
20
|
-
protected initStruct(): Promise<void>;
|
|
21
|
-
protected setFromJSON(json: PublishedIntroKeysJSON): void;
|
|
22
|
-
protected toFileJSON(): PublishedIntroKeysJSON;
|
|
23
|
-
protected toServiceJSON(): Certs;
|
|
24
|
-
private makeNewIntroKey;
|
|
25
|
-
update: ExposedFuncs['update'];
|
|
26
|
-
find: ExposedFuncs['find'];
|
|
7
|
+
export interface PublishedIntroKey {
|
|
8
|
+
update: () => Promise<void>;
|
|
9
|
+
find: (kid: string) => {
|
|
10
|
+
role: MsgKeyRole;
|
|
11
|
+
pair: JWKeyPair;
|
|
12
|
+
replacedAt?: number;
|
|
13
|
+
} | undefined;
|
|
14
|
+
start: (file: WritableFile) => Promise<void>;
|
|
27
15
|
}
|
|
16
|
+
export declare function makePublishedIntroKey(getSigner: GetSigner, serviceConf: MailConfigurator): PublishedIntroKey;
|
|
28
17
|
export {};
|
|
@@ -15,49 +15,25 @@
|
|
|
15
15
|
You should have received a copy of the GNU General Public License along with
|
|
16
16
|
this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.
|
|
18
|
+
exports.makePublishedIntroKey = void 0;
|
|
19
19
|
const api = require("../../../lib-common/service-api/asmail/config");
|
|
20
20
|
const common_1 = require("../keyring/common");
|
|
21
21
|
const common_2 = require("./common");
|
|
22
22
|
const INTRO_KEY_VALIDITY = 31 * 24 * 60 * 60;
|
|
23
|
-
|
|
23
|
+
function makePublishedIntroKey(getSigner, serviceConf) {
|
|
24
|
+
const published = new PublishedKey(getSigner, serviceConf);
|
|
25
|
+
return {
|
|
26
|
+
find: published.find.bind(published),
|
|
27
|
+
update: published.update.bind(published),
|
|
28
|
+
start: published.start.bind(published)
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
exports.makePublishedIntroKey = makePublishedIntroKey;
|
|
32
|
+
class PublishedKey extends common_2.ParamOnFileAndServer {
|
|
24
33
|
constructor(getSigner, serviceConf) {
|
|
25
34
|
super(api.p.initPubKey.URL_END, serviceConf);
|
|
26
35
|
this.getSigner = getSigner;
|
|
27
36
|
this.published = undefined;
|
|
28
|
-
this.update = async () => {
|
|
29
|
-
const newKey = await this.makeNewIntroKey();
|
|
30
|
-
if (this.published.current) {
|
|
31
|
-
this.published.current.keyPair.retiredAt = newKey.pair.createdAt;
|
|
32
|
-
this.published.previous = this.published.current.keyPair;
|
|
33
|
-
}
|
|
34
|
-
this.published.current = {
|
|
35
|
-
keyPair: newKey.pair,
|
|
36
|
-
certs: newKey.certs
|
|
37
|
-
};
|
|
38
|
-
await this.save();
|
|
39
|
-
};
|
|
40
|
-
this.find = (kid) => {
|
|
41
|
-
// check current key
|
|
42
|
-
if (this.published.current
|
|
43
|
-
&& (this.published.current.keyPair.skey.kid === kid)) {
|
|
44
|
-
return {
|
|
45
|
-
role: 'published_intro',
|
|
46
|
-
pair: this.published.current.keyPair
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
// check previous key
|
|
50
|
-
if (this.published.previous
|
|
51
|
-
&& (this.published.previous.skey.kid === kid)) {
|
|
52
|
-
return {
|
|
53
|
-
role: 'prev_published_intro',
|
|
54
|
-
pair: this.published.previous,
|
|
55
|
-
replacedAt: this.published.previous.retiredAt
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
// if nothing found, explicitly return undefined
|
|
59
|
-
return;
|
|
60
|
-
};
|
|
61
37
|
Object.seal(this);
|
|
62
38
|
}
|
|
63
39
|
async initStruct() {
|
|
@@ -89,8 +65,41 @@ class PublishedIntroKey extends common_2.ParamOnFileAndServer {
|
|
|
89
65
|
pair.createdAt = Date.now();
|
|
90
66
|
return { pair, certs };
|
|
91
67
|
}
|
|
68
|
+
async update() {
|
|
69
|
+
const newKey = await this.makeNewIntroKey();
|
|
70
|
+
if (this.published.current) {
|
|
71
|
+
this.published.current.keyPair.retiredAt = newKey.pair.createdAt;
|
|
72
|
+
this.published.previous = this.published.current.keyPair;
|
|
73
|
+
}
|
|
74
|
+
this.published.current = {
|
|
75
|
+
keyPair: newKey.pair,
|
|
76
|
+
certs: newKey.certs
|
|
77
|
+
};
|
|
78
|
+
await this.save();
|
|
79
|
+
}
|
|
80
|
+
;
|
|
81
|
+
find(kid) {
|
|
82
|
+
// check current key
|
|
83
|
+
if (this.published.current
|
|
84
|
+
&& (this.published.current.keyPair.skey.kid === kid)) {
|
|
85
|
+
return {
|
|
86
|
+
role: 'published_intro',
|
|
87
|
+
pair: this.published.current.keyPair
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
// check previous key
|
|
91
|
+
if (this.published.previous
|
|
92
|
+
&& (this.published.previous.skey.kid === kid)) {
|
|
93
|
+
return {
|
|
94
|
+
role: 'prev_published_intro',
|
|
95
|
+
pair: this.published.previous,
|
|
96
|
+
replacedAt: this.published.previous.retiredAt
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
// if nothing found, explicitly return undefined
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
92
102
|
}
|
|
93
|
-
|
|
94
|
-
Object.freeze(
|
|
95
|
-
Object.freeze(PublishedIntroKey);
|
|
103
|
+
Object.freeze(PublishedKey.prototype);
|
|
104
|
+
Object.freeze(PublishedKey);
|
|
96
105
|
Object.freeze(exports);
|
|
@@ -10,6 +10,7 @@ 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;
|
|
13
14
|
private readonly inboxPathForUser;
|
|
14
15
|
private readonly logger;
|
|
15
16
|
private keyring;
|
|
@@ -18,7 +19,6 @@ export declare class ASMail {
|
|
|
18
19
|
private delivery;
|
|
19
20
|
private config;
|
|
20
21
|
private sendingParams;
|
|
21
|
-
private readonly makeNet;
|
|
22
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;
|
|
@@ -32,6 +32,7 @@ const SEND_PARAMS_DATA_FOLDER = 'sending-params';
|
|
|
32
32
|
class ASMail {
|
|
33
33
|
constructor(cryptor, makeNet, inboxPathForUser, logger) {
|
|
34
34
|
this.cryptor = cryptor;
|
|
35
|
+
this.makeNet = makeNet;
|
|
35
36
|
this.inboxPathForUser = inboxPathForUser;
|
|
36
37
|
this.logger = logger;
|
|
37
38
|
this.keyring = undefined;
|
|
@@ -40,7 +41,6 @@ class ASMail {
|
|
|
40
41
|
this.delivery = undefined;
|
|
41
42
|
this.config = undefined;
|
|
42
43
|
this.sendingParams = undefined;
|
|
43
|
-
this.makeNet = () => makeNet();
|
|
44
44
|
Object.seal(this);
|
|
45
45
|
}
|
|
46
46
|
async init(address, getSigner, syncedFS, localFS, getStorages, makeResolver) {
|
|
@@ -70,7 +70,7 @@ class ASMail {
|
|
|
70
70
|
}
|
|
71
71
|
async setupKeyring(syncedFS) {
|
|
72
72
|
const fs = await (0, fs_sync_utils_1.getOrMakeAndUploadFolderIn)(syncedFS, KEYRING_DATA_FOLDER);
|
|
73
|
-
this.keyring = await keyring_1.
|
|
73
|
+
this.keyring = await (0, keyring_1.makeAndKeyRing)(this.cryptor, fs, this.config.publishedKeys);
|
|
74
74
|
}
|
|
75
75
|
async setupSendingParams(syncedFS) {
|
|
76
76
|
const fs = await (0, fs_sync_utils_1.getOrMakeAndUploadFolderIn)(syncedFS, SEND_PARAMS_DATA_FOLDER);
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { JWKeyPair, MsgKeyRole, ASMailKeyPair } from './common';
|
|
5
5
|
import { JsonKey, JsonKeyShort } from '../../../lib-common/jwkeys';
|
|
6
6
|
import { SuggestedNextKeyPair } from '../msg/opener';
|
|
7
|
-
import {
|
|
7
|
+
import { KeyPairsStorage } from './index';
|
|
8
8
|
import { Decryptor } from '../../../lib-common/async-cryptor-wrap';
|
|
9
9
|
import { AsyncSBoxCryptor } from 'xsp-files';
|
|
10
10
|
export interface ReceptionPair {
|
|
@@ -89,7 +89,7 @@ export declare class CorrespondentKeys {
|
|
|
89
89
|
* @param serialData from which this object should be reconstructed.
|
|
90
90
|
* Either serialData, or an address should be defined, not both.
|
|
91
91
|
*/
|
|
92
|
-
constructor(keyring:
|
|
92
|
+
constructor(keyring: KeyPairsStorage, address: string | undefined, serialData?: string);
|
|
93
93
|
/**
|
|
94
94
|
* This attaches all keys into ring's maps.
|
|
95
95
|
* Theis method should be called only once, and only on a deserialized
|
|
@@ -25,35 +25,15 @@ export interface MsgKeyInfo {
|
|
|
25
25
|
declare type WritableFS = web3n.files.WritableFS;
|
|
26
26
|
declare type SendingResources = ResourcesForSending['correspondents'];
|
|
27
27
|
declare type ReceptionResources = ResourcesForReceiving['correspondents'];
|
|
28
|
-
export
|
|
29
|
-
private readonly cryptor;
|
|
30
|
-
private readonly publishedKeys;
|
|
31
|
-
/**
|
|
32
|
-
* This is a map from correspondents' canonical addresses to key objects.
|
|
33
|
-
*/
|
|
34
|
-
private readonly corrKeys;
|
|
35
|
-
readonly pairIdToEmailMap: IdToEmailMap;
|
|
36
|
-
private storage;
|
|
37
|
-
constructor(cryptor: AsyncSBoxCryptor, publishedKeys: ConfigOfASMailServer['publishedKeys']);
|
|
38
|
-
private addCorrespondent;
|
|
39
|
-
private init;
|
|
40
|
-
static makeAndStart(cryptor: AsyncSBoxCryptor, fs: WritableFS, publishedKeys: ConfigOfASMailServer['publishedKeys']): Promise<KeyRing>;
|
|
41
|
-
saveChanges(): void;
|
|
28
|
+
export interface KeyRing {
|
|
42
29
|
needIntroKeyFor: SendingResources['needIntroKeyFor'];
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
private findEstablishedReceptionPairs;
|
|
47
|
-
private decryptMsgKeyWithEstablishedPair;
|
|
48
|
-
/**
|
|
49
|
-
* This method updates message counts and a timestamp in a given reception
|
|
50
|
-
* pair.
|
|
51
|
-
* @param rp is a sending pair, in which changes should be done. Note this
|
|
52
|
-
* must be a shared structure at this point, not a copy of a pair.
|
|
53
|
-
* @param msgCount is a message count that should be added to the pair.
|
|
54
|
-
*/
|
|
55
|
-
private updateReceivedMsgCountIn;
|
|
56
|
-
private absorbSuggestedNextKeyPair;
|
|
57
|
-
readonly decrypt: ReceptionResources['msgDecryptor'];
|
|
30
|
+
generateKeysToSend: SendingResources['generateKeysToSend'];
|
|
31
|
+
nextCrypto: SendingResources['nextCrypto'];
|
|
32
|
+
decrypt: ReceptionResources['msgDecryptor'];
|
|
58
33
|
close(): Promise<void>;
|
|
59
34
|
}
|
|
35
|
+
export declare function makeAndKeyRing(cryptor: AsyncSBoxCryptor, fs: WritableFS, publishedKeys: ConfigOfASMailServer['publishedKeys']): Promise<KeyRing>;
|
|
36
|
+
export interface KeyPairsStorage {
|
|
37
|
+
pairIdToEmailMap: IdToEmailMap;
|
|
38
|
+
saveChanges: () => void;
|
|
39
|
+
}
|