Internalize SignDoc and omitDefaults for sign bytes creation
This commit is contained in:
parent
0bf58e5a51
commit
6832fd5737
@ -1,4 +1,3 @@
|
||||
export { omitDefaults } from "./adr27";
|
||||
export { Coin } from "./msgs";
|
||||
export { cosmosField } from "./decorator";
|
||||
export { Registry } from "./registry";
|
||||
|
||||
@ -2,13 +2,12 @@
|
||||
import { Bech32, fromBase64, fromHex, toHex } from "@cosmjs/encoding";
|
||||
import { Secp256k1Wallet } from "@cosmjs/launchpad";
|
||||
|
||||
import { omitDefaults } from "./adr27";
|
||||
import { cosmos } from "./generated/codecimpl";
|
||||
import { defaultRegistry } from "./msgs";
|
||||
import { Registry, TxBodyValue } from "./registry";
|
||||
import { makeSignBytes } from "./signing";
|
||||
|
||||
const { AuthInfo, SignDoc, Tx, TxBody } = cosmos.tx;
|
||||
const { AuthInfo, Tx, TxBody } = cosmos.tx;
|
||||
const { PublicKey } = cosmos.crypto;
|
||||
|
||||
export function pendingWithoutSimapp(): void {
|
||||
@ -149,17 +148,8 @@ describe("signing demo", () => {
|
||||
const accountNumber = 1;
|
||||
|
||||
await Promise.all(
|
||||
testVectors.map(async ({ sequenceNumber, signBytes, signedTxBytes }) => {
|
||||
const signDoc = SignDoc.create(
|
||||
omitDefaults({
|
||||
bodyBytes: txBodyBytes,
|
||||
authInfoBytes: authInfoBytes,
|
||||
chainId: chainId,
|
||||
accountNumber: accountNumber,
|
||||
accountSequence: sequenceNumber,
|
||||
}),
|
||||
);
|
||||
const signDocBytes = makeSignBytes(signDoc);
|
||||
testVectors.map(async ({ sequenceNumber: sequence, signBytes, signedTxBytes }) => {
|
||||
const signDocBytes = makeSignBytes(txBodyBytes, authInfoBytes, chainId, accountNumber, sequence);
|
||||
expect(toHex(signDocBytes)).toEqual(signBytes);
|
||||
|
||||
const signature = await wallet.sign(address, signDocBytes);
|
||||
|
||||
@ -1,8 +1,24 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { omitDefaults } from "./adr27";
|
||||
import { cosmos } from "./generated/codecimpl";
|
||||
|
||||
const { SignDoc } = cosmos.tx;
|
||||
|
||||
export function makeSignBytes(signDoc: cosmos.tx.ISignDoc): Uint8Array {
|
||||
export function makeSignBytes(
|
||||
txBody: Uint8Array,
|
||||
authInfo: Uint8Array,
|
||||
chainId: string,
|
||||
accountNumber: number,
|
||||
sequence: number,
|
||||
): Uint8Array {
|
||||
const signDoc = SignDoc.create(
|
||||
omitDefaults({
|
||||
bodyBytes: txBody,
|
||||
authInfoBytes: authInfo,
|
||||
chainId: chainId,
|
||||
accountNumber: accountNumber,
|
||||
accountSequence: sequence,
|
||||
}),
|
||||
);
|
||||
return Uint8Array.from(SignDoc.encode(signDoc).finish());
|
||||
}
|
||||
|
||||
1
packages/proto-signing/types/index.d.ts
vendored
1
packages/proto-signing/types/index.d.ts
vendored
@ -1,4 +1,3 @@
|
||||
export { omitDefaults } from "./adr27";
|
||||
export { Coin } from "./msgs";
|
||||
export { cosmosField } from "./decorator";
|
||||
export { Registry } from "./registry";
|
||||
|
||||
9
packages/proto-signing/types/signing.d.ts
vendored
9
packages/proto-signing/types/signing.d.ts
vendored
@ -1,2 +1,7 @@
|
||||
import { cosmos } from "./generated/codecimpl";
|
||||
export declare function makeSignBytes(signDoc: cosmos.tx.ISignDoc): Uint8Array;
|
||||
export declare function makeSignBytes(
|
||||
txBody: Uint8Array,
|
||||
authInfo: Uint8Array,
|
||||
chainId: string,
|
||||
accountNumber: number,
|
||||
sequence: number,
|
||||
): Uint8Array;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { Bech32, fromBase64 } from "@cosmjs/encoding";
|
||||
import { Coin, coins, Secp256k1Wallet } from "@cosmjs/launchpad";
|
||||
import { makeSignBytes, omitDefaults, Registry } from "@cosmjs/proto-signing";
|
||||
import { makeSignBytes, Registry } from "@cosmjs/proto-signing";
|
||||
import { assert } from "@cosmjs/utils";
|
||||
import Long from "long";
|
||||
|
||||
@ -14,7 +14,7 @@ import {
|
||||
} from "./stargateclient";
|
||||
import { faucet, makeRandomAddress, pendingWithoutSimapp, simapp, simappEnabled } from "./testutils.spec";
|
||||
|
||||
const { AuthInfo, SignDoc, Tx, TxBody } = cosmos.tx;
|
||||
const { AuthInfo, Tx, TxBody } = cosmos.tx;
|
||||
const { PublicKey } = cosmos.crypto;
|
||||
|
||||
interface TestTxSend {
|
||||
@ -76,16 +76,7 @@ async function sendTokens(
|
||||
|
||||
const { accountNumber, sequence } = (await client.getSequence(walletAddress))!;
|
||||
const chainId = await client.getChainId();
|
||||
const signDoc = SignDoc.create(
|
||||
omitDefaults({
|
||||
bodyBytes: txBodyBytes,
|
||||
authInfoBytes: authInfoBytes,
|
||||
chainId: chainId,
|
||||
accountNumber: accountNumber,
|
||||
accountSequence: sequence,
|
||||
}),
|
||||
);
|
||||
const signDocBytes = makeSignBytes(signDoc);
|
||||
const signDocBytes = makeSignBytes(txBodyBytes, authInfoBytes, chainId, accountNumber, sequence);
|
||||
const signature = await wallet.sign(walletAddress, signDocBytes);
|
||||
const txRaw = Tx.create({
|
||||
body: txBody,
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { Bech32, fromBase64 } from "@cosmjs/encoding";
|
||||
import { Secp256k1Wallet } from "@cosmjs/launchpad";
|
||||
import { makeSignBytes, omitDefaults, Registry } from "@cosmjs/proto-signing";
|
||||
import { makeSignBytes, Registry } from "@cosmjs/proto-signing";
|
||||
import { assert, sleep } from "@cosmjs/utils";
|
||||
import Long from "long";
|
||||
import { ReadonlyDate } from "readonly-date";
|
||||
@ -19,7 +19,7 @@ import {
|
||||
validator,
|
||||
} from "./testutils.spec";
|
||||
|
||||
const { AuthInfo, SignDoc, Tx, TxBody } = cosmos.tx;
|
||||
const { AuthInfo, Tx, TxBody } = cosmos.tx;
|
||||
const { PublicKey } = cosmos.crypto;
|
||||
|
||||
describe("StargateClient", () => {
|
||||
@ -298,16 +298,7 @@ describe("StargateClient", () => {
|
||||
|
||||
const chainId = await client.getChainId();
|
||||
const { accountNumber, sequence } = (await client.getSequence(address))!;
|
||||
const signDoc = SignDoc.create(
|
||||
omitDefaults({
|
||||
bodyBytes: txBodyBytes,
|
||||
authInfoBytes: authInfoBytes,
|
||||
chainId: chainId,
|
||||
accountNumber: accountNumber,
|
||||
accountSequence: sequence,
|
||||
}),
|
||||
);
|
||||
const signDocBytes = makeSignBytes(signDoc);
|
||||
const signDocBytes = makeSignBytes(txBodyBytes, authInfoBytes, chainId, accountNumber, sequence);
|
||||
const signature = await wallet.sign(address, signDocBytes);
|
||||
const txRaw = Tx.create({
|
||||
body: txBody,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user