@abtnode/util 1.6.7 → 1.6.11

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.
@@ -0,0 +1,92 @@
1
+ const get = require('lodash/get');
2
+ const stringify = require('json-stable-stringify');
3
+ const { toBase64, toBase58 } = require('@ocap/util');
4
+ const joinUrl = require('url-join');
5
+ const pRetry = require('p-retry');
6
+ const debug = require('debug')('@abtnode/util:did-document');
7
+ const axios = require('./axios');
8
+
9
+ const update = async ({ records, didRegistryUrl, wallet }) => {
10
+ debug('update did document', { didRegistryUrl });
11
+
12
+ const did = `did:abt:${wallet.address}`;
13
+ const time = new Date().toISOString();
14
+
15
+ const document = {
16
+ '@context': 'https://www.w3.org/ns/did/v1',
17
+ id: did,
18
+ controller: did,
19
+ service: [
20
+ {
21
+ id: `${did}#dns`,
22
+ type: 'DNSRecords',
23
+ records,
24
+ },
25
+ ],
26
+ verificationMethod: [
27
+ {
28
+ id: `${did}#key-1`,
29
+ type: 'Ed25519Signature',
30
+ controller: did,
31
+ publicKeyMultibase: toBase58(wallet.publicKey),
32
+ },
33
+ ],
34
+ authentication: [`${did}#key-1`],
35
+ created: time,
36
+ updated: time,
37
+ };
38
+
39
+ const proof = {
40
+ type: 'Ed25519Signature',
41
+ created: time,
42
+ verificationMethod: `${did}#key-1`,
43
+ jws: toBase64(wallet.sign(stringify(document))),
44
+ };
45
+
46
+ document.proof = proof;
47
+
48
+ return axios.post(joinUrl(didRegistryUrl, '/.well-known/did-resolver/registries'), document, { timeout: 10 * 1000 });
49
+ };
50
+
51
+ const updateWithRetry = async (...args) => pRetry(() => update(...args), { retries: 3 });
52
+
53
+ const updateDaemon = async ({ ips, wallet, didRegistryUrl, domain }) => {
54
+ try {
55
+ const filteredIps = (ips || []).filter(Boolean);
56
+ if (filteredIps.length === 0) {
57
+ return {
58
+ status: 'warn',
59
+ message: 'No DID Document to update',
60
+ };
61
+ }
62
+
63
+ const records = filteredIps.map((ip) => {
64
+ return {
65
+ type: 'A',
66
+ rr: wallet.address.toLowerCase(),
67
+ value: ip,
68
+ domain,
69
+ };
70
+ });
71
+
72
+ await updateWithRetry({ records, didRegistryUrl, wallet });
73
+ return { status: 'success' };
74
+ } catch (err) {
75
+ return { status: 'error', message: get(err, 'response.data') || err.message };
76
+ }
77
+ };
78
+
79
+ const updateBlocklet = async ({ nodeDid, wallet, didRegistryUrl, domain }) => {
80
+ const records = [
81
+ {
82
+ type: 'CNAME',
83
+ rr: wallet.address.toLowerCase(),
84
+ value: `${nodeDid.toLowerCase()}.${domain}`,
85
+ domain,
86
+ },
87
+ ];
88
+
89
+ await updateWithRetry({ records, didRegistryUrl, wallet });
90
+ };
91
+
92
+ module.exports = { updateDaemon, updateBlocklet };
File without changes
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.6.7",
6
+ "version": "1.6.11",
7
7
  "description": "ArcBlock's JavaScript utility",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -19,6 +19,7 @@
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
21
  "@ocap/mcrypto": "^1.13.79",
22
+ "@ocap/util": "^1.13.79",
22
23
  "@ocap/wallet": "^1.13.79",
23
24
  "axios": "^0.21.4",
24
25
  "axios-mock-adapter": "^1.20.0",
@@ -30,6 +31,9 @@
30
31
  "hasha": "^5.2.0",
31
32
  "internal-ip": "^6.1.0",
32
33
  "is-docker": "^2.1.1",
34
+ "json-stable-stringify": "^1.0.1",
35
+ "lodash": "^4.17.21",
36
+ "p-retry": "4.6.1",
33
37
  "parallel-transform": "^1.2.0",
34
38
  "public-ip": "^4.0.2",
35
39
  "pump": "^3.0.0",
@@ -39,7 +43,8 @@
39
43
  "systeminformation": "^5.6.12",
40
44
  "through2-filter": "^3.0.0",
41
45
  "through2-map": "^3.0.0",
42
- "to-semver": "^3.0.0"
46
+ "to-semver": "^3.0.0",
47
+ "url-join": "^4.0.1"
43
48
  },
44
49
  "devDependencies": {
45
50
  "detect-port": "^1.3.0",
@@ -47,5 +52,5 @@
47
52
  "fs-extra": "^10.0.0",
48
53
  "jest": "^27.4.5"
49
54
  },
50
- "gitHead": "d681c03a398e3c7d4dbc878db93b2ab778dded81"
55
+ "gitHead": "3e98db6be1337968182396e6aac1b3de53b03807"
51
56
  }