-
We are able to sign the cosmos transaction has from the external client and it is getting generated like this
and the signature is done in the external wallet which ever installed. For that we are using
But the if we broadcast the output bytes generated when trying, it throws error |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
Hi @punithbm, we have it("test compile", () => {
const { PrivateKey, HexCoding, AnyAddress, CoinType, Curve, TransactionCompiler, DataVector } = globalThis.core;
const signingMode = 1;
const amounts = TW.Cosmos.Proto.Amount.create({
amount: "400000",
denom: "uatom",
});
const sendCoinsMessage = TW.Cosmos.Proto.Message.Send.create({
toAddress: "cosmos18s0hdnsllgcclweu9aymw4ngktr2k0rkygdzdp",
fromAddress: "cosmos1mky69cn8ektwy0845vec9upsdphktxt03gkwlx",
amounts: [amounts],
});
const message = TW.Cosmos.Proto.Message.create({
sendCoinsMessage: sendCoinsMessage,
});
const fee = TW.Cosmos.Proto.Fee.create({
gas: new Long(200000),
amounts: [
{
amount: "1000",
denom: "uatom",
},
],
});
const input = TW.Cosmos.Proto.SigningInput.create({
signingMode: signingMode,
accountNumber: new Long(546179),
chainId: "cosmoshub-4",
memo: "",
sequence: new Long(0),
// Sign as Protobuf encoded.
mode: 1,
messages: [message],
fee: fee,
// Must be specified instead of `privateKey`.
publicKey: HexCoding.decode("02ecef5ce437a302c67f95468de4b31f36e911f467d7e6a52b41c1e13e1d563649"),
});
const inputEncoded = TW.Cosmos.Proto.SigningInput.encode(input).finish();
/// Step 2: Obtain preimage hashes
const preimageOutputData = TransactionCompiler.preImageHashes(CoinType.cosmos, inputEncoded);
const preimageOutput = TW.TxCompiler.Proto.PreSigningOutput.decode(preimageOutputData);
assert.equal(HexCoding.encode(preimageOutput.dataHash), "0xfa7990e1814c900efaedf1bdbedba22c22336675befe0ae39974130fc204f3de");
/// Step 3: Compile transaction info with an "external" signature.
const signatures = DataVector.createWithData(HexCoding.decode("afbd513a776f4fdf470ef7f9675f21ae9d630fc4d635d8dbaa0dc0a716434cd07e02510765d4673dfa880825bae8e67cb367396ff6b976fc6b19a31fc95e8097"));
const publicKeys = DataVector.createWithData(HexCoding.decode("02ecef5ce437a302c67f95468de4b31f36e911f467d7e6a52b41c1e13e1d563649"));
const outputData = TransactionCompiler.compileWithSignatures(CoinType.cosmos, inputEncoded, signatures, publicKeys);
const output = TW.Cosmos.Proto.SigningOutput.decode(outputData);
assert.equal(output.serialized, "{\"mode\":\"BROADCAST_MODE_SYNC\",\"tx_bytes\":\"CpIBCo8BChwvY29zbW9zLmJhbmsudjFiZXRhMS5Nc2dTZW5kEm8KLWNvc21vczFta3k2OWNuOGVrdHd5MDg0NXZlYzl1cHNkcGhrdHh0MDNna3dseBItY29zbW9zMThzMGhkbnNsbGdjY2x3ZXU5YXltdzRuZ2t0cjJrMHJreWdkemRwGg8KBXVhdG9tEgY0MDAwMDASZQpOCkYKHy9jb3Ntb3MuY3J5cHRvLnNlY3AyNTZrMS5QdWJLZXkSIwohAuzvXOQ3owLGf5VGjeSzHzbpEfRn1+alK0HB4T4dVjZJEgQKAggBEhMKDQoFdWF0b20SBDEwMDAQwJoMGkCvvVE6d29P30cO9/lnXyGunWMPxNY12NuqDcCnFkNM0H4CUQdl1Gc9+ogIJbro5nyzZzlv9rl2/GsZox/JXoCX\"}");
}); |
Beta Was this translation helpful? Give feedback.
Figured out the issue, removing the r (recovery) component in the signature and using it resolved. Signature from the external signer was 130 characters length where as last 2 characters were carrying the bytes for recover. Slicing and using it worked.