@visa/cli 4.1.0-rc.25 → 4.1.0-rc.250
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 +273 -227
- package/dist/checkout-engine/adapters/generic.d.ts +69 -0
- package/dist/checkout-engine/adapters/generic.js +383 -58
- package/dist/checkout-engine/adapters/index.d.ts +4 -1
- package/dist/checkout-engine/adapters/index.js +10 -3
- package/dist/checkout-engine/adapters/shopify.d.ts +80 -0
- package/dist/checkout-engine/adapters/shopify.js +688 -0
- package/dist/checkout-engine/amount.d.ts +15 -0
- package/dist/checkout-engine/amount.js +72 -0
- package/dist/checkout-engine/browser-launch.d.ts +9 -4
- package/dist/checkout-engine/browser-launch.js +19 -4
- package/dist/checkout-engine/browserbase-browser.d.ts +24 -0
- package/dist/checkout-engine/browserbase-browser.js +186 -0
- package/dist/checkout-engine/cli-engine.d.ts +297 -4
- package/dist/checkout-engine/cli-engine.js +942 -48
- package/dist/checkout-engine/confirmed-merchants.d.ts +31 -0
- package/dist/checkout-engine/confirmed-merchants.js +165 -0
- package/dist/checkout-engine/detect.d.ts +1 -1
- package/dist/checkout-engine/detect.js +26 -0
- package/dist/checkout-engine/evidence.d.ts +4 -1
- package/dist/checkout-engine/evidence.js +51 -6
- package/dist/checkout-engine/executor.d.ts +64 -4
- package/dist/checkout-engine/executor.js +625 -146
- package/dist/checkout-engine/hosted-approval.d.ts +124 -7
- package/dist/checkout-engine/hosted-approval.js +384 -54
- package/dist/checkout-engine/index.d.ts +9 -2
- package/dist/checkout-engine/index.js +8 -1
- package/dist/checkout-engine/instrument.d.ts +7 -0
- package/dist/checkout-engine/instrument.js +4 -0
- package/dist/checkout-engine/known-merchants.d.ts +10 -0
- package/dist/checkout-engine/known-merchants.js +38 -0
- package/dist/checkout-engine/live-fill-approval.d.ts +5 -20
- package/dist/checkout-engine/live-fill-approval.js +20 -51
- package/dist/checkout-engine/mandate/card-mandate.d.ts +121 -0
- package/dist/checkout-engine/mandate/card-mandate.js +226 -0
- package/dist/checkout-engine/mandate/mandate-ledger.d.ts +174 -0
- package/dist/checkout-engine/mandate/mandate-ledger.js +410 -0
- package/dist/checkout-engine/outcome.d.ts +2 -2
- package/dist/checkout-engine/outcome.js +36 -1
- package/dist/checkout-engine/owner-only-file.d.ts +9 -0
- package/dist/checkout-engine/owner-only-file.js +20 -1
- package/dist/checkout-engine/receipt-dir.d.ts +6 -0
- package/dist/checkout-engine/receipt-dir.js +8 -0
- package/dist/checkout-engine/receipt.d.ts +56 -2
- package/dist/checkout-engine/receipt.js +55 -16
- package/dist/checkout-engine/shopify-primary-domain.d.ts +25 -0
- package/dist/checkout-engine/shopify-primary-domain.js +96 -0
- package/dist/checkout-engine/trace-handles.d.ts +8 -0
- package/dist/checkout-engine/trace-handles.js +12 -0
- package/dist/checkout-engine/types.d.ts +28 -2
- package/dist/checkout-engine/unresolved-charges.d.ts +34 -0
- package/dist/checkout-engine/unresolved-charges.js +134 -0
- package/dist/checkout-engine/vgs-gateway/server-mint-client.d.ts +53 -1
- package/dist/checkout-engine/vgs-gateway/server-mint-client.js +78 -10
- package/dist/checkout-engine/vgs-live-instrument.d.ts +38 -35
- package/dist/checkout-engine/vgs-live-instrument.js +51 -74
- package/dist/checkout-engine/vic-confirmation.d.ts +18 -0
- package/dist/checkout-engine/vic-confirmation.js +9 -3
- package/dist/checkout-engine/web-bot-auth.d.ts +98 -0
- package/dist/checkout-engine/web-bot-auth.js +218 -0
- package/dist/cli.js +905 -505
- package/dist/mcp-apps/ucp-checkout.html +280 -0
- package/dist/mcp-server/index.js +744 -175
- package/dist/merchant-ucp-mcp/index.js +6 -0
- package/dist/skills/pair-visa-agent/RUNTIMES.md +122 -79
- package/dist/skills/pair-visa-agent/SKILL.md +436 -279
- package/dist/skills/pair-visa-agent/scripts/__tests__/setup.test.mjs +407 -0
- package/dist/skills/pair-visa-agent/scripts/setup.mjs +310 -30
- package/dist/skills/visa-shopify-checkout/SKILL.md +122 -0
- package/dist/skills/visa-shopify-checkout/references/evidence-and-states.md +37 -0
- package/dist/skills/visa-ucp-shopping/SKILL.md +86 -0
- package/dist/subway-direct.mjs +1 -0
- package/install.ps1 +9 -46
- package/install.sh +5 -37
- package/native/bin/win32-x64/visa-keychain-win.exe +0 -0
- package/package.json +32 -28
- package/server.json +4 -4
- package/dist/checkout-engine/inline-target.d.ts +0 -13
- package/dist/checkout-engine/inline-target.js +0 -37
- package/dist/checkout-engine/pay-args.d.ts +0 -14
- package/dist/checkout-engine/pay-args.js +0 -44
- package/dist/checkout-engine/pay.d.ts +0 -1
- package/dist/checkout-engine/pay.js +0 -13
- package/dist/checkout-engine/repo-env.d.ts +0 -11
- package/dist/checkout-engine/repo-env.js +0 -23
- package/dist/checkout-engine/run-live-fill.d.ts +0 -1
- package/dist/checkout-engine/run-live-fill.js +0 -443
- package/dist/checkout-engine/vgs-gateway/fetch-credential.d.mts +0 -74
- package/dist/checkout-engine/vgs-gateway/fetch-credential.mjs +0 -248
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @purpose Web Bot Auth (RFC 9421) request signing for checkout navigations —
|
|
3
|
+
* the client half of Trusted Agent Protocol verification.
|
|
4
|
+
*
|
|
5
|
+
* Cloudflare's TAP verifies an agent by checking an RFC 9421 HTTP message
|
|
6
|
+
* signature on the request. Three headers carry it: `Signature-Input` names the
|
|
7
|
+
* covered components and parameters, `Signature` carries the Ed25519 signature
|
|
8
|
+
* over the derived base, and `Signature-Agent` gives the URL of the directory
|
|
9
|
+
* that resolves `keyid` to a public key. The checkout browser previously sent
|
|
10
|
+
* none of them, so a TAP-aware edge had nothing to verify and fell through to
|
|
11
|
+
* ordinary bot management.
|
|
12
|
+
*
|
|
13
|
+
* TWO HALVES, BOTH REQUIRED. This module presents a `keyid`; the auth server
|
|
14
|
+
* must publish that key at the `Signature-Agent` URL for anything to resolve.
|
|
15
|
+
* Signing while the directory is absent is strictly worse than not signing,
|
|
16
|
+
* because it advertises intent and then fails verification — which is why
|
|
17
|
+
* signing stays OFF unless explicitly configured with a directory URL.
|
|
18
|
+
*
|
|
19
|
+
* KEY MATERIAL NEVER LEAVES THIS MODULE. The signing key is accepted as a
|
|
20
|
+
* value, used once per request, and never logged, serialized, returned, or
|
|
21
|
+
* attached to evidence. Callers get headers, never the key. This module takes
|
|
22
|
+
* no logger for exactly that reason.
|
|
23
|
+
*/
|
|
24
|
+
import { createPrivateKey, sign as cryptoSign } from 'node:crypto';
|
|
25
|
+
/** Signature validity ceiling. A signature is a bearer-ish artifact for as long
|
|
26
|
+
* as it is valid, so the window stays short even if a caller asks for more. */
|
|
27
|
+
export const WEB_BOT_AUTH_MAX_TTL_SECONDS = 300;
|
|
28
|
+
/** Default validity. Long enough to survive a redirect chain and a slow TLS
|
|
29
|
+
* handshake, short enough that a captured signature is near-useless. */
|
|
30
|
+
export const WEB_BOT_AUTH_DEFAULT_TTL_SECONDS = 60;
|
|
31
|
+
/** Label for the single signature we emit. RFC 9421 allows several per request. */
|
|
32
|
+
export const WEB_BOT_AUTH_SIGNATURE_LABEL = 'sig1';
|
|
33
|
+
/** Tag fixed by the Web Bot Auth draft; verifiers select on it. */
|
|
34
|
+
export const WEB_BOT_AUTH_TAG = 'web-bot-auth';
|
|
35
|
+
/** Components covered by the signature, in the order they appear in the base. */
|
|
36
|
+
export const WEB_BOT_AUTH_COVERED_COMPONENTS = ['@authority', 'signature-agent'];
|
|
37
|
+
/** Serialize an RFC 8941 structured-field string (always double-quoted). */
|
|
38
|
+
function sfString(value) {
|
|
39
|
+
return `"${value.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Build the RFC 9421 signature base.
|
|
43
|
+
*
|
|
44
|
+
* The base is what actually gets signed, so its exact bytes are the contract
|
|
45
|
+
* with every verifier — one wrong space or a reordered parameter and the
|
|
46
|
+
* signature fails against a correct key. It is exported and pinned by a
|
|
47
|
+
* deterministic test vector for that reason.
|
|
48
|
+
*/
|
|
49
|
+
export function buildSignatureBase(params) {
|
|
50
|
+
return [
|
|
51
|
+
`"@authority": ${params.authority}`,
|
|
52
|
+
`"signature-agent": ${sfString(params.directoryUrl)}`,
|
|
53
|
+
`"@signature-params": ${buildSignatureParams(params)}`,
|
|
54
|
+
].join('\n');
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The `@signature-params` value, which appears twice: as the final line of the
|
|
58
|
+
* signature base, and verbatim as the `Signature-Input` header value. Building
|
|
59
|
+
* it once is what keeps those two identical — a verifier rederives the base
|
|
60
|
+
* from the header it received, so any divergence fails every signature.
|
|
61
|
+
*/
|
|
62
|
+
export function buildSignatureParams(params) {
|
|
63
|
+
return (`(${WEB_BOT_AUTH_COVERED_COMPONENTS.map(sfString).join(' ')})` +
|
|
64
|
+
`;created=${params.created}` +
|
|
65
|
+
`;expires=${params.expires}` +
|
|
66
|
+
`;keyid=${sfString(params.keyId)}` +
|
|
67
|
+
`;alg="ed25519"` +
|
|
68
|
+
`;tag=${sfString(WEB_BOT_AUTH_TAG)}`);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Produce the three Web Bot Auth headers for one request authority.
|
|
72
|
+
*
|
|
73
|
+
* Throws on unusable key material rather than emitting an unverifiable
|
|
74
|
+
* signature. Callers on the checkout path must treat a throw as "proceed
|
|
75
|
+
* unsigned" — see `webBotAuthHeadersOrNone`.
|
|
76
|
+
*/
|
|
77
|
+
export function buildWebBotAuthHeaders(params) {
|
|
78
|
+
const { authority, config, nowSeconds } = params;
|
|
79
|
+
const ttl = Math.min(Math.max(1, Math.floor(config.ttlSeconds ?? WEB_BOT_AUTH_DEFAULT_TTL_SECONDS)), WEB_BOT_AUTH_MAX_TTL_SECONDS);
|
|
80
|
+
const created = Math.floor(nowSeconds);
|
|
81
|
+
const expires = created + ttl;
|
|
82
|
+
const baseParams = {
|
|
83
|
+
authority,
|
|
84
|
+
directoryUrl: config.directoryUrl,
|
|
85
|
+
keyId: config.key.keyId,
|
|
86
|
+
created,
|
|
87
|
+
expires,
|
|
88
|
+
};
|
|
89
|
+
const base = buildSignatureBase(baseParams);
|
|
90
|
+
const signatureParams = buildSignatureParams(baseParams);
|
|
91
|
+
// privateJwk is optional on the key so a vault-held signer can supply signFn
|
|
92
|
+
// instead. Only the async builder can await such a signer, so refuse here with
|
|
93
|
+
// the same explicit message rather than handing undefined to createPrivateKey
|
|
94
|
+
// and surfacing an opaque node:crypto error.
|
|
95
|
+
if (!config.key.privateJwk) {
|
|
96
|
+
throw new Error(config.key.signFn
|
|
97
|
+
? 'WebBotAuthSigningKey with signFn requires buildWebBotAuthHeadersAsync'
|
|
98
|
+
: 'WebBotAuthSigningKey requires either privateJwk or signFn');
|
|
99
|
+
}
|
|
100
|
+
const privateKey = createPrivateKey({
|
|
101
|
+
key: config.key.privateJwk,
|
|
102
|
+
format: 'jwk',
|
|
103
|
+
});
|
|
104
|
+
// Ed25519 takes no separate digest algorithm; null is the required argument.
|
|
105
|
+
const signature = cryptoSign(null, Buffer.from(base, 'utf8'), privateKey);
|
|
106
|
+
return {
|
|
107
|
+
'Signature-Input': `${WEB_BOT_AUTH_SIGNATURE_LABEL}=${signatureParams}`,
|
|
108
|
+
Signature: `${WEB_BOT_AUTH_SIGNATURE_LABEL}=:${signature.toString('base64')}:`,
|
|
109
|
+
'Signature-Agent': sfString(config.directoryUrl),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Header-or-nothing wrapper for the checkout path.
|
|
114
|
+
*
|
|
115
|
+
* Signing is an optional trust upgrade, never a precondition for buying
|
|
116
|
+
* something. Unusable key material, a malformed URL, or any crypto failure
|
|
117
|
+
* degrades to an unsigned request — which is exactly what we sent before this
|
|
118
|
+
* module existed — rather than throwing into a live checkout.
|
|
119
|
+
*/
|
|
120
|
+
export function webBotAuthHeadersOrNone(config, targetUrl, nowSeconds) {
|
|
121
|
+
if (!config)
|
|
122
|
+
return null;
|
|
123
|
+
try {
|
|
124
|
+
const authority = new URL(targetUrl).host;
|
|
125
|
+
if (!authority)
|
|
126
|
+
return null;
|
|
127
|
+
return buildWebBotAuthHeaders({ authority, config, nowSeconds });
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Async version of buildWebBotAuthHeaders, supporting Turnkey or vault signFn signers.
|
|
135
|
+
*/
|
|
136
|
+
export async function buildWebBotAuthHeadersAsync(params) {
|
|
137
|
+
const { authority, config, nowSeconds } = params;
|
|
138
|
+
const ttl = Math.min(Math.max(1, Math.floor(config.ttlSeconds ?? WEB_BOT_AUTH_DEFAULT_TTL_SECONDS)), WEB_BOT_AUTH_MAX_TTL_SECONDS);
|
|
139
|
+
const created = Math.floor(nowSeconds);
|
|
140
|
+
const expires = created + ttl;
|
|
141
|
+
const baseParams = {
|
|
142
|
+
authority,
|
|
143
|
+
directoryUrl: config.directoryUrl,
|
|
144
|
+
keyId: config.key.keyId,
|
|
145
|
+
created,
|
|
146
|
+
expires,
|
|
147
|
+
};
|
|
148
|
+
const base = buildSignatureBase(baseParams);
|
|
149
|
+
const signatureParams = buildSignatureParams(baseParams);
|
|
150
|
+
let signature;
|
|
151
|
+
if (config.key.signFn) {
|
|
152
|
+
signature = await config.key.signFn(Buffer.from(base, 'utf8'));
|
|
153
|
+
}
|
|
154
|
+
else if (config.key.privateJwk) {
|
|
155
|
+
const privateKey = createPrivateKey({
|
|
156
|
+
key: config.key.privateJwk,
|
|
157
|
+
format: 'jwk',
|
|
158
|
+
});
|
|
159
|
+
signature = cryptoSign(null, Buffer.from(base, 'utf8'), privateKey);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
throw new Error('WebBotAuthSigningKey requires either privateJwk or signFn');
|
|
163
|
+
}
|
|
164
|
+
return {
|
|
165
|
+
'Signature-Input': `${WEB_BOT_AUTH_SIGNATURE_LABEL}=${signatureParams}`,
|
|
166
|
+
Signature: `${WEB_BOT_AUTH_SIGNATURE_LABEL}=:${Buffer.from(signature).toString('base64')}:`,
|
|
167
|
+
'Signature-Agent': sfString(config.directoryUrl),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
export async function webBotAuthHeadersOrNoneAsync(config, targetUrl, nowSeconds) {
|
|
171
|
+
if (!config)
|
|
172
|
+
return null;
|
|
173
|
+
try {
|
|
174
|
+
const authority = new URL(targetUrl).host;
|
|
175
|
+
if (!authority)
|
|
176
|
+
return null;
|
|
177
|
+
return await buildWebBotAuthHeadersAsync({ authority, config, nowSeconds });
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Resolve signing config from the environment. Returns `null` — meaning "send
|
|
185
|
+
* unsigned" — unless a directory URL and a usable key are BOTH present.
|
|
186
|
+
*
|
|
187
|
+
* Default-off is deliberate. Until the operator directory is live and serving
|
|
188
|
+
* this key, a signature resolves to nothing and fails verification, which is
|
|
189
|
+
* worse than the honest unsigned request we sent before.
|
|
190
|
+
*/
|
|
191
|
+
export function resolveWebBotAuthConfig(env, loadKey) {
|
|
192
|
+
const directoryUrl = env.VISA_WEB_BOT_AUTH_DIRECTORY_URL?.trim();
|
|
193
|
+
if (!directoryUrl)
|
|
194
|
+
return null;
|
|
195
|
+
let parsed;
|
|
196
|
+
try {
|
|
197
|
+
parsed = new URL(directoryUrl);
|
|
198
|
+
}
|
|
199
|
+
catch {
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
// A directory fetched over plain http could be swapped in flight, which would
|
|
203
|
+
// let an observer substitute the key set our identity is judged against.
|
|
204
|
+
if (parsed.protocol !== 'https:')
|
|
205
|
+
return null;
|
|
206
|
+
let key = null;
|
|
207
|
+
try {
|
|
208
|
+
key = loadKey();
|
|
209
|
+
}
|
|
210
|
+
catch {
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
if (!key?.keyId || (!key.signFn && (key.privateJwk?.crv !== 'Ed25519' || !key.privateJwk.d)))
|
|
214
|
+
return null;
|
|
215
|
+
const rawTtl = Number(env.VISA_WEB_BOT_AUTH_TTL_SECONDS);
|
|
216
|
+
const ttlSeconds = Number.isFinite(rawTtl) && rawTtl > 0 ? rawTtl : undefined;
|
|
217
|
+
return { directoryUrl: parsed.toString(), key, ttlSeconds };
|
|
218
|
+
}
|