Skip to content

Commit

Permalink
chore: Refactoring RPC response parsing for cosmos (#500)
Browse files Browse the repository at this point in the history
  • Loading branch information
y3fers0n authored Feb 7, 2024
1 parent 09a0228 commit 7034fdc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
4 changes: 2 additions & 2 deletions dist/trust-min.js
Git LFS file not shown
31 changes: 18 additions & 13 deletions src/cosmos_provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,35 +61,40 @@ 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 };
});
}

signArbitrary(chainId, signerAddress, data) {
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) {
Expand Down

0 comments on commit 7034fdc

Please sign in to comment.