@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
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { ContractRunner, ethers } from "ethers";
|
|
2
|
+
export declare enum DeliverableType {
|
|
3
|
+
text = "text",
|
|
4
|
+
code = "code",
|
|
5
|
+
data = "data",
|
|
6
|
+
media = "media",
|
|
7
|
+
api = "api",
|
|
8
|
+
composite = "composite",
|
|
9
|
+
null = "null"
|
|
10
|
+
}
|
|
11
|
+
export interface DeliverableManifestEntry {
|
|
12
|
+
path: string;
|
|
13
|
+
hash: string;
|
|
14
|
+
size: number;
|
|
15
|
+
type?: DeliverableType;
|
|
16
|
+
}
|
|
17
|
+
export interface DeliverableManifest {
|
|
18
|
+
type: DeliverableType.composite;
|
|
19
|
+
version: string;
|
|
20
|
+
files: DeliverableManifestEntry[];
|
|
21
|
+
metadata?: Record<string, unknown>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The encrypted structure returned by encryptDeliverable.
|
|
25
|
+
* encryptedBuffer contains the nonce (24 bytes) followed by the box ciphertext.
|
|
26
|
+
* ephemeralPublicKey is the sender's one-time public key; the recipient needs it
|
|
27
|
+
* along with their own private key to decrypt.
|
|
28
|
+
*/
|
|
29
|
+
export interface EncryptedDeliverable {
|
|
30
|
+
encryptedBuffer: Buffer;
|
|
31
|
+
ephemeralPublicKey: Uint8Array;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Encrypt a buffer for a recipient using NaCl box (X25519-XSalsa20-Poly1305).
|
|
35
|
+
* An ephemeral keypair is generated per call so encryptions are unlinkable.
|
|
36
|
+
*/
|
|
37
|
+
export declare function encryptDeliverable(buffer: Buffer, recipientPublicKey: Uint8Array): Promise<EncryptedDeliverable>;
|
|
38
|
+
/**
|
|
39
|
+
* Decrypt a buffer produced by encryptDeliverable.
|
|
40
|
+
* secretKey is the recipient's NaCl box secret key (32 bytes).
|
|
41
|
+
*/
|
|
42
|
+
export declare function decryptDeliverable(encryptedBuffer: Buffer, ephemeralPublicKey: Uint8Array, secretKey: Uint8Array): Promise<Buffer>;
|
|
43
|
+
export interface IPFSUploadOptions {
|
|
44
|
+
/** IPFS HTTP API base URL. Defaults to https://ipfs.io/api/v0.
|
|
45
|
+
* Override with a pinning service endpoint (e.g. Infura, Pinata) for persistence. */
|
|
46
|
+
apiEndpoint?: string;
|
|
47
|
+
}
|
|
48
|
+
export interface IPFSUploadResult {
|
|
49
|
+
cid: string;
|
|
50
|
+
uri: string;
|
|
51
|
+
}
|
|
52
|
+
/** Compute keccak256 over arbitrary bytes. Returns 0x-prefixed hex. */
|
|
53
|
+
export declare function hashDeliverable(buffer: Buffer): Promise<string>;
|
|
54
|
+
/** Read a file and return its keccak256 hash. */
|
|
55
|
+
export declare function hashDeliverableFile(filePath: string): Promise<string>;
|
|
56
|
+
/**
|
|
57
|
+
* Upload a buffer to IPFS via the HTTP API.
|
|
58
|
+
* Returns the CID and an ipfs:// URI.
|
|
59
|
+
*
|
|
60
|
+
* The default endpoint (https://ipfs.io/api/v0) is a public gateway — it may
|
|
61
|
+
* not persist content long-term. Pass a dedicated pinning service endpoint via
|
|
62
|
+
* options.apiEndpoint for production use.
|
|
63
|
+
*/
|
|
64
|
+
export declare function uploadToIPFS(buffer: Buffer, options?: IPFSUploadOptions): Promise<IPFSUploadResult>;
|
|
65
|
+
/**
|
|
66
|
+
* Encrypt a buffer with the recipient's public key, then upload the packed
|
|
67
|
+
* ciphertext to IPFS. The IPFS blob format is:
|
|
68
|
+
* magic "ARC1" (4 bytes) | ephemeral public key (32 bytes) | nonce (24 bytes) | ciphertext
|
|
69
|
+
* This self-contained layout lets the recipient recover all decryption inputs
|
|
70
|
+
* from the CID alone (plus their own private key).
|
|
71
|
+
*/
|
|
72
|
+
export declare function uploadEncryptedIPFS(buffer: Buffer, recipientPublicKey: Uint8Array, options?: IPFSUploadOptions): Promise<IPFSUploadResult>;
|
|
73
|
+
export declare class DeliverableClient {
|
|
74
|
+
private contract;
|
|
75
|
+
constructor(address: string, runner: ContractRunner);
|
|
76
|
+
/** Compute keccak256 over a buffer. Returns 0x-prefixed hex. */
|
|
77
|
+
hashDeliverable(buffer: Buffer): Promise<string>;
|
|
78
|
+
/** Read a file and return its keccak256 hash. */
|
|
79
|
+
hashDeliverableFile(filePath: string): Promise<string>;
|
|
80
|
+
/**
|
|
81
|
+
* Commit a deliverable hash on-chain via ServiceAgreement.commitDeliverable().
|
|
82
|
+
* metadataURI is accepted for caller convenience but is not forwarded to the
|
|
83
|
+
* contract (the current ABI takes only agreementId + hash).
|
|
84
|
+
*/
|
|
85
|
+
commitDeliverable(agreementId: bigint, hash: string, metadataURI: string, signer?: ContractRunner): Promise<ethers.TransactionReceipt | null>;
|
|
86
|
+
/**
|
|
87
|
+
* Fetch the on-chain committed hash and compare it against a local buffer.
|
|
88
|
+
* Does NOT release escrow — call ServiceAgreementClient.verifyDeliverable()
|
|
89
|
+
* separately once satisfied.
|
|
90
|
+
*/
|
|
91
|
+
verifyDeliverable(agreementId: bigint, localBuffer: Buffer, signer?: ContractRunner): Promise<{
|
|
92
|
+
match: boolean;
|
|
93
|
+
onChainHash: string;
|
|
94
|
+
localHash: string;
|
|
95
|
+
}>;
|
|
96
|
+
/** Upload a buffer to IPFS. See uploadToIPFS for endpoint notes. */
|
|
97
|
+
uploadToIPFS(buffer: Buffer, options?: IPFSUploadOptions): Promise<IPFSUploadResult>;
|
|
98
|
+
/**
|
|
99
|
+
* Upload buffer to IPFS then commit the hash + URI in one call.
|
|
100
|
+
* Returns the committed hash, IPFS URI, and the on-chain transaction receipt.
|
|
101
|
+
*/
|
|
102
|
+
commitDeliverableIPFS(agreementId: bigint, buffer: Buffer, options?: IPFSUploadOptions, signer?: ContractRunner): Promise<{
|
|
103
|
+
hash: string;
|
|
104
|
+
uri: string;
|
|
105
|
+
receipt: ethers.TransactionReceipt;
|
|
106
|
+
}>;
|
|
107
|
+
/**
|
|
108
|
+
* Encrypt buffer for recipientPublicKey, upload the ciphertext to IPFS, then
|
|
109
|
+
* commit the plaintext hash on-chain. The on-chain hash covers plaintext so
|
|
110
|
+
* the client can verify integrity after decryption.
|
|
111
|
+
*/
|
|
112
|
+
commitDeliverableIPFSEncrypted(agreementId: bigint, buffer: Buffer, recipientPublicKey: Uint8Array, options?: IPFSUploadOptions, signer?: ContractRunner): Promise<{
|
|
113
|
+
hash: string;
|
|
114
|
+
uri: string;
|
|
115
|
+
receipt: ethers.TransactionReceipt;
|
|
116
|
+
}>;
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=deliverable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deliverable.d.ts","sourceRoot":"","sources":["../src/deliverable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAOhD,oBAAY,eAAe;IACzB,IAAI,SAAS;IACb,IAAI,SAAS;IACb,IAAI,SAAS;IACb,KAAK,UAAU;IACf,GAAG,QAAQ;IACX,SAAS,cAAc;IACvB,IAAI,SAAS;CACd;AAED,MAAM,WAAW,wBAAwB;IAC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;;;;OAIG;IACG,8BAA8B,CAClC,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,MAAM,EACd,kBAAkB,EAAE,UAAU,EAC9B,OAAO,CAAC,EAAE,iBAAiB,EAC3B,MAAM,CAAC,EAAE,cAAc,GACtB,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC,kBAAkB,CAAA;KAAE,CAAC;CAQ9E"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DeliverableClient = exports.DeliverableType = void 0;
|
|
7
|
+
exports.encryptDeliverable = encryptDeliverable;
|
|
8
|
+
exports.decryptDeliverable = decryptDeliverable;
|
|
9
|
+
exports.hashDeliverable = hashDeliverable;
|
|
10
|
+
exports.hashDeliverableFile = hashDeliverableFile;
|
|
11
|
+
exports.uploadToIPFS = uploadToIPFS;
|
|
12
|
+
exports.uploadEncryptedIPFS = uploadEncryptedIPFS;
|
|
13
|
+
const ethers_1 = require("ethers");
|
|
14
|
+
const promises_1 = require("fs/promises");
|
|
15
|
+
const tweetnacl_1 = __importDefault(require("tweetnacl"));
|
|
16
|
+
const contracts_1 = require("./contracts");
|
|
17
|
+
// ─── Deliverable Types ────────────────────────────────────────────────────────
|
|
18
|
+
var DeliverableType;
|
|
19
|
+
(function (DeliverableType) {
|
|
20
|
+
DeliverableType["text"] = "text";
|
|
21
|
+
DeliverableType["code"] = "code";
|
|
22
|
+
DeliverableType["data"] = "data";
|
|
23
|
+
DeliverableType["media"] = "media";
|
|
24
|
+
DeliverableType["api"] = "api";
|
|
25
|
+
DeliverableType["composite"] = "composite";
|
|
26
|
+
DeliverableType["null"] = "null";
|
|
27
|
+
})(DeliverableType || (exports.DeliverableType = DeliverableType = {}));
|
|
28
|
+
/**
|
|
29
|
+
* Encrypt a buffer for a recipient using NaCl box (X25519-XSalsa20-Poly1305).
|
|
30
|
+
* An ephemeral keypair is generated per call so encryptions are unlinkable.
|
|
31
|
+
*/
|
|
32
|
+
async function encryptDeliverable(buffer, recipientPublicKey) {
|
|
33
|
+
const ephemeralKeyPair = tweetnacl_1.default.box.keyPair();
|
|
34
|
+
const nonce = tweetnacl_1.default.randomBytes(tweetnacl_1.default.box.nonceLength);
|
|
35
|
+
const ciphertext = tweetnacl_1.default.box(buffer, nonce, recipientPublicKey, ephemeralKeyPair.secretKey);
|
|
36
|
+
const encryptedBuffer = Buffer.concat([Buffer.from(nonce), Buffer.from(ciphertext)]);
|
|
37
|
+
return { encryptedBuffer, ephemeralPublicKey: ephemeralKeyPair.publicKey };
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Decrypt a buffer produced by encryptDeliverable.
|
|
41
|
+
* secretKey is the recipient's NaCl box secret key (32 bytes).
|
|
42
|
+
*/
|
|
43
|
+
async function decryptDeliverable(encryptedBuffer, ephemeralPublicKey, secretKey) {
|
|
44
|
+
const nonce = encryptedBuffer.subarray(0, tweetnacl_1.default.box.nonceLength);
|
|
45
|
+
const ciphertext = encryptedBuffer.subarray(tweetnacl_1.default.box.nonceLength);
|
|
46
|
+
const plaintext = tweetnacl_1.default.box.open(ciphertext, nonce, ephemeralPublicKey, secretKey);
|
|
47
|
+
if (!plaintext)
|
|
48
|
+
throw new Error("Decryption failed: invalid ciphertext or wrong keys");
|
|
49
|
+
return Buffer.from(plaintext);
|
|
50
|
+
}
|
|
51
|
+
// ─── Standalone functions ─────────────────────────────────────────────────────
|
|
52
|
+
/** Compute keccak256 over arbitrary bytes. Returns 0x-prefixed hex. */
|
|
53
|
+
async function hashDeliverable(buffer) {
|
|
54
|
+
return ethers_1.ethers.keccak256(buffer);
|
|
55
|
+
}
|
|
56
|
+
/** Read a file and return its keccak256 hash. */
|
|
57
|
+
async function hashDeliverableFile(filePath) {
|
|
58
|
+
const buffer = await (0, promises_1.readFile)(filePath);
|
|
59
|
+
return hashDeliverable(buffer);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Upload a buffer to IPFS via the HTTP API.
|
|
63
|
+
* Returns the CID and an ipfs:// URI.
|
|
64
|
+
*
|
|
65
|
+
* The default endpoint (https://ipfs.io/api/v0) is a public gateway — it may
|
|
66
|
+
* not persist content long-term. Pass a dedicated pinning service endpoint via
|
|
67
|
+
* options.apiEndpoint for production use.
|
|
68
|
+
*/
|
|
69
|
+
async function uploadToIPFS(buffer, options) {
|
|
70
|
+
const apiEndpoint = options?.apiEndpoint ?? "https://ipfs.io/api/v0";
|
|
71
|
+
const form = new FormData();
|
|
72
|
+
form.append("file", new Blob([buffer]));
|
|
73
|
+
const response = await fetch(`${apiEndpoint}/add`, { method: "POST", body: form });
|
|
74
|
+
if (!response.ok)
|
|
75
|
+
throw new Error(`IPFS upload failed: ${response.status} ${response.statusText}`);
|
|
76
|
+
const data = (await response.json());
|
|
77
|
+
const cid = data.Hash;
|
|
78
|
+
return { cid, uri: `ipfs://${cid}` };
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Encrypt a buffer with the recipient's public key, then upload the packed
|
|
82
|
+
* ciphertext to IPFS. The IPFS blob format is:
|
|
83
|
+
* magic "ARC1" (4 bytes) | ephemeral public key (32 bytes) | nonce (24 bytes) | ciphertext
|
|
84
|
+
* This self-contained layout lets the recipient recover all decryption inputs
|
|
85
|
+
* from the CID alone (plus their own private key).
|
|
86
|
+
*/
|
|
87
|
+
async function uploadEncryptedIPFS(buffer, recipientPublicKey, options) {
|
|
88
|
+
const { encryptedBuffer, ephemeralPublicKey } = await encryptDeliverable(buffer, recipientPublicKey);
|
|
89
|
+
const MAGIC = Buffer.from("ARC1");
|
|
90
|
+
const packed = Buffer.concat([MAGIC, Buffer.from(ephemeralPublicKey), encryptedBuffer]);
|
|
91
|
+
return uploadToIPFS(packed, options);
|
|
92
|
+
}
|
|
93
|
+
// ─── DeliverableClient ────────────────────────────────────────────────────────
|
|
94
|
+
class DeliverableClient {
|
|
95
|
+
constructor(address, runner) {
|
|
96
|
+
this.contract = new ethers_1.ethers.Contract(address, contracts_1.SERVICE_AGREEMENT_ABI, runner);
|
|
97
|
+
}
|
|
98
|
+
/** Compute keccak256 over a buffer. Returns 0x-prefixed hex. */
|
|
99
|
+
async hashDeliverable(buffer) {
|
|
100
|
+
return hashDeliverable(buffer);
|
|
101
|
+
}
|
|
102
|
+
/** Read a file and return its keccak256 hash. */
|
|
103
|
+
async hashDeliverableFile(filePath) {
|
|
104
|
+
return hashDeliverableFile(filePath);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Commit a deliverable hash on-chain via ServiceAgreement.commitDeliverable().
|
|
108
|
+
* metadataURI is accepted for caller convenience but is not forwarded to the
|
|
109
|
+
* contract (the current ABI takes only agreementId + hash).
|
|
110
|
+
*/
|
|
111
|
+
async commitDeliverable(agreementId, hash, metadataURI, signer) {
|
|
112
|
+
const contract = signer ? this.contract.connect(signer) : this.contract;
|
|
113
|
+
const tx = await contract.commitDeliverable(agreementId, hash);
|
|
114
|
+
return tx.wait();
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Fetch the on-chain committed hash and compare it against a local buffer.
|
|
118
|
+
* Does NOT release escrow — call ServiceAgreementClient.verifyDeliverable()
|
|
119
|
+
* separately once satisfied.
|
|
120
|
+
*/
|
|
121
|
+
async verifyDeliverable(agreementId, localBuffer, signer) {
|
|
122
|
+
const contract = signer ? this.contract.connect(signer) : this.contract;
|
|
123
|
+
const agreement = await contract.getAgreement(agreementId);
|
|
124
|
+
const onChainHash = agreement.deliverableHash;
|
|
125
|
+
const localHash = await hashDeliverable(localBuffer);
|
|
126
|
+
const match = onChainHash.toLowerCase() === localHash.toLowerCase();
|
|
127
|
+
return { match, onChainHash, localHash };
|
|
128
|
+
}
|
|
129
|
+
/** Upload a buffer to IPFS. See uploadToIPFS for endpoint notes. */
|
|
130
|
+
async uploadToIPFS(buffer, options) {
|
|
131
|
+
return uploadToIPFS(buffer, options);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Upload buffer to IPFS then commit the hash + URI in one call.
|
|
135
|
+
* Returns the committed hash, IPFS URI, and the on-chain transaction receipt.
|
|
136
|
+
*/
|
|
137
|
+
async commitDeliverableIPFS(agreementId, buffer, options, signer) {
|
|
138
|
+
const [hash, { uri }] = await Promise.all([hashDeliverable(buffer), uploadToIPFS(buffer, options)]);
|
|
139
|
+
const receipt = await this.commitDeliverable(agreementId, hash, uri, signer);
|
|
140
|
+
return { hash, uri, receipt };
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Encrypt buffer for recipientPublicKey, upload the ciphertext to IPFS, then
|
|
144
|
+
* commit the plaintext hash on-chain. The on-chain hash covers plaintext so
|
|
145
|
+
* the client can verify integrity after decryption.
|
|
146
|
+
*/
|
|
147
|
+
async commitDeliverableIPFSEncrypted(agreementId, buffer, recipientPublicKey, options, signer) {
|
|
148
|
+
const [hash, { uri }] = await Promise.all([
|
|
149
|
+
hashDeliverable(buffer),
|
|
150
|
+
uploadEncryptedIPFS(buffer, recipientPublicKey, options),
|
|
151
|
+
]);
|
|
152
|
+
const receipt = await this.commitDeliverable(agreementId, hash, uri, signer);
|
|
153
|
+
return { hash, uri, receipt };
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
exports.DeliverableClient = DeliverableClient;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ContractRunner, ethers } from "ethers";
|
|
2
|
+
import { ArbitratorBondState, DisputeClass, DisputeFeeState, DisputeMode } from "./types";
|
|
3
|
+
export declare class DisputeArbitrationClient {
|
|
4
|
+
private contract;
|
|
5
|
+
constructor(address: string, runner: ContractRunner);
|
|
6
|
+
getDisputeFeeState(agreementId: bigint): Promise<DisputeFeeState>;
|
|
7
|
+
getArbitratorBondState(arbitrator: string, agreementId: bigint): Promise<ArbitratorBondState>;
|
|
8
|
+
getFeeQuote(agreementPrice: bigint, token: string, mode: DisputeMode, disputeClass: DisputeClass): Promise<bigint>;
|
|
9
|
+
getAcceptedArbitrators(agreementId: bigint): Promise<string[]>;
|
|
10
|
+
isEligibleArbitrator(address: string): Promise<boolean>;
|
|
11
|
+
getTokenUsdRate(token: string): Promise<bigint>;
|
|
12
|
+
/** Respondent in MUTUAL dispute funds their half of the fee. */
|
|
13
|
+
joinMutualDispute(agreementId: bigint, halfFeeEth?: bigint): Promise<ethers.TransactionReceipt>;
|
|
14
|
+
/** Nominated arbitrator accepts assignment and posts bond. */
|
|
15
|
+
acceptAssignment(agreementId: bigint, bondEth?: bigint): Promise<ethers.TransactionReceipt>;
|
|
16
|
+
/** Trigger fallback to human backstop queue (mutual unfunded or panel not formed). */
|
|
17
|
+
triggerFallback(agreementId: bigint): Promise<ethers.TransactionReceipt>;
|
|
18
|
+
/** Owner-only: slash an arbitrator for manual rules violation. */
|
|
19
|
+
slashArbitrator(agreementId: bigint, arbitrator: string, reason: string): Promise<ethers.TransactionReceipt>;
|
|
20
|
+
/**
|
|
21
|
+
* Arbitrators can reclaim their bond after 45 days if the dispute was never resolved via resolveDisputeFee.
|
|
22
|
+
* Prevents permanent bond lock on stalled disputes.
|
|
23
|
+
*/
|
|
24
|
+
reclaimExpiredBond(agreementId: bigint): Promise<ethers.TransactionReceipt>;
|
|
25
|
+
/** Step 1 of two-step ownership transfer. Owner-only. */
|
|
26
|
+
proposeOwner(newOwner: string): Promise<ethers.TransactionReceipt>;
|
|
27
|
+
/** Step 2 of two-step ownership transfer. Must be called by the pending owner. */
|
|
28
|
+
acceptOwnership(): Promise<ethers.TransactionReceipt>;
|
|
29
|
+
/**
|
|
30
|
+
* Set the USD rate for a payment token. Owner only.
|
|
31
|
+
* @param token Token address (address(0) for ETH)
|
|
32
|
+
* @param usdRate18 USD per token with 18 decimals (e.g. 2000e18 for ETH at $2000)
|
|
33
|
+
* IMPORTANT: This is an admin-set rate, not a trustless oracle. Keep it current.
|
|
34
|
+
*/
|
|
35
|
+
setTokenUsdRate(token: string, usdRate18: bigint): Promise<ethers.TransactionReceipt>;
|
|
36
|
+
setFeeFloorUsd(floorUsd18: bigint): Promise<ethers.TransactionReceipt>;
|
|
37
|
+
setFeeCapUsd(capUsd18: bigint): Promise<ethers.TransactionReceipt>;
|
|
38
|
+
setServiceAgreement(address: string): Promise<ethers.TransactionReceipt>;
|
|
39
|
+
setTrustRegistry(address: string): Promise<ethers.TransactionReceipt>;
|
|
40
|
+
setTreasury(address: string): Promise<ethers.TransactionReceipt>;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=dispute-arbitration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispute-arbitration.d.ts","sourceRoot":"","sources":["../src/dispute-arbitration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAwC1F,qBAAa,wBAAwB;IACnC,OAAO,CAAC,QAAQ,CAAkB;gBAEtB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc;IAM7C,kBAAkB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAmBjE,sBAAsB,CAAC,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAW7F,WAAW,CACf,cAAc,EAAE,MAAM,EACtB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,WAAW,EACjB,YAAY,EAAE,YAAY,GACzB,OAAO,CAAC,MAAM,CAAC;IAIZ,sBAAsB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAI9D,oBAAoB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C,kBAAkB,CAAC;IAKxE,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAC;IAKrE,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAC;CAIvE"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DisputeArbitrationClient = void 0;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
const DISPUTE_ARBITRATION_ABI = [
|
|
6
|
+
// Views
|
|
7
|
+
"function getDisputeFeeState(uint256 agreementId) view returns (tuple(uint8 mode, uint8 disputeClass, address opener, address client, address provider, address token, uint256 agreementPrice, uint256 feeRequired, uint256 openerPaid, uint256 respondentPaid, uint256 openedAt, bool active, bool resolved))",
|
|
8
|
+
"function getArbitratorBondState(address arbitrator, uint256 agreementId) view returns (tuple(uint256 bondAmount, uint256 lockedAt, bool locked, bool slashed, bool returned))",
|
|
9
|
+
"function getFeeQuote(uint256 agreementPrice, address token, uint8 mode, uint8 disputeClass) view returns (uint256 feeInTokens)",
|
|
10
|
+
"function getAcceptedArbitrators(uint256 agreementId) view returns (address[])",
|
|
11
|
+
"function isEligibleArbitrator(address arbitrator) view returns (bool)",
|
|
12
|
+
"function tokenUsdRate18(address token) view returns (uint256)",
|
|
13
|
+
"function feeFloorUsd18() view returns (uint256)",
|
|
14
|
+
"function feeCapUsd18() view returns (uint256)",
|
|
15
|
+
"function minBondFloorUsd18() view returns (uint256)",
|
|
16
|
+
// Transactions
|
|
17
|
+
"function joinMutualDispute(uint256 agreementId) payable",
|
|
18
|
+
"function acceptAssignment(uint256 agreementId) payable",
|
|
19
|
+
"function triggerFallback(uint256 agreementId) returns (bool)",
|
|
20
|
+
"function slashArbitrator(uint256 agreementId, address arbitrator, string reason)",
|
|
21
|
+
"function reclaimExpiredBond(uint256 agreementId)",
|
|
22
|
+
"function transferOwnership(address newOwner)",
|
|
23
|
+
"function acceptOwnership()",
|
|
24
|
+
"function setTokenUsdRate(address token, uint256 usdRate18)",
|
|
25
|
+
"function setFeeFloorUsd(uint256 floorUsd18)",
|
|
26
|
+
"function setFeeCapUsd(uint256 capUsd18)",
|
|
27
|
+
"function setMinBondFloorUsd(uint256 floorUsd18)",
|
|
28
|
+
"function setServiceAgreement(address sa)",
|
|
29
|
+
"function setTrustRegistry(address tr)",
|
|
30
|
+
"function setTreasury(address treasury)",
|
|
31
|
+
// Events
|
|
32
|
+
"event DisputeFeeOpened(uint256 indexed agreementId, uint8 mode, uint8 disputeClass, uint256 feeRequired, address token)",
|
|
33
|
+
"event MutualDisputeFunded(uint256 indexed agreementId, address respondent, uint256 respondentFee)",
|
|
34
|
+
"event DisputeFeeResolved(uint256 indexed agreementId, uint8 outcome, uint256 openerRefund)",
|
|
35
|
+
"event ArbitratorAssigned(uint256 indexed agreementId, address indexed arbitrator, uint256 bondAmount)",
|
|
36
|
+
"event ArbitratorBondReturned(uint256 indexed agreementId, address indexed arbitrator, uint256 amount)",
|
|
37
|
+
"event ArbitratorBondSlashed(uint256 indexed agreementId, address indexed arbitrator, uint256 amount, string reason)",
|
|
38
|
+
"event ArbitratorFeePaid(uint256 indexed agreementId, address indexed arbitrator, uint256 feeShare)",
|
|
39
|
+
"event DisputeFallbackTriggered(uint256 indexed agreementId, string reason)",
|
|
40
|
+
"event TokenRateSet(address indexed token, uint256 usdRate18)",
|
|
41
|
+
];
|
|
42
|
+
class DisputeArbitrationClient {
|
|
43
|
+
constructor(address, runner) {
|
|
44
|
+
this.contract = new ethers_1.ethers.Contract(address, DISPUTE_ARBITRATION_ABI, runner);
|
|
45
|
+
}
|
|
46
|
+
// ─── Views ────────────────────────────────────────────────────────────────
|
|
47
|
+
async getDisputeFeeState(agreementId) {
|
|
48
|
+
const r = await this.contract.getDisputeFeeState(agreementId);
|
|
49
|
+
return {
|
|
50
|
+
mode: Number(r.mode),
|
|
51
|
+
disputeClass: Number(r.disputeClass),
|
|
52
|
+
opener: r.opener,
|
|
53
|
+
client: r.client,
|
|
54
|
+
provider: r.provider,
|
|
55
|
+
token: r.token,
|
|
56
|
+
agreementPrice: BigInt(r.agreementPrice),
|
|
57
|
+
feeRequired: BigInt(r.feeRequired),
|
|
58
|
+
openerPaid: BigInt(r.openerPaid),
|
|
59
|
+
respondentPaid: BigInt(r.respondentPaid),
|
|
60
|
+
openedAt: BigInt(r.openedAt),
|
|
61
|
+
active: r.active,
|
|
62
|
+
resolved: r.resolved,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
async getArbitratorBondState(arbitrator, agreementId) {
|
|
66
|
+
const r = await this.contract.getArbitratorBondState(arbitrator, agreementId);
|
|
67
|
+
return {
|
|
68
|
+
bondAmount: BigInt(r.bondAmount),
|
|
69
|
+
lockedAt: BigInt(r.lockedAt),
|
|
70
|
+
locked: r.locked,
|
|
71
|
+
slashed: r.slashed,
|
|
72
|
+
returned: r.returned,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
async getFeeQuote(agreementPrice, token, mode, disputeClass) {
|
|
76
|
+
return BigInt(await this.contract.getFeeQuote(agreementPrice, token, mode, disputeClass));
|
|
77
|
+
}
|
|
78
|
+
async getAcceptedArbitrators(agreementId) {
|
|
79
|
+
return this.contract.getAcceptedArbitrators(agreementId);
|
|
80
|
+
}
|
|
81
|
+
async isEligibleArbitrator(address) {
|
|
82
|
+
return this.contract.isEligibleArbitrator(address);
|
|
83
|
+
}
|
|
84
|
+
async getTokenUsdRate(token) {
|
|
85
|
+
return BigInt(await this.contract.tokenUsdRate18(token));
|
|
86
|
+
}
|
|
87
|
+
// ─── Transactions ─────────────────────────────────────────────────────────
|
|
88
|
+
/** Respondent in MUTUAL dispute funds their half of the fee. */
|
|
89
|
+
async joinMutualDispute(agreementId, halfFeeEth = 0n // 0 for ERC-20 agreements (pre-approve instead)
|
|
90
|
+
) {
|
|
91
|
+
const tx = await this.contract.joinMutualDispute(agreementId, { value: halfFeeEth });
|
|
92
|
+
return (await tx.wait());
|
|
93
|
+
}
|
|
94
|
+
/** Nominated arbitrator accepts assignment and posts bond. */
|
|
95
|
+
async acceptAssignment(agreementId, bondEth = 0n // 0 for ERC-20 agreements (pre-approve instead)
|
|
96
|
+
) {
|
|
97
|
+
const tx = await this.contract.acceptAssignment(agreementId, { value: bondEth });
|
|
98
|
+
return (await tx.wait());
|
|
99
|
+
}
|
|
100
|
+
/** Trigger fallback to human backstop queue (mutual unfunded or panel not formed). */
|
|
101
|
+
async triggerFallback(agreementId) {
|
|
102
|
+
const tx = await this.contract.triggerFallback(agreementId);
|
|
103
|
+
return (await tx.wait());
|
|
104
|
+
}
|
|
105
|
+
/** Owner-only: slash an arbitrator for manual rules violation. */
|
|
106
|
+
async slashArbitrator(agreementId, arbitrator, reason) {
|
|
107
|
+
const tx = await this.contract.slashArbitrator(agreementId, arbitrator, reason);
|
|
108
|
+
return (await tx.wait());
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Arbitrators can reclaim their bond after 45 days if the dispute was never resolved via resolveDisputeFee.
|
|
112
|
+
* Prevents permanent bond lock on stalled disputes.
|
|
113
|
+
*/
|
|
114
|
+
async reclaimExpiredBond(agreementId) {
|
|
115
|
+
const tx = await this.contract.reclaimExpiredBond(agreementId);
|
|
116
|
+
return (await tx.wait());
|
|
117
|
+
}
|
|
118
|
+
/** Step 1 of two-step ownership transfer. Owner-only. */
|
|
119
|
+
async proposeOwner(newOwner) {
|
|
120
|
+
const tx = await this.contract.transferOwnership(newOwner);
|
|
121
|
+
return (await tx.wait());
|
|
122
|
+
}
|
|
123
|
+
/** Step 2 of two-step ownership transfer. Must be called by the pending owner. */
|
|
124
|
+
async acceptOwnership() {
|
|
125
|
+
const tx = await this.contract.acceptOwnership();
|
|
126
|
+
return (await tx.wait());
|
|
127
|
+
}
|
|
128
|
+
// ─── Admin ────────────────────────────────────────────────────────────────
|
|
129
|
+
/**
|
|
130
|
+
* Set the USD rate for a payment token. Owner only.
|
|
131
|
+
* @param token Token address (address(0) for ETH)
|
|
132
|
+
* @param usdRate18 USD per token with 18 decimals (e.g. 2000e18 for ETH at $2000)
|
|
133
|
+
* IMPORTANT: This is an admin-set rate, not a trustless oracle. Keep it current.
|
|
134
|
+
*/
|
|
135
|
+
async setTokenUsdRate(token, usdRate18) {
|
|
136
|
+
const tx = await this.contract.setTokenUsdRate(token, usdRate18);
|
|
137
|
+
return (await tx.wait());
|
|
138
|
+
}
|
|
139
|
+
async setFeeFloorUsd(floorUsd18) {
|
|
140
|
+
const tx = await this.contract.setFeeFloorUsd(floorUsd18);
|
|
141
|
+
return (await tx.wait());
|
|
142
|
+
}
|
|
143
|
+
async setFeeCapUsd(capUsd18) {
|
|
144
|
+
const tx = await this.contract.setFeeCapUsd(capUsd18);
|
|
145
|
+
return (await tx.wait());
|
|
146
|
+
}
|
|
147
|
+
async setServiceAgreement(address) {
|
|
148
|
+
const tx = await this.contract.setServiceAgreement(address);
|
|
149
|
+
return (await tx.wait());
|
|
150
|
+
}
|
|
151
|
+
async setTrustRegistry(address) {
|
|
152
|
+
const tx = await this.contract.setTrustRegistry(address);
|
|
153
|
+
return (await tx.wait());
|
|
154
|
+
}
|
|
155
|
+
async setTreasury(address) {
|
|
156
|
+
const tx = await this.contract.setTreasury(address);
|
|
157
|
+
return (await tx.wait());
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
exports.DisputeArbitrationClient = DisputeArbitrationClient;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ContractRunner } from "ethers";
|
|
2
|
+
import { GovernanceTransaction } from "./types";
|
|
3
|
+
export declare class GovernanceClient {
|
|
4
|
+
private contract;
|
|
5
|
+
constructor(address: string, runner: ContractRunner);
|
|
6
|
+
submitTransaction(target: string, value: bigint, data: string): Promise<any>;
|
|
7
|
+
confirmTransaction(txId: bigint): Promise<any>;
|
|
8
|
+
revokeConfirmation(txId: bigint): Promise<any>;
|
|
9
|
+
executeTransaction(txId: bigint): Promise<any>;
|
|
10
|
+
getTransaction(txId: bigint): Promise<GovernanceTransaction>;
|
|
11
|
+
transactionCount(): Promise<bigint>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=governance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"governance.d.ts","sourceRoot":"","sources":["../src/governance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAU,MAAM,QAAQ,CAAC;AAEhD,OAAO,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAEhD,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAkB;gBACtB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc;IAC7C,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAC7D,kBAAkB,CAAC,IAAI,EAAE,MAAM;IAC/B,kBAAkB,CAAC,IAAI,EAAE,MAAM;IAC/B,kBAAkB,CAAC,IAAI,EAAE,MAAM;IAC/B,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAClE,gBAAgB;CACjB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GovernanceClient = void 0;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
const contracts_1 = require("./contracts");
|
|
6
|
+
class GovernanceClient {
|
|
7
|
+
constructor(address, runner) { this.contract = new ethers_1.ethers.Contract(address, contracts_1.GOVERNANCE_ABI, runner); }
|
|
8
|
+
async submitTransaction(target, value, data) { const tx = await this.contract.submitTransaction(target, value, data); return tx.wait(); }
|
|
9
|
+
async confirmTransaction(txId) { const tx = await this.contract.confirmTransaction(txId); return tx.wait(); }
|
|
10
|
+
async revokeConfirmation(txId) { const tx = await this.contract.revokeConfirmation(txId); return tx.wait(); }
|
|
11
|
+
async executeTransaction(txId) { const tx = await this.contract.executeTransaction(txId); return tx.wait(); }
|
|
12
|
+
async getTransaction(txId) { const raw = await this.contract.getTransaction(txId); return { target: raw.target, value: BigInt(raw.value), data: raw.data, executed: raw.executed, confirmationCount: BigInt(raw.confirmationCount) }; }
|
|
13
|
+
transactionCount() { return this.contract.transactionCount().then(BigInt); }
|
|
14
|
+
}
|
|
15
|
+
exports.GovernanceClient = GovernanceClient;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export { ARC402WalletClient, ARC402Wallet, type ContextBinding } from "./wallet";
|
|
2
|
+
export { ContractInteractionClient, type IntentPayload, type ContractCallAttestation, type ContractCallResult } from "./contractinteraction";
|
|
3
|
+
export { PolicyClient, PolicyObject, PolicyValidator } from "./policy";
|
|
4
|
+
export { TrustClient, TrustPrimitive } from "./trust";
|
|
5
|
+
export { IntentAttestationClient, IntentAttestation } from "./intent";
|
|
6
|
+
export { SettlementClient, MultiAgentSettlement } from "./settlement";
|
|
7
|
+
export { AgentRegistryClient, type AgentRegistrationInput } from "./agent";
|
|
8
|
+
export { ServiceAgreementClient } from "./agreement";
|
|
9
|
+
export { DisputeArbitrationClient } from "./dispute-arbitration";
|
|
10
|
+
export { ReputationOracleClient } from "./reputation";
|
|
11
|
+
export { SponsorshipAttestationClient } from "./sponsorship";
|
|
12
|
+
export { CapabilityRegistryClient } from "./capability";
|
|
13
|
+
export { GovernanceClient } from "./governance";
|
|
14
|
+
export { signNegotiationMessage, createSignedProposal, createSignedCounter, createSignedAccept, createSignedReject, createNegotiationProposal, createNegotiationCounter, createNegotiationAccept, createNegotiationReject, parseNegotiationMessage } from "./negotiation";
|
|
15
|
+
export { NegotiationGuard } from "./negotiation-guard";
|
|
16
|
+
export { SessionManager } from "./session-manager";
|
|
17
|
+
export { ChannelClient } from "./channel";
|
|
18
|
+
export { AgreementTreeClient, type AgreementTree, type PaymentSplit, type PaymentDistribution, type CreateAgreementResult } from "./multiparty";
|
|
19
|
+
export { WatchtowerClient } from "./watchtower";
|
|
20
|
+
export type { WatchtowerMetadata, WatchtowerStatus } from "./watchtower";
|
|
21
|
+
export { DeliverableClient, DeliverableType, hashDeliverable, hashDeliverableFile, uploadToIPFS, encryptDeliverable, decryptDeliverable, uploadEncryptedIPFS } from "./deliverable";
|
|
22
|
+
export type { DeliverableManifest, DeliverableManifestEntry, IPFSUploadOptions, IPFSUploadResult, EncryptedDeliverable } from "./deliverable";
|
|
23
|
+
export type { NegotiationVerificationResult, NegotiationVerificationError, SignedNegotiationMessage } from "./types";
|
|
24
|
+
export type { ChannelState, Channel, ChannelStatus, OpenChannelParams } from "./types";
|
|
25
|
+
export * from "./contracts";
|
|
26
|
+
export * from "./types";
|
|
27
|
+
export { buildMetadata, validateMetadata, encodeMetadata, decodeMetadata, uploadMetadata, AGENT_METADATA_SCHEMA } from "./metadata";
|
|
28
|
+
export type { AgentMetadata, AgentMetadataModel, AgentMetadataTraining, AgentMetadataPricing, AgentMetadataSla, AgentMetadataContact, AgentMetadataSecurity } from "./metadata";
|
|
29
|
+
export { ColdStartClient } from "./coldstart";
|
|
30
|
+
export { MigrationClient } from "./migration";
|
|
31
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,KAAK,cAAc,EAAE,MAAM,UAAU,CAAC;AACjF,OAAO,EAAE,yBAAyB,EAAE,KAAK,aAAa,EAAE,KAAK,uBAAuB,EAAE,KAAK,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC7I,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACtD,OAA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