@5ive-tech/sdk 1.1.2

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 (119) hide show
  1. package/README.md +279 -0
  2. package/dist/FiveSDK.d.ts +336 -0
  3. package/dist/FiveSDK.js +395 -0
  4. package/dist/accounts/index.d.ts +254 -0
  5. package/dist/accounts/index.js +543 -0
  6. package/dist/assets/vm/dummy.file +0 -0
  7. package/dist/assets/vm/five_vm_wasm.d.ts +762 -0
  8. package/dist/assets/vm/five_vm_wasm.js +3754 -0
  9. package/dist/assets/vm/five_vm_wasm_bg.js +3307 -0
  10. package/dist/assets/vm/five_vm_wasm_bg.wasm +0 -0
  11. package/dist/assets/vm/five_vm_wasm_bg.wasm.d.ts +247 -0
  12. package/dist/assets/vm/package.json +11 -0
  13. package/dist/bin/gen-types.d.ts +2 -0
  14. package/dist/bin/gen-types.js +35 -0
  15. package/dist/compiler/BytecodeCompiler.d.ts +83 -0
  16. package/dist/compiler/BytecodeCompiler.js +379 -0
  17. package/dist/config/ConfigManager.d.ts +13 -0
  18. package/dist/config/ConfigManager.js +27 -0
  19. package/dist/config/ProgramIdResolver.d.ts +62 -0
  20. package/dist/config/ProgramIdResolver.js +104 -0
  21. package/dist/crypto/index.d.ts +211 -0
  22. package/dist/crypto/index.js +451 -0
  23. package/dist/encoding/ParameterEncoder.d.ts +31 -0
  24. package/dist/encoding/ParameterEncoder.js +278 -0
  25. package/dist/index.d.ts +21 -0
  26. package/dist/index.js +28 -0
  27. package/dist/lib/bytecode-encoder.d.ts +62 -0
  28. package/dist/lib/bytecode-encoder.js +281 -0
  29. package/dist/logging/index.d.ts +9 -0
  30. package/dist/logging/index.js +10 -0
  31. package/dist/metadata/index.d.ts +213 -0
  32. package/dist/metadata/index.js +296 -0
  33. package/dist/modules/accounts.d.ts +60 -0
  34. package/dist/modules/accounts.js +275 -0
  35. package/dist/modules/deploy.d.ts +90 -0
  36. package/dist/modules/deploy.js +1118 -0
  37. package/dist/modules/execute.d.ts +90 -0
  38. package/dist/modules/execute.js +649 -0
  39. package/dist/modules/fees.d.ts +14 -0
  40. package/dist/modules/fees.js +112 -0
  41. package/dist/modules/namespaces.d.ts +39 -0
  42. package/dist/modules/namespaces.js +190 -0
  43. package/dist/modules/state-diff.d.ts +35 -0
  44. package/dist/modules/state-diff.js +342 -0
  45. package/dist/modules/vm-state.d.ts +7 -0
  46. package/dist/modules/vm-state.js +44 -0
  47. package/dist/program/AccountResolver.d.ts +67 -0
  48. package/dist/program/AccountResolver.js +134 -0
  49. package/dist/program/BorshSchemaGenerator.d.ts +8 -0
  50. package/dist/program/BorshSchemaGenerator.js +57 -0
  51. package/dist/program/FiveProgram.d.ts +144 -0
  52. package/dist/program/FiveProgram.js +282 -0
  53. package/dist/program/FunctionBuilder.d.ts +114 -0
  54. package/dist/program/FunctionBuilder.js +347 -0
  55. package/dist/program/ProgramAccount.d.ts +38 -0
  56. package/dist/program/ProgramAccount.js +170 -0
  57. package/dist/program/TypeGenerator.d.ts +90 -0
  58. package/dist/program/TypeGenerator.js +195 -0
  59. package/dist/program/index.d.ts +24 -0
  60. package/dist/program/index.js +21 -0
  61. package/dist/project/config.d.ts +5 -0
  62. package/dist/project/config.js +33 -0
  63. package/dist/project/toml.d.ts +6 -0
  64. package/dist/project/toml.js +43 -0
  65. package/dist/project/workspace.d.ts +160 -0
  66. package/dist/project/workspace.js +73 -0
  67. package/dist/testing/AccountMetaGenerator.d.ts +121 -0
  68. package/dist/testing/AccountMetaGenerator.js +261 -0
  69. package/dist/testing/AccountTestFixture.d.ts +211 -0
  70. package/dist/testing/AccountTestFixture.js +530 -0
  71. package/dist/testing/OnChainAccountManager.d.ts +81 -0
  72. package/dist/testing/OnChainAccountManager.js +260 -0
  73. package/dist/testing/StateSerializer.d.ts +65 -0
  74. package/dist/testing/StateSerializer.js +330 -0
  75. package/dist/testing/TestDiscovery.d.ts +79 -0
  76. package/dist/testing/TestDiscovery.js +274 -0
  77. package/dist/testing/TestRunner.d.ts +117 -0
  78. package/dist/testing/TestRunner.js +346 -0
  79. package/dist/testing/index.d.ts +14 -0
  80. package/dist/testing/index.js +13 -0
  81. package/dist/types.d.ts +356 -0
  82. package/dist/types.js +32 -0
  83. package/dist/utils/abi.d.ts +31 -0
  84. package/dist/utils/abi.js +92 -0
  85. package/dist/utils/transaction.d.ts +5 -0
  86. package/dist/utils/transaction.js +48 -0
  87. package/dist/validation/InputValidator.d.ts +142 -0
  88. package/dist/validation/InputValidator.js +332 -0
  89. package/dist/validation/index.d.ts +4 -0
  90. package/dist/validation/index.js +4 -0
  91. package/dist/wasm/compiler/AbiLogic.d.ts +4 -0
  92. package/dist/wasm/compiler/AbiLogic.js +37 -0
  93. package/dist/wasm/compiler/AnalysisLogic.d.ts +6 -0
  94. package/dist/wasm/compiler/AnalysisLogic.js +61 -0
  95. package/dist/wasm/compiler/CompilationLogic.d.ts +10 -0
  96. package/dist/wasm/compiler/CompilationLogic.js +431 -0
  97. package/dist/wasm/compiler/FiveCompiler.d.ts +48 -0
  98. package/dist/wasm/compiler/FiveCompiler.js +183 -0
  99. package/dist/wasm/compiler/InfoLogic.d.ts +6 -0
  100. package/dist/wasm/compiler/InfoLogic.js +24 -0
  101. package/dist/wasm/compiler/OptimizationLogic.d.ts +2 -0
  102. package/dist/wasm/compiler/OptimizationLogic.js +13 -0
  103. package/dist/wasm/compiler/ValidationLogic.d.ts +7 -0
  104. package/dist/wasm/compiler/ValidationLogic.js +26 -0
  105. package/dist/wasm/compiler/index.d.ts +2 -0
  106. package/dist/wasm/compiler/index.js +2 -0
  107. package/dist/wasm/compiler/types.d.ts +8 -0
  108. package/dist/wasm/compiler/types.js +1 -0
  109. package/dist/wasm/compiler/utils.d.ts +8 -0
  110. package/dist/wasm/compiler/utils.js +75 -0
  111. package/dist/wasm/index.d.ts +9 -0
  112. package/dist/wasm/index.js +12 -0
  113. package/dist/wasm/instance.d.ts +1 -0
  114. package/dist/wasm/instance.js +26 -0
  115. package/dist/wasm/loader.d.ts +7 -0
  116. package/dist/wasm/loader.js +112 -0
  117. package/dist/wasm/vm.d.ts +33 -0
  118. package/dist/wasm/vm.js +250 -0
  119. package/package.json +59 -0
@@ -0,0 +1,356 @@
1
+ /**
2
+ * Type definitions for Five SDK.
3
+ */
4
+ export interface ProjectConfig {
5
+ name: string;
6
+ version: string;
7
+ description?: string;
8
+ sourceDir: string;
9
+ buildDir: string;
10
+ target?: CompilationTarget;
11
+ entryPoint?: string;
12
+ outputArtifactName?: string;
13
+ cluster?: string;
14
+ commitment?: string;
15
+ rpcUrl?: string;
16
+ programId?: string;
17
+ namespaceManager?: string;
18
+ keypairPath?: string;
19
+ optimizations?: ProjectOptimizations;
20
+ dependencies?: ProjectDependency[];
21
+ multiFileMode?: boolean;
22
+ wasm?: {
23
+ loader?: 'auto' | 'node' | 'bundler';
24
+ modulePaths?: string[];
25
+ };
26
+ }
27
+ export interface ProjectOptimizations {
28
+ enableCompression?: boolean;
29
+ enableConstraintOptimization?: boolean;
30
+ optimizationLevel?: 'production' | 'development';
31
+ }
32
+ export interface ProjectDependency {
33
+ name: string;
34
+ version: string;
35
+ type: 'five' | 'wasm' | 'solana';
36
+ path?: string;
37
+ }
38
+ export type CompilationTarget = 'vm' | 'solana' | 'debug' | 'test' | 'deployment';
39
+ export interface CompilationOptions {
40
+ /** Source file path (if applicable) */
41
+ sourceFile?: string;
42
+ /** Output file path (if applicable) */
43
+ outputFile?: string;
44
+ /** ABI output file path (if applicable) */
45
+ abiOutputFile?: string;
46
+ /** Enable optimizations */
47
+ optimize?: boolean;
48
+ /** Optimization level */
49
+ optimizationLevel?: 'production' | 'development';
50
+ /** Target environment */
51
+ target?: CompilationTarget;
52
+ /** Include debug info in bytecode */
53
+ includeDebugInfo?: boolean;
54
+ debug?: boolean;
55
+ /** Max allowed bytecode size in bytes */
56
+ maxBytecodeSize?: number;
57
+ maxSize?: number;
58
+ /** Enable general compression */
59
+ enableCompression?: boolean;
60
+ /** Include compilation metrics */
61
+ includeMetrics?: boolean;
62
+ /** Metrics output format */
63
+ metricsFormat?: "json" | "csv" | "toml";
64
+ /** Error output format */
65
+ errorFormat?: "terminal" | "json" | "lsp";
66
+ /** Include comprehensive metrics */
67
+ comprehensiveMetrics?: boolean;
68
+ /** Output file for metrics */
69
+ metricsOutput?: string;
70
+ /** Enable constraint cache */
71
+ enable_constraint_cache?: boolean;
72
+ /** Flat namespace for modules */
73
+ flatNamespace?: boolean;
74
+ }
75
+ export type FiveScript = FiveScriptSource | FiveBytecode;
76
+ export interface CompilationResult {
77
+ success: boolean;
78
+ bytecode?: Uint8Array;
79
+ abi?: any;
80
+ metadata?: CompilationMetadata;
81
+ errors?: CompilationError[];
82
+ warnings?: CompilationWarning[];
83
+ disassembly?: string[];
84
+ metrics?: CompilationMetrics;
85
+ metricsReport?: CompilationMetricsReport;
86
+ fiveFile?: FiveCompiledFile;
87
+ publicFunctionNames?: string[];
88
+ functionNames?: string[] | FunctionNameEntry[];
89
+ }
90
+ export interface CompilationMetadata {
91
+ sourceFile: string;
92
+ timestamp: string;
93
+ compilerVersion: string;
94
+ target: CompilationTarget;
95
+ optimizations: string[];
96
+ originalSize: number;
97
+ compressedSize: number;
98
+ compressionRatio: number;
99
+ sourceSize?: number;
100
+ bytecodeSize?: number;
101
+ compilationTime?: number;
102
+ functions?: any[];
103
+ }
104
+ export interface CompilationError {
105
+ type: string;
106
+ message: string;
107
+ line?: number;
108
+ column?: number;
109
+ sourceLocation?: string;
110
+ suggestion?: string;
111
+ code?: string;
112
+ severity?: string;
113
+ category?: string;
114
+ description?: string;
115
+ location?: any;
116
+ suggestions?: string[];
117
+ }
118
+ export interface CompilationWarning {
119
+ type: string;
120
+ message: string;
121
+ line?: number;
122
+ column?: number;
123
+ sourceLocation?: string;
124
+ }
125
+ export interface CompilationMetrics {
126
+ compilationTime: number;
127
+ memoryUsed: number;
128
+ optimizationTime: number;
129
+ bytecodeSize: number;
130
+ instructionCount: number;
131
+ functionCount: number;
132
+ }
133
+ export interface CompilationMetricsReport {
134
+ format: string;
135
+ exported: string;
136
+ detailed?: any;
137
+ }
138
+ export interface VMExecutionOptions {
139
+ bytecode: Uint8Array;
140
+ inputData?: Uint8Array;
141
+ accounts?: AccountInfo[];
142
+ maxComputeUnits?: number;
143
+ enableLogging?: boolean;
144
+ enableProfiling?: boolean;
145
+ }
146
+ export interface VMExecutionResult {
147
+ success: boolean;
148
+ result?: any;
149
+ error?: VMError;
150
+ logs?: string[];
151
+ computeUnitsUsed?: number;
152
+ executionTime?: number;
153
+ memoryUsage?: MemoryUsage;
154
+ profileData?: ProfileData;
155
+ status?: string;
156
+ stoppedAt?: string;
157
+ errorMessage?: string;
158
+ }
159
+ export interface VMError {
160
+ type: string;
161
+ message: string;
162
+ instructionPointer?: number;
163
+ stackTrace?: string[];
164
+ errorCode?: number;
165
+ details?: any;
166
+ }
167
+ export interface AccountInfo {
168
+ pubkey?: string;
169
+ key?: Uint8Array;
170
+ lamports: number;
171
+ data: Uint8Array;
172
+ owner?: Uint8Array | string;
173
+ executable?: boolean;
174
+ rentEpoch?: number;
175
+ isWritable?: boolean;
176
+ isSigner?: boolean;
177
+ }
178
+ export interface MemoryUsage {
179
+ heapUsed: number;
180
+ heapTotal: number;
181
+ external: number;
182
+ arrayBuffers: number;
183
+ rss: number;
184
+ }
185
+ export interface ProfileData {
186
+ instructionCounts: Map<string, number>;
187
+ functionCallCounts: Map<string, number>;
188
+ hotspots: Array<{
189
+ instruction: string;
190
+ count: number;
191
+ percentage: number;
192
+ }>;
193
+ }
194
+ export interface Logger {
195
+ debug(message: string, ...args: any[]): void;
196
+ info(message: string, ...args: any[]): void;
197
+ warn(message: string, ...args: any[]): void;
198
+ error(message: string, ...args: any[]): void;
199
+ }
200
+ export interface CLIError extends Error {
201
+ code: string;
202
+ exitCode?: number;
203
+ category: string;
204
+ details?: any;
205
+ }
206
+ export declare const FIVE_VM_PROGRAM_ID = "Five111111111111111111111111111111111111111";
207
+ export interface FiveSDKConfig {
208
+ network?: string;
209
+ connection?: any;
210
+ payer?: any;
211
+ confirmTransactionInitialTimeout?: number;
212
+ debug?: boolean;
213
+ fiveVMProgramId?: string;
214
+ }
215
+ export interface FiveScriptSource {
216
+ filename: string;
217
+ content: string;
218
+ }
219
+ export type FiveBytecode = Uint8Array;
220
+ export type ScriptAccount = SerializableAccount;
221
+ export interface SerializableAccount {
222
+ pubkey: string;
223
+ data: string;
224
+ lamports: number;
225
+ owner: string;
226
+ executable: boolean;
227
+ isSigner?: boolean;
228
+ isWritable?: boolean;
229
+ }
230
+ export interface DeploymentOptions {
231
+ network?: string;
232
+ payer?: any;
233
+ space?: number;
234
+ programId?: string;
235
+ scriptAccount?: any;
236
+ extraLamports?: number;
237
+ debug?: boolean;
238
+ permissions?: number;
239
+ adminAccount?: string;
240
+ estimateFees?: boolean;
241
+ fiveVMProgramId?: string;
242
+ exportMetadata?: {
243
+ methods?: string[];
244
+ interfaces?: Array<{
245
+ name: string;
246
+ methodMap?: Record<string, string>;
247
+ }>;
248
+ };
249
+ namespace?: string;
250
+ }
251
+ export interface FeeInformation {
252
+ feeBps: number;
253
+ basisLamports: number;
254
+ feeLamports: number;
255
+ totalEstimatedCost: number;
256
+ costBreakdown: {
257
+ basis: string;
258
+ fee: string;
259
+ total: string;
260
+ };
261
+ }
262
+ export interface SerializedDeployment {
263
+ programId: string;
264
+ signature?: string;
265
+ instruction?: any;
266
+ scriptAccount?: string;
267
+ requiredSigners?: string[];
268
+ estimatedCost?: number;
269
+ bytecodeSize?: number;
270
+ setupInstructions?: any;
271
+ adminAccount?: string;
272
+ feeInformation?: FeeInformation;
273
+ }
274
+ export interface SerializedExecution {
275
+ transactionId?: string;
276
+ result?: any;
277
+ logs?: string[];
278
+ estimatedComputeUnits?: number;
279
+ instruction?: any;
280
+ scriptAccount?: string;
281
+ parameters?: any;
282
+ requiredSigners?: string[];
283
+ adminAccount?: string;
284
+ feeInformation?: FeeInformation;
285
+ }
286
+ export interface SerializedInstruction {
287
+ programId: string;
288
+ keys: Array<{
289
+ pubkey: string;
290
+ isSigner: boolean;
291
+ isWritable: boolean;
292
+ }>;
293
+ data: string;
294
+ }
295
+ export interface ExecutionOptions extends VMExecutionOptions {
296
+ }
297
+ export declare class FiveSDKError extends Error {
298
+ code: string;
299
+ details?: any;
300
+ constructor(message: string, code: string, details?: any);
301
+ }
302
+ export declare class ExecutionSDKError extends FiveSDKError {
303
+ constructor(message: string, details?: any);
304
+ }
305
+ export declare class CompilationSDKError extends FiveSDKError {
306
+ constructor(message: string, details?: any);
307
+ }
308
+ export interface EncodedParameters {
309
+ data: Uint8Array;
310
+ }
311
+ export interface EncodedParameter {
312
+ type: string | number;
313
+ value: any;
314
+ }
315
+ export interface ParameterEncodingOptions {
316
+ none?: boolean;
317
+ strict?: boolean;
318
+ }
319
+ export declare class ParameterEncodingError extends Error {
320
+ details?: any;
321
+ constructor(message: string, details?: any);
322
+ }
323
+ export interface FiveCompiledFile {
324
+ filename: string;
325
+ bytecode: string;
326
+ metadata?: CompilationMetadata;
327
+ abi?: any;
328
+ debug?: any;
329
+ metrics?: any;
330
+ disassembly?: string[];
331
+ version: string;
332
+ }
333
+ export interface FiveFunction {
334
+ name: string;
335
+ parameters: FiveParameter[];
336
+ returnType?: FiveType;
337
+ }
338
+ export interface FiveParameter {
339
+ name: string;
340
+ type: FiveType;
341
+ }
342
+ export type FiveType = string;
343
+ export interface FunctionNameEntry {
344
+ name: string;
345
+ index: number;
346
+ function_index?: number;
347
+ }
348
+ export interface Provider {
349
+ connection: any;
350
+ publicKey?: {
351
+ toBase58(): string;
352
+ };
353
+ sendAndConfirm?: (tx: any, // Transaction | VersionedTransaction
354
+ signers?: any[], options?: any) => Promise<string>;
355
+ simulate?: (tx: any, signers?: any[], options?: any) => Promise<any>;
356
+ }
package/dist/types.js ADDED
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Type definitions for Five SDK.
3
+ */
4
+ // ==================== Legacy SDK Types (for compatibility) ====================
5
+ export const FIVE_VM_PROGRAM_ID = "Five111111111111111111111111111111111111111";
6
+ export class FiveSDKError extends Error {
7
+ constructor(message, code, details) {
8
+ super(message);
9
+ this.code = code;
10
+ this.details = details;
11
+ this.name = 'FiveSDKError';
12
+ }
13
+ }
14
+ export class ExecutionSDKError extends FiveSDKError {
15
+ constructor(message, details) {
16
+ super(message, 'EXECUTION_ERROR', details);
17
+ this.name = 'ExecutionSDKError';
18
+ }
19
+ }
20
+ export class CompilationSDKError extends FiveSDKError {
21
+ constructor(message, details) {
22
+ super(message, 'COMPILATION_ERROR', details);
23
+ this.name = 'CompilationSDKError';
24
+ }
25
+ }
26
+ export class ParameterEncodingError extends Error {
27
+ constructor(message, details) {
28
+ super(message);
29
+ this.details = details;
30
+ this.name = 'ParameterEncodingError';
31
+ }
32
+ }
@@ -0,0 +1,31 @@
1
+ export interface NormalizedABIFunction {
2
+ name: string;
3
+ index: number;
4
+ parameters: Array<{
5
+ name: string;
6
+ type: string;
7
+ optional?: boolean;
8
+ }>;
9
+ returnType?: string;
10
+ accounts?: any[];
11
+ visibility?: 'public' | 'private';
12
+ }
13
+ /**
14
+ * Normalize ABI function definitions that may be emitted as either arrays (FIVEABI)
15
+ * or maps (SimpleABI) into a consistent array format.
16
+ */
17
+ export declare function normalizeAbiFunctions(abiFunctions: unknown): NormalizedABIFunction[];
18
+ /**
19
+ * Find a function in the ABI by name, supporting both flat and qualified names
20
+ *
21
+ * Handles both naming modes:
22
+ * - Flat namespace: "functionName"
23
+ * - Qualified namespace: "module::functionName"
24
+ *
25
+ * Falls back to partial matching if exact match not found.
26
+ */
27
+ export declare function findFunctionInABI(abi: any, functionName: string): NormalizedABIFunction | undefined;
28
+ /**
29
+ * Resolve function name to index using ABI
30
+ */
31
+ export declare function resolveFunctionIndex(abi: any, functionName: string): number;
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Normalize ABI function definitions that may be emitted as either arrays (FIVEABI)
3
+ * or maps (SimpleABI) into a consistent array format.
4
+ */
5
+ export function normalizeAbiFunctions(abiFunctions) {
6
+ if (!abiFunctions)
7
+ return [];
8
+ const functionsArray = Array.isArray(abiFunctions)
9
+ ? abiFunctions
10
+ : Object.entries(abiFunctions).map(([name, func]) => ({
11
+ name,
12
+ ...(func || {}),
13
+ }));
14
+ return functionsArray
15
+ .map((func, idx) => {
16
+ const parameters = Array.isArray(func.parameters) ? func.parameters : [];
17
+ return {
18
+ name: func.name ?? `function_${func.index ?? idx}`,
19
+ index: typeof func.index === 'number' ? func.index : idx,
20
+ parameters: parameters.map((param, paramIdx) => ({
21
+ name: param.name ?? `param${paramIdx}`,
22
+ type: param.type ?? param.param_type ?? param.paramType ?? '',
23
+ optional: param.optional ?? false,
24
+ isAccount: param.isAccount ?? param.is_account ?? false,
25
+ })),
26
+ returnType: func.returnType ?? func.return_type,
27
+ accounts: func.accounts ?? [],
28
+ visibility: func.visibility ??
29
+ (func.is_public === false ? 'private' : 'public'),
30
+ };
31
+ })
32
+ .sort((a, b) => a.index - b.index);
33
+ }
34
+ /**
35
+ * Find a function in the ABI by name, supporting both flat and qualified names
36
+ *
37
+ * Handles both naming modes:
38
+ * - Flat namespace: "functionName"
39
+ * - Qualified namespace: "module::functionName"
40
+ *
41
+ * Falls back to partial matching if exact match not found.
42
+ */
43
+ export function findFunctionInABI(abi, functionName) {
44
+ const functions = normalizeAbiFunctions(abi);
45
+ // Try exact match first
46
+ let func = functions.find(f => f.name === functionName);
47
+ if (func)
48
+ return func;
49
+ // Try qualified name match (e.g., "module::function" -> "function")
50
+ if (functionName.includes('::')) {
51
+ const parts = functionName.split('::');
52
+ const unqualifiedName = parts[parts.length - 1];
53
+ func = functions.find(f => f.name === unqualifiedName);
54
+ if (func)
55
+ return func;
56
+ }
57
+ // Try partial match (e.g., "function" matches "module::function")
58
+ func = functions.find(f => f.name.endsWith(`::${functionName}`));
59
+ if (func)
60
+ return func;
61
+ // No match found
62
+ return undefined;
63
+ }
64
+ /**
65
+ * Resolve function name to index using ABI
66
+ */
67
+ export function resolveFunctionIndex(abi, functionName) {
68
+ if (!abi || !abi.functions) {
69
+ throw new Error("No ABI information available for function name resolution");
70
+ }
71
+ // Handle both array format: [{ name: "add", index: 0 }] and object format: { "add": { index: 0 } }
72
+ if (Array.isArray(abi.functions)) {
73
+ // Array format (legacy)
74
+ const func = abi.functions.find((f) => f.name === functionName);
75
+ if (!func) {
76
+ const availableFunctions = abi.functions
77
+ .map((f) => f.name)
78
+ .join(", ");
79
+ throw new Error(`Function '${functionName}' not found in ABI. Available functions: ${availableFunctions}`);
80
+ }
81
+ return func.index;
82
+ }
83
+ else {
84
+ // Object format (new WASM ABI)
85
+ const func = abi.functions[functionName];
86
+ if (!func) {
87
+ const availableFunctions = Object.keys(abi.functions).join(", ");
88
+ throw new Error(`Function '${functionName}' not found in ABI. Available functions: ${availableFunctions}`);
89
+ }
90
+ return func.index;
91
+ }
92
+ }
@@ -0,0 +1,5 @@
1
+ export declare function pollForConfirmation(connection: any, signature: string, commitment?: string, timeoutMs?: number, debug?: boolean): Promise<{
2
+ success: boolean;
3
+ err?: any;
4
+ error?: string;
5
+ }>;
@@ -0,0 +1,48 @@
1
+ export async function pollForConfirmation(connection, signature, commitment = "confirmed", timeoutMs = 120000, debug = false) {
2
+ const startTime = Date.now();
3
+ const pollIntervalMs = 1000;
4
+ if (debug) {
5
+ console.log(`[FiveSDK] Starting confirmation poll with ${timeoutMs}ms timeout`);
6
+ }
7
+ while (Date.now() - startTime < timeoutMs) {
8
+ try {
9
+ const confirmationStatus = await connection.getSignatureStatus(signature);
10
+ if (debug && (Date.now() - startTime) % 10000 < 1000) {
11
+ console.log(`[FiveSDK] Confirmation status: ${JSON.stringify(confirmationStatus.value)}`);
12
+ }
13
+ if (confirmationStatus.value) {
14
+ if (confirmationStatus.value.confirmationStatus === commitment ||
15
+ confirmationStatus.value.confirmations >= 1) {
16
+ const transactionError = confirmationStatus.value.err;
17
+ const succeeded = !transactionError;
18
+ if (debug) {
19
+ console.log(`[FiveSDK] Transaction confirmed after ${Date.now() - startTime}ms${succeeded ? '' : ' (with error)'}`);
20
+ if (transactionError) {
21
+ console.log(`[FiveSDK] Transaction error: ${JSON.stringify(transactionError)}`);
22
+ }
23
+ }
24
+ return {
25
+ success: succeeded,
26
+ err: transactionError,
27
+ error: transactionError ? JSON.stringify(transactionError) : undefined,
28
+ };
29
+ }
30
+ }
31
+ await new Promise(resolve => setTimeout(resolve, pollIntervalMs));
32
+ }
33
+ catch (error) {
34
+ if (debug) {
35
+ console.log(`[FiveSDK] Polling error: ${error instanceof Error ? error.message : String(error)}`);
36
+ }
37
+ await new Promise(resolve => setTimeout(resolve, pollIntervalMs));
38
+ }
39
+ }
40
+ const elapsed = Date.now() - startTime;
41
+ if (debug) {
42
+ console.log(`[FiveSDK] Confirmation polling timeout after ${elapsed}ms`);
43
+ }
44
+ return {
45
+ success: false,
46
+ error: `Transaction confirmation timeout after ${elapsed}ms. Signature: ${signature}`,
47
+ };
48
+ }
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Five SDK input validation.
3
+ * Protects against common injection and resource abuse cases.
4
+ */
5
+ import { FiveSDKError } from '../types.js';
6
+ /**
7
+ * Input validation configuration
8
+ */
9
+ export interface ValidationConfig {
10
+ /** Maximum source code size in bytes */
11
+ maxSourceSize: number;
12
+ /** Maximum bytecode size in bytes */
13
+ maxBytecodeSize: number;
14
+ /** Maximum parameter count */
15
+ maxParameters: number;
16
+ /** Maximum parameter value size */
17
+ maxParameterSize: number;
18
+ /** Maximum file path length */
19
+ maxPathLength: number;
20
+ /** Maximum account count */
21
+ maxAccounts: number;
22
+ /** Maximum string length */
23
+ maxStringLength: number;
24
+ /** Maximum array length */
25
+ maxArrayLength: number;
26
+ /** Allowed file extensions */
27
+ allowedExtensions: string[];
28
+ /** Path whitelist patterns */
29
+ allowedPaths: RegExp[];
30
+ }
31
+ /**
32
+ * Default validation configuration
33
+ */
34
+ export declare const DEFAULT_VALIDATION_CONFIG: ValidationConfig;
35
+ /**
36
+ * Validation error types
37
+ */
38
+ export declare enum ValidationErrorType {
39
+ INVALID_INPUT = "INVALID_INPUT",
40
+ SIZE_EXCEEDED = "SIZE_EXCEEDED",
41
+ TYPE_MISMATCH = "TYPE_MISMATCH",
42
+ UNSAFE_PATH = "UNSAFE_PATH",
43
+ RESOURCE_EXHAUSTION = "RESOURCE_EXHAUSTION",
44
+ MALICIOUS_CONTENT = "MALICIOUS_CONTENT",
45
+ ENCODING_ERROR = "ENCODING_ERROR"
46
+ }
47
+ /**
48
+ * Input validation error
49
+ */
50
+ export declare class ValidationError extends FiveSDKError {
51
+ type: ValidationErrorType;
52
+ field?: string;
53
+ value?: any;
54
+ constructor(message: string, type: ValidationErrorType, field?: string, value?: any);
55
+ }
56
+ /**
57
+ * Input validator for Five SDK
58
+ */
59
+ export declare class InputValidator {
60
+ private config;
61
+ constructor(config?: ValidationConfig);
62
+ /**
63
+ * Validate source code input
64
+ */
65
+ validateSourceCode(source: string, context?: string): void;
66
+ /**
67
+ * Validate bytecode input
68
+ */
69
+ validateBytecode(bytecode: Uint8Array, context?: string): void;
70
+ /**
71
+ * Validate file path
72
+ */
73
+ validateFilePath(path: string, context?: string): void;
74
+ /**
75
+ * Validate function parameters
76
+ */
77
+ validateParameters(parameters: any[], context?: string): void;
78
+ /**
79
+ * Validate individual parameter
80
+ */
81
+ validateParameter(parameter: any, context?: string): void;
82
+ /**
83
+ * Validate account addresses
84
+ */
85
+ validateAccounts(accounts: string[], context?: string): void;
86
+ /**
87
+ * Validate Base58 address
88
+ */
89
+ validateBase58Address(address: string, context?: string): void;
90
+ /**
91
+ * Validate function name or index
92
+ */
93
+ validateFunctionReference(functionRef: string | number, context?: string): void;
94
+ /**
95
+ * Validate options object
96
+ */
97
+ validateOptions(options: any, context?: string): void;
98
+ /**
99
+ * Validate string input
100
+ */
101
+ private validateString;
102
+ /**
103
+ * Validate number input (also exposed as public for external use)
104
+ */
105
+ validateNumber(value: number, context?: string): void;
106
+ /**
107
+ * Validate number input (private implementation)
108
+ */
109
+ private validateNumberPrivate;
110
+ /**
111
+ * Validate buffer input
112
+ */
113
+ private validateBuffer;
114
+ /**
115
+ * Validate array input
116
+ */
117
+ private validateArray;
118
+ /**
119
+ * Check for malicious patterns in source code
120
+ */
121
+ private containsMaliciousPatterns;
122
+ }
123
+ /**
124
+ * Global validator instance
125
+ */
126
+ export declare const validator: InputValidator;
127
+ /**
128
+ * Validation decorators for class methods
129
+ */
130
+ export declare function validateInput(validationFn: (args: any[]) => void): (target: any, propertyName: string, descriptor: PropertyDescriptor) => void;
131
+ /**
132
+ * Common validation patterns
133
+ */
134
+ export declare const Validators: {
135
+ sourceCode: (source: string) => void;
136
+ bytecode: (bytecode: Uint8Array) => void;
137
+ filePath: (path: string) => void;
138
+ parameters: (params: any[]) => void;
139
+ accounts: (accounts: string[]) => void;
140
+ functionRef: (ref: string | number) => void;
141
+ options: (opts: any) => void;
142
+ };