@arc402/sdk 0.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 +184 -0
- package/dist/agent.d.ts +29 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +95 -0
- package/dist/agreement.d.ts +57 -0
- package/dist/agreement.d.ts.map +1 -0
- package/dist/agreement.js +156 -0
- package/dist/capability.d.ts +17 -0
- package/dist/capability.d.ts.map +1 -0
- package/dist/capability.js +19 -0
- package/dist/channel.d.ts +39 -0
- package/dist/channel.d.ts.map +1 -0
- package/dist/channel.js +160 -0
- package/dist/coldstart.d.ts +15 -0
- package/dist/coldstart.d.ts.map +1 -0
- package/dist/coldstart.js +44 -0
- package/dist/context.d.ts +2 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +2 -0
- package/dist/contractinteraction.d.ts +47 -0
- package/dist/contractinteraction.d.ts.map +1 -0
- package/dist/contractinteraction.js +80 -0
- package/dist/contracts.d.ts +27 -0
- package/dist/contracts.d.ts.map +1 -0
- package/dist/contracts.js +187 -0
- package/dist/deliverable.d.ts +118 -0
- package/dist/deliverable.d.ts.map +1 -0
- package/dist/deliverable.js +156 -0
- package/dist/dispute-arbitration.d.ts +42 -0
- package/dist/dispute-arbitration.d.ts.map +1 -0
- package/dist/dispute-arbitration.js +160 -0
- package/dist/governance.d.ts +13 -0
- package/dist/governance.d.ts.map +1 -0
- package/dist/governance.js +15 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +92 -0
- package/dist/intent.d.ts +13 -0
- package/dist/intent.d.ts.map +1 -0
- package/dist/intent.js +26 -0
- package/dist/metadata.d.ts +55 -0
- package/dist/metadata.d.ts.map +1 -0
- package/dist/metadata.js +106 -0
- package/dist/migration.d.ts +11 -0
- package/dist/migration.d.ts.map +1 -0
- package/dist/migration.js +38 -0
- package/dist/multiparty.d.ts +56 -0
- package/dist/multiparty.d.ts.map +1 -0
- package/dist/multiparty.js +86 -0
- package/dist/negotiation-guard.d.ts +20 -0
- package/dist/negotiation-guard.d.ts.map +1 -0
- package/dist/negotiation-guard.js +96 -0
- package/dist/negotiation.d.ts +25 -0
- package/dist/negotiation.d.ts.map +1 -0
- package/dist/negotiation.js +102 -0
- package/dist/policy.d.ts +33 -0
- package/dist/policy.d.ts.map +1 -0
- package/dist/policy.js +72 -0
- package/dist/reputation.d.ts +13 -0
- package/dist/reputation.d.ts.map +1 -0
- package/dist/reputation.js +21 -0
- package/dist/session-manager.d.ts +13 -0
- package/dist/session-manager.d.ts.map +1 -0
- package/dist/session-manager.js +102 -0
- package/dist/settlement.d.ts +14 -0
- package/dist/settlement.d.ts.map +1 -0
- package/dist/settlement.js +35 -0
- package/dist/sponsorship.d.ts +17 -0
- package/dist/sponsorship.d.ts.map +1 -0
- package/dist/sponsorship.js +19 -0
- package/dist/trust.d.ts +22 -0
- package/dist/trust.d.ts.map +1 -0
- package/dist/trust.js +52 -0
- package/dist/types.d.ts +391 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +119 -0
- package/dist/wallet.d.ts +31 -0
- package/dist/wallet.d.ts.map +1 -0
- package/dist/wallet.js +83 -0
- package/dist/watchtower.d.ts +60 -0
- package/dist/watchtower.d.ts.map +1 -0
- package/dist/watchtower.js +93 -0
- package/package.json +30 -0
- package/src/agent.ts +122 -0
- package/src/agreement.ts +236 -0
- package/src/capability.ts +18 -0
- package/src/channel.ts +203 -0
- package/src/coldstart.ts +52 -0
- package/src/context.ts +2 -0
- package/src/contractinteraction.d.ts +47 -0
- package/src/contractinteraction.d.ts.map +1 -0
- package/src/contractinteraction.js +81 -0
- package/src/contractinteraction.js.map +1 -0
- package/src/contractinteraction.ts +157 -0
- package/src/contracts.d.ts +27 -0
- package/src/contracts.d.ts.map +1 -0
- package/src/contracts.js +188 -0
- package/src/contracts.js.map +1 -0
- package/src/contracts.ts +186 -0
- package/src/deliverable.ts +231 -0
- package/src/demos/demo-insurance.ts +148 -0
- package/src/demos/demo-multiagent.ts +197 -0
- package/src/demos/demo-research.ts +124 -0
- package/src/dispute-arbitration.ts +196 -0
- package/src/governance.ts +14 -0
- package/src/index.ts +31 -0
- package/src/intent.ts +22 -0
- package/src/metadata.ts +158 -0
- package/src/migration.ts +43 -0
- package/src/multiparty.ts +132 -0
- package/src/negotiation-guard.ts +125 -0
- package/src/negotiation.ts +135 -0
- package/src/policy.ts +71 -0
- package/src/reputation.ts +20 -0
- package/src/session-manager.ts +80 -0
- package/src/settlement.ts +31 -0
- package/src/sponsorship.ts +18 -0
- package/src/trust.ts +43 -0
- package/src/types.d.ts +391 -0
- package/src/types.d.ts.map +1 -0
- package/src/types.js +113 -0
- package/src/types.js.map +1 -0
- package/src/types.ts +484 -0
- package/src/wallet.ts +86 -0
- package/src/watchtower.ts +124 -0
- package/test/negotiation-signing.test.js +157 -0
- package/test/sdk.test.js +19 -0
- package/tsconfig.json +17 -0
package/dist/channel.js
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChannelClient = void 0;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
const CHANNEL_ABI_FRAGMENT = [
|
|
6
|
+
"function openSessionChannel(address provider, address token, uint256 maxAmount, uint256 ratePerCall, uint256 deadline) external payable returns (bytes32 channelId)",
|
|
7
|
+
"function closeChannel(bytes32 channelId, bytes finalState) external",
|
|
8
|
+
"function challengeChannel(bytes32 channelId, bytes latestState) external",
|
|
9
|
+
"function finaliseChallenge(bytes32 channelId) external",
|
|
10
|
+
"function reclaimExpiredChannel(bytes32 channelId) external",
|
|
11
|
+
"function getChannel(bytes32 channelId) external view returns (tuple(address client, address provider, address token, uint256 depositAmount, uint256 settledAmount, uint256 lastSequenceNumber, uint256 deadline, uint256 challengeExpiry, uint8 status))",
|
|
12
|
+
"function getChannelsByClient(address client) external view returns (bytes32[])",
|
|
13
|
+
"function getChannelsByProvider(address provider) external view returns (bytes32[])",
|
|
14
|
+
"event ChannelOpened(bytes32 indexed channelId, address indexed client, address indexed provider, address token, uint256 depositAmount, uint256 deadline)",
|
|
15
|
+
"event ChannelSettled(bytes32 indexed channelId, address indexed provider, uint256 settledAmount, uint256 refundAmount)",
|
|
16
|
+
];
|
|
17
|
+
class ChannelClient {
|
|
18
|
+
constructor(address, runner) {
|
|
19
|
+
this.contract = new ethers_1.ethers.Contract(address, CHANNEL_ABI_FRAGMENT, runner);
|
|
20
|
+
this.signer = runner instanceof ethers_1.AbstractSigner ? runner : null;
|
|
21
|
+
}
|
|
22
|
+
async openSessionChannel(provider, token, maxAmount, ratePerCall, deadline) {
|
|
23
|
+
const isEth = token === ethers_1.ethers.ZeroAddress;
|
|
24
|
+
const tx = await this.contract.openSessionChannel(provider, token, maxAmount, ratePerCall, deadline, {
|
|
25
|
+
value: isEth ? maxAmount : 0n
|
|
26
|
+
});
|
|
27
|
+
const receipt = await tx.wait();
|
|
28
|
+
const iface = new ethers_1.ethers.Interface(CHANNEL_ABI_FRAGMENT);
|
|
29
|
+
for (const log of receipt.logs) {
|
|
30
|
+
try {
|
|
31
|
+
const parsed = iface.parseLog(log);
|
|
32
|
+
if (parsed?.name === "ChannelOpened") {
|
|
33
|
+
return { channelId: parsed.args.channelId, txHash: receipt.hash };
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
catch { }
|
|
37
|
+
}
|
|
38
|
+
throw new Error("Could not parse ChannelOpened event");
|
|
39
|
+
}
|
|
40
|
+
// ─── EIP-712 domain helpers (MA-07) ──────────────────────────────────────
|
|
41
|
+
/**
|
|
42
|
+
* Compute the EIP-712 domain separator for a deployed SessionChannels contract.
|
|
43
|
+
* Must match SessionChannels._domainSeparator() on-chain.
|
|
44
|
+
*/
|
|
45
|
+
static domainSeparator(chainId, contractAddress) {
|
|
46
|
+
const DOMAIN_TYPEHASH = ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes("EIP712Domain(string name,uint256 chainId,address verifyingContract)"));
|
|
47
|
+
return ethers_1.ethers.keccak256(ethers_1.ethers.AbiCoder.defaultAbiCoder().encode(["bytes32", "bytes32", "uint256", "address"], [DOMAIN_TYPEHASH, ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes("ARC402SessionChannels")), chainId, contractAddress]));
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Compute the EIP-712 typed-data digest for a ChannelState.
|
|
51
|
+
* Must match SessionChannels._verifyChannelStateSigs() digest on-chain.
|
|
52
|
+
*/
|
|
53
|
+
static channelStateDigest(state, chainId, contractAddress) {
|
|
54
|
+
const CHANNEL_STATE_TYPEHASH = ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes("ChannelState(bytes32 channelId,uint256 sequenceNumber,uint256 callCount,uint256 cumulativePayment,address token,uint256 timestamp)"));
|
|
55
|
+
const structHash = ethers_1.ethers.keccak256(ethers_1.ethers.AbiCoder.defaultAbiCoder().encode(["bytes32", "bytes32", "uint256", "uint256", "uint256", "address", "uint256"], [CHANNEL_STATE_TYPEHASH, state.channelId, state.sequenceNumber, state.callCount, state.cumulativePayment, state.token, state.timestamp]));
|
|
56
|
+
const domainSep = ChannelClient.domainSeparator(chainId, contractAddress);
|
|
57
|
+
return ethers_1.ethers.getBytes(ethers_1.ethers.keccak256(ethers_1.ethers.concat([new Uint8Array([0x19, 0x01]), ethers_1.ethers.getBytes(domainSep), ethers_1.ethers.getBytes(structHash)])));
|
|
58
|
+
}
|
|
59
|
+
async signStateUpdate(channelId, sequenceNumber, callCount, cumulativePayment, token, chainId, contractAddress) {
|
|
60
|
+
if (!this.signer)
|
|
61
|
+
throw new Error("Signer required for signing");
|
|
62
|
+
const timestamp = Math.floor(Date.now() / 1000);
|
|
63
|
+
const stateData = { channelId, sequenceNumber, callCount, cumulativePayment, token, timestamp };
|
|
64
|
+
const digest = ChannelClient.channelStateDigest(stateData, chainId, contractAddress);
|
|
65
|
+
// Use signMessage with raw bytes — ethers.js v6 handles the prefix
|
|
66
|
+
const sig = await this.signer.signMessage(ethers_1.ethers.getBytes(digest));
|
|
67
|
+
return {
|
|
68
|
+
...stateData,
|
|
69
|
+
clientSig: sig, // caller sets correct field (clientSig or providerSig)
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
async verifyStateUpdate(state, channel, chainId, contractAddress) {
|
|
73
|
+
const stateData = {
|
|
74
|
+
channelId: state.channelId,
|
|
75
|
+
sequenceNumber: state.sequenceNumber,
|
|
76
|
+
callCount: state.callCount,
|
|
77
|
+
cumulativePayment: state.cumulativePayment,
|
|
78
|
+
token: state.token,
|
|
79
|
+
timestamp: state.timestamp,
|
|
80
|
+
};
|
|
81
|
+
const digest = ChannelClient.channelStateDigest(stateData, chainId, contractAddress);
|
|
82
|
+
try {
|
|
83
|
+
if (state.clientSig) {
|
|
84
|
+
const clientSigner = ethers_1.ethers.verifyMessage(digest, state.clientSig);
|
|
85
|
+
if (clientSigner.toLowerCase() !== channel.client.toLowerCase())
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
if (state.providerSig) {
|
|
89
|
+
const providerSigner = ethers_1.ethers.verifyMessage(digest, state.providerSig);
|
|
90
|
+
if (providerSigner.toLowerCase() !== channel.provider.toLowerCase())
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
return !!(state.clientSig && state.providerSig);
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
encodeChannelState(state) {
|
|
100
|
+
return ethers_1.ethers.AbiCoder.defaultAbiCoder().encode(["tuple(bytes32 channelId, uint256 sequenceNumber, uint256 callCount, uint256 cumulativePayment, address token, uint256 timestamp, bytes clientSig, bytes providerSig)"], [{
|
|
101
|
+
channelId: state.channelId,
|
|
102
|
+
sequenceNumber: state.sequenceNumber,
|
|
103
|
+
callCount: state.callCount,
|
|
104
|
+
cumulativePayment: state.cumulativePayment,
|
|
105
|
+
token: state.token,
|
|
106
|
+
timestamp: state.timestamp,
|
|
107
|
+
clientSig: state.clientSig ?? "0x",
|
|
108
|
+
providerSig: state.providerSig ?? "0x",
|
|
109
|
+
}]);
|
|
110
|
+
}
|
|
111
|
+
async closeChannel(channelId, finalState) {
|
|
112
|
+
const encoded = this.encodeChannelState(finalState);
|
|
113
|
+
const tx = await this.contract.closeChannel(channelId, encoded);
|
|
114
|
+
const receipt = await tx.wait();
|
|
115
|
+
return { txHash: receipt.hash };
|
|
116
|
+
}
|
|
117
|
+
async challengeChannel(channelId, latestState) {
|
|
118
|
+
const encoded = this.encodeChannelState(latestState);
|
|
119
|
+
const tx = await this.contract.challengeChannel(channelId, encoded);
|
|
120
|
+
const receipt = await tx.wait();
|
|
121
|
+
return { txHash: receipt.hash };
|
|
122
|
+
}
|
|
123
|
+
async finaliseChallenge(channelId) {
|
|
124
|
+
const tx = await this.contract.finaliseChallenge(channelId);
|
|
125
|
+
const receipt = await tx.wait();
|
|
126
|
+
return { txHash: receipt.hash };
|
|
127
|
+
}
|
|
128
|
+
async reclaimExpiredChannel(channelId) {
|
|
129
|
+
const tx = await this.contract.reclaimExpiredChannel(channelId);
|
|
130
|
+
const receipt = await tx.wait();
|
|
131
|
+
return { txHash: receipt.hash };
|
|
132
|
+
}
|
|
133
|
+
async getChannelStatus(channelId) {
|
|
134
|
+
const raw = await this.contract.getChannel(channelId);
|
|
135
|
+
const statusMap = {
|
|
136
|
+
0: "OPEN", 1: "CLOSING", 2: "CHALLENGED", 3: "SETTLED"
|
|
137
|
+
};
|
|
138
|
+
return {
|
|
139
|
+
client: raw.client,
|
|
140
|
+
provider: raw.provider,
|
|
141
|
+
token: raw.token,
|
|
142
|
+
depositAmount: raw.depositAmount,
|
|
143
|
+
settledAmount: raw.settledAmount,
|
|
144
|
+
lastSequenceNumber: Number(raw.lastSequenceNumber),
|
|
145
|
+
deadline: Number(raw.deadline),
|
|
146
|
+
challengeExpiry: Number(raw.challengeExpiry),
|
|
147
|
+
status: statusMap[Number(raw.status)] ?? "OPEN",
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
async getOpenChannels(wallet) {
|
|
151
|
+
const [clientIds, providerIds] = await Promise.all([
|
|
152
|
+
this.contract.getChannelsByClient(wallet),
|
|
153
|
+
this.contract.getChannelsByProvider(wallet),
|
|
154
|
+
]);
|
|
155
|
+
const allIds = [...new Set([...clientIds, ...providerIds])];
|
|
156
|
+
const channels = await Promise.all(allIds.map(id => this.getChannelStatus(id)));
|
|
157
|
+
return channels.filter(ch => ch.status === "OPEN" || ch.status === "CLOSING" || ch.status === "CHALLENGED");
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
exports.ChannelClient = ChannelClient;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BigNumberish, ContractRunner, ethers } from "ethers";
|
|
2
|
+
export declare class ColdStartClient {
|
|
3
|
+
private vouchingRegistryAddress;
|
|
4
|
+
private trustRegistryAddress;
|
|
5
|
+
private runner?;
|
|
6
|
+
constructor(vouchingRegistryAddress: string, trustRegistryAddress: string, runner?: ContractRunner);
|
|
7
|
+
vouch(newAgent: string, stakeAmount: BigNumberish, signer: ContractRunner): Promise<ethers.TransactionReceipt>;
|
|
8
|
+
postBond(signer: ContractRunner, options?: {
|
|
9
|
+
amount?: BigNumberish;
|
|
10
|
+
}): Promise<ethers.TransactionReceipt>;
|
|
11
|
+
claimBond(signer: ContractRunner): Promise<ethers.TransactionReceipt>;
|
|
12
|
+
getVouchedBoost(address: string): Promise<bigint>;
|
|
13
|
+
getActiveVouch(address: string): Promise<string>;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=coldstart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coldstart.d.ts","sourceRoot":"","sources":["../src/coldstart.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAa9D,qBAAa,eAAe;IAC1B,OAAO,CAAC,uBAAuB,CAAS;IACxC,OAAO,CAAC,oBAAoB,CAAS;IACrC,OAAO,CAAC,MAAM,CAAC,CAAiB;gBAEpB,uBAAuB,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,cAAc;IAM5F,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAC;IAM9G,QAAQ,CAAC,MAAM,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,YAAY,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAC;IAMzG,SAAS,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAC;IAMrE,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAKjD,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAIvD"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ColdStartClient = void 0;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
const VOUCHING_REGISTRY_ABI = [
|
|
6
|
+
"function vouch(address newAgent, uint256 stakeAmount) external payable",
|
|
7
|
+
"function getVouchedBoost(address agent) external view returns (uint256)",
|
|
8
|
+
"function getVoucher(address agent) external view returns (address)",
|
|
9
|
+
];
|
|
10
|
+
const TRUST_REGISTRY_BOND_ABI = [
|
|
11
|
+
"function postBond() external payable",
|
|
12
|
+
"function claimBond() external",
|
|
13
|
+
];
|
|
14
|
+
class ColdStartClient {
|
|
15
|
+
constructor(vouchingRegistryAddress, trustRegistryAddress, runner) {
|
|
16
|
+
this.vouchingRegistryAddress = vouchingRegistryAddress;
|
|
17
|
+
this.trustRegistryAddress = trustRegistryAddress;
|
|
18
|
+
this.runner = runner;
|
|
19
|
+
}
|
|
20
|
+
async vouch(newAgent, stakeAmount, signer) {
|
|
21
|
+
const contract = new ethers_1.ethers.Contract(this.vouchingRegistryAddress, VOUCHING_REGISTRY_ABI, signer);
|
|
22
|
+
const tx = await contract.vouch(newAgent, stakeAmount);
|
|
23
|
+
return tx.wait();
|
|
24
|
+
}
|
|
25
|
+
async postBond(signer, options) {
|
|
26
|
+
const contract = new ethers_1.ethers.Contract(this.trustRegistryAddress, TRUST_REGISTRY_BOND_ABI, signer);
|
|
27
|
+
const tx = await contract.postBond({ value: options?.amount ?? 0n });
|
|
28
|
+
return tx.wait();
|
|
29
|
+
}
|
|
30
|
+
async claimBond(signer) {
|
|
31
|
+
const contract = new ethers_1.ethers.Contract(this.trustRegistryAddress, TRUST_REGISTRY_BOND_ABI, signer);
|
|
32
|
+
const tx = await contract.claimBond();
|
|
33
|
+
return tx.wait();
|
|
34
|
+
}
|
|
35
|
+
async getVouchedBoost(address) {
|
|
36
|
+
const contract = new ethers_1.ethers.Contract(this.vouchingRegistryAddress, VOUCHING_REGISTRY_ABI, this.runner);
|
|
37
|
+
return BigInt(await contract.getVouchedBoost(address));
|
|
38
|
+
}
|
|
39
|
+
async getActiveVouch(address) {
|
|
40
|
+
const contract = new ethers_1.ethers.Contract(this.vouchingRegistryAddress, VOUCHING_REGISTRY_ABI, this.runner);
|
|
41
|
+
return contract.getVoucher(address);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.ColdStartClient = ColdStartClient;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/context.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ContractRunner, ethers } from "ethers";
|
|
2
|
+
import { Intent } from "./types";
|
|
3
|
+
export interface IntentPayload {
|
|
4
|
+
target: string;
|
|
5
|
+
data: string;
|
|
6
|
+
value: bigint;
|
|
7
|
+
minReturnValue: bigint;
|
|
8
|
+
maxApprovalAmount: bigint;
|
|
9
|
+
approvalToken: string;
|
|
10
|
+
}
|
|
11
|
+
export interface ContractCallAttestation {
|
|
12
|
+
attestationId: string;
|
|
13
|
+
intent: Intent;
|
|
14
|
+
payload: IntentPayload;
|
|
15
|
+
}
|
|
16
|
+
export interface ContractCallResult {
|
|
17
|
+
txHash: string;
|
|
18
|
+
success: boolean;
|
|
19
|
+
returnData?: string;
|
|
20
|
+
blockNumber?: number;
|
|
21
|
+
}
|
|
22
|
+
export declare class ContractInteractionClient {
|
|
23
|
+
private walletAddress;
|
|
24
|
+
private intentContract;
|
|
25
|
+
private provider;
|
|
26
|
+
constructor(intentAttestationAddress: string, runner: ContractRunner, walletAddress: string);
|
|
27
|
+
/** Encode a contract method call into an IntentPayload ready for on-chain execution. */
|
|
28
|
+
buildContractCall(target: string, abi: readonly string[] | unknown[], method: string, args: unknown[], options?: {
|
|
29
|
+
value?: bigint;
|
|
30
|
+
minReturnValue?: bigint;
|
|
31
|
+
maxApprovalAmount?: bigint;
|
|
32
|
+
approvalToken?: string;
|
|
33
|
+
}): IntentPayload;
|
|
34
|
+
/**
|
|
35
|
+
* Create an intent attestation for the contract call. Records agent intent
|
|
36
|
+
* on-chain before execution — provides auditable pre-execution evidence.
|
|
37
|
+
*/
|
|
38
|
+
signAndAttestContractCall(payload: IntentPayload, signer: ethers.Signer): Promise<ContractCallAttestation>;
|
|
39
|
+
/**
|
|
40
|
+
* Execute a contract call under a ServiceAgreement escrow via the ARC402Wallet.
|
|
41
|
+
* The wallet enforces PolicyEngine validation, per-tx approvals, and slippage guards.
|
|
42
|
+
*/
|
|
43
|
+
executeWithEscrow(walletContractAddress: string, payload: IntentPayload, signer: ethers.Signer): Promise<ethers.ContractTransactionResponse>;
|
|
44
|
+
/** Verify the result of a previously submitted contract call transaction. */
|
|
45
|
+
verifyContractCallResult(txHash: string, expectedResult?: string): Promise<ContractCallResult>;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=contractinteraction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contractinteraction.d.ts","sourceRoot":"","sources":["../src/contractinteraction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEjC,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,uBAAuB;IACtC,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,aAAa,CAAC;CACxB;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAMD,qBAAa,yBAAyB;IAOlC,OAAO,CAAC,aAAa;IANvB,OAAO,CAAC,cAAc,CAAkB;IACxC,OAAO,CAAC,QAAQ,CAAkB;gBAGhC,wBAAwB,EAAE,MAAM,EAChC,MAAM,EAAE,cAAc,EACd,aAAa,EAAE,MAAM;IAM/B,wFAAwF;IACxF,iBAAiB,CACf,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,EAAE,EAClC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,EAAE,EACf,OAAO,GAAE;QACP,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,aAAa,CAAC,EAAE,MAAM,CAAC;KACnB,GACL,aAAa;IAahB;;;OAGG;IACG,yBAAyB,CAC7B,OAAO,EAAE,aAAa,EACtB,MAAM,EAAE,MAAM,CAAC,MAAM,GACpB,OAAO,CAAC,uBAAuB,CAAC;IAuCnC;;;OAGG;IACG,iBAAiB,CACrB,qBAAqB,EAAE,MAAM,EAC7B,OAAO,EAAE,aAAa,EACtB,MAAM,EAAE,MAAM,CAAC,MAAM,GACpB,OAAO,CAAC,MAAM,CAAC,2BAA2B,CAAC;IAS9C,6EAA6E;IACvE,wBAAwB,CAC5B,MAAM,EAAE,MAAM,EACd,cAAc,CAAC,EAAE,MAAM,GACtB,OAAO,CAAC,kBAAkB,CAAC;CAqB/B"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ContractInteractionClient = void 0;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
const contracts_1 = require("./contracts");
|
|
6
|
+
const ARC402_WALLET_EXECUTE_ABI = [
|
|
7
|
+
"function executeContractCall((address target, bytes data, uint256 value, uint256 minReturnValue, uint256 maxApprovalAmount, address approvalToken) params) external returns (bytes memory)",
|
|
8
|
+
];
|
|
9
|
+
class ContractInteractionClient {
|
|
10
|
+
constructor(intentAttestationAddress, runner, walletAddress) {
|
|
11
|
+
this.walletAddress = walletAddress;
|
|
12
|
+
this.intentContract = new ethers_1.ethers.Contract(intentAttestationAddress, contracts_1.INTENT_ATTESTATION_ABI, runner);
|
|
13
|
+
this.provider = runner.provider ?? runner;
|
|
14
|
+
}
|
|
15
|
+
/** Encode a contract method call into an IntentPayload ready for on-chain execution. */
|
|
16
|
+
buildContractCall(target, abi, method, args, options = {}) {
|
|
17
|
+
const iface = new ethers_1.ethers.Interface(abi);
|
|
18
|
+
const data = iface.encodeFunctionData(method, args);
|
|
19
|
+
return {
|
|
20
|
+
target,
|
|
21
|
+
data,
|
|
22
|
+
value: options.value ?? 0n,
|
|
23
|
+
minReturnValue: options.minReturnValue ?? 0n,
|
|
24
|
+
maxApprovalAmount: options.maxApprovalAmount ?? 0n,
|
|
25
|
+
approvalToken: options.approvalToken ?? ethers_1.ethers.ZeroAddress,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Create an intent attestation for the contract call. Records agent intent
|
|
30
|
+
* on-chain before execution — provides auditable pre-execution evidence.
|
|
31
|
+
*/
|
|
32
|
+
async signAndAttestContractCall(payload, signer) {
|
|
33
|
+
const methodSelector = payload.data.slice(0, 10); // 4-byte selector
|
|
34
|
+
const action = `CONTRACT_CALL:${payload.target}:${methodSelector}`;
|
|
35
|
+
const reason = `Executing contract call to ${payload.target} with value=${payload.value}`;
|
|
36
|
+
const attestationId = ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(`${this.walletAddress}:${action}:${reason}:${payload.target}:${payload.value}:${Date.now()}`));
|
|
37
|
+
const contractWithSigner = this.intentContract.connect(signer);
|
|
38
|
+
const tx = await contractWithSigner.attest(attestationId, action, reason, payload.target, payload.value);
|
|
39
|
+
await tx.wait();
|
|
40
|
+
const [id, wallet, attestedAction, attestedReason, recipient, amount, timestamp] = await this.intentContract.getAttestation(attestationId);
|
|
41
|
+
const intent = {
|
|
42
|
+
attestationId: id,
|
|
43
|
+
wallet,
|
|
44
|
+
action: attestedAction,
|
|
45
|
+
reason: attestedReason,
|
|
46
|
+
recipient,
|
|
47
|
+
amount: BigInt(amount),
|
|
48
|
+
timestamp: Number(timestamp),
|
|
49
|
+
};
|
|
50
|
+
return { attestationId, intent, payload };
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Execute a contract call under a ServiceAgreement escrow via the ARC402Wallet.
|
|
54
|
+
* The wallet enforces PolicyEngine validation, per-tx approvals, and slippage guards.
|
|
55
|
+
*/
|
|
56
|
+
async executeWithEscrow(walletContractAddress, payload, signer) {
|
|
57
|
+
const walletContract = new ethers_1.ethers.Contract(walletContractAddress, ARC402_WALLET_EXECUTE_ABI, signer);
|
|
58
|
+
return walletContract.executeContractCall(payload, { value: payload.value });
|
|
59
|
+
}
|
|
60
|
+
/** Verify the result of a previously submitted contract call transaction. */
|
|
61
|
+
async verifyContractCallResult(txHash, expectedResult) {
|
|
62
|
+
const receipt = await this.provider.getTransactionReceipt(txHash);
|
|
63
|
+
if (!receipt) {
|
|
64
|
+
return { txHash, success: false };
|
|
65
|
+
}
|
|
66
|
+
const success = receipt.status === 1;
|
|
67
|
+
if (expectedResult && success) {
|
|
68
|
+
const tx = await this.provider.getTransaction(txHash);
|
|
69
|
+
const returnData = tx ? await this.provider.call({ to: tx.to, data: tx.data, blockTag: receipt.blockNumber }) : undefined;
|
|
70
|
+
return {
|
|
71
|
+
txHash,
|
|
72
|
+
success: returnData === expectedResult,
|
|
73
|
+
returnData,
|
|
74
|
+
blockNumber: receipt.blockNumber,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
return { txHash, success, blockNumber: receipt.blockNumber };
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.ContractInteractionClient = ContractInteractionClient;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Contract, ContractRunner } from "ethers";
|
|
2
|
+
export declare const POLICY_ENGINE_ABI: readonly ["function setPolicy(bytes32 policyHash, bytes policyData) external", "function getPolicy(address wallet) external view returns (bytes32, bytes)", "function setCategoryLimit(string category, uint256 limitPerTx) external", "function setCategoryLimitFor(address wallet, string category, uint256 limitPerTx) external", "function validateSpend(address wallet, string category, uint256 amount, bytes32 contextId) external view returns (bool, string)", "function categoryLimits(address wallet, string category) external view returns (uint256)", "function registerWallet(address wallet, address owner) external", "function freezeSpend(address wallet) external", "function unfreeze(address wallet) external", "function authorizeFreezeAgent(address agent) external", "function revokeFreezeAgent(address agent) external", "function queueCapReduction(address wallet, string category, uint256 newCap) external", "function applyCapReduction(address wallet, string category) external"];
|
|
3
|
+
export declare const TRUST_REGISTRY_ABI: readonly ["function getScore(address wallet) external view returns (uint256)", "function getEffectiveScore(address wallet) external view returns (uint256)", "function getTrustLevel(address wallet) external view returns (string)", "function initWallet(address wallet) external", "function recordSuccess(address wallet) external", "function recordAnomaly(address wallet) external"];
|
|
4
|
+
export declare const INTENT_ATTESTATION_ABI: readonly ["function attest(bytes32 attestationId, string action, string reason, address recipient, uint256 amount) external", "function verify(bytes32 attestationId, address wallet) external view returns (bool)", "function getAttestation(bytes32 attestationId) external view returns (bytes32, address, string, string, address, uint256, uint256)", "event AttestationCreated(bytes32 indexed id, address indexed wallet, string action, string reason, address recipient, uint256 amount, uint256 timestamp)"];
|
|
5
|
+
export declare const ARC402_WALLET_ABI: readonly ["function openContext(bytes32 contextId, string taskType) external", "function closeContext() external", "function executeSpend(address recipient, uint256 amount, string category, bytes32 attestationId) external", "function getTrustScore() external view returns (uint256)", "function getActiveContext() external view returns (bytes32, string, uint256, bool)", "function updatePolicy(bytes32 newPolicyId) external"];
|
|
6
|
+
export declare const SETTLEMENT_COORDINATOR_ABI: readonly ["function propose(address fromWallet, address toWallet, uint256 amount, bytes32 intentId, uint256 expiresAt) external returns (bytes32)", "function accept(bytes32 proposalId) external", "function reject(bytes32 proposalId, string reason) external", "function execute(bytes32 proposalId) external payable", "function checkExpiry(bytes32 proposalId) external", "function getProposal(bytes32 proposalId) external view returns (address, address, uint256, bytes32, uint256, uint8, string)", "event ProposalCreated(bytes32 indexed proposalId, address indexed from, address indexed to, uint256 amount)"];
|
|
7
|
+
export declare const WALLET_FACTORY_ABI: readonly ["function createWallet() external returns (address)", "function getWallets(address owner) external view returns (address[])", "event WalletCreated(address indexed owner, address indexed walletAddress)"];
|
|
8
|
+
export declare const AGENT_REGISTRY_ABI: readonly ["function register(string name, string[] capabilities, string serviceType, string endpoint, string metadataURI) external", "function update(string name, string[] capabilities, string serviceType, string endpoint, string metadataURI) external", "function deactivate() external", "function reactivate() external", "function submitHeartbeat(uint32 latencyMs) external", "function setHeartbeatPolicy(uint64 interval, uint64 gracePeriod) external", "function getAgent(address wallet) external view returns (tuple(address wallet, string name, string[] capabilities, string serviceType, string endpoint, string metadataURI, bool active, uint256 registeredAt, uint256 endpointChangedAt, uint256 endpointChangeCount))", "function getOperationalMetrics(address wallet) external view returns (tuple(uint64 heartbeatInterval, uint64 heartbeatGracePeriod, uint64 lastHeartbeatAt, uint64 rollingLatency, uint32 heartbeatCount, uint32 missedHeartbeatCount, uint32 uptimeScore, uint32 responseScore))", "function isRegistered(address wallet) external view returns (bool)", "function isActive(address wallet) external view returns (bool)", "function getCapabilities(address wallet) external view returns (string[])", "function getTrustScore(address wallet) external view returns (uint256)", "function getEndpointStability(address wallet) external view returns (uint256)", "function agentCount() external view returns (uint256)", "function getAgentAtIndex(uint256 index) external view returns (address)"];
|
|
9
|
+
export declare const SERVICE_AGREEMENT_ABI: readonly ["function propose(address provider, string serviceType, string description, uint256 price, address token, uint256 deadline, bytes32 deliverablesHash) external payable returns (uint256)", "function accept(uint256 agreementId) external", "function fulfill(uint256 agreementId, bytes32 actualDeliverablesHash) external", "function commitDeliverable(uint256 agreementId, bytes32 deliverableHash) external", "function verifyDeliverable(uint256 agreementId) external", "function autoRelease(uint256 agreementId) external", "function dispute(uint256 agreementId, string reason) external", "function directDispute(uint256 agreementId, uint8 directReason, string reason) external", "function requestRevision(uint256 agreementId, bytes32 feedbackHash, string feedbackURI, bytes32 previousTranscriptHash) external", "function respondToRevision(uint256 agreementId, uint8 responseType, uint256 proposedProviderPayout, bytes32 responseHash, string responseURI, bytes32 previousTranscriptHash) external", "function escalateToDispute(uint256 agreementId, string reason) external", "function canDirectDispute(uint256 agreementId, uint8 directReason) external view returns (bool)", "function submitDisputeEvidence(uint256 agreementId, uint8 evidenceType, bytes32 evidenceHash, string evidenceURI) external", "function nominateArbitrator(uint256 agreementId, address arbitrator) external", "function castArbitrationVote(uint256 agreementId, uint8 vote, uint256 providerAward, uint256 clientAward) external", "function requestHumanEscalation(uint256 agreementId, string reason) external", "function resolveDisputeDetailed(uint256 agreementId, uint8 outcome, uint256 providerAward, uint256 clientAward) external", "function cancel(uint256 agreementId) external", "function expiredCancel(uint256 agreementId) external", "function resolveDispute(uint256 agreementId, bool favorProvider) external", "function getAgreement(uint256 id) external view returns (tuple(uint256 id, address client, address provider, string serviceType, string description, uint256 price, address token, uint256 deadline, bytes32 deliverablesHash, uint8 status, uint256 createdAt, uint256 resolvedAt, uint256 verifyWindowEnd, bytes32 committedHash))", "function getRemediationCase(uint256 agreementId) external view returns (tuple(uint8 cycleCount, uint256 openedAt, uint256 deadlineAt, uint256 lastActionAt, bytes32 latestTranscriptHash, bool active))", "function getRemediationFeedback(uint256 agreementId, uint256 index) external view returns (tuple(uint8 cycle, address author, bytes32 feedbackHash, string feedbackURI, bytes32 previousTranscriptHash, bytes32 transcriptHash, uint256 timestamp))", "function getRemediationResponse(uint256 agreementId, uint256 index) external view returns (tuple(uint8 cycle, address author, uint8 responseType, uint256 proposedProviderPayout, bytes32 responseHash, string responseURI, bytes32 previousTranscriptHash, bytes32 transcriptHash, uint256 timestamp))", "function getDisputeCase(uint256 agreementId) external view returns (tuple(uint256 agreementId, uint256 openedAt, uint256 responseDeadlineAt, uint8 outcome, uint256 providerAward, uint256 clientAward, bool humanReviewRequested, uint256 evidenceCount))", "function getDisputeEvidence(uint256 agreementId, uint256 index) external view returns (tuple(address submitter, uint8 evidenceType, bytes32 evidenceHash, string evidenceURI, uint256 timestamp))", "function getArbitrationCase(uint256 agreementId) external view returns (tuple(uint256 agreementId, address[3] arbitrators, uint8 arbitratorCount, uint8 providerVotes, uint8 clientVotes, uint8 splitVotes, uint8 humanVotes, uint256 selectionDeadlineAt, uint256 decisionDeadlineAt, uint256 splitProviderAward, uint256 splitClientAward, bool finalized, bool humanBackstopUsed))", "function getAgreementsByClient(address client) external view returns (uint256[])", "function getAgreementsByProvider(address provider) external view returns (uint256[])", "function agreementCount() external view returns (uint256)", "function openSessionChannel(address provider, address token, uint256 maxAmount, uint256 ratePerCall, uint256 deadline) external payable returns (bytes32 channelId)", "function closeChannel(bytes32 channelId, bytes finalState) external", "function challengeChannel(bytes32 channelId, bytes latestState) external", "function finaliseChallenge(bytes32 channelId) external", "function reclaimExpiredChannel(bytes32 channelId) external", "function getChannel(bytes32 channelId) external view returns (tuple(address client, address provider, address token, uint256 depositAmount, uint256 settledAmount, uint256 lastSequenceNumber, uint256 deadline, uint256 challengeExpiry, uint8 status))", "function getChannelsByClient(address client) external view returns (bytes32[])", "function getChannelsByProvider(address provider) external view returns (bytes32[])", "function resolveFromArbitration(uint256 agreementId, address recipient, uint256 providerAmount, uint256 clientAmount) external", "function ownerResolveDispute(uint256 agreementId, bool favorProvider) external", "event AgreementProposed(uint256 indexed id, address indexed client, address indexed provider, string serviceType, uint256 price, address token, uint256 deadline)"];
|
|
10
|
+
export declare const REPUTATION_ORACLE_ABI: readonly ["function publishSignal(address subject, uint8 signalType, bytes32 capabilityHash, string reason) external", "function getReputation(address subject) external view returns (uint256, uint256, uint256, uint256)", "function getCapabilityReputation(address subject, bytes32 capabilityHash) external view returns (uint256)", "function getSignalCount(address subject) external view returns (uint256)", "function getSignal(address subject, uint256 index) external view returns (tuple(address publisher, address subject, uint8 signalType, bytes32 capabilityHash, string reason, uint256 publisherTrustAtTime, uint256 timestamp, bool autoPublished))"];
|
|
11
|
+
export declare const SPONSORSHIP_ATTESTATION_ABI: readonly ["function publish(address agent, uint256 expiresAt) external returns (bytes32)", "function publishWithTier(address agent, uint256 expiresAt, uint8 tier, string evidenceURI) external returns (bytes32)", "function revoke(bytes32 attestationId) external", "function isActive(bytes32 attestationId) external view returns (bool)", "function getActiveAttestation(address sponsor, address agent) external view returns (bytes32)", "function getAttestation(bytes32 attestationId) external view returns (tuple(address sponsor, address agent, uint256 issuedAt, uint256 expiresAt, bool revoked, uint8 tier, string evidenceURI))", "function getSponsorAttestations(address sponsor) external view returns (bytes32[])", "function getAgentAttestations(address agent) external view returns (bytes32[])", "function activeSponsorCount(address sponsor) external view returns (uint256)", "function getHighestTier(address agent) external view returns (uint8)"];
|
|
12
|
+
export declare const CAPABILITY_REGISTRY_ABI: readonly ["function registerRoot(string root) external returns (bytes32)", "function setRootStatus(string root, bool active) external", "function claim(string capability) external", "function revoke(string capability) external", "function isRootActive(string root) external view returns (bool)", "function getRoot(string root) external view returns (tuple(bytes32 rootId, string root, bool active))", "function rootCount() external view returns (uint256)", "function getRootAt(uint256 index) external view returns (tuple(bytes32 rootId, string root, bool active))", "function getCapabilities(address agent) external view returns (string[])", "function capabilityCount(address agent) external view returns (uint256)", "function isCapabilityClaimed(address agent, string capability) external view returns (bool)"];
|
|
13
|
+
export declare const GOVERNANCE_ABI: readonly ["function submitTransaction(address target, uint256 value, bytes data) external returns (uint256)", "function confirmTransaction(uint256 txId) external", "function revokeConfirmation(uint256 txId) external", "function executeTransaction(uint256 txId) external returns (bytes)", "function getTransaction(uint256 txId) external view returns (tuple(address target, uint256 value, bytes data, bool executed, uint256 confirmationCount))", "function transactionCount() external view returns (uint256)"];
|
|
14
|
+
export declare const AGREEMENT_TREE_ABI: readonly ["function registerSubAgreement(uint256 parentAgreementId, uint256 childAgreementId) external", "function getChildren(uint256 agreementId) external view returns (uint256[])", "function getRoot(uint256 agreementId) external view returns (uint256)", "function getPath(uint256 agreementId) external view returns (uint256[])", "function allChildrenSettled(uint256 agreementId) external view returns (bool)", "function getDepth(uint256 agreementId) external view returns (uint256)"];
|
|
15
|
+
export declare const getPolicyEngine: (address: string, runner: ContractRunner) => Contract;
|
|
16
|
+
export declare const getTrustRegistry: (address: string, runner: ContractRunner) => Contract;
|
|
17
|
+
export declare const getIntentAttestation: (address: string, runner: ContractRunner) => Contract;
|
|
18
|
+
export declare const getARC402Wallet: (address: string, runner: ContractRunner) => Contract;
|
|
19
|
+
export declare const getSettlementCoordinator: (address: string, runner: ContractRunner) => Contract;
|
|
20
|
+
export declare const getWalletFactory: (address: string, runner: ContractRunner) => Contract;
|
|
21
|
+
export declare const getAgentRegistry: (address: string, runner: ContractRunner) => Contract;
|
|
22
|
+
export declare const getServiceAgreement: (address: string, runner: ContractRunner) => Contract;
|
|
23
|
+
export declare const getReputationOracle: (address: string, runner: ContractRunner) => Contract;
|
|
24
|
+
export declare const getSponsorshipAttestation: (address: string, runner: ContractRunner) => Contract;
|
|
25
|
+
export declare const getCapabilityRegistry: (address: string, runner: ContractRunner) => Contract;
|
|
26
|
+
export declare const getGovernance: (address: string, runner: ContractRunner) => Contract;
|
|
27
|
+
//# sourceMappingURL=contracts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contracts.d.ts","sourceRoot":"","sources":["../src/contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAElD,eAAO,MAAM,iBAAiB,s9BAcpB,CAAC;AAEX,eAAO,MAAM,kBAAkB,6XAOrB,CAAC;AAEX,eAAO,MAAM,sBAAsB,wfAKzB,CAAC;AAEX,eAAO,MAAM,iBAAiB,0aAOpB,CAAC;AAEX,eAAO,MAAM,0BAA0B,gmBAQ7B,CAAC;AAEX,eAAO,MAAM,kBAAkB,sNAIrB,CAAC;AAEX,eAAO,MAAM,kBAAkB,09CAgBrB,CAAC;AAEX,eAAO,MAAM,qBAAqB,woKA0CxB,CAAC;AAEX,eAAO,MAAM,qBAAqB,6oBAMxB,CAAC;AAEX,eAAO,MAAM,2BAA2B,q7BAW9B,CAAC;AAEX,eAAO,MAAM,uBAAuB,6yBAY1B,CAAC;AAEX,eAAO,MAAM,cAAc,4fAOjB,CAAC;AAEX,eAAO,MAAM,kBAAkB,weAOrB,CAAC;AAEX,eAAO,MAAM,eAAe,GAAI,SAAS,MAAM,EAAE,QAAQ,cAAc,aAAqD,CAAC;AAC7H,eAAO,MAAM,gBAAgB,GAAI,SAAS,MAAM,EAAE,QAAQ,cAAc,aAAsD,CAAC;AAC/H,eAAO,MAAM,oBAAoB,GAAI,SAAS,MAAM,EAAE,QAAQ,cAAc,aAA0D,CAAC;AACvI,eAAO,MAAM,eAAe,GAAI,SAAS,MAAM,EAAE,QAAQ,cAAc,aAAqD,CAAC;AAC7H,eAAO,MAAM,wBAAwB,GAAI,SAAS,MAAM,EAAE,QAAQ,cAAc,aAA8D,CAAC;AAC/I,eAAO,MAAM,gBAAgB,GAAI,SAAS,MAAM,EAAE,QAAQ,cAAc,aAAsD,CAAC;AAC/H,eAAO,MAAM,gBAAgB,GAAI,SAAS,MAAM,EAAE,QAAQ,cAAc,aAAsD,CAAC;AAC/H,eAAO,MAAM,mBAAmB,GAAI,SAAS,MAAM,EAAE,QAAQ,cAAc,aAAyD,CAAC;AACrI,eAAO,MAAM,mBAAmB,GAAI,SAAS,MAAM,EAAE,QAAQ,cAAc,aAAyD,CAAC;AACrI,eAAO,MAAM,yBAAyB,GAAI,SAAS,MAAM,EAAE,QAAQ,cAAc,aAA+D,CAAC;AACjJ,eAAO,MAAM,qBAAqB,GAAI,SAAS,MAAM,EAAE,QAAQ,cAAc,aAA2D,CAAC;AACzI,eAAO,MAAM,aAAa,GAAI,SAAS,MAAM,EAAE,QAAQ,cAAc,aAAkD,CAAC"}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getGovernance = exports.getCapabilityRegistry = exports.getSponsorshipAttestation = exports.getReputationOracle = exports.getServiceAgreement = exports.getAgentRegistry = exports.getWalletFactory = exports.getSettlementCoordinator = exports.getARC402Wallet = exports.getIntentAttestation = exports.getTrustRegistry = exports.getPolicyEngine = exports.AGREEMENT_TREE_ABI = exports.GOVERNANCE_ABI = exports.CAPABILITY_REGISTRY_ABI = exports.SPONSORSHIP_ATTESTATION_ABI = exports.REPUTATION_ORACLE_ABI = exports.SERVICE_AGREEMENT_ABI = exports.AGENT_REGISTRY_ABI = exports.WALLET_FACTORY_ABI = exports.SETTLEMENT_COORDINATOR_ABI = exports.ARC402_WALLET_ABI = exports.INTENT_ATTESTATION_ABI = exports.TRUST_REGISTRY_ABI = exports.POLICY_ENGINE_ABI = void 0;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
exports.POLICY_ENGINE_ABI = [
|
|
6
|
+
"function setPolicy(bytes32 policyHash, bytes policyData) external",
|
|
7
|
+
"function getPolicy(address wallet) external view returns (bytes32, bytes)",
|
|
8
|
+
"function setCategoryLimit(string category, uint256 limitPerTx) external",
|
|
9
|
+
"function setCategoryLimitFor(address wallet, string category, uint256 limitPerTx) external",
|
|
10
|
+
"function validateSpend(address wallet, string category, uint256 amount, bytes32 contextId) external view returns (bool, string)",
|
|
11
|
+
"function categoryLimits(address wallet, string category) external view returns (uint256)",
|
|
12
|
+
"function registerWallet(address wallet, address owner) external",
|
|
13
|
+
"function freezeSpend(address wallet) external",
|
|
14
|
+
"function unfreeze(address wallet) external",
|
|
15
|
+
"function authorizeFreezeAgent(address agent) external",
|
|
16
|
+
"function revokeFreezeAgent(address agent) external",
|
|
17
|
+
"function queueCapReduction(address wallet, string category, uint256 newCap) external",
|
|
18
|
+
"function applyCapReduction(address wallet, string category) external",
|
|
19
|
+
];
|
|
20
|
+
exports.TRUST_REGISTRY_ABI = [
|
|
21
|
+
"function getScore(address wallet) external view returns (uint256)",
|
|
22
|
+
"function getEffectiveScore(address wallet) external view returns (uint256)",
|
|
23
|
+
"function getTrustLevel(address wallet) external view returns (string)",
|
|
24
|
+
"function initWallet(address wallet) external",
|
|
25
|
+
"function recordSuccess(address wallet) external",
|
|
26
|
+
"function recordAnomaly(address wallet) external",
|
|
27
|
+
];
|
|
28
|
+
exports.INTENT_ATTESTATION_ABI = [
|
|
29
|
+
"function attest(bytes32 attestationId, string action, string reason, address recipient, uint256 amount) external",
|
|
30
|
+
"function verify(bytes32 attestationId, address wallet) external view returns (bool)",
|
|
31
|
+
"function getAttestation(bytes32 attestationId) external view returns (bytes32, address, string, string, address, uint256, uint256)",
|
|
32
|
+
"event AttestationCreated(bytes32 indexed id, address indexed wallet, string action, string reason, address recipient, uint256 amount, uint256 timestamp)",
|
|
33
|
+
];
|
|
34
|
+
exports.ARC402_WALLET_ABI = [
|
|
35
|
+
"function openContext(bytes32 contextId, string taskType) external",
|
|
36
|
+
"function closeContext() external",
|
|
37
|
+
"function executeSpend(address recipient, uint256 amount, string category, bytes32 attestationId) external",
|
|
38
|
+
"function getTrustScore() external view returns (uint256)",
|
|
39
|
+
"function getActiveContext() external view returns (bytes32, string, uint256, bool)",
|
|
40
|
+
"function updatePolicy(bytes32 newPolicyId) external",
|
|
41
|
+
];
|
|
42
|
+
exports.SETTLEMENT_COORDINATOR_ABI = [
|
|
43
|
+
"function propose(address fromWallet, address toWallet, uint256 amount, bytes32 intentId, uint256 expiresAt) external returns (bytes32)",
|
|
44
|
+
"function accept(bytes32 proposalId) external",
|
|
45
|
+
"function reject(bytes32 proposalId, string reason) external",
|
|
46
|
+
"function execute(bytes32 proposalId) external payable",
|
|
47
|
+
"function checkExpiry(bytes32 proposalId) external",
|
|
48
|
+
"function getProposal(bytes32 proposalId) external view returns (address, address, uint256, bytes32, uint256, uint8, string)",
|
|
49
|
+
"event ProposalCreated(bytes32 indexed proposalId, address indexed from, address indexed to, uint256 amount)",
|
|
50
|
+
];
|
|
51
|
+
exports.WALLET_FACTORY_ABI = [
|
|
52
|
+
"function createWallet() external returns (address)",
|
|
53
|
+
"function getWallets(address owner) external view returns (address[])",
|
|
54
|
+
"event WalletCreated(address indexed owner, address indexed walletAddress)",
|
|
55
|
+
];
|
|
56
|
+
exports.AGENT_REGISTRY_ABI = [
|
|
57
|
+
"function register(string name, string[] capabilities, string serviceType, string endpoint, string metadataURI) external",
|
|
58
|
+
"function update(string name, string[] capabilities, string serviceType, string endpoint, string metadataURI) external",
|
|
59
|
+
"function deactivate() external",
|
|
60
|
+
"function reactivate() external",
|
|
61
|
+
"function submitHeartbeat(uint32 latencyMs) external",
|
|
62
|
+
"function setHeartbeatPolicy(uint64 interval, uint64 gracePeriod) external",
|
|
63
|
+
"function getAgent(address wallet) external view returns (tuple(address wallet, string name, string[] capabilities, string serviceType, string endpoint, string metadataURI, bool active, uint256 registeredAt, uint256 endpointChangedAt, uint256 endpointChangeCount))",
|
|
64
|
+
"function getOperationalMetrics(address wallet) external view returns (tuple(uint64 heartbeatInterval, uint64 heartbeatGracePeriod, uint64 lastHeartbeatAt, uint64 rollingLatency, uint32 heartbeatCount, uint32 missedHeartbeatCount, uint32 uptimeScore, uint32 responseScore))",
|
|
65
|
+
"function isRegistered(address wallet) external view returns (bool)",
|
|
66
|
+
"function isActive(address wallet) external view returns (bool)",
|
|
67
|
+
"function getCapabilities(address wallet) external view returns (string[])",
|
|
68
|
+
"function getTrustScore(address wallet) external view returns (uint256)",
|
|
69
|
+
"function getEndpointStability(address wallet) external view returns (uint256)",
|
|
70
|
+
"function agentCount() external view returns (uint256)",
|
|
71
|
+
"function getAgentAtIndex(uint256 index) external view returns (address)",
|
|
72
|
+
];
|
|
73
|
+
exports.SERVICE_AGREEMENT_ABI = [
|
|
74
|
+
"function propose(address provider, string serviceType, string description, uint256 price, address token, uint256 deadline, bytes32 deliverablesHash) external payable returns (uint256)",
|
|
75
|
+
"function accept(uint256 agreementId) external",
|
|
76
|
+
"function fulfill(uint256 agreementId, bytes32 actualDeliverablesHash) external",
|
|
77
|
+
"function commitDeliverable(uint256 agreementId, bytes32 deliverableHash) external",
|
|
78
|
+
"function verifyDeliverable(uint256 agreementId) external",
|
|
79
|
+
"function autoRelease(uint256 agreementId) external",
|
|
80
|
+
"function dispute(uint256 agreementId, string reason) external",
|
|
81
|
+
"function directDispute(uint256 agreementId, uint8 directReason, string reason) external",
|
|
82
|
+
"function requestRevision(uint256 agreementId, bytes32 feedbackHash, string feedbackURI, bytes32 previousTranscriptHash) external",
|
|
83
|
+
"function respondToRevision(uint256 agreementId, uint8 responseType, uint256 proposedProviderPayout, bytes32 responseHash, string responseURI, bytes32 previousTranscriptHash) external",
|
|
84
|
+
"function escalateToDispute(uint256 agreementId, string reason) external",
|
|
85
|
+
"function canDirectDispute(uint256 agreementId, uint8 directReason) external view returns (bool)",
|
|
86
|
+
"function submitDisputeEvidence(uint256 agreementId, uint8 evidenceType, bytes32 evidenceHash, string evidenceURI) external",
|
|
87
|
+
"function nominateArbitrator(uint256 agreementId, address arbitrator) external",
|
|
88
|
+
"function castArbitrationVote(uint256 agreementId, uint8 vote, uint256 providerAward, uint256 clientAward) external",
|
|
89
|
+
"function requestHumanEscalation(uint256 agreementId, string reason) external",
|
|
90
|
+
"function resolveDisputeDetailed(uint256 agreementId, uint8 outcome, uint256 providerAward, uint256 clientAward) external",
|
|
91
|
+
"function cancel(uint256 agreementId) external",
|
|
92
|
+
"function expiredCancel(uint256 agreementId) external",
|
|
93
|
+
"function resolveDispute(uint256 agreementId, bool favorProvider) external",
|
|
94
|
+
"function getAgreement(uint256 id) external view returns (tuple(uint256 id, address client, address provider, string serviceType, string description, uint256 price, address token, uint256 deadline, bytes32 deliverablesHash, uint8 status, uint256 createdAt, uint256 resolvedAt, uint256 verifyWindowEnd, bytes32 committedHash))",
|
|
95
|
+
"function getRemediationCase(uint256 agreementId) external view returns (tuple(uint8 cycleCount, uint256 openedAt, uint256 deadlineAt, uint256 lastActionAt, bytes32 latestTranscriptHash, bool active))",
|
|
96
|
+
"function getRemediationFeedback(uint256 agreementId, uint256 index) external view returns (tuple(uint8 cycle, address author, bytes32 feedbackHash, string feedbackURI, bytes32 previousTranscriptHash, bytes32 transcriptHash, uint256 timestamp))",
|
|
97
|
+
"function getRemediationResponse(uint256 agreementId, uint256 index) external view returns (tuple(uint8 cycle, address author, uint8 responseType, uint256 proposedProviderPayout, bytes32 responseHash, string responseURI, bytes32 previousTranscriptHash, bytes32 transcriptHash, uint256 timestamp))",
|
|
98
|
+
"function getDisputeCase(uint256 agreementId) external view returns (tuple(uint256 agreementId, uint256 openedAt, uint256 responseDeadlineAt, uint8 outcome, uint256 providerAward, uint256 clientAward, bool humanReviewRequested, uint256 evidenceCount))",
|
|
99
|
+
"function getDisputeEvidence(uint256 agreementId, uint256 index) external view returns (tuple(address submitter, uint8 evidenceType, bytes32 evidenceHash, string evidenceURI, uint256 timestamp))",
|
|
100
|
+
"function getArbitrationCase(uint256 agreementId) external view returns (tuple(uint256 agreementId, address[3] arbitrators, uint8 arbitratorCount, uint8 providerVotes, uint8 clientVotes, uint8 splitVotes, uint8 humanVotes, uint256 selectionDeadlineAt, uint256 decisionDeadlineAt, uint256 splitProviderAward, uint256 splitClientAward, bool finalized, bool humanBackstopUsed))",
|
|
101
|
+
"function getAgreementsByClient(address client) external view returns (uint256[])",
|
|
102
|
+
"function getAgreementsByProvider(address provider) external view returns (uint256[])",
|
|
103
|
+
"function agreementCount() external view returns (uint256)",
|
|
104
|
+
"function openSessionChannel(address provider, address token, uint256 maxAmount, uint256 ratePerCall, uint256 deadline) external payable returns (bytes32 channelId)",
|
|
105
|
+
"function closeChannel(bytes32 channelId, bytes finalState) external",
|
|
106
|
+
"function challengeChannel(bytes32 channelId, bytes latestState) external",
|
|
107
|
+
"function finaliseChallenge(bytes32 channelId) external",
|
|
108
|
+
"function reclaimExpiredChannel(bytes32 channelId) external",
|
|
109
|
+
"function getChannel(bytes32 channelId) external view returns (tuple(address client, address provider, address token, uint256 depositAmount, uint256 settledAmount, uint256 lastSequenceNumber, uint256 deadline, uint256 challengeExpiry, uint8 status))",
|
|
110
|
+
"function getChannelsByClient(address client) external view returns (bytes32[])",
|
|
111
|
+
"function getChannelsByProvider(address provider) external view returns (bytes32[])",
|
|
112
|
+
"function resolveFromArbitration(uint256 agreementId, address recipient, uint256 providerAmount, uint256 clientAmount) external",
|
|
113
|
+
"function ownerResolveDispute(uint256 agreementId, bool favorProvider) external",
|
|
114
|
+
"event AgreementProposed(uint256 indexed id, address indexed client, address indexed provider, string serviceType, uint256 price, address token, uint256 deadline)",
|
|
115
|
+
];
|
|
116
|
+
exports.REPUTATION_ORACLE_ABI = [
|
|
117
|
+
"function publishSignal(address subject, uint8 signalType, bytes32 capabilityHash, string reason) external",
|
|
118
|
+
"function getReputation(address subject) external view returns (uint256, uint256, uint256, uint256)",
|
|
119
|
+
"function getCapabilityReputation(address subject, bytes32 capabilityHash) external view returns (uint256)",
|
|
120
|
+
"function getSignalCount(address subject) external view returns (uint256)",
|
|
121
|
+
"function getSignal(address subject, uint256 index) external view returns (tuple(address publisher, address subject, uint8 signalType, bytes32 capabilityHash, string reason, uint256 publisherTrustAtTime, uint256 timestamp, bool autoPublished))",
|
|
122
|
+
];
|
|
123
|
+
exports.SPONSORSHIP_ATTESTATION_ABI = [
|
|
124
|
+
"function publish(address agent, uint256 expiresAt) external returns (bytes32)",
|
|
125
|
+
"function publishWithTier(address agent, uint256 expiresAt, uint8 tier, string evidenceURI) external returns (bytes32)",
|
|
126
|
+
"function revoke(bytes32 attestationId) external",
|
|
127
|
+
"function isActive(bytes32 attestationId) external view returns (bool)",
|
|
128
|
+
"function getActiveAttestation(address sponsor, address agent) external view returns (bytes32)",
|
|
129
|
+
"function getAttestation(bytes32 attestationId) external view returns (tuple(address sponsor, address agent, uint256 issuedAt, uint256 expiresAt, bool revoked, uint8 tier, string evidenceURI))",
|
|
130
|
+
"function getSponsorAttestations(address sponsor) external view returns (bytes32[])",
|
|
131
|
+
"function getAgentAttestations(address agent) external view returns (bytes32[])",
|
|
132
|
+
"function activeSponsorCount(address sponsor) external view returns (uint256)",
|
|
133
|
+
"function getHighestTier(address agent) external view returns (uint8)",
|
|
134
|
+
];
|
|
135
|
+
exports.CAPABILITY_REGISTRY_ABI = [
|
|
136
|
+
"function registerRoot(string root) external returns (bytes32)",
|
|
137
|
+
"function setRootStatus(string root, bool active) external",
|
|
138
|
+
"function claim(string capability) external",
|
|
139
|
+
"function revoke(string capability) external",
|
|
140
|
+
"function isRootActive(string root) external view returns (bool)",
|
|
141
|
+
"function getRoot(string root) external view returns (tuple(bytes32 rootId, string root, bool active))",
|
|
142
|
+
"function rootCount() external view returns (uint256)",
|
|
143
|
+
"function getRootAt(uint256 index) external view returns (tuple(bytes32 rootId, string root, bool active))",
|
|
144
|
+
"function getCapabilities(address agent) external view returns (string[])",
|
|
145
|
+
"function capabilityCount(address agent) external view returns (uint256)",
|
|
146
|
+
"function isCapabilityClaimed(address agent, string capability) external view returns (bool)",
|
|
147
|
+
];
|
|
148
|
+
exports.GOVERNANCE_ABI = [
|
|
149
|
+
"function submitTransaction(address target, uint256 value, bytes data) external returns (uint256)",
|
|
150
|
+
"function confirmTransaction(uint256 txId) external",
|
|
151
|
+
"function revokeConfirmation(uint256 txId) external",
|
|
152
|
+
"function executeTransaction(uint256 txId) external returns (bytes)",
|
|
153
|
+
"function getTransaction(uint256 txId) external view returns (tuple(address target, uint256 value, bytes data, bool executed, uint256 confirmationCount))",
|
|
154
|
+
"function transactionCount() external view returns (uint256)",
|
|
155
|
+
];
|
|
156
|
+
exports.AGREEMENT_TREE_ABI = [
|
|
157
|
+
"function registerSubAgreement(uint256 parentAgreementId, uint256 childAgreementId) external",
|
|
158
|
+
"function getChildren(uint256 agreementId) external view returns (uint256[])",
|
|
159
|
+
"function getRoot(uint256 agreementId) external view returns (uint256)",
|
|
160
|
+
"function getPath(uint256 agreementId) external view returns (uint256[])",
|
|
161
|
+
"function allChildrenSettled(uint256 agreementId) external view returns (bool)",
|
|
162
|
+
"function getDepth(uint256 agreementId) external view returns (uint256)",
|
|
163
|
+
];
|
|
164
|
+
const getPolicyEngine = (address, runner) => new ethers_1.Contract(address, exports.POLICY_ENGINE_ABI, runner);
|
|
165
|
+
exports.getPolicyEngine = getPolicyEngine;
|
|
166
|
+
const getTrustRegistry = (address, runner) => new ethers_1.Contract(address, exports.TRUST_REGISTRY_ABI, runner);
|
|
167
|
+
exports.getTrustRegistry = getTrustRegistry;
|
|
168
|
+
const getIntentAttestation = (address, runner) => new ethers_1.Contract(address, exports.INTENT_ATTESTATION_ABI, runner);
|
|
169
|
+
exports.getIntentAttestation = getIntentAttestation;
|
|
170
|
+
const getARC402Wallet = (address, runner) => new ethers_1.Contract(address, exports.ARC402_WALLET_ABI, runner);
|
|
171
|
+
exports.getARC402Wallet = getARC402Wallet;
|
|
172
|
+
const getSettlementCoordinator = (address, runner) => new ethers_1.Contract(address, exports.SETTLEMENT_COORDINATOR_ABI, runner);
|
|
173
|
+
exports.getSettlementCoordinator = getSettlementCoordinator;
|
|
174
|
+
const getWalletFactory = (address, runner) => new ethers_1.Contract(address, exports.WALLET_FACTORY_ABI, runner);
|
|
175
|
+
exports.getWalletFactory = getWalletFactory;
|
|
176
|
+
const getAgentRegistry = (address, runner) => new ethers_1.Contract(address, exports.AGENT_REGISTRY_ABI, runner);
|
|
177
|
+
exports.getAgentRegistry = getAgentRegistry;
|
|
178
|
+
const getServiceAgreement = (address, runner) => new ethers_1.Contract(address, exports.SERVICE_AGREEMENT_ABI, runner);
|
|
179
|
+
exports.getServiceAgreement = getServiceAgreement;
|
|
180
|
+
const getReputationOracle = (address, runner) => new ethers_1.Contract(address, exports.REPUTATION_ORACLE_ABI, runner);
|
|
181
|
+
exports.getReputationOracle = getReputationOracle;
|
|
182
|
+
const getSponsorshipAttestation = (address, runner) => new ethers_1.Contract(address, exports.SPONSORSHIP_ATTESTATION_ABI, runner);
|
|
183
|
+
exports.getSponsorshipAttestation = getSponsorshipAttestation;
|
|
184
|
+
const getCapabilityRegistry = (address, runner) => new ethers_1.Contract(address, exports.CAPABILITY_REGISTRY_ABI, runner);
|
|
185
|
+
exports.getCapabilityRegistry = getCapabilityRegistry;
|
|
186
|
+
const getGovernance = (address, runner) => new ethers_1.Contract(address, exports.GOVERNANCE_ABI, runner);
|
|
187
|
+
exports.getGovernance = getGovernance;
|