aip

package module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: MIT Imports: 10 Imported by: 4

README

go-aip

Library for working with Author Identity Protocol in Go

Release Build Status Report codecov Go
Mergify Status Sponsor Donate


Table of Contents


Installation

go-aip requires a supported release of Go.

go get -u github.com/bitcoinschema/go-aip

Documentation

View the generated documentation

GoDoc

Features
Package Dependencies
Library Deployment

goreleaser for easy binary or library deployment to Github and can be installed via: brew install goreleaser.

The .goreleaser.yml file is used to configure goreleaser.

Use make release-snap to create a snapshot version of the release, and finally make release to ship to production.

Makefile Commands

View all makefile commands

make help

List of all current commands:

all                   Runs multiple commands
clean                 Remove previous builds and any test cache data
clean-mods            Remove all the Go mod cache
coverage              Shows the test coverage
diff                  Show the git diff
generate              Runs the go generate command in the base of the repo
godocs                Sync the latest tag with GoDocs
help                  Show this help message
install               Install the application
install-go            Install the application (Using Native Go)
install-releaser      Install the GoReleaser application
lint                  Run the golangci-lint application (install if not found)
release               Full production release (creates release in Github)
release               Runs common.release then runs godocs
release-snap          Test the full release (build binaries)
release-test          Full production test release (everything except deploy)
replace-version       Replaces the version in HTML/JS (pre-deploy)
tag                   Generate a new tag and push (tag version=0.0.0)
tag-remove            Remove a tag if found (tag-remove version=0.0.0)
tag-update            Update an existing tag to current commit (tag-update version=0.0.0)
test                  Runs lint and ALL tests
test-ci               Runs all tests via CI (exports coverage)
test-ci-no-race       Runs all tests via CI (no race) (exports coverage)
test-ci-short         Runs unit tests via CI (exports coverage)
test-no-lint          Runs just tests
test-short            Runs vet, lint and tests (excludes integration tests)
test-unit             Runs tests and outputs coverage
uninstall             Uninstall the application (and remove files)
update-linter         Update the golangci-lint package (macOS only)
vet                   Run the Go vet application

Examples & Tests

All unit tests and examples run via GitHub Actions and uses Go version 1.18.x. View the configuration file.

Run all tests (including integration tests)

make test

Run tests (excluding integration tests)

make test-short

Benchmarks

Run the Go benchmarks:

make bench

Code Standards

Read more about this Go project's code standards.


Usage

Checkout all the examples!


Maintainers

MrZ MrZ
Satchmo MrZ

Contributing

View the contributing guidelines and follow the code of conduct.

How can I help?

All kinds of contributions are welcome 🙌! The most basic way to show your support is to star 🌟 the project, or to raise issues 💬. You can also support this project by becoming a sponsor on GitHub 👏 or by making a bitcoin donation to ensure this journey continues indefinitely! 🚀


License

License

Documentation

Overview

Package aip is a library for working with Author Identity Protocol (AIP) in Go

If you have any suggestions or comments, please feel free to open an issue on this GitHub repository!

By BitcoinSchema Organization (https://bitcoinschema.org)

Index

Examples

Constants

This section is empty.

Variables

View Source
var Prefix = "15PciHG22SNLQJXMoSUaWVi7WSqc7hCfva"

Prefix is the Bitcom prefix used by AIP

Functions

func ValidateTapes

func ValidateTapes(tapes []bpu.Tape) (bool, error)

ValidateTapes validates the AIP signature for a given []bob.Tape

Example

ExampleValidateTapes example using ValidateTapes()

// Get BOB data from a TX
bobValidData, err := bob.NewFromString(sampleValidBobTx)
if err != nil {
	fmt.Printf("error occurred: %s", err.Error())
	return
}

// Get from tape
if valid, err := ValidateTapes(bobValidData.Out[0].Tape); valid {
	fmt.Print("AIP is valid")
} else if err != nil {
	fmt.Printf("AIP is invalid: %s", err.Error())
}
Output:

AIP is valid

Types

type Aip

type Aip struct {
	Algorithm                 Algorithm `json:"algorithm"`                   // Known AIP algorithm type
	AlgorithmSigningComponent string    `json:"algorithm_signing_component"` // Changes based on the Algorithm
	Data                      []string  `json:"data"`                        // Data to be signed or validated
	Indices                   []int     `json:"indices,omitempty"`           // BOB indices
	Signature                 string    `json:"signature"`                   // AIP generated signature
}

Aip is an Author Identity Protocol object

func NewFromTape added in v0.0.10

func NewFromTape(tape bpu.Tape) (a *Aip)

NewFromTape will create a new AIP object from a bob.Tape Using the FromTape() alone will prevent validation (data is needed via SetData to enable)

Example

ExampleNewFromTape example using NewFromTape()

// Get BOB data from a TX
bobValidData, err := bob.NewFromString(sampleValidBobTx)
if err != nil {
	fmt.Printf("error occurred: %s", err.Error())
	return
}

// Get from tape given the AIP index
a := NewFromTape(bobValidData.Out[0].Tape[2])

fmt.Printf("address: %s signature: %s", a.AlgorithmSigningComponent, a.Signature)
Output:

address: 134a6TXxzgQ9Az3w8BcvgdZyA5UqRL89da signature: H+lubfcz5Z2oG8B7HwmP8Z+tALP+KNOPgedo7UTXwW8LBpMkgCgatCdpvbtf7wZZQSIMz83emmAvVS4S3F5X1wo=

func NewFromTapes added in v0.0.12

func NewFromTapes(tapes []bpu.Tape) (a *Aip)

NewFromTapes will create a new AIP object from a []bob.Tape Using the FromTapes() alone will prevent validation (data is needed via SetData to enable)

Example

ExampleNewFromTapes example using NewFromTapes()

// Get BOB data from a TX
bobValidData, err := bob.NewFromString(sampleValidBobTx)
if err != nil {
	fmt.Printf("error occurred: %s", err.Error())
	return
}

// Get from tape given the AIP index
a := NewFromTapes(bobValidData.Out[0].Tape)

fmt.Printf("address: %s signature: %s", a.AlgorithmSigningComponent, a.Signature)
Output:

address: 134a6TXxzgQ9Az3w8BcvgdZyA5UqRL89da signature: H+lubfcz5Z2oG8B7HwmP8Z+tALP+KNOPgedo7UTXwW8LBpMkgCgatCdpvbtf7wZZQSIMz83emmAvVS4S3F5X1wo=

func Sign added in v0.0.10

func Sign(privateKey string, algorithm Algorithm, message string) (a *Aip, err error)

Sign will provide an AIP signature for a given private key and message using the provided algorithm. It prepends an OP_RETURN to the payload

Example

ExampleSign example using Sign()

a, err := Sign(examplePrivateKey, BitcoinECDSA, exampleMessage)
if err != nil {
	fmt.Printf("error occurred: %s", err.Error())
	return
}
fmt.Printf("address: %s signature: %s", a.AlgorithmSigningComponent, a.Signature)
Output:

address: 1Dw6EeFNRZStXTUENRrV9tGUh1rT2hi6YP signature: HNQwm/7FV7S5wzDf4L+HayG8PVhenwgeZ0T5QuNnVGbtSe+7L+Um7lxcrjsj7eMi3N4K1dAOqrVbkESkQfV7odc=
Example (Paymail)

ExampleSign_paymail example using Sign()

a, err := Sign(examplePrivateKey, Paymail, exampleMessage)
if err != nil {
	fmt.Printf("error occurred: %s", err.Error())
	return
}
fmt.Printf("address: %s signature: %s", a.AlgorithmSigningComponent, a.Signature)
Output:

address: 041b8c93100d35bd448f4646cc4678f278351b439b52b303ea31ec9edb5475e73f36e7ef720509250313fcf1b4c5af0dc7c5efa126efe2c3b7008e6f1487c61f31 signature: HNQwm/7FV7S5wzDf4L+HayG8PVhenwgeZ0T5QuNnVGbtSe+7L+Um7lxcrjsj7eMi3N4K1dAOqrVbkESkQfV7odc=

func SignBobOpReturnData added in v0.0.10

func SignBobOpReturnData(privateKey string, algorithm Algorithm, output bpu.Output) (*bpu.Output, *Aip, error)

SignBobOpReturnData appends a signature to a BOB Tx by adding a protocol separator followed by AIP information

func SignOpReturnData added in v0.0.10

func SignOpReturnData(privateKey string, algorithm Algorithm,
	data [][]byte) (outData [][]byte, a *Aip, err error)

SignOpReturnData will append the given data and return a bt.Output

Example

ExampleSignOpReturnData example using SignOpReturnData()

outData, a, err := SignOpReturnData(examplePrivateKey, BitcoinECDSA, [][]byte{[]byte("some op_return data")})
if err != nil {
	fmt.Printf("error occurred: %s", err.Error())
	return
}
fmt.Printf("signature: %s outData: %x", a.Signature, outData)
Output:

signature: G7zptA7IbNaa7PQlblH1v5ElaOj3Zo49oiUrDMqfWM4QFNdIKDnXMkxLU1YgrxODd8uFNU279utUCC4MGPp5pjM= outData: [736f6d65206f705f72657475726e2064617461 313550636948473232534e4c514a584d6f5355615756693757537163376843667661 424954434f494e5f4543445341 314477364565464e525a5374585455454e5272563974475568317254326869365950 47377a7074413749624e61613750516c626c48317635456c614f6a335a6f34396f695572444d7166574d3451464e64494b446e584d6b784c5531596772784f44643875464e553237397574554343344d47507035706a4d3d]

func (*Aip) FromTape

func (a *Aip) FromTape(tape bpu.Tape)

FromTape takes a BOB Tape and returns an Aip data structure. Using the FromTape() alone will prevent validation (data is needed via SetData to enable)

func (*Aip) SetDataFromTapes added in v0.0.12

func (a *Aip) SetDataFromTapes(tapes []bpu.Tape)

SetDataFromTapes sets the data the AIP signature is signing

func (*Aip) Validate

func (a *Aip) Validate() (bool, error)

Validate returns true if the given AIP signature is valid for given data

Example

ExampleAip_Validate example using Validate()

a, err := Sign(examplePrivateKey, BitcoinECDSA, exampleMessage)
if err != nil {
	fmt.Printf("error occurred: %s", err.Error())
	return
}

if valid, err := a.Validate(); valid {
	fmt.Printf("valid signature: %s", a.Signature)
} else if err != nil {
	fmt.Printf("signature validation failed: %s", err.Error())
}
Output:

valid signature: HNQwm/7FV7S5wzDf4L+HayG8PVhenwgeZ0T5QuNnVGbtSe+7L+Um7lxcrjsj7eMi3N4K1dAOqrVbkESkQfV7odc=

type Algorithm

type Algorithm string

Algorithm is an enum for the different possible signature algorithms

const (
	BitcoinECDSA         Algorithm = "BITCOIN_ECDSA"        // Backwards compatible for BitcoinSignedMessage
	BitcoinSignedMessage Algorithm = "BitcoinSignedMessage" // New algo name
	Paymail              Algorithm = "paymail"              // Using "pubkey" as aip.Address
)

Algorithm names

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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