@factoidal/core 0.11.0 → 0.12.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/rdfjs.mjs CHANGED
@@ -15,6 +15,8 @@
15
15
  // ES module (0.9.0): the same file serves Node (index.mjs, and rdfjs.js for
16
16
  // require()) and the browser (browser.js), with no build step.
17
17
 
18
+ import { FactoidalError } from './lib/errors.mjs';
19
+
18
20
  // RDF/JS Data Model defaults of DataFactory.literal.
19
21
  const XSD_STRING = 'http://www.w3.org/2001/XMLSchema#string'; // purity-lint: allow RDF/JS DataFactory default
20
22
  const RDF_LANGSTRING =
@@ -330,10 +332,10 @@ function _setTextEngine(engine) { textEngine = engine; }
330
332
 
331
333
  function needEngine(who) {
332
334
  if (!textEngine) {
333
- throw new Error(
335
+ throw new FactoidalError(
334
336
  `${who}: N-Quads text is read and written by the engine, which is not ` +
335
337
  'loaded yet. Await any @factoidal/core call first (for example ' +
336
- '`await ready()`), or use parse() and Dataset.toString().');
338
+ '`await ready()`), or use parse() and Dataset.toString().', { code: 'op.unknown' });
337
339
  }
338
340
  return textEngine;
339
341
  }
@@ -56,7 +56,7 @@
56
56
  // stay distinct.
57
57
 
58
58
  import { loadEngine } from '../../bin/engine.mjs'
59
- import { readSnapshot, persistIfChanged } from '../../lws/persist.mjs'
59
+ import { readSnapshot, persistIfChanged, storageKeyText } from '../../lws/persist.mjs'
60
60
 
61
61
  /** The ops this host needs from the engine. */
62
62
  export const SOLID_SERVER_OPS = ['solidOpen', 'solidStep', 'solidClose', 'solidSnapshot',
@@ -169,6 +169,8 @@ function contentBytes (request) {
169
169
  * @param {string} [options.owner] the WebID the storage advertises
170
170
  * @param {string} [options.agent] the WebID of the requesting agent
171
171
  * @param {boolean} [options.realClock] stamp each request with this host's clock
172
+ * @param {string|null} [options.storageKey] the storage key text (64 hex digits or base64url);
173
+ * default the environment variable FACTOIDAL_LWS_KEY; `null` reads no key
172
174
  * @param {object} [options.engine] an engine handle to reuse
173
175
  * @returns {Promise<{step: Function, close: Function, handle: string,
174
176
  * engine: object}>}
@@ -186,6 +188,10 @@ export async function openSolidStorage (options = {}) {
186
188
  if (options.insecureNoAuth === true) config.insecureNoAuth = true
187
189
  if (typeof options.enforceWac === 'boolean') config.enforceWac = options.enforceWac
188
190
  if (typeof options.rootAcl === 'string') config.rootAcl = options.rootAcl
191
+ // Encryption at rest (issue 921), as the LWS host: the key text from
192
+ // `storageKey` or FACTOIDAL_LWS_KEY, passed unread; the engine decides.
193
+ const storageKey = storageKeyText(options.storageKey)
194
+ if (storageKey !== undefined) config.storageKey = storageKey
189
195
  // `dir` names the storage directory. The snapshot found there, if any,
190
196
  // is the storage to continue from; the engine checks it.
191
197
  const dir = typeof options.dir === 'string' ? options.dir : null