Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: updating Anoncreds to io fork #157

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[submodule "externals/anoncreds"]
path = externals/anoncreds
url = [email protected]:curtis-h/anoncreds-rs.git
branch = wasm-prism
path = externals/anoncreds
url = [email protected]:input-output-hk/anoncreds-rs.git
branch = feature/wasm

[submodule "externals/didcomm"]
path = externals/didcomm
url = [email protected]:sicpa-dlab/didcomm-rust.git
path = externals/didcomm
url = [email protected]:sicpa-dlab/didcomm-rust.git
68 changes: 0 additions & 68 deletions build_dependencies.sh

This file was deleted.

11 changes: 11 additions & 0 deletions externals/README.md
Original file line number Diff line number Diff line change
@@ -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.
185 changes: 185 additions & 0 deletions externals/run.sh
Original file line number Diff line number Diff line change
@@ -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
17 changes: 10 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 .",
Expand Down Expand Up @@ -83,17 +86,17 @@
"@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",
"chai-as-promised": "^7.1.1",
"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",
Expand Down
Loading