diff --git a/packages/amino/src/index.ts b/packages/amino/src/index.ts index 340fd598..7c576317 100644 --- a/packages/amino/src/index.ts +++ b/packages/amino/src/index.ts @@ -20,3 +20,4 @@ export { } from "./pubkeys"; export { createMultisigThresholdPubkey } from "./multisig"; export { decodeSignature, encodeSecp256k1Signature, StdSignature } from "./signature"; +export { AccountData, Algo, AminoMsg, AminoSignResponse, OfflineAminoSigner, StdSignDoc } from "./signer"; diff --git a/packages/amino/src/signer.ts b/packages/amino/src/signer.ts new file mode 100644 index 00000000..fcfce60c --- /dev/null +++ b/packages/amino/src/signer.ts @@ -0,0 +1,67 @@ +/* eslint-disable @typescript-eslint/naming-convention */ +import { StdSignature } from "./signature"; + +export interface AminoMsg { + readonly type: string; + readonly value: any; +} + +interface Coin { + readonly denom: string; + readonly amount: string; +} + +interface StdFee { + readonly amount: readonly Coin[]; + readonly gas: string; +} + +/** + * The document to be signed + * + * @see https://docs.cosmos.network/master/modules/auth/03_types.html#stdsigndoc + */ +export interface StdSignDoc { + readonly chain_id: string; + readonly account_number: string; + readonly sequence: string; + readonly fee: StdFee; + readonly msgs: readonly AminoMsg[]; + readonly memo: string; +} + +export type Algo = "secp256k1" | "ed25519" | "sr25519"; + +export interface AccountData { + /** A printable address (typically bech32 encoded) */ + readonly address: string; + readonly algo: Algo; + readonly pubkey: Uint8Array; +} + +export interface AminoSignResponse { + /** + * The sign doc that was signed. + * This may be different from the input signDoc when the signer modifies it as part of the signing process. + */ + readonly signed: StdSignDoc; + readonly signature: StdSignature; +} + +export interface OfflineAminoSigner { + /** + * Get AccountData array from wallet. Rejects if not enabled. + */ + readonly getAccounts: () => Promise; + + /** + * Request signature from whichever key corresponds to provided bech32-encoded address. Rejects if not enabled. + * + * The signer implementation may offer the user the ability to override parts of the signDoc. It must + * return the doc that was signed in the response. + * + * @param signerAddress The address of the account that should sign the transaction + * @param signDoc The content that should be signed + */ + readonly signAmino: (signerAddress: string, signDoc: StdSignDoc) => Promise; +}