UNPKG

n8n-nodes-wax

Version:

n8n Community Node Package for the WAX Blockchain

188 lines 7.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MAX_PAGINATION_ITERATIONS = void 0; exports.getCredentials = getCredentials; exports.validateEndpoint = validateEndpoint; exports.buildUrl = buildUrl; exports.requireAccountName = requireAccountName; exports.requireAmount = requireAmount; exports.requirePrecision = requirePrecision; exports.requireSymbol = requireSymbol; exports.requireAssetIds = requireAssetIds; exports.normalizeMemo = normalizeMemo; exports.redactSensitive = redactSensitive; exports.safeError = safeError; const n8n_workflow_1 = require("n8n-workflow"); async function getCredentials(context, errorMessage) { try { return await context.getCredentials('waxPrivateKeyApi'); } catch (error) { throw new n8n_workflow_1.NodeOperationError(context.getNode(), errorMessage || `Credentials required for this operation.`); } } const BLOCKED_HOSTS = new Set([ 'metadata.google.internal', 'metadata', 'metadata.aws', 'instance-data', 'localhost', ]); function stripIpv6Brackets(host) { return host.replace(/^\[|\]$/g, ''); } function isBareIp(host) { const h = stripIpv6Brackets(host); if (/^\d+\.\d+\.\d+\.\d+$/.test(h)) return true; if (/^0x[\da-f.]+$/i.test(h)) return true; if (/^\d{8,}$/.test(h)) return true; if (h.includes(':') && /^[\da-f:%.]+$/i.test(h)) return true; return false; } function validateEndpoint(context, raw, options = {}) { const node = context.getNode(); if (!raw || typeof raw !== 'string') { throw new n8n_workflow_1.NodeOperationError(node, 'API Endpoint is required'); } const trimmed = raw.trim(); let url; try { url = new URL(trimmed); } catch { throw new n8n_workflow_1.NodeOperationError(node, `Invalid API Endpoint URL`); } if (url.protocol !== 'https:' && url.protocol !== 'http:') { throw new n8n_workflow_1.NodeOperationError(node, `API Endpoint must use http or https`); } if (options.signing && url.protocol !== 'https:') { throw new n8n_workflow_1.NodeOperationError(node, 'API Endpoint must use https for signing operations'); } if (url.username || url.password) { throw new n8n_workflow_1.NodeOperationError(node, 'API Endpoint must not embed credentials'); } const host = url.hostname.toLowerCase(); if (!host) { throw new n8n_workflow_1.NodeOperationError(node, 'API Endpoint must include a host'); } if (BLOCKED_HOSTS.has(host)) { throw new n8n_workflow_1.NodeOperationError(node, `API Endpoint host not allowed`); } if (isBareIp(host)) { throw new n8n_workflow_1.NodeOperationError(node, `API Endpoint must use a hostname, not an IP address`); } return url.toString().replace(/\/+$/, ''); } function buildUrl(endpoint, path) { const base = new URL(endpoint); const basePath = base.pathname.endsWith('/') ? base.pathname : `${base.pathname}/`; const rel = path.startsWith('/') ? path.slice(1) : path; return new URL(basePath + rel, base).toString(); } exports.MAX_PAGINATION_ITERATIONS = 5000; const ACCOUNT_NAME_RE = /^[a-z1-5.]+$/; const SYMBOL_RE = /^[A-Z]{1,7}$/; const ASSET_ID_RE = /^\d+$/; const MEMO_MAX_BYTES = 256; function requireAccountName(context, raw, field) { const node = context.getNode(); if (typeof raw !== 'string' || raw.trim() === '') { throw new n8n_workflow_1.NodeOperationError(node, `${field} is required`); } const name = raw.trim().toLowerCase(); if (name.length > 13) { throw new n8n_workflow_1.NodeOperationError(node, `${field} must be at most 13 characters`); } if (!ACCOUNT_NAME_RE.test(name)) { throw new n8n_workflow_1.NodeOperationError(node, `${field} must contain only lowercase letters a-z, digits 1-5, and dots`); } if (!/[a-z1-5]/.test(name)) { throw new n8n_workflow_1.NodeOperationError(node, `${field} must contain at least one letter or digit`); } return name; } function requireAmount(context, raw, field) { const node = context.getNode(); const n = typeof raw === 'number' ? raw : Number(raw); if (!Number.isFinite(n)) { throw new n8n_workflow_1.NodeOperationError(node, `${field} must be a finite number`); } if (n <= 0) { throw new n8n_workflow_1.NodeOperationError(node, `${field} must be greater than zero`); } return n; } function requirePrecision(context, raw, field, fallback = 8) { const node = context.getNode(); if (raw === undefined || raw === null || raw === '') return fallback; const n = typeof raw === 'number' ? raw : Number(raw); if (!Number.isInteger(n) || n < 0 || n > 18) { throw new n8n_workflow_1.NodeOperationError(node, `${field} must be an integer between 0 and 18`); } return n; } function requireSymbol(context, raw, field) { const node = context.getNode(); if (typeof raw !== 'string' || raw.trim() === '') { throw new n8n_workflow_1.NodeOperationError(node, `${field} is required`); } const sym = raw.trim().toUpperCase(); if (!SYMBOL_RE.test(sym)) { throw new n8n_workflow_1.NodeOperationError(node, `${field} must be 1-7 uppercase letters`); } return sym; } function requireAssetIds(context, raw, field) { const node = context.getNode(); if (typeof raw !== 'string' || raw.trim() === '') { throw new n8n_workflow_1.NodeOperationError(node, `${field} is required`); } const ids = raw.split(',').map((id) => id.trim()).filter((id) => id !== ''); if (ids.length === 0) { throw new n8n_workflow_1.NodeOperationError(node, `${field} must contain at least one ID`); } for (const id of ids) { if (!ASSET_ID_RE.test(id)) { throw new n8n_workflow_1.NodeOperationError(node, `${field} must be a comma-separated list of numeric IDs`); } } return ids; } function normalizeMemo(context, raw, field) { const node = context.getNode(); const memo = typeof raw === 'string' ? raw : ''; if (Buffer.byteLength(memo, 'utf8') > MEMO_MAX_BYTES) { throw new n8n_workflow_1.NodeOperationError(node, `${field} must be ${MEMO_MAX_BYTES} bytes or fewer`); } return memo; } const REDACT_PATTERNS = [ /\b5[1-9A-HJ-NP-Za-km-z]{50}\b/g, /\bPVT_[A-Z0-9]+_[1-9A-HJ-NP-Za-km-z]+/g, /\bEOS[1-9A-HJ-NP-Za-km-z]{50}\b/g, /\bPUB_[A-Z0-9]+_[1-9A-HJ-NP-Za-km-z]+/g, /\bSIG_[A-Z0-9]+_[1-9A-HJ-NP-Za-km-z]+/g, /\b[a-f0-9]{64,}\b/gi, ]; function redactSensitive(input) { let out = input; for (const re of REDACT_PATTERNS) { out = out.replace(re, '[REDACTED]'); } return out; } function safeError(error) { if (error instanceof Error) { return { message: redactSensitive(error.message) }; } if (typeof error === 'string') { return { message: redactSensitive(error) }; } return { message: 'Unknown error' }; } //# sourceMappingURL=util.js.map