@cosmos-kit/terra-extension
Version:
cosmos-kit wallet connector
37 lines • 1.36 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import { Fee as TerraFee, Msg as TerraMsg, SignatureV2 } from '@terra-money/feather.js';
export class OfflineSigner {
constructor(extension, accountInfo) {
_defineProperty(this, "extension", void 0);
_defineProperty(this, "accountInfo", void 0);
this.extension = extension;
this.accountInfo = accountInfo;
}
async getAccounts() {
return [{
address: this.accountInfo.address,
algo: this.accountInfo.algo || 'secp256k1',
pubkey: this.accountInfo.pubkey
}];
}
async signAmino(signerAddress, signDoc) {
const signDocFee = signDoc.fee;
const feeAmount = signDocFee.amount[0].amount + signDocFee.amount[0].denom;
const fakeMsgs = signDoc.msgs.map(msg => TerraMsg.fromAmino(msg));
const signResponse = await this.extension.sign({
chainID: signDoc.chain_id,
msgs: fakeMsgs,
fee: new TerraFee(parseInt(signDocFee.gas), feeAmount, signDocFee.payer, signDocFee.granter),
memo: signDoc.memo,
signMode: SignatureV2.SignMode.SIGN_MODE_LEGACY_AMINO_JSON
});
const signature = {
pub_key: signResponse.payload.result.auth_info.signer_infos[0].public_key.key,
signature: signResponse.payload.result.signatures[0]
};
return {
signed: signDoc,
signature
};
}
}