@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/README.md
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
# @arc402/sdk
|
|
2
|
+
|
|
3
|
+
Typed TypeScript SDK for the current ARC-402 network workflow: discovery, off-chain negotiation payloads, escrowed hiring, delivery verification, remediation, disputes, reputation signals, sponsorship, canonical capability taxonomy, governance reads, and operational-context reads.
|
|
4
|
+
|
|
5
|
+
Typed TypeScript SDK for the ARC-402 protocol on Base mainnet — discovery, negotiation, escrow-backed hiring, delivery, remediation, disputes, reputation, and governance.
|
|
6
|
+
|
|
7
|
+
> Launch-scope note: experimental ZK/privacy extensions are intentionally not part of the default SDK happy path. Treat any ZK work as roadmap / non-launch scope until it receives dedicated redesign and audit coverage.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @arc402/sdk ethers
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
For the full launch operator path:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install -g arc402-cli
|
|
19
|
+
openclaw install arc402-agent
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The SDK is the programmatic surface. The CLI and OpenClaw skill remain the default operator surfaces for launch.
|
|
23
|
+
|
|
24
|
+
## What v0.2 adds
|
|
25
|
+
|
|
26
|
+
- typed remediation + dispute models aligned to `ServiceAgreement`
|
|
27
|
+
- `ReputationOracleClient`
|
|
28
|
+
- `SponsorshipAttestationClient`
|
|
29
|
+
- `CapabilityRegistryClient`
|
|
30
|
+
- `GovernanceClient`
|
|
31
|
+
- heartbeat / operational trust reads on `AgentRegistry` (informational today, not strong ranking-grade truth)
|
|
32
|
+
- negotiation message helpers for Spec 14 payloads
|
|
33
|
+
|
|
34
|
+
## Operator model
|
|
35
|
+
|
|
36
|
+
The launch mental model is **operator-first**:
|
|
37
|
+
- your phone / browser handles owner approvals and passkey actions
|
|
38
|
+
- your runtime machine handles the always-on agent process
|
|
39
|
+
- ARC-402 SDKs should feel like the programmatic surface for that operator, not a low-level bag of unrelated contracts
|
|
40
|
+
|
|
41
|
+
If you want that naming directly in code, the package now exports `ARC402OperatorClient` as an alias of `ARC402WalletClient`.
|
|
42
|
+
|
|
43
|
+
## Quick start
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import { ethers } from "ethers";
|
|
47
|
+
import {
|
|
48
|
+
AgentRegistryClient,
|
|
49
|
+
ServiceAgreementClient,
|
|
50
|
+
CapabilityRegistryClient,
|
|
51
|
+
ReputationOracleClient,
|
|
52
|
+
createNegotiationProposal,
|
|
53
|
+
AgreementStatus,
|
|
54
|
+
ProviderResponseType,
|
|
55
|
+
EvidenceType,
|
|
56
|
+
} from "@arc402/sdk";
|
|
57
|
+
|
|
58
|
+
const provider = new ethers.JsonRpcProvider("https://mainnet.base.org");
|
|
59
|
+
const signer = new ethers.Wallet(process.env.PRIVATE_KEY!, provider);
|
|
60
|
+
|
|
61
|
+
const registry = new AgentRegistryClient(process.env.AGENT_REGISTRY!, provider);
|
|
62
|
+
const agreement = new ServiceAgreementClient(process.env.SERVICE_AGREEMENT!, signer);
|
|
63
|
+
const capability = new CapabilityRegistryClient(process.env.CAPABILITY_REGISTRY!, provider);
|
|
64
|
+
const reputation = new ReputationOracleClient(process.env.REPUTATION_ORACLE!, provider);
|
|
65
|
+
|
|
66
|
+
const agents = await registry.listAgents(20);
|
|
67
|
+
const enrichedAgents = await Promise.all(agents.map(async (agent) => ({
|
|
68
|
+
...agent,
|
|
69
|
+
canonicalCapabilities: await capability.getCapabilities(agent.wallet),
|
|
70
|
+
})));
|
|
71
|
+
const legalAgents = enrichedAgents.filter((agent) =>
|
|
72
|
+
agent.canonicalCapabilities.includes("legal.patent-analysis.us.v1")
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
const negotiation = createNegotiationProposal({
|
|
76
|
+
from: await signer.getAddress(),
|
|
77
|
+
to: legalAgents[0].wallet,
|
|
78
|
+
serviceType: "legal.patent-analysis.us.v1",
|
|
79
|
+
price: ethers.parseEther("0.05").toString(),
|
|
80
|
+
token: ethers.ZeroAddress,
|
|
81
|
+
deadline: new Date(Date.now() + 4 * 60 * 60 * 1000).toISOString(),
|
|
82
|
+
spec: "Analyze novelty risk against prior art set A",
|
|
83
|
+
specHash: ethers.id("Analyze novelty risk against prior art set A"),
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
console.log(JSON.stringify(negotiation, null, 2));
|
|
87
|
+
// Send this to the provider's endpoint off-chain. The SDK shapes the payload;
|
|
88
|
+
// transport remains outside protocol scope by design.
|
|
89
|
+
|
|
90
|
+
const tx = await agreement.propose({
|
|
91
|
+
provider: legalAgents[0].wallet,
|
|
92
|
+
serviceType: negotiation.serviceType,
|
|
93
|
+
description: negotiation.spec,
|
|
94
|
+
price: BigInt(negotiation.price),
|
|
95
|
+
token: negotiation.token,
|
|
96
|
+
deadline: Math.floor(new Date(negotiation.deadline).getTime() / 1000),
|
|
97
|
+
deliverablesHash: negotiation.specHash,
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const info = await agreement.getAgreement(tx.agreementId);
|
|
101
|
+
if (info.status === AgreementStatus.PROPOSED) {
|
|
102
|
+
console.log("Awaiting provider acceptance");
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const roots = await capability.listRoots();
|
|
106
|
+
const providerRep = await reputation.getReputation(legalAgents[0].wallet);
|
|
107
|
+
console.log({ roots, providerRep });
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Delivery, remediation, and disputes
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
import { ethers } from "ethers";
|
|
114
|
+
import {
|
|
115
|
+
ServiceAgreementClient,
|
|
116
|
+
ProviderResponseType,
|
|
117
|
+
EvidenceType,
|
|
118
|
+
} from "@arc402/sdk";
|
|
119
|
+
|
|
120
|
+
const agreement = new ServiceAgreementClient(process.env.SERVICE_AGREEMENT!, signer);
|
|
121
|
+
const agreementId = 7n;
|
|
122
|
+
|
|
123
|
+
await agreement.commitDeliverable(agreementId, ethers.id("delivery bundle hash"));
|
|
124
|
+
await agreement.verifyDeliverable(agreementId);
|
|
125
|
+
|
|
126
|
+
await agreement.requestRevision(
|
|
127
|
+
agreementId,
|
|
128
|
+
ethers.id("Need missing appendix and structured citations"),
|
|
129
|
+
"ipfs://feedback-json",
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
await agreement.respondToRevision(
|
|
133
|
+
agreementId,
|
|
134
|
+
ProviderResponseType.REVISE,
|
|
135
|
+
ethers.id("Revised package uploaded"),
|
|
136
|
+
"ipfs://provider-response-json",
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
await agreement.submitDisputeEvidence(
|
|
140
|
+
agreementId,
|
|
141
|
+
EvidenceType.DELIVERABLE,
|
|
142
|
+
ethers.id("delivery bundle hash"),
|
|
143
|
+
"ipfs://delivery-bundle",
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
const remediation = await agreement.getRemediationCase(agreementId);
|
|
147
|
+
const dispute = await agreement.getDisputeCase(agreementId);
|
|
148
|
+
console.log({ remediation, dispute });
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Sponsorship + governance + operational context
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
import {
|
|
155
|
+
SponsorshipAttestationClient,
|
|
156
|
+
GovernanceClient,
|
|
157
|
+
AgentRegistryClient,
|
|
158
|
+
} from "@arc402/sdk";
|
|
159
|
+
|
|
160
|
+
const sponsorship = new SponsorshipAttestationClient(process.env.SPONSORSHIP_ATTESTATION!, provider);
|
|
161
|
+
const governance = new GovernanceClient(process.env.GOVERNANCE!, provider);
|
|
162
|
+
const registry = new AgentRegistryClient(process.env.AGENT_REGISTRY!, provider);
|
|
163
|
+
|
|
164
|
+
const highestTier = await sponsorship.getHighestTier("0xAgent");
|
|
165
|
+
const metrics = await registry.getOperationalMetrics("0xAgent");
|
|
166
|
+
const tx0 = await governance.getTransaction(0n);
|
|
167
|
+
|
|
168
|
+
console.log({ highestTier, metrics, tx0 });
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Notes
|
|
172
|
+
|
|
173
|
+
- The default settlement flow is propose -> accept -> commitDeliverable -> verifyDeliverable/autoRelease, with remediation required before dispute in normal cases. Direct dispute is reserved for explicit hard-fail cases: no delivery, hard deadline breach, clearly invalid/fraudulent deliverables, or safety-critical violations.
|
|
174
|
+
- `fulfill()` remains in the ABI only as a legacy/trusted-only compatibility path and should not be used for broader integrations.
|
|
175
|
+
- Current dispute outcomes still depend on deployment authority design; do not describe this SDK as proving decentralized adjudication.
|
|
176
|
+
- Negotiation helpers only shape Spec 14 messages. They do **not** send them.
|
|
177
|
+
- Governance support is fully typed for reads and multisig transaction lifecycle calls.
|
|
178
|
+
- Experimental ZK/privacy extensions are intentionally excluded from the launch-path SDK flow.
|
|
179
|
+
- Reputation and operational trust data are useful signals, not standalone truth guarantees.
|
|
180
|
+
- Contract address availability depends on network deployment. Some newer modules may still be undeployed on a given network.
|
|
181
|
+
|
|
182
|
+
## License
|
|
183
|
+
|
|
184
|
+
MIT
|
package/dist/agent.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ContractRunner } from "ethers";
|
|
2
|
+
import { AgentInfo, OperationalMetrics } from "./types";
|
|
3
|
+
export interface AgentRegistrationInput {
|
|
4
|
+
name: string;
|
|
5
|
+
capabilities: string[];
|
|
6
|
+
serviceType: string;
|
|
7
|
+
endpoint: string;
|
|
8
|
+
metadataURI?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class AgentRegistryClient {
|
|
11
|
+
private contract;
|
|
12
|
+
constructor(address: string, runner: ContractRunner);
|
|
13
|
+
register(input: AgentRegistrationInput): Promise<any>;
|
|
14
|
+
update(input: AgentRegistrationInput): Promise<any>;
|
|
15
|
+
deactivate(): Promise<any>;
|
|
16
|
+
reactivate(): Promise<any>;
|
|
17
|
+
submitHeartbeat(latencyMs: number): Promise<any>;
|
|
18
|
+
setHeartbeatPolicy(intervalSeconds: number, gracePeriodSeconds: number): Promise<any>;
|
|
19
|
+
getAgent(wallet: string): Promise<AgentInfo>;
|
|
20
|
+
getOperationalMetrics(wallet: string): Promise<OperationalMetrics>;
|
|
21
|
+
listAgents(limit?: number): Promise<AgentInfo[]>;
|
|
22
|
+
findByCapability(capability: string, limit?: number): Promise<AgentInfo[]>;
|
|
23
|
+
searchByCapability(capability: string): Promise<AgentInfo[]>;
|
|
24
|
+
searchByServiceType(serviceType: string): Promise<AgentInfo[]>;
|
|
25
|
+
searchByName(query: string): Promise<AgentInfo[]>;
|
|
26
|
+
getTopByTrust(limit?: number): Promise<AgentInfo[]>;
|
|
27
|
+
getActive(limit?: number): Promise<AgentInfo[]>;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAGxC,OAAO,EAAE,SAAS,E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E,CAAC;CAKtD"}
|
package/dist/agent.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AgentRegistryClient = void 0;
|
|
4
|
+
const contracts_1 = require("./contracts");
|
|
5
|
+
const ethers_1 = require("ethers");
|
|
6
|
+
class AgentRegistryClient {
|
|
7
|
+
constructor(address, runner) {
|
|
8
|
+
this.contract = new ethers_1.ethers.Contract(address, contracts_1.AGENT_REGISTRY_ABI, runner);
|
|
9
|
+
}
|
|
10
|
+
async register(input) {
|
|
11
|
+
const tx = await this.contract.register(input.name, input.capabilities, input.serviceType, input.endpoint, input.metadataURI ?? "");
|
|
12
|
+
return tx.wait();
|
|
13
|
+
}
|
|
14
|
+
async update(input) {
|
|
15
|
+
const tx = await this.contract.update(input.name, input.capabilities, input.serviceType, input.endpoint, input.metadataURI ?? "");
|
|
16
|
+
return tx.wait();
|
|
17
|
+
}
|
|
18
|
+
async deactivate() { const tx = await this.contract.deactivate(); return tx.wait(); }
|
|
19
|
+
async reactivate() { const tx = await this.contract.reactivate(); return tx.wait(); }
|
|
20
|
+
async submitHeartbeat(latencyMs) { const tx = await this.contract.submitHeartbeat(latencyMs); return tx.wait(); }
|
|
21
|
+
async setHeartbeatPolicy(intervalSeconds, gracePeriodSeconds) {
|
|
22
|
+
const tx = await this.contract.setHeartbeatPolicy(intervalSeconds, gracePeriodSeconds);
|
|
23
|
+
return tx.wait();
|
|
24
|
+
}
|
|
25
|
+
async getAgent(wallet) {
|
|
26
|
+
const [raw, trustScore] = await Promise.all([this.contract.getAgent(wallet), this.contract.getTrustScore(wallet)]);
|
|
27
|
+
return {
|
|
28
|
+
wallet: raw.wallet,
|
|
29
|
+
name: raw.name,
|
|
30
|
+
capabilities: [...raw.capabilities],
|
|
31
|
+
serviceType: raw.serviceType,
|
|
32
|
+
endpoint: raw.endpoint,
|
|
33
|
+
metadataURI: raw.metadataURI,
|
|
34
|
+
active: raw.active,
|
|
35
|
+
registeredAt: BigInt(raw.registeredAt),
|
|
36
|
+
endpointChangedAt: BigInt(raw.endpointChangedAt),
|
|
37
|
+
endpointChangeCount: BigInt(raw.endpointChangeCount),
|
|
38
|
+
trustScore: BigInt(trustScore),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
async getOperationalMetrics(wallet) {
|
|
42
|
+
const raw = await this.contract.getOperationalMetrics(wallet);
|
|
43
|
+
return {
|
|
44
|
+
heartbeatInterval: BigInt(raw.heartbeatInterval),
|
|
45
|
+
heartbeatGracePeriod: BigInt(raw.heartbeatGracePeriod),
|
|
46
|
+
lastHeartbeatAt: BigInt(raw.lastHeartbeatAt),
|
|
47
|
+
rollingLatency: BigInt(raw.rollingLatency),
|
|
48
|
+
heartbeatCount: BigInt(raw.heartbeatCount),
|
|
49
|
+
missedHeartbeatCount: BigInt(raw.missedHeartbeatCount),
|
|
50
|
+
uptimeScore: BigInt(raw.uptimeScore),
|
|
51
|
+
responseScore: BigInt(raw.responseScore),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
async listAgents(limit) {
|
|
55
|
+
const count = Number(await this.contract.agentCount());
|
|
56
|
+
const end = limit ? Math.min(limit, count) : count;
|
|
57
|
+
const addresses = await Promise.all(Array.from({ length: end }, (_, i) => this.contract.getAgentAtIndex(i)));
|
|
58
|
+
return Promise.all(addresses.map((address) => this.getAgent(address)));
|
|
59
|
+
}
|
|
60
|
+
async findByCapability(capability, limit) {
|
|
61
|
+
const agents = await this.listAgents(limit);
|
|
62
|
+
return agents.filter((agent) => agent.capabilities.includes(capability));
|
|
63
|
+
}
|
|
64
|
+
async searchByCapability(capability) {
|
|
65
|
+
const agents = await this.listAgents();
|
|
66
|
+
return agents.filter((agent) => agent.active && agent.capabilities.some((c) => c === capability || c.startsWith(capability + ".")));
|
|
67
|
+
}
|
|
68
|
+
async searchByServiceType(serviceType) {
|
|
69
|
+
const agents = await this.listAgents();
|
|
70
|
+
const query = serviceType.toLowerCase();
|
|
71
|
+
return agents.filter((agent) => agent.active && agent.serviceType.toLowerCase().includes(query));
|
|
72
|
+
}
|
|
73
|
+
async searchByName(query) {
|
|
74
|
+
const agents = await this.listAgents();
|
|
75
|
+
const lower = query.toLowerCase();
|
|
76
|
+
return agents.filter((agent) => agent.active && agent.name.toLowerCase().includes(lower));
|
|
77
|
+
}
|
|
78
|
+
async getTopByTrust(limit = 20) {
|
|
79
|
+
const agents = await this.listAgents();
|
|
80
|
+
return agents
|
|
81
|
+
.filter((agent) => agent.active)
|
|
82
|
+
.sort((a, b) => {
|
|
83
|
+
const aScore = BigInt(a.trustScore ?? 0n);
|
|
84
|
+
const bScore = BigInt(b.trustScore ?? 0n);
|
|
85
|
+
return bScore > aScore ? 1 : bScore < aScore ? -1 : 0;
|
|
86
|
+
})
|
|
87
|
+
.slice(0, limit);
|
|
88
|
+
}
|
|
89
|
+
async getActive(limit) {
|
|
90
|
+
const agents = await this.listAgents();
|
|
91
|
+
const active = agents.filter((agent) => agent.active);
|
|
92
|
+
return limit ? active.slice(0, limit) : active;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.AgentRegistryClient = AgentRegistryClient;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ContractRunner, ethers } from "ethers";
|
|
2
|
+
import { Agreement, ArbitrationCase, ArbitrationVote, DisputeCase, DisputeClass, DisputeEvidence, DisputeMode, DisputeOutcome, DirectDisputeReason, EvidenceType, ProposeParams, ProviderResponseType, RemediationCase, RemediationFeedback, RemediationResponse } from "./types";
|
|
3
|
+
export declare class ServiceAgreementClient {
|
|
4
|
+
private contract;
|
|
5
|
+
constructor(address: string, runner: ContractRunner);
|
|
6
|
+
propose(params: ProposeParams): Promise<{
|
|
7
|
+
agreementId: bigint;
|
|
8
|
+
receipt: ethers.TransactionReceipt;
|
|
9
|
+
}>;
|
|
10
|
+
accept(id: bigint): Promise<any>;
|
|
11
|
+
/** @deprecated Legacy/trusted-only immediate release path. Prefer commitDeliverable() + verifyDeliverable()/autoRelease(). */
|
|
12
|
+
fulfill(id: bigint, hash: string): Promise<any>;
|
|
13
|
+
fulfillLegacyTrustedOnly(id: bigint, hash: string): Promise<any>;
|
|
14
|
+
commitDeliverable(id: bigint, hash: string): Promise<any>;
|
|
15
|
+
verifyDeliverable(id: bigint): Promise<any>;
|
|
16
|
+
autoRelease(id: bigint): Promise<any>;
|
|
17
|
+
dispute(id: bigint, reason: string, feeEth?: bigint): Promise<any>;
|
|
18
|
+
directDispute(id: bigint, directReason: DirectDisputeReason, reason: string, feeEth?: bigint): Promise<any>;
|
|
19
|
+
escalateToDispute(id: bigint, reason: string, feeEth?: bigint): Promise<any>;
|
|
20
|
+
/** Open a dispute with explicit mode and class. For ETH agreements, pass fee as feeEth. */
|
|
21
|
+
openDisputeWithMode(id: bigint, mode: DisputeMode, disputeClass: DisputeClass, reason: string, feeEth?: bigint): Promise<ethers.TransactionReceipt>;
|
|
22
|
+
/** Shorthand: UNILATERAL dispute with specified class. */
|
|
23
|
+
openUnilateralDispute(id: bigint, disputeClass: DisputeClass, reason: string, feeEth?: bigint): Promise<ethers.TransactionReceipt>;
|
|
24
|
+
/** Shorthand: MUTUAL dispute — opener pays half. Respondent calls DisputeArbitrationClient.joinMutualDispute(). */
|
|
25
|
+
openMutualDispute(id: bigint, disputeClass: DisputeClass, reason: string, halfFeeEth?: bigint): Promise<ethers.TransactionReceipt>;
|
|
26
|
+
canDirectDispute(id: bigint, directReason: DirectDisputeReason): Promise<boolean>;
|
|
27
|
+
cancel(id: bigint): Promise<any>;
|
|
28
|
+
expiredCancel(id: bigint): Promise<any>;
|
|
29
|
+
resolveDisputeDetailed(id: bigint, outcome: DisputeOutcome, providerAward: bigint, clientAward: bigint): Promise<any>;
|
|
30
|
+
/** Owner-only: resolve a dispute directly in favor of provider or client. Requires DISPUTED or ESCALATED_TO_HUMAN status. */
|
|
31
|
+
ownerResolveDispute(agreementId: bigint, favorProvider: boolean): Promise<ethers.TransactionReceipt>;
|
|
32
|
+
/**
|
|
33
|
+
* Called by the DisputeArbitration contract to resolve a dispute with split amounts.
|
|
34
|
+
* @param agreementId Agreement to resolve
|
|
35
|
+
* @param recipient Address of the winning party
|
|
36
|
+
* @param providerAmount Provider payout in token units
|
|
37
|
+
* @param clientAmount Client refund in token units
|
|
38
|
+
*/
|
|
39
|
+
resolveFromArbitration(agreementId: bigint, recipient: string, providerAmount: bigint, clientAmount: bigint): Promise<ethers.TransactionReceipt>;
|
|
40
|
+
requestRevision(agreementId: bigint, feedbackHash: string, feedbackURI?: string, previousTranscriptHash?: string): Promise<any>;
|
|
41
|
+
respondToRevision(agreementId: bigint, responseType: ProviderResponseType, responseHash: string, responseURI?: string, previousTranscriptHash?: string, proposedProviderPayout?: bigint): Promise<any>;
|
|
42
|
+
submitDisputeEvidence(agreementId: bigint, evidenceType: EvidenceType, evidenceHash: string, evidenceURI?: string): Promise<any>;
|
|
43
|
+
nominateArbitrator(agreementId: bigint, arbitrator: string): Promise<any>;
|
|
44
|
+
castArbitrationVote(agreementId: bigint, vote: ArbitrationVote, providerAward: bigint, clientAward: bigint): Promise<any>;
|
|
45
|
+
requestHumanEscalation(agreementId: bigint, reason: string): Promise<any>;
|
|
46
|
+
getAgreement(id: bigint): Promise<Agreement>;
|
|
47
|
+
getRemediationCase(id: bigint): Promise<RemediationCase>;
|
|
48
|
+
getRemediationFeedback(id: bigint, index: bigint): Promise<RemediationFeedback>;
|
|
49
|
+
getRemediationResponse(id: bigint, index: bigint): Promise<RemediationResponse>;
|
|
50
|
+
getDisputeCase(id: bigint): Promise<DisputeCase>;
|
|
51
|
+
getDisputeEvidence(id: bigint, index: bigint): Promise<DisputeEvidence>;
|
|
52
|
+
getArbitrationCase(id: bigint): Promise<ArbitrationCase>;
|
|
53
|
+
getDisputeEvidenceAll(id: bigint): Promise<DisputeEvidence[]>;
|
|
54
|
+
getClientAgreements(client: string): Promise<Agreement[]>;
|
|
55
|
+
getProviderAgreements(provider: string): Promise<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EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;CAIpE"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ServiceAgreementClient = void 0;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
const contracts_1 = require("./contracts");
|
|
6
|
+
const types_1 = require("./types");
|
|
7
|
+
class ServiceAgreementClient {
|
|
8
|
+
constructor(address, runner) {
|
|
9
|
+
this.contract = new ethers_1.ethers.Contract(address, contracts_1.SERVICE_AGREEMENT_ABI, runner);
|
|
10
|
+
}
|
|
11
|
+
async propose(params) {
|
|
12
|
+
const isEth = params.token === ethers_1.ethers.ZeroAddress;
|
|
13
|
+
const tx = await this.contract.propose(params.provider, params.serviceType, params.description, params.price, params.token, params.deadline, params.deliverablesHash, { value: isEth ? params.price : 0n });
|
|
14
|
+
const receipt = await tx.wait();
|
|
15
|
+
const iface = new ethers_1.ethers.Interface(contracts_1.SERVICE_AGREEMENT_ABI);
|
|
16
|
+
for (const log of receipt.logs) {
|
|
17
|
+
try {
|
|
18
|
+
const parsed = iface.parseLog(log);
|
|
19
|
+
if (parsed?.name === "AgreementProposed")
|
|
20
|
+
return { agreementId: BigInt(parsed.args.id), receipt };
|
|
21
|
+
}
|
|
22
|
+
catch { }
|
|
23
|
+
}
|
|
24
|
+
throw new Error("Could not parse AgreementProposed event");
|
|
25
|
+
}
|
|
26
|
+
async accept(id) { const tx = await this.contract.accept(id); return tx.wait(); }
|
|
27
|
+
/** @deprecated Legacy/trusted-only immediate release path. Prefer commitDeliverable() + verifyDeliverable()/autoRelease(). */
|
|
28
|
+
async fulfill(id, hash) { const tx = await this.contract.fulfill(id, hash); return tx.wait(); }
|
|
29
|
+
async fulfillLegacyTrustedOnly(id, hash) { return this.fulfill(id, hash); }
|
|
30
|
+
async commitDeliverable(id, hash) { const tx = await this.contract.commitDeliverable(id, hash); return tx.wait(); }
|
|
31
|
+
async verifyDeliverable(id) { const tx = await this.contract.verifyDeliverable(id); return tx.wait(); }
|
|
32
|
+
async autoRelease(id) { const tx = await this.contract.autoRelease(id); return tx.wait(); }
|
|
33
|
+
async dispute(id, reason, feeEth = 0n) { const tx = await this.contract.dispute(id, reason, { value: feeEth }); return tx.wait(); }
|
|
34
|
+
async directDispute(id, directReason, reason, feeEth = 0n) { const tx = await this.contract.directDispute(id, directReason, reason, { value: feeEth }); return tx.wait(); }
|
|
35
|
+
async escalateToDispute(id, reason, feeEth = 0n) { const tx = await this.contract.escalateToDispute(id, reason, { value: feeEth }); return tx.wait(); }
|
|
36
|
+
/** Open a dispute with explicit mode and class. For ETH agreements, pass fee as feeEth. */
|
|
37
|
+
async openDisputeWithMode(id, mode, disputeClass, reason, feeEth = 0n) {
|
|
38
|
+
const tx = await this.contract.openDisputeWithMode(id, mode, disputeClass, reason, { value: feeEth });
|
|
39
|
+
return tx.wait();
|
|
40
|
+
}
|
|
41
|
+
/** Shorthand: UNILATERAL dispute with specified class. */
|
|
42
|
+
async openUnilateralDispute(id, disputeClass, reason, feeEth = 0n) {
|
|
43
|
+
return this.openDisputeWithMode(id, types_1.DisputeMode.UNILATERAL, disputeClass, reason, feeEth);
|
|
44
|
+
}
|
|
45
|
+
/** Shorthand: MUTUAL dispute — opener pays half. Respondent calls DisputeArbitrationClient.joinMutualDispute(). */
|
|
46
|
+
async openMutualDispute(id, disputeClass, reason, halfFeeEth = 0n) {
|
|
47
|
+
return this.openDisputeWithMode(id, types_1.DisputeMode.MUTUAL, disputeClass, reason, halfFeeEth);
|
|
48
|
+
}
|
|
49
|
+
async canDirectDispute(id, directReason) { return this.contract.canDirectDispute(id, directReason); }
|
|
50
|
+
async cancel(id) { const tx = await this.contract.cancel(id); return tx.wait(); }
|
|
51
|
+
async expiredCancel(id) { const tx = await this.contract.expiredCancel(id); return tx.wait(); }
|
|
52
|
+
async resolveDisputeDetailed(id, outcome, providerAward, clientAward) {
|
|
53
|
+
const tx = await this.contract.resolveDisputeDetailed(id, outcome, providerAward, clientAward);
|
|
54
|
+
return tx.wait();
|
|
55
|
+
}
|
|
56
|
+
/** Owner-only: resolve a dispute directly in favor of provider or client. Requires DISPUTED or ESCALATED_TO_HUMAN status. */
|
|
57
|
+
async ownerResolveDispute(agreementId, favorProvider) {
|
|
58
|
+
const tx = await this.contract.ownerResolveDispute(agreementId, favorProvider);
|
|
59
|
+
return tx.wait();
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Called by the DisputeArbitration contract to resolve a dispute with split amounts.
|
|
63
|
+
* @param agreementId Agreement to resolve
|
|
64
|
+
* @param recipient Address of the winning party
|
|
65
|
+
* @param providerAmount Provider payout in token units
|
|
66
|
+
* @param clientAmount Client refund in token units
|
|
67
|
+
*/
|
|
68
|
+
async resolveFromArbitration(agreementId, recipient, providerAmount, clientAmount) {
|
|
69
|
+
const tx = await this.contract.resolveFromArbitration(agreementId, recipient, providerAmount, clientAmount);
|
|
70
|
+
return tx.wait();
|
|
71
|
+
}
|
|
72
|
+
async requestRevision(agreementId, feedbackHash, feedbackURI = "", previousTranscriptHash = ethers_1.ethers.ZeroHash) {
|
|
73
|
+
const tx = await this.contract.requestRevision(agreementId, feedbackHash, feedbackURI, previousTranscriptHash);
|
|
74
|
+
return tx.wait();
|
|
75
|
+
}
|
|
76
|
+
async respondToRevision(agreementId, responseType, responseHash, responseURI = "", previousTranscriptHash = ethers_1.ethers.ZeroHash, proposedProviderPayout = 0n) {
|
|
77
|
+
const tx = await this.contract.respondToRevision(agreementId, responseType, proposedProviderPayout, responseHash, responseURI, previousTranscriptHash);
|
|
78
|
+
return tx.wait();
|
|
79
|
+
}
|
|
80
|
+
async submitDisputeEvidence(agreementId, evidenceType, evidenceHash, evidenceURI = "") {
|
|
81
|
+
const tx = await this.contract.submitDisputeEvidence(agreementId, evidenceType, evidenceHash, evidenceURI);
|
|
82
|
+
return tx.wait();
|
|
83
|
+
}
|
|
84
|
+
async nominateArbitrator(agreementId, arbitrator) {
|
|
85
|
+
const tx = await this.contract.nominateArbitrator(agreementId, arbitrator);
|
|
86
|
+
return tx.wait();
|
|
87
|
+
}
|
|
88
|
+
async castArbitrationVote(agreementId, vote, providerAward, clientAward) {
|
|
89
|
+
const tx = await this.contract.castArbitrationVote(agreementId, vote, providerAward, clientAward);
|
|
90
|
+
return tx.wait();
|
|
91
|
+
}
|
|
92
|
+
async requestHumanEscalation(agreementId, reason) {
|
|
93
|
+
const tx = await this.contract.requestHumanEscalation(agreementId, reason);
|
|
94
|
+
return tx.wait();
|
|
95
|
+
}
|
|
96
|
+
async getAgreement(id) {
|
|
97
|
+
const raw = await this.contract.getAgreement(id);
|
|
98
|
+
return {
|
|
99
|
+
id: BigInt(raw.id), client: raw.client, provider: raw.provider, serviceType: raw.serviceType,
|
|
100
|
+
description: raw.description, price: BigInt(raw.price), token: raw.token, deadline: BigInt(raw.deadline),
|
|
101
|
+
deliverablesHash: raw.deliverablesHash, status: Number(raw.status),
|
|
102
|
+
createdAt: BigInt(raw.createdAt), resolvedAt: BigInt(raw.resolvedAt), verifyWindowEnd: BigInt(raw.verifyWindowEnd), committedHash: raw.committedHash,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
async getRemediationCase(id) {
|
|
106
|
+
const raw = await this.contract.getRemediationCase(id);
|
|
107
|
+
return { cycleCount: Number(raw.cycleCount), openedAt: BigInt(raw.openedAt), deadlineAt: BigInt(raw.deadlineAt), lastActionAt: BigInt(raw.lastActionAt), latestTranscriptHash: raw.latestTranscriptHash, active: raw.active };
|
|
108
|
+
}
|
|
109
|
+
async getRemediationFeedback(id, index) {
|
|
110
|
+
const raw = await this.contract.getRemediationFeedback(id, index);
|
|
111
|
+
return { cycle: Number(raw.cycle), author: raw.author, feedbackHash: raw.feedbackHash, feedbackURI: raw.feedbackURI, previousTranscriptHash: raw.previousTranscriptHash, transcriptHash: raw.transcriptHash, timestamp: BigInt(raw.timestamp) };
|
|
112
|
+
}
|
|
113
|
+
async getRemediationResponse(id, index) {
|
|
114
|
+
const raw = await this.contract.getRemediationResponse(id, index);
|
|
115
|
+
return { cycle: Number(raw.cycle), author: raw.author, responseType: Number(raw.responseType), proposedProviderPayout: BigInt(raw.proposedProviderPayout), responseHash: raw.responseHash, responseURI: raw.responseURI, previousTranscriptHash: raw.previousTranscriptHash, transcriptHash: raw.transcriptHash, timestamp: BigInt(raw.timestamp) };
|
|
116
|
+
}
|
|
117
|
+
async getDisputeCase(id) {
|
|
118
|
+
const raw = await this.contract.getDisputeCase(id);
|
|
119
|
+
return { agreementId: BigInt(raw.agreementId), openedAt: BigInt(raw.openedAt), responseDeadlineAt: BigInt(raw.responseDeadlineAt), outcome: Number(raw.outcome), providerAward: BigInt(raw.providerAward), clientAward: BigInt(raw.clientAward), humanReviewRequested: raw.humanReviewRequested, evidenceCount: BigInt(raw.evidenceCount) };
|
|
120
|
+
}
|
|
121
|
+
async getDisputeEvidence(id, index) {
|
|
122
|
+
const raw = await this.contract.getDisputeEvidence(id, index);
|
|
123
|
+
return { submitter: raw.submitter, evidenceType: Number(raw.evidenceType), evidenceHash: raw.evidenceHash, evidenceURI: raw.evidenceURI, timestamp: BigInt(raw.timestamp) };
|
|
124
|
+
}
|
|
125
|
+
async getArbitrationCase(id) {
|
|
126
|
+
const raw = await this.contract.getArbitrationCase(id);
|
|
127
|
+
return {
|
|
128
|
+
agreementId: BigInt(raw.agreementId),
|
|
129
|
+
arbitrators: [...raw.arbitrators],
|
|
130
|
+
arbitratorCount: Number(raw.arbitratorCount),
|
|
131
|
+
providerVotes: Number(raw.providerVotes),
|
|
132
|
+
clientVotes: Number(raw.clientVotes),
|
|
133
|
+
splitVotes: Number(raw.splitVotes),
|
|
134
|
+
humanVotes: Number(raw.humanVotes),
|
|
135
|
+
selectionDeadlineAt: BigInt(raw.selectionDeadlineAt),
|
|
136
|
+
decisionDeadlineAt: BigInt(raw.decisionDeadlineAt),
|
|
137
|
+
splitProviderAward: BigInt(raw.splitProviderAward),
|
|
138
|
+
splitClientAward: BigInt(raw.splitClientAward),
|
|
139
|
+
finalized: raw.finalized,
|
|
140
|
+
humanBackstopUsed: raw.humanBackstopUsed,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
async getDisputeEvidenceAll(id) {
|
|
144
|
+
const dispute = await this.getDisputeCase(id);
|
|
145
|
+
return Promise.all(Array.from({ length: Number(dispute.evidenceCount) }, (_, i) => this.getDisputeEvidence(id, BigInt(i))));
|
|
146
|
+
}
|
|
147
|
+
async getClientAgreements(client) {
|
|
148
|
+
const ids = await this.contract.getAgreementsByClient(client);
|
|
149
|
+
return Promise.all(ids.map((id) => this.getAgreement(BigInt(id))));
|
|
150
|
+
}
|
|
151
|
+
async getProviderAgreements(provider) {
|
|
152
|
+
const ids = await this.contract.getAgreementsByProvider(provider);
|
|
153
|
+
return Promise.all(ids.map((id) => this.getAgreement(BigInt(id))));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
exports.ServiceAgreementClient = ServiceAgreementClient;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ContractRunner } from "ethers";
|
|
2
|
+
import { CapabilityRoot } from "./types";
|
|
3
|
+
export declare class CapabilityRegistryClient {
|
|
4
|
+
private contract;
|
|
5
|
+
constructor(address: string, runner: ContractRunner);
|
|
6
|
+
registerRoot(root: string): Promise<any>;
|
|
7
|
+
setRootStatus(root: string, active: boolean): Promise<any>;
|
|
8
|
+
claim(capability: string): Promise<any>;
|
|
9
|
+
revoke(capability: string): Promise<any>;
|
|
10
|
+
isRootActive(root: string): Promise<any>;
|
|
11
|
+
getRoot(root: string): Promise<CapabilityRoot>;
|
|
12
|
+
listRoots(): Promise<CapabilityRoot[]>;
|
|
13
|
+
getCapabilities(agent: string): Promise<string[]>;
|
|
14
|
+
capabilityCount(agent: string): Promise<bigint>;
|
|
15
|
+
isCapabilityClaimed(agent: string, capability: string): Promise<any>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=capability.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capability.d.ts","sourceRoot":"","sources":["../src/capability.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAU,MAAM,QAAQ,CAAC;AAEhD,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEzC,qBAAa,wBAAwB;IACnC,OAAO,CAAC,QAAQ,CAAkB;gBACtB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc;IAC7C,YAAY,CAAC,IAAI,EAAE,MAAM;IACzB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO;IAC3C,KAAK,CAAC,UAAU,EAAE,MAAM;IACxB,MAAM,CAAC,UAAU,EAAE,MAAM;IAC/B,YAAY,CAAC,IAAI,EAAE,MAAM;IACnB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAC9C,SAAS,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IAC5C,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IACjD,eAAe,CAAC,KAAK,EAAE,MAAM;IAC7B,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;CACtD"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CapabilityRegistryClient = void 0;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
const contracts_1 = require("./contracts");
|
|
6
|
+
class CapabilityRegistryClient {
|
|
7
|
+
constructor(address, runner) { this.contract = new ethers_1.ethers.Contract(address, contracts_1.CAPABILITY_REGISTRY_ABI, runner); }
|
|
8
|
+
async registerRoot(root) { const tx = await this.contract.registerRoot(root); return tx.wait(); }
|
|
9
|
+
async setRootStatus(root, active) { const tx = await this.contract.setRootStatus(root, active); return tx.wait(); }
|
|
10
|
+
async claim(capability) { const tx = await this.contract.claim(capability); return tx.wait(); }
|
|
11
|
+
async revoke(capability) { const tx = await this.contract.revoke(capability); return tx.wait(); }
|
|
12
|
+
isRootActive(root) { return this.contract.isRootActive(root); }
|
|
13
|
+
async getRoot(root) { const raw = await this.contract.getRoot(root); return { root: raw.root, rootId: raw.rootId, active: raw.active }; }
|
|
14
|
+
async listRoots() { const count = Number(await this.contract.rootCount()); return Promise.all(Array.from({ length: count }, async (_, i) => { const raw = await this.contract.getRootAt(i); return { root: raw.root, rootId: raw.rootId, active: raw.active }; })); }
|
|
15
|
+
getCapabilities(agent) { return this.contract.getCapabilities(agent); }
|
|
16
|
+
capabilityCount(agent) { return this.contract.capabilityCount(agent).then(BigInt); }
|
|
17
|
+
isCapabilityClaimed(agent, capability) { return this.contract.isCapabilityClaimed(agent, capability); }
|
|
18
|
+
}
|
|
19
|
+
exports.CapabilityRegistryClient = CapabilityRegistryClient;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ContractRunner } from "ethers";
|
|
2
|
+
import { Channel, ChannelState } from "./types";
|
|
3
|
+
export declare class ChannelClient {
|
|
4
|
+
private contract;
|
|
5
|
+
private signer;
|
|
6
|
+
constructor(address: string, runner: ContractRunner);
|
|
7
|
+
openSessionChannel(provider: string, token: string, maxAmount: bigint, ratePerCall: bigint, deadline: number): Promise<{
|
|
8
|
+
channelId: string;
|
|
9
|
+
txHash: string;
|
|
10
|
+
}>;
|
|
11
|
+
/**
|
|
12
|
+
* Compute the EIP-712 domain separator for a deployed SessionChannels contract.
|
|
13
|
+
* Must match SessionChannels._domainSeparator() on-chain.
|
|
14
|
+
*/
|
|
15
|
+
static domainSeparator(chainId: bigint, contractAddress: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Compute the EIP-712 typed-data digest for a ChannelState.
|
|
18
|
+
* Must match SessionChannels._verifyChannelStateSigs() digest on-chain.
|
|
19
|
+
*/
|
|
20
|
+
static channelStateDigest(state: Omit<ChannelState, "clientSig" | "providerSig">, chainId: bigint, contractAddress: string): Uint8Array;
|
|
21
|
+
signStateUpdate(channelId: string, sequenceNumber: number, callCount: number, cumulativePayment: bigint, token: string, chainId: bigint, contractAddress: string): Promise<ChannelState>;
|
|
22
|
+
verifyStateUpdate(state: ChannelState, channel: Channel, chainId: bigint, contractAddress: string): Promise<boolean>;
|
|
23
|
+
encodeChannelState(state: ChannelState): string;
|
|
24
|
+
closeChannel(channelId: string, finalState: ChannelState): Promise<{
|
|
25
|
+
txHash: string;
|
|
26
|
+
}>;
|
|
27
|
+
challengeChannel(channelId: string, latestState: ChannelState): Promise<{
|
|
28
|
+
txHash: string;
|
|
29
|
+
}>;
|
|
30
|
+
finaliseChallenge(channelId: string): Promise<{
|
|
31
|
+
txHash: string;
|
|
32
|
+
}>;
|
|
33
|
+
reclaimExpiredChannel(channelId: string): Promise<{
|
|
34
|
+
txHash: string;
|
|
35
|
+
}>;
|
|
36
|
+
getChannelStatus(channelId: string): Promise<Channel>;
|
|
37
|
+
getOpenChannels(wallet: string): Promise<Channel[]>;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=channel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../src/channel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,cAAc,EAAU,MAAM,QAAQ,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAiB,MAAM,SAAS,CAAC;AAe/D,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAkB;IAClC,OAAO,CAAC,MAAM,CAAuB;gBAEzB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc;IAK7C,kBAAkB,CACtB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC;QAAE,SAAS,EAAE,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