From 4626d036cbea1a6f6379a07b4cf40b05c8658c13 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 16 Dec 2019 17:12:58 +0100 Subject: [PATCH] Cryptget in common/invitation --- www/common/invitation.js | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/www/common/invitation.js b/www/common/invitation.js index e26a39597..9bf840e15 100644 --- a/www/common/invitation.js +++ b/www/common/invitation.js @@ -1,5 +1,5 @@ (function () { -var factory = function (Hash, Nacl, Scrypt/*, Util, Cred, nThen */) { +var factory = function (Hash, Crypt, Nacl, Scrypt/*, Util, Cred, nThen */) { var Invite = {}; Invite.deriveSeeds = function (seed) { @@ -44,14 +44,30 @@ var factory = function (Hash, Nacl, Scrypt/*, Util, Cred, nThen */) { }; Invite.getPreviewContent = function (seeds, cb) { + /* var secrets = Invite.derivePreviewSecrets(seeds); 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... Invite.setPreviewContent = function (seeds, cb) { - cb = cb; + var hash = Invite.derivePreviewHash(seeds); + Crypt.put(hash, '', function (err) { // value? + cb(err); + }); + //cb = cb; }; return Invite; @@ -59,16 +75,18 @@ var factory = function (Hash, Nacl, Scrypt/*, Util, Cred, nThen */) { if (typeof(module) !== 'undefined' && module.exports) { module.exports = factory( require("../common-hash"), + require("../cryptget"), // XXX npm cryptget? require("tweetnacl/nacl-fast"), require("scrypt-async") ); } else if ((typeof(define) !== 'undefined' && define !== null) && (define.amd !== null)) { define([ '/common/common-hash.js', + '/common/cryptget.js', '/bower_components/tweetnacl/nacl-fast.min.js', '/bower_components/scrypt_async/scrypt-async.min.js', - ], function (Hash /*, Nacl, Scrypt */) { - return factory(Hash, window.nacl, window.Scrypt); + ], function (Hash, Crypt /*, Nacl, Scrypt */) { + return factory(Hash, Crypt, window.nacl, window.Scrypt); }); } }());