@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
|
@@ -6,52 +6,36 @@
|
|
|
6
6
|
},
|
|
7
7
|
"states": {
|
|
8
8
|
"UNREGISTERED": {
|
|
9
|
-
"id":
|
|
10
|
-
"value": "UNREGISTERED"
|
|
11
|
-
},
|
|
9
|
+
"id": "UNREGISTERED",
|
|
12
10
|
"isFinal": false,
|
|
13
11
|
"metadata": null
|
|
14
12
|
},
|
|
15
13
|
"REGISTERED": {
|
|
16
|
-
"id":
|
|
17
|
-
"value": "REGISTERED"
|
|
18
|
-
},
|
|
14
|
+
"id": "REGISTERED",
|
|
19
15
|
"isFinal": false,
|
|
20
16
|
"metadata": null
|
|
21
17
|
},
|
|
22
18
|
"ACTIVE": {
|
|
23
|
-
"id":
|
|
24
|
-
"value": "ACTIVE"
|
|
25
|
-
},
|
|
19
|
+
"id": "ACTIVE",
|
|
26
20
|
"isFinal": false,
|
|
27
21
|
"metadata": null
|
|
28
22
|
},
|
|
29
23
|
"SLASHED": {
|
|
30
|
-
"id":
|
|
31
|
-
"value": "SLASHED"
|
|
32
|
-
},
|
|
24
|
+
"id": "SLASHED",
|
|
33
25
|
"isFinal": false,
|
|
34
26
|
"metadata": null
|
|
35
27
|
},
|
|
36
28
|
"WITHDRAWN": {
|
|
37
|
-
"id":
|
|
38
|
-
"value": "WITHDRAWN"
|
|
39
|
-
},
|
|
29
|
+
"id": "WITHDRAWN",
|
|
40
30
|
"isFinal": true,
|
|
41
31
|
"metadata": null
|
|
42
32
|
}
|
|
43
33
|
},
|
|
44
|
-
"initialState":
|
|
45
|
-
"value": "UNREGISTERED"
|
|
46
|
-
},
|
|
34
|
+
"initialState": "UNREGISTERED",
|
|
47
35
|
"transitions": [
|
|
48
36
|
{
|
|
49
|
-
"from":
|
|
50
|
-
|
|
51
|
-
},
|
|
52
|
-
"to": {
|
|
53
|
-
"value": "REGISTERED"
|
|
54
|
-
},
|
|
37
|
+
"from": "UNREGISTERED",
|
|
38
|
+
"to": "REGISTERED",
|
|
55
39
|
"eventName": "register",
|
|
56
40
|
"guard": {
|
|
57
41
|
">=": [
|
|
@@ -95,12 +79,8 @@
|
|
|
95
79
|
"dependencies": []
|
|
96
80
|
},
|
|
97
81
|
{
|
|
98
|
-
"from":
|
|
99
|
-
|
|
100
|
-
},
|
|
101
|
-
"to": {
|
|
102
|
-
"value": "ACTIVE"
|
|
103
|
-
},
|
|
82
|
+
"from": "REGISTERED",
|
|
83
|
+
"to": "ACTIVE",
|
|
104
84
|
"eventName": "activate",
|
|
105
85
|
"guard": {
|
|
106
86
|
"or": [
|
|
@@ -135,12 +115,8 @@
|
|
|
135
115
|
"dependencies": []
|
|
136
116
|
},
|
|
137
117
|
{
|
|
138
|
-
"from":
|
|
139
|
-
|
|
140
|
-
},
|
|
141
|
-
"to": {
|
|
142
|
-
"value": "ACTIVE"
|
|
143
|
-
},
|
|
118
|
+
"from": "ACTIVE",
|
|
119
|
+
"to": "ACTIVE",
|
|
144
120
|
"eventName": "add_stake",
|
|
145
121
|
"guard": {
|
|
146
122
|
"and": [
|
|
@@ -189,12 +165,8 @@
|
|
|
189
165
|
"dependencies": []
|
|
190
166
|
},
|
|
191
167
|
{
|
|
192
|
-
"from":
|
|
193
|
-
|
|
194
|
-
},
|
|
195
|
-
"to": {
|
|
196
|
-
"value": "ACTIVE"
|
|
197
|
-
},
|
|
168
|
+
"from": "ACTIVE",
|
|
169
|
+
"to": "ACTIVE",
|
|
198
170
|
"eventName": "record_resolution",
|
|
199
171
|
"guard": {
|
|
200
172
|
"var": "event.marketId"
|
|
@@ -249,12 +221,8 @@
|
|
|
249
221
|
"dependencies": []
|
|
250
222
|
},
|
|
251
223
|
{
|
|
252
|
-
"from":
|
|
253
|
-
|
|
254
|
-
},
|
|
255
|
-
"to": {
|
|
256
|
-
"value": "SLASHED"
|
|
257
|
-
},
|
|
224
|
+
"from": "ACTIVE",
|
|
225
|
+
"to": "SLASHED",
|
|
258
226
|
"eventName": "slash",
|
|
259
227
|
"guard": {
|
|
260
228
|
"and": [
|
|
@@ -330,12 +298,8 @@
|
|
|
330
298
|
"dependencies": []
|
|
331
299
|
},
|
|
332
300
|
{
|
|
333
|
-
"from":
|
|
334
|
-
|
|
335
|
-
},
|
|
336
|
-
"to": {
|
|
337
|
-
"value": "ACTIVE"
|
|
338
|
-
},
|
|
301
|
+
"from": "SLASHED",
|
|
302
|
+
"to": "ACTIVE",
|
|
339
303
|
"eventName": "reactivate",
|
|
340
304
|
"guard": {
|
|
341
305
|
"and": [
|
|
@@ -377,12 +341,8 @@
|
|
|
377
341
|
"dependencies": []
|
|
378
342
|
},
|
|
379
343
|
{
|
|
380
|
-
"from":
|
|
381
|
-
|
|
382
|
-
},
|
|
383
|
-
"to": {
|
|
384
|
-
"value": "WITHDRAWN"
|
|
385
|
-
},
|
|
344
|
+
"from": "ACTIVE",
|
|
345
|
+
"to": "WITHDRAWN",
|
|
386
346
|
"eventName": "withdraw",
|
|
387
347
|
"guard": {
|
|
388
348
|
"===": [
|
|
@@ -413,12 +373,8 @@
|
|
|
413
373
|
"dependencies": []
|
|
414
374
|
},
|
|
415
375
|
{
|
|
416
|
-
"from":
|
|
417
|
-
|
|
418
|
-
},
|
|
419
|
-
"to": {
|
|
420
|
-
"value": "WITHDRAWN"
|
|
421
|
-
},
|
|
376
|
+
"from": "SLASHED",
|
|
377
|
+
"to": "WITHDRAWN",
|
|
422
378
|
"eventName": "withdraw",
|
|
423
379
|
"guard": {
|
|
424
380
|
"===": [
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* @packageDocumentation
|
|
8
8
|
*
|
|
9
9
|
* NOTE — Dual-type architecture:
|
|
10
|
-
* These generated types use proto conventions (FIBER_STATUS_ACTIVE,
|
|
10
|
+
* These generated types use proto conventions (FIBER_STATUS_ACTIVE, plain string StateId).
|
|
11
11
|
* The wire-format REST API types in src/ottochain/types.ts use plain strings ('Active').
|
|
12
12
|
* Both coexist intentionally until PR #89 (Migrate fiber-engine to generated Scala types) merges.
|
|
13
13
|
*
|
package/dist/esm/index.js
CHANGED
|
@@ -31,3 +31,5 @@ validate, validatePrivateKey, validatePublicKey, validateAddress, validateKeyPai
|
|
|
31
31
|
export * from './errors.js';
|
|
32
32
|
// Validation schemas and helpers
|
|
33
33
|
export * from './validation.js';
|
|
34
|
+
// Ottochain metagraph client
|
|
35
|
+
export { MetagraphClient } from './ottochain/metagraph-client.js';
|
|
@@ -28,3 +28,6 @@ export { TOKEN_DECIMALS } from './currency-types.js';
|
|
|
28
28
|
export { createCurrencyTransaction, createCurrencyTransactionBatch, signCurrencyTransaction, verifyCurrencyTransaction, encodeCurrencyTransaction, hashCurrencyTransaction, getTransactionReference, isValidDagAddress, tokenToUnits, unitsToToken, } from './currency-transaction.js';
|
|
29
29
|
// Network operations
|
|
30
30
|
export { CurrencyL1Client, DataL1Client, HttpClient, NetworkError } from './network/index.js';
|
|
31
|
+
// Transaction helpers for self-signed mode
|
|
32
|
+
export { createTransitionPayload, createArchivePayload, createInvokeScriptPayload, signTransaction, addTransactionSignature, getPublicKeyForRegistration, } from './transaction.js';
|
|
33
|
+
export { createStateMachinePayload, createScriptPayload, createDataTransactionRequest, } from './transaction.js';
|
|
@@ -0,0 +1,240 @@
|
|
|
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 { signDataUpdate } from './sign.js';
|
|
8
|
+
import { getPublicKeyId } from './wallet.js';
|
|
9
|
+
/**
|
|
10
|
+
* Create a new state machine fiber payload.
|
|
11
|
+
*
|
|
12
|
+
* @param params - State machine creation parameters
|
|
13
|
+
* @returns A CreateStateMachine message ready for signing
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const create = createStateMachinePayload({
|
|
18
|
+
* fiberId: crypto.randomUUID(),
|
|
19
|
+
* definition: {
|
|
20
|
+
* states: { CREATED: { on: { activate: 'ACTIVE' } }, ACTIVE: {} },
|
|
21
|
+
* initialState: 'CREATED',
|
|
22
|
+
* },
|
|
23
|
+
* initialData: { owner: myAddress },
|
|
24
|
+
* });
|
|
25
|
+
* const signed = await signTransaction(create, privateKey);
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export function createStateMachinePayload(params) {
|
|
29
|
+
return {
|
|
30
|
+
CreateStateMachine: {
|
|
31
|
+
fiberId: params.fiberId,
|
|
32
|
+
definition: params.definition,
|
|
33
|
+
initialData: params.initialData ?? {},
|
|
34
|
+
...(params.parentFiberId ? { parentFiberId: params.parentFiberId } : {}),
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Create a transition payload ready for signing.
|
|
40
|
+
*
|
|
41
|
+
* This creates the exact message structure expected by the metagraph.
|
|
42
|
+
*
|
|
43
|
+
* @param params - Transition parameters
|
|
44
|
+
* @returns A TransitionStateMachine message ready for signing
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* const transition = createTransitionPayload({
|
|
49
|
+
* fiberId: 'my-fiber-id',
|
|
50
|
+
* eventName: 'activate',
|
|
51
|
+
* payload: {},
|
|
52
|
+
* targetSequenceNumber: 0,
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export function createTransitionPayload(params) {
|
|
57
|
+
return {
|
|
58
|
+
TransitionStateMachine: {
|
|
59
|
+
fiberId: params.fiberId,
|
|
60
|
+
eventName: params.eventName,
|
|
61
|
+
payload: params.payload ?? {},
|
|
62
|
+
targetSequenceNumber: params.targetSequenceNumber,
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Create an archive payload ready for signing.
|
|
68
|
+
*
|
|
69
|
+
* @param params - Archive parameters
|
|
70
|
+
* @returns An ArchiveStateMachine message ready for signing
|
|
71
|
+
*/
|
|
72
|
+
export function createArchivePayload(params) {
|
|
73
|
+
return {
|
|
74
|
+
ArchiveStateMachine: {
|
|
75
|
+
fiberId: params.fiberId,
|
|
76
|
+
targetSequenceNumber: params.targetSequenceNumber,
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Create a new script fiber payload.
|
|
82
|
+
*
|
|
83
|
+
* Note: `initialState` must be an object or array, NOT a primitive.
|
|
84
|
+
*
|
|
85
|
+
* @param params - Script creation parameters
|
|
86
|
+
* @returns A CreateScript message ready for signing
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* const script = createScriptPayload({
|
|
91
|
+
* fiberId: crypto.randomUUID(),
|
|
92
|
+
* scriptProgram: {
|
|
93
|
+
* methods: {
|
|
94
|
+
* increment: { "+": [{ var: "state.value" }, 1] },
|
|
95
|
+
* },
|
|
96
|
+
* },
|
|
97
|
+
* initialState: { value: 0 },
|
|
98
|
+
* accessControl: { type: 'open' },
|
|
99
|
+
* });
|
|
100
|
+
* const signed = await signTransaction(script, privateKey);
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export function createScriptPayload(params) {
|
|
104
|
+
return {
|
|
105
|
+
CreateScript: {
|
|
106
|
+
fiberId: params.fiberId,
|
|
107
|
+
scriptProgram: params.scriptProgram,
|
|
108
|
+
initialState: params.initialState ?? null,
|
|
109
|
+
accessControl: params.accessControl ?? { type: 'open' },
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Create an invoke script payload ready for signing.
|
|
115
|
+
*
|
|
116
|
+
* @param params - Invoke script parameters
|
|
117
|
+
* @returns An InvokeScript message ready for signing
|
|
118
|
+
*/
|
|
119
|
+
export function createInvokeScriptPayload(params) {
|
|
120
|
+
return {
|
|
121
|
+
InvokeScript: {
|
|
122
|
+
fiberId: params.fiberId,
|
|
123
|
+
method: params.method,
|
|
124
|
+
args: params.args ?? {},
|
|
125
|
+
targetSequenceNumber: params.targetSequenceNumber,
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Sign a transaction payload for self-signed mode.
|
|
131
|
+
*
|
|
132
|
+
* This creates a Signed<T> object with the exact format expected by the bridge's
|
|
133
|
+
* `/agent/transition` endpoint when using self-signed mode.
|
|
134
|
+
*
|
|
135
|
+
* @param message - The message to sign (e.g., from createTransitionPayload)
|
|
136
|
+
* @param privateKey - The private key in hex format (64 characters)
|
|
137
|
+
* @returns A signed object ready for submission to the bridge
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```typescript
|
|
141
|
+
* import { createTransitionPayload, signTransaction, generateKeyPair } from '@ottochain/sdk';
|
|
142
|
+
*
|
|
143
|
+
* const keyPair = generateKeyPair();
|
|
144
|
+
*
|
|
145
|
+
* // Create the transition message
|
|
146
|
+
* const transition = createTransitionPayload({
|
|
147
|
+
* fiberId: 'my-fiber-id',
|
|
148
|
+
* eventName: 'activate',
|
|
149
|
+
* payload: {},
|
|
150
|
+
* targetSequenceNumber: 0,
|
|
151
|
+
* });
|
|
152
|
+
*
|
|
153
|
+
* // Sign it
|
|
154
|
+
* const signedUpdate = await signTransaction(transition, keyPair.privateKey);
|
|
155
|
+
*
|
|
156
|
+
* // Submit to bridge
|
|
157
|
+
* await fetch('https://bridge/agent/transition', {
|
|
158
|
+
* method: 'POST',
|
|
159
|
+
* body: JSON.stringify({
|
|
160
|
+
* fiberId: 'my-fiber-id',
|
|
161
|
+
* signedUpdate,
|
|
162
|
+
* }),
|
|
163
|
+
* });
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
export async function signTransaction(message, privateKey) {
|
|
167
|
+
const proof = await signDataUpdate(message, privateKey);
|
|
168
|
+
return {
|
|
169
|
+
value: message,
|
|
170
|
+
proofs: [proof],
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Wrap a signed transaction in the DataTransactionRequest format
|
|
175
|
+
* expected by tessellation's DL1 `/data` endpoint.
|
|
176
|
+
*
|
|
177
|
+
* @param signed - A signed transaction from signTransaction()
|
|
178
|
+
* @returns Payload ready for POST to DL1 `/data`
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```typescript
|
|
182
|
+
* const transition = createTransitionPayload({ ... });
|
|
183
|
+
* const signed = await signTransaction(transition, privateKey);
|
|
184
|
+
* const payload = createDataTransactionRequest(signed);
|
|
185
|
+
*
|
|
186
|
+
* // Submit directly to DL1
|
|
187
|
+
* await fetch('http://dl1-node:9400/data', {
|
|
188
|
+
* method: 'POST',
|
|
189
|
+
* headers: { 'Content-Type': 'application/json' },
|
|
190
|
+
* body: JSON.stringify(payload),
|
|
191
|
+
* });
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
export function createDataTransactionRequest(signed) {
|
|
195
|
+
return { data: signed, fee: null };
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Add an additional signature to a signed transaction.
|
|
199
|
+
*
|
|
200
|
+
* Use this for multi-signature scenarios where multiple parties
|
|
201
|
+
* need to sign the same transaction.
|
|
202
|
+
*
|
|
203
|
+
* @param signed - The already-signed transaction
|
|
204
|
+
* @param privateKey - Additional signer's private key
|
|
205
|
+
* @returns Transaction with additional signature
|
|
206
|
+
*/
|
|
207
|
+
export async function addTransactionSignature(signed, privateKey) {
|
|
208
|
+
const newProof = await signDataUpdate(signed.value, privateKey);
|
|
209
|
+
return {
|
|
210
|
+
value: signed.value,
|
|
211
|
+
proofs: [...signed.proofs, newProof],
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Get the public key ID from a private key in the format expected by registration.
|
|
216
|
+
*
|
|
217
|
+
* The bridge's self-signed registration expects the public key as a 128-character
|
|
218
|
+
* hex string (without the 04 prefix).
|
|
219
|
+
*
|
|
220
|
+
* @param privateKey - Private key in hex format
|
|
221
|
+
* @returns Public key ID (128 chars, no prefix)
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* ```typescript
|
|
225
|
+
* const keyPair = generateKeyPair();
|
|
226
|
+
* const publicKeyId = getPublicKeyForRegistration(keyPair.privateKey);
|
|
227
|
+
*
|
|
228
|
+
* await fetch('https://bridge/agent/register', {
|
|
229
|
+
* method: 'POST',
|
|
230
|
+
* body: JSON.stringify({
|
|
231
|
+
* signingMode: 'self',
|
|
232
|
+
* publicKey: publicKeyId,
|
|
233
|
+
* displayName: 'My Agent',
|
|
234
|
+
* }),
|
|
235
|
+
* });
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
export function getPublicKeyForRegistration(privateKey) {
|
|
239
|
+
return getPublicKeyId(privateKey);
|
|
240
|
+
}
|
|
@@ -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 { createDataTransactionRequest } from '../metakit/transaction.js';
|
|
11
12
|
import { HttpClient } from '../metakit/network/client.js';
|
|
12
13
|
import { NetworkError } from '../metakit/network/types.js';
|
|
13
14
|
import { extractOnChainState } from './snapshot.js';
|
|
@@ -40,6 +41,9 @@ export class MetagraphClient {
|
|
|
40
41
|
if (config.dl1Url) {
|
|
41
42
|
this.dl1 = new HttpClient(config.dl1Url, config.timeout);
|
|
42
43
|
}
|
|
44
|
+
// Build DL1 client pool from dl1Urls (falls back to dl1Url if provided)
|
|
45
|
+
const urls = config.dl1Urls ?? (config.dl1Url ? [config.dl1Url] : []);
|
|
46
|
+
this.dl1Clients = urls.map((url) => new HttpClient(url, config.timeout));
|
|
43
47
|
}
|
|
44
48
|
// -------------------------------------------------------------------------
|
|
45
49
|
// Custom routes (ML0 /data-application/v1/*)
|
|
@@ -297,4 +301,52 @@ export class MetagraphClient {
|
|
|
297
301
|
}
|
|
298
302
|
return this.dl1.post('/data', signedData);
|
|
299
303
|
}
|
|
304
|
+
/**
|
|
305
|
+
* Submit a self-signed transaction directly to DL1 nodes.
|
|
306
|
+
*
|
|
307
|
+
* Wraps the signed payload in `{ data, fee: null }` format and submits
|
|
308
|
+
* to one of the configured DL1 nodes. Uses `Promise.any` when multiple
|
|
309
|
+
* DL1 URLs are configured for resilience.
|
|
310
|
+
*
|
|
311
|
+
* @param signed - A `Signed<T>` object from `signTransaction()`
|
|
312
|
+
* @returns Response containing the data hash
|
|
313
|
+
* @throws Error if no DL1 URLs are configured or all nodes fail
|
|
314
|
+
*
|
|
315
|
+
* @example
|
|
316
|
+
* ```typescript
|
|
317
|
+
* const metagraph = new MetagraphClient({
|
|
318
|
+
* ml0Url: 'http://localhost:9200',
|
|
319
|
+
* dl1Urls: ['http://node1:9400', 'http://node2:9400'],
|
|
320
|
+
* });
|
|
321
|
+
* const signed = await signTransaction(payload, privateKey);
|
|
322
|
+
* await metagraph.submitData(signed);
|
|
323
|
+
* ```
|
|
324
|
+
*/
|
|
325
|
+
async submitData(signed) {
|
|
326
|
+
if (this.dl1Clients.length === 0) {
|
|
327
|
+
throw new Error('dl1Url or dl1Urls is required for submitData');
|
|
328
|
+
}
|
|
329
|
+
const request = createDataTransactionRequest(signed);
|
|
330
|
+
if (this.dl1Clients.length === 1) {
|
|
331
|
+
return this.dl1Clients[0].post('/data', request);
|
|
332
|
+
}
|
|
333
|
+
// Try all DL1 nodes concurrently, return first success
|
|
334
|
+
const errors = [];
|
|
335
|
+
return new Promise((resolve, reject) => {
|
|
336
|
+
let settled = false;
|
|
337
|
+
let pending = this.dl1Clients.length;
|
|
338
|
+
for (const client of this.dl1Clients) {
|
|
339
|
+
client.post('/data', request).then((result) => { if (!settled) {
|
|
340
|
+
settled = true;
|
|
341
|
+
resolve(result);
|
|
342
|
+
} }, (err) => {
|
|
343
|
+
errors.push(err instanceof Error ? err : new Error(String(err)));
|
|
344
|
+
pending--;
|
|
345
|
+
if (pending === 0 && !settled) {
|
|
346
|
+
reject(new Error('All DL1 nodes failed: ' + errors.map(e => e.message).join('; ')));
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
}
|
|
300
352
|
}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* @packageDocumentation
|
|
8
8
|
*
|
|
9
9
|
* NOTE — Dual-type architecture:
|
|
10
|
-
* These generated types use proto conventions (FIBER_STATUS_ACTIVE,
|
|
10
|
+
* These generated types use proto conventions (FIBER_STATUS_ACTIVE, plain string StateId).
|
|
11
11
|
* The wire-format REST API types in src/ottochain/types.ts use plain strings ('Active').
|
|
12
12
|
* Both coexist intentionally until PR #89 (Migrate fiber-engine to generated Scala types) merges.
|
|
13
13
|
*
|
package/dist/types/index.d.ts
CHANGED
|
@@ -20,3 +20,5 @@ export { OttoChainError, NetworkError, ValidationError, SigningError, Transactio
|
|
|
20
20
|
export { DagAddressSchema, PrivateKeySchema, PublicKeySchema, KeyPairSchema, SignatureProofSchema, SignedSchema, TransactionReferenceSchema, CurrencyTransactionValueSchema, CurrencyTransactionSchema, TransferParamsSchema, AgentIdentityRegistrationSchema, PlatformLinkSchema, ContractTermsSchema, ProposeContractRequestSchema, AcceptContractRequestSchema, CompleteContractRequestSchema, validate, validatePrivateKey, validatePublicKey, validateAddress, validateKeyPair, safeParse, assert, type ValidatedKeyPair, type ValidatedSignatureProof, type ValidatedCurrencyTransaction, type ValidatedTransferParams, type ValidatedAgentIdentityRegistration, type ValidatedPlatformLink, type ValidatedProposeContractRequest, type ValidatedAcceptContractRequest, type ValidatedCompleteContractRequest, } from './validation.js';
|
|
21
21
|
export * from './errors.js';
|
|
22
22
|
export * from './validation.js';
|
|
23
|
+
export { MetagraphClient } from './ottochain/metagraph-client.js';
|
|
24
|
+
export type { MetagraphClientConfig, Checkpoint, SubscribeOptions, FiberStateCallback, Unsubscribe } from './ottochain/metagraph-client.js';
|
|
@@ -21,3 +21,6 @@ export { TOKEN_DECIMALS } from './currency-types.js';
|
|
|
21
21
|
export { createCurrencyTransaction, createCurrencyTransactionBatch, signCurrencyTransaction, verifyCurrencyTransaction, encodeCurrencyTransaction, hashCurrencyTransaction, getTransactionReference, isValidDagAddress, tokenToUnits, unitsToToken, } from './currency-transaction.js';
|
|
22
22
|
export { CurrencyL1Client, DataL1Client, HttpClient, NetworkError } from './network/index.js';
|
|
23
23
|
export type { NetworkConfig, RequestOptions, TransactionStatus, PendingTransaction, PostTransactionResponse, EstimateFeeResponse, PostDataResponse, } from './network/index.js';
|
|
24
|
+
export { createTransitionPayload, createArchivePayload, createInvokeScriptPayload, signTransaction, addTransactionSignature, getPublicKeyForRegistration, } from './transaction.js';
|
|
25
|
+
export { createStateMachinePayload, createScriptPayload, createDataTransactionRequest, } from './transaction.js';
|
|
26
|
+
export type { CreateStateMachineParams, CreateStateMachineMessage, CreateScriptParams, CreateScriptMessage, DataTransactionRequest, TransitionParams, TransitionStateMachineMessage, ArchiveParams, ArchiveStateMachineMessage, InvokeScriptParams, InvokeScriptMessage, } from './transaction.js';
|