@ottochain/sdk 1.4.2 → 1.6.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 (80) hide show
  1. package/dist/cjs/apps/contracts/index.js +6 -10
  2. package/dist/cjs/apps/{governance/state-machines/governance-legislature.json → contracts/state-machines/index.js} +381 -330
  3. package/dist/cjs/apps/corporate/index.js +12 -24
  4. package/dist/cjs/apps/corporate/state-machines/index.js +10246 -0
  5. package/dist/cjs/apps/governance/index.js +11 -22
  6. package/dist/cjs/apps/governance/state-machines/index.js +4755 -0
  7. package/dist/cjs/apps/identity/index.js +3 -6
  8. package/dist/{esm/apps/identity/state-machines/agent-identity.json → cjs/apps/identity/state-machines/index.js} +9 -2
  9. package/dist/cjs/apps/markets/index.js +2 -5
  10. package/dist/{esm/apps/markets/state-machines/market-universal.json → cjs/apps/markets/state-machines/index.js} +9 -2
  11. package/dist/cjs/apps/oracles/index.js +2 -5
  12. package/dist/{esm/apps/oracles/state-machines/oracle.json → cjs/apps/oracles/state-machines/index.js} +9 -2
  13. package/dist/cjs/ottochain/index.js +4 -1
  14. package/dist/cjs/ottochain/normalize.js +40 -15
  15. package/dist/cjs/ottochain/types.js +12 -0
  16. package/dist/esm/apps/contracts/index.js +2 -3
  17. package/dist/esm/apps/{governance/state-machines/governance-legislature.json → contracts/state-machines/index.js} +378 -330
  18. package/dist/esm/apps/corporate/index.js +2 -11
  19. package/dist/esm/apps/corporate/state-machines/index.js +10243 -0
  20. package/dist/esm/apps/governance/index.js +2 -10
  21. package/dist/esm/apps/governance/state-machines/index.js +4752 -0
  22. package/dist/esm/apps/identity/index.js +2 -2
  23. package/dist/{cjs/apps/identity/state-machines/agent-identity.json → esm/apps/identity/state-machines/index.js} +6 -2
  24. package/dist/esm/apps/markets/index.js +1 -1
  25. package/dist/{cjs/apps/markets/state-machines/market-universal.json → esm/apps/markets/state-machines/index.js} +6 -2
  26. package/dist/esm/apps/oracles/index.js +1 -1
  27. package/dist/{cjs/apps/oracles/state-machines/oracle.json → esm/apps/oracles/state-machines/index.js} +6 -2
  28. package/dist/esm/ottochain/index.js +2 -0
  29. package/dist/esm/ottochain/normalize.js +40 -15
  30. package/dist/esm/ottochain/types.js +11 -1
  31. package/dist/types/apps/contracts/state-machines/index.d.ts +549 -0
  32. package/dist/types/apps/corporate/state-machines/index.d.ts +9121 -0
  33. package/dist/types/apps/governance/state-machines/index.d.ts +3551 -0
  34. package/dist/types/apps/identity/state-machines/index.d.ts +206 -0
  35. package/dist/types/apps/markets/state-machines/index.d.ts +448 -0
  36. package/dist/types/apps/oracles/state-machines/index.d.ts +312 -0
  37. package/dist/types/ottochain/index.d.ts +2 -1
  38. package/dist/types/ottochain/normalize.d.ts +21 -8
  39. package/dist/types/ottochain/types.d.ts +12 -1
  40. package/package.json +10 -9
  41. package/dist/cjs/apps/contracts/state-machines/contract.json +0 -352
  42. package/dist/cjs/apps/contracts/state-machines/escrow.json +0 -354
  43. package/dist/cjs/apps/corporate/state-machines/corporate-board.json +0 -1064
  44. package/dist/cjs/apps/corporate/state-machines/corporate-bylaws.json +0 -751
  45. package/dist/cjs/apps/corporate/state-machines/corporate-committee.json +0 -957
  46. package/dist/cjs/apps/corporate/state-machines/corporate-compliance.json +0 -1293
  47. package/dist/cjs/apps/corporate/state-machines/corporate-entity.json +0 -861
  48. package/dist/cjs/apps/corporate/state-machines/corporate-officers.json +0 -843
  49. package/dist/cjs/apps/corporate/state-machines/corporate-proxy.json +0 -783
  50. package/dist/cjs/apps/corporate/state-machines/corporate-resolution.json +0 -1174
  51. package/dist/cjs/apps/corporate/state-machines/corporate-securities.json +0 -1215
  52. package/dist/cjs/apps/corporate/state-machines/corporate-shareholders.json +0 -1298
  53. package/dist/cjs/apps/governance/state-machines/dao-multisig.json +0 -667
  54. package/dist/cjs/apps/governance/state-machines/dao-single.json +0 -230
  55. package/dist/cjs/apps/governance/state-machines/dao-threshold.json +0 -624
  56. package/dist/cjs/apps/governance/state-machines/dao-token.json +0 -638
  57. package/dist/cjs/apps/governance/state-machines/governance-constitution.json +0 -357
  58. package/dist/cjs/apps/governance/state-machines/governance-executive.json +0 -387
  59. package/dist/cjs/apps/governance/state-machines/governance-judiciary.json +0 -558
  60. package/dist/cjs/apps/governance/state-machines/governance-simple.json +0 -625
  61. package/dist/esm/apps/contracts/state-machines/contract.json +0 -352
  62. package/dist/esm/apps/contracts/state-machines/escrow.json +0 -354
  63. package/dist/esm/apps/corporate/state-machines/corporate-board.json +0 -1064
  64. package/dist/esm/apps/corporate/state-machines/corporate-bylaws.json +0 -751
  65. package/dist/esm/apps/corporate/state-machines/corporate-committee.json +0 -957
  66. package/dist/esm/apps/corporate/state-machines/corporate-compliance.json +0 -1293
  67. package/dist/esm/apps/corporate/state-machines/corporate-entity.json +0 -861
  68. package/dist/esm/apps/corporate/state-machines/corporate-officers.json +0 -843
  69. package/dist/esm/apps/corporate/state-machines/corporate-proxy.json +0 -783
  70. package/dist/esm/apps/corporate/state-machines/corporate-resolution.json +0 -1174
  71. package/dist/esm/apps/corporate/state-machines/corporate-securities.json +0 -1215
  72. package/dist/esm/apps/corporate/state-machines/corporate-shareholders.json +0 -1298
  73. package/dist/esm/apps/governance/state-machines/dao-multisig.json +0 -667
  74. package/dist/esm/apps/governance/state-machines/dao-single.json +0 -230
  75. package/dist/esm/apps/governance/state-machines/dao-threshold.json +0 -624
  76. package/dist/esm/apps/governance/state-machines/dao-token.json +0 -638
  77. package/dist/esm/apps/governance/state-machines/governance-constitution.json +0 -357
  78. package/dist/esm/apps/governance/state-machines/governance-executive.json +0 -387
  79. package/dist/esm/apps/governance/state-machines/governance-judiciary.json +0 -558
  80. package/dist/esm/apps/governance/state-machines/governance-simple.json +0 -625
@@ -37,9 +37,9 @@ export const DEFAULT_REPUTATION_CONFIG = {
37
37
  challengeThreshold: 5,
38
38
  };
39
39
  // ---------------------------------------------------------------------------
40
- // State Machine JSON Definition
40
+ // State Machine Definition (generated from JSON at build time)
41
41
  // ---------------------------------------------------------------------------
42
- import agentIdentityDef from './state-machines/agent-identity.json';
42
+ import { agentIdentityDef } from './state-machines/index.js';
43
43
  /**
44
44
  * Get the agent identity state machine definition.
45
45
  *
@@ -1,4 +1,8 @@
1
- {
1
+ /**
2
+ * Auto-generated from JSON state machine definitions.
3
+ * DO NOT EDIT - regenerate with: npm run prebuild
4
+ */
5
+ export const agentIdentityDef = {
2
6
  "metadata": {
3
7
  "name": "AgentIdentity",
4
8
  "description": "Decentralized agent identity with reputation tracking and lifecycle management",
@@ -267,4 +271,4 @@
267
271
  "dependencies": []
268
272
  }
269
273
  ]
270
- }
274
+ };
@@ -22,7 +22,7 @@ export { MarketType, MarketState, Commitment, Resolution, Market, CreateMarketRe
22
22
  // ---------------------------------------------------------------------------
23
23
  // State Machine JSON Definitions
24
24
  // ---------------------------------------------------------------------------
25
- import marketUniversalDef from './state-machines/market-universal.json';
25
+ import { marketUniversalDef } from './state-machines/index.js';
26
26
  export const MARKET_DEFINITIONS = {
27
27
  Universal: marketUniversalDef,
28
28
  };
@@ -1,4 +1,8 @@
1
- {
1
+ /**
2
+ * Auto-generated from JSON state machine definitions.
3
+ * DO NOT EDIT - regenerate with: npm run prebuild
4
+ */
5
+ export const marketUniversalDef = {
2
6
  "metadata": {
3
7
  "name": "Market",
4
8
  "description": "Universal market state machine: predictions, auctions, crowdfunding, group buys",
@@ -618,4 +622,4 @@
618
622
  "dependencies": []
619
623
  }
620
624
  ]
621
- }
625
+ };
@@ -22,7 +22,7 @@ export { OracleState, OracleReputation, SlashingEvent, Oracle, RegisterOracleReq
22
22
  // ---------------------------------------------------------------------------
23
23
  // State Machine JSON Definitions
24
24
  // ---------------------------------------------------------------------------
25
- import oracleDef from './state-machines/oracle.json';
25
+ import { oracleDef } from './state-machines/index.js';
26
26
  export const ORACLE_DEFINITIONS = {
27
27
  Oracle: oracleDef,
28
28
  };
@@ -1,4 +1,8 @@
1
- {
1
+ /**
2
+ * Auto-generated from JSON state machine definitions.
3
+ * DO NOT EDIT - regenerate with: npm run prebuild
4
+ */
5
+ export const oracleDef = {
2
6
  "metadata": {
3
7
  "name": "Oracle",
4
8
  "description": "Oracle registration, reputation, and slashing state machine",
@@ -405,4 +409,4 @@
405
409
  "dependencies": []
406
410
  }
407
411
  ]
408
- }
412
+ };
@@ -7,6 +7,8 @@
7
7
  */
8
8
  // Re-export generated protobuf types (for binary encoding)
9
9
  export * as proto from '../generated/index.js';
10
+ // Runtime message type validation
11
+ export { OTTOCHAIN_MESSAGE_TYPES } from './types.js';
10
12
  export { decodeOnChainState, getSnapshotOnChainState, getLatestOnChainState, getLogsForFiber, getEventReceipts, getScriptInvocations, extractOnChainState, } from './snapshot.js';
11
13
  export { MetagraphClient } from './metagraph-client.js';
12
14
  // Transaction helpers (state machine payloads, signing)
@@ -29,15 +29,26 @@ function normalizeState(state) {
29
29
  }
30
30
  /**
31
31
  * Normalize a Transition object for wire format
32
+ *
33
+ * Scala Transition schema:
34
+ * from: StateId (required)
35
+ * to: StateId (required)
36
+ * eventName: String (required)
37
+ * guard: JsonLogicExpression (required)
38
+ * effect: JsonLogicExpression (required)
39
+ * dependencies: Set[UUID] = Set.empty
40
+ *
41
+ * `dependencies` serializes as `[]` when empty (default). Both `guard`
42
+ * and `effect` are required non-optional fields.
32
43
  */
33
44
  function normalizeTransition(t) {
34
45
  return {
35
46
  from: t.from,
36
- eventName: t.eventName,
37
47
  to: t.to,
38
- guard: t.guard ?? null,
39
- actions: t.actions ?? null,
40
- metadata: t.metadata ?? null,
48
+ eventName: t.eventName,
49
+ guard: t.guard,
50
+ effect: t.effect,
51
+ dependencies: t.dependencies ?? [],
41
52
  };
42
53
  }
43
54
  /**
@@ -62,13 +73,12 @@ function normalizeDefinition(def) {
62
73
  /**
63
74
  * Normalize a CreateStateMachine message for wire format
64
75
  *
65
- * Ensures all Option fields are explicit null:
66
- * - definition.metadata
67
- * - definition.states[*].metadata
68
- * - definition.transitions[*].guard
69
- * - definition.transitions[*].actions
70
- * - definition.transitions[*].metadata
71
- * - parentFiberId
76
+ * Ensures all Option/default fields are explicit in wire format:
77
+ * - definition.metadata → null when absent
78
+ * - definition.states[*].metadata → null when absent
79
+ * - definition.transitions[*].dependencies → [] when absent
80
+ * - parentFiberId → null when absent
81
+ * - participants → null when absent (Optional Set[Address] for multi-party signing)
72
82
  *
73
83
  * @example
74
84
  * ```typescript
@@ -77,7 +87,7 @@ function normalizeDefinition(def) {
77
87
  * definition: { states: { INIT: { id: { value: 'INIT' }, isFinal: false } }, ... },
78
88
  * initialData: {}
79
89
  * });
80
- * // message now has parentFiberId: null, definition.metadata: null, etc.
90
+ * // message now has parentFiberId: null, participants: null, definition.metadata: null, etc.
81
91
  * ```
82
92
  */
83
93
  export function normalizeCreateStateMachine(msg) {
@@ -86,26 +96,41 @@ export function normalizeCreateStateMachine(msg) {
86
96
  definition: normalizeDefinition(msg.definition),
87
97
  initialData: msg.initialData ?? {},
88
98
  parentFiberId: msg.parentFiberId ?? null,
99
+ participants: msg.participants ?? null,
89
100
  };
90
101
  }
91
102
  /**
92
103
  * Normalize a TransitionStateMachine message for wire format
104
+ *
105
+ * Scala TransitionStateMachine schema:
106
+ * fiberId: UUID (required)
107
+ * eventName: String (required)
108
+ * payload: JsonLogicValue (required)
109
+ * targetSequenceNumber: FiberOrdinal (required)
110
+ *
111
+ * All fields are required — no Option types, so no null normalization needed.
93
112
  */
94
113
  export function normalizeTransitionStateMachine(msg) {
95
114
  return {
96
115
  fiberId: msg.fiberId,
97
116
  eventName: msg.eventName,
98
- eventData: msg.eventData ?? null,
99
- fiberOrdinal: msg.fiberOrdinal,
117
+ payload: msg.payload,
118
+ targetSequenceNumber: msg.targetSequenceNumber,
100
119
  };
101
120
  }
102
121
  /**
103
122
  * Normalize an ArchiveStateMachine message for wire format
123
+ *
124
+ * Scala ArchiveStateMachine schema:
125
+ * fiberId: UUID (required)
126
+ * targetSequenceNumber: FiberOrdinal (required)
127
+ *
128
+ * All fields are required — no Option types, so no null normalization needed.
104
129
  */
105
130
  export function normalizeArchiveStateMachine(msg) {
106
131
  return {
107
132
  fiberId: msg.fiberId,
108
- reason: msg.reason ?? null,
133
+ targetSequenceNumber: msg.targetSequenceNumber,
109
134
  };
110
135
  }
111
136
  /**
@@ -7,4 +7,14 @@
7
7
  * @see modules/models/src/main/scala/xyz/kd5ujc/schema/
8
8
  * @packageDocumentation
9
9
  */
10
- export {};
10
+ /**
11
+ * Names of all valid OttochainMessage types.
12
+ * Use this for runtime validation (e.g., in API routes).
13
+ */
14
+ export const OTTOCHAIN_MESSAGE_TYPES = [
15
+ 'CreateStateMachine',
16
+ 'TransitionStateMachine',
17
+ 'ArchiveStateMachine',
18
+ 'CreateScript',
19
+ 'InvokeScript',
20
+ ];