@eluvio/elv-client-js 3.1.72 → 3.1.76

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.
@@ -1094,6 +1094,8 @@ exports.DownloadFile = function _callee12(_ref13) {
1094
1094
  encryption,
1095
1095
  path,
1096
1096
  headers,
1097
+ ownerCapKey,
1098
+ ownerCap,
1097
1099
  bytesTotal,
1098
1100
  _args14 = arguments;
1099
1101
 
@@ -1139,33 +1141,53 @@ exports.DownloadFile = function _callee12(_ref13) {
1139
1141
  headers = _context14.sent;
1140
1142
  headers.Accept = "*/*"; // If not owner, indicate re-encryption
1141
1143
 
1142
- _context14.t0 = encrypted;
1144
+ ownerCapKey = "eluv.caps.iusr".concat(this.utils.AddressToHash(this.signer.address));
1145
+ _context14.next = 17;
1146
+ return _regeneratorRuntime.awrap(this.ContentObjectMetadata({
1147
+ libraryId: libraryId,
1148
+ objectId: objectId,
1149
+ metadataSubtree: ownerCapKey
1150
+ }));
1143
1151
 
1144
- if (!_context14.t0) {
1145
- _context14.next = 22;
1152
+ case 17:
1153
+ ownerCap = _context14.sent;
1154
+ _context14.t1 = encrypted;
1155
+
1156
+ if (!_context14.t1) {
1157
+ _context14.next = 26;
1146
1158
  break;
1147
1159
  }
1148
1160
 
1149
- _context14.t1 = this.utils;
1150
- _context14.t2 = this.signer.address;
1151
- _context14.next = 20;
1161
+ _context14.t2 = this.utils;
1162
+ _context14.t3 = this.signer.address;
1163
+ _context14.next = 24;
1152
1164
  return _regeneratorRuntime.awrap(this.ContentObjectOwner({
1153
1165
  objectId: objectId
1154
1166
  }));
1155
1167
 
1156
- case 20:
1157
- _context14.t3 = _context14.sent;
1158
- _context14.t0 = !_context14.t1.EqualAddress.call(_context14.t1, _context14.t2, _context14.t3);
1168
+ case 24:
1169
+ _context14.t4 = _context14.sent;
1170
+ _context14.t1 = !_context14.t2.EqualAddress.call(_context14.t2, _context14.t3, _context14.t4);
1171
+
1172
+ case 26:
1173
+ _context14.t0 = _context14.t1;
1159
1174
 
1160
- case 22:
1161
1175
  if (!_context14.t0) {
1162
- _context14.next = 24;
1176
+ _context14.next = 29;
1177
+ break;
1178
+ }
1179
+
1180
+ _context14.t0 = !ownerCap;
1181
+
1182
+ case 29:
1183
+ if (!_context14.t0) {
1184
+ _context14.next = 31;
1163
1185
  break;
1164
1186
  }
1165
1187
 
1166
1188
  headers["X-Content-Fabric-Decryption-Mode"] = "reencrypt";
1167
1189
 
1168
- case 24:
1190
+ case 31:
1169
1191
  // If using server side decryption, specify in header
1170
1192
  if (encrypted && !clientSideDecryption) {
1171
1193
  headers["X-Content-Fabric-Decryption-Mode"] = "decrypt"; // rep/files_download endpoint doesn't currently support Range header
@@ -1176,13 +1198,13 @@ exports.DownloadFile = function _callee12(_ref13) {
1176
1198
  bytesTotal = fileInfo["."].size;
1177
1199
 
1178
1200
  if (!(encrypted && clientSideDecryption)) {
1179
- _context14.next = 46;
1201
+ _context14.next = 53;
1180
1202
  break;
1181
1203
  }
1182
1204
 
1183
- _context14.t4 = _regeneratorRuntime;
1184
- _context14.t5 = this;
1185
- _context14.next = 31;
1205
+ _context14.t5 = _regeneratorRuntime;
1206
+ _context14.t6 = this;
1207
+ _context14.next = 38;
1186
1208
  return _regeneratorRuntime.awrap(this.EncryptionConk({
1187
1209
  libraryId: libraryId,
1188
1210
  objectId: objectId,
@@ -1190,39 +1212,39 @@ exports.DownloadFile = function _callee12(_ref13) {
1190
1212
  download: true
1191
1213
  }));
1192
1214
 
1193
- case 31:
1194
- _context14.t6 = _context14.sent;
1195
- _context14.t7 = path;
1196
- _context14.t8 = bytesTotal;
1197
- _context14.t9 = headers;
1198
- _context14.t10 = callback;
1199
- _context14.t11 = format;
1200
- _context14.t12 = clientSideDecryption;
1201
- _context14.t13 = chunked;
1202
- _context14.t14 = {
1203
- conk: _context14.t6,
1204
- downloadPath: _context14.t7,
1205
- bytesTotal: _context14.t8,
1206
- headers: _context14.t9,
1207
- callback: _context14.t10,
1208
- format: _context14.t11,
1209
- clientSideDecryption: _context14.t12,
1210
- chunked: _context14.t13
1215
+ case 38:
1216
+ _context14.t7 = _context14.sent;
1217
+ _context14.t8 = path;
1218
+ _context14.t9 = bytesTotal;
1219
+ _context14.t10 = headers;
1220
+ _context14.t11 = callback;
1221
+ _context14.t12 = format;
1222
+ _context14.t13 = clientSideDecryption;
1223
+ _context14.t14 = chunked;
1224
+ _context14.t15 = {
1225
+ conk: _context14.t7,
1226
+ downloadPath: _context14.t8,
1227
+ bytesTotal: _context14.t9,
1228
+ headers: _context14.t10,
1229
+ callback: _context14.t11,
1230
+ format: _context14.t12,
1231
+ clientSideDecryption: _context14.t13,
1232
+ chunked: _context14.t14
1211
1233
  };
1212
- _context14.t15 = _context14.t5.DownloadEncrypted.call(_context14.t5, _context14.t14);
1213
- _context14.next = 43;
1214
- return _context14.t4.awrap.call(_context14.t4, _context14.t15);
1234
+ _context14.t16 = _context14.t6.DownloadEncrypted.call(_context14.t6, _context14.t15);
1235
+ _context14.next = 50;
1236
+ return _context14.t5.awrap.call(_context14.t5, _context14.t16);
1215
1237
 
1216
- case 43:
1238
+ case 50:
1217
1239
  return _context14.abrupt("return", _context14.sent);
1218
1240
 
1219
- case 46:
1241
+ case 53:
1220
1242
  if (!chunkSize) {
1221
1243
  chunkSize = 10000000;
1222
1244
  }
1223
1245
 
1224
- _context14.prev = 47;
1225
- _context14.next = 50;
1246
+ _context14.prev = 54;
1247
+ _context14.next = 57;
1226
1248
  return _regeneratorRuntime.awrap(this.Download({
1227
1249
  downloadPath: path,
1228
1250
  bytesTotal: bytesTotal,
@@ -1233,15 +1255,15 @@ exports.DownloadFile = function _callee12(_ref13) {
1233
1255
  chunkSize: chunkSize
1234
1256
  }));
1235
1257
 
1236
- case 50:
1258
+ case 57:
1237
1259
  return _context14.abrupt("return", _context14.sent);
1238
1260
 
1239
- case 53:
1240
- _context14.prev = 53;
1241
- _context14.t16 = _context14["catch"](47);
1261
+ case 60:
1262
+ _context14.prev = 60;
1263
+ _context14.t17 = _context14["catch"](54);
1242
1264
 
1243
1265
  if (!(encrypted && !clientSideDecryption)) {
1244
- _context14.next = 57;
1266
+ _context14.next = 64;
1245
1267
  break;
1246
1268
  }
1247
1269
 
@@ -1249,15 +1271,15 @@ exports.DownloadFile = function _callee12(_ref13) {
1249
1271
  clientSideDecryption: true
1250
1272
  })));
1251
1273
 
1252
- case 57:
1253
- throw _context14.t16;
1274
+ case 64:
1275
+ throw _context14.t17;
1254
1276
 
1255
- case 58:
1277
+ case 65:
1256
1278
  case "end":
1257
1279
  return _context14.stop();
1258
1280
  }
1259
1281
  }
1260
- }, null, this, [[47, 53]]);
1282
+ }, null, this, [[54, 60]]);
1261
1283
  };
1262
1284
  /* Parts */
1263
1285
 
@@ -1819,7 +1841,7 @@ exports.DownloadEncrypted = function _callee18(_ref18) {
1819
1841
  * @param {string} libraryId - ID of the library
1820
1842
  * @param {string} objectId - ID of the object
1821
1843
  * @param {string} writeToken - Write token of the content object draft
1822
- * @param {string=} encryption=none - Desired encryption scheme. Options: 'none (default)', 'cgck'
1844
+ * @param {string=} encryption=none - Desired encryption scheme. Options: 'none' (default), 'cgck'
1823
1845
  *
1824
1846
  * @returns {Promise<string>} - The part write token for the part draft
1825
1847
  */
@@ -1887,7 +1909,7 @@ exports.CreatePart = function _callee19(_ref19) {
1887
1909
  * @param {string} writeToken - Write token of the content object draft
1888
1910
  * @param {string} partWriteToken - Write token of the part
1889
1911
  * @param {(ArrayBuffer | Buffer)} chunk - Data to upload
1890
- * @param {string=} encryption=none - Desired encryption scheme. Options: 'none (default)', 'cgck'
1912
+ * @param {string=} encryption=none - Desired encryption scheme. Options: 'none' (default), 'cgck'
1891
1913
  *
1892
1914
  * @returns {Promise<string>} - The part write token for the part draft
1893
1915
  */
@@ -1974,7 +1996,7 @@ exports.UploadPartChunk = function _callee20(_ref20) {
1974
1996
  * @param {string} objectId - ID of the object
1975
1997
  * @param {string} writeToken - Write token of the content object draft
1976
1998
  * @param {string} partWriteToken - Write token of the part
1977
- * @param {string=} encryption=none - Desired encryption scheme. Options: 'none (default)', 'cgck'
1999
+ * @param {string=} encryption=none - Desired encryption scheme. Options: 'none' (default), 'cgck'
1978
2000
  *
1979
2001
  * @returns {Promise<object>} - The finalize response for the new part
1980
2002
  */
@@ -2051,7 +2073,7 @@ exports.FinalizePart = function _callee21(_ref21) {
2051
2073
  * @param {string} writeToken - Write token of the content object draft
2052
2074
  * @param {(File | ArrayBuffer | Buffer)} data - Data to upload
2053
2075
  * @param {number=} chunkSize=1000000 (1MB) - Chunk size, in bytes
2054
- * @param {string=} encryption=none - Desired encryption scheme. Options: 'none (default)', 'cgck'
2076
+ * @param {string=} encryption=none - Desired encryption scheme. Options: 'none' (default), 'cgck'
2055
2077
  * @param {function=} callback - If specified, will be periodically called with current upload status
2056
2078
  * - Signature: ({bytesFinished, bytesTotal}) => {}
2057
2079
  *
package/package-lock.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eluvio/elv-client-js",
3
- "version": "3.1.72",
3
+ "version": "3.1.76",
4
4
  "lockfileVersion": 1,
5
5
  "requires": true,
6
6
  "dependencies": {
@@ -2688,6 +2688,15 @@
2688
2688
  "tslib": "^1.9.0"
2689
2689
  }
2690
2690
  },
2691
+ "chrono-node": {
2692
+ "version": "2.3.2",
2693
+ "resolved": "https://registry.npmjs.org/chrono-node/-/chrono-node-2.3.2.tgz",
2694
+ "integrity": "sha512-uZkVtF8dJ7llRzk3zrjGjV524I6NvojqMYk30tIfnUQ8ODrL8wvi/E2iEOTfcyiJaLf0dGDu9XVqNkVFNDMPCA==",
2695
+ "dev": true,
2696
+ "requires": {
2697
+ "dayjs": "^1.10.0"
2698
+ }
2699
+ },
2691
2700
  "ci-info": {
2692
2701
  "version": "2.0.0",
2693
2702
  "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-2.0.0.tgz",
@@ -3357,6 +3366,12 @@
3357
3366
  }
3358
3367
  }
3359
3368
  },
3369
+ "dayjs": {
3370
+ "version": "1.10.7",
3371
+ "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.10.7.tgz",
3372
+ "integrity": "sha512-P6twpd70BcPK34K26uJ1KT3wlhpuOAPoMwJzpsIWUxHZ7wpmbdZL/hQqBDfz7hGurYSa5PhzdhDHtt319hL3ig==",
3373
+ "dev": true
3374
+ },
3360
3375
  "debug": {
3361
3376
  "version": "2.6.9",
3362
3377
  "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
@@ -5910,9 +5925,9 @@
5910
5925
  "dev": true
5911
5926
  },
5912
5927
  "i": {
5913
- "version": "0.3.6",
5914
- "resolved": "https://registry.npmjs.org/i/-/i-0.3.6.tgz",
5915
- "integrity": "sha1-2WyScyB28HJxG2sQ/X1PZa2O4j0="
5928
+ "version": "0.3.7",
5929
+ "resolved": "https://registry.npmjs.org/i/-/i-0.3.7.tgz",
5930
+ "integrity": "sha512-FYz4wlXgkQwIPqhzC5TdNMLSE5+GS1IIDJZY/1ZiEPCT2S3COUVZeT5OW4BmW4r5LHLQuOosSwsvnroG9GR59Q=="
5916
5931
  },
5917
5932
  "iconv-lite": {
5918
5933
  "version": "0.4.24",
@@ -7191,9 +7206,9 @@
7191
7206
  }
7192
7207
  },
7193
7208
  "jsonpath-plus": {
7194
- "version": "4.0.0",
7195
- "resolved": "https://registry.npmjs.org/jsonpath-plus/-/jsonpath-plus-4.0.0.tgz",
7196
- "integrity": "sha512-e0Jtg4KAzDJKKwzbLaUtinCn0RZseWBVRTRGihSpvFlM3wTR7ExSp+PTdeTsDrLNJUe7L7JYJe8mblHX5SCT6A=="
7209
+ "version": "6.0.1",
7210
+ "resolved": "https://registry.npmjs.org/jsonpath-plus/-/jsonpath-plus-6.0.1.tgz",
7211
+ "integrity": "sha512-EvGovdvau6FyLexFH2OeXfIITlgIbgZoAZe3usiySeaIDm5QS+A10DKNpaPBBqqRSZr2HN6HVNXxtwUAr2apEw=="
7197
7212
  },
7198
7213
  "jsprim": {
7199
7214
  "version": "1.4.1",
@@ -8319,6 +8334,16 @@
8319
8334
  "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==",
8320
8335
  "dev": true
8321
8336
  },
8337
+ "stream-browserify": {
8338
+ "version": "2.0.2",
8339
+ "resolved": "https://registry.npmjs.org/stream-browserify/-/stream-browserify-2.0.2.tgz",
8340
+ "integrity": "sha512-nX6hmklHs/gr2FuxYDltq8fJA1GDlxKQCz8O/IM4atRqBH8OORmBNgfvW5gG10GT/qQ9u0CzIvr2X5Pkt6ntqg==",
8341
+ "dev": true,
8342
+ "requires": {
8343
+ "inherits": "~2.0.1",
8344
+ "readable-stream": "^2.0.2"
8345
+ }
8346
+ },
8322
8347
  "util": {
8323
8348
  "version": "0.11.1",
8324
8349
  "resolved": "https://registry.npmjs.org/util/-/util-0.11.1.tgz",
@@ -8487,9 +8512,9 @@
8487
8512
  "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA=="
8488
8513
  },
8489
8514
  "object-path": {
8490
- "version": "0.11.5",
8491
- "resolved": "https://registry.npmjs.org/object-path/-/object-path-0.11.5.tgz",
8492
- "integrity": "sha512-jgSbThcoR/s+XumvGMTMf81QVBmah+/Q7K7YduKeKVWL7N111unR2d6pZZarSk6kY/caeNxUDyxOvMWyzoU2eg=="
8515
+ "version": "0.11.8",
8516
+ "resolved": "https://registry.npmjs.org/object-path/-/object-path-0.11.8.tgz",
8517
+ "integrity": "sha512-YJjNZrlXJFM42wTBn6zgOJVar9KFJvzx6sTWDte8sWZF//cnjl0BxHNpfZx+ZffXX63A9q0b1zsFiBX4g4X5KA=="
8493
8518
  },
8494
8519
  "object-visit": {
8495
8520
  "version": "1.0.1",
@@ -10366,43 +10391,22 @@
10366
10391
  "dev": true
10367
10392
  },
10368
10393
  "stream-browserify": {
10369
- "version": "2.0.2",
10370
- "resolved": "https://registry.npmjs.org/stream-browserify/-/stream-browserify-2.0.2.tgz",
10371
- "integrity": "sha512-nX6hmklHs/gr2FuxYDltq8fJA1GDlxKQCz8O/IM4atRqBH8OORmBNgfvW5gG10GT/qQ9u0CzIvr2X5Pkt6ntqg==",
10372
- "dev": true,
10394
+ "version": "3.0.0",
10395
+ "resolved": "https://registry.npmjs.org/stream-browserify/-/stream-browserify-3.0.0.tgz",
10396
+ "integrity": "sha512-H73RAHsVBapbim0tU2JwwOiXUj+fikfiaoYAKHF3VJfA0pe2BCzkhAHBlLG6REzE+2WNZcxOXjK7lkso+9euLA==",
10373
10397
  "requires": {
10374
- "inherits": "~2.0.1",
10375
- "readable-stream": "^2.0.2"
10398
+ "inherits": "~2.0.4",
10399
+ "readable-stream": "^3.5.0"
10376
10400
  },
10377
10401
  "dependencies": {
10378
10402
  "readable-stream": {
10379
- "version": "2.3.6",
10380
- "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz",
10381
- "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==",
10382
- "dev": true,
10383
- "requires": {
10384
- "core-util-is": "~1.0.0",
10385
- "inherits": "~2.0.3",
10386
- "isarray": "~1.0.0",
10387
- "process-nextick-args": "~2.0.0",
10388
- "safe-buffer": "~5.1.1",
10389
- "string_decoder": "~1.1.1",
10390
- "util-deprecate": "~1.0.1"
10391
- }
10392
- },
10393
- "safe-buffer": {
10394
- "version": "5.1.2",
10395
- "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
10396
- "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==",
10397
- "dev": true
10398
- },
10399
- "string_decoder": {
10400
- "version": "1.1.1",
10401
- "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
10402
- "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
10403
- "dev": true,
10403
+ "version": "3.6.0",
10404
+ "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz",
10405
+ "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==",
10404
10406
  "requires": {
10405
- "safe-buffer": "~5.1.0"
10407
+ "inherits": "^2.0.3",
10408
+ "string_decoder": "^1.1.1",
10409
+ "util-deprecate": "^1.0.1"
10406
10410
  }
10407
10411
  }
10408
10412
  }
@@ -10836,9 +10840,9 @@
10836
10840
  }
10837
10841
  },
10838
10842
  "tmpl": {
10839
- "version": "1.0.4",
10840
- "resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.4.tgz",
10841
- "integrity": "sha1-I2QN17QtAEM5ERQIIOXPRA5SHdE=",
10843
+ "version": "1.0.5",
10844
+ "resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.5.tgz",
10845
+ "integrity": "sha512-3f0uOEAQwIqGuWW2MVzYg8fV/QNnc/IpuJNG837rLuczAaLVHslWHZQj4IGiEl5Hs3kkbhwL9Ab7Hrsmuj+Smw==",
10842
10846
  "dev": true
10843
10847
  },
10844
10848
  "to-arraybuffer": {
@@ -12491,8 +12495,7 @@
12491
12495
  "dependencies": {
12492
12496
  "ansi-regex": {
12493
12497
  "version": "5.0.0",
12494
- "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz",
12495
- "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg=="
12498
+ "resolved": ""
12496
12499
  },
12497
12500
  "ansi-styles": {
12498
12501
  "version": "4.3.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eluvio/elv-client-js",
3
- "version": "3.1.72",
3
+ "version": "3.1.76",
4
4
  "description": "Javascript client for the Eluvio Content Fabric",
5
5
  "main": "src/ElvClient.js",
6
6
  "author": "Kevin Talmadge",
@@ -91,6 +91,7 @@
91
91
  "ramda": "^0.27.1",
92
92
  "shell-escape": "^0.2.0",
93
93
  "sjcl": "^1.0.8",
94
+ "stream-browserify": "^3.0.0",
94
95
  "typedarray": "0.0.6",
95
96
  "unorm": "^1.5.0",
96
97
  "urijs": "^1.19.7",
@@ -176,7 +176,10 @@ class AuthorizationClient {
176
176
  let publicKey;
177
177
  if(encryption && encryption !== "none" && objectId && await this.AccessType(objectId) === ACCESS_TYPES.OBJECT) {
178
178
  const owner = await this.Owner({id: objectId});
179
- if(!Utils.EqualAddress(owner, this.client.signer.address)) {
179
+ const ownerCapKey = `eluv.caps.iusr${Utils.AddressToHash(this.client.signer.address)}`;
180
+ const ownerCap = await client.ContentObjectMetadata({libraryId, objectId, metadataSubtree: ownerCapKey});
181
+
182
+ if(!Utils.EqualAddress(owner, this.client.signer.address) && !ownerCap) {
180
183
  const cap = await this.ReEncryptionConk({libraryId, objectId});
181
184
  publicKey = cap.public_key;
182
185
  }
@@ -290,6 +290,7 @@ class FrameClient {
290
290
  "ClearCache",
291
291
  "ClearStaticToken",
292
292
  "Collection",
293
+ "CollectionTransactions",
293
294
  "ConfigUrl",
294
295
  "ContentLibraries",
295
296
  "ContentLibrary",
@@ -303,6 +304,7 @@ class FrameClient {
303
304
  "ContentObjectLibraryId",
304
305
  "ContentObjectMetadata",
305
306
  "ContentObjectOwner",
307
+ "ContentObjectTenantId",
306
308
  "ContentObjectVersions",
307
309
  "ContentObjects",
308
310
  "ContentPart",
@@ -327,6 +329,7 @@ class FrameClient {
327
329
  "CreateFileUploadJob",
328
330
  "CreateLinks",
329
331
  "CreateNTPInstance",
332
+ "CreateNonOwnerCap",
330
333
  "CreatePart",
331
334
  "CreateProductionMaster",
332
335
  "CreateSignedToken",
@@ -473,9 +473,8 @@ exports.LibraryContentTypes = async function({libraryId}) {
473
473
  * @param {object=} filterOptions - Pagination, sorting and filtering options
474
474
  * @param {number=} filterOptions.start - Start index for pagination
475
475
  * @param {number=} filterOptions.limit - Max number of objects to return
476
- * @param {string=} filterOptions.cacheId - Cache ID corresponding a previous query
477
476
  * @param {(Array<string> | string)=} filterOptions.sort - Sort by the specified key(s)
478
- * * @param {boolean=} filterOptions.sortDesc=false - Sort in descending order
477
+ * @param {boolean=} filterOptions.sortDesc - Sort in descending order
479
478
  * @param {(Array<string> | string)=} filterOptions.select - Include only the specified metadata keys (all must start with /public)
480
479
  * @param {(Array<object> | object)=} filterOptions.filter - Filter objects by metadata
481
480
  * @param {string=} filterOptions.filter.key - Key to filter on (must start with /public)
@@ -2408,7 +2407,10 @@ exports.EncryptionConk = async function({libraryId, objectId, versionHash, write
2408
2407
 
2409
2408
  const owner = await this.authClient.Owner({id: objectId});
2410
2409
 
2411
- if(!this.utils.EqualAddress(owner, this.signer.address)) {
2410
+ const ownerCapKey = `eluv.caps.iusr${this.utils.AddressToHash(this.signer.address)}`;
2411
+ const ownerCap = await this.ContentObjectMetadata({libraryId, objectId, metadataSubtree: ownerCapKey});
2412
+
2413
+ if(!this.utils.EqualAddress(owner, this.signer.address) && !ownerCap) {
2412
2414
  if(download) {
2413
2415
  return await this.authClient.ReEncryptionConk({libraryId, objectId, versionHash});
2414
2416
  } else {
@@ -21,7 +21,8 @@ const {
21
21
  ValidateVersion,
22
22
  ValidateWriteToken,
23
23
  ValidateParameters,
24
- ValidatePresence
24
+ ValidatePresence,
25
+ ValidateAddress
25
26
  } = require("../Validation");
26
27
 
27
28
  exports.SetVisibility = async function({id, visibility}) {
@@ -58,8 +59,9 @@ exports.SetVisibility = async function({id, visibility}) {
58
59
  * @methodGroup Content Objects
59
60
  * @param {string} objectId - The ID of the object
60
61
  * @param {string} permission - The key for the permission to set - See client.permissionLevels for available permissions
62
+ * @param {string} writeToken - Write token for the content object - If specified, info will be retrieved from the write draft instead of creating a new draft and finalizing
61
63
  */
62
- exports.SetPermission = async function({objectId, permission}) {
64
+ exports.SetPermission = async function({objectId, permission, writeToken}) {
63
65
  ValidateObject(objectId);
64
66
  ValidatePresence("permission", permission);
65
67
 
@@ -118,14 +120,16 @@ exports.SetPermission = async function({objectId, permission}) {
118
120
  }
119
121
  });
120
122
  } else if(!kmsConk && settings.kmsConk) {
121
- await this.EditAndFinalizeContentObject({
122
- libraryId,
123
- objectId,
124
- commitMessage: "Add encryption conk",
125
- callback: async ({writeToken}) => {
126
- await this.CreateEncryptionConk({libraryId, objectId, writeToken, createKMSConk: true});
127
- }
128
- });
123
+ const finalize = !writeToken;
124
+ if(!writeToken) {
125
+ writeToken = (await this.EditContentObject({libraryId, objectId})).writeToken;
126
+ }
127
+
128
+ await this.CreateEncryptionConk({libraryId, objectId, writeToken, createKMSConk: true});
129
+
130
+ if(finalize) {
131
+ await this.FinalizeContentObject({libraryId, objectId, writeToken, commitMessage: `Set permissions to ${permission}`});
132
+ }
129
133
  }
130
134
  };
131
135
 
@@ -622,7 +626,100 @@ exports.CopyContentObject = async function({libraryId, originalVersionHash, opti
622
626
 
623
627
  options.copy_from = originalVersionHash;
624
628
 
625
- return await this.CreateContentObject({libraryId, options});
629
+ const {objectId, writeToken} = await this.CreateContentObject({libraryId, options});
630
+ const originalObjectId = this.utils.DecodeVersionHash(originalVersionHash).objectId;
631
+ const metadata = await this.ContentObjectMetadata({versionHash: originalVersionHash});
632
+ const permission = await this.Permission({objectId: originalObjectId});
633
+
634
+ // User CAP
635
+ const userCapKey = `eluv.caps.iusr${this.utils.AddressToHash(this.signer.address)}`;
636
+
637
+ if(metadata[userCapKey]) {
638
+ const isOwner = this.utils.EqualAddress(this.signer.address, await this.ContentObjectOwner({objectId: originalObjectId}));
639
+
640
+ if(!isOwner) {
641
+ throw Error(`Current user is not owner of object ${metadata}`);
642
+ }
643
+
644
+ const userConkKey = await this.Crypto.DecryptCap(metadata[userCapKey], this.signer.signingKey.privateKey);
645
+ userConkKey.qid = objectId;
646
+
647
+ this.ReplaceMetadata({
648
+ libraryId,
649
+ objectId,
650
+ writeToken,
651
+ metadataSubtree: userCapKey,
652
+ metadata: await this.Crypto.EncryptConk(userConkKey, this.signer.signingKey.publicKey)
653
+ });
654
+ }
655
+
656
+ // KMS CAP
657
+ await Promise.all(
658
+ Object.keys(metadata)
659
+ .filter(key => key.startsWith("eluv.caps.ikms"))
660
+ .map(async kmsCapKey => await this.DeleteMetadata({
661
+ libraryId,
662
+ objectId,
663
+ writeToken,
664
+ metadataSubtree: kmsCapKey
665
+ }))
666
+ );
667
+
668
+ if(permission !== "owner") {
669
+ await this.SetPermission({objectId, permission, writeToken});
670
+ }
671
+
672
+ return await this.FinalizeContentObject({libraryId, objectId, writeToken});
673
+ };
674
+
675
+ /**
676
+ * Create a non-owner cap key using the specified public key and address
677
+ *
678
+ * @methodGroup Access Requests
679
+ * @namedParams
680
+ * @param {string} libraryId - ID of the library
681
+ * @param {string} objectId - ID of the object
682
+ * @param {string} publicKey - Public key for the target cap
683
+ * @param {string} publicAddress - Public address for the target cap key
684
+ * @param {string} writeToken - Write token for the content object - If specified, info will be retrieved from the write draft instead of creating a new draft and finalizing
685
+ *
686
+ * @returns {Promise<Object>}
687
+ */
688
+ exports.CreateNonOwnerCap = async function({objectId, libraryId, publicKey, publicAddress, writeToken}) {
689
+ publicAddress = ValidateAddress(publicAddress);
690
+ const userCapKey = `eluv.caps.iusr${this.utils.AddressToHash(this.signer.address)}`;
691
+ const userCapValue = await this.ContentObjectMetadata({objectId, libraryId, metadataSubtree: userCapKey});
692
+
693
+ if(!userCapValue) {
694
+ throw Error("No user cap found for current user");
695
+ }
696
+
697
+ const userConk = await this.Crypto.DecryptCap(userCapValue, this.signer.signingKey.privateKey);
698
+
699
+ const targetUserCapKey = `eluv.caps.iusr${this.utils.AddressToHash(publicAddress)}`;
700
+ const targetUserCapValue = await this.Crypto.EncryptConk(userConk, publicKey);
701
+
702
+ const finalize = !writeToken;
703
+ if(!writeToken) {
704
+ writeToken = await this.EditContentObject({libraryId, objectId}).writeToken;
705
+ }
706
+
707
+ this.ReplaceMetadata({
708
+ libraryId,
709
+ objectId,
710
+ writeToken,
711
+ metadataSubtree: targetUserCapKey,
712
+ metadata: targetUserCapValue
713
+ });
714
+
715
+ if(finalize) {
716
+ await this.FinalizeContentObject({
717
+ libraryId,
718
+ objectId,
719
+ writeToken,
720
+ commitMessage: "Create non-owner cap"
721
+ });
722
+ }
626
723
  };
627
724
 
628
725
  /**
@@ -641,7 +641,10 @@ exports.DownloadFile = async function({
641
641
  headers.Accept = "*/*";
642
642
 
643
643
  // If not owner, indicate re-encryption
644
- if(encrypted && !this.utils.EqualAddress(this.signer.address, await this.ContentObjectOwner({objectId}))) {
644
+ const ownerCapKey = `eluv.caps.iusr${this.utils.AddressToHash(this.signer.address)}`;
645
+ const ownerCap = await this.ContentObjectMetadata({libraryId, objectId, metadataSubtree: ownerCapKey});
646
+
647
+ if(encrypted && !this.utils.EqualAddress(this.signer.address, await this.ContentObjectOwner({objectId})) && !ownerCap) {
645
648
  headers["X-Content-Fabric-Decryption-Mode"] = "reencrypt";
646
649
  }
647
650
 
Binary file