zf

zenflows testing
git clone https://s.sonu.ch/~srfsh/zf.git
Log | Files | Refs | Submodules | README | LICENSE

commit d5d0a86909fa138e6e3fc66cfa3627b5c8b65e20
parent f3353a092fd2ff4a437b7059aa326c181c4eb232
Author: srfsh <dev@srf.sh>
Date:   Fri, 22 Jul 2022 11:38:34 +0300

zencode: rm -rf

Diffstat:
Dzencode/Dockerfile | 39---------------------------------------
Dzencode/README.md | 11-----------
Dzencode/src/byte_equal.zen | 5-----
Dzencode/src/create_otp.zen | 4----
Dzencode/src/keygen.zen | 28----------------------------
Dzencode/src/sign_graphql.zen | 11-----------
Dzencode/src/verify_graphql.data | 5-----
Dzencode/src/verify_graphql.zen | 25-------------------------
Dzencode/test/api.sh | 20--------------------
Dzencode/test/scripts.sh | 143-------------------------------------------------------------------------------
10 files changed, 0 insertions(+), 291 deletions(-)

diff --git a/zencode/Dockerfile b/zencode/Dockerfile @@ -1,39 +0,0 @@ -# Zenflows is designed to implement the Valueflows vocabulary, -# written and maintained by srfsh <info@dyne.org>. -# Copyright (C) 2021-2022 Dyne.org foundation <foundation@dyne.org>. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <https://www.gnu.org/licenses/>. - -ARG NODE_VERSION=16 -# Importing node12 docker image -FROM node:$NODE_VERSION-alpine - -WORKDIR /app - -# Add dependencies -RUN apk add git python3 make g++ - -# Installing restroom -RUN yarn create restroom -a . - -# Configure restroom -ENV HTTP_PORT=3000 -ENV HTTPS_PORT=3301 -ENV OPENAPI=true -ENV FILES_DIR=./contracts -ENV CHAIN_EXT=chain -ENV YML_EXT=yml - -# yarn install and run -CMD yarn start diff --git a/zencode/README.md b/zencode/README.md @@ -1,11 +0,0 @@ -# Zencode scripts used in Zenflows - -Zencode is executed by the [Zenroom](http://zenroom.org) VM running inside a crypto-provider micro-service locally reachable by Zenflows. - -The language documentation is found on [dev.zenroom.org](https://dev.zenroom.org). - -The `src` directory contains scripts called by the running Zenflows instance. - -The `test` directory contains unit tests (single scripts tested in local) and integration tests (shell scripts that call zenflows staging instances to test its api). - - diff --git a/zencode/src/byte_equal.zen b/zencode/src/byte_equal.zen @@ -1,5 +0,0 @@ -Given I have a 'base64' named 'left' -and I have a 'base64' named 'right' -When I verify 'left' is equal to 'right' -Then print the string '1' -# else, zenroom exits non-zero diff --git a/zencode/src/create_otp.zen b/zencode/src/create_otp.zen @@ -1,3 +0,0 @@ -Given nothing -When I create the random object of '32' bytes -then print the 'random object' as 'base58' -\ No newline at end of file diff --git a/zencode/src/keygen.zen b/zencode/src/keygen.zen @@ -1,28 +0,0 @@ -Scenario ecdh : 'keygen' -Scenario ethereum: 'keygen' -Scenario schnorr: 'keygen' -Scenario reflow: 'keygen' -Scenario eddsa: 'keygen' - -Given nothing -When I create the ecdh key -When I create the reflow key -When I create the schnorr key -When I create the ethereum key -When I create the eddsa key - -When I create the 'base64 dictionary' named 'pubkeys' -When I create the ecdh public key -and I move 'ecdh public key' in 'pubkeys' -When I create the reflow public key -and I move 'reflow public key' in 'pubkeys' -When I create the schnorr public key -and I move 'schnorr public key' in 'pubkeys' -When I create the eddsa public key -and I move 'eddsa public key' in 'pubkeys' - -When I create the ethereum address -and schema -Then print the 'keyring' -and print the 'pubkeys' -and print the 'ethereum address' diff --git a/zencode/src/sign_graphql.zen b/zencode/src/sign_graphql.zen @@ -1,11 +0,0 @@ -# The input expected is a graph query encoded as base64 -# and signed using ecdh - -Scenario eddsa: sign a graph query - -Given I have a 'base64' named 'graphql' -and I have a 'keyring' - -When I create the eddsa signature of 'graphql' -Then print 'eddsa signature' -and print 'graphql' diff --git a/zencode/src/verify_graphql.data b/zencode/src/verify_graphql.data @@ -1,5 +0,0 @@ -{ - "eddsa_public_key": "C2z3kTw5QYEyULbDzFvq4RhWXNJBcLXpikYMf388xfXN", - "eddsa_signature": "3zmw9U5vCn85CxePAnEHQhUKZGDhr7h7fh4GMVXXvHVkWvH91Er5kzfCjXkeWMAgzwoqeezqCUm8r3M6bBauNwMy", - "graphql": "0tssyQTrRsIBnrsX62sN7gGmBIdFpKArCVOStqcoQ2bstYvS7tvBU258ChufGghJqEzaCPCzls_gFqDdyThNpg" -} diff --git a/zencode/src/verify_graphql.zen b/zencode/src/verify_graphql.zen @@ -1,25 +0,0 @@ -Scenario eddsa: verify the signature of a graph query - -Given I have a 'base64' named 'graphql' -Given I have a 'base58' named 'eddsa signature' -Given I have a 'base64' named 'eddsa public key' - -# check that the graph query is reentrant -# When I create the count of char '{' found in 'graphql' -# and I rename 'count' to 'open' -# and I create the count of char '}' found in 'graphql' -# and I remove 'count' -# and I remove 'open' -# When I create the count of char '(' found in 'graphql' -# and I rename 'count' to 'open' -# and I create the count of char ')' found in 'graphql' -# and I remove 'count' -# and I remove 'open' -# When I create the count of char '[' found in 'graphql' -# and I rename 'count' to 'open' -# and I create the count of char ']' found in 'graphql' -# and I verify 'count' is equal to 'open' - -When I verify the 'graphql' has a eddsa signature in 'eddsa signature' by 'eddsa public key' - -Then print the string '1' diff --git a/zencode/test/api.sh b/zencode/test/api.sh @@ -1,20 +0,0 @@ -#!/bin/bash -# -# simple shell script to test the api - -conf="rngseed=hex:00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" - -# eddsa public key will always be: Lotmt4Of+Ca93Jxfvqz4I+gXCJkAVA0tcaFczuyxZNs= -zenroom -c $conf -z ../../zencode/keygen.zen | tee keyring.json | jq . - -query='hello world! this should be a $mutation' - -cat <<EOF > query.json -{"graphql": "$(echo $query | base64)"} -EOF -zenroom -c $conf -z ../../zencode/sign_graphql.zen -a query.json -k keyring.json | tee signed_query.json | jq . - -echo "Body: $query" -echo "Header: `awk -F'"' '/eddsa_signature/ {print $4}' signed_query.json`" - -# TODO: continue diff --git a/zencode/test/scripts.sh b/zencode/test/scripts.sh @@ -1,143 +0,0 @@ -#!/usr/bin/env bash - -conf="debug=1,rngseed=hex:00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" - -which zenroom > /dev/null -if [ $? != 0 ]; then - echo "Error: zenroom interpreter not found in PATH" - exit 1 -fi -if ! ls ../src/*.zen >/dev/null 2>&1 ; then - echo "Error: there is no zencode scripts in PWD to run" - exit 1 -fi - -results=`mktemp` -echo > $results -echo "Zenflows tests of zencode scripts" >> $results -date >> $results -echo >> $results - -function testzen() { - script="../src/${1}.zen" - expect="$2" - input="$3" - keys="$4" - tmpin=`mktemp` - tmpkey=`mktemp` - if [ -r "${input}" ]; then cp ${input} ${tmpin}; else echo "$input" > $tmpin; fi - if [ -r "${keys}" ]; then cp ${keys} ${tmpkey}; else echo "$keys" > $tmpkey; fi - - if [ "$keys" != "" ]; then - result=`cat $script | zenroom -z -c $conf -a $tmpin -k $tmpkey` - rm -f $tmpin $tmpkey - elif [ "$input" != "" ]; then - result=`cat $script | zenroom -z -c $conf -a $tmpin` - rm -f $tmpin - else - result=`cat $script | zenroom -z -c $conf` - fi - res=$? - if [ $res != 0 ]; then - echo "[!] Parse error in $script" >> $results - else - if [ "$result" != "$expect" ]; then - echo "[!] Error in $script" >> $results - echo "$result" - else - echo " . Success: $script" >> $results - echo $result - fi - fi -} - -keyring='{"ethereum_address":"05a94ba6d94f9056e79351a8fd1dc186b737993f","keyring":{"ecdh":"B4rYTWx6UMbc2YPWRNpl4w2M6gY9jqSa637n8Kr2pPc=","eddsa":"6kqZKA5WJ6aiVh4DThcY821RVhBV8r39TyHx24zX2JKx","ethereum":"d6fe79ff70b4a8663d1ecf495a983ba6effd0392c636923dff08a0482f5e5d5f","reflow":"abYTJShT0ZBKU+ZwJlEIPNinT6TFU+unaKMEZ+u3kbs=","schnorr":"DR92VSF2l3Az1K1+LyWO13Jk1eBPmuhhPT2NbpxGgsk="},"pubkeys":{"ecdh_public_key":"BHdrWMNBRclVO1I1/iEaYjfEi5C0eEvG2GZgsCNq87qy8feZ74JEvnKK9FC07ThhJ8s4ON2ZQcLJ+8HpWMfKPww=","eddsa_public_key":"NjrWkWySCow9osq/gBqfw8yyqVAa04n+MBqHfVOCtj0=","reflow_public_key":"FwWLOfRBAoZKfykEvq26iNn2D64gvwgCfinWWZnG4HotCuomB6EB9qJ0sinpV5LNB6GdkrKU3wvYMUU+fBMX8mtR77E3x/ljbqpwwpcmjB9YtONG1peywJvRhXqhIBJSALFTXAB2Y1XtM63Uw5/CBex8zH3wXyYU6sv/ctKi5bUZ2Zzqua9Q8LMqtgLsrrB9GDKbmPT1einkXVMLX0kuJV/AOTnA57q91HKXMCvlvlKs/sr5mJ70FchdEZl0UHIV","schnorr_public_key":"EZH/DtDoGvjabyqiHwROQpt5suHlD3JiMZ7Cqv8yAWZpewOm8i5TlOq6L6eBbc/J"}}' - -testzen keygen "${keyring}" - -testzen byte_equal '{"output":["1"]}' '{"left":"dGhpcyBpcyBhIGJhc2U2NCBzdHJpbmcK","right":"dGhpcyBpcyBhIGJhc2U2NCBzdHJpbmcK"}' > /dev/null - -gql64=`mktemp` - -# example graphql with most allowed characters used -gqljson=`mktemp` -cat <<EOF | base64 -w0 > ${gql64} -mutation { - createEconomicEvent( - event: { - action: "produce" - provider: "01FWN12XX7TJX1AFF5KA4WPNN9" # bob - receiver: "01FWN12XX7TJX1AFF5KA4WPNN9" # bob - outputOf: "01FWN136SPDMKWWF23SWQZRM5F" # harvesting apples process - resourceConformsTo: "01FWN136Y4ZZ7K9F314HQ7MKRG" # apple - resourceQuantity: { - hasNumericalValue: 50 - hasUnit: "01FWN136S5VPCCR3B3TGYDYEY9" # kilogram - } - atLocation: "01FWN136ZAPQ5ENBF3FZ79935D" # bob's farm - hasPointInTime: "2022-01-02T03:04:05Z" - } - newInventoriedResource: { - name: "bob's apples" - note: "bob's delish apples" - trackingIdentifier: "lot 123" - currentLocation: "01FWN136ZAPQ5ENBF3FZ79935D" # bob's farm - stage: "01FWN136X183DM43CTWXESNWAB" # fresh - } - ) { - economicEvent { - id - action {id} - provider {id} - receiver {id} - outputOf {id} - resourceConformsTo {id} - resourceQuantity { - hasNumericalValue - hasUnit {id} - } - atLocation {id} - hasPointInTime - } - economicResource { # this is the newly-created resource - id - name - note - trackingIdentifier - stage {id} - currentLocation {id} - conformsTo {id} - primaryAccountable {id} - custodian {id} - accountingQuantity { - hasNumericalValue - hasUnit {id} - } - onhandQuantity { - hasNumericalValue - hasUnit {id} - } - } - } -} -EOF - -cat <<EOF > ${gqljson} -{"graphql":"`cat ${gql64}`"} -EOF - -keyfile=`mktemp` -echo ${keyring} > ${keyfile} - -gqlsigned=`mktemp` -testzen sign_graphql '{"eddsa_signature":"4UNmAMzk8Qi44rd72ocxbN8ijv7RtFASPX9yfHnjVrtp8kWyktyJWZZnyodeFr42GZ5rGPVAU5McaD41dW4hotqi","graphql":"bXV0YXRpb24gewogIGNyZWF0ZUVjb25vbWljRXZlbnQoCiAgICBldmVudDogewogICAgICBhY3Rpb246ICJwcm9kdWNlIgogICAgICBwcm92aWRlcjogIjAxRldOMTJYWDdUSlgxQUZGNUtBNFdQTk45IiAjIGJvYgogICAgICByZWNlaXZlcjogIjAxRldOMTJYWDdUSlgxQUZGNUtBNFdQTk45IiAjIGJvYgogICAgICBvdXRwdXRPZjogIjAxRldOMTM2U1BETUtXV0YyM1NXUVpSTTVGIiAjIGhhcnZlc3RpbmcgYXBwbGVzIHByb2Nlc3MKICAgICAgcmVzb3VyY2VDb25mb3Jtc1RvOiAiMDFGV04xMzZZNFpaN0s5RjMxNEhRN01LUkciICMgYXBwbGUKICAgICAgcmVzb3VyY2VRdWFudGl0eTogewogICAgICAgIGhhc051bWVyaWNhbFZhbHVlOiA1MAogICAgICAgIGhhc1VuaXQ6ICIwMUZXTjEzNlM1VlBDQ1IzQjNUR1lEWUVZOSIgIyBraWxvZ3JhbQogICAgICB9CiAgICAgIGF0TG9jYXRpb246ICIwMUZXTjEzNlpBUFE1RU5CRjNGWjc5OTM1RCIgIyBib2IncyBmYXJtCiAgICAgIGhhc1BvaW50SW5UaW1lOiAiMjAyMi0wMS0wMlQwMzowNDowNVoiCiAgICB9CiAgICBuZXdJbnZlbnRvcmllZFJlc291cmNlOiB7CiAgICAgIG5hbWU6ICJib2IncyBhcHBsZXMiCiAgICAgIG5vdGU6ICJib2IncyBkZWxpc2ggYXBwbGVzIgogICAgICB0cmFja2luZ0lkZW50aWZpZXI6ICJsb3QgMTIzIgogICAgICBjdXJyZW50TG9jYXRpb246ICIwMUZXTjEzNlpBUFE1RU5CRjNGWjc5OTM1RCIgIyBib2IncyBmYXJtCiAgICAgIHN0YWdlOiAiMDFGV04xMzZYMTgzRE00M0NUV1hFU05XQUIiICMgZnJlc2gKICAgIH0KICApIHsKICAgIGVjb25vbWljRXZlbnQgewogICAgICBpZAogICAgICBhY3Rpb24ge2lkfQogICAgICBwcm92aWRlciB7aWR9CiAgICAgIHJlY2VpdmVyIHtpZH0KICAgICAgb3V0cHV0T2Yge2lkfQogICAgICByZXNvdXJjZUNvbmZvcm1zVG8ge2lkfQogICAgICByZXNvdXJjZVF1YW50aXR5IHsKICAgICAgICBoYXNOdW1lcmljYWxWYWx1ZQogICAgICAgIGhhc1VuaXQge2lkfQogICAgICB9CiAgICAgIGF0TG9jYXRpb24ge2lkfQogICAgICBoYXNQb2ludEluVGltZQogICAgfQogICAgZWNvbm9taWNSZXNvdXJjZSB7ICMgdGhpcyBpcyB0aGUgbmV3bHktY3JlYXRlZCByZXNvdXJjZQogICAgICBpZAogICAgICBuYW1lCiAgICAgIG5vdGUKICAgICAgdHJhY2tpbmdJZGVudGlmaWVyCiAgICAgIHN0YWdlIHtpZH0KICAgICAgY3VycmVudExvY2F0aW9uIHtpZH0KICAgICAgY29uZm9ybXNUbyB7aWR9CiAgICAgIHByaW1hcnlBY2NvdW50YWJsZSB7aWR9CiAgICAgIGN1c3RvZGlhbiB7aWR9CiAgICAgIGFjY291bnRpbmdRdWFudGl0eSB7CiAgICAgICAgaGFzTnVtZXJpY2FsVmFsdWUKICAgICAgICBoYXNVbml0IHtpZH0KICAgICAgfQogICAgICBvbmhhbmRRdWFudGl0eSB7CiAgICAgICAgaGFzTnVtZXJpY2FsVmFsdWUKICAgICAgICBoYXNVbml0IHtpZH0KICAgICAgfQogICAgfQogIH0KfQo="}' ${gqljson} ${keyfile} > ${gqlsigned} -# cat sign_graphql.zen | zenroom -z -c ${conf} -k ${keyfile} -a ${gqljson} > ${gqlsigned} - -testzen verify_graphql '{"output":["VALID_SIGNATURE"]}' ${gqlsigned} ${keyfile} > /dev/null - -# cleanup tempfiles -rm -f $keyfile $gqljson $gql64 $gqlsigned - -echo >> $results -cat $results -rm -f $results