Class: Solana::Ruby::Kit::Signers::KeyPairSigner

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/solana/ruby/kit/signers/keypair_signer.rb

Overview

A signer backed by an Ed25519 key pair, capable of signing both transaction messages and off-chain messages.

Mirrors TypeScript’s ‘KeyPairSigner<TAddress>`, which combines MessagePartialSigner and TransactionPartialSigner with a CryptoKeyPair reference.

In Ruby we keep it simple: the signer holds an RbNaCl::SigningKey (which contains the private key seed and can derive the public key) and exposes the signer’s address.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key_pair) ⇒ KeyPairSigner

Returns a new instance of KeyPairSigner.



34
35
36
37
38
39
40
# File 'lib/solana/ruby/kit/signers/keypair_signer.rb', line 34

def initialize(key_pair)
  @key_pair = T.let(key_pair, Keys::KeyPair)
  @address  = T.let(
    Addresses::Address.new(Addresses.encode_address(key_pair.verify_key.to_bytes)),
    Addresses::Address
  )
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



28
29
30
# File 'lib/solana/ruby/kit/signers/keypair_signer.rb', line 28

def address
  @address
end

#key_pairObject (readonly)

Returns the value of attribute key_pair.



31
32
33
# File 'lib/solana/ruby/kit/signers/keypair_signer.rb', line 31

def key_pair
  @key_pair
end

Instance Method Details

#inspectObject



46
# File 'lib/solana/ruby/kit/signers/keypair_signer.rb', line 46

def inspect = "#<KeyPairSigner address=#{@address}>"

#sign(data) ⇒ Object



51
52
53
# File 'lib/solana/ruby/kit/signers/keypair_signer.rb', line 51

def sign(data)
  Keys.sign_bytes(@key_pair.signing_key, data)
end

#to_sObject



43
# File 'lib/solana/ruby/kit/signers/keypair_signer.rb', line 43

def to_s = @address.to_s

#verify(sig_bytes, data) ⇒ Object



57
58
59
# File 'lib/solana/ruby/kit/signers/keypair_signer.rb', line 57

def verify(sig_bytes, data)
  Keys.verify_signature(@key_pair.verify_key, sig_bytes, data)
end