class Fabric::Identity

@attr_reader [String] private_key raw private key in hex format @attr_reader [String] public_key raw public key in hex format @attr_reader [String] certificate raw certificate in pem format @attr_reader [String] msp_id MSP (Membership Service Provider) Identifier

Attributes

address[R]
certificate[RW]
crypto_suite[R]
msp_id[RW]
private_key[R]
public_key[R]

Public Class Methods

new(private_key: nil, public_key: nil, certificate: nil, msp_id: nil, crypto_suite: nil) click to toggle source
# 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

Public Instance Methods

as_proto() click to toggle source
# 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) click to toggle source
# File lib/fabric/entities/identity.rb, line 59
def digest(message)
  @crypto_suite.digest message
end
generate_csr(attrs = []) click to toggle source
# File lib/fabric/entities/identity.rb, line 51
def generate_csr(attrs = [])
  @crypto_suite.generate_csr private_key, attrs
end
new_gateway(client) click to toggle source

Creates a new gateway passing in the current identity

@param [Fabric::Client] client

@return [Fabric::Gateway] gateway

# File lib/fabric/entities/identity.rb, line 83
def new_gateway(client)
  Fabric::Gateway.new(self, client)
end
shared_secret_by(public_key) click to toggle source

TODO: Do we need this?

# 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) click to toggle source
# File lib/fabric/entities/identity.rb, line 55
def sign(message)
  @crypto_suite.sign(private_key, message)
end
to_proto() click to toggle source
# 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() click to toggle source

Validates that the private_key, public_key, and certificate are valid and match

@return [boolean] true if valid, false otherwise

# 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