pub struct NwcService { /* private fields */ }Expand description
A NIP-47 Nostr Wallet Connect wallet service bound to a CDK wallet.
Create one with NwcService::create (new connection) or
NwcService::restore (existing connection from a persisted client
secret), call NwcService::connection_uri to obtain the URI for the
Nostr app, then NwcService::start to begin servicing requests.
Implementations§
Source§impl NwcService
impl NwcService
Sourcepub fn create(
wallet: Arc<Wallet>,
relays: Vec<String>,
service_secret_key: String,
max_payment_msat: Option<u64>,
) -> Result<Self, FfiError>
pub fn create( wallet: Arc<Wallet>, relays: Vec<String>, service_secret_key: String, max_payment_msat: Option<u64>, ) -> Result<Self, FfiError>
Create a new wallet service with a freshly generated client connection.
§Arguments
wallet- The CDK wallet that backs the service.relays- Relay URLs the service connects to and listens on.service_secret_key- Secret key of the wallet service (the signer). Accepts hex or bech32nsec. Derive a stable one from the wallet seed withnwc_derive_service_secret_key_from_seed.max_payment_msat- Optional cap (in millisatoshis) on any singlepay_invoicerequest.
§Errors
Returns an error if a key or relay URL is invalid, or no relays are given.
Sourcepub fn restore(
wallet: Arc<Wallet>,
relays: Vec<String>,
service_secret_key: String,
client_secret_key: String,
max_payment_msat: Option<u64>,
) -> Result<Self, FfiError>
pub fn restore( wallet: Arc<Wallet>, relays: Vec<String>, service_secret_key: String, client_secret_key: String, max_payment_msat: Option<u64>, ) -> Result<Self, FfiError>
Restore a wallet service for an existing connection.
Use this to rebuild a service after a restart from a persisted client secret, so the previously issued connection URI keeps working.
§Arguments
client_secret_key- The client secret from the original connection URI (hex ornsec).
See Self::create for the other arguments.
§Errors
Returns an error if a key or relay URL is invalid, or no relays are given.
Sourcepub fn connection_uri(&self) -> String
pub fn connection_uri(&self) -> String
The nostr+walletconnect:// connection URI to hand to the Nostr app.
Sourcepub fn service_pubkey(&self) -> String
pub fn service_pubkey(&self) -> String
Hex-encoded public key of the wallet service (advertised in the URI).
Sourcepub fn client_pubkey(&self) -> String
pub fn client_pubkey(&self) -> String
Hex-encoded public key of the authorized client.
Sourcepub async fn start(&self) -> Result<(), FfiError>
pub async fn start(&self) -> Result<(), FfiError>
Start servicing requests in the background.
Connects to the relays, publishes the info event, and begins answering
commands. Returns immediately; the service runs until Self::stop is
called. Per-request failures are answered with NIP-47 error responses
and logged rather than surfaced here.
§Errors
Returns an error if the service is already running.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Whether the background service is currently running.
Trait Implementations§
Source§impl Drop for NwcService
impl Drop for NwcService
Source§impl<UT> LiftRef<UT> for NwcService
impl<UT> LiftRef<UT> for NwcService
type LiftType = Arc<NwcService>
Source§impl<UT> LowerError<UT> for NwcService
impl<UT> LowerError<UT> for NwcService
Source§fn lower_error(obj: Self) -> RustBuffer
fn lower_error(obj: Self) -> RustBuffer
Source§impl<UT> LowerReturn<UT> for NwcService
impl<UT> LowerReturn<UT> for NwcService
Source§type ReturnType = <Arc<NwcService> as LowerReturn<UniFfiTag>>::ReturnType
type ReturnType = <Arc<NwcService> as LowerReturn<UniFfiTag>>::ReturnType
Source§fn lower_return(obj: Self) -> Result<Self::ReturnType, RustCallError>
fn lower_return(obj: Self) -> Result<Self::ReturnType, RustCallError>
Source§fn handle_failed_lift(
error: LiftArgsError,
) -> Result<Self::ReturnType, RustCallError>
fn handle_failed_lift( error: LiftArgsError, ) -> Result<Self::ReturnType, RustCallError>
Source§impl<UT> TypeId<UT> for NwcService
impl<UT> TypeId<UT> for NwcService
Auto Trait Implementations§
impl !Freeze for NwcService
impl !RefUnwindSafe for NwcService
impl !UnwindSafe for NwcService
impl Send for NwcService
impl Sync for NwcService
impl Unpin for NwcService
impl UnsafeUnpin for NwcService
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more