@goodmeta/agent-verifier 0.2.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +67 -26
- package/dist/ap2/chain.d.ts +43 -0
- package/dist/ap2/chain.d.ts.map +1 -0
- package/dist/ap2/chain.js +100 -0
- package/dist/ap2/chain.js.map +1 -0
- package/dist/ap2/chains.d.ts +68 -0
- package/dist/ap2/chains.d.ts.map +1 -0
- package/dist/ap2/chains.js +119 -0
- package/dist/ap2/chains.js.map +1 -0
- package/dist/ap2/constraints.d.ts +47 -0
- package/dist/ap2/constraints.d.ts.map +1 -0
- package/dist/ap2/constraints.js +231 -0
- package/dist/ap2/constraints.js.map +1 -0
- package/dist/ap2/hash.d.ts +23 -0
- package/dist/ap2/hash.d.ts.map +1 -0
- package/dist/ap2/hash.js +54 -0
- package/dist/ap2/hash.js.map +1 -0
- package/dist/ap2/index.d.ts +28 -0
- package/dist/ap2/index.d.ts.map +1 -0
- package/dist/ap2/index.js +35 -0
- package/dist/ap2/index.js.map +1 -0
- package/dist/ap2/jwk.d.ts +24 -0
- package/dist/ap2/jwk.d.ts.map +1 -0
- package/dist/ap2/jwk.js +29 -0
- package/dist/ap2/jwk.js.map +1 -0
- package/dist/ap2/kb-sd-jwt.d.ts +44 -0
- package/dist/ap2/kb-sd-jwt.d.ts.map +1 -0
- package/dist/ap2/kb-sd-jwt.js +97 -0
- package/dist/ap2/kb-sd-jwt.js.map +1 -0
- package/dist/ap2/keys.d.ts +41 -0
- package/dist/ap2/keys.d.ts.map +1 -0
- package/dist/ap2/keys.js +114 -0
- package/dist/ap2/keys.js.map +1 -0
- package/dist/ap2/max-flow.d.ts +26 -0
- package/dist/ap2/max-flow.d.ts.map +1 -0
- package/dist/ap2/max-flow.js +173 -0
- package/dist/ap2/max-flow.js.map +1 -0
- package/dist/ap2/parse.d.ts +35 -0
- package/dist/ap2/parse.d.ts.map +1 -0
- package/dist/ap2/parse.js +78 -0
- package/dist/ap2/parse.js.map +1 -0
- package/dist/ap2/sd-jwt.d.ts +83 -0
- package/dist/ap2/sd-jwt.d.ts.map +1 -0
- package/dist/ap2/sd-jwt.js +306 -0
- package/dist/ap2/sd-jwt.js.map +1 -0
- package/dist/ap2/types.d.ts +270 -0
- package/dist/ap2/types.d.ts.map +1 -0
- package/dist/ap2/types.js +141 -0
- package/dist/ap2/types.js.map +1 -0
- package/dist/client.d.ts +152 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +171 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/policy.d.ts +45 -0
- package/dist/policy.d.ts.map +1 -0
- package/dist/policy.js +88 -0
- package/dist/policy.js.map +1 -0
- package/dist/receipt-jwt.d.ts +30 -0
- package/dist/receipt-jwt.d.ts.map +1 -0
- package/dist/receipt-jwt.js +39 -0
- package/dist/receipt-jwt.js.map +1 -0
- package/dist/schema.d.ts +41 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +50 -0
- package/dist/schema.js.map +1 -0
- package/dist/types.d.ts +116 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/dist/verify.d.ts +24 -0
- package/dist/verify.d.ts.map +1 -0
- package/dist/verify.js +69 -0
- package/dist/verify.js.map +1 -0
- package/package.json +14 -7
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed AP2 payment-mandate schemas (zod), mirroring AP2's generated models at
|
|
3
|
+
* commit e1ea56d (`generated/open_payment_mandate.py`, `payment_mandate.py`,
|
|
4
|
+
* `types/{amount,merchant,payment_instrument,pisp}.py`).
|
|
5
|
+
*
|
|
6
|
+
* `vct` is pinned to the EXACT version-suffixed literal (AUTH-1 / SPEC-16: a
|
|
7
|
+
* verifier MUST match the full `vct` string), so a wrong/loose `vct` fails to
|
|
8
|
+
* parse. Objects are non-strict (unknown keys stripped) to match pydantic's
|
|
9
|
+
* default `extra='ignore'` and tolerate `iat`/`exp`/`risk_data`/future fields.
|
|
10
|
+
* Constraints are kept loosely typed at the mandate level so an UNKNOWN
|
|
11
|
+
* constraint type does not crash parsing — it is surfaced as a violation during
|
|
12
|
+
* evaluation (AUTH-15: unknown constraints MUST fail evaluation), not silently
|
|
13
|
+
* dropped.
|
|
14
|
+
*/
|
|
15
|
+
import { z } from "zod";
|
|
16
|
+
// ── Shared value types ───────────────────────────────────────────────────────
|
|
17
|
+
export const AmountSchema = z.object({ amount: z.number().int(), currency: z.string() });
|
|
18
|
+
export const MerchantSchema = z.object({
|
|
19
|
+
id: z.string(),
|
|
20
|
+
name: z.string(),
|
|
21
|
+
website: z.string().nullish(),
|
|
22
|
+
});
|
|
23
|
+
export const PaymentInstrumentSchema = z.object({
|
|
24
|
+
id: z.string(),
|
|
25
|
+
type: z.string(),
|
|
26
|
+
description: z.string().nullish(),
|
|
27
|
+
});
|
|
28
|
+
export const PispSchema = z.object({
|
|
29
|
+
legal_name: z.string(),
|
|
30
|
+
brand_name: z.string(),
|
|
31
|
+
domain_name: z.string(),
|
|
32
|
+
});
|
|
33
|
+
// ── Payment constraints (the `type` discriminators are AP2 wire literals) ─────
|
|
34
|
+
export const AmountRangeSchema = z.object({
|
|
35
|
+
type: z.literal("payment.amount_range"),
|
|
36
|
+
currency: z.string(),
|
|
37
|
+
max: z.number().int(),
|
|
38
|
+
min: z.number().int().nullish(),
|
|
39
|
+
});
|
|
40
|
+
export const BudgetSchema = z.object({
|
|
41
|
+
type: z.literal("payment.budget"),
|
|
42
|
+
max: z.number(), // MAJOR-unit float; evaluator converts to cents via trunc(max*100)
|
|
43
|
+
currency: z.string(),
|
|
44
|
+
});
|
|
45
|
+
export const AgentRecurrenceSchema = z.object({
|
|
46
|
+
type: z.literal("payment.agent_recurrence"),
|
|
47
|
+
frequency: z.string(),
|
|
48
|
+
max_occurrences: z.number().int().nullish(),
|
|
49
|
+
});
|
|
50
|
+
export const AllowedPayeesSchema = z.object({
|
|
51
|
+
type: z.literal("payment.allowed_payees"),
|
|
52
|
+
allowed: z.array(MerchantSchema),
|
|
53
|
+
});
|
|
54
|
+
export const AllowedPaymentInstrumentsSchema = z.object({
|
|
55
|
+
type: z.literal("payment.allowed_payment_instruments"),
|
|
56
|
+
allowed: z.array(PaymentInstrumentSchema),
|
|
57
|
+
});
|
|
58
|
+
export const AllowedPispsSchema = z.object({
|
|
59
|
+
type: z.literal("payment.allowed_pisps"),
|
|
60
|
+
allowed: z.array(PispSchema),
|
|
61
|
+
});
|
|
62
|
+
export const ExecutionDateSchema = z.object({
|
|
63
|
+
type: z.literal("payment.execution_date"),
|
|
64
|
+
not_before: z.string().nullish(),
|
|
65
|
+
not_after: z.string().nullish(),
|
|
66
|
+
});
|
|
67
|
+
export const PaymentReferenceSchema = z.object({
|
|
68
|
+
type: z.literal("payment.reference"),
|
|
69
|
+
conditional_transaction_id: z.string(),
|
|
70
|
+
});
|
|
71
|
+
/** Strongly-typed union of the known payment constraints (for the evaluator). */
|
|
72
|
+
export const KnownPaymentConstraintSchema = z.discriminatedUnion("type", [
|
|
73
|
+
AmountRangeSchema,
|
|
74
|
+
BudgetSchema,
|
|
75
|
+
AgentRecurrenceSchema,
|
|
76
|
+
AllowedPayeesSchema,
|
|
77
|
+
AllowedPaymentInstrumentsSchema,
|
|
78
|
+
AllowedPispsSchema,
|
|
79
|
+
ExecutionDateSchema,
|
|
80
|
+
PaymentReferenceSchema,
|
|
81
|
+
]);
|
|
82
|
+
/** A constraint as it appears in a mandate: at least a `type`, possibly unknown. */
|
|
83
|
+
const LooseConstraintSchema = z.object({ type: z.string() }).passthrough();
|
|
84
|
+
// ── Mandates ─────────────────────────────────────────────────────────────────
|
|
85
|
+
export const OpenPaymentMandateSchema = z.object({
|
|
86
|
+
vct: z.literal("mandate.payment.open.1"),
|
|
87
|
+
constraints: z.array(LooseConstraintSchema),
|
|
88
|
+
cnf: z.unknown().optional(), // already validated during chain walk (jwk.ts/cnfJwk)
|
|
89
|
+
payee: MerchantSchema.nullish(),
|
|
90
|
+
payment_amount: AmountSchema.nullish(),
|
|
91
|
+
payment_instrument: PaymentInstrumentSchema.nullish(),
|
|
92
|
+
pisp: PispSchema.nullish(),
|
|
93
|
+
execution_date: z.string().nullish(),
|
|
94
|
+
});
|
|
95
|
+
export const PaymentMandateSchema = z.object({
|
|
96
|
+
vct: z.literal("mandate.payment.1"),
|
|
97
|
+
transaction_id: z.string(),
|
|
98
|
+
payee: MerchantSchema,
|
|
99
|
+
pisp: PispSchema.nullish(),
|
|
100
|
+
payment_amount: AmountSchema,
|
|
101
|
+
payment_instrument: PaymentInstrumentSchema,
|
|
102
|
+
execution_date: z.string().nullish(),
|
|
103
|
+
});
|
|
104
|
+
// ── Checkout mandate + constraints (mirror `generated/open_checkout_mandate.py`) ─
|
|
105
|
+
export const AllowedMerchantsSchema = z.object({
|
|
106
|
+
type: z.literal("checkout.allowed_merchants"),
|
|
107
|
+
allowed: z.array(MerchantSchema),
|
|
108
|
+
});
|
|
109
|
+
const LineItemRequirementsSchema = z.object({
|
|
110
|
+
id: z.string(),
|
|
111
|
+
acceptable_items: z.array(z.object({ id: z.string(), title: z.string() })),
|
|
112
|
+
quantity: z.number().int().positive(),
|
|
113
|
+
});
|
|
114
|
+
export const LineItemsSchema = z.object({
|
|
115
|
+
type: z.literal("checkout.line_items"),
|
|
116
|
+
items: z.array(LineItemRequirementsSchema).min(1),
|
|
117
|
+
});
|
|
118
|
+
export const KnownCheckoutConstraintSchema = z.discriminatedUnion("type", [AllowedMerchantsSchema, LineItemsSchema]);
|
|
119
|
+
export const OpenCheckoutMandateSchema = z.object({
|
|
120
|
+
vct: z.literal("mandate.checkout.open.1"),
|
|
121
|
+
constraints: z.array(LooseConstraintSchema),
|
|
122
|
+
cnf: z.unknown().optional(),
|
|
123
|
+
});
|
|
124
|
+
/** Closed checkout mandate (mirror `generated/checkout_mandate.py`). */
|
|
125
|
+
export const CheckoutMandateSchema = z.object({
|
|
126
|
+
vct: z.literal("mandate.checkout.1"),
|
|
127
|
+
checkout_jwt: z.string(),
|
|
128
|
+
checkout_hash: z.string(),
|
|
129
|
+
});
|
|
130
|
+
/** Minimal UCP Checkout — only the fields the constraint evaluators read
|
|
131
|
+
* (`merchant`, `line_items[].item.id`, `line_items[].quantity`). `extra='allow'`
|
|
132
|
+
* in AP2, so unknown keys pass through. */
|
|
133
|
+
export const CheckoutSchema = z
|
|
134
|
+
.object({
|
|
135
|
+
merchant: MerchantSchema.nullish(),
|
|
136
|
+
line_items: z
|
|
137
|
+
.array(z.object({ item: z.object({ id: z.string() }).passthrough(), quantity: z.number().int() }).passthrough())
|
|
138
|
+
.nullish(),
|
|
139
|
+
})
|
|
140
|
+
.passthrough();
|
|
141
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/ap2/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,gFAAgF;AAChF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AACzF,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC;IACrC,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;IACd,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE;CAC9B,CAAC,CAAC;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC9C,EAAE,EAAE,CAAC,CAAC,MAAM,EA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Ac,CAAC,OAAO,EAAE;IAClC,UAAU,EAAE,CAAC;SACV,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;SAC/G,OAAO,EAAE;CACb,CAAC;KACD,WAAW,EAAE,CAAC"}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Verifier API Client
|
|
3
|
+
*
|
|
4
|
+
* For merchants integrating with the hosted Good Meta Verifier.
|
|
5
|
+
* Cross-merchant budget tracking, hold management, audit trail.
|
|
6
|
+
*
|
|
7
|
+
* Every call applies a timeout, surfaces transport/auth/server/non-JSON failures
|
|
8
|
+
* as a typed VerifierError, and never blind-parses an error body as a success
|
|
9
|
+
* response. A *denied* verification (HTTP 403 with { approved: false }) is a
|
|
10
|
+
* normal domain outcome and is returned, not thrown.
|
|
11
|
+
*
|
|
12
|
+
* import { VerifierClient, VerifierError } from "@goodmeta/agent-verifier";
|
|
13
|
+
*
|
|
14
|
+
* const verifier = new VerifierClient({ apiKey: "gm_test_..." });
|
|
15
|
+
* const result = await verifier.verify(mandate, { amount: "3000", currency: "USDC", idempotencyKey: "tx-1" });
|
|
16
|
+
* if (result.approved) await verifier.settle(result.verificationId!, { success: true });
|
|
17
|
+
*/
|
|
18
|
+
import type { IntentMandate, CartMandate, CartItem, VerifyResponse, SettleResponse, ReleaseResponse, RefundResponse } from "./types.js";
|
|
19
|
+
export interface VerifyByIdTransaction {
|
|
20
|
+
amount: string;
|
|
21
|
+
currency: string;
|
|
22
|
+
items?: CartItem[];
|
|
23
|
+
idempotencyKey: string;
|
|
24
|
+
}
|
|
25
|
+
export interface VerifierClientOptions {
|
|
26
|
+
apiKey: string;
|
|
27
|
+
baseUrl?: string;
|
|
28
|
+
/** Per-request timeout in milliseconds. Default 10_000. */
|
|
29
|
+
timeoutMs?: number;
|
|
30
|
+
/** Override the fetch implementation (testing / custom agents). Defaults to global fetch. */
|
|
31
|
+
fetch?: typeof fetch;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Thrown for transport, timeout, auth (401), client (4xx), server (5xx), or
|
|
35
|
+
* non-JSON failures. Business outcomes (e.g. a denied verification) are
|
|
36
|
+
* returned, not thrown. Carries the HTTP `status` and parsed `body` when available.
|
|
37
|
+
*/
|
|
38
|
+
export declare class VerifierError extends Error {
|
|
39
|
+
readonly status?: number;
|
|
40
|
+
readonly body?: unknown;
|
|
41
|
+
constructor(message: string, opts?: {
|
|
42
|
+
status?: number;
|
|
43
|
+
body?: unknown;
|
|
44
|
+
cause?: unknown;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
export declare class VerifierClient {
|
|
48
|
+
private apiKey;
|
|
49
|
+
private baseUrl;
|
|
50
|
+
private timeoutMs;
|
|
51
|
+
private fetchImpl;
|
|
52
|
+
constructor(options: VerifierClientOptions);
|
|
53
|
+
/**
|
|
54
|
+
* Low-level request: applies auth header + timeout, returns { status, body }.
|
|
55
|
+
* Throws VerifierError on network failure, timeout (AbortError), or a body
|
|
56
|
+
* that isn't valid JSON.
|
|
57
|
+
*/
|
|
58
|
+
private raw;
|
|
59
|
+
/** POST that throws VerifierError on any non-2xx. */
|
|
60
|
+
private post;
|
|
61
|
+
/** GET that throws VerifierError on any non-2xx. */
|
|
62
|
+
private get;
|
|
63
|
+
/**
|
|
64
|
+
* verify/verifyById share this: a denial (HTTP 403, { approved:false }) is a
|
|
65
|
+
* domain outcome and is returned. Auth/validation/server errors throw.
|
|
66
|
+
*/
|
|
67
|
+
private doVerify;
|
|
68
|
+
/**
|
|
69
|
+
* Verify a mandate and place a budget hold. Call this BEFORE processing payment.
|
|
70
|
+
* A denied result is returned with `approved: false`; transport/auth/server
|
|
71
|
+
* errors throw VerifierError.
|
|
72
|
+
*/
|
|
73
|
+
verify(mandate: IntentMandate | CartMandate, transaction: {
|
|
74
|
+
amount: string;
|
|
75
|
+
currency: string;
|
|
76
|
+
items?: CartItem[];
|
|
77
|
+
idempotencyKey: string;
|
|
78
|
+
}): Promise<VerifyResponse>;
|
|
79
|
+
/**
|
|
80
|
+
* Verify by mandate/policy ID — for integrations where the agent only passes
|
|
81
|
+
* an ID (e.g. cart metadata), not the full mandate object.
|
|
82
|
+
*/
|
|
83
|
+
verifyById(mandateId: string, transaction: VerifyByIdTransaction): Promise<VerifyResponse>;
|
|
84
|
+
/**
|
|
85
|
+
* Settle a verification after payment succeeds or fails.
|
|
86
|
+
* success=true → budget permanently debited; success=false → hold released.
|
|
87
|
+
*/
|
|
88
|
+
settle(verificationId: string, paymentResult: {
|
|
89
|
+
success: boolean;
|
|
90
|
+
transactionId?: string;
|
|
91
|
+
rail?: string;
|
|
92
|
+
}): Promise<SettleResponse>;
|
|
93
|
+
/**
|
|
94
|
+
* Release a pre-commit hold, returning the unspent reservation to the budget.
|
|
95
|
+
* Use BEFORE a payment settles (planned charge cancelled, hold expiring).
|
|
96
|
+
* For an already-settled payment, use refund() instead.
|
|
97
|
+
*/
|
|
98
|
+
release(verificationId: string): Promise<ReleaseResponse>;
|
|
99
|
+
/**
|
|
100
|
+
* Refund a settled (committed) payment, fully or partially. Restores budget.
|
|
101
|
+
* `idempotencyKey` makes retries safe — the same key never double-refunds.
|
|
102
|
+
* For a pre-commit hold that hasn't settled, use release() instead.
|
|
103
|
+
*/
|
|
104
|
+
refund(verificationId: string, amountCents: number, idempotencyKey: string): Promise<RefundResponse>;
|
|
105
|
+
/**
|
|
106
|
+
* Create a spending budget — no crypto signatures needed. The API key holder
|
|
107
|
+
* is the trust anchor. Returns a budget_id for use with verifyById().
|
|
108
|
+
*/
|
|
109
|
+
createBudget(options: {
|
|
110
|
+
agentId: string;
|
|
111
|
+
budgetTotal: number;
|
|
112
|
+
currency?: string;
|
|
113
|
+
validUntil: string;
|
|
114
|
+
validFrom?: string;
|
|
115
|
+
maxTransactions?: number;
|
|
116
|
+
constraints?: {
|
|
117
|
+
maxAmount?: string;
|
|
118
|
+
currency?: string;
|
|
119
|
+
allowedMerchants?: string[];
|
|
120
|
+
blockedMerchants?: string[];
|
|
121
|
+
categories?: string[];
|
|
122
|
+
};
|
|
123
|
+
}): Promise<{
|
|
124
|
+
id: string;
|
|
125
|
+
type: "budget";
|
|
126
|
+
agentId: string;
|
|
127
|
+
budgetTotal: string;
|
|
128
|
+
remainingBudget: string;
|
|
129
|
+
currency: string;
|
|
130
|
+
validUntil: string;
|
|
131
|
+
}>;
|
|
132
|
+
/**
|
|
133
|
+
* Query mandate state — budget, transaction count, history.
|
|
134
|
+
*/
|
|
135
|
+
getMandateState(mandateId: string): Promise<{
|
|
136
|
+
mandate: {
|
|
137
|
+
id: string;
|
|
138
|
+
budgetTotal: string;
|
|
139
|
+
budgetSpent: string;
|
|
140
|
+
remainingBudget: string;
|
|
141
|
+
txCount: number;
|
|
142
|
+
};
|
|
143
|
+
transactions: Array<{
|
|
144
|
+
verification_id: string;
|
|
145
|
+
merchant_name: string;
|
|
146
|
+
amount: number;
|
|
147
|
+
status: string;
|
|
148
|
+
payment_rail: string | null;
|
|
149
|
+
}>;
|
|
150
|
+
}>;
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,WAAW,EACX,QAAQ,EACR,cAAc,EACd,cAAc,EACd,eAAe,EACf,cAAc,EACf,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CA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O,EAAE;YACP,EAAE,EAAE,MAAM,CAAC;YACX,WAAW,EAAE,MAAM,CAAC;YACpB,WAAW,EAAE,MAAM,CAAC;YACpB,eAAe,EAAE,MAAM,CAAC;YACxB,OAAO,EAAE,MAAM,CAAC;SACjB,CAAC;QACF,YAAY,EAAE,KAAK,CAAC;YAClB,eAAe,EAAE,MAAM,CAAC;YACxB,aAAa,EAAE,MAAM,CAAC;YACtB,MAAM,EAAE,MAAM,CAAC;YACf,MAAM,EAAE,MAAM,CAAC;YACf,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;SAC7B,CAAC,CAAC;KACJ,CAAC;CAGH"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Verifier API Client
|
|
3
|
+
*
|
|
4
|
+
* For merchants integrating with the hosted Good Meta Verifier.
|
|
5
|
+
* Cross-merchant budget tracking, hold management, audit trail.
|
|
6
|
+
*
|
|
7
|
+
* Every call applies a timeout, surfaces transport/auth/server/non-JSON failures
|
|
8
|
+
* as a typed VerifierError, and never blind-parses an error body as a success
|
|
9
|
+
* response. A *denied* verification (HTTP 403 with { approved: false }) is a
|
|
10
|
+
* normal domain outcome and is returned, not thrown.
|
|
11
|
+
*
|
|
12
|
+
* import { VerifierClient, VerifierError } from "@goodmeta/agent-verifier";
|
|
13
|
+
*
|
|
14
|
+
* const verifier = new VerifierClient({ apiKey: "gm_test_..." });
|
|
15
|
+
* const result = await verifier.verify(mandate, { amount: "3000", currency: "USDC", idempotencyKey: "tx-1" });
|
|
16
|
+
* if (result.approved) await verifier.settle(result.verificationId!, { success: true });
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Thrown for transport, timeout, auth (401), client (4xx), server (5xx), or
|
|
20
|
+
* non-JSON failures. Business outcomes (e.g. a denied verification) are
|
|
21
|
+
* returned, not thrown. Carries the HTTP `status` and parsed `body` when available.
|
|
22
|
+
*/
|
|
23
|
+
export class VerifierError extends Error {
|
|
24
|
+
status;
|
|
25
|
+
body;
|
|
26
|
+
constructor(message, opts = {}) {
|
|
27
|
+
super(message, opts.cause !== undefined ? { cause: opts.cause } : undefined);
|
|
28
|
+
this.name = "VerifierError";
|
|
29
|
+
this.status = opts.status;
|
|
30
|
+
this.body = opts.body;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const DEFAULT_TIMEOUT_MS = 10_000;
|
|
34
|
+
export class VerifierClient {
|
|
35
|
+
apiKey;
|
|
36
|
+
baseUrl;
|
|
37
|
+
timeoutMs;
|
|
38
|
+
fetchImpl;
|
|
39
|
+
constructor(options) {
|
|
40
|
+
if (!options.apiKey)
|
|
41
|
+
throw new VerifierError("apiKey is required");
|
|
42
|
+
this.apiKey = options.apiKey;
|
|
43
|
+
this.baseUrl = (options.baseUrl || "https://verifier.goodmeta.co").replace(/\/$/, "");
|
|
44
|
+
this.timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
45
|
+
this.fetchImpl = options.fetch ?? fetch;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Low-level request: applies auth header + timeout, returns { status, body }.
|
|
49
|
+
* Throws VerifierError on network failure, timeout (AbortError), or a body
|
|
50
|
+
* that isn't valid JSON.
|
|
51
|
+
*/
|
|
52
|
+
async raw(path, init) {
|
|
53
|
+
const controller = new AbortController();
|
|
54
|
+
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
55
|
+
let res;
|
|
56
|
+
try {
|
|
57
|
+
res = await this.fetchImpl(`${this.baseUrl}${path}`, {
|
|
58
|
+
method: init.method,
|
|
59
|
+
headers: { Authorization: `Bearer ${this.apiKey}`, "Content-Type": "application/json" },
|
|
60
|
+
body: init.body,
|
|
61
|
+
signal: controller.signal,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
catch (cause) {
|
|
65
|
+
const aborted = cause?.name === "AbortError";
|
|
66
|
+
throw new VerifierError(aborted
|
|
67
|
+
? `${init.method} ${path} timed out after ${this.timeoutMs}ms`
|
|
68
|
+
: `${init.method} ${path} failed: ${cause?.message ?? "network error"}`, { cause });
|
|
69
|
+
}
|
|
70
|
+
finally {
|
|
71
|
+
clearTimeout(timer);
|
|
72
|
+
}
|
|
73
|
+
const text = await res.text();
|
|
74
|
+
let body;
|
|
75
|
+
if (text) {
|
|
76
|
+
try {
|
|
77
|
+
body = JSON.parse(text);
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
throw new VerifierError(`non-JSON response from ${path} (HTTP ${res.status})`, {
|
|
81
|
+
status: res.status,
|
|
82
|
+
body: text,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return { status: res.status, body };
|
|
87
|
+
}
|
|
88
|
+
/** POST that throws VerifierError on any non-2xx. */
|
|
89
|
+
async post(path, payload) {
|
|
90
|
+
const { status, body } = await this.raw(path, { method: "POST", body: JSON.stringify(payload) });
|
|
91
|
+
if (status >= 200 && status < 300)
|
|
92
|
+
return body;
|
|
93
|
+
throw new VerifierError(`POST ${path} failed (HTTP ${status})`, { status, body });
|
|
94
|
+
}
|
|
95
|
+
/** GET that throws VerifierError on any non-2xx. */
|
|
96
|
+
async get(path) {
|
|
97
|
+
const { status, body } = await this.raw(path, { method: "GET" });
|
|
98
|
+
if (status >= 200 && status < 300)
|
|
99
|
+
return body;
|
|
100
|
+
throw new VerifierError(`GET ${path} failed (HTTP ${status})`, { status, body });
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* verify/verifyById share this: a denial (HTTP 403, { approved:false }) is a
|
|
104
|
+
* domain outcome and is returned. Auth/validation/server errors throw.
|
|
105
|
+
*/
|
|
106
|
+
async doVerify(payload) {
|
|
107
|
+
const { status, body } = await this.raw("/v1/verify", {
|
|
108
|
+
method: "POST",
|
|
109
|
+
body: JSON.stringify(payload),
|
|
110
|
+
});
|
|
111
|
+
if ((status >= 200 && status < 300) || status === 403)
|
|
112
|
+
return body;
|
|
113
|
+
throw new VerifierError(`verify failed (HTTP ${status})`, { status, body });
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Verify a mandate and place a budget hold. Call this BEFORE processing payment.
|
|
117
|
+
* A denied result is returned with `approved: false`; transport/auth/server
|
|
118
|
+
* errors throw VerifierError.
|
|
119
|
+
*/
|
|
120
|
+
async verify(mandate, transaction) {
|
|
121
|
+
return this.doVerify({ mandate, transaction });
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Verify by mandate/policy ID — for integrations where the agent only passes
|
|
125
|
+
* an ID (e.g. cart metadata), not the full mandate object.
|
|
126
|
+
*/
|
|
127
|
+
async verifyById(mandateId, transaction) {
|
|
128
|
+
return this.doVerify({ mandateId, transaction });
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Settle a verification after payment succeeds or fails.
|
|
132
|
+
* success=true → budget permanently debited; success=false → hold released.
|
|
133
|
+
*/
|
|
134
|
+
async settle(verificationId, paymentResult) {
|
|
135
|
+
return this.post("/v1/settle", { verificationId, paymentResult });
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Release a pre-commit hold, returning the unspent reservation to the budget.
|
|
139
|
+
* Use BEFORE a payment settles (planned charge cancelled, hold expiring).
|
|
140
|
+
* For an already-settled payment, use refund() instead.
|
|
141
|
+
*/
|
|
142
|
+
async release(verificationId) {
|
|
143
|
+
return this.post("/v1/release", { verificationId });
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Refund a settled (committed) payment, fully or partially. Restores budget.
|
|
147
|
+
* `idempotencyKey` makes retries safe — the same key never double-refunds.
|
|
148
|
+
* For a pre-commit hold that hasn't settled, use release() instead.
|
|
149
|
+
*/
|
|
150
|
+
async refund(verificationId, amountCents, idempotencyKey) {
|
|
151
|
+
return this.post("/v1/refund", {
|
|
152
|
+
verificationId,
|
|
153
|
+
amount_cents: amountCents,
|
|
154
|
+
idempotency_key: idempotencyKey,
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Create a spending budget — no crypto signatures needed. The API key holder
|
|
159
|
+
* is the trust anchor. Returns a budget_id for use with verifyById().
|
|
160
|
+
*/
|
|
161
|
+
async createBudget(options) {
|
|
162
|
+
return this.post("/v1/budgets", options);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Query mandate state — budget, transaction count, history.
|
|
166
|
+
*/
|
|
167
|
+
async getMandateState(mandateId) {
|
|
168
|
+
return this.get(`/v1/mandates/${encodeURIComponent(mandateId)}`);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AA4BH;;;;GAIG;AACH,MAAM,OAAO,aAAc,SAAQ,KAAK;IAC7B,MAAM,CAAU;IAChB,IAAI,CAAW;IACxB,YAAY,OAAe,EAAE,OAA6D,EAAE;QAC1F,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QAC7E,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;IACxB,CAAC;CACF;AAED,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAElC,MAAM,OAAO,cAAc;IACjB,MAAM,CAAS;IACf,OAAO,CAAS;IAChB,SAAS,CAAS;IAClB,SAAS,CAAe;IAEhC,YAAY,OAA8B;QACxC,IAAI,CAAC,OAAO,CAAC,MAAM;YAAE,MAAM,IAAI,aAAa,CAAC,oBAAoB,CAAC,CAAC;QACnE,IAAI,CAAC,MAA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E,cAAc,EAAE,CAAC,CAAC;IACvE,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,MAAM,CACV,cAAsB,EACtB,WAAmB,EACnB,cAAsB;QAEtB,OAAO,IAAI,CAAC,IAAI,CAAiB,YAAY,EAAE;YAC7C,cAAc;YACd,YAAY,EAAE,WAAW;YACzB,eAAe,EAAE,cAAc;SAChC,CAAC,CAAC;IACL,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,YAAY,CAAC,OAclB;QASC,OAAO,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IAC3C,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,eAAe,CAAC,SAAiB;QAgBrC,OAAO,IAAI,CAAC,GAAG,CAAC,gBAAgB,kBAAkB,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IACnE,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @goodmeta/agent-verifier
|
|
3
|
+
*
|
|
4
|
+
* Agent spending verification — open source.
|
|
5
|
+
*
|
|
6
|
+
* Real AP2 mandate verification (dSD-JWT delegation chains) — the headline:
|
|
7
|
+
* import { ap2 } from "@goodmeta/agent-verifier";
|
|
8
|
+
* const payloads = await ap2.verifyChain(ap2.splitChain(chain), key, { expectedAud, expectedNonce });
|
|
9
|
+
* const violations = ap2.verifyPaymentChain(ap2.parsePaymentChain(payloads));
|
|
10
|
+
*
|
|
11
|
+
* Receipt signing & verification (ES256 JWS — AP2's *receipt* format):
|
|
12
|
+
* import { signReceipt, verifyReceipt } from "@goodmeta/agent-verifier";
|
|
13
|
+
*
|
|
14
|
+
* Hosted Verifier API (cross-agent budget state) + policy engine:
|
|
15
|
+
* import { VerifierClient, checkPolicy } from "@goodmeta/agent-verifier";
|
|
16
|
+
*/
|
|
17
|
+
export * as ap2 from "./ap2/index.js";
|
|
18
|
+
export { signReceipt, verifyReceipt } from "./receipt-jwt.js";
|
|
19
|
+
export type { VerifiedReceipt, JWK } from "./receipt-jwt.js";
|
|
20
|
+
export { checkPolicy } from "./policy.js";
|
|
21
|
+
export type { SpendingPolicy, PolicyVerifyRequest, PolicyVerifyResponse } from "./policy.js";
|
|
22
|
+
export { VerifierClient, VerifierError } from "./client.js";
|
|
23
|
+
export type { VerifierClientOptions, VerifyByIdTransaction } from "./client.js";
|
|
24
|
+
export { parseCents, Cents, ConstraintTxSchema, PolicyRequestSchema } from "./schema.js";
|
|
25
|
+
export { checkConstraints } from "./verify.js";
|
|
26
|
+
export type { IntentMandate, CartMandate, CartItem, SpendingConstraint, VerifyRequest, VerifyResponse, SettleRequest, SettleResponse, MandateSummary, ReleaseResponse, RefundResponse, } from "./types.js";
|
|
27
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,KAAK,GAAG,MAAM,gBAAgB,CAAC;AAGtC,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC9D,YAAY,EAAE,eAAe,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAG7D,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,YAAY,EAAE,cAAc,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAC7F,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5D,YAAY,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAGhF,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAKzF,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EACV,aAAa,EACb,WAAW,EACX,QAAQ,EACR,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,aAAa,EACb,cAAc,EACd,cAAc,EACd,eAAe,EACf,cAAc,GACf,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @goodmeta/agent-verifier
|
|
3
|
+
*
|
|
4
|
+
* Agent spending verification — open source.
|
|
5
|
+
*
|
|
6
|
+
* Real AP2 mandate verification (dSD-JWT delegation chains) — the headline:
|
|
7
|
+
* import { ap2 } from "@goodmeta/agent-verifier";
|
|
8
|
+
* const payloads = await ap2.verifyChain(ap2.splitChain(chain), key, { expectedAud, expectedNonce });
|
|
9
|
+
* const violations = ap2.verifyPaymentChain(ap2.parsePaymentChain(payloads));
|
|
10
|
+
*
|
|
11
|
+
* Receipt signing & verification (ES256 JWS — AP2's *receipt* format):
|
|
12
|
+
* import { signReceipt, verifyReceipt } from "@goodmeta/agent-verifier";
|
|
13
|
+
*
|
|
14
|
+
* Hosted Verifier API (cross-agent budget state) + policy engine:
|
|
15
|
+
* import { VerifierClient, checkPolicy } from "@goodmeta/agent-verifier";
|
|
16
|
+
*/
|
|
17
|
+
// ── Real AP2 mandate verification (dSD-JWT) — see src/ap2 + AP2-AUDIT.md ──────
|
|
18
|
+
export * as ap2 from "./ap2/index.js";
|
|
19
|
+
// ── Receipt signing & verification — ES256 JWS, AP2's receipt format ─────────
|
|
20
|
+
export { signReceipt, verifyReceipt } from "./receipt-jwt.js";
|
|
21
|
+
// ── Hosted Verifier API + policy engine (non-AP2 billing systems) ────────────
|
|
22
|
+
export { checkPolicy } from "./policy.js";
|
|
23
|
+
export { VerifierClient, VerifierError } from "./client.js";
|
|
24
|
+
// Input validation schemas (zod) — boundary validators + shared cents rule
|
|
25
|
+
export { parseCents, Cents, ConstraintTxSchema, PolicyRequestSchema } from "./schema.js";
|
|
26
|
+
// ── LEGACY (pre-AP2) hosted-API types — camelCase, NOT the AP2 dSD-JWT mandate
|
|
27
|
+
// model. Retained for the hosted Verifier client API; new integrations
|
|
28
|
+
// should use the snake_case `ap2.*` mandate schemas above. ─────────────────
|
|
29
|
+
export { checkConstraints } from "./verify.js";
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,iFAAiF;AACjF,OAAO,KAAK,GAAG,MAAM,gBAAgB,CAAC;AAEtC,gFAAgF;AAChF,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAG9D,gFAAgF;AAChF,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5D,2EAA2E;AAC3E,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEzF,gFAAgF;AAChF,0EAA0E;AAC1E,gFAAgF;AAChF,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/policy.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Policy-Based Spending Verification
|
|
3
|
+
*
|
|
4
|
+
* For systems that don't use AP2 mandates (Lago, custom billing, etc).
|
|
5
|
+
* Spending rules are configured via API, not cryptographic signatures.
|
|
6
|
+
*
|
|
7
|
+
* Same core logic: can this agent spend $X on Y right now?
|
|
8
|
+
*/
|
|
9
|
+
export interface SpendingPolicy {
|
|
10
|
+
agentId: string;
|
|
11
|
+
budgetTotal: number;
|
|
12
|
+
budgetPeriod: "daily" | "weekly" | "monthly" | "total";
|
|
13
|
+
constraints: {
|
|
14
|
+
maxPerEvent: number;
|
|
15
|
+
allowedCodes?: string[];
|
|
16
|
+
blockedCodes?: string[];
|
|
17
|
+
allowedCustomers?: string[];
|
|
18
|
+
blockedCustomers?: string[];
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export interface PolicyVerifyRequest {
|
|
22
|
+
agentId: string;
|
|
23
|
+
amount: number;
|
|
24
|
+
metadata?: {
|
|
25
|
+
code?: string;
|
|
26
|
+
customer?: string;
|
|
27
|
+
[key: string]: unknown;
|
|
28
|
+
};
|
|
29
|
+
idempotencyKey: string;
|
|
30
|
+
}
|
|
31
|
+
export interface PolicyVerifyResponse {
|
|
32
|
+
approved: boolean;
|
|
33
|
+
reason?: string;
|
|
34
|
+
detail?: string;
|
|
35
|
+
remaining?: {
|
|
36
|
+
budget: number;
|
|
37
|
+
period: string;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Check a spending request against a local policy (stateless).
|
|
42
|
+
* For cross-agent budget tracking, use the hosted Verifier.
|
|
43
|
+
*/
|
|
44
|
+
export declare function checkPolicy(policy: SpendingPolicy, request: PolicyVerifyRequest, currentSpend?: number): PolicyVerifyResponse;
|
|
45
|
+
//# sourceMappingURL=policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../src/policy.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,OAAO,GAAG,QAAQ,GAAG,SAAS,GAAG,OAAO,CAAC;IACvD,WAAW,EAAE;QACX,WAAW,EAAE,MAAM,CAAC;QACpB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;QACxB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;QACxB,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;QAC5B,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;KAC7B,CAAC;CACH;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE;QACT,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACxB,CAAC;IACF,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE;QACV,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH;AAED;;;GAGG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,cAAc,EACtB,OAAO,EAAE,mBAAmB,EAC5B,YAAY,GAAE,MAAU,GACvB,oBAAoB,CAiFtB"}
|