@vaultgraph/sdk 0.1.3 → 0.1.4

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 CHANGED
@@ -15,18 +15,15 @@ pnpm add @vaultgraph/sdk
15
15
  **Supported algorithm (MVP): Ed25519.** The ingestion API verifies with `algorithm: null`, which assumes Ed25519/Ed448; RSA/ECDSA signatures are not accepted right now.
16
16
 
17
17
  ```ts
18
- import { generateKeyPairSync } from "crypto";
18
+ import { generateKeyPair } from "@vaultgraph/sdk";
19
19
 
20
- const { privateKey, publicKey } = generateKeyPairSync("ed25519", {
21
- privateKeyEncoding: { format: "pem", type: "pkcs8" },
22
- publicKeyEncoding: { format: "pem", type: "spki" },
23
- });
20
+ const { privateKey, publicKey } = generateKeyPair();
24
21
 
25
22
  console.log("Private key (keep secret):\n", privateKey);
26
23
  console.log("Public key (share with VaultGraph):\n", publicKey);
27
24
  ```
28
25
 
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.
26
+ 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
27
 
31
28
  ### Create, sign, verify, and submit
32
29
 
@@ -35,6 +32,7 @@ import {
35
32
  createReceipt,
36
33
  createSignedReceipt,
37
34
  hashContext,
35
+ submitSignedReceipt,
38
36
  signReceipt,
39
37
  submitReceipt,
40
38
  verifyReceipt,
@@ -68,14 +66,34 @@ const ok = verifyReceipt({
68
66
 
69
67
  // 5) Submit to your portal deployment
70
68
  await submitReceipt({
71
- apiUrl: "https://app.vaultgraph.com", // or your self-hosted URL
72
69
  receipt,
73
70
  signature,
74
71
  publicKey: process.env.VAULTGRAPH_VENDOR_PUBLIC_KEY!,
75
72
  apiKey: process.env.VAULTGRAPH_VENDOR_API_KEY!,
73
+ // apiUrl: "https://localhost:3000" // optional override
76
74
  });
77
75
  ```
78
76
 
77
+ ### Convenience: create + sign + submit in one step (server-only)
78
+
79
+ ```ts
80
+ import { submitSignedReceipt } from "@vaultgraph/sdk";
81
+
82
+ const { receipt, signature, response } = await submitSignedReceipt({
83
+ apiKey: process.env.VAULTGRAPH_VENDOR_API_KEY!,
84
+ publicKey: process.env.VAULTGRAPH_VENDOR_PUBLIC_KEY!,
85
+ privateKey: process.env.VAULTGRAPH_VENDOR_PRIVATE_KEY!,
86
+ agentId: "agent-123",
87
+ consumerId: "consumer-456",
88
+ jobId: "job-789",
89
+ resolution: "resolved",
90
+ contextHash: hashContext({ transcript: "hello" }),
91
+ metadata: { source: "sdk" },
92
+ });
93
+
94
+ console.log(response); // { id, status }
95
+ ```
96
+
79
97
  ### Convenience: create + sign in one step
80
98
 
81
99
  ```ts
@@ -100,6 +118,7 @@ const { receipt, signature } = createSignedReceipt({
100
118
  - `signReceipt(options)` → signature string (base64 default)
101
119
  - `verifyReceipt(options)` → boolean
102
120
  - `createSignedReceipt(options)` → `{ receipt, signature }`
121
+ - `submitSignedReceipt(options)` → creates, signs, and submits; defaults `apiUrl` to portal base
103
122
  - `submitReceipt(options)` → POSTs to `/api/receipts` (requires `apiKey`)
104
123
  - Types: `JobReceipt`, `JobResolution`, `ReceiptVersion`, `SubmitReceiptOptions`, `SubmitReceiptResponse`
105
124
 
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
- // ../lib/src/job-receipt.ts
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaultgraph/sdk",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "license": "MIT",