Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var AnonymousID = Principal{[]byte{0x04}}
AnonymousID is used for the anonymous caller. It can be used in call and query requests without a signature.
var ( // DefaultSubAccount is the default sub-account represented by the empty byte array. DefaultSubAccount [32]byte )
Functions ¶
This section is empty.
Types ¶
type AccountIdentifier ¶
type AccountIdentifier [28]byte
AccountIdentifier is a unique identifier for an account.
func DecodeAccountID ¶
func DecodeAccountID(s string) (AccountIdentifier, error)
DecodeAccountID decodes the given string into an account identifier.
func NewAccountID ¶
func NewAccountID(p Principal, subAccount [32]byte) AccountIdentifier
NewAccountID returns the account identifier corresponding with the given sub-account.
Example ¶
package main import ( "fmt" "github.com/mohaijiang/agent-go/principal" ) func main() { fmt.Println(principal.NewAccountID(principal.Principal{}, principal.DefaultSubAccount).String()) }
Output: 2d0e897f7e862d2b57d9bc9ea5c65f9a24ac6c074575f47898314b8d6cb0929d
func (AccountIdentifier) Bytes ¶
func (id AccountIdentifier) Bytes() []byte
Bytes returns the bytes of the account identifier, including the checksum.
func (AccountIdentifier) Encode ¶
func (id AccountIdentifier) Encode() string
Encode returns the hexadecimal representation of the account identifier.
func (AccountIdentifier) String ¶
func (id AccountIdentifier) String() string
String returns the hexadecimal representation of the account identifier.
type Principal ¶
type Principal struct {
Raw []byte
}
Principal are generic identifiers for canisters, users and possibly other concepts in the future.
Example ¶
package main import ( "encoding/hex" "fmt" "github.com/mohaijiang/agent-go/principal" ) func main() { raw, _ := hex.DecodeString("abcd01") p := principal.Principal{raw} fmt.Println(p.Encode()) }
Output: em77e-bvlzu-aq
func Decode ¶
Decode converts a textual representation into a principal.
Example ¶
package main import ( "fmt" "github.com/mohaijiang/agent-go/principal" ) func main() { p, _ := principal.Decode("em77e-bvlzu-aq") fmt.Printf("%x", p.Raw) }
Output: abcd01
func NewSelfAuthenticating ¶
NewSelfAuthenticating returns a self authenticating principal identifier based on the given public key.
func (Principal) MarshalCBOR ¶
MarshalCBOR converts the principal to its CBOR representation.
func (*Principal) UnmarshalCBOR ¶
UnmarshalCBOR converts a CBOR representation into a principal.