Skip to content

Commit

Permalink
Merge pull request #48 from hollow-leaf/feat/arBackend
Browse files Browse the repository at this point in the history
feat: ar backend
  • Loading branch information
kidneyweakx authored Sep 11, 2023
2 parents d0e29da + 6280172 commit f860f6e
Show file tree
Hide file tree
Showing 14 changed files with 12,267 additions and 379 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18.12
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Simultaneously, we employ zero-knowledge proofs to safeguard user data while ach
sequenceDiagram
actor User
participant Web
participant I as LightHouse IPFS
participant I as Arweave and Filecoin
participant Z as Zero Knowledge Model
participant S as Sepolia
participant T as Tezos
Expand Down Expand Up @@ -128,6 +128,12 @@ pnpm run dev
pnpm build
```

7. Arweave Upload Model Service
```sh
# copy private key to packages
touch packages/arweave-service/wallet.json
docker-compose -f packages/arweave-service/docker-compose.yaml up -d --build ar_backend
```
### Contributors
- Frontend + Voting Contract: [YeeeTai](https://github.com/YeeeTai)
- ZKML Model Circuits + Wormhole Support + LightHouse Support: [kidneyweakx](https://github.com/kidneyweakx)
Expand Down
1 change: 1 addition & 0 deletions packages/arweave-service/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
2 changes: 2 additions & 0 deletions packages/arweave-service/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
wallet.json
logs
15 changes: 15 additions & 0 deletions packages/arweave-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM node:18.16-alpine3.16

WORKDIR /usr/src/app

RUN apk add git

COPY package.json .

RUN npm install

COPY . .

EXPOSE 8080

CMD ["npx", "ts-node", "--esm" ,"src/app.ts" ]
33 changes: 33 additions & 0 deletions packages/arweave-service/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: '3.7'
services:
ar_backend:
container_name: ar_backend
image: ar_backend
ports:
- '8080:8080'
restart: always
networks:
- ar_network
build:
context: ./
dockerfile: Dockerfile
caddy:
container_name: ar_caddy
image: caddy:latest
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
- ./scripts/caddy_data:/data
- ./scripts/caddy_config:/config
- ./scripts/caddy_config/Caddyfile:/etc/caddy/Caddyfile
networks:
- ar_network
- public_access

networks:
public_access:
ar_network:
name: ar_network
driver: bridge
24 changes: 24 additions & 0 deletions packages/arweave-service/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "arweave-service",
"version": "1.0.0",
"type": "module",
"scripts": {
"start": "ts-node --esm src/service/ar.ts",
"ar:local": "arlocal",
"build": "docker build -f Dockerfile -t arbackend ."
},
"devDependencies": {
"@types/cors": "^2.8.14",
"@types/express": "^4.17.17",
"arlocal": "^1.1.61",
"dotenv": "^16.3.1",
"ts-node": "^10.9.1",
"typescript": "^5.2.2"
},
"dependencies": {
"arweavekit": "^1.4.9",
"cors": "^2.8.5",
"ethers": "6.7.1",
"express": "^4.18.2"
}
}
60 changes: 60 additions & 0 deletions packages/arweave-service/src/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import express from 'express'
import cors from 'cors'
import { upload, list } from './service/ar.js'
import fs from 'fs'

const app = express()

app.use(cors())
app.use(express.json())
app.use(express.urlencoded({ extended: true }))

app.post('/upload', async (req, res) => {
const key = JSON.parse(fs.readFileSync('./wallet.json').toString())
try {
const data = {
in: req.body.in,
conv2d_weights: req.body.conv2d_weights,
conv2d_bias: req.body.conv2d_bias,
batch_normalization_a: req.body.batch_normalization_a,
dense_weights: req.body.dense_weights,
dense_bias: req.body.dense_bias,
}
const response = await upload(data, key, 'mainnet')
res.send(response)
} catch (e) {
res.send(`Error: ${e}`)
}
})

app.post('/uploadTest', async (req, res) => {
const key = JSON.parse(fs.readFileSync('./wallet.json').toString())
try {
const data = {
in: req.body.in,
conv2d_weights: req.body.conv2d_weights,
conv2d_bias: req.body.conv2d_bias,
batch_normalization_a: req.body.batch_normalization_a,
dense_weights: req.body.dense_weights,
dense_bias: req.body.dense_bias,
}
const response = await upload(data, key, 'local')
res.send(response)
} catch (e) {
res.send(`Error: ${e}`)
}
})

app.get('/uploadExample', async (req, res) => {
const key = JSON.parse(fs.readFileSync('./wallet.json').toString())
const data = JSON.parse(fs.readFileSync('./src/resource/model.json').toString())
const tx = await upload(data, key, 'local')
res.send(JSON.parse(tx))
})

app.post('/list', async (req, res) => {
const data = req.body
const response = await list(data.priv, data.name, data.url)
res.send(response)
})
app.listen(8080)
9 changes: 9 additions & 0 deletions packages/arweave-service/src/interface/model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export interface IAgeModel {
in: number[][]
conv2d_weights: number[]
conv2d_bias: number[]
batch_normalization_a: number[]
batch_normalization_b: number[]
dense_weights: number[]
dense_bias: number[]
}
1 change: 1 addition & 0 deletions packages/arweave-service/src/resource/abi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"status":"1","message":"OK-Missing/Invalid API Key, rate limit of 1/5sec applied","result":"[{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"id\",\"type\":\"uint256\"}],\"name\":\"buyWeight\",\"outputs\":[],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"user\",\"type\":\"address\"}],\"name\":\"getList\",\"outputs\":[{\"internalType\":\"string[]\",\"name\":\"\",\"type\":\"string[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"totalWeight\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"name\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"url\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"uploadType\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"price\",\"type\":\"uint256\"}],\"name\":\"uploadWeight\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"userWeight\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"weightList\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"name\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"url\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"uploadType\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"price\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"}]"}
Loading

0 comments on commit f860f6e

Please sign in to comment.