emblem-vault-sdk 1.10.2 → 1.10.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -35,7 +35,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
35
35
  const bignumber_1 = require("@ethersproject/bignumber");
36
36
  const utils_1 = require("./utils");
37
37
  const derive_1 = require("./derive");
38
- const SDK_VERSION = '1.10.2';
38
+ const SDK_VERSION = '1.10.4';
39
39
  class EmblemVaultSDK {
40
40
  constructor(apiKey, baseUrl) {
41
41
  this.apiKey = apiKey;
@@ -81,8 +81,8 @@ class EmblemVaultSDK {
81
81
  }
82
82
  // ** Curated **
83
83
  //
84
- fetchCuratedContracts(hideUnMintable = false, overrideFunc = false) {
85
- return __awaiter(this, void 0, void 0, function* () {
84
+ fetchCuratedContracts() {
85
+ return __awaiter(this, arguments, void 0, function* (hideUnMintable = false, overrideFunc = false) {
86
86
  let url = `${this.baseUrl}/curated`;
87
87
  // Fetch using URL or override function
88
88
  let data = typeof overrideFunc === 'function' ? yield overrideFunc() : yield (0, utils_1.fetchData)(url, this.apiKey);
@@ -104,15 +104,15 @@ class EmblemVaultSDK {
104
104
  return data;
105
105
  });
106
106
  }
107
- fetchCuratedContractByName(name, contracts = false) {
108
- return __awaiter(this, void 0, void 0, function* () {
107
+ fetchCuratedContractByName(name_1) {
108
+ return __awaiter(this, arguments, void 0, function* (name, contracts = false) {
109
109
  !contracts ? contracts = yield this.fetchCuratedContracts() : null;
110
110
  let contract = contracts.find((contract) => contract.name === name);
111
111
  return contract || null;
112
112
  });
113
113
  }
114
- createCuratedVault(template, callback = null) {
115
- return __awaiter(this, void 0, void 0, function* () {
114
+ createCuratedVault(template_1) {
115
+ return __awaiter(this, arguments, void 0, function* (template, callback = null) {
116
116
  (0, utils_1.templateGuard)(template);
117
117
  template.chainId == 1 ? delete template.targetContract[5] : delete template.targetContract[1];
118
118
  let url = `${this.baseUrl}/create-curated`;
@@ -126,8 +126,8 @@ class EmblemVaultSDK {
126
126
  return vaultCreationResponse.data;
127
127
  });
128
128
  }
129
- fetchMetadata(tokenId, callback = null) {
130
- return __awaiter(this, void 0, void 0, function* () {
129
+ fetchMetadata(tokenId_1) {
130
+ return __awaiter(this, arguments, void 0, function* (tokenId, callback = null) {
131
131
  (0, utils_1.genericGuard)(tokenId, "string", "tokenId");
132
132
  if (callback) {
133
133
  callback('getting Metadata');
@@ -140,13 +140,13 @@ class EmblemVaultSDK {
140
140
  return metadata;
141
141
  });
142
142
  }
143
- refreshBalance(tokenId, callback = null) {
144
- return __awaiter(this, void 0, void 0, function* () {
143
+ refreshBalance(tokenId_1) {
144
+ return __awaiter(this, arguments, void 0, function* (tokenId, callback = null) {
145
145
  (0, utils_1.genericGuard)(tokenId, "string", "tokenId");
146
146
  if (callback) {
147
147
  callback('refreshing Balance');
148
148
  }
149
- let url = `${this.v1Url}/vault/balance/${tokenId}?live=true`;
149
+ let url = `${this.v3Url}/vault/balance/${tokenId}?live=true`;
150
150
  let balance = yield (0, utils_1.fetchData)(url, this.apiKey);
151
151
  if (callback) {
152
152
  callback('received Balance', balance.balances);
@@ -163,8 +163,8 @@ class EmblemVaultSDK {
163
163
  return vaults;
164
164
  });
165
165
  }
166
- generateJumpReport(address, hideUnMintable = false) {
167
- return __awaiter(this, void 0, void 0, function* () {
166
+ generateJumpReport(address_1) {
167
+ return __awaiter(this, arguments, void 0, function* (address, hideUnMintable = false) {
168
168
  let vaultType = "unclaimed";
169
169
  let curated = yield this.fetchCuratedContracts();
170
170
  return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
@@ -202,8 +202,8 @@ class EmblemVaultSDK {
202
202
  }));
203
203
  });
204
204
  }
205
- generateMintReport(address, hideUnMintable = false) {
206
- return __awaiter(this, void 0, void 0, function* () {
205
+ generateMintReport(address_1) {
206
+ return __awaiter(this, arguments, void 0, function* (address, hideUnMintable = false) {
207
207
  let vaults = yield this.fetchVaultsOfType("created", address);
208
208
  let curated = yield this.fetchCuratedContracts();
209
209
  let map = {};
@@ -212,7 +212,7 @@ class EmblemVaultSDK {
212
212
  vaults.forEach((vault) => __awaiter(this, void 0, void 0, function* () {
213
213
  if (vault.targetContract) {
214
214
  let targetVault = yield this.fetchCuratedContractByName(vault.targetContract.name, curated);
215
- let balance = vault.balances && vault.balances.length > 0 ? vault.balances : [];
215
+ let balance = vault.balances && vault.balances.length > 0 ? vault.balances : vault.ownership && vault.ownership.balances && vault.ownership.balances.length > 0 ? vault.ownership.balances : [];
216
216
  let allowed = targetVault.allowed(balance, targetVault);
217
217
  if (allowed || !hideUnMintable) {
218
218
  map[vault.tokenId] = { to: vault.targetContract.name, mintable: allowed };
@@ -234,8 +234,8 @@ class EmblemVaultSDK {
234
234
  }));
235
235
  });
236
236
  }
237
- generateMigrateReport(address, hideUnMintable = false) {
238
- return __awaiter(this, void 0, void 0, function* () {
237
+ generateMigrateReport(address_1) {
238
+ return __awaiter(this, arguments, void 0, function* (address, hideUnMintable = false) {
239
239
  let vaultType = "unclaimed";
240
240
  let curated = yield this.fetchCuratedContracts();
241
241
  return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
@@ -301,8 +301,8 @@ class EmblemVaultSDK {
301
301
  }
302
302
  });
303
303
  }
304
- performMintChain(web3, tokenId, collectionName, callback = null) {
305
- return __awaiter(this, void 0, void 0, function* () {
304
+ performMintChain(web3_1, tokenId_1, collectionName_1) {
305
+ return __awaiter(this, arguments, void 0, function* (web3, tokenId, collectionName, callback = null) {
306
306
  let collection = yield this.fetchCuratedContractByName(collectionName);
307
307
  let mintRequestSig = yield this.requestLocalMintSignature(web3, tokenId, callback);
308
308
  let remoteMintSig = yield this.requestRemoteMintSignature(web3, tokenId, mintRequestSig, callback);
@@ -312,16 +312,16 @@ class EmblemVaultSDK {
312
312
  return { mintResponse };
313
313
  });
314
314
  }
315
- performClaimChain(web3, tokenId, serialNumber, callback = null) {
316
- return __awaiter(this, void 0, void 0, function* () {
315
+ performClaimChain(web3_1, tokenId_1, serialNumber_1) {
316
+ return __awaiter(this, arguments, void 0, function* (web3, tokenId, serialNumber, callback = null) {
317
317
  let sig = yield this.requestLocalClaimSignature(web3, tokenId, serialNumber, callback);
318
318
  let jwt = yield this.requestRemoteClaimToken(web3, tokenId, sig, callback);
319
319
  let dkeys = yield this.requestRemoteKey(tokenId, jwt, callback);
320
320
  return yield this.decryptVaultKeys(tokenId, dkeys, callback);
321
321
  });
322
322
  }
323
- requestLocalMintSignature(web3, tokenId, callback = null) {
324
- return __awaiter(this, void 0, void 0, function* () {
323
+ requestLocalMintSignature(web3_1, tokenId_1) {
324
+ return __awaiter(this, arguments, void 0, function* (web3, tokenId, callback = null) {
325
325
  if (callback) {
326
326
  callback('requesting User Mint Signature');
327
327
  }
@@ -334,8 +334,8 @@ class EmblemVaultSDK {
334
334
  return signature;
335
335
  });
336
336
  }
337
- requestLocalClaimSignature(web3, tokenId, serialNumber, callback = null) {
338
- return __awaiter(this, void 0, void 0, function* () {
337
+ requestLocalClaimSignature(web3_1, tokenId_1, serialNumber_1) {
338
+ return __awaiter(this, arguments, void 0, function* (web3, tokenId, serialNumber, callback = null) {
339
339
  if (callback) {
340
340
  callback('requesting User Claim Signature');
341
341
  }
@@ -348,8 +348,8 @@ class EmblemVaultSDK {
348
348
  return signature;
349
349
  });
350
350
  }
351
- requestRemoteMintSignature(web3, tokenId, signature, callback = null) {
352
- return __awaiter(this, void 0, void 0, function* () {
351
+ requestRemoteMintSignature(web3_1, tokenId_1, signature_1) {
352
+ return __awaiter(this, arguments, void 0, function* (web3, tokenId, signature, callback = null) {
353
353
  if (callback) {
354
354
  callback('requesting Remote Mint signature');
355
355
  }
@@ -365,8 +365,8 @@ class EmblemVaultSDK {
365
365
  return remoteMintResponse;
366
366
  });
367
367
  }
368
- requestRemoteClaimToken(web3, tokenId, signature, callback = null) {
369
- return __awaiter(this, void 0, void 0, function* () {
368
+ requestRemoteClaimToken(web3_1, tokenId_1, signature_1) {
369
+ return __awaiter(this, arguments, void 0, function* (web3, tokenId, signature, callback = null) {
370
370
  if (callback) {
371
371
  callback('requesting Remote Claim token');
372
372
  }
@@ -379,8 +379,8 @@ class EmblemVaultSDK {
379
379
  return remoteClaimResponse;
380
380
  });
381
381
  }
382
- requestRemoteKey(tokenId, jwt, callback = null) {
383
- return __awaiter(this, void 0, void 0, function* () {
382
+ requestRemoteKey(tokenId_1, jwt_1) {
383
+ return __awaiter(this, arguments, void 0, function* (tokenId, jwt, callback = null) {
384
384
  if (callback) {
385
385
  callback('requesting Remote Key');
386
386
  }
@@ -391,8 +391,8 @@ class EmblemVaultSDK {
391
391
  return dkeys;
392
392
  });
393
393
  }
394
- decryptVaultKeys(tokenId, dkeys, callback = null) {
395
- return __awaiter(this, void 0, void 0, function* () {
394
+ decryptVaultKeys(tokenId_1, dkeys_1) {
395
+ return __awaiter(this, arguments, void 0, function* (tokenId, dkeys, callback = null) {
396
396
  if (callback) {
397
397
  callback('decrypting Vault Keys');
398
398
  }
@@ -404,8 +404,8 @@ class EmblemVaultSDK {
404
404
  return ukeys;
405
405
  });
406
406
  }
407
- getQuote(web3, amount, callback = null) {
408
- return __awaiter(this, void 0, void 0, function* () {
407
+ getQuote(web3_1, amount_1) {
408
+ return __awaiter(this, arguments, void 0, function* (web3, amount, callback = null) {
409
409
  if (callback) {
410
410
  callback('requesting Quote');
411
411
  }
@@ -418,8 +418,8 @@ class EmblemVaultSDK {
418
418
  return quote;
419
419
  });
420
420
  }
421
- performMint(web3, quote, remoteMintSig, callback = null) {
422
- return __awaiter(this, void 0, void 0, function* () {
421
+ performMint(web3_1, quote_1, remoteMintSig_1) {
422
+ return __awaiter(this, arguments, void 0, function* (web3, quote, remoteMintSig, callback = null) {
423
423
  // async performMint(web3, quote, remoteMintSig, callback = null) {
424
424
  if (callback) {
425
425
  callback('performing Mint');
@@ -456,8 +456,8 @@ class EmblemVaultSDK {
456
456
  return mintResponse;
457
457
  });
458
458
  }
459
- performBurn(web3, tokenId, callback = null) {
460
- return __awaiter(this, void 0, void 0, function* () {
459
+ performBurn(web3_1, tokenId_1) {
460
+ return __awaiter(this, arguments, void 0, function* (web3, tokenId, callback = null) {
461
461
  let metadata = yield this.fetchMetadata(tokenId);
462
462
  let targetContract = yield this.fetchCuratedContractByName(metadata.targetContract.name);
463
463
  if (callback) {
@@ -518,20 +518,20 @@ class EmblemVaultSDK {
518
518
  }));
519
519
  });
520
520
  }
521
- checkLiveliness(tokenId, chainId = 1) {
522
- return __awaiter(this, void 0, void 0, function* () {
521
+ checkLiveliness(tokenId_1) {
522
+ return __awaiter(this, arguments, void 0, function* (tokenId, chainId = 1) {
523
523
  let url = `${this.baseUrl}/liveliness-curated/`;
524
524
  return yield (0, utils_1.fetchData)(url, this.apiKey, 'POST', { tokenId: tokenId }, { chainid: chainId, "Content-Type": "application/json" });
525
525
  });
526
526
  }
527
- checkLivelinessBulk(tokenIds, chainId = 1) {
528
- return __awaiter(this, void 0, void 0, function* () {
527
+ checkLivelinessBulk(tokenIds_1) {
528
+ return __awaiter(this, arguments, void 0, function* (tokenIds, chainId = 1) {
529
529
  const chunkSize = 20;
530
530
  let results = [];
531
531
  let url = `${this.baseUrl}/batch_liveliness/`;
532
532
  let apiKey = this.apiKey;
533
- function processChunks(i = 0, delay = 1000) {
534
- return __awaiter(this, void 0, void 0, function* () {
533
+ function processChunks() {
534
+ return __awaiter(this, arguments, void 0, function* (i = 0, delay = 1000) {
535
535
  if (i < tokenIds.length) {
536
536
  let chunk = tokenIds.slice(i, i + chunkSize);
537
537
  try {
@@ -551,8 +551,8 @@ class EmblemVaultSDK {
551
551
  });
552
552
  }
553
553
  // BTC
554
- sweepVaultUsingPhrase(phrase, satsPerByte = 20, broadcast = false) {
555
- return __awaiter(this, void 0, void 0, function* () {
554
+ sweepVaultUsingPhrase(phrase_1) {
555
+ return __awaiter(this, arguments, void 0, function* (phrase, satsPerByte = 20, broadcast = false) {
556
556
  const { paymentAddress, paymentPublicKey, ordinalsAddress } = yield (0, utils_1.getSatsConnectAddress)();
557
557
  // change this to mainnet
558
558
  if (window.bitcoin) {
package/dist/utils.js CHANGED
@@ -12,7 +12,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.signPSBT = exports.getSatsConnectAddress = exports.decryptKeys = exports.getTorusKeys = exports.COIN_TO_NETWORK = exports.checkContentType = exports.getLegacyContract = exports.getHandlerContract = exports.getQuoteContractObject = exports.genericGuard = exports.templateGuard = exports.generateTemplate = exports.generateImageTemplate = exports.generateAttributeTemplate = exports.fetchData = exports.metadataAllProjects = exports.metadataObj2Arr = exports.evaluateFacts = exports.pad = exports.NFT_DATA = void 0;
15
+ exports.COIN_TO_NETWORK = exports.fetchData = exports.metadataAllProjects = exports.metadataObj2Arr = exports.evaluateFacts = exports.pad = exports.NFT_DATA = void 0;
16
+ exports.generateAttributeTemplate = generateAttributeTemplate;
17
+ exports.generateImageTemplate = generateImageTemplate;
18
+ exports.generateTemplate = generateTemplate;
19
+ exports.templateGuard = templateGuard;
20
+ exports.genericGuard = genericGuard;
21
+ exports.getQuoteContractObject = getQuoteContractObject;
22
+ exports.getHandlerContract = getHandlerContract;
23
+ exports.getLegacyContract = getLegacyContract;
24
+ exports.checkContentType = checkContentType;
25
+ exports.getTorusKeys = getTorusKeys;
26
+ exports.decryptKeys = decryptKeys;
27
+ exports.getSatsConnectAddress = getSatsConnectAddress;
28
+ exports.signPSBT = signPSBT;
16
29
  const crypto_js_1 = __importDefault(require("crypto-js"));
17
30
  const metadata_json_1 = __importDefault(require("./curated/metadata.json"));
18
31
  const darkfarms_metadata_json_1 = __importDefault(require("./curated/darkfarms-metadata.json"));
@@ -68,7 +81,7 @@ const metadataAllProjects = (projects) => projects.reduce((unique, item) => {
68
81
  return unique;
69
82
  }, []);
70
83
  exports.metadataAllProjects = metadataAllProjects;
71
- const fetchData = (url, apiKey, method = 'GET', body = null, headers = null) => __awaiter(void 0, void 0, void 0, function* () {
84
+ const fetchData = (url_1, apiKey_1, ...args_1) => __awaiter(void 0, [url_1, apiKey_1, ...args_1], void 0, function* (url, apiKey, method = 'GET', body = null, headers = null) {
72
85
  const options = {
73
86
  method: method,
74
87
  headers: headers ? Object.assign(Object.assign({}, headers), { 'x-api-key': apiKey }) : { 'x-api-key': apiKey },
@@ -197,7 +210,6 @@ function generateAttributeTemplate(record) {
197
210
  }
198
211
  return template;
199
212
  }
200
- exports.generateAttributeTemplate = generateAttributeTemplate;
201
213
  function generateImageTemplate(record) {
202
214
  let template = {};
203
215
  if (record.imageHandler) {
@@ -219,7 +231,6 @@ function generateImageTemplate(record) {
219
231
  }
220
232
  return template;
221
233
  }
222
- exports.generateImageTemplate = generateImageTemplate;
223
234
  /**
224
235
  * generateTemplate defines rules and utilitites for a given curated
225
236
  * collection. This is used by callers, like emblem.finance website
@@ -532,7 +543,6 @@ function generateTemplate(record) {
532
543
  });
533
544
  return template;
534
545
  }
535
- exports.generateTemplate = generateTemplate;
536
546
  function templateGuard(input) {
537
547
  if (!input)
538
548
  throw new Error(`No template provided`);
@@ -564,14 +574,12 @@ function templateGuard(input) {
564
574
  }
565
575
  }
566
576
  }
567
- exports.templateGuard = templateGuard;
568
577
  function genericGuard(input, type, key) {
569
578
  if (!input)
570
579
  throw new Error(`No ${key} provided`);
571
580
  if (typeof input !== type)
572
581
  throw new Error(`Invalid ${key} provided`);
573
582
  }
574
- exports.genericGuard = genericGuard;
575
583
  function getQuoteContractObject(web3) {
576
584
  return __awaiter(this, void 0, void 0, function* () {
577
585
  let contractAddress = '0xE5dec92911c78069d727a67C85936EDDbc9B02Cf';
@@ -579,7 +587,6 @@ function getQuoteContractObject(web3) {
579
587
  return quoteContract;
580
588
  });
581
589
  }
582
- exports.getQuoteContractObject = getQuoteContractObject;
583
590
  function getHandlerContract(web3) {
584
591
  return __awaiter(this, void 0, void 0, function* () {
585
592
  let contractAddress = '0x23859b51117dbFBcdEf5b757028B18d7759a4460';
@@ -587,7 +594,6 @@ function getHandlerContract(web3) {
587
594
  return handlerContract;
588
595
  });
589
596
  }
590
- exports.getHandlerContract = getHandlerContract;
591
597
  function getLegacyContract(web3) {
592
598
  return __awaiter(this, void 0, void 0, function* () {
593
599
  let contractAddress = '0x82c7a8f707110f5fbb16184a5933e9f78a34c6ab';
@@ -595,14 +601,13 @@ function getLegacyContract(web3) {
595
601
  return handlerContract;
596
602
  });
597
603
  }
598
- exports.getLegacyContract = getLegacyContract;
599
604
  function checkContentType(url) {
600
605
  return new Promise((resolve, reject) => {
601
606
  let returnVal = { valid: false };
602
607
  // Function to make fetch requests
603
608
  function fetchUrl(method) {
604
609
  const controller = new AbortController();
605
- const timeoutId = setTimeout(() => controller.abort(), 3000); // 10 seconds timeout
610
+ const timeoutId = setTimeout(() => controller.abort(), 3000); // 3 seconds timeout (probably need to make this timeout only for HEAD)
606
611
  return fetch(url, { method: method, signal: controller.signal })
607
612
  .then(response => {
608
613
  clearTimeout(timeoutId);
@@ -645,7 +650,6 @@ function checkContentType(url) {
645
650
  });
646
651
  });
647
652
  }
648
- exports.checkContentType = checkContentType;
649
653
  // export function checkContentType(url: string) {
650
654
  // return new Promise((resolve, reject) => {
651
655
  // // Making a HTTP HEAD request to get only the headers
@@ -760,8 +764,8 @@ const mimeToExtensionMap = {
760
764
  "video/vnd.dlna.mpeg-tts": ".ts"
761
765
  // Add more mappings if needed
762
766
  };
763
- function getTorusKeys(verifierId, idToken, cb = null) {
764
- return __awaiter(this, void 0, void 0, function* () {
767
+ function getTorusKeys(verifierId_1, idToken_1) {
768
+ return __awaiter(this, arguments, void 0, function* (verifierId, idToken, cb = null) {
765
769
  const FetchNodeDetails = require("@toruslabs/fetch-node-details").default;
766
770
  const TorusUtils = require("@toruslabs/torus.js").default;
767
771
  const fetchNodeDetails = new FetchNodeDetails();
@@ -771,7 +775,6 @@ function getTorusKeys(verifierId, idToken, cb = null) {
771
775
  return { privateKey: privKey };
772
776
  });
773
777
  }
774
- exports.getTorusKeys = getTorusKeys;
775
778
  function decryptKeys(vaultCiphertextV2, keys, addresses) {
776
779
  return __awaiter(this, void 0, void 0, function* () {
777
780
  try {
@@ -789,7 +792,6 @@ function decryptKeys(vaultCiphertextV2, keys, addresses) {
789
792
  }
790
793
  });
791
794
  }
792
- exports.decryptKeys = decryptKeys;
793
795
  function getSatsConnectAddress() {
794
796
  return __awaiter(this, void 0, void 0, function* () {
795
797
  return new Promise((resolve, reject) => {
@@ -820,9 +822,8 @@ function getSatsConnectAddress() {
820
822
  });
821
823
  });
822
824
  }
823
- exports.getSatsConnectAddress = getSatsConnectAddress;
824
- function signPSBT(psbtBase64, paymentAddress, indexes, broadcast = false) {
825
- return __awaiter(this, void 0, void 0, function* () {
825
+ function signPSBT(psbtBase64_1, paymentAddress_1, indexes_1) {
826
+ return __awaiter(this, arguments, void 0, function* (psbtBase64, paymentAddress, indexes, broadcast = false) {
826
827
  return new Promise((resolve, reject) => {
827
828
  (0, sats_connect_1.signTransaction)({
828
829
  payload: {
@@ -853,4 +854,3 @@ function signPSBT(psbtBase64, paymentAddress, indexes, broadcast = false) {
853
854
  });
854
855
  });
855
856
  }
856
- exports.signPSBT = signPSBT;