Cryptget in common/invitation

pull/1/head
yflory 5 years ago
parent 6686e0e841
commit 4626d036cb

@ -1,5 +1,5 @@
(function () { (function () {
var factory = function (Hash, Nacl, Scrypt/*, Util, Cred, nThen */) { var factory = function (Hash, Crypt, Nacl, Scrypt/*, Util, Cred, nThen */) {
var Invite = {}; var Invite = {};
Invite.deriveSeeds = function (seed) { Invite.deriveSeeds = function (seed) {
@ -44,14 +44,30 @@ var factory = function (Hash, Nacl, Scrypt/*, Util, Cred, nThen */) {
}; };
Invite.getPreviewContent = function (seeds, cb) { Invite.getPreviewContent = function (seeds, cb) {
/*
var secrets = Invite.derivePreviewSecrets(seeds); var secrets = Invite.derivePreviewSecrets(seeds);
secrets = secrets; secrets = secrets;
cb("NOT_IMPLEMENTED"); // XXX cryptget */
var hash = Invite.derivePreviewHash(seeds);
Crypt.get(hash, function (err, val) {
if (err) { return void cb(err); }
try {
cb(void 0, JSON.parse(val));
} catch (e) {
console.error(e);
cb(e);
}
});
// cb("NOT_IMPLEMENTED"); // XXX cryptget
}; };
// XXX remember to pin invites... // XXX remember to pin invites...
Invite.setPreviewContent = function (seeds, cb) { Invite.setPreviewContent = function (seeds, cb) {
cb = cb; var hash = Invite.derivePreviewHash(seeds);
Crypt.put(hash, '', function (err) { // value?
cb(err);
});
//cb = cb;
}; };
return Invite; return Invite;
@ -59,16 +75,18 @@ var factory = function (Hash, Nacl, Scrypt/*, Util, Cred, nThen */) {
if (typeof(module) !== 'undefined' && module.exports) { if (typeof(module) !== 'undefined' && module.exports) {
module.exports = factory( module.exports = factory(
require("../common-hash"), require("../common-hash"),
require("../cryptget"), // XXX npm cryptget?
require("tweetnacl/nacl-fast"), require("tweetnacl/nacl-fast"),
require("scrypt-async") require("scrypt-async")
); );
} 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/cryptget.js',
'/bower_components/tweetnacl/nacl-fast.min.js', '/bower_components/tweetnacl/nacl-fast.min.js',
'/bower_components/scrypt_async/scrypt-async.min.js', '/bower_components/scrypt_async/scrypt-async.min.js',
], function (Hash /*, Nacl, Scrypt */) { ], function (Hash, Crypt /*, Nacl, Scrypt */) {
return factory(Hash, window.nacl, window.Scrypt); return factory(Hash, Crypt, window.nacl, window.Scrypt);
}); });
} }
}()); }());

Loading…
Cancel
Save