@ottochain/sdk 1.1.1 → 1.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 (103) hide show
  1. package/LICENSE +190 -0
  2. package/dist/cjs/index.js +35 -13
  3. package/dist/cjs/ottochain/index.js +20 -1
  4. package/dist/cjs/ottochain/metagraph-client.js +57 -6
  5. package/dist/cjs/ottochain/snapshot.js +3 -3
  6. package/dist/cjs/ottochain/transaction.js +251 -0
  7. package/dist/cjs/verify.js +17 -0
  8. package/dist/esm/apps/contracts/index.js +28 -10
  9. package/dist/esm/apps/corporate/index.js +79 -24
  10. package/dist/esm/apps/governance/index.js +85 -36
  11. package/dist/esm/apps/identity/constants.js +27 -22
  12. package/dist/esm/apps/identity/index.js +35 -7
  13. package/dist/esm/apps/index.js +32 -6
  14. package/dist/esm/apps/markets/index.js +27 -6
  15. package/dist/esm/apps/oracles/index.js +27 -7
  16. package/dist/esm/errors.js +19 -9
  17. package/dist/esm/generated/google/protobuf/struct.js +39 -33
  18. package/dist/esm/generated/google/protobuf/timestamp.js +9 -6
  19. package/dist/esm/generated/index.js +134 -10
  20. package/dist/esm/generated/ottochain/apps/contracts/v1/contract.js +54 -48
  21. package/dist/esm/generated/ottochain/apps/corporate/v1/corporate.js +357 -335
  22. package/dist/esm/generated/ottochain/apps/governance/v1/governance.js +299 -284
  23. package/dist/esm/generated/ottochain/apps/identity/v1/agent.js +47 -38
  24. package/dist/esm/generated/ottochain/apps/identity/v1/attestation.js +50 -44
  25. package/dist/esm/generated/ottochain/apps/markets/v1/market.js +86 -77
  26. package/dist/esm/generated/ottochain/apps/oracles/v1/oracle.js +72 -66
  27. package/dist/esm/generated/ottochain/v1/common.js +4 -1
  28. package/dist/esm/generated/ottochain/v1/fiber.js +96 -90
  29. package/dist/esm/generated/ottochain/v1/messages.js +82 -79
  30. package/dist/esm/generated/ottochain/v1/records.js +140 -137
  31. package/dist/esm/index.js +86 -18
  32. package/dist/esm/{metakit → ottochain}/drop-nulls.js +5 -1
  33. package/dist/esm/ottochain/index.js +56 -3
  34. package/dist/esm/ottochain/metagraph-client.js +65 -10
  35. package/dist/esm/{metakit → ottochain}/normalize.js +11 -4
  36. package/dist/esm/ottochain/snapshot.js +20 -10
  37. package/dist/esm/ottochain/transaction.js +251 -0
  38. package/dist/esm/ottochain/types.js +2 -1
  39. package/dist/esm/types.js +7 -2
  40. package/dist/esm/validation.js +76 -65
  41. package/dist/esm/verify.js +17 -0
  42. package/dist/types/index.d.ts +14 -5
  43. package/dist/types/ottochain/index.d.ts +4 -0
  44. package/dist/types/ottochain/metagraph-client.d.ts +28 -0
  45. package/dist/types/ottochain/transaction.d.ts +283 -0
  46. package/dist/types/validation.d.ts +8 -8
  47. package/dist/types/verify.d.ts +9 -0
  48. package/package.json +5 -3
  49. package/dist/cjs/metakit/binary.js +0 -58
  50. package/dist/cjs/metakit/canonicalize.js +0 -40
  51. package/dist/cjs/metakit/codec.js +0 -45
  52. package/dist/cjs/metakit/currency-transaction.js +0 -319
  53. package/dist/cjs/metakit/currency-types.js +0 -13
  54. package/dist/cjs/metakit/hash.js +0 -84
  55. package/dist/cjs/metakit/index.js +0 -74
  56. package/dist/cjs/metakit/network/client.js +0 -78
  57. package/dist/cjs/metakit/network/currency-l1-client.js +0 -101
  58. package/dist/cjs/metakit/network/data-l1-client.js +0 -76
  59. package/dist/cjs/metakit/network/index.js +0 -16
  60. package/dist/cjs/metakit/network/types.js +0 -20
  61. package/dist/cjs/metakit/sign.js +0 -120
  62. package/dist/cjs/metakit/signed-object.js +0 -100
  63. package/dist/cjs/metakit/types.js +0 -14
  64. package/dist/cjs/metakit/verify.js +0 -217
  65. package/dist/cjs/metakit/wallet.js +0 -127
  66. package/dist/esm/metakit/binary.js +0 -53
  67. package/dist/esm/metakit/canonicalize.js +0 -33
  68. package/dist/esm/metakit/codec.js +0 -38
  69. package/dist/esm/metakit/currency-transaction.js +0 -306
  70. package/dist/esm/metakit/currency-types.js +0 -10
  71. package/dist/esm/metakit/hash.js +0 -77
  72. package/dist/esm/metakit/index.js +0 -30
  73. package/dist/esm/metakit/network/client.js +0 -74
  74. package/dist/esm/metakit/network/currency-l1-client.js +0 -97
  75. package/dist/esm/metakit/network/data-l1-client.js +0 -72
  76. package/dist/esm/metakit/network/index.js +0 -9
  77. package/dist/esm/metakit/network/types.js +0 -16
  78. package/dist/esm/metakit/sign.js +0 -114
  79. package/dist/esm/metakit/signed-object.js +0 -94
  80. package/dist/esm/metakit/types.js +0 -11
  81. package/dist/esm/metakit/verify.js +0 -210
  82. package/dist/esm/metakit/wallet.js +0 -117
  83. package/dist/types/metakit/binary.d.ts +0 -38
  84. package/dist/types/metakit/canonicalize.d.ts +0 -26
  85. package/dist/types/metakit/codec.d.ts +0 -16
  86. package/dist/types/metakit/currency-transaction.d.ts +0 -157
  87. package/dist/types/metakit/currency-types.d.ts +0 -55
  88. package/dist/types/metakit/hash.d.ts +0 -50
  89. package/dist/types/metakit/index.d.ts +0 -23
  90. package/dist/types/metakit/network/client.d.ts +0 -23
  91. package/dist/types/metakit/network/currency-l1-client.d.ts +0 -71
  92. package/dist/types/metakit/network/data-l1-client.d.ts +0 -57
  93. package/dist/types/metakit/network/index.d.ts +0 -10
  94. package/dist/types/metakit/network/types.d.ts +0 -74
  95. package/dist/types/metakit/sign.d.ts +0 -65
  96. package/dist/types/metakit/signed-object.d.ts +0 -66
  97. package/dist/types/metakit/types.d.ts +0 -67
  98. package/dist/types/metakit/verify.d.ts +0 -55
  99. package/dist/types/metakit/wallet.d.ts +0 -70
  100. /package/dist/cjs/{metakit → ottochain}/drop-nulls.js +0 -0
  101. /package/dist/cjs/{metakit → ottochain}/normalize.js +0 -0
  102. /package/dist/types/{metakit → ottochain}/drop-nulls.d.ts +0 -0
  103. /package/dist/types/{metakit → ottochain}/normalize.d.ts +0 -0
@@ -11,3 +11,7 @@ export type { CurrencySnapshotResponse } from './snapshot.js';
11
11
  export { decodeOnChainState, getSnapshotOnChainState, getLatestOnChainState, getLogsForFiber, getEventReceipts, getScriptInvocations, extractOnChainState, } from './snapshot.js';
12
12
  export type { Checkpoint, MetagraphClientConfig, SubscribeOptions, FiberStateCallback, Unsubscribe, } from './metagraph-client.js';
13
13
  export { MetagraphClient } from './metagraph-client.js';
14
+ export { createTransitionPayload, createArchivePayload, createInvokeScriptPayload, signTransaction, addTransactionSignature, getPublicKeyForRegistration, createStateMachinePayload, createScriptPayload, createDataTransactionRequest, } from './transaction.js';
15
+ export type { CreateStateMachineParams, CreateStateMachineMessage, CreateScriptParams, CreateScriptMessage, DataTransactionRequest, TransitionParams, TransitionStateMachineMessage, ArchiveParams, ArchiveStateMachineMessage, InvokeScriptParams, InvokeScriptMessage, } from './transaction.js';
16
+ export { normalizeCreateStateMachine, normalizeTransitionStateMachine, normalizeArchiveStateMachine, normalizeMessage, } from './normalize.js';
17
+ export { dropNulls } from './drop-nulls.js';
@@ -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 '@constellation-network/metagraph-sdk';
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
  }
@@ -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 '@constellation-network/metagraph-sdk';
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;
@@ -142,11 +142,11 @@ export declare const TransactionReferenceSchema: z.ZodObject<{
142
142
  ordinal: z.ZodNumber;
143
143
  hash: z.ZodString;
144
144
  }, "strip", z.ZodTypeAny, {
145
- hash: string;
146
145
  ordinal: number;
147
- }, {
148
146
  hash: string;
147
+ }, {
149
148
  ordinal: number;
149
+ hash: string;
150
150
  }>;
151
151
  /**
152
152
  * Schema for CurrencyTransactionValue
@@ -191,11 +191,11 @@ export declare const CurrencyTransactionSchema: z.ZodObject<{
191
191
  ordinal: z.ZodNumber;
192
192
  hash: z.ZodString;
193
193
  }, "strip", z.ZodTypeAny, {
194
- hash: string;
195
194
  ordinal: number;
196
- }, {
197
195
  hash: string;
196
+ }, {
198
197
  ordinal: number;
198
+ hash: string;
199
199
  }>;
200
200
  }, "strip", z.ZodTypeAny, {
201
201
  value: {
@@ -205,8 +205,8 @@ export declare const CurrencyTransactionSchema: z.ZodObject<{
205
205
  fee: number;
206
206
  };
207
207
  parent: {
208
- hash: string;
209
208
  ordinal: number;
209
+ hash: string;
210
210
  };
211
211
  }, {
212
212
  value: {
@@ -216,8 +216,8 @@ export declare const CurrencyTransactionSchema: z.ZodObject<{
216
216
  fee?: number | undefined;
217
217
  };
218
218
  parent: {
219
- hash: string;
220
219
  ordinal: number;
220
+ hash: string;
221
221
  };
222
222
  }>;
223
223
  /**
@@ -233,14 +233,14 @@ export declare const TransferParamsSchema: z.ZodObject<{
233
233
  amount: z.ZodNumber;
234
234
  fee: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
235
235
  }, "strip", z.ZodTypeAny, {
236
- amount: number;
237
236
  from: string;
238
237
  to: string;
238
+ amount: number;
239
239
  fee: number;
240
240
  }, {
241
- amount: number;
242
241
  from: string;
243
242
  to: string;
243
+ amount: number;
244
244
  fee?: number | undefined;
245
245
  }>;
246
246
  /**
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Backward-compatible verify wrapper.
3
+ *
4
+ * The package embeds `mode: "standard"|"dataUpdate"` in signed objects and
5
+ * its verify() ignores the `isDataUpdate` parameter when `mode` is present.
6
+ * This wrapper strips `mode` so callers' explicit `isDataUpdate` always wins.
7
+ */
8
+ import type { Signed, VerificationResult } from '@constellation-network/metagraph-sdk';
9
+ export declare function verify<T>(signed: Signed<T>, isDataUpdate?: boolean): VerificationResult;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ottochain/sdk",
3
- "version": "1.1.1",
3
+ "version": "1.3.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",
@@ -104,6 +104,7 @@
104
104
  },
105
105
  "dependencies": {
106
106
  "@bufbuild/protobuf": "^2.11.0",
107
+ "@constellation-network/metagraph-sdk": "^0.2.0",
107
108
  "@stardust-collective/dag4": "^2.6.0",
108
109
  "@stardust-collective/dag4-keystore": "^2.6.0",
109
110
  "canonicalize": "^2.1.0",
@@ -112,8 +113,9 @@
112
113
  "zod": "^3.22.0"
113
114
  },
114
115
  "devDependencies": {
116
+ "@babel/preset-env": "^7.29.0",
115
117
  "@types/jest": "^30.0.0",
116
- "@types/node": "^20.0.0",
118
+ "@types/node": "^25.3.3",
117
119
  "@typescript-eslint/eslint-plugin": "^8.56.1",
118
120
  "@typescript-eslint/parser": "^8.56.1",
119
121
  "eslint": "^9.39.3",
@@ -128,7 +130,7 @@
128
130
  "@stardust-collective/dag4": "^2.6.0"
129
131
  },
130
132
  "engines": {
131
- "node": ">=18.0.0"
133
+ "node": ">=20.19.0"
132
134
  },
133
135
  "publishConfig": {
134
136
  "registry": "https://registry.npmjs.org"
@@ -1,58 +0,0 @@
1
- "use strict";
2
- /**
3
- * Binary Encoding
4
- *
5
- * Converts JSON data to binary format for cryptographic operations.
6
- * Supports both regular encoding and DataUpdate encoding with Constellation prefix.
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.encodeDataUpdate = exports.toBytes = void 0;
10
- const canonicalize_js_1 = require("./canonicalize.js");
11
- const types_js_1 = require("./types.js");
12
- /**
13
- * Convert data to binary bytes for signing
14
- *
15
- * For regular data:
16
- * JSON -> RFC 8785 canonicalization -> UTF-8 bytes
17
- *
18
- * For DataUpdate (isDataUpdate=true):
19
- * JSON -> RFC 8785 -> UTF-8 -> Base64 -> prepend Constellation prefix -> UTF-8 bytes
20
- *
21
- * @param data - Any JSON-serializable object
22
- * @param isDataUpdate - If true, applies DataUpdate encoding with Constellation prefix
23
- * @returns Binary bytes as Uint8Array
24
- *
25
- * @example
26
- * ```typescript
27
- * // Regular encoding
28
- * const bytes = toBytes({ action: 'test' });
29
- *
30
- * // DataUpdate encoding
31
- * const updateBytes = toBytes({ action: 'test' }, true);
32
- * ```
33
- */
34
- function toBytes(data, isDataUpdate = false) {
35
- const canonicalJson = (0, canonicalize_js_1.canonicalize)(data);
36
- const utf8Bytes = new TextEncoder().encode(canonicalJson);
37
- if (isDataUpdate) {
38
- // Base64 encode the UTF-8 bytes
39
- const base64String = Buffer.from(utf8Bytes).toString('base64');
40
- // Create the wrapped string with Constellation prefix
41
- const wrappedString = `${types_js_1.CONSTELLATION_PREFIX}${base64String.length}\n${base64String}`;
42
- return new TextEncoder().encode(wrappedString);
43
- }
44
- return utf8Bytes;
45
- }
46
- exports.toBytes = toBytes;
47
- /**
48
- * Encode data as a DataUpdate with Constellation prefix
49
- *
50
- * This is equivalent to `toBytes(data, true)`.
51
- *
52
- * @param data - Any JSON-serializable object
53
- * @returns Binary bytes with Constellation prefix
54
- */
55
- function encodeDataUpdate(data) {
56
- return toBytes(data, true);
57
- }
58
- exports.encodeDataUpdate = encodeDataUpdate;
@@ -1,40 +0,0 @@
1
- "use strict";
2
- /**
3
- * RFC 8785 JSON Canonicalization
4
- *
5
- * Provides deterministic JSON serialization according to RFC 8785.
6
- * This ensures identical JSON objects always produce identical strings.
7
- */
8
- var __importDefault = (this && this.__importDefault) || function (mod) {
9
- return (mod && mod.__esModule) ? mod : { "default": mod };
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.canonicalize = void 0;
13
- const canonicalize_1 = __importDefault(require("canonicalize"));
14
- /**
15
- * Canonicalize JSON data according to RFC 8785
16
- *
17
- * Key features:
18
- * - Object keys sorted by UTF-16BE binary comparison
19
- * - Numbers serialized in shortest decimal representation
20
- * - No whitespace
21
- * - Proper Unicode escaping
22
- *
23
- * @param data - Any JSON-serializable object
24
- * @returns Canonical JSON string
25
- * @throws Error if data cannot be serialized to JSON
26
- *
27
- * @example
28
- * ```typescript
29
- * const canonical = canonicalize({ b: 2, a: 1 });
30
- * // Returns: '{"a":1,"b":2}'
31
- * ```
32
- */
33
- function canonicalize(data) {
34
- const result = (0, canonicalize_1.default)(data);
35
- if (result === undefined) {
36
- throw new Error('Failed to canonicalize data: data cannot be serialized to JSON');
37
- }
38
- return result;
39
- }
40
- exports.canonicalize = canonicalize;
@@ -1,45 +0,0 @@
1
- "use strict";
2
- /**
3
- * Codec Utilities
4
- *
5
- * Encoding/decoding utilities for the Constellation signature protocol.
6
- * Re-exports from binary.ts for backwards compatibility and provides additional utilities.
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.decodeDataUpdate = exports.CONSTELLATION_PREFIX = exports.encodeDataUpdate = exports.toBytes = void 0;
10
- var binary_js_1 = require("./binary.js");
11
- Object.defineProperty(exports, "toBytes", { enumerable: true, get: function () { return binary_js_1.toBytes; } });
12
- Object.defineProperty(exports, "encodeDataUpdate", { enumerable: true, get: function () { return binary_js_1.encodeDataUpdate; } });
13
- var types_js_1 = require("./types.js");
14
- Object.defineProperty(exports, "CONSTELLATION_PREFIX", { enumerable: true, get: function () { return types_js_1.CONSTELLATION_PREFIX; } });
15
- /**
16
- * Decode a DataUpdate encoded message back to its original JSON
17
- *
18
- * @param bytes - DataUpdate encoded bytes
19
- * @returns Decoded JSON object
20
- * @throws Error if bytes are not valid DataUpdate encoding
21
- */
22
- function decodeDataUpdate(bytes) {
23
- const text = new TextDecoder().decode(bytes);
24
- // Validate prefix
25
- if (!text.startsWith('\x19Constellation Signed Data:\n')) {
26
- throw new Error('Invalid DataUpdate encoding: missing Constellation prefix');
27
- }
28
- // Parse the format: \x19Constellation Signed Data:\n{length}\n{base64}
29
- const withoutPrefix = text.slice('\x19Constellation Signed Data:\n'.length);
30
- const newlineIndex = withoutPrefix.indexOf('\n');
31
- if (newlineIndex === -1) {
32
- throw new Error('Invalid DataUpdate encoding: missing length delimiter');
33
- }
34
- const lengthStr = withoutPrefix.slice(0, newlineIndex);
35
- const base64Data = withoutPrefix.slice(newlineIndex + 1);
36
- const expectedLength = parseInt(lengthStr, 10);
37
- if (isNaN(expectedLength) || base64Data.length !== expectedLength) {
38
- throw new Error('Invalid DataUpdate encoding: length mismatch');
39
- }
40
- // Decode base64 to UTF-8 JSON
41
- const jsonBytes = Buffer.from(base64Data, 'base64');
42
- const jsonString = new TextDecoder().decode(jsonBytes);
43
- return JSON.parse(jsonString);
44
- }
45
- exports.decodeDataUpdate = decodeDataUpdate;