|
@ -206,6 +206,20 @@ function isScriptHashOutput (script) { |
|
|
buffer[22] === OPS.OP_EQUAL |
|
|
buffer[22] === OPS.OP_EQUAL |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function isWitnessPubKeyHashOutput (script) { |
|
|
|
|
|
var buffer = compile(script) |
|
|
|
|
|
|
|
|
|
|
|
return buffer.length === 22 && |
|
|
|
|
|
buffer[0] === OPS.OP_0 |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function isWitnessScriptHashOutput (script) { |
|
|
|
|
|
var buffer = compile(script) |
|
|
|
|
|
|
|
|
|
|
|
return buffer.length === 34 && |
|
|
|
|
|
buffer[0] === OPS.OP_0 |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// allowIncomplete is to account for combining signatures
|
|
|
// allowIncomplete is to account for combining signatures
|
|
|
// See https://github.com/bitcoin/bitcoin/blob/f425050546644a36b0b8e0eb2f6934a3e0f6f80f/src/script/sign.cpp#L195-L197
|
|
|
// See https://github.com/bitcoin/bitcoin/blob/f425050546644a36b0b8e0eb2f6934a3e0f6f80f/src/script/sign.cpp#L195-L197
|
|
|
function isMultisigInput (script, allowIncomplete) { |
|
|
function isMultisigInput (script, allowIncomplete) { |
|
@ -253,7 +267,11 @@ function isNullDataOutput (script) { |
|
|
function classifyOutput (script) { |
|
|
function classifyOutput (script) { |
|
|
var chunks = decompile(script) |
|
|
var chunks = decompile(script) |
|
|
|
|
|
|
|
|
if (isPubKeyHashOutput(chunks)) { |
|
|
if (isWitnessPubKeyHashOutput(chunks)) { |
|
|
|
|
|
return 'witnesspubkeyhash' |
|
|
|
|
|
} else if (isWitnessScriptHashOutput(chunks)) { |
|
|
|
|
|
return 'witnessscripthash' |
|
|
|
|
|
} else if (isPubKeyHashOutput(chunks)) { |
|
|
return 'pubkeyhash' |
|
|
return 'pubkeyhash' |
|
|
} else if (isScriptHashOutput(chunks)) { |
|
|
} else if (isScriptHashOutput(chunks)) { |
|
|
return 'scripthash' |
|
|
return 'scripthash' |
|
@ -319,6 +337,20 @@ function multisigOutput (m, pubKeys) { |
|
|
)) |
|
|
)) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// OP_0 {pubKeyHash}
|
|
|
|
|
|
function witnessPubKeyHashOutput (pubKeyHash) { |
|
|
|
|
|
typeforce(types.Hash160bit, pubKeyHash) |
|
|
|
|
|
|
|
|
|
|
|
return compile([OPS.OP_0, pubKeyHash]) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// OP_0 {scriptHash}
|
|
|
|
|
|
function witnessScriptHashOutput (scriptHash) { |
|
|
|
|
|
typeforce(types.Hash256bit, scriptHash) |
|
|
|
|
|
|
|
|
|
|
|
return compile([OPS.OP_0, scriptHash]) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// {signature}
|
|
|
// {signature}
|
|
|
function pubKeyInput (signature) { |
|
|
function pubKeyInput (signature) { |
|
|
typeforce(types.Buffer, signature) |
|
|
typeforce(types.Buffer, signature) |
|
@ -344,6 +376,11 @@ function scriptHashInput (scriptSig, scriptPubKey) { |
|
|
)) |
|
|
)) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// <scriptSig> {serialized scriptPubKey script}
|
|
|
|
|
|
function witnessScriptHashInput (scriptSig, scriptPubKey) { |
|
|
|
|
|
return scriptHashInput(scriptSig, scriptPubKey) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// OP_0 [signatures ...]
|
|
|
// OP_0 [signatures ...]
|
|
|
function multisigInput (signatures, scriptPubKey) { |
|
|
function multisigInput (signatures, scriptPubKey) { |
|
|
if (scriptPubKey) { |
|
|
if (scriptPubKey) { |
|
@ -383,14 +420,21 @@ module.exports = { |
|
|
isPubKeyOutput: isPubKeyOutput, |
|
|
isPubKeyOutput: isPubKeyOutput, |
|
|
isScriptHashInput: isScriptHashInput, |
|
|
isScriptHashInput: isScriptHashInput, |
|
|
isScriptHashOutput: isScriptHashOutput, |
|
|
isScriptHashOutput: isScriptHashOutput, |
|
|
|
|
|
isWitnessPubKeyHashOutput: isWitnessPubKeyHashOutput, |
|
|
|
|
|
isWitnessScriptHashOutput: isWitnessScriptHashOutput, |
|
|
isMultisigInput: isMultisigInput, |
|
|
isMultisigInput: isMultisigInput, |
|
|
isMultisigOutput: isMultisigOutput, |
|
|
isMultisigOutput: isMultisigOutput, |
|
|
isNullDataOutput: isNullDataOutput, |
|
|
isNullDataOutput: isNullDataOutput, |
|
|
|
|
|
|
|
|
classifyOutput: classifyOutput, |
|
|
classifyOutput: classifyOutput, |
|
|
classifyInput: classifyInput, |
|
|
classifyInput: classifyInput, |
|
|
pubKeyOutput: pubKeyOutput, |
|
|
pubKeyOutput: pubKeyOutput, |
|
|
pubKeyHashOutput: pubKeyHashOutput, |
|
|
pubKeyHashOutput: pubKeyHashOutput, |
|
|
scriptHashOutput: scriptHashOutput, |
|
|
scriptHashOutput: scriptHashOutput, |
|
|
|
|
|
witnessPubKeyHashOutput: witnessPubKeyHashOutput, |
|
|
|
|
|
witnessScriptHashInput: witnessScriptHashInput, |
|
|
|
|
|
witnessScriptHashOutput: witnessScriptHashOutput, |
|
|
|
|
|
|
|
|
multisigOutput: multisigOutput, |
|
|
multisigOutput: multisigOutput, |
|
|
pubKeyInput: pubKeyInput, |
|
|
pubKeyInput: pubKeyInput, |
|
|
pubKeyHashInput: pubKeyHashInput, |
|
|
pubKeyHashInput: pubKeyHashInput, |
|
|