diff --git a/packages/cosmic-proto/src/helpers.ts b/packages/cosmic-proto/src/helpers.ts index 237d985d316..feea08b879a 100644 --- a/packages/cosmic-proto/src/helpers.ts +++ b/packages/cosmic-proto/src/helpers.ts @@ -1,6 +1,7 @@ import type { QueryAllBalancesRequest } from './codegen/cosmos/bank/v1beta1/query.js'; import type { MsgSend } from './codegen/cosmos/bank/v1beta1/tx.js'; import type { MsgDelegate } from './codegen/cosmos/staking/v1beta1/tx.js'; +import type { RequestQuery } from './codegen/tendermint/abci/types.js'; /** * The result of Any.toJSON(). The type in cosms-types says it returns @@ -49,3 +50,24 @@ export const typedJson = ( export type Base64Any = { [Prop in keyof T]: T[Prop] extends Uint8Array ? string : T[Prop]; }; + +// TODO make codegen toJSON() return these instead of unknown +// https://github.com/cosmology-tech/telescope/issues/605 +/** + * Mimics behavor of .toJSON(), converting Uint8Array to base64 strings + * and bigints to strings + */ +export type JsonSafe = { + [Prop in keyof T]: T[Prop] extends Uint8Array + ? string + : T[Prop] extends bigint + ? string + : T[Prop]; +}; + +/** + * The result of RequestQuery.toJSON(). The type in cosms-types says it returns + * `unknown` but it's actually this. The Uint8Array fields are base64 encoded, while + * bigint fields are strings. + */ +export type RequestQueryJson = JsonSafe;