From e3556fcc00227000986b6117c58ef404849bdf6e Mon Sep 17 00:00:00 2001
From: Sandwich <299465+dskvr@users.noreply.github.com>
Date: Sun, 15 Sep 2024 15:05:44 +0200
Subject: [PATCH] inline wasm/workers for seamless integration
---
.gitignore | 3 +-
README.md | 106 +-
build-worker.js | 0
build.js | 137 +
demo/.eslintrc.json | 5 +
demo/.gitignore | 4 +
demo/README.md | 107 +
demo/package.json | 36 +
demo/public/favicon.png | Bin 0 -> 3127 bytes
demo/public/global.css | 63 +
demo/public/index.html | 18 +
demo/public/lib/img/anon.svg | 16 +
demo/rollup.config.js | 92 +
demo/scripts/setupTypeScript.js | 134 +
demo/src/App.svelte | 365 +++
demo/src/lib/publish.ts | 41 +
demo/src/lib/stores/content-state.js | 7 +
demo/src/lib/stores/index.js | 4 +
demo/src/lib/stores/mining-state.js | 10 +
demo/src/lib/stores/relay-settings.js | 7 +
demo/src/lib/stores/user.js | 7 +
demo/src/main.js | 7 +
demo/vite.config.js | 19 +
demo/yarn.lock | 3696 ++++++++++++++++++++++
handleWasmUrl.cjs | 19 +
package.json | 67 +-
rollup.config.mjs | 63 +
scripts/build_notemine.sh | 19 -
scripts/build_notemine_wasm.sh | 47 -
src/global.d.ts | 44 +-
src/index.test.ts | 13 +-
src/index.ts | 265 +-
src/mine.worker.ts | 150 +-
src/worker-types.d.ts | 6 +
tsconfig.json | 23 +-
webpack.config.js | 43 -
yarn.lock | 4063 +++++--------------------
37 files changed, 5971 insertions(+), 3735 deletions(-)
create mode 100644 build-worker.js
create mode 100644 build.js
create mode 100644 demo/.eslintrc.json
create mode 100644 demo/.gitignore
create mode 100644 demo/README.md
create mode 100644 demo/package.json
create mode 100644 demo/public/favicon.png
create mode 100644 demo/public/global.css
create mode 100644 demo/public/index.html
create mode 100644 demo/public/lib/img/anon.svg
create mode 100644 demo/rollup.config.js
create mode 100644 demo/scripts/setupTypeScript.js
create mode 100644 demo/src/App.svelte
create mode 100644 demo/src/lib/publish.ts
create mode 100644 demo/src/lib/stores/content-state.js
create mode 100644 demo/src/lib/stores/index.js
create mode 100644 demo/src/lib/stores/mining-state.js
create mode 100644 demo/src/lib/stores/relay-settings.js
create mode 100644 demo/src/lib/stores/user.js
create mode 100644 demo/src/main.js
create mode 100644 demo/vite.config.js
create mode 100644 demo/yarn.lock
create mode 100644 handleWasmUrl.cjs
create mode 100644 rollup.config.mjs
delete mode 100755 scripts/build_notemine.sh
delete mode 100755 scripts/build_notemine_wasm.sh
create mode 100644 src/worker-types.d.ts
delete mode 100644 webpack.config.js
diff --git a/.gitignore b/.gitignore
index 31b5e37..e931de8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,4 +2,5 @@
tmp/
dist/
node_modules
-rust
\ No newline at end of file
+rust
+src/wasm
\ No newline at end of file
diff --git a/README.md b/README.md
index dec820d..0a0cc2b 100644
--- a/README.md
+++ b/README.md
@@ -1,11 +1,10 @@
-# notemine js
+# note⛏️ (js)
-![build](https://img.shields.io/npm/v/notemine)
-![build](https://github.com/github/docs/actions/workflows/main.yml/badge.svg)
-![test](https://github.com/github/docs/actions/workflows/main.yml/badge.svg)
-![coverage](https://github.com/github/docs/actions/workflows/main.yml/badge.svg)
+[![npm](https://img.shields.io/npm/v/notemine)]( https://www.npmjs.com/package/notemine )
+[![build](https://github.com/sandwichfarm/notemine-js/actions/workflows/build.yaml/badge.svg)]( https://github.com/sandwichfarm/notemine-js/actions/workflows/build.yaml )
+[![test](https://github.com/sandwichfarm/notemine-js/actions/workflows/test.yaml/badge.svg)]( https://github.com/sandwichfarm/notemine-js/actions/workflows/test.yaml )
-a module for implementing [notemine](https://github.com/sandwichfarm/notemine) wasm nostr event miner in modern web applications with observables.
+`notemine` is a typescript module that wraps [notemine](https://github.com/sandwichfarm/notemine) `wasm-bindgen` interfaces. More convenient and has added observables for more consistent use throughout modern web stacks.
## install
package name: `notemine`
@@ -42,12 +41,12 @@ _untested_
const tags = [ "#t", "introduction"]
const pubkey = "e771af0b05c8e95fcdf6feb3500544d2fb1ccd384788e9f490bb3ee28e8ed66f"
- //set options for miner
+ //set options for notemine
const difficulty = 21
const numberOfWorkers = 7
- const noteminer = new Noteminer({
+ const notemine = new Notemine({
content,
tags,
difficulty,
@@ -55,18 +54,18 @@ _untested_
})
//you can also set content, tags and pubkey via assessors after initialization.
- noteminer.pubkey = pubkey
+ notemine.pubkey = pubkey
- //start miner
- noteminer.mine()
+ //start notemine
+ notemine.mine()
```
-Updates to noteminer can be accessed via observables.
+Updates to notemine can be accessed via observables.
```
-noteminer.progress$
-noteminer.error$
-noteminer.progress$
-noteminer.progress$
+notemine.progress$
+notemine.error$
+notemine.cancelled$
+notemine.success$
```
@@ -78,29 +77,40 @@ noteminer.progress$
@@ -110,6 +120,12 @@ noteminer.progress$
Miner #{miner.workerId}: {miner.hashRate}kH/s [Best PoW: ${miner.bestPowData}]
{/each}
+{#if($success !== null)}
+
+ {$success.event}
+
+{/if}
+
```
@@ -121,21 +137,21 @@ noteminer.progress$
```reactjs
import React, { useEffect } from 'react';
- import { NostrMiner } from 'nostr-miner';
+ import { Notemine } from 'notemine';
const MyComponent = () => {
- const miner = new NostrMiner({ content: 'Hello, Nostr!' });
+ const notemine = new Notemine({ content: 'Hello, Nostr!' });
useEffect(() => {
- const subscription = miner.progress$.subscribe(progress => {
- // Update progress bar or display miner's progress
+ const subscription = notemine.progress$.subscribe(progress => {
+ // Update progress bar or display notemine's progress
});
- miner.mine();
+ notemine.mine();
return () => {
subscription.unsubscribe();
- miner.cancel();
+ notemine.cancel();
};
}, []);
@@ -161,23 +177,23 @@ noteminer.progress$
+
+
+
+
+