Tidy proto-signing and stargate after review
This commit is contained in:
parent
fca13eee85
commit
a2acf9e061
@ -76,9 +76,9 @@ describe("DirectSecp256k1Wallet", () => {
|
||||
accountNumber,
|
||||
);
|
||||
const signDocBytes = makeSignBytes(signDoc);
|
||||
const signResponse = await wallet.signDirect(faucet.address, signDoc);
|
||||
const { signature } = await wallet.signDirect(faucet.address, signDoc);
|
||||
const valid = await Secp256k1.verifySignature(
|
||||
Secp256k1Signature.fromFixedLength(fromBase64(signResponse.signature.signature)),
|
||||
Secp256k1Signature.fromFixedLength(fromBase64(signature.signature)),
|
||||
sha256(signDocBytes),
|
||||
pubkey.value,
|
||||
);
|
||||
|
||||
@ -22,5 +22,5 @@ export interface OfflineDirectSigner {
|
||||
export type OfflineSigner = OfflineAminoSigner | OfflineDirectSigner;
|
||||
|
||||
export function isOfflineDirectSigner(signer: OfflineSigner): signer is OfflineDirectSigner {
|
||||
return (signer as any).signDirect !== undefined;
|
||||
return (signer as OfflineDirectSigner).signDirect !== undefined;
|
||||
}
|
||||
|
||||
@ -100,11 +100,11 @@ describe("signing", () => {
|
||||
const signDocBytes = makeSignBytes(signDoc);
|
||||
expect(toHex(signDocBytes)).toEqual(signBytes);
|
||||
|
||||
const signResponse = await wallet.signDirect(address, signDoc);
|
||||
const { signature } = await wallet.signDirect(address, signDoc);
|
||||
const txRaw = TxRaw.create({
|
||||
bodyBytes: txBodyBytes,
|
||||
authInfoBytes: authInfoBytes,
|
||||
signatures: [fromBase64(signResponse.signature.signature)],
|
||||
signatures: [fromBase64(signature.signature)],
|
||||
});
|
||||
const txRawBytes = Uint8Array.from(TxRaw.encode(txRaw).finish());
|
||||
const txBytesHex = toHex(txRawBytes);
|
||||
|
||||
@ -123,11 +123,11 @@ export class SigningStargateClient extends StargateClient {
|
||||
if (isOfflineDirectSigner(this.signer)) {
|
||||
const authInfoBytes = makeAuthInfoBytes([pubkeyAny], fee.amount, gasLimit, sequence);
|
||||
const signDoc = makeSignDoc(txBodyBytes, authInfoBytes, chainId, accountNumber);
|
||||
const signResponse = await this.signer.signDirect(address, signDoc);
|
||||
const { signature } = await this.signer.signDirect(address, signDoc);
|
||||
const txRaw = TxRaw.create({
|
||||
bodyBytes: txBodyBytes,
|
||||
authInfoBytes: authInfoBytes,
|
||||
signatures: [fromBase64(signResponse.signature.signature)],
|
||||
signatures: [fromBase64(signature.signature)],
|
||||
});
|
||||
const signedTx = Uint8Array.from(TxRaw.encode(txRaw).finish());
|
||||
return this.broadcastTx(signedTx);
|
||||
|
||||
@ -74,11 +74,11 @@ async function sendTokens(
|
||||
|
||||
const chainId = await client.getChainId();
|
||||
const signDoc = makeSignDoc(txBodyBytes, authInfoBytes, chainId, accountNumber);
|
||||
const signResponse = await wallet.signDirect(walletAddress, signDoc);
|
||||
const { signature } = await wallet.signDirect(walletAddress, signDoc);
|
||||
const txRaw = TxRaw.create({
|
||||
bodyBytes: txBodyBytes,
|
||||
authInfoBytes: authInfoBytes,
|
||||
signatures: [fromBase64(signResponse.signature.signature)],
|
||||
signatures: [fromBase64(signature.signature)],
|
||||
});
|
||||
const txRawBytes = Uint8Array.from(TxRaw.encode(txRaw).finish());
|
||||
const broadcastResponse = await client.broadcastTx(txRawBytes);
|
||||
|
||||
@ -296,11 +296,11 @@ describe("StargateClient", () => {
|
||||
|
||||
const chainId = await client.getChainId();
|
||||
const signDoc = makeSignDoc(txBodyBytes, authInfoBytes, chainId, accountNumber);
|
||||
const signResponse = await wallet.signDirect(address, signDoc);
|
||||
const { signature } = await wallet.signDirect(address, signDoc);
|
||||
const txRaw = TxRaw.create({
|
||||
bodyBytes: txBodyBytes,
|
||||
authInfoBytes: authInfoBytes,
|
||||
signatures: [fromBase64(signResponse.signature.signature)],
|
||||
signatures: [fromBase64(signature.signature)],
|
||||
});
|
||||
const txRawBytes = Uint8Array.from(TxRaw.encode(txRaw).finish());
|
||||
const txResult = await client.broadcastTx(txRawBytes);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user