From 7a60e3056acb199718df18031f1f6fed9eec3dd1 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Tue, 10 May 2022 15:10:30 +0300 Subject: [PATCH 1/2] create npm package for threshold encryption on publish --- .github/workflows/publish.yml | 50 +++++++++++++++++++++++++++++-- .github/workflows/test.yml | 1 - node/encryptTransaction.html | 44 ---------------------------- node/encryptTransaction.js | 55 ----------------------------------- node/package.json | 32 ++++++++++++-------- node/webpack.config.js | 25 ---------------- 6 files changed, 68 insertions(+), 139 deletions(-) delete mode 100644 node/encryptTransaction.html delete mode 100644 node/encryptTransaction.js delete mode 100644 node/webpack.config.js diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index fb175824..d1bcb6e0 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -21,6 +21,12 @@ jobs: ACTIONS_ALLOW_UNSECURE_COMMANDS: true - name: Checkout uses: actions/checkout@v2 + + - uses: actions/setup-node@v1 + with: + node-version: '14.x' + registry-url: 'https://registry.npmjs.org' + - name: Update apt run: sudo add-apt-repository ppa:ubuntu-toolchain-r/test; sudo apt-get update - name: Install packages @@ -45,7 +51,7 @@ jobs: cd deps ./build.sh - - name: Configure all + - name: Configure run: | export CC=gcc-9 export CXX=g++-9 @@ -53,18 +59,42 @@ jobs: mkdir -p build && cd build cmake .. - - name: Build all + - name: Build run: | export CC=gcc-9 export CXX=g++-9 export TARGET=all cd build make -j$(nproc) + + - name: Build dependencies wasm + run: | + export CC=gcc-9 + export CXX=g++-9 + export TARGET=all + cd deps + ./clean.sh + ./build.sh WITH_EMSCRIPTEN=1 + cd .. + + - name: Build wasm + run: | + cd deps/emsdk + ./emsdk install latest + ./emsdk activate latest + source ./emsdk_env.sh + cd ../.. + mkdir -p build_em && cd build_em + export LIBRARIES_ROOT=../deps/deps_inst/x86_or_x64/lib + emcmake cmake -DEMSCRIPTEN=ON .. -DGMP_LIBRARY="$LIBRARIES_ROOT"/libgmp.a -DCRYPTOPP_LIBRARY="$LIBRARIES_ROOT"/libcrypto.a -DGMPXX_LIBRARY="$LIBRARIES_ROOT"/libgmpxx.a + emmake make -j$(nproc) + cd .. - name: Calculate version run: | export BRANCH=${GITHUB_REF##*/} echo "Branch $BRANCH" + echo "::set-env name=BRANCH::$BRANCH" export VERSION=$(cat VERSION.txt) export VERSION=$(bash ./scripts/calculate_version.sh $BRANCH $VERSION) echo "::set-env name=VERSION::$VERSION" @@ -74,6 +104,22 @@ jobs: env: ACTIONS_ALLOW_UNSECURE_COMMANDS: true + - name: Publish on npm + if: github.ref != 'refs/heads/stable' + run: | + cd node + npm version --no-git-tag-version ${{ env.VERSION }} + npm publish --access public --tag ${{ env.BRANCH }} + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + - name: Publish on npm (stable) + if: github.ref == 'refs/heads/stable' + run: | + cd node + npm publish --access public + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + - name: Create Release id: create_release uses: actions/create-release@latest diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6f3839e3..d514bfd5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -219,7 +219,6 @@ jobs: export CC=gcc-9 export CXX=g++-9 export TARGET=all - export CMAKE_BUILD_FLAGS="-DCOVERAGE=ON" cd deps ./build.sh WITH_EMSCRIPTEN=1 cd .. diff --git a/node/encryptTransaction.html b/node/encryptTransaction.html deleted file mode 100644 index 3fd20297..00000000 --- a/node/encryptTransaction.html +++ /dev/null @@ -1,44 +0,0 @@ - - - - - Demo - - - - - - - - -
-

Tx data

-

- - -

-

- - -

-
-
-

-
- - \ No newline at end of file diff --git a/node/encryptTransaction.js b/node/encryptTransaction.js deleted file mode 100644 index fa5ec184..00000000 --- a/node/encryptTransaction.js +++ /dev/null @@ -1,55 +0,0 @@ -const Web3 = require("web3"); - -async function get_common_bls_public_key( eth ) { - // hardcoded address and function signature - let web3 = new Web3( eth.currentProvider ); - // TODO: check if it works ok with zeros in coordinates - return await web3.eth.call({"to": "0xd2aaa00200000000000000000000000000000000", "data": "0x554ef7a6"}); -} - -async function encrypt_data( data, common_bls_public_key ) { - var factory = require("./encrypt.js"); - - var encryptedMesage = ""; - var instance = await factory(); - var ptrData = instance.allocate(instance.intArrayFromString(data), instance.ALLOC_NORMAL); - var ptrKey = instance.allocate(instance.intArrayFromString(common_bls_public_key), instance.ALLOC_NORMAL); - var result = instance.ccall("encryptMessage", "number", ["number", "number"], [ptrData, ptrKey]); - var resValue = instance.UTF8ToString(result); - instance._free(ptrKey); - instance._free(ptrData); - encryptedMesage = resValue; - return encryptedMesage; -} - -async function sendData( eth, to, data ) { - let web3 = new Web3( eth.currentProvider ); - - let accs = await web3.eth.getAccounts(); - let address = accs[0]; - let nonce = await web3.eth.getTransactionCount( address ); - let chainId = await web3.eth.getChainId(); - - let tx = { - from: address, - data: data, - gas: 1000000, - to: to, - nonce: nonce, - chainId: chainId - }; - - return await web3.eth.sendTransaction(tx); -} - -async function encryptAndSend(eth, to, data) { - let bls_key = await get_common_bls_public_key( eth ); - let encrypted_data = await encrypt_data( data, bls_key.substring(2) ); - let res = await sendData(eth, to, encrypted_data); - return res; -} - - -module.exports.encryptAndSend = encryptAndSend -module.exports.encrypt_data = encrypt_data -module.exports.get_common_bls_public_key = get_common_bls_public_key \ No newline at end of file diff --git a/node/package.json b/node/package.json index 66b56465..f8281b4c 100644 --- a/node/package.json +++ b/node/package.json @@ -1,14 +1,22 @@ { - "name": "encryptte-test", - "version": "1.0.0", - "dependencies": { - "@babel/core": "^7.13.8", - "babel-core": "6.26.3", - "babel-loader": "8.1.0", - "web3": "1.3.0", - "webpack": "4.43.0" - }, - "devDependencies": { - "webpack-cli": "^3.3.6" - } + "name": "@skalenetwork/t-encrypt", + "version": "0.1.0", + "keywords": [ + "SKALE", + "blockchain", + "ethereum", + "threshold", + "cryptography", + "encryption" + ], + "homepage": "https://github.com/skalenetwork/libBLS", + "license": "AGPL-3.0", + "author": "SKALE Labs and contributors", + "publishConfig": { + "access": "public" + }, + "scripts": { + "version": "node -e \"console.log(require('./package.json').version);\"" + } } + \ No newline at end of file diff --git a/node/webpack.config.js b/node/webpack.config.js deleted file mode 100644 index 53f5782e..00000000 --- a/node/webpack.config.js +++ /dev/null @@ -1,25 +0,0 @@ -module.exports = { - entry: { - "encryptTransaction": "./encryptTransaction.js" - }, - output: { - path: __dirname, - filename: "[name].min.js", - library: "encryptTransaction" - }, - module: { - rules: [ - { - exclude: /node_modules/, - use: { - loader: "babel-loader" - } - } - ] - }, - node: { - fs: "empty", - child_process: "empty" - }, - performance: { hints: false } -}; \ No newline at end of file From d48e33edcd24db9a8ae8e20eaef18fea5f1fe83a Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Wed, 11 May 2022 11:00:24 +0300 Subject: [PATCH 2/2] fix publishing --- .github/workflows/publish.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index d1bcb6e0..d0f50048 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -89,6 +89,7 @@ jobs: emcmake cmake -DEMSCRIPTEN=ON .. -DGMP_LIBRARY="$LIBRARIES_ROOT"/libgmp.a -DCRYPTOPP_LIBRARY="$LIBRARIES_ROOT"/libcrypto.a -DGMPXX_LIBRARY="$LIBRARIES_ROOT"/libgmpxx.a emmake make -j$(nproc) cd .. + cp build_em/threshold_encryption/encrypt.js node/ - name: Calculate version run: |