1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//! The policy hook: the wallet builds and signs, it does not decide.
//!
//! ADR-2100 says every settlement passes an authority gate; ADR-2101 says a
//! spend key is a role key behind a port. This crate keeps to its half of
//! that bargain: every builder asks a [`SpendPolicy`] before it signs, and
//! ships one implementation, [`Permissive`], which says yes. The gate itself
//! (limits per session, per chain, per counterparty; a supervisor's veto) is
//! the caller's to plug in. Nothing else in the crate reads an [`Intent`].
//!
//! ```
//! use sidestr_wallet::policy::{Intent, IntentKind, SpendPolicy};
//!
//! /// A cap: no single payment over 1 BTC-equivalent of sats.
//! struct Cap(u64);
//! impl SpendPolicy for Cap {
//! fn permit(&self, intent: &Intent<'_>) -> Result<(), String> {
//! if intent.amount > self.0 { Err(format!("{} sats is over the cap of {}", intent.amount, self.0)) } else { Ok(()) }
//! }
//! }
//! let cap = Cap(100_000_000);
//! let script = bitcoin::ScriptBuf::new();
//! let small = Intent { chain_id: "sidestr:example", kind: IntentKind::Spend, script: &script, amount: 1, fee: 1, inputs: 1 };
//! assert!(cap.permit(&small).is_ok());
//! assert!(cap.permit(&Intent { amount: 200_000_000, ..small }).is_err());
//! ```
use Script;
/// What kind of settlement a builder is about to sign.
/// Everything a policy may weigh, decided before any signature exists.
/// The gate a builder consults before signing. Return `Err(reason)` to
/// refuse; the builder surfaces it as [`Error::Policy`](crate::Error::Policy)
/// and signs nothing.
/// The default: every intent is permitted. The right choice for a test, a
/// faucet on a chain whose coins carry no value, or a caller that has
/// already passed the authority gate upstream; the wrong one for a wallet
/// holding value, which is why it has to be named to be used.
;