@trustthenverify/sdk 1.0.0 → 1.1.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/dist/index.d.ts CHANGED
@@ -4,34 +4,23 @@
4
4
  * TypeScript SDK for the AI agent trust registry.
5
5
  * https://trustthenverify.com
6
6
  */
7
+ export interface TrustDimension {
8
+ score: number;
9
+ max: number;
10
+ }
7
11
  export interface TrustScore {
8
12
  total: number;
9
13
  confidence: number;
10
- tier: number;
11
- tier_label: string;
12
- badge: string;
13
14
  dimensions: {
14
- identity: {
15
- score: number;
16
- max: number;
17
- };
18
- economic: {
19
- score: number;
20
- max: number;
21
- };
22
- track_record: {
23
- score: number;
24
- max: number;
25
- };
26
- social: {
27
- score: number;
28
- max: number;
29
- };
30
- behavioral: {
31
- score: number;
32
- max: number;
33
- };
15
+ identity: TrustDimension;
16
+ economic: TrustDimension;
17
+ social: TrustDimension;
18
+ behavioral: TrustDimension;
34
19
  };
20
+ risk_flags: string[];
21
+ safe_to_transact: boolean;
22
+ risk_level: "low" | "medium" | "high" | "unknown";
23
+ evidence_summary: string;
35
24
  }
36
25
  export interface Agent {
37
26
  id: string;
@@ -60,9 +49,13 @@ export interface ReviewResponse {
60
49
  review_id?: string;
61
50
  error?: string;
62
51
  }
52
+ export declare class TrustRegistryOfflineError extends Error {
53
+ constructor(message?: string);
54
+ }
63
55
  export declare class TrustClient {
64
56
  private baseUrl;
65
57
  constructor(baseUrl?: string);
58
+ private safeFetch;
66
59
  /**
67
60
  * Look up an agent's trust score
68
61
  */
package/dist/index.js CHANGED
@@ -6,18 +6,38 @@
6
6
  * https://trustthenverify.com
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.badgeUrl = exports.isTrusted = exports.listAgents = exports.review = exports.register = exports.lookup = exports.trust = exports.TrustClient = void 0;
9
+ exports.badgeUrl = exports.isTrusted = exports.listAgents = exports.review = exports.register = exports.lookup = exports.trust = exports.TrustClient = exports.TrustRegistryOfflineError = void 0;
10
10
  exports.ensureRegistered = ensureRegistered;
11
11
  exports.checkBeforeTransaction = checkBeforeTransaction;
12
+ class TrustRegistryOfflineError extends Error {
13
+ constructor(message = "Trust registry is temporarily offline") {
14
+ super(message);
15
+ this.name = "TrustRegistryOfflineError";
16
+ }
17
+ }
18
+ exports.TrustRegistryOfflineError = TrustRegistryOfflineError;
12
19
  class TrustClient {
13
20
  constructor(baseUrl = "https://trustthenverify.com") {
14
21
  this.baseUrl = baseUrl.replace(/\/$/, "");
15
22
  }
23
+ async safeFetch(url, init) {
24
+ let res;
25
+ try {
26
+ res = await fetch(url, init);
27
+ }
28
+ catch (err) {
29
+ throw new TrustRegistryOfflineError(`Registry unreachable: ${err.message || "network error"}`);
30
+ }
31
+ if (res.status === 502 || res.status === 503 || res.status === 504) {
32
+ throw new TrustRegistryOfflineError(`Registry returned ${res.status}`);
33
+ }
34
+ return res;
35
+ }
16
36
  /**
17
37
  * Look up an agent's trust score
18
38
  */
19
39
  async lookup(agentId) {
20
- const res = await fetch(`${this.baseUrl}/registry/trust/${agentId}`);
40
+ const res = await this.safeFetch(`${this.baseUrl}/v1/trust/${agentId}`);
21
41
  if (!res.ok)
22
42
  return null;
23
43
  return res.json();
@@ -26,7 +46,7 @@ class TrustClient {
26
46
  * Get an agent by ID
27
47
  */
28
48
  async getAgent(agentId) {
29
- const res = await fetch(`${this.baseUrl}/registry/agent/${agentId}`);
49
+ const res = await this.safeFetch(`${this.baseUrl}/registry/agent/${agentId}`);
30
50
  if (!res.ok)
31
51
  return null;
32
52
  return res.json();
@@ -35,7 +55,7 @@ class TrustClient {
35
55
  * List all registered agents
36
56
  */
37
57
  async listAgents() {
38
- const res = await fetch(`${this.baseUrl}/registry/agents`);
58
+ const res = await this.safeFetch(`${this.baseUrl}/registry/agents`);
39
59
  if (!res.ok)
40
60
  return [];
41
61
  const data = await res.json();
@@ -45,18 +65,22 @@ class TrustClient {
45
65
  * Register a new agent
46
66
  */
47
67
  async register(name, contact, options) {
48
- const res = await fetch(`${this.baseUrl}/register`, {
68
+ const res = await this.safeFetch(`${this.baseUrl}/register`, {
49
69
  method: "POST",
50
70
  headers: { "Content-Type": "application/json" },
51
71
  body: JSON.stringify({ name, contact, ...options }),
52
72
  });
73
+ if (!res.ok) {
74
+ const body = await res.json().catch(() => ({}));
75
+ throw new Error(body.error || `Registration failed (${res.status})`);
76
+ }
53
77
  return res.json();
54
78
  }
55
79
  /**
56
80
  * Submit a review for an agent
57
81
  */
58
82
  async review(agentId, rating, comment, options) {
59
- const res = await fetch(`${this.baseUrl}/registry/review`, {
83
+ const res = await this.safeFetch(`${this.baseUrl}/registry/review`, {
60
84
  method: "POST",
61
85
  headers: { "Content-Type": "application/json" },
62
86
  body: JSON.stringify({
@@ -66,6 +90,10 @@ class TrustClient {
66
90
  ...options,
67
91
  }),
68
92
  });
93
+ if (!res.ok) {
94
+ const body = await res.json().catch(() => ({}));
95
+ throw new Error(body.error || `Review failed (${res.status})`);
96
+ }
69
97
  return res.json();
70
98
  }
71
99
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trustthenverify/sdk",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "TypeScript SDK for the Trust Then Verify agent registry",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -1,23 +1,28 @@
1
1
  /**
2
2
  * Trust Then Verify SDK
3
- *
3
+ *
4
4
  * TypeScript SDK for the AI agent trust registry.
5
5
  * https://trustthenverify.com
6
6
  */
7
7
 
8
+ export interface TrustDimension {
9
+ score: number;
10
+ max: number;
11
+ }
12
+
8
13
  export interface TrustScore {
9
14
  total: number;
10
15
  confidence: number;
11
- tier: number;
12
- tier_label: string;
13
- badge: string;
14
16
  dimensions: {
15
- identity: { score: number; max: number };
16
- economic: { score: number; max: number };
17
- track_record: { score: number; max: number };
18
- social: { score: number; max: number };
19
- behavioral: { score: number; max: number };
17
+ identity: TrustDimension;
18
+ economic: TrustDimension;
19
+ social: TrustDimension;
20
+ behavioral: TrustDimension;
20
21
  };
22
+ risk_flags: string[];
23
+ safe_to_transact: boolean;
24
+ risk_level: "low" | "medium" | "high" | "unknown";
25
+ evidence_summary: string;
21
26
  }
22
27
 
23
28
  export interface Agent {
@@ -47,6 +52,13 @@ export interface ReviewResponse {
47
52
  error?: string;
48
53
  }
49
54
 
55
+ export class TrustRegistryOfflineError extends Error {
56
+ constructor(message = "Trust registry is temporarily offline") {
57
+ super(message);
58
+ this.name = "TrustRegistryOfflineError";
59
+ }
60
+ }
61
+
50
62
  export class TrustClient {
51
63
  private baseUrl: string;
52
64
 
@@ -54,11 +66,28 @@ export class TrustClient {
54
66
  this.baseUrl = baseUrl.replace(/\/$/, "");
55
67
  }
56
68
 
69
+ private async safeFetch(url: string, init?: RequestInit): Promise<Response> {
70
+ let res: Response;
71
+ try {
72
+ res = await fetch(url, init);
73
+ } catch (err: any) {
74
+ throw new TrustRegistryOfflineError(
75
+ `Registry unreachable: ${err.message || "network error"}`
76
+ );
77
+ }
78
+ if (res.status === 502 || res.status === 503 || res.status === 504) {
79
+ throw new TrustRegistryOfflineError(
80
+ `Registry returned ${res.status}`
81
+ );
82
+ }
83
+ return res;
84
+ }
85
+
57
86
  /**
58
87
  * Look up an agent's trust score
59
88
  */
60
89
  async lookup(agentId: string): Promise<{ agent: Agent; trust_score: TrustScore } | null> {
61
- const res = await fetch(`${this.baseUrl}/registry/trust/${agentId}`);
90
+ const res = await this.safeFetch(`${this.baseUrl}/v1/trust/${agentId}`);
62
91
  if (!res.ok) return null;
63
92
  return res.json();
64
93
  }
@@ -67,7 +96,7 @@ export class TrustClient {
67
96
  * Get an agent by ID
68
97
  */
69
98
  async getAgent(agentId: string): Promise<Agent | null> {
70
- const res = await fetch(`${this.baseUrl}/registry/agent/${agentId}`);
99
+ const res = await this.safeFetch(`${this.baseUrl}/registry/agent/${agentId}`);
71
100
  if (!res.ok) return null;
72
101
  return res.json();
73
102
  }
@@ -76,7 +105,7 @@ export class TrustClient {
76
105
  * List all registered agents
77
106
  */
78
107
  async listAgents(): Promise<Agent[]> {
79
- const res = await fetch(`${this.baseUrl}/registry/agents`);
108
+ const res = await this.safeFetch(`${this.baseUrl}/registry/agents`);
80
109
  if (!res.ok) return [];
81
110
  const data = await res.json();
82
111
  return data.agents || [];
@@ -97,11 +126,15 @@ export class TrustClient {
97
126
  website?: string;
98
127
  }
99
128
  ): Promise<RegisterResponse> {
100
- const res = await fetch(`${this.baseUrl}/register`, {
129
+ const res = await this.safeFetch(`${this.baseUrl}/register`, {
101
130
  method: "POST",
102
131
  headers: { "Content-Type": "application/json" },
103
132
  body: JSON.stringify({ name, contact, ...options }),
104
133
  });
134
+ if (!res.ok) {
135
+ const body = await res.json().catch(() => ({}));
136
+ throw new Error(body.error || `Registration failed (${res.status})`);
137
+ }
105
138
  return res.json();
106
139
  }
107
140
 
@@ -118,7 +151,7 @@ export class TrustClient {
118
151
  proof_of_payment?: string;
119
152
  }
120
153
  ): Promise<ReviewResponse> {
121
- const res = await fetch(`${this.baseUrl}/registry/review`, {
154
+ const res = await this.safeFetch(`${this.baseUrl}/registry/review`, {
122
155
  method: "POST",
123
156
  headers: { "Content-Type": "application/json" },
124
157
  body: JSON.stringify({
@@ -128,6 +161,10 @@ export class TrustClient {
128
161
  ...options,
129
162
  }),
130
163
  });
164
+ if (!res.ok) {
165
+ const body = await res.json().catch(() => ({}));
166
+ throw new Error(body.error || `Review failed (${res.status})`);
167
+ }
131
168
  return res.json();
132
169
  }
133
170
 
@@ -174,10 +211,10 @@ export const badgeUrl = (agentId: string) => trust.badgeUrl(agentId);
174
211
 
175
212
  /**
176
213
  * Auto-register helper for agents
177
- *
214
+ *
178
215
  * Ensures the calling agent is registered before making lookups.
179
216
  * Returns the agent ID for future reference.
180
- *
217
+ *
181
218
  * @example
182
219
  * const myId = await ensureRegistered({
183
220
  * name: "MyAgent",
@@ -195,11 +232,11 @@ export async function ensureRegistered(options: {
195
232
  // Check if already registered by name
196
233
  const agents = await trust.listAgents();
197
234
  const existing = agents.find(a => a.name.toLowerCase() === options.name.toLowerCase());
198
-
235
+
199
236
  if (existing) {
200
237
  return existing.id;
201
238
  }
202
-
239
+
203
240
  // Register new agent
204
241
  const result = await trust.register(
205
242
  options.name,
@@ -210,15 +247,15 @@ export async function ensureRegistered(options: {
210
247
  lightning_pubkey: options.lightning_pubkey,
211
248
  }
212
249
  );
213
-
250
+
214
251
  return result.agent_id;
215
252
  }
216
253
 
217
254
  /**
218
255
  * Check trust before transaction helper
219
- *
256
+ *
220
257
  * Returns detailed recommendation for whether to proceed.
221
- *
258
+ *
222
259
  * @example
223
260
  * const check = await checkBeforeTransaction("target-agent", 1000);
224
261
  * if (check.proceed) {
@@ -237,7 +274,7 @@ export async function checkBeforeTransaction(
237
274
  riskLevel: "low" | "medium" | "high" | "unknown";
238
275
  }> {
239
276
  const result = await trust.lookup(agentId);
240
-
277
+
241
278
  if (!result) {
242
279
  return {
243
280
  proceed: false,
@@ -246,13 +283,13 @@ export async function checkBeforeTransaction(
246
283
  riskLevel: "unknown",
247
284
  };
248
285
  }
249
-
286
+
250
287
  const score = result.trust_score.total;
251
288
  const tier = TrustClient.getTier(score);
252
-
289
+
253
290
  // High amounts require higher trust
254
291
  const requiredScore = amountSats > 10000 ? 60 : amountSats > 1000 ? 40 : 20;
255
-
292
+
256
293
  if (score >= requiredScore) {
257
294
  return {
258
295
  proceed: true,
@@ -261,7 +298,7 @@ export async function checkBeforeTransaction(
261
298
  riskLevel: tier.safe ? "low" : "medium",
262
299
  };
263
300
  }
264
-
301
+
265
302
  return {
266
303
  proceed: false,
267
304
  score,