Class: Fabric::Identity

Inherits:
Object
  • Object
show all
Defined in:
lib/fabric/identity.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(crypto_suite, opts = {}) ⇒ Identity

Returns a new instance of Identity.



12
13
14
15
16
17
18
19
20
21
# File 'lib/fabric/identity.rb', line 12

def initialize(crypto_suite, opts = {})
  @crypto_suite = crypto_suite

  @private_key = opts[:private_key] || @crypto_suite.generate_private_key
  @public_key = opts[:public_key] || @crypto_suite.restore_public_key(private_key)
  @certificate = opts[:certificate]
  @mspid = opts[:mspid]

  @address = @crypto_suite.address_from_public_key public_key
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



5
6
7
# File 'lib/fabric/identity.rb', line 5

def address
  @address
end

#certificateObject

Returns the value of attribute certificate.



10
11
12
# File 'lib/fabric/identity.rb', line 10

def certificate
  @certificate
end

#crypto_suiteObject (readonly)

Returns the value of attribute crypto_suite.



5
6
7
# File 'lib/fabric/identity.rb', line 5

def crypto_suite
  @crypto_suite
end

#mspidObject

Returns the value of attribute mspid.



10
11
12
# File 'lib/fabric/identity.rb', line 10

def mspid
  @mspid
end

#private_keyObject (readonly)

Returns the value of attribute private_key.



5
6
7
# File 'lib/fabric/identity.rb', line 5

def private_key
  @private_key
end

#public_keyObject (readonly)

Returns the value of attribute public_key.



5
6
7
# File 'lib/fabric/identity.rb', line 5

def public_key
  @public_key
end

Instance Method Details

#decoded_certificateObject



35
36
37
# File 'lib/fabric/identity.rb', line 35

def decoded_certificate
  Base64.strict_decode64 certificate
end

#generate_csr(attrs = []) ⇒ Object



23
24
25
# File 'lib/fabric/identity.rb', line 23

def generate_csr(attrs = [])
  @crypto_suite.generate_csr private_key, attrs
end

#serializeObject



39
40
41
# File 'lib/fabric/identity.rb', line 39

def serialize
  Msp::SerializedIdentity.new(mspid: mspid, id_bytes: decoded_certificate).to_proto
end

#shared_secret_by(public_key) ⇒ Object



31
32
33
# File 'lib/fabric/identity.rb', line 31

def shared_secret_by(public_key)
  @crypto_suite.build_shared_key private_key, public_key
end

#sign(message) ⇒ Object



27
28
29
# File 'lib/fabric/identity.rb', line 27

def sign(message)
  @crypto_suite.sign(private_key, message)
end