user

package
v1.0.0-rc.11 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2023 License: Apache-2.0 Imports: 12 Imported by: 53

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

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ID

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

ID identifies users of the NeoFS system.

ID is mutually compatible with github.com/nspcc-dev/neofs-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, etc.).

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 (
	apiGoRefs "github.com/nspcc-dev/neofs-api-go/v2/refs"
	"github.com/nspcc-dev/neofs-sdk-go/user"
)

func main() {
	// import apiGoRefs "github.com/nspcc-dev/neofs-api-go/v2/refs"

	// On the client side.

	var id user.ID
	var msg apiGoRefs.OwnerID
	id.WriteToV2(&msg)
	// *send message*

	// On the server side.

	_ = id.ReadFromV2(msg)
}
Output:

func ResolveFromECDSAPublicKey

func ResolveFromECDSAPublicKey(pk ecdsa.PublicKey) ID

ResolveFromECDSAPublicKey resolves ID from the given ecdsa.PublicKey.

func (*ID) DecodeString

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

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

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)
}
Output:

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()
}
Output:

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 NeoFS API V2 protocol.

See also WriteToV2.

func (*ID) SetScriptHash

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

SetScriptHash forms user ID from wallet address scripthash.

Example

NeoFS user identification is compatible with Neo accounts.

package main

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

func main() {
	// import "github.com/nspcc-dev/neo-go/pkg/util"
	var id user.ID

	var scriptHash util.Uint160 // user account in NeoFS
	id.SetScriptHash(scriptHash)
}
Output:

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.

func (ID) WalletBytes

func (x ID) WalletBytes() []byte

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

The value returned shares memory with the structure itself, so changing it can lead to data corruption. Make a copy if you need to change it.

See also Neo3 wallet docs.

Example

ID is compatible with the NeoFS Smart Contract API.

package main

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

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

	wallet := id.WalletBytes()
	_ = wallet

	// use wallet in call
}
Output:

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.

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