-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTag3.js
45 lines (40 loc) · 1.02 KB
/
Tag3.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import crypto from "crypto";
export class Tag {
constructor(meta, data, tags = new Map()) {
this.meta = meta;
this.data = data;
this.tags = tags;
this.stamp = 0;
}
#stamp() {
let data = this.data;
if (this.tags !== null) {
for (let tag of this.tags.keys()) {
data += tag.stamp.toString();
}
}
return crypto.createHash('sha256').update(data).digest('base64');
}
add(tag1, tag2) {
if (this.tags.has(JSON.stringify(tag1))) return this;
this.tags.set(JSON.stringify(tag1), tag2);
return this;
}
remove(tag1) {
this.tags.delete(JSON.stringify(tag1));
return this;
}
getCurrentStamp(){
return this.#stamp();
}
getSavedStamp(){
return this.stamp;
}
lock(){
this.stamp = this.#stamp();
return this.stamp;
}
isLock(){
return this.stamp === this.#stamp();
}
}