core-3nweb-client-lib 0.49.0 → 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.
@@ -20,6 +20,7 @@ export declare class SignIn {
20
20
  constructor(cryptor: Cryptor, startInitWithoutCache: StartInitWithoutCache, initWithCache: InitWithCache, getUsersOnDisk: GetUsersOnDisk, saveStorageKeyForAutologin: ((storageKey: Uint8Array) => void) | undefined, watchBoot: SignInService['watchBoot'], logError: LogError);
21
21
  exposedService(): SignInService;
22
22
  private startLoginToRemoteStorage;
23
+ private getAddressFromDisk;
23
24
  private completeLoginAndLocalSetup;
24
25
  private useExistingStorage;
25
26
  private logAndWrap;
@@ -20,6 +20,7 @@ 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
25
  constructor(cryptor, startInitWithoutCache, initWithCache, getUsersOnDisk, saveStorageKeyForAutologin, watchBoot, logError) {
25
26
  this.cryptor = cryptor;
@@ -44,6 +45,10 @@ class SignIn {
44
45
  }
45
46
  async startLoginToRemoteStorage(address) {
46
47
  try {
48
+ const addrOnDisk = await this.getAddressFromDisk(address);
49
+ if (addrOnDisk) {
50
+ throw new Error(`${address} exists on disk as ${addrOnDisk}`);
51
+ }
47
52
  this.completeInitWithoutCache = await this.startInitWithoutCache(address);
48
53
  return !!this.completeInitWithoutCache;
49
54
  }
@@ -51,6 +56,10 @@ class SignIn {
51
56
  throw await this.logAndWrap(err, 'Fail to start login to remote storage');
52
57
  }
53
58
  }
59
+ async getAddressFromDisk(address) {
60
+ const usersOnDisk = await this.getUsersOnDisk();
61
+ return usersOnDisk.find(existing => (0, canonical_address_1.areAddressesEqual)(existing, address));
62
+ }
54
63
  async completeLoginAndLocalSetup(pass, progressCB) {
55
64
  var _a;
56
65
  if (!this.completeInitWithoutCache) {
@@ -62,8 +71,10 @@ class SignIn {
62
71
  const storeKeyProgressCB = makeKeyGenProgressCB(51, 100, progressCB);
63
72
  let storeKey;
64
73
  const storeKeyGen = async (params) => {
65
- storeKey = await (0, key_derivation_1.deriveStorageSKey)(this.cryptor, pass, params, storeKeyProgressCB);
66
- return storeKey;
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;
67
78
  };
68
79
  const ok = await this.completeInitWithoutCache(midKeyGen, storeKeyGen);
69
80
  if (ok) {
@@ -77,12 +88,18 @@ class SignIn {
77
88
  }
78
89
  async useExistingStorage(user, pass, progressCB) {
79
90
  var _a;
91
+ const addrOnDisk = await this.getAddressFromDisk(user);
92
+ if (addrOnDisk) {
93
+ user = addrOnDisk;
94
+ }
80
95
  try {
81
96
  let storeKey;
82
97
  const storeKeyProgressCB = makeKeyGenProgressCB(0, 99, progressCB);
83
98
  const storeKeyGen = async (params) => {
84
- storeKey = await (0, key_derivation_1.deriveStorageSKey)(this.cryptor, pass, params, storeKeyProgressCB);
85
- return storeKey;
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;
86
103
  };
87
104
  const ok = await this.initWithCache(user, storeKeyGen);
88
105
  if (ok) {
@@ -164,7 +164,8 @@ class SignUp {
164
164
  if (!accountCreated) {
165
165
  return false;
166
166
  }
167
- const storeKey = this.store.skey;
167
+ const storeKey = new Uint8Array(this.store.skey.length);
168
+ storeKey.set(this.store.skey);
168
169
  this.initForNewUser({
169
170
  address,
170
171
  midSKey: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "core-3nweb-client-lib",
3
- "version": "0.49.0",
3
+ "version": "0.49.1",
4
4
  "description": "3NWeb client core library, embeddable into different environments",
5
5
  "main": "build/lib-index.js",
6
6
  "types": "build/lib-index.d.ts",