@degenerate/generic 0.4.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_settings/cryptography-settings.d.ts +5 -1
- package/dist/_settings/cryptography-settings.d.ts.map +1 -1
- package/dist/_settings/cryptography-settings.js +5 -1
- package/dist/crypto/index.d.ts +5 -9
- package/dist/crypto/index.d.ts.map +1 -1
- package/dist/crypto/index.js +7 -9
- package/dist/crypto/private-public-keys/create-ed25519-keys-from-mnemonic.d.ts +22 -0
- package/dist/crypto/private-public-keys/create-ed25519-keys-from-mnemonic.d.ts.map +1 -0
- package/dist/crypto/private-public-keys/create-ed25519-keys-from-mnemonic.js +65 -0
- package/dist/crypto/private-public-keys/get-ed25519-public-key-from-private-key.d.ts +11 -0
- package/dist/crypto/private-public-keys/get-ed25519-public-key-from-private-key.d.ts.map +1 -0
- package/dist/crypto/private-public-keys/get-ed25519-public-key-from-private-key.js +15 -0
- package/dist/crypto/signature/create-ed25519-signature.d.ts +16 -0
- package/dist/crypto/signature/create-ed25519-signature.d.ts.map +1 -0
- package/dist/crypto/signature/create-ed25519-signature.js +26 -0
- package/dist/crypto/signature/ed25519-primitives.d.ts +25 -0
- package/dist/crypto/signature/ed25519-primitives.d.ts.map +1 -0
- package/dist/crypto/signature/ed25519-primitives.js +65 -0
- package/dist/crypto/signature/verify-ed25519-signature.d.ts +13 -0
- package/dist/crypto/signature/verify-ed25519-signature.d.ts.map +1 -0
- package/dist/crypto/signature/verify-ed25519-signature.js +31 -0
- package/dist/errors/index.d.ts +2 -0
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +2 -0
- package/dist/errors/library/library-errors.d.ts +101 -0
- package/dist/errors/library/library-errors.d.ts.map +1 -0
- package/dist/errors/library/library-errors.js +133 -0
- package/dist/errors/settlement/settlement-errors.d.ts +74 -0
- package/dist/errors/settlement/settlement-errors.d.ts.map +1 -0
- package/dist/errors/settlement/settlement-errors.js +93 -0
- package/dist/errors/share-data/share-data-errors.d.ts +21 -0
- package/dist/errors/share-data/share-data-errors.d.ts.map +1 -1
- package/dist/errors/share-data/share-data-errors.js +30 -1
- package/dist/helpers/apply-share-function.d.ts +23 -0
- package/dist/helpers/apply-share-function.d.ts.map +1 -0
- package/dist/helpers/apply-share-function.js +32 -0
- package/dist/helpers/index.d.ts +1 -0
- package/dist/helpers/index.d.ts.map +1 -1
- package/dist/helpers/index.js +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/library/authorize-library.d.ts +17 -0
- package/dist/library/authorize-library.d.ts.map +1 -0
- package/dist/library/authorize-library.js +39 -0
- package/dist/library/build-library.d.ts +49 -0
- package/dist/library/build-library.d.ts.map +1 -0
- package/dist/library/build-library.js +119 -0
- package/dist/library/caching-library-store.d.ts +19 -0
- package/dist/library/caching-library-store.d.ts.map +1 -0
- package/dist/library/caching-library-store.js +56 -0
- package/dist/library/canonical-json.d.ts +12 -0
- package/dist/library/canonical-json.d.ts.map +1 -0
- package/dist/library/canonical-json.js +30 -0
- package/dist/library/compile-rule-source.d.ts +21 -0
- package/dist/library/compile-rule-source.d.ts.map +1 -0
- package/dist/library/compile-rule-source.js +91 -0
- package/dist/library/evaluate-library-rules.d.ts +36 -0
- package/dist/library/evaluate-library-rules.d.ts.map +1 -0
- package/dist/library/evaluate-library-rules.js +47 -0
- package/dist/library/evaluate-library.d.ts +34 -0
- package/dist/library/evaluate-library.d.ts.map +1 -0
- package/dist/library/evaluate-library.js +66 -0
- package/dist/library/in-memory-library-store.d.ts +22 -0
- package/dist/library/in-memory-library-store.d.ts.map +1 -0
- package/dist/library/in-memory-library-store.js +92 -0
- package/dist/library/index.d.ts +18 -0
- package/dist/library/index.d.ts.map +1 -0
- package/dist/library/index.js +33 -0
- package/dist/library/library-hash.d.ts +9 -0
- package/dist/library/library-hash.d.ts.map +1 -0
- package/dist/library/library-hash.js +14 -0
- package/dist/library/library-models.d.ts +134 -0
- package/dist/library/library-models.d.ts.map +1 -0
- package/dist/library/library-models.js +84 -0
- package/dist/library/library-proof.d.ts +40 -0
- package/dist/library/library-proof.d.ts.map +1 -0
- package/dist/library/library-proof.js +44 -0
- package/dist/library/library-reference.d.ts +75 -0
- package/dist/library/library-reference.d.ts.map +1 -0
- package/dist/library/library-reference.js +98 -0
- package/dist/library/library-server.d.ts +17 -0
- package/dist/library/library-server.d.ts.map +1 -0
- package/dist/library/library-server.js +45 -0
- package/dist/library/library-store.d.ts +37 -0
- package/dist/library/library-store.d.ts.map +1 -0
- package/dist/library/library-store.js +2 -0
- package/dist/library/remote-library-models.d.ts +54 -0
- package/dist/library/remote-library-models.d.ts.map +1 -0
- package/dist/library/remote-library-models.js +2 -0
- package/dist/library/remote-library-store.d.ts +15 -0
- package/dist/library/remote-library-store.d.ts.map +1 -0
- package/dist/library/remote-library-store.js +59 -0
- package/dist/library/verify-library.d.ts +21 -0
- package/dist/library/verify-library.d.ts.map +1 -0
- package/dist/library/verify-library.js +86 -0
- package/dist/models/functions/share-data-function-models.d.ts +6 -74
- package/dist/models/functions/share-data-function-models.d.ts.map +1 -1
- package/dist/models/functions/share-data-function-models.js +7 -65
- package/dist/models/index.d.ts +1 -0
- package/dist/models/index.d.ts.map +1 -1
- package/dist/models/index.js +1 -0
- 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/settlement/settlement-models.d.ts +221 -0
- package/dist/models/settlement/settlement-models.d.ts.map +1 -0
- package/dist/models/settlement/settlement-models.js +152 -0
- package/dist/models/share-data/share-data-models.d.ts +12 -0
- package/dist/models/share-data/share-data-models.d.ts.map +1 -1
- package/dist/models/share-data/share-data-persistence-models.d.ts +3 -0
- package/dist/models/share-data/share-data-persistence-models.d.ts.map +1 -1
- package/dist/models/shareblock/shareblock-models.d.ts +179 -3
- package/dist/models/shareblock/shareblock-models.d.ts.map +1 -1
- package/dist/models/shareblock/shareblock-models.js +99 -7
- package/dist/sandbox/in-process-executor.d.ts +13 -0
- package/dist/sandbox/in-process-executor.d.ts.map +1 -0
- package/dist/sandbox/in-process-executor.js +31 -0
- package/dist/sandbox/index.d.ts +8 -0
- package/dist/sandbox/index.d.ts.map +1 -0
- package/dist/sandbox/index.js +23 -0
- package/dist/sandbox/remote-sandbox-executor.d.ts +12 -0
- package/dist/sandbox/remote-sandbox-executor.d.ts.map +1 -0
- package/dist/sandbox/remote-sandbox-executor.js +49 -0
- package/dist/sandbox/remote-sandbox-models.d.ts +37 -0
- package/dist/sandbox/remote-sandbox-models.d.ts.map +1 -0
- package/dist/sandbox/remote-sandbox-models.js +2 -0
- package/dist/sandbox/rule-evaluator.d.ts +32 -0
- package/dist/sandbox/rule-evaluator.d.ts.map +1 -0
- package/dist/sandbox/rule-evaluator.js +23 -0
- package/dist/sandbox/run-sandboxed.d.ts +24 -0
- package/dist/sandbox/run-sandboxed.d.ts.map +1 -0
- package/dist/sandbox/run-sandboxed.js +88 -0
- package/dist/sandbox/sandbox-models.d.ts +40 -0
- package/dist/sandbox/sandbox-models.d.ts.map +1 -0
- package/dist/sandbox/sandbox-models.js +2 -0
- package/dist/sandbox/sandbox-server.d.ts +22 -0
- package/dist/sandbox/sandbox-server.d.ts.map +1 -0
- package/dist/sandbox/sandbox-server.js +62 -0
- package/package.json +3 -4
- package/dist/crypto/private-public-keys/create-key-pair-from-mnemonic.d.ts +0 -12
- package/dist/crypto/private-public-keys/create-key-pair-from-mnemonic.d.ts.map +0 -1
- package/dist/crypto/private-public-keys/create-key-pair-from-mnemonic.js +0 -54
- package/dist/crypto/private-public-keys/create-key-pair-from-private-key.d.ts +0 -11
- package/dist/crypto/private-public-keys/create-key-pair-from-private-key.d.ts.map +0 -1
- package/dist/crypto/private-public-keys/create-key-pair-from-private-key.js +0 -50
- package/dist/crypto/private-public-keys/create-key-pair-from-public-key.d.ts +0 -11
- package/dist/crypto/private-public-keys/create-key-pair-from-public-key.d.ts.map +0 -1
- package/dist/crypto/private-public-keys/create-key-pair-from-public-key.js +0 -51
- package/dist/crypto/private-public-keys/generation/create-entropy-for-elliptical-curve.d.ts +0 -10
- package/dist/crypto/private-public-keys/generation/create-entropy-for-elliptical-curve.d.ts.map +0 -1
- package/dist/crypto/private-public-keys/generation/create-entropy-for-elliptical-curve.js +0 -51
- package/dist/crypto/private-public-keys/generation/generate-key-pair.d.ts +0 -11
- package/dist/crypto/private-public-keys/generation/generate-key-pair.d.ts.map +0 -1
- package/dist/crypto/private-public-keys/generation/generate-key-pair.js +0 -49
- package/dist/crypto/private-public-keys/generation/get-private-public-key-from-keypair.d.ts +0 -15
- package/dist/crypto/private-public-keys/generation/get-private-public-key-from-keypair.d.ts.map +0 -1
- package/dist/crypto/private-public-keys/generation/get-private-public-key-from-keypair.js +0 -21
- package/dist/crypto/signature/create-crypto-signature.d.ts +0 -20
- package/dist/crypto/signature/create-crypto-signature.d.ts.map +0 -1
- package/dist/crypto/signature/create-crypto-signature.js +0 -26
- package/dist/crypto/signature/verify-crypto-signature-by-data.d.ts +0 -17
- package/dist/crypto/signature/verify-crypto-signature-by-data.d.ts.map +0 -1
- package/dist/crypto/signature/verify-crypto-signature-by-data.js +0 -61
- package/dist/crypto/signature/verify-crypto-signature-by-hash.d.ts +0 -17
- package/dist/crypto/signature/verify-crypto-signature-by-hash.d.ts.map +0 -1
- package/dist/crypto/signature/verify-crypto-signature-by-hash.js +0 -58
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import z from 'zod';
|
|
2
2
|
/**
|
|
3
|
-
* The
|
|
4
|
-
*
|
|
3
|
+
* The ShareBlock specializations the platform uses to move money through a
|
|
4
|
+
* loan's lifecycle, plus the cross-block settlement coordinator.
|
|
5
5
|
*
|
|
6
6
|
* - `Clearing` — neutral holding spot funds pass through before they're
|
|
7
7
|
* committed to either side of a deal. Used to net
|
|
@@ -17,6 +17,11 @@ import z from 'zod';
|
|
|
17
17
|
* allocation when the borrower pays. Terminal state is
|
|
18
18
|
* either `fullyRepaid: true` OR `defaulted: true`,
|
|
19
19
|
* mutually exclusive.
|
|
20
|
+
* - `Settlement` — a cross-block atomic-settlement coordinator. Not a
|
|
21
|
+
* money-holding block: its state is the settlement
|
|
22
|
+
* plan + per-leg status + two-phase-commit phase, and
|
|
23
|
+
* its append-only history is the recovery journal that
|
|
24
|
+
* drives funds across the blocks above all-or-nothing.
|
|
20
25
|
*
|
|
21
26
|
* New ShareBlock variants should be additive — never re-use a value with new
|
|
22
27
|
* semantics, since downstream rule libraries pattern-match on the literal.
|
|
@@ -25,14 +30,42 @@ export declare enum ShareBlockType {
|
|
|
25
30
|
Clearing = "Clearing",
|
|
26
31
|
Funding = "Funding",
|
|
27
32
|
Distribution = "Distribution",
|
|
28
|
-
GraceRepayment = "GraceRepayment"
|
|
33
|
+
GraceRepayment = "GraceRepayment",
|
|
34
|
+
Settlement = "Settlement"
|
|
29
35
|
}
|
|
30
36
|
export declare const ShareBlockTypeSchema: z.ZodEnum<{
|
|
31
37
|
Clearing: "Clearing";
|
|
32
38
|
Funding: "Funding";
|
|
33
39
|
Distribution: "Distribution";
|
|
34
40
|
GraceRepayment: "GraceRepayment";
|
|
41
|
+
Settlement: "Settlement";
|
|
35
42
|
}>;
|
|
43
|
+
/**
|
|
44
|
+
* Direction of a settlement leg relative to one participating block:
|
|
45
|
+
*
|
|
46
|
+
* - `debit` — funds leave this block (it is the source). On reserve the
|
|
47
|
+
* amount is removed from spendable `balance` and held.
|
|
48
|
+
* - `credit` — funds arrive at this block (it is the destination). On
|
|
49
|
+
* reserve nothing moves yet; the amount lands at commit.
|
|
50
|
+
*
|
|
51
|
+
* Shared by the per-block reservation bucket and the coordinator's leg list.
|
|
52
|
+
*/
|
|
53
|
+
export declare const SettlementLegDirectionSchema: z.ZodEnum<{
|
|
54
|
+
debit: "debit";
|
|
55
|
+
credit: "credit";
|
|
56
|
+
}>;
|
|
57
|
+
export type SettlementLegDirection = z.infer<typeof SettlementLegDirectionSchema>;
|
|
58
|
+
/**
|
|
59
|
+
* Lifecycle of one block's reservation for a settlement. Advances forward
|
|
60
|
+
* only: `reserved → committed` (finalized) or `reserved → released` (unwound
|
|
61
|
+
* on abort). A standard rule enforces the monotonicity.
|
|
62
|
+
*/
|
|
63
|
+
export declare const ReservationStatusSchema: z.ZodEnum<{
|
|
64
|
+
reserved: "reserved";
|
|
65
|
+
committed: "committed";
|
|
66
|
+
released: "released";
|
|
67
|
+
}>;
|
|
68
|
+
export type ReservationStatus = z.infer<typeof ReservationStatusSchema>;
|
|
36
69
|
/**
|
|
37
70
|
* Roles a participant plays inside a ShareBlock. A single party may hold
|
|
38
71
|
* multiple roles across different ShareBlocks (e.g. the same uid is `Lender`
|
|
@@ -68,6 +101,37 @@ export declare const IShareBlockParticipantSchema: z.ZodObject<{
|
|
|
68
101
|
settledAmount: z.ZodNumber;
|
|
69
102
|
}, z.core.$strip>;
|
|
70
103
|
export type IShareBlockParticipant = z.infer<typeof IShareBlockParticipantSchema>;
|
|
104
|
+
/**
|
|
105
|
+
* One block's record of funds it is holding for an in-flight settlement,
|
|
106
|
+
* stored under `settlementId` in the block's `reservations` bucket. The
|
|
107
|
+
* per-block half of the two-phase-commit money model:
|
|
108
|
+
*
|
|
109
|
+
* - debit leg — `amountCents` is already removed from `balance` and held
|
|
110
|
+
* here until the settlement commits (finalized out) or aborts
|
|
111
|
+
* (returned to `balance`).
|
|
112
|
+
* - credit leg — pending incoming funds; `balance` is unchanged until the
|
|
113
|
+
* settlement commits, at which point `amountCents` lands.
|
|
114
|
+
*
|
|
115
|
+
* `againstHash` pins the leg to the block's current-state hash at sign time
|
|
116
|
+
* (D5 drift guard): if the block advanced since the leg was signed, the
|
|
117
|
+
* reserve proof fails at the transaction boundary and the settlement aborts.
|
|
118
|
+
*/
|
|
119
|
+
export declare const IReservedLegSchema: z.ZodObject<{
|
|
120
|
+
settlementId: z.ZodString;
|
|
121
|
+
direction: z.ZodEnum<{
|
|
122
|
+
debit: "debit";
|
|
123
|
+
credit: "credit";
|
|
124
|
+
}>;
|
|
125
|
+
amountCents: z.ZodNumber;
|
|
126
|
+
currency: z.ZodString;
|
|
127
|
+
againstHash: z.ZodString;
|
|
128
|
+
status: z.ZodEnum<{
|
|
129
|
+
reserved: "reserved";
|
|
130
|
+
committed: "committed";
|
|
131
|
+
released: "released";
|
|
132
|
+
}>;
|
|
133
|
+
}, z.core.$strip>;
|
|
134
|
+
export type IReservedLeg = z.infer<typeof IReservedLegSchema>;
|
|
71
135
|
/**
|
|
72
136
|
* The mutable state carried inside a ShareBlock's `_currentState`. This is
|
|
73
137
|
* the canonical shape rules and functions inspect when proposing changes.
|
|
@@ -80,6 +144,11 @@ export type IShareBlockParticipant = z.infer<typeof IShareBlockParticipantSchema
|
|
|
80
144
|
* - `participants` — committed parties keyed by `userId`. Adding a
|
|
81
145
|
* participant goes through a rule-gated function so the
|
|
82
146
|
* participant list itself is auditable.
|
|
147
|
+
* - `reservations` — in-flight settlement holds keyed by `settlementId`.
|
|
148
|
+
* Optional and absent by default; a block only carries this
|
|
149
|
+
* once it opts into the settlement capability and a settlement
|
|
150
|
+
* reserves against it. Funds held here are excluded from
|
|
151
|
+
* spendable `balance` (debit legs are already deducted).
|
|
83
152
|
*/
|
|
84
153
|
export declare const IShareBlockStateSchema: z.ZodObject<{
|
|
85
154
|
blockType: z.ZodEnum<{
|
|
@@ -87,6 +156,7 @@ export declare const IShareBlockStateSchema: z.ZodObject<{
|
|
|
87
156
|
Funding: "Funding";
|
|
88
157
|
Distribution: "Distribution";
|
|
89
158
|
GraceRepayment: "GraceRepayment";
|
|
159
|
+
Settlement: "Settlement";
|
|
90
160
|
}>;
|
|
91
161
|
balance: z.ZodNumber;
|
|
92
162
|
currency: z.ZodString;
|
|
@@ -102,6 +172,21 @@ export declare const IShareBlockStateSchema: z.ZodObject<{
|
|
|
102
172
|
committedAmount: z.ZodNumber;
|
|
103
173
|
settledAmount: z.ZodNumber;
|
|
104
174
|
}, z.core.$strip>>;
|
|
175
|
+
reservations: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
176
|
+
settlementId: z.ZodString;
|
|
177
|
+
direction: z.ZodEnum<{
|
|
178
|
+
debit: "debit";
|
|
179
|
+
credit: "credit";
|
|
180
|
+
}>;
|
|
181
|
+
amountCents: z.ZodNumber;
|
|
182
|
+
currency: z.ZodString;
|
|
183
|
+
againstHash: z.ZodString;
|
|
184
|
+
status: z.ZodEnum<{
|
|
185
|
+
reserved: "reserved";
|
|
186
|
+
committed: "committed";
|
|
187
|
+
released: "released";
|
|
188
|
+
}>;
|
|
189
|
+
}, z.core.$strip>>>;
|
|
105
190
|
}, z.core.$strip>;
|
|
106
191
|
export type IShareBlockState = z.infer<typeof IShareBlockStateSchema>;
|
|
107
192
|
/**
|
|
@@ -130,6 +215,21 @@ export declare const IFundingShareBlockStateSchema: z.ZodObject<{
|
|
|
130
215
|
committedAmount: z.ZodNumber;
|
|
131
216
|
settledAmount: z.ZodNumber;
|
|
132
217
|
}, z.core.$strip>>;
|
|
218
|
+
reservations: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
219
|
+
settlementId: z.ZodString;
|
|
220
|
+
direction: z.ZodEnum<{
|
|
221
|
+
debit: "debit";
|
|
222
|
+
credit: "credit";
|
|
223
|
+
}>;
|
|
224
|
+
amountCents: z.ZodNumber;
|
|
225
|
+
currency: z.ZodString;
|
|
226
|
+
againstHash: z.ZodString;
|
|
227
|
+
status: z.ZodEnum<{
|
|
228
|
+
reserved: "reserved";
|
|
229
|
+
committed: "committed";
|
|
230
|
+
released: "released";
|
|
231
|
+
}>;
|
|
232
|
+
}, z.core.$strip>>>;
|
|
133
233
|
blockType: z.ZodLiteral<"Funding">;
|
|
134
234
|
committed: z.ZodBoolean;
|
|
135
235
|
committedBy: z.ZodOptional<z.ZodString>;
|
|
@@ -163,6 +263,21 @@ export declare const IDistributionShareBlockStateSchema: z.ZodObject<{
|
|
|
163
263
|
committedAmount: z.ZodNumber;
|
|
164
264
|
settledAmount: z.ZodNumber;
|
|
165
265
|
}, z.core.$strip>>;
|
|
266
|
+
reservations: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
267
|
+
settlementId: z.ZodString;
|
|
268
|
+
direction: z.ZodEnum<{
|
|
269
|
+
debit: "debit";
|
|
270
|
+
credit: "credit";
|
|
271
|
+
}>;
|
|
272
|
+
amountCents: z.ZodNumber;
|
|
273
|
+
currency: z.ZodString;
|
|
274
|
+
againstHash: z.ZodString;
|
|
275
|
+
status: z.ZodEnum<{
|
|
276
|
+
reserved: "reserved";
|
|
277
|
+
committed: "committed";
|
|
278
|
+
released: "released";
|
|
279
|
+
}>;
|
|
280
|
+
}, z.core.$strip>>>;
|
|
166
281
|
blockType: z.ZodLiteral<"Distribution">;
|
|
167
282
|
distributed: z.ZodBoolean;
|
|
168
283
|
distributedBy: z.ZodOptional<z.ZodString>;
|
|
@@ -251,6 +366,21 @@ export declare const IGraceRepaymentShareBlockStateSchema: z.ZodObject<{
|
|
|
251
366
|
balance: z.ZodNumber;
|
|
252
367
|
currency: z.ZodString;
|
|
253
368
|
isOpen: z.ZodBoolean;
|
|
369
|
+
reservations: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
370
|
+
settlementId: z.ZodString;
|
|
371
|
+
direction: z.ZodEnum<{
|
|
372
|
+
debit: "debit";
|
|
373
|
+
credit: "credit";
|
|
374
|
+
}>;
|
|
375
|
+
amountCents: z.ZodNumber;
|
|
376
|
+
currency: z.ZodString;
|
|
377
|
+
againstHash: z.ZodString;
|
|
378
|
+
status: z.ZodEnum<{
|
|
379
|
+
reserved: "reserved";
|
|
380
|
+
committed: "committed";
|
|
381
|
+
released: "released";
|
|
382
|
+
}>;
|
|
383
|
+
}, z.core.$strip>>>;
|
|
254
384
|
blockType: z.ZodLiteral<"GraceRepayment">;
|
|
255
385
|
participants: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
256
386
|
userId: z.ZodString;
|
|
@@ -301,6 +431,7 @@ export declare const IShareBlockMetadataSchema: z.ZodObject<{
|
|
|
301
431
|
Funding: "Funding";
|
|
302
432
|
Distribution: "Distribution";
|
|
303
433
|
GraceRepayment: "GraceRepayment";
|
|
434
|
+
Settlement: "Settlement";
|
|
304
435
|
}>;
|
|
305
436
|
relatedLoanApplicationId: z.ZodOptional<z.ZodString>;
|
|
306
437
|
description: z.ZodOptional<z.ZodString>;
|
|
@@ -486,4 +617,49 @@ export declare const IShareBlockMarkDefaultedInputSchema: z.ZodObject<{
|
|
|
486
617
|
asOf: z.ZodNumber;
|
|
487
618
|
}, z.core.$strip>;
|
|
488
619
|
export type IShareBlockMarkDefaultedInput = z.infer<typeof IShareBlockMarkDefaultedInputSchema>;
|
|
620
|
+
/**
|
|
621
|
+
* Input for the generic `reserveForSettlement` function (any block that opted
|
|
622
|
+
* into the settlement capability). Phase-1 (PREPARE) of the two-phase commit:
|
|
623
|
+
* holds `amountCents` for `settlementId`. `direction` selects debit (deduct
|
|
624
|
+
* from `balance`) vs credit (pending incoming, no balance change).
|
|
625
|
+
* `expectedHash` is the block's current-state hash the leg was signed against
|
|
626
|
+
* — the function rejects if it does not match, backing up the proof-chain
|
|
627
|
+
* drift guard (D5). Idempotent: a second reserve for the same `settlementId`
|
|
628
|
+
* is a no-op.
|
|
629
|
+
*/
|
|
630
|
+
export declare const IShareBlockReserveForSettlementInputSchema: z.ZodObject<{
|
|
631
|
+
userId: z.ZodString;
|
|
632
|
+
settlementId: z.ZodString;
|
|
633
|
+
direction: z.ZodEnum<{
|
|
634
|
+
debit: "debit";
|
|
635
|
+
credit: "credit";
|
|
636
|
+
}>;
|
|
637
|
+
amountCents: z.ZodNumber;
|
|
638
|
+
currency: z.ZodString;
|
|
639
|
+
expectedHash: z.ZodString;
|
|
640
|
+
}, z.core.$strip>;
|
|
641
|
+
export type IShareBlockReserveForSettlementInput = z.infer<typeof IShareBlockReserveForSettlementInputSchema>;
|
|
642
|
+
/**
|
|
643
|
+
* Input for the generic `commitSettlement` function. Phase-2 finalize for one
|
|
644
|
+
* leg: credit legs add the held amount to `balance`; both directions then
|
|
645
|
+
* clear the reservation. Carries only the settlement id — amount and
|
|
646
|
+
* direction are read from the stored reservation. Idempotent: a second call
|
|
647
|
+
* once the reservation is gone is a no-op.
|
|
648
|
+
*/
|
|
649
|
+
export declare const IShareBlockCommitSettlementInputSchema: z.ZodObject<{
|
|
650
|
+
userId: z.ZodString;
|
|
651
|
+
settlementId: z.ZodString;
|
|
652
|
+
}, z.core.$strip>;
|
|
653
|
+
export type IShareBlockCommitSettlementInput = z.infer<typeof IShareBlockCommitSettlementInputSchema>;
|
|
654
|
+
/**
|
|
655
|
+
* Input for the generic `releaseSettlement` function. Abort-path unwind for
|
|
656
|
+
* one leg: debit legs return the held amount to `balance`; both directions
|
|
657
|
+
* delete the reservation. Idempotent: releasing an absent reservation is a
|
|
658
|
+
* no-op.
|
|
659
|
+
*/
|
|
660
|
+
export declare const IShareBlockReleaseSettlementInputSchema: z.ZodObject<{
|
|
661
|
+
userId: z.ZodString;
|
|
662
|
+
settlementId: z.ZodString;
|
|
663
|
+
}, z.core.$strip>;
|
|
664
|
+
export type IShareBlockReleaseSettlementInput = z.infer<typeof IShareBlockReleaseSettlementInputSchema>;
|
|
489
665
|
//# 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;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,oBAAY,cAAc;IACtB,QAAQ,aAAa;IACrB,OAAO,YAAY;IACnB,Y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C,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;AAExD;;;;;;;;;GASG;AACH,eAAO,MAAM,0CAA0C;;;;;;;;;;iBAOrD,CAAC;AACH,MAAM,MAAM,oCAAoC,GAC5C,CAAC,CAAC,KAAK,CAAC,OAAO,0CAA0C,CAAC,CAAC;AAE/D;;;;;;GAMG;AACH,eAAO,MAAM,sCAAsC;;;iBAGjD,CAAC;AACH,MAAM,MAAM,gCAAgC,GACxC,CAAC,CAAC,KAAK,CAAC,OAAO,sCAAsC,CAAC,CAAC;AAE3D;;;;;GAKG;AACH,eAAO,MAAM,uCAAuC;;;iBAGlD,CAAC;AACH,MAAM,MAAM,iCAAiC,GACzC,CAAC,CAAC,KAAK,CAAC,OAAO,uCAAuC,CAAC,CAAC"}
|
|
@@ -3,12 +3,12 @@ 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.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;
|
|
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
|
|
11
|
-
*
|
|
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
13
|
* - `Clearing` — neutral holding spot funds pass through before they're
|
|
14
14
|
* committed to either side of a deal. Used to net
|
|
@@ -24,6 +24,11 @@ const zod_1 = __importDefault(require("zod"));
|
|
|
24
24
|
* allocation when the borrower pays. Terminal state is
|
|
25
25
|
* either `fullyRepaid: true` OR `defaulted: true`,
|
|
26
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.
|
|
27
32
|
*
|
|
28
33
|
* New ShareBlock variants should be additive — never re-use a value with new
|
|
29
34
|
* semantics, since downstream rule libraries pattern-match on the literal.
|
|
@@ -34,13 +39,32 @@ var ShareBlockType;
|
|
|
34
39
|
ShareBlockType["Funding"] = "Funding";
|
|
35
40
|
ShareBlockType["Distribution"] = "Distribution";
|
|
36
41
|
ShareBlockType["GraceRepayment"] = "GraceRepayment";
|
|
42
|
+
ShareBlockType["Settlement"] = "Settlement";
|
|
37
43
|
})(ShareBlockType || (exports.ShareBlockType = ShareBlockType = {}));
|
|
38
44
|
exports.ShareBlockTypeSchema = zod_1.default.enum([
|
|
39
45
|
'Clearing',
|
|
40
46
|
'Funding',
|
|
41
47
|
'Distribution',
|
|
42
48
|
'GraceRepayment',
|
|
49
|
+
'Settlement',
|
|
43
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']);
|
|
44
68
|
//#endregion Enums
|
|
45
69
|
//#region Participant
|
|
46
70
|
/**
|
|
@@ -75,6 +99,29 @@ exports.IShareBlockParticipantSchema = zod_1.default.object({
|
|
|
75
99
|
});
|
|
76
100
|
//#endregion Participant
|
|
77
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
|
+
});
|
|
78
125
|
/**
|
|
79
126
|
* The mutable state carried inside a ShareBlock's `_currentState`. This is
|
|
80
127
|
* the canonical shape rules and functions inspect when proposing changes.
|
|
@@ -87,6 +134,11 @@ exports.IShareBlockParticipantSchema = zod_1.default.object({
|
|
|
87
134
|
* - `participants` — committed parties keyed by `userId`. Adding a
|
|
88
135
|
* participant goes through a rule-gated function so the
|
|
89
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).
|
|
90
142
|
*/
|
|
91
143
|
exports.IShareBlockStateSchema = zod_1.default.object({
|
|
92
144
|
blockType: exports.ShareBlockTypeSchema,
|
|
@@ -94,6 +146,7 @@ exports.IShareBlockStateSchema = zod_1.default.object({
|
|
|
94
146
|
currency: zod_1.default.string().min(3).max(3),
|
|
95
147
|
isOpen: zod_1.default.boolean(),
|
|
96
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(),
|
|
97
150
|
});
|
|
98
151
|
/**
|
|
99
152
|
* Funding-specific extension of `IShareBlockState`. Adds:
|
|
@@ -263,11 +316,11 @@ exports.IShareBlockInitialStateInputSchema = zod_1.default.object({
|
|
|
263
316
|
*/
|
|
264
317
|
exports.IShareBlockDepositInputSchema = zod_1.default.object({
|
|
265
318
|
userId: zod_1.default.string(),
|
|
266
|
-
amount: zod_1.default.number().positive(),
|
|
319
|
+
amount: zod_1.default.number().positive().finite(),
|
|
267
320
|
});
|
|
268
321
|
exports.IShareBlockWithdrawInputSchema = zod_1.default.object({
|
|
269
322
|
userId: zod_1.default.string(),
|
|
270
|
-
amount: zod_1.default.number().positive(),
|
|
323
|
+
amount: zod_1.default.number().positive().finite(),
|
|
271
324
|
});
|
|
272
325
|
exports.IShareBlockCloseInputSchema = zod_1.default.object({
|
|
273
326
|
userId: zod_1.default.string(), // Who is closing the block — used for audit attribution.
|
|
@@ -303,7 +356,7 @@ exports.IShareBlockRegisterLenderInputSchema = zod_1.default.object({
|
|
|
303
356
|
*/
|
|
304
357
|
exports.IShareBlockFundInputSchema = zod_1.default.object({
|
|
305
358
|
fromBlockId: zod_1.default.string().optional(), // upstream block id when known
|
|
306
|
-
amount: zod_1.default.number().positive(),
|
|
359
|
+
amount: zod_1.default.number().positive().finite(),
|
|
307
360
|
});
|
|
308
361
|
/**
|
|
309
362
|
* Input for the Distribution-specific `disburse` function. `userId` must
|
|
@@ -311,7 +364,7 @@ exports.IShareBlockFundInputSchema = zod_1.default.object({
|
|
|
311
364
|
*/
|
|
312
365
|
exports.IShareBlockDisburseInputSchema = zod_1.default.object({
|
|
313
366
|
userId: zod_1.default.string(),
|
|
314
|
-
amount: zod_1.default.number().positive(),
|
|
367
|
+
amount: zod_1.default.number().positive().finite(),
|
|
315
368
|
});
|
|
316
369
|
/**
|
|
317
370
|
* Input for the Distribution-specific `markFullyDistributed` function.
|
|
@@ -392,4 +445,43 @@ exports.IShareBlockMarkDefaultedInputSchema = zod_1.default.object({
|
|
|
392
445
|
reason: zod_1.default.string().min(1),
|
|
393
446
|
asOf: zod_1.default.number().int().nonnegative(),
|
|
394
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().min(1),
|
|
464
|
+
expectedHash: zod_1.default.string().min(1),
|
|
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
|
+
});
|
|
395
487
|
//#endregion Transaction Function Inputs
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FunctionExecutor } from './sandbox-models';
|
|
2
|
+
/**
|
|
3
|
+
* An in-process {@link FunctionExecutor} over the shared sandbox core
|
|
4
|
+
* ({@link runSandboxed}). It runs `({ current, input }) => state` and requires a
|
|
5
|
+
* plain state object back; a Promise or any non-object is rejected as
|
|
6
|
+
* `invalid-output` (async is not permitted — the timeout cannot bound it and it
|
|
7
|
+
* would break reproducibility).
|
|
8
|
+
*
|
|
9
|
+
* NOT a security sandbox (see {@link runSandboxed}); for trusted standard
|
|
10
|
+
* functions and tests. It enforces the gas ceiling and determinism.
|
|
11
|
+
*/
|
|
12
|
+
export declare const createInProcessFunctionExecutor: () => FunctionExecutor;
|
|
13
|
+
//# sourceMappingURL=in-process-executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-process-executor.d.ts","sourceRoot":"","sources":["../../src/sandbox/in-process-executor.ts"],"names":[],"mappings":"AAEA,OAAO,EAGH,gBAAgB,EACnB,MAAM,kBAAkB,CAAC;AAE1B;;;;;;;;;GASG;AACH,eAAO,MAAM,+BAA+B,QAAO,gBAejD,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createInProcessFunctionExecutor = void 0;
|
|
4
|
+
const run_sandboxed_1 = require("./run-sandboxed");
|
|
5
|
+
/**
|
|
6
|
+
* An in-process {@link FunctionExecutor} over the shared sandbox core
|
|
7
|
+
* ({@link runSandboxed}). It runs `({ current, input }) => state` and requires a
|
|
8
|
+
* plain state object back; a Promise or any non-object is rejected as
|
|
9
|
+
* `invalid-output` (async is not permitted — the timeout cannot bound it and it
|
|
10
|
+
* would break reproducibility).
|
|
11
|
+
*
|
|
12
|
+
* NOT a security sandbox (see {@link runSandboxed}); for trusted standard
|
|
13
|
+
* functions and tests. It enforces the gas ceiling and determinism.
|
|
14
|
+
*/
|
|
15
|
+
const createInProcessFunctionExecutor = () => ({
|
|
16
|
+
async execute(request) {
|
|
17
|
+
const run = (0, run_sandboxed_1.runSandboxed)(request.source, { current: request.current, input: request.input }, request.gasLimit);
|
|
18
|
+
if (!run.ok) {
|
|
19
|
+
return { ok: false, failure: run.failure, error: run.error, gasUsed: run.gasUsed, executionTime: run.executionTime };
|
|
20
|
+
}
|
|
21
|
+
if (!isPlainStateObject(run.value)) {
|
|
22
|
+
return { ok: false, failure: 'invalid-output', gasUsed: run.gasUsed, executionTime: run.executionTime };
|
|
23
|
+
}
|
|
24
|
+
return { ok: true, output: run.value, gasUsed: run.gasUsed, executionTime: run.executionTime };
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
exports.createInProcessFunctionExecutor = createInProcessFunctionExecutor;
|
|
28
|
+
const isPlainStateObject = (value) => value !== null &&
|
|
29
|
+
typeof value === 'object' &&
|
|
30
|
+
!Array.isArray(value) &&
|
|
31
|
+
typeof value.then !== 'function'; // reject Promises (async not allowed)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './sandbox-models';
|
|
2
|
+
export * from './run-sandboxed';
|
|
3
|
+
export * from './in-process-executor';
|
|
4
|
+
export * from './rule-evaluator';
|
|
5
|
+
export * from './remote-sandbox-models';
|
|
6
|
+
export * from './remote-sandbox-executor';
|
|
7
|
+
export * from './sandbox-server';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sandbox/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./sandbox-models"), exports);
|
|
18
|
+
__exportStar(require("./run-sandboxed"), exports);
|
|
19
|
+
__exportStar(require("./in-process-executor"), exports);
|
|
20
|
+
__exportStar(require("./rule-evaluator"), exports);
|
|
21
|
+
__exportStar(require("./remote-sandbox-models"), exports);
|
|
22
|
+
__exportStar(require("./remote-sandbox-executor"), exports);
|
|
23
|
+
__exportStar(require("./sandbox-server"), exports);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FunctionExecutor } from './sandbox-models';
|
|
2
|
+
import { RuleEvaluator } from './rule-evaluator';
|
|
3
|
+
import { SandboxTransport } from './remote-sandbox-models';
|
|
4
|
+
/**
|
|
5
|
+
* A {@link FunctionExecutor} that runs source on a remote sandbox via a
|
|
6
|
+
* {@link SandboxTransport}. Drop-in interchangeable with the in-process
|
|
7
|
+
* executor — the application path does not know or care which it holds.
|
|
8
|
+
*/
|
|
9
|
+
export declare const createRemoteSandboxFunctionExecutor: (transport: SandboxTransport) => FunctionExecutor;
|
|
10
|
+
/** A {@link RuleEvaluator} that runs rule source on a remote sandbox. */
|
|
11
|
+
export declare const createRemoteSandboxRuleEvaluator: (transport: SandboxTransport) => RuleEvaluator;
|
|
12
|
+
//# sourceMappingURL=remote-sandbox-executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remote-sandbox-executor.d.ts","sourceRoot":"","sources":["../../src/sandbox/remote-sandbox-executor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqD,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACvG,OAAO,EAA+C,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC9F,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D;;;;GAIG;AACH,eAAO,MAAM,mCAAmC,GAAI,WAAW,gBAAgB,KAAG,gBAkBhF,CAAC;AAEH,yEAAyE;AACzE,eAAO,MAAM,gCAAgC,GAAI,WAAW,gBAAgB,KAAG,aAkB7E,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createRemoteSandboxRuleEvaluator = exports.createRemoteSandboxFunctionExecutor = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* A {@link FunctionExecutor} that runs source on a remote sandbox via a
|
|
6
|
+
* {@link SandboxTransport}. Drop-in interchangeable with the in-process
|
|
7
|
+
* executor — the application path does not know or care which it holds.
|
|
8
|
+
*/
|
|
9
|
+
const createRemoteSandboxFunctionExecutor = (transport) => ({
|
|
10
|
+
async execute(request) {
|
|
11
|
+
const response = await transport.send({
|
|
12
|
+
kind: 'function',
|
|
13
|
+
source: request.source,
|
|
14
|
+
current: request.current,
|
|
15
|
+
input: request.input,
|
|
16
|
+
gasLimit: request.gasLimit,
|
|
17
|
+
});
|
|
18
|
+
return {
|
|
19
|
+
ok: response.ok,
|
|
20
|
+
output: response.output,
|
|
21
|
+
failure: response.failure,
|
|
22
|
+
error: response.error,
|
|
23
|
+
gasUsed: response.gasUsed,
|
|
24
|
+
executionTime: response.executionTime,
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
exports.createRemoteSandboxFunctionExecutor = createRemoteSandboxFunctionExecutor;
|
|
29
|
+
/** A {@link RuleEvaluator} that runs rule source on a remote sandbox. */
|
|
30
|
+
const createRemoteSandboxRuleEvaluator = (transport) => ({
|
|
31
|
+
async evaluate(request) {
|
|
32
|
+
const response = await transport.send({
|
|
33
|
+
kind: 'rule',
|
|
34
|
+
source: request.source,
|
|
35
|
+
current: request.current,
|
|
36
|
+
proposed: request.proposed,
|
|
37
|
+
gasLimit: request.gasLimit,
|
|
38
|
+
});
|
|
39
|
+
return {
|
|
40
|
+
ok: response.ok,
|
|
41
|
+
passed: response.passed,
|
|
42
|
+
failure: response.failure,
|
|
43
|
+
error: response.error,
|
|
44
|
+
gasUsed: response.gasUsed,
|
|
45
|
+
executionTime: response.executionTime,
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
exports.createRemoteSandboxRuleEvaluator = createRemoteSandboxRuleEvaluator;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { IShareData } from '../models/share-data/share-data-models';
|
|
2
|
+
import { RuleEvaluationFailure } from './rule-evaluator';
|
|
3
|
+
/**
|
|
4
|
+
* A portable-JSON request sent to a sandbox server. Discriminated by `kind`:
|
|
5
|
+
* a function carries `input`, a rule carries `proposed`.
|
|
6
|
+
*/
|
|
7
|
+
export interface RemoteSandboxRequest {
|
|
8
|
+
kind: 'function' | 'rule';
|
|
9
|
+
source: string;
|
|
10
|
+
gasLimit: number;
|
|
11
|
+
current: IShareData;
|
|
12
|
+
input?: unknown;
|
|
13
|
+
proposed?: IShareData;
|
|
14
|
+
}
|
|
15
|
+
/** A portable-JSON response from a sandbox server. */
|
|
16
|
+
export interface RemoteSandboxResponse {
|
|
17
|
+
ok: boolean;
|
|
18
|
+
output?: IShareData;
|
|
19
|
+
passed?: boolean;
|
|
20
|
+
failure?: RuleEvaluationFailure;
|
|
21
|
+
error?: string;
|
|
22
|
+
gasUsed: number;
|
|
23
|
+
executionTime: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The pluggable transport (a "port") that carries a request to a remote sandbox
|
|
27
|
+
* and returns its response. The consumer wires this to their HTTP client, so
|
|
28
|
+
* `@degenerate/generic` stays dependency-free — no `http`/`fetch` import here,
|
|
29
|
+
* the same discipline as the realtime Redis port.
|
|
30
|
+
*
|
|
31
|
+
* `send` may reject on a transport-level failure (network, timeout); that
|
|
32
|
+
* propagates to the caller rather than being mapped to an execution failure.
|
|
33
|
+
*/
|
|
34
|
+
export interface SandboxTransport {
|
|
35
|
+
send(request: RemoteSandboxRequest): Promise<RemoteSandboxResponse>;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=remote-sandbox-models.d.ts.map
|