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 ¶
CreateSignBytes creates the bytes to be signed for ADR-036. This is the canonical JSON serialization of the SignDoc.
func NormalizeToLowS ¶
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 ¶
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 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 ¶
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 ¶
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.