"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.createSigningClient = exports.SigningStargateClient = void 0;
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _amino = require("@cosmjs/amino");
var _encoding = require("@cosmjs/encoding");
var _math = require("@cosmjs/math");
var _protoSigning = require("@cosmjs/proto-signing");
var _stargate = require("@cosmjs/stargate");
var _tendermintRpc = require("@cosmjs/tendermint-rpc");
var _utils = require("@cosmjs/utils");
var _signing = require("cosmjs-types/cosmos/tx/signing/v1beta1/signing");
var _tx = require("cosmjs-types/cosmos/tx/v1beta1/tx");
var _customRegistries = require("./customRegistries");
var _store = require("./store");
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
function createDefaultRegistry() {
  return new _protoSigning.Registry(_customRegistries.defaultRegistryTypes);
}
var SigningStargateClient = exports.SigningStargateClient = /*#__PURE__*/function (_StargateClient) {
  function SigningStargateClient(cometClient, signer, options) {
    var _this;
    var ignoreGetSequence = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
    var localStoreFunctions = arguments.length > 4 ? arguments[4] : undefined;
    (0, _classCallCheck2["default"])(this, SigningStargateClient);
    _this = _callSuper(this, SigningStargateClient, [cometClient, options]);
    (0, _defineProperty2["default"])(_this, "registry", void 0);
    (0, _defineProperty2["default"])(_this, "broadcastTimeoutMs", void 0);
    (0, _defineProperty2["default"])(_this, "broadcastPollIntervalMs", void 0);
    (0, _defineProperty2["default"])(_this, "signer", void 0);
    (0, _defineProperty2["default"])(_this, "aminoTypes", void 0);
    (0, _defineProperty2["default"])(_this, "gasPrice", void 0);
    (0, _defineProperty2["default"])(_this, "ignoreGetSequence", void 0);
    // Starting with Cosmos SDK 0.47, we see many cases in which 1.3 is not enough anymore
    // E.g. https://github.com/cosmos/cosmos-sdk/issues/16020
    (0, _defineProperty2["default"])(_this, "defaultGasMultiplier", 1.4);
    // sequence store functions for consecutive transactions
    (0, _defineProperty2["default"])(_this, "localStoreFunctions", void 0);
    // public cometClient for convenience
    (0, _defineProperty2["default"])(_this, "publicCometClient", void 0);
    var _options$registry = options.registry,
      registry = _options$registry === void 0 ? createDefaultRegistry() : _options$registry,
      aminoTypes = options.aminoTypes;
    _this.publicCometClient = cometClient;
    _this.registry = registry;
    _this.aminoTypes = aminoTypes;
    _this.signer = signer;
    _this.broadcastTimeoutMs = options.broadcastTimeoutMs;
    _this.broadcastPollIntervalMs = options.broadcastPollIntervalMs;
    _this.gasPrice = options.gasPrice;
    _this.ignoreGetSequence = ignoreGetSequence;
    _this.localStoreFunctions = localStoreFunctions;
    return _this;
  }
  (0, _inherits2["default"])(SigningStargateClient, _StargateClient);
  return (0, _createClass2["default"])(SigningStargateClient, [{
    key: "simulate",
    value: function () {
      var _simulate = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator().m(function _callee(signerAddress, messages, memo, txBodyBytes, explicitSignerData) {
        var _this2 = this;
        var anyMsgs, accountFromSigner, pubkey, sequence, seqResult, _yield$this$forceGetQ, gasInfo;
        return _regenerator().w(function (_context) {
          while (1) switch (_context.n) {
            case 0:
              // const txBody = txBodyBytes ? this.registry.decodeTxBody(txBodyBytes) : null;
              // console.log("txBody", txBody);
              anyMsgs = messages.map(function (m) {
                return _this2.registry.encodeAsAny(m);
              });
              _context.n = 1;
              return this.signer.getAccounts();
            case 1:
              accountFromSigner = _context.v.find(function (account) {
                return account.address === signerAddress;
              });
              if (accountFromSigner) {
                _context.n = 2;
                break;
              }
              throw new Error("Failed to retrieve account from signer");
            case 2:
              pubkey = {
                type: accountFromSigner.algo === "secp256k1" ? _amino.pubkeyType.secp256k1 : _amino.pubkeyType.ed25519,
                value: (0, _encoding.toBase64)(accountFromSigner.pubkey)
              }; // Use explicit sequence if provided, otherwise fetch from chain
              if (!((explicitSignerData === null || explicitSignerData === void 0 ? void 0 : explicitSignerData.sequence) !== undefined)) {
                _context.n = 3;
                break;
              }
              sequence = explicitSignerData.sequence;
              _context.n = 6;
              break;
            case 3:
              if (!this.ignoreGetSequence) {
                _context.n = 4;
                break;
              }
              sequence = 0;
              _context.n = 6;
              break;
            case 4:
              _context.n = 5;
              return this.getSequence(signerAddress);
            case 5:
              seqResult = _context.v;
              sequence = seqResult.sequence;
            case 6:
              _context.n = 7;
              return this.forceGetQueryClient().tx.simulate(anyMsgs, memo, pubkey, sequence);
            case 7:
              _yield$this$forceGetQ = _context.v;
              gasInfo = _yield$this$forceGetQ.gasInfo;
              (0, _utils.assertDefined)(gasInfo);
              return _context.a(2, _math.Uint53.fromString(gasInfo.gasUsed.toString()).toNumber());
          }
        }, _callee, this);
      }));
      function simulate(_x, _x2, _x3, _x4, _x5) {
        return _simulate.apply(this, arguments);
      }
      return simulate;
    }()
  }, {
    key: "signAndBroadcast",
    value: function () {
      var _signAndBroadcast = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator().m(function _callee2(signerAddress, messages, fee) {
        var memo,
          explicitSignerData,
          txBodyBytes,
          timeoutHeight,
          signerData,
          usedFee,
          txRaw,
          txBytes,
          _args2 = arguments;
        return _regenerator().w(function (_context2) {
          while (1) switch (_context2.n) {
            case 0:
              memo = _args2.length > 3 && _args2[3] !== undefined ? _args2[3] : "";
              explicitSignerData = _args2.length > 4 ? _args2[4] : undefined;
              txBodyBytes = _args2.length > 5 ? _args2[5] : undefined;
              timeoutHeight = _args2.length > 6 ? _args2[6] : undefined;
              // Get signer data FIRST before getUsedFee, so simulate uses correct sequence
              signerData = explicitSignerData;
              if (!(!signerData && !this.ignoreGetSequence && this.localStoreFunctions)) {
                _context2.n = 2;
                break;
              }
              _context2.n = 1;
              return (0, _store.getSignerData)(this, this.signer, this.localStoreFunctions);
            case 1:
              signerData = _context2.v;
            case 2:
              _context2.n = 3;
              return this.getUsedFee(signerAddress, messages, fee, memo, txBodyBytes, signerData);
            case 3:
              usedFee = _context2.v;
              _context2.n = 4;
              return this.sign(signerAddress, messages, usedFee, memo, signerData, txBodyBytes, timeoutHeight);
            case 4:
              txRaw = _context2.v;
              txBytes = _tx.TxRaw.encode(txRaw).finish();
              return _context2.a(2, this.broadcastTx(txBytes, this.broadcastTimeoutMs, this.broadcastPollIntervalMs));
          }
        }, _callee2, this);
      }));
      function signAndBroadcast(_x6, _x7, _x8) {
        return _signAndBroadcast.apply(this, arguments);
      }
      return signAndBroadcast;
    }()
    /**
     * This method is useful if you want to send a transaction in broadcast,
     * without waiting for it to be placed inside a block, because for example
     * I would like to receive the hash to later track the transaction with another tool.
     * @returns Returns the hash of the transaction
     */
  }, {
    key: "signAndBroadcastSync",
    value: (function () {
      var _signAndBroadcastSync = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator().m(function _callee3(signerAddress, messages, fee) {
        var memo,
          explicitSignerData,
          txBodyBytes,
          timeoutHeight,
          signerData,
          usedFee,
          txRaw,
          txBytes,
          _args3 = arguments;
        return _regenerator().w(function (_context3) {
          while (1) switch (_context3.n) {
            case 0:
              memo = _args3.length > 3 && _args3[3] !== undefined ? _args3[3] : "";
              explicitSignerData = _args3.length > 4 ? _args3[4] : undefined;
              txBodyBytes = _args3.length > 5 ? _args3[5] : undefined;
              timeoutHeight = _args3.length > 6 ? _args3[6] : undefined;
              // Get signer data FIRST before getUsedFee, so simulate uses correct sequence
              signerData = explicitSignerData;
              if (!(!signerData && !this.ignoreGetSequence && this.localStoreFunctions)) {
                _context3.n = 2;
                break;
              }
              _context3.n = 1;
              return (0, _store.getSignerData)(this, this.signer, this.localStoreFunctions);
            case 1:
              signerData = _context3.v;
            case 2:
              _context3.n = 3;
              return this.getUsedFee(signerAddress, messages, fee, memo, txBodyBytes, signerData);
            case 3:
              usedFee = _context3.v;
              _context3.n = 4;
              return this.sign(signerAddress, messages, usedFee, memo, signerData, txBodyBytes, timeoutHeight);
            case 4:
              txRaw = _context3.v;
              txBytes = _tx.TxRaw.encode(txRaw).finish();
              return _context3.a(2, this.broadcastTxSync(txBytes));
          }
        }, _callee3, this);
      }));
      function signAndBroadcastSync(_x9, _x0, _x1) {
        return _signAndBroadcastSync.apply(this, arguments);
      }
      return signAndBroadcastSync;
    }()
    /**
     * Gets account number and sequence from the API, creates a sign doc,
     * creates a single signature and assembles the signed transaction.
     *
     * The sign mode (SIGN_MODE_DIRECT or SIGN_MODE_LEGACY_AMINO_JSON) is determined by this client's signer.
     *
     * You can pass signer data (account number, sequence and chain ID) explicitly instead of querying them
     * from the chain. This is needed when signing for a multisig account, but it also allows for offline signing
     * (See the SigningStargateClient.offline constructor).
     */
    )
  }, {
    key: "sign",
    value: (function () {
      var _sign = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator().m(function _callee4(signerAddress, messages, fee, memo, explicitSignerData, txBodyBytes, timeoutHeight) {
        var signerData, _ref, accountNumber, sequence, chainId, _t;
        return _regenerator().w(function (_context4) {
          while (1) switch (_context4.n) {
            case 0:
              if (!explicitSignerData) {
                _context4.n = 1;
                break;
              }
              signerData = explicitSignerData;
              _context4.n = 8;
              break;
            case 1:
              if (!(!this.ignoreGetSequence && this.localStoreFunctions)) {
                _context4.n = 3;
                break;
              }
              _context4.n = 2;
              return (0, _store.getSignerData)(this, this.signer, this.localStoreFunctions);
            case 2:
              signerData = _context4.v;
              _context4.n = 8;
              break;
            case 3:
              if (!this.ignoreGetSequence) {
                _context4.n = 4;
                break;
              }
              _t = {
                sequence: 0,
                accountNumber: 0
              };
              _context4.n = 6;
              break;
            case 4:
              _context4.n = 5;
              return this.getSequence(signerAddress);
            case 5:
              _t = _context4.v;
            case 6:
              _ref = _t;
              accountNumber = _ref.accountNumber;
              sequence = _ref.sequence;
              _context4.n = 7;
              return this.getChainId();
            case 7:
              chainId = _context4.v;
              signerData = {
                accountNumber: accountNumber,
                sequence: sequence,
                chainId: chainId
              };
            case 8:
              return _context4.a(2, (0, _protoSigning.isOfflineDirectSigner)(this.signer) ? this.signDirect(signerAddress, messages, fee, memo, signerData, txBodyBytes, timeoutHeight) : this.signAmino(signerAddress, messages, fee, memo, signerData, timeoutHeight));
          }
        }, _callee4, this);
      }));
      function sign(_x10, _x11, _x12, _x13, _x14, _x15, _x16) {
        return _sign.apply(this, arguments);
      }
      return sign;
    }())
  }, {
    key: "getUsedFee",
    value: function () {
      var _getUsedFee = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator().m(function _callee5(signerAddress, messages, fee) {
        var memo,
          txBodyBytes,
          explicitSignerData,
          gasEstimation,
          multiplier,
          _args5 = arguments;
        return _regenerator().w(function (_context5) {
          while (1) switch (_context5.n) {
            case 0:
              memo = _args5.length > 3 && _args5[3] !== undefined ? _args5[3] : "";
              txBodyBytes = _args5.length > 4 ? _args5[4] : undefined;
              explicitSignerData = _args5.length > 5 ? _args5[5] : undefined;
              if (!(fee == "auto" || typeof fee === "number")) {
                _context5.n = 2;
                break;
              }
              (0, _utils.assertDefined)(this.gasPrice, "Gas price must be set in the client options when auto gas is used.");
              _context5.n = 1;
              return this.simulate(signerAddress, messages, memo, txBodyBytes, explicitSignerData);
            case 1:
              gasEstimation = _context5.v;
              multiplier = typeof fee === "number" ? fee : this.defaultGasMultiplier;
              return _context5.a(2, (0, _stargate.calculateFee)(Math.round(gasEstimation * multiplier), this.gasPrice));
            case 2:
              return _context5.a(2, fee);
            case 3:
              return _context5.a(2);
          }
        }, _callee5, this);
      }));
      function getUsedFee(_x17, _x18, _x19) {
        return _getUsedFee.apply(this, arguments);
      }
      return getUsedFee;
    }()
  }, {
    key: "signAmino",
    value: function () {
      var _signAmino = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator().m(function _callee6(signerAddress, messages, fee, memo, _ref2, timeoutHeight) {
        var _this3 = this;
        var accountNumber, sequence, chainId, accountFromSigner, pubkey, signMode, msgs, signDoc, _yield$this$signer$si, signature, signed, signedTxBody, signedTxBodyEncodeObject, signedTxBodyBytes, signedGasLimit, signedSequence, signedAuthInfoBytes;
        return _regenerator().w(function (_context6) {
          while (1) switch (_context6.n) {
            case 0:
              accountNumber = _ref2.accountNumber, sequence = _ref2.sequence, chainId = _ref2.chainId;
              (0, _utils.assert)(!(0, _protoSigning.isOfflineDirectSigner)(this.signer));
              _context6.n = 1;
              return this.signer.getAccounts();
            case 1:
              accountFromSigner = _context6.v.find(function (account) {
                return account.address === signerAddress;
              });
              if (accountFromSigner) {
                _context6.n = 2;
                break;
              }
              throw new Error("Failed to retrieve account from signer");
            case 2:
              pubkey = (0, _protoSigning.encodePubkey)({
                type: accountFromSigner.algo === "secp256k1" ? _amino.pubkeyType.secp256k1 : _amino.pubkeyType.ed25519,
                value: (0, _encoding.toBase64)(accountFromSigner.pubkey)
              });
              signMode = _signing.SignMode.SIGN_MODE_LEGACY_AMINO_JSON;
              msgs = messages.map(function (msg) {
                return _this3.aminoTypes.toAmino(msg);
              });
              signDoc = (0, _amino.makeSignDoc)(msgs, fee, chainId, memo, accountNumber, sequence, timeoutHeight);
              _context6.n = 3;
              return this.signer.signAmino(signerAddress, signDoc);
            case 3:
              _yield$this$signer$si = _context6.v;
              signature = _yield$this$signer$si.signature;
              signed = _yield$this$signer$si.signed;
              signedTxBody = {
                // messages: messages,
                messages: signed.msgs.map(function (msg) {
                  return _this3.aminoTypes.fromAmino(msg);
                }),
                memo: signed.memo,
                timeoutHeight: timeoutHeight
              };
              signedTxBodyEncodeObject = {
                typeUrl: "/cosmos.tx.v1beta1.TxBody",
                value: signedTxBody
              };
              signedTxBodyBytes = this.registry.encode(signedTxBodyEncodeObject);
              signedGasLimit = _math.Int53.fromString(signed.fee.gas).toNumber();
              signedSequence = _math.Int53.fromString(signed.sequence).toNumber();
              signedAuthInfoBytes = (0, _protoSigning.makeAuthInfoBytes)([{
                pubkey: pubkey,
                sequence: signedSequence
              }], signed.fee.amount, signedGasLimit, signed.fee.granter, signed.fee.payer, signMode);
              return _context6.a(2, _tx.TxRaw.fromPartial({
                bodyBytes: signedTxBodyBytes,
                authInfoBytes: signedAuthInfoBytes,
                signatures: [(0, _encoding.fromBase64)(signature.signature)]
              }));
          }
        }, _callee6, this);
      }));
      function signAmino(_x20, _x21, _x22, _x23, _x24, _x25) {
        return _signAmino.apply(this, arguments);
      }
      return signAmino;
    }()
  }, {
    key: "signDirect",
    value: function () {
      var _signDirect = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator().m(function _callee7(signerAddress, messages, fee, memo, _ref3, txBodyBytes, timeoutHeight) {
        var accountNumber, sequence, chainId, accountFromSigner, pubkey, txBodyBytes1, gasLimit, authInfoBytes, signDoc, _yield$this$signer$si2, signature, signed;
        return _regenerator().w(function (_context7) {
          while (1) switch (_context7.n) {
            case 0:
              accountNumber = _ref3.accountNumber, sequence = _ref3.sequence, chainId = _ref3.chainId;
              (0, _utils.assert)((0, _protoSigning.isOfflineDirectSigner)(this.signer));
              _context7.n = 1;
              return this.signer.getAccounts();
            case 1:
              accountFromSigner = _context7.v.find(function (account) {
                return account.address === signerAddress;
              });
              if (accountFromSigner) {
                _context7.n = 2;
                break;
              }
              throw new Error("Failed to retrieve account from signer");
            case 2:
              pubkey = (0, _protoSigning.encodePubkey)({
                type: accountFromSigner.algo === "secp256k1" ? _amino.pubkeyType.secp256k1 : _amino.pubkeyType.ed25519,
                value: (0, _encoding.toBase64)(accountFromSigner.pubkey)
              });
              txBodyBytes1 = txBodyBytes || this.registry.encodeTxBody({
                messages: messages,
                memo: memo,
                timeoutHeight: timeoutHeight
              });
              gasLimit = _math.Int53.fromString(fee.gas).toNumber();
              authInfoBytes = (0, _protoSigning.makeAuthInfoBytes)([{
                pubkey: pubkey,
                sequence: sequence
              }], fee.amount, gasLimit, fee.granter, fee.payer);
              signDoc = (0, _protoSigning.makeSignDoc)(txBodyBytes1, authInfoBytes, chainId, accountNumber);
              _context7.n = 3;
              return this.signer.signDirect(signerAddress, signDoc);
            case 3:
              _yield$this$signer$si2 = _context7.v;
              signature = _yield$this$signer$si2.signature;
              signed = _yield$this$signer$si2.signed;
              return _context7.a(2, _tx.TxRaw.fromPartial({
                bodyBytes: signed.bodyBytes,
                authInfoBytes: signed.authInfoBytes,
                signatures: [(0, _encoding.fromBase64)(signature.signature)]
              }));
          }
        }, _callee7, this);
      }));
      function signDirect(_x26, _x27, _x28, _x29, _x30, _x31, _x32) {
        return _signDirect.apply(this, arguments);
      }
      return signDirect;
    }()
  }], [{
    key: "connectWithSigner",
    value: function () {
      var _connectWithSigner = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator().m(function _callee8(endpoint, signer) {
        var options,
          ignoreGetSequence,
          localStoreFunctions,
          cometClient,
          _args8 = arguments;
        return _regenerator().w(function (_context8) {
          while (1) switch (_context8.n) {
            case 0:
              options = _args8.length > 2 && _args8[2] !== undefined ? _args8[2] : {};
              ignoreGetSequence = _args8.length > 3 ? _args8[3] : undefined;
              localStoreFunctions = _args8.length > 4 ? _args8[4] : undefined;
              _context8.n = 1;
              return (0, _tendermintRpc.connectComet)(endpoint);
            case 1:
              cometClient = _context8.v;
              return _context8.a(2, new SigningStargateClient(cometClient, signer, options, ignoreGetSequence, localStoreFunctions));
          }
        }, _callee8);
      }));
      function connectWithSigner(_x33, _x34) {
        return _connectWithSigner.apply(this, arguments);
      }
      return connectWithSigner;
    }()
    /**
     * Creates an instance from a manually created Comet client.
     * Use this to use `Comet38Client` or `Tendermint37Client` instead of `Tendermint34Client`.
     */
  }, {
    key: "createWithSigner",
    value: (function () {
      var _createWithSigner = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator().m(function _callee9(cometClient, signer) {
        var options,
          _args9 = arguments;
        return _regenerator().w(function (_context9) {
          while (1) switch (_context9.n) {
            case 0:
              options = _args9.length > 2 && _args9[2] !== undefined ? _args9[2] : {};
              return _context9.a(2, new SigningStargateClient(cometClient, signer, options));
          }
        }, _callee9);
      }));
      function createWithSigner(_x35, _x36) {
        return _createWithSigner.apply(this, arguments);
      }
      return createWithSigner;
    }()
    /**
     * Creates a client in offline mode.
     *
     * This should only be used in niche cases where you know exactly what you're doing,
     * e.g. when building an offline signing application.
     *
     * When you try to use online functionality with such a signer, an
     * exception will be raised.
     */
    )
  }, {
    key: "offline",
    value: (function () {
      var _offline = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator().m(function _callee0(signer) {
        var options,
          ignoreGetSequence,
          localStoreFunctions,
          _args0 = arguments;
        return _regenerator().w(function (_context0) {
          while (1) switch (_context0.n) {
            case 0:
              options = _args0.length > 1 && _args0[1] !== undefined ? _args0[1] : {};
              ignoreGetSequence = _args0.length > 2 ? _args0[2] : undefined;
              localStoreFunctions = _args0.length > 3 ? _args0[3] : undefined;
              return _context0.a(2, new SigningStargateClient(undefined, signer, options, ignoreGetSequence, localStoreFunctions));
          }
        }, _callee0);
      }));
      function offline(_x37) {
        return _offline.apply(this, arguments);
      }
      return offline;
    }())
  }]);
}(_stargate.StargateClient);
/**
 * Creates a new SigningStargateClient with the given signer.
 * @param rpcEndpoint - The RPC endpoint of the chain.
 * @param offlineWallet - The wallet to sign transactions.
 * @param ignoreGetSequence - If true, the client will not query the chain for the account sequence.
 * @param options - The client options.
 * @param localStoreFunctions - The local storage getter and setter to use save sequence locally.
 */
var createSigningClient = exports.createSigningClient = /*#__PURE__*/function () {
  var _ref4 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator().m(function _callee1(rpcEndpoint, offlineWallet, ignoreGetSequence, options, localStoreFunctions) {
    return _regenerator().w(function (_context1) {
      while (1) switch (_context1.n) {
        case 0:
          _context1.n = 1;
          return SigningStargateClient.connectWithSigner(rpcEndpoint, offlineWallet, _objectSpread({
            // registry: new Registry([...defaultRegistryTypes, ...ixoProtoRegistry]),
            registry: (0, _customRegistries.createRegistry)(),
            accountParser: _stargate.accountFromAny
          }, options), ignoreGetSequence, localStoreFunctions);
        case 1:
          return _context1.a(2, _context1.v);
      }
    }, _callee1);
  }));
  return function createSigningClient(_x38, _x39, _x40, _x41, _x42) {
    return _ref4.apply(this, arguments);
  };
}();