Class: Secp256k1::KeyPair
- Inherits:
-
Object
- Object
- Secp256k1::KeyPair
- Defined in:
- ext/rbsecp256k1/rbsecp256k1.c
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compare two key pairs.
-
#private_key ⇒ Secp256k1::PrivateKey
Retrieve the private key for the given key pair.
-
#public_key ⇒ Secp256k1::PublicKey
Retrieve the public key for the given key pair.
-
#xonly_public_key ⇒ Secp256k1::XOnlyPublicKey
Retrieve the x-only public key for the given key pair.
Instance Method Details
#==(other) ⇒ Boolean
Compare two key pairs.
Two key pairs are equal if they have the same public and private key. The keys are compared using their own comparison operators.
907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 |
# File 'ext/rbsecp256k1/rbsecp256k1.c', line 907
static VALUE
KeyPair_equals(VALUE self, VALUE other)
{
KeyPair *lhs;
KeyPair *rhs;
TypedData_Get_Struct(self, KeyPair, &KeyPair_DataType, lhs);
TypedData_Get_Struct(other, KeyPair, &KeyPair_DataType, rhs);
if (memcmp(&lhs->keypair, &rhs->keypair, sizeof(secp256k1_keypair)) == 0)
{
return Qtrue;
}
return Qfalse;
}
|
#private_key ⇒ Secp256k1::PrivateKey
Retrieve the private key for the given key pair.
881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 |
# File 'ext/rbsecp256k1/rbsecp256k1.c', line 881
static VALUE
KeyPair_private_key(VALUE self)
{
KeyPair *key_pair;
unsigned char private_key_data[32];
TypedData_Get_Struct(self, KeyPair, &KeyPair_DataType, key_pair);
if (secp256k1_keypair_sec(secp256k1_context_static, private_key_data, &key_pair->keypair) == 0)
{
rb_raise(Secp256k1_Error_class, "failed to derive private key from keypair");
return Qnil;
}
return PrivateKey_create(private_key_data);
}
|
#public_key ⇒ Secp256k1::PublicKey
Retrieve the public key for the given key pair.
828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 |
# File 'ext/rbsecp256k1/rbsecp256k1.c', line 828
static VALUE
KeyPair_public_key(VALUE self)
{
KeyPair *key_pair;
VALUE result;
PublicKey *public_key;
TypedData_Get_Struct(self, KeyPair, &KeyPair_DataType, key_pair);
result = PublicKey_alloc(Secp256k1_PublicKey_class);
TypedData_Get_Struct(result, PublicKey, &PublicKey_DataType, public_key);
if (secp256k1_keypair_pub(secp256k1_context_static, &public_key->pubkey, &key_pair->keypair) == 0)
{
rb_raise(Secp256k1_Error_class, "failed to derive public key from keypair");
return Qnil;
}
return result;
}
|
#xonly_public_key ⇒ Secp256k1::XOnlyPublicKey
Retrieve the x-only public key for the given key pair.
private key.
855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 |
# File 'ext/rbsecp256k1/rbsecp256k1.c', line 855
static VALUE
KeyPair_xonly_public_key(VALUE self)
{
KeyPair *key_pair;
VALUE result;
XOnlyPublicKey *xonly_pubkey;
TypedData_Get_Struct(self, KeyPair, &KeyPair_DataType, key_pair);
result = XOnlyPublicKey_alloc(Secp256k1_XOnlyPublicKey_class);
TypedData_Get_Struct(result, XOnlyPublicKey, &XOnlyPublicKey_DataType, xonly_pubkey);
if (secp256k1_keypair_xonly_pub(secp256k1_context_static, &xonly_pubkey->pubkey, NULL, &key_pair->keypair) == 0)
{
rb_raise(Secp256k1_Error_class, "failed to derive x-only public key from keypair");
return Qnil;
}
return result;
}
|