UNPKG

n8n-nodes-tweetnacl

Version:

An n8n node to use TweetNaCl for encryption and descryption

72 lines 2.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TweetNacl = void 0; const SignDescription_1 = require("./SignDescription"); const nacl = require("tweetnacl"); class TweetNacl { constructor() { this.description = { displayName: "TweetNaCl", name: "tweetNaCl", group: ["transform"], version: 1, description: "Use TweetNaCl to encrypt or decrypt data.", subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}', defaults: { name: "TweetNaCl", color: "#772244", description: "Use TweetNaCl to encrypt or decrypt data.", }, inputs: ["main"], outputs: ["main"], properties: [ { displayName: "Resource", name: "resource", type: "options", default: "sign", description: "The resource to perform", options: [ { name: "Sign", value: "sign", description: "Sign a message", }, ], }, ...SignDescription_1.signOperations, ...SignDescription_1.signFields, ], }; } async execute() { const items = this.getInputData(); const returnData = []; let responseData; const resource = this.getNodeParameter("resource", 0); const operation = this.getNodeParameter("operation", 0); for (let i = 0; i < items.length; i++) { if (resource === "sign") { if (operation === "detachedVerify") { const message = this.getNodeParameter("message", i); const signature = this.getNodeParameter("signature", i); const publicKey = this.getNodeParameter("publicKey", i); try { responseData = nacl.sign.detached.verify(Buffer.from(message), Buffer.from(signature, "hex"), Buffer.from(publicKey, "hex")); returnData.push({ isVerified: responseData }); } catch (error) { if (this.continueOnFail()) { returnData.push({ error: "Failed to execute TweetNaCl. " }); continue; } throw error; } } } } return [this.helpers.returnJsonArray(returnData)]; } } exports.TweetNacl = TweetNacl; //# sourceMappingURL=TweetNacl.node.js.map