Class: Solace::PublicKey

Inherits:
Object
  • Object
show all
Includes:
Utils::PDA
Defined in:
lib/solace/public_key.rb

Constant Summary collapse

LENGTH =

!@const LENGTH

The length of a Solana public key in bytes

Returns:

  • (Integer)

    The length of a public key

32
MAX_BUMP_SEED =

!@const MAX_BUMP_SEED

The maximum seed value for a Program Derived Address

Returns:

  • (Integer)

    The maximum seed value

255
PDA_MARKER =

!@const PDA_MARKER

The marker for a Program Derived Address

Returns:

  • (String)

    The marker for a PDA

'ProgramDerivedAddress'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::PDA

create_program_address, find_program_address, looks_like_base58_address?, seed_to_bytes

Constructor Details

#initialize(bytes) ⇒ PublicKey

Initialize with a 32-byte array or string

Parameters:

  • bytes (String, Array<Integer>)

    32-byte array or string

Raises:

  • (ArgumentError)


39
40
41
42
43
# File 'lib/solace/public_key.rb', line 39

def initialize(bytes)
  raise ArgumentError, "Public key must be #{LENGTH} bytes" unless bytes.length == LENGTH

  @bytes = bytes.freeze
end

Instance Attribute Details

#bytesObject (readonly)

!@attribute bytes

@return [Array<Integer>] The bytes of the public key


33
34
35
# File 'lib/solace/public_key.rb', line 33

def bytes
  @bytes
end

Instance Method Details

#==(other) ⇒ Boolean

Compare two public keys for equality

Parameters:

Returns:

  • (Boolean)


63
64
65
# File 'lib/solace/public_key.rb', line 63

def ==(other)
  other.is_a?(Solace::PublicKey) && other.bytes == bytes
end

#to_base58String

Return the base58 representation of the public key

Returns:

  • (String)


48
49
50
# File 'lib/solace/public_key.rb', line 48

def to_base58
  Solace::Utils::Codecs.bytes_to_base58(@bytes)
end

#to_bytesArray<Integer>

Return the public key as a byte array

Returns:

  • (Array<Integer>)


70
71
72
# File 'lib/solace/public_key.rb', line 70

def to_bytes
  @bytes.dup
end

#to_sString

String representation (base58)

Returns:

  • (String)


55
56
57
# File 'lib/solace/public_key.rb', line 55

def to_s
  to_base58
end