@nomosprotocol/sdk 2.3.1 → 2.3.2
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 +11 -0
- package/dist/index.cjs +20 -8
- package/dist/index.d.cts +14 -1
- package/dist/index.d.ts +14 -1
- package/dist/index.js +20 -8
- package/package.json +9 -2
package/README.md
CHANGED
|
@@ -161,6 +161,17 @@ const verdict = await nomos.can({
|
|
|
161
161
|
});
|
|
162
162
|
```
|
|
163
163
|
|
|
164
|
+
Name your agent so the transcript records who asked, and mark test traffic so it stays out of the authority's public history and counts:
|
|
165
|
+
|
|
166
|
+
```ts
|
|
167
|
+
const verdict = await nomos.can(
|
|
168
|
+
{ authority: "eu-ai-act", ai_categorises_biometric_data_for_sensitive_attributes: true },
|
|
169
|
+
{ caller: { agent_id: "acme-hiring-agent", purpose: process.env.CI ? "test" : "production" } },
|
|
170
|
+
);
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
The name is declared, not verified, and is shown as such. Don't know which authority applies? `GET /api/exchange/find?q=<what you're about to do>`, or the MCP tool `find_authority`.
|
|
174
|
+
|
|
164
175
|
If a paid authority has not been purchased, NOMOS throws `NomosPaymentRequiredError` with the price and purchase URL attached.
|
|
165
176
|
|
|
166
177
|
NOMOS never auto-charges on your behalf.
|
package/dist/index.cjs
CHANGED
|
@@ -191,7 +191,7 @@ function isRetryable(status) {
|
|
|
191
191
|
}
|
|
192
192
|
|
|
193
193
|
// src/http-client.ts
|
|
194
|
-
var SDK_VERSION = "2.3.
|
|
194
|
+
var SDK_VERSION = "2.3.2";
|
|
195
195
|
var HttpClient = class {
|
|
196
196
|
constructor(opts) {
|
|
197
197
|
this.opts = opts;
|
|
@@ -215,6 +215,7 @@ var HttpClient = class {
|
|
|
215
215
|
"User-Agent": `nomos-node/${SDK_VERSION}`,
|
|
216
216
|
"NOMOS-SDK-Version": SDK_VERSION
|
|
217
217
|
};
|
|
218
|
+
if (reqOpts?.headers) Object.assign(headers, reqOpts.headers);
|
|
218
219
|
if (reqOpts?.idempotencyKey) {
|
|
219
220
|
headers["Idempotency-Key"] = reqOpts.idempotencyKey;
|
|
220
221
|
}
|
|
@@ -723,6 +724,13 @@ function normalizeAuthorityQueryResult(data, authority) {
|
|
|
723
724
|
...data.revoked === true ? { revoked: true, revocation_reason: data.revocation_reason } : {}
|
|
724
725
|
};
|
|
725
726
|
}
|
|
727
|
+
function callerHeaders(c) {
|
|
728
|
+
const h = {};
|
|
729
|
+
if (c?.agent_id) h["X-Nomos-Agent"] = c.agent_id;
|
|
730
|
+
if (c?.acts_for) h["X-Nomos-Acts-For"] = c.acts_for;
|
|
731
|
+
if (c?.purpose) h["X-Nomos-Purpose"] = c.purpose;
|
|
732
|
+
return h;
|
|
733
|
+
}
|
|
726
734
|
async function canViaExchange(authority, facts, action, opts) {
|
|
727
735
|
const base = (opts?.baseUrl ?? DEFAULT_EXCHANGE_BASE).replace(/\/$/, "");
|
|
728
736
|
const url = `${base}/api/v1/can`;
|
|
@@ -730,7 +738,7 @@ async function canViaExchange(authority, facts, action, opts) {
|
|
|
730
738
|
try {
|
|
731
739
|
res = await fetch(url, {
|
|
732
740
|
method: "POST",
|
|
733
|
-
headers: { "Content-Type": "application/json" },
|
|
741
|
+
headers: { "Content-Type": "application/json", "User-Agent": `nomos-node/${SDK_VERSION}`, ...callerHeaders(opts?.caller) },
|
|
734
742
|
body: JSON.stringify({ artifact: authority, action, ...facts }),
|
|
735
743
|
signal: opts?.signal
|
|
736
744
|
});
|
|
@@ -743,8 +751,8 @@ async function canViaExchange(authority, facts, action, opts) {
|
|
|
743
751
|
if (!res.ok) mapHttpError(res.status, data, requestId);
|
|
744
752
|
return normalizeAuthorityQueryResult(data, authority);
|
|
745
753
|
}
|
|
746
|
-
async function canViaExchangeAuthenticated(http, authority, facts, action) {
|
|
747
|
-
const { data } = await http.post("/api/v1/can", { artifact: authority, action, ...facts });
|
|
754
|
+
async function canViaExchangeAuthenticated(http, authority, facts, action, caller) {
|
|
755
|
+
const { data } = await http.post("/api/v1/can", { artifact: authority, action, ...facts }, { headers: callerHeaders(caller) });
|
|
748
756
|
return normalizeAuthorityQueryResult(data, authority);
|
|
749
757
|
}
|
|
750
758
|
async function canViaArtifact(http, artifactId, facts, action) {
|
|
@@ -841,7 +849,6 @@ async function can(params, opts) {
|
|
|
841
849
|
return canViaExchange(params.authority, facts, action, opts);
|
|
842
850
|
}
|
|
843
851
|
async function canAuthenticated(http, params, opts) {
|
|
844
|
-
void opts;
|
|
845
852
|
const { facts, action } = splitFacts(params);
|
|
846
853
|
if (params.artifact !== void 0) {
|
|
847
854
|
if (!params.key_certs || !params.root_public_key_pem) {
|
|
@@ -850,7 +857,7 @@ async function canAuthenticated(http, params, opts) {
|
|
|
850
857
|
return canViaChain(params.artifact, params.key_certs, params.root_public_key_pem, facts, action, opts);
|
|
851
858
|
}
|
|
852
859
|
if (params.artifact_id) return canViaArtifact(http, params.artifact_id, facts, action);
|
|
853
|
-
if (params.authority) return canViaExchangeAuthenticated(http, params.authority, facts, action);
|
|
860
|
+
if (params.authority) return canViaExchangeAuthenticated(http, params.authority, facts, action, opts?.caller);
|
|
854
861
|
throw new Error("can(): `authority` (a public Exchange artifact), `artifact_id` (your own artifact), or `artifact` (chain-of-trust) is required.");
|
|
855
862
|
}
|
|
856
863
|
var nomos = { can };
|
|
@@ -5051,9 +5058,14 @@ var TIE_ORDERS = {
|
|
|
5051
5058
|
function evaluate(artifact, facts) {
|
|
5052
5059
|
const logic = artifact.logic;
|
|
5053
5060
|
const res = logic.resolution ?? {};
|
|
5054
|
-
|
|
5055
|
-
if (!Array.isArray(decisions))
|
|
5061
|
+
if (!Array.isArray(logic.decisions))
|
|
5056
5062
|
throw new Error("logic.decisions missing");
|
|
5063
|
+
const declared = new Set(Object.keys(artifact.execution?.actions ?? {}));
|
|
5064
|
+
const isObligation = (d) => {
|
|
5065
|
+
const t = d?.then?.[0];
|
|
5066
|
+
return t?.type === "emit" || t?.type === "action" && declared.has(t?.action_name);
|
|
5067
|
+
};
|
|
5068
|
+
const decisions = logic.decisions.filter((d) => !isObligation(d));
|
|
5057
5069
|
const order = TIE_ORDERS[res.tie_breaker ?? "deny_wins"];
|
|
5058
5070
|
if (!order)
|
|
5059
5071
|
throw new Error("unknown tie_breaker");
|
package/dist/index.d.cts
CHANGED
|
@@ -88,6 +88,17 @@ interface CanOptions {
|
|
|
88
88
|
baseUrl?: string;
|
|
89
89
|
/** AbortSignal to cancel the request. */
|
|
90
90
|
signal?: AbortSignal;
|
|
91
|
+
/** Who is asking, recorded on the transcript (sent as X-Nomos-Agent / -Acts-For / -Purpose).
|
|
92
|
+
* `purpose: 'test'` queries are answered and sealed but kept out of the authority's public
|
|
93
|
+
* history and counts — set it from tests and CI. Exchange authorities only. */
|
|
94
|
+
caller?: CanCaller;
|
|
95
|
+
}
|
|
96
|
+
interface CanCaller {
|
|
97
|
+
/** A stable name for your agent, e.g. "acme-credit-agent". */
|
|
98
|
+
agent_id?: string;
|
|
99
|
+
/** The organisation it acts for. Ignored when the request carries an API key (the key's account is used). */
|
|
100
|
+
acts_for?: string;
|
|
101
|
+
purpose?: 'production' | 'test';
|
|
91
102
|
}
|
|
92
103
|
interface CanResult {
|
|
93
104
|
/** True only for an AUTHORIZED verdict. DENIED and ESCALATED are both `false`. */
|
|
@@ -411,6 +422,8 @@ interface RequestOptions {
|
|
|
411
422
|
idempotencyKey?: string;
|
|
412
423
|
/** Per-request API key — useful for multi-tenant platforms */
|
|
413
424
|
apiKey?: string;
|
|
425
|
+
/** Extra request headers. */
|
|
426
|
+
headers?: Record<string, string>;
|
|
414
427
|
}
|
|
415
428
|
interface NomosRawResponse {
|
|
416
429
|
/** x-request-id header value — include in support tickets */
|
|
@@ -1622,4 +1635,4 @@ declare function approver(o: ApproverOptions): {
|
|
|
1622
1635
|
pending: Map<string, Pending>;
|
|
1623
1636
|
};
|
|
1624
1637
|
|
|
1625
|
-
export { ACT_MEDIA_TYPE, type AcceptOptions, type AcceptStore, type AcceptTransaction, type AcceptedAuthority, type KeyCertificate as ActKeyCertificate, type ActOptions, type ActResult, type ActStatus, type Action, type Answer, type ApproverOptions, type Artifact, type ArtifactList, type ArtifactSchema, type ArtifactSchemaField, type AttestationInfo, type BindingProposal, type BindingSuggestion, type BuildActOptions, type CanOptions, type CanParams, type CanResult, type CanVerdict, type CertificateRegistry, type ChainVerdictDecision, type ConservedStateInfo, type ConservedStateReceipt, type Contradiction, type DetectContradictionsParams, type DetectContradictionsResult, type EnrolmentClaims, type FactBinding, type GenerateGovernanceParams, type GenerateGovernanceResult, type IssueOptions, type IssuerDocument, type IssuerOptions, type KeyCertificate$1 as KeyCertificate, type ListArtifactsParams, MAX_PRESENTED, Nomos, NomosAPIError, NomosActError, NomosAuthenticationError, NomosAuthorizationError, type NomosConfig, NomosDiscoveryError, NomosError, type NomosErrorCode, NomosIssuerNotTrustedError, NomosNetworkError, NomosNotFoundError, NomosPaymentRequiredError, NomosRateLimitError, type NomosRawResponse, NomosValidationError, type NomosWebhookEvent, type NomosWebhookEventType, NomosWebhookSignatureError, type PasskeyApproverOptions, type PasskeyCredential, type PasskeyStore, type PendingApproval, type PgClient, type PgPool, type PolicyField, type PostgresStoreOptions, type Receipt, RegistryError, type RegistryStore, type RelyingPartyDocument, type RequestOptions, type Reservation, type ReserveByActParams, type ReserveByQueryParams, type ReserveParams, type RevocationSourceOptions, RevocationUnavailable, type SignatureSuite, type Signer, type ToolBindings, type ToolDescription, type UnresolvedFact, type Verdict, type VerifyChainOptions, type VerifyChainParams, type VerifyChainResult, type VerifyDecisionParams, type VerifyDecisionResult, WELL_KNOWN, type WithLastResponse, type WitnessDocument, type WitnessOptions, accept, act, applyToolBindings, approver, buildAct, can, certificateRegistry, certify, describeSuggestion, fetchDocument, generateSigner, issuer, kidOf, localSigner, memoryPasskeyStore, memoryRegistryStore, memoryStore, nomos, originOf, parseToolBindings, passkeyApprover, postgresPasskeyStore, postgresRegistryStore, postgresStore, presentedCertificates, readAttestation, reliedKids, revocationListCertificates, revocationSource, seal, seededSigner, signConsent, signEnrolmentToken, signInForce, signRevocation, signRevocationList, signTestimony, statusFor, suggestToolBindings, verifyChain, verifyEnrolmentToken, witness };
|
|
1638
|
+
export { ACT_MEDIA_TYPE, type AcceptOptions, type AcceptStore, type AcceptTransaction, type AcceptedAuthority, type KeyCertificate as ActKeyCertificate, type ActOptions, type ActResult, type ActStatus, type Action, type Answer, type ApproverOptions, type Artifact, type ArtifactList, type ArtifactSchema, type ArtifactSchemaField, type AttestationInfo, type BindingProposal, type BindingSuggestion, type BuildActOptions, type CanCaller, type CanOptions, type CanParams, type CanResult, type CanVerdict, type CertificateRegistry, type ChainVerdictDecision, type ConservedStateInfo, type ConservedStateReceipt, type Contradiction, type DetectContradictionsParams, type DetectContradictionsResult, type EnrolmentClaims, type FactBinding, type GenerateGovernanceParams, type GenerateGovernanceResult, type IssueOptions, type IssuerDocument, type IssuerOptions, type KeyCertificate$1 as KeyCertificate, type ListArtifactsParams, MAX_PRESENTED, Nomos, NomosAPIError, NomosActError, NomosAuthenticationError, NomosAuthorizationError, type NomosConfig, NomosDiscoveryError, NomosError, type NomosErrorCode, NomosIssuerNotTrustedError, NomosNetworkError, NomosNotFoundError, NomosPaymentRequiredError, NomosRateLimitError, type NomosRawResponse, NomosValidationError, type NomosWebhookEvent, type NomosWebhookEventType, NomosWebhookSignatureError, type PasskeyApproverOptions, type PasskeyCredential, type PasskeyStore, type PendingApproval, type PgClient, type PgPool, type PolicyField, type PostgresStoreOptions, type Receipt, RegistryError, type RegistryStore, type RelyingPartyDocument, type RequestOptions, type Reservation, type ReserveByActParams, type ReserveByQueryParams, type ReserveParams, type RevocationSourceOptions, RevocationUnavailable, type SignatureSuite, type Signer, type ToolBindings, type ToolDescription, type UnresolvedFact, type Verdict, type VerifyChainOptions, type VerifyChainParams, type VerifyChainResult, type VerifyDecisionParams, type VerifyDecisionResult, WELL_KNOWN, type WithLastResponse, type WitnessDocument, type WitnessOptions, accept, act, applyToolBindings, approver, buildAct, can, certificateRegistry, certify, describeSuggestion, fetchDocument, generateSigner, issuer, kidOf, localSigner, memoryPasskeyStore, memoryRegistryStore, memoryStore, nomos, originOf, parseToolBindings, passkeyApprover, postgresPasskeyStore, postgresRegistryStore, postgresStore, presentedCertificates, readAttestation, reliedKids, revocationListCertificates, revocationSource, seal, seededSigner, signConsent, signEnrolmentToken, signInForce, signRevocation, signRevocationList, signTestimony, statusFor, suggestToolBindings, verifyChain, verifyEnrolmentToken, witness };
|
package/dist/index.d.ts
CHANGED
|
@@ -88,6 +88,17 @@ interface CanOptions {
|
|
|
88
88
|
baseUrl?: string;
|
|
89
89
|
/** AbortSignal to cancel the request. */
|
|
90
90
|
signal?: AbortSignal;
|
|
91
|
+
/** Who is asking, recorded on the transcript (sent as X-Nomos-Agent / -Acts-For / -Purpose).
|
|
92
|
+
* `purpose: 'test'` queries are answered and sealed but kept out of the authority's public
|
|
93
|
+
* history and counts — set it from tests and CI. Exchange authorities only. */
|
|
94
|
+
caller?: CanCaller;
|
|
95
|
+
}
|
|
96
|
+
interface CanCaller {
|
|
97
|
+
/** A stable name for your agent, e.g. "acme-credit-agent". */
|
|
98
|
+
agent_id?: string;
|
|
99
|
+
/** The organisation it acts for. Ignored when the request carries an API key (the key's account is used). */
|
|
100
|
+
acts_for?: string;
|
|
101
|
+
purpose?: 'production' | 'test';
|
|
91
102
|
}
|
|
92
103
|
interface CanResult {
|
|
93
104
|
/** True only for an AUTHORIZED verdict. DENIED and ESCALATED are both `false`. */
|
|
@@ -411,6 +422,8 @@ interface RequestOptions {
|
|
|
411
422
|
idempotencyKey?: string;
|
|
412
423
|
/** Per-request API key — useful for multi-tenant platforms */
|
|
413
424
|
apiKey?: string;
|
|
425
|
+
/** Extra request headers. */
|
|
426
|
+
headers?: Record<string, string>;
|
|
414
427
|
}
|
|
415
428
|
interface NomosRawResponse {
|
|
416
429
|
/** x-request-id header value — include in support tickets */
|
|
@@ -1622,4 +1635,4 @@ declare function approver(o: ApproverOptions): {
|
|
|
1622
1635
|
pending: Map<string, Pending>;
|
|
1623
1636
|
};
|
|
1624
1637
|
|
|
1625
|
-
export { ACT_MEDIA_TYPE, type AcceptOptions, type AcceptStore, type AcceptTransaction, type AcceptedAuthority, type KeyCertificate as ActKeyCertificate, type ActOptions, type ActResult, type ActStatus, type Action, type Answer, type ApproverOptions, type Artifact, type ArtifactList, type ArtifactSchema, type ArtifactSchemaField, type AttestationInfo, type BindingProposal, type BindingSuggestion, type BuildActOptions, type CanOptions, type CanParams, type CanResult, type CanVerdict, type CertificateRegistry, type ChainVerdictDecision, type ConservedStateInfo, type ConservedStateReceipt, type Contradiction, type DetectContradictionsParams, type DetectContradictionsResult, type EnrolmentClaims, type FactBinding, type GenerateGovernanceParams, type GenerateGovernanceResult, type IssueOptions, type IssuerDocument, type IssuerOptions, type KeyCertificate$1 as KeyCertificate, type ListArtifactsParams, MAX_PRESENTED, Nomos, NomosAPIError, NomosActError, NomosAuthenticationError, NomosAuthorizationError, type NomosConfig, NomosDiscoveryError, NomosError, type NomosErrorCode, NomosIssuerNotTrustedError, NomosNetworkError, NomosNotFoundError, NomosPaymentRequiredError, NomosRateLimitError, type NomosRawResponse, NomosValidationError, type NomosWebhookEvent, type NomosWebhookEventType, NomosWebhookSignatureError, type PasskeyApproverOptions, type PasskeyCredential, type PasskeyStore, type PendingApproval, type PgClient, type PgPool, type PolicyField, type PostgresStoreOptions, type Receipt, RegistryError, type RegistryStore, type RelyingPartyDocument, type RequestOptions, type Reservation, type ReserveByActParams, type ReserveByQueryParams, type ReserveParams, type RevocationSourceOptions, RevocationUnavailable, type SignatureSuite, type Signer, type ToolBindings, type ToolDescription, type UnresolvedFact, type Verdict, type VerifyChainOptions, type VerifyChainParams, type VerifyChainResult, type VerifyDecisionParams, type VerifyDecisionResult, WELL_KNOWN, type WithLastResponse, type WitnessDocument, type WitnessOptions, accept, act, applyToolBindings, approver, buildAct, can, certificateRegistry, certify, describeSuggestion, fetchDocument, generateSigner, issuer, kidOf, localSigner, memoryPasskeyStore, memoryRegistryStore, memoryStore, nomos, originOf, parseToolBindings, passkeyApprover, postgresPasskeyStore, postgresRegistryStore, postgresStore, presentedCertificates, readAttestation, reliedKids, revocationListCertificates, revocationSource, seal, seededSigner, signConsent, signEnrolmentToken, signInForce, signRevocation, signRevocationList, signTestimony, statusFor, suggestToolBindings, verifyChain, verifyEnrolmentToken, witness };
|
|
1638
|
+
export { ACT_MEDIA_TYPE, type AcceptOptions, type AcceptStore, type AcceptTransaction, type AcceptedAuthority, type KeyCertificate as ActKeyCertificate, type ActOptions, type ActResult, type ActStatus, type Action, type Answer, type ApproverOptions, type Artifact, type ArtifactList, type ArtifactSchema, type ArtifactSchemaField, type AttestationInfo, type BindingProposal, type BindingSuggestion, type BuildActOptions, type CanCaller, type CanOptions, type CanParams, type CanResult, type CanVerdict, type CertificateRegistry, type ChainVerdictDecision, type ConservedStateInfo, type ConservedStateReceipt, type Contradiction, type DetectContradictionsParams, type DetectContradictionsResult, type EnrolmentClaims, type FactBinding, type GenerateGovernanceParams, type GenerateGovernanceResult, type IssueOptions, type IssuerDocument, type IssuerOptions, type KeyCertificate$1 as KeyCertificate, type ListArtifactsParams, MAX_PRESENTED, Nomos, NomosAPIError, NomosActError, NomosAuthenticationError, NomosAuthorizationError, type NomosConfig, NomosDiscoveryError, NomosError, type NomosErrorCode, NomosIssuerNotTrustedError, NomosNetworkError, NomosNotFoundError, NomosPaymentRequiredError, NomosRateLimitError, type NomosRawResponse, NomosValidationError, type NomosWebhookEvent, type NomosWebhookEventType, NomosWebhookSignatureError, type PasskeyApproverOptions, type PasskeyCredential, type PasskeyStore, type PendingApproval, type PgClient, type PgPool, type PolicyField, type PostgresStoreOptions, type Receipt, RegistryError, type RegistryStore, type RelyingPartyDocument, type RequestOptions, type Reservation, type ReserveByActParams, type ReserveByQueryParams, type ReserveParams, type RevocationSourceOptions, RevocationUnavailable, type SignatureSuite, type Signer, type ToolBindings, type ToolDescription, type UnresolvedFact, type Verdict, type VerifyChainOptions, type VerifyChainParams, type VerifyChainResult, type VerifyDecisionParams, type VerifyDecisionResult, WELL_KNOWN, type WithLastResponse, type WitnessDocument, type WitnessOptions, accept, act, applyToolBindings, approver, buildAct, can, certificateRegistry, certify, describeSuggestion, fetchDocument, generateSigner, issuer, kidOf, localSigner, memoryPasskeyStore, memoryRegistryStore, memoryStore, nomos, originOf, parseToolBindings, passkeyApprover, postgresPasskeyStore, postgresRegistryStore, postgresStore, presentedCertificates, readAttestation, reliedKids, revocationListCertificates, revocationSource, seal, seededSigner, signConsent, signEnrolmentToken, signInForce, signRevocation, signRevocationList, signTestimony, statusFor, suggestToolBindings, verifyChain, verifyEnrolmentToken, witness };
|
package/dist/index.js
CHANGED
|
@@ -107,7 +107,7 @@ function isRetryable(status) {
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
// src/http-client.ts
|
|
110
|
-
var SDK_VERSION = "2.3.
|
|
110
|
+
var SDK_VERSION = "2.3.2";
|
|
111
111
|
var HttpClient = class {
|
|
112
112
|
constructor(opts) {
|
|
113
113
|
this.opts = opts;
|
|
@@ -131,6 +131,7 @@ var HttpClient = class {
|
|
|
131
131
|
"User-Agent": `nomos-node/${SDK_VERSION}`,
|
|
132
132
|
"NOMOS-SDK-Version": SDK_VERSION
|
|
133
133
|
};
|
|
134
|
+
if (reqOpts?.headers) Object.assign(headers, reqOpts.headers);
|
|
134
135
|
if (reqOpts?.idempotencyKey) {
|
|
135
136
|
headers["Idempotency-Key"] = reqOpts.idempotencyKey;
|
|
136
137
|
}
|
|
@@ -639,6 +640,13 @@ function normalizeAuthorityQueryResult(data, authority) {
|
|
|
639
640
|
...data.revoked === true ? { revoked: true, revocation_reason: data.revocation_reason } : {}
|
|
640
641
|
};
|
|
641
642
|
}
|
|
643
|
+
function callerHeaders(c) {
|
|
644
|
+
const h = {};
|
|
645
|
+
if (c?.agent_id) h["X-Nomos-Agent"] = c.agent_id;
|
|
646
|
+
if (c?.acts_for) h["X-Nomos-Acts-For"] = c.acts_for;
|
|
647
|
+
if (c?.purpose) h["X-Nomos-Purpose"] = c.purpose;
|
|
648
|
+
return h;
|
|
649
|
+
}
|
|
642
650
|
async function canViaExchange(authority, facts, action, opts) {
|
|
643
651
|
const base = (opts?.baseUrl ?? DEFAULT_EXCHANGE_BASE).replace(/\/$/, "");
|
|
644
652
|
const url = `${base}/api/v1/can`;
|
|
@@ -646,7 +654,7 @@ async function canViaExchange(authority, facts, action, opts) {
|
|
|
646
654
|
try {
|
|
647
655
|
res = await fetch(url, {
|
|
648
656
|
method: "POST",
|
|
649
|
-
headers: { "Content-Type": "application/json" },
|
|
657
|
+
headers: { "Content-Type": "application/json", "User-Agent": `nomos-node/${SDK_VERSION}`, ...callerHeaders(opts?.caller) },
|
|
650
658
|
body: JSON.stringify({ artifact: authority, action, ...facts }),
|
|
651
659
|
signal: opts?.signal
|
|
652
660
|
});
|
|
@@ -659,8 +667,8 @@ async function canViaExchange(authority, facts, action, opts) {
|
|
|
659
667
|
if (!res.ok) mapHttpError(res.status, data, requestId);
|
|
660
668
|
return normalizeAuthorityQueryResult(data, authority);
|
|
661
669
|
}
|
|
662
|
-
async function canViaExchangeAuthenticated(http, authority, facts, action) {
|
|
663
|
-
const { data } = await http.post("/api/v1/can", { artifact: authority, action, ...facts });
|
|
670
|
+
async function canViaExchangeAuthenticated(http, authority, facts, action, caller) {
|
|
671
|
+
const { data } = await http.post("/api/v1/can", { artifact: authority, action, ...facts }, { headers: callerHeaders(caller) });
|
|
664
672
|
return normalizeAuthorityQueryResult(data, authority);
|
|
665
673
|
}
|
|
666
674
|
async function canViaArtifact(http, artifactId, facts, action) {
|
|
@@ -757,7 +765,6 @@ async function can(params, opts) {
|
|
|
757
765
|
return canViaExchange(params.authority, facts, action, opts);
|
|
758
766
|
}
|
|
759
767
|
async function canAuthenticated(http, params, opts) {
|
|
760
|
-
void opts;
|
|
761
768
|
const { facts, action } = splitFacts(params);
|
|
762
769
|
if (params.artifact !== void 0) {
|
|
763
770
|
if (!params.key_certs || !params.root_public_key_pem) {
|
|
@@ -766,7 +773,7 @@ async function canAuthenticated(http, params, opts) {
|
|
|
766
773
|
return canViaChain(params.artifact, params.key_certs, params.root_public_key_pem, facts, action, opts);
|
|
767
774
|
}
|
|
768
775
|
if (params.artifact_id) return canViaArtifact(http, params.artifact_id, facts, action);
|
|
769
|
-
if (params.authority) return canViaExchangeAuthenticated(http, params.authority, facts, action);
|
|
776
|
+
if (params.authority) return canViaExchangeAuthenticated(http, params.authority, facts, action, opts?.caller);
|
|
770
777
|
throw new Error("can(): `authority` (a public Exchange artifact), `artifact_id` (your own artifact), or `artifact` (chain-of-trust) is required.");
|
|
771
778
|
}
|
|
772
779
|
var nomos = { can };
|
|
@@ -4967,9 +4974,14 @@ var TIE_ORDERS = {
|
|
|
4967
4974
|
function evaluate(artifact, facts) {
|
|
4968
4975
|
const logic = artifact.logic;
|
|
4969
4976
|
const res = logic.resolution ?? {};
|
|
4970
|
-
|
|
4971
|
-
if (!Array.isArray(decisions))
|
|
4977
|
+
if (!Array.isArray(logic.decisions))
|
|
4972
4978
|
throw new Error("logic.decisions missing");
|
|
4979
|
+
const declared = new Set(Object.keys(artifact.execution?.actions ?? {}));
|
|
4980
|
+
const isObligation = (d) => {
|
|
4981
|
+
const t = d?.then?.[0];
|
|
4982
|
+
return t?.type === "emit" || t?.type === "action" && declared.has(t?.action_name);
|
|
4983
|
+
};
|
|
4984
|
+
const decisions = logic.decisions.filter((d) => !isObligation(d));
|
|
4973
4985
|
const order = TIE_ORDERS[res.tie_breaker ?? "deny_wins"];
|
|
4974
4986
|
if (!order)
|
|
4975
4987
|
throw new Error("unknown tie_breaker");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nomosprotocol/sdk",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.2",
|
|
4
4
|
"description": "NOMOS for TypeScript: accept() for the system that makes a change, act() for the agent that asks, the issuer, witness and approver roles, and the Exchange client. Verification is local (@nomosprotocol/verify).",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -64,6 +64,13 @@
|
|
|
64
64
|
],
|
|
65
65
|
"author": "NOMOS",
|
|
66
66
|
"license": "MIT",
|
|
67
|
+
"repository": {
|
|
68
|
+
"type": "git",
|
|
69
|
+
"url": "git+https://github.com/nomos-spec/spec.git"
|
|
70
|
+
},
|
|
71
|
+
"bugs": {
|
|
72
|
+
"url": "https://github.com/nomos-spec/spec/issues"
|
|
73
|
+
},
|
|
67
74
|
"engines": {
|
|
68
75
|
"node": ">=20"
|
|
69
76
|
},
|
|
@@ -74,6 +81,6 @@
|
|
|
74
81
|
"dependencies": {
|
|
75
82
|
"@noble/curves": "^2.4.0",
|
|
76
83
|
"@noble/hashes": "^2.4.0",
|
|
77
|
-
"@nomosprotocol/verify": "^1.
|
|
84
|
+
"@nomosprotocol/verify": "^1.3.0"
|
|
78
85
|
}
|
|
79
86
|
}
|