@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
@@ -0,0 +1,312 @@
1
+ /**
2
+ * Auto-generated from JSON state machine definitions.
3
+ * DO NOT EDIT - regenerate with: npm run prebuild
4
+ */
5
+ export declare const oracleDef: {
6
+ readonly metadata: {
7
+ readonly name: "Oracle";
8
+ readonly description: "Oracle registration, reputation, and slashing state machine";
9
+ readonly version: "1.0.0";
10
+ };
11
+ readonly states: {
12
+ readonly UNREGISTERED: {
13
+ readonly id: "UNREGISTERED";
14
+ readonly isFinal: false;
15
+ readonly metadata: null;
16
+ };
17
+ readonly REGISTERED: {
18
+ readonly id: "REGISTERED";
19
+ readonly isFinal: false;
20
+ readonly metadata: null;
21
+ };
22
+ readonly ACTIVE: {
23
+ readonly id: "ACTIVE";
24
+ readonly isFinal: false;
25
+ readonly metadata: null;
26
+ };
27
+ readonly SLASHED: {
28
+ readonly id: "SLASHED";
29
+ readonly isFinal: false;
30
+ readonly metadata: null;
31
+ };
32
+ readonly WITHDRAWN: {
33
+ readonly id: "WITHDRAWN";
34
+ readonly isFinal: true;
35
+ readonly metadata: null;
36
+ };
37
+ };
38
+ readonly initialState: "UNREGISTERED";
39
+ readonly transitions: readonly [{
40
+ readonly from: "UNREGISTERED";
41
+ readonly to: "REGISTERED";
42
+ readonly eventName: "register";
43
+ readonly guard: {
44
+ readonly ">=": readonly [{
45
+ readonly var: "event.stake";
46
+ }, {
47
+ readonly var: "state.minStake";
48
+ }];
49
+ };
50
+ readonly effect: {
51
+ readonly merge: readonly [{
52
+ readonly var: "state";
53
+ }, {
54
+ readonly status: "REGISTERED";
55
+ readonly address: {
56
+ readonly var: "event.agent";
57
+ };
58
+ readonly stake: {
59
+ readonly var: "event.stake";
60
+ };
61
+ readonly registeredAt: {
62
+ readonly var: "$timestamp";
63
+ };
64
+ readonly reputation: {
65
+ readonly accuracy: 100;
66
+ readonly totalResolutions: 0;
67
+ readonly disputesWon: 0;
68
+ readonly disputesLost: 0;
69
+ };
70
+ readonly domains: {
71
+ readonly var: "event.domains";
72
+ };
73
+ readonly slashingHistory: readonly [];
74
+ }];
75
+ };
76
+ readonly dependencies: readonly [];
77
+ }, {
78
+ readonly from: "REGISTERED";
79
+ readonly to: "ACTIVE";
80
+ readonly eventName: "activate";
81
+ readonly guard: {
82
+ readonly or: readonly [{
83
+ readonly "===": readonly [{
84
+ readonly var: "event.agent";
85
+ }, {
86
+ readonly var: "state.address";
87
+ }];
88
+ }, {
89
+ readonly var: "event.adminOverride";
90
+ }];
91
+ };
92
+ readonly effect: {
93
+ readonly merge: readonly [{
94
+ readonly var: "state";
95
+ }, {
96
+ readonly status: "ACTIVE";
97
+ readonly activatedAt: {
98
+ readonly var: "$timestamp";
99
+ };
100
+ }];
101
+ };
102
+ readonly dependencies: readonly [];
103
+ }, {
104
+ readonly from: "ACTIVE";
105
+ readonly to: "ACTIVE";
106
+ readonly eventName: "add_stake";
107
+ readonly guard: {
108
+ readonly and: readonly [{
109
+ readonly "===": readonly [{
110
+ readonly var: "event.agent";
111
+ }, {
112
+ readonly var: "state.address";
113
+ }];
114
+ }, {
115
+ readonly ">": readonly [{
116
+ readonly var: "event.amount";
117
+ }, 0];
118
+ }];
119
+ };
120
+ readonly effect: {
121
+ readonly merge: readonly [{
122
+ readonly var: "state";
123
+ }, {
124
+ readonly stake: {
125
+ readonly "+": readonly [{
126
+ readonly var: "state.stake";
127
+ }, {
128
+ readonly var: "event.amount";
129
+ }];
130
+ };
131
+ readonly lastStakeAt: {
132
+ readonly var: "$timestamp";
133
+ };
134
+ }];
135
+ };
136
+ readonly dependencies: readonly [];
137
+ }, {
138
+ readonly from: "ACTIVE";
139
+ readonly to: "ACTIVE";
140
+ readonly eventName: "record_resolution";
141
+ readonly guard: {
142
+ readonly var: "event.marketId";
143
+ };
144
+ readonly effect: {
145
+ readonly merge: readonly [{
146
+ readonly var: "state";
147
+ }, {
148
+ readonly reputation: {
149
+ readonly merge: readonly [{
150
+ readonly var: "state.reputation";
151
+ }, {
152
+ readonly totalResolutions: {
153
+ readonly "+": readonly [{
154
+ readonly var: "state.reputation.totalResolutions";
155
+ }, 1];
156
+ };
157
+ readonly accuracy: {
158
+ readonly if: readonly [{
159
+ readonly var: "event.correct";
160
+ }, {
161
+ readonly var: "state.reputation.accuracy";
162
+ }, {
163
+ readonly "-": readonly [{
164
+ readonly var: "state.reputation.accuracy";
165
+ }, 5];
166
+ }];
167
+ };
168
+ }];
169
+ };
170
+ readonly lastResolutionAt: {
171
+ readonly var: "$timestamp";
172
+ };
173
+ }];
174
+ };
175
+ readonly dependencies: readonly [];
176
+ }, {
177
+ readonly from: "ACTIVE";
178
+ readonly to: "SLASHED";
179
+ readonly eventName: "slash";
180
+ readonly guard: {
181
+ readonly and: readonly [{
182
+ readonly var: "event.reason";
183
+ }, {
184
+ readonly ">": readonly [{
185
+ readonly var: "event.amount";
186
+ }, 0];
187
+ }, {
188
+ readonly "<=": readonly [{
189
+ readonly var: "event.amount";
190
+ }, {
191
+ readonly var: "state.stake";
192
+ }];
193
+ }];
194
+ };
195
+ readonly effect: {
196
+ readonly merge: readonly [{
197
+ readonly var: "state";
198
+ }, {
199
+ readonly status: "SLASHED";
200
+ readonly stake: {
201
+ readonly "-": readonly [{
202
+ readonly var: "state.stake";
203
+ }, {
204
+ readonly var: "event.amount";
205
+ }];
206
+ };
207
+ readonly slashingHistory: {
208
+ readonly cat: readonly [{
209
+ readonly var: "state.slashingHistory";
210
+ }, readonly [{
211
+ readonly reason: {
212
+ readonly var: "event.reason";
213
+ };
214
+ readonly amount: {
215
+ readonly var: "event.amount";
216
+ };
217
+ readonly marketId: {
218
+ readonly var: "event.marketId";
219
+ };
220
+ readonly slashedAt: {
221
+ readonly var: "$timestamp";
222
+ };
223
+ }]];
224
+ };
225
+ readonly slashedAt: {
226
+ readonly var: "$timestamp";
227
+ };
228
+ }];
229
+ };
230
+ readonly dependencies: readonly [];
231
+ }, {
232
+ readonly from: "SLASHED";
233
+ readonly to: "ACTIVE";
234
+ readonly eventName: "reactivate";
235
+ readonly guard: {
236
+ readonly and: readonly [{
237
+ readonly "===": readonly [{
238
+ readonly var: "event.agent";
239
+ }, {
240
+ readonly var: "state.address";
241
+ }];
242
+ }, {
243
+ readonly ">=": readonly [{
244
+ readonly var: "state.stake";
245
+ }, {
246
+ readonly var: "state.minStake";
247
+ }];
248
+ }];
249
+ };
250
+ readonly effect: {
251
+ readonly merge: readonly [{
252
+ readonly var: "state";
253
+ }, {
254
+ readonly status: "ACTIVE";
255
+ readonly reactivatedAt: {
256
+ readonly var: "$timestamp";
257
+ };
258
+ }];
259
+ };
260
+ readonly dependencies: readonly [];
261
+ }, {
262
+ readonly from: "ACTIVE";
263
+ readonly to: "WITHDRAWN";
264
+ readonly eventName: "withdraw";
265
+ readonly guard: {
266
+ readonly "===": readonly [{
267
+ readonly var: "event.agent";
268
+ }, {
269
+ readonly var: "state.address";
270
+ }];
271
+ };
272
+ readonly effect: {
273
+ readonly merge: readonly [{
274
+ readonly var: "state";
275
+ }, {
276
+ readonly status: "WITHDRAWN";
277
+ readonly withdrawnAt: {
278
+ readonly var: "$timestamp";
279
+ };
280
+ readonly finalStake: {
281
+ readonly var: "state.stake";
282
+ };
283
+ }];
284
+ };
285
+ readonly dependencies: readonly [];
286
+ }, {
287
+ readonly from: "SLASHED";
288
+ readonly to: "WITHDRAWN";
289
+ readonly eventName: "withdraw";
290
+ readonly guard: {
291
+ readonly "===": readonly [{
292
+ readonly var: "event.agent";
293
+ }, {
294
+ readonly var: "state.address";
295
+ }];
296
+ };
297
+ readonly effect: {
298
+ readonly merge: readonly [{
299
+ readonly var: "state";
300
+ }, {
301
+ readonly status: "WITHDRAWN";
302
+ readonly withdrawnAt: {
303
+ readonly var: "$timestamp";
304
+ };
305
+ readonly finalStake: {
306
+ readonly var: "state.stake";
307
+ };
308
+ }];
309
+ };
310
+ readonly dependencies: readonly [];
311
+ }];
312
+ };
@@ -6,7 +6,8 @@
6
6
  * @packageDocumentation
7
7
  */
8
8
  export * as proto from '../generated/index.js';
9
- export type { Address, FiberId, StateId, HashValue, FiberOrdinal, SnapshotOrdinal, JsonLogicValue, JsonLogicExpression, FiberStatus, AccessControlPolicy, StateMachineDefinition, EmittedEvent, EventReceipt, OracleInvocation, FiberLogEntry, StateMachineFiberRecord, ScriptFiberRecord, FiberRecord, FiberCommit, OnChain, CalculatedState, CreateStateMachine, TransitionStateMachine, ArchiveStateMachine, CreateScript, InvokeScript, OttochainMessage, } from './types.js';
9
+ export type { Address, FiberId, StateId, HashValue, FiberOrdinal, SnapshotOrdinal, JsonLogicValue, JsonLogicExpression, FiberStatus, AccessControlPolicy, StateMachineDefinition, EmittedEvent, EventReceipt, OracleInvocation, FiberLogEntry, StateMachineFiberRecord, ScriptFiberRecord, FiberRecord, FiberCommit, OnChain, CalculatedState, CreateStateMachine, TransitionStateMachine, ArchiveStateMachine, CreateScript, InvokeScript, OttochainMessage, OttochainMessageType, } from './types.js';
10
+ export { OTTOCHAIN_MESSAGE_TYPES } from './types.js';
10
11
  export type { CurrencySnapshotResponse } from './snapshot.js';
11
12
  export { decodeOnChainState, getSnapshotOnChainState, getLatestOnChainState, getLogsForFiber, getEventReceipts, getScriptInvocations, extractOnChainState, } from './snapshot.js';
12
13
  export type { Checkpoint, MetagraphClientConfig, SubscribeOptions, FiberStateCallback, Unsubscribe, } from './metagraph-client.js';
@@ -20,13 +20,12 @@
20
20
  /**
21
21
  * Normalize a CreateStateMachine message for wire format
22
22
  *
23
- * Ensures all Option fields are explicit null:
24
- * - definition.metadata
25
- * - definition.states[*].metadata
26
- * - definition.transitions[*].guard
27
- * - definition.transitions[*].actions
28
- * - definition.transitions[*].metadata
29
- * - parentFiberId
23
+ * Ensures all Option/default fields are explicit in wire format:
24
+ * - definition.metadata → null when absent
25
+ * - definition.states[*].metadata → null when absent
26
+ * - definition.transitions[*].dependencies → [] when absent
27
+ * - parentFiberId → null when absent
28
+ * - participants → null when absent (Optional Set[Address] for multi-party signing)
30
29
  *
31
30
  * @example
32
31
  * ```typescript
@@ -35,16 +34,30 @@
35
34
  * definition: { states: { INIT: { id: { value: 'INIT' }, isFinal: false } }, ... },
36
35
  * initialData: {}
37
36
  * });
38
- * // message now has parentFiberId: null, definition.metadata: null, etc.
37
+ * // message now has parentFiberId: null, participants: null, definition.metadata: null, etc.
39
38
  * ```
40
39
  */
41
40
  export declare function normalizeCreateStateMachine(msg: Record<string, unknown>): Record<string, unknown>;
42
41
  /**
43
42
  * Normalize a TransitionStateMachine message for wire format
43
+ *
44
+ * Scala TransitionStateMachine schema:
45
+ * fiberId: UUID (required)
46
+ * eventName: String (required)
47
+ * payload: JsonLogicValue (required)
48
+ * targetSequenceNumber: FiberOrdinal (required)
49
+ *
50
+ * All fields are required — no Option types, so no null normalization needed.
44
51
  */
45
52
  export declare function normalizeTransitionStateMachine(msg: Record<string, unknown>): Record<string, unknown>;
46
53
  /**
47
54
  * Normalize an ArchiveStateMachine message for wire format
55
+ *
56
+ * Scala ArchiveStateMachine schema:
57
+ * fiberId: UUID (required)
58
+ * targetSequenceNumber: FiberOrdinal (required)
59
+ *
60
+ * All fields are required — no Option types, so no null normalization needed.
48
61
  */
49
62
  export declare function normalizeArchiveStateMachine(msg: Record<string, unknown>): Record<string, unknown>;
50
63
  /**
@@ -157,7 +157,9 @@ export interface CreateStateMachine {
157
157
  fiberId: string;
158
158
  definition: StateMachineDefinition;
159
159
  initialData: JsonLogicValue;
160
- parentFiberId?: string;
160
+ parentFiberId?: string | null;
161
+ /** Optional set of DAG addresses authorized to sign transitions (multi-party signing). */
162
+ participants?: string[] | null;
161
163
  }
162
164
  /**
163
165
  * Trigger a state machine transition.
@@ -208,3 +210,12 @@ export type OttochainMessage = {
208
210
  } | {
209
211
  InvokeScript: InvokeScript;
210
212
  };
213
+ /**
214
+ * Names of all valid OttochainMessage types.
215
+ * Use this for runtime validation (e.g., in API routes).
216
+ */
217
+ export declare const OTTOCHAIN_MESSAGE_TYPES: readonly ["CreateStateMachine", "TransitionStateMachine", "ArchiveStateMachine", "CreateScript", "InvokeScript"];
218
+ /**
219
+ * Type representing valid message type names.
220
+ */
221
+ export type OttochainMessageType = (typeof OTTOCHAIN_MESSAGE_TYPES)[number];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ottochain/sdk",
3
- "version": "1.4.2",
3
+ "version": "1.6.0",
4
4
  "description": "TypeScript SDK for ottochain metagraph operations - signing, encoding, and network interactions",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -100,18 +100,18 @@
100
100
  "devDependencies": {
101
101
  "@babel/preset-env": "^7.29.0",
102
102
  "@commitlint/cli": "^20.4.4",
103
- "@commitlint/config-conventional": "^19.0.0",
104
- "@eslint/js": "^9.39.3",
103
+ "@commitlint/config-conventional": "^20.5.0",
104
+ "@eslint/js": "^9.39.4",
105
105
  "@jest/globals": "^30.3.0",
106
106
  "@types/jest": "^30.0.0",
107
- "@types/node": "^25.3.3",
107
+ "@types/node": "^25.5.0",
108
108
  "@typescript-eslint/eslint-plugin": "^8.56.1",
109
- "@typescript-eslint/parser": "^8.56.1",
109
+ "@typescript-eslint/parser": "^8.57.1",
110
110
  "eslint": "^9.39.3",
111
- "jest": "^30.2.0",
111
+ "jest": "^30.3.0",
112
112
  "prettier": "^3.0.0",
113
113
  "ts-jest": "^29.0.0",
114
- "ts-proto": "^2.11.2",
114
+ "ts-proto": "^2.11.5",
115
115
  "typedoc": "^0.28.17",
116
116
  "typescript": "^5.0.0"
117
117
  },
@@ -125,7 +125,7 @@
125
125
  "registry": "https://registry.npmjs.org"
126
126
  },
127
127
  "scripts": {
128
- "build": "npm run build:cjs && npm run build:esm && npm run build:types && npm run build:fixup",
128
+ "build": "npm run prebuild && npm run build:cjs && npm run build:esm && npm run build:types && npm run build:fixup",
129
129
  "build:fixup": "echo '{\"type\":\"module\"}' > dist/esm/package.json && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
130
130
  "build:cjs": "tsc -p tsconfig.cjs.json",
131
131
  "build:esm": "tsc -p tsconfig.esm.json",
@@ -137,6 +137,7 @@
137
137
  "generate": "buf generate",
138
138
  "lint:proto": "buf lint",
139
139
  "docs": "typedoc",
140
- "docs:watch": "typedoc --watch"
140
+ "docs:watch": "typedoc --watch",
141
+ "prebuild": "node scripts/inline-json.mjs"
141
142
  }
142
143
  }