@semiotic-labs/agentium-sdk 0.6.0 → 0.8.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 +234 -56
- package/dist/index.d.ts +15 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -26
- package/dist/index.js.map +1 -1
- package/dist/telemetry.d.ts +128 -0
- package/dist/telemetry.d.ts.map +1 -0
- package/dist/telemetry.js +148 -0
- package/dist/telemetry.js.map +1 -0
- package/dist/wasm.d.ts +2 -6
- package/dist/wasm.d.ts.map +1 -1
- package/dist/wasm.js +1 -12
- package/dist/wasm.js.map +1 -1
- package/package.json +1 -1
- package/packages/agentium-native/wasm/pkg/agentium_sdk_wasm.d.ts +3 -9
- package/packages/agentium-native/wasm/pkg/agentium_sdk_wasm.js +10 -78
- package/packages/agentium-native/wasm/pkg/agentium_sdk_wasm_bg.wasm +0 -0
- package/packages/agentium-native/wasm/pkg/agentium_sdk_wasm_bg.wasm.d.ts +2 -2
package/README.md
CHANGED
|
@@ -6,112 +6,290 @@ SPDX-License-Identifier: MIT
|
|
|
6
6
|
|
|
7
7
|
# @semiotic-labs/agentium-sdk
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
TypeScript SDK for interacting with the Agentium Network API. Supports identity connection, OAuth token management, and W3C Verifiable Credentials (VCs) with Ed25519 signatures.
|
|
10
10
|
|
|
11
11
|
## Installation
|
|
12
12
|
|
|
13
|
-
Install the package using npm:
|
|
14
|
-
|
|
15
13
|
```bash
|
|
16
14
|
npm install @semiotic-labs/agentium-sdk
|
|
17
15
|
```
|
|
18
16
|
|
|
19
|
-
##
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { AgentiumClient } from '@semiotic-labs/agentium-sdk';
|
|
20
21
|
|
|
21
|
-
|
|
22
|
+
const client = new AgentiumClient();
|
|
23
|
+
|
|
24
|
+
// Connect with Google identity
|
|
25
|
+
const response = await client.connectGoogleIdentity(googleJwtToken);
|
|
26
|
+
console.log('User DID:', response.did);
|
|
27
|
+
console.log('Access Token:', response.accessToken);
|
|
28
|
+
```
|
|
22
29
|
|
|
23
|
-
|
|
30
|
+
## API Reference
|
|
31
|
+
|
|
32
|
+
### Client Setup
|
|
24
33
|
|
|
25
34
|
```typescript
|
|
26
35
|
import { AgentiumClient } from '@semiotic-labs/agentium-sdk';
|
|
27
36
|
|
|
37
|
+
// Default: https://api.agentium.network
|
|
28
38
|
const client = new AgentiumClient();
|
|
29
39
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const googleToken = 'YOUR_GOOGLE_JWT'; // Replace with your actual Google JWT
|
|
33
|
-
const response = await client.connectGoogleIdentity(googleToken);
|
|
34
|
-
console.log('Connected Identity:', response);
|
|
35
|
-
} catch (error) {
|
|
36
|
-
console.error('Failed to connect identity:', error);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
40
|
+
// Custom endpoint (for local/staging)
|
|
41
|
+
const client = new AgentiumClient({ baseURL: 'http://localhost:8080' });
|
|
39
42
|
|
|
40
|
-
|
|
43
|
+
// For bundlers like Vite that require explicit WASM URL
|
|
44
|
+
import wasmUrl from '@semiotic-labs/agentium-sdk/wasm?url';
|
|
45
|
+
const client = new AgentiumClient({ wasmUrl });
|
|
41
46
|
```
|
|
42
47
|
|
|
43
|
-
###
|
|
48
|
+
### Identity Connection
|
|
44
49
|
|
|
45
|
-
|
|
50
|
+
#### `connectGoogleIdentity(googleToken, options?)`
|
|
51
|
+
|
|
52
|
+
Connects a Google identity to an Agentium identity.
|
|
46
53
|
|
|
47
54
|
```typescript
|
|
48
|
-
|
|
55
|
+
// Standard Google Sign-In
|
|
56
|
+
const response = await client.connectGoogleIdentity(googleJwtToken);
|
|
49
57
|
|
|
50
|
-
//
|
|
51
|
-
const
|
|
52
|
-
|
|
58
|
+
// External OAuth (e.g., zkLogin) - skip audience validation
|
|
59
|
+
const response = await client.connectGoogleIdentity(googleJwtToken, {
|
|
60
|
+
skipAudienceValidation: true,
|
|
53
61
|
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
**Returns:** `ConnectIdentityResponse` with `did`, `accessToken`, `refreshToken`, `expiresIn`, `isNew`, `badge`
|
|
65
|
+
|
|
66
|
+
### Token Management
|
|
67
|
+
|
|
68
|
+
#### `exchangeApiKey(apiKey)`
|
|
69
|
+
|
|
70
|
+
Exchanges an API key for JWT tokens (M2M authentication).
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
const tokens = await client.exchangeApiKey('ak_your_api_key');
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
#### `refreshToken(refreshTokenValue)`
|
|
77
|
+
|
|
78
|
+
Refreshes an access token using a refresh token.
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
const newTokens = await client.refreshToken(currentRefreshToken);
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Verifiable Credentials
|
|
85
|
+
|
|
86
|
+
The SDK supports W3C Verifiable Credentials issued as JWTs with Ed25519 signatures.
|
|
87
|
+
|
|
88
|
+
#### Storage Setup
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
import { createBrowserStorage, createMemoryStorage } from '@semiotic-labs/agentium-sdk';
|
|
92
|
+
|
|
93
|
+
// Browser environment (uses localStorage)
|
|
94
|
+
client.setVcStorage(createBrowserStorage());
|
|
95
|
+
|
|
96
|
+
// Node.js or testing (in-memory)
|
|
97
|
+
client.setVcStorage(createMemoryStorage());
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
#### `fetchMembershipCredential(token)`
|
|
101
|
+
|
|
102
|
+
Fetches a membership credential from the backend.
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
const vcJwt = await client.fetchMembershipCredential(authToken);
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
#### `verifyCredential(jwt)`
|
|
109
|
+
|
|
110
|
+
Verifies a JWT-VC against the issuer's public key.
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
const result = await client.verifyCredential(vcJwt);
|
|
114
|
+
|
|
115
|
+
if (result.valid) {
|
|
116
|
+
console.log('Subject DID:', result.claims?.sub);
|
|
117
|
+
} else {
|
|
118
|
+
console.error('Error:', result.error?.code, result.error?.message);
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
#### `connectAndStoreMembership(token)`
|
|
123
|
+
|
|
124
|
+
Full flow: fetch, verify, and store a membership credential.
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
const result = await client.connectAndStoreMembership(authToken);
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
#### `getStoredCredential()`
|
|
54
131
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
132
|
+
Retrieves the stored VC JWT from storage.
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
const storedVc = client.getStoredCredential();
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### WASM Utilities
|
|
139
|
+
|
|
140
|
+
Low-level cryptographic operations for Ed25519. WASM is automatically initialized on first use — no manual setup required.
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
import { verifyJwt, generateKeypair, getPublicKey } from '@semiotic-labs/agentium-sdk';
|
|
144
|
+
|
|
145
|
+
// Generate key pair
|
|
146
|
+
const { privateKey, publicKey } = await generateKeypair();
|
|
147
|
+
|
|
148
|
+
// Verify JWT directly
|
|
149
|
+
const result = await verifyJwt(jwtString, publicKeyJwk);
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
#### Bundler Configuration (Vite, etc.)
|
|
153
|
+
|
|
154
|
+
For bundlers like Vite that require explicit WASM URL resolution, pass `wasmUrl` to the client constructor (see [Client Setup](#client-setup)).
|
|
155
|
+
|
|
156
|
+
If using low-level WASM utilities directly (without `AgentiumClient`), initialize manually:
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
import { ensureWasmReady } from '@semiotic-labs/agentium-sdk';
|
|
160
|
+
import wasmUrl from '@semiotic-labs/agentium-sdk/wasm?url';
|
|
161
|
+
|
|
162
|
+
await ensureWasmReady(wasmUrl);
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Error Handling
|
|
166
|
+
|
|
167
|
+
All API methods throw `AgentiumApiError` on failure:
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
import { AgentiumApiError } from '@semiotic-labs/agentium-sdk';
|
|
171
|
+
|
|
172
|
+
try {
|
|
173
|
+
await client.connectGoogleIdentity(token);
|
|
174
|
+
} catch (error) {
|
|
175
|
+
if (error instanceof AgentiumApiError) {
|
|
176
|
+
console.error(`API Error (${error.statusCode}): ${error.message}`);
|
|
62
177
|
}
|
|
63
178
|
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Telemetry
|
|
182
|
+
|
|
183
|
+
The SDK provides a flexible telemetry system that forwards tracing events from the WASM layer to JavaScript. Consumers can define custom sinks to handle events (logging, analytics, monitoring services, etc.).
|
|
184
|
+
|
|
185
|
+
> **Note:** The WASM layer currently emits events only — spans are not yet supported.
|
|
64
186
|
|
|
65
|
-
|
|
187
|
+
#### Initialization
|
|
188
|
+
|
|
189
|
+
Telemetry must be initialized after WASM is ready and can only be called once. If not initialized, no telemetry is emitted (silent by default).
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
import { ensureWasmReady, initTelemetry, consoleSink } from '@semiotic-labs/agentium-sdk';
|
|
193
|
+
|
|
194
|
+
await ensureWasmReady();
|
|
195
|
+
initTelemetry({ sink: consoleSink });
|
|
66
196
|
```
|
|
67
197
|
|
|
68
|
-
|
|
198
|
+
#### Built-in Sinks
|
|
69
199
|
|
|
70
|
-
|
|
200
|
+
- **`consoleSink`** — Logs events to the browser/Node console using the appropriate method (`console.error`, `console.warn`, etc.)
|
|
201
|
+
- **`nullSink`** — Discards all events (useful for explicitly disabling telemetry)
|
|
71
202
|
|
|
72
|
-
|
|
73
|
-
2. Install dependencies:
|
|
74
|
-
```bash
|
|
75
|
-
npm install
|
|
76
|
-
```
|
|
203
|
+
#### Filtering Events
|
|
77
204
|
|
|
78
|
-
|
|
205
|
+
Filter events by level or target module:
|
|
79
206
|
|
|
80
|
-
|
|
207
|
+
```typescript
|
|
208
|
+
import { withLevelFilter, withTargetFilter, consoleSink } from '@semiotic-labs/agentium-sdk';
|
|
81
209
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
pip install reuse
|
|
85
|
-
```
|
|
210
|
+
// Only log errors and warnings
|
|
211
|
+
const errorSink = withLevelFilter(['error', 'warn'], consoleSink);
|
|
86
212
|
|
|
87
|
-
|
|
213
|
+
// Only log events from agentium modules
|
|
214
|
+
const agentiumSink = withTargetFilter(['agentium_sdk'], consoleSink);
|
|
215
|
+
```
|
|
88
216
|
|
|
89
|
-
|
|
217
|
+
#### Composing Sinks
|
|
90
218
|
|
|
91
|
-
|
|
92
|
-
|
|
219
|
+
Combine multiple sinks to forward events to different destinations:
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
import { composeSinks, withLevelFilter, consoleSink, initTelemetry } from '@semiotic-labs/agentium-sdk';
|
|
223
|
+
|
|
224
|
+
const myAnalyticsSink = (event) => {
|
|
225
|
+
// Send to your analytics service
|
|
226
|
+
analytics.track('sdk_event', event);
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
initTelemetry({
|
|
230
|
+
sink: composeSinks(
|
|
231
|
+
withLevelFilter(['error', 'warn', 'info'], consoleSink),
|
|
232
|
+
myAnalyticsSink
|
|
233
|
+
),
|
|
234
|
+
filter: 'agentium_sdk=debug' // tracing-subscriber EnvFilter syntax
|
|
235
|
+
});
|
|
93
236
|
```
|
|
94
237
|
|
|
95
|
-
|
|
238
|
+
#### Event Structure
|
|
96
239
|
|
|
97
|
-
|
|
240
|
+
Events passed to sinks have the following shape:
|
|
241
|
+
|
|
242
|
+
```typescript
|
|
243
|
+
interface TelemetryEvent {
|
|
244
|
+
kind: 'event'; // Event type (currently always "event")
|
|
245
|
+
level: 'error' | 'warn' | 'info' | 'debug' | 'trace';
|
|
246
|
+
target: string; // Module path (e.g., "agentium_sdk_wasm::vc")
|
|
247
|
+
name?: string; // Event name
|
|
248
|
+
fields: Record<string, unknown>; // Structured fields from the event
|
|
249
|
+
ts_ms: number; // Timestamp in milliseconds
|
|
250
|
+
}
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
## API Documentation
|
|
254
|
+
|
|
255
|
+
Generate full API documentation from source:
|
|
98
256
|
|
|
99
257
|
```bash
|
|
100
|
-
npm run
|
|
258
|
+
npm run docs
|
|
101
259
|
```
|
|
102
260
|
|
|
103
|
-
|
|
261
|
+
Documentation is output to the `docs/` folder.
|
|
262
|
+
|
|
263
|
+
## Development
|
|
264
|
+
|
|
265
|
+
### Setup
|
|
104
266
|
|
|
105
|
-
|
|
267
|
+
```bash
|
|
268
|
+
git clone https://github.com/semiotic-agentium/agentium-sdk.git
|
|
269
|
+
cd agentium-sdk
|
|
270
|
+
npm install
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### Scripts
|
|
106
274
|
|
|
107
275
|
```bash
|
|
108
|
-
npm test
|
|
276
|
+
npm test # Run tests
|
|
277
|
+
npm run build # Build (WASM + TypeScript)
|
|
278
|
+
npm run docs # Generate API docs
|
|
279
|
+
npm run lint # Lint code
|
|
280
|
+
npm run check # Lint + format check
|
|
109
281
|
```
|
|
110
282
|
|
|
111
|
-
###
|
|
283
|
+
### REUSE Compliance
|
|
112
284
|
|
|
113
|
-
|
|
285
|
+
This project follows the [REUSE Specification](https://reuse.software/spec/).
|
|
114
286
|
|
|
115
287
|
```bash
|
|
116
|
-
|
|
288
|
+
pip install reuse # Install REUSE tool
|
|
289
|
+
npm run reuse:check # Verify compliance
|
|
290
|
+
npm run reuse:write # Apply SPDX headers
|
|
117
291
|
```
|
|
292
|
+
|
|
293
|
+
## License
|
|
294
|
+
|
|
295
|
+
MIT
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { type WasmInitInput } from './wasm.js';
|
|
1
2
|
import type { VcStorage, VerificationResult, DidDocument, JwtHeader } from './vc/index.js';
|
|
2
3
|
export * from './vc/index.js';
|
|
3
|
-
export { ensureWasmReady,
|
|
4
|
+
export { ensureWasmReady, verifyJwt, generateKeypair, getPublicKey, type WasmInitInput, } from './wasm.js';
|
|
5
|
+
export { initTelemetry, consoleSink, nullSink, withLevelFilter, withTargetFilter, composeSinks, type TelemetryEvent, type TelemetryLevel, type TelemetrySink, type InitTelemetryOptions, } from './telemetry.js';
|
|
4
6
|
/**
|
|
5
7
|
* Options for configuring the AgentiumClient.
|
|
6
8
|
*/
|
|
@@ -10,6 +12,15 @@ export interface AgentiumClientOptions {
|
|
|
10
12
|
* @default https://api.agentium.network
|
|
11
13
|
*/
|
|
12
14
|
baseURL?: string;
|
|
15
|
+
/**
|
|
16
|
+
* URL to the WASM binary. Required for bundlers like Vite that need explicit URL resolution.
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import wasmUrl from '@semiotic-labs/agentium-sdk/wasm?url';
|
|
20
|
+
* const client = new AgentiumClient({ wasmUrl });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
wasmUrl?: WasmInitInput;
|
|
13
24
|
}
|
|
14
25
|
/**
|
|
15
26
|
* Supported OAuth grant types for token exchange.
|
|
@@ -103,6 +114,7 @@ export declare class AgentiumClient {
|
|
|
103
114
|
private readonly axiosInstance;
|
|
104
115
|
private readonly DEFAULT_BASE_URL;
|
|
105
116
|
private readonly OAUTH_TOKEN_PATH;
|
|
117
|
+
private readonly wasmReady;
|
|
106
118
|
private vcStorage;
|
|
107
119
|
/**
|
|
108
120
|
* Creates an instance of the AgentiumClient.
|
|
@@ -134,13 +146,6 @@ export declare class AgentiumClient {
|
|
|
134
146
|
* @throws {AgentiumApiError} Will throw a custom API error if the call fails.
|
|
135
147
|
*/
|
|
136
148
|
refreshToken(refreshTokenValue: string): Promise<OAuthTokenResponse>;
|
|
137
|
-
/**
|
|
138
|
-
* Exchanges a Privy ID token for JWT tokens.
|
|
139
|
-
* @param idToken - The Privy ID token to exchange.
|
|
140
|
-
* @returns A promise that resolves with the OAuth token response.
|
|
141
|
-
* @throws {AgentiumApiError} Will throw a custom API error if the call fails.
|
|
142
|
-
*/
|
|
143
|
-
exchangePrivyToken(idToken: string): Promise<OAuthTokenResponse>;
|
|
144
149
|
/**
|
|
145
150
|
* Configures VC storage for persisting membership credentials.
|
|
146
151
|
* Call this with `createBrowserStorage()` in browser environments.
|
|
@@ -205,9 +210,9 @@ export declare class AgentiumClient {
|
|
|
205
210
|
*
|
|
206
211
|
* Per spec: errors are logged but user sees no change (silent failure).
|
|
207
212
|
*
|
|
208
|
-
* @param
|
|
213
|
+
* @param token - Server auth token for authorization
|
|
209
214
|
* @returns Verification result (always returns, never throws)
|
|
210
215
|
*/
|
|
211
|
-
connectAndStoreMembership(
|
|
216
|
+
connectAndStoreMembership(token: string): Promise<VerificationResult>;
|
|
212
217
|
}
|
|
213
218
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAA8B,KAAK,aAAa,EAAE,MAAM,WAAW,CAAC;AAC3E,OAAO,KAAK,EAAE,SAAS,EAAE,kBAAkB,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAG3F,cAAc,eAAe,CAAC;AAC9B,OAAO,EACL,eAAe,EACf,SAAS,EACT,eAAe,EACf,YAAY,EACZ,KAAK,aAAa,GACnB,MAAM,WAAW,CAAC;AAGnB,OAAO,EACL,aAAa,EACb,WAAW,EACX,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AAC,kBAAkB,CAAC;CA2B5E"}
|
package/dist/index.js
CHANGED
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
//
|
|
3
3
|
// SPDX-License-Identifier: MIT
|
|
4
4
|
import axios, { isAxiosError } from 'axios';
|
|
5
|
-
import { verifyJwt } from './wasm.js';
|
|
5
|
+
import { ensureWasmReady, verifyJwt } from './wasm.js';
|
|
6
6
|
// Re-export VC module types and utilities
|
|
7
7
|
export * from './vc/index.js';
|
|
8
|
-
export { ensureWasmReady,
|
|
8
|
+
export { ensureWasmReady, verifyJwt, generateKeypair, getPublicKey, } from './wasm.js';
|
|
9
|
+
// Re-export telemetry module
|
|
10
|
+
export { initTelemetry, consoleSink, nullSink, withLevelFilter, withTargetFilter, composeSinks, } from './telemetry.js';
|
|
9
11
|
/**
|
|
10
12
|
* Custom error class for API-related errors from the AgentiumClient.
|
|
11
13
|
*/
|
|
@@ -34,6 +36,7 @@ export class AgentiumClient {
|
|
|
34
36
|
axiosInstance;
|
|
35
37
|
DEFAULT_BASE_URL = 'https://api.agentium.network';
|
|
36
38
|
OAUTH_TOKEN_PATH = '/oauth/token';
|
|
39
|
+
wasmReady;
|
|
37
40
|
vcStorage = null;
|
|
38
41
|
/**
|
|
39
42
|
* Creates an instance of the AgentiumClient.
|
|
@@ -44,6 +47,7 @@ export class AgentiumClient {
|
|
|
44
47
|
this.axiosInstance = axios.create({
|
|
45
48
|
baseURL: baseURL,
|
|
46
49
|
});
|
|
50
|
+
this.wasmReady = ensureWasmReady(options.wasmUrl);
|
|
47
51
|
}
|
|
48
52
|
/**
|
|
49
53
|
* Connects a Google identity to an Agentium identity.
|
|
@@ -123,27 +127,6 @@ export class AgentiumClient {
|
|
|
123
127
|
throw error;
|
|
124
128
|
}
|
|
125
129
|
}
|
|
126
|
-
/**
|
|
127
|
-
* Exchanges a Privy ID token for JWT tokens.
|
|
128
|
-
* @param idToken - The Privy ID token to exchange.
|
|
129
|
-
* @returns A promise that resolves with the OAuth token response.
|
|
130
|
-
* @throws {AgentiumApiError} Will throw a custom API error if the call fails.
|
|
131
|
-
*/
|
|
132
|
-
async exchangePrivyToken(idToken) {
|
|
133
|
-
try {
|
|
134
|
-
const response = await this.axiosInstance.post(this.OAUTH_TOKEN_PATH, {
|
|
135
|
-
grant_type: 'privy_id_token',
|
|
136
|
-
id_token: idToken,
|
|
137
|
-
});
|
|
138
|
-
return response.data;
|
|
139
|
-
}
|
|
140
|
-
catch (error) {
|
|
141
|
-
if (isAxiosError(error)) {
|
|
142
|
-
throw new AgentiumApiError(error.message, error.response?.status);
|
|
143
|
-
}
|
|
144
|
-
throw error;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
130
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
148
131
|
// Verifiable Credentials (VC) Methods
|
|
149
132
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
@@ -278,6 +261,7 @@ export class AgentiumClient {
|
|
|
278
261
|
* @returns Verification result with validity status, decoded claims, and structured error if invalid
|
|
279
262
|
*/
|
|
280
263
|
async verifyCredential(jwt) {
|
|
264
|
+
await this.wasmReady;
|
|
281
265
|
// Extract kid from JWT header to find the correct key
|
|
282
266
|
const header = this.parseJwtHeader(jwt);
|
|
283
267
|
const didDocument = await this.fetchIssuerDidDocument();
|
|
@@ -290,12 +274,12 @@ export class AgentiumClient {
|
|
|
290
274
|
*
|
|
291
275
|
* Per spec: errors are logged but user sees no change (silent failure).
|
|
292
276
|
*
|
|
293
|
-
* @param
|
|
277
|
+
* @param token - Server auth token for authorization
|
|
294
278
|
* @returns Verification result (always returns, never throws)
|
|
295
279
|
*/
|
|
296
|
-
async connectAndStoreMembership(
|
|
280
|
+
async connectAndStoreMembership(token) {
|
|
297
281
|
try {
|
|
298
|
-
const jwt = await this.fetchMembershipCredential(
|
|
282
|
+
const jwt = await this.fetchMembershipCredential(token);
|
|
299
283
|
const result = await this.verifyCredential(jwt);
|
|
300
284
|
if (result.valid && this.vcStorage) {
|
|
301
285
|
this.vcStorage.set(jwt);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,iDAAiD;AACjD,EAAE;AACF,+BAA+B;AAE/B,OAAO,KAAK,EAAE,EAAE,YAAY,EAAsB,MAAM,OAAO,CAAC;AAChE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,iDAAiD;AACjD,EAAE;AACF,+BAA+B;AAE/B,OAAO,KAAK,EAAE,EAAE,YAAY,EAAsB,MAAM,OAAO,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,SAAS,EAAsB,MAAM,WAAW,CAAC;AAG3E,0CAA0C;AAC1C,cAAc,eAAe,CAAC;AAC9B,OAAO,EACL,eAAe,EACf,SAAS,EACT,eAAe,EACf,YAAY,GAEb,MAAM,WAAW,CAAC;AAEnB,6BAA6B;AAC7B,OAAO,EACL,aAAa,EACb,WAAW,EACX,QAAQ,EACR,eAAe,EACf,gBAAgB,EAChB,YAAY,GAKb,MAAM,gBAAgB,CAAC;AA+GxB;;GAEG;AACH,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACzB,UAAU,CAAqB;IAE/C,YAAY,OAAe,EAAE,UAAmB;QAC9C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;QAC/B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF;AAED;;;GAGG;AACH,SAAS,qBAAqB,CAAC,KAAa;IAC1C,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACjC,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,IAAI,EAAE,CAAC;IACpE,MAAM,KAAK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error' | 'warn' | 'info' | 'debug' | 'trace';
|
|
5
|
+
/**
|
|
6
|
+
* Telemetry event structure as serialized from Rust.
|
|
7
|
+
* This is the shape of events passed to sink callbacks.
|
|
8
|
+
*/
|
|
9
|
+
export interface TelemetryEvent {
|
|
10
|
+
/** Event kind (currently always "event") */
|
|
11
|
+
kind: 'event';
|
|
12
|
+
/** Log level */
|
|
13
|
+
level: TelemetryLevel;
|
|
14
|
+
/** Module/crate target (e.g., "agentium_sdk_wasm::vc") */
|
|
15
|
+
target: string;
|
|
16
|
+
/** Event name (from tracing span/event) */
|
|
17
|
+
name?: string;
|
|
18
|
+
/** Structured fields from the tracing event */
|
|
19
|
+
fields: Record<string, unknown>;
|
|
20
|
+
/** Timestamp in milliseconds (from JS Date.now()) */
|
|
21
|
+
ts_ms: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A sink receives telemetry events and handles them (log, send to service, etc.).
|
|
25
|
+
*/
|
|
26
|
+
export type TelemetrySink = (event: TelemetryEvent) => void;
|
|
27
|
+
/**
|
|
28
|
+
* Console sink that logs events to the browser/Node console.
|
|
29
|
+
* Uses appropriate console method based on level (console.error, console.warn, etc.).
|
|
30
|
+
*/
|
|
31
|
+
export declare const consoleSink: TelemetrySink;
|
|
32
|
+
/**
|
|
33
|
+
* No-op sink that discards all events.
|
|
34
|
+
* Useful for explicitly disabling telemetry output.
|
|
35
|
+
*/
|
|
36
|
+
export declare const nullSink: TelemetrySink;
|
|
37
|
+
/**
|
|
38
|
+
* Wraps a sink with a level filter.
|
|
39
|
+
* Only events matching one of the specified levels are forwarded.
|
|
40
|
+
*
|
|
41
|
+
* @param levels - Array of levels to allow through
|
|
42
|
+
* @param sink - The sink to forward matching events to
|
|
43
|
+
* @returns Filtered sink
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* // Only log errors and warnings to console
|
|
48
|
+
* const errorSink = withLevelFilter(['error', 'warn'], consoleSink);
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare function withLevelFilter(levels: TelemetryLevel[], sink: TelemetrySink): TelemetrySink;
|
|
52
|
+
/**
|
|
53
|
+
* Wraps a sink with a target filter.
|
|
54
|
+
* Only events whose target starts with one of the specified prefixes are forwarded.
|
|
55
|
+
*
|
|
56
|
+
* @param prefixes - Array of target prefixes to allow
|
|
57
|
+
* @param sink - The sink to forward matching events to
|
|
58
|
+
* @returns Filtered sink
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* // Only log events from agentium modules
|
|
63
|
+
* const agentiumSink = withTargetFilter(['agentium_sdk'], consoleSink);
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export declare function withTargetFilter(prefixes: string[], sink: TelemetrySink): TelemetrySink;
|
|
67
|
+
/**
|
|
68
|
+
* Composes multiple sinks into a single sink.
|
|
69
|
+
* Each event is forwarded to all sinks in order.
|
|
70
|
+
*
|
|
71
|
+
* @param sinks - Array of sinks to compose
|
|
72
|
+
* @returns Combined sink
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* const sink = composeSinks(
|
|
77
|
+
* withLevelFilter(['error', 'warn', 'info'], consoleSink),
|
|
78
|
+
* myPrometheusSink,
|
|
79
|
+
* myAnalyticsSink
|
|
80
|
+
* );
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export declare function composeSinks(...sinks: TelemetrySink[]): TelemetrySink;
|
|
84
|
+
/**
|
|
85
|
+
* Options for initializing telemetry.
|
|
86
|
+
*/
|
|
87
|
+
export interface InitTelemetryOptions {
|
|
88
|
+
/**
|
|
89
|
+
* The sink to receive telemetry events.
|
|
90
|
+
* Use composeSinks() to combine multiple sinks.
|
|
91
|
+
*/
|
|
92
|
+
sink: TelemetrySink;
|
|
93
|
+
/**
|
|
94
|
+
* Tracing filter directive (e.g., "info", "debug", "agentium_sdk=trace").
|
|
95
|
+
* Uses tracing-subscriber's EnvFilter syntax.
|
|
96
|
+
* @default "info"
|
|
97
|
+
*/
|
|
98
|
+
filter?: string;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Initializes WASM telemetry with the provided sink.
|
|
102
|
+
*
|
|
103
|
+
* This must be called after ensureWasmReady() and can only be called once.
|
|
104
|
+
* If not called, no telemetry is emitted (silent by default).
|
|
105
|
+
*
|
|
106
|
+
* @param options - Telemetry configuration
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```ts
|
|
110
|
+
* import { ensureWasmReady, initTelemetry, consoleSink, withLevelFilter, composeSinks } from 'agentium-sdk';
|
|
111
|
+
*
|
|
112
|
+
* await ensureWasmReady();
|
|
113
|
+
*
|
|
114
|
+
* // Simple: log everything to console
|
|
115
|
+
* initTelemetry({ sink: consoleSink });
|
|
116
|
+
*
|
|
117
|
+
* // Advanced: filter and compose
|
|
118
|
+
* initTelemetry({
|
|
119
|
+
* sink: composeSinks(
|
|
120
|
+
* withLevelFilter(['error', 'warn', 'info'], consoleSink),
|
|
121
|
+
* myCustomSink
|
|
122
|
+
* ),
|
|
123
|
+
* filter: 'agentium_sdk=debug'
|
|
124
|
+
* });
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
export declare function initTelemetry(options: InitTelemetryOptions): Promise<void>;
|
|
128
|
+
//# sourceMappingURL=telemetry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetry.d.ts","sourceRoot":"","sources":["../src/telemetry.ts"],"names":[],"mappings":"AAWA;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;AAE3E;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,4CAA4C;IAC5C,IAAI,EAAE,OAAO,CAAC;IACd,gBAAgB;IAChB,KAAK,EAAE,cAAc,CAAC;IACtB,0DAA0D;IAC1D,MAAM,EAAE,MAAM,CAAC;IACf,2CAA2C;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,+CAA+C;IAC/C,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,qDAAqD;IACrD,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAC;AAM5D;;;GAGG;AACH,eAAO,MAAM,WAAW,EAAE,aAgBzB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,QAAQ,EAAE,aAEtB,CAAC;AAMF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,cAAc,EAAE,EAAE,IAAI,EAAE,aAAa,GAAG,aAAa,CAO5F;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,aAAa,GAAG,aAAa,CAMvF;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAAC,GAAG,KAAK,EAAE,aAAa,EAAE,GAAG,aAAa,CAMrE;AAQD;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,IAAI,EAAE,aAAa,CAAC;IAEpB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBhF"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: 2025 Semiotic AI, Inc.
|
|
2
|
+
//
|
|
3
|
+
// SPDX-License-Identifier: MIT
|
|
4
|
+
import { init_tracing as wasmInitTracing } from '../packages/agentium-native/wasm/pkg/agentium_sdk_wasm.js';
|
|
5
|
+
import { ensureWasmReady } from './wasm.js';
|
|
6
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
7
|
+
// Built-in Sinks
|
|
8
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
9
|
+
/**
|
|
10
|
+
* Console sink that logs events to the browser/Node console.
|
|
11
|
+
* Uses appropriate console method based on level (console.error, console.warn, etc.).
|
|
12
|
+
*/
|
|
13
|
+
export const consoleSink = (event) => {
|
|
14
|
+
const method = event.level === 'trace' ? 'debug' : event.level;
|
|
15
|
+
const consoleFn = console[method] ?? console.log;
|
|
16
|
+
const prefix = `[${event.target}]`;
|
|
17
|
+
// Format message from fields if present
|
|
18
|
+
const message = event.fields['message'] ?? event.name ?? '';
|
|
19
|
+
const otherFields = Object.fromEntries(Object.entries(event.fields).filter(([k]) => k !== 'message'));
|
|
20
|
+
if (Object.keys(otherFields).length > 0) {
|
|
21
|
+
consoleFn(prefix, message, otherFields);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
consoleFn(prefix, message);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* No-op sink that discards all events.
|
|
29
|
+
* Useful for explicitly disabling telemetry output.
|
|
30
|
+
*/
|
|
31
|
+
export const nullSink = () => {
|
|
32
|
+
// Intentionally empty
|
|
33
|
+
};
|
|
34
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
35
|
+
// Composable Utilities
|
|
36
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
37
|
+
/**
|
|
38
|
+
* Wraps a sink with a level filter.
|
|
39
|
+
* Only events matching one of the specified levels are forwarded.
|
|
40
|
+
*
|
|
41
|
+
* @param levels - Array of levels to allow through
|
|
42
|
+
* @param sink - The sink to forward matching events to
|
|
43
|
+
* @returns Filtered sink
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* // Only log errors and warnings to console
|
|
48
|
+
* const errorSink = withLevelFilter(['error', 'warn'], consoleSink);
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export function withLevelFilter(levels, sink) {
|
|
52
|
+
const levelSet = new Set(levels);
|
|
53
|
+
return (event) => {
|
|
54
|
+
if (levelSet.has(event.level)) {
|
|
55
|
+
sink(event);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Wraps a sink with a target filter.
|
|
61
|
+
* Only events whose target starts with one of the specified prefixes are forwarded.
|
|
62
|
+
*
|
|
63
|
+
* @param prefixes - Array of target prefixes to allow
|
|
64
|
+
* @param sink - The sink to forward matching events to
|
|
65
|
+
* @returns Filtered sink
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* // Only log events from agentium modules
|
|
70
|
+
* const agentiumSink = withTargetFilter(['agentium_sdk'], consoleSink);
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export function withTargetFilter(prefixes, sink) {
|
|
74
|
+
return (event) => {
|
|
75
|
+
if (prefixes.some((prefix) => event.target.startsWith(prefix))) {
|
|
76
|
+
sink(event);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Composes multiple sinks into a single sink.
|
|
82
|
+
* Each event is forwarded to all sinks in order.
|
|
83
|
+
*
|
|
84
|
+
* @param sinks - Array of sinks to compose
|
|
85
|
+
* @returns Combined sink
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* const sink = composeSinks(
|
|
90
|
+
* withLevelFilter(['error', 'warn', 'info'], consoleSink),
|
|
91
|
+
* myPrometheusSink,
|
|
92
|
+
* myAnalyticsSink
|
|
93
|
+
* );
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export function composeSinks(...sinks) {
|
|
97
|
+
return (event) => {
|
|
98
|
+
for (const sink of sinks) {
|
|
99
|
+
sink(event);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
104
|
+
// Initialization
|
|
105
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
106
|
+
let telemetryInitialized = false;
|
|
107
|
+
/**
|
|
108
|
+
* Initializes WASM telemetry with the provided sink.
|
|
109
|
+
*
|
|
110
|
+
* This must be called after ensureWasmReady() and can only be called once.
|
|
111
|
+
* If not called, no telemetry is emitted (silent by default).
|
|
112
|
+
*
|
|
113
|
+
* @param options - Telemetry configuration
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* import { ensureWasmReady, initTelemetry, consoleSink, withLevelFilter, composeSinks } from 'agentium-sdk';
|
|
118
|
+
*
|
|
119
|
+
* await ensureWasmReady();
|
|
120
|
+
*
|
|
121
|
+
* // Simple: log everything to console
|
|
122
|
+
* initTelemetry({ sink: consoleSink });
|
|
123
|
+
*
|
|
124
|
+
* // Advanced: filter and compose
|
|
125
|
+
* initTelemetry({
|
|
126
|
+
* sink: composeSinks(
|
|
127
|
+
* withLevelFilter(['error', 'warn', 'info'], consoleSink),
|
|
128
|
+
* myCustomSink
|
|
129
|
+
* ),
|
|
130
|
+
* filter: 'agentium_sdk=debug'
|
|
131
|
+
* });
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
export async function initTelemetry(options) {
|
|
135
|
+
if (telemetryInitialized) {
|
|
136
|
+
console.warn('[Agentium] Telemetry already initialized, ignoring subsequent call');
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
await ensureWasmReady();
|
|
140
|
+
// Wrap the sink to handle the raw JsValue from WASM
|
|
141
|
+
const wrappedSink = (rawEvent) => {
|
|
142
|
+
// The event comes as a plain object from serde_wasm_bindgen
|
|
143
|
+
options.sink(rawEvent);
|
|
144
|
+
};
|
|
145
|
+
wasmInitTracing(wrappedSink, options.filter ?? null);
|
|
146
|
+
telemetryInitialized = true;
|
|
147
|
+
}
|
|
148
|
+
//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I,CAAC,oEAAoE,CAAC,CAAC;QACnF,OAAO;IACT,CAAC;IAED,MAAM,eAAe,EAAE,CAAC;IAExB,oDAAoD;IACpD,MAAM,WAAW,GAAG,CAAC,QAAiB,EAAE,EAAE;QACxC,4DAA4D;QAC5D,OAAO,CAAC,IAAI,CAAC,QAA0B,CAAC,CAAC;IAC3C,CAAC,CAAC;IAEF,eAAe,CAAC,WAAW,EAAE,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,CAAC;IACrD,oBAAoB,GAAG,IAAI,CAAC;AAC9B,CAAC"}
|
package/dist/wasm.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { InitInput } from '../packages/agentium-native/wasm/pkg/agentium_sdk_wasm.js';
|
|
2
2
|
import type { VerificationResult, KeyPair } from './vc/types.js';
|
|
3
|
+
export type { InitInput as WasmInitInput };
|
|
3
4
|
/**
|
|
4
5
|
* Ensures the WASM module is loaded and ready.
|
|
5
6
|
* Uses lazy initialization - only loads on first call.
|
|
@@ -14,11 +15,6 @@ import type { VerificationResult, KeyPair } from './vc/types.js';
|
|
|
14
15
|
* @returns Promise that resolves when WASM is ready
|
|
15
16
|
*/
|
|
16
17
|
export declare function ensureWasmReady(wasmUrl?: InitInput): Promise<void>;
|
|
17
|
-
/**
|
|
18
|
-
* Initialize WASM logging to browser console.
|
|
19
|
-
* Call once after ensureWasmReady() to enable debug output.
|
|
20
|
-
*/
|
|
21
|
-
export declare function initLogging(): void;
|
|
22
18
|
/**
|
|
23
19
|
* Verify a JWT-VC against a public key.
|
|
24
20
|
*
|
package/dist/wasm.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wasm.d.ts","sourceRoot":"","sources":["../src/wasm.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wasm.d.ts","sourceRoot":"","sources":["../src/wasm.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2DAA2D,CAAC;AAC3F,OAAO,KAAK,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAEjE,YAAY,EAAE,SAAS,IAAI,aAAa,EAAE,CAAC;AAI3C;;;;;;;;;;;;GAYG;AACH,wBAAsB,eAAe,CAAC,OAAO,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAOxE;AAED;;;;;;;;;GASG;AACH,wBAAsB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAG9F;AAED;;;;;GAKG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC,OAAO,CAAC,CAGxD;AAED;;;;;;GAMG;AACH,wBAAsB,YAAY,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAGzE"}
|
package/dist/wasm.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2025 Semiotic AI, Inc.
|
|
2
2
|
//
|
|
3
3
|
// SPDX-License-Identifier: MIT
|
|
4
|
-
import init, { verify_jwt as wasmVerifyJwt, generate_keypair as wasmGenerateKeypair, get_public_key as wasmGetPublicKey,
|
|
4
|
+
import init, { verify_jwt as wasmVerifyJwt, generate_keypair as wasmGenerateKeypair, get_public_key as wasmGetPublicKey, } from '../packages/agentium-native/wasm/pkg/agentium_sdk_wasm.js';
|
|
5
5
|
let wasmInitialized = null;
|
|
6
|
-
let loggingInitialized = false;
|
|
7
6
|
/**
|
|
8
7
|
* Ensures the WASM module is loaded and ready.
|
|
9
8
|
* Uses lazy initialization - only loads on first call.
|
|
@@ -25,16 +24,6 @@ export async function ensureWasmReady(wasmUrl) {
|
|
|
25
24
|
}
|
|
26
25
|
await wasmInitialized;
|
|
27
26
|
}
|
|
28
|
-
/**
|
|
29
|
-
* Initialize WASM logging to browser console.
|
|
30
|
-
* Call once after ensureWasmReady() to enable debug output.
|
|
31
|
-
*/
|
|
32
|
-
export function initLogging() {
|
|
33
|
-
if (!loggingInitialized) {
|
|
34
|
-
wasmInitLogging();
|
|
35
|
-
loggingInitialized = true;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
27
|
/**
|
|
39
28
|
* Verify a JWT-VC against a public key.
|
|
40
29
|
*
|
package/dist/wasm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wasm.js","sourceRoot":"","sources":["../src/wasm.ts"],"names":[],"mappings":"AAAA,iDAAiD;AACjD,EAAE;AACF,+BAA+B;AAE/B,OAAO,IAAI,EAAE,EACX,UAAU,IAAI,aAAa,EAC3B,gBAAgB,IAAI,mBAAmB,EACvC,cAAc,IAAI,gBAAgB,
|
|
1
|
+
{"version":3,"file":"wasm.js","sourceRoot":"","sources":["../src/wasm.ts"],"names":[],"mappings":"AAAA,iDAAiD;AACjD,EAAE;AACF,+BAA+B;AAE/B,OAAO,IAAI,EAAE,EACX,UAAU,IAAI,aAAa,EAC3B,gBAAgB,IAAI,mBAAmB,EACvC,cAAc,IAAI,gBAAgB,GACnC,MAAM,2DAA2D,CAAC;AAMnE,IAAI,eAAe,GAAyB,IAAI,CAAC;AAEjD;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,OAAmB;IACvD,IAAI,eAAe,KAAK,IAAI,EAAE,CAAC;QAC7B,eAAe,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;YACxC,6BAA6B;QAC/B,CAAC,CAAC,CAAC;IACL,CAAC;IACD,MAAM,eAAe,CAAC;AACxB,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,GAAW,EAAE,YAAoB;IAC/D,MAAM,eAAe,EAAE,CAAC;IACxB,OAAO,aAAa,CAAC,GAAG,EAAE,YAAY,CAAuB,CAAC;AAChE,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe;IACnC,MAAM,eAAe,EAAE,CAAC;IACxB,OAAO,mBAAmB,EAAa,CAAC;AAC1C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,aAAqB;IACtD,MAAM,eAAe,EAAE,CAAC;IACxB,OAAO,gBAAgB,CAAC,aAAa,CAAC,CAAC;AACzC,CAAC"}
|
package/package.json
CHANGED
|
@@ -20,13 +20,7 @@ export function generate_keypair(): any;
|
|
|
20
20
|
*/
|
|
21
21
|
export function get_public_key(private_key_jwk: string): string;
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
* Initialize logging for the WASM module.
|
|
25
|
-
*
|
|
26
|
-
* This sets up `tracing` to output to the browser console via `tracing-wasm`.
|
|
27
|
-
* Call this once before using any other functions from this library.
|
|
28
|
-
*/
|
|
29
|
-
export function init_logging(): void;
|
|
23
|
+
export function init_tracing(sink: Function, filter?: string | null): void;
|
|
30
24
|
|
|
31
25
|
/**
|
|
32
26
|
* Verify a JWT against a public key
|
|
@@ -47,15 +41,15 @@ export interface InitOutput {
|
|
|
47
41
|
readonly memory: WebAssembly.Memory;
|
|
48
42
|
readonly generate_keypair: () => [number, number, number];
|
|
49
43
|
readonly get_public_key: (a: number, b: number) => [number, number, number, number];
|
|
50
|
-
readonly init_logging: () => void;
|
|
51
44
|
readonly verify_jwt: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
45
|
+
readonly init_tracing: (a: any, b: number, c: number) => void;
|
|
52
46
|
readonly __wbindgen_exn_store: (a: number) => void;
|
|
53
47
|
readonly __externref_table_alloc: () => number;
|
|
54
48
|
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
55
|
-
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
56
49
|
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
57
50
|
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
58
51
|
readonly __externref_table_dealloc: (a: number) => void;
|
|
52
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
59
53
|
readonly __wbindgen_start: () => void;
|
|
60
54
|
}
|
|
61
55
|
|
|
@@ -11,14 +11,6 @@ function getArrayU8FromWasm0(ptr, len) {
|
|
|
11
11
|
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
let cachedDataViewMemory0 = null;
|
|
15
|
-
function getDataViewMemory0() {
|
|
16
|
-
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
17
|
-
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
18
|
-
}
|
|
19
|
-
return cachedDataViewMemory0;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
14
|
function getStringFromWasm0(ptr, len) {
|
|
23
15
|
ptr = ptr >>> 0;
|
|
24
16
|
return decodeText(ptr, len);
|
|
@@ -165,13 +157,13 @@ export function get_public_key(private_key_jwk) {
|
|
|
165
157
|
}
|
|
166
158
|
|
|
167
159
|
/**
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
* This sets up `tracing` to output to the browser console via `tracing-wasm`.
|
|
171
|
-
* Call this once before using any other functions from this library.
|
|
160
|
+
* @param {Function} sink
|
|
161
|
+
* @param {string | null} [filter]
|
|
172
162
|
*/
|
|
173
|
-
export function
|
|
174
|
-
wasm.
|
|
163
|
+
export function init_tracing(sink, filter) {
|
|
164
|
+
var ptr0 = isLikeNone(filter) ? 0 : passStringToWasm0(filter, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
165
|
+
var len0 = WASM_VECTOR_LEN;
|
|
166
|
+
wasm.init_tracing(sink, ptr0, len0);
|
|
175
167
|
}
|
|
176
168
|
|
|
177
169
|
/**
|
|
@@ -271,17 +263,6 @@ function __wbg_get_imports() {
|
|
|
271
263
|
const ret = arg0.crypto;
|
|
272
264
|
return ret;
|
|
273
265
|
};
|
|
274
|
-
imports.wbg.__wbg_error_7534b8e9a36f1ab4 = function(arg0, arg1) {
|
|
275
|
-
let deferred0_0;
|
|
276
|
-
let deferred0_1;
|
|
277
|
-
try {
|
|
278
|
-
deferred0_0 = arg0;
|
|
279
|
-
deferred0_1 = arg1;
|
|
280
|
-
console.error(getStringFromWasm0(arg0, arg1));
|
|
281
|
-
} finally {
|
|
282
|
-
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
283
|
-
}
|
|
284
|
-
};
|
|
285
266
|
imports.wbg.__wbg_getRandomValues_b8f5dbd5f3995a9e = function() { return handleError(function (arg0, arg1) {
|
|
286
267
|
arg0.getRandomValues(arg1);
|
|
287
268
|
}, arguments) };
|
|
@@ -293,47 +274,6 @@ function __wbg_get_imports() {
|
|
|
293
274
|
const ret = arg0.length;
|
|
294
275
|
return ret;
|
|
295
276
|
};
|
|
296
|
-
imports.wbg.__wbg_log_0cc1b7768397bcfe = function(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) {
|
|
297
|
-
let deferred0_0;
|
|
298
|
-
let deferred0_1;
|
|
299
|
-
try {
|
|
300
|
-
deferred0_0 = arg0;
|
|
301
|
-
deferred0_1 = arg1;
|
|
302
|
-
console.log(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3), getStringFromWasm0(arg4, arg5), getStringFromWasm0(arg6, arg7));
|
|
303
|
-
} finally {
|
|
304
|
-
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
305
|
-
}
|
|
306
|
-
};
|
|
307
|
-
imports.wbg.__wbg_log_cb9e190acc5753fb = function(arg0, arg1) {
|
|
308
|
-
let deferred0_0;
|
|
309
|
-
let deferred0_1;
|
|
310
|
-
try {
|
|
311
|
-
deferred0_0 = arg0;
|
|
312
|
-
deferred0_1 = arg1;
|
|
313
|
-
console.log(getStringFromWasm0(arg0, arg1));
|
|
314
|
-
} finally {
|
|
315
|
-
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
316
|
-
}
|
|
317
|
-
};
|
|
318
|
-
imports.wbg.__wbg_mark_7438147ce31e9d4b = function(arg0, arg1) {
|
|
319
|
-
performance.mark(getStringFromWasm0(arg0, arg1));
|
|
320
|
-
};
|
|
321
|
-
imports.wbg.__wbg_measure_fb7825c11612c823 = function() { return handleError(function (arg0, arg1, arg2, arg3) {
|
|
322
|
-
let deferred0_0;
|
|
323
|
-
let deferred0_1;
|
|
324
|
-
let deferred1_0;
|
|
325
|
-
let deferred1_1;
|
|
326
|
-
try {
|
|
327
|
-
deferred0_0 = arg0;
|
|
328
|
-
deferred0_1 = arg1;
|
|
329
|
-
deferred1_0 = arg2;
|
|
330
|
-
deferred1_1 = arg3;
|
|
331
|
-
performance.measure(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3));
|
|
332
|
-
} finally {
|
|
333
|
-
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
334
|
-
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
335
|
-
}
|
|
336
|
-
}, arguments) };
|
|
337
277
|
imports.wbg.__wbg_msCrypto_a61aeb35a24c1329 = function(arg0) {
|
|
338
278
|
const ret = arg0.msCrypto;
|
|
339
279
|
return ret;
|
|
@@ -350,10 +290,6 @@ function __wbg_get_imports() {
|
|
|
350
290
|
const ret = new Array();
|
|
351
291
|
return ret;
|
|
352
292
|
};
|
|
353
|
-
imports.wbg.__wbg_new_8a6f238a6ece86ea = function() {
|
|
354
|
-
const ret = new Error();
|
|
355
|
-
return ret;
|
|
356
|
-
};
|
|
357
293
|
imports.wbg.__wbg_new_b546ae120718850e = function() {
|
|
358
294
|
const ret = new Map();
|
|
359
295
|
return ret;
|
|
@@ -370,6 +306,10 @@ function __wbg_get_imports() {
|
|
|
370
306
|
const ret = arg0.node;
|
|
371
307
|
return ret;
|
|
372
308
|
};
|
|
309
|
+
imports.wbg.__wbg_now_69d776cd24f5215b = function() {
|
|
310
|
+
const ret = Date.now();
|
|
311
|
+
return ret;
|
|
312
|
+
};
|
|
373
313
|
imports.wbg.__wbg_process_dc0fbacc7c1c06f7 = function(arg0) {
|
|
374
314
|
const ret = arg0.process;
|
|
375
315
|
return ret;
|
|
@@ -394,13 +334,6 @@ function __wbg_get_imports() {
|
|
|
394
334
|
const ret = arg0.set(arg1, arg2);
|
|
395
335
|
return ret;
|
|
396
336
|
};
|
|
397
|
-
imports.wbg.__wbg_stack_0ed75d68575b0f3c = function(arg0, arg1) {
|
|
398
|
-
const ret = arg1.stack;
|
|
399
|
-
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
400
|
-
const len1 = WASM_VECTOR_LEN;
|
|
401
|
-
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
402
|
-
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
403
|
-
};
|
|
404
337
|
imports.wbg.__wbg_static_accessor_GLOBAL_769e6b65d6557335 = function() {
|
|
405
338
|
const ret = typeof global === 'undefined' ? null : global;
|
|
406
339
|
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
@@ -461,7 +394,6 @@ function __wbg_get_imports() {
|
|
|
461
394
|
function __wbg_finalize_init(instance, module) {
|
|
462
395
|
wasm = instance.exports;
|
|
463
396
|
__wbg_init.__wbindgen_wasm_module = module;
|
|
464
|
-
cachedDataViewMemory0 = null;
|
|
465
397
|
cachedUint8ArrayMemory0 = null;
|
|
466
398
|
|
|
467
399
|
|
|
Binary file
|
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
export const memory: WebAssembly.Memory;
|
|
4
4
|
export const generate_keypair: () => [number, number, number];
|
|
5
5
|
export const get_public_key: (a: number, b: number) => [number, number, number, number];
|
|
6
|
-
export const init_logging: () => void;
|
|
7
6
|
export const verify_jwt: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
7
|
+
export const init_tracing: (a: any, b: number, c: number) => void;
|
|
8
8
|
export const __wbindgen_exn_store: (a: number) => void;
|
|
9
9
|
export const __externref_table_alloc: () => number;
|
|
10
10
|
export const __wbindgen_externrefs: WebAssembly.Table;
|
|
11
|
-
export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
12
11
|
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
13
12
|
export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
14
13
|
export const __externref_table_dealloc: (a: number) => void;
|
|
14
|
+
export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
15
15
|
export const __wbindgen_start: () => void;
|