@spacesops/wdk-react-native-core 1.0.0-beta.69 → 1.0.0-beta.71

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 (142) hide show
  1. package/dist/hooks/useBalance.js +50 -7
  2. package/dist/hooks/useBalance.js.map +1 -1
  3. package/dist/hooks/useTransactions.d.ts +21 -0
  4. package/dist/hooks/useTransactions.js +64 -0
  5. package/dist/hooks/useTransactions.js.map +1 -0
  6. package/dist/index.d.ts +5 -2
  7. package/dist/index.js +3 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/provider/WdkAppProvider.d.ts +7 -2
  10. package/dist/provider/WdkAppProvider.js +6 -1
  11. package/dist/provider/WdkAppProvider.js.map +1 -1
  12. package/dist/services/transactionService.d.ts +27 -0
  13. package/dist/services/transactionService.js +173 -0
  14. package/dist/services/transactionService.js.map +1 -0
  15. package/dist/store/indexerConfigStore.d.ts +7 -0
  16. package/dist/store/indexerConfigStore.js +14 -0
  17. package/dist/store/indexerConfigStore.js.map +1 -0
  18. package/dist/types.d.ts +39 -0
  19. package/dist/utils/constants.d.ts +18 -0
  20. package/dist/utils/constants.js +18 -0
  21. package/dist/utils/constants.js.map +1 -1
  22. package/dist/utils/mmkvKeyManager.js +3 -3
  23. package/dist/utils/mmkvKeyManager.js.map +1 -1
  24. package/dist/utils/operationMutex.js.map +1 -1
  25. package/dist/utils/retryUtils.d.ts +19 -0
  26. package/dist/utils/retryUtils.js +55 -0
  27. package/dist/utils/retryUtils.js.map +1 -0
  28. package/dist/utils/schemas.d.ts +15 -3
  29. package/dist/utils/schemas.js +27 -2
  30. package/dist/utils/schemas.js.map +1 -1
  31. package/dist/utils/typeGuards.d.ts +1 -1
  32. package/dist/utils/typeGuards.js +3 -3
  33. package/dist/utils/typeGuards.js.map +1 -1
  34. package/package.json +2 -1
  35. package/src/__tests__/services/transactionService.test.ts +22 -0
  36. package/src/hooks/useBalance.ts +2 -3
  37. package/src/services/transactionService.ts +28 -5
  38. package/src/types.ts +6 -0
  39. package/src/utils/mmkvKeyManager.ts +3 -3
  40. package/src/utils/operationMutex.ts +1 -1
  41. package/dist/__mocks__/react.d.ts +0 -40
  42. package/dist/__mocks__/react.js +0 -33
  43. package/dist/__mocks__/react.js.map +0 -1
  44. package/dist/__mocks__/secureStorage.d.ts +0 -27
  45. package/dist/__mocks__/secureStorage.js +0 -81
  46. package/dist/__mocks__/secureStorage.js.map +0 -1
  47. package/dist/__tests__/hooks/useBalance.test.d.ts +0 -6
  48. package/dist/__tests__/hooks/useBalance.test.js +0 -217
  49. package/dist/__tests__/hooks/useBalance.test.js.map +0 -1
  50. package/dist/__tests__/hooks/useWallet.test.d.ts +0 -6
  51. package/dist/__tests__/hooks/useWallet.test.js +0 -105
  52. package/dist/__tests__/hooks/useWallet.test.js.map +0 -1
  53. package/dist/__tests__/hooks/useWalletManager.test.d.ts +0 -6
  54. package/dist/__tests__/hooks/useWalletManager.test.js +0 -193
  55. package/dist/__tests__/hooks/useWalletManager.test.js.map +0 -1
  56. package/dist/__tests__/hooks/useWdkApp.test.d.ts +0 -6
  57. package/dist/__tests__/hooks/useWdkApp.test.js +0 -55
  58. package/dist/__tests__/hooks/useWdkApp.test.js.map +0 -1
  59. package/dist/__tests__/hooks/useWorklet.test.d.ts +0 -6
  60. package/dist/__tests__/hooks/useWorklet.test.js +0 -168
  61. package/dist/__tests__/hooks/useWorklet.test.js.map +0 -1
  62. package/dist/__tests__/provider/WdkAppProvider.test.d.ts +0 -6
  63. package/dist/__tests__/provider/WdkAppProvider.test.js +0 -57
  64. package/dist/__tests__/provider/WdkAppProvider.test.js.map +0 -1
  65. package/dist/__tests__/services/accountService.test.d.ts +0 -6
  66. package/dist/__tests__/services/accountService.test.js +0 -263
  67. package/dist/__tests__/services/accountService.test.js.map +0 -1
  68. package/dist/__tests__/services/addressService.test.d.ts +0 -6
  69. package/dist/__tests__/services/addressService.test.js +0 -258
  70. package/dist/__tests__/services/addressService.test.js.map +0 -1
  71. package/dist/__tests__/services/balanceService.test.d.ts +0 -6
  72. package/dist/__tests__/services/balanceService.test.js +0 -333
  73. package/dist/__tests__/services/balanceService.test.js.map +0 -1
  74. package/dist/__tests__/services/walletSetupService.test.d.ts +0 -6
  75. package/dist/__tests__/services/walletSetupService.test.js +0 -304
  76. package/dist/__tests__/services/walletSetupService.test.js.map +0 -1
  77. package/dist/__tests__/services/walletSwitchingService.test.d.ts +0 -6
  78. package/dist/__tests__/services/walletSwitchingService.test.js +0 -209
  79. package/dist/__tests__/services/walletSwitchingService.test.js.map +0 -1
  80. package/dist/__tests__/services/workletLifecycleService.test.d.ts +0 -6
  81. package/dist/__tests__/services/workletLifecycleService.test.js +0 -451
  82. package/dist/__tests__/services/workletLifecycleService.test.js.map +0 -1
  83. package/dist/__tests__/setup.d.ts +0 -4
  84. package/dist/__tests__/setup.js +0 -49
  85. package/dist/__tests__/setup.js.map +0 -1
  86. package/dist/__tests__/storage/mmkvStorage.test.d.ts +0 -6
  87. package/dist/__tests__/storage/mmkvStorage.test.js +0 -213
  88. package/dist/__tests__/storage/mmkvStorage.test.js.map +0 -1
  89. package/dist/__tests__/store/walletStore.test.d.ts +0 -4
  90. package/dist/__tests__/store/walletStore.test.js +0 -86
  91. package/dist/__tests__/store/walletStore.test.js.map +0 -1
  92. package/dist/__tests__/store/workletStore.test.d.ts +0 -4
  93. package/dist/__tests__/store/workletStore.test.js +0 -255
  94. package/dist/__tests__/store/workletStore.test.js.map +0 -1
  95. package/dist/__tests__/types/hrpc.test.d.ts +0 -4
  96. package/dist/__tests__/types/hrpc.test.js +0 -99
  97. package/dist/__tests__/types/hrpc.test.js.map +0 -1
  98. package/dist/__tests__/utils/balanceUtils.test.d.ts +0 -4
  99. package/dist/__tests__/utils/balanceUtils.test.js +0 -133
  100. package/dist/__tests__/utils/balanceUtils.test.js.map +0 -1
  101. package/dist/__tests__/utils/errorHandling.test.d.ts +0 -6
  102. package/dist/__tests__/utils/errorHandling.test.js +0 -119
  103. package/dist/__tests__/utils/errorHandling.test.js.map +0 -1
  104. package/dist/__tests__/utils/errorUtils.test.d.ts +0 -4
  105. package/dist/__tests__/utils/errorUtils.test.js +0 -133
  106. package/dist/__tests__/utils/errorUtils.test.js.map +0 -1
  107. package/dist/__tests__/utils/initializationState.test.d.ts +0 -6
  108. package/dist/__tests__/utils/initializationState.test.js +0 -243
  109. package/dist/__tests__/utils/initializationState.test.js.map +0 -1
  110. package/dist/__tests__/utils/jsonUtils.test.d.ts +0 -4
  111. package/dist/__tests__/utils/jsonUtils.test.js +0 -118
  112. package/dist/__tests__/utils/jsonUtils.test.js.map +0 -1
  113. package/dist/__tests__/utils/mmkvKeyManager.test.d.ts +0 -6
  114. package/dist/__tests__/utils/mmkvKeyManager.test.js +0 -158
  115. package/dist/__tests__/utils/mmkvKeyManager.test.js.map +0 -1
  116. package/dist/__tests__/utils/mnemonicUtils.test.d.ts +0 -4
  117. package/dist/__tests__/utils/mnemonicUtils.test.js +0 -40
  118. package/dist/__tests__/utils/mnemonicUtils.test.js.map +0 -1
  119. package/dist/__tests__/utils/raceConditions.test.d.ts +0 -6
  120. package/dist/__tests__/utils/raceConditions.test.js +0 -239
  121. package/dist/__tests__/utils/raceConditions.test.js.map +0 -1
  122. package/dist/__tests__/utils/result.test.d.ts +0 -4
  123. package/dist/__tests__/utils/result.test.js +0 -66
  124. package/dist/__tests__/utils/result.test.js.map +0 -1
  125. package/dist/__tests__/utils/schemas.test.d.ts +0 -4
  126. package/dist/__tests__/utils/schemas.test.js +0 -66
  127. package/dist/__tests__/utils/schemas.test.js.map +0 -1
  128. package/dist/__tests__/utils/storeHelpers.test.d.ts +0 -4
  129. package/dist/__tests__/utils/storeHelpers.test.js +0 -227
  130. package/dist/__tests__/utils/storeHelpers.test.js.map +0 -1
  131. package/dist/__tests__/utils/typeGuards.test.d.ts +0 -4
  132. package/dist/__tests__/utils/typeGuards.test.js +0 -175
  133. package/dist/__tests__/utils/typeGuards.test.js.map +0 -1
  134. package/dist/__tests__/utils/validation.test.d.ts +0 -4
  135. package/dist/__tests__/utils/validation.test.js +0 -167
  136. package/dist/__tests__/utils/validation.test.js.map +0 -1
  137. package/dist/__tests__/utils/walletUtils.test.d.ts +0 -4
  138. package/dist/__tests__/utils/walletUtils.test.js +0 -156
  139. package/dist/__tests__/utils/walletUtils.test.js.map +0 -1
  140. package/dist/utils/types.js +0 -6
  141. package/dist/utils/utils/schemas.js +0 -173
  142. package/dist/utils/utils/validation.js +0 -151
@@ -1,173 +0,0 @@
1
- /**
2
- * Zod Schemas for Runtime Validation
3
- *
4
- * Provides Zod schemas for all WDK types to replace manual if/else type guards.
5
- * These schemas provide better error messages and are easier to maintain.
6
- */
7
- import { z } from 'zod';
8
- /**
9
- * Ethereum address schema (0x followed by 40 hex characters)
10
- */
11
- export const ethereumAddressSchema = z.string().regex(/^0x[a-fA-F0-9]{40}$/, {
12
- message: 'Must be a valid Ethereum address (0x followed by 40 hex characters)',
13
- });
14
- /**
15
- * Token contract address schema — EVM, TON, Tron, Solana, and other worklet-supported formats.
16
- * Wallet receive addresses use {@link addressSchema}; token mint/contract IDs are chain-specific.
17
- */
18
- export const tokenContractAddressSchema = z.union([
19
- ethereumAddressSchema,
20
- z.string().regex(/^T[1-9A-HJ-NP-Za-km-z]{33}$/, {
21
- message: 'Must be a valid Tron token contract address',
22
- }),
23
- z.string().regex(/^[1-9A-HJ-NP-Za-km-z]{32,44}$/, {
24
- message: 'Must be a valid Solana token mint address',
25
- }),
26
- z.string().regex(/^(EQ|UQ)[A-Za-z0-9_-]{46}$/, {
27
- message: 'Must be a valid TON jetton master address',
28
- }),
29
- ]);
30
- /**
31
- * Spark address schema (Bech32 format: spark1/sparkt1/sparkrt1 followed by base32 characters)
32
- */
33
- export const sparkAddressSchema = z.string().regex(/^spark(1|t1|rt1|test1)[a-z0-9]+$/, {
34
- message: 'Must be a valid Spark address (spark1/sparkt1/sparkrt1 followed by base32 characters)',
35
- }).min(14).max(90);
36
- /**
37
- * Bitcoin address schema — mainnet/testnet/regtest bech32 (bc1/tb1/bcrt1) and legacy Base58.
38
- */
39
- export const bitcoinAddressSchema = z.string().regex(/^(bc1[qp][a-z0-9]{11,71}|tb1[qp][a-z0-9]{11,71}|bcrt1[qp][a-z0-9]{11,71}|[13][a-km-zA-HJ-NP-Z1-9]{25,34}|[mn2][a-km-zA-HJ-NP-Z1-9]{25,34})$/, {
40
- message: 'Must be a valid Bitcoin address (bech32 bc1/tb1/bcrt1 or legacy Base58)',
41
- });
42
- /**
43
- * Address schema (Ethereum, Spark, or Bitcoin)
44
- */
45
- export const addressSchema = z.union([ethereumAddressSchema, sparkAddressSchema, bitcoinAddressSchema]);
46
- /**
47
- * Network configuration schema
48
- */
49
- export const networkConfigSchema = z.object({
50
- chainId: z.number().int().positive(),
51
- blockchain: z.string().min(1),
52
- provider: z.string().min(1).optional(),
53
- bundlerUrl: z.string().min(1).optional(),
54
- paymasterUrl: z.string().min(1).optional(),
55
- paymasterAddress: ethereumAddressSchema.optional(),
56
- entryPointAddress: ethereumAddressSchema.optional(),
57
- transferMaxFee: z.number().nonnegative().optional(),
58
- });
59
- /**
60
- * Network configurations schema
61
- */
62
- export const networkConfigsSchema = z.record(z.string().regex(/^[a-zA-Z0-9_-]+$/, {
63
- message: 'Network name must contain only alphanumeric characters, hyphens, and underscores',
64
- }), networkConfigSchema).refine((configs) => Object.keys(configs).length > 0, {
65
- message: 'NetworkConfigs must contain at least one network',
66
- });
67
- /**
68
- * Token configuration schema
69
- */
70
- export const tokenConfigSchema = z.object({
71
- symbol: z.string().min(1),
72
- name: z.string().min(1),
73
- decimals: z.number().int().min(0).max(18),
74
- address: z.union([tokenContractAddressSchema, z.null()]),
75
- });
76
- /**
77
- * Network tokens schema
78
- */
79
- export const networkTokensSchema = z.object({
80
- native: tokenConfigSchema,
81
- tokens: z.array(tokenConfigSchema),
82
- });
83
- /**
84
- * Token configurations schema
85
- */
86
- export const tokenConfigsSchema = z.record(z.string().min(1), networkTokensSchema).refine((configs) => Object.keys(configs).length > 0, {
87
- message: 'TokenConfigs must contain at least one network',
88
- });
89
- /**
90
- * Account index schema
91
- */
92
- export const accountIndexSchema = z.number().int().nonnegative();
93
- /**
94
- * Network name schema
95
- */
96
- export const networkNameSchema = z.string().regex(/^[a-zA-Z0-9_-]+$/, {
97
- message: 'Network name must contain only alphanumeric characters, hyphens, and underscores',
98
- }).min(1);
99
- /**
100
- * Balance string schema (valid number string)
101
- */
102
- export const balanceStringSchema = z.string().regex(/^-?\d+(\.\d+)?$/, {
103
- message: 'Balance must be a valid number string',
104
- });
105
- /**
106
- * Wallet addresses schema
107
- * Maps network -> accountIndex -> address
108
- */
109
- export const walletAddressesSchema = z.record(networkNameSchema, z.record(z.string().transform((val) => {
110
- const num = parseInt(val, 10);
111
- if (isNaN(num) || num < 0) {
112
- throw new Error('Account index must be a non-negative integer');
113
- }
114
- return num;
115
- }), addressSchema));
116
- /**
117
- * Wallet balances schema
118
- * Maps network -> accountIndex -> tokenAddress -> balance
119
- */
120
- export const walletBalancesSchema = z.record(networkNameSchema, z.record(z.string().transform((val) => {
121
- const num = parseInt(val, 10);
122
- if (isNaN(num) || num < 0) {
123
- throw new Error('Account index must be a non-negative integer');
124
- }
125
- return num;
126
- }), z.record(z.string(), balanceStringSchema)));
127
- /**
128
- * Balance loading states schema
129
- * Maps "network-accountIndex-tokenAddress" -> boolean
130
- */
131
- export const balanceLoadingStatesSchema = z.record(z.string(), z.boolean());
132
- /**
133
- * Balance fetch result schema
134
- */
135
- export const balanceFetchResultSchema = z.object({
136
- success: z.boolean(),
137
- network: networkNameSchema,
138
- accountIndex: accountIndexSchema,
139
- tokenAddress: z.union([tokenContractAddressSchema, z.null()]),
140
- balance: z.union([balanceStringSchema, z.null()]),
141
- error: z.string().optional(),
142
- });
143
- /**
144
- * Wallet schema
145
- */
146
- export const walletSchema = z.object({
147
- accountIndex: accountIndexSchema,
148
- identifier: z.string().min(1),
149
- name: z.string().min(1),
150
- createdAt: z.number().int().nonnegative(),
151
- updatedAt: z.number().int().nonnegative(),
152
- });
153
- /**
154
- * Worklet response schemas for runtime validation
155
- */
156
- export const workletResponseSchema = z.object({
157
- result: z.string(),
158
- error: z.string().optional(),
159
- });
160
- /**
161
- * Balance response schema (numeric string)
162
- */
163
- export const balanceResponseSchema = z.string().regex(/^\d+$/, {
164
- message: 'Balance must be a numeric string',
165
- });
166
- /**
167
- * Account method response schema (union of possible return types)
168
- */
169
- export const accountMethodResponseSchema = z.union([
170
- balanceResponseSchema,
171
- z.string(), // For addresses
172
- z.object({}).passthrough(), // For other responses (objects)
173
- ]);
@@ -1,151 +0,0 @@
1
- /**
2
- * Validation utilities for WDK provider props and inputs
3
- *
4
- * These functions throw errors for invalid inputs.
5
- * Uses Zod schemas for validation with better error messages.
6
- * For type guards (boolean returns), see typeGuards.ts
7
- */
8
- import { z } from 'zod';
9
- import { networkConfigsSchema, tokenConfigsSchema, accountIndexSchema, networkNameSchema, balanceStringSchema, tokenContractAddressSchema, } from './schemas';
10
- /**
11
- * Extract error message from Zod error
12
- */
13
- function getZodErrorMessage(error) {
14
- if (error instanceof z.ZodError) {
15
- // Get the first error message for simplicity
16
- const firstIssue = error.issues[0];
17
- if (firstIssue) {
18
- return firstIssue.message;
19
- }
20
- return 'Validation failed';
21
- }
22
- if (error instanceof Error) {
23
- return error.message;
24
- }
25
- return String(error);
26
- }
27
- /**
28
- * Validate network configuration
29
- */
30
- export function validateNetworkConfigs(networkConfigs) {
31
- try {
32
- networkConfigsSchema.parse(networkConfigs);
33
- }
34
- catch (error) {
35
- throw new Error(`Invalid networkConfigs: ${getZodErrorMessage(error)}`);
36
- }
37
- }
38
- /**
39
- * Validate token configuration
40
- */
41
- export function validateTokenConfigs(tokenConfigs) {
42
- try {
43
- tokenConfigsSchema.parse(tokenConfigs);
44
- }
45
- catch (error) {
46
- throw new Error(`Invalid tokenConfigs: ${getZodErrorMessage(error)}`);
47
- }
48
- }
49
- /**
50
- * Validate balance refresh interval
51
- */
52
- export function validateBalanceRefreshInterval(interval) {
53
- if (interval !== undefined) {
54
- if (typeof interval !== 'number') {
55
- throw new Error('balanceRefreshInterval must be a number');
56
- }
57
- if (interval < 0) {
58
- throw new Error('balanceRefreshInterval must be a non-negative number');
59
- }
60
- if (!Number.isFinite(interval)) {
61
- throw new Error('balanceRefreshInterval must be a finite number');
62
- }
63
- }
64
- }
65
- /**
66
- * Validate that an object has required methods
67
- *
68
- * @param obj - Object to validate
69
- * @param requiredMethods - Array of required method names
70
- * @param objectName - Name of the object for error messages
71
- */
72
- export function validateRequiredMethods(obj, requiredMethods, objectName) {
73
- if (!obj || typeof obj !== 'object') {
74
- throw new Error(`${objectName} must be an object`);
75
- }
76
- for (const methodName of requiredMethods) {
77
- if (typeof obj[methodName] !== 'function') {
78
- throw new Error(`${objectName} must have a ${methodName} method`);
79
- }
80
- }
81
- }
82
- /**
83
- * Validate account index
84
- */
85
- export function validateAccountIndex(accountIndex) {
86
- try {
87
- accountIndexSchema.parse(accountIndex);
88
- }
89
- catch (error) {
90
- const message = getZodErrorMessage(error);
91
- throw new Error(`Invalid accountIndex: ${message}`);
92
- }
93
- }
94
- /**
95
- * Validate network name
96
- */
97
- export function validateNetworkName(network) {
98
- try {
99
- networkNameSchema.parse(network);
100
- }
101
- catch (error) {
102
- const message = getZodErrorMessage(error);
103
- // Provide a fallback message if Zod error doesn't have a clear message
104
- if (message === 'Validation failed' || !message) {
105
- throw new Error('network must be a non-empty string containing only alphanumeric characters, hyphens, and underscores');
106
- }
107
- throw new Error(`Invalid network name: ${message}`);
108
- }
109
- }
110
- /**
111
- * Validate token address (can be null for native tokens)
112
- */
113
- export function validateTokenAddress(tokenAddress) {
114
- if (tokenAddress === null) {
115
- return;
116
- }
117
- try {
118
- tokenContractAddressSchema.parse(tokenAddress);
119
- }
120
- catch (error) {
121
- const message = getZodErrorMessage(error);
122
- throw new Error(`Invalid tokenAddress: ${message}`);
123
- }
124
- }
125
- /**
126
- * Validate balance string
127
- */
128
- export function validateBalance(balance) {
129
- try {
130
- balanceStringSchema.parse(balance);
131
- }
132
- catch (error) {
133
- const message = getZodErrorMessage(error);
134
- throw new Error(`Invalid balance: ${message}`);
135
- }
136
- }
137
- /**
138
- * Validate wallet parameters (network, accountIndex, optional tokenAddress)
139
- * Convenience function to validate common wallet operation parameters
140
- *
141
- * @param network - Network name
142
- * @param accountIndex - Account index
143
- * @param tokenAddress - Optional token address (null for native tokens)
144
- */
145
- export function validateWalletParams(network, accountIndex, tokenAddress) {
146
- validateNetworkName(network);
147
- validateAccountIndex(accountIndex);
148
- if (tokenAddress !== undefined) {
149
- validateTokenAddress(tokenAddress);
150
- }
151
- }