@firmachain/firma-js
Version:
The Official FirmaChain Javascript SDK written in Typescript
76 lines (75 loc) • 2.77 kB
JavaScript
;
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeSignBytes = exports.makeSignDoc = exports.makeAuthInfoBytes = void 0;
var signing_1 = require("cosmjs-types/cosmos/tx/signing/v1beta1/signing");
var tx_1 = require("cosmjs-types/cosmos/tx/v1beta1/tx");
var long_1 = __importDefault(require("long"));
function makeSignerInfos(signers, signMode) {
return signers.map(function (_a) {
var pubkey = _a.pubkey, sequence = _a.sequence;
return ({
publicKey: pubkey,
modeInfo: {
single: { mode: signMode },
},
sequence: long_1.default.fromNumber(sequence),
});
});
}
function makeAuthInfoBytes(signers, feeAmount, gasLimit, granter, signMode) {
if (signMode === void 0) { signMode = signing_1.SignMode.SIGN_MODE_DIRECT; }
var authInfo = {
signerInfos: makeSignerInfos(signers, signMode),
fee: {
amount: __spreadArray([], __read(feeAmount)),
gasLimit: long_1.default.fromNumber(gasLimit),
granter: granter,
},
};
return tx_1.AuthInfo.encode(tx_1.AuthInfo.fromPartial(authInfo)).finish();
}
exports.makeAuthInfoBytes = makeAuthInfoBytes;
function makeSignDoc(bodyBytes, authInfoBytes, chainId, accountNumber) {
return {
bodyBytes: bodyBytes,
authInfoBytes: authInfoBytes,
chainId: chainId,
accountNumber: long_1.default.fromNumber(accountNumber),
};
}
exports.makeSignDoc = makeSignDoc;
function makeSignBytes(_a) {
var accountNumber = _a.accountNumber, authInfoBytes = _a.authInfoBytes, bodyBytes = _a.bodyBytes, chainId = _a.chainId;
var signDoc = tx_1.SignDoc.fromPartial({
accountNumber: accountNumber,
authInfoBytes: authInfoBytes,
bodyBytes: bodyBytes,
chainId: chainId,
});
return tx_1.SignDoc.encode(signDoc).finish();
}
exports.makeSignBytes = makeSignBytes;