Documentation ¶
Index ¶
- Variables
- type AccountIdentifier
- type Principal
- func (p Principal) Encode() string
- func (p Principal) Equal(other Principal) bool
- func (p Principal) IsAnonymous() bool
- func (p Principal) IsDerived() bool
- func (p Principal) IsOpaque() bool
- func (p Principal) IsReserved() bool
- func (p Principal) IsSelfAuthenticating() bool
- func (p Principal) MarshalCBOR() ([]byte, error)
- func (p Principal) MarshalJSON() ([]byte, error)
- func (p Principal) String() string
- func (p *Principal) UnmarshalCBOR(bytes []byte) error
- func (p *Principal) UnmarshalJSON(bytes []byte) error
- type SubAccount
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var AnonymousID = Principal{Raw: []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 ¶ added in v0.3.0
func DecodeAccountID(s string) (AccountIdentifier, error)
DecodeAccountID decodes the given string into an account identifier.
func NewAccountID ¶ added in v0.3.0
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/aviate-labs/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 ¶ added in v0.3.0
func (id AccountIdentifier) Encode() string
Encode returns the hexadecimal representation of the account identifier.
func (AccountIdentifier) MarshalJSON ¶ added in v0.4.4
func (id AccountIdentifier) MarshalJSON() ([]byte, error)
MarshalJSON encodes the account identifier into JSON bytes as a string.
func (AccountIdentifier) String ¶
func (id AccountIdentifier) String() string
String returns the hexadecimal representation of the account identifier.
func (*AccountIdentifier) UnmarshalJSON ¶ added in v0.4.4
func (id *AccountIdentifier) UnmarshalJSON(bytes []byte) error
UnmarshalJSON decodes the given JSON bytes into an account identifier from a string.
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/aviate-labs/agent-go/principal" ) func main() { raw, _ := hex.DecodeString("abcd01") p := principal.Principal{Raw: 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/aviate-labs/agent-go/principal" ) func main() { p, _ := principal.Decode("em77e-bvlzu-aq") fmt.Printf("%x", p.Raw) }
Output: abcd01
func MustDecode ¶ added in v0.4.4
MustDecode converts a textual representation into a principal. It panics if the input is invalid.
func NewRandomPrincipal ¶ added in v0.4.4
func NewRandomPrincipal() Principal
NewRandomPrincipal returns a new random principal.
func NewSelfAuthenticating ¶
NewSelfAuthenticating returns a self authenticating principal identifier based on the given public key.
func (Principal) IsAnonymous ¶ added in v0.4.4
IsAnonymous checks if the principal is the anonymous id.
func (Principal) IsOpaque ¶ added in v0.4.4
IsOpaque checks if the principal is opaque, these are always generated by the IC and have no structure of interest outside of it.
func (Principal) IsReserved ¶ added in v0.4.4
IsReserved checks if the principal is reserved. These ids can be useful for applications that want to re-use the Textual representation of principals but want to indicate explicitly that the blob does not address any canisters or a user.
func (Principal) IsSelfAuthenticating ¶ added in v0.4.4
IsSelfAuthenticating checks if the principal is self authenticating, an external user can use these ids as the sender of a request if they own the corresponding private key.
func (Principal) MarshalCBOR ¶
MarshalCBOR converts the principal to its CBOR representation.
func (Principal) MarshalJSON ¶ added in v0.4.4
MarshalJSON converts the principal to its JSON representation as a string.
func (*Principal) UnmarshalCBOR ¶
UnmarshalCBOR converts a CBOR representation into a principal.
func (*Principal) UnmarshalJSON ¶ added in v0.4.4
UnmarshalJSON converts the JSON bytes into a principal from a string.