@ocap/tx-protocols 1.25.1 → 1.25.3

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.
@@ -152,7 +152,10 @@ runner.use(pipes.VerifyBlocked({ stateKeys: ['senderState'] }));
152
152
  // verify staking: get address, extract state, verify amount
153
153
  runner.use((context, next) => {
154
154
  const { tx, itx } = context;
155
- context.stakeAddress = toStakeAddress(tx.from, tx.from, itx.token.symbol);
155
+ // stake from sender to main token
156
+ const sender = tx.delegator || tx.from;
157
+ const receiver = context.config.token.address;
158
+ context.stakeAddress = toStakeAddress(sender, receiver, itx.token.symbol);
156
159
  return next();
157
160
  });
158
161
  runner.use(
@@ -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,16 +12,48 @@ 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 },
15
35
  } = context;
16
36
 
17
37
  const sender = delegator || from;
18
- const verificationUrl = `${website}/.well-known/ocap/tokens.json`;
38
+
39
+ const { origin } = new URL(website);
40
+ const verificationUrl = `${origin}/.well-known/ocap/tokens.json`;
19
41
 
20
42
  try {
21
- 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
+
22
57
  const data = await response.json();
23
58
 
24
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 (url && !verifyUrl(url)) {
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.1",
6
+ "version": "1.25.3",
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.1",
23
- "@arcblock/did-util": "1.25.1",
24
- "@arcblock/jwt": "1.25.1",
25
- "@arcblock/validator": "1.25.1",
26
- "@arcblock/vc": "1.25.1",
27
- "@ocap/client": "1.25.1",
28
- "@ocap/mcrypto": "1.25.1",
29
- "@ocap/merkle-tree": "1.25.1",
30
- "@ocap/state": "1.25.1",
31
- "@ocap/message": "1.25.1",
32
- "@ocap/util": "1.25.1",
33
- "@ocap/tx-pipeline": "1.25.1",
34
- "@ocap/wallet": "1.25.1",
35
- "@ocap/asset": "1.25.1"
22
+ "@arcblock/did-util": "1.25.3",
23
+ "@arcblock/jwt": "1.25.3",
24
+ "@arcblock/validator": "1.25.3",
25
+ "@arcblock/vc": "1.25.3",
26
+ "@ocap/asset": "1.25.3",
27
+ "@ocap/client": "1.25.3",
28
+ "@ocap/mcrypto": "1.25.3",
29
+ "@ocap/merkle-tree": "1.25.3",
30
+ "@arcblock/did": "1.25.3",
31
+ "@ocap/message": "1.25.3",
32
+ "@ocap/state": "1.25.3",
33
+ "@ocap/tx-pipeline": "1.25.3",
34
+ "@ocap/util": "1.25.3",
35
+ "@ocap/wallet": "1.25.3"
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.1",
45
- "@ocap/statedb-memory": "1.25.1"
44
+ "@ocap/e2e-test": "1.25.3",
45
+ "@ocap/statedb-memory": "1.25.3"
46
46
  },
47
47
  "scripts": {
48
48
  "lint": "eslint tests lib",