Class: Fabric::Identity
- Inherits:
-
Object
- Object
- Fabric::Identity
- Defined in:
- lib/fabric/entities/identity.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#certificate ⇒ String
raw certificate in pem format.
-
#crypto_suite ⇒ Object
readonly
Returns the value of attribute crypto_suite.
-
#msp_id ⇒ String
MSP (Membership Service Provider) Identifier.
-
#private_key ⇒ String
readonly
raw private key in hex format.
-
#public_key ⇒ String
readonly
raw public key in hex format.
Instance Method Summary collapse
-
#as_proto ⇒ Object
-
#digest(message) ⇒ Object
-
#generate_csr(attrs = []) ⇒ Object
-
#initialize(private_key: nil, public_key: nil, certificate: nil, msp_id: nil, crypto_suite: nil) ⇒ Identity
constructor
A new instance of Identity.
-
#new_gateway(client) ⇒ Fabric::Gateway
Creates a new gateway passing in the current identity.
-
#shared_secret_by(public_key) ⇒ Object
TODO: Do we need this?.
-
#sign(message) ⇒ Object
-
#to_proto ⇒ Object
-
#validate_key_integrity ⇒ boolean
Validates that the private_key, public_key, and certificate are valid and match.
Constructor Details
#initialize(private_key: nil, public_key: nil, certificate: nil, msp_id: nil, crypto_suite: nil) ⇒ Identity
Returns a new instance of Identity.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/fabric/entities/identity.rb', line 24 def initialize(private_key: nil, public_key: nil, certificate: nil, msp_id: nil, crypto_suite: nil) @crypto_suite = crypto_suite || Fabric.crypto_suite @private_key = private_key || @crypto_suite.generate_private_key @public_key = public_key || @crypto_suite.restore_public_key(@private_key) @certificate = certificate @msp_id = msp_id @address = @crypto_suite.address_from_public_key @public_key return unless @certificate raise Fabric::Error, 'Key mismatch (public_key or certificate) for identity' unless validate_key_integrity end |
Instance Attribute Details
#address ⇒ Object (readonly)
Returns the value of attribute address.
17 18 19 |
# File 'lib/fabric/entities/identity.rb', line 17 def address @address end |
#certificate ⇒ String
raw certificate in pem format
16 17 18 |
# File 'lib/fabric/entities/identity.rb', line 16 def certificate @certificate end |
#crypto_suite ⇒ Object (readonly)
Returns the value of attribute crypto_suite.
17 18 19 |
# File 'lib/fabric/entities/identity.rb', line 17 def crypto_suite @crypto_suite end |
#msp_id ⇒ String
MSP (Membership Service Provider) Identifier
16 17 18 |
# File 'lib/fabric/entities/identity.rb', line 16 def msp_id @msp_id end |
#private_key ⇒ String (readonly)
raw private key in hex format
16 17 18 |
# File 'lib/fabric/entities/identity.rb', line 16 def private_key @private_key end |
#public_key ⇒ String (readonly)
raw public key in hex format
16 17 18 |
# File 'lib/fabric/entities/identity.rb', line 16 def public_key @public_key end |
Instance Method Details
#as_proto ⇒ Object
68 69 70 |
# File 'lib/fabric/entities/identity.rb', line 68 def as_proto @as_proto ||= Msp::SerializedIdentity.new(mspid: msp_id, id_bytes: certificate) end |
#digest(message) ⇒ Object
59 60 61 |
# File 'lib/fabric/entities/identity.rb', line 59 def digest() @crypto_suite.digest end |
#generate_csr(attrs = []) ⇒ Object
51 52 53 |
# File 'lib/fabric/entities/identity.rb', line 51 def generate_csr(attrs = []) @crypto_suite.generate_csr private_key, attrs end |
#new_gateway(client) ⇒ Fabric::Gateway
Creates a new gateway passing in the current identity
83 84 85 |
# File 'lib/fabric/entities/identity.rb', line 83 def new_gateway(client) Fabric::Gateway.new(self, client) end |
#shared_secret_by(public_key) ⇒ Object
TODO: Do we need this?
64 65 66 |
# File 'lib/fabric/entities/identity.rb', line 64 def shared_secret_by(public_key) @crypto_suite.build_shared_key private_key, public_key end |
#sign(message) ⇒ Object
55 56 57 |
# File 'lib/fabric/entities/identity.rb', line 55 def sign() @crypto_suite.sign(private_key, ) end |
#to_proto ⇒ Object
72 73 74 |
# File 'lib/fabric/entities/identity.rb', line 72 def to_proto @to_proto ||= Msp::SerializedIdentity.new(mspid: msp_id, id_bytes: certificate).to_proto end |
#validate_key_integrity ⇒ boolean
Validates that the private_key, public_key, and certificate are valid and match
44 45 46 47 48 49 |
# File 'lib/fabric/entities/identity.rb', line 44 def validate_key_integrity cert_pubkey = @crypto_suite.pkey_from_x509_certificate(certificate) priv_pubkey = @crypto_suite.restore_public_key(@private_key) @public_key == cert_pubkey && @public_key == priv_pubkey end |