From f6f542912a4a29a35674ab924e250fe7ea37d39f Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Tue, 4 Feb 2020 09:07:25 +0100 Subject: [PATCH] Let nonceToAccountNumber/nonceToSequence return number --- packages/bcp/src/cosmwasmcodec.ts | 4 ++-- packages/bcp/src/cosmwasmconnection.spec.ts | 2 +- packages/bcp/src/types.spec.ts | 4 ++-- packages/bcp/src/types.ts | 8 ++++---- packages/bcp/types/types.d.ts | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/bcp/src/cosmwasmcodec.ts b/packages/bcp/src/cosmwasmcodec.ts index 2ca6e273..caf46ad7 100644 --- a/packages/bcp/src/cosmwasmcodec.ts +++ b/packages/bcp/src/cosmwasmcodec.ts @@ -56,12 +56,12 @@ export class CosmWasmCodec implements TxCodec { const built = buildUnsignedTx(unsigned, this.tokens); const signMsg = sortJson({ - account_number: nonceToAccountNumber(nonce), + account_number: nonceToAccountNumber(nonce).toString(), chain_id: Caip5.decode(unsigned.chainId), fee: (built.value as any).fee, memo: memo, msgs: (built.value as any).msg, - sequence: nonceToSequence(nonce), + sequence: nonceToSequence(nonce).toString(), }); const signBytes = toUtf8(JSON.stringify(signMsg)); diff --git a/packages/bcp/src/cosmwasmconnection.spec.ts b/packages/bcp/src/cosmwasmconnection.spec.ts index 100ddc3b..c59759a7 100644 --- a/packages/bcp/src/cosmwasmconnection.spec.ts +++ b/packages/bcp/src/cosmwasmconnection.spec.ts @@ -242,7 +242,7 @@ describe("CosmWasmConnection", () => { expect(signatures.length).toEqual(1); // TODO: the nonce we recover in response doesn't have accountNumber, only sequence - const signedSequence = parseInt(nonceToSequence(signed.signatures[0].nonce), 10); + const signedSequence = nonceToSequence(signed.signatures[0].nonce); expect(signatures[0].nonce).toEqual(signedSequence); expect(signatures[0].pubkey.algo).toEqual(signed.signatures[0].pubkey.algo); expect(toHex(signatures[0].pubkey.data)).toEqual( diff --git a/packages/bcp/src/types.spec.ts b/packages/bcp/src/types.spec.ts index be1c8702..3fab0b47 100644 --- a/packages/bcp/src/types.spec.ts +++ b/packages/bcp/src/types.spec.ts @@ -7,8 +7,8 @@ describe("nonceEncoding", () => { account_number: 1234, sequence: 7890, }); - expect(nonceToAccountNumber(nonce)).toEqual("1234"); - expect(nonceToSequence(nonce)).toEqual("7890"); + expect(nonceToAccountNumber(nonce)).toEqual(1234); + expect(nonceToSequence(nonce)).toEqual(7890); }); it("errors on input too large", () => { diff --git a/packages/bcp/src/types.ts b/packages/bcp/src/types.ts index dd804395..2f1ee35a 100644 --- a/packages/bcp/src/types.ts +++ b/packages/bcp/src/types.ts @@ -44,16 +44,16 @@ export function accountToNonce({ account_number: account, sequence }: NonceInfo) } // this extracts info from nonce for signing -export function nonceToAccountNumber(nonce: Nonce): string { +export function nonceToAccountNumber(nonce: Nonce): number { const acct = nonce / maxSeq; if (acct > maxAcct) { throw new Error("Invalid Nonce, account number is higher than can safely be encoded in Nonce"); } - return Math.round(acct).toString(); + return Math.round(acct); } // this extracts info from nonce for signing -export function nonceToSequence(nonce: Nonce): string { +export function nonceToSequence(nonce: Nonce): number { const seq = nonce % maxSeq; - return Math.round(seq).toString(); + return Math.round(seq); } diff --git a/packages/bcp/types/types.d.ts b/packages/bcp/types/types.d.ts index e100d159..d89725f4 100644 --- a/packages/bcp/types/types.d.ts +++ b/packages/bcp/types/types.d.ts @@ -17,5 +17,5 @@ export interface TokenInfo { export declare type TokenInfos = ReadonlyArray; export declare type NonceInfo = Pick; export declare function accountToNonce({ account_number: account, sequence }: NonceInfo): Nonce; -export declare function nonceToAccountNumber(nonce: Nonce): string; -export declare function nonceToSequence(nonce: Nonce): string; +export declare function nonceToAccountNumber(nonce: Nonce): number; +export declare function nonceToSequence(nonce: Nonce): number;