move hashChannelList into common-hash.js

This commit is contained in:
ansuz
2017-04-14 11:40:28 +02:00
parent 63960bd38c
commit f42da4ecd8
3 changed files with 40 additions and 15 deletions

View File

@@ -1,13 +1,23 @@
define([
'/common/common-util.js',
'/bower_components/chainpad-crypto/crypto.js',
'/bower_components/tweetnacl/nacl-fast.min.js'
], function (Util, Crypto) {
var Nacl = window.nacl;
var Hash = {};
var uint8ArrayToHex = Util.uint8ArrayToHex;
var hexToBase64 = Util.hexToBase64;
var base64ToHex = Util.base64ToHex;
// This implementation must match that on the server
// it's used for a checksum
Hash.hashChannelList = function (list) {
return Nacl.util.encodeBase64(Nacl.hash(Nacl.util
.decodeUTF8(JSON.stringify(list))));
};
var getEditHashFromKeys = Hash.getEditHashFromKeys = function (chanKey, keys) {
if (typeof keys === 'string') {
return chanKey + keys;
@@ -231,6 +241,5 @@ define([
return hex;
};
return Hash;
});