Compare commits

..
Author SHA1 Message Date
3a17a564d3 Merge branch 'main' into wt/t_49b7c2b1
Some checks failed
ci / sdk (pull_request) Successful in 1m8s
android-ci / android (pull_request) Has been cancelled
ci / test (pull_request) Successful in 4m3s
2026-09-15 21:50:53 +00:00
995f46013e Merge pull request 'feat(sdk): sign/encode/decode/verify invoice, receipt and tip frames' (#77) from wt/t_cd793d2c into main
All checks were successful
ci / test (push) Successful in 3m55s
android-ci / android (push) Successful in 8m42s
ci / sdk (push) Successful in 56s
Reviewed-on: #77
2026-09-15 17:38:35 +00:00
b1dd18a4a2 Merge branch 'main' into wt/t_cd793d2c
All checks were successful
ci / test (pull_request) Successful in 3m51s
ci / sdk (pull_request) Successful in 57s
android-ci / android (pull_request) Successful in 8m33s
2026-09-15 17:01:58 +00:00
agent
96d582153a
feat(sdk): sign/encode/decode/verify invoice, receipt and tip frames
All checks were successful
ci / test (pull_request) Successful in 4m24s
android-ci / android (pull_request) Successful in 8m53s
ci / sdk (pull_request) Successful in 1m17s
The SDK could already send an invoice or a tip through Node::pay_invoice /
Node::tip, but it could not touch the payment frames themselves: pay::sign_*
take the ed25519 identity secret and Node exposed only identity_pk(), so the
signing half lived nowhere the SDK could reach.

Add the signing surface to the node instead of exporting the key:

  * Node::sign_invoice / sign_receipt / sign_tip sign with the node's own
    identity key and return the core frame struct. The secret never leaves
    the process and there is no API that hands it out.
  * pay_invoice and tip now call those methods rather than signing inline, so
    there is one signing path, not two.

SDK (crates/onionwire-sdk), all backward compatible:

  * Records Invoice, Receipt, Tip mirroring src/pay.rs, sig as raw bytes so a
    frame re-encodes byte-for-byte.
  * Wire::sign_invoice / sign_receipt / sign_tip (async, over the node).
  * Free functions encode_invoice / encode_receipt / encode_tip,
    decode_invoice / decode_receipt / decode_tip (None on a foreign or
    truncated frame), verify_invoice / verify_receipt / verify_tip against
    the sender's pubkey hex (false on a bad key, never a panic).

Tests: 8 new SDK unit tests (record round-trips through the core encoders,
signer-key-only verification, tamper rejection, foreign/truncated frame,
typed Stopped error after shutdown). SDK 27 passed, 0 failed; SDK clippy
--all-targets -D warnings clean; root clippy --all-targets -D warnings
clean; root lib tests 14 passed; tests/pay.rs 11 passed.
2026-09-15 12:45:49 -04:00
3dc52edc71 Merge pull request 'fix(android): make the new launcher icon actually display (adaptive icon + roundIcon)' (#74) from wt/app-icon-adaptive into main
All checks were successful
android-ci / android (push) Successful in 8m0s
Reviewed-on: #74
2026-09-15 02:31:22 +00:00
6f69d629fb Merge branch 'main' into wt/app-icon-adaptive
All checks were successful
ci / test (pull_request) Successful in 4m19s
ci / sdk (pull_request) Successful in 1m14s
android-ci / android (pull_request) Successful in 8m19s
2026-09-15 02:25:12 +00:00
agent
faf4d1bb15
fix(android): make the new launcher icon actually show up as an adaptive icon
The icon change landed as a bitmap dropped straight into
res/mipmap-anydpi-v26/ and wired to android:icon only, so the installed app
kept showing the old art:

- android:roundIcon still pointed at @mipmap/ic_launcher (the old vector
  adaptive icon). Launchers that prefer roundIcon — Pixel Launcher, Samsung
  One UI — render it in preference to android:icon, so the new bitmap never
  appeared. Verified on the ow35 emulator drawer: old cyan/green line-art
  onion while android:icon was already the new PNG.
- a bitmap under mipmap-anydpi-v26 is a legacy icon, not an adaptive one: the
  launcher pads it into the mask itself and it is not density-aware.

Now:
- drawable-nodpi/onionwire_app_icon.png: the artwork squared to 432x432 with
  the logo at 62% of the canvas (inside the 66dp/108dp safe zone) over a
  seamless blurred backdrop of itself, so no launcher mask clips the logo.
- mipmap-anydpi-v26/ic_launcher.xml and ic_launcher_round.xml: adaptive icons
  with that bitmap as the background layer and a transparent foreground.
- AndroidManifest.xml: icon=@mipmap/ic_launcher, roundIcon=@mipmap/ic_launcher_round.
- Delete the retired vectors (ic_launcher_background/foreground.xml) and the
  misplaced mipmap-anydpi-v26/onionwire_app_icon.png.
2026-09-14 22:16:24 -04:00
33d5d080a4 Merge pull request 'docs(readme): document v0.2.1 wallet create/import, tip frame, F6 screen, SDK payment surface' (#72) from docs/readme-v0.2.1-wallet into main
Reviewed-on: #72
2026-09-14 21:11:15 +00:00
9 changed files with 461 additions and 173 deletions

View file

@ -36,9 +36,9 @@
android:allowBackup="false" android:allowBackup="false"
android:dataExtractionRules="@xml/data_extraction_rules" android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="false" android:fullBackupContent="false"
android:icon="@mipmap/onionwire_app_icon" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.OnionWire"> android:theme="@style/Theme.OnionWire">

Binary file not shown.

After

Width:  |  Height:  |  Size: 123 KiB

View file

@ -1,22 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- OnionWire adaptive-icon background: deep indigo-to-purple gradient that
matches the app's dark theme and lets the cyan-networked onion bulb pop. -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillColor="#0B0B10"
android:pathData="M0,0h108v108h-108z" />
<path
android:fillColor="#1A0A2E"
android:pathData="M0,0 L108,0 L108,108 L0,108 Z"
android:fillAlpha="0.55" />
<!-- subtle radial highlight toward the center so the icon has depth on
launchers that blur the background -->
<path
android:fillColor="#3D1A5C"
android:fillAlpha="0.28"
android:pathData="M54,20 m-34,0 a34,34 0 1,1 68,0 a34,34 0 1,1 -68,0" />
</vector>

View file

@ -1,138 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- OnionWire launcher foreground: Tor onion bulb with layered rings and
cyan network-connectivity lines. Keep art inside the 66dp safe zone
(the inner 66x66 of the 108x108 viewport) so it survives the adaptive
icon mask on every OEM launcher. -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<!-- translucent backdrop so the bulb reads against any mask -->
<path
android:fillColor="#000000"
android:fillAlpha="0.18"
android:pathData="M54,30 m-26,0 a26,26 0 1,1 52,0 a26,26 0 1,1 -52,0" />
<!-- onion bulb: deep purple-violet built from nested ellipses -->
<path
android:fillColor="#4A148C"
android:pathData="M54,30 C74,30 86,48 86,64 C86,78 72,86 54,86 C36,86 22,78 22,64 C22,48 34,30 54,30 Z" />
<path
android:fillColor="#7B1FA2"
android:pathData="M54,34 C70,34 80,48 80,62 C80,75 69,82 54,82 C39,82 28,75 28,62 C28,48 38,34 54,34 Z" />
<path
android:fillColor="#9C27B0"
android:pathData="M54,38 C66,38 74,49 74,60 C74,71 65,76 54,76 C43,76 34,71 34,60 C34,49 42,38 54,38 Z" />
<!-- glossy highlight -->
<path
android:fillColor="#CE93D8"
android:fillAlpha="0.55"
android:pathData="M46,44 C46,44 50,38 56,38 C62,38 66,44 66,44 C66,44 60,56 56,58 C52,60 48,56 46,44 Z" />
<!-- sprout crown at top: three-point silhouette -->
<path
android:strokeColor="#38F2C7"
android:strokeWidth="2.2"
android:strokeLineCap="round"
android:fillColor="#38F2C7"
android:fillAlpha="0.9"
android:pathData="M54,30 L50,20 L54,26 L58,20 Z" />
<path
android:strokeColor="#38F2C7"
android:strokeWidth="1.6"
android:strokeLineCap="round"
android:pathData="M54,30 L54,19" />
<!-- layered rings -->
<path
android:strokeColor="#38F2C7"
android:strokeWidth="2.0"
android:strokeLineCap="round"
android:fillColor="#00000000"
android:pathData="M36,42 C30,56 33,74 46,82" />
<path
android:strokeColor="#38F2C7"
android:strokeWidth="2.0"
android:strokeLineCap="round"
android:fillColor="#00000000"
android:pathData="M72,42 C78,56 75,74 62,82" />
<path
android:strokeColor="#38F2C7"
android:strokeWidth="2.0"
android:strokeLineCap="round"
android:fillColor="#00000000"
android:pathData="M40,38 C30,52 34,70 50,80" />
<path
android:strokeColor="#38F2C7"
android:strokeWidth="2.0"
android:strokeLineCap="round"
android:fillColor="#00000000"
android:pathData="M68,38 C78,52 74,70 58,80" />
<!-- vertical seam -->
<path
android:strokeColor="#0B0B10"
android:strokeWidth="1.8"
android:strokeLineCap="round"
android:fillColor="#00000000"
android:pathData="M54,32 L54,84" />
<!-- cyan network lines + nodes -->
<path
android:strokeColor="#38F2C7"
android:strokeWidth="1.0"
android:strokeLineCap="round"
android:fillColor="#38F2C7"
android:pathData="M42,52 L50,48 L42,44" />
<path
android:strokeColor="#38F2C7"
android:strokeWidth="1.0"
android:strokeLineCap="round"
android:fillColor="#38F2C7"
android:pathData="M66,52 L58,48 L66,44" />
<path
android:strokeColor="#38F2C7"
android:strokeWidth="1.0"
android:strokeLineCap="round"
android:pathData="M54,56 L54,64" />
<path
android:strokeColor="#38F2C7"
android:strokeWidth="1.0"
android:strokeLineCap="round"
android:pathData="M46,60 L54,64 L62,60" />
<path
android:fillColor="#38F2C7"
android:pathData="M42,52 m-1.4,0 a1.4,1.4 0 1,1 2.8,0 a1.4,1.4 0 1,1 -2.8,0" />
<path
android:fillColor="#38F2C7"
android:pathData="M50,48 m-1.4,0 a1.4,1.4 0 1,1 2.8,0 a1.4,1.4 0 1,1 -2.8,0" />
<path
android:fillColor="#38F2C7"
android:pathData="M42,44 m-1.4,0 a1.4,1.4 0 1,1 2.8,0 a1.4,1.4 0 1,1 -2.8,0" />
<path
android:fillColor="#38F2C7"
android:pathData="M66,52 m-1.4,0 a1.4,1.4 0 1,1 2.8,0 a1.4,1.4 0 1,1 -2.8,0" />
<path
android:fillColor="#38F2C7"
android:pathData="M58,48 m-1.4,0 a1.4,1.4 0 1,1 2.8,0 a1.4,1.4 0 1,1 -2.8,0" />
<path
android:fillColor="#38F2C7"
android:pathData="M66,44 m-1.4,0 a1.4,1.4 0 1,1 2.8,0 a1.4,1.4 0 1,1 -2.8,0" />
<path
android:fillColor="#38F2C7"
android:pathData="M54,56 m-1.4,0 a1.4,1.4 0 1,1 2.8,0 a1.4,1.4 0 1,1 -2.8,0" />
<path
android:fillColor="#38F2C7"
android:pathData="M54,64 m-1.4,0 a1.4,1.4 0 1,1 2.8,0 a1.4,1.4 0 1,1 -2.8,0" />
<path
android:fillColor="#38F2C7"
android:pathData="M46,60 m-1.4,0 a1.4,1.4 0 1,1 2.8,0 a1.4,1.4 0 1,1 -2.8,0" />
<path
android:fillColor="#38F2C7"
android:pathData="M62,60 m-1.4,0 a1.4,1.4 0 1,1 2.8,0 a1.4,1.4 0 1,1 -2.8,0" />
</vector>

View file

@ -1,5 +1,19 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- OnionWire launcher icon (adaptive).
The artwork lives in drawable-nodpi/onionwire_app_icon.png as a single
432x432 full-bleed bitmap: the networked-onion logo at 62% of the canvas
(inside the 66dp/108dp adaptive-icon safe zone) over a seamless blurred
backdrop of itself. It is used as the background layer, so the launcher
mask can crop the outer edge of the artwork without ever clipping the
logo. The foreground layer is transparent on purpose: the whole icon is
the bitmap.
Do not point android:icon at a bitmap in this directory again. A bitmap
under mipmap-anydpi-v26 is a *legacy* icon: it is not an adaptive icon, so
the launcher pads it into the mask with its own plate and it scales wrong
on high-density screens. -->
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> <adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" /> <background android:drawable="@drawable/onionwire_app_icon" />
<foreground android:drawable="@drawable/ic_launcher_foreground" /> <foreground android:drawable="@android:color/transparent" />
</adaptive-icon> </adaptive-icon>

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Round variant for launchers that ask for android:roundIcon (Pixel
Launcher, Samsung One UI). Must render the same artwork as ic_launcher.xml
— a stale roundIcon is exactly how an "old icon" survives an icon change,
because those launchers prefer roundIcon over icon. -->
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/onionwire_app_icon" />
<foreground android:drawable="@android:color/transparent" />
</adaptive-icon>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 150 KiB

View file

@ -595,6 +595,55 @@ impl Wire {
.map_err(WireError::new) .map_err(WireError::new)
} }
/// Sign an invoice frame with this node's identity key.
///
/// The ed25519 secret stays inside the node: this is the only way the SDK
/// signs a payment frame and there is no method that hands the key out.
/// `amount_atomic` is piconero (`xmr_to_atomic` converts a typed amount).
/// Signing does not touch the network — carry the result with
/// [`encode_invoice`] and send it as chat bytes, or use the one-shot
/// [`Wire::send_invoice`], which signs, sends and records the chat line.
pub async fn sign_invoice(
&self,
amount_atomic: String,
address: String,
memo: String,
) -> WResult<Invoice> {
self.node()?
.sign_invoice(&amount_atomic, &address, &memo)
.map(invoice_record)
.map_err(WireError::new)
}
/// Sign a receipt frame for a transfer that already happened. Signing only,
/// never a transfer: this does not move funds.
pub async fn sign_receipt(
&self,
txid: String,
amount_atomic: String,
address: String,
) -> WResult<Receipt> {
self.node()?
.sign_receipt(&txid, &amount_atomic, &address)
.map(receipt_record)
.map_err(WireError::new)
}
/// Sign a tip frame (receipt plus memo) for a transfer that already
/// happened. Signing only, never a transfer.
pub async fn sign_tip(
&self,
txid: String,
amount_atomic: String,
address: String,
memo: String,
) -> WResult<Tip> {
self.node()?
.sign_tip(&txid, &amount_atomic, &address, &memo)
.map(tip_record)
.map_err(WireError::new)
}
/// Spend-authority warning shown before create. Not a tooltip. /// Spend-authority warning shown before create. Not a tooltip.
pub fn spend_authority_warning(&self) -> String { pub fn spend_authority_warning(&self) -> String {
onionwire::wallet::SPEND_AUTHORITY_WARNING.to_string() onionwire::wallet::SPEND_AUTHORITY_WARNING.to_string()
@ -691,6 +740,178 @@ pub struct TransferRow {
pub address: String, pub address: String,
} }
/// One signed invoice frame: "pay me `amount_atomic` piconero at `address`".
///
/// Mirrors `pay::Invoice`. `sig` is the raw 64-byte ed25519 signature, not hex,
/// so the frame re-encodes byte-for-byte. Sign it with [`Wire::sign_invoice`]
/// (the identity key never leaves the node), carry it with [`encode_invoice`],
/// and check an inbound one against the sender's pubkey with [`verify_invoice`].
#[derive(Debug, Clone, PartialEq, Eq, uniffi::Record)]
pub struct Invoice {
/// Piconero as a decimal string. `xmr_to_atomic("0.5")` is the form to
/// build this from a typed amount.
pub amount_atomic: String,
pub address: String,
/// May be empty; must not contain a newline.
pub memo: String,
/// Unix seconds the frame was signed at.
pub ts: i64,
pub sig: Vec<u8>,
}
/// One signed receipt frame: "transaction `txid` paid `amount_atomic` to
/// `address`". Mirrors `pay::Receipt`; same signing rules as [`Invoice`].
#[derive(Debug, Clone, PartialEq, Eq, uniffi::Record)]
pub struct Receipt {
pub txid: String,
pub amount_atomic: String,
pub address: String,
pub ts: i64,
pub sig: Vec<u8>,
}
/// One signed tip frame: a receipt plus the memo the sender attached. Mirrors
/// `pay::Tip`; same signing rules as [`Invoice`].
#[derive(Debug, Clone, PartialEq, Eq, uniffi::Record)]
pub struct Tip {
pub txid: String,
pub amount_atomic: String,
pub address: String,
pub memo: String,
pub ts: i64,
pub sig: Vec<u8>,
}
fn invoice_record(inv: pay::Invoice) -> Invoice {
Invoice {
amount_atomic: inv.amount_atomic,
address: inv.address,
memo: inv.memo,
ts: inv.ts,
sig: inv.sig,
}
}
fn invoice_core(rec: Invoice) -> pay::Invoice {
pay::Invoice {
amount_atomic: rec.amount_atomic,
address: rec.address,
memo: rec.memo,
ts: rec.ts,
sig: rec.sig,
}
}
fn receipt_record(rcp: pay::Receipt) -> Receipt {
Receipt {
txid: rcp.txid,
amount_atomic: rcp.amount_atomic,
address: rcp.address,
ts: rcp.ts,
sig: rcp.sig,
}
}
fn receipt_core(rec: Receipt) -> pay::Receipt {
pay::Receipt {
txid: rec.txid,
amount_atomic: rec.amount_atomic,
address: rec.address,
ts: rec.ts,
sig: rec.sig,
}
}
fn tip_record(tip: pay::Tip) -> Tip {
Tip {
txid: tip.txid,
amount_atomic: tip.amount_atomic,
address: tip.address,
memo: tip.memo,
ts: tip.ts,
sig: tip.sig,
}
}
fn tip_core(rec: Tip) -> pay::Tip {
pay::Tip {
txid: rec.txid,
amount_atomic: rec.amount_atomic,
address: rec.address,
memo: rec.memo,
ts: rec.ts,
sig: rec.sig,
}
}
/// Encode an invoice as the wire frame the peer decodes with
/// [`decode_invoice`]. Pass the bytes to [`Wire::send`].
#[uniffi::export]
pub fn encode_invoice(invoice: Invoice) -> Vec<u8> {
pay::encode_invoice(&invoice_core(invoice))
}
/// Decode an invoice frame. `None` for another frame kind, a truncated frame or
/// other malformed bytes — decoding never panics.
#[uniffi::export]
pub fn decode_invoice(frame: Vec<u8>) -> Option<Invoice> {
pay::decode_invoice(&frame).map(invoice_record)
}
/// Verify an invoice against the sender's ed25519 identity pubkey (lowercase
/// hex — the same key [`FriendInfo::pubkey_hex`] carries). `false` for a bad
/// signature, an edited frame, or a malformed key.
#[uniffi::export]
pub fn verify_invoice(pubkey_hex: String, invoice: Invoice) -> bool {
match unhex(&pubkey_hex) {
Ok(pk) => pay::verify_invoice(&pk, &invoice_core(invoice)),
Err(_) => false,
}
}
/// Encode a receipt as the wire frame the peer decodes with
/// [`decode_receipt`].
#[uniffi::export]
pub fn encode_receipt(receipt: Receipt) -> Vec<u8> {
pay::encode_receipt(&receipt_core(receipt))
}
/// Decode a receipt frame. `None` for another frame kind or malformed bytes.
#[uniffi::export]
pub fn decode_receipt(frame: Vec<u8>) -> Option<Receipt> {
pay::decode_receipt(&frame).map(receipt_record)
}
/// Verify a receipt against the sender's ed25519 identity pubkey (hex).
#[uniffi::export]
pub fn verify_receipt(pubkey_hex: String, receipt: Receipt) -> bool {
match unhex(&pubkey_hex) {
Ok(pk) => pay::verify_receipt(&pk, &receipt_core(receipt)),
Err(_) => false,
}
}
/// Encode a tip as the wire frame the peer decodes with [`decode_tip`].
#[uniffi::export]
pub fn encode_tip(tip: Tip) -> Vec<u8> {
pay::encode_tip(&tip_core(tip))
}
/// Decode a tip frame. `None` for another frame kind or malformed bytes.
#[uniffi::export]
pub fn decode_tip(frame: Vec<u8>) -> Option<Tip> {
pay::decode_tip(&frame).map(tip_record)
}
/// Verify a tip against the sender's ed25519 identity pubkey (hex).
#[uniffi::export]
pub fn verify_tip(pubkey_hex: String, tip: Tip) -> bool {
match unhex(&pubkey_hex) {
Ok(pk) => pay::verify_tip(&pk, &tip_core(tip)),
Err(_) => false,
}
}
/// Convert a user-facing XMR amount string to a piconero string. /// Convert a user-facing XMR amount string to a piconero string.
/// ///
/// Accepts `"0.5"`, `"1"`, `"0.001"` etc. Returns the piconero string on /// Accepts `"0.5"`, `"1"`, `"0.001"` etc. Returns the piconero string on
@ -1017,4 +1238,162 @@ mod tests {
fn check_address_rejects_invalid_address() { fn check_address_rejects_invalid_address() {
assert!(check_address("not-an-address".to_string()).is_err()); assert!(check_address("not-an-address".to_string()).is_err());
} }
// ---- pay.rs surface: Invoice / Receipt / Tip frames ----
/// A throwaway identity for the signing half, without Arti or a store:
/// `session::Keys::generate` is the core's own generator and hands out both
/// the secret half the signer needs and the public half a verifier needs.
fn test_keys() -> onionwire::session::Keys {
onionwire::session::Keys::generate()
}
/// Same mainnet address the address tests use.
const ADDR: &str = "4AdUndXHHZ6cfufTMvppY6JwXNouMBzSkbLYfpAV5Usx3skxNgYeYTRj5UzqtReoS44qo9mtmXCqY45DJ852K5Jv2684Rge";
fn signed_invoice(k: &onionwire::session::Keys) -> pay::Invoice {
pay::sign_invoice(&k.identity_sk, "500000000000", ADDR, "lunch", 1_700_000_000)
.expect("sign_invoice")
}
fn signed_receipt(k: &onionwire::session::Keys) -> pay::Receipt {
pay::sign_receipt(&k.identity_sk, "ab12", "500000000000", ADDR, 1_700_000_000)
.expect("sign_receipt")
}
fn signed_tip(k: &onionwire::session::Keys) -> pay::Tip {
pay::sign_tip(
&k.identity_sk,
"ab12",
"500000000000",
ADDR,
"lunch",
1_700_000_000,
)
.expect("sign_tip")
}
#[test]
fn invoice_record_round_trips_through_encode_and_decode() {
let k = test_keys();
let core = signed_invoice(&k);
let rec = invoice_record(core.clone());
// The record carries the core's fields, not defaults.
assert_eq!(rec.amount_atomic, "500000000000");
assert_eq!(rec.address, ADDR);
assert_eq!(rec.memo, "lunch");
assert_eq!(rec.ts, 1_700_000_000);
assert_eq!(rec.sig, core.sig);
// Encoding the record is byte-identical to encoding the core frame …
let pt = encode_invoice(rec.clone());
assert_eq!(pt, pay::encode_invoice(&core));
// … and the frame decodes back to the same record.
assert_eq!(decode_invoice(pt).as_ref(), Some(&rec));
}
#[test]
fn receipt_record_round_trips_through_encode_and_decode() {
let k = test_keys();
let core = signed_receipt(&k);
let rec = receipt_record(core.clone());
assert_eq!(rec.txid, "ab12");
assert_eq!(rec.amount_atomic, "500000000000");
assert_eq!(rec.address, ADDR);
assert_eq!(rec.ts, 1_700_000_000);
let pt = encode_receipt(rec.clone());
assert_eq!(pt, pay::encode_receipt(&core));
assert_eq!(decode_receipt(pt).as_ref(), Some(&rec));
}
#[test]
fn tip_record_round_trips_through_encode_and_decode() {
let k = test_keys();
let core = signed_tip(&k);
let rec = tip_record(core.clone());
assert_eq!(rec.txid, "ab12");
assert_eq!(rec.memo, "lunch");
let pt = encode_tip(rec.clone());
assert_eq!(pt, pay::encode_tip(&core));
assert_eq!(decode_tip(pt).as_ref(), Some(&rec));
}
#[test]
fn a_frame_verifies_against_the_signers_pubkey_only() {
let k = test_keys();
let other = test_keys();
let rec = invoice_record(signed_invoice(&k));
assert!(verify_invoice(hex(&k.identity_pk), rec.clone()));
assert!(!verify_invoice(hex(&other.identity_pk), rec.clone()));
// A malformed key is a failed verification, not a panic.
assert!(!verify_invoice("zz".to_string(), rec));
}
#[test]
fn receipt_and_tip_verify_against_the_signers_pubkey_only() {
let k = test_keys();
let other = test_keys();
let pk = hex(&k.identity_pk);
let wrong = hex(&other.identity_pk);
let rcp = receipt_record(signed_receipt(&k));
assert!(verify_receipt(pk.clone(), rcp.clone()));
assert!(!verify_receipt(wrong.clone(), rcp));
let tip = tip_record(signed_tip(&k));
assert!(verify_tip(pk, tip.clone()));
assert!(!verify_tip(wrong, tip));
}
#[test]
fn verification_rejects_a_frame_whose_amount_was_edited() {
let k = test_keys();
let pk = hex(&k.identity_pk);
let mut inv = invoice_record(signed_invoice(&k));
inv.amount_atomic = "900000000000".to_string();
assert!(!verify_invoice(pk.clone(), inv));
let mut tip = tip_record(signed_tip(&k));
tip.address = ADDR.replace("4AdUnd", "4AdUne");
assert!(!verify_tip(pk, tip));
}
#[test]
fn decode_rejects_a_foreign_or_truncated_frame() {
let k = test_keys();
assert_eq!(decode_invoice(b"nonsense".to_vec()), None);
// A tip frame is not an invoice frame.
assert_eq!(decode_invoice(encode_tip(tip_record(signed_tip(&k)))), None);
// The prefix without its fields is not a frame either.
let mut truncated = encode_receipt(receipt_record(signed_receipt(&k)));
truncated.truncate(10);
assert_eq!(decode_receipt(truncated), None);
}
#[test]
fn payment_signing_after_shutdown_is_a_typed_error() {
let wire = stopped_wire();
for err in [
block_on(wire.sign_invoice("500000000000".into(), ADDR.into(), String::new()))
.unwrap_err(),
block_on(wire.sign_receipt("ab12".into(), "500000000000".into(), ADDR.into()))
.unwrap_err(),
block_on(wire.sign_tip(
"ab12".into(),
"500000000000".into(),
ADDR.into(),
String::new(),
))
.unwrap_err(),
] {
assert!(matches!(err, WireError::Stopped { .. }), "got {err:?}");
}
}
} }

View file

@ -520,6 +520,57 @@ impl Node {
self.try_send(&onion, friend_pk, &prekey, &pt).await self.try_send(&onion, friend_pk, &prekey, &pt).await
} }
/// Sign an invoice with this node's identity key.
///
/// The signing half of [`Self::pay_invoice`], for callers that build the
/// frame themselves (the Android SDK). The ed25519 secret never leaves the
/// node: it is signed with here and not handed out. `amount_atomic` is
/// piconero; `address` must be a valid Monero address; `memo` may be empty.
pub fn sign_invoice(
&self,
amount_atomic: &str,
address: &str,
memo: &str,
) -> Result<pay::Invoice, String> {
let k = self.keys()?;
pay::sign_invoice(&k.identity_sk, amount_atomic, address, memo, unix_now())
.map_err(|e| e.to_string())
}
/// Sign a receipt for a transfer that already happened: the signing half of
/// [`Self::tip`]. Same key discipline as [`Self::sign_invoice`].
pub fn sign_receipt(
&self,
txid: &str,
amount_atomic: &str,
address: &str,
) -> Result<pay::Receipt, String> {
let k = self.keys()?;
pay::sign_receipt(&k.identity_sk, txid, amount_atomic, address, unix_now())
.map_err(|e| e.to_string())
}
/// Sign a tip frame (receipt + memo) for a transfer that already happened.
/// This signs only — it does not move funds; that is [`Self::tip`].
pub fn sign_tip(
&self,
txid: &str,
amount_atomic: &str,
address: &str,
memo: &str,
) -> Result<pay::Tip, String> {
let k = self.keys()?;
pay::sign_tip(
&k.identity_sk,
txid,
amount_atomic,
address,
memo,
unix_now(),
)
.map_err(|e| e.to_string())
}
/// Invoice to receive. Wallet subaddress if up, else self_profile.xmr_addr. /// Invoice to receive. Wallet subaddress if up, else self_profile.xmr_addr.
pub async fn pay_invoice( pub async fn pay_invoice(
&self, &self,
@ -528,9 +579,7 @@ impl Node {
memo: &str, memo: &str,
) -> Result<(), String> { ) -> Result<(), String> {
let address = self.invoice_address().await?; let address = self.invoice_address().await?;
let k = self.keys()?; let inv = self.sign_invoice(atomic, &address, memo)?;
let inv = pay::sign_invoice(&k.identity_sk, atomic, &address, memo, unix_now())
.map_err(|e| e.to_string())?;
let pt = pay::encode_invoice(&inv); let pt = pay::encode_invoice(&inv);
self.send_once(friend_pk, &pt).await?; self.send_once(friend_pk, &pt).await?;
let store = self.store.lock().map_err(|e| e.to_string())?; let store = self.store.lock().map_err(|e| e.to_string())?;
@ -579,12 +628,9 @@ impl Node {
.transfer(&address, amount) .transfer(&address, amount)
.await .await
.map_err(|e| e.to_string())?; .map_err(|e| e.to_string())?;
let k = self.keys()?; let rcp = self.sign_receipt(&txid, atomic, &address)?;
let rcp = pay::sign_receipt(&k.identity_sk, &txid, atomic, &address, unix_now())
.map_err(|e| e.to_string())?;
let rcp_pt = pay::encode_receipt(&rcp); let rcp_pt = pay::encode_receipt(&rcp);
let tip = pay::sign_tip(&k.identity_sk, &txid, atomic, &address, _memo, unix_now()) let tip = self.sign_tip(&txid, atomic, &address, _memo)?;
.map_err(|e| e.to_string())?;
let tip_pt = pay::encode_tip(&tip); let tip_pt = pay::encode_tip(&tip);
self.send_once(friend_pk, &rcp_pt).await?; self.send_once(friend_pk, &rcp_pt).await?;
self.send_once(friend_pk, &tip_pt).await?; self.send_once(friend_pk, &tip_pt).await?;