From 173d8b15d0df90d563899162627424ad0e1e337f Mon Sep 17 00:00:00 2001 From: Yuki Kishimoto Date: Wed, 30 Oct 2024 08:42:38 +0100 Subject: [PATCH] js: merge `nostr-js` into `nostr-sdk-js` Signed-off-by: Yuki Kishimoto --- CHANGELOG.md | 1 + Cargo.lock | 13 +--- Cargo.toml | 1 - README.md | 2 +- bindings/README.md | 11 ++- bindings/nostr-js/.cargo/config.toml | 10 --- bindings/nostr-js/.gitignore | 7 -- bindings/nostr-js/.npmignore | 12 --- bindings/nostr-js/BUILD.md | 22 ------ bindings/nostr-js/Cargo.toml | 18 ----- bindings/nostr-js/README.md | 60 --------------- bindings/nostr-js/build.rs | 17 ----- bindings/nostr-js/examples/nip07.js | 25 ------ bindings/nostr-js/justfile | 16 ---- bindings/nostr-js/package.json | 51 ------------- bindings/nostr-js/scripts/build.sh | 42 ---------- bindings/nostr-js/scripts/epilogue.d.ts | 10 --- bindings/nostr-js/scripts/epilogue.js | 76 ------------------- bindings/nostr-js/src/lib.rs | 54 ------------- bindings/nostr-js/tsconfig.json | 9 --- bindings/nostr-sdk-js/.npmignore | 4 +- bindings/nostr-sdk-js/Cargo.toml | 4 +- bindings/nostr-sdk-js/build.rs | 9 +++ .../examples/event-builder.js | 0 .../examples/filter.js | 0 .../examples/metadata.js | 0 .../examples/nip05.js | 0 bindings/nostr-sdk-js/examples/nip07.js | 23 +++++- .../examples/nip19.js | 0 .../examples/nip26.js | 0 bindings/nostr-sdk-js/justfile | 14 ++-- bindings/nostr-sdk-js/package.json | 12 ++- bindings/nostr-sdk-js/scripts/build.sh | 9 ++- bindings/nostr-sdk-js/scripts/epilogue.js | 16 +++- bindings/nostr-sdk-js/src/client/mod.rs | 12 +-- .../nostr-sdk-js/src/client/signer/mod.rs | 10 +-- .../nostr-sdk-js/src/client/signer/nip46.rs | 8 +- bindings/nostr-sdk-js/src/client/zapper.rs | 8 +- bindings/nostr-sdk-js/src/database/events.rs | 3 +- bindings/nostr-sdk-js/src/database/mod.rs | 10 +-- .../{nostr-js => nostr-sdk-js}/src/error.rs | 0 bindings/nostr-sdk-js/src/lib.rs | 39 +++++++++- bindings/nostr-sdk-js/src/logger.rs | 5 +- bindings/nostr-sdk-js/src/nwc/mod.rs | 12 +-- bindings/nostr-sdk-js/src/pool/mod.rs | 8 +- bindings/nostr-sdk-js/src/pool/result.rs | 2 +- bindings/nostr-sdk-js/src/profile.rs | 5 +- .../src/protocol}/event/builder.rs | 28 +++---- .../src/protocol}/event/id.rs | 6 +- .../src/protocol}/event/kind.rs | 2 +- .../src/protocol}/event/mod.rs | 6 +- .../src/protocol}/event/tag/list.rs | 10 +-- .../src/protocol}/event/tag/mod.rs | 18 ++--- .../src/protocol}/event/unsigned.rs | 10 +-- .../src/protocol}/key/mod.rs | 2 +- .../src/protocol}/key/public_key.rs | 2 +- .../src/protocol}/key/secret_key.rs | 4 +- .../src/protocol}/message/client.rs | 6 +- .../src/protocol}/message/mod.rs | 0 .../src/protocol}/message/relay.rs | 4 +- bindings/nostr-sdk-js/src/protocol/mod.rs | 10 +++ .../src/protocol}/nips/mod.rs | 0 .../src/protocol}/nips/nip01.rs | 6 +- .../src/protocol}/nips/nip04.rs | 4 +- .../src/protocol}/nips/nip05.rs | 4 +- .../src/protocol}/nips/nip07.rs | 7 +- .../src/protocol}/nips/nip11.rs | 2 +- .../src/protocol}/nips/nip15.rs | 2 +- .../src/protocol}/nips/nip19.rs | 6 +- .../src/protocol}/nips/nip26.rs | 10 +-- .../src/protocol}/nips/nip34.rs | 6 +- .../src/protocol}/nips/nip44.rs | 4 +- .../src/protocol}/nips/nip46.rs | 2 +- .../src/protocol}/nips/nip47.rs | 6 +- .../src/protocol}/nips/nip49.rs | 6 +- .../src/protocol}/nips/nip51.rs | 11 +-- .../src/protocol}/nips/nip53.rs | 7 +- .../src/protocol}/nips/nip56.rs | 2 +- .../src/protocol}/nips/nip57.rs | 6 +- .../src/protocol}/nips/nip59.rs | 6 +- .../src/protocol}/nips/nip65.rs | 4 +- .../src/protocol}/nips/nip90.rs | 4 +- .../src/protocol}/nips/nip94.rs | 7 +- .../src/protocol}/nips/nip98.rs | 2 +- .../src/protocol}/types/contact.rs | 4 +- .../src/protocol}/types/filter.rs | 10 +-- .../src/protocol}/types/image.rs | 2 +- .../src/protocol}/types/metadata.rs | 2 +- .../src/protocol}/types/mod.rs | 0 .../src/protocol}/types/time.rs | 2 +- .../src => nostr-sdk-js/src/protocol}/util.rs | 4 +- bindings/nostr-sdk-js/src/relay/filtering.rs | 5 +- bindings/nostr-sdk-js/src/relay/mod.rs | 10 +-- contrib/scripts/check-bindings.sh | 3 +- 94 files changed, 288 insertions(+), 646 deletions(-) delete mode 100644 bindings/nostr-js/.cargo/config.toml delete mode 100644 bindings/nostr-js/.gitignore delete mode 100644 bindings/nostr-js/.npmignore delete mode 100644 bindings/nostr-js/BUILD.md delete mode 100644 bindings/nostr-js/Cargo.toml delete mode 100644 bindings/nostr-js/README.md delete mode 100644 bindings/nostr-js/build.rs delete mode 100644 bindings/nostr-js/examples/nip07.js delete mode 100644 bindings/nostr-js/justfile delete mode 100644 bindings/nostr-js/package.json delete mode 100755 bindings/nostr-js/scripts/build.sh delete mode 100644 bindings/nostr-js/scripts/epilogue.d.ts delete mode 100644 bindings/nostr-js/scripts/epilogue.js delete mode 100644 bindings/nostr-js/src/lib.rs delete mode 100644 bindings/nostr-js/tsconfig.json rename bindings/{nostr-js => nostr-sdk-js}/examples/event-builder.js (100%) rename bindings/{nostr-js => nostr-sdk-js}/examples/filter.js (100%) rename bindings/{nostr-js => nostr-sdk-js}/examples/metadata.js (100%) rename bindings/{nostr-js => nostr-sdk-js}/examples/nip05.js (100%) rename bindings/{nostr-js => nostr-sdk-js}/examples/nip19.js (100%) rename bindings/{nostr-js => nostr-sdk-js}/examples/nip26.js (100%) rename bindings/{nostr-js => nostr-sdk-js}/src/error.rs (100%) rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/event/builder.rs (97%) rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/event/id.rs (96%) rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/event/kind.rs (99%) rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/event/mod.rs (97%) rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/event/tag/list.rs (94%) rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/event/tag/mod.rs (94%) rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/event/unsigned.rs (92%) rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/key/mod.rs (98%) rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/key/public_key.rs (98%) rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/key/secret_key.rs (95%) rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/message/client.rs (95%) rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/message/mod.rs (100%) rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/message/relay.rs (96%) create mode 100644 bindings/nostr-sdk-js/src/protocol/mod.rs rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/nips/mod.rs (100%) rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/nips/nip01.rs (95%) rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/nips/nip04.rs (90%) rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/nips/nip05.rs (96%) rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/nips/nip07.rs (94%) rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/nips/nip11.rs (98%) rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/nips/nip15.rs (98%) rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/nips/nip19.rs (96%) rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/nips/nip26.rs (92%) rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/nips/nip34.rs (96%) rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/nips/nip44.rs (92%) rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/nips/nip46.rs (98%) rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/nips/nip47.rs (99%) rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/nips/nip49.rs (96%) rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/nips/nip51.rs (95%) rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/nips/nip53.rs (96%) rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/nips/nip56.rs (97%) rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/nips/nip57.rs (97%) rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/nips/nip59.rs (90%) rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/nips/nip65.rs (95%) rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/nips/nip90.rs (97%) rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/nips/nip94.rs (94%) rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/nips/nip98.rs (98%) rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/types/contact.rs (95%) rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/types/filter.rs (98%) rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/types/image.rs (98%) rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/types/metadata.rs (99%) rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/types/mod.rs (100%) rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/types/time.rs (97%) rename bindings/{nostr-js/src => nostr-sdk-js/src/protocol}/util.rs (88%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 424132a8a..2a2086934 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -70,6 +70,7 @@ * signer: bootstrap NIP46 signer on demand ([Yuki Kishimoto]) * bindings(nostr): adj. `tag` module ([Yuki Kishimoto]) * js: change `opt-level` to `z` ([Yuki Kishimoto]) +* js: merge `nostr-js` into `nostr-sdk-js` ([Yuki Kishimoto]) ### Added diff --git a/Cargo.lock b/Cargo.lock index 336478e07..35f517e9b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2834,17 +2834,6 @@ dependencies = [ "wasm-bindgen-test", ] -[[package]] -name = "nostr-js" -version = "0.1.0" -dependencies = [ - "console_error_panic_hook", - "js-sys", - "nostr", - "wasm-bindgen", - "wasm-bindgen-futures", -] - [[package]] name = "nostr-lmdb" version = "0.35.0" @@ -2957,8 +2946,8 @@ dependencies = [ name = "nostr-sdk-js" version = "0.1.0" dependencies = [ + "console_error_panic_hook", "js-sys", - "nostr-js", "nostr-sdk", "tracing", "tracing-subscriber", diff --git a/Cargo.toml b/Cargo.toml index 59c6b8900..3ca2d10d1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,6 @@ [workspace] members = [ "bindings/nostr-ffi", - "bindings/nostr-js", "bindings/nostr-sdk-ffi", "bindings/nostr-sdk-js", "bindings/uniffi-bindgen", diff --git a/README.md b/README.md index 7235e7d0c..09b70e090 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ Learn more about `rust-nostr` at . * Python: https://pypi.org/project/nostr-protocol * Kotlin: https://central.sonatype.com/artifact/org.rust-nostr/nostr * Swift: https://github.com/rust-nostr/nostr-swift - * JavaScript: https://www.npmjs.com/package/@rust-nostr/nostr + * JavaScript: https://www.npmjs.com/package/@rust-nostr/nostr-sdk * **nostr-sdk**: * Rust: https://crates.io/crates/nostr-sdk * Python: https://pypi.org/project/nostr-sdk diff --git a/bindings/README.md b/bindings/README.md index acf6a48e4..0540eaca0 100644 --- a/bindings/README.md +++ b/bindings/README.md @@ -1,11 +1,10 @@ -# Rust Nostr bindings +# rust-nostr bindings - UniFFI (Python, Kotlin, Swift): - * [nostr-ffi](./nostr-ffi/): UniFFI bindings of the [nostr] crate - * [nostr-sdk-ffi](./nostr-sdk-ffi/): UniFFI bindings of the [nostr-sdk] crate + * [nostr-ffi](./nostr-ffi): UniFFI bindings of the [nostr] crate + * [nostr-sdk-ffi](./nostr-sdk-ffi): UniFFI bindings of the [nostr-sdk] crate - JavaScript: - * [nostr-js](./nostr-js/): JavaScript bindings of the [nostr] crate - * [nostr-sdk-js](./nostr-sdk-js/): JavaScript bindings of the [nostr-sdk] crate + * [nostr-sdk-js](./nostr-sdk-js): JavaScript bindings of the [nostr] and [nostr-sdk] crates [nostr]: ../crates/nostr/ -[nostr-sdk]: ../crates/nostr-sdk/ \ No newline at end of file +[nostr-sdk]: ../crates/nostr-sdk/ diff --git a/bindings/nostr-js/.cargo/config.toml b/bindings/nostr-js/.cargo/config.toml deleted file mode 100644 index 3a85386f9..000000000 --- a/bindings/nostr-js/.cargo/config.toml +++ /dev/null @@ -1,10 +0,0 @@ -[build] -target = "wasm32-unknown-unknown" - -[profile.release] -opt-level = "s" -lto = true -codegen-units = 1 -panic = "abort" -strip = true -debug = false \ No newline at end of file diff --git a/bindings/nostr-js/.gitignore b/bindings/nostr-js/.gitignore deleted file mode 100644 index bed4e246e..000000000 --- a/bindings/nostr-js/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -/target -**/*.rs.bk -Cargo.lock -bin/ -pkg/ -wasm-pack.log -*.tgz diff --git a/bindings/nostr-js/.npmignore b/bindings/nostr-js/.npmignore deleted file mode 100644 index 32ba3b598..000000000 --- a/bindings/nostr-js/.npmignore +++ /dev/null @@ -1,12 +0,0 @@ -.cargo/ -target/ -src/ -scripts/ -examples/ -pkg/package.json -pkg/*.md -pkg/*.wasm -.gitignore -Cargo.toml -Cargo.lock -*.tgz \ No newline at end of file diff --git a/bindings/nostr-js/BUILD.md b/bindings/nostr-js/BUILD.md deleted file mode 100644 index 416e96717..000000000 --- a/bindings/nostr-js/BUILD.md +++ /dev/null @@ -1,22 +0,0 @@ -# Build - -## Prerequisites - -* Rust: https://www.rust-lang.org/tools/install -* Just: https://just.systems/man/en/ (install with `cargo install just`) - -## First build - -On first usage you will need to run: - -```bash -just init -``` - -## Build - -```bash -just pack -``` - -You'll find a `tgz` archive in this folder. diff --git a/bindings/nostr-js/Cargo.toml b/bindings/nostr-js/Cargo.toml deleted file mode 100644 index 28f537fbc..000000000 --- a/bindings/nostr-js/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -name = "nostr-js" -version = "0.1.0" -edition = "2021" -publish = false - -[lib] -crate-type = ["lib", "cdylib"] - -[dependencies] -console_error_panic_hook = "0.1" -js-sys.workspace = true -nostr = { workspace = true, features = ["std", "all-nips"] } -wasm-bindgen = { workspace = true, features = ["std"] } -wasm-bindgen-futures.workspace = true - -[package.metadata.wasm-pack.profile.release] -wasm-opt = true diff --git a/bindings/nostr-js/README.md b/bindings/nostr-js/README.md deleted file mode 100644 index e3c41aad9..000000000 --- a/bindings/nostr-js/README.md +++ /dev/null @@ -1,60 +0,0 @@ -# Nostr - -## Description - -JavaScript bindings of [nostr](https://github.com/rust-nostr/nostr) library. - -If you're writing a typical Nostr client or bot, you may be interested in [nostr-sdk](https://www.npmjs.com/package/@rust-nostr/nostr-sdk). - -This library **should** work on every JavaScript environment (nodejs, web, react native, ...). - -## Getting started - -```sh -npm i @rust-nostr/nostr -``` - -```javascript -const { Keys, loadWasmAsync } = require("@rust-nostr/nostr"); - -async function main() { - // Load WASM - // if you are in a non async context, use loadWasmSync() - await loadWasmAsync(); - - // Generate random keys - let keys = Keys.generate(); - - // Hex keys - console.log("Public key (hex): ", keys.publicKey.toHex()); - console.log("Secret key (hex): ", keys.secretKey.toHex()); - - // Bech32 keys - console.log("Public key (bech32): ", keys.publicKey.toBech32()); - console.log("Secret key (bech32): ", keys.secretKey.toBech32()); -} - -main(); -``` - -More examples can be found in the [examples](https://github.com/rust-nostr/nostr/tree/master/bindings/nostr-js/examples) directory. - -## Supported NIPs - -Look at (the Js library could be out of sync with the supported NIPs in the `nostr` rust crate) - -## Book - -Learn more about `rust-nostr` at . - -## State - -**This library is in an ALPHA state**, things that are implemented generally work but the API will change in breaking ways. - -## Donations - -`rust-nostr` is free and open-source. This means we do not earn any revenue by selling it. Instead, we rely on your financial support. If you actively use any of the `rust-nostr` libs/software/services, then please [donate](https://rust-nostr.org/donate). - -## License - -This project is distributed under the MIT software license - see the [LICENSE](https://github.com/rust-nostr/nostr/blob/master/LICENSE) file for details diff --git a/bindings/nostr-js/build.rs b/bindings/nostr-js/build.rs deleted file mode 100644 index e9ebf2b77..000000000 --- a/bindings/nostr-js/build.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) 2022-2023 Yuki Kishimoto -// Copyright (c) 2023-2024 Rust Nostr Developers -// Distributed under the MIT software license - -use std::process::Command; - -fn main() { - if let Ok(output) = Command::new("git").args(["rev-parse", "HEAD"]).output() { - if let Ok(git_hash) = String::from_utf8(output.stdout) { - println!("cargo:rerun-if-changed={git_hash}"); - println!("cargo:rustc-env=GIT_HASH={git_hash}"); - } - } - - // 0x1E84800 bytes = 32MiB - println!("cargo:rustc-link-arg=-zstack-size=0x1E84800"); -} diff --git a/bindings/nostr-js/examples/nip07.js b/bindings/nostr-js/examples/nip07.js deleted file mode 100644 index 7eb896d41..000000000 --- a/bindings/nostr-js/examples/nip07.js +++ /dev/null @@ -1,25 +0,0 @@ -const { loadWasmAsync, EventBuilder, Nip07Signer } = require("../"); - -// NOTE: this code work only on browser! - -async function main() { - await loadWasmAsync(); - - try { - let signer = new Nip07Signer(); - - let public_key = await signer.getPublicKey(); - console.log(public_key.toBech32()) - - let ciphertext = await signer.nip04Encrypt(public_key, "Test"); - console.log("NIP04: " + ciphertext); - - let unsigned = EventBuilder.textNote("Test", []).toUnsignedEvent(public_key); - let event = await signer.signEvent(unsigned); - console.log(event.asJson()); - } catch (error) { - console.log(error) - } -} - -main(); \ No newline at end of file diff --git a/bindings/nostr-js/justfile b/bindings/nostr-js/justfile deleted file mode 100644 index cfbe48a6b..000000000 --- a/bindings/nostr-js/justfile +++ /dev/null @@ -1,16 +0,0 @@ -set windows-shell := ["powershell.exe", "-NoLogo", "-Command"] - -init: - cargo install wasm-pack - -publish: pack - npm publish --access public - -pack: - rm -rf ./pkg - npm run package - -twiggy: - cargo install twiggy --version 0.7.0 - npm run build:dev - twiggy top pkg/nostr_js_bg.wasm diff --git a/bindings/nostr-js/package.json b/bindings/nostr-js/package.json deleted file mode 100644 index ad1c24d94..000000000 --- a/bindings/nostr-js/package.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "name": "@rust-nostr/nostr", - "version": "0.35.0", - "description": "Nostr protocol implementation", - "keywords": [ - "nostr", - "protocol", - "rust", - "bindings", - "javascript" - ], - "license": "MIT", - "homepage": "https://github.com/rust-nostr/nostr", - "repository": { - "type": "git", - "url": "git+https://github.com/rust-nostr/nostr.git" - }, - "bugs": { - "url": "https://github.com/rust-nostr/nostr/issues" - }, - "author": { - "name": "Yuki Kishimoto", - "email": "yukikishimoto@protonmail.com", - "url": "https://github.com/yukibtc" - }, - "funding": [ - { - "type": "individual", - "url": "https://rust-nostr.org/donate" - } - ], - "main": "pkg/nostr_js.js", - "types": "pkg/nostr_js.d.ts", - "files": [ - "pkg/nostr_js_bg.wasm.js", - "pkg/nostr_js_bg.wasm.d.ts", - "pkg/nostr_js.js", - "pkg/nostr_js.d.ts" - ], - "devDependencies": { - "wasm-pack": "^0.10.2" - }, - "engines": { - "node": ">= 10" - }, - "scripts": { - "build": "WASM_PACK_ARGS=--release ./scripts/build.sh", - "build:dev": "WASM_PACK_ARGS=--dev ./scripts/build.sh", - "package": "npm run build && npm pack" - } -} diff --git a/bindings/nostr-js/scripts/build.sh b/bindings/nostr-js/scripts/build.sh deleted file mode 100755 index da00d0740..000000000 --- a/bindings/nostr-js/scripts/build.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash -# -# Build the JavaScript modules -# -# This script is really a workaround for https://github.com/rustwasm/wasm-pack/issues/1074. -# -# Currently, the only reliable way to load WebAssembly in all the JS -# environments we want to target (web-via-webpack, web-via-browserify, jest) -# seems to be to pack the WASM into base64, and then unpack it and instantiate -# it at runtime. -# -# Hopefully one day, https://github.com/rustwasm/wasm-pack/issues/1074 will be -# fixed and this will be unnecessary. - -set -exuo pipefail - -cd "$(dirname "$0")/.." - -wasm-pack build --target nodejs --no-pack --scope rust-nostr --weak-refs --reference-types --out-dir pkg "${WASM_PACK_ARGS[@]}" - -# Shrinking .wasm Size -wc -c pkg/nostr_js_bg.wasm - -# Convert the Wasm into a JS file that exports the base64'ed Wasm. -{ - printf 'module.exports = `' - base64 < pkg/nostr_js_bg.wasm - printf '`;' -} > pkg/nostr_js_bg.wasm.js - -# In the JavaScript: -# 1. Strip out the lines that load the WASM, and our new epilogue. -# 2. Remove the imports of `TextDecoder` and `TextEncoder`. We rely on the global defaults. -{ - sed -e '/Text..coder.*= require(.util.)/d' \ - -e '/^const path = /,$d' pkg/nostr_js.js - cat scripts/epilogue.js -} > pkg/nostr_js.js.new -mv pkg/nostr_js.js.new pkg/nostr_js.js - -# also extend the typescript -cat scripts/epilogue.d.ts >> pkg/nostr_js.d.ts \ No newline at end of file diff --git a/bindings/nostr-js/scripts/epilogue.d.ts b/bindings/nostr-js/scripts/epilogue.d.ts deleted file mode 100644 index db38bcde9..000000000 --- a/bindings/nostr-js/scripts/epilogue.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -/** - * Load the WebAssembly module in the background, if it has not already been loaded. - * - * Returns a promise which will resolve once the other methods are ready. - * - * @returns {Promise} - */ - export function loadWasmAsync(): Promise; - - export function loadWasmSync(): void; \ No newline at end of file diff --git a/bindings/nostr-js/scripts/epilogue.js b/bindings/nostr-js/scripts/epilogue.js deleted file mode 100644 index b4c25ba86..000000000 --- a/bindings/nostr-js/scripts/epilogue.js +++ /dev/null @@ -1,76 +0,0 @@ -let inited = false; -module.exports.loadWasmSync = function () { - if (inited) { - return; - } - if (initPromise) { - throw new Error("Asynchronous initialisation already in progress: cannot initialise synchronously"); - } - const bytes = unbase64(require("./nostr_js_bg.wasm.js")); - const mod = new WebAssembly.Module(bytes); - const instance = new WebAssembly.Instance(mod, imports); - wasm = instance.exports; - wasm.__wbindgen_start(); - inited = true; -}; - -let initPromise = null; - -/** - * Load the WebAssembly module in the background, if it has not already been loaded. - * - * Returns a promise which will resolve once the other methods are ready. - * - * @returns {Promise} - */ -module.exports.loadWasmAsync = function () { - if (inited) { - return Promise.resolve(); - } - if (!initPromise) { - initPromise = Promise.resolve() - .then(() => require("./nostr_js_bg.wasm.js")) - .then((b64) => WebAssembly.instantiate(unbase64(b64), imports)) - .then((result) => { - wasm = result.instance.exports; - wasm.__wbindgen_start(); - inited = true; - }); - } - return initPromise; -}; - -const b64lookup = new Uint8Array([ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 62, 0, 62, 0, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, - 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0, 0, 0, 0, 63, 0, 26, 27, 28, 29, 30, 31, 32, - 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -]); - -// base64 decoder, based on the code at https://developer.mozilla.org/en-US/docs/Glossary/Base64#solution_2_%E2%80%93_rewriting_atob_and_btoa_using_typedarrays_and_utf-8 -function unbase64(sBase64) { - const sB64Enc = sBase64.replace(/[^A-Za-z0-9+/]/g, ""); - const nInLen = sB64Enc.length; - const nOutLen = (nInLen * 3 + 1) >> 2; - const taBytes = new Uint8Array(nOutLen); - - let nMod3; - let nMod4; - let nUint24 = 0; - let nOutIdx = 0; - for (let nInIdx = 0; nInIdx < nInLen; nInIdx++) { - nMod4 = nInIdx & 3; - nUint24 |= b64lookup[sB64Enc.charCodeAt(nInIdx)] << (6 * (3 - nMod4)); - if (nMod4 === 3 || nInLen - nInIdx === 1) { - nMod3 = 0; - while (nMod3 < 3 && nOutIdx < nOutLen) { - taBytes[nOutIdx] = (nUint24 >>> ((16 >>> nMod3) & 24)) & 255; - nMod3++; - nOutIdx++; - } - nUint24 = 0; - } - } - - return taBytes; -} \ No newline at end of file diff --git a/bindings/nostr-js/src/lib.rs b/bindings/nostr-js/src/lib.rs deleted file mode 100644 index 4f2377ab4..000000000 --- a/bindings/nostr-js/src/lib.rs +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (c) 2022-2023 Yuki Kishimoto -// Copyright (c) 2023-2024 Rust Nostr Developers -// Distributed under the MIT software license - -#![allow(clippy::drop_non_drop)] -#![allow(non_snake_case)] -#![allow(clippy::new_without_default)] -// rust-analyzer not work well with multiple different targets in workspace -#![cfg(target_arch = "wasm32")] - -use wasm_bindgen::prelude::*; - -pub mod error; -pub mod event; -pub mod key; -pub mod message; -pub mod nips; -pub mod types; -pub mod util; - -#[wasm_bindgen] -extern "C" { - /// String array - #[wasm_bindgen(typescript_type = "string[]")] - pub type JsStringArray; -} - -/// Run some stuff when the Wasm module is instantiated. -/// -/// Right now, it does the following: -/// -/// * Redirect Rust panics to JavaScript console. -#[wasm_bindgen(start)] -pub fn start() { - console_error_panic_hook::set_once(); -} - -#[wasm_bindgen(js_name = NostrLibrary)] -pub struct JsNostrLibrary; - -#[wasm_bindgen(js_class = NostrLibrary)] -impl JsNostrLibrary { - #[inline] - #[wasm_bindgen(constructor)] - pub fn new() -> Self { - Self - } - - #[inline] - #[wasm_bindgen(js_name = gitHashVersion)] - pub fn git_hash_version(&self) -> Option { - option_env!("GIT_HASH").map(|v| v.to_string()) - } -} diff --git a/bindings/nostr-js/tsconfig.json b/bindings/nostr-js/tsconfig.json deleted file mode 100644 index 84bc409ff..000000000 --- a/bindings/nostr-js/tsconfig.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "compilerOptions": { - "strict": true - }, - "typedocOptions": { - "entryPoints": ["pkg/nostr_js.d.ts"], - "readme": "README.md" - } -} diff --git a/bindings/nostr-sdk-js/.npmignore b/bindings/nostr-sdk-js/.npmignore index f3f005d6a..2ccc3286f 100644 --- a/bindings/nostr-sdk-js/.npmignore +++ b/bindings/nostr-sdk-js/.npmignore @@ -3,10 +3,10 @@ target/ src/ scripts/ examples/ -pkg/README.md +pkg/README.md pkg/package.json pkg/*.wasm .gitignore Cargo.toml Cargo.lock -*.tgz \ No newline at end of file +*.tgz diff --git a/bindings/nostr-sdk-js/Cargo.toml b/bindings/nostr-sdk-js/Cargo.toml index a4952ccf0..c6988e68a 100644 --- a/bindings/nostr-sdk-js/Cargo.toml +++ b/bindings/nostr-sdk-js/Cargo.toml @@ -8,9 +8,9 @@ publish = false crate-type = ["lib", "cdylib"] [dependencies] +console_error_panic_hook = "0.1" js-sys.workspace = true -nostr-js = { path = "../nostr-js" } -nostr-sdk = { path = "../../crates/nostr-sdk", default-features = false, features = ["all-nips", "indexeddb", "webln"] } +nostr-sdk = { workspace = true, default-features = false, features = ["all-nips", "indexeddb", "webln"] } tracing.workspace = true tracing-subscriber.workspace = true wasm-bindgen = { workspace = true, features = ["std"] } diff --git a/bindings/nostr-sdk-js/build.rs b/bindings/nostr-sdk-js/build.rs index 20a05192c..e9ebf2b77 100644 --- a/bindings/nostr-sdk-js/build.rs +++ b/bindings/nostr-sdk-js/build.rs @@ -2,7 +2,16 @@ // Copyright (c) 2023-2024 Rust Nostr Developers // Distributed under the MIT software license +use std::process::Command; + fn main() { + if let Ok(output) = Command::new("git").args(["rev-parse", "HEAD"]).output() { + if let Ok(git_hash) = String::from_utf8(output.stdout) { + println!("cargo:rerun-if-changed={git_hash}"); + println!("cargo:rustc-env=GIT_HASH={git_hash}"); + } + } + // 0x1E84800 bytes = 32MiB println!("cargo:rustc-link-arg=-zstack-size=0x1E84800"); } diff --git a/bindings/nostr-js/examples/event-builder.js b/bindings/nostr-sdk-js/examples/event-builder.js similarity index 100% rename from bindings/nostr-js/examples/event-builder.js rename to bindings/nostr-sdk-js/examples/event-builder.js diff --git a/bindings/nostr-js/examples/filter.js b/bindings/nostr-sdk-js/examples/filter.js similarity index 100% rename from bindings/nostr-js/examples/filter.js rename to bindings/nostr-sdk-js/examples/filter.js diff --git a/bindings/nostr-js/examples/metadata.js b/bindings/nostr-sdk-js/examples/metadata.js similarity index 100% rename from bindings/nostr-js/examples/metadata.js rename to bindings/nostr-sdk-js/examples/metadata.js diff --git a/bindings/nostr-js/examples/nip05.js b/bindings/nostr-sdk-js/examples/nip05.js similarity index 100% rename from bindings/nostr-js/examples/nip05.js rename to bindings/nostr-sdk-js/examples/nip05.js diff --git a/bindings/nostr-sdk-js/examples/nip07.js b/bindings/nostr-sdk-js/examples/nip07.js index 0de1f94ae..756d8e8aa 100644 --- a/bindings/nostr-sdk-js/examples/nip07.js +++ b/bindings/nostr-sdk-js/examples/nip07.js @@ -18,8 +18,27 @@ async function main() { await client.publishTextNote("Test from rust-nostr JavaScript bindings with NIP07 signer!", []); } catch (error) { - console.log(error) + console.log(error) } } -main(); \ No newline at end of file +async function main2() { + try { + let signer = new Nip07Signer(); + + let public_key = await signer.getPublicKey(); + console.log(public_key.toBech32()) + + let ciphertext = await signer.nip04Encrypt(public_key, "Test"); + console.log("NIP04: " + ciphertext); + + let unsigned = EventBuilder.textNote("Test", []).toUnsignedEvent(public_key); + let event = await signer.signEvent(unsigned); + console.log(event.asJson()); + } catch (error) { + console.log(error) + } +} + +main(); +main2(); diff --git a/bindings/nostr-js/examples/nip19.js b/bindings/nostr-sdk-js/examples/nip19.js similarity index 100% rename from bindings/nostr-js/examples/nip19.js rename to bindings/nostr-sdk-js/examples/nip19.js diff --git a/bindings/nostr-js/examples/nip26.js b/bindings/nostr-sdk-js/examples/nip26.js similarity index 100% rename from bindings/nostr-js/examples/nip26.js rename to bindings/nostr-sdk-js/examples/nip26.js diff --git a/bindings/nostr-sdk-js/justfile b/bindings/nostr-sdk-js/justfile index 801d91528..60e0aec30 100644 --- a/bindings/nostr-sdk-js/justfile +++ b/bindings/nostr-sdk-js/justfile @@ -1,11 +1,15 @@ set windows-shell := ["powershell.exe", "-NoLogo", "-Command"] init: - cargo install wasm-pack + @wasm-pack --version || cargo install wasm-pack -publish: pack +clean: + rm -rf ./pkg + rm -f rust-nostr-*.tgz + +publish: npm publish --access public -pack: - rm -rf ./pkg - npm run package +pack: init clean + bash ./scripts/build.sh + npm pack diff --git a/bindings/nostr-sdk-js/package.json b/bindings/nostr-sdk-js/package.json index eb253d5d0..c245a665f 100644 --- a/bindings/nostr-sdk-js/package.json +++ b/bindings/nostr-sdk-js/package.json @@ -5,8 +5,10 @@ "keywords": [ "nostr", "sdk", - "rust", - "javascript" + "client", + "decentralization", + "censorship-resistance", + "social" ], "license": "MIT", "homepage": "https://github.com/rust-nostr/nostr", @@ -37,6 +39,7 @@ "pkg/nostr_sdk_js.d.ts" ], "dependencies": { + "pako": "^2.1.0", "ws": "^8.15.1" }, "devDependencies": { @@ -44,10 +47,5 @@ }, "engines": { "node": ">= 10" - }, - "scripts": { - "build": "WASM_PACK_ARGS=--release ./scripts/build.sh", - "build:dev": "WASM_PACK_ARGS=--dev ./scripts/build.sh", - "package": "npm run build && npm pack" } } diff --git a/bindings/nostr-sdk-js/scripts/build.sh b/bindings/nostr-sdk-js/scripts/build.sh index a1b10178e..5d4ab826d 100755 --- a/bindings/nostr-sdk-js/scripts/build.sh +++ b/bindings/nostr-sdk-js/scripts/build.sh @@ -16,15 +16,18 @@ set -exuo pipefail cd "$(dirname "$0")/.." -wasm-pack build --target nodejs --no-pack --scope rust-nostr --weak-refs --reference-types --out-dir pkg "${WASM_PACK_ARGS[@]}" +wasm-pack build --target nodejs --no-pack --scope rust-nostr --weak-refs --reference-types --out-dir pkg --release # Shrinking .wasm Size wc -c pkg/nostr_sdk_js_bg.wasm +# Compress +gzip -c pkg/nostr_sdk_js_bg.wasm > pkg/nostr_sdk_js_bg.wasm.gz + # Convert the Wasm into a JS file that exports the base64'ed Wasm. { printf 'module.exports = `' - base64 < pkg/nostr_sdk_js_bg.wasm + base64 < pkg/nostr_sdk_js_bg.wasm.gz printf '`;' } > pkg/nostr_sdk_js_bg.wasm.js @@ -39,4 +42,4 @@ wc -c pkg/nostr_sdk_js_bg.wasm mv pkg/nostr_sdk_js.js.new pkg/nostr_sdk_js.js # also extend the typescript -cat scripts/epilogue.d.ts >> pkg/nostr_sdk_js.d.ts \ No newline at end of file +cat scripts/epilogue.d.ts >> pkg/nostr_sdk_js.d.ts diff --git a/bindings/nostr-sdk-js/scripts/epilogue.js b/bindings/nostr-sdk-js/scripts/epilogue.js index 46dfa642c..2e0dc19d3 100644 --- a/bindings/nostr-sdk-js/scripts/epilogue.js +++ b/bindings/nostr-sdk-js/scripts/epilogue.js @@ -1,3 +1,6 @@ +// gzip +const { inflate } = require("pako"); + let WebSocketClass; // Check if WebSocket is available in the current environment @@ -19,8 +22,9 @@ module.exports.loadWasmSync = function () { if (initPromise) { throw new Error("Asynchronous initialisation already in progress: cannot initialise synchronously"); } - const bytes = unbase64(require("./nostr_sdk_js_bg.wasm.js")); - const mod = new WebAssembly.Module(bytes); + const compressedBytes = unbase64(require("./nostr_sdk_js_bg.wasm.js")); + const decompressedBytes = inflate(compressedBytes); + const mod = new WebAssembly.Module(decompressedBytes); const instance = new WebAssembly.Instance(mod, imports); wasm = instance.exports; wasm.__wbindgen_start(); @@ -43,7 +47,11 @@ module.exports.loadWasmAsync = function () { if (!initPromise) { initPromise = Promise.resolve() .then(() => require("./nostr_sdk_js_bg.wasm.js")) - .then((b64) => WebAssembly.instantiate(unbase64(b64), imports)) + .then((b64) => { + const compressedBytes = unbase64(b64); + const decompressedBytes = inflate(compressedBytes); + return WebAssembly.instantiate(decompressedBytes, imports); + }) .then((result) => { wasm = result.instance.exports; wasm.__wbindgen_start(); @@ -86,4 +94,4 @@ function unbase64(sBase64) { } return taBytes; -} \ No newline at end of file +} diff --git a/bindings/nostr-sdk-js/src/client/mod.rs b/bindings/nostr-sdk-js/src/client/mod.rs index 245c2f9eb..99eae9ca4 100644 --- a/bindings/nostr-sdk-js/src/client/mod.rs +++ b/bindings/nostr-sdk-js/src/client/mod.rs @@ -6,12 +6,6 @@ use std::ops::Deref; use std::time::Duration; use js_sys::Array; -use nostr_js::error::{into_err, Result}; -use nostr_js::event::{JsEvent, JsEventBuilder, JsEventId, JsTag}; -use nostr_js::key::JsPublicKey; -use nostr_js::message::{JsClientMessage, JsRelayMessage}; -use nostr_js::nips::nip59::JsUnwrappedGift; -use nostr_js::types::{JsContact, JsFilter, JsMetadata, JsTimestamp}; use nostr_sdk::async_utility::thread; use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; @@ -28,8 +22,14 @@ use self::zapper::{JsZapDetails, JsZapEntity}; use crate::abortable::JsAbortHandle; use crate::database::{JsEvents, JsNostrDatabase}; use crate::duration::JsDuration; +use crate::error::{into_err, Result}; use crate::pool::result::{JsOutput, JsReconciliationOutput, JsSendEventOutput, JsSubscribeOutput}; use crate::pool::JsRelayPool; +use crate::protocol::event::{JsEvent, JsEventBuilder, JsEventId, JsTag}; +use crate::protocol::key::JsPublicKey; +use crate::protocol::message::{JsClientMessage, JsRelayMessage}; +use crate::protocol::nips::nip59::JsUnwrappedGift; +use crate::protocol::types::{JsContact, JsFilter, JsMetadata, JsTimestamp}; use crate::relay::filtering::JsRelayFiltering; use crate::relay::options::{JsSubscribeAutoCloseOptions, JsSyncOptions}; use crate::relay::{JsRelay, JsRelayArray}; diff --git a/bindings/nostr-sdk-js/src/client/signer/mod.rs b/bindings/nostr-sdk-js/src/client/signer/mod.rs index 24e0927c1..72faa6b18 100644 --- a/bindings/nostr-sdk-js/src/client/signer/mod.rs +++ b/bindings/nostr-sdk-js/src/client/signer/mod.rs @@ -4,17 +4,17 @@ use std::ops::Deref; -use nostr_js::error::{into_err, Result}; -use nostr_js::event::{JsEvent, JsEventBuilder, JsUnsignedEvent}; -use nostr_js::key::{JsKeys, JsPublicKey}; -use nostr_js::nips::nip07::JsNip07Signer; -use nostr_js::nips::nip59::JsUnwrappedGift; use nostr_sdk::NostrSigner; use wasm_bindgen::prelude::*; pub mod nip46; use self::nip46::JsNip46Signer; +use crate::error::{into_err, Result}; +use crate::protocol::event::{JsEvent, JsEventBuilder, JsUnsignedEvent}; +use crate::protocol::key::{JsKeys, JsPublicKey}; +use crate::protocol::nips::nip07::JsNip07Signer; +use crate::protocol::nips::nip59::JsUnwrappedGift; #[wasm_bindgen(js_name = NostrSigner)] pub struct JsNostrSigner { diff --git a/bindings/nostr-sdk-js/src/client/signer/nip46.rs b/bindings/nostr-sdk-js/src/client/signer/nip46.rs index e78775aab..b0c2568ad 100644 --- a/bindings/nostr-sdk-js/src/client/signer/nip46.rs +++ b/bindings/nostr-sdk-js/src/client/signer/nip46.rs @@ -5,14 +5,14 @@ use core::ops::Deref; use js_sys::Array; -use nostr_js::error::{into_err, Result}; -use nostr_js::key::{JsKeys, JsPublicKey}; -use nostr_js::nips::nip46::JsNostrConnectURI; -use nostr_js::JsStringArray; use nostr_sdk::signer::Nip46Signer; use wasm_bindgen::prelude::*; use crate::duration::JsDuration; +use crate::error::{into_err, Result}; +use crate::protocol::key::{JsKeys, JsPublicKey}; +use crate::protocol::nips::nip46::JsNostrConnectURI; +use crate::JsStringArray; #[wasm_bindgen(js_name = Nip46Signer)] pub struct JsNip46Signer { diff --git a/bindings/nostr-sdk-js/src/client/zapper.rs b/bindings/nostr-sdk-js/src/client/zapper.rs index c351239c0..02342a123 100644 --- a/bindings/nostr-sdk-js/src/client/zapper.rs +++ b/bindings/nostr-sdk-js/src/client/zapper.rs @@ -5,14 +5,14 @@ use core::ops::Deref; use std::sync::Arc; -use nostr_js::error::{into_err, Result}; -use nostr_js::event::JsEventId; -use nostr_js::key::JsPublicKey; -use nostr_js::nips::nip57::JsZapType; use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; +use crate::error::{into_err, Result}; use crate::nwc::JsNwc; +use crate::protocol::event::JsEventId; +use crate::protocol::key::JsPublicKey; +use crate::protocol::nips::nip57::JsZapType; /// Zap entity #[wasm_bindgen(js_name = ZapEntity)] diff --git a/bindings/nostr-sdk-js/src/database/events.rs b/bindings/nostr-sdk-js/src/database/events.rs index da046dfa6..48dd9206b 100644 --- a/bindings/nostr-sdk-js/src/database/events.rs +++ b/bindings/nostr-sdk-js/src/database/events.rs @@ -5,10 +5,11 @@ use core::ops::Deref; use js_sys::Function; -use nostr_js::event::JsEvent; use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; +use crate::protocol::event::JsEvent; + #[wasm_bindgen(js_name = Events)] pub struct JsEvents { inner: Events, diff --git a/bindings/nostr-sdk-js/src/database/mod.rs b/bindings/nostr-sdk-js/src/database/mod.rs index b3d4bda99..d71acbb94 100644 --- a/bindings/nostr-sdk-js/src/database/mod.rs +++ b/bindings/nostr-sdk-js/src/database/mod.rs @@ -6,11 +6,6 @@ use std::ops::Deref; use std::sync::Arc; use js_sys::Array; -use nostr_js::error::{into_err, Result}; -use nostr_js::event::{JsEvent, JsEventId}; -use nostr_js::key::JsPublicKey; -use nostr_js::types::JsFilter; -use nostr_js::JsStringArray; use nostr_sdk::database::{DynNostrDatabase, IntoNostrDatabase, NostrDatabaseExt}; use nostr_sdk::WebDatabase; use wasm_bindgen::prelude::*; @@ -18,7 +13,12 @@ use wasm_bindgen::prelude::*; pub mod events; pub use self::events::JsEvents; +use crate::error::{into_err, Result}; use crate::profile::JsProfile; +use crate::protocol::event::{JsEvent, JsEventId}; +use crate::protocol::key::JsPublicKey; +use crate::protocol::types::JsFilter; +use crate::JsStringArray; /// Nostr Database #[wasm_bindgen(js_name = NostrDatabase)] diff --git a/bindings/nostr-js/src/error.rs b/bindings/nostr-sdk-js/src/error.rs similarity index 100% rename from bindings/nostr-js/src/error.rs rename to bindings/nostr-sdk-js/src/error.rs diff --git a/bindings/nostr-sdk-js/src/lib.rs b/bindings/nostr-sdk-js/src/lib.rs index 5e208b466..4dffe8865 100644 --- a/bindings/nostr-sdk-js/src/lib.rs +++ b/bindings/nostr-sdk-js/src/lib.rs @@ -10,14 +10,51 @@ // rust-analyzer not work well with multiple different targets in workspace #![cfg(target_arch = "wasm32")] -pub use nostr_js; +use wasm_bindgen::prelude::*; pub mod abortable; pub mod client; pub mod database; pub mod duration; +pub mod error; pub mod logger; pub mod nwc; pub mod pool; pub mod profile; +pub mod protocol; pub mod relay; + +#[wasm_bindgen] +extern "C" { + /// String array + #[wasm_bindgen(typescript_type = "string[]")] + pub type JsStringArray; +} + +/// Run some stuff when the Wasm module is instantiated. +/// +/// Right now, it does the following: +/// +/// * Redirect Rust panics to JavaScript console. +#[wasm_bindgen(start)] +pub fn start() { + console_error_panic_hook::set_once(); +} + +#[wasm_bindgen(js_name = NostrLibrary)] +pub struct JsNostrLibrary; + +#[wasm_bindgen(js_class = NostrLibrary)] +impl JsNostrLibrary { + #[inline] + #[wasm_bindgen(constructor)] + pub fn new() -> Self { + Self + } + + #[inline] + #[wasm_bindgen(js_name = gitHashVersion)] + pub fn git_hash_version(&self) -> Option { + option_env!("GIT_HASH").map(|v| v.to_string()) + } +} diff --git a/bindings/nostr-sdk-js/src/logger.rs b/bindings/nostr-sdk-js/src/logger.rs index 8a4dfd5c2..0f29f9ac6 100644 --- a/bindings/nostr-sdk-js/src/logger.rs +++ b/bindings/nostr-sdk-js/src/logger.rs @@ -5,8 +5,6 @@ use core::fmt::{self, Write}; use core::sync::atomic::{AtomicUsize, Ordering}; -use nostr_js::error::{into_err, Result}; -use nostr_js::JsNostrLibrary; use tracing::dispatcher::SetGlobalDefaultError; use tracing::field::{Field, Visit}; use tracing::{Level, Subscriber}; @@ -14,6 +12,9 @@ use tracing_subscriber::layer::*; use tracing_subscriber::registry::*; use wasm_bindgen::prelude::*; +use crate::error::{into_err, Result}; +use crate::JsNostrLibrary; + #[wasm_bindgen(js_name = LogLevel)] pub struct JsLogLevel { inner: Level, diff --git a/bindings/nostr-sdk-js/src/nwc/mod.rs b/bindings/nostr-sdk-js/src/nwc/mod.rs index 3e3d69cf3..620e0662f 100644 --- a/bindings/nostr-sdk-js/src/nwc/mod.rs +++ b/bindings/nostr-sdk-js/src/nwc/mod.rs @@ -5,18 +5,18 @@ use std::ops::Deref; use js_sys::Array; -use nostr_js::error::{into_err, Result}; -use nostr_js::nips::nip47::{ - JsGetInfoResponseResult, JsListTransactionsRequestParams, JsLookupInvoiceRequestParams, - JsLookupInvoiceResponseResult, JsMakeInvoiceRequestParams, JsMakeInvoiceResponseResult, - JsNostrWalletConnectURI, JsPayKeysendRequestParams, JsPayKeysendResponseResult, -}; use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; pub mod options; use self::options::JsNostrWalletConnectOptions; +use crate::error::{into_err, Result}; +use crate::protocol::nips::nip47::{ + JsGetInfoResponseResult, JsListTransactionsRequestParams, JsLookupInvoiceRequestParams, + JsLookupInvoiceResponseResult, JsMakeInvoiceRequestParams, JsMakeInvoiceResponseResult, + JsNostrWalletConnectURI, JsPayKeysendRequestParams, JsPayKeysendResponseResult, +}; #[wasm_bindgen] extern "C" { diff --git a/bindings/nostr-sdk-js/src/pool/mod.rs b/bindings/nostr-sdk-js/src/pool/mod.rs index 4586fd6ab..ba932aecd 100644 --- a/bindings/nostr-sdk-js/src/pool/mod.rs +++ b/bindings/nostr-sdk-js/src/pool/mod.rs @@ -6,10 +6,6 @@ use std::ops::Deref; use std::sync::Arc; use js_sys::Array; -use nostr_js::error::{into_err, Result}; -use nostr_js::event::JsEvent; -use nostr_js::message::JsClientMessage; -use nostr_js::types::JsFilter; use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; @@ -18,6 +14,10 @@ pub mod result; use self::result::{JsOutput, JsReconciliationOutput, JsSendEventOutput, JsSubscribeOutput}; use crate::database::JsNostrDatabase; use crate::duration::JsDuration; +use crate::error::{into_err, Result}; +use crate::protocol::event::JsEvent; +use crate::protocol::message::JsClientMessage; +use crate::protocol::types::JsFilter; use crate::relay::filtering::JsRelayFiltering; use crate::relay::options::{ JsRelayOptions, JsRelaySendOptions, JsSubscribeOptions, JsSyncOptions, diff --git a/bindings/nostr-sdk-js/src/pool/result.rs b/bindings/nostr-sdk-js/src/pool/result.rs index 07e15f067..5d43f394a 100644 --- a/bindings/nostr-sdk-js/src/pool/result.rs +++ b/bindings/nostr-sdk-js/src/pool/result.rs @@ -4,10 +4,10 @@ use std::collections::{HashMap, HashSet}; -use nostr_js::event::JsEventId; use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; +use crate::protocol::event::JsEventId; use crate::relay::JsReconciliation; #[derive(Clone)] diff --git a/bindings/nostr-sdk-js/src/profile.rs b/bindings/nostr-sdk-js/src/profile.rs index c55370896..0ba2b97c5 100644 --- a/bindings/nostr-sdk-js/src/profile.rs +++ b/bindings/nostr-sdk-js/src/profile.rs @@ -4,11 +4,12 @@ use std::ops::Deref; -use nostr_js::key::JsPublicKey; -use nostr_js::types::JsMetadata; use nostr_sdk::database::Profile; use wasm_bindgen::prelude::*; +use crate::protocol::key::JsPublicKey; +use crate::protocol::types::JsMetadata; + #[wasm_bindgen(js_name = Profile)] pub struct JsProfile { inner: Profile, diff --git a/bindings/nostr-js/src/event/builder.rs b/bindings/nostr-sdk-js/src/protocol/event/builder.rs similarity index 97% rename from bindings/nostr-js/src/event/builder.rs rename to bindings/nostr-sdk-js/src/protocol/event/builder.rs index 5be63df0c..09cd7f5ad 100644 --- a/bindings/nostr-js/src/event/builder.rs +++ b/bindings/nostr-sdk-js/src/protocol/event/builder.rs @@ -5,26 +5,26 @@ use core::ops::Deref; use std::str::FromStr; -use nostr::prelude::*; +use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; use super::{JsEvent, JsEventId, JsKind, JsTag, JsUnsignedEvent}; use crate::error::{into_err, Result}; -use crate::key::{JsKeys, JsPublicKey}; -use crate::nips::nip01::JsCoordinate; -use crate::nips::nip15::{JsProductData, JsStallData}; -use crate::nips::nip34::{JsGitIssue, JsGitRepositoryAnnouncement}; -use crate::nips::nip51::{ +use crate::protocol::key::{JsKeys, JsPublicKey}; +use crate::protocol::nips::nip01::JsCoordinate; +use crate::protocol::nips::nip15::{JsProductData, JsStallData}; +use crate::protocol::nips::nip34::{JsGitIssue, JsGitRepositoryAnnouncement}; +use crate::protocol::nips::nip51::{ JsArticlesCuration, JsBookmarks, JsEmojiInfo, JsEmojis, JsInterests, JsMuteList, }; -use crate::nips::nip53::JsLiveEvent; -use crate::nips::nip57::JsZapRequestData; -use crate::nips::nip65::JsRelayListItem; -use crate::nips::nip90::JsJobFeedbackData; -use crate::nips::nip94::JsFileMetadata; -use crate::nips::nip98::JsHttpData; -use crate::types::image::{JsImageDimensions, JsThumbnails}; -use crate::types::{JsContact, JsMetadata, JsTimestamp}; +use crate::protocol::nips::nip53::JsLiveEvent; +use crate::protocol::nips::nip57::JsZapRequestData; +use crate::protocol::nips::nip65::JsRelayListItem; +use crate::protocol::nips::nip90::JsJobFeedbackData; +use crate::protocol::nips::nip94::JsFileMetadata; +use crate::protocol::nips::nip98::JsHttpData; +use crate::protocol::types::image::{JsImageDimensions, JsThumbnails}; +use crate::protocol::types::{JsContact, JsMetadata, JsTimestamp}; #[wasm_bindgen(js_name = EventBuilder)] pub struct JsEventBuilder { diff --git a/bindings/nostr-js/src/event/id.rs b/bindings/nostr-sdk-js/src/protocol/event/id.rs similarity index 96% rename from bindings/nostr-js/src/event/id.rs rename to bindings/nostr-sdk-js/src/protocol/event/id.rs index 51c7b487c..c0a08a308 100644 --- a/bindings/nostr-js/src/event/id.rs +++ b/bindings/nostr-sdk-js/src/protocol/event/id.rs @@ -4,13 +4,13 @@ use core::ops::Deref; -use nostr::prelude::*; +use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; use super::{JsKind, JsTag}; use crate::error::{into_err, Result}; -use crate::key::JsPublicKey; -use crate::types::JsTimestamp; +use crate::protocol::key::JsPublicKey; +use crate::protocol::types::JsTimestamp; #[wasm_bindgen(js_name = EventId)] #[derive(Clone, Copy)] diff --git a/bindings/nostr-js/src/event/kind.rs b/bindings/nostr-sdk-js/src/protocol/event/kind.rs similarity index 99% rename from bindings/nostr-js/src/event/kind.rs rename to bindings/nostr-sdk-js/src/protocol/event/kind.rs index 4a385cc61..07ea04ee7 100644 --- a/bindings/nostr-js/src/event/kind.rs +++ b/bindings/nostr-sdk-js/src/protocol/event/kind.rs @@ -4,7 +4,7 @@ use std::ops::Deref; -use nostr::prelude::*; +use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; /// Event Kind diff --git a/bindings/nostr-js/src/event/mod.rs b/bindings/nostr-sdk-js/src/protocol/event/mod.rs similarity index 97% rename from bindings/nostr-js/src/event/mod.rs rename to bindings/nostr-sdk-js/src/protocol/event/mod.rs index 6ca1b8b27..b5f3e82ad 100644 --- a/bindings/nostr-js/src/event/mod.rs +++ b/bindings/nostr-sdk-js/src/protocol/event/mod.rs @@ -4,7 +4,7 @@ use core::ops::Deref; -use nostr::prelude::*; +use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; pub mod builder; @@ -18,9 +18,9 @@ pub use self::id::JsEventId; pub use self::kind::JsKind; pub use self::tag::{JsTag, JsTags}; pub use self::unsigned::JsUnsignedEvent; +use super::key::JsPublicKey; +use super::types::JsTimestamp; use crate::error::{into_err, Result}; -use crate::key::JsPublicKey; -use crate::types::JsTimestamp; #[wasm_bindgen(js_name = Event)] pub struct JsEvent { diff --git a/bindings/nostr-js/src/event/tag/list.rs b/bindings/nostr-sdk-js/src/protocol/event/tag/list.rs similarity index 94% rename from bindings/nostr-js/src/event/tag/list.rs rename to bindings/nostr-sdk-js/src/protocol/event/tag/list.rs index cfb7566c7..768483d7c 100644 --- a/bindings/nostr-js/src/event/tag/list.rs +++ b/bindings/nostr-sdk-js/src/protocol/event/tag/list.rs @@ -2,14 +2,14 @@ // Copyright (c) 2023-2024 Rust Nostr Developers // Distributed under the MIT software license -use nostr::prelude::*; +use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; use super::JsTag; -use crate::event::JsEventId; -use crate::key::JsPublicKey; -use crate::nips::nip01::JsCoordinate; -use crate::types::JsTimestamp; +use crate::protocol::event::JsEventId; +use crate::protocol::key::JsPublicKey; +use crate::protocol::nips::nip01::JsCoordinate; +use crate::protocol::types::JsTimestamp; #[wasm_bindgen(js_name = Tags)] pub struct JsTags { diff --git a/bindings/nostr-js/src/event/tag/mod.rs b/bindings/nostr-sdk-js/src/protocol/event/tag/mod.rs similarity index 94% rename from bindings/nostr-js/src/event/tag/mod.rs rename to bindings/nostr-sdk-js/src/protocol/event/tag/mod.rs index df21ec4b7..d15393a1a 100644 --- a/bindings/nostr-js/src/event/tag/mod.rs +++ b/bindings/nostr-sdk-js/src/protocol/event/tag/mod.rs @@ -4,21 +4,21 @@ use std::ops::Deref; -use nostr::prelude::*; +use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; pub mod list; pub use self::list::JsTags; +use super::JsEventId; use crate::error::{into_err, Result}; -use crate::event::JsEventId; -use crate::key::JsPublicKey; -use crate::nips::nip01::JsCoordinate; -use crate::nips::nip56::JsReport; -use crate::nips::nip65::JsRelayMetadata; -use crate::types::filter::JsSingleLetterTag; -use crate::types::image::JsImageDimensions; -use crate::types::JsTimestamp; +use crate::protocol::key::JsPublicKey; +use crate::protocol::nips::nip01::JsCoordinate; +use crate::protocol::nips::nip56::JsReport; +use crate::protocol::nips::nip65::JsRelayMetadata; +use crate::protocol::types::filter::JsSingleLetterTag; +use crate::protocol::types::image::JsImageDimensions; +use crate::protocol::types::JsTimestamp; /// Tag #[wasm_bindgen(js_name = Tag)] diff --git a/bindings/nostr-js/src/event/unsigned.rs b/bindings/nostr-sdk-js/src/protocol/event/unsigned.rs similarity index 92% rename from bindings/nostr-js/src/event/unsigned.rs rename to bindings/nostr-sdk-js/src/protocol/event/unsigned.rs index 1984e7537..5333f8b98 100644 --- a/bindings/nostr-js/src/event/unsigned.rs +++ b/bindings/nostr-sdk-js/src/protocol/event/unsigned.rs @@ -5,15 +5,15 @@ use core::ops::Deref; use core::str::FromStr; -use nostr::bitcoin::secp256k1::schnorr::Signature; -use nostr::{JsonUtil, UnsignedEvent}; +use nostr_sdk::bitcoin::secp256k1::schnorr::Signature; +use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; use super::tag::JsTag; use crate::error::{into_err, Result}; -use crate::event::{JsEvent, JsEventId, JsKind}; -use crate::key::{JsKeys, JsPublicKey}; -use crate::types::JsTimestamp; +use crate::protocol::event::{JsEvent, JsEventId, JsKind}; +use crate::protocol::key::{JsKeys, JsPublicKey}; +use crate::protocol::types::JsTimestamp; #[wasm_bindgen(js_name = UnsignedEvent)] pub struct JsUnsignedEvent { diff --git a/bindings/nostr-js/src/key/mod.rs b/bindings/nostr-sdk-js/src/protocol/key/mod.rs similarity index 98% rename from bindings/nostr-js/src/key/mod.rs rename to bindings/nostr-sdk-js/src/protocol/key/mod.rs index e96e70063..51d651c68 100644 --- a/bindings/nostr-js/src/key/mod.rs +++ b/bindings/nostr-sdk-js/src/protocol/key/mod.rs @@ -4,7 +4,7 @@ use core::ops::Deref; -use nostr::prelude::*; +use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; mod public_key; diff --git a/bindings/nostr-js/src/key/public_key.rs b/bindings/nostr-sdk-js/src/protocol/key/public_key.rs similarity index 98% rename from bindings/nostr-js/src/key/public_key.rs rename to bindings/nostr-sdk-js/src/protocol/key/public_key.rs index 07eab2273..5f6f589df 100644 --- a/bindings/nostr-js/src/key/public_key.rs +++ b/bindings/nostr-sdk-js/src/protocol/key/public_key.rs @@ -4,7 +4,7 @@ use core::ops::Deref; -use nostr::prelude::*; +use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; use crate::error::{into_err, Result}; diff --git a/bindings/nostr-js/src/key/secret_key.rs b/bindings/nostr-sdk-js/src/protocol/key/secret_key.rs similarity index 95% rename from bindings/nostr-js/src/key/secret_key.rs rename to bindings/nostr-sdk-js/src/protocol/key/secret_key.rs index 2414f4cda..3d8367f63 100644 --- a/bindings/nostr-js/src/key/secret_key.rs +++ b/bindings/nostr-sdk-js/src/protocol/key/secret_key.rs @@ -4,11 +4,11 @@ use core::ops::Deref; -use nostr::prelude::*; +use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; use crate::error::{into_err, Result}; -use crate::nips::nip49::JsEncryptedSecretKey; +use crate::protocol::nips::nip49::JsEncryptedSecretKey; #[wasm_bindgen(js_name = SecretKey)] pub struct JsSecretKey { diff --git a/bindings/nostr-js/src/message/client.rs b/bindings/nostr-sdk-js/src/protocol/message/client.rs similarity index 95% rename from bindings/nostr-js/src/message/client.rs rename to bindings/nostr-sdk-js/src/protocol/message/client.rs index a56489c67..5d055b4d3 100644 --- a/bindings/nostr-js/src/message/client.rs +++ b/bindings/nostr-sdk-js/src/protocol/message/client.rs @@ -4,12 +4,12 @@ use core::ops::Deref; -use nostr::{ClientMessage, JsonUtil, SubscriptionId}; +use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; use crate::error::{into_err, Result}; -use crate::event::JsEvent; -use crate::types::JsFilter; +use crate::protocol::event::JsEvent; +use crate::protocol::types::JsFilter; #[wasm_bindgen(js_name = ClientMessage)] pub struct JsClientMessage { diff --git a/bindings/nostr-js/src/message/mod.rs b/bindings/nostr-sdk-js/src/protocol/message/mod.rs similarity index 100% rename from bindings/nostr-js/src/message/mod.rs rename to bindings/nostr-sdk-js/src/protocol/message/mod.rs diff --git a/bindings/nostr-js/src/message/relay.rs b/bindings/nostr-sdk-js/src/protocol/message/relay.rs similarity index 96% rename from bindings/nostr-js/src/message/relay.rs rename to bindings/nostr-sdk-js/src/protocol/message/relay.rs index c396bada5..0e7141c39 100644 --- a/bindings/nostr-js/src/message/relay.rs +++ b/bindings/nostr-sdk-js/src/protocol/message/relay.rs @@ -4,11 +4,11 @@ use core::ops::Deref; -use nostr::{JsonUtil, RelayMessage, SubscriptionId}; +use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; use crate::error::{into_err, Result}; -use crate::event::{JsEvent, JsEventId}; +use crate::protocol::event::{JsEvent, JsEventId}; #[wasm_bindgen(js_name = RelayMessage)] pub struct JsRelayMessage { diff --git a/bindings/nostr-sdk-js/src/protocol/mod.rs b/bindings/nostr-sdk-js/src/protocol/mod.rs new file mode 100644 index 000000000..7aaade91d --- /dev/null +++ b/bindings/nostr-sdk-js/src/protocol/mod.rs @@ -0,0 +1,10 @@ +// Copyright (c) 2022-2023 Yuki Kishimoto +// Copyright (c) 2023-2024 Rust Nostr Developers +// Distributed under the MIT software license + +pub mod event; +pub mod key; +pub mod message; +pub mod nips; +pub mod types; +pub mod util; diff --git a/bindings/nostr-js/src/nips/mod.rs b/bindings/nostr-sdk-js/src/protocol/nips/mod.rs similarity index 100% rename from bindings/nostr-js/src/nips/mod.rs rename to bindings/nostr-sdk-js/src/protocol/nips/mod.rs diff --git a/bindings/nostr-js/src/nips/nip01.rs b/bindings/nostr-sdk-js/src/protocol/nips/nip01.rs similarity index 95% rename from bindings/nostr-js/src/nips/nip01.rs rename to bindings/nostr-sdk-js/src/protocol/nips/nip01.rs index e47179a19..c544c3b1b 100644 --- a/bindings/nostr-js/src/nips/nip01.rs +++ b/bindings/nostr-sdk-js/src/protocol/nips/nip01.rs @@ -3,12 +3,12 @@ use core::ops::Deref; -use nostr::prelude::*; +use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; use crate::error::{into_err, Result}; -use crate::event::JsKind; -use crate::key::JsPublicKey; +use crate::protocol::event::JsKind; +use crate::protocol::key::JsPublicKey; #[wasm_bindgen(js_name = Coordinate)] #[derive(Clone)] diff --git a/bindings/nostr-js/src/nips/nip04.rs b/bindings/nostr-sdk-js/src/protocol/nips/nip04.rs similarity index 90% rename from bindings/nostr-js/src/nips/nip04.rs rename to bindings/nostr-sdk-js/src/protocol/nips/nip04.rs index 05a6a70a3..ec50e080e 100644 --- a/bindings/nostr-js/src/nips/nip04.rs +++ b/bindings/nostr-sdk-js/src/protocol/nips/nip04.rs @@ -4,11 +4,11 @@ use std::ops::Deref; -use nostr::nips::nip04; +use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; use crate::error::{into_err, Result}; -use crate::key::{JsPublicKey, JsSecretKey}; +use crate::protocol::key::{JsPublicKey, JsSecretKey}; /// Encrypt (NIP04) #[wasm_bindgen(js_name = nip04Encrypt)] diff --git a/bindings/nostr-js/src/nips/nip05.rs b/bindings/nostr-sdk-js/src/protocol/nips/nip05.rs similarity index 96% rename from bindings/nostr-js/src/nips/nip05.rs rename to bindings/nostr-sdk-js/src/protocol/nips/nip05.rs index e5100045e..8578eea84 100644 --- a/bindings/nostr-js/src/nips/nip05.rs +++ b/bindings/nostr-sdk-js/src/protocol/nips/nip05.rs @@ -4,11 +4,11 @@ use core::ops::Deref; -use nostr::prelude::*; +use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; use crate::error::{into_err, Result}; -use crate::key::JsPublicKey; +use crate::protocol::key::JsPublicKey; /// NIP05 profile /// diff --git a/bindings/nostr-js/src/nips/nip07.rs b/bindings/nostr-sdk-js/src/protocol/nips/nip07.rs similarity index 94% rename from bindings/nostr-js/src/nips/nip07.rs rename to bindings/nostr-sdk-js/src/protocol/nips/nip07.rs index 127a8b566..369df584f 100644 --- a/bindings/nostr-js/src/nips/nip07.rs +++ b/bindings/nostr-sdk-js/src/protocol/nips/nip07.rs @@ -4,13 +4,12 @@ use core::ops::Deref; -use nostr::nips::nip07::Nip07Signer; -use nostr::PublicKey; +use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; use crate::error::{into_err, Result}; -use crate::event::{JsEvent, JsUnsignedEvent}; -use crate::key::JsPublicKey; +use crate::protocol::event::{JsEvent, JsUnsignedEvent}; +use crate::protocol::key::JsPublicKey; /// NIP07 Signer for interaction with browser extensions (ex. Alby) /// diff --git a/bindings/nostr-js/src/nips/nip11.rs b/bindings/nostr-sdk-js/src/protocol/nips/nip11.rs similarity index 98% rename from bindings/nostr-js/src/nips/nip11.rs rename to bindings/nostr-sdk-js/src/protocol/nips/nip11.rs index 586cd7555..530d948a7 100644 --- a/bindings/nostr-js/src/nips/nip11.rs +++ b/bindings/nostr-sdk-js/src/protocol/nips/nip11.rs @@ -2,7 +2,7 @@ // Copyright (c) 2023-2024 Rust Nostr Developers // Distributed under the MIT software license -use nostr::prelude::*; +use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; use crate::error::{into_err, Result}; diff --git a/bindings/nostr-js/src/nips/nip15.rs b/bindings/nostr-sdk-js/src/protocol/nips/nip15.rs similarity index 98% rename from bindings/nostr-js/src/nips/nip15.rs rename to bindings/nostr-sdk-js/src/protocol/nips/nip15.rs index 73487b958..307bd32de 100644 --- a/bindings/nostr-js/src/nips/nip15.rs +++ b/bindings/nostr-sdk-js/src/protocol/nips/nip15.rs @@ -4,7 +4,7 @@ use std::ops::Deref; use js_sys::Array; -use nostr::nips::nip15::{ProductData, ShippingCost, ShippingMethod, StallData}; +use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; use crate::JsStringArray; diff --git a/bindings/nostr-js/src/nips/nip19.rs b/bindings/nostr-sdk-js/src/protocol/nips/nip19.rs similarity index 96% rename from bindings/nostr-js/src/nips/nip19.rs rename to bindings/nostr-sdk-js/src/protocol/nips/nip19.rs index 8e54abc78..6b32f31d6 100644 --- a/bindings/nostr-js/src/nips/nip19.rs +++ b/bindings/nostr-sdk-js/src/protocol/nips/nip19.rs @@ -2,12 +2,12 @@ // Copyright (c) 2023-2024 Rust Nostr Developers // Distributed under the MIT software license -use nostr::prelude::*; +use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; use crate::error::{into_err, Result}; -use crate::event::{JsEventId, JsKind}; -use crate::key::JsPublicKey; +use crate::protocol::event::{JsEventId, JsKind}; +use crate::protocol::key::JsPublicKey; #[wasm_bindgen(js_name = Nip19Event)] pub struct JsNip19Event { diff --git a/bindings/nostr-js/src/nips/nip26.rs b/bindings/nostr-sdk-js/src/protocol/nips/nip26.rs similarity index 92% rename from bindings/nostr-js/src/nips/nip26.rs rename to bindings/nostr-sdk-js/src/protocol/nips/nip26.rs index 1d61a9758..426706c8c 100644 --- a/bindings/nostr-js/src/nips/nip26.rs +++ b/bindings/nostr-sdk-js/src/protocol/nips/nip26.rs @@ -5,14 +5,14 @@ use std::ops::Deref; use std::str::FromStr; -use nostr::nips::nip26::{self, Conditions, DelegationTag, EventProperties}; -use nostr::secp256k1::schnorr::Signature; +use nostr_sdk::prelude::*; +use nostr_sdk::secp256k1::schnorr::Signature; use wasm_bindgen::prelude::*; use crate::error::{into_err, Result}; -use crate::event::JsKind; -use crate::key::{JsKeys, JsPublicKey}; -use crate::types::JsTimestamp; +use crate::protocol::event::JsKind; +use crate::protocol::key::{JsKeys, JsPublicKey}; +use crate::protocol::types::JsTimestamp; /// Create a NIP26 delegation tag (including the signature). /// See also validate_delegation_tag(). diff --git a/bindings/nostr-js/src/nips/nip34.rs b/bindings/nostr-sdk-js/src/protocol/nips/nip34.rs similarity index 96% rename from bindings/nostr-js/src/nips/nip34.rs rename to bindings/nostr-sdk-js/src/protocol/nips/nip34.rs index 6c4c71836..70e48983f 100644 --- a/bindings/nostr-js/src/nips/nip34.rs +++ b/bindings/nostr-sdk-js/src/protocol/nips/nip34.rs @@ -4,11 +4,11 @@ use core::ops::Deref; -use nostr::prelude::*; +use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; -use crate::key::JsPublicKey; -use crate::nips::nip01::JsCoordinate; +use crate::protocol::key::JsPublicKey; +use crate::protocol::nips::nip01::JsCoordinate; /// Git Repository Announcement /// diff --git a/bindings/nostr-js/src/nips/nip44.rs b/bindings/nostr-sdk-js/src/protocol/nips/nip44.rs similarity index 92% rename from bindings/nostr-js/src/nips/nip44.rs rename to bindings/nostr-sdk-js/src/protocol/nips/nip44.rs index 4ebe1a4e8..8e3ea2d86 100644 --- a/bindings/nostr-js/src/nips/nip44.rs +++ b/bindings/nostr-sdk-js/src/protocol/nips/nip44.rs @@ -4,11 +4,11 @@ use std::ops::Deref; -use nostr::nips::nip44::{self, Version}; +use nostr_sdk::nips::nip44::{self, Version}; use wasm_bindgen::prelude::*; use crate::error::{into_err, Result}; -use crate::key::{JsPublicKey, JsSecretKey}; +use crate::protocol::key::{JsPublicKey, JsSecretKey}; #[wasm_bindgen(js_name = NIP44Version)] pub enum JsNIP44Version { diff --git a/bindings/nostr-js/src/nips/nip46.rs b/bindings/nostr-sdk-js/src/protocol/nips/nip46.rs similarity index 98% rename from bindings/nostr-js/src/nips/nip46.rs rename to bindings/nostr-sdk-js/src/protocol/nips/nip46.rs index b13c6bfc7..d81093b3d 100644 --- a/bindings/nostr-js/src/nips/nip46.rs +++ b/bindings/nostr-sdk-js/src/protocol/nips/nip46.rs @@ -4,7 +4,7 @@ use core::ops::Deref; -use nostr::prelude::*; +use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; use crate::error::{into_err, Result}; diff --git a/bindings/nostr-js/src/nips/nip47.rs b/bindings/nostr-sdk-js/src/protocol/nips/nip47.rs similarity index 99% rename from bindings/nostr-js/src/nips/nip47.rs rename to bindings/nostr-sdk-js/src/protocol/nips/nip47.rs index 1c7b27e6f..800a0920c 100644 --- a/bindings/nostr-js/src/nips/nip47.rs +++ b/bindings/nostr-sdk-js/src/protocol/nips/nip47.rs @@ -5,12 +5,12 @@ use core::ops::Deref; use core::str::FromStr; -use nostr::prelude::*; +use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; use crate::error::{into_err, Result}; -use crate::key::{JsPublicKey, JsSecretKey}; -use crate::types::time::JsTimestamp; +use crate::protocol::key::{JsPublicKey, JsSecretKey}; +use crate::protocol::types::time::JsTimestamp; /// NIP47 Response Error codes #[wasm_bindgen(js_name = Nip47ErrorCode)] diff --git a/bindings/nostr-js/src/nips/nip49.rs b/bindings/nostr-sdk-js/src/protocol/nips/nip49.rs similarity index 96% rename from bindings/nostr-js/src/nips/nip49.rs rename to bindings/nostr-sdk-js/src/protocol/nips/nip49.rs index 3ff22fb8b..234654b3b 100644 --- a/bindings/nostr-js/src/nips/nip49.rs +++ b/bindings/nostr-sdk-js/src/protocol/nips/nip49.rs @@ -4,12 +4,12 @@ use std::ops::Deref; -use nostr::nips::nip49::{EncryptedSecretKey, KeySecurity, Version}; -use nostr::{FromBech32, ToBech32}; +use nostr_sdk::nips::nip49::{EncryptedSecretKey, KeySecurity, Version}; +use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; use crate::error::{into_err, Result}; -use crate::key::JsSecretKey; +use crate::protocol::key::JsSecretKey; /// Encrypted Secret Key version (NIP49) #[wasm_bindgen(js_name = EncryptedSecretKeyVersion)] diff --git a/bindings/nostr-js/src/nips/nip51.rs b/bindings/nostr-sdk-js/src/protocol/nips/nip51.rs similarity index 95% rename from bindings/nostr-js/src/nips/nip51.rs rename to bindings/nostr-sdk-js/src/protocol/nips/nip51.rs index a75371968..2b4d5b81d 100644 --- a/bindings/nostr-js/src/nips/nip51.rs +++ b/bindings/nostr-sdk-js/src/protocol/nips/nip51.rs @@ -1,22 +1,17 @@ // Copyright (c) 2023-2024 Rust Nostr Developers // Distributed under the MIT software license -//! NIP51 -//! -//! - use std::ops::Deref; use std::str::FromStr; use js_sys::Error; -use nostr::nips::nip51::{ArticlesCuration, Bookmarks, Emojis, Interests, MuteList}; -use nostr::{UncheckedUrl, Url}; +use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; use super::nip01::JsCoordinate; use crate::error::{into_err, Result}; -use crate::event::JsEventId; -use crate::key::JsPublicKey; +use crate::protocol::event::JsEventId; +use crate::protocol::key::JsPublicKey; /// Things the user doesn't want to see in their feeds /// diff --git a/bindings/nostr-js/src/nips/nip53.rs b/bindings/nostr-sdk-js/src/protocol/nips/nip53.rs similarity index 96% rename from bindings/nostr-js/src/nips/nip53.rs rename to bindings/nostr-sdk-js/src/protocol/nips/nip53.rs index cdc879ba6..3aada12f4 100644 --- a/bindings/nostr-js/src/nips/nip53.rs +++ b/bindings/nostr-sdk-js/src/protocol/nips/nip53.rs @@ -3,12 +3,11 @@ use std::ops::Deref; -use nostr::nips::nip53::{LiveEvent, LiveEventHost, LiveEventStatus}; -use nostr::{ImageDimensions, PublicKey, UncheckedUrl}; +use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; -use crate::key::JsPublicKey; -use crate::types::image::JsImageDimensions; +use crate::protocol::key::JsPublicKey; +use crate::protocol::types::image::JsImageDimensions; #[wasm_bindgen(js_name = Image)] pub struct JsImage { diff --git a/bindings/nostr-js/src/nips/nip56.rs b/bindings/nostr-sdk-js/src/protocol/nips/nip56.rs similarity index 97% rename from bindings/nostr-js/src/nips/nip56.rs rename to bindings/nostr-sdk-js/src/protocol/nips/nip56.rs index 52e7f3fda..c356e03a9 100644 --- a/bindings/nostr-js/src/nips/nip56.rs +++ b/bindings/nostr-sdk-js/src/protocol/nips/nip56.rs @@ -2,7 +2,7 @@ // Copyright (c) 2023-2024 Rust Nostr Developers // Distributed under the MIT software license -use nostr::prelude::*; +use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; /// Report diff --git a/bindings/nostr-js/src/nips/nip57.rs b/bindings/nostr-sdk-js/src/protocol/nips/nip57.rs similarity index 97% rename from bindings/nostr-js/src/nips/nip57.rs rename to bindings/nostr-sdk-js/src/protocol/nips/nip57.rs index 2f1db31b0..9b659bfd5 100644 --- a/bindings/nostr-js/src/nips/nip57.rs +++ b/bindings/nostr-sdk-js/src/protocol/nips/nip57.rs @@ -4,13 +4,13 @@ use std::ops::Deref; -use nostr::prelude::*; +use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; use super::nip01::JsCoordinate; use crate::error::{into_err, Result}; -use crate::event::{JsEvent, JsEventId}; -use crate::key::{JsKeys, JsPublicKey, JsSecretKey}; +use crate::protocol::event::{JsEvent, JsEventId}; +use crate::protocol::key::{JsKeys, JsPublicKey, JsSecretKey}; #[wasm_bindgen(js_name = ZapType)] pub enum JsZapType { diff --git a/bindings/nostr-js/src/nips/nip59.rs b/bindings/nostr-sdk-js/src/protocol/nips/nip59.rs similarity index 90% rename from bindings/nostr-js/src/nips/nip59.rs rename to bindings/nostr-sdk-js/src/protocol/nips/nip59.rs index 9a51657b1..72b574ee4 100644 --- a/bindings/nostr-js/src/nips/nip59.rs +++ b/bindings/nostr-sdk-js/src/protocol/nips/nip59.rs @@ -4,12 +4,12 @@ use core::ops::Deref; -use nostr::prelude::*; +use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; use crate::error::{into_err, Result}; -use crate::event::{JsEvent, JsUnsignedEvent}; -use crate::key::{JsKeys, JsPublicKey}; +use crate::protocol::event::{JsEvent, JsUnsignedEvent}; +use crate::protocol::key::{JsKeys, JsPublicKey}; /// Unwrapped Gift Wrap /// diff --git a/bindings/nostr-js/src/nips/nip65.rs b/bindings/nostr-sdk-js/src/protocol/nips/nip65.rs similarity index 95% rename from bindings/nostr-js/src/nips/nip65.rs rename to bindings/nostr-sdk-js/src/protocol/nips/nip65.rs index 565916f96..f33d4a97f 100644 --- a/bindings/nostr-js/src/nips/nip65.rs +++ b/bindings/nostr-sdk-js/src/protocol/nips/nip65.rs @@ -3,10 +3,10 @@ use std::ops::Deref; -use nostr::prelude::*; +use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; -use crate::event::JsEvent; +use crate::protocol::event::JsEvent; #[derive(Clone, Copy)] #[wasm_bindgen(js_name = RelayMetadata)] diff --git a/bindings/nostr-js/src/nips/nip90.rs b/bindings/nostr-sdk-js/src/protocol/nips/nip90.rs similarity index 97% rename from bindings/nostr-js/src/nips/nip90.rs rename to bindings/nostr-sdk-js/src/protocol/nips/nip90.rs index d1aed6b3f..26952bfb8 100644 --- a/bindings/nostr-js/src/nips/nip90.rs +++ b/bindings/nostr-sdk-js/src/protocol/nips/nip90.rs @@ -3,10 +3,10 @@ use std::ops::Deref; -use nostr::prelude::*; +use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; -use crate::event::JsEvent; +use crate::protocol::event::JsEvent; #[wasm_bindgen(js_name = DataVendingMachineStatus)] pub enum JsDataVendingMachineStatus { diff --git a/bindings/nostr-js/src/nips/nip94.rs b/bindings/nostr-sdk-js/src/protocol/nips/nip94.rs similarity index 94% rename from bindings/nostr-js/src/nips/nip94.rs rename to bindings/nostr-sdk-js/src/protocol/nips/nip94.rs index 8405072d8..e67ec66a6 100644 --- a/bindings/nostr-js/src/nips/nip94.rs +++ b/bindings/nostr-sdk-js/src/protocol/nips/nip94.rs @@ -4,13 +4,12 @@ use std::ops::Deref; use std::str::FromStr; -use nostr::hashes::sha256::Hash as Sha256Hash; -use nostr::nips::nip94::FileMetadata; -use nostr::Url; +use nostr_sdk::hashes::sha256::Hash as Sha256Hash; +use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; use crate::error::{into_err, Result}; -use crate::types::image::JsImageDimensions; +use crate::protocol::types::image::JsImageDimensions; #[wasm_bindgen(js_name = Aes256Gcm)] pub struct JsAes256Gcm { diff --git a/bindings/nostr-js/src/nips/nip98.rs b/bindings/nostr-sdk-js/src/protocol/nips/nip98.rs similarity index 98% rename from bindings/nostr-js/src/nips/nip98.rs rename to bindings/nostr-sdk-js/src/protocol/nips/nip98.rs index 31932f3e5..b41cbfea0 100644 --- a/bindings/nostr-js/src/nips/nip98.rs +++ b/bindings/nostr-sdk-js/src/protocol/nips/nip98.rs @@ -3,7 +3,7 @@ use std::ops::Deref; -use nostr::prelude::*; +use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; #[wasm_bindgen(js_name = HttpMethod)] diff --git a/bindings/nostr-js/src/types/contact.rs b/bindings/nostr-sdk-js/src/protocol/types/contact.rs similarity index 95% rename from bindings/nostr-js/src/types/contact.rs rename to bindings/nostr-sdk-js/src/protocol/types/contact.rs index d3cb980a7..20ca9039f 100644 --- a/bindings/nostr-js/src/types/contact.rs +++ b/bindings/nostr-sdk-js/src/protocol/types/contact.rs @@ -4,10 +4,10 @@ use std::ops::Deref; -use nostr::prelude::*; +use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; -use crate::key::JsPublicKey; +use crate::protocol::key::JsPublicKey; #[wasm_bindgen(js_name = Contact)] pub struct JsContact { diff --git a/bindings/nostr-js/src/types/filter.rs b/bindings/nostr-sdk-js/src/protocol/types/filter.rs similarity index 98% rename from bindings/nostr-js/src/types/filter.rs rename to bindings/nostr-sdk-js/src/protocol/types/filter.rs index a2a2a6c9d..5bcfcc3e7 100644 --- a/bindings/nostr-js/src/types/filter.rs +++ b/bindings/nostr-sdk-js/src/protocol/types/filter.rs @@ -4,14 +4,14 @@ use core::ops::Deref; -use nostr::prelude::*; +use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; use crate::error::{into_err, Result}; -use crate::event::{JsEvent, JsEventId, JsKind}; -use crate::key::JsPublicKey; -use crate::nips::nip01::JsCoordinate; -use crate::types::JsTimestamp; +use crate::protocol::event::{JsEvent, JsEventId, JsKind}; +use crate::protocol::key::JsPublicKey; +use crate::protocol::nips::nip01::JsCoordinate; +use crate::protocol::types::JsTimestamp; #[wasm_bindgen(js_name = Alphabet)] pub enum JsAlphabet { diff --git a/bindings/nostr-js/src/types/image.rs b/bindings/nostr-sdk-js/src/protocol/types/image.rs similarity index 98% rename from bindings/nostr-js/src/types/image.rs rename to bindings/nostr-sdk-js/src/protocol/types/image.rs index cca329cae..a278a7044 100644 --- a/bindings/nostr-js/src/types/image.rs +++ b/bindings/nostr-sdk-js/src/protocol/types/image.rs @@ -2,7 +2,7 @@ // Copyright (c) 2023-2024 Rust Nostr Developers // Distributed under the MIT software license -use nostr::prelude::*; +use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; #[wasm_bindgen(js_name = Thumbnails)] diff --git a/bindings/nostr-js/src/types/metadata.rs b/bindings/nostr-sdk-js/src/protocol/types/metadata.rs similarity index 99% rename from bindings/nostr-js/src/types/metadata.rs rename to bindings/nostr-sdk-js/src/protocol/types/metadata.rs index 32f058e0b..89706a113 100644 --- a/bindings/nostr-js/src/types/metadata.rs +++ b/bindings/nostr-sdk-js/src/protocol/types/metadata.rs @@ -4,7 +4,7 @@ use std::ops::Deref; -use nostr::prelude::*; +use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; use crate::error::{into_err, Result}; diff --git a/bindings/nostr-js/src/types/mod.rs b/bindings/nostr-sdk-js/src/protocol/types/mod.rs similarity index 100% rename from bindings/nostr-js/src/types/mod.rs rename to bindings/nostr-sdk-js/src/protocol/types/mod.rs diff --git a/bindings/nostr-js/src/types/time.rs b/bindings/nostr-sdk-js/src/protocol/types/time.rs similarity index 97% rename from bindings/nostr-js/src/types/time.rs rename to bindings/nostr-sdk-js/src/protocol/types/time.rs index 84d243953..183c729da 100644 --- a/bindings/nostr-js/src/types/time.rs +++ b/bindings/nostr-sdk-js/src/protocol/types/time.rs @@ -4,7 +4,7 @@ use std::ops::Deref; -use nostr::prelude::*; +use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; #[derive(Clone, Copy)] diff --git a/bindings/nostr-js/src/util.rs b/bindings/nostr-sdk-js/src/protocol/util.rs similarity index 88% rename from bindings/nostr-js/src/util.rs rename to bindings/nostr-sdk-js/src/protocol/util.rs index c2d557ced..e2287eba0 100644 --- a/bindings/nostr-js/src/util.rs +++ b/bindings/nostr-sdk-js/src/protocol/util.rs @@ -4,10 +4,10 @@ use std::ops::Deref; -use nostr::prelude::*; +use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; -use crate::key::{JsPublicKey, JsSecretKey}; +use crate::protocol::key::{JsPublicKey, JsSecretKey}; /// Generate shared key /// diff --git a/bindings/nostr-sdk-js/src/relay/filtering.rs b/bindings/nostr-sdk-js/src/relay/filtering.rs index a5f59a826..ef42d7145 100644 --- a/bindings/nostr-sdk-js/src/relay/filtering.rs +++ b/bindings/nostr-sdk-js/src/relay/filtering.rs @@ -4,11 +4,12 @@ use std::ops::Deref; -use nostr_js::event::JsEventId; -use nostr_js::key::JsPublicKey; use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; +use crate::protocol::event::JsEventId; +use crate::protocol::key::JsPublicKey; + #[wasm_bindgen(js_name = RelayFilteringMode)] pub enum JsRelayFilteringMode { /// Only the matching values will be allowed diff --git a/bindings/nostr-sdk-js/src/relay/mod.rs b/bindings/nostr-sdk-js/src/relay/mod.rs index c91c053ab..648f6f044 100644 --- a/bindings/nostr-sdk-js/src/relay/mod.rs +++ b/bindings/nostr-sdk-js/src/relay/mod.rs @@ -4,11 +4,6 @@ use std::ops::Deref; -use nostr_js::error::{into_err, Result}; -use nostr_js::event::{JsEvent, JsEventId}; -use nostr_js::message::JsClientMessage; -use nostr_js::nips::nip11::JsRelayInformationDocument; -use nostr_js::types::JsFilter; use nostr_sdk::prelude::*; use wasm_bindgen::prelude::*; @@ -24,6 +19,11 @@ use self::options::{ }; use crate::database::JsEvents; use crate::duration::JsDuration; +use crate::error::{into_err, Result}; +use crate::protocol::event::{JsEvent, JsEventId}; +use crate::protocol::message::JsClientMessage; +use crate::protocol::nips::nip11::JsRelayInformationDocument; +use crate::protocol::types::JsFilter; #[derive(Clone)] #[wasm_bindgen(js_name = Reconciliation)] diff --git a/contrib/scripts/check-bindings.sh b/contrib/scripts/check-bindings.sh index 09b7d7f38..6454cb909 100755 --- a/contrib/scripts/check-bindings.sh +++ b/contrib/scripts/check-bindings.sh @@ -6,7 +6,6 @@ set -euo pipefail buildargs=( "-p nostr-ffi" "-p nostr-sdk-ffi" - "-p nostr-js --target wasm32-unknown-unknown" "-p nostr-sdk-js --target wasm32-unknown-unknown" ) @@ -23,4 +22,4 @@ for arg in "${buildargs[@]}"; do cargo clippy $arg -- -D warnings echo -done \ No newline at end of file +done