user

package
v0.0.0-...-5e759bf Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2023 License: Apache-2.0 Imports: 10 Imported by: 34

Documentation

Overview

Package user provides functionality related to FrostFS users.

User identity is reflected in ID type. Each user has its own unique identifier within the same network.

FrostFS user identification is compatible with Neo accounts:

import "github.com/nspcc-dev/neo-go/pkg/crypto/keys"
import "github.com/nspcc-dev/neo-go/pkg/crypto/hash"

var id user.ID

var scriptHash util.Uint160 // user account in FrostFS
id.SetScriptHash(scriptHash)

var key keys.PublicKey // user's public key
user.IDFromKey(&id, k.PrivateKey.PublicKey)

ID is compatible with the FrostFS Smart Contract API:

var id user.ID
// ...

wallet := id.WalletBytes()

// use wallet in call

Encoding/decoding mechanisms are used to transfer identifiers:

var id user.ID
// ...

s := id.EncodeToString() // on transmitter
err = id.DecodeString(s) // on receiver

Instances can be also used to process FrostFS API protocol messages (see neo.fs.v2.refs package in https://github.com/TrueCloudLab/frostfs-api).

On client side:

import "github.com/TrueCloudLab/frostfs-api-go/v2/refs"

var msg refs.OwnerID
id.WriteToV2(&msg)

// send msg

On server side:

// recv msg

var id user.ID

err := id.ReadFromV2(msg)
// ...

// process id

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IDFromKey

func IDFromKey(id *ID, key ecdsa.PublicKey)

IDFromKey forms the ID using script hash calculated for the given key.

Types

type ID

type ID struct {
	// contains filtered or unexported fields
}

ID identifies users of the FrostFS system.

ID is mutually compatible with github.com/TrueCloudLab/frostfs-api-go/v2/refs.OwnerID message. See ReadFromV2 / WriteToV2 methods.

Instances can be created using built-in var declaration. Zero ID is not valid, so it MUST be initialized using some modifying function (e.g. SetScriptHash, IDFromKey, etc.).

func (*ID) DecodeString

func (x *ID) DecodeString(s string) error

DecodeString decodes FrostFS API V2 protocol string. Returns an error if s is malformed.

DecodeString always changes the ID.

See also EncodeToString.

func (ID) EncodeToString

func (x ID) EncodeToString() string

EncodeToString encodes ID into FrostFS API V2 protocol string.

See also DecodeString.

func (ID) Equals

func (x ID) Equals(x2 ID) bool

Equals defines a comparison relation between two ID instances.

func (*ID) ReadFromV2

func (x *ID) ReadFromV2(m refs.OwnerID) error

ReadFromV2 reads ID from the refs.OwnerID message. Returns an error if the message is malformed according to the FrostFS API V2 protocol.

See also WriteToV2.

func (*ID) SetScriptHash

func (x *ID) SetScriptHash(scriptHash util.Uint160)

SetScriptHash forms user ID from wallet address scripthash.

func (ID) String

func (x ID) String() string

String implements fmt.Stringer.

String is designed to be human-readable, and its format MAY differ between SDK versions. String MAY return same result as EncodeToString. String MUST NOT be used to encode ID into FrostFS protocol string.

func (ID) WalletBytes

func (x ID) WalletBytes() []byte

WalletBytes returns FrostFS user ID as Neo3 wallet address in a binary format.

Return value MUST NOT be mutated: to do this, first make a copy.

See also Neo3 wallet docs.

func (ID) WriteToV2

func (x ID) WriteToV2(m *refs.OwnerID)

WriteToV2 writes ID to the refs.OwnerID message. The message must not be nil.

See also ReadFromV2.

Directories

Path Synopsis
Package usertest provides functions for convenient testing of user package API.
Package usertest provides functions for convenient testing of user package API.

Jump to

Keyboard shortcuts

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