@eluvio/elv-client-js 3.1.94 → 3.1.97

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.
@@ -151,13 +151,14 @@ function (_Ethers$Signer) {
151
151
  switch (_context3.prev = _context3.next) {
152
152
  case 0:
153
153
  if (!this.signatureCache[digest]) {
154
- this.signatureCache[digest] = new Promise(function _callee(resolve) {
154
+ this.signatureCache[digest] = new Promise(function _callee(resolve, reject) {
155
155
  var signature;
156
156
  return _regeneratorRuntime.async(function _callee$(_context2) {
157
157
  while (1) {
158
158
  switch (_context2.prev = _context2.next) {
159
159
  case 0:
160
- _context2.next = 2;
160
+ _context2.prev = 0;
161
+ _context2.next = 3;
161
162
  return _regeneratorRuntime.awrap(Utils.ResponseToJson(_this2.HttpClient.Request({
162
163
  method: "POST",
163
164
  path: UrlJoin("as", "wlt", "sign", "eth", _this2.id),
@@ -169,18 +170,25 @@ function (_Ethers$Signer) {
169
170
  }
170
171
  })));
171
172
 
172
- case 2:
173
+ case 3:
173
174
  signature = _context2.sent;
174
175
  signature.v = parseInt(signature.v, 16);
175
176
  signature.recoveryParam = signature.v - 27;
176
177
  resolve(signature);
178
+ _context2.next = 12;
179
+ break;
177
180
 
178
- case 6:
181
+ case 9:
182
+ _context2.prev = 9;
183
+ _context2.t0 = _context2["catch"](0);
184
+ reject(_context2.t0);
185
+
186
+ case 12:
179
187
  case "end":
180
188
  return _context2.stop();
181
189
  }
182
190
  }
183
- });
191
+ }, null, null, [[0, 9]]);
184
192
  });
185
193
  }
186
194
 
package/dist/src/Utils.js CHANGED
@@ -24,6 +24,8 @@ var VarInt = require("varint");
24
24
 
25
25
  var URI = require("urijs");
26
26
 
27
+ var Pako = require("pako");
28
+
27
29
  var _require$utils = require("ethers").utils,
28
30
  keccak256 = _require$utils.keccak256,
29
31
  getAddress = _require$utils.getAddress;
@@ -165,6 +167,24 @@ var Utils = {
165
167
  };
166
168
  },
167
169
 
170
+ /**
171
+ * Decode the specified signed token into its component parts
172
+ *
173
+ * @param {string} token - The token to decode
174
+ *
175
+ * @return {Object} - Components of the signed token
176
+ */
177
+ DecodeSignedToken: function DecodeSignedToken(token) {
178
+ var decodedToken = Utils.FromB58(token.slice(6));
179
+ var signature = "0x".concat(decodedToken.slice(0, 65).toString("hex"));
180
+ var payload = JSON.parse(Buffer.from(Pako.inflateRaw(decodedToken.slice(65))).toString("utf-8"));
181
+ payload.adr = Utils.FormatAddress("0x".concat(Buffer.from(payload.adr, "base64").toString("hex")));
182
+ return {
183
+ payload: payload,
184
+ signature: signature
185
+ };
186
+ },
187
+
168
188
  /**
169
189
  * Decode the specified write token into its component parts
170
190
  *
@@ -625,7 +625,7 @@ exports.CreateABRMezzanine = function _callee2(_ref4) {
625
625
  exports.StartABRMezzanineJobs = function _callee4(_ref6) {
626
626
  var _this = this;
627
627
 
628
- var libraryId, objectId, _ref6$offeringKey, offeringKey, _ref6$access, access, _ref6$jobIndexes, jobIndexes, mezzanineMetadata, prepSpecs, masterVersionHashes, authorizationTokens, headers, processingDraft, lroInfo, statusDraft, _ref7, data, errors, warnings, logs;
628
+ var libraryId, objectId, _ref6$offeringKey, offeringKey, _ref6$access, access, _ref6$jobIndexes, jobIndexes, mezzanineMetadata, prepSpecs, masterVersionHashes, authorizationTokens, headers, processingDraft, lroInfo, statusDraft, finalizeResponse, _ref7, data, errors, warnings, logs;
629
629
 
630
630
  return _regeneratorRuntime.async(function _callee4$(_context4) {
631
631
  while (1) {
@@ -740,7 +740,8 @@ exports.StartABRMezzanineJobs = function _callee4(_ref6) {
740
740
  }));
741
741
 
742
742
  case 28:
743
- _context4.next = 30;
743
+ finalizeResponse = _context4.sent;
744
+ _context4.next = 31;
744
745
  return _regeneratorRuntime.awrap(this.CallBitcodeMethod({
745
746
  libraryId: libraryId,
746
747
  objectId: objectId,
@@ -755,13 +756,14 @@ exports.StartABRMezzanineJobs = function _callee4(_ref6) {
755
756
  }
756
757
  }));
757
758
 
758
- case 30:
759
+ case 31:
759
760
  _ref7 = _context4.sent;
760
761
  data = _ref7.data;
761
762
  errors = _ref7.errors;
762
763
  warnings = _ref7.warnings;
763
764
  logs = _ref7.logs;
764
765
  return _context4.abrupt("return", {
766
+ hash: finalizeResponse.hash,
765
767
  lro_draft: lroInfo,
766
768
  writeToken: processingDraft.write_token,
767
769
  data: data,
@@ -770,7 +772,7 @@ exports.StartABRMezzanineJobs = function _callee4(_ref6) {
770
772
  errors: errors || []
771
773
  });
772
774
 
773
- case 36:
775
+ case 37:
774
776
  case "end":
775
777
  return _context4.stop();
776
778
  }
@@ -4104,6 +4104,15 @@ exports.CreateEncryptionConk = function _callee46(_ref39) {
4104
4104
  switch (_context46.prev = _context46.next) {
4105
4105
  case 0:
4106
4106
  libraryId = _ref39.libraryId, objectId = _ref39.objectId, versionHash = _ref39.versionHash, writeToken = _ref39.writeToken, _ref39$createKMSConk = _ref39.createKMSConk, createKMSConk = _ref39$createKMSConk === void 0 ? true : _ref39$createKMSConk;
4107
+
4108
+ if (!this.signer.remoteSigner) {
4109
+ _context46.next = 3;
4110
+ break;
4111
+ }
4112
+
4113
+ return _context46.abrupt("return");
4114
+
4115
+ case 3:
4107
4116
  ValidateParameters({
4108
4117
  libraryId: libraryId,
4109
4118
  objectId: objectId,
@@ -4116,21 +4125,21 @@ exports.CreateEncryptionConk = function _callee46(_ref39) {
4116
4125
  }
4117
4126
 
4118
4127
  if (libraryId) {
4119
- _context46.next = 8;
4128
+ _context46.next = 10;
4120
4129
  break;
4121
4130
  }
4122
4131
 
4123
- _context46.next = 7;
4132
+ _context46.next = 9;
4124
4133
  return _regeneratorRuntime.awrap(this.ContentObjectLibraryId({
4125
4134
  objectId: objectId
4126
4135
  }));
4127
4136
 
4128
- case 7:
4137
+ case 9:
4129
4138
  libraryId = _context46.sent;
4130
4139
 
4131
- case 8:
4140
+ case 10:
4132
4141
  capKey = "eluv.caps.iusr".concat(this.utils.AddressToHash(this.signer.address));
4133
- _context46.next = 11;
4142
+ _context46.next = 13;
4134
4143
  return _regeneratorRuntime.awrap(this.ContentObjectMetadata({
4135
4144
  libraryId: libraryId,
4136
4145
  objectId: objectId,
@@ -4138,30 +4147,30 @@ exports.CreateEncryptionConk = function _callee46(_ref39) {
4138
4147
  metadataSubtree: capKey
4139
4148
  }));
4140
4149
 
4141
- case 11:
4150
+ case 13:
4142
4151
  existingUserCap = _context46.sent;
4143
4152
 
4144
4153
  if (!existingUserCap) {
4145
- _context46.next = 18;
4154
+ _context46.next = 20;
4146
4155
  break;
4147
4156
  }
4148
4157
 
4149
- _context46.next = 15;
4158
+ _context46.next = 17;
4150
4159
  return _regeneratorRuntime.awrap(this.Crypto.DecryptCap(existingUserCap, this.signer.signingKey.privateKey));
4151
4160
 
4152
- case 15:
4161
+ case 17:
4153
4162
  this.encryptionConks[objectId] = _context46.sent;
4154
- _context46.next = 34;
4163
+ _context46.next = 36;
4155
4164
  break;
4156
4165
 
4157
- case 18:
4158
- _context46.next = 20;
4166
+ case 20:
4167
+ _context46.next = 22;
4159
4168
  return _regeneratorRuntime.awrap(this.Crypto.GeneratePrimaryConk({
4160
4169
  spaceId: this.contentSpaceId,
4161
4170
  objectId: objectId
4162
4171
  }));
4163
4172
 
4164
- case 20:
4173
+ case 22:
4165
4174
  this.encryptionConks[objectId] = _context46.sent;
4166
4175
  _context46.t0 = _regeneratorRuntime;
4167
4176
  _context46.t1 = this;
@@ -4169,10 +4178,10 @@ exports.CreateEncryptionConk = function _callee46(_ref39) {
4169
4178
  _context46.t3 = objectId;
4170
4179
  _context46.t4 = writeToken;
4171
4180
  _context46.t5 = capKey;
4172
- _context46.next = 29;
4181
+ _context46.next = 31;
4173
4182
  return _regeneratorRuntime.awrap(this.Crypto.EncryptConk(this.encryptionConks[objectId], this.signer.signingKey.publicKey));
4174
4183
 
4175
- case 29:
4184
+ case 31:
4176
4185
  _context46.t6 = _context46.sent;
4177
4186
  _context46.t7 = {
4178
4187
  libraryId: _context46.t2,
@@ -4182,32 +4191,32 @@ exports.CreateEncryptionConk = function _callee46(_ref39) {
4182
4191
  metadata: _context46.t6
4183
4192
  };
4184
4193
  _context46.t8 = _context46.t1.ReplaceMetadata.call(_context46.t1, _context46.t7);
4185
- _context46.next = 34;
4194
+ _context46.next = 36;
4186
4195
  return _context46.t0.awrap.call(_context46.t0, _context46.t8);
4187
4196
 
4188
- case 34:
4197
+ case 36:
4189
4198
  if (!createKMSConk) {
4190
- _context46.next = 66;
4199
+ _context46.next = 68;
4191
4200
  break;
4192
4201
  }
4193
4202
 
4194
- _context46.prev = 35;
4195
- _context46.next = 38;
4203
+ _context46.prev = 37;
4204
+ _context46.next = 40;
4196
4205
  return _regeneratorRuntime.awrap(this.authClient.KMSAddress({
4197
4206
  objectId: objectId
4198
4207
  }));
4199
4208
 
4200
- case 38:
4209
+ case 40:
4201
4210
  kmsAddress = _context46.sent;
4202
- _context46.next = 41;
4211
+ _context46.next = 43;
4203
4212
  return _regeneratorRuntime.awrap(this.authClient.KMSInfo({
4204
4213
  objectId: objectId
4205
4214
  }));
4206
4215
 
4207
- case 41:
4216
+ case 43:
4208
4217
  kmsPublicKey = _context46.sent.publicKey;
4209
4218
  kmsCapKey = "eluv.caps.ikms".concat(this.utils.AddressToHash(kmsAddress));
4210
- _context46.next = 45;
4219
+ _context46.next = 47;
4211
4220
  return _regeneratorRuntime.awrap(this.ContentObjectMetadata({
4212
4221
  libraryId: libraryId,
4213
4222
  // Cap may only exist in draft
@@ -4216,11 +4225,11 @@ exports.CreateEncryptionConk = function _callee46(_ref39) {
4216
4225
  metadataSubtree: kmsCapKey
4217
4226
  }));
4218
4227
 
4219
- case 45:
4228
+ case 47:
4220
4229
  existingKMSCap = _context46.sent;
4221
4230
 
4222
4231
  if (existingKMSCap) {
4223
- _context46.next = 60;
4232
+ _context46.next = 62;
4224
4233
  break;
4225
4234
  }
4226
4235
 
@@ -4230,10 +4239,10 @@ exports.CreateEncryptionConk = function _callee46(_ref39) {
4230
4239
  _context46.t12 = objectId;
4231
4240
  _context46.t13 = writeToken;
4232
4241
  _context46.t14 = kmsCapKey;
4233
- _context46.next = 55;
4242
+ _context46.next = 57;
4234
4243
  return _regeneratorRuntime.awrap(this.Crypto.EncryptConk(this.encryptionConks[objectId], kmsPublicKey));
4235
4244
 
4236
- case 55:
4245
+ case 57:
4237
4246
  _context46.t15 = _context46.sent;
4238
4247
  _context46.t16 = {
4239
4248
  libraryId: _context46.t11,
@@ -4243,30 +4252,30 @@ exports.CreateEncryptionConk = function _callee46(_ref39) {
4243
4252
  metadata: _context46.t15
4244
4253
  };
4245
4254
  _context46.t17 = _context46.t10.ReplaceMetadata.call(_context46.t10, _context46.t16);
4246
- _context46.next = 60;
4255
+ _context46.next = 62;
4247
4256
  return _context46.t9.awrap.call(_context46.t9, _context46.t17);
4248
4257
 
4249
- case 60:
4250
- _context46.next = 66;
4258
+ case 62:
4259
+ _context46.next = 68;
4251
4260
  break;
4252
4261
 
4253
- case 62:
4254
- _context46.prev = 62;
4255
- _context46.t18 = _context46["catch"](35);
4262
+ case 64:
4263
+ _context46.prev = 64;
4264
+ _context46.t18 = _context46["catch"](37);
4256
4265
  // eslint-disable-next-line no-console
4257
4266
  console.error("Failed to create encryption cap for KMS:"); // eslint-disable-next-line no-console
4258
4267
 
4259
4268
  console.error(_context46.t18);
4260
4269
 
4261
- case 66:
4270
+ case 68:
4262
4271
  return _context46.abrupt("return", this.encryptionConks[objectId]);
4263
4272
 
4264
- case 67:
4273
+ case 69:
4265
4274
  case "end":
4266
4275
  return _context46.stop();
4267
4276
  }
4268
4277
  }
4269
- }, null, this, [[35, 62]]);
4278
+ }, null, this, [[37, 64]]);
4270
4279
  };
4271
4280
  /**
4272
4281
  * Retrieve the encryption conk for the specified object. If one has not yet been created