orbitdb/HashCacheItem.js
2015-12-27 17:27:17 +02:00

31 lines
966 B
JavaScript

'use strict';
var encryption = require('./Encryption');
class HashCacheItem {
constructor(sequenceNumber, targetHash, metaInfo) {
this.seq = sequenceNumber;
this.target = targetHash;
this.meta = metaInfo;
}
}
class EncryptedHashCacheItem extends HashCacheItem {
constructor(sequenceNumber, targetHash, metaInfo, publicKey, privateKey, salt) {
super(sequenceNumber, targetHash, metaInfo);
this.pubkey = publicKey;
try {
this.target = encryption.encrypt(targetHash, privateKey, publicKey);
this.payload = this.target; // old hash-cache api compatibility
this.meta = encryption.encrypt(JSON.stringify(metaInfo), privateKey, publicKey);
this.sig = encryption.sign(this.target, privateKey, this.seq, salt || "");
} catch(e) {
console.log("Signing HashCacheItem failed:", e);
}
}
}
module.exports = {
HashCacheItem: HashCacheItem,
EncryptedHashCacheItem: EncryptedHashCacheItem
};