tenjin-cli 0.1.0-alpha.14 → 0.1.0-alpha.15
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/README.md +18 -3
- package/dist/{buy-2JBYPHAI.js → buy-VIRNSYGN.js} +24 -23
- package/dist/{chunk-QWBUKIP2.js → chunk-2MYQN7HM.js} +66 -27
- package/dist/chunk-2MYQN7HM.js.map +1 -0
- package/dist/{chunk-DAZAXFSF.js → chunk-2RF2GIJQ.js} +57 -226
- package/dist/chunk-2RF2GIJQ.js.map +1 -0
- package/dist/{chunk-VEAERJVJ.js → chunk-3GL2Z5QK.js} +23 -9
- package/dist/chunk-3GL2Z5QK.js.map +1 -0
- package/dist/{chunk-IUQZ4Z7M.js → chunk-4CQIDQOT.js} +6 -1
- package/dist/chunk-4CQIDQOT.js.map +1 -0
- package/dist/{chunk-IXZJ3JOO.js → chunk-4KG27W2S.js} +10 -10
- package/dist/chunk-4KG27W2S.js.map +1 -0
- package/dist/{chunk-54AJIO3E.js → chunk-5QQTYWEU.js} +4 -3
- package/dist/chunk-5QQTYWEU.js.map +1 -0
- package/dist/chunk-65DTCCJ7.js +21 -0
- package/dist/chunk-65DTCCJ7.js.map +1 -0
- package/dist/{chunk-7NADDA2V.js → chunk-A5DKHMUN.js} +20 -8
- package/dist/chunk-A5DKHMUN.js.map +1 -0
- package/dist/{chunk-WYLMJQVH.js → chunk-B63XPWQ4.js} +24 -18
- package/dist/chunk-B63XPWQ4.js.map +1 -0
- package/dist/{chunk-L6G35FU5.js → chunk-CAR6FHK6.js} +5 -5
- package/dist/{chunk-7GJQ5RGA.js → chunk-CPCX67TI.js} +20 -22
- package/dist/{chunk-7GJQ5RGA.js.map → chunk-CPCX67TI.js.map} +1 -1
- package/dist/{chunk-XVPQGCH4.js → chunk-CQBVCYI2.js} +36 -50
- package/dist/chunk-CQBVCYI2.js.map +1 -0
- package/dist/chunk-DBU5CXBV.js +4731 -0
- package/dist/chunk-DBU5CXBV.js.map +1 -0
- package/dist/chunk-DHJD77OW.js +81 -0
- package/dist/chunk-DHJD77OW.js.map +1 -0
- package/dist/{chunk-XGZ5EVMB.js → chunk-EDZSNPE5.js} +2 -2
- package/dist/{chunk-736DW4V3.js → chunk-EFWZPUTC.js} +2 -2
- package/dist/chunk-EPFL6CTE.js +448 -0
- package/dist/chunk-EPFL6CTE.js.map +1 -0
- package/dist/{chunk-3P3ES4XU.js → chunk-GHLVXVZD.js} +3 -5
- package/dist/{chunk-3P3ES4XU.js.map → chunk-GHLVXVZD.js.map} +1 -1
- package/dist/{chunk-4UHNXY6B.js → chunk-H3SOOJ2I.js} +88 -294
- package/dist/chunk-H3SOOJ2I.js.map +1 -0
- package/dist/{chunk-MJSXP4LW.js → chunk-HPJGOLTN.js} +6 -8
- package/dist/{chunk-MJSXP4LW.js.map → chunk-HPJGOLTN.js.map} +1 -1
- package/dist/{chunk-J6FUAIRR.js → chunk-HRGBS2PA.js} +4 -6
- package/dist/{chunk-J6FUAIRR.js.map → chunk-HRGBS2PA.js.map} +1 -1
- package/dist/{chunk-FDUD3W5V.js → chunk-ITUXPJIS.js} +55 -58
- package/dist/chunk-ITUXPJIS.js.map +1 -0
- package/dist/{chunk-ETKZWJ4B.js → chunk-JBIKAAT3.js} +2 -2
- package/dist/{chunk-ETKZWJ4B.js.map → chunk-JBIKAAT3.js.map} +1 -1
- package/dist/{chunk-3ZW7HPY5.js → chunk-KAJZHIQ4.js} +13 -10
- package/dist/chunk-KAJZHIQ4.js.map +1 -0
- package/dist/{chunk-OWVVI4VQ.js → chunk-KINZ23CV.js} +107 -4535
- package/dist/chunk-KINZ23CV.js.map +1 -0
- package/dist/{chunk-PCX2JQ2J.js → chunk-LRYV3SK7.js} +9 -7
- package/dist/{chunk-PCX2JQ2J.js.map → chunk-LRYV3SK7.js.map} +1 -1
- package/dist/{chunk-ACBEHJAH.js → chunk-NIKXHWOL.js} +11 -13
- package/dist/{chunk-ACBEHJAH.js.map → chunk-NIKXHWOL.js.map} +1 -1
- package/dist/chunk-OKDRDT74.js +209 -0
- package/dist/chunk-OKDRDT74.js.map +1 -0
- package/dist/chunk-OKYSNAS3.js +2144 -0
- package/dist/chunk-OKYSNAS3.js.map +1 -0
- package/dist/{chunk-B676GPS2.js → chunk-OLWTRUTS.js} +7 -3
- package/dist/{chunk-B676GPS2.js.map → chunk-OLWTRUTS.js.map} +1 -1
- package/dist/{chunk-WU5CZPLD.js → chunk-QQ6ELLSA.js} +6 -8
- package/dist/{chunk-WU5CZPLD.js.map → chunk-QQ6ELLSA.js.map} +1 -1
- package/dist/{chunk-NAAMHWSI.js → chunk-QZ6ROAJU.js} +5 -4
- package/dist/chunk-QZ6ROAJU.js.map +1 -0
- package/dist/{chunk-GEHL43VE.js → chunk-R7RSCBI7.js} +130 -47
- package/dist/chunk-R7RSCBI7.js.map +1 -0
- package/dist/{chunk-LSWP7MU2.js → chunk-U6VPKMGC.js} +127 -27
- package/dist/chunk-U6VPKMGC.js.map +1 -0
- package/dist/{chunk-W4VW5XYB.js → chunk-US456VUI.js} +6 -6
- package/dist/{chunk-O75FOHXS.js → chunk-V44J2MXV.js} +64 -36
- package/dist/chunk-V44J2MXV.js.map +1 -0
- package/dist/{chunk-4Y53PDH6.js → chunk-VJQKL3YH.js} +10 -7
- package/dist/{chunk-4Y53PDH6.js.map → chunk-VJQKL3YH.js.map} +1 -1
- package/dist/{chunk-VRPLZERE.js → chunk-VJSQSLBM.js} +47 -26
- package/dist/chunk-VJSQSLBM.js.map +1 -0
- package/dist/{chunk-PKW3H26Z.js → chunk-VYOJOX4Z.js} +9 -7
- package/dist/chunk-VYOJOX4Z.js.map +1 -0
- package/dist/chunk-WY2K35OL.js +269 -0
- package/dist/chunk-WY2K35OL.js.map +1 -0
- package/dist/{chunk-PAOVPSP6.js → chunk-ZFJJ3EXC.js} +53 -5
- package/dist/chunk-ZFJJ3EXC.js.map +1 -0
- package/dist/{cli-U2BEUA55.js → cli-KKRKBU5T.js} +71 -40
- package/dist/{cli-U2BEUA55.js.map → cli-KKRKBU5T.js.map} +1 -1
- package/dist/config-JMRUNYE6.js +37 -0
- package/dist/discover-B5HF6SHM.js +102 -0
- package/dist/discover-B5HF6SHM.js.map +1 -0
- package/dist/doctor-ZBG7X66D.js +32 -0
- package/dist/edit-PZJIILQE.js +40 -0
- package/dist/{fund-Y5IAHZ5D.js → fund-EUDH5KPA.js} +19 -19
- package/dist/index.js +1 -1
- package/dist/{inspect-NFQ6SQQQ.js → inspect-QC6WEQPN.js} +20 -20
- package/dist/{install-DXX7PVUP.js → install-GNK2W3PI.js} +196 -78
- package/dist/install-GNK2W3PI.js.map +1 -0
- package/dist/outcome-KSGWZHUS.js +24 -0
- package/dist/pay-BC4UICPA.js +361 -0
- package/dist/pay-BC4UICPA.js.map +1 -0
- package/dist/publish-LXWFDIKF.js +42 -0
- package/dist/{read-W7QVRBVD.js → read-JMNUQ56P.js} +21 -21
- package/dist/{run-CJWPGMIQ.js → run-XYTQ5TWQ.js} +52 -45
- package/dist/{run-CJWPGMIQ.js.map → run-XYTQ5TWQ.js.map} +1 -1
- package/dist/search-TSQAB45E.js +25 -0
- package/dist/{send-C5EOKXOU.js → send-G746D7PQ.js} +14 -15
- package/dist/{send-C5EOKXOU.js.map → send-G746D7PQ.js.map} +1 -1
- package/dist/{session-OBCUUIFX.js → session-JBKWMJ24.js} +17 -17
- package/dist/{skill-heal-D6EPLPS6.js → skill-heal-WKD67SLJ.js} +17 -9
- package/dist/skill-heal-WKD67SLJ.js.map +1 -0
- package/dist/skill-placement-RIU4AMC2.js +20 -0
- package/dist/{uninstall-OWJNJ5LI.js → uninstall-5E263VTS.js} +12 -12
- package/dist/uninstall-5E263VTS.js.map +1 -0
- package/dist/{update-24Y2CQTT.js → update-R76LHOZW.js} +7 -8
- package/dist/{update-24Y2CQTT.js.map → update-R76LHOZW.js.map} +1 -1
- package/dist/{wallet-SLRIYJ2U.js → wallet-TQ7D5EQ7.js} +7 -8
- package/dist/{wallet-OFXDIIGP.js → wallet-ZAVXWLWP.js} +11 -12
- package/dist/wallet-ZAVXWLWP.js.map +1 -0
- package/docs/agent-permissions.md +17 -2
- package/docs/command-reference.md +84 -42
- package/docs/safety-model.md +9 -0
- package/package.json +1 -1
- package/skills/tenjin/SKILL.md +38 -29
- package/skills/tenjin-pay/SKILL.md +76 -0
- package/skills/tenjin-publish/SKILL.md +10 -7
- package/skills/tenjin-search/SKILL.md +18 -13
- package/skills/tenjin-search/references/permissions.md +9 -3
- package/dist/chunk-3ZW7HPY5.js.map +0 -1
- package/dist/chunk-4UHNXY6B.js.map +0 -1
- package/dist/chunk-54AJIO3E.js.map +0 -1
- package/dist/chunk-7NADDA2V.js.map +0 -1
- package/dist/chunk-DAZAXFSF.js.map +0 -1
- package/dist/chunk-DTCXO7HS.js +0 -791
- package/dist/chunk-DTCXO7HS.js.map +0 -1
- package/dist/chunk-FDUD3W5V.js.map +0 -1
- package/dist/chunk-GEHL43VE.js.map +0 -1
- package/dist/chunk-IU2HVT3Y.js +0 -313
- package/dist/chunk-IU2HVT3Y.js.map +0 -1
- package/dist/chunk-IUQZ4Z7M.js.map +0 -1
- package/dist/chunk-IXZJ3JOO.js.map +0 -1
- package/dist/chunk-LSWP7MU2.js.map +0 -1
- package/dist/chunk-NAAMHWSI.js.map +0 -1
- package/dist/chunk-O75FOHXS.js.map +0 -1
- package/dist/chunk-OWVVI4VQ.js.map +0 -1
- package/dist/chunk-PAOVPSP6.js.map +0 -1
- package/dist/chunk-PKW3H26Z.js.map +0 -1
- package/dist/chunk-PQZVDCCA.js +0 -125
- package/dist/chunk-PQZVDCCA.js.map +0 -1
- package/dist/chunk-QWBUKIP2.js.map +0 -1
- package/dist/chunk-VEAERJVJ.js.map +0 -1
- package/dist/chunk-VRPLZERE.js.map +0 -1
- package/dist/chunk-WYLMJQVH.js.map +0 -1
- package/dist/chunk-XVPQGCH4.js.map +0 -1
- package/dist/chunk-ZQIQ55KK.js +0 -51
- package/dist/chunk-ZQIQ55KK.js.map +0 -1
- package/dist/config-CNUIX23Q.js +0 -32
- package/dist/doctor-QJJXRWTO.js +0 -31
- package/dist/edit-HJ44P44P.js +0 -40
- package/dist/install-DXX7PVUP.js.map +0 -1
- package/dist/outcome-ANV4QIED.js +0 -24
- package/dist/publish-PCBTCXCZ.js +0 -42
- package/dist/search-JGAVKTYJ.js +0 -25
- package/dist/skill-heal-D6EPLPS6.js.map +0 -1
- package/dist/uninstall-OWJNJ5LI.js.map +0 -1
- /package/dist/{buy-2JBYPHAI.js.map → buy-VIRNSYGN.js.map} +0 -0
- /package/dist/{chunk-L6G35FU5.js.map → chunk-CAR6FHK6.js.map} +0 -0
- /package/dist/{chunk-XGZ5EVMB.js.map → chunk-EDZSNPE5.js.map} +0 -0
- /package/dist/{chunk-736DW4V3.js.map → chunk-EFWZPUTC.js.map} +0 -0
- /package/dist/{chunk-W4VW5XYB.js.map → chunk-US456VUI.js.map} +0 -0
- /package/dist/{config-CNUIX23Q.js.map → config-JMRUNYE6.js.map} +0 -0
- /package/dist/{doctor-QJJXRWTO.js.map → doctor-ZBG7X66D.js.map} +0 -0
- /package/dist/{edit-HJ44P44P.js.map → edit-PZJIILQE.js.map} +0 -0
- /package/dist/{fund-Y5IAHZ5D.js.map → fund-EUDH5KPA.js.map} +0 -0
- /package/dist/{inspect-NFQ6SQQQ.js.map → inspect-QC6WEQPN.js.map} +0 -0
- /package/dist/{outcome-ANV4QIED.js.map → outcome-KSGWZHUS.js.map} +0 -0
- /package/dist/{publish-PCBTCXCZ.js.map → publish-LXWFDIKF.js.map} +0 -0
- /package/dist/{read-W7QVRBVD.js.map → read-JMNUQ56P.js.map} +0 -0
- /package/dist/{search-JGAVKTYJ.js.map → search-TSQAB45E.js.map} +0 -0
- /package/dist/{session-OBCUUIFX.js.map → session-JBKWMJ24.js.map} +0 -0
- /package/dist/{wallet-OFXDIIGP.js.map → skill-placement-RIU4AMC2.js.map} +0 -0
- /package/dist/{wallet-SLRIYJ2U.js.map → wallet-TQ7D5EQ7.js.map} +0 -0
|
@@ -1,36 +1,39 @@
|
|
|
1
1
|
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
SESSION_CHAIN_ID
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-QQ6ELLSA.js";
|
|
5
5
|
import {
|
|
6
6
|
SIWX_HEADER,
|
|
7
7
|
buildSiwxHeader
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-KINZ23CV.js";
|
|
9
9
|
import {
|
|
10
10
|
getUsdcBalance
|
|
11
11
|
} from "./chunk-MJZZTKCC.js";
|
|
12
12
|
import {
|
|
13
13
|
describeWallet,
|
|
14
14
|
resolveWalletProvider
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-CPCX67TI.js";
|
|
16
16
|
import {
|
|
17
17
|
fetchFailureToCliError,
|
|
18
18
|
httpRequest
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-5QQTYWEU.js";
|
|
20
20
|
import {
|
|
21
21
|
emitNotice,
|
|
22
22
|
emitWriteNotice
|
|
23
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-OLWTRUTS.js";
|
|
24
24
|
import {
|
|
25
25
|
toMoney
|
|
26
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-EFWZPUTC.js";
|
|
27
27
|
import {
|
|
28
28
|
loadRawConfig,
|
|
29
29
|
resolveSettings
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-U6VPKMGC.js";
|
|
31
|
+
import {
|
|
32
|
+
PRODUCTION_ORIGIN
|
|
33
|
+
} from "./chunk-2MYQN7HM.js";
|
|
31
34
|
import {
|
|
32
35
|
CliError
|
|
33
|
-
} from "./chunk-
|
|
36
|
+
} from "./chunk-ZFJJ3EXC.js";
|
|
34
37
|
import {
|
|
35
38
|
getAddress,
|
|
36
39
|
isAddress
|
|
@@ -59,7 +62,7 @@ async function openInBrowser(url, opts = {}) {
|
|
|
59
62
|
|
|
60
63
|
// src/commands/fund.ts
|
|
61
64
|
var CHECKOUT_HOST = "pay.coinbase.com";
|
|
62
|
-
var FUND_ORIGIN =
|
|
65
|
+
var FUND_ORIGIN = PRODUCTION_ORIGIN;
|
|
63
66
|
var MAX_PRESET_USD = 1e5;
|
|
64
67
|
var POLL_INTERVAL_MS = 5e3;
|
|
65
68
|
var POLL_TIMEOUT_MS = 6e5;
|
|
@@ -234,4 +237,4 @@ async function pollForFunds(ctx, desc, rpcUrl, startBalance, opts) {
|
|
|
234
237
|
export {
|
|
235
238
|
runFund
|
|
236
239
|
};
|
|
237
|
-
//# sourceMappingURL=chunk-
|
|
240
|
+
//# sourceMappingURL=chunk-KAJZHIQ4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/open-url.ts","../src/commands/fund.ts"],"sourcesContent":["import { execFile } from 'node:child_process';\n\n/**\n * Open a URL in the platform's default browser, best-effort. Follows the\n * passphrase.ts subprocess rules: an argv array (never a shell), a hard\n * timeout, and failure as a return value rather than a throw — callers print\n * the URL first, so a machine without an opener degrades to copy/paste.\n * Windows uses rundll32's FileProtocolHandler because `start` exists only\n * inside cmd.exe, and spawning a shell around an attacker-influenced string is\n * the injection shape this module exists to avoid.\n */\n\nexport interface OpenUrlOptions {\n platform?: NodeJS.Platform;\n execFileImpl?: typeof execFile;\n}\n\nconst OPEN_TIMEOUT_MS = 5000;\n\nexport function openerFor(platform: NodeJS.Platform): { cmd: string; args: string[] } {\n if (platform === 'darwin') return { cmd: 'open', args: [] };\n if (platform === 'win32') return { cmd: 'rundll32', args: ['url.dll,FileProtocolHandler'] };\n return { cmd: 'xdg-open', args: [] };\n}\n\nexport async function openInBrowser(url: string, opts: OpenUrlOptions = {}): Promise<boolean> {\n const { cmd, args } = openerFor(opts.platform ?? process.platform);\n const run = opts.execFileImpl ?? execFile;\n return await new Promise((resolve) => {\n run(cmd, [...args, url], { timeout: OPEN_TIMEOUT_MS, windowsHide: true }, (err) =>\n resolve(err === null),\n );\n });\n}\n","import { getAddress, isAddress } from 'viem';\nimport { CliError } from '../lib/errors';\nimport { loadRawConfig, resolveSettings } from '../lib/config';\nimport { httpRequest, fetchFailureToCliError, type HttpRequestOptions } from '../lib/http';\nimport { buildSiwxHeader, SIWX_HEADER } from '../lib/siwx';\nimport { SESSION_CHAIN_ID } from '../lib/session-key';\nimport {\n describeWallet,\n resolveWalletProvider,\n type ResolveWalletProviderOptions,\n} from '../lib/wallet';\nimport { getUsdcBalance } from '../lib/usdc';\nimport { toMoney } from '../lib/money';\nimport { emitNotice, emitWriteNotice } from '../lib/output';\nimport { openInBrowser } from '../lib/open-url';\nimport { PRODUCTION_ORIGIN } from '../lib/production-origin';\nimport type { CommandContext, CommandResult } from '../context';\n\n/*\n * `tenjin fund`: card-fund THIS wallet via Coinbase Onramp. The CLI signs a\n * SIWX proof with the wallet's own key and asks the Tenjin backend to mint a\n * Coinbase-hosted checkout URL for that same address (the server refuses any\n * other address, per Coinbase's onboarding-verified auth model). The money\n * moves entirely on Coinbase's side; the minted session grants no spending\n * power over the wallet. Two Coinbase properties shape the UX here: the URL is\n * single-use and expires in ~5 minutes (mint fresh per run, open immediately,\n * never persist), and it is bound to this machine's public IP at mint time, so\n * it must be opened in a browser on this machine/network.\n */\n\n/** The only host a minted checkout URL may point at; anything else is refused unopened. */\nconst CHECKOUT_HOST = 'pay.coinbase.com';\n/**\n * fund talks to production, full stop (owner decision, 2026-08-12): the mint\n * signs with the wallet key, so this path takes no override -- not `--base-url`,\n * not the env, not config. Cutting the surface entirely is what lets the verb\n * sit in the free allowlist tier with nothing to caveat.\n */\nconst FUND_ORIGIN = PRODUCTION_ORIGIN;\n/** Matches the server's presetAmount bound (app/api/cdp/session bodySchema). */\nconst MAX_PRESET_USD = 100_000;\nconst POLL_INTERVAL_MS = 5_000;\nconst POLL_TIMEOUT_MS = 600_000;\n\n/**\n * Why the run is not reporting an arrival, kept distinct in the envelope because\n * three different outcomes otherwise collapse into `funded: false`: the run never\n * waited, it wanted to but could not read a baseline balance, or it waited and\n * the deadline won. Only `timed-out` says anything about the purchase.\n */\nexport type FundPollStatus = 'skipped' | 'unavailable' | 'timed-out' | 'arrived';\n\nexport interface FundOptions extends ResolveWalletProviderOptions {\n /** Optional USD preset forwarded to Coinbase (clamped upward to its own floor there). */\n amountUsd?: string;\n /** Skip the browser open (still prints the URL). */\n open?: boolean;\n /** Poll the balance after issuing the link. Defaults to ON at a TTY, OFF otherwise. */\n wait?: boolean;\n fetchImpl?: typeof fetch;\n openUrl?: typeof openInBrowser;\n /** Poll seams so tests never sleep for real. */\n sleep?: (ms: number) => Promise<void>;\n pollIntervalMs?: number;\n pollTimeoutMs?: number;\n}\n\nexport async function runFund(ctx: CommandContext, opts: FundOptions = {}): Promise<CommandResult> {\n const preset = parsePreset(opts.amountUsd);\n\n const provider = resolveWalletProvider(ctx, opts);\n const desc = await describeWallet(provider);\n const address = checksummed(desc.address);\n const signer = await provider.getSigner();\n\n const config = await loadRawConfig(ctx.dataDir);\n const settings = resolveSettings({ config, flags: {}, env: process.env });\n const baseUrl = FUND_ORIGIN;\n const rpcUrl = settings.rpcUrl.value;\n\n // Waiting is an INTERACTIVE posture: a human is standing at the terminal with\n // a browser open. Piped, --json, and MCP runs default to not waiting, because\n // the envelope carrying the link is written only after runFund returns, and a\n // link that expires in ~5 minutes is worthless after a 10-minute poll.\n const shouldWait = opts.wait ?? ctx.io.isTTY;\n\n // Read the balance BEFORE minting so the poll has a baseline; an RPC flake\n // here only disables the wait, it never blocks funding.\n const startBalance = shouldWait ? await balanceOrUndefined(desc, rpcUrl) : undefined;\n\n const siwxHeader = await buildSiwxHeader(signer, { baseUrl, chainId: SESSION_CHAIN_ID });\n const request: HttpRequestOptions = {\n method: 'POST',\n timeoutMs: ctx.flags.timeout,\n headers: { [SIWX_HEADER]: siwxHeader },\n jsonBody: {\n mode: 'onramp',\n address,\n ...(preset !== undefined ? { presetAmount: preset } : {}),\n },\n ...(opts.fetchImpl !== undefined ? { fetchImpl: opts.fetchImpl } : {}),\n };\n const res = await httpRequest(`${baseUrl}/api/cdp/session`, request);\n if (!res.ok) {\n throw fetchFailureToCliError(res, {\n fix: 'Check your network, then retry.',\n });\n }\n const url = checkoutUrlFrom(res.status, res.json);\n\n // The link goes out on EVERY surface and before any waiting: it is single-use\n // with a ~5 minute expiry, and the stdout envelope that also carries it is\n // written only after this function returns. A piped or agent-driven run is\n // exactly the case that must not get the link after it has died, so these\n // three lines are write-notices (stderr, no TTY gate, no --json gate) rather\n // than human-mode notices. stdout stays exactly one JSON object.\n emitWriteNotice(ctx.io, `Coinbase Onramp checkout for ${address}:`);\n emitWriteNotice(ctx.io, ` ${url}`);\n emitWriteNotice(\n ctx.io,\n 'The link is single-use, expires in ~5 minutes, and only works in a browser on this machine (it is bound to this network). A Coinbase account is required.',\n );\n\n let opened = false;\n if (opts.open !== false && ctx.io.isTTY) {\n opened = await (opts.openUrl ?? openInBrowser)(url);\n emitNotice(\n ctx.io,\n opened ? 'Opened in your default browser.' : 'Could not open a browser; use the link above.',\n { json: ctx.flags.json },\n );\n }\n\n const funded =\n shouldWait && startBalance !== undefined\n ? await pollForFunds(ctx, desc, rpcUrl, startBalance, opts)\n : undefined;\n if (funded !== undefined) {\n emitWriteNotice(ctx.io, 'USDC arrived - you can close the checkout tab.');\n }\n const pollStatus: FundPollStatus = !shouldWait\n ? 'skipped'\n : startBalance === undefined\n ? 'unavailable'\n : funded !== undefined\n ? 'arrived'\n : 'timed-out';\n\n const balanceAtomic = funded ?? startBalance;\n return {\n data: {\n address,\n checkoutUrl: url,\n opened,\n ...(preset !== undefined ? { presetAmount: preset } : {}),\n funded: funded !== undefined,\n pollStatus,\n ...(balanceAtomic !== undefined ? { balance: toMoney(balanceAtomic.toString()) } : {}),\n },\n humanLines:\n funded !== undefined\n ? [`Funded: balance is now ${toMoney(funded.toString()).usd} USDC on Base.`]\n : [\n 'Checkout link issued (printed above).',\n ...(pollStatus === 'unavailable'\n ? ['Could not read the balance to wait on it; the link is unaffected.']\n : []),\n 'Confirm arrival later with `tenjin wallet balance`.',\n ],\n };\n}\n\n/**\n * The route parses the destination with strict EIP-55 (`checksummedAddress`) but\n * the local wallet store accepts any casing, so an imported or hand-edited wallet\n * file would earn an unactionable 400 on a purely local condition. Normalize here\n * instead, as `send` does for its recipient.\n */\nfunction checksummed(address: string): string {\n if (!isAddress(address, { strict: false })) {\n throw new CliError(\n 'USAGE',\n `The active wallet address is not a valid EVM address: ${address}`,\n {\n fix: 'Check the wallet file, or create a fresh wallet with `tenjin wallet create`.',\n },\n );\n }\n return getAddress(address);\n}\n\nfunction parsePreset(raw: string | undefined): number | undefined {\n if (raw === undefined) return undefined;\n const n = Number(raw);\n if (!Number.isFinite(n) || n <= 0 || n > MAX_PRESET_USD) {\n throw new CliError('USAGE', `Amount must be a positive USD number up to ${MAX_PRESET_USD}.`, {\n fix: 'Example: tenjin fund 5',\n });\n }\n return n;\n}\n\n/**\n * Map the mint response to either the checkout URL or the coded refusal. The\n * URL is opened by this process, so it is validated as https on Coinbase's\n * checkout host before anything else sees it: a compromised or misconfigured\n * server must not be able to steer the user's browser anywhere else.\n */\nfunction checkoutUrlFrom(status: number, json: unknown): string {\n if (status === 200) {\n const url =\n typeof json === 'object' && json !== null ? (json as { url?: unknown }).url : undefined;\n if (typeof url === 'string') {\n let parsed: URL | undefined;\n try {\n parsed = new URL(url);\n } catch {\n parsed = undefined;\n }\n if (parsed !== undefined && parsed.protocol === 'https:' && parsed.host === CHECKOUT_HOST) {\n return url;\n }\n }\n throw new CliError(\n 'CONTRACT_MISMATCH',\n `The server's checkout URL was missing or not https://${CHECKOUT_HOST}; refusing to open it.`,\n );\n }\n const code = errorCode(json);\n if (status === 403 && code === 'region_not_supported') {\n throw new CliError('REFUSED', 'Coinbase Onramp is not available in your region.');\n }\n // A rejected proof is a local condition (\"retry\" never fixes it): the signed\n // window is clock-relative, and the domain is always the pinned production origin.\n if (status === 401) {\n throw new CliError('REFUSED', 'The funding endpoint rejected the signed proof.', {\n fix: 'Check this machine’s clock, then retry.',\n });\n }\n if (status === 429) {\n throw new CliError('RATE_LIMITED', 'The funding endpoint is rate limited right now.', {\n fix: 'Wait a minute and retry.',\n });\n }\n if (status === 503) {\n throw new CliError(\n 'API_UNREACHABLE',\n 'Production has no Coinbase Onramp configured right now.',\n {\n fix: 'Retry later.',\n },\n );\n }\n throw new CliError(\n 'API_UNREACHABLE',\n `The funding endpoint returned ${status}${code !== undefined ? ` (${code})` : ''}.`,\n { fix: 'Retry; if it persists, check the service status.' },\n );\n}\n\n/** The `error.code` of the withApi failure envelope, when the server sent one. */\nfunction errorCode(json: unknown): string | undefined {\n if (typeof json !== 'object' || json === null) return undefined;\n const err = (json as { error?: unknown }).error;\n if (typeof err !== 'object' || err === null) return undefined;\n const code = (err as { code?: unknown }).code;\n return typeof code === 'string' ? code : undefined;\n}\n\nasync function balanceOrUndefined(\n desc: { address: string },\n rpcUrl: string,\n): Promise<bigint | undefined> {\n try {\n return await getUsdcBalance(desc.address as `0x${string}`, rpcUrl);\n } catch {\n return undefined;\n }\n}\n\n/**\n * Wait for the purchased USDC to land: any balance above the pre-mint baseline\n * counts (Coinbase clamps presets, so an exact-amount check would be wrong).\n * RPC flakes mid-poll are tolerated; the deadline is the only exit besides\n * arrival, and timing out is a normal outcome (the human may still be paying),\n * not an error.\n */\nasync function pollForFunds(\n ctx: CommandContext,\n desc: { address: string },\n rpcUrl: string,\n startBalance: bigint,\n opts: FundOptions,\n): Promise<bigint | undefined> {\n const sleep =\n opts.sleep ?? ((ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms)));\n const interval = opts.pollIntervalMs ?? POLL_INTERVAL_MS;\n const deadline = Date.now() + (opts.pollTimeoutMs ?? POLL_TIMEOUT_MS);\n emitNotice(ctx.io, 'Waiting for the USDC to arrive (Ctrl-C is safe; the purchase is not).', {\n json: ctx.flags.json,\n });\n while (Date.now() < deadline) {\n await sleep(interval);\n const balance = await balanceOrUndefined(desc, rpcUrl);\n if (balance !== undefined && balance > startBalance) return balance;\n }\n return undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,gBAAgB;AAiBzB,IAAM,kBAAkB;AAEjB,SAAS,UAAU,UAA4D;AACpF,MAAI,aAAa,SAAU,QAAO,EAAE,KAAK,QAAQ,MAAM,CAAC,EAAE;AAC1D,MAAI,aAAa,QAAS,QAAO,EAAE,KAAK,YAAY,MAAM,CAAC,6BAA6B,EAAE;AAC1F,SAAO,EAAE,KAAK,YAAY,MAAM,CAAC,EAAE;AACrC;AAEA,eAAsB,cAAc,KAAa,OAAuB,CAAC,GAAqB;AAC5F,QAAM,EAAE,KAAK,KAAK,IAAI,UAAU,KAAK,YAAY,QAAQ,QAAQ;AACjE,QAAM,MAAM,KAAK,gBAAgB;AACjC,SAAO,MAAM,IAAI,QAAQ,CAAC,YAAY;AACpC;AAAA,MAAI;AAAA,MAAK,CAAC,GAAG,MAAM,GAAG;AAAA,MAAG,EAAE,SAAS,iBAAiB,aAAa,KAAK;AAAA,MAAG,CAAC,QACzE,QAAQ,QAAQ,IAAI;AAAA,IACtB;AAAA,EACF,CAAC;AACH;;;ACFA,IAAM,gBAAgB;AAOtB,IAAM,cAAc;AAEpB,IAAM,iBAAiB;AACvB,IAAM,mBAAmB;AACzB,IAAM,kBAAkB;AAyBxB,eAAsB,QAAQ,KAAqB,OAAoB,CAAC,GAA2B;AACjG,QAAM,SAAS,YAAY,KAAK,SAAS;AAEzC,QAAM,WAAW,sBAAsB,KAAK,IAAI;AAChD,QAAM,OAAO,MAAM,eAAe,QAAQ;AAC1C,QAAM,UAAU,YAAY,KAAK,OAAO;AACxC,QAAM,SAAS,MAAM,SAAS,UAAU;AAExC,QAAM,SAAS,MAAM,cAAc,IAAI,OAAO;AAC9C,QAAM,WAAW,gBAAgB,EAAE,QAAQ,OAAO,CAAC,GAAG,KA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