principal

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 2, 2024 License: Apache-2.0 Imports: 11 Imported by: 16

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
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.

View Source
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

func Decode(s string) (Principal, error)

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

func MustDecode(s string) Principal

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

func NewSelfAuthenticating(pub []byte) Principal

NewSelfAuthenticating returns a self authenticating principal identifier based on the given public key.

func (Principal) Encode

func (p Principal) Encode() string

Encode converts the principal to its textual representation.

func (Principal) Equal added in v0.4.4

func (p Principal) Equal(other Principal) bool

Equal checks if two principals are equal.

func (Principal) IsAnonymous added in v0.4.4

func (p Principal) IsAnonymous() bool

IsAnonymous checks if the principal is the anonymous id.

func (Principal) IsDerived added in v0.4.4

func (p Principal) IsDerived() bool

IsDerived checks if the principal is derived.

func (Principal) IsOpaque added in v0.4.4

func (p Principal) IsOpaque() bool

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

func (p Principal) IsReserved() bool

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

func (p Principal) IsSelfAuthenticating() bool

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

func (p Principal) MarshalCBOR() ([]byte, error)

MarshalCBOR converts the principal to its CBOR representation.

func (Principal) MarshalJSON added in v0.4.4

func (p Principal) MarshalJSON() ([]byte, error)

MarshalJSON converts the principal to its JSON representation as a string.

func (Principal) String

func (p Principal) String() string

String implements the Stringer interface.

func (*Principal) UnmarshalCBOR

func (p *Principal) UnmarshalCBOR(bytes []byte) error

UnmarshalCBOR converts a CBOR representation into a principal.

func (*Principal) UnmarshalJSON added in v0.4.4

func (p *Principal) UnmarshalJSON(bytes []byte) error

UnmarshalJSON converts the JSON bytes into a principal from a string.

type SubAccount

type SubAccount [32]byte

SubAccount is the sub-account identifier for an account.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL