@ocap/state 1.18.127 → 1.18.129
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/states/blacklist.js +14 -1
- package/package.json +8 -8
package/lib/states/blacklist.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
|
+
const { isSameDid } = require('@ocap/util');
|
|
2
3
|
const { CustomError: Error } = require('@ocap/util/lib/error');
|
|
3
4
|
const { BloomFilter } = require('bloom-filters');
|
|
4
5
|
|
|
5
6
|
class Blacklist {
|
|
6
|
-
constructor({ size = 256, numHashFns = 4, dumpPath = '', dumpInterval = 0 } = {}) {
|
|
7
|
+
constructor({ size = 256, numHashFns = 4, dumpPath = '', dumpInterval = 0, getBlockedAccounts = null } = {}) {
|
|
7
8
|
let filter;
|
|
8
9
|
|
|
9
10
|
if (dumpPath && fs.existsSync(dumpPath)) {
|
|
@@ -21,6 +22,7 @@ class Blacklist {
|
|
|
21
22
|
|
|
22
23
|
this.dumpPath = dumpPath;
|
|
23
24
|
this.filter = filter;
|
|
25
|
+
this.getBlockedAccounts = getBlockedAccounts;
|
|
24
26
|
|
|
25
27
|
if (dumpPath && dumpInterval > 0) {
|
|
26
28
|
this.timer = setTimeout(() => {
|
|
@@ -48,6 +50,17 @@ class Blacklist {
|
|
|
48
50
|
return this.filter.add(key);
|
|
49
51
|
}
|
|
50
52
|
|
|
53
|
+
async isBlocked(address) {
|
|
54
|
+
if (typeof this.getBlockedAccounts === 'function') {
|
|
55
|
+
const blocked = await this.getBlockedAccounts();
|
|
56
|
+
if (blocked.length) {
|
|
57
|
+
return blocked.some((b) => isSameDid(b, address));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
|
|
51
64
|
dump() {
|
|
52
65
|
try {
|
|
53
66
|
const exported = this.filter.saveAsJSON();
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.18.
|
|
6
|
+
"version": "1.18.129",
|
|
7
7
|
"description": "",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -16,12 +16,12 @@
|
|
|
16
16
|
"coverage": "npm run test -- --coverage"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@arcblock/did": "1.18.
|
|
20
|
-
"@arcblock/validator": "1.18.
|
|
21
|
-
"@ocap/contract": "1.18.
|
|
22
|
-
"@ocap/mcrypto": "1.18.
|
|
23
|
-
"@ocap/message": "1.18.
|
|
24
|
-
"@ocap/util": "1.18.
|
|
19
|
+
"@arcblock/did": "1.18.129",
|
|
20
|
+
"@arcblock/validator": "1.18.129",
|
|
21
|
+
"@ocap/contract": "1.18.129",
|
|
22
|
+
"@ocap/mcrypto": "1.18.129",
|
|
23
|
+
"@ocap/message": "1.18.129",
|
|
24
|
+
"@ocap/util": "1.18.129",
|
|
25
25
|
"bloom-filters": "^1.3.9",
|
|
26
26
|
"lodash": "^4.17.21"
|
|
27
27
|
},
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"keywords": [],
|
|
32
32
|
"author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
|
|
33
33
|
"license": "MIT",
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "422e48b5668be8d25d76037d86926a625b194758"
|
|
35
35
|
}
|