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

Refine deployment #11

Merged
merged 3 commits into from
Aug 9, 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
26 changes: 23 additions & 3 deletions .github/workflows/static.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
name: bip322.rs Website
name: bip322.rs

on:
push:
branches: ["master"]

workflow_dispatch:

permissions:
contents: read
pages: write
Expand All @@ -24,12 +22,34 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: wasm32-unknown-unknown

- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

- name: Build WASM
run: |
cd www
wasm-pack build \
--target web \
--out-name bip322 \
www
cp www/pkg/bip322.js www/pkg/bip322_bg.wasm www

- name: Setup Pages
uses: actions/configure-pages@v5

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: './www'

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4

8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ For MacOs:
```
brew install llvm
cargo install wasm-pack
rustup toolchain install nightly
rustup target add wasm32-unknown-unknown --toolchain nightly
rustup default nightly-aarch64-apple-darwin
rustup target add wasm32-unknown-unknown
cd www
AR=/opt/homebrew/opt/llvm/bin/llvm-ar CC=/opt/homebrew/opt/llvm/bin/clang wasm-pack build --target web --no-typescript
AR=/opt/homebrew/opt/llvm/bin/llvm-ar \
CC=/opt/homebrew/opt/llvm/bin/clang \
wasm-pack build --target web
```
12 changes: 12 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ outdated:
coverage:
cargo llvm-cov

wasm:
AR=/opt/homebrew/opt/llvm/bin/llvm-ar \
CC=/opt/homebrew/opt/llvm/bin/clang \
wasm-pack build \
--target web \
--out-name bip322 \
www
cp www/pkg/bip322.js www/pkg/bip322_bg.wasm www

serve: wasm
python3 -m http.server -b 127.0.0.1 -d www 8080

prepare-release revision='master':
#!/usr/bin/env bash
set -euxo pipefail
Expand Down
69 changes: 1 addition & 68 deletions www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,74 +24,7 @@
<a href=https://github.com/raphjaph/bip322>github</a>
<a href=https://crates.io/crates/bip322>crate</a>
</nav>

<script type="module">
import init, {verify} from './www.js';

let wasmInitialized = false;

async function initializeWasm() {
if (!wasmInitialized) {
await init();
console.log('WASM module loaded');
wasmInitialized = true;
}
}

async function runVerification(event) {
event.preventDefault();
await initializeWasm();

const address = document.getElementById('address').value;
const message = document.getElementById('message').value;
const signature = document.getElementById('signature').value;

const result = verify(address, message, signature);
console.log(result);

document.getElementById('verify-form').style.display = 'none';
const resultElement = document.getElementById('verify');
resultElement.textContent = result;
resultElement.style.display = 'block';
}

function showForm() {
document.getElementById('navbar').style.display = 'none';
document.getElementById('bip').classList.add('hidden');
document.getElementById('verify-form').classList.add('visible');
}

function handleFocus(event) {
if (event.target.value === event.target.getAttribute('data-default')) {
event.target.value = '';
}
}

function handleBlur(event) {
if (event.target.value === '') {
event.target.value = event.target.getAttribute('data-default');
}
}

function handleKeyPress(event) {
if (event.key === 'Enter') {
event.preventDefault();
runVerification(event);
}
}

document.getElementById('bip').addEventListener('click', showForm);
document.getElementById('verify-form').addEventListener('submit', runVerification);

const inputs = document.querySelectorAll('#verify-form input');
inputs.forEach(input => {
const defaultValue = input.value;
input.setAttribute('data-default', defaultValue);
input.addEventListener('focus', handleFocus);
input.addEventListener('blur', handleBlur);
input.addEventListener('keypress', handleKeyPress);
});
</script>
<script type="module" src="index.js"></script>
</body>

</html>
65 changes: 65 additions & 0 deletions www/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import init, { verify } from './bip322.js';

let wasmInitialized = false;

async function initializeWasm() {
if (!wasmInitialized) {
await init();
console.log('WASM module loaded');
wasmInitialized = true;
}
}

async function runVerification(event) {
event.preventDefault();
await initializeWasm();

const address = document.getElementById('address').value;
const message = document.getElementById('message').value;
const signature = document.getElementById('signature').value;

const result = verify(address, message, signature);
console.log(result);

document.getElementById('verify-form').style.display = 'none';
const resultElement = document.getElementById('verify');
resultElement.textContent = result;
resultElement.style.display = 'block';
}

function showForm() {
document.getElementById('navbar').style.display = 'none';
document.getElementById('bip').classList.add('hidden');
document.getElementById('verify-form').classList.add('visible');
}

function handleFocus(event) {
if (event.target.value === event.target.getAttribute('data-default')) {
event.target.value = '';
}
}

function handleBlur(event) {
if (event.target.value === '') {
event.target.value = event.target.getAttribute('data-default');
}
}

function handleKeyPress(event) {
if (event.key === 'Enter') {
event.preventDefault();
runVerification(event);
}
}

document.getElementById('bip').addEventListener('click', showForm);
document.getElementById('verify-form').addEventListener('submit', runVerification);

const inputs = document.querySelectorAll('#verify-form input');
inputs.forEach(input => {
const defaultValue = input.value;
input.setAttribute('data-default', defaultValue);
input.addEventListener('focus', handleFocus);
input.addEventListener('blur', handleBlur);
input.addEventListener('keypress', handleKeyPress);
});
10 changes: 0 additions & 10 deletions www/justfile

This file was deleted.

Loading
Loading