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 ¶
- Variables
- func ValidateTapes(tapes []bpu.Tape) (bool, error)
- type Aip
- func NewFromTape(tape bpu.Tape) (a *Aip)
- func NewFromTapes(tapes []bpu.Tape) (a *Aip)
- func Sign(privateKey string, algorithm Algorithm, message string) (a *Aip, err error)
- func SignBobOpReturnData(privateKey string, algorithm Algorithm, output bpu.Output) (*bpu.Output, *Aip, error)
- func SignOpReturnData(privateKey string, algorithm Algorithm, data [][]byte) (outData [][]byte, a *Aip, err error)
- type Algorithm
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var Prefix = "15PciHG22SNLQJXMoSUaWVi7WSqc7hCfva"
Prefix is the Bitcom prefix used by AIP
Functions ¶
func ValidateTapes ¶
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
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 ¶
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=