bsv-x402 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +125 -466
- package/dist/index.d.cts +56 -145
- package/dist/index.d.ts +56 -145
- package/dist/index.js +117 -458
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -6,7 +6,7 @@ interface Challenge {
|
|
|
6
6
|
}
|
|
7
7
|
interface Proof {
|
|
8
8
|
txid: string;
|
|
9
|
-
|
|
9
|
+
beef: string;
|
|
10
10
|
}
|
|
11
11
|
interface Brc105Challenge {
|
|
12
12
|
version: string;
|
|
@@ -37,6 +37,11 @@ interface Brc105Wallet {
|
|
|
37
37
|
hmac: number[];
|
|
38
38
|
}>;
|
|
39
39
|
createAction(params: CWICreateActionParams): Promise<CWICreateActionResult>;
|
|
40
|
+
abortAction?: (args: {
|
|
41
|
+
reference: string;
|
|
42
|
+
}) => Promise<{
|
|
43
|
+
aborted: boolean;
|
|
44
|
+
}>;
|
|
40
45
|
}
|
|
41
46
|
interface Brc105Proof {
|
|
42
47
|
derivationPrefix: string;
|
|
@@ -45,46 +50,26 @@ interface Brc105Proof {
|
|
|
45
50
|
clientIdentityKey: string;
|
|
46
51
|
txid: string;
|
|
47
52
|
}
|
|
48
|
-
|
|
53
|
+
interface Brc105ProofResult {
|
|
54
|
+
proof: Brc105Proof;
|
|
55
|
+
abort?: () => Promise<void>;
|
|
56
|
+
}
|
|
57
|
+
type Brc105ProofConstructor = (challenge: Brc105Challenge) => Promise<Brc105ProofResult>;
|
|
49
58
|
type PaymentProtocol = 'x402' | 'brc105';
|
|
50
59
|
interface PaymentRequest {
|
|
51
60
|
amount: number;
|
|
52
61
|
origin: string;
|
|
53
62
|
protocol: PaymentProtocol;
|
|
54
63
|
}
|
|
55
|
-
type SpendMode = "interactive" | "programmatic";
|
|
56
|
-
type TimeWindow = "minute" | "hour" | "day" | "week";
|
|
57
|
-
interface WindowLimit {
|
|
58
|
-
window: TimeWindow;
|
|
59
|
-
maxSatoshis: number;
|
|
60
|
-
maxTransactions: number;
|
|
61
|
-
}
|
|
62
|
-
interface SpendLimits {
|
|
63
|
-
windows: WindowLimit[];
|
|
64
|
-
perTxMaxSatoshis: number;
|
|
65
|
-
yellowLightThreshold: number;
|
|
66
|
-
requirePerSitePrompt: boolean;
|
|
67
|
-
sitePolicies: Record<string, SitePolicy>;
|
|
68
|
-
require2fa: TwoFactorPolicy;
|
|
69
|
-
}
|
|
70
|
-
type SitePolicyAction = "global" | "custom" | "block";
|
|
71
|
-
interface SitePolicy {
|
|
72
|
-
origin: string;
|
|
73
|
-
action: SitePolicyAction;
|
|
74
|
-
limits?: WindowLimit[];
|
|
75
|
-
perTxMaxSatoshis?: number;
|
|
76
|
-
}
|
|
77
|
-
interface TwoFactorPolicy {
|
|
78
|
-
onCircuitBreakerReset: boolean;
|
|
79
|
-
onTierChange: boolean;
|
|
80
|
-
onHighValueTx: boolean;
|
|
81
|
-
highValueThreshold: number;
|
|
82
|
-
onNewSiteApproval: boolean;
|
|
83
|
-
}
|
|
84
64
|
type TierName = "I'm Too Young to Die" | "Hey, Not Too Rough" | "Hurt Me Plenty" | "Ultra-Violence" | "Nightmare!";
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
65
|
+
type WeaponName = "Fists" | "Chainsaw" | "Pistol" | "Shotgun" | "Super Shotgun" | "Chaingun" | "Rocket Launcher" | "Plasma Rifle" | "BFG9000";
|
|
66
|
+
type PickupName = "Medkit" | "Stimpak" | "Soul Sphere" | "New Game";
|
|
67
|
+
interface AutospendConfig {
|
|
68
|
+
tier: TierName;
|
|
69
|
+
weapon: WeaponName;
|
|
70
|
+
}
|
|
71
|
+
interface AutospendState {
|
|
72
|
+
balance: number;
|
|
88
73
|
}
|
|
89
74
|
interface X402Config {
|
|
90
75
|
proofConstructor?: (challenge: Challenge) => Promise<Proof>;
|
|
@@ -92,42 +77,6 @@ interface X402Config {
|
|
|
92
77
|
brc105Wallet?: Brc105Wallet;
|
|
93
78
|
onProofError?: (error: unknown, protocol: PaymentProtocol) => void;
|
|
94
79
|
}
|
|
95
|
-
interface YellowLightEvent {
|
|
96
|
-
origin: string;
|
|
97
|
-
currentSpend: number;
|
|
98
|
-
limit: number;
|
|
99
|
-
window: TimeWindow;
|
|
100
|
-
challenge: Challenge | PaymentRequest;
|
|
101
|
-
}
|
|
102
|
-
interface LedgerEntry {
|
|
103
|
-
timestamp: number;
|
|
104
|
-
origin: string;
|
|
105
|
-
satoshis: number;
|
|
106
|
-
txid: string;
|
|
107
|
-
protocol?: PaymentProtocol;
|
|
108
|
-
}
|
|
109
|
-
interface LimitState {
|
|
110
|
-
entries: LedgerEntry[];
|
|
111
|
-
circuitBroken: boolean;
|
|
112
|
-
hmac: string;
|
|
113
|
-
}
|
|
114
|
-
type BlockSeverity = "reject" | "window" | "trip";
|
|
115
|
-
type LimitCheckResult = {
|
|
116
|
-
action: "allow";
|
|
117
|
-
} | {
|
|
118
|
-
action: "yellow-light";
|
|
119
|
-
detail: YellowLightEvent;
|
|
120
|
-
} | {
|
|
121
|
-
action: "block";
|
|
122
|
-
reason: string;
|
|
123
|
-
severity: BlockSeverity;
|
|
124
|
-
};
|
|
125
|
-
interface StorageAdapter {
|
|
126
|
-
load(): Promise<LimitState | null>;
|
|
127
|
-
save(state: LimitState): Promise<void>;
|
|
128
|
-
loadSitePolicies(): Promise<Record<string, SitePolicy>>;
|
|
129
|
-
saveSitePolicies(policies: Record<string, SitePolicy>): Promise<void>;
|
|
130
|
-
}
|
|
131
80
|
interface CWICreateActionOutput {
|
|
132
81
|
satoshis: number;
|
|
133
82
|
lockingScript: string;
|
|
@@ -150,28 +99,6 @@ interface CWICreateActionResult {
|
|
|
150
99
|
rawTx?: string;
|
|
151
100
|
tx?: number[];
|
|
152
101
|
}
|
|
153
|
-
type TwoFactorAction = {
|
|
154
|
-
type: "circuit-breaker-reset";
|
|
155
|
-
} | {
|
|
156
|
-
type: "tier-change";
|
|
157
|
-
from: TierName;
|
|
158
|
-
to: TierName;
|
|
159
|
-
} | {
|
|
160
|
-
type: "high-value-tx";
|
|
161
|
-
amount: number;
|
|
162
|
-
origin: string;
|
|
163
|
-
} | {
|
|
164
|
-
type: "new-site-approval";
|
|
165
|
-
origin: string;
|
|
166
|
-
} | {
|
|
167
|
-
type: "limit-override";
|
|
168
|
-
amount: number;
|
|
169
|
-
origin: string;
|
|
170
|
-
reason: string;
|
|
171
|
-
};
|
|
172
|
-
interface TwoFactorProvider {
|
|
173
|
-
verify(action: TwoFactorAction): Promise<boolean>;
|
|
174
|
-
}
|
|
175
102
|
|
|
176
103
|
type X402FetchFn = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
177
104
|
declare function createX402Fetch(config?: X402Config): X402FetchFn;
|
|
@@ -200,62 +127,46 @@ declare function parseBrc105Challenge(response: Response): Brc105Challenge;
|
|
|
200
127
|
* 4. Call wallet.createAction with the locking script and custom instructions
|
|
201
128
|
* 5. Convert transaction to base64
|
|
202
129
|
*/
|
|
203
|
-
declare function constructBrc105Proof(challenge: Brc105Challenge, wallet: Brc105Wallet, origin?: string): Promise<
|
|
204
|
-
|
|
205
|
-
/** Anything with a numeric `amount` can be checked against spending limits. */
|
|
206
|
-
type SpendCheckable = Challenge | PaymentRequest;
|
|
207
|
-
declare const BFG_DAILY_CEILING_SATOSHIS = 10000000000;
|
|
208
|
-
declare const BFG_PER_TX_CEILING_SATOSHIS = 1000000000;
|
|
209
|
-
declare const TIER_PRESETS: Record<TierName, TierPreset>;
|
|
210
|
-
declare function resolveSpendLimits(tier?: TierName, mode?: SpendMode, overrides?: Partial<SpendLimits>): SpendLimits;
|
|
211
|
-
declare class RateLimiter {
|
|
212
|
-
private entries;
|
|
213
|
-
private limits;
|
|
214
|
-
private broken;
|
|
215
|
-
private now;
|
|
216
|
-
constructor(limits: SpendLimits, state?: LimitState, now?: () => number);
|
|
217
|
-
check(request: SpendCheckable, origin: string): LimitCheckResult;
|
|
218
|
-
record(entry: LedgerEntry): void;
|
|
219
|
-
trip(): void;
|
|
220
|
-
reset(): void;
|
|
221
|
-
isBroken(): boolean;
|
|
222
|
-
getState(): LimitState;
|
|
223
|
-
private hasCustomPolicy;
|
|
224
|
-
private effectiveWindows;
|
|
225
|
-
private effectivePerTxMax;
|
|
226
|
-
private entriesInWindow;
|
|
227
|
-
private sumSatoshis;
|
|
228
|
-
private prune;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
type KeyDeriver = () => Promise<Uint8Array>;
|
|
232
|
-
declare class LocalStorageAdapter implements StorageAdapter {
|
|
233
|
-
private keyDeriver?;
|
|
234
|
-
private storage;
|
|
235
|
-
constructor(keyDeriver?: KeyDeriver, storage?: Pick<Storage, "getItem" | "setItem">);
|
|
236
|
-
load(): Promise<LimitState | null>;
|
|
237
|
-
save(state: LimitState): Promise<void>;
|
|
238
|
-
loadSitePolicies(): Promise<Record<string, SitePolicy>>;
|
|
239
|
-
saveSitePolicies(policies: Record<string, SitePolicy>): Promise<void>;
|
|
240
|
-
}
|
|
130
|
+
declare function constructBrc105Proof(challenge: Brc105Challenge, wallet: Brc105Wallet, origin?: string): Promise<Brc105ProofResult>;
|
|
241
131
|
|
|
242
132
|
/**
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
* A malicious page script cannot forge a wallet signature.
|
|
133
|
+
* Autospend balance cap per tier (max sats that can be auto-spent without confirmation).
|
|
134
|
+
* Doom II difficulty progression — each tier is 10x the previous.
|
|
246
135
|
*/
|
|
247
|
-
declare
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
136
|
+
declare const TIER_CAPS: Record<TierName, number>;
|
|
137
|
+
/**
|
|
138
|
+
* Per-tx max per weapon. BFG9000 has no hard cap — it's bound only by the
|
|
139
|
+
* autospend balance at payment time.
|
|
140
|
+
*/
|
|
141
|
+
declare const WEAPON_CAPS: Record<WeaponName, number>;
|
|
142
|
+
/**
|
|
143
|
+
* Pickup percentages — how much of the tier cap each pickup restores.
|
|
144
|
+
*/
|
|
145
|
+
declare const PICKUP_PERCENTAGES: Record<PickupName, number>;
|
|
146
|
+
type PaymentDecision = "auto" | "confirm";
|
|
147
|
+
declare function checkPayment(amount: number, state: AutospendState, config: AutospendConfig): PaymentDecision;
|
|
148
|
+
/**
|
|
149
|
+
* Deduct a payment from the autospend balance.
|
|
150
|
+
* Balance can never go below zero. Invalid amounts are ignored.
|
|
151
|
+
*/
|
|
152
|
+
declare function recordPayment(amount: number, state: AutospendState): AutospendState;
|
|
153
|
+
/**
|
|
154
|
+
* Apply a pickup to the autospend state.
|
|
155
|
+
*
|
|
156
|
+
* - Medkit / Stimpak / Soul Sphere: add a percentage of tier cap to current balance
|
|
157
|
+
* - New Game: reset balance to tier cap (not additive)
|
|
158
|
+
*
|
|
159
|
+
* All pickups are capped by `min(tierCap, walletBalance)`.
|
|
160
|
+
*/
|
|
161
|
+
declare function applyPickup(pickup: PickupName, state: AutospendState, config: AutospendConfig, walletBalance: number): AutospendState;
|
|
162
|
+
/**
|
|
163
|
+
* Clamp the autospend balance to the current tier cap and wallet balance.
|
|
164
|
+
* Used after a tier change to ensure the balance doesn't exceed the new cap.
|
|
165
|
+
*/
|
|
166
|
+
declare function clampBalanceToTier(state: AutospendState, config: AutospendConfig, walletBalance: number): AutospendState;
|
|
253
167
|
/**
|
|
254
|
-
*
|
|
255
|
-
* If the origin already has a policy, returns it.
|
|
256
|
-
* If not, and requirePerSitePrompt is true, prompts the user.
|
|
257
|
-
* Otherwise falls back to global limits.
|
|
168
|
+
* Create a fresh autospend state at the tier cap.
|
|
258
169
|
*/
|
|
259
|
-
declare function
|
|
170
|
+
declare function initialState(config: AutospendConfig, walletBalance: number): AutospendState;
|
|
260
171
|
|
|
261
|
-
export {
|
|
172
|
+
export { type AutospendConfig, type AutospendState, type Brc105Challenge, type Brc105Proof, type Brc105ProofConstructor, type Brc105Wallet, type CWICreateActionOutput, type CWICreateActionParams, type CWICreateActionResult, type Challenge, PICKUP_PERCENTAGES, type PaymentDecision, type PaymentProtocol, type PaymentRequest, type PickupName, type Proof, TIER_CAPS, type TierName, WEAPON_CAPS, type WeaponName, type X402Config, type X402FetchFn, applyPickup, checkPayment, clampBalanceToTier, constructBrc105Proof, createX402Fetch, initialState, parseBrc105Challenge, parseChallenge, recordPayment, x402Fetch };
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ interface Challenge {
|
|
|
6
6
|
}
|
|
7
7
|
interface Proof {
|
|
8
8
|
txid: string;
|
|
9
|
-
|
|
9
|
+
beef: string;
|
|
10
10
|
}
|
|
11
11
|
interface Brc105Challenge {
|
|
12
12
|
version: string;
|
|
@@ -37,6 +37,11 @@ interface Brc105Wallet {
|
|
|
37
37
|
hmac: number[];
|
|
38
38
|
}>;
|
|
39
39
|
createAction(params: CWICreateActionParams): Promise<CWICreateActionResult>;
|
|
40
|
+
abortAction?: (args: {
|
|
41
|
+
reference: string;
|
|
42
|
+
}) => Promise<{
|
|
43
|
+
aborted: boolean;
|
|
44
|
+
}>;
|
|
40
45
|
}
|
|
41
46
|
interface Brc105Proof {
|
|
42
47
|
derivationPrefix: string;
|
|
@@ -45,46 +50,26 @@ interface Brc105Proof {
|
|
|
45
50
|
clientIdentityKey: string;
|
|
46
51
|
txid: string;
|
|
47
52
|
}
|
|
48
|
-
|
|
53
|
+
interface Brc105ProofResult {
|
|
54
|
+
proof: Brc105Proof;
|
|
55
|
+
abort?: () => Promise<void>;
|
|
56
|
+
}
|
|
57
|
+
type Brc105ProofConstructor = (challenge: Brc105Challenge) => Promise<Brc105ProofResult>;
|
|
49
58
|
type PaymentProtocol = 'x402' | 'brc105';
|
|
50
59
|
interface PaymentRequest {
|
|
51
60
|
amount: number;
|
|
52
61
|
origin: string;
|
|
53
62
|
protocol: PaymentProtocol;
|
|
54
63
|
}
|
|
55
|
-
type SpendMode = "interactive" | "programmatic";
|
|
56
|
-
type TimeWindow = "minute" | "hour" | "day" | "week";
|
|
57
|
-
interface WindowLimit {
|
|
58
|
-
window: TimeWindow;
|
|
59
|
-
maxSatoshis: number;
|
|
60
|
-
maxTransactions: number;
|
|
61
|
-
}
|
|
62
|
-
interface SpendLimits {
|
|
63
|
-
windows: WindowLimit[];
|
|
64
|
-
perTxMaxSatoshis: number;
|
|
65
|
-
yellowLightThreshold: number;
|
|
66
|
-
requirePerSitePrompt: boolean;
|
|
67
|
-
sitePolicies: Record<string, SitePolicy>;
|
|
68
|
-
require2fa: TwoFactorPolicy;
|
|
69
|
-
}
|
|
70
|
-
type SitePolicyAction = "global" | "custom" | "block";
|
|
71
|
-
interface SitePolicy {
|
|
72
|
-
origin: string;
|
|
73
|
-
action: SitePolicyAction;
|
|
74
|
-
limits?: WindowLimit[];
|
|
75
|
-
perTxMaxSatoshis?: number;
|
|
76
|
-
}
|
|
77
|
-
interface TwoFactorPolicy {
|
|
78
|
-
onCircuitBreakerReset: boolean;
|
|
79
|
-
onTierChange: boolean;
|
|
80
|
-
onHighValueTx: boolean;
|
|
81
|
-
highValueThreshold: number;
|
|
82
|
-
onNewSiteApproval: boolean;
|
|
83
|
-
}
|
|
84
64
|
type TierName = "I'm Too Young to Die" | "Hey, Not Too Rough" | "Hurt Me Plenty" | "Ultra-Violence" | "Nightmare!";
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
65
|
+
type WeaponName = "Fists" | "Chainsaw" | "Pistol" | "Shotgun" | "Super Shotgun" | "Chaingun" | "Rocket Launcher" | "Plasma Rifle" | "BFG9000";
|
|
66
|
+
type PickupName = "Medkit" | "Stimpak" | "Soul Sphere" | "New Game";
|
|
67
|
+
interface AutospendConfig {
|
|
68
|
+
tier: TierName;
|
|
69
|
+
weapon: WeaponName;
|
|
70
|
+
}
|
|
71
|
+
interface AutospendState {
|
|
72
|
+
balance: number;
|
|
88
73
|
}
|
|
89
74
|
interface X402Config {
|
|
90
75
|
proofConstructor?: (challenge: Challenge) => Promise<Proof>;
|
|
@@ -92,42 +77,6 @@ interface X402Config {
|
|
|
92
77
|
brc105Wallet?: Brc105Wallet;
|
|
93
78
|
onProofError?: (error: unknown, protocol: PaymentProtocol) => void;
|
|
94
79
|
}
|
|
95
|
-
interface YellowLightEvent {
|
|
96
|
-
origin: string;
|
|
97
|
-
currentSpend: number;
|
|
98
|
-
limit: number;
|
|
99
|
-
window: TimeWindow;
|
|
100
|
-
challenge: Challenge | PaymentRequest;
|
|
101
|
-
}
|
|
102
|
-
interface LedgerEntry {
|
|
103
|
-
timestamp: number;
|
|
104
|
-
origin: string;
|
|
105
|
-
satoshis: number;
|
|
106
|
-
txid: string;
|
|
107
|
-
protocol?: PaymentProtocol;
|
|
108
|
-
}
|
|
109
|
-
interface LimitState {
|
|
110
|
-
entries: LedgerEntry[];
|
|
111
|
-
circuitBroken: boolean;
|
|
112
|
-
hmac: string;
|
|
113
|
-
}
|
|
114
|
-
type BlockSeverity = "reject" | "window" | "trip";
|
|
115
|
-
type LimitCheckResult = {
|
|
116
|
-
action: "allow";
|
|
117
|
-
} | {
|
|
118
|
-
action: "yellow-light";
|
|
119
|
-
detail: YellowLightEvent;
|
|
120
|
-
} | {
|
|
121
|
-
action: "block";
|
|
122
|
-
reason: string;
|
|
123
|
-
severity: BlockSeverity;
|
|
124
|
-
};
|
|
125
|
-
interface StorageAdapter {
|
|
126
|
-
load(): Promise<LimitState | null>;
|
|
127
|
-
save(state: LimitState): Promise<void>;
|
|
128
|
-
loadSitePolicies(): Promise<Record<string, SitePolicy>>;
|
|
129
|
-
saveSitePolicies(policies: Record<string, SitePolicy>): Promise<void>;
|
|
130
|
-
}
|
|
131
80
|
interface CWICreateActionOutput {
|
|
132
81
|
satoshis: number;
|
|
133
82
|
lockingScript: string;
|
|
@@ -150,28 +99,6 @@ interface CWICreateActionResult {
|
|
|
150
99
|
rawTx?: string;
|
|
151
100
|
tx?: number[];
|
|
152
101
|
}
|
|
153
|
-
type TwoFactorAction = {
|
|
154
|
-
type: "circuit-breaker-reset";
|
|
155
|
-
} | {
|
|
156
|
-
type: "tier-change";
|
|
157
|
-
from: TierName;
|
|
158
|
-
to: TierName;
|
|
159
|
-
} | {
|
|
160
|
-
type: "high-value-tx";
|
|
161
|
-
amount: number;
|
|
162
|
-
origin: string;
|
|
163
|
-
} | {
|
|
164
|
-
type: "new-site-approval";
|
|
165
|
-
origin: string;
|
|
166
|
-
} | {
|
|
167
|
-
type: "limit-override";
|
|
168
|
-
amount: number;
|
|
169
|
-
origin: string;
|
|
170
|
-
reason: string;
|
|
171
|
-
};
|
|
172
|
-
interface TwoFactorProvider {
|
|
173
|
-
verify(action: TwoFactorAction): Promise<boolean>;
|
|
174
|
-
}
|
|
175
102
|
|
|
176
103
|
type X402FetchFn = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
177
104
|
declare function createX402Fetch(config?: X402Config): X402FetchFn;
|
|
@@ -200,62 +127,46 @@ declare function parseBrc105Challenge(response: Response): Brc105Challenge;
|
|
|
200
127
|
* 4. Call wallet.createAction with the locking script and custom instructions
|
|
201
128
|
* 5. Convert transaction to base64
|
|
202
129
|
*/
|
|
203
|
-
declare function constructBrc105Proof(challenge: Brc105Challenge, wallet: Brc105Wallet, origin?: string): Promise<
|
|
204
|
-
|
|
205
|
-
/** Anything with a numeric `amount` can be checked against spending limits. */
|
|
206
|
-
type SpendCheckable = Challenge | PaymentRequest;
|
|
207
|
-
declare const BFG_DAILY_CEILING_SATOSHIS = 10000000000;
|
|
208
|
-
declare const BFG_PER_TX_CEILING_SATOSHIS = 1000000000;
|
|
209
|
-
declare const TIER_PRESETS: Record<TierName, TierPreset>;
|
|
210
|
-
declare function resolveSpendLimits(tier?: TierName, mode?: SpendMode, overrides?: Partial<SpendLimits>): SpendLimits;
|
|
211
|
-
declare class RateLimiter {
|
|
212
|
-
private entries;
|
|
213
|
-
private limits;
|
|
214
|
-
private broken;
|
|
215
|
-
private now;
|
|
216
|
-
constructor(limits: SpendLimits, state?: LimitState, now?: () => number);
|
|
217
|
-
check(request: SpendCheckable, origin: string): LimitCheckResult;
|
|
218
|
-
record(entry: LedgerEntry): void;
|
|
219
|
-
trip(): void;
|
|
220
|
-
reset(): void;
|
|
221
|
-
isBroken(): boolean;
|
|
222
|
-
getState(): LimitState;
|
|
223
|
-
private hasCustomPolicy;
|
|
224
|
-
private effectiveWindows;
|
|
225
|
-
private effectivePerTxMax;
|
|
226
|
-
private entriesInWindow;
|
|
227
|
-
private sumSatoshis;
|
|
228
|
-
private prune;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
type KeyDeriver = () => Promise<Uint8Array>;
|
|
232
|
-
declare class LocalStorageAdapter implements StorageAdapter {
|
|
233
|
-
private keyDeriver?;
|
|
234
|
-
private storage;
|
|
235
|
-
constructor(keyDeriver?: KeyDeriver, storage?: Pick<Storage, "getItem" | "setItem">);
|
|
236
|
-
load(): Promise<LimitState | null>;
|
|
237
|
-
save(state: LimitState): Promise<void>;
|
|
238
|
-
loadSitePolicies(): Promise<Record<string, SitePolicy>>;
|
|
239
|
-
saveSitePolicies(policies: Record<string, SitePolicy>): Promise<void>;
|
|
240
|
-
}
|
|
130
|
+
declare function constructBrc105Proof(challenge: Brc105Challenge, wallet: Brc105Wallet, origin?: string): Promise<Brc105ProofResult>;
|
|
241
131
|
|
|
242
132
|
/**
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
* A malicious page script cannot forge a wallet signature.
|
|
133
|
+
* Autospend balance cap per tier (max sats that can be auto-spent without confirmation).
|
|
134
|
+
* Doom II difficulty progression — each tier is 10x the previous.
|
|
246
135
|
*/
|
|
247
|
-
declare
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
136
|
+
declare const TIER_CAPS: Record<TierName, number>;
|
|
137
|
+
/**
|
|
138
|
+
* Per-tx max per weapon. BFG9000 has no hard cap — it's bound only by the
|
|
139
|
+
* autospend balance at payment time.
|
|
140
|
+
*/
|
|
141
|
+
declare const WEAPON_CAPS: Record<WeaponName, number>;
|
|
142
|
+
/**
|
|
143
|
+
* Pickup percentages — how much of the tier cap each pickup restores.
|
|
144
|
+
*/
|
|
145
|
+
declare const PICKUP_PERCENTAGES: Record<PickupName, number>;
|
|
146
|
+
type PaymentDecision = "auto" | "confirm";
|
|
147
|
+
declare function checkPayment(amount: number, state: AutospendState, config: AutospendConfig): PaymentDecision;
|
|
148
|
+
/**
|
|
149
|
+
* Deduct a payment from the autospend balance.
|
|
150
|
+
* Balance can never go below zero. Invalid amounts are ignored.
|
|
151
|
+
*/
|
|
152
|
+
declare function recordPayment(amount: number, state: AutospendState): AutospendState;
|
|
153
|
+
/**
|
|
154
|
+
* Apply a pickup to the autospend state.
|
|
155
|
+
*
|
|
156
|
+
* - Medkit / Stimpak / Soul Sphere: add a percentage of tier cap to current balance
|
|
157
|
+
* - New Game: reset balance to tier cap (not additive)
|
|
158
|
+
*
|
|
159
|
+
* All pickups are capped by `min(tierCap, walletBalance)`.
|
|
160
|
+
*/
|
|
161
|
+
declare function applyPickup(pickup: PickupName, state: AutospendState, config: AutospendConfig, walletBalance: number): AutospendState;
|
|
162
|
+
/**
|
|
163
|
+
* Clamp the autospend balance to the current tier cap and wallet balance.
|
|
164
|
+
* Used after a tier change to ensure the balance doesn't exceed the new cap.
|
|
165
|
+
*/
|
|
166
|
+
declare function clampBalanceToTier(state: AutospendState, config: AutospendConfig, walletBalance: number): AutospendState;
|
|
253
167
|
/**
|
|
254
|
-
*
|
|
255
|
-
* If the origin already has a policy, returns it.
|
|
256
|
-
* If not, and requirePerSitePrompt is true, prompts the user.
|
|
257
|
-
* Otherwise falls back to global limits.
|
|
168
|
+
* Create a fresh autospend state at the tier cap.
|
|
258
169
|
*/
|
|
259
|
-
declare function
|
|
170
|
+
declare function initialState(config: AutospendConfig, walletBalance: number): AutospendState;
|
|
260
171
|
|
|
261
|
-
export {
|
|
172
|
+
export { type AutospendConfig, type AutospendState, type Brc105Challenge, type Brc105Proof, type Brc105ProofConstructor, type Brc105Wallet, type CWICreateActionOutput, type CWICreateActionParams, type CWICreateActionResult, type Challenge, PICKUP_PERCENTAGES, type PaymentDecision, type PaymentProtocol, type PaymentRequest, type PickupName, type Proof, TIER_CAPS, type TierName, WEAPON_CAPS, type WeaponName, type X402Config, type X402FetchFn, applyPickup, checkPayment, clampBalanceToTier, constructBrc105Proof, createX402Fetch, initialState, parseBrc105Challenge, parseChallenge, recordPayment, x402Fetch };
|