core-3nweb-client-lib 0.27.0 → 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 +56 -26
- 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/attachments/fs.d.ts +2 -1
- package/build/core/asmail/inbox/attachments/fs.js +4 -3
- package/build/core/asmail/inbox/index.js +2 -2
- 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/id-manager/index.d.ts +43 -0
- package/build/core/{id-manager.js → id-manager/index.js} +33 -114
- package/build/core/id-manager/key-storage.d.ts +21 -0
- package/build/core/id-manager/key-storage.js +96 -0
- package/build/core/index.js +22 -25
- package/build/core/sign-in.d.ts +1 -2
- package/build/core/sign-in.js +5 -14
- package/build/core/sign-up.d.ts +2 -0
- package/build/core/sign-up.js +2 -1
- package/build/core/storage/index.d.ts +4 -2
- package/build/core/storage/index.js +36 -57
- package/build/core/storage/local/storage.d.ts +1 -1
- package/build/core/storage/synced/obj-files-gc.d.ts +1 -4
- package/build/core/storage/synced/obj-files-gc.js +1 -18
- package/build/core/storage/synced/obj-files.d.ts +11 -1
- package/build/core/storage/synced/obj-files.js +59 -34
- package/build/core/storage/synced/obj-status.d.ts +19 -7
- package/build/core/storage/synced/obj-status.js +158 -83
- package/build/core/storage/synced/storage.d.ts +7 -2
- package/build/core/storage/synced/storage.js +38 -15
- package/build/core/storage/synced/upsyncer.d.ts +4 -4
- package/build/core/storage/synced/upsyncer.js +14 -9
- 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/exceptions.d.ts +13 -1
- package/build/lib-client/3nstorage/exceptions.js +9 -3
- package/build/lib-client/3nstorage/service.d.ts +6 -2
- package/build/lib-client/3nstorage/service.js +33 -17
- package/build/lib-client/3nstorage/util/file-based-json.js +2 -1
- package/build/lib-client/3nstorage/util/for-arrays.d.ts +1 -0
- package/build/lib-client/3nstorage/util/for-arrays.js +32 -0
- package/build/lib-client/3nstorage/xsp-fs/common.d.ts +5 -4
- package/build/lib-client/3nstorage/xsp-fs/common.js +1 -0
- 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 +14 -20
- package/build/lib-client/3nstorage/xsp-fs/folder-node.d.ts +16 -5
- package/build/lib-client/3nstorage/xsp-fs/folder-node.js +238 -68
- package/build/lib-client/3nstorage/xsp-fs/fs.d.ts +18 -17
- package/build/lib-client/3nstorage/xsp-fs/fs.js +32 -37
- package/build/lib-client/3nstorage/xsp-fs/node-in-fs.d.ts +15 -11
- package/build/lib-client/3nstorage/xsp-fs/node-in-fs.js +72 -22
- package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v1.js +1 -1
- package/build/lib-client/local-files/device-fs.js +11 -11
- 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-client/user-with-mid-session.d.ts +2 -1
- package/build/lib-client/user-with-mid-session.js +7 -1
- package/build/lib-common/async-fs-node.js +8 -8
- package/build/lib-common/exceptions/file.d.ts +4 -2
- package/build/lib-common/exceptions/file.js +24 -58
- package/build/lib-common/ipc/generic-ipc.js +5 -4
- package/build/lib-common/objs-on-disk/file-layout.js +1 -1
- package/build/lib-common/objs-on-disk/utils.js +1 -1
- package/build/lib-common/service-api/3nstorage/owner.d.ts +8 -9
- package/build/lib-common/service-api/3nstorage/owner.js +2 -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 +3 -2
- package/protos/file.proto +23 -7
- package/protos/fs.proto +27 -13
- package/build/core/id-manager.d.ts +0 -46
|
@@ -18,10 +18,13 @@
|
|
|
18
18
|
|
|
19
19
|
declare namespace web3n.files {
|
|
20
20
|
|
|
21
|
-
interface FileException extends RuntimeException {
|
|
21
|
+
interface FileException extends RuntimeException, FileExceptionFlag {
|
|
22
22
|
type: 'file';
|
|
23
23
|
code: string|undefined;
|
|
24
24
|
path: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface FileExceptionFlag {
|
|
25
28
|
notFound?: true;
|
|
26
29
|
alreadyExists?: true;
|
|
27
30
|
notDirectory?: true;
|
|
@@ -48,19 +51,13 @@ declare namespace web3n.files {
|
|
|
48
51
|
alreadyExists: 'EEXIST';
|
|
49
52
|
notDirectory: 'ENOTDIR';
|
|
50
53
|
notFile: 'ENOTFILE';
|
|
51
|
-
notLink: 'not-link';
|
|
52
54
|
isDirectory: 'EISDIR';
|
|
53
55
|
notEmpty: 'ENOTEMPTY';
|
|
54
56
|
endOfFile: 'EEOF';
|
|
55
57
|
opNotPermitted: 'EPERM';
|
|
56
58
|
busy: 'EBUSY';
|
|
57
59
|
ioError: 'EIO';
|
|
58
|
-
concurrentUpdate: 'concurrent-update';
|
|
59
|
-
parsingError: 'parsing-error';
|
|
60
60
|
notImplemented: 'ENOSYS';
|
|
61
|
-
isEndless: 'is-endless';
|
|
62
|
-
storageClosed: 'storage-closed';
|
|
63
|
-
versionMismatch: 'version-mismatch';
|
|
64
61
|
}
|
|
65
62
|
|
|
66
63
|
interface FSSyncException extends RuntimeException {
|
|
@@ -423,9 +420,13 @@ declare namespace web3n.files {
|
|
|
423
420
|
|
|
424
421
|
interface ReadonlyFileVersionedAPI {
|
|
425
422
|
|
|
426
|
-
getXAttr(
|
|
423
|
+
getXAttr(
|
|
424
|
+
xaName: string, flags?: VersionedReadFlags
|
|
425
|
+
): Promise<{ attr: any; version: number; }>;
|
|
427
426
|
|
|
428
|
-
listXAttrs(
|
|
427
|
+
listXAttrs(
|
|
428
|
+
flags?: VersionedReadFlags
|
|
429
|
+
): Promise<{ lst: string[]; version: number; }>;
|
|
429
430
|
|
|
430
431
|
/**
|
|
431
432
|
* This returns a promise, resolvable to either non-empty byte array, or
|
|
@@ -436,34 +437,51 @@ declare namespace web3n.files {
|
|
|
436
437
|
* @param end optional parameter, setting an end of read. If end is
|
|
437
438
|
* greater than file length, all available bytes are read. If parameter
|
|
438
439
|
* is missing, read will be done to file's end.
|
|
440
|
+
* @param flags are optional flags to read archived or remote versions.
|
|
439
441
|
*/
|
|
440
442
|
readBytes(
|
|
441
|
-
start?: number, end?: number
|
|
443
|
+
start?: number, end?: number, flags?: VersionedReadFlags
|
|
442
444
|
): Promise<{ bytes: Uint8Array|undefined; version: number; }>;
|
|
443
445
|
|
|
444
446
|
/**
|
|
445
447
|
* This returns a promise, resolvable to text, read from file, assuming
|
|
446
448
|
* utf8 encoding.
|
|
449
|
+
* @param flags are optional flags to read archived or remote versions.
|
|
447
450
|
*/
|
|
448
|
-
readTxt(
|
|
451
|
+
readTxt(
|
|
452
|
+
flags?: VersionedReadFlags
|
|
453
|
+
): Promise<{ txt: string; version: number; }>;
|
|
449
454
|
|
|
450
455
|
/**
|
|
451
456
|
* This returns a promise, resolvable to json, read from file
|
|
457
|
+
* @param flags are optional flags to read archived or remote versions.
|
|
452
458
|
*/
|
|
453
|
-
readJSON<T>(
|
|
459
|
+
readJSON<T>(
|
|
460
|
+
flags?: VersionedReadFlags
|
|
461
|
+
): Promise<{ json: T; version: number; }>;
|
|
454
462
|
|
|
455
463
|
/**
|
|
456
464
|
* This returns a promise, resolvable to bytes source with seek, which
|
|
457
465
|
* allows random reads, and a file version
|
|
466
|
+
* @param flags are optional flags to read archived or remote versions.
|
|
458
467
|
*/
|
|
459
|
-
getByteSource(
|
|
468
|
+
getByteSource(
|
|
469
|
+
flags?: VersionedReadFlags
|
|
470
|
+
): Promise<{ src: FileByteSource; version: number; }>;
|
|
460
471
|
|
|
461
|
-
listVersions(
|
|
472
|
+
listVersions(
|
|
473
|
+
flags?: VersionedReadFlags
|
|
474
|
+
): Promise<{ current?: number; archived?: number[]; }>;
|
|
462
475
|
|
|
463
476
|
sync?: ReadonlyFileSyncAPI;
|
|
464
477
|
|
|
465
478
|
}
|
|
466
479
|
|
|
480
|
+
interface VersionedReadFlags {
|
|
481
|
+
archivedVersion?: number;
|
|
482
|
+
remoteVersion?: number;
|
|
483
|
+
}
|
|
484
|
+
|
|
467
485
|
interface WritableFileVersionedAPI extends ReadonlyFileVersionedAPI {
|
|
468
486
|
|
|
469
487
|
/**
|
|
@@ -975,7 +993,7 @@ declare namespace web3n.files {
|
|
|
975
993
|
|
|
976
994
|
}
|
|
977
995
|
|
|
978
|
-
interface
|
|
996
|
+
interface VersionedFileWriteFlags extends FileFlags {
|
|
979
997
|
|
|
980
998
|
/**
|
|
981
999
|
* currentVersion flag is optional. This flag is applicable to existing
|
|
@@ -989,33 +1007,42 @@ declare namespace web3n.files {
|
|
|
989
1007
|
interface ReadonlyFSVersionedAPI {
|
|
990
1008
|
|
|
991
1009
|
getXAttr(
|
|
992
|
-
path: string, xaName: string
|
|
1010
|
+
path: string, xaName: string, flags?: VersionedReadFlags
|
|
993
1011
|
): Promise<{ attr: any; version: number; }>;
|
|
994
1012
|
|
|
995
|
-
listXAttrs(
|
|
1013
|
+
listXAttrs(
|
|
1014
|
+
path: string, flags?: VersionedReadFlags
|
|
1015
|
+
): Promise<{ lst: string[]; version: number; }>;
|
|
996
1016
|
|
|
997
1017
|
/**
|
|
998
1018
|
* This returns a promise, resolvable to a list of informational objects
|
|
999
1019
|
* for entries in the folder, and a folder's version.
|
|
1000
1020
|
* @param path of a folder that should be listed
|
|
1021
|
+
* @param flags are optional flags to read archived or remote versions.
|
|
1001
1022
|
*/
|
|
1002
1023
|
listFolder(
|
|
1003
|
-
path: string
|
|
1024
|
+
path: string, flags?: VersionedReadFlags
|
|
1004
1025
|
): Promise<{ lst: ListingEntry[]; version: number; }>;
|
|
1005
1026
|
|
|
1006
1027
|
/**
|
|
1007
1028
|
* This returns a promise, resolvable to json, read from file, and a
|
|
1008
1029
|
* version of file.
|
|
1009
1030
|
* @param path of a file from which to read json
|
|
1031
|
+
* @param flags are optional flags to read archived or remote versions.
|
|
1010
1032
|
*/
|
|
1011
|
-
readJSONFile<T>(
|
|
1033
|
+
readJSONFile<T>(
|
|
1034
|
+
path: string, flags?: VersionedReadFlags
|
|
1035
|
+
): Promise<{ json: T; version: number; }>;
|
|
1012
1036
|
|
|
1013
1037
|
/**
|
|
1014
1038
|
* This returns a promise, resolvable to text, read from file, assuming
|
|
1015
1039
|
* utf8 encoding, and version of file.
|
|
1016
1040
|
* @param path of a file from which to read text
|
|
1041
|
+
* @param flags are optional flags to read archived or remote versions.
|
|
1017
1042
|
*/
|
|
1018
|
-
readTxtFile(
|
|
1043
|
+
readTxtFile(
|
|
1044
|
+
path: string, flags?: VersionedReadFlags
|
|
1045
|
+
): Promise<{ txt: string; version: number; }>;
|
|
1019
1046
|
|
|
1020
1047
|
/**
|
|
1021
1048
|
* This returns a promise, resolvable to bytes, that is either non-empty
|
|
@@ -1027,18 +1054,21 @@ declare namespace web3n.files {
|
|
|
1027
1054
|
* @param end optional parameter, setting an end of read. If end is
|
|
1028
1055
|
* greater than file length, all available bytes are read. If parameter
|
|
1029
1056
|
* is missing, read will be done to file's end.
|
|
1057
|
+
* @param flags are optional flags to read archived or remote versions.
|
|
1030
1058
|
*/
|
|
1031
1059
|
readBytes(
|
|
1032
|
-
path: string, start?: number, end?: number
|
|
1060
|
+
path: string, start?: number, end?: number,
|
|
1061
|
+
flags?: VersionedReadFlags
|
|
1033
1062
|
): Promise<{ bytes: Uint8Array|undefined; version: number; }>;
|
|
1034
1063
|
|
|
1035
1064
|
/**
|
|
1036
1065
|
* This returns a promise, resolvable to bytes source with seek, which
|
|
1037
1066
|
* allows random reads, and a file version
|
|
1038
1067
|
* @param path of a file from which to read bytes
|
|
1068
|
+
* @param flags are optional flags to read archived or remote versions.
|
|
1039
1069
|
*/
|
|
1040
1070
|
getByteSource(
|
|
1041
|
-
path: string
|
|
1071
|
+
path: string, flags?: VersionedReadFlags
|
|
1042
1072
|
): Promise<{ src: FileByteSource; version: number; }>;
|
|
1043
1073
|
|
|
1044
1074
|
listVersions(
|
|
@@ -1068,7 +1098,7 @@ declare namespace web3n.files {
|
|
|
1068
1098
|
* exclusive=false.
|
|
1069
1099
|
*/
|
|
1070
1100
|
writeJSONFile(
|
|
1071
|
-
path: string, json: any, flags?:
|
|
1101
|
+
path: string, json: any, flags?: VersionedFileWriteFlags
|
|
1072
1102
|
): Promise<number>;
|
|
1073
1103
|
|
|
1074
1104
|
/**
|
|
@@ -1080,7 +1110,7 @@ declare namespace web3n.files {
|
|
|
1080
1110
|
* exclusive=false.
|
|
1081
1111
|
*/
|
|
1082
1112
|
writeTxtFile(
|
|
1083
|
-
path: string, txt: string, flags?:
|
|
1113
|
+
path: string, txt: string, flags?: VersionedFileWriteFlags
|
|
1084
1114
|
): Promise<number>;
|
|
1085
1115
|
|
|
1086
1116
|
/**
|
|
@@ -1092,7 +1122,7 @@ declare namespace web3n.files {
|
|
|
1092
1122
|
* exclusive=false.
|
|
1093
1123
|
*/
|
|
1094
1124
|
writeBytes(
|
|
1095
|
-
path: string, bytes: Uint8Array, flags?:
|
|
1125
|
+
path: string, bytes: Uint8Array, flags?: VersionedFileWriteFlags
|
|
1096
1126
|
): Promise<number>;
|
|
1097
1127
|
|
|
1098
1128
|
/**
|
|
@@ -1103,7 +1133,7 @@ declare namespace web3n.files {
|
|
|
1103
1133
|
* exclusive=false, truncate=true.
|
|
1104
1134
|
*/
|
|
1105
1135
|
getByteSink(
|
|
1106
|
-
path: string, flags?:
|
|
1136
|
+
path: string, flags?: VersionedFileWriteFlags
|
|
1107
1137
|
): Promise<{ sink: FileByteSink; version: number; }>;
|
|
1108
1138
|
|
|
1109
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);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { StorageGetter, FolderInJSON } from '../../../../lib-client/3nstorage/xsp-fs/common';
|
|
2
2
|
import { AsyncSBoxCryptor } from 'xsp-files';
|
|
3
3
|
import { MsgOnDisk } from '../msg-on-disk';
|
|
4
|
+
import { LogError } from '../../../../lib-client/logging/log-to-file';
|
|
4
5
|
declare type ReadonlyFS = web3n.files.ReadonlyFS;
|
|
5
|
-
export declare function fsForAttachments(msg: MsgOnDisk, rootJson: FolderInJSON, storages: StorageGetter, cryptor: AsyncSBoxCryptor): ReadonlyFS;
|
|
6
|
+
export declare function fsForAttachments(msg: MsgOnDisk, rootJson: FolderInJSON, storages: StorageGetter, cryptor: AsyncSBoxCryptor, logError: LogError): ReadonlyFS;
|
|
6
7
|
export {};
|
|
@@ -20,10 +20,11 @@ exports.fsForAttachments = void 0;
|
|
|
20
20
|
const common_1 = require("../../../../lib-client/3nstorage/xsp-fs/common");
|
|
21
21
|
const fs_1 = require("../../../../lib-client/3nstorage/xsp-fs/fs");
|
|
22
22
|
class AttachmentStore {
|
|
23
|
-
constructor(msg, getStorages, cryptor) {
|
|
23
|
+
constructor(msg, getStorages, cryptor, logError) {
|
|
24
24
|
this.msg = msg;
|
|
25
25
|
this.getStorages = getStorages;
|
|
26
26
|
this.cryptor = cryptor;
|
|
27
|
+
this.logError = logError;
|
|
27
28
|
this.type = 'asmail-msg';
|
|
28
29
|
this.versioned = false;
|
|
29
30
|
this.nodes = new common_1.NodesContainer();
|
|
@@ -66,8 +67,8 @@ class AttachmentStore {
|
|
|
66
67
|
}
|
|
67
68
|
Object.freeze(AttachmentStore.prototype);
|
|
68
69
|
Object.freeze(AttachmentStore);
|
|
69
|
-
function fsForAttachments(msg, rootJson, storages, cryptor) {
|
|
70
|
-
const storage = new AttachmentStore(msg, storages, cryptor);
|
|
70
|
+
function fsForAttachments(msg, rootJson, storages, cryptor, logError) {
|
|
71
|
+
const storage = new AttachmentStore(msg, storages, cryptor, logError);
|
|
71
72
|
const fs = fs_1.XspFS.fromASMailMsgRootFromJSON(storage, rootJson, 'attachments');
|
|
72
73
|
return fs;
|
|
73
74
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2015 - 2020 3NSoft Inc.
|
|
3
|
+
Copyright (C) 2015 - 2020, 2022 3NSoft Inc.
|
|
4
4
|
|
|
5
5
|
This program is free software: you can redistribute it and/or modify it under
|
|
6
6
|
the terms of the GNU General Public License as published by the Free Software
|
|
@@ -297,7 +297,7 @@ class InboxOnServer {
|
|
|
297
297
|
}
|
|
298
298
|
const attachments = msg.attachmentsJSON;
|
|
299
299
|
if (attachments) {
|
|
300
|
-
m.attachments = (0, fs_1.fsForAttachments)(msgOnDisk, attachments, this.storages, this.cryptor);
|
|
300
|
+
m.attachments = (0, fs_1.fsForAttachments)(msgOnDisk, attachments, this.storages, this.cryptor, this.logError);
|
|
301
301
|
}
|
|
302
302
|
return m;
|
|
303
303
|
}
|
|
@@ -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
|