diff --git a/packages/bcp/src/cosmwasmconnection.spec.ts b/packages/bcp/src/cosmwasmconnection.spec.ts index e858de22..91fd0495 100644 --- a/packages/bcp/src/cosmwasmconnection.spec.ts +++ b/packages/bcp/src/cosmwasmconnection.spec.ts @@ -322,7 +322,7 @@ describe("CosmWasmConnection", () => { expect(transaction).toEqual(unsigned); expect(signatures.length).toEqual(1); expect(signatures[0]).toEqual({ - nonce: signed.signatures[0].nonce, // This equality check works by pure luck. The implementation is broken. See https://github.com/iov-one/iov-core/pull/1390 + nonce: -1, // Unfortunately this information is unavailable as previous implementation attempt is broken. See https://github.com/iov-one/iov-core/pull/1390 pubkey: { algo: signed.signatures[0].pubkey.algo, data: Secp256k1.compressPubkey(signed.signatures[0].pubkey.data), diff --git a/packages/bcp/src/cosmwasmconnection.ts b/packages/bcp/src/cosmwasmconnection.ts index c90047ef..93e102d1 100644 --- a/packages/bcp/src/cosmwasmconnection.ts +++ b/packages/bcp/src/cosmwasmconnection.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/camelcase */ -import { CosmosAddressBech32Prefix, CosmWasmClient, RestClient, TxsResponse, types } from "@cosmwasm/sdk"; +import { CosmosAddressBech32Prefix, CosmWasmClient, RestClient, TxsResponse } from "@cosmwasm/sdk"; import { Account, AccountQuery, @@ -364,30 +364,10 @@ export class CosmWasmConnection implements BlockchainConnection { private async parseAndPopulateTxResponseSigned( response: TxsResponse, ): Promise | FailedTransaction> { - const firstMsg = response.tx.value.msg.find(() => true); - if (!firstMsg) throw new Error("Got transaction without a first message. What is going on here?"); - - // needed to get the (account_number, sequence) for the primary signature - let primarySignerAddress: string; - if (types.isMsgSend(firstMsg)) { - primarySignerAddress = firstMsg.value.from_address; - } else if ( - types.isMsgStoreCode(firstMsg) || - types.isMsgInstantiateContract(firstMsg) || - types.isMsgExecuteContract(firstMsg) - ) { - primarySignerAddress = firstMsg.value.sender; - } else { - throw new Error(`Got unsupported type of message: ${firstMsg.type}`); - } - - // tslint:disable-next-line: deprecation - const accountForHeight = await this.restClient.authAccounts(primarySignerAddress, response.height); - 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; - const nonce = accountToNonce(accountNumber, sequence); + // There is no known way to get the nonce that was used for signing a transaction. + // This information is nesessary for signature validation. + // TODO: fix + const nonce = -1 as Nonce; const chainId = this.chainId(); return parseTxsResponseSigned(chainId, parseInt(response.height, 10), nonce, response, this.bankTokens); diff --git a/packages/sdk/src/restclient.ts b/packages/sdk/src/restclient.ts index 8815981d..a8d4b1a5 100644 --- a/packages/sdk/src/restclient.ts +++ b/packages/sdk/src/restclient.ts @@ -228,9 +228,8 @@ export class RestClient { return Encoding.fromBase64((responseData as EncodeTxResponse).tx); } - public async authAccounts(address: string, height?: string): Promise { - const path = - height === undefined ? `/auth/accounts/${address}` : `/auth/accounts/${address}?tx.height=${height}`; + public async authAccounts(address: string): Promise { + const path = `/auth/accounts/${address}`; const responseData = await this.get(path); if ((responseData as any).result.type !== "cosmos-sdk/Account") { throw new Error("Unexpected response data format"); diff --git a/packages/sdk/types/restclient.d.ts b/packages/sdk/types/restclient.d.ts index a7e87e27..2da34281 100644 --- a/packages/sdk/types/restclient.d.ts +++ b/packages/sdk/types/restclient.d.ts @@ -93,7 +93,7 @@ export declare class RestClient { blocks(height: number): Promise; /** returns the amino-encoding of the transaction performed by the server */ encodeTx(tx: CosmosSdkTx): Promise; - authAccounts(address: string, height?: string): Promise; + authAccounts(address: string): Promise; txs(query: string): Promise; txsById(id: string): Promise; postTx(tx: Uint8Array): Promise;