@abtnode/util 1.8.49 → 1.8.50
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/base32.js +14 -0
- package/lib/did-document.js +66 -34
- package/package.json +6 -5
package/lib/base32.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const { fromBase58 } = require('@ocap/util');
|
|
2
|
+
const { base32 } = require('multiformats/bases/base32');
|
|
3
|
+
|
|
4
|
+
const encode = (did) => {
|
|
5
|
+
if (!did) {
|
|
6
|
+
return did;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const buffer = fromBase58(did);
|
|
10
|
+
|
|
11
|
+
return base32.encode(buffer);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
module.exports = { encode };
|
package/lib/did-document.js
CHANGED
|
@@ -1,28 +1,24 @@
|
|
|
1
|
-
const get = require('lodash/get');
|
|
2
1
|
const stringify = require('json-stable-stringify');
|
|
3
2
|
const { toBase64, toBase58 } = require('@ocap/util');
|
|
4
3
|
const joinUrl = require('url-join');
|
|
5
4
|
const pRetry = require('p-retry');
|
|
6
5
|
const debug = require('debug')('@abtnode/util:did-document');
|
|
7
6
|
const axios = require('./axios');
|
|
7
|
+
const { encode: encodeBase32 } = require('./base32');
|
|
8
8
|
|
|
9
|
-
const
|
|
9
|
+
const getDID = (address) => `did:abt:${address}`;
|
|
10
|
+
|
|
11
|
+
const update = async ({ services, didRegistryUrl, wallet }) => {
|
|
10
12
|
debug('update did document', { didRegistryUrl });
|
|
11
13
|
|
|
12
|
-
const did =
|
|
14
|
+
const did = getDID(wallet.address);
|
|
13
15
|
const time = new Date().toISOString();
|
|
14
16
|
|
|
15
17
|
const document = {
|
|
16
18
|
'@context': 'https://www.w3.org/ns/did/v1',
|
|
17
19
|
id: did,
|
|
18
20
|
controller: did,
|
|
19
|
-
service:
|
|
20
|
-
{
|
|
21
|
-
id: `${did}#dns`,
|
|
22
|
-
type: 'DNSRecords',
|
|
23
|
-
records,
|
|
24
|
-
},
|
|
25
|
-
],
|
|
21
|
+
service: services,
|
|
26
22
|
verificationMethod: [
|
|
27
23
|
{
|
|
28
24
|
id: `${did}#key-1`,
|
|
@@ -50,30 +46,66 @@ const update = async ({ records, didRegistryUrl, wallet }) => {
|
|
|
50
46
|
|
|
51
47
|
const updateWithRetry = async (...args) => pRetry(() => update(...args), { retries: 3 });
|
|
52
48
|
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
49
|
+
const getServerServices = ({ ips, wallet, domain }) => {
|
|
50
|
+
const records = ips.map((ip) => ({
|
|
51
|
+
type: 'A',
|
|
52
|
+
rr: encodeBase32(wallet.address),
|
|
53
|
+
value: ip,
|
|
54
|
+
domain,
|
|
55
|
+
}));
|
|
56
|
+
|
|
57
|
+
const services = [
|
|
58
|
+
{
|
|
59
|
+
id: getDID(wallet.address),
|
|
60
|
+
type: 'DNSRecords',
|
|
61
|
+
records,
|
|
62
|
+
},
|
|
63
|
+
];
|
|
64
|
+
|
|
65
|
+
return services;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const getBlockletServices = ({ blockletAppDid, daemonDidDomain, domain }) => {
|
|
69
|
+
return [
|
|
70
|
+
{
|
|
71
|
+
id: getDID(blockletAppDid),
|
|
72
|
+
type: 'DNSRecords',
|
|
73
|
+
records: [
|
|
74
|
+
{
|
|
75
|
+
type: 'CNAME',
|
|
76
|
+
rr: encodeBase32(blockletAppDid),
|
|
77
|
+
value: daemonDidDomain,
|
|
78
|
+
domain,
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
},
|
|
82
|
+
];
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const updateServerDocument = async ({ ips, wallet, didRegistryUrl, domain }) => {
|
|
86
|
+
const filteredIps = (ips || []).filter(Boolean);
|
|
87
|
+
if (filteredIps.length === 0) {
|
|
88
|
+
throw new Error('No DID Document to update');
|
|
76
89
|
}
|
|
90
|
+
|
|
91
|
+
const services = getServerServices({ ips: filteredIps, domain, wallet });
|
|
92
|
+
|
|
93
|
+
return updateWithRetry({ services, didRegistryUrl, wallet });
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const updateBlockletDocument = async ({ wallet, didRegistryUrl, domain, daemonDidDomain, blockletAppDid }) => {
|
|
97
|
+
const services = getBlockletServices({ blockletAppDid, daemonDidDomain, domain });
|
|
98
|
+
|
|
99
|
+
return updateWithRetry({ services, didRegistryUrl, wallet });
|
|
77
100
|
};
|
|
78
101
|
|
|
79
|
-
|
|
102
|
+
const disableDNS = async ({ wallet, didRegistryUrl }) => updateWithRetry({ services: [], didRegistryUrl, wallet });
|
|
103
|
+
|
|
104
|
+
module.exports = {
|
|
105
|
+
updateServerDocument,
|
|
106
|
+
updateBlockletDocument,
|
|
107
|
+
disableDNS,
|
|
108
|
+
getDID,
|
|
109
|
+
getServerServices,
|
|
110
|
+
getBlockletServices,
|
|
111
|
+
};
|
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.50",
|
|
7
7
|
"description": "ArcBlock's JavaScript utility",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
"author": "polunzh <polunzh@gmail.com> (http://github.com/polunzh)",
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@abtnode/constant": "1.8.
|
|
22
|
-
"@abtnode/logger": "1.8.
|
|
21
|
+
"@abtnode/constant": "1.8.50",
|
|
22
|
+
"@abtnode/logger": "1.8.50",
|
|
23
23
|
"@arcblock/jwt": "^1.18.32",
|
|
24
|
-
"@blocklet/constant": "1.8.
|
|
24
|
+
"@blocklet/constant": "1.8.50",
|
|
25
25
|
"@ocap/mcrypto": "1.18.32",
|
|
26
26
|
"@ocap/util": "1.18.32",
|
|
27
27
|
"@ocap/wallet": "1.18.32",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"is-docker": "^2.2.1",
|
|
42
42
|
"json-stable-stringify": "^1.0.1",
|
|
43
43
|
"lodash": "^4.17.21",
|
|
44
|
+
"multiformats": "9.9.0",
|
|
44
45
|
"p-retry": "4.6.1",
|
|
45
46
|
"parallel-transform": "^1.2.0",
|
|
46
47
|
"public-ip": "^4.0.4",
|
|
@@ -63,5 +64,5 @@
|
|
|
63
64
|
"fs-extra": "^10.1.0",
|
|
64
65
|
"jest": "^27.5.1"
|
|
65
66
|
},
|
|
66
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "7f3ccb957659a6791b93b6fc4fbcbbd2c42f1efd"
|
|
67
68
|
}
|