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 ¶
- type ID
- func (x *ID) DecodeString(s string) error
- func (x ID) EncodeToString() string
- func (x ID) Equals(x2 ID) bool
- func (x *ID) ReadFromV2(m refs.OwnerID) error
- func (x *ID) SetScriptHash(scriptHash util.Uint160)
- func (x ID) String() string
- func (x ID) WalletBytes() []byte
- func (x ID) WriteToV2(m *refs.OwnerID)
- type Signer
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 ¶
ResolveFromECDSAPublicKey resolves ID from the given ecdsa.PublicKey.
func (*ID) DecodeString ¶
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 ¶
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) ReadFromV2 ¶
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 ¶
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 ¶
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 ¶
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:
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.