Skip to content

Commit

Permalink
Merge pull request #525 from forbole/dev
Browse files Browse the repository at this point in the history
v0.16.2
  • Loading branch information
calvinkei committed Dec 15, 2021
2 parents c53f800 + 62ed11d commit c0d1590
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
38 changes: 35 additions & 3 deletions misc/tx/generateProof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ import { stringToPath } from '@cosmjs/crypto'
import { LedgerSigner } from '@cosmjs/ledger-amino'
import { toBase64 } from '@cosmjs/encoding'
import TerraApp from '@terra-money/ledger-terra-js'
import { Extension, Fee, LCDClient, Msg, MsgSend } from '@terra-money/terra.js'
import {
Extension,
AuthInfo,
Fee,
LCDClient,
MsgSend,
SignDoc,
TxBody,
} from '@terra-money/terra.js'
import { signatureImport } from 'secp256k1'
import get from 'lodash/get'
import { sortedJsonStringify } from '@cosmjs/amino/build/signdoc'
Expand Down Expand Up @@ -91,13 +99,37 @@ const generateProof = async (
const terraAddress = get(result, 'result.body.messages[0].from_address', '')
const signature = get(result, 'result.signatures[0]', '')
const pubkey = get(result, 'result.auth_info.signer_infos[0].public_key.key', '')
proof.msgs = get(result, 'result.body.messages', []).map((m) => MsgSend.fromData(m).toAmino())
proof.sequence = get(result, 'result.auth_info.signer_infos[0].sequence', '')
const signMode = get(result, 'result.auth_info.signer_infos[0].mode_info.single.mode', '')
const terraLCDClient = new LCDClient({
URL: 'https://lcd.terra.dev',
chainID: option.chainId,
})
const auth = await terraLCDClient.auth.accountInfo(terraAddress)

if (signMode === 'SIGN_MODE_DIRECT') {
const txBody = get(result, 'result.body', {})
const signDoc = new SignDoc(
proof.chain_id,
auth.getAccountNumber(),
get(result, 'result.auth_info.signer_infos[0].sequence', ''),
AuthInfo.fromData(get(result, 'result.auth_info', {})),
TxBody.fromData(txBody)
)
return {
proof: {
plainText: Buffer.from(signDoc.toBytes()).toString('hex'),
pubKey: {
typeUrl: '/cosmos.crypto.secp256k1.PubKey',
value: pubkey,
},
signature: Buffer.from(signature, 'base64').toString('hex'),
},
address: terraAddress,
}
}
proof.msgs = get(result, 'result.body.messages', []).map((m) => MsgSend.fromData(m).toAmino())
proof.sequence = get(result, 'result.auth_info.signer_infos[0].sequence', '')

proof.account_number = String(auth.getAccountNumber())
return {
proof: {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "forbole-x",
"version": "0.16.1",
"version": "0.16.2",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down

0 comments on commit c0d1590

Please sign in to comment.