@eluvio/elv-client-js 4.0.147 → 4.2.0
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 +2 -67
- package/dist/ElvClient-min.js.LICENSE.txt +72 -0
- package/dist/ElvClient-node-min.js +2 -66
- package/dist/ElvClient-node-min.js.LICENSE.txt +72 -0
- package/dist/ElvFrameClient-min.js +2 -60
- package/dist/ElvFrameClient-min.js.LICENSE.txt +72 -0
- package/dist/ElvPermissionsClient-min.js +2 -60
- package/dist/ElvPermissionsClient-min.js.LICENSE.txt +72 -0
- package/dist/ElvWalletClient-min.js +2 -67
- package/dist/ElvWalletClient-min.js.LICENSE.txt +72 -0
- package/dist/ElvWalletClient-node-min.js +2 -66
- package/dist/ElvWalletClient-node-min.js.LICENSE.txt +72 -0
- package/dist/src/AuthorizationClient.js +713 -715
- package/dist/src/ContentObjectAudit.js +59 -59
- package/dist/src/Crypto.js +85 -86
- package/dist/src/ElvClient.js +532 -501
- package/dist/src/ElvWallet.js +30 -28
- package/dist/src/EthClient.js +316 -316
- package/dist/src/FrameClient.js +70 -71
- package/dist/src/HttpClient.js +60 -60
- package/dist/src/Id.js +1 -2
- package/dist/src/PermissionsClient.js +501 -489
- package/dist/src/RemoteSigner.js +83 -84
- package/dist/src/UserProfileClient.js +392 -374
- package/dist/src/Utils.js +67 -67
- package/dist/src/Validation.js +20 -12
- package/dist/src/client/ABRPublishing.js +412 -356
- package/dist/src/client/AccessGroups.js +479 -476
- package/dist/src/client/ContentAccess.js +1750 -1804
- package/dist/src/client/ContentManagement.js +874 -874
- package/dist/src/client/Contracts.js +586 -590
- package/dist/src/client/Files.js +702 -686
- package/dist/src/client/LiveConf.js +3 -5
- package/dist/src/client/LiveStream.js +659 -652
- package/dist/src/client/NFT.js +16 -16
- package/dist/src/client/NTP.js +84 -84
- package/dist/src/client/Shares.js +51 -51
- package/dist/src/walletClient/ClientMethods.js +979 -953
- package/dist/src/walletClient/Notifications.js +14 -14
- package/dist/src/walletClient/Profile.js +68 -68
- package/dist/src/walletClient/Utils.js +17 -17
- package/dist/src/walletClient/index.js +574 -564
- package/package.json +17 -16
- package/src/client/AccessGroups.js +1 -1
- package/testScripts/Test.js +5 -1
- package/webpack.config.js +10 -13
- package/dist/src/ContentObjectVerification.js +0 -281
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eluvio/elv-client-js",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "Javascript client for the Eluvio Content Fabric",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"author": "Kevin Talmadge",
|
|
@@ -14,13 +14,13 @@
|
|
|
14
14
|
"build-wallet-client-docs": "./node_modules/.bin/jsdoc --configure ./.jsdoc-mc.json --readme ./src/walletClient/README.md",
|
|
15
15
|
"build-dist": "node ./node_modules/@babel/cli/bin/babel.js --source-type=unambiguous --presets=@babel/preset-env --plugins @babel/plugin-transform-runtime src --out-dir dist/src",
|
|
16
16
|
"build-contracts": "node build/BuildContracts.js",
|
|
17
|
-
"build-frame-client": "webpack
|
|
18
|
-
"build-permissions-client": "webpack
|
|
19
|
-
"build-wallet-client-web": "webpack
|
|
20
|
-
"build-wallet-client-node": "webpack
|
|
17
|
+
"build-frame-client": "webpack --mode=production --progress --entry ./dist/src/FrameClient.js --output-filename ElvFrameClient-min.js && mv test/bundle-analysis/index.html test/bundle-analysis/frame-client.html",
|
|
18
|
+
"build-permissions-client": "webpack --mode=production --progress --entry ./dist/src/PermissionsClient.js --output-filename ElvPermissionsClient-min.js && mv test/bundle-analysis/index.html test/bundle-analysis/permissions-client.html",
|
|
19
|
+
"build-wallet-client-web": "webpack --mode=production --progress --mode production --entry ./dist/src/walletClient/index.js --target web --output-filename ElvWalletClient-min.js && mv test/bundle-analysis/index.html test/bundle-analysis/wallet-client.html",
|
|
20
|
+
"build-wallet-client-node": "webpack --mode=production --progress --mode production --entry ./dist/src/walletClient/index.js --target node --output-filename ElvWalletClient-node-min.js && mv test/bundle-analysis/index.html test/bundle-analysis/wallet-client.html",
|
|
21
21
|
"build-prod": "npm run build-web && npm run build-node",
|
|
22
|
-
"build-web": "webpack --progress --mode production --target web --output-filename ElvClient-min.js
|
|
23
|
-
"build-node": "webpack --progress --mode production --target node --output-filename ElvClient-node-min.js
|
|
22
|
+
"build-web": "webpack --progress --mode production --target web --output-filename ElvClient-min.js && mv test/bundle-analysis/index.html test/bundle-analysis/web.html",
|
|
23
|
+
"build-node": "webpack --progress --mode production --target node --output-filename ElvClient-node-min.js && mv test/bundle-analysis/index.html test/bundle-analysis/node.html",
|
|
24
24
|
"build-dev": "npm run build-web-dev && npm run build-node-dev",
|
|
25
25
|
"build-web-dev": "webpack --progress --target web --output-filename ElvClient-min-dev.js",
|
|
26
26
|
"build-node-dev": "webpack --progress --target node --output-filename ElvClient-node-min-dev.js",
|
|
@@ -66,6 +66,7 @@
|
|
|
66
66
|
"columnify": "^1.5.4",
|
|
67
67
|
"country-codes-list": "^1.6.8",
|
|
68
68
|
"crocks": "^0.12.4",
|
|
69
|
+
"crypto-browserify": "^3.12.1",
|
|
69
70
|
"deep-equal": "^1.0.1",
|
|
70
71
|
"ellipsize": "^0.1.0",
|
|
71
72
|
"ethers": "^5.7.2",
|
|
@@ -90,7 +91,6 @@
|
|
|
90
91
|
"shell-escape": "^0.2.0",
|
|
91
92
|
"sjcl": "^1.0.8",
|
|
92
93
|
"typedarray": "0.0.6",
|
|
93
|
-
"unorm": "^1.5.0",
|
|
94
94
|
"urijs": "^1.19.10",
|
|
95
95
|
"url-join": "^4.0.0",
|
|
96
96
|
"uuid": "^8.3.2",
|
|
@@ -98,27 +98,28 @@
|
|
|
98
98
|
"yargs": "^16.2.0"
|
|
99
99
|
},
|
|
100
100
|
"devDependencies": {
|
|
101
|
-
"@babel/cli": "^7.
|
|
101
|
+
"@babel/cli": "^7.28.0",
|
|
102
102
|
"@babel/plugin-transform-runtime": "^7.8.3",
|
|
103
103
|
"@babel/preset-env": "^7.4.5",
|
|
104
|
+
"@jsdoc/salty": "^0.2.9",
|
|
104
105
|
"chai": "^4.2.0",
|
|
105
106
|
"chai-as-promised": "^7.1.1",
|
|
106
107
|
"chrono-node": "^2.3.1",
|
|
107
108
|
"colors": "^1.4.0",
|
|
108
109
|
"copy-webpack-plugin": "^6.0.2",
|
|
109
|
-
"eslint": "^
|
|
110
|
+
"eslint": "^9.32.0",
|
|
110
111
|
"eslint-plugin-html": "^5.0.0",
|
|
111
112
|
"jsdoc": "^4.0.0",
|
|
112
|
-
"
|
|
113
|
+
"jsdom": "^26.1.0",
|
|
113
114
|
"moment": "^2.27.0",
|
|
114
115
|
"raw-loader": "^0.5.1",
|
|
115
116
|
"shell-quote": "^1.7.2",
|
|
116
117
|
"showdown": "^1.9.1",
|
|
117
118
|
"simple-mock": "^0.8.0",
|
|
118
|
-
"
|
|
119
|
-
"
|
|
120
|
-
"webpack
|
|
121
|
-
"webpack-
|
|
122
|
-
"
|
|
119
|
+
"stream-browserify": "^3.0.0",
|
|
120
|
+
"vm-browserify": "^1.1.2",
|
|
121
|
+
"webpack": "^5.101.0",
|
|
122
|
+
"webpack-bundle-analyzer": "^4.10.2",
|
|
123
|
+
"webpack-cli": "^6.0.1"
|
|
123
124
|
}
|
|
124
125
|
}
|
package/testScripts/Test.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
const { ElvClient } = require("../src/
|
|
1
|
+
const { ElvClient } = require("../src/index");
|
|
2
2
|
const { ElvWalletClient } = require("../src/walletClient/index");
|
|
3
3
|
const ClientConfiguration = require("../TestConfiguration.json");
|
|
4
4
|
const fs = require("fs");
|
|
5
5
|
const HttpClient = require("../src/HttpClient");
|
|
6
|
+
//const NodeFetch = require("node-fetch");
|
|
6
7
|
|
|
7
8
|
const Test = async () => {
|
|
9
|
+
// For some reason, fetch isn't defined for ethers in the build node version, need to set this
|
|
10
|
+
//globalThis.fetch = NodeFetch;
|
|
11
|
+
|
|
8
12
|
try {
|
|
9
13
|
const client = await ElvClient.FromNetworkName({
|
|
10
14
|
networkName: "demo"
|
package/webpack.config.js
CHANGED
|
@@ -15,42 +15,39 @@ let plugins = [
|
|
|
15
15
|
new webpack.optimize.LimitChunkCountPlugin({
|
|
16
16
|
maxChunks: 1,
|
|
17
17
|
}),
|
|
18
|
-
new webpack.IgnorePlugin(/unorm/),
|
|
19
18
|
new BundleAnalyzerPlugin({
|
|
20
19
|
analyzerMode: "static",
|
|
21
20
|
reportFilename: path.resolve(path.join(__dirname, "test", "bundle-analysis", "index.html")),
|
|
22
21
|
openAnalyzer: false
|
|
23
|
-
})
|
|
22
|
+
}),
|
|
23
|
+
new webpack.IgnorePlugin({resourceRegExp: /window/})
|
|
24
24
|
];
|
|
25
25
|
|
|
26
|
-
plugins.push(new webpack.IgnorePlugin(/window/));
|
|
27
|
-
|
|
28
|
-
// Exclude node-fetch for web build
|
|
29
26
|
if(cmdOpts["target"] !== "node") {
|
|
30
|
-
plugins.push(new webpack.IgnorePlugin(
|
|
31
|
-
plugins.push(new webpack.IgnorePlugin(/@eluvio\/crypto\/dist\/elv-crypto.bundle.node/));
|
|
27
|
+
plugins.push(new webpack.IgnorePlugin({resourceRegExp: /@eluvio\/crypto\/dist\/elv-crypto.bundle.node/}));
|
|
32
28
|
} else {
|
|
33
|
-
plugins.push(new webpack.IgnorePlugin(/@eluvio\/crypto\/dist\/elv-crypto.bundle.js/));
|
|
29
|
+
plugins.push(new webpack.IgnorePlugin({resourceRegExp: /@eluvio\/crypto\/dist\/elv-crypto.bundle.js/}));
|
|
34
30
|
}
|
|
35
31
|
|
|
36
32
|
module.exports = {
|
|
37
|
-
entry: "./
|
|
33
|
+
entry: "./src/ElvClient.js",
|
|
38
34
|
output: {
|
|
39
35
|
path: path.resolve(__dirname, "dist"),
|
|
40
36
|
filename: "ElvClient-min-dev.js",
|
|
41
37
|
libraryTarget: "umd"
|
|
42
38
|
},
|
|
43
|
-
node: {
|
|
44
|
-
fs: "empty"
|
|
45
|
-
},
|
|
46
39
|
resolve: {
|
|
47
40
|
alias: {
|
|
48
41
|
// Force webpack to use *one* copy of bn.js instead of 8
|
|
49
42
|
"bn.js": path.resolve(path.join(__dirname, "node_modules", "bn.js"))
|
|
43
|
+
},
|
|
44
|
+
fallback: {
|
|
45
|
+
"crypto": require.resolve("crypto-browserify"),
|
|
46
|
+
"stream": require.resolve("stream-browserify"),
|
|
47
|
+
"vm": require.resolve("vm-browserify")
|
|
50
48
|
}
|
|
51
49
|
},
|
|
52
50
|
mode: "development",
|
|
53
|
-
devtool: cmdOpts["mode"] === "production" ? "" : "source-map",
|
|
54
51
|
plugins: plugins,
|
|
55
52
|
module: {
|
|
56
53
|
noParse: [
|
|
@@ -1,281 +0,0 @@
|
|
|
1
|
-
var _regeneratorRuntime = require("@babel/runtime/regenerator");
|
|
2
|
-
var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator");
|
|
3
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
4
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
5
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
6
|
-
var CBOR = require("cbor");
|
|
7
|
-
var SJCL = require("sjcl");
|
|
8
|
-
var MultiHash = require("multihashes");
|
|
9
|
-
var DeepEqual = require("deep-equal");
|
|
10
|
-
var Utils = require("./Utils");
|
|
11
|
-
var ContentObjectVerification = {
|
|
12
|
-
VerifyContentObject: function VerifyContentObject(_ref) {
|
|
13
|
-
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
14
|
-
var client, libraryId, objectId, versionHash, response, partHash, qpartsResponse, partVerification, qmdHash, metadataPartHash, metadataPartResponse, metadataVerification, metadata, qstructHash, structPartHash, structPartResponse, structVerification;
|
|
15
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
16
|
-
while (1) switch (_context.prev = _context.next) {
|
|
17
|
-
case 0:
|
|
18
|
-
client = _ref.client, libraryId = _ref.libraryId, objectId = _ref.objectId, versionHash = _ref.versionHash;
|
|
19
|
-
response = {
|
|
20
|
-
hash: versionHash
|
|
21
|
-
};
|
|
22
|
-
partHash = Utils.DecodeVersionHash(versionHash).partHash;
|
|
23
|
-
_context.next = 5;
|
|
24
|
-
return client.QParts({
|
|
25
|
-
libraryId: libraryId,
|
|
26
|
-
objectId: objectId,
|
|
27
|
-
partHash: partHash,
|
|
28
|
-
format: "arrayBuffer"
|
|
29
|
-
}).then(function (response) {
|
|
30
|
-
return Buffer.from(response);
|
|
31
|
-
});
|
|
32
|
-
case 5:
|
|
33
|
-
qpartsResponse = _context.sent;
|
|
34
|
-
partVerification = ContentObjectVerification._VerifyPart({
|
|
35
|
-
partHash: partHash,
|
|
36
|
-
qpartsResponse: qpartsResponse
|
|
37
|
-
});
|
|
38
|
-
if (partVerification.valid) {
|
|
39
|
-
response.qref = {
|
|
40
|
-
valid: true
|
|
41
|
-
};
|
|
42
|
-
} else {
|
|
43
|
-
response.qref = {
|
|
44
|
-
valid: false,
|
|
45
|
-
error: partVerification.error.message
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
response.qref.hash = partHash;
|
|
49
|
-
if (!response.qref.valid) {
|
|
50
|
-
_context.next = 32;
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
// Validate Metadata
|
|
54
|
-
qmdHash = partVerification.cbor.QmdHash.value;
|
|
55
|
-
metadataPartHash = "hqp_" + MultiHash.toB58String(qmdHash.slice(1, qmdHash.length));
|
|
56
|
-
_context.next = 14;
|
|
57
|
-
return client.QParts({
|
|
58
|
-
libraryId: libraryId,
|
|
59
|
-
objectId: objectId,
|
|
60
|
-
partHash: metadataPartHash,
|
|
61
|
-
format: "arrayBuffer"
|
|
62
|
-
}).then(function (response) {
|
|
63
|
-
return Buffer.from(response);
|
|
64
|
-
});
|
|
65
|
-
case 14:
|
|
66
|
-
metadataPartResponse = _context.sent;
|
|
67
|
-
metadataVerification = ContentObjectVerification._VerifyPart({
|
|
68
|
-
partHash: metadataPartHash,
|
|
69
|
-
qpartsResponse: metadataPartResponse
|
|
70
|
-
});
|
|
71
|
-
if (metadataVerification.valid) {
|
|
72
|
-
response.qmd = {
|
|
73
|
-
valid: true
|
|
74
|
-
};
|
|
75
|
-
} else {
|
|
76
|
-
response.qmd = {
|
|
77
|
-
valid: false,
|
|
78
|
-
error: metadataVerification.error.message
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
response.qmd.hash = metadataPartHash;
|
|
82
|
-
if (!(response.qmd.valid && libraryId)) {
|
|
83
|
-
_context.next = 23;
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
_context.next = 21;
|
|
87
|
-
return client.ContentObjectMetadata({
|
|
88
|
-
libraryId: libraryId,
|
|
89
|
-
objectId: objectId,
|
|
90
|
-
versionHash: partHash.replace("hqp_", "hq__")
|
|
91
|
-
});
|
|
92
|
-
case 21:
|
|
93
|
-
metadata = _context.sent;
|
|
94
|
-
response.qmd.check = ContentObjectVerification._VerifyMetadata({
|
|
95
|
-
metadataCbor: metadataVerification.cbor,
|
|
96
|
-
metadata: metadata
|
|
97
|
-
});
|
|
98
|
-
case 23:
|
|
99
|
-
// Validate Qstruct
|
|
100
|
-
qstructHash = partVerification.cbor.QstructHash.value;
|
|
101
|
-
structPartHash = "hqp_" + MultiHash.toB58String(qstructHash.slice(1, qstructHash.length));
|
|
102
|
-
_context.next = 27;
|
|
103
|
-
return client.QParts({
|
|
104
|
-
libraryId: libraryId,
|
|
105
|
-
objectId: objectId,
|
|
106
|
-
partHash: structPartHash,
|
|
107
|
-
format: "arrayBuffer"
|
|
108
|
-
}).then(function (response) {
|
|
109
|
-
return Buffer.from(response);
|
|
110
|
-
});
|
|
111
|
-
case 27:
|
|
112
|
-
structPartResponse = _context.sent;
|
|
113
|
-
structVerification = ContentObjectVerification._VerifyPart({
|
|
114
|
-
partHash: structPartHash,
|
|
115
|
-
qpartsResponse: structPartResponse
|
|
116
|
-
});
|
|
117
|
-
if (structVerification.valid) {
|
|
118
|
-
response.qstruct = {
|
|
119
|
-
valid: true
|
|
120
|
-
};
|
|
121
|
-
} else {
|
|
122
|
-
response.qstruct = {
|
|
123
|
-
valid: false,
|
|
124
|
-
error: structVerification.error.message
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
response.qstruct.hash = structPartHash;
|
|
128
|
-
if (response.qstruct.valid) {
|
|
129
|
-
response.qstruct.parts = ContentObjectVerification._FormatQStruct(structVerification.cbor.Parts);
|
|
130
|
-
}
|
|
131
|
-
case 32:
|
|
132
|
-
response.valid = response.qref.valid && response.qmd.valid && response.qstruct.valid && (!response.qmd.check || response.qmd.check.valid);
|
|
133
|
-
return _context.abrupt("return", response);
|
|
134
|
-
case 34:
|
|
135
|
-
case "end":
|
|
136
|
-
return _context.stop();
|
|
137
|
-
}
|
|
138
|
-
}, _callee);
|
|
139
|
-
}))();
|
|
140
|
-
},
|
|
141
|
-
// Content verification methods //
|
|
142
|
-
_FormatQStruct: function _FormatQStruct(structParts) {
|
|
143
|
-
if (!structParts) {
|
|
144
|
-
return [];
|
|
145
|
-
}
|
|
146
|
-
return structParts.map(function (structPart) {
|
|
147
|
-
return {
|
|
148
|
-
hash: "hqp_" + MultiHash.toB58String(structPart.Hash.value.slice(1, structPart.Hash.length)),
|
|
149
|
-
size: structPart.Size
|
|
150
|
-
};
|
|
151
|
-
});
|
|
152
|
-
},
|
|
153
|
-
_Hash: function _Hash(thing) {
|
|
154
|
-
function fromBits(arr) {
|
|
155
|
-
var out = [],
|
|
156
|
-
bl = SJCL.bitArray.bitLength(arr),
|
|
157
|
-
i,
|
|
158
|
-
tmp;
|
|
159
|
-
for (i = 0; i < bl / 8; i++) {
|
|
160
|
-
if ((i & 3) === 0) {
|
|
161
|
-
tmp = arr[i / 4];
|
|
162
|
-
}
|
|
163
|
-
out.push(tmp >>> 24);
|
|
164
|
-
tmp <<= 8;
|
|
165
|
-
}
|
|
166
|
-
return out;
|
|
167
|
-
}
|
|
168
|
-
function toBits(bytes) {
|
|
169
|
-
var out = [],
|
|
170
|
-
i,
|
|
171
|
-
tmp = 0;
|
|
172
|
-
for (i = 0; i < bytes.length; i++) {
|
|
173
|
-
tmp = tmp << 8 | bytes[i];
|
|
174
|
-
if ((i & 3) === 3) {
|
|
175
|
-
out.push(tmp);
|
|
176
|
-
tmp = 0;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
if (i & 3) {
|
|
180
|
-
out.push(SJCL.bitArray.partial(8 * (i & 3), tmp));
|
|
181
|
-
}
|
|
182
|
-
return out;
|
|
183
|
-
}
|
|
184
|
-
var digest = SJCL.hash.sha256.hash(toBits(thing));
|
|
185
|
-
var bytes = fromBits(digest);
|
|
186
|
-
var out = Buffer.from(bytes, "binary");
|
|
187
|
-
return MultiHash.toB58String(MultiHash.encode(out, "sha2-256"));
|
|
188
|
-
},
|
|
189
|
-
_ParseCBOR: function _ParseCBOR(cborResponse) {
|
|
190
|
-
var buffer = cborResponse.slice(7, cborResponse.length);
|
|
191
|
-
var hex = buffer.toString("hex");
|
|
192
|
-
return CBOR.decodeFirstSync(hex);
|
|
193
|
-
},
|
|
194
|
-
_VerifyPart: function _VerifyPart(_ref2) {
|
|
195
|
-
var partHash = _ref2.partHash,
|
|
196
|
-
qpartsResponse = _ref2.qpartsResponse;
|
|
197
|
-
try {
|
|
198
|
-
if (ContentObjectVerification._Hash(qpartsResponse) !== partHash.replace("hqp_", "")) {
|
|
199
|
-
throw Error("Hashes do not match");
|
|
200
|
-
}
|
|
201
|
-
var cbor = ContentObjectVerification._ParseCBOR(qpartsResponse);
|
|
202
|
-
return {
|
|
203
|
-
valid: true,
|
|
204
|
-
cbor: cbor
|
|
205
|
-
};
|
|
206
|
-
} catch (error) {
|
|
207
|
-
return {
|
|
208
|
-
valid: false,
|
|
209
|
-
error: error
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
},
|
|
213
|
-
_VerifyMetadata: function _VerifyMetadata(_ref3) {
|
|
214
|
-
var metadataCbor = _ref3.metadataCbor,
|
|
215
|
-
metadata = _ref3.metadata;
|
|
216
|
-
if (!metadataCbor) {
|
|
217
|
-
metadataCbor = {};
|
|
218
|
-
}
|
|
219
|
-
if (!metadata) {
|
|
220
|
-
metadata = {};
|
|
221
|
-
}
|
|
222
|
-
var response = {
|
|
223
|
-
valid: true,
|
|
224
|
-
invalidValues: []
|
|
225
|
-
};
|
|
226
|
-
var cborKeys = Object.keys(metadataCbor);
|
|
227
|
-
var metadataKeys = Object.keys(metadata);
|
|
228
|
-
|
|
229
|
-
// Find any difference between top level keys
|
|
230
|
-
var differentKeys = cborKeys.filter(function (x) {
|
|
231
|
-
return !metadataKeys.includes(x);
|
|
232
|
-
}).concat(metadataKeys.filter(function (x) {
|
|
233
|
-
return !cborKeys.includes(x);
|
|
234
|
-
}));
|
|
235
|
-
var _iterator = _createForOfIteratorHelper(differentKeys),
|
|
236
|
-
_step;
|
|
237
|
-
try {
|
|
238
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
239
|
-
var key = _step.value;
|
|
240
|
-
var cborValue = metadataCbor[key];
|
|
241
|
-
var metadataValue = metadata[key];
|
|
242
|
-
response.invalidValues.push({
|
|
243
|
-
key: key,
|
|
244
|
-
cborValue: cborValue,
|
|
245
|
-
metadataValue: metadataValue
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
// Deep comparison of up to 5 keys
|
|
250
|
-
} catch (err) {
|
|
251
|
-
_iterator.e(err);
|
|
252
|
-
} finally {
|
|
253
|
-
_iterator.f();
|
|
254
|
-
}
|
|
255
|
-
var _iterator2 = _createForOfIteratorHelper(Object.keys(metadataCbor).slice(0, 5)),
|
|
256
|
-
_step2;
|
|
257
|
-
try {
|
|
258
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
259
|
-
var fieldToValidate = _step2.value;
|
|
260
|
-
var _cborValue = metadataCbor[fieldToValidate];
|
|
261
|
-
var _metadataValue = metadata[fieldToValidate];
|
|
262
|
-
if (!DeepEqual(_cborValue, _metadataValue)) {
|
|
263
|
-
response.invalidValues.push({
|
|
264
|
-
key: fieldToValidate,
|
|
265
|
-
cborValue: _cborValue,
|
|
266
|
-
metadataValue: _metadataValue
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
} catch (err) {
|
|
271
|
-
_iterator2.e(err);
|
|
272
|
-
} finally {
|
|
273
|
-
_iterator2.f();
|
|
274
|
-
}
|
|
275
|
-
if (response.invalidValues.length !== 0) {
|
|
276
|
-
response.valid = false;
|
|
277
|
-
}
|
|
278
|
-
return response;
|
|
279
|
-
}
|
|
280
|
-
};
|
|
281
|
-
module.exports = ContentObjectVerification;
|