@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.
Files changed (128) hide show
  1. package/README.md +184 -0
  2. package/dist/agent.d.ts +29 -0
  3. package/dist/agent.d.ts.map +1 -0
  4. package/dist/agent.js +95 -0
  5. package/dist/agreement.d.ts +57 -0
  6. package/dist/agreement.d.ts.map +1 -0
  7. package/dist/agreement.js +156 -0
  8. package/dist/capability.d.ts +17 -0
  9. package/dist/capability.d.ts.map +1 -0
  10. package/dist/capability.js +19 -0
  11. package/dist/channel.d.ts +39 -0
  12. package/dist/channel.d.ts.map +1 -0
  13. package/dist/channel.js +160 -0
  14. package/dist/coldstart.d.ts +15 -0
  15. package/dist/coldstart.d.ts.map +1 -0
  16. package/dist/coldstart.js +44 -0
  17. package/dist/context.d.ts +2 -0
  18. package/dist/context.d.ts.map +1 -0
  19. package/dist/context.js +2 -0
  20. package/dist/contractinteraction.d.ts +47 -0
  21. package/dist/contractinteraction.d.ts.map +1 -0
  22. package/dist/contractinteraction.js +80 -0
  23. package/dist/contracts.d.ts +27 -0
  24. package/dist/contracts.d.ts.map +1 -0
  25. package/dist/contracts.js +187 -0
  26. package/dist/deliverable.d.ts +118 -0
  27. package/dist/deliverable.d.ts.map +1 -0
  28. package/dist/deliverable.js +156 -0
  29. package/dist/dispute-arbitration.d.ts +42 -0
  30. package/dist/dispute-arbitration.d.ts.map +1 -0
  31. package/dist/dispute-arbitration.js +160 -0
  32. package/dist/governance.d.ts +13 -0
  33. package/dist/governance.d.ts.map +1 -0
  34. package/dist/governance.js +15 -0
  35. package/dist/index.d.ts +31 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +92 -0
  38. package/dist/intent.d.ts +13 -0
  39. package/dist/intent.d.ts.map +1 -0
  40. package/dist/intent.js +26 -0
  41. package/dist/metadata.d.ts +55 -0
  42. package/dist/metadata.d.ts.map +1 -0
  43. package/dist/metadata.js +106 -0
  44. package/dist/migration.d.ts +11 -0
  45. package/dist/migration.d.ts.map +1 -0
  46. package/dist/migration.js +38 -0
  47. package/dist/multiparty.d.ts +56 -0
  48. package/dist/multiparty.d.ts.map +1 -0
  49. package/dist/multiparty.js +86 -0
  50. package/dist/negotiation-guard.d.ts +20 -0
  51. package/dist/negotiation-guard.d.ts.map +1 -0
  52. package/dist/negotiation-guard.js +96 -0
  53. package/dist/negotiation.d.ts +25 -0
  54. package/dist/negotiation.d.ts.map +1 -0
  55. package/dist/negotiation.js +102 -0
  56. package/dist/policy.d.ts +33 -0
  57. package/dist/policy.d.ts.map +1 -0
  58. package/dist/policy.js +72 -0
  59. package/dist/reputation.d.ts +13 -0
  60. package/dist/reputation.d.ts.map +1 -0
  61. package/dist/reputation.js +21 -0
  62. package/dist/session-manager.d.ts +13 -0
  63. package/dist/session-manager.d.ts.map +1 -0
  64. package/dist/session-manager.js +102 -0
  65. package/dist/settlement.d.ts +14 -0
  66. package/dist/settlement.d.ts.map +1 -0
  67. package/dist/settlement.js +35 -0
  68. package/dist/sponsorship.d.ts +17 -0
  69. package/dist/sponsorship.d.ts.map +1 -0
  70. package/dist/sponsorship.js +19 -0
  71. package/dist/trust.d.ts +22 -0
  72. package/dist/trust.d.ts.map +1 -0
  73. package/dist/trust.js +52 -0
  74. package/dist/types.d.ts +391 -0
  75. package/dist/types.d.ts.map +1 -0
  76. package/dist/types.js +119 -0
  77. package/dist/wallet.d.ts +31 -0
  78. package/dist/wallet.d.ts.map +1 -0
  79. package/dist/wallet.js +83 -0
  80. package/dist/watchtower.d.ts +60 -0
  81. package/dist/watchtower.d.ts.map +1 -0
  82. package/dist/watchtower.js +93 -0
  83. package/package.json +30 -0
  84. package/src/agent.ts +122 -0
  85. package/src/agreement.ts +236 -0
  86. package/src/capability.ts +18 -0
  87. package/src/channel.ts +203 -0
  88. package/src/coldstart.ts +52 -0
  89. package/src/context.ts +2 -0
  90. package/src/contractinteraction.d.ts +47 -0
  91. package/src/contractinteraction.d.ts.map +1 -0
  92. package/src/contractinteraction.js +81 -0
  93. package/src/contractinteraction.js.map +1 -0
  94. package/src/contractinteraction.ts +157 -0
  95. package/src/contracts.d.ts +27 -0
  96. package/src/contracts.d.ts.map +1 -0
  97. package/src/contracts.js +188 -0
  98. package/src/contracts.js.map +1 -0
  99. package/src/contracts.ts +186 -0
  100. package/src/deliverable.ts +231 -0
  101. package/src/demos/demo-insurance.ts +148 -0
  102. package/src/demos/demo-multiagent.ts +197 -0
  103. package/src/demos/demo-research.ts +124 -0
  104. package/src/dispute-arbitration.ts +196 -0
  105. package/src/governance.ts +14 -0
  106. package/src/index.ts +31 -0
  107. package/src/intent.ts +22 -0
  108. package/src/metadata.ts +158 -0
  109. package/src/migration.ts +43 -0
  110. package/src/multiparty.ts +132 -0
  111. package/src/negotiation-guard.ts +125 -0
  112. package/src/negotiation.ts +135 -0
  113. package/src/policy.ts +71 -0
  114. package/src/reputation.ts +20 -0
  115. package/src/session-manager.ts +80 -0
  116. package/src/settlement.ts +31 -0
  117. package/src/sponsorship.ts +18 -0
  118. package/src/trust.ts +43 -0
  119. package/src/types.d.ts +391 -0
  120. package/src/types.d.ts.map +1 -0
  121. package/src/types.js +113 -0
  122. package/src/types.js.map +1 -0
  123. package/src/types.ts +484 -0
  124. package/src/wallet.ts +86 -0
  125. package/src/watchtower.ts +124 -0
  126. package/test/negotiation-signing.test.js +157 -0
  127. package/test/sdk.test.js +19 -0
  128. package/tsconfig.json +17 -0
@@ -0,0 +1,25 @@
1
+ import { ethers } from "ethers";
2
+ import type { NegotiationMessage, NegotiationProposal, NegotiationCounter, NegotiationAccept, NegotiationReject } from "./types";
3
+ export declare function computeMessageDigest(message: NegotiationMessage | (Omit<NegotiationMessage, "sig"> & {
4
+ sig?: string;
5
+ })): string;
6
+ export declare function signNegotiationMessage<T extends NegotiationMessage>(message: Omit<T, "sig">, signer: ethers.Wallet | ethers.Signer): Promise<T>;
7
+ export declare function createSignedProposal(input: Omit<NegotiationProposal, "type" | "nonce" | "sig" | "timestamp" | "expiresAt"> & {
8
+ nonce?: string;
9
+ expiresAt?: number;
10
+ }, signer: ethers.Wallet | ethers.Signer): Promise<NegotiationProposal>;
11
+ export declare function createSignedCounter(input: Omit<NegotiationCounter, "type" | "sig" | "timestamp">, signer: ethers.Wallet | ethers.Signer): Promise<NegotiationCounter>;
12
+ export declare function createSignedAccept(input: Omit<NegotiationAccept, "type" | "sig" | "timestamp">, signer: ethers.Wallet | ethers.Signer): Promise<NegotiationAccept>;
13
+ export declare function createSignedReject(input: Omit<NegotiationReject, "type" | "sig" | "timestamp">, signer: ethers.Wallet | ethers.Signer): Promise<NegotiationReject>;
14
+ /** @deprecated Use createSignedProposal instead */
15
+ export declare function createNegotiationProposal(input: Omit<NegotiationProposal, "type" | "nonce" | "sig" | "timestamp" | "expiresAt"> & {
16
+ nonce?: string;
17
+ }): NegotiationProposal;
18
+ /** @deprecated Use createSignedCounter instead */
19
+ export declare function createNegotiationCounter(input: Omit<NegotiationCounter, "type" | "sig" | "timestamp">): NegotiationCounter;
20
+ /** @deprecated Use createSignedAccept instead */
21
+ export declare function createNegotiationAccept(input: Omit<NegotiationAccept, "type" | "sig" | "timestamp">): NegotiationAccept;
22
+ /** @deprecated Use createSignedReject instead */
23
+ export declare function createNegotiationReject(input: Omit<NegotiationReject, "type" | "sig" | "timestamp">): NegotiationReject;
24
+ export declare function parseNegotiationMessage(json: string): NegotiationMessage;
25
+ //# sourceMappingURL=negotiation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"negotiation.d.ts","sourceRoot":"","sources":["../src/negotiation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,SAAS,CAAC;AAOjB,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,kBAAkB,GAAG,CAAC,IAAI,CAAC,kBAAkB,EAAE,KAAK,CAAC,GAAG;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,MAAM,CAU/H;AAID,wBAAsB,sBAAsB,CAAC,CAAC,SAAS,kBAAkB,EACvE,OAAO,EAAE,IAAI,CAAC,CAAC,EAAE,KAAK,CAAC,EACvB,MAAM,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,GACpC,OAAO,CAAC,CAAC,CAAC,CAIZ;AAID,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,IAAI,CAAC,mBAAmB,EAAE,MAAM,GAAG,OAAO,GAAG,KAAK,GAAG,WAAW,GAAG,WAAW,CAAC,GAAG;IACvF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,EACD,MAAM,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,GACpC,OAAO,CAAC,mBAAmB,CAAC,CAU9B;AAED,wBAAsB,mBAAmB,CACvC,KAAK,EAAE,IAAI,CAAC,kBAAkB,EAAE,MAAM,GAAG,KAAK,GAAG,WAAW,CAAC,EAC7D,MAAM,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,GACpC,OAAO,CAAC,kBAAkB,CAAC,CAO7B;AAED,wBAAsB,kBAAkB,CACtC,KAAK,EAAE,IAAI,CAAC,iBAAiB,EAAE,MAAM,GAAG,KAAK,GAAG,WAAW,CAAC,EAC5D,MAAM,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,GACpC,OAAO,CAAC,iBAAiB,CAAC,CAO5B;AAED,wBAAsB,kBAAkB,CACtC,KAAK,EAAE,IAAI,CAAC,iBAAiB,EAAE,MAAM,GAAG,KAAK,GAAG,WAAW,CAAC,EAC5D,MAAM,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,GACpC,OAAO,CAAC,iBAAiB,CAAC,CAO5B;AAID,mDAAmD;AACnD,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,IAAI,CAAC,mBAAmB,EAAE,MAAM,GAAG,OAAO,GAAG,KAAK,GAAG,WAAW,GAAG,WAAW,CAAC,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GAC1G,mBAAmB,CAWrB;AAED,kDAAkD;AAClD,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,IAAI,CAAC,kBAAkB,EAAE,MAAM,GAAG,KAAK,GAAG,WAAW,CAAC,GAAG,kBAAkB,CAG1H;AAED,iDAAiD;AACjD,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,IAAI,CAAC,iBAAiB,EAAE,MAAM,GAAG,KAAK,GAAG,WAAW,CAAC,GAAG,iBAAiB,CAGvH;AAED,iDAAiD;AACjD,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,IAAI,CAAC,iBAAiB,EAAE,MAAM,GAAG,KAAK,GAAG,WAAW,CAAC,GAAG,iBAAiB,CAGvH;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,CAKxE"}
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.computeMessageDigest = computeMessageDigest;
4
+ exports.signNegotiationMessage = signNegotiationMessage;
5
+ exports.createSignedProposal = createSignedProposal;
6
+ exports.createSignedCounter = createSignedCounter;
7
+ exports.createSignedAccept = createSignedAccept;
8
+ exports.createSignedReject = createSignedReject;
9
+ exports.createNegotiationProposal = createNegotiationProposal;
10
+ exports.createNegotiationCounter = createNegotiationCounter;
11
+ exports.createNegotiationAccept = createNegotiationAccept;
12
+ exports.createNegotiationReject = createNegotiationReject;
13
+ exports.parseNegotiationMessage = parseNegotiationMessage;
14
+ const ethers_1 = require("ethers");
15
+ const MAX_MESSAGE_BYTES = 64 * 1024; // 64KB
16
+ // --- Digest computation ---
17
+ // digest = keccak256(abi.encodePacked(type, from, to, nonce, timestamp))
18
+ // nonce is message.nonce (PROPOSE) or message.refNonce (COUNTER/ACCEPT/REJECT) or bytes32(0) if absent
19
+ function computeMessageDigest(message) {
20
+ const m = message;
21
+ const rawNonce = m.nonce || m.refNonce || ethers_1.ethers.ZeroHash;
22
+ // solidityPackedKeccak256 requires exactly 32 bytes for bytes32 — pad to 32 bytes
23
+ const nonce = ethers_1.ethers.zeroPadValue(rawNonce, 32);
24
+ return ethers_1.ethers.solidityPackedKeccak256(["string", "address", "address", "bytes32", "uint256"], [message.type, message.from, message.to, nonce, message.timestamp]);
25
+ }
26
+ // --- Signing ---
27
+ async function signNegotiationMessage(message, signer) {
28
+ const digest = computeMessageDigest(message);
29
+ const sig = await signer.signMessage(ethers_1.ethers.getBytes(digest));
30
+ return { ...message, sig };
31
+ }
32
+ // --- Signed factory functions ---
33
+ async function createSignedProposal(input, signer) {
34
+ const now = Math.floor(Date.now() / 1000);
35
+ const unsigned = {
36
+ type: "PROPOSE",
37
+ nonce: input.nonce ?? ethers_1.ethers.hexlify(ethers_1.ethers.randomBytes(16)),
38
+ timestamp: now,
39
+ expiresAt: input.expiresAt ?? now + 3600,
40
+ ...input,
41
+ };
42
+ return signNegotiationMessage(unsigned, signer);
43
+ }
44
+ async function createSignedCounter(input, signer) {
45
+ const unsigned = {
46
+ type: "COUNTER",
47
+ timestamp: Math.floor(Date.now() / 1000),
48
+ ...input,
49
+ };
50
+ return signNegotiationMessage(unsigned, signer);
51
+ }
52
+ async function createSignedAccept(input, signer) {
53
+ const unsigned = {
54
+ type: "ACCEPT",
55
+ timestamp: Math.floor(Date.now() / 1000),
56
+ ...input,
57
+ };
58
+ return signNegotiationMessage(unsigned, signer);
59
+ }
60
+ async function createSignedReject(input, signer) {
61
+ const unsigned = {
62
+ type: "REJECT",
63
+ timestamp: Math.floor(Date.now() / 1000),
64
+ ...input,
65
+ };
66
+ return signNegotiationMessage(unsigned, signer);
67
+ }
68
+ // --- Deprecated unsigned factories (backwards compat) ---
69
+ /** @deprecated Use createSignedProposal instead */
70
+ function createNegotiationProposal(input) {
71
+ console.warn("createNegotiationProposal: unsigned messages are deprecated. Use createSignedProposal instead.");
72
+ const now = Math.floor(Date.now() / 1000);
73
+ return {
74
+ type: "PROPOSE",
75
+ nonce: input.nonce ?? ethers_1.ethers.hexlify(ethers_1.ethers.randomBytes(16)),
76
+ timestamp: now,
77
+ expiresAt: now + 3600,
78
+ sig: "0x",
79
+ ...input,
80
+ };
81
+ }
82
+ /** @deprecated Use createSignedCounter instead */
83
+ function createNegotiationCounter(input) {
84
+ console.warn("createNegotiationCounter: unsigned messages are deprecated. Use createSignedCounter instead.");
85
+ return { type: "COUNTER", timestamp: Math.floor(Date.now() / 1000), sig: "0x", ...input };
86
+ }
87
+ /** @deprecated Use createSignedAccept instead */
88
+ function createNegotiationAccept(input) {
89
+ console.warn("createNegotiationAccept: unsigned messages are deprecated. Use createSignedAccept instead.");
90
+ return { type: "ACCEPT", timestamp: Math.floor(Date.now() / 1000), sig: "0x", ...input };
91
+ }
92
+ /** @deprecated Use createSignedReject instead */
93
+ function createNegotiationReject(input) {
94
+ console.warn("createNegotiationReject: unsigned messages are deprecated. Use createSignedReject instead.");
95
+ return { type: "REJECT", timestamp: Math.floor(Date.now() / 1000), sig: "0x", ...input };
96
+ }
97
+ function parseNegotiationMessage(json) {
98
+ if (Buffer.byteLength(json, "utf8") > MAX_MESSAGE_BYTES) {
99
+ throw new Error("NegotiationMessage exceeds 64KB size limit");
100
+ }
101
+ return JSON.parse(json);
102
+ }
@@ -0,0 +1,33 @@
1
+ import { ContractRunner, ethers } from "ethers";
2
+ import { Policy } from "./types";
3
+ export declare class PolicyClient {
4
+ private contract;
5
+ constructor(address: string, runner: ContractRunner);
6
+ set(walletAddress: string, categories: Record<string, bigint>): Promise<void>;
7
+ get(walletAddress: string): Promise<Policy>;
8
+ validate(walletAddress: string, category: string, amount: bigint): Promise<{
9
+ valid: any;
10
+ reason: any;
11
+ }>;
12
+ /** Freeze spend for a wallet. Callable by the wallet, its owner, or an authorized freeze agent. */
13
+ freezeSpend(wallet: string): Promise<ethers.TransactionReceipt>;
14
+ /** Unfreeze spend for a wallet. Only callable by the wallet or its registered owner. */
15
+ unfreeze(wallet: string): Promise<ethers.TransactionReceipt>;
16
+ /** Authorize a watchtower agent to freeze this wallet's spending. Caller must be the wallet. */
17
+ authorizeFreezeAgent(agent: string): Promise<ethers.TransactionReceipt>;
18
+ /** Revoke a watchtower agent's freeze authorization. */
19
+ revokeFreezeAgent(agent: string): Promise<ethers.TransactionReceipt>;
20
+ /**
21
+ * Queue a daily-limit reduction for wallet+category. Only reductions (newCap < current) are allowed.
22
+ * A 24-hour timelock applies before the new cap can be applied.
23
+ */
24
+ queueCapReduction(wallet: string, category: string, newCap: bigint): Promise<ethers.TransactionReceipt>;
25
+ /** Apply a queued cap reduction after the 24-hour timelock has elapsed. */
26
+ applyCapReduction(wallet: string, category: string): Promise<ethers.TransactionReceipt>;
27
+ }
28
+ export declare class PolicyObject extends PolicyClient {
29
+ }
30
+ export declare class PolicyValidator {
31
+ static validate(policy: Policy, category: string, amount: bigint): boolean;
32
+ }
33
+ //# sourceMappingURL=policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../src/policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEjC,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAkB;gBACtB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc;IAC7C,GAAG,CAAC,aAAa,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAS7D,GAAG,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAS3C,QAAQ,CAAC,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;;;;IAKtE,mGAAmG;IAC7F,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAC;IAKrE,wFAAwF;IAClF,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAC;IAKlE,gGAAgG;IAC1F,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAC;IAK7E,wDAAwD;IAClD,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAC;IAK1E;;;OAGG;IACG,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAC;IAK7G,2EAA2E;IACrE,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAC;CAI9F;AACD,qBAAa,YAAa,SAAQ,YAAY;CAAG;AACjD,qBAAa,eAAe;IAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CAAiG"}
package/dist/policy.js ADDED
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PolicyValidator = exports.PolicyObject = exports.PolicyClient = void 0;
4
+ const ethers_1 = require("ethers");
5
+ const contracts_1 = require("./contracts");
6
+ class PolicyClient {
7
+ constructor(address, runner) { this.contract = new ethers_1.ethers.Contract(address, contracts_1.POLICY_ENGINE_ABI, runner); }
8
+ async set(walletAddress, categories) {
9
+ const policyData = JSON.stringify(Object.fromEntries(Object.entries(categories).map(([k, v]) => [k, v.toString()])));
10
+ const tx = await this.contract.setPolicy(ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(policyData)), ethers_1.ethers.toUtf8Bytes(policyData));
11
+ await tx.wait();
12
+ for (const [category, limit] of Object.entries(categories)) {
13
+ const updateTx = await this.contract.setCategoryLimitFor(walletAddress, category, limit);
14
+ await updateTx.wait();
15
+ }
16
+ }
17
+ async get(walletAddress) {
18
+ const [policyHash, policyDataBytes] = await this.contract.getPolicy(walletAddress);
19
+ const categories = {};
20
+ if (policyDataBytes && policyDataBytes !== "0x") {
21
+ const parsed = JSON.parse(ethers_1.ethers.toUtf8String(policyDataBytes));
22
+ for (const [key, value] of Object.entries(parsed))
23
+ categories[key] = { limitPerTx: BigInt(value) };
24
+ }
25
+ return { walletAddress, policyHash, categories };
26
+ }
27
+ async validate(walletAddress, category, amount) {
28
+ const [valid, reason] = await this.contract.validateSpend(walletAddress, category, amount, ethers_1.ethers.ZeroHash);
29
+ return { valid, reason: valid ? undefined : reason };
30
+ }
31
+ /** Freeze spend for a wallet. Callable by the wallet, its owner, or an authorized freeze agent. */
32
+ async freezeSpend(wallet) {
33
+ const tx = await this.contract.freezeSpend(wallet);
34
+ return (await tx.wait());
35
+ }
36
+ /** Unfreeze spend for a wallet. Only callable by the wallet or its registered owner. */
37
+ async unfreeze(wallet) {
38
+ const tx = await this.contract.unfreeze(wallet);
39
+ return (await tx.wait());
40
+ }
41
+ /** Authorize a watchtower agent to freeze this wallet's spending. Caller must be the wallet. */
42
+ async authorizeFreezeAgent(agent) {
43
+ const tx = await this.contract.authorizeFreezeAgent(agent);
44
+ return (await tx.wait());
45
+ }
46
+ /** Revoke a watchtower agent's freeze authorization. */
47
+ async revokeFreezeAgent(agent) {
48
+ const tx = await this.contract.revokeFreezeAgent(agent);
49
+ return (await tx.wait());
50
+ }
51
+ /**
52
+ * Queue a daily-limit reduction for wallet+category. Only reductions (newCap < current) are allowed.
53
+ * A 24-hour timelock applies before the new cap can be applied.
54
+ */
55
+ async queueCapReduction(wallet, category, newCap) {
56
+ const tx = await this.contract.queueCapReduction(wallet, category, newCap);
57
+ return (await tx.wait());
58
+ }
59
+ /** Apply a queued cap reduction after the 24-hour timelock has elapsed. */
60
+ async applyCapReduction(wallet, category) {
61
+ const tx = await this.contract.applyCapReduction(wallet, category);
62
+ return (await tx.wait());
63
+ }
64
+ }
65
+ exports.PolicyClient = PolicyClient;
66
+ class PolicyObject extends PolicyClient {
67
+ }
68
+ exports.PolicyObject = PolicyObject;
69
+ class PolicyValidator {
70
+ static validate(policy, category, amount) { return !!policy.categories[category] && amount <= policy.categories[category].limitPerTx; }
71
+ }
72
+ exports.PolicyValidator = PolicyValidator;
@@ -0,0 +1,13 @@
1
+ import { ContractRunner } from "ethers";
2
+ import { ReputationSignal, ReputationSignalType, ReputationSummary } from "./types";
3
+ export declare class ReputationOracleClient {
4
+ private contract;
5
+ constructor(address: string, runner: ContractRunner);
6
+ publishSignal(subject: string, signalType: ReputationSignalType, capabilityHash?: string, reason?: string): Promise<any>;
7
+ getReputation(subject: string): Promise<ReputationSummary>;
8
+ getCapabilityReputation(subject: string, capabilityHash: string): Promise<bigint>;
9
+ getSignalCount(subject: string): Promise<bigint>;
10
+ getSignal(subject: string, index: bigint): Promise<ReputationSignal>;
11
+ listSignals(subject: string): Promise<ReputationSignal[]>;
12
+ }
13
+ //# sourceMappingURL=reputation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reputation.d.ts","sourceRoot":"","sources":["../src/reputation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAU,MAAM,QAAQ,CAAC;AAEhD,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEpF,qBAAa,sBAAsB;IACjC,OAAO,CAAC,QAAQ,CAAkB;gBACtB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc;IAC7C,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,oBAAoB,EAAE,cAAc,SAAkB,EAAE,MAAM,SAAK;IAC9G,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAIhE,uBAAuB,CAAC,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM;IAC/D,cAAc,CAAC,OAAO,EAAE,MAAM;IACxB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAIpE,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC;CAChE"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ReputationOracleClient = void 0;
4
+ const ethers_1 = require("ethers");
5
+ const contracts_1 = require("./contracts");
6
+ class ReputationOracleClient {
7
+ constructor(address, runner) { this.contract = new ethers_1.ethers.Contract(address, contracts_1.REPUTATION_ORACLE_ABI, runner); }
8
+ async publishSignal(subject, signalType, capabilityHash = ethers_1.ethers.ZeroHash, reason = "") { const tx = await this.contract.publishSignal(subject, signalType, capabilityHash, reason); return tx.wait(); }
9
+ async getReputation(subject) {
10
+ const [endorsements, warnings, blocks, weightedScore] = await this.contract.getReputation(subject);
11
+ return { endorsements: BigInt(endorsements), warnings: BigInt(warnings), blocks: BigInt(blocks), weightedScore: BigInt(weightedScore) };
12
+ }
13
+ getCapabilityReputation(subject, capabilityHash) { return this.contract.getCapabilityReputation(subject, capabilityHash).then(BigInt); }
14
+ getSignalCount(subject) { return this.contract.getSignalCount(subject).then(BigInt); }
15
+ async getSignal(subject, index) {
16
+ const raw = await this.contract.getSignal(subject, index);
17
+ return { publisher: raw.publisher, subject: raw.subject, signalType: Number(raw.signalType), capabilityHash: raw.capabilityHash, reason: raw.reason, publisherTrustAtTime: BigInt(raw.publisherTrustAtTime), timestamp: BigInt(raw.timestamp), autoPublished: raw.autoPublished };
18
+ }
19
+ async listSignals(subject) { const count = Number(await this.getSignalCount(subject)); return Promise.all(Array.from({ length: count }, (_, i) => this.getSignal(subject, BigInt(i)))); }
20
+ }
21
+ exports.ReputationOracleClient = ReputationOracleClient;
@@ -0,0 +1,13 @@
1
+ import type { NegotiationMessage, NegotiationSession } from "./types";
2
+ export declare class SessionManager {
3
+ private sessionsDir;
4
+ constructor(sessionsDir?: string);
5
+ createSession(initiator: string, responder: string): NegotiationSession;
6
+ addMessage(sessionId: string, message: NegotiationMessage): void;
7
+ computeTranscriptHash(messages: NegotiationMessage[]): `0x${string}`;
8
+ load(sessionId: string): NegotiationSession;
9
+ save(session: NegotiationSession): void;
10
+ list(): NegotiationSession[];
11
+ setOnChainId(sessionId: string, agreementId: string): void;
12
+ }
13
+ //# sourceMappingURL=session-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-manager.d.ts","sourceRoot":"","sources":["../src/session-manager.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAItE,qBAAa,cAAc;IACb,OAAO,CAAC,WAAW;gBAAX,WAAW,SAAe;IAI9C,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,kBAAkB;IAoBvE,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB,GAAG,IAAI;IAgBhE,qBAAqB,CAAC,QAAQ,EAAE,kBAAkB,EAAE,GAAG,KAAK,MAAM,EAAE;IAKpE,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,kBAAkB;IAM3C,IAAI,CAAC,OAAO,EAAE,kBAAkB,GAAG,IAAI;IAOvC,IAAI,IAAI,kBAAkB,EAAE;IAO5B,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI;CAK3D"}
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.SessionManager = void 0;
37
+ const fs = __importStar(require("fs"));
38
+ const path = __importStar(require("path"));
39
+ const os = __importStar(require("os"));
40
+ const ethers_1 = require("ethers");
41
+ const SESSIONS_DIR = path.join(os.homedir(), ".arc402", "sessions");
42
+ class SessionManager {
43
+ constructor(sessionsDir = SESSIONS_DIR) {
44
+ this.sessionsDir = sessionsDir;
45
+ fs.mkdirSync(this.sessionsDir, { recursive: true });
46
+ }
47
+ createSession(initiator, responder) {
48
+ const nonce = ethers_1.ethers.hexlify(ethers_1.ethers.randomBytes(16));
49
+ const sessionId = ethers_1.ethers.keccak256(ethers_1.ethers.AbiCoder.defaultAbiCoder().encode(["address", "address", "uint256", "bytes16"], [initiator, responder, Math.floor(Date.now() / 1000), nonce]));
50
+ const session = {
51
+ sessionId,
52
+ initiator: initiator,
53
+ responder: responder,
54
+ createdAt: Math.floor(Date.now() / 1000),
55
+ messages: [],
56
+ state: "OPEN",
57
+ };
58
+ this.save(session);
59
+ return session;
60
+ }
61
+ addMessage(sessionId, message) {
62
+ const session = this.load(sessionId);
63
+ session.messages.push(message);
64
+ if (message.type === "ACCEPT") {
65
+ session.state = "ACCEPTED";
66
+ session.agreedPrice = message.agreedPrice;
67
+ session.agreedDeadline = message.agreedDeadline;
68
+ session.transcriptHash = this.computeTranscriptHash(session.messages);
69
+ }
70
+ if (message.type === "REJECT") {
71
+ session.state = "REJECTED";
72
+ session.transcriptHash = this.computeTranscriptHash(session.messages);
73
+ }
74
+ this.save(session);
75
+ }
76
+ computeTranscriptHash(messages) {
77
+ const transcript = JSON.stringify(messages);
78
+ return ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(transcript));
79
+ }
80
+ load(sessionId) {
81
+ const file = path.join(this.sessionsDir, `${sessionId}.json`);
82
+ if (!fs.existsSync(file))
83
+ throw new Error(`Session not found: ${sessionId}`);
84
+ return JSON.parse(fs.readFileSync(file, "utf8"));
85
+ }
86
+ save(session) {
87
+ fs.writeFileSync(path.join(this.sessionsDir, `${session.sessionId}.json`), JSON.stringify(session, null, 2));
88
+ }
89
+ list() {
90
+ if (!fs.existsSync(this.sessionsDir))
91
+ return [];
92
+ return fs.readdirSync(this.sessionsDir)
93
+ .filter(f => f.endsWith(".json"))
94
+ .map(f => JSON.parse(fs.readFileSync(path.join(this.sessionsDir, f), "utf8")));
95
+ }
96
+ setOnChainId(sessionId, agreementId) {
97
+ const session = this.load(sessionId);
98
+ session.onChainAgreementId = agreementId;
99
+ this.save(session);
100
+ }
101
+ }
102
+ exports.SessionManager = SessionManager;
@@ -0,0 +1,14 @@
1
+ import { ContractRunner } from "ethers";
2
+ import { SettlementProposal } from "./types";
3
+ export declare class SettlementClient {
4
+ private contract;
5
+ constructor(address: string, runner: ContractRunner);
6
+ propose(fromWallet: string, toWallet: string, amount: bigint, intentId: string, ttlSeconds?: number): Promise<string>;
7
+ accept(id: string): Promise<any>;
8
+ reject(id: string, reason: string): Promise<any>;
9
+ execute(id: string): Promise<any>;
10
+ getProposal(id: string): Promise<SettlementProposal>;
11
+ }
12
+ export declare class MultiAgentSettlement extends SettlementClient {
13
+ }
14
+ //# sourceMappingURL=settlement.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settlement.d.ts","sourceRoot":"","sources":["../src/settlement.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAU,MAAM,QAAQ,CAAC;AAEhD,OAAO,EAAE,kBAAkB,EAAoB,MAAM,SAAS,CAAC;AAI/D,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAkB;gBACtB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc;IAC7C,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,SAAO;IAajG,MAAM,CAAC,EAAE,EAAE,MAAM;IACjB,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IACjC,OAAO,CAAC,EAAE,EAAE,MAAM;IAClB,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;CAI3D;AACD,qBAAa,oBAAqB,SAAQ,gBAAgB;CAAG"}
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MultiAgentSettlement = exports.SettlementClient = void 0;
4
+ const ethers_1 = require("ethers");
5
+ const contracts_1 = require("./contracts");
6
+ const STATUS_MAP = ["PENDING", "ACCEPTED", "REJECTED", "EXECUTED", "EXPIRED"];
7
+ class SettlementClient {
8
+ constructor(address, runner) { this.contract = new ethers_1.ethers.Contract(address, contracts_1.SETTLEMENT_COORDINATOR_ABI, runner); }
9
+ async propose(fromWallet, toWallet, amount, intentId, ttlSeconds = 3600) {
10
+ const expiresAt = Math.floor(Date.now() / 1000) + ttlSeconds;
11
+ const tx = await this.contract.propose(fromWallet, toWallet, amount, intentId, expiresAt);
12
+ const receipt = await tx.wait();
13
+ const iface = new ethers_1.ethers.Interface(contracts_1.SETTLEMENT_COORDINATOR_ABI);
14
+ for (const log of receipt.logs) {
15
+ try {
16
+ const parsed = iface.parseLog(log);
17
+ if (parsed?.name === "ProposalCreated")
18
+ return parsed.args.proposalId;
19
+ }
20
+ catch { }
21
+ }
22
+ throw new Error("Could not parse proposalId from receipt");
23
+ }
24
+ async accept(id) { const tx = await this.contract.accept(id); return tx.wait(); }
25
+ async reject(id, reason) { const tx = await this.contract.reject(id, reason); return tx.wait(); }
26
+ async execute(id) { const proposal = await this.getProposal(id); const tx = await this.contract.execute(id, { value: proposal.amount }); return tx.wait(); }
27
+ async getProposal(id) {
28
+ const [from, to, amount, intentId, expiresAt, statusNum, rejectionReason] = await this.contract.getProposal(id);
29
+ return { proposalId: id, from, to, amount: BigInt(amount), intentId, expiresAt: Number(expiresAt), status: STATUS_MAP[Number(statusNum)] ?? "PENDING", rejectionReason };
30
+ }
31
+ }
32
+ exports.SettlementClient = SettlementClient;
33
+ class MultiAgentSettlement extends SettlementClient {
34
+ }
35
+ exports.MultiAgentSettlement = MultiAgentSettlement;
@@ -0,0 +1,17 @@
1
+ import { ContractRunner } from "ethers";
2
+ import { IdentityTier, SponsorshipAttestationRecord } from "./types";
3
+ export declare class SponsorshipAttestationClient {
4
+ private contract;
5
+ constructor(address: string, runner: ContractRunner);
6
+ publish(agent: string, expiresAt?: number): Promise<any>;
7
+ publishWithTier(agent: string, expiresAt: number, tier: IdentityTier, evidenceURI?: string): Promise<any>;
8
+ revoke(attestationId: string): Promise<any>;
9
+ isActive(attestationId: string): Promise<any>;
10
+ getActiveAttestation(sponsor: string, agent: string): Promise<any>;
11
+ getAttestation(attestationId: string): Promise<SponsorshipAttestationRecord>;
12
+ getSponsorAttestations(sponsor: string): Promise<any>;
13
+ getAgentAttestations(agent: string): Promise<any>;
14
+ activeSponsorCount(sponsor: string): Promise<bigint>;
15
+ getHighestTier(agent: string): Promise<IdentityTier>;
16
+ }
17
+ //# sourceMappingURL=sponsorship.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sponsorship.d.ts","sourceRoot":"","sources":["../src/sponsorship.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAU,MAAM,QAAQ,CAAC;AAEhD,OAAO,EAAE,YAAY,EAAE,4BAA4B,EAAE,MAAM,SAAS,CAAC;AAErE,qBAAa,4BAA4B;IACvC,OAAO,CAAC,QAAQ,CAAkB;gBACtB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc;IAC7C,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,SAAI;IACpC,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,WAAW,SAAK;IACtF,MAAM,CAAC,aAAa,EAAE,MAAM;IAClC,QAAQ,CAAC,aAAa,EAAE,MAAM;IAC9B,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAC7C,cAAc,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,4BAA4B,CAAC;IAClF,sBAAsB,CAAC,OAAO,EAAE,MAAM;IACtC,oBAAoB,CAAC,KAAK,EAAE,MAAM;IAClC,kBAAkB,CAAC,OAAO,EAAE,MAAM;IAClC,cAAc,CAAC,KAAK,EAAE,MAAM;CAC7B"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SponsorshipAttestationClient = void 0;
4
+ const ethers_1 = require("ethers");
5
+ const contracts_1 = require("./contracts");
6
+ class SponsorshipAttestationClient {
7
+ constructor(address, runner) { this.contract = new ethers_1.ethers.Contract(address, contracts_1.SPONSORSHIP_ATTESTATION_ABI, runner); }
8
+ async publish(agent, expiresAt = 0) { const tx = await this.contract.publish(agent, expiresAt); return tx.wait(); }
9
+ async publishWithTier(agent, expiresAt, tier, evidenceURI = "") { const tx = await this.contract.publishWithTier(agent, expiresAt, tier, evidenceURI); return tx.wait(); }
10
+ async revoke(attestationId) { const tx = await this.contract.revoke(attestationId); return tx.wait(); }
11
+ isActive(attestationId) { return this.contract.isActive(attestationId); }
12
+ getActiveAttestation(sponsor, agent) { return this.contract.getActiveAttestation(sponsor, agent); }
13
+ async getAttestation(attestationId) { const raw = await this.contract.getAttestation(attestationId); return { sponsor: raw.sponsor, agent: raw.agent, issuedAt: BigInt(raw.issuedAt), expiresAt: BigInt(raw.expiresAt), revoked: raw.revoked, tier: Number(raw.tier), evidenceURI: raw.evidenceURI }; }
14
+ getSponsorAttestations(sponsor) { return this.contract.getSponsorAttestations(sponsor); }
15
+ getAgentAttestations(agent) { return this.contract.getAgentAttestations(agent); }
16
+ activeSponsorCount(sponsor) { return this.contract.activeSponsorCount(sponsor).then(BigInt); }
17
+ getHighestTier(agent) { return this.contract.getHighestTier(agent).then((value) => Number(value)); }
18
+ }
19
+ exports.SponsorshipAttestationClient = SponsorshipAttestationClient;
@@ -0,0 +1,22 @@
1
+ import { ContractRunner } from "ethers";
2
+ import { TrustScore } from "./types";
3
+ declare function getTrustLevel(score: number): TrustScore["level"];
4
+ declare function getNextLevelAt(score: number): number;
5
+ export declare class TrustClient {
6
+ private contract;
7
+ constructor(address: string, runner: ContractRunner);
8
+ getScore(walletAddress: string): Promise<TrustScore>;
9
+ /**
10
+ * Returns the effective trust score for a wallet, accounting for any decay or bonus adjustments
11
+ * applied by the TrustRegistry (e.g. velocity bonuses, anomaly penalties).
12
+ * Prefer this over getScore for policy decisions.
13
+ */
14
+ getEffectiveScore(walletAddress: string): Promise<TrustScore>;
15
+ init(walletAddress: string): Promise<any>;
16
+ getTrustLevel: typeof getTrustLevel;
17
+ getNextLevelAt: typeof getNextLevelAt;
18
+ }
19
+ export declare class TrustPrimitive extends TrustClient {
20
+ }
21
+ export {};
22
+ //# sourceMappingURL=trust.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trust.d.ts","sourceRoot":"","sources":["../src/trust.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAU,MAAM,QAAQ,CAAC;AAEhD,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC,iBAAS,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC,OAAO,CAAC,CAMzD;AAED,iBAAS,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAM7C;AAED,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAkB;gBACtB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc;IAC7C,QAAQ,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAK1D;;;;OAIG;IACG,iBAAiB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAK7D,IAAI,CAAC,aAAa,EAAE,MAAM;IAChC,aAAa,uBAAiB;IAC9B,cAAc,wBAAkB;CACjC;AACD,qBAAa,cAAe,SAAQ,WAAW;CAAG"}
package/dist/trust.js ADDED
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TrustPrimitive = exports.TrustClient = void 0;
4
+ const ethers_1 = require("ethers");
5
+ const contracts_1 = require("./contracts");
6
+ function getTrustLevel(score) {
7
+ if (score < 100)
8
+ return "probationary";
9
+ if (score < 300)
10
+ return "restricted";
11
+ if (score < 600)
12
+ return "standard";
13
+ if (score < 800)
14
+ return "elevated";
15
+ return "autonomous";
16
+ }
17
+ function getNextLevelAt(score) {
18
+ if (score < 100)
19
+ return 100;
20
+ if (score < 300)
21
+ return 300;
22
+ if (score < 600)
23
+ return 600;
24
+ if (score < 800)
25
+ return 800;
26
+ return 0;
27
+ }
28
+ class TrustClient {
29
+ constructor(address, runner) {
30
+ this.getTrustLevel = getTrustLevel;
31
+ this.getNextLevelAt = getNextLevelAt;
32
+ this.contract = new ethers_1.ethers.Contract(address, contracts_1.TRUST_REGISTRY_ABI, runner);
33
+ }
34
+ async getScore(walletAddress) {
35
+ const score = Number(await this.contract.getScore(walletAddress));
36
+ return { score, level: getTrustLevel(score), nextLevelAt: getNextLevelAt(score) };
37
+ }
38
+ /**
39
+ * Returns the effective trust score for a wallet, accounting for any decay or bonus adjustments
40
+ * applied by the TrustRegistry (e.g. velocity bonuses, anomaly penalties).
41
+ * Prefer this over getScore for policy decisions.
42
+ */
43
+ async getEffectiveScore(walletAddress) {
44
+ const score = Number(await this.contract.getEffectiveScore(walletAddress));
45
+ return { score, level: getTrustLevel(score), nextLevelAt: getNextLevelAt(score) };
46
+ }
47
+ async init(walletAddress) { const tx = await this.contract.initWallet(walletAddress); return tx.wait(); }
48
+ }
49
+ exports.TrustClient = TrustClient;
50
+ class TrustPrimitive extends TrustClient {
51
+ }
52
+ exports.TrustPrimitive = TrustPrimitive;