Add makeStdSignDoc and serializeSignDoc

This commit is contained in:
Simon Warta 2020-09-23 11:03:15 +02:00
parent a0ee9963c1
commit 6c116f3d5a
5 changed files with 47 additions and 20 deletions

View File

@ -45,6 +45,8 @@
`isSearchBySentFromOrToQuery` and `isSearchByTagsQuery`.
- @cosmjs/launchpad: Change type of `TxsResponse.logs` and
`BroadcastTxsResponse.logs` to `unknown[]`.
- @cosmjs/launchpad: Export `StdSignDoc` and create helpers to make and
serialize a `StdSignDoc`: `makeStdSignDoc` and `serializeSignDoc`.
- @cosmjs/launchpad-ledger: Add package supporting Ledger device integration for
Launchpad. Two new classes are provided: `LedgerSigner` (for most use cases)
and `LaunchpadLedger` for more fine-grained access.

View File

@ -29,14 +29,38 @@ function sortJson(json: any): any {
* @see https://docs.cosmos.network/master/modules/auth/03_types.html#stdsigndoc
*/
export interface StdSignDoc {
readonly account_number: string;
readonly chain_id: string;
readonly fee: StdFee;
readonly memo: string;
readonly msgs: readonly Msg[];
readonly account_number: string;
readonly sequence: string;
readonly fee: StdFee;
readonly msgs: readonly Msg[];
readonly memo: string;
}
export function makeStdSignDoc(
msgs: readonly Msg[],
fee: StdFee,
chainId: string,
memo: string,
accountNumber: number | string,
sequence: number | string,
): StdSignDoc {
return {
chain_id: chainId,
account_number: uint64ToString(accountNumber),
sequence: uint64ToString(sequence),
fee: fee,
msgs: msgs,
memo: memo,
};
}
export function serializeSignDoc(signDoc: StdSignDoc): Uint8Array {
const sortedSignDoc = sortJson(signDoc);
return toUtf8(JSON.stringify(sortedSignDoc));
}
/** A convenience helper to create the StdSignDoc and serialize it */
export function makeSignBytes(
msgs: readonly Msg[],
fee: StdFee,
@ -45,14 +69,5 @@ export function makeSignBytes(
accountNumber: number | string,
sequence: number | string,
): Uint8Array {
const signDoc: StdSignDoc = {
account_number: uint64ToString(accountNumber),
chain_id: chainId,
fee: fee,
memo: memo,
msgs: msgs,
sequence: uint64ToString(sequence),
};
const sortedSignDoc = sortJson(signDoc);
return toUtf8(JSON.stringify(sortedSignDoc));
return serializeSignDoc(makeStdSignDoc(msgs, fee, chainId, memo, accountNumber, sequence));
}

View File

@ -28,7 +28,7 @@ export {
isSearchBySentFromOrToQuery,
isSearchByTagsQuery,
} from "./cosmosclient";
export { makeSignBytes, StdSignDoc } from "./encoding";
export { makeSignBytes, makeStdSignDoc, serializeSignDoc, StdSignDoc } from "./encoding";
export { buildFeeTable, FeeTable, GasLimits, GasPrice } from "./gas";
export {
AuthAccountsResponse,

View File

@ -6,13 +6,23 @@ import { StdFee } from "./types";
* @see https://docs.cosmos.network/master/modules/auth/03_types.html#stdsigndoc
*/
export interface StdSignDoc {
readonly account_number: string;
readonly chain_id: string;
readonly fee: StdFee;
readonly memo: string;
readonly msgs: readonly Msg[];
readonly account_number: string;
readonly sequence: string;
readonly fee: StdFee;
readonly msgs: readonly Msg[];
readonly memo: string;
}
export declare function makeStdSignDoc(
msgs: readonly Msg[],
fee: StdFee,
chainId: string,
memo: string,
accountNumber: number | string,
sequence: number | string,
): StdSignDoc;
export declare function serializeSignDoc(signDoc: StdSignDoc): Uint8Array;
/** A convenience helper to create the StdSignDoc and serialize it */
export declare function makeSignBytes(
msgs: readonly Msg[],
fee: StdFee,

View File

@ -26,7 +26,7 @@ export {
isSearchBySentFromOrToQuery,
isSearchByTagsQuery,
} from "./cosmosclient";
export { makeSignBytes, StdSignDoc } from "./encoding";
export { makeSignBytes, makeStdSignDoc, serializeSignDoc, StdSignDoc } from "./encoding";
export { buildFeeTable, FeeTable, GasLimits, GasPrice } from "./gas";
export {
AuthAccountsResponse,