Skip to content

Commit

Permalink
Project import generated by Copybara.
Browse files Browse the repository at this point in the history
GitOrigin-RevId: e8ca93608cf9baae92f8d548828bbc214565fcb5
  • Loading branch information
Lightspark Eng authored and zhenlu committed Sep 28, 2023
1 parent 54ab2e5 commit 0a98df5
Show file tree
Hide file tree
Showing 41 changed files with 267 additions and 1,968 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ resolver = "2"
members = [
"lightspark",
"lightspark-remote-signing",
"uma",
"examples/*",
]
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ The Lightspark Rust SDK provides a convenient way to interact with the Lightspar
The rust-sdk consists of multiple crates that can be picked at your convenience:
- `lightspark`: The main crate that contains the SDK.
- `lightspark-remote-signing`: The SDK for handling remote signing webhook handler.
- `uma`: The UMA protocol implementation.
- `example`: Examples that shows you how to use the SDK.

## License
Expand Down
2 changes: 1 addition & 1 deletion copy.bara.sky
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ core.workflow(

origin_files = glob(
["python-sdk/**", "copy.bara.sky"],
exclude = ["python-sdk/examples/internal_example.py"],
exclude = ["python-sdk/examples/internal_example.py", "python-sdk/RELEASE-internal.md"],
),

authoring = authoring.pass_thru("Lightspark Eng <[email protected]>"),
Expand Down
1 change: 0 additions & 1 deletion examples/lightspark-remote-signing-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
lightspark = "0.6.3"
lightspark-remote-signing = { path = "../../lightspark-remote-signing" }
tokio = "1.32.0"
actix-web = "4.4.0"
Expand Down
14 changes: 10 additions & 4 deletions examples/lightspark-remote-signing-server/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use actix_web::{get, post, web, App, HttpRequest, HttpResponse, HttpServer, Responder};
use futures_util::StreamExt as _;
use lightspark::{
use lightspark_remote_signing::lightspark::{
key::Secp256k1SigningKey, request::auth_provider::AccountAuthProvider, webhooks::WebhookEvent,
};
use lightspark_remote_signing::{
Expand All @@ -24,14 +24,20 @@ async fn webhook_handler(
data: web::Data<config::Config>,
) -> impl Responder {
let headers = req.headers();
let signature = headers.get(lightspark::webhooks::SIGNATURE_HEADER).unwrap();
let signature = headers
.get(lightspark_remote_signing::lightspark::webhooks::SIGNATURE_HEADER)
.unwrap();
let mut bytes = web::BytesMut::new();
while let Some(item) = body.next().await {
bytes.extend_from_slice(&item.unwrap());
}

let auth = AccountAuthProvider::new(data.api_client_id.clone(), data.api_client_secret.clone());
let client = lightspark::client::LightsparkClient::<Secp256k1SigningKey>::new(auth).unwrap();
let client = lightspark_remote_signing::lightspark::client::LightsparkClient::<
Secp256k1SigningKey,
>::new(auth)
.unwrap();
// client.requester.set_base_url(data.api_endpoint.clone());

let seed = Seed::new(hex::decode(data.master_seed_hex.clone()).unwrap());
let signer =
Expand Down Expand Up @@ -63,7 +69,7 @@ async fn main() -> std::io::Result<()> {
.service(ping)
.service(webhook_handler)
})
.bind(("127.0.0.1", 8080))?
.bind(("0.0.0.0", 8080))?
.run()
.await
}
1 change: 1 addition & 0 deletions lightspark-remote-signing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
//! This crates also provides a `signer::LightsparkSigner` that can be used to sign transactions.
use std::fmt;

pub extern crate lightspark;
pub mod handler;
pub mod response;
pub mod signer;
Expand Down
4 changes: 4 additions & 0 deletions lightspark/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

# v0.7.0
- Refine requester.
- Separate crate into features.

# v0.6.4
- Remove all openssl dependencies.

Expand Down
16 changes: 13 additions & 3 deletions lightspark/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,26 @@
name = "lightspark"
description = "Lightspark Rust SDK"
authors = ["Lightspark Group, Inc. <[email protected]>"]
version = "0.6.4"
version = "0.7.0"
edition = "2021"
documentation = "https://app.lightspark.com/docs/sdk"
homepage = "https://www.lightspark.com/"
repository = "https://github.com/lightsparkdev/lightspark-rs"
license = "Apache-2.0"
readme = "README.md"

[features]
default = ["base", "objects", "client"]
base = []
objects = ["base"]
webhooks = ["base", "objects"]
client = ["base", "objects", "dep:reqwest"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
reqwest = { version = "0.11", default-features = false, features = ["blocking", "json"] }
reqwest = { version = "0.11", features = ["blocking", "json"], optional = true }
futures = "0.3"
tokio = { version = "1.12.0", features = ["full"] }
base64 = "0.21.0"
serde_json = "1.0.94"
serde = { version = "1.0.155", features = ["derive"] }
Expand All @@ -33,3 +39,7 @@ bitcoin = "0.30.1"
pbkdf2 = "0.12.2"
rsa = { version ="0.9.2", features = ["sha2"] }
cbc = "0.1.2"
async-trait = "0.1.73"

[dev-dependencies]
tokio = { version = "1.12.0", features = ["full"] }
4 changes: 2 additions & 2 deletions lightspark/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Lightspark Rust SDK - v0.6.4
# Lightspark Rust SDK - v0.7.0

The Lightspark Rust SDK provides a convenient way to interact with the Lightspark services from applications written in the Rust language.

***WARNING: This SDK is in version 0.6.0 (active development). It means that its APIs may not be fully stable. Please expect that changes to the APIs may happen until we move to v1.0.0.***
***WARNING: This SDK is in version 0.7.0 (active development). It means that its APIs may not be fully stable. Please expect that changes to the APIs may happen until we move to v1.0.0.***

## Documentation

Expand Down
41 changes: 41 additions & 0 deletions lightspark/examples/rk_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ use lightspark::{
async fn create_invoice() {
let api_id = std::env::var("RK_API_CLIENT_ID").unwrap();
let api_token = std::env::var("RK_API_CLIENT_SECRET").unwrap();
let endpoint = std::env::var("RK_API_ENDPOINT").unwrap();

let auth = AccountAuthProvider::new(api_id.to_string(), api_token.to_string());
let mut client = LightsparkClient::<Secp256k1SigningKey>::new(auth).unwrap();
client.requester.set_base_url(Some(endpoint));

let node_id = std::env::var("RK_NODE_ID").unwrap();

Expand Down Expand Up @@ -35,7 +37,46 @@ async fn create_invoice() {
println!("Payment response: {:?}", response.unwrap().id);
}

async fn test_payment() {
let api_id = std::env::var("RK_API_CLIENT_ID").unwrap();
let api_token = std::env::var("RK_API_CLIENT_SECRET").unwrap();
let endpoint = std::env::var("RK_API_ENDPOINT").unwrap();

let auth = AccountAuthProvider::new(api_id.to_string(), api_token.to_string());
let mut client = LightsparkClient::<Secp256k1SigningKey>::new(auth).unwrap();
client.requester.set_base_url(Some(endpoint));

let node_id = std::env::var("RK_NODE_ID").unwrap();

let _ = client.fund_node(&node_id, 1000000).await;
let master_seed = std::env::var("RK_MASTER_SEED_HEX").unwrap();
let _ = client.provide_master_seed(
&node_id,
hex::decode(master_seed).unwrap(),
lightspark::objects::bitcoin_network::BitcoinNetwork::Mainnet,
);

println!("API ID: {:?}", api_id);
println!("API Token: {:?}", api_token);
println!("Node ID: {:?}", node_id);

let account = client.get_current_account().await.unwrap();
println!("Account: {:?}", account.name);

let invoice = client
.create_test_mode_invoice(&node_id, 10000, Some("test"), None)
.await;
let payment_request = invoice.unwrap().replace("\"", "");
println!("Invoice created: {:?}", payment_request);

let response = client
.pay_invoice(&node_id, &payment_request, 100, None, 1000)
.await;
println!("Payment response: {:?}", response.unwrap().id);
}

#[tokio::main]
async fn main() {
create_invoice().await;
test_payment().await;
}
Loading

0 comments on commit 0a98df5

Please sign in to comment.