Author

Topic: Provide the signature hash (Read 130 times)

full member
Activity: 161
Merit: 168
January 01, 2024, 06:25:03 PM
#7
How are you doing the hashing?

are you SHA256 hashing twice?


Here's my Java code. This calculation does not work for P2SH transactions. This affects multisignature address with the 3 at the beginning.
To fix the method, I need a reference. So I need to know what's right. Hence my questions here.

Code:
public byte[] getSigHash(byte[] pkScript, byte[] valueRaw, int txIndex) throws Exception
{
if(isWitness)
{
byte[][] txPrev = getTxPrevHashNoSwap();
byte[][] prevIndex = getTxPrevIndexByte();
ByteArrayList list = new ByteArrayList(new byte[0]);
for(int i=0; i {
list.add(txPrev[i]);
list.add(prevIndex[i]);
}
byte[] nVersion = getVersion_byte();
byte[] hashPrevouts = Calc.getHashSHA256(Calc.getHashSHA256(list.getArrayAll()));
list = new ByteArrayList(new byte[0]);
for(int i=0; i byte[] hashSequence = Calc.getHashSHA256(Calc.getHashSHA256(list.getArrayAll()));
list = new ByteArrayList(new byte[0]);
list.add(txPrev[txIndex]); list.add(prevIndex[txIndex]);
byte[] outpoint = list.getArrayAll();
PkScript pk = new PkScript(pkScript);
byte[] b = {0x19,0x76,(byte)0xa9,0x14};
list = new ByteArrayList(b);
list.add(pk.getHash160());
list.add((byte) 0x88); list.add((byte) 0xac);
byte[] scriptCode = list.getArrayAll();
byte[] amount = valueRaw;
byte[] nSequence = getSequence()[txIndex];
byte[] hashOutputs = new byte[witness_pos-value_pos[0]];
System.arraycopy(data, value_pos[0], hashOutputs, 0, hashOutputs.length);
hashOutputs = Calc.getHashSHA256(Calc.getHashSHA256(hashOutputs));
byte[] nLockTime = getLockTime();
byte[] nHashType = {1,0,0,0};
list = new ByteArrayList(nVersion);
list.add(hashPrevouts);
list.add(hashSequence);
list.add(outpoint);
list.add(scriptCode);
list.add(amount);
list.add(nSequence);
list.add(hashOutputs);
list.add(nLockTime);
list.add(nHashType);
return Calc.getHashSHA256(Calc.getHashSHA256(list.getArrayAll()));
}
else
{
ByteArrayList list = new ByteArrayList(data);
for(int i=txIn_count-1; i>=0;i--)
{
int pos = sigScript_pos[i]-1;
list.remove(pos, pos + sigScript_len[i]+1);
if(i==txIndex)
{
list.insert(pkScript, pos);
list.insert((byte)pkScript.length,pos);
}
else list.insert((byte)0x00, pos);
}
byte[] b = {0x01, 0x00, 0x00, 0x00};
list.add(b);
byte[] uSigTx =  list.getArrayAll();
return  Calc.getHashSHA256(Calc.getHashSHA256(uSigTx));
}
}
full member
Activity: 161
Merit: 168
January 01, 2024, 05:08:34 PM
#6
Unfortunately, the signature -Hash is not included on this website.
Could someone please calculate me the Signature Hash for this transaction?
Code:
TxID: ac919ea7cd1564fe0826851076041d58185b2ca04f2305f22dd60b63ac476913
Addres:             2NDRD773hJ2aJNNgKNH45CYCzPWQmL6vs5a
prev PkScript: a914dd45f04f230f752dc1236e5cc830a1bcce74f9db87
Value: 77cd300000000000
Sig R: 0d8e8eaa6ecaa92eae1208b04fd6306f02bc66078fab46c9a60bfbf94a49ee18
Sig S: 770a265fe229918c0d67b0bc73dc4408248939d2b261f2b6ea4b7c9c5bcd123c
PubKey: 02b17450a1cabad6f734df66e4ea6a85882c8a14ce350733a20f83f2f10448803e
member
Activity: 113
Merit: 28
January 01, 2024, 08:48:10 PM
#5
Well I get
Code:
Msg: 02000000000101e977d313dd88253458ea455fd4a8256453acd7ad193b2c72ae376492ed338e1f01000000171600148e6e804524d16ff27b51fa0b0e65463028ffd4b8feffffff02ae8421000000000017a9146d27a4bada9013c2edf1820230f945005302e8e48740420f000000000017a914c695375cf8fc5f081c009d33943e581c9dc4e631870247304402200d8e8eaa6ecaa92eae1208b04fd6306f02bc66078fab46c9a60bfbf94a49ee180220770a265fe229918c0d67b0bc73dc4408248939d2b261f2b6ea4b7c9c5bcd123c012102b17450a1cabad6f734df66e4ea6a85882c8a14ce350733a20f83f2f10448803e0a6a1800


Public key  = b17450a1cabad6f734df66e4ea6a85882c8a14ce350733a20f83f2f10448803e 17a6393dfd1e448bc2d810100e0a4cef8966f92cd866ef7a4e759998a3bf6d2a

r           = d8e8eaa6ecaa92eae1208b04fd6306f02bc66078fab46c9a60bfbf94a49ee18
s           = 770a265fe229918c0d67b0bc73dc4408248939d2b261f2b6ea4b7c9c5bcd123c
z           = 282a1d2d78b6f0e3ca5d1b40f62f18f5c0d8e3208834603989eeef1519ebc2aa

Result r    = dff6f9f14a9ca3e8efaa7775c08426fce0671dbf885316d9a18e242db99853ea




But the 2 r's do not match so either I am doing something wrong or 'witness' is created differently to the legacy way of doing an R,S signature?
Perhaps someone else can help.

member
Activity: 113
Merit: 28
December 31, 2023, 05:32:34 PM
#3
How are you doing the hashing?

are you SHA256 hashing twice?
That might be why the value is wrong

I take it this isn't what you are looking for?

0 P2SH 2NDRD773hJ2aJNNgKNH45CYCzPWQmL6vs5a

SigScript    OP_PUSHBYTES[22] 00148e6e804524d16ff27b51fa0b0e65463028ffd4b8

Witness    304402200d8e8eaa6ecaa92eae1208b04fd6306f02bc66078fab46c9a60bfbf94a49ee180220770 a265fe229918c0d67b0bc73dc4408248939d2b261f2b6ea4b7c9c5bcd123c01 02b17450a1cabad6f734df66e4ea6a85882c8a14ce350733a20f83f2f10448803e
member
Activity: 113
Merit: 28
December 31, 2023, 01:50:22 AM
#2
This might help

https://tbtc.bitaps.com/ac919ea7cd1564fe0826851076041d58185b2ca04f2305f22dd60b63ac476913

Bottom left has display scripts or raw transaction under the value.

Also perhaps you could change the URL  of this program to point at the testnet...

https://github.com/iceland2k14/rsz
full member
Activity: 161
Merit: 168
December 30, 2023, 10:39:12 PM
#1
please delete!
Jump to: