Class: JSON::LD::SIGNATURE::Ed25519Verifier

Inherits:
Object
  • Object
show all
Defined in:
lib/json/ld/signature/ed25519Verifier.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#privObject



14
15
16
# File 'lib/json/ld/signature/ed25519Verifier.rb', line 14

def priv
  @priv
end

#pubObject



10
11
12
# File 'lib/json/ld/signature/ed25519Verifier.rb', line 10

def pub
  @pub
end

Instance Method Details

#verify(input, options = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/json/ld/signature/ed25519Verifier.rb', line 18

def verify(input, options = {})
  
  # We require a publicKeyPem in the options hash
#      if options['publicKey'].nil?
#        raise JsonLdSignatureError::MissingKey, "options parameter must include publicKey"
#      end

  # The publicKeyPem can be either a String or a parsed RSA key
#      publicKey = options['publicKey']
  publicKey = pub
  
  # Check the input, it should either be a String or a parsed JSON object

  jsonld = case input
  when String then 
  begin
      JSON.parse(input)        
    rescue JSON::ParserError => e
        raise JsonLdSignatureError::InvalidJsonLdDocument, e.message
  end 
  when Hash then input
  else
    raise JsonLdSignatureError::InvalidJsonLdDocument
  end
  
  signature = jsonld['signature']
  
  created = signature['created']
  creator = signature['creator']
  signatureValue = signature['signatureValue']
  domain = signature['domain']
  nonce = signature['nonce']
  
  uri = URI(creator)
  
  normOpts = {
    'nonce' => nonce,
    'domain' => domain,
    'created' => created,
    'creator' => creator
  }
  
  normalizedGraph = JSON::LD::SIGNATURE::generateNormalizedGraph jsonld, normOpts

  publicKey.verify Base64.decode64(signatureValue), normalizedGraph
end