@audius/sdk 1.0.11 → 1.0.12

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.
@@ -514,9 +514,9 @@ if (typeof window !== 'undefined' && window && window.Web3) {
514
514
  var LibsWeb3 = Web3;
515
515
 
516
516
  var name = "@audius/sdk";
517
- var version = "1.0.11";
517
+ var version = "1.0.12";
518
518
  var audius = {
519
- releaseSHA: "5f2f952b49defef75aab2e13ce086178edf8f66c"
519
+ releaseSHA: "78388a5771c4a3dca52d6805824b8710b17bb280"
520
520
  };
521
521
  var description = "";
522
522
  var main = "dist/index.cjs.js";
@@ -2368,6 +2368,16 @@ var getPermitTypehash = function getPermitTypehash() {
2368
2368
 
2369
2369
  return _permitTypehash;
2370
2370
  };
2371
+
2372
+ var _transferTokensTypehash = null;
2373
+
2374
+ var getTransferTokensTypeHash = function getTransferTokensTypeHash() {
2375
+ if (!_transferTokensTypehash) {
2376
+ _transferTokensTypehash = Utils.keccak256('TransferTokens(address from,uint256 amount,uint16 recipientChain,bytes32 recipient,uint256 artbiterFee,uint32 nonce,uint256 deadline)');
2377
+ }
2378
+
2379
+ return _transferTokensTypehash;
2380
+ }; // Returns the EIP712 hash which should be signed by the user
2371
2381
  // in order to make a call to `permit`
2372
2382
 
2373
2383
 
@@ -2377,6 +2387,14 @@ function getPermitDigest(web3, name, address, chainId, approve, nonce, deadline)
2377
2387
  var encoded = pack(['bytes1', 'bytes1', 'bytes32', 'bytes32'], ['0x19', '0x01', DOMAIN_SEPARATOR, Utils.keccak256(innerEncoded)]);
2378
2388
  return Utils.keccak256(encoded);
2379
2389
  } // Returns the EIP712 hash which should be signed by the user
2390
+ // in order to make a call to `transferTokens`
2391
+
2392
+ function getTransferTokensDigest(web3, name, address, chainId, transferTokens, nonce, deadline) {
2393
+ var DOMAIN_SEPARATOR = getDomainSeparator(web3, name, address, chainId);
2394
+ var innerEncoded = web3.eth.abi.encodeParameters(['bytes32', 'address', 'uint256', 'uint16', 'bytes32', 'uint256', 'uint32', 'uint256'], [getTransferTokensTypeHash(), transferTokens.from, transferTokens.amount, transferTokens.recipientChain, transferTokens.recipient, transferTokens.arbiterFee, nonce, deadline]);
2395
+ var encoded = pack(['bytes1', 'bytes1', 'bytes32', 'bytes32'], ['0x19', '0x01', DOMAIN_SEPARATOR, Utils.keccak256(innerEncoded)]);
2396
+ return Utils.keccak256(encoded);
2397
+ } // Gets the EIP712 domain separator
2380
2398
 
2381
2399
  function getDomainSeparator(web3, name, contractAddress, chainId) {
2382
2400
  var encoded = web3.eth.abi.encodeParameters(['bytes32', 'bytes32', 'bytes32', 'uint256', 'address'], [Utils.keccak256('EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)'), Utils.keccak256(name), Utils.keccak256('1'), chainId, contractAddress]);
@@ -48947,6 +48965,148 @@ var EntityManager = /*#__PURE__*/function (_Base) {
48947
48965
  return EntityManager;
48948
48966
  }(Base);
48949
48967
 
48968
+ /** Singleton state-manager for audius proxy wormhole interaction */
48969
+
48970
+ var ProxyWormhole = /*#__PURE__*/function () {
48971
+ function ProxyWormhole(hedgehog, ethWeb3Manager, ethContracts, identityService, solanaWeb3Manager) {
48972
+ _classCallCheck(this, ProxyWormhole);
48973
+
48974
+ // Wormhole service dependecies
48975
+ this.hedgehog = hedgehog;
48976
+ this.ethWeb3Manager = ethWeb3Manager;
48977
+ this.ethContracts = ethContracts;
48978
+ this.identityService = identityService;
48979
+ this.solanaWeb3Manager = solanaWeb3Manager;
48980
+ }
48981
+ /**
48982
+ * Locks assets owned by `fromAccount` into the Solana wormhole with a target
48983
+ * solanaAccount destination via the provided relayer wallet.
48984
+ */
48985
+
48986
+
48987
+ _createClass(ProxyWormhole, [{
48988
+ key: "_getTransferTokensToEthWormholeParams",
48989
+ value: function () {
48990
+ var _getTransferTokensToEthWormholeParams2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(fromAccount, amount, solanaAccount) {
48991
+ var _this$hedgehog$getWal;
48992
+
48993
+ var web3, wormholeClientAddress, chainId, currentBlockNumber, currentBlock, deadline, solanaB58, recipient, nonce, arbiterFee, digest, privateKey, signedDigest;
48994
+ return regeneratorRuntime.wrap(function _callee$(_context) {
48995
+ while (1) {
48996
+ switch (_context.prev = _context.next) {
48997
+ case 0:
48998
+ if (this.hedgehog) {
48999
+ _context.next = 2;
49000
+ break;
49001
+ }
49002
+
49003
+ throw new Error('Hedgehog required for _getTransferTokensToEthWormholeParams');
49004
+
49005
+ case 2:
49006
+ web3 = this.ethWeb3Manager.getWeb3();
49007
+ wormholeClientAddress = this.ethContracts.WormholeClient.contractAddress;
49008
+ _context.next = 6;
49009
+ return web3.eth.getChainId();
49010
+
49011
+ case 6:
49012
+ chainId = _context.sent;
49013
+ _context.next = 9;
49014
+ return web3.eth.getBlockNumber();
49015
+
49016
+ case 9:
49017
+ currentBlockNumber = _context.sent;
49018
+ _context.next = 12;
49019
+ return web3.eth.getBlock(currentBlockNumber);
49020
+
49021
+ case 12:
49022
+ currentBlock = _context.sent;
49023
+ // 1 hour, sufficiently far in future
49024
+ deadline = currentBlock.timestamp + 60 * 60 * 1;
49025
+ solanaB58 = bs58.decode(solanaAccount).toString('hex');
49026
+ recipient = toBuffer("0x".concat(solanaB58));
49027
+ _context.next = 18;
49028
+ return this.ethContracts.WormholeClient.nonces(fromAccount);
49029
+
49030
+ case 18:
49031
+ nonce = _context.sent;
49032
+ arbiterFee = Utils.toBN('0');
49033
+ digest = getTransferTokensDigest(web3, 'AudiusWormholeClient', wormholeClientAddress, chainId, {
49034
+ from: fromAccount,
49035
+ amount: amount,
49036
+ recipientChain: chainId,
49037
+ recipient: recipient,
49038
+ arbiterFee: arbiterFee
49039
+ }, nonce, deadline);
49040
+ privateKey = (_this$hedgehog$getWal = this.hedgehog.getWallet()) === null || _this$hedgehog$getWal === void 0 ? void 0 : _this$hedgehog$getWal.getPrivateKey();
49041
+ signedDigest = sign(digest, privateKey);
49042
+ return _context.abrupt("return", {
49043
+ chainId: chainId,
49044
+ deadline: deadline,
49045
+ recipient: recipient,
49046
+ arbiterFee: arbiterFee,
49047
+ signedDigest: signedDigest
49048
+ });
49049
+
49050
+ case 24:
49051
+ case "end":
49052
+ return _context.stop();
49053
+ }
49054
+ }
49055
+ }, _callee, this);
49056
+ }));
49057
+
49058
+ function _getTransferTokensToEthWormholeParams(_x, _x2, _x3) {
49059
+ return _getTransferTokensToEthWormholeParams2.apply(this, arguments);
49060
+ }
49061
+
49062
+ return _getTransferTokensToEthWormholeParams;
49063
+ }()
49064
+ }, {
49065
+ key: "getTransferTokensToEthWormholeMethod",
49066
+ value: function () {
49067
+ var _getTransferTokensToEthWormholeMethod = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(fromAccount, amount, solanaAccount) {
49068
+ var _yield$this$_getTrans, chainId, deadline, recipient, arbiterFee, signedDigest, method;
49069
+
49070
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
49071
+ while (1) {
49072
+ switch (_context2.prev = _context2.next) {
49073
+ case 0:
49074
+ _context2.next = 2;
49075
+ return this._getTransferTokensToEthWormholeParams(fromAccount, amount, solanaAccount);
49076
+
49077
+ case 2:
49078
+ _yield$this$_getTrans = _context2.sent;
49079
+ chainId = _yield$this$_getTrans.chainId;
49080
+ deadline = _yield$this$_getTrans.deadline;
49081
+ recipient = _yield$this$_getTrans.recipient;
49082
+ arbiterFee = _yield$this$_getTrans.arbiterFee;
49083
+ signedDigest = _yield$this$_getTrans.signedDigest;
49084
+ _context2.next = 10;
49085
+ return this.ethContracts.WormholeClient.WormholeContract.methods.transferTokens(fromAccount, amount, chainId, recipient, arbiterFee, deadline, signedDigest.v, signedDigest.r, signedDigest.s);
49086
+
49087
+ case 10:
49088
+ method = _context2.sent;
49089
+ return _context2.abrupt("return", method);
49090
+
49091
+ case 12:
49092
+ case "end":
49093
+ return _context2.stop();
49094
+ }
49095
+ }
49096
+ }, _callee2, this);
49097
+ }));
49098
+
49099
+ function getTransferTokensToEthWormholeMethod(_x4, _x5, _x6) {
49100
+ return _getTransferTokensToEthWormholeMethod.apply(this, arguments);
49101
+ }
49102
+
49103
+ return getTransferTokensToEthWormholeMethod;
49104
+ }()
49105
+ }]);
49106
+
49107
+ return ProxyWormhole;
49108
+ }();
49109
+
48950
49110
  /**
48951
49111
  * Add secondary creator nodes for a user if they don't have any
48952
49112
  * Goal: Make it so users always have a replica set
@@ -49309,6 +49469,7 @@ var AudiusLibs = /*#__PURE__*/function () {
49309
49469
  discoveryProviderConfig = _ref.discoveryProviderConfig,
49310
49470
  creatorNodeConfig = _ref.creatorNodeConfig,
49311
49471
  comstockConfig = _ref.comstockConfig,
49472
+ wormholeConfig = _ref.wormholeConfig,
49312
49473
  captchaConfig = _ref.captchaConfig,
49313
49474
  hedgehogConfig = _ref.hedgehogConfig,
49314
49475
  isServer = _ref.isServer,
@@ -49334,6 +49495,7 @@ var AudiusLibs = /*#__PURE__*/function () {
49334
49495
  this.creatorNodeConfig = creatorNodeConfig;
49335
49496
  this.discoveryProviderConfig = discoveryProviderConfig;
49336
49497
  this.comstockConfig = comstockConfig;
49498
+ this.wormholeConfig = wormholeConfig;
49337
49499
  this.captchaConfig = captchaConfig;
49338
49500
  this.hedgehogConfig = hedgehogConfig;
49339
49501
  this.isServer = isServer;
@@ -49348,10 +49510,11 @@ var AudiusLibs = /*#__PURE__*/function () {
49348
49510
  this.ethContracts = null;
49349
49511
  this.web3Manager = null;
49350
49512
  this.solanaWeb3Manager = null;
49513
+ this.wormholeClient = null;
49351
49514
  this.contracts = null;
49352
49515
  this.creatorNode = null;
49353
49516
  this.captcha = null;
49354
- this.comstock = null; // // API
49517
+ this.comstock = null; // API
49355
49518
 
49356
49519
  this.ServiceProvider = null;
49357
49520
  this.Account = null;
@@ -49501,8 +49664,14 @@ var AudiusLibs = /*#__PURE__*/function () {
49501
49664
  return Promise.all(contractsToInit);
49502
49665
 
49503
49666
  case 30:
49667
+ if (this.wormholeConfig && this.ethWeb3Manager && this.ethContracts && this.solanaWeb3Manager) {
49668
+ this.wormholeClient = new ProxyWormhole(this.hedgehog, this.ethWeb3Manager, this.ethContracts, this.identityService, this.solanaWeb3Manager);
49669
+ }
49670
+ /** Discovery Provider */
49671
+
49672
+
49504
49673
  if (!this.discoveryProviderConfig) {
49505
- _context.next = 34;
49674
+ _context.next = 35;
49506
49675
  break;
49507
49676
  }
49508
49677
 
@@ -49512,29 +49681,29 @@ var AudiusLibs = /*#__PURE__*/function () {
49512
49681
  web3Manager: this.web3Manager,
49513
49682
  localStorage: this.localStorage
49514
49683
  }, this.discoveryProviderConfig));
49515
- _context.next = 34;
49684
+ _context.next = 35;
49516
49685
  return this.discoveryProvider.init();
49517
49686
 
49518
- case 34:
49687
+ case 35:
49519
49688
  if (!this.creatorNodeConfig) {
49520
- _context.next = 40;
49689
+ _context.next = 41;
49521
49690
  break;
49522
49691
  }
49523
49692
 
49524
49693
  currentUser = this.userStateManager.getCurrentUser();
49525
49694
  creatorNodeEndpoint = currentUser ? (_CreatorNode$getPrima = CreatorNode.getPrimary(currentUser.creator_node_endpoint)) !== null && _CreatorNode$getPrima !== void 0 ? _CreatorNode$getPrima : this.creatorNodeConfig.fallbackUrl : this.creatorNodeConfig.fallbackUrl;
49526
49695
  this.creatorNode = new CreatorNode(this.web3Manager, creatorNodeEndpoint, this.isServer, this.userStateManager, this.creatorNodeConfig.lazyConnect, this.schemas, this.creatorNodeConfig.passList, this.creatorNodeConfig.blockList, this.creatorNodeConfig.monitoringCallbacks, this.creatorNodeConfig.writeQuorumEnabled);
49527
- _context.next = 40;
49696
+ _context.next = 41;
49528
49697
  return this.creatorNode.init();
49529
49698
 
49530
- case 40:
49699
+ case 41:
49531
49700
  /** Comstock */
49532
49701
  if (this.comstockConfig) {
49533
49702
  this.comstock = new Comstock(this.comstockConfig.url);
49534
49703
  } // Initialize apis
49535
49704
 
49536
49705
 
49537
- services = [this.userStateManager, this.identityService, this.hedgehog, this.discoveryProvider, this.web3Manager, this.contracts, this.ethWeb3Manager, this.ethContracts, this.solanaWeb3Manager, null, null, this.creatorNode, this.comstock, this.captcha, this.isServer, this.logger];
49706
+ services = [this.userStateManager, this.identityService, this.hedgehog, this.discoveryProvider, this.web3Manager, this.contracts, this.ethWeb3Manager, this.ethContracts, this.solanaWeb3Manager, null, this.wormholeClient, this.creatorNode, this.comstock, this.captcha, this.isServer, this.logger];
49538
49707
  this.ServiceProvider = _construct(ServiceProvider, services);
49539
49708
  this.User = _construct(Users, [this.ServiceProvider, this.preferHigherPatchForPrimary, this.preferHigherPatchForSecondaries].concat(services));
49540
49709
  this.Account = _construct(Account, [this.User].concat(services));
@@ -49545,7 +49714,7 @@ var AudiusLibs = /*#__PURE__*/function () {
49545
49714
  this.Reactions = _construct(Reactions, services);
49546
49715
  this.EntityManager = _construct(EntityManager, services);
49547
49716
 
49548
- case 51:
49717
+ case 52:
49549
49718
  case "end":
49550
49719
  return _context.stop();
49551
49720
  }
@@ -49721,8 +49890,7 @@ var AudiusLibs = /*#__PURE__*/function () {
49721
49890
  };
49722
49891
  }
49723
49892
  /**
49724
- * Configures wormhole
49725
- * This is a stubbed version for native
49893
+ * Configures proxy-only wormhole
49726
49894
  */
49727
49895
 
49728
49896
  }, {