@pioneer-platform/pioneer-coins 9.3.0 → 9.3.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.
- package/lib/thorchain.d.ts +1 -0
- package/lib/thorchain.js +71 -0
- package/package.json +1 -1
package/lib/thorchain.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ interface BaseTx {
|
|
|
3
3
|
asset: string;
|
|
4
4
|
destAddr: string;
|
|
5
5
|
}
|
|
6
|
+
export declare function validateMemo(memo: string): boolean;
|
|
6
7
|
export declare function normalizeSwapMemo(memo: string): string;
|
|
7
8
|
export declare function createMemo(tx: BaseTx): string;
|
|
8
9
|
export declare function parseMemo(memo: string): BaseTx;
|
package/lib/thorchain.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
----------------------
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.validateMemo = validateMemo;
|
|
7
8
|
exports.normalizeSwapMemo = normalizeSwapMemo;
|
|
8
9
|
exports.createMemo = createMemo;
|
|
9
10
|
exports.parseMemo = parseMemo;
|
|
@@ -199,6 +200,76 @@ function buildNoOpMemo(tx) {
|
|
|
199
200
|
return truncateMemo(parts.filter(function (part) { return part; }).join(':'));
|
|
200
201
|
}
|
|
201
202
|
// Main function to create a memo from any transaction type
|
|
203
|
+
// Validate a THORChain memo - returns true if valid, false otherwise
|
|
204
|
+
function validateMemo(memo) {
|
|
205
|
+
try {
|
|
206
|
+
if (!memo || memo.trim() === '')
|
|
207
|
+
return false;
|
|
208
|
+
var trimmed = memo.trim();
|
|
209
|
+
// Check basic format
|
|
210
|
+
if (!trimmed.startsWith('=:') && !trimmed.startsWith('SWAP:') &&
|
|
211
|
+
!trimmed.startsWith('DEPOSIT:') && !trimmed.startsWith('WITHDRAW:') &&
|
|
212
|
+
!trimmed.startsWith('LOAN+:') && !trimmed.startsWith('LOAN-:') &&
|
|
213
|
+
!trimmed.startsWith('ADD:') && !trimmed.startsWith('WD:') &&
|
|
214
|
+
!trimmed.startsWith('BOND:') && !trimmed.startsWith('UNBOND:') &&
|
|
215
|
+
!trimmed.startsWith('MIGRATE:') && !trimmed.startsWith('*NOOP*:')) {
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
// For swap memos, validate format more strictly
|
|
219
|
+
if (trimmed.startsWith('=:') || trimmed.startsWith('SWAP:')) {
|
|
220
|
+
var prefix = trimmed.startsWith('=:') ? '=:' : 'SWAP:';
|
|
221
|
+
var parts = trimmed.slice(prefix.length).split(':');
|
|
222
|
+
// Must have at least asset and destination
|
|
223
|
+
if (parts.length < 2)
|
|
224
|
+
return false;
|
|
225
|
+
// Check asset format (must be CHAIN.SYMBOL)
|
|
226
|
+
var asset = parts[0];
|
|
227
|
+
// Don't allow single-letter shorthands in validation
|
|
228
|
+
if (asset.length === 1)
|
|
229
|
+
return false;
|
|
230
|
+
var assetParts = asset.split('.');
|
|
231
|
+
if (assetParts.length !== 2)
|
|
232
|
+
return false;
|
|
233
|
+
var chain = assetParts[0], symbol = assetParts[1];
|
|
234
|
+
// Must be uppercase alphanumeric (symbol can have dash)
|
|
235
|
+
if (!/^[A-Z0-9]+$/.test(chain))
|
|
236
|
+
return false;
|
|
237
|
+
if (!/^[A-Z0-9\-]+$/.test(symbol))
|
|
238
|
+
return false;
|
|
239
|
+
// Must have destination
|
|
240
|
+
var destination = parts[1];
|
|
241
|
+
if (!destination || destination.trim() === '')
|
|
242
|
+
return false;
|
|
243
|
+
// Check optional limit/stream format
|
|
244
|
+
if (parts[2] && parts[2] !== '') {
|
|
245
|
+
var limitStream = parts[2].split('/');
|
|
246
|
+
// Limit must be integer if present
|
|
247
|
+
if (limitStream[0] && !/^\d+$/.test(limitStream[0]))
|
|
248
|
+
return false;
|
|
249
|
+
// Stream must be integer if present
|
|
250
|
+
if (limitStream[1] && !/^\d+$/.test(limitStream[1]))
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
// Check affiliate BP if present
|
|
254
|
+
if (parts[4] && parts[4] !== '') {
|
|
255
|
+
if (!/^\d+$/.test(parts[4]))
|
|
256
|
+
return false;
|
|
257
|
+
var bp = parseInt(parts[4]);
|
|
258
|
+
if (bp < 0 || bp > 1000)
|
|
259
|
+
return false;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
// Check memo length
|
|
263
|
+
if (Buffer.from(trimmed, 'utf-8').length > 250)
|
|
264
|
+
return false;
|
|
265
|
+
// If we made it here, memo is valid
|
|
266
|
+
return true;
|
|
267
|
+
}
|
|
268
|
+
catch (error) {
|
|
269
|
+
// Any error means invalid memo
|
|
270
|
+
return false;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
202
273
|
// Normalize and validate swap memo
|
|
203
274
|
function normalizeSwapMemo(memo) {
|
|
204
275
|
// Ensure "=:" prefix and fully qualified asset
|