@priors/mcp 0.15.0 → 0.17.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/CHANGELOG.md +80 -2
- package/README.md +58 -27
- package/deployments/4663.agent-lease.json +46 -0
- package/package.json +2 -2
- package/src/agent-lease.mjs +6 -7
- package/src/key-file.mjs +37 -12
- package/src/market-plan.mjs +25 -4
- package/src/market-tools.mjs +45 -14
- package/src/pt-onestep-core.cjs +128 -0
- package/src/rialto.mjs +217 -0
- package/src/server.mjs +169 -10
- package/src/stock-tools.mjs +63 -10
- package/src/stock-trade.mjs +200 -11
- package/src/work-types.mjs +11 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,11 +1,89 @@
|
|
|
1
1
|
# @priors/mcp changelog
|
|
2
2
|
|
|
3
|
+
## 0.17.0 (2026-11-04)
|
|
4
|
+
|
|
5
|
+
On @priors/x402 0.8.6, as 0.16.0.
|
|
6
|
+
|
|
7
|
+
- **Rialto's route checks the quote's transaction, not only its JSON** (GHSA-cqcw-9qjc-5qc7, reported by
|
|
8
|
+
@hey-research-lab; only with `PRIORS_STOCKS` and `PRIORS_RIALTO=on`, both off by default). 0.16.0 checked the gate's
|
|
9
|
+
JSON terms (this wallet as taker, the tokens, the amount, a minimum within the slippage), then sent the quote's
|
|
10
|
+
transaction data as it came, and the router's swap carries its own recipient and minimum: an answer whose JSON was
|
|
11
|
+
honest and whose data was not could pay up to the amount sold to another address, or fill at any price. The data is
|
|
12
|
+
now decoded (`src/rialto.mjs` `decodeSwap`, `checkSwap`, `sdk/rialto.mjs` in the repository) and Rialto's route is
|
|
13
|
+
taken only when it is the router's swap of the tokens and the amount checked, paid to this wallet, with at least the
|
|
14
|
+
quote's minimum and a deadline at most 30 minutes after the plan's block. Anything else keeps the pinned trade, and
|
|
15
|
+
the answer says why. The minimum shown and sent is the transaction's own, and a sale's value is counted from it. Priors'
|
|
16
|
+
gas gate and Go mode hold Rialto's quotes to the same check.
|
|
17
|
+
- `pt_buy_and_deposit` (only with `PRIORS_PT_ONESTEP=on`, off by default; docs/PT-USDG.md in the repository, "One step:
|
|
18
|
+
buy and back a line"): PT-USDG bought with the wallet's USDG and deposited, with the PT-USDG the wallet already holds,
|
|
19
|
+
behind the agent's line on the Priors stock vault in one call. Its plan and its four calls are Go mode's own
|
|
20
|
+
(`src/pt-onestep-core.cjs`, the site's `web/pt-onestep-core.js` byte for byte): the exact USDG approval to Pendle's
|
|
21
|
+
router, the buy with its minimum out from the oracle's spot rate less the slippage (at most 3%), the exact PT-USDG
|
|
22
|
+
approval to the vault, then the vault's open with this wallet's pool consent, checked against the pool's
|
|
23
|
+
`consentDigest` before it is signed. Refused before anything is signed when the wallet does not own the agent, the agent
|
|
24
|
+
has an open line, the vault takes no new PT-USDG line, the line would be under the pool's smallest, or over a cap.
|
|
25
|
+
`pt_buy`'s caps count it. Off, the server is as before, word for word.
|
|
26
|
+
|
|
27
|
+
## 0.16.0 (2026-11-02)
|
|
28
|
+
|
|
29
|
+
On @priors/x402 0.8.6 (Autopay's `OWNER_IS_WALLET`, below).
|
|
30
|
+
|
|
31
|
+
- **Rialto's route for `stock_buy` and `stock_sell`** (`PRIORS_RIALTO`, off by default; off, every list, instruction
|
|
32
|
+
and answer is as before, and nothing is asked of anyone). With it on, a trade that passes every check is also quoted
|
|
33
|
+
by Rialto through Priors' gas gate (`priors_stockQuote` at `PRIORS_STOCK_QUOTE_URL`, default
|
|
34
|
+
`https://priors.trade/gas`). Rialto's API key stays on the gate, never in this package. The quote is checked again
|
|
35
|
+
here: the router Rialto's Router Registry names on chain, the tokens, the amount, this wallet, the slippage, and
|
|
36
|
+
Chainlink's 5% for its output and its minimum. It is taken only when it gives more of the token bought than the
|
|
37
|
+
pinned pool: an approval of exactly the amount sold to that router, then Rialto's transaction, its gas estimated
|
|
38
|
+
first. Otherwise the pinned trade goes ahead as before, and the answer says why. The answer names the route, both
|
|
39
|
+
quotes, Rialto's fee and quote id, what the wallet received and the router's allowance after (0 after a full fill). No
|
|
40
|
+
Priors fee. `src/rialto.mjs` (`sdk/rialto.mjs` in the repository) is bundled byte for byte.
|
|
41
|
+
- **AgentLease's record is in this package** (`deployments/4663.agent-lease.json`: AgentLease
|
|
42
|
+
`0xF2299A992879764ceF0107Aa9Beb07AdfBe0e479` on Robinhood Chain, deployed 2026-11-01, its market this package's
|
|
43
|
+
AgentMarketV2). So with `PRIORS_MARKET` on, `market_buy` and `market_accept` now claim on a stored lease around a
|
|
44
|
+
change of hands, as 0.15.0 set out: they read the lease stored on the agent (`leaseOf`) and, while one is stored, send
|
|
45
|
+
`claim` on the lease before the change of hands and after it (gas only), the client rule of `docs/AGENT-LEASE.md`, so
|
|
46
|
+
each day's rent goes to whoever held the agent when the day ended. `market_agent` says who runs a rented agent and
|
|
47
|
+
until when.
|
|
48
|
+
- **The market tools' day count holds what each step commits** (`PRIORS_MARKET`): a step whose answer is lost
|
|
49
|
+
(`TX_UNCONFIRMED`) adds what it alone commits, an approval nothing and a buy, a bid or a bond its amount, and what the
|
|
50
|
+
steps mined before it committed stays counted. A bond mined before a later step's answer was lost was released from
|
|
51
|
+
`PRIORS_MAX_MARKET_DAY_USD` (GHSA-pg36-8pmq-5p4v), and an approval whose answer was lost counted the whole buy, bid or
|
|
52
|
+
bond, then the retry counted it again (GHSA-m2h8-m55f-9j66).
|
|
53
|
+
- **`market_accept` refuses a bid made before the agent's builder share was set** (its id under the market's
|
|
54
|
+
`builderSince`, which `acceptBid` refuses with `BuilderAfterBid`) before anything is signed, so no cancel, bond or
|
|
55
|
+
approval is sent for it; `market_agent` leaves such a bid out, and the market's refusal is said in its words
|
|
56
|
+
(GHSA-m2h8-m55f-9j66).
|
|
57
|
+
- **Keep back counts what this wallet has committed elsewhere**: before a buy or a bond, what its open bids can still
|
|
58
|
+
take (its approval to the bids' spender) and what payments signed and not settled yet still need are not counted as
|
|
59
|
+
there to repay the agent's open loans (GHSA-m2h8-m55f-9j66). `first_line` keeps the latter back too.
|
|
60
|
+
- **`market_cancel_bid` never sets the bids' approval down while Priors' hub doesn't answer** (bids made elsewhere,
|
|
61
|
+
Go mode's or another machine's, can't be counted then, and would be left unfunded), and with `all` and no open bid it
|
|
62
|
+
sets an approval left standing to 0 (GHSA-m2h8-m55f-9j66).
|
|
63
|
+
- **Stock tools** (`PRIORS_STOCKS`): a swap mined and reverted moved nothing, so it counts neither in
|
|
64
|
+
`PRIORS_MAX_STOCK_TOTAL_USD` nor in the day's trades (GHSA-m2h8-m55f-9j66, GHSA-c4xq-qmpq-6xmm); a sale planned again
|
|
65
|
+
after its approval is held to `PRIORS_MAX_STOCK_TOTAL_USD` at its new quote, before the swap is signed, and counted at
|
|
66
|
+
it (GHSA-c4xq-qmpq-6xmm).
|
|
67
|
+
- **`first_line`** (`PRIORS_JOIN`): a bond deposit the node refused for its gas, or one mined and reverted, no longer
|
|
68
|
+
counts against `PRIORS_MAX_SPEND_DAY_USD` (it already gave back its `PRIORS_MAX_BOND_TOTAL_USD` room).
|
|
69
|
+
- **`PRIORS_KEY_FILE`**: on Windows, an access rule that lets another account change the file or who may read it
|
|
70
|
+
(WriteData, AppendData, WRITE_DAC, WRITE_OWNER, GENERIC_WRITE) refuses the file as read access does; root reading
|
|
71
|
+
another user's key, and `PRIORS_STATE_DIR`, check the directory of every link a chain of symlinks passes through, not
|
|
72
|
+
only the path given and the one it resolves to (GHSA-m2h8-m55f-9j66).
|
|
73
|
+
- **Autopay and auto-borrow** (GHSA-65qg-4h7m-j2cm): an agent whose declared wallet is its owner's own address (what
|
|
74
|
+
`join`'s `register()` leaves) is repaid by AutoRepayV2 under its owner's plan only, never under a wallet plan of that
|
|
75
|
+
address. `autopay_on` enrolled such a plan and said each loan would be repaid from this wallet, and auto-borrow
|
|
76
|
+
(`PRIORS_AUTO_BORROW_USD`) borrowed on it. Now `autopay_on` refuses it before anything is sent (with @priors/x402's
|
|
77
|
+
`OWNER_IS_WALLET`), auto-borrow refuses to borrow on it, and `credit_status` says Autopay is off for this wallet and
|
|
78
|
+
why: declare a key of the agent's own as its wallet (`setAgentWallet`) and turn Autopay on from that key, or repay by
|
|
79
|
+
hand.
|
|
80
|
+
|
|
3
81
|
## 0.15.0 (2026-11-01)
|
|
4
82
|
|
|
5
83
|
- **Auto-borrow, for inference on credit** (`PRIORS_AUTO_BORROW_USD`, off by default): with it set, a `pay_url` (or
|
|
6
84
|
`pay_gateway`) call that names no `max_borrow_usd` borrows the gap on its own when the wallet and the agent's
|
|
7
|
-
savings are short, up to that amount a call, for 14 days. That way an agent buying its own model calls (
|
|
8
|
-
OpenAI-compatible
|
|
85
|
+
savings are short, up to that amount a call, for 14 days. That way an agent buying its own model calls (from an
|
|
86
|
+
OpenAI-compatible model API it chooses, paid over x402 in USDG on Robinhood Chain) keeps working mid-task. The guards:
|
|
9
87
|
- It borrows only while this wallet's Autopay covers the new loan: plan on and current, not held or paused, its
|
|
10
88
|
limit per loan at least the loan's due, its approval enough for that due on top of the loans it already repays.
|
|
11
89
|
Otherwise nothing is borrowed or signed, and the answer says to turn Autopay on.
|
package/README.md
CHANGED
|
@@ -47,6 +47,7 @@ repaying.
|
|
|
47
47
|
| `pt_buy(amount_usdg, slippage_bps?, dry_run?)` | buy PT-USDG with the wallet's USDG through Pendle's router (at most `PRIORS_MAX_PT_USD` per call, `PRIORS_MAX_PT_TOTAL_USD` per run); `dry_run` lists the calls; needs ETH for gas | yes |
|
|
48
48
|
| `pt_sell(amount_pt \| "all", slippage_bps?, dry_run?)` | sell the wallet's PT-USDG for USDG at the market, before maturity; needs ETH for gas | yes |
|
|
49
49
|
| `pt_redeem(amount_pt \| "all", slippage_bps?, dry_run?)` | redeem the wallet's PT-USDG for USDG 1:1, from maturity (2027-03-25) on; needs ETH for gas | yes |
|
|
50
|
+
| `pt_buy_and_deposit(amount_usdg, agent_id?, include_held?, slippage_bps?, dry_run?)` | only with `PRIORS_PT_ONESTEP=on` (below): buy PT-USDG with the wallet's USDG and deposit it, with the PT-USDG the wallet already holds (unless `include_held` is false), behind the agent's line on the Priors stock vault, which opens the line, in one call: four transactions (the exact USDG approval, the buy with its minimum out, the exact PT-USDG approval to the vault, the vault's open with this wallet's pool consent). The wallet must own the agent, and the agent must have no open stock line; checked before the first is signed. `pt_buy`'s caps apply; `dry_run` lists the calls; needs ETH for gas | yes |
|
|
50
51
|
| `fund_base(amount_usd, max_borrow_usd?)` | only with Base on (below): move USDG to USDC in the same address on Base through Across, keeping back what Autopay and signed payments need, borrowing the gap only with `max_borrow_usd`; needs ETH for gas | yes |
|
|
51
52
|
| `return_to_robinhood(amount_usd \| "all")` | only with Base on: move USDC from the Base float back to USDG on Robinhood Chain through Relay, one signature and no gas on Base; keeps back what signed Base payments need | yes |
|
|
52
53
|
| `pay_gateway(service_id, input?, seller_url?, max_price_usd?, max_borrow_usd?, use_savings?)` | (since 0.10.0) only with `PRIORS_GATEWAY=on` (below): buy one call from a seller in Vantis' Keyring catalog with one USDG payment on Robinhood Chain through Keyring's gateway, which pays the seller and relays its answer; `pay_url`'s limits and its one payment per purchase apply | yes |
|
|
@@ -102,7 +103,8 @@ trade may need a wider margin.
|
|
|
102
103
|
|
|
103
104
|
The Priors stock vault lists PT-USDG: an agent's owner can post it behind a line in Go mode
|
|
104
105
|
(https://go.priors.trade/account#ac-pt) while the vault takes new PT-USDG lines, and `pt_position` says whether it does
|
|
105
|
-
right now (it reads the vault's hold live). `
|
|
106
|
+
right now (it reads the vault's hold live). With `PRIORS_PT_ONESTEP=on`, `pt_buy_and_deposit` buys PT-USDG and deposits it
|
|
107
|
+
behind the agent's line in one call. `PRIORS_PT=off` removes the PT-USDG tools.
|
|
106
108
|
|
|
107
109
|
## Trading agents (off by default)
|
|
108
110
|
|
|
@@ -120,8 +122,8 @@ nothing changes: no tool, no sentence in the instructions, and none of the setti
|
|
|
120
122
|
| `market_buy` | an approval of exactly the price when the USDG approved is short, then `buy`, pinned to the listing read (its nonce, the agent's file, its record) |
|
|
121
123
|
| `market_bid` | an approval to the bids' spender of exactly what all of this wallet's open bids take, when it is short or above `PRIORS_MAX_BIDS_USD`, then `bid` |
|
|
122
124
|
| `market_bid_any` | the same approval, then `bidAny` on the origin's list from Priors' hub, its ids checked against its root first. The root proves only that the list is the hub's: any agent on it can be sold to this wallet, so the answer names the list and its first ids, and the bid asks at least 1 repaid loan unless `min_repaid` says otherwise |
|
|
123
|
-
| `market_cancel_bid` | `cancelBid` for one bid, or `all` (at most 10 a call), then the approval set down to what the bids left take |
|
|
124
|
-
| `market_accept` | the cancels and the bond as `market_list` (the bond stays on the agent after the sale until its new owner bonds), the registry's approval, then `acceptBid` with what this wallet gets pinned exactly |
|
|
125
|
+
| `market_cancel_bid` | `cancelBid` for one bid, or `all` (at most 10 a call), then the approval set down to what the bids left take (left as it is while Priors' hub doesn't answer, since bids made elsewhere can't be counted then; with `all` and no open bid, an approval left standing is set to 0) |
|
|
126
|
+
| `market_accept` | the cancels and the bond as `market_list` (the bond stays on the agent after the sale until its new owner bonds), the registry's approval, then `acceptBid` with what this wallet gets pinned exactly; a bid made before the agent's builder share was set, which the market refuses, is refused before anything is sent |
|
|
125
127
|
|
|
126
128
|
Every write tool has `dry_run`. Every rule of the market is checked on reads taken at one block before anything is
|
|
127
129
|
signed; each step is simulated just before it is signed, and before each later step everything is read and planned
|
|
@@ -129,12 +131,12 @@ again: a listing, a nonce, a pin or a net that changed stops the call, and the a
|
|
|
129
131
|
mined leave standing (an approval lets only this wallet's own list, buy or bids use it). A sale's net is the price less
|
|
130
132
|
the fee, and less the agent's builder share where the market has one.
|
|
131
133
|
|
|
132
|
-
Renting (AgentLease),
|
|
133
|
-
|
|
134
|
-
on the lease before and after the change of hands while a lease is stored on the agent (`claim`,
|
|
135
|
-
change of hands on Priors does, so each day's rent goes to whoever held the agent when the day
|
|
136
|
-
says who runs a rented agent and until when. A claim after that can't be sent, or doesn't go
|
|
137
|
-
as it is, and the answer says so, a retry's from the market record too.
|
|
134
|
+
Renting (AgentLease), since 0.16.0, which carries the lease's record (`deployments/4663.agent-lease.json`, AgentLease
|
|
135
|
+
`0xF2299A992879764ceF0107Aa9Beb07AdfBe0e479`): a rented agent changes hands with its lease, and `market_buy` and
|
|
136
|
+
`market_accept` claim on the lease before and after the change of hands while a lease is stored on the agent (`claim`,
|
|
137
|
+
gas only), as every change of hands on Priors does, so each day's rent goes to whoever held the agent when the day
|
|
138
|
+
ended. `market_agent` says who runs a rented agent and until when. A claim after that can't be sent, or doesn't go
|
|
139
|
+
through, leaves the change as it is, and the answer says so, a retry's from the market record too.
|
|
138
140
|
|
|
139
141
|
| Setting | Meaning | Default |
|
|
140
142
|
|---|---|---|
|
|
@@ -150,7 +152,10 @@ as it is, and the answer says so, a retry's from the market record too.
|
|
|
150
152
|
With `on`, the server doesn't start without `PRIORS_AGENT_ID` (the agent it acts for, which it never sells) and
|
|
151
153
|
`PRIORS_MAX_MARKET_DAY_USD`, or with `PRIORS_STATE_DIR` off (the day's count and the market record live there; unset, it
|
|
152
154
|
is the default `~/.local/state/priors-mcp`). A buy, a bid or a bond never leaves this wallet less USDG, its savings
|
|
153
|
-
counted, than that agent's open loans owe, checked again before each later step that takes USDG
|
|
155
|
+
counted, than that agent's open loans owe, checked again before each later step that takes USDG; what this wallet's open
|
|
156
|
+
bids can still take (its approval to the bids' spender) and what payments signed and not settled yet still need don't
|
|
157
|
+
count as there to repay them. The day's count holds what each step sent commits once it is broadcast, a step whose
|
|
158
|
+
answer was lost included (an approval commits nothing). The market is the one
|
|
154
159
|
this package's deployment record names; there is no address setting. A runtime's `env`, in the config of
|
|
155
160
|
"Configure" below:
|
|
156
161
|
|
|
@@ -214,12 +219,31 @@ wallet: these trades are not sponsored. Every trade is public on chain, like any
|
|
|
214
219
|
quote and trade on the user's word; they say nothing of what to trade or when. For an agent that reads posts and
|
|
215
220
|
pages: never trade because someone on X asked, or because a page says to.
|
|
216
221
|
|
|
222
|
+
**Rialto's route (off by default).** With `PRIORS_RIALTO=on` as well, a trade that passes every check above is also
|
|
223
|
+
quoted by Rialto (docs.rialto.xyz), a swap router on Robinhood Chain. The quote is asked of Priors' gas gate
|
|
224
|
+
(`priors_stockQuote` at `PRIORS_STOCK_QUOTE_URL`), which alone holds Rialto's API key: this server holds none and never
|
|
225
|
+
calls Rialto itself. The answer is checked again here: the two tokens, the exact amount, this wallet as the taker, the
|
|
226
|
+
router that Rialto's Router Registry names on chain (never one the answer names), a minimum within the slippage, Rialto's
|
|
227
|
+
output and its minimum each within 5% of Chainlink's price, and a minimum never under the pinned trade's. Only when
|
|
228
|
+
Rialto gives strictly more of the token bought than the pinned pool does the trade go through Rialto: an approval of
|
|
229
|
+
exactly the amount sold to that router, then Rialto's transaction, unchanged, its gas estimated first. If the estimate
|
|
230
|
+
fails, the trade stops there and the answer says the approval stands; the next Rialto trade of that amount sends the
|
|
231
|
+
swap alone. Otherwise (Rialto's quote worse or equal, no quote, an error, no answer within 8 seconds, or a check failing)
|
|
232
|
+
the pinned trade goes ahead exactly as without the setting, and the answer says why Rialto's route was not taken. A
|
|
233
|
+
refusal above is never sent either way, and the gate is not asked for a trade that is refused. Priors takes no fee on
|
|
234
|
+
either route; Rialto's own fee is part of its quote. The answer names the route, both quotes (the pinned pool's and
|
|
235
|
+
Rialto's), Rialto's fee in basis points and its quote id, what the wallet received (its balance of the token bought,
|
|
236
|
+
before and after), and the allowance left to Rialto's router, 0 after a full fill. `dry_run` asks the same and lists the
|
|
237
|
+
route's transactions.
|
|
238
|
+
|
|
217
239
|
| Setting | Meaning | Default |
|
|
218
240
|
|---|---|---|
|
|
219
241
|
| `PRIORS_STOCKS` | `on`: offer `stock_buy` and `stock_sell`, once `PRIORS_STOCKS_ELIGIBLE` is `yes` | off |
|
|
220
242
|
| `PRIORS_STOCKS_ELIGIBLE` | `yes`: the user's statement above | unset |
|
|
221
243
|
| `PRIORS_MAX_STOCK_USD` | the most one buy spends, or one sale brings in by its quote, 1 to 1,000 (the stock buy's most) | 50 |
|
|
222
244
|
| `PRIORS_MAX_STOCK_TOTAL_USD` | the most both may trade in total while the server runs | 200 |
|
|
245
|
+
| `PRIORS_RIALTO` | `on`: Rialto's route, above; any value other than on or off stops the start | off |
|
|
246
|
+
| `PRIORS_STOCK_QUOTE_URL` | with `PRIORS_RIALTO` on: where Rialto's quote is asked, Priors' gas gate (https; http only for localhost) | `https://priors.trade/gas` |
|
|
223
247
|
|
|
224
248
|
With both on, the server doesn't start without `PRIORS_AGENT_ID` (the agent whose open loans a buy leaves covered, and
|
|
225
249
|
whose day is counted) or with `PRIORS_STATE_DIR` off (the day's count lives there, in `stocks/`). A runtime's `env`:
|
|
@@ -230,7 +254,8 @@ whose day is counted) or with `PRIORS_STATE_DIR` off (the day's count lives ther
|
|
|
230
254
|
|
|
231
255
|
The SDK runs the same plan from any key: `stockQuote`, `stockBuy` and `stockSell` in the repository's
|
|
232
256
|
`sdk/stock-trade.mjs` (bundled here byte for byte), each refused unless the caller passes `eligible: true`, which states
|
|
233
|
-
the same, and a buy names `agentId` (or `null` for a key that acts for no agent).
|
|
257
|
+
the same, and a buy names `agentId` (or `null` for a key that acts for no agent). With `rialto: {}` (or
|
|
258
|
+
`{ url, fetch, timeoutMs }`) they take Rialto's route as above, checked by `sdk/rialto.mjs` (bundled here too).
|
|
234
259
|
|
|
235
260
|
## Paying USDC sellers on Base (off by default)
|
|
236
261
|
|
|
@@ -314,7 +339,8 @@ may spend. Rows marked (0.8.0) take effect from that version; 0.7.x ignores them
|
|
|
314
339
|
| `PRIORS_AUTOPAY_RESERVE` | on | with Autopay on, `pay_url` keeps back what loans whose window opens in the next 24 h will pull, and says so when a payment would cut into it; `off` turns that off |
|
|
315
340
|
| `PRIORS_PT` | on | `off` (or `false`, `0`, `no`) removes the PT-USDG tools |
|
|
316
341
|
| `PRIORS_MAX_PT_USD` | `50` | most USDG one `pt_buy` may spend (sales and redemptions only turn the wallet's PT back into USDG) |
|
|
317
|
-
| `PRIORS_MAX_PT_TOTAL_USD` | `200` | most USDG `pt_buy` may spend in total while the server runs (a buy whose transaction was sent counts, even if its answer is lost) |
|
|
342
|
+
| `PRIORS_MAX_PT_TOTAL_USD` | `200` | most USDG `pt_buy` and `pt_buy_and_deposit` may spend in total while the server runs (a buy whose transaction was sent counts, even if its answer is lost) |
|
|
343
|
+
| `PRIORS_PT_ONESTEP` | off | `on`: `pt_buy_and_deposit` (PT-USDG bought and deposited behind the agent's line in one call), with the PT-USDG tools on |
|
|
318
344
|
| `PRIORS_PAY_NETWORKS` | `eip155:4663` | networks `pay_url` pays on, comma-separated; add `eip155:8453` for USDC on Base (also needs `PRIORS_BRIDGE`). Robinhood Chain is always on |
|
|
319
345
|
| `PRIORS_BRIDGE` | `off` | `across`: `fund_base` moves money out through Across (`relay`, the Relay route out, is not built yet); `return_to_robinhood` goes through Relay either way |
|
|
320
346
|
| `PRIORS_BASE_RPC` | `https://mainnet.base.org` | Base JSON-RPC endpoint, read only (a private URL is redacted from every answer) |
|
|
@@ -344,7 +370,7 @@ Settings → Developer → Edit Config (`claude_desktop_config.json`), then rest
|
|
|
344
370
|
"mcpServers": {
|
|
345
371
|
"priors": {
|
|
346
372
|
"command": "npx",
|
|
347
|
-
"args": ["-y", "@priors/mcp@0.
|
|
373
|
+
"args": ["-y", "@priors/mcp@0.17.0"],
|
|
348
374
|
"env": {
|
|
349
375
|
"PRIORS_KEY": "0xYOUR_AGENT_WALLET_KEY",
|
|
350
376
|
"PRIORS_AGENT_ID": "1234"
|
|
@@ -366,7 +392,7 @@ A project `.mcp.json` that reads the key from your shell's environment, so the f
|
|
|
366
392
|
"mcpServers": {
|
|
367
393
|
"priors": {
|
|
368
394
|
"command": "npx",
|
|
369
|
-
"args": ["-y", "@priors/mcp@0.
|
|
395
|
+
"args": ["-y", "@priors/mcp@0.17.0"],
|
|
370
396
|
"env": {
|
|
371
397
|
"PRIORS_KEY": "${PRIORS_KEY}",
|
|
372
398
|
"PRIORS_AGENT_ID": "${PRIORS_AGENT_ID:-}"
|
|
@@ -379,7 +405,7 @@ A project `.mcp.json` that reads the key from your shell's environment, so the f
|
|
|
379
405
|
or, for your user only, from a macOS or Linux terminal:
|
|
380
406
|
|
|
381
407
|
```sh
|
|
382
|
-
(read -rs PRIORS_KEY && umask 077 && mkdir -p ~/.config/priors && rm -f ~/.config/priors/agent.key && printf '%s\n' "$PRIORS_KEY" > ~/.config/priors/agent.key) && claude mcp add priors --scope user -- sh -c 'read -r PRIORS_KEY < "$1" && export PRIORS_KEY && exec npx -y @priors/mcp@0.
|
|
408
|
+
(read -rs PRIORS_KEY && umask 077 && mkdir -p ~/.config/priors && rm -f ~/.config/priors/agent.key && printf '%s\n' "$PRIORS_KEY" > ~/.config/priors/agent.key) && claude mcp add priors --scope user -- sh -c 'read -r PRIORS_KEY < "$1" && export PRIORS_KEY && exec npx -y @priors/mcp@0.17.0' priors-mcp ~/.config/priors/agent.key
|
|
383
409
|
```
|
|
384
410
|
|
|
385
411
|
It waits for the key without showing it (paste it, then Enter), saves it in a file only you can read, and gives Claude
|
|
@@ -404,7 +430,8 @@ macOS or Linux terminal (it waits for the key without showing it):
|
|
|
404
430
|
The server reads the file only when nobody but you can: on Linux and macOS a regular file you own with no group or
|
|
405
431
|
other permission (`chmod 600`; root may read a file another user owns, such as a secret mounted owner-only into a
|
|
406
432
|
container, but only where every directory above it belongs to root or to that user and nobody else can write it, as
|
|
407
|
-
ssh requires: never under /tmp); on Windows a file whose access list lets only you, SYSTEM and Administrators read it
|
|
433
|
+
ssh requires: never under /tmp); on Windows a file whose access list lets only you, SYSTEM and Administrators read it
|
|
434
|
+
or change it (its content, or who may read it),
|
|
408
435
|
which `icacls "C:\Users\you\.config\priors\agent-7311.key" /inheritance:r /grant:r "%USERNAME%:R"` sets. Anything
|
|
409
436
|
else is refused and not read: the server then starts with its read-only tools, and every tool that moves money says
|
|
410
437
|
what to fix. The path is absolute or starts with `~/` (`~\` on Windows; in JSON write `C:\\Users\\…` or `C:/Users/…`). In a
|
|
@@ -430,32 +457,36 @@ internationalised names in their `xn--` form), so a look-alike spelled with othe
|
|
|
430
457
|
the list is refused before any request; pay_url never follows a redirect, and every request the payer sends is checked
|
|
431
458
|
against the list too. A wildcard, a URL or a path in the list stops the server at start.
|
|
432
459
|
|
|
433
|
-
**Inference on credit (`PRIORS_AUTO_BORROW_USD`, 0.15.0).** An agent that buys its own model calls,
|
|
434
|
-
|
|
435
|
-
runs short mid-task. With `PRIORS_AUTO_BORROW_USD` set, a `pay_url` call that names no `max_borrow_usd` takes the
|
|
460
|
+
**Inference on credit (`PRIORS_AUTO_BORROW_USD`, 0.15.0).** An agent that buys its own model calls, from an
|
|
461
|
+
OpenAI-compatible model API you choose that charges over x402 in USDG on Robinhood Chain, can keep working when its
|
|
462
|
+
wallet runs short mid-task. With `PRIORS_AUTO_BORROW_USD` set, a `pay_url` call that names no `max_borrow_usd` takes the
|
|
436
463
|
agent's savings first, then borrows the gap from its Priors line. The loan is the larger of the gap and the pool's
|
|
437
464
|
minimum loan (5 USDG, so one loan pays many 0.02 USDG calls), for 14 days. It borrows only when this wallet's Autopay
|
|
438
465
|
covers the new loan: the plan is on and current, its limit per loan is at least the loan's due, and its approval covers
|
|
439
466
|
that due on top of the loans it already repays. Otherwise nothing is borrowed or signed, and the answer says to turn
|
|
440
|
-
Autopay on (`autopay_on`).
|
|
467
|
+
Autopay on (`autopay_on`). The wallet must be a key of the agent's own, declared with the registry's `setAgentWallet`:
|
|
468
|
+
an agent `join` registered still has this wallet, its owner, as its declared wallet, and AutoRepay repays such an agent
|
|
469
|
+
under its owner's plan only, so `autopay_on` and auto-borrow refuse it. Autopay then repays the loan from the wallet in its window, the last hours before it is due,
|
|
441
470
|
which keeps the loan seasoned. The day's borrow limit and the run's total still hold: once either has no room, a call
|
|
442
471
|
pays from what the wallet holds and says why it did not borrow. A call that names `max_borrow_usd` works as before
|
|
443
|
-
(`0` never borrows).
|
|
472
|
+
(`0` never borrows). There is no default host: auto-borrow pays only the hosts in `PRIORS_PAY_HOSTS`. Suggested
|
|
473
|
+
settings for an agent buying inference (`models.example` stands for the model API's host):
|
|
444
474
|
|
|
445
475
|
```json
|
|
446
|
-
"PRIORS_AUTO_BORROW_USD": "5", "PRIORS_MAX_BORROW_DAY_USD": "10", "PRIORS_PAY_HOSTS": "
|
|
476
|
+
"PRIORS_AUTO_BORROW_USD": "5", "PRIORS_MAX_BORROW_DAY_USD": "10", "PRIORS_PAY_HOSTS": "models.example",
|
|
447
477
|
"PRIORS_AGENT_ID": "7311", "PRIORS_STATE_DIR": "~/.local/state/priors-mcp"
|
|
448
478
|
```
|
|
449
479
|
|
|
450
|
-
Then a chat call: `pay_url` with `url`
|
|
451
|
-
|
|
480
|
+
Then a chat call: `pay_url` with `url` the API's chat completions URL (for example
|
|
481
|
+
`https://models.example/v1/chat/completions`), `method` `POST`, `body` the OpenAI-style request
|
|
482
|
+
(`{"model": "…", "messages": […]}`) and `max_price_usd` the most to pay for the call (for example `0.02`).
|
|
452
483
|
|
|
453
484
|
**A block per runtime.** The hosted connector (`https://mcp.priors.trade/mcp`, no key) reads records and asks the owner
|
|
454
485
|
to approve a borrow; this package, with the key, pays for APIs. With borrowing off, the agent asks and its owner
|
|
455
486
|
approves each loan in Priors' Go mode. ElizaOS (`@elizaos/plugin-mcp`):
|
|
456
487
|
|
|
457
488
|
```ts
|
|
458
|
-
"priors-wallet": { type: "stdio", command: "npx", args: ["-y", "@priors/mcp@0.
|
|
489
|
+
"priors-wallet": { type: "stdio", command: "npx", args: ["-y", "@priors/mcp@0.17.0"],
|
|
459
490
|
env: { PRIORS_KEY_FILE: "/home/agent/.config/priors/agent-7311.key", PRIORS_AGENT_ID: "7311",
|
|
460
491
|
PRIORS_MAX_BORROW_USD: "0", PRIORS_MAX_BORROW_DAY_USD: "0", PRIORS_MAX_SPEND_DAY_USD: "1", PRIORS_MAX_PRICE_USD: "0.10",
|
|
461
492
|
PRIORS_PAY_HOSTS: "api.example.com" } }
|
|
@@ -467,7 +498,7 @@ OpenClaw (`mcp.servers`, JSON5) takes the same `command`, `args` and `env`; Herm
|
|
|
467
498
|
mcp_servers:
|
|
468
499
|
priors-wallet:
|
|
469
500
|
command: npx
|
|
470
|
-
args: ["-y", "@priors/mcp@0.
|
|
501
|
+
args: ["-y", "@priors/mcp@0.17.0"]
|
|
471
502
|
env:
|
|
472
503
|
PRIORS_KEY_FILE: /home/agent/.config/priors/agent-7311.key
|
|
473
504
|
PRIORS_AGENT_ID: "7311"
|
|
@@ -494,7 +525,7 @@ key proves it is there: it signs the ERC-8004 identity registry's `AgentWalletSe
|
|
|
494
525
|
agent's).
|
|
495
526
|
|
|
496
527
|
```sh
|
|
497
|
-
PRIORS_KEY_FILE=~/.config/priors/agent-7311.key npx -y @priors/mcp@0.
|
|
528
|
+
PRIORS_KEY_FILE=~/.config/priors/agent-7311.key npx -y @priors/mcp@0.17.0 link-wallet --agent 7311
|
|
498
529
|
```
|
|
499
530
|
|
|
500
531
|
It reads the registry's EIP-712 domain and refuses to sign for any other, takes the owner from the chain (`--owner`
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"chainId": 4663,
|
|
3
|
+
"agentLease": "0xF2299A992879764ceF0107Aa9Beb07AdfBe0e479",
|
|
4
|
+
"agentLeaseBlock": 103660343,
|
|
5
|
+
"market": "0x6a4583242B8313313E684d02aB7dc6bFf8749670",
|
|
6
|
+
"tx": "0x30e3720f45094c01e9891e170dbe6c68187a7f8769990f193d8261dcd1191dc2",
|
|
7
|
+
"txBlock": 103660343,
|
|
8
|
+
"deployedAt": "2026-11-01T20:25:21Z",
|
|
9
|
+
"deployer": "0x140e38e4eD308e534fBb2Ee3EF057A51b98d5932",
|
|
10
|
+
"nonce": 577,
|
|
11
|
+
"gasUsed": 4431461,
|
|
12
|
+
"salt": "0x1607e98fccc3b56df6921c0595e4fe9051ebc2bfeb46a1ce4548611be2801bfe",
|
|
13
|
+
"constructorArgs": {
|
|
14
|
+
"registry": "0x8004A169FB4a3325136EB29fA0ceB6D2e539a432",
|
|
15
|
+
"usdg": "0x5fc5360D0400a0Fd4f2af552ADD042D716F1d168",
|
|
16
|
+
"poolV2": "0x281210097f0de7A8FB6F87310AF0f089c9C8DE21",
|
|
17
|
+
"poolV1": "0x0259889e6EBab1a18CeE7e62Bc5B9648FB6C44e5",
|
|
18
|
+
"market": "0x6a4583242B8313313E684d02aB7dc6bFf8749670",
|
|
19
|
+
"previous": "0xe5C8b3FacD7802099C1DfB88c0C818Cd0ebA7B19",
|
|
20
|
+
"guardian": "0x20c6816B2419616238772591965E6E9AbE493fD5"
|
|
21
|
+
},
|
|
22
|
+
"constructorArgsEncoded": "0x0000000000000000000000008004a169fb4a3325136eb29fa0ceb6d2e539a4320000000000000000000000005fc5360d0400a0fd4f2af552add042d716f1d168000000000000000000000000281210097f0de7a8fb6f87310af0f089c9c8de210000000000000000000000000259889e6ebab1a18cee7e62bc5b9648fb6c44e50000000000000000000000006a4583242b8313313e684d02ab7dc6bff8749670000000000000000000000000e5c8b3facd7802099c1dfb88c0c818cd0eba7b1900000000000000000000000020c6816b2419616238772591965e6e9abe493fd5",
|
|
23
|
+
"source": "src/AgentLease.sol:AgentLease",
|
|
24
|
+
"sourceCommit": "0ffef5c1e74fd1623d42f45cf9bfcaded43f1704",
|
|
25
|
+
"compiler": {
|
|
26
|
+
"solc": "0.8.26+commit.8a97fa7a",
|
|
27
|
+
"optimizer": true,
|
|
28
|
+
"runs": 200,
|
|
29
|
+
"evmVersion": "cancun",
|
|
30
|
+
"viaIR": false
|
|
31
|
+
},
|
|
32
|
+
"creationCodeHash": "0xd94df7813804743e9c20f9e343f9ee23cc8188948c98912ce6003b06f1ccb8cd",
|
|
33
|
+
"initcodeHash": "0x3465dbbf5d4d99fc77b5b3706dd2323946ecb5a81defbf6cfff55c5f0cbf593f",
|
|
34
|
+
"runtimeCodeHash": "0xd9b292e4f9aac597020934aad823c69b2b24e968d8d69cb0f1b24657cc6d3867",
|
|
35
|
+
"verification": {
|
|
36
|
+
"script": "script/DeployAgentLease.s.sol verify(): the address is CREATE2(factory, salt, this build's initcode) and the runtime code equals a fresh local copy's",
|
|
37
|
+
"sourcify": {
|
|
38
|
+
"match": "exact_match",
|
|
39
|
+
"creationMatch": "exact_match",
|
|
40
|
+
"runtimeMatch": "exact_match",
|
|
41
|
+
"verifiedAt": "2026-11-01T20:26:40Z",
|
|
42
|
+
"url": "https://sourcify.dev/server/v2/contract/4663/0xF2299A992879764ceF0107Aa9Beb07AdfBe0e479"
|
|
43
|
+
},
|
|
44
|
+
"blockscout": "verified (exact match), AgentLease, 2026-11-01T20:26:53Z: https://robinhoodchain.blockscout.com/address/0xF2299A992879764ceF0107Aa9Beb07AdfBe0e479?tab=contract"
|
|
45
|
+
}
|
|
46
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@priors/mcp",
|
|
3
3
|
"mcpName": "io.github.priors-agents/priors",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.17.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "MCP server for Priors on Robinhood Chain: pay x402 URLs in USDG, read balances, credit lines and scores, borrow and repay, and buy, sell and redeem PT-USDG. Key from PRIORS_KEY_FILE (a file only you can read) or PRIORS_KEY, never the command line.",
|
|
7
7
|
"type": "module",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@modelcontextprotocol/sdk": "^1.30.1",
|
|
48
|
-
"@priors/x402": "0.8.
|
|
48
|
+
"@priors/x402": "0.8.6",
|
|
49
49
|
"ethers": "^6.13.4",
|
|
50
50
|
"undici": "6.29.1",
|
|
51
51
|
"viem": "^2.56.9",
|
package/src/agent-lease.mjs
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// the days paid and the refunds, exactly as the contract computes them; the words a lease or an offer shows; and the
|
|
5
5
|
// calls an account sends.
|
|
6
6
|
//
|
|
7
|
-
// A renter runs an agent on Priors for 1 to
|
|
7
|
+
// A renter runs an agent on Priors for 1 to 90 days: it sells the agent's work and takes paid jobs under its name, paid
|
|
8
8
|
// to its own address. It never borrows on the agent's line, never becomes its wallet or its delegate, and never
|
|
9
9
|
// changes its file. The agent stays in its owner's wallet the whole time: the lease never moves it, so its record, its
|
|
10
10
|
// line and its Score v2 stay where they are, and the owner can sell it like any other agent.
|
|
@@ -190,9 +190,9 @@ const DAY = 86_400;
|
|
|
190
190
|
/** The contract's rules, and Go mode's cap on one lease, added days included (goMax, the gas gate's: 600 USDG). */
|
|
191
191
|
export const LEASE_RULES = Object.freeze({
|
|
192
192
|
minRent: 5_000_000n, // 5 USDG in all at the offer's shortest term, as the market's MIN_PRICE
|
|
193
|
-
maxDays:
|
|
193
|
+
maxDays: 90, // MAX_DAYS: a lease runs 1 to 90 days, added days included (the owner's answer of 2026-10-31)
|
|
194
194
|
dayS: DAY,
|
|
195
|
-
maxOfferS: 30 * DAY,
|
|
195
|
+
maxOfferS: 30 * DAY, // MAX_OFFER: an offer stands 30 days at most
|
|
196
196
|
goMax: 600_000_000n,
|
|
197
197
|
});
|
|
198
198
|
|
|
@@ -250,7 +250,7 @@ function offerShape({ dayPrice, minDays, maxDays, renter }) {
|
|
|
250
250
|
}
|
|
251
251
|
|
|
252
252
|
/**
|
|
253
|
-
* Why `offerRent` would refuse these terms, or null: "days" (1 <= minDays <= maxDays <=
|
|
253
|
+
* Why `offerRent` would refuse these terms, or null: "days" (1 <= minDays <= maxDays <= 90), "free" (a day price of 0
|
|
254
254
|
* with no named renter), "low" (under 5 USDG in all at minDays), "fee" (a day not above the fee on the longest term at
|
|
255
255
|
* the market's fee now: DayBelowFee). `feeBps` and `minFee` are the market's, read live; they have no default.
|
|
256
256
|
*/
|
|
@@ -494,7 +494,7 @@ export const LEASE_WORDS = Object.freeze({
|
|
|
494
494
|
controls: "This address can borrow for this agent. Rent from another address.",
|
|
495
495
|
marked: "This address has a defaulted loan on Priors, so it can't rent here. Use another address.",
|
|
496
496
|
record: "Its record changed since you looked. Read it again, then rent.",
|
|
497
|
-
price: "The price
|
|
497
|
+
price: "The price changed since you looked. Read the offer again, then rent.",
|
|
498
498
|
short: "You have {cash} USDG. Add {short} more, then rent.",
|
|
499
499
|
over: "Go mode rents up to 600 USDG a lease, added days included. Choose fewer days.",
|
|
500
500
|
low: "A paid lease costs 5 USDG or more in all, and a day costs more than the fee. Raise the day price.",
|
|
@@ -509,11 +509,10 @@ export const LEASE_WORDS = Object.freeze({
|
|
|
509
509
|
bell: Object.freeze({
|
|
510
510
|
rented: "#{id} is rented until {date}.",
|
|
511
511
|
extended: "#{id}'s lease now runs until {date}.",
|
|
512
|
-
ending: "Your lease on #{id} ends
|
|
512
|
+
ending: "Your lease on #{id} ends within a day, on {date}.",
|
|
513
513
|
endedEarly: "Your lease on #{id} ended early. {refund} USDG came back to you.",
|
|
514
514
|
collect: "{amount} USDG of rent to collect on #{id}.",
|
|
515
515
|
defaulted: "#{id} defaulted, so you can end its lease. The current day and every day after it come back to you.",
|
|
516
|
-
bidRented: "#{id}, which you bid on, is rented until {date}.",
|
|
517
516
|
}),
|
|
518
517
|
});
|
|
519
518
|
|
package/src/key-file.mjs
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
// read one another user owns (a key mounted owner-only into a container), but only when every directory above it, on
|
|
9
9
|
// the path as given and on the path it resolves to, belongs to root or to the file's owner and nobody else can write
|
|
10
10
|
// it: OpenSSH's secure_path rule (in /tmp, or under a directory another user owns, anyone could have put their own key
|
|
11
|
-
// at that path). On Windows, a file whose ACL lets nobody read it but the user, SYSTEM
|
|
12
|
-
// (the rule OpenSSH for Windows applies), read with PowerShell's Get-Acl by SID so the answer does not depend on the
|
|
11
|
+
// at that path). On Windows, a file whose ACL lets nobody read it, or change it or who may read it, but the user, SYSTEM
|
|
12
|
+
// and the Administrators group (the rule OpenSSH for Windows applies), read with PowerShell's Get-Acl by SID so the answer does not depend on the
|
|
13
13
|
// system's language; PowerShell is run from System32 by its full path, never looked up by name (Windows searches the
|
|
14
14
|
// working directory, which the MCP client chooses, before PATH). Anything else is refused, and the key is not read at
|
|
15
15
|
// all: the server then starts with its read-only tools, and every tool that moves money says what to fix.
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
// The path may start with ~/ (or ~\ on Windows), the user's home directory; otherwise it must be absolute, since an
|
|
20
20
|
// MCP client starts the server in a directory of its own choosing. Setting both PRIORS_KEY and PRIORS_KEY_FILE is
|
|
21
21
|
// refused: the server never guesses which key signs.
|
|
22
|
-
import { closeSync, constants, fstatSync, openSync, readSync, realpathSync, statSync } from "node:fs";
|
|
22
|
+
import { closeSync, constants, fstatSync, lstatSync, openSync, readSync, readlinkSync, realpathSync, statSync } from "node:fs";
|
|
23
23
|
import { homedir as osHomedir } from "node:os";
|
|
24
24
|
import path from "node:path";
|
|
25
25
|
import { spawnSync } from "node:child_process";
|
|
@@ -33,6 +33,10 @@ const WIN_TRUSTED = new Set(["S-1-5-18", "S-1-5-32-544"]);
|
|
|
33
33
|
/** FileSystemRights bits that let a holder read the content: ReadData, GENERIC_ALL, GENERIC_READ (FullControl, Modify,
|
|
34
34
|
* Read and ReadAndExecute all include ReadData). */
|
|
35
35
|
const WIN_READ_BITS = [0x1, 0x10000000, 0x80000000];
|
|
36
|
+
/** And the bits that let a holder change the content or who may read it (GHSA-m2h8-m55f-9j66): WriteData, AppendData,
|
|
37
|
+
* WRITE_DAC (a holder grants itself read), WRITE_OWNER (takes the file, then the same) and GENERIC_WRITE. WriteAttributes
|
|
38
|
+
* and Delete are not among them: neither reads the key nor puts another key in its place. */
|
|
39
|
+
const WIN_WRITE_BITS = [0x2, 0x4, 0x40000, 0x80000, 0x40000000];
|
|
36
40
|
|
|
37
41
|
/**
|
|
38
42
|
* The Get-Acl report for `p`, as lines: "ME <sid>", "OWNER <sid>", then "ACE <sid> <Allow|Deny> <rights>" per rule,
|
|
@@ -49,7 +53,8 @@ const ACL_SCRIPT = [
|
|
|
49
53
|
].join("; ");
|
|
50
54
|
|
|
51
55
|
/** Who may read a Windows file, from Get-Acl's report (aclReport): null when only the user, SYSTEM and Administrators
|
|
52
|
-
* can, else a sentence naming the first other SID (and what to
|
|
56
|
+
* can read it or change it (its content, or who may read it), else a sentence naming the first other SID (and what to
|
|
57
|
+
* run). Pure, for tests. */
|
|
53
58
|
export function aclVerdict(report, file) {
|
|
54
59
|
const lines = String(report ?? "").split(/\r?\n/).map((l) => l.trim()).filter(Boolean);
|
|
55
60
|
const me = lines.find((l) => l.startsWith("ME "))?.slice(3).trim();
|
|
@@ -61,9 +66,10 @@ export function aclVerdict(report, file) {
|
|
|
61
66
|
const [, who, type, rights] = l.split(/\s+/);
|
|
62
67
|
if (type !== "Allow") continue; // a Deny rule only takes access away
|
|
63
68
|
const mask = Number(rights) >>> 0; // GENERIC_READ comes back negative as a 32-bit enum
|
|
64
|
-
|
|
69
|
+
const reads = WIN_READ_BITS.some((b) => (mask & b) !== 0), writes = WIN_WRITE_BITS.some((b) => (mask & b) !== 0);
|
|
70
|
+
if (!reads && !writes) continue;
|
|
65
71
|
if (who === me || WIN_TRUSTED.has(who)) continue;
|
|
66
|
-
return `${who === "S-1-1-0" ? "Everyone" : who === "S-1-5-32-545" ? "the Users group" : who === "S-1-5-11" ? "Authenticated Users" : `another account (${who})`} can read it. Let only your own user read it: ${fix}`;
|
|
72
|
+
return `${who === "S-1-1-0" ? "Everyone" : who === "S-1-5-32-545" ? "the Users group" : who === "S-1-5-11" ? "Authenticated Users" : `another account (${who})`} ${reads ? "can read it" : "can change it, or who may read it"}. Let only your own user read it: ${fix}`;
|
|
67
73
|
}
|
|
68
74
|
return null;
|
|
69
75
|
}
|
|
@@ -89,20 +95,39 @@ export function windowsAclReport(file, { spawn = spawnSync, env = process.env }
|
|
|
89
95
|
return r.stdout;
|
|
90
96
|
}
|
|
91
97
|
|
|
98
|
+
/** The paths a chain of symlinks passes through on its way from `p` (each link of its last component, read with lstat
|
|
99
|
+
* and readlink, up to 40), `p` first: a link in the middle of a chain sits in a directory that is neither on the path
|
|
100
|
+
* as given nor on the path it resolves to, and whoever can write that directory can point the chain elsewhere
|
|
101
|
+
* (GHSA-m2h8-m55f-9j66). An lstat or readlink that cannot answer ends the walk there (the realpath check still runs). */
|
|
102
|
+
function chainOf(p, fs) {
|
|
103
|
+
const out = [p];
|
|
104
|
+
if (typeof fs.lstatSync !== "function" || typeof fs.readlinkSync !== "function") return out;
|
|
105
|
+
let cur = p;
|
|
106
|
+
for (let i = 0; i < 40; i++) {
|
|
107
|
+
let next;
|
|
108
|
+
try { if (!fs.lstatSync(cur).isSymbolicLink()) break; next = path.posix.resolve(path.posix.dirname(cur), String(fs.readlinkSync(cur))); } catch (_) { break; }
|
|
109
|
+
if (out.includes(next)) break;
|
|
110
|
+
out.push(next);
|
|
111
|
+
cur = next;
|
|
112
|
+
}
|
|
113
|
+
return out;
|
|
114
|
+
}
|
|
115
|
+
|
|
92
116
|
/**
|
|
93
117
|
* For root reading a POSIX file another user owns: null when nobody but root and the file's owner could have put it at
|
|
94
118
|
* `file`, else what is wrong (in words, never the content). OpenSSH's secure_path rule: every directory above the file
|
|
95
119
|
* belongs to root or to the file's owner and has no group or other write bit (a root-owned sticky /tmp fails too). It
|
|
96
|
-
* is checked on the path as given (whoever can write one of its directories could have put a symlink there)
|
|
97
|
-
*
|
|
98
|
-
* fstat: same device and inode), so nothing was
|
|
120
|
+
* is checked on the path as given (whoever can write one of its directories could have put a symlink there), on each
|
|
121
|
+
* link a chain of symlinks passes through on the way (chainOf), and on the path that resolves to (realpath), up to /,
|
|
122
|
+
* and the resolved file must be the one that was opened (`st`, its fstat: same device and inode), so nothing was
|
|
123
|
+
* swapped in between. `fs` needs realpathSync and statSync (lstatSync and readlinkSync for the chain).
|
|
99
124
|
*/
|
|
100
125
|
export function securePathProblem(file, st, fs) {
|
|
101
126
|
let real, rs;
|
|
102
127
|
try { real = fs.realpathSync(file); rs = fs.statSync(real); } catch (e) { return `its path could not be resolved (${e?.code || "error"})`; }
|
|
103
128
|
if (rs.dev !== st.dev || rs.ino !== st.ino) return "it changed while it was being checked";
|
|
104
129
|
const dirs = [];
|
|
105
|
-
for (const p of [file, real]) {
|
|
130
|
+
for (const p of [...chainOf(file, fs), real]) {
|
|
106
131
|
for (let d = path.posix.dirname(p); ; d = path.posix.dirname(d)) {
|
|
107
132
|
if (!dirs.includes(d)) dirs.push(d);
|
|
108
133
|
if (d === path.posix.dirname(d)) break;
|
|
@@ -132,7 +157,7 @@ export function stateDirProblem(dir, { fs, uid }) {
|
|
|
132
157
|
if (st.uid !== uid) return `it belongs to another user (uid ${st.uid})`;
|
|
133
158
|
if ((st.mode & 0o022) !== 0) return `other users can write to it (mode ${(st.mode & 0o7777).toString(8).padStart(4, "0")})`;
|
|
134
159
|
const dirs = [];
|
|
135
|
-
for (const p of [dir, real]) {
|
|
160
|
+
for (const p of [...chainOf(dir, fs), real]) {
|
|
136
161
|
for (let d = path.posix.dirname(p); ; d = path.posix.dirname(d)) {
|
|
137
162
|
if (!dirs.includes(d)) dirs.push(d);
|
|
138
163
|
if (d === path.posix.dirname(d)) break;
|
|
@@ -168,7 +193,7 @@ export function keyFilePath(raw, { platform = process.platform, homedir = osHome
|
|
|
168
193
|
*/
|
|
169
194
|
export function keyFromEnv(env = process.env, deps = {}) {
|
|
170
195
|
const platform = deps.platform ?? process.platform;
|
|
171
|
-
const fs = deps.fs ?? { openSync, fstatSync, readSync, closeSync, statSync, realpathSync };
|
|
196
|
+
const fs = deps.fs ?? { openSync, fstatSync, readSync, closeSync, statSync, realpathSync, lstatSync, readlinkSync };
|
|
172
197
|
const inline = typeof env.PRIORS_KEY === "string" ? env.PRIORS_KEY.trim() : "";
|
|
173
198
|
const fileRaw = typeof env.PRIORS_KEY_FILE === "string" ? env.PRIORS_KEY_FILE.trim() : "";
|
|
174
199
|
if (!fileRaw) return { key: inline, source: inline ? "PRIORS_KEY" : null, problem: null };
|