user

package
v1.0.0-rc.20 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: Apache-2.0 Imports: 12 Imported by: 70

Documentation

Overview

Package user provides functionality related to NeoFS users.

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

Index

Examples

Constants

View Source
const IDSize = 25

IDSize is the size of an ID in bytes.

Variables

View Source
var ErrZeroID = errors.New("zero user ID")

ErrZeroID is an error returned on zero ID encounter.

Functions

This section is empty.

Types

type ID

type ID [IDSize]byte

ID identifies users of the NeoFS system and represents Neo3 account address. Zero ID is usually prohibited, see docs for details.

ID implements built-in comparable interface.

ID is mutually compatible with refs.OwnerID message. See ID.FromProtoMessage / ID.ProtoMessage methods.

Example (Marshalling)

Instances can be also used to process NeoFS API V2 protocol messages with [https://github.com/nspcc-dev/neofs-api] package.

package main

import (
	"github.com/nspcc-dev/neofs-sdk-go/user"
)

func main() {
	// On the client side.

	var id user.ID
	msg := id.ProtoMessage()
	// *send message*

	// On the server side.

	_ = id.FromProtoMessage(msg)
}

func DecodeString

func DecodeString(s string) (ID, error)

DecodeString creates new ID and makes ID.DecodeString.

func NewFromECDSAPublicKey

func NewFromECDSAPublicKey(pub ecdsa.PublicKey) ID

NewFromECDSAPublicKey creates new ID corresponding to Neo3 verification script hash of the given ECDSA public key. The point must be on the [elliptic.P256] curve.

func NewFromScriptHash

func NewFromScriptHash(scriptHash util.Uint160) ID

NewFromScriptHash creates new ID and makes [ID.SetScriptHash].

func (*ID) DecodeString

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

DecodeString decodes NeoFS API V2 protocol string. Returns an error if s is malformed. Use DecodeString to decode s into a new ID.

DecodeString always changes the ID.

See also EncodeToString.

Example

Encoding mechanisms are used to transfer identifiers on server.

package main

import (
	"github.com/nspcc-dev/neofs-sdk-go/user"
)

func main() {
	var id user.ID
	// ...

	var s string
	_ = id.DecodeString(s)
}

func (ID) EncodeToString

func (x ID) EncodeToString() string

EncodeToString encodes ID into NeoFS API V2 protocol string.

See also DecodeString.

Example

Encoding mechanisms are used to transfer identifiers on client.

package main

import (
	"github.com/nspcc-dev/neofs-sdk-go/user"
)

func main() {
	var id user.ID
	// ...

	_ = id.EncodeToString()
}

func (*ID) FromProtoMessage

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

FromProtoMessage validates m according to the NeoFS API protocol and restores x from it.

See also ID.ProtoMessage.

func (ID) IsZero

func (x ID) IsZero() bool

IsZero checks whether ID is zero.

func (ID) ProtoMessage

func (x ID) ProtoMessage() *refs.OwnerID

ProtoMessage converts x into message to transmit using the NeoFS API protocol.

See also ID.FromProtoMessage.

func (ID) ScriptHash

func (x ID) ScriptHash() util.Uint160

ScriptHash gets scripthash from user ID.

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 NeoFS protocol string.

type Signer

type Signer interface {
	// Signer signs data on behalf of the user.
	neofscrypto.Signer
	// UserID returns ID of the associated user.
	UserID() ID
}

Signer represents a NeoFS user authorized by a digital signature.

func NewAutoIDSigner

func NewAutoIDSigner(key ecdsa.PrivateKey) Signer

NewAutoIDSigner returns Signer with neofscrypto.ECDSA_SHA512 signature scheme and user ID automatically resolved from the ECDSA public key.

See also NewAutoIDSignerRFC6979.

func NewAutoIDSignerRFC6979

func NewAutoIDSignerRFC6979(key ecdsa.PrivateKey) Signer

NewAutoIDSignerRFC6979 is an analogue of NewAutoIDSigner but with neofscrypto.ECDSA_DETERMINISTIC_SHA256 signature scheme.

func NewSigner

func NewSigner(s neofscrypto.Signer, usr ID) Signer

NewSigner combines provided neofscrypto.Signer and ID into Signer.

See also NewAutoIDSigner.

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