@eluvio/elv-client-js 3.1.83 → 3.1.84

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.
@@ -54,7 +54,7 @@ function (_Ethers$Signer) {
54
54
  _createClass(RemoteSigner, [{
55
55
  key: "Initialize",
56
56
  value: function Initialize() {
57
- var _ref2, addr, eth, token, keys;
57
+ var _ref2, addr, eth, token, keys, address;
58
58
 
59
59
  return _regeneratorRuntime.async(function Initialize$(_context) {
60
60
  while (1) {
@@ -91,7 +91,7 @@ function (_Ethers$Signer) {
91
91
 
92
92
  case 10:
93
93
  if (this.address) {
94
- _context.next = 15;
94
+ _context.next = 16;
95
95
  break;
96
96
  }
97
97
 
@@ -106,13 +106,19 @@ function (_Ethers$Signer) {
106
106
 
107
107
  case 13:
108
108
  keys = _context.sent;
109
- this.address = Utils.HashToAddress(keys.eth[0]);
109
+ address = keys.eth[0];
110
110
 
111
- case 15:
111
+ if (address && address.startsWith("0x")) {
112
+ this.address = address;
113
+ } else {
114
+ this.address = Utils.HashToAddress(keys.eth[0]);
115
+ }
116
+
117
+ case 16:
112
118
  this.id = this.address ? "ikms".concat(Utils.AddressToHash(this.address)) : undefined;
113
119
  this.signer = this.provider.getSigner(this.address);
114
120
 
115
- case 17:
121
+ case 18:
116
122
  case "end":
117
123
  return _context.stop();
118
124
  }
package/dist/src/Utils.js CHANGED
@@ -21,6 +21,8 @@ var BigNumber = require("bignumber.js")["default"];
21
21
  var VarInt = require("varint");
22
22
 
23
23
  var URI = require("urijs");
24
+
25
+ var keccak256 = require("ethers").utils.keccak256;
24
26
  /**
25
27
  * @namespace
26
28
  * @description This is a utility namespace mostly containing functions for managing
@@ -163,11 +165,13 @@ var Utils = {
163
165
  * Convert contract address to multiformat hash
164
166
  *
165
167
  * @param {string} address - Address of contract
168
+ * @param {boolean} key - Whether or not the first param is a public key. Defaults to address type
166
169
  *
167
170
  * @returns {string} - Hash of contract address
168
171
  */
169
172
  AddressToHash: function AddressToHash(address) {
170
- address = address.replace("0x", "");
173
+ var key = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
174
+ address = address.replace(key ? "0x04" : "0x", "");
171
175
  return bs58.encode(Buffer.from(address, "hex"));
172
176
  },
173
177
 
@@ -208,12 +212,14 @@ var Utils = {
208
212
  * Convert any content fabric ID to the corresponding contract address
209
213
  *
210
214
  * @param {string} hash - Hash to convert to address
215
+ * @param {boolean} key - Whether or not the first param is a key. Defaults to address type
211
216
  *
212
217
  * @returns {string} - Contract address of item
213
218
  */
214
219
  HashToAddress: function HashToAddress(hash) {
215
- hash = hash.substr(4);
216
- return Utils.FormatAddress("0x" + bs58.decode(hash).toString("hex"));
220
+ var key = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
221
+ hash = key ? hash : hash.substr(4);
222
+ return Utils.FormatAddress((key ? "0x04" : "0x") + bs58.decode(hash).toString("hex"));
217
223
  },
218
224
 
219
225
  /**
@@ -667,6 +673,20 @@ var Utils = {
667
673
  return JSON.parse(JSON.stringify(value));
668
674
  }
669
675
  },
676
+
677
+ /**
678
+ * Converts the given string to a public address
679
+ *
680
+ * @param key - Public key to convert to a public address
681
+ *
682
+ * @returns {string} - the public address
683
+ */
684
+ PublicKeyToAddress: function PublicKeyToAddress(key) {
685
+ var keyData = new Uint8Array(Buffer.from(key.replace("0x04", ""), "hex"));
686
+ var keccakHash = keccak256(keyData);
687
+ var address = "0x" + keccakHash.slice(26);
688
+ return Utils.FormatAddress(address);
689
+ },
670
690
  PLATFORM_NODE: "node",
671
691
  PLATFORM_WEB: "web",
672
692
  PLATFORM_REACT_NATIVE: "react-native",
@@ -32,8 +32,7 @@ var _require = require("../Validation"),
32
32
  ValidateVersion = _require.ValidateVersion,
33
33
  ValidateWriteToken = _require.ValidateWriteToken,
34
34
  ValidateParameters = _require.ValidateParameters,
35
- ValidatePresence = _require.ValidatePresence,
36
- ValidateAddress = _require.ValidateAddress;
35
+ ValidatePresence = _require.ValidatePresence;
37
36
 
38
37
  exports.SetVisibility = function _callee(_ref) {
39
38
  var id, visibility, hasSetVisibility, event;
@@ -1246,7 +1245,6 @@ exports.CopyContentObject = function _callee12(_ref15) {
1246
1245
  * @param {string} libraryId - ID of the library
1247
1246
  * @param {string} objectId - ID of the object
1248
1247
  * @param {string} publicKey - Public key for the target cap
1249
- * @param {string} publicAddress - Public address for the target cap key
1250
1248
  * @param {string} writeToken - Write token for the content object - If specified, info will be retrieved from the write draft instead of creating a new draft and finalizing
1251
1249
  *
1252
1250
  * @returns {Promise<Object>}
@@ -1254,37 +1252,37 @@ exports.CopyContentObject = function _callee12(_ref15) {
1254
1252
 
1255
1253
 
1256
1254
  exports.CreateNonOwnerCap = function _callee13(_ref17) {
1257
- var objectId, libraryId, publicKey, publicAddress, writeToken, userCapKey, userCapValue, userConk, targetUserCapKey, targetUserCapValue, finalize;
1255
+ var objectId, libraryId, publicKey, writeToken, userCapKey, userCapValue, userConk, publicAddress, targetUserCapKey, targetUserCapValue, finalize;
1258
1256
  return _regeneratorRuntime.async(function _callee13$(_context14) {
1259
1257
  while (1) {
1260
1258
  switch (_context14.prev = _context14.next) {
1261
1259
  case 0:
1262
- objectId = _ref17.objectId, libraryId = _ref17.libraryId, publicKey = _ref17.publicKey, publicAddress = _ref17.publicAddress, writeToken = _ref17.writeToken;
1263
- publicAddress = ValidateAddress(publicAddress);
1260
+ objectId = _ref17.objectId, libraryId = _ref17.libraryId, publicKey = _ref17.publicKey, writeToken = _ref17.writeToken;
1264
1261
  userCapKey = "eluv.caps.iusr".concat(this.utils.AddressToHash(this.signer.address));
1265
- _context14.next = 5;
1262
+ _context14.next = 4;
1266
1263
  return _regeneratorRuntime.awrap(this.ContentObjectMetadata({
1267
1264
  objectId: objectId,
1268
1265
  libraryId: libraryId,
1269
1266
  metadataSubtree: userCapKey
1270
1267
  }));
1271
1268
 
1272
- case 5:
1269
+ case 4:
1273
1270
  userCapValue = _context14.sent;
1274
1271
 
1275
1272
  if (userCapValue) {
1276
- _context14.next = 8;
1273
+ _context14.next = 7;
1277
1274
  break;
1278
1275
  }
1279
1276
 
1280
1277
  throw Error("No user cap found for current user");
1281
1278
 
1282
- case 8:
1283
- _context14.next = 10;
1279
+ case 7:
1280
+ _context14.next = 9;
1284
1281
  return _regeneratorRuntime.awrap(this.Crypto.DecryptCap(userCapValue, this.signer.signingKey.privateKey));
1285
1282
 
1286
- case 10:
1283
+ case 9:
1287
1284
  userConk = _context14.sent;
1285
+ publicAddress = this.utils.PublicKeyToAddress(publicKey);
1288
1286
  targetUserCapKey = "eluv.caps.iusr".concat(this.utils.AddressToHash(publicAddress));
1289
1287
  _context14.next = 14;
1290
1288
  return _regeneratorRuntime.awrap(this.Crypto.EncryptConk(userConk, publicKey));
package/package-lock.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eluvio/elv-client-js",
3
- "version": "3.1.83",
3
+ "version": "3.1.84",
4
4
  "lockfileVersion": 1,
5
5
  "requires": true,
6
6
  "dependencies": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eluvio/elv-client-js",
3
- "version": "3.1.83",
3
+ "version": "3.1.84",
4
4
  "description": "Javascript client for the Eluvio Content Fabric",
5
5
  "main": "src/ElvClient.js",
6
6
  "author": "Kevin Talmadge",
@@ -55,7 +55,13 @@ class RemoteSigner extends Ethers.Signer {
55
55
  })
56
56
  );
57
57
 
58
- this.address = Utils.HashToAddress(keys.eth[0]);
58
+ const address = keys.eth[0];
59
+
60
+ if(address && address.startsWith("0x")) {
61
+ this.address = address;
62
+ } else {
63
+ this.address = Utils.HashToAddress(keys.eth[0]);
64
+ }
59
65
  }
60
66
 
61
67
  this.id = this.address ? `ikms${Utils.AddressToHash(this.address)}` : undefined;
package/src/Utils.js CHANGED
@@ -5,6 +5,10 @@ const BigNumber = require("bignumber.js").default;
5
5
  const VarInt = require("varint");
6
6
  const URI = require("urijs");
7
7
 
8
+ const {
9
+ keccak256
10
+ } = require("ethers").utils;
11
+
8
12
  /**
9
13
  * @namespace
10
14
  * @description This is a utility namespace mostly containing functions for managing
@@ -149,11 +153,12 @@ const Utils = {
149
153
  * Convert contract address to multiformat hash
150
154
  *
151
155
  * @param {string} address - Address of contract
156
+ * @param {boolean} key - Whether or not the first param is a public key. Defaults to address type
152
157
  *
153
158
  * @returns {string} - Hash of contract address
154
159
  */
155
- AddressToHash: (address) => {
156
- address = address.replace("0x", "");
160
+ AddressToHash: (address, key=false) => {
161
+ address = address.replace(key ? "0x04" : "0x", "");
157
162
  return bs58.encode(Buffer.from(address, "hex"));
158
163
  },
159
164
 
@@ -194,12 +199,13 @@ const Utils = {
194
199
  * Convert any content fabric ID to the corresponding contract address
195
200
  *
196
201
  * @param {string} hash - Hash to convert to address
202
+ * @param {boolean} key - Whether or not the first param is a key. Defaults to address type
197
203
  *
198
204
  * @returns {string} - Contract address of item
199
205
  */
200
- HashToAddress: (hash) => {
201
- hash = hash.substr(4);
202
- return Utils.FormatAddress("0x" + bs58.decode(hash).toString("hex"));
206
+ HashToAddress: (hash, key=false) => {
207
+ hash = key ? hash : hash.substr(4);
208
+ return Utils.FormatAddress((key ? "0x04" : "0x") + bs58.decode(hash).toString("hex"));
203
209
  },
204
210
 
205
211
  /**
@@ -505,6 +511,21 @@ const Utils = {
505
511
  }
506
512
  },
507
513
 
514
+ /**
515
+ * Converts the given string to a public address
516
+ *
517
+ * @param key - Public key to convert to a public address
518
+ *
519
+ * @returns {string} - the public address
520
+ */
521
+ PublicKeyToAddress: (key) => {
522
+ const keyData = new Uint8Array(Buffer.from(key.replace("0x04", ""), "hex"));
523
+ const keccakHash = keccak256(keyData);
524
+ const address = "0x" + keccakHash.slice(26);
525
+
526
+ return Utils.FormatAddress(address);
527
+ },
528
+
508
529
  PLATFORM_NODE: "node",
509
530
  PLATFORM_WEB: "web",
510
531
  PLATFORM_REACT_NATIVE: "react-native",
@@ -22,7 +22,6 @@ const {
22
22
  ValidateWriteToken,
23
23
  ValidateParameters,
24
24
  ValidatePresence,
25
- ValidateAddress
26
25
  } = require("../Validation");
27
26
 
28
27
  exports.SetVisibility = async function({id, visibility}) {
@@ -691,13 +690,11 @@ exports.CopyContentObject = async function({libraryId, originalVersionHash, opti
691
690
  * @param {string} libraryId - ID of the library
692
691
  * @param {string} objectId - ID of the object
693
692
  * @param {string} publicKey - Public key for the target cap
694
- * @param {string} publicAddress - Public address for the target cap key
695
693
  * @param {string} writeToken - Write token for the content object - If specified, info will be retrieved from the write draft instead of creating a new draft and finalizing
696
694
  *
697
695
  * @returns {Promise<Object>}
698
696
  */
699
- exports.CreateNonOwnerCap = async function({objectId, libraryId, publicKey, publicAddress, writeToken}) {
700
- publicAddress = ValidateAddress(publicAddress);
697
+ exports.CreateNonOwnerCap = async function({objectId, libraryId, publicKey, writeToken}) {
701
698
  const userCapKey = `eluv.caps.iusr${this.utils.AddressToHash(this.signer.address)}`;
702
699
  const userCapValue = await this.ContentObjectMetadata({objectId, libraryId, metadataSubtree: userCapKey});
703
700
 
@@ -707,6 +704,8 @@ exports.CreateNonOwnerCap = async function({objectId, libraryId, publicKey, publ
707
704
 
708
705
  const userConk = await this.Crypto.DecryptCap(userCapValue, this.signer.signingKey.privateKey);
709
706
 
707
+ const publicAddress = this.utils.PublicKeyToAddress(publicKey);
708
+
710
709
  const targetUserCapKey = `eluv.caps.iusr${this.utils.AddressToHash(publicAddress)}`;
711
710
  const targetUserCapValue = await this.Crypto.EncryptConk(userConk, publicKey);
712
711
 
@@ -16,7 +16,6 @@ const reportTypes = [
16
16
 
17
17
  const liveTypes = [
18
18
  { name: "Eluvio LIVE Drop Event Site", spec: require("../typeSpecs/DropEventSite") },
19
- { name: "Eluvio LIVE Event Site", spec: require("../typeSpecs/EventSite") },
20
19
  { name: "Eluvio LIVE Marketplace", spec: require("../typeSpecs/Marketplace") },
21
20
  { name: "Eluvio LIVE Tenant", spec: require("../typeSpecs/EventTenant") },
22
21
  { name: "NFT Collection", spec: require("../typeSpecs/NFTCollection") },