From 7034fdc8bcb124c3b83bd29af612068a1ec0e4c4 Mon Sep 17 00:00:00 2001 From: Yeferson Licet <111311418+y3fers0n@users.noreply.github.com> Date: Wed, 7 Feb 2024 15:06:41 -0300 Subject: [PATCH] chore: Refactoring RPC response parsing for cosmos (#500) --- dist/trust-min.js | 4 ++-- src/cosmos_provider.js | 31 ++++++++++++++++++------------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/dist/trust-min.js b/dist/trust-min.js index 527b552b..ac1ac5a3 100644 --- a/dist/trust-min.js +++ b/dist/trust-min.js @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e7cfcf1c7453298f3998ec5bdd77a4ace4a029b71027135a29b8004cc36fb694 -size 906477 +oid sha256:df8966810f0970b613ddc5fc3440fc1d6bfca9c7538df35b9b41d0e6873d83a1 +size 906614 diff --git a/src/cosmos_provider.js b/src/cosmos_provider.js index c2599019..d9b906ee 100644 --- a/src/cosmos_provider.js +++ b/src/cosmos_provider.js @@ -61,21 +61,25 @@ export class TrustCosmosWeb3Provider extends BaseProvider { return this._request("signAmino", { chainId: chainId, sign_doc: signDoc, - }).then((signatures) => { - return { signed: signDoc, signature: JSON.parse(signatures)[0] }; + }).then((response) => { + const { signed, signature } = JSON.parse(response); + return { signed, signature }; }); } signDirect(chainId, signerAddress, signDoc) { const object = { - body_bytes: Utils.bufferToHex(signDoc.bodyBytes), - auth_info_bytes: Utils.bufferToHex(signDoc.authInfoBytes), + bodyBytes: Utils.bufferToHex(signDoc.bodyBytes), + authInfoBytes: Utils.bufferToHex(signDoc.authInfoBytes), }; + return this._request("signDirect", { + signerAddress, chainId: chainId, sign_doc: object, - }).then((signatures) => { - return { signed: signDoc, signature: JSON.parse(signatures)[0] }; + }).then((response) => { + const { signature } = JSON.parse(response); + return { signed: signDoc, signature }; }); } @@ -83,13 +87,14 @@ export class TrustCosmosWeb3Provider extends BaseProvider { const buffer = Buffer.from(data); const hex = Utils.bufferToHex(buffer); - return this._request("signArbitrary", { chainId: chainId, data: hex }).then( - (result) => { - const signature = JSON.parse(result)[0].signature; - const signDoc = {}; - return { signDoc, signature }; - } - ); + return this._request("signArbitrary", { + chainId: chainId, + data: hex, + signerAddress, + }).then((response) => { + const signDoc = {}; + return { signDoc, signature: response }; + }); } sendTx(chainId, tx, mode) {