principal

package
v0.3.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2023 License: Apache-2.0 Imports: 8 Imported by: 13

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var AnonymousID = Principal{[]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 (AccountIdentifier) Bytes

func (id AccountIdentifier) Bytes() []byte

Bytes returns the bytes of the account identifier, including the checksum.

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/aviate-labs/agent-go/principal"
)

func main() {
	raw, _ := hex.DecodeString("abcd01")
	p := principal.Principal{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 NewSelfAuthenticating

func NewSelfAuthenticating(pub []byte) Principal

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

func (Principal) AccountIdentifier

func (p Principal) AccountIdentifier(subAccount [32]byte) AccountIdentifier

AccountIdentifier returns the account identifier corresponding with the given sub-account.

func (Principal) Encode

func (p Principal) Encode() string

Encode converts the principal to its textual representation.

func (Principal) MarshalCBOR

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

MarshalCBOR converts the principal to its CBOR representation.

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.

type SubAccount

type SubAccount [32]byte

SubAccount is the sub-account identifier for an account.

Jump to

Keyboard shortcuts

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