@degenerate/generic 0.6.0 → 0.7.1

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 (103) hide show
  1. package/dist/errors/index.d.ts +1 -0
  2. package/dist/errors/index.d.ts.map +1 -1
  3. package/dist/errors/index.js +1 -0
  4. package/dist/errors/library/library-errors.d.ts +101 -0
  5. package/dist/errors/library/library-errors.d.ts.map +1 -0
  6. package/dist/errors/library/library-errors.js +133 -0
  7. package/dist/errors/share-data/share-data-errors.d.ts +21 -0
  8. package/dist/errors/share-data/share-data-errors.d.ts.map +1 -1
  9. package/dist/errors/share-data/share-data-errors.js +30 -1
  10. package/dist/helpers/apply-share-function.d.ts +23 -0
  11. package/dist/helpers/apply-share-function.d.ts.map +1 -0
  12. package/dist/helpers/apply-share-function.js +32 -0
  13. package/dist/helpers/index.d.ts +1 -0
  14. package/dist/helpers/index.d.ts.map +1 -1
  15. package/dist/helpers/index.js +1 -0
  16. package/dist/index.d.ts +2 -0
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +2 -0
  19. package/dist/library/authorize-library.d.ts +17 -0
  20. package/dist/library/authorize-library.d.ts.map +1 -0
  21. package/dist/library/authorize-library.js +39 -0
  22. package/dist/library/build-library.d.ts +49 -0
  23. package/dist/library/build-library.d.ts.map +1 -0
  24. package/dist/library/build-library.js +119 -0
  25. package/dist/library/caching-library-store.d.ts +19 -0
  26. package/dist/library/caching-library-store.d.ts.map +1 -0
  27. package/dist/library/caching-library-store.js +56 -0
  28. package/dist/library/canonical-json.d.ts +12 -0
  29. package/dist/library/canonical-json.d.ts.map +1 -0
  30. package/dist/library/canonical-json.js +30 -0
  31. package/dist/library/compile-rule-source.d.ts +21 -0
  32. package/dist/library/compile-rule-source.d.ts.map +1 -0
  33. package/dist/library/compile-rule-source.js +91 -0
  34. package/dist/library/evaluate-library-rules.d.ts +36 -0
  35. package/dist/library/evaluate-library-rules.d.ts.map +1 -0
  36. package/dist/library/evaluate-library-rules.js +47 -0
  37. package/dist/library/evaluate-library.d.ts +34 -0
  38. package/dist/library/evaluate-library.d.ts.map +1 -0
  39. package/dist/library/evaluate-library.js +66 -0
  40. package/dist/library/in-memory-library-store.d.ts +22 -0
  41. package/dist/library/in-memory-library-store.d.ts.map +1 -0
  42. package/dist/library/in-memory-library-store.js +92 -0
  43. package/dist/library/index.d.ts +18 -0
  44. package/dist/library/index.d.ts.map +1 -0
  45. package/dist/library/index.js +33 -0
  46. package/dist/library/library-hash.d.ts +9 -0
  47. package/dist/library/library-hash.d.ts.map +1 -0
  48. package/dist/library/library-hash.js +14 -0
  49. package/dist/library/library-models.d.ts +134 -0
  50. package/dist/library/library-models.d.ts.map +1 -0
  51. package/dist/library/library-models.js +84 -0
  52. package/dist/library/library-proof.d.ts +40 -0
  53. package/dist/library/library-proof.d.ts.map +1 -0
  54. package/dist/library/library-proof.js +44 -0
  55. package/dist/library/library-reference.d.ts +75 -0
  56. package/dist/library/library-reference.d.ts.map +1 -0
  57. package/dist/library/library-reference.js +98 -0
  58. package/dist/library/library-server.d.ts +17 -0
  59. package/dist/library/library-server.d.ts.map +1 -0
  60. package/dist/library/library-server.js +45 -0
  61. package/dist/library/library-store.d.ts +37 -0
  62. package/dist/library/library-store.d.ts.map +1 -0
  63. package/dist/library/library-store.js +2 -0
  64. package/dist/library/remote-library-models.d.ts +135 -0
  65. package/dist/library/remote-library-models.d.ts.map +1 -0
  66. package/dist/library/remote-library-models.js +26 -0
  67. package/dist/library/remote-library-store.d.ts +15 -0
  68. package/dist/library/remote-library-store.d.ts.map +1 -0
  69. package/dist/library/remote-library-store.js +59 -0
  70. package/dist/library/verify-library.d.ts +21 -0
  71. package/dist/library/verify-library.d.ts.map +1 -0
  72. package/dist/library/verify-library.js +86 -0
  73. package/dist/models/functions/share-data-function-models.d.ts +6 -74
  74. package/dist/models/functions/share-data-function-models.d.ts.map +1 -1
  75. package/dist/models/functions/share-data-function-models.js +7 -65
  76. package/dist/models/share-data/share-data-models.d.ts +12 -0
  77. package/dist/models/share-data/share-data-models.d.ts.map +1 -1
  78. package/dist/models/shareblock/shareblock-models.js +6 -6
  79. package/dist/sandbox/in-process-executor.d.ts +13 -0
  80. package/dist/sandbox/in-process-executor.d.ts.map +1 -0
  81. package/dist/sandbox/in-process-executor.js +31 -0
  82. package/dist/sandbox/index.d.ts +8 -0
  83. package/dist/sandbox/index.d.ts.map +1 -0
  84. package/dist/sandbox/index.js +23 -0
  85. package/dist/sandbox/remote-sandbox-executor.d.ts +12 -0
  86. package/dist/sandbox/remote-sandbox-executor.d.ts.map +1 -0
  87. package/dist/sandbox/remote-sandbox-executor.js +49 -0
  88. package/dist/sandbox/remote-sandbox-models.d.ts +37 -0
  89. package/dist/sandbox/remote-sandbox-models.d.ts.map +1 -0
  90. package/dist/sandbox/remote-sandbox-models.js +2 -0
  91. package/dist/sandbox/rule-evaluator.d.ts +32 -0
  92. package/dist/sandbox/rule-evaluator.d.ts.map +1 -0
  93. package/dist/sandbox/rule-evaluator.js +23 -0
  94. package/dist/sandbox/run-sandboxed.d.ts +24 -0
  95. package/dist/sandbox/run-sandboxed.d.ts.map +1 -0
  96. package/dist/sandbox/run-sandboxed.js +88 -0
  97. package/dist/sandbox/sandbox-models.d.ts +40 -0
  98. package/dist/sandbox/sandbox-models.d.ts.map +1 -0
  99. package/dist/sandbox/sandbox-models.js +2 -0
  100. package/dist/sandbox/sandbox-server.d.ts +22 -0
  101. package/dist/sandbox/sandbox-server.d.ts.map +1 -0
  102. package/dist/sandbox/sandbox-server.js +62 -0
  103. package/package.json +2 -2
@@ -2,6 +2,7 @@ export * from './audit-log/audit-log-errors';
2
2
  export * from './authorization/authorization-errors';
3
3
  export * from './database/database-errors';
4
4
  export * from './generic/generic-errors';
5
+ export * from './library/library-errors';
5
6
  export * from './request/request-errors';
6
7
  export * from './safe/safe-rules-errors';
7
8
  export * from './scheduler/scheduler-errors';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,sCAAsC,CAAC;AACrD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,uCAAuC,CAAC;AAGtD,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,sCAAsC,CAAC;AACrD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,uCAAuC,CAAC;AAGtD,cAAc,cAAc,CAAC"}
@@ -18,6 +18,7 @@ __exportStar(require("./audit-log/audit-log-errors"), exports);
18
18
  __exportStar(require("./authorization/authorization-errors"), exports);
19
19
  __exportStar(require("./database/database-errors"), exports);
20
20
  __exportStar(require("./generic/generic-errors"), exports);
21
+ __exportStar(require("./library/library-errors"), exports);
21
22
  __exportStar(require("./request/request-errors"), exports);
22
23
  __exportStar(require("./safe/safe-rules-errors"), exports);
23
24
  __exportStar(require("./scheduler/scheduler-errors"), exports);
@@ -0,0 +1,101 @@
1
+ import { BaseError } from '../base-error';
2
+ /**
3
+ * Thrown when a library version's recorded `currentHash` does not match the
4
+ * hash recomputed from its `source` + `previousHash`. The content of the
5
+ * version has been altered (or the hash was forged).
6
+ */
7
+ export declare class LibraryVersionHashMismatchError extends BaseError {
8
+ readonly entityId: string;
9
+ readonly claimedHash: string;
10
+ readonly recomputedHash: string;
11
+ constructor(entityId: string, claimedHash: string, recomputedHash: string);
12
+ }
13
+ /**
14
+ * Thrown when a version's `previousHash` does not equal the `currentHash` of
15
+ * the version before it (the prior version's hash, or the empty seed for the
16
+ * first version). The append-only chain has been broken or reordered.
17
+ */
18
+ export declare class LibraryChainBrokenError extends BaseError {
19
+ readonly entityId: string;
20
+ readonly expectedPreviousHash: string;
21
+ readonly actualPreviousHash: string;
22
+ constructor(entityId: string, expectedPreviousHash: string, actualPreviousHash: string);
23
+ }
24
+ /**
25
+ * Thrown when a version or head proof's Ed25519 signature does not verify
26
+ * against the canonical, purpose-bound payload reconstructed from the record.
27
+ * A signature was forged, or a signed field (including metadata such as
28
+ * `createdAt`, which is bound by the signature though not by the content hash)
29
+ * was tampered with.
30
+ */
31
+ export declare class LibraryProofInvalidError extends BaseError {
32
+ readonly entityId: string;
33
+ readonly proofKind: 'version' | 'head' | 'delegation';
34
+ constructor(entityId: string, proofKind: 'version' | 'head' | 'delegation');
35
+ }
36
+ /**
37
+ * Thrown when a delegation is registered by a key that is not the entity owner.
38
+ * Only the owner (the key that signed the first version) may delegate, which
39
+ * also blocks transitive delegation — a delegate's key is never the owner key,
40
+ * so a delegate can never register further delegates.
41
+ */
42
+ export declare class LibraryDelegationNotAuthorizedError extends BaseError {
43
+ readonly entityId: string;
44
+ readonly attemptedBy: string;
45
+ constructor(entityId: string, attemptedBy: string, reason?: string);
46
+ }
47
+ /**
48
+ * Thrown when a version's signer is neither the entity owner nor a verified
49
+ * delegate. Signature validity alone only proves *someone* signed the version;
50
+ * this proves the *authorized* someone did.
51
+ */
52
+ export declare class LibraryVersionNotAuthorizedError extends BaseError {
53
+ readonly entityId: string;
54
+ readonly signerPublicKey: string;
55
+ constructor(entityId: string, signerPublicKey: string);
56
+ }
57
+ /**
58
+ * Thrown when a store `save` would violate the append-only ledger: the incoming
59
+ * entity truncates or diverges from the stored history rather than extending it.
60
+ * The ledger may only grow, and existing versions may never change.
61
+ */
62
+ export declare class LibraryStoreConflictError extends BaseError {
63
+ readonly entityId: string;
64
+ readonly reason: string;
65
+ constructor(entityId: string, reason: string);
66
+ }
67
+ /**
68
+ * Thrown when an entity is evaluated as the wrong kind — e.g. evaluating a rule
69
+ * entity through the function path. The entity is valid; the call is not.
70
+ */
71
+ export declare class LibraryKindMismatchError extends BaseError {
72
+ readonly entityId: string;
73
+ readonly expected: string;
74
+ readonly actual: string;
75
+ constructor(entityId: string, expected: string, actual: string);
76
+ }
77
+ /** Thrown when a reference resolves to an id the store does not hold. */
78
+ export declare class LibraryEntityNotFoundError extends BaseError {
79
+ readonly entityId: string;
80
+ constructor(entityId: string);
81
+ }
82
+ /**
83
+ * Thrown when a reference pins a `currentHash` that is not present in the
84
+ * entity's version ledger (e.g. a stale or forged reference).
85
+ */
86
+ export declare class LibraryVersionNotFoundError extends BaseError {
87
+ readonly entityId: string;
88
+ readonly currentHash: string;
89
+ constructor(entityId: string, currentHash: string);
90
+ }
91
+ /**
92
+ * Thrown when a library entity is structurally invalid: no versions, an `id`
93
+ * that is not the first version's `currentHash` (identity is content-addressed
94
+ * to the first version), a `head` that does not match the latest version, or an
95
+ * out-of-range `gasLimit`.
96
+ */
97
+ export declare class LibraryEntityInvalidError extends BaseError {
98
+ readonly reason: string;
99
+ constructor(reason: string);
100
+ }
101
+ //# sourceMappingURL=library-errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"library-errors.d.ts","sourceRoot":"","sources":["../../../src/errors/library/library-errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C;;;;GAIG;AACH,qBAAa,+BAAgC,SAAQ,SAAS;IAC1D,SAAgB,QAAQ,EAAE,MAAM,CAAC;IACjC,SAAgB,WAAW,EAAE,MAAM,CAAC;IACpC,SAAgB,cAAc,EAAE,MAAM,CAAC;gBAE3B,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM;CAQ5E;AAED;;;;GAIG;AACH,qBAAa,uBAAwB,SAAQ,SAAS;IAClD,SAAgB,QAAQ,EAAE,MAAM,CAAC;IACjC,SAAgB,oBAAoB,EAAE,MAAM,CAAC;IAC7C,SAAgB,kBAAkB,EAAE,MAAM,CAAC;gBAE/B,QAAQ,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM;CAQzF;AAED;;;;;;GAMG;AACH,qBAAa,wBAAyB,SAAQ,SAAS;IACnD,SAAgB,QAAQ,EAAE,MAAM,CAAC;IACjC,SAAgB,SAAS,EAAE,SAAS,GAAG,MAAM,GAAG,YAAY,CAAC;gBAEjD,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,GAAG,MAAM,GAAG,YAAY;CAK7E;AAED;;;;;GAKG;AACH,qBAAa,mCAAoC,SAAQ,SAAS;IAC9D,SAAgB,QAAQ,EAAE,MAAM,CAAC;IACjC,SAAgB,WAAW,EAAE,MAAM,CAAC;gBAExB,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;CAOrE;AAED;;;;GAIG;AACH,qBAAa,gCAAiC,SAAQ,SAAS;IAC3D,SAAgB,QAAQ,EAAE,MAAM,CAAC;IACjC,SAAgB,eAAe,EAAE,MAAM,CAAC;gBAE5B,QAAQ,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM;CAOxD;AAED;;;;GAIG;AACH,qBAAa,yBAA0B,SAAQ,SAAS;IACpD,SAAgB,QAAQ,EAAE,MAAM,CAAC;IACjC,SAAgB,MAAM,EAAE,MAAM,CAAC;gBAEnB,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CAK/C;AAED;;;GAGG;AACH,qBAAa,wBAAyB,SAAQ,SAAS;IACnD,SAAgB,QAAQ,EAAE,MAAM,CAAC;IACjC,SAAgB,QAAQ,EAAE,MAAM,CAAC;IACjC,SAAgB,MAAM,EAAE,MAAM,CAAC;gBAEnB,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CAMjE;AAED,yEAAyE;AACzE,qBAAa,0BAA2B,SAAQ,SAAS;IACrD,SAAgB,QAAQ,EAAE,MAAM,CAAC;gBAErB,QAAQ,EAAE,MAAM;CAI/B;AAED;;;GAGG;AACH,qBAAa,2BAA4B,SAAQ,SAAS;IACtD,SAAgB,QAAQ,EAAE,MAAM,CAAC;IACjC,SAAgB,WAAW,EAAE,MAAM,CAAC;gBAExB,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM;CAKpD;AAED;;;;;GAKG;AACH,qBAAa,yBAA0B,SAAQ,SAAS;IACpD,SAAgB,MAAM,EAAE,MAAM,CAAC;gBAEnB,MAAM,EAAE,MAAM;CAI7B"}
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LibraryEntityInvalidError = exports.LibraryVersionNotFoundError = exports.LibraryEntityNotFoundError = exports.LibraryKindMismatchError = exports.LibraryStoreConflictError = exports.LibraryVersionNotAuthorizedError = exports.LibraryDelegationNotAuthorizedError = exports.LibraryProofInvalidError = exports.LibraryChainBrokenError = exports.LibraryVersionHashMismatchError = void 0;
4
+ const base_error_1 = require("../base-error");
5
+ /**
6
+ * Thrown when a library version's recorded `currentHash` does not match the
7
+ * hash recomputed from its `source` + `previousHash`. The content of the
8
+ * version has been altered (or the hash was forged).
9
+ */
10
+ class LibraryVersionHashMismatchError extends base_error_1.BaseError {
11
+ constructor(entityId, claimedHash, recomputedHash) {
12
+ super(`Library ${entityId}: version hash mismatch — recorded ${claimedHash}, recomputed ${recomputedHash}.`);
13
+ this.entityId = entityId;
14
+ this.claimedHash = claimedHash;
15
+ this.recomputedHash = recomputedHash;
16
+ }
17
+ }
18
+ exports.LibraryVersionHashMismatchError = LibraryVersionHashMismatchError;
19
+ /**
20
+ * Thrown when a version's `previousHash` does not equal the `currentHash` of
21
+ * the version before it (the prior version's hash, or the empty seed for the
22
+ * first version). The append-only chain has been broken or reordered.
23
+ */
24
+ class LibraryChainBrokenError extends base_error_1.BaseError {
25
+ constructor(entityId, expectedPreviousHash, actualPreviousHash) {
26
+ super(`Library ${entityId}: broken version chain — expected previousHash ${expectedPreviousHash || '<seed>'}, got ${actualPreviousHash || '<seed>'}.`);
27
+ this.entityId = entityId;
28
+ this.expectedPreviousHash = expectedPreviousHash;
29
+ this.actualPreviousHash = actualPreviousHash;
30
+ }
31
+ }
32
+ exports.LibraryChainBrokenError = LibraryChainBrokenError;
33
+ /**
34
+ * Thrown when a version or head proof's Ed25519 signature does not verify
35
+ * against the canonical, purpose-bound payload reconstructed from the record.
36
+ * A signature was forged, or a signed field (including metadata such as
37
+ * `createdAt`, which is bound by the signature though not by the content hash)
38
+ * was tampered with.
39
+ */
40
+ class LibraryProofInvalidError extends base_error_1.BaseError {
41
+ constructor(entityId, proofKind) {
42
+ super(`Library ${entityId}: ${proofKind} proof signature did not verify.`);
43
+ this.entityId = entityId;
44
+ this.proofKind = proofKind;
45
+ }
46
+ }
47
+ exports.LibraryProofInvalidError = LibraryProofInvalidError;
48
+ /**
49
+ * Thrown when a delegation is registered by a key that is not the entity owner.
50
+ * Only the owner (the key that signed the first version) may delegate, which
51
+ * also blocks transitive delegation — a delegate's key is never the owner key,
52
+ * so a delegate can never register further delegates.
53
+ */
54
+ class LibraryDelegationNotAuthorizedError extends base_error_1.BaseError {
55
+ constructor(entityId, attemptedBy, reason) {
56
+ super(`Library ${entityId}: delegation not authorized${reason ? ` (${reason})` : ''} — attempted by ${attemptedBy}.`);
57
+ this.entityId = entityId;
58
+ this.attemptedBy = attemptedBy;
59
+ }
60
+ }
61
+ exports.LibraryDelegationNotAuthorizedError = LibraryDelegationNotAuthorizedError;
62
+ /**
63
+ * Thrown when a version's signer is neither the entity owner nor a verified
64
+ * delegate. Signature validity alone only proves *someone* signed the version;
65
+ * this proves the *authorized* someone did.
66
+ */
67
+ class LibraryVersionNotAuthorizedError extends base_error_1.BaseError {
68
+ constructor(entityId, signerPublicKey) {
69
+ super(`Library ${entityId}: version signer ${signerPublicKey} is not the owner or an authorized delegate.`);
70
+ this.entityId = entityId;
71
+ this.signerPublicKey = signerPublicKey;
72
+ }
73
+ }
74
+ exports.LibraryVersionNotAuthorizedError = LibraryVersionNotAuthorizedError;
75
+ /**
76
+ * Thrown when a store `save` would violate the append-only ledger: the incoming
77
+ * entity truncates or diverges from the stored history rather than extending it.
78
+ * The ledger may only grow, and existing versions may never change.
79
+ */
80
+ class LibraryStoreConflictError extends base_error_1.BaseError {
81
+ constructor(entityId, reason) {
82
+ super(`Library ${entityId}: store conflict — ${reason}.`);
83
+ this.entityId = entityId;
84
+ this.reason = reason;
85
+ }
86
+ }
87
+ exports.LibraryStoreConflictError = LibraryStoreConflictError;
88
+ /**
89
+ * Thrown when an entity is evaluated as the wrong kind — e.g. evaluating a rule
90
+ * entity through the function path. The entity is valid; the call is not.
91
+ */
92
+ class LibraryKindMismatchError extends base_error_1.BaseError {
93
+ constructor(entityId, expected, actual) {
94
+ super(`Library ${entityId}: expected a ${expected} entity, got a ${actual}.`);
95
+ this.entityId = entityId;
96
+ this.expected = expected;
97
+ this.actual = actual;
98
+ }
99
+ }
100
+ exports.LibraryKindMismatchError = LibraryKindMismatchError;
101
+ /** Thrown when a reference resolves to an id the store does not hold. */
102
+ class LibraryEntityNotFoundError extends base_error_1.BaseError {
103
+ constructor(entityId) {
104
+ super(`Library ${entityId}: entity not found in store.`);
105
+ this.entityId = entityId;
106
+ }
107
+ }
108
+ exports.LibraryEntityNotFoundError = LibraryEntityNotFoundError;
109
+ /**
110
+ * Thrown when a reference pins a `currentHash` that is not present in the
111
+ * entity's version ledger (e.g. a stale or forged reference).
112
+ */
113
+ class LibraryVersionNotFoundError extends base_error_1.BaseError {
114
+ constructor(entityId, currentHash) {
115
+ super(`Library ${entityId}: no version ${currentHash} in the ledger.`);
116
+ this.entityId = entityId;
117
+ this.currentHash = currentHash;
118
+ }
119
+ }
120
+ exports.LibraryVersionNotFoundError = LibraryVersionNotFoundError;
121
+ /**
122
+ * Thrown when a library entity is structurally invalid: no versions, an `id`
123
+ * that is not the first version's `currentHash` (identity is content-addressed
124
+ * to the first version), a `head` that does not match the latest version, or an
125
+ * out-of-range `gasLimit`.
126
+ */
127
+ class LibraryEntityInvalidError extends base_error_1.BaseError {
128
+ constructor(reason) {
129
+ super(`Library entity invalid: ${reason}.`);
130
+ this.reason = reason;
131
+ }
132
+ }
133
+ exports.LibraryEntityInvalidError = LibraryEntityInvalidError;
@@ -1,6 +1,19 @@
1
+ import { z } from 'zod';
1
2
  import { BaseError } from '../base-error';
2
3
  import { ShareDataTypes } from '../../models/share-data/share-data-models';
3
4
  import { IShareDataFunction } from '../../models/functions/share-data-function-models';
5
+ /**
6
+ * Thrown when a share function's runtime input fails its declared
7
+ * `inputSchema` (input well-formedness). Distinct from a stateful no-op: a
8
+ * malformed input is a caller/attacker error, surfaced explicitly rather than
9
+ * collapsed into a silent "no change". Carries the function id and the Zod
10
+ * issue list so callers (and HTTP layers) can render a precise rejection.
11
+ */
12
+ export declare class ShareFunctionInputInvalidError extends BaseError {
13
+ readonly functionId?: string;
14
+ readonly issues: z.ZodError['issues'];
15
+ constructor(functionId: string | undefined, error: z.ZodError);
16
+ }
4
17
  /**
5
18
  * This error is thrown when a function is tried to be applied to the share data thats state is locked.
6
19
  */
@@ -19,6 +32,14 @@ export declare class ShareDataCurrentAndProposalDataMatchesError extends BaseErr
19
32
  */
20
33
  constructor(shareDataId: string);
21
34
  }
35
+ /**
36
+ * Thrown when a block carries library rule references but no library store has
37
+ * been injected to resolve them. Fail-closed: rather than silently skip the
38
+ * governing rules, evaluation refuses to proceed.
39
+ */
40
+ export declare class ShareDataLibraryStoreNotSetError extends BaseError {
41
+ constructor(shareDataId: string);
42
+ }
22
43
  /**
23
44
  * This error is thrown when the share data integrity check fails.
24
45
  */
@@ -1 +1 @@
1
- {"version":3,"file":"share-data-errors.d.ts","sourceRoot":"","sources":["../../../src/errors/share-data/share-data-errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,2CAA2C,CAAC;AAC3E,OAAO,EAAE,kBAAkB,EAAE,MAAM,mDAAmD,CAAC;AAEvF;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,SAAS;IACjD;;OAEG;gBACS,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,cAAc;CAGjE;AAED;;GAEG;AACH,qBAAa,2CAA4C,SAAQ,SAAS;IACtE;;OAEG;gBACS,WAAW,EAAE,MAAM;CAGlC;AAED;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,SAAS;IAClD;;OAEG;gBACS,WAAW,EAAE,MAAM;CAGlC;AAED;;GAEG;AACH,qBAAa,yDAA0D,SAAQ,SAAS;IACpF;;OAEG;gBACS,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;CAI5E;AAGD;;GAEG;AACH,qBAAa,6BAA8B,SAAQ,SAAS;IACxD;;OAEG;gBACS,WAAW,EAAE,MAAM,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM;CAIjG;AAKD;;GAEG;AACH,qBAAa,yCAA0C,SAAQ,SAAS;IACpE;;OAEG;gBACS,MAAM,EAAE,MAAM;CAG7B;AAED;;GAEG;AACH,qBAAa,0CAA2C,SAAQ,SAAS;IACrE;;OAEG;gBACS,MAAM,EAAE,MAAM;CAG7B;AAID;;GAEG;AACH,qBAAa,2BAA4B,SAAQ,SAAS;gBAC1C,WAAW,EAAE,MAAM;CAGlC;AAED;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,SAAS;gBACrC,WAAW,EAAE,MAAM;CAGlC;AAED;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,SAAS;gBACtC,WAAW,EAAE,MAAM;CAGlC;AAED;;GAEG;AACH,qBAAa,iCAAkC,SAAQ,SAAS;gBAChD,WAAW,EAAE,MAAM;CAGlC;AAED;;GAEG;AACH,qBAAa,6CAA8C,SAAQ,SAAS;gBAC5D,WAAW,EAAE,MAAM;CAGlC;AAED;;GAEG;AACH,qBAAa,+BAAgC,SAAQ,SAAS;gBAC9C,WAAW,EAAE,MAAM;CAGlC;AAED;;GAEG;AACH,qBAAa,0CAA2C,SAAQ,SAAS;gBACzD,WAAW,EAAE,MAAM;CAGlC;AAED;;GAEG;AACH,qBAAa,mCAAoC,SAAQ,SAAS;gBAClD,WAAW,EAAE,MAAM;CAGlC;AAED;;;;;;;;;GASG;AACH,qBAAa,oCAAqC,SAAQ,SAAS;gBACnD,WAAW,EAAE,MAAM;CAGlC;AAED;;;;;;;;;GASG;AACH,qBAAa,sCAAuC,SAAQ,SAAS;gBACrD,WAAW,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM;CAM5D;AAED;;;;;;;;;GASG;AACH,qBAAa,qCAAsC,SAAQ,SAAS;gBACpD,WAAW,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM;CAOhE;AAED;;;GAGG;AACH,qBAAa,sCAAuC,SAAQ,SAAS;gBACrD,WAAW,EAAE,MAAM;CAIlC;AAED;;;;;;GAMG;AACH,qBAAa,yBAA0B,SAAQ,SAAS;gBACxC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CAGlD"}
1
+ {"version":3,"file":"share-data-errors.d.ts","sourceRoot":"","sources":["../../../src/errors/share-data/share-data-errors.ts"],"names":[],"mappings":"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"}
@@ -1,7 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ShareDataPersistenceError = exports.ShareDataPreviousHashNotAvailableError = exports.ShareDataDelegationNotAuthorizedError = exports.ShareDataTransactionNotAuthorizedError = exports.ShareDataTransactionProofFailedError = exports.ShareDataStructuralProofFailedError = exports.ShareDataStructuralProofAlreadyExistsError = exports.ShareDataCryptoProofFailedError = exports.CryptoInitializationPublicKeyIsDifferentError = exports.ShareDataCryptoAlreadyExistsError = exports.ShareDataDuplicateError = exports.ShareDataNotFoundError = exports.ShareDataAlreadyExistsError = exports.ShareRuleProposedConditionsNotPresentError = exports.ShareRuleCurrentConditionsNotPresentError = exports.ShareDataFunctionHashNotValid = exports.ShareDataFunctionBeingAppliedDoesNotExistOnShareDataError = exports.ShareDataIntegrityError = exports.ShareDataCurrentAndProposalDataMatchesError = exports.ShareDataIsLockedError = void 0;
3
+ exports.ShareDataPersistenceError = exports.ShareDataPreviousHashNotAvailableError = exports.ShareDataDelegationNotAuthorizedError = exports.ShareDataTransactionNotAuthorizedError = exports.ShareDataTransactionProofFailedError = exports.ShareDataStructuralProofFailedError = exports.ShareDataStructuralProofAlreadyExistsError = exports.ShareDataCryptoProofFailedError = exports.CryptoInitializationPublicKeyIsDifferentError = exports.ShareDataCryptoAlreadyExistsError = exports.ShareDataDuplicateError = exports.ShareDataNotFoundError = exports.ShareDataAlreadyExistsError = exports.ShareRuleProposedConditionsNotPresentError = exports.ShareRuleCurrentConditionsNotPresentError = exports.ShareDataFunctionHashNotValid = exports.ShareDataFunctionBeingAppliedDoesNotExistOnShareDataError = exports.ShareDataIntegrityError = exports.ShareDataLibraryStoreNotSetError = exports.ShareDataCurrentAndProposalDataMatchesError = exports.ShareDataIsLockedError = exports.ShareFunctionInputInvalidError = void 0;
4
4
  const base_error_1 = require("../base-error");
5
+ /**
6
+ * Thrown when a share function's runtime input fails its declared
7
+ * `inputSchema` (input well-formedness). Distinct from a stateful no-op: a
8
+ * malformed input is a caller/attacker error, surfaced explicitly rather than
9
+ * collapsed into a silent "no change". Carries the function id and the Zod
10
+ * issue list so callers (and HTTP layers) can render a precise rejection.
11
+ */
12
+ class ShareFunctionInputInvalidError extends base_error_1.BaseError {
13
+ constructor(functionId, error) {
14
+ const detail = error.issues
15
+ .map((issue) => `${issue.path.join('.') || '(root)'}: ${issue.message}`)
16
+ .join('; ');
17
+ super(`Input for share function ${functionId ?? '(anonymous)'} is invalid: ${detail}`);
18
+ this.functionId = functionId;
19
+ this.issues = error.issues;
20
+ }
21
+ }
22
+ exports.ShareFunctionInputInvalidError = ShareFunctionInputInvalidError;
5
23
  /**
6
24
  * This error is thrown when a function is tried to be applied to the share data thats state is locked.
7
25
  */
@@ -26,6 +44,17 @@ class ShareDataCurrentAndProposalDataMatchesError extends base_error_1.BaseError
26
44
  }
27
45
  }
28
46
  exports.ShareDataCurrentAndProposalDataMatchesError = ShareDataCurrentAndProposalDataMatchesError;
47
+ /**
48
+ * Thrown when a block carries library rule references but no library store has
49
+ * been injected to resolve them. Fail-closed: rather than silently skip the
50
+ * governing rules, evaluation refuses to proceed.
51
+ */
52
+ class ShareDataLibraryStoreNotSetError extends base_error_1.BaseError {
53
+ constructor(shareDataId) {
54
+ super(`Share data with id ${shareDataId} has rule references but no library store set to resolve them.`);
55
+ }
56
+ }
57
+ exports.ShareDataLibraryStoreNotSetError = ShareDataLibraryStoreNotSetError;
29
58
  /**
30
59
  * This error is thrown when the share data integrity check fails.
31
60
  */
@@ -0,0 +1,23 @@
1
+ import { IShareFunction } from '../models/share-data/share-data-models';
2
+ /**
3
+ * Validates a share function's runtime input against its declared
4
+ * `inputSchema`, if any. Opt-in: a function with no schema is not checked.
5
+ * Throws {@link ShareFunctionInputInvalidError} (carrying the function id and
6
+ * the Zod issues) on a malformed input — input well-formedness only; stateful
7
+ * legality stays in `func` / the rule engine.
8
+ */
9
+ export declare const validateShareFunctionInput: (fn: Pick<IShareFunction<unknown, any, unknown>, "id" | "inputSchema">, input: unknown) => void;
10
+ /**
11
+ * The single place a share function turns an `input` into a proposed state:
12
+ * validate the input first (throwing on malformed), then run `func`. Both
13
+ * application points (`safeSubmitTransaction` and the manager proposer) route
14
+ * through here, so the input contract cannot be silently bypassed.
15
+ */
16
+ export declare const applyShareFunction: <TState, TInput>(fn: IShareFunction<{
17
+ current: TState;
18
+ input: TInput;
19
+ }, (args: {
20
+ current: TState;
21
+ input: TInput;
22
+ }) => TState, TState>, current: TState, input: TInput) => TState;
23
+ //# sourceMappingURL=apply-share-function.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apply-share-function.d.ts","sourceRoot":"","sources":["../../src/helpers/apply-share-function.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AAExE;;;;;;GAMG;AACH,eAAO,MAAM,0BAA0B,GACnC,IAAI,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,IAAI,GAAG,aAAa,CAAC,EACrE,OAAO,OAAO,KACf,IAQF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAAI,MAAM,EAAE,MAAM,EAC7C,IAAI,cAAc,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,EAAE,CAAC,IAAI,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,KAAK,MAAM,EAAE,MAAM,CAAC,EACpH,SAAS,MAAM,EACf,OAAO,MAAM,KACd,MAGF,CAAC"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.applyShareFunction = exports.validateShareFunctionInput = void 0;
4
+ const share_data_errors_1 = require("../errors/share-data/share-data-errors");
5
+ /**
6
+ * Validates a share function's runtime input against its declared
7
+ * `inputSchema`, if any. Opt-in: a function with no schema is not checked.
8
+ * Throws {@link ShareFunctionInputInvalidError} (carrying the function id and
9
+ * the Zod issues) on a malformed input — input well-formedness only; stateful
10
+ * legality stays in `func` / the rule engine.
11
+ */
12
+ const validateShareFunctionInput = (fn, input) => {
13
+ if (!fn.inputSchema) {
14
+ return; // opt-in: no schema, no check
15
+ }
16
+ const result = fn.inputSchema.safeParse(input);
17
+ if (!result.success) {
18
+ throw new share_data_errors_1.ShareFunctionInputInvalidError(fn.id, result.error);
19
+ }
20
+ };
21
+ exports.validateShareFunctionInput = validateShareFunctionInput;
22
+ /**
23
+ * The single place a share function turns an `input` into a proposed state:
24
+ * validate the input first (throwing on malformed), then run `func`. Both
25
+ * application points (`safeSubmitTransaction` and the manager proposer) route
26
+ * through here, so the input contract cannot be silently bypassed.
27
+ */
28
+ const applyShareFunction = (fn, current, input) => {
29
+ (0, exports.validateShareFunctionInput)(fn, input);
30
+ return fn.func({ current, input });
31
+ };
32
+ exports.applyShareFunction = applyShareFunction;
@@ -1,6 +1,7 @@
1
1
  export * from './id-helpers';
2
2
  export * from './object-helpers';
3
3
  export * from './object-validation-helpers';
4
+ export * from './apply-share-function';
4
5
  export * from './request/params-object-helpers';
5
6
  export * from './request/query-object-helpers';
6
7
  export * from './request/request-object-helpers';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,6BAA6B,CAAC;AAM5C,cAAc,iCAAiC,CAAC;AAChD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,kCAAkC,CAAC;AAKjD,cAAc,uBAAuB,CAAC;AACtC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wBAAwB,CAAC;AAMvC,cAAc,iCAAiC,CAAC;AAChD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,kCAAkC,CAAC;AAKjD,cAAc,uBAAuB,CAAC;AACtC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC"}
@@ -18,6 +18,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
18
18
  __exportStar(require("./id-helpers"), exports);
19
19
  __exportStar(require("./object-helpers"), exports);
20
20
  __exportStar(require("./object-validation-helpers"), exports);
21
+ __exportStar(require("./apply-share-function"), exports);
21
22
  // #endregion main exports
22
23
  // #region request exports
23
24
  __exportStar(require("./request/params-object-helpers"), exports);
package/dist/index.d.ts CHANGED
@@ -5,5 +5,7 @@ export * from './authorization';
5
5
  export * from './crypto';
6
6
  export * from './errors';
7
7
  export * from './helpers';
8
+ export * from './library';
8
9
  export * from './models';
10
+ export * from './sandbox';
9
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,kCAAkC,CAAC;AACjD,cAAc,mCAAmC,CAAC;AAClD,cAAc,+BAA+B,CAAC;AAM9C,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,kCAAkC,CAAC;AACjD,cAAc,mCAAmC,CAAC;AAClD,cAAc,+BAA+B,CAAC;AAM9C,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC"}
package/dist/index.js CHANGED
@@ -25,4 +25,6 @@ __exportStar(require("./authorization"), exports);
25
25
  __exportStar(require("./crypto"), exports);
26
26
  __exportStar(require("./errors"), exports);
27
27
  __exportStar(require("./helpers"), exports);
28
+ __exportStar(require("./library"), exports);
28
29
  __exportStar(require("./models"), exports);
30
+ __exportStar(require("./sandbox"), exports);
@@ -0,0 +1,17 @@
1
+ import { ILibraryDelegation, ILibraryEntity } from './library-models';
2
+ /**
3
+ * Whether `delegation` is a genuine, owner-signed grant for this entity: its
4
+ * proof must be signed by the entity owner over the canonical, purpose-bound
5
+ * payload that binds the entity id and the granted key. A forged delegation
6
+ * entry (no valid owner signature) returns `false`.
7
+ */
8
+ export declare const isValidLibraryDelegation: (entity: ILibraryEntity, delegation: ILibraryDelegation) => boolean;
9
+ /**
10
+ * Whether `publicKey` may append a version to `entity`: the owner is always
11
+ * authorized; a delegated key is authorized only if it carries a valid,
12
+ * owner-signed delegation. This is the single predicate behind the append gate
13
+ * and the per-version authorization check in `verifyLibraryEntity`, so the live
14
+ * and verify paths cannot drift.
15
+ */
16
+ export declare const isLibraryAuthorizedSigner: (entity: ILibraryEntity, publicKey: string) => boolean;
17
+ //# sourceMappingURL=authorize-library.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorize-library.d.ts","sourceRoot":"","sources":["../../src/library/authorize-library.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGtE;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,GACjC,QAAQ,cAAc,EACtB,YAAY,kBAAkB,KAC/B,OAYF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,yBAAyB,GAAI,QAAQ,cAAc,EAAE,WAAW,MAAM,KAAG,OAQrF,CAAC"}
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isLibraryAuthorizedSigner = exports.isValidLibraryDelegation = void 0;
4
+ const verify_ed25519_signature_1 = require("../crypto/signature/verify-ed25519-signature");
5
+ const library_proof_1 = require("./library-proof");
6
+ /**
7
+ * Whether `delegation` is a genuine, owner-signed grant for this entity: its
8
+ * proof must be signed by the entity owner over the canonical, purpose-bound
9
+ * payload that binds the entity id and the granted key. A forged delegation
10
+ * entry (no valid owner signature) returns `false`.
11
+ */
12
+ const isValidLibraryDelegation = (entity, delegation) => {
13
+ // Only the owner may delegate; the proof must be the owner's signature.
14
+ if (delegation.proof.publicKey !== entity.owner.publicKey) {
15
+ return false;
16
+ }
17
+ const payload = (0, library_proof_1.buildDelegationProofPayload)({
18
+ id: entity.id,
19
+ signerPublicKey: delegation.signerPublicKey,
20
+ purpose: (0, library_proof_1.delegatePurpose)(entity.kind),
21
+ publicKey: entity.owner.publicKey,
22
+ });
23
+ return (0, verify_ed25519_signature_1.verifyEd25519Signature)(entity.owner.publicKey, payload, delegation.proof.signature);
24
+ };
25
+ exports.isValidLibraryDelegation = isValidLibraryDelegation;
26
+ /**
27
+ * Whether `publicKey` may append a version to `entity`: the owner is always
28
+ * authorized; a delegated key is authorized only if it carries a valid,
29
+ * owner-signed delegation. This is the single predicate behind the append gate
30
+ * and the per-version authorization check in `verifyLibraryEntity`, so the live
31
+ * and verify paths cannot drift.
32
+ */
33
+ const isLibraryAuthorizedSigner = (entity, publicKey) => {
34
+ if (publicKey === entity.owner.publicKey) {
35
+ return true;
36
+ }
37
+ return entity.delegations.some((delegation) => delegation.signerPublicKey === publicKey && (0, exports.isValidLibraryDelegation)(entity, delegation));
38
+ };
39
+ exports.isLibraryAuthorizedSigner = isLibraryAuthorizedSigner;
@@ -0,0 +1,49 @@
1
+ import { ILibraryEntity, LibraryEntityKind } from './library-models';
2
+ export interface CreateLibraryEntityArgs {
3
+ kind: LibraryEntityKind;
4
+ name: string;
5
+ description: string;
6
+ gasLimit: number;
7
+ /** The stringified function/rule source for the first version. */
8
+ source: string;
9
+ /** 32-byte Ed25519 secret seed (hex) — becomes the entity owner. */
10
+ privateKey: string;
11
+ /** Defaults to `Date.now()`. Signed, but not part of the content hash. */
12
+ createdAt?: number;
13
+ }
14
+ export interface AppendLibraryVersionArgs {
15
+ source: string;
16
+ privateKey: string;
17
+ createdAt?: number;
18
+ }
19
+ /**
20
+ * Creates a new library entity from its first version. The entity `id` is the
21
+ * first version's `currentHash` (content-addressed identity); the signing key
22
+ * becomes the entity owner.
23
+ */
24
+ export declare const createLibraryEntity: (args: CreateLibraryEntityArgs) => ILibraryEntity;
25
+ export interface AddLibraryDelegateArgs {
26
+ /** The key being granted append rights. */
27
+ signerPublicKey: string;
28
+ /** Must be the entity owner's private key — only the owner may delegate. */
29
+ ownerPrivateKey: string;
30
+ createdAt?: number;
31
+ }
32
+ /**
33
+ * Grants `signerPublicKey` the right to append versions, signed by the owner.
34
+ * Returns a new entity (the input is not mutated). Rejects with
35
+ * {@link LibraryDelegationNotAuthorizedError} if the signing key is not the
36
+ * owner (which also blocks a delegate from re-delegating — a delegate's key is
37
+ * never the owner key) or if the grant targets the owner itself.
38
+ */
39
+ export declare const addLibraryDelegate: (entity: ILibraryEntity, args: AddLibraryDelegateArgs) => ILibraryEntity;
40
+ /**
41
+ * Appends a new signed version to an entity's ledger and returns a new entity
42
+ * (the input is not mutated). The new version chains to the prior tip via
43
+ * `previousHash`, and a fresh head proof is minted over the new tip.
44
+ *
45
+ * Gated: the signer must be the owner or a verified delegate
46
+ * ({@link isLibraryAuthorizedSigner}), else {@link LibraryVersionNotAuthorizedError}.
47
+ */
48
+ export declare const appendLibraryVersion: (entity: ILibraryEntity, args: AppendLibraryVersionArgs) => ILibraryEntity;
49
+ //# sourceMappingURL=build-library.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-library.d.ts","sourceRoot":"","sources":["../../src/library/build-library.ts"],"names":[],"mappings":"AASA,OAAO,EAEH,cAAc,EAGd,iBAAiB,EAGpB,MAAM,kBAAkB,CAAC;AAU1B,MAAM,WAAW,uBAAuB;IACpC,IAAI,EAAE,iBAAiB,CAAC;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,kEAAkE;IAClE,MAAM,EAAE,MAAM,CAAC;IACf,oEAAoE;IACpE,UAAU,EAAE,MAAM,CAAC;IACnB,0EAA0E;IAC1E,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,wBAAwB;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAiDD;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAAI,MAAM,uBAAuB,KAAG,cAuBnE,CAAC;AAEF,MAAM,WAAW,sBAAsB;IACnC,2CAA2C;IAC3C,eAAe,EAAE,MAAM,CAAC;IACxB,4EAA4E;IAC5E,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,GAC3B,QAAQ,cAAc,EACtB,MAAM,sBAAsB,KAC7B,cAqBF,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,GAC7B,QAAQ,cAAc,EACtB,MAAM,wBAAwB,KAC/B,cAeF,CAAC"}