Skip to content

Commit

Permalink
update to v0.3.1 (#19)
Browse files Browse the repository at this point in the history
* update from cryptogarageinc v0.3.5
  • Loading branch information
k-matsuzawa authored May 27, 2021
1 parent f644942 commit a970bfc
Show file tree
Hide file tree
Showing 33 changed files with 2,634 additions and 340 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/check_pre-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ on:
- master
- develop
- features/sprint*
- stable_v*
pull_request:
branches:
- master
- develop
- features/sprint*
- stable_v*

jobs:
wasm-test:
Expand All @@ -19,7 +21,7 @@ jobs:
runs-on: ubuntu-18.04
strategy:
matrix:
node: [12, 14, 15]
node: [12, 14, 16]

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -64,17 +66,14 @@ jobs:
npm set progress=false
npm ci
- name: test
if: matrix.node != 8
run: npm run test
- name: example
run: |
npm run example
npm run elements_example
- name: ts example
if: matrix.node != 8
run: npm run ts_example
- name: lint_check
if: matrix.node != 8
run: npm run lint_all

doxygen-ubuntu:
Expand Down
8 changes: 2 additions & 6 deletions .github/workflows/code_scanner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ jobs:
# We must fetch at least the immediate parents so that if this is a pull request then we can checkout the head.
fetch-depth: 2

# If this run was triggered by a pull request event, then checkout the head of the pull request instead of the merge commit.
- run: git checkout HEAD^2
if: ${{ github.event_name == 'pull_request' }}

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
Expand All @@ -60,10 +56,10 @@ jobs:
- name: Autobuild
uses: github/codeql-action/autobuild@v1

# ℹ️ Command-line programs to run using the OS shell.
# ?? Command-line programs to run using the OS shell.
# https://git.io/JvXDl

# If the Autobuild fails above, remove it and uncomment the following three lines and modify them (or add more) to build your code if your project uses a compiled language
# ? If the Autobuild fails above, remove it and uncomment the following three lines and modify them (or add more) to build your code if your project uses a compiled language

#- run: |
# make bootstrap
Expand Down
72 changes: 0 additions & 72 deletions .github/workflows/workflow_modify_checker.yml

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ WebAssembly of cfd libraries (by JSON format API)

## WebAssembly Example

- [example](https://cryptogarageinc.github.io/cfd-js-wasm/example/index.html)
- [example](https://p2pderivatives.github.io/cfd-js-wasm/example/index.html)

---

Expand Down Expand Up @@ -86,7 +86,7 @@ If you use old npm or yarn, describe as follows:

- Clang (10.0.0 or higher)
- C/C++ Compiler
  - can compile c++11
- can compile c++11
- CMake (3.14.3 or higher)
- Python (3.8 or higher)
- node.js (12.8 or higher)
Expand Down
2 changes: 1 addition & 1 deletion dist/cfdjs_wasm.js

Large diffs are not rendered by default.

Binary file modified dist/cfdjs_wasm.wasm
Binary file not shown.
95 changes: 95 additions & 0 deletions example/add_tx_multisig_sign.html
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>
121 changes: 121 additions & 0 deletions example/add_tx_multisig_sign.js
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...";
}
}
Loading

0 comments on commit a970bfc

Please sign in to comment.