@oracle-agent/oracle 0.1.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/CONTRIBUTING.md +98 -0
- package/LICENSE +202 -0
- package/README.md +384 -0
- package/SECURITY.md +89 -0
- package/SETUP.md +235 -0
- package/artifacts/inscription/oracle-was-here-preview.png +0 -0
- package/artifacts/inscription/oracle-was-here.svg +1 -0
- package/artifacts/specialist-packs/oracle-full-crypto.json +273 -0
- package/bin/desk-server.mjs +438 -0
- package/bin/oracle-data-mcp.mjs +603 -0
- package/bin/oracle-init.mjs +423 -0
- package/bin/oracle-public-server.mjs +36 -0
- package/bin/oracle-route.mjs +254 -0
- package/bin/oracle-scan.mjs +192 -0
- package/docs/adding-a-chain.md +229 -0
- package/docs/architecture.md +135 -0
- package/docs/profiles.md +132 -0
- package/examples/add-a-chain.mjs +65 -0
- package/examples/research-a-token.mjs +70 -0
- package/package.json +90 -0
- package/profiles/_template/SOUL.md +47 -0
- package/profiles/_template/profile.json +22 -0
- package/profiles/bitcoin-agent/SOUL.md +31 -0
- package/profiles/bitcoin-agent/profile.json +32 -0
- package/profiles/hyperliquid-agent/SOUL.md +34 -0
- package/profiles/hyperliquid-agent/profile.json +37 -0
- package/profiles/oracle/SOUL.md +65 -0
- package/profiles/oracle/profile.json +35 -0
- package/profiles/polymarket-agent/SOUL.md +35 -0
- package/profiles/polymarket-agent/profile.json +34 -0
- package/profiles/profile.schema.json +90 -0
- package/profiles/protocol-builder/SOUL.md +50 -0
- package/profiles/protocol-builder/profile.json +37 -0
- package/profiles/robinhood-agent/SOUL.md +45 -0
- package/profiles/robinhood-agent/profile.json +39 -0
- package/profiles/solana-agent/SOUL.md +37 -0
- package/profiles/solana-agent/profile.json +37 -0
- package/profiles/stable-agent/SOUL.md +43 -0
- package/profiles/stable-agent/profile.json +37 -0
- package/public/oracle-console/app.js +272 -0
- package/public/oracle-console/bitcoin-wallets.js +206 -0
- package/public/oracle-console/index.html +91 -0
- package/public/oracle-console/styles.css +239 -0
- package/public/oracle-splash/index.html +931 -0
- package/scripts/build-inscription.py +230 -0
- package/scripts/check-test-count.mjs +105 -0
- package/scripts/e2e-hl-markets.mjs +21 -0
- package/scripts/e2e-hl-perps.mjs +48 -0
- package/scripts/e2e-hypercore-staking.mjs +128 -0
- package/scripts/e2e-solana-bitcoin.mjs +183 -0
- package/scripts/public-api-scan.mjs +23 -0
- package/scripts/secret-scan.mjs +181 -0
- package/scripts/verify-v3-venues.mjs +192 -0
- package/skills/oracle-best-execution/SKILL.md +127 -0
- package/skills/oracle-bitcoin/SKILL.md +53 -0
- package/skills/oracle-chain-graphs-telegram-cards/SKILL.md +59 -0
- package/skills/oracle-circuit-breaker/SKILL.md +51 -0
- package/skills/oracle-contract-research/SKILL.md +55 -0
- package/skills/oracle-desk/SKILL.md +58 -0
- package/skills/oracle-dex-launch/SKILL.md +38 -0
- package/skills/oracle-grants/SKILL.md +69 -0
- package/skills/oracle-hypercore-staking/SKILL.md +57 -0
- package/skills/oracle-hyperliquid/SKILL.md +56 -0
- package/skills/oracle-meme-token-sniper/SKILL.md +73 -0
- package/skills/oracle-nft-gacha-launch/SKILL.md +48 -0
- package/skills/oracle-nft-mint-gas-war/SKILL.md +63 -0
- package/skills/oracle-polymarket/SKILL.md +60 -0
- package/skills/oracle-protocol-builder/SKILL.md +38 -0
- package/skills/oracle-protocol-security/SKILL.md +60 -0
- package/skills/oracle-public-product/SKILL.md +44 -0
- package/skills/oracle-receipts/SKILL.md +52 -0
- package/skills/oracle-rfq-tokenized-assets/SKILL.md +69 -0
- package/skills/oracle-smart-wallet-scanner/SKILL.md +49 -0
- package/skills/oracle-solana/SKILL.md +65 -0
- package/skills/oracle-solana-nft/SKILL.md +54 -0
- package/skills/oracle-token-research/SKILL.md +67 -0
- package/src/agent-auth.mjs +191 -0
- package/src/approval-guard.mjs +282 -0
- package/src/attestation-secret.mjs +88 -0
- package/src/audit-log.mjs +196 -0
- package/src/auto-slippage.mjs +378 -0
- package/src/capability-posture.mjs +125 -0
- package/src/chains.mjs +62 -0
- package/src/data/catalog.mjs +495 -0
- package/src/data/desk-data.mjs +623 -0
- package/src/data/http.mjs +200 -0
- package/src/data/provider-endpoint.mjs +94 -0
- package/src/data/providers/aerodrome.mjs +244 -0
- package/src/data/providers/balancer.mjs +208 -0
- package/src/data/providers/bitcoin-esplora.mjs +230 -0
- package/src/data/providers/bitcoin-meta.mjs +378 -0
- package/src/data/providers/blockscout.mjs +14 -0
- package/src/data/providers/bridges.mjs +241 -0
- package/src/data/providers/cowswap.mjs +501 -0
- package/src/data/providers/curve.mjs +200 -0
- package/src/data/providers/defillama.mjs +88 -0
- package/src/data/providers/dexscreener.mjs +43 -0
- package/src/data/providers/evm-rpc.mjs +203 -0
- package/src/data/providers/geckoterminal.mjs +34 -0
- package/src/data/providers/gmx.mjs +495 -0
- package/src/data/providers/hl-info.mjs +102 -0
- package/src/data/providers/hl-markets.mjs +210 -0
- package/src/data/providers/hl-perps.mjs +382 -0
- package/src/data/providers/hl-staking.mjs +352 -0
- package/src/data/providers/hl-ws.mjs +119 -0
- package/src/data/providers/hyperevm-dex.mjs +49 -0
- package/src/data/providers/jupiter.mjs +182 -0
- package/src/data/providers/lifi.mjs +150 -0
- package/src/data/providers/magiceden-sol.mjs +355 -0
- package/src/data/providers/morpho.mjs +173 -0
- package/src/data/providers/odos.mjs +155 -0
- package/src/data/providers/oneinch.mjs +173 -0
- package/src/data/providers/opensea-multichain.mjs +136 -0
- package/src/data/providers/opensea-nft.mjs +99 -0
- package/src/data/providers/paraswap.mjs +117 -0
- package/src/data/providers/pendle.mjs +187 -0
- package/src/data/providers/poly-public.mjs +96 -0
- package/src/data/providers/poly-ws.mjs +103 -0
- package/src/data/providers/rh-agent.mjs +59 -0
- package/src/data/providers/satflow.mjs +336 -0
- package/src/data/providers/solana-rpc.mjs +186 -0
- package/src/data/providers/uniswap-v3.mjs +303 -0
- package/src/data/providers/zerox.mjs +166 -0
- package/src/data/public-api-scan.mjs +61 -0
- package/src/data/quote-placeholder.mjs +31 -0
- package/src/exact-integer.mjs +72 -0
- package/src/exec-policy.mjs +444 -0
- package/src/flags.mjs +15 -0
- package/src/fresh-window.mjs +76 -0
- package/src/gmx-attestation.mjs +175 -0
- package/src/index.mjs +50 -0
- package/src/nft-gas-war-guard.mjs +139 -0
- package/src/onboarding/agent-keys.mjs +157 -0
- package/src/onboarding/index.mjs +18 -0
- package/src/onboarding/tiers.mjs +139 -0
- package/src/oracle-env.mjs +38 -0
- package/src/protocol-execution.mjs +84 -0
- package/src/public-api/buzz-integration.mjs +256 -0
- package/src/public-api/connect-agent.mjs +397 -0
- package/src/public-api/grants.mjs +142 -0
- package/src/public-api/http.mjs +374 -0
- package/src/public-control/aa-adapter.mjs +402 -0
- package/src/public-control/build-registry.mjs +227 -0
- package/src/public-control/bundler-client.mjs +372 -0
- package/src/public-control/grant-indexer.mjs +296 -0
- package/src/public-control/policy-render.mjs +69 -0
- package/src/public-control/policy-schema.mjs +318 -0
- package/src/public-control/runtime-config.mjs +265 -0
- package/src/public-control/session-key-model.mjs +374 -0
- package/src/public-control/session-orchestrator.mjs +412 -0
- package/src/route-attestation.mjs +132 -0
- package/src/router/best-execution.mjs +221 -0
- package/src/router/index.mjs +185 -0
- package/src/router/prepare-bridge.mjs +288 -0
- package/src/router/prepare-route.mjs +341 -0
- package/src/router/proposal.mjs +311 -0
- package/src/router/risk-classifier.mjs +119 -0
- package/src/router/route-sources.mjs +292 -0
- package/src/scanner/chains.config.mjs +381 -0
- package/src/scanner/contract.mjs +270 -0
- package/src/scanner/evm-scanner.mjs +394 -0
- package/src/scanner/index.mjs +9 -0
- package/src/scanner/v2-venue.mjs +335 -0
- package/src/scanner/v3-venue.mjs +290 -0
- package/src/scopes.mjs +44 -0
- package/src/sell-simulation.mjs +167 -0
- package/src/token-transfer-guard.mjs +188 -0
- package/src/vault-attestation.mjs +145 -0
- package/src/venues.mjs +206 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: oracle-token-research
|
|
3
|
+
description: Use when researching any token, especially low-cap or newly launched. The sell-side-first checklist that catches honeypots.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Token research
|
|
7
|
+
|
|
8
|
+
The default assumption for a new token is **hostile**. Research exists to disprove
|
|
9
|
+
that, not to confirm a story.
|
|
10
|
+
|
|
11
|
+
## Sell side first
|
|
12
|
+
|
|
13
|
+
Most losses here are not bad entries. They are tokens that **buy cleanly and cannot
|
|
14
|
+
be sold**. So the first question is never "will it go up" — it is "can I get out."
|
|
15
|
+
|
|
16
|
+
Run a **round-trip simulation** in one state-free call: wrap native → buy token →
|
|
17
|
+
sell token back → require a minimum return. Treat any of these as FAIL:
|
|
18
|
+
|
|
19
|
+
- quote failure in either direction
|
|
20
|
+
- transfer failure
|
|
21
|
+
- router revert
|
|
22
|
+
- round-trip return below the no-tax reverse quote by more than a small tolerance
|
|
23
|
+
|
|
24
|
+
A successful **buy** quote proves nothing about the sell.
|
|
25
|
+
|
|
26
|
+
## Price against the real pool
|
|
27
|
+
|
|
28
|
+
A launchpad or bonding-curve token often exposes its **own** `getReserves()`
|
|
29
|
+
returning zero or virtual values. The tradeable market is a *different* pair.
|
|
30
|
+
|
|
31
|
+
- `blockTimestampLast == 0` → not a live pool. Do not size against it.
|
|
32
|
+
- Find the real pair via `factory.getPair(a, b)` or a live swap's decoded target
|
|
33
|
+
- A pair with `kLast`, `price0CumulativeLast`, `MINIMUM_LIQUIDITY` is standard V2
|
|
34
|
+
even when the router in front of it is a custom fork
|
|
35
|
+
|
|
36
|
+
Sizing against stale reserves is how a "0.4% impact" trade becomes 3%.
|
|
37
|
+
|
|
38
|
+
## Identity before action
|
|
39
|
+
|
|
40
|
+
Tickers collide and get squatted. A fuzzy name match is a **candidate**, never
|
|
41
|
+
confirmation.
|
|
42
|
+
|
|
43
|
+
Always surface the **contract address** and require explicit confirmation before
|
|
44
|
+
anything that moves value. `FEFUR` vs `FEFER` is a real class of loss.
|
|
45
|
+
|
|
46
|
+
## The rest of the checklist
|
|
47
|
+
|
|
48
|
+
| Check | Red flag |
|
|
49
|
+
|---|---|
|
|
50
|
+
| holder concentration | top 5 hold most of supply |
|
|
51
|
+
| liquidity depth | thin relative to your size |
|
|
52
|
+
| LP status | unlocked or removable |
|
|
53
|
+
| age | hours old with heavy volume |
|
|
54
|
+
| router | non-canonical clone with a familiar name |
|
|
55
|
+
| mint authority | still open |
|
|
56
|
+
| transfer logic | fees or blocks that change post-launch |
|
|
57
|
+
|
|
58
|
+
## Label your evidence
|
|
59
|
+
|
|
60
|
+
Mark every finding `LIVE`, `STALE`, `UNKNOWN`, or `UNAVAILABLE` with a timestamp.
|
|
61
|
+
Do not call holder-concentration analysis "bundle detection" — bundles require
|
|
62
|
+
launch-block clustering and common-funder evidence, which is a different query.
|
|
63
|
+
|
|
64
|
+
## Honest output
|
|
65
|
+
|
|
66
|
+
`unknown` is a correct and frequent answer about a two-hour-old token. Say it.
|
|
67
|
+
Never let narrative quality substitute for a passing sell simulation.
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
// Owner-signed, self-verifying, time-bounded agent capability tokens.
|
|
2
|
+
//
|
|
3
|
+
// Adapted from block/buzz NIP-OA ("Owner Attestation") to MAD's EVM world.
|
|
4
|
+
// NIP-OA is Schnorr/BIP-340 over a nostr event; MAD signs ECDSA/EIP-191 with
|
|
5
|
+
// the same secp256k1 curve, so the credential format ports directly while the
|
|
6
|
+
// signature primitive becomes ethers `verifyMessage` (already used elsewhere).
|
|
7
|
+
//
|
|
8
|
+
// WHY: today MAD proves owner authority ONLY server-side (MAD_EXECUTOR_CONTROLLERS
|
|
9
|
+
// allowlist + key-hash + bearer). That is a denylist the server must carry. A
|
|
10
|
+
// capability is the complement: a self-contained grant the AGENT carries and
|
|
11
|
+
// presents, that the exec layer verifies without consulting a list, and that
|
|
12
|
+
// EXPIRES on its own. Revocation-by-expiry, not just server denial. For the
|
|
13
|
+
// multi-user agency version an owner key mints a scoped, expiring grant per
|
|
14
|
+
// client without the server tracking every delegation.
|
|
15
|
+
//
|
|
16
|
+
// A capability is: ["auth", <ownerAddress>, <conditions>, <signature>]
|
|
17
|
+
// ownerAddress : 0x EVM address that authorized the agent
|
|
18
|
+
// conditions : "" or clause(&clause)* — clauses below
|
|
19
|
+
// signature : owner EIP-191 signature over the preimage
|
|
20
|
+
//
|
|
21
|
+
// Preimage (exact bytes, order-sensitive — the owner signs this string):
|
|
22
|
+
// "mad:agent-auth:" + <agentAddress-lowercased> + ":" + <conditions>
|
|
23
|
+
//
|
|
24
|
+
// Clauses (case-sensitive, no whitespace, canonical base-10):
|
|
25
|
+
// chain=<decimal> agent may act on this EVM chainId
|
|
26
|
+
// action=<string> agent may perform this action/scope (e.g. exec.broadcast)
|
|
27
|
+
// expires<unix> capability invalid at/after this wall-clock time
|
|
28
|
+
// notbefore>unix capability invalid before this wall-clock time
|
|
29
|
+
//
|
|
30
|
+
// Unlike NIP-OA (which constrains an agent-controlled event.created_at and so
|
|
31
|
+
// cannot enforce wall-clock expiry), MAD verifies a capability presented LIVE
|
|
32
|
+
// against real time, so `expires<`/`notbefore>` ARE enforced against the
|
|
33
|
+
// verifier clock here — the wall-clock enforcement NIP-OA defers to the caller.
|
|
34
|
+
|
|
35
|
+
import { verifyMessage, getAddress, isAddress } from "ethers";
|
|
36
|
+
|
|
37
|
+
export const AUTH_DOMAIN = "mad:agent-auth:";
|
|
38
|
+
|
|
39
|
+
/** Build the exact signing preimage. Owner signs this via personal_sign. */
|
|
40
|
+
export function authPreimage(agentAddress, conditions) {
|
|
41
|
+
const a = String(agentAddress || "").toLowerCase();
|
|
42
|
+
if (!/^0x[0-9a-f]{40}$/.test(a)) throw new Error("agentAddress must be a 0x 20-byte address");
|
|
43
|
+
return AUTH_DOMAIN + a + ":" + String(conditions ?? "");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Parse + validate the conditions string into typed clauses. Throws on any
|
|
47
|
+
// malformed clause (mirrors NIP-OA's strict rejection rules).
|
|
48
|
+
function parseConditions(conditions) {
|
|
49
|
+
const out = { chains: new Set(), actions: new Set(), expires: null, notbefore: null };
|
|
50
|
+
const s = String(conditions ?? "");
|
|
51
|
+
if (s === "") return out; // empty imposes no constraints
|
|
52
|
+
if (/\s/.test(s)) throw new Error("conditions: whitespace not permitted");
|
|
53
|
+
if (s.startsWith("&") || s.endsWith("&") || s.includes("&&")) {
|
|
54
|
+
throw new Error("conditions: empty clause");
|
|
55
|
+
}
|
|
56
|
+
const decimal = (v, max) => {
|
|
57
|
+
if (!/^(0|[1-9][0-9]*)$/.test(v)) throw new Error(`conditions: non-canonical decimal '${v}'`);
|
|
58
|
+
const n = Number(v);
|
|
59
|
+
if (!Number.isSafeInteger(n) || n < 0 || n > max) throw new Error(`conditions: out of range '${v}'`);
|
|
60
|
+
return n;
|
|
61
|
+
};
|
|
62
|
+
for (const clause of s.split("&")) {
|
|
63
|
+
if (clause.startsWith("chain=")) {
|
|
64
|
+
out.chains.add(decimal(clause.slice(6), 0xffffffff));
|
|
65
|
+
} else if (clause.startsWith("action=")) {
|
|
66
|
+
const v = clause.slice(7);
|
|
67
|
+
if (!v) throw new Error("conditions: empty action");
|
|
68
|
+
out.actions.add(v);
|
|
69
|
+
} else if (clause.startsWith("expires<")) {
|
|
70
|
+
out.expires = decimal(clause.slice(8), 0xffffffff);
|
|
71
|
+
} else if (clause.startsWith("notbefore>")) {
|
|
72
|
+
out.notbefore = decimal(clause.slice(10), 0xffffffff);
|
|
73
|
+
} else {
|
|
74
|
+
throw new Error(`conditions: unsupported clause '${clause}'`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return out;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Verify an owner capability authorizes `agentAddress` for `{ chainId, action }`
|
|
82
|
+
* right now. Pure + self-contained: no allowlist, no DB. Returns a result object
|
|
83
|
+
* rather than throwing so the exec path can log a reason and fail closed.
|
|
84
|
+
*
|
|
85
|
+
* @param {[string,string,string,string]} tag ["auth", owner, conditions, sig]
|
|
86
|
+
* @param {object} ctx
|
|
87
|
+
* @param {string} ctx.agentAddress the agent key the capability was signed for
|
|
88
|
+
* @param {number} [ctx.chainId] chain the action targets (checked vs chain=)
|
|
89
|
+
* @param {string} [ctx.action] action/scope requested (checked vs action=)
|
|
90
|
+
* @param {number} [ctx.now] unix seconds override (tests)
|
|
91
|
+
* @returns {{ ok: boolean, owner?: string, reason?: string }}
|
|
92
|
+
*/
|
|
93
|
+
export function verifyCapability(tag, { agentAddress, chainId = null, action = null, now = null } = {}) {
|
|
94
|
+
if (!Array.isArray(tag) || tag.length !== 4 || tag[0] !== "auth") {
|
|
95
|
+
return { ok: false, reason: "malformed-tag" };
|
|
96
|
+
}
|
|
97
|
+
const [, ownerRaw, conditions, sig] = tag;
|
|
98
|
+
if (!isAddress(ownerRaw)) return { ok: false, reason: "bad-owner-address" };
|
|
99
|
+
if (!isAddress(agentAddress)) return { ok: false, reason: "bad-agent-address" };
|
|
100
|
+
|
|
101
|
+
const owner = getAddress(ownerRaw);
|
|
102
|
+
// Self-attestation is meaningless — an agent can't authorize itself.
|
|
103
|
+
if (owner.toLowerCase() === String(agentAddress).toLowerCase()) {
|
|
104
|
+
return { ok: false, reason: "self-attestation" };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
let parsed;
|
|
108
|
+
try {
|
|
109
|
+
parsed = parseConditions(conditions);
|
|
110
|
+
} catch (e) {
|
|
111
|
+
return { ok: false, reason: String(e.message || e) };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Recover the signer from the exact preimage. Any tamper to agent/conditions
|
|
115
|
+
// changes the preimage and the recovered address won't match the owner.
|
|
116
|
+
let recovered;
|
|
117
|
+
try {
|
|
118
|
+
recovered = verifyMessage(authPreimage(agentAddress, conditions), sig);
|
|
119
|
+
} catch {
|
|
120
|
+
return { ok: false, reason: "bad-signature" };
|
|
121
|
+
}
|
|
122
|
+
if (recovered.toLowerCase() !== owner.toLowerCase()) {
|
|
123
|
+
return { ok: false, reason: "signature-owner-mismatch" };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const t = now == null ? Math.floor(Date.now() / 1000) : Number(now);
|
|
127
|
+
if (parsed.expires != null && t >= parsed.expires) return { ok: false, reason: "expired", owner };
|
|
128
|
+
if (parsed.notbefore != null && t <= parsed.notbefore) return { ok: false, reason: "not-yet-valid", owner };
|
|
129
|
+
if (parsed.chains.size > 0 && chainId != null && !parsed.chains.has(Number(chainId))) {
|
|
130
|
+
return { ok: false, reason: "chain-not-authorized", owner };
|
|
131
|
+
}
|
|
132
|
+
if (parsed.actions.size > 0 && action != null && !parsed.actions.has(String(action))) {
|
|
133
|
+
return { ok: false, reason: "action-not-authorized", owner };
|
|
134
|
+
}
|
|
135
|
+
return { ok: true, owner };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Owner-side helper: given an owner ethers Signer, mint the capability tag for
|
|
140
|
+
* an agent. Kept dependency-light — caller supplies the signer so the owner key
|
|
141
|
+
* NEVER touches this module or the exec box.
|
|
142
|
+
*
|
|
143
|
+
* @param {import('ethers').Signer} ownerSigner
|
|
144
|
+
* @param {string} agentAddress
|
|
145
|
+
* @param {string} [conditions]
|
|
146
|
+
* @returns {Promise<[string,string,string,string]>}
|
|
147
|
+
*/
|
|
148
|
+
export async function mintCapability(ownerSigner, agentAddress, conditions = "") {
|
|
149
|
+
parseConditions(conditions); // validate before signing
|
|
150
|
+
const owner = await ownerSigner.getAddress();
|
|
151
|
+
if (owner.toLowerCase() === String(agentAddress).toLowerCase()) {
|
|
152
|
+
throw new Error("owner and agent must differ");
|
|
153
|
+
}
|
|
154
|
+
const sig = await ownerSigner.signMessage(authPreimage(agentAddress, conditions));
|
|
155
|
+
return ["auth", getAddress(owner), String(conditions), sig];
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Gate decision: a capability verifies AND its owner is one MAD trusts.
|
|
160
|
+
*
|
|
161
|
+
* `verifyCapability` proves *some* owner signed the grant; on its own that is
|
|
162
|
+
* not authorization — anyone can sign a grant for the agent from a random key.
|
|
163
|
+
* This adds the missing half: the recovered owner must be in the trusted
|
|
164
|
+
* `owners` set. BOTH must hold. Fails CLOSED — an empty trusted set denies
|
|
165
|
+
* every request (so turning the gate on without configuring owners cannot
|
|
166
|
+
* silently allow-all).
|
|
167
|
+
*
|
|
168
|
+
* Pure: no env, no I/O, no clock unless `now` omitted. The exec layer supplies
|
|
169
|
+
* env-derived `required`/`owners` and records the outcome to the audit chain.
|
|
170
|
+
*
|
|
171
|
+
* @param {[string,string,string,string]} tag
|
|
172
|
+
* @param {object} ctx
|
|
173
|
+
* @param {string} ctx.agentAddress agent the capability must authorize
|
|
174
|
+
* @param {number} [ctx.chainId] chain the action targets
|
|
175
|
+
* @param {string} [ctx.action] action/scope requested
|
|
176
|
+
* @param {string[]} [ctx.owners] trusted owner addresses (allowlist)
|
|
177
|
+
* @param {number} [ctx.now] unix seconds override (tests)
|
|
178
|
+
* @returns {{ ok: boolean, owner?: string, reason?: string }}
|
|
179
|
+
*/
|
|
180
|
+
export function requireCapability(tag, { agentAddress, chainId = null, action = null, owners = [], now = null } = {}) {
|
|
181
|
+
const allow = new Set(
|
|
182
|
+
(owners || []).map((a) => String(a).toLowerCase()).filter(Boolean)
|
|
183
|
+
);
|
|
184
|
+
if (allow.size === 0) return { ok: false, reason: "no-trusted-owners" };
|
|
185
|
+
const r = verifyCapability(tag, { agentAddress, chainId, action, now });
|
|
186
|
+
if (!r.ok) return r;
|
|
187
|
+
if (!allow.has(r.owner.toLowerCase())) {
|
|
188
|
+
return { ok: false, reason: "owner-not-trusted", owner: r.owner };
|
|
189
|
+
}
|
|
190
|
+
return { ok: true, owner: r.owner };
|
|
191
|
+
}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { Interface, MaxUint256, isAddress, keccak256, toUtf8Bytes } from "ethers";
|
|
2
|
+
import { venuesFor } from "./venues.mjs";
|
|
3
|
+
import { assertVaultApprovalAttestation } from "./vault-attestation.mjs";
|
|
4
|
+
import { assertGmxApprovalAttestation } from "./gmx-attestation.mjs";
|
|
5
|
+
import { exactBigInt } from "./exact-integer.mjs";
|
|
6
|
+
import { assertFreshWindow } from "./fresh-window.mjs";
|
|
7
|
+
|
|
8
|
+
const DEFAULT_APPROVAL_TTL_MS = 20_000;
|
|
9
|
+
|
|
10
|
+
const ERC20 = new Interface(["function approve(address spender,uint256 amount) returns (bool)"]);
|
|
11
|
+
|
|
12
|
+
function normalAddress(value, label) {
|
|
13
|
+
const text = String(value || "").trim();
|
|
14
|
+
if (!isAddress(text)) throw new Error(`${label} must be an address`);
|
|
15
|
+
return text.toLowerCase();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function amountString(value, label = "approval amount", { allowZero = false } = {}) {
|
|
19
|
+
// Unsafe JS numbers round UP above 2^53, which would widen the allowance past
|
|
20
|
+
// what the caller wrote. Same class already fixed for ERC-20 transfers.
|
|
21
|
+
const amount = exactBigInt(value, label);
|
|
22
|
+
if (allowZero ? amount < 0n : amount <= 0n) throw new Error(`${label} must be positive`);
|
|
23
|
+
if (amount >= MaxUint256) throw new Error("unlimited approvals are refused; use an exact bounded amount");
|
|
24
|
+
return amount.toString();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function canonicalJson(value) {
|
|
28
|
+
if (Array.isArray(value)) return `[${value.map(canonicalJson).join(",")}]`;
|
|
29
|
+
if (value && typeof value === "object") {
|
|
30
|
+
return `{${Object.keys(value).sort().map((k) => `${JSON.stringify(k)}:${canonicalJson(value[k])}`).join(",")}}`;
|
|
31
|
+
}
|
|
32
|
+
return JSON.stringify(value);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Selectors that grant or increase an allowance.
|
|
37
|
+
*
|
|
38
|
+
* Gating only on `approve()` meant every other allowance-granting entrypoint
|
|
39
|
+
* skipped the guard entirely: `increaseAllowance` raises the same allowance,
|
|
40
|
+
* SafeERC20's `forceApprove`/`safeApprove` set one on the caller's behalf,
|
|
41
|
+
* Permit2's `approve`/`permit` grant spend rights, and DAI-style `permit` sets
|
|
42
|
+
* an allowance from a signature. A guard that covers one selector is a guard
|
|
43
|
+
* an attacker routes around.
|
|
44
|
+
*
|
|
45
|
+
* Every value here was computed from its signature with keccak256, not copied
|
|
46
|
+
* from memory — an incorrect selector in this list is a silent hole.
|
|
47
|
+
*/
|
|
48
|
+
const ALLOWANCE_SELECTORS = new Set([
|
|
49
|
+
"0x095ea7b3", // approve(address,uint256)
|
|
50
|
+
"0x39509351", // increaseAllowance(address,uint256)
|
|
51
|
+
"0x61f49ed6", // forceApprove(address,address,uint256) [SafeERC20]
|
|
52
|
+
"0xeb5625d9", // safeApprove(address,address,uint256) [SafeERC20]
|
|
53
|
+
"0xf9255c1f", // safeIncreaseAllowance(address,address,uint256) [SafeERC20]
|
|
54
|
+
"0x87517c45", // approve(address,address,uint160,uint48) [Permit2]
|
|
55
|
+
"0xd505accf", // permit(address,address,uint256,uint256,uint8,bytes32,bytes32) [EIP-2612]
|
|
56
|
+
"0x8fcbaf0c", // permit(address,address,uint256,uint256,bool,uint8,bytes32,bytes32) [DAI]
|
|
57
|
+
"0x2b67b570", // permit(address,PermitSingle,bytes) [Permit2]
|
|
58
|
+
"0x2a2d80d1", // permitBatch [Permit2]
|
|
59
|
+
]);
|
|
60
|
+
|
|
61
|
+
export function isApprovalCall(data) {
|
|
62
|
+
const hex = String(data || "").toLowerCase();
|
|
63
|
+
if (hex.length < 10) return false;
|
|
64
|
+
return ALLOWANCE_SELECTORS.has(hex.slice(0, 10));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export { ALLOWANCE_SELECTORS };
|
|
68
|
+
|
|
69
|
+
export function decodeApproveCalldata(data) {
|
|
70
|
+
if (!isApprovalCall(data)) throw new Error("approval calldata required");
|
|
71
|
+
const hex = String(data || "").toLowerCase();
|
|
72
|
+
const selector = hex.slice(0, 10);
|
|
73
|
+
const words = hex.slice(10).match(/.{1,64}/g) || [];
|
|
74
|
+
const wordAddr = (i) => (words[i] ? "0x" + words[i].slice(24) : null);
|
|
75
|
+
const wordBig = (i) => (words[i] ? BigInt("0x" + words[i]) : null);
|
|
76
|
+
|
|
77
|
+
// Each allowance-granting shape puts (spender, amount) in different slots.
|
|
78
|
+
// Detecting a selector without being able to decode it made every non-approve
|
|
79
|
+
// allowance call unsignable — the guard recognised the tx, demanded a bound
|
|
80
|
+
// guard, then threw "invalid approve calldata" because it only knew how to
|
|
81
|
+
// read approve(). Recognition and decoding must cover the same set.
|
|
82
|
+
let spenderRaw = null;
|
|
83
|
+
let amountRaw = null;
|
|
84
|
+
|
|
85
|
+
switch (selector) {
|
|
86
|
+
// approve(address spender, uint256 value)
|
|
87
|
+
// increaseAllowance(address spender, uint256 addedValue)
|
|
88
|
+
case "0x095ea7b3":
|
|
89
|
+
case "0x39509351":
|
|
90
|
+
spenderRaw = wordAddr(0);
|
|
91
|
+
amountRaw = wordBig(1);
|
|
92
|
+
break;
|
|
93
|
+
// SafeERC20 helpers: (IERC20 token, address spender, uint256 value)
|
|
94
|
+
case "0x61f49ed6": // forceApprove
|
|
95
|
+
case "0xeb5625d9": // safeApprove
|
|
96
|
+
case "0xf9255c1f": // safeIncreaseAllowance
|
|
97
|
+
spenderRaw = wordAddr(1);
|
|
98
|
+
amountRaw = wordBig(2);
|
|
99
|
+
break;
|
|
100
|
+
// EIP-2612 permit(owner, spender, value, deadline, v, r, s)
|
|
101
|
+
case "0xd505accf":
|
|
102
|
+
spenderRaw = wordAddr(1);
|
|
103
|
+
amountRaw = wordBig(2);
|
|
104
|
+
break;
|
|
105
|
+
// DAI permit(holder, spender, nonce, expiry, allowed, v, r, s) — `allowed`
|
|
106
|
+
// is a boolean, so an unlimited allowance is expressed as true.
|
|
107
|
+
case "0x8fcbaf0c": {
|
|
108
|
+
spenderRaw = wordAddr(1);
|
|
109
|
+
const allowed = wordBig(4);
|
|
110
|
+
amountRaw = allowed === 0n ? 0n : (1n << 256n) - 1n;
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
// Permit2 approve(token, spender, uint160 amount, uint48 expiration)
|
|
114
|
+
case "0x87517c45":
|
|
115
|
+
spenderRaw = wordAddr(1);
|
|
116
|
+
amountRaw = wordBig(2);
|
|
117
|
+
break;
|
|
118
|
+
default:
|
|
119
|
+
// A selector we recognise but cannot decode must FAIL, not silently pass:
|
|
120
|
+
// an undecodable allowance cannot be bounded.
|
|
121
|
+
throw new Error(`approval selector ${selector} is recognised but not decodable; refusing to bound it`);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (spenderRaw == null || amountRaw == null) throw new Error("invalid approve calldata");
|
|
125
|
+
return {
|
|
126
|
+
spender: normalAddress(spenderRaw, "approval spender"),
|
|
127
|
+
amount: amountString(amountRaw, "approval amount", { allowZero: true }),
|
|
128
|
+
selector,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function normalizeApprovalRequests(value) {
|
|
133
|
+
if (!value) return [];
|
|
134
|
+
const raw = Array.isArray(value) ? value : [value];
|
|
135
|
+
return raw
|
|
136
|
+
.filter(Boolean)
|
|
137
|
+
.map((approval) => ({
|
|
138
|
+
token: normalAddress(approval.token, "approval token"),
|
|
139
|
+
spender: normalAddress(approval.spender, "approval spender"),
|
|
140
|
+
amount: amountString(approval.amount, "approval amount"),
|
|
141
|
+
}));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function createApprovalGuard({
|
|
145
|
+
chainId,
|
|
146
|
+
token,
|
|
147
|
+
spender,
|
|
148
|
+
amount,
|
|
149
|
+
provider,
|
|
150
|
+
routeVenue,
|
|
151
|
+
routeGuard,
|
|
152
|
+
purpose,
|
|
153
|
+
nowMs = Date.now(),
|
|
154
|
+
ttlMs = DEFAULT_APPROVAL_TTL_MS,
|
|
155
|
+
} = {}) {
|
|
156
|
+
const approvalPurpose = String(purpose || "").trim();
|
|
157
|
+
const guard = {
|
|
158
|
+
mode: "approval",
|
|
159
|
+
chainId: Number(chainId),
|
|
160
|
+
token: normalAddress(token, "approval token"),
|
|
161
|
+
spender: normalAddress(spender, "approval spender"),
|
|
162
|
+
amount: amountString(amount, "approval amount", { allowZero: approvalPurpose === "revoke" }),
|
|
163
|
+
provider: String(provider || "").trim() || "unknown",
|
|
164
|
+
routeVenue: routeVenue ? normalAddress(routeVenue, "approval route venue") : normalAddress(spender, "approval route venue"),
|
|
165
|
+
issuedAtMs: Number(nowMs),
|
|
166
|
+
expiresAtMs: Number(nowMs) + Number(ttlMs || DEFAULT_APPROVAL_TTL_MS),
|
|
167
|
+
};
|
|
168
|
+
if (approvalPurpose) guard.purpose = approvalPurpose;
|
|
169
|
+
if (!Number.isFinite(guard.chainId)) throw new Error("approval chainId required");
|
|
170
|
+
if (!Number.isFinite(guard.issuedAtMs) || !Number.isFinite(guard.expiresAtMs) || guard.expiresAtMs <= guard.issuedAtMs) {
|
|
171
|
+
throw new Error("approval guard expiry invalid");
|
|
172
|
+
}
|
|
173
|
+
if (routeGuard) {
|
|
174
|
+
guard.routeGuardHash = keccak256(toUtf8Bytes(canonicalJson(routeGuard)));
|
|
175
|
+
}
|
|
176
|
+
return guard;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export function buildApprovalTransaction(approval, {
|
|
180
|
+
chainId,
|
|
181
|
+
provider,
|
|
182
|
+
routeTransaction,
|
|
183
|
+
routeGuard,
|
|
184
|
+
nowMs = Date.now(),
|
|
185
|
+
ttlMs = DEFAULT_APPROVAL_TTL_MS,
|
|
186
|
+
} = {}) {
|
|
187
|
+
const [req] = normalizeApprovalRequests(approval);
|
|
188
|
+
if (!req) throw new Error("approval request required");
|
|
189
|
+
const madApproval = createApprovalGuard({
|
|
190
|
+
chainId,
|
|
191
|
+
token: req.token,
|
|
192
|
+
spender: req.spender,
|
|
193
|
+
amount: req.amount,
|
|
194
|
+
provider,
|
|
195
|
+
routeVenue: routeTransaction?.to || req.spender,
|
|
196
|
+
routeGuard,
|
|
197
|
+
nowMs,
|
|
198
|
+
ttlMs,
|
|
199
|
+
});
|
|
200
|
+
return {
|
|
201
|
+
chainId: Number(chainId),
|
|
202
|
+
to: req.token,
|
|
203
|
+
data: ERC20.encodeFunctionData("approve", [req.spender, req.amount]),
|
|
204
|
+
value: "0x0",
|
|
205
|
+
madApproval,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export function buildApprovalRevokeTransaction(approval, {
|
|
210
|
+
chainId,
|
|
211
|
+
provider,
|
|
212
|
+
nowMs = Date.now(),
|
|
213
|
+
ttlMs = DEFAULT_APPROVAL_TTL_MS,
|
|
214
|
+
} = {}) {
|
|
215
|
+
const token = normalAddress(approval?.token, "approval token");
|
|
216
|
+
const spender = normalAddress(approval?.spender, "approval spender");
|
|
217
|
+
const madApproval = createApprovalGuard({
|
|
218
|
+
chainId,
|
|
219
|
+
token,
|
|
220
|
+
spender,
|
|
221
|
+
amount: "0",
|
|
222
|
+
provider,
|
|
223
|
+
routeVenue: spender,
|
|
224
|
+
purpose: "revoke",
|
|
225
|
+
nowMs,
|
|
226
|
+
ttlMs,
|
|
227
|
+
});
|
|
228
|
+
return {
|
|
229
|
+
chainId: Number(chainId),
|
|
230
|
+
to: token,
|
|
231
|
+
data: ERC20.encodeFunctionData("approve", [spender, "0"]),
|
|
232
|
+
value: "0x0",
|
|
233
|
+
madApproval,
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export function assertApprovalGuard(guard, tx = {}, { chainId, nowMs = Date.now() } = {}) {
|
|
238
|
+
if (!guard || guard.mode !== "approval") throw new Error("approval guard required");
|
|
239
|
+
const txChainId = Number(tx.chainId ?? chainId);
|
|
240
|
+
if (Number(guard.chainId) !== txChainId) throw new Error(`approval chain mismatch: expected ${txChainId}, got ${guard.chainId}`);
|
|
241
|
+
const token = normalAddress(tx.to, "approval token");
|
|
242
|
+
if (normalAddress(guard.token, "approval token") !== token) throw new Error("approval token mismatch");
|
|
243
|
+
const decoded = decodeApproveCalldata(tx.data);
|
|
244
|
+
if (normalAddress(guard.spender, "approval spender") !== decoded.spender) throw new Error("approval spender mismatch");
|
|
245
|
+
const isRevoke = String(guard.purpose || "") === "revoke";
|
|
246
|
+
if (decoded.amount === "0" && !isRevoke) throw new Error("zero approval amount requires revoke purpose");
|
|
247
|
+
if (amountString(guard.amount, "approval amount", { allowZero: isRevoke }) !== decoded.amount) throw new Error("approval amount mismatch");
|
|
248
|
+
const value = tx.value == null ? 0n : BigInt(String(tx.value).startsWith("0x") ? String(tx.value) : String(tx.value));
|
|
249
|
+
if (value !== 0n) throw new Error("approval tx value must be zero");
|
|
250
|
+
// Same clock fail-closed as every other guard. A missing expiresAtMs used to
|
|
251
|
+
// make Number(undefined) <= now evaluate false, turning a captured approval
|
|
252
|
+
// into a permanent re-grant. NaN/null/"later" clocks had the same effect.
|
|
253
|
+
const { now } = assertFreshWindow(guard, nowMs, "approval guard");
|
|
254
|
+
if (Number(guard.issuedAtMs) > now + 5_000) throw new Error("approval guard issued in the future");
|
|
255
|
+
const allowedSpenders = venuesFor(txChainId);
|
|
256
|
+
if (!allowedSpenders.has(decoded.spender)) {
|
|
257
|
+
if (String(guard.provider || "") === "morpho") {
|
|
258
|
+
assertVaultApprovalAttestation(tx.madVault || tx.vaultGuard, tx, guard, { chainId: txChainId, nowMs });
|
|
259
|
+
return {
|
|
260
|
+
chainId: txChainId,
|
|
261
|
+
token,
|
|
262
|
+
spender: decoded.spender,
|
|
263
|
+
amount: decoded.amount,
|
|
264
|
+
provider: guard.provider || null,
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
throw new Error(`approval spender ${decoded.spender} not allowlisted for chain ${txChainId}`);
|
|
268
|
+
}
|
|
269
|
+
if (String(guard.provider || "") === "gmx") {
|
|
270
|
+
assertGmxApprovalAttestation(tx.madGmx || tx.gmxGuard, tx, guard, { chainId: txChainId, nowMs });
|
|
271
|
+
}
|
|
272
|
+
if (guard.routeVenue && !allowedSpenders.has(normalAddress(guard.routeVenue, "approval route venue"))) {
|
|
273
|
+
throw new Error(`approval route venue ${guard.routeVenue} not allowlisted for chain ${txChainId}`);
|
|
274
|
+
}
|
|
275
|
+
return {
|
|
276
|
+
chainId: txChainId,
|
|
277
|
+
token,
|
|
278
|
+
spender: decoded.spender,
|
|
279
|
+
amount: decoded.amount,
|
|
280
|
+
provider: guard.provider || null,
|
|
281
|
+
};
|
|
282
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// Shared secret resolution for attestation modules.
|
|
2
|
+
//
|
|
3
|
+
// Attestations are minted inside the trusted boundary to bind a dynamic execution
|
|
4
|
+
// target (a route, a vault, a GMX order) so that model-authored JSON cannot become
|
|
5
|
+
// authorization on its own. That makes the secret's LOOKUP path security-relevant:
|
|
6
|
+
// reading it from a wrong or attacker-writable location is as bad as leaking it.
|
|
7
|
+
//
|
|
8
|
+
// Extracted here because three modules had drifted into three near-identical copies,
|
|
9
|
+
// each carrying a hardcoded operator home directory -- which is both a leak of the
|
|
10
|
+
// author's environment and simply broken for anyone else, since a public user has no
|
|
11
|
+
// matching private home path.
|
|
12
|
+
|
|
13
|
+
import { readFileSync } from "node:fs";
|
|
14
|
+
import { homedir } from "node:os";
|
|
15
|
+
import { join } from "node:path";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Candidate env-file locations, in priority order.
|
|
19
|
+
*
|
|
20
|
+
* Resolved from the CURRENT user's home, never a baked-in absolute path.
|
|
21
|
+
*/
|
|
22
|
+
function envFileCandidates() {
|
|
23
|
+
// Under test, do NOT read the developer's real ~/.config secrets. A suite
|
|
24
|
+
// that silently picks up a secret on the maintainer's box and finds none on a
|
|
25
|
+
// contributor's machine is not reproducible, and the difference shows up as
|
|
26
|
+
// mysterious pass/fail drift rather than an honest failure.
|
|
27
|
+
if (process.env.ORACLE_TEST_ISOLATE_SECRETS === "1") {
|
|
28
|
+
const explicitOnly = (process.env.ORACLE_EXEC_ENV_FILE || "").trim();
|
|
29
|
+
return explicitOnly ? [explicitOnly] : [];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const explicit = (
|
|
33
|
+
process.env.ORACLE_EXEC_ENV_FILE ||
|
|
34
|
+
process.env.MAD_EXEC_ENV_FILE || // legacy name, kept for existing deployments
|
|
35
|
+
""
|
|
36
|
+
).trim();
|
|
37
|
+
|
|
38
|
+
const home = homedir();
|
|
39
|
+
return [
|
|
40
|
+
explicit,
|
|
41
|
+
join(home, ".config", "oracle", "exec.env"),
|
|
42
|
+
join(home, ".config", "mad-desk", "exec.env"), // legacy dir
|
|
43
|
+
].filter(Boolean);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Resolve an attestation secret.
|
|
48
|
+
*
|
|
49
|
+
* Order: explicit argument, then env var, then an env FILE. The file fallback exists
|
|
50
|
+
* so a long-lived deployment can keep the secret out of the process environment
|
|
51
|
+
* (where it would show up in `ps` output and child processes).
|
|
52
|
+
*
|
|
53
|
+
* @param {string|undefined} secret explicit override
|
|
54
|
+
* @param {string} primaryEnv e.g. "ORACLE_ROUTE_ATTESTATION_SECRET"
|
|
55
|
+
* @param {string} legacyEnv e.g. "MAD_ROUTE_ATTESTATION_SECRET"
|
|
56
|
+
* @returns {string}
|
|
57
|
+
* @throws when no secret can be found -- fail closed, never mint unsigned
|
|
58
|
+
*/
|
|
59
|
+
export function resolveAttestationSecret(secret, primaryEnv, legacyEnv) {
|
|
60
|
+
let value = secret ?? process.env[primaryEnv] ?? process.env[legacyEnv];
|
|
61
|
+
|
|
62
|
+
if (!String(value || "").trim()) {
|
|
63
|
+
for (const envFile of envFileCandidates()) {
|
|
64
|
+
try {
|
|
65
|
+
const txt = readFileSync(envFile, "utf8");
|
|
66
|
+
// Accept either name in the file, primary winning.
|
|
67
|
+
const m =
|
|
68
|
+
txt.match(new RegExp(`^${primaryEnv}=(.*)$`, "m")) ||
|
|
69
|
+
txt.match(new RegExp(`^${legacyEnv}=(.*)$`, "m"));
|
|
70
|
+
if (m) {
|
|
71
|
+
value = m[1].trim();
|
|
72
|
+
if (value) break;
|
|
73
|
+
}
|
|
74
|
+
} catch {
|
|
75
|
+
// Unreadable or absent: try the next candidate. A missing optional file is
|
|
76
|
+
// not an error; running out of candidates is, and that is handled below.
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (!String(value || "").trim()) {
|
|
82
|
+
throw new Error(
|
|
83
|
+
`${primaryEnv} required for attestation. Set it in the environment, or place ` +
|
|
84
|
+
`${primaryEnv}=<value> in ~/.config/oracle/exec.env`,
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
return value;
|
|
88
|
+
}
|