@vaultgraph/sdk 0.1.3 → 0.1.5
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 +48 -13
- package/dist/index.d.ts +25 -1
- package/dist/index.js +31 -14
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
# VaultGraph SDK
|
|
2
2
|
|
|
3
|
-
VaultGraph
|
|
3
|
+
[VaultGraph](https://vaultgraph.com) is a platform for building trustworthy AI agent applications.
|
|
4
|
+
|
|
5
|
+
## What this SDK is for
|
|
6
|
+
|
|
7
|
+
- Build canonical `JobReceipt` payloads that match the portal ingestion API.
|
|
8
|
+
- Hash sensitive context before it leaves your system.
|
|
9
|
+
- Sign receipts with your vendor keys and submit them to `/api/receipts` using your vendor API key.
|
|
10
|
+
- Verify signatures locally when needed.
|
|
11
|
+
|
|
12
|
+
## Prerequisites
|
|
13
|
+
|
|
14
|
+
- A VaultGraph vendor organization in the portal (create or join at https://app.vaultgraph.com). Marketing site: https://vaultgraph.com.
|
|
15
|
+
- Vendor API key created in the portal (Org Settings → API Keys). Keep this server-side only.
|
|
16
|
+
- At least one agent and consumer defined in the portal so you can reference their IDs when creating receipts.
|
|
17
|
+
|
|
18
|
+
If you need step-by-step UI guidance, see the [VaultGraph Docs](https://vaultgraph.com/docs).
|
|
4
19
|
|
|
5
20
|
## Install
|
|
6
21
|
|
|
@@ -12,28 +27,24 @@ pnpm add @vaultgraph/sdk
|
|
|
12
27
|
|
|
13
28
|
### Generate a keypair (one-time, server-side)
|
|
14
29
|
|
|
15
|
-
**Supported algorithm
|
|
30
|
+
**Supported algorithm: Ed25519.** The ingestion API verifies with `algorithm: null`, which assumes Ed25519/Ed448; RSA/ECDSA signatures are not accepted right now.
|
|
16
31
|
|
|
17
32
|
```ts
|
|
18
|
-
import {
|
|
33
|
+
import { generateKeyPair } from "@vaultgraph/sdk";
|
|
19
34
|
|
|
20
|
-
const { privateKey, publicKey } =
|
|
21
|
-
privateKeyEncoding: { format: "pem", type: "pkcs8" },
|
|
22
|
-
publicKeyEncoding: { format: "pem", type: "spki" },
|
|
23
|
-
});
|
|
35
|
+
const { privateKey, publicKey } = generateKeyPair();
|
|
24
36
|
|
|
25
37
|
console.log("Private key (keep secret):\n", privateKey);
|
|
26
38
|
console.log("Public key (share with VaultGraph):\n", publicKey);
|
|
27
39
|
```
|
|
28
40
|
|
|
29
|
-
Store the private key in your secrets manager; never ship it to the browser. Publish the public key wherever you manage org settings or bundle it with exports.
|
|
41
|
+
This helper is server-only (Node 18+/edge) and returns PEM-encoded Ed25519 keys. Store the private key in your secrets manager; never ship it to the browser. Publish the public key wherever you manage org settings or bundle it with exports.
|
|
30
42
|
|
|
31
43
|
### Create, sign, verify, and submit
|
|
32
44
|
|
|
33
45
|
```ts
|
|
34
46
|
import {
|
|
35
47
|
createReceipt,
|
|
36
|
-
createSignedReceipt,
|
|
37
48
|
hashContext,
|
|
38
49
|
signReceipt,
|
|
39
50
|
submitReceipt,
|
|
@@ -53,8 +64,8 @@ const receipt = createReceipt({
|
|
|
53
64
|
metadata: { channel: "email" },
|
|
54
65
|
});
|
|
55
66
|
|
|
56
|
-
// 3) Sign the receipt
|
|
57
|
-
const
|
|
67
|
+
// 3) Sign the receipt with Ed25519 algorithm
|
|
68
|
+
const signature = signReceipt({
|
|
58
69
|
receipt,
|
|
59
70
|
privateKey: process.env.VAULTGRAPH_VENDOR_PRIVATE_KEY!,
|
|
60
71
|
});
|
|
@@ -68,7 +79,6 @@ const ok = verifyReceipt({
|
|
|
68
79
|
|
|
69
80
|
// 5) Submit to your portal deployment
|
|
70
81
|
await submitReceipt({
|
|
71
|
-
apiUrl: "https://app.vaultgraph.com", // or your self-hosted URL
|
|
72
82
|
receipt,
|
|
73
83
|
signature,
|
|
74
84
|
publicKey: process.env.VAULTGRAPH_VENDOR_PUBLIC_KEY!,
|
|
@@ -76,6 +86,26 @@ await submitReceipt({
|
|
|
76
86
|
});
|
|
77
87
|
```
|
|
78
88
|
|
|
89
|
+
### Convenience: create + sign + submit in one step (server-only)
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
import { submitSignedReceipt } from "@vaultgraph/sdk";
|
|
93
|
+
|
|
94
|
+
const { receipt, signature, response } = await submitSignedReceipt({
|
|
95
|
+
apiKey: process.env.VAULTGRAPH_VENDOR_API_KEY!,
|
|
96
|
+
publicKey: process.env.VAULTGRAPH_VENDOR_PUBLIC_KEY!,
|
|
97
|
+
privateKey: process.env.VAULTGRAPH_VENDOR_PRIVATE_KEY!,
|
|
98
|
+
agentId: "agent-123",
|
|
99
|
+
consumerId: "consumer-456",
|
|
100
|
+
jobId: "job-789",
|
|
101
|
+
resolution: "resolved",
|
|
102
|
+
contextHash: hashContext({ transcript: "hello" }),
|
|
103
|
+
metadata: { source: "sdk" },
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
console.log(response); // { id, status }
|
|
107
|
+
```
|
|
108
|
+
|
|
79
109
|
### Convenience: create + sign in one step
|
|
80
110
|
|
|
81
111
|
```ts
|
|
@@ -100,11 +130,16 @@ const { receipt, signature } = createSignedReceipt({
|
|
|
100
130
|
- `signReceipt(options)` → signature string (base64 default)
|
|
101
131
|
- `verifyReceipt(options)` → boolean
|
|
102
132
|
- `createSignedReceipt(options)` → `{ receipt, signature }`
|
|
133
|
+
- `submitSignedReceipt(options)` → creates, signs, and submits; defaults `apiUrl` to portal base
|
|
134
|
+
- `submitReceipt(options)` → POSTs to `/api/receipts` (requires `apiKey`)
|
|
103
135
|
- `submitReceipt(options)` → POSTs to `/api/receipts` (requires `apiKey`)
|
|
104
|
-
-
|
|
136
|
+
- `generateKeyPair()` → returns PEM-encoded Ed25519 keypair
|
|
137
|
+
- Types: `CreateReceiptInput`, `JobReceipt`, `JobReceiptV0`, `JobResolution`, `ReceiptVersion`, `SubmitReceiptOptions`, `SubmitReceiptResponse`
|
|
105
138
|
|
|
106
139
|
## Notes
|
|
107
140
|
|
|
108
141
|
- Do not send raw conversation context; send `context_hash` instead.
|
|
109
142
|
- Keep your private key and vendor API key server-side only (API key is required for ingestion).
|
|
110
143
|
- Receipt versioning currently `v0`; breaking changes will bump the major version of this package.
|
|
144
|
+
- Portal: https://app.vaultgraph.com
|
|
145
|
+
- Docs: https://vaultgraph.com/docs
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { KeyLike, BinaryToTextEncoding } from 'crypto';
|
|
2
2
|
import { CreateReceiptInput, JobReceipt } from '@repo/lib/job-receipt';
|
|
3
3
|
export { CreateReceiptInput, JOB_RESOLUTIONS, JobReceipt, JobReceiptV0, JobResolution, ReceiptVersion, canonicalJSONStringify, createReceipt, hashContext, jobReceiptV0Schema, serializeReceipt, signReceipt, verifyReceipt } from '@repo/lib/job-receipt';
|
|
4
|
+
import { SubmitReceiptResponse } from '@repo/lib/submit-receipt';
|
|
4
5
|
export { SubmitReceiptOptions, SubmitReceiptResponse, submitReceipt } from '@repo/lib/submit-receipt';
|
|
5
6
|
|
|
6
7
|
interface CreateSignedReceiptOptions extends CreateReceiptInput {
|
|
@@ -8,6 +9,14 @@ interface CreateSignedReceiptOptions extends CreateReceiptInput {
|
|
|
8
9
|
algorithm?: string | null;
|
|
9
10
|
encoding?: BinaryToTextEncoding;
|
|
10
11
|
}
|
|
12
|
+
interface SubmitSignedReceiptOptions extends CreateSignedReceiptOptions {
|
|
13
|
+
/** API base URL; defaults to the portal URL (app.vaultgraph.com in prod). */
|
|
14
|
+
apiUrl?: string;
|
|
15
|
+
apiKey: string;
|
|
16
|
+
publicKey: KeyLike;
|
|
17
|
+
/** Optional fetch implementation for custom transports or tests. */
|
|
18
|
+
fetchImpl?: typeof fetch;
|
|
19
|
+
}
|
|
11
20
|
/**
|
|
12
21
|
* Convenience helper to construct and sign a receipt in one step.
|
|
13
22
|
*/
|
|
@@ -15,5 +24,20 @@ declare function createSignedReceipt(options: CreateSignedReceiptOptions): {
|
|
|
15
24
|
receipt: JobReceipt;
|
|
16
25
|
signature: string;
|
|
17
26
|
};
|
|
27
|
+
/**
|
|
28
|
+
* Server-only helper to create, sign, and submit a receipt in one step.
|
|
29
|
+
*/
|
|
30
|
+
declare function submitSignedReceipt(options: SubmitSignedReceiptOptions): Promise<{
|
|
31
|
+
receipt: JobReceipt;
|
|
32
|
+
signature: string;
|
|
33
|
+
response: SubmitReceiptResponse;
|
|
34
|
+
}>;
|
|
35
|
+
/**
|
|
36
|
+
* Generates an Ed25519 keypair encoded as PEM strings (server-only).
|
|
37
|
+
*/
|
|
38
|
+
declare function generateKeyPair(): {
|
|
39
|
+
privateKey: string;
|
|
40
|
+
publicKey: string;
|
|
41
|
+
};
|
|
18
42
|
|
|
19
|
-
export { type CreateSignedReceiptOptions, createSignedReceipt };
|
|
43
|
+
export { type CreateSignedReceiptOptions, type SubmitSignedReceiptOptions, createSignedReceipt, generateKeyPair, submitSignedReceipt };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { createHash, sign, verify, createPrivateKey, createPublicKey } from 'crypto';
|
|
1
|
+
import { createHash, sign, verify, createPrivateKey, createPublicKey, generateKeyPairSync } from 'crypto';
|
|
2
2
|
|
|
3
|
-
//
|
|
3
|
+
// src/index.ts
|
|
4
4
|
var JOB_RESOLUTIONS = ["resolved", "partial", "failed"];
|
|
5
5
|
var VALID_JOB_RESOLUTIONS = JOB_RESOLUTIONS;
|
|
6
6
|
var jobReceiptV0Schema = {
|
|
@@ -167,15 +167,7 @@ function canonicalize(value) {
|
|
|
167
167
|
|
|
168
168
|
// ../lib/src/submit-receipt.ts
|
|
169
169
|
async function submitReceipt(options) {
|
|
170
|
-
const {
|
|
171
|
-
apiUrl,
|
|
172
|
-
receipt,
|
|
173
|
-
signature,
|
|
174
|
-
publicKey,
|
|
175
|
-
metadata,
|
|
176
|
-
apiKey,
|
|
177
|
-
fetchImpl
|
|
178
|
-
} = options;
|
|
170
|
+
const { apiUrl, receipt, signature, publicKey, apiKey, fetchImpl } = options;
|
|
179
171
|
if (!apiUrl || !apiUrl.trim()) {
|
|
180
172
|
throw new Error("apiUrl is required");
|
|
181
173
|
}
|
|
@@ -193,8 +185,7 @@ async function submitReceipt(options) {
|
|
|
193
185
|
body: JSON.stringify({
|
|
194
186
|
receipt,
|
|
195
187
|
signature,
|
|
196
|
-
public_key: publicKey
|
|
197
|
-
metadata
|
|
188
|
+
public_key: publicKey
|
|
198
189
|
})
|
|
199
190
|
});
|
|
200
191
|
const payload = await safeParseJson(res);
|
|
@@ -221,6 +212,11 @@ async function safeParseJson(response) {
|
|
|
221
212
|
}
|
|
222
213
|
}
|
|
223
214
|
|
|
215
|
+
// ../lib/src/site-url.ts
|
|
216
|
+
function getPortalURL() {
|
|
217
|
+
return process.env.NEXT_PUBLIC_PORTAL_URL || process.env.NODE_ENV === "development" && "http://localhost:3001" || "https://app.vaultgraph.com";
|
|
218
|
+
}
|
|
219
|
+
|
|
224
220
|
// src/index.ts
|
|
225
221
|
function createSignedReceipt(options) {
|
|
226
222
|
const { privateKey, algorithm, encoding, ...receiptInput } = options;
|
|
@@ -233,5 +229,26 @@ function createSignedReceipt(options) {
|
|
|
233
229
|
});
|
|
234
230
|
return { receipt, signature };
|
|
235
231
|
}
|
|
232
|
+
async function submitSignedReceipt(options) {
|
|
233
|
+
const { apiUrl, apiKey, publicKey, fetchImpl, ...createAndSignOptions } = options;
|
|
234
|
+
const { receipt, signature } = createSignedReceipt(createAndSignOptions);
|
|
235
|
+
const targetApiUrl = apiUrl ?? getPortalURL();
|
|
236
|
+
const response = await submitReceipt({
|
|
237
|
+
apiUrl: targetApiUrl,
|
|
238
|
+
apiKey,
|
|
239
|
+
receipt,
|
|
240
|
+
signature,
|
|
241
|
+
publicKey: createPublicKey(publicKey).export({ type: "spki", format: "pem" }).toString(),
|
|
242
|
+
fetchImpl
|
|
243
|
+
});
|
|
244
|
+
return { receipt, signature, response };
|
|
245
|
+
}
|
|
246
|
+
function generateKeyPair() {
|
|
247
|
+
const { privateKey, publicKey } = generateKeyPairSync("ed25519", {
|
|
248
|
+
privateKeyEncoding: { format: "pem", type: "pkcs8" },
|
|
249
|
+
publicKeyEncoding: { format: "pem", type: "spki" }
|
|
250
|
+
});
|
|
251
|
+
return { privateKey, publicKey };
|
|
252
|
+
}
|
|
236
253
|
|
|
237
|
-
export { JOB_RESOLUTIONS, canonicalJSONStringify, createReceipt, createSignedReceipt, hashContext, jobReceiptV0Schema, serializeReceipt, signReceipt, submitReceipt, verifyReceipt };
|
|
254
|
+
export { JOB_RESOLUTIONS, canonicalJSONStringify, createReceipt, createSignedReceipt, generateKeyPair, hashContext, jobReceiptV0Schema, serializeReceipt, signReceipt, submitReceipt, submitSignedReceipt, verifyReceipt };
|
package/package.json
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaultgraph/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
|
+
"homepage": "https://vaultgraph.com/",
|
|
8
|
+
"bugs": {
|
|
9
|
+
"url": "mailto:admin@vaultgraph.com"
|
|
10
|
+
},
|
|
7
11
|
"files": ["dist"],
|
|
8
12
|
"main": "./dist/index.js",
|
|
9
13
|
"module": "./dist/index.js",
|