mirror of
https://github.com/sparrowwallet/drongo.git
synced 2025-11-05 11:56:38 +00:00
support uncompressed raw keys for silent payments scans
This commit is contained in:
parent
7f707017b7
commit
af879a30f1
1 changed files with 16 additions and 1 deletions
|
|
@ -153,6 +153,10 @@ public class SilentPaymentUtils {
|
|||
}
|
||||
|
||||
public static byte[] getTweak(Transaction tx, Map<HashIndex, Script> spentScriptPubKeys) {
|
||||
return getTweak(tx, spentScriptPubKeys, true);
|
||||
}
|
||||
|
||||
public static byte[] getTweak(Transaction tx, Map<HashIndex, Script> spentScriptPubKeys, boolean compressed) {
|
||||
if(tx.getOutputs().stream().noneMatch(output -> ScriptType.P2TR.isScriptType(output.getScript()))) {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -179,7 +183,7 @@ public class SilentPaymentUtils {
|
|||
byte[] smallestOutpoint = tx.getInputs().stream().map(input -> input.getOutpoint().bitcoinSerialize()).min(new Utils.LexicographicByteArrayComparator()).orElseThrow();
|
||||
|
||||
byte[] inputHash = Utils.taggedHash(BIP_0352_INPUTS_TAG, Utils.concat(smallestOutpoint, combinedPubKey));
|
||||
return NativeSecp256k1.pubKeyTweakMul(combinedPubKey, inputHash, true);
|
||||
return NativeSecp256k1.pubKeyTweakMul(combinedPubKey, inputHash, compressed);
|
||||
} catch(NativeSecp256k1Util.AssertFailException e) {
|
||||
log.error("Error computing tweak", e);
|
||||
}
|
||||
|
|
@ -278,4 +282,15 @@ public class SilentPaymentUtils {
|
|||
Utils.concat(scanPrivateKey.getPrivKeyBytes(), ByteBuffer.allocate(4).order(ByteOrder.BIG_ENDIAN).putInt(labelIndex).array())));
|
||||
return ECKey.fromPublicOnly(ECKey.publicPointFromPrivate(labelTweak).getEncoded(true));
|
||||
}
|
||||
|
||||
public static byte[] getSecp256k1PubKey(ECKey ecKey) {
|
||||
return getSecp256k1PubKey(ecKey.getPubKey(false));
|
||||
}
|
||||
|
||||
public static byte[] getSecp256k1PubKey(byte[] uncompressedKey) {
|
||||
byte[] key = new byte[64];
|
||||
System.arraycopy(uncompressedKey, 1, key, 32, 32);
|
||||
System.arraycopy(uncompressedKey, 33, key, 0, 32);
|
||||
return Utils.reverseBytes(key);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue