Skip to content

Commit 48fb443

Browse files
committed
Init nostr-browser-signer-proxy
Reviewed-by: Awiteb <a@4rs.nl> Signed-off-by: Yuki Kishimoto <yukikishimoto@protonmail.com>
1 parent baeba7b commit 48fb443

File tree

15 files changed

+972
-14
lines changed

15 files changed

+972
-14
lines changed

Cargo.lock

Lines changed: 45 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ members = [
2020

2121
# Signers
2222
"signer/nostr-browser-signer",
23+
"signer/nostr-browser-signer-proxy",
2324
"signer/nostr-connect",
2425
]
2526
default-members = ["crates/*"]

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The project is split up into several crates in the `crates/` directory:
88
* [**nostr**](./crates/nostr): Rust implementation of Nostr protocol
99
* Signers
1010
* [**nostr-browser-signer**](./signer/nostr-browser-signer): Nostr Browser signer implementation (NIP-07)
11+
* [**nostr-browser-signer-proxy**](./signer/nostr-browser-signer-proxy): Proxy for using the Nostr Browser signer (NIP-07) in native applications
1112
* [**nostr-connect**](./signer/nostr-connect): Nostr Connect (NIP-46)
1213
* [**nostr-database**](./database/nostr-database): Events database abstraction and in-memory implementation
1314
* [**nostr-lmdb**](./database/nostr-lmdb): LMDB storage backend

contrib/scripts/check-crates.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ buildargs=(
3737
"-p nostr --no-default-features --features alloc" # Only alloc feature
3838
"-p nostr --no-default-features --features alloc,all-nips" # alloc + all-nips
3939
"-p nostr-browser-signer --target wasm32-unknown-unknown"
40+
"-p nostr-browser-signer-proxy"
4041
"-p nostr-blossom"
4142
"-p nostr-http-file-storage"
4243
"-p nostr-database"

contrib/scripts/release.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ set -euo pipefail
55
args=(
66
"-p nostr"
77
"-p nostr-browser-signer"
8+
"-p nostr-browser-signer-proxy"
89
"-p nostr-database"
910
"-p nostr-lmdb"
1011
"-p nostr-mls-storage"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Changelog
2+
3+
<!-- All notable changes to this project will be documented in this file. -->
4+
5+
<!-- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), -->
6+
<!-- and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -->
7+
8+
<!-- Template
9+
10+
## Unreleased
11+
12+
### Breaking changes
13+
14+
### Changed
15+
16+
### Added
17+
18+
### Fixed
19+
20+
### Removed
21+
22+
### Deprecated
23+
24+
-->
25+
26+
## Unreleased
27+
28+
First release.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[package]
2+
name = "nostr-browser-signer-proxy"
3+
version = "0.1.0"
4+
edition = "2021"
5+
description = "Proxy to use Nostr Browser signer (NIP-07) in native applications."
6+
authors.workspace = true
7+
homepage.workspace = true
8+
repository.workspace = true
9+
license.workspace = true
10+
readme = "README.md"
11+
rust-version.workspace = true
12+
keywords = ["nostr", "nip07", "browser", "signer", "proxy"]
13+
14+
[dependencies]
15+
bytes = "1.10"
16+
http-body-util = "0.1"
17+
hyper = { version = "1.6", features = ["server", "http1"] }
18+
hyper-util = { version = "0.1", features = ["tokio"] }
19+
nostr = { workspace = true, features = ["std"] }
20+
serde = { workspace = true, features = ["std", "derive"] }
21+
serde_json = { workspace = true, features = ["std"] }
22+
tokio = { workspace = true, features = ["macros", "net", "rt", "rt-multi-thread", "sync", "time"] }
23+
tracing = { workspace = true, features = ["std"] }
24+
uuid = { version = "1.17", features = ["serde", "v4"] }
25+
26+
[dev-dependencies]
27+
nostr = { workspace = true, features = ["nip59"] }
28+
tokio = { workspace = true, features = ["signal"] }
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Browser signer proxy (NIP-07)
2+
3+
## Description
4+
5+
Proxy to use Nostr Browser signer ([NIP-07](https://github.com/nostr-protocol/nips/blob/master/07.md)) in native applications.
6+
7+
## Changelog
8+
9+
All notable changes to this library are documented in the [CHANGELOG.md](CHANGELOG.md).
10+
11+
## State
12+
13+
**This library is in an ALPHA state**, things that are implemented generally work but the API will change in breaking ways.
14+
15+
## Donations
16+
17+
`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).
18+
19+
## License
20+
21+
This project is distributed under the MIT software license - see the [LICENSE](../../LICENSE) file for details
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (c) 2022-2023 Yuki Kishimoto
2+
// Copyright (c) 2023-2025 Rust Nostr Developers
3+
// Distributed under the MIT software license
4+
5+
use std::time::Duration;
6+
7+
use nostr_browser_signer_proxy::prelude::*;
8+
use tokio::{signal, time};
9+
10+
#[tokio::main]
11+
async fn main() -> Result<()> {
12+
let proxy = BrowserSignerProxy::new(8080);
13+
14+
proxy.start().await?;
15+
16+
println!("Url: {}", proxy.url());
17+
18+
// Give time to open the webpage
19+
time::sleep(Duration::from_secs(10)).await;
20+
21+
// Get public key
22+
let public_key = proxy.get_public_key().await?;
23+
println!("Public key: {}", public_key);
24+
25+
// Sign event
26+
let event = EventBuilder::text_note("Testing browser signer proxy")
27+
.sign(&proxy)
28+
.await?;
29+
println!("Event: {}", event.as_json());
30+
31+
// Build a gift wrap
32+
let receiver =
33+
PublicKey::parse("npub1drvpzev3syqt0kjrls50050uzf25gehpz9vgdw08hvex7e0vgfeq0eseet")?;
34+
let rumor = EventBuilder::new(Kind::Custom(123), "test").build(public_key);
35+
let gift_wrap = EventBuilder::gift_wrap(&proxy, &receiver, rumor, []).await?;
36+
println!("Gift wrap: {}", gift_wrap.as_json());
37+
38+
// Keep up the program
39+
signal::ctrl_c().await?;
40+
41+
Ok(())
42+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>NIP-07 Proxy</title>
5+
<link rel="stylesheet" href="style.css">
6+
</head>
7+
<body>
8+
<div class="container">
9+
<h1>NIP-07 Proxy</h1>
10+
<p>This page acts as a proxy between your native application and the NIP-07 browser extension.</p>
11+
<div class="status-box">
12+
<strong>Status:</strong> <span id="status">Checking...</span>
13+
</div>
14+
<p><small>Keep this tab open while using your application. The page will automatically poll for requests from your native app.</small></p>
15+
16+
<h3>Debug Info</h3>
17+
<p><small>Check the browser console (F12) for detailed logs.</small></p>
18+
</div>
19+
20+
<script src="proxy.js"></script>
21+
</body>
22+
</html>

0 commit comments

Comments
 (0)