Created
April 19, 2019 13:57
-
-
Save takuto-h/84a38ef19ec8b0246f6449ed6c92c03e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bitcore from 'bitcore-lib-cash'; | |
const { | |
crypto: { BN, Signature }, | |
PublicKey, | |
Script, | |
Transaction, | |
} = bitcore; | |
function main(txHex, satoshisStr) { | |
const tx = new Transaction(txHex); | |
const scriptSig = tx.inputs[0].script; | |
const signatureChunks = scriptSig.chunks.slice(1, -1); | |
const signatures = signatureChunks.map(chunk => Signature.fromTxFormat(chunk.buf)); | |
const redeemScript = Script.fromBuffer(scriptSig.chunks.slice(-1)[0].buf); | |
const publicKeyChunks = redeemScript.chunks.slice(1, -2); | |
const publicKeys = publicKeyChunks.map(chunk => PublicKey.fromBuffer(chunk.buf)); | |
const satoshisBN = BN.fromString(satoshisStr); | |
const result = {}; | |
publicKeys.forEach((publicKey) => { | |
result[publicKey.toString()] = []; | |
signatures.forEach((signature) => { | |
if (tx.verifySignature(signature, publicKey, 0, redeemScript, satoshisBN)) { | |
result[publicKey.toString()].push(signature.toString()); | |
} | |
}); | |
}); | |
console.log(result); | |
} | |
const txHex = process.argv[2]; | |
const satoshisStr = process.argv[3]; | |
main(txHex, satoshisStr); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment