@eluvio/elv-client-js 4.0.111 → 4.0.113

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