owner

package
v0.7.6 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2021 License: MIT Imports: 3 Imported by: 11

README

Owner - access control hyperledger fabric chaincode extension

In many cases during chaincode instantiating we need to define permissions for chaincode functions - "who is allowed to do this thing", incredibly important in the world of smart contracts, but in many examples access control implemented at the application level but not at the blockchain layer.

The most common and basic form of access control is the concept of ownership: there's one account (combination of MSP and certificate identifiers) that is the owner and can do administrative tasks on contracts. This approach is perfectly reasonable for contracts that only have a single administrative user.

CCKit provides owner extension for implementing ownership and access control in Hyperledger Fabric chaincodes.

Documentation

Overview

Package owner provides method for storing in chaincode state information about chaincode owner

Index

Constants

View Source
const OwnerStateKey = `OWNER`

OwnerStateKey key used to store owner grant struct in chain code state

View Source
const QueryMethod = `owner`

Variables

View Source
var (
	// ErrOwnerNotProvided occurs when providing owner identity in init arguments
	ErrOwnerNotProvided = errors.New(`owner not provided`)

	// ErrOwnerAlreadySetted owner already setted
	ErrOwnerAlreadySetted = errors.New(`owner already setted`)
)
View Source
var (
	// ErrOwnerOnly error occurs when trying to invoke chaincode func  protected by onlyOwner middleware (modifier)
	ErrOwnerOnly = errors.New(`owner only`)
)

Functions

func Get

func Get(c r.Context) (*identity.Entry, error)

func IdentityEntryFromState

func IdentityEntryFromState(c r.Context) (identity.Entry, error)

IdentityFromState

func Insert

func Insert(c r.Context, mspID string, cert []byte) (*identity.Entry, error)

Insert

func InvokeSetFromArgs added in v0.3.0

func InvokeSetFromArgs(c router.Context) (interface{}, error)

InvokeSetFromArgs gets owner data fron args[0] (Msp Id) and arg[1] (cert)

func InvokeSetFromCreator added in v0.3.0

func InvokeSetFromCreator(c router.Context) (interface{}, error)

InvokeSetFromCreator sets tx creator as chaincode owner, if owner not previously setted

func IsInvoker

func IsInvoker(c r.Context) (bool, error)

IsInvoker checks than tx creator is chain code owner

func IsInvokerOr

func IsInvokerOr(c r.Context, allowedTo ...identity.Identity) (bool, error)

IsInvokerOr checks tx creator and compares with owner of another identity

func IsSetted

func IsSetted(c r.Context) (bool, error)

func Only

func Only(next router.HandlerFunc, pos ...int) router.HandlerFunc

Only allow access from chain code owner

func Query

func Query(c router.Context) (interface{}, error)

FromState returns raw data ( serialized Grant ) of current chain code owner

func SetFromArgs

func SetFromArgs(c r.Context) (*identity.Entry, error)

SetFromArgs set owner fron first args

func SetFromCreator

func SetFromCreator(c r.Context) (*identity.Entry, error)

SetFromCreator sets chain code owner from stub creator

Types

This section is empty.

Jump to

Keyboard shortcuts

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