@ottochain/sdk 2.3.0 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (209) hide show
  1. package/dist/cjs/apps/contracts/index.js +15 -8
  2. package/dist/cjs/apps/contracts/state-machines/contract-agreement.js +35 -40
  3. package/dist/cjs/apps/contracts/state-machines/contract-escrow.js +80 -37
  4. package/dist/cjs/apps/contracts/state-machines/contract-universal.js +4 -4
  5. package/dist/cjs/apps/corporate/index.js +2 -2
  6. package/dist/cjs/apps/corporate/state-machines/corp-board.js +169 -59
  7. package/dist/cjs/apps/corporate/state-machines/corp-entity.js +245 -47
  8. package/dist/cjs/apps/corporate/state-machines/corp-securities.js +407 -99
  9. package/dist/cjs/apps/corporate/state-machines/corp-shareholders.js +151 -37
  10. package/dist/cjs/apps/governance/index.js +14 -14
  11. package/dist/cjs/apps/governance/state-machines/dao-multisig.js +58 -40
  12. package/dist/cjs/apps/governance/state-machines/dao-reputation.js +46 -40
  13. package/dist/cjs/apps/governance/state-machines/dao-single.js +28 -11
  14. package/dist/cjs/apps/governance/state-machines/dao-token.js +67 -41
  15. package/dist/cjs/apps/governance/state-machines/governance-simple.js +93 -61
  16. package/dist/cjs/apps/governance/state-machines/governance-universal.js +2 -2
  17. package/dist/cjs/apps/identity/constants.js +55 -14
  18. package/dist/cjs/apps/identity/index.js +27 -11
  19. package/dist/cjs/apps/identity/state-machines/identity-agent.js +3 -3
  20. package/dist/cjs/apps/identity/state-machines/identity-oracle.js +25 -22
  21. package/dist/cjs/apps/identity/state-machines/identity-registry.js +288 -0
  22. package/dist/cjs/apps/identity/state-machines/identity-universal.js +3 -3
  23. package/dist/cjs/apps/identity/state-machines/index.js +3 -1
  24. package/dist/cjs/apps/index.js +19 -8
  25. package/dist/cjs/apps/lending/assets.js +223 -0
  26. package/dist/cjs/apps/lending/credit-scoring.js +87 -0
  27. package/dist/cjs/apps/lending/eligibility.js +121 -0
  28. package/dist/cjs/apps/lending/index.js +91 -0
  29. package/dist/cjs/apps/lending/state-machines/index.js +9 -0
  30. package/dist/cjs/apps/lending/state-machines/lending-zk-loan.js +412 -0
  31. package/dist/cjs/apps/markets/index.js +21 -11
  32. package/dist/cjs/apps/markets/state-machines/market-auction.js +14 -13
  33. package/dist/cjs/apps/markets/state-machines/market-crowdfund.js +29 -24
  34. package/dist/cjs/apps/markets/state-machines/market-group-buy.js +24 -26
  35. package/dist/cjs/apps/markets/state-machines/market-prediction.js +80 -53
  36. package/dist/cjs/apps/markets/state-machines/market-universal.js +5 -5
  37. package/dist/cjs/apps/oracles/index.js +2 -2
  38. package/dist/cjs/errors.js +3 -3
  39. package/dist/cjs/generated/google/protobuf/struct.js +4 -4
  40. package/dist/cjs/generated/index.js +11 -7
  41. package/dist/cjs/generated/openapi.js +6 -0
  42. package/dist/cjs/generated/ottochain/apps/contracts/v1/contract.js +50 -50
  43. package/dist/cjs/generated/ottochain/apps/corporate/v1/corporate.js +19 -20
  44. package/dist/cjs/generated/ottochain/apps/governance/v1/governance.js +13 -13
  45. package/dist/cjs/generated/ottochain/apps/identity/v1/attestation.js +4 -4
  46. package/dist/cjs/generated/ottochain/apps/identity/v1/identity.js +124 -130
  47. package/dist/cjs/generated/ottochain/apps/markets/v1/market.js +107 -107
  48. package/dist/cjs/generated/ottochain/v1/common.js +4 -4
  49. package/dist/cjs/generated/ottochain/v1/fiber.js +4 -4
  50. package/dist/cjs/index.js +41 -7
  51. package/dist/cjs/openapi.js +2 -0
  52. package/dist/cjs/ottochain/drop-nulls.js +1 -2
  53. package/dist/cjs/ottochain/genesis-manifest.js +11 -11
  54. package/dist/cjs/ottochain/index.js +23 -13
  55. package/dist/cjs/ottochain/metagraph-client.js +65 -8
  56. package/dist/cjs/ottochain/snapshot.js +11 -12
  57. package/dist/cjs/ottochain/transaction.js +57 -14
  58. package/dist/cjs/ottochain/types.js +16 -2
  59. package/dist/cjs/privacy/index.js +14 -0
  60. package/dist/cjs/privacy/sealed-bid.js +210 -0
  61. package/dist/cjs/privacy/shield-app.js +131 -0
  62. package/dist/cjs/schema/effects.js +40 -0
  63. package/dist/cjs/schema/fiber-app.js +19 -13
  64. package/dist/cjs/schema/guard-lint.js +352 -0
  65. package/dist/cjs/schema/guards.js +246 -0
  66. package/dist/cjs/signing.js +80 -0
  67. package/dist/cjs/types.js +2 -3
  68. package/dist/cjs/validation.js +8 -8
  69. package/dist/cjs/verify.js +9 -4
  70. package/dist/cjs/zk/commit.js +53 -0
  71. package/dist/cjs/zk/guard.js +107 -0
  72. package/dist/cjs/zk/index.js +48 -0
  73. package/dist/cjs/zk/preimage.js +37 -0
  74. package/dist/cjs/zk/prover.js +87 -0
  75. package/dist/cjs/zk/registry.js +62 -0
  76. package/dist/cjs/zk/types.js +28 -0
  77. package/dist/cjs/zk/witness.js +19 -0
  78. package/dist/esm/apps/contracts/index.js +7 -3
  79. package/dist/esm/apps/contracts/state-machines/contract-agreement.js +35 -40
  80. package/dist/esm/apps/contracts/state-machines/contract-escrow.js +80 -37
  81. package/dist/esm/apps/contracts/state-machines/contract-universal.js +4 -4
  82. package/dist/esm/apps/corporate/state-machines/corp-board.js +169 -59
  83. package/dist/esm/apps/corporate/state-machines/corp-entity.js +245 -47
  84. package/dist/esm/apps/corporate/state-machines/corp-securities.js +407 -99
  85. package/dist/esm/apps/corporate/state-machines/corp-shareholders.js +151 -37
  86. package/dist/esm/apps/governance/state-machines/dao-multisig.js +58 -40
  87. package/dist/esm/apps/governance/state-machines/dao-reputation.js +46 -40
  88. package/dist/esm/apps/governance/state-machines/dao-single.js +28 -11
  89. package/dist/esm/apps/governance/state-machines/dao-token.js +67 -41
  90. package/dist/esm/apps/governance/state-machines/governance-simple.js +93 -61
  91. package/dist/esm/apps/governance/state-machines/governance-universal.js +2 -2
  92. package/dist/esm/apps/identity/constants.js +51 -12
  93. package/dist/esm/apps/identity/index.js +12 -7
  94. package/dist/esm/apps/identity/state-machines/identity-agent.js +3 -3
  95. package/dist/esm/apps/identity/state-machines/identity-oracle.js +25 -22
  96. package/dist/esm/apps/identity/state-machines/identity-registry.js +285 -0
  97. package/dist/esm/apps/identity/state-machines/identity-universal.js +3 -3
  98. package/dist/esm/apps/identity/state-machines/index.js +1 -0
  99. package/dist/esm/apps/index.js +1 -0
  100. package/dist/esm/apps/lending/assets.js +207 -0
  101. package/dist/esm/apps/lending/credit-scoring.js +81 -0
  102. package/dist/esm/apps/lending/eligibility.js +115 -0
  103. package/dist/esm/apps/lending/index.js +69 -0
  104. package/dist/esm/apps/lending/state-machines/index.js +5 -0
  105. package/dist/esm/apps/lending/state-machines/lending-zk-loan.js +409 -0
  106. package/dist/esm/apps/markets/index.js +8 -4
  107. package/dist/esm/apps/markets/state-machines/market-auction.js +14 -13
  108. package/dist/esm/apps/markets/state-machines/market-crowdfund.js +29 -24
  109. package/dist/esm/apps/markets/state-machines/market-group-buy.js +24 -26
  110. package/dist/esm/apps/markets/state-machines/market-prediction.js +80 -53
  111. package/dist/esm/apps/markets/state-machines/market-universal.js +5 -5
  112. package/dist/esm/generated/index.js +9 -5
  113. package/dist/esm/generated/openapi.js +5 -0
  114. package/dist/esm/generated/ottochain/apps/contracts/v1/contract.js +46 -46
  115. package/dist/esm/generated/ottochain/apps/identity/v1/identity.js +114 -120
  116. package/dist/esm/generated/ottochain/apps/markets/v1/market.js +100 -100
  117. package/dist/esm/index.js +21 -2
  118. package/dist/esm/openapi.js +1 -0
  119. package/dist/esm/ottochain/genesis-manifest.js +9 -9
  120. package/dist/esm/ottochain/index.js +2 -3
  121. package/dist/esm/ottochain/metagraph-client.js +65 -8
  122. package/dist/esm/ottochain/snapshot.js +4 -4
  123. package/dist/esm/ottochain/transaction.js +43 -3
  124. package/dist/esm/ottochain/types.js +15 -1
  125. package/dist/esm/privacy/index.js +6 -0
  126. package/dist/esm/privacy/sealed-bid.js +206 -0
  127. package/dist/esm/privacy/shield-app.js +127 -0
  128. package/dist/esm/schema/effects.js +35 -0
  129. package/dist/esm/schema/fiber-app.js +13 -6
  130. package/dist/esm/schema/guard-lint.js +346 -0
  131. package/dist/esm/schema/guards.js +229 -0
  132. package/dist/esm/signing.js +74 -0
  133. package/dist/esm/verify.js +8 -2
  134. package/dist/esm/zk/commit.js +44 -0
  135. package/dist/esm/zk/guard.js +99 -0
  136. package/dist/esm/zk/index.js +19 -0
  137. package/dist/esm/zk/preimage.js +30 -0
  138. package/dist/esm/zk/prover.js +82 -0
  139. package/dist/esm/zk/registry.js +55 -0
  140. package/dist/esm/zk/types.js +25 -0
  141. package/dist/esm/zk/witness.js +15 -0
  142. package/dist/types/apps/contracts/index.d.ts +69 -209
  143. package/dist/types/apps/contracts/state-machines/contract-agreement.d.ts +20 -95
  144. package/dist/types/apps/contracts/state-machines/contract-escrow.d.ts +46 -112
  145. package/dist/types/apps/corporate/index.d.ts +1040 -304
  146. package/dist/types/apps/corporate/state-machines/corp-board.d.ts +188 -52
  147. package/dist/types/apps/corporate/state-machines/corp-entity.d.ts +267 -62
  148. package/dist/types/apps/corporate/state-machines/corp-securities.d.ts +355 -131
  149. package/dist/types/apps/corporate/state-machines/corp-shareholders.d.ts +225 -53
  150. package/dist/types/apps/governance/index.d.ts +296 -398
  151. package/dist/types/apps/governance/state-machines/dao-multisig.d.ts +77 -92
  152. package/dist/types/apps/governance/state-machines/dao-reputation.d.ts +42 -66
  153. package/dist/types/apps/governance/state-machines/dao-single.d.ts +25 -47
  154. package/dist/types/apps/governance/state-machines/dao-token.d.ts +60 -49
  155. package/dist/types/apps/governance/state-machines/governance-simple.d.ts +87 -117
  156. package/dist/types/apps/governance/state-machines/governance-universal.d.ts +2 -2
  157. package/dist/types/apps/identity/constants.d.ts +32 -4
  158. package/dist/types/apps/identity/index.d.ts +378 -94
  159. package/dist/types/apps/identity/state-machines/identity-oracle.d.ts +16 -87
  160. package/dist/types/apps/identity/state-machines/identity-registry.d.ts +379 -0
  161. package/dist/types/apps/identity/state-machines/index.d.ts +1 -0
  162. package/dist/types/apps/index.d.ts +1 -0
  163. package/dist/types/apps/lending/assets.d.ts +258 -0
  164. package/dist/types/apps/lending/credit-scoring.d.ts +80 -0
  165. package/dist/types/apps/lending/eligibility.d.ts +83 -0
  166. package/dist/types/apps/lending/index.d.ts +548 -0
  167. package/dist/types/apps/lending/state-machines/index.d.ts +5 -0
  168. package/dist/types/apps/lending/state-machines/lending-zk-loan.d.ts +528 -0
  169. package/dist/types/apps/markets/index.d.ts +108 -203
  170. package/dist/types/apps/markets/state-machines/market-auction.d.ts +13 -37
  171. package/dist/types/apps/markets/state-machines/market-crowdfund.d.ts +16 -34
  172. package/dist/types/apps/markets/state-machines/market-group-buy.d.ts +17 -43
  173. package/dist/types/apps/markets/state-machines/market-prediction.d.ts +51 -72
  174. package/dist/types/apps/markets/state-machines/market-universal.d.ts +5 -5
  175. package/dist/types/generated/index.d.ts +5 -5
  176. package/dist/types/generated/openapi.d.ts +1257 -0
  177. package/dist/types/generated/ottochain/apps/contracts/v1/contract.d.ts +5 -5
  178. package/dist/types/generated/ottochain/apps/identity/v1/identity.d.ts +12 -12
  179. package/dist/types/generated/ottochain/apps/markets/v1/market.d.ts +11 -11
  180. package/dist/types/index.d.ts +6 -2
  181. package/dist/types/openapi.d.ts +22 -0
  182. package/dist/types/ottochain/genesis-manifest.d.ts +5 -5
  183. package/dist/types/ottochain/index.d.ts +5 -6
  184. package/dist/types/ottochain/metagraph-client.d.ts +49 -7
  185. package/dist/types/ottochain/snapshot.d.ts +6 -6
  186. package/dist/types/ottochain/transaction.d.ts +33 -1
  187. package/dist/types/ottochain/types.d.ts +335 -30
  188. package/dist/types/privacy/index.d.ts +6 -0
  189. package/dist/types/privacy/sealed-bid.d.ts +348 -0
  190. package/dist/types/privacy/shield-app.d.ts +48 -0
  191. package/dist/types/schema/effects.d.ts +34 -0
  192. package/dist/types/schema/fiber-app.d.ts +1 -2
  193. package/dist/types/schema/guard-lint.d.ts +111 -0
  194. package/dist/types/schema/guards.d.ts +134 -0
  195. package/dist/types/signing.d.ts +45 -0
  196. package/dist/types/validation.d.ts +22 -217
  197. package/dist/types/verify.d.ts +4 -0
  198. package/dist/types/zk/commit.d.ts +28 -0
  199. package/dist/types/zk/guard.d.ts +46 -0
  200. package/dist/types/zk/index.d.ts +19 -0
  201. package/dist/types/zk/preimage.d.ts +10 -0
  202. package/dist/types/zk/prover.d.ts +34 -0
  203. package/dist/types/zk/registry.d.ts +34 -0
  204. package/dist/types/zk/types.d.ts +33 -0
  205. package/dist/types/zk/witness.d.ts +40 -0
  206. package/package.json +27 -13
  207. package/dist/cjs/ottochain/normalize.js +0 -186
  208. package/dist/esm/ottochain/normalize.js +0 -179
  209. package/dist/types/ottochain/normalize.d.ts +0 -79
@@ -0,0 +1,258 @@
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
+ /** A holder of an asset: a wallet address, or a custody fiber (the escrow). */
21
+ export type AssetHolder = {
22
+ Wallet: {
23
+ address: string;
24
+ };
25
+ } | {
26
+ Fiber: {
27
+ fiberId: string;
28
+ };
29
+ };
30
+ /** Helpers for the two-variant holder. */
31
+ export declare const walletHolder: (address: string) => AssetHolder;
32
+ export declare const fiberHolder: (fiberId: string) => AssetHolder;
33
+ /** 5-bit token behavior lattice (T/S/C ascending, E/G descending). asset-model.md §2. */
34
+ export interface TokenBehavior {
35
+ transferable: boolean;
36
+ splittable: boolean;
37
+ combinable: boolean;
38
+ expirable: boolean;
39
+ governable: boolean;
40
+ }
41
+ /** Pack a {@link TokenBehavior} to its 5-bit integer (T=16 S=8 C=4 E=2 G=1). */
42
+ export declare function behaviorBits(b: TokenBehavior): number;
43
+ /** Common behavior presets (asset-model.md §2). */
44
+ export declare const TokenBehaviors: {
45
+ /** Non-transferable, non-divisible (bits 0). */
46
+ readonly Soulbound: TokenBehavior;
47
+ /** Transferable only (bits 16). */
48
+ readonly NFT: TokenBehavior;
49
+ /** Transferable + splittable + combinable (bits 28 = TSC). */
50
+ readonly Fungible: TokenBehavior;
51
+ /** Fungible + governable (bits 29 = TSCG) — the default for a gated debt token. */
52
+ readonly GovernedFungible: TokenBehavior;
53
+ };
54
+ /** A JSON-Logic expression (guard/policy). */
55
+ export type JsonLogicRule = Record<string, unknown>;
56
+ /** Supply policy: cap, mint/burn JSON-Logic guards, decimals. asset-model.md §3. */
57
+ export interface SupplyPolicy {
58
+ /** Hard cap; null = uncapped. */
59
+ maxSupply?: number | string | null;
60
+ /** Mint guard (JSON-Logic); null = minting closed after genesis. */
61
+ mintPolicy?: JsonLogicRule | null;
62
+ /** Burn guard (JSON-Logic); null = no burning. */
63
+ burnPolicy?: JsonLogicRule | null;
64
+ /** Fungible decimals; null/0 for NFTs. */
65
+ decimals?: number | null;
66
+ }
67
+ /** Morphism kinds. asset-model.md §4. */
68
+ export type MorphismKind = "Transfer" | "Burn" | "Fractionalize" | "Compose" | "Decompose" | "Wrap" | "Stake";
69
+ /** Morphism visibility — Governed carries a JSON-Logic guard. asset-model.md §8. */
70
+ export type MorphismVisibility = "Public" | "Governed" | "Disabled";
71
+ /** Per-kind morphism spec on a policy version. asset-model.md §7. */
72
+ export interface MorphismSpec {
73
+ visibility: MorphismVisibility;
74
+ /** Counter-party policy allowlist; omit for any. */
75
+ allowedPolicies?: string[];
76
+ /** Counter-party behavior-bitmask allowlist; omit for any. */
77
+ allowedTypes?: number[];
78
+ /** JSON-Logic guard (Governed only). */
79
+ guard?: JsonLogicRule;
80
+ }
81
+ /** A version requirement for resolving a policy. mirrors SDK `VersionReq`. */
82
+ export type VersionReq = {
83
+ Exact: {
84
+ version: string;
85
+ };
86
+ } | {
87
+ Caret: {
88
+ version: string;
89
+ };
90
+ } | {
91
+ Tilde: {
92
+ version: string;
93
+ };
94
+ } | {
95
+ Latest: Record<string, never>;
96
+ } | {
97
+ PinnedHash: {
98
+ hash: string;
99
+ };
100
+ };
101
+ /** A policy reference `(name, versionReq)`. mirrors SDK `SchemaRef`. */
102
+ export interface PolicyRef {
103
+ name: string;
104
+ version: VersionReq;
105
+ }
106
+ export interface CreateAssetPolicyParams {
107
+ /** `.asset` registry name, e.g. "collateral-vault-v1.asset". */
108
+ name: string;
109
+ version: string;
110
+ behavior: TokenBehavior;
111
+ supply: SupplyPolicy;
112
+ morphisms: Partial<Record<MorphismKind, MorphismSpec>>;
113
+ /** The asset record's state shape (proto message shape); free-form here. */
114
+ stateShape: Record<string, unknown>;
115
+ metadata?: Record<string, string>;
116
+ }
117
+ export interface CreateAssetPolicyMessage {
118
+ CreateAssetPolicy: {
119
+ name: string;
120
+ version: string;
121
+ behavior: TokenBehavior;
122
+ supply: SupplyPolicy;
123
+ morphisms: Partial<Record<MorphismKind, MorphismSpec>>;
124
+ stateShape: Record<string, unknown>;
125
+ metadata?: Record<string, string>;
126
+ };
127
+ }
128
+ /** Publish an asset policy package version. asset-model.md §7. */
129
+ export declare function createAssetPolicyPayload(params: CreateAssetPolicyParams): CreateAssetPolicyMessage;
130
+ export interface MintAssetParams {
131
+ /** The new asset instance id (UUID). */
132
+ assetId: string;
133
+ policyRef: PolicyRef;
134
+ holder: AssetHolder;
135
+ amount: number | string;
136
+ expiresAt?: number;
137
+ /** Witness the policy's `mintPolicy` guard reads (e.g. a Groth16 eligibility proof). */
138
+ witness?: Record<string, unknown>;
139
+ }
140
+ export interface MintAssetMessage {
141
+ MintAsset: {
142
+ assetId: string;
143
+ policyRef: PolicyRef;
144
+ holder: AssetHolder;
145
+ amount: number | string;
146
+ expiresAt?: number;
147
+ witness?: Record<string, unknown>;
148
+ };
149
+ }
150
+ /**
151
+ * Mint an asset instance. asset-model.md §7. When the policy's `mintPolicy` is a
152
+ * `groth16_verify` guard (proof-gated mint), pass the eligibility `witness`.
153
+ */
154
+ export declare function createMintAssetPayload(params: MintAssetParams): MintAssetMessage;
155
+ export interface ApplyMorphismParams {
156
+ assetId: string;
157
+ kind: MorphismKind;
158
+ targetSequenceNumber: number;
159
+ recipient?: AssetHolder;
160
+ otherAssets?: string[];
161
+ compositeId?: string;
162
+ shardIds?: string[];
163
+ nonce?: number;
164
+ /** Witness a Governed morphism's `guard` reads. */
165
+ witness?: Record<string, unknown>;
166
+ }
167
+ export interface ApplyMorphismMessage {
168
+ ApplyMorphism: {
169
+ assetId: string;
170
+ kind: MorphismKind;
171
+ targetSequenceNumber: number;
172
+ recipient?: AssetHolder;
173
+ otherAssets?: string[];
174
+ compositeId?: string;
175
+ shardIds?: string[];
176
+ nonce?: number;
177
+ witness?: Record<string, unknown>;
178
+ };
179
+ }
180
+ /**
181
+ * Apply a typed morphism (Transfer / Burn / Compose / ...). asset-model.md §7.
182
+ * Transfer = `{ kind: "Transfer", recipient }`; Burn (repay) = `{ kind: "Burn" }`.
183
+ */
184
+ export declare function createApplyMorphismPayload(params: ApplyMorphismParams): ApplyMorphismMessage;
185
+ export interface AuthorizeComposeParams {
186
+ assetId: string;
187
+ partnerPolicy: string;
188
+ nonce: number;
189
+ expiresAt: number;
190
+ targetSequenceNumber: number;
191
+ }
192
+ export interface AuthorizeComposeMessage {
193
+ AuthorizeCompose: {
194
+ assetId: string;
195
+ partnerPolicy: string;
196
+ nonce: number;
197
+ expiresAt: number;
198
+ targetSequenceNumber: number;
199
+ };
200
+ }
201
+ /** Commit half of a two-party compose. asset-model.md §7/§8. */
202
+ export declare function createAuthorizeComposePayload(params: AuthorizeComposeParams): AuthorizeComposeMessage;
203
+ /**
204
+ * The collateral vault policy: an NFT-like custodial holding (no fungible split) whose
205
+ * `Transfer` morphism is Governed — the loan/escrow fiber is the authorization. Locking is
206
+ * a custody Transfer into `AssetHolder.Fiber(escrow)`; release/liquidation is a Transfer out
207
+ * driven by the loan fiber's REPAID / LIQUIDATED transition (`_transferAsset`).
208
+ */
209
+ export declare function collateralPolicy(name?: string, version?: string): CreateAssetPolicyParams;
210
+ /**
211
+ * The loan-debt / principal policy: a governed fungible whose `mintPolicy` is the
212
+ * proof-gated origination guard — the principal is mintable to the borrower only when the
213
+ * eligibility proof verifies. Repayment is a `Burn` governed by `burnPolicy`.
214
+ *
215
+ * @param mintGuard the origination guard (see `buildOriginationGuard`) — a `groth16_verify`
216
+ * expression bound to the pinned public lending rule.
217
+ */
218
+ export declare function debtPolicy(mintGuard: JsonLogicRule, name?: string, version?: string): CreateAssetPolicyParams;
219
+ /**
220
+ * lock_collateral: custody Transfer of the pledged collateral into the loan escrow fiber.
221
+ * (asset-model.md §10 — locking is a custody transfer to `AssetHolder.Fiber`, there is no
222
+ * `Lock` morphism.)
223
+ */
224
+ export declare function lockCollateralOp(args: {
225
+ collateralAssetId: string;
226
+ escrowFiberId: string;
227
+ targetSequenceNumber: number;
228
+ }): ApplyMorphismMessage;
229
+ /**
230
+ * originate: Mint the loan principal/debt to the borrower. The policy's `mintPolicy`
231
+ * (the origination guard) reads the eligibility `witness` ({publicValues, proof}).
232
+ */
233
+ export declare function mintPrincipalOp(args: {
234
+ debtAssetId: string;
235
+ debtPolicyRef: PolicyRef;
236
+ borrower: string;
237
+ principalAmount: number | string;
238
+ witness: {
239
+ publicValues: string;
240
+ proof: string;
241
+ };
242
+ }): MintAssetMessage;
243
+ /** repay: Burn the borrower's debt token (the principal is repaid). */
244
+ export declare function repayBurnOp(args: {
245
+ debtAssetId: string;
246
+ targetSequenceNumber: number;
247
+ }): ApplyMorphismMessage;
248
+ /**
249
+ * release / liquidate: Transfer the escrowed collateral out of the escrow fiber to a
250
+ * recipient (the borrower on REPAID, the lender on LIQUIDATED). On-chain this is emitted by
251
+ * the loan fiber's transition via `_transferAsset`; this builder produces the equivalent
252
+ * explicit `ApplyMorphism(Transfer)` for off-fiber/manual settlement.
253
+ */
254
+ export declare function settleCollateralOp(args: {
255
+ collateralAssetId: string;
256
+ recipient: string;
257
+ targetSequenceNumber: number;
258
+ }): ApplyMorphismMessage;
@@ -0,0 +1,80 @@
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 { Attestation, ReputationConfig } from "../identity/index.js";
24
+ import { type LendingRuleParams, type JsonLogicRule } from "./eligibility.js";
25
+ /** The reputation config fields credit scoring needs (a subset of the identity {@link ReputationConfig}). */
26
+ export type CreditScoreConfig = Pick<ReputationConfig, "baseReputation" | "minReputation">;
27
+ /**
28
+ * Derive an agent's credit score from their identity reputation attestations:
29
+ * `baseReputation + Σ attestation.delta`, floored at `minReputation`. This IS the integration point —
30
+ * a zk-loan's creditScore is the borrower's identity reputation, not an independent number.
31
+ */
32
+ export declare function reputationScore(attestations: ReadonlyArray<Pick<Attestation, "delta">>, config?: CreditScoreConfig): number;
33
+ /** Params for a reputation-bound credit rule: the lending params plus the borrower identity it pins. */
34
+ export interface ReputationCreditParams extends LendingRuleParams {
35
+ /** The borrower's identity (agent id / DID) the proven reputation score must belong to. */
36
+ borrowerId: string;
37
+ }
38
+ /** The PRIVATE data context a borrower proves a reputation-credit rule over (only `subject` is public). */
39
+ export interface CreditDataContext {
40
+ /** PRIVATE — the borrower's collateral value. */
41
+ collateralValue: number;
42
+ /** PRIVATE — the borrower's reputation-derived credit score. */
43
+ creditScore: number;
44
+ /** PUBLIC — the borrower identity the score is bound to (pinned in the rule). */
45
+ subject: string;
46
+ }
47
+ /**
48
+ * The PUBLIC reputation-credit lending rule. Extends {@link lendingRule} (collateral coverage +
49
+ * optional credit-score floor) with a SUBJECT binding `subject === borrowerId`, so the proven score
50
+ * belongs to a specific identity — a borrower cannot prove eligibility against another agent's
51
+ * reputation. `borrowerId` and all bounds are literals, so pinning the rule pins them.
52
+ */
53
+ export declare function reputationCreditRule(params: ReputationCreditParams): JsonLogicRule;
54
+ /**
55
+ * Assemble the PRIVATE data context the borrower feeds to the zk-jlvm prover: the `creditScore` is
56
+ * their identity {@link reputationScore}, the `subject` is their identity. Only its keccak (`dataHash`)
57
+ * becomes public.
58
+ */
59
+ export declare function buildCreditDataContext(args: {
60
+ borrowerId: string;
61
+ attestations: ReadonlyArray<Pick<Attestation, "delta">>;
62
+ collateralValue: number;
63
+ config?: CreditScoreConfig;
64
+ }): CreditDataContext;
65
+ /**
66
+ * OPTIONAL hardening — an authority-attested credit clause. ANDed into a rule, it makes the SP1 guest
67
+ * verify (in zero knowledge) the reputation issuer's Schnorr signature over the score, so the score is
68
+ * not merely borrower-supplied but ATTESTED.
69
+ *
70
+ * SECURITY: the authority's `authorityPubKey` MUST be a LITERAL pinned in the rule (it is part of the
71
+ * rule's keccak `logicHash`, so pinning it binds it) — NEVER read from the borrower's witness/private
72
+ * data, or the borrower could supply their own keypair and self-attest any score. Only the signature
73
+ * `repSig` and the signed `scoreCommit` ride on the (private) witness; the signature binds them to the
74
+ * pinned key. `scoreCommit` should commit the pinned `subject` + the proof's `dataHash` so a signature
75
+ * cannot be replayed for a different borrower/score.
76
+ *
77
+ * NOTE: producing a real signature + proof is required to exercise this end-to-end; the builder pins
78
+ * the structure so the on-chain rule and the prover agree. See the JLVM `schnorr_verify` opcode.
79
+ */
80
+ export declare function reputationAuthorityClause(authorityPubKey: string): JsonLogicRule;
@@ -0,0 +1,83 @@
1
+ import type { Groth16WitnessMap, Groth16Bundle } from "../../zk/index.js";
2
+ /** A JSON-Logic expression. */
3
+ export type JsonLogicRule = Record<string, unknown>;
4
+ /**
5
+ * Parameters for the standard collateral-coverage + credit-score lending rule.
6
+ *
7
+ * The literal bounds are baked INTO the rule expression, so they are part of its logicHash —
8
+ * pinning the rule pins the bounds. The numerator/denominator form expresses the LTV bound
9
+ * `collateralValue * 100 >= loanAmount * collateralRatioPct` without floating-point.
10
+ */
11
+ export interface LendingRuleParams {
12
+ /** Required collateralization, as a percent of the loan (e.g. 150 = 150% over-collateralized). */
13
+ collateralRatioPct: number;
14
+ /** PUBLIC loan principal the rule is checked against. */
15
+ loanAmount: number;
16
+ /** Optional minimum credit score floor; omit to gate on collateral coverage only. */
17
+ minCreditScore?: number;
18
+ }
19
+ /**
20
+ * The PUBLIC lending rule, as a JSON-Logic predicate over the borrower's PRIVATE data context
21
+ * `{ collateralValue, creditScore }`. Evaluates to `true` iff the borrower is eligible:
22
+ *
23
+ * collateralValue * 100 >= loanAmount * collateralRatioPct (collateral coverage)
24
+ * AND creditScore >= minCreditScore (if a floor is set)
25
+ *
26
+ * Only the predicate and its literal bounds are public; the data it is evaluated over
27
+ * (`collateralValue`, `creditScore`) is the prover's private witness — its keccak is the
28
+ * proof's `dataHash`, never revealed. This is the rule the zk-jlvm guest runs; its `exprHash`
29
+ * is pinned as the loan's `lendingRuleLogicHash`.
30
+ */
31
+ export declare function lendingRule(params: LendingRuleParams): JsonLogicRule;
32
+ /** The pinned public constants a zk-loan create-state carries so its origination guard is closed. */
33
+ export interface PinnedLendingRule {
34
+ /** The PUBLIC rule expression (with literal bounds). */
35
+ rule: JsonLogicRule;
36
+ /** keccak256(canonicalize(rule)) — pinned as `lendingRuleLogicHash`; the proof's exprHash must equal it. */
37
+ logicHash: `0x${string}`;
38
+ /** keccak256(canonicalize(true)) — pinned as `keccakTrue`; a "rule == true" proof's outputHash. */
39
+ keccakTrue: `0x${string}`;
40
+ /** The SP1 program verifying key (bytes32, 0x-hex) for the eligibility circuit. */
41
+ vkey: `0x${string}`;
42
+ }
43
+ /**
44
+ * Pin a lending rule: produce the public rule plus the three constants the loan's origination
45
+ * guard binds against. `vkey` is the verifying key of the SP1 zk-jlvm program that runs the
46
+ * rule (supplied by the lender / deployment).
47
+ */
48
+ export declare function pinLendingRule(params: LendingRuleParams, vkey: `0x${string}`): PinnedLendingRule;
49
+ /** The pinned public references the origination guard reads off the loan state. */
50
+ export interface OriginationGuardRefs {
51
+ /** State path to the pinned vkey (default `state.lendingRuleVKey`). */
52
+ vkeyVar?: string;
53
+ /** State path to the pinned logicHash (default `state.lendingRuleLogicHash`). */
54
+ logicHashVar?: string;
55
+ /** State path to the pinned keccakTrue (default `state.keccakTrue`). */
56
+ keccakTrueVar?: string;
57
+ }
58
+ /**
59
+ * Build the semi-private ORIGINATION guard expression.
60
+ *
61
+ * It verifies the SP1-Groth16 eligibility proof AND binds its committed public values to the
62
+ * pinned public rule. `publicValues = abi_encode(JlvmPublicValues{exprHash|dataHash|outputHash|ok})`
63
+ * is opaque to `groth16_verify`; the guard slices the `0x`-hex form with native JLVM `substr`
64
+ * (start, len) and re-`cat`s the `0x` prefix — there is no `jlvm_pv_decode` opcode. Clauses:
65
+ *
66
+ * 1. `groth16_verify(vkey, witness.publicValues, witness.proof)` — the proof is valid
67
+ * 2. `exprHash == logicHash` (word 0, hex chars [2,66)) — it proved THE pinned rule
68
+ * 3. `outputHash == keccakTrue` (word 2, hex chars [130,194)) — the rule evaluated to true
69
+ * 4. `ok == "01"` (word 3 final pair, [256,258)) — the JLVM run did not error
70
+ *
71
+ * This is the closed boolean an asset `mintPolicy` or a fiber-transition guard wraps. The
72
+ * lending state machine ANDs clause 0 (`agent == lender`) in front of it; the debt asset
73
+ * policy uses it directly as the proof-gated `mintPolicy`.
74
+ */
75
+ export declare function buildOriginationGuard(refs?: OriginationGuardRefs): JsonLogicRule;
76
+ /**
77
+ * Construct the eligibility-proof witness the origination guard reads. The `{publicValues,
78
+ * proof}` come from the SP1 zk-jlvm prover (`--mode groth16`) run over the public rule and the
79
+ * borrower's PRIVATE data context. Both are lowercase `0x`-hex; they are exposed to the guard
80
+ * under the reserved `witness` key (on the loan `originate` event payload, or on a proof-gated
81
+ * `MintAsset`).
82
+ */
83
+ export declare function buildEligibilityWitness(bundle: Pick<Groth16Bundle, "publicValues" | "proof">): Groth16WitnessMap;