-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
33 changed files
with
2,634 additions
and
340 deletions.
There are no files selected for viewing
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
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
This file was deleted.
Oops, something went wrong.
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
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<title>Add Tx Multisig Sign</title> | ||
<style> | ||
#main { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
height: 120vh; | ||
font-family: sans-serif; | ||
} | ||
.decoderawtxInput { | ||
width: 99%; | ||
} | ||
.input { | ||
width: 99%; | ||
} | ||
.decodeOutput { | ||
width: 99%; | ||
} | ||
.decode-output { | ||
vertical-align: top; | ||
margin-top: 13px; | ||
} | ||
h1 { | ||
font-size: 32px; | ||
} | ||
h2 { | ||
font-size: 20px; | ||
font-weight: bold; | ||
} | ||
h3 { | ||
font-size: 16px; | ||
margin-bottom: 0px; | ||
padding-bottom: 0px; | ||
} | ||
.xpubkey-label { | ||
font-size: 12px; | ||
display: inline-block; | ||
width: 8em; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="decode"> | ||
<h3 class="decode-title">Add Tx Multisig Sign</h3> | ||
<div class="decode-input"> | ||
<div> | ||
network: <select name="network" id="network"> | ||
<option value="mainnet">mainnet</option> | ||
<option value="testnet">testnet</option> | ||
<option value="regtest">regtest</option> | ||
<option value="liquidv1">liquidv1</option> | ||
<option value="elementsregtest">elementsRegTest</option> | ||
</select><br> | ||
<div class="decodetx-label">Input tx hex:</div> | ||
<textarea rows="10" id="inputTx" class="input"></textarea><br> | ||
<!-- txid:vout --> | ||
txid: <input type="text" name="txid" id="txid" value="" class="input" /><br> | ||
vout: <input type="number" name="vout" id="vout" value="0" min="0" max="2147483647" step="1" /><br> | ||
addressType: <select name="type" id="type"> | ||
<option value="p2sh">p2sh</option> | ||
<option value="p2sh-p2wsh">p2sh-p2wsh</option> | ||
<option value="p2wsh" selected>p2wsh</option> | ||
</select><br> | ||
<!-- descriptor --> | ||
RedeemScript or OutputDescriptor:<br> | ||
<textarea rows="2" name="script" id="script" class="input"></textarea><br> | ||
<!-- signature --> | ||
<input type="button" name="addField" id="addField" value="Add input field" /> | ||
<div id="multisig"> | ||
<div> | ||
Signature1: <input type="text" name="signature" id="signature1" value="" class="input" /><br> | ||
Pubkey1(option): <input type="text" name="pubkey" id="pubkey1" value="" class="input" /><br> | ||
</div> | ||
</div> | ||
|
||
<input type="button" name="decode" id="execDecode" value="Execute" /> | ||
</div> | ||
<div class="decode-output"> | ||
<div class="decode-label">Output signed tx hex:</div> | ||
<textarea rows="10" id="decoded" class="decodeOutput" readonly></textarea> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<script src="/cfd-js-wasm/dist/cfdjs_wasm.js"></script> | ||
<script src="/cfd-js-wasm/cfdjs_wasm_jsonapi.js"></script> | ||
<script src="add_tx_multisig_sign.js"></script> | ||
<p><a href="index.html">back</a></p> | ||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
const updateField = async function(event) { | ||
const decoded = document.getElementById("decoded"); | ||
const inputTx = document.getElementById("inputTx").value; | ||
const txid = document.getElementById("txid").value; | ||
const vout = document.getElementById("vout").value; | ||
const networkObj = document.getElementById("network"); | ||
const selectedNetworkIdx = networkObj.selectedIndex; | ||
let network = networkObj.options[selectedNetworkIdx].value; | ||
const hashtypeObj = document.getElementById("type"); | ||
const selectedHashtypeIdx = hashtypeObj.selectedIndex; | ||
let hashType = hashtypeObj.options[selectedHashtypeIdx].value; | ||
const signParams = []; | ||
const keyData = document.getElementById('script').value; | ||
let keyHex = keyData; | ||
let descriptor = ''; | ||
|
||
let isElements = true; | ||
if ((network === 'mainnet') || (network === 'testnet') || (network === 'regtest')) { | ||
isElements = false; | ||
} else if (network === 'elementsregtest') { | ||
network = 'regtest'; | ||
} | ||
|
||
try { | ||
const req = { | ||
descriptor: keyData, | ||
isElements, | ||
network, | ||
}; | ||
const descData = await callJsonApi(Module, 'ParseDescriptor', req); | ||
if (descData.includeMultisig == true && | ||
(descData.hashType == 'p2sh' || descData.hashType == 'p2sh-p2wsh' | ||
|| descData.hashType == 'p2wsh')) { | ||
keyHex = descData.redeemScript; | ||
descriptor = keyData; | ||
hashType = descData.hashType; | ||
} else { | ||
decoded.value = 'This descriptor type cannot use.'; | ||
return; | ||
} | ||
} catch (e) { | ||
// do nothing | ||
} | ||
const isWitness = !(hashType == 'p2sh'); | ||
if (!descriptor) { | ||
const req = { | ||
isElements, | ||
redeemScript: keyHex, | ||
network, | ||
hashType: 'p2pkh', | ||
}; | ||
await callJsonApi(Module, 'GetAddressesFromMultisig', req); | ||
} | ||
|
||
const pubkeys = document.getElementsByName('pubkey'); | ||
for (let i = 1; i <= pubkeys.length; i++) { | ||
const pubkeyId = `pubkey${i}`; | ||
const sigId = `signature${i}`; | ||
const hex = document.getElementById(sigId).value; | ||
const relatedPubkey = document.getElementById(pubkeyId).value; | ||
signParams.push({hex, relatedPubkey, derEncode: false}); | ||
} | ||
|
||
try { | ||
const req = { | ||
tx: inputTx, | ||
isElements, | ||
txin: { | ||
txid, | ||
vout: parseInt(vout), | ||
signParams, | ||
redeemScript: (isWitness) ? '' : keyHex, | ||
witnessScript: (isWitness) ? keyHex : '', | ||
hashType, | ||
}, | ||
}; | ||
const resp = await callJsonApi(Module, 'AddMultisigSign', req); | ||
decoded.value = JSON.stringify(resp, (_key, value) => | ||
typeof value === 'bigint' ? value.toString() : value, ' '); | ||
} catch (e) { | ||
decoded.value = 'Invalid transaction format'; | ||
} | ||
} | ||
|
||
const decodeBtnField = document.getElementById("execDecode"); | ||
decodeBtnField.addEventListener('click', updateField); | ||
|
||
const addField = async function(event) { | ||
const pubkeys = document.getElementsByName('pubkey'); | ||
if (pubkeys.length >= 20) return; | ||
const idCount = pubkeys.length + 1; | ||
|
||
const newItem = document.createElement("div"); | ||
newItem.innerHTML = `Signature${idCount}: <input type="text" name="signature" id="signature${idCount}" value="" class="input" /><br>Pubkey${idCount}(option): <input type="text" name="pubkey" id="pubkey${idCount}" value="" class="input" /><br>`; | ||
|
||
const multisigField = document.getElementById('multisig'); | ||
multisigField.appendChild(newItem); | ||
} | ||
|
||
const addFieldBtnField = document.getElementById("addField"); | ||
addFieldBtnField.addEventListener('click', addField); | ||
|
||
Module['onRuntimeInitialized'] = async function(){ | ||
const decoded = document.getElementById("decoded"); | ||
if (Module['_cfdjsJsonApi']) { | ||
console.log("exist cfdjsJsonApi."); | ||
decoded.value = ""; | ||
} else { | ||
console.log("cfdjsJsonApi not found!"); | ||
decoded.value = "WebAssembly load fail."; | ||
} | ||
} | ||
|
||
window.onload = function() { | ||
const decoded = document.getElementById("decoded"); | ||
if (Module['_cfdjsJsonApi']) { | ||
decoded.value = ""; | ||
} else { | ||
decoded.value = "WebAssembly loading..."; | ||
} | ||
} |
Oops, something went wrong.