Socket
Socket
Sign inDemoInstall

@opengovsg/formsg-sdk

Package Overview
Dependencies
Maintainers
4
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opengovsg/formsg-sdk - npm Package Compare versions

Comparing version 0.11.0 to 0.12.0-alpha.1

dist/crypto-base.d.ts

27

dist/crypto.d.ts

@@ -1,3 +0,4 @@

import { DecryptedContent, DecryptedContentAndAttachments, DecryptParams, EncryptedContent, EncryptedFileContent } from './types';
export default class Crypto {
import CryptoBase from './crypto-base';
import { DecryptedContent, DecryptedContentAndAttachments, DecryptParams, EncryptedContent } from './types';
export default class Crypto extends CryptoBase {
signingPublicKey?: string;

@@ -27,7 +28,2 @@ constructor({ signingPublicKey }?: {

/**
* Generates a new keypair for encryption.
* @returns The generated keypair.
*/
generate: () => import("./types").Keypair;
/**
* Returns true if a pair of public & secret keys are associated with each other

@@ -39,19 +35,2 @@ * @param publicKey The public key to verify against.

/**
* Encrypt given binary file with a unique keypair for each submission.
* @param binary The file to encrypt, should be a blob that is converted to Uint8Array binary
* @param formPublicKey The base-64 encoded public key
* @returns Promise holding the encrypted file
* @throws error if any of the encrypt methods fail
*/
encryptFile: (binary: Uint8Array, formPublicKey: string) => Promise<EncryptedFileContent>;
/**
* Decrypt the given encrypted file content.
* @param formSecretKey Secret key as a base-64 string
* @param encrypted Object returned from encryptFile function
* @param encrypted.submissionPublicKey The submission public key as a base-64 string
* @param encrypted.nonce The nonce as a base-64 string
* @param encrypted.blob The encrypted file as a Blob object
*/
decryptFile: (formSecretKey: string, { submissionPublicKey, nonce, binary: encryptedBinary, }: EncryptedFileContent) => Promise<Uint8Array | null>;
/**
* Decrypts an encrypted submission, and also download and decrypt any attachments alongside it.

@@ -58,0 +37,0 @@ * @param formSecretKey Secret key as a base-64 string

"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -47,7 +62,9 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

var validate_1 = require("./util/validate");
var crypto_base_1 = __importDefault(require("./crypto-base"));
var errors_1 = require("./errors");
var Crypto = /** @class */ (function () {
var Crypto = /** @class */ (function (_super) {
__extends(Crypto, _super);
function Crypto(_a) {
var _b = _a === void 0 ? {} : _a, signingPublicKey = _b.signingPublicKey;
var _this = this;
var _this = _super.call(this) || this;
/**

@@ -60,3 +77,3 @@ * Encrypt input with a unique keypair for each submission

*/
this.encrypt = function (msg, encryptionPublicKey, signingPrivateKey) {
_this.encrypt = function (msg, encryptionPublicKey, signingPrivateKey) {
var processedMsg = (0, tweetnacl_util_1.decodeUTF8)(JSON.stringify(msg));

@@ -78,3 +95,3 @@ if (signingPrivateKey) {

*/
this.decrypt = function (formSecretKey, decryptParams) {
_this.decrypt = function (formSecretKey, decryptParams) {
try {

@@ -123,7 +140,2 @@ var encryptedContent = decryptParams.encryptedContent, verifiedContent = decryptParams.verifiedContent;

/**
* Generates a new keypair for encryption.
* @returns The generated keypair.
*/
this.generate = crypto_1.generateKeypair;
/**
* Returns true if a pair of public & secret keys are associated with each other

@@ -133,3 +145,3 @@ * @param publicKey The public key to verify against.

*/
this.valid = function (publicKey, secretKey) {
_this.valid = function (publicKey, secretKey) {
var _a;

@@ -147,37 +159,2 @@ var testResponse = [];

/**
* Encrypt given binary file with a unique keypair for each submission.
* @param binary The file to encrypt, should be a blob that is converted to Uint8Array binary
* @param formPublicKey The base-64 encoded public key
* @returns Promise holding the encrypted file
* @throws error if any of the encrypt methods fail
*/
this.encryptFile = function (binary, formPublicKey) { return __awaiter(_this, void 0, void 0, function () {
var submissionKeypair, nonce;
return __generator(this, function (_a) {
submissionKeypair = this.generate();
nonce = tweetnacl_1.default.randomBytes(24);
return [2 /*return*/, {
submissionPublicKey: submissionKeypair.publicKey,
nonce: (0, tweetnacl_util_1.encodeBase64)(nonce),
binary: tweetnacl_1.default.box(binary, nonce, (0, tweetnacl_util_1.decodeBase64)(formPublicKey), (0, tweetnacl_util_1.decodeBase64)(submissionKeypair.secretKey)),
}];
});
}); };
/**
* Decrypt the given encrypted file content.
* @param formSecretKey Secret key as a base-64 string
* @param encrypted Object returned from encryptFile function
* @param encrypted.submissionPublicKey The submission public key as a base-64 string
* @param encrypted.nonce The nonce as a base-64 string
* @param encrypted.blob The encrypted file as a Blob object
*/
this.decryptFile = function (formSecretKey, _a) {
var submissionPublicKey = _a.submissionPublicKey, nonce = _a.nonce, encryptedBinary = _a.binary;
return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_b) {
return [2 /*return*/, tweetnacl_1.default.box.open(encryptedBinary, (0, tweetnacl_util_1.decodeBase64)(nonce), (0, tweetnacl_util_1.decodeBase64)(submissionPublicKey), (0, tweetnacl_util_1.decodeBase64)(formSecretKey))];
});
});
};
/**
* Decrypts an encrypted submission, and also download and decrypt any attachments alongside it.

@@ -189,3 +166,3 @@ * @param formSecretKey Secret key as a base-64 string

*/
this.decryptWithAttachments = function (formSecretKey, decryptParams) { return __awaiter(_this, void 0, void 0, function () {
_this.decryptWithAttachments = function (formSecretKey, decryptParams) { return __awaiter(_this, void 0, void 0, function () {
var decryptedRecords, filenames, attachmentRecords, decryptedContent, fieldIds, downloadPromises, _a;

@@ -258,6 +235,7 @@ var _this = this;

}); };
this.signingPublicKey = signingPublicKey;
_this.signingPublicKey = signingPublicKey;
return _this;
}
return Crypto;
}());
}(crypto_base_1.default));
exports.default = Crypto;
import Crypto from './crypto';
import CryptoV3 from './crypto-v3';
import { PackageInitParams } from './types';

@@ -16,4 +17,5 @@ import Verification from './verification';

crypto: Crypto;
cryptoV3: CryptoV3;
verification: Verification;
};
export = _default;

@@ -7,2 +7,3 @@ "use strict";

var crypto_1 = __importDefault(require("./crypto"));
var crypto_v3_1 = __importDefault(require("./crypto-v3"));
var verification_1 = __importDefault(require("./verification"));

@@ -28,2 +29,3 @@ var webhooks_1 = __importDefault(require("./webhooks"));

crypto: new crypto_1.default({ signingPublicKey: signingPublicKey }),
cryptoV3: new crypto_v3_1.default(),
verification: new verification_1.default({

@@ -30,0 +32,0 @@ publicKey: verificationPublicKey,

@@ -9,3 +9,3 @@ export type PackageInitParams = {

};
export type FieldType = 'section' | 'radiobutton' | 'dropdown' | 'checkbox' | 'nric' | 'email' | 'table' | 'number' | 'rating' | 'yes_no' | 'decimal' | 'textfield' | 'textarea' | 'attachment' | 'date' | 'mobile' | 'homeno';
export type FieldType = 'section' | 'radiobutton' | 'dropdown' | 'checkbox' | 'nric' | 'email' | 'table' | 'number' | 'rating' | 'yes_no' | 'decimal' | 'textfield' | 'textarea' | 'attachment' | 'date' | 'mobile' | 'homeno' | 'statement' | 'image' | 'country_region' | 'uen' | 'children';
export type FormField = {

@@ -24,3 +24,13 @@ _id: string;

});
export type FormFieldsV3 = Record<string, {
fieldType: FieldType;
answer: any;
}>;
export type EncryptedContent = string;
export type EncryptedContentV3 = {
submissionPublicKey: string;
submissionSecretKey: string;
encryptedContent: EncryptedContent;
encryptedSubmissionSecretKey: EncryptedContent;
};
export type EncryptedAttachmentRecords = Record<string, string>;

@@ -33,2 +43,7 @@ export interface DecryptParams {

}
export interface DecryptParamsV3 {
encryptedContent: EncryptedContent;
encryptedSubmissionSecretKey: EncryptedContent;
version: number;
}
export type DecryptedContent = {

@@ -38,2 +53,6 @@ responses: FormField[];

};
export type DecryptedContentV3 = {
submissionSecretKey: string;
responses: FormFieldsV3;
};
export type DecryptedFile = {

@@ -40,0 +59,0 @@ filename: string;

@@ -1,2 +0,2 @@

import { Keypair, EncryptedContent, EncryptedAttachmentContent, EncryptedFileContent } from '../types';
import { EncryptedAttachmentContent, EncryptedContent, EncryptedFileContent, Keypair } from '../types';
/**

@@ -3,0 +3,0 @@ * Helper method to generate a new keypair for encryption.

@@ -1,3 +0,4 @@

import { FormField } from '../types';
import { FormField, FormFieldsV3 } from '../types';
declare function determineIsFormFields(tbd: any): tbd is FormField[];
export { determineIsFormFields };
declare function determineIsFormFieldsV3(tbd: any): tbd is FormFieldsV3;
export { determineIsFormFields, determineIsFormFieldsV3 };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.determineIsFormFields = void 0;
exports.determineIsFormFieldsV3 = exports.determineIsFormFields = void 0;
function determineIsFormFields(tbd) {

@@ -25,1 +25,13 @@ if (!Array.isArray(tbd)) {

exports.determineIsFormFields = determineIsFormFields;
// TODO(MRF): This is currently very rudimentary, we should look at making this more specific where required.
function determineIsFormFieldsV3(tbd) {
for (var _i = 0, _a = Object.keys(tbd); _i < _a.length; _i++) {
var id = _a[_i];
var value = tbd[id];
var hasCorrectShape = value.fieldType && value.answer !== undefined;
if (!hasCorrectShape)
return false;
}
return true;
}
exports.determineIsFormFieldsV3 = determineIsFormFieldsV3;
{
"name": "@opengovsg/formsg-sdk",
"version": "0.11.0",
"version": "0.12.0-alpha.1",
"repository": {

@@ -12,3 +12,3 @@ "type": "git",

"scripts": {
"test": "jest",
"test": "NODE_OPTIONS=\"--max-old-space-size=8192\" jest",
"test-ci": "jest --coverage",

@@ -15,0 +15,0 @@ "test-watch": "jest --watch",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc