@degenerate/generic 0.3.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_settings/database-settings.d.ts +3 -0
- package/dist/_settings/database-settings.d.ts.map +1 -1
- package/dist/_settings/database-settings.js +3 -0
- package/dist/errors/share-data/share-data-errors.d.ts +13 -0
- package/dist/errors/share-data/share-data-errors.d.ts.map +1 -1
- package/dist/errors/share-data/share-data-errors.js +19 -1
- package/dist/models/safe/transactions/sharedata-transactions-models.d.ts +5 -0
- package/dist/models/safe/transactions/sharedata-transactions-models.d.ts.map +1 -1
- package/dist/models/share-data/share-data-crypto-models.d.ts +37 -0
- package/dist/models/share-data/share-data-crypto-models.d.ts.map +1 -1
- package/dist/models/share-data/share-data-crypto-models.js +41 -1
- package/dist/models/share-data/share-data-persistence-models.d.ts +9 -2
- package/dist/models/share-data/share-data-persistence-models.d.ts.map +1 -1
- package/dist/models/share-data/share-data-persistence-models.js +9 -2
- package/dist/models/shareblock/shareblock-models.d.ts +218 -9
- package/dist/models/shareblock/shareblock-models.d.ts.map +1 -1
- package/dist/models/shareblock/shareblock-models.js +182 -9
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database-settings.d.ts","sourceRoot":"","sources":["../../src/_settings/database-settings.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,yBAAyB
|
|
1
|
+
{"version":3,"file":"database-settings.d.ts","sourceRoot":"","sources":["../../src/_settings/database-settings.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;CAmBrC,CAAA"}
|
|
@@ -138,6 +138,19 @@ export declare class ShareDataTransactionProofFailedError extends BaseError {
|
|
|
138
138
|
export declare class ShareDataTransactionNotAuthorizedError extends BaseError {
|
|
139
139
|
constructor(shareDataId: string, signingPublicKey: string);
|
|
140
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* This error is thrown when a delegated-signer registration is rejected.
|
|
143
|
+
* Distinct from {@link ShareDataTransactionNotAuthorizedError} (which rejects a
|
|
144
|
+
* runtime *transaction* whose signer is not authorized): this rejects the
|
|
145
|
+
* *registration* of a delegate — either because the registration proof was not
|
|
146
|
+
* signed by the block's `creationPublicKey` (only the owner may delegate; there
|
|
147
|
+
* is no transitive delegation), because the granted function-id set is empty,
|
|
148
|
+
* or because the proof's `purpose` does not bind the exact
|
|
149
|
+
* `(signerPublicKey, functionIds)` grant being registered.
|
|
150
|
+
*/
|
|
151
|
+
export declare class ShareDataDelegationNotAuthorizedError extends BaseError {
|
|
152
|
+
constructor(shareDataId: string, registeringPublicKey: string);
|
|
153
|
+
}
|
|
141
154
|
/**
|
|
142
155
|
* This error is thrown when the system attempts to get the previous share data hash
|
|
143
156
|
* but the share data has not been initialized for the proof yet.
|
|
@@ -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;;G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AAS;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,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ShareDataPersistenceError = exports.ShareDataPreviousHashNotAvailableError = 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.ShareDataCurrentAndProposalDataMatchesError = exports.ShareDataIsLockedError = void 0;
|
|
4
4
|
const base_error_1 = require("../base-error");
|
|
5
5
|
/**
|
|
6
6
|
* This error is thrown when a function is tried to be applied to the share data thats state is locked.
|
|
@@ -195,6 +195,24 @@ class ShareDataTransactionNotAuthorizedError extends base_error_1.BaseError {
|
|
|
195
195
|
}
|
|
196
196
|
}
|
|
197
197
|
exports.ShareDataTransactionNotAuthorizedError = ShareDataTransactionNotAuthorizedError;
|
|
198
|
+
/**
|
|
199
|
+
* This error is thrown when a delegated-signer registration is rejected.
|
|
200
|
+
* Distinct from {@link ShareDataTransactionNotAuthorizedError} (which rejects a
|
|
201
|
+
* runtime *transaction* whose signer is not authorized): this rejects the
|
|
202
|
+
* *registration* of a delegate — either because the registration proof was not
|
|
203
|
+
* signed by the block's `creationPublicKey` (only the owner may delegate; there
|
|
204
|
+
* is no transitive delegation), because the granted function-id set is empty,
|
|
205
|
+
* or because the proof's `purpose` does not bind the exact
|
|
206
|
+
* `(signerPublicKey, functionIds)` grant being registered.
|
|
207
|
+
*/
|
|
208
|
+
class ShareDataDelegationNotAuthorizedError extends base_error_1.BaseError {
|
|
209
|
+
constructor(shareDataId, registeringPublicKey) {
|
|
210
|
+
super(`Share data with id ${shareDataId} rejected a delegated-signer registration: ` +
|
|
211
|
+
`key ${registeringPublicKey} is not authorized to delegate, or the registration ` +
|
|
212
|
+
`proof does not bind the requested grant.`);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
exports.ShareDataDelegationNotAuthorizedError = ShareDataDelegationNotAuthorizedError;
|
|
198
216
|
/**
|
|
199
217
|
* This error is thrown when the system attempts to get the previous share data hash
|
|
200
218
|
* but the share data has not been initialized for the proof yet.
|
|
@@ -33,6 +33,7 @@ export declare const ISAFETransactionShareDataDataSchema: z.ZodObject<{
|
|
|
33
33
|
Clearing: "Clearing";
|
|
34
34
|
Funding: "Funding";
|
|
35
35
|
Distribution: "Distribution";
|
|
36
|
+
GraceRepayment: "GraceRepayment";
|
|
36
37
|
}>;
|
|
37
38
|
relatedLoanApplicationId: z.ZodOptional<z.ZodString>;
|
|
38
39
|
description: z.ZodOptional<z.ZodString>;
|
|
@@ -91,6 +92,7 @@ export declare const ISAFETransactionShareDataSchema: z.ZodObject<{
|
|
|
91
92
|
Clearing: "Clearing";
|
|
92
93
|
Funding: "Funding";
|
|
93
94
|
Distribution: "Distribution";
|
|
95
|
+
GraceRepayment: "GraceRepayment";
|
|
94
96
|
}>;
|
|
95
97
|
relatedLoanApplicationId: z.ZodOptional<z.ZodString>;
|
|
96
98
|
description: z.ZodOptional<z.ZodString>;
|
|
@@ -148,6 +150,7 @@ export declare const ISAFETransactionShareDataAddSchema: z.ZodObject<{
|
|
|
148
150
|
Clearing: "Clearing";
|
|
149
151
|
Funding: "Funding";
|
|
150
152
|
Distribution: "Distribution";
|
|
153
|
+
GraceRepayment: "GraceRepayment";
|
|
151
154
|
}>;
|
|
152
155
|
relatedLoanApplicationId: z.ZodOptional<z.ZodString>;
|
|
153
156
|
description: z.ZodOptional<z.ZodString>;
|
|
@@ -204,6 +207,7 @@ export declare const ISAFETransactionShareDataUpdateSchema: z.ZodObject<{
|
|
|
204
207
|
Clearing: "Clearing";
|
|
205
208
|
Funding: "Funding";
|
|
206
209
|
Distribution: "Distribution";
|
|
210
|
+
GraceRepayment: "GraceRepayment";
|
|
207
211
|
}>;
|
|
208
212
|
relatedLoanApplicationId: z.ZodOptional<z.ZodString>;
|
|
209
213
|
description: z.ZodOptional<z.ZodString>;
|
|
@@ -260,6 +264,7 @@ export declare const ISAFETransactionShareDataDeleteSchema: z.ZodObject<{
|
|
|
260
264
|
Clearing: "Clearing";
|
|
261
265
|
Funding: "Funding";
|
|
262
266
|
Distribution: "Distribution";
|
|
267
|
+
GraceRepayment: "GraceRepayment";
|
|
263
268
|
}>;
|
|
264
269
|
relatedLoanApplicationId: z.ZodOptional<z.ZodString>;
|
|
265
270
|
description: z.ZodOptional<z.ZodString>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sharedata-transactions-models.d.ts","sourceRoot":"","sources":["../../../../src/models/safe/transactions/sharedata-transactions-models.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACH,mBAAmB,EACnB,yBAAyB,EAG5B,MAAM,4BAA4B,CAAC;AASpC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,mCAAmC
|
|
1
|
+
{"version":3,"file":"sharedata-transactions-models.d.ts","sourceRoot":"","sources":["../../../../src/models/safe/transactions/sharedata-transactions-models.ts"],"names":[],"mappings":"AAAA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|
46
46
|
}, z.core.$strip>>;
|
|
47
47
|
export type ShareDataProofs = z.infer<typeof ShareDataProofsSchema>;
|
|
48
|
+
/**
|
|
49
|
+
* A single delegated-signer grant on a block: a public key the block owner has
|
|
50
|
+
* authorized to propose runtime transactions, scoped to a specific set of
|
|
51
|
+
* function ids (least privilege — a granted key can only drive the function(s)
|
|
52
|
+
* it was delegated, not arbitrary mutations).
|
|
53
|
+
*
|
|
54
|
+
* Field-declaration order is load-bearing, NOT cosmetic — same constraint as
|
|
55
|
+
* {@link IShareDataCryptoProofSchema}. The grant is folded into the canonical
|
|
56
|
+
* share-data string via order-sensitive `JSON.stringify` (see `getArrayString`
|
|
57
|
+
* / `calculateShareDataString`), so a grant that round-trips through `.parse()`
|
|
58
|
+
* (persistence reload) must come back with the SAME key order a freshly-built
|
|
59
|
+
* grant has, or the block's hash diverges and later proofs fail to verify.
|
|
60
|
+
* Keep `publicKey` before `functionIds`, matching the object literal pushed in
|
|
61
|
+
* `ShareData.addAuthorizedSigner`.
|
|
62
|
+
*/
|
|
63
|
+
export declare const IAuthorizedSignerSchema: z.ZodObject<{
|
|
64
|
+
publicKey: z.ZodString;
|
|
65
|
+
functionIds: z.ZodArray<z.ZodString>;
|
|
66
|
+
}, z.core.$strip>;
|
|
67
|
+
export type IAuthorizedSigner = z.infer<typeof IAuthorizedSignerSchema>;
|
|
68
|
+
/** Prefix marking a structural proof's `purpose` as a delegate registration. */
|
|
69
|
+
export declare const DELEGATE_PURPOSE_PREFIX = "delegate:";
|
|
70
|
+
/**
|
|
71
|
+
* Builds the canonical `purpose` for a delegated-signer registration proof.
|
|
72
|
+
*
|
|
73
|
+
* The registration proof is signed over the block's PRE-append state (the grant
|
|
74
|
+
* is not yet folded into `_authorizedSigners` at signing time), so the proof's
|
|
75
|
+
* `purpose` is the only thing that cryptographically attests to the exact
|
|
76
|
+
* `(signerPublicKey, functionIds)` grant. Binding both into the purpose means a
|
|
77
|
+
* tampered snapshot cannot widen a delegate's scope (add function ids) or lift
|
|
78
|
+
* the signature to authorize a different key without invalidating the proof.
|
|
79
|
+
*
|
|
80
|
+
* `functionIds` are normalized (trimmed, de-duped, sorted) and JSON-encoded so
|
|
81
|
+
* the encoding is collision-free regardless of characters in the ids and
|
|
82
|
+
* order-independent across live-create and replay.
|
|
83
|
+
*/
|
|
84
|
+
export declare const buildDelegatePurpose: (signerPublicKey: string, functionIds: string[]) => string;
|
|
48
85
|
/**
|
|
49
86
|
* This contains the interface for the share data property config
|
|
50
87
|
* for creating strings from the object to ensure that signatures and
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"share-data-crypto-models.d.ts","sourceRoot":"","sources":["../../../src/models/share-data/share-data-crypto-models.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAWxB;;GAEG;AACH,eAAO,MAAM,iCAAiC;;;;;iBAK5C,CAAC;AAEH,MAAM,MAAM,2BAA2B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iCAAiC,CAAC,CAAC;AAE5F;;;;;;;;;;GAUG;AASH,eAAO,MAAM,2BAA2B;;;;;;;iBAOtC,CAAC;AAEH,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAEhF;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB;;;;;;;kBAAoD,CAAC;AAEvF,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"share-data-crypto-models.d.ts","sourceRoot":"","sources":["../../../src/models/share-data/share-data-crypto-models.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAWxB;;GAEG;AACH,eAAO,MAAM,iCAAiC;;;;;iBAK5C,CAAC;AAEH,MAAM,MAAM,2BAA2B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iCAAiC,CAA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;;;;iBAMpD,CAAC;AACH,MAAM,MAAM,mCAAmC,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,yCAAyC,CAAC,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.IShareDataAdditionalValuesToIncludeSchema = exports.IShareDataConfigSchema = exports.IShareDataPropertyConfigSchema = exports.ShareDataProofsSchema = exports.IShareDataCryptoProofSchema = exports.IShareDataInitialCryptoDataSchema = void 0;
|
|
3
|
+
exports.IShareDataAdditionalValuesToIncludeSchema = exports.IShareDataConfigSchema = exports.IShareDataPropertyConfigSchema = exports.buildDelegatePurpose = exports.DELEGATE_PURPOSE_PREFIX = exports.IAuthorizedSignerSchema = exports.ShareDataProofsSchema = exports.IShareDataCryptoProofSchema = exports.IShareDataInitialCryptoDataSchema = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const share_rule_models_1 = require("../rules/share-rule-models");
|
|
6
6
|
const share_data_models_1 = require("./share-data-models");
|
|
@@ -51,6 +51,46 @@ exports.IShareDataCryptoProofSchema = zod_1.z.object({
|
|
|
51
51
|
* `addFunction` / `addRule` call.
|
|
52
52
|
*/
|
|
53
53
|
exports.ShareDataProofsSchema = zod_1.z.record(zod_1.z.string(), exports.IShareDataCryptoProofSchema);
|
|
54
|
+
/**
|
|
55
|
+
* A single delegated-signer grant on a block: a public key the block owner has
|
|
56
|
+
* authorized to propose runtime transactions, scoped to a specific set of
|
|
57
|
+
* function ids (least privilege — a granted key can only drive the function(s)
|
|
58
|
+
* it was delegated, not arbitrary mutations).
|
|
59
|
+
*
|
|
60
|
+
* Field-declaration order is load-bearing, NOT cosmetic — same constraint as
|
|
61
|
+
* {@link IShareDataCryptoProofSchema}. The grant is folded into the canonical
|
|
62
|
+
* share-data string via order-sensitive `JSON.stringify` (see `getArrayString`
|
|
63
|
+
* / `calculateShareDataString`), so a grant that round-trips through `.parse()`
|
|
64
|
+
* (persistence reload) must come back with the SAME key order a freshly-built
|
|
65
|
+
* grant has, or the block's hash diverges and later proofs fail to verify.
|
|
66
|
+
* Keep `publicKey` before `functionIds`, matching the object literal pushed in
|
|
67
|
+
* `ShareData.addAuthorizedSigner`.
|
|
68
|
+
*/
|
|
69
|
+
exports.IAuthorizedSignerSchema = zod_1.z.object({
|
|
70
|
+
publicKey: zod_1.z.string(), // the delegate's public key (hex)
|
|
71
|
+
functionIds: zod_1.z.array(zod_1.z.string()), // the function ids this key may drive (sorted)
|
|
72
|
+
});
|
|
73
|
+
/** Prefix marking a structural proof's `purpose` as a delegate registration. */
|
|
74
|
+
exports.DELEGATE_PURPOSE_PREFIX = 'delegate:';
|
|
75
|
+
/**
|
|
76
|
+
* Builds the canonical `purpose` for a delegated-signer registration proof.
|
|
77
|
+
*
|
|
78
|
+
* The registration proof is signed over the block's PRE-append state (the grant
|
|
79
|
+
* is not yet folded into `_authorizedSigners` at signing time), so the proof's
|
|
80
|
+
* `purpose` is the only thing that cryptographically attests to the exact
|
|
81
|
+
* `(signerPublicKey, functionIds)` grant. Binding both into the purpose means a
|
|
82
|
+
* tampered snapshot cannot widen a delegate's scope (add function ids) or lift
|
|
83
|
+
* the signature to authorize a different key without invalidating the proof.
|
|
84
|
+
*
|
|
85
|
+
* `functionIds` are normalized (trimmed, de-duped, sorted) and JSON-encoded so
|
|
86
|
+
* the encoding is collision-free regardless of characters in the ids and
|
|
87
|
+
* order-independent across live-create and replay.
|
|
88
|
+
*/
|
|
89
|
+
const buildDelegatePurpose = (signerPublicKey, functionIds) => {
|
|
90
|
+
const normalized = Array.from(new Set(functionIds.map((id) => id.trim()).filter((id) => id.length > 0))).sort();
|
|
91
|
+
return `${exports.DELEGATE_PURPOSE_PREFIX}${signerPublicKey}:${JSON.stringify(normalized)}`;
|
|
92
|
+
};
|
|
93
|
+
exports.buildDelegatePurpose = buildDelegatePurpose;
|
|
54
94
|
//#endregion Share Data Crypto Schemas
|
|
55
95
|
//#region Stringify Configurations
|
|
56
96
|
/**
|
|
@@ -25,6 +25,7 @@ export declare const PersistedCreationConfigSchema: z.ZodObject<{
|
|
|
25
25
|
Clearing: "Clearing";
|
|
26
26
|
Funding: "Funding";
|
|
27
27
|
Distribution: "Distribution";
|
|
28
|
+
GraceRepayment: "GraceRepayment";
|
|
28
29
|
}>;
|
|
29
30
|
relatedLoanApplicationId: z.ZodOptional<z.ZodString>;
|
|
30
31
|
description: z.ZodOptional<z.ZodString>;
|
|
@@ -90,12 +91,13 @@ export type PersistedTransaction = z.infer<typeof PersistedTransactionSchema>;
|
|
|
90
91
|
* a snapshot whose state was edited without re-signing fails loudly.
|
|
91
92
|
*/
|
|
92
93
|
export declare const PersistedShareDataSchema: z.ZodObject<{
|
|
93
|
-
schemaVersion: z.ZodLiteral<
|
|
94
|
+
schemaVersion: z.ZodLiteral<3>;
|
|
94
95
|
id: z.ZodString;
|
|
95
96
|
blockType: z.ZodEnum<{
|
|
96
97
|
Clearing: "Clearing";
|
|
97
98
|
Funding: "Funding";
|
|
98
99
|
Distribution: "Distribution";
|
|
100
|
+
GraceRepayment: "GraceRepayment";
|
|
99
101
|
}>;
|
|
100
102
|
signingCurve: z.ZodEnum<{
|
|
101
103
|
ed25519: EllipticalCurvesSigning.Curve25519;
|
|
@@ -114,6 +116,7 @@ export declare const PersistedShareDataSchema: z.ZodObject<{
|
|
|
114
116
|
Clearing: "Clearing";
|
|
115
117
|
Funding: "Funding";
|
|
116
118
|
Distribution: "Distribution";
|
|
119
|
+
GraceRepayment: "GraceRepayment";
|
|
117
120
|
}>;
|
|
118
121
|
relatedLoanApplicationId: z.ZodOptional<z.ZodString>;
|
|
119
122
|
description: z.ZodOptional<z.ZodString>;
|
|
@@ -131,6 +134,10 @@ export declare const PersistedShareDataSchema: z.ZodObject<{
|
|
|
131
134
|
timestamp: z.ZodNumber;
|
|
132
135
|
purpose: z.ZodString;
|
|
133
136
|
}, z.core.$strip>>;
|
|
137
|
+
authorizedSigners: z.ZodArray<z.ZodObject<{
|
|
138
|
+
publicKey: z.ZodString;
|
|
139
|
+
functionIds: z.ZodArray<z.ZodString>;
|
|
140
|
+
}, z.core.$strip>>;
|
|
134
141
|
transactionLog: z.ZodArray<z.ZodObject<{
|
|
135
142
|
functionId: z.ZodString;
|
|
136
143
|
input: z.ZodOptional<z.ZodAny>;
|
|
@@ -154,5 +161,5 @@ export declare const PersistedShareDataSchema: z.ZodObject<{
|
|
|
154
161
|
}, z.core.$strip>;
|
|
155
162
|
export type PersistedShareData = z.infer<typeof PersistedShareDataSchema>;
|
|
156
163
|
/** The only schema version this build understands. */
|
|
157
|
-
export declare const PERSISTED_SHARE_DATA_SCHEMA_VERSION:
|
|
164
|
+
export declare const PERSISTED_SHARE_DATA_SCHEMA_VERSION: 3;
|
|
158
165
|
//# sourceMappingURL=share-data-persistence-models.d.ts.map
|
|
@@ -1 +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;
|
|
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;AAmBzC;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAuBnC,CAAC;AAEH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAE1E,sDAAsD;AACtD,eAAO,MAAM,mCAAmC,EAAG,CAAU,CAAC"}
|
|
@@ -73,13 +73,20 @@ exports.PersistedTransactionSchema = zod_1.default.object({
|
|
|
73
73
|
* a snapshot whose state was edited without re-signing fails loudly.
|
|
74
74
|
*/
|
|
75
75
|
exports.PersistedShareDataSchema = zod_1.default.object({
|
|
76
|
-
schemaVersion: zod_1.default.literal(
|
|
76
|
+
schemaVersion: zod_1.default.literal(3),
|
|
77
77
|
id: zod_1.default.string(),
|
|
78
78
|
blockType: shareblock_models_1.ShareBlockTypeSchema,
|
|
79
79
|
signingCurve: exports.PersistedSigningCurveSchema,
|
|
80
80
|
initialCrypto: share_data_crypto_models_1.IShareDataInitialCryptoDataSchema,
|
|
81
81
|
creationConfig: exports.PersistedCreationConfigSchema,
|
|
82
82
|
structuralProofs: share_data_crypto_models_1.ShareDataProofsSchema,
|
|
83
|
+
// The delegated-signer grants registered at construction (least-privilege
|
|
84
|
+
// function scoping per grant). The registration *proofs* live in
|
|
85
|
+
// `structuralProofs` keyed by their `delegate:<key>:<ids>` purpose; this
|
|
86
|
+
// field carries the grant tuples the builder replays via
|
|
87
|
+
// `addAuthorizedSigner` so the rebuilt block re-derives the same signer set
|
|
88
|
+
// (and the same canonical hash). Empty for blocks with no delegations.
|
|
89
|
+
authorizedSigners: zod_1.default.array(share_data_crypto_models_1.IAuthorizedSignerSchema),
|
|
83
90
|
transactionLog: zod_1.default.array(exports.PersistedTransactionSchema),
|
|
84
91
|
// Integrity cross-checks — compared against the replayed result, never
|
|
85
92
|
// trusted as source of truth.
|
|
@@ -90,5 +97,5 @@ exports.PersistedShareDataSchema = zod_1.default.object({
|
|
|
90
97
|
expectedVersion: zod_1.default.number(),
|
|
91
98
|
});
|
|
92
99
|
/** The only schema version this build understands. */
|
|
93
|
-
exports.PERSISTED_SHARE_DATA_SCHEMA_VERSION =
|
|
100
|
+
exports.PERSISTED_SHARE_DATA_SCHEMA_VERSION = 3;
|
|
94
101
|
//#endregion Persistence Schemas
|
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
import z from 'zod';
|
|
2
2
|
/**
|
|
3
|
-
* The
|
|
3
|
+
* The four ShareBlock specializations the platform uses to move money
|
|
4
4
|
* through a loan's lifecycle.
|
|
5
5
|
*
|
|
6
|
-
* - `Clearing`
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* - `Funding`
|
|
10
|
-
*
|
|
11
|
-
* - `Distribution`
|
|
12
|
-
*
|
|
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
|
+
* - `GraceRepayment` — the borrower-repayment block for Rapture's Grace
|
|
14
|
+
* product. Per-lender Grace-or-yield decisions are
|
|
15
|
+
* toggled while the loan is in flight, snapshotted at
|
|
16
|
+
* repayment-initiate, and drive the blended-rate
|
|
17
|
+
* allocation when the borrower pays. Terminal state is
|
|
18
|
+
* either `fullyRepaid: true` OR `defaulted: true`,
|
|
19
|
+
* mutually exclusive.
|
|
13
20
|
*
|
|
14
21
|
* New ShareBlock variants should be additive — never re-use a value with new
|
|
15
22
|
* semantics, since downstream rule libraries pattern-match on the literal.
|
|
@@ -17,12 +24,14 @@ import z from 'zod';
|
|
|
17
24
|
export declare enum ShareBlockType {
|
|
18
25
|
Clearing = "Clearing",
|
|
19
26
|
Funding = "Funding",
|
|
20
|
-
Distribution = "Distribution"
|
|
27
|
+
Distribution = "Distribution",
|
|
28
|
+
GraceRepayment = "GraceRepayment"
|
|
21
29
|
}
|
|
22
30
|
export declare const ShareBlockTypeSchema: z.ZodEnum<{
|
|
23
31
|
Clearing: "Clearing";
|
|
24
32
|
Funding: "Funding";
|
|
25
33
|
Distribution: "Distribution";
|
|
34
|
+
GraceRepayment: "GraceRepayment";
|
|
26
35
|
}>;
|
|
27
36
|
/**
|
|
28
37
|
* Roles a participant plays inside a ShareBlock. A single party may hold
|
|
@@ -77,6 +86,7 @@ export declare const IShareBlockStateSchema: z.ZodObject<{
|
|
|
77
86
|
Clearing: "Clearing";
|
|
78
87
|
Funding: "Funding";
|
|
79
88
|
Distribution: "Distribution";
|
|
89
|
+
GraceRepayment: "GraceRepayment";
|
|
80
90
|
}>;
|
|
81
91
|
balance: z.ZodNumber;
|
|
82
92
|
currency: z.ZodString;
|
|
@@ -159,6 +169,125 @@ export declare const IDistributionShareBlockStateSchema: z.ZodObject<{
|
|
|
159
169
|
distributedAt: z.ZodOptional<z.ZodNumber>;
|
|
160
170
|
}, z.core.$strip>;
|
|
161
171
|
export type IDistributionShareBlockState = z.infer<typeof IDistributionShareBlockStateSchema>;
|
|
172
|
+
/**
|
|
173
|
+
* GraceRepayment-specific participant. Extends the base participant with
|
|
174
|
+
* three Grace-specific fields plus a denormalized ShareBlock count:
|
|
175
|
+
*
|
|
176
|
+
* - `graceDecision` — Lender-only field. The lender's current
|
|
177
|
+
* choice: take their yield, grant Grace, or
|
|
178
|
+
* undecided (the initial state when the
|
|
179
|
+
* GraceRepayment block is constructed).
|
|
180
|
+
* Borrower and Platform participants always
|
|
181
|
+
* carry `'undecided'` and never mutate it.
|
|
182
|
+
* - `decidedAtMs` — Unix-ms timestamp the lender last set their
|
|
183
|
+
* decision. `null` while undecided.
|
|
184
|
+
* - `snapshotDecision` — The locked-in decision at the moment the
|
|
185
|
+
* borrower initiated repayment. `null` until
|
|
186
|
+
* snapshot. After snapshot it's the
|
|
187
|
+
* authoritative value the per-lender
|
|
188
|
+
* settlement uses.
|
|
189
|
+
* - `shareBlockCount` — Derived count of $10 ShareBlocks held by
|
|
190
|
+
* this lender on this loan
|
|
191
|
+
* (`committedAmount / 1000` for cents-based
|
|
192
|
+
* committed amounts). Cached for fast UI
|
|
193
|
+
* queries; the canonical source is still
|
|
194
|
+
* `committedAmount`.
|
|
195
|
+
*/
|
|
196
|
+
export declare const IGraceRepaymentParticipantSchema: z.ZodObject<{
|
|
197
|
+
userId: z.ZodString;
|
|
198
|
+
role: z.ZodEnum<{
|
|
199
|
+
Borrower: "Borrower";
|
|
200
|
+
Lender: "Lender";
|
|
201
|
+
Platform: "Platform";
|
|
202
|
+
Recipient: "Recipient";
|
|
203
|
+
}>;
|
|
204
|
+
committedAmount: z.ZodNumber;
|
|
205
|
+
settledAmount: z.ZodNumber;
|
|
206
|
+
graceDecision: z.ZodEnum<{
|
|
207
|
+
yield: "yield";
|
|
208
|
+
grace: "grace";
|
|
209
|
+
undecided: "undecided";
|
|
210
|
+
}>;
|
|
211
|
+
decidedAtMs: z.ZodOptional<z.ZodNumber>;
|
|
212
|
+
snapshotDecision: z.ZodOptional<z.ZodEnum<{
|
|
213
|
+
yield: "yield";
|
|
214
|
+
grace: "grace";
|
|
215
|
+
}>>;
|
|
216
|
+
shareBlockCount: z.ZodNumber;
|
|
217
|
+
}, z.core.$strip>;
|
|
218
|
+
export type IGraceRepaymentParticipant = z.infer<typeof IGraceRepaymentParticipantSchema>;
|
|
219
|
+
/**
|
|
220
|
+
* GraceRepayment-specific extension of `IShareBlockState`. Adds:
|
|
221
|
+
*
|
|
222
|
+
* - `outstandingPrincipalCents` — running principal balance the
|
|
223
|
+
* borrower owes. Decrements as
|
|
224
|
+
* repayments land.
|
|
225
|
+
* - `outstandingInterestCents` — interest owed at the time of
|
|
226
|
+
* repayment snapshot. Computed
|
|
227
|
+
* atomically at snapshot from the
|
|
228
|
+
* blended rate; decrements as
|
|
229
|
+
* repayments land.
|
|
230
|
+
* - `repaymentSnapshotAtMs` — unix-ms timestamp the per-lender
|
|
231
|
+
* Grace decisions were locked in.
|
|
232
|
+
* `null` until the borrower
|
|
233
|
+
* initiates repayment.
|
|
234
|
+
* - `blendedRatePercent` — weighted-average effective rate
|
|
235
|
+
* computed at snapshot. `null` pre-
|
|
236
|
+
* snapshot.
|
|
237
|
+
* - `finalEffectiveRatePercent` — what the borrower actually pays;
|
|
238
|
+
* equal to `blendedRatePercent`
|
|
239
|
+
* under the standard formula. `null`
|
|
240
|
+
* pre-snapshot.
|
|
241
|
+
* - `fullyRepaid` / `defaulted` — mutually exclusive terminal flags.
|
|
242
|
+
* Both monotonic (once true, never
|
|
243
|
+
* back to false).
|
|
244
|
+
* - `defaultReason` / `defaultedAtMs` — audit attribution for the
|
|
245
|
+
* default moment.
|
|
246
|
+
*
|
|
247
|
+
* Participants are typed as `IGraceRepaymentParticipant` (extended
|
|
248
|
+
* with per-lender Grace decision fields).
|
|
249
|
+
*/
|
|
250
|
+
export declare const IGraceRepaymentShareBlockStateSchema: z.ZodObject<{
|
|
251
|
+
balance: z.ZodNumber;
|
|
252
|
+
currency: z.ZodString;
|
|
253
|
+
isOpen: z.ZodBoolean;
|
|
254
|
+
blockType: z.ZodLiteral<"GraceRepayment">;
|
|
255
|
+
participants: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
256
|
+
userId: z.ZodString;
|
|
257
|
+
role: z.ZodEnum<{
|
|
258
|
+
Borrower: "Borrower";
|
|
259
|
+
Lender: "Lender";
|
|
260
|
+
Platform: "Platform";
|
|
261
|
+
Recipient: "Recipient";
|
|
262
|
+
}>;
|
|
263
|
+
committedAmount: z.ZodNumber;
|
|
264
|
+
settledAmount: z.ZodNumber;
|
|
265
|
+
graceDecision: z.ZodEnum<{
|
|
266
|
+
yield: "yield";
|
|
267
|
+
grace: "grace";
|
|
268
|
+
undecided: "undecided";
|
|
269
|
+
}>;
|
|
270
|
+
decidedAtMs: z.ZodOptional<z.ZodNumber>;
|
|
271
|
+
snapshotDecision: z.ZodOptional<z.ZodEnum<{
|
|
272
|
+
yield: "yield";
|
|
273
|
+
grace: "grace";
|
|
274
|
+
}>>;
|
|
275
|
+
shareBlockCount: z.ZodNumber;
|
|
276
|
+
}, z.core.$strip>>;
|
|
277
|
+
outstandingPrincipalCents: z.ZodNumber;
|
|
278
|
+
outstandingInterestCents: z.ZodNumber;
|
|
279
|
+
repaymentSnapshotAtMs: z.ZodOptional<z.ZodNumber>;
|
|
280
|
+
blendedRatePercent: z.ZodOptional<z.ZodNumber>;
|
|
281
|
+
finalEffectiveRatePercent: z.ZodOptional<z.ZodNumber>;
|
|
282
|
+
snapshotBaselineRatePercent: z.ZodOptional<z.ZodNumber>;
|
|
283
|
+
snapshotGraceMicroInterestPercent: z.ZodOptional<z.ZodNumber>;
|
|
284
|
+
snapshotGracePerShareBlockFeeCents: z.ZodOptional<z.ZodNumber>;
|
|
285
|
+
fullyRepaid: z.ZodBoolean;
|
|
286
|
+
defaulted: z.ZodBoolean;
|
|
287
|
+
defaultReason: z.ZodOptional<z.ZodString>;
|
|
288
|
+
defaultedAtMs: z.ZodOptional<z.ZodNumber>;
|
|
289
|
+
}, z.core.$strip>;
|
|
290
|
+
export type IGraceRepaymentShareBlockState = z.infer<typeof IGraceRepaymentShareBlockStateSchema>;
|
|
162
291
|
/**
|
|
163
292
|
* Static information about a ShareBlock — set at construction and never
|
|
164
293
|
* mutated through transactions. Lives outside `IShareBlockState` because
|
|
@@ -171,6 +300,7 @@ export declare const IShareBlockMetadataSchema: z.ZodObject<{
|
|
|
171
300
|
Clearing: "Clearing";
|
|
172
301
|
Funding: "Funding";
|
|
173
302
|
Distribution: "Distribution";
|
|
303
|
+
GraceRepayment: "GraceRepayment";
|
|
174
304
|
}>;
|
|
175
305
|
relatedLoanApplicationId: z.ZodOptional<z.ZodString>;
|
|
176
306
|
description: z.ZodOptional<z.ZodString>;
|
|
@@ -277,4 +407,83 @@ export declare const IShareBlockMarkFullyDistributedInputSchema: z.ZodObject<{
|
|
|
277
407
|
userId: z.ZodString;
|
|
278
408
|
}, z.core.$strip>;
|
|
279
409
|
export type IShareBlockMarkFullyDistributedInput = z.infer<typeof IShareBlockMarkFullyDistributedInputSchema>;
|
|
410
|
+
/**
|
|
411
|
+
* Input for the GraceRepayment `setLenderGraceDecision` function.
|
|
412
|
+
* Lender-callable while the block is open and pre-snapshot. The block's
|
|
413
|
+
* rules also enforce that the calling userId matches the participant
|
|
414
|
+
* being mutated (lenders can only set their own decisions, not others').
|
|
415
|
+
*/
|
|
416
|
+
export declare const IShareBlockSetLenderGraceDecisionInputSchema: z.ZodObject<{
|
|
417
|
+
userId: z.ZodString;
|
|
418
|
+
decision: z.ZodEnum<{
|
|
419
|
+
yield: "yield";
|
|
420
|
+
grace: "grace";
|
|
421
|
+
}>;
|
|
422
|
+
decidedAtMs: z.ZodNumber;
|
|
423
|
+
}, z.core.$strip>;
|
|
424
|
+
export type IShareBlockSetLenderGraceDecisionInput = z.infer<typeof IShareBlockSetLenderGraceDecisionInputSchema>;
|
|
425
|
+
/**
|
|
426
|
+
* Input for the GraceRepayment `snapshotForRepayment` function.
|
|
427
|
+
* Platform-only. Atomic: freezes every Lender participant's
|
|
428
|
+
* `snapshotDecision` from their current `graceDecision`, computes
|
|
429
|
+
* `blendedRatePercent` and `finalEffectiveRatePercent` from the
|
|
430
|
+
* weighted decisions, sets `outstandingInterestCents` to the final
|
|
431
|
+
* computed amount, and stamps `repaymentSnapshotAtMs`.
|
|
432
|
+
*
|
|
433
|
+
* `graceMicroInterestPercent` and `gracePerShareBlockFeeCents` are the
|
|
434
|
+
* platform-fee configuration values used in the math; passing them via
|
|
435
|
+
* the input keeps the variant function pure (no implicit config
|
|
436
|
+
* lookup).
|
|
437
|
+
*/
|
|
438
|
+
export declare const IShareBlockSnapshotForRepaymentInputSchema: z.ZodObject<{
|
|
439
|
+
userId: z.ZodString;
|
|
440
|
+
baselineRatePercent: z.ZodNumber;
|
|
441
|
+
termDays: z.ZodNumber;
|
|
442
|
+
graceMicroInterestPercent: z.ZodNumber;
|
|
443
|
+
gracePerShareBlockFeeCents: z.ZodNumber;
|
|
444
|
+
snapshotAtMs: z.ZodNumber;
|
|
445
|
+
}, z.core.$strip>;
|
|
446
|
+
export type IShareBlockSnapshotForRepaymentInput = z.infer<typeof IShareBlockSnapshotForRepaymentInputSchema>;
|
|
447
|
+
/**
|
|
448
|
+
* Input for the GraceRepayment `recordRepayment` function. Platform-only.
|
|
449
|
+
* Applies an inbound borrower payment per the snapshot decisions:
|
|
450
|
+
* yield-ShareBlock lenders receive their share of `borrowerInterest`;
|
|
451
|
+
* grace-ShareBlock lenders receive only the micro-interest minus the
|
|
452
|
+
* per-ShareBlock fee. Decrements `outstandingInterestCents` first,
|
|
453
|
+
* then `outstandingPrincipalCents`. Auto-marks `fullyRepaid` when
|
|
454
|
+
* both reach zero.
|
|
455
|
+
*
|
|
456
|
+
* `paymentAttemptId` is the idempotency key — a second call with the
|
|
457
|
+
* same id is a no-op.
|
|
458
|
+
*/
|
|
459
|
+
export declare const IShareBlockRecordRepaymentInputSchema: z.ZodObject<{
|
|
460
|
+
userId: z.ZodString;
|
|
461
|
+
paymentAttemptId: z.ZodString;
|
|
462
|
+
amountCents: z.ZodNumber;
|
|
463
|
+
paidAtMs: z.ZodNumber;
|
|
464
|
+
}, z.core.$strip>;
|
|
465
|
+
export type IShareBlockRecordRepaymentInput = z.infer<typeof IShareBlockRecordRepaymentInputSchema>;
|
|
466
|
+
/**
|
|
467
|
+
* Input for the GraceRepayment `markFullyRepaid` function. Platform-only.
|
|
468
|
+
* Asserts `outstandingPrincipalCents === 0 && outstandingInterestCents
|
|
469
|
+
* === 0` before flipping. Mutually exclusive with `markDefaulted`.
|
|
470
|
+
*/
|
|
471
|
+
export declare const IShareBlockMarkFullyRepaidInputSchema: z.ZodObject<{
|
|
472
|
+
userId: z.ZodString;
|
|
473
|
+
asOf: z.ZodNumber;
|
|
474
|
+
}, z.core.$strip>;
|
|
475
|
+
export type IShareBlockMarkFullyRepaidInput = z.infer<typeof IShareBlockMarkFullyRepaidInputSchema>;
|
|
476
|
+
/**
|
|
477
|
+
* Input for the GraceRepayment `markDefaulted` function. Platform-only.
|
|
478
|
+
* Mutually exclusive with `markFullyRepaid`. Sets the terminal default
|
|
479
|
+
* flag + audit metadata; the post-default flow (lender write-off,
|
|
480
|
+
* borrower loyalty reset, identity-reveal opt-ins) happens in Rapture's
|
|
481
|
+
* trigger layer, not here.
|
|
482
|
+
*/
|
|
483
|
+
export declare const IShareBlockMarkDefaultedInputSchema: z.ZodObject<{
|
|
484
|
+
userId: z.ZodString;
|
|
485
|
+
reason: z.ZodString;
|
|
486
|
+
asOf: z.ZodNumber;
|
|
487
|
+
}, z.core.$strip>;
|
|
488
|
+
export type IShareBlockMarkDefaultedInput = z.infer<typeof IShareBlockMarkDefaultedInputSchema>;
|
|
280
489
|
//# sourceMappingURL=shareblock-models.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shareblock-models.d.ts","sourceRoot":"","sources":["../../../src/models/shareblock/shareblock-models.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAC;AAIpB
|
|
1
|
+
{"version":3,"file":"shareblock-models.d.ts","sourceRoot":"","sources":["../../../src/models/shareblock/shareblock-models.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAC;AAIpB;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,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,0BAA0B,CAAC,CAAC;AAE9E;;;GAGG;AACH,eAAO,MAAM,8BAA8B;;;iBAGzC,CAAC;AACH,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,8BAA8B,CAAC,CAAC;AAEtF;;;;GAIG;AACH,eAAO,MAAM,0CAA0C;;iBAErD,CAAC;AACH,MAAM,MAAM,oCAAoC,GAC5C,CAAC,CAAC,KAAK,CAAC,OAAO,0CAA0C,CAAC,CAAC;AAE/D;;;;;GAKG;AACH,eAAO,MAAM,4CAA4C;;;;;;;iBAIvD,CAAC;AACH,MAAM,MAAM,sCAAsC,GAC9C,CAAC,CAAC,KAAK,CAAC,OAAO,4CAA4C,CAAC,CAAC;AAEjE;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,0CAA0C;;;;;;;iBAOrD,CAAC;AACH,MAAM,MAAM,oCAAoC,GAC5C,CAAC,CAAC,KAAK,CAAC,OAAO,0CAA0C,CAAC,CAAC;AAE/D;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,qCAAqC;;;;;iBAKhD,CAAC;AACH,MAAM,MAAM,+BAA+B,GACvC,CAAC,CAAC,KAAK,CAAC,OAAO,qCAAqC,CAAC,CAAC;AAE1D;;;;GAIG;AACH,eAAO,MAAM,qCAAqC;;;iBAGhD,CAAC;AACH,MAAM,MAAM,+BAA+B,GACvC,CAAC,CAAC,KAAK,CAAC,OAAO,qCAAqC,CAAC,CAAC;AAE1D;;;;;;GAMG;AACH,eAAO,MAAM,mCAAmC;;;;iBAI9C,CAAC;AACH,MAAM,MAAM,6BAA6B,GACrC,CAAC,CAAC,KAAK,CAAC,OAAO,mCAAmC,CAAC,CAAC"}
|
|
@@ -3,20 +3,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.IShareBlockMarkFullyDistributedInputSchema = exports.IShareBlockDisburseInputSchema = exports.IShareBlockFundInputSchema = exports.IShareBlockRegisterLenderInputSchema = exports.IShareBlockCommitInputSchema = exports.IShareBlockCloseInputSchema = exports.IShareBlockWithdrawInputSchema = exports.IShareBlockDepositInputSchema = exports.IShareBlockInitialStateInputSchema = exports.IShareBlockMetadataSchema = exports.IDistributionShareBlockStateSchema = exports.IFundingShareBlockStateSchema = exports.IShareBlockStateSchema = exports.IShareBlockParticipantSchema = exports.ShareBlockParticipantRoleSchema = exports.ShareBlockParticipantRole = exports.ShareBlockTypeSchema = exports.ShareBlockType = void 0;
|
|
6
|
+
exports.IShareBlockMarkDefaultedInputSchema = exports.IShareBlockMarkFullyRepaidInputSchema = exports.IShareBlockRecordRepaymentInputSchema = exports.IShareBlockSnapshotForRepaymentInputSchema = exports.IShareBlockSetLenderGraceDecisionInputSchema = exports.IShareBlockMarkFullyDistributedInputSchema = exports.IShareBlockDisburseInputSchema = exports.IShareBlockFundInputSchema = exports.IShareBlockRegisterLenderInputSchema = exports.IShareBlockCommitInputSchema = exports.IShareBlockCloseInputSchema = exports.IShareBlockWithdrawInputSchema = exports.IShareBlockDepositInputSchema = exports.IShareBlockInitialStateInputSchema = exports.IShareBlockMetadataSchema = exports.IGraceRepaymentShareBlockStateSchema = exports.IGraceRepaymentParticipantSchema = exports.IDistributionShareBlockStateSchema = exports.IFundingShareBlockStateSchema = exports.IShareBlockStateSchema = exports.IShareBlockParticipantSchema = exports.ShareBlockParticipantRoleSchema = exports.ShareBlockParticipantRole = exports.ShareBlockTypeSchema = exports.ShareBlockType = void 0;
|
|
7
7
|
const zod_1 = __importDefault(require("zod"));
|
|
8
8
|
//#region Enums
|
|
9
9
|
/**
|
|
10
|
-
* The
|
|
10
|
+
* The four ShareBlock specializations the platform uses to move money
|
|
11
11
|
* through a loan's lifecycle.
|
|
12
12
|
*
|
|
13
|
-
* - `Clearing`
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* - `Funding`
|
|
17
|
-
*
|
|
18
|
-
* - `Distribution`
|
|
19
|
-
*
|
|
13
|
+
* - `Clearing` — neutral holding spot funds pass through before they're
|
|
14
|
+
* committed to either side of a deal. Used to net
|
|
15
|
+
* borrower and lender flows before settling.
|
|
16
|
+
* - `Funding` — the lender-funded pool that backs a specific loan.
|
|
17
|
+
* Holds principal between funding and disbursement.
|
|
18
|
+
* - `Distribution` — the destination ShareBlock that pays principal to a
|
|
19
|
+
* borrower or returns/interest to a lender.
|
|
20
|
+
* - `GraceRepayment` — the borrower-repayment block for Rapture's Grace
|
|
21
|
+
* product. Per-lender Grace-or-yield decisions are
|
|
22
|
+
* toggled while the loan is in flight, snapshotted at
|
|
23
|
+
* repayment-initiate, and drive the blended-rate
|
|
24
|
+
* allocation when the borrower pays. Terminal state is
|
|
25
|
+
* either `fullyRepaid: true` OR `defaulted: true`,
|
|
26
|
+
* mutually exclusive.
|
|
20
27
|
*
|
|
21
28
|
* New ShareBlock variants should be additive — never re-use a value with new
|
|
22
29
|
* semantics, since downstream rule libraries pattern-match on the literal.
|
|
@@ -26,11 +33,13 @@ var ShareBlockType;
|
|
|
26
33
|
ShareBlockType["Clearing"] = "Clearing";
|
|
27
34
|
ShareBlockType["Funding"] = "Funding";
|
|
28
35
|
ShareBlockType["Distribution"] = "Distribution";
|
|
36
|
+
ShareBlockType["GraceRepayment"] = "GraceRepayment";
|
|
29
37
|
})(ShareBlockType || (exports.ShareBlockType = ShareBlockType = {}));
|
|
30
38
|
exports.ShareBlockTypeSchema = zod_1.default.enum([
|
|
31
39
|
'Clearing',
|
|
32
40
|
'Funding',
|
|
33
41
|
'Distribution',
|
|
42
|
+
'GraceRepayment',
|
|
34
43
|
]);
|
|
35
44
|
//#endregion Enums
|
|
36
45
|
//#region Participant
|
|
@@ -121,6 +130,99 @@ exports.IDistributionShareBlockStateSchema = exports.IShareBlockStateSchema.exte
|
|
|
121
130
|
distributedBy: zod_1.default.string().optional(),
|
|
122
131
|
distributedAt: zod_1.default.number().optional(),
|
|
123
132
|
});
|
|
133
|
+
/**
|
|
134
|
+
* GraceRepayment-specific participant. Extends the base participant with
|
|
135
|
+
* three Grace-specific fields plus a denormalized ShareBlock count:
|
|
136
|
+
*
|
|
137
|
+
* - `graceDecision` — Lender-only field. The lender's current
|
|
138
|
+
* choice: take their yield, grant Grace, or
|
|
139
|
+
* undecided (the initial state when the
|
|
140
|
+
* GraceRepayment block is constructed).
|
|
141
|
+
* Borrower and Platform participants always
|
|
142
|
+
* carry `'undecided'` and never mutate it.
|
|
143
|
+
* - `decidedAtMs` — Unix-ms timestamp the lender last set their
|
|
144
|
+
* decision. `null` while undecided.
|
|
145
|
+
* - `snapshotDecision` — The locked-in decision at the moment the
|
|
146
|
+
* borrower initiated repayment. `null` until
|
|
147
|
+
* snapshot. After snapshot it's the
|
|
148
|
+
* authoritative value the per-lender
|
|
149
|
+
* settlement uses.
|
|
150
|
+
* - `shareBlockCount` — Derived count of $10 ShareBlocks held by
|
|
151
|
+
* this lender on this loan
|
|
152
|
+
* (`committedAmount / 1000` for cents-based
|
|
153
|
+
* committed amounts). Cached for fast UI
|
|
154
|
+
* queries; the canonical source is still
|
|
155
|
+
* `committedAmount`.
|
|
156
|
+
*/
|
|
157
|
+
exports.IGraceRepaymentParticipantSchema = exports.IShareBlockParticipantSchema.extend({
|
|
158
|
+
graceDecision: zod_1.default.enum(['yield', 'grace', 'undecided']),
|
|
159
|
+
/** Unset until the lender first sets a decision. */
|
|
160
|
+
decidedAtMs: zod_1.default.number().int().nonnegative().optional(),
|
|
161
|
+
/** Unset until the borrower initiates repayment. */
|
|
162
|
+
snapshotDecision: zod_1.default.enum(['yield', 'grace']).optional(),
|
|
163
|
+
shareBlockCount: zod_1.default.number().int().nonnegative(),
|
|
164
|
+
});
|
|
165
|
+
/**
|
|
166
|
+
* GraceRepayment-specific extension of `IShareBlockState`. Adds:
|
|
167
|
+
*
|
|
168
|
+
* - `outstandingPrincipalCents` — running principal balance the
|
|
169
|
+
* borrower owes. Decrements as
|
|
170
|
+
* repayments land.
|
|
171
|
+
* - `outstandingInterestCents` — interest owed at the time of
|
|
172
|
+
* repayment snapshot. Computed
|
|
173
|
+
* atomically at snapshot from the
|
|
174
|
+
* blended rate; decrements as
|
|
175
|
+
* repayments land.
|
|
176
|
+
* - `repaymentSnapshotAtMs` — unix-ms timestamp the per-lender
|
|
177
|
+
* Grace decisions were locked in.
|
|
178
|
+
* `null` until the borrower
|
|
179
|
+
* initiates repayment.
|
|
180
|
+
* - `blendedRatePercent` — weighted-average effective rate
|
|
181
|
+
* computed at snapshot. `null` pre-
|
|
182
|
+
* snapshot.
|
|
183
|
+
* - `finalEffectiveRatePercent` — what the borrower actually pays;
|
|
184
|
+
* equal to `blendedRatePercent`
|
|
185
|
+
* under the standard formula. `null`
|
|
186
|
+
* pre-snapshot.
|
|
187
|
+
* - `fullyRepaid` / `defaulted` — mutually exclusive terminal flags.
|
|
188
|
+
* Both monotonic (once true, never
|
|
189
|
+
* back to false).
|
|
190
|
+
* - `defaultReason` / `defaultedAtMs` — audit attribution for the
|
|
191
|
+
* default moment.
|
|
192
|
+
*
|
|
193
|
+
* Participants are typed as `IGraceRepaymentParticipant` (extended
|
|
194
|
+
* with per-lender Grace decision fields).
|
|
195
|
+
*/
|
|
196
|
+
exports.IGraceRepaymentShareBlockStateSchema = exports.IShareBlockStateSchema.extend({
|
|
197
|
+
blockType: zod_1.default.literal(exports.ShareBlockTypeSchema.enum.GraceRepayment),
|
|
198
|
+
participants: zod_1.default.record(zod_1.default.string(), exports.IGraceRepaymentParticipantSchema),
|
|
199
|
+
outstandingPrincipalCents: zod_1.default.number().int().nonnegative(),
|
|
200
|
+
outstandingInterestCents: zod_1.default.number().int().nonnegative(),
|
|
201
|
+
/** Unset until the borrower initiates repayment. */
|
|
202
|
+
repaymentSnapshotAtMs: zod_1.default.number().int().nonnegative().optional(),
|
|
203
|
+
/** Computed at snapshot; unset pre-snapshot. */
|
|
204
|
+
blendedRatePercent: zod_1.default.number().optional(),
|
|
205
|
+
/** Computed at snapshot; unset pre-snapshot. */
|
|
206
|
+
finalEffectiveRatePercent: zod_1.default.number().optional(),
|
|
207
|
+
/**
|
|
208
|
+
* Borrower's baseline rate at snapshot. Captured so the
|
|
209
|
+
* `recordRepayment` per-lender settlement can recompute the
|
|
210
|
+
* yield-side interest allocation without rolling the inputs back
|
|
211
|
+
* in through the call (the audit chain already carries
|
|
212
|
+
* `snapshotForRepayment`'s input, but the per-lender allocation
|
|
213
|
+
* function reads from current state, not the prior transaction).
|
|
214
|
+
*/
|
|
215
|
+
snapshotBaselineRatePercent: zod_1.default.number().optional(),
|
|
216
|
+
/** Grace micro-interest at snapshot (e.g., 0.77). */
|
|
217
|
+
snapshotGraceMicroInterestPercent: zod_1.default.number().optional(),
|
|
218
|
+
/** Grace per-ShareBlock fee at snapshot (cents, e.g., 1 = $0.01). */
|
|
219
|
+
snapshotGracePerShareBlockFeeCents: zod_1.default.number().int().nonnegative().optional(),
|
|
220
|
+
fullyRepaid: zod_1.default.boolean(),
|
|
221
|
+
defaulted: zod_1.default.boolean(),
|
|
222
|
+
/** Set when the block transitions to `defaulted: true`. */
|
|
223
|
+
defaultReason: zod_1.default.string().optional(),
|
|
224
|
+
defaultedAtMs: zod_1.default.number().int().nonnegative().optional(),
|
|
225
|
+
});
|
|
124
226
|
//#endregion State
|
|
125
227
|
//#region Metadata
|
|
126
228
|
/**
|
|
@@ -219,4 +321,75 @@ exports.IShareBlockDisburseInputSchema = zod_1.default.object({
|
|
|
219
321
|
exports.IShareBlockMarkFullyDistributedInputSchema = zod_1.default.object({
|
|
220
322
|
userId: zod_1.default.string(),
|
|
221
323
|
});
|
|
324
|
+
/**
|
|
325
|
+
* Input for the GraceRepayment `setLenderGraceDecision` function.
|
|
326
|
+
* Lender-callable while the block is open and pre-snapshot. The block's
|
|
327
|
+
* rules also enforce that the calling userId matches the participant
|
|
328
|
+
* being mutated (lenders can only set their own decisions, not others').
|
|
329
|
+
*/
|
|
330
|
+
exports.IShareBlockSetLenderGraceDecisionInputSchema = zod_1.default.object({
|
|
331
|
+
userId: zod_1.default.string(),
|
|
332
|
+
decision: zod_1.default.enum(['yield', 'grace']),
|
|
333
|
+
decidedAtMs: zod_1.default.number().int().nonnegative(),
|
|
334
|
+
});
|
|
335
|
+
/**
|
|
336
|
+
* Input for the GraceRepayment `snapshotForRepayment` function.
|
|
337
|
+
* Platform-only. Atomic: freezes every Lender participant's
|
|
338
|
+
* `snapshotDecision` from their current `graceDecision`, computes
|
|
339
|
+
* `blendedRatePercent` and `finalEffectiveRatePercent` from the
|
|
340
|
+
* weighted decisions, sets `outstandingInterestCents` to the final
|
|
341
|
+
* computed amount, and stamps `repaymentSnapshotAtMs`.
|
|
342
|
+
*
|
|
343
|
+
* `graceMicroInterestPercent` and `gracePerShareBlockFeeCents` are the
|
|
344
|
+
* platform-fee configuration values used in the math; passing them via
|
|
345
|
+
* the input keeps the variant function pure (no implicit config
|
|
346
|
+
* lookup).
|
|
347
|
+
*/
|
|
348
|
+
exports.IShareBlockSnapshotForRepaymentInputSchema = zod_1.default.object({
|
|
349
|
+
userId: zod_1.default.string(),
|
|
350
|
+
baselineRatePercent: zod_1.default.number().positive(),
|
|
351
|
+
termDays: zod_1.default.number().int().positive(),
|
|
352
|
+
graceMicroInterestPercent: zod_1.default.number().nonnegative(),
|
|
353
|
+
gracePerShareBlockFeeCents: zod_1.default.number().int().nonnegative(),
|
|
354
|
+
snapshotAtMs: zod_1.default.number().int().nonnegative(),
|
|
355
|
+
});
|
|
356
|
+
/**
|
|
357
|
+
* Input for the GraceRepayment `recordRepayment` function. Platform-only.
|
|
358
|
+
* Applies an inbound borrower payment per the snapshot decisions:
|
|
359
|
+
* yield-ShareBlock lenders receive their share of `borrowerInterest`;
|
|
360
|
+
* grace-ShareBlock lenders receive only the micro-interest minus the
|
|
361
|
+
* per-ShareBlock fee. Decrements `outstandingInterestCents` first,
|
|
362
|
+
* then `outstandingPrincipalCents`. Auto-marks `fullyRepaid` when
|
|
363
|
+
* both reach zero.
|
|
364
|
+
*
|
|
365
|
+
* `paymentAttemptId` is the idempotency key — a second call with the
|
|
366
|
+
* same id is a no-op.
|
|
367
|
+
*/
|
|
368
|
+
exports.IShareBlockRecordRepaymentInputSchema = zod_1.default.object({
|
|
369
|
+
userId: zod_1.default.string(),
|
|
370
|
+
paymentAttemptId: zod_1.default.string(),
|
|
371
|
+
amountCents: zod_1.default.number().int().positive(),
|
|
372
|
+
paidAtMs: zod_1.default.number().int().nonnegative(),
|
|
373
|
+
});
|
|
374
|
+
/**
|
|
375
|
+
* Input for the GraceRepayment `markFullyRepaid` function. Platform-only.
|
|
376
|
+
* Asserts `outstandingPrincipalCents === 0 && outstandingInterestCents
|
|
377
|
+
* === 0` before flipping. Mutually exclusive with `markDefaulted`.
|
|
378
|
+
*/
|
|
379
|
+
exports.IShareBlockMarkFullyRepaidInputSchema = zod_1.default.object({
|
|
380
|
+
userId: zod_1.default.string(),
|
|
381
|
+
asOf: zod_1.default.number().int().nonnegative(),
|
|
382
|
+
});
|
|
383
|
+
/**
|
|
384
|
+
* Input for the GraceRepayment `markDefaulted` function. Platform-only.
|
|
385
|
+
* Mutually exclusive with `markFullyRepaid`. Sets the terminal default
|
|
386
|
+
* flag + audit metadata; the post-default flow (lender write-off,
|
|
387
|
+
* borrower loyalty reset, identity-reveal opt-ins) happens in Rapture's
|
|
388
|
+
* trigger layer, not here.
|
|
389
|
+
*/
|
|
390
|
+
exports.IShareBlockMarkDefaultedInputSchema = zod_1.default.object({
|
|
391
|
+
userId: zod_1.default.string(),
|
|
392
|
+
reason: zod_1.default.string().min(1),
|
|
393
|
+
asOf: zod_1.default.number().int().nonnegative(),
|
|
394
|
+
});
|
|
222
395
|
//#endregion Transaction Function Inputs
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@degenerate/generic",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "This contains the generic information needed for the ShareData Adaptive Framework Ecosystem (SAFE) network",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"jsonwebtoken": "^9.0.3",
|
|
46
46
|
"zod": "^4.4.3"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "9453d9ab785e03fd01eb5b408ed0e3ca22baefd5",
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@eslint/js": "^10.0.1",
|
|
51
51
|
"@types/eslint__js": "^8.42.3",
|