aptos-x402 2.0.2 → 2.2.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 +16 -13
- package/dist/aptos-utils.d.ts +46 -0
- package/dist/aptos-utils.d.ts.map +1 -0
- package/dist/aptos-utils.js +144 -0
- package/dist/aptos-utils.js.map +1 -0
- package/dist/arc8004/identity/agent-card.d.ts +66 -0
- package/dist/arc8004/identity/agent-card.d.ts.map +1 -0
- package/dist/arc8004/identity/agent-card.js +141 -0
- package/dist/arc8004/identity/agent-card.js.map +1 -0
- package/dist/arc8004/identity/index.d.ts +7 -0
- package/dist/arc8004/identity/index.d.ts.map +1 -0
- package/dist/arc8004/identity/index.js +7 -0
- package/dist/arc8004/identity/index.js.map +1 -0
- package/dist/arc8004/identity/registry.d.ts +60 -0
- package/dist/arc8004/identity/registry.d.ts.map +1 -0
- package/dist/arc8004/identity/registry.js +297 -0
- package/dist/arc8004/identity/registry.js.map +1 -0
- package/dist/arc8004/index.d.ts +21 -0
- package/dist/arc8004/index.d.ts.map +1 -0
- package/dist/arc8004/index.js +26 -0
- package/dist/arc8004/index.js.map +1 -0
- package/dist/arc8004/reputation/index.d.ts +7 -0
- package/dist/arc8004/reputation/index.d.ts.map +1 -0
- package/dist/arc8004/reputation/index.js +7 -0
- package/dist/arc8004/reputation/index.js.map +1 -0
- package/dist/arc8004/reputation/registry.d.ts +60 -0
- package/dist/arc8004/reputation/registry.d.ts.map +1 -0
- package/dist/arc8004/reputation/registry.js +373 -0
- package/dist/arc8004/reputation/registry.js.map +1 -0
- package/dist/arc8004/reputation/scoring.d.ts +60 -0
- package/dist/arc8004/reputation/scoring.d.ts.map +1 -0
- package/dist/arc8004/reputation/scoring.js +130 -0
- package/dist/arc8004/reputation/scoring.js.map +1 -0
- package/dist/arc8004/types.d.ts +268 -0
- package/dist/arc8004/types.d.ts.map +1 -0
- package/dist/arc8004/types.js +27 -0
- package/dist/arc8004/types.js.map +1 -0
- package/dist/arc8004/validation/index.d.ts +6 -0
- package/dist/arc8004/validation/index.d.ts.map +1 -0
- package/dist/arc8004/validation/index.js +6 -0
- package/dist/arc8004/validation/index.js.map +1 -0
- package/dist/arc8004/validation/registry.d.ts +72 -0
- package/dist/arc8004/validation/registry.d.ts.map +1 -0
- package/dist/arc8004/validation/registry.js +268 -0
- package/dist/arc8004/validation/registry.js.map +1 -0
- package/dist/components/ui/button.d.ts +1 -1
- package/dist/components/ui/button.d.ts.map +1 -1
- package/dist/components/ui/button.js +34 -0
- package/dist/components/ui/button.js.map +1 -0
- package/dist/components/ui/select.d.ts +10 -10
- package/dist/components/ui/select.d.ts.map +1 -1
- package/dist/components/ui/select.js +38 -0
- package/dist/components/ui/select.js.map +1 -0
- package/dist/db/index.d.ts +10 -0
- package/dist/db/index.d.ts.map +1 -0
- package/dist/db/index.js +27 -0
- package/dist/db/index.js.map +1 -0
- package/dist/db/schema.d.ts +2086 -0
- package/dist/db/schema.d.ts.map +1 -0
- package/dist/db/schema.js +220 -0
- package/dist/db/schema.js.map +1 -0
- package/dist/facilitator-client.d.ts +89 -0
- package/dist/facilitator-client.d.ts.map +1 -0
- package/dist/facilitator-client.js +140 -0
- package/dist/facilitator-client.js.map +1 -0
- package/dist/index.d.ts +67 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +80 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/aptos-utils.d.ts +30 -29
- package/dist/lib/aptos-utils.d.ts.map +1 -1
- package/dist/lib/aptos-utils.js +87 -105
- package/dist/lib/aptos-utils.js.map +1 -1
- package/dist/lib/facilitator-client.d.ts +1 -1
- package/dist/lib/facilitator-client.js +1 -1
- package/dist/lib/index.d.ts +16 -39
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +21 -45
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/services/geomi-gas-station.d.ts +33 -0
- package/dist/lib/services/geomi-gas-station.d.ts.map +1 -0
- package/dist/lib/services/geomi-gas-station.js +97 -0
- package/dist/lib/services/geomi-gas-station.js.map +1 -0
- package/dist/lib/x402-axios.d.ts +24 -96
- package/dist/lib/x402-axios.d.ts.map +1 -1
- package/dist/lib/x402-axios.js +198 -385
- package/dist/lib/x402-axios.js.map +1 -1
- package/dist/lib/x402-middleware.d.ts +5 -3
- package/dist/lib/x402-middleware.d.ts.map +1 -1
- package/dist/lib/x402-middleware.js +137 -161
- package/dist/lib/x402-middleware.js.map +1 -1
- package/dist/lib/x402-protocol-types.d.ts +116 -54
- package/dist/lib/x402-protocol-types.d.ts.map +1 -1
- package/dist/lib/x402-protocol-types.js +58 -7
- package/dist/lib/x402-protocol-types.js.map +1 -1
- package/dist/lib/x402-types.d.ts +66 -1
- package/dist/lib/x402-types.d.ts.map +1 -1
- package/dist/lib/x402-types.js +26 -2
- package/dist/lib/x402-types.js.map +1 -1
- package/dist/src/components/ui/shadcn-io/code-block/index.d.ts +13 -13
- package/dist/src/components/ui/shadcn-io/code-block/index.d.ts.map +1 -1
- package/dist/src/components/ui/shadcn-io/code-block/index.js +209 -0
- package/dist/src/components/ui/shadcn-io/code-block/index.js.map +1 -0
- package/dist/src/components/ui/shadcn-io/code-block/server.d.ts +1 -1
- package/dist/src/components/ui/shadcn-io/code-block/server.d.ts.map +1 -1
- package/dist/src/components/ui/shadcn-io/code-block/server.js +35 -0
- package/dist/src/components/ui/shadcn-io/code-block/server.js.map +1 -0
- package/dist/src/index.d.ts +4 -7
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +5 -15
- package/dist/src/index.js.map +1 -1
- package/dist/src/server/index.d.ts +3 -5
- package/dist/src/server/index.d.ts.map +1 -1
- package/dist/src/server/index.js +2 -5
- package/dist/src/server/index.js.map +1 -1
- package/dist/src/server/next.js +6 -6
- package/dist/src/server/next.js.map +1 -1
- package/dist/tsconfig.sdk.tsbuildinfo +1 -1
- package/dist/utils/agent-symbols.d.ts +20 -0
- package/dist/utils/agent-symbols.d.ts.map +1 -0
- package/dist/utils/agent-symbols.js +86 -0
- package/dist/utils/agent-symbols.js.map +1 -0
- package/dist/utils/server-user-id.d.ts +2 -0
- package/dist/utils/server-user-id.d.ts.map +1 -0
- package/dist/utils/server-user-id.js +9 -0
- package/dist/utils/server-user-id.js.map +1 -0
- package/dist/utils/user-id.d.ts +21 -0
- package/dist/utils/user-id.d.ts.map +1 -0
- package/dist/utils/user-id.js +102 -0
- package/dist/utils/user-id.js.map +1 -0
- package/dist/utils.d.ts +3 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +6 -0
- package/dist/utils.js.map +1 -0
- package/dist/x402-axios.d.ts +117 -0
- package/dist/x402-axios.d.ts.map +1 -0
- package/dist/x402-axios.js +425 -0
- package/dist/x402-axios.js.map +1 -0
- package/dist/x402-middleware.d.ts +9 -0
- package/dist/x402-middleware.d.ts.map +1 -0
- package/dist/x402-middleware.js +207 -0
- package/dist/x402-middleware.js.map +1 -0
- package/dist/x402-protocol-types.d.ts +115 -0
- package/dist/x402-protocol-types.d.ts.map +1 -0
- package/dist/x402-protocol-types.js +12 -0
- package/dist/x402-protocol-types.js.map +1 -0
- package/dist/x402-types.d.ts +18 -0
- package/dist/x402-types.d.ts.map +1 -0
- package/dist/x402-types.js +6 -0
- package/dist/x402-types.js.map +1 -0
- package/package.json +8 -6
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
[](https://www.typescriptlang.org/)
|
|
9
9
|
[](https://nextjs.org/)
|
|
10
10
|
|
|
11
|
-
[Documentation](https://aptos-x402.
|
|
11
|
+
[Documentation](https://aptos-x402.org/docs) • [API Reference](#api-reference) • [Demo](https://aptos-x402.org)
|
|
12
12
|
|
|
13
13
|
</div>
|
|
14
14
|
|
|
@@ -16,12 +16,15 @@
|
|
|
16
16
|
|
|
17
17
|
## Overview
|
|
18
18
|
|
|
19
|
-
**Aptos x402** is a TypeScript SDK implementing the
|
|
19
|
+
**Aptos x402** is a TypeScript SDK implementing the **x402 v2 protocol** ([spec](https://github.com/coinbase/x402)) for the Aptos blockchain. Enable your APIs to require cryptocurrency payments before serving responses using the standardized HTTP 402 status code.
|
|
20
|
+
|
|
21
|
+
> ✅ **x402 v2 compliant** | ⚠️ v1 is deprecated
|
|
20
22
|
|
|
21
23
|
Built for **machine-to-machine micropayments**, this SDK provides zero-friction payment integration for Next.js applications with automatic payment handling, cryptographic verification, and **sub-second settlement times** (optimized from 2-3s to 200-500ms).
|
|
22
24
|
|
|
23
|
-
### What’s new in 2.
|
|
25
|
+
### What’s new in 2.2.0
|
|
24
26
|
- 🛡️ **ARC-8004 Agent Trust Layer** (Aptos-native, inspired by ERC-8004): agent identities, reputation, and task validation.
|
|
27
|
+
- ⛽ **Geomi Gas Sponsorship**: Native support for gasless transactions.
|
|
25
28
|
- ✅ Frontend badges for Verified + Trust, with a verify API.
|
|
26
29
|
- 📚 Docs and API routes for ARC-8004 (identity, reputation, validation).
|
|
27
30
|
|
|
@@ -133,7 +136,7 @@ const api = x402axios.create({
|
|
|
133
136
|
baseURL: 'https://api.example.com',
|
|
134
137
|
timeout: 10000,
|
|
135
138
|
privateKey: process.env.APTOS_PRIVATE_KEY,
|
|
136
|
-
headers: { '
|
|
139
|
+
headers: { 'Client-Version': '1.0.0' }
|
|
137
140
|
});
|
|
138
141
|
|
|
139
142
|
// Use instance for all requests
|
|
@@ -165,7 +168,7 @@ Create `.env.local` in your project root:
|
|
|
165
168
|
|
|
166
169
|
```env
|
|
167
170
|
PAYMENT_RECIPIENT_ADDRESS=0xYOUR_APTOS_WALLET_ADDRESS
|
|
168
|
-
FACILITATOR_URL=https://aptos-x402.
|
|
171
|
+
FACILITATOR_URL=https://aptos-x402.org/api/facilitator
|
|
169
172
|
```
|
|
170
173
|
|
|
171
174
|
> **Getting a Wallet Address:**
|
|
@@ -608,7 +611,7 @@ async function manualPaymentFlow(url: string, privateKey: string) {
|
|
|
608
611
|
// 5. Retry with payment
|
|
609
612
|
response = await fetch(url, {
|
|
610
613
|
headers: {
|
|
611
|
-
'
|
|
614
|
+
'Payment': Buffer.from(JSON.stringify(paymentPayload)).toString('base64')
|
|
612
615
|
}
|
|
613
616
|
});
|
|
614
617
|
}
|
|
@@ -635,7 +638,7 @@ const signedTx = await signTransaction(transaction);
|
|
|
635
638
|
|
|
636
639
|
### Interactive Demo
|
|
637
640
|
|
|
638
|
-
Try the complete payment flow: **[aptos-x402.
|
|
641
|
+
Try the complete payment flow: **[aptos-x402.org](https://aptos-x402.org)**
|
|
639
642
|
|
|
640
643
|
### Example Code
|
|
641
644
|
|
|
@@ -665,7 +668,7 @@ The facilitator handles blockchain operations (verification and settlement) sepa
|
|
|
665
668
|
|
|
666
669
|
| Option | Best For | Setup |
|
|
667
670
|
|--------|----------|-------|
|
|
668
|
-
| **Public Facilitator** | Development, testing, POCs | `FACILITATOR_URL=https://aptos-x402.
|
|
671
|
+
| **Public Facilitator** | Development, testing, POCs | `FACILITATOR_URL=https://aptos-x402.org/api/facilitator` |
|
|
669
672
|
| **Self-Hosted (Same App)** | Small to medium deployments | Copy facilitator routes to your Next.js app |
|
|
670
673
|
| **Self-Hosted (Separate)** | Production, high scale | Deploy as standalone service |
|
|
671
674
|
|
|
@@ -762,9 +765,9 @@ Track payment performance with built-in timing headers:
|
|
|
762
765
|
const response = await x402axios.get(url, { privateKey });
|
|
763
766
|
|
|
764
767
|
// Check performance metrics
|
|
765
|
-
const verifyTime = response.headers['
|
|
766
|
-
const settleTime = response.headers['
|
|
767
|
-
const cached = response.headers['
|
|
768
|
+
const verifyTime = response.headers['verification-time'];
|
|
769
|
+
const settleTime = response.headers['settlement-time'];
|
|
770
|
+
const cached = response.headers['cached'] === 'true';
|
|
768
771
|
|
|
769
772
|
console.log(`Verification: ${verifyTime}ms`);
|
|
770
773
|
console.log(`Settlement: ${settleTime}ms`);
|
|
@@ -792,7 +795,7 @@ APTOS_PRIVATE_KEY=0x... npx tsx scripts/benchmark-payment-flow.ts
|
|
|
792
795
|
## Resources
|
|
793
796
|
|
|
794
797
|
### Documentation
|
|
795
|
-
- [Full Documentation](https://aptos-x402.
|
|
798
|
+
- [Full Documentation](https://aptos-x402.org/docs)
|
|
796
799
|
- [API Reference](./docs/api-reference/server-api.md)
|
|
797
800
|
- [Protocol Specification](https://github.com/coinbase/x402)
|
|
798
801
|
- [Performance Guide](./PERFORMANCE_OPTIMIZATIONS.md)
|
|
@@ -817,7 +820,7 @@ Contributions are welcome! Please feel free to submit issues, feature requests,
|
|
|
817
820
|
|
|
818
821
|
**Built for the Aptos Ecosystem**
|
|
819
822
|
|
|
820
|
-
[Documentation](https://aptos-x402.
|
|
823
|
+
[Documentation](https://aptos-x402.org) • [GitHub](https://github.com/adipundir/Aptos-x402) • [NPM](https://www.npmjs.com/package/aptos-x402)
|
|
821
824
|
|
|
822
825
|
</div>
|
|
823
826
|
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Aptos, Account } from "@aptos-labs/ts-sdk";
|
|
2
|
+
export interface TransactionPayload {
|
|
3
|
+
function: string;
|
|
4
|
+
functionArguments: any[];
|
|
5
|
+
typeArguments?: string[];
|
|
6
|
+
}
|
|
7
|
+
export interface X402PaymentRequest {
|
|
8
|
+
amount: string;
|
|
9
|
+
recipient: string;
|
|
10
|
+
network: string;
|
|
11
|
+
memo?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface X402PaymentResponse {
|
|
14
|
+
transactionHash: string;
|
|
15
|
+
sender: string;
|
|
16
|
+
amount: string;
|
|
17
|
+
recipient: string;
|
|
18
|
+
timestamp: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Initialize Aptos client based on network
|
|
22
|
+
* Supports both x402 format (aptos-testnet) and simple format (testnet)
|
|
23
|
+
* Uses custom RPC URLs from environment variables when available
|
|
24
|
+
*/
|
|
25
|
+
export declare function getAptosClient(network?: string): Aptos;
|
|
26
|
+
/**
|
|
27
|
+
* Create an Account from a private key
|
|
28
|
+
*/
|
|
29
|
+
export declare function getAccountFromPrivateKey(privateKeyHex: string): Account;
|
|
30
|
+
/**
|
|
31
|
+
* Sign and submit a simple coin transfer transaction
|
|
32
|
+
*/
|
|
33
|
+
export declare function signAndSubmitPayment(aptos: Aptos, sender: Account, recipientAddress: string, amount: string): Promise<string>;
|
|
34
|
+
/**
|
|
35
|
+
* Verify a transaction exists and matches expected parameters
|
|
36
|
+
*/
|
|
37
|
+
export declare function verifyTransaction(aptos: Aptos, transactionHash: string, expectedSender?: string, expectedRecipient?: string, expectedAmount?: string): Promise<boolean>;
|
|
38
|
+
/**
|
|
39
|
+
* Wait for a transaction to be confirmed
|
|
40
|
+
*/
|
|
41
|
+
export declare function waitForTransaction(aptos: Aptos, transactionHash: string): Promise<boolean>;
|
|
42
|
+
/**
|
|
43
|
+
* Get account balance
|
|
44
|
+
*/
|
|
45
|
+
export declare function getAccountBalance(aptos: Aptos, accountAddress: string): Promise<string>;
|
|
46
|
+
//# sourceMappingURL=aptos-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aptos-utils.d.ts","sourceRoot":"","sources":["../lib/aptos-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EAGL,OAAO,EAIR,MAAM,oBAAoB,CAAC;AAE5B,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,iBAAiB,EAAE,GAAG,EAAE,CAAC;IACzB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,mBAAmB;IAClC,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,OAAO,GAAE,MAAkB,GAAG,KAAK,CAyCjE;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAKvE;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,OAAO,EACf,gBAAgB,EAAE,MAAM,EACxB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,CAAC,CAejB;AAED;;GAEG;AACH,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,KAAK,EACZ,eAAe,EAAE,MAAM,EACvB,cAAc,CAAC,EAAE,MAAM,EACvB,iBAAiB,CAAC,EAAE,MAAM,EAC1B,cAAc,CAAC,EAAE,MAAM,GACtB,OAAO,CAAC,OAAO,CAAC,CAwClB;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,KAAK,EAAE,KAAK,EACZ,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,OAAO,CAAC,CAUlB;AAED;;GAEG;AACH,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,KAAK,EACZ,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,MAAM,CAAC,CAUjB"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { Aptos, AptosConfig, Network, Account, Ed25519PrivateKey, } from "@aptos-labs/ts-sdk";
|
|
2
|
+
/**
|
|
3
|
+
* Initialize Aptos client based on network
|
|
4
|
+
* Supports both x402 format (aptos-testnet) and simple format (testnet)
|
|
5
|
+
* Uses custom RPC URLs from environment variables when available
|
|
6
|
+
*/
|
|
7
|
+
export function getAptosClient(network = "testnet") {
|
|
8
|
+
// Map x402 network identifiers to Aptos SDK network enum
|
|
9
|
+
let aptosNetwork;
|
|
10
|
+
if (network === "aptos-mainnet" || network === "mainnet") {
|
|
11
|
+
aptosNetwork = Network.MAINNET;
|
|
12
|
+
}
|
|
13
|
+
else if (network === "aptos-testnet" || network === "testnet") {
|
|
14
|
+
aptosNetwork = Network.TESTNET;
|
|
15
|
+
}
|
|
16
|
+
else if (network === "aptos-devnet" || network === "devnet") {
|
|
17
|
+
aptosNetwork = Network.DEVNET;
|
|
18
|
+
}
|
|
19
|
+
else if (network.startsWith("aptos-")) {
|
|
20
|
+
// Strip "aptos-" prefix and use as network
|
|
21
|
+
aptosNetwork = network.replace("aptos-", "").toLowerCase();
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
aptosNetwork = network.toLowerCase();
|
|
25
|
+
}
|
|
26
|
+
// Check for custom RPC URLs from environment variables
|
|
27
|
+
let config;
|
|
28
|
+
let rpcUrl;
|
|
29
|
+
// Map network to corresponding environment variable
|
|
30
|
+
if (aptosNetwork === Network.MAINNET && process.env.APTOS_MAINNET_NODE_URL) {
|
|
31
|
+
rpcUrl = process.env.APTOS_MAINNET_NODE_URL;
|
|
32
|
+
}
|
|
33
|
+
else if (aptosNetwork === Network.TESTNET && process.env.APTOS_TESTNET_NODE_URL) {
|
|
34
|
+
rpcUrl = process.env.APTOS_TESTNET_NODE_URL;
|
|
35
|
+
}
|
|
36
|
+
else if (aptosNetwork === Network.DEVNET && process.env.APTOS_DEVNET_NODE_URL) {
|
|
37
|
+
rpcUrl = process.env.APTOS_DEVNET_NODE_URL;
|
|
38
|
+
}
|
|
39
|
+
if (rpcUrl) {
|
|
40
|
+
config = new AptosConfig({
|
|
41
|
+
network: aptosNetwork,
|
|
42
|
+
fullnode: rpcUrl
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
// Use default Aptos Labs RPC endpoints
|
|
47
|
+
config = new AptosConfig({ network: aptosNetwork });
|
|
48
|
+
}
|
|
49
|
+
return new Aptos(config);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Create an Account from a private key
|
|
53
|
+
*/
|
|
54
|
+
export function getAccountFromPrivateKey(privateKeyHex) {
|
|
55
|
+
// Remove '0x' prefix if present
|
|
56
|
+
const cleanKey = privateKeyHex.replace(/^0x/, "");
|
|
57
|
+
const privateKey = new Ed25519PrivateKey(cleanKey);
|
|
58
|
+
return Account.fromPrivateKey({ privateKey });
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Sign and submit a simple coin transfer transaction
|
|
62
|
+
*/
|
|
63
|
+
export async function signAndSubmitPayment(aptos, sender, recipientAddress, amount) {
|
|
64
|
+
const transaction = await aptos.transaction.build.simple({
|
|
65
|
+
sender: sender.accountAddress,
|
|
66
|
+
data: {
|
|
67
|
+
function: "0x1::aptos_account::transfer",
|
|
68
|
+
functionArguments: [recipientAddress, amount],
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
const committedTxn = await aptos.signAndSubmitTransaction({
|
|
72
|
+
signer: sender,
|
|
73
|
+
transaction,
|
|
74
|
+
});
|
|
75
|
+
return committedTxn.hash;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Verify a transaction exists and matches expected parameters
|
|
79
|
+
*/
|
|
80
|
+
export async function verifyTransaction(aptos, transactionHash, expectedSender, expectedRecipient, expectedAmount) {
|
|
81
|
+
try {
|
|
82
|
+
const txn = await aptos.transaction.getTransactionByHash({
|
|
83
|
+
transactionHash,
|
|
84
|
+
});
|
|
85
|
+
// Check if transaction is committed and successful
|
|
86
|
+
if (!('success' in txn) || !txn.success) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
// Basic verification - transaction exists and succeeded
|
|
90
|
+
if (!expectedSender && !expectedRecipient && !expectedAmount) {
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
// Additional verification if parameters provided
|
|
94
|
+
const payload = txn.payload;
|
|
95
|
+
if (payload?.function === "0x1::aptos_account::transfer") {
|
|
96
|
+
const args = payload.arguments;
|
|
97
|
+
if (expectedRecipient && args[0] !== expectedRecipient) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
if (expectedAmount && args[1] !== expectedAmount) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (expectedSender && txn.sender !== expectedSender) {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
console.error("Error verifying transaction:", error);
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Wait for a transaction to be confirmed
|
|
116
|
+
*/
|
|
117
|
+
export async function waitForTransaction(aptos, transactionHash) {
|
|
118
|
+
try {
|
|
119
|
+
await aptos.waitForTransaction({
|
|
120
|
+
transactionHash,
|
|
121
|
+
});
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
console.error("Error waiting for transaction:", error);
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Get account balance
|
|
131
|
+
*/
|
|
132
|
+
export async function getAccountBalance(aptos, accountAddress) {
|
|
133
|
+
try {
|
|
134
|
+
const balance = await aptos.getAccountAPTAmount({
|
|
135
|
+
accountAddress,
|
|
136
|
+
});
|
|
137
|
+
return balance.toString();
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
console.error("Error getting account balance:", error);
|
|
141
|
+
return "0";
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=aptos-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aptos-utils.js","sourceRoot":"","sources":["../lib/aptos-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,WAAW,EACX,OAAO,EACP,OAAO,EACP,iBAAiB,GAGlB,MAAM,oBAAoB,CAAC;AAuB5B;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,UAAkB,SAAS;IACxD,yDAAyD;IACzD,IAAI,YAAqB,CAAC;IAE1B,IAAI,OAAO,KAAK,eAAe,IAAI,O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CAAC;QACvD,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,KAAY,EACZ,cAAsB;IAEtB,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,mBAAmB,CAAC;YAC9C,cAAc;SACf,CAAC,CAAC;QACH,OAAO,OAAO,CAAC,QAAQ,EAAE,CAAC;IAC5B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,gCAAgC,EAAE,KAAK,CAAC,CAAC;QACvD,OAAO,GAAG,CAAC;IACb,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Card Utilities
|
|
3
|
+
* Helpers for creating and validating Agent Cards
|
|
4
|
+
*/
|
|
5
|
+
import type { AgentCard } from '../types';
|
|
6
|
+
/**
|
|
7
|
+
* ARC-8004 protocol version for Agent Cards
|
|
8
|
+
*/
|
|
9
|
+
export declare const AGENT_CARD_VERSION = "1.0.0";
|
|
10
|
+
/**
|
|
11
|
+
* Default capabilities for agents
|
|
12
|
+
*/
|
|
13
|
+
export declare const DEFAULT_CAPABILITIES: string[];
|
|
14
|
+
/**
|
|
15
|
+
* Default protocols supported
|
|
16
|
+
*/
|
|
17
|
+
export declare const DEFAULT_PROTOCOLS: string[];
|
|
18
|
+
/**
|
|
19
|
+
* Default supported networks
|
|
20
|
+
*/
|
|
21
|
+
export declare const DEFAULT_NETWORKS: string[];
|
|
22
|
+
/**
|
|
23
|
+
* Create a new Agent Card with defaults
|
|
24
|
+
*/
|
|
25
|
+
export declare function createAgentCard(params: {
|
|
26
|
+
name: string;
|
|
27
|
+
description: string;
|
|
28
|
+
ownerAddress: string;
|
|
29
|
+
ownerPublicKey: string;
|
|
30
|
+
capabilities?: string[];
|
|
31
|
+
protocols?: string[];
|
|
32
|
+
supportedNetworks?: string[];
|
|
33
|
+
endpoints?: {
|
|
34
|
+
api?: string;
|
|
35
|
+
webhook?: string;
|
|
36
|
+
};
|
|
37
|
+
metadata?: Record<string, unknown>;
|
|
38
|
+
}): AgentCard;
|
|
39
|
+
/**
|
|
40
|
+
* Validation errors for Agent Card
|
|
41
|
+
*/
|
|
42
|
+
export interface AgentCardValidationError {
|
|
43
|
+
field: string;
|
|
44
|
+
message: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Validate an Agent Card
|
|
48
|
+
*/
|
|
49
|
+
export declare function validateAgentCard(agentCard: AgentCard): {
|
|
50
|
+
valid: boolean;
|
|
51
|
+
errors: AgentCardValidationError[];
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Generate metadata URI for on-chain storage
|
|
55
|
+
* Returns a hash-based URI for the agent card
|
|
56
|
+
*/
|
|
57
|
+
export declare function generateMetadataUri(agentCard: AgentCard): string;
|
|
58
|
+
/**
|
|
59
|
+
* Parse metadata URI to extract agent card
|
|
60
|
+
*/
|
|
61
|
+
export declare function parseMetadataUri(uri: string): AgentCard | null;
|
|
62
|
+
/**
|
|
63
|
+
* Merge agent card updates with existing card
|
|
64
|
+
*/
|
|
65
|
+
export declare function updateAgentCard(existing: AgentCard, updates: Partial<Omit<AgentCard, 'owner' | 'version'>>): AgentCard;
|
|
66
|
+
//# sourceMappingURL=agent-card.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-card.d.ts","sourceRoot":"","sources":["../../../lib/arc8004/identity/agent-card.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE1C;;GAEG;AACH,eAAO,MAAM,kBAAkB,UAAU,CAAC;AAE1C;;GAEG;AACH,eAAO,MAAM,oBAAoB,UAA4B,CAAC;AAE9D;;GAEG;AACH,eAAO,MAAM,iBAAiB,UAAmB,CAAC;AAElD;;GAEG;AACH,eAAO,MAAM,gBAAgB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
* ARC-8004 protocol version for Agent Cards
|
|
7
|
+
*/
|
|
8
|
+
export const AGENT_CARD_VERSION = '1.0.0';
|
|
9
|
+
/**
|
|
10
|
+
* Default capabilities for agents
|
|
11
|
+
*/
|
|
12
|
+
export const DEFAULT_CAPABILITIES = ['payment', 'data-fetch'];
|
|
13
|
+
/**
|
|
14
|
+
* Default protocols supported
|
|
15
|
+
*/
|
|
16
|
+
export const DEFAULT_PROTOCOLS = ['x402', 'http'];
|
|
17
|
+
/**
|
|
18
|
+
* Default supported networks
|
|
19
|
+
*/
|
|
20
|
+
export const DEFAULT_NETWORKS = ['aptos-testnet'];
|
|
21
|
+
/**
|
|
22
|
+
* Create a new Agent Card with defaults
|
|
23
|
+
*/
|
|
24
|
+
export function createAgentCard(params) {
|
|
25
|
+
return {
|
|
26
|
+
name: params.name,
|
|
27
|
+
description: params.description,
|
|
28
|
+
version: AGENT_CARD_VERSION,
|
|
29
|
+
capabilities: params.capabilities || DEFAULT_CAPABILITIES,
|
|
30
|
+
protocols: params.protocols || DEFAULT_PROTOCOLS,
|
|
31
|
+
supportedNetworks: params.supportedNetworks || DEFAULT_NETWORKS,
|
|
32
|
+
endpoints: params.endpoints,
|
|
33
|
+
owner: {
|
|
34
|
+
address: params.ownerAddress,
|
|
35
|
+
publicKey: params.ownerPublicKey,
|
|
36
|
+
},
|
|
37
|
+
metadata: params.metadata,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Validate an Agent Card
|
|
42
|
+
*/
|
|
43
|
+
export function validateAgentCard(agentCard) {
|
|
44
|
+
const errors = [];
|
|
45
|
+
// Required fields
|
|
46
|
+
if (!agentCard.name || agentCard.name.trim().length === 0) {
|
|
47
|
+
errors.push({ field: 'name', message: 'Name is required' });
|
|
48
|
+
}
|
|
49
|
+
if (!agentCard.description || agentCard.description.trim().length === 0) {
|
|
50
|
+
errors.push({ field: 'description', message: 'Description is required' });
|
|
51
|
+
}
|
|
52
|
+
if (!agentCard.version) {
|
|
53
|
+
errors.push({ field: 'version', message: 'Version is required' });
|
|
54
|
+
}
|
|
55
|
+
// Owner validation
|
|
56
|
+
if (!agentCard.owner) {
|
|
57
|
+
errors.push({ field: 'owner', message: 'Owner information is required' });
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
if (!agentCard.owner.address) {
|
|
61
|
+
errors.push({ field: 'owner.address', message: 'Owner address is required' });
|
|
62
|
+
}
|
|
63
|
+
else if (!isValidAptosAddress(agentCard.owner.address)) {
|
|
64
|
+
errors.push({ field: 'owner.address', message: 'Invalid Aptos address format' });
|
|
65
|
+
}
|
|
66
|
+
if (!agentCard.owner.publicKey) {
|
|
67
|
+
errors.push({ field: 'owner.publicKey', message: 'Owner public key is required' });
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// Capabilities validation
|
|
71
|
+
if (!agentCard.capabilities || !Array.isArray(agentCard.capabilities)) {
|
|
72
|
+
errors.push({ field: 'capabilities', message: 'Capabilities must be an array' });
|
|
73
|
+
}
|
|
74
|
+
else if (agentCard.capabilities.length === 0) {
|
|
75
|
+
errors.push({ field: 'capabilities', message: 'At least one capability is required' });
|
|
76
|
+
}
|
|
77
|
+
// Protocols validation
|
|
78
|
+
if (!agentCard.protocols || !Array.isArray(agentCard.protocols)) {
|
|
79
|
+
errors.push({ field: 'protocols', message: 'Protocols must be an array' });
|
|
80
|
+
}
|
|
81
|
+
else if (agentCard.protocols.length === 0) {
|
|
82
|
+
errors.push({ field: 'protocols', message: 'At least one protocol is required' });
|
|
83
|
+
}
|
|
84
|
+
// Networks validation
|
|
85
|
+
if (!agentCard.supportedNetworks || !Array.isArray(agentCard.supportedNetworks)) {
|
|
86
|
+
errors.push({ field: 'supportedNetworks', message: 'Supported networks must be an array' });
|
|
87
|
+
}
|
|
88
|
+
else if (agentCard.supportedNetworks.length === 0) {
|
|
89
|
+
errors.push({ field: 'supportedNetworks', message: 'At least one network is required' });
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
valid: errors.length === 0,
|
|
93
|
+
errors,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Check if a string is a valid Aptos address
|
|
98
|
+
*/
|
|
99
|
+
function isValidAptosAddress(address) {
|
|
100
|
+
// Aptos addresses are 64 hex characters with optional 0x prefix
|
|
101
|
+
const cleanAddress = address.startsWith('0x') ? address.slice(2) : address;
|
|
102
|
+
return /^[0-9a-fA-F]{1,64}$/.test(cleanAddress);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Generate metadata URI for on-chain storage
|
|
106
|
+
* Returns a hash-based URI for the agent card
|
|
107
|
+
*/
|
|
108
|
+
export function generateMetadataUri(agentCard) {
|
|
109
|
+
const data = JSON.stringify(agentCard);
|
|
110
|
+
const hash = Buffer.from(data).toString('base64url');
|
|
111
|
+
return `arc8004://${hash}`;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Parse metadata URI to extract agent card
|
|
115
|
+
*/
|
|
116
|
+
export function parseMetadataUri(uri) {
|
|
117
|
+
if (!uri.startsWith('arc8004://')) {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
try {
|
|
121
|
+
const hash = uri.slice('arc8004://'.length);
|
|
122
|
+
const data = Buffer.from(hash, 'base64url').toString();
|
|
123
|
+
return JSON.parse(data);
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Merge agent card updates with existing card
|
|
131
|
+
*/
|
|
132
|
+
export function updateAgentCard(existing, updates) {
|
|
133
|
+
return {
|
|
134
|
+
...existing,
|
|
135
|
+
...updates,
|
|
136
|
+
// Preserve owner and version
|
|
137
|
+
owner: existing.owner,
|
|
138
|
+
version: existing.version,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=agent-card.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
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;AACJ,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ARC-8004 Identity Module
|
|
3
|
+
* Agent identity management with on-chain NFT support
|
|
4
|
+
*/
|
|
5
|
+
export { IdentityRegistry } from './registry';
|
|
6
|
+
export { createAgentCard, validateAgentCard, generateMetadataUri, parseMetadataUri, updateAgentCard, AGENT_CARD_VERSION, DEFAULT_CAPABILITIES, DEFAULT_PROTOCOLS, DEFAULT_NETWORKS, } from './agent-card';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/arc8004/identity/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,EAChB,eAAe,EACf,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ARC-8004 Identity Module
|
|
3
|
+
* Agent identity management with on-chain NFT support
|
|
4
|
+
*/
|
|
5
|
+
export { IdentityRegistry } from './registry';
|
|
6
|
+
export { createAgentCard, validateAgentCard, generateMetadataUri, parseMetadataUri, updateAgentCard, AGENT_CARD_VERSION, DEFAULT_CAPABILITIES, DEFAULT_PROTOCOLS, DEFAULT_NETWORKS, } from './agent-card';
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../lib/arc8004/identity/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,EAChB,eAAe,EACf,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ARC-8004 Identity Registry
|
|
3
|
+
* Manages on-chain agent identities using Aptos Digital Assets
|
|
4
|
+
*/
|
|
5
|
+
import { Account } from '@aptos-labs/ts-sdk';
|
|
6
|
+
import type { AgentCard, AgentIdentity, RegisterIdentityRequest, RegisterIdentityResponse, ARC8004Config } from '../types';
|
|
7
|
+
/**
|
|
8
|
+
* ARC-8004 Identity Registry
|
|
9
|
+
* Manages agent identities with optional on-chain NFT minting
|
|
10
|
+
*/
|
|
11
|
+
export declare class IdentityRegistry {
|
|
12
|
+
private aptos;
|
|
13
|
+
private network;
|
|
14
|
+
private moduleAddress;
|
|
15
|
+
private config;
|
|
16
|
+
constructor(config?: Partial<ARC8004Config>);
|
|
17
|
+
/**
|
|
18
|
+
* Register a new agent identity
|
|
19
|
+
*/
|
|
20
|
+
registerIdentity(request: RegisterIdentityRequest): Promise<RegisterIdentityResponse>;
|
|
21
|
+
/**
|
|
22
|
+
* Mint identity NFT on-chain (requires signer)
|
|
23
|
+
*/
|
|
24
|
+
mintIdentityOnChain(agentId: string, signer: Account): Promise<{
|
|
25
|
+
tokenAddress: string;
|
|
26
|
+
transactionHash: string;
|
|
27
|
+
}>;
|
|
28
|
+
/**
|
|
29
|
+
* Resolve agent identity by agent ID
|
|
30
|
+
*/
|
|
31
|
+
resolveIdentity(agentId: string): Promise<AgentIdentity | null>;
|
|
32
|
+
/**
|
|
33
|
+
* Resolve identity by wallet address
|
|
34
|
+
*/
|
|
35
|
+
resolveIdentityByAddress(walletAddress: string): Promise<AgentIdentity | null>;
|
|
36
|
+
/**
|
|
37
|
+
* Update agent card metadata
|
|
38
|
+
*/
|
|
39
|
+
updateAgentCard(agentId: string, updates: Partial<Omit<AgentCard, 'owner' | 'version'>>): Promise<AgentIdentity>;
|
|
40
|
+
/**
|
|
41
|
+
* Verify an agent's identity (admin function)
|
|
42
|
+
*/
|
|
43
|
+
verifyIdentity(agentId: string, verifiedBy: string): Promise<AgentIdentity>;
|
|
44
|
+
/**
|
|
45
|
+
* Verify identity exists on-chain
|
|
46
|
+
*/
|
|
47
|
+
verifyIdentityOnChain(tokenAddress: string): Promise<boolean>;
|
|
48
|
+
/**
|
|
49
|
+
* Delete an agent identity
|
|
50
|
+
*/
|
|
51
|
+
deleteIdentity(agentId: string): Promise<boolean>;
|
|
52
|
+
/**
|
|
53
|
+
* List all identities (with optional filters)
|
|
54
|
+
*/
|
|
55
|
+
listIdentities(options?: {
|
|
56
|
+
verified?: boolean;
|
|
57
|
+
limit?: number;
|
|
58
|
+
}): Promise<AgentIdentity[]>;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../lib/arc8004/identity/registry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAS,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAKpD,OAAO,KAAK,EACV,SAAS,EACT,aAAa,EACb,uBAAuB,EACvB,wBAAwB,EACxB,aAAa,EACd,MAAM,UAAU,CAAC;AAWlB;;;GAGG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,KAAK,CAAQ;IACrB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,MAAM,CAAgB;gBAElB,MAAM,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC;IAO3C;;OAEG;IACG,gBAAgB,CACpB,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,wBAAwB,CAAC;IAyDpC;;OAEG;IACG,mBAAmB,CACvB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,OAAO,GACd,OAAO,CAAC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