agentwallet-sdk 3.1.2 → 3.2.1

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.
@@ -0,0 +1,185 @@
1
+ /**
2
+ * AP2Client — ISO 20022 / AP2 European Payment Module for agentwallet-sdk
3
+ *
4
+ * Non-custodial AI agent bridge for AP2 payments:
5
+ * - Parse ISO 20022 pacs.008 XML → bridge quote
6
+ * - Sign x402 payment header locally (private key never leaves agent)
7
+ * - Execute USDC → EUR settlement via CCTP V2 (Base → EUR off-ramp)
8
+ *
9
+ * AP2 context:
10
+ * Nexi + Google Cloud MoU (2026): AP2 processes ~2.9T EUR/year across Europe.
11
+ * ISO 20022 is the wire standard. This module makes AI agents first-class
12
+ * European payment participants — non-custodially.
13
+ *
14
+ * @module ap2
15
+ */
16
+ /** Parameters for building a pacs.008 XML message from simple inputs. */
17
+ export interface AP2PaymentParams {
18
+ /** Unique message ID (e.g. "MSG-2026-0001") */
19
+ messageId: string;
20
+ /** ISO 8601 creation datetime (defaults to now) */
21
+ creationDateTime?: string;
22
+ /** Payment amount in EUR (or specified currency) */
23
+ amount: number;
24
+ /** Currency code (default: "EUR") */
25
+ currency?: string;
26
+ /** Debtor full name */
27
+ debtorName: string;
28
+ /** Debtor IBAN */
29
+ debtorIban: string;
30
+ /** Debtor BIC */
31
+ debtorBic: string;
32
+ /** Creditor full name */
33
+ creditorName: string;
34
+ /** Creditor IBAN */
35
+ creditorIban: string;
36
+ /** Creditor BIC */
37
+ creditorBic: string;
38
+ /** Optional end-to-end reference */
39
+ endToEndId?: string;
40
+ /** Optional purpose code (e.g. "SUPP") */
41
+ purposeCode?: string;
42
+ /** Optional unstructured remittance info */
43
+ remittanceInfo?: string;
44
+ }
45
+ /** Bridge quote returned by the AP2 facilitator. */
46
+ export interface AP2Quote {
47
+ /** ISO 20022 message ID */
48
+ messageId: string;
49
+ /** Creditor IBAN for SEPA settlement */
50
+ creditorIban: string;
51
+ /** EUR payment amount */
52
+ amountEur: number;
53
+ /** USDC required (6 decimal precision, as bigint μUSDC) */
54
+ usdcRequired: bigint;
55
+ /** Bridge fee in USDC (μUSDC) */
56
+ bridgeFeeUsdc: bigint;
57
+ /** Estimated settlement time in seconds */
58
+ estimatedSettlementSeconds: number;
59
+ /** x402 payment header string */
60
+ x402PaymentHeader: string;
61
+ /** Raw calldata for agentwallet-sdk */
62
+ agentWalletCalldata: Record<string, unknown>;
63
+ /** Quote expiry ISO timestamp */
64
+ expiresAt: string;
65
+ }
66
+ /** Execution receipt after AP2 payment is submitted. */
67
+ export interface AP2Receipt {
68
+ /** ISO 20022 message ID */
69
+ messageId: string;
70
+ /** On-chain transaction hash */
71
+ txHash: string;
72
+ /** USDC bridged (μUSDC as bigint) */
73
+ usdcBridged: bigint;
74
+ /** SEPA creditor reference */
75
+ sepaReference: string;
76
+ /** Payment status */
77
+ status: 'pending' | 'confirmed' | 'failed' | 'dry_run';
78
+ /** True if this was a dry run simulation */
79
+ dryRun: boolean;
80
+ /** x402 payment header signature */
81
+ x402Signature: string;
82
+ /** Agent Ethereum address */
83
+ agentAddress: string;
84
+ /** CCTP bridge nonce */
85
+ nonce: number;
86
+ /** ISO timestamp of execution */
87
+ executedAt: string;
88
+ /** Creditor IBAN */
89
+ creditorIban: string;
90
+ /** Bridge fee in USDC (μUSDC) */
91
+ bridgeFeeUsdc: bigint;
92
+ }
93
+ /** AP2Client configuration */
94
+ export interface AP2ClientConfig {
95
+ /**
96
+ * URL of the AP2 facilitator (FastAPI handler).
97
+ * Defaults to http://localhost:8420
98
+ */
99
+ facilitatorUrl?: string;
100
+ }
101
+ /**
102
+ * Build a valid ISO 20022 pacs.008 (FIToFICstmrCdtTrf) XML string
103
+ * from simple agent-friendly parameters.
104
+ *
105
+ * @param params - Payment parameters
106
+ * @returns ISO 20022 pacs.008 XML string
107
+ */
108
+ declare function buildPacs008(params: AP2PaymentParams): string;
109
+ /**
110
+ * AP2Client — Non-custodial ISO 20022 / AP2 payment client for AI agents.
111
+ *
112
+ * Connects to the AP2 facilitator (ap2_handler.py FastAPI service) to
113
+ * get bridge quotes and execute payments via CCTP V2 / x402.
114
+ *
115
+ * @example
116
+ * ```typescript
117
+ * const client = new AP2Client({ facilitatorUrl: 'http://localhost:8420' });
118
+ *
119
+ * const xml = AP2Client.buildPacs008({
120
+ * messageId: 'MSG-2026-0001',
121
+ * amount: 1000,
122
+ * debtorName: 'Agent Zero',
123
+ * debtorIban: 'DE89370400440532013000',
124
+ * debtorBic: 'COBADEFFXXX',
125
+ * creditorName: 'Acme GmbH',
126
+ * creditorIban: 'FR7630006000011234567890189',
127
+ * creditorBic: 'BNPAFRPPXXX',
128
+ * });
129
+ *
130
+ * const quote = await client.quote(xml);
131
+ * const receipt = await client.pay(xml);
132
+ * ```
133
+ */
134
+ export declare class AP2Client {
135
+ private readonly facilitatorUrl;
136
+ constructor(config?: AP2ClientConfig);
137
+ /**
138
+ * Parse ISO 20022 pacs.008 XML and get a bridge quote from the facilitator.
139
+ *
140
+ * @param iso20022Xml - Raw pacs.008 XML string
141
+ * @returns AP2Quote with USDC amounts and x402 calldata
142
+ * @throws Error if the facilitator returns an error or the XML is invalid
143
+ */
144
+ quote(iso20022Xml: string): Promise<AP2Quote>;
145
+ /**
146
+ * Execute the full AP2 payment: sign x402 header + bridge USDC + settle.
147
+ *
148
+ * Calls the /ap2/execute endpoint on the facilitator, which:
149
+ * 1. Parses the XML
150
+ * 2. Signs x402 header with agent's private key (server-side in this flow)
151
+ * 3. Submits USDC to CCTP V2 bridge
152
+ * 4. Returns receipt
153
+ *
154
+ * @param iso20022Xml - Raw pacs.008 XML string
155
+ * @returns AP2Receipt with txHash and SEPA reference
156
+ * @throws AP2Error on execution failure
157
+ */
158
+ pay(iso20022Xml: string): Promise<AP2Receipt>;
159
+ /**
160
+ * Generate a valid ISO 20022 pacs.008 XML string from simple parameters.
161
+ *
162
+ * Handles XML escaping, IBAN normalization, and timestamp formatting.
163
+ * Makes AP2 payments agent-friendly — no ISO 20022 expertise required.
164
+ *
165
+ * @param params - Simple payment parameters
166
+ * @returns Valid pacs.008 XML string
167
+ */
168
+ static buildPacs008(params: AP2PaymentParams): string;
169
+ /**
170
+ * Estimate USDC required for a given EUR amount.
171
+ *
172
+ * Uses the default EUR/USDC rate. For accurate quotes, call quote() instead.
173
+ *
174
+ * @param amountEur - Amount in EUR
175
+ * @returns Estimated USDC amount as bigint (μUSDC, 6 decimals)
176
+ */
177
+ static estimateUsdc(amountEur: number): bigint;
178
+ }
179
+ /** AP2-specific error with structured context. */
180
+ export declare class AP2Error extends Error {
181
+ readonly context?: Record<string, unknown> | undefined;
182
+ constructor(message: string, context?: Record<string, unknown> | undefined);
183
+ }
184
+ export { buildPacs008 };
185
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ap2/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAMH,yEAAyE;AACzE,MAAM,WAAW,gBAAgB;IAC/B,+CAA+C;IAC/C,SAAS,EAAE,MAAM,CAAC;IAClB,mDAAmD;IACnD,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,oDAAoD;IACpD,MAAM,EAAE,MAAM,CAAC;IACf,qCAAqC;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,uBAAuB;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,kBAAkB;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,yBAAyB;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,oBAAoB;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,mBAAmB;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,oCAAoC;IACpC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,0CAA0C;IAC1C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4CAA4C;IAC5C,cAAc,CA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AuBD;;;;;;GAMG;AACH,iBAAS,YAAY,CAAC,MAAM,EAAE,gBAAgB,GAAG,MAAM,CA0DtD;AAuBD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;gBAE5B,MAAM,GAAE,eAAoB;IAIxC;;;;;;OAMG;IACG,KAAK,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IA6BnD;;;;;;;;;;;;OAYG;IACG,GAAG,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IA+BnD;;;;;;;;OAQG;IACH,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,gBAAgB,GAAG,MAAM;IAIrD;;;;;;;OAOG;IACH,MAAM,CAAC,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM;CAI/C;AAMD,kDAAkD;AAClD,qBAAa,QAAS,SAAQ,KAAK;aACY,OAAO,CAAC;gBAAzC,OAAO,EAAE,MAAM,EAAkB,OAAO,CAAC,qCAAyB;CAI/E;AAMD,OAAO,EAAE,YAAY,EAAE,CAAC"}
@@ -0,0 +1,255 @@
1
+ /**
2
+ * AP2Client — ISO 20022 / AP2 European Payment Module for agentwallet-sdk
3
+ *
4
+ * Non-custodial AI agent bridge for AP2 payments:
5
+ * - Parse ISO 20022 pacs.008 XML → bridge quote
6
+ * - Sign x402 payment header locally (private key never leaves agent)
7
+ * - Execute USDC → EUR settlement via CCTP V2 (Base → EUR off-ramp)
8
+ *
9
+ * AP2 context:
10
+ * Nexi + Google Cloud MoU (2026): AP2 processes ~2.9T EUR/year across Europe.
11
+ * ISO 20022 is the wire standard. This module makes AI agents first-class
12
+ * European payment participants — non-custodially.
13
+ *
14
+ * @module ap2
15
+ */
16
+ // ---------------------------------------------------------------------------
17
+ // Constants
18
+ // ---------------------------------------------------------------------------
19
+ /** USDC decimals (6) */
20
+ const USDC_DECIMALS = 6n;
21
+ const USDC_MULTIPLIER = 10n ** USDC_DECIMALS;
22
+ /** EUR → USDC rate (fallback; production uses Chainlink oracle) */
23
+ const EUR_TO_USDC_RATE = 1.08;
24
+ /** Default facilitator URL */
25
+ const DEFAULT_FACILITATOR_URL = 'http://localhost:8420';
26
+ /** Estimated CCTP V2 settlement time (~20 min) */
27
+ const ESTIMATED_SETTLEMENT_SECONDS = 1200;
28
+ // ---------------------------------------------------------------------------
29
+ // ISO 20022 pacs.008 XML Builder
30
+ // ---------------------------------------------------------------------------
31
+ /**
32
+ * Build a valid ISO 20022 pacs.008 (FIToFICstmrCdtTrf) XML string
33
+ * from simple agent-friendly parameters.
34
+ *
35
+ * @param params - Payment parameters
36
+ * @returns ISO 20022 pacs.008 XML string
37
+ */
38
+ function buildPacs008(params) {
39
+ const now = params.creationDateTime ?? new Date().toISOString().replace(/\.\d+Z$/, '+00:00');
40
+ const currency = params.currency ?? 'EUR';
41
+ const e2eId = params.endToEndId ?? params.messageId;
42
+ const amount = params.amount.toFixed(2);
43
+ return `<?xml version="1.0" encoding="UTF-8"?>
44
+ <Document xmlns="urn:iso:std:iso:20022:tech:xsd:pacs.008.001.08">
45
+ <FIToFICstmrCdtTrf>
46
+ <GrpHdr>
47
+ <MsgId>${escapeXml(params.messageId)}</MsgId>
48
+ <CreDtTm>${escapeXml(now)}</CreDtTm>
49
+ <NbOfTxs>1</NbOfTxs>
50
+ <SttlmInf>
51
+ <SttlmMtd>CLRG</SttlmMtd>
52
+ </SttlmInf>
53
+ </GrpHdr>
54
+ <CdtTrfTxInf>
55
+ <PmtId>
56
+ <EndToEndId>${escapeXml(e2eId)}</EndToEndId>
57
+ </PmtId>
58
+ <IntrBkSttlmAmt Ccy="${escapeXml(currency)}">${amount}</IntrBkSttlmAmt>
59
+ <ChrgBr>SHAR</ChrgBr>
60
+ <Dbtr>
61
+ <Nm>${escapeXml(params.debtorName)}</Nm>
62
+ </Dbtr>
63
+ <DbtrAcct>
64
+ <Id>
65
+ <IBAN>${escapeXml(params.debtorIban.replace(/\s/g, '').toUpperCase())}</IBAN>
66
+ </Id>
67
+ </DbtrAcct>
68
+ <DbtrAgt>
69
+ <FinInstnId>
70
+ <BICFI>${escapeXml(params.debtorBic.toUpperCase())}</BICFI>
71
+ </FinInstnId>
72
+ </DbtrAgt>
73
+ <Cdtr>
74
+ <Nm>${escapeXml(params.creditorName)}</Nm>
75
+ </Cdtr>
76
+ <CdtrAcct>
77
+ <Id>
78
+ <IBAN>${escapeXml(params.creditorIban.replace(/\s/g, '').toUpperCase())}</IBAN>
79
+ </Id>
80
+ </CdtrAcct>
81
+ <CdtrAgt>
82
+ <FinInstnId>
83
+ <BICFI>${escapeXml(params.creditorBic.toUpperCase())}</BICFI>
84
+ </FinInstnId>
85
+ </CdtrAgt>${params.purposeCode ? `
86
+ <Purp>
87
+ <Cd>${escapeXml(params.purposeCode)}</Cd>
88
+ </Purp>` : ''}${params.remittanceInfo ? `
89
+ <RmtInf>
90
+ <Ustrd>${escapeXml(params.remittanceInfo)}</Ustrd>
91
+ </RmtInf>` : ''}
92
+ </CdtTrfTxInf>
93
+ </FIToFICstmrCdtTrf>
94
+ </Document>`;
95
+ }
96
+ /** Escape XML special characters. */
97
+ function escapeXml(str) {
98
+ return str
99
+ .replace(/&/g, '&amp;')
100
+ .replace(/</g, '&lt;')
101
+ .replace(/>/g, '&gt;')
102
+ .replace(/"/g, '&quot;')
103
+ .replace(/'/g, '&apos;');
104
+ }
105
+ /** Convert a decimal USDC string to bigint μUSDC. */
106
+ function usdcToBigInt(usdcStr) {
107
+ const [whole, frac = ''] = usdcStr.split('.');
108
+ const fracPadded = frac.padEnd(Number(USDC_DECIMALS), '0').slice(0, Number(USDC_DECIMALS));
109
+ return BigInt(whole) * USDC_MULTIPLIER + BigInt(fracPadded);
110
+ }
111
+ // ---------------------------------------------------------------------------
112
+ // AP2Client
113
+ // ---------------------------------------------------------------------------
114
+ /**
115
+ * AP2Client — Non-custodial ISO 20022 / AP2 payment client for AI agents.
116
+ *
117
+ * Connects to the AP2 facilitator (ap2_handler.py FastAPI service) to
118
+ * get bridge quotes and execute payments via CCTP V2 / x402.
119
+ *
120
+ * @example
121
+ * ```typescript
122
+ * const client = new AP2Client({ facilitatorUrl: 'http://localhost:8420' });
123
+ *
124
+ * const xml = AP2Client.buildPacs008({
125
+ * messageId: 'MSG-2026-0001',
126
+ * amount: 1000,
127
+ * debtorName: 'Agent Zero',
128
+ * debtorIban: 'DE89370400440532013000',
129
+ * debtorBic: 'COBADEFFXXX',
130
+ * creditorName: 'Acme GmbH',
131
+ * creditorIban: 'FR7630006000011234567890189',
132
+ * creditorBic: 'BNPAFRPPXXX',
133
+ * });
134
+ *
135
+ * const quote = await client.quote(xml);
136
+ * const receipt = await client.pay(xml);
137
+ * ```
138
+ */
139
+ export class AP2Client {
140
+ constructor(config = {}) {
141
+ this.facilitatorUrl = (config.facilitatorUrl ?? DEFAULT_FACILITATOR_URL).replace(/\/$/, '');
142
+ }
143
+ /**
144
+ * Parse ISO 20022 pacs.008 XML and get a bridge quote from the facilitator.
145
+ *
146
+ * @param iso20022Xml - Raw pacs.008 XML string
147
+ * @returns AP2Quote with USDC amounts and x402 calldata
148
+ * @throws Error if the facilitator returns an error or the XML is invalid
149
+ */
150
+ async quote(iso20022Xml) {
151
+ const response = await fetch(`${this.facilitatorUrl}/ap2/payment`, {
152
+ method: 'POST',
153
+ headers: { 'Content-Type': 'application/xml' },
154
+ body: iso20022Xml,
155
+ });
156
+ if (!response.ok) {
157
+ const body = await response.text();
158
+ throw new AP2Error(`Quote failed (${response.status}): ${body}`);
159
+ }
160
+ const json = (await response.json());
161
+ const bq = json.bridge_quote;
162
+ const payment = json.payment;
163
+ return {
164
+ messageId: payment.message_id,
165
+ creditorIban: payment.creditor.iban,
166
+ amountEur: parseFloat(payment.amount),
167
+ usdcRequired: usdcToBigInt(bq.usdc_amount),
168
+ bridgeFeeUsdc: usdcToBigInt(bq.bridge_fee_usdc),
169
+ estimatedSettlementSeconds: ESTIMATED_SETTLEMENT_SECONDS,
170
+ x402PaymentHeader: bq.x402_payment_header,
171
+ agentWalletCalldata: bq.agent_wallet_calldata,
172
+ expiresAt: bq.expires_at,
173
+ };
174
+ }
175
+ /**
176
+ * Execute the full AP2 payment: sign x402 header + bridge USDC + settle.
177
+ *
178
+ * Calls the /ap2/execute endpoint on the facilitator, which:
179
+ * 1. Parses the XML
180
+ * 2. Signs x402 header with agent's private key (server-side in this flow)
181
+ * 3. Submits USDC to CCTP V2 bridge
182
+ * 4. Returns receipt
183
+ *
184
+ * @param iso20022Xml - Raw pacs.008 XML string
185
+ * @returns AP2Receipt with txHash and SEPA reference
186
+ * @throws AP2Error on execution failure
187
+ */
188
+ async pay(iso20022Xml) {
189
+ const response = await fetch(`${this.facilitatorUrl}/ap2/execute`, {
190
+ method: 'POST',
191
+ headers: { 'Content-Type': 'application/xml' },
192
+ body: iso20022Xml,
193
+ });
194
+ if (!response.ok) {
195
+ const body = await response.text();
196
+ throw new AP2Error(`Execution failed (${response.status}): ${body}`);
197
+ }
198
+ const json = (await response.json());
199
+ const r = json.receipt;
200
+ return {
201
+ messageId: r.message_id,
202
+ txHash: r.tx_hash,
203
+ usdcBridged: usdcToBigInt(r.usdc_bridged),
204
+ sepaReference: r.sepa_reference,
205
+ status: r.status,
206
+ dryRun: r.dry_run,
207
+ x402Signature: r.x402_signature,
208
+ agentAddress: r.agent_address,
209
+ nonce: r.nonce,
210
+ executedAt: r.executed_at,
211
+ creditorIban: r.creditor_iban,
212
+ bridgeFeeUsdc: usdcToBigInt(r.bridge_fee_usdc),
213
+ };
214
+ }
215
+ /**
216
+ * Generate a valid ISO 20022 pacs.008 XML string from simple parameters.
217
+ *
218
+ * Handles XML escaping, IBAN normalization, and timestamp formatting.
219
+ * Makes AP2 payments agent-friendly — no ISO 20022 expertise required.
220
+ *
221
+ * @param params - Simple payment parameters
222
+ * @returns Valid pacs.008 XML string
223
+ */
224
+ static buildPacs008(params) {
225
+ return buildPacs008(params);
226
+ }
227
+ /**
228
+ * Estimate USDC required for a given EUR amount.
229
+ *
230
+ * Uses the default EUR/USDC rate. For accurate quotes, call quote() instead.
231
+ *
232
+ * @param amountEur - Amount in EUR
233
+ * @returns Estimated USDC amount as bigint (μUSDC, 6 decimals)
234
+ */
235
+ static estimateUsdc(amountEur) {
236
+ const usdc = amountEur * EUR_TO_USDC_RATE;
237
+ return BigInt(Math.round(usdc * Number(USDC_MULTIPLIER)));
238
+ }
239
+ }
240
+ // ---------------------------------------------------------------------------
241
+ // Error class
242
+ // ---------------------------------------------------------------------------
243
+ /** AP2-specific error with structured context. */
244
+ export class AP2Error extends Error {
245
+ constructor(message, context) {
246
+ super(message);
247
+ this.context = context;
248
+ this.name = 'AP2Error';
249
+ }
250
+ }
251
+ // ---------------------------------------------------------------------------
252
+ // Re-export builder as standalone function
253
+ // ---------------------------------------------------------------------------
254
+ export { buildPacs008 };
255
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ap2/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAiIH,8EAA8E;AAC9E,YAAY;AACZ,8EAA8E;AAE9E,wBAAwB;AACxB,MAAM,aAAa,GAAG,EAAE,CAAC;AACzB,MAAM,eAAe,GAAG,GAAG,IAAI,aAAa,CAAC;AAE7C,mEAAmE;AACnE,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAE9B,8BAA8B;AAC9B,MAAM,uBAAuB,GAAG,uBAAuB,CAAC;AAExD,kDAAkD;AAClD,MAAM,4BAA4B,GAAG,IAAI,CAAC;AAE1C,8EAA8E;AAC9E,iCAAiC;AACjC,8EAA8E;AAE9E;;;;;;GAMG;AACH,SAAS,YAAY,CAAC,MAAwB;IAC5C,MAAM,GAAG,GAAG,MAAM,CAAC,gBAAgB,IAAI,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;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