From 58634eb577f96cba113e632642a2d9b4a37c1fe5 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Wed, 12 Feb 2020 00:39:02 +0100 Subject: [PATCH] Calculate Nonce from account number and sequence --- packages/bcp/src/cosmwasmconnection.spec.ts | 5 +---- packages/bcp/src/cosmwasmconnection.ts | 9 ++++++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/bcp/src/cosmwasmconnection.spec.ts b/packages/bcp/src/cosmwasmconnection.spec.ts index 6e28d6dc..7387cd2f 100644 --- a/packages/bcp/src/cosmwasmconnection.spec.ts +++ b/packages/bcp/src/cosmwasmconnection.spec.ts @@ -19,7 +19,6 @@ import { assert } from "@iov/utils"; import { CosmWasmCodec } from "./cosmwasmcodec"; import { CosmWasmConnection, TokenConfiguration } from "./cosmwasmconnection"; import { signedTxJson, txId } from "./testdata.spec"; -import { nonceToSequence } from "./types"; const { fromBase64, toHex } = Encoding; @@ -317,9 +316,7 @@ describe("CosmWasmConnection", () => { expect(transaction.chainId).toEqual(unsigned.chainId); expect(signatures.length).toEqual(1); - // TODO: the nonce we recover in response doesn't have accountNumber, only sequence - const signedSequence = nonceToSequence(signed.signatures[0].nonce); - expect(signatures[0].nonce).toEqual(signedSequence); + expect(signatures[0].nonce).toEqual(signed.signatures[0].nonce); expect(signatures[0].pubkey.algo).toEqual(signed.signatures[0].pubkey.algo); expect(toHex(signatures[0].pubkey.data)).toEqual( toHex(Secp256k1.compressPubkey(signed.signatures[0].pubkey.data)), diff --git a/packages/bcp/src/cosmwasmconnection.ts b/packages/bcp/src/cosmwasmconnection.ts index a659d89f..801ec313 100644 --- a/packages/bcp/src/cosmwasmconnection.ts +++ b/packages/bcp/src/cosmwasmconnection.ts @@ -372,9 +372,12 @@ export class CosmWasmConnection implements BlockchainConnection { // tslint:disable-next-line: deprecation const accountForHeight = await this.restClient.authAccounts(senderAddress, response.height); - // this is technically not the proper nonce. maybe this causes issues for sig validation? + const accountNumber = accountForHeight.result.value.account_number; + // this is technically not the proper sequence. maybe this causes issues for sig validation? // leaving for now unless it causes issues - const sequence = (accountForHeight.result.value.sequence - 1) as Nonce; - return parseTxsResponse(chainId, parseInt(response.height, 10), sequence, response, this.bankTokens); + const sequence = accountForHeight.result.value.sequence - 1; + const nonce = accountToNonce(accountNumber, sequence); + + return parseTxsResponse(chainId, parseInt(response.height, 10), nonce, response, this.bankTokens); } }