@ottochain/sdk 1.4.0 → 1.4.2

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 (36) hide show
  1. package/README.md +8 -7
  2. package/dist/esm/apps/contracts/index.js +10 -28
  3. package/dist/esm/apps/corporate/index.js +24 -79
  4. package/dist/esm/apps/governance/index.js +36 -85
  5. package/dist/esm/apps/identity/constants.js +22 -27
  6. package/dist/esm/apps/identity/index.js +7 -35
  7. package/dist/esm/apps/index.js +6 -32
  8. package/dist/esm/apps/markets/index.js +6 -27
  9. package/dist/esm/apps/oracles/index.js +7 -27
  10. package/dist/esm/errors.js +9 -19
  11. package/dist/esm/generated/google/protobuf/struct.js +33 -39
  12. package/dist/esm/generated/google/protobuf/timestamp.js +6 -9
  13. package/dist/esm/generated/index.js +10 -134
  14. package/dist/esm/generated/ottochain/apps/contracts/v1/contract.js +48 -54
  15. package/dist/esm/generated/ottochain/apps/corporate/v1/corporate.js +335 -357
  16. package/dist/esm/generated/ottochain/apps/governance/v1/governance.js +284 -299
  17. package/dist/esm/generated/ottochain/apps/identity/v1/agent.js +38 -47
  18. package/dist/esm/generated/ottochain/apps/identity/v1/attestation.js +44 -50
  19. package/dist/esm/generated/ottochain/apps/markets/v1/market.js +77 -86
  20. package/dist/esm/generated/ottochain/apps/oracles/v1/oracle.js +66 -72
  21. package/dist/esm/generated/ottochain/v1/common.js +1 -4
  22. package/dist/esm/generated/ottochain/v1/fiber.js +90 -96
  23. package/dist/esm/generated/ottochain/v1/messages.js +79 -82
  24. package/dist/esm/generated/ottochain/v1/records.js +137 -140
  25. package/dist/esm/index.js +13 -70
  26. package/dist/esm/ottochain/drop-nulls.js +1 -5
  27. package/dist/esm/ottochain/index.js +6 -54
  28. package/dist/esm/ottochain/metagraph-client.js +12 -16
  29. package/dist/esm/ottochain/normalize.js +4 -11
  30. package/dist/esm/ottochain/snapshot.js +10 -20
  31. package/dist/esm/ottochain/transaction.js +13 -25
  32. package/dist/esm/ottochain/types.js +1 -2
  33. package/dist/esm/types.js +2 -7
  34. package/dist/esm/validation.js +65 -76
  35. package/dist/esm/verify.js +3 -7
  36. package/package.json +21 -17
package/dist/esm/types.js CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * OttoChain Type Aliases
4
3
  *
@@ -7,19 +6,15 @@
7
6
  *
8
7
  * @packageDocumentation
9
8
  */
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.isValidFiberId = exports.isValidAddress = void 0;
12
9
  /**
13
10
  * Validate a DAG address format.
14
11
  */
15
- function isValidAddress(value) {
12
+ export function isValidAddress(value) {
16
13
  return /^DAG[0-9a-zA-Z]+$/.test(value);
17
14
  }
18
- exports.isValidAddress = isValidAddress;
19
15
  /**
20
16
  * Validate a UUID format.
21
17
  */
22
- function isValidFiberId(value) {
18
+ export function isValidFiberId(value) {
23
19
  return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value);
24
20
  }
25
- exports.isValidFiberId = isValidFiberId;
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * Input Validation with Zod Schemas
4
3
  *
@@ -6,10 +5,8 @@
6
5
  *
7
6
  * @packageDocumentation
8
7
  */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.assert = exports.safeParse = exports.validateKeyPair = exports.validateAddress = exports.validatePublicKey = exports.validatePrivateKey = exports.validate = exports.CompleteContractRequestSchema = exports.AcceptContractRequestSchema = exports.ProposeContractRequestSchema = exports.ContractTermsSchema = exports.PlatformLinkSchema = exports.AgentIdentityRegistrationSchema = exports.TransferParamsSchema = exports.CurrencyTransactionSchema = exports.CurrencyTransactionValueSchema = exports.TransactionReferenceSchema = exports.SignedSchema = exports.SignatureProofSchema = exports.KeyPairSchema = exports.PublicKeySchema = exports.PrivateKeySchema = exports.DagAddressSchema = void 0;
11
- const zod_1 = require("zod");
12
- const errors_js_1 = require("./errors.js");
8
+ import { z } from 'zod';
9
+ import { ValidationError } from './errors.js';
13
10
  // ============================================================================
14
11
  // Primitive Schemas
15
12
  // ============================================================================
@@ -17,7 +14,7 @@ const errors_js_1 = require("./errors.js");
17
14
  * Schema for a hex string of specific length
18
15
  */
19
16
  const hexString = (length) => {
20
- let schema = zod_1.z.string().regex(/^[0-9a-fA-F]+$/, 'Must be a valid hex string');
17
+ let schema = z.string().regex(/^[0-9a-fA-F]+$/, 'Must be a valid hex string');
21
18
  if (length !== undefined) {
22
19
  schema = schema.length(length, `Must be exactly ${length} characters`);
23
20
  }
@@ -26,7 +23,7 @@ const hexString = (length) => {
26
23
  /**
27
24
  * Schema for a DAG address
28
25
  */
29
- exports.DagAddressSchema = zod_1.z
26
+ export const DagAddressSchema = z
30
27
  .string()
31
28
  .regex(/^DAG[0-9][a-zA-Z0-9]{36}$/, 'Must be a valid DAG address');
32
29
  // ============================================================================
@@ -35,29 +32,29 @@ exports.DagAddressSchema = zod_1.z
35
32
  /**
36
33
  * Schema for a private key (64-character hex string)
37
34
  */
38
- exports.PrivateKeySchema = hexString(64).describe('Private key in hex format (64 characters)');
35
+ export const PrivateKeySchema = hexString(64).describe('Private key in hex format (64 characters)');
39
36
  /**
40
37
  * Schema for a public key (128 or 130 character hex string)
41
38
  */
42
- exports.PublicKeySchema = zod_1.z
39
+ export const PublicKeySchema = z
43
40
  .string()
44
41
  .regex(/^(04)?[0-9a-fA-F]{128}$/, 'Must be a valid public key (128 or 130 hex chars)')
45
42
  .describe('Public key in hex format (with optional 04 prefix)');
46
43
  /**
47
44
  * Schema for a KeyPair
48
45
  */
49
- exports.KeyPairSchema = zod_1.z.object({
46
+ export const KeyPairSchema = z.object({
50
47
  /** Private key in hex format */
51
- privateKey: exports.PrivateKeySchema,
48
+ privateKey: PrivateKeySchema,
52
49
  /** Public key in hex format (uncompressed, with 04 prefix) */
53
- publicKey: exports.PublicKeySchema,
50
+ publicKey: PublicKeySchema,
54
51
  /** DAG address derived from the public key */
55
- address: exports.DagAddressSchema,
52
+ address: DagAddressSchema,
56
53
  });
57
54
  /**
58
55
  * Schema for a SignatureProof
59
56
  */
60
- exports.SignatureProofSchema = zod_1.z.object({
57
+ export const SignatureProofSchema = z.object({
61
58
  /** Public key hex (uncompressed, without 04 prefix) - 128 characters */
62
59
  id: hexString(128),
63
60
  /** DER-encoded ECDSA signature in hex format */
@@ -66,45 +63,44 @@ exports.SignatureProofSchema = zod_1.z.object({
66
63
  /**
67
64
  * Schema for a Signed object (generic)
68
65
  */
69
- const SignedSchema = (valueSchema) => zod_1.z.object({
66
+ export const SignedSchema = (valueSchema) => z.object({
70
67
  value: valueSchema,
71
- proofs: zod_1.z.array(exports.SignatureProofSchema).min(1, 'At least one proof is required'),
68
+ proofs: z.array(SignatureProofSchema).min(1, 'At least one proof is required'),
72
69
  });
73
- exports.SignedSchema = SignedSchema;
74
70
  // ============================================================================
75
71
  // Transaction Schemas
76
72
  // ============================================================================
77
73
  /**
78
74
  * Schema for TransactionReference
79
75
  */
80
- exports.TransactionReferenceSchema = zod_1.z.object({
81
- ordinal: zod_1.z.number().int().min(0),
82
- hash: zod_1.z.string().min(1),
76
+ export const TransactionReferenceSchema = z.object({
77
+ ordinal: z.number().int().min(0),
78
+ hash: z.string().min(1),
83
79
  });
84
80
  /**
85
81
  * Schema for CurrencyTransactionValue
86
82
  */
87
- exports.CurrencyTransactionValueSchema = zod_1.z.object({
88
- source: exports.DagAddressSchema,
89
- destination: exports.DagAddressSchema,
90
- amount: zod_1.z.number().int().positive('Amount must be positive'),
91
- fee: zod_1.z.number().int().min(0).default(0),
83
+ export const CurrencyTransactionValueSchema = z.object({
84
+ source: DagAddressSchema,
85
+ destination: DagAddressSchema,
86
+ amount: z.number().int().positive('Amount must be positive'),
87
+ fee: z.number().int().min(0).default(0),
92
88
  });
93
89
  /**
94
90
  * Schema for CurrencyTransaction
95
91
  */
96
- exports.CurrencyTransactionSchema = zod_1.z.object({
97
- value: exports.CurrencyTransactionValueSchema,
98
- parent: exports.TransactionReferenceSchema,
92
+ export const CurrencyTransactionSchema = z.object({
93
+ value: CurrencyTransactionValueSchema,
94
+ parent: TransactionReferenceSchema,
99
95
  });
100
96
  /**
101
97
  * Schema for TransferParams
102
98
  */
103
- exports.TransferParamsSchema = zod_1.z.object({
104
- from: exports.DagAddressSchema,
105
- to: exports.DagAddressSchema,
106
- amount: zod_1.z.number().positive('Amount must be positive'),
107
- fee: zod_1.z.number().min(0).optional().default(0),
99
+ export const TransferParamsSchema = z.object({
100
+ from: DagAddressSchema,
101
+ to: DagAddressSchema,
102
+ amount: z.number().positive('Amount must be positive'),
103
+ fee: z.number().min(0).optional().default(0),
108
104
  });
109
105
  // ============================================================================
110
106
  // Identity Schemas
@@ -112,22 +108,22 @@ exports.TransferParamsSchema = zod_1.z.object({
112
108
  /**
113
109
  * Schema for AgentIdentity registration
114
110
  */
115
- exports.AgentIdentityRegistrationSchema = zod_1.z.object({
111
+ export const AgentIdentityRegistrationSchema = z.object({
116
112
  /** Public key in hex format */
117
- publicKey: exports.PublicKeySchema,
113
+ publicKey: PublicKeySchema,
118
114
  /** Display name for the agent */
119
- displayName: zod_1.z.string().min(1).max(64),
115
+ displayName: z.string().min(1).max(64),
120
116
  /** Initial reputation (default: 10) */
121
- reputation: zod_1.z.number().int().min(0).optional().default(10),
117
+ reputation: z.number().int().min(0).optional().default(10),
122
118
  });
123
119
  /**
124
120
  * Schema for PlatformLink
125
121
  */
126
- exports.PlatformLinkSchema = zod_1.z.object({
127
- platform: zod_1.z.enum(['DISCORD', 'TELEGRAM', 'TWITTER', 'GITHUB', 'CUSTOM']),
128
- platformUserId: zod_1.z.string().min(1),
129
- platformUsername: zod_1.z.string().min(1),
130
- verified: zod_1.z.boolean().optional().default(false),
122
+ export const PlatformLinkSchema = z.object({
123
+ platform: z.enum(['DISCORD', 'TELEGRAM', 'TWITTER', 'GITHUB', 'CUSTOM']),
124
+ platformUserId: z.string().min(1),
125
+ platformUsername: z.string().min(1),
126
+ verified: z.boolean().optional().default(false),
131
127
  });
132
128
  // ============================================================================
133
129
  // Contract Schemas
@@ -135,39 +131,39 @@ exports.PlatformLinkSchema = zod_1.z.object({
135
131
  /**
136
132
  * Schema for contract terms (flexible structure)
137
133
  */
138
- exports.ContractTermsSchema = zod_1.z.record(zod_1.z.string(), zod_1.z.unknown());
134
+ export const ContractTermsSchema = z.record(z.string(), z.unknown());
139
135
  /**
140
136
  * Schema for ProposeContractRequest
141
137
  */
142
- exports.ProposeContractRequestSchema = zod_1.z.object({
138
+ export const ProposeContractRequestSchema = z.object({
143
139
  /** Proposer's DAG address */
144
- proposer: exports.DagAddressSchema,
140
+ proposer: DagAddressSchema,
145
141
  /** Counterparty's DAG address */
146
- counterparty: exports.DagAddressSchema,
142
+ counterparty: DagAddressSchema,
147
143
  /** Contract terms */
148
- terms: exports.ContractTermsSchema,
144
+ terms: ContractTermsSchema,
149
145
  /** Human-readable description */
150
- description: zod_1.z.string().min(1).max(1000),
146
+ description: z.string().min(1).max(1000),
151
147
  });
152
148
  /**
153
149
  * Schema for AcceptContractRequest
154
150
  */
155
- exports.AcceptContractRequestSchema = zod_1.z.object({
151
+ export const AcceptContractRequestSchema = z.object({
156
152
  /** Contract ID to accept */
157
- contractId: zod_1.z.string().min(1),
153
+ contractId: z.string().min(1),
158
154
  /** Acceptor's DAG address */
159
- acceptor: exports.DagAddressSchema,
155
+ acceptor: DagAddressSchema,
160
156
  });
161
157
  /**
162
158
  * Schema for CompleteContractRequest
163
159
  */
164
- exports.CompleteContractRequestSchema = zod_1.z.object({
160
+ export const CompleteContractRequestSchema = z.object({
165
161
  /** Contract ID to complete */
166
- contractId: zod_1.z.string().min(1),
162
+ contractId: z.string().min(1),
167
163
  /** Completer's DAG address */
168
- completer: exports.DagAddressSchema,
164
+ completer: DagAddressSchema,
169
165
  /** Proof of completion */
170
- proof: zod_1.z.string().min(1),
166
+ proof: z.string().min(1),
171
167
  });
172
168
  // ============================================================================
173
169
  // Validation Helpers
@@ -187,7 +183,7 @@ exports.CompleteContractRequestSchema = zod_1.z.object({
187
183
  * // keyPair is now typed as ValidatedKeyPair
188
184
  * ```
189
185
  */
190
- function validate(schema, data, fieldName) {
186
+ export function validate(schema, data, fieldName) {
191
187
  const result = schema.safeParse(data);
192
188
  if (!result.success) {
193
189
  const issues = result.error.issues;
@@ -195,7 +191,7 @@ function validate(schema, data, fieldName) {
195
191
  // Build a helpful error message
196
192
  const path = firstIssue.path.length > 0 ? firstIssue.path.join('.') : fieldName || 'input';
197
193
  const message = `Validation failed for '${path}': ${firstIssue.message}`;
198
- throw new errors_js_1.ValidationError(message, {
194
+ throw new ValidationError(message, {
199
195
  field: path,
200
196
  value: data,
201
197
  details: {
@@ -209,7 +205,6 @@ function validate(schema, data, fieldName) {
209
205
  }
210
206
  return result.data;
211
207
  }
212
- exports.validate = validate;
213
208
  /**
214
209
  * Validate a private key
215
210
  *
@@ -217,10 +212,9 @@ exports.validate = validate;
217
212
  * @returns Validated private key
218
213
  * @throws {ValidationError} If validation fails
219
214
  */
220
- function validatePrivateKey(privateKey) {
221
- return validate(exports.PrivateKeySchema, privateKey, 'privateKey');
215
+ export function validatePrivateKey(privateKey) {
216
+ return validate(PrivateKeySchema, privateKey, 'privateKey');
222
217
  }
223
- exports.validatePrivateKey = validatePrivateKey;
224
218
  /**
225
219
  * Validate a public key
226
220
  *
@@ -228,10 +222,9 @@ exports.validatePrivateKey = validatePrivateKey;
228
222
  * @returns Validated public key
229
223
  * @throws {ValidationError} If validation fails
230
224
  */
231
- function validatePublicKey(publicKey) {
232
- return validate(exports.PublicKeySchema, publicKey, 'publicKey');
225
+ export function validatePublicKey(publicKey) {
226
+ return validate(PublicKeySchema, publicKey, 'publicKey');
233
227
  }
234
- exports.validatePublicKey = validatePublicKey;
235
228
  /**
236
229
  * Validate a DAG address
237
230
  *
@@ -239,10 +232,9 @@ exports.validatePublicKey = validatePublicKey;
239
232
  * @returns Validated address
240
233
  * @throws {ValidationError} If validation fails
241
234
  */
242
- function validateAddress(address) {
243
- return validate(exports.DagAddressSchema, address, 'address');
235
+ export function validateAddress(address) {
236
+ return validate(DagAddressSchema, address, 'address');
244
237
  }
245
- exports.validateAddress = validateAddress;
246
238
  /**
247
239
  * Validate a KeyPair
248
240
  *
@@ -250,10 +242,9 @@ exports.validateAddress = validateAddress;
250
242
  * @returns Validated KeyPair
251
243
  * @throws {ValidationError} If validation fails
252
244
  */
253
- function validateKeyPair(keyPair) {
254
- return validate(exports.KeyPairSchema, keyPair, 'keyPair');
245
+ export function validateKeyPair(keyPair) {
246
+ return validate(KeyPairSchema, keyPair, 'keyPair');
255
247
  }
256
- exports.validateKeyPair = validateKeyPair;
257
248
  /**
258
249
  * Safe validation that returns a result object instead of throwing
259
250
  *
@@ -271,7 +262,7 @@ exports.validateKeyPair = validateKeyPair;
271
262
  * }
272
263
  * ```
273
264
  */
274
- function safeParse(schema, data) {
265
+ export function safeParse(schema, data) {
275
266
  const result = schema.safeParse(data);
276
267
  if (result.success) {
277
268
  return { success: true, data: result.data };
@@ -282,7 +273,7 @@ function safeParse(schema, data) {
282
273
  const message = `Validation failed for '${path}': ${firstIssue.message}`;
283
274
  return {
284
275
  success: false,
285
- error: new errors_js_1.ValidationError(message, {
276
+ error: new ValidationError(message, {
286
277
  field: path,
287
278
  value: data,
288
279
  details: {
@@ -295,7 +286,6 @@ function safeParse(schema, data) {
295
286
  }),
296
287
  };
297
288
  }
298
- exports.safeParse = safeParse;
299
289
  /**
300
290
  * Assert that a condition is true, throwing ValidationError if not
301
291
  *
@@ -304,9 +294,8 @@ exports.safeParse = safeParse;
304
294
  * @param field - Optional field name for context
305
295
  * @throws {ValidationError} If condition is false
306
296
  */
307
- function assert(condition, message, field) {
297
+ export function assert(condition, message, field) {
308
298
  if (!condition) {
309
- throw new errors_js_1.ValidationError(message, { field });
299
+ throw new ValidationError(message, { field });
310
300
  }
311
301
  }
312
- exports.assert = assert;
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * Backward-compatible verify wrapper.
4
3
  *
@@ -6,12 +5,9 @@
6
5
  * its verify() ignores the `isDataUpdate` parameter when `mode` is present.
7
6
  * This wrapper strips `mode` so callers' explicit `isDataUpdate` always wins.
8
7
  */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.verify = void 0;
11
- const metagraph_sdk_1 = require("@constellation-network/metagraph-sdk");
12
- function verify(signed, isDataUpdate) {
8
+ import { verify as _verify } from '@constellation-network/metagraph-sdk';
9
+ export function verify(signed, isDataUpdate) {
13
10
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
14
11
  const { mode, ...rest } = signed;
15
- return (0, metagraph_sdk_1.verify)(rest, isDataUpdate);
12
+ return _verify(rest, isDataUpdate);
16
13
  }
17
- exports.verify = verify;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ottochain/sdk",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
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",
@@ -66,21 +66,6 @@
66
66
  "dist",
67
67
  "README.md"
68
68
  ],
69
- "scripts": {
70
- "build": "npm run build:cjs && npm run build:esm && npm run build:types && npm run build:fixup",
71
- "build:fixup": "echo '{\"type\":\"module\"}' > dist/esm/package.json && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
72
- "build:cjs": "tsc -p tsconfig.cjs.json",
73
- "build:esm": "tsc -p tsconfig.esm.json",
74
- "build:types": "tsc -p tsconfig.types.json",
75
- "test": "jest",
76
- "test:coverage": "jest --coverage",
77
- "lint": "eslint src tests",
78
- "format": "prettier --write src tests",
79
- "generate": "buf generate",
80
- "lint:proto": "buf lint",
81
- "docs": "typedoc",
82
- "docs:watch": "typedoc --watch"
83
- },
84
69
  "keywords": [
85
70
  "ottochain",
86
71
  "constellation",
@@ -114,6 +99,10 @@
114
99
  },
115
100
  "devDependencies": {
116
101
  "@babel/preset-env": "^7.29.0",
102
+ "@commitlint/cli": "^20.4.4",
103
+ "@commitlint/config-conventional": "^19.0.0",
104
+ "@eslint/js": "^9.39.3",
105
+ "@jest/globals": "^30.3.0",
117
106
  "@types/jest": "^30.0.0",
118
107
  "@types/node": "^25.3.3",
119
108
  "@typescript-eslint/eslint-plugin": "^8.56.1",
@@ -134,5 +123,20 @@
134
123
  },
135
124
  "publishConfig": {
136
125
  "registry": "https://registry.npmjs.org"
126
+ },
127
+ "scripts": {
128
+ "build": "npm run build:cjs && npm run build:esm && npm run build:types && npm run build:fixup",
129
+ "build:fixup": "echo '{\"type\":\"module\"}' > dist/esm/package.json && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
130
+ "build:cjs": "tsc -p tsconfig.cjs.json",
131
+ "build:esm": "tsc -p tsconfig.esm.json",
132
+ "build:types": "tsc -p tsconfig.types.json",
133
+ "test": "jest",
134
+ "test:coverage": "jest --coverage",
135
+ "lint": "eslint src tests",
136
+ "format": "prettier --write src tests",
137
+ "generate": "buf generate",
138
+ "lint:proto": "buf lint",
139
+ "docs": "typedoc",
140
+ "docs:watch": "typedoc --watch"
137
141
  }
138
- }
142
+ }