Skip to content

Commit

Permalink
Merge pull request #31 from mlabs-haskell/move-to-workspaces
Browse files Browse the repository at this point in the history
Move to npm workspaces, turbo repo and bun
  • Loading branch information
adamczykm authored May 7, 2024
2 parents f2e71b4 + cbbe084 commit e256642
Show file tree
Hide file tree
Showing 249 changed files with 247 additions and 63,438 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# turbo
.turbo

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ The zero-knowledge part is provided via MINA's o1js library.
## Core Components
This repository is organized as a monorepo containing all the system's core components.

### MinAuth Library [:link:](https://github.com/mlabs-haskell/MinAuth/tree/develop/minauth)
### MinAuth Library [:link:](https://github.com/mlabs-haskell/MinAuth/tree/develop/library/minauth)
The library provides all the core types and interfaces that allow for cooperation between the system's elements. It has functions and utilities that help quickly set up compatible authorization plugins. Additionally, it contains tools that may be useful when working with MinAuth, for example, a plugin HTTP server, and a compatible passport.js strategy.

### MinAuth Plugins [:link:](https://github.com/mlabs-haskell/MinAuth/tree/develop/minauth-plugins)
### MinAuth Plugins [:link:](https://github.com/mlabs-haskell/MinAuth/tree/develop/plugins)
MinAuth features a plugin-based architecture where the main functionality of building and verifying proofs is done via plugins. It provides a couple of example plugins and various utilities for building custom ones.
The plugin may, but doesn't have to involve blockchains such as MINA (the natural choice because of `o1js`).
Since the authorization is given by a centralized authority (for example a server exposing a protected API) the proofs may regard any data that is verifiable by this authority ( blockchains, 3rd party database, trusted KYC provider's API data, trusted public keys, NFTs, etc).
Expand All @@ -26,21 +26,21 @@ You can find it [https://github.com/adamczykm/minauth-plugin-starter-pack](here)

### Provided plugins

**A Simple Preimage Plugin** [:link:](https://github.com/mlabs-haskell/MinAuth/tree/develop/minauth-plugins/minauth-simple-preimage-plugin)
**A Simple Preimage Plugin** [:link:](https://github.com/mlabs-haskell/MinAuth/tree/develop/plugins/minauth-simple-preimage-plugin)
Probably the simplest possible plugin which functionality equals to that of a password authentication.
The server holds a set of Poseidon hashes assigned to roles or users. A ZKSnark that prove the knowledge of the preimage of given hash will grant the access.

**Merkle Memberships Plugin** [:link:](https://github.com/mlabs-haskell/MinAuth/tree/develop/minauth-plugins/minauth-merkle-membership-plugin)
**Merkle Memberships Plugin** [:link:](https://github.com/mlabs-haskell/MinAuth/tree/develop/plugins/minauth-merkle-membership-plugin)
A simple plugin that features an amazing `o1js` feature of recursive proofs.
Server is set up to have access to a storage of Merkle trees of secret commitments that can optionally be pinned to a MINA contract via their roots.
The client can prove "membership" into the sets represented by merkle trees, by recursively adding proof layers. Each layer accepts a merkle witness and the secret behind the commitment.

**ERC721 Time-lock Plugin** [:link:](https://github.com/mlabs-haskell/MinAuth/tree/develop/minauth-plugins/minauth-erc721-timelock-plugin)
**ERC721 Time-lock Plugin** [:link:](https://github.com/mlabs-haskell/MinAuth/tree/develop/plugins/minauth-erc721-timelock-plugin)
A plugin that demonstrates the ability to work against publicly verifiable data hosted on a blockchain. In this case Ethereum. The plugin is configured to point to a contract with a special interface that allow to time-lock an Ethereum NFT along with a secret commitment.
The plugin then monitors the chain and the contract state (and events) to build a merkle tree of secret commitments.
The prover can prove that

### MinAuth Demo [:link:](https://github.com/mlabs-haskell/MinAuth/tree/develop/minauth-demo)
### MinAuth Demo [:link:](https://github.com/mlabs-haskell/MinAuth/tree/develop/demo-apps)
Part of MinAuth's value proposition is to show a way to connect these innovative technologies in a full-stack web application where all the system components are configured and set up to work together. Consider it an example of how MinAuth can be set up with JWT-based ZKP-backed authentication and a playground to test out plugins or build your own.

## Usage
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
36 changes: 36 additions & 0 deletions _devops/mkenvrc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

# Check if direnv is installed
if ! command -v direnv &> /dev/null; then
echo "Error: 'direnv' is not installed. Please install it and try again."
exit 1
fi

# Check if the path to the .envrc file is provided
if [ -z "$1" ]; then
echo "Please provide the path to the .envrc file as an argument."
exit 1
fi

# Resolve the absolute path of the given .envrc file
DIRPATH=$(realpath "$1")
ENVRCPATH=$DIRPATH/.envrc

# Construct the export command using the current working directory
NODE_MODULES_PATH=$DIRPATH/node_modules
EXPORT_COMMAND="export NODE_MODULES=${NODE_MODULES_PATH}"

# Check if the .envrc file exists, if not, create it
if [ ! -f "$ENVRCPATH" ]; then
touch "$ENVRCPATH"
fi

# Check if the export command is already present in the .envrc file
if grep -Fxq "$EXPORT_COMMAND" "$ENVRCPATH"; then
echo "NODE_MODULES is already set in ${ENVRCPATH}"
else
# Append the export command to the file
echo "$EXPORT_COMMAND" >> "$ENVRCPATH"
echo "Successfully added NODE_MODULES to ${ENVRCPATH}"
fi

Binary file added bun.lockb
Binary file not shown.
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions demo-apps/minauth-demo-client/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# minauth-demo-client

## 0.12.0

### Minor Changes

- Make package compatible with npm workspaces. Migrate to using bun and turbo repo.

### Patch Changes

- Updated dependencies
- [email protected]
- [email protected]
- [email protected]
- [email protected]
File renamed without changes.
File renamed without changes.
35 changes: 35 additions & 0 deletions demo-apps/minauth-demo-client/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
productionBrowserSourceMaps: false,
reactStrictMode: false,

webpack(config) {
config.resolve.alias = {
...config.resolve.alias,
o1js: `${process.env.NODE_MODULES}/o1js`
};
config.experiments = {
...config.experiments,
topLevelAwait: true
};
return config;
},
// To enable o1js for the web, we must set the COOP and COEP headers.
// See here for more information: https://docs.minaprotocol.com/zkapps/how-to-write-a-zkapp-ui#enabling-coop-and-coep-headers
async headers() {
return [{
source: '/(.*)',
headers: [{
key: 'Cross-Origin-Opener-Policy',
value: 'same-origin'
},
{
key: 'Cross-Origin-Embedder-Policy',
value: 'require-corp'
}
]
}];
}
};

module.exports = nextConfig;
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "minauth-demo-client",
"version": "0.11.0",
"version": "0.12.0",
"private": true,
"scripts": {
"install-ci": "npm install --unsafe-perm=true",
"dev": "next dev",
"dev-kill": "bash -c 'next dev & PID=$!; sleep 5; kill $PID; exit 0'",
"build": "node --max-old-space-size=8192 ./node_modules/.bin/next build",
"start": "next start",
"install-ci": "bun install --unsafe-perm=true",
"dev": "bunx next dev",
"dev-kill": "bash -c 'bunx next dev & PID=$!; sleep 5; kill $PID; exit 0'",
"build": "bunx next build",
"start": "bunx next start",
"test": "echo \"Error: no tests here\" && exit 0",
"lint": "next lint",
"ts-watch": "tsc --noEmit --incremental --watch"
Expand All @@ -23,10 +23,10 @@
"eslint": "8.55.0",
"ethers": "^6.9.2",
"fp-ts": "^2.16.2",
"minauth": "file:./../../minauth",
"minauth-erc721-timelock-plugin": "file:./../../minauth-plugins/minauth-erc721-timelock-plugin",
"minauth-merkle-membership-plugin": "file:./../../minauth-plugins/minauth-merkle-membership-plugin",
"minauth-simple-preimage-plugin": "file:./../../minauth-plugins/minauth-simple-preimage-plugin",
"minauth": "workspace:*",
"minauth-erc721-timelock-plugin": "workspace:*",
"minauth-merkle-membership-plugin": "workspace:*",
"minauth-simple-preimage-plugin": "workspace:*",
"next": "*",
"o1js": "0.16.0",
"postcss": "8.4.32",
Expand Down
File renamed without changes.
13 changes: 13 additions & 0 deletions demo-apps/minauth-demo-client/turbo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": [
"//"
],
"pipeline": {
"build": {
"outputs": [
".next/**",
"!.next/cache/**"
]
}
}
}
File renamed without changes.
15 changes: 15 additions & 0 deletions demo-apps/minauth-demo-server/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# minauth-demo-server

## 0.12.0

### Minor Changes

- Make package compatible with npm workspaces. Migrate to using bun and turbo repo.

### Patch Changes

- Updated dependencies
- [email protected]
- [email protected]
- [email protected]
- [email protected]
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "minauth-demo-server",
"version": "0.11.0",
"version": "0.12.0",
"description": "",
"type": "module",
"main": "index.js",
Expand All @@ -9,8 +9,8 @@
"run-client": "node ./dist/headless-test-client/index.js",
"hardhat-node": "cd eth-contract && npx hardhat node && cd ..",
"deploy-eth-contracts": "cd eth-contract && rm -rf ./ignition/deployments/chain-31337 && npx ts-node scripts/cli.ts deploy-erc721timelock --lock-period 60 && npx ts-node scripts/cli.ts deploy-erc721mock -n 'minauth_nft' -s 'MNFT' && cd ..",
"serve-api": "node ./dist/api-server/index.js",
"serve-plugin-server": "node ./node_modules/minauth/dist/tools/plugin-server/index.js",
"serve-api": "bunx node ./dist/api-server/index.js",
"serve-plugin-server": "bunx node $NODE_MODULES/minauth/dist/tools/plugin-server/index.js",
"run-backend": "concurrently 'npm run serve-plugin-server' 'npm run serve-api' 'npm run hardhat-node' 'npm run deploy-eth-contracts' -c magent,green,yellow,blue",
"prettier-format": "prettier --config .prettierrc 'src/**/*.ts' --write",
"test": "NODE_OPTIONS=--experimental-vm-modules npx jest",
Expand All @@ -30,10 +30,10 @@
"fp-ts": "^2.16.1",
"http-proxy-middleware": "^2.0.6",
"jsonwebtoken": "^9.0.2",
"minauth": "file:./../../minauth",
"minauth-erc721-timelock-plugin": "file:./../../minauth-plugins/minauth-erc721-timelock-plugin",
"minauth-merkle-membership-plugin": "file:./../../minauth-plugins/minauth-merkle-membership-plugin",
"minauth-simple-preimage-plugin": "file:./../../minauth-plugins/minauth-simple-preimage-plugin",
"minauth": "workspace:*",
"minauth-erc721-timelock-plugin": "workspace:*",
"minauth-merkle-membership-plugin": "workspace:*",
"minauth-simple-preimage-plugin": "workspace:*",
"o1js": "0.16.0",
"passport": "^0.6.0",
"passport-jwt": "^4.0.1",
Expand Down
1 change: 1 addition & 0 deletions demo-apps/minauth-demo-server/plugins/erc721-timelock
1 change: 1 addition & 0 deletions demo-apps/minauth-demo-server/plugins/merkle-memberships
1 change: 1 addition & 0 deletions demo-apps/minauth-demo-server/plugins/simple-preimage
23 changes: 23 additions & 0 deletions demo-apps/minauth-demo-server/scripts/resolve-and-run.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// File: scripts/serve-plugin-server.js
const path = require("path");
const { execSync } = require("child_process");

console.log(process.argv);

if (process.argv.length < 3) {
console.error("Please provide a path to resolve, e.g., 'minauth/dist/tools/plugin-server/index.js'");
process.exit(1);
}

// The first two elements in `process.argv` are 'node' and the script name
const packagePath = process.argv[2];

// Attempt to resolve the package
try {
const resolvedPath = require.resolve(packagePath);
execSync(`bunx node ${resolvedPath}`, { stdio: "inherit" });
} catch (error) {
console.error(`Error: Unable to resolve path "${packagePath}"`);
process.exit(1);
}

File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions library/minauth/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# minauth

## 0.12.0

### Minor Changes

- Make package compatible with npm workspaces. Migrate to using bun and turbo repo.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions minauth/package.json → library/minauth/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "minauth",
"version": "0.11.0",
"version": "0.12.0",
"description": "A TypeScript library for building authentication systems on top of the Mina blockchain and other zero-knowledge proofs solutions.",
"type": "module",
"files": [
Expand All @@ -10,7 +10,7 @@
"build": "tsc -p tsconfig.json",
"lint": "eslint . --ext .ts",
"prettier-format": "prettier --config .prettierrc 'src/**/*.ts' --write",
"test": "echo \"E2E & integration tests are provided in the minauth-demo package.\" && jest --config jest.config.ts"
"test": "echo \"E2E & integration tests are provided in the minauth-demo-server package.\" && jest --config jest.config.ts"
},
"repository": {
"type": "git",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
35 changes: 0 additions & 35 deletions minauth-demo/minauth-demo-client/next.config.js

This file was deleted.

Loading

0 comments on commit e256642

Please sign in to comment.