add some comments to common-hash for new APIs

pull/1/head
ansuz 5 years ago
parent 0b17df3302
commit 646d8e7341

@ -85,16 +85,27 @@ define([
return id; return id;
}; };
/* Given a base64-encoded public key, deterministically derive a channel id
Used for support mailboxes
*/
Hash.getChannelIdFromKey = function (publicKey) { Hash.getChannelIdFromKey = function (publicKey) {
if (!publicKey) { return; } if (!publicKey) { return; }
return uint8ArrayToHex(Hash.decodeBase64(publicKey).subarray(0,16)); return uint8ArrayToHex(Hash.decodeBase64(publicKey).subarray(0,16));
}; };
/* Given a base64-encoded asymmetric private key
derive the corresponding public key
*/
Hash.getBoxPublicFromSecret = function (priv) { Hash.getBoxPublicFromSecret = function (priv) {
if (!priv) { return; } if (!priv) { return; }
var u8_priv = Hash.decodeBase64(priv); var u8_priv = Hash.decodeBase64(priv);
var pair = Nacl.box.keyPair.fromSecretKey(u8_priv); var pair = Nacl.box.keyPair.fromSecretKey(u8_priv);
return Hash.encodeBase64(pair.publicKey); return Hash.encodeBase64(pair.publicKey);
}; };
/* Given a base64-encoded private key and public key
check that the keys are part of a valid keypair
*/
Hash.checkBoxKeyPair = function (priv, pub) { Hash.checkBoxKeyPair = function (priv, pub) {
if (!pub || !priv) { return false; } if (!pub || !priv) { return false; }
var u8_priv = Hash.decodeBase64(priv); var u8_priv = Hash.decodeBase64(priv);

Loading…
Cancel
Save