principal

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

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

func Decode(s string) (Principal, error)

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

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) 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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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