Documentation
¶
Overview ¶
Package aleo_utils implements Aleo-compatible Schnorr signing.
Example ¶
package main
import (
"log"
aleo "github.com/venture23-aleo/aleo-utils-go"
)
func main() {
// create Aleo wrapper
wrapper, closeFn, err := aleo.NewWrapper()
if err != nil {
log.Fatalln(err)
}
defer closeFn()
// create a new session
s, err := wrapper.NewSession()
if err != nil {
log.Fatalln(err)
}
// generate a new Aleo private key
privKey, address, err := s.NewPrivateKey()
if err != nil {
log.Fatalln(err)
}
// create a formatted message. the message fits in 1 512-byte block, so that's how many we request.
// the formatted message is an equivalent of Leo type Data with 1 DataChunk
// struct DataChunk {
// f0: u128,
// ...
// f31: u128
// }
// struct Data {
// c0: DataChunk
// }
formattedMessage, err := s.FormatMessage([]byte("btc/usd = 1.0"), 1)
if err != nil {
log.Fatalln(err)
}
// formatted message can be signed as is or hashed first
hashedMessage, err := s.HashMessage(formattedMessage)
if err != nil {
log.Fatalln(err)
}
// sign a message
signature, err := s.Sign(privKey, hashedMessage)
if err != nil {
log.Fatalln(err)
}
log.Println("Formatted message:", formattedMessage)
log.Println("Signature:", signature)
log.Println("Address:", address)
log.Println("Poseidon8 hash:", hashedMessage)
log.Println("Private key:", string(privKey))
}
Output:
Index ¶
Examples ¶
Constants ¶
View Source
const ( PRIVATE_KEY_SIZE = 59 ADDRESS_SIZE = 63 SIGNATURE_SIZE = 216 MESSAGE_FORMAT_BLOCK_SIZE = 16 * 32 MAX_FORMAT_MESSAGE_CHUNKS = 32 )
Variables ¶
View Source
var ErrNoModule = errors.New("session module is closed")
View Source
var ErrNoRuntime = errors.New("no runtime, create new wrapper")
Functions ¶
This section is empty.
Types ¶
type Session ¶
type Session interface {
// NewPrivateKey returns a newly generated private key as a byte slice and the
// corresponding address. The caller is responsible for zeroizing the returned
// slice when it is no longer needed (see ZeroizePrivateKey).
NewPrivateKey() (key []byte, address string, err error)
FormatMessage(message []byte, targetChunks int) (formattedMessage []byte, err error)
RecoverMessage(formattedMessage []byte) (message []byte, err error)
HashMessageToString(message []byte) (hash string, err error)
HashMessage(message []byte) (hash []byte, err error)
// Sign creates an Aleo-compatible Schnorr signature. The private key is not
// copied as a string and is wiped from WASM memory immediately after use.
Sign(key []byte, message []byte) (signature string, err error)
Close()
}
Provides access to wrapper functionality. A session is not goroutine safe so you need to create a new one for every goroutine
type Wrapper ¶
Wrapper is an interface for Aleo Wrapper session manager. Create an instance of a Wrapper using NewWrapper, then create a new Session to use the signing functionality.
func NewWrapper ¶
NewWrapper creates Leo contract compatible Schnorr wrapper manager. The second argument is a cleanup function, which destroys wrapper runtime. aleoWrapper cannot be used after the cleanup function is called, and must be recreated using this function.
Click to show internal directories.
Click to hide internal directories.