@ottochain/sdk 2.4.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 +1 -1
- package/dist/cjs/apps/contracts/state-machines/contract-agreement.js +126 -148
- package/dist/cjs/apps/contracts/state-machines/contract-escrow.js +153 -174
- package/dist/cjs/apps/contracts/state-machines/contract-universal.js +46 -58
- package/dist/cjs/apps/corporate/state-machines/corp-board.js +415 -481
- package/dist/cjs/apps/corporate/state-machines/corp-entity.js +368 -440
- package/dist/cjs/apps/corporate/state-machines/corp-securities.js +532 -647
- package/dist/cjs/apps/corporate/state-machines/corp-shareholders.js +499 -603
- package/dist/cjs/apps/governance/index.js +7 -7
- package/dist/cjs/apps/governance/state-machines/dao-multisig.js +170 -209
- package/dist/cjs/apps/governance/state-machines/dao-reputation.js +161 -214
- package/dist/cjs/apps/governance/state-machines/dao-single.js +92 -92
- package/dist/cjs/apps/governance/state-machines/dao-token.js +169 -223
- package/dist/cjs/apps/governance/state-machines/governance-simple.js +185 -217
- package/dist/cjs/apps/governance/state-machines/governance-universal.js +64 -64
- package/dist/cjs/apps/identity/constants.js +16 -24
- package/dist/cjs/apps/identity/index.js +1 -1
- package/dist/cjs/apps/identity/state-machines/identity-agent.js +124 -158
- package/dist/cjs/apps/identity/state-machines/identity-oracle.js +151 -169
- package/dist/cjs/apps/identity/state-machines/identity-registry.js +89 -115
- package/dist/cjs/apps/identity/state-machines/identity-universal.js +51 -57
- package/dist/cjs/apps/index.js +4 -1
- package/dist/cjs/apps/lending/assets.js +41 -17
- package/dist/cjs/apps/lending/credit-scoring.js +4 -4
- package/dist/cjs/apps/lending/eligibility.js +9 -25
- package/dist/cjs/apps/lending/index.js +1 -1
- package/dist/cjs/apps/lending/state-machines/lending-zk-loan.js +177 -156
- package/dist/cjs/apps/markets/index.js +1 -1
- package/dist/cjs/apps/markets/state-machines/market-auction.js +115 -134
- package/dist/cjs/apps/markets/state-machines/market-crowdfund.js +122 -137
- package/dist/cjs/apps/markets/state-machines/market-group-buy.js +158 -177
- package/dist/cjs/apps/markets/state-machines/market-prediction.js +193 -227
- package/dist/cjs/apps/markets/state-machines/market-universal.js +65 -80
- package/dist/cjs/apps/oracles/index.js +1 -1
- 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/generated/google/protobuf/struct.js +1 -1
- package/dist/cjs/generated/google/protobuf/timestamp.js +1 -1
- package/dist/cjs/generated/ottochain/apps/contracts/v1/contract.js +1 -1
- package/dist/cjs/generated/ottochain/apps/corporate/v1/corporate.js +1 -1
- package/dist/cjs/generated/ottochain/apps/governance/v1/governance.js +1 -1
- package/dist/cjs/generated/ottochain/apps/identity/v1/attestation.js +1 -1
- package/dist/cjs/generated/ottochain/apps/identity/v1/identity.js +1 -1
- package/dist/cjs/generated/ottochain/apps/markets/v1/market.js +1 -1
- package/dist/cjs/generated/ottochain/v1/common.js +1 -1
- package/dist/cjs/generated/ottochain/v1/fiber.js +40 -2
- 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 +20 -3
- package/dist/cjs/ottochain/genesis-manifest.js +6 -0
- package/dist/cjs/ottochain/metagraph-client.js +16 -8
- package/dist/cjs/ottochain/snapshot.js +2 -4
- package/dist/cjs/ottochain/transaction.js +10 -0
- package/dist/cjs/privacy/sealed-bid.js +85 -82
- package/dist/cjs/privacy/shield-app.js +32 -32
- package/dist/cjs/schema/effects.js +117 -1
- package/dist/cjs/schema/fiber-app.js +132 -3
- package/dist/cjs/schema/guard-lint.js +3 -12
- package/dist/cjs/schema/guards.js +38 -38
- 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/validation.js +1 -3
- 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 +4 -4
- package/dist/esm/apps/contracts/state-machines/contract-agreement.js +128 -150
- package/dist/esm/apps/contracts/state-machines/contract-escrow.js +155 -176
- 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 +418 -484
- package/dist/esm/apps/corporate/state-machines/corp-entity.js +371 -443
- package/dist/esm/apps/corporate/state-machines/corp-securities.js +535 -650
- package/dist/esm/apps/corporate/state-machines/corp-shareholders.js +502 -606
- package/dist/esm/apps/governance/index.js +10 -10
- package/dist/esm/apps/governance/state-machines/dao-multisig.js +172 -211
- package/dist/esm/apps/governance/state-machines/dao-reputation.js +163 -216
- package/dist/esm/apps/governance/state-machines/dao-single.js +94 -94
- package/dist/esm/apps/governance/state-machines/dao-token.js +171 -225
- package/dist/esm/apps/governance/state-machines/governance-simple.js +187 -219
- package/dist/esm/apps/governance/state-machines/governance-universal.js +65 -65
- package/dist/esm/apps/identity/constants.js +18 -26
- package/dist/esm/apps/identity/index.js +8 -8
- package/dist/esm/apps/identity/state-machines/identity-agent.js +125 -159
- package/dist/esm/apps/identity/state-machines/identity-oracle.js +153 -171
- package/dist/esm/apps/identity/state-machines/identity-registry.js +91 -117
- package/dist/esm/apps/identity/state-machines/identity-universal.js +52 -58
- package/dist/esm/apps/index.js +9 -6
- package/dist/esm/apps/lending/assets.js +41 -17
- package/dist/esm/apps/lending/credit-scoring.js +6 -6
- package/dist/esm/apps/lending/eligibility.js +10 -26
- package/dist/esm/apps/lending/index.js +5 -5
- package/dist/esm/apps/lending/state-machines/lending-zk-loan.js +178 -157
- package/dist/esm/apps/markets/index.js +5 -5
- package/dist/esm/apps/markets/state-machines/market-auction.js +117 -136
- package/dist/esm/apps/markets/state-machines/market-crowdfund.js +124 -139
- package/dist/esm/apps/markets/state-machines/market-group-buy.js +160 -179
- package/dist/esm/apps/markets/state-machines/market-prediction.js +195 -229
- 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/ottochain/apps/contracts/v1/contract.js +1 -1
- 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 +1 -1
- package/dist/esm/generated/ottochain/apps/markets/v1/market.js +1 -1
- 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 +10 -4
- package/dist/esm/ottochain/genesis-manifest.js +6 -0
- package/dist/esm/ottochain/metagraph-client.js +16 -8
- package/dist/esm/ottochain/snapshot.js +2 -4
- package/dist/esm/ottochain/transaction.js +8 -0
- package/dist/esm/privacy/index.js +2 -2
- package/dist/esm/privacy/sealed-bid.js +87 -84
- package/dist/esm/privacy/shield-app.js +33 -33
- package/dist/esm/schema/effects.js +110 -0
- package/dist/esm/schema/fiber-app.js +127 -3
- package/dist/esm/schema/guard-lint.js +3 -12
- package/dist/esm/schema/guards.js +36 -37
- 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/zk/index.js +4 -4
- 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 +14 -14
- package/dist/types/apps/contracts/state-machines/contract-agreement.d.ts +3 -3
- package/dist/types/apps/contracts/state-machines/contract-escrow.d.ts +3 -3
- package/dist/types/apps/contracts/state-machines/contract-universal.d.ts +4 -4
- package/dist/types/apps/corporate/index.d.ts +162 -162
- package/dist/types/apps/corporate/state-machines/corp-board.d.ts +88 -88
- package/dist/types/apps/corporate/state-machines/corp-entity.d.ts +14 -14
- package/dist/types/apps/corporate/state-machines/corp-securities.d.ts +18 -18
- package/dist/types/apps/corporate/state-machines/corp-shareholders.d.ts +43 -43
- package/dist/types/apps/governance/index.d.ts +81 -81
- package/dist/types/apps/governance/state-machines/dao-multisig.d.ts +16 -16
- package/dist/types/apps/governance/state-machines/dao-reputation.d.ts +22 -22
- package/dist/types/apps/governance/state-machines/dao-token.d.ts +21 -21
- package/dist/types/apps/governance/state-machines/governance-simple.d.ts +11 -11
- package/dist/types/apps/governance/state-machines/governance-universal.d.ts +4 -4
- package/dist/types/apps/identity/constants.d.ts +2 -2
- package/dist/types/apps/identity/index.d.ts +70 -70
- package/dist/types/apps/identity/state-machines/identity-agent.d.ts +23 -23
- package/dist/types/apps/identity/state-machines/identity-oracle.d.ts +11 -11
- package/dist/types/apps/identity/state-machines/identity-registry.d.ts +27 -27
- package/dist/types/apps/identity/state-machines/identity-universal.d.ts +4 -4
- package/dist/types/apps/index.d.ts +9 -6
- package/dist/types/apps/lending/assets.d.ts +2 -2
- package/dist/types/apps/lending/credit-scoring.d.ts +5 -5
- package/dist/types/apps/lending/eligibility.d.ts +2 -2
- package/dist/types/apps/lending/index.d.ts +20 -12
- package/dist/types/apps/lending/state-machines/lending-zk-loan.d.ts +15 -7
- package/dist/types/apps/markets/index.d.ts +76 -76
- package/dist/types/apps/markets/state-machines/market-auction.d.ts +12 -12
- package/dist/types/apps/markets/state-machines/market-crowdfund.d.ts +19 -19
- package/dist/types/apps/markets/state-machines/market-group-buy.d.ts +18 -18
- package/dist/types/apps/markets/state-machines/market-prediction.d.ts +15 -15
- package/dist/types/apps/markets/state-machines/market-universal.d.ts +7 -7
- 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/openapi.d.ts +13 -0
- package/dist/types/generated/ottochain/v1/fiber.d.ts +7 -0
- package/dist/types/index.d.ts +3 -3
- package/dist/types/openapi.d.ts +4 -2
- package/dist/types/ottochain/genesis-manifest.d.ts +6 -0
- package/dist/types/ottochain/transaction.d.ts +9 -1
- package/dist/types/ottochain/types.d.ts +1 -1
- package/dist/types/privacy/index.d.ts +2 -2
- package/dist/types/privacy/sealed-bid.d.ts +9 -9
- package/dist/types/privacy/shield-app.d.ts +1 -1
- package/dist/types/schema/effects.d.ts +107 -0
- package/dist/types/schema/fiber-app.d.ts +281 -0
- package/dist/types/schema/guards.d.ts +12 -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/zk/index.d.ts +4 -4
- package/package.json +31 -13
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
* (the Vickrey price). This is the one shared-state step, kept simple for v1; a zk settlement
|
|
12
12
|
* proof that seals losers' amounts forever is the deferred upgrade (RFC §10).
|
|
13
13
|
*/
|
|
14
|
-
import { type FiberAppDefinition } from
|
|
15
|
-
import { type ShieldOptions } from
|
|
14
|
+
import { type FiberAppDefinition } from '../schema/fiber-app.js';
|
|
15
|
+
import { type ShieldOptions } from './shield-app.js';
|
|
16
16
|
/** The per-bidder PRIVATE state: a bid note `{ amount, bidder, nonce }`. */
|
|
17
17
|
export declare const sealedBidAccountDef: {
|
|
18
18
|
readonly metadata: {
|
|
@@ -75,7 +75,7 @@ export declare const sealedBidAccountDef: {
|
|
|
75
75
|
readonly to: "BID";
|
|
76
76
|
readonly eventName: "place_bid";
|
|
77
77
|
readonly guard: {
|
|
78
|
-
readonly
|
|
78
|
+
readonly '>': readonly [{
|
|
79
79
|
readonly var: "event.amount";
|
|
80
80
|
}, 0];
|
|
81
81
|
};
|
|
@@ -209,7 +209,7 @@ export declare const vickreyAuctionDef: {
|
|
|
209
209
|
readonly to: "REVEAL";
|
|
210
210
|
readonly eventName: "reveal";
|
|
211
211
|
readonly guard: {
|
|
212
|
-
readonly
|
|
212
|
+
readonly '>=': readonly [{
|
|
213
213
|
readonly var: "$timestamp";
|
|
214
214
|
}, {
|
|
215
215
|
readonly var: "state.deadline";
|
|
@@ -240,7 +240,7 @@ export declare const vickreyAuctionDef: {
|
|
|
240
240
|
readonly to: "REVEAL";
|
|
241
241
|
readonly eventName: "reveal";
|
|
242
242
|
readonly guard: {
|
|
243
|
-
readonly
|
|
243
|
+
readonly '>=': readonly [{
|
|
244
244
|
readonly var: "$timestamp";
|
|
245
245
|
}, {
|
|
246
246
|
readonly var: "state.deadline";
|
|
@@ -270,11 +270,11 @@ export declare const vickreyAuctionDef: {
|
|
|
270
270
|
readonly to: "SETTLED";
|
|
271
271
|
readonly eventName: "settle";
|
|
272
272
|
readonly guard: {
|
|
273
|
-
readonly
|
|
273
|
+
readonly '>': readonly [{
|
|
274
274
|
readonly reduce: readonly [{
|
|
275
275
|
readonly var: "state.revealed";
|
|
276
276
|
}, {
|
|
277
|
-
readonly
|
|
277
|
+
readonly '+': readonly [{
|
|
278
278
|
readonly var: "accumulator";
|
|
279
279
|
}, 1];
|
|
280
280
|
}, 0];
|
|
@@ -299,7 +299,7 @@ export declare const vickreyAuctionDef: {
|
|
|
299
299
|
readonly var: "state.revealed";
|
|
300
300
|
}, {
|
|
301
301
|
readonly if: readonly [{
|
|
302
|
-
readonly
|
|
302
|
+
readonly '>': readonly [{
|
|
303
303
|
readonly var: "current.amount";
|
|
304
304
|
}, {
|
|
305
305
|
readonly var: "accumulator.max";
|
|
@@ -316,7 +316,7 @@ export declare const vickreyAuctionDef: {
|
|
|
316
316
|
};
|
|
317
317
|
}, {
|
|
318
318
|
readonly if: readonly [{
|
|
319
|
-
readonly
|
|
319
|
+
readonly '>': readonly [{
|
|
320
320
|
readonly var: "current.amount";
|
|
321
321
|
}, {
|
|
322
322
|
readonly var: "accumulator.second";
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* O(state size) (RFC §8). Keep shielded note state small (a few KB); for large keyed state use
|
|
25
25
|
* the auth-DB variant (RFC §3.1.1).
|
|
26
26
|
*/
|
|
27
|
-
import { type FiberAppDefinition, type SchemaField } from
|
|
27
|
+
import { type FiberAppDefinition, type SchemaField } from '../schema/fiber-app.js';
|
|
28
28
|
export interface ShieldOptions {
|
|
29
29
|
/** SP1 program vkey for the zk-jlvm-shielded circuit (0x-prefixed bytes32 hex). Pinned at creation. */
|
|
30
30
|
vkey: string;
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* }
|
|
15
15
|
* ```
|
|
16
16
|
*/
|
|
17
|
+
import type { ProtoStateMachineDefinition } from './fiber-app.js';
|
|
17
18
|
/** A JSON-Logic value: a literal (string/number/bool) or a `{var}`/operator expression. */
|
|
18
19
|
type JsonLogicValue = unknown;
|
|
19
20
|
/**
|
|
@@ -31,4 +32,110 @@ export declare const addDependency: (fiberId: JsonLogicValue) => Record<string,
|
|
|
31
32
|
* may be a literal or an expression.
|
|
32
33
|
*/
|
|
33
34
|
export declare const setDependencyActive: (fiberId: JsonLogicValue, active: boolean) => Record<string, unknown>;
|
|
35
|
+
/**
|
|
36
|
+
* `_transferAsset`: move one or more WHOLE asset instances the emitting fiber holds, each to a single
|
|
37
|
+
* recipient. The directive rides INSIDE a `merge` effect map (the engine extracts `_`-prefixed keys
|
|
38
|
+
* before merging into state); a transition-level `emits` block is silently stripped by
|
|
39
|
+
* `toProtoDefinition`, which would strand the asset.
|
|
40
|
+
*
|
|
41
|
+
* Each directive is `{ assetId, recipient }` ONLY — there is NO `amount` field. The combiner reassigns
|
|
42
|
+
* `holder := recipient` on the WHOLE asset record (`AssetCombiner.applyFiberTransfer`); value is moved
|
|
43
|
+
* one whole instance at a time, never split. `recipient` must resolve to the canonical `AssetHolder`
|
|
44
|
+
* OBJECT form — `{"Fiber":{"fiberId":..}}` / `{"Wallet":{"address":..}}` — built with {@link toFiber} /
|
|
45
|
+
* {@link toWallet}; the chain raises a graceful `CombineRejected` on a bare string or malformed object
|
|
46
|
+
* (`EffectExtractor.parseAssetTransfer`). `assetId` is a UUID; the holder id may be a literal or an
|
|
47
|
+
* expression (e.g. `{ var: "event.agent" }`).
|
|
48
|
+
*
|
|
49
|
+
* Combiner-side holder defense (R1) independently re-validates every directive: the asset must resolve,
|
|
50
|
+
* be held by `Fiber(self)`, be `behavior.transferable`, and (Fiber recipient) the recipient fiber must be
|
|
51
|
+
* live — else the whole transition is `CombineRejected`. There is a hard cap of 32 asset mutations per
|
|
52
|
+
* transition (all-or-nothing); keep emitting fibers at ≤1 transfer per transition for claim/withdraw/slash.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* effect: { merge: [ { var: "state" }, {
|
|
56
|
+
* status: "SETTLED",
|
|
57
|
+
* ...transferAsset([{ assetId: { var: "event.rewardAssetId" }, recipient: toWallet({ var: "event.agent" }) }]),
|
|
58
|
+
* } ] }
|
|
59
|
+
*/
|
|
60
|
+
export declare const transferAsset: (transfers: {
|
|
61
|
+
assetId: JsonLogicValue;
|
|
62
|
+
recipient: JsonLogicValue;
|
|
63
|
+
}[]) => Record<string, unknown>;
|
|
64
|
+
/**
|
|
65
|
+
* Build a `_transferAsset` `recipient` as the canonical `AssetHolder` OBJECT form. The chain requires the
|
|
66
|
+
* object form ONLY — `{"Fiber":{"fiberId":..}}` / `{"Wallet":{"address":..}}` — and raises a graceful
|
|
67
|
+
* `CombineRejected` on a bare string or a malformed object (`EffectExtractor.parseAssetTransfer`); the
|
|
68
|
+
* legacy bare-string UUID/DAG-address disambiguation has been removed. These mirror the typed
|
|
69
|
+
* {@link fiberHolder} / {@link walletHolder} `AssetHolder` builders (used for `MintAsset.holder` /
|
|
70
|
+
* `ApplyMorphism.recipient`) but accept a `JsonLogicValue`, so the id can be a runtime expression:
|
|
71
|
+
*
|
|
72
|
+
* ```ts
|
|
73
|
+
* transferAsset([{ assetId, recipient: toFiber({ var: "event.retailerId" }) }]); // → {"Fiber":{"fiberId":..}}
|
|
74
|
+
* transferAsset([{ assetId, recipient: toWallet({ var: "event.agent" }) }]); // → {"Wallet":{"address":..}}
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export declare const toFiber: (fiberId: JsonLogicValue) => JsonLogicValue;
|
|
78
|
+
/** See {@link toFiber}: a `transferAsset` recipient held by a wallet — `{"Wallet":{"address":..}}`. */
|
|
79
|
+
export declare const toWallet: (address: JsonLogicValue) => JsonLogicValue;
|
|
80
|
+
/**
|
|
81
|
+
* `_triggers` (F4): fire one or more CROSS-FIBER events. Each entry is projected to
|
|
82
|
+
* `{ targetMachineId, eventName, payload }` — the exact shape the chain's `EffectExtractor` reads
|
|
83
|
+
* (`ReservedKeys.scala`, `EffectExtractor.scala`). `target` is the recipient fiber id (a literal UUID
|
|
84
|
+
* or an expression, e.g. `{ var: "event.retailerId" }`); `event` is the event NAME to enqueue on it;
|
|
85
|
+
* `payload` is the event body — omit it and the builder emits `{}` (never `null`).
|
|
86
|
+
*
|
|
87
|
+
* Authoring this as a builder makes a typo'd `_trigger` / `triggres` a TypeScript error rather than a
|
|
88
|
+
* silently-merged state field (the F4 foot-gun). Place the fragment INSIDE the effect's state-update
|
|
89
|
+
* map so it rides in the evaluated result the extractor reads.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* effect: { merge: [ { var: "state" }, {
|
|
93
|
+
* status: "debt_current",
|
|
94
|
+
* ...triggers([{ target: { var: "event.retailerId" }, event: "process_sale",
|
|
95
|
+
* payload: { buyerId: { var: "machineId" }, quantity: { var: "event.quantity" } } }]),
|
|
96
|
+
* } ] }
|
|
97
|
+
*/
|
|
98
|
+
export declare const triggers: (ts: {
|
|
99
|
+
target: JsonLogicValue;
|
|
100
|
+
event: string;
|
|
101
|
+
payload?: Record<string, unknown>;
|
|
102
|
+
}[]) => Record<string, unknown>;
|
|
103
|
+
/**
|
|
104
|
+
* `_spawn`: create one or more CHILD fibers, each from a literal machine `definition`. Each entry is
|
|
105
|
+
* `{ childId, definition, initialData, owners }` (`ReservedKeys.scala`, `EffectExtractor.scala`).
|
|
106
|
+
*
|
|
107
|
+
* The chain extracts `_spawn` from the effect EXPRESSION, not the evaluated result, so `definition`
|
|
108
|
+
* MUST be a literal {@link ProtoStateMachineDefinition} (e.g. a nested `machine().wireDefinition()` /
|
|
109
|
+
* `toProtoDefinition(child)` output) — NOT an expression the engine would evaluate at runtime.
|
|
110
|
+
*
|
|
111
|
+
* F8 gotcha — `owners` is load-bearing. A spawned child's transitions are gated by
|
|
112
|
+
* `owners ∪ authorizedSigners` (`riverdale-economy/README.md`), so EVERY party that will later drive
|
|
113
|
+
* the child (e.g. every bidder on a spawned auction) MUST be listed in `owners`, or their events are
|
|
114
|
+
* rejected. `owners` may be a literal id array or an expression (e.g. `{ var: "event.auctionOwners" }`);
|
|
115
|
+
* `childId` / `initialData` likewise accept literals or expressions.
|
|
116
|
+
*/
|
|
117
|
+
export declare const spawn: (ds: {
|
|
118
|
+
childId: JsonLogicValue;
|
|
119
|
+
definition: ProtoStateMachineDefinition;
|
|
120
|
+
initialData: Record<string, unknown>;
|
|
121
|
+
owners: JsonLogicValue;
|
|
122
|
+
}[]) => Record<string, unknown>;
|
|
123
|
+
/**
|
|
124
|
+
* `_emit`: emit one or more domain events to the fiber's outbox. Each entry is
|
|
125
|
+
* `{ name, data, destination? }` (`ReservedKeys.scala`, `EffectExtractor.scala`). `name` is the event
|
|
126
|
+
* name, `data` the body (a literal or an expression), and `destination` an OPTIONAL routing target —
|
|
127
|
+
* omit it when absent (callers never pass `null`, so it is simply absent on the wire).
|
|
128
|
+
*/
|
|
129
|
+
export declare const emit: (es: {
|
|
130
|
+
name: string;
|
|
131
|
+
data: JsonLogicValue;
|
|
132
|
+
destination?: string;
|
|
133
|
+
}[]) => Record<string, unknown>;
|
|
134
|
+
/**
|
|
135
|
+
* The complete set of `_`-prefixed RESERVED effect keys the chain's `EffectExtractor` consumes and
|
|
136
|
+
* `StateMerger` strips from state (`ReservedKeys.scala:12-49`). Exported so a validator (Proposal 01)
|
|
137
|
+
* can reject an unknown `_`-prefixed key (a typo'd directive) instead of letting it silently leak into
|
|
138
|
+
* persisted state.
|
|
139
|
+
*/
|
|
140
|
+
export declare const RESERVED_EFFECT_KEYS: readonly ["_triggers", "_spawn", "_emit", "_transferAsset", "_scriptCall", "_addDependency", "_setDependencyActive"];
|
|
34
141
|
export {};
|
|
@@ -105,6 +105,269 @@ export interface Transition<TState extends string = string, TEvent extends strin
|
|
|
105
105
|
dependencies?: readonly (string | DependencySpec)[];
|
|
106
106
|
emits?: readonly (string | EmitSpec)[];
|
|
107
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* `allowedEffects` element — the 5 `EffectKind` families, UPPERCASE on the wire
|
|
110
|
+
* (`enumeratum` `Uppercase` mixin). Chain: `EffectKind` in `FiberPolicy.scala`.
|
|
111
|
+
*/
|
|
112
|
+
export type EffectKind = 'TRIGGER' | 'SPAWN' | 'EMIT' | 'TRANSFER' | 'DEPENDENCY';
|
|
113
|
+
/**
|
|
114
|
+
* `spawnOwnerPolicy` — UPPERCASE (`enumeratum` `Uppercase`). Chain: `SpawnOwnerPolicy`
|
|
115
|
+
* (`Explicit` / `SubsetOfParent` / `InheritParent` ⇒ `"EXPLICIT"` / `"SUBSETOFPARENT"`
|
|
116
|
+
* / `"INHERITPARENT"`).
|
|
117
|
+
*/
|
|
118
|
+
export type SpawnOwnerPolicy = 'EXPLICIT' | 'SUBSETOFPARENT' | 'INHERITPARENT';
|
|
119
|
+
/**
|
|
120
|
+
* `dependencyPolicy.mode` — UPPERCASE (`enumeratum` `Uppercase`). Chain: `DependencyMode`
|
|
121
|
+
* (`Open` / `Allowlist` / `Frozen`). REQUIRED on the wire (Scala defaults it to `Open`,
|
|
122
|
+
* but the `customizableEncoder` always encodes the value).
|
|
123
|
+
*/
|
|
124
|
+
export type DependencyMode = 'OPEN' | 'ALLOWLIST' | 'FROZEN';
|
|
125
|
+
/**
|
|
126
|
+
* `transferPolicy` — recipient allowlist for `_transferAsset`. Chain: `TransferPolicy`
|
|
127
|
+
* (`Option[Set[UUID]]` fibers, `Option[Set[Address]]` wallets). Each field is OPTIONAL;
|
|
128
|
+
* an absent field ⇒ that recipient class is unconstrained (and is `dropNulls`-stripped).
|
|
129
|
+
*/
|
|
130
|
+
export interface TransferPolicy {
|
|
131
|
+
/** Fiber UUIDs permitted to receive a transfer. */
|
|
132
|
+
allowedRecipientFibers?: readonly string[];
|
|
133
|
+
/** DAG wallet addresses permitted to receive a transfer. */
|
|
134
|
+
allowedRecipientWallets?: readonly string[];
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* `dependencyPolicy` — dynamic-dependency posture. Chain: `DependencyPolicy`
|
|
138
|
+
* (`mode: DependencyMode`, `allowed: Option[Set[UUID]]`). `mode` is REQUIRED; `allowed`
|
|
139
|
+
* is meaningful only when `mode === 'ALLOWLIST'` and is `dropNulls`-stripped otherwise.
|
|
140
|
+
*/
|
|
141
|
+
export interface DependencyPolicy {
|
|
142
|
+
/** Posture: `OPEN` (any target) / `ALLOWLIST` (only `allowed`) / `FROZEN` (no new). */
|
|
143
|
+
mode: DependencyMode;
|
|
144
|
+
/** Fiber UUIDs permitted as dependency targets (meaningful only under `ALLOWLIST`). */
|
|
145
|
+
allowed?: readonly string[];
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* `migrationAuthority` — who may authorize a `Governed` migration. Chain:
|
|
149
|
+
* `MigrationAuthority`, a DISJOINT-FIELD discriminated union (no tag key): the `Signers`
|
|
150
|
+
* arm carries `addresses`, the `Role` arm carries `registryFiberId` + `roleField`. The
|
|
151
|
+
* presence of disjoint fields is the discriminator (same as the chain decoder's `.or`).
|
|
152
|
+
*/
|
|
153
|
+
export type MigrationAuthority = {
|
|
154
|
+
/** VERIFIED signer DAG addresses permitted to authorize the migration (`Signers`). */
|
|
155
|
+
addresses: readonly string[];
|
|
156
|
+
} | {
|
|
157
|
+
/** Registry fiber UUID whose role-map is consulted (`Role`). */
|
|
158
|
+
registryFiberId: string;
|
|
159
|
+
/** Field/key in that fiber's state holding the `{<address>: true}` role map (`Role`). */
|
|
160
|
+
roleField: string;
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* `upgradePolicy` — the upgrade-path constitution. Chain: `UpgradePolicy`. The three
|
|
164
|
+
* bare variants encode as LOWERCASE tag STRINGS (`"immutable"` / `"appendOnly"` /
|
|
165
|
+
* `"arbitrary"`); the `Governed` arm encodes as the object `{ authority: <MigrationAuthority> }`.
|
|
166
|
+
*
|
|
167
|
+
* NOTE: this lowercase `"immutable"` is the upgradePolicy DIAL VALUE — distinct from the
|
|
168
|
+
* policy-level variant tag `"Immutable"` (capital-I), a different construct added in a
|
|
169
|
+
* later change.
|
|
170
|
+
*/
|
|
171
|
+
export type UpgradePolicy = 'immutable' | 'appendOnly' | 'arbitrary' | {
|
|
172
|
+
/** Authority that may consent to a `Governed` migration. */
|
|
173
|
+
authority: MigrationAuthority;
|
|
174
|
+
};
|
|
175
|
+
/**
|
|
176
|
+
* `transitionPolicy` — WHO may drive a transition on this fiber. Chain: `TransitionPolicy`
|
|
177
|
+
* (chain PR #194), a bare tag STRING with three ranked levels:
|
|
178
|
+
*
|
|
179
|
+
* - `"Open"` — anyone may drive a transition; the transition's `guard` is the only gate.
|
|
180
|
+
* This is the chain DEFAULT when the dial is ABSENT, so omitting it is byte-identical
|
|
181
|
+
* to the legacy (pre-#194) behaviour.
|
|
182
|
+
* - `"OwnersOrParticipants"` — only the fiber's owners or its declared participants.
|
|
183
|
+
* - `"Owners"` — only the fiber's owners.
|
|
184
|
+
*
|
|
185
|
+
* Absent ⇒ `"Open"` (chain `transitionPolicy: Option[TransitionPolicy] = None`,
|
|
186
|
+
* `dropNulls`-stripped). The chain joins this to the tighten-only upgrade lattice, so an
|
|
187
|
+
* upgrade may only RAISE the level (`Open < OwnersOrParticipants < Owners`); LOOSENING it
|
|
188
|
+
* (including dropping the dial on a fiber that had it set) is rejected as `CombineRejected`.
|
|
189
|
+
*/
|
|
190
|
+
export type TransitionPolicy = 'Open' | 'OwnersOrParticipants' | 'Owners';
|
|
191
|
+
/**
|
|
192
|
+
* `compatibleWith` — the inclusive-min / exclusive-max SemVer bridge window a migration
|
|
193
|
+
* may target. Chain: `VersionRange` (`min: Option[SemVer]`, `max: Option[SemVer]`). Each
|
|
194
|
+
* bound is a SemVer STRING (`"1.2.3"`); an absent bound is unconstrained on that side and
|
|
195
|
+
* is `dropNulls`-stripped.
|
|
196
|
+
*/
|
|
197
|
+
export interface VersionRange {
|
|
198
|
+
/** Inclusive lower bound, e.g. `"1.0.0"` (absent ⇒ unconstrained below). */
|
|
199
|
+
min?: string;
|
|
200
|
+
/** Exclusive upper bound, e.g. `"2.0.0"` (absent ⇒ unconstrained above). */
|
|
201
|
+
max?: string;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* `FiberPolicy` — the constitution a definition declares for the fibers it spawns.
|
|
205
|
+
*
|
|
206
|
+
* This MIRRORS the chain ADT `FiberPolicy = Unconstrained | Immutable | Constrained(<dials>)`
|
|
207
|
+
* (chain branch `feat/fiber-policy-adt`). The representation here is chosen for
|
|
208
|
+
* BYTE-FOR-BYTE wire parity with the chain, because a `StateMachineDefinition` is
|
|
209
|
+
* signed verbatim by the SDK (`batchSign(dropNulls(...))`) and re-encoded + verified
|
|
210
|
+
* by the chain. The rule is:
|
|
211
|
+
*
|
|
212
|
+
* - **`Unconstrained`** ⇒ there is **NO `policy` key** on the wire definition at all.
|
|
213
|
+
* In the SDK this is the DEFAULT and is represented by simply OMITTING `policy`
|
|
214
|
+
* (i.e. `policy === undefined`).
|
|
215
|
+
* - **`Immutable`** ⇒ the definition is permanently locked; `policy` is the bare JSON
|
|
216
|
+
* STRING `"Immutable"` (EXACT casing, capital-I) — NOT an object. Semantically this is
|
|
217
|
+
* the upgradePolicy DIAL set to its LOWERCASE `"immutable"` value with no other dial
|
|
218
|
+
* set, and the chain collapses that exact `Constrained` into the `Immutable` variant.
|
|
219
|
+
* See {@link immutable} and the canonical collapse in {@link projectFiberPolicy}.
|
|
220
|
+
* - **`Constrained(dials)`** ⇒ `policy` is a bare object of ONLY the dials that are
|
|
221
|
+
* SET. Unset dials are absent (the chain `dropNulls`-strips them; so does the SDK
|
|
222
|
+
* at sign time). A `Constrained` with no dials set is wire-indistinguishable from
|
|
223
|
+
* `Unconstrained`, so `toProtoDefinition` collapses it back to "no policy key".
|
|
224
|
+
*
|
|
225
|
+
* All 15 dials are optional. Provide any subset.
|
|
226
|
+
*/
|
|
227
|
+
export interface FiberPolicyDials {
|
|
228
|
+
/** Whether the fiber may reproduce itself (spawn instances of its own definition). Wire: boolean. */
|
|
229
|
+
selfReproducing?: boolean;
|
|
230
|
+
/**
|
|
231
|
+
* Allow-list of effect families this fiber's transitions may produce, as a SET of the 5
|
|
232
|
+
* UPPERCASE {@link EffectKind} tokens (`"TRIGGER" | "SPAWN" | "EMIT" | "TRANSFER" |
|
|
233
|
+
* "DEPENDENCY"`). Order is not significant; duplicates are collapsed by the chain's `Set`.
|
|
234
|
+
* Chain: `allowedEffects: Option[Set[EffectKind]]`.
|
|
235
|
+
*/
|
|
236
|
+
allowedEffects?: readonly EffectKind[];
|
|
237
|
+
/**
|
|
238
|
+
* Who/what may own fibers this one spawns — an UPPERCASE {@link SpawnOwnerPolicy} token
|
|
239
|
+
* (`"EXPLICIT" | "SUBSETOFPARENT" | "INHERITPARENT"`). Chain: `spawnOwnerPolicy: Option[SpawnOwnerPolicy]`.
|
|
240
|
+
*/
|
|
241
|
+
spawnOwnerPolicy?: SpawnOwnerPolicy;
|
|
242
|
+
/** Maximum spawn-generation depth (descendant chain length). Wire: number. */
|
|
243
|
+
maxGenerations?: number;
|
|
244
|
+
/** Maximum number of children a single transition may spawn. Wire: number. */
|
|
245
|
+
maxSpawnFanout?: number;
|
|
246
|
+
/** SET of caller fiber UUIDs permitted to drive transitions on this fiber. Wire: string[]. */
|
|
247
|
+
acceptedCallers?: readonly string[];
|
|
248
|
+
/** SET of state ids that are sealed (no transition may fire from them). Wire: string[]. */
|
|
249
|
+
sealedStates?: readonly string[];
|
|
250
|
+
/**
|
|
251
|
+
* WHO may drive a transition on this fiber — a {@link TransitionPolicy} bare tag
|
|
252
|
+
* (`"Open" | "OwnersOrParticipants" | "Owners"`). Absent ⇒ `"Open"` (guard-only, the
|
|
253
|
+
* chain default); set `"Owners"`/`"OwnersOrParticipants"` to gate transitions by identity
|
|
254
|
+
* in ADDITION to the guard. Chain: `transitionPolicy: Option[TransitionPolicy]` (chain PR #194).
|
|
255
|
+
*/
|
|
256
|
+
transitionPolicy?: TransitionPolicy;
|
|
257
|
+
/**
|
|
258
|
+
* Recipient allowlist for `_transferAsset` — the {@link TransferPolicy} object
|
|
259
|
+
* `{ allowedRecipientFibers?: uuid[], allowedRecipientWallets?: DAG-address[] }`.
|
|
260
|
+
* Chain: `transferPolicy: Option[TransferPolicy]`.
|
|
261
|
+
*/
|
|
262
|
+
transferPolicy?: TransferPolicy;
|
|
263
|
+
/**
|
|
264
|
+
* Dynamic-dependency policy — the {@link DependencyPolicy} object `{ mode, allowed? }`
|
|
265
|
+
* where `mode` is the REQUIRED UPPERCASE {@link DependencyMode}. Chain:
|
|
266
|
+
* `dependencyPolicy: Option[DependencyPolicy]`.
|
|
267
|
+
*/
|
|
268
|
+
dependencyPolicy?: DependencyPolicy;
|
|
269
|
+
/**
|
|
270
|
+
* In-place upgrade/migration posture — an {@link UpgradePolicy}: a LOWERCASE bare tag
|
|
271
|
+
* (`"immutable" | "appendOnly" | "arbitrary"`) OR the `Governed` object
|
|
272
|
+
* `{ authority: <MigrationAuthority> }`. Chain: `upgradePolicy: Option[UpgradePolicy]`.
|
|
273
|
+
*/
|
|
274
|
+
upgradePolicy?: UpgradePolicy;
|
|
275
|
+
/** Self-declared SemVer of this definition as a STRING `"major.minor.patch"` (e.g. `"1.2.3"`). Chain: `version: Option[SemVer]`. */
|
|
276
|
+
version?: string;
|
|
277
|
+
/**
|
|
278
|
+
* Migration bridge window — the {@link VersionRange} object `{ min?: semver, max?: semver }`
|
|
279
|
+
* naming the successor versions this definition declares it will migrate TO. Chain:
|
|
280
|
+
* `compatibleWith: Option[VersionRange]`.
|
|
281
|
+
*/
|
|
282
|
+
compatibleWith?: VersionRange;
|
|
283
|
+
/** SET of (ERC-165-style) interface identifiers this definition advertises. Wire: string[]. */
|
|
284
|
+
interfaces?: readonly string[];
|
|
285
|
+
/**
|
|
286
|
+
* Authority permitted to authorize a `Governed` migration — a {@link MigrationAuthority}:
|
|
287
|
+
* `{ addresses: DAG-address[] }` (Signers) OR `{ registryFiberId: uuid, roleField: string }`
|
|
288
|
+
* (Role), discriminated by disjoint fields. Chain: `migrationAuthority: Option[MigrationAuthority]`.
|
|
289
|
+
*/
|
|
290
|
+
migrationAuthority?: MigrationAuthority;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* The wire (and authoring) tag for the `Immutable` policy VARIANT: the bare JSON string
|
|
294
|
+
* `"Immutable"`. EXACT casing, capital-I — this is the POLICY-LEVEL variant name and is
|
|
295
|
+
* DISTINCT from the `upgradePolicy` dial VALUE `"immutable"` (lowercase). The chain emits
|
|
296
|
+
* exactly this capital-I string for `Immutable`, so the SDK must too, byte-for-byte.
|
|
297
|
+
*/
|
|
298
|
+
export declare const IMMUTABLE_POLICY: "Immutable";
|
|
299
|
+
export type ImmutablePolicy = typeof IMMUTABLE_POLICY;
|
|
300
|
+
/**
|
|
301
|
+
* Wire form of a `FiberPolicy`. Mirrors the chain ADT's non-`Unconstrained` arms:
|
|
302
|
+
*
|
|
303
|
+
* - a bare object of the SET dials — the `Constrained` arm. Unset dials are stripped at
|
|
304
|
+
* projection time (and again by `dropNulls` at sign time), so this object matches the
|
|
305
|
+
* chain's `dropNulls`-stripped `Constrained` encoding exactly; OR
|
|
306
|
+
* - the bare JSON string `"Immutable"` — the {@link ImmutablePolicy} arm.
|
|
307
|
+
*
|
|
308
|
+
* (`Unconstrained` has no wire representation: it is the absence of the `policy` key.)
|
|
309
|
+
*/
|
|
310
|
+
export type FiberPolicy = FiberPolicyDials | ImmutablePolicy;
|
|
311
|
+
/**
|
|
312
|
+
* The canonical UNCONSTRAINED policy: omission. Provided as a named export for
|
|
313
|
+
* readability at call sites — `policy: unconstrained()` documents intent, and projects
|
|
314
|
+
* to NO `policy` key (identical to leaving `policy` off entirely).
|
|
315
|
+
*/
|
|
316
|
+
export declare function unconstrained(): undefined;
|
|
317
|
+
/**
|
|
318
|
+
* The canonical IMMUTABLE policy: the definition is permanently locked. Projects to the
|
|
319
|
+
* bare JSON string `"Immutable"` ({@link IMMUTABLE_POLICY}), the chain's `Immutable`
|
|
320
|
+
* variant tag. Semantically equivalent to `constrained({ upgradePolicy: 'immutable' })`
|
|
321
|
+
* with no other dial set — which `constrained()`/`projectFiberPolicy()` collapse to the
|
|
322
|
+
* same string for wire parity (see {@link constrained}).
|
|
323
|
+
*
|
|
324
|
+
* @example
|
|
325
|
+
* ```ts
|
|
326
|
+
* const def = defineFiberApp({ ...spec, policy: immutable() });
|
|
327
|
+
* ```
|
|
328
|
+
*/
|
|
329
|
+
export declare function immutable(): ImmutablePolicy;
|
|
330
|
+
/**
|
|
331
|
+
* Build a CONSTRAINED `FiberPolicy` from any subset of the 15 dials.
|
|
332
|
+
*
|
|
333
|
+
* Pass only the dials you want to set. Dials left `undefined`/`null` are dropped so the
|
|
334
|
+
* result is a clean, minimal object that serializes identically to the chain's
|
|
335
|
+
* `dropNulls`-stripped `Constrained`. If NO dial is effectively set, this returns
|
|
336
|
+
* `undefined` (an empty constraint == `Unconstrained`), which projects to no `policy`
|
|
337
|
+
* key — preserving wire parity.
|
|
338
|
+
*
|
|
339
|
+
* CANONICAL COLLAPSE: `constrained({ upgradePolicy: 'immutable' })` with NO other dial set
|
|
340
|
+
* collapses to the bare string `"Immutable"` ({@link IMMUTABLE_POLICY}), because the chain
|
|
341
|
+
* collapses that exact `Constrained` into the `Immutable` variant. NOTE the casing: the
|
|
342
|
+
* collapse triggers on the chain's LOWERCASE upgradePolicy dial value `"immutable"`, and
|
|
343
|
+
* the result is the capital-I policy-variant tag `"Immutable"`. Signing the dials object
|
|
344
|
+
* `{ "upgradePolicy": "immutable" }` instead would diverge the canonical (the chain
|
|
345
|
+
* re-encodes it as `"Immutable"`) and break the create signature. Adding ANY other dial
|
|
346
|
+
* keeps it a dials object.
|
|
347
|
+
*
|
|
348
|
+
* @example
|
|
349
|
+
* ```ts
|
|
350
|
+
* const policy = constrained({
|
|
351
|
+
* selfReproducing: false,
|
|
352
|
+
* maxGenerations: 3,
|
|
353
|
+
* allowedEffects: ['EMIT', 'TRANSFER'],
|
|
354
|
+
* sealedStates: ['ARCHIVED'],
|
|
355
|
+
* });
|
|
356
|
+
* ```
|
|
357
|
+
*/
|
|
358
|
+
export declare function constrained(dials: FiberPolicyDials): FiberPolicy | undefined;
|
|
359
|
+
/**
|
|
360
|
+
* Project an authoring `policy` value onto the wire form. Returns one of:
|
|
361
|
+
* - `undefined` when the policy is (effectively) `Unconstrained` — i.e. omit the `policy`
|
|
362
|
+
* key entirely;
|
|
363
|
+
* - the bare string `"Immutable"` ({@link IMMUTABLE_POLICY}) for the `Immutable` variant
|
|
364
|
+
* (also the collapse of a lone LOWERCASE `upgradePolicy: 'immutable'`); or
|
|
365
|
+
* - the minimal `Constrained` dials object otherwise.
|
|
366
|
+
*
|
|
367
|
+
* Centralizes the omit-on-unconstrained AND the Immutable-collapse parity rules so every
|
|
368
|
+
* projection path (`toProtoDefinition`, the genesis manifest) stays consistent.
|
|
369
|
+
*/
|
|
370
|
+
export declare function projectFiberPolicy(policy: FiberPolicy | undefined): FiberPolicy | undefined;
|
|
108
371
|
export interface FiberAppMetadata {
|
|
109
372
|
name: string;
|
|
110
373
|
app: string;
|
|
@@ -125,6 +388,16 @@ export interface CrossReferences {
|
|
|
125
388
|
}
|
|
126
389
|
export interface FiberAppDefinition<TState extends string = string, TEvent extends string = string> {
|
|
127
390
|
metadata: FiberAppMetadata;
|
|
391
|
+
/**
|
|
392
|
+
* Fiber constitution. Mirrors the chain ADT `FiberPolicy = Unconstrained | Immutable |
|
|
393
|
+
* Constrained(<dials>)`. OMIT this field (the default) for `Unconstrained` — the projected
|
|
394
|
+
* wire definition then has NO `policy` key. Set it to `immutable()` to permanently lock the
|
|
395
|
+
* definition (projects to the bare string `"Immutable"`). Set it to a `constrained({...})`
|
|
396
|
+
* object to declare a subset of the 15 dials; unset dials are stripped so the wire form
|
|
397
|
+
* matches the chain's `dropNulls`-stripped `Constrained` byte-for-byte (and a lone
|
|
398
|
+
* `upgradePolicy: 'immutable'` collapses to `"Immutable"`).
|
|
399
|
+
*/
|
|
400
|
+
policy?: FiberPolicy;
|
|
128
401
|
/** Schema for fiber creation inputs (user-provided) */
|
|
129
402
|
createSchema?: {
|
|
130
403
|
required?: readonly string[];
|
|
@@ -195,6 +468,14 @@ export interface ProtoStateMachineDefinition {
|
|
|
195
468
|
dependencies: string[];
|
|
196
469
|
}>;
|
|
197
470
|
metadata?: Record<string, unknown>;
|
|
471
|
+
/**
|
|
472
|
+
* Fiber constitution. PRESENT for `Constrained` (a bare object of the SET dials) and for
|
|
473
|
+
* `Immutable` (the bare string `"Immutable"`); ABSENT for `Unconstrained`. This
|
|
474
|
+
* omit-on-unconstrained rule is the wire parity contract: the chain emits no `policy` key
|
|
475
|
+
* for `Unconstrained`, so neither may the SDK, or the signature breaks (HTTP 400). See
|
|
476
|
+
* {@link projectFiberPolicy}.
|
|
477
|
+
*/
|
|
478
|
+
policy?: FiberPolicy;
|
|
198
479
|
}
|
|
199
480
|
/**
|
|
200
481
|
* Extract proto-compatible StateMachineDefinition from a FiberAppDefinition.
|
|
@@ -131,4 +131,16 @@ export declare const signerHasRoleVia: (registryIdVar: string, roleField: string
|
|
|
131
131
|
* so a single gated transition is split into a bind step then this assert step. See
|
|
132
132
|
* docs/design/app-hardening-identity-integration.md §5–§6.
|
|
133
133
|
*/
|
|
134
|
+
/**
|
|
135
|
+
* EFFECT-KEY-BINDING dedup over an ARRAY of records: no existing element of the array at `arrayVar`
|
|
136
|
+
* (e.g. `"state.submissions"`, shaped `[ { addr, value }, … ]`) has its `field` (default `"addr"`)
|
|
137
|
+
* equal to the actor at `actorVar` (default `"event.agent"`). The array analog of the map-keyed
|
|
138
|
+
* `{"!":[has(...)]}` dedup — used where the collection is an append-only array of `{addr,…}` records
|
|
139
|
+
* (there is no `(array,string)` key check, but `none` over the array with a per-element `===` is total).
|
|
140
|
+
*
|
|
141
|
+
* The bare-element callback context inside `none` sees each record map directly, so `{get:[{var:""},field]}`
|
|
142
|
+
* is a valid `(map,string)` read. Pair with an `actorIsSigner`/`actorHasEntry` clause on the same
|
|
143
|
+
* `actorVar` (the dedup proves "not yet present", not "is the verified signer").
|
|
144
|
+
*/
|
|
145
|
+
export declare const actorNotInArray: (arrayVar: string, field?: string, actorVar?: string) => GuardRule;
|
|
134
146
|
export declare const depInState: (refVar: string, requiredState: string) => GuardRule;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asset-policy preset builders (§1.1 of the SDK std-lib/templates handoff).
|
|
3
|
+
*
|
|
4
|
+
* Each builder is a PURE function that emits the exact {@link CreateAssetPolicy} wire body the chain
|
|
5
|
+
* re-derives — no `Date.now()`/`Math.random()`/`crypto.randomUUID()`; fixed inputs → fixed output. The
|
|
6
|
+
* on-chain policy `schemaHash` and `logicHash` are both `RegistryShape.AssetPolicy.computeDigest` over
|
|
7
|
+
* `behavior`/`supply`/`morphisms`/`stateShape` (no JSON-Logic body), so these presets are pure data.
|
|
8
|
+
*
|
|
9
|
+
* Hard invariants (CLAUDE.md rule #1 — the signed canonical is frozen):
|
|
10
|
+
* - `behavior` is ALWAYS summed from {@link TOKEN_BEHAVIOR_BITS} (T=16, S=8, C=4, E=2, G=1), never a
|
|
11
|
+
* magic literal int.
|
|
12
|
+
* - `morphisms` is REQUIRED on the wire (presence required, emptiness meaningful) — emit `{}` when empty,
|
|
13
|
+
* NEVER omit it.
|
|
14
|
+
* - `supply` is REQUIRED — emit `{}` when there is no supply authority, never omit it.
|
|
15
|
+
* - Absent optionals are OMITTED, never emitted as `null`/`undefined` (the chain signs over
|
|
16
|
+
* `JCS(dropNulls(payload))`).
|
|
17
|
+
*
|
|
18
|
+
* @see src/ottochain/types.ts — CreateAssetPolicy, SupplyPolicy, MorphismSpec, MorphismKind, TOKEN_BEHAVIOR_BITS
|
|
19
|
+
*/
|
|
20
|
+
import { TOKEN_BEHAVIOR_BITS, type CreateAssetPolicy, type JsonLogicExpression, type MorphismKind, type MorphismSpec, type SupplyPolicy } from '../ottochain/types.js';
|
|
21
|
+
/** A behavior-bit NAME (a key of {@link TOKEN_BEHAVIOR_BITS}) — the only legal way to spell `behavior`. */
|
|
22
|
+
export type BehaviorBitName = keyof typeof TOKEN_BEHAVIOR_BITS;
|
|
23
|
+
/** Sum behavior bits from their NAMES — never a magic literal int (CLAUDE.md #1). */
|
|
24
|
+
export declare function sumBehavior(bits: readonly BehaviorBitName[]): number;
|
|
25
|
+
/**
|
|
26
|
+
* Derive the default `stateShape.typeName`: strip a trailing `.asset` label, PascalCase the remainder
|
|
27
|
+
* (splitting on `.`/`-`/`_`/space), then append `State`.
|
|
28
|
+
* `rvd.asset` → `RvdState`, `goods.asset` → `GoodsState`, `capped.asset` → `CappedState`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function defaultStateTypeName(name: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* Fungible currency. Behavior `T|S|C = 28` (transferable + splittable + combinable). Standard morphism
|
|
33
|
+
* set TRANSFER + FRACTIONALIZE + STAKE (`stakeable`, default true) + BURN (when `burnable`), all PUBLIC.
|
|
34
|
+
*
|
|
35
|
+
* Reproduces `riverdale-economy/rvd-policy.json` exactly via
|
|
36
|
+
* `fungiblePolicy({ name: 'rvd.asset', version: '1.0.0', mintable: true, burnable: true })`.
|
|
37
|
+
*/
|
|
38
|
+
export declare function fungiblePolicy(p: {
|
|
39
|
+
/** Registry name; conventionally ends `.asset`. */
|
|
40
|
+
name: string;
|
|
41
|
+
/** SemVer string. */
|
|
42
|
+
version: string;
|
|
43
|
+
/** `supply.decimals` — fractional precision; omit for whole-unit. */
|
|
44
|
+
decimals?: number;
|
|
45
|
+
/** `supply.maxSupply` — omit ⇒ uncapped. */
|
|
46
|
+
maxSupply?: number;
|
|
47
|
+
/** true ⇒ `supply.mintPolicy = {"==":[1,1]}` (open mint). */
|
|
48
|
+
mintable?: boolean;
|
|
49
|
+
/** true ⇒ `supply.burnPolicy = {"==":[1,1]}` AND a BURN morphism. */
|
|
50
|
+
burnable?: boolean;
|
|
51
|
+
/** JSON-Logic predicate that OVERRIDES `mintable`'s default mint guard (and enables minting). */
|
|
52
|
+
mintGuard?: JsonLogicExpression;
|
|
53
|
+
/** default true ⇒ a STAKE morphism. */
|
|
54
|
+
stakeable?: boolean;
|
|
55
|
+
/** `stateShape.typeName`; default `${PascalCase(name-without-.asset)}State`. */
|
|
56
|
+
stateTypeName?: string;
|
|
57
|
+
/** Off-chain links grab-bag; omitted when absent. */
|
|
58
|
+
metadata?: Record<string, string>;
|
|
59
|
+
}): CreateAssetPolicy;
|
|
60
|
+
/**
|
|
61
|
+
* Non-fungible token. Behavior `T = 16`, or `T|C = 20` with `combinable: true` (the riverdale
|
|
62
|
+
* `goods.asset`); `transferable: false` drops the T bit (a bound collectible). `morphisms` is `{}` by
|
|
63
|
+
* default (emitted explicitly, never omitted). Mintable by default ⇒ `supply.mintPolicy = {"==":[1,1]}`.
|
|
64
|
+
*
|
|
65
|
+
* Reproduces `riverdale-economy/goods-policy.json` exactly via
|
|
66
|
+
* `nftPolicy({ name: 'goods.asset', version: '1.0.0', combinable: true })`.
|
|
67
|
+
*/
|
|
68
|
+
export declare function nftPolicy(p: {
|
|
69
|
+
name: string;
|
|
70
|
+
version: string;
|
|
71
|
+
/** `T(16)` → `T|C(20)`. */
|
|
72
|
+
combinable?: boolean;
|
|
73
|
+
/** default true; false ⇒ drop the T bit (bound collectible: `0`, or `4` with `combinable`). */
|
|
74
|
+
transferable?: boolean;
|
|
75
|
+
/** default true ⇒ `supply.mintPolicy = {"==":[1,1]}`. */
|
|
76
|
+
mintable?: boolean;
|
|
77
|
+
/** JSON-Logic predicate that OVERRIDES the default mint guard. */
|
|
78
|
+
mintGuard?: JsonLogicExpression;
|
|
79
|
+
/** `supply.maxSupply` — omit ⇒ uncapped edition. */
|
|
80
|
+
maxSupply?: number;
|
|
81
|
+
/** `stateShape.typeName`; default `${PascalCase(name-without-.asset)}State`. */
|
|
82
|
+
stateTypeName?: string;
|
|
83
|
+
metadata?: Record<string, string>;
|
|
84
|
+
}): CreateAssetPolicy;
|
|
85
|
+
/**
|
|
86
|
+
* Soulbound token: non-transferable, governable only (`G = 1`; `+E = 3` when `expirable`). No TRANSFER
|
|
87
|
+
* morphism (`morphisms: {}`); minting is closed after issue (empty `supply`).
|
|
88
|
+
*/
|
|
89
|
+
export declare function soulboundPolicy(p: {
|
|
90
|
+
name: string;
|
|
91
|
+
version: string;
|
|
92
|
+
/** `+E(2)` ⇒ behavior `3`. */
|
|
93
|
+
expirable?: boolean;
|
|
94
|
+
/** `stateShape.typeName`; default `${PascalCase(name-without-.asset)}State`. */
|
|
95
|
+
stateTypeName?: string;
|
|
96
|
+
metadata?: Record<string, string>;
|
|
97
|
+
}): CreateAssetPolicy;
|
|
98
|
+
/**
|
|
99
|
+
* Escape hatch: declare `behavior` by NAME (summed from {@link TOKEN_BEHAVIOR_BITS}, never a magic int)
|
|
100
|
+
* and pass `supply` + `morphisms` through raw. Use when no preset fits.
|
|
101
|
+
*
|
|
102
|
+
* Reproduces `riverdale-economy/capped-policy.json` exactly via
|
|
103
|
+
* `customPolicy({ name: 'capped.asset', version: '1.0.0',
|
|
104
|
+
* behavior: ['transferable', 'splittable', 'combinable'],
|
|
105
|
+
* supply: { maxSupply: 100, mintPolicy: { '==': [1, 1] } }, morphisms: {} })`.
|
|
106
|
+
*/
|
|
107
|
+
export declare function customPolicy(p: {
|
|
108
|
+
name: string;
|
|
109
|
+
version: string;
|
|
110
|
+
/** Behavior-bit NAMES summed to the int (e.g. `['transferable','combinable']` ⇒ 20). Never a literal. */
|
|
111
|
+
behavior: readonly BehaviorBitName[];
|
|
112
|
+
/** Raw supply authority, passed through verbatim. */
|
|
113
|
+
supply: SupplyPolicy;
|
|
114
|
+
/** Raw morphism map, passed through verbatim (emit `{}` when empty, never omit). */
|
|
115
|
+
morphisms: Partial<Record<MorphismKind, MorphismSpec>>;
|
|
116
|
+
/** `stateShape.typeName`; default `${PascalCase(name-without-.asset)}State`. */
|
|
117
|
+
stateTypeName?: string;
|
|
118
|
+
metadata?: Record<string, string>;
|
|
119
|
+
}): CreateAssetPolicy;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@ottochain/sdk/templates` — the fiber & asset authoring template catalog.
|
|
3
|
+
*
|
|
4
|
+
* Typed builders that emit the EXACT canonical wire shapes app authors otherwise hand-roll as raw
|
|
5
|
+
* JSON-Logic (asset policies, versioned machines, effect directives, migrations, seeded state). Every
|
|
6
|
+
* builder is additive and pure — it returns the same wire shape the chain re-derives, so a template
|
|
7
|
+
* output signs to byte-identical `JCS(dropNulls(payload))` (CLAUDE.md rule #1). Hand-rolled JSON keeps
|
|
8
|
+
* working; these just make the recurring shapes typed, named, and mistake-resistant.
|
|
9
|
+
*
|
|
10
|
+
* Origin: the fiber-ergonomics program (ottochain `docs/proposals/fiber-ergonomics/`), Phase A — the
|
|
11
|
+
* `riverdale-economy` e2e is the migration proof (each preset reproduces its checked-in golden JSON).
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import {
|
|
15
|
+
* fungiblePolicy, machine, transition, effect, guard,
|
|
16
|
+
* transferAsset, triggers, spawn, seedState, seedFields,
|
|
17
|
+
* } from '@ottochain/sdk/templates';
|
|
18
|
+
*/
|
|
19
|
+
export * from './asset-policy.js';
|
|
20
|
+
export * from './machine.js';
|
|
21
|
+
export * from './migration.js';
|
|
22
|
+
export * from './state-shape.js';
|
|
23
|
+
export * from '../schema/effects.js';
|
|
24
|
+
export * as guard from '../schema/guards.js';
|
|
25
|
+
export { defineFiberApp, toProtoDefinition, constrained, unconstrained, immutable, projectFiberPolicy, } from '../schema/fiber-app.js';
|
|
26
|
+
export type { FiberAppDefinition, Transition, ProtoStateMachineDefinition, FiberPolicy, FiberPolicyDials, } from '../schema/fiber-app.js';
|