aptos-x402 3.0.0 → 3.0.2
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/dist/lib/aptos-utils.d.ts +47 -0
- package/dist/lib/aptos-utils.d.ts.map +1 -0
- package/dist/lib/aptos-utils.js +120 -0
- package/dist/lib/aptos-utils.js.map +1 -0
- package/dist/lib/arc8004/chain/index.d.ts +10 -0
- package/dist/lib/arc8004/chain/index.d.ts.map +1 -0
- package/dist/lib/arc8004/chain/index.js +9 -0
- package/dist/lib/arc8004/chain/index.js.map +1 -0
- package/dist/lib/arc8004/chain/types.d.ts +190 -0
- package/dist/lib/arc8004/chain/types.d.ts.map +1 -0
- package/dist/lib/arc8004/chain/types.js +278 -0
- package/dist/lib/arc8004/chain/types.js.map +1 -0
- package/dist/lib/arc8004/identity/agent-card.d.ts +66 -0
- package/dist/lib/arc8004/identity/agent-card.d.ts.map +1 -0
- package/dist/lib/arc8004/identity/agent-card.js +141 -0
- package/dist/lib/arc8004/identity/agent-card.js.map +1 -0
- package/dist/lib/arc8004/index.d.ts +39 -0
- package/dist/lib/arc8004/index.d.ts.map +1 -0
- package/dist/lib/arc8004/index.js +43 -0
- package/dist/lib/arc8004/index.js.map +1 -0
- package/dist/lib/arc8004/reputation/scoring.d.ts +60 -0
- package/dist/lib/arc8004/reputation/scoring.d.ts.map +1 -0
- package/dist/lib/arc8004/reputation/scoring.js +130 -0
- package/dist/lib/arc8004/reputation/scoring.js.map +1 -0
- package/dist/lib/arc8004/storage/index.d.ts +39 -0
- package/dist/lib/arc8004/storage/index.d.ts.map +1 -0
- package/dist/lib/arc8004/storage/index.js +69 -0
- package/dist/lib/arc8004/storage/index.js.map +1 -0
- package/dist/lib/arc8004/storage/memory.d.ts +114 -0
- package/dist/lib/arc8004/storage/memory.d.ts.map +1 -0
- package/dist/lib/arc8004/storage/memory.js +458 -0
- package/dist/lib/arc8004/storage/memory.js.map +1 -0
- package/dist/lib/arc8004/storage/types.d.ts +201 -0
- package/dist/lib/arc8004/storage/types.d.ts.map +1 -0
- package/dist/lib/arc8004/storage/types.js +12 -0
- package/dist/lib/arc8004/storage/types.js.map +1 -0
- package/dist/lib/arc8004/types.d.ts +323 -0
- package/dist/lib/arc8004/types.d.ts.map +1 -0
- package/dist/lib/arc8004/types.js +75 -0
- package/dist/lib/arc8004/types.js.map +1 -0
- package/dist/lib/index.d.ts +44 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +56 -0
- package/dist/lib/index.js.map +1 -0
- 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/utils.d.ts +3 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/lib/utils.js +6 -0
- package/dist/lib/utils.js.map +1 -0
- package/dist/lib/x402-axios.d.ts +45 -0
- package/dist/lib/x402-axios.d.ts.map +1 -0
- package/dist/lib/x402-axios.js +262 -0
- package/dist/lib/x402-axios.js.map +1 -0
- package/dist/lib/x402-middleware.d.ts +11 -0
- package/dist/lib/x402-middleware.d.ts.map +1 -0
- package/dist/lib/x402-middleware.js +191 -0
- package/dist/lib/x402-middleware.js.map +1 -0
- package/dist/lib/x402-protocol-types.d.ts +178 -0
- package/dist/lib/x402-protocol-types.d.ts.map +1 -0
- package/dist/lib/x402-protocol-types.js +64 -0
- package/dist/lib/x402-protocol-types.js.map +1 -0
- package/dist/lib/x402-types.d.ts +83 -0
- package/dist/lib/x402-types.d.ts.map +1 -0
- package/dist/lib/x402-types.js +30 -0
- package/dist/lib/x402-types.js.map +1 -0
- package/dist/src/arc8004/client.d.ts +313 -0
- package/dist/src/arc8004/client.d.ts.map +1 -0
- package/dist/src/arc8004/client.js +586 -0
- package/dist/src/arc8004/client.js.map +1 -0
- package/dist/src/arc8004/index.d.ts +54 -0
- package/dist/src/arc8004/index.d.ts.map +1 -0
- package/dist/src/arc8004/index.js +57 -0
- package/dist/src/arc8004/index.js.map +1 -0
- package/dist/src/index.d.ts +11 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +13 -0
- package/dist/src/index.js.map +1 -0
- package/dist/tsconfig.sdk.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/components/ui/button.d.ts +0 -11
- package/dist/components/ui/button.d.ts.map +0 -1
- package/dist/components/ui/button.js +0 -34
- package/dist/components/ui/button.js.map +0 -1
- package/dist/components/ui/button.jsx +0 -34
- package/dist/components/ui/button.jsx.map +0 -1
- package/dist/components/ui/select.d.ts +0 -16
- package/dist/components/ui/select.d.ts.map +0 -1
- package/dist/components/ui/select.js +0 -38
- package/dist/components/ui/select.js.map +0 -1
- package/dist/components/ui/select.jsx +0 -62
- package/dist/components/ui/select.jsx.map +0 -1
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Aptos Utilities for x402
|
|
3
|
+
*
|
|
4
|
+
* Utilities for building, signing, and submitting Aptos transactions.
|
|
5
|
+
*/
|
|
6
|
+
import { Aptos, Account, SimpleTransaction, AccountAuthenticator } from "@aptos-labs/ts-sdk";
|
|
7
|
+
export interface FeePayerTransactionResult {
|
|
8
|
+
transaction: SimpleTransaction;
|
|
9
|
+
senderAuthenticator: AccountAuthenticator;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Get Aptos client based on network (CAIP-2 format)
|
|
13
|
+
*/
|
|
14
|
+
export declare function getAptosClient(network?: string): Aptos;
|
|
15
|
+
/**
|
|
16
|
+
* Create an Account from a private key
|
|
17
|
+
*/
|
|
18
|
+
export declare function getAccountFromPrivateKey(privateKeyHex: string): Account;
|
|
19
|
+
/**
|
|
20
|
+
* Build a sponsored fungible asset transfer transaction
|
|
21
|
+
*/
|
|
22
|
+
export declare function buildFeePayerFATransfer(aptos: Aptos, sender: Account, recipient: string, amount: string | bigint, assetMetadata: string): Promise<SimpleTransaction>;
|
|
23
|
+
/**
|
|
24
|
+
* Sign a transaction as the sender
|
|
25
|
+
*/
|
|
26
|
+
export declare function signAsSender(aptos: Aptos, signer: Account, transaction: SimpleTransaction): AccountAuthenticator;
|
|
27
|
+
/**
|
|
28
|
+
* Submit a transaction with sender signature
|
|
29
|
+
*/
|
|
30
|
+
export declare function submitTransaction(aptos: Aptos, transaction: SimpleTransaction, senderAuthenticator: AccountAuthenticator): Promise<string>;
|
|
31
|
+
/**
|
|
32
|
+
* Get fungible asset balance
|
|
33
|
+
*/
|
|
34
|
+
export declare function getFungibleAssetBalance(aptos: Aptos, accountAddress: string, assetMetadata: string): Promise<string>;
|
|
35
|
+
/**
|
|
36
|
+
* Check if an account exists on chain
|
|
37
|
+
*/
|
|
38
|
+
export declare function accountExists(aptos: Aptos, accountAddress: string): Promise<boolean>;
|
|
39
|
+
/**
|
|
40
|
+
* Get chain ID from CAIP-2 network
|
|
41
|
+
*/
|
|
42
|
+
export declare function getChainId(network: string): number;
|
|
43
|
+
/**
|
|
44
|
+
* Get CAIP-2 network from chain ID
|
|
45
|
+
*/
|
|
46
|
+
export declare function getNetworkFromChainId(chainId: number): string;
|
|
47
|
+
//# 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;;;;GAIG;AAEH,OAAO,EACL,KAAK,EAGL,OAAO,EAEP,iBAAiB,EACjB,oBAAoB,EACrB,MAAM,oBAAoB,CAAC;AAQ5B,MAAM,WAAW,yBAAyB;IACxC,WAAW,EAAE,iBAAiB,CAAC;IAC/B,mBAAmB,EAAE,oBAAoB,CAAC;CAC3C;AAMD;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,GAAE,MAAkB,GAAG,KAAK,CAKjE;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAGvE;AAMD;;GAEG;AACH,wBAAsB,uBAAuB,CAC3C,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,OAAO,EACf,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,iBAAiB,CAAC,CAU5B;AAMD;;GAEG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,OAAO,EACf,WAAW,EAAE,iBAAiB,GAC7B,oBAAoB,CAEtB;AAMD;;GAEG;AACH,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,KAAK,EACZ,WAAW,EAAE,iBAAiB,EAC9B,mBAAmB,EAAE,oBAAoB,GACxC,OAAO,CAAC,MAAM,CAAC,CAMjB;AAMD;;GAEG;AACH,wBAAsB,uBAAuB,CAC3C,KAAK,EAAE,KAAK,EACZ,cAAc,EAAE,MAAM,EACtB,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,MAAM,CAAC,CAcjB;AAED;;GAEG;AACH,wBAAsB,aAAa,CACjC,KAAK,EAAE,KAAK,EACZ,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,OAAO,CAAC,CAOlB;AAMD;;GAEG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAOlD;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAE7D"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Aptos Utilities for x402
|
|
3
|
+
*
|
|
4
|
+
* Utilities for building, signing, and submitting Aptos transactions.
|
|
5
|
+
*/
|
|
6
|
+
import { Aptos, AptosConfig, Network, Account, Ed25519PrivateKey, } from "@aptos-labs/ts-sdk";
|
|
7
|
+
import { parseCAIP2Network } from "./x402-protocol-types";
|
|
8
|
+
// ============================================
|
|
9
|
+
// CLIENT MANAGEMENT
|
|
10
|
+
// ============================================
|
|
11
|
+
/**
|
|
12
|
+
* Get Aptos client based on network (CAIP-2 format)
|
|
13
|
+
*/
|
|
14
|
+
export function getAptosClient(network = "aptos:2") {
|
|
15
|
+
const parsed = parseCAIP2Network(network);
|
|
16
|
+
const aptosNetwork = parsed?.chainId === '1' ? Network.MAINNET : Network.TESTNET;
|
|
17
|
+
return new Aptos(new AptosConfig({ network: aptosNetwork }));
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Create an Account from a private key
|
|
21
|
+
*/
|
|
22
|
+
export function getAccountFromPrivateKey(privateKeyHex) {
|
|
23
|
+
const cleanKey = privateKeyHex.replace(/^0x/, "");
|
|
24
|
+
return Account.fromPrivateKey({ privateKey: new Ed25519PrivateKey(cleanKey) });
|
|
25
|
+
}
|
|
26
|
+
// ============================================
|
|
27
|
+
// TRANSACTION BUILDING (Fungible Assets Only)
|
|
28
|
+
// ============================================
|
|
29
|
+
/**
|
|
30
|
+
* Build a sponsored fungible asset transfer transaction
|
|
31
|
+
*/
|
|
32
|
+
export async function buildFeePayerFATransfer(aptos, sender, recipient, amount, assetMetadata) {
|
|
33
|
+
return await aptos.transaction.build.simple({
|
|
34
|
+
sender: sender.accountAddress,
|
|
35
|
+
withFeePayer: true,
|
|
36
|
+
data: {
|
|
37
|
+
function: "0x1::primary_fungible_store::transfer",
|
|
38
|
+
typeArguments: ["0x1::fungible_asset::Metadata"],
|
|
39
|
+
functionArguments: [assetMetadata, recipient, BigInt(amount.toString())],
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
// ============================================
|
|
44
|
+
// TRANSACTION SIGNING
|
|
45
|
+
// ============================================
|
|
46
|
+
/**
|
|
47
|
+
* Sign a transaction as the sender
|
|
48
|
+
*/
|
|
49
|
+
export function signAsSender(aptos, signer, transaction) {
|
|
50
|
+
return aptos.transaction.sign({ signer, transaction });
|
|
51
|
+
}
|
|
52
|
+
// ============================================
|
|
53
|
+
// TRANSACTION SUBMISSION
|
|
54
|
+
// ============================================
|
|
55
|
+
/**
|
|
56
|
+
* Submit a transaction with sender signature
|
|
57
|
+
*/
|
|
58
|
+
export async function submitTransaction(aptos, transaction, senderAuthenticator) {
|
|
59
|
+
const committed = await aptos.transaction.submit.simple({
|
|
60
|
+
transaction,
|
|
61
|
+
senderAuthenticator,
|
|
62
|
+
});
|
|
63
|
+
return committed.hash;
|
|
64
|
+
}
|
|
65
|
+
// ============================================
|
|
66
|
+
// ACCOUNT UTILITIES
|
|
67
|
+
// ============================================
|
|
68
|
+
/**
|
|
69
|
+
* Get fungible asset balance
|
|
70
|
+
*/
|
|
71
|
+
export async function getFungibleAssetBalance(aptos, accountAddress, assetMetadata) {
|
|
72
|
+
try {
|
|
73
|
+
const balances = await aptos.getCurrentFungibleAssetBalances({
|
|
74
|
+
options: {
|
|
75
|
+
where: {
|
|
76
|
+
owner_address: { _eq: accountAddress },
|
|
77
|
+
asset_type: { _eq: assetMetadata },
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
return balances.length > 0 ? balances[0].amount.toString() : "0";
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return "0";
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Check if an account exists on chain
|
|
89
|
+
*/
|
|
90
|
+
export async function accountExists(aptos, accountAddress) {
|
|
91
|
+
try {
|
|
92
|
+
await aptos.getAccountInfo({ accountAddress });
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// ============================================
|
|
100
|
+
// NETWORK UTILITIES
|
|
101
|
+
// ============================================
|
|
102
|
+
/**
|
|
103
|
+
* Get chain ID from CAIP-2 network
|
|
104
|
+
*/
|
|
105
|
+
export function getChainId(network) {
|
|
106
|
+
const parsed = parseCAIP2Network(network);
|
|
107
|
+
if (parsed?.chainId) {
|
|
108
|
+
const id = parseInt(parsed.chainId, 10);
|
|
109
|
+
if (!isNaN(id))
|
|
110
|
+
return id;
|
|
111
|
+
}
|
|
112
|
+
return 2; // Default testnet
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Get CAIP-2 network from chain ID
|
|
116
|
+
*/
|
|
117
|
+
export function getNetworkFromChainId(chainId) {
|
|
118
|
+
return `aptos:${chainId}`;
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=aptos-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aptos-utils.js","sourceRoot":"","sources":["../../lib/aptos-utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,KAAK,EACL,WAAW,EACX,OAAO,EACP,OAAO,EACP,iBAAiB,GAGlB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAW1D,+CAA+C;AAC/C,oBAAoB;AACpB,+CAA+C;AAE/C;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,UAAkB,SAAS;IACxD,MAAM,MAAM,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAC1C,MAAM,YAAY,GAAG,MAAM,EAAE,OAAO,KAAK,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC;IAEjF,OAAO,IAAI,KAAK,CAAC,IAAI,WAAW,CAAC,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC;AAC/D,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,wBAAwB,CAAC,aAAqB;IAC5D,MAAM,QAAQ,GAAG,aAAa,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAClD,OAAO,OAAO,CAAC,cAAc,CAAC,EAAE,UAAU,EAAE,IAAI,iBAAiB,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;AACjF,CAAC;AAED,+C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*
|
|
4
|
+
* Provides on-chain provider abstraction for blockchain operations
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
export type { OnChainProvider, MintIdentityResult, VerifyIdentityResult, AttestationResult, OnChainAgentScore, } from './types';
|
|
9
|
+
export { NullOnChainProvider, AptosOnChainProvider, createOnChainProvider, } from './types';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../lib/arc8004/chain/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,YAAY,EACV,eAAe,EACf,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ARC-8004 On-Chain Module
|
|
3
|
+
*
|
|
4
|
+
* Provides on-chain provider abstraction for blockchain operations
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
export { NullOnChainProvider, AptosOnChainProvider, createOnChainProvider, } from './types';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../lib/arc8004/chain/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAUH,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ARC-8004 On-Chain Provider Interface
|
|
3
|
+
*
|
|
4
|
+
* Abstracts blockchain operations for ARC-8004, allowing:
|
|
5
|
+
* - Null implementation for off-chain only mode
|
|
6
|
+
* - Aptos implementation for full on-chain support
|
|
7
|
+
* - Custom implementations for other blockchains
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
import type { Account } from '@aptos-labs/ts-sdk';
|
|
12
|
+
import type { AgentCard } from '../types';
|
|
13
|
+
/**
|
|
14
|
+
* Result of minting an identity NFT on-chain
|
|
15
|
+
*/
|
|
16
|
+
export interface MintIdentityResult {
|
|
17
|
+
/** On-chain token address */
|
|
18
|
+
tokenAddress: string;
|
|
19
|
+
/** Transaction hash */
|
|
20
|
+
txHash: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Result of verifying an identity on-chain
|
|
24
|
+
*/
|
|
25
|
+
export interface VerifyIdentityResult {
|
|
26
|
+
/** Transaction hash */
|
|
27
|
+
txHash: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Result of creating an on-chain attestation
|
|
31
|
+
*/
|
|
32
|
+
export interface AttestationResult {
|
|
33
|
+
/** Attestation/transaction hash */
|
|
34
|
+
attestationHash: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* On-chain agent score data
|
|
38
|
+
*/
|
|
39
|
+
export interface OnChainAgentScore {
|
|
40
|
+
/** Total sum of all scores received */
|
|
41
|
+
totalScore: number;
|
|
42
|
+
/** Number of feedback submissions */
|
|
43
|
+
feedbackCount: number;
|
|
44
|
+
/** Average score scaled by 100 (e.g., 450 = 4.50) */
|
|
45
|
+
averageScoreScaled: number;
|
|
46
|
+
/** Computed trust level (0-5) */
|
|
47
|
+
trustLevel: number;
|
|
48
|
+
/** Last update timestamp (unix seconds) */
|
|
49
|
+
lastUpdated: number;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Interface for on-chain operations
|
|
53
|
+
* Implement this interface to provide custom blockchain integration
|
|
54
|
+
*/
|
|
55
|
+
export interface OnChainProvider {
|
|
56
|
+
/**
|
|
57
|
+
* Whether on-chain operations are enabled
|
|
58
|
+
*/
|
|
59
|
+
readonly enabled: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Mint an agent identity NFT on-chain
|
|
62
|
+
*
|
|
63
|
+
* @param agentId - Unique agent identifier
|
|
64
|
+
* @param agentCard - Agent metadata
|
|
65
|
+
* @param signer - Account to sign the transaction
|
|
66
|
+
* @returns Token address and transaction hash
|
|
67
|
+
*/
|
|
68
|
+
mintIdentity(agentId: string, agentCard: AgentCard, signer: Account): Promise<MintIdentityResult>;
|
|
69
|
+
/**
|
|
70
|
+
* Verify an agent identity on-chain
|
|
71
|
+
*
|
|
72
|
+
* @param tokenAddress - On-chain token address
|
|
73
|
+
* @param signer - Admin account to sign verification
|
|
74
|
+
* @returns Transaction hash
|
|
75
|
+
*/
|
|
76
|
+
verifyIdentity(tokenAddress: string, signer: Account): Promise<VerifyIdentityResult>;
|
|
77
|
+
/**
|
|
78
|
+
* Create an on-chain feedback attestation
|
|
79
|
+
*
|
|
80
|
+
* @param agentId - Agent receiving feedback
|
|
81
|
+
* @param clientAddress - Address of client giving feedback
|
|
82
|
+
* @param score - Overall score (1-5)
|
|
83
|
+
* @param paymentHash - Optional related payment hash
|
|
84
|
+
* @param signer - Account to sign the transaction
|
|
85
|
+
* @returns Attestation hash
|
|
86
|
+
*/
|
|
87
|
+
attestFeedback(agentId: string, clientAddress: string, score: number, paymentHash: string | undefined, signer: Account): Promise<AttestationResult>;
|
|
88
|
+
/**
|
|
89
|
+
* Submit a task validation on-chain
|
|
90
|
+
*
|
|
91
|
+
* @param taskId - Task identifier
|
|
92
|
+
* @param agentId - Agent that performed the task
|
|
93
|
+
* @param validatorId - Validator identifier
|
|
94
|
+
* @param proof - Optional cryptographic proof
|
|
95
|
+
* @param signer - Account to sign the transaction
|
|
96
|
+
* @returns Attestation hash
|
|
97
|
+
*/
|
|
98
|
+
submitValidation(taskId: string, agentId: string, validatorId: string, proof: string | undefined, signer: Account): Promise<AttestationResult>;
|
|
99
|
+
/**
|
|
100
|
+
* Check if an identity exists on-chain
|
|
101
|
+
*
|
|
102
|
+
* @param tokenAddress - Token address to check
|
|
103
|
+
* @returns Whether the identity exists
|
|
104
|
+
*/
|
|
105
|
+
identityExists(tokenAddress: string): Promise<boolean>;
|
|
106
|
+
/**
|
|
107
|
+
* Get account balance (for checking if account can pay fees)
|
|
108
|
+
*
|
|
109
|
+
* @param address - Account address
|
|
110
|
+
* @returns Balance in native units (e.g., octas for Aptos)
|
|
111
|
+
*/
|
|
112
|
+
getAccountBalance(address: string): Promise<bigint>;
|
|
113
|
+
/**
|
|
114
|
+
* Get aggregated agent score from on-chain
|
|
115
|
+
*
|
|
116
|
+
* @param agentId - Agent identifier
|
|
117
|
+
* @returns On-chain agent score data or null if not found
|
|
118
|
+
*/
|
|
119
|
+
getAgentScore(agentId: string): Promise<OnChainAgentScore | null>;
|
|
120
|
+
/**
|
|
121
|
+
* Check if an agent has any on-chain reputation
|
|
122
|
+
*
|
|
123
|
+
* @param agentId - Agent identifier
|
|
124
|
+
* @returns Whether the agent has on-chain reputation data
|
|
125
|
+
*/
|
|
126
|
+
hasOnChainReputation(agentId: string): Promise<boolean>;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Null implementation of OnChainProvider
|
|
130
|
+
* Used when on-chain operations are disabled
|
|
131
|
+
* All operations return empty results or throw appropriate errors
|
|
132
|
+
*/
|
|
133
|
+
export declare class NullOnChainProvider implements OnChainProvider {
|
|
134
|
+
readonly enabled = false;
|
|
135
|
+
mintIdentity(): Promise<MintIdentityResult>;
|
|
136
|
+
verifyIdentity(): Promise<VerifyIdentityResult>;
|
|
137
|
+
attestFeedback(): Promise<AttestationResult>;
|
|
138
|
+
submitValidation(): Promise<AttestationResult>;
|
|
139
|
+
identityExists(): Promise<boolean>;
|
|
140
|
+
getAccountBalance(): Promise<bigint>;
|
|
141
|
+
getAgentScore(): Promise<OnChainAgentScore | null>;
|
|
142
|
+
hasOnChainReputation(): Promise<boolean>;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Aptos blockchain implementation of OnChainProvider
|
|
146
|
+
*/
|
|
147
|
+
export declare class AptosOnChainProvider implements OnChainProvider {
|
|
148
|
+
private aptos;
|
|
149
|
+
readonly enabled = true;
|
|
150
|
+
private moduleAddress;
|
|
151
|
+
constructor(aptos: import('@aptos-labs/ts-sdk').Aptos, moduleAddress: string);
|
|
152
|
+
mintIdentity(agentId: string, agentCard: AgentCard, signer: Account): Promise<MintIdentityResult>;
|
|
153
|
+
verifyIdentity(tokenAddress: string, signer: Account): Promise<VerifyIdentityResult>;
|
|
154
|
+
attestFeedback(agentId: string, clientAddress: string, score: number, paymentHash: string | undefined, signer: Account): Promise<AttestationResult>;
|
|
155
|
+
submitValidation(taskId: string, agentId: string, validatorId: string, proof: string | undefined, signer: Account): Promise<AttestationResult>;
|
|
156
|
+
identityExists(tokenAddress: string): Promise<boolean>;
|
|
157
|
+
getAccountBalance(address: string): Promise<bigint>;
|
|
158
|
+
getAgentScore(agentId: string): Promise<OnChainAgentScore | null>;
|
|
159
|
+
hasOnChainReputation(agentId: string): Promise<boolean>;
|
|
160
|
+
/**
|
|
161
|
+
* Extract token address from mint transaction events
|
|
162
|
+
*/
|
|
163
|
+
private extractTokenAddressFromTx;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Create an on-chain provider based on configuration
|
|
167
|
+
*
|
|
168
|
+
* @param config - Configuration options
|
|
169
|
+
* @returns OnChainProvider instance
|
|
170
|
+
*
|
|
171
|
+
* @example Disabled (null provider)
|
|
172
|
+
* ```typescript
|
|
173
|
+
* const provider = createOnChainProvider({ enabled: false });
|
|
174
|
+
* ```
|
|
175
|
+
*
|
|
176
|
+
* @example Aptos provider
|
|
177
|
+
* ```typescript
|
|
178
|
+
* const provider = createOnChainProvider({
|
|
179
|
+
* enabled: true,
|
|
180
|
+
* moduleAddress: '0x...',
|
|
181
|
+
* network: 'testnet',
|
|
182
|
+
* });
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
export declare function createOnChainProvider(config: {
|
|
186
|
+
enabled: boolean;
|
|
187
|
+
moduleAddress?: string;
|
|
188
|
+
network?: string;
|
|
189
|
+
}): OnChainProvider;
|
|
190
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../lib/arc8004/chain/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAA6C,MAAM,UAAU,CAAC;AAMrF;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,6BAA6B;IAC7B,YAAY,EAAE,MAAM,CAAC;IACrB,uBAAuB;IACvB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,uBAAuB;IACvB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,mCAAmC;IACnC,eAAe,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,uCAAuC;IACvC,UAAU,EAAE,MAAM,CAAC;IACnB,qCAAqC;IACrC,aAAa,EAAE,MAAM,CAAC;IACtB,qDAAqD;IACrD,kBAAkB,EAAE,MAAM,CAAC;IAC3B,iCAAiC;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,2CAA2C;IAC3C,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAE1B;;;;;;;OAOG;IACH,YAAY,CACV,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,OAAO,GACd,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAE/B;;;;;;OAMG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;;;GAmBG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE;IAC5C,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,GAAG,eAAe,CAelB"}
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ARC-8004 On-Chain Provider Interface
|
|
3
|
+
*
|
|
4
|
+
* Abstracts blockchain operations for ARC-8004, allowing:
|
|
5
|
+
* - Null implementation for off-chain only mode
|
|
6
|
+
* - Aptos implementation for full on-chain support
|
|
7
|
+
* - Custom implementations for other blockchains
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
// ============================================
|
|
12
|
+
// Null On-Chain Provider
|
|
13
|
+
// ============================================
|
|
14
|
+
/**
|
|
15
|
+
* Null implementation of OnChainProvider
|
|
16
|
+
* Used when on-chain operations are disabled
|
|
17
|
+
* All operations return empty results or throw appropriate errors
|
|
18
|
+
*/
|
|
19
|
+
export class NullOnChainProvider {
|
|
20
|
+
enabled = false;
|
|
21
|
+
async mintIdentity() {
|
|
22
|
+
throw new Error('On-chain operations are disabled. Set onChainEnabled: true to enable.');
|
|
23
|
+
}
|
|
24
|
+
async verifyIdentity() {
|
|
25
|
+
throw new Error('On-chain operations are disabled. Set onChainEnabled: true to enable.');
|
|
26
|
+
}
|
|
27
|
+
async attestFeedback() {
|
|
28
|
+
// For attestations, we can silently skip rather than throw
|
|
29
|
+
return { attestationHash: '' };
|
|
30
|
+
}
|
|
31
|
+
async submitValidation() {
|
|
32
|
+
// For validations, we can silently skip rather than throw
|
|
33
|
+
return { attestationHash: '' };
|
|
34
|
+
}
|
|
35
|
+
async identityExists() {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
async getAccountBalance() {
|
|
39
|
+
return BigInt(0);
|
|
40
|
+
}
|
|
41
|
+
async getAgentScore() {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
async hasOnChainReputation() {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// ============================================
|
|
49
|
+
// Aptos On-Chain Provider
|
|
50
|
+
// ============================================
|
|
51
|
+
/**
|
|
52
|
+
* Aptos blockchain implementation of OnChainProvider
|
|
53
|
+
*/
|
|
54
|
+
export class AptosOnChainProvider {
|
|
55
|
+
aptos;
|
|
56
|
+
enabled = true;
|
|
57
|
+
moduleAddress;
|
|
58
|
+
constructor(aptos, moduleAddress) {
|
|
59
|
+
this.aptos = aptos;
|
|
60
|
+
this.moduleAddress = moduleAddress;
|
|
61
|
+
}
|
|
62
|
+
async mintIdentity(agentId, agentCard, signer) {
|
|
63
|
+
// Generate metadata URI (data URL with JSON)
|
|
64
|
+
const metadataUri = `data:application/json;base64,${Buffer.from(JSON.stringify(agentCard)).toString('base64')}`;
|
|
65
|
+
const transaction = await this.aptos.transaction.build.simple({
|
|
66
|
+
sender: signer.accountAddress,
|
|
67
|
+
data: {
|
|
68
|
+
function: `${this.moduleAddress}::agent_identity::mint_identity`,
|
|
69
|
+
functionArguments: [
|
|
70
|
+
agentId,
|
|
71
|
+
agentCard.name,
|
|
72
|
+
metadataUri,
|
|
73
|
+
JSON.stringify(agentCard.capabilities),
|
|
74
|
+
],
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
const committed = await this.aptos.signAndSubmitTransaction({
|
|
78
|
+
signer,
|
|
79
|
+
transaction,
|
|
80
|
+
});
|
|
81
|
+
await this.aptos.waitForTransaction({ transactionHash: committed.hash });
|
|
82
|
+
// Extract token address from events
|
|
83
|
+
const tokenAddress = await this.extractTokenAddressFromTx(committed.hash);
|
|
84
|
+
return {
|
|
85
|
+
tokenAddress,
|
|
86
|
+
txHash: committed.hash,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
async verifyIdentity(tokenAddress, signer) {
|
|
90
|
+
const transaction = await this.aptos.transaction.build.simple({
|
|
91
|
+
sender: signer.accountAddress,
|
|
92
|
+
data: {
|
|
93
|
+
function: `${this.moduleAddress}::agent_identity::verify_identity`,
|
|
94
|
+
functionArguments: [tokenAddress],
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
const committed = await this.aptos.signAndSubmitTransaction({
|
|
98
|
+
signer,
|
|
99
|
+
transaction,
|
|
100
|
+
});
|
|
101
|
+
await this.aptos.waitForTransaction({ transactionHash: committed.hash });
|
|
102
|
+
return { txHash: committed.hash };
|
|
103
|
+
}
|
|
104
|
+
async attestFeedback(agentId, clientAddress, score, paymentHash, signer) {
|
|
105
|
+
const transaction = await this.aptos.transaction.build.simple({
|
|
106
|
+
sender: signer.accountAddress,
|
|
107
|
+
data: {
|
|
108
|
+
function: `${this.moduleAddress}::reputation::attest_feedback`,
|
|
109
|
+
functionArguments: [
|
|
110
|
+
agentId,
|
|
111
|
+
clientAddress,
|
|
112
|
+
score,
|
|
113
|
+
paymentHash || '',
|
|
114
|
+
],
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
const committed = await this.aptos.signAndSubmitTransaction({
|
|
118
|
+
signer,
|
|
119
|
+
transaction,
|
|
120
|
+
});
|
|
121
|
+
await this.aptos.waitForTransaction({ transactionHash: committed.hash });
|
|
122
|
+
return { attestationHash: committed.hash };
|
|
123
|
+
}
|
|
124
|
+
async submitValidation(taskId, agentId, validatorId, proof, signer) {
|
|
125
|
+
const transaction = await this.aptos.transaction.build.simple({
|
|
126
|
+
sender: signer.accountAddress,
|
|
127
|
+
data: {
|
|
128
|
+
function: `${this.moduleAddress}::validation::submit_validation`,
|
|
129
|
+
functionArguments: [
|
|
130
|
+
taskId,
|
|
131
|
+
agentId,
|
|
132
|
+
validatorId,
|
|
133
|
+
proof || '',
|
|
134
|
+
],
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
const committed = await this.aptos.signAndSubmitTransaction({
|
|
138
|
+
signer,
|
|
139
|
+
transaction,
|
|
140
|
+
});
|
|
141
|
+
await this.aptos.waitForTransaction({ transactionHash: committed.hash });
|
|
142
|
+
return { attestationHash: committed.hash };
|
|
143
|
+
}
|
|
144
|
+
async identityExists(tokenAddress) {
|
|
145
|
+
try {
|
|
146
|
+
const resource = await this.aptos.getAccountResource({
|
|
147
|
+
accountAddress: tokenAddress,
|
|
148
|
+
resourceType: `${this.moduleAddress}::agent_identity::AgentIdentity`,
|
|
149
|
+
});
|
|
150
|
+
return !!resource;
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
async getAccountBalance(address) {
|
|
157
|
+
try {
|
|
158
|
+
return BigInt(await this.aptos.getAccountAPTAmount({ accountAddress: address }));
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
return BigInt(0);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
async getAgentScore(agentId) {
|
|
165
|
+
try {
|
|
166
|
+
const result = await this.aptos.view({
|
|
167
|
+
payload: {
|
|
168
|
+
function: `${this.moduleAddress}::reputation::get_agent_score`,
|
|
169
|
+
functionArguments: [agentId],
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
// Result is tuple: (total_score, feedback_count, average_score_scaled, trust_level, last_updated)
|
|
173
|
+
if (result && Array.isArray(result) && result.length >= 5) {
|
|
174
|
+
const [totalScore, feedbackCount, averageScoreScaled, trustLevel, lastUpdated] = result;
|
|
175
|
+
// If feedback count is 0, no reputation exists
|
|
176
|
+
if (Number(feedbackCount) === 0) {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
return {
|
|
180
|
+
totalScore: Number(totalScore),
|
|
181
|
+
feedbackCount: Number(feedbackCount),
|
|
182
|
+
averageScoreScaled: Number(averageScoreScaled),
|
|
183
|
+
trustLevel: Number(trustLevel),
|
|
184
|
+
lastUpdated: Number(lastUpdated),
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
console.warn('[ARC8004] Failed to get agent score from chain:', error);
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
async hasOnChainReputation(agentId) {
|
|
195
|
+
try {
|
|
196
|
+
const result = await this.aptos.view({
|
|
197
|
+
payload: {
|
|
198
|
+
function: `${this.moduleAddress}::reputation::has_reputation`,
|
|
199
|
+
functionArguments: [agentId],
|
|
200
|
+
},
|
|
201
|
+
});
|
|
202
|
+
return result && Array.isArray(result) && result[0] === true;
|
|
203
|
+
}
|
|
204
|
+
catch {
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Extract token address from mint transaction events
|
|
210
|
+
*/
|
|
211
|
+
async extractTokenAddressFromTx(txHash) {
|
|
212
|
+
const txDetails = await this.aptos.getTransactionByHash({ transactionHash: txHash });
|
|
213
|
+
if (txDetails && 'events' in txDetails && Array.isArray(txDetails.events)) {
|
|
214
|
+
// Look for IdentityCreated event
|
|
215
|
+
const identityCreatedEvent = txDetails.events.find((event) => {
|
|
216
|
+
const eventTypeStr = typeof event.type === 'string' ? event.type : '';
|
|
217
|
+
return eventTypeStr.includes('IdentityCreated');
|
|
218
|
+
});
|
|
219
|
+
if (identityCreatedEvent && identityCreatedEvent.data) {
|
|
220
|
+
const eventData = identityCreatedEvent.data;
|
|
221
|
+
if (eventData.token_address) {
|
|
222
|
+
return eventData.token_address;
|
|
223
|
+
}
|
|
224
|
+
if (eventData.token_addr) {
|
|
225
|
+
return eventData.token_addr;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
// Fallback: try to extract from transaction changes
|
|
230
|
+
if (txDetails && 'changes' in txDetails && Array.isArray(txDetails.changes)) {
|
|
231
|
+
const identityChange = txDetails.changes.find((change) => {
|
|
232
|
+
const data = change.data;
|
|
233
|
+
return data?.type && String(data.type).includes('agent_identity::AgentIdentity');
|
|
234
|
+
});
|
|
235
|
+
if (identityChange && typeof identityChange.address === 'string') {
|
|
236
|
+
return identityChange.address;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
throw new Error('Failed to extract token address from mint transaction');
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
// ============================================
|
|
243
|
+
// Factory Function
|
|
244
|
+
// ============================================
|
|
245
|
+
/**
|
|
246
|
+
* Create an on-chain provider based on configuration
|
|
247
|
+
*
|
|
248
|
+
* @param config - Configuration options
|
|
249
|
+
* @returns OnChainProvider instance
|
|
250
|
+
*
|
|
251
|
+
* @example Disabled (null provider)
|
|
252
|
+
* ```typescript
|
|
253
|
+
* const provider = createOnChainProvider({ enabled: false });
|
|
254
|
+
* ```
|
|
255
|
+
*
|
|
256
|
+
* @example Aptos provider
|
|
257
|
+
* ```typescript
|
|
258
|
+
* const provider = createOnChainProvider({
|
|
259
|
+
* enabled: true,
|
|
260
|
+
* moduleAddress: '0x...',
|
|
261
|
+
* network: 'testnet',
|
|
262
|
+
* });
|
|
263
|
+
* ```
|
|
264
|
+
*/
|
|
265
|
+
export function createOnChainProvider(config) {
|
|
266
|
+
if (!config.enabled) {
|
|
267
|
+
return new NullOnChainProvider();
|
|
268
|
+
}
|
|
269
|
+
if (!config.moduleAddress) {
|
|
270
|
+
console.warn('[ARC8004] On-chain enabled but moduleAddress not provided. Using NullOnChainProvider.');
|
|
271
|
+
return new NullOnChainProvider();
|
|
272
|
+
}
|
|
273
|
+
// Lazy import Aptos client
|
|
274
|
+
const { getAptosClient } = require('../../aptos-utils');
|
|
275
|
+
const aptos = getAptosClient(config.network || 'aptos-testnet');
|
|
276
|
+
return new AptosOnChainProvider(aptos, config.moduleAddress);
|
|
277
|
+
}
|
|
278
|
+
//# sourceMappingURL=types.js.map
|