@nexart/ai-execution 0.4.2 → 0.6.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.
Files changed (36) hide show
  1. package/README.md +79 -2
  2. package/dist/index.cjs +1433 -10
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +140 -3
  5. package/dist/index.d.ts +140 -3
  6. package/dist/index.mjs +1425 -10
  7. package/dist/index.mjs.map +1 -1
  8. package/dist/providers/anthropic.cjs +1 -1
  9. package/dist/providers/anthropic.cjs.map +1 -1
  10. package/dist/providers/anthropic.d.cts +1 -1
  11. package/dist/providers/anthropic.d.ts +1 -1
  12. package/dist/providers/anthropic.mjs +1 -1
  13. package/dist/providers/anthropic.mjs.map +1 -1
  14. package/dist/providers/openai.cjs +1 -1
  15. package/dist/providers/openai.cjs.map +1 -1
  16. package/dist/providers/openai.d.cts +1 -1
  17. package/dist/providers/openai.d.ts +1 -1
  18. package/dist/providers/openai.mjs +1 -1
  19. package/dist/providers/openai.mjs.map +1 -1
  20. package/dist/providers/wrap.cjs +1 -1
  21. package/dist/providers/wrap.cjs.map +1 -1
  22. package/dist/providers/wrap.d.cts +1 -1
  23. package/dist/providers/wrap.d.ts +1 -1
  24. package/dist/providers/wrap.mjs +1 -1
  25. package/dist/providers/wrap.mjs.map +1 -1
  26. package/dist/{types-Cnm2G_rg.d.cts → types-Cgb52dTx.d.cts} +90 -1
  27. package/dist/{types-Cnm2G_rg.d.ts → types-Cgb52dTx.d.ts} +90 -1
  28. package/fixtures/attestation/keys-v1.json +18 -0
  29. package/fixtures/attestation/receipt-v1.json +10 -0
  30. package/fixtures/attestation/receipt-v1.pub +1 -0
  31. package/fixtures/attestation/receipt-v1.sig +1 -0
  32. package/fixtures/v060/legacy-attestation.json +32 -0
  33. package/fixtures/v060/original-meta-bundle.json +36 -0
  34. package/fixtures/v060/pre-v05-bundle.json +29 -0
  35. package/fixtures/v060/redacted-bundle.json +36 -0
  36. package/package.json +6 -4
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as CreateSnapshotParams, A as AiExecutionSnapshotV1, V as VerificationResult, a as CerMeta, b as CerAiExecutionBundle, c as CertifyDecisionParams, R as RunBuilderOptions, S as StepParams, d as RunSummary, e as AttestOptions, f as AttestationResult, g as AttestationReceipt } from './types-Cnm2G_rg.cjs';
2
- export { i as AiExecutionParameters, j as AttestationReceiptResult, h as CerVerifyCode, h as CerVerifyCodeType, P as ProviderConfig, W as WrappedExecutionParams, k as WrappedExecutionResult } from './types-Cnm2G_rg.cjs';
1
+ import { C as CreateSnapshotParams, A as AiExecutionSnapshotV1, V as VerificationResult, a as CerMeta, b as CerAiExecutionBundle, c as CertifyDecisionParams, R as RunBuilderOptions, S as StepParams, d as RunSummary, e as AttestOptions, f as AttestationResult, g as SanitizeStorageOptions, h as AttestationReceipt, N as NodeKeysDocument, i as NodeReceiptVerifyResult, j as SignedAttestationReceipt, k as CerVerifyCode } from './types-Cgb52dTx.cjs';
2
+ export { l as AiExecutionParameters, m as AttestationReceiptResult, n as ClientDefaults, o as NexArtClient, P as ProviderCallParams, p as ProviderCallResult, q as ProviderConfig, W as WrappedExecutionParams, r as WrappedExecutionResult } from './types-Cgb52dTx.cjs';
3
3
  export { wrapProvider } from './providers/wrap.cjs';
4
4
 
5
5
  declare class CerVerificationError extends Error {
@@ -50,7 +50,27 @@ declare function attest(bundle: CerAiExecutionBundle, options: AttestOptions): P
50
50
  declare function exportCer(bundle: CerAiExecutionBundle): string;
51
51
  declare function importCer(json: string): CerAiExecutionBundle;
52
52
 
53
+ /** @deprecated Use sanitizeForStorage or sanitizeForStamp instead. */
53
54
  declare function sanitizeForAttestation(bundle: CerAiExecutionBundle): CerAiExecutionBundle;
55
+ /**
56
+ * Prepare a bundle for safe storage:
57
+ * - Removes undefined keys.
58
+ * - Removes non-JSON-serializable types (bigint, function, symbol).
59
+ * - Optionally redacts sensitive field paths.
60
+ *
61
+ * Does NOT recompute certificateHash or any content hashes.
62
+ */
63
+ declare function sanitizeForStorage(bundle: CerAiExecutionBundle, options?: SanitizeStorageOptions): CerAiExecutionBundle;
64
+ /**
65
+ * Produce the minimal "attestable core" envelope for a bundle.
66
+ *
67
+ * Returns only: bundleType, certificateHash, createdAt, version, snapshot.
68
+ * The meta field is excluded — it is informational and not included in the
69
+ * certificateHash computation.
70
+ *
71
+ * Does NOT recompute any hashes.
72
+ */
73
+ declare function sanitizeForStamp(bundle: CerAiExecutionBundle): Omit<CerAiExecutionBundle, 'meta'>;
54
74
  declare function hasAttestation(bundle: unknown): boolean;
55
75
 
56
76
  declare function getAttestationReceipt(bundle: unknown): AttestationReceipt | null;
@@ -64,4 +84,121 @@ declare function attestIfNeeded(bundle: CerAiExecutionBundle, options: AttestOpt
64
84
  receipt: AttestationReceipt;
65
85
  }>;
66
86
 
67
- export { AiExecutionSnapshotV1, AttestOptions, AttestationReceipt, AttestationResult, CerAiExecutionBundle, CerAttestationError, CerMeta, CerVerificationError, CertifyDecisionParams, CreateSnapshotParams, RunBuilder, RunBuilderOptions, RunSummary, StepParams, VerificationResult, attest, attestIfNeeded, certifyAndAttestDecision, certifyDecision, computeInputHash, computeOutputHash, createSnapshot, exportCer, getAttestationReceipt, hasAttestation, hashCanonicalJson, hashUtf8, importCer, sanitizeForAttestation, sealCer, sha256Hex, toCanonicalJson, verifyCer as verify, verifyCer, verifySnapshot };
87
+ declare function verifyNodeReceiptSignature(params: {
88
+ receipt: SignedAttestationReceipt;
89
+ signatureB64Url: string;
90
+ key: {
91
+ jwk?: NodeKeysDocument['keys'][number]['publicKeyJwk'];
92
+ spkiB64?: string;
93
+ rawB64Url?: string;
94
+ };
95
+ }): Promise<NodeReceiptVerifyResult>;
96
+ declare function fetchNodeKeys(nodeUrl: string): Promise<NodeKeysDocument>;
97
+ type SelectKeySuccess = {
98
+ key: NodeKeysDocument['keys'][number];
99
+ error?: never;
100
+ };
101
+ type SelectKeyFailure = {
102
+ error: NodeReceiptVerifyResult;
103
+ key?: never;
104
+ };
105
+ type SelectKeyResult = SelectKeySuccess | SelectKeyFailure;
106
+ declare function selectNodeKey(doc: NodeKeysDocument, kid?: string): SelectKeyResult;
107
+ declare function verifyBundleAttestation(bundle: unknown, options: {
108
+ nodeUrl: string;
109
+ kid?: string;
110
+ }): Promise<NodeReceiptVerifyResult>;
111
+
112
+ /**
113
+ * @nexart/ai-execution — certifyDecisionFromProviderCall (v0.6.0)
114
+ *
115
+ * High-level one-function wrapper for common AI provider call patterns.
116
+ * Extracts prompt / input / output / parameters from raw request+response
117
+ * objects and produces a sealed CerAiExecutionBundle.
118
+ *
119
+ * Supported providers: openai, anthropic, mistral, gemini, bedrock, + generic.
120
+ *
121
+ * Returns { ok: true, bundle } on success.
122
+ * Returns { ok: false, code: 'SCHEMA_ERROR', reason } when a required field
123
+ * cannot be extracted — never silently guesses.
124
+ */
125
+
126
+ interface ProviderCallParams {
127
+ provider: string;
128
+ model?: string;
129
+ request: Record<string, unknown>;
130
+ response: Record<string, unknown>;
131
+ meta?: CerMeta;
132
+ executionId?: string;
133
+ timestamp?: string;
134
+ /** CER creation timestamp. Defaults to current time if omitted. */
135
+ createdAt?: string;
136
+ appId?: string | null;
137
+ workflowId?: string | null;
138
+ conversationId?: string | null;
139
+ }
140
+ type ProviderCallResult = {
141
+ ok: true;
142
+ bundle: CerAiExecutionBundle;
143
+ } | {
144
+ ok: false;
145
+ code: typeof CerVerifyCode.SCHEMA_ERROR;
146
+ reason: string;
147
+ };
148
+ /**
149
+ * Certify an AI provider call from raw request + response objects.
150
+ *
151
+ * @example
152
+ * ```typescript
153
+ * const res = certifyDecisionFromProviderCall({
154
+ * provider: 'openai',
155
+ * request: { model: 'gpt-4o', messages: [...] },
156
+ * response: { choices: [{ message: { content: 'Hello' } }] },
157
+ * });
158
+ * if (res.ok) console.log(res.bundle.certificateHash);
159
+ * else console.error(res.reason);
160
+ * ```
161
+ */
162
+ declare function certifyDecisionFromProviderCall(params: ProviderCallParams): ProviderCallResult;
163
+
164
+ /**
165
+ * @nexart/ai-execution — createClient factory (v0.6.0)
166
+ *
167
+ * Returns a configured client with opinionated defaults applied to every call.
168
+ * Defaults NEVER affect bundle hashing — they are only injected into snapshot
169
+ * fields (appId, workflowId) and attestation options (nodeUrl, apiKey).
170
+ *
171
+ * Usage:
172
+ * const client = createClient({ appId: 'my-app', nodeUrl: 'https://...' });
173
+ * const bundle = client.certifyDecision({ provider, model, ... });
174
+ * const result = await client.verify(bundle);
175
+ */
176
+
177
+ interface ClientDefaults {
178
+ appId?: string | null;
179
+ workflowId?: string | null;
180
+ nodeUrl?: string;
181
+ apiKey?: string | (() => string | Promise<string>);
182
+ tags?: string[];
183
+ source?: string;
184
+ }
185
+ interface NexArtClient {
186
+ certifyDecision(params: CertifyDecisionParams): CerAiExecutionBundle;
187
+ certifyAndAttestDecision(params: CertifyDecisionParams, options?: Partial<AttestOptions>): Promise<{
188
+ bundle: CerAiExecutionBundle;
189
+ receipt: AttestationReceipt;
190
+ }>;
191
+ verify(bundle: CerAiExecutionBundle): VerificationResult;
192
+ verifyBundleAttestation(bundle: unknown, options?: {
193
+ nodeUrl?: string;
194
+ kid?: string;
195
+ }): Promise<NodeReceiptVerifyResult>;
196
+ }
197
+ /**
198
+ * Create a pre-configured client that applies defaults to every operation.
199
+ *
200
+ * @param defaults — Shared configuration applied to all client calls.
201
+ */
202
+ declare function createClient(defaults?: ClientDefaults): NexArtClient;
203
+
204
+ export { AiExecutionSnapshotV1, AttestOptions, AttestationReceipt, AttestationResult, CerAiExecutionBundle, CerAttestationError, CerMeta, CerVerificationError, CerVerifyCode, CerVerifyCode as CerVerifyCodeType, CertifyDecisionParams, CreateSnapshotParams, NodeKeysDocument, NodeReceiptVerifyResult, RunBuilder, RunBuilderOptions, RunSummary, SanitizeStorageOptions, SignedAttestationReceipt, StepParams, VerificationResult, attest, attestIfNeeded, certifyAndAttestDecision, certifyDecision, certifyDecisionFromProviderCall, computeInputHash, computeOutputHash, createClient, createSnapshot, exportCer, fetchNodeKeys, getAttestationReceipt, hasAttestation, hashCanonicalJson, hashUtf8, importCer, sanitizeForAttestation, sanitizeForStamp, sanitizeForStorage, sealCer, selectNodeKey, sha256Hex, toCanonicalJson, verifyCer as verify, verifyBundleAttestation, verifyCer, verifyNodeReceiptSignature, verifySnapshot };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as CreateSnapshotParams, A as AiExecutionSnapshotV1, V as VerificationResult, a as CerMeta, b as CerAiExecutionBundle, c as CertifyDecisionParams, R as RunBuilderOptions, S as StepParams, d as RunSummary, e as AttestOptions, f as AttestationResult, g as AttestationReceipt } from './types-Cnm2G_rg.js';
2
- export { i as AiExecutionParameters, j as AttestationReceiptResult, h as CerVerifyCode, h as CerVerifyCodeType, P as ProviderConfig, W as WrappedExecutionParams, k as WrappedExecutionResult } from './types-Cnm2G_rg.js';
1
+ import { C as CreateSnapshotParams, A as AiExecutionSnapshotV1, V as VerificationResult, a as CerMeta, b as CerAiExecutionBundle, c as CertifyDecisionParams, R as RunBuilderOptions, S as StepParams, d as RunSummary, e as AttestOptions, f as AttestationResult, g as SanitizeStorageOptions, h as AttestationReceipt, N as NodeKeysDocument, i as NodeReceiptVerifyResult, j as SignedAttestationReceipt, k as CerVerifyCode } from './types-Cgb52dTx.js';
2
+ export { l as AiExecutionParameters, m as AttestationReceiptResult, n as ClientDefaults, o as NexArtClient, P as ProviderCallParams, p as ProviderCallResult, q as ProviderConfig, W as WrappedExecutionParams, r as WrappedExecutionResult } from './types-Cgb52dTx.js';
3
3
  export { wrapProvider } from './providers/wrap.js';
4
4
 
5
5
  declare class CerVerificationError extends Error {
@@ -50,7 +50,27 @@ declare function attest(bundle: CerAiExecutionBundle, options: AttestOptions): P
50
50
  declare function exportCer(bundle: CerAiExecutionBundle): string;
51
51
  declare function importCer(json: string): CerAiExecutionBundle;
52
52
 
53
+ /** @deprecated Use sanitizeForStorage or sanitizeForStamp instead. */
53
54
  declare function sanitizeForAttestation(bundle: CerAiExecutionBundle): CerAiExecutionBundle;
55
+ /**
56
+ * Prepare a bundle for safe storage:
57
+ * - Removes undefined keys.
58
+ * - Removes non-JSON-serializable types (bigint, function, symbol).
59
+ * - Optionally redacts sensitive field paths.
60
+ *
61
+ * Does NOT recompute certificateHash or any content hashes.
62
+ */
63
+ declare function sanitizeForStorage(bundle: CerAiExecutionBundle, options?: SanitizeStorageOptions): CerAiExecutionBundle;
64
+ /**
65
+ * Produce the minimal "attestable core" envelope for a bundle.
66
+ *
67
+ * Returns only: bundleType, certificateHash, createdAt, version, snapshot.
68
+ * The meta field is excluded — it is informational and not included in the
69
+ * certificateHash computation.
70
+ *
71
+ * Does NOT recompute any hashes.
72
+ */
73
+ declare function sanitizeForStamp(bundle: CerAiExecutionBundle): Omit<CerAiExecutionBundle, 'meta'>;
54
74
  declare function hasAttestation(bundle: unknown): boolean;
55
75
 
56
76
  declare function getAttestationReceipt(bundle: unknown): AttestationReceipt | null;
@@ -64,4 +84,121 @@ declare function attestIfNeeded(bundle: CerAiExecutionBundle, options: AttestOpt
64
84
  receipt: AttestationReceipt;
65
85
  }>;
66
86
 
67
- export { AiExecutionSnapshotV1, AttestOptions, AttestationReceipt, AttestationResult, CerAiExecutionBundle, CerAttestationError, CerMeta, CerVerificationError, CertifyDecisionParams, CreateSnapshotParams, RunBuilder, RunBuilderOptions, RunSummary, StepParams, VerificationResult, attest, attestIfNeeded, certifyAndAttestDecision, certifyDecision, computeInputHash, computeOutputHash, createSnapshot, exportCer, getAttestationReceipt, hasAttestation, hashCanonicalJson, hashUtf8, importCer, sanitizeForAttestation, sealCer, sha256Hex, toCanonicalJson, verifyCer as verify, verifyCer, verifySnapshot };
87
+ declare function verifyNodeReceiptSignature(params: {
88
+ receipt: SignedAttestationReceipt;
89
+ signatureB64Url: string;
90
+ key: {
91
+ jwk?: NodeKeysDocument['keys'][number]['publicKeyJwk'];
92
+ spkiB64?: string;
93
+ rawB64Url?: string;
94
+ };
95
+ }): Promise<NodeReceiptVerifyResult>;
96
+ declare function fetchNodeKeys(nodeUrl: string): Promise<NodeKeysDocument>;
97
+ type SelectKeySuccess = {
98
+ key: NodeKeysDocument['keys'][number];
99
+ error?: never;
100
+ };
101
+ type SelectKeyFailure = {
102
+ error: NodeReceiptVerifyResult;
103
+ key?: never;
104
+ };
105
+ type SelectKeyResult = SelectKeySuccess | SelectKeyFailure;
106
+ declare function selectNodeKey(doc: NodeKeysDocument, kid?: string): SelectKeyResult;
107
+ declare function verifyBundleAttestation(bundle: unknown, options: {
108
+ nodeUrl: string;
109
+ kid?: string;
110
+ }): Promise<NodeReceiptVerifyResult>;
111
+
112
+ /**
113
+ * @nexart/ai-execution — certifyDecisionFromProviderCall (v0.6.0)
114
+ *
115
+ * High-level one-function wrapper for common AI provider call patterns.
116
+ * Extracts prompt / input / output / parameters from raw request+response
117
+ * objects and produces a sealed CerAiExecutionBundle.
118
+ *
119
+ * Supported providers: openai, anthropic, mistral, gemini, bedrock, + generic.
120
+ *
121
+ * Returns { ok: true, bundle } on success.
122
+ * Returns { ok: false, code: 'SCHEMA_ERROR', reason } when a required field
123
+ * cannot be extracted — never silently guesses.
124
+ */
125
+
126
+ interface ProviderCallParams {
127
+ provider: string;
128
+ model?: string;
129
+ request: Record<string, unknown>;
130
+ response: Record<string, unknown>;
131
+ meta?: CerMeta;
132
+ executionId?: string;
133
+ timestamp?: string;
134
+ /** CER creation timestamp. Defaults to current time if omitted. */
135
+ createdAt?: string;
136
+ appId?: string | null;
137
+ workflowId?: string | null;
138
+ conversationId?: string | null;
139
+ }
140
+ type ProviderCallResult = {
141
+ ok: true;
142
+ bundle: CerAiExecutionBundle;
143
+ } | {
144
+ ok: false;
145
+ code: typeof CerVerifyCode.SCHEMA_ERROR;
146
+ reason: string;
147
+ };
148
+ /**
149
+ * Certify an AI provider call from raw request + response objects.
150
+ *
151
+ * @example
152
+ * ```typescript
153
+ * const res = certifyDecisionFromProviderCall({
154
+ * provider: 'openai',
155
+ * request: { model: 'gpt-4o', messages: [...] },
156
+ * response: { choices: [{ message: { content: 'Hello' } }] },
157
+ * });
158
+ * if (res.ok) console.log(res.bundle.certificateHash);
159
+ * else console.error(res.reason);
160
+ * ```
161
+ */
162
+ declare function certifyDecisionFromProviderCall(params: ProviderCallParams): ProviderCallResult;
163
+
164
+ /**
165
+ * @nexart/ai-execution — createClient factory (v0.6.0)
166
+ *
167
+ * Returns a configured client with opinionated defaults applied to every call.
168
+ * Defaults NEVER affect bundle hashing — they are only injected into snapshot
169
+ * fields (appId, workflowId) and attestation options (nodeUrl, apiKey).
170
+ *
171
+ * Usage:
172
+ * const client = createClient({ appId: 'my-app', nodeUrl: 'https://...' });
173
+ * const bundle = client.certifyDecision({ provider, model, ... });
174
+ * const result = await client.verify(bundle);
175
+ */
176
+
177
+ interface ClientDefaults {
178
+ appId?: string | null;
179
+ workflowId?: string | null;
180
+ nodeUrl?: string;
181
+ apiKey?: string | (() => string | Promise<string>);
182
+ tags?: string[];
183
+ source?: string;
184
+ }
185
+ interface NexArtClient {
186
+ certifyDecision(params: CertifyDecisionParams): CerAiExecutionBundle;
187
+ certifyAndAttestDecision(params: CertifyDecisionParams, options?: Partial<AttestOptions>): Promise<{
188
+ bundle: CerAiExecutionBundle;
189
+ receipt: AttestationReceipt;
190
+ }>;
191
+ verify(bundle: CerAiExecutionBundle): VerificationResult;
192
+ verifyBundleAttestation(bundle: unknown, options?: {
193
+ nodeUrl?: string;
194
+ kid?: string;
195
+ }): Promise<NodeReceiptVerifyResult>;
196
+ }
197
+ /**
198
+ * Create a pre-configured client that applies defaults to every operation.
199
+ *
200
+ * @param defaults — Shared configuration applied to all client calls.
201
+ */
202
+ declare function createClient(defaults?: ClientDefaults): NexArtClient;
203
+
204
+ export { AiExecutionSnapshotV1, AttestOptions, AttestationReceipt, AttestationResult, CerAiExecutionBundle, CerAttestationError, CerMeta, CerVerificationError, CerVerifyCode, CerVerifyCode as CerVerifyCodeType, CertifyDecisionParams, CreateSnapshotParams, NodeKeysDocument, NodeReceiptVerifyResult, RunBuilder, RunBuilderOptions, RunSummary, SanitizeStorageOptions, SignedAttestationReceipt, StepParams, VerificationResult, attest, attestIfNeeded, certifyAndAttestDecision, certifyDecision, certifyDecisionFromProviderCall, computeInputHash, computeOutputHash, createClient, createSnapshot, exportCer, fetchNodeKeys, getAttestationReceipt, hasAttestation, hashCanonicalJson, hashUtf8, importCer, sanitizeForAttestation, sanitizeForStamp, sanitizeForStorage, sealCer, selectNodeKey, sha256Hex, toCanonicalJson, verifyCer as verify, verifyBundleAttestation, verifyCer, verifyNodeReceiptSignature, verifySnapshot };