@ottochain/sdk 1.1.0 → 1.2.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/contracts/state-machines/contract.json +21 -63
- package/dist/cjs/apps/contracts/state-machines/escrow.json +23 -69
- package/dist/cjs/apps/governance/state-machines/dao-multisig.json +22 -66
- package/dist/cjs/apps/governance/state-machines/dao-single.json +14 -42
- package/dist/cjs/apps/governance/state-machines/dao-threshold.json +18 -54
- package/dist/cjs/apps/governance/state-machines/dao-token.json +21 -63
- package/dist/cjs/apps/governance/state-machines/governance-constitution.json +22 -66
- package/dist/cjs/apps/governance/state-machines/governance-executive.json +27 -81
- package/dist/cjs/apps/governance/state-machines/governance-judiciary.json +34 -102
- package/dist/cjs/apps/governance/state-machines/governance-legislature.json +32 -96
- package/dist/cjs/apps/governance/state-machines/governance-simple.json +27 -81
- package/dist/cjs/apps/identity/state-machines/agent-identity.json +25 -75
- package/dist/cjs/apps/markets/state-machines/market-universal.json +377 -110
- package/dist/cjs/apps/oracles/state-machines/oracle.json +22 -66
- package/dist/cjs/generated/index.js +1 -1
- package/dist/cjs/index.js +4 -1
- package/dist/cjs/metakit/index.js +13 -1
- package/dist/cjs/metakit/transaction.js +252 -0
- package/dist/cjs/ottochain/metagraph-client.js +52 -0
- package/dist/esm/apps/contracts/state-machines/contract.json +21 -63
- package/dist/esm/apps/contracts/state-machines/escrow.json +23 -69
- package/dist/esm/apps/governance/state-machines/dao-multisig.json +22 -66
- package/dist/esm/apps/governance/state-machines/dao-single.json +14 -42
- package/dist/esm/apps/governance/state-machines/dao-threshold.json +18 -54
- package/dist/esm/apps/governance/state-machines/dao-token.json +21 -63
- package/dist/esm/apps/governance/state-machines/governance-constitution.json +22 -66
- package/dist/esm/apps/governance/state-machines/governance-executive.json +27 -81
- package/dist/esm/apps/governance/state-machines/governance-judiciary.json +34 -102
- package/dist/esm/apps/governance/state-machines/governance-legislature.json +32 -96
- package/dist/esm/apps/governance/state-machines/governance-simple.json +27 -81
- package/dist/esm/apps/identity/state-machines/agent-identity.json +25 -75
- package/dist/esm/apps/markets/state-machines/market-universal.json +377 -110
- package/dist/esm/apps/oracles/state-machines/oracle.json +22 -66
- package/dist/esm/generated/index.js +1 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/metakit/index.js +3 -0
- package/dist/esm/metakit/transaction.js +240 -0
- package/dist/esm/ottochain/metagraph-client.js +52 -0
- package/dist/types/generated/index.d.ts +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/metakit/index.d.ts +3 -0
- package/dist/types/metakit/transaction.d.ts +283 -0
- package/dist/types/ottochain/metagraph-client.d.ts +28 -0
- package/package.json +1 -1
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transaction Helpers for Self-Signed Mode
|
|
3
|
+
*
|
|
4
|
+
* These helpers create properly formatted payloads for the bridge's
|
|
5
|
+
* self-signed mode, where clients sign their own transactions.
|
|
6
|
+
*/
|
|
7
|
+
import type { Signed } from './types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Parameters for creating a new state machine fiber
|
|
10
|
+
*/
|
|
11
|
+
export interface CreateStateMachineParams {
|
|
12
|
+
fiberId: string;
|
|
13
|
+
definition: Record<string, unknown>;
|
|
14
|
+
initialData?: Record<string, unknown>;
|
|
15
|
+
parentFiberId?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A CreateStateMachine message ready for signing
|
|
19
|
+
*/
|
|
20
|
+
export interface CreateStateMachineMessage {
|
|
21
|
+
CreateStateMachine: {
|
|
22
|
+
fiberId: string;
|
|
23
|
+
definition: Record<string, unknown>;
|
|
24
|
+
initialData: Record<string, unknown>;
|
|
25
|
+
parentFiberId?: string;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Create a new state machine fiber payload.
|
|
30
|
+
*
|
|
31
|
+
* @param params - State machine creation parameters
|
|
32
|
+
* @returns A CreateStateMachine message ready for signing
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const create = createStateMachinePayload({
|
|
37
|
+
* fiberId: crypto.randomUUID(),
|
|
38
|
+
* definition: {
|
|
39
|
+
* states: { CREATED: { on: { activate: 'ACTIVE' } }, ACTIVE: {} },
|
|
40
|
+
* initialState: 'CREATED',
|
|
41
|
+
* },
|
|
42
|
+
* initialData: { owner: myAddress },
|
|
43
|
+
* });
|
|
44
|
+
* const signed = await signTransaction(create, privateKey);
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function createStateMachinePayload(params: CreateStateMachineParams): CreateStateMachineMessage;
|
|
48
|
+
/**
|
|
49
|
+
* Parameters for creating a transition payload
|
|
50
|
+
*/
|
|
51
|
+
export interface TransitionParams {
|
|
52
|
+
fiberId: string;
|
|
53
|
+
eventName: string;
|
|
54
|
+
payload?: Record<string, unknown>;
|
|
55
|
+
targetSequenceNumber: number;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* A TransitionStateMachine message ready for signing
|
|
59
|
+
*/
|
|
60
|
+
export interface TransitionStateMachineMessage {
|
|
61
|
+
TransitionStateMachine: {
|
|
62
|
+
fiberId: string;
|
|
63
|
+
eventName: string;
|
|
64
|
+
payload: Record<string, unknown>;
|
|
65
|
+
targetSequenceNumber: number;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Create a transition payload ready for signing.
|
|
70
|
+
*
|
|
71
|
+
* This creates the exact message structure expected by the metagraph.
|
|
72
|
+
*
|
|
73
|
+
* @param params - Transition parameters
|
|
74
|
+
* @returns A TransitionStateMachine message ready for signing
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* const transition = createTransitionPayload({
|
|
79
|
+
* fiberId: 'my-fiber-id',
|
|
80
|
+
* eventName: 'activate',
|
|
81
|
+
* payload: {},
|
|
82
|
+
* targetSequenceNumber: 0,
|
|
83
|
+
* });
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export declare function createTransitionPayload(params: TransitionParams): TransitionStateMachineMessage;
|
|
87
|
+
/**
|
|
88
|
+
* Parameters for creating an archive payload
|
|
89
|
+
*/
|
|
90
|
+
export interface ArchiveParams {
|
|
91
|
+
fiberId: string;
|
|
92
|
+
targetSequenceNumber: number;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* An ArchiveStateMachine message ready for signing
|
|
96
|
+
*/
|
|
97
|
+
export interface ArchiveStateMachineMessage {
|
|
98
|
+
ArchiveStateMachine: {
|
|
99
|
+
fiberId: string;
|
|
100
|
+
targetSequenceNumber: number;
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Create an archive payload ready for signing.
|
|
105
|
+
*
|
|
106
|
+
* @param params - Archive parameters
|
|
107
|
+
* @returns An ArchiveStateMachine message ready for signing
|
|
108
|
+
*/
|
|
109
|
+
export declare function createArchivePayload(params: ArchiveParams): ArchiveStateMachineMessage;
|
|
110
|
+
/**
|
|
111
|
+
* Parameters for creating a new script fiber
|
|
112
|
+
*/
|
|
113
|
+
export interface CreateScriptParams {
|
|
114
|
+
fiberId: string;
|
|
115
|
+
scriptProgram: Record<string, unknown>;
|
|
116
|
+
initialState?: Record<string, unknown> | unknown[];
|
|
117
|
+
accessControl?: Record<string, unknown>;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* A CreateScript message ready for signing
|
|
121
|
+
*/
|
|
122
|
+
export interface CreateScriptMessage {
|
|
123
|
+
CreateScript: {
|
|
124
|
+
fiberId: string;
|
|
125
|
+
scriptProgram: Record<string, unknown>;
|
|
126
|
+
initialState: Record<string, unknown> | unknown[] | null;
|
|
127
|
+
accessControl: Record<string, unknown>;
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Create a new script fiber payload.
|
|
132
|
+
*
|
|
133
|
+
* Note: `initialState` must be an object or array, NOT a primitive.
|
|
134
|
+
*
|
|
135
|
+
* @param params - Script creation parameters
|
|
136
|
+
* @returns A CreateScript message ready for signing
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```typescript
|
|
140
|
+
* const script = createScriptPayload({
|
|
141
|
+
* fiberId: crypto.randomUUID(),
|
|
142
|
+
* scriptProgram: {
|
|
143
|
+
* methods: {
|
|
144
|
+
* increment: { "+": [{ var: "state.value" }, 1] },
|
|
145
|
+
* },
|
|
146
|
+
* },
|
|
147
|
+
* initialState: { value: 0 },
|
|
148
|
+
* accessControl: { type: 'open' },
|
|
149
|
+
* });
|
|
150
|
+
* const signed = await signTransaction(script, privateKey);
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
export declare function createScriptPayload(params: CreateScriptParams): CreateScriptMessage;
|
|
154
|
+
/**
|
|
155
|
+
* Parameters for creating an invoke script payload
|
|
156
|
+
*/
|
|
157
|
+
export interface InvokeScriptParams {
|
|
158
|
+
fiberId: string;
|
|
159
|
+
method: string;
|
|
160
|
+
args?: Record<string, unknown>;
|
|
161
|
+
targetSequenceNumber: number;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* An InvokeScript message ready for signing
|
|
165
|
+
*/
|
|
166
|
+
export interface InvokeScriptMessage {
|
|
167
|
+
InvokeScript: {
|
|
168
|
+
fiberId: string;
|
|
169
|
+
method: string;
|
|
170
|
+
args: Record<string, unknown>;
|
|
171
|
+
targetSequenceNumber: number;
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Create an invoke script payload ready for signing.
|
|
176
|
+
*
|
|
177
|
+
* @param params - Invoke script parameters
|
|
178
|
+
* @returns An InvokeScript message ready for signing
|
|
179
|
+
*/
|
|
180
|
+
export declare function createInvokeScriptPayload(params: InvokeScriptParams): InvokeScriptMessage;
|
|
181
|
+
/**
|
|
182
|
+
* Sign a transaction payload for self-signed mode.
|
|
183
|
+
*
|
|
184
|
+
* This creates a Signed<T> object with the exact format expected by the bridge's
|
|
185
|
+
* `/agent/transition` endpoint when using self-signed mode.
|
|
186
|
+
*
|
|
187
|
+
* @param message - The message to sign (e.g., from createTransitionPayload)
|
|
188
|
+
* @param privateKey - The private key in hex format (64 characters)
|
|
189
|
+
* @returns A signed object ready for submission to the bridge
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* ```typescript
|
|
193
|
+
* import { createTransitionPayload, signTransaction, generateKeyPair } from '@ottochain/sdk';
|
|
194
|
+
*
|
|
195
|
+
* const keyPair = generateKeyPair();
|
|
196
|
+
*
|
|
197
|
+
* // Create the transition message
|
|
198
|
+
* const transition = createTransitionPayload({
|
|
199
|
+
* fiberId: 'my-fiber-id',
|
|
200
|
+
* eventName: 'activate',
|
|
201
|
+
* payload: {},
|
|
202
|
+
* targetSequenceNumber: 0,
|
|
203
|
+
* });
|
|
204
|
+
*
|
|
205
|
+
* // Sign it
|
|
206
|
+
* const signedUpdate = await signTransaction(transition, keyPair.privateKey);
|
|
207
|
+
*
|
|
208
|
+
* // Submit to bridge
|
|
209
|
+
* await fetch('https://bridge/agent/transition', {
|
|
210
|
+
* method: 'POST',
|
|
211
|
+
* body: JSON.stringify({
|
|
212
|
+
* fiberId: 'my-fiber-id',
|
|
213
|
+
* signedUpdate,
|
|
214
|
+
* }),
|
|
215
|
+
* });
|
|
216
|
+
* ```
|
|
217
|
+
*/
|
|
218
|
+
export declare function signTransaction<T>(message: T, privateKey: string): Promise<Signed<T>>;
|
|
219
|
+
/**
|
|
220
|
+
* A DataTransactionRequest ready for submission to the DL1 `/data` endpoint.
|
|
221
|
+
*/
|
|
222
|
+
export interface DataTransactionRequest<T> {
|
|
223
|
+
data: Signed<T>;
|
|
224
|
+
fee: null;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Wrap a signed transaction in the DataTransactionRequest format
|
|
228
|
+
* expected by tessellation's DL1 `/data` endpoint.
|
|
229
|
+
*
|
|
230
|
+
* @param signed - A signed transaction from signTransaction()
|
|
231
|
+
* @returns Payload ready for POST to DL1 `/data`
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```typescript
|
|
235
|
+
* const transition = createTransitionPayload({ ... });
|
|
236
|
+
* const signed = await signTransaction(transition, privateKey);
|
|
237
|
+
* const payload = createDataTransactionRequest(signed);
|
|
238
|
+
*
|
|
239
|
+
* // Submit directly to DL1
|
|
240
|
+
* await fetch('http://dl1-node:9400/data', {
|
|
241
|
+
* method: 'POST',
|
|
242
|
+
* headers: { 'Content-Type': 'application/json' },
|
|
243
|
+
* body: JSON.stringify(payload),
|
|
244
|
+
* });
|
|
245
|
+
* ```
|
|
246
|
+
*/
|
|
247
|
+
export declare function createDataTransactionRequest<T>(signed: Signed<T>): DataTransactionRequest<T>;
|
|
248
|
+
/**
|
|
249
|
+
* Add an additional signature to a signed transaction.
|
|
250
|
+
*
|
|
251
|
+
* Use this for multi-signature scenarios where multiple parties
|
|
252
|
+
* need to sign the same transaction.
|
|
253
|
+
*
|
|
254
|
+
* @param signed - The already-signed transaction
|
|
255
|
+
* @param privateKey - Additional signer's private key
|
|
256
|
+
* @returns Transaction with additional signature
|
|
257
|
+
*/
|
|
258
|
+
export declare function addTransactionSignature<T>(signed: Signed<T>, privateKey: string): Promise<Signed<T>>;
|
|
259
|
+
/**
|
|
260
|
+
* Get the public key ID from a private key in the format expected by registration.
|
|
261
|
+
*
|
|
262
|
+
* The bridge's self-signed registration expects the public key as a 128-character
|
|
263
|
+
* hex string (without the 04 prefix).
|
|
264
|
+
*
|
|
265
|
+
* @param privateKey - Private key in hex format
|
|
266
|
+
* @returns Public key ID (128 chars, no prefix)
|
|
267
|
+
*
|
|
268
|
+
* @example
|
|
269
|
+
* ```typescript
|
|
270
|
+
* const keyPair = generateKeyPair();
|
|
271
|
+
* const publicKeyId = getPublicKeyForRegistration(keyPair.privateKey);
|
|
272
|
+
*
|
|
273
|
+
* await fetch('https://bridge/agent/register', {
|
|
274
|
+
* method: 'POST',
|
|
275
|
+
* body: JSON.stringify({
|
|
276
|
+
* signingMode: 'self',
|
|
277
|
+
* publicKey: publicKeyId,
|
|
278
|
+
* displayName: 'My Agent',
|
|
279
|
+
* }),
|
|
280
|
+
* });
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
export declare function getPublicKeyForRegistration(privateKey: string): string;
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* @see modules/data_l1/src/main/scala/xyz/kd5ujc/data_l1/DataL1CustomRoutes.scala
|
|
9
9
|
* @packageDocumentation
|
|
10
10
|
*/
|
|
11
|
+
import type { Signed } from '../metakit/types.js';
|
|
11
12
|
import type { OnChain, CalculatedState, StateMachineFiberRecord, ScriptFiberRecord, EventReceipt, OracleInvocation, FiberStatus } from './types.js';
|
|
12
13
|
/**
|
|
13
14
|
* Checkpoint response from the metagraph (ordinal + calculated state).
|
|
@@ -63,6 +64,8 @@ export interface MetagraphClientConfig {
|
|
|
63
64
|
ml0Url: string;
|
|
64
65
|
/** DL1 node base URL for data submission (e.g., 'http://localhost:9400') */
|
|
65
66
|
dl1Url?: string;
|
|
67
|
+
/** Multiple DL1 node URLs for resilient data submission */
|
|
68
|
+
dl1Urls?: string[];
|
|
66
69
|
/** Request timeout in milliseconds (default: 30000) */
|
|
67
70
|
timeout?: number;
|
|
68
71
|
}
|
|
@@ -92,6 +95,7 @@ export interface MetagraphClientConfig {
|
|
|
92
95
|
export declare class MetagraphClient {
|
|
93
96
|
private ml0;
|
|
94
97
|
private dl1?;
|
|
98
|
+
private dl1Clients;
|
|
95
99
|
constructor(config: MetagraphClientConfig);
|
|
96
100
|
/**
|
|
97
101
|
* Get the current on-chain state (directly from L0 context).
|
|
@@ -198,4 +202,28 @@ export declare class MetagraphClient {
|
|
|
198
202
|
postData<T>(signedData: T): Promise<{
|
|
199
203
|
hash: string;
|
|
200
204
|
}>;
|
|
205
|
+
/**
|
|
206
|
+
* Submit a self-signed transaction directly to DL1 nodes.
|
|
207
|
+
*
|
|
208
|
+
* Wraps the signed payload in `{ data, fee: null }` format and submits
|
|
209
|
+
* to one of the configured DL1 nodes. Uses `Promise.any` when multiple
|
|
210
|
+
* DL1 URLs are configured for resilience.
|
|
211
|
+
*
|
|
212
|
+
* @param signed - A `Signed<T>` object from `signTransaction()`
|
|
213
|
+
* @returns Response containing the data hash
|
|
214
|
+
* @throws Error if no DL1 URLs are configured or all nodes fail
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* ```typescript
|
|
218
|
+
* const metagraph = new MetagraphClient({
|
|
219
|
+
* ml0Url: 'http://localhost:9200',
|
|
220
|
+
* dl1Urls: ['http://node1:9400', 'http://node2:9400'],
|
|
221
|
+
* });
|
|
222
|
+
* const signed = await signTransaction(payload, privateKey);
|
|
223
|
+
* await metagraph.submitData(signed);
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
submitData<T>(signed: Signed<T>): Promise<{
|
|
227
|
+
hash: string;
|
|
228
|
+
}>;
|
|
201
229
|
}
|
package/package.json
CHANGED