From 06b50c9c3f753e5f16dac11a595a535c90cec390 Mon Sep 17 00:00:00 2001 From: Curtis Date: Fri, 8 Mar 2024 10:57:21 +0000 Subject: [PATCH] feat: updating Anoncreds to io fork (#157) --- .gitmodules | 11 +-- build_dependencies.sh | 68 ---------------- externals/README.md | 11 +++ externals/run.sh | 185 ++++++++++++++++++++++++++++++++++++++++++ package.json | 17 ++-- 5 files changed, 212 insertions(+), 80 deletions(-) delete mode 100644 build_dependencies.sh create mode 100644 externals/README.md create mode 100755 externals/run.sh diff --git a/.gitmodules b/.gitmodules index 610a6c042..9fad52261 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,7 +1,8 @@ [submodule "externals/anoncreds"] - path = externals/anoncreds - url = git@github.com:curtis-h/anoncreds-rs.git - branch = wasm-prism + path = externals/anoncreds + url = git@github.com:input-output-hk/anoncreds-rs.git + branch = feature/wasm + [submodule "externals/didcomm"] - path = externals/didcomm - url = git@github.com:sicpa-dlab/didcomm-rust.git + path = externals/didcomm + url = git@github.com:sicpa-dlab/didcomm-rust.git diff --git a/build_dependencies.sh b/build_dependencies.sh deleted file mode 100644 index 32868e108..000000000 --- a/build_dependencies.sh +++ /dev/null @@ -1,68 +0,0 @@ -#!bin/bash -ExternalsFolder="./externals" -DIDCommFolder="./externals/didcomm" -AnonCredsFolder="./externals/anoncreds" -GeneratedFolder="./generated" -buildDIDComm() { - cd $DIDCommFolder/wasm - wasm-pack build --target=web --out-dir=../../../generated/didcomm-wasm-browser - wasm-pack build --target=nodejs --out-dir=../../../generated/didcomm-wasm-node - #TODO: find better way to approach this - #This code fails on browser when wasm is first loaded, it can just be ignored - #The code will fully work - sed "/if (typeof input === 'undefined') {/,/}/d" ../../../generated/didcomm-wasm-browser/didcomm_js.js > temp_file && mv temp_file ../../../generated/didcomm-wasm-browser/didcomm_js.js - cd ../../../ - git submodule | grep didcomm | awk '{print $1}' > ./didcomm.commit -} - -buildAnoncreds() { - cd $AnonCredsFolder - wasm-pack build --target=web --no-default-features --features=wasm - #TODO: find better way to approach this - #This code fails on browser when wasm is first loaded, it can just be ignored - #The code will fully work - sed '/if (typeof input === '\''undefined'\'') {/,/}/d' pkg/anoncreds.js > temp_file && mv temp_file pkg/anoncreds.js - rm -rf ../../generated/anoncreds-wasm-browser - mv pkg ../../generated/anoncreds-wasm-browser - wasm-pack build --target=nodejs --no-default-features --features=wasm - rm -rf ../../generated/anoncreds-wasm-node - mv pkg ../../generated/anoncreds-wasm-node - cd ../../ - rm ./anoncreds.commit - git submodule | grep anoncreds | awk '{print $1}' >> ./anoncreds.commit -} - -if [ -z "$(find "$DIDCommFolder" -maxdepth 1 -type f)" ] || [ -z "$(find "$AnonCredsFolder" -maxdepth 1 -type f)" ]; then - # The folder does not exist - echo "Automatically initializing submodules" - mkdir -p ./externals - git submodule update --init --recursive --remote - -fi - -if [ ! -d "$GeneratedFolder" ]; then - rm -rf ./generated - mkdir -p ./generated - echo "Storing submodule reference" - - buildDIDComm - buildAnoncreds -fi - - -didcommOldCommit=$(cat didcomm.commit) -didcommNewCommit=$(git submodule | grep didcomm | awk '{print $1}') - -if [ "$didcommOldCommit" != "$didcommNewCommit" ]; then - buildDIDComm -else - echo "DIDComm ($didcommNewCommit) is last version." -fi - -anoncredsOldCommit=$(cat anoncreds.commit) -anoncredsNewCommit=$(git submodule | grep anoncreds | awk '{print $1}') -if [ "$anoncredsOldCommit" != "$anoncredsNewCommit" ]; then - buildAnoncreds -else - echo "Anoncreds ($anoncredsNewCommit) is last version." -fi \ No newline at end of file diff --git a/externals/README.md b/externals/README.md new file mode 100644 index 000000000..8628f02d0 --- /dev/null +++ b/externals/README.md @@ -0,0 +1,11 @@ +# Externals + +Manage external code dependencies. + + +### Files and Folders +[run.sh](./run.sh) - script to help manage dependency installation and builds. + +`/generated` - folder for dependency code. + +`*.commit` - files to track the commit for a submodule build. diff --git a/externals/run.sh b/externals/run.sh new file mode 100755 index 000000000..edcae4047 --- /dev/null +++ b/externals/run.sh @@ -0,0 +1,185 @@ +#!/bin/bash + +cwd=`pwd` +ExternalsDir="${cwd}/externals" +GeneratedDir="${ExternalsDir}/generated" +AnonCreds=anoncreds +AnonCredsDir="${ExternalsDir}/${AnonCreds}" +DIDComm=didcomm +DIDCommDir="${ExternalsDir}/${DIDComm}" + +BOLD='\033[1m' +BLUE='\033[33m' +GREEN='\033[32m' +RED='\033[31m' +END='\033[0m' + + +didcommNewCommit=$(git submodule | grep $DIDComm | awk '{print $1}') +didcommOldCommit=$(cat "${ExternalsDir}/${DIDComm}.commit" 2>/dev/null) +didcommRequired=$? + +anoncredsNewCommit=$(git submodule | grep $AnonCreds | awk '{print $1}') +anoncredsOldCommit=$(cat "${ExternalsDir}/${AnonCreds}.commit" 2>/dev/null) +anoncredsRequired=$? + + +buildDIDComm() { + echo "Build DIDComm" + + local GenDIDComm="${GeneratedDir}/${DIDComm}" + # remove previous generated + rm -rfv "${GenDIDComm}*" + # generate new + cd "${DIDCommDir}/wasm" + wasm-pack build --target=web --out-dir="${GenDIDComm}-wasm-browser" + wasm-pack build --target=nodejs --out-dir="${GenDIDComm}-wasm-node" + + #TODO: find better way to approach this + #This code fails on browser when wasm is first loaded, it can just be ignored + #The code will fully work + cd "${GenDIDComm}-wasm-browser" + sed -i "/if (typeof input === 'undefined') {/,/}/d" didcomm_js.js + + cd $ExternalsDir + git submodule | grep $DIDComm | awk '{print $1}' > "./${DIDComm}.commit" +} + +buildAnonCreds() { + echo "Build AnonCreds" + + GenAnonCreds="${GeneratedDir}/${AnonCreds}" + rm -rfv "${GenAnonCreds}*" + + cd $AnonCredsDir + + # cant use --out-dir + wasm-pack build --target=web --no-default-features --features=wasm + mv pkg "${GenAnonCreds}-wasm-browser" + + wasm-pack build --target=nodejs --no-default-features --features=wasm + mv pkg "${GenAnonCreds}-wasm-node" + + #TODO: find better way to approach this + #This code fails on browser when wasm is first loaded, it can just be ignored + #The code will fully work + cd "${GenAnonCreds}-wasm-browser" + sed -i '/if (typeof input === '\''undefined'\'') {/,/}/d' "./${AnonCreds}.js" + + cd $ExternalsDir + git submodule | grep $AnonCreds | awk '{print $1}' > "./${AnonCreds}.commit" +} + +checkDIDComm() { + # no commit found - update + # commits mismatch - update + # submodule folder missing - update + if [ "$didcommRequired" -eq 1 ] || \ + [ "$didcommOldCommit" != "$didcommNewCommit" ] || \ + [ -z "$(find "$DIDCommDir" -maxdepth 1 -type f)" ]; then + return 2 + # generated folder missing - build + elif [ -z "$(find "${GeneratedDir}" -name "${DIDComm}*" -maxdepth 1 -type d 2>/dev/null)" ]; then + return 1 + else + return 0 + fi +} + +checkAnonCreds() { + # no commit found - update + # commits mismatch - update + # submodule folder missing - update + if [ "$anoncredsRequired" -eq 1 ] || \ + [ "$anoncredsOldCommit" != "$anoncredsNewCommit" ] || \ + [ -z "$(find "$AnonCredsDir" -maxdepth 1 -type f)" ]; then + return 2 + # generated folder missing - build + elif [ -z "$(find "${GeneratedDir}" -name "${AnonCreds}*" -maxdepth 1 -type d 2>/dev/null)" ]; then + return 1 + else + return 0 + fi +} + +checkSubmodules() { + echo "Checking submodules" + git submodule sync + echo + + # update latest commit after sync + didcommNewCommit=$(git submodule | grep $DIDComm | awk '{print $1}') + anoncredsNewCommit=$(git submodule | grep $AnonCreds | awk '{print $1}') + + checkAnonCreds + anoncredsResult=$? + checkDIDComm + didcommResult=$? + + case "$anoncredsResult" in + "2") echo -e "${BOLD}AnonCreds: ${RED}out of date ${END}" ;; + "1") echo -e "${BOLD}AnonCreds: ${RED}build files missing${END}" ;; + "0") echo -e "${BOLD}AnonCreds: ${GREEN}up to date ${END}" ;; + esac + + case "$didcommResult" in + "2") echo -e "${BOLD}DIDComm: ${RED}out of date ${END}" ;; + "1") echo -e "${BOLD}DIDComm: ${RED}build files missing${END}" ;; + "0") echo -e "${BOLD}DIDComm: ${GREEN}up to date ${END}" ;; + esac + + + echo + + if [ "$anoncredsResult" -eq 2 ] || [ "$didcommResult" -eq 2 ]; then + echo -e "Update submodules with: ${BLUE}npm run externals:update${END}" + elif [ "$anoncredsResult" -eq 1 ] || [ "$didcommResult" -eq 1 ]; then + echo -e "Build submodules with: ${BLUE}npm run externals:build${END}" + fi +} + +# parse args +while [[ "$#" -gt 0 ]]; do + case $1 in + -x) execute="$2"; shift ;; + # -t) target="$2"; shift ;; + *) echo "Unknown parameter passed: $1"; exit 1 ;; + esac + shift +done + + +if [ "$execute" = "check" ]; then + checkSubmodules +elif [ "$execute" = "build" ]; then + echo "Building submodules" + mkdir -p "$GeneratedDir" + buildAnonCreds + buildDIDComm +elif [ "$execute" = "update" ]; then + echo "Updating submodules" + mkdir -p "$GeneratedDir" + git submodule update --init --recursive --remote + + checkAnonCreds + anoncredsResult=$? + checkDIDComm + didcommResult=$? + + if [ "$anoncredsResult" -ne 0 ]; then + buildAnonCreds + fi + + if [ "$didcommResult" -ne 0 ]; then + buildDIDComm + fi +else + echo "Usage: $0 [-x execution mode]" + echo " -x [build | check | update]" + echo " build - build the current submodules" + echo " check - check the status" + echo " update - get latest and build the submodules" + echo + echo "Example: $0 -x check" + exit 1 +fi diff --git a/package.json b/package.json index 9193c1f0a..e97bd222c 100644 --- a/package.json +++ b/package.json @@ -27,11 +27,14 @@ "last 2 edge version" ], "scripts": { - "dependencies": "sh build_dependencies.sh", - "build": "npm run dependencies && rm -rf build && npm run build:browser && npm run build:node && npm run types", - "types": "rm -rf build/typings && tsc", + "externals:check": "./externals/run.sh -x check", + "externals:build": "./externals/run.sh -x build", + "externals:update": "./externals/run.sh -x update", + "build": "npm run externals:update && rm -rf build && npm run build:browser && npm run build:node && npm run types", + "build:dev": "npm run externals:check && rm -rf build && npm run build:browser && npm run build:node && npm run types", "build:browser": "rollup -c rollup/rollup.browser.mjs", "build:node": "rollup -c rollup/rollup.node.mjs", + "types": "rm -rf build/typings && tsc", "test": "jest", "coverage": "npm run test -- --coverage", "lint": "npx eslint .", @@ -83,8 +86,8 @@ "@types/uuid": "^9.0.1", "@typescript-eslint/eslint-plugin": "^5.56.0", "@typescript-eslint/parser": "^5.55.0", - "anoncreds-browser": "file:./generated/anoncreds-wasm-browser", - "anoncreds-node": "file:./generated/anoncreds-wasm-node", + "anoncreds-browser": "file:./externals/generated/anoncreds-wasm-browser", + "anoncreds-node": "file:./externals/generated/anoncreds-wasm-node", "babel-plugin-transform-import-meta": "^2.2.0", "babel-plugin-transform-typescript-metadata": "^0.3.2", "chai": "^4.3.7", @@ -92,8 +95,8 @@ "clean-webpack-plugin": "^4.0.0", "copy-webpack-plugin": "^11.0.0", "core-js": "^3.32.2", - "didcomm-browser": "file:./generated/didcomm-wasm-browser", - "didcomm-node": "file:./generated/didcomm-wasm-node", + "didcomm-browser": "file:./externals/generated/didcomm-wasm-browser", + "didcomm-node": "file:./externals/generated/didcomm-wasm-node", "eslint": "^8.36.0", "eslint-config-react-app": "^7.0.1", "eslint-config-standard-with-typescript": "^34.0.1",