@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,147 @@
|
|
|
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 BaseException, { type BaseExceptionOptions } from './BaseException'
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* UnauthenticatedException - Thrown when authentication is required but missing or invalid
|
|
53
|
+
* Used for GraphQL operations that require valid authentication tokens
|
|
54
|
+
*/
|
|
55
|
+
export default class UnauthenticatedException extends BaseException {
|
|
56
|
+
public readonly errorType: string = 'UNAUTHENTICATED_ERROR'
|
|
57
|
+
|
|
58
|
+
constructor(message: string, options: BaseExceptionOptions = {}) {
|
|
59
|
+
super('UNAUTHENTICATED_ERROR', message, options)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Create exception for missing authentication
|
|
64
|
+
*/
|
|
65
|
+
static missingAuth(operation?: string, context?: Record<string, unknown>): UnauthenticatedException {
|
|
66
|
+
const message = operation
|
|
67
|
+
? `Authentication required for operation: ${operation}`
|
|
68
|
+
: 'Authentication required'
|
|
69
|
+
|
|
70
|
+
return new UnauthenticatedException(message, {
|
|
71
|
+
code: 'MISSING_AUTH',
|
|
72
|
+
context: {
|
|
73
|
+
...(operation ? { operation } : {}),
|
|
74
|
+
...context
|
|
75
|
+
}
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Create exception for expired tokens
|
|
81
|
+
*/
|
|
82
|
+
static tokenExpired(expiresAt?: number, context?: Record<string, unknown>): UnauthenticatedException {
|
|
83
|
+
const message = expiresAt
|
|
84
|
+
? `Authentication token expired at ${new Date(expiresAt * 1000).toISOString()}`
|
|
85
|
+
: 'Authentication token expired'
|
|
86
|
+
|
|
87
|
+
return new UnauthenticatedException(message, {
|
|
88
|
+
code: 'TOKEN_EXPIRED',
|
|
89
|
+
context: {
|
|
90
|
+
...(expiresAt ? { expiresAt } : {}),
|
|
91
|
+
...(expiresAt ? { expiredAt: new Date(expiresAt * 1000).toISOString() } : {}),
|
|
92
|
+
...context
|
|
93
|
+
}
|
|
94
|
+
})
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Create exception for invalid tokens
|
|
99
|
+
*/
|
|
100
|
+
static invalidToken(reason?: string, context?: Record<string, unknown>): UnauthenticatedException {
|
|
101
|
+
const message = reason
|
|
102
|
+
? `Invalid authentication token: ${reason}`
|
|
103
|
+
: 'Invalid authentication token'
|
|
104
|
+
|
|
105
|
+
return new UnauthenticatedException(message, {
|
|
106
|
+
code: 'INVALID_TOKEN',
|
|
107
|
+
context: {
|
|
108
|
+
...(reason ? { reason } : {}),
|
|
109
|
+
...context
|
|
110
|
+
}
|
|
111
|
+
})
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Create exception for rejected authentication
|
|
116
|
+
*/
|
|
117
|
+
static authenticationRejected(reason?: string, context?: Record<string, unknown>): UnauthenticatedException {
|
|
118
|
+
const message = reason
|
|
119
|
+
? `Authentication rejected: ${reason}`
|
|
120
|
+
: 'Authentication rejected by server'
|
|
121
|
+
|
|
122
|
+
return new UnauthenticatedException(message, {
|
|
123
|
+
code: 'AUTHENTICATION_REJECTED',
|
|
124
|
+
context: {
|
|
125
|
+
...(reason ? { reason } : {}),
|
|
126
|
+
...context
|
|
127
|
+
}
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Create exception for missing credentials
|
|
133
|
+
*/
|
|
134
|
+
static missingCredentials(credentialType?: string, context?: Record<string, unknown>): UnauthenticatedException {
|
|
135
|
+
const message = credentialType
|
|
136
|
+
? `Missing required credential: ${credentialType}`
|
|
137
|
+
: 'Missing required authentication credentials'
|
|
138
|
+
|
|
139
|
+
return new UnauthenticatedException(message, {
|
|
140
|
+
code: 'MISSING_CREDENTIALS',
|
|
141
|
+
context: {
|
|
142
|
+
...(credentialType ? { credentialType } : {}),
|
|
143
|
+
...context
|
|
144
|
+
}
|
|
145
|
+
})
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
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 BaseException, { type BaseExceptionOptions } from './BaseException'
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Exception thrown when wallet credentials are invalid or compromised
|
|
53
|
+
* Used for wallet authentication and authorization failures
|
|
54
|
+
*/
|
|
55
|
+
export default class WalletCredentialException extends BaseException {
|
|
56
|
+
constructor(message = 'Invalid wallet credentials', options: BaseExceptionOptions = {}) {
|
|
57
|
+
super('WALLET_CREDENTIAL_ERROR', message, options)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Factory method for invalid secret
|
|
62
|
+
*/
|
|
63
|
+
static invalidSecret(): WalletCredentialException {
|
|
64
|
+
return new WalletCredentialException(
|
|
65
|
+
'Wallet secret is invalid or corrupted',
|
|
66
|
+
{
|
|
67
|
+
code: 'INVALID_SECRET'
|
|
68
|
+
}
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Factory method for missing credentials
|
|
74
|
+
*/
|
|
75
|
+
static missingCredentials(): WalletCredentialException {
|
|
76
|
+
return new WalletCredentialException(
|
|
77
|
+
'Wallet credentials are required but not provided',
|
|
78
|
+
{
|
|
79
|
+
code: 'MISSING_CREDENTIALS'
|
|
80
|
+
}
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Factory method for expired credentials
|
|
86
|
+
*/
|
|
87
|
+
static credentialsExpired(): WalletCredentialException {
|
|
88
|
+
return new WalletCredentialException(
|
|
89
|
+
'Wallet credentials have expired',
|
|
90
|
+
{
|
|
91
|
+
code: 'CREDENTIALS_EXPIRED'
|
|
92
|
+
}
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Factory method for bundle mismatch
|
|
98
|
+
*/
|
|
99
|
+
static bundleMismatch(expected: string, actual: string): WalletCredentialException {
|
|
100
|
+
return new WalletCredentialException(
|
|
101
|
+
`Wallet bundle mismatch: expected ${expected.substring(0, 16)}..., got ${actual.substring(0, 16)}...`,
|
|
102
|
+
{
|
|
103
|
+
details: { expected: expected.substring(0, 16) + '...', actual: actual.substring(0, 16) + '...' },
|
|
104
|
+
code: 'BUNDLE_MISMATCH'
|
|
105
|
+
}
|
|
106
|
+
)
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
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 BaseException from './BaseException'
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Thrown when failing to retrieve shadow wallets
|
|
53
|
+
*/
|
|
54
|
+
export class WalletShadowException extends BaseException {
|
|
55
|
+
/**
|
|
56
|
+
* Constructor using proper error type
|
|
57
|
+
*/
|
|
58
|
+
constructor(
|
|
59
|
+
message: string = 'The shadow wallet does not exist'
|
|
60
|
+
) {
|
|
61
|
+
super('WALLET_SHADOW_ERROR', message)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export default WalletShadowException
|
|
@@ -0,0 +1,58 @@
|
|
|
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 BaseException from './BaseException'
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Exception thrown when token type is invalid for operation
|
|
53
|
+
*/
|
|
54
|
+
export default class WrongTokenTypeException extends BaseException {
|
|
55
|
+
constructor(message = 'Wrong token type for this operation') {
|
|
56
|
+
super('WRONG_TOKEN_TYPE_ERROR', message)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,272 @@
|
|
|
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
|
+
* Complete KnishIO Exception System
|
|
51
|
+
* Exports all 22 exception classes maintaining compatibility with JS SDK
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
// Base Exception
|
|
55
|
+
export { default as BaseException } from './BaseException'
|
|
56
|
+
export type { BaseExceptionOptions } from './BaseException'
|
|
57
|
+
|
|
58
|
+
// Core exceptions (implemented)
|
|
59
|
+
export { default as AtomIndexException } from './AtomIndexException'
|
|
60
|
+
export { default as AtomsMissingException } from './AtomsMissingException'
|
|
61
|
+
export { default as MolecularHashMismatchException } from './MolecularHashMismatchException'
|
|
62
|
+
export { default as SignatureMismatchException } from './SignatureMismatchException'
|
|
63
|
+
export { default as TransferBalanceException } from './TransferBalanceException'
|
|
64
|
+
export { default as WalletCredentialException } from './WalletCredentialException'
|
|
65
|
+
export { default as InvalidResponseException } from './InvalidResponseException'
|
|
66
|
+
|
|
67
|
+
// Additional exceptions (now implemented)
|
|
68
|
+
export { default as BalanceInsufficientException } from './BalanceInsufficientException'
|
|
69
|
+
export { default as BatchIdException } from './BatchIdException'
|
|
70
|
+
export { default as MetaMissingException } from './MetaMissingException'
|
|
71
|
+
export { default as MolecularHashMissingException } from './MolecularHashMissingException'
|
|
72
|
+
export { default as NegativeAmountException } from './NegativeAmountException'
|
|
73
|
+
export { default as PolicyInvalidException } from './PolicyInvalidException'
|
|
74
|
+
export { default as SignatureMalformedException } from './SignatureMalformedException'
|
|
75
|
+
export { default as TransferMalformedException } from './TransferMalformedException'
|
|
76
|
+
export { default as TransferMismatchedException } from './TransferMismatchedException'
|
|
77
|
+
export { default as TransferRemainderException } from './TransferRemainderException'
|
|
78
|
+
export { default as TransferToSelfException } from './TransferToSelfException'
|
|
79
|
+
export { default as TransferUnbalancedException } from './TransferUnbalancedException'
|
|
80
|
+
export { default as WrongTokenTypeException } from './WrongTokenTypeException'
|
|
81
|
+
|
|
82
|
+
// Additional essential exceptions (now implemented)
|
|
83
|
+
export { default as CodeException } from './CodeException'
|
|
84
|
+
export { default as UnauthenticatedException } from './UnauthenticatedException'
|
|
85
|
+
|
|
86
|
+
// Missing exceptions now implemented (Phase 1 complete)
|
|
87
|
+
export { default as AuthorizationRejectedException } from './AuthorizationRejectedException'
|
|
88
|
+
export { default as DecryptionKeyException } from './DecryptionKeyException'
|
|
89
|
+
export { default as StackableUnitAmountException } from './StackableUnitAmountException'
|
|
90
|
+
export { default as StackableUnitDecimalsException } from './StackableUnitDecimalsException'
|
|
91
|
+
export { default as WalletShadowException } from './WalletShadowException'
|
|
92
|
+
|
|
93
|
+
// Utility functions and type guards
|
|
94
|
+
export {
|
|
95
|
+
isKnishIOError,
|
|
96
|
+
hasErrorType,
|
|
97
|
+
getErrorMessage,
|
|
98
|
+
createErrorContext
|
|
99
|
+
} from './BaseException'
|
|
100
|
+
|
|
101
|
+
// =============================================================================
|
|
102
|
+
// EXCEPTION FACTORY FUNCTIONS
|
|
103
|
+
// =============================================================================
|
|
104
|
+
|
|
105
|
+
import BaseException from './BaseException'
|
|
106
|
+
import AtomIndexException from './AtomIndexException'
|
|
107
|
+
import AtomsMissingException from './AtomsMissingException'
|
|
108
|
+
import MolecularHashMismatchException from './MolecularHashMismatchException'
|
|
109
|
+
import SignatureMismatchException from './SignatureMismatchException'
|
|
110
|
+
import TransferBalanceException from './TransferBalanceException'
|
|
111
|
+
import WalletCredentialException from './WalletCredentialException'
|
|
112
|
+
import InvalidResponseException from './InvalidResponseException'
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Exception factory for creating typed exceptions
|
|
116
|
+
*/
|
|
117
|
+
export class ExceptionFactory {
|
|
118
|
+
/**
|
|
119
|
+
* Create AtomIndexException
|
|
120
|
+
*/
|
|
121
|
+
static atomIndex = {
|
|
122
|
+
indexConflict: AtomIndexException.indexConflict.bind(AtomIndexException),
|
|
123
|
+
indexOutOfRange: AtomIndexException.indexOutOfRange.bind(AtomIndexException),
|
|
124
|
+
missingIndex: AtomIndexException.missingIndex.bind(AtomIndexException)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Create AtomsMissingException
|
|
129
|
+
*/
|
|
130
|
+
static atomsMissing = {
|
|
131
|
+
emptyMolecule: AtomsMissingException.emptyMolecule.bind(AtomsMissingException),
|
|
132
|
+
missingIsotope: AtomsMissingException.missingIsotope.bind(AtomsMissingException),
|
|
133
|
+
missingRemainder: AtomsMissingException.missingRemainder.bind(AtomsMissingException),
|
|
134
|
+
missingValueAtoms: AtomsMissingException.missingValueAtoms.bind(AtomsMissingException)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Create MolecularHashMismatchException
|
|
139
|
+
*/
|
|
140
|
+
static molecularHashMismatch = {
|
|
141
|
+
hashMismatch: MolecularHashMismatchException.hashMismatch.bind(MolecularHashMismatchException),
|
|
142
|
+
invalidFormat: MolecularHashMismatchException.invalidFormat.bind(MolecularHashMismatchException),
|
|
143
|
+
crossPlatformMismatch: MolecularHashMismatchException.crossPlatformMismatch.bind(MolecularHashMismatchException),
|
|
144
|
+
atomIntegrityFailure: MolecularHashMismatchException.atomIntegrityFailure.bind(MolecularHashMismatchException)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Create SignatureMismatchException
|
|
149
|
+
*/
|
|
150
|
+
static signatureMismatch = {
|
|
151
|
+
verificationFailed: SignatureMismatchException.verificationFailed.bind(SignatureMismatchException),
|
|
152
|
+
otsVerificationFailed: SignatureMismatchException.otsVerificationFailed.bind(SignatureMismatchException),
|
|
153
|
+
crossPlatformMismatch: SignatureMismatchException.crossPlatformMismatch.bind(SignatureMismatchException)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Create TransferBalanceException
|
|
158
|
+
*/
|
|
159
|
+
static transferBalance = {
|
|
160
|
+
insufficientBalance: TransferBalanceException.insufficientBalance.bind(TransferBalanceException),
|
|
161
|
+
negativeBalance: TransferBalanceException.negativeBalance.bind(TransferBalanceException),
|
|
162
|
+
calculationError: TransferBalanceException.calculationError.bind(TransferBalanceException)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Create WalletCredentialException
|
|
167
|
+
*/
|
|
168
|
+
static walletCredential = {
|
|
169
|
+
invalidSecret: WalletCredentialException.invalidSecret.bind(WalletCredentialException),
|
|
170
|
+
missingCredentials: WalletCredentialException.missingCredentials.bind(WalletCredentialException),
|
|
171
|
+
credentialsExpired: WalletCredentialException.credentialsExpired.bind(WalletCredentialException),
|
|
172
|
+
bundleMismatch: WalletCredentialException.bundleMismatch.bind(WalletCredentialException)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Create InvalidResponseException
|
|
177
|
+
*/
|
|
178
|
+
static invalidResponse = {
|
|
179
|
+
malformedJson: InvalidResponseException.malformedJson.bind(InvalidResponseException),
|
|
180
|
+
graphqlError: InvalidResponseException.graphqlError.bind(InvalidResponseException),
|
|
181
|
+
missingData: InvalidResponseException.missingData.bind(InvalidResponseException),
|
|
182
|
+
networkError: InvalidResponseException.networkError.bind(InvalidResponseException)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Convert any error to KnishIO exception
|
|
187
|
+
*/
|
|
188
|
+
static fromError = BaseException.fromError.bind(BaseException)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// =============================================================================
|
|
192
|
+
// EXCEPTION CONSTANTS
|
|
193
|
+
// =============================================================================
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Exception type constants for easy reference
|
|
197
|
+
*/
|
|
198
|
+
export const EXCEPTION_TYPES = {
|
|
199
|
+
ATOM_INDEX_ERROR: 'ATOM_INDEX_ERROR',
|
|
200
|
+
ATOMS_MISSING_ERROR: 'ATOMS_MISSING_ERROR',
|
|
201
|
+
AUTHORIZATION_REJECTED_ERROR: 'AUTHORIZATION_REJECTED_ERROR',
|
|
202
|
+
BALANCE_INSUFFICIENT_ERROR: 'BALANCE_INSUFFICIENT_ERROR',
|
|
203
|
+
BATCH_ID_ERROR: 'BATCH_ID_ERROR',
|
|
204
|
+
CODE_ERROR: 'CODE_ERROR',
|
|
205
|
+
DECRYPTION_KEY_ERROR: 'DECRYPTION_KEY_ERROR',
|
|
206
|
+
INVALID_RESPONSE_ERROR: 'INVALID_RESPONSE_ERROR',
|
|
207
|
+
META_MISSING_ERROR: 'META_MISSING_ERROR',
|
|
208
|
+
MOLECULAR_HASH_MISMATCH_ERROR: 'MOLECULAR_HASH_MISMATCH_ERROR',
|
|
209
|
+
MOLECULAR_HASH_MISSING_ERROR: 'MOLECULAR_HASH_MISSING_ERROR',
|
|
210
|
+
NEGATIVE_AMOUNT_ERROR: 'NEGATIVE_AMOUNT_ERROR',
|
|
211
|
+
POLICY_INVALID_ERROR: 'POLICY_INVALID_ERROR',
|
|
212
|
+
SIGNATURE_MALFORMED_ERROR: 'SIGNATURE_MALFORMED_ERROR',
|
|
213
|
+
SIGNATURE_MISMATCH_ERROR: 'SIGNATURE_MISMATCH_ERROR',
|
|
214
|
+
STACKABLE_UNIT_AMOUNT_ERROR: 'STACKABLE_UNIT_AMOUNT_ERROR',
|
|
215
|
+
STACKABLE_UNIT_DECIMALS_ERROR: 'STACKABLE_UNIT_DECIMALS_ERROR',
|
|
216
|
+
TRANSFER_BALANCE_ERROR: 'TRANSFER_BALANCE_ERROR',
|
|
217
|
+
TRANSFER_MALFORMED_ERROR: 'TRANSFER_MALFORMED_ERROR',
|
|
218
|
+
TRANSFER_MISMATCHED_ERROR: 'TRANSFER_MISMATCHED_ERROR',
|
|
219
|
+
TRANSFER_REMAINDER_ERROR: 'TRANSFER_REMAINDER_ERROR',
|
|
220
|
+
TRANSFER_TO_SELF_ERROR: 'TRANSFER_TO_SELF_ERROR',
|
|
221
|
+
TRANSFER_UNBALANCED_ERROR: 'TRANSFER_UNBALANCED_ERROR',
|
|
222
|
+
UNAUTHENTICATED_ERROR: 'UNAUTHENTICATED_ERROR',
|
|
223
|
+
WALLET_CREDENTIAL_ERROR: 'WALLET_CREDENTIAL_ERROR',
|
|
224
|
+
WALLET_SHADOW_ERROR: 'WALLET_SHADOW_ERROR',
|
|
225
|
+
WRONG_TOKEN_TYPE_ERROR: 'WRONG_TOKEN_TYPE_ERROR'
|
|
226
|
+
} as const
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Exception code constants for common error scenarios
|
|
230
|
+
*/
|
|
231
|
+
export const EXCEPTION_CODES = {
|
|
232
|
+
// Generic codes
|
|
233
|
+
UNKNOWN_ERROR: 'UNKNOWN_ERROR',
|
|
234
|
+
VALIDATION_FAILED: 'VALIDATION_FAILED',
|
|
235
|
+
OPERATION_FAILED: 'OPERATION_FAILED',
|
|
236
|
+
|
|
237
|
+
// Atom-specific codes
|
|
238
|
+
INDEX_CONFLICT: 'INDEX_CONFLICT',
|
|
239
|
+
INDEX_OUT_OF_RANGE: 'INDEX_OUT_OF_RANGE',
|
|
240
|
+
INDEX_MISSING: 'INDEX_MISSING',
|
|
241
|
+
EMPTY_MOLECULE: 'EMPTY_MOLECULE',
|
|
242
|
+
MISSING_ISOTOPE: 'MISSING_ISOTOPE',
|
|
243
|
+
MISSING_REMAINDER: 'MISSING_REMAINDER',
|
|
244
|
+
MISSING_VALUE_ATOMS: 'MISSING_VALUE_ATOMS',
|
|
245
|
+
|
|
246
|
+
// Hash-specific codes
|
|
247
|
+
HASH_MISMATCH: 'HASH_MISMATCH',
|
|
248
|
+
INVALID_FORMAT: 'INVALID_FORMAT',
|
|
249
|
+
CROSS_PLATFORM_MISMATCH: 'CROSS_PLATFORM_MISMATCH',
|
|
250
|
+
ATOM_INTEGRITY_FAILURE: 'ATOM_INTEGRITY_FAILURE',
|
|
251
|
+
|
|
252
|
+
// Signature-specific codes
|
|
253
|
+
VERIFICATION_FAILED: 'VERIFICATION_FAILED',
|
|
254
|
+
OTS_VERIFICATION_FAILED: 'OTS_VERIFICATION_FAILED',
|
|
255
|
+
|
|
256
|
+
// Transfer-specific codes
|
|
257
|
+
INSUFFICIENT_BALANCE: 'INSUFFICIENT_BALANCE',
|
|
258
|
+
NEGATIVE_BALANCE: 'NEGATIVE_BALANCE',
|
|
259
|
+
CALCULATION_ERROR: 'CALCULATION_ERROR',
|
|
260
|
+
|
|
261
|
+
// Wallet-specific codes
|
|
262
|
+
INVALID_SECRET: 'INVALID_SECRET',
|
|
263
|
+
MISSING_CREDENTIALS: 'MISSING_CREDENTIALS',
|
|
264
|
+
CREDENTIALS_EXPIRED: 'CREDENTIALS_EXPIRED',
|
|
265
|
+
BUNDLE_MISMATCH: 'BUNDLE_MISMATCH',
|
|
266
|
+
|
|
267
|
+
// Response-specific codes
|
|
268
|
+
MALFORMED_JSON: 'MALFORMED_JSON',
|
|
269
|
+
GRAPHQL_ERROR: 'GRAPHQL_ERROR',
|
|
270
|
+
MISSING_DATA: 'MISSING_DATA',
|
|
271
|
+
NETWORK_ERROR: 'NETWORK_ERROR'
|
|
272
|
+
} as const
|