@degenerate/generic 0.2.6 → 0.3.2

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 (162) hide show
  1. package/dist/application/audit-log/additional-ids/create-audit-log-additional-ids-with-query.d.ts.map +1 -1
  2. package/dist/application/audit-log/additional-ids/create-multiple-path-alai.d.ts.map +1 -1
  3. package/dist/application/audit-log/additional-ids/create-query-audit-log-for-alai.d.ts.map +1 -1
  4. package/dist/application/audit-log/create-application-audit-log.d.ts.map +1 -1
  5. package/dist/application/audit-log/create-application-audit-log.js +1 -1
  6. package/dist/application/database/firestore/generics/add-items-to-database.d.ts.map +1 -1
  7. package/dist/application/database/firestore/generics/add-items-to-database.js +2 -2
  8. package/dist/application/database/firestore/generics/add-or-update-items-to-database.d.ts.map +1 -1
  9. package/dist/application/database/firestore/generics/add-or-update-items-to-database.js +3 -3
  10. package/dist/application/database/firestore/generics/create-database-change-information.d.ts.map +1 -1
  11. package/dist/application/database/firestore/generics/delete-items-on-database.d.ts.map +1 -1
  12. package/dist/application/database/firestore/generics/delete-items-on-database.js +2 -2
  13. package/dist/application/database/firestore/generics/get-item-from-database.d.ts.map +1 -1
  14. package/dist/application/database/firestore/generics/get-item-from-database.js +2 -2
  15. package/dist/application/database/firestore/generics/get-items-different-path-on-database.d.ts.map +1 -1
  16. package/dist/application/database/firestore/generics/get-items-different-path-on-database.js +2 -2
  17. package/dist/application/database/firestore/generics/get-items-from-database.d.ts.map +1 -1
  18. package/dist/application/database/firestore/generics/get-items-from-database.js +1 -1
  19. package/dist/application/database/firestore/generics/update-items-on-database.d.ts.map +1 -1
  20. package/dist/application/database/firestore/generics/update-items-on-database.js +2 -2
  21. package/dist/application/database/firestore/generics/update-items-properties-on-database.d.ts.map +1 -1
  22. package/dist/application/database/firestore/generics/update-items-properties-on-database.js +2 -2
  23. package/dist/authorization/index.d.ts +1 -0
  24. package/dist/authorization/index.d.ts.map +1 -1
  25. package/dist/authorization/index.js +1 -0
  26. package/dist/authorization/jwt/keys/create-public-key-pem.d.ts.map +1 -1
  27. package/dist/authorization/jwt/keys/create-secret-key-pem.d.ts.map +1 -1
  28. package/dist/authorization/jwt/sign/create-authorization-issuer.d.ts.map +1 -1
  29. package/dist/authorization/jwt/sign/create-authorization-subject.d.ts.map +1 -1
  30. package/dist/authorization/jwt/sign/create-jwt-options.d.ts +7 -1
  31. package/dist/authorization/jwt/sign/create-jwt-options.d.ts.map +1 -1
  32. package/dist/authorization/jwt/sign/create-jwt-signed-token.d.ts.map +1 -1
  33. package/dist/authorization/jwt/transform/transform-token-payload-to-safe-payload.d.ts.map +1 -1
  34. package/dist/authorization/jwt/verify/get-decoded-jwt-header.d.ts.map +1 -1
  35. package/dist/authorization/jwt/verify/get-decoded-jwt-signed-token-payload.d.ts.map +1 -1
  36. package/dist/authorization/jwt/verify/verify-jwt-signed-token.d.ts.map +1 -1
  37. package/dist/authorization/safe/request/decode-bearer-token.d.ts.map +1 -1
  38. package/dist/authorization/safe/request/decode-safe-request.d.ts.map +1 -1
  39. package/dist/authorization/safe/request/determine-issuer-from-request.d.ts.map +1 -1
  40. package/dist/authorization/safe/request/issuer/determine-issuer-from-bearer-token.d.ts.map +1 -1
  41. package/dist/authorization/safe/request/verify-jwt-bearer-token-for-audience.d.ts +31 -0
  42. package/dist/authorization/safe/request/verify-jwt-bearer-token-for-audience.d.ts.map +1 -0
  43. package/dist/authorization/safe/request/verify-jwt-bearer-token-for-audience.js +50 -0
  44. package/dist/authorization/safe/validation/jwt/payload/verify-authorization-audience.d.ts.map +1 -1
  45. package/dist/authorization/safe/validation/jwt/payload/verify-authorization-expiration-time.d.ts.map +1 -1
  46. package/dist/authorization/safe/validation/jwt/payload/verify-authorization-issued-at-time.d.ts.map +1 -1
  47. package/dist/authorization/safe/validation/jwt/payload/verify-authorization-issuer.d.ts.map +1 -1
  48. package/dist/authorization/safe/validation/jwt/payload/verify-authorization-not-before-time.d.ts.map +1 -1
  49. package/dist/authorization/safe/validation/jwt/payload/verify-authorization-subject.d.ts.map +1 -1
  50. package/dist/authorization/safe/validation/jwt/verify-token-header.d.ts.map +1 -1
  51. package/dist/authorization/safe/validation/jwt/verify-token-payload.d.ts.map +1 -1
  52. package/dist/crypto/calculate-combined-hash.d.ts.map +1 -1
  53. package/dist/crypto/calculate-hash.d.ts +1 -1
  54. package/dist/crypto/calculate-hash.d.ts.map +1 -1
  55. package/dist/crypto/calculate-hash.js +1 -1
  56. package/dist/crypto/index.d.ts +1 -0
  57. package/dist/crypto/index.d.ts.map +1 -1
  58. package/dist/crypto/index.js +1 -0
  59. package/dist/crypto/private-public-keys/create-key-pair-from-mnemonic.d.ts.map +1 -1
  60. package/dist/crypto/private-public-keys/create-key-pair-from-private-key.d.ts.map +1 -1
  61. package/dist/crypto/private-public-keys/create-key-pair-from-private-key.js +1 -1
  62. package/dist/crypto/private-public-keys/create-key-pair-from-public-key.d.ts +11 -0
  63. package/dist/crypto/private-public-keys/create-key-pair-from-public-key.d.ts.map +1 -0
  64. package/dist/crypto/private-public-keys/create-key-pair-from-public-key.js +51 -0
  65. package/dist/crypto/private-public-keys/generation/create-entropy-for-elliptical-curve.d.ts.map +1 -1
  66. package/dist/crypto/private-public-keys/generation/generate-key-pair.d.ts.map +1 -1
  67. package/dist/crypto/private-public-keys/generation/get-private-public-key-from-keypair.d.ts.map +1 -1
  68. package/dist/crypto/signature/create-crypto-signature.d.ts +11 -0
  69. package/dist/crypto/signature/create-crypto-signature.d.ts.map +1 -1
  70. package/dist/crypto/signature/create-crypto-signature.js +14 -1
  71. package/dist/crypto/signature/verify-crypto-signature-by-data.d.ts +4 -0
  72. package/dist/crypto/signature/verify-crypto-signature-by-data.d.ts.map +1 -1
  73. package/dist/crypto/signature/verify-crypto-signature-by-data.js +8 -2
  74. package/dist/crypto/signature/verify-crypto-signature-by-hash.d.ts +4 -0
  75. package/dist/crypto/signature/verify-crypto-signature-by-hash.d.ts.map +1 -1
  76. package/dist/crypto/signature/verify-crypto-signature-by-hash.js +7 -1
  77. package/dist/errors/index.d.ts +2 -0
  78. package/dist/errors/index.d.ts.map +1 -1
  79. package/dist/errors/index.js +2 -0
  80. package/dist/errors/share-data/share-data-errors.d.ts +92 -1
  81. package/dist/errors/share-data/share-data-errors.d.ts.map +1 -1
  82. package/dist/errors/share-data/share-data-errors.js +130 -1
  83. package/dist/errors/shareblock/shareblock-errors.d.ts +40 -0
  84. package/dist/errors/shareblock/shareblock-errors.d.ts.map +1 -0
  85. package/dist/errors/shareblock/shareblock-errors.js +50 -0
  86. package/dist/errors/validation/crypto-validation-errors.d.ts +8 -0
  87. package/dist/errors/validation/crypto-validation-errors.d.ts.map +1 -0
  88. package/dist/errors/validation/crypto-validation-errors.js +15 -0
  89. package/dist/helpers/array/array-helpers.d.ts.map +1 -1
  90. package/dist/helpers/crypto/cryptography-helpers.d.ts.map +1 -1
  91. package/dist/helpers/data/data-helpers.d.ts.map +1 -1
  92. package/dist/helpers/file/file-helpers.d.ts.map +1 -1
  93. package/dist/helpers/id-helpers.d.ts.map +1 -1
  94. package/dist/helpers/lodash/lodash-helpers.d.ts.map +1 -1
  95. package/dist/helpers/object-helpers.d.ts.map +1 -1
  96. package/dist/helpers/object-validation-helpers.d.ts.map +1 -1
  97. package/dist/helpers/request/params-object-helpers.d.ts +6 -6
  98. package/dist/helpers/request/params-object-helpers.d.ts.map +1 -1
  99. package/dist/helpers/request/params-object-helpers.js +11 -11
  100. package/dist/helpers/request/query-object-helpers.d.ts.map +1 -1
  101. package/dist/helpers/request/request-object-helpers.d.ts.map +1 -1
  102. package/dist/models/application/audit-log/application-audit-log-models.d.ts +82 -92
  103. package/dist/models/application/audit-log/application-audit-log-models.d.ts.map +1 -1
  104. package/dist/models/application/database/firestore-models.d.ts +158 -307
  105. package/dist/models/application/database/firestore-models.d.ts.map +1 -1
  106. package/dist/models/authorization/authorization-models.d.ts +34 -44
  107. package/dist/models/authorization/authorization-models.d.ts.map +1 -1
  108. package/dist/models/authorization/authorization-models.js +2 -2
  109. package/dist/models/crypto/crypto-models.d.ts +1 -7
  110. package/dist/models/crypto/crypto-models.d.ts.map +1 -1
  111. package/dist/models/data/data-models.d.ts +27 -13
  112. package/dist/models/data/data-models.d.ts.map +1 -1
  113. package/dist/models/data/data-models.js +23 -2
  114. package/dist/models/dynamic-execution/dynamic-execution-models.d.ts +1 -9
  115. package/dist/models/dynamic-execution/dynamic-execution-models.d.ts.map +1 -1
  116. package/dist/models/events/share-event-models.d.ts +90 -119
  117. package/dist/models/events/share-event-models.d.ts.map +1 -1
  118. package/dist/models/events/share-event-models.js +34 -3
  119. package/dist/models/functions/share-data-function-models.d.ts +23 -193
  120. package/dist/models/functions/share-data-function-models.d.ts.map +1 -1
  121. package/dist/models/functions/share-data-function-models.js +1 -1
  122. package/dist/models/generic/request-response-models.d.ts +1 -7
  123. package/dist/models/generic/request-response-models.d.ts.map +1 -1
  124. package/dist/models/index.d.ts +7 -1
  125. package/dist/models/index.d.ts.map +1 -1
  126. package/dist/models/index.js +7 -1
  127. package/dist/models/rules/share-rule-models.d.ts +759 -1116
  128. package/dist/models/rules/share-rule-models.d.ts.map +1 -1
  129. package/dist/models/rules/share-rule-models.js +6 -6
  130. package/dist/models/safe/safe-transaction-models.d.ts +28 -30
  131. package/dist/models/safe/safe-transaction-models.d.ts.map +1 -1
  132. package/dist/models/safe/transactions/authorities-transactions-models.d.ts +77 -419
  133. package/dist/models/safe/transactions/authorities-transactions-models.d.ts.map +1 -1
  134. package/dist/models/safe/transactions/authorities-transactions-models.js +3 -3
  135. package/dist/models/safe/transactions/events-transactions-models.d.ts +89 -0
  136. package/dist/models/safe/transactions/events-transactions-models.d.ts.map +1 -0
  137. package/dist/models/safe/transactions/events-transactions-models.js +53 -0
  138. package/dist/models/safe/transactions/functions-transactions-models.d.ts +89 -0
  139. package/dist/models/safe/transactions/functions-transactions-models.d.ts.map +1 -0
  140. package/dist/models/safe/transactions/functions-transactions-models.js +53 -0
  141. package/dist/models/safe/transactions/rules-transactions-models.d.ts +59 -603
  142. package/dist/models/safe/transactions/rules-transactions-models.d.ts.map +1 -1
  143. package/dist/models/safe/transactions/sharedata-transactions-models.d.ts +302 -0
  144. package/dist/models/safe/transactions/sharedata-transactions-models.d.ts.map +1 -0
  145. package/dist/models/safe/transactions/sharedata-transactions-models.js +79 -0
  146. package/dist/models/share-data/share-data-crypto-models.d.ts +307 -0
  147. package/dist/models/share-data/share-data-crypto-models.d.ts.map +1 -0
  148. package/dist/models/share-data/share-data-crypto-models.js +91 -0
  149. package/dist/models/share-data/share-data-models.d.ts +114 -0
  150. package/dist/models/share-data/share-data-models.d.ts.map +1 -0
  151. package/dist/models/share-data/{share-data.js → share-data-models.js} +1 -1
  152. package/dist/models/share-data/share-data-persistence-models.d.ts +158 -0
  153. package/dist/models/share-data/share-data-persistence-models.d.ts.map +1 -0
  154. package/dist/models/share-data/share-data-persistence-models.js +94 -0
  155. package/dist/models/shareblock/shareblock-models.d.ts +280 -0
  156. package/dist/models/shareblock/shareblock-models.d.ts.map +1 -0
  157. package/dist/models/shareblock/shareblock-models.js +222 -0
  158. package/dist/transactions/authority/create-safe-transaction-authority-data.d.ts.map +1 -1
  159. package/dist/transactions/authority/create-safe-transaction-authority.d.ts.map +1 -1
  160. package/package.json +32 -21
  161. package/dist/models/share-data/share-data.d.ts +0 -181
  162. package/dist/models/share-data/share-data.d.ts.map +0 -1
@@ -0,0 +1,158 @@
1
+ import z from 'zod';
2
+ import { EllipticalCurvesSigning } from '../../_settings/cryptography-settings';
3
+ import { ShareBlockType } from '../shareblock/shareblock-models';
4
+ /**
5
+ * The signing curve a persisted block was created with. Mirrors the values of
6
+ * {@link EllipticalCurvesSigning}; stored for forward-compatibility even
7
+ * though every shipped factory currently uses the `Curve25519` default.
8
+ */
9
+ export declare const PersistedSigningCurveSchema: z.ZodEnum<{
10
+ ed25519: EllipticalCurvesSigning.Curve25519;
11
+ p521: EllipticalCurvesSigning.P521;
12
+ }>;
13
+ /**
14
+ * The factory creation input needed to replay construction, minus the
15
+ * `proofFor` callback (which is reconstructed from the stored
16
+ * `structuralProofs` + `initialCrypto` at load time). `initialState` is the
17
+ * *partial* state the factory was given — the factory deterministically
18
+ * assembles the full state from it, so storing the partial form is both
19
+ * sufficient and forward-stable.
20
+ */
21
+ export declare const PersistedCreationConfigSchema: z.ZodObject<{
22
+ metadata: z.ZodObject<{
23
+ shareBlockId: z.ZodString;
24
+ blockType: z.ZodEnum<{
25
+ Clearing: "Clearing";
26
+ Funding: "Funding";
27
+ Distribution: "Distribution";
28
+ }>;
29
+ relatedLoanApplicationId: z.ZodOptional<z.ZodString>;
30
+ description: z.ZodOptional<z.ZodString>;
31
+ createdAt: z.ZodNumber;
32
+ createdBy: z.ZodString;
33
+ }, z.core.$strip>;
34
+ creationPublicKey: z.ZodString;
35
+ initialState: z.ZodRecord<z.ZodString, z.ZodAny>;
36
+ }, z.core.$strip>;
37
+ export type PersistedCreationConfig = z.infer<typeof PersistedCreationConfigSchema>;
38
+ /**
39
+ * The two facts a {@link ShareDataManager} must retain about a block to keep
40
+ * persisting it after creation: which factory built it and the creation input
41
+ * that factory was given. A live block retains neither — `serializeShareData`
42
+ * needs both supplied — so the manager captures them at `addShareData` time and
43
+ * carries them alongside the accumulating transaction log for every subsequent
44
+ * write-through. Supplied by the caller that created the block (e.g. the HTTP
45
+ * create route).
46
+ */
47
+ export interface ShareDataCreationRecord {
48
+ blockType: ShareBlockType;
49
+ creationConfig: PersistedCreationConfig;
50
+ }
51
+ /**
52
+ * One post-creation transaction, captured at apply time. The live
53
+ * `transactionHistory` does NOT retain a transaction's input or proposed
54
+ * state, so these must be recorded when the transaction is applied rather
55
+ * than recovered from a finished block.
56
+ *
57
+ * - `functionId` re-resolves the live function on the rebuilt block (same
58
+ * id-based lookup `createIdBasedFunctionResolver` uses).
59
+ * - `proposedState` is the state written when the transaction was accepted;
60
+ * it is what replay re-applies.
61
+ * - `proof` is the transaction proposal proof that authorized the change. It
62
+ * is re-verified against the rebuilt block + `proposedState` during replay,
63
+ * so a snapshot whose proposed state or proof was edited fails the load.
64
+ * Recording it also keeps the rebuilt block byte-faithful: the live history
65
+ * entry carries its proof, and the canonical share-data hash folds the
66
+ * history in, so replay must reproduce the proof to hash identically.
67
+ * - `transactionTime` is stored so the replayed history hashes identically.
68
+ * - `ruleOutcome` records whether the original proposal was accepted.
69
+ */
70
+ export declare const PersistedTransactionSchema: z.ZodObject<{
71
+ functionId: z.ZodString;
72
+ input: z.ZodOptional<z.ZodAny>;
73
+ proposedState: z.ZodRecord<z.ZodString, z.ZodAny>;
74
+ proof: z.ZodObject<{
75
+ publicKey: z.ZodString;
76
+ shareDataHash: z.ZodString;
77
+ shareDataPreviousHash: z.ZodString;
78
+ shareDataSignature: z.ZodString;
79
+ timestamp: z.ZodNumber;
80
+ purpose: z.ZodString;
81
+ }, z.core.$strip>;
82
+ transactionTime: z.ZodNumber;
83
+ ruleOutcome: z.ZodBoolean;
84
+ }, z.core.$strip>;
85
+ export type PersistedTransaction = z.infer<typeof PersistedTransactionSchema>;
86
+ /**
87
+ * A durable snapshot of a ShareData. Versioned via `schemaVersion` so a future
88
+ * format change can be gated cleanly. The `expected*` fields are NOT trusted
89
+ * on load — they are cross-checked against the independently replayed block so
90
+ * a snapshot whose state was edited without re-signing fails loudly.
91
+ */
92
+ export declare const PersistedShareDataSchema: z.ZodObject<{
93
+ schemaVersion: z.ZodLiteral<2>;
94
+ id: z.ZodString;
95
+ blockType: z.ZodEnum<{
96
+ Clearing: "Clearing";
97
+ Funding: "Funding";
98
+ Distribution: "Distribution";
99
+ }>;
100
+ signingCurve: z.ZodEnum<{
101
+ ed25519: EllipticalCurvesSigning.Curve25519;
102
+ p521: EllipticalCurvesSigning.P521;
103
+ }>;
104
+ initialCrypto: z.ZodObject<{
105
+ publicKey: z.ZodString;
106
+ shareDataHash: z.ZodString;
107
+ shareDataSignature: z.ZodString;
108
+ timestamp: z.ZodNumber;
109
+ }, z.core.$strip>;
110
+ creationConfig: z.ZodObject<{
111
+ metadata: z.ZodObject<{
112
+ shareBlockId: z.ZodString;
113
+ blockType: z.ZodEnum<{
114
+ Clearing: "Clearing";
115
+ Funding: "Funding";
116
+ Distribution: "Distribution";
117
+ }>;
118
+ relatedLoanApplicationId: z.ZodOptional<z.ZodString>;
119
+ description: z.ZodOptional<z.ZodString>;
120
+ createdAt: z.ZodNumber;
121
+ createdBy: z.ZodString;
122
+ }, z.core.$strip>;
123
+ creationPublicKey: z.ZodString;
124
+ initialState: z.ZodRecord<z.ZodString, z.ZodAny>;
125
+ }, z.core.$strip>;
126
+ structuralProofs: z.ZodRecord<z.ZodString, z.ZodObject<{
127
+ publicKey: z.ZodString;
128
+ shareDataHash: z.ZodString;
129
+ shareDataPreviousHash: z.ZodString;
130
+ shareDataSignature: z.ZodString;
131
+ timestamp: z.ZodNumber;
132
+ purpose: z.ZodString;
133
+ }, z.core.$strip>>;
134
+ transactionLog: z.ZodArray<z.ZodObject<{
135
+ functionId: z.ZodString;
136
+ input: z.ZodOptional<z.ZodAny>;
137
+ proposedState: z.ZodRecord<z.ZodString, z.ZodAny>;
138
+ proof: z.ZodObject<{
139
+ publicKey: z.ZodString;
140
+ shareDataHash: z.ZodString;
141
+ shareDataPreviousHash: z.ZodString;
142
+ shareDataSignature: z.ZodString;
143
+ timestamp: z.ZodNumber;
144
+ purpose: z.ZodString;
145
+ }, z.core.$strip>;
146
+ transactionTime: z.ZodNumber;
147
+ ruleOutcome: z.ZodBoolean;
148
+ }, z.core.$strip>>;
149
+ expectedCurrentState: z.ZodRecord<z.ZodString, z.ZodAny>;
150
+ expectedCreationHash: z.ZodString;
151
+ expectedCreationSignature: z.ZodString;
152
+ expectedIsLocked: z.ZodBoolean;
153
+ expectedVersion: z.ZodNumber;
154
+ }, z.core.$strip>;
155
+ export type PersistedShareData = z.infer<typeof PersistedShareDataSchema>;
156
+ /** The only schema version this build understands. */
157
+ export declare const PERSISTED_SHARE_DATA_SCHEMA_VERSION: 2;
158
+ //# sourceMappingURL=share-data-persistence-models.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"share-data-persistence-models.d.ts","sourceRoot":"","sources":["../../../src/models/share-data/share-data-persistence-models.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAC;AACpB,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAChF,OAAO,EAEH,cAAc,EAEjB,MAAM,iCAAiC,CAAC;AAkBzC;;;;GAIG;AACH,eAAO,MAAM,2BAA2B;;;EAGtC,CAAC;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,6BAA6B;;;;;;;;;;;;;;;iBAIxC,CAAC;AAEH,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,6BAA6B,CAAC,CAAC;AAEpF;;;;;;;;GAQG;AACH,MAAM,WAAW,uBAAuB;IACpC,SAAS,EAAE,cAAc,CAAC;IAC1B,cAAc,EAAE,uBAAuB,CAAC;CAC3C;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;iBAOrC,CAAC;AAEH,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,0BAA0B,CAAC,CAAC;AAE9E;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAgBnC,CAAC;AAEH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAE1E,sDAAsD;AACtD,eAAO,MAAM,mCAAmC,EAAG,CAAU,CAAC"}
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PERSISTED_SHARE_DATA_SCHEMA_VERSION = exports.PersistedShareDataSchema = exports.PersistedTransactionSchema = exports.PersistedCreationConfigSchema = exports.PersistedSigningCurveSchema = void 0;
7
+ const zod_1 = __importDefault(require("zod"));
8
+ const cryptography_settings_1 = require("../../_settings/cryptography-settings");
9
+ const shareblock_models_1 = require("../shareblock/shareblock-models");
10
+ const share_data_crypto_models_1 = require("./share-data-crypto-models");
11
+ const share_data_models_1 = require("./share-data-models");
12
+ // This file contains the wire-format models for persisting a ShareData to a
13
+ // durable store and reconstructing it. The design is event-sourced: a
14
+ // snapshot stores the *creation recipe* + an ordered transaction log, not a
15
+ // field-dump of a finished object. Reload replays construction (re-verifying
16
+ // the structural-proof chain) and the transaction log, then cross-checks the
17
+ // result against the stored `expected*` integrity values. See
18
+ // `plans/PERSISTENCE_PLAN.html`.
19
+ //#region Persistence Schemas
20
+ /**
21
+ * The signing curve a persisted block was created with. Mirrors the values of
22
+ * {@link EllipticalCurvesSigning}; stored for forward-compatibility even
23
+ * though every shipped factory currently uses the `Curve25519` default.
24
+ */
25
+ exports.PersistedSigningCurveSchema = zod_1.default.enum([
26
+ cryptography_settings_1.EllipticalCurvesSigning.Curve25519,
27
+ cryptography_settings_1.EllipticalCurvesSigning.P521,
28
+ ]);
29
+ /**
30
+ * The factory creation input needed to replay construction, minus the
31
+ * `proofFor` callback (which is reconstructed from the stored
32
+ * `structuralProofs` + `initialCrypto` at load time). `initialState` is the
33
+ * *partial* state the factory was given — the factory deterministically
34
+ * assembles the full state from it, so storing the partial form is both
35
+ * sufficient and forward-stable.
36
+ */
37
+ exports.PersistedCreationConfigSchema = zod_1.default.object({
38
+ metadata: shareblock_models_1.IShareBlockMetadataSchema,
39
+ creationPublicKey: zod_1.default.string(),
40
+ initialState: zod_1.default.record(zod_1.default.string(), zod_1.default.any()),
41
+ });
42
+ /**
43
+ * One post-creation transaction, captured at apply time. The live
44
+ * `transactionHistory` does NOT retain a transaction's input or proposed
45
+ * state, so these must be recorded when the transaction is applied rather
46
+ * than recovered from a finished block.
47
+ *
48
+ * - `functionId` re-resolves the live function on the rebuilt block (same
49
+ * id-based lookup `createIdBasedFunctionResolver` uses).
50
+ * - `proposedState` is the state written when the transaction was accepted;
51
+ * it is what replay re-applies.
52
+ * - `proof` is the transaction proposal proof that authorized the change. It
53
+ * is re-verified against the rebuilt block + `proposedState` during replay,
54
+ * so a snapshot whose proposed state or proof was edited fails the load.
55
+ * Recording it also keeps the rebuilt block byte-faithful: the live history
56
+ * entry carries its proof, and the canonical share-data hash folds the
57
+ * history in, so replay must reproduce the proof to hash identically.
58
+ * - `transactionTime` is stored so the replayed history hashes identically.
59
+ * - `ruleOutcome` records whether the original proposal was accepted.
60
+ */
61
+ exports.PersistedTransactionSchema = zod_1.default.object({
62
+ functionId: zod_1.default.string(),
63
+ input: zod_1.default.any().optional(),
64
+ proposedState: share_data_models_1.IShareDataSchema,
65
+ proof: share_data_crypto_models_1.IShareDataCryptoProofSchema,
66
+ transactionTime: zod_1.default.number(),
67
+ ruleOutcome: zod_1.default.boolean(),
68
+ });
69
+ /**
70
+ * A durable snapshot of a ShareData. Versioned via `schemaVersion` so a future
71
+ * format change can be gated cleanly. The `expected*` fields are NOT trusted
72
+ * on load — they are cross-checked against the independently replayed block so
73
+ * a snapshot whose state was edited without re-signing fails loudly.
74
+ */
75
+ exports.PersistedShareDataSchema = zod_1.default.object({
76
+ schemaVersion: zod_1.default.literal(2),
77
+ id: zod_1.default.string(),
78
+ blockType: shareblock_models_1.ShareBlockTypeSchema,
79
+ signingCurve: exports.PersistedSigningCurveSchema,
80
+ initialCrypto: share_data_crypto_models_1.IShareDataInitialCryptoDataSchema,
81
+ creationConfig: exports.PersistedCreationConfigSchema,
82
+ structuralProofs: share_data_crypto_models_1.ShareDataProofsSchema,
83
+ transactionLog: zod_1.default.array(exports.PersistedTransactionSchema),
84
+ // Integrity cross-checks — compared against the replayed result, never
85
+ // trusted as source of truth.
86
+ expectedCurrentState: share_data_models_1.IShareDataSchema,
87
+ expectedCreationHash: zod_1.default.string(),
88
+ expectedCreationSignature: zod_1.default.string(),
89
+ expectedIsLocked: zod_1.default.boolean(),
90
+ expectedVersion: zod_1.default.number(),
91
+ });
92
+ /** The only schema version this build understands. */
93
+ exports.PERSISTED_SHARE_DATA_SCHEMA_VERSION = 2;
94
+ //#endregion Persistence Schemas
@@ -0,0 +1,280 @@
1
+ import z from 'zod';
2
+ /**
3
+ * The three ShareBlock specializations the platform uses to move money
4
+ * through a loan's lifecycle.
5
+ *
6
+ * - `Clearing` — neutral holding spot funds pass through before they're
7
+ * committed to either side of a deal. Used to net
8
+ * borrower and lender flows before settling.
9
+ * - `Funding` — the lender-funded pool that backs a specific loan.
10
+ * Holds principal between funding and disbursement.
11
+ * - `Distribution` — the destination ShareBlock that pays principal to a
12
+ * borrower or returns/interest to a lender.
13
+ *
14
+ * New ShareBlock variants should be additive — never re-use a value with new
15
+ * semantics, since downstream rule libraries pattern-match on the literal.
16
+ */
17
+ export declare enum ShareBlockType {
18
+ Clearing = "Clearing",
19
+ Funding = "Funding",
20
+ Distribution = "Distribution"
21
+ }
22
+ export declare const ShareBlockTypeSchema: z.ZodEnum<{
23
+ Clearing: "Clearing";
24
+ Funding: "Funding";
25
+ Distribution: "Distribution";
26
+ }>;
27
+ /**
28
+ * Roles a participant plays inside a ShareBlock. A single party may hold
29
+ * multiple roles across different ShareBlocks (e.g. the same uid is `Lender`
30
+ * on a Funding block and `Recipient` on a Distribution block).
31
+ */
32
+ export declare enum ShareBlockParticipantRole {
33
+ Borrower = "Borrower",
34
+ Lender = "Lender",
35
+ Platform = "Platform",
36
+ Recipient = "Recipient"
37
+ }
38
+ export declare const ShareBlockParticipantRoleSchema: z.ZodEnum<{
39
+ Borrower: "Borrower";
40
+ Lender: "Lender";
41
+ Platform: "Platform";
42
+ Recipient: "Recipient";
43
+ }>;
44
+ /**
45
+ * A party in a ShareBlock with their associated role and committed amount.
46
+ * `committedAmount` is the headline contribution promised by the participant;
47
+ * `settledAmount` tracks how much has actually moved (so partial fills are
48
+ * representable). Both are in the ShareBlock's `currency`.
49
+ */
50
+ export declare const IShareBlockParticipantSchema: z.ZodObject<{
51
+ userId: z.ZodString;
52
+ role: z.ZodEnum<{
53
+ Borrower: "Borrower";
54
+ Lender: "Lender";
55
+ Platform: "Platform";
56
+ Recipient: "Recipient";
57
+ }>;
58
+ committedAmount: z.ZodNumber;
59
+ settledAmount: z.ZodNumber;
60
+ }, z.core.$strip>;
61
+ export type IShareBlockParticipant = z.infer<typeof IShareBlockParticipantSchema>;
62
+ /**
63
+ * The mutable state carried inside a ShareBlock's `_currentState`. This is
64
+ * the canonical shape rules and functions inspect when proposing changes.
65
+ *
66
+ * - `balance` — funds currently held in the ShareBlock. Never negative.
67
+ * - `currency` — ISO-4217 code (e.g. `'USD'`, `'CAD'`). Pinned at creation.
68
+ * - `isOpen` — whether the ShareBlock will accept further transactions.
69
+ * Closing is irreversible; once `false`, all standard rules
70
+ * reject mutating proposals.
71
+ * - `participants` — committed parties keyed by `userId`. Adding a
72
+ * participant goes through a rule-gated function so the
73
+ * participant list itself is auditable.
74
+ */
75
+ export declare const IShareBlockStateSchema: z.ZodObject<{
76
+ blockType: z.ZodEnum<{
77
+ Clearing: "Clearing";
78
+ Funding: "Funding";
79
+ Distribution: "Distribution";
80
+ }>;
81
+ balance: z.ZodNumber;
82
+ currency: z.ZodString;
83
+ isOpen: z.ZodBoolean;
84
+ participants: z.ZodRecord<z.ZodString, z.ZodObject<{
85
+ userId: z.ZodString;
86
+ role: z.ZodEnum<{
87
+ Borrower: "Borrower";
88
+ Lender: "Lender";
89
+ Platform: "Platform";
90
+ Recipient: "Recipient";
91
+ }>;
92
+ committedAmount: z.ZodNumber;
93
+ settledAmount: z.ZodNumber;
94
+ }, z.core.$strip>>;
95
+ }, z.core.$strip>;
96
+ export type IShareBlockState = z.infer<typeof IShareBlockStateSchema>;
97
+ /**
98
+ * Funding-specific extension of `IShareBlockState`. Adds:
99
+ *
100
+ * - `committed` — once `true`, the block's funds are locked: deposits and
101
+ * withdrawals become no-ops, and a "committed-is-monotonic"
102
+ * rule blocks any proposal that flips it back to `false`.
103
+ * - `committedBy` / `committedAt` — audit attribution for the commit moment.
104
+ *
105
+ * Clearing ShareBlocks don't carry these fields; the discriminator is the
106
+ * `blockType` on the base state.
107
+ */
108
+ export declare const IFundingShareBlockStateSchema: z.ZodObject<{
109
+ balance: z.ZodNumber;
110
+ currency: z.ZodString;
111
+ isOpen: z.ZodBoolean;
112
+ participants: z.ZodRecord<z.ZodString, z.ZodObject<{
113
+ userId: z.ZodString;
114
+ role: z.ZodEnum<{
115
+ Borrower: "Borrower";
116
+ Lender: "Lender";
117
+ Platform: "Platform";
118
+ Recipient: "Recipient";
119
+ }>;
120
+ committedAmount: z.ZodNumber;
121
+ settledAmount: z.ZodNumber;
122
+ }, z.core.$strip>>;
123
+ blockType: z.ZodLiteral<"Funding">;
124
+ committed: z.ZodBoolean;
125
+ committedBy: z.ZodOptional<z.ZodString>;
126
+ committedAt: z.ZodOptional<z.ZodNumber>;
127
+ }, z.core.$strip>;
128
+ export type IFundingShareBlockState = z.infer<typeof IFundingShareBlockStateSchema>;
129
+ /**
130
+ * Distribution-specific extension of `IShareBlockState`. Adds:
131
+ *
132
+ * - `distributed` — once `true`, the block is fully paid out and further
133
+ * disbursements become no-ops. Enforced as monotonic by
134
+ * a dedicated rule (mirrors Funding's `committed`).
135
+ * - `distributedAt` — audit attribution for the moment the block was
136
+ * marked fully distributed.
137
+ *
138
+ * Clearing ShareBlocks don't carry these fields; the discriminator is the
139
+ * `blockType` on the base state.
140
+ */
141
+ export declare const IDistributionShareBlockStateSchema: z.ZodObject<{
142
+ balance: z.ZodNumber;
143
+ currency: z.ZodString;
144
+ isOpen: z.ZodBoolean;
145
+ participants: z.ZodRecord<z.ZodString, z.ZodObject<{
146
+ userId: z.ZodString;
147
+ role: z.ZodEnum<{
148
+ Borrower: "Borrower";
149
+ Lender: "Lender";
150
+ Platform: "Platform";
151
+ Recipient: "Recipient";
152
+ }>;
153
+ committedAmount: z.ZodNumber;
154
+ settledAmount: z.ZodNumber;
155
+ }, z.core.$strip>>;
156
+ blockType: z.ZodLiteral<"Distribution">;
157
+ distributed: z.ZodBoolean;
158
+ distributedBy: z.ZodOptional<z.ZodString>;
159
+ distributedAt: z.ZodOptional<z.ZodNumber>;
160
+ }, z.core.$strip>;
161
+ export type IDistributionShareBlockState = z.infer<typeof IDistributionShareBlockStateSchema>;
162
+ /**
163
+ * Static information about a ShareBlock — set at construction and never
164
+ * mutated through transactions. Lives outside `IShareBlockState` because
165
+ * the rule-evaluation engine compares state shapes, and including identity
166
+ * metadata in that comparison would treat any new ShareBlock as a "change."
167
+ */
168
+ export declare const IShareBlockMetadataSchema: z.ZodObject<{
169
+ shareBlockId: z.ZodString;
170
+ blockType: z.ZodEnum<{
171
+ Clearing: "Clearing";
172
+ Funding: "Funding";
173
+ Distribution: "Distribution";
174
+ }>;
175
+ relatedLoanApplicationId: z.ZodOptional<z.ZodString>;
176
+ description: z.ZodOptional<z.ZodString>;
177
+ createdAt: z.ZodNumber;
178
+ createdBy: z.ZodString;
179
+ }, z.core.$strip>;
180
+ export type IShareBlockMetadata = z.infer<typeof IShareBlockMetadataSchema>;
181
+ /**
182
+ * Input shape every ShareBlock factory's `initialState` argument accepts.
183
+ * The factory layers the variant-specific defaults on top (`blockType`,
184
+ * `committed: false`, `distributed: false`, `isOpen: true`) — callers only
185
+ * supply the genuinely variant-agnostic fields.
186
+ *
187
+ * Used by the HTTP create route to validate the wire payload before
188
+ * dispatching to the matching factory.
189
+ */
190
+ export declare const IShareBlockInitialStateInputSchema: z.ZodObject<{
191
+ currency: z.ZodString;
192
+ participants: z.ZodRecord<z.ZodString, z.ZodObject<{
193
+ userId: z.ZodString;
194
+ role: z.ZodEnum<{
195
+ Borrower: "Borrower";
196
+ Lender: "Lender";
197
+ Platform: "Platform";
198
+ Recipient: "Recipient";
199
+ }>;
200
+ committedAmount: z.ZodNumber;
201
+ settledAmount: z.ZodNumber;
202
+ }, z.core.$strip>>;
203
+ balance: z.ZodOptional<z.ZodNumber>;
204
+ }, z.core.$strip>;
205
+ export type IShareBlockInitialStateInput = z.infer<typeof IShareBlockInitialStateInputSchema>;
206
+ /**
207
+ * Input shapes for the standard ShareBlock mutating functions. Each function
208
+ * the factory wires up takes one of these and proposes a new
209
+ * `IShareBlockState`. Rules judge the transition; the ShareData container
210
+ * applies it iff every rule passes.
211
+ */
212
+ export declare const IShareBlockDepositInputSchema: z.ZodObject<{
213
+ userId: z.ZodString;
214
+ amount: z.ZodNumber;
215
+ }, z.core.$strip>;
216
+ export type IShareBlockDepositInput = z.infer<typeof IShareBlockDepositInputSchema>;
217
+ export declare const IShareBlockWithdrawInputSchema: z.ZodObject<{
218
+ userId: z.ZodString;
219
+ amount: z.ZodNumber;
220
+ }, z.core.$strip>;
221
+ export type IShareBlockWithdrawInput = z.infer<typeof IShareBlockWithdrawInputSchema>;
222
+ export declare const IShareBlockCloseInputSchema: z.ZodObject<{
223
+ userId: z.ZodString;
224
+ }, z.core.$strip>;
225
+ export type IShareBlockCloseInput = z.infer<typeof IShareBlockCloseInputSchema>;
226
+ /**
227
+ * Input for the Funding-specific `commit` function. Records who pulled the
228
+ * trigger on locking the funded amount; the function itself stamps
229
+ * `committedAt` from the system clock.
230
+ */
231
+ export declare const IShareBlockCommitInputSchema: z.ZodObject<{
232
+ userId: z.ZodString;
233
+ }, z.core.$strip>;
234
+ export type IShareBlockCommitInput = z.infer<typeof IShareBlockCommitInputSchema>;
235
+ /**
236
+ * Input for the Funding-specific `registerLender` function. Adds a new
237
+ * `Lender`-role participant to the block so they can subsequently
238
+ * `deposit` (deposit gates on participant.role === Lender).
239
+ *
240
+ * The caller (Rapture's authenticated endpoint) is responsible for
241
+ * authorizing the registration — i.e. for confirming that `userId` is the
242
+ * authenticated user pledging on this loan. The shareblock layer just
243
+ * enforces structural invariants (no duplicate userId, positive
244
+ * committedAmount, block must be open and not committed).
245
+ */
246
+ export declare const IShareBlockRegisterLenderInputSchema: z.ZodObject<{
247
+ userId: z.ZodString;
248
+ committedAmount: z.ZodNumber;
249
+ }, z.core.$strip>;
250
+ export type IShareBlockRegisterLenderInput = z.infer<typeof IShareBlockRegisterLenderInputSchema>;
251
+ /**
252
+ * Input for the Distribution-specific `fund` function. Distinct from
253
+ * `IShareBlockDepositInput` only at the type level: keeps the wire shape
254
+ * narrow to "money coming in from another block" semantics rather than the
255
+ * general-purpose deposit on Clearing.
256
+ */
257
+ export declare const IShareBlockFundInputSchema: z.ZodObject<{
258
+ fromBlockId: z.ZodOptional<z.ZodString>;
259
+ amount: z.ZodNumber;
260
+ }, z.core.$strip>;
261
+ export type IShareBlockFundInput = z.infer<typeof IShareBlockFundInputSchema>;
262
+ /**
263
+ * Input for the Distribution-specific `disburse` function. `userId` must
264
+ * resolve to a participant with role `Recipient`, or the function no-ops.
265
+ */
266
+ export declare const IShareBlockDisburseInputSchema: z.ZodObject<{
267
+ userId: z.ZodString;
268
+ amount: z.ZodNumber;
269
+ }, z.core.$strip>;
270
+ export type IShareBlockDisburseInput = z.infer<typeof IShareBlockDisburseInputSchema>;
271
+ /**
272
+ * Input for the Distribution-specific `markFullyDistributed` function.
273
+ * Records who declared the block fully paid out; the function stamps
274
+ * `distributedAt`.
275
+ */
276
+ export declare const IShareBlockMarkFullyDistributedInputSchema: z.ZodObject<{
277
+ userId: z.ZodString;
278
+ }, z.core.$strip>;
279
+ export type IShareBlockMarkFullyDistributedInput = z.infer<typeof IShareBlockMarkFullyDistributedInputSchema>;
280
+ //# sourceMappingURL=shareblock-models.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shareblock-models.d.ts","sourceRoot":"","sources":["../../../src/models/shareblock/shareblock-models.ts"],"names":[],"mappings":"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"}