@wishknish/knishio-client-ts 0.7.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/LICENSE +674 -0
- package/README.md +425 -0
- package/dist/index.cjs +9961 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.iife.js +32241 -0
- package/dist/index.iife.js.map +1 -0
- package/dist/index.js +9853 -0
- package/dist/index.js.map +1 -0
- package/package.json +113 -0
- package/src/AuthToken.ts +214 -0
- package/src/KnishIOClient.ts +2020 -0
- package/src/constants.ts +398 -0
- package/src/core/Atom.ts +646 -0
- package/src/core/AtomMeta.ts +278 -0
- package/src/core/Meta.ts +428 -0
- package/src/core/Molecule.ts +825 -0
- package/src/core/PolicyMeta.ts +130 -0
- package/src/core/TokenUnit.ts +148 -0
- package/src/core/Wallet.ts +467 -0
- package/src/exception/AtomIndexException.ts +97 -0
- package/src/exception/AtomsMissingException.ts +109 -0
- package/src/exception/AuthorizationRejectedException.ts +63 -0
- package/src/exception/BalanceInsufficientException.ts +58 -0
- package/src/exception/BaseException.ts +275 -0
- package/src/exception/BatchIdException.ts +58 -0
- package/src/exception/CodeException.ts +119 -0
- package/src/exception/DecryptionKeyException.ts +65 -0
- package/src/exception/InvalidResponseException.ts +112 -0
- package/src/exception/MetaMissingException.ts +58 -0
- package/src/exception/MolecularHashMismatchException.ts +115 -0
- package/src/exception/MolecularHashMissingException.ts +58 -0
- package/src/exception/NegativeAmountException.ts +58 -0
- package/src/exception/PolicyInvalidException.ts +58 -0
- package/src/exception/SignatureMalformedException.ts +58 -0
- package/src/exception/SignatureMismatchException.ts +98 -0
- package/src/exception/StackableUnitAmountException.ts +65 -0
- package/src/exception/StackableUnitDecimalsException.ts +65 -0
- package/src/exception/TransferBalanceException.ts +98 -0
- package/src/exception/TransferMalformedException.ts +58 -0
- package/src/exception/TransferMismatchedException.ts +58 -0
- package/src/exception/TransferRemainderException.ts +58 -0
- package/src/exception/TransferToSelfException.ts +58 -0
- package/src/exception/TransferUnbalancedException.ts +58 -0
- package/src/exception/UnauthenticatedException.ts +147 -0
- package/src/exception/WalletCredentialException.ts +108 -0
- package/src/exception/WalletShadowException.ts +65 -0
- package/src/exception/WrongTokenTypeException.ts +58 -0
- package/src/exception/index.ts +272 -0
- package/src/index.ts +512 -0
- package/src/instance/rules/Callback.ts +257 -0
- package/src/instance/rules/Condition.ts +96 -0
- package/src/instance/rules/Meta.ts +163 -0
- package/src/instance/rules/Rule.ts +29 -0
- package/src/instance/rules/exception/RuleArgumentException.ts +65 -0
- package/src/libraries/CheckMolecule.ts +581 -0
- package/src/libraries/Decimal.ts +94 -0
- package/src/libraries/Dot.ts +202 -0
- package/src/libraries/GraphQLClient.ts +276 -0
- package/src/libraries/Hex.ts +155 -0
- package/src/libraries/UrqlClientWrapper.ts +336 -0
- package/src/libraries/array.ts +91 -0
- package/src/libraries/crypto.ts +816 -0
- package/src/libraries/strings.ts +458 -0
- package/src/mutation/Mutation.ts +103 -0
- package/src/mutation/MutationActiveSession.ts +108 -0
- package/src/mutation/MutationClaimShadowWallet.ts +91 -0
- package/src/mutation/MutationCreateIdentifier.ts +86 -0
- package/src/mutation/MutationCreateMeta.ts +92 -0
- package/src/mutation/MutationCreateRule.ts +90 -0
- package/src/mutation/MutationCreateToken.ts +92 -0
- package/src/mutation/MutationCreateWallet.ts +78 -0
- package/src/mutation/MutationDepositBufferToken.ts +72 -0
- package/src/mutation/MutationLinkIdentifier.ts +87 -0
- package/src/mutation/MutationProposeMolecule.ts +147 -0
- package/src/mutation/MutationRequestAuthorization.ts +77 -0
- package/src/mutation/MutationRequestAuthorizationGuest.ts +85 -0
- package/src/mutation/MutationRequestTokens.ts +98 -0
- package/src/mutation/MutationTransferTokens.ts +87 -0
- package/src/mutation/MutationWithdrawBufferToken.ts +73 -0
- package/src/query/Query.ts +187 -0
- package/src/query/QueryActiveSession.ts +89 -0
- package/src/query/QueryAtom.ts +275 -0
- package/src/query/QueryBalance.ts +102 -0
- package/src/query/QueryBatch.ts +145 -0
- package/src/query/QueryBatchHistory.ts +86 -0
- package/src/query/QueryContinuId.ts +91 -0
- package/src/query/QueryMetaType.ts +177 -0
- package/src/query/QueryMetaTypeViaAtom.ts +199 -0
- package/src/query/QueryPolicy.ts +91 -0
- package/src/query/QueryToken.ts +90 -0
- package/src/query/QueryUserActivity.ts +153 -0
- package/src/query/QueryWalletBundle.ts +92 -0
- package/src/query/QueryWalletList.ts +106 -0
- package/src/response/EnhancedResponse.ts +345 -0
- package/src/response/Response.ts +254 -0
- package/src/response/ResponseActiveSession.ts +72 -0
- package/src/response/ResponseAtom.ts +132 -0
- package/src/response/ResponseAuthorizationGuest.ts +119 -0
- package/src/response/ResponseBalance.ts +153 -0
- package/src/response/ResponseClaimShadowWallet.ts +56 -0
- package/src/response/ResponseContinuId.ts +101 -0
- package/src/response/ResponseCreateIdentifier.ts +56 -0
- package/src/response/ResponseCreateMeta.ts +58 -0
- package/src/response/ResponseCreateRule.ts +56 -0
- package/src/response/ResponseCreateToken.ts +58 -0
- package/src/response/ResponseCreateWallet.ts +58 -0
- package/src/response/ResponseLinkIdentifier.ts +87 -0
- package/src/response/ResponseMetaBatch.ts +72 -0
- package/src/response/ResponseMetaType.ts +108 -0
- package/src/response/ResponseMetaTypeViaAtom.ts +108 -0
- package/src/response/ResponsePolicy.ts +90 -0
- package/src/response/ResponseProposeMolecule.ts +155 -0
- package/src/response/ResponseQueryActiveSession.ts +105 -0
- package/src/response/ResponseQueryUserActivity.ts +89 -0
- package/src/response/ResponseRequestAuthorization.ts +100 -0
- package/src/response/ResponseRequestAuthorizationGuest.ts +133 -0
- package/src/response/ResponseRequestTokens.ts +58 -0
- package/src/response/ResponseTransferTokens.ts +72 -0
- package/src/response/ResponseWalletBundle.ts +95 -0
- package/src/response/ResponseWalletList.ts +165 -0
- package/src/schemas/index.ts +457 -0
- package/src/subscribe/ActiveSessionSubscribe.ts +72 -0
- package/src/subscribe/ActiveWalletSubscribe.ts +99 -0
- package/src/subscribe/CreateMoleculeSubscribe.ts +106 -0
- package/src/subscribe/Subscribe.ts +182 -0
- package/src/subscribe/WalletStatusSubscribe.ts +70 -0
- package/src/subscribe/index.ts +59 -0
- package/src/types/assertions.ts +722 -0
- package/src/types/client.ts +567 -0
- package/src/types/crypto.ts +541 -0
- package/src/types/graphql.ts +630 -0
- package/src/types/guards.ts +659 -0
- package/src/types/index.ts +614 -0
- package/src/types/response.ts +133 -0
- package/src/types/template-literals.ts +382 -0
- package/src/validation/UNIVERSAL_CONFIGURATION_INTERFACES.ts +580 -0
- package/src/validation/ValidationService.ts +607 -0
- package/src/validation/schemas.ts +447 -0
- package/src/versions/HashAtom.ts +170 -0
- package/src/versions/Version4.ts +120 -0
- package/src/versions/index.ts +80 -0
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
/*
|
|
2
|
+
(
|
|
3
|
+
(/(
|
|
4
|
+
(//(
|
|
5
|
+
(///(
|
|
6
|
+
(/////(
|
|
7
|
+
(//////( )
|
|
8
|
+
(////////( (/)
|
|
9
|
+
(////////( (///)
|
|
10
|
+
(//////////( (////)
|
|
11
|
+
(//////////( (//////)
|
|
12
|
+
(////////////( (///////)
|
|
13
|
+
(/////////////( (/////////)
|
|
14
|
+
(//////////////( (///////////)
|
|
15
|
+
(///////////////( (/////////////)
|
|
16
|
+
(////////////////( (//////////////)
|
|
17
|
+
((((((((((((((((((( (((((((((((((((
|
|
18
|
+
((((((((((((((((((( ((((((((((((((
|
|
19
|
+
((((((((((((((((((( ((((((((((((((
|
|
20
|
+
(((((((((((((((((((( (((((((((((((
|
|
21
|
+
(((((((((((((((((((( ((((((((((((
|
|
22
|
+
((((((((((((((((((( ((((((((((((
|
|
23
|
+
((((((((((((((((((( ((((((((((
|
|
24
|
+
((((((((((((((((((/ (((((((((
|
|
25
|
+
(((((((((((((((((( ((((((((
|
|
26
|
+
((((((((((((((((( (((((((
|
|
27
|
+
(((((((((((((((((( (((((
|
|
28
|
+
################# ##
|
|
29
|
+
################ #
|
|
30
|
+
################# ##
|
|
31
|
+
%################ ###
|
|
32
|
+
###############( ####
|
|
33
|
+
############### ####
|
|
34
|
+
############### ######
|
|
35
|
+
%#############( (#######
|
|
36
|
+
%############# #########
|
|
37
|
+
############( ##########
|
|
38
|
+
########### #############
|
|
39
|
+
######### ##############
|
|
40
|
+
%######
|
|
41
|
+
|
|
42
|
+
Powered by Knish.IO: Connecting a Decentralized World
|
|
43
|
+
|
|
44
|
+
Please visit https://github.com/WishKnish/KnishIO-Client-TS for information.
|
|
45
|
+
|
|
46
|
+
License: https://github.com/WishKnish/KnishIO-Client-TS/blob/master/LICENSE
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Zod Runtime Validation Schemas for KnishIO TypeScript SDK
|
|
51
|
+
*
|
|
52
|
+
* Implements TypeScript 2025 best practices with comprehensive runtime validation
|
|
53
|
+
* for all core data structures, ensuring type safety at runtime and compile time.
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
import { z } from 'zod'
|
|
57
|
+
|
|
58
|
+
// =============================================================================
|
|
59
|
+
// BRANDED TYPE VALIDATION SCHEMAS
|
|
60
|
+
// =============================================================================
|
|
61
|
+
|
|
62
|
+
const hexStringRegex = /^[0-9a-fA-F]+$/
|
|
63
|
+
const base17HashRegex = /^[0-9a-g]+$/
|
|
64
|
+
|
|
65
|
+
export const HexStringSchema = z.string()
|
|
66
|
+
.regex(hexStringRegex, 'Must be a valid hexadecimal string')
|
|
67
|
+
.brand<'HexString'>()
|
|
68
|
+
|
|
69
|
+
export const WalletAddressSchema = z.string()
|
|
70
|
+
.regex(hexStringRegex, 'Wallet address must be hexadecimal')
|
|
71
|
+
.length(64, 'Wallet address must be exactly 64 characters')
|
|
72
|
+
.brand<'WalletAddress'>()
|
|
73
|
+
|
|
74
|
+
export const BundleHashSchema = z.string()
|
|
75
|
+
.regex(hexStringRegex, 'Bundle hash must be hexadecimal')
|
|
76
|
+
.length(64, 'Bundle hash must be exactly 64 characters')
|
|
77
|
+
.brand<'BundleHash'>()
|
|
78
|
+
|
|
79
|
+
export const PositionSchema = z.string()
|
|
80
|
+
.regex(hexStringRegex, 'Position must be hexadecimal')
|
|
81
|
+
.length(64, 'Position must be exactly 64 characters')
|
|
82
|
+
.brand<'Position'>()
|
|
83
|
+
|
|
84
|
+
export const MolecularHashSchema = z.string()
|
|
85
|
+
.regex(base17HashRegex, 'Molecular hash must be base17 format (0-9,a-g)')
|
|
86
|
+
.min(1, 'Molecular hash cannot be empty')
|
|
87
|
+
.brand<'MolecularHash'>()
|
|
88
|
+
|
|
89
|
+
export const TokenSlugSchema = z.string()
|
|
90
|
+
.min(1, 'Token slug cannot be empty')
|
|
91
|
+
.max(64, 'Token slug cannot exceed 64 characters')
|
|
92
|
+
.transform(val => val.toUpperCase())
|
|
93
|
+
.brand<'TokenSlug'>()
|
|
94
|
+
|
|
95
|
+
export const MetaTypeSchema = z.string()
|
|
96
|
+
.min(1, 'Meta type cannot be empty')
|
|
97
|
+
.max(256, 'Meta type cannot exceed 256 characters')
|
|
98
|
+
.brand<'MetaType'>()
|
|
99
|
+
|
|
100
|
+
export const MetaIdSchema = z.string()
|
|
101
|
+
.min(1, 'Meta ID cannot be empty')
|
|
102
|
+
.brand<'MetaId'>()
|
|
103
|
+
|
|
104
|
+
export const BatchIdSchema = z.string()
|
|
105
|
+
.min(1, 'Batch ID cannot be empty')
|
|
106
|
+
.brand<'BatchId'>()
|
|
107
|
+
|
|
108
|
+
export const CellSlugSchema = z.string()
|
|
109
|
+
.min(1, 'Cell slug cannot be empty')
|
|
110
|
+
.max(64, 'Cell slug cannot exceed 64 characters')
|
|
111
|
+
.brand<'CellSlug'>()
|
|
112
|
+
|
|
113
|
+
// =============================================================================
|
|
114
|
+
// ATOM ISOTOPE VALIDATION
|
|
115
|
+
// =============================================================================
|
|
116
|
+
|
|
117
|
+
export const AtomIsotopeSchema = z.enum(['C', 'V', 'U', 'T', 'M', 'I', 'R', 'B', 'F'], {
|
|
118
|
+
errorMap: () => ({ message: 'Invalid atom isotope. Must be one of: C, V, U, T, M, I, R, B, F' })
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
// =============================================================================
|
|
122
|
+
// METADATA VALIDATION SCHEMAS
|
|
123
|
+
// =============================================================================
|
|
124
|
+
|
|
125
|
+
export const MetaDataValueSchema: z.ZodType<string | number | boolean | null> = z.union([
|
|
126
|
+
z.string(),
|
|
127
|
+
z.number(),
|
|
128
|
+
z.boolean(),
|
|
129
|
+
z.null()
|
|
130
|
+
])
|
|
131
|
+
|
|
132
|
+
export const AtomMetaDataSchema = z.object({
|
|
133
|
+
key: z.string().min(1, 'Meta key cannot be empty'),
|
|
134
|
+
value: MetaDataValueSchema
|
|
135
|
+
}).strict()
|
|
136
|
+
|
|
137
|
+
export const MetaDataSchema: z.ZodType<Record<string, any>> = z.lazy(() =>
|
|
138
|
+
z.record(z.union([
|
|
139
|
+
MetaDataValueSchema,
|
|
140
|
+
MetaDataSchema,
|
|
141
|
+
z.array(MetaDataSchema)
|
|
142
|
+
]))
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
// =============================================================================
|
|
146
|
+
// CORE PARAMETER SCHEMAS
|
|
147
|
+
// =============================================================================
|
|
148
|
+
|
|
149
|
+
export const AtomParamsSchema = z.object({
|
|
150
|
+
position: z.union([z.string(), z.null()]).optional(),
|
|
151
|
+
walletAddress: z.union([WalletAddressSchema, z.string(), z.null()]).optional(),
|
|
152
|
+
isotope: AtomIsotopeSchema.optional(),
|
|
153
|
+
token: z.union([TokenSlugSchema, z.string()]).optional(),
|
|
154
|
+
value: z.union([z.string(), z.number(), z.null()]).optional(),
|
|
155
|
+
batchId: z.union([BatchIdSchema, z.string(), z.null()]).optional(),
|
|
156
|
+
metaType: z.union([MetaTypeSchema, z.string(), z.null()]).optional(),
|
|
157
|
+
metaId: z.union([MetaIdSchema, z.string(), z.null()]).optional(),
|
|
158
|
+
meta: z.union([z.array(AtomMetaDataSchema), z.null()]).optional(),
|
|
159
|
+
otsFragment: z.union([z.string(), z.null()]).optional(),
|
|
160
|
+
index: z.union([z.number().int().min(0), z.null()]).optional(),
|
|
161
|
+
createdAt: z.union([z.string(), z.null()]).optional(),
|
|
162
|
+
version: z.union([z.number().int().min(1), z.null()]).optional()
|
|
163
|
+
}).strict()
|
|
164
|
+
|
|
165
|
+
export const WalletParamsSchema = z.object({
|
|
166
|
+
secret: z.union([z.string(), z.null()]).optional(),
|
|
167
|
+
bundle: z.union([BundleHashSchema, z.string(), z.null()]).optional(),
|
|
168
|
+
token: z.union([TokenSlugSchema, z.string()]).optional(),
|
|
169
|
+
address: z.union([WalletAddressSchema, z.string(), z.null()]).optional(),
|
|
170
|
+
position: z.union([PositionSchema, z.string(), z.null()]).optional(),
|
|
171
|
+
batchId: z.union([BatchIdSchema, z.string(), z.null()]).optional(),
|
|
172
|
+
characters: z.union([z.string(), z.null()]).optional()
|
|
173
|
+
}).strict()
|
|
174
|
+
|
|
175
|
+
export const MoleculeParamsSchema = z.object({
|
|
176
|
+
secret: z.union([z.string(), z.null()]).optional(),
|
|
177
|
+
bundle: z.union([BundleHashSchema, z.string(), z.null()]).optional(),
|
|
178
|
+
sourceWallet: z.union([WalletParamsSchema, z.null()]).optional(),
|
|
179
|
+
remainderWallet: z.union([WalletParamsSchema, z.null()]).optional(),
|
|
180
|
+
cellSlug: z.union([CellSlugSchema, z.string(), z.null()]).optional(),
|
|
181
|
+
version: z.number().int().min(1).optional()
|
|
182
|
+
}).strict()
|
|
183
|
+
|
|
184
|
+
// =============================================================================
|
|
185
|
+
// CLIENT CONFIGURATION SCHEMAS
|
|
186
|
+
// =============================================================================
|
|
187
|
+
|
|
188
|
+
export const KnishIOClientConfigSchema = z.object({
|
|
189
|
+
uri: z.union([z.string().url(), z.array(z.string().url())]).optional(),
|
|
190
|
+
cellSlug: z.union([CellSlugSchema, z.string(), z.null()]).optional(),
|
|
191
|
+
client: z.unknown().optional(),
|
|
192
|
+
socket: z.unknown().optional(),
|
|
193
|
+
serverSdkVersion: z.number().int().min(1).optional(),
|
|
194
|
+
logging: z.boolean().optional()
|
|
195
|
+
}).strict()
|
|
196
|
+
|
|
197
|
+
// =============================================================================
|
|
198
|
+
// AUTHENTICATION SCHEMAS
|
|
199
|
+
// =============================================================================
|
|
200
|
+
|
|
201
|
+
export const AuthTokenParamsSchema = z.object({
|
|
202
|
+
token: z.string().min(1, 'Auth token cannot be empty'),
|
|
203
|
+
expiresAt: z.number().int().min(0, 'Expiration time must be positive'),
|
|
204
|
+
encrypt: z.boolean(),
|
|
205
|
+
pubkey: z.string().min(1, 'Public key cannot be empty')
|
|
206
|
+
}).strict()
|
|
207
|
+
|
|
208
|
+
export const AuthParamsSchema = z.object({
|
|
209
|
+
cellSlug: z.union([CellSlugSchema, z.string(), z.null()]).optional(),
|
|
210
|
+
encrypt: z.boolean().optional(),
|
|
211
|
+
callback: z.function().args(z.unknown()).returns(z.void()).optional()
|
|
212
|
+
}).strict()
|
|
213
|
+
|
|
214
|
+
export const GuestAuthParamsSchema = z.object({
|
|
215
|
+
cellSlug: z.union([CellSlugSchema, z.string(), z.null()]).optional()
|
|
216
|
+
}).strict()
|
|
217
|
+
|
|
218
|
+
// =============================================================================
|
|
219
|
+
// TOKEN OPERATION SCHEMAS
|
|
220
|
+
// =============================================================================
|
|
221
|
+
|
|
222
|
+
export const TransferParamsSchema = z.object({
|
|
223
|
+
recipient: z.union([WalletAddressSchema, z.string()]),
|
|
224
|
+
amount: z.union([z.number().positive(), z.string().min(1)]),
|
|
225
|
+
token: z.union([TokenSlugSchema, z.string()]).optional(),
|
|
226
|
+
callbackUrl: z.union([z.string().url(), z.null()]).optional(),
|
|
227
|
+
metaType: z.union([MetaTypeSchema, z.string(), z.null()]).optional(),
|
|
228
|
+
metaId: z.union([MetaIdSchema, z.string(), z.null()]).optional(),
|
|
229
|
+
meta: z.union([MetaDataSchema, z.null()]).optional()
|
|
230
|
+
}).strict()
|
|
231
|
+
|
|
232
|
+
export const CreateTokenParamsSchema = z.object({
|
|
233
|
+
token: z.union([TokenSlugSchema, z.string()]),
|
|
234
|
+
amount: z.union([z.number().positive(), z.string().min(1)]),
|
|
235
|
+
metaType: z.union([MetaTypeSchema, z.string(), z.null()]).optional(),
|
|
236
|
+
metaId: z.union([MetaIdSchema, z.string(), z.null()]).optional(),
|
|
237
|
+
meta: z.union([MetaDataSchema, z.null()]).optional(),
|
|
238
|
+
fungible: z.boolean().optional(),
|
|
239
|
+
splittable: z.number().int().min(0).optional(),
|
|
240
|
+
supplyToken: z.union([TokenSlugSchema, z.string(), z.null()]).optional()
|
|
241
|
+
}).strict()
|
|
242
|
+
|
|
243
|
+
export const RequestTokensParamsSchema = z.object({
|
|
244
|
+
amount: z.union([z.number().positive(), z.string().min(1)]),
|
|
245
|
+
token: z.union([TokenSlugSchema, z.string()]).optional(),
|
|
246
|
+
metaType: z.union([MetaTypeSchema, z.string(), z.null()]).optional(),
|
|
247
|
+
metaId: z.union([MetaIdSchema, z.string(), z.null()]).optional(),
|
|
248
|
+
meta: z.union([MetaDataSchema, z.null()]).optional()
|
|
249
|
+
}).strict()
|
|
250
|
+
|
|
251
|
+
// =============================================================================
|
|
252
|
+
// QUERY PARAMETER SCHEMAS
|
|
253
|
+
// =============================================================================
|
|
254
|
+
|
|
255
|
+
export const BalanceQueryParamsSchema = z.object({
|
|
256
|
+
address: z.union([WalletAddressSchema, z.string(), z.null()]).optional(),
|
|
257
|
+
bundleHash: z.union([BundleHashSchema, z.string(), z.null()]).optional(),
|
|
258
|
+
token: z.union([TokenSlugSchema, z.string(), z.null()]).optional(),
|
|
259
|
+
type: z.enum(['token', 'user']).nullable().optional()
|
|
260
|
+
}).strict()
|
|
261
|
+
|
|
262
|
+
export const MetaQueryParamsSchema = z.object({
|
|
263
|
+
metaType: z.union([MetaTypeSchema, z.string()]),
|
|
264
|
+
metaId: z.union([MetaIdSchema, z.string(), z.null()]).optional(),
|
|
265
|
+
key: z.union([z.string(), z.null()]).optional(),
|
|
266
|
+
value: z.union([z.string(), z.null()]).optional(),
|
|
267
|
+
latest: z.union([z.boolean(), z.null()]).optional(),
|
|
268
|
+
filter: z.union([z.string(), z.null()]).optional(),
|
|
269
|
+
queryArgs: z.union([z.record(z.unknown()), z.null()]).optional(),
|
|
270
|
+
count: z.union([z.number().int().min(1), z.null()]).optional(),
|
|
271
|
+
countBy: z.union([z.string(), z.null()]).optional(),
|
|
272
|
+
cellSlug: z.union([CellSlugSchema, z.string(), z.null()]).optional()
|
|
273
|
+
}).strict()
|
|
274
|
+
|
|
275
|
+
export const WalletQueryParamsSchema = z.object({
|
|
276
|
+
bundleHash: z.union([BundleHashSchema, z.string(), z.null()]).optional(),
|
|
277
|
+
tokenSlug: z.union([TokenSlugSchema, z.string(), z.null()]).optional(),
|
|
278
|
+
unspent: z.union([z.boolean(), z.null()]).optional()
|
|
279
|
+
}).strict()
|
|
280
|
+
|
|
281
|
+
// =============================================================================
|
|
282
|
+
// CRYPTOGRAPHIC SCHEMAS
|
|
283
|
+
// =============================================================================
|
|
284
|
+
|
|
285
|
+
export const CryptoOptionsSchema = z.object({
|
|
286
|
+
seed: z.union([z.string(), z.null()]).optional(),
|
|
287
|
+
length: z.number().int().min(1).optional(),
|
|
288
|
+
outputLength: z.number().int().min(1).optional()
|
|
289
|
+
}).strict()
|
|
290
|
+
|
|
291
|
+
export const KeyPairResultSchema = z.object({
|
|
292
|
+
privateKey: z.string().min(1, 'Private key cannot be empty'),
|
|
293
|
+
publicKey: z.string().min(1, 'Public key cannot be empty')
|
|
294
|
+
}).strict()
|
|
295
|
+
|
|
296
|
+
export const SignatureResultSchema = z.object({
|
|
297
|
+
signature: z.string().min(1, 'Signature cannot be empty'),
|
|
298
|
+
otsFragments: z.array(z.string()).optional()
|
|
299
|
+
}).strict()
|
|
300
|
+
|
|
301
|
+
// =============================================================================
|
|
302
|
+
// GRAPHQL OPERATION SCHEMAS
|
|
303
|
+
// =============================================================================
|
|
304
|
+
|
|
305
|
+
export const GraphQLRequestSchema = z.object({
|
|
306
|
+
query: z.string().min(1, 'GraphQL query cannot be empty'),
|
|
307
|
+
variables: z.record(z.unknown()).optional(),
|
|
308
|
+
operationName: z.union([z.string(), z.null()]).optional()
|
|
309
|
+
}).strict()
|
|
310
|
+
|
|
311
|
+
export const GraphQLErrorSchema = z.object({
|
|
312
|
+
message: z.string(),
|
|
313
|
+
locations: z.array(z.object({
|
|
314
|
+
line: z.number().int().min(1),
|
|
315
|
+
column: z.number().int().min(1)
|
|
316
|
+
})).optional(),
|
|
317
|
+
path: z.array(z.union([z.string(), z.number()])).optional(),
|
|
318
|
+
extensions: z.record(z.unknown()).optional()
|
|
319
|
+
}).strict()
|
|
320
|
+
|
|
321
|
+
export const GraphQLResponseSchema = z.object({
|
|
322
|
+
data: z.unknown().optional(),
|
|
323
|
+
errors: z.array(GraphQLErrorSchema).nullable().optional(),
|
|
324
|
+
extensions: z.record(z.unknown()).optional()
|
|
325
|
+
}).strict()
|
|
326
|
+
|
|
327
|
+
// =============================================================================
|
|
328
|
+
// SUBSCRIPTION SCHEMAS
|
|
329
|
+
// =============================================================================
|
|
330
|
+
|
|
331
|
+
export const SubscriptionOptionsSchema = z.object({
|
|
332
|
+
operationName: z.string().optional(),
|
|
333
|
+
query: z.string().optional(),
|
|
334
|
+
variables: z.record(z.unknown()).optional(),
|
|
335
|
+
callback: z.function().args(z.unknown()).returns(z.void()).optional()
|
|
336
|
+
}).strict()
|
|
337
|
+
|
|
338
|
+
// =============================================================================
|
|
339
|
+
// VALIDATION RESULT SCHEMAS
|
|
340
|
+
// =============================================================================
|
|
341
|
+
|
|
342
|
+
export const ValidationResultSchema = z.object({
|
|
343
|
+
valid: z.boolean(),
|
|
344
|
+
error: z.union([z.string(), z.null()]).optional(),
|
|
345
|
+
expected: z.string().optional(),
|
|
346
|
+
actual: z.unknown().optional()
|
|
347
|
+
}).strict()
|
|
348
|
+
|
|
349
|
+
// =============================================================================
|
|
350
|
+
// ERROR CONTEXT SCHEMAS
|
|
351
|
+
// =============================================================================
|
|
352
|
+
|
|
353
|
+
export const ErrorContextSchema = z.object({
|
|
354
|
+
operation: z.string().optional(),
|
|
355
|
+
parameters: z.record(z.unknown()).optional(),
|
|
356
|
+
timestamp: z.number().int().min(0).optional(),
|
|
357
|
+
stack: z.string().optional()
|
|
358
|
+
}).strict()
|
|
359
|
+
|
|
360
|
+
export const KnishIOErrorTypeSchema = z.enum([
|
|
361
|
+
'ATOM_INDEX_ERROR',
|
|
362
|
+
'ATOMS_MISSING_ERROR',
|
|
363
|
+
'AUTHORIZATION_REJECTED_ERROR',
|
|
364
|
+
'BALANCE_INSUFFICIENT_ERROR',
|
|
365
|
+
'BATCH_ID_ERROR',
|
|
366
|
+
'CODE_ERROR',
|
|
367
|
+
'DECRYPTION_KEY_ERROR',
|
|
368
|
+
'INVALID_RESPONSE_ERROR',
|
|
369
|
+
'META_MISSING_ERROR',
|
|
370
|
+
'MOLECULAR_HASH_MISMATCH_ERROR',
|
|
371
|
+
'MOLECULAR_HASH_MISSING_ERROR',
|
|
372
|
+
'NEGATIVE_AMOUNT_ERROR',
|
|
373
|
+
'POLICY_INVALID_ERROR',
|
|
374
|
+
'SIGNATURE_MALFORMED_ERROR',
|
|
375
|
+
'SIGNATURE_MISMATCH_ERROR',
|
|
376
|
+
'STACKABLE_UNIT_AMOUNT_ERROR',
|
|
377
|
+
'STACKABLE_UNIT_DECIMALS_ERROR',
|
|
378
|
+
'TRANSFER_BALANCE_ERROR',
|
|
379
|
+
'TRANSFER_MALFORMED_ERROR',
|
|
380
|
+
'TRANSFER_MISMATCHED_ERROR',
|
|
381
|
+
'TRANSFER_REMAINDER_ERROR',
|
|
382
|
+
'TRANSFER_TO_SELF_ERROR',
|
|
383
|
+
'TRANSFER_UNBALANCED_ERROR',
|
|
384
|
+
'UNAUTHENTICATED_ERROR',
|
|
385
|
+
'WALLET_CREDENTIAL_ERROR',
|
|
386
|
+
'WALLET_SHADOW_ERROR',
|
|
387
|
+
'WRONG_TOKEN_TYPE_ERROR'
|
|
388
|
+
])
|
|
389
|
+
|
|
390
|
+
// =============================================================================
|
|
391
|
+
// UTILITY VALIDATION FUNCTIONS
|
|
392
|
+
// =============================================================================
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Validates and parses data using a Zod schema with enhanced error messages
|
|
396
|
+
*/
|
|
397
|
+
export function parseWithSchema<T>(
|
|
398
|
+
schema: z.ZodSchema<T>,
|
|
399
|
+
data: unknown,
|
|
400
|
+
context?: string
|
|
401
|
+
): T {
|
|
402
|
+
const result = schema.safeParse(data)
|
|
403
|
+
|
|
404
|
+
if (!result.success) {
|
|
405
|
+
const errorMessage = context
|
|
406
|
+
? `${context}: ${result.error.message}`
|
|
407
|
+
: result.error.message
|
|
408
|
+
|
|
409
|
+
throw new Error(errorMessage)
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
return result.data
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Type-safe validation that returns a result object instead of throwing
|
|
417
|
+
*/
|
|
418
|
+
export function validateWithSchema<T>(
|
|
419
|
+
schema: z.ZodSchema<T>,
|
|
420
|
+
data: unknown
|
|
421
|
+
): { success: true; data: T } | { success: false; error: string } {
|
|
422
|
+
const result = schema.safeParse(data)
|
|
423
|
+
|
|
424
|
+
if (result.success) {
|
|
425
|
+
return { success: true, data: result.data }
|
|
426
|
+
} else {
|
|
427
|
+
return { success: false, error: result.error.message }
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Validates multiple values with their respective schemas
|
|
433
|
+
*/
|
|
434
|
+
export function validateMultiple<T extends Record<string, any>>(
|
|
435
|
+
validations: { [K in keyof T]: { schema: z.ZodSchema<T[K]>; data: unknown } }
|
|
436
|
+
): T {
|
|
437
|
+
const result = {} as T
|
|
438
|
+
|
|
439
|
+
for (const [key, { schema, data }] of Object.entries(validations)) {
|
|
440
|
+
result[key as keyof T] = parseWithSchema(schema, data, `Field '${key}'`)
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
return result
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
// =============================================================================
|
|
447
|
+
// EXPORTS
|
|
448
|
+
// =============================================================================
|
|
449
|
+
|
|
450
|
+
export type {
|
|
451
|
+
z as ZodType
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
// Export all schemas for external use
|
|
455
|
+
export {
|
|
456
|
+
z
|
|
457
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/*
|
|
2
|
+
(
|
|
3
|
+
(/(
|
|
4
|
+
(//(
|
|
5
|
+
(///(
|
|
6
|
+
(/////(
|
|
7
|
+
(//////( )
|
|
8
|
+
(////////( (/)
|
|
9
|
+
(////////( (///)
|
|
10
|
+
(//////////( (////)
|
|
11
|
+
(//////////( (//////)
|
|
12
|
+
(////////////( (///////)
|
|
13
|
+
(/////////////( (/////////)
|
|
14
|
+
(//////////////( (///////////)
|
|
15
|
+
(///////////////( (/////////////)
|
|
16
|
+
(////////////////( (//////////////)
|
|
17
|
+
((((((((((((((((((( (((((((((((((((
|
|
18
|
+
((((((((((((((((((( ((((((((((((((
|
|
19
|
+
((((((((((((((((((( ((((((((((((((
|
|
20
|
+
(((((((((((((((((((( (((((((((((((
|
|
21
|
+
(((((((((((((((((((( ((((((((((((
|
|
22
|
+
((((((((((((((((((( ((((((((((((
|
|
23
|
+
((((((((((((((((((( ((((((((((
|
|
24
|
+
((((((((((((((((((/ (((((((((
|
|
25
|
+
(((((((((((((((((( ((((((((
|
|
26
|
+
((((((((((((((((( (((((((
|
|
27
|
+
(((((((((((((((((( (((((
|
|
28
|
+
################# ##
|
|
29
|
+
################ #
|
|
30
|
+
################# ##
|
|
31
|
+
%################ ###
|
|
32
|
+
###############( ####
|
|
33
|
+
############### ####
|
|
34
|
+
############### ######
|
|
35
|
+
%#############( (#######
|
|
36
|
+
%############# #########
|
|
37
|
+
############( ##########
|
|
38
|
+
########### #############
|
|
39
|
+
######### ##############
|
|
40
|
+
%######
|
|
41
|
+
|
|
42
|
+
Powered by Knish.IO: Connecting a Decentralized World
|
|
43
|
+
|
|
44
|
+
Please visit https://github.com/WishKnish/KnishIO-Client-TS for information.
|
|
45
|
+
|
|
46
|
+
License: https://github.com/WishKnish/KnishIO-Client-TS/blob/master/LICENSE
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
import Subscribe from './Subscribe'
|
|
50
|
+
import { gql } from '@urql/core'
|
|
51
|
+
import type { GraphQLClient as IGraphQLClient } from '@/types'
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* ActiveSessionSubscribe handles real-time active user session events
|
|
55
|
+
*/
|
|
56
|
+
export default class ActiveSessionSubscribe extends Subscribe {
|
|
57
|
+
constructor(graphQLClient: IGraphQLClient) {
|
|
58
|
+
super(graphQLClient)
|
|
59
|
+
this.$__subscribe = gql`
|
|
60
|
+
subscription onActiveUser($metaType: String!, $metaId: String!) {
|
|
61
|
+
ActiveUser(metaType: $metaType, metaId: $metaId) {
|
|
62
|
+
bundleHash
|
|
63
|
+
metaType
|
|
64
|
+
metaId
|
|
65
|
+
jsonData
|
|
66
|
+
createdAt
|
|
67
|
+
updatedAt
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
`
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/*
|
|
2
|
+
(
|
|
3
|
+
(/(
|
|
4
|
+
(//(
|
|
5
|
+
(///(
|
|
6
|
+
(/////(
|
|
7
|
+
(//////( )
|
|
8
|
+
(////////( (/)
|
|
9
|
+
(////////( (///)
|
|
10
|
+
(//////////( (////)
|
|
11
|
+
(//////////( (//////)
|
|
12
|
+
(////////////( (///////)
|
|
13
|
+
(/////////////( (/////////)
|
|
14
|
+
(//////////////( (///////////)
|
|
15
|
+
(///////////////( (/////////////)
|
|
16
|
+
(////////////////( (//////////////)
|
|
17
|
+
((((((((((((((((((( (((((((((((((((
|
|
18
|
+
((((((((((((((((((( ((((((((((((((
|
|
19
|
+
((((((((((((((((((( ((((((((((((((
|
|
20
|
+
(((((((((((((((((((( (((((((((((((
|
|
21
|
+
(((((((((((((((((((( ((((((((((((
|
|
22
|
+
((((((((((((((((((( ((((((((((((
|
|
23
|
+
((((((((((((((((((( ((((((((((
|
|
24
|
+
((((((((((((((((((/ (((((((((
|
|
25
|
+
(((((((((((((((((( ((((((((
|
|
26
|
+
((((((((((((((((( (((((((
|
|
27
|
+
(((((((((((((((((( (((((
|
|
28
|
+
################# ##
|
|
29
|
+
################ #
|
|
30
|
+
################# ##
|
|
31
|
+
%################ ###
|
|
32
|
+
###############( ####
|
|
33
|
+
############### ####
|
|
34
|
+
############### ######
|
|
35
|
+
%#############( (#######
|
|
36
|
+
%############# #########
|
|
37
|
+
############( ##########
|
|
38
|
+
########### #############
|
|
39
|
+
######### ##############
|
|
40
|
+
%######
|
|
41
|
+
|
|
42
|
+
Powered by Knish.IO: Connecting a Decentralized World
|
|
43
|
+
|
|
44
|
+
Please visit https://github.com/WishKnish/KnishIO-Client-TS for information.
|
|
45
|
+
|
|
46
|
+
License: https://github.com/WishKnish/KnishIO-Client-TS/blob/master/LICENSE
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
import Subscribe from './Subscribe'
|
|
50
|
+
import { gql } from '@urql/core'
|
|
51
|
+
import type { GraphQLClient as IGraphQLClient } from '@/types'
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* ActiveWalletSubscribe handles real-time active wallet events
|
|
55
|
+
*/
|
|
56
|
+
export default class ActiveWalletSubscribe extends Subscribe {
|
|
57
|
+
constructor(graphQLClient: IGraphQLClient) {
|
|
58
|
+
super(graphQLClient)
|
|
59
|
+
this.$__subscribe = gql`
|
|
60
|
+
subscription onActiveWallet($bundle: String!) {
|
|
61
|
+
ActiveWallet(bundle: $bundle) {
|
|
62
|
+
address
|
|
63
|
+
bundleHash
|
|
64
|
+
walletBundle {
|
|
65
|
+
bundleHash
|
|
66
|
+
slug
|
|
67
|
+
createdAt
|
|
68
|
+
}
|
|
69
|
+
tokenSlug
|
|
70
|
+
token {
|
|
71
|
+
slug
|
|
72
|
+
name
|
|
73
|
+
fungibility
|
|
74
|
+
supply
|
|
75
|
+
decimals
|
|
76
|
+
amount
|
|
77
|
+
icon
|
|
78
|
+
createdAt
|
|
79
|
+
}
|
|
80
|
+
batchId
|
|
81
|
+
position
|
|
82
|
+
characters
|
|
83
|
+
pubkey
|
|
84
|
+
amount
|
|
85
|
+
createdAt
|
|
86
|
+
metas {
|
|
87
|
+
molecularHash
|
|
88
|
+
position
|
|
89
|
+
metaType
|
|
90
|
+
metaId
|
|
91
|
+
key
|
|
92
|
+
value
|
|
93
|
+
createdAt
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
`
|
|
98
|
+
}
|
|
99
|
+
}
|