@flashnet/sdk 0.1.1

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 (50) hide show
  1. package/README.md +479 -0
  2. package/dist/index.d.ts +13 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +15 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/src/api/client.d.ts +20 -0
  7. package/dist/src/api/client.d.ts.map +1 -0
  8. package/dist/src/api/client.js +85 -0
  9. package/dist/src/api/client.js.map +1 -0
  10. package/dist/src/api/typed-endpoints.d.ts +135 -0
  11. package/dist/src/api/typed-endpoints.d.ts.map +1 -0
  12. package/dist/src/api/typed-endpoints.js +202 -0
  13. package/dist/src/api/typed-endpoints.js.map +1 -0
  14. package/dist/src/api/validation.d.ts +114 -0
  15. package/dist/src/api/validation.d.ts.map +1 -0
  16. package/dist/src/api/validation.js +128 -0
  17. package/dist/src/api/validation.js.map +1 -0
  18. package/dist/src/client/FlashnetClient.d.ts +216 -0
  19. package/dist/src/client/FlashnetClient.d.ts.map +1 -0
  20. package/dist/src/client/FlashnetClient.js +800 -0
  21. package/dist/src/client/FlashnetClient.js.map +1 -0
  22. package/dist/src/config/index.d.ts +14 -0
  23. package/dist/src/config/index.d.ts.map +1 -0
  24. package/dist/src/config/index.js +40 -0
  25. package/dist/src/config/index.js.map +1 -0
  26. package/dist/src/types/index.d.ts +484 -0
  27. package/dist/src/types/index.d.ts.map +1 -0
  28. package/dist/src/types/index.js +2 -0
  29. package/dist/src/types/index.js.map +1 -0
  30. package/dist/src/utils/auth.d.ts +26 -0
  31. package/dist/src/utils/auth.d.ts.map +1 -0
  32. package/dist/src/utils/auth.js +85 -0
  33. package/dist/src/utils/auth.js.map +1 -0
  34. package/dist/src/utils/index.d.ts +8 -0
  35. package/dist/src/utils/index.d.ts.map +1 -0
  36. package/dist/src/utils/index.js +19 -0
  37. package/dist/src/utils/index.js.map +1 -0
  38. package/dist/src/utils/intents.d.ts +86 -0
  39. package/dist/src/utils/intents.d.ts.map +1 -0
  40. package/dist/src/utils/intents.js +133 -0
  41. package/dist/src/utils/intents.js.map +1 -0
  42. package/dist/src/utils/signer.d.ts +29 -0
  43. package/dist/src/utils/signer.d.ts.map +1 -0
  44. package/dist/src/utils/signer.js +34 -0
  45. package/dist/src/utils/signer.js.map +1 -0
  46. package/dist/src/utils/spark-address.d.ts +60 -0
  47. package/dist/src/utils/spark-address.d.ts.map +1 -0
  48. package/dist/src/utils/spark-address.js +227 -0
  49. package/dist/src/utils/spark-address.js.map +1 -0
  50. package/package.json +43 -0
@@ -0,0 +1,135 @@
1
+ import { ApiClient } from "./client";
2
+ import type * as Types from "../types";
3
+ /**
4
+ * Typed API endpoints for the Flashnet AMM Gateway
5
+ */
6
+ export declare class TypedAmmApi {
7
+ private client;
8
+ constructor(client: ApiClient);
9
+ /**
10
+ * Request authentication challenge
11
+ * @POST /v1/auth/challenge
12
+ */
13
+ getChallenge(request: Types.ChallengeRequest): Promise<Types.ChallengeResponse>;
14
+ /**
15
+ * Verify challenge and get access token
16
+ * @POST /v1/auth/verify
17
+ */
18
+ verify(request: Types.VerifyRequest): Promise<Types.VerifyResponse>;
19
+ /**
20
+ * Register a new host
21
+ * @POST /v1/hosts/register
22
+ * @requires Bearer token
23
+ */
24
+ registerHost(request: Types.RegisterHostRequest): Promise<Types.RegisterHostResponse>;
25
+ /**
26
+ * Get host information
27
+ * @GET /v1/hosts/{namespace}
28
+ */
29
+ getHost(namespace: string): Promise<Types.GetHostResponse>;
30
+ /**
31
+ * Withdraw host fees
32
+ * @POST /v1/hosts/withdraw-fees
33
+ * @requires Bearer token
34
+ */
35
+ withdrawHostFees(request: Types.WithdrawHostFeesRequest): Promise<Types.WithdrawHostFeesResponse>;
36
+ /**
37
+ * Get pool host fees
38
+ * @POST /v1/hosts/pool-fees
39
+ * @requires Bearer token
40
+ */
41
+ getPoolHostFees(request: Types.GetPoolHostFeesRequest): Promise<Types.GetPoolHostFeesResponse>;
42
+ /**
43
+ * Create constant product pool
44
+ * @POST /v1/pools/constant-product
45
+ * @requires Bearer token
46
+ */
47
+ createConstantProductPool(request: Types.CreateConstantProductPoolRequest): Promise<Types.CreatePoolResponse>;
48
+ /**
49
+ * Create single-sided pool
50
+ * @POST /v1/pools/single-sided
51
+ * @requires Bearer token
52
+ */
53
+ createSingleSidedPool(request: Types.CreateSingleSidedPoolRequest): Promise<Types.CreatePoolResponse>;
54
+ /**
55
+ * Confirm initial deposit for single-sided pool
56
+ * @POST /v1/pools/single-sided/confirm-initial-deposit
57
+ * @requires Bearer token
58
+ */
59
+ confirmInitialDeposit(request: Types.ConfirmInitialDepositRequest): Promise<Types.ConfirmDepositResponse>;
60
+ /**
61
+ * List pools with filters
62
+ * @GET /v1/pools
63
+ */
64
+ listPools(query?: Types.ListPoolsQuery): Promise<Types.ListPoolsResponse>;
65
+ /**
66
+ * Get pool details
67
+ * @GET /v1/pools/{poolId}
68
+ */
69
+ getPool(poolId: string): Promise<Types.PoolDetailsResponse>;
70
+ /**
71
+ * Get LP position details
72
+ * @GET /v1/pools/{poolId}/lp/{providerPublicKey}
73
+ * @requires Bearer token
74
+ */
75
+ getLpPosition(poolId: string, providerPublicKey: string): Promise<Types.LpPositionDetailsResponse>;
76
+ /**
77
+ * Add liquidity to pool
78
+ * @POST /v1/liquidity/add
79
+ * @requires Bearer token
80
+ */
81
+ addLiquidity(request: Types.AddLiquidityRequest): Promise<Types.AddLiquidityResponse>;
82
+ /**
83
+ * Simulate adding liquidity
84
+ * @POST /v1/liquidity/add/simulate
85
+ */
86
+ simulateAddLiquidity(request: Types.SimulateAddLiquidityRequest): Promise<Types.SimulateAddLiquidityResponse>;
87
+ /**
88
+ * Remove liquidity from pool
89
+ * @POST /v1/liquidity/remove
90
+ * @requires Bearer token
91
+ */
92
+ removeLiquidity(request: Types.RemoveLiquidityRequest): Promise<Types.RemoveLiquidityResponse>;
93
+ /**
94
+ * Simulate removing liquidity
95
+ * @POST /v1/liquidity/remove/simulate
96
+ */
97
+ simulateRemoveLiquidity(request: Types.SimulateRemoveLiquidityRequest): Promise<Types.SimulateRemoveLiquidityResponse>;
98
+ /**
99
+ * Execute swap
100
+ * @POST /v1/swap
101
+ * @requires Bearer token
102
+ */
103
+ executeSwap(request: Types.ExecuteSwapRequest): Promise<Types.SwapResponse>;
104
+ /**
105
+ * Simulate swap
106
+ * @POST /v1/swap/simulate
107
+ */
108
+ simulateSwap(request: Types.SimulateSwapRequest): Promise<Types.SimulateSwapResponse>;
109
+ /**
110
+ * Get swaps for a pool
111
+ * @GET /v1/pools/{lpPubkey}/swaps
112
+ */
113
+ getPoolSwaps(lpPubkey: string, query?: Types.ListPoolSwapsQuery): Promise<Types.ListPoolSwapsResponse>;
114
+ /**
115
+ * Get global swaps
116
+ * @GET /v1/swaps
117
+ */
118
+ getGlobalSwaps(query?: Types.ListGlobalSwapsQuery): Promise<Types.ListGlobalSwapsResponse>;
119
+ /**
120
+ * Get user swaps
121
+ * @GET /v1/swaps/user/{userPublicKey}
122
+ */
123
+ getUserSwaps(userPublicKey: string, query?: Types.ListUserSwapsQuery): Promise<Types.ListUserSwapsResponse>;
124
+ /**
125
+ * Ping settlement service
126
+ * @GET /v1/ping
127
+ */
128
+ ping(): Promise<Types.SettlementPingResponse>;
129
+ }
130
+ /**
131
+ * Error checking utilities
132
+ */
133
+ export declare function isFlashnetError(error: unknown): error is Types.FlashnetErrorResponse;
134
+ export declare function isApiError(error: unknown): error is Types.ApiErrorResponse;
135
+ //# sourceMappingURL=typed-endpoints.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typed-endpoints.d.ts","sourceRoot":"","sources":["../../../src/api/typed-endpoints.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,KAAK,KAAK,KAAK,MAAM,UAAU,CAAC;AAEvC;;GAEG;AACH,qBAAa,WAAW;IACV,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,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;GAEG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,KAAK,CAAC,qBAAqB,CAStC;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,KAAK,CAAC,gBAAgB,CAO1E"}
@@ -0,0 +1,202 @@
1
+ import { ApiClient } from "./client";
2
+ /**
3
+ * Typed API endpoints for the Flashnet AMM Gateway
4
+ */
5
+ export class TypedAmmApi {
6
+ client;
7
+ constructor(client) {
8
+ this.client = client;
9
+ }
10
+ // ===== Authentication Endpoints =====
11
+ /**
12
+ * Request authentication challenge
13
+ * @POST /v1/auth/challenge
14
+ */
15
+ async getChallenge(request) {
16
+ return this.client.ammPost("/v1/auth/challenge", request);
17
+ }
18
+ /**
19
+ * Verify challenge and get access token
20
+ * @POST /v1/auth/verify
21
+ */
22
+ async verify(request) {
23
+ return this.client.ammPost("/v1/auth/verify", request);
24
+ }
25
+ // ===== Host Endpoints =====
26
+ /**
27
+ * Register a new host
28
+ * @POST /v1/hosts/register
29
+ * @requires Bearer token
30
+ */
31
+ async registerHost(request) {
32
+ return this.client.ammPost("/v1/hosts/register", request);
33
+ }
34
+ /**
35
+ * Get host information
36
+ * @GET /v1/hosts/{namespace}
37
+ */
38
+ async getHost(namespace) {
39
+ return this.client.ammGet(`/v1/hosts/${namespace}`);
40
+ }
41
+ /**
42
+ * Withdraw host fees
43
+ * @POST /v1/hosts/withdraw-fees
44
+ * @requires Bearer token
45
+ */
46
+ async withdrawHostFees(request) {
47
+ return this.client.ammPost("/v1/hosts/withdraw-fees", request);
48
+ }
49
+ /**
50
+ * Get pool host fees
51
+ * @POST /v1/hosts/pool-fees
52
+ * @requires Bearer token
53
+ */
54
+ async getPoolHostFees(request) {
55
+ return this.client.ammPost("/v1/hosts/pool-fees", request);
56
+ }
57
+ // ===== Pool Endpoints =====
58
+ /**
59
+ * Create constant product pool
60
+ * @POST /v1/pools/constant-product
61
+ * @requires Bearer token
62
+ */
63
+ async createConstantProductPool(request) {
64
+ return this.client.ammPost("/v1/pools/constant-product", request);
65
+ }
66
+ /**
67
+ * Create single-sided pool
68
+ * @POST /v1/pools/single-sided
69
+ * @requires Bearer token
70
+ */
71
+ async createSingleSidedPool(request) {
72
+ return this.client.ammPost("/v1/pools/single-sided", request);
73
+ }
74
+ /**
75
+ * Confirm initial deposit for single-sided pool
76
+ * @POST /v1/pools/single-sided/confirm-initial-deposit
77
+ * @requires Bearer token
78
+ */
79
+ async confirmInitialDeposit(request) {
80
+ return this.client.ammPost("/v1/pools/single-sided/confirm-initial-deposit", request);
81
+ }
82
+ /**
83
+ * List pools with filters
84
+ * @GET /v1/pools
85
+ */
86
+ async listPools(query) {
87
+ return this.client.ammGet("/v1/pools", {
88
+ params: query,
89
+ });
90
+ }
91
+ /**
92
+ * Get pool details
93
+ * @GET /v1/pools/{poolId}
94
+ */
95
+ async getPool(poolId) {
96
+ return this.client.ammGet(`/v1/pools/${poolId}`);
97
+ }
98
+ /**
99
+ * Get LP position details
100
+ * @GET /v1/pools/{poolId}/lp/{providerPublicKey}
101
+ * @requires Bearer token
102
+ */
103
+ async getLpPosition(poolId, providerPublicKey) {
104
+ return this.client.ammGet(`/v1/pools/${poolId}/lp/${providerPublicKey}`);
105
+ }
106
+ // ===== Liquidity Endpoints =====
107
+ /**
108
+ * Add liquidity to pool
109
+ * @POST /v1/liquidity/add
110
+ * @requires Bearer token
111
+ */
112
+ async addLiquidity(request) {
113
+ return this.client.ammPost("/v1/liquidity/add", request);
114
+ }
115
+ /**
116
+ * Simulate adding liquidity
117
+ * @POST /v1/liquidity/add/simulate
118
+ */
119
+ async simulateAddLiquidity(request) {
120
+ return this.client.ammPost("/v1/liquidity/add/simulate", request);
121
+ }
122
+ /**
123
+ * Remove liquidity from pool
124
+ * @POST /v1/liquidity/remove
125
+ * @requires Bearer token
126
+ */
127
+ async removeLiquidity(request) {
128
+ return this.client.ammPost("/v1/liquidity/remove", request);
129
+ }
130
+ /**
131
+ * Simulate removing liquidity
132
+ * @POST /v1/liquidity/remove/simulate
133
+ */
134
+ async simulateRemoveLiquidity(request) {
135
+ return this.client.ammPost("/v1/liquidity/remove/simulate", request);
136
+ }
137
+ // ===== Swap Endpoints =====
138
+ /**
139
+ * Execute swap
140
+ * @POST /v1/swap
141
+ * @requires Bearer token
142
+ */
143
+ async executeSwap(request) {
144
+ return this.client.ammPost("/v1/swap", request);
145
+ }
146
+ /**
147
+ * Simulate swap
148
+ * @POST /v1/swap/simulate
149
+ */
150
+ async simulateSwap(request) {
151
+ return this.client.ammPost("/v1/swap/simulate", request);
152
+ }
153
+ /**
154
+ * Get swaps for a pool
155
+ * @GET /v1/pools/{lpPubkey}/swaps
156
+ */
157
+ async getPoolSwaps(lpPubkey, query) {
158
+ return this.client.ammGet(`/v1/pools/${lpPubkey}/swaps`, { params: query });
159
+ }
160
+ /**
161
+ * Get global swaps
162
+ * @GET /v1/swaps
163
+ */
164
+ async getGlobalSwaps(query) {
165
+ return this.client.ammGet("/v1/swaps", {
166
+ params: query,
167
+ });
168
+ }
169
+ /**
170
+ * Get user swaps
171
+ * @GET /v1/swaps/user/{userPublicKey}
172
+ */
173
+ async getUserSwaps(userPublicKey, query) {
174
+ return this.client.ammGet(`/v1/swaps/user/${userPublicKey}`, { params: query });
175
+ }
176
+ // ===== Status Endpoints =====
177
+ /**
178
+ * Ping settlement service
179
+ * @GET /v1/ping
180
+ */
181
+ async ping() {
182
+ return this.client.ammGet("/v1/ping");
183
+ }
184
+ }
185
+ /**
186
+ * Error checking utilities
187
+ */
188
+ export function isFlashnetError(error) {
189
+ return (typeof error === "object" &&
190
+ error !== null &&
191
+ "code" in error &&
192
+ "msg" in error &&
193
+ typeof error.code === "number" &&
194
+ typeof error.msg === "string");
195
+ }
196
+ export function isApiError(error) {
197
+ return (typeof error === "object" &&
198
+ error !== null &&
199
+ "error" in error &&
200
+ typeof error.error === "object");
201
+ }
202
+ //# sourceMappingURL=typed-endpoints.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typed-endpoints.js","sourceRoot":"","sources":["../../../src/api/typed-endpoints.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAGrC;;GAEG;AACH,MAAM,OAAO,WAAW;IACF;IAApB,YAAoB,MAAiB;QAAjB,WAAM,GAAN,MAAM,CAAW;IAAG,CAAC;IAEzC,uCAAuC;IAEvC;;;OAGG;IACH,KAAK,CAAC,YAAY,CAChB,OAA+B;QAE/B,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CACxB,oBAAoB,EACpB,OAAO,CACR,CAAC;IACJ,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,MAAM,CAAC,OAA4B;QACvC,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CACxB,iBAAiB,EACjB,OAAO,CACR,CAAC;IACJ,CAAC;IAED,6BAA6B;IAE7B;;;;OAIG;IACH,KAAK,CAAC,YAAY,CAChB,OAAkC;QAElC,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CACxB,oBAAoB,EACpB,OAAO,CACR,CAAC;IACJ,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,OAAO,CAAC,SAAiB;QAC7B,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAwB,aAAa,SAAS,EAAE,CAAC,CAAC;IAC7E,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,gBAAgB,CACpB,OAAsC;QAEtC,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CACxB,yBAAyB,EACzB,OAAO,CACR,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,eAAe,CACnB,OAAqC;QAErC,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CACxB,qBAAqB,EACrB,OAAO,CACR,CAAC;IACJ,CAAC;IAED,6BAA6B;IAE7B;;;;OAIG;IACH,KAAK,CAAC,yBAAyB,CAC7B,OAA+C;QAE/C,OAAO,IAAI,CAAC,MAAM,CAA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,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,MAAM,IAAI,KAAK;QACf,KAAK,IAAI,KAAK;QACd,OAAQ,KAAa,CAAC,IAAI,KAAK,QAAQ;QACvC,OAAQ,KAAa,CAAC,GAAG,KAAK,QAAQ,CACvC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,OAAO,IAAI,KAAK;QAChB,OAAQ,KAAa,CAAC,KAAK,KAAK,QAAQ,CACzC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Validation helpers for API requests
3
+ */
4
+ /**
5
+ * Validates that a public key is in the correct format
6
+ */
7
+ export declare function validatePublicKey(publicKey: string): boolean;
8
+ /**
9
+ * Validates that a signature is in the correct format
10
+ */
11
+ export declare function validateSignature(signature: string): boolean;
12
+ /**
13
+ * Validates that an amount is positive
14
+ */
15
+ export declare function validatePositiveAmount(amount: number | string): boolean;
16
+ /**
17
+ * Validates that a BPS value is in the valid range
18
+ */
19
+ export declare function validateBps(bps: number, min?: number, max?: number): boolean;
20
+ /**
21
+ * Validates a namespace string
22
+ */
23
+ export declare function validateNamespace(namespace: string): boolean;
24
+ /**
25
+ * Common validation errors
26
+ */
27
+ export declare class ValidationError extends Error {
28
+ field: string;
29
+ reason: string;
30
+ constructor(field: string, reason: string);
31
+ }
32
+ /**
33
+ * Validates a request object against a set of rules
34
+ */
35
+ export declare function validateRequest<T extends Record<string, any>>(request: T, rules: ValidationRules<T>): void;
36
+ export interface ValidationRule {
37
+ required?: boolean;
38
+ validator?: (value: any) => boolean;
39
+ message?: string;
40
+ }
41
+ export type ValidationRules<T> = {
42
+ [K in keyof T]?: ValidationRule;
43
+ };
44
+ /**
45
+ * Pre-defined validation rules for common request types
46
+ */
47
+ export declare const commonValidationRules: {
48
+ publicKey: {
49
+ required: boolean;
50
+ validator: typeof validatePublicKey;
51
+ message: string;
52
+ };
53
+ signature: {
54
+ required: boolean;
55
+ validator: typeof validateSignature;
56
+ message: string;
57
+ };
58
+ nonce: {
59
+ required: boolean;
60
+ validator: (v: any) => boolean;
61
+ message: string;
62
+ };
63
+ amount: {
64
+ required: boolean;
65
+ validator: typeof validatePositiveAmount;
66
+ message: string;
67
+ };
68
+ bps: {
69
+ required: boolean;
70
+ validator: (v: any) => boolean;
71
+ message: string;
72
+ };
73
+ };
74
+ /**
75
+ * Validation rules for CreateConstantProductPoolRequest
76
+ */
77
+ export declare const constantProductPoolValidationRules: {
78
+ poolOwnerPublicKey: {
79
+ required: boolean;
80
+ validator: typeof validatePublicKey;
81
+ message: string;
82
+ };
83
+ assetATokenPublicKey: {
84
+ required: boolean;
85
+ validator: typeof validatePublicKey;
86
+ message: string;
87
+ };
88
+ assetBTokenPublicKey: {
89
+ required: boolean;
90
+ validator: typeof validatePublicKey;
91
+ message: string;
92
+ };
93
+ lpFeeRateBps: {
94
+ required: boolean;
95
+ validator: (v: any) => boolean;
96
+ message: string;
97
+ };
98
+ integratorNamespace: {
99
+ required: boolean;
100
+ validator: typeof validateNamespace;
101
+ message: string;
102
+ };
103
+ nonce: {
104
+ required: boolean;
105
+ validator: (v: any) => boolean;
106
+ message: string;
107
+ };
108
+ signature: {
109
+ required: boolean;
110
+ validator: typeof validateSignature;
111
+ message: string;
112
+ };
113
+ };
114
+ //# sourceMappingURL=validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../../src/api/validation.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAS5D;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAS5D;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAGvE;AAED;;GAEG;AACH,wBAAgB,WAAW,CACzB,GAAG,EAAE,MAAM,EACX,GAAG,GAAE,MAAU,EACf,GAAG,GAAE,MAAc,GAClB,OAAO,CAET;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAO5D;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,KAAK;IACrB,KAAK,EAAE,MAAM;IAAS,MAAM,EAAE,MAAM;gBAApC,KAAK,EAAE,MAAM,EAAS,MAAM,EAAE,MAAM;CAIxD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC3D,OAAO,EAAE,CAAC,EACV,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,GACxB,IAAI,CA4BN;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,OAAO,CAAC;IACpC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI;KAC9B,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,cAAc;CAChC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;uBAaf,GAAG;;;;;;;;;;uBAUH,GAAG;;;CAGrB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kCAAkC;;;;;;;;;;;;;;;;;;uBAR5B,GAAG;;;;;;;;;;uBAVH,GAAG;;;;;;;;CA8BrB,CAAC"}
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Validation helpers for API requests
3
+ */
4
+ /**
5
+ * Validates that a public key is in the correct format
6
+ */
7
+ export function validatePublicKey(publicKey) {
8
+ // Check if it's a valid hex string of the correct length
9
+ // Bitcoin/Spark public keys are typically 33 bytes (66 hex chars) for compressed
10
+ // or 65 bytes (130 hex chars) for uncompressed
11
+ const hexRegex = /^[0-9a-fA-F]+$/;
12
+ return (hexRegex.test(publicKey) &&
13
+ (publicKey.length === 66 || publicKey.length === 130));
14
+ }
15
+ /**
16
+ * Validates that a signature is in the correct format
17
+ */
18
+ export function validateSignature(signature) {
19
+ // Check if it's a valid hex string
20
+ // Signatures are typically 64-72 bytes (128-144 hex chars)
21
+ const hexRegex = /^[0-9a-fA-F]+$/;
22
+ return (hexRegex.test(signature) &&
23
+ signature.length >= 128 &&
24
+ signature.length <= 144);
25
+ }
26
+ /**
27
+ * Validates that an amount is positive
28
+ */
29
+ export function validatePositiveAmount(amount) {
30
+ const numAmount = typeof amount === "string" ? parseFloat(amount) : amount;
31
+ return !isNaN(numAmount) && numAmount > 0;
32
+ }
33
+ /**
34
+ * Validates that a BPS value is in the valid range
35
+ */
36
+ export function validateBps(bps, min = 0, max = 10000) {
37
+ return Number.isInteger(bps) && bps >= min && bps <= max;
38
+ }
39
+ /**
40
+ * Validates a namespace string
41
+ */
42
+ export function validateNamespace(namespace) {
43
+ // Namespace must be between 3-32 characters
44
+ return (namespace.length >= 3 &&
45
+ namespace.length <= 32 &&
46
+ /^[a-zA-Z0-9-_]+$/.test(namespace));
47
+ }
48
+ /**
49
+ * Common validation errors
50
+ */
51
+ export class ValidationError extends Error {
52
+ field;
53
+ reason;
54
+ constructor(field, reason) {
55
+ super(`Validation failed for ${field}: ${reason}`);
56
+ this.field = field;
57
+ this.reason = reason;
58
+ this.name = "ValidationError";
59
+ }
60
+ }
61
+ /**
62
+ * Validates a request object against a set of rules
63
+ */
64
+ export function validateRequest(request, rules) {
65
+ for (const [field, rule] of Object.entries(rules)) {
66
+ const value = request[field];
67
+ // Check required fields
68
+ if (rule.required &&
69
+ (value === undefined || value === null || value === "")) {
70
+ throw new ValidationError(String(field), "field is required");
71
+ }
72
+ // Skip validation for optional fields that are not provided
73
+ if (!rule.required && (value === undefined || value === null)) {
74
+ continue;
75
+ }
76
+ // Run custom validator if provided
77
+ if (rule.validator && !rule.validator(value)) {
78
+ throw new ValidationError(String(field), rule.message || "validation failed");
79
+ }
80
+ }
81
+ }
82
+ /**
83
+ * Pre-defined validation rules for common request types
84
+ */
85
+ export const commonValidationRules = {
86
+ publicKey: {
87
+ required: true,
88
+ validator: validatePublicKey,
89
+ message: "invalid public key format",
90
+ },
91
+ signature: {
92
+ required: true,
93
+ validator: validateSignature,
94
+ message: "invalid signature format",
95
+ },
96
+ nonce: {
97
+ required: true,
98
+ validator: (v) => typeof v === "string" && v.length > 0,
99
+ message: "nonce must be a non-empty string",
100
+ },
101
+ amount: {
102
+ required: true,
103
+ validator: validatePositiveAmount,
104
+ message: "amount must be positive",
105
+ },
106
+ bps: {
107
+ required: true,
108
+ validator: (v) => validateBps(v),
109
+ message: "BPS must be between 0 and 10000",
110
+ },
111
+ };
112
+ /**
113
+ * Validation rules for CreateConstantProductPoolRequest
114
+ */
115
+ export const constantProductPoolValidationRules = {
116
+ poolOwnerPublicKey: commonValidationRules.publicKey,
117
+ assetATokenPublicKey: commonValidationRules.publicKey,
118
+ assetBTokenPublicKey: commonValidationRules.publicKey,
119
+ lpFeeRateBps: commonValidationRules.bps,
120
+ integratorNamespace: {
121
+ required: true,
122
+ validator: validateNamespace,
123
+ message: "invalid namespace format",
124
+ },
125
+ nonce: commonValidationRules.nonce,
126
+ signature: commonValidationRules.signature,
127
+ };
128
+ //# sourceMappingURL=validation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.js","sourceRoot":"","sources":["../../../src/api/validation.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,SAAiB;IACjD,yDAAyD;IACzD,iFAAiF;IACjF,+CAA+C;IAC/C,MAAM,QAAQ,GAAG,gBAAgB,CAAC;IAClC,OAAO,CACL,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC;QACxB,CAAC,SAAS,CAAC,MAAM,KAAK,EAAE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