Skip to content

Commit

Permalink
update to v0.2.1 (#8)
Browse files Browse the repository at this point in the history
* update from cryptogarageinc v0.2.5

Co-authored-by: k-matsuzawa <[email protected]>
  • Loading branch information
ko-matsu and k-matsuzawa authored Nov 21, 2020
1 parent 394aa6e commit c81813c
Show file tree
Hide file tree
Showing 20 changed files with 409 additions and 249 deletions.
17 changes: 7 additions & 10 deletions .github/workflows/check_pre-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,14 @@ jobs:
wasm-test:
name: wasm test
timeout-minutes: 30
runs-on: ubuntu-latest
runs-on: ubuntu-18.04
strategy:
matrix:
node: [8, 12, 14]
node: [8, 12, 14, 15]

steps:
- uses: actions/checkout@v2
- uses: actions/[email protected]
continue-on-error: true
timeout-minutes: 1
with:
node-version: ${{ matrix.node }}
- name: setup-node retry
uses: actions/[email protected]
- uses: actions/[email protected]
timeout-minutes: 1
with:
node-version: ${{ matrix.node }}
Expand Down Expand Up @@ -69,6 +63,9 @@ jobs:
run: |
npm set progress=false
npm ci
- name: test
if: matrix.node != 8
run: npm run test
- name: example
run: |
npm run example
Expand All @@ -82,7 +79,7 @@ jobs:

doxygen-ubuntu:
name: doxygen-ubuntu
runs-on: ubuntu-latest
runs-on: ubuntu-18.04

steps:
- uses: actions/checkout@v2
Expand Down
49 changes: 8 additions & 41 deletions .github/workflows/code_scanner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ on:
- develop
- features/sprint*
- feature/code_scanning
paths:
- '**.js'
- '**.ts'
- '**.cpp'
- '**.h'
- '**/code_scanner.yml'
- '**/external_project_local_setting.config'
pull_request:
branches:
- master
Expand All @@ -16,7 +23,7 @@ on:
jobs:
analyze-CodeQL:
name: CodeQL
runs-on: ubuntu-latest
runs-on: ubuntu-18.04

strategy:
fail-fast: false
Expand Down Expand Up @@ -64,43 +71,3 @@ jobs:

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1

OSSAR-Scan:
# OSSAR runs on windows-latest.
# ubuntu-latest and macos-latest support coming soon
runs-on: windows-latest

steps:
# Checkout your code repository to scan
- name: Checkout repository
uses: actions/checkout@v2
with:
# 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' }}

# Ensure a compatible version of dotnet is installed.
# The [Microsoft Security Code Analysis CLI](https://aka.ms/mscadocs) is built with dotnet v3.1.201.
# A version greater than or equal to v3.1.201 of dotnet must be installed on the agent in order to run this action.
# GitHub hosted runners already have a compatible version of dotnet installed and this step may be skipped.
# For self-hosted runners, ensure dotnet version 3.1.201 or later is installed by including this action:
# - name: Install .NET
# uses: actions/setup-dotnet@v1
# with:
# dotnet-version: '3.1.x'

# Run open source static analysis tools
- name: Run OSSAR
uses: github/ossar-action@v1
id: ossar

# Upload results to the Security tab
- name: Upload OSSAR results
uses: github/codeql-action/upload-sarif@v1
with:
sarif_file: ${{ steps.ossar.outputs.sarifFile }}
2 changes: 1 addition & 1 deletion .github/workflows/create_release-and-upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
jobs:
create-releases:
name: create-releases
runs-on: ubuntu-latest
runs-on: ubuntu-18.04

steps:
- name: checkout
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.
1 change: 1 addition & 0 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<li> for Elements
<ul>
<li><a href="get_commitment.html">get asset/amount commitment</a>
<li><a href="unblind_txout.html">Unblind TxOut</a>
</ul>
<li> Utility
<ul>
Expand Down
74 changes: 74 additions & 0 deletions example/unblind_txout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Unblind TxOut</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">Unblind TxOut</h3>
<div class="decode-input">
<div>
<div class="decodetx-label">Input tx hex:</div>
<textarea rows="10" id="inputTx" class="input"></textarea><br>
<!-- txid:vout -->
vout: <input type="number" name="vout" id="vout" value="0" min="0" max="2147483647" step="1" /><br>
<!-- address/descriptor -->
blinding key:<br>
<textarea rows="2" name="key" id="key" class="input"></textarea><br>

<input type="button" name="decode" id="execDecode" value="Verify" />
</div>
<div class="decode-output">
<div class="decode-label">Result:</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="unblind_txout.js"></script>
<p><a href="index.html">back</a></p>
</body>
</html>
44 changes: 44 additions & 0 deletions example/unblind_txout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const updateField = async function(event) {
const inputTx = document.getElementById("inputTx");
const decoded = document.getElementById("decoded");
const vout = document.getElementById("vout");
const key = document.getElementById("key");

try {
const req = {
tx: inputTx.value,
txouts: [{
index: vout.value,
blindingKey: key.value,
}],
};
const resp = await callJsonApi(Module, 'UnblindRawTransaction', req);
decoded.value = JSON.stringify(resp.outputs[0], (key, value) =>
typeof value === 'bigint' ? value.toString() : value, ' ');
} catch (e) {
decoded.value = 'Invalid transaction format';
}
}

const decodeBtnField = document.getElementById("execDecode");
decodeBtnField.addEventListener('click', updateField);

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...";
}
}
2 changes: 1 addition & 1 deletion external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ if(CFDJS_TARGET_VERSION)
set(CFDJS_TARGET_TAG ${CFDJS_TARGET_VERSION})
message(STATUS "[external project local] cfd-js target=${CFDJS_TARGET_VERSION}")
else()
set(CFDJS_TARGET_TAG v0.2.0)
set(CFDJS_TARGET_TAG v0.2.1)
endif()
if(CFDJS_TARGET_URL)
set(CFDJS_TARGET_REP ${CFDJS_TARGET_URL})
Expand Down
22 changes: 20 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ export interface BlindIssuanceRequest {
* @property {bigint | number} minimumRangeValue? - rangeproof minimum value.
* @property {number} exponent? - An exponential value that guarantees a range of rangeproof.
* @property {number} minimumBits? - minimum bits of rangeproof.
* @property {boolean} collectBlinder? - collect blinder data. (blinders and issuanceBlinders)
*/
export interface BlindRawTransactionRequest {
tx: string;
Expand All @@ -190,6 +191,19 @@ export interface BlindRawTransactionRequest {
minimumRangeValue?: bigint | number;
exponent?: number;
minimumBits?: number;
collectBlinder?: boolean;
}

/**
* The output blind transaction data.
* @property {string} hex - transaction hex.
* @property {UnblindOutput[]} blinders? - unblind txout
* @property {UnblindIssuanceOutput[]} issuanceBlinders? - unblind issuance data
*/
export interface BlindTransactionResponse {
hex: string;
blinders?: UnblindOutput[];
issuanceBlinders?: UnblindIssuanceOutput[];
}

/**
Expand Down Expand Up @@ -2283,6 +2297,8 @@ export interface UnblindIssuance {
* @property {bigint} assetamount? - asset amount
* @property {string} token? - token
* @property {bigint} tokenamount? - token amount
* @property {string} assetValueBlindFactor? - asset amount blind factor
* @property {string} tokenValueBlindFactor? - token amount blind factor
*/
export interface UnblindIssuanceOutput {
txid: string;
Expand All @@ -2291,6 +2307,8 @@ export interface UnblindIssuanceOutput {
assetamount?: bigint;
token?: string;
tokenamount?: bigint;
assetValueBlindFactor?: string;
tokenValueBlindFactor?: string;
}

/**
Expand Down Expand Up @@ -2573,9 +2591,9 @@ export class Cfdjs {
/**
* blind the transaction.
* @param {BlindRawTransactionRequest} jsonObject - request data.
* @return {Promise<RawTransactionResponse>} - response data.
* @return {Promise<BlindTransactionResponse>} - response data.
*/
BlindRawTransaction(jsonObject: BlindRawTransactionRequest): Promise<RawTransactionResponse>;
BlindRawTransaction(jsonObject: BlindRawTransactionRequest): Promise<BlindTransactionResponse>;
/**
* calculate ec signature.
* @param {CalculateEcSignatureRequest} jsonObject - request data.
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cfd-js-wasm",
"version": "0.2.0",
"version": "0.2.1",
"domain": "p2pderivatives",
"repository": {
"type": "git",
Expand Down
46 changes: 46 additions & 0 deletions wrap_js/__test__/TestDescriptor.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const TestHelper = require('./JsonTestHelper');

const createTestFunc = (helper) => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
return async (cfd, testName, req, isError) => {
let resp;
switch (testName) {
case 'Descriptor.Parse':
resp = cfd.ParseDescriptor(req);
resp = await helper.getResponse(resp);
break;
case 'Descriptor.Checksum':
resp = cfd.AppendDescriptorChecksum(req);
resp = await helper.getResponse(resp);
break;
case 'Descriptor.Create':
resp = cfd.CreateDescriptor(req);
resp = await helper.getResponse(resp);
resp = {...req, ...resp};
break;
default:
throw new Error('unknown name: ' + testName);
}
return resp;
};
};

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const createCheckFunc = (helper) => {
return (resp, exp, errorData) => {
if (errorData) {
const errMsg = TestHelper.getErrorMessage(errorData);
expect(resp).toEqual(errMsg);
return;
}
if (exp.descriptor) expect(resp.descriptor).toEqual(exp.descriptor);

if (exp.type) {
const expStr = JSON.stringify(exp, null, null);
const respStr = JSON.stringify(resp, null, null);
expect(respStr).toEqual(expStr);
}
};
};

TestHelper.doTest('Descriptor', 'descriptor_test', createTestFunc, createCheckFunc);
Loading

0 comments on commit c81813c

Please sign in to comment.