cryptpad/www/common/outer/invitation.js

100 lines
2.9 KiB
JavaScript
Raw Normal View History

2019-09-27 10:05:08 +00:00
(function () {
2019-12-18 22:59:28 +00:00
var factory = function (Util, Cred, Nacl) {
2019-09-27 10:05:08 +00:00
var Invite = {};
2019-12-17 01:57:19 +00:00
var encode64 = Nacl.util.encodeBase64;
2019-12-17 09:29:02 +00:00
var decode64 = Nacl.util.decodeBase64;
2019-12-17 01:57:19 +00:00
// ed and curve keys can be random...
Invite.generateKeys = function () {
var ed = Nacl.sign.keyPair();
var curve = Nacl.box.keyPair();
return {
edPublic: encode64(ed.publicKey),
edPrivate: encode64(ed.secretKey),
curvePublic: encode64(curve.publicKey),
curvePrivate: encode64(curve.secretKey),
};
};
2019-12-18 00:27:39 +00:00
Invite.generateSignPair = function () {
var ed = Nacl.sign.keyPair();
return {
validateKey: encode64(ed.publicKey),
signKey: encode64(ed.secretKey),
};
};
2019-12-17 01:57:19 +00:00
var b64ToChannelKeys = function (b64) {
var dispense = Cred.dispenser(decode64(b64));
return {
channel: Util.uint8ArrayToHex(dispense(16)),
2019-12-18 00:27:39 +00:00
cryptKey: dispense(Nacl.secretbox.keyLength),
2019-12-17 01:57:19 +00:00
};
};
// the secret invite values (cryptkey and channel) can be derived
// from the link seed and (optional) password
Invite.deriveInviteKeys = b64ToChannelKeys;
// the preview values (cryptkey and channel) are less sensitive than the invite values
// as they cannot be leveraged to access any further content on their own
// unless the message contains secrets.
// derived from the link seed alone.
Invite.derivePreviewKeys = b64ToChannelKeys;
Invite.createRosterEntry = function (roster, data, cb) {
var toInvite = {};
toInvite[data.curvePublic] = data.content;
roster.invite(toInvite, cb);
};
2019-12-13 23:38:05 +00:00
/* INPUTS
* password (for scrypt)
* message (personal note)
* link hash
* bytes64 (scrypt output)
* preview_hash
*/
/* IO / FUNCTIONALITY
* creator
* generate a random signKey (prevent writes to preview channel)
* encrypt and upload the preview content
* via CryptGet
* owned by:
* the ephemeral edPublic
* the invite creator
* create a roster entry for the invitation
* with encrypted notes for the creator
* redeemer
* get the preview content
* redeem the invite
* add yourself to the roster
* add the team to your proxy-manager
*/
2019-09-27 10:05:08 +00:00
return Invite;
};
if (typeof(module) !== 'undefined' && module.exports) {
module.exports = factory(
require("../common-util"),
require("../common-credential.js"),
2019-12-17 01:57:19 +00:00
require("nthen"),
require("tweetnacl/nacl-fast")
2019-09-27 10:05:08 +00:00
);
} else if ((typeof(define) !== 'undefined' && define !== null) && (define.amd !== null)) {
define([
'/common/common-util.js',
'/common/common-credential.js',
2019-12-17 01:57:19 +00:00
'/bower_components/tweetnacl/nacl-fast.min.js',
2019-12-18 22:59:28 +00:00
], function (Util, Cred) {
return factory(Util, Cred, window.nacl);
2019-09-27 10:05:08 +00:00
});
}
}());