first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled

This commit is contained in:
2026-03-17 16:22:57 +03:30
commit 3d5eaf9445
15349 changed files with 2847338 additions and 0 deletions
@@ -0,0 +1,564 @@
import type { BinaryToTextEncoding } from 'crypto';
import { createHash, createHmac, createSign, getHashes, randomBytes } from 'crypto';
import set from 'lodash/set';
import type {
IExecuteFunctions,
INodeExecutionData,
INodeType,
INodeTypeBaseDescription,
INodeTypeDescription,
JsonObject,
} from 'n8n-workflow';
import { deepCopy, BINARY_ENCODING, NodeConnectionTypes } from 'n8n-workflow';
import { pipeline } from 'stream/promises';
import { v4 as uuid } from 'uuid';
const unsupportedAlgorithms = [
'RSA-MD4',
'RSA-MDC2',
'md4',
'md4WithRSAEncryption',
'mdc2',
'mdc2WithRSA',
];
const supportedAlgorithms = getHashes()
.filter((algorithm) => !unsupportedAlgorithms.includes(algorithm))
.map((algorithm) => ({ name: algorithm, value: algorithm }));
const versionDescription: INodeTypeDescription = {
displayName: 'Crypto',
name: 'crypto',
icon: 'fa:key',
iconColor: 'green',
group: ['transform'],
version: 1,
subtitle: '={{$parameter["action"]}}',
description: 'Provide cryptographic utilities',
defaults: {
name: 'Crypto',
color: '#408000',
},
usableAsTool: true,
inputs: [NodeConnectionTypes.Main],
outputs: [NodeConnectionTypes.Main],
properties: [
{
displayName: 'Action',
name: 'action',
type: 'options',
options: [
{
name: 'Generate',
description: 'Generate random string',
value: 'generate',
action: 'Generate random string',
},
{
name: 'Hash',
description: 'Hash a text or file in a specified format',
value: 'hash',
action: 'Hash a text or file in a specified format',
},
{
name: 'Hmac',
description: 'Hmac a text or file in a specified format',
value: 'hmac',
action: 'HMAC a text or file in a specified format',
},
{
name: 'Sign',
description: 'Sign a string using a private key',
value: 'sign',
action: 'Sign a string using a private key',
},
],
default: 'hash',
},
{
displayName: 'Binary File',
name: 'binaryData',
type: 'boolean',
default: false,
required: true,
displayOptions: {
show: {
action: ['hash', 'hmac'],
},
},
description: 'Whether the data to hashed should be taken from binary field',
},
{
displayName: 'Binary Property Name',
name: 'binaryPropertyName',
displayOptions: {
show: {
action: ['hash', 'hmac'],
binaryData: [true],
},
},
type: 'string',
default: 'data',
description: 'Name of the binary property which contains the input data',
required: true,
},
{
displayName: 'Type',
name: 'type',
displayOptions: {
show: {
action: ['hash'],
},
},
type: 'options',
options: [
{
name: 'MD5',
value: 'MD5',
},
{
name: 'SHA256',
value: 'SHA256',
},
{
name: 'SHA3-256',
value: 'SHA3-256',
},
{
name: 'SHA3-384',
value: 'SHA3-384',
},
{
name: 'SHA3-512',
value: 'SHA3-512',
},
{
name: 'SHA384',
value: 'SHA384',
},
{
name: 'SHA512',
value: 'SHA512',
},
],
default: 'MD5',
description: 'The hash type to use',
required: true,
},
{
displayName: 'Value',
name: 'value',
displayOptions: {
show: {
action: ['hash'],
binaryData: [false],
},
},
type: 'string',
default: '',
description: 'The value that should be hashed',
required: true,
},
{
displayName: 'Property Name',
name: 'dataPropertyName',
type: 'string',
default: 'data',
required: true,
displayOptions: {
show: {
action: ['hash'],
},
},
description: 'Name of the property to which to write the hash',
},
{
displayName: 'Encoding',
name: 'encoding',
displayOptions: {
show: {
action: ['hash'],
},
},
type: 'options',
options: [
{
name: 'BASE64',
value: 'base64',
},
{
name: 'HEX',
value: 'hex',
},
],
default: 'hex',
required: true,
},
{
displayName: 'Type',
name: 'type',
displayOptions: {
show: {
action: ['hmac'],
},
},
type: 'options',
options: [
{
name: 'MD5',
value: 'MD5',
},
{
name: 'SHA256',
value: 'SHA256',
},
{
name: 'SHA3-256',
value: 'SHA3-256',
},
{
name: 'SHA3-384',
value: 'SHA3-384',
},
{
name: 'SHA3-512',
value: 'SHA3-512',
},
{
name: 'SHA384',
value: 'SHA384',
},
{
name: 'SHA512',
value: 'SHA512',
},
],
default: 'MD5',
description: 'The hash type to use',
required: true,
},
{
displayName: 'Value',
name: 'value',
displayOptions: {
show: {
action: ['hmac'],
binaryData: [false],
},
},
type: 'string',
default: '',
description: 'The value of which the hmac should be created',
required: true,
},
{
displayName: 'Property Name',
name: 'dataPropertyName',
type: 'string',
default: 'data',
required: true,
displayOptions: {
show: {
action: ['hmac'],
},
},
description: 'Name of the property to which to write the hmac',
},
{
displayName: 'Secret',
name: 'secret',
displayOptions: {
show: {
action: ['hmac'],
},
},
type: 'string',
typeOptions: { password: true },
default: '',
required: true,
description: 'Secret used for Hmac',
},
{
displayName: 'Encoding',
name: 'encoding',
displayOptions: {
show: {
action: ['hmac'],
},
},
type: 'options',
options: [
{
name: 'BASE64',
value: 'base64',
},
{
name: 'HEX',
value: 'hex',
},
],
default: 'hex',
required: true,
},
{
displayName: 'Value',
name: 'value',
displayOptions: {
show: {
action: ['sign'],
},
},
type: 'string',
default: '',
description: 'The value that should be signed',
required: true,
},
{
displayName: 'Property Name',
name: 'dataPropertyName',
type: 'string',
default: 'data',
required: true,
displayOptions: {
show: {
action: ['sign'],
},
},
description: 'Name of the property to which to write the signed value',
},
{
displayName: 'Algorithm Name or ID',
name: 'algorithm',
displayOptions: {
show: {
action: ['sign'],
},
},
type: 'options',
description:
'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>',
options: supportedAlgorithms,
default: '',
required: true,
},
{
displayName: 'Encoding',
name: 'encoding',
displayOptions: {
show: {
action: ['sign'],
},
},
type: 'options',
options: [
{
name: 'BASE64',
value: 'base64',
},
{
name: 'HEX',
value: 'hex',
},
],
default: 'hex',
required: true,
},
{
displayName: 'Private Key',
name: 'privateKey',
displayOptions: {
show: {
action: ['sign'],
},
},
type: 'string',
typeOptions: { password: true },
description: 'Private key to use when signing the string',
default: '',
required: true,
},
{
displayName: 'Property Name',
name: 'dataPropertyName',
type: 'string',
default: 'data',
required: true,
displayOptions: {
show: {
action: ['generate'],
},
},
description: 'Name of the property to which to write the random string',
},
{
displayName: 'Type',
name: 'encodingType',
displayOptions: {
show: {
action: ['generate'],
},
},
type: 'options',
options: [
{
name: 'ASCII',
value: 'ascii',
},
{
name: 'BASE64',
value: 'base64',
},
{
name: 'HEX',
value: 'hex',
},
{
name: 'UUID',
value: 'uuid',
},
],
default: 'uuid',
description: 'Encoding that will be used to generate string',
required: true,
},
{
displayName: 'Length',
name: 'stringLength',
type: 'number',
default: 32,
description: 'Length of the generated string',
displayOptions: {
show: {
action: ['generate'],
encodingType: ['ascii', 'base64', 'hex'],
},
},
},
],
};
export class CryptoV1 implements INodeType {
description: INodeTypeDescription;
constructor(baseDescription: INodeTypeBaseDescription) {
this.description = {
...baseDescription,
...versionDescription,
};
}
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
const returnData: INodeExecutionData[] = [];
const length = items.length;
const action = this.getNodeParameter('action', 0) as string;
let item: INodeExecutionData;
for (let i = 0; i < length; i++) {
try {
item = items[i];
const dataPropertyName = this.getNodeParameter('dataPropertyName', i);
const value = this.getNodeParameter('value', i, '') as string;
let newValue;
let binaryProcessed = false;
if (action === 'generate') {
const encodingType = this.getNodeParameter('encodingType', i);
if (encodingType === 'uuid') {
newValue = uuid();
} else {
const stringLength = this.getNodeParameter('stringLength', i) as number;
if (encodingType === 'base64') {
newValue = randomBytes(stringLength)
.toString(encodingType as BufferEncoding)
.replace(/\W/g, '')
.slice(0, stringLength);
} else {
newValue = randomBytes(stringLength)
.toString(encodingType as BufferEncoding)
.slice(0, stringLength);
}
}
}
if (action === 'hash' || action === 'hmac') {
const type = this.getNodeParameter('type', i) as string;
const encoding = this.getNodeParameter('encoding', i) as BinaryToTextEncoding;
const hashOrHmac =
action === 'hash'
? createHash(type)
: createHmac(type, this.getNodeParameter('secret', i) as string);
if (this.getNodeParameter('binaryData', i)) {
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
if (binaryData.id) {
const binaryStream = await this.helpers.getBinaryStream(binaryData.id);
hashOrHmac.setEncoding(encoding);
await pipeline(binaryStream, hashOrHmac);
newValue = hashOrHmac.read();
} else {
newValue = hashOrHmac
.update(Buffer.from(binaryData.data, BINARY_ENCODING))
.digest(encoding);
}
binaryProcessed = true;
} else {
newValue = hashOrHmac.update(value).digest(encoding);
}
}
if (action === 'sign') {
const algorithm = this.getNodeParameter('algorithm', i) as string;
const encoding = this.getNodeParameter('encoding', i) as BinaryToTextEncoding;
const privateKey = this.getNodeParameter('privateKey', i) as string;
const sign = createSign(algorithm);
sign.write(value);
sign.end();
newValue = sign.sign(privateKey, encoding);
}
let newItem: INodeExecutionData;
if (dataPropertyName.includes('.')) {
// Uses dot notation so copy all data
newItem = {
json: deepCopy(item.json),
pairedItem: {
item: i,
},
};
} else {
// Does not use dot notation so shallow copy is enough
newItem = {
json: { ...item.json },
pairedItem: {
item: i,
},
};
}
if (item.binary !== undefined && !binaryProcessed) {
newItem.binary = item.binary;
}
set(newItem, ['json', dataPropertyName], newValue);
returnData.push(newItem);
} catch (error) {
if (this.continueOnFail()) {
returnData.push({
json: {
error: (error as JsonObject).message,
},
pairedItem: {
item: i,
},
});
continue;
}
throw error;
}
}
return [returnData];
}
}
@@ -0,0 +1,45 @@
import { NodeTestHarness } from '@nodes-testing/node-test-harness';
import type fs from 'fs';
import fsPromises, { type FileHandle } from 'fs/promises';
import { Readable } from 'stream';
describe('Test Crypto Node', () => {
jest.mock('fast-glob', () => async () => ['/test/binary.data']);
jest.mock('fs/promises');
fsPromises.access = async () => {};
fsPromises.stat = jest.fn(async (path: fs.PathLike) => {
if (path === '/test/binary.data') {
return {
isFile: () => true,
dev: 123456,
ino: 654321,
} as fs.Stats;
}
throw Object.assign(new Error('File not found'), { code: 'ENOENT' });
}) as unknown as typeof fsPromises.stat;
fsPromises.open = jest.fn(async (path: fs.PathLike) => {
if (path === '/test/binary.data') {
return {
close: async () => {},
// eslint-disable-next-line @typescript-eslint/require-await
stat: async () =>
({
isFile: () => true,
dev: 123456,
ino: 654321,
}) as fs.Stats,
createReadStream: () => {
const stream = Readable.from(Buffer.from('test')) as fs.ReadStream;
// Emit 'open' event asynchronously to match real fs.ReadStream behavior
setImmediate(() => stream.emit('open'));
return stream;
},
} as FileHandle;
}
throw Object.assign(new Error('File not found'), { code: 'ENOENT' });
}) as unknown as typeof fsPromises.open;
const realpathSpy = jest.spyOn(fsPromises, 'realpath');
realpathSpy.mockImplementation(async (path) => path as string);
new NodeTestHarness().setupTests();
});
@@ -0,0 +1,277 @@
{
"name": "Crypto Test",
"nodes": [
{
"parameters": {},
"id": "78f64c0f-d6a7-47fb-920d-5471fcd8caa1",
"name": "When clicking \"Execute Workflow\"",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [-480, 460]
},
{
"parameters": {
"value": "test"
},
"id": "90831322-8a73-40ac-ae52-84a6504d3d95",
"name": "Crypto Hash into Hex",
"type": "n8n-nodes-base.crypto",
"typeVersion": 1,
"position": [360, 660]
},
{
"parameters": {
"value": "test"
},
"id": "9836f128-6798-498e-8752-ba447218ce21",
"name": "Crypto Hash into MD5",
"type": "n8n-nodes-base.crypto",
"typeVersion": 1,
"position": [360, 500]
},
{
"parameters": {
"action": "sign",
"value": "test",
"algorithm": "RSA-MD5",
"encoding": "base64",
"privateKey": "-----BEGIN RSA PRIVATE KEY-----\nMIIBOgIBAAJBAKj34GkxFhD90vcNLYLInFEX6Ppy1tPf9Cnzj4p4WGeKLs1Pt8Qu\nKUpRKfFLfRYC9AIKjbJTWit+CqvjWYzvQwECAwEAAQJAIJLixBy2qpFoS4DSmoEm\no3qGy0t6z09AIJtH+5OeRV1be+N4cDYJKffGzDa88vQENZiRm0GRq6a+HPGQMd2k\nTQIhAKMSvzIBnni7ot/OSie2TmJLY4SwTQAevXysE2RbFDYdAiEBCUEaRQnMnbp7\n9mxDXDf6AU0cN/RPBjb9qSHDcWZHGzUCIG2Es59z8ugGrDY+pxLQnwfotadxd+Uy\nv/Ow5T0q5gIJAiEAyS4RaI9YG8EWx/2w0T67ZUVAw8eOMB6BIUg0Xcu+3okCIBOs\n/5OiPgoTdSy7bcF9IGpSE8ZgGKzgYQVZeN97YE00\n-----END RSA PRIVATE KEY-----"
},
"id": "4ec3781a-433d-4b68-bc94-3fbe6ed55a0e",
"name": "Crypto Sign data with RSA-MD5",
"type": "n8n-nodes-base.crypto",
"typeVersion": 1,
"position": [80, 860]
},
{
"parameters": {
"action": "hmac",
"value": "test",
"secret": "-----BEGIN RSA PRIVATE KEY-----|MIIBOgIBAAJBAKj34GkxFhD90vcNLYLInFEX6Ppy1tPf9Cnzj4p4WGeKLs1Pt8QuKUpRKfFLfRYC9AIKjbJTWit+CqvjWYzvQwECAwEAAQJAIJLixBy2qpFoS4DSmoEmo3qGy0t6z09AIJtH+5OeRV1be+N4cDYJKffGzDa88vQENZiRm0GRq6a+HPGQMd2kTQIhAKMSvzIBnni7ot/OSie2TmJLY4SwTQAevXysE2RbFDYdAiEBCUEaRQnMnbp79mxDXDf6AU0cN/RPBjb9qSHDcWZHGzUCIG2Es59z8ugGrDY+pxLQnwfotadxd+Uyv/Ow5T0q5gIJAiEAyS4RaI9YG8EWx/2w0T67ZUVAw8eOMB6BIUg0Xcu+3okCIBOs/5OiPgoTdSy7bcF9IGpSE8ZgGKzgYQVZeN97YE00-----END RSA PRIVATE KEY-----",
"encoding": "base64"
},
"id": "797ba0d9-28e0-4494-bafd-d0603e85c303",
"name": "Crypto Hmac data with MD5",
"type": "n8n-nodes-base.crypto",
"typeVersion": 1,
"position": [360, 320]
},
{
"parameters": {
"action": "generate"
},
"id": "a6682d88-0842-4884-9869-220597ac3d2a",
"name": "Crypto Generate UUID",
"type": "n8n-nodes-base.crypto",
"typeVersion": 1,
"position": [-160, 1060]
},
{
"parameters": {
"conditions": {
"string": [
{
"value1": "={{ $json.data }}",
"operation": "regex",
"value2": "^[0-9a-fA-F]{8}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{12}$"
}
]
}
},
"id": "89297cfb-e119-45b8-87b4-021a8272534b",
"name": "IF",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [80, 1060]
},
{
"parameters": {},
"id": "1954d932-2878-403d-ad16-373585dbe9cd",
"name": "No Operation, do nothing",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [420, 1040]
},
{
"parameters": {
"errorMessage": "Not a valid uuid"
},
"id": "b1154e93-9d39-40c6-8ca6-aadc8103cfbd",
"name": "Stop and Error",
"type": "n8n-nodes-base.stopAndError",
"typeVersion": 1,
"position": [260, 1180]
},
{
"parameters": {
"fileSelector": "/test/binary.data"
},
"id": "09bbc611-c2ca-4750-94a7-d1bb4fc53a57",
"name": "Read Binary Files",
"type": "n8n-nodes-base.readBinaryFiles",
"typeVersion": 1,
"position": [-160, 40]
},
{
"parameters": {
"binaryData": true
},
"id": "9f23080a-402d-4a82-821c-b74388cc9a26",
"name": "Crypto Hash Binary Data",
"type": "n8n-nodes-base.crypto",
"typeVersion": 1,
"position": [200, -80]
},
{
"parameters": {
"action": "hmac",
"binaryData": true,
"secret": "-----BEGIN RSA PRIVATE KEY-----|MIIBOgIBAAJBAKj34GkxFhD90vcNLYLInFEX6Ppy1tPf9Cnzj4p4WGeKLs1Pt8QuKUpRKfFLfRYC9AIKjbJTWit+CqvjWYzvQwECAwEAAQJAIJLixBy2qpFoS4DSmoEmo3qGy0t6z09AIJtH+5OeRV1be+N4cDYJKffGzDa88vQENZiRm0GRq6a+HPGQMd2kTQIhAKMSvzIBnni7ot/OSie2TmJLY4SwTQAevXysE2RbFDYdAiEBCUEaRQnMnbp79mxDXDf6AU0cN/RPBjb9qSHDcWZHGzUCIG2Es59z8ugGrDY+pxLQnwfotadxd+Uyv/Ow5T0q5gIJAiEAyS4RaI9YG8EWx/2w0T67ZUVAw8eOMB6BIUg0Xcu+3okCIBOs/5OiPgoTdSy7bcF9IGpSE8ZgGKzgYQVZeN97YE00-----END RSA PRIVATE KEY-----",
"encoding": "base64"
},
"id": "43d5ffa2-9c95-4287-b582-b912071a05c1",
"name": "Crypto Hmac Binary Data",
"type": "n8n-nodes-base.crypto",
"typeVersion": 1,
"position": [200, 100]
}
],
"pinData": {
"Crypto Sign data with RSA-MD5": [
{
"json": {
"data": "MVr+iZiOFtHVwO0iKC+CF+QlrZZKcGk7zBvUrWHC1fHBeS6IoWa8B/wrMvazV5H1YR8tbK8baZHD/vUNdfvjiA=="
}
}
],
"Crypto Hash into MD5": [
{
"json": {
"data": "098f6bcd4621d373cade4e832627b4f6"
}
}
],
"Crypto Hash into Hex": [
{
"json": {
"data": "098f6bcd4621d373cade4e832627b4f6"
}
}
],
"Crypto Hmac data with MD5": [
{
"json": {
"data": "BBXLTeT2o/R6oy5H69Yh7w=="
}
}
],
"Crypto Hash Binary Data": [
{
"json": {
"data": "098f6bcd4621d373cade4e832627b4f6"
}
}
],
"Crypto Hmac Binary Data": [
{
"json": {
"data": "BBXLTeT2o/R6oy5H69Yh7w=="
}
}
]
},
"connections": {
"When clicking \"Execute Workflow\"": {
"main": [
[
{
"node": "Crypto Hash into Hex",
"type": "main",
"index": 0
},
{
"node": "Crypto Hash into MD5",
"type": "main",
"index": 0
},
{
"node": "Crypto Sign data with RSA-MD5",
"type": "main",
"index": 0
},
{
"node": "Crypto Hmac data with MD5",
"type": "main",
"index": 0
},
{
"node": "Crypto Generate UUID",
"type": "main",
"index": 0
},
{
"node": "Read Binary Files",
"type": "main",
"index": 0
}
]
]
},
"Crypto Generate UUID": {
"main": [
[
{
"node": "IF",
"type": "main",
"index": 0
}
]
]
},
"IF": {
"main": [
[
{
"node": "No Operation, do nothing",
"type": "main",
"index": 0
}
],
[
{
"node": "Stop and Error",
"type": "main",
"index": 0
}
]
]
},
"No Operation, do nothing": {
"main": [[]]
},
"Read Binary Files": {
"main": [
[
{
"node": "Crypto Hash Binary Data",
"type": "main",
"index": 0
},
{
"node": "Crypto Hmac Binary Data",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {},
"versionId": "399353bc-5707-41b2-8046-a55cdc69300d",
"id": "182",
"meta": {
"instanceId": "104a4d08d8897b8bdeb38aaca515021075e0bd8544c983c2bb8c86e6a8e6081c"
},
"tags": []
}