@appport/integration 0.0.0-stage → 1.2.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/LICENSE +126 -0
- package/README.md +35 -2
- package/dist/base64url.d.ts +4 -0
- package/dist/base64url.d.ts.map +1 -0
- package/dist/base64url.js +36 -0
- package/dist/base64url.js.map +1 -0
- package/dist/behavior.d.ts +164 -0
- package/dist/behavior.d.ts.map +1 -0
- package/dist/behavior.js +493 -0
- package/dist/behavior.js.map +1 -0
- package/dist/coverage.d.ts +44 -0
- package/dist/coverage.d.ts.map +1 -0
- package/dist/coverage.js +43 -0
- package/dist/coverage.js.map +1 -0
- package/dist/declarations.d.ts +53 -0
- package/dist/declarations.d.ts.map +1 -0
- package/dist/declarations.js +45 -0
- package/dist/declarations.js.map +1 -0
- package/dist/ed25519.d.ts +8 -0
- package/dist/ed25519.d.ts.map +1 -0
- package/dist/ed25519.js +128 -0
- package/dist/ed25519.js.map +1 -0
- package/dist/encodings.d.ts +9 -0
- package/dist/encodings.d.ts.map +1 -0
- package/dist/encodings.js +75 -0
- package/dist/encodings.js.map +1 -0
- package/dist/fields.d.ts +29 -0
- package/dist/fields.d.ts.map +1 -0
- package/dist/fields.js +76 -0
- package/dist/fields.js.map +1 -0
- package/dist/findings.d.ts +189 -0
- package/dist/findings.d.ts.map +1 -0
- package/dist/findings.js +195 -0
- package/dist/findings.js.map +1 -0
- package/dist/footprint.d.ts +67 -0
- package/dist/footprint.d.ts.map +1 -0
- package/dist/footprint.js +78 -0
- package/dist/footprint.js.map +1 -0
- package/dist/graph.d.ts +111 -0
- package/dist/graph.d.ts.map +1 -0
- package/dist/graph.js +396 -0
- package/dist/graph.js.map +1 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -0
- package/dist/lint.d.ts +57 -0
- package/dist/lint.d.ts.map +1 -0
- package/dist/lint.js +281 -0
- package/dist/lint.js.map +1 -0
- package/dist/mapping.d.ts +28 -0
- package/dist/mapping.d.ts.map +1 -0
- package/dist/mapping.js +282 -0
- package/dist/mapping.js.map +1 -0
- package/dist/normalize.d.ts +27 -0
- package/dist/normalize.d.ts.map +1 -0
- package/dist/normalize.js +56 -0
- package/dist/normalize.js.map +1 -0
- package/dist/plan.d.ts +240 -0
- package/dist/plan.d.ts.map +1 -0
- package/dist/plan.js +746 -0
- package/dist/plan.js.map +1 -0
- package/dist/readiness.d.ts +146 -0
- package/dist/readiness.d.ts.map +1 -0
- package/dist/readiness.js +346 -0
- package/dist/readiness.js.map +1 -0
- package/dist/reference.d.ts +39 -0
- package/dist/reference.d.ts.map +1 -0
- package/dist/reference.js +74 -0
- package/dist/reference.js.map +1 -0
- package/dist/scenario.d.ts +114 -0
- package/dist/scenario.d.ts.map +1 -0
- package/dist/scenario.js +117 -0
- package/dist/scenario.js.map +1 -0
- package/dist/select.d.ts +41 -0
- package/dist/select.d.ts.map +1 -0
- package/dist/select.js +71 -0
- package/dist/select.js.map +1 -0
- package/dist/trust.d.ts +237 -0
- package/dist/trust.d.ts.map +1 -0
- package/dist/trust.js +511 -0
- package/dist/trust.js.map +1 -0
- package/dist/types.d.ts +130 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +19 -0
- package/dist/types.js.map +1 -0
- package/dist/units.d.ts +20 -0
- package/dist/units.d.ts.map +1 -0
- package/dist/units.js +47 -0
- package/dist/units.js.map +1 -0
- package/dist/verification.d.ts +54 -0
- package/dist/verification.d.ts.map +1 -0
- package/dist/verification.js +115 -0
- package/dist/verification.js.map +1 -0
- package/package.json +28 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coverage.d.ts","sourceRoot":"","sources":["../src/coverage.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,WAAW,mBAAmB;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,6EAA6E;IAC7E,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,2EAA2E;IAC3E,kBAAkB,EAAE,OAAO,CAAC;IAC5B,mEAAmE;IACnE,aAAa,EAAE,OAAO,CAAC;IACvB,8GAA8G;IAC9G,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,yBAAyB;IACzB,QAAQ,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;IACvC,+HAA+H;IAC/H,wBAAwB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC9C;AAED,6EAA6E;AAC7E,eAAO,MAAM,iBAAiB,EAAE,SAAS,MAAM,EAM9C,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,mBAAmB,GAAG,MAAM,EAAE,CASxE;AAED,gFAAgF;AAChF,MAAM,WAAW,kBAAkB;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;IAC/B,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,QAAQ,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;IACvC,sEAAsE;IACtE,KAAK,EAAE,yCAAyC,CAAC;CAClD;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,mBAAmB,GAAG,kBAAkB,CAkBnF"}
|
package/dist/coverage.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/** Paths no AppPort boundary observes, always reported with any coverage. */
|
|
2
|
+
export const ALWAYS_UNOBSERVED = [
|
|
3
|
+
"calls made with a handler's own HTTP or service clients",
|
|
4
|
+
"reads and writes through context.db",
|
|
5
|
+
"anything reached through context.services",
|
|
6
|
+
"direct database access by any code",
|
|
7
|
+
"external side effects (email, payments, files, queues)"
|
|
8
|
+
];
|
|
9
|
+
export function validateCoverage(coverage) {
|
|
10
|
+
const issues = [];
|
|
11
|
+
if (!coverage.application)
|
|
12
|
+
issues.push("application is required");
|
|
13
|
+
const [from, to] = [Date.parse(coverage.interval?.from), Date.parse(coverage.interval?.to)];
|
|
14
|
+
if (Number.isNaN(from) || Number.isNaN(to))
|
|
15
|
+
issues.push("interval needs ISO-8601 from and to");
|
|
16
|
+
else if (to < from)
|
|
17
|
+
issues.push("interval ends before it starts");
|
|
18
|
+
if (!coverage.invocationBoundary && !coverage.stateBoundary)
|
|
19
|
+
issues.push("no boundary was instrumented: this says nothing");
|
|
20
|
+
if (coverage.stateMappingConfigured && !coverage.stateBoundary)
|
|
21
|
+
issues.push("a state mapping without an instrumented state boundary observes nothing");
|
|
22
|
+
return issues;
|
|
23
|
+
}
|
|
24
|
+
export function summarizeCoverage(coverage) {
|
|
25
|
+
const through = [
|
|
26
|
+
...(coverage.invocationBoundary ? ["mediated invocations (context.invoke / CapabilityInvoker)"] : []),
|
|
27
|
+
...(coverage.stateBoundary ? [coverage.stateMappingConfigured ? "mediated state (journaled, with owner-declared resource mapping)" : "mediated state (journaled, no resource mapping: all access unclassified)"] : [])
|
|
28
|
+
];
|
|
29
|
+
return {
|
|
30
|
+
application: coverage.application,
|
|
31
|
+
capabilities: coverage.capabilities ? [...coverage.capabilities].sort() : "all",
|
|
32
|
+
observedThrough: through,
|
|
33
|
+
notObserved: [
|
|
34
|
+
...(coverage.invocationBoundary ? [] : ["mediated invocations"]),
|
|
35
|
+
...(coverage.stateBoundary ? [] : ["mediated state access"]),
|
|
36
|
+
...ALWAYS_UNOBSERVED,
|
|
37
|
+
...(coverage.knownUninstrumentedPaths ?? [])
|
|
38
|
+
],
|
|
39
|
+
interval: { ...coverage.interval },
|
|
40
|
+
claim: "observed-through-listed-boundaries-only"
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=coverage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coverage.js","sourceRoot":"","sources":["../src/coverage.ts"],"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CAAC,CAAC,CAAC,QAAQ,CAAC,sBAAsB,CAAC,CAAC,CAAC,kEAAkE,CAAC,CAAC,CAAC,0EAA0E,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;KACvN,CAAC;IACF,OAAO;QACL,WAAW,EAAE,QAAQ,CAAC,WAAW;QACjC,YAAY,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,KAAK;QAC/E,eAAe,EAAE,OAAO;QACxB,WAAW,EAAE;YACX,GAAG,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC;YAChE,GAAG,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC;YAC5D,GAAG,iBAAiB;YACpB,GAAG,CAAC,QAAQ,CAAC,wBAAwB,IAAI,EAAE,CAAC;SAC7C;QACD,QAAQ,EAAE,EAAE,GAAG,QAAQ,CAAC,QAAQ,EAAE;QAClC,KAAK,EAAE,yCAAyC;KACjD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a published contract says about one capability, and, as importantly, what it leaves unsaid.
|
|
3
|
+
*
|
|
4
|
+
* Every facet carries an *information state*. The states are the whole point: a consumer that
|
|
5
|
+
* collapses "unknown" into "none" will skip an approval, retry a charge or call a write a read.
|
|
6
|
+
*
|
|
7
|
+
* - `declared`: the contract states it.
|
|
8
|
+
* - `declared-absence`: the contract states that there is none (e.g. `coverage.access: "complete"` and no access listed).
|
|
9
|
+
* - `unknown`: the contract is silent. It is *not* evidence of absence.
|
|
10
|
+
* - `incompatible`: the contract states something that conflicts with the task or another contract.
|
|
11
|
+
* - `requires-observation`: only runtime evidence can answer it; no contract could.
|
|
12
|
+
*
|
|
13
|
+
* `classifyDeclarations` is deliberately small and has no dependencies, so an independent
|
|
14
|
+
* implementation in another language can reproduce it from `conformance/fixtures/discovery/`.
|
|
15
|
+
*/
|
|
16
|
+
import type { CapabilityIntegration, CapabilityVersionEntry } from "@appport/protocol";
|
|
17
|
+
export declare const INFORMATION_STATES: readonly ["declared", "declared-absence", "unknown", "incompatible", "requires-observation"];
|
|
18
|
+
export type InformationState = (typeof INFORMATION_STATES)[number];
|
|
19
|
+
/** How an agent may treat a repeated invocation, derived only from published fields. */
|
|
20
|
+
export type RetryDisposition = "safe" | "safe-with-idempotency-key" | "unsafe" | "unknown";
|
|
21
|
+
export interface Facet<T = undefined> {
|
|
22
|
+
state: InformationState;
|
|
23
|
+
value?: T;
|
|
24
|
+
}
|
|
25
|
+
export interface DeclarationFacts {
|
|
26
|
+
effect: Facet<"observation" | "consequential">;
|
|
27
|
+
authorization: Facet<{
|
|
28
|
+
mode: "public";
|
|
29
|
+
} | {
|
|
30
|
+
mode: "scoped";
|
|
31
|
+
scopes: string[];
|
|
32
|
+
}>;
|
|
33
|
+
approval: Facet<{
|
|
34
|
+
required: boolean;
|
|
35
|
+
approver?: string;
|
|
36
|
+
}>;
|
|
37
|
+
idempotency: Facet<"supported" | "unsupported">;
|
|
38
|
+
/** Derived. Never `safe` unless the contract declares the capability an observation. */
|
|
39
|
+
retry: RetryDisposition;
|
|
40
|
+
verification: Facet<{
|
|
41
|
+
state: number;
|
|
42
|
+
event: number;
|
|
43
|
+
}>;
|
|
44
|
+
preconditions: Facet<number>;
|
|
45
|
+
failures: Facet<number>;
|
|
46
|
+
access: Facet<number>;
|
|
47
|
+
requires: Facet<number>;
|
|
48
|
+
}
|
|
49
|
+
type Entry = Pick<CapabilityIntegration, "approval" | "preconditions" | "failures" | "verify" | "access" | "requires" | "coverage"> | undefined;
|
|
50
|
+
type Definition = Pick<CapabilityVersionEntry, "effect" | "authorizationContract" | "idempotency">;
|
|
51
|
+
export declare function classifyDeclarations(definition: Definition, entry: Entry): DeclarationFacts;
|
|
52
|
+
export {};
|
|
53
|
+
//# sourceMappingURL=declarations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"declarations.d.ts","sourceRoot":"","sources":["../src/declarations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAEvF,eAAO,MAAM,kBAAkB,8FAA+F,CAAC;AAC/H,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEnE,wFAAwF;AACxF,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,2BAA2B,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE3F,MAAM,WAAW,KAAK,CAAC,CAAC,GAAG,SAAS;IAClC,KAAK,EAAE,gBAAgB,CAAC;IACxB,KAAK,CAAC,EAAE,CAAC,CAAC;CACX;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,KAAK,CAAC,aAAa,GAAG,eAAe,CAAC,CAAC;IAC/C,aAAa,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,QAAQ,CAAA;KAAE,GAAG;QAAE,IAAI,EAAE,QAAQ,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAAC;IAChF,QAAQ,EAAE,KAAK,CAAC;QAAE,QAAQ,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC1D,WAAW,EAAE,KAAK,CAAC,WAAW,GAAG,aAAa,CAAC,CAAC;IAChD,wFAAwF;IACxF,KAAK,EAAE,gBAAgB,CAAC;IACxB,YAAY,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACtD,aAAa,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC7B,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACxB,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACtB,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CACzB;AAED,KAAK,KAAK,GAAG,IAAI,CAAC,qBAAqB,EAAE,UAAU,GAAG,eAAe,GAAG,UAAU,GAAG,QAAQ,GAAG,QAAQ,GAAG,UAAU,GAAG,UAAU,CAAC,GAAG,SAAS,CAAC;AAChJ,KAAK,UAAU,GAAG,IAAI,CAAC,sBAAsB,EAAE,QAAQ,GAAG,uBAAuB,GAAG,aAAa,CAAC,CAAC;AAQnG,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,GAAG,gBAAgB,CAyC3F"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export const INFORMATION_STATES = ["declared", "declared-absence", "unknown", "incompatible", "requires-observation"];
|
|
2
|
+
/** A list whose absence is only meaningful when the publisher claimed the list is complete. */
|
|
3
|
+
function listFacet(list, complete) {
|
|
4
|
+
if (list && list.length > 0)
|
|
5
|
+
return { state: "declared", value: list.length };
|
|
6
|
+
return { state: complete ? "declared-absence" : "unknown" };
|
|
7
|
+
}
|
|
8
|
+
export function classifyDeclarations(definition, entry) {
|
|
9
|
+
const effect = definition.effect ? { state: "declared", value: definition.effect } : { state: "unknown" };
|
|
10
|
+
const contract = definition.authorizationContract;
|
|
11
|
+
const authorization = !contract
|
|
12
|
+
? { state: "unknown" }
|
|
13
|
+
: contract.required
|
|
14
|
+
? { state: "declared", value: { mode: "scoped", scopes: [...contract.scopes] } }
|
|
15
|
+
: { state: "declared", value: { mode: "public" } };
|
|
16
|
+
const approval = entry?.approval
|
|
17
|
+
? { state: "declared", value: { required: entry.approval.required, ...(entry.approval.approver ? { approver: entry.approval.approver } : {}) } }
|
|
18
|
+
: { state: "unknown" };
|
|
19
|
+
const idempotency = definition.idempotency ? { state: "declared", value: definition.idempotency } : { state: "unknown" };
|
|
20
|
+
let retry = "unknown";
|
|
21
|
+
if (effect.value === "observation")
|
|
22
|
+
retry = "safe";
|
|
23
|
+
else if (effect.value === "consequential")
|
|
24
|
+
retry = idempotency.value === "supported" ? "safe-with-idempotency-key" : idempotency.value === "unsupported" ? "unsafe" : "unknown";
|
|
25
|
+
const verify = entry?.verify ?? [];
|
|
26
|
+
const verification = verify.length > 0
|
|
27
|
+
? { state: "declared", value: { state: verify.filter((m) => m.kind === "state").length, event: verify.filter((m) => m.kind === "event").length } }
|
|
28
|
+
: effect.value === "observation"
|
|
29
|
+
? { state: "declared-absence" } // a read has no effect to verify
|
|
30
|
+
: { state: "unknown" };
|
|
31
|
+
const complete = (key) => entry?.coverage?.[key] === "complete";
|
|
32
|
+
return {
|
|
33
|
+
effect,
|
|
34
|
+
authorization,
|
|
35
|
+
approval,
|
|
36
|
+
idempotency,
|
|
37
|
+
retry,
|
|
38
|
+
verification,
|
|
39
|
+
preconditions: listFacet(entry?.preconditions, complete("preconditions")),
|
|
40
|
+
failures: listFacet(entry?.failures, complete("failures")),
|
|
41
|
+
access: listFacet(entry?.access, complete("access")),
|
|
42
|
+
requires: listFacet(entry?.requires, complete("requires"))
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=declarations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"declarations.js","sourceRoot":"","sources":["../src/declarations.ts"],"names":[],"mappings":"AAiBA,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,UAAU,EAAE,kBAAkB,EAAE,SAAS,EAAE,cAAc,EAAE,sBAAsB,CAAU,CAAC;AA4B/H,+FAA+F;AAC/F,SAAS,SAAS,CAAC,IAAoC,EAAE,QAAiB;IACxE,IAAI,IAAI,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,IAA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Q;QACR,WAAW;QACX,KAAK;QACL,YAAY;QACZ,aAAa,EAAE,SAAS,CAAC,KAAK,EAAE,aAAa,EAAE,QAAQ,CAAC,eAAe,CAAC,CAAC;QACzE,QAAQ,EAAE,SAAS,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC;QAC1D,MAAM,EAAE,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACpD,QAAQ,EAAE,SAAS,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC;KAC3D,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Why a public key is unusable as a publisher key, or `undefined` if it is a valid, canonical, non-small-order Ed25519 point. */
|
|
2
|
+
export declare function publicKeyProblem(publicKey: Uint8Array): string | undefined;
|
|
3
|
+
/** The strict profile's rejections that precede the cryptographic check. `undefined` means the inputs pass them. */
|
|
4
|
+
export declare function profileProblem(publicKey: Uint8Array, signature: Uint8Array): string | undefined;
|
|
5
|
+
export type Ed25519Verdict = boolean | "unavailable";
|
|
6
|
+
/** Verifies under the strict profile. `"unavailable"` when the runtime cannot do Ed25519 at all (never a success). */
|
|
7
|
+
export declare function verifyEd25519Strict(publicKey: Uint8Array, message: Uint8Array, signature: Uint8Array): Promise<Ed25519Verdict>;
|
|
8
|
+
//# sourceMappingURL=ed25519.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ed25519.d.ts","sourceRoot":"","sources":["../src/ed25519.ts"],"names":[],"mappings":"AAsFA,kIAAkI;AAClI,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,CAM1E;AAED,oHAAoH;AACpH,wBAAgB,cAAc,CAAC,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,CAO/F;AAED,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,aAAa,CAAC;AAErD,sHAAsH;AACtH,wBAAsB,mBAAmB,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,GAAG,OAAO,CAAC,cAAc,CAAC,CAWpI"}
|
package/dist/ed25519.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ed25519 verification for mapping signatures, as a *strict profile* over a vetted primitive.
|
|
3
|
+
*
|
|
4
|
+
* The cryptographic check itself is always the platform's (WebCrypto, backed by the runtime's vetted implementation). This file adds
|
|
5
|
+
* only checks that can make acceptance STRICTER, never looser, so nothing here can turn a forgery into an acceptance:
|
|
6
|
+
*
|
|
7
|
+
* 1. lengths: a 32-byte public key and a 64-byte signature;
|
|
8
|
+
* 2. the public key and the signature's R decode to a point on the curve with a canonical (< p) y coordinate;
|
|
9
|
+
* 3. the signature scalar S is canonical (S < L), so a signature has exactly one valid encoding;
|
|
10
|
+
* 4. the public key is not a small-order point (a key of small order verifies for every message, so it is never a publisher's key).
|
|
11
|
+
*
|
|
12
|
+
* Why a profile: RFC 8032 verifiers legitimately differ on these cases (OpenSSL accepts a small-order key and some non-canonical keys;
|
|
13
|
+
* other libraries reject them). Different answers across languages would let one consumer accept what another refuses. The profile fixes
|
|
14
|
+
* one answer, and `conformance/fixtures/trust/ed25519.json` pins it for every implementation.
|
|
15
|
+
*
|
|
16
|
+
* The arithmetic below is used only for decoding and the small-order test on PUBLIC data; no secret ever passes through it, so its
|
|
17
|
+
* variable-time behaviour is not a confidentiality concern.
|
|
18
|
+
*/
|
|
19
|
+
const P = (1n << 255n) - 19n;
|
|
20
|
+
const L = (1n << 252n) + 27742317777372353535851937790883648493n;
|
|
21
|
+
const D = (((-121665n % P) + P) % P * modInverse(121666n)) % P;
|
|
22
|
+
const SQRT_M1 = modPow(2n, (P - 1n) / 4n);
|
|
23
|
+
function modPow(base, exponent) {
|
|
24
|
+
let result = 1n;
|
|
25
|
+
let b = ((base % P) + P) % P;
|
|
26
|
+
let e = exponent;
|
|
27
|
+
while (e > 0n) {
|
|
28
|
+
if (e & 1n)
|
|
29
|
+
result = (result * b) % P;
|
|
30
|
+
b = (b * b) % P;
|
|
31
|
+
e >>= 1n;
|
|
32
|
+
}
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
function modInverse(a) {
|
|
36
|
+
return modPow(a, P - 2n);
|
|
37
|
+
}
|
|
38
|
+
const littleEndian = (bytes) => {
|
|
39
|
+
let n = 0n;
|
|
40
|
+
for (let i = bytes.length - 1; i >= 0; i--)
|
|
41
|
+
n = (n << 8n) | BigInt(bytes[i]);
|
|
42
|
+
return n;
|
|
43
|
+
};
|
|
44
|
+
/** Decodes a 32-byte point encoding; `undefined` if non-canonical (y >= p) or not on the curve. */
|
|
45
|
+
function decode(bytes) {
|
|
46
|
+
if (bytes.length !== 32)
|
|
47
|
+
return undefined;
|
|
48
|
+
const raw = littleEndian(bytes);
|
|
49
|
+
const sign = raw >> 255n;
|
|
50
|
+
const y = raw & ((1n << 255n) - 1n);
|
|
51
|
+
if (y >= P)
|
|
52
|
+
return undefined; // non-canonical encoding
|
|
53
|
+
const x2 = ((y * y - 1n) * modInverse(D * y * y + 1n)) % P;
|
|
54
|
+
const normalized = ((x2 % P) + P) % P;
|
|
55
|
+
if (normalized === 0n)
|
|
56
|
+
return sign ? undefined : [0n, y, 1n, 0n];
|
|
57
|
+
let x = modPow(normalized, (P + 3n) / 8n);
|
|
58
|
+
if ((x * x - normalized) % P !== 0n)
|
|
59
|
+
x = (x * SQRT_M1) % P;
|
|
60
|
+
if ((x * x - normalized) % P !== 0n)
|
|
61
|
+
return undefined; // not a square: y is not on the curve
|
|
62
|
+
if (BigInt(Number(x & 1n)) !== sign)
|
|
63
|
+
x = P - x;
|
|
64
|
+
return [x, y, 1n, (x * y) % P];
|
|
65
|
+
}
|
|
66
|
+
function add(a, b) {
|
|
67
|
+
const A = (((a[1] - a[0]) * (b[1] - b[0])) % P + P) % P;
|
|
68
|
+
const B = (((a[1] + a[0]) * (b[1] + b[0])) % P + P) % P;
|
|
69
|
+
const C = (2n * a[3] * b[3] * D) % P;
|
|
70
|
+
const Dd = (2n * a[2] * b[2]) % P;
|
|
71
|
+
const E = B - A, F = Dd - C, G = Dd + C, H = B + A;
|
|
72
|
+
return [(E * F) % P, (G * H) % P, (F * G) % P, (E * H) % P];
|
|
73
|
+
}
|
|
74
|
+
function multiply(scalar, point) {
|
|
75
|
+
let result = [0n, 1n, 1n, 0n];
|
|
76
|
+
let addend = point;
|
|
77
|
+
let s = scalar;
|
|
78
|
+
while (s > 0n) {
|
|
79
|
+
if (s & 1n)
|
|
80
|
+
result = add(result, addend);
|
|
81
|
+
addend = add(addend, addend);
|
|
82
|
+
s >>= 1n;
|
|
83
|
+
}
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
const isIdentity = (p) => ((p[0] % P) + P) % P === 0n && (((p[1] - p[2]) % P) + P) % P === 0n;
|
|
87
|
+
/** Why a public key is unusable as a publisher key, or `undefined` if it is a valid, canonical, non-small-order Ed25519 point. */
|
|
88
|
+
export function publicKeyProblem(publicKey) {
|
|
89
|
+
if (publicKey.length !== 32)
|
|
90
|
+
return "not 32 bytes";
|
|
91
|
+
const point = decode(publicKey);
|
|
92
|
+
if (!point)
|
|
93
|
+
return "not a canonical encoding of a point on the curve";
|
|
94
|
+
if (isIdentity(multiply(8n, point)))
|
|
95
|
+
return "a small-order point";
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
/** The strict profile's rejections that precede the cryptographic check. `undefined` means the inputs pass them. */
|
|
99
|
+
export function profileProblem(publicKey, signature) {
|
|
100
|
+
if (signature.length !== 64)
|
|
101
|
+
return "signature is not 64 bytes";
|
|
102
|
+
const keyProblem = publicKeyProblem(publicKey);
|
|
103
|
+
if (keyProblem)
|
|
104
|
+
return `public key: ${keyProblem}`;
|
|
105
|
+
if (!decode(signature.subarray(0, 32)))
|
|
106
|
+
return "signature R is not a canonical point on the curve";
|
|
107
|
+
if (littleEndian(signature.subarray(32)) >= L)
|
|
108
|
+
return "signature S is not canonical (S >= L)";
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
/** Verifies under the strict profile. `"unavailable"` when the runtime cannot do Ed25519 at all (never a success). */
|
|
112
|
+
export async function verifyEd25519Strict(publicKey, message, signature) {
|
|
113
|
+
if (profileProblem(publicKey, signature) !== undefined)
|
|
114
|
+
return false;
|
|
115
|
+
const subtle = globalThis.crypto?.subtle;
|
|
116
|
+
if (!subtle)
|
|
117
|
+
return "unavailable";
|
|
118
|
+
try {
|
|
119
|
+
const key = await subtle.importKey("raw", publicKey, { name: "Ed25519" }, false, ["verify"]);
|
|
120
|
+
return await subtle.verify({ name: "Ed25519" }, key, signature, message);
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
if (error.name === "NotSupportedError")
|
|
124
|
+
return "unavailable";
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=ed25519.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ed25519.js","sourceRoot":"","sources":["../src/ed25519.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,GAAG,CAAC,EAAE,IAAI,IAAI,CAAC,GAAG,GAAG,CAAC;AAC7B,MAAM,CAAC,GAAG,CAAC,EAAE,IAAI,IAAI,CAAC,GAAG,uCAAuC,CAAC;AACjE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC;AAC/D,MAAM,OAAO,GAAG,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;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;QAAE,OAAO,mDAAmD,CAAC;IACnG,IAAI,YAAY,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC;QAAE,OAAO,uCAAuC,CAAC;IAC9F,OAAO,SAAS,CAAC;AACnB,CAAC;AAID,sHAAsH;AACtH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,SAAqB,EAAE,OAAmB,EAAE,SAAqB;IACzG,IAAI,cAAc,CAAC,SAAS,EAAE,SAAS,CAAC,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IACrE,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC;IACzC,IAAI,CAAC,MAAM;QAAE,OAAO,aAAa,CAAC;IAClC,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,SAAyB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC7G,OAAO,MAAM,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,GAAG,EAAE,SAAyB,EAAE,OAAuB,CAAC,CAAC;IAC3G,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAK,KAA2B,CAAC,IAAI,KAAK,mBAAmB;YAAE,OAAO,aAAa,CAAC;QACpF,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SemanticEncoding } from "@appport/protocol";
|
|
2
|
+
/**
|
|
3
|
+
* Converts between `iso8601` (rendered as UTC `YYYY-MM-DDTHH:mm:ss.sssZ`),
|
|
4
|
+
* `epoch-seconds` and `epoch-milliseconds`. Precision that would be lost is an
|
|
5
|
+
* error (`LOSSY_VALUE`) unless the rule sets `truncate`, which rounds toward
|
|
6
|
+
* negative infinity and must be declared in the mapping's `lossy` list.
|
|
7
|
+
*/
|
|
8
|
+
export declare function convertEncoding(value: unknown, from: SemanticEncoding, to: SemanticEncoding, pointer: string, truncate?: boolean): string | number;
|
|
9
|
+
//# sourceMappingURL=encodings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encodings.d.ts","sourceRoot":"","sources":["../src/encodings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAyD1D;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,gBAAgB,EACtB,EAAE,EAAE,gBAAgB,EACpB,OAAO,EAAE,MAAM,EACf,QAAQ,UAAQ,GACf,MAAM,GAAG,MAAM,CASjB"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { MappingError } from "./types.js";
|
|
2
|
+
const ISO = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,9}))?(Z|[+-]\d{2}:\d{2})$/;
|
|
3
|
+
const MIN_MS = -62167219200000; // 0000-01-01T00:00:00.000Z
|
|
4
|
+
const MAX_MS = 253402300799999; // 9999-12-31T23:59:59.999Z
|
|
5
|
+
/** Parses a strict ISO-8601 instant (offset required, no leap seconds) into whole milliseconds since the epoch. */
|
|
6
|
+
function parseIso(value, pointer, truncate) {
|
|
7
|
+
const match = typeof value === "string" ? ISO.exec(value) : null;
|
|
8
|
+
if (!match)
|
|
9
|
+
throw new MappingError("INVALID_VALUE", `expected an ISO-8601 instant with an offset, got ${JSON.stringify(value)}`, { pointer });
|
|
10
|
+
const [, y, mo, d, h, mi, s, frac = "", zone] = match;
|
|
11
|
+
const [year, month, day, hour, minute, second] = [y, mo, d, h, mi, s].map(Number);
|
|
12
|
+
const probe = new Date(Date.UTC(2000, month - 1, day, hour, minute, second));
|
|
13
|
+
const leap = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
|
14
|
+
const daysInMonth = [31, leap ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month - 1];
|
|
15
|
+
if (month < 1 || month > 12 || day < 1 || day > daysInMonth || hour > 23 || minute > 59 || second > 59 || Number.isNaN(probe.getTime())) {
|
|
16
|
+
throw new MappingError("INVALID_VALUE", `not a valid calendar instant: ${value}`, { pointer });
|
|
17
|
+
}
|
|
18
|
+
const offset = zone === "Z" ? 0 : (zone[0] === "-" ? -1 : 1) * (Number(zone.slice(1, 3)) * 60 + Number(zone.slice(4, 6)));
|
|
19
|
+
const fractional = frac.padEnd(9, "0");
|
|
20
|
+
if (/[^0]/.test(fractional.slice(3)) && !truncate) {
|
|
21
|
+
throw new MappingError("LOSSY_VALUE", "the value has sub-millisecond precision", { pointer });
|
|
22
|
+
}
|
|
23
|
+
const base = new Date(0);
|
|
24
|
+
base.setUTCFullYear(year, month - 1, day);
|
|
25
|
+
base.setUTCHours(hour, minute, second, Number(fractional.slice(0, 3)));
|
|
26
|
+
return base.getTime() - offset * 60000;
|
|
27
|
+
}
|
|
28
|
+
function formatIso(ms, pointer) {
|
|
29
|
+
if (!Number.isSafeInteger(ms) || ms < MIN_MS || ms > MAX_MS) {
|
|
30
|
+
throw new MappingError("INVALID_VALUE", `instant ${ms} ms is outside 0000-01-01..9999-12-31`, { pointer });
|
|
31
|
+
}
|
|
32
|
+
return new Date(ms).toISOString();
|
|
33
|
+
}
|
|
34
|
+
function toMilliseconds(value, encoding, pointer, truncate) {
|
|
35
|
+
if (encoding === "iso8601")
|
|
36
|
+
return parseIso(value, pointer, truncate);
|
|
37
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
38
|
+
throw new MappingError("INVALID_VALUE", `expected a number, got ${JSON.stringify(value)}`, { pointer });
|
|
39
|
+
}
|
|
40
|
+
if (encoding === "epoch-milliseconds") {
|
|
41
|
+
if (!Number.isInteger(value)) {
|
|
42
|
+
if (!truncate)
|
|
43
|
+
throw new MappingError("LOSSY_VALUE", "fractional milliseconds", { pointer });
|
|
44
|
+
return Math.floor(value);
|
|
45
|
+
}
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
const ms = value * 1000;
|
|
49
|
+
if (!Number.isInteger(ms)) {
|
|
50
|
+
if (!truncate)
|
|
51
|
+
throw new MappingError("LOSSY_VALUE", "sub-millisecond precision", { pointer });
|
|
52
|
+
return Math.floor(ms);
|
|
53
|
+
}
|
|
54
|
+
return ms;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Converts between `iso8601` (rendered as UTC `YYYY-MM-DDTHH:mm:ss.sssZ`),
|
|
58
|
+
* `epoch-seconds` and `epoch-milliseconds`. Precision that would be lost is an
|
|
59
|
+
* error (`LOSSY_VALUE`) unless the rule sets `truncate`, which rounds toward
|
|
60
|
+
* negative infinity and must be declared in the mapping's `lossy` list.
|
|
61
|
+
*/
|
|
62
|
+
export function convertEncoding(value, from, to, pointer, truncate = false) {
|
|
63
|
+
const ms = toMilliseconds(value, from, pointer, truncate);
|
|
64
|
+
if (to === "iso8601")
|
|
65
|
+
return formatIso(ms, pointer);
|
|
66
|
+
if (to === "epoch-milliseconds")
|
|
67
|
+
return ms;
|
|
68
|
+
if (ms % 1000 !== 0) {
|
|
69
|
+
if (!truncate)
|
|
70
|
+
throw new MappingError("LOSSY_VALUE", "the instant has a sub-second part", { pointer });
|
|
71
|
+
return Math.floor(ms / 1000);
|
|
72
|
+
}
|
|
73
|
+
return ms / 1000;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=encodings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encodings.js","sourceRoot":"","sources":["../src/encodings.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C,MAAM,GAAG,GAAG,sFAAsF,CAAC;AACnG,MAAM,MAAM,GAAG,CAAC,cAAc,CAAC,CAAC,2BAA2B;AAC3D,MAAM,MAAM,GAAG,eAAe,CAAC,CAAC,2BA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C,CAAC;QAC3B,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,EAAE,GAAG,KAAK,GAAG,IAAI,CAAC;IACxB,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,CAAC;QAC1B,IAAI,CAAC,QAAQ;YAAE,MAAM,IAAI,YAAY,CAAC,aAAa,EAAE,2BAA2B,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;QAC/F,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACxB,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAC7B,KAAc,EACd,IAAsB,EACtB,EAAoB,EACpB,OAAe,EACf,QAAQ,GAAG,KAAK;IAEhB,MAAM,EAAE,GAAG,cAAc,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC1D,IAAI,EAAE,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IACpD,IAAI,EAAE,KAAK,oBAAoB;QAAE,OAAO,EAAE,CAAC;IAC3C,IAAI,EAAE,GAAG,IAAI,KAAK,CAAC,EAAE,CAAC;QACpB,IAAI,CAAC,QAAQ;YAAE,MAAM,IAAI,YAAY,CAAC,aAAa,EAAE,mCAAmC,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;QACvG,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC;IAC/B,CAAC;IACD,OAAO,EAAE,GAAG,IAAI,CAAC;AACnB,CAAC"}
|
package/dist/fields.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { CapabilityFootprint } from "./footprint.js";
|
|
2
|
+
/**
|
|
3
|
+
* How one required target field can be fed from the source's output, judged only from the
|
|
4
|
+
* annotations both contracts publish.
|
|
5
|
+
*
|
|
6
|
+
* - `exact`: same concept, and unit/encoding/enum meaning agree where stated.
|
|
7
|
+
* - `needs-conversion`: same concept, a defined conversion exists (different unit, encoding, type), so a mapping is required.
|
|
8
|
+
* - `incompatible`: same concept but no conversion is defined (e.g. time vs length).
|
|
9
|
+
* - `unit-unstated` / `encoding-unstated`: one side declares it, the other does not. The conversion cannot be known.
|
|
10
|
+
* - `enum-unmapped`: both sides are enumerations but the contracts do not say how values correspond.
|
|
11
|
+
* - `ambiguous-source`: more than one source field carries the target's concept.
|
|
12
|
+
* - `no-source`: nothing the source produces carries the target's concept.
|
|
13
|
+
* - `concept-missing-target` / `concept-missing-source`: meaning is not declared, so none can be compared.
|
|
14
|
+
*/
|
|
15
|
+
export type FieldVerdict = "exact" | "needs-conversion" | "incompatible" | "unit-unstated" | "encoding-unstated" | "enum-unmapped" | "ambiguous-source" | "no-source" | "concept-missing-target" | "concept-missing-source";
|
|
16
|
+
export interface FieldPairing {
|
|
17
|
+
target: string;
|
|
18
|
+
source?: string;
|
|
19
|
+
candidates?: string[];
|
|
20
|
+
verdict: FieldVerdict;
|
|
21
|
+
detail?: string;
|
|
22
|
+
concept?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Pairs every *required* target input field with the source output field carrying the same
|
|
26
|
+
* concept. Optional target fields are not paired: nothing requires them.
|
|
27
|
+
*/
|
|
28
|
+
export declare function pairFields(source: CapabilityFootprint, target: CapabilityFootprint, bindings?: Record<string, string>): FieldPairing[];
|
|
29
|
+
//# sourceMappingURL=fields.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../src/fields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAkB,MAAM,gBAAgB,CAAC;AAI1E;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,YAAY,GACpB,OAAO,GACP,kBAAkB,GAClB,cAAc,GACd,eAAe,GACf,mBAAmB,GACnB,eAAe,GACf,kBAAkB,GAClB,WAAW,GACX,wBAAwB,GACxB,wBAAwB,CAAC;AAE7B,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,OAAO,EAAE,YAAY,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAsCD;;;GAGG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,mBAAmB,EAAE,MAAM,EAAE,mBAAmB,EAAE,QAAQ,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAAG,YAAY,EAAE,CAwB1I"}
|
package/dist/fields.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { unitProblem } from "./units.js";
|
|
2
|
+
const typeOf = (f) => f.type?.replace("integer", "number");
|
|
3
|
+
function pair(target, source) {
|
|
4
|
+
const base = { target: target.pointer, source: source.pointer, concept: target.concept };
|
|
5
|
+
const reasons = [];
|
|
6
|
+
let verdict = "exact";
|
|
7
|
+
const worsen = (next, why) => {
|
|
8
|
+
const rank = ["exact", "needs-conversion", "enum-unmapped", "encoding-unstated", "unit-unstated", "incompatible"];
|
|
9
|
+
if (rank.indexOf(next) > rank.indexOf(verdict))
|
|
10
|
+
verdict = next;
|
|
11
|
+
reasons.push(why);
|
|
12
|
+
};
|
|
13
|
+
if (target.unit !== undefined && source.unit !== undefined) {
|
|
14
|
+
if (target.unit !== source.unit) {
|
|
15
|
+
const problem = unitProblem(source.unit, target.unit);
|
|
16
|
+
problem ? worsen("incompatible", problem) : worsen("needs-conversion", `unit ${source.unit} → ${target.unit}`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
else if (target.unit !== undefined || source.unit !== undefined) {
|
|
20
|
+
worsen("unit-unstated", `${target.unit === undefined ? "target" : "source"} declares no unit`);
|
|
21
|
+
}
|
|
22
|
+
if (target.encoding !== undefined && source.encoding !== undefined) {
|
|
23
|
+
if (target.encoding !== source.encoding)
|
|
24
|
+
worsen("needs-conversion", `encoding ${source.encoding} → ${target.encoding}`);
|
|
25
|
+
}
|
|
26
|
+
else if (target.encoding !== undefined || source.encoding !== undefined) {
|
|
27
|
+
worsen("encoding-unstated", `${target.encoding === undefined ? "target" : "source"} declares no encoding`);
|
|
28
|
+
}
|
|
29
|
+
if (typeOf(target) !== undefined && typeOf(source) !== undefined && typeOf(target) !== typeOf(source))
|
|
30
|
+
worsen("needs-conversion", `type ${source.type} → ${target.type}`);
|
|
31
|
+
if (target.enumConcepts || source.enumConcepts) {
|
|
32
|
+
if (!target.enumConcepts || !source.enumConcepts)
|
|
33
|
+
worsen("enum-unmapped", "only one side declares enum value concepts");
|
|
34
|
+
else {
|
|
35
|
+
const accepted = new Set(Object.values(target.enumConcepts));
|
|
36
|
+
const lost = Object.entries(source.enumConcepts).filter(([, concept]) => !accepted.has(concept)).map(([value]) => value);
|
|
37
|
+
if (lost.length)
|
|
38
|
+
worsen("enum-unmapped", `source values with no counterpart in the target: ${lost.sort().join(", ")}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return { ...base, verdict, ...(reasons.length ? { detail: reasons.join("; ") } : {}) };
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Pairs every *required* target input field with the source output field carrying the same
|
|
45
|
+
* concept. Optional target fields are not paired: nothing requires them.
|
|
46
|
+
*/
|
|
47
|
+
export function pairFields(source, target, bindings = {}) {
|
|
48
|
+
const out = [];
|
|
49
|
+
const unannotatedSource = source.produces.filter((f) => f.concept === undefined);
|
|
50
|
+
for (const field of target.consumes.filter((f) => f.required)) {
|
|
51
|
+
if (field.concept === undefined) {
|
|
52
|
+
out.push({ target: field.pointer, verdict: "concept-missing-target", detail: "the target field declares no concept" });
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const candidates = source.produces.filter((f) => f.concept === field.concept);
|
|
56
|
+
const bound = bindings[field.pointer];
|
|
57
|
+
if (bound !== undefined) {
|
|
58
|
+
const chosen = source.produces.find((f) => f.pointer === bound);
|
|
59
|
+
if (chosen) {
|
|
60
|
+
out.push({ ...pair(field, chosen), detail: `caller-bound to ${bound}` });
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (candidates.length === 1)
|
|
65
|
+
out.push(pair(field, candidates[0]));
|
|
66
|
+
else if (candidates.length > 1)
|
|
67
|
+
out.push({ target: field.pointer, concept: field.concept, verdict: "ambiguous-source", candidates: candidates.map((c) => c.pointer).sort(), detail: "several source fields carry this concept" });
|
|
68
|
+
else if (unannotatedSource.some((f) => typeOf(f) === typeOf(field) || typeOf(f) === undefined)) {
|
|
69
|
+
out.push({ target: field.pointer, concept: field.concept, verdict: "concept-missing-source", candidates: unannotatedSource.map((f) => f.pointer).sort(), detail: "source fields exist that declare no concept; none can be matched" });
|
|
70
|
+
}
|
|
71
|
+
else
|
|
72
|
+
out.push({ target: field.pointer, concept: field.concept, verdict: "no-source", detail: "nothing the source produces carries this concept" });
|
|
73
|
+
}
|
|
74
|
+
return out.sort((a, b) => a.target.localeCompare(b.target));
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=fields.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fields.js","sourceRoot":"","sources":["../src/fields.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAqCzC,MAAM,MAAM,GAAG,CAAC,CAAiB,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;AAE3E,SAAS,IAAI,CAAC,MAAsB,EAAE,MAAsB;IAC1D,MAAM,IAAI,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,OAAQ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