You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.3 KiB
JavaScript
49 lines
1.3 KiB
JavaScript
![]()
8 years ago
|
define([
|
||
|
'/common/encode.js',
|
||
|
|
||
|
'/bower_components/tweetnacl/nacl-fast.min.js',
|
||
|
], function (Encode) {
|
||
|
|
||
|
var getHistoryKeeperName = function (network) {
|
||
|
var wc = network.webChannels[0];
|
||
|
if (!wc) {
|
||
|
throw new Error("ERROR: no joined webchannels so we can't get the history keeper name");
|
||
|
}
|
||
|
if (!wc.history_keeper) { throw new Error("ERROR: no history keeper"); }
|
||
|
return wc.history_keeper;
|
||
|
};
|
||
|
|
||
|
var sendMsg = function (ctx, cb) {
|
||
|
var hkn = getHistoryKeeperName(ctx.network);
|
||
|
};
|
||
|
|
||
|
var onMsg = function (ctx, msg) {
|
||
|
console.log(msg);
|
||
|
};
|
||
|
|
||
|
var cookie = function (ctx, cb) {
|
||
|
// TODO
|
||
|
};
|
||
|
|
||
|
var signMsg = function (msg, secKey) {
|
||
|
// TODO
|
||
|
};
|
||
|
|
||
|
var create = function (network, edPrivateKey) {
|
||
|
if (!/[0-9a-f]{64}/.test(edPrivateKey)) {
|
||
|
throw new Error("private signing key is not valid");
|
||
|
}
|
||
|
var ctx = {
|
||
|
privateKey: Encode.hexToUint8Array(edPrivateKey),
|
||
|
seq: new Date().getTime(),
|
||
|
network: network
|
||
|
};
|
||
|
network.on('message', function (msg) { onMsg(ctx, msg); });
|
||
|
return {
|
||
|
cookie: function (cb) { cookie(ctx, cb); },
|
||
|
};
|
||
|
};
|
||
|
|
||
|
return { create: create };
|
||
|
});
|