Class: EphemeralCalc::Registration
- Inherits:
-
Object
- Object
- EphemeralCalc::Registration
- Defined in:
- lib/ephemeral_calc/registration.rb
Constant Summary collapse
- DEFAULT_NAMESPACE =
"e3dd811dd3bbe49e630a"
- DEFAULT_ROTATION_EXP =
2^12 = ~68 minutes
12
Instance Attribute Summary collapse
-
#beacon_keypair ⇒ Object
readonly
Returns the value of attribute beacon_keypair.
-
#beacon_name ⇒ Object
readonly
Returns the value of attribute beacon_name.
-
#beacon_private_key ⇒ Object
readonly
Returns the value of attribute beacon_private_key.
-
#beacon_time_zero ⇒ Object
readonly
Returns the value of attribute beacon_time_zero.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#instance ⇒ Object
readonly
Returns the value of attribute instance.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#rotation_exp ⇒ Object
readonly
Returns the value of attribute rotation_exp.
Instance Method Summary collapse
- #api_client ⇒ Object
- #as_yaml ⇒ Object
- #eid_params ⇒ Object
- #encryptor ⇒ Object
- #identity_key ⇒ Object
- #initial_eid ⇒ Object
-
#initialize(name: nil, rotation_exp: nil, namespace: nil, instance: nil, beacon_private_key: nil) ⇒ Registration
constructor
A new instance of Registration.
- #register ⇒ Object
- #resolver_public_key ⇒ Object
- #to_yaml ⇒ Object
Constructor Details
#initialize(name: nil, rotation_exp: nil, namespace: nil, instance: nil, beacon_private_key: nil) ⇒ Registration
Returns a new instance of Registration.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ephemeral_calc/registration.rb', line 16 def initialize(name: nil, rotation_exp: nil, namespace: nil, instance: nil, beacon_private_key: nil) @description = name @rotation_exp = (rotation_exp || DEFAULT_ROTATION_EXP).to_i @namespace = namespace || DEFAULT_NAMESPACE @instance = instance || random_instance @beacon_private_key = beacon_private_key || EphemeralCalc::KeyPair.generate_private_key @beacon_keypair = EphemeralCalc::KeyPair.new(@beacon_private_key) end |
Instance Attribute Details
#beacon_keypair ⇒ Object (readonly)
Returns the value of attribute beacon_keypair.
7 8 9 |
# File 'lib/ephemeral_calc/registration.rb', line 7 def beacon_keypair @beacon_keypair end |
#beacon_name ⇒ Object (readonly)
Returns the value of attribute beacon_name.
7 8 9 |
# File 'lib/ephemeral_calc/registration.rb', line 7 def beacon_name @beacon_name end |
#beacon_private_key ⇒ Object (readonly)
Returns the value of attribute beacon_private_key.
7 8 9 |
# File 'lib/ephemeral_calc/registration.rb', line 7 def beacon_private_key @beacon_private_key end |
#beacon_time_zero ⇒ Object (readonly)
Returns the value of attribute beacon_time_zero.
7 8 9 |
# File 'lib/ephemeral_calc/registration.rb', line 7 def beacon_time_zero @beacon_time_zero end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
7 8 9 |
# File 'lib/ephemeral_calc/registration.rb', line 7 def description @description end |
#instance ⇒ Object (readonly)
Returns the value of attribute instance.
7 8 9 |
# File 'lib/ephemeral_calc/registration.rb', line 7 def instance @instance end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
7 8 9 |
# File 'lib/ephemeral_calc/registration.rb', line 7 def namespace @namespace end |
#rotation_exp ⇒ Object (readonly)
Returns the value of attribute rotation_exp.
7 8 9 |
# File 'lib/ephemeral_calc/registration.rb', line 7 def rotation_exp @rotation_exp end |
Instance Method Details
#api_client ⇒ Object
29 30 31 |
# File 'lib/ephemeral_calc/registration.rb', line 29 def api_client @api_client ||= ProximityBeacon::Client.new end |
#as_yaml ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/ephemeral_calc/registration.rb', line 72 def as_yaml { beacon_name: beacon_name, identity_key: identity_key, rotation_exp: rotation_exp, initial_time: encryptor.initial_time, } end |
#eid_params ⇒ Object
33 34 35 |
# File 'lib/ephemeral_calc/registration.rb', line 33 def eid_params @eid_params ||= api_client.eidparams end |
#encryptor ⇒ Object
45 46 47 |
# File 'lib/ephemeral_calc/registration.rb', line 45 def encryptor @encryptor ||= EphemeralCalc::Encryptor.new(identity_key, rotation_exp) end |
#identity_key ⇒ Object
41 42 43 |
# File 'lib/ephemeral_calc/registration.rb', line 41 def identity_key beacon_keypair.identity_key(resolver_public_key: resolver_public_key) end |
#initial_eid ⇒ Object
49 50 51 |
# File 'lib/ephemeral_calc/registration.rb', line 49 def initial_eid [encryptor.get_identifier(0)].pack("H*") end |
#register ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ephemeral_calc/registration.rb', line 53 def register beacon = ProximityBeacon::Beacon.new( ephemeral_id_registration: { beaconEcdhPublicKey: Base64.strict_encode64(beacon_keypair.public_key), serviceEcdhPublicKey: eid_params["serviceEcdhPublicKey"], rotationPeriodExponent: rotation_exp, initialClockValue: encryptor.beacon_time, initialEid: Base64.strict_encode64(initial_eid) }, advertised_id: ProximityBeacon::AdvertisedId.new( eddystone_ids: [namespace, instance] ), status: "ACTIVE", description: self.description, ) registered_beacon = api_client.beacons.register(beacon) @beacon_name = registered_beacon.name end |
#resolver_public_key ⇒ Object
37 38 39 |
# File 'lib/ephemeral_calc/registration.rb', line 37 def resolver_public_key Base64.decode64(eid_params["serviceEcdhPublicKey"]) end |
#to_yaml ⇒ Object
81 82 83 |
# File 'lib/ephemeral_calc/registration.rb', line 81 def to_yaml as_yaml.to_yaml end |