@ottochain/sdk 2.3.0 → 2.5.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/cjs/apps/compute/index.js +33 -0
- package/dist/cjs/apps/compute/state-machines/compute-rule110.js +164 -0
- package/dist/cjs/apps/compute/state-machines/index.js +9 -0
- package/dist/cjs/apps/contracts/index.js +16 -9
- package/dist/cjs/apps/contracts/state-machines/contract-agreement.js +134 -161
- package/dist/cjs/apps/contracts/state-machines/contract-escrow.js +192 -170
- package/dist/cjs/apps/contracts/state-machines/contract-universal.js +46 -58
- package/dist/cjs/apps/corporate/index.js +2 -2
- package/dist/cjs/apps/corporate/state-machines/corp-board.js +500 -456
- package/dist/cjs/apps/corporate/state-machines/corp-entity.js +487 -361
- package/dist/cjs/apps/corporate/state-machines/corp-securities.js +769 -576
- package/dist/cjs/apps/corporate/state-machines/corp-shareholders.js +567 -557
- package/dist/cjs/apps/governance/index.js +21 -21
- package/dist/cjs/apps/governance/state-machines/dao-multisig.js +188 -209
- package/dist/cjs/apps/governance/state-machines/dao-reputation.js +181 -228
- package/dist/cjs/apps/governance/state-machines/dao-single.js +105 -88
- package/dist/cjs/apps/governance/state-machines/dao-token.js +199 -227
- package/dist/cjs/apps/governance/state-machines/governance-simple.js +231 -231
- package/dist/cjs/apps/governance/state-machines/governance-universal.js +64 -64
- package/dist/cjs/apps/identity/constants.js +55 -22
- package/dist/cjs/apps/identity/index.js +28 -12
- package/dist/cjs/apps/identity/state-machines/identity-agent.js +124 -158
- package/dist/cjs/apps/identity/state-machines/identity-oracle.js +158 -173
- package/dist/cjs/apps/identity/state-machines/identity-registry.js +262 -0
- package/dist/cjs/apps/identity/state-machines/identity-universal.js +51 -57
- package/dist/cjs/apps/identity/state-machines/index.js +3 -1
- package/dist/cjs/apps/index.js +22 -8
- package/dist/cjs/apps/lending/assets.js +247 -0
- package/dist/cjs/apps/lending/credit-scoring.js +87 -0
- package/dist/cjs/apps/lending/eligibility.js +105 -0
- package/dist/cjs/apps/lending/index.js +91 -0
- package/dist/cjs/apps/lending/state-machines/index.js +9 -0
- package/dist/cjs/apps/lending/state-machines/lending-zk-loan.js +433 -0
- package/dist/cjs/apps/markets/index.js +22 -12
- package/dist/cjs/apps/markets/state-machines/market-auction.js +116 -134
- package/dist/cjs/apps/markets/state-machines/market-crowdfund.js +131 -141
- package/dist/cjs/apps/markets/state-machines/market-group-buy.js +163 -184
- package/dist/cjs/apps/markets/state-machines/market-prediction.js +226 -233
- package/dist/cjs/apps/markets/state-machines/market-universal.js +65 -80
- package/dist/cjs/apps/oracles/index.js +3 -3
- package/dist/cjs/apps/privacy/index.js +67 -0
- package/dist/cjs/apps/privacy/state-machines/index.js +17 -0
- package/dist/cjs/apps/privacy/state-machines/mixer-ddhRing.js +286 -0
- package/dist/cjs/apps/privacy/state-machines/note-pool.js +476 -0
- package/dist/cjs/apps/staked-pool/assets.js +103 -0
- package/dist/cjs/apps/staked-pool/base.js +498 -0
- package/dist/cjs/apps/staked-pool/consumer.js +55 -0
- package/dist/cjs/apps/staked-pool/index.js +83 -0
- package/dist/cjs/apps/staked-pool/state-machines/index.js +12 -0
- package/dist/cjs/apps/staked-pool/state-machines/staked-pool-base.js +49 -0
- package/dist/cjs/apps/staked-pool/state-machines/staked-pool-oracle.js +131 -0
- package/dist/cjs/errors.js +3 -3
- package/dist/cjs/generated/google/protobuf/struct.js +5 -5
- package/dist/cjs/generated/google/protobuf/timestamp.js +1 -1
- package/dist/cjs/generated/index.js +11 -7
- package/dist/cjs/generated/openapi.js +6 -0
- package/dist/cjs/generated/ottochain/apps/contracts/v1/contract.js +51 -51
- package/dist/cjs/generated/ottochain/apps/corporate/v1/corporate.js +20 -21
- package/dist/cjs/generated/ottochain/apps/governance/v1/governance.js +14 -14
- package/dist/cjs/generated/ottochain/apps/identity/v1/attestation.js +5 -5
- package/dist/cjs/generated/ottochain/apps/identity/v1/identity.js +125 -131
- package/dist/cjs/generated/ottochain/apps/markets/v1/market.js +108 -108
- package/dist/cjs/generated/ottochain/v1/common.js +5 -5
- package/dist/cjs/generated/ottochain/v1/fiber.js +44 -6
- package/dist/cjs/generated/ottochain/v1/messages.js +1 -1
- package/dist/cjs/generated/ottochain/v1/records.js +1 -1
- package/dist/cjs/index.js +58 -7
- package/dist/cjs/openapi.js +2 -0
- package/dist/cjs/ottochain/drop-nulls.js +1 -2
- package/dist/cjs/ottochain/genesis-manifest.js +17 -11
- package/dist/cjs/ottochain/index.js +23 -13
- package/dist/cjs/ottochain/metagraph-client.js +81 -16
- package/dist/cjs/ottochain/snapshot.js +13 -16
- package/dist/cjs/ottochain/transaction.js +67 -14
- package/dist/cjs/ottochain/types.js +16 -2
- package/dist/cjs/privacy/index.js +14 -0
- package/dist/cjs/privacy/sealed-bid.js +213 -0
- package/dist/cjs/privacy/shield-app.js +131 -0
- package/dist/cjs/schema/effects.js +156 -0
- package/dist/cjs/schema/fiber-app.js +150 -15
- package/dist/cjs/schema/guard-lint.js +343 -0
- package/dist/cjs/schema/guards.js +246 -0
- package/dist/cjs/signing.js +80 -0
- package/dist/cjs/templates/asset-policy.js +190 -0
- package/dist/cjs/templates/index.js +86 -0
- package/dist/cjs/templates/machine.js +130 -0
- package/dist/cjs/templates/migration.js +39 -0
- package/dist/cjs/templates/state-shape.js +38 -0
- package/dist/cjs/types.js +2 -3
- package/dist/cjs/validation.js +9 -11
- package/dist/cjs/verify.js +9 -4
- package/dist/cjs/zk/commit.js +53 -0
- package/dist/cjs/zk/guard.js +107 -0
- package/dist/cjs/zk/index.js +48 -0
- package/dist/cjs/zk/preimage.js +37 -0
- package/dist/cjs/zk/prover.js +87 -0
- package/dist/cjs/zk/registry.js +62 -0
- package/dist/cjs/zk/types.js +28 -0
- package/dist/cjs/zk/witness.js +19 -0
- package/dist/esm/apps/compute/index.js +29 -0
- package/dist/esm/apps/compute/state-machines/compute-rule110.js +161 -0
- package/dist/esm/apps/compute/state-machines/index.js +5 -0
- package/dist/esm/apps/contracts/index.js +9 -5
- package/dist/esm/apps/contracts/state-machines/contract-agreement.js +135 -162
- package/dist/esm/apps/contracts/state-machines/contract-escrow.js +193 -171
- package/dist/esm/apps/contracts/state-machines/contract-universal.js +47 -59
- package/dist/esm/apps/corporate/index.js +2 -2
- package/dist/esm/apps/corporate/state-machines/corp-board.js +501 -457
- package/dist/esm/apps/corporate/state-machines/corp-entity.js +488 -362
- package/dist/esm/apps/corporate/state-machines/corp-securities.js +770 -577
- package/dist/esm/apps/corporate/state-machines/corp-shareholders.js +568 -558
- package/dist/esm/apps/governance/index.js +10 -10
- package/dist/esm/apps/governance/state-machines/dao-multisig.js +189 -210
- package/dist/esm/apps/governance/state-machines/dao-reputation.js +182 -229
- package/dist/esm/apps/governance/state-machines/dao-single.js +106 -89
- package/dist/esm/apps/governance/state-machines/dao-token.js +200 -228
- package/dist/esm/apps/governance/state-machines/governance-simple.js +232 -232
- package/dist/esm/apps/governance/state-machines/governance-universal.js +65 -65
- package/dist/esm/apps/identity/constants.js +52 -21
- package/dist/esm/apps/identity/index.js +14 -9
- package/dist/esm/apps/identity/state-machines/identity-agent.js +125 -159
- package/dist/esm/apps/identity/state-machines/identity-oracle.js +159 -174
- package/dist/esm/apps/identity/state-machines/identity-registry.js +259 -0
- package/dist/esm/apps/identity/state-machines/identity-universal.js +52 -58
- package/dist/esm/apps/identity/state-machines/index.js +1 -0
- package/dist/esm/apps/index.js +9 -5
- package/dist/esm/apps/lending/assets.js +231 -0
- package/dist/esm/apps/lending/credit-scoring.js +81 -0
- package/dist/esm/apps/lending/eligibility.js +99 -0
- package/dist/esm/apps/lending/index.js +69 -0
- package/dist/esm/apps/lending/state-machines/index.js +5 -0
- package/dist/esm/apps/lending/state-machines/lending-zk-loan.js +430 -0
- package/dist/esm/apps/markets/index.js +11 -7
- package/dist/esm/apps/markets/state-machines/market-auction.js +117 -135
- package/dist/esm/apps/markets/state-machines/market-crowdfund.js +132 -142
- package/dist/esm/apps/markets/state-machines/market-group-buy.js +164 -185
- package/dist/esm/apps/markets/state-machines/market-prediction.js +227 -234
- package/dist/esm/apps/markets/state-machines/market-universal.js +66 -81
- package/dist/esm/apps/oracles/index.js +3 -3
- package/dist/esm/apps/privacy/index.js +56 -0
- package/dist/esm/apps/privacy/state-machines/index.js +6 -0
- package/dist/esm/apps/privacy/state-machines/mixer-ddhRing.js +282 -0
- package/dist/esm/apps/privacy/state-machines/note-pool.js +470 -0
- package/dist/esm/apps/staked-pool/assets.js +91 -0
- package/dist/esm/apps/staked-pool/base.js +493 -0
- package/dist/esm/apps/staked-pool/consumer.js +49 -0
- package/dist/esm/apps/staked-pool/index.js +60 -0
- package/dist/esm/apps/staked-pool/state-machines/index.js +6 -0
- package/dist/esm/apps/staked-pool/state-machines/staked-pool-base.js +46 -0
- package/dist/esm/apps/staked-pool/state-machines/staked-pool-oracle.js +127 -0
- package/dist/esm/generated/google/protobuf/struct.js +1 -1
- package/dist/esm/generated/google/protobuf/timestamp.js +1 -1
- package/dist/esm/generated/index.js +9 -5
- package/dist/esm/generated/openapi.js +5 -0
- package/dist/esm/generated/ottochain/apps/contracts/v1/contract.js +47 -47
- package/dist/esm/generated/ottochain/apps/corporate/v1/corporate.js +1 -1
- package/dist/esm/generated/ottochain/apps/governance/v1/governance.js +1 -1
- package/dist/esm/generated/ottochain/apps/identity/v1/attestation.js +1 -1
- package/dist/esm/generated/ottochain/apps/identity/v1/identity.js +115 -121
- package/dist/esm/generated/ottochain/apps/markets/v1/market.js +101 -101
- package/dist/esm/generated/ottochain/v1/common.js +1 -1
- package/dist/esm/generated/ottochain/v1/fiber.js +40 -2
- package/dist/esm/generated/ottochain/v1/messages.js +1 -1
- package/dist/esm/generated/ottochain/v1/records.js +1 -1
- package/dist/esm/index.js +28 -3
- package/dist/esm/openapi.js +1 -0
- package/dist/esm/ottochain/genesis-manifest.js +15 -9
- package/dist/esm/ottochain/index.js +2 -3
- package/dist/esm/ottochain/metagraph-client.js +81 -16
- package/dist/esm/ottochain/snapshot.js +6 -8
- package/dist/esm/ottochain/transaction.js +51 -3
- package/dist/esm/ottochain/types.js +15 -1
- package/dist/esm/privacy/index.js +6 -0
- package/dist/esm/privacy/sealed-bid.js +209 -0
- package/dist/esm/privacy/shield-app.js +127 -0
- package/dist/esm/schema/effects.js +145 -0
- package/dist/esm/schema/fiber-app.js +139 -8
- package/dist/esm/schema/guard-lint.js +337 -0
- package/dist/esm/schema/guards.js +228 -0
- package/dist/esm/signing.js +74 -0
- package/dist/esm/templates/asset-policy.js +182 -0
- package/dist/esm/templates/index.js +41 -0
- package/dist/esm/templates/machine.js +125 -0
- package/dist/esm/templates/migration.js +34 -0
- package/dist/esm/templates/state-shape.js +34 -0
- package/dist/esm/validation.js +1 -3
- package/dist/esm/verify.js +8 -2
- package/dist/esm/zk/commit.js +44 -0
- package/dist/esm/zk/guard.js +99 -0
- package/dist/esm/zk/index.js +19 -0
- package/dist/esm/zk/preimage.js +30 -0
- package/dist/esm/zk/prover.js +82 -0
- package/dist/esm/zk/registry.js +55 -0
- package/dist/esm/zk/types.js +25 -0
- package/dist/esm/zk/witness.js +15 -0
- package/dist/types/apps/compute/index.d.ts +176 -0
- package/dist/types/apps/compute/state-machines/compute-rule110.d.ts +157 -0
- package/dist/types/apps/compute/state-machines/index.d.ts +5 -0
- package/dist/types/apps/contracts/index.d.ts +81 -221
- package/dist/types/apps/contracts/state-machines/contract-agreement.d.ts +23 -98
- package/dist/types/apps/contracts/state-machines/contract-escrow.d.ts +49 -115
- package/dist/types/apps/contracts/state-machines/contract-universal.d.ts +4 -4
- package/dist/types/apps/corporate/index.d.ts +1176 -440
- package/dist/types/apps/corporate/state-machines/corp-board.d.ts +271 -135
- package/dist/types/apps/corporate/state-machines/corp-entity.d.ts +279 -74
- package/dist/types/apps/corporate/state-machines/corp-securities.d.ts +373 -149
- package/dist/types/apps/corporate/state-machines/corp-shareholders.d.ts +252 -80
- package/dist/types/apps/governance/index.d.ts +368 -470
- package/dist/types/apps/governance/state-machines/dao-multisig.d.ts +92 -107
- package/dist/types/apps/governance/state-machines/dao-reputation.d.ts +61 -85
- package/dist/types/apps/governance/state-machines/dao-single.d.ts +25 -47
- package/dist/types/apps/governance/state-machines/dao-token.d.ts +79 -68
- package/dist/types/apps/governance/state-machines/governance-simple.d.ts +95 -125
- package/dist/types/apps/governance/state-machines/governance-universal.d.ts +6 -6
- package/dist/types/apps/identity/constants.d.ts +33 -5
- package/dist/types/apps/identity/index.d.ts +415 -131
- package/dist/types/apps/identity/state-machines/identity-agent.d.ts +23 -23
- package/dist/types/apps/identity/state-machines/identity-oracle.d.ts +27 -98
- package/dist/types/apps/identity/state-machines/identity-registry.d.ts +379 -0
- package/dist/types/apps/identity/state-machines/identity-universal.d.ts +4 -4
- package/dist/types/apps/identity/state-machines/index.d.ts +1 -0
- package/dist/types/apps/index.d.ts +9 -5
- package/dist/types/apps/lending/assets.d.ts +258 -0
- package/dist/types/apps/lending/credit-scoring.d.ts +80 -0
- package/dist/types/apps/lending/eligibility.d.ts +83 -0
- package/dist/types/apps/lending/index.d.ts +556 -0
- package/dist/types/apps/lending/state-machines/index.d.ts +5 -0
- package/dist/types/apps/lending/state-machines/lending-zk-loan.d.ts +536 -0
- package/dist/types/apps/markets/index.d.ts +181 -276
- package/dist/types/apps/markets/state-machines/market-auction.d.ts +25 -49
- package/dist/types/apps/markets/state-machines/market-crowdfund.d.ts +35 -53
- package/dist/types/apps/markets/state-machines/market-group-buy.d.ts +35 -61
- package/dist/types/apps/markets/state-machines/market-prediction.d.ts +65 -86
- package/dist/types/apps/markets/state-machines/market-universal.d.ts +12 -12
- package/dist/types/apps/oracles/index.d.ts +1 -1
- package/dist/types/apps/privacy/index.d.ts +328 -0
- package/dist/types/apps/privacy/state-machines/index.d.ts +6 -0
- package/dist/types/apps/privacy/state-machines/mixer-ddhRing.d.ts +337 -0
- package/dist/types/apps/privacy/state-machines/note-pool.d.ts +196 -0
- package/dist/types/apps/staked-pool/assets.d.ts +53 -0
- package/dist/types/apps/staked-pool/base.d.ts +80 -0
- package/dist/types/apps/staked-pool/consumer.d.ts +29 -0
- package/dist/types/apps/staked-pool/index.d.ts +51 -0
- package/dist/types/apps/staked-pool/state-machines/index.d.ts +6 -0
- package/dist/types/apps/staked-pool/state-machines/staked-pool-base.d.ts +8 -0
- package/dist/types/apps/staked-pool/state-machines/staked-pool-oracle.d.ts +34 -0
- package/dist/types/generated/index.d.ts +5 -5
- package/dist/types/generated/openapi.d.ts +1270 -0
- package/dist/types/generated/ottochain/apps/contracts/v1/contract.d.ts +5 -5
- package/dist/types/generated/ottochain/apps/identity/v1/identity.d.ts +12 -12
- package/dist/types/generated/ottochain/apps/markets/v1/market.d.ts +11 -11
- package/dist/types/generated/ottochain/v1/fiber.d.ts +7 -0
- package/dist/types/index.d.ts +7 -3
- package/dist/types/openapi.d.ts +24 -0
- package/dist/types/ottochain/genesis-manifest.d.ts +11 -5
- package/dist/types/ottochain/index.d.ts +5 -6
- package/dist/types/ottochain/metagraph-client.d.ts +49 -7
- package/dist/types/ottochain/snapshot.d.ts +6 -6
- package/dist/types/ottochain/transaction.d.ts +41 -1
- package/dist/types/ottochain/types.d.ts +336 -31
- package/dist/types/privacy/index.d.ts +6 -0
- package/dist/types/privacy/sealed-bid.d.ts +348 -0
- package/dist/types/privacy/shield-app.d.ts +48 -0
- package/dist/types/schema/effects.d.ts +141 -0
- package/dist/types/schema/fiber-app.d.ts +282 -2
- package/dist/types/schema/guard-lint.d.ts +111 -0
- package/dist/types/schema/guards.d.ts +146 -0
- package/dist/types/signing.d.ts +45 -0
- package/dist/types/templates/asset-policy.d.ts +119 -0
- package/dist/types/templates/index.d.ts +26 -0
- package/dist/types/templates/machine.d.ts +139 -0
- package/dist/types/templates/migration.d.ts +34 -0
- package/dist/types/templates/state-shape.d.ts +30 -0
- package/dist/types/validation.d.ts +22 -217
- package/dist/types/verify.d.ts +4 -0
- package/dist/types/zk/commit.d.ts +28 -0
- package/dist/types/zk/guard.d.ts +46 -0
- package/dist/types/zk/index.d.ts +19 -0
- package/dist/types/zk/preimage.d.ts +10 -0
- package/dist/types/zk/prover.d.ts +34 -0
- package/dist/types/zk/registry.d.ts +34 -0
- package/dist/types/zk/types.d.ts +33 -0
- package/dist/types/zk/witness.d.ts +40 -0
- package/package.json +47 -15
- package/dist/cjs/ottochain/normalize.js +0 -186
- package/dist/esm/ottochain/normalize.js +0 -179
- package/dist/types/ottochain/normalize.d.ts +0 -79
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asset-subsystem integration for the lending family.
|
|
3
|
+
*
|
|
4
|
+
* The loan's collateral, principal/debt, and repayment are ASSETS. This module provides
|
|
5
|
+
* typed payload builders for the OttoChain asset operations and loan-specific helpers that
|
|
6
|
+
* map the zk-loan lifecycle onto typed asset morphisms.
|
|
7
|
+
*
|
|
8
|
+
* Wire shapes mirror the asset-model proposal
|
|
9
|
+
* (`/home/euler/repos/ottochain/docs/proposals/asset-model.md` §7 — `CreateAssetPolicy`,
|
|
10
|
+
* `MintAsset`, `ApplyMorphism`, `AuthorizeCompose`; §8 — Governed/ZkVerify-gated morphisms)
|
|
11
|
+
* and follow the SDK's existing single-key-wrapper convention (the discriminator is the outer
|
|
12
|
+
* key, e.g. `{ MintAsset: {...} }`), matching `src/ottochain/transaction.ts`
|
|
13
|
+
* (`createTransitionPayload`, `createScriptPayload`, ...). The asset op-codes are not yet a
|
|
14
|
+
* merged TypeScript SDK surface; these builders let the lending app construct the proposed
|
|
15
|
+
* wire format today and sign it with the existing `signTransaction` path.
|
|
16
|
+
*
|
|
17
|
+
* Amounts are `Long` on-chain; modeled here as `number` for SDK ergonomics (callers may pass a
|
|
18
|
+
* string for values beyond 2^53 — the field is serialized verbatim).
|
|
19
|
+
*/
|
|
20
|
+
/** Helpers for the two-variant holder. */
|
|
21
|
+
export const walletHolder = (address) => ({ Wallet: { address } });
|
|
22
|
+
export const fiberHolder = (fiberId) => ({ Fiber: { fiberId } });
|
|
23
|
+
/** Pack a {@link TokenBehavior} to its 5-bit integer (T=16 S=8 C=4 E=2 G=1). */
|
|
24
|
+
export function behaviorBits(b) {
|
|
25
|
+
return ((b.transferable ? 16 : 0) |
|
|
26
|
+
(b.splittable ? 8 : 0) |
|
|
27
|
+
(b.combinable ? 4 : 0) |
|
|
28
|
+
(b.expirable ? 2 : 0) |
|
|
29
|
+
(b.governable ? 1 : 0));
|
|
30
|
+
}
|
|
31
|
+
/** Common behavior presets (asset-model.md §2). */
|
|
32
|
+
export const TokenBehaviors = {
|
|
33
|
+
/** Non-transferable, non-divisible (bits 0). */
|
|
34
|
+
Soulbound: {
|
|
35
|
+
transferable: false,
|
|
36
|
+
splittable: false,
|
|
37
|
+
combinable: false,
|
|
38
|
+
expirable: false,
|
|
39
|
+
governable: false,
|
|
40
|
+
},
|
|
41
|
+
/** Transferable only (bits 16). */
|
|
42
|
+
NFT: {
|
|
43
|
+
transferable: true,
|
|
44
|
+
splittable: false,
|
|
45
|
+
combinable: false,
|
|
46
|
+
expirable: false,
|
|
47
|
+
governable: false,
|
|
48
|
+
},
|
|
49
|
+
/** Transferable + splittable + combinable (bits 28 = TSC). */
|
|
50
|
+
Fungible: {
|
|
51
|
+
transferable: true,
|
|
52
|
+
splittable: true,
|
|
53
|
+
combinable: true,
|
|
54
|
+
expirable: false,
|
|
55
|
+
governable: false,
|
|
56
|
+
},
|
|
57
|
+
/** Fungible + governable (bits 29 = TSCG) — the default for a gated debt token. */
|
|
58
|
+
GovernedFungible: {
|
|
59
|
+
transferable: true,
|
|
60
|
+
splittable: true,
|
|
61
|
+
combinable: true,
|
|
62
|
+
expirable: false,
|
|
63
|
+
governable: true,
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
/** Publish an asset policy package version. asset-model.md §7. */
|
|
67
|
+
export function createAssetPolicyPayload(params) {
|
|
68
|
+
return {
|
|
69
|
+
CreateAssetPolicy: {
|
|
70
|
+
name: params.name,
|
|
71
|
+
version: params.version,
|
|
72
|
+
behavior: params.behavior,
|
|
73
|
+
supply: params.supply,
|
|
74
|
+
morphisms: params.morphisms,
|
|
75
|
+
stateShape: params.stateShape,
|
|
76
|
+
...(params.metadata ? { metadata: params.metadata } : {}),
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Mint an asset instance. asset-model.md §7. When the policy's `mintPolicy` is a
|
|
82
|
+
* `groth16_verify` guard (proof-gated mint), pass the eligibility `witness`.
|
|
83
|
+
*/
|
|
84
|
+
export function createMintAssetPayload(params) {
|
|
85
|
+
return {
|
|
86
|
+
MintAsset: {
|
|
87
|
+
assetId: params.assetId,
|
|
88
|
+
policyRef: params.policyRef,
|
|
89
|
+
holder: params.holder,
|
|
90
|
+
amount: params.amount,
|
|
91
|
+
...(params.expiresAt !== undefined ? { expiresAt: params.expiresAt } : {}),
|
|
92
|
+
...(params.witness ? { witness: params.witness } : {}),
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Apply a typed morphism (Transfer / Burn / Compose / ...). asset-model.md §7.
|
|
98
|
+
* Transfer = `{ kind: "Transfer", recipient }`; Burn (repay) = `{ kind: "Burn" }`.
|
|
99
|
+
*/
|
|
100
|
+
export function createApplyMorphismPayload(params) {
|
|
101
|
+
return {
|
|
102
|
+
ApplyMorphism: {
|
|
103
|
+
assetId: params.assetId,
|
|
104
|
+
kind: params.kind,
|
|
105
|
+
targetSequenceNumber: params.targetSequenceNumber,
|
|
106
|
+
...(params.recipient ? { recipient: params.recipient } : {}),
|
|
107
|
+
...(params.otherAssets ? { otherAssets: params.otherAssets } : {}),
|
|
108
|
+
...(params.compositeId ? { compositeId: params.compositeId } : {}),
|
|
109
|
+
...(params.shardIds ? { shardIds: params.shardIds } : {}),
|
|
110
|
+
...(params.nonce !== undefined ? { nonce: params.nonce } : {}),
|
|
111
|
+
...(params.witness ? { witness: params.witness } : {}),
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/** Commit half of a two-party compose. asset-model.md §7/§8. */
|
|
116
|
+
export function createAuthorizeComposePayload(params) {
|
|
117
|
+
return {
|
|
118
|
+
AuthorizeCompose: {
|
|
119
|
+
assetId: params.assetId,
|
|
120
|
+
partnerPolicy: params.partnerPolicy,
|
|
121
|
+
nonce: params.nonce,
|
|
122
|
+
expiresAt: params.expiresAt,
|
|
123
|
+
targetSequenceNumber: params.targetSequenceNumber,
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
// ---------------------------------------------------------------------------
|
|
128
|
+
// Loan-specific asset policy builders
|
|
129
|
+
// ---------------------------------------------------------------------------
|
|
130
|
+
/**
|
|
131
|
+
* The collateral vault policy: an NFT-like custodial holding (no fungible split) whose
|
|
132
|
+
* `Transfer` morphism is Governed — the loan/escrow fiber is the authorization. Locking is
|
|
133
|
+
* a custody Transfer into `AssetHolder.Fiber(escrow)`; release/liquidation is a Transfer out
|
|
134
|
+
* driven by the loan fiber's REPAID / LIQUIDATED transition (`_transferAsset`).
|
|
135
|
+
*/
|
|
136
|
+
export function collateralPolicy(name = 'collateral-vault-v1.asset', version = '1.0.0') {
|
|
137
|
+
return {
|
|
138
|
+
name,
|
|
139
|
+
version,
|
|
140
|
+
behavior: { transferable: true, splittable: false, combinable: false, expirable: false, governable: true },
|
|
141
|
+
supply: { maxSupply: null, mintPolicy: null, burnPolicy: null, decimals: 0 },
|
|
142
|
+
morphisms: {
|
|
143
|
+
Transfer: { visibility: 'Governed' },
|
|
144
|
+
Burn: { visibility: 'Disabled' },
|
|
145
|
+
Compose: { visibility: 'Disabled' },
|
|
146
|
+
},
|
|
147
|
+
stateShape: {},
|
|
148
|
+
metadata: { family: 'lending', role: 'collateral' },
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* The loan-debt / principal policy: a governed fungible whose `mintPolicy` is the
|
|
153
|
+
* proof-gated origination guard — the principal is mintable to the borrower only when the
|
|
154
|
+
* eligibility proof verifies. Repayment is a `Burn` governed by `burnPolicy`.
|
|
155
|
+
*
|
|
156
|
+
* @param mintGuard the origination guard (see `buildOriginationGuard`) — a `groth16_verify`
|
|
157
|
+
* expression bound to the pinned public lending rule.
|
|
158
|
+
*/
|
|
159
|
+
export function debtPolicy(mintGuard, name = 'loan-debt-v1.asset', version = '1.0.0') {
|
|
160
|
+
return {
|
|
161
|
+
name,
|
|
162
|
+
version,
|
|
163
|
+
behavior: TokenBehaviors.GovernedFungible,
|
|
164
|
+
supply: {
|
|
165
|
+
maxSupply: null,
|
|
166
|
+
// Proof-gated mint: principal is minted only if the eligibility proof verifies.
|
|
167
|
+
mintPolicy: mintGuard,
|
|
168
|
+
// Repayment burns the debt; only the holder (borrower) may burn theirs. The asset context has
|
|
169
|
+
// no `event` key — bind to the verified `signers` (chain-derived from the op's proofs).
|
|
170
|
+
burnPolicy: { in: [{ var: 'holder.Wallet.address' }, { var: 'signers' }] },
|
|
171
|
+
decimals: 2,
|
|
172
|
+
},
|
|
173
|
+
morphisms: {
|
|
174
|
+
Transfer: { visibility: 'Public' },
|
|
175
|
+
Burn: { visibility: 'Public' },
|
|
176
|
+
},
|
|
177
|
+
stateShape: {},
|
|
178
|
+
metadata: { family: 'lending', role: 'debt' },
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
// ---------------------------------------------------------------------------
|
|
182
|
+
// Loan lifecycle → asset morphism drivers
|
|
183
|
+
// ---------------------------------------------------------------------------
|
|
184
|
+
/**
|
|
185
|
+
* lock_collateral: custody Transfer of the pledged collateral into the loan escrow fiber.
|
|
186
|
+
* (asset-model.md §10 — locking is a custody transfer to `AssetHolder.Fiber`, there is no
|
|
187
|
+
* `Lock` morphism.)
|
|
188
|
+
*/
|
|
189
|
+
export function lockCollateralOp(args) {
|
|
190
|
+
return createApplyMorphismPayload({
|
|
191
|
+
assetId: args.collateralAssetId,
|
|
192
|
+
kind: 'Transfer',
|
|
193
|
+
recipient: fiberHolder(args.escrowFiberId),
|
|
194
|
+
targetSequenceNumber: args.targetSequenceNumber,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* originate: Mint the loan principal/debt to the borrower. The policy's `mintPolicy`
|
|
199
|
+
* (the origination guard) reads the eligibility `witness` ({publicValues, proof}).
|
|
200
|
+
*/
|
|
201
|
+
export function mintPrincipalOp(args) {
|
|
202
|
+
return createMintAssetPayload({
|
|
203
|
+
assetId: args.debtAssetId,
|
|
204
|
+
policyRef: args.debtPolicyRef,
|
|
205
|
+
holder: walletHolder(args.borrower),
|
|
206
|
+
amount: args.principalAmount,
|
|
207
|
+
witness: args.witness,
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
/** repay: Burn the borrower's debt token (the principal is repaid). */
|
|
211
|
+
export function repayBurnOp(args) {
|
|
212
|
+
return createApplyMorphismPayload({
|
|
213
|
+
assetId: args.debtAssetId,
|
|
214
|
+
kind: 'Burn',
|
|
215
|
+
targetSequenceNumber: args.targetSequenceNumber,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* release / liquidate: Transfer the escrowed collateral out of the escrow fiber to a
|
|
220
|
+
* recipient (the borrower on REPAID, the lender on LIQUIDATED). On-chain this is emitted by
|
|
221
|
+
* the loan fiber's transition via `_transferAsset`; this builder produces the equivalent
|
|
222
|
+
* explicit `ApplyMorphism(Transfer)` for off-fiber/manual settlement.
|
|
223
|
+
*/
|
|
224
|
+
export function settleCollateralOp(args) {
|
|
225
|
+
return createApplyMorphismPayload({
|
|
226
|
+
assetId: args.collateralAssetId,
|
|
227
|
+
kind: 'Transfer',
|
|
228
|
+
recipient: walletHolder(args.recipient),
|
|
229
|
+
targetSequenceNumber: args.targetSequenceNumber,
|
|
230
|
+
});
|
|
231
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credit scoring via the identity + reputation app.
|
|
3
|
+
*
|
|
4
|
+
* A zk-loan's `creditScore` is NOT a self-asserted number — it is the borrower's on-chain identity
|
|
5
|
+
* REPUTATION, derived from their {@link Attestation} deltas (the identity app's reputation model:
|
|
6
|
+
* `baseReputation + Σ delta`, floored at `minReputation`). This module is the wire between the two
|
|
7
|
+
* apps: it computes the reputation-backed score, pins a lending rule that BINDS the score to a
|
|
8
|
+
* specific borrower identity (so a borrower cannot prove eligibility against someone else's
|
|
9
|
+
* reputation), and assembles the PRIVATE data context the borrower proves it over.
|
|
10
|
+
*
|
|
11
|
+
* Privacy boundary: the exact `creditScore` and `collateralValue` stay private (their keccak is the
|
|
12
|
+
* proof's `dataHash`); the `subject` (borrower identity) and the bounds are PUBLIC (pinned in the
|
|
13
|
+
* rule's `logicHash`). The zk proof attests "borrower X's reputation-backed score ≥ floor and
|
|
14
|
+
* collateral coverage ≥ ratio" without revealing the score or the holdings.
|
|
15
|
+
*
|
|
16
|
+
* Trust model: the proof binds the score to the borrower's identity, but the borrower supplies the
|
|
17
|
+
* score value. When reputation attestations are PUBLIC on-chain, a verifier can independently
|
|
18
|
+
* recompute the score and check the proof used it; when reputation is PRIVATE (off-chain / held
|
|
19
|
+
* credentials) the score is genuinely hidden. To make the score AUTHORITY-attested in zero knowledge
|
|
20
|
+
* (the strongest form), have the SP1 rule additionally `schnorr_verify` the reputation issuer's
|
|
21
|
+
* signature over `(subject, score)` — see {@link reputationAuthorityClause}.
|
|
22
|
+
*/
|
|
23
|
+
import { DEFAULT_REPUTATION_CONFIG } from '../identity/index.js';
|
|
24
|
+
import { lendingRule } from './eligibility.js';
|
|
25
|
+
/**
|
|
26
|
+
* Derive an agent's credit score from their identity reputation attestations:
|
|
27
|
+
* `baseReputation + Σ attestation.delta`, floored at `minReputation`. This IS the integration point —
|
|
28
|
+
* a zk-loan's creditScore is the borrower's identity reputation, not an independent number.
|
|
29
|
+
*/
|
|
30
|
+
export function reputationScore(attestations, config = DEFAULT_REPUTATION_CONFIG) {
|
|
31
|
+
const raw = attestations.reduce((sum, a) => sum + (a.delta ?? 0), config.baseReputation);
|
|
32
|
+
return Math.max(config.minReputation, raw);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The PUBLIC reputation-credit lending rule. Extends {@link lendingRule} (collateral coverage +
|
|
36
|
+
* optional credit-score floor) with a SUBJECT binding `subject === borrowerId`, so the proven score
|
|
37
|
+
* belongs to a specific identity — a borrower cannot prove eligibility against another agent's
|
|
38
|
+
* reputation. `borrowerId` and all bounds are literals, so pinning the rule pins them.
|
|
39
|
+
*/
|
|
40
|
+
export function reputationCreditRule(params) {
|
|
41
|
+
const base = lendingRule(params); // coverage, or {and:[coverage, creditScore floor]}
|
|
42
|
+
const subjectBound = { '===': [{ var: 'subject' }, params.borrowerId] };
|
|
43
|
+
const clauses = 'and' in base ? base.and : [base];
|
|
44
|
+
return { and: [...clauses, subjectBound] };
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Assemble the PRIVATE data context the borrower feeds to the zk-jlvm prover: the `creditScore` is
|
|
48
|
+
* their identity {@link reputationScore}, the `subject` is their identity. Only its keccak (`dataHash`)
|
|
49
|
+
* becomes public.
|
|
50
|
+
*/
|
|
51
|
+
export function buildCreditDataContext(args) {
|
|
52
|
+
return {
|
|
53
|
+
collateralValue: args.collateralValue,
|
|
54
|
+
creditScore: reputationScore(args.attestations, args.config ?? DEFAULT_REPUTATION_CONFIG),
|
|
55
|
+
subject: args.borrowerId,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* OPTIONAL hardening — an authority-attested credit clause. ANDed into a rule, it makes the SP1 guest
|
|
60
|
+
* verify (in zero knowledge) the reputation issuer's Schnorr signature over the score, so the score is
|
|
61
|
+
* not merely borrower-supplied but ATTESTED.
|
|
62
|
+
*
|
|
63
|
+
* SECURITY: the authority's `authorityPubKey` MUST be a LITERAL pinned in the rule (it is part of the
|
|
64
|
+
* rule's keccak `logicHash`, so pinning it binds it) — NEVER read from the borrower's witness/private
|
|
65
|
+
* data, or the borrower could supply their own keypair and self-attest any score. Only the signature
|
|
66
|
+
* `repSig` and the signed `scoreCommit` ride on the (private) witness; the signature binds them to the
|
|
67
|
+
* pinned key. `scoreCommit` should commit the pinned `subject` + the proof's `dataHash` so a signature
|
|
68
|
+
* cannot be replayed for a different borrower/score.
|
|
69
|
+
*
|
|
70
|
+
* NOTE: producing a real signature + proof is required to exercise this end-to-end; the builder pins
|
|
71
|
+
* the structure so the on-chain rule and the prover agree. See the JLVM `schnorr_verify` opcode.
|
|
72
|
+
*/
|
|
73
|
+
export function reputationAuthorityClause(authorityPubKey) {
|
|
74
|
+
return {
|
|
75
|
+
schnorr_verify: [
|
|
76
|
+
authorityPubKey, // the reputation authority's public key — PINNED literal, not witness-supplied
|
|
77
|
+
{ var: 'scoreCommit' }, // the signed message: a commitment over (subject, creditScore)
|
|
78
|
+
{ var: 'repSig' }, // the authority's signature over scoreCommit
|
|
79
|
+
],
|
|
80
|
+
};
|
|
81
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The eligibility-proof model for the zk-loan: pin a PUBLIC lending rule, build the
|
|
3
|
+
* semi-private origination guard that gates it, and construct the witness the guard reads.
|
|
4
|
+
*
|
|
5
|
+
* The borrower proves in zero-knowledge that their PRIVATE financials satisfy the PUBLIC
|
|
6
|
+
* lending rule — without revealing them. The rule (with its literal bounds) is canonicalized
|
|
7
|
+
* and keccak-hashed into a `logicHash`; the proof commits that same `exprHash`, so binding
|
|
8
|
+
* `exprHash == logicHash` pins exactly WHICH rule was proven. See `src/zk` and
|
|
9
|
+
* `/home/euler/repos/ottochain/docs/proposals/asset-model.md` §8 (ZkVerify-gated morphisms).
|
|
10
|
+
*/
|
|
11
|
+
import { exprHash, KECCAK_TRUE } from '../../zk/index.js';
|
|
12
|
+
/**
|
|
13
|
+
* The PUBLIC lending rule, as a JSON-Logic predicate over the borrower's PRIVATE data context
|
|
14
|
+
* `{ collateralValue, creditScore }`. Evaluates to `true` iff the borrower is eligible:
|
|
15
|
+
*
|
|
16
|
+
* collateralValue * 100 >= loanAmount * collateralRatioPct (collateral coverage)
|
|
17
|
+
* AND creditScore >= minCreditScore (if a floor is set)
|
|
18
|
+
*
|
|
19
|
+
* Only the predicate and its literal bounds are public; the data it is evaluated over
|
|
20
|
+
* (`collateralValue`, `creditScore`) is the prover's private witness — its keccak is the
|
|
21
|
+
* proof's `dataHash`, never revealed. This is the rule the zk-jlvm guest runs; its `exprHash`
|
|
22
|
+
* is pinned as the loan's `lendingRuleLogicHash`.
|
|
23
|
+
*/
|
|
24
|
+
export function lendingRule(params) {
|
|
25
|
+
const coverage = {
|
|
26
|
+
'>=': [{ '*': [{ var: 'collateralValue' }, 100] }, params.loanAmount * params.collateralRatioPct],
|
|
27
|
+
};
|
|
28
|
+
if (params.minCreditScore === undefined) {
|
|
29
|
+
return coverage;
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
and: [coverage, { '>=': [{ var: 'creditScore' }, params.minCreditScore] }],
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Pin a lending rule: produce the public rule plus the three constants the loan's origination
|
|
37
|
+
* guard binds against. `vkey` is the verifying key of the SP1 zk-jlvm program that runs the
|
|
38
|
+
* rule (supplied by the lender / deployment).
|
|
39
|
+
*/
|
|
40
|
+
export function pinLendingRule(params, vkey) {
|
|
41
|
+
const rule = lendingRule(params);
|
|
42
|
+
return {
|
|
43
|
+
rule,
|
|
44
|
+
logicHash: exprHash(rule),
|
|
45
|
+
keccakTrue: KECCAK_TRUE,
|
|
46
|
+
vkey,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Build the semi-private ORIGINATION guard expression.
|
|
51
|
+
*
|
|
52
|
+
* It verifies the SP1-Groth16 eligibility proof AND binds its committed public values to the
|
|
53
|
+
* pinned public rule. `publicValues = abi_encode(JlvmPublicValues{exprHash|dataHash|outputHash|ok})`
|
|
54
|
+
* is opaque to `groth16_verify`; the guard slices the `0x`-hex form with native JLVM `substr`
|
|
55
|
+
* (start, len) and re-`cat`s the `0x` prefix — there is no `jlvm_pv_decode` opcode. Clauses:
|
|
56
|
+
*
|
|
57
|
+
* 1. `groth16_verify(vkey, witness.publicValues, witness.proof)` — the proof is valid
|
|
58
|
+
* 2. `exprHash == logicHash` (word 0, hex chars [2,66)) — it proved THE pinned rule
|
|
59
|
+
* 3. `outputHash == keccakTrue` (word 2, hex chars [130,194)) — the rule evaluated to true
|
|
60
|
+
* 4. `ok == "01"` (word 3 final pair, [256,258)) — the JLVM run did not error
|
|
61
|
+
*
|
|
62
|
+
* This is the closed boolean an asset `mintPolicy` or a fiber-transition guard wraps. The
|
|
63
|
+
* lending state machine ANDs clause 0 (`agent == lender`) in front of it; the debt asset
|
|
64
|
+
* policy uses it directly as the proof-gated `mintPolicy`.
|
|
65
|
+
*/
|
|
66
|
+
export function buildOriginationGuard(refs = {}) {
|
|
67
|
+
const vkeyVar = refs.vkeyVar ?? 'state.lendingRuleVKey';
|
|
68
|
+
const logicHashVar = refs.logicHashVar ?? 'state.lendingRuleLogicHash';
|
|
69
|
+
const keccakTrueVar = refs.keccakTrueVar ?? 'state.keccakTrue';
|
|
70
|
+
return {
|
|
71
|
+
and: [
|
|
72
|
+
{
|
|
73
|
+
groth16_verify: [{ var: vkeyVar }, { var: 'witness.publicValues' }, { var: 'witness.proof' }],
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
'===': [{ cat: ['0x', { substr: [{ var: 'witness.publicValues' }, 2, 64] }] }, { var: logicHashVar }],
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
'===': [{ cat: ['0x', { substr: [{ var: 'witness.publicValues' }, 130, 64] }] }, { var: keccakTrueVar }],
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
'===': [{ substr: [{ var: 'witness.publicValues' }, 256, 2] }, '01'],
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Construct the eligibility-proof witness the origination guard reads. The `{publicValues,
|
|
89
|
+
* proof}` come from the SP1 zk-jlvm prover (`--mode groth16`) run over the public rule and the
|
|
90
|
+
* borrower's PRIVATE data context. Both are lowercase `0x`-hex; they are exposed to the guard
|
|
91
|
+
* under the reserved `witness` key (on the loan `originate` event payload, or on a proof-gated
|
|
92
|
+
* `MintAsset`).
|
|
93
|
+
*/
|
|
94
|
+
export function buildEligibilityWitness(bundle) {
|
|
95
|
+
return {
|
|
96
|
+
publicValues: bundle.publicValues,
|
|
97
|
+
proof: bundle.proof,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lending Application — privacy-preserving credit & lending on OttoChain.
|
|
3
|
+
*
|
|
4
|
+
* The lending family hosts private-finance fibers whose financial state stays private while
|
|
5
|
+
* eligibility is proven in zero-knowledge. The collateral, principal, and repayment are
|
|
6
|
+
* asset-subsystem tokens driven by the fiber lifecycle.
|
|
7
|
+
*
|
|
8
|
+
* Variants:
|
|
9
|
+
* - `zkLoan` — a collateralized loan whose origination is gated by a zk eligibility proof
|
|
10
|
+
* (collateral coverage / credit-score floor) without revealing the borrower's financials.
|
|
11
|
+
*
|
|
12
|
+
* The name `lending` (vs. `loans`) deliberately generalizes for the future credit family —
|
|
13
|
+
* credit lines, BNPL, bonds, escrowed credit — mirroring how `markets` hosts prediction /
|
|
14
|
+
* auction / crowdfund variants under one app.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import {
|
|
19
|
+
* getLendingDefinition,
|
|
20
|
+
* pinLendingRule,
|
|
21
|
+
* buildOriginationGuard,
|
|
22
|
+
* buildEligibilityWitness,
|
|
23
|
+
* debtPolicy,
|
|
24
|
+
* collateralPolicy,
|
|
25
|
+
* } from '@ottochain/sdk/apps/lending';
|
|
26
|
+
*
|
|
27
|
+
* const loanDef = getLendingDefinition('zkLoan');
|
|
28
|
+
*
|
|
29
|
+
* // Pin the public rule + build the proof-gated origination guard.
|
|
30
|
+
* const pinned = pinLendingRule({ collateralRatioPct: 150, loanAmount: 1000, minCreditScore: 680 }, vkey);
|
|
31
|
+
* const guard = buildOriginationGuard();
|
|
32
|
+
* const debt = debtPolicy(guard);
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @packageDocumentation
|
|
36
|
+
*/
|
|
37
|
+
import { lendingZkLoanDef } from './state-machines/index.js';
|
|
38
|
+
export { lendingZkLoanDef };
|
|
39
|
+
/** All lending state machine definitions. */
|
|
40
|
+
export const LENDING_DEFINITIONS = {
|
|
41
|
+
zkLoan: lendingZkLoanDef,
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Get a lending state machine definition by type.
|
|
45
|
+
* @param type - 'zkLoan' (default: 'zkLoan')
|
|
46
|
+
*/
|
|
47
|
+
export function getLendingDefinition(type = 'zkLoan') {
|
|
48
|
+
return LENDING_DEFINITIONS[type];
|
|
49
|
+
}
|
|
50
|
+
// ---------------------------------------------------------------------------
|
|
51
|
+
// Eligibility-proof model (the semi-private gate)
|
|
52
|
+
// ---------------------------------------------------------------------------
|
|
53
|
+
export { lendingRule, pinLendingRule, buildOriginationGuard, buildEligibilityWitness, } from './eligibility.js';
|
|
54
|
+
// ---------------------------------------------------------------------------
|
|
55
|
+
// Credit scoring via the identity + reputation app (the creditScore IS reputation)
|
|
56
|
+
// ---------------------------------------------------------------------------
|
|
57
|
+
export { reputationScore, reputationCreditRule, buildCreditDataContext, reputationAuthorityClause, } from './credit-scoring.js';
|
|
58
|
+
// ---------------------------------------------------------------------------
|
|
59
|
+
// Asset-subsystem integration (collateral, debt/principal, repayment morphisms)
|
|
60
|
+
// ---------------------------------------------------------------------------
|
|
61
|
+
export {
|
|
62
|
+
// value types
|
|
63
|
+
walletHolder, fiberHolder, behaviorBits, TokenBehaviors,
|
|
64
|
+
// op payload builders
|
|
65
|
+
createAssetPolicyPayload, createMintAssetPayload, createApplyMorphismPayload, createAuthorizeComposePayload,
|
|
66
|
+
// loan policy builders
|
|
67
|
+
collateralPolicy, debtPolicy,
|
|
68
|
+
// lifecycle → morphism drivers
|
|
69
|
+
lockCollateralOp, mintPrincipalOp, repayBurnOp, settleCollateralOp, } from './assets.js';
|