signature

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 10, 2024 License: AGPL-3.0 Imports: 8 Imported by: 2

README

signature

The signature package serves a centralized module for validating signatures.

Example Usage

package main

import (
    "log"

    "github.com/rddl-network/go-utils/signature"
    "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
)

func main() {
    privKey := secp256k1.GenPrivKey()
    pubKey := privKey.PubKey()
    
    msg := []byte("msg")
    sign, err := privKey.Sign(msg)
    if err != nil {
        log.Fatalln(err)
    }

    hexMsg := hex.EncodeToString(msg)
    hexSign := hex.EncodeToString(sign)
    hexPublicKey := hex.EncodeToString(pubKey.Bytes())
    
    isValid, err := signature.ValidateSignature(hexMsg, hexSign, hexPublicKey)
    if err != nil {
        log.Fatalln(err)
    }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PublicKeyToUncompressedBytes added in v0.1.0

func PublicKeyToUncompressedBytes(pub *ecdsa.PublicKey) []byte

func UncompressedBytesToPublicKey added in v0.1.0

func UncompressedBytesToPublicKey(b []byte) (*ecdsa.PublicKey, error)

func ValidateSECP256R1Signature added in v0.1.0

func ValidateSECP256R1Signature(hexMessage string, hexSignature string, hexPublicKey string) (bool, error)

ValidateSECP256R1Signature takes the hex-encoded message together with r, s of the signature (combined as []byte{r.Bytes()..., s.Bytes()...}) and x, y (combined as []byte{0x04, x.Bytes()..., y.Bytes()...}) of the public key

func ValidateSignature

func ValidateSignature(hexMessage string, hexSignature string, hexPublicKey string) (bool, error)

Types

type ECDSASignature added in v0.1.0

type ECDSASignature struct {
	R, S *big.Int
}

Jump to

Keyboard shortcuts

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