Class: Secp256k1::RecoverableSignature
- Inherits:
-
Object
- Object
- Secp256k1::RecoverableSignature
- Defined in:
- ext/rbsecp256k1/rbsecp256k1.c
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compares two recoverable signatures.
-
#compact ⇒ Array
Returns the compact encoding of recoverable signature.
-
#recover_public_key(in_hash32) ⇒ Secp256k1::PublicKey
Attempts to recover the public key associated with this signature.
-
#to_signature ⇒ Secp256k1::Signature
Convert a recoverable signature to a non-recoverable signature.
Instance Method Details
#==(other) ⇒ Boolean
Compares two recoverable signatures.
Two recoverable signatures their secp256k1_ecdsa_recoverable_signature data is identical.
1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 |
# File 'ext/rbsecp256k1/rbsecp256k1.c', line 1054
static VALUE
RecoverableSignature_equals(VALUE self, VALUE other)
{
RecoverableSignature *lhs;
RecoverableSignature *rhs;
TypedData_Get_Struct(
self, RecoverableSignature, &RecoverableSignature_DataType, lhs
);
TypedData_Get_Struct(
other, RecoverableSignature, &RecoverableSignature_DataType, rhs
);
// NOTE: It is safe to directly compare these data structures rather than
// first serializing and then comparing.
if (memcmp(&(lhs->sig),
&(rhs->sig),
sizeof(secp256k1_ecdsa_recoverable_signature)) == 0)
{
return Qtrue;
}
return Qfalse;
}
|
#compact ⇒ Array
Returns the compact encoding of recoverable signature.
926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 |
# File 'ext/rbsecp256k1/rbsecp256k1.c', line 926
static VALUE
RecoverableSignature_compact(VALUE self)
{
RecoverableSignature *recoverable_signature;
unsigned char compact_sig[64];
int recovery_id;
VALUE result;
TypedData_Get_Struct(
self,
RecoverableSignature,
&RecoverableSignature_DataType,
recoverable_signature
);
if (secp256k1_ecdsa_recoverable_signature_serialize_compact(
secp256k1_context_no_precomp,
compact_sig,
&recovery_id,
&(recoverable_signature->sig)) != 1)
{
rb_raise(
Secp256k1_SerializationError_class,
"unable to serialize recoverable signature"
);
}
// Create a new array with room for 2 elements and push data onto it
result = rb_ary_new2(2);
rb_ary_push(result, rb_str_new((char*)compact_sig, 64));
rb_ary_push(result, rb_int_new(recovery_id));
return result;
}
|
#recover_public_key(in_hash32) ⇒ Secp256k1::PublicKey
Attempts to recover the public key associated with this signature.
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 |
# File 'ext/rbsecp256k1/rbsecp256k1.c', line 1007
static VALUE
RecoverableSignature_recover_public_key(VALUE self, VALUE in_hash32)
{
RecoverableSignature *recoverable_signature;
PublicKey *public_key;
VALUE result;
unsigned char *hash32;
Check_Type(in_hash32, T_STRING);
if (RSTRING_LEN(in_hash32) != 32)
{
rb_raise(Secp256k1_Error_class, "in_hash32 is not 32 bytes in length");
}
TypedData_Get_Struct(
self,
RecoverableSignature,
&RecoverableSignature_DataType,
recoverable_signature
);
hash32 = (unsigned char*)StringValuePtr(in_hash32);
result = PublicKey_alloc(Secp256k1_PublicKey_class);
TypedData_Get_Struct(result, PublicKey, &PublicKey_DataType, public_key);
if (secp256k1_ecdsa_recover(recoverable_signature->ctx,
&(public_key->pubkey),
&(recoverable_signature->sig),
hash32) == 1)
{
return result;
}
rb_raise(Secp256k1_DeserializationError_class, "unable to recover public key");
}
|
#to_signature ⇒ Secp256k1::Signature
Convert a recoverable signature to a non-recoverable signature.
967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 |
# File 'ext/rbsecp256k1/rbsecp256k1.c', line 967
static VALUE
RecoverableSignature_to_signature(VALUE self)
{
RecoverableSignature *recoverable_signature;
Signature *signature;
VALUE result;
TypedData_Get_Struct(
self,
RecoverableSignature,
&RecoverableSignature_DataType,
recoverable_signature
);
result = Signature_alloc(Secp256k1_Signature_class);
TypedData_Get_Struct(
result,
Signature,
&Signature_DataType,
signature
);
// NOTE: This method cannot fail
secp256k1_ecdsa_recoverable_signature_convert(
secp256k1_context_no_precomp,
&(signature->sig),
&(recoverable_signature->sig));
return result;
}
|