hyperledger-fabric-sdk 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fabric/block_decoder.rb +299 -0
- data/lib/fabric/chaincode_response.rb +47 -0
- data/lib/fabric/channel.rb +55 -34
- data/lib/fabric/client.rb +107 -25
- data/lib/fabric/configuration.rb +12 -4
- data/lib/fabric/constants.rb +1 -1
- data/lib/fabric/crypto_suite.rb +145 -0
- data/lib/fabric/enumerator_queue.rb +26 -0
- data/lib/fabric/error.rb +52 -0
- data/lib/fabric/event_hub.rb +81 -0
- data/lib/fabric/helper.rb +31 -0
- data/lib/fabric/identity.rb +25 -19
- data/lib/fabric/logger.rb +37 -0
- data/lib/fabric/orderer.rb +18 -2
- data/lib/fabric/peer.rb +15 -36
- data/lib/fabric/proposal.rb +100 -0
- data/lib/{protos → fabric/protos}/common/collection_pb.rb +14 -14
- data/lib/{protos → fabric/protos}/common/common_pb.rb +37 -36
- data/lib/fabric/protos/common/configtx_pb.rb +71 -0
- data/lib/{protos → fabric/protos}/common/configuration_pb.rb +13 -13
- data/lib/{protos → fabric/protos}/common/ledger_pb.rb +2 -2
- data/lib/{protos → fabric/protos}/common/policies_pb.rb +19 -19
- data/lib/fabric/protos/discovery/protocol_pb.rb +120 -0
- data/lib/{protos → fabric/protos}/discovery/protocol_services_pb.rb +0 -1
- data/lib/fabric/protos/gossip/message_pb.rb +233 -0
- data/lib/{protos → fabric/protos}/gossip/message_services_pb.rb +0 -1
- data/lib/{protos → fabric/protos}/idemix/idemix_pb.rb +37 -37
- data/lib/{protos → fabric/protos}/ledger/queryresult/kv_query_result_pb.rb +5 -5
- data/lib/fabric/protos/ledger/rwset/kvrwset/kv_rwset_pb.rb +85 -0
- data/lib/fabric/protos/ledger/rwset/rwset_pb.rb +46 -0
- data/lib/{protos → fabric/protos}/msp/identities_pb.rb +4 -4
- data/lib/{protos → fabric/protos}/msp/msp_config_pb.rb +27 -27
- data/lib/{protos → fabric/protos}/msp/msp_principal_pb.rb +20 -20
- data/lib/fabric/protos/orderer/ab_pb.rb +52 -0
- data/lib/{protos → fabric/protos}/orderer/ab_services_pb.rb +0 -1
- data/lib/fabric/protos/orderer/cluster_pb.rb +31 -0
- data/lib/fabric/protos/orderer/cluster_services_pb.rb +31 -0
- data/lib/{protos → fabric/protos}/orderer/configuration_pb.rb +11 -10
- data/lib/fabric/protos/orderer/etcdraft/configuration_pb.rb +21 -0
- data/lib/{protos → fabric/protos}/orderer/kafka_pb.rb +16 -16
- data/lib/{protos → fabric/protos}/peer/admin_pb.rb +12 -12
- data/lib/{protos → fabric/protos}/peer/admin_services_pb.rb +0 -1
- data/lib/{protos → fabric/protos}/peer/chaincode_event_pb.rb +2 -2
- data/lib/fabric/protos/peer/chaincode_pb.rb +60 -0
- data/lib/fabric/protos/peer/chaincode_shim_pb.rb +129 -0
- data/lib/{protos → fabric/protos}/peer/chaincode_shim_services_pb.rb +0 -1
- data/lib/{protos → fabric/protos}/peer/configuration_pb.rb +10 -10
- data/lib/fabric/protos/peer/events_pb.rb +45 -0
- data/lib/fabric/protos/peer/events_services_pb.rb +34 -0
- data/lib/{protos → fabric/protos}/peer/peer_pb.rb +5 -5
- data/lib/{protos → fabric/protos}/peer/peer_services_pb.rb +0 -1
- data/lib/{protos → fabric/protos}/peer/proposal_pb.rb +13 -13
- data/lib/{protos → fabric/protos}/peer/proposal_response_pb.rb +11 -11
- data/lib/{protos → fabric/protos}/peer/query_pb.rb +10 -10
- data/lib/{protos → fabric/protos}/peer/resources_pb.rb +12 -12
- data/lib/{protos → fabric/protos}/peer/signed_cc_dep_spec_pb.rb +3 -3
- data/lib/{protos → fabric/protos}/peer/transaction_pb.rb +22 -18
- data/lib/fabric/protos/token/prover_pb.rb +66 -0
- data/lib/fabric/protos/token/prover_services_pb.rb +33 -0
- data/lib/fabric/protos/token/transaction_pb.rb +41 -0
- data/lib/{protos → fabric/protos}/transientstore/transientstore_pb.rb +4 -4
- data/lib/fabric/queue.rb +26 -0
- data/lib/fabric/transaction.rb +51 -0
- data/lib/fabric/transaction_info.rb +20 -0
- data/lib/fabric/version.rb +1 -1
- data/lib/fabric.rb +74 -0
- data/lib/fabric_ca/attribute.rb +7 -0
- data/lib/fabric_ca/client.rb +11 -19
- data/lib/fabric_ca/configuration.rb +4 -2
- data/lib/fabric_ca/connection.rb +22 -20
- data/lib/fabric_ca/error.rb +3 -2
- data/lib/fabric_ca/faraday_middleware/basic_auth.rb +3 -3
- data/lib/fabric_ca/faraday_middleware/raise_http_exception.rb +13 -13
- data/lib/fabric_ca/faraday_middleware/token_auth.rb +10 -12
- data/lib/fabric_ca/request.rb +13 -24
- data/lib/fabric_ca/version.rb +1 -1
- data/lib/fabric_ca.rb +16 -0
- data/lib/hyperledger-fabric-sdk.rb +2 -47
- metadata +161 -61
- data/lib/crypto_suite/ecdsa_aes.rb +0 -86
- data/lib/fabric/peer_endorser.rb +0 -85
- data/lib/fabric/transaction_id.rb +0 -11
- data/lib/fabric/user.rb +0 -24
- data/lib/fabric_ca/tools.rb +0 -35
- data/lib/protos/common/configtx_pb.rb +0 -71
- data/lib/protos/discovery/protocol_pb.rb +0 -119
- data/lib/protos/gossip/message_pb.rb +0 -233
- data/lib/protos/ledger/rwset/kvrwset/kv_rwset_pb.rb +0 -85
- data/lib/protos/ledger/rwset/rwset_pb.rb +0 -46
- data/lib/protos/orderer/ab_pb.rb +0 -52
- data/lib/protos/peer/chaincode_pb.rb +0 -60
- data/lib/protos/peer/chaincode_shim_pb.rb +0 -94
- data/lib/protos/peer/events_pb.rb +0 -98
- data/lib/protos/peer/events_services_pb.rb +0 -59
data/lib/fabric.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
lib_dir = File.join(__dir__, 'fabric/protos')
|
2
|
+
|
3
|
+
$LOAD_PATH.push(lib_dir) unless $LOAD_PATH.include?(lib_dir)
|
4
|
+
|
5
|
+
require 'colorize'
|
6
|
+
|
7
|
+
require 'common/common_pb'
|
8
|
+
require 'common/configtx_pb'
|
9
|
+
require 'peer/events_services_pb'
|
10
|
+
require 'ledger/rwset/rwset_pb'
|
11
|
+
require 'ledger/rwset/kvrwset/kv_rwset_pb'
|
12
|
+
|
13
|
+
require_relative 'fabric/version'
|
14
|
+
require_relative 'fabric/configuration'
|
15
|
+
require_relative 'fabric/constants'
|
16
|
+
require_relative 'fabric/client'
|
17
|
+
require_relative 'fabric/peer'
|
18
|
+
require_relative 'fabric/orderer'
|
19
|
+
require_relative 'fabric/enumerator_queue'
|
20
|
+
require_relative 'fabric/crypto_suite'
|
21
|
+
require_relative 'fabric/identity'
|
22
|
+
require_relative 'fabric/proposal'
|
23
|
+
require_relative 'fabric/transaction'
|
24
|
+
require_relative 'fabric/error'
|
25
|
+
require_relative 'fabric/logger'
|
26
|
+
require_relative 'fabric/chaincode_response'
|
27
|
+
require_relative 'fabric/channel'
|
28
|
+
require_relative 'fabric/transaction_info'
|
29
|
+
require_relative 'fabric/helper'
|
30
|
+
require_relative 'fabric/block_decoder'
|
31
|
+
require_relative 'fabric/event_hub'
|
32
|
+
|
33
|
+
module Fabric
|
34
|
+
extend Configuration
|
35
|
+
@orderers = []
|
36
|
+
@peers = []
|
37
|
+
|
38
|
+
def self.new(config)
|
39
|
+
@orderers = config[:orderers]
|
40
|
+
@peers = config[:peers]
|
41
|
+
self
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.client(opts = {})
|
45
|
+
client = Fabric::Client.new opts
|
46
|
+
|
47
|
+
@orderers.each { |url| client.register_orderer url, opts }
|
48
|
+
@peers.each { |url| client.register_peer url, opts }
|
49
|
+
|
50
|
+
client
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.channel(opts = {})
|
54
|
+
channel = Fabric::Channel.new opts
|
55
|
+
|
56
|
+
@orderers.each { |url| channel.register_orderer url, opts }
|
57
|
+
@peers.each { |url| channel.register_peer url, opts }
|
58
|
+
|
59
|
+
channel
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.event_hub(opts = {})
|
63
|
+
options = Fabric.options.merge opts
|
64
|
+
|
65
|
+
options[:crypto_suite] ||= Fabric.crypto_suite
|
66
|
+
options[:url] = options[:event_hub_url]
|
67
|
+
|
68
|
+
Fabric::EventHub.new options
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.crypto_suite(opts = {})
|
72
|
+
@crypto_suite ||= Fabric::CryptoSuite.new opts
|
73
|
+
end
|
74
|
+
end
|
data/lib/fabric_ca/client.rb
CHANGED
@@ -1,12 +1,9 @@
|
|
1
|
-
require File.expand_path('../connection', __FILE__)
|
2
|
-
require File.expand_path('../request', __FILE__)
|
3
|
-
|
4
1
|
module FabricCA
|
5
2
|
class Client
|
6
3
|
include Connection
|
7
4
|
include Request
|
8
5
|
|
9
|
-
|
6
|
+
Configuration::VALID_OPTIONS_KEYS.each { |attr| attr_accessor attr }
|
10
7
|
|
11
8
|
def initialize(options = {})
|
12
9
|
options = FabricCA.options.merge(options)
|
@@ -25,27 +22,22 @@ module FabricCA
|
|
25
22
|
conf
|
26
23
|
end
|
27
24
|
|
28
|
-
def enroll(
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
[['CN', identity_context.username]]
|
33
|
-
|
34
|
-
response = post 'enroll', certificate_request: certificate_request.to_s
|
35
|
-
|
36
|
-
identity_context.enroll private_key: private_key,
|
37
|
-
certificate: Base64.decode64(response.result['Cert']),
|
38
|
-
msp_id: msp_id
|
39
|
-
|
40
|
-
identity_context
|
25
|
+
def enroll(certificate_request, attrs = nil)
|
26
|
+
post 'enroll', certificate_request: certificate_request.to_s,
|
27
|
+
caName: ca_name,
|
28
|
+
attr_reqs: attrs
|
41
29
|
end
|
42
30
|
|
43
31
|
def register(params = {})
|
44
32
|
post 'register', params
|
45
33
|
end
|
46
34
|
|
47
|
-
def
|
48
|
-
|
35
|
+
def list_identities(opts = {})
|
36
|
+
get 'identities', opts
|
37
|
+
end
|
38
|
+
|
39
|
+
def list_affiliations(opts = {})
|
40
|
+
get 'affiliations', opts
|
49
41
|
end
|
50
42
|
end
|
51
43
|
end
|
@@ -1,8 +1,10 @@
|
|
1
1
|
module FabricCA
|
2
2
|
module Configuration
|
3
|
-
VALID_OPTIONS_KEYS = [
|
3
|
+
VALID_OPTIONS_KEYS = %i[endpoint ca_name identity
|
4
|
+
username password logger
|
5
|
+
connection_opts].freeze
|
4
6
|
|
5
|
-
attr_accessor
|
7
|
+
VALID_OPTIONS_KEYS.each { |attr| attr_accessor attr }
|
6
8
|
|
7
9
|
def self.extended(base)
|
8
10
|
base.reset
|
data/lib/fabric_ca/connection.rb
CHANGED
@@ -1,32 +1,34 @@
|
|
1
1
|
require 'faraday_middleware'
|
2
2
|
|
3
|
-
Dir[File.expand_path('
|
3
|
+
Dir[File.expand_path('faraday_middleware/*.rb', __dir__)].each { |f| require_relative f }
|
4
4
|
|
5
5
|
module FabricCA
|
6
6
|
module Connection
|
7
7
|
private
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
9
|
+
def connection(opts = {})
|
10
|
+
Faraday::Connection.new(opts.merge(options)) do |connection|
|
11
|
+
connection.use ::FaradayMiddleware::EncodeJson
|
12
|
+
connection.use FabricCA::FaradayMiddleware::BasicAuth, username, password
|
13
|
+
connection.use FabricCA::FaradayMiddleware::TokenAuth, identity
|
14
|
+
connection.use ::Faraday::Request::UrlEncoded
|
15
|
+
connection.use ::FaradayMiddleware::Mashify
|
16
|
+
connection.use ::Faraday::Response::ParseJson
|
17
|
+
connection.use FabricCA::FaradayMiddleware::RaiseHttpException, logger
|
18
|
+
connection.adapter(adapter)
|
20
19
|
end
|
20
|
+
end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
url: endpoint
|
25
|
-
}
|
26
|
-
end
|
22
|
+
def options
|
23
|
+
opts = connection_opts || {}
|
27
24
|
|
28
|
-
|
29
|
-
|
30
|
-
|
25
|
+
opts[:url] = endpoint
|
26
|
+
|
27
|
+
opts
|
28
|
+
end
|
29
|
+
|
30
|
+
def adapter
|
31
|
+
Faraday.default_adapter
|
32
|
+
end
|
31
33
|
end
|
32
34
|
end
|
data/lib/fabric_ca/error.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
module FabricCA
|
2
2
|
class Error < StandardError
|
3
|
-
attr_reader :response
|
3
|
+
attr_reader :response, :full_message
|
4
4
|
|
5
5
|
def initialize(message, response)
|
6
6
|
super message
|
7
7
|
|
8
|
-
@response = response
|
8
|
+
@response = Hashie::Mash.new JSON.parse(response.body)
|
9
|
+
@full_message = @response.errors.map(&:message).join(', ')
|
9
10
|
end
|
10
11
|
end
|
11
12
|
end
|
@@ -4,7 +4,7 @@ module FabricCA
|
|
4
4
|
module FaradayMiddleware
|
5
5
|
class RaiseHttpException < Faraday::Middleware
|
6
6
|
## Variables
|
7
|
-
LOGGER_TAG = 'FABRIC CA'
|
7
|
+
LOGGER_TAG = 'FABRIC CA'.freeze
|
8
8
|
|
9
9
|
## Attributes
|
10
10
|
attr_reader :app, :logger
|
@@ -28,20 +28,20 @@ module FabricCA
|
|
28
28
|
|
29
29
|
private
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
31
|
+
def build_error_message(response)
|
32
|
+
[
|
33
|
+
response[:method].to_s.upcase,
|
34
|
+
response[:url],
|
35
|
+
response[:status],
|
36
|
+
response[:body]
|
37
|
+
].join(', ')
|
38
|
+
end
|
39
39
|
|
40
|
-
|
41
|
-
|
40
|
+
def logging(message)
|
41
|
+
return unless logger
|
42
42
|
|
43
|
-
|
44
|
-
|
43
|
+
logger.tagged(LOGGER_TAG) { |logger| logger.error message }
|
44
|
+
end
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
@@ -4,10 +4,10 @@ require 'base64'
|
|
4
4
|
module FabricCA
|
5
5
|
module FaradayMiddleware
|
6
6
|
class TokenAuth < Faraday::Middleware
|
7
|
-
attr_reader :app, :
|
7
|
+
attr_reader :app, :identity
|
8
8
|
|
9
9
|
def call(env)
|
10
|
-
if
|
10
|
+
if identity
|
11
11
|
env[:request_headers] =
|
12
12
|
env[:request_headers].merge(
|
13
13
|
'Authorization' => generate_auth_header(env)
|
@@ -17,22 +17,20 @@ module FabricCA
|
|
17
17
|
app.call env
|
18
18
|
end
|
19
19
|
|
20
|
-
def initialize(app,
|
20
|
+
def initialize(app, identity)
|
21
21
|
@app = app
|
22
|
-
@
|
22
|
+
@identity = identity
|
23
23
|
end
|
24
24
|
|
25
25
|
private
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
cert = Base64.strict_encode64 identity.certificate
|
31
|
-
body_and_cert = body + '.' + cert
|
32
|
-
sign = Base64.strict_encode64 identity.sign(body_and_cert)
|
27
|
+
def generate_auth_header(env)
|
28
|
+
body = Base64.strict_encode64(env.body.to_s)
|
29
|
+
body_and_cert = body + '.' + identity.certificate
|
33
30
|
|
34
|
-
|
35
|
-
|
31
|
+
identity.certificate + '.' +
|
32
|
+
Base64.strict_encode64(identity.sign(body_and_cert))
|
33
|
+
end
|
36
34
|
end
|
37
35
|
end
|
38
36
|
end
|
data/lib/fabric_ca/request.rb
CHANGED
@@ -18,33 +18,22 @@ module FabricCA
|
|
18
18
|
|
19
19
|
private
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
def request(method, path, params, options)
|
22
|
+
response = send_request method, path, params, options
|
23
23
|
|
24
|
-
|
25
|
-
|
24
|
+
Response.create response.body
|
25
|
+
end
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
p method
|
36
|
-
p options
|
37
|
-
request.path = URI.encode path
|
38
|
-
request.body = params unless params.empty?
|
39
|
-
request.options.params_encoder = Encoder.new
|
40
|
-
end
|
27
|
+
def send_request(method, path, params, options)
|
28
|
+
connection(options).send(method) do |request|
|
29
|
+
case method
|
30
|
+
when :get, :delete
|
31
|
+
request.url(URI.encode(path), params)
|
32
|
+
when :post, :put
|
33
|
+
request.path = URI.encode path
|
34
|
+
request.body = params unless params.empty?
|
41
35
|
end
|
42
36
|
end
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
class Encoder
|
47
|
-
def encode(param)
|
48
|
-
param.to_json
|
37
|
+
end
|
49
38
|
end
|
50
39
|
end
|
data/lib/fabric_ca/version.rb
CHANGED
data/lib/fabric_ca.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require_relative 'fabric_ca/version'
|
2
|
+
require_relative 'fabric_ca/configuration'
|
3
|
+
require_relative 'fabric_ca/error'
|
4
|
+
require_relative 'fabric_ca/connection'
|
5
|
+
require_relative 'fabric_ca/request'
|
6
|
+
require_relative 'fabric_ca/response'
|
7
|
+
require_relative 'fabric_ca/client'
|
8
|
+
require_relative 'fabric_ca/attribute'
|
9
|
+
|
10
|
+
module FabricCA
|
11
|
+
extend Configuration
|
12
|
+
|
13
|
+
def self.new(options = {})
|
14
|
+
FabricCA::Client.new(options)
|
15
|
+
end
|
16
|
+
end
|
@@ -1,47 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
require_relative 'fabric/version'
|
5
|
-
require_relative 'fabric/configuration'
|
6
|
-
require_relative 'fabric/constants'
|
7
|
-
require_relative 'fabric/client'
|
8
|
-
require_relative 'fabric/peer_endorser'
|
9
|
-
require_relative 'fabric/transaction_id'
|
10
|
-
require_relative 'fabric/channel'
|
11
|
-
require_relative 'fabric/peer'
|
12
|
-
require_relative 'fabric/orderer'
|
13
|
-
require_relative 'fabric/user'
|
14
|
-
require_relative 'fabric/identity'
|
15
|
-
|
16
|
-
require_relative 'fabric_ca/error'
|
17
|
-
require_relative 'fabric_ca/configuration'
|
18
|
-
require_relative 'fabric_ca/client'
|
19
|
-
require_relative 'fabric_ca/response'
|
20
|
-
require_relative 'fabric_ca/version'
|
21
|
-
require_relative 'fabric_ca/tools'
|
22
|
-
|
23
|
-
require_relative 'crypto_suite/ecdsa_aes'
|
24
|
-
|
25
|
-
require 'common/common_pb'
|
26
|
-
require 'common/configtx_pb'
|
27
|
-
|
28
|
-
module Fabric
|
29
|
-
extend Configuration
|
30
|
-
|
31
|
-
def self.new(config)
|
32
|
-
client = Fabric::Client.new config[:options]
|
33
|
-
|
34
|
-
config[:orderer_urls].each { |url| client.new_orderer url }
|
35
|
-
config[:peer_urls].each { |url| client.new_peer url }
|
36
|
-
|
37
|
-
client
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
module FabricCA
|
42
|
-
extend Configuration
|
43
|
-
|
44
|
-
def self.new(options = {})
|
45
|
-
FabricCA::Client.new(options)
|
46
|
-
end
|
47
|
-
end
|
1
|
+
require_relative 'fabric'
|
2
|
+
require_relative 'fabric_ca'
|