adr036

package
v0.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package adr036 implements ADR-036 off-chain message signing and verification. See: https://docs.cosmos.network/main/build/architecture/adr-036-arbitrary-signature

Note: This package uses custom Coin/Fee types instead of sdk.Coin because ADR-036 requires the legacy Amino JSON format with string amounts. The SDK's sdk.Coin uses math.Int which serializes differently and would produce invalid sign documents that wallets cannot verify.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateSignBytes

func CreateSignBytes(message []byte, signer string) []byte

CreateSignBytes creates the bytes to be signed for ADR-036. This is the canonical JSON serialization of the SignDoc.

func NormalizeToLowS

func NormalizeToLowS(sig []byte) []byte

NormalizeToLowS normalizes a 64-byte secp256k1 signature to low-S canonical form. ECDSA signatures have two valid forms: (r, s) and (r, N-s). This function ensures the S value is in the lower half of the curve order, producing a unique canonical representation. This prevents signature malleability where an attacker flips the S value to create a different-but-valid signature.

Returns the normalized signature (may be the same slice if already low-S), or nil if the input is not a valid 64-byte signature.

func VerifySignature

func VerifySignature(pubKeyBytes, message, signature []byte, signer string) error

VerifySignature verifies an ADR-036 off-chain signature. The signature is normalized to low-S canonical form before verification to accept both (r, s) and (r, N-s) forms.

Parameters:

  • pubKeyBytes: 33-byte compressed secp256k1 public key
  • message: the original message that was signed
  • signature: the signature bytes (64 bytes for secp256k1)
  • signer: the bech32 address of the signer (used in the sign doc)

Returns nil if the signature is valid, otherwise an error.

Types

type Coin

type Coin struct {
	Denom  string `json:"denom"`
	Amount string `json:"amount"`
}

Coin represents a coin amount (used in fee structure).

type Fee

type Fee struct {
	Amount []Coin `json:"amount"`
	Gas    string `json:"gas"`
}

Fee represents the fee structure in ADR-036 (always zero for off-chain).

type MsgValue

type MsgValue struct {
	Data   string `json:"data"`   // Base64-encoded message data
	Signer string `json:"signer"` // Bech32 address of the signer
}

MsgValue contains the actual sign data.

type MsgWrapper

type MsgWrapper struct {
	Type  string   `json:"type"`
	Value MsgValue `json:"value"`
}

MsgWrapper wraps the ADR-036 message.

type SignDoc

type SignDoc struct {
	AccountNumber string       `json:"account_number"`
	ChainID       string       `json:"chain_id"`
	Fee           Fee          `json:"fee"`
	Memo          string       `json:"memo"`
	Msgs          []MsgWrapper `json:"msgs"`
	Sequence      string       `json:"sequence"`
}

SignDoc represents the ADR-036 sign document structure. This is the canonical format that wallets sign for off-chain messages.

func CreateSignDoc

func CreateSignDoc(message []byte, signer string) *SignDoc

CreateSignDoc creates an ADR-036 SignDoc for the given message and signer. This can be used by clients to construct the document they need to sign.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL