Understand the Ethereum ECDSA signature format
When there is a specific format that needs to be followed on the Ethereum network, especially the fiction function (RFC6979), when signing the traances. In this article, we deal with the signature of Ethereum in Dedeils v
,r
and «Svalues.
Overview of ECDSA signature format
Before immersing into the characteristics of the value of "V", it must be understood that ECDSA is the context of Etherum. ECDSA is a diigital signature scheme that can control the credibility and integrity of the jerseys with the eliptic curve cryptography. In Ethereum, ECDSA is used together by the restore control function (RFC6979) to sign transactions.
Definition ofv
When you determine the value of "V", you need to understand what value. According to the code detail,V = 27 + (y % 2)» calculates «V». In each theher this formula adds two important elements:
- The consequence of «y % 2
: This party determines whether a" signed "or non -written transaction is authentic.
- A "V" Walue: This final calculation gives the full value of the Walue used for the WTH RFC6979.
Interpretation of Patrity in ECDSA signatures
*
The ECDSA is two Walues, "" "and" S ", on a private key provided by consumers. The "parity" of Thees Walues is a household house associated with overwriting. According to Ethereum documentation:
- Ify % 2 == 0
, the result of the" V "calculation increases by one.
- That if you are a usual ECDSA implementation, then as Pycryptodome and yougener
and" s
sWeaur (which "E" is the pkcs#1 v1 .5., Theen to determine the "V" The parity of values, you will add 2.
Example
For bad control of this, take an example of generating a new transaction using Pycryptodome and RFC6979. For you, we will reach a private T 27 with a public exponent of 27 (the Cryptographic General Selects).
Python
Pyecdse
Def generate_keypair ():
Generate a new RSA pair
Key = Pyecdse.rspivatey.Generate (2048)
Find out private and public exponents
E, D = Pyecdse.rsspublickey.get_exponent (key)
Return (key, pyecdse.ecdsiplickey (E = E))
`
Suppose you have a public key to which 27: e
:
`Python
Def Generate_public_key (Key):
Find out private and public exponents
D = Pyecdse.rsApivatey.Generate (2048)
Return (key, pyecdse.ecdsiplickey (d = d))
Generate a new key generated by this value
(Key, ECS) = Generate_keypair ()
Print («E :, ECPS.E)
Print («D :, ECPS.D)
`
With the values of «Eand" D "you can use Pycryptodome to belong to the general Utlic exponent:
Python
Derives the public exponence
public_exponent = pyecdse.ecdsiplickey (E = 27, d = d) .get_public_exponent ()
Print («Public Exponent:», Public_Exponent)
`
Now we can calculate «V» based on the parallels of tenders.
Calculation of V
`Python
Calculate v = 27 + (y % 2) for all transactions.
For TX in transactions:
Signature = Pyecdse.ecdasignature.generate (ECPS, TX)
To withdraw public and individuals from signature
Signature_Public_Exponent = Signature.get_public_Exponent ()
Signature_Private_Exponent = Signature.get_Private_Exponent ()
Check that the transaction is a message message -e
If Signature_Public_Exponent <0:
Print («The transaction is signed.
Deja una respuesta