dashmsg

package module
v0.10.4 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2022 License: MIT Imports: 14 Imported by: 0

README

dashmsg

Sign and Verify messages with Dash Private Keys

dashmsg sign --cointype 0x4c \
    'XK5DHnAiSj6HQNsNcDkawd9qdp8UFMdYftdVZFuRreTMJtbJhk8i' \
    'dte2022-akerdemelidis|estoever|mmason'
dashmsg verify \
    'Xn4A2vv5fb7LvmiiXPPMexYbSbiQ29rzDu' \
    'dte2022-akerdemelidis|estoever|mmason' \
    'H2Opy9NX72iPZRcDVEHrFn2qmVwWMgc+DKILdVxl1yfmcL2qcpu9esw9wcD7RH0/dJHnIISe5j39EYahorWQM7I='

Also useful for and inspecting debugging:

  • coin type (network) byte
  • payment address of private key
  • i (quadrant), r, and s of signature

Usage

dashmsg help
dashmsg v0.9.1 (xxxxxxx) 2022-03-13T11:45:52-0700

Usage
    dashmsg <command> [flags] args...

See usage: dashmsg help <command>

Commands:
    version
    gen [--cointype '0xcc'] [name.wif]
    sign [--cointype '0x4c'] <key> <msg>
    inspect [--cointype '0x4c'] <key | address | signature>
    decode (alias of inspect)
    verify <payment address> <msg> <signature>

Examples:
    dashmsg gen ./dash.wif

    dashmsg sign dash.wif ./msg.txt
    dashmsg sign dash.wif 'my message'
    dashmsg sign 'Xxxx...ccc' 'my message'

    dashmsg inspect --verbose 'Xxxxxxxxxxxxxxxxxxxxxxxxxxxxcccccc'

    dashmsg verify Xxxx...ccc 'my message' 'II....signature...'
    dashmsg verify ./addr.b58c.txt ./msg.txt ./sig.b64.txt

How to Build

git clone https://github.com/dashhive/dashmsg
pushd ./dashmsg/
go build -mod=vendor -o dashmsg ./cmd/dashmsg/
GoReleaser

Because one of the dependencies requires CGO_ENABLED=1 and uses low-level syscalls (I have no idea why - probably completely unnecessary), it must be built on and released from the respective OSes.

goreleaser -f .goreleaser.yml --rm-dist --single-target --skip-validate
--single-target - build only for the current OS
--skip-validate - uploads the image even though it can update the checksums

Note: MacOS actually can build both the amd64 and arm64 versions on an M1.

Go Library

Documentation at https://pkg.go.dev/github.com/dashhive/dashmsg.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// CheckVersion is the Base58Check magic version (coin / network type) byte signifying the payment address coin type (i.e. Dash, Public Key, mainnet)
	CheckVersion = "4c" // Dash mainnet (vs 0x00 for BC)

	// CheckVersionTest is CheckVersion, but for testnet
	CheckVersionTest = "8c" // Dash testnet

	// WIFVersion is the Base58Check magic version (coin / network type) byte signifying the wallet type (i.e. Dash, Private Key, mainnet)
	WIFVersion = "cc" // Dash mainnet (vs 0x80 for BC)

	// WIFVersionTest is WIFVersion, but for testnet
	WIFVersionTest = "ef" // Dash testnet

	// MagicBytes is the secure delimiter that scopes a message to a particular network
	MagicBytes = []byte("DarkCoin Signed Message:\n")
)

Functions

func AddressToCointype added in v0.10.0

func AddressToCointype(addr string) (string, error)

AddressToCointype reads the magic version (coin / network type) from the base58check address

func DoubleHash

func DoubleHash(buf []byte) []byte

DoubleHash simply runs one sha256 sum in series with another

func EncodeToBCVarint

func EncodeToBCVarint(m int) []byte

EncodeToBCVarint is a special variable-width byte encoding for 8, 16, 32, or 64-bit integers. For integers less than 253 bytes it uses a single bit. 253, 254, and 255 signify a 16, 32, and 64-bit (2, 4, and 8-byte) little-endian encodings respectively.

func GenerateWIF

func GenerateWIF(magicVersion string) string

GenerateWIF creates a new wallet private key as WIF

func MagicConcat

func MagicConcat(magicBytes, msg []byte) []byte

MagicConcat combines the magic bytes (which signify the network the message belongs to) and message, with their respective lengths (encoded as BCVarint) prepended to each

func MagicHash

func MagicHash(msg []byte) []byte

MagicHash combines the magic bytes and message, with their respective lengths (encoded as BCVarint) prepended to each, and then double hashes the result

func MagicSign

func MagicSign(priv *ecdsa.PrivateKey, msg []byte) ([]byte, error)

MagicSign scopes the signature of a message to the Dash network

func MagicVerify added in v0.10.1

func MagicVerify(addr Base58Check, msg []byte, sig Base64) error

MagicVerify checks that the given public key hash payment address can be used to verify the given base64 signature and arbitrary message

func MarshalPublicKey

func MarshalPublicKey(pub ecdsa.PublicKey) []byte

MarshalPublicKey uses elliptic.Marshal to output the secp256k1.S256() curve public key

func PublicKeyToAddress

func PublicKeyToAddress(magicVersion string, pub ecdsa.PublicKey) string

PublicKeyToAddress transforms a PublicKey into a PubKeyHash address is Base58Check format

func SigToPub

func SigToPub(magichash, dsig []byte) (*ecdsa.PublicKey, error)

SigToPub computes the public key from the message's magichash and the recovery signature (has the magic byte, a.k.a. "i" at the front of it)

func WIFToPrivateKey

func WIFToPrivateKey(wif string) (string, *ecdsa.PrivateKey, error)

WIFToPrivateKey decodes the base58check (WIF) into the network magicVersion and a standard(ish) ECDSA private key

Types

type Base58Check added in v0.10.1

type Base58Check = string

Base58Check indicates that the given string should be in Base58Check encoded (coint type prefix on double hash of public key, BaseX-style Base58 encoding)

type Base64 added in v0.10.1

type Base64 = string

Base64 indicates that the given string should be Base64 encoded (std, with padding)

type CompactSignature

type CompactSignature struct {
	I int
	R []byte
	S []byte
}

CompactSignature is the 65-byte Dash signature with the magic "i" recovery int as the first byte

func DecodeSignature

func DecodeSignature(b64 string) (*CompactSignature, error)

DecodeSignature will break a Dash message signature into its component parts of "i" (the pub key recovery int), and "r" and "s" - the normal (non-ASN.1) ECDSA signature parts

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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