libves 2.1.1 → 2.3.0
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 +131 -11
- package/libves-2.3.0.tgz +0 -0
- package/package.json +3 -3
- package/libves-2.1.1.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 2.
|
|
30
|
+
* @version 2.03
|
|
31
31
|
*
|
|
32
32
|
* @dev Official source code: https://github.com/vesvault/libVES
|
|
33
33
|
*
|
|
@@ -141,7 +141,7 @@ libVES.prototype = {
|
|
|
141
141
|
});
|
|
142
142
|
},
|
|
143
143
|
logout: function() {
|
|
144
|
-
this.token = undefined;
|
|
144
|
+
this.token = this.userMe = this.vaultKey = undefined;
|
|
145
145
|
return this.lock();
|
|
146
146
|
},
|
|
147
147
|
delegate: function(optns) {
|
|
@@ -191,11 +191,13 @@ libVES.prototype = {
|
|
|
191
191
|
},
|
|
192
192
|
authorize: function(msg) {
|
|
193
193
|
var self = this;
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
return self
|
|
194
|
+
return this.logout().then(function() {
|
|
195
|
+
if (msg.token) self.token = msg.token;
|
|
196
|
+
if (msg.domain) self.domain = msg.domain;
|
|
197
|
+
if (msg.externalId) self.externalId = msg.externalId;
|
|
198
|
+
return (msg.VESkey ? self.unlock(msg.VESkey) : self.me()).then(function() {
|
|
199
|
+
return self;
|
|
200
|
+
});
|
|
199
201
|
});
|
|
200
202
|
},
|
|
201
203
|
carry: function(optns) {
|
|
@@ -2683,6 +2685,10 @@ libVES.Cipher.AES256CBC = function(rec) {
|
|
|
2683
2685
|
this.init(rec);
|
|
2684
2686
|
};
|
|
2685
2687
|
|
|
2688
|
+
libVES.Cipher.AES256CFB = function(rec) {
|
|
2689
|
+
this.init(rec);
|
|
2690
|
+
};
|
|
2691
|
+
|
|
2686
2692
|
libVES.Cipher.AES256GCM = function(rec) {
|
|
2687
2693
|
this.init(rec);
|
|
2688
2694
|
};
|
|
@@ -2713,6 +2719,7 @@ libVES.Cipher.AES.prototype = new libVES.Cipher({
|
|
|
2713
2719
|
});
|
|
2714
2720
|
|
|
2715
2721
|
libVES.Cipher.AES256CBC.prototype = new libVES.Cipher.AES({
|
|
2722
|
+
a: 'AES256CBC',
|
|
2716
2723
|
algo: 'AES-CBC',
|
|
2717
2724
|
keySize: 32,
|
|
2718
2725
|
ivSize: 16
|
|
@@ -2736,6 +2743,11 @@ libVES.Cipher.AES256CBC.info = function(chain,optns) {
|
|
|
2736
2743
|
return Promise.resolve({algorithm: {name: 'AES-CBC', length: 256}});
|
|
2737
2744
|
};
|
|
2738
2745
|
|
|
2746
|
+
libVES.Cipher.AES256CFB.prototype = new libVES.Cipher.AES({
|
|
2747
|
+
a: 'AES256CFB',
|
|
2748
|
+
algo: 'AES-CFB'
|
|
2749
|
+
});
|
|
2750
|
+
|
|
2739
2751
|
libVES.Cipher.AES256GCM.prototype = new libVES.Cipher.AES({
|
|
2740
2752
|
algo: 'AES-GCM',
|
|
2741
2753
|
keySize: 32,
|
|
@@ -2743,6 +2755,7 @@ libVES.Cipher.AES256GCM.prototype = new libVES.Cipher.AES({
|
|
|
2743
2755
|
});
|
|
2744
2756
|
|
|
2745
2757
|
libVES.Cipher.AES256GCMp.prototype = new libVES.Cipher.AES({
|
|
2758
|
+
a: 'AES256GCMp',
|
|
2746
2759
|
algo: 'AES-GCM',
|
|
2747
2760
|
keySize: 32,
|
|
2748
2761
|
ivSize: 12,
|
|
@@ -2764,6 +2777,7 @@ libVES.Cipher.AES256GCMp.prototype = new libVES.Cipher.AES({
|
|
|
2764
2777
|
});
|
|
2765
2778
|
|
|
2766
2779
|
libVES.Cipher.AES256GCM1K.prototype = new libVES.Cipher.AES({
|
|
2780
|
+
a: 'AES256GCM1K',
|
|
2767
2781
|
algo: 'AES-GCM',
|
|
2768
2782
|
keySize: 32,
|
|
2769
2783
|
ivSize: 12,
|
|
@@ -3204,9 +3218,12 @@ libVES.Delegate = {
|
|
|
3204
3218
|
} catch(e) {
|
|
3205
3219
|
window.alert(self.htmlBlockerMsg);
|
|
3206
3220
|
}
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3221
|
+
if (!self.listening) {
|
|
3222
|
+
window.addEventListener('message',self.listener.bind(self));
|
|
3223
|
+
window.addEventListener('focus',self.chkCancel.bind(self));
|
|
3224
|
+
window.addEventListener('beforeunload',self.cancel.bind(self));
|
|
3225
|
+
self.listening = true;
|
|
3226
|
+
}
|
|
3210
3227
|
window.clearInterval(self.popupInterval);
|
|
3211
3228
|
self.popupInterval = window.setInterval(self.chkCancel.bind(self),1000);
|
|
3212
3229
|
});
|
|
@@ -3458,8 +3475,12 @@ libVES.Flow.prototype.click = function(a) {
|
|
|
3458
3475
|
var self = this;
|
|
3459
3476
|
(a.origin == this.origin ? self.store() : self.addToken(a.href).then(function(url) {
|
|
3460
3477
|
a.href = url;
|
|
3461
|
-
})).
|
|
3478
|
+
})).catch(function(e) {
|
|
3479
|
+
if (!e || e.code != 'NotFound') throw e;
|
|
3480
|
+
}).then(function() {
|
|
3462
3481
|
document.location.href = a.href;
|
|
3482
|
+
}).catch(function(e) {
|
|
3483
|
+
console.log(e);
|
|
3463
3484
|
});
|
|
3464
3485
|
return false;
|
|
3465
3486
|
};
|
|
@@ -3540,4 +3561,103 @@ libVES.Flow.prototype.logout = function() {
|
|
|
3540
3561
|
return libVES.Flow.logout();
|
|
3541
3562
|
};
|
|
3542
3563
|
|
|
3564
|
+
|
|
3565
|
+
libVES.Auth = function(optns) {
|
|
3566
|
+
for (var k in optns) this[k] = optns[k];
|
|
3567
|
+
return this;
|
|
3568
|
+
};
|
|
3569
|
+
|
|
3570
|
+
libVES.Auth.prototype.getToken = function() {
|
|
3571
|
+
if (this.vaultItem) return Promise.all([this.vaultItem.getId(), this.vaultItem.getField('verifyToken')]).then(function(flds) {
|
|
3572
|
+
return 'vaultItem.' + flds[0] + '.' + flds[1];
|
|
3573
|
+
});
|
|
3574
|
+
else if (this.vaultKey) return Promise.all([this.vaultKey.getId(), this.vaultItem.getSessionToken()]).then(function(flds) {
|
|
3575
|
+
return 'vaultKey.' + flds[0] + '.' + flds[1];
|
|
3576
|
+
});
|
|
3577
|
+
else if ((VES = this.VES) && VES.token) return this.VES.getVaultKey().then(function(vkey) {
|
|
3578
|
+
return vkey.getId().then(function(id) {
|
|
3579
|
+
return 'vaultKey.' + id + '.' + VES.token;
|
|
3580
|
+
});
|
|
3581
|
+
});
|
|
3582
|
+
return Promise.reject({code: 'VESauth', message: 'No object to generate a VESauth token for'});
|
|
3583
|
+
};
|
|
3584
|
+
|
|
3585
|
+
libVES.Auth.prototype.getData = function(url, type) {
|
|
3586
|
+
return this.getToken().then(function(tkn) {
|
|
3587
|
+
return new Promise(function(resolve, reject) {
|
|
3588
|
+
var xhr = new XMLHttpRequest();
|
|
3589
|
+
xhr.open('GET', url);
|
|
3590
|
+
if (type) xhr.responseType = type;
|
|
3591
|
+
xhr.onreadystatechange = function() {
|
|
3592
|
+
switch(xhr.readyState) {
|
|
3593
|
+
case 4:
|
|
3594
|
+
if (xhr.status == 200) resolve(xhr.response);
|
|
3595
|
+
else reject({code: xhr.status, message: xhr.statusText});
|
|
3596
|
+
}
|
|
3597
|
+
};
|
|
3598
|
+
xhr.setRequestHeader('X-VES-Authorization', tkn);
|
|
3599
|
+
xhr.send();
|
|
3600
|
+
});
|
|
3601
|
+
});
|
|
3602
|
+
};
|
|
3603
|
+
|
|
3604
|
+
libVES.Auth.prototype.getJSON = function(url) {
|
|
3605
|
+
return this.getData(url, 'json').then(function(json) {
|
|
3606
|
+
var a = document.createElement('a');
|
|
3607
|
+
a.href = url;
|
|
3608
|
+
if (!a.hash) return json;
|
|
3609
|
+
var path = a.hash.split(/\//);
|
|
3610
|
+
for (var i = 1; i < path.length; i++) if (path[i]) {
|
|
3611
|
+
if (json instanceof Array) json = json[Number(path[i])];
|
|
3612
|
+
else if (json instanceof Object) json = json[path[i]];
|
|
3613
|
+
else return null;
|
|
3614
|
+
}
|
|
3615
|
+
return json;
|
|
3616
|
+
});
|
|
3617
|
+
};
|
|
3618
|
+
|
|
3619
|
+
libVES.Auth.prototype.auth = function(token) {
|
|
3620
|
+
return this.verify(token, true);
|
|
3621
|
+
};
|
|
3622
|
+
|
|
3623
|
+
libVES.Auth.prototype.verify = function(token, auth) {
|
|
3624
|
+
var tk = token.match(/^(\w*)\.(\d*)\.(.*)$/);
|
|
3625
|
+
if (!tk) return Promise.reject(new libVES.Error('VESauth', 'Invalid VESauth token'));
|
|
3626
|
+
var ves = new libVES({domain: (this.domain || '*'), token: tk[3]});
|
|
3627
|
+
if (tk[1] == 'vaultItem') {
|
|
3628
|
+
if (auth) return Promise.reject(new libVES.Error('VESauth', 'Verify token cannot be used for authentication'));
|
|
3629
|
+
return Promise.resolve(this.vaultItem ? this.vaultItem.getId() : tk[2]).then(function(id) {
|
|
3630
|
+
var vi = new libVES.VaultItem({id: id}, ves);
|
|
3631
|
+
return vi.getFile().then(function(file) {
|
|
3632
|
+
return vi.getField('deleted').then(function(f) {
|
|
3633
|
+
if (f) throw new libVES.Error('VESauth', 'Verify token expired');
|
|
3634
|
+
return file.getCreator();
|
|
3635
|
+
});
|
|
3636
|
+
});
|
|
3637
|
+
});
|
|
3638
|
+
}
|
|
3639
|
+
if (tk[1] != 'vaultKey') return Promise.reject(new libVES.Error('VESauth', 'Unknown token type'));
|
|
3640
|
+
if (this.vaultItem) return this.vaultItem.getId().then(function(id) {
|
|
3641
|
+
var vi = new libVES.VaultItem({id: id}, ves);
|
|
3642
|
+
return vi.getVaultEntries().then(function(vents) {
|
|
3643
|
+
if (!auth && vents && vents.length) return ves.me();
|
|
3644
|
+
if (vents && tk[2]) for (var i = 0; i < vents.length; i++) if (vents[i].vaultKey && Number(vents[i].vaultKey.id) == Number(tk[2])) return ves.me();
|
|
3645
|
+
throw new libVES.Error('VESauth', 'ACL not authorized');
|
|
3646
|
+
});
|
|
3647
|
+
});
|
|
3648
|
+
if (!auth) return ves.me();
|
|
3649
|
+
return Promise.resolve(this.vaultKey ? this.vaultKey.getId() : tk[2]).then(function(id) {
|
|
3650
|
+
return (new libVES.VaultKey({id: id}, ves)).getExternals().then(function(ext) {
|
|
3651
|
+
if (!ext || !ext[0]) throw new libVES.Error('VESauth', 'Bad vaultKey for VESauth');
|
|
3652
|
+
return ext[0].getDomain().then(function(dom) {
|
|
3653
|
+
return ext[0].getExternalId().then(function(extid) {
|
|
3654
|
+
if (!extid || !extid.match(/^[^\!\@]+\@[^\!\@]+$/)) throw new libVES.Error('VESauth', 'Bad vaultKey for VESauth');
|
|
3655
|
+
if (dom && dom.toLowerCase() == ves.domain.toLowerCase()) return ves.me();
|
|
3656
|
+
throw new libVES.Error('VESuath', 'VES domain does not match');
|
|
3657
|
+
});
|
|
3658
|
+
});
|
|
3659
|
+
});
|
|
3660
|
+
});
|
|
3661
|
+
};
|
|
3662
|
+
|
|
3543
3663
|
module.exports = libVES;
|
package/libves-2.3.0.tgz
ADDED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "libves",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "Simple, safe and secure end-to-end encryption
|
|
3
|
+
"version": "2.3.0",
|
|
4
|
+
"description": "Simple, safe and secure end-to-end encryption at-rest",
|
|
5
5
|
"main": "libVES.node.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "echo \"No test defined\" && exit 1"
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"crypto": "*",
|
|
26
26
|
"subtle": "*",
|
|
27
|
-
"
|
|
27
|
+
"xhr2": "*"
|
|
28
28
|
},
|
|
29
29
|
"author": "jz@vesvault.com",
|
|
30
30
|
"license": "GPL-3.0",
|
package/libves-2.1.1.tgz
DELETED
|
Binary file
|