@blocklet/meta 1.8.0 → 1.8.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.
- package/lib/channel.js +39 -0
- package/lib/constants.js +2 -0
- package/lib/nft-templates.js +47 -0
- package/lib/payment.js +1 -1
- package/lib/util.js +51 -0
- package/package.json +12 -13
package/lib/channel.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const { isValid: isValidDid } = require('@arcblock/did');
|
|
2
|
+
|
|
3
|
+
const getAppPublicChannelRegex = () => /app:(\w+):public/;
|
|
4
|
+
|
|
5
|
+
const getAppPublicChannel = (appDid) => `app:${appDid}:public`;
|
|
6
|
+
|
|
7
|
+
const CHANNEL_TYPE = {
|
|
8
|
+
DID: 'DID',
|
|
9
|
+
APP: 'APP',
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const parseChannel = (channel) => {
|
|
13
|
+
if (!channel) {
|
|
14
|
+
throw new Error('Channel should not be empty');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const matchAppPublicChannel = getAppPublicChannelRegex().exec(channel);
|
|
18
|
+
if (matchAppPublicChannel) {
|
|
19
|
+
return {
|
|
20
|
+
type: CHANNEL_TYPE.APP,
|
|
21
|
+
appDid: matchAppPublicChannel[1],
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (isValidDid(channel)) {
|
|
26
|
+
return {
|
|
27
|
+
type: CHANNEL_TYPE.DID,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
throw new Error(`Invalid channel format: ${channel}`);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
module.exports = {
|
|
35
|
+
CHANNEL_TYPE,
|
|
36
|
+
getAppPublicChannel,
|
|
37
|
+
getAppPublicChannelRegex,
|
|
38
|
+
parseChannel,
|
|
39
|
+
};
|
package/lib/constants.js
CHANGED
|
@@ -77,7 +77,9 @@ const BlockletEvents = Object.freeze({
|
|
|
77
77
|
installed: 'blocklet.installed',
|
|
78
78
|
installFailed: 'blocklet.installFailed',
|
|
79
79
|
upgraded: 'blocklet.upgraded',
|
|
80
|
+
upgradeFailed: 'blocklet.upgradedFailed',
|
|
80
81
|
downgraded: 'blocklet.downgraded',
|
|
82
|
+
downgradeFailed: 'blocklet.downgradedFailed',
|
|
81
83
|
deployed: 'blocklet.deployed',
|
|
82
84
|
updated: 'blocklet.updated',
|
|
83
85
|
statusChange: 'blocklet.statusChange',
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const joinUrl = require('url-join');
|
|
2
|
+
|
|
3
|
+
const getBlockletPurchaseTemplate = (serviceUrl = 'https://registry.arcblock.io') => ({
|
|
4
|
+
type: 'vc',
|
|
5
|
+
value: {
|
|
6
|
+
'@context': 'https://schema.arcblock.io/v0.1/context.jsonld',
|
|
7
|
+
id: '{{input.id}}',
|
|
8
|
+
tag: ['{{data.did}}'],
|
|
9
|
+
type: ['VerifiableCredential', 'PurchaseCredential', 'NFTCertificate', 'BlockletPurchaseCredential'],
|
|
10
|
+
issuer: {
|
|
11
|
+
id: '{{ctx.issuer.id}}',
|
|
12
|
+
pk: '{{ctx.issuer.pk}}',
|
|
13
|
+
name: '{{ctx.issuer.name}}',
|
|
14
|
+
},
|
|
15
|
+
issuanceDate: '{{input.issuanceDate}}', // does not expire
|
|
16
|
+
credentialSubject: {
|
|
17
|
+
id: '{{ctx.owner}}',
|
|
18
|
+
sn: '{{ctx.id}}',
|
|
19
|
+
purchased: {
|
|
20
|
+
blocklet: {
|
|
21
|
+
id: '{{data.did}}',
|
|
22
|
+
url: '{{{data.url}}}',
|
|
23
|
+
name: '{{data.name}}',
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
display: {
|
|
27
|
+
type: 'url',
|
|
28
|
+
content: joinUrl(serviceUrl, '/api/nft/display'), // accept asset-did in query param
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
credentialStatus: {
|
|
32
|
+
id: joinUrl(serviceUrl, '/api/nft/status'),
|
|
33
|
+
type: 'NFTStatusList2021',
|
|
34
|
+
scope: 'public',
|
|
35
|
+
},
|
|
36
|
+
proof: {
|
|
37
|
+
type: '{{input.proofType}}',
|
|
38
|
+
created: '{{input.issuanceDate}}',
|
|
39
|
+
proofPurpose: 'assertionMethod',
|
|
40
|
+
jws: '{{input.signature}}',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
module.exports = {
|
|
46
|
+
getBlockletPurchaseTemplate,
|
|
47
|
+
};
|
package/lib/payment.js
CHANGED
|
@@ -3,7 +3,7 @@ const joinURL = require('url-join');
|
|
|
3
3
|
const { BN } = require('@ocap/util');
|
|
4
4
|
const { isValidFactory } = require('@ocap/asset');
|
|
5
5
|
const { toFactoryAddress } = require('@arcblock/did-util');
|
|
6
|
-
const { getBlockletPurchaseTemplate } = require('
|
|
6
|
+
const { getBlockletPurchaseTemplate } = require('./nft-templates');
|
|
7
7
|
|
|
8
8
|
const createShareContract = ({ tokens = [], shares = [] }) => {
|
|
9
9
|
const zeroBN = new BN(0);
|
package/lib/util.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* eslint-disable no-await-in-loop */
|
|
2
2
|
const get = require('lodash/get');
|
|
3
3
|
const slugify = require('slugify');
|
|
4
|
+
const joinUrl = require('url-join');
|
|
4
5
|
|
|
5
6
|
const { NODE_SERVICES, SLOT_FOR_IP_DNS_SITE, WHO_CAN_ACCESS } = require('@abtnode/constant');
|
|
6
7
|
|
|
@@ -24,6 +25,39 @@ const getComponentName = (component, ancestors = []) =>
|
|
|
24
25
|
|
|
25
26
|
const getComponentBundleId = (component) => `${component.meta.bundleName}@${component.meta.version}`;
|
|
26
27
|
|
|
28
|
+
/**
|
|
29
|
+
* a => ''
|
|
30
|
+
* @a/b => ''
|
|
31
|
+
* a/b => a
|
|
32
|
+
* @a/b/c => @a/b
|
|
33
|
+
* a/@b/c => a
|
|
34
|
+
* @a/b/@c/d => @a/b
|
|
35
|
+
* @a/b/@c/d/e => @a/b/@c/d
|
|
36
|
+
* @a/b/@c/d/@e/f => @a/b/@c/d
|
|
37
|
+
*/
|
|
38
|
+
const getParentComponentName = (name) => {
|
|
39
|
+
if (!name) {
|
|
40
|
+
return '';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const arr = name.split('/');
|
|
44
|
+
arr.pop();
|
|
45
|
+
|
|
46
|
+
if (!arr.length) {
|
|
47
|
+
return '';
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (arr[arr.length - 1].startsWith('@')) {
|
|
51
|
+
arr.pop();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (!arr.length) {
|
|
55
|
+
return '';
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return arr.join('/');
|
|
59
|
+
};
|
|
60
|
+
|
|
27
61
|
const forEachBlocklet = (
|
|
28
62
|
blocklet,
|
|
29
63
|
cb,
|
|
@@ -374,6 +408,21 @@ const getWhoCanAccess = (blocklet) => {
|
|
|
374
408
|
return WHO_CAN_ACCESS.ALL;
|
|
375
409
|
};
|
|
376
410
|
|
|
411
|
+
const getConnectAppUrl = ({ request, baseUrl }) => {
|
|
412
|
+
const blockletDid = request.headers['x-blocklet-did'] || '';
|
|
413
|
+
const blockletRealDid = request.headers['x-blocklet-real-did'] || '';
|
|
414
|
+
const pathPrefix = request.headers['x-path-prefix'] || '/';
|
|
415
|
+
const groupPathPrefix = request.headers['x-group-path-prefix'] || '/';
|
|
416
|
+
|
|
417
|
+
// Child blocklets should set appInfo.link to exactly the same path as the root blocklet
|
|
418
|
+
let appUrl = baseUrl;
|
|
419
|
+
if (blockletDid !== blockletRealDid && pathPrefix !== groupPathPrefix) {
|
|
420
|
+
appUrl = joinUrl(joinUrl(appUrl, '/').replace(pathPrefix, groupPathPrefix), '');
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
return appUrl;
|
|
424
|
+
};
|
|
425
|
+
|
|
377
426
|
const replaceSlotToIp = (url, ip) => (url || '').replace(SLOT_FOR_IP_DNS_SITE, (ip || '').replace(/\./g, '-'));
|
|
378
427
|
|
|
379
428
|
const urlFriendly = (name) => slugify(name.replace(/^[@./-]/, '').replace(/[@./_]/g, '-'));
|
|
@@ -402,4 +451,6 @@ module.exports = {
|
|
|
402
451
|
getComponentName,
|
|
403
452
|
getComponentBundleId,
|
|
404
453
|
findComponentById,
|
|
454
|
+
getParentComponentName,
|
|
455
|
+
getConnectAppUrl,
|
|
405
456
|
};
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.8.
|
|
6
|
+
"version": "1.8.3",
|
|
7
7
|
"description": "Library to parse/validate/fix blocklet meta",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -18,17 +18,16 @@
|
|
|
18
18
|
"author": "wangshijun <wangshijun2020@gmail.com> (http://github.com/wangshijun)",
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@abtnode/constant": "1.8.
|
|
22
|
-
"@abtnode/util": "1.8.
|
|
23
|
-
"@arcblock/did": "1.17.
|
|
24
|
-
"@arcblock/did-ext": "1.17.
|
|
25
|
-
"@arcblock/did-util": "1.17.
|
|
26
|
-
"@arcblock/jwt": "1.17.
|
|
27
|
-
"@
|
|
28
|
-
"@ocap/
|
|
29
|
-
"@ocap/
|
|
30
|
-
"@ocap/
|
|
31
|
-
"@ocap/wallet": "1.17.0",
|
|
21
|
+
"@abtnode/constant": "1.8.3",
|
|
22
|
+
"@abtnode/util": "1.8.3",
|
|
23
|
+
"@arcblock/did": "1.17.5",
|
|
24
|
+
"@arcblock/did-ext": "1.17.5",
|
|
25
|
+
"@arcblock/did-util": "1.17.5",
|
|
26
|
+
"@arcblock/jwt": "1.17.5",
|
|
27
|
+
"@ocap/asset": "1.17.5",
|
|
28
|
+
"@ocap/mcrypto": "1.17.5",
|
|
29
|
+
"@ocap/util": "1.17.5",
|
|
30
|
+
"@ocap/wallet": "1.17.5",
|
|
32
31
|
"ajv": "^8.11.0",
|
|
33
32
|
"cjk-length": "^1.0.0",
|
|
34
33
|
"debug": "^4.3.3",
|
|
@@ -47,5 +46,5 @@
|
|
|
47
46
|
"devDependencies": {
|
|
48
47
|
"jest": "^27.4.5"
|
|
49
48
|
},
|
|
50
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "c734aca7bf1fc03378c3b082d0622b6a540a8bd3"
|
|
51
50
|
}
|