@ocap/tx-protocols 1.25.2 → 1.25.4
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.
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
const get = require('lodash/get');
|
|
2
2
|
const { CustomError: Error } = require('@ocap/util/lib/error');
|
|
3
|
+
const { verifyUrl } = require('@ocap/util/lib/url');
|
|
3
4
|
const { verify: verifyVC } = require('@arcblock/vc');
|
|
4
5
|
|
|
6
|
+
const isTest = ['development', 'test'].includes(process.env.NODE_ENV) || !!process.env.CI;
|
|
7
|
+
|
|
5
8
|
module.exports =
|
|
6
9
|
({ tokenKey = 'itx.token' } = {}) =>
|
|
7
10
|
async (context, next) => {
|
|
@@ -9,6 +12,23 @@ module.exports =
|
|
|
9
12
|
|
|
10
13
|
if (!website) return next();
|
|
11
14
|
|
|
15
|
+
try {
|
|
16
|
+
await verifyUrl(
|
|
17
|
+
website,
|
|
18
|
+
isTest
|
|
19
|
+
? {
|
|
20
|
+
protocols: ['http:', 'https:'],
|
|
21
|
+
blockedHosts: [],
|
|
22
|
+
allowIp: true,
|
|
23
|
+
}
|
|
24
|
+
: {
|
|
25
|
+
checkDns: true,
|
|
26
|
+
}
|
|
27
|
+
);
|
|
28
|
+
} catch (error) {
|
|
29
|
+
return next(new Error('INVALID_WEBSITE', `Website ${website} must be a valid URL: ${error.message}`));
|
|
30
|
+
}
|
|
31
|
+
|
|
12
32
|
const {
|
|
13
33
|
tx: { from, delegator },
|
|
14
34
|
config: { chainId },
|
|
@@ -20,7 +40,20 @@ module.exports =
|
|
|
20
40
|
const verificationUrl = `${origin}/.well-known/ocap/tokens.json`;
|
|
21
41
|
|
|
22
42
|
try {
|
|
23
|
-
const response = await fetch(verificationUrl
|
|
43
|
+
const response = await fetch(verificationUrl, {
|
|
44
|
+
redirect: 'manual',
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
if (!response || !response.ok) {
|
|
48
|
+
context?.logger.info('Website verification failed', {
|
|
49
|
+
symbol,
|
|
50
|
+
website,
|
|
51
|
+
status: response?.status,
|
|
52
|
+
statusText: response?.statusText,
|
|
53
|
+
});
|
|
54
|
+
return next(new Error('INVALID_WEBSITE', `Website ${website} verification failed`));
|
|
55
|
+
}
|
|
56
|
+
|
|
24
57
|
const data = await response.json();
|
|
25
58
|
|
|
26
59
|
const valids = await Promise.all(
|
|
@@ -2,14 +2,29 @@ const get = require('lodash/get');
|
|
|
2
2
|
const { CustomError: Error } = require('@ocap/util/lib/error');
|
|
3
3
|
const { verifyUrl } = require('@ocap/util/lib/url');
|
|
4
4
|
|
|
5
|
+
const isTest = ['development', 'test'].includes(process.env.NODE_ENV) || !!process.env.CI;
|
|
6
|
+
|
|
5
7
|
module.exports =
|
|
6
8
|
({ urlKeys = ['itx.token.website', 'itx.token.metadata.value.communityUrl'] } = {}) =>
|
|
7
|
-
(context, next) => {
|
|
9
|
+
async (context, next) => {
|
|
8
10
|
for (const key of urlKeys) {
|
|
9
11
|
const url = get(context, key);
|
|
10
|
-
if (
|
|
12
|
+
if (!url) continue;
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
await verifyUrl(
|
|
16
|
+
url,
|
|
17
|
+
isTest
|
|
18
|
+
? {
|
|
19
|
+
protocols: ['http:', 'https:'],
|
|
20
|
+
blockedHosts: [],
|
|
21
|
+
allowIp: true,
|
|
22
|
+
}
|
|
23
|
+
: {}
|
|
24
|
+
);
|
|
25
|
+
} catch (error) {
|
|
11
26
|
const name = key.split('.').pop();
|
|
12
|
-
return next(new Error('INVALID_TX', `${name} is not valid`));
|
|
27
|
+
return next(new Error('INVALID_TX', `${name} is not valid: ${error.message}`));
|
|
13
28
|
}
|
|
14
29
|
}
|
|
15
30
|
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.25.
|
|
6
|
+
"version": "1.25.4",
|
|
7
7
|
"description": "Predefined tx pipeline sets to execute certain type of transactions",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -19,20 +19,20 @@
|
|
|
19
19
|
"empty-value": "^1.0.1",
|
|
20
20
|
"lodash": "^4.17.21",
|
|
21
21
|
"url-join": "^4.0.1",
|
|
22
|
-
"@arcblock/did": "1.25.
|
|
23
|
-
"@arcblock/did-util": "1.25.
|
|
24
|
-
"@arcblock/jwt": "1.25.
|
|
25
|
-
"@arcblock/validator": "1.25.
|
|
26
|
-
"@arcblock/vc": "1.25.
|
|
27
|
-
"@ocap/asset": "1.25.
|
|
28
|
-
"@ocap/
|
|
29
|
-
"@ocap/
|
|
30
|
-
"@ocap/merkle-tree": "1.25.
|
|
31
|
-
"@ocap/message": "1.25.
|
|
32
|
-
"@ocap/state": "1.25.
|
|
33
|
-
"@ocap/tx-pipeline": "1.25.
|
|
34
|
-
"@ocap/util": "1.25.
|
|
35
|
-
"@ocap/wallet": "1.25.
|
|
22
|
+
"@arcblock/did": "1.25.4",
|
|
23
|
+
"@arcblock/did-util": "1.25.4",
|
|
24
|
+
"@arcblock/jwt": "1.25.4",
|
|
25
|
+
"@arcblock/validator": "1.25.4",
|
|
26
|
+
"@arcblock/vc": "1.25.4",
|
|
27
|
+
"@ocap/asset": "1.25.4",
|
|
28
|
+
"@ocap/client": "1.25.4",
|
|
29
|
+
"@ocap/mcrypto": "1.25.4",
|
|
30
|
+
"@ocap/merkle-tree": "1.25.4",
|
|
31
|
+
"@ocap/message": "1.25.4",
|
|
32
|
+
"@ocap/state": "1.25.4",
|
|
33
|
+
"@ocap/tx-pipeline": "1.25.4",
|
|
34
|
+
"@ocap/util": "1.25.4",
|
|
35
|
+
"@ocap/wallet": "1.25.4"
|
|
36
36
|
},
|
|
37
37
|
"resolutions": {
|
|
38
38
|
"bn.js": "5.2.2",
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"jest": "^29.7.0",
|
|
43
43
|
"start-server-and-test": "^1.14.0",
|
|
44
|
-
"@ocap/e2e-test": "1.25.
|
|
45
|
-
"@ocap/statedb-memory": "1.25.
|
|
44
|
+
"@ocap/e2e-test": "1.25.4",
|
|
45
|
+
"@ocap/statedb-memory": "1.25.4"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"lint": "eslint tests lib",
|