@agentidcard/sdk 1.0.0 → 1.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/index.d.ts CHANGED
@@ -71,6 +71,27 @@ export interface ReputationQueryParams {
71
71
  dimension?: string;
72
72
  }
73
73
 
74
+ export interface ClientRegistrationOptions {
75
+ name: string;
76
+ allowed_origins: string[];
77
+ redirect_uris: string[];
78
+ admin_api_key: string;
79
+ }
80
+
81
+ export interface AuthCodeExchangeOptions {
82
+ code: string;
83
+ client_id: string;
84
+ client_secret: string;
85
+ origin?: string;
86
+ }
87
+
88
+ export interface QuickVerifyOptions {
89
+ token: string;
90
+ client_id: string;
91
+ client_secret: string;
92
+ origin?: string;
93
+ }
94
+
74
95
  export declare class AilClient {
75
96
  constructor(options?: AilClientOptions);
76
97
  registerOwner(options: { email: string; org?: string }): Promise<OwnerRegistrationResponse>;
@@ -92,6 +113,15 @@ export declare class AilClient {
92
113
  private_key_jwk: Jwk;
93
114
  }): Promise<Record<string, unknown>>;
94
115
  verify(token: string): Promise<Record<string, unknown>>;
116
+ getAuthUrl(options: {
117
+ client_id: string;
118
+ redirect_uri: string;
119
+ scope?: string;
120
+ state?: string;
121
+ }): string;
122
+ registerClient(options: ClientRegistrationOptions): Promise<Record<string, unknown>>;
123
+ exchangeAuthCode(options: AuthCodeExchangeOptions): Promise<Record<string, unknown>>;
124
+ verifyQuick(options: QuickVerifyOptions): Promise<Record<string, unknown>>;
95
125
  verifyOffline(token: string): Promise<OfflineVerificationResult>;
96
126
  getPublicKeys(): Promise<Record<string, unknown>>;
97
127
  getReputation(ailId: string): Promise<Record<string, unknown>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentidcard/sdk",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "description": "Official JavaScript SDK for Agent ID Card - AI agent identity credentials",
5
5
  "type": "module",
6
6
  "main": "./index.mjs",
package/src/client.mjs CHANGED
@@ -22,10 +22,10 @@ export class AilClient {
22
22
  return query ? `${path}?${query}` : path;
23
23
  }
24
24
 
25
- async #post(path, body) {
25
+ async #post(path, body, headers = {}) {
26
26
  const res = await fetch(`${this.serverUrl}${path}`, {
27
27
  method: "POST",
28
- headers: { "Content-Type": "application/json" },
28
+ headers: { "Content-Type": "application/json", ...headers },
29
29
  body: JSON.stringify(body),
30
30
  });
31
31
  const data = await res.json();
@@ -38,10 +38,16 @@ export class AilClient {
38
38
  return data;
39
39
  }
40
40
 
41
- async #get(path) {
42
- const res = await fetch(`${this.serverUrl}${path}`);
43
- if (!res.ok) throw new Error(`HTTP ${res.status}`);
44
- return res.json();
41
+ async #get(path, headers = {}) {
42
+ const res = await fetch(`${this.serverUrl}${path}`, { headers });
43
+ const data = await res.json();
44
+ if (!res.ok) {
45
+ const err = new Error(data.message ?? data.error ?? `HTTP ${res.status}`);
46
+ err.code = data.error;
47
+ err.status = res.status;
48
+ throw err;
49
+ }
50
+ return data;
45
51
  }
46
52
 
47
53
  // -------------------------------------------------------------------------
@@ -130,6 +136,39 @@ export class AilClient {
130
136
  return this.#post("/verify", { token });
131
137
  }
132
138
 
139
+ getAuthUrl({ client_id, redirect_uri, scope = "identity", state = "" }) {
140
+ const params = new URLSearchParams({
141
+ client_id,
142
+ redirect_uri,
143
+ scope,
144
+ state,
145
+ });
146
+ return `${this.serverUrl}/auth/verify?${params}`;
147
+ }
148
+
149
+ async registerClient({ name, allowed_origins, redirect_uris, admin_api_key }) {
150
+ return this.#post("/auth/clients/register", {
151
+ name,
152
+ allowed_origins,
153
+ redirect_uris,
154
+ }, {
155
+ "X-Admin-Key": admin_api_key,
156
+ });
157
+ }
158
+
159
+ async exchangeAuthCode({ code, client_id, client_secret, origin }) {
160
+ const headers = {};
161
+ if (origin) headers.Origin = origin;
162
+ return this.#post("/auth/exchange", { code, client_id, client_secret }, headers);
163
+ }
164
+
165
+ async verifyQuick({ token, client_id, client_secret, origin }) {
166
+ const path = this.#withQuery("/auth/verify-quick", { token, client_id });
167
+ const headers = { Authorization: `Bearer ${client_secret}` };
168
+ if (origin) headers.Origin = origin;
169
+ return this.#get(path, headers);
170
+ }
171
+
133
172
  /**
134
173
  * Verify a credential offline using the server's public key.
135
174
  * Fetches the JWKS once and caches it.