Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ hkdf = "0.12"
hmac = "0.12"
humantime-serde = "1"
locks-core = { git = "https://github.com/pubky/locks.git", rev = "df5ea1b6d8dcdec3a9b5a915c3f57bca69d75c8a" }
paykit-lib = { git = "https://github.com/pubky/paykit-rs.git", rev = "52a852995bfc457b78d32f5a45f6741766a89bba" }
paykit-sdk = { git = "https://github.com/pubky/paykit-rs.git", rev = "52a852995bfc457b78d32f5a45f6741766a89bba" }
paykit-lib = { git = "https://github.com/pubky/paykit-rs.git", rev = "6b241878a9bba5cecea919c0298c3f90624be6ff" }
paykit-sdk = { git = "https://github.com/pubky/paykit-rs.git", rev = "6b241878a9bba5cecea919c0298c3f90624be6ff" }
pubky = "=0.8.0"
pubky-testnet = "=0.8.0"
prometheus-client = "0.25"
Expand Down
2 changes: 1 addition & 1 deletion paykit-server-e2e/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn payment_intent(reader: &ReaderPubky) -> DeliveryIntentV1 {
&marker(),
PaykitReceiverPath::new("paykit/server").unwrap(),
&PaymentRequestTerms {
amount: PaymentAmount::new("0.00000100", "BTC").unwrap(),
amount: PaymentAmount::new("0.00000100", "btc").unwrap(),
payment_reference: PaymentReference::new(uuid::Uuid::new_v4().to_string()).unwrap(),
proposal_expires_at: None,
recurrence: None,
Expand Down
2 changes: 1 addition & 1 deletion paykit-server-e2e/tests/composition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ fn payment_intent(reader: &ReaderPubky, marker: &PaykitReceiverMarker) -> Delive
marker,
PaykitReceiverPath::new("paykit/server").unwrap(),
&PaymentRequestTerms {
amount: PaymentAmount::new("0.00000100", "BTC").unwrap(),
amount: PaymentAmount::new("0.00000100", "btc").unwrap(),
payment_reference: PaymentReference::new(Uuid::new_v4().to_string()).unwrap(),
proposal_expires_at: None,
recurrence: None,
Expand Down
2 changes: 1 addition & 1 deletion paykit-server-e2e/tests/invoices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ fn payment_intent() -> DeliveryIntentV1 {
&marker(),
PaykitReceiverPath::new("paykit/server").unwrap(),
&PaymentRequestTerms {
amount: PaymentAmount::new("0.00000100", "BTC").unwrap(),
amount: PaymentAmount::new("0.00000100", "btc").unwrap(),
payment_reference: PaymentReference::new(uuid::Uuid::new_v4().to_string()).unwrap(),
proposal_expires_at: None,
recurrence: None,
Expand Down
2 changes: 1 addition & 1 deletion paykit-server-e2e/tests/live_adapters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ async fn live_pubky_marker_discovery_and_payment_request_delivery() {
payer_key.clone(),
payer_path.clone(),
PaymentRequestTerms {
amount: PaymentAmount::new("0.00000100", "BTC").unwrap(),
amount: PaymentAmount::new("0.00000100", "btc").unwrap(),
payment_reference: PaymentReference::new(reference.clone()).unwrap(),
proposal_expires_at: None,
recurrence: None,
Expand Down
9 changes: 5 additions & 4 deletions paykit-server-e2e/tests/server_workflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,12 +726,13 @@ async fn assert_persisted_workflow_inputs(
"paykit/server"
);
assert_ne!(endpoint.marker_fingerprint(), [0; 32]);
let expected_payload = serde_json::json!({ "value": fixture.address }).to_string();
assert!(matches!(
endpoint.operation(),
DeliveryOperationV1::EndpointPublication { receiving_details }
if receiving_details.len() == 1
&& receiving_details[0].identifier == "btc-bitcoin-p2wpkh"
&& receiving_details[0].payload == fixture.address
&& receiving_details[0].identifier == "btc-testnet-p2wpkh"
&& receiving_details[0].payload == expected_payload
));

let payment_plaintext = crypto
Expand Down Expand Up @@ -761,13 +762,13 @@ async fn assert_persisted_workflow_inputs(
payment.operation(),
DeliveryOperationV1::PaymentRequestProposal { terms }
if terms.amount == amount
&& terms.asset == "BTC"
&& terms.asset == "btc"
&& uuid::Uuid::parse_str(&terms.payment_reference)
.is_ok_and(|reference| reference.get_version_num() == 4
&& reference.get_variant() == uuid::Variant::RFC4122
&& terms.payment_reference == reference.hyphenated().to_string())
&& terms.proposal_expires_at.is_none()
&& terms.accepted_endpoint_identifiers == ["btc-bitcoin-p2wpkh"]
&& terms.accepted_endpoint_identifiers == ["btc-testnet-p2wpkh"]
&& terms.metadata.get("bundle_id") == Some(&serde_json::json!(bundle))
&& terms.metadata.get("lock_resource")
== Some(&serde_json::json!(fixture.lock_resource))
Expand Down
31 changes: 25 additions & 6 deletions paykit-server/src/application/create_invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,25 @@ pub trait IntentBuilder: Send + Sync {
) -> Result<Vec<(PaymentEndpointIdentifier, PaymentEndpointPayload)>, CreateInvoiceError>;
}

#[derive(Default)]
pub struct PaykitIntentBuilder;
pub struct PaykitIntentBuilder {
bitcoin_network: crate::config::BitcoinNetwork,
}

impl PaykitIntentBuilder {
pub fn new(bitcoin_network: crate::config::BitcoinNetwork) -> Self {
Self { bitcoin_network }
}

fn p2wpkh_identifier(&self) -> &'static str {
match self.bitcoin_network {
crate::config::BitcoinNetwork::Mainnet => "btc-bitcoin-p2wpkh",
crate::config::BitcoinNetwork::Testnet => "btc-testnet-p2wpkh",
crate::config::BitcoinNetwork::Signet => "btc-signet-p2wpkh",
crate::config::BitcoinNetwork::Regtest => "btc-regtest-p2wpkh",
}
}
}

impl IntentBuilder for PaykitIntentBuilder {
fn payment_request_terms(
&self,
Expand All @@ -176,15 +193,15 @@ impl IntentBuilder for PaykitIntentBuilder {
Ok(PaymentRequestTerms {
amount: PaymentAmount::new(
format!("{}.{:08}", sats / 100_000_000, sats % 100_000_000),
"BTC",
"btc",
)
.map_err(|_| CreateInvoiceError::InvalidRequest)?,
payment_reference: PaymentReference::new(uuid::Uuid::new_v4().hyphenated().to_string())
.map_err(|_| CreateInvoiceError::InvalidRequest)?,
proposal_expires_at: None,
recurrence: None,
accepted_payment_endpoint_identifiers: vec![
PaymentEndpointIdentifier::new("btc-bitcoin-p2wpkh")
PaymentEndpointIdentifier::new(self.p2wpkh_identifier())
.map_err(|_| CreateInvoiceError::InvalidRequest)?,
],
metadata,
Expand All @@ -198,9 +215,11 @@ impl IntentBuilder for PaykitIntentBuilder {
if address.is_empty() {
return Err(CreateInvoiceError::InvalidRequest);
}
let identifier = PaymentEndpointIdentifier::new("btc-bitcoin-p2wpkh")
let identifier = PaymentEndpointIdentifier::new(self.p2wpkh_identifier())
.map_err(|_| CreateInvoiceError::InvalidRequest)?;
let payload = serde_json::to_string(&serde_json::json!({ "value": address }))
.map_err(|_| CreateInvoiceError::InvalidRequest)?;
Ok(vec![(identifier, PaymentEndpointPayload::new(address))])
Ok(vec![(identifier, PaymentEndpointPayload::new(payload))])
}
}

Expand Down
2 changes: 1 addition & 1 deletion paykit-server/src/application/semantic_intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ mod tests {
operation: DeliveryOperationV1::PaymentRequestProposal {
terms: PaymentTermsV1 {
amount: "0.00000100".into(),
asset: "BTC".into(),
asset: "btc".into(),
payment_reference: "550e8400-e29b-41d4-a716-446655440000".into(),
proposal_expires_at: None,
accepted_endpoint_identifiers: vec!["btc-bitcoin-p2wpkh".into()],
Expand Down
31 changes: 22 additions & 9 deletions paykit-server/src/bin/paykit-reader-demo/payment_instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@ use paykit_sdk::{
PaymentRequestLifecycleState, PaymentRequestLocalRole, PaymentRequestRecord,
PrivatePaymentListView, PubkyPublicKey,
};
use serde::Deserialize;

use super::{Failure, ReceiveOutput};

pub(super) const BITCOIN_ENDPOINT: &str = "btc-bitcoin-p2wpkh";
pub(super) const BITCOIN_ENDPOINT: &str = "btc-regtest-p2wpkh";
const MAX_BITCOIN_SATS: u64 = 2_100_000_000_000_000;

#[derive(Deserialize)]
#[serde(deny_unknown_fields)]
struct BitcoinEndpointPayload {
value: String,
}

pub(super) fn select_actionable_request(
requests: &[PaymentRequestRecord],
) -> Result<Option<&PaymentRequestRecord>, Failure> {
Expand Down Expand Up @@ -50,7 +57,7 @@ pub(super) fn payment_instructions(
return Err(Failure::ProtocolFailed);
}
let terms = request.terms.as_ref().ok_or(Failure::ProtocolFailed)?;
if terms.amount.asset != "BTC"
if terms.amount.asset != "btc"
|| terms.recurrence.is_some()
|| terms.proposal_expires_at.is_some()
|| terms.accepted_payment_endpoint_identifiers != [BITCOIN_ENDPOINT.to_owned()]
Expand All @@ -71,15 +78,18 @@ pub(super) fn payment_instructions(
if private_list.payment_endpoints.len() != 1 {
return Err(Failure::ProtocolFailed);
}
let raw_address = private_list
let raw_payload = private_list
.payment_endpoints
.get(BITCOIN_ENDPOINT)
.ok_or(Failure::ProtocolFailed)?;
let address = Address::from_str(raw_address)
let raw_address = serde_json::from_str::<BitcoinEndpointPayload>(raw_payload)
.map_err(|_| Failure::ProtocolFailed)?
.value;
let address = Address::from_str(&raw_address)
.map_err(|_| Failure::ProtocolFailed)?
.require_network(Network::Regtest)
.map_err(|_| Failure::ProtocolFailed)?;
if address.address_type() != Some(AddressType::P2wpkh) || address.to_string() != *raw_address {
if address.address_type() != Some(AddressType::P2wpkh) || address.to_string() != raw_address {
return Err(Failure::ProtocolFailed);
}
let address = address.to_string();
Expand All @@ -93,7 +103,7 @@ pub(super) fn payment_instructions(
status: "received",
payment_request_id: request.payment_request_id.clone(),
address: address.clone(),
asset: "BTC",
asset: "btc",
amount_sats: amount_sats.to_string(),
payment_command: format!(
"docker compose exec -T bitcoin sh -ec 'bitcoin-cli -conf=\"$BITCOIN_DATA/bitcoin.conf\" -regtest -rpcwallet=miner sendtoaddress \"{address}\" \"{bitcoin_amount}\"'"
Expand Down Expand Up @@ -139,7 +149,7 @@ mod tests {
proposal_event_id: Some("8a0d8b4c-913f-4e31-9f2c-2a6f5bb4d101".into()),
terms: Some(PaymentRequestTermsRecord {
amount: AmountRecord {
asset: "BTC".into(),
asset: "btc".into(),
value: "0.00050000".into(),
},
payment_reference: "reference-1".into(),
Expand All @@ -166,7 +176,10 @@ mod tests {
fn private_list(address: &str) -> PrivatePaymentListView {
PrivatePaymentListView {
latest_stream_item_id: Some(2),
payment_endpoints: HashMap::from([(BITCOIN_ENDPOINT.into(), address.into())]),
payment_endpoints: HashMap::from([(
BITCOIN_ENDPOINT.into(),
serde_json::json!({ "value": address }).to_string(),
)]),
last_refresh_at: None,
}
}
Expand Down Expand Up @@ -206,7 +219,7 @@ mod tests {
"status": "received",
"payment_request_id": request().payment_request_id,
"address": regtest_p2wpkh(),
"asset": "BTC",
"asset": "btc",
"amount_sats": "50000",
"payment_command": format!(
"docker compose exec -T bitcoin sh -ec 'bitcoin-cli -conf=\"$BITCOIN_DATA/bitcoin.conf\" -regtest -rpcwallet=miner sendtoaddress \"{}\" \"0.00050000\"'",
Expand Down
Loading