-
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
820 additions
and
40 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -830,7 +830,7 @@ impl NostrWalletConnectURI { | |
Url::parse(&relay_url)?, | ||
**random_secret_key, | ||
lud16, | ||
)? | ||
) | ||
.into()) | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,5 @@ pub mod nip19; | |
pub mod nip26; | ||
pub mod nip44; | ||
pub mod nip46; | ||
pub mod nip47; | ||
pub mod nip57; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright (c) 2022-2023 Yuki Kishimoto | ||
// Copyright (c) 2023-2024 Rust Nostr Developers | ||
// Distributed under the MIT software license | ||
|
||
use core::ops::Deref; | ||
use core::str::FromStr; | ||
|
||
use nostr::nips::nip47::NostrWalletConnectURI; | ||
use nostr::Url; | ||
use wasm_bindgen::prelude::*; | ||
|
||
use crate::error::{into_err, Result}; | ||
use crate::key::{JsPublicKey, JsSecretKey}; | ||
|
||
#[wasm_bindgen(js_name = NostrWalletConnectURI)] | ||
pub struct JsNostrWalletConnectURI { | ||
inner: NostrWalletConnectURI, | ||
} | ||
|
||
impl Deref for JsNostrWalletConnectURI { | ||
type Target = NostrWalletConnectURI; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.inner | ||
} | ||
} | ||
|
||
#[wasm_bindgen(js_class = NostrWalletConnectURI)] | ||
impl JsNostrWalletConnectURI { | ||
/// Create new Nostr Wallet Connect URI | ||
pub fn new( | ||
public_key: &JsPublicKey, | ||
relay_url: &str, | ||
random_secret_key: &JsSecretKey, | ||
lud16: Option<String>, | ||
) -> Result<JsNostrWalletConnectURI> { | ||
let relay_url = Url::parse(relay_url).map_err(into_err)?; | ||
Ok(Self { | ||
inner: NostrWalletConnectURI::new(**public_key, relay_url, **random_secret_key, lud16), | ||
}) | ||
} | ||
|
||
/// Parse | ||
pub fn parse(uri: &str) -> Result<JsNostrWalletConnectURI> { | ||
Ok(Self { | ||
inner: NostrWalletConnectURI::from_str(uri).map_err(into_err)?, | ||
}) | ||
} | ||
|
||
/// App Pubkey | ||
#[wasm_bindgen(js_name = publicKey)] | ||
pub fn public_key(&self) -> JsPublicKey { | ||
self.inner.public_key.into() | ||
} | ||
|
||
/// URL of the relay of choice where the `App` is connected and the `Signer` must send and listen for messages. | ||
#[wasm_bindgen(js_name = relayUrl)] | ||
pub fn relay_url(&self) -> String { | ||
self.inner.relay_url.to_string() | ||
} | ||
|
||
/// 32-byte randomly generated hex encoded string | ||
pub fn secret(&self) -> JsSecretKey { | ||
self.inner.secret.into() | ||
} | ||
|
||
/// A lightning address that clients can use to automatically setup the lud16 field on the user's profile if they have none configured. | ||
pub fn lud16(&self) -> Option<String> { | ||
self.inner.lud16.clone() | ||
} | ||
|
||
#[wasm_bindgen(js_name = asString)] | ||
pub fn as_string(&self) -> String { | ||
self.inner.to_string() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) 2022-2023 Yuki Kishimoto | ||
// Copyright (c) 2023-2024 Rust Nostr Developers | ||
// Distributed under the MIT software license | ||
|
||
use nostr::nips::nip57::ZapType; | ||
use wasm_bindgen::prelude::*; | ||
|
||
#[wasm_bindgen(js_name = ZapType)] | ||
pub enum JsZapType { | ||
/// Public | ||
Public, | ||
/// Private | ||
Private, | ||
/// Anonymous | ||
Anonymous, | ||
} | ||
|
||
impl From<JsZapType> for ZapType { | ||
fn from(value: JsZapType) -> Self { | ||
match value { | ||
JsZapType::Public => Self::Public, | ||
JsZapType::Private => Self::Private, | ||
JsZapType::Anonymous => Self::Anonymous, | ||
} | ||
} | ||
} | ||
|
||
impl From<ZapType> for JsZapType { | ||
fn from(value: ZapType) -> Self { | ||
match value { | ||
ZapType::Public => Self::Public, | ||
ZapType::Private => Self::Private, | ||
ZapType::Anonymous => Self::Anonymous, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// Copyright (c) 2022-2023 Yuki Kishimoto | ||
// Copyright (c) 2023-2024 Rust Nostr Developers | ||
// Distributed under the MIT software license | ||
|
||
use core::ops::Deref; | ||
|
||
use nostr_js::event::JsEventId; | ||
use nostr_js::key::JsPublicKey; | ||
use nostr_js::nips::nip47::JsNostrWalletConnectURI; | ||
use nostr_js::nips::nip57::JsZapType; | ||
use nostr_sdk::client::{ClientZapper, ZapDetails, ZapEntity}; | ||
use wasm_bindgen::prelude::*; | ||
use webln_js::JsWebLN; | ||
|
||
/// Zap entity | ||
#[wasm_bindgen(js_name = ZapEntity)] | ||
pub struct JsZapEntity { | ||
inner: ZapEntity, | ||
} | ||
|
||
impl Deref for JsZapEntity { | ||
type Target = ZapEntity; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.inner | ||
} | ||
} | ||
|
||
#[wasm_bindgen(js_class = ZapEntity)] | ||
impl JsZapEntity { | ||
pub fn event(event_id: &JsEventId) -> Self { | ||
Self { | ||
inner: ZapEntity::Event(**event_id), | ||
} | ||
} | ||
|
||
#[wasm_bindgen(js_name = publicKey)] | ||
pub fn public_key(public_key: &JsPublicKey) -> Self { | ||
Self { | ||
inner: ZapEntity::PublicKey(**public_key), | ||
} | ||
} | ||
} | ||
|
||
/// Client Zapper | ||
#[wasm_bindgen(js_name = ClientZapper)] | ||
pub struct JsClientZapper { | ||
inner: ClientZapper, | ||
} | ||
|
||
impl Deref for JsClientZapper { | ||
type Target = ClientZapper; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.inner | ||
} | ||
} | ||
|
||
#[wasm_bindgen(js_class = ClientZapper)] | ||
impl JsClientZapper { | ||
pub fn webln(instance: &JsWebLN) -> Self { | ||
Self { | ||
inner: ClientZapper::WebLN(instance.deref().clone()), | ||
} | ||
} | ||
|
||
pub fn nwc(uri: &JsNostrWalletConnectURI) -> Self { | ||
Self { | ||
inner: ClientZapper::NWC(uri.deref().clone()), | ||
} | ||
} | ||
} | ||
|
||
/// Zap Details | ||
#[wasm_bindgen(js_name = ZapDetails)] | ||
pub struct JsZapDetails { | ||
inner: ZapDetails, | ||
} | ||
|
||
impl From<JsZapDetails> for ZapDetails { | ||
fn from(value: JsZapDetails) -> Self { | ||
value.inner | ||
} | ||
} | ||
|
||
#[wasm_bindgen(js_class = ZapDetails)] | ||
impl JsZapDetails { | ||
/// Create new Zap Details | ||
/// | ||
/// **Note: `private` zaps are not currently supported here!** | ||
#[wasm_bindgen(constructor)] | ||
pub fn new(zap_type: JsZapType) -> Self { | ||
Self { | ||
inner: ZapDetails::new(zap_type.into()), | ||
} | ||
} | ||
|
||
/// Add message | ||
pub fn message(self, message: String) -> Self { | ||
Self { | ||
inner: self.inner.message(message), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.