@provenanceio/wallet-utils
Version:
Typescript Utilities for Provenance Blockchain Wallet
55 lines (44 loc) • 3.59 kB
JavaScript
;
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.buildSignerInfo = void 0;
var google_protobuf_any_pb = _interopRequireWildcard(require("google-protobuf/google/protobuf/any_pb"));
var _tx_pb = require("../../../proto/cosmos/tx/v1beta1/tx_pb");
var _signing_pb = require("../../../proto/cosmos/tx/signing/v1beta1/signing_pb");
var _keys_pb = require("../../../proto/cosmos/crypto/secp256k1/keys_pb");
var _types = require("../../../types");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
/** Builds the SignerInfo messages, which describes the public key and
* signing mode of a single top-level signer
* @param baseAccount: The base account used for signatures. This provides
* the signer sequence. The sequence is the sequence of the account, which
* describes the number of committed transactions signed by a given address.
* It is used to prevent replay attacks.
* @param pubKeyBytes: The public key of the signer as a Uint8Array. It is
* optional for accounts that already exist in state. If unset, the verifier
* can use the required signer address for this position and lookup the public
* key.
* reference: https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/tx/v1beta1/tx.proto#L13-L26
*/
var buildSignerInfo = function buildSignerInfo(baseAccount, pubKeyBytes) {
// mode_info describes the signing mode of the signer and is a nested
// structure to support nested multisig pubkey's. This function only
// supports single signer functionality.
var single = new _tx_pb.ModeInfo.Single();
single.setMode(_signing_pb.SignMode.SIGN_MODE_DIRECT);
var modeInfo = new _tx_pb.ModeInfo();
modeInfo.setSingle(single);
var signerInfo = new _tx_pb.SignerInfo();
var pubKey = new _keys_pb.PubKey();
pubKey.setKey(pubKeyBytes);
var pubKeyAny = new google_protobuf_any_pb.Any();
pubKeyAny.pack(pubKey.serializeBinary(), _types.TYPE_NAMES_READABLE_MAP.PubKey, '/');
signerInfo.setPublicKey(pubKeyAny);
signerInfo.setModeInfo(modeInfo);
signerInfo.setSequence(baseAccount.getSequence());
return signerInfo;
};
exports.buildSignerInfo = buildSignerInfo;