Let nonceToAccountNumber/nonceToSequence return number
This commit is contained in:
parent
4b91ed8f0c
commit
f6f542912a
@ -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));
|
||||
|
||||
|
||||
@ -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(
|
||||
|
||||
@ -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", () => {
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
4
packages/bcp/types/types.d.ts
vendored
4
packages/bcp/types/types.d.ts
vendored
@ -17,5 +17,5 @@ export interface TokenInfo {
|
||||
export declare type TokenInfos = ReadonlyArray<TokenInfo>;
|
||||
export declare type NonceInfo = Pick<types.BaseAccount, "account_number" | "sequence">;
|
||||
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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user