core-3nweb-client-lib 0.48.7 → 0.49.1
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/core/index.d.ts +1 -1
- package/build/core/index.js +3 -3
- package/build/core/startup/sign-in.d.ts +7 -5
- package/build/core/startup/sign-in.js +41 -5
- package/build/core/startup/sign-up.d.ts +2 -1
- package/build/core/startup/sign-up.js +6 -2
- package/build/protos/asmail.proto.js +6504 -3198
- package/build/protos/bytes.proto.js +695 -283
- package/build/protos/common.proto.js +312 -112
- package/build/protos/file.proto.js +2678 -1280
- package/build/protos/fs.proto.js +5520 -2706
- package/build/protos/ipc.proto.js +399 -155
- package/build/protos/json-ipc.proto.js +483 -195
- package/build/protos/storage.proto.js +468 -180
- package/package.json +2 -2
package/build/core/index.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ export declare class Core {
|
|
|
28
28
|
private isInitialized;
|
|
29
29
|
private constructor();
|
|
30
30
|
static make(conf: CoreConf, makeNet: MakeNet, makeResolver: ServiceLocatorMaker, makeCryptor: makeCryptor, random: AsyncRNG): Core;
|
|
31
|
-
start(): {
|
|
31
|
+
start(saveStorageKeyForAutologin?: (storageKey: Uint8Array) => void): {
|
|
32
32
|
capsForStartup: web3n.startup.W3N;
|
|
33
33
|
coreInit: Promise<string>;
|
|
34
34
|
coreAppsInit: Promise<void>;
|
package/build/core/index.js
CHANGED
|
@@ -53,11 +53,11 @@ class Core {
|
|
|
53
53
|
const core = new Core(makeNet, makeResolver, makeCryptor, random, dirs, logger, conf.signUpUrl);
|
|
54
54
|
return core;
|
|
55
55
|
}
|
|
56
|
-
start() {
|
|
56
|
+
start(saveStorageKeyForAutologin) {
|
|
57
57
|
const { promise: midPromise, resolve: midDone } = (0, deferred_1.defer)();
|
|
58
58
|
const { watchBoot, emitBootEvent } = makeForBootEvents();
|
|
59
|
-
const signUp = new sign_up_1.SignUp(this.signUpUrl, this.cryptor.cryptor, this.random, this.makeNet, this.appDirs.getUsersOnDisk, user => this.initForNewUser(user, midDone, emitBootEvent), watchBoot, this.logger.logError);
|
|
60
|
-
const signIn = new sign_in_1.SignIn(this.cryptor.cryptor, addr => this.initForExistingUserWithoutCache(addr, midDone, emitBootEvent), (addr, storageKey) => this.initForExistingUserWithCache(addr, storageKey, midDone, emitBootEvent), this.appDirs.getUsersOnDisk, watchBoot, this.logger.logError);
|
|
59
|
+
const signUp = new sign_up_1.SignUp(this.signUpUrl, this.cryptor.cryptor, this.random, this.makeNet, this.appDirs.getUsersOnDisk, user => this.initForNewUser(user, midDone, emitBootEvent), saveStorageKeyForAutologin, watchBoot, this.logger.logError);
|
|
60
|
+
const signIn = new sign_in_1.SignIn(this.cryptor.cryptor, addr => this.initForExistingUserWithoutCache(addr, midDone, emitBootEvent), (addr, storageKey) => this.initForExistingUserWithCache(addr, storageKey, midDone, emitBootEvent), this.appDirs.getUsersOnDisk, saveStorageKeyForAutologin, watchBoot, this.logger.logError);
|
|
61
61
|
const capsForStartup = {
|
|
62
62
|
signUp: signUp.exposedService(),
|
|
63
63
|
signIn: signIn.exposedService()
|
|
@@ -9,16 +9,18 @@ export type InitWithCache = (address: string, storageKey: GenerateKey) => Promis
|
|
|
9
9
|
type SignInService = web3n.startup.SignInService;
|
|
10
10
|
type ProgressCB = web3n.startup.ProgressCB;
|
|
11
11
|
export declare class SignIn {
|
|
12
|
-
private cryptor;
|
|
13
|
-
private startInitWithoutCache;
|
|
14
|
-
private initWithCache;
|
|
15
|
-
private getUsersOnDisk;
|
|
12
|
+
private readonly cryptor;
|
|
13
|
+
private readonly startInitWithoutCache;
|
|
14
|
+
private readonly initWithCache;
|
|
15
|
+
private readonly getUsersOnDisk;
|
|
16
|
+
private readonly saveStorageKeyForAutologin;
|
|
16
17
|
private readonly watchBoot;
|
|
17
18
|
private readonly logError;
|
|
18
19
|
private completeInitWithoutCache;
|
|
19
|
-
constructor(cryptor: Cryptor, startInitWithoutCache: StartInitWithoutCache, initWithCache: InitWithCache, getUsersOnDisk: GetUsersOnDisk, watchBoot: SignInService['watchBoot'], logError: LogError);
|
|
20
|
+
constructor(cryptor: Cryptor, startInitWithoutCache: StartInitWithoutCache, initWithCache: InitWithCache, getUsersOnDisk: GetUsersOnDisk, saveStorageKeyForAutologin: ((storageKey: Uint8Array) => void) | undefined, watchBoot: SignInService['watchBoot'], logError: LogError);
|
|
20
21
|
exposedService(): SignInService;
|
|
21
22
|
private startLoginToRemoteStorage;
|
|
23
|
+
private getAddressFromDisk;
|
|
22
24
|
private completeLoginAndLocalSetup;
|
|
23
25
|
private useExistingStorage;
|
|
24
26
|
private logAndWrap;
|
|
@@ -20,12 +20,14 @@ exports.SignIn = void 0;
|
|
|
20
20
|
exports.makeKeyGenProgressCB = makeKeyGenProgressCB;
|
|
21
21
|
const key_derivation_1 = require("../../lib-client/key-derivation");
|
|
22
22
|
const error_1 = require("../../lib-common/exceptions/error");
|
|
23
|
+
const canonical_address_1 = require("../../lib-common/canonical-address");
|
|
23
24
|
class SignIn {
|
|
24
|
-
constructor(cryptor, startInitWithoutCache, initWithCache, getUsersOnDisk, watchBoot, logError) {
|
|
25
|
+
constructor(cryptor, startInitWithoutCache, initWithCache, getUsersOnDisk, saveStorageKeyForAutologin, watchBoot, logError) {
|
|
25
26
|
this.cryptor = cryptor;
|
|
26
27
|
this.startInitWithoutCache = startInitWithoutCache;
|
|
27
28
|
this.initWithCache = initWithCache;
|
|
28
29
|
this.getUsersOnDisk = getUsersOnDisk;
|
|
30
|
+
this.saveStorageKeyForAutologin = saveStorageKeyForAutologin;
|
|
29
31
|
this.watchBoot = watchBoot;
|
|
30
32
|
this.logError = logError;
|
|
31
33
|
this.completeInitWithoutCache = undefined;
|
|
@@ -43,6 +45,10 @@ class SignIn {
|
|
|
43
45
|
}
|
|
44
46
|
async startLoginToRemoteStorage(address) {
|
|
45
47
|
try {
|
|
48
|
+
const addrOnDisk = await this.getAddressFromDisk(address);
|
|
49
|
+
if (addrOnDisk) {
|
|
50
|
+
throw new Error(`${address} exists on disk as ${addrOnDisk}`);
|
|
51
|
+
}
|
|
46
52
|
this.completeInitWithoutCache = await this.startInitWithoutCache(address);
|
|
47
53
|
return !!this.completeInitWithoutCache;
|
|
48
54
|
}
|
|
@@ -50,7 +56,12 @@ class SignIn {
|
|
|
50
56
|
throw await this.logAndWrap(err, 'Fail to start login to remote storage');
|
|
51
57
|
}
|
|
52
58
|
}
|
|
59
|
+
async getAddressFromDisk(address) {
|
|
60
|
+
const usersOnDisk = await this.getUsersOnDisk();
|
|
61
|
+
return usersOnDisk.find(existing => (0, canonical_address_1.areAddressesEqual)(existing, address));
|
|
62
|
+
}
|
|
53
63
|
async completeLoginAndLocalSetup(pass, progressCB) {
|
|
64
|
+
var _a;
|
|
54
65
|
if (!this.completeInitWithoutCache) {
|
|
55
66
|
throw new Error(`Call method startLoginToRemoteStorage() before calling this.`);
|
|
56
67
|
}
|
|
@@ -58,18 +69,43 @@ class SignIn {
|
|
|
58
69
|
const midKeyProgressCB = makeKeyGenProgressCB(0, 50, progressCB);
|
|
59
70
|
const midKeyGen = async (params) => (await (0, key_derivation_1.deriveMidKeyPair)(this.cryptor, pass, params, midKeyProgressCB)).skey;
|
|
60
71
|
const storeKeyProgressCB = makeKeyGenProgressCB(51, 100, progressCB);
|
|
61
|
-
|
|
62
|
-
|
|
72
|
+
let storeKey;
|
|
73
|
+
const storeKeyGen = async (params) => {
|
|
74
|
+
const key = await (0, key_derivation_1.deriveStorageSKey)(this.cryptor, pass, params, storeKeyProgressCB);
|
|
75
|
+
storeKey = new Uint8Array(key.length);
|
|
76
|
+
storeKey.set(key);
|
|
77
|
+
return key;
|
|
78
|
+
};
|
|
79
|
+
const ok = await this.completeInitWithoutCache(midKeyGen, storeKeyGen);
|
|
80
|
+
if (ok) {
|
|
81
|
+
(_a = this.saveStorageKeyForAutologin) === null || _a === void 0 ? void 0 : _a.call(this, storeKey);
|
|
82
|
+
}
|
|
83
|
+
return ok;
|
|
63
84
|
}
|
|
64
85
|
catch (err) {
|
|
65
86
|
throw await this.logAndWrap(err, 'Fail to initialize from a state without cache');
|
|
66
87
|
}
|
|
67
88
|
}
|
|
68
89
|
async useExistingStorage(user, pass, progressCB) {
|
|
90
|
+
var _a;
|
|
91
|
+
const addrOnDisk = await this.getAddressFromDisk(user);
|
|
92
|
+
if (addrOnDisk) {
|
|
93
|
+
user = addrOnDisk;
|
|
94
|
+
}
|
|
69
95
|
try {
|
|
96
|
+
let storeKey;
|
|
70
97
|
const storeKeyProgressCB = makeKeyGenProgressCB(0, 99, progressCB);
|
|
71
|
-
const storeKeyGen =
|
|
72
|
-
|
|
98
|
+
const storeKeyGen = async (params) => {
|
|
99
|
+
const key = await (0, key_derivation_1.deriveStorageSKey)(this.cryptor, pass, params, storeKeyProgressCB);
|
|
100
|
+
storeKey = new Uint8Array(key.length);
|
|
101
|
+
storeKey.set(key);
|
|
102
|
+
return key;
|
|
103
|
+
};
|
|
104
|
+
const ok = await this.initWithCache(user, storeKeyGen);
|
|
105
|
+
if (ok) {
|
|
106
|
+
(_a = this.saveStorageKeyForAutologin) === null || _a === void 0 ? void 0 : _a.call(this, storeKey);
|
|
107
|
+
}
|
|
108
|
+
return ok;
|
|
73
109
|
}
|
|
74
110
|
catch (err) {
|
|
75
111
|
throw await this.logAndWrap(err, 'Failing to start in a state with cache');
|
|
@@ -18,6 +18,7 @@ export declare class SignUp {
|
|
|
18
18
|
private readonly makeNet;
|
|
19
19
|
private readonly getUsersOnDisk;
|
|
20
20
|
private readonly initForNewUser;
|
|
21
|
+
private readonly saveStorageKeyForAutologin;
|
|
21
22
|
private readonly watchBoot;
|
|
22
23
|
private readonly logError;
|
|
23
24
|
private mid;
|
|
@@ -25,7 +26,7 @@ export declare class SignUp {
|
|
|
25
26
|
private serviceURL;
|
|
26
27
|
private netLazyInit;
|
|
27
28
|
private get net();
|
|
28
|
-
constructor(serviceURL: string, cryptor: Cryptor, random: AsyncRNG, makeNet: () => NetClient, getUsersOnDisk: GetUsersOnDisk, initForNewUser: (u: CreatedUser) => Promise<void>, watchBoot: SignUpService['watchBoot'], logError: LogError);
|
|
29
|
+
constructor(serviceURL: string, cryptor: Cryptor, random: AsyncRNG, makeNet: () => NetClient, getUsersOnDisk: GetUsersOnDisk, initForNewUser: (u: CreatedUser) => Promise<void>, saveStorageKeyForAutologin: ((storageKey: Uint8Array) => void) | undefined, watchBoot: SignUpService['watchBoot'], logError: LogError);
|
|
29
30
|
private setServiceURL;
|
|
30
31
|
private getAvailableDomains;
|
|
31
32
|
private getAvailableAddresses;
|
|
@@ -61,12 +61,13 @@ class SignUp {
|
|
|
61
61
|
}
|
|
62
62
|
return this.netLazyInit;
|
|
63
63
|
}
|
|
64
|
-
constructor(serviceURL, cryptor, random, makeNet, getUsersOnDisk, initForNewUser, watchBoot, logError) {
|
|
64
|
+
constructor(serviceURL, cryptor, random, makeNet, getUsersOnDisk, initForNewUser, saveStorageKeyForAutologin, watchBoot, logError) {
|
|
65
65
|
this.cryptor = cryptor;
|
|
66
66
|
this.random = random;
|
|
67
67
|
this.makeNet = makeNet;
|
|
68
68
|
this.getUsersOnDisk = getUsersOnDisk;
|
|
69
69
|
this.initForNewUser = initForNewUser;
|
|
70
|
+
this.saveStorageKeyForAutologin = saveStorageKeyForAutologin;
|
|
70
71
|
this.watchBoot = watchBoot;
|
|
71
72
|
this.logError = logError;
|
|
72
73
|
this.mid = undefined;
|
|
@@ -163,6 +164,8 @@ class SignUp {
|
|
|
163
164
|
if (!accountCreated) {
|
|
164
165
|
return false;
|
|
165
166
|
}
|
|
167
|
+
const storeKey = new Uint8Array(this.store.skey.length);
|
|
168
|
+
storeKey.set(this.store.skey);
|
|
166
169
|
this.initForNewUser({
|
|
167
170
|
address,
|
|
168
171
|
midSKey: {
|
|
@@ -171,7 +174,8 @@ class SignUp {
|
|
|
171
174
|
},
|
|
172
175
|
storeSKey: this.store.skey,
|
|
173
176
|
storeParams: this.store.params.kdParams
|
|
174
|
-
})
|
|
177
|
+
})
|
|
178
|
+
.then(() => { var _a; return (_a = this.saveStorageKeyForAutologin) === null || _a === void 0 ? void 0 : _a.call(this, storeKey); });
|
|
175
179
|
this.forgetKeys();
|
|
176
180
|
return true;
|
|
177
181
|
}
|