@degenerate/generic 0.3.2 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/dist/_settings/cryptography-settings.d.ts +5 -1
  2. package/dist/_settings/cryptography-settings.d.ts.map +1 -1
  3. package/dist/_settings/cryptography-settings.js +5 -1
  4. package/dist/_settings/database-settings.d.ts +3 -0
  5. package/dist/_settings/database-settings.d.ts.map +1 -1
  6. package/dist/_settings/database-settings.js +3 -0
  7. package/dist/crypto/index.d.ts +5 -9
  8. package/dist/crypto/index.d.ts.map +1 -1
  9. package/dist/crypto/index.js +7 -9
  10. package/dist/crypto/private-public-keys/create-ed25519-keys-from-mnemonic.d.ts +22 -0
  11. package/dist/crypto/private-public-keys/create-ed25519-keys-from-mnemonic.d.ts.map +1 -0
  12. package/dist/crypto/private-public-keys/create-ed25519-keys-from-mnemonic.js +65 -0
  13. package/dist/crypto/private-public-keys/get-ed25519-public-key-from-private-key.d.ts +11 -0
  14. package/dist/crypto/private-public-keys/get-ed25519-public-key-from-private-key.d.ts.map +1 -0
  15. package/dist/crypto/private-public-keys/get-ed25519-public-key-from-private-key.js +15 -0
  16. package/dist/crypto/signature/create-ed25519-signature.d.ts +16 -0
  17. package/dist/crypto/signature/create-ed25519-signature.d.ts.map +1 -0
  18. package/dist/crypto/signature/create-ed25519-signature.js +26 -0
  19. package/dist/crypto/signature/ed25519-primitives.d.ts +25 -0
  20. package/dist/crypto/signature/ed25519-primitives.d.ts.map +1 -0
  21. package/dist/crypto/signature/ed25519-primitives.js +65 -0
  22. package/dist/crypto/signature/verify-ed25519-signature.d.ts +13 -0
  23. package/dist/crypto/signature/verify-ed25519-signature.d.ts.map +1 -0
  24. package/dist/crypto/signature/verify-ed25519-signature.js +31 -0
  25. package/dist/errors/index.d.ts +1 -0
  26. package/dist/errors/index.d.ts.map +1 -1
  27. package/dist/errors/index.js +1 -0
  28. package/dist/errors/settlement/settlement-errors.d.ts +74 -0
  29. package/dist/errors/settlement/settlement-errors.d.ts.map +1 -0
  30. package/dist/errors/settlement/settlement-errors.js +93 -0
  31. package/dist/errors/share-data/share-data-errors.d.ts +13 -0
  32. package/dist/errors/share-data/share-data-errors.d.ts.map +1 -1
  33. package/dist/errors/share-data/share-data-errors.js +19 -1
  34. package/dist/models/index.d.ts +1 -0
  35. package/dist/models/index.d.ts.map +1 -1
  36. package/dist/models/index.js +1 -0
  37. package/dist/models/safe/transactions/sharedata-transactions-models.d.ts +10 -0
  38. package/dist/models/safe/transactions/sharedata-transactions-models.d.ts.map +1 -1
  39. package/dist/models/settlement/settlement-models.d.ts +221 -0
  40. package/dist/models/settlement/settlement-models.d.ts.map +1 -0
  41. package/dist/models/settlement/settlement-models.js +152 -0
  42. package/dist/models/share-data/share-data-crypto-models.d.ts +37 -0
  43. package/dist/models/share-data/share-data-crypto-models.d.ts.map +1 -1
  44. package/dist/models/share-data/share-data-crypto-models.js +41 -1
  45. package/dist/models/share-data/share-data-persistence-models.d.ts +12 -2
  46. package/dist/models/share-data/share-data-persistence-models.d.ts.map +1 -1
  47. package/dist/models/share-data/share-data-persistence-models.js +9 -2
  48. package/dist/models/shareblock/shareblock-models.d.ts +395 -10
  49. package/dist/models/shareblock/shareblock-models.d.ts.map +1 -1
  50. package/dist/models/shareblock/shareblock-models.js +275 -10
  51. package/package.json +3 -4
  52. package/dist/crypto/private-public-keys/create-key-pair-from-mnemonic.d.ts +0 -12
  53. package/dist/crypto/private-public-keys/create-key-pair-from-mnemonic.d.ts.map +0 -1
  54. package/dist/crypto/private-public-keys/create-key-pair-from-mnemonic.js +0 -54
  55. package/dist/crypto/private-public-keys/create-key-pair-from-private-key.d.ts +0 -11
  56. package/dist/crypto/private-public-keys/create-key-pair-from-private-key.d.ts.map +0 -1
  57. package/dist/crypto/private-public-keys/create-key-pair-from-private-key.js +0 -50
  58. package/dist/crypto/private-public-keys/create-key-pair-from-public-key.d.ts +0 -11
  59. package/dist/crypto/private-public-keys/create-key-pair-from-public-key.d.ts.map +0 -1
  60. package/dist/crypto/private-public-keys/create-key-pair-from-public-key.js +0 -51
  61. package/dist/crypto/private-public-keys/generation/create-entropy-for-elliptical-curve.d.ts +0 -10
  62. package/dist/crypto/private-public-keys/generation/create-entropy-for-elliptical-curve.d.ts.map +0 -1
  63. package/dist/crypto/private-public-keys/generation/create-entropy-for-elliptical-curve.js +0 -51
  64. package/dist/crypto/private-public-keys/generation/generate-key-pair.d.ts +0 -11
  65. package/dist/crypto/private-public-keys/generation/generate-key-pair.d.ts.map +0 -1
  66. package/dist/crypto/private-public-keys/generation/generate-key-pair.js +0 -49
  67. package/dist/crypto/private-public-keys/generation/get-private-public-key-from-keypair.d.ts +0 -15
  68. package/dist/crypto/private-public-keys/generation/get-private-public-key-from-keypair.d.ts.map +0 -1
  69. package/dist/crypto/private-public-keys/generation/get-private-public-key-from-keypair.js +0 -21
  70. package/dist/crypto/signature/create-crypto-signature.d.ts +0 -20
  71. package/dist/crypto/signature/create-crypto-signature.d.ts.map +0 -1
  72. package/dist/crypto/signature/create-crypto-signature.js +0 -26
  73. package/dist/crypto/signature/verify-crypto-signature-by-data.d.ts +0 -17
  74. package/dist/crypto/signature/verify-crypto-signature-by-data.d.ts.map +0 -1
  75. package/dist/crypto/signature/verify-crypto-signature-by-data.js +0 -61
  76. package/dist/crypto/signature/verify-crypto-signature-by-hash.d.ts +0 -17
  77. package/dist/crypto/signature/verify-crypto-signature-by-hash.d.ts.map +0 -1
  78. package/dist/crypto/signature/verify-crypto-signature-by-hash.js +0 -58
@@ -3,20 +3,32 @@ 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.IShareBlockReleaseSettlementInputSchema = exports.IShareBlockCommitSettlementInputSchema = exports.IShareBlockReserveForSettlementInputSchema = 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.IReservedLegSchema = exports.IShareBlockParticipantSchema = exports.ShareBlockParticipantRoleSchema = exports.ShareBlockParticipantRole = exports.ReservationStatusSchema = exports.SettlementLegDirectionSchema = exports.ShareBlockTypeSchema = exports.ShareBlockType = void 0;
7
7
  const zod_1 = __importDefault(require("zod"));
8
8
  //#region Enums
9
9
  /**
10
- * The three ShareBlock specializations the platform uses to move money
11
- * through a loan's lifecycle.
10
+ * The ShareBlock specializations the platform uses to move money through a
11
+ * loan's lifecycle, plus the cross-block settlement coordinator.
12
12
  *
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.
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.
27
+ * - `Settlement` — a cross-block atomic-settlement coordinator. Not a
28
+ * money-holding block: its state is the settlement
29
+ * plan + per-leg status + two-phase-commit phase, and
30
+ * its append-only history is the recovery journal that
31
+ * drives funds across the blocks above all-or-nothing.
20
32
  *
21
33
  * New ShareBlock variants should be additive — never re-use a value with new
22
34
  * semantics, since downstream rule libraries pattern-match on the literal.
@@ -26,12 +38,33 @@ var ShareBlockType;
26
38
  ShareBlockType["Clearing"] = "Clearing";
27
39
  ShareBlockType["Funding"] = "Funding";
28
40
  ShareBlockType["Distribution"] = "Distribution";
41
+ ShareBlockType["GraceRepayment"] = "GraceRepayment";
42
+ ShareBlockType["Settlement"] = "Settlement";
29
43
  })(ShareBlockType || (exports.ShareBlockType = ShareBlockType = {}));
30
44
  exports.ShareBlockTypeSchema = zod_1.default.enum([
31
45
  'Clearing',
32
46
  'Funding',
33
47
  'Distribution',
48
+ 'GraceRepayment',
49
+ 'Settlement',
34
50
  ]);
51
+ /**
52
+ * Direction of a settlement leg relative to one participating block:
53
+ *
54
+ * - `debit` — funds leave this block (it is the source). On reserve the
55
+ * amount is removed from spendable `balance` and held.
56
+ * - `credit` — funds arrive at this block (it is the destination). On
57
+ * reserve nothing moves yet; the amount lands at commit.
58
+ *
59
+ * Shared by the per-block reservation bucket and the coordinator's leg list.
60
+ */
61
+ exports.SettlementLegDirectionSchema = zod_1.default.enum(['debit', 'credit']);
62
+ /**
63
+ * Lifecycle of one block's reservation for a settlement. Advances forward
64
+ * only: `reserved → committed` (finalized) or `reserved → released` (unwound
65
+ * on abort). A standard rule enforces the monotonicity.
66
+ */
67
+ exports.ReservationStatusSchema = zod_1.default.enum(['reserved', 'committed', 'released']);
35
68
  //#endregion Enums
36
69
  //#region Participant
37
70
  /**
@@ -66,6 +99,29 @@ exports.IShareBlockParticipantSchema = zod_1.default.object({
66
99
  });
67
100
  //#endregion Participant
68
101
  //#region State
102
+ /**
103
+ * One block's record of funds it is holding for an in-flight settlement,
104
+ * stored under `settlementId` in the block's `reservations` bucket. The
105
+ * per-block half of the two-phase-commit money model:
106
+ *
107
+ * - debit leg — `amountCents` is already removed from `balance` and held
108
+ * here until the settlement commits (finalized out) or aborts
109
+ * (returned to `balance`).
110
+ * - credit leg — pending incoming funds; `balance` is unchanged until the
111
+ * settlement commits, at which point `amountCents` lands.
112
+ *
113
+ * `againstHash` pins the leg to the block's current-state hash at sign time
114
+ * (D5 drift guard): if the block advanced since the leg was signed, the
115
+ * reserve proof fails at the transaction boundary and the settlement aborts.
116
+ */
117
+ exports.IReservedLegSchema = zod_1.default.object({
118
+ settlementId: zod_1.default.string(),
119
+ direction: exports.SettlementLegDirectionSchema,
120
+ amountCents: zod_1.default.number().int().positive(),
121
+ currency: zod_1.default.string(),
122
+ againstHash: zod_1.default.string(),
123
+ status: exports.ReservationStatusSchema,
124
+ });
69
125
  /**
70
126
  * The mutable state carried inside a ShareBlock's `_currentState`. This is
71
127
  * the canonical shape rules and functions inspect when proposing changes.
@@ -78,6 +134,11 @@ exports.IShareBlockParticipantSchema = zod_1.default.object({
78
134
  * - `participants` — committed parties keyed by `userId`. Adding a
79
135
  * participant goes through a rule-gated function so the
80
136
  * participant list itself is auditable.
137
+ * - `reservations` — in-flight settlement holds keyed by `settlementId`.
138
+ * Optional and absent by default; a block only carries this
139
+ * once it opts into the settlement capability and a settlement
140
+ * reserves against it. Funds held here are excluded from
141
+ * spendable `balance` (debit legs are already deducted).
81
142
  */
82
143
  exports.IShareBlockStateSchema = zod_1.default.object({
83
144
  blockType: exports.ShareBlockTypeSchema,
@@ -85,6 +146,7 @@ exports.IShareBlockStateSchema = zod_1.default.object({
85
146
  currency: zod_1.default.string().min(3).max(3),
86
147
  isOpen: zod_1.default.boolean(),
87
148
  participants: zod_1.default.record(zod_1.default.string(), exports.IShareBlockParticipantSchema),
149
+ reservations: zod_1.default.record(zod_1.default.string(), exports.IReservedLegSchema).optional(),
88
150
  });
89
151
  /**
90
152
  * Funding-specific extension of `IShareBlockState`. Adds:
@@ -121,6 +183,99 @@ exports.IDistributionShareBlockStateSchema = exports.IShareBlockStateSchema.exte
121
183
  distributedBy: zod_1.default.string().optional(),
122
184
  distributedAt: zod_1.default.number().optional(),
123
185
  });
186
+ /**
187
+ * GraceRepayment-specific participant. Extends the base participant with
188
+ * three Grace-specific fields plus a denormalized ShareBlock count:
189
+ *
190
+ * - `graceDecision` — Lender-only field. The lender's current
191
+ * choice: take their yield, grant Grace, or
192
+ * undecided (the initial state when the
193
+ * GraceRepayment block is constructed).
194
+ * Borrower and Platform participants always
195
+ * carry `'undecided'` and never mutate it.
196
+ * - `decidedAtMs` — Unix-ms timestamp the lender last set their
197
+ * decision. `null` while undecided.
198
+ * - `snapshotDecision` — The locked-in decision at the moment the
199
+ * borrower initiated repayment. `null` until
200
+ * snapshot. After snapshot it's the
201
+ * authoritative value the per-lender
202
+ * settlement uses.
203
+ * - `shareBlockCount` — Derived count of $10 ShareBlocks held by
204
+ * this lender on this loan
205
+ * (`committedAmount / 1000` for cents-based
206
+ * committed amounts). Cached for fast UI
207
+ * queries; the canonical source is still
208
+ * `committedAmount`.
209
+ */
210
+ exports.IGraceRepaymentParticipantSchema = exports.IShareBlockParticipantSchema.extend({
211
+ graceDecision: zod_1.default.enum(['yield', 'grace', 'undecided']),
212
+ /** Unset until the lender first sets a decision. */
213
+ decidedAtMs: zod_1.default.number().int().nonnegative().optional(),
214
+ /** Unset until the borrower initiates repayment. */
215
+ snapshotDecision: zod_1.default.enum(['yield', 'grace']).optional(),
216
+ shareBlockCount: zod_1.default.number().int().nonnegative(),
217
+ });
218
+ /**
219
+ * GraceRepayment-specific extension of `IShareBlockState`. Adds:
220
+ *
221
+ * - `outstandingPrincipalCents` — running principal balance the
222
+ * borrower owes. Decrements as
223
+ * repayments land.
224
+ * - `outstandingInterestCents` — interest owed at the time of
225
+ * repayment snapshot. Computed
226
+ * atomically at snapshot from the
227
+ * blended rate; decrements as
228
+ * repayments land.
229
+ * - `repaymentSnapshotAtMs` — unix-ms timestamp the per-lender
230
+ * Grace decisions were locked in.
231
+ * `null` until the borrower
232
+ * initiates repayment.
233
+ * - `blendedRatePercent` — weighted-average effective rate
234
+ * computed at snapshot. `null` pre-
235
+ * snapshot.
236
+ * - `finalEffectiveRatePercent` — what the borrower actually pays;
237
+ * equal to `blendedRatePercent`
238
+ * under the standard formula. `null`
239
+ * pre-snapshot.
240
+ * - `fullyRepaid` / `defaulted` — mutually exclusive terminal flags.
241
+ * Both monotonic (once true, never
242
+ * back to false).
243
+ * - `defaultReason` / `defaultedAtMs` — audit attribution for the
244
+ * default moment.
245
+ *
246
+ * Participants are typed as `IGraceRepaymentParticipant` (extended
247
+ * with per-lender Grace decision fields).
248
+ */
249
+ exports.IGraceRepaymentShareBlockStateSchema = exports.IShareBlockStateSchema.extend({
250
+ blockType: zod_1.default.literal(exports.ShareBlockTypeSchema.enum.GraceRepayment),
251
+ participants: zod_1.default.record(zod_1.default.string(), exports.IGraceRepaymentParticipantSchema),
252
+ outstandingPrincipalCents: zod_1.default.number().int().nonnegative(),
253
+ outstandingInterestCents: zod_1.default.number().int().nonnegative(),
254
+ /** Unset until the borrower initiates repayment. */
255
+ repaymentSnapshotAtMs: zod_1.default.number().int().nonnegative().optional(),
256
+ /** Computed at snapshot; unset pre-snapshot. */
257
+ blendedRatePercent: zod_1.default.number().optional(),
258
+ /** Computed at snapshot; unset pre-snapshot. */
259
+ finalEffectiveRatePercent: zod_1.default.number().optional(),
260
+ /**
261
+ * Borrower's baseline rate at snapshot. Captured so the
262
+ * `recordRepayment` per-lender settlement can recompute the
263
+ * yield-side interest allocation without rolling the inputs back
264
+ * in through the call (the audit chain already carries
265
+ * `snapshotForRepayment`'s input, but the per-lender allocation
266
+ * function reads from current state, not the prior transaction).
267
+ */
268
+ snapshotBaselineRatePercent: zod_1.default.number().optional(),
269
+ /** Grace micro-interest at snapshot (e.g., 0.77). */
270
+ snapshotGraceMicroInterestPercent: zod_1.default.number().optional(),
271
+ /** Grace per-ShareBlock fee at snapshot (cents, e.g., 1 = $0.01). */
272
+ snapshotGracePerShareBlockFeeCents: zod_1.default.number().int().nonnegative().optional(),
273
+ fullyRepaid: zod_1.default.boolean(),
274
+ defaulted: zod_1.default.boolean(),
275
+ /** Set when the block transitions to `defaulted: true`. */
276
+ defaultReason: zod_1.default.string().optional(),
277
+ defaultedAtMs: zod_1.default.number().int().nonnegative().optional(),
278
+ });
124
279
  //#endregion State
125
280
  //#region Metadata
126
281
  /**
@@ -219,4 +374,114 @@ exports.IShareBlockDisburseInputSchema = zod_1.default.object({
219
374
  exports.IShareBlockMarkFullyDistributedInputSchema = zod_1.default.object({
220
375
  userId: zod_1.default.string(),
221
376
  });
377
+ /**
378
+ * Input for the GraceRepayment `setLenderGraceDecision` function.
379
+ * Lender-callable while the block is open and pre-snapshot. The block's
380
+ * rules also enforce that the calling userId matches the participant
381
+ * being mutated (lenders can only set their own decisions, not others').
382
+ */
383
+ exports.IShareBlockSetLenderGraceDecisionInputSchema = zod_1.default.object({
384
+ userId: zod_1.default.string(),
385
+ decision: zod_1.default.enum(['yield', 'grace']),
386
+ decidedAtMs: zod_1.default.number().int().nonnegative(),
387
+ });
388
+ /**
389
+ * Input for the GraceRepayment `snapshotForRepayment` function.
390
+ * Platform-only. Atomic: freezes every Lender participant's
391
+ * `snapshotDecision` from their current `graceDecision`, computes
392
+ * `blendedRatePercent` and `finalEffectiveRatePercent` from the
393
+ * weighted decisions, sets `outstandingInterestCents` to the final
394
+ * computed amount, and stamps `repaymentSnapshotAtMs`.
395
+ *
396
+ * `graceMicroInterestPercent` and `gracePerShareBlockFeeCents` are the
397
+ * platform-fee configuration values used in the math; passing them via
398
+ * the input keeps the variant function pure (no implicit config
399
+ * lookup).
400
+ */
401
+ exports.IShareBlockSnapshotForRepaymentInputSchema = zod_1.default.object({
402
+ userId: zod_1.default.string(),
403
+ baselineRatePercent: zod_1.default.number().positive(),
404
+ termDays: zod_1.default.number().int().positive(),
405
+ graceMicroInterestPercent: zod_1.default.number().nonnegative(),
406
+ gracePerShareBlockFeeCents: zod_1.default.number().int().nonnegative(),
407
+ snapshotAtMs: zod_1.default.number().int().nonnegative(),
408
+ });
409
+ /**
410
+ * Input for the GraceRepayment `recordRepayment` function. Platform-only.
411
+ * Applies an inbound borrower payment per the snapshot decisions:
412
+ * yield-ShareBlock lenders receive their share of `borrowerInterest`;
413
+ * grace-ShareBlock lenders receive only the micro-interest minus the
414
+ * per-ShareBlock fee. Decrements `outstandingInterestCents` first,
415
+ * then `outstandingPrincipalCents`. Auto-marks `fullyRepaid` when
416
+ * both reach zero.
417
+ *
418
+ * `paymentAttemptId` is the idempotency key — a second call with the
419
+ * same id is a no-op.
420
+ */
421
+ exports.IShareBlockRecordRepaymentInputSchema = zod_1.default.object({
422
+ userId: zod_1.default.string(),
423
+ paymentAttemptId: zod_1.default.string(),
424
+ amountCents: zod_1.default.number().int().positive(),
425
+ paidAtMs: zod_1.default.number().int().nonnegative(),
426
+ });
427
+ /**
428
+ * Input for the GraceRepayment `markFullyRepaid` function. Platform-only.
429
+ * Asserts `outstandingPrincipalCents === 0 && outstandingInterestCents
430
+ * === 0` before flipping. Mutually exclusive with `markDefaulted`.
431
+ */
432
+ exports.IShareBlockMarkFullyRepaidInputSchema = zod_1.default.object({
433
+ userId: zod_1.default.string(),
434
+ asOf: zod_1.default.number().int().nonnegative(),
435
+ });
436
+ /**
437
+ * Input for the GraceRepayment `markDefaulted` function. Platform-only.
438
+ * Mutually exclusive with `markFullyRepaid`. Sets the terminal default
439
+ * flag + audit metadata; the post-default flow (lender write-off,
440
+ * borrower loyalty reset, identity-reveal opt-ins) happens in Rapture's
441
+ * trigger layer, not here.
442
+ */
443
+ exports.IShareBlockMarkDefaultedInputSchema = zod_1.default.object({
444
+ userId: zod_1.default.string(),
445
+ reason: zod_1.default.string().min(1),
446
+ asOf: zod_1.default.number().int().nonnegative(),
447
+ });
448
+ /**
449
+ * Input for the generic `reserveForSettlement` function (any block that opted
450
+ * into the settlement capability). Phase-1 (PREPARE) of the two-phase commit:
451
+ * holds `amountCents` for `settlementId`. `direction` selects debit (deduct
452
+ * from `balance`) vs credit (pending incoming, no balance change).
453
+ * `expectedHash` is the block's current-state hash the leg was signed against
454
+ * — the function rejects if it does not match, backing up the proof-chain
455
+ * drift guard (D5). Idempotent: a second reserve for the same `settlementId`
456
+ * is a no-op.
457
+ */
458
+ exports.IShareBlockReserveForSettlementInputSchema = zod_1.default.object({
459
+ userId: zod_1.default.string(),
460
+ settlementId: zod_1.default.string(),
461
+ direction: exports.SettlementLegDirectionSchema,
462
+ amountCents: zod_1.default.number().int().positive(),
463
+ currency: zod_1.default.string(),
464
+ expectedHash: zod_1.default.string(),
465
+ });
466
+ /**
467
+ * Input for the generic `commitSettlement` function. Phase-2 finalize for one
468
+ * leg: credit legs add the held amount to `balance`; both directions then
469
+ * clear the reservation. Carries only the settlement id — amount and
470
+ * direction are read from the stored reservation. Idempotent: a second call
471
+ * once the reservation is gone is a no-op.
472
+ */
473
+ exports.IShareBlockCommitSettlementInputSchema = zod_1.default.object({
474
+ userId: zod_1.default.string(),
475
+ settlementId: zod_1.default.string(),
476
+ });
477
+ /**
478
+ * Input for the generic `releaseSettlement` function. Abort-path unwind for
479
+ * one leg: debit legs return the held amount to `balance`; both directions
480
+ * delete the reservation. Idempotent: releasing an absent reservation is a
481
+ * no-op.
482
+ */
483
+ exports.IShareBlockReleaseSettlementInputSchema = zod_1.default.object({
484
+ userId: zod_1.default.string(),
485
+ settlementId: zod_1.default.string(),
486
+ });
222
487
  //#endregion Transaction Function Inputs
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@degenerate/generic",
3
- "version": "0.3.2",
3
+ "version": "0.6.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",
@@ -38,14 +38,13 @@
38
38
  },
39
39
  "homepage": "https://github.com/syncrude/safe#readme",
40
40
  "dependencies": {
41
- "@types/elliptic": "^6.4.18",
41
+ "@noble/ed25519": "3.1.0",
42
42
  "bip39": "^3.1.0",
43
- "elliptic": "^6.6.1",
44
43
  "firebase-admin": "^13.9.0",
45
44
  "jsonwebtoken": "^9.0.3",
46
45
  "zod": "^4.4.3"
47
46
  },
48
- "gitHead": "c33ed2f06679f5bd76c2eccf7054212c1820a014",
47
+ "gitHead": "c8c1a2f456cdb01a74f85779275b246361e33b81",
49
48
  "devDependencies": {
50
49
  "@eslint/js": "^10.0.1",
51
50
  "@types/eslint__js": "^8.42.3",
@@ -1,12 +0,0 @@
1
- import * as Elliptic from 'elliptic';
2
- import { EllipticalCurvesSigning, EllipticalCurvesEncryption } from '../../_settings/cryptography-settings';
3
- /**
4
- * This function creates a key pair from a mnemonic using the elliptic library.
5
- *
6
- * @param curve the elliptical curve to create the key pair for.
7
- * @param mnemonic the mnemonic to create the key pair from.
8
- * @returns
9
- */
10
- declare const createKeyPairFromMnemonic: (curve: EllipticalCurvesSigning | EllipticalCurvesEncryption, mnemonic: string) => Elliptic.ec.KeyPair;
11
- export { createKeyPairFromMnemonic };
12
- //# sourceMappingURL=create-key-pair-from-mnemonic.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-key-pair-from-mnemonic.d.ts","sourceRoot":"","sources":["../../../src/crypto/private-public-keys/create-key-pair-from-mnemonic.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAC;AAErC,OAAO,EAAE,uBAAuB,EAAE,0BAA0B,EAAkB,MAAM,uCAAuC,CAAC;AAE5H;;;;;;GAMG;AACH,QAAA,MAAM,yBAAyB,GAAI,OAAO,uBAAuB,GAAG,0BAA0B,EAAE,UAAU,MAAM,KAAG,QAAQ,CAAC,EAAE,CAAC,OAO9H,CAAC;AAEF,OAAO,EAAE,yBAAyB,EAAE,CAAC"}
@@ -1,54 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.createKeyPairFromMnemonic = void 0;
37
- /* eslint-disable new-cap */
38
- const Elliptic = __importStar(require("elliptic"));
39
- const crypto = __importStar(require("crypto"));
40
- const cryptography_settings_1 = require("../../_settings/cryptography-settings");
41
- /**
42
- * This function creates a key pair from a mnemonic using the elliptic library.
43
- *
44
- * @param curve the elliptical curve to create the key pair for.
45
- * @param mnemonic the mnemonic to create the key pair from.
46
- * @returns
47
- */
48
- const createKeyPairFromMnemonic = (curve, mnemonic) => {
49
- const ellipticalCurve = new Elliptic.ec(curve);
50
- const hash = crypto.createHash(cryptography_settings_1.CryptoSettings.Hash.Algorithm).update(mnemonic, cryptography_settings_1.CryptoSettings.TextEncoding).digest(cryptography_settings_1.CryptoSettings.Hash.Digest);
51
- const keyPair = ellipticalCurve.keyFromPrivate(hash);
52
- return keyPair;
53
- };
54
- exports.createKeyPairFromMnemonic = createKeyPairFromMnemonic;
@@ -1,11 +0,0 @@
1
- import * as Elliptic from 'elliptic';
2
- import { EllipticalCurvesSigning, EllipticalCurvesEncryption } from '../../_settings/cryptography-settings';
3
- /**
4
- * This function creates a key pair from a private key using the elliptic library.
5
- * @param curve the elliptical curve to create the key pair for.
6
- * @param privateKey the private key in hexadecimal format.
7
- * @returns
8
- */
9
- declare const createKeyPairFromPrivateKey: (curve: EllipticalCurvesSigning | EllipticalCurvesEncryption, privateKey: string) => Elliptic.ec.KeyPair;
10
- export { createKeyPairFromPrivateKey };
11
- //# sourceMappingURL=create-key-pair-from-private-key.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-key-pair-from-private-key.d.ts","sourceRoot":"","sources":["../../../src/crypto/private-public-keys/create-key-pair-from-private-key.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,uBAAuB,EAAE,0BAA0B,EAAE,MAAM,uCAAuC,CAAC;AAE5G;;;;;GAKG;AACH,QAAA,MAAM,2BAA2B,GAAI,OAAO,uBAAuB,GAAG,0BAA0B,EAC5F,YAAY,MAAM,KAAG,QAAQ,CAAC,EAAE,CAAC,OAKpC,CAAC;AAEF,OAAO,EAAE,2BAA2B,EAAE,CAAC"}
@@ -1,50 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.createKeyPairFromPrivateKey = void 0;
37
- /* eslint-disable new-cap */
38
- const Elliptic = __importStar(require("elliptic"));
39
- /**
40
- * This function creates a key pair from a private key using the elliptic library.
41
- * @param curve the elliptical curve to create the key pair for.
42
- * @param privateKey the private key in hexadecimal format.
43
- * @returns
44
- */
45
- const createKeyPairFromPrivateKey = (curve, privateKey) => {
46
- const ellipticalCurve = new Elliptic.ec(curve);
47
- const keyPair = ellipticalCurve.keyFromPrivate(privateKey, 'hex');
48
- return keyPair;
49
- };
50
- exports.createKeyPairFromPrivateKey = createKeyPairFromPrivateKey;
@@ -1,11 +0,0 @@
1
- import * as Elliptic from 'elliptic';
2
- import { EllipticalCurvesEncryption, EllipticalCurvesSigning } from '../../_settings/cryptography-settings';
3
- /**
4
- * This function creates a key pair from a public key using the elliptic library.
5
- *
6
- * @param curve the elliptical curve to create the key pair for.
7
- * @param publicKey the public key in hexadecimal format.
8
- * @returns
9
- */
10
- export declare const createKeyPairFromPublicKey: (curve: EllipticalCurvesSigning | EllipticalCurvesEncryption, publicKey: string, encoding?: BufferEncoding) => Elliptic.ec.KeyPair;
11
- //# sourceMappingURL=create-key-pair-from-public-key.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-key-pair-from-public-key.d.ts","sourceRoot":"","sources":["../../../src/crypto/private-public-keys/create-key-pair-from-public-key.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,0BAA0B,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAE5G;;;;;;GAMG;AACH,eAAO,MAAM,0BAA0B,GACnC,OAAO,uBAAuB,GAAG,0BAA0B,EAC3D,WAAW,MAAM,EACjB,WAAU,cAAsB,KACjC,QAAQ,CAAC,EAAE,CAAC,OAKd,CAAC"}
@@ -1,51 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.createKeyPairFromPublicKey = void 0;
37
- /* eslint-disable new-cap */
38
- const Elliptic = __importStar(require("elliptic"));
39
- /**
40
- * This function creates a key pair from a public key using the elliptic library.
41
- *
42
- * @param curve the elliptical curve to create the key pair for.
43
- * @param publicKey the public key in hexadecimal format.
44
- * @returns
45
- */
46
- const createKeyPairFromPublicKey = (curve, publicKey, encoding = 'hex') => {
47
- const ellipticalCurve = new Elliptic.ec(curve);
48
- const keyPair = ellipticalCurve.keyFromPublic(publicKey, encoding);
49
- return keyPair;
50
- };
51
- exports.createKeyPairFromPublicKey = createKeyPairFromPublicKey;
@@ -1,10 +0,0 @@
1
- import { EllipticalCurvesEncryption, EllipticalCurvesSigning } from '../../../_settings/cryptography-settings';
2
- /**
3
- * Creates entropy for an elliptical curve.
4
- *
5
- * @param signingCurve - The elliptical curve to create entropy for.
6
- * @returns The entropy for the elliptical curve. string in hexadecimal format.
7
- */
8
- declare const createEntropyForEllipitalCurve: (curve: EllipticalCurvesSigning | EllipticalCurvesEncryption) => string;
9
- export { createEntropyForEllipitalCurve };
10
- //# sourceMappingURL=create-entropy-for-elliptical-curve.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-entropy-for-elliptical-curve.d.ts","sourceRoot":"","sources":["../../../../src/crypto/private-public-keys/generation/create-entropy-for-elliptical-curve.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,0BAA0B,EAAE,uBAAuB,EAAE,MAAM,0CAA0C,CAAC;AAG/G;;;;;GAKG;AACH,QAAA,MAAM,8BAA8B,GAAI,OAAO,uBAAuB,GAAG,0BAA0B,KAAG,MAQrG,CAAC;AAEF,OAAO,EAAE,8BAA8B,EAAE,CAAC"}
@@ -1,51 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.createEntropyForEllipitalCurve = void 0;
37
- const Elliptic = __importStar(require("elliptic"));
38
- /**
39
- * Creates entropy for an elliptical curve.
40
- *
41
- * @param signingCurve - The elliptical curve to create entropy for.
42
- * @returns The entropy for the elliptical curve. string in hexadecimal format.
43
- */
44
- const createEntropyForEllipitalCurve = (curve) => {
45
- const ecKey = new Elliptic.ec(curve);
46
- const hashStrength = ecKey.hash.hmacStrength;
47
- const entropy = Elliptic.rand(hashStrength);
48
- const entropyHex = entropy.toString('hex');
49
- return entropyHex;
50
- };
51
- exports.createEntropyForEllipitalCurve = createEntropyForEllipitalCurve;
@@ -1,11 +0,0 @@
1
- import { EllipticalCurvesSigning, EllipticalCurvesEncryption } from '../../../_settings/cryptography-settings';
2
- import * as Elliptic from 'elliptic';
3
- /**
4
- * This function generates a key pair from a private key and entropy using the elliptic library.
5
- *
6
- * @param privateKey the private key in hexadecimal format
7
- * @param entropy the entropy in hexadecimal format
8
- */
9
- declare const generateKeyPair: (curve: EllipticalCurvesSigning | EllipticalCurvesEncryption, privateKey: string, entropy: string) => Elliptic.ec.KeyPair;
10
- export { generateKeyPair };
11
- //# sourceMappingURL=generate-key-pair.d.ts.map