github.com/bigzoro/my_simplechain@v0.0.0-20240315012955-8ad0a2a29bb9/core/access_contoller/access_provider_interface.go (about)

     1  package access_contoller
     2  
     3  import "github.com/bigzoro/my_simplechain/core/access_contoller/crypto"
     4  
     5  const (
     6  	//PermissionedWithCert permissioned with certificate
     7  	PermissionedWithCert string = "permissionedwithcert"
     8  
     9  	//PermissionedWithKey permissioned with public key
    10  	PermissionedWithKey string = "permissionedwithkey"
    11  
    12  	// Public public key
    13  	Public string = "public"
    14  
    15  	// Identity (1.X PermissionedWithCert)
    16  	Identity string = "identity"
    17  )
    18  
    19  type AccessControlProvider interface {
    20  
    21  	// GetHashAlg return hash algorithm the access control provider uses
    22  	GetHashAlg() string
    23  
    24  	// ValidateResourcePolicy checks whether the given resource policy is valid
    25  	//ValidateResourcePolicy(resourcePolicy *params.ResourcePolicy) bool
    26  
    27  	// LookUpPolicy returns corresponding policy configured for the given resource name
    28  	//LookUpPolicy(resourceName string) (*params.Policy, error)
    29  
    30  	// LookUpExceptionalPolicy returns corresponding exceptional policy configured for the given resource name
    31  	//LookUpExceptionalPolicy(resourceName string) (*params.Policy, error)
    32  
    33  	//GetAllPolicy returns all policies
    34  	//GetAllPolicy() (map[string]*params.Policy, error)
    35  
    36  	// CreatePrincipal creates a principal for one time authentication
    37  	CreatePrincipal(resourceName string, endorsements []*EndorsementEntry, message []byte) (Principal, error)
    38  
    39  	// CreatePrincipalForTargetOrg creates a principal for "SELF" type policy,
    40  	// which needs to convert SELF to a sepecific organization id in one authentication
    41  	//CreatePrincipalForTargetOrg(resourceName string, endorsements []*common.EndorsementEntry, message []byte,
    42  	//	targetOrgId string) (Principal, error)
    43  
    44  	//GetValidEndorsements filters all endorsement entries and returns all valid ones
    45  	//GetValidEndorsements(principal Principal) ([]*common.EndorsementEntry, error)
    46  
    47  	// VerifyPrincipal verifies if the policy for the resource is met
    48  	VerifyPrincipal(principal Principal) (bool, error)
    49  
    50  	// RefineEndorsements verifies endorsements
    51  	//RefineEndorsements(endorsements []*common.EndorsementEntry, msg []byte) []*common.EndorsementEntry
    52  
    53  	// NewMember creates a member from pb Member
    54  	//NewMember(member *pbac.Member) (Member, error)
    55  
    56  	//GetMemberStatus get the status information of the member
    57  	//GetMemberStatus(member *pbac.Member) (pbac.MemberStatus, error)
    58  
    59  	//VerifyRelatedMaterial verify the member's relevant identity material
    60  	//VerifyRelatedMaterial(verifyType pbac.VerifyType, data []byte) (bool, error)
    61  }
    62  
    63  // Principal contains all information related to one time verification
    64  type Principal interface {
    65  	// GetResourceName returns resource name of the verification
    66  	GetResourceName() string
    67  
    68  	// GetEndorsement returns all endorsements (signatures) of the verification
    69  	GetEndorsement() []*EndorsementEntry
    70  
    71  	// GetMessage returns signing data of the verification
    72  	GetMessage() []byte
    73  
    74  	// GetTargetOrgId returns target organization id of the verification if the verification is for a specific organization
    75  	GetTargetOrgId() string
    76  }
    77  
    78  // Member is the identity of a node or user.
    79  type MemberInterface interface {
    80  	// GetMemberId returns the identity of this member (non-uniqueness)
    81  	GetMemberId() string
    82  
    83  	// GetOrgId returns the organization id which this member belongs to
    84  	GetOrgId() string
    85  
    86  	// GetRole returns roles of this member
    87  	GetRole() Role
    88  
    89  	// GetUid returns the identity of this member (unique)
    90  	GetUid() string
    91  
    92  	// Verify verifies a signature over some message using this member
    93  	Verify(hashType string, msg []byte, sig []byte) error
    94  
    95  	// GetMember returns Member
    96  	GetMember() (*Member, error)
    97  
    98  	//GetPk returns public key
    99  	GetPk() crypto.PublicKey
   100  }
   101  
   102  type SigningMember interface {
   103  	// Extends Member interface
   104  	MemberInterface
   105  
   106  	// Sign signs the message with the given hash type and returns signature bytes
   107  	Sign(hashType string, msg []byte) ([]byte, error)
   108  }