Sha256: 94b83450418a01354100321d3fb716042f73b05ac0632bafec765f28ab45053b

Contents?: true

Size: 925 Bytes

Versions: 15

Compression:

Stored size: 925 Bytes

Contents

module Stellar
  class TransactionEnvelope

    # 
    # Checks to ensure that every signature for the envelope is
    # a valid signature of one of the provided `key_pairs`
    # 
    # NOTE: this does not do any authorization checks, which requires access to
    # the current ledger state.
    # 
    # @param *key_pairs [Array<Stellar::KeyPair>] The key pairs to check the envelopes signatures against
    # 
    # @return [Boolean] true if all signatures are from the provided key_pairs and validly sign the tx's hash
    def signed_correctly?(*key_pairs)
      hash = tx.hash
      return false if signatures.empty?

      key_index = key_pairs.index_by(&:public_key_hint)
      
      signatures.all? do |sig| 
        key_pair = key_index[sig.hint]
        break false if key_pair.nil?

        key_pair.verify(sig.signature, hash)
      end
    end

    def hash
      Digest::SHA256.digest(to_xdr)
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
stellar-base-0.0.18 lib/stellar/transaction_envelope.rb
stellar-base-0.0.17 lib/stellar/transaction_envelope.rb
stellar-base-0.0.16 lib/stellar/transaction_envelope.rb
stellar-base-0.0.15 lib/stellar/transaction_envelope.rb
stellar-base-0.0.14 lib/stellar/transaction_envelope.rb
stellar-base-0.0.13 lib/stellar/transaction_envelope.rb
stellar-base-0.0.12 lib/stellar/transaction_envelope.rb
stellar-base-0.0.11 lib/stellar/transaction_envelope.rb
stellar-base-0.0.10 lib/stellar/transaction_envelope.rb
stellar-base-0.0.9 lib/stellar/transaction_envelope.rb
stellar-base-0.0.8 lib/stellar/transaction_envelope.rb
stellar-base-0.0.7 lib/stellar/transaction_envelope.rb
stellar-base-0.0.6 lib/stellar/transaction_envelope.rb
stellar-base-0.0.5 lib/stellar/transaction_envelope.rb
stellar-base-0.0.4 lib/stellar/transaction_envelope.rb