@degenerate/sharedata 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +1 -0
  4. package/dist/library/apply-library-function-transaction.d.ts +60 -0
  5. package/dist/library/apply-library-function-transaction.d.ts.map +1 -0
  6. package/dist/library/apply-library-function-transaction.js +73 -0
  7. package/dist/manager/share-data-manager.d.ts +6 -2
  8. package/dist/manager/share-data-manager.d.ts.map +1 -1
  9. package/dist/manager/share-data-manager.js +7 -3
  10. package/dist/persistence/deserialize-share-data.d.ts +8 -1
  11. package/dist/persistence/deserialize-share-data.d.ts.map +1 -1
  12. package/dist/persistence/deserialize-share-data.js +13 -1
  13. package/dist/persistence/file-share-data-repository.d.ts +8 -2
  14. package/dist/persistence/file-share-data-repository.d.ts.map +1 -1
  15. package/dist/persistence/file-share-data-repository.js +9 -3
  16. package/dist/persistence/firestore-share-data-repository.d.ts +3 -2
  17. package/dist/persistence/firestore-share-data-repository.d.ts.map +1 -1
  18. package/dist/persistence/firestore-share-data-repository.js +4 -3
  19. package/dist/persistence/in-memory-share-data-repository.d.ts +8 -1
  20. package/dist/persistence/in-memory-share-data-repository.d.ts.map +1 -1
  21. package/dist/persistence/in-memory-share-data-repository.js +9 -3
  22. package/dist/share-data/helpers/config/default-share-data-string.config.d.ts.map +1 -1
  23. package/dist/share-data/helpers/config/default-share-data-string.config.js +5 -0
  24. package/dist/share-data/share-data.d.ts +39 -5
  25. package/dist/share-data/share-data.d.ts.map +1 -1
  26. package/dist/share-data/share-data.js +89 -7
  27. package/package.json +4 -4
package/dist/index.d.ts CHANGED
@@ -15,4 +15,5 @@ export * from './share-data/proofs/creation/build-transaction-proposal-signer';
15
15
  export * from './share-data/proofs/verification/verify-share-data-proposal-proof';
16
16
  export * from './share-data/proofs/verification/verify-transaction-proposal-proof';
17
17
  export * from './share-data/proofs/testing/test-proof-signer';
18
+ export * from './library/apply-library-function-transaction';
18
19
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qCAAqC,CAAC;AACpD,cAAc,sCAAsC,CAAC;AACrD,cAAc,oCAAoC,CAAC;AACnD,cAAc,sCAAsC,CAAC;AACrD,cAAc,qCAAqC,CAAC;AACpD,cAAc,0CAA0C,CAAC;AACzD,cAAc,+CAA+C,CAAC;AAC9D,cAAc,+CAA+C,CAAC;AAC9D,cAAc,yBAAyB,CAAC;AACxC,cAAc,wDAAwD,CAAC;AACvE,cAAc,+DAA+D,CAAC;AAC9E,cAAc,gEAAgE,CAAC;AAC/E,cAAc,gEAAgE,CAAC;AAC/E,cAAc,mEAAmE,CAAC;AAClF,cAAc,oEAAoE,CAAC;AAKnF,cAAc,+CAA+C,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qCAAqC,CAAC;AACpD,cAAc,sCAAsC,CAAC;AACrD,cAAc,oCAAoC,CAAC;AACnD,cAAc,sCAAsC,CAAC;AACrD,cAAc,qCAAqC,CAAC;AACpD,cAAc,0CAA0C,CAAC;AACzD,cAAc,+CAA+C,CAAC;AAC9D,cAAc,+CAA+C,CAAC;AAC9D,cAAc,yBAAyB,CAAC;AACxC,cAAc,wDAAwD,CAAC;AACvE,cAAc,+DAA+D,CAAC;AAC9E,cAAc,gEAAgE,CAAC;AAC/E,cAAc,gEAAgE,CAAC;AAC/E,cAAc,mEAAmE,CAAC;AAClF,cAAc,oEAAoE,CAAC;AAKnF,cAAc,+CAA+C,CAAC;AAC9D,cAAc,8CAA8C,CAAC"}
package/dist/index.js CHANGED
@@ -35,3 +35,4 @@ __exportStar(require("./share-data/proofs/verification/verify-transaction-propos
35
35
  // production use. Production wiring lives in
36
36
  // `buildEllipticalCurvesProofFor` from `@degenerate/shareblock`.
37
37
  __exportStar(require("./share-data/proofs/testing/test-proof-signer"), exports);
38
+ __exportStar(require("./library/apply-library-function-transaction"), exports);
@@ -0,0 +1,60 @@
1
+ import { FunctionExecutionFailure, FunctionExecutor, IShareFunction, LibraryReference, LibraryRuleReferenceResult, LibraryStore, RuleEvaluator } from '@degenerate/generic';
2
+ import { ShareData } from '../share-data/share-data';
3
+ export interface ApplyLibraryFunctionResult {
4
+ /** Whether the rule engine accepted the proposal. */
5
+ accepted: boolean;
6
+ /** Transaction id assigned by ShareData; empty when nothing was submitted. */
7
+ transactionId: string;
8
+ /** True when the function produced no change (content-equal proposal). */
9
+ noOp: boolean;
10
+ /** Set when the sandbox run failed (the proposal was never produced/submitted). */
11
+ executionFailure?: FunctionExecutionFailure;
12
+ error?: string;
13
+ /** Gas consumed by the sandbox run. */
14
+ gasUsed?: number;
15
+ /** True when library rule references rejected the proposed transition. */
16
+ ruleRejected?: boolean;
17
+ /** Which rule references failed (the diagnostics) when `ruleRejected`. */
18
+ ruleFailures?: LibraryRuleReferenceResult[];
19
+ }
20
+ export interface ApplyLibraryFunctionArgs {
21
+ shareData: ShareData;
22
+ /**
23
+ * A function registered on the block. It supplies the rule-engine identity
24
+ * for the proposed transition; the library reference supplies the actual
25
+ * logic (its source computes the proposed state). The registered function's
26
+ * own `func` is not invoked here.
27
+ */
28
+ transactionFunction: IShareFunction<any, (...args: any[]) => any, any>;
29
+ /** The library function whose pinned version computes the proposed state. */
30
+ reference: LibraryReference;
31
+ store: LibraryStore;
32
+ input: unknown;
33
+ executor?: FunctionExecutor;
34
+ /**
35
+ * Optional library rule references that gate the proposed transition. If any
36
+ * fails, the transaction is not submitted. This is the additive ledger rule
37
+ * gate — it runs alongside (does not replace) the block's inline rule engine.
38
+ */
39
+ ruleReferences?: LibraryReference[];
40
+ ruleEvaluator?: RuleEvaluator;
41
+ }
42
+ /**
43
+ * The ledger-backed, async analogue of `safeSubmitTransaction`. Instead of
44
+ * calling a live `fn.func({ current, input })`, it resolves a library function
45
+ * reference, runs its stored source in the sandbox executor to compute the
46
+ * proposed state, then submits that state through the ShareData's existing
47
+ * unsigned apply path (`addTransactionNotValidated`).
48
+ *
49
+ * Outcomes:
50
+ * - sandbox failure (gas-exceeded / threw / invalid-output): nothing is
51
+ * submitted; `executionFailure` is set and `noOp` is false.
52
+ * - content-equal proposal: the engine rejects a no-change transaction, which
53
+ * is reported as `noOp: true` (mirrors `safeSubmitTransaction`).
54
+ * - otherwise: the rule engine's verdict is returned via `accepted`.
55
+ *
56
+ * This is the additive ledger path; the existing live-`func` `safeSubmitTransaction`
57
+ * is unchanged. The signed analogue (the manager proposer) follows the same shape.
58
+ */
59
+ export declare const applyLibraryFunctionTransaction: (args: ApplyLibraryFunctionArgs) => Promise<ApplyLibraryFunctionResult>;
60
+ //# sourceMappingURL=apply-library-function-transaction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apply-library-function-transaction.d.ts","sourceRoot":"","sources":["../../src/library/apply-library-function-transaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,wBAAwB,EACxB,gBAAgB,EAEhB,cAAc,EACd,gBAAgB,EAChB,0BAA0B,EAC1B,YAAY,EACZ,aAAa,EAEhB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAErD,MAAM,WAAW,0BAA0B;IACvC,qDAAqD;IACrD,QAAQ,EAAE,OAAO,CAAC;IAClB,8EAA8E;IAC9E,aAAa,EAAE,MAAM,CAAC;IACtB,0EAA0E;IAC1E,IAAI,EAAE,OAAO,CAAC;IACd,mFAAmF;IACnF,gBAAgB,CAAC,EAAE,wBAAwB,CAAC;IAC5C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uCAAuC;IACvC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,0EAA0E;IAC1E,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,0EAA0E;IAC1E,YAAY,CAAC,EAAE,0BAA0B,EAAE,CAAC;CAC/C;AAED,MAAM,WAAW,wBAAwB;IACrC,SAAS,EAAE,SAAS,CAAC;IACrB;;;;;OAKG;IACH,mBAAmB,EAAE,cAAc,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAAE,GAAG,CAAC,CAAC;IACvE,6EAA6E;IAC7E,SAAS,EAAE,gBAAgB,CAAC;IAC5B,KAAK,EAAE,YAAY,CAAC;IACpB,KAAK,EAAE,OAAO,CAAC;IACf,QAAQ,CAAC,EAAE,gBAAgB,CAAC;IAC5B;;;;OAIG;IACH,cAAc,CAAC,EAAE,gBAAgB,EAAE,CAAC;IACpC,aAAa,CAAC,EAAE,aAAa,CAAC;CACjC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,+BAA+B,GACxC,MAAM,wBAAwB,KAC/B,OAAO,CAAC,0BAA0B,CAqDpC,CAAC"}
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.applyLibraryFunctionTransaction = void 0;
4
+ const generic_1 = require("@degenerate/generic");
5
+ /**
6
+ * The ledger-backed, async analogue of `safeSubmitTransaction`. Instead of
7
+ * calling a live `fn.func({ current, input })`, it resolves a library function
8
+ * reference, runs its stored source in the sandbox executor to compute the
9
+ * proposed state, then submits that state through the ShareData's existing
10
+ * unsigned apply path (`addTransactionNotValidated`).
11
+ *
12
+ * Outcomes:
13
+ * - sandbox failure (gas-exceeded / threw / invalid-output): nothing is
14
+ * submitted; `executionFailure` is set and `noOp` is false.
15
+ * - content-equal proposal: the engine rejects a no-change transaction, which
16
+ * is reported as `noOp: true` (mirrors `safeSubmitTransaction`).
17
+ * - otherwise: the rule engine's verdict is returned via `accepted`.
18
+ *
19
+ * This is the additive ledger path; the existing live-`func` `safeSubmitTransaction`
20
+ * is unchanged. The signed analogue (the manager proposer) follows the same shape.
21
+ */
22
+ const applyLibraryFunctionTransaction = async (args) => {
23
+ const execution = await (0, generic_1.executeFunctionReference)(args.reference, args.store, {
24
+ current: args.shareData.currentState,
25
+ input: args.input,
26
+ executor: args.executor,
27
+ });
28
+ if (!execution.ok) {
29
+ return {
30
+ accepted: false,
31
+ transactionId: '',
32
+ noOp: false,
33
+ executionFailure: execution.failure,
34
+ error: execution.error,
35
+ gasUsed: execution.gasUsed,
36
+ };
37
+ }
38
+ const proposed = execution.output;
39
+ // Optional ledger rule gate: resolve + sandbox-evaluate the rule references
40
+ // against this transition. Fail-closed — a failing or unresolved rule blocks
41
+ // submission. Runs alongside the block's inline rule engine.
42
+ if (args.ruleReferences && args.ruleReferences.length > 0) {
43
+ const verdict = await (0, generic_1.evaluateLibraryRuleReferences)(args.ruleReferences, {
44
+ current: args.shareData.currentState,
45
+ proposed,
46
+ store: args.store,
47
+ evaluator: args.ruleEvaluator,
48
+ });
49
+ if (!verdict.passed) {
50
+ return {
51
+ accepted: false,
52
+ transactionId: '',
53
+ noOp: false,
54
+ ruleRejected: true,
55
+ ruleFailures: verdict.failures,
56
+ gasUsed: execution.gasUsed,
57
+ };
58
+ }
59
+ }
60
+ try {
61
+ const outcome = await args.shareData.addTransactionNotValidated(proposed, args.transactionFunction);
62
+ return { accepted: outcome.accepted, transactionId: outcome.transactionId, noOp: false, gasUsed: execution.gasUsed };
63
+ }
64
+ catch (err) {
65
+ // The function produced a content-equal proposal; the engine rejects a
66
+ // no-change transaction. Treat as a no-op rather than surfacing the error.
67
+ if (err instanceof generic_1.ShareDataCurrentAndProposalDataMatchesError) {
68
+ return { accepted: false, transactionId: '', noOp: true, gasUsed: execution.gasUsed };
69
+ }
70
+ throw err;
71
+ }
72
+ };
73
+ exports.applyLibraryFunctionTransaction = applyLibraryFunctionTransaction;
@@ -1,4 +1,4 @@
1
- import { IShareData, IShareDataCryptoProof, IShareFunction, ShareDataCreationRecord } from '@degenerate/generic';
1
+ import { IShareData, IShareDataCryptoProof, IShareFunction, LibraryStore, ShareDataCreationRecord } from '@degenerate/generic';
2
2
  import { ShareData } from '../share-data/share-data';
3
3
  import { ShareDataRepository } from '../persistence/share-data-repository';
4
4
  import { ShareDataManagerEventType, ShareDataManagerListener } from './share-data-manager-events';
@@ -6,6 +6,7 @@ export declare class ShareDataManager {
6
6
  private _shareDataObjects;
7
7
  private _emitter;
8
8
  private readonly _repository?;
9
+ private readonly _libraryStore?;
9
10
  private _persistence;
10
11
  /**
11
12
  * @param repository optional durable store. When supplied, blocks added
@@ -13,8 +14,11 @@ export declare class ShareDataManager {
13
14
  * writes through; call {@link hydrate} once at startup to reload them.
14
15
  * The no-arg form stays purely in-memory, so existing callers/tests are
15
16
  * untouched.
17
+ * @param libraryStore optional rule library store injected onto reloaded
18
+ * blocks so their rule references resolve from a deployment store
19
+ * (DB/rules-server). Omitted → blocks use the factory's default store.
16
20
  */
17
- constructor(repository?: ShareDataRepository);
21
+ constructor(repository?: ShareDataRepository, libraryStore?: LibraryStore);
18
22
  /**
19
23
  * Loads every durably-stored block into memory, re-verifying each through
20
24
  * the trust gate, and recovers its per-block persistence state so later
@@ -1 +1 @@
1
- {"version":3,"file":"share-data-manager.d.ts","sourceRoot":"","sources":["../../src/manager/share-data-manager.ts"],"names":[],"mappings":"AACA,OAAO,EACH,UAAU,EACV,qBAAqB,EACrB,cAAc,EAGd,uBAAuB,EAG1B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAGrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAC3E,OAAO,EAEH,yBAAyB,EACzB,wBAAwB,EAC3B,MAAM,6BAA6B,CAAC;AAmBrC,qBAAa,gBAAgB;IACzB,OAAO,CAAC,iBAAiB,CAAc;IACvC,OAAO,CAAC,QAAQ,CAAe;IAC/B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAsB;IACnD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EAAE,KAAK,GAAG,EAAE,GAAG,CAAC,EACtE,KAAK,EAAE,qBAAqB,GAC7B,OAAO,CAAC;QAAE,QAAQ,EAAE,OAAO,CAAC;QAAC,aAAa,EAAE,MAAM,CAAA;KAAE,CAAC;IAmDxD,EAAE,CAAC,IAAI,EAAE,yBAAyB,EAAE,QAAQ,EAAE,wBAAwB,GAAG,IAAI;IAI7E,GAAG,CAAC,IAAI,EAAE,yBAAyB,EAAE,QAAQ,EAAE,wBAAwB,GAAG,IAAI;IAI9E,OAAO,CAAC,KAAK;CAGhB"}
@@ -12,11 +12,15 @@ class ShareDataManager {
12
12
  * writes through; call {@link hydrate} once at startup to reload them.
13
13
  * The no-arg form stays purely in-memory, so existing callers/tests are
14
14
  * untouched.
15
+ * @param libraryStore optional rule library store injected onto reloaded
16
+ * blocks so their rule references resolve from a deployment store
17
+ * (DB/rules-server). Omitted → blocks use the factory's default store.
15
18
  */
16
- constructor(repository) {
19
+ constructor(repository, libraryStore) {
17
20
  this._shareDataObjects = [];
18
21
  this._emitter = new events_1.EventEmitter();
19
22
  this._repository = repository;
23
+ this._libraryStore = libraryStore;
20
24
  this._persistence = new Map();
21
25
  }
22
26
  /**
@@ -36,7 +40,7 @@ class ShareDataManager {
36
40
  // The trust gate: a tampered snapshot throws here rather than being
37
41
  // loaded. The executable block and the recovered persistence state
38
42
  // are rebuilt from the same bytes.
39
- const block = (0, deserialize_share_data_1.deserializeShareData)(snapshot);
43
+ const block = (0, deserialize_share_data_1.deserializeShareData)(snapshot, this._libraryStore);
40
44
  if (this.getShareDataById(block.id)) {
41
45
  throw new generic_1.ShareDataAlreadyExistsError(block.id);
42
46
  }
@@ -164,7 +168,7 @@ class ShareDataManager {
164
168
  if (!shareData) {
165
169
  throw new generic_1.ShareDataNotFoundError(id);
166
170
  }
167
- const outcome = shareData.addTransaction(proposedData, transactionFunction, proof);
171
+ const outcome = await shareData.addTransaction(proposedData, transactionFunction, proof);
168
172
  const persistence = this._persistence.get(id);
169
173
  if (this._repository && persistence) {
170
174
  if (transactionFunction.id === undefined) {
@@ -1,3 +1,4 @@
1
+ import { LibraryStore } from '@degenerate/generic';
1
2
  import { ShareData } from '../share-data/share-data';
2
3
  /**
3
4
  * Replays a {@link PersistedShareData} snapshot back into a live, executable
@@ -13,6 +14,12 @@ import { ShareData } from '../share-data/share-data';
13
14
  * if the structural-proof chain does not verify.
14
15
  * - {@link ShareDataIntegrityError} if the replayed block diverges from the
15
16
  * snapshot's `expected*` cross-checks.
17
+ *
18
+ * `libraryStore`, when provided, is injected onto the rebuilt block so its rule
19
+ * references resolve from that store (a DB- or rules-server-backed store) for
20
+ * future transactions. Replay itself does not resolve rules — it replays the
21
+ * recorded outcomes — so omitting it leaves the block on the factory's default
22
+ * self-seeding store.
16
23
  */
17
- export declare const deserializeShareData: (snapshot: unknown) => ShareData;
24
+ export declare const deserializeShareData: (snapshot: unknown, libraryStore?: LibraryStore) => ShareData;
18
25
  //# sourceMappingURL=deserialize-share-data.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"deserialize-share-data.d.ts","sourceRoot":"","sources":["../../src/persistence/deserialize-share-data.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAYrD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,oBAAoB,GAAI,UAAU,OAAO,KAAG,SAoHxD,CAAC"}
1
+ {"version":3,"file":"deserialize-share-data.d.ts","sourceRoot":"","sources":["../../src/persistence/deserialize-share-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,YAAY,EAQf,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAYrD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,oBAAoB,GAAI,UAAU,OAAO,EAAE,eAAe,YAAY,KAAG,SA2HrF,CAAC"}
@@ -25,8 +25,14 @@ const block_factory_registry_1 = require("./block-factory-registry");
25
25
  * if the structural-proof chain does not verify.
26
26
  * - {@link ShareDataIntegrityError} if the replayed block diverges from the
27
27
  * snapshot's `expected*` cross-checks.
28
+ *
29
+ * `libraryStore`, when provided, is injected onto the rebuilt block so its rule
30
+ * references resolve from that store (a DB- or rules-server-backed store) for
31
+ * future transactions. Replay itself does not resolve rules — it replays the
32
+ * recorded outcomes — so omitting it leaves the block on the factory's default
33
+ * self-seeding store.
28
34
  */
29
- const deserializeShareData = (snapshot) => {
35
+ const deserializeShareData = (snapshot, libraryStore) => {
30
36
  // Read id + schemaVersion defensively *before* full validation so an
31
37
  // unsupported version yields a precise persistence error (naming the id)
32
38
  // rather than a raw Zod failure on the `schemaVersion` literal.
@@ -57,6 +63,12 @@ const deserializeShareData = (snapshot) => {
57
63
  structuralProofs: parsed.structuralProofs,
58
64
  authorizedSigners: parsed.authorizedSigners,
59
65
  });
66
+ // Override the factory's default resolver store with the injected one, so
67
+ // future transactions on the reloaded block resolve rule references from the
68
+ // deployment's store. Replay below records stored outcomes and needs no store.
69
+ if (libraryStore) {
70
+ block.setLibraryStore(libraryStore);
71
+ }
60
72
  // Replay the transaction log in recorded order.
61
73
  for (const entry of parsed.transactionLog) {
62
74
  const transactionFunction = block.functions.find((fn) => fn.id === entry.functionId);
@@ -1,4 +1,4 @@
1
- import { PersistedShareData } from '@degenerate/generic';
1
+ import { LibraryStore, PersistedShareData } from '@degenerate/generic';
2
2
  import { ShareData } from '../share-data/share-data';
3
3
  import { ShareDataRepository } from './share-data-repository';
4
4
  /**
@@ -10,7 +10,13 @@ import { ShareDataRepository } from './share-data-repository';
10
10
  */
11
11
  export declare class FileShareDataRepository implements ShareDataRepository {
12
12
  private readonly directory;
13
- constructor(directory: string);
13
+ private readonly libraryStore?;
14
+ /**
15
+ * @param directory where snapshot JSON files live.
16
+ * @param libraryStore optional rule library store injected onto reloaded
17
+ * blocks (passed to {@link deserializeShareData}).
18
+ */
19
+ constructor(directory: string, libraryStore?: LibraryStore | undefined);
14
20
  save(snapshot: PersistedShareData): Promise<void>;
15
21
  load(id: string): Promise<ShareData | undefined>;
16
22
  loadAll(): Promise<ShareData[]>;
@@ -1 +1 @@
1
- {"version":3,"file":"file-share-data-repository.d.ts","sourceRoot":"","sources":["../../src/persistence/file-share-data-repository.ts"],"names":[],"mappings":"AAGA,OAAO,EACH,kBAAkB,EAGrB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAErD,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAS9D;;;;;;GAMG;AACH,qBAAa,uBAAwB,YAAW,mBAAmB;IACnD,OAAO,CAAC,QAAQ,CAAC,SAAS;gBAAT,SAAS,EAAE,MAAM;IAExC,IAAI,CAAC,QAAQ,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBjD,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IAchD,OAAO,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAK/B,gBAAgB,IAAI,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAuBjD,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAYvC;;;;;;;;OAQG;IACH,OAAO,CAAC,eAAe;CAY1B"}
1
+ {"version":3,"file":"file-share-data-repository.d.ts","sourceRoot":"","sources":["../../src/persistence/file-share-data-repository.ts"],"names":[],"mappings":"AAGA,OAAO,EACH,YAAY,EACZ,kBAAkB,EAGrB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAErD,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAS9D;;;;;;GAMG;AACH,qBAAa,uBAAwB,YAAW,mBAAmB;IAMnD,OAAO,CAAC,QAAQ,CAAC,SAAS;IAAU,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC;IAL9E;;;;OAIG;gBAC0B,SAAS,EAAE,MAAM,EAAmB,YAAY,CAAC,EAAE,YAAY,YAAA;IAEtF,IAAI,CAAC,QAAQ,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBjD,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IAchD,OAAO,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAK/B,gBAAgB,IAAI,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAuBjD,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAYvC;;;;;;;;OAQG;IACH,OAAO,CAAC,eAAe;CAY1B"}
@@ -52,8 +52,14 @@ const deserialize_share_data_1 = require("./deserialize-share-data");
52
52
  * verification instead of loading silently.
53
53
  */
54
54
  class FileShareDataRepository {
55
- constructor(directory) {
55
+ /**
56
+ * @param directory where snapshot JSON files live.
57
+ * @param libraryStore optional rule library store injected onto reloaded
58
+ * blocks (passed to {@link deserializeShareData}).
59
+ */
60
+ constructor(directory, libraryStore) {
56
61
  this.directory = directory;
62
+ this.libraryStore = libraryStore;
57
63
  }
58
64
  async save(snapshot) {
59
65
  await fs_1.promises.mkdir(this.directory, { recursive: true });
@@ -84,11 +90,11 @@ class FileShareDataRepository {
84
90
  }
85
91
  throw err;
86
92
  }
87
- return (0, deserialize_share_data_1.deserializeShareData)(JSON.parse(raw));
93
+ return (0, deserialize_share_data_1.deserializeShareData)(JSON.parse(raw), this.libraryStore);
88
94
  }
89
95
  async loadAll() {
90
96
  const snapshots = await this.loadAllSnapshots();
91
- return snapshots.map((snapshot) => (0, deserialize_share_data_1.deserializeShareData)(snapshot));
97
+ return snapshots.map((snapshot) => (0, deserialize_share_data_1.deserializeShareData)(snapshot, this.libraryStore));
92
98
  }
93
99
  async loadAllSnapshots() {
94
100
  let entries;
@@ -1,5 +1,5 @@
1
1
  import type { firestore } from 'firebase-admin';
2
- import { PersistedShareData } from '@degenerate/generic';
2
+ import { LibraryStore, PersistedShareData } from '@degenerate/generic';
3
3
  import { ShareData } from '../share-data/share-data';
4
4
  import { ShareDataRepository } from './share-data-repository';
5
5
  /**
@@ -13,7 +13,8 @@ import { ShareDataRepository } from './share-data-repository';
13
13
  export declare class FirestoreShareDataRepository implements ShareDataRepository {
14
14
  private readonly firestore;
15
15
  private readonly collectionName;
16
- constructor(firestore: firestore.Firestore, collectionName?: string);
16
+ private readonly libraryStore?;
17
+ constructor(firestore: firestore.Firestore, collectionName?: string, libraryStore?: LibraryStore | undefined);
17
18
  save(snapshot: PersistedShareData): Promise<void>;
18
19
  load(id: string): Promise<ShareData | undefined>;
19
20
  loadAll(): Promise<ShareData[]>;
@@ -1 +1 @@
1
- {"version":3,"file":"firestore-share-data-repository.d.ts","sourceRoot":"","sources":["../../src/persistence/firestore-share-data-repository.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,EAEH,kBAAkB,EAGrB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAErD,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAU9D;;;;;;;GAOG;AACH,qBAAa,4BAA6B,YAAW,mBAAmB;IAEhE,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,cAAc;gBADd,SAAS,EAAE,SAAS,CAAC,SAAS,EAC9B,cAAc,GAAE,MAAuD;IAGtF,IAAI,CAAC,QAAQ,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAIjD,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IAQhD,OAAO,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAK/B,gBAAgB,IAAI,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAOjD,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIvC,OAAO,CAAC,MAAM;IAId;;;;OAIG;IACH,OAAO,CAAC,eAAe;IAIvB;;;;;;OAMG;IACH,OAAO,CAAC,KAAK;CAYhB"}
1
+ {"version":3,"file":"firestore-share-data-repository.d.ts","sourceRoot":"","sources":["../../src/persistence/firestore-share-data-repository.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,EAEH,YAAY,EACZ,kBAAkB,EAGrB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAErD,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAU9D;;;;;;;GAOG;AACH,qBAAa,4BAA6B,YAAW,mBAAmB;IAEhE,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,cAAc;IAC/B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC;gBAFb,SAAS,EAAE,SAAS,CAAC,SAAS,EAC9B,cAAc,GAAE,MAAuD,EACvE,YAAY,CAAC,EAAE,YAAY,YAAA;IAG1C,IAAI,CAAC,QAAQ,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAIjD,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IAQhD,OAAO,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAK/B,gBAAgB,IAAI,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAOjD,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIvC,OAAO,CAAC,MAAM;IAId;;;;OAIG;IACH,OAAO,CAAC,eAAe;IAIvB;;;;;;OAMG;IACH,OAAO,CAAC,KAAK;CAYhB"}
@@ -19,9 +19,10 @@ const deserialize_share_data_1 = require("./deserialize-share-data");
19
19
  * document edited out-of-band fails verification instead of loading silently.
20
20
  */
21
21
  class FirestoreShareDataRepository {
22
- constructor(firestore, collectionName = generic_1.DatabaseSettingsFirestore.ShareData.Collection) {
22
+ constructor(firestore, collectionName = generic_1.DatabaseSettingsFirestore.ShareData.Collection, libraryStore) {
23
23
  this.firestore = firestore;
24
24
  this.collectionName = collectionName;
25
+ this.libraryStore = libraryStore;
25
26
  }
26
27
  async save(snapshot) {
27
28
  await this.docRef(snapshot.id).set(this.toFirestoreData(snapshot));
@@ -31,11 +32,11 @@ class FirestoreShareDataRepository {
31
32
  if (!doc.exists) {
32
33
  return undefined;
33
34
  }
34
- return (0, deserialize_share_data_1.deserializeShareData)(generic_1.PersistedShareDataSchema.parse(doc.data()));
35
+ return (0, deserialize_share_data_1.deserializeShareData)(generic_1.PersistedShareDataSchema.parse(doc.data()), this.libraryStore);
35
36
  }
36
37
  async loadAll() {
37
38
  const snapshots = await this.loadAllSnapshots();
38
- return snapshots.map((snapshot) => (0, deserialize_share_data_1.deserializeShareData)(snapshot));
39
+ return snapshots.map((snapshot) => (0, deserialize_share_data_1.deserializeShareData)(snapshot, this.libraryStore));
39
40
  }
40
41
  async loadAllSnapshots() {
41
42
  const query = await this.firestore.collection(this.collectionName).get();
@@ -1,4 +1,4 @@
1
- import { PersistedShareData } from '@degenerate/generic';
1
+ import { LibraryStore, PersistedShareData } from '@degenerate/generic';
2
2
  import { ShareData } from '../share-data/share-data';
3
3
  import { ShareDataRepository } from './share-data-repository';
4
4
  /**
@@ -9,7 +9,14 @@ import { ShareDataRepository } from './share-data-repository';
9
9
  * through {@link deserializeShareData} on the way out.
10
10
  */
11
11
  export declare class InMemoryShareDataRepository implements ShareDataRepository {
12
+ private readonly libraryStore?;
12
13
  private readonly snapshots;
14
+ /**
15
+ * @param libraryStore optional rule library store injected onto reloaded
16
+ * blocks (passed to {@link deserializeShareData}). Omit to use the
17
+ * factory's default self-seeding store.
18
+ */
19
+ constructor(libraryStore?: LibraryStore | undefined);
13
20
  save(snapshot: PersistedShareData): Promise<void>;
14
21
  load(id: string): Promise<ShareData | undefined>;
15
22
  loadAll(): Promise<ShareData[]>;
@@ -1 +1 @@
1
- {"version":3,"file":"in-memory-share-data-repository.d.ts","sourceRoot":"","sources":["../../src/persistence/in-memory-share-data-repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAA4B,MAAM,qBAAqB,CAAC;AAEnF,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAErD,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAU9D;;;;;;GAMG;AACH,qBAAa,2BAA4B,YAAW,mBAAmB;IACnE,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAyC;IAE7D,IAAI,CAAC,QAAQ,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAOjD,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IAQhD,OAAO,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAK/B,gBAAgB,IAAI,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAMjD,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAG1C"}
1
+ {"version":3,"file":"in-memory-share-data-repository.d.ts","sourceRoot":"","sources":["../../src/persistence/in-memory-share-data-repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAA4B,MAAM,qBAAqB,CAAC;AAEjG,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAErD,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAU9D;;;;;;GAMG;AACH,qBAAa,2BAA4B,YAAW,mBAAmB;IAQvD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC;IAP1C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAyC;IAEnE;;;;OAIG;gBAC0B,YAAY,CAAC,EAAE,YAAY,YAAA;IAElD,IAAI,CAAC,QAAQ,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAOjD,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IAQhD,OAAO,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAK/B,gBAAgB,IAAI,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAMjD,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAG1C"}
@@ -18,7 +18,13 @@ const deserialize_share_data_1 = require("./deserialize-share-data");
18
18
  * through {@link deserializeShareData} on the way out.
19
19
  */
20
20
  class InMemoryShareDataRepository {
21
- constructor() {
21
+ /**
22
+ * @param libraryStore optional rule library store injected onto reloaded
23
+ * blocks (passed to {@link deserializeShareData}). Omit to use the
24
+ * factory's default self-seeding store.
25
+ */
26
+ constructor(libraryStore) {
27
+ this.libraryStore = libraryStore;
22
28
  this.snapshots = new Map();
23
29
  }
24
30
  async save(snapshot) {
@@ -32,11 +38,11 @@ class InMemoryShareDataRepository {
32
38
  if (!snapshot) {
33
39
  return undefined;
34
40
  }
35
- return (0, deserialize_share_data_1.deserializeShareData)(generic_1.PersistedShareDataSchema.parse(snapshot));
41
+ return (0, deserialize_share_data_1.deserializeShareData)(generic_1.PersistedShareDataSchema.parse(snapshot), this.libraryStore);
36
42
  }
37
43
  async loadAll() {
38
44
  const snapshots = await this.loadAllSnapshots();
39
- return snapshots.map((snapshot) => (0, deserialize_share_data_1.deserializeShareData)(snapshot));
45
+ return snapshots.map((snapshot) => (0, deserialize_share_data_1.deserializeShareData)(snapshot, this.libraryStore));
40
46
  }
41
47
  async loadAllSnapshots() {
42
48
  return [...this.snapshots.values()].map((snapshot) => generic_1.PersistedShareDataSchema.parse(snapshot));
@@ -1 +1 @@
1
- {"version":3,"file":"default-share-data-string.config.d.ts","sourceRoot":"","sources":["../../../../src/share-data/helpers/config/default-share-data-string.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAIvD;;;GAGG;AACH,eAAO,MAAM,4BAA4B,EAAE,gBAoB1C,CAAC"}
1
+ {"version":3,"file":"default-share-data-string.config.d.ts","sourceRoot":"","sources":["../../../../src/share-data/helpers/config/default-share-data-string.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAIvD;;;GAGG;AACH,eAAO,MAAM,4BAA4B,EAAE,gBAyB1C,CAAC"}
@@ -24,6 +24,11 @@ exports.defaultShareDataStringConfig = [
24
24
  { key: 'events', process: get_array_string_1.getArrayString },
25
25
  { key: 'functions', process: get_array_string_1.getArrayString },
26
26
  { key: 'rules', process: get_array_string_1.getArrayString },
27
+ // Library rule references, folded into the signed structure the same way as
28
+ // `authorizedSigners`/`rules`. `getArrayString([])` returns '', so a block
29
+ // with no rule references hashes identically to before this field existed —
30
+ // existing proofs stay valid.
31
+ { key: 'ruleReferences', process: get_array_string_1.getArrayString },
27
32
  { key: 'transactionHistory', process: get_array_string_1.getArrayString },
28
33
  { key: 'creationHash' },
29
34
  { key: 'creationSignature' },
@@ -1,4 +1,4 @@
1
- import { IShareData, IShareDataEvent, IShareFunction, IShareRuleApplied, IShareRuleEvalutionResult, IShareDataTransactionHistory, IShareDataCryptoProof, EllipticalCurvesSigning, IShareDataInitialCryptoData, IAuthorizedSigner } from '@degenerate/generic';
1
+ import { IShareData, IShareDataEvent, IShareFunction, IShareRuleApplied, IShareRuleEvalutionResult, IShareDataTransactionHistory, IShareDataCryptoProof, EllipticalCurvesSigning, IShareDataInitialCryptoData, IAuthorizedSigner, ILibraryRuleReferenceBinding, LibraryStore } from '@degenerate/generic';
2
2
  /**
3
3
  * This contains the interface for the share data object
4
4
  */
@@ -19,6 +19,9 @@ export declare class ShareData {
19
19
  private _lastUpdated;
20
20
  private _structuralProofs;
21
21
  private _authorizedSigners;
22
+ private _ruleReferences;
23
+ private _libraryStore?;
24
+ private _hydratedReferenceRules?;
22
25
  /**
23
26
  * This is the constructor for the share data object
24
27
  * @param id the id of the share data
@@ -99,6 +102,12 @@ export declare class ShareData {
99
102
  * NOT listed here.
100
103
  */
101
104
  get authorizedSigners(): IAuthorizedSigner[];
105
+ /**
106
+ * The library rule references governing this block. Each binding pairs a
107
+ * library reference (id + pinned `currentHash`) with the root property it
108
+ * governs. Frozen after `initialize()` like rules/functions.
109
+ */
110
+ get ruleReferences(): ILibraryRuleReferenceBinding[];
102
111
  /**
103
112
  * This gets the transaction history for the share block
104
113
  */
@@ -122,6 +131,31 @@ export declare class ShareData {
122
131
  * @param rule the rule to add to the share block
123
132
  */
124
133
  addRule(rule: IShareRuleApplied, cryptoProof: IShareDataCryptoProof): void;
134
+ /**
135
+ * Registers a library rule reference governing this block. The reference
136
+ * (id + pinned `currentHash`) plus the governed `targettedProperty` are
137
+ * folded into the signed structure, so a tampered snapshot cannot add or
138
+ * retarget a rule reference without breaking the hash chain. Creation-time
139
+ * only (rejected once locked); verified against the pre-append state,
140
+ * mirroring `addRule` / `addFunction`.
141
+ */
142
+ addRuleReference(binding: ILibraryRuleReferenceBinding, cryptoProof: IShareDataCryptoProof): void;
143
+ /**
144
+ * Injects the library store used to resolve this block's rule references at
145
+ * change time. This is runtime infrastructure — it is NOT folded into the
146
+ * canonical hash or the signed structure, so setting it does not affect any
147
+ * proof. Replacing the store clears the resolved-rule cache.
148
+ */
149
+ setLibraryStore(store: LibraryStore): void;
150
+ /**
151
+ * Resolves `_ruleReferences` into executable applied rules via the library
152
+ * store, materializing the lean "reference" block into the rules needed to
153
+ * evaluate a change. The result is cached (references are pinned to
154
+ * content-addressed versions, so the resolution is stable). Fail-closed: if
155
+ * references exist but no store was injected, evaluation refuses to proceed
156
+ * rather than silently dropping the governing rules.
157
+ */
158
+ private resolveReferenceRules;
125
159
  /**
126
160
  * Delegates `signerPublicKey` the right to propose runtime transactions for
127
161
  * the given `functionIds` (and ONLY those — least privilege). Creation-time
@@ -193,10 +227,10 @@ export declare class ShareData {
193
227
  * @param proposedData the proposed data
194
228
  * @param transactionFunction the function that was attempted
195
229
  */
196
- addTransactionNotValidated(proposedData: IShareData, transactionFunction: IShareFunction<any, (...args: any[]) => any, any>): {
230
+ addTransactionNotValidated(proposedData: IShareData, transactionFunction: IShareFunction<any, (...args: any[]) => any, any>): Promise<{
197
231
  accepted: boolean;
198
232
  transactionId: string;
199
- };
233
+ }>;
200
234
  /**
201
235
  * Signed runtime mutation path. Verifies that `proof` cryptographically
202
236
  * authorizes applying `transactionFunction` to move this share-data to
@@ -230,10 +264,10 @@ export declare class ShareData {
230
264
  * @param transactionFunction the function producing `proposedData`
231
265
  * @param proof the transaction proposal proof authorizing the change
232
266
  */
233
- addTransaction(proposedData: IShareData, transactionFunction: IShareFunction<any, (...args: any[]) => any, any>, proof: IShareDataCryptoProof): {
267
+ addTransaction(proposedData: IShareData, transactionFunction: IShareFunction<any, (...args: any[]) => any, any>, proof: IShareDataCryptoProof): Promise<{
234
268
  accepted: boolean;
235
269
  transactionId: string;
236
- };
270
+ }>;
237
271
  /**
238
272
  * Shared rule-evaluate → apply-if-valid → record path used by both
239
273
  * {@link addTransactionNotValidated} (no proof) and {@link addTransaction}
@@ -1 +1 @@
1
- {"version":3,"file":"share-data.d.ts","sourceRoot":"","sources":["../../src/share-data/share-data.ts"],"names":[],"mappings":"AACA,OAAO,EACH,UAAU,EACV,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,yBAAyB,EACzB,4BAA4B,EAG5B,qBAAqB,EAErB,uBAAuB,EACvB,2BAA2B,EAK3B,iBAAiB,EAGpB,MAAM,qBAAqB,CAAC;AAI7B;;GAEG;AACH,qBAAa,SAAS;IAClB,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,SAAS,CAAU;IAC3B,OAAO,CAAC,MA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,qBAAqB,GAC7B,IAAI;IAIP;;;;;;;OAOG;IACH,sBAAsB,CAClB,KAAK,EAAE,qBAAqB,EAC5B,YAAY,EAAE,UAAU,GACzB,IAAI;IAQP;;;OAGG;IACH,kBAAkB,CAAC,KAAK,EAAE,qBAAqB,GAAG,IAAI;IAUtD;;OAEG;IACH,UAAU,IAAI,IAAI;CAQrB"}
@@ -31,6 +31,7 @@ class ShareData {
31
31
  this._signingCurve = signingCurve;
32
32
  this._structuralProofs = [];
33
33
  this._authorizedSigners = [];
34
+ this._ruleReferences = [];
34
35
  }
35
36
  /**
36
37
  * This initializes the cryptographic properties of the share data
@@ -150,6 +151,14 @@ class ShareData {
150
151
  get authorizedSigners() {
151
152
  return this._authorizedSigners;
152
153
  }
154
+ /**
155
+ * The library rule references governing this block. Each binding pairs a
156
+ * library reference (id + pinned `currentHash`) with the root property it
157
+ * governs. Frozen after `initialize()` like rules/functions.
158
+ */
159
+ get ruleReferences() {
160
+ return this._ruleReferences;
161
+ }
153
162
  /**
154
163
  * This gets the transaction history for the share block
155
164
  */
@@ -200,6 +209,64 @@ class ShareData {
200
209
  this._structuralProofs.push(cryptoProof);
201
210
  this._rules.push(rule);
202
211
  }
212
+ /**
213
+ * Registers a library rule reference governing this block. The reference
214
+ * (id + pinned `currentHash`) plus the governed `targettedProperty` are
215
+ * folded into the signed structure, so a tampered snapshot cannot add or
216
+ * retarget a rule reference without breaking the hash chain. Creation-time
217
+ * only (rejected once locked); verified against the pre-append state,
218
+ * mirroring `addRule` / `addFunction`.
219
+ */
220
+ addRuleReference(binding, cryptoProof) {
221
+ if (this._isLocked) {
222
+ throw new generic_1.ShareDataIsLockedError(this._id, generic_1.ShareDataTypes.RULE);
223
+ }
224
+ // Pre-append verification: the signer signed over the state before this
225
+ // reference was added.
226
+ this.verifyStructuralProof(cryptoProof);
227
+ this._structuralProofs.push(cryptoProof);
228
+ this._ruleReferences.push(binding);
229
+ }
230
+ /**
231
+ * Injects the library store used to resolve this block's rule references at
232
+ * change time. This is runtime infrastructure — it is NOT folded into the
233
+ * canonical hash or the signed structure, so setting it does not affect any
234
+ * proof. Replacing the store clears the resolved-rule cache.
235
+ */
236
+ setLibraryStore(store) {
237
+ this._libraryStore = store;
238
+ this._hydratedReferenceRules = undefined;
239
+ }
240
+ /**
241
+ * Resolves `_ruleReferences` into executable applied rules via the library
242
+ * store, materializing the lean "reference" block into the rules needed to
243
+ * evaluate a change. The result is cached (references are pinned to
244
+ * content-addressed versions, so the resolution is stable). Fail-closed: if
245
+ * references exist but no store was injected, evaluation refuses to proceed
246
+ * rather than silently dropping the governing rules.
247
+ */
248
+ async resolveReferenceRules() {
249
+ if (this._ruleReferences.length === 0) {
250
+ return [];
251
+ }
252
+ if (this._hydratedReferenceRules) {
253
+ return this._hydratedReferenceRules;
254
+ }
255
+ if (!this._libraryStore) {
256
+ throw new generic_1.ShareDataLibraryStoreNotSetError(this._id);
257
+ }
258
+ const resolved = [];
259
+ for (const binding of this._ruleReferences) {
260
+ const { version } = await (0, generic_1.resolveLibraryReference)(binding.reference, this._libraryStore);
261
+ // A rule entity's source is the canonical applied-rule DEFINITION;
262
+ // the binding carries the routed `targettedProperty` as a backstop
263
+ // for sources that predate embedding it.
264
+ const rule = JSON.parse(version.source);
265
+ resolved.push({ ...rule, targettedProperty: rule.targettedProperty ?? binding.targettedProperty });
266
+ }
267
+ this._hydratedReferenceRules = resolved;
268
+ return resolved;
269
+ }
203
270
  /**
204
271
  * Delegates `signerPublicKey` the right to propose runtime transactions for
205
272
  * the given `functionIds` (and ONLY those — least privilege). Creation-time
@@ -320,7 +387,7 @@ class ShareData {
320
387
  * @param proposedData the proposed data
321
388
  * @param transactionFunction the function that was attempted
322
389
  */
323
- addTransactionNotValidated(proposedData, transactionFunction) {
390
+ async addTransactionNotValidated(proposedData, transactionFunction) {
324
391
  return this.evaluateAndApply(proposedData, transactionFunction);
325
392
  }
326
393
  /**
@@ -356,7 +423,7 @@ class ShareData {
356
423
  * @param transactionFunction the function producing `proposedData`
357
424
  * @param proof the transaction proposal proof authorizing the change
358
425
  */
359
- addTransaction(proposedData, transactionFunction, proof) {
426
+ async addTransaction(proposedData, transactionFunction, proof) {
360
427
  // Gate 1: function registered on this block.
361
428
  if (!this._functions.includes(transactionFunction)) {
362
429
  throw new Error('The function is not known');
@@ -392,13 +459,28 @@ class ShareData {
392
459
  * (proof already verified by the caller). When `proof` is supplied it is
393
460
  * recorded on the history entry so the audit log carries the signature.
394
461
  */
395
- evaluateAndApply(proposedData, transactionFunction, proof) {
462
+ async evaluateAndApply(proposedData, transactionFunction, proof) {
396
463
  // make sure the function is known.
397
464
  if (!this._functions.includes(transactionFunction)) {
398
465
  // throw ShareDataFunctionBeingAppliedDoesNotExistOnShareDataError
399
466
  throw new Error('The function is not known');
400
467
  }
401
- const rulesOutcome = (0, rules_1.startRuleEvaluation)(this._id, transactionFunction, this.functions, this._rules, this._currentState, proposedData);
468
+ // Rule gate. The data must actually change (the engine's guard, inlined
469
+ // so the no-op path stays decoupled from the rules module), then the
470
+ // block's rules are evaluated in the SANDBOX (untrusted) under the
471
+ // engine's trusted per-property routing. `evaluateRulesViaSandbox` is
472
+ // faithfulness-proven to match `startRuleEvaluation`'s verdict.
473
+ if (JSON.stringify(this._currentState) === JSON.stringify(proposedData)) {
474
+ throw new generic_1.ShareDataCurrentAndProposalDataMatchesError(this._id);
475
+ }
476
+ // Hydrate any library rule references into executable rules and evaluate
477
+ // them alongside the inline `_rules`. When the block carries no
478
+ // references (every block today), this resolves to `_rules` unchanged.
479
+ const referenceRules = await this.resolveReferenceRules();
480
+ const effectiveRules = referenceRules.length > 0
481
+ ? [...this._rules, ...referenceRules]
482
+ : this._rules;
483
+ const rulesOutcome = await (0, rules_1.evaluateRulesViaSandbox)(effectiveRules, this._currentState, proposedData);
402
484
  const transactionTime = Date.now();
403
485
  const transactionId = (this._transactionHistory.length + 1).toString();
404
486
  const transaction = {
@@ -426,6 +508,9 @@ class ShareData {
426
508
  // return share data with a new ID
427
509
  const newShareData = new ShareData(`${this._id}-${transactionNumber}`, publicKey);
428
510
  newShareData._rules = [...this._rules];
511
+ newShareData._ruleReferences = [...this._ruleReferences];
512
+ // Carry the resolver so a copied block can still hydrate its references.
513
+ newShareData._libraryStore = this._libraryStore;
429
514
  newShareData._functions = [...this._functions];
430
515
  newShareData._transactionHistory = [...this._transactionHistory];
431
516
  newShareData._events = [...this._events];
@@ -485,6 +570,3 @@ class ShareData {
485
570
  }
486
571
  }
487
572
  exports.ShareData = ShareData;
488
- const itiem2 = new ShareData('1', '1234');
489
- const item = new ShareData('1', '1234');
490
- item.initialize();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@degenerate/sharedata",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "This contains the ShareData Adaptive Framework Ecosystem (SAFE) network core code",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -49,10 +49,10 @@
49
49
  "url": "https://github.com/syncrude/safe/issues"
50
50
  },
51
51
  "homepage": "https://github.com/syncrude/safe#readme",
52
- "gitHead": "c8c1a2f456cdb01a74f85779275b246361e33b81",
52
+ "gitHead": "1f747e160c9022863c7b2d7b8a6a157f204be95b",
53
53
  "dependencies": {
54
- "@degenerate/generic": "^0.6.0",
55
- "@degenerate/rules": "^0.6.0",
54
+ "@degenerate/generic": "^0.7.0",
55
+ "@degenerate/rules": "^0.7.0",
56
56
  "zod": "^4.4.3"
57
57
  },
58
58
  "engines": {