@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,541 @@
|
|
|
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
|
+
* Cryptographic type definitions for KnishIO SDK
|
|
51
|
+
* Ensures type safety for post-quantum cryptographic operations
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
import type { WalletAddress, BundleHash, Position, TokenSlug } from './index'
|
|
55
|
+
|
|
56
|
+
// =============================================================================
|
|
57
|
+
// CRYPTOGRAPHIC ALGORITHM TYPES
|
|
58
|
+
// =============================================================================
|
|
59
|
+
|
|
60
|
+
export type HashAlgorithm = 'SHAKE256' | 'SHA3-256' | 'BLAKE2B'
|
|
61
|
+
export type SignatureAlgorithm = 'XMSS' | 'ML-KEM768' | 'SPHINCS+'
|
|
62
|
+
export type EncryptionAlgorithm = 'ML-KEM768' | 'Kyber768' | 'ChaCha20Poly1305'
|
|
63
|
+
|
|
64
|
+
// =============================================================================
|
|
65
|
+
// SHAKE256 SPECIFIC TYPES
|
|
66
|
+
// =============================================================================
|
|
67
|
+
|
|
68
|
+
export interface SHAKE256Options {
|
|
69
|
+
input: string | Uint8Array
|
|
70
|
+
outputLength: number // in bits
|
|
71
|
+
encoding?: 'hex' | 'base64' | 'bytes'
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface SHAKE256Result {
|
|
75
|
+
hash: string
|
|
76
|
+
algorithm: 'SHAKE256'
|
|
77
|
+
inputLength: number
|
|
78
|
+
outputLength: number
|
|
79
|
+
timestamp: number
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// =============================================================================
|
|
83
|
+
// KEY GENERATION TYPES
|
|
84
|
+
// =============================================================================
|
|
85
|
+
|
|
86
|
+
export interface KeyGenerationOptions {
|
|
87
|
+
secret?: string | null
|
|
88
|
+
token?: TokenSlug | string | null
|
|
89
|
+
position?: Position | string | null
|
|
90
|
+
algorithm?: SignatureAlgorithm
|
|
91
|
+
keyLength?: number
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface PrivateKey {
|
|
95
|
+
readonly key: string
|
|
96
|
+
readonly algorithm: SignatureAlgorithm
|
|
97
|
+
readonly length: number
|
|
98
|
+
readonly createdAt: number
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface PublicKey {
|
|
102
|
+
readonly key: string
|
|
103
|
+
readonly address: WalletAddress
|
|
104
|
+
readonly algorithm: SignatureAlgorithm
|
|
105
|
+
readonly length: number
|
|
106
|
+
readonly createdAt: number
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export interface KeyPair {
|
|
110
|
+
readonly privateKey: PrivateKey
|
|
111
|
+
readonly publicKey: PublicKey
|
|
112
|
+
readonly algorithm: SignatureAlgorithm
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// =============================================================================
|
|
116
|
+
// XMSS (eXtended Merkle Signature Scheme) TYPES
|
|
117
|
+
// =============================================================================
|
|
118
|
+
|
|
119
|
+
export interface XMSSParameters {
|
|
120
|
+
height: number // Tree height (typically 10, 16, or 20)
|
|
121
|
+
winternitzParameter: number // Winternitz parameter (typically 16)
|
|
122
|
+
hashFunction: 'SHAKE256' | 'SHA3-256'
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export interface XMSSSignatureState {
|
|
126
|
+
nextIndex: number
|
|
127
|
+
secretSeed: string
|
|
128
|
+
publicSeed: string
|
|
129
|
+
root: string
|
|
130
|
+
usedIndices: Set<number>
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export interface XMSSSignature {
|
|
134
|
+
signature: string
|
|
135
|
+
index: number
|
|
136
|
+
authPath: string[]
|
|
137
|
+
randomization: string
|
|
138
|
+
timestamp: number
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// =============================================================================
|
|
142
|
+
// ML-KEM768 (Post-Quantum Key Encapsulation) TYPES
|
|
143
|
+
// =============================================================================
|
|
144
|
+
|
|
145
|
+
export interface MLKEMKeyPair {
|
|
146
|
+
privateKey: Uint8Array
|
|
147
|
+
publicKey: Uint8Array
|
|
148
|
+
algorithm: 'ML-KEM768'
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export interface MLKEMEncapsulationResult {
|
|
152
|
+
ciphertext: Uint8Array
|
|
153
|
+
sharedSecret: Uint8Array
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export interface MLKEMDecapsulationOptions {
|
|
157
|
+
ciphertext: Uint8Array
|
|
158
|
+
privateKey: Uint8Array
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// =============================================================================
|
|
162
|
+
// WALLET CRYPTOGRAPHIC TYPES
|
|
163
|
+
// =============================================================================
|
|
164
|
+
|
|
165
|
+
export interface WalletKeyGeneration {
|
|
166
|
+
secret: string
|
|
167
|
+
token: TokenSlug | string
|
|
168
|
+
position: Position | string
|
|
169
|
+
bundleHash?: BundleHash | string
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export interface WalletCryptoResult {
|
|
173
|
+
privateKey: string
|
|
174
|
+
publicKey: string
|
|
175
|
+
address: WalletAddress
|
|
176
|
+
bundle: BundleHash
|
|
177
|
+
position: Position
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// =============================================================================
|
|
181
|
+
// SIGNATURE TYPES
|
|
182
|
+
// =============================================================================
|
|
183
|
+
|
|
184
|
+
export interface SignatureOptions {
|
|
185
|
+
message: string | Uint8Array
|
|
186
|
+
privateKey: PrivateKey | string
|
|
187
|
+
algorithm?: SignatureAlgorithm
|
|
188
|
+
oneTimeUse?: boolean
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export interface SignatureResult {
|
|
192
|
+
signature: string
|
|
193
|
+
algorithm: SignatureAlgorithm
|
|
194
|
+
messageHash: string
|
|
195
|
+
publicKey: string
|
|
196
|
+
timestamp: number
|
|
197
|
+
otsFragments?: OTSFragment[]
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export interface VerificationOptions {
|
|
201
|
+
message: string | Uint8Array
|
|
202
|
+
signature: string
|
|
203
|
+
publicKey: PublicKey | string
|
|
204
|
+
algorithm?: SignatureAlgorithm
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export interface VerificationResult {
|
|
208
|
+
valid: boolean
|
|
209
|
+
algorithm: SignatureAlgorithm
|
|
210
|
+
publicKey: string
|
|
211
|
+
messageHash: string
|
|
212
|
+
timestamp: number
|
|
213
|
+
error?: string
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// =============================================================================
|
|
217
|
+
// ONE-TIME SIGNATURE (OTS) TYPES
|
|
218
|
+
// =============================================================================
|
|
219
|
+
|
|
220
|
+
export interface OTSFragment {
|
|
221
|
+
index: number
|
|
222
|
+
fragment: string
|
|
223
|
+
algorithm: SignatureAlgorithm
|
|
224
|
+
atomIndex?: number
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export interface OTSKeyManager {
|
|
228
|
+
generateNextKey(): Promise<PrivateKey>
|
|
229
|
+
markKeyUsed(keyId: string): void
|
|
230
|
+
rotateKeys(): Promise<void>
|
|
231
|
+
getUsedKeyCount(): number
|
|
232
|
+
getRemainingKeys(): number
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// =============================================================================
|
|
236
|
+
// MOLECULAR HASH TYPES
|
|
237
|
+
// =============================================================================
|
|
238
|
+
|
|
239
|
+
export interface MolecularHashOptions {
|
|
240
|
+
atoms: Array<{
|
|
241
|
+
position: string
|
|
242
|
+
walletAddress: WalletAddress
|
|
243
|
+
isotope: string
|
|
244
|
+
token: TokenSlug
|
|
245
|
+
value: string | null
|
|
246
|
+
metaType?: string | null
|
|
247
|
+
metaId?: string | null
|
|
248
|
+
createdAt: string
|
|
249
|
+
index: number
|
|
250
|
+
}>
|
|
251
|
+
algorithm?: HashAlgorithm
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export interface MolecularHashResult {
|
|
255
|
+
hash: string
|
|
256
|
+
algorithm: HashAlgorithm
|
|
257
|
+
atomCount: number
|
|
258
|
+
base17Hash: string
|
|
259
|
+
timestamp: number
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// =============================================================================
|
|
263
|
+
// ENCRYPTION/DECRYPTION TYPES
|
|
264
|
+
// =============================================================================
|
|
265
|
+
|
|
266
|
+
export interface EncryptionOptions {
|
|
267
|
+
message: string | Uint8Array
|
|
268
|
+
publicKey: PublicKey | string
|
|
269
|
+
algorithm?: EncryptionAlgorithm
|
|
270
|
+
additionalData?: Uint8Array
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export interface EncryptionResult {
|
|
274
|
+
ciphertext: string
|
|
275
|
+
algorithm: EncryptionAlgorithm
|
|
276
|
+
nonce: string
|
|
277
|
+
tag: string
|
|
278
|
+
timestamp: number
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export interface DecryptionOptions {
|
|
282
|
+
ciphertext: string
|
|
283
|
+
privateKey: PrivateKey | string
|
|
284
|
+
algorithm?: EncryptionAlgorithm
|
|
285
|
+
nonce: string
|
|
286
|
+
tag: string
|
|
287
|
+
additionalData?: Uint8Array
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export interface DecryptionResult {
|
|
291
|
+
plaintext: string
|
|
292
|
+
algorithm: EncryptionAlgorithm
|
|
293
|
+
timestamp: number
|
|
294
|
+
valid: boolean
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// =============================================================================
|
|
298
|
+
// BUNDLE HASH GENERATION TYPES
|
|
299
|
+
// =============================================================================
|
|
300
|
+
|
|
301
|
+
export interface BundleHashOptions {
|
|
302
|
+
secret: string
|
|
303
|
+
source?: string | null
|
|
304
|
+
algorithm?: HashAlgorithm
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export interface BundleHashResult {
|
|
308
|
+
hash: BundleHash
|
|
309
|
+
algorithm: HashAlgorithm
|
|
310
|
+
secretHash: string
|
|
311
|
+
timestamp: number
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// =============================================================================
|
|
315
|
+
// POSITION GENERATION TYPES
|
|
316
|
+
// =============================================================================
|
|
317
|
+
|
|
318
|
+
export interface PositionGenerationOptions {
|
|
319
|
+
entropy?: Uint8Array | null
|
|
320
|
+
algorithm?: HashAlgorithm
|
|
321
|
+
length?: number
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
export interface PositionGenerationResult {
|
|
325
|
+
position: Position
|
|
326
|
+
entropy: string
|
|
327
|
+
algorithm: HashAlgorithm
|
|
328
|
+
timestamp: number
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// =============================================================================
|
|
332
|
+
// SECRET GENERATION TYPES
|
|
333
|
+
// =============================================================================
|
|
334
|
+
|
|
335
|
+
export interface SecretGenerationOptions {
|
|
336
|
+
seed?: string | null
|
|
337
|
+
length?: number
|
|
338
|
+
algorithm?: HashAlgorithm
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export interface SecretGenerationResult {
|
|
342
|
+
secret: string
|
|
343
|
+
algorithm: HashAlgorithm
|
|
344
|
+
seedUsed: boolean
|
|
345
|
+
length: number
|
|
346
|
+
timestamp: number
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// =============================================================================
|
|
350
|
+
// CROSS-PLATFORM COMPATIBILITY TYPES
|
|
351
|
+
// =============================================================================
|
|
352
|
+
|
|
353
|
+
export interface TestVector {
|
|
354
|
+
input: string
|
|
355
|
+
expectedOutput: string
|
|
356
|
+
algorithm: HashAlgorithm | SignatureAlgorithm
|
|
357
|
+
parameters?: Record<string, unknown>
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
export interface CryptoCompatibilityResult {
|
|
361
|
+
compatible: boolean
|
|
362
|
+
algorithm: string
|
|
363
|
+
testsPassed: number
|
|
364
|
+
testsFailed: number
|
|
365
|
+
errors: string[]
|
|
366
|
+
details: Array<{
|
|
367
|
+
test: string
|
|
368
|
+
expected: string
|
|
369
|
+
actual: string
|
|
370
|
+
passed: boolean
|
|
371
|
+
}>
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// =============================================================================
|
|
375
|
+
// PERFORMANCE MONITORING TYPES
|
|
376
|
+
// =============================================================================
|
|
377
|
+
|
|
378
|
+
export interface CryptoPerformanceMetrics {
|
|
379
|
+
operation: string
|
|
380
|
+
algorithm: string
|
|
381
|
+
duration: number
|
|
382
|
+
inputSize: number
|
|
383
|
+
outputSize: number
|
|
384
|
+
timestamp: number
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
export interface CryptoPerformanceThresholds {
|
|
388
|
+
shake256: number // max ms
|
|
389
|
+
keyGeneration: number // max ms
|
|
390
|
+
signing: number // max ms
|
|
391
|
+
verification: number // max ms
|
|
392
|
+
encryption: number // max ms
|
|
393
|
+
decryption: number // max ms
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// =============================================================================
|
|
397
|
+
// CRYPTOGRAPHIC LIBRARY INTERFACE TYPES
|
|
398
|
+
// =============================================================================
|
|
399
|
+
|
|
400
|
+
export interface CryptoLibrary {
|
|
401
|
+
// Hash functions
|
|
402
|
+
shake256(input: string, outputLength: number): Promise<string>
|
|
403
|
+
sha3_256(input: string): Promise<string>
|
|
404
|
+
|
|
405
|
+
// Key generation
|
|
406
|
+
generateKeyPair(options: KeyGenerationOptions): Promise<KeyPair>
|
|
407
|
+
generatePrivateKey(options: KeyGenerationOptions): Promise<PrivateKey>
|
|
408
|
+
derivePublicKey(privateKey: PrivateKey): Promise<PublicKey>
|
|
409
|
+
|
|
410
|
+
// Address generation
|
|
411
|
+
generateAddress(publicKey: PublicKey | string): Promise<WalletAddress>
|
|
412
|
+
|
|
413
|
+
// Signatures
|
|
414
|
+
sign(options: SignatureOptions): Promise<SignatureResult>
|
|
415
|
+
verify(options: VerificationOptions): Promise<VerificationResult>
|
|
416
|
+
|
|
417
|
+
// Encryption
|
|
418
|
+
encrypt(options: EncryptionOptions): Promise<EncryptionResult>
|
|
419
|
+
decrypt(options: DecryptionOptions): Promise<DecryptionResult>
|
|
420
|
+
|
|
421
|
+
// Utility functions
|
|
422
|
+
generateSecret(options: SecretGenerationOptions): Promise<string>
|
|
423
|
+
generateBundleHash(options: BundleHashOptions): Promise<BundleHash>
|
|
424
|
+
generatePosition(options?: PositionGenerationOptions): Promise<Position>
|
|
425
|
+
generateBatchId(options?: { molecularHash?: string; index?: number }): Promise<string>
|
|
426
|
+
|
|
427
|
+
// Validation
|
|
428
|
+
validateHash(hash: string, algorithm: HashAlgorithm): boolean
|
|
429
|
+
validateSignature(signature: string, algorithm: SignatureAlgorithm): boolean
|
|
430
|
+
validatePublicKey(publicKey: string, algorithm: SignatureAlgorithm): boolean
|
|
431
|
+
|
|
432
|
+
// Compatibility testing
|
|
433
|
+
runCompatibilityTests(testVectors: TestVector[]): Promise<CryptoCompatibilityResult>
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
// =============================================================================
|
|
437
|
+
// ERROR TYPES FOR CRYPTOGRAPHIC OPERATIONS
|
|
438
|
+
// =============================================================================
|
|
439
|
+
|
|
440
|
+
export type CryptoErrorType =
|
|
441
|
+
| 'INVALID_INPUT'
|
|
442
|
+
| 'INVALID_KEY'
|
|
443
|
+
| 'INVALID_SIGNATURE'
|
|
444
|
+
| 'ENCRYPTION_FAILED'
|
|
445
|
+
| 'DECRYPTION_FAILED'
|
|
446
|
+
| 'KEY_GENERATION_FAILED'
|
|
447
|
+
| 'HASH_COMPUTATION_FAILED'
|
|
448
|
+
| 'INCOMPATIBLE_ALGORITHM'
|
|
449
|
+
| 'INSUFFICIENT_ENTROPY'
|
|
450
|
+
| 'KEY_ALREADY_USED'
|
|
451
|
+
| 'SIGNATURE_VERIFICATION_FAILED'
|
|
452
|
+
|
|
453
|
+
export interface CryptoError extends Error {
|
|
454
|
+
type: CryptoErrorType
|
|
455
|
+
algorithm?: string
|
|
456
|
+
operation?: string
|
|
457
|
+
details?: Record<string, unknown>
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
// =============================================================================
|
|
461
|
+
// CONSTANTS FOR CRYPTOGRAPHIC OPERATIONS
|
|
462
|
+
// =============================================================================
|
|
463
|
+
|
|
464
|
+
export const CRYPTO_CONSTANTS = {
|
|
465
|
+
SHAKE256_OUTPUT_LENGTH: 256,
|
|
466
|
+
SECRET_LENGTH: 2048,
|
|
467
|
+
POSITION_LENGTH: 64,
|
|
468
|
+
ADDRESS_LENGTH: 64,
|
|
469
|
+
BUNDLE_HASH_LENGTH: 64,
|
|
470
|
+
|
|
471
|
+
XMSS_TREE_HEIGHT: 10,
|
|
472
|
+
XMSS_WINTERNITZ_PARAMETER: 16,
|
|
473
|
+
|
|
474
|
+
ML_KEM768_PUBLIC_KEY_SIZE: 1184,
|
|
475
|
+
ML_KEM768_PRIVATE_KEY_SIZE: 2400,
|
|
476
|
+
ML_KEM768_CIPHERTEXT_SIZE: 1088,
|
|
477
|
+
ML_KEM768_SHARED_SECRET_SIZE: 32,
|
|
478
|
+
|
|
479
|
+
KEY_FRAGMENT_SIZE: 128,
|
|
480
|
+
OTS_FRAGMENT_COUNT: 16,
|
|
481
|
+
HASH_ITERATION_COUNT: 16
|
|
482
|
+
} as const
|
|
483
|
+
|
|
484
|
+
// =============================================================================
|
|
485
|
+
// TYPE GUARDS FOR CRYPTOGRAPHIC TYPES
|
|
486
|
+
// =============================================================================
|
|
487
|
+
|
|
488
|
+
export function isPrivateKey(obj: unknown): obj is PrivateKey {
|
|
489
|
+
return typeof obj === 'object' &&
|
|
490
|
+
obj !== null &&
|
|
491
|
+
'key' in obj &&
|
|
492
|
+
'algorithm' in obj &&
|
|
493
|
+
'length' in obj &&
|
|
494
|
+
'createdAt' in obj
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
export function isPublicKey(obj: unknown): obj is PublicKey {
|
|
498
|
+
return typeof obj === 'object' &&
|
|
499
|
+
obj !== null &&
|
|
500
|
+
'key' in obj &&
|
|
501
|
+
'address' in obj &&
|
|
502
|
+
'algorithm' in obj &&
|
|
503
|
+
'length' in obj &&
|
|
504
|
+
'createdAt' in obj
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
export function isKeyPair(obj: unknown): obj is KeyPair {
|
|
508
|
+
return typeof obj === 'object' &&
|
|
509
|
+
obj !== null &&
|
|
510
|
+
'privateKey' in obj &&
|
|
511
|
+
'publicKey' in obj &&
|
|
512
|
+
'algorithm' in obj &&
|
|
513
|
+
isPrivateKey((obj as KeyPair).privateKey) &&
|
|
514
|
+
isPublicKey((obj as KeyPair).publicKey)
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
export function isSignatureResult(obj: unknown): obj is SignatureResult {
|
|
518
|
+
return typeof obj === 'object' &&
|
|
519
|
+
obj !== null &&
|
|
520
|
+
'signature' in obj &&
|
|
521
|
+
'algorithm' in obj &&
|
|
522
|
+
'messageHash' in obj &&
|
|
523
|
+
'publicKey' in obj &&
|
|
524
|
+
'timestamp' in obj
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
export function isVerificationResult(obj: unknown): obj is VerificationResult {
|
|
528
|
+
return typeof obj === 'object' &&
|
|
529
|
+
obj !== null &&
|
|
530
|
+
'valid' in obj &&
|
|
531
|
+
'algorithm' in obj &&
|
|
532
|
+
'publicKey' in obj &&
|
|
533
|
+
'messageHash' in obj &&
|
|
534
|
+
'timestamp' in obj
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
// =============================================================================
|
|
538
|
+
// EXPORT ALL TYPES
|
|
539
|
+
// =============================================================================
|
|
540
|
+
|
|
541
|
+
// All types are already exported at their definitions above
|