stellar-sdk 5.0.4: tx_bad_auth
Closed this issue · 2 comments
vlddm commented
UPD: got it working using stellar-sdk 0.6.2
.
Is is possible to sign and submit transaction using latest stellar-sdk
?
Code below always retuning 400 tx_bad_auth
.
transaction.signatures.push()
marked read-only in sdk docs, tried to use signHashX
and addSignature
- no luck.
Package versions:
Trezor-connect 8.1.8-extended
stellar-sdk 5.0.4
import StellarSdk, { Keypair, xdr, Memo } from 'stellar-sdk';
import TrezorConnect from 'trezor-connect'
import transformTransaction from 'trezor-connect/lib/plugins/stellar/plugin.js'
TrezorConnect.manifest({
email: 'developer@xyz.com',
appUrl: 'http://your.application.com'
});
async function send() {
try {
const dstAddress = 'GAIH3ULLFQ4DGSECF2AR555KZ4KNDGEKN4AFI4SU2M7B43MGK3QJZNSR' //testnet faucet
const path = "m/44'/148'/0'"
const resp = await TrezorConnect.stellarGetAddress({
path,
showOnTrezor: false
});
const address = resp.payload.address
const server = new StellarSdk.Server('https://horizon-testnet.stellar.org');
const source = await server.loadAccount(address)
const memo = new Memo(StellarSdk.MemoNone)
const transaction = new StellarSdk.TransactionBuilder (source , {
fee: 100,
networkPassphrase: StellarSdk.Networks.TESTNET })
.addMemo(memo)
.setTimeout(0)
.addOperation(StellarSdk.Operation.payment({
destination: dstAddress,
asset: StellarSdk.Asset.native(),
amount: "1.20" // 1.20 XLM
}))
.build()
let params = transformTransaction(path, transaction);
params.transaction.fee = parseInt(params.transaction.fee)
console.log('params: ', params)
const { payload } = await TrezorConnect.stellarSignTransaction(params)
if (payload.error) console.error(payload.error)
let signature = _hexToByteArray(payload.signature);
let keyPair = Keypair.fromPublicKey(address);
let hint = keyPair.signatureHint();
let decorated = new xdr.DecoratedSignature({hint, signature});
console.log('decorated: ', decorated)
transaction.signatures.push(decorated);
//transaction.signHashX(payload.signature)
const submitResult = await server.submitTransaction(transaction)
console.log(submitResult)
} catch (e) {
console.log(JSON.stringify(e, null, ' '))
}
}
function _hexToByteArray(str) {
let result = [];
while (str.length >= 2) {
result.push(parseInt(str.substring(0, 2), 16));
str = str.substring(2, str.length);
}
return new Uint8Array(result);
}
send()
keraf commented
Any luck with getting this to work? I'm not too familiar with the Stellar SDK but seeing that it works with one version and not another one makes me believe something is wrong on that library or how it's being used.
tsusanka commented
Seems to be working in stellar-sdk 0.6.2 and newer 🎉.