Generating the receiving address from P2Wash Multi-Sig Script
==================================================================== =====================================
Although deeper in the understanding of Bitcoins and its basic protocols, it is crucial to examine the mechanisms used in portfolios to facilitate safe transactions. One of the key aspects is to generate receiving addresses needed to receive funds from other users.
In this article, we will examine how to generate influence from the Multi-Sig P2SH script in Python.
preliminary requirements
——————
P2WASH SIMPT SIMPT
————————–
The P2ASH multi -lane script is a kind of portfolio that allows safe transactions with more signing. Here is an example of how it can be implemented:
`Python
Have a hashlib
Binascia import
From Emhovnic imports Bech32
Define a constant blockchain and signature performance parameters
Blockchain_hash = "your_blockchain_hash_here"
Bermetra parameter = 3
Def derive_signature (p, r, s):
"" "Make a signature using the" "" "" "" "
Return (hexphs (P) .decode () + hashlib.sha256 (b "s" .Encode ()). Digest (). Hex ()) % 100000
Def P2WPUB_Script (P, SIG, R, S, N):
"" "Generate P2Wash Multi-Sig Script" "" "
Return Bech32.decode_P2WSH_Script (
f "1. {sig}. {r}. {s}. {n}",
[Hexlify (P) .decode (), hashlib.sha256 (b "s" .Encode ()). Digest (). hex ()]]]
)
Def main ():
Make a public key, signature and random number
P = deleve_signature ("your_public_key_here", 0x12, 0x34)
r = performance_SIGNATURE (p, 1, 2)
S = Performance_SIGNATURE (R, 3, 4)
n = derive_signature (p, 5, 6)
Generate P2Wash Multi-Sig script
Script = p2wpub_script (p, none, r, s, n)
Print the generated script
Print (script.decode ("UTF-8"))
If __Name__ == "__Main__":
main()
generating the receiving address
———————————————–
Receiving the address is a unique identifier that can be used to receive funds from other users. In the context of P2WWash, the addresses of the party are usually performed using a similar procedure.
The “P2WPUB_SCRIPTfunction generates a P2ash multi -lane script, which contains a public key, signature, random number and parameters that are not accidental (R, S, N). To generate the receipt of addresses from this script, we must perform a unique identifier that is not present in the script.
Here is an updated version of the code:
` Python
Have a hashlib
Binascia import
Define a constant blockchain and signature performance parameters
Blockchain_hash = “your_blockchain_hash_here”
Sigderavitation of theprameter = 3
Def derive_signature (p, r, s):
“” “Make a signature using the” “” “” “” “
Return (hexphs (P) .decode () + hashlib.sha256 (b “s” .Encode ()). Digest (). Hex ()) % 100000
Def P2WPUB_Script (P, SIG, R, S, N):
“” “Generate P2Wash Multi-Sig Script” “” “
Return Bech32.decode_P2WSH_Script (
f “1. {sig}. {r}. {s}. {n}”,
[Hexlify (P) .decode (), hashlib.sha256 (b “s” .Encode ()). Digest (). hex ()]]]
)
Def derive_receive_address (script, script_hash):
“” “Make the receipt address from P2Wash Multi-Sig Script” “” “
Stand out that they are not random (R, S, N) and the abbreviation parameters
R, s, n = formulation_pameters (script)
Make a unique identifier with SHA-256
ID = HASHLIB.SHA256 (R + S + N.ENCODE ()). Digest ()
Return f “2. {Id.hex ()} {blockchain_hash}”
Defin extract_pameters (script):
“” “Say parameters that are not random (r, s, n) and abbreviation from the script” “”
House the signature, random number and parameters that are not random
R, s = fragment_signature (script)
id = hashlib.sha256 (r + s.encode ()).