@jack-kernel/sdk 1.0.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/README.md +757 -0
- package/dist/cjs/agent.js +321 -0
- package/dist/cjs/agent.js.map +1 -0
- package/dist/cjs/cache.js +58 -0
- package/dist/cjs/cache.js.map +1 -0
- package/dist/cjs/client.js +196 -0
- package/dist/cjs/client.js.map +1 -0
- package/dist/cjs/costs.js +104 -0
- package/dist/cjs/costs.js.map +1 -0
- package/dist/cjs/errors.js +287 -0
- package/dist/cjs/errors.js.map +1 -0
- package/dist/cjs/execution.js +385 -0
- package/dist/cjs/execution.js.map +1 -0
- package/dist/cjs/index.js +256 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/intents.js +185 -0
- package/dist/cjs/intents.js.map +1 -0
- package/dist/cjs/serialization.js +164 -0
- package/dist/cjs/serialization.js.map +1 -0
- package/dist/cjs/types.js +31 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/validation.js +114 -0
- package/dist/cjs/validation.js.map +1 -0
- package/dist/esm/agent.js +317 -0
- package/dist/esm/agent.js.map +1 -0
- package/dist/esm/cache.js +54 -0
- package/dist/esm/cache.js.map +1 -0
- package/dist/esm/client.js +192 -0
- package/dist/esm/client.js.map +1 -0
- package/dist/esm/costs.js +100 -0
- package/dist/esm/costs.js.map +1 -0
- package/dist/esm/errors.js +278 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/execution.js +381 -0
- package/dist/esm/execution.js.map +1 -0
- package/dist/esm/index.js +236 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/intents.js +181 -0
- package/dist/esm/intents.js.map +1 -0
- package/dist/esm/serialization.js +159 -0
- package/dist/esm/serialization.js.map +1 -0
- package/dist/esm/types.js +28 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/validation.js +111 -0
- package/dist/esm/validation.js.map +1 -0
- package/dist/types/agent.d.ts +171 -0
- package/dist/types/agent.d.ts.map +1 -0
- package/dist/types/cache.d.ts +25 -0
- package/dist/types/cache.d.ts.map +1 -0
- package/dist/types/client.d.ts +46 -0
- package/dist/types/client.d.ts.map +1 -0
- package/dist/types/costs.d.ts +91 -0
- package/dist/types/costs.d.ts.map +1 -0
- package/dist/types/errors.d.ts +242 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/execution.d.ts +145 -0
- package/dist/types/execution.d.ts.map +1 -0
- package/dist/types/index.d.ts +205 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/intents.d.ts +158 -0
- package/dist/types/intents.d.ts.map +1 -0
- package/dist/types/serialization.d.ts +82 -0
- package/dist/types/serialization.d.ts.map +1 -0
- package/dist/types/types.d.ts +302 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/validation.d.ts +40 -0
- package/dist/types/validation.d.ts.map +1 -0
- package/package.json +56 -0
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Intent management for the JACK SDK
|
|
4
|
+
*
|
|
5
|
+
* This module provides the IntentManager class for creating, submitting,
|
|
6
|
+
* and querying intents through the JACK API.
|
|
7
|
+
*
|
|
8
|
+
* Requirements: 1.1, 1.2, 1.3, 1.4
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.IntentManager = void 0;
|
|
12
|
+
const serialization_js_1 = require("./serialization.js");
|
|
13
|
+
const validation_js_1 = require("./validation.js");
|
|
14
|
+
const errors_js_1 = require("./errors.js");
|
|
15
|
+
/**
|
|
16
|
+
* Manager for intent operations
|
|
17
|
+
*
|
|
18
|
+
* Provides methods to create EIP-712 typed data, validate parameters,
|
|
19
|
+
* submit signed intents, and query intent status.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const client = new JackClient({ baseUrl: 'https://api.jack.example' });
|
|
24
|
+
* const manager = new IntentManager(client);
|
|
25
|
+
*
|
|
26
|
+
* // Create typed data for signing
|
|
27
|
+
* const typedData = manager.getTypedData(params);
|
|
28
|
+
* const signature = await wallet.signTypedData(typedData);
|
|
29
|
+
*
|
|
30
|
+
* // Submit the signed intent
|
|
31
|
+
* const intentId = await manager.submit(params, signature);
|
|
32
|
+
*
|
|
33
|
+
* // Query the intent
|
|
34
|
+
* const intent = await manager.get(intentId);
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
class IntentManager {
|
|
38
|
+
client;
|
|
39
|
+
/**
|
|
40
|
+
* Creates a new IntentManager
|
|
41
|
+
*
|
|
42
|
+
* @param client - The JackClient instance to use for API requests
|
|
43
|
+
*/
|
|
44
|
+
constructor(client) {
|
|
45
|
+
this.client = client;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Get EIP-712 typed data for intent signing
|
|
49
|
+
*
|
|
50
|
+
* Constructs properly formatted EIP-712 TypedData that can be signed
|
|
51
|
+
* by a wallet. This method delegates to the serialization module.
|
|
52
|
+
*
|
|
53
|
+
* @param params - Intent parameters to serialize
|
|
54
|
+
* @param chainId - Chain ID for the domain separator (default: 1)
|
|
55
|
+
* @param verifyingContract - Address of the verifying contract
|
|
56
|
+
* @returns EIP-712 TypedData object ready for signing
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* const typedData = manager.getTypedData({
|
|
61
|
+
* sourceChain: 'arbitrum',
|
|
62
|
+
* destinationChain: 'base',
|
|
63
|
+
* tokenIn: '0xUSDC...',
|
|
64
|
+
* tokenOut: '0xWETH...',
|
|
65
|
+
* amountIn: '1000000',
|
|
66
|
+
* minAmountOut: '42000000000000000',
|
|
67
|
+
* deadline: Date.now() + 3600000
|
|
68
|
+
* });
|
|
69
|
+
*
|
|
70
|
+
* const signature = await wallet.signTypedData(typedData);
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* **Validates: Requirement 1.1**
|
|
74
|
+
*/
|
|
75
|
+
getTypedData(params, chainId = 1, verifyingContract = '0x0000000000000000000000000000000000000000') {
|
|
76
|
+
return (0, serialization_js_1.getTypedData)(params, chainId, verifyingContract);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Validate intent parameters
|
|
80
|
+
*
|
|
81
|
+
* Checks that all required fields are present, amounts are positive,
|
|
82
|
+
* deadline is in the future, and addresses are valid format.
|
|
83
|
+
* This method delegates to the validation module.
|
|
84
|
+
*
|
|
85
|
+
* @param params - Intent parameters to validate
|
|
86
|
+
* @returns ValidationResult with valid flag and error messages
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* const result = manager.validate(params);
|
|
91
|
+
* if (!result.valid) {
|
|
92
|
+
* console.error('Validation errors:', result.errors);
|
|
93
|
+
* }
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* **Validates: Requirement 5.4**
|
|
97
|
+
*/
|
|
98
|
+
validate(params) {
|
|
99
|
+
return (0, validation_js_1.validateIntentParams)(params);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Submit a signed intent to the JACK API
|
|
103
|
+
*
|
|
104
|
+
* Validates the intent parameters before submission. If validation fails,
|
|
105
|
+
* throws a ValidationError without making any network request. On success,
|
|
106
|
+
* returns the intent ID.
|
|
107
|
+
*
|
|
108
|
+
* @param params - Intent parameters
|
|
109
|
+
* @param signature - EIP-712 signature from the user's wallet
|
|
110
|
+
* @returns Promise resolving to the intent ID (format: JK-[A-Z0-9]{9})
|
|
111
|
+
* @throws ValidationError if parameters are invalid
|
|
112
|
+
* @throws APIError if the API returns an error
|
|
113
|
+
* @throws NetworkError if the network request fails
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```typescript
|
|
117
|
+
* const intentId = await manager.submit(params, signature);
|
|
118
|
+
* console.log('Intent submitted:', intentId); // "JK-ABC123456"
|
|
119
|
+
* ```
|
|
120
|
+
*
|
|
121
|
+
* **Validates: Requirement 1.2**
|
|
122
|
+
*/
|
|
123
|
+
async submit(params, signature) {
|
|
124
|
+
// Validate parameters before making network request
|
|
125
|
+
const validation = this.validate(params);
|
|
126
|
+
if (!validation.valid) {
|
|
127
|
+
throw new errors_js_1.ValidationError('Invalid intent parameters', validation.errors);
|
|
128
|
+
}
|
|
129
|
+
// Submit to API
|
|
130
|
+
const response = await this.client.post('/api/intents', {
|
|
131
|
+
params,
|
|
132
|
+
signature
|
|
133
|
+
});
|
|
134
|
+
return response.intentId;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Get a single intent by ID
|
|
138
|
+
*
|
|
139
|
+
* Queries the JACK API for the complete intent object including
|
|
140
|
+
* current status, execution steps, and settlement transaction (if settled).
|
|
141
|
+
*
|
|
142
|
+
* @param intentId - The intent ID to query (format: JK-[A-Z0-9]{9})
|
|
143
|
+
* @returns Promise resolving to the complete Intent object
|
|
144
|
+
* @throws APIError if the intent is not found (404) or other API error
|
|
145
|
+
* @throws NetworkError if the network request fails
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* const intent = await manager.get('JK-ABC123456');
|
|
150
|
+
* console.log('Status:', intent.status);
|
|
151
|
+
* console.log('Settlement tx:', intent.settlementTx);
|
|
152
|
+
* ```
|
|
153
|
+
*
|
|
154
|
+
* **Validates: Requirement 1.3**
|
|
155
|
+
*/
|
|
156
|
+
async get(intentId) {
|
|
157
|
+
return this.client.get(`/api/intents/${intentId}`);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* List all intents
|
|
161
|
+
*
|
|
162
|
+
* Queries the JACK API for all intents. The API may implement pagination
|
|
163
|
+
* or filtering in the future, but currently returns all intents.
|
|
164
|
+
*
|
|
165
|
+
* @returns Promise resolving to an array of Intent objects
|
|
166
|
+
* @throws APIError if the API returns an error
|
|
167
|
+
* @throws NetworkError if the network request fails
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```typescript
|
|
171
|
+
* const intents = await manager.list();
|
|
172
|
+
* console.log(`Found ${intents.length} intents`);
|
|
173
|
+
* intents.forEach(intent => {
|
|
174
|
+
* console.log(`${intent.id}: ${intent.status}`);
|
|
175
|
+
* });
|
|
176
|
+
* ```
|
|
177
|
+
*
|
|
178
|
+
* **Validates: Requirement 1.4**
|
|
179
|
+
*/
|
|
180
|
+
async list() {
|
|
181
|
+
return this.client.get('/api/intents');
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
exports.IntentManager = IntentManager;
|
|
185
|
+
//# sourceMappingURL=intents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intents.js","sourceRoot":"","sources":["../../src/intents.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAGH,yDAAkD;AAClD,mDAAuD;AACvD,2CAA8C;AAG9C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAa,aAAa;IACP,MAAM,CAAa;IAEpC;;;;OAIG;IACH,YAAY,MAAkB;QAC5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,YAAY,CACV,MAAoB,EACpB,UAAkB,CAAC,EACnB,oBAAmC,4CAA4C;QAE/E,OAAO,IAAA,+BAAY,EAAC,MAAM,EAAE,OAAO,EAAE,iBAAiB,CAAC,CAAC;IAC1D,CAAC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,QAAQ,CAAC,MAAoB;QAC3B,OAAO,IAAA,oCAAoB,EAAC,MAAM,CAAC,CAAC;IACtC,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,KAAK,CAAC,MAAM,CAAC,MAAoB,EAAE,SAAiB;QAClD,oDAAoD;QACpD,MAAM,UAAU,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACzC,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;YACtB,MAAM,IAAI,2BAAe,CACvB,2BAA2B,EAC3B,UAAU,CAAC,MAAM,CAClB,CAAC;QACJ,CAAC;QAED,gBAAgB;QAChB,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CACrC,cAAc,EACd;YACE,MAAM;YACN,SAAS;SACV,CACF,CAAC;QAEF,OAAO,QAAQ,CAAC,QAAQ,CAAC;IAC3B,CAAC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,KAAK,CAAC,GAAG,CAAC,QAAgB;QACxB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAS,gBAAgB,QAAQ,EAAE,CAAC,CAAC;IAC7D,CAAC;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,KAAK,CAAC,IAAI;QACR,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAW,cAAc,CAAC,CAAC;IACnD,CAAC;CACF;AApKD,sCAoKC"}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* EIP-712 serialization for JACK intents
|
|
4
|
+
*
|
|
5
|
+
* This module provides functions to construct EIP-712 typed data for intent signing.
|
|
6
|
+
* The typed data follows the EIP-712 standard for structured data hashing and signing.
|
|
7
|
+
*
|
|
8
|
+
* Requirements: 1.1, 14.1
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.getTypedData = getTypedData;
|
|
12
|
+
exports.serializeIntentParams = serializeIntentParams;
|
|
13
|
+
exports.parseIntentParams = parseIntentParams;
|
|
14
|
+
/**
|
|
15
|
+
* Get EIP-712 typed data for an intent
|
|
16
|
+
*
|
|
17
|
+
* Constructs a properly formatted EIP-712 TypedData object that can be used
|
|
18
|
+
* with wallet signing methods (e.g., eth_signTypedData_v4). The typed data
|
|
19
|
+
* includes the domain separator, type definitions, and the intent message.
|
|
20
|
+
*
|
|
21
|
+
* @param params - Intent parameters to serialize
|
|
22
|
+
* @param chainId - Chain ID for the domain separator (default: 1 for Ethereum mainnet)
|
|
23
|
+
* @param verifyingContract - Address of the verifying contract
|
|
24
|
+
* @returns EIP-712 TypedData object ready for signing
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* const params = {
|
|
29
|
+
* sourceChain: 'arbitrum',
|
|
30
|
+
* destinationChain: 'base',
|
|
31
|
+
* tokenIn: '0xUSDC...',
|
|
32
|
+
* tokenOut: '0xWETH...',
|
|
33
|
+
* amountIn: '1000000',
|
|
34
|
+
* minAmountOut: '42000000000000000',
|
|
35
|
+
* deadline: Date.now() + 3600000
|
|
36
|
+
* };
|
|
37
|
+
*
|
|
38
|
+
* const typedData = getTypedData(
|
|
39
|
+
* params,
|
|
40
|
+
* 1,
|
|
41
|
+
* '0x1234567890123456789012345678901234567890'
|
|
42
|
+
* );
|
|
43
|
+
*
|
|
44
|
+
* // Sign with wallet
|
|
45
|
+
* const signature = await wallet.signTypedData(typedData);
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* Validates: Requirements 1.1, 14.1
|
|
49
|
+
*/
|
|
50
|
+
function getTypedData(params, chainId = 1, verifyingContract = '0x0000000000000000000000000000000000000000') {
|
|
51
|
+
// Define the EIP-712 domain
|
|
52
|
+
const domain = {
|
|
53
|
+
name: 'JACK',
|
|
54
|
+
version: '1',
|
|
55
|
+
chainId,
|
|
56
|
+
verifyingContract,
|
|
57
|
+
};
|
|
58
|
+
// Define the Intent type structure
|
|
59
|
+
// This must match the on-chain struct definition
|
|
60
|
+
const types = {
|
|
61
|
+
Intent: [
|
|
62
|
+
{ name: 'sourceChain', type: 'string' },
|
|
63
|
+
{ name: 'destinationChain', type: 'string' },
|
|
64
|
+
{ name: 'tokenIn', type: 'string' },
|
|
65
|
+
{ name: 'tokenOut', type: 'string' },
|
|
66
|
+
{ name: 'amountIn', type: 'string' },
|
|
67
|
+
{ name: 'minAmountOut', type: 'string' },
|
|
68
|
+
{ name: 'deadline', type: 'uint256' },
|
|
69
|
+
],
|
|
70
|
+
};
|
|
71
|
+
// Construct the message from intent parameters
|
|
72
|
+
// Only include the fields defined in the Intent type
|
|
73
|
+
const message = {
|
|
74
|
+
sourceChain: params.sourceChain,
|
|
75
|
+
destinationChain: params.destinationChain,
|
|
76
|
+
tokenIn: params.tokenIn,
|
|
77
|
+
tokenOut: params.tokenOut,
|
|
78
|
+
amountIn: params.amountIn,
|
|
79
|
+
minAmountOut: params.minAmountOut,
|
|
80
|
+
deadline: params.deadline,
|
|
81
|
+
};
|
|
82
|
+
// Return the complete TypedData structure
|
|
83
|
+
return {
|
|
84
|
+
domain,
|
|
85
|
+
types,
|
|
86
|
+
message,
|
|
87
|
+
primaryType: 'Intent',
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Serialize intent parameters to a consistent string representation
|
|
92
|
+
*
|
|
93
|
+
* This function is useful for generating cache keys, logging, or debugging.
|
|
94
|
+
* It produces a deterministic string representation of the intent parameters.
|
|
95
|
+
*
|
|
96
|
+
* @param params - Intent parameters to serialize
|
|
97
|
+
* @returns JSON string representation of the parameters
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* const params = { sourceChain: 'arbitrum', ... };
|
|
102
|
+
* const serialized = serializeIntentParams(params);
|
|
103
|
+
* console.log(serialized); // {"sourceChain":"arbitrum",...}
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
function serializeIntentParams(params) {
|
|
107
|
+
// Create a clean object with only the core intent fields
|
|
108
|
+
const cleanParams = {
|
|
109
|
+
sourceChain: params.sourceChain,
|
|
110
|
+
destinationChain: params.destinationChain,
|
|
111
|
+
tokenIn: params.tokenIn,
|
|
112
|
+
tokenOut: params.tokenOut,
|
|
113
|
+
amountIn: params.amountIn,
|
|
114
|
+
minAmountOut: params.minAmountOut,
|
|
115
|
+
deadline: params.deadline,
|
|
116
|
+
};
|
|
117
|
+
// Return deterministic JSON string (sorted keys)
|
|
118
|
+
return JSON.stringify(cleanParams, Object.keys(cleanParams).sort());
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Parse a serialized intent parameters string back to IntentParams
|
|
122
|
+
*
|
|
123
|
+
* This is the inverse of serializeIntentParams(). It parses a JSON string
|
|
124
|
+
* back into an IntentParams object.
|
|
125
|
+
*
|
|
126
|
+
* @param serialized - JSON string representation of intent parameters
|
|
127
|
+
* @returns Parsed IntentParams object
|
|
128
|
+
* @throws Error if the string cannot be parsed or is missing required fields
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* const serialized = '{"sourceChain":"arbitrum",...}';
|
|
133
|
+
* const params = parseIntentParams(serialized);
|
|
134
|
+
* console.log(params.sourceChain); // 'arbitrum'
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
function parseIntentParams(serialized) {
|
|
138
|
+
try {
|
|
139
|
+
const parsed = JSON.parse(serialized);
|
|
140
|
+
// Validate required fields are present
|
|
141
|
+
const requiredFields = [
|
|
142
|
+
'sourceChain',
|
|
143
|
+
'destinationChain',
|
|
144
|
+
'tokenIn',
|
|
145
|
+
'tokenOut',
|
|
146
|
+
'amountIn',
|
|
147
|
+
'minAmountOut',
|
|
148
|
+
'deadline',
|
|
149
|
+
];
|
|
150
|
+
for (const field of requiredFields) {
|
|
151
|
+
if (!(field in parsed)) {
|
|
152
|
+
throw new Error(`Missing required field: ${field}`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return parsed;
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
if (error instanceof Error) {
|
|
159
|
+
throw new Error(`Failed to parse intent parameters: ${error.message}`);
|
|
160
|
+
}
|
|
161
|
+
throw new Error('Failed to parse intent parameters: Unknown error');
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=serialization.js.map
|
|
@@ -0,0 +1 @@
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3B,MAAM,IAAI,KAAK,CAAC,sCAAsC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACzE,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;IACtE,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Core TypeScript types for the JACK SDK
|
|
4
|
+
*
|
|
5
|
+
* This module exports all interfaces, types, and enums used in the public API.
|
|
6
|
+
* Requirements: 1.5, 3.4, 4.3, 5.1
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ExecutionStatus = void 0;
|
|
10
|
+
/**
|
|
11
|
+
* Execution status of an intent
|
|
12
|
+
* Requirement 1.5
|
|
13
|
+
*/
|
|
14
|
+
var ExecutionStatus;
|
|
15
|
+
(function (ExecutionStatus) {
|
|
16
|
+
/** Intent created but not yet quoted */
|
|
17
|
+
ExecutionStatus["CREATED"] = "CREATED";
|
|
18
|
+
/** Solver quotes received */
|
|
19
|
+
ExecutionStatus["QUOTED"] = "QUOTED";
|
|
20
|
+
/** Intent is being executed */
|
|
21
|
+
ExecutionStatus["EXECUTING"] = "EXECUTING";
|
|
22
|
+
/** Settlement transaction is being processed */
|
|
23
|
+
ExecutionStatus["SETTLING"] = "SETTLING";
|
|
24
|
+
/** Intent successfully settled on-chain */
|
|
25
|
+
ExecutionStatus["SETTLED"] = "SETTLED";
|
|
26
|
+
/** Intent execution was aborted */
|
|
27
|
+
ExecutionStatus["ABORTED"] = "ABORTED";
|
|
28
|
+
/** Intent expired before completion */
|
|
29
|
+
ExecutionStatus["EXPIRED"] = "EXPIRED";
|
|
30
|
+
})(ExecutionStatus || (exports.ExecutionStatus = ExecutionStatus = {}));
|
|
31
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AA6BH;;;GAGG;AACH,IAAY,eAeX;AAfD,WAAY,eAAe;IACzB,wCAAwC;IACxC,sCAAmB,CAAA;IACnB,6BAA6B;IAC7B,oCAAiB,CAAA;IACjB,+BAA+B;IAC/B,0CAAuB,CAAA;IACvB,gDAAgD;IAChD,wCAAqB,CAAA;IACrB,2CAA2C;IAC3C,sCAAmB,CAAA;IACnB,mCAAmC;IACnC,sCAAmB,CAAA;IACnB,uCAAuC;IACvC,sCAAmB,CAAA;AACrB,CAAC,EAfW,eAAe,+BAAf,eAAe,QAe1B"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Input validation helpers for the JACK SDK
|
|
4
|
+
*
|
|
5
|
+
* This module provides validation functions for intent parameters and other inputs.
|
|
6
|
+
* Requirements: 5.4, 8.5
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.validateIntentParams = validateIntentParams;
|
|
10
|
+
/**
|
|
11
|
+
* Validates that a string is a valid Ethereum address format
|
|
12
|
+
* @param address - The address string to validate
|
|
13
|
+
* @returns true if the address is valid, false otherwise
|
|
14
|
+
*/
|
|
15
|
+
function isValidAddress(address) {
|
|
16
|
+
// Check if it's a valid hex string starting with 0x and has 40 hex characters
|
|
17
|
+
return /^0x[a-fA-F0-9]{40}$/.test(address);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Validates that a string represents a positive number
|
|
21
|
+
* @param value - The string value to validate
|
|
22
|
+
* @returns true if the value is a positive number, false otherwise
|
|
23
|
+
*/
|
|
24
|
+
function isPositiveAmount(value) {
|
|
25
|
+
try {
|
|
26
|
+
const num = BigInt(value);
|
|
27
|
+
return num > 0n;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Validates intent parameters before submission
|
|
35
|
+
*
|
|
36
|
+
* This function checks:
|
|
37
|
+
* - All required fields are present and non-empty
|
|
38
|
+
* - Amounts (amountIn, minAmountOut) are positive numbers
|
|
39
|
+
* - Deadline is in the future
|
|
40
|
+
* - Token addresses are valid Ethereum address format
|
|
41
|
+
*
|
|
42
|
+
* @param params - The intent parameters to validate
|
|
43
|
+
* @returns ValidationResult with valid flag and array of error messages
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* const result = validateIntentParams({
|
|
48
|
+
* sourceChain: 'arbitrum',
|
|
49
|
+
* destinationChain: 'base',
|
|
50
|
+
* tokenIn: '0x...',
|
|
51
|
+
* tokenOut: '0x...',
|
|
52
|
+
* amountIn: '1000000',
|
|
53
|
+
* minAmountOut: '950000',
|
|
54
|
+
* deadline: Date.now() + 3600000
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* if (!result.valid) {
|
|
58
|
+
* console.error('Validation errors:', result.errors);
|
|
59
|
+
* }
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* **Validates: Requirements 5.4, 8.5**
|
|
63
|
+
*/
|
|
64
|
+
function validateIntentParams(params) {
|
|
65
|
+
const errors = [];
|
|
66
|
+
// Validate required fields are present and non-empty
|
|
67
|
+
if (!params.sourceChain || params.sourceChain.trim() === '') {
|
|
68
|
+
errors.push('sourceChain is required and must not be empty');
|
|
69
|
+
}
|
|
70
|
+
if (!params.destinationChain || params.destinationChain.trim() === '') {
|
|
71
|
+
errors.push('destinationChain is required and must not be empty');
|
|
72
|
+
}
|
|
73
|
+
if (!params.tokenIn || params.tokenIn.trim() === '') {
|
|
74
|
+
errors.push('tokenIn is required and must not be empty');
|
|
75
|
+
}
|
|
76
|
+
if (!params.tokenOut || params.tokenOut.trim() === '') {
|
|
77
|
+
errors.push('tokenOut is required and must not be empty');
|
|
78
|
+
}
|
|
79
|
+
if (!params.amountIn || params.amountIn.trim() === '') {
|
|
80
|
+
errors.push('amountIn is required and must not be empty');
|
|
81
|
+
}
|
|
82
|
+
if (!params.minAmountOut || params.minAmountOut.trim() === '') {
|
|
83
|
+
errors.push('minAmountOut is required and must not be empty');
|
|
84
|
+
}
|
|
85
|
+
if (params.deadline === undefined || params.deadline === null) {
|
|
86
|
+
errors.push('deadline is required');
|
|
87
|
+
}
|
|
88
|
+
// Validate amounts are positive
|
|
89
|
+
if (params.amountIn && !isPositiveAmount(params.amountIn)) {
|
|
90
|
+
errors.push('amountIn must be a positive number');
|
|
91
|
+
}
|
|
92
|
+
if (params.minAmountOut && !isPositiveAmount(params.minAmountOut)) {
|
|
93
|
+
errors.push('minAmountOut must be a positive number');
|
|
94
|
+
}
|
|
95
|
+
// Validate deadline is in the future
|
|
96
|
+
if (typeof params.deadline === 'number') {
|
|
97
|
+
const now = Date.now();
|
|
98
|
+
if (params.deadline <= now) {
|
|
99
|
+
errors.push('deadline must be in the future');
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// Validate addresses are valid format
|
|
103
|
+
if (params.tokenIn && !isValidAddress(params.tokenIn)) {
|
|
104
|
+
errors.push('tokenIn must be a valid Ethereum address (0x followed by 40 hex characters)');
|
|
105
|
+
}
|
|
106
|
+
if (params.tokenOut && !isValidAddress(params.tokenOut)) {
|
|
107
|
+
errors.push('tokenOut must be a valid Ethereum address (0x followed by 40 hex characters)');
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
valid: errors.length === 0,
|
|
111
|
+
errors
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/validation.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AA2DH,oDA8DC;AArHD;;;;GAIG;AACH,SAAS,cAAc,CAAC,OAAe;IACrC,8EAA8E;IAC9E,OAAO,qBAAqB,CAAC,IAAI,CAAC,OAAO,C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