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 NewFromAllTapes(tapes []bpu.Tape) []*Aip
- func NewFromTape(tape bpu.Tape) (a *Aip)
- func NewFromTapes(tapes []bpu.Tape) (a *Aip)
- func Sign(privateKey *ec.PrivateKey, algorithm Algorithm, message string) (a *Aip, err error)
- func SignBobOpReturnData(privateKey *ec.PrivateKey, algorithm Algorithm, output bpu.Output) (*bpu.Output, *Aip, error)
- func SignOpReturnData(privateKey *ec.PrivateKey, 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 NewFromAllTapes ¶ added in v0.3.2
NewFromAllTapes will create all AIP objects from a []bob.Tape
func NewFromTape ¶ added in v0.0.10
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
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: 1DfGxKmgL3ETwUdNnXLBueEvNpjcDGcKgK signature: INQwm/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: 031b8c93100d35bd448f4646cc4678f278351b439b52b303ea31ec9edb5475e73f signature: INQwm/7FV7S5wzDf4L+HayG8PVhenwgeZ0T5QuNnVGbtSe+7L+Um7lxcrjsj7eMi3N4K1dAOqrVbkESkQfV7odc=
func SignBobOpReturnData ¶ added in v0.0.10
func SignBobOpReturnData(privateKey *ec.PrivateKey, 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 *ec.PrivateKey, 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: H7zptA7IbNaa7PQlblH1v5ElaOj3Zo49oiUrDMqfWM4QFNdIKDnXMkxLU1YgrxODd8uFNU279utUCC4MGPp5pjM= outData: [736f6d65206f705f72657475726e2064617461 313550636948473232534e4c514a584d6f5355615756693757537163376843667661 424954434f494e5f4543445341 31446647784b6d674c3345547755644e6e584c42756545764e706a634447634b674b 48377a7074413749624e61613750516c626c48317635456c614f6a335a6f34396f695572444d7166574d3451464e64494b446e584d6b784c5531596772784f44643875464e553237397574554343344d47507035706a4d3d]
func (*Aip) FromTape ¶
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
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: INQwm/7FV7S5wzDf4L+HayG8PVhenwgeZ0T5QuNnVGbtSe+7L+Um7lxcrjsj7eMi3N4K1dAOqrVbkESkQfV7odc=

