@factoidal/core 0.20.0 → 0.22.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/bin/pack-host.mjs CHANGED
@@ -363,6 +363,11 @@ export async function denoReexec (options) {
363
363
  return null
364
364
  }
365
365
  if (granted.indexOf('run') < 0 || granted.indexOf('read') < 0) return null
366
+ // A `deno compile` executable is not the deno command: given `run ...` it
367
+ // reads `run` as a factoidal command (found 2026-10-28, building the
368
+ // single-file executables of docs/designissues/2026-10-28-single-file-app.md).
369
+ // It packs in process instead.
370
+ if (!/^deno(\.exe)?$/i.test(Deno.execPath().split(/[\\/]/).pop())) return null
366
371
  const main = Deno.mainModule.startsWith('file://')
367
372
  ? fileUrlToPath(Deno.mainModule)
368
373
  : Deno.mainModule
package/bin/serve.mjs CHANGED
@@ -147,6 +147,8 @@ export async function openServedStore (root, options = {}) {
147
147
  const config = {}
148
148
  if (typeof options.queryPath === 'string') config.queryPath = options.queryPath
149
149
  if (typeof options.gspPath === 'string') config.gspPath = options.gspPath
150
+ // The Host and Origin guard (issue 1124): passed unread; the engine decides.
151
+ if (options.localGuard !== undefined && options.localGuard !== null) config.localGuard = options.localGuard
150
152
  const info = engine.callBlobIO('storeServeOpen',
151
153
  [manifestHex, JSON.stringify(artifacts), JSON.stringify(state), JSON.stringify(config)],
152
154
  concatenate(chunks)).envelope
@@ -233,6 +235,8 @@ export async function openServedTdb2 (root, options = {}) {
233
235
  const config = {}
234
236
  if (typeof options.queryPath === 'string') config.queryPath = options.queryPath
235
237
  if (typeof options.gspPath === 'string') config.gspPath = options.gspPath
238
+ // The Host and Origin guard (issue 1124): passed unread; the engine decides.
239
+ if (options.localGuard !== undefined && options.localGuard !== null) config.localGuard = options.localGuard
236
240
  const info = engine.callBlobIO('tdb2ServeOpen',
237
241
  [JSON.stringify(files), JSON.stringify(config)], concatenate(chunks)).envelope
238
242
  const handle = info.handle
@@ -343,9 +347,22 @@ function serveConnection (served, socket, onError) {
343
347
  */
344
348
  export async function listen (root, options = {}) {
345
349
  const net = await import('node:net')
350
+ const host = typeof options.host === 'string' ? options.host : '127.0.0.1'
351
+ // `factoidal serve` has no authentication: the engine answers only the
352
+ // listener's own names and refuses writes from another origin
353
+ // (https://github.com/danbri/factoidal/issues/1124). Data for its check.
354
+ const os = await import('node:os')
355
+ let addresses = []
356
+ try { addresses = Object.values(os.networkInterfaces()).flat().filter(Boolean).map((i) => i.address) } catch (_error) { addresses = [] }
357
+ const localGuard = {
358
+ host,
359
+ addresses,
360
+ ...(Array.isArray(options.allowHosts) ? { allowHosts: options.allowHosts } : {}),
361
+ ...(Array.isArray(options.allowOrigins) ? { allowOrigins: options.allowOrigins } : {})
362
+ }
346
363
  const served = options.tdb2 === true
347
- ? await openServedTdb2(root, options)
348
- : await openServedStore(root, options)
364
+ ? await openServedTdb2(root, { ...options, localGuard })
365
+ : await openServedStore(root, { ...options, localGuard })
349
366
  const onError = typeof options.onError === 'function'
350
367
  ? options.onError
351
368
  : (error) => { console.error(`factoidal serve: ${error && error.message ? error.message : error}`) }
@@ -356,7 +373,6 @@ export async function listen (root, options = {}) {
356
373
  serveConnection(served, socket, onError)
357
374
  })
358
375
  const port = typeof options.port === 'number' ? options.port : 0
359
- const host = typeof options.host === 'string' ? options.host : '127.0.0.1'
360
376
  await new Promise((resolve, reject) => {
361
377
  server.once('error', reject)
362
378
  server.listen(port, host, resolve)
package/browser.d.ts CHANGED
@@ -14,6 +14,8 @@ export type {
14
14
  Sbm11Reader, Sbm11Answer, Sbm11Store, Sbm11ReadEvidence, Sbm11Transport,
15
15
  LiteralValueData, LiteralValueResult,
16
16
  ExplainResult, StageInfo, EvidenceRecord, Wire, FactoidalNode, Pipeline, RunResult, RunOptions,
17
+ NodePort, GraphSource, GraphSpec, GraphIssue, GraphCheck, FactoidalGraph, GraphRunResult,
18
+ QtError, Qt4Item, Qt4Result, Xslt4Result,
17
19
  } from './index';
18
20
 
19
21
  export {
@@ -26,6 +28,7 @@ export {
26
28
  canonicalHash,
27
29
  asDefaultGraph,
28
30
  isomorphic,
31
+ datasetMerge,
29
32
  fromQuads,
30
33
  literalValue,
31
34
  isValidLiteral,
@@ -42,6 +45,7 @@ export {
42
45
  memberOrdinal,
43
46
  openDataset,
44
47
  closure,
48
+ sparqlRlInfer,
45
49
  formats,
46
50
  queryRaw,
47
51
  queryHdt,
@@ -74,6 +78,7 @@ export {
74
78
  stages,
75
79
  node,
76
80
  pipe,
81
+ graph,
77
82
  run,
78
83
  rdfsPlusClosure,
79
84
  rhoDfClosure,
@@ -90,6 +95,9 @@ export {
90
95
  xmlWellformed,
91
96
  xpathEval,
92
97
  xsltTransform,
98
+ xpath4Eval,
99
+ xqueryEval,
100
+ xslt4Transform,
93
101
  schematronValidate,
94
102
  jsonSchemaValidate,
95
103
  mathmlEval,
@@ -107,12 +115,18 @@ export {
107
115
  vcEd25519SecretToPublic,
108
116
  vcEd25519Sign,
109
117
  vcEd25519Verify,
118
+ xmlDecrypt,
119
+ xmlEncrypt,
120
+ jweDecrypt,
121
+ jweEncrypt,
110
122
  vcEddsaCreateFromCanonical,
111
123
  vcEddsaVerifyFromCanonical,
112
124
  vcCheckCredential,
113
125
  vcCheckCredentialSubject,
114
126
  vcCheckNoDataLoss,
115
127
  vcCheckRelatedResourceDigests,
128
+ cidValidate,
129
+ cidRetrieveVerificationMethod,
116
130
  didKeyResolve,
117
131
  capabilities,
118
132
  Dataset,
package/browser.js CHANGED
@@ -85,6 +85,7 @@ export const graphs = api.graphs;
85
85
  export const canonicalHash = api.canonicalHash;
86
86
  export const asDefaultGraph = api.asDefaultGraph;
87
87
  export const isomorphic = api.isomorphic;
88
+ export const datasetMerge = api.datasetMerge;
88
89
  export const fromQuads = api.fromQuads;
89
90
  // Literal values (https://github.com/danbri/factoidal/issues/1051): synchronous
90
91
  // after the engine is loaded.
@@ -103,6 +104,7 @@ export const memberIri = api.memberIri;
103
104
  export const memberOrdinal = api.memberOrdinal;
104
105
  export const openDataset = api.openDataset;
105
106
  export const closure = api.closure;
107
+ export const sparqlRlInfer = api.sparqlRlInfer;
106
108
  export const formats = api.formats;
107
109
  export const queryRaw = api.queryRaw;
108
110
  export const queryHdt = api.queryHdt;
@@ -136,6 +138,7 @@ export const explain = api.explain;
136
138
  export const stages = api.stages;
137
139
  export const node = api.node;
138
140
  export const pipe = api.pipe;
141
+ export const graph = api.graph;
139
142
  export const run = api.run;
140
143
  export const rdfsPlusClosure = api.rdfsPlusClosure;
141
144
  export const rhoDfClosure = api.rhoDfClosure;
@@ -154,6 +157,10 @@ export const jsonldFromRdf = api.jsonldFromRdf;
154
157
  export const xmlWellformed = api.xmlWellformed;
155
158
  export const xpathEval = api.xpathEval;
156
159
  export const xsltTransform = api.xsltTransform;
160
+ // XPath 4.0, XQuery 4.0 and XSLT 4.0 (formal/lean4/Wasm/Ops/Qt4.lean).
161
+ export const xpath4Eval = api.xpath4Eval;
162
+ export const xqueryEval = api.xqueryEval;
163
+ export const xslt4Transform = api.xslt4Transform;
157
164
  export const schematronValidate = api.schematronValidate;
158
165
  export const jsonSchemaValidate = api.jsonSchemaValidate;
159
166
  export const mathmlEval = api.mathmlEval;
@@ -177,12 +184,21 @@ export const vcSha256Hex = api.vcSha256Hex;
177
184
  export const vcEd25519SecretToPublic = api.vcEd25519SecretToPublic;
178
185
  export const vcEd25519Sign = api.vcEd25519Sign;
179
186
  export const vcEd25519Verify = api.vcEd25519Verify;
187
+
188
+ // XML Encryption 1.1 and JWE; AES through WebCrypto (lib/cipher-host.mjs)
189
+ export const xmlDecrypt = api.xmlDecrypt;
190
+ export const xmlEncrypt = api.xmlEncrypt;
191
+ export const jweDecrypt = api.jweDecrypt;
192
+ export const jweEncrypt = api.jweEncrypt;
180
193
  export const vcEddsaCreateFromCanonical = api.vcEddsaCreateFromCanonical;
181
194
  export const vcEddsaVerifyFromCanonical = api.vcEddsaVerifyFromCanonical;
182
195
  export const vcCheckCredential = api.vcCheckCredential;
183
196
  export const vcCheckCredentialSubject = api.vcCheckCredentialSubject;
184
197
  export const vcCheckNoDataLoss = api.vcCheckNoDataLoss;
185
198
  export const vcCheckRelatedResourceDigests = api.vcCheckRelatedResourceDigests;
199
+ // Controlled Identifiers v1.0 (https://github.com/danbri/factoidal/issues/1100).
200
+ export const cidValidate = api.cidValidate;
201
+ export const cidRetrieveVerificationMethod = api.cidRetrieveVerificationMethod;
186
202
  export const didKeyResolve = api.didKeyResolve;
187
203
 
188
204
  // Types, probes and metadata
package/index.d.ts CHANGED
@@ -167,6 +167,20 @@ export class FactoidalError extends Error {
167
167
  readonly format?: string;
168
168
  /** For a parse failure of text: true when the syntax was inferred. */
169
169
  readonly formatInferred?: boolean;
170
+ /**
171
+ * For xpath4Eval, xqueryEval and xslt4Transform: the error that the
172
+ * XPath, XQuery or XSLT 4.0 specification names (code `XPST0003`,
173
+ * namespace `http://www.w3.org/2005/xqt-errors`, ...).
174
+ */
175
+ readonly qtError?: QtError;
176
+ }
177
+
178
+ /** An error of XPath 4.0, XQuery 4.0 or XSLT 4.0: the local part and the
179
+ * namespace of the error QName, and the engine's message. */
180
+ export interface QtError {
181
+ code: string;
182
+ namespace: string;
183
+ message: string;
170
184
  }
171
185
 
172
186
  /** One recoverable-parse diagnostic from a `{lenient:true}` parse() call. */
@@ -530,6 +544,18 @@ export function closure(
530
544
  options?: { format?: DataFormat; baseIRI?: string }
531
545
  ): Promise<Dataset>;
532
546
 
547
+ /**
548
+ * SPARQL 1.2 RL infer (https://w3c.github.io/data-shapes/sparql12-rl/): the
549
+ * inference graph of the rule set `rules` (SPARQL-RL text) over the default
550
+ * graph of `data`, as a new Dataset. Rejects when the rule set has a syntax
551
+ * error, is not well-formed or not stratifiable, or has IMPORTS.
552
+ */
553
+ export function sparqlRlInfer(
554
+ data: DataInput,
555
+ rules: string,
556
+ options?: { format?: DataFormat; baseIRI?: string }
557
+ ): Promise<Dataset>;
558
+
533
559
  /** The syntaxes the engine reads and writes, from the engine (op datasetFormats). */
534
560
  export function formats(): Promise<FormatCapability[]>;
535
561
 
@@ -574,9 +600,16 @@ export function graphs(dataset: Dataset): Array<[name: NamedNode | BlankNode, gr
574
600
  * differ only in their graph names got the same hash. To hash a graph
575
601
  * whatever its name (for example one entry of graphs()), use
576
602
  * canonicalHash(asDefaultGraph(g)). Rejects when the input holds an RDF 1.2
577
- * triple term or the section 4.4 call budget is exceeded.
578
- */
579
- export function canonicalHash(dataset: Dataset): Promise<string>;
603
+ * triple term or the section 4.4 call budget is exceeded. The input is what
604
+ * canonicalize() takes: a Dataset, or text with `format` and `baseIRI`.
605
+ * Text is a JavaScript string (characters, not bytes): decode bytes first;
606
+ * the RDF text syntaxes are UTF-8 (`new TextDecoder('utf-8', { fatal: true })`).
607
+ * A Uint8Array is refused.
608
+ */
609
+ export function canonicalHash(
610
+ data: Dataset | string | { text: string; format?: DataFormat; baseIRI?: string },
611
+ options?: { format?: DataFormat; baseIRI?: string },
612
+ ): Promise<string>;
580
613
 
581
614
  /**
582
615
  * A new Dataset with the triples of every graph of `dataset`, all in the
@@ -593,6 +626,15 @@ export function asDefaultGraph(dataset: Dataset): Dataset;
593
626
  */
594
627
  export function isomorphic(a: DataInput, b: DataInput, options?: { format?: string; baseIRI?: string }): Promise<boolean>;
595
628
 
629
+ /**
630
+ * The RDF merge of two datasets (RDF 1.1 Semantics 5.2): the quads of both,
631
+ * with the blank nodes of each input kept apart (`_:b` in `a` and `_:b` in
632
+ * `b` are two blank nodes). The engine computes it (op datasetMerge, Lean
633
+ * theorem mergeDatasets_isMerge). Prefixes: those of `a`, then those of `b`
634
+ * whose label `a` does not declare. Since 0.21.0.
635
+ */
636
+ export function datasetMerge(a: DataInput, b: DataInput, options?: { format?: string; baseIRI?: string }): Promise<Dataset>;
637
+
596
638
  /** A Dataset holding RDF/JS quads; each term is sent to the engine as its components. */
597
639
  export function fromQuads(quads: Iterable<Quad>): Promise<Dataset>;
598
640
 
@@ -937,17 +979,30 @@ export interface Wire<G = unknown> {
937
979
  evidence: EvidenceRecord[];
938
980
  }
939
981
 
982
+ /** An input port of a node: its name and its wire. */
983
+ export interface NodePort {
984
+ readonly name: string;
985
+ readonly wire: string;
986
+ }
987
+
940
988
  /** A node: a registered stage with its parameters. */
941
989
  export interface FactoidalNode {
942
990
  readonly stage: string;
943
991
  readonly kind: string | null;
944
992
  /** The engine's status of this node with its settings (see NodeStatus). */
945
993
  readonly status: NodeStatus;
946
- /** The registry status of the stage. */
947
- readonly registryStatus: StageInfo['status'];
994
+ /** The registry status of the stage; null for a stage with more than one port (not a registry entry). */
995
+ readonly registryStatus: StageInfo['status'] | null;
948
996
  readonly contract: string | null;
949
997
  readonly assumptions: readonly string[];
950
- readonly wireIn: string;
998
+ /**
999
+ * The input ports: one port 'in' for a registry stage; for a stage with
1000
+ * more than one port (datasetMerge: 'left', 'right'), the engine's list
1001
+ * (op graphCheckNodes). Such a node runs only in graph().
1002
+ */
1003
+ readonly ports: readonly NodePort[];
1004
+ /** The input wire of a one-port stage; null for a stage with more than one port. */
1005
+ readonly wireIn: string | null;
951
1006
  /**
952
1007
  * The output wire with these settings: for shippedEvaluator, 'Table' for
953
1008
  * SELECT, 'Answer' for ASK, 'Dataset' for CONSTRUCT and DESCRIBE (Lean
@@ -1047,9 +1102,74 @@ export function stages(): Promise<StageInfo[]>;
1047
1102
  */
1048
1103
  export function node(name: string, params?: Record<string, unknown>): Promise<FactoidalNode>;
1049
1104
 
1050
- /** Compose nodes and pipelines left to right. */
1105
+ /** Compose nodes and pipelines left to right. A node with more than one input port throws a TypeError (use graph()). */
1051
1106
  export function pipe(...nodes: Array<FactoidalNode | Pipeline>): Pipeline;
1052
1107
 
1108
+ /** Where a port's value comes from: graph input `input`, or the output of node `node` (an earlier node). */
1109
+ export type GraphSource = { readonly input: number } | { readonly node: number };
1110
+
1111
+ /** The request of graph(). */
1112
+ export interface GraphSpec {
1113
+ /** The wire of each graph input: a wire label of stages() (e.g. 'String', 'Dataset'). */
1114
+ inputs?: string[];
1115
+ /** The nodes in order; `from` has one source per input port of the node. */
1116
+ nodes: Array<{ node: FactoidalNode; from: GraphSource[] }>;
1117
+ }
1118
+
1119
+ /** An issue of the engine's static check of a graph (op graphCheckNodes, Lean graphIssues). */
1120
+ export type GraphIssue =
1121
+ | { readonly kind: 'unknownInput'; readonly node: number; readonly port: number; readonly portName: string; readonly input: number }
1122
+ | { readonly kind: 'forwardRef'; readonly node: number; readonly port: number; readonly portName: string; readonly ref: number }
1123
+ | { readonly kind: 'portCount'; readonly node: number; readonly ports: number; readonly sources: number }
1124
+ | { readonly kind: 'wireMismatch'; readonly node: number; readonly port: number; readonly portName: string; readonly source: string; readonly portWire: string };
1125
+
1126
+ /** The engine's check of a graph with no issue (op graphCheckNodes). */
1127
+ export interface GraphCheck {
1128
+ readonly issues: readonly GraphIssue[];
1129
+ /** The output wire of the last node. */
1130
+ readonly wireOut: string | null;
1131
+ /** The union of the nodes' named assumptions: the premises of Graph.guarantee_sound. */
1132
+ readonly assumptions: readonly string[];
1133
+ readonly contract: { readonly theorem: string; readonly staticCheck: string };
1134
+ readonly nodes: readonly {
1135
+ readonly name: string; readonly kind: string | null; readonly status: NodeStatus;
1136
+ /** null for a stage with more than one port (not a registry entry). */
1137
+ readonly registryStatus: StageInfo['status'] | null;
1138
+ readonly checked: boolean; readonly contract: string | null;
1139
+ readonly theorems: readonly string[]; readonly assumptions: readonly string[];
1140
+ readonly ports: readonly NodePort[]; readonly wireOut: string;
1141
+ readonly settings: Record<string, unknown>; readonly settingsDigest: string;
1142
+ readonly roles: Readonly<Record<string, string>>;
1143
+ readonly outside: readonly OutsideSetting[];
1144
+ readonly derived: Readonly<Record<string, string>>;
1145
+ }[];
1146
+ }
1147
+
1148
+ /** A graph from graph(): checked by the engine, with no issue. */
1149
+ export interface FactoidalGraph {
1150
+ readonly inputs: readonly string[];
1151
+ readonly nodes: readonly { readonly node: FactoidalNode; readonly from: readonly GraphSource[] }[];
1152
+ readonly wireOut: string | null;
1153
+ readonly assumptions: readonly string[];
1154
+ readonly check: GraphCheck;
1155
+ }
1156
+
1157
+ /** The result of run() on a graph. */
1158
+ export interface GraphRunResult<G = unknown> extends RunResult<G> {
1159
+ /** The output of each node, in order; `graph` is the last one. */
1160
+ values: unknown[];
1161
+ issues: GraphIssue[];
1162
+ }
1163
+
1164
+ /**
1165
+ * A pipeline that is an acyclic graph of nodes with named input ports
1166
+ * (https://github.com/danbri/factoidal/issues/1130). The engine's op
1167
+ * graphCheckNodes checks it: a graph with an issue throws a FactoidalError
1168
+ * (code 'op.failed') whose `issues` is the engine's list; an engine without
1169
+ * the op throws code 'op.unknown'. Since 0.21.0.
1170
+ */
1171
+ export function graph(spec: GraphSpec): FactoidalGraph;
1172
+
1053
1173
  /**
1054
1174
  * Run a node or pipeline on `input` (a Wire, or the graph: text for a
1055
1175
  * reader, else a Dataset or data input). Rejects before any node runs when
@@ -1061,6 +1181,12 @@ export function pipe(...nodes: Array<FactoidalNode | Pipeline>): Pipeline;
1061
1181
  * `wireOut` (see Wire).
1062
1182
  */
1063
1183
  export function run(pipeline: FactoidalNode | Pipeline, input: unknown, options?: RunOptions): Promise<RunResult>;
1184
+ /**
1185
+ * Run a graph on `inputs`, one value per graph input. Each node runs on the
1186
+ * values of its sources (a node with more than one port gets them in port
1187
+ * order); one evidence record per node, with `node` (its index) and `from`.
1188
+ */
1189
+ export function run(graph: FactoidalGraph, inputs: unknown[], options?: RunOptions): Promise<GraphRunResult>;
1064
1190
 
1065
1191
  /** Literature-name alias for coreRdfsClosure (ρdf). */
1066
1192
  export function rhoDfClosure(
@@ -1374,6 +1500,10 @@ export interface Sbm11Store {
1374
1500
  terms: number;
1375
1501
  /** how the engine checks reads; undefined from a wasm module built before the Merkle check */
1376
1502
  verify: 'merkle' | 'none' | undefined;
1503
+ /** the SHA-256 of the bytes of manifest.sbm11, 64 lowercase hex digits, as
1504
+ * the engine computed it at open (pin it, then give it as
1505
+ * `manifestSha256`); undefined from a wasm module built before issue 1105 */
1506
+ manifestSha256: string | undefined;
1377
1507
  query(sparql: string, options?: { base?: string; sparql12?: boolean; reference?: boolean }): Sbm11Answer;
1378
1508
  /** the resources the reader read, when its reader records them (lwsSbm11Reader) */
1379
1509
  readonly evidence: Sbm11ReadEvidence[] | undefined;
@@ -1384,8 +1514,13 @@ export interface Sbm11Store {
1384
1514
  * Node: `source` is a directory unless a reader is given or registered.
1385
1515
  * `verify` (default 'merkle'): the engine checks every byte it decodes against
1386
1516
  * the manifest's Merkle roots and refuses a changed file with its name;
1387
- * 'none' checks lengths only. */
1388
- export function openSbm11(source: string, options?: { reader?: Sbm11Reader; verify?: 'merkle' | 'none' }): Promise<Sbm11Store>;
1517
+ * 'none' checks lengths only.
1518
+ * `manifestSha256`: the trust anchor, the SHA-256 of the bytes of
1519
+ * manifest.sbm11 as 64 hex digits (https://github.com/danbri/factoidal/issues/1105);
1520
+ * the engine refuses the open when the manifest has another digest. */
1521
+ export function openSbm11(source: string, options?: {
1522
+ reader?: Sbm11Reader; verify?: 'merkle' | 'none'; manifestSha256?: string
1523
+ }): Promise<Sbm11Store>;
1389
1524
 
1390
1525
  /** Serve `source` with `reader`; `null` removes it. */
1391
1526
  export function registerSbm11Source(source: string, reader: Sbm11Reader | null): void;
@@ -1588,6 +1723,63 @@ export function xsltTransform(
1588
1723
  sourceXml: string
1589
1724
  ): Promise<string>;
1590
1725
 
1726
+ /** One item of an XPath 4.0 or XQuery 4.0 result. */
1727
+ export interface Qt4Item {
1728
+ /** The item's type: `xs:integer`, `element()`, `map(*)`, `array(*)`,
1729
+ * `function(*)`, ... */
1730
+ type: string;
1731
+ /** The item serialized with the Serialization 4.0 adaptive method. */
1732
+ value: string;
1733
+ }
1734
+
1735
+ /** The value shape returned by {@link xpath4Eval} and {@link xqueryEval}. */
1736
+ export interface Qt4Result {
1737
+ count: number;
1738
+ items: Qt4Item[];
1739
+ /** The whole sequence, Serialization 4.0 adaptive method. */
1740
+ adaptive: string;
1741
+ /** The whole sequence, xml method (no XML declaration); null when the
1742
+ * xml method cannot serialize it (a map, an array, a function). */
1743
+ xml: string | null;
1744
+ }
1745
+
1746
+ /**
1747
+ * Evaluate an XPath 4.0 expression with `xmlText` as the context item
1748
+ * ('' for no context item). The engine does no I/O: fn:doc and
1749
+ * fn:unparsed-text of a URI fail (FODC0002, FOUT1170). A QT4 error rejects
1750
+ * with a FactoidalError whose `qtError` names the error code.
1751
+ */
1752
+ export function xpath4Eval(xmlText: string, expr: string): Promise<Qt4Result>;
1753
+
1754
+ /**
1755
+ * Evaluate an XQuery 4.0 main module, with `contextXml` as the context item
1756
+ * when it is given and not ''. `import module` of a module that is not
1757
+ * given fails with XQST0059; no resource is fetched.
1758
+ */
1759
+ export function xqueryEval(query: string, contextXml?: string): Promise<Qt4Result>;
1760
+
1761
+ /** The value shape returned by {@link xslt4Transform}. */
1762
+ export interface Xslt4Result {
1763
+ /** The principal result, serialized with the stylesheet's unnamed output definition. */
1764
+ output: string;
1765
+ /** The output method used for `output` (xml, html, xhtml, text, json, adaptive, csv). */
1766
+ method: string;
1767
+ /** The results of xsl:result-document, each serialized with its output definition. */
1768
+ secondary: Array<{ href: string; output: string }>;
1769
+ /** The texts of xsl:message. */
1770
+ messages: string[];
1771
+ }
1772
+
1773
+ /**
1774
+ * XSLT 4.0 transform of `sourceXml` ('' for no global context item) by a
1775
+ * stylesheet of one module. xsl:import and xsl:include of another module
1776
+ * fail with XTSE0165: no module is fetched.
1777
+ */
1778
+ export function xslt4Transform(
1779
+ stylesheetXml: string,
1780
+ sourceXml: string
1781
+ ): Promise<Xslt4Result>;
1782
+
1591
1783
  /** The exact value a Content MathML expression evaluates to. */
1592
1784
  export type MathValue =
1593
1785
  | { kind: 'rat'; num: number; den: number }
@@ -1749,6 +1941,45 @@ export function vcEd25519Verify(
1749
1941
  signatureHex: string
1750
1942
  ): Promise<boolean>;
1751
1943
 
1944
+ /**
1945
+ * Decrypt every xenc:EncryptedData of an XML document (XML Encryption 1.1).
1946
+ * RSA-OAEP, ECDH-ES and X25519 run in the wasm (HACL*); AES runs in the
1947
+ * host's WebCrypto. Every failure after the structure check is the one
1948
+ * error "XML decryption failed".
1949
+ */
1950
+ export function xmlDecrypt(
1951
+ document: string,
1952
+ options: { keys: object[]; allowCbc?: boolean }
1953
+ ): Promise<{ document: string; canonical: string }>;
1954
+
1955
+ /** Encrypt an XML document element, or its content, for one recipient. */
1956
+ export function xmlEncrypt(
1957
+ document: string,
1958
+ options: {
1959
+ recipient: object;
1960
+ algorithm?: 'aes128-gcm' | 'aes256-gcm';
1961
+ keyTransport?: 'rsa-oaep-mgf1p' | 'rsa-oaep-sha256';
1962
+ keyWrap?: 'kw-aes128' | 'kw-aes256';
1963
+ content?: boolean;
1964
+ saml?: boolean;
1965
+ }
1966
+ ): Promise<{ document: string; canonical: string }>;
1967
+
1968
+ /**
1969
+ * Decrypt a compact JWE (RFC 7516). Every failure after the allowlist is
1970
+ * the one error "decryption failed".
1971
+ */
1972
+ export function jweDecrypt(
1973
+ token: string,
1974
+ options: { jwk: object }
1975
+ ): Promise<{ header: Record<string, unknown>; plaintext: Uint8Array }>;
1976
+
1977
+ /** Encrypt to a compact JWE (RFC 7516). */
1978
+ export function jweEncrypt(
1979
+ plaintext: Uint8Array | string,
1980
+ options: { alg: string; enc: string; jwk: object; header?: Record<string, unknown> }
1981
+ ): Promise<string>;
1982
+
1752
1983
  /**
1753
1984
  * Create an eddsa-rdfc-2022 Data Integrity proofValue (multibase-z,
1754
1985
  * base58btc) over already-canonicalized inputs — RDFC-1.0 canonical
@@ -1817,6 +2048,70 @@ export function vcCheckRelatedResourceDigests(
1817
2048
  credentialJson: string
1818
2049
  ): Promise<{ valid: boolean; reason?: string }>;
1819
2050
 
2051
+ /** One failed MUST of CID 1.0 §2 (cidValidate). */
2052
+ export interface CidValidationError {
2053
+ /** The engine's name of the failed MUST, e.g. 'idNotUrl', 'jwkPrivateMember'. */
2054
+ code: string;
2055
+ message: string;
2056
+ /** RFC 6901 JSON Pointer to the member, e.g. '/verificationMethod/1/publicKeyJwk/d'; '' is the whole document. */
2057
+ path: string;
2058
+ }
2059
+
2060
+ /**
2061
+ * Controlled Identifiers v1.0 §2 (https://www.w3.org/TR/cid-1.0/): check a
2062
+ * controlled identifier document. `valid` is the engine's answer
2063
+ * (L4Factoidal.CID.parseDocument); `errors` lists every failed MUST it found,
2064
+ * empty when valid. Issue 1100 item 9.
2065
+ */
2066
+ export function cidValidate(doc: string | object): Promise<{ valid: boolean; errors: CidValidationError[] }>;
2067
+
2068
+ /** An RFC 9457 problem details object. */
2069
+ export interface CidProblem {
2070
+ /** https://w3id.org/security#<NAME> for a §3.5 error; a tag: URI for the others. */
2071
+ type: string;
2072
+ title: string;
2073
+ detail: string;
2074
+ }
2075
+
2076
+ export interface CidRetrieveOptions {
2077
+ /**
2078
+ * GET the URL the engine names. Called as fetch(url, init) with
2079
+ * init.headers.accept, init.redirect 'manual' and, when the engine chose
2080
+ * one, init.address (the address to connect to). Answers a Response, or
2081
+ * { status, headers: { get(name) }, text() }. Default: Node and Deno
2082
+ * connect to init.address; a browser uses the page's fetch.
2083
+ */
2084
+ fetch?: (url: string, init: { method: 'GET'; headers: { accept: string }; redirect: 'manual'; address?: string }) =>
2085
+ Promise<{ status: number; headers: { get(name: string): string | null }; text(): Promise<string> }>;
2086
+ /** Every address of a host name. Default: the system resolver (Node, Deno); none in a browser. null: none. */
2087
+ resolve?: ((host: string) => Promise<string[]>) | null;
2088
+ /** Refuse a method that has expired or been revoked at this time (a Date, or seconds since the epoch). */
2089
+ now?: Date | number;
2090
+ /** Allow an http document URL (default: https only). */
2091
+ allowHttp?: boolean;
2092
+ /** Allow loopback, link-local, private and localhost addresses (default: refused). */
2093
+ allowPrivateFetch?: boolean;
2094
+ }
2095
+
2096
+ /**
2097
+ * Controlled Identifiers v1.0 §3.3 Retrieve Verification Method. The engine
2098
+ * names each fetch and decides each answer (the private-address guard of the
2099
+ * authorization server, the status, the Content-Type: application/cid,
2100
+ * application/cid+json, application/ld+json or application/json, then §3.3);
2101
+ * this function does the fetch. Never rejects for a failed retrieval: it
2102
+ * answers `ok: false` with the §3.5 name (or FETCH_REFUSED, FETCH_FAILED,
2103
+ * UNSUPPORTED_MEDIA_TYPE, VERIFICATION_METHOD_NOT_IN_FORCE) and an RFC 9457
2104
+ * object. Issue 1100 items 7 and 9.
2105
+ */
2106
+ export function cidRetrieveVerificationMethod(
2107
+ url: string,
2108
+ relationship: 'authentication' | 'assertionMethod' | 'keyAgreement' | 'capabilityInvocation' | 'capabilityDelegation',
2109
+ options?: CidRetrieveOptions
2110
+ ): Promise<
2111
+ | { ok: true; verificationMethod: Record<string, unknown>; controllerDocument: string }
2112
+ | { ok: false; code: string; problem: CidProblem }
2113
+ >;
2114
+
1820
2115
  /**
1821
2116
  * Feature probe: which ops the loaded wasm module serves. A module older
1822
2117
  * than this package can lack some; an operation whose op is missing
@@ -1831,6 +2126,8 @@ export function capabilities(): Promise<{
1831
2126
  canonicalHash: boolean;
1832
2127
  shacl: boolean;
1833
2128
  shex: boolean;
2129
+ /** the engine has the SPARQL 1.2 RL op (datasetSparqlRlInfer) */
2130
+ sparqlRl: boolean;
1834
2131
  owlClosure: boolean;
1835
2132
  explain: boolean;
1836
2133
  stages: boolean;
@@ -1838,6 +2135,10 @@ export function capabilities(): Promise<{
1838
2135
  pipelineCheck: boolean;
1839
2136
  /** The op pipelineCheckNodes: node settings in evidence, and the evaluator's output wire from the query form. */
1840
2137
  pipelineCheckNodes: boolean;
2138
+ /** The op graphCheckNodes: graph() and run() of a graph, and node('datasetMerge'). */
2139
+ graphCheck: boolean;
2140
+ /** The op datasetMerge: datasetMerge(). */
2141
+ datasetMerge: boolean;
1841
2142
  tableau: boolean;
1842
2143
  rml: boolean;
1843
2144
  csvw: boolean;
@@ -1848,6 +2149,9 @@ export function capabilities(): Promise<{
1848
2149
  xpath: boolean;
1849
2150
  rif: boolean;
1850
2151
  xslt: boolean;
2152
+ xpath4: boolean;
2153
+ xquery: boolean;
2154
+ xslt4: boolean;
1851
2155
  mathml: boolean;
1852
2156
  xforms: boolean;
1853
2157
  jsonSchema: boolean;
@@ -1867,6 +2171,8 @@ export function capabilities(): Promise<{
1867
2171
  deltaLog: boolean;
1868
2172
  /** ops literalValue and literalFromValue (issue 1051). */
1869
2173
  literalValues: boolean;
2174
+ /** ops cidValidate and cidRetrieve (issue 1100). */
2175
+ cid: boolean;
1870
2176
  /** 'full': the whole library is in the wasm module. */
1871
2177
  profile: 'full' | string;
1872
2178
  /** The dispatch ABI version string of the loaded wasm module. */
@@ -1945,6 +2251,7 @@ declare const _default: {
1945
2251
  update: typeof update;
1946
2252
  openDataset: typeof openDataset;
1947
2253
  closure: typeof closure;
2254
+ sparqlRlInfer: typeof sparqlRlInfer;
1948
2255
  formats: typeof formats;
1949
2256
  serialize: typeof serialize;
1950
2257
  canonicalize: typeof canonicalize;
@@ -1992,6 +2299,9 @@ declare const _default: {
1992
2299
  deltaLogDestroy: typeof deltaLogDestroy;
1993
2300
  _deltaLogCorruptLastForTest: typeof _deltaLogCorruptLastForTest;
1994
2301
  xsltTransform: typeof xsltTransform;
2302
+ xpath4Eval: typeof xpath4Eval;
2303
+ xqueryEval: typeof xqueryEval;
2304
+ xslt4Transform: typeof xslt4Transform;
1995
2305
  mathmlEval: typeof mathmlEval;
1996
2306
  xformsRecalc: typeof xformsRecalc;
1997
2307
  jsonSchemaValidate: typeof jsonSchemaValidate;
@@ -2005,12 +2315,18 @@ declare const _default: {
2005
2315
  vcEd25519SecretToPublic: typeof vcEd25519SecretToPublic;
2006
2316
  vcEd25519Sign: typeof vcEd25519Sign;
2007
2317
  vcEd25519Verify: typeof vcEd25519Verify;
2318
+ xmlDecrypt: typeof xmlDecrypt;
2319
+ xmlEncrypt: typeof xmlEncrypt;
2320
+ jweDecrypt: typeof jweDecrypt;
2321
+ jweEncrypt: typeof jweEncrypt;
2008
2322
  vcEddsaCreateFromCanonical: typeof vcEddsaCreateFromCanonical;
2009
2323
  vcEddsaVerifyFromCanonical: typeof vcEddsaVerifyFromCanonical;
2010
2324
  vcCheckCredential: typeof vcCheckCredential;
2011
2325
  vcCheckCredentialSubject: typeof vcCheckCredentialSubject;
2012
2326
  vcCheckNoDataLoss: typeof vcCheckNoDataLoss;
2013
2327
  vcCheckRelatedResourceDigests: typeof vcCheckRelatedResourceDigests;
2328
+ cidValidate: typeof cidValidate;
2329
+ cidRetrieveVerificationMethod: typeof cidRetrieveVerificationMethod;
2014
2330
  capabilities: typeof capabilities;
2015
2331
  Dataset: typeof Dataset;
2016
2332
  Store: typeof Store;