@visa/cli 4.1.0-rc.3 → 4.1.0-rc.30
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 +132 -242
- package/dist/checkout-engine/adapters/generic.d.ts +19 -0
- package/dist/checkout-engine/adapters/generic.js +201 -0
- package/dist/checkout-engine/adapters/index.d.ts +7 -0
- package/dist/checkout-engine/adapters/index.js +17 -0
- package/dist/checkout-engine/adapters/stripe-like.d.ts +10 -0
- package/dist/checkout-engine/adapters/stripe-like.js +21 -0
- package/dist/checkout-engine/browser-launch.d.ts +46 -0
- package/dist/checkout-engine/browser-launch.js +81 -0
- package/dist/checkout-engine/ceremony.d.ts +64 -0
- package/dist/checkout-engine/ceremony.js +261 -0
- package/dist/checkout-engine/cli-engine.d.ts +208 -0
- package/dist/checkout-engine/cli-engine.js +584 -0
- package/dist/checkout-engine/detect.d.ts +61 -0
- package/dist/checkout-engine/detect.js +392 -0
- package/dist/checkout-engine/evidence.d.ts +25 -0
- package/dist/checkout-engine/evidence.js +104 -0
- package/dist/checkout-engine/executor.d.ts +174 -0
- package/dist/checkout-engine/executor.js +1306 -0
- package/dist/checkout-engine/hosted-approval.d.ts +135 -0
- package/dist/checkout-engine/hosted-approval.js +311 -0
- package/dist/checkout-engine/index.d.ts +6 -0
- package/dist/checkout-engine/index.js +8 -0
- package/dist/checkout-engine/inline-target.d.ts +13 -0
- package/dist/checkout-engine/inline-target.js +37 -0
- package/dist/checkout-engine/instrument.d.ts +55 -0
- package/dist/checkout-engine/instrument.js +87 -0
- package/dist/checkout-engine/live-fill-approval.d.ts +43 -0
- package/dist/checkout-engine/live-fill-approval.js +90 -0
- package/dist/checkout-engine/mandate/card-mandate.d.ts +117 -0
- package/dist/checkout-engine/mandate/card-mandate.js +221 -0
- package/dist/checkout-engine/mandate/mandate-ledger.d.ts +135 -0
- package/dist/checkout-engine/mandate/mandate-ledger.js +318 -0
- package/dist/checkout-engine/mandate.d.ts +25 -0
- package/dist/checkout-engine/mandate.js +100 -0
- package/dist/checkout-engine/outcome.d.ts +30 -0
- package/dist/checkout-engine/outcome.js +225 -0
- package/dist/checkout-engine/owner-only-file.d.ts +19 -0
- package/dist/checkout-engine/owner-only-file.js +41 -0
- package/dist/checkout-engine/package.json +3 -0
- package/dist/checkout-engine/pay-args.d.ts +14 -0
- package/dist/checkout-engine/pay-args.js +44 -0
- package/dist/checkout-engine/pay.d.ts +1 -0
- package/dist/checkout-engine/pay.js +13 -0
- package/dist/checkout-engine/receipt.d.ts +81 -0
- package/dist/checkout-engine/receipt.js +109 -0
- package/dist/checkout-engine/repo-env.d.ts +11 -0
- package/dist/checkout-engine/repo-env.js +23 -0
- package/dist/checkout-engine/run-live-fill.d.ts +1 -0
- package/dist/checkout-engine/run-live-fill.js +493 -0
- package/dist/checkout-engine/types.d.ts +39 -0
- package/dist/checkout-engine/types.js +2 -0
- package/dist/checkout-engine/vgs-gateway/fetch-credential.d.mts +74 -0
- package/dist/checkout-engine/vgs-gateway/fetch-credential.mjs +248 -0
- package/dist/checkout-engine/vgs-gateway/server-mint-client.d.ts +82 -0
- package/dist/checkout-engine/vgs-gateway/server-mint-client.js +178 -0
- package/dist/checkout-engine/vgs-live-instrument.d.ts +168 -0
- package/dist/checkout-engine/vgs-live-instrument.js +289 -0
- package/dist/checkout-engine/vic-confirmation.d.ts +34 -0
- package/dist/checkout-engine/vic-confirmation.js +39 -0
- package/dist/cli.js +327 -375
- package/dist/mcp-server/index.js +253 -163
- package/dist/skills/pair-visa-agent/RUNTIMES.md +79 -0
- package/dist/skills/pair-visa-agent/SKILL.md +402 -0
- package/dist/skills/pair-visa-agent/scripts/setup.mjs +48 -0
- package/install.ps1 +3 -41
- package/install.sh +3 -35
- package/native/bin/win32-x64/visa-keychain-win.exe +0 -0
- package/package.json +9 -5
- package/server.json +3 -3
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import type { PurchaseAssurance, VgsCheckoutTarget } from './vgs-live-instrument.js';
|
|
2
|
+
/**
|
|
3
|
+
* Hosted purchase approval — the deployed-site replacement for the loopback
|
|
4
|
+
* ceremony page (ceremony.ts). The passkey tap happens on the verify-web
|
|
5
|
+
* deployment's /approve page instead of a 127.0.0.1 tab; this module is the
|
|
6
|
+
* runner's side of that relay (PKCE / device-code shape, mirroring the app's
|
|
7
|
+
* lib/server/agent-approval.ts):
|
|
8
|
+
*
|
|
9
|
+
* 1. Mint a 32-byte VERIFIER in process memory (never on disk — an approval
|
|
10
|
+
* lives and dies inside one run), derive challenge = sha256(verifier).
|
|
11
|
+
* 2. Register the purchase context under the challenge, then open
|
|
12
|
+
* <baseUrl>/approve?req=<challenge> in the operator's browser.
|
|
13
|
+
* 3. Poll the claim route with the verifier: `pending` while the operator
|
|
14
|
+
* signs in and taps the passkey; `completed` returns the assuranceData
|
|
15
|
+
* ONCE and the entry is gone.
|
|
16
|
+
*
|
|
17
|
+
* The URL only ever carries the challenge — useless without the verifier —
|
|
18
|
+
* and the verifier only ever travels to an HTTPS (or explicit-loopback)
|
|
19
|
+
* origin. The claim response echoes the context the approval was COMPLETED
|
|
20
|
+
* against; it is verified field-by-field against this run's checkout target
|
|
21
|
+
* before the assuranceData is accepted, so relay corruption or a divergent
|
|
22
|
+
* registration can never smuggle in an assurance scoped to something else
|
|
23
|
+
* (#5709 would reject it at cryptogram time anyway — this fails minutes
|
|
24
|
+
* earlier, with the divergent field named). Every network wait is bounded by
|
|
25
|
+
* the remaining deadline via AbortController — a stalled connection cannot
|
|
26
|
+
* hang the runner past the advertised timeout.
|
|
27
|
+
*/
|
|
28
|
+
export type HostedApprovalOptions = {
|
|
29
|
+
/** The enrollment web deployment origin (apps/web), e.g. https://web-….up.railway.app */
|
|
30
|
+
baseUrl: string;
|
|
31
|
+
/** Durable agentic token id from the CLI agent credential. */
|
|
32
|
+
tokenId: string;
|
|
33
|
+
target: VgsCheckoutTarget;
|
|
34
|
+
/** Prefills the approval page's enrollment-email field (optional). */
|
|
35
|
+
consumerEmail?: string;
|
|
36
|
+
/**
|
|
37
|
+
* BUDGET/mandate approval: `target.transactionAmount` is the approved spend
|
|
38
|
+
* CEILING (not one charge), so the server mints a BUDGET mint token that later
|
|
39
|
+
* accepts many sub-ceiling draws tap-free. Omit for a single-purchase approval.
|
|
40
|
+
*/
|
|
41
|
+
budget?: boolean;
|
|
42
|
+
/** Advisory max draws the ceiling intent may fulfil — carried onto the token. */
|
|
43
|
+
maxDraws?: number;
|
|
44
|
+
/**
|
|
45
|
+
* Per-purchase cap (decimal string, <= the ceiling) on a BUDGET approval —
|
|
46
|
+
* shown on the approval page as a worst-case term and carried onto the mint
|
|
47
|
+
* token so the displayed cap is the enforced cap. Budget mode only.
|
|
48
|
+
*/
|
|
49
|
+
perTransaction?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Agent-supplied one-liner describing what this approval is for. Sanitized
|
|
52
|
+
* here (control chars stripped, trimmed, capped) and rendered by the approval
|
|
53
|
+
* page in a clearly-labeled "written by the agent" block — provenance for the
|
|
54
|
+
* human to cross-check, never a trusted field.
|
|
55
|
+
*/
|
|
56
|
+
intent?: string;
|
|
57
|
+
log?: (line: string) => void;
|
|
58
|
+
/**
|
|
59
|
+
* Called once with the approval URL as DATA (not a log line) the instant it is
|
|
60
|
+
* known — before any polling. A headless agent (OpenClaw/Hermes) has no browser
|
|
61
|
+
* and no passkey; its whole job is to relay this URL to its human operator, so
|
|
62
|
+
* the URL must be capturable as a value, not just printed. The interactive CLI
|
|
63
|
+
* leaves this unset and relies on `log` + `openUrl`.
|
|
64
|
+
*/
|
|
65
|
+
onApprovalUrl?: (url: string) => void;
|
|
66
|
+
/** Injectable for tests; default opens the operator's default browser, best-effort. */
|
|
67
|
+
openUrl?: (url: string) => void;
|
|
68
|
+
fetchImpl?: typeof fetch;
|
|
69
|
+
/** Injectable for tests — never wall-clock-sleep in a unit test. */
|
|
70
|
+
sleep?: (ms: number) => Promise<void>;
|
|
71
|
+
now?: () => number;
|
|
72
|
+
pollIntervalMs?: number;
|
|
73
|
+
timeoutMs?: number;
|
|
74
|
+
};
|
|
75
|
+
/** One short sentence — must match the relay's cap (agent-approval.ts). */
|
|
76
|
+
export declare const APPROVAL_INTENT_MAX_CHARS = 200;
|
|
77
|
+
/**
|
|
78
|
+
* Sanitize an agent-supplied intent to what the relay will accept and the page
|
|
79
|
+
* will display: control chars (and JS line separators) stripped, trimmed,
|
|
80
|
+
* TRUNCATED to the cap (the runner is the agent's own side, so truncating here
|
|
81
|
+
* beats a failed registration; the server still rejects an over-cap value).
|
|
82
|
+
* Returns undefined when nothing displayable remains.
|
|
83
|
+
*/
|
|
84
|
+
export declare function sanitizeApprovalIntent(value: string | undefined): string | undefined;
|
|
85
|
+
/**
|
|
86
|
+
* The operator saw the request and said NO. Terminal and non-retryable: the
|
|
87
|
+
* relay entry is consumed, re-running would only re-ask a human who already
|
|
88
|
+
* refused. Callers must not classify this as transient.
|
|
89
|
+
*/
|
|
90
|
+
export declare class HostedApprovalDeclinedError extends Error {
|
|
91
|
+
constructor();
|
|
92
|
+
}
|
|
93
|
+
export declare const HOSTED_APPROVAL_TIMEOUT_MS: number;
|
|
94
|
+
export declare const HOSTED_APPROVAL_POLL_MS = 3000;
|
|
95
|
+
/** Emit a "still waiting" heartbeat roughly every this-many ms during the poll. */
|
|
96
|
+
export declare const HOSTED_APPROVAL_HEARTBEAT_MS = 30000;
|
|
97
|
+
/**
|
|
98
|
+
* Resolve the approval timeout: `CHECKOUT_APPROVAL_TIMEOUT_MS` (seconds*1000, an
|
|
99
|
+
* integer ms) overrides the default when it parses to a positive integer.
|
|
100
|
+
* Lets an operator widen the window for separate-device / headless approval
|
|
101
|
+
* without threading a flag through every caller. Invalid values fall back.
|
|
102
|
+
*/
|
|
103
|
+
export declare function resolveApprovalTimeoutMs(): number;
|
|
104
|
+
/**
|
|
105
|
+
* The staging apps/web deploy (which now hosts the /agent/enroll/approve page
|
|
106
|
+
* after the v4-verify-web GA graduation) — hosted approval is the NORMAL path
|
|
107
|
+
* (no local certs, no vendored SDK, no localhost anywhere), so its origin is a
|
|
108
|
+
* built-in default rather than per-machine config. Not a secret: it's the
|
|
109
|
+
* public page the operator's browser opens anyway.
|
|
110
|
+
*/
|
|
111
|
+
export declare const DEFAULT_APPROVAL_BASE_URL = "https://web-visa-code-preview.up.railway.app";
|
|
112
|
+
/**
|
|
113
|
+
* Flag > environment > built-in default. An explicitly EMPTY value
|
|
114
|
+
* (CHECKOUT_APPROVAL_BASE_URL='') opts out of hosted approval entirely —
|
|
115
|
+
* that is the loopback-ceremony escape hatch, so the default must not
|
|
116
|
+
* resurrect over it (?? not ||).
|
|
117
|
+
*/
|
|
118
|
+
export declare function resolveApprovalBaseUrl(flagValue: string | undefined, env?: Record<string, string | undefined>): string;
|
|
119
|
+
/**
|
|
120
|
+
* Validate the approval-page origin: HTTPS everywhere except explicit
|
|
121
|
+
* loopback hosts — the SAME policy the loader applies to the checkout URL.
|
|
122
|
+
* The claim call sends the verifier (the credential that releases the
|
|
123
|
+
* assurance), so a cleartext remote origin is never acceptable.
|
|
124
|
+
*/
|
|
125
|
+
export declare function assertApprovalBaseUrl(value: string): string;
|
|
126
|
+
/**
|
|
127
|
+
* The claim also releases the scoped MINT TOKEN (server-side mint, Phase 1) —
|
|
128
|
+
* bound to this exact approved purchase — so the runner can call the gateway
|
|
129
|
+
* mint routes without the VGS secret. Absent when the deployment ran the
|
|
130
|
+
* dev-auth stub (it mints no token); the caller then surfaces a clear error
|
|
131
|
+
* rather than falling back to a client-held secret.
|
|
132
|
+
*/
|
|
133
|
+
export declare function runHostedApproval(opts: HostedApprovalOptions): Promise<PurchaseAssurance & {
|
|
134
|
+
mintToken?: string;
|
|
135
|
+
}>;
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
2
|
+
import { exec } from 'node:child_process';
|
|
3
|
+
import { assuranceFromCeremony } from './ceremony.js';
|
|
4
|
+
/** One short sentence — must match the relay's cap (agent-approval.ts). */
|
|
5
|
+
export const APPROVAL_INTENT_MAX_CHARS = 200;
|
|
6
|
+
/**
|
|
7
|
+
* Sanitize an agent-supplied intent to what the relay will accept and the page
|
|
8
|
+
* will display: control chars (and JS line separators) stripped, trimmed,
|
|
9
|
+
* TRUNCATED to the cap (the runner is the agent's own side, so truncating here
|
|
10
|
+
* beats a failed registration; the server still rejects an over-cap value).
|
|
11
|
+
* Returns undefined when nothing displayable remains.
|
|
12
|
+
*/
|
|
13
|
+
export function sanitizeApprovalIntent(value) {
|
|
14
|
+
if (value === undefined)
|
|
15
|
+
return undefined;
|
|
16
|
+
const cleaned = value
|
|
17
|
+
.replace(/[\p{Cc}\u2028\u2029]/gu, '')
|
|
18
|
+
.trim()
|
|
19
|
+
.slice(0, APPROVAL_INTENT_MAX_CHARS)
|
|
20
|
+
.trim();
|
|
21
|
+
return cleaned.length > 0 ? cleaned : undefined;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The operator saw the request and said NO. Terminal and non-retryable: the
|
|
25
|
+
* relay entry is consumed, re-running would only re-ask a human who already
|
|
26
|
+
* refused. Callers must not classify this as transient.
|
|
27
|
+
*/
|
|
28
|
+
export class HostedApprovalDeclinedError extends Error {
|
|
29
|
+
constructor() {
|
|
30
|
+
super('The approver declined this request — the checkout was cancelled and nothing was charged');
|
|
31
|
+
this.name = 'HostedApprovalDeclinedError';
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export const HOSTED_APPROVAL_TIMEOUT_MS = 4 * 60 * 1000;
|
|
35
|
+
export const HOSTED_APPROVAL_POLL_MS = 3_000;
|
|
36
|
+
/** Emit a "still waiting" heartbeat roughly every this-many ms during the poll. */
|
|
37
|
+
export const HOSTED_APPROVAL_HEARTBEAT_MS = 30_000;
|
|
38
|
+
/**
|
|
39
|
+
* Resolve the approval timeout: `CHECKOUT_APPROVAL_TIMEOUT_MS` (seconds*1000, an
|
|
40
|
+
* integer ms) overrides the default when it parses to a positive integer.
|
|
41
|
+
* Lets an operator widen the window for separate-device / headless approval
|
|
42
|
+
* without threading a flag through every caller. Invalid values fall back.
|
|
43
|
+
*/
|
|
44
|
+
export function resolveApprovalTimeoutMs() {
|
|
45
|
+
const raw = process.env.CHECKOUT_APPROVAL_TIMEOUT_MS;
|
|
46
|
+
if (raw !== undefined) {
|
|
47
|
+
const n = Number(raw);
|
|
48
|
+
if (Number.isSafeInteger(n) && n > 0)
|
|
49
|
+
return n;
|
|
50
|
+
}
|
|
51
|
+
return HOSTED_APPROVAL_TIMEOUT_MS;
|
|
52
|
+
}
|
|
53
|
+
/** Unref'd so a raced-and-abandoned deadline timer can never hold the process open. */
|
|
54
|
+
const defaultSleep = (ms) => new Promise((r) => {
|
|
55
|
+
const t = setTimeout(r, ms);
|
|
56
|
+
t.unref?.();
|
|
57
|
+
});
|
|
58
|
+
function defaultOpenUrl(url) {
|
|
59
|
+
// Best-effort convenience only — the URL is always surfaced via `log`/
|
|
60
|
+
// `onApprovalUrl`, so this must never throw or hang if there is no browser.
|
|
61
|
+
// `CHECKOUT_SKIP_BROWSER_OPEN=1` disables it (headless/agent hosts where
|
|
62
|
+
// launching a browser on the WRONG machine is pointless or noisy).
|
|
63
|
+
if (process.env.CHECKOUT_SKIP_BROWSER_OPEN === '1')
|
|
64
|
+
return;
|
|
65
|
+
// Platform-appropriate opener; unknown platforms just skip (the URL is logged).
|
|
66
|
+
const opener = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'start ""' : 'xdg-open';
|
|
67
|
+
if (process.platform !== 'darwin' && process.platform !== 'win32' && process.platform !== 'linux')
|
|
68
|
+
return;
|
|
69
|
+
const quoted = `'${url.replaceAll("'", "'\\''")}'`;
|
|
70
|
+
try {
|
|
71
|
+
// exec is async and fire-and-forget; swallow the callback error so a missing
|
|
72
|
+
// opener binary (common on headless Linux) can never surface as a failure.
|
|
73
|
+
exec(`${opener} ${quoted}`, () => { });
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
// Spawn failure (no shell, sandboxed) — ignore; the printed URL is the path.
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The staging apps/web deploy (which now hosts the /agent/enroll/approve page
|
|
81
|
+
* after the v4-verify-web GA graduation) — hosted approval is the NORMAL path
|
|
82
|
+
* (no local certs, no vendored SDK, no localhost anywhere), so its origin is a
|
|
83
|
+
* built-in default rather than per-machine config. Not a secret: it's the
|
|
84
|
+
* public page the operator's browser opens anyway.
|
|
85
|
+
*/
|
|
86
|
+
export const DEFAULT_APPROVAL_BASE_URL = 'https://web-visa-code-preview.up.railway.app';
|
|
87
|
+
/**
|
|
88
|
+
* Flag > environment > built-in default. An explicitly EMPTY value
|
|
89
|
+
* (CHECKOUT_APPROVAL_BASE_URL='') opts out of hosted approval entirely —
|
|
90
|
+
* that is the loopback-ceremony escape hatch, so the default must not
|
|
91
|
+
* resurrect over it (?? not ||).
|
|
92
|
+
*/
|
|
93
|
+
export function resolveApprovalBaseUrl(flagValue, env = process.env) {
|
|
94
|
+
return (flagValue ?? env.CHECKOUT_APPROVAL_BASE_URL ?? DEFAULT_APPROVAL_BASE_URL).trim();
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Validate the approval-page origin: HTTPS everywhere except explicit
|
|
98
|
+
* loopback hosts — the SAME policy the loader applies to the checkout URL.
|
|
99
|
+
* The claim call sends the verifier (the credential that releases the
|
|
100
|
+
* assurance), so a cleartext remote origin is never acceptable.
|
|
101
|
+
*/
|
|
102
|
+
export function assertApprovalBaseUrl(value) {
|
|
103
|
+
let url;
|
|
104
|
+
try {
|
|
105
|
+
url = new URL(value);
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
throw new Error('--approval-base-url must be a valid http(s) origin');
|
|
109
|
+
}
|
|
110
|
+
const loopback = url.hostname === 'localhost' || url.hostname === '127.0.0.1';
|
|
111
|
+
if (url.protocol !== 'https:' && !(url.protocol === 'http:' && loopback)) {
|
|
112
|
+
throw new Error('--approval-base-url must use HTTPS (localhost is allowed for local testing) — ' +
|
|
113
|
+
'the approval claim carries a credential and never travels cleartext');
|
|
114
|
+
}
|
|
115
|
+
return value;
|
|
116
|
+
}
|
|
117
|
+
function stripTrailingSlashes(value) {
|
|
118
|
+
let out = value;
|
|
119
|
+
while (out.endsWith('/'))
|
|
120
|
+
out = out.slice(0, -1);
|
|
121
|
+
return out;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* The claim also releases the scoped MINT TOKEN (server-side mint, Phase 1) —
|
|
125
|
+
* bound to this exact approved purchase — so the runner can call the gateway
|
|
126
|
+
* mint routes without the VGS secret. Absent when the deployment ran the
|
|
127
|
+
* dev-auth stub (it mints no token); the caller then surfaces a clear error
|
|
128
|
+
* rather than falling back to a client-held secret.
|
|
129
|
+
*/
|
|
130
|
+
export async function runHostedApproval(opts) {
|
|
131
|
+
const { baseUrl, tokenId, target, consumerEmail, budget, maxDraws, perTransaction, intent,
|
|
132
|
+
// Default to stderr, NOT a no-op: the approval URL is the one thing a remote /
|
|
133
|
+
// SSH / headless-terminal human needs to proceed, and swallowing it (the old
|
|
134
|
+
// `() => {}` default) left it emitted nowhere readable. Tests inject their own.
|
|
135
|
+
log = (line) => void process.stderr.write(`${line}\n`), onApprovalUrl, openUrl = defaultOpenUrl, fetchImpl = fetch, sleep = defaultSleep, now = Date.now, pollIntervalMs = HOSTED_APPROVAL_POLL_MS,
|
|
136
|
+
// A human approving on a SEPARATE device (open the link, sign in, tap the
|
|
137
|
+
// passkey) needs more than the interactive 4-minute window; allow an env
|
|
138
|
+
// override without threading a flag through every caller.
|
|
139
|
+
timeoutMs = resolveApprovalTimeoutMs(), } = opts;
|
|
140
|
+
const base = stripTrailingSlashes(assertApprovalBaseUrl(baseUrl));
|
|
141
|
+
// The server's currency map is uppercase ISO 4217; the loader normalizes the
|
|
142
|
+
// target once, but normalize here too so a direct caller with a lowercase
|
|
143
|
+
// code registers (and verifies) the same value the relay stores.
|
|
144
|
+
const currency = target.transactionCurrencyCode.toUpperCase();
|
|
145
|
+
// Sanitize once, register + verify the SAME value: the relay stores the
|
|
146
|
+
// sanitized form, so equality below must compare against it, not the raw input.
|
|
147
|
+
const intentSanitized = sanitizeApprovalIntent(intent);
|
|
148
|
+
const verifier = randomBytes(32).toString('base64url');
|
|
149
|
+
const challenge = createHash('sha256').update(verifier, 'utf8').digest('base64url');
|
|
150
|
+
const deadline = now() + timeoutMs;
|
|
151
|
+
const timeoutError = () => new Error(`no passkey approval within ${Math.round(timeoutMs / 1000)}s — ` +
|
|
152
|
+
'the checkout was cancelled; run again to retry');
|
|
153
|
+
// Bound EVERY request by the remaining deadline: race the fetch against the
|
|
154
|
+
// (injectable) sleep and abort the request when the deadline wins, so a
|
|
155
|
+
// stalled connection can never hang the runner past the advertised timeout.
|
|
156
|
+
const TIMED_OUT = Symbol('timed-out');
|
|
157
|
+
async function fetchWithDeadline(url, init) {
|
|
158
|
+
const remaining = deadline - now();
|
|
159
|
+
if (remaining <= 0)
|
|
160
|
+
throw timeoutError();
|
|
161
|
+
const controller = new AbortController();
|
|
162
|
+
const winner = await Promise.race([
|
|
163
|
+
fetchImpl(url, { ...init, signal: controller.signal }),
|
|
164
|
+
sleep(remaining).then(() => TIMED_OUT),
|
|
165
|
+
]);
|
|
166
|
+
if (typeof winner === 'symbol') {
|
|
167
|
+
controller.abort();
|
|
168
|
+
throw timeoutError();
|
|
169
|
+
}
|
|
170
|
+
return winner;
|
|
171
|
+
}
|
|
172
|
+
const registerRes = await fetchWithDeadline(`${base}/api/vgs/agent-approval`, {
|
|
173
|
+
method: 'POST',
|
|
174
|
+
headers: { 'content-type': 'application/json' },
|
|
175
|
+
body: JSON.stringify({
|
|
176
|
+
challenge,
|
|
177
|
+
context: {
|
|
178
|
+
tokenId,
|
|
179
|
+
merchantName: target.merchantName,
|
|
180
|
+
merchantUrl: target.merchantUrl,
|
|
181
|
+
merchantCountryCode: target.merchantCountryCode,
|
|
182
|
+
amount: target.transactionAmount,
|
|
183
|
+
currency,
|
|
184
|
+
...(consumerEmail ? { consumerEmail } : {}),
|
|
185
|
+
...(budget ? { budget: true } : {}),
|
|
186
|
+
...(budget && maxDraws !== undefined ? { maxDraws } : {}),
|
|
187
|
+
...(budget && perTransaction !== undefined ? { perTransaction } : {}),
|
|
188
|
+
...(intentSanitized !== undefined ? { intent: intentSanitized } : {}),
|
|
189
|
+
},
|
|
190
|
+
}),
|
|
191
|
+
});
|
|
192
|
+
if (!registerRes.ok) {
|
|
193
|
+
const body = (await registerRes.json().catch(() => ({})));
|
|
194
|
+
throw new Error(`could not register the hosted approval (${registerRes.status})` +
|
|
195
|
+
(body.error ? `: ${body.error}` : ''));
|
|
196
|
+
}
|
|
197
|
+
// GA graduation: the approval page moved into apps/web under /agent/enroll
|
|
198
|
+
// (the /api/vgs/** routes above kept their paths verbatim).
|
|
199
|
+
const approveUrl = `${base}/agent/enroll/approve?req=${challenge}`;
|
|
200
|
+
// Surface the URL as DATA first (headless relay), then as a log line + best-
|
|
201
|
+
// effort browser open for the interactive case.
|
|
202
|
+
onApprovalUrl?.(approveUrl);
|
|
203
|
+
log(`approve the purchase in your browser: ${approveUrl}`);
|
|
204
|
+
openUrl(approveUrl);
|
|
205
|
+
let lastHeartbeat = now();
|
|
206
|
+
// Keep the event loop alive for the whole poll wait. `defaultSleep` unref()'s
|
|
207
|
+
// its timer (so the deadline race can't hang the process past the timeout), but
|
|
208
|
+
// that means the ONLY pending work between polls is an unref'd timer — in a bare
|
|
209
|
+
// CLI invocation (no stdin/other handles) node would exit 0 mid-poll, after the
|
|
210
|
+
// first `pending` claim and before the operator finishes the passkey, so the
|
|
211
|
+
// minted token is parked but never claimed. A ref'd keepalive, cleared on every
|
|
212
|
+
// exit, holds the process open until the poll loop returns/throws.
|
|
213
|
+
const keepAlive = setInterval(() => { }, 60_000);
|
|
214
|
+
try {
|
|
215
|
+
for (;;) {
|
|
216
|
+
const res = await fetchWithDeadline(`${base}/api/vgs/agent-approval/claim`, {
|
|
217
|
+
method: 'POST',
|
|
218
|
+
headers: { 'content-type': 'application/json' },
|
|
219
|
+
body: JSON.stringify({ verifier }),
|
|
220
|
+
});
|
|
221
|
+
if (res.ok) {
|
|
222
|
+
const doc = (await res.json().catch(() => null));
|
|
223
|
+
// The operator refused — terminal and immediate. Exit the wait now
|
|
224
|
+
// rather than polling out the timeout; retrying cannot help.
|
|
225
|
+
if (doc?.status === 'declined')
|
|
226
|
+
throw new HostedApprovalDeclinedError();
|
|
227
|
+
if (doc?.status === 'completed') {
|
|
228
|
+
if (doc.assuranceData === undefined || doc.assuranceData === null) {
|
|
229
|
+
throw new Error('hosted approval completed but carried no assuranceData');
|
|
230
|
+
}
|
|
231
|
+
// The context the approval was COMPLETED against must be exactly this
|
|
232
|
+
// run's checkout target — a divergent field means the relay entry was
|
|
233
|
+
// not ours (corruption, or a mutated registration) and the assurance
|
|
234
|
+
// is scoped to something else. Fail naming the field; no secrets here
|
|
235
|
+
// (merchant facts only).
|
|
236
|
+
const expected = {
|
|
237
|
+
tokenId,
|
|
238
|
+
merchantName: target.merchantName,
|
|
239
|
+
merchantUrl: target.merchantUrl,
|
|
240
|
+
merchantCountryCode: target.merchantCountryCode,
|
|
241
|
+
amount: target.transactionAmount,
|
|
242
|
+
currency,
|
|
243
|
+
};
|
|
244
|
+
for (const [field, want] of Object.entries(expected)) {
|
|
245
|
+
if (doc.context?.[field] !== want) {
|
|
246
|
+
throw new Error(`hosted approval context mismatch on ${field} — the approval was not for this ` +
|
|
247
|
+
'exact purchase; run the checkout again for a fresh link');
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
// A budget approval must complete AS a budget approval — a relay that
|
|
251
|
+
// dropped the flag would mint a single-purchase token that then rejects
|
|
252
|
+
// the first sub-ceiling draw. Compare the boolean explicitly (it is not a
|
|
253
|
+
// string, so it lives outside the string-map loop above).
|
|
254
|
+
if (Boolean(doc.context?.budget) !== Boolean(budget)) {
|
|
255
|
+
throw new Error('hosted approval context mismatch on budget — the approval was not for this ' +
|
|
256
|
+
'exact purchase; run the checkout again for a fresh link');
|
|
257
|
+
}
|
|
258
|
+
// The advisory draw ceiling must survive the relay intact too — a relay
|
|
259
|
+
// that dropped or altered maxDraws would mint a budget token whose draw
|
|
260
|
+
// count no longer matches what the operator approved. Only the budget
|
|
261
|
+
// path registers maxDraws, so only enforce it there; compare exactly,
|
|
262
|
+
// the omitted/undefined case included, so a silently dropped value is
|
|
263
|
+
// caught the same as a mutated one.
|
|
264
|
+
if (budget && doc.context?.maxDraws !== maxDraws) {
|
|
265
|
+
throw new Error('hosted approval context mismatch on maxDraws — the approval was not for this ' +
|
|
266
|
+
'exact purchase; run the checkout again for a fresh link');
|
|
267
|
+
}
|
|
268
|
+
// Same drop-or-mutate rule for the per-purchase cap: the term the
|
|
269
|
+
// operator read must be the term the token enforces.
|
|
270
|
+
if (budget && doc.context?.perTransaction !== perTransaction) {
|
|
271
|
+
throw new Error('hosted approval context mismatch on perTransaction — the approval was not for ' +
|
|
272
|
+
'this exact purchase; run the checkout again for a fresh link');
|
|
273
|
+
}
|
|
274
|
+
// The intent is display-only, but a relay that altered it showed the
|
|
275
|
+
// operator different words than the agent sent — refuse, either way.
|
|
276
|
+
if (doc.context?.intent !== intentSanitized) {
|
|
277
|
+
throw new Error('hosted approval context mismatch on intent — the approval was not for this ' +
|
|
278
|
+
'exact purchase; run the checkout again for a fresh link');
|
|
279
|
+
}
|
|
280
|
+
log('passkey approval received from the hosted page.');
|
|
281
|
+
return {
|
|
282
|
+
...assuranceFromCeremony(target, doc.assuranceData),
|
|
283
|
+
...(typeof doc.mintToken === 'string' && doc.mintToken
|
|
284
|
+
? { mintToken: doc.mintToken }
|
|
285
|
+
: {}),
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
// status 'pending' — the operator is still signing in / tapping.
|
|
289
|
+
}
|
|
290
|
+
else if (res.status === 404) {
|
|
291
|
+
// Registered moments ago, so absent now means expired or already claimed.
|
|
292
|
+
throw new Error('the hosted approval expired or was already used — run the checkout again for a fresh link');
|
|
293
|
+
}
|
|
294
|
+
// Any other status (429 rate bucket, transient 5xx) polls through.
|
|
295
|
+
if (now() >= deadline)
|
|
296
|
+
throw timeoutError();
|
|
297
|
+
// Heartbeat so a human staring at a terminal (or an agent tailing logs)
|
|
298
|
+
// knows the wait is live and where to approve — the loop is otherwise silent
|
|
299
|
+
// for up to the full timeout between the open and the completed claim.
|
|
300
|
+
if (now() - lastHeartbeat >= HOSTED_APPROVAL_HEARTBEAT_MS) {
|
|
301
|
+
lastHeartbeat = now();
|
|
302
|
+
const leftS = Math.max(0, Math.round((deadline - now()) / 1000));
|
|
303
|
+
log(`still waiting for approval (~${leftS}s left) — approve at ${approveUrl}`);
|
|
304
|
+
}
|
|
305
|
+
await sleep(pollIntervalMs);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
finally {
|
|
309
|
+
clearInterval(keepAlive);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { createCliCheckoutEngine, type CliReviewInput, type CliReviewFacts, type CliPayInput, type CliReceiptFacts, type CliStartMandateInput, type CliMandateFacts, type CliEngineDeps, } from './cli-engine.js';
|
|
2
|
+
export { prepareCheckout, submitApprovedCheckout, runCheckout, InMemoryPreparedCheckoutStore, } from './executor.js';
|
|
3
|
+
export type { CheckoutResult, CheckoutReview, CheckoutOutcome } from './executor.js';
|
|
4
|
+
export { HostedApprovalDeclinedError, sanitizeApprovalIntent, APPROVAL_INTENT_MAX_CHARS, } from './hosted-approval.js';
|
|
5
|
+
export { createCardMandate, drawFromMandate, MandateDrawDeclinedError, DEFAULT_MANDATE_MAX_DRAWS, type CreateCardMandateInput, type CreateCardMandateDeps, type CardMandateFacts, type DrawFromMandateInput, type DrawFromMandateDeps, type DrawResult, type CardMandateMerchant, } from './mandate/card-mandate.js';
|
|
6
|
+
export { MandateLedger, remainingMinor, defaultLedgerPath, CARD_MANDATE_LEDGER_VERSION, type CardMandateRecord, type CardMandateLedgerFile, type CardMandateDraw, type CardMandateReservation, } from './mandate/mandate-ledger.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Public API of @visa/checkout-engine. The pay_merchant tool in @visa/cli
|
|
2
|
+
// consumes createCliCheckoutEngine() through a structural seam; the core engine
|
|
3
|
+
// primitives are re-exported for direct/embedded use.
|
|
4
|
+
export { createCliCheckoutEngine, } from './cli-engine.js';
|
|
5
|
+
export { prepareCheckout, submitApprovedCheckout, runCheckout, InMemoryPreparedCheckoutStore, } from './executor.js';
|
|
6
|
+
export { HostedApprovalDeclinedError, sanitizeApprovalIntent, APPROVAL_INTENT_MAX_CHARS, } from './hosted-approval.js';
|
|
7
|
+
export { createCardMandate, drawFromMandate, MandateDrawDeclinedError, DEFAULT_MANDATE_MAX_DRAWS, } from './mandate/card-mandate.js';
|
|
8
|
+
export { MandateLedger, remainingMinor, defaultLedgerPath, CARD_MANDATE_LEDGER_VERSION, } from './mandate/mandate-ledger.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { VgsCheckoutTarget } from './vgs-live-instrument.js';
|
|
2
|
+
/**
|
|
3
|
+
* Build a checkout target from inline CLI flags (`--merchant-url` +
|
|
4
|
+
* `--amount`, with optional `--merchant-name` / `--country` / `--currency`)
|
|
5
|
+
* so any merchant can be paid without authoring a checkout JSON file first.
|
|
6
|
+
*
|
|
7
|
+
* Returns null when neither driving flag is present (file mode). Shape-only:
|
|
8
|
+
* the returned target flows through run-live-fill's existing validation block
|
|
9
|
+
* (positive-decimal amount, ISO codes, HTTPS), which stays the single source
|
|
10
|
+
* of truth — nothing is double-validated here except the URL parse, which
|
|
11
|
+
* must happen early because the merchant-name default derives from it.
|
|
12
|
+
*/
|
|
13
|
+
export declare function inlineTargetFromFlags(input: Map<string, string>): VgsCheckoutTarget | null;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build a checkout target from inline CLI flags (`--merchant-url` +
|
|
3
|
+
* `--amount`, with optional `--merchant-name` / `--country` / `--currency`)
|
|
4
|
+
* so any merchant can be paid without authoring a checkout JSON file first.
|
|
5
|
+
*
|
|
6
|
+
* Returns null when neither driving flag is present (file mode). Shape-only:
|
|
7
|
+
* the returned target flows through run-live-fill's existing validation block
|
|
8
|
+
* (positive-decimal amount, ISO codes, HTTPS), which stays the single source
|
|
9
|
+
* of truth — nothing is double-validated here except the URL parse, which
|
|
10
|
+
* must happen early because the merchant-name default derives from it.
|
|
11
|
+
*/
|
|
12
|
+
export function inlineTargetFromFlags(input) {
|
|
13
|
+
const merchantUrl = input.get('--merchant-url');
|
|
14
|
+
const amount = input.get('--amount');
|
|
15
|
+
if (merchantUrl === undefined && amount === undefined)
|
|
16
|
+
return null;
|
|
17
|
+
if (!merchantUrl || !amount) {
|
|
18
|
+
throw new Error('inline checkout needs both --merchant-url and --amount');
|
|
19
|
+
}
|
|
20
|
+
let host;
|
|
21
|
+
try {
|
|
22
|
+
host = new URL(merchantUrl).hostname;
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
throw new Error('--merchant-url must be a valid URL');
|
|
26
|
+
}
|
|
27
|
+
if (!host) {
|
|
28
|
+
throw new Error('--merchant-url must have a hostname');
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
merchantName: input.get('--merchant-name') ?? host,
|
|
32
|
+
merchantUrl,
|
|
33
|
+
merchantCountryCode: input.get('--country') ?? 'US',
|
|
34
|
+
transactionAmount: amount,
|
|
35
|
+
transactionCurrencyCode: input.get('--currency') ?? 'USD',
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export type CardCredential = {
|
|
2
|
+
pan: string;
|
|
3
|
+
expMonth: number;
|
|
4
|
+
expYear: number;
|
|
5
|
+
cvc: string;
|
|
6
|
+
cardholderName: string;
|
|
7
|
+
/** Dynamic payment credential expiry, distinct from the card expiration. */
|
|
8
|
+
credentialExpiresAt?: string;
|
|
9
|
+
};
|
|
10
|
+
export type InstrumentContext = {
|
|
11
|
+
merchantHost: string;
|
|
12
|
+
amountMinor: number;
|
|
13
|
+
currency: string;
|
|
14
|
+
};
|
|
15
|
+
export type InstrumentKind = 'test-card' | 'vgs-alias' | 'agentic-token';
|
|
16
|
+
export interface Instrument {
|
|
17
|
+
kind: InstrumentKind;
|
|
18
|
+
getCredential(ctx: InstrumentContext): Promise<CardCredential>;
|
|
19
|
+
}
|
|
20
|
+
export declare const OFFICIAL_TEST_PANS: {
|
|
21
|
+
readonly visa: "4242424242424242";
|
|
22
|
+
readonly visaAlt: "4111111111111111";
|
|
23
|
+
readonly visaDecline: "4000000000000002";
|
|
24
|
+
readonly visaSlowConfirm: "4000000000000069";
|
|
25
|
+
readonly visaUnknownOutcome: "4000000000000044";
|
|
26
|
+
readonly visaChallenge: "4000000000000010";
|
|
27
|
+
readonly visaEmailOtp: "4000000000000077";
|
|
28
|
+
};
|
|
29
|
+
export type TestCardOptions = {
|
|
30
|
+
pan?: string;
|
|
31
|
+
cardholderName?: string;
|
|
32
|
+
cvc?: string;
|
|
33
|
+
expMonth?: number;
|
|
34
|
+
expYear?: number;
|
|
35
|
+
};
|
|
36
|
+
export declare class TestCardInstrument implements Instrument {
|
|
37
|
+
readonly kind: "test-card";
|
|
38
|
+
private readonly credential;
|
|
39
|
+
constructor(opts?: TestCardOptions);
|
|
40
|
+
getCredential(_ctx: InstrumentContext): Promise<CardCredential>;
|
|
41
|
+
}
|
|
42
|
+
export declare class VgsAliasInstrument implements Instrument {
|
|
43
|
+
private readonly _alias;
|
|
44
|
+
readonly kind: "vgs-alias";
|
|
45
|
+
constructor(_alias: string);
|
|
46
|
+
getCredential(_ctx: InstrumentContext): Promise<CardCredential>;
|
|
47
|
+
}
|
|
48
|
+
export declare class AgenticTokenInstrument implements Instrument {
|
|
49
|
+
private readonly tokenRef;
|
|
50
|
+
private readonly mintCredential?;
|
|
51
|
+
readonly kind: "agentic-token";
|
|
52
|
+
private used;
|
|
53
|
+
constructor(tokenRef: string, mintCredential?: ((ctx: InstrumentContext) => Promise<CardCredential>) | undefined);
|
|
54
|
+
getCredential(ctx: InstrumentContext): Promise<CardCredential>;
|
|
55
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// Instrument abstraction: the checkout engine is deliberately blind to WHERE
|
|
2
|
+
// card credentials come from. Official test PANs, callback-backed agentic
|
|
3
|
+
// credentials, and owner-only VIC harness files are enabled; VGS aliases stay
|
|
4
|
+
// stubbed until a reveal seam exists. The executor remains unchanged across
|
|
5
|
+
// every instrument.
|
|
6
|
+
// Official public test PANs only. These are the sanctioned Visa/network test
|
|
7
|
+
// numbers used against local fixtures; they carry no funds and pass Luhn.
|
|
8
|
+
export const OFFICIAL_TEST_PANS = {
|
|
9
|
+
visa: '4242424242424242',
|
|
10
|
+
visaAlt: '4111111111111111',
|
|
11
|
+
// PAN whose last four are 0002 is treated as a forced decline by the
|
|
12
|
+
// fixture acquirer, for exercising the declined outcome path.
|
|
13
|
+
visaDecline: '4000000000000002',
|
|
14
|
+
// Ending 0069: the fixture acquirer shows a processing interstitial, then
|
|
15
|
+
// JS-redirects to a Shopify-style thank-you URL with no confirmation text —
|
|
16
|
+
// exercises the outcome observer's late, URL-signal confirmation path.
|
|
17
|
+
visaSlowConfirm: '4000000000000069',
|
|
18
|
+
// Ending 0044: the fixture acquirer returns a neutral page with neither a
|
|
19
|
+
// confirmation nor a decline signal — exercises the unknown-outcome deadline.
|
|
20
|
+
visaUnknownOutcome: '4000000000000044',
|
|
21
|
+
// Ending 0010: the fixture acquirer answers with a 3DS-style verification
|
|
22
|
+
// page embedding an ACS challenge iframe that never completes — exercises
|
|
23
|
+
// the observer's action-required (issuer challenge) path.
|
|
24
|
+
visaChallenge: '4000000000000010',
|
|
25
|
+
// Ending 0077: the fixture acquirer emails a one-time code to the agent
|
|
26
|
+
// inbox and shows a 'check your email for a code' page with a one-time-code
|
|
27
|
+
// field — exercises the executor's agent-resolvable email-OTP subroutine.
|
|
28
|
+
visaEmailOtp: '4000000000000077',
|
|
29
|
+
};
|
|
30
|
+
function futureExpiry() {
|
|
31
|
+
const now = new Date();
|
|
32
|
+
return { expMonth: 12, expYear: now.getFullYear() + 3 };
|
|
33
|
+
}
|
|
34
|
+
export class TestCardInstrument {
|
|
35
|
+
kind = 'test-card';
|
|
36
|
+
credential;
|
|
37
|
+
constructor(opts = {}) {
|
|
38
|
+
const exp = futureExpiry();
|
|
39
|
+
this.credential = {
|
|
40
|
+
pan: opts.pan ?? OFFICIAL_TEST_PANS.visa,
|
|
41
|
+
expMonth: opts.expMonth ?? exp.expMonth,
|
|
42
|
+
expYear: opts.expYear ?? exp.expYear,
|
|
43
|
+
cvc: opts.cvc ?? '123',
|
|
44
|
+
cardholderName: opts.cardholderName ?? 'Test Agent',
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
async getCredential(_ctx) {
|
|
48
|
+
return this.credential;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const NOT_ENABLED = 'not enabled: pending VGS alias reveal support';
|
|
52
|
+
// Stub. Once VGS enablement lands, this resolves a network token / alias into a
|
|
53
|
+
// fillable credential (a virtual PAN plus its verification value).
|
|
54
|
+
export class VgsAliasInstrument {
|
|
55
|
+
_alias;
|
|
56
|
+
kind = 'vgs-alias';
|
|
57
|
+
constructor(_alias) {
|
|
58
|
+
this._alias = _alias;
|
|
59
|
+
}
|
|
60
|
+
async getCredential(_ctx) {
|
|
61
|
+
throw new Error(`${NOT_ENABLED}. VgsAliasInstrument cannot resolve alias "${this._alias}" ` +
|
|
62
|
+
'to a fillable PAN until VGS exposes the reveal seam for this spike.');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// A server-side provider mints the transaction-bound credential whose pan
|
|
66
|
+
// carries the DPAN and whose cvc carries the short DAVV. Omitting the provider
|
|
67
|
+
// preserves a clear fail-closed result for callers that have only a token ref.
|
|
68
|
+
export class AgenticTokenInstrument {
|
|
69
|
+
tokenRef;
|
|
70
|
+
mintCredential;
|
|
71
|
+
kind = 'agentic-token';
|
|
72
|
+
used = false;
|
|
73
|
+
constructor(tokenRef, mintCredential) {
|
|
74
|
+
this.tokenRef = tokenRef;
|
|
75
|
+
this.mintCredential = mintCredential;
|
|
76
|
+
}
|
|
77
|
+
async getCredential(ctx) {
|
|
78
|
+
if (!this.mintCredential) {
|
|
79
|
+
throw new Error('not enabled: no agentic credential provider configured. ' +
|
|
80
|
+
`Token ${this.tokenRef} needs a server-side VGS credential provider.`);
|
|
81
|
+
}
|
|
82
|
+
if (this.used)
|
|
83
|
+
throw new Error('agentic credential instrument is single-use');
|
|
84
|
+
this.used = true;
|
|
85
|
+
return this.mintCredential(ctx);
|
|
86
|
+
}
|
|
87
|
+
}
|