moeralib 0.18.0 → 0.18.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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateNamingSchema = exports.shorten = exports.resolve = exports.expand = exports.parseNodeName = exports.DEV_NAMING_SERVER = exports.MAIN_NAMING_SERVER = exports.MoeraNamingConnectionError = exports.MoeraNamingApiError = exports.MoeraNamingError = exports.MoeraNaming = void 0;
3
+ exports.validateNamingSchema = exports.shorten = exports.resolve = exports.expand = exports.parseNodeName = exports.ANONYMOUS_NODE_PRIVATE_KEY = exports.ANONYMOUS_NODE_PUBLIC_KEY = exports.ANONYMOUS_NODE_NAME = exports.DEV_NAMING_SERVER = exports.MAIN_NAMING_SERVER = exports.MoeraNamingConnectionError = exports.MoeraNamingApiError = exports.MoeraNamingError = exports.MoeraNaming = void 0;
4
4
  var naming_1 = require("./naming");
5
5
  Object.defineProperty(exports, "MoeraNaming", { enumerable: true, get: function () { return naming_1.MoeraNaming; } });
6
6
  Object.defineProperty(exports, "MoeraNamingError", { enumerable: true, get: function () { return naming_1.MoeraNamingError; } });
@@ -8,6 +8,9 @@ Object.defineProperty(exports, "MoeraNamingApiError", { enumerable: true, get: f
8
8
  Object.defineProperty(exports, "MoeraNamingConnectionError", { enumerable: true, get: function () { return naming_1.MoeraNamingConnectionError; } });
9
9
  Object.defineProperty(exports, "MAIN_NAMING_SERVER", { enumerable: true, get: function () { return naming_1.MAIN_NAMING_SERVER; } });
10
10
  Object.defineProperty(exports, "DEV_NAMING_SERVER", { enumerable: true, get: function () { return naming_1.DEV_NAMING_SERVER; } });
11
+ Object.defineProperty(exports, "ANONYMOUS_NODE_NAME", { enumerable: true, get: function () { return naming_1.ANONYMOUS_NODE_NAME; } });
12
+ Object.defineProperty(exports, "ANONYMOUS_NODE_PUBLIC_KEY", { enumerable: true, get: function () { return naming_1.ANONYMOUS_NODE_PUBLIC_KEY; } });
13
+ Object.defineProperty(exports, "ANONYMOUS_NODE_PRIVATE_KEY", { enumerable: true, get: function () { return naming_1.ANONYMOUS_NODE_PRIVATE_KEY; } });
11
14
  Object.defineProperty(exports, "parseNodeName", { enumerable: true, get: function () { return naming_1.parseNodeName; } });
12
15
  Object.defineProperty(exports, "expand", { enumerable: true, get: function () { return naming_1.expand; } });
13
16
  Object.defineProperty(exports, "resolve", { enumerable: true, get: function () { return naming_1.resolve; } });
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.MoeraNaming = exports.MoeraNamingConnectionError = exports.MoeraNamingApiError = exports.MoeraNamingError = exports.DEV_NAMING_SERVER = exports.MAIN_NAMING_SERVER = void 0;
12
+ exports.MoeraNaming = exports.MoeraNamingConnectionError = exports.MoeraNamingApiError = exports.MoeraNamingError = exports.ANONYMOUS_NODE_PRIVATE_KEY = exports.ANONYMOUS_NODE_PUBLIC_KEY = exports.ANONYMOUS_NODE_NAME = exports.DEV_NAMING_SERVER = exports.MAIN_NAMING_SERVER = void 0;
13
13
  exports.parseNodeName = parseNodeName;
14
14
  exports.shorten = shorten;
15
15
  exports.expand = expand;
@@ -25,6 +25,18 @@ exports.MAIN_NAMING_SERVER = "https://naming.moera.org/moera-naming";
25
25
  * Moera developers' naming server.
26
26
  */
27
27
  exports.DEV_NAMING_SERVER = "https://naming-dev.moera.org/moera-naming";
28
+ /**
29
+ * Node name used to represent anonymous content author.
30
+ */
31
+ exports.ANONYMOUS_NODE_NAME = "unk_0";
32
+ /**
33
+ * Public key used to verify signatures of anonymous content.
34
+ */
35
+ exports.ANONYMOUS_NODE_PUBLIC_KEY = Buffer.from("VNKYmrV8b1XR7phWvrTUbkfnxsPTKvHIcvJLGrBZQr0Z8eKVdTooBkIWS0CECPjLxPGaQkcKkMcZ6M6wEsJm9A==", "base64");
36
+ /**
37
+ * Private key used to sign anonymous content.
38
+ */
39
+ exports.ANONYMOUS_NODE_PRIVATE_KEY = Buffer.from("tCb+02pUSC6FLdQLPvrUhSBjD0xiV5Q+fQmZY3PKybo=", "base64");
28
40
  /**
29
41
  * Generic naming server error.
30
42
  */
@@ -116,8 +116,9 @@ function generateCarte(ownerName_1, signingKey_1, beginning_1) {
116
116
  if (Array.isArray(adminScope)) {
117
117
  adminScope = toScopeMask(adminScope);
118
118
  }
119
+ const addresses = address == null ? null : Array.isArray(address) ? address : [address];
119
120
  const salt = yield (0, util_1.promisify)(crypto_1.default.randomBytes)(8);
120
- const fingerprint = (0, fingerprints_1.createCarteFingerprint2)(ownerName, address, beginning, beginning + ttl, nodeName, clientScope, adminScope, salt);
121
+ const fingerprint = (0, fingerprints_1.createCarteFingerprint3)(ownerName, addresses, beginning, beginning + ttl, nodeName, clientScope, adminScope, salt);
121
122
  const signature = (0, crypto_2.signFingerprint)(fingerprint, signingKey);
122
123
  return Buffer.concat([fingerprint, signature]).toString("base64url");
123
124
  });
@@ -2,9 +2,11 @@
2
2
  // This file is generated
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.createAttachmentFingerprint0 = createAttachmentFingerprint0;
5
+ exports.createCarteFingerprint3 = createCarteFingerprint3;
5
6
  exports.createCarteFingerprint2 = createCarteFingerprint2;
6
7
  exports.createCarteFingerprint1 = createCarteFingerprint1;
7
8
  exports.createCarteFingerprint0 = createCarteFingerprint0;
9
+ exports.createCommentFingerprint1 = createCommentFingerprint1;
8
10
  exports.createCommentFingerprint0 = createCommentFingerprint0;
9
11
  exports.createNotificationPacketFingerprint1 = createNotificationPacketFingerprint1;
10
12
  exports.createNotificationPacketFingerprint0 = createNotificationPacketFingerprint0;
@@ -23,6 +25,22 @@ const ATTACHMENT_FINGERPRINT0_SCHEMA = [
23
25
  function createAttachmentFingerprint0(digest) {
24
26
  return (0, crypto_1.fingerprintBytes)({ "version": 0, "objectType": "ATTACHMENT", digest }, ATTACHMENT_FINGERPRINT0_SCHEMA);
25
27
  }
28
+ const CARTE_FINGERPRINT3_SCHEMA = [
29
+ ["version", "number"],
30
+ ["objectType", "string"],
31
+ ["ownerName", "string"],
32
+ ["addresses", "string[]"],
33
+ ["beginning", "number"],
34
+ ["deadline", "number"],
35
+ ["nodeName", "string"],
36
+ ["clientScope", "number"],
37
+ ["adminScope", "number"],
38
+ ["salt", "bytes"],
39
+ ];
40
+ function createCarteFingerprint3(ownerName, addresses, beginning, deadline, nodeName, clientScope, adminScope, salt) {
41
+ return (0, crypto_1.fingerprintBytes)({ "version": 3, "objectType": "CARTE", ownerName, addresses, beginning, deadline, nodeName, clientScope,
42
+ adminScope, salt }, CARTE_FINGERPRINT3_SCHEMA);
43
+ }
26
44
  const CARTE_FINGERPRINT2_SCHEMA = [
27
45
  ["version", "number"],
28
46
  ["objectType", "string"],
@@ -66,6 +84,24 @@ const CARTE_FINGERPRINT0_SCHEMA = [
66
84
  function createCarteFingerprint0(ownerName, address, beginning, deadline, permissions, salt) {
67
85
  return (0, crypto_1.fingerprintBytes)({ "version": 0, "objectType": "CARTE", ownerName, address, beginning, deadline, permissions, salt }, CARTE_FINGERPRINT0_SCHEMA);
68
86
  }
87
+ const COMMENT_FINGERPRINT1_SCHEMA = [
88
+ ["version", "number"],
89
+ ["objectType", "string"],
90
+ ["ownerName", "string"],
91
+ ["postingFingerprint", "bytes"],
92
+ ["repliedToFingerprint", "bytes"],
93
+ ["bodySrcHash", "bytes"],
94
+ ["bodySrcFormat", "string"],
95
+ ["body", "string"],
96
+ ["bodyFormat", "string"],
97
+ ["createdAt", "number"],
98
+ ["permissions", "number"],
99
+ ["attachments", "bytes[]"],
100
+ ];
101
+ function createCommentFingerprint1(ownerName, postingFingerprint, repliedToFingerprint, bodySrcHash, bodySrcFormat, body, bodyFormat, createdAt, permissions, attachments) {
102
+ return (0, crypto_1.fingerprintBytes)({ "version": 1, "objectType": "COMMENT", ownerName, postingFingerprint, repliedToFingerprint, bodySrcHash,
103
+ bodySrcFormat, body, bodyFormat, createdAt, permissions, attachments }, COMMENT_FINGERPRINT1_SCHEMA);
104
+ }
69
105
  const COMMENT_FINGERPRINT0_SCHEMA = [
70
106
  ["version", "number"],
71
107
  ["objectType", "string"],
package/lib/node/node.js CHANGED
@@ -1398,12 +1398,14 @@ class MoeraNode extends caller_1.Caller {
1398
1398
  * the smallest in size, but the best in quality variant of the media, according to the width provided
1399
1399
  * @param {boolean | null} download - if ``true``, the node will add ``Content-Disposition: attachment`` header to
1400
1400
  * the output
1401
+ * @param {boolean | null} ignoremalware - if ``true``, the node will ignore malware detection and return the media
1402
+ * file; only admin may use this option
1401
1403
  * @return {Promise<Blob>}
1402
1404
  */
1403
1405
  getPrivateMedia(id_1) {
1404
- return __awaiter(this, arguments, void 0, function* (id, width = null, download = null) {
1406
+ return __awaiter(this, arguments, void 0, function* (id, width = null, download = null, ignoremalware = null) {
1405
1407
  const location = (0, util_1.ut) `/media/private/${id}/data`;
1406
- const params = { width, download };
1408
+ const params = { width, download, ignoremalware };
1407
1409
  return yield this.call("getPrivateMedia", location, {
1408
1410
  method: "GET", params, schema: "blob"
1409
1411
  });
@@ -1423,6 +1425,21 @@ class MoeraNode extends caller_1.Caller {
1423
1425
  });
1424
1426
  });
1425
1427
  }
1428
+ /**
1429
+ * Update media file details.
1430
+ *
1431
+ * @param {string} id - media file ID
1432
+ * @param {API.PrivateMediaFileAttributes} attributes
1433
+ * @return {Promise<API.PrivateMediaFileInfo>}
1434
+ */
1435
+ updatePrivateMediaInfo(id, attributes) {
1436
+ return __awaiter(this, void 0, void 0, function* () {
1437
+ const location = (0, util_1.ut) `/media/private/${id}/info`;
1438
+ return yield this.call("updatePrivateMediaInfo", location, {
1439
+ method: "PUT", body: attributes, schema: "PrivateMediaFileInfo"
1440
+ });
1441
+ });
1442
+ }
1426
1443
  /**
1427
1444
  * Get the list of all postings and comments the media file is attached to.
1428
1445
  *
@@ -2355,6 +2372,21 @@ class MoeraNode extends caller_1.Caller {
2355
2372
  });
2356
2373
  });
2357
2374
  }
2375
+ /**
2376
+ * Download the private media file from the remote node and store it at the home node.
2377
+ *
2378
+ * @param {string} remoteNodeName - name of the remote node
2379
+ * @param {string} id - id of the media file
2380
+ * @return {Promise<API.PrivateMediaFileInfo>}
2381
+ */
2382
+ downloadRemoteMedia(remoteNodeName, id) {
2383
+ return __awaiter(this, void 0, void 0, function* () {
2384
+ const location = (0, util_1.ut) `/nodes/${remoteNodeName}/media/private/${id}/download`;
2385
+ return yield this.call("downloadRemoteMedia", location, {
2386
+ method: "POST", schema: "PrivateMediaFileInfo"
2387
+ });
2388
+ });
2389
+ }
2358
2390
  /**
2359
2391
  * Add a posting to the remote node and register it in the registry at the local node.
2360
2392
  *