mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-03-30 15:08:28 +00:00
31 lines
966 B
JavaScript
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
|
|
}; |