|
|
@ -1,57 +1,57 @@
|
|
|
|
(function () {
|
|
|
|
(function () {
|
|
|
|
var factory = function (Hash, Nacl/*, Util, Cred, nThen */) {
|
|
|
|
var factory = function (Hash, Nacl, Scrypt/*, Util, Cred, nThen */) {
|
|
|
|
var Invite = {};
|
|
|
|
var Invite = {};
|
|
|
|
|
|
|
|
|
|
|
|
/* XXX ansuz
|
|
|
|
Invite.deriveSeeds = function (seed) {
|
|
|
|
inner invitation components
|
|
|
|
// take the hash of the provided seed
|
|
|
|
|
|
|
|
var u8_seed = Nacl.hash(Nacl.util.decodeBase64(seed));
|
|
|
|
|
|
|
|
|
|
|
|
* create an invitation link
|
|
|
|
// hash the first half again for scrypt's input
|
|
|
|
* derive secrets from a v2 link and password
|
|
|
|
var subseed1 = Nacl.hash(u8_seed.subarray(0, 32));
|
|
|
|
* split hash into two preseeds
|
|
|
|
// hash the remainder for the invite content
|
|
|
|
* preseed1 => preview hash
|
|
|
|
var subseed2 = Nacl.hash(u8_seed.subarray(32));
|
|
|
|
* scrypt(scrypt_seed) => b64_bytes
|
|
|
|
|
|
|
|
* preview an invitation link
|
|
|
|
|
|
|
|
* get preview hash from invitation link
|
|
|
|
|
|
|
|
* decrypt an invitation link
|
|
|
|
|
|
|
|
* (slowly) get b64_bytes from hash
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
return {
|
|
|
|
|
|
|
|
scrypt: Nacl.util.encodeBase64(subseed1),
|
|
|
|
Invite.deriveSeeds = function (key) {
|
|
|
|
preview: Nacl.util.encodeBase64(subseed2),
|
|
|
|
var seeds = {};
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
/*
|
|
|
|
|
|
|
|
var preview_channel;
|
|
|
|
|
|
|
|
var preview_cryptKey;
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
var preview_secrets;
|
|
|
|
|
|
|
|
(function () {
|
|
|
|
|
|
|
|
var b64_seed = key;
|
|
|
|
|
|
|
|
if (typeof(b64_seed) !== 'string') {
|
|
|
|
|
|
|
|
return console.error('invite seed is not a string');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var u8_seed = Nacl.util.decodeBase64(b64_seed);
|
|
|
|
Invite.derivePreviewHash = function (seeds) {
|
|
|
|
var step1 = Nacl.hash(u8_seed);
|
|
|
|
return '#/2/invite/view/' +
|
|
|
|
seeds.scrypt = Nacl.util.encodeBase64(step1.subarray(0, 32));
|
|
|
|
Nacl.util.encodeBase64(seeds.preview.slice(0, 18)).replace('/', '-')
|
|
|
|
|
|
|
|
+ '/';
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var preview_hash = '#/2/invite/view/' +
|
|
|
|
Invite.derivePreviewSecrets = function (seeds) {
|
|
|
|
Nacl.util.encodeBase64(step1.subarray(32, 50)).replace('/', '-')
|
|
|
|
return Hash.getSecrets('pad', Invite.derivePreviewHash(seeds));
|
|
|
|
+ '/';
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
preview_secrets = Hash.getSecrets('pad', preview_hash);
|
|
|
|
Invite.deriveSalt = function (password, instance_salt) {
|
|
|
|
}());
|
|
|
|
return (password || '') + (instance_salt || '');
|
|
|
|
return seeds;
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// seed => bytes64
|
|
|
|
// seed => bytes64
|
|
|
|
Invite.deriveBytes = function (scrypt_seed, cb) {
|
|
|
|
Invite.deriveBytes = function (scrypt_seed, salt, cb) {
|
|
|
|
// XXX do scrypt stuff...
|
|
|
|
Scrypt(scrypt_seed,
|
|
|
|
cb = cb;
|
|
|
|
salt,
|
|
|
|
|
|
|
|
8, // memoryCost (n)
|
|
|
|
|
|
|
|
1024, // block size parameter (r)
|
|
|
|
|
|
|
|
192, // dkLen
|
|
|
|
|
|
|
|
200, // interruptStep
|
|
|
|
|
|
|
|
cb,
|
|
|
|
|
|
|
|
'base64'); // format, could be 'base64'
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Invite.getPreviewContent = function (seeds, cb) {
|
|
|
|
|
|
|
|
var secrets = Invite.derivePreviewSecrets(seeds);
|
|
|
|
|
|
|
|
secrets = secrets;
|
|
|
|
|
|
|
|
cb("NOT_IMPLEMENTED"); // XXX cryptget
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Invite.derivePreviewHash = function (preview_seed) {
|
|
|
|
// XXX remember to pin invites...
|
|
|
|
preview_seed = preview_seed;
|
|
|
|
Invite.setPreviewContent = function (seeds, cb) {
|
|
|
|
|
|
|
|
cb = cb;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return Invite;
|
|
|
|
return Invite;
|
|
|
@ -60,19 +60,15 @@ var factory = function (Hash, Nacl/*, Util, Cred, nThen */) {
|
|
|
|
module.exports = factory(
|
|
|
|
module.exports = factory(
|
|
|
|
require("../common-hash"),
|
|
|
|
require("../common-hash"),
|
|
|
|
require("tweetnacl/nacl-fast"),
|
|
|
|
require("tweetnacl/nacl-fast"),
|
|
|
|
require("../common-util"),
|
|
|
|
require("scrypt-async")
|
|
|
|
require("../common-credential.js"),
|
|
|
|
|
|
|
|
require("nthen")
|
|
|
|
|
|
|
|
);
|
|
|
|
);
|
|
|
|
} else if ((typeof(define) !== 'undefined' && define !== null) && (define.amd !== null)) {
|
|
|
|
} else if ((typeof(define) !== 'undefined' && define !== null) && (define.amd !== null)) {
|
|
|
|
define([
|
|
|
|
define([
|
|
|
|
'/common/common-hash.js',
|
|
|
|
'/common/common-hash.js',
|
|
|
|
'/common/common-util.js',
|
|
|
|
|
|
|
|
'/common/common-credential.js',
|
|
|
|
|
|
|
|
'/bower_components/nthen/index.js',
|
|
|
|
|
|
|
|
'/bower_components/tweetnacl/nacl-fast.min.js',
|
|
|
|
'/bower_components/tweetnacl/nacl-fast.min.js',
|
|
|
|
], function (Hash, Util, Cred, nThen) {
|
|
|
|
'/bower_components/scrypt_async/scrypt-async.min.js',
|
|
|
|
return factory(Hash, window.nacl, Util, Cred, nThen);
|
|
|
|
], function (Hash /*, Nacl, Scrypt */) {
|
|
|
|
|
|
|
|
return factory(Hash, window.nacl, window.Scrypt);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}());
|
|
|
|
}());
|
|
|
|