principal

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2022 License: Apache-2.0 Imports: 7 Imported by: 3

README

Principal

Docs GoDoc

Principal are generic identifiers for canisters and users.

Usage

raw, _ := hex.DecodeString("abcd01")
p := principal.Principal(raw)
fmt.Println(p.Encode())
// Output:
// em77e-bvlzu-aq

Special Forms

Opaque Identifiers

These are always generated by the system and have no structure of interest outside the system. Typically, these end with the byte 0x01.

Self-Authenticating Identifiers

An external user can use these ids as the sender of a request if they own the corresponding private key.

sha224(public_key) 0x02
Derived Identifiers

Derived IDs are currently not explicitly used, but they may be used internally or in the future.

sha224(len(registering_principal) registering_principal derivation_nonce) 0x03
Anonymous Identifiers

Used for the anonymous caller. It can be used in call and query requests without a signature.

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 [32]byte
)

Functions

This section is empty.

Types

type AccountIdentifier added in v0.2.1

type AccountIdentifier [28]byte

func (AccountIdentifier) String added in v0.2.1

func (id AccountIdentifier) String() string

type Principal

type Principal struct {
	Raw []byte
}

Principal are generic identifiers for canisters, users and possibly other concepts in the future.

Example
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
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 added in v0.2.1

func (p Principal) AccountIdentifier(subAccount [32]byte) 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) String added in v0.2.2

func (p Principal) String() string

type SubAccount added in v0.2.1

type SubAccount [32]byte

Jump to

Keyboard shortcuts

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