Giter Site home page Giter Site logo

wtz_file_crypto_suiteapp's People

Contributors

tomaswatz avatar watzen avatar

Stargazers

 avatar

Watchers

 avatar

wtz_file_crypto_suiteapp's Issues

TypeError: global.Set is not a constructor

While trying to implement a simple PGP encryption solution using your PGP library in lib folder , i run into this error :

TypeError: global.Set is not a constructor [at Object.<anonymous> (/SuiteScripts/Third Party PGP Solution/lib/openpgp.js:31665:39)]

I had been trying to use OpenPGP.js for a long time when I stumbled upon your solution. In my expedition, I always ran into the issue of not converting OpenPGP to AMD fully because of so many dependencies on Node or Browser. Your solution seems to be working because you also included the TextEncoder that I was not able to implement. But now I have ran into this issue.

Would you please help me out?

P.S. this is my Map/Reduce file :

/**
 * @NApiVersion 2.1
 * @NScriptType MapReduceScript
 */
define(["N/file", "N/log", "./lib/openpgp.js"], function (file, log, openpgp) {
  /* ================== ENCRYPT FILE ======================== */

  async function encryptPGP(params) {
    const publicKeyArmored = params.publicKeyArmored;
    const inputFileContents = params.inputFileContents;
    const isText = params.isText;

    const encryptMessage = isText
      ? openpgp.message.fromText(inputFileContents)
      : openpgp.message.fromBinary(inputFileContents);

    const publicKeys = (await openpgp.key.readArmored(publicKeyArmored)).keys;

    const encryptionResult = await openpgp.encrypt({
      message: encryptMessage,
      publicKeys: publicKeys,
    });

    const encrypted = encryptionResult.data;

    return encrypted;
  }

  /* ======================== MAIN FUNCTION ======================= */
  async function mainAsyncExecution(processingObj) {
    log.debug("mainAsyncExecution - start -", processingObj);

    const inputFile = file.load({
      id: processingObj.inputFileId,
    }); //10 units

    const publicKeyFile = file.load({
      id: processingObj.publicKeyFileId,
    }); //10 units

    await Promise.all([inputFile, publicKeyFile]); //wait for the two inputFileContents and cryptoType loads to complete

    const inputFileContents = inputFile.isText
      ? inputFile.getContents()
      : Base64Binary.decode(inputFile.getContents());

    const publicKeyFileContents = publicKeyFile.isText
      ? publicKeyFile.getContents()
      : Base64Binary.decode(publicKeyFile.getContents());

    log.debug("inputFileContents", inputFileContents);
    log.debug("publicKeyFileContents", publicKeyFileContents);

    const outputFolderId = processingObj.outputFolderId;

    let newFileId;

    let encryptedContents = await encryptPGP({
      publicKeyArmored: publicKeyFileContents,
      inputFileContents: inputFileContents,
      isText: inputFile.isText,
    });

    const newFile = file.create({
      name: inputFile.name + ".pgp",
      fileType: file.Type.PLAINTEXT,
      contents: encryptedContents,
      folder: outputFolderId,
    });

    newFileId = newFile.save();

    log.debug("mainAsyncExecution", "new encrypted fileId:" + newFileId);

    return newFileId;
  }

  function getInputData() {
    return { myKey: "1" };
  }

  function map(mapContext) {
    const key = JSON.parse(mapContext.key);
    const value = JSON.parse(mapContext.value);
    mapContext.write({ key: key, value: value });
  }

  function reduce(reduceContext) {
    const executionOptions = {
      inputFileId: "856",
      outputFolderId: "44",
      publicKeyFileId: "808",
    };

    mainAsyncExecution(executionOptions);
  }

  return { getInputData: getInputData, map: map, reduce: reduce };
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.