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_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.
-
#instance ⇒ Object
readonly
Returns the value of attribute instance.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#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:, 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:, rotation_exp: nil, namespace: nil, instance: nil, beacon_private_key: nil) ⇒ Registration
Returns a new instance of Registration.
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ephemeral_calc/registration.rb', line 15 def initialize(name:, rotation_exp: nil, namespace: nil, instance: nil, beacon_private_key: nil) @name = 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_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 |
#instance ⇒ Object (readonly)
Returns the value of attribute instance.
7 8 9 |
# File 'lib/ephemeral_calc/registration.rb', line 7 def instance @instance end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/ephemeral_calc/registration.rb', line 7 def name @name 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
28 29 30 |
# File 'lib/ephemeral_calc/registration.rb', line 28 def api_client @api_client ||= ProximityBeacon::Client.new end |
#as_yaml ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/ephemeral_calc/registration.rb', line 70 def as_yaml { identity_key: identity_key, rotation_exp: rotation_exp, initial_time: encryptor.initial_time, } end |
#eid_params ⇒ Object
32 33 34 |
# File 'lib/ephemeral_calc/registration.rb', line 32 def eid_params @eid_params ||= api_client.eidparams end |
#encryptor ⇒ Object
44 45 46 |
# File 'lib/ephemeral_calc/registration.rb', line 44 def encryptor @encryptor ||= EphemeralCalc::Encryptor.new(identity_key, rotation_exp) end |
#identity_key ⇒ Object
40 41 42 |
# File 'lib/ephemeral_calc/registration.rb', line 40 def identity_key beacon_keypair.identity_key(resolver_public_key: resolver_public_key) end |
#initial_eid ⇒ Object
48 49 50 |
# File 'lib/ephemeral_calc/registration.rb', line 48 def initial_eid [encryptor.get_identifier(0)].pack("H*") end |
#register ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/ephemeral_calc/registration.rb', line 52 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.name, ) api_client.beacons.register(beacon) end |
#resolver_public_key ⇒ Object
36 37 38 |
# File 'lib/ephemeral_calc/registration.rb', line 36 def resolver_public_key Base64.decode64(eid_params["serviceEcdhPublicKey"]) end |
#to_yaml ⇒ Object
78 79 80 |
# File 'lib/ephemeral_calc/registration.rb', line 78 def to_yaml as_yaml.to_yaml end |