@ottochain/sdk 1.0.2 → 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.
- package/dist/cjs/apps/contracts/state-machines/contract.json +1 -29
- package/dist/cjs/apps/contracts/state-machines/escrow.json +2 -32
- package/dist/cjs/generated/index.js +11 -1
- package/dist/cjs/metakit/drop-nulls.js +50 -0
- package/dist/cjs/metakit/normalize.js +147 -0
- package/dist/cjs/ottochain/metagraph-client.js +147 -0
- package/dist/cjs/validation.js +1 -1
- package/dist/esm/apps/contracts/state-machines/contract.json +1 -29
- package/dist/esm/apps/contracts/state-machines/escrow.json +2 -32
- package/dist/esm/generated/index.js +11 -1
- package/dist/esm/metakit/drop-nulls.js +46 -0
- package/dist/esm/metakit/normalize.js +140 -0
- package/dist/esm/ottochain/metagraph-client.js +147 -0
- package/dist/esm/validation.js +1 -1
- package/dist/types/generated/index.d.ts +11 -1
- package/dist/types/metakit/drop-nulls.d.ts +29 -0
- package/dist/types/metakit/normalize.d.ts +67 -0
- package/dist/types/ottochain/index.d.ts +1 -1
- package/dist/types/ottochain/metagraph-client.d.ts +90 -0
- package/package.json +12 -12
- package/dist/apps/contracts/index.d.ts +0 -21
- package/dist/apps/contracts/index.js +0 -39
- package/dist/apps/contracts/types.d.ts +0 -24
- package/dist/apps/contracts/types.js +0 -48
- package/dist/apps/identity/index.d.ts +0 -22
- package/dist/apps/identity/index.js +0 -40
- package/dist/apps/identity/types.d.ts +0 -30
- package/dist/apps/identity/types.js +0 -53
- package/dist/apps/index.d.ts +0 -29
- package/dist/apps/index.js +0 -60
- package/dist/apps/markets/index.d.ts +0 -26
- package/dist/apps/markets/index.js +0 -46
- package/dist/apps/markets/types.d.ts +0 -185
- package/dist/apps/markets/types.js +0 -252
- package/dist/apps/oracles/index.d.ts +0 -26
- package/dist/apps/oracles/index.js +0 -46
- package/dist/apps/oracles/types.d.ts +0 -211
- package/dist/apps/oracles/types.js +0 -306
- package/dist/cjs/apps/contracts/types.js +0 -48
- package/dist/cjs/apps/corporate/types.js +0 -44
- package/dist/cjs/apps/governance/types.js +0 -42
- package/dist/cjs/apps/identity/types.js +0 -53
- package/dist/cjs/apps/markets/types.js +0 -219
- package/dist/cjs/apps/oracles/types.js +0 -282
- package/dist/cjs/generated/ottochain/apps/contracts/v1/contract_pb.js +0 -100
- package/dist/cjs/generated/ottochain/apps/corporate/v1/corporate_pb.js +0 -392
- package/dist/cjs/generated/ottochain/apps/governance/v1/governance_pb.js +0 -235
- package/dist/cjs/generated/ottochain/apps/identity/v1/agent_pb.js +0 -116
- package/dist/cjs/generated/ottochain/apps/identity/v1/attestation_pb.js +0 -79
- package/dist/cjs/generated/ottochain/apps/markets/v1/market_pb.js +0 -151
- package/dist/cjs/generated/ottochain/apps/oracles/v1/oracle_pb.js +0 -109
- package/dist/cjs/generated/ottochain/v1/common_pb.js +0 -37
- package/dist/cjs/generated/ottochain/v1/fiber_pb.js +0 -86
- package/dist/cjs/generated/ottochain/v1/messages_pb.js +0 -44
- package/dist/cjs/generated/ottochain/v1/records_pb.js +0 -44
- package/dist/errors.d.ts +0 -221
- package/dist/errors.js +0 -293
- package/dist/esm/apps/contracts/types.js +0 -44
- package/dist/esm/apps/corporate/types.js +0 -38
- package/dist/esm/apps/governance/types.js +0 -35
- package/dist/esm/apps/identity/types.js +0 -50
- package/dist/esm/apps/markets/types.js +0 -206
- package/dist/esm/apps/oracles/types.js +0 -267
- package/dist/esm/generated/ottochain/apps/contracts/v1/contract_pb.js +0 -97
- package/dist/esm/generated/ottochain/apps/corporate/v1/corporate_pb.js +0 -389
- package/dist/esm/generated/ottochain/apps/governance/v1/governance_pb.js +0 -232
- package/dist/esm/generated/ottochain/apps/identity/v1/agent_pb.js +0 -113
- package/dist/esm/generated/ottochain/apps/identity/v1/attestation_pb.js +0 -76
- package/dist/esm/generated/ottochain/apps/markets/v1/market_pb.js +0 -148
- package/dist/esm/generated/ottochain/apps/oracles/v1/oracle_pb.js +0 -106
- package/dist/esm/generated/ottochain/v1/common_pb.js +0 -34
- package/dist/esm/generated/ottochain/v1/fiber_pb.js +0 -83
- package/dist/esm/generated/ottochain/v1/messages_pb.js +0 -41
- package/dist/esm/generated/ottochain/v1/records_pb.js +0 -41
- package/dist/generated/index.d.ts +0 -15
- package/dist/generated/index.js +0 -34
- package/dist/generated/ottochain/apps/contracts/v1/contract_pb.d.ts +0 -274
- package/dist/generated/ottochain/apps/contracts/v1/contract_pb.js +0 -100
- package/dist/generated/ottochain/apps/identity/v1/agent_pb.d.ts +0 -211
- package/dist/generated/ottochain/apps/identity/v1/agent_pb.js +0 -116
- package/dist/generated/ottochain/apps/identity/v1/attestation_pb.d.ts +0 -238
- package/dist/generated/ottochain/apps/identity/v1/attestation_pb.js +0 -79
- package/dist/generated/ottochain/apps/markets/v1/market_pb.d.ts +0 -436
- package/dist/generated/ottochain/apps/markets/v1/market_pb.js +0 -151
- package/dist/generated/ottochain/apps/oracles/v1/oracle_pb.d.ts +0 -393
- package/dist/generated/ottochain/apps/oracles/v1/oracle_pb.js +0 -109
- package/dist/generated/ottochain/v1/common_pb.d.ts +0 -86
- package/dist/generated/ottochain/v1/common_pb.js +0 -37
- package/dist/generated/ottochain/v1/fiber_pb.d.ts +0 -292
- package/dist/generated/ottochain/v1/fiber_pb.js +0 -86
- package/dist/generated/ottochain/v1/messages_pb.d.ts +0 -190
- package/dist/generated/ottochain/v1/messages_pb.js +0 -44
- package/dist/generated/ottochain/v1/records_pb.d.ts +0 -221
- package/dist/generated/ottochain/v1/records_pb.js +0 -44
- package/dist/index.d.ts +0 -21
- package/dist/index.js +0 -77
- package/dist/metakit/binary.d.ts +0 -38
- package/dist/metakit/binary.js +0 -58
- package/dist/metakit/canonicalize.d.ts +0 -26
- package/dist/metakit/canonicalize.js +0 -40
- package/dist/metakit/codec.d.ts +0 -16
- package/dist/metakit/codec.js +0 -45
- package/dist/metakit/currency-transaction.d.ts +0 -157
- package/dist/metakit/currency-transaction.js +0 -319
- package/dist/metakit/currency-types.d.ts +0 -55
- package/dist/metakit/currency-types.js +0 -13
- package/dist/metakit/hash.d.ts +0 -50
- package/dist/metakit/hash.js +0 -84
- package/dist/metakit/index.d.ts +0 -23
- package/dist/metakit/index.js +0 -74
- package/dist/metakit/network/client.d.ts +0 -23
- package/dist/metakit/network/client.js +0 -78
- package/dist/metakit/network/currency-l1-client.d.ts +0 -71
- package/dist/metakit/network/currency-l1-client.js +0 -101
- package/dist/metakit/network/data-l1-client.d.ts +0 -57
- package/dist/metakit/network/data-l1-client.js +0 -76
- package/dist/metakit/network/index.d.ts +0 -10
- package/dist/metakit/network/index.js +0 -16
- package/dist/metakit/network/types.d.ts +0 -74
- package/dist/metakit/network/types.js +0 -20
- package/dist/metakit/sign.d.ts +0 -65
- package/dist/metakit/sign.js +0 -120
- package/dist/metakit/signed-object.d.ts +0 -66
- package/dist/metakit/signed-object.js +0 -100
- package/dist/metakit/types.d.ts +0 -67
- package/dist/metakit/types.js +0 -14
- package/dist/metakit/verify.d.ts +0 -55
- package/dist/metakit/verify.js +0 -217
- package/dist/metakit/wallet.d.ts +0 -70
- package/dist/metakit/wallet.js +0 -127
- package/dist/ottochain/index.d.ts +0 -13
- package/dist/ottochain/index.js +0 -45
- package/dist/ottochain/metagraph-client.d.ts +0 -111
- package/dist/ottochain/metagraph-client.js +0 -157
- package/dist/ottochain/snapshot.d.ts +0 -86
- package/dist/ottochain/snapshot.js +0 -110
- package/dist/ottochain/types.d.ts +0 -278
- package/dist/ottochain/types.js +0 -11
- package/dist/types/apps/contracts/types.d.ts +0 -24
- package/dist/types/apps/corporate/types.d.ts +0 -9861
- package/dist/types/apps/governance/types.d.ts +0 -344
- package/dist/types/apps/identity/types.d.ts +0 -30
- package/dist/types/apps/markets/types.d.ts +0 -155
- package/dist/types/apps/oracles/types.d.ts +0 -193
- package/dist/types/generated/ottochain/apps/contracts/v1/contract_pb.d.ts +0 -274
- package/dist/types/generated/ottochain/apps/corporate/v1/corporate_pb.d.ts +0 -1172
- package/dist/types/generated/ottochain/apps/governance/v1/governance_pb.d.ts +0 -772
- package/dist/types/generated/ottochain/apps/identity/v1/agent_pb.d.ts +0 -211
- package/dist/types/generated/ottochain/apps/identity/v1/attestation_pb.d.ts +0 -238
- package/dist/types/generated/ottochain/apps/markets/v1/market_pb.d.ts +0 -436
- package/dist/types/generated/ottochain/apps/oracles/v1/oracle_pb.d.ts +0 -393
- package/dist/types/generated/ottochain/v1/common_pb.d.ts +0 -86
- package/dist/types/generated/ottochain/v1/fiber_pb.d.ts +0 -292
- package/dist/types/generated/ottochain/v1/messages_pb.d.ts +0 -190
- package/dist/types/generated/ottochain/v1/records_pb.d.ts +0 -221
- package/dist/validation.d.ts +0 -449
- package/dist/validation.js +0 -312
package/dist/validation.js
DELETED
|
@@ -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;
|