@ottochain/sdk 2.2.4 → 2.3.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 (85) hide show
  1. package/dist/cjs/apps/contracts/state-machines/contract-agreement.js +54 -6
  2. package/dist/cjs/apps/contracts/state-machines/contract-escrow.js +72 -8
  3. package/dist/cjs/apps/contracts/state-machines/contract-universal.js +36 -4
  4. package/dist/cjs/apps/governance/state-machines/dao-multisig.js +27 -3
  5. package/dist/cjs/apps/governance/state-machines/dao-reputation.js +27 -3
  6. package/dist/cjs/apps/governance/state-machines/dao-single.js +27 -3
  7. package/dist/cjs/apps/governance/state-machines/dao-token.js +36 -4
  8. package/dist/cjs/apps/governance/state-machines/governance-simple.js +36 -4
  9. package/dist/cjs/apps/governance/state-machines/governance-universal.js +27 -3
  10. package/dist/cjs/apps/identity/state-machines/identity-agent.js +54 -6
  11. package/dist/cjs/apps/identity/state-machines/identity-oracle.js +45 -5
  12. package/dist/cjs/apps/identity/state-machines/identity-universal.js +27 -3
  13. package/dist/cjs/apps/markets/state-machines/market-auction.js +30 -6
  14. package/dist/cjs/apps/markets/state-machines/market-crowdfund.js +25 -5
  15. package/dist/cjs/apps/markets/state-machines/market-group-buy.js +29 -5
  16. package/dist/cjs/apps/markets/state-machines/market-prediction.js +40 -8
  17. package/dist/cjs/apps/markets/state-machines/market-universal.js +45 -5
  18. package/dist/cjs/generated/ottochain/v1/common.js +1722 -1
  19. package/dist/cjs/generated/ottochain/v1/fiber.js +352 -2
  20. package/dist/cjs/generated/ottochain/v1/messages.js +775 -3
  21. package/dist/cjs/generated/ottochain/v1/records.js +350 -3
  22. package/dist/cjs/index.js +5 -1
  23. package/dist/cjs/ottochain/genesis-manifest.js +193 -0
  24. package/dist/cjs/ottochain/index.js +5 -1
  25. package/dist/cjs/ottochain/normalize.js +26 -48
  26. package/dist/cjs/ottochain/types.js +4 -0
  27. package/dist/esm/apps/contracts/state-machines/contract-agreement.js +54 -6
  28. package/dist/esm/apps/contracts/state-machines/contract-escrow.js +72 -8
  29. package/dist/esm/apps/contracts/state-machines/contract-universal.js +36 -4
  30. package/dist/esm/apps/governance/state-machines/dao-multisig.js +27 -3
  31. package/dist/esm/apps/governance/state-machines/dao-reputation.js +27 -3
  32. package/dist/esm/apps/governance/state-machines/dao-single.js +27 -3
  33. package/dist/esm/apps/governance/state-machines/dao-token.js +36 -4
  34. package/dist/esm/apps/governance/state-machines/governance-simple.js +36 -4
  35. package/dist/esm/apps/governance/state-machines/governance-universal.js +27 -3
  36. package/dist/esm/apps/identity/state-machines/identity-agent.js +54 -6
  37. package/dist/esm/apps/identity/state-machines/identity-oracle.js +45 -5
  38. package/dist/esm/apps/identity/state-machines/identity-universal.js +27 -3
  39. package/dist/esm/apps/markets/state-machines/market-auction.js +30 -6
  40. package/dist/esm/apps/markets/state-machines/market-crowdfund.js +25 -5
  41. package/dist/esm/apps/markets/state-machines/market-group-buy.js +29 -5
  42. package/dist/esm/apps/markets/state-machines/market-prediction.js +40 -8
  43. package/dist/esm/apps/markets/state-machines/market-universal.js +45 -5
  44. package/dist/esm/generated/ottochain/v1/common.js +1718 -0
  45. package/dist/esm/generated/ottochain/v1/fiber.js +351 -1
  46. package/dist/esm/generated/ottochain/v1/messages.js +774 -2
  47. package/dist/esm/generated/ottochain/v1/records.js +349 -2
  48. package/dist/esm/index.js +2 -0
  49. package/dist/esm/ottochain/genesis-manifest.js +189 -0
  50. package/dist/esm/ottochain/index.js +2 -0
  51. package/dist/esm/ottochain/normalize.js +26 -48
  52. package/dist/esm/ottochain/types.js +4 -0
  53. package/dist/types/apps/contracts/index.d.ts +90 -18
  54. package/dist/types/apps/contracts/state-machines/contract-agreement.d.ts +30 -6
  55. package/dist/types/apps/contracts/state-machines/contract-escrow.d.ts +40 -8
  56. package/dist/types/apps/contracts/state-machines/contract-universal.d.ts +20 -4
  57. package/dist/types/apps/governance/index.d.ts +114 -33
  58. package/dist/types/apps/governance/state-machines/dao-multisig.d.ts +15 -3
  59. package/dist/types/apps/governance/state-machines/dao-reputation.d.ts +15 -3
  60. package/dist/types/apps/governance/state-machines/dao-single.d.ts +15 -3
  61. package/dist/types/apps/governance/state-machines/dao-token.d.ts +20 -4
  62. package/dist/types/apps/governance/state-machines/governance-simple.d.ts +20 -4
  63. package/dist/types/apps/governance/state-machines/governance-universal.d.ts +15 -3
  64. package/dist/types/apps/identity/index.d.ts +71 -6
  65. package/dist/types/apps/identity/state-machines/identity-agent.d.ts +30 -0
  66. package/dist/types/apps/identity/state-machines/identity-oracle.d.ts +25 -0
  67. package/dist/types/apps/identity/state-machines/identity-universal.d.ts +15 -0
  68. package/dist/types/apps/markets/index.d.ts +80 -5
  69. package/dist/types/apps/markets/state-machines/market-auction.d.ts +12 -0
  70. package/dist/types/apps/markets/state-machines/market-crowdfund.d.ts +10 -0
  71. package/dist/types/apps/markets/state-machines/market-group-buy.d.ts +14 -0
  72. package/dist/types/apps/markets/state-machines/market-prediction.d.ts +16 -0
  73. package/dist/types/apps/markets/state-machines/market-universal.d.ts +25 -5
  74. package/dist/types/generated/ottochain/v1/common.d.ts +228 -0
  75. package/dist/types/generated/ottochain/v1/fiber.d.ts +32 -1
  76. package/dist/types/generated/ottochain/v1/messages.d.ts +84 -0
  77. package/dist/types/generated/ottochain/v1/records.d.ts +34 -0
  78. package/dist/types/index.d.ts +3 -1
  79. package/dist/types/ottochain/genesis-manifest.d.ts +130 -0
  80. package/dist/types/ottochain/index.d.ts +3 -1
  81. package/dist/types/ottochain/normalize.d.ts +17 -25
  82. package/dist/types/ottochain/types.d.ts +288 -2
  83. package/dist/types/schema/fiber-app.d.ts +40 -1
  84. package/dist/types/validation.d.ts +17 -17
  85. package/package.json +30 -27
@@ -0,0 +1,193 @@
1
+ "use strict";
2
+ /**
3
+ * Genesis Manifest Exporter
4
+ *
5
+ * The ottochain metagraph can boot from a NON-EMPTY genesis: a set of standard
6
+ * packages pre-registered in the registry before any user transaction. This SDK
7
+ * is the source of truth for those std apps (their proto schemas + JSON-Logic
8
+ * state-machine definitions), so it is also the source of truth for the
9
+ * *genesis manifest* — the per-app CONTENT the chain needs to pre-register each
10
+ * package at genesis.
11
+ *
12
+ * DESIGN — content, not consensus hashes:
13
+ * The manifest ships CONTENT only: the `schemaShape` (the typed, proto-faithful
14
+ * projection of the app's state message) and the `definition` (the JSON-Logic
15
+ * `StateMachineDefinition`, verbatim — the same object the chain decodes for any
16
+ * fiber). The CHAIN computes the consensus values itself from this content:
17
+ * - `logicHash` = `StateMachineDefinition.computeDigest(definition)`
18
+ * - `schemaHash` = commitment over the FileDescriptorSet (off-chain/Bridge)
19
+ * We deliberately do NOT replicate the chain's canonical hashing here, so there
20
+ * is ZERO hash-parity risk. No advisory hashes are emitted (see HONESTY notes in
21
+ * the PR description); add them later only if an off-chain consumer needs them,
22
+ * clearly marked advisory.
23
+ *
24
+ * NAMING — the reserved `std` label:
25
+ * Each package is named `std.<app>.package`. `RegistryName` reserves the `std`
26
+ * label in-protocol (`RegistryName.isReserved`), so ordinary user registrations
27
+ * of `std.*` are rejected — only the privileged genesis path may claim them.
28
+ * That is exactly the point: users cannot squat the standard names.
29
+ *
30
+ * SCHEMA SHAPES — chain-verified ground truth:
31
+ * The three `stateMessage` shapes are reproduced verbatim from the chain's own
32
+ * conformance suite (`StandardAppsConformanceSuite`, the `identity` / `proposal`
33
+ * / `market` `MessageShape` vals), which proves the on-chain shape validator and
34
+ * the conformance gate accept them. `commands` is left EMPTY for this first cut —
35
+ * the conformance suite itself models all three apps with `SortedMap.empty`
36
+ * commands, and the proto `*Request` messages are transaction-layer DTOs that do
37
+ * not map cleanly onto the universal state machines' free-form JSON-Logic event
38
+ * payloads. Deriving per-event command shapes is a flagged follow-up.
39
+ *
40
+ * The JSON shape emitted here is built to deserialize against the chain's circe
41
+ * codecs (`SchemaShape` / `FieldShape` / `MessageShape` and
42
+ * `StateMachineDefinition`), whose magnolia config is camelCase with defaults.
43
+ *
44
+ * @packageDocumentation
45
+ */
46
+ Object.defineProperty(exports, "__esModule", { value: true });
47
+ exports.buildGenesisManifest = exports.GENESIS_MANIFEST_VERSION = void 0;
48
+ const identity_universal_js_1 = require("../apps/identity/state-machines/identity-universal.js");
49
+ const governance_universal_js_1 = require("../apps/governance/state-machines/governance-universal.js");
50
+ const market_universal_js_1 = require("../apps/markets/state-machines/market-universal.js");
51
+ const fiber_app_js_1 = require("../schema/fiber-app.js");
52
+ /** Manifest schema version. Bump on any breaking change to the shape. */
53
+ exports.GENESIS_MANIFEST_VERSION = 1;
54
+ // ─── Chain-verified state-message shapes ──────────────────────────────────────
55
+ // Reproduced VERBATIM from ottochain
56
+ // modules/shared-data/.../StandardAppsConformanceSuite.scala — the `identity`,
57
+ // `proposal`, and `market` MessageShape vals. Keep these byte-for-byte in step
58
+ // with that suite; it is what guarantees the chain accepts them.
59
+ /** Helper: a FieldShape with the two boolean defaults made explicit. */
60
+ function field(name, number, typeName, repeated = false, optional = false) {
61
+ return { name, number, typeName, repeated, optional };
62
+ }
63
+ /** ottochain.apps.identity.v1.Identity */
64
+ const identityStateMessage = {
65
+ typeName: 'ottochain.apps.identity.v1.Identity',
66
+ fields: [
67
+ field('id', 1, 'string'),
68
+ field('address', 2, 'string'),
69
+ field('public_key', 3, 'string'),
70
+ field('display_name', 4, 'string'),
71
+ field('identity_type', 5, 'ottochain.apps.identity.v1.IdentityType'),
72
+ field('state', 6, 'ottochain.apps.identity.v1.IdentityState'),
73
+ field('reputation', 7, 'ottochain.apps.identity.v1.Reputation'),
74
+ field('stake', 8, 'int64'),
75
+ field('domains', 9, 'string', true),
76
+ field('platform_links', 10, 'ottochain.apps.identity.v1.PlatformLink', true),
77
+ field('penalty_history', 11, 'ottochain.apps.identity.v1.PenaltyEvent', true),
78
+ field('created_at', 12, 'google.protobuf.Timestamp'),
79
+ field('updated_at', 13, 'google.protobuf.Timestamp'),
80
+ ],
81
+ };
82
+ /** ottochain.apps.governance.v1.Proposal */
83
+ const governanceStateMessage = {
84
+ typeName: 'ottochain.apps.governance.v1.Proposal',
85
+ fields: [
86
+ field('id', 1, 'string'),
87
+ field('title', 2, 'string'),
88
+ field('description', 3, 'string'),
89
+ field('action_type', 4, 'string'),
90
+ field('payload', 5, 'google.protobuf.Struct'),
91
+ field('proposer', 6, 'string'),
92
+ field('proposed_at', 7, 'google.protobuf.Timestamp'),
93
+ field('deadline', 8, 'google.protobuf.Timestamp'),
94
+ field('queued_at', 9, 'google.protobuf.Timestamp'),
95
+ field('executable_at', 10, 'google.protobuf.Timestamp'),
96
+ ],
97
+ };
98
+ /** ottochain.apps.markets.v1.Market */
99
+ const marketStateMessage = {
100
+ typeName: 'ottochain.apps.markets.v1.Market',
101
+ fields: [
102
+ field('id', 1, 'string'),
103
+ field('market_type', 2, 'ottochain.apps.markets.v1.MarketType'),
104
+ field('creator', 3, 'string'),
105
+ field('title', 4, 'string'),
106
+ field('terms', 5, 'google.protobuf.Struct'),
107
+ field('deadline', 6, 'google.protobuf.Timestamp'),
108
+ field('threshold', 7, 'int64'),
109
+ field('commitments', 8, 'ottochain.apps.markets.v1.Commitment', true),
110
+ field('oracles', 9, 'string', true),
111
+ field('quorum', 10, 'int32'),
112
+ field('resolutions', 11, 'ottochain.apps.markets.v1.Resolution', true),
113
+ field('status', 12, 'ottochain.apps.markets.v1.MarketState'),
114
+ field('created_at', 13, 'google.protobuf.Timestamp'),
115
+ field('updated_at', 14, 'google.protobuf.Timestamp'),
116
+ ],
117
+ };
118
+ // ─── Definition projection (single source of truth = the exported defs) ───────
119
+ /**
120
+ * Project a `FiberAppDefinition` into the chain's wire `StateMachineDefinition`,
121
+ * matching the `json-archive/*.json` convention exactly:
122
+ * - states carry explicit `metadata: null`,
123
+ * - transitions carry explicit `dependencies: []`,
124
+ * - the TypeScript-only `FiberAppMetadata` is stripped (`metadata: null`).
125
+ *
126
+ * Built on the shared `toProtoDefinition` projector so the manifest never drifts
127
+ * from the SDK's own exported app definitions. The chain decodes `dependencies:
128
+ * []` / `metadata: null` identically to their absent forms (its codecs use
129
+ * defaults), so this is consensus-equivalent to the archives while staying
130
+ * byte-identical to the checked-in `json-archive/*.json` files.
131
+ */
132
+ function toWireDefinition(def) {
133
+ const proto = (0, fiber_app_js_1.toProtoDefinition)(def);
134
+ const states = {};
135
+ for (const [key, st] of Object.entries(proto.states)) {
136
+ states[key] = { id: st.id, isFinal: st.isFinal, metadata: null };
137
+ }
138
+ return {
139
+ states,
140
+ initialState: proto.initialState,
141
+ transitions: proto.transitions.map((t) => ({
142
+ from: t.from,
143
+ to: t.to,
144
+ eventName: t.eventName,
145
+ guard: t.guard,
146
+ effect: t.effect,
147
+ dependencies: t.dependencies ?? [],
148
+ })),
149
+ // Strip FiberAppMetadata — the chain's `metadata` is `Option[JsonLogicValue]`.
150
+ metadata: null,
151
+ };
152
+ }
153
+ // ─── Builder ──────────────────────────────────────────────────────────────────
154
+ /**
155
+ * Assemble the genesis manifest for the standard apps.
156
+ *
157
+ * Covers THREE apps in this first cut — identity, governance, markets (all the
158
+ * `universal` variant). The other std apps (contracts, oracles, corporate) and
159
+ * non-universal variants are a flagged follow-up.
160
+ *
161
+ * @returns a `GenesisManifest` whose JSON deserializes against the chain's circe
162
+ * codecs. Hashes are intentionally absent — the chain derives them.
163
+ */
164
+ function buildGenesisManifest() {
165
+ const packages = [
166
+ {
167
+ name: 'std.identity.package',
168
+ semver: '1.0.0',
169
+ strict: false,
170
+ metadata: {},
171
+ schemaShape: { stateMessage: identityStateMessage, commands: {} },
172
+ definition: toWireDefinition(identity_universal_js_1.identityUniversalDef),
173
+ },
174
+ {
175
+ name: 'std.governance.package',
176
+ semver: '1.0.0',
177
+ strict: false,
178
+ metadata: {},
179
+ schemaShape: { stateMessage: governanceStateMessage, commands: {} },
180
+ definition: toWireDefinition(governance_universal_js_1.govUniversalDef),
181
+ },
182
+ {
183
+ name: 'std.markets.package',
184
+ semver: '1.0.0',
185
+ strict: false,
186
+ metadata: {},
187
+ schemaShape: { stateMessage: marketStateMessage, commands: {} },
188
+ definition: toWireDefinition(market_universal_js_1.marketUniversalDef),
189
+ },
190
+ ];
191
+ return { version: exports.GENESIS_MANIFEST_VERSION, packages };
192
+ }
193
+ exports.buildGenesisManifest = buildGenesisManifest;
@@ -30,7 +30,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
30
30
  return result;
31
31
  };
32
32
  Object.defineProperty(exports, "__esModule", { value: true });
33
- exports.dropNulls = exports.normalizeMessage = exports.normalizeArchiveStateMachine = exports.normalizeTransitionStateMachine = exports.normalizeCreateStateMachine = exports.createDataTransactionRequest = exports.createScriptPayload = exports.createStateMachinePayload = exports.getPublicKeyForRegistration = exports.addTransactionSignature = exports.signTransaction = exports.createInvokeScriptPayload = exports.createArchivePayload = exports.createTransitionPayload = exports.MetagraphClient = exports.extractOnChainState = exports.getScriptInvocations = exports.getEventReceipts = exports.getLogsForFiber = exports.getLatestOnChainState = exports.getSnapshotOnChainState = exports.decodeOnChainState = exports.OTTOCHAIN_MESSAGE_TYPES = exports.proto = void 0;
33
+ exports.GENESIS_MANIFEST_VERSION = exports.buildGenesisManifest = exports.dropNulls = exports.normalizeMessage = exports.normalizeArchiveStateMachine = exports.normalizeTransitionStateMachine = exports.normalizeCreateStateMachine = exports.createDataTransactionRequest = exports.createScriptPayload = exports.createStateMachinePayload = exports.getPublicKeyForRegistration = exports.addTransactionSignature = exports.signTransaction = exports.createInvokeScriptPayload = exports.createArchivePayload = exports.createTransitionPayload = exports.MetagraphClient = exports.extractOnChainState = exports.getScriptInvocations = exports.getEventReceipts = exports.getLogsForFiber = exports.getLatestOnChainState = exports.getSnapshotOnChainState = exports.decodeOnChainState = exports.OTTOCHAIN_MESSAGE_TYPES = exports.proto = void 0;
34
34
  // Re-export generated protobuf types (for binary encoding)
35
35
  exports.proto = __importStar(require("../generated/index.js"));
36
36
  // Runtime message type validation
@@ -65,5 +65,9 @@ Object.defineProperty(exports, "normalizeArchiveStateMachine", { enumerable: tru
65
65
  Object.defineProperty(exports, "normalizeMessage", { enumerable: true, get: function () { return normalize_js_1.normalizeMessage; } });
66
66
  var drop_nulls_js_1 = require("./drop-nulls.js");
67
67
  Object.defineProperty(exports, "dropNulls", { enumerable: true, get: function () { return drop_nulls_js_1.dropNulls; } });
68
+ // Genesis manifest exporter (std-app pre-registration content)
69
+ var genesis_manifest_js_1 = require("./genesis-manifest.js");
70
+ Object.defineProperty(exports, "buildGenesisManifest", { enumerable: true, get: function () { return genesis_manifest_js_1.buildGenesisManifest; } });
71
+ Object.defineProperty(exports, "GENESIS_MANIFEST_VERSION", { enumerable: true, get: function () { return genesis_manifest_js_1.GENESIS_MANIFEST_VERSION; } });
68
72
  // Note: Governance and Corporate types are now in src/apps/
69
73
  // Import from '@ottochain/sdk/apps' instead
@@ -3,41 +3,32 @@
3
3
  * Normalize OttoChain Messages for Signing
4
4
  *
5
5
  * Converts OttoChain message objects to the wire format expected by the
6
- * Scala metagraph. Metakit's JsonBinaryCodec (used by OttoChain for data
7
- * transaction signing) canonicalizes JSON with dropNullValues = true.
6
+ * Scala metagraph. Specifically, ensures all `Option[A]=None` fields are
7
+ * present as explicit `null` values, matching what circe's magnolia encoder
8
+ * produces on the Scala side.
8
9
  *
9
- * NOTE: This is Metakit's codec, NOT tessellation's JsonSerializer (which
10
- * uses Brotli compression for snapshots/consensus a different layer).
11
- * Different layers use different byte-sequence encoders.
10
+ * This is necessary because metakit's `JsonBinaryCodec.deriveDataUpdate`
11
+ * (rc.8) canonicalizes the circe-encoded JSON **including null fields**.
12
+ * If the TypeScript client omits optional fields (undefined), the canonical
13
+ * JSON won't match and signature verification will fail.
12
14
  *
13
- * Because Metakit drops null fields during canonicalization, the canonical
14
- * JSON used for signature verification **omits** null fields entirely.
15
- * If the TypeScript client includes explicit nulls (e.g., `"metadata": null`),
16
- * the canonical form won't match and signature verification will fail.
17
- *
18
- * Schema mapping (Scala → TypeScript wire format):
19
- * - `Option[A] = None` → field OMITTED (not null, not undefined)
15
+ * Schema mapping (Scala TypeScript):
16
+ * - `Option[A] = None` `null` (must be explicit, not undefined/absent)
20
17
  * - `Option[A] = Some(v)` → `v`
21
- * - `List.empty` / `Set.empty` → `[]`
18
+ * - `List.empty` → `[]`
22
19
  * - `Map.empty` → `{}`
23
- * - `Boolean = false` → `false` (always include, not a null/Option)
24
20
  */
25
21
  Object.defineProperty(exports, "__esModule", { value: true });
26
22
  exports.normalizeMessage = exports.normalizeArchiveStateMachine = exports.normalizeTransitionStateMachine = exports.normalizeCreateStateMachine = void 0;
27
23
  /**
28
- * Normalize a State object for wire format.
29
- * State: id (required), isFinal (default false), metadata (Option = None)
30
- * Omit metadata when null/undefined (dropNullValues).
24
+ * Normalize a State object for wire format
31
25
  */
32
26
  function normalizeState(state) {
33
- const result = {
27
+ return {
34
28
  id: state.id,
35
29
  isFinal: state.isFinal ?? false,
30
+ metadata: state.metadata ?? null,
36
31
  };
37
- if (state.metadata != null) {
38
- result.metadata = state.metadata;
39
- }
40
- return result;
41
32
  }
42
33
  /**
43
34
  * Normalize a Transition object for wire format
@@ -89,54 +80,41 @@ function normalizeDefinition(def) {
89
80
  }
90
81
  const transitions = def.transitions ?? [];
91
82
  // Strip FiberAppMetadata if present — it's TypeScript-only, not part of wire format.
92
- // Omit metadata entirely when null/FiberAppMetadata (dropNullValues = true on Scala side).
93
- const wireMetadata = isFiberAppMetadata(def.metadata) ? undefined : def.metadata;
94
- const result = {
83
+ // The Scala schema has `metadata: Option[Json] = None`, so use null for wire format.
84
+ const wireMetadata = isFiberAppMetadata(def.metadata) ? null : (def.metadata ?? null);
85
+ return {
95
86
  states: normalizedStates,
96
87
  initialState: def.initialState,
97
88
  transitions: transitions.map(normalizeTransition),
89
+ metadata: wireMetadata,
98
90
  };
99
- if (wireMetadata != null) {
100
- result.metadata = wireMetadata;
101
- }
102
- return result;
103
91
  }
104
92
  /**
105
93
  * Normalize a CreateStateMachine message for wire format
106
94
  *
107
- * Metakit's JsonBinaryCodec uses dropNullValues = true for canonicalization.
108
- * Optional fields at their defaults must be OMITTED (not set to null)
109
- * to match the canonical JSON used for signature verification.
110
- *
111
- * - definition.metadataOMITTED when absent/FiberAppMetadata
112
- * - definition.states[*].metadata → OMITTED when absent
113
- * - definition.transitions[*].dependencies → [] (Set.empty default, always included)
114
- * - parentFiberId → OMITTED when absent (Option[UUID] = None)
115
- * - participants → OMITTED when absent (Option[Set[Address]] = None)
95
+ * Ensures all Option/default fields are explicit in wire format:
96
+ * - definition.metadata null when absent
97
+ * - definition.states[*].metadata null when absent
98
+ * - definition.transitions[*].dependencies → [] when absent
99
+ * - parentFiberIdnull when absent
116
100
  *
117
101
  * @example
118
102
  * ```typescript
119
103
  * const message = normalizeCreateStateMachine({
120
104
  * fiberId: '...',
121
- * definition: { states: { INIT: { id: 'INIT', isFinal: false } }, ... },
105
+ * definition: { states: { INIT: { id: { value: 'INIT' }, isFinal: false } }, ... },
122
106
  * initialData: {}
123
107
  * });
124
- * // Optional fields are absent (not null): no parentFiberId, no metadata, etc.
108
+ * // message now has parentFiberId: null, definition.metadata: null, etc.
125
109
  * ```
126
110
  */
127
111
  function normalizeCreateStateMachine(msg) {
128
- const result = {
112
+ return {
129
113
  fiberId: msg.fiberId,
130
114
  definition: normalizeDefinition(msg.definition),
131
115
  initialData: msg.initialData ?? {},
116
+ parentFiberId: msg.parentFiberId ?? null,
132
117
  };
133
- if (msg.parentFiberId != null) {
134
- result.parentFiberId = msg.parentFiberId;
135
- }
136
- if (msg.participants != null) {
137
- result.participants = msg.participants;
138
- }
139
- return result;
140
118
  }
141
119
  exports.normalizeCreateStateMachine = normalizeCreateStateMachine;
142
120
  /**
@@ -18,6 +18,10 @@ exports.OTTOCHAIN_MESSAGE_TYPES = [
18
18
  'CreateStateMachine',
19
19
  'TransitionStateMachine',
20
20
  'ArchiveStateMachine',
21
+ 'UpgradeFiber',
21
22
  'CreateScript',
22
23
  'InvokeScript',
24
+ 'PublishVersion',
25
+ 'SetVersionStatus',
26
+ 'RegisterAlias',
23
27
  ];
@@ -84,12 +84,60 @@ export const contractAgreementDef = defineFiberApp({
84
84
  },
85
85
  },
86
86
  states: {
87
- PROPOSED: { id: "PROPOSED", isFinal: false, metadata: null },
88
- ACTIVE: { id: "ACTIVE", isFinal: false, metadata: null },
89
- COMPLETED: { id: "COMPLETED", isFinal: true, metadata: null },
90
- DISPUTED: { id: "DISPUTED", isFinal: false, metadata: null },
91
- REJECTED: { id: "REJECTED", isFinal: true, metadata: null },
92
- CANCELLED: { id: "CANCELLED", isFinal: true, metadata: null },
87
+ PROPOSED: {
88
+ id: "PROPOSED",
89
+ isFinal: false,
90
+ metadata: {
91
+ label: "Proposed",
92
+ description: "Agreement proposed; awaiting the counterparty",
93
+ category: "initial",
94
+ },
95
+ },
96
+ ACTIVE: {
97
+ id: "ACTIVE",
98
+ isFinal: false,
99
+ metadata: {
100
+ label: "Active",
101
+ description: "Agreement accepted and in effect",
102
+ category: "active",
103
+ },
104
+ },
105
+ COMPLETED: {
106
+ id: "COMPLETED",
107
+ isFinal: true,
108
+ metadata: {
109
+ label: "Completed",
110
+ description: "Agreement completed and attested (terminal)",
111
+ category: "terminal",
112
+ },
113
+ },
114
+ DISPUTED: {
115
+ id: "DISPUTED",
116
+ isFinal: false,
117
+ metadata: {
118
+ label: "Disputed",
119
+ description: "A party has raised a dispute; awaiting resolution",
120
+ category: "pending",
121
+ },
122
+ },
123
+ REJECTED: {
124
+ id: "REJECTED",
125
+ isFinal: true,
126
+ metadata: {
127
+ label: "Rejected",
128
+ description: "Proposal rejected by the counterparty (terminal)",
129
+ category: "terminal",
130
+ },
131
+ },
132
+ CANCELLED: {
133
+ id: "CANCELLED",
134
+ isFinal: true,
135
+ metadata: {
136
+ label: "Cancelled",
137
+ description: "Agreement cancelled before completion (terminal)",
138
+ category: "terminal",
139
+ },
140
+ },
93
141
  },
94
142
  initialState: "PROPOSED",
95
143
  transitions: [
@@ -121,14 +121,78 @@ export const contractEscrowDef = defineFiberApp({
121
121
  cancel: {},
122
122
  },
123
123
  states: {
124
- CREATED: { id: "CREATED", isFinal: false, metadata: null },
125
- FUNDED: { id: "FUNDED", isFinal: false, metadata: null },
126
- ACTIVE: { id: "ACTIVE", isFinal: false, metadata: null },
127
- RELEASING: { id: "RELEASING", isFinal: false, metadata: null },
128
- DISPUTED: { id: "DISPUTED", isFinal: false, metadata: null },
129
- RELEASED: { id: "RELEASED", isFinal: true, metadata: null },
130
- REFUNDED: { id: "REFUNDED", isFinal: true, metadata: null },
131
- SPLIT: { id: "SPLIT", isFinal: true, metadata: null },
124
+ CREATED: {
125
+ id: "CREATED",
126
+ isFinal: false,
127
+ metadata: {
128
+ label: "Created",
129
+ description: "Escrow created; awaiting funding",
130
+ category: "initial",
131
+ },
132
+ },
133
+ FUNDED: {
134
+ id: "FUNDED",
135
+ isFinal: false,
136
+ metadata: {
137
+ label: "Funded",
138
+ description: "Funds deposited into escrow",
139
+ category: "active",
140
+ },
141
+ },
142
+ ACTIVE: {
143
+ id: "ACTIVE",
144
+ isFinal: false,
145
+ metadata: {
146
+ label: "Active",
147
+ description: "Escrow in effect while work is performed",
148
+ category: "active",
149
+ },
150
+ },
151
+ RELEASING: {
152
+ id: "RELEASING",
153
+ isFinal: false,
154
+ metadata: {
155
+ label: "Releasing",
156
+ description: "Release approved; payout in progress",
157
+ category: "pending",
158
+ },
159
+ },
160
+ DISPUTED: {
161
+ id: "DISPUTED",
162
+ isFinal: false,
163
+ metadata: {
164
+ label: "Disputed",
165
+ description: "A party disputed the escrow; awaiting arbitration",
166
+ category: "pending",
167
+ },
168
+ },
169
+ RELEASED: {
170
+ id: "RELEASED",
171
+ isFinal: true,
172
+ metadata: {
173
+ label: "Released",
174
+ description: "Funds released to the beneficiary (terminal)",
175
+ category: "terminal",
176
+ },
177
+ },
178
+ REFUNDED: {
179
+ id: "REFUNDED",
180
+ isFinal: true,
181
+ metadata: {
182
+ label: "Refunded",
183
+ description: "Funds refunded to the depositor (terminal)",
184
+ category: "terminal",
185
+ },
186
+ },
187
+ SPLIT: {
188
+ id: "SPLIT",
189
+ isFinal: true,
190
+ metadata: {
191
+ label: "Split",
192
+ description: "Funds split between parties per arbitration (terminal)",
193
+ category: "terminal",
194
+ },
195
+ },
132
196
  },
133
197
  initialState: "CREATED",
134
198
  transitions: [
@@ -27,10 +27,42 @@ export const contractUniversalDef = defineFiberApp({
27
27
  complete: {},
28
28
  },
29
29
  states: {
30
- PROPOSED: { id: "PROPOSED", isFinal: false, metadata: null },
31
- ACTIVE: { id: "ACTIVE", isFinal: false, metadata: null },
32
- COMPLETED: { id: "COMPLETED", isFinal: true, metadata: null },
33
- CANCELLED: { id: "CANCELLED", isFinal: true, metadata: null },
30
+ PROPOSED: {
31
+ id: "PROPOSED",
32
+ isFinal: false,
33
+ metadata: {
34
+ label: "Proposed",
35
+ description: "Contract proposed; awaiting acceptance",
36
+ category: "initial",
37
+ },
38
+ },
39
+ ACTIVE: {
40
+ id: "ACTIVE",
41
+ isFinal: false,
42
+ metadata: {
43
+ label: "Active",
44
+ description: "Contract accepted and in effect",
45
+ category: "active",
46
+ },
47
+ },
48
+ COMPLETED: {
49
+ id: "COMPLETED",
50
+ isFinal: true,
51
+ metadata: {
52
+ label: "Completed",
53
+ description: "Contract obligations fulfilled (terminal)",
54
+ category: "terminal",
55
+ },
56
+ },
57
+ CANCELLED: {
58
+ id: "CANCELLED",
59
+ isFinal: true,
60
+ metadata: {
61
+ label: "Cancelled",
62
+ description: "Contract cancelled before completion (terminal)",
63
+ category: "terminal",
64
+ },
65
+ },
34
66
  },
35
67
  initialState: "PROPOSED",
36
68
  transitions: [
@@ -117,9 +117,33 @@ export const daoMultisigDef = defineFiberApp({
117
117
  },
118
118
  },
119
119
  states: {
120
- ACTIVE: { id: "ACTIVE", isFinal: false, metadata: null },
121
- PENDING: { id: "PENDING", isFinal: false, metadata: null },
122
- DISSOLVED: { id: "DISSOLVED", isFinal: true, metadata: null },
120
+ ACTIVE: {
121
+ id: "ACTIVE",
122
+ isFinal: false,
123
+ metadata: {
124
+ label: "Active",
125
+ description: "Multisig is idle and ready to propose an action",
126
+ category: "initial",
127
+ },
128
+ },
129
+ PENDING: {
130
+ id: "PENDING",
131
+ isFinal: false,
132
+ metadata: {
133
+ label: "Pending",
134
+ description: "An action is awaiting the required signature threshold",
135
+ category: "pending",
136
+ },
137
+ },
138
+ DISSOLVED: {
139
+ id: "DISSOLVED",
140
+ isFinal: true,
141
+ metadata: {
142
+ label: "Dissolved",
143
+ description: "Multisig DAO dissolved (terminal)",
144
+ category: "terminal",
145
+ },
146
+ },
123
147
  },
124
148
  initialState: "ACTIVE",
125
149
  transitions: [
@@ -124,9 +124,33 @@ export const daoReputationDef = defineFiberApp({
124
124
  },
125
125
  },
126
126
  states: {
127
- ACTIVE: { id: "ACTIVE", isFinal: false, metadata: null },
128
- VOTING: { id: "VOTING", isFinal: false, metadata: null },
129
- DISSOLVED: { id: "DISSOLVED", isFinal: true, metadata: null },
127
+ ACTIVE: {
128
+ id: "ACTIVE",
129
+ isFinal: false,
130
+ metadata: {
131
+ label: "Active",
132
+ description: "DAO is idle and ready to accept a proposal",
133
+ category: "initial",
134
+ },
135
+ },
136
+ VOTING: {
137
+ id: "VOTING",
138
+ isFinal: false,
139
+ metadata: {
140
+ label: "Voting",
141
+ description: "Members vote with reputation-weighted power",
142
+ category: "pending",
143
+ },
144
+ },
145
+ DISSOLVED: {
146
+ id: "DISSOLVED",
147
+ isFinal: true,
148
+ metadata: {
149
+ label: "Dissolved",
150
+ description: "Reputation DAO dissolved (terminal)",
151
+ category: "terminal",
152
+ },
153
+ },
130
154
  },
131
155
  initialState: "ACTIVE",
132
156
  transitions: [
@@ -75,9 +75,33 @@ export const daoSingleDef = defineFiberApp({
75
75
  },
76
76
  },
77
77
  states: {
78
- ACTIVE: { id: "ACTIVE", isFinal: false, metadata: null },
79
- TRANSFERRING: { id: "TRANSFERRING", isFinal: false, metadata: null },
80
- DISSOLVED: { id: "DISSOLVED", isFinal: true, metadata: null },
78
+ ACTIVE: {
79
+ id: "ACTIVE",
80
+ isFinal: false,
81
+ metadata: {
82
+ label: "Active",
83
+ description: "Single owner controls the DAO and may act or transfer ownership",
84
+ category: "initial",
85
+ },
86
+ },
87
+ TRANSFERRING: {
88
+ id: "TRANSFERRING",
89
+ isFinal: false,
90
+ metadata: {
91
+ label: "Transferring",
92
+ description: "Ownership transfer proposed; awaiting acceptance",
93
+ category: "pending",
94
+ },
95
+ },
96
+ DISSOLVED: {
97
+ id: "DISSOLVED",
98
+ isFinal: true,
99
+ metadata: {
100
+ label: "Dissolved",
101
+ description: "DAO dissolved by its owner (terminal)",
102
+ category: "terminal",
103
+ },
104
+ },
81
105
  },
82
106
  initialState: "ACTIVE",
83
107
  transitions: [