@ottochain/sdk 1.0.3 → 1.1.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 (153) hide show
  1. package/dist/cjs/generated/index.js +11 -1
  2. package/dist/cjs/metakit/drop-nulls.js +50 -0
  3. package/dist/cjs/metakit/normalize.js +147 -0
  4. package/dist/cjs/ottochain/metagraph-client.js +147 -0
  5. package/dist/cjs/validation.js +1 -1
  6. package/dist/esm/generated/index.js +11 -1
  7. package/dist/esm/metakit/drop-nulls.js +46 -0
  8. package/dist/esm/metakit/normalize.js +140 -0
  9. package/dist/esm/ottochain/metagraph-client.js +147 -0
  10. package/dist/esm/validation.js +1 -1
  11. package/dist/types/generated/index.d.ts +11 -1
  12. package/dist/types/metakit/drop-nulls.d.ts +29 -0
  13. package/dist/types/metakit/normalize.d.ts +67 -0
  14. package/dist/types/ottochain/index.d.ts +1 -1
  15. package/dist/types/ottochain/metagraph-client.d.ts +90 -0
  16. package/package.json +12 -12
  17. package/dist/apps/contracts/index.d.ts +0 -21
  18. package/dist/apps/contracts/index.js +0 -39
  19. package/dist/apps/contracts/types.d.ts +0 -24
  20. package/dist/apps/contracts/types.js +0 -48
  21. package/dist/apps/identity/index.d.ts +0 -22
  22. package/dist/apps/identity/index.js +0 -40
  23. package/dist/apps/identity/types.d.ts +0 -30
  24. package/dist/apps/identity/types.js +0 -53
  25. package/dist/apps/index.d.ts +0 -29
  26. package/dist/apps/index.js +0 -60
  27. package/dist/apps/markets/index.d.ts +0 -26
  28. package/dist/apps/markets/index.js +0 -46
  29. package/dist/apps/markets/types.d.ts +0 -185
  30. package/dist/apps/markets/types.js +0 -252
  31. package/dist/apps/oracles/index.d.ts +0 -26
  32. package/dist/apps/oracles/index.js +0 -46
  33. package/dist/apps/oracles/types.d.ts +0 -211
  34. package/dist/apps/oracles/types.js +0 -306
  35. package/dist/cjs/apps/contracts/types.js +0 -48
  36. package/dist/cjs/apps/corporate/types.js +0 -44
  37. package/dist/cjs/apps/governance/types.js +0 -42
  38. package/dist/cjs/apps/identity/types.js +0 -53
  39. package/dist/cjs/apps/markets/types.js +0 -219
  40. package/dist/cjs/apps/oracles/types.js +0 -282
  41. package/dist/cjs/generated/ottochain/apps/contracts/v1/contract_pb.js +0 -100
  42. package/dist/cjs/generated/ottochain/apps/corporate/v1/corporate_pb.js +0 -392
  43. package/dist/cjs/generated/ottochain/apps/governance/v1/governance_pb.js +0 -235
  44. package/dist/cjs/generated/ottochain/apps/identity/v1/agent_pb.js +0 -116
  45. package/dist/cjs/generated/ottochain/apps/identity/v1/attestation_pb.js +0 -79
  46. package/dist/cjs/generated/ottochain/apps/markets/v1/market_pb.js +0 -151
  47. package/dist/cjs/generated/ottochain/apps/oracles/v1/oracle_pb.js +0 -109
  48. package/dist/cjs/generated/ottochain/v1/common_pb.js +0 -37
  49. package/dist/cjs/generated/ottochain/v1/fiber_pb.js +0 -86
  50. package/dist/cjs/generated/ottochain/v1/messages_pb.js +0 -44
  51. package/dist/cjs/generated/ottochain/v1/records_pb.js +0 -44
  52. package/dist/errors.d.ts +0 -221
  53. package/dist/errors.js +0 -293
  54. package/dist/esm/apps/contracts/types.js +0 -44
  55. package/dist/esm/apps/corporate/types.js +0 -38
  56. package/dist/esm/apps/governance/types.js +0 -35
  57. package/dist/esm/apps/identity/types.js +0 -50
  58. package/dist/esm/apps/markets/types.js +0 -206
  59. package/dist/esm/apps/oracles/types.js +0 -267
  60. package/dist/esm/generated/ottochain/apps/contracts/v1/contract_pb.js +0 -97
  61. package/dist/esm/generated/ottochain/apps/corporate/v1/corporate_pb.js +0 -389
  62. package/dist/esm/generated/ottochain/apps/governance/v1/governance_pb.js +0 -232
  63. package/dist/esm/generated/ottochain/apps/identity/v1/agent_pb.js +0 -113
  64. package/dist/esm/generated/ottochain/apps/identity/v1/attestation_pb.js +0 -76
  65. package/dist/esm/generated/ottochain/apps/markets/v1/market_pb.js +0 -148
  66. package/dist/esm/generated/ottochain/apps/oracles/v1/oracle_pb.js +0 -106
  67. package/dist/esm/generated/ottochain/v1/common_pb.js +0 -34
  68. package/dist/esm/generated/ottochain/v1/fiber_pb.js +0 -83
  69. package/dist/esm/generated/ottochain/v1/messages_pb.js +0 -41
  70. package/dist/esm/generated/ottochain/v1/records_pb.js +0 -41
  71. package/dist/generated/index.d.ts +0 -15
  72. package/dist/generated/index.js +0 -34
  73. package/dist/generated/ottochain/apps/contracts/v1/contract_pb.d.ts +0 -274
  74. package/dist/generated/ottochain/apps/contracts/v1/contract_pb.js +0 -100
  75. package/dist/generated/ottochain/apps/identity/v1/agent_pb.d.ts +0 -211
  76. package/dist/generated/ottochain/apps/identity/v1/agent_pb.js +0 -116
  77. package/dist/generated/ottochain/apps/identity/v1/attestation_pb.d.ts +0 -238
  78. package/dist/generated/ottochain/apps/identity/v1/attestation_pb.js +0 -79
  79. package/dist/generated/ottochain/apps/markets/v1/market_pb.d.ts +0 -436
  80. package/dist/generated/ottochain/apps/markets/v1/market_pb.js +0 -151
  81. package/dist/generated/ottochain/apps/oracles/v1/oracle_pb.d.ts +0 -393
  82. package/dist/generated/ottochain/apps/oracles/v1/oracle_pb.js +0 -109
  83. package/dist/generated/ottochain/v1/common_pb.d.ts +0 -86
  84. package/dist/generated/ottochain/v1/common_pb.js +0 -37
  85. package/dist/generated/ottochain/v1/fiber_pb.d.ts +0 -292
  86. package/dist/generated/ottochain/v1/fiber_pb.js +0 -86
  87. package/dist/generated/ottochain/v1/messages_pb.d.ts +0 -190
  88. package/dist/generated/ottochain/v1/messages_pb.js +0 -44
  89. package/dist/generated/ottochain/v1/records_pb.d.ts +0 -221
  90. package/dist/generated/ottochain/v1/records_pb.js +0 -44
  91. package/dist/index.d.ts +0 -21
  92. package/dist/index.js +0 -77
  93. package/dist/metakit/binary.d.ts +0 -38
  94. package/dist/metakit/binary.js +0 -58
  95. package/dist/metakit/canonicalize.d.ts +0 -26
  96. package/dist/metakit/canonicalize.js +0 -40
  97. package/dist/metakit/codec.d.ts +0 -16
  98. package/dist/metakit/codec.js +0 -45
  99. package/dist/metakit/currency-transaction.d.ts +0 -157
  100. package/dist/metakit/currency-transaction.js +0 -319
  101. package/dist/metakit/currency-types.d.ts +0 -55
  102. package/dist/metakit/currency-types.js +0 -13
  103. package/dist/metakit/hash.d.ts +0 -50
  104. package/dist/metakit/hash.js +0 -84
  105. package/dist/metakit/index.d.ts +0 -23
  106. package/dist/metakit/index.js +0 -74
  107. package/dist/metakit/network/client.d.ts +0 -23
  108. package/dist/metakit/network/client.js +0 -78
  109. package/dist/metakit/network/currency-l1-client.d.ts +0 -71
  110. package/dist/metakit/network/currency-l1-client.js +0 -101
  111. package/dist/metakit/network/data-l1-client.d.ts +0 -57
  112. package/dist/metakit/network/data-l1-client.js +0 -76
  113. package/dist/metakit/network/index.d.ts +0 -10
  114. package/dist/metakit/network/index.js +0 -16
  115. package/dist/metakit/network/types.d.ts +0 -74
  116. package/dist/metakit/network/types.js +0 -20
  117. package/dist/metakit/sign.d.ts +0 -65
  118. package/dist/metakit/sign.js +0 -120
  119. package/dist/metakit/signed-object.d.ts +0 -66
  120. package/dist/metakit/signed-object.js +0 -100
  121. package/dist/metakit/types.d.ts +0 -67
  122. package/dist/metakit/types.js +0 -14
  123. package/dist/metakit/verify.d.ts +0 -55
  124. package/dist/metakit/verify.js +0 -217
  125. package/dist/metakit/wallet.d.ts +0 -70
  126. package/dist/metakit/wallet.js +0 -127
  127. package/dist/ottochain/index.d.ts +0 -13
  128. package/dist/ottochain/index.js +0 -45
  129. package/dist/ottochain/metagraph-client.d.ts +0 -111
  130. package/dist/ottochain/metagraph-client.js +0 -157
  131. package/dist/ottochain/snapshot.d.ts +0 -86
  132. package/dist/ottochain/snapshot.js +0 -110
  133. package/dist/ottochain/types.d.ts +0 -278
  134. package/dist/ottochain/types.js +0 -11
  135. package/dist/types/apps/contracts/types.d.ts +0 -24
  136. package/dist/types/apps/corporate/types.d.ts +0 -9861
  137. package/dist/types/apps/governance/types.d.ts +0 -344
  138. package/dist/types/apps/identity/types.d.ts +0 -30
  139. package/dist/types/apps/markets/types.d.ts +0 -155
  140. package/dist/types/apps/oracles/types.d.ts +0 -193
  141. package/dist/types/generated/ottochain/apps/contracts/v1/contract_pb.d.ts +0 -274
  142. package/dist/types/generated/ottochain/apps/corporate/v1/corporate_pb.d.ts +0 -1172
  143. package/dist/types/generated/ottochain/apps/governance/v1/governance_pb.d.ts +0 -772
  144. package/dist/types/generated/ottochain/apps/identity/v1/agent_pb.d.ts +0 -211
  145. package/dist/types/generated/ottochain/apps/identity/v1/attestation_pb.d.ts +0 -238
  146. package/dist/types/generated/ottochain/apps/markets/v1/market_pb.d.ts +0 -436
  147. package/dist/types/generated/ottochain/apps/oracles/v1/oracle_pb.d.ts +0 -393
  148. package/dist/types/generated/ottochain/v1/common_pb.d.ts +0 -86
  149. package/dist/types/generated/ottochain/v1/fiber_pb.d.ts +0 -292
  150. package/dist/types/generated/ottochain/v1/messages_pb.d.ts +0 -190
  151. package/dist/types/generated/ottochain/v1/records_pb.d.ts +0 -221
  152. package/dist/validation.d.ts +0 -449
  153. package/dist/validation.js +0 -312
@@ -1,312 +0,0 @@
1
- "use strict";
2
- /**
3
- * Input Validation with Zod Schemas
4
- *
5
- * Provides runtime validation for SDK types using Zod.
6
- *
7
- * @packageDocumentation
8
- */
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");
13
- // ============================================================================
14
- // Primitive Schemas
15
- // ============================================================================
16
- /**
17
- * Schema for a hex string of specific length
18
- */
19
- const hexString = (length) => {
20
- let schema = zod_1.z.string().regex(/^[0-9a-fA-F]+$/, 'Must be a valid hex string');
21
- if (length !== undefined) {
22
- schema = schema.length(length, `Must be exactly ${length} characters`);
23
- }
24
- return schema;
25
- };
26
- /**
27
- * Schema for a DAG address
28
- */
29
- exports.DagAddressSchema = zod_1.z
30
- .string()
31
- .regex(/^DAG[0-9][a-zA-Z0-9]{36}$/, 'Must be a valid DAG address');
32
- // ============================================================================
33
- // Core Type Schemas
34
- // ============================================================================
35
- /**
36
- * Schema for a private key (64-character hex string)
37
- */
38
- exports.PrivateKeySchema = hexString(64).describe('Private key in hex format (64 characters)');
39
- /**
40
- * Schema for a public key (128 or 130 character hex string)
41
- */
42
- exports.PublicKeySchema = zod_1.z
43
- .string()
44
- .regex(/^(04)?[0-9a-fA-F]{128}$/, 'Must be a valid public key (128 or 130 hex chars)')
45
- .describe('Public key in hex format (with optional 04 prefix)');
46
- /**
47
- * Schema for a KeyPair
48
- */
49
- exports.KeyPairSchema = zod_1.z.object({
50
- /** Private key in hex format */
51
- privateKey: exports.PrivateKeySchema,
52
- /** Public key in hex format (uncompressed, with 04 prefix) */
53
- publicKey: exports.PublicKeySchema,
54
- /** DAG address derived from the public key */
55
- address: exports.DagAddressSchema,
56
- });
57
- /**
58
- * Schema for a SignatureProof
59
- */
60
- exports.SignatureProofSchema = zod_1.z.object({
61
- /** Public key hex (uncompressed, without 04 prefix) - 128 characters */
62
- id: hexString(128),
63
- /** DER-encoded ECDSA signature in hex format */
64
- signature: hexString(),
65
- });
66
- /**
67
- * Schema for a Signed object (generic)
68
- */
69
- const SignedSchema = (valueSchema) => zod_1.z.object({
70
- value: valueSchema,
71
- proofs: zod_1.z.array(exports.SignatureProofSchema).min(1, 'At least one proof is required'),
72
- });
73
- exports.SignedSchema = SignedSchema;
74
- // ============================================================================
75
- // Transaction Schemas
76
- // ============================================================================
77
- /**
78
- * Schema for TransactionReference
79
- */
80
- exports.TransactionReferenceSchema = zod_1.z.object({
81
- ordinal: zod_1.z.number().int().min(0),
82
- hash: zod_1.z.string().min(1),
83
- });
84
- /**
85
- * Schema for CurrencyTransactionValue
86
- */
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),
92
- });
93
- /**
94
- * Schema for CurrencyTransaction
95
- */
96
- exports.CurrencyTransactionSchema = zod_1.z.object({
97
- value: exports.CurrencyTransactionValueSchema,
98
- parent: exports.TransactionReferenceSchema,
99
- });
100
- /**
101
- * Schema for TransferParams
102
- */
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),
108
- });
109
- // ============================================================================
110
- // Identity Schemas
111
- // ============================================================================
112
- /**
113
- * Schema for AgentIdentity registration
114
- */
115
- exports.AgentIdentityRegistrationSchema = zod_1.z.object({
116
- /** Public key in hex format */
117
- publicKey: exports.PublicKeySchema,
118
- /** Display name for the agent */
119
- displayName: zod_1.z.string().min(1).max(64),
120
- /** Initial reputation (default: 10) */
121
- reputation: zod_1.z.number().int().min(0).optional().default(10),
122
- });
123
- /**
124
- * Schema for PlatformLink
125
- */
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),
131
- });
132
- // ============================================================================
133
- // Contract Schemas
134
- // ============================================================================
135
- /**
136
- * Schema for contract terms (flexible structure)
137
- */
138
- exports.ContractTermsSchema = zod_1.z.record(zod_1.z.unknown());
139
- /**
140
- * Schema for ProposeContractRequest
141
- */
142
- exports.ProposeContractRequestSchema = zod_1.z.object({
143
- /** Proposer's DAG address */
144
- proposer: exports.DagAddressSchema,
145
- /** Counterparty's DAG address */
146
- counterparty: exports.DagAddressSchema,
147
- /** Contract terms */
148
- terms: exports.ContractTermsSchema,
149
- /** Human-readable description */
150
- description: zod_1.z.string().min(1).max(1000),
151
- });
152
- /**
153
- * Schema for AcceptContractRequest
154
- */
155
- exports.AcceptContractRequestSchema = zod_1.z.object({
156
- /** Contract ID to accept */
157
- contractId: zod_1.z.string().min(1),
158
- /** Acceptor's DAG address */
159
- acceptor: exports.DagAddressSchema,
160
- });
161
- /**
162
- * Schema for CompleteContractRequest
163
- */
164
- exports.CompleteContractRequestSchema = zod_1.z.object({
165
- /** Contract ID to complete */
166
- contractId: zod_1.z.string().min(1),
167
- /** Completer's DAG address */
168
- completer: exports.DagAddressSchema,
169
- /** Proof of completion */
170
- proof: zod_1.z.string().min(1),
171
- });
172
- // ============================================================================
173
- // Validation Helpers
174
- // ============================================================================
175
- /**
176
- * Validate data against a Zod schema
177
- *
178
- * @param schema - Zod schema to validate against
179
- * @param data - Data to validate
180
- * @param fieldName - Optional field name for error context
181
- * @returns Validated and typed data
182
- * @throws {ValidationError} If validation fails
183
- *
184
- * @example
185
- * ```typescript
186
- * const keyPair = validate(KeyPairSchema, inputData, 'keyPair');
187
- * // keyPair is now typed as ValidatedKeyPair
188
- * ```
189
- */
190
- function validate(schema, data, fieldName) {
191
- const result = schema.safeParse(data);
192
- if (!result.success) {
193
- const issues = result.error.issues;
194
- const firstIssue = issues[0];
195
- // Build a helpful error message
196
- const path = firstIssue.path.length > 0 ? firstIssue.path.join('.') : fieldName || 'input';
197
- const message = `Validation failed for '${path}': ${firstIssue.message}`;
198
- throw new errors_js_1.ValidationError(message, {
199
- field: path,
200
- value: data,
201
- details: {
202
- issues: issues.map((issue) => ({
203
- path: issue.path.join('.'),
204
- message: issue.message,
205
- code: issue.code,
206
- })),
207
- },
208
- });
209
- }
210
- return result.data;
211
- }
212
- exports.validate = validate;
213
- /**
214
- * Validate a private key
215
- *
216
- * @param privateKey - Private key to validate
217
- * @returns Validated private key
218
- * @throws {ValidationError} If validation fails
219
- */
220
- function validatePrivateKey(privateKey) {
221
- return validate(exports.PrivateKeySchema, privateKey, 'privateKey');
222
- }
223
- exports.validatePrivateKey = validatePrivateKey;
224
- /**
225
- * Validate a public key
226
- *
227
- * @param publicKey - Public key to validate
228
- * @returns Validated public key
229
- * @throws {ValidationError} If validation fails
230
- */
231
- function validatePublicKey(publicKey) {
232
- return validate(exports.PublicKeySchema, publicKey, 'publicKey');
233
- }
234
- exports.validatePublicKey = validatePublicKey;
235
- /**
236
- * Validate a DAG address
237
- *
238
- * @param address - Address to validate
239
- * @returns Validated address
240
- * @throws {ValidationError} If validation fails
241
- */
242
- function validateAddress(address) {
243
- return validate(exports.DagAddressSchema, address, 'address');
244
- }
245
- exports.validateAddress = validateAddress;
246
- /**
247
- * Validate a KeyPair
248
- *
249
- * @param keyPair - KeyPair to validate
250
- * @returns Validated KeyPair
251
- * @throws {ValidationError} If validation fails
252
- */
253
- function validateKeyPair(keyPair) {
254
- return validate(exports.KeyPairSchema, keyPair, 'keyPair');
255
- }
256
- exports.validateKeyPair = validateKeyPair;
257
- /**
258
- * Safe validation that returns a result object instead of throwing
259
- *
260
- * @param schema - Zod schema to validate against
261
- * @param data - Data to validate
262
- * @returns Object with success status and data or error
263
- *
264
- * @example
265
- * ```typescript
266
- * const result = safeParse(KeyPairSchema, inputData);
267
- * if (result.success) {
268
- * console.log(result.data.address);
269
- * } else {
270
- * console.log(result.error.message);
271
- * }
272
- * ```
273
- */
274
- function safeParse(schema, data) {
275
- const result = schema.safeParse(data);
276
- if (result.success) {
277
- return { success: true, data: result.data };
278
- }
279
- const issues = result.error.issues;
280
- const firstIssue = issues[0];
281
- const path = firstIssue.path.length > 0 ? firstIssue.path.join('.') : 'input';
282
- const message = `Validation failed for '${path}': ${firstIssue.message}`;
283
- return {
284
- success: false,
285
- error: new errors_js_1.ValidationError(message, {
286
- field: path,
287
- value: data,
288
- details: {
289
- issues: issues.map((issue) => ({
290
- path: issue.path.join('.'),
291
- message: issue.message,
292
- code: issue.code,
293
- })),
294
- },
295
- }),
296
- };
297
- }
298
- exports.safeParse = safeParse;
299
- /**
300
- * Assert that a condition is true, throwing ValidationError if not
301
- *
302
- * @param condition - Condition to check
303
- * @param message - Error message if condition is false
304
- * @param field - Optional field name for context
305
- * @throws {ValidationError} If condition is false
306
- */
307
- function assert(condition, message, field) {
308
- if (!condition) {
309
- throw new errors_js_1.ValidationError(message, { field });
310
- }
311
- }
312
- exports.assert = assert;