@eluvio/elv-client-js 4.0.114 → 4.0.116

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.
Files changed (129) hide show
  1. package/dist/ElvClient-min.js +68 -0
  2. package/dist/ElvClient-node-min.js +67 -0
  3. package/dist/ElvFrameClient-min.js +60 -0
  4. package/dist/ElvPermissionsClient-min.js +60 -0
  5. package/dist/ElvWalletClient-min.js +68 -0
  6. package/dist/ElvWalletClient-node-min.js +67 -0
  7. package/dist/src/AuthorizationClient.js +2166 -0
  8. package/dist/src/ContentObjectAudit.js +175 -0
  9. package/dist/src/ContentObjectVerification.js +281 -0
  10. package/dist/src/Crypto.js +412 -0
  11. package/dist/src/ElvClient.js +2063 -0
  12. package/dist/src/ElvWallet.js +247 -0
  13. package/dist/src/EthClient.js +1153 -0
  14. package/dist/src/FrameClient.js +484 -0
  15. package/dist/src/HttpClient.js +314 -0
  16. package/dist/src/Id.js +20 -0
  17. package/dist/src/LogMessage.js +25 -0
  18. package/dist/src/PermissionsClient.js +1556 -0
  19. package/dist/src/RemoteSigner.js +383 -0
  20. package/dist/src/UserProfileClient.js +1465 -0
  21. package/dist/src/Utils.js +893 -0
  22. package/dist/src/Validation.js +121 -0
  23. package/dist/src/abr_profiles/abr_profile_live_drm.js +1661 -0
  24. package/dist/src/abr_profiles/abr_profile_live_to_vod.js +1606 -0
  25. package/dist/src/client/ABRPublishing.js +1018 -0
  26. package/dist/src/client/AccessGroups.js +1503 -0
  27. package/dist/src/client/ContentAccess.js +5202 -0
  28. package/dist/src/client/ContentManagement.js +2680 -0
  29. package/dist/src/client/Contracts.js +1520 -0
  30. package/dist/src/client/Files.js +2181 -0
  31. package/dist/src/client/LiveConf.js +567 -0
  32. package/dist/src/client/LiveStream.js +2638 -0
  33. package/dist/src/client/NFT.js +162 -0
  34. package/dist/src/client/NTP.js +581 -0
  35. package/dist/src/contracts/v2/AccessIndexor.js +831 -0
  36. package/dist/src/contracts/v2/Accessible.js +31 -0
  37. package/dist/src/contracts/v2/BaseAccessControlGroup.js +1263 -0
  38. package/dist/src/contracts/v2/BaseAccessWallet.js +1609 -0
  39. package/dist/src/contracts/v2/BaseAccessWalletFactory.js +93 -0
  40. package/dist/src/contracts/v2/BaseContent.js +1076 -0
  41. package/dist/src/contracts/v2/BaseContentFactory.js +219 -0
  42. package/dist/src/contracts/v2/BaseContentSpace.js +1352 -0
  43. package/dist/src/contracts/v2/BaseContentType.js +364 -0
  44. package/dist/src/contracts/v2/BaseFactory.js +107 -0
  45. package/dist/src/contracts/v2/BaseGroupFactory.js +93 -0
  46. package/dist/src/contracts/v2/BaseLibrary.js +1041 -0
  47. package/dist/src/contracts/v2/BaseLibraryFactory.js +96 -0
  48. package/dist/src/contracts/v2/Certifyer.js +86 -0
  49. package/dist/src/contracts/v2/Container.js +540 -0
  50. package/dist/src/contracts/v2/Content.js +443 -0
  51. package/dist/src/contracts/v2/Editable.js +306 -0
  52. package/dist/src/contracts/v2/ExternalUserWallet.js +379 -0
  53. package/dist/src/contracts/v2/IFactorySpace.js +57 -0
  54. package/dist/src/contracts/v2/IKmsSpace.js +52 -0
  55. package/dist/src/contracts/v2/INodeSpace.js +18 -0
  56. package/dist/src/contracts/v2/IUserSpace.js +18 -0
  57. package/dist/src/contracts/v2/LvRecordableStream.js +1037 -0
  58. package/dist/src/contracts/v2/LvRecording.js +627 -0
  59. package/dist/src/contracts/v2/LvStreamRightsHolder.js +562 -0
  60. package/dist/src/contracts/v2/MetaObject.js +119 -0
  61. package/dist/src/contracts/v2/Node.js +167 -0
  62. package/dist/src/contracts/v2/NodeSpace.js +273 -0
  63. package/dist/src/contracts/v2/Ownable.js +87 -0
  64. package/dist/src/contracts/v2/PaymentService.js +627 -0
  65. package/dist/src/contracts/v2/Precompile.js +15 -0
  66. package/dist/src/contracts/v2/Transactable.js +82 -0
  67. package/dist/src/contracts/v2/UserSpace.js +29 -0
  68. package/dist/src/contracts/v2/Utils.js +18 -0
  69. package/dist/src/contracts/v2/Verifier.js +53 -0
  70. package/dist/src/contracts/v2/strings.js +4 -0
  71. package/dist/src/contracts/v3/AccessIndexor.js +774 -0
  72. package/dist/src/contracts/v3/Accessible.js +232 -0
  73. package/dist/src/contracts/v3/Adminable.js +107 -0
  74. package/dist/src/contracts/v3/AvailsDelivery.js +586 -0
  75. package/dist/src/contracts/v3/BaseAccessControlGroup.js +1603 -0
  76. package/dist/src/contracts/v3/BaseAccessWallet.js +1628 -0
  77. package/dist/src/contracts/v3/BaseAccessWalletFactory.js +112 -0
  78. package/dist/src/contracts/v3/BaseContent.js +1312 -0
  79. package/dist/src/contracts/v3/BaseContentFactory.js +183 -0
  80. package/dist/src/contracts/v3/BaseContentFactoryExt.js +175 -0
  81. package/dist/src/contracts/v3/BaseContentSpace.js +1515 -0
  82. package/dist/src/contracts/v3/BaseContentType.js +527 -0
  83. package/dist/src/contracts/v3/BaseFactory.js +126 -0
  84. package/dist/src/contracts/v3/BaseGroupFactory.js +112 -0
  85. package/dist/src/contracts/v3/BaseLibrary.js +1204 -0
  86. package/dist/src/contracts/v3/BaseLibraryFactory.js +115 -0
  87. package/dist/src/contracts/v3/BaseTenantSpace.js +1587 -0
  88. package/dist/src/contracts/v3/Certifyer.js +86 -0
  89. package/dist/src/contracts/v3/Container.js +739 -0
  90. package/dist/src/contracts/v3/Content.js +438 -0
  91. package/dist/src/contracts/v3/CounterObject.js +243 -0
  92. package/dist/src/contracts/v3/Editable.js +519 -0
  93. package/dist/src/contracts/v3/EncToken.js +4 -0
  94. package/dist/src/contracts/v3/ExternalUserWallet.js +587 -0
  95. package/dist/src/contracts/v3/IAdmin.js +18 -0
  96. package/dist/src/contracts/v3/IFactorySpace.js +57 -0
  97. package/dist/src/contracts/v3/IKmsSpace.js +52 -0
  98. package/dist/src/contracts/v3/INodeSpace.js +18 -0
  99. package/dist/src/contracts/v3/IUserSpace.js +32 -0
  100. package/dist/src/contracts/v3/LvRecordableStream.js +1032 -0
  101. package/dist/src/contracts/v3/LvRecording.js +650 -0
  102. package/dist/src/contracts/v3/LvStreamRightsHolder.js +557 -0
  103. package/dist/src/contracts/v3/MetaObject.js +144 -0
  104. package/dist/src/contracts/v3/Node.js +178 -0
  105. package/dist/src/contracts/v3/NodeSpace.js +284 -0
  106. package/dist/src/contracts/v3/Ownable.js +98 -0
  107. package/dist/src/contracts/v3/PaymentService.js +622 -0
  108. package/dist/src/contracts/v3/Precompile.js +26 -0
  109. package/dist/src/contracts/v3/TenantFuncsBase.js +351 -0
  110. package/dist/src/contracts/v3/Transactable.js +82 -0
  111. package/dist/src/contracts/v3/UserSpace.js +43 -0
  112. package/dist/src/contracts/v3/Utils.js +18 -0
  113. package/dist/src/contracts/v3/Verifier.js +53 -0
  114. package/dist/src/contracts/v3/strings.js +4 -0
  115. package/dist/src/contracts/v3b/BaseAccessControlGroup.js +1704 -0
  116. package/dist/src/events/Topics.js +1793 -0
  117. package/dist/src/index.js +8 -0
  118. package/dist/src/walletClient/ClientMethods.js +3102 -0
  119. package/dist/src/walletClient/Configuration.js +38 -0
  120. package/dist/src/walletClient/Notifications.js +168 -0
  121. package/dist/src/walletClient/Profile.js +332 -0
  122. package/dist/src/walletClient/Utils.js +281 -0
  123. package/dist/src/walletClient/index.js +2109 -0
  124. package/package.json +1 -1
  125. package/src/AuthorizationClient.js +24 -16
  126. package/src/ElvClient.js +19 -0
  127. package/src/client/ContentAccess.js +20 -2
  128. package/src/client/LiveConf.js +10 -8
  129. package/src/client/LiveStream.js +6 -4
@@ -0,0 +1,893 @@
1
+ var _toConsumableArray = require("@babel/runtime/helpers/toConsumableArray");
2
+ var _regeneratorRuntime = require("@babel/runtime/regenerator");
3
+ var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator");
4
+ var _defineProperty = require("@babel/runtime/helpers/defineProperty");
5
+ var _slicedToArray = require("@babel/runtime/helpers/slicedToArray");
6
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
7
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
8
+ if (typeof globalThis.Buffer === "undefined") {
9
+ globalThis.Buffer = require("buffer/").Buffer;
10
+ }
11
+ var bs58 = require("bs58");
12
+ var BigNumber = require("bignumber.js")["default"];
13
+ var VarInt = require("varint");
14
+ var URI = require("urijs");
15
+ var Pako = require("pako");
16
+ var _require$utils = require("ethers").utils,
17
+ keccak256 = _require$utils.keccak256,
18
+ getAddress = _require$utils.getAddress;
19
+
20
+ /**
21
+ * @namespace
22
+ * @description This is a utility namespace mostly containing functions for managing
23
+ * multiformat type conversions.
24
+ *
25
+ * Utils can be imported separately from the client:
26
+ *
27
+ * `const Utils = require("@eluvio/elv-client-js/src/Utils)`
28
+ *
29
+ * or
30
+ *
31
+ * `import Utils from "@eluvio/elv-client-js/src/Utils"`
32
+ *
33
+ *
34
+ * It can be accessed from ElvClient and FrameClient as `client.utils`
35
+ */
36
+ var Utils = {
37
+ name: "Utils",
38
+ nullAddress: "0x0000000000000000000000000000000000000000",
39
+ weiPerEther: new BigNumber("1000000000000000000"),
40
+ /**
41
+ * Convert number or string to BigNumber
42
+ *
43
+ * @param {string | number} value - Value to convert to BigNumber
44
+ *
45
+ * @see https://github.com/MikeMcl/bignumber.js
46
+ *
47
+ * @returns {BigNumber} - Given value as a BigNumber
48
+ */
49
+ ToBigNumber: function ToBigNumber(value) {
50
+ return new BigNumber(value);
51
+ },
52
+ /**
53
+ * Convert wei to ether
54
+ *
55
+ * @param {string | BigNumber} wei - Wei value to convert to ether
56
+ *
57
+ * @see https://github.com/MikeMcl/bignumber.js
58
+ *
59
+ * @returns {BigNumber} - Given value in ether
60
+ */
61
+ WeiToEther: function WeiToEther(wei) {
62
+ return Utils.ToBigNumber(wei).div(Utils.weiPerEther);
63
+ },
64
+ /**
65
+ * Convert ether to wei
66
+ *
67
+ * @param {number | string | BigNumber} ether - Ether value to convert to wei
68
+ *
69
+ * @see https://github.com/indutny/bn.js/
70
+ *
71
+ * @returns {BigNumber} - Given value in wei
72
+ */
73
+ EtherToWei: function EtherToWei(ether) {
74
+ return Utils.ToBigNumber(ether).times(Utils.weiPerEther);
75
+ },
76
+ /**
77
+ * Convert address to normalized form - lower case with "0x" prefix
78
+ *
79
+ * @param {string} address - Address to format
80
+ *
81
+ * @returns {string} - Formatted address
82
+ */
83
+ FormatAddress: function FormatAddress(address) {
84
+ if (!address || typeof address !== "string") {
85
+ return "";
86
+ }
87
+ address = address.trim();
88
+ if (!address.startsWith("0x")) {
89
+ address = "0x" + address;
90
+ }
91
+ return address.toLowerCase();
92
+ },
93
+ /**
94
+ * Formats a signature into multi-sig
95
+ *
96
+ * @param {string} sig - Hex representation of signature
97
+ *
98
+ * @returns {string} - Multi-sig string representation of signature
99
+ */
100
+ FormatSignature: function FormatSignature(sig) {
101
+ sig = sig.replace("0x", "");
102
+ return "ES256K_" + bs58.encode(Buffer.from(sig, "hex"));
103
+ },
104
+ /**
105
+ * Decode the specified version hash into its component parts
106
+ *
107
+ * @param versionHash
108
+ *
109
+ * @returns {Object} - Components of the version hash.
110
+ */
111
+ DecodeVersionHash: function DecodeVersionHash(versionHash) {
112
+ if (!(versionHash.startsWith("hq__") || versionHash.startsWith("tq__"))) {
113
+ throw new Error("Invalid version hash: \"".concat(versionHash, "\""));
114
+ }
115
+ versionHash = versionHash.slice(4);
116
+
117
+ // Decode base58 payload
118
+ var bytes = Utils.FromB58(versionHash);
119
+
120
+ // Remove 32 byte SHA256 digest
121
+ var digestBytes = bytes.slice(0, 32);
122
+ var digest = digestBytes.toString("hex");
123
+ bytes = bytes.slice(32);
124
+
125
+ // Determine size of varint content size
126
+ var sizeLength = 0;
127
+ while (bytes[sizeLength] >= 128) {
128
+ sizeLength++;
129
+ }
130
+ sizeLength++;
131
+
132
+ // Remove size
133
+ var sizeBytes = bytes.slice(0, sizeLength);
134
+ var size = VarInt.decode(sizeBytes);
135
+ bytes = bytes.slice(sizeLength);
136
+
137
+ // Remaining bytes is object ID
138
+ var objectId = "iq__" + Utils.B58(bytes);
139
+
140
+ // Part hash is B58 encoded version hash without the ID
141
+ var partHash = "hqp_" + Utils.B58(Buffer.concat([digestBytes, sizeBytes]));
142
+ return {
143
+ digest: digest,
144
+ size: size,
145
+ objectId: objectId,
146
+ partHash: partHash
147
+ };
148
+ },
149
+ /**
150
+ * Decode the specified signed token into its component parts
151
+ *
152
+ * @param {string} token - The token to decode
153
+ *
154
+ * @return {Object} - Components of the signed token
155
+ */
156
+ DecodeSignedToken: function DecodeSignedToken(token) {
157
+ var decodedToken = Utils.FromB58(token.slice(6));
158
+ var signature = "0x".concat(decodedToken.slice(0, 65).toString("hex"));
159
+ var payload = JSON.parse(Buffer.from(Pako.inflateRaw(decodedToken.slice(65))).toString("utf-8"));
160
+ payload.adr = Utils.FormatAddress("0x".concat(Buffer.from(payload.adr, "base64").toString("hex")));
161
+ return {
162
+ payload: payload,
163
+ signature: signature
164
+ };
165
+ },
166
+ /**
167
+ * Decode the specified write token into its component parts
168
+ *
169
+ * @param writeToken
170
+ *
171
+ * @returns {Object} - Components of the write token.
172
+ */
173
+ DecodeWriteToken: function DecodeWriteToken(writeToken) {
174
+ /*
175
+ Format:
176
+ - content write token, LRO:
177
+ - prefix: "tq__", "tqw__", "tlro"
178
+ - format:
179
+ prefix + base58(uvarint(len(QID) | QID |
180
+ uvarint(len(NID) | NID |
181
+ uvarint(len(RAND_BYTES) | RAND_BYTES)
182
+ - content part write token:
183
+ - prefix: "tqp_"
184
+ - format:
185
+ prefix + base58(scheme | flags | uvarint(len(RAND_BYTES) | RAND_BYTES)
186
+ - content write token v1, content part write token v1:
187
+ - prefix: "tqw_", "tqpw"
188
+ - format:
189
+ prefix + base58(RAND_BYTES)
190
+ */
191
+
192
+ if (writeToken.length < 4) {
193
+ throw new Error("Invalid write token: [\"".concat(writeToken, "\"] (unknown prefix)"));
194
+ }
195
+ var tokenType;
196
+ if (writeToken.startsWith("tqw__")) {
197
+ tokenType = "tq__";
198
+ writeToken = writeToken.slice(5);
199
+ } else {
200
+ tokenType = writeToken.slice(0, 4);
201
+ writeToken = writeToken.slice(4);
202
+ }
203
+ if (writeToken.length === 0) {
204
+ throw new Error("Invalid write token: [\"".concat(writeToken, "\"] (too short)"));
205
+ }
206
+ switch (tokenType) {
207
+ case "tqw_":
208
+ case "tq__":
209
+ case "tqpw":
210
+ case "tqp_":
211
+ case "tlro":
212
+ break;
213
+ default:
214
+ throw new Error("Invalid write token: [\"".concat(writeToken, "\"] (unknown prefix)"));
215
+ }
216
+
217
+ // decode base58 payload
218
+ var bytes = Utils.FromB58(writeToken);
219
+ function decodeBytes(isID, prefix) {
220
+ var bsize = VarInt.decode(bytes, 0); // decode: count of bytes to read
221
+ var offset = VarInt.decode.bytes; // offset in buffer to start read after decode
222
+ var theBytes;
223
+ var ret;
224
+ if (isID) {
225
+ theBytes = bytes.slice(offset + 1, bsize + offset); // skip 1st byte (code id) at offset 0
226
+ if (theBytes.length === 0) {
227
+ ret = "";
228
+ } else {
229
+ ret = prefix + Utils.B58(theBytes);
230
+ }
231
+ } else {
232
+ theBytes = bytes.slice(offset, bsize + offset);
233
+ ret = "0x" + theBytes.toString("hex");
234
+ }
235
+ bytes = bytes.slice(bsize + offset);
236
+ return ret;
237
+ }
238
+ var tokenId;
239
+ var qid;
240
+ var nid;
241
+ var scheme;
242
+ var flags;
243
+ switch (tokenType) {
244
+ case "tqw_": // content write token v1
245
+ case "tqpw":
246
+ // content part write token v1
247
+ tokenId = "0x" + bytes.toString("hex");
248
+ break;
249
+ case "tlro": // LRO,
250
+ case "tq__":
251
+ // content write token
252
+ qid = decodeBytes(true, "iq__");
253
+ nid = decodeBytes(true, "inod");
254
+ tokenId = decodeBytes(false, "");
255
+ break;
256
+ case "tqp_":
257
+ // content part write token
258
+ if (bytes.length < 3) {
259
+ throw new Error("Invalid write token: [\"".concat(writeToken, "\"] (token truncated)"));
260
+ }
261
+ scheme = bytes[0];
262
+ flags = bytes[1];
263
+ bytes = bytes.slice(2);
264
+ tokenId = decodeBytes(false, "");
265
+ break;
266
+ default:
267
+ // already raised
268
+ throw new Error("Invalid write token: [\"".concat(writeToken, "\"] (unknown prefix)"));
269
+ }
270
+ return {
271
+ tokenType: tokenType,
272
+ // type of token
273
+ tokenId: tokenId,
274
+ // random bytes generated by the fabric node
275
+ objectId: qid,
276
+ // content id for content write token (tq__) or LRO (tlro)
277
+ nodeId: nid,
278
+ // node id where the content write token is valid (tq__)
279
+ scheme: scheme,
280
+ // encryption scheme for part write token - (tqp_)
281
+ flags: flags // flags for part write token (tqp_)
282
+ };
283
+ },
284
+ /**
285
+ * Convert contract address to multiformat hash
286
+ *
287
+ * @param {string} address - Address of contract
288
+ * @param {boolean} key - Whether or not the first param is a public key. Defaults to address type
289
+ *
290
+ * @returns {string} - Hash of contract address
291
+ */
292
+ AddressToHash: function AddressToHash(address) {
293
+ var key = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
294
+ address = address.replace(key ? "0x04" : "0x", "");
295
+ return bs58.encode(Buffer.from(address, "hex"));
296
+ },
297
+ /**
298
+ * Convert contract address to content space ID
299
+ *
300
+ * @param {string} address - Address of contract
301
+ *
302
+ * @returns {string} - Content space ID from contract address
303
+ */
304
+ AddressToSpaceId: function AddressToSpaceId(address) {
305
+ return "ispc" + Utils.AddressToHash(address);
306
+ },
307
+ /**
308
+ * Convert contract address to node ID
309
+ *
310
+ * @param {string} address - Address of contract
311
+ *
312
+ * @returns {string} - Node ID from contract address
313
+ */
314
+ AddressToNodeId: function AddressToNodeId(address) {
315
+ return "inod" + Utils.AddressToHash(address);
316
+ },
317
+ /**
318
+ * Convert contract address to content library ID
319
+ *
320
+ * @param {string} address - Address of contract
321
+ *
322
+ * @returns {string} - Content library ID from contract address
323
+ */
324
+ AddressToLibraryId: function AddressToLibraryId(address) {
325
+ return "ilib" + Utils.AddressToHash(address);
326
+ },
327
+ /**
328
+ * Convert contract address to content object ID
329
+ *
330
+ * @param {string} address - Address of contract
331
+ *
332
+ * @returns {string} - Content object ID from contract address
333
+ */
334
+ AddressToObjectId: function AddressToObjectId(address) {
335
+ return "iq__" + Utils.AddressToHash(address);
336
+ },
337
+ /**
338
+ * Convert any content fabric ID to the corresponding contract address
339
+ *
340
+ * @param {string} hash - Hash to convert to address
341
+ * @param {boolean} key - Whether or not the first param is a key. Defaults to address type
342
+ *
343
+ * @returns {string} - Contract address of item
344
+ */
345
+ HashToAddress: function HashToAddress(hash) {
346
+ var key = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
347
+ hash = key ? hash : hash.substr(4);
348
+ return Utils.FormatAddress((key ? "0x04" : "0x") + bs58.decode(hash).toString("hex"));
349
+ },
350
+ /**
351
+ * Compare two addresses to determine if they are the same, regardless of format/capitalization
352
+ *
353
+ * @param firstAddress
354
+ * @param secondAddress
355
+ *
356
+ * @returns {boolean} - Whether or not the addresses match
357
+ */
358
+ EqualAddress: function EqualAddress(firstAddress, secondAddress) {
359
+ if (!firstAddress || !secondAddress) {
360
+ return false;
361
+ }
362
+ return Utils.FormatAddress(firstAddress) === Utils.FormatAddress(secondAddress);
363
+ },
364
+ /**
365
+ * Compare two IDs to determine if the hashes are the same
366
+ * by comparing the contract address they resolve to
367
+ *
368
+ * @param firstHash
369
+ * @param secondHash
370
+ *
371
+ * @returns {boolean} - Whether or not the hashes of the IDs match
372
+ */
373
+ EqualHash: function EqualHash(firstHash, secondHash) {
374
+ if (!firstHash || !secondHash) {
375
+ return false;
376
+ }
377
+ if (firstHash.length <= 4 || secondHash.length <= 4) {
378
+ return false;
379
+ }
380
+ return Utils.HashToAddress(firstHash) === Utils.HashToAddress(secondHash);
381
+ },
382
+ /**
383
+ * Determine whether the address is valid
384
+ *
385
+ * @param {string} address - Address to validate
386
+ *
387
+ * @returns {boolean} - Whether or not the address is valid
388
+ */
389
+ ValidAddress: function ValidAddress(address) {
390
+ try {
391
+ getAddress(address);
392
+ return true;
393
+ } catch (error) {
394
+ return false;
395
+ }
396
+ },
397
+ /**
398
+ * Determine whether the hash is valid
399
+ *
400
+ * @param {string} hash - Hash to validate
401
+ *
402
+ * @returns {boolean} - Whether or not the hash is valid
403
+ */
404
+ ValidHash: function ValidHash(hash) {
405
+ return Utils.ValidAddress(Utils.HashToAddress(hash));
406
+ },
407
+ /**
408
+ * Convert the specified string to a bytes32 string
409
+ *
410
+ * @param {string} string - String to format as a bytes32 string
411
+ *
412
+ * @returns {string} - The given string in bytes32 format
413
+ */
414
+ ToBytes32: function ToBytes32(string) {
415
+ var bytes32 = string.split("").map(function (_char) {
416
+ return _char.charCodeAt(0).toString(16);
417
+ }).join("");
418
+ return "0x" + bytes32.slice(0, 64).padEnd(64, "0");
419
+ },
420
+ BufferToArrayBuffer: function BufferToArrayBuffer(buffer) {
421
+ return buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
422
+ },
423
+ FromHex: function FromHex(str) {
424
+ str = str.replace(/^0x/, "");
425
+ return Buffer.from(str, "hex").toString();
426
+ },
427
+ B64: function B64(str) {
428
+ var encoding = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "utf-8";
429
+ return Buffer.from(str, encoding).toString("base64");
430
+ },
431
+ FromB64: function FromB64(str) {
432
+ return Buffer.from(str, "base64").toString("utf-8");
433
+ },
434
+ FromB64URL: function FromB64URL(str) {
435
+ str = str.replace(/-/g, "+").replace(/_/g, "/");
436
+ var pad = str.length % 4;
437
+ if (pad) {
438
+ if (pad === 1) {
439
+ throw new Error("InvalidLengthError: Input base64url string is the wrong length to determine padding");
440
+ }
441
+ str += new Array(5 - pad).join("=");
442
+ }
443
+ return Utils.FromB64(str);
444
+ },
445
+ B58: function B58(arr) {
446
+ return bs58.encode(Buffer.from(arr));
447
+ },
448
+ FromB58: function FromB58(str) {
449
+ return bs58.decode(str);
450
+ },
451
+ FromB58ToStr: function FromB58ToStr(str) {
452
+ return new TextDecoder().decode(Utils.FromB58(str));
453
+ },
454
+ /**
455
+ * Decode the given fabric authorization token
456
+ *
457
+ * @param {string} token - The authorization token to decode
458
+ * @return {Object} - Token Info: {qspace_id, qlib_id*, addr, tx_id*, afgh_pk*, signature}
459
+ */
460
+ DecodeAuthorizationToken: function DecodeAuthorizationToken(token) {
461
+ token = decodeURIComponent(token);
462
+ var _token$split = token.split("."),
463
+ _token$split2 = _slicedToArray(_token$split, 2),
464
+ info = _token$split2[0],
465
+ signature = _token$split2[1];
466
+ info = JSON.parse(Utils.FromB64(info));
467
+ return _objectSpread(_objectSpread({}, info), {}, {
468
+ signature: signature
469
+ });
470
+ },
471
+ LimitedMap: function () {
472
+ var _LimitedMap = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(limit, array, f) {
473
+ var index, locked, nextIndex, results, active;
474
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
475
+ while (1) switch (_context3.prev = _context3.next) {
476
+ case 0:
477
+ index = 0;
478
+ locked = false;
479
+ nextIndex = /*#__PURE__*/function () {
480
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
481
+ var thisIndex;
482
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
483
+ while (1) switch (_context.prev = _context.next) {
484
+ case 0:
485
+ if (!locked) {
486
+ _context.next = 5;
487
+ break;
488
+ }
489
+ _context.next = 3;
490
+ return new Promise(function (resolve) {
491
+ return setTimeout(resolve, 10);
492
+ });
493
+ case 3:
494
+ _context.next = 0;
495
+ break;
496
+ case 5:
497
+ locked = true;
498
+ thisIndex = index;
499
+ index += 1;
500
+ locked = false;
501
+ return _context.abrupt("return", thisIndex);
502
+ case 10:
503
+ case "end":
504
+ return _context.stop();
505
+ }
506
+ }, _callee);
507
+ }));
508
+ return function nextIndex() {
509
+ return _ref.apply(this, arguments);
510
+ };
511
+ }();
512
+ results = [];
513
+ active = 0;
514
+ return _context3.abrupt("return", new Promise(function (resolve, reject) {
515
+ _toConsumableArray(Array(limit || 1)).forEach( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
516
+ var index;
517
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
518
+ while (1) switch (_context2.prev = _context2.next) {
519
+ case 0:
520
+ active += 1;
521
+ _context2.next = 3;
522
+ return nextIndex();
523
+ case 3:
524
+ index = _context2.sent;
525
+ case 4:
526
+ if (!(index < array.length)) {
527
+ _context2.next = 19;
528
+ break;
529
+ }
530
+ _context2.prev = 5;
531
+ _context2.next = 8;
532
+ return f(array[index], index);
533
+ case 8:
534
+ results[index] = _context2.sent;
535
+ _context2.next = 14;
536
+ break;
537
+ case 11:
538
+ _context2.prev = 11;
539
+ _context2.t0 = _context2["catch"](5);
540
+ reject(_context2.t0);
541
+ case 14:
542
+ _context2.next = 16;
543
+ return nextIndex();
544
+ case 16:
545
+ index = _context2.sent;
546
+ _context2.next = 4;
547
+ break;
548
+ case 19:
549
+ // When finished and no more workers are active, resolve
550
+ active -= 1;
551
+ if (active === 0) {
552
+ resolve(results);
553
+ }
554
+ case 21:
555
+ case "end":
556
+ return _context2.stop();
557
+ }
558
+ }, _callee2, null, [[5, 11]]);
559
+ })));
560
+ }));
561
+ case 6:
562
+ case "end":
563
+ return _context3.stop();
564
+ }
565
+ }, _callee3);
566
+ }));
567
+ function LimitedMap(_x, _x2, _x3) {
568
+ return _LimitedMap.apply(this, arguments);
569
+ }
570
+ return LimitedMap;
571
+ }(),
572
+ /**
573
+ * Interprets an http response body obtained from an http call as JSON and returns result of parsing it.
574
+ *
575
+ * @param {Promise} response - An http response from node-fetch
576
+ * @param {boolean=} debug - Whether or not to log the body
577
+ * @param {Function} logFn - Log function to use if debug is truthy
578
+ * @return {*} - Result of parsing response body as JSON
579
+ */
580
+ ResponseToJson: function () {
581
+ var _ResponseToJson = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(response) {
582
+ var debug,
583
+ logFn,
584
+ _args4 = arguments;
585
+ return _regeneratorRuntime.wrap(function _callee4$(_context4) {
586
+ while (1) switch (_context4.prev = _context4.next) {
587
+ case 0:
588
+ debug = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : false;
589
+ logFn = _args4.length > 2 ? _args4[2] : undefined;
590
+ _context4.next = 4;
591
+ return Utils.ResponseToFormat("json", response, debug, logFn);
592
+ case 4:
593
+ return _context4.abrupt("return", _context4.sent);
594
+ case 5:
595
+ case "end":
596
+ return _context4.stop();
597
+ }
598
+ }, _callee4);
599
+ }));
600
+ function ResponseToJson(_x4) {
601
+ return _ResponseToJson.apply(this, arguments);
602
+ }
603
+ return ResponseToJson;
604
+ }(),
605
+ /**
606
+ * Interprets an http response body obtained from an http call as a requested format and returns result of converting/formatting.
607
+ *
608
+ * @param {string} format - The format to use when interpreting response body (e.g. "json", "text" et. al.)
609
+ * @param {Promise} response - An http response from node-fetch
610
+ * @param {boolean=} debug - Whether or not to log a debug statement containing the body (ignored for formats other than "json" and "text")
611
+ * @param {Function} logFn - Log function to use if debug is truthy
612
+ * @return {*} - Result of converting response body into the requested format
613
+ */
614
+ ResponseToFormat: function () {
615
+ var _ResponseToFormat = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(format, response) {
616
+ var debug,
617
+ logFn,
618
+ formattedBody,
619
+ _args5 = arguments;
620
+ return _regeneratorRuntime.wrap(function _callee5$(_context5) {
621
+ while (1) switch (_context5.prev = _context5.next) {
622
+ case 0:
623
+ debug = _args5.length > 2 && _args5[2] !== undefined ? _args5[2] : false;
624
+ logFn = _args5.length > 3 ? _args5[3] : undefined;
625
+ _context5.next = 4;
626
+ return response;
627
+ case 4:
628
+ response = _context5.sent;
629
+ _context5.t0 = format.toLowerCase();
630
+ _context5.next = _context5.t0 === "json" ? 8 : _context5.t0 === "text" ? 13 : _context5.t0 === "blob" ? 18 : _context5.t0 === "arraybuffer" ? 21 : _context5.t0 === "formdata" ? 24 : _context5.t0 === "buffer" ? 27 : 30;
631
+ break;
632
+ case 8:
633
+ _context5.next = 10;
634
+ return response.json();
635
+ case 10:
636
+ formattedBody = _context5.sent;
637
+ if (debug) logFn("response body: ".concat(JSON.stringify(formattedBody, null, 2)));
638
+ return _context5.abrupt("return", formattedBody);
639
+ case 13:
640
+ _context5.next = 15;
641
+ return response.text();
642
+ case 15:
643
+ formattedBody = _context5.sent;
644
+ if (debug) logFn("response body: ".concat(formattedBody));
645
+ return _context5.abrupt("return", formattedBody);
646
+ case 18:
647
+ _context5.next = 20;
648
+ return response.blob();
649
+ case 20:
650
+ return _context5.abrupt("return", _context5.sent);
651
+ case 21:
652
+ _context5.next = 23;
653
+ return response.arrayBuffer();
654
+ case 23:
655
+ return _context5.abrupt("return", _context5.sent);
656
+ case 24:
657
+ _context5.next = 26;
658
+ return response.formData();
659
+ case 26:
660
+ return _context5.abrupt("return", _context5.sent);
661
+ case 27:
662
+ _context5.next = 29;
663
+ return response.buffer();
664
+ case 29:
665
+ return _context5.abrupt("return", _context5.sent);
666
+ case 30:
667
+ return _context5.abrupt("return", response);
668
+ case 31:
669
+ case "end":
670
+ return _context5.stop();
671
+ }
672
+ }, _callee5);
673
+ }));
674
+ function ResponseToFormat(_x5, _x6) {
675
+ return _ResponseToFormat.apply(this, arguments);
676
+ }
677
+ return ResponseToFormat;
678
+ }(),
679
+ /**
680
+ * Resize the image file or link URL to the specified maximum height. Can also be used to remove
681
+ * max height parameter(s) from a url if height is not specified.
682
+ *
683
+ * @param imageUrl - Url to an image file or link in the Fabric
684
+ * @param {number=} height - The maximum height for the image to be scaled to.
685
+ *
686
+ * @returns {string} - The modified URL with the height parameter
687
+ */
688
+ ResizeImage: function ResizeImage(_ref3) {
689
+ var imageUrl = _ref3.imageUrl,
690
+ height = _ref3.height;
691
+ if (!imageUrl || imageUrl && !imageUrl.startsWith("http")) {
692
+ return imageUrl;
693
+ }
694
+ imageUrl = URI(imageUrl).removeSearch("height").removeSearch("header-x_image_height");
695
+ if (height && !isNaN(parseInt(height))) {
696
+ imageUrl.addSearch("height", parseInt(height));
697
+ }
698
+ return imageUrl.toString();
699
+ },
700
+ SafeTraverse: function SafeTraverse(object) {
701
+ for (var _len = arguments.length, keys = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
702
+ keys[_key - 1] = arguments[_key];
703
+ }
704
+ if (!object) {
705
+ return object;
706
+ }
707
+ if (keys.length === 1 && Array.isArray(keys[0])) {
708
+ keys = keys[0];
709
+ }
710
+ var result = object;
711
+ for (var i = 0; i < keys.length; i++) {
712
+ result = result[keys[i]];
713
+ if (result === undefined) {
714
+ return undefined;
715
+ }
716
+ }
717
+ return result;
718
+ },
719
+ /**
720
+ * Determine if the given value is cloneable - Data passed in messages must be cloneable
721
+ *
722
+ * @param {*} value - Value to check
723
+ * @returns {boolean} - Whether or not the value is cloneable
724
+ */
725
+ IsCloneable: function IsCloneable(value) {
726
+ if (Object(value) !== value) {
727
+ // Primitive value
728
+ return true;
729
+ }
730
+ switch ({}.toString.call(value).slice(8, -1)) {
731
+ // Class
732
+ case "Boolean":
733
+ case "Number":
734
+ case "String":
735
+ case "Date":
736
+ case "RegExp":
737
+ case "Blob":
738
+ case "FileList":
739
+ case "ImageData":
740
+ case "ImageBitmap":
741
+ case "ArrayBuffer":
742
+ return true;
743
+ case "Array":
744
+ case "Object":
745
+ return Object.keys(value).every(function (prop) {
746
+ return Utils.IsCloneable(value[prop]);
747
+ });
748
+ case "Map":
749
+ return _toConsumableArray(value.keys()).every(Utils.IsCloneable) && _toConsumableArray(value.values()).every(Utils.IsCloneable);
750
+ case "Set":
751
+ return _toConsumableArray(value.keys()).every(Utils.IsCloneable);
752
+ default:
753
+ return false;
754
+ }
755
+ },
756
+ /**
757
+ * Make the given value cloneable if it is not already.
758
+ *
759
+ * Note: this will remove or transform any attributes of the object that are not cloneable (e.g. functions)
760
+ *
761
+ * Transformations:
762
+ * - Buffer: Converted to ArrayBuffer
763
+ * - Error: Converted to string (error.message)
764
+ *
765
+ * @param {*} value - Value to check
766
+ * @returns {*} - Cloneable value
767
+ */
768
+ MakeClonable: function MakeClonable(value) {
769
+ if (Utils.IsCloneable(value)) {
770
+ return value;
771
+ }
772
+ if (Buffer.isBuffer(value)) {
773
+ return Utils.BufferToArrayBuffer(value);
774
+ }
775
+ switch ({}.toString.call(value).slice(8, -1)) {
776
+ // Class
777
+ case "Response":
778
+ case "Function":
779
+ return undefined;
780
+ case "Boolean":
781
+ case "Number":
782
+ case "String":
783
+ case "Date":
784
+ case "RegExp":
785
+ case "Blob":
786
+ case "FileList":
787
+ case "ImageData":
788
+ case "ImageBitmap":
789
+ case "ArrayBuffer":
790
+ return value;
791
+ case "Array":
792
+ return value.map(function (element) {
793
+ return Utils.MakeClonable(element);
794
+ });
795
+ case "Set":
796
+ return new Set(Array.from(value.keys()).map(function (entry) {
797
+ return Utils.MakeClonable(entry);
798
+ }));
799
+ case "Map":
800
+ var cloneableMap = new Map();
801
+ Array.from(value.keys()).forEach(function (key) {
802
+ var cloneable = Utils.MakeClonable(value.get(key));
803
+ if (cloneable) {
804
+ cloneableMap.set(key, cloneable);
805
+ }
806
+ });
807
+ return cloneableMap;
808
+ case "Error":
809
+ return value.message;
810
+ case "Object":
811
+ var cloneableObject = {};
812
+ Object.keys(value).map(function (key) {
813
+ var cloneable = Utils.MakeClonable(value[key]);
814
+ if (cloneable) {
815
+ cloneableObject[key] = cloneable;
816
+ }
817
+ });
818
+ return cloneableObject;
819
+ default:
820
+ return JSON.parse(JSON.stringify(value));
821
+ }
822
+ },
823
+ /**
824
+ * Converts the given string to a public address
825
+ *
826
+ * @param key - Public key to convert to a public address
827
+ *
828
+ * @returns {string} - the public address
829
+ */
830
+ PublicKeyToAddress: function PublicKeyToAddress(key) {
831
+ var keyData = new Uint8Array(Buffer.from(key.replace("0x04", ""), "hex"));
832
+ var keccakHash = keccak256(keyData);
833
+ var address = "0x" + keccakHash.slice(26);
834
+ return Utils.FormatAddress(address);
835
+ },
836
+ PLATFORM_NODE: "node",
837
+ PLATFORM_WEB: "web",
838
+ PLATFORM_REACT_NATIVE: "react-native",
839
+ Platform: function Platform() {
840
+ if (typeof navigator !== "undefined" && navigator.product === "ReactNative") {
841
+ return Utils.PLATFORM_REACT_NATIVE;
842
+ } else if (typeof process !== "undefined" && typeof process.versions !== "undefined" && typeof process.versions.node !== "undefined") {
843
+ return Utils.PLATFORM_NODE;
844
+ } else {
845
+ return Utils.PLATFORM_WEB;
846
+ }
847
+ },
848
+ HLSJSSettings: function HLSJSSettings() {
849
+ var _ref4 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
850
+ _ref4$profile = _ref4.profile,
851
+ profile = _ref4$profile === void 0 ? "default" : _ref4$profile;
852
+ var isSafari = typeof window !== "undefined" && typeof window.navigator !== "undefined" && /^((?!chrome|android).)*safari/i.test(window.navigator.userAgent);
853
+ var defaultSettings = {
854
+ "maxBufferHole": 2.2,
855
+ "nudgeOffset": 0.2,
856
+ "nudgeMaxRetry": 12,
857
+ "highBufferWatchdogPeriod": 1
858
+ };
859
+ if (!isSafari && ["ull", "ultraLowLatency"].includes(profile)) {
860
+ return {
861
+ "lowLatencyMode": true,
862
+ "liveSyncDuration": 4,
863
+ "liveMaxLatencyDuration": 5,
864
+ "liveDurationInfinity": false,
865
+ "maxBufferLength": 8,
866
+ "backBufferLength": 4,
867
+ "highBufferWatchdogPeriod": 1
868
+ };
869
+ } else if (["ll", "lowLatency", "ull", "ultraLowLatency"].includes(profile)) {
870
+ return _objectSpread({
871
+ "lowLatencyMode": true,
872
+ "liveSyncDuration": 5,
873
+ "liveMaxLatencyDuration": isSafari ? 15 : 10,
874
+ "liveDurationInfinity": false,
875
+ "maxBufferLength": 5,
876
+ "backBufferLength": 5
877
+ }, defaultSettings);
878
+ } else {
879
+ return defaultSettings;
880
+ }
881
+ },
882
+ // Alias for HLSJSSettings
883
+ LiveHLSJSSettings: function LiveHLSJSSettings(_ref5) {
884
+ var _ref5$lowLatency = _ref5.lowLatency,
885
+ lowLatency = _ref5$lowLatency === void 0 ? false : _ref5$lowLatency,
886
+ _ref5$ultraLowLatency = _ref5.ultraLowLatency,
887
+ ultraLowLatency = _ref5$ultraLowLatency === void 0 ? false : _ref5$ultraLowLatency;
888
+ return Utils.HLSJSSettings({
889
+ profile: ultraLowLatency ? "ull" : lowLatency ? "ll" : "default"
890
+ });
891
+ }
892
+ };
893
+ module.exports = Utils;