@eluvio/elv-client-js 3.2.41 → 3.2.43
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/dist/ElvClient-min.js +4 -4
- package/dist/ElvClient-node-min.js +6 -6
- package/dist/ElvWalletClient-min.js +4 -4
- package/dist/ElvWalletClient-node-min.js +6 -6
- package/dist/src/AuthorizationClient.js +507 -599
- package/dist/src/client/ContentManagement.js +152 -52
- package/dist/src/walletClient/Notifications.js +5 -0
- package/package.json +1 -1
- package/src/AuthorizationClient.js +0 -43
- package/src/client/ContentAccess.js +0 -1
- package/src/client/ContentManagement.js +71 -8
- package/src/walletClient/index.js +1 -1
|
@@ -20,6 +20,8 @@ var UrlJoin = require("url-join");
|
|
|
20
20
|
var ImageType = require("image-type");
|
|
21
21
|
|
|
22
22
|
var Ethers = require("ethers");
|
|
23
|
+
|
|
24
|
+
var Pako = require("pako");
|
|
23
25
|
/*
|
|
24
26
|
const LibraryContract = require("../contracts/BaseLibrary");
|
|
25
27
|
const ContentContract = require("../contracts/BaseContent");
|
|
@@ -1283,10 +1285,11 @@ exports.CopyContentObject = /*#__PURE__*/function () {
|
|
|
1283
1285
|
}
|
|
1284
1286
|
|
|
1285
1287
|
_context13.next = 38;
|
|
1286
|
-
return this.
|
|
1288
|
+
return this.CreateEncryptionConk({
|
|
1289
|
+
libraryId: libraryId,
|
|
1287
1290
|
objectId: objectId,
|
|
1288
|
-
|
|
1289
|
-
|
|
1291
|
+
writeToken: writeToken,
|
|
1292
|
+
createKMSConk: true
|
|
1290
1293
|
});
|
|
1291
1294
|
|
|
1292
1295
|
case 38:
|
|
@@ -2633,6 +2636,103 @@ exports.UpdateContentObjectGraph = /*#__PURE__*/function () {
|
|
|
2633
2636
|
return _ref52.apply(this, arguments);
|
|
2634
2637
|
};
|
|
2635
2638
|
}();
|
|
2639
|
+
/**
|
|
2640
|
+
* Generate a signed link token.
|
|
2641
|
+
*
|
|
2642
|
+
* @methodGroup Access Requests
|
|
2643
|
+
* @namedParams
|
|
2644
|
+
* @param {string=} containerId - ID of the container object
|
|
2645
|
+
* @param {string=} versionHash - Version hash of the object
|
|
2646
|
+
* @param {string=} link - Path
|
|
2647
|
+
* @param {string=} duration - How long the link should last in milliseconds
|
|
2648
|
+
*
|
|
2649
|
+
* @return {Promise<string>} - The state channel token
|
|
2650
|
+
*/
|
|
2651
|
+
|
|
2652
|
+
|
|
2653
|
+
exports.GenerateSignedLinkToken = /*#__PURE__*/function () {
|
|
2654
|
+
var _ref56 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee31(_ref55) {
|
|
2655
|
+
var containerId, versionHash, link, duration, canEdit, _this$utils$DecodeVer2, objectId, signerAddress, token, compressedToken, signature;
|
|
2656
|
+
|
|
2657
|
+
return _regeneratorRuntime.wrap(function _callee31$(_context32) {
|
|
2658
|
+
while (1) {
|
|
2659
|
+
switch (_context32.prev = _context32.next) {
|
|
2660
|
+
case 0:
|
|
2661
|
+
containerId = _ref55.containerId, versionHash = _ref55.versionHash, link = _ref55.link, duration = _ref55.duration;
|
|
2662
|
+
ValidateObject(containerId);
|
|
2663
|
+
_context32.next = 4;
|
|
2664
|
+
return this.CallContractMethod({
|
|
2665
|
+
contractAddress: this.utils.HashToAddress(containerId),
|
|
2666
|
+
methodName: "canEdit"
|
|
2667
|
+
});
|
|
2668
|
+
|
|
2669
|
+
case 4:
|
|
2670
|
+
canEdit = _context32.sent;
|
|
2671
|
+
_this$utils$DecodeVer2 = this.utils.DecodeVersionHash(versionHash), objectId = _this$utils$DecodeVer2.objectId;
|
|
2672
|
+
|
|
2673
|
+
if (canEdit) {
|
|
2674
|
+
_context32.next = 8;
|
|
2675
|
+
break;
|
|
2676
|
+
}
|
|
2677
|
+
|
|
2678
|
+
throw Error("Current user does not have permission to edit content object ".concat(objectId));
|
|
2679
|
+
|
|
2680
|
+
case 8:
|
|
2681
|
+
signerAddress = this.CurrentAccountAddress();
|
|
2682
|
+
_context32.t0 = this.utils.B64(signerAddress.replace("0x", ""), "hex");
|
|
2683
|
+
_context32.next = 12;
|
|
2684
|
+
return this.ContentSpaceId();
|
|
2685
|
+
|
|
2686
|
+
case 12:
|
|
2687
|
+
_context32.t1 = _context32.sent;
|
|
2688
|
+
_context32.next = 15;
|
|
2689
|
+
return this.ContentObjectLibraryId({
|
|
2690
|
+
objectId: objectId
|
|
2691
|
+
});
|
|
2692
|
+
|
|
2693
|
+
case 15:
|
|
2694
|
+
_context32.t2 = _context32.sent;
|
|
2695
|
+
_context32.t3 = objectId;
|
|
2696
|
+
_context32.t4 = "iusr".concat(this.utils.AddressToHash(signerAddress));
|
|
2697
|
+
_context32.t5 = Date.now();
|
|
2698
|
+
_context32.t6 = duration ? Date.now() + duration : "";
|
|
2699
|
+
_context32.t7 = {
|
|
2700
|
+
elv: {
|
|
2701
|
+
lnk: link,
|
|
2702
|
+
src: containerId
|
|
2703
|
+
}
|
|
2704
|
+
};
|
|
2705
|
+
token = {
|
|
2706
|
+
adr: _context32.t0,
|
|
2707
|
+
spc: _context32.t1,
|
|
2708
|
+
lib: _context32.t2,
|
|
2709
|
+
qid: _context32.t3,
|
|
2710
|
+
sub: _context32.t4,
|
|
2711
|
+
gra: "read",
|
|
2712
|
+
iat: _context32.t5,
|
|
2713
|
+
exp: _context32.t6,
|
|
2714
|
+
ctx: _context32.t7
|
|
2715
|
+
};
|
|
2716
|
+
compressedToken = Pako.deflateRaw(Buffer.from(JSON.stringify(token), "utf-8"));
|
|
2717
|
+
_context32.next = 25;
|
|
2718
|
+
return this.authClient.Sign(Ethers.utils.keccak256(compressedToken));
|
|
2719
|
+
|
|
2720
|
+
case 25:
|
|
2721
|
+
signature = _context32.sent;
|
|
2722
|
+
return _context32.abrupt("return", "aslsjc".concat(this.utils.B58(Buffer.concat([Buffer.from(signature.replace(/^0x/, ""), "hex"), Buffer.from(compressedToken)]))));
|
|
2723
|
+
|
|
2724
|
+
case 27:
|
|
2725
|
+
case "end":
|
|
2726
|
+
return _context32.stop();
|
|
2727
|
+
}
|
|
2728
|
+
}
|
|
2729
|
+
}, _callee31, this);
|
|
2730
|
+
}));
|
|
2731
|
+
|
|
2732
|
+
return function (_x29) {
|
|
2733
|
+
return _ref56.apply(this, arguments);
|
|
2734
|
+
};
|
|
2735
|
+
}();
|
|
2636
2736
|
/**
|
|
2637
2737
|
* Create links to files, metadata and/or representations of this or or other
|
|
2638
2738
|
* content objects.
|
|
@@ -2661,28 +2761,28 @@ exports.UpdateContentObjectGraph = /*#__PURE__*/function () {
|
|
|
2661
2761
|
|
|
2662
2762
|
|
|
2663
2763
|
exports.CreateLinks = /*#__PURE__*/function () {
|
|
2664
|
-
var
|
|
2764
|
+
var _ref58 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee33(_ref57) {
|
|
2665
2765
|
var _this6 = this;
|
|
2666
2766
|
|
|
2667
|
-
var libraryId, objectId, writeToken,
|
|
2767
|
+
var libraryId, objectId, writeToken, _ref57$links, links;
|
|
2668
2768
|
|
|
2669
|
-
return _regeneratorRuntime.wrap(function
|
|
2769
|
+
return _regeneratorRuntime.wrap(function _callee33$(_context34) {
|
|
2670
2770
|
while (1) {
|
|
2671
|
-
switch (
|
|
2771
|
+
switch (_context34.prev = _context34.next) {
|
|
2672
2772
|
case 0:
|
|
2673
|
-
libraryId =
|
|
2773
|
+
libraryId = _ref57.libraryId, objectId = _ref57.objectId, writeToken = _ref57.writeToken, _ref57$links = _ref57.links, links = _ref57$links === void 0 ? [] : _ref57$links;
|
|
2674
2774
|
ValidateParameters({
|
|
2675
2775
|
libraryId: libraryId,
|
|
2676
2776
|
objectId: objectId
|
|
2677
2777
|
});
|
|
2678
2778
|
ValidateWriteToken(writeToken);
|
|
2679
|
-
|
|
2779
|
+
_context34.next = 5;
|
|
2680
2780
|
return this.utils.LimitedMap(10, links, /*#__PURE__*/function () {
|
|
2681
|
-
var
|
|
2781
|
+
var _ref59 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee32(info) {
|
|
2682
2782
|
var path, type, target, authTarget, link, linkMetadata;
|
|
2683
|
-
return _regeneratorRuntime.wrap(function
|
|
2783
|
+
return _regeneratorRuntime.wrap(function _callee32$(_context33) {
|
|
2684
2784
|
while (1) {
|
|
2685
|
-
switch (
|
|
2785
|
+
switch (_context33.prev = _context33.next) {
|
|
2686
2786
|
case 0:
|
|
2687
2787
|
path = info.path.replace(/^(\/|\.)+/, "");
|
|
2688
2788
|
type = (info.type || "file") === "file" ? "files" : info.type;
|
|
@@ -2713,11 +2813,11 @@ exports.CreateLinks = /*#__PURE__*/function () {
|
|
|
2713
2813
|
|
|
2714
2814
|
|
|
2715
2815
|
if (!info.authContainer) {
|
|
2716
|
-
|
|
2816
|
+
_context33.next = 17;
|
|
2717
2817
|
break;
|
|
2718
2818
|
}
|
|
2719
2819
|
|
|
2720
|
-
|
|
2820
|
+
_context33.next = 10;
|
|
2721
2821
|
return _this6.ContentObjectMetadata({
|
|
2722
2822
|
libraryId: libraryId,
|
|
2723
2823
|
objectId: objectId,
|
|
@@ -2725,7 +2825,7 @@ exports.CreateLinks = /*#__PURE__*/function () {
|
|
|
2725
2825
|
});
|
|
2726
2826
|
|
|
2727
2827
|
case 10:
|
|
2728
|
-
linkMetadata =
|
|
2828
|
+
linkMetadata = _context33.sent;
|
|
2729
2829
|
|
|
2730
2830
|
if (linkMetadata) {
|
|
2731
2831
|
link = linkMetadata;
|
|
@@ -2734,22 +2834,22 @@ exports.CreateLinks = /*#__PURE__*/function () {
|
|
|
2734
2834
|
if (!link["."]) link["."] = {};
|
|
2735
2835
|
|
|
2736
2836
|
if (linkMetadata["."]["authorization"]) {
|
|
2737
|
-
|
|
2837
|
+
_context33.next = 17;
|
|
2738
2838
|
break;
|
|
2739
2839
|
}
|
|
2740
2840
|
|
|
2741
|
-
|
|
2742
|
-
return _this6.
|
|
2841
|
+
_context33.next = 16;
|
|
2842
|
+
return _this6.GenerateSignedLinkToken({
|
|
2743
2843
|
containerId: info.authContainer,
|
|
2744
2844
|
versionHash: info.targetHash,
|
|
2745
2845
|
link: "./".concat(type, "/").concat(authTarget)
|
|
2746
2846
|
});
|
|
2747
2847
|
|
|
2748
2848
|
case 16:
|
|
2749
|
-
link["."]["authorization"] =
|
|
2849
|
+
link["."]["authorization"] = _context33.sent;
|
|
2750
2850
|
|
|
2751
2851
|
case 17:
|
|
2752
|
-
|
|
2852
|
+
_context33.next = 19;
|
|
2753
2853
|
return _this6.ReplaceMetadata({
|
|
2754
2854
|
libraryId: libraryId,
|
|
2755
2855
|
objectId: objectId,
|
|
@@ -2760,27 +2860,27 @@ exports.CreateLinks = /*#__PURE__*/function () {
|
|
|
2760
2860
|
|
|
2761
2861
|
case 19:
|
|
2762
2862
|
case "end":
|
|
2763
|
-
return
|
|
2863
|
+
return _context33.stop();
|
|
2764
2864
|
}
|
|
2765
2865
|
}
|
|
2766
|
-
},
|
|
2866
|
+
}, _callee32);
|
|
2767
2867
|
}));
|
|
2768
2868
|
|
|
2769
|
-
return function (
|
|
2770
|
-
return
|
|
2869
|
+
return function (_x31) {
|
|
2870
|
+
return _ref59.apply(this, arguments);
|
|
2771
2871
|
};
|
|
2772
2872
|
}());
|
|
2773
2873
|
|
|
2774
2874
|
case 5:
|
|
2775
2875
|
case "end":
|
|
2776
|
-
return
|
|
2876
|
+
return _context34.stop();
|
|
2777
2877
|
}
|
|
2778
2878
|
}
|
|
2779
|
-
},
|
|
2879
|
+
}, _callee33, this);
|
|
2780
2880
|
}));
|
|
2781
2881
|
|
|
2782
|
-
return function (
|
|
2783
|
-
return
|
|
2882
|
+
return function (_x30) {
|
|
2883
|
+
return _ref58.apply(this, arguments);
|
|
2784
2884
|
};
|
|
2785
2885
|
}();
|
|
2786
2886
|
/**
|
|
@@ -2800,14 +2900,14 @@ exports.CreateLinks = /*#__PURE__*/function () {
|
|
|
2800
2900
|
|
|
2801
2901
|
|
|
2802
2902
|
exports.InitializeAuthPolicy = /*#__PURE__*/function () {
|
|
2803
|
-
var
|
|
2804
|
-
var libraryId, objectId, writeToken,
|
|
2903
|
+
var _ref61 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee34(_ref60) {
|
|
2904
|
+
var libraryId, objectId, writeToken, _ref60$target, target, body, version, description, id, authPolicy, string;
|
|
2805
2905
|
|
|
2806
|
-
return _regeneratorRuntime.wrap(function
|
|
2906
|
+
return _regeneratorRuntime.wrap(function _callee34$(_context35) {
|
|
2807
2907
|
while (1) {
|
|
2808
|
-
switch (
|
|
2908
|
+
switch (_context35.prev = _context35.next) {
|
|
2809
2909
|
case 0:
|
|
2810
|
-
libraryId =
|
|
2910
|
+
libraryId = _ref60.libraryId, objectId = _ref60.objectId, writeToken = _ref60.writeToken, _ref60$target = _ref60.target, target = _ref60$target === void 0 ? "auth_policy_spec" : _ref60$target, body = _ref60.body, version = _ref60.version, description = _ref60.description, id = _ref60.id;
|
|
2811
2911
|
authPolicy = {
|
|
2812
2912
|
type: "epl-ast",
|
|
2813
2913
|
version: version,
|
|
@@ -2820,14 +2920,14 @@ exports.InitializeAuthPolicy = /*#__PURE__*/function () {
|
|
|
2820
2920
|
id: id || ""
|
|
2821
2921
|
};
|
|
2822
2922
|
string = "".concat(authPolicy.type, "|").concat(authPolicy.version, "|").concat(authPolicy.body, "|").concat(authPolicy.data["/"]);
|
|
2823
|
-
|
|
2824
|
-
|
|
2923
|
+
_context35.t0 = this.utils;
|
|
2924
|
+
_context35.next = 6;
|
|
2825
2925
|
return this.authClient.Sign(Ethers.utils.keccak256(Ethers.utils.toUtf8Bytes(string)));
|
|
2826
2926
|
|
|
2827
2927
|
case 6:
|
|
2828
|
-
|
|
2829
|
-
authPolicy.signature =
|
|
2830
|
-
|
|
2928
|
+
_context35.t1 = _context35.sent;
|
|
2929
|
+
authPolicy.signature = _context35.t0.FormatSignature.call(_context35.t0, _context35.t1);
|
|
2930
|
+
_context35.next = 10;
|
|
2831
2931
|
return this.ReplaceMetadata({
|
|
2832
2932
|
libraryId: libraryId,
|
|
2833
2933
|
objectId: objectId,
|
|
@@ -2837,7 +2937,7 @@ exports.InitializeAuthPolicy = /*#__PURE__*/function () {
|
|
|
2837
2937
|
});
|
|
2838
2938
|
|
|
2839
2939
|
case 10:
|
|
2840
|
-
|
|
2940
|
+
_context35.next = 12;
|
|
2841
2941
|
return this.SetAuthPolicy({
|
|
2842
2942
|
objectId: objectId,
|
|
2843
2943
|
policyId: objectId
|
|
@@ -2845,14 +2945,14 @@ exports.InitializeAuthPolicy = /*#__PURE__*/function () {
|
|
|
2845
2945
|
|
|
2846
2946
|
case 12:
|
|
2847
2947
|
case "end":
|
|
2848
|
-
return
|
|
2948
|
+
return _context35.stop();
|
|
2849
2949
|
}
|
|
2850
2950
|
}
|
|
2851
|
-
},
|
|
2951
|
+
}, _callee34, this);
|
|
2852
2952
|
}));
|
|
2853
2953
|
|
|
2854
|
-
return function (
|
|
2855
|
-
return
|
|
2954
|
+
return function (_x32) {
|
|
2955
|
+
return _ref61.apply(this, arguments);
|
|
2856
2956
|
};
|
|
2857
2957
|
}();
|
|
2858
2958
|
/**
|
|
@@ -2866,14 +2966,14 @@ exports.InitializeAuthPolicy = /*#__PURE__*/function () {
|
|
|
2866
2966
|
|
|
2867
2967
|
|
|
2868
2968
|
exports.SetAuthPolicy = /*#__PURE__*/function () {
|
|
2869
|
-
var
|
|
2969
|
+
var _ref63 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee35(_ref62) {
|
|
2870
2970
|
var objectId, policyId;
|
|
2871
|
-
return _regeneratorRuntime.wrap(function
|
|
2971
|
+
return _regeneratorRuntime.wrap(function _callee35$(_context36) {
|
|
2872
2972
|
while (1) {
|
|
2873
|
-
switch (
|
|
2973
|
+
switch (_context36.prev = _context36.next) {
|
|
2874
2974
|
case 0:
|
|
2875
|
-
objectId =
|
|
2876
|
-
|
|
2975
|
+
objectId = _ref62.objectId, policyId = _ref62.policyId;
|
|
2976
|
+
_context36.next = 3;
|
|
2877
2977
|
return this.MergeContractMetadata({
|
|
2878
2978
|
contractAddress: this.utils.HashToAddress(objectId),
|
|
2879
2979
|
metadataKey: "_AUTH_CONTEXT",
|
|
@@ -2884,13 +2984,13 @@ exports.SetAuthPolicy = /*#__PURE__*/function () {
|
|
|
2884
2984
|
|
|
2885
2985
|
case 3:
|
|
2886
2986
|
case "end":
|
|
2887
|
-
return
|
|
2987
|
+
return _context36.stop();
|
|
2888
2988
|
}
|
|
2889
2989
|
}
|
|
2890
|
-
},
|
|
2990
|
+
}, _callee35, this);
|
|
2891
2991
|
}));
|
|
2892
2992
|
|
|
2893
|
-
return function (
|
|
2894
|
-
return
|
|
2993
|
+
return function (_x33) {
|
|
2994
|
+
return _ref63.apply(this, arguments);
|
|
2895
2995
|
};
|
|
2896
2996
|
}();
|
|
@@ -2,6 +2,11 @@ var _regeneratorRuntime = require("@babel/runtime/regenerator");
|
|
|
2
2
|
|
|
3
3
|
var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator");
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Methods related to notifications for the current user.
|
|
7
|
+
*
|
|
8
|
+
* @module Notifications
|
|
9
|
+
*/
|
|
5
10
|
var Utils = require("../Utils");
|
|
6
11
|
|
|
7
12
|
var UrlJoin = require("url-join");
|
package/package.json
CHANGED
|
@@ -3,8 +3,6 @@ const Ethers = require("ethers");
|
|
|
3
3
|
const Utils = require("./Utils");
|
|
4
4
|
const UrlJoin = require("url-join");
|
|
5
5
|
const {LogMessage} = require("./LogMessage");
|
|
6
|
-
const {ValidateObject} = require("./Validation");
|
|
7
|
-
const Pako = require("pako");
|
|
8
6
|
|
|
9
7
|
/*
|
|
10
8
|
// -- Contract javascript files built using build/BuildContracts.js
|
|
@@ -242,47 +240,6 @@ class AuthorizationClient {
|
|
|
242
240
|
return `${token}.${Utils.B64(multiSig)}`;
|
|
243
241
|
}
|
|
244
242
|
|
|
245
|
-
async GenerateSignedLinkToken({containerId, versionHash, link}) {
|
|
246
|
-
ValidateObject(containerId);
|
|
247
|
-
const canEdit = await this.client.CallContractMethod({
|
|
248
|
-
contractAddress: Utils.HashToAddress(containerId),
|
|
249
|
-
methodName: "canEdit"
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
const { objectId } = Utils.DecodeVersionHash(versionHash);
|
|
253
|
-
|
|
254
|
-
if(!canEdit) {
|
|
255
|
-
throw Error(`Current user does not have permission to edit content object ${objectId}`);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
const signerAddress = this.client.CurrentAccountAddress();
|
|
259
|
-
|
|
260
|
-
let token = {
|
|
261
|
-
adr: Utils.B64(signerAddress.replace("0x", ""), "hex"),
|
|
262
|
-
spc: await this.client.ContentSpaceId(),
|
|
263
|
-
lib: await this.client.ContentObjectLibraryId({objectId}),
|
|
264
|
-
qid: objectId,
|
|
265
|
-
sub: Utils.FormatAddress(signerAddress),
|
|
266
|
-
gra: "read",
|
|
267
|
-
iat: Date.now(),
|
|
268
|
-
exp: Date.now() + 3600000,
|
|
269
|
-
ctx: {
|
|
270
|
-
elv: {
|
|
271
|
-
lnk: link,
|
|
272
|
-
src: containerId
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
};
|
|
276
|
-
|
|
277
|
-
const compressedToken = Pako.deflateRaw(Buffer.from(JSON.stringify(token), "utf-8"));
|
|
278
|
-
const signature = await this.Sign(Ethers.utils.keccak256(compressedToken));
|
|
279
|
-
|
|
280
|
-
return `aslsjc${Utils.B58(Buffer.concat([
|
|
281
|
-
Buffer.from(signature.replace(/^0x/, ""), "hex"),
|
|
282
|
-
Buffer.from(compressedToken)
|
|
283
|
-
]))}`;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
243
|
async MakeAccessRequest({
|
|
287
244
|
libraryId,
|
|
288
245
|
objectId,
|
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
const UrlJoin = require("url-join");
|
|
8
8
|
const ImageType = require("image-type");
|
|
9
9
|
const Ethers = require("ethers");
|
|
10
|
+
const Pako = require("pako");
|
|
11
|
+
|
|
10
12
|
|
|
11
13
|
/*
|
|
12
14
|
const LibraryContract = require("../contracts/BaseLibrary");
|
|
@@ -670,16 +672,18 @@ exports.CopyContentObject = async function({libraryId, originalVersionHash, opti
|
|
|
670
672
|
await Promise.all(
|
|
671
673
|
Object.keys(metadata)
|
|
672
674
|
.filter(key => key.startsWith("eluv.caps.ikms"))
|
|
673
|
-
.map(async kmsCapKey =>
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
675
|
+
.map(async kmsCapKey =>
|
|
676
|
+
await this.DeleteMetadata({
|
|
677
|
+
libraryId,
|
|
678
|
+
objectId,
|
|
679
|
+
writeToken,
|
|
680
|
+
metadataSubtree: kmsCapKey
|
|
681
|
+
})
|
|
682
|
+
)
|
|
679
683
|
);
|
|
680
684
|
|
|
681
685
|
if(permission !== "owner") {
|
|
682
|
-
await this.
|
|
686
|
+
await this.CreateEncryptionConk({libraryId, objectId, writeToken, createKMSConk: true});
|
|
683
687
|
}
|
|
684
688
|
|
|
685
689
|
return await this.FinalizeContentObject({libraryId, objectId, writeToken});
|
|
@@ -1306,6 +1310,65 @@ exports.UpdateContentObjectGraph = async function({libraryId, objectId, versionH
|
|
|
1306
1310
|
}
|
|
1307
1311
|
};
|
|
1308
1312
|
|
|
1313
|
+
/**
|
|
1314
|
+
* Generate a signed link token.
|
|
1315
|
+
*
|
|
1316
|
+
* @methodGroup Links
|
|
1317
|
+
* @namedParams
|
|
1318
|
+
* @param {string=} containerId - ID of the container object
|
|
1319
|
+
* @param {string=} versionHash - Version hash of the object
|
|
1320
|
+
* @param {string=} link - Path
|
|
1321
|
+
* @param {string=} duration - How long the link should last in milliseconds
|
|
1322
|
+
*
|
|
1323
|
+
* @return {Promise<string>} - The state channel token
|
|
1324
|
+
*/
|
|
1325
|
+
exports.GenerateSignedLinkToken = async function({
|
|
1326
|
+
containerId,
|
|
1327
|
+
versionHash,
|
|
1328
|
+
link,
|
|
1329
|
+
duration
|
|
1330
|
+
}) {
|
|
1331
|
+
ValidateObject(containerId);
|
|
1332
|
+
const canEdit = await this.CallContractMethod({
|
|
1333
|
+
contractAddress: this.utils.HashToAddress(containerId),
|
|
1334
|
+
methodName: "canEdit"
|
|
1335
|
+
});
|
|
1336
|
+
|
|
1337
|
+
const { objectId } = this.utils.DecodeVersionHash(versionHash);
|
|
1338
|
+
|
|
1339
|
+
if(!canEdit) {
|
|
1340
|
+
throw Error(`Current user does not have permission to edit content object ${objectId}`);
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
const signerAddress = this.CurrentAccountAddress();
|
|
1344
|
+
|
|
1345
|
+
let token = {
|
|
1346
|
+
adr: this.utils.B64(signerAddress.replace("0x", ""), "hex"),
|
|
1347
|
+
spc: await this.ContentSpaceId(),
|
|
1348
|
+
lib: await this.ContentObjectLibraryId({objectId}),
|
|
1349
|
+
qid: objectId,
|
|
1350
|
+
sub: `iusr${this.utils.AddressToHash(signerAddress)}`,
|
|
1351
|
+
gra: "read",
|
|
1352
|
+
iat: Date.now(),
|
|
1353
|
+
exp: duration ? (Date.now() + duration) : "",
|
|
1354
|
+
ctx: {
|
|
1355
|
+
elv: {
|
|
1356
|
+
lnk: link,
|
|
1357
|
+
src: containerId
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
};
|
|
1361
|
+
|
|
1362
|
+
const compressedToken = Pako.deflateRaw(Buffer.from(JSON.stringify(token), "utf-8"));
|
|
1363
|
+
const signature = await this.authClient.Sign(Ethers.utils.keccak256(compressedToken));
|
|
1364
|
+
|
|
1365
|
+
return `aslsjc${this.utils.B58(Buffer.concat([
|
|
1366
|
+
Buffer.from(signature.replace(/^0x/, ""), "hex"),
|
|
1367
|
+
Buffer.from(compressedToken)
|
|
1368
|
+
]))}`;
|
|
1369
|
+
};
|
|
1370
|
+
|
|
1371
|
+
|
|
1309
1372
|
/**
|
|
1310
1373
|
* Create links to files, metadata and/or representations of this or or other
|
|
1311
1374
|
* content objects.
|
|
@@ -1381,7 +1444,7 @@ exports.CreateLinks = async function({
|
|
|
1381
1444
|
if(!link["."]) link["."] = {};
|
|
1382
1445
|
|
|
1383
1446
|
if(!linkMetadata["."]["authorization"]) {
|
|
1384
|
-
link["."]["authorization"] = await this.
|
|
1447
|
+
link["."]["authorization"] = await this.GenerateSignedLinkToken({
|
|
1385
1448
|
containerId: info.authContainer,
|
|
1386
1449
|
versionHash: info.targetHash,
|
|
1387
1450
|
link: `./${type}/${authTarget}`
|
|
@@ -755,7 +755,7 @@ class ElvWalletClient {
|
|
|
755
755
|
let marketplace = await this.client.ContentObjectMetadata({
|
|
756
756
|
versionHash: marketplaceHash,
|
|
757
757
|
metadataSubtree: "public/asset_metadata/info",
|
|
758
|
-
linkDepthLimit:
|
|
758
|
+
linkDepthLimit: 1,
|
|
759
759
|
resolveLinks: true,
|
|
760
760
|
resolveIgnoreErrors: true,
|
|
761
761
|
resolveIncludeSource: true,
|