| 
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178 | # File 'lib/signature_graph.rb', line 125
def execute(operation)
  op = Operation.new(operation)
  raise "operation sequence is out of order" if op.sequence != @operations.length
  if op.sequence > 0
    if @signatures[op.previous] != op.sequence - 1
      raise "operation previous signature does not match"
    end
    if @operations[op.sequence - 1].timestamp >= op.timestamp
      raise "operation timestamp occurs before previous operation"
    end
    sk = @keys[op.signing_key]
    raise "operation specifies a signing key that does not exist" if sk.nil?
    if sk.revoked? && op.timestamp > sk.revoked
      raise "operation was signed by a key that was revoked at the time of signing"
    end
    if sk.type == KEY_TYPE_RECOVERY && op.revokes(op.signing_key) != true
      raise "account recovery operation does not revoke the current active recovery key"
    end
  end
  execute_actions(op)
  sk = @keys[op.signing_key]
  raise "operation specifies a signing key that does not exist" if sk.nil?
  if op.timestamp < sk.created || sk.revoked? && op.timestamp > sk.revoked
    raise "operation was signed with a key that was revoked"
  end
  sig = Base64.urlsafe_decode64(op.jws[:signature])
  sk.public_key.verify(sig, "#{op.jws[:protected]}.#{op.jws[:payload]}")
  has_valid_key = false
  @keys.each do |kid, k|
    has_valid_key = true unless k.revoked?
  end
  raise "signature graph does not contain any active or valid keys" unless has_valid_key
  raise "signature graph does not contain a valid recovery key" if @recovery_key.nil?
  raise "signature graph does not contain a valid recovery key" if @recovery_key.revoked?
  @operations.push(op)
  @signatures[op.jws[:signature]] = op.sequence
end |