Skip to content

Commit 45e822b

Browse files
committed
[FAB-9644] Interfaces for pluggable endorsement/valid
This change set adds interfaces for the pluggable endorsement and validation. Change-Id: I51d1cbf55e7b01ec0bf173fe9a92f953591af448 Signed-off-by: yacovm <yacovm@il.ibm.com>
1 parent 2561a4b commit 45e822b

File tree

6 files changed

+223
-0
lines changed

6 files changed

+223
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package endorsement
8+
9+
import (
10+
"github.com/hyperledger/fabric/protos/peer"
11+
)
12+
13+
// Argument defines the argument for endorsement
14+
type Argument interface {
15+
Dependency
16+
// Arg returns the bytes of the argument
17+
Arg() []byte
18+
}
19+
20+
// Dependency marks a dependency passed to the Init() method
21+
type Dependency interface {
22+
}
23+
24+
// Plugin endorses a proposal response
25+
type Plugin interface {
26+
// Endorse signs the given payload(ProposalResponsePayload bytes), and optionally mutates it.
27+
// Returns:
28+
// The Endorsement: A signature over the payload, and an identity that is used to verify the signature
29+
// The payload that was given as input (could be modified within this function)
30+
// Or error on failure
31+
Endorse(payload []byte, sp *peer.SignedProposal) (*peer.Endorsement, []byte, error)
32+
33+
// Init injects dependencies into the instance of the Plugin
34+
Init(dependencies ...Dependency) error
35+
}
36+
37+
// PluginFactory creates a new instance of a Plugin
38+
type PluginFactory interface {
39+
New() Plugin
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package endorsement
8+
9+
import (
10+
"github.com/hyperledger/fabric/core/handlers/endorsement/api"
11+
"github.com/hyperledger/fabric/protos/peer"
12+
)
13+
14+
// SigningIdentity signs messages and serializes its public identity to bytes
15+
type SigningIdentity interface {
16+
// Serialize returns a byte representation of this identity which is used to verify
17+
// messages signed by this SigningIdentity
18+
Serialize() ([]byte, error)
19+
20+
// Sign signs the given payload and returns a signature
21+
Sign([]byte) ([]byte, error)
22+
}
23+
24+
// SigningIdentityFetcher fetches a signing identity based on the proposal
25+
type SigningIdentityFetcher interface {
26+
endorsement.Dependency
27+
// SigningIdentityForRequest returns a signing identity for the given proposal
28+
SigningIdentityForRequest(*peer.SignedProposal) (SigningIdentity, error)
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package endorsement
8+
9+
import (
10+
"github.com/hyperledger/fabric/core/handlers/endorsement/api"
11+
"github.com/hyperledger/fabric/protos/ledger/rwset"
12+
)
13+
14+
// State defines interaction with the world state
15+
type State interface {
16+
endorsement.Dependency
17+
// GetPrivateDataMultipleKeys gets the values for the multiple private data items in a single call
18+
GetPrivateDataMultipleKeys(namespace, collection string, keys []string) ([][]byte, error)
19+
20+
// GetStateMultipleKeys gets the values for multiple keys in a single call
21+
GetStateMultipleKeys(namespace string, keys []string) ([][]byte, error)
22+
23+
// GetTransientByTXID gets the values private data associated with the given txID
24+
GetTransientByTXID(txID string) ([]*rwset.TxPvtReadWriteSet, error)
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package validation
8+
9+
import (
10+
"github.com/hyperledger/fabric/core/handlers/validation/api"
11+
"github.com/hyperledger/fabric/protos/msp"
12+
)
13+
14+
// IdentityDeserializer converts serialized identities
15+
// to identities.
16+
type IdentityDeserializer interface {
17+
validation.Dependency
18+
// DeserializeIdentity deserializes an identity.
19+
// Deserialization will fail if the identity is associated to
20+
// an msp that is different from this one that is performing
21+
// the deserialization.
22+
DeserializeIdentity(serializedIdentity []byte) (Identity, error)
23+
}
24+
25+
// Identity interface defining operations associated to a "certificate".
26+
// That is, the public part of the identity could be thought to be a certificate,
27+
// and offers solely signature verification capabilities. This is to be used
28+
// at the peer side when verifying certificates that transactions are signed
29+
// with, and verifying signatures that correspond to these certificates.///
30+
type Identity interface {
31+
// Validate uses the rules that govern this identity to validate it.
32+
Validate() error
33+
34+
// SatisfiesPrincipal checks whether this instance matches
35+
// the description supplied in MSPPrincipal. The check may
36+
// involve a byte-by-byte comparison (if the principal is
37+
// a serialized identity) or may require MSP validation
38+
SatisfiesPrincipal(principal *msp.MSPPrincipal) error
39+
40+
// Verify a signature over some message using this identity as reference
41+
Verify(msg []byte, sig []byte) error
42+
43+
// GetIdentityIdentifier returns the identifier of that identity
44+
GetIdentityIdentifier() *IdentityIdentifier
45+
46+
// GetMSPIdentifier returns the MSP Id for this instance
47+
GetMSPIdentifier() string
48+
}
49+
50+
// IdentityIdentifier is a holder for the identifier of a specific
51+
// identity, naturally namespaced, by its provider identifier.
52+
type IdentityIdentifier struct {
53+
54+
// The identifier of the associated membership service provider
55+
Mspid string
56+
57+
// The identifier for an identity within a provider
58+
Id string
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package validation
8+
9+
import "github.com/hyperledger/fabric/core/handlers/validation/api"
10+
11+
// State defines interaction with the world state
12+
type State interface {
13+
validation.Dependency
14+
// GetStateMultipleKeys gets the values for multiple keys in a single call
15+
GetStateMultipleKeys(namespace string, keys []string) ([][]byte, error)
16+
17+
// GetStateRangeScanIterator returns an iterator that contains all the key-values between given key ranges.
18+
// startKey is included in the results and endKey is excluded. An empty startKey refers to the first available key
19+
// and an empty endKey refers to the last available key. For scanning all the keys, both the startKey and the endKey
20+
// can be supplied as empty strings. However, a full scan should be used judiciously for performance reasons.
21+
// The returned ResultsIterator contains results of type *KV which is defined in protos/ledger/queryresult.
22+
GetStateRangeScanIterator(namespace string, startKey string, endKey string) (ResultsIterator, error)
23+
}
24+
25+
// ResultsIterator - an iterator for query result set
26+
type ResultsIterator interface {
27+
// Next returns the next item in the result set. The `QueryResult` is expected to be nil when
28+
// the iterator gets exhausted
29+
Next() (QueryResult, error)
30+
// Close releases resources occupied by the iterator
31+
Close()
32+
}
33+
34+
// QueryResult - a general interface for supporting different types of query results. Actual types differ for different queries
35+
type QueryResult interface{}
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package validation
8+
9+
import "github.com/hyperledger/fabric/protos/common"
10+
11+
// Argument defines the argument for validation
12+
type Argument interface {
13+
Dependency
14+
// Arg returns the bytes of the argument
15+
Arg() []byte
16+
}
17+
18+
// Dependency marks a dependency passed to the Init() method
19+
type Dependency interface {
20+
}
21+
22+
// Plugin validates transactions
23+
type Plugin interface {
24+
// Validate returns nil if the action at the given position inside the transaction
25+
// at the given position in the given block is valid, or an error if not.
26+
Validate(block *common.Block, namespace string, txPosition int, actionPosition int) error
27+
28+
// Init injects dependencies into the instance of the Plugin
29+
Init(dependencies ...Dependency) error
30+
}
31+
32+
// PluginFactory creates a new instance of a Plugin
33+
type PluginFactory interface {
34+
New() Plugin
35+
}

0 commit comments

Comments
 (0)