@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.
Files changed (141) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +425 -0
  3. package/dist/index.cjs +9961 -0
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.iife.js +32241 -0
  6. package/dist/index.iife.js.map +1 -0
  7. package/dist/index.js +9853 -0
  8. package/dist/index.js.map +1 -0
  9. package/package.json +113 -0
  10. package/src/AuthToken.ts +214 -0
  11. package/src/KnishIOClient.ts +2020 -0
  12. package/src/constants.ts +398 -0
  13. package/src/core/Atom.ts +646 -0
  14. package/src/core/AtomMeta.ts +278 -0
  15. package/src/core/Meta.ts +428 -0
  16. package/src/core/Molecule.ts +825 -0
  17. package/src/core/PolicyMeta.ts +130 -0
  18. package/src/core/TokenUnit.ts +148 -0
  19. package/src/core/Wallet.ts +467 -0
  20. package/src/exception/AtomIndexException.ts +97 -0
  21. package/src/exception/AtomsMissingException.ts +109 -0
  22. package/src/exception/AuthorizationRejectedException.ts +63 -0
  23. package/src/exception/BalanceInsufficientException.ts +58 -0
  24. package/src/exception/BaseException.ts +275 -0
  25. package/src/exception/BatchIdException.ts +58 -0
  26. package/src/exception/CodeException.ts +119 -0
  27. package/src/exception/DecryptionKeyException.ts +65 -0
  28. package/src/exception/InvalidResponseException.ts +112 -0
  29. package/src/exception/MetaMissingException.ts +58 -0
  30. package/src/exception/MolecularHashMismatchException.ts +115 -0
  31. package/src/exception/MolecularHashMissingException.ts +58 -0
  32. package/src/exception/NegativeAmountException.ts +58 -0
  33. package/src/exception/PolicyInvalidException.ts +58 -0
  34. package/src/exception/SignatureMalformedException.ts +58 -0
  35. package/src/exception/SignatureMismatchException.ts +98 -0
  36. package/src/exception/StackableUnitAmountException.ts +65 -0
  37. package/src/exception/StackableUnitDecimalsException.ts +65 -0
  38. package/src/exception/TransferBalanceException.ts +98 -0
  39. package/src/exception/TransferMalformedException.ts +58 -0
  40. package/src/exception/TransferMismatchedException.ts +58 -0
  41. package/src/exception/TransferRemainderException.ts +58 -0
  42. package/src/exception/TransferToSelfException.ts +58 -0
  43. package/src/exception/TransferUnbalancedException.ts +58 -0
  44. package/src/exception/UnauthenticatedException.ts +147 -0
  45. package/src/exception/WalletCredentialException.ts +108 -0
  46. package/src/exception/WalletShadowException.ts +65 -0
  47. package/src/exception/WrongTokenTypeException.ts +58 -0
  48. package/src/exception/index.ts +272 -0
  49. package/src/index.ts +512 -0
  50. package/src/instance/rules/Callback.ts +257 -0
  51. package/src/instance/rules/Condition.ts +96 -0
  52. package/src/instance/rules/Meta.ts +163 -0
  53. package/src/instance/rules/Rule.ts +29 -0
  54. package/src/instance/rules/exception/RuleArgumentException.ts +65 -0
  55. package/src/libraries/CheckMolecule.ts +581 -0
  56. package/src/libraries/Decimal.ts +94 -0
  57. package/src/libraries/Dot.ts +202 -0
  58. package/src/libraries/GraphQLClient.ts +276 -0
  59. package/src/libraries/Hex.ts +155 -0
  60. package/src/libraries/UrqlClientWrapper.ts +336 -0
  61. package/src/libraries/array.ts +91 -0
  62. package/src/libraries/crypto.ts +816 -0
  63. package/src/libraries/strings.ts +458 -0
  64. package/src/mutation/Mutation.ts +103 -0
  65. package/src/mutation/MutationActiveSession.ts +108 -0
  66. package/src/mutation/MutationClaimShadowWallet.ts +91 -0
  67. package/src/mutation/MutationCreateIdentifier.ts +86 -0
  68. package/src/mutation/MutationCreateMeta.ts +92 -0
  69. package/src/mutation/MutationCreateRule.ts +90 -0
  70. package/src/mutation/MutationCreateToken.ts +92 -0
  71. package/src/mutation/MutationCreateWallet.ts +78 -0
  72. package/src/mutation/MutationDepositBufferToken.ts +72 -0
  73. package/src/mutation/MutationLinkIdentifier.ts +87 -0
  74. package/src/mutation/MutationProposeMolecule.ts +147 -0
  75. package/src/mutation/MutationRequestAuthorization.ts +77 -0
  76. package/src/mutation/MutationRequestAuthorizationGuest.ts +85 -0
  77. package/src/mutation/MutationRequestTokens.ts +98 -0
  78. package/src/mutation/MutationTransferTokens.ts +87 -0
  79. package/src/mutation/MutationWithdrawBufferToken.ts +73 -0
  80. package/src/query/Query.ts +187 -0
  81. package/src/query/QueryActiveSession.ts +89 -0
  82. package/src/query/QueryAtom.ts +275 -0
  83. package/src/query/QueryBalance.ts +102 -0
  84. package/src/query/QueryBatch.ts +145 -0
  85. package/src/query/QueryBatchHistory.ts +86 -0
  86. package/src/query/QueryContinuId.ts +91 -0
  87. package/src/query/QueryMetaType.ts +177 -0
  88. package/src/query/QueryMetaTypeViaAtom.ts +199 -0
  89. package/src/query/QueryPolicy.ts +91 -0
  90. package/src/query/QueryToken.ts +90 -0
  91. package/src/query/QueryUserActivity.ts +153 -0
  92. package/src/query/QueryWalletBundle.ts +92 -0
  93. package/src/query/QueryWalletList.ts +106 -0
  94. package/src/response/EnhancedResponse.ts +345 -0
  95. package/src/response/Response.ts +254 -0
  96. package/src/response/ResponseActiveSession.ts +72 -0
  97. package/src/response/ResponseAtom.ts +132 -0
  98. package/src/response/ResponseAuthorizationGuest.ts +119 -0
  99. package/src/response/ResponseBalance.ts +153 -0
  100. package/src/response/ResponseClaimShadowWallet.ts +56 -0
  101. package/src/response/ResponseContinuId.ts +101 -0
  102. package/src/response/ResponseCreateIdentifier.ts +56 -0
  103. package/src/response/ResponseCreateMeta.ts +58 -0
  104. package/src/response/ResponseCreateRule.ts +56 -0
  105. package/src/response/ResponseCreateToken.ts +58 -0
  106. package/src/response/ResponseCreateWallet.ts +58 -0
  107. package/src/response/ResponseLinkIdentifier.ts +87 -0
  108. package/src/response/ResponseMetaBatch.ts +72 -0
  109. package/src/response/ResponseMetaType.ts +108 -0
  110. package/src/response/ResponseMetaTypeViaAtom.ts +108 -0
  111. package/src/response/ResponsePolicy.ts +90 -0
  112. package/src/response/ResponseProposeMolecule.ts +155 -0
  113. package/src/response/ResponseQueryActiveSession.ts +105 -0
  114. package/src/response/ResponseQueryUserActivity.ts +89 -0
  115. package/src/response/ResponseRequestAuthorization.ts +100 -0
  116. package/src/response/ResponseRequestAuthorizationGuest.ts +133 -0
  117. package/src/response/ResponseRequestTokens.ts +58 -0
  118. package/src/response/ResponseTransferTokens.ts +72 -0
  119. package/src/response/ResponseWalletBundle.ts +95 -0
  120. package/src/response/ResponseWalletList.ts +165 -0
  121. package/src/schemas/index.ts +457 -0
  122. package/src/subscribe/ActiveSessionSubscribe.ts +72 -0
  123. package/src/subscribe/ActiveWalletSubscribe.ts +99 -0
  124. package/src/subscribe/CreateMoleculeSubscribe.ts +106 -0
  125. package/src/subscribe/Subscribe.ts +182 -0
  126. package/src/subscribe/WalletStatusSubscribe.ts +70 -0
  127. package/src/subscribe/index.ts +59 -0
  128. package/src/types/assertions.ts +722 -0
  129. package/src/types/client.ts +567 -0
  130. package/src/types/crypto.ts +541 -0
  131. package/src/types/graphql.ts +630 -0
  132. package/src/types/guards.ts +659 -0
  133. package/src/types/index.ts +614 -0
  134. package/src/types/response.ts +133 -0
  135. package/src/types/template-literals.ts +382 -0
  136. package/src/validation/UNIVERSAL_CONFIGURATION_INTERFACES.ts +580 -0
  137. package/src/validation/ValidationService.ts +607 -0
  138. package/src/validation/schemas.ts +447 -0
  139. package/src/versions/HashAtom.ts +170 -0
  140. package/src/versions/Version4.ts +120 -0
  141. package/src/versions/index.ts +80 -0
package/package.json ADDED
@@ -0,0 +1,113 @@
1
+ {
2
+ "name": "@wishknish/knishio-client-ts",
3
+ "version": "0.7.0",
4
+ "productName": "Knish.IO TypeScript SDK Client",
5
+ "description": "TypeScript implementation of the Knish.IO SDK to consume Knish.IO GraphQL APIs with enhanced type safety.",
6
+ "license": "GPL-3.0-or-later",
7
+ "type": "module",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/WishKnish/KnishIO-Client-TS.git"
11
+ },
12
+ "contributors": [
13
+ {
14
+ "name": "Eugene Teplitsky",
15
+ "email": "eugene@wishknish.com",
16
+ "homepage": "https://wishknish.com",
17
+ "role": "developer"
18
+ }
19
+ ],
20
+ "main": "./dist/index.cjs",
21
+ "module": "./dist/index.js",
22
+ "types": "./dist/index.d.ts",
23
+ "browser": "./dist/client.iife.js",
24
+ "exports": {
25
+ ".": {
26
+ "browser": "./dist/client.iife.js",
27
+ "import": "./dist/index.js",
28
+ "require": "./dist/index.cjs",
29
+ "types": "./dist/index.d.ts"
30
+ },
31
+ "./types": {
32
+ "import": "./dist/types/index.d.ts",
33
+ "require": "./dist/types/index.d.ts"
34
+ },
35
+ "./package.json": "./package.json"
36
+ },
37
+ "keywords": [
38
+ "wishknish",
39
+ "knishio",
40
+ "blockchain",
41
+ "dag",
42
+ "post-blockchain",
43
+ "dlt",
44
+ "client",
45
+ "graphql",
46
+ "xmss",
47
+ "post-quantum",
48
+ "quantum-safe",
49
+ "sdk",
50
+ "typescript",
51
+ "ml-kem768",
52
+ "cryptography",
53
+ "crystals-kyber",
54
+ "fips-202",
55
+ "fips-203"
56
+ ],
57
+ "dependencies": {
58
+ "@noble/post-quantum": "^0.5.2",
59
+ "@thumbmarkjs/thumbmarkjs": "^0.19.1",
60
+ "@urql/core": "^5.2.0",
61
+ "graphql": "^16.11.0",
62
+ "graphql-ws": "^6.0.6",
63
+ "isomorphic-fetch": "^3.0.0",
64
+ "jssha": "^3.3.1",
65
+ "wonka": "^6.3.5",
66
+ "zod": "^3.23.8"
67
+ },
68
+ "devDependencies": {
69
+ "@types/isomorphic-fetch": "^0.0.39",
70
+ "@types/jssha": "^3.0.0",
71
+ "@types/node": "^22.8.1",
72
+ "@typescript-eslint/eslint-plugin": "^8.15.0",
73
+ "@typescript-eslint/parser": "^8.15.0",
74
+ "eslint": "^9.16.0",
75
+ "prettier": "^3.4.2",
76
+ "tsup": "^8.3.5",
77
+ "tsx": "^4.20.5",
78
+ "typescript": "^5.6.3",
79
+ "vite": "^6.3.5",
80
+ "vite-plugin-dts": "^4.2.3",
81
+ "vitest": "^2.1.8"
82
+ },
83
+ "browserslist": [
84
+ "> 1%",
85
+ "last 2 versions",
86
+ "not ie <= 8",
87
+ "supports es6-module"
88
+ ],
89
+ "scripts": {
90
+ "build": "tsup src/index.ts --format esm,cjs,iife --clean",
91
+ "build:test": "tsup src/index.ts --format esm,cjs,iife --tsconfig tsconfig.build.json --clean",
92
+ "build:dev": "tsup src/index.ts --format esm,cjs --dts --sourcemap --watch",
93
+ "typecheck": "tsc --noEmit",
94
+ "lint": "eslint src --ext .ts,.tsx --fix",
95
+ "format": "prettier --write \"src/**/*.{ts,tsx}\"",
96
+ "test": "vitest",
97
+ "test:coverage": "vitest --coverage",
98
+ "test:ui": "vitest --ui",
99
+ "dev": "vite",
100
+ "prepublishOnly": "npm run build",
101
+ "selftest": "npm run build && node self-test.cjs"
102
+ },
103
+ "files": [
104
+ "/src",
105
+ "/dist",
106
+ "README.md",
107
+ "LICENSE"
108
+ ],
109
+ "packageManager": "yarn@4.10.3",
110
+ "engines": {
111
+ "node": ">=18.0.0"
112
+ }
113
+ }
@@ -0,0 +1,214 @@
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 Wallet from '@/core/Wallet'
50
+
51
+ /**
52
+ * AuthToken class for managing authentication tokens
53
+ */
54
+ export default class AuthToken {
55
+ private $__token: string
56
+ private $__expiresAt: number
57
+ private $__pubkey: string
58
+ private $__encrypt: boolean
59
+ private $__wallet?: Wallet
60
+
61
+ /**
62
+ * Create new AuthToken instance
63
+ */
64
+ constructor({
65
+ token,
66
+ expiresAt,
67
+ encrypt,
68
+ pubkey
69
+ }: {
70
+ token: string
71
+ expiresAt: number
72
+ encrypt: boolean
73
+ pubkey: string
74
+ }) {
75
+ this.$__token = token
76
+ this.$__expiresAt = expiresAt
77
+ this.$__pubkey = pubkey
78
+ this.$__encrypt = encrypt
79
+ }
80
+
81
+ /**
82
+ * Static factory method to create AuthToken with wallet
83
+ */
84
+ static create(data: {
85
+ token: string
86
+ expiresAt: number
87
+ encrypt: boolean
88
+ pubkey: string
89
+ }, wallet: Wallet): AuthToken {
90
+ const authToken = new AuthToken(data)
91
+ authToken.setWallet(wallet)
92
+ return authToken
93
+ }
94
+
95
+ /**
96
+ * Restore AuthToken from snapshot
97
+ */
98
+ static restore(snapshot: {
99
+ token: string
100
+ expiresAt: number
101
+ pubkey: string
102
+ encrypt: boolean
103
+ wallet: {
104
+ position: string
105
+ characters: string | null
106
+ }
107
+ }, secret: string): AuthToken {
108
+ const wallet = new Wallet({
109
+ secret,
110
+ token: 'AUTH',
111
+ position: snapshot.wallet.position,
112
+ characters: snapshot.wallet.characters
113
+ })
114
+
115
+ return AuthToken.create({
116
+ token: snapshot.token,
117
+ expiresAt: snapshot.expiresAt,
118
+ pubkey: snapshot.pubkey,
119
+ encrypt: snapshot.encrypt
120
+ }, wallet)
121
+ }
122
+
123
+ /**
124
+ * Set wallet for this auth token
125
+ */
126
+ setWallet(wallet: Wallet): void {
127
+ this.$__wallet = wallet
128
+ }
129
+
130
+ /**
131
+ * Get wallet
132
+ */
133
+ getWallet(): Wallet | undefined {
134
+ return this.$__wallet
135
+ }
136
+
137
+ /**
138
+ * Get auth token
139
+ */
140
+ getToken(): string {
141
+ return this.$__token
142
+ }
143
+
144
+ /**
145
+ * Get expiration timestamp
146
+ */
147
+ getExpiresAt(): number {
148
+ return this.$__expiresAt
149
+ }
150
+
151
+ /**
152
+ * Get public key
153
+ */
154
+ getPubkey(): string {
155
+ return this.$__pubkey
156
+ }
157
+
158
+ /**
159
+ * Check if encryption is enabled
160
+ */
161
+ isEncrypted(): boolean {
162
+ return this.$__encrypt
163
+ }
164
+
165
+ /**
166
+ * Check if token is expired
167
+ */
168
+ isExpired(): boolean {
169
+ const now = Math.floor(Date.now() / 1000)
170
+ return now >= this.$__expiresAt
171
+ }
172
+
173
+ /**
174
+ * Get auth data for GraphQL client
175
+ */
176
+ getAuthData(): {
177
+ token: string
178
+ pubkey: string
179
+ wallet: Wallet | undefined
180
+ } {
181
+ return {
182
+ token: this.$__token,
183
+ pubkey: this.$__pubkey,
184
+ wallet: this.$__wallet
185
+ }
186
+ }
187
+
188
+ /**
189
+ * Create snapshot for persistence
190
+ */
191
+ toSnapshot(): {
192
+ token: string
193
+ expiresAt: number
194
+ pubkey: string
195
+ encrypt: boolean
196
+ wallet?: {
197
+ position: string | null
198
+ characters: string | null
199
+ }
200
+ } {
201
+ return {
202
+ token: this.$__token,
203
+ expiresAt: this.$__expiresAt,
204
+ pubkey: this.$__pubkey,
205
+ encrypt: this.$__encrypt,
206
+ ...(this.$__wallet ? {
207
+ wallet: {
208
+ position: this.$__wallet.position,
209
+ characters: this.$__wallet.characters
210
+ }
211
+ } : {})
212
+ }
213
+ }
214
+ }