mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-10-07 22:57:07 +00:00
Move source files to src/. Update package.json.
This commit is contained in:
40
src/HashCacheItem.js
Normal file
40
src/HashCacheItem.js
Normal file
@@ -0,0 +1,40 @@
|
||||
'use strict';
|
||||
|
||||
const encryption = require('./Encryption');
|
||||
|
||||
const HashCacheOps = {
|
||||
Add: "ADD",
|
||||
Put: "PUT",
|
||||
Delete: "DELETE"
|
||||
};
|
||||
|
||||
class HashCacheItem {
|
||||
constructor(operation, key, sequenceNumber, targetHash, metaInfo) {
|
||||
this.op = operation;
|
||||
this.key = key;
|
||||
this.seq = sequenceNumber;
|
||||
this.target = targetHash;
|
||||
this.meta = metaInfo;
|
||||
}
|
||||
}
|
||||
|
||||
class EncryptedHashCacheItem extends HashCacheItem {
|
||||
constructor(operation, key, sequenceNumber, targetHash, metaInfo, publicKey, privateKey, salt) {
|
||||
super(operation, key, 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 = {
|
||||
HashCacheOps: HashCacheOps,
|
||||
HashCacheItem: HashCacheItem,
|
||||
EncryptedHashCacheItem: EncryptedHashCacheItem
|
||||
};
|
||||
Reference in New Issue
Block a user