forked from keep-starknet-strange/shinigami
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backend compiler and Frontend Setup (keep-starknet-strange#177)
<!-- enter the gh issue after hash --> - [ ] issue # - [ ] follows contribution [guide](https://github.com/keep-starknet-strange/shinigami/blob/main/CONTRIBUTING.md) - [ ] code change includes tests <!-- PR description below --> Created a simple nodejs script with Express.js to collect two arguments via post requests Also I setup the frontend to use ```swr``` to fetch mock data and simulate how clicking run script will work Made Pub key to be the default editor when editor is not split and sig key to be the top editor when split --------- Co-authored-by: Brandon Roberts <[email protected]>
- Loading branch information
1 parent
fe1c0d6
commit 1833214
Showing
11 changed files
with
2,145 additions
and
2,414 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
FROM node:20.5.0 | ||
|
||
SHELL ["bash", "-c"] | ||
RUN curl https://get.starkli.sh | sh && \ | ||
source $HOME/.starkli/env && \ | ||
starkliup && \ | ||
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.14.1 && \ | ||
. "$HOME/.asdf/asdf.sh" && \ | ||
. "$HOME/.asdf/completions/asdf.bash" && \ | ||
asdf plugin add scarb && \ | ||
asdf install scarb latest && \ | ||
asdf global scarb latest | ||
|
||
WORKDIR /backend | ||
|
||
COPY ./index.js ./package.json ./ | ||
|
||
RUN npm i | ||
|
||
EXPOSE 3000 | ||
|
||
CMD ["node", "index.js"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
services: | ||
web: | ||
build: . | ||
ports: | ||
- "8000:3000" | ||
develop: | ||
watch: | ||
- action: sync | ||
path: . | ||
target: /backend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
const express = require('express'); | ||
const { exec } = require('child_process'); | ||
const app = express(); | ||
const cors = require('cors') | ||
|
||
const MAX_SIZE = 350000; // Max script size is 10000 bytes, longest named opcode is ~25 chars, so 25 * 10000 = 250000 + extra allowance | ||
|
||
function runShellCommand(command, callback) { | ||
exec(command, (error, stdout, stderr) => { | ||
if (error) { | ||
callback(`Error: ${error.message}`); | ||
return; | ||
} | ||
if (stderr) { | ||
callback(stderr); | ||
return; | ||
} | ||
callback(stdout); | ||
}); | ||
} | ||
|
||
function extractStack(output) { | ||
const match = output.match(/\[.*\]/); | ||
return match ? match[0] : 'No message found'; | ||
} | ||
|
||
app.use(cors()); | ||
app.use(express.json()); | ||
|
||
app.post('/run-script', (req, res) => { | ||
const { pub_key, sig } = req.body; | ||
if (!pub_key) { | ||
return res.status(400).send('Missing public key parameter'); | ||
} | ||
if (pub_key.length > MAX_SIZE || sig.length > MAX_SIZE) { | ||
//for a more detailed error message | ||
if (pub_key.length > MAX_SIZE) { | ||
return res.status(400).send('Script Public Key exceeds maximum allowed size'); | ||
} | ||
if (sig.length > MAX_SIZE) { | ||
return res.status(400).send('Script Signature exceeds maximum allowed size'); | ||
} | ||
} | ||
const scriptPath = '../tests/text_to_byte_array.sh'; | ||
const sigCommand = `bash ${scriptPath} "${sig}"`; | ||
const pubCommand = `bash ${scriptPath} "${pub_key}"`; | ||
runShellCommand(sigCommand, (sigOutput) => { | ||
runShellCommand(pubCommand, (pubOutput) => { | ||
const modifiedSigOutput = sigOutput.trim().slice(1, -1); | ||
const modifiedPubOutput = pubOutput.trim().slice(1, -1); | ||
const combinedOutput = `[${modifiedSigOutput},${modifiedPubOutput}]`; | ||
const cairoCommand = `scarb cairo-run ${combinedOutput} --no-build`; | ||
runShellCommand(cairoCommand, (finalOutput) => { | ||
const message = extractStack(finalOutput); | ||
res.json({ message }); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
const PORT = process.env.PORT || 3000; | ||
app.listen(PORT, () => { | ||
console.log(`Server is running on port ${PORT}`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "backend", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"scripts": { | ||
"start": "node index.js" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"description": "", | ||
"devDependencies": { | ||
"@types/node": "^22.5.0" | ||
}, | ||
"dependencies": { | ||
"cors": "^2.8.5", | ||
"express": "^4.19.2" | ||
} | ||
} |
Empty file.
Oops, something went wrong.