libves 3.0.0 → 3.0.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.
- package/libVES.node.js +66 -25
- package/libves-3.0.2.tgz +0 -0
- package/package.json +1 -1
- package/libves-3.0.0.tgz +0 -0
package/libVES.node.js
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
*
|
|
28
28
|
* @title libVES
|
|
29
29
|
* @dev A JavaScript end-to-end encryption interface to VESvault REST API
|
|
30
|
-
* @version 3.
|
|
30
|
+
* @version 3.02
|
|
31
31
|
*
|
|
32
32
|
* @dev Official source code: https://github.com/vesvault/libVES
|
|
33
33
|
*
|
|
@@ -63,7 +63,7 @@ libVES.prototype = {
|
|
|
63
63
|
keyOptions: {namedCurve: 'P-521'},
|
|
64
64
|
textCipher: 'AES256GCMp',
|
|
65
65
|
defaultHash: 'SHA256',
|
|
66
|
-
propagators:
|
|
66
|
+
propagators: null,
|
|
67
67
|
request: function(method,uri,body,optns) {
|
|
68
68
|
var self = this;
|
|
69
69
|
if (!optns) optns = {};
|
|
@@ -266,6 +266,7 @@ libVES.prototype = {
|
|
|
266
266
|
for (var kid in this.unlockedKeys) lock.push(this.unlockedKeys[kid].then(function(k) {
|
|
267
267
|
return k.lock();
|
|
268
268
|
}).catch(function() {}));
|
|
269
|
+
this.propagators = null;
|
|
269
270
|
return Promise.all(lock).then(function() {
|
|
270
271
|
return true;
|
|
271
272
|
});
|
|
@@ -425,6 +426,20 @@ libVES.prototype = {
|
|
|
425
426
|
});
|
|
426
427
|
});
|
|
427
428
|
},
|
|
429
|
+
getPropagators: function() {
|
|
430
|
+
if (!this.propagators) {
|
|
431
|
+
let xid = (this.externalId ?? this.email);
|
|
432
|
+
this.propagators = (xid?.match(/^[^\!]+\@\w/) ? Promise.resolve(xid.replace(/\!.*/, '')) : this.me().then((me) => me.getEmail())).then((xid) => {
|
|
433
|
+
if (!xid) return [];
|
|
434
|
+
let prop = new libVES.VaultKey({externals: {domain: '.propagate', externalId: xid.toLowerCase()}}, this);
|
|
435
|
+
return prop.getId().then(() => [prop]);
|
|
436
|
+
}).catch((er) => {
|
|
437
|
+
if (er?.code == 'NotFound' || er?.code == 'Unauthorized') return [];
|
|
438
|
+
throw er;
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
return Promise.resolve(this.propagators);
|
|
442
|
+
},
|
|
428
443
|
getUserKeys: function(usr) {
|
|
429
444
|
var self = this;
|
|
430
445
|
return usr.getActiveVaultKeys().catch(function(e) {
|
|
@@ -459,8 +474,7 @@ libVES.prototype = {
|
|
|
459
474
|
}).catch(function(e) {
|
|
460
475
|
if (e.code != 'NotFound') throw e;
|
|
461
476
|
var sh = self.type == 'secondary' ? [self.me(), self.getVaultKey()] : [self.me()];
|
|
462
|
-
|
|
463
|
-
return sh;
|
|
477
|
+
return self.getPropagators().then((props) => sh.concat(props)).catch((er) => sh);
|
|
464
478
|
}).then(function(sh) {
|
|
465
479
|
return Promise.all(sh);
|
|
466
480
|
}).then(function(sh) {
|
|
@@ -875,11 +889,20 @@ libVES.prototype = {
|
|
|
875
889
|
return vkey.rekey(optns);
|
|
876
890
|
});
|
|
877
891
|
else return vkey.getVaultItems().then(function(vis) {
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
892
|
+
return Promise.all([user.getActiveVaultKeys(), vkey.getExternals().then((exts) => {
|
|
893
|
+
let ckey = new libVES.VaultKey({externals: exts}, self);
|
|
894
|
+
return ckey.getType().then(() => [ckey]).catch((er) => {
|
|
895
|
+
if (er?.code != 'NotFound') throw er;
|
|
896
|
+
return [];
|
|
897
|
+
});
|
|
898
|
+
})]).then((klists) => {
|
|
899
|
+
let ks = (klists[0] ?? []).concat(klists[1]);
|
|
900
|
+
return Promise.all(ks.map((k) => k.getType())).then((ktypes) => ks.filter((k, i) => ktypes[i] != 'temp'));
|
|
901
|
+
}).then((ks) => self.elevateAuth().then(function(optns) {
|
|
902
|
+
return Promise.all(vis.map(function(vi, i) {
|
|
903
|
+
return vi.reshareWith(ks, undefined, optns);
|
|
904
|
+
}));
|
|
905
|
+
}));
|
|
883
906
|
});
|
|
884
907
|
});
|
|
885
908
|
});
|
|
@@ -4601,7 +4624,7 @@ libVES.Vault = class extends libVES.EventTarget {
|
|
|
4601
4624
|
fields ||= {};
|
|
4602
4625
|
if (ref.externalId) fields.externals = [{domain: (this.domain = String(ref.domain)), externalId: (this.externalId = String(ref.externalId))}];
|
|
4603
4626
|
this.email = ref.email || '';
|
|
4604
|
-
if (ref.email) fields.
|
|
4627
|
+
if (ref.email) fields.user = {email: this.email};
|
|
4605
4628
|
if (ref.version) this.version = fields.id = Number(ref.version);
|
|
4606
4629
|
if (!fields.id) fields.type = this.externalId ? 'secondary' : 'current';
|
|
4607
4630
|
this.vaultKey = new libVES.VaultKey(fields, ves);
|
|
@@ -4650,22 +4673,30 @@ libVES.Vault = class extends libVES.EventTarget {
|
|
|
4650
4673
|
return this.objects(optns).then((objs) => objs.filter((obj) => (obj instanceof libVES.Vault)));
|
|
4651
4674
|
}
|
|
4652
4675
|
|
|
4676
|
+
reauth() {
|
|
4677
|
+
clearTimeout(this.refreshTmout);
|
|
4678
|
+
return this.vaultKey.loadFields({encSessionToken: true}, true, {token: ''}).then((flds) => this.vaultKey.setFields(flds)).then(() => this.vaultKey.getSessionToken()).then((tk) => {
|
|
4679
|
+
this.vaultKey.VES.token = tk;
|
|
4680
|
+
return this;
|
|
4681
|
+
});
|
|
4682
|
+
}
|
|
4683
|
+
|
|
4653
4684
|
_setunlock(reauth) {
|
|
4654
4685
|
this.current = true;
|
|
4655
|
-
this.owner = this.externalId[0] != '!';
|
|
4686
|
+
this.owner = this.externalId?.[0] != '!';
|
|
4656
4687
|
this.lock(600);
|
|
4657
4688
|
let rf;
|
|
4658
|
-
if (reauth !== false) (rf = (tmout) => {
|
|
4689
|
+
if (reauth !== false && this.externalId) (rf = (tmout) => {
|
|
4659
4690
|
this.refreshTmout = setTimeout(() => {
|
|
4660
|
-
this.
|
|
4661
|
-
this.vaultKey.VES.token = tk;
|
|
4662
|
-
rf();
|
|
4663
|
-
}).catch((er) => {
|
|
4691
|
+
this.reauth().then(() => rf()).catch((er) => {
|
|
4664
4692
|
console.log(er);
|
|
4665
4693
|
rf(60000);
|
|
4666
4694
|
});
|
|
4667
4695
|
}, (tmout || 14400000));
|
|
4668
4696
|
})();
|
|
4697
|
+
if (this.appUrl === undefined) try {
|
|
4698
|
+
this.appUrl = document.location.origin;
|
|
4699
|
+
} catch(er) {}
|
|
4669
4700
|
return this;
|
|
4670
4701
|
}
|
|
4671
4702
|
|
|
@@ -4759,8 +4790,9 @@ libVES.Vault = class extends libVES.EventTarget {
|
|
|
4759
4790
|
if (!(refs instanceof Array)) refs = [refs];
|
|
4760
4791
|
refs = refs.map((ref) => libVES.Vault.toRef(ref, ves)).filter((ref) => ref);
|
|
4761
4792
|
if (owner) {
|
|
4762
|
-
if (
|
|
4763
|
-
refs.push({
|
|
4793
|
+
if (ves.externalId) refs.push({domain: ves.domain, externalId: ves.externalId});
|
|
4794
|
+
else if (ves.user) refs.push({email: ves.user});
|
|
4795
|
+
else throw new libVES.Error.Unauthorized('The vault is locked');
|
|
4764
4796
|
}
|
|
4765
4797
|
return refs;
|
|
4766
4798
|
}
|
|
@@ -4837,6 +4869,14 @@ libVES.Vault = class extends libVES.EventTarget {
|
|
|
4837
4869
|
return new libVES.EventTracker(this);
|
|
4838
4870
|
}
|
|
4839
4871
|
|
|
4872
|
+
toAppRefs(refs, ves, owner) {
|
|
4873
|
+
let shares = libVES.Vault.toRefs(refs, ves, owner);
|
|
4874
|
+
if (this.appUrl !== undefined) shares.map((share) => {
|
|
4875
|
+
if (share.appUrl === undefined) share.appUrl = this.appUrl;
|
|
4876
|
+
});
|
|
4877
|
+
return shares;
|
|
4878
|
+
}
|
|
4879
|
+
|
|
4840
4880
|
toString() {
|
|
4841
4881
|
return 'libVES.Vault(' + (this.uri() ?? '[pending]') + ')';
|
|
4842
4882
|
}
|
|
@@ -4925,7 +4965,8 @@ libVES.EventTracker = class {
|
|
|
4925
4965
|
case 'vaultItem.created':
|
|
4926
4966
|
return itemfn('create');
|
|
4927
4967
|
case 'vaultItem.listening':
|
|
4928
|
-
|
|
4968
|
+
case 'vaultKey.listening':
|
|
4969
|
+
return itemfn('change', attn !== false);
|
|
4929
4970
|
case 'session.created':
|
|
4930
4971
|
return e.getFields({session: {id: true, remote: true, userAgent: true, vaultKey: {id: true}, user: {id: true}}}).then((flds) => {
|
|
4931
4972
|
if (!flds?.session) return null;
|
|
@@ -5005,7 +5046,7 @@ libVES.Item = class extends libVES.EventTarget {
|
|
|
5005
5046
|
put(value, shares) {
|
|
5006
5047
|
if (value == null) return Promise.reject(new libVES.Error.InvalidValue('The item value cannot be empty'));
|
|
5007
5048
|
let prref;
|
|
5008
|
-
return (shares ? Promise.resolve(
|
|
5049
|
+
return (shares ? Promise.resolve(this.vault.toAppRefs(shares, this.vaultItem.VES, true)) : this.share().then((shares) => {
|
|
5009
5050
|
let owner = shares.reduce((cur, sh) => (cur || ((sh.owner && sh.externalId?.match(/@/)) ? sh : null)), null);
|
|
5010
5051
|
if (owner && owner.uri() != this.vault.uri()) shares.push(this.vault.vault({domain: '.admin', externalId: owner.externalId}));
|
|
5011
5052
|
return shares;
|
|
@@ -5067,7 +5108,7 @@ libVES.Item = class extends libVES.EventTarget {
|
|
|
5067
5108
|
let sh = new libVES.Vault((flds?.externals?.[0] ?? flds?.user?.email), this.vaultItem.VES, flds);
|
|
5068
5109
|
if (sh) return sh.verify();
|
|
5069
5110
|
}))))).then((shares) => shares.filter((sh) => sh)).then((shares) => {
|
|
5070
|
-
this.provisional.share = this.provisional.share.concat(shares);
|
|
5111
|
+
this.provisional.share = this.provisional.share.concat(this.vault.toAppRefs(shares));
|
|
5071
5112
|
if (del) {
|
|
5072
5113
|
let uris = {};
|
|
5073
5114
|
shares.map((sh) => uris[sh.uri()] = sh);
|
|
@@ -5083,7 +5124,7 @@ libVES.Item = class extends libVES.EventTarget {
|
|
|
5083
5124
|
if (shares) return this._provShare(shares, true);
|
|
5084
5125
|
return Promise.resolve(this.provisional.share);
|
|
5085
5126
|
}
|
|
5086
|
-
return (shares ? (this._reset(), this.vaultItem.shareWith(
|
|
5127
|
+
return (shares ? (this._reset(), this.vaultItem.shareWith(this.vault.toAppRefs(shares, this.vaultItem.VES, true))) : Promise.resolve(null)).then(() => {
|
|
5087
5128
|
let result = [];
|
|
5088
5129
|
let found = {};
|
|
5089
5130
|
let admins = {};
|
|
@@ -5121,7 +5162,7 @@ libVES.Item = class extends libVES.EventTarget {
|
|
|
5121
5162
|
return this._entries().then(() => this.vaultItem.getShareVaultKeys()).then((vkeys) => {
|
|
5122
5163
|
if (!vkeys) throw new libVES.Error.InvalidKey('Not authorized to share this item');
|
|
5123
5164
|
if (!shares) return true;
|
|
5124
|
-
|
|
5165
|
+
this.vault.toAppRefs(shares, this.vaultItem.VES).map((share) => vkeys.push(share));
|
|
5125
5166
|
this._reset();
|
|
5126
5167
|
return this.vaultItem.shareWith(vkeys);
|
|
5127
5168
|
}).then(() => true);
|
|
@@ -5145,7 +5186,7 @@ libVES.Item = class extends libVES.EventTarget {
|
|
|
5145
5186
|
|
|
5146
5187
|
delete() {
|
|
5147
5188
|
this._reset();
|
|
5148
|
-
return this.vaultItem.delete();
|
|
5189
|
+
return this.vaultItem.delete().then(() => true);
|
|
5149
5190
|
}
|
|
5150
5191
|
|
|
5151
5192
|
badauth() {
|
|
@@ -5270,6 +5311,6 @@ libVES.ItemCipher = class {
|
|
|
5270
5311
|
return this.item?.uri();
|
|
5271
5312
|
}
|
|
5272
5313
|
};
|
|
5273
|
-
libVES.version = '3.
|
|
5314
|
+
libVES.version = '3.02';
|
|
5274
5315
|
|
|
5275
5316
|
module.exports = libVES;
|
package/libves-3.0.2.tgz
ADDED
|
Binary file
|
package/package.json
CHANGED
package/libves-3.0.0.tgz
DELETED
|
Binary file
|