@visa/cli 4.1.0-rc.2 → 4.1.0-rc.200
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 +200 -226
- package/dist/checkout-engine/adapters/generic.d.ts +88 -0
- package/dist/checkout-engine/adapters/generic.js +526 -0
- package/dist/checkout-engine/adapters/index.d.ts +10 -0
- package/dist/checkout-engine/adapters/index.js +24 -0
- package/dist/checkout-engine/adapters/shopify.d.ts +55 -0
- package/dist/checkout-engine/adapters/shopify.js +514 -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/amount.d.ts +15 -0
- package/dist/checkout-engine/amount.js +72 -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 +315 -0
- package/dist/checkout-engine/cli-engine.js +996 -0
- 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 +61 -0
- package/dist/checkout-engine/detect.js +398 -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 +215 -0
- package/dist/checkout-engine/executor.js +1520 -0
- package/dist/checkout-engine/hosted-approval.d.ts +195 -0
- package/dist/checkout-engine/hosted-approval.js +498 -0
- package/dist/checkout-engine/index.d.ts +9 -0
- package/dist/checkout-engine/index.js +11 -0
- package/dist/checkout-engine/instrument.d.ts +61 -0
- package/dist/checkout-engine/instrument.js +87 -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 +37 -0
- package/dist/checkout-engine/live-fill-approval.js +76 -0
- package/dist/checkout-engine/mandate/card-mandate.d.ts +121 -0
- package/dist/checkout-engine/mandate/card-mandate.js +227 -0
- package/dist/checkout-engine/mandate/mandate-ledger.d.ts +178 -0
- package/dist/checkout-engine/mandate/mandate-ledger.js +395 -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/receipt-dir.d.ts +6 -0
- package/dist/checkout-engine/receipt-dir.js +8 -0
- package/dist/checkout-engine/receipt.d.ts +121 -0
- package/dist/checkout-engine/receipt.js +138 -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 +52 -0
- package/dist/checkout-engine/types.js +2 -0
- package/dist/checkout-engine/unresolved-charges.d.ts +34 -0
- package/dist/checkout-engine/unresolved-charges.js +125 -0
- package/dist/checkout-engine/vgs-gateway/server-mint-client.d.ts +101 -0
- package/dist/checkout-engine/vgs-gateway/server-mint-client.js +218 -0
- package/dist/checkout-engine/vgs-live-instrument.d.ts +144 -0
- package/dist/checkout-engine/vgs-live-instrument.js +229 -0
- package/dist/checkout-engine/vic-confirmation.d.ts +52 -0
- package/dist/checkout-engine/vic-confirmation.js +45 -0
- package/dist/checkout-engine/web-bot-auth.d.ts +92 -0
- package/dist/checkout-engine/web-bot-auth.js +159 -0
- package/dist/cli.js +721 -445
- package/dist/mcp-apps/ucp-checkout.html +280 -0
- package/dist/mcp-server/index.js +573 -175
- package/dist/skills/pair-visa-agent/RUNTIMES.md +93 -0
- package/dist/skills/pair-visa-agent/SKILL.md +557 -0
- package/dist/skills/pair-visa-agent/scripts/setup.mjs +48 -0
- package/dist/subway-direct.mjs +1 -0
- package/install.ps1 +5 -43
- package/install.sh +5 -37
- package/native/bin/win32-x64/visa-keychain-win.exe +0 -0
- package/package.json +33 -25
- package/server.json +4 -4
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/** Definitive merchant answers map to a status; everything else maps to none. */
|
|
2
|
+
export function outcomeToTransactionStatus(outcome) {
|
|
3
|
+
if (outcome === 'confirmed')
|
|
4
|
+
return 'APPROVED';
|
|
5
|
+
if (outcome === 'declined')
|
|
6
|
+
return 'DECLINED';
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
export async function reportVicOutcome(input) {
|
|
10
|
+
const transactionStatus = outcomeToTransactionStatus(input.outcome);
|
|
11
|
+
if (!transactionStatus) {
|
|
12
|
+
return {
|
|
13
|
+
posted: false,
|
|
14
|
+
code: 'outcome_not_definitive',
|
|
15
|
+
reason: `outcome '${input.outcome}' is not a definitive merchant answer — ` +
|
|
16
|
+
'resolve it with the merchant, then post the confirmation manually',
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
if (!input.target) {
|
|
20
|
+
return {
|
|
21
|
+
posted: false,
|
|
22
|
+
code: 'no_credential_minted',
|
|
23
|
+
reason: 'no VIC credential was minted in this run',
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
await input.post({
|
|
28
|
+
tokenId: input.target.tokenId,
|
|
29
|
+
intentId: input.target.intentId,
|
|
30
|
+
transactionStatus,
|
|
31
|
+
transactionType: 'PURCHASE',
|
|
32
|
+
transactionTimestamp: (input.timestamp ?? new Date()).toISOString(),
|
|
33
|
+
transaction: input.transaction,
|
|
34
|
+
});
|
|
35
|
+
return { posted: true, transactionStatus };
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
return {
|
|
39
|
+
posted: false,
|
|
40
|
+
code: 'post_failed',
|
|
41
|
+
reason: `confirmation POST failed: ${err.message} — the merchant-reported outcome ` +
|
|
42
|
+
'remains unverified; retry the confirmation for this intent out-of-band',
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/** Signature validity ceiling. A signature is a bearer-ish artifact for as long
|
|
2
|
+
* as it is valid, so the window stays short even if a caller asks for more. */
|
|
3
|
+
export declare const WEB_BOT_AUTH_MAX_TTL_SECONDS = 300;
|
|
4
|
+
/** Default validity. Long enough to survive a redirect chain and a slow TLS
|
|
5
|
+
* handshake, short enough that a captured signature is near-useless. */
|
|
6
|
+
export declare const WEB_BOT_AUTH_DEFAULT_TTL_SECONDS = 60;
|
|
7
|
+
/** Label for the single signature we emit. RFC 9421 allows several per request. */
|
|
8
|
+
export declare const WEB_BOT_AUTH_SIGNATURE_LABEL = "sig1";
|
|
9
|
+
/** Tag fixed by the Web Bot Auth draft; verifiers select on it. */
|
|
10
|
+
export declare const WEB_BOT_AUTH_TAG = "web-bot-auth";
|
|
11
|
+
/** Components covered by the signature, in the order they appear in the base. */
|
|
12
|
+
export declare const WEB_BOT_AUTH_COVERED_COMPONENTS: readonly ["@authority", "signature-agent"];
|
|
13
|
+
/** Ed25519 private key in JWK form, as stored in the agent's runtime key file. */
|
|
14
|
+
export interface WebBotAuthPrivateJwk {
|
|
15
|
+
kty: 'OKP';
|
|
16
|
+
crv: 'Ed25519';
|
|
17
|
+
x: string;
|
|
18
|
+
d: string;
|
|
19
|
+
}
|
|
20
|
+
export interface WebBotAuthSigningKey {
|
|
21
|
+
/** RFC 7638 thumbprint. Must match a `kid` published in the directory. */
|
|
22
|
+
keyId: string;
|
|
23
|
+
privateJwk: WebBotAuthPrivateJwk;
|
|
24
|
+
}
|
|
25
|
+
export interface WebBotAuthConfig {
|
|
26
|
+
/** Absolute https URL of the operator-hosted signature directory. */
|
|
27
|
+
directoryUrl: string;
|
|
28
|
+
key: WebBotAuthSigningKey;
|
|
29
|
+
ttlSeconds?: number;
|
|
30
|
+
}
|
|
31
|
+
export interface WebBotAuthHeaders {
|
|
32
|
+
'Signature-Input': string;
|
|
33
|
+
Signature: string;
|
|
34
|
+
'Signature-Agent': string;
|
|
35
|
+
[header: string]: string;
|
|
36
|
+
}
|
|
37
|
+
export interface SignatureBaseParams {
|
|
38
|
+
authority: string;
|
|
39
|
+
directoryUrl: string;
|
|
40
|
+
keyId: string;
|
|
41
|
+
created: number;
|
|
42
|
+
expires: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Build the RFC 9421 signature base.
|
|
46
|
+
*
|
|
47
|
+
* The base is what actually gets signed, so its exact bytes are the contract
|
|
48
|
+
* with every verifier — one wrong space or a reordered parameter and the
|
|
49
|
+
* signature fails against a correct key. It is exported and pinned by a
|
|
50
|
+
* deterministic test vector for that reason.
|
|
51
|
+
*/
|
|
52
|
+
export declare function buildSignatureBase(params: SignatureBaseParams): string;
|
|
53
|
+
/**
|
|
54
|
+
* The `@signature-params` value, which appears twice: as the final line of the
|
|
55
|
+
* signature base, and verbatim as the `Signature-Input` header value. Building
|
|
56
|
+
* it once is what keeps those two identical — a verifier rederives the base
|
|
57
|
+
* from the header it received, so any divergence fails every signature.
|
|
58
|
+
*/
|
|
59
|
+
export declare function buildSignatureParams(params: SignatureBaseParams): string;
|
|
60
|
+
export interface BuildHeadersParams {
|
|
61
|
+
/** Host (and port, if non-default) of the request being signed. */
|
|
62
|
+
authority: string;
|
|
63
|
+
config: WebBotAuthConfig;
|
|
64
|
+
/** Unix seconds. Injected so tests are deterministic and never wall-clock. */
|
|
65
|
+
nowSeconds: number;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Produce the three Web Bot Auth headers for one request authority.
|
|
69
|
+
*
|
|
70
|
+
* Throws on unusable key material rather than emitting an unverifiable
|
|
71
|
+
* signature. Callers on the checkout path must treat a throw as "proceed
|
|
72
|
+
* unsigned" — see `webBotAuthHeadersOrNone`.
|
|
73
|
+
*/
|
|
74
|
+
export declare function buildWebBotAuthHeaders(params: BuildHeadersParams): WebBotAuthHeaders;
|
|
75
|
+
/**
|
|
76
|
+
* Header-or-nothing wrapper for the checkout path.
|
|
77
|
+
*
|
|
78
|
+
* Signing is an optional trust upgrade, never a precondition for buying
|
|
79
|
+
* something. Unusable key material, a malformed URL, or any crypto failure
|
|
80
|
+
* degrades to an unsigned request — which is exactly what we sent before this
|
|
81
|
+
* module existed — rather than throwing into a live checkout.
|
|
82
|
+
*/
|
|
83
|
+
export declare function webBotAuthHeadersOrNone(config: WebBotAuthConfig | null, targetUrl: string, nowSeconds: number): WebBotAuthHeaders | null;
|
|
84
|
+
/**
|
|
85
|
+
* Resolve signing config from the environment. Returns `null` — meaning "send
|
|
86
|
+
* unsigned" — unless a directory URL and a usable key are BOTH present.
|
|
87
|
+
*
|
|
88
|
+
* Default-off is deliberate. Until the operator directory is live and serving
|
|
89
|
+
* this key, a signature resolves to nothing and fails verification, which is
|
|
90
|
+
* worse than the honest unsigned request we sent before.
|
|
91
|
+
*/
|
|
92
|
+
export declare function resolveWebBotAuthConfig(env: NodeJS.ProcessEnv, loadKey: () => WebBotAuthSigningKey | null): WebBotAuthConfig | null;
|
|
@@ -0,0 +1,159 @@
|
|
|
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
|
+
const privateKey = createPrivateKey({
|
|
92
|
+
key: config.key.privateJwk,
|
|
93
|
+
format: 'jwk',
|
|
94
|
+
});
|
|
95
|
+
// Ed25519 takes no separate digest algorithm; null is the required argument.
|
|
96
|
+
const signature = cryptoSign(null, Buffer.from(base, 'utf8'), privateKey);
|
|
97
|
+
return {
|
|
98
|
+
'Signature-Input': `${WEB_BOT_AUTH_SIGNATURE_LABEL}=${signatureParams}`,
|
|
99
|
+
Signature: `${WEB_BOT_AUTH_SIGNATURE_LABEL}=:${signature.toString('base64')}:`,
|
|
100
|
+
'Signature-Agent': sfString(config.directoryUrl),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Header-or-nothing wrapper for the checkout path.
|
|
105
|
+
*
|
|
106
|
+
* Signing is an optional trust upgrade, never a precondition for buying
|
|
107
|
+
* something. Unusable key material, a malformed URL, or any crypto failure
|
|
108
|
+
* degrades to an unsigned request — which is exactly what we sent before this
|
|
109
|
+
* module existed — rather than throwing into a live checkout.
|
|
110
|
+
*/
|
|
111
|
+
export function webBotAuthHeadersOrNone(config, targetUrl, nowSeconds) {
|
|
112
|
+
if (!config)
|
|
113
|
+
return null;
|
|
114
|
+
try {
|
|
115
|
+
const authority = new URL(targetUrl).host;
|
|
116
|
+
if (!authority)
|
|
117
|
+
return null;
|
|
118
|
+
return buildWebBotAuthHeaders({ authority, config, nowSeconds });
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Resolve signing config from the environment. Returns `null` — meaning "send
|
|
126
|
+
* unsigned" — unless a directory URL and a usable key are BOTH present.
|
|
127
|
+
*
|
|
128
|
+
* Default-off is deliberate. Until the operator directory is live and serving
|
|
129
|
+
* this key, a signature resolves to nothing and fails verification, which is
|
|
130
|
+
* worse than the honest unsigned request we sent before.
|
|
131
|
+
*/
|
|
132
|
+
export function resolveWebBotAuthConfig(env, loadKey) {
|
|
133
|
+
const directoryUrl = env.VISA_WEB_BOT_AUTH_DIRECTORY_URL?.trim();
|
|
134
|
+
if (!directoryUrl)
|
|
135
|
+
return null;
|
|
136
|
+
let parsed;
|
|
137
|
+
try {
|
|
138
|
+
parsed = new URL(directoryUrl);
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
// A directory fetched over plain http could be swapped in flight, which would
|
|
144
|
+
// let an observer substitute the key set our identity is judged against.
|
|
145
|
+
if (parsed.protocol !== 'https:')
|
|
146
|
+
return null;
|
|
147
|
+
let key = null;
|
|
148
|
+
try {
|
|
149
|
+
key = loadKey();
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
if (!key?.keyId || key.privateJwk?.crv !== 'Ed25519' || !key.privateJwk.d)
|
|
155
|
+
return null;
|
|
156
|
+
const rawTtl = Number(env.VISA_WEB_BOT_AUTH_TTL_SECONDS);
|
|
157
|
+
const ttlSeconds = Number.isFinite(rawTtl) && rawTtl > 0 ? rawTtl : undefined;
|
|
158
|
+
return { directoryUrl: parsed.toString(), key, ttlSeconds };
|
|
159
|
+
}
|