Class: Secp256k1::PrivateKey

Inherits:
Object
  • Object
show all
Defined in:
ext/rbsecp256k1/rbsecp256k1.c

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_data(in_private_key_data) ⇒ Secp256k1::PrivateKey

Load a private key from binary data.

Parameters:

  • in_private_key_data (String)

    32 byte binary string of private key data.

Returns:

Raises:



765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
# File 'ext/rbsecp256k1/rbsecp256k1.c', line 765

static VALUE
PrivateKey_from_data(VALUE klass, VALUE in_private_key_data)
{
  unsigned char *private_key_data;

  Check_Type(in_private_key_data, T_STRING);
  if (RSTRING_LEN(in_private_key_data) != 32)
  {
    rb_raise(
      Secp256k1_Error_class,
      "private key data must be 32 bytes in length"
    );
    return Qnil;
  }

  private_key_data = (unsigned char*)StringValuePtr(in_private_key_data);
  return PrivateKey_create(private_key_data);
}

Instance Method Details

#==(other) ⇒ Boolean

Compare two private keys.

Private keys are considered equal if their data fields are identical.

Parameters:

Returns:

  • (Boolean)

    true if they are equal, false otherwise.



792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
# File 'ext/rbsecp256k1/rbsecp256k1.c', line 792

static VALUE
PrivateKey_equals(VALUE self, VALUE other)
{
  PrivateKey *lhs;
  PrivateKey *rhs;

  TypedData_Get_Struct(self, PrivateKey, &PrivateKey_DataType, lhs);
  TypedData_Get_Struct(other, PrivateKey, &PrivateKey_DataType, rhs);

  if (memcmp(lhs->data, rhs->data, 32) == 0)
  {
    return Qtrue;
  }

  return Qfalse;
}

#dataString

Returns binary string of private key data.

Returns:

  • (String)

    32 byte binary string of private key data.



747
748
749
750
751
752
753
754
755
# File 'ext/rbsecp256k1/rbsecp256k1.c', line 747

static VALUE
PrivateKey_data(VALUE self)
{
  PrivateKey *private_key;

  TypedData_Get_Struct(self, PrivateKey, &PrivateKey_DataType, private_key);

  return(rb_str_new((char*)private_key->data, 32));
}