Socket
Socket
Sign inDemoInstall

@unumid/server-sdk

Package Overview
Dependencies
219
Maintainers
1
Versions
88
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.0.2 to 4.0.3

5

build/index.d.ts

@@ -23,3 +23,6 @@ import { registerVerifier } from './verifier/registerVerifier';

import { getPresentationRequest } from './verifier/getRequestById';
export { registerIssuer, issueCredentials, reEncryptCredentials, updateCredentialStatuses, verifySubjectCredentialRequests, revokeAllCredentials, registerVerifier, sendEmail, sendRequest, sendSms, verifyPresentation, checkCredentialStatuses, getPresentationRequestByUuid, getPresentationRequest, UnumDto, RegisteredVerifier, VerifiedStatus, Presentation, RegisteredIssuer, CredentialSubject, DecryptedPresentation, CredentialStatusInfo, CustError, Proof, Credential, CredentialInfo, extractCredentialInfo, extractCredentialType, verifySignedDid, createProof, convertCredentialSubject };
import { doVerify } from './utils/verify';
import { doEncrypt } from './utils/encrypt';
import { doDecrypt } from './utils/decrypt';
export { registerIssuer, issueCredentials, reEncryptCredentials, updateCredentialStatuses, verifySubjectCredentialRequests, revokeAllCredentials, registerVerifier, sendEmail, sendRequest, sendSms, verifyPresentation, checkCredentialStatuses, getPresentationRequestByUuid, getPresentationRequest, UnumDto, RegisteredVerifier, VerifiedStatus, Presentation, RegisteredIssuer, CredentialSubject, DecryptedPresentation, CredentialStatusInfo, CustError, Proof, Credential, CredentialInfo, extractCredentialInfo, extractCredentialType, verifySignedDid, createProof, convertCredentialSubject, doVerify, doDecrypt, doEncrypt };
//# sourceMappingURL=index.d.ts.map

8

build/index.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertCredentialSubject = exports.createProof = exports.verifySignedDid = exports.extractCredentialType = exports.extractCredentialInfo = exports.CustError = exports.getPresentationRequest = exports.getPresentationRequestByUuid = exports.checkCredentialStatuses = exports.verifyPresentation = exports.sendSms = exports.sendRequest = exports.sendEmail = exports.registerVerifier = exports.revokeAllCredentials = exports.verifySubjectCredentialRequests = exports.updateCredentialStatuses = exports.reEncryptCredentials = exports.issueCredentials = exports.registerIssuer = void 0;
exports.doEncrypt = exports.doDecrypt = exports.doVerify = exports.convertCredentialSubject = exports.createProof = exports.verifySignedDid = exports.extractCredentialType = exports.extractCredentialInfo = exports.CustError = exports.getPresentationRequest = exports.getPresentationRequestByUuid = exports.checkCredentialStatuses = exports.verifyPresentation = exports.sendSms = exports.sendRequest = exports.sendEmail = exports.registerVerifier = exports.revokeAllCredentials = exports.verifySubjectCredentialRequests = exports.updateCredentialStatuses = exports.reEncryptCredentials = exports.issueCredentials = exports.registerIssuer = void 0;
var registerVerifier_1 = require("./verifier/registerVerifier");

@@ -44,2 +44,8 @@ Object.defineProperty(exports, "registerVerifier", { enumerable: true, get: function () { return registerVerifier_1.registerVerifier; } });

Object.defineProperty(exports, "getPresentationRequest", { enumerable: true, get: function () { return getRequestById_1.getPresentationRequest; } });
var verify_1 = require("./utils/verify");
Object.defineProperty(exports, "doVerify", { enumerable: true, get: function () { return verify_1.doVerify; } });
var encrypt_1 = require("./utils/encrypt");
Object.defineProperty(exports, "doEncrypt", { enumerable: true, get: function () { return encrypt_1.doEncrypt; } });
var decrypt_1 = require("./utils/decrypt");
Object.defineProperty(exports, "doDecrypt", { enumerable: true, get: function () { return decrypt_1.doDecrypt; } });
//# sourceMappingURL=index.js.map

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

var handleImageCredentialData_1 = require("../utils/handleImageCredentialData");
var winston_1 = require("winston");
/**

@@ -91,3 +92,3 @@ * Multiplexed handler for issuing credentials with UnumID's SaaS.

return __awaiter(void 0, void 0, void 0, function () {
var publicKeyInfoResponse, publicKeyInfos, issuerPublicKeyInfos, publicKeyInfoResponse_1, creds, proofOfCreds, i, type, credData, credSubject, credentialId, credentialVersionPairs, proofOfType, proofOfCredentialSubject, proofOfCredentailId, proofOfCredentialVersionPairs, issuerCredSubject, issuerCredentialVersionPairs, issuerProofOfType, issuerProofOfCredentialSubject, issuerProofOfCredentialVersionPairs, _loop_1, _i, versionList_2, version, latestVersion, resultantCredentials;
var publicKeyInfoResponse, publicKeyInfos, issuerPublicKeyInfos, publicKeyInfoResponse_1, creds, proofOfCreds, i, type, credData, credSubject, credentialId, credentialVersionPairs, proofOfType, proofOfCredentialSubject, proofOfCredentailId, proofOfCredentialVersionPairs, issuerCredSubject, issuerCredentialVersionPairs, issuerProofOfType, issuerProofOfCredentialSubject, issuerProofOfCredentialVersionPairs, _loop_1, _i, versionList_2, version_1, latestVersion, resultantCredentials;
return __generator(this, function (_a) {

@@ -144,3 +145,3 @@ switch (_a.label) {

}
_loop_1 = function (version) {
_loop_1 = function (version_1) {
var resultantEncryptedCredentials, result, proofOfResultantEncryptedCredentials, proofOfResult;

@@ -150,9 +151,9 @@ return __generator(this, function (_a) {

case 0:
resultantEncryptedCredentials = creds.filter(function (credPair) { return credPair.version === version; }).map(function (credPair) { return credPair.encryptedCredential; });
return [4 /*yield*/, sendEncryptedCredentials(authorization, { credentialRequests: resultantEncryptedCredentials }, version)];
resultantEncryptedCredentials = creds.filter(function (credPair) { return credPair.version === version_1; }).map(function (credPair) { return credPair.encryptedCredential; });
return [4 /*yield*/, sendEncryptedCredentials(authorization, { credentialRequests: resultantEncryptedCredentials }, version_1)];
case 1:
result = _a.sent();
authorization = result.authToken;
proofOfResultantEncryptedCredentials = proofOfCreds.filter(function (credPair) { return credPair.version === version; }).map(function (credPair) { return credPair.encryptedCredential; });
return [4 /*yield*/, sendEncryptedCredentials(authorization, { credentialRequests: proofOfResultantEncryptedCredentials }, version)];
proofOfResultantEncryptedCredentials = proofOfCreds.filter(function (credPair) { return credPair.version === version_1; }).map(function (credPair) { return credPair.encryptedCredential; });
return [4 /*yield*/, sendEncryptedCredentials(authorization, { credentialRequests: proofOfResultantEncryptedCredentials }, version_1)];
case 2:

@@ -169,4 +170,4 @@ proofOfResult = _a.sent();

if (!(_i < versionList_2.length)) return [3 /*break*/, 8];
version = versionList_2[_i];
return [5 /*yield**/, _loop_1(version)];
version_1 = versionList_2[_i];
return [5 /*yield**/, _loop_1(version_1)];
case 6:

@@ -198,3 +199,3 @@ _a.sent();

*/
var constructEncryptedCredentialOpts = function (cred, publicKeyInfos) {
var constructEncryptedCredentialOpts = function (cred, publicKeyInfos, version) {
var credentialSubject = convertCredentialSubject_1.convertCredentialSubject(cred.credentialSubject);

@@ -207,3 +208,3 @@ var subjectDid = credentialSubject.id;

// use the protobuf byte array encryption if dealing with a CredentialPb cred type
var encryptedData = encrypt_1.doEncrypt(subjectDidWithKeyFragment, publicKeyInfo, types_1.CredentialPb.encode(cred).finish());
var encryptedData = encrypt_1.doEncrypt(subjectDidWithKeyFragment, publicKeyInfo, types_1.CredentialPb.encode(cred).finish(), version);
// Removing the w3c credential spec of "VerifiableCredential" from the Unum ID internal type for simplicity

@@ -227,7 +228,7 @@ var credentialType = getCredentialType_1.getCredentialType(cred.type);

*/
var constructSignedCredentialPbObj = function (usCred, privateKey) {
var constructSignedCredentialPbObj = function (usCred, privateKey, version) {
try {
// convert the protobuf to a byte array
var bytes = types_1.UnsignedCredentialPb.encode(usCred).finish();
var proof = createProof_1.createProof(bytes, privateKey, usCred.issuer);
var proof = createProof_1.createProof(bytes, privateKey, usCred.issuer, version);
var credential = {

@@ -361,14 +362,14 @@ context: usCred.context,

for (var v = 0; v < versionList_1.versionList.length - 1; v++) { // note: purposely terminating one index early, which ought to be the most recent version.
var version = versionList_1.versionList[v];
if (semver_1.gte(version, '3.0.0') && semver_1.lt(version, '4.0.0')) {
var version_2 = versionList_1.versionList[v];
if (semver_1.gte(version_2, '3.0.0') && semver_1.lt(version_2, '4.0.0')) {
// Create latest version of the UnsignedCredential object
var unsignedCredential_1 = constructUnsignedCredentialPbObj(credentialOptions);
// Create the signed Credential object from the unsignedCredential object
var credential_1 = constructSignedCredentialPbObj(unsignedCredential_1, signingPrivateKey);
var credential_1 = constructSignedCredentialPbObj(unsignedCredential_1, signingPrivateKey, version_2);
// Create the encrypted credential issuance dto
var encryptedCredentialUploadOptions_1 = constructIssueCredentialOptions(credential_1, publicKeyInfos, credentialSubject.id);
var encryptedCredentialUploadOptions_1 = constructIssueCredentialOptions(credential_1, publicKeyInfos, credentialSubject.id, version_2);
var credPair_1 = {
credential: credential_1,
encryptedCredential: encryptedCredentialUploadOptions_1,
version: version
version: version_2
};

@@ -383,5 +384,5 @@ results.push(credPair_1);

// Create the signed Credential object from the unsignedCredential object
var credential = constructSignedCredentialPbObj(unsignedCredential, signingPrivateKey);
var credential = constructSignedCredentialPbObj(unsignedCredential, signingPrivateKey, winston_1.version);
// Create the encrypted credential issuance dto
var encryptedCredentialUploadOptions = constructIssueCredentialOptions(credential, publicKeyInfos, credentialSubject.id);
var encryptedCredentialUploadOptions = constructIssueCredentialOptions(credential, publicKeyInfos, credentialSubject.id, winston_1.version);
var credPair = {

@@ -403,5 +404,5 @@ credential: credential,

*/
var constructIssueCredentialOptions = function (credential, publicKeyInfos, subjectDid) {
var constructIssueCredentialOptions = function (credential, publicKeyInfos, subjectDid, version) {
// Create the attributes for an encrypted credential. The authorization string is used to get the DID Document containing the subject's public key for encryption.
var encryptedCredentialOptions = constructEncryptedCredentialOpts(credential, publicKeyInfos);
var encryptedCredentialOptions = constructEncryptedCredentialOpts(credential, publicKeyInfos, version);
// Removing the 'credential' of "VerifiableCredential" from the Unum ID internal type for simplicity

@@ -408,0 +409,0 @@ var credentialType = getCredentialType_1.getCredentialType(credential.type);

@@ -99,3 +99,3 @@ "use strict";

bytes = types_1.UnsignedRevokeAllCredentials.encode(unsignedDto).finish();
proof = createProof_1.createProof(bytes, signingPrivateKey, issuerDid);
proof = createProof_1.createProof(bytes, signingPrivateKey, issuerDid, '4.0.0');
signedDto = __assign(__assign({}, unsignedDto), { proof: proof });

@@ -102,0 +102,0 @@ restData = {

{
"name": "@unumid/server-sdk",
"version": "4.0.2",
"version": "4.0.3",
"main": "build/index.js",

@@ -5,0 +5,0 @@ "repository": "git@github.com:UnumID/Server-SDK-TypeScript.git",

import { Proof } from '@unumid/types';
/**
* Create cryptographic proof from byte array of a Protobuf object
* Creates cryptographic proof from byte array of a Protobuf object.
* Supports v3 and v4 proofs.
* @param data

@@ -9,3 +10,3 @@ * @param privateKey

*/
export declare const createProof: (data: Uint8Array, privateKey: string, method: string) => Proof;
export declare const createProof: (data: Uint8Array, privateKey: string, method: string, version: string) => Proof;
//# sourceMappingURL=createProof.d.ts.map

@@ -8,5 +8,9 @@ "use strict";

var library_crypto_1 = require("@unumid/library-crypto");
var library_crypto_v1_1 = require("@unumid/library-crypto-v1");
var lodash_1 = require("lodash");
var winston_1 = require("winston");
var logger_1 = __importDefault(require("../logger"));
/**
* Create cryptographic proof from byte array of a Protobuf object
* Creates cryptographic proof from byte array of a Protobuf object.
* Supports v3 and v4 proofs.
* @param data

@@ -17,3 +21,13 @@ * @param privateKey

*/
exports.createProof = function (data, privateKey, method) {
exports.createProof = function (data, privateKey, method, version) {
return lodash_1.lt(version, '4.0.0') ? _createProofV3(data, privateKey, method) : _createProof(data, privateKey, method);
};
/**
* Creates a v4 cryptographic proof from byte array of a Protobuf object.
* @param data
* @param privateKey
* @param method
* @returns
*/
var _createProof = function (data, privateKey, method) {
var signature = library_crypto_1.signBytes(data, privateKey);

@@ -27,5 +41,24 @@ var proof = {

};
logger_1.default.debug("Successfully created proof " + JSON.stringify(proof));
logger_1.default.debug("Successfully created " + winston_1.version + " proof " + JSON.stringify(proof));
return (proof);
};
/**
* Creates a v3 cryptographic proof from byte array of a Protobuf object.
* @param data
* @param privateKey
* @param method
* @returns
*/
var _createProofV3 = function (data, privateKey, method) {
var signature = library_crypto_v1_1.signBytes(data, privateKey);
var proof = {
created: new Date(),
signatureValue: signature,
type: 'secp256r1Signature2020',
verificationMethod: method,
proofPurpose: 'assertionMethod'
};
logger_1.default.debug("Successfully created " + winston_1.version + " proof " + JSON.stringify(proof));
return (proof);
};
//# sourceMappingURL=createProof.js.map
/// <reference types="node" />
import { EncryptedData } from '@unumid/types';
/**
* Decrypt the data.
* Decrypt the data. Supports v3 and v4.
* @param privateRSAKey

@@ -6,0 +6,0 @@ * @param data

@@ -11,3 +11,3 @@ "use strict";

/**
* Decrypt the data.
* Decrypt the data. Supports v3 and v4.
* @param privateRSAKey

@@ -14,0 +14,0 @@ * @param data

@@ -8,3 +8,3 @@ import { EncryptedData, PublicKeyInfo } from '@unumid/types';

*/
export declare const doEncrypt: (did: string, publicKeyObj: PublicKeyInfo, data: Uint8Array) => EncryptedData;
export declare const doEncrypt: (did: string, publicKeyObj: PublicKeyInfo, data: Uint8Array, version: string) => EncryptedData;
//# sourceMappingURL=encrypt.d.ts.map

@@ -9,2 +9,4 @@ "use strict";

var library_crypto_1 = require("@unumid/library-crypto");
var library_crypto_v1_1 = require("@unumid/library-crypto-v1");
var semver_1 = require("semver");
/**

@@ -16,3 +18,6 @@ * Encrypt the provided data object.

*/
exports.doEncrypt = function (did, publicKeyObj, data) {
exports.doEncrypt = function (did, publicKeyObj, data, version) {
return semver_1.lt(version, '4.0.0') ? _doEncryptV3(did, publicKeyObj, data) : _doEncrypt(did, publicKeyObj, data);
};
var _doEncrypt = function (did, publicKeyObj, data) {
logger_1.default.debug('Performing byte array encryption using public key', publicKeyObj);

@@ -23,2 +28,8 @@ var result = library_crypto_1.encryptBytes(did + '#' + publicKeyObj.id, publicKeyObj, data);

};
var _doEncryptV3 = function (did, publicKeyObj, data) {
logger_1.default.debug('Performing byte array encryption using public key', publicKeyObj);
var result = library_crypto_v1_1.encryptBytes(did + '#' + publicKeyObj.id, publicKeyObj, data);
logger_1.default.debug("Encrypted data result: " + result.data);
return result;
};
//# sourceMappingURL=encrypt.js.map

@@ -241,3 +241,3 @@ "use strict";

var bytes = types_1.UnsignedPresentationRequestPb.encode(unsignedPresentationRequest).finish();
var proof = createProof_1.createProof(bytes, privateKey, unsignedPresentationRequest.verifier);
var proof = createProof_1.createProof(bytes, privateKey, unsignedPresentationRequest.verifier, '3.0.0');
var signedPresentationRequest = __assign(__assign({}, unsignedPresentationRequest), { proof: proof });

@@ -265,3 +265,3 @@ return signedPresentationRequest;

var bytes = types_1.UnsignedPresentationRequestPb.encode(unsignedPresentationRequest).finish();
var proof = createProof_1.createProof(bytes, privateKey, unsignedPresentationRequest.verifier);
var proof = createProof_1.createProof(bytes, privateKey, unsignedPresentationRequest.verifier, '4.0.0');
var signedPresentationRequest = __assign(__assign({}, unsignedPresentationRequest), { proof: proof });

@@ -268,0 +268,0 @@ return signedPresentationRequest;

{
"name": "@unumid/server-sdk",
"version": "4.0.2",
"version": "4.0.3",
"main": "build/index.js",

@@ -5,0 +5,0 @@ "repository": "git@github.com:UnumID/Server-SDK-TypeScript.git",

@@ -23,2 +23,5 @@ import { registerVerifier } from './verifier/registerVerifier';

import { getPresentationRequest } from './verifier/getRequestById';
import { doVerify } from './utils/verify';
import { doEncrypt } from './utils/encrypt';
import { doDecrypt } from './utils/decrypt';

@@ -61,3 +64,6 @@ export {

createProof,
convertCredentialSubject
convertCredentialSubject,
doVerify,
doDecrypt,
doEncrypt
};

@@ -24,2 +24,3 @@ import { configData } from '../config';

import { handleImageCredentialData } from '../utils/handleImageCredentialData';
import { version } from 'winston';

@@ -149,3 +150,3 @@ // interface to handle grouping Credentials and their encrypted form

*/
const constructEncryptedCredentialOpts = (cred: CredentialPb, publicKeyInfos: PublicKeyInfo[]): EncryptedCredentialOptions[] => {
const constructEncryptedCredentialOpts = (cred: CredentialPb, publicKeyInfos: PublicKeyInfo[], version: string): EncryptedCredentialOptions[] => {
const credentialSubject: CredentialSubject = convertCredentialSubject(cred.credentialSubject);

@@ -160,3 +161,3 @@ const subjectDid = credentialSubject.id;

// use the protobuf byte array encryption if dealing with a CredentialPb cred type
const encryptedData: EncryptedData = doEncrypt(subjectDidWithKeyFragment, publicKeyInfo, CredentialPb.encode(cred as CredentialPb).finish());
const encryptedData: EncryptedData = doEncrypt(subjectDidWithKeyFragment, publicKeyInfo, CredentialPb.encode(cred as CredentialPb).finish(), version);

@@ -184,3 +185,3 @@ // Removing the w3c credential spec of "VerifiableCredential" from the Unum ID internal type for simplicity

*/
const constructSignedCredentialPbObj = (usCred: UnsignedCredentialPb, privateKey: string): CredentialPb => {
const constructSignedCredentialPbObj = (usCred: UnsignedCredentialPb, privateKey: string, version: string): CredentialPb => {
try {

@@ -190,3 +191,3 @@ // convert the protobuf to a byte array

const proof: ProofPb = createProof(bytes, privateKey, usCred.issuer);
const proof: ProofPb = createProof(bytes, privateKey, usCred.issuer, version);

@@ -346,6 +347,6 @@ const credential: CredentialPb = {

// Create the signed Credential object from the unsignedCredential object
const credential = constructSignedCredentialPbObj(unsignedCredential, signingPrivateKey);
const credential = constructSignedCredentialPbObj(unsignedCredential, signingPrivateKey, version);
// Create the encrypted credential issuance dto
const encryptedCredentialUploadOptions: IssueCredentialOptions = constructIssueCredentialOptions(credential, publicKeyInfos, credentialSubject.id);
const encryptedCredentialUploadOptions: IssueCredentialOptions = constructIssueCredentialOptions(credential, publicKeyInfos, credentialSubject.id, version);
const credPair: WithVersion<CredentialPair> = {

@@ -368,6 +369,6 @@ credential,

// Create the signed Credential object from the unsignedCredential object
const credential = constructSignedCredentialPbObj(unsignedCredential, signingPrivateKey);
const credential = constructSignedCredentialPbObj(unsignedCredential, signingPrivateKey, version);
// Create the encrypted credential issuance dto
const encryptedCredentialUploadOptions: IssueCredentialOptions = constructIssueCredentialOptions(credential, publicKeyInfos, credentialSubject.id);
const encryptedCredentialUploadOptions: IssueCredentialOptions = constructIssueCredentialOptions(credential, publicKeyInfos, credentialSubject.id, version);
const credPair: WithVersion<CredentialPair> = {

@@ -392,5 +393,5 @@ credential,

*/
const constructIssueCredentialOptions = (credential: CredentialPb, publicKeyInfos: PublicKeyInfo[], subjectDid: string): IssueCredentialOptions => {
const constructIssueCredentialOptions = (credential: CredentialPb, publicKeyInfos: PublicKeyInfo[], subjectDid: string, version: string): IssueCredentialOptions => {
// Create the attributes for an encrypted credential. The authorization string is used to get the DID Document containing the subject's public key for encryption.
const encryptedCredentialOptions = constructEncryptedCredentialOpts(credential, publicKeyInfos);
const encryptedCredentialOptions = constructEncryptedCredentialOpts(credential, publicKeyInfos, version);

@@ -397,0 +398,0 @@ // Removing the 'credential' of "VerifiableCredential" from the Unum ID internal type for simplicity

@@ -52,3 +52,3 @@ import { configData } from '../config';

const bytes = UnsignedRevokeAllCredentials.encode(unsignedDto).finish();
const proof: ProofPb = createProof(bytes, signingPrivateKey, issuerDid);
const proof: ProofPb = createProof(bytes, signingPrivateKey, issuerDid, '4.0.0');

@@ -55,0 +55,0 @@ const signedDto: RevokeAllCredentials = {

import { signBytes } from '@unumid/library-crypto';
import { signBytes as signBytesDeprecated } from '@unumid/library-crypto-v1';
import { Proof } from '@unumid/types';
import { lt } from 'lodash';
import { version } from 'winston';
import logger from '../logger';
/**
* Create cryptographic proof from byte array of a Protobuf object
* Creates cryptographic proof from byte array of a Protobuf object.
* Supports v3 and v4 proofs.
* @param data

@@ -12,3 +16,14 @@ * @param privateKey

*/
export const createProof = (data: Uint8Array, privateKey: string, method: string): Proof => {
export const createProof = (data: Uint8Array, privateKey: string, method: string, version: string): Proof => {
return lt(version, '4.0.0') ? _createProofV3(data, privateKey, method) : _createProof(data, privateKey, method);
};
/**
* Creates a v4 cryptographic proof from byte array of a Protobuf object.
* @param data
* @param privateKey
* @param method
* @returns
*/
const _createProof = (data: Uint8Array, privateKey: string, method: string): Proof => {
const signature = signBytes(data, privateKey);

@@ -24,4 +39,26 @@

logger.debug(`Successfully created proof ${JSON.stringify(proof)}`);
logger.debug(`Successfully created ${version} proof ${JSON.stringify(proof)}`);
return (proof);
};
/**
* Creates a v3 cryptographic proof from byte array of a Protobuf object.
* @param data
* @param privateKey
* @param method
* @returns
*/
const _createProofV3 = (data: Uint8Array, privateKey: string, method: string): Proof => {
const signature = signBytesDeprecated(data, privateKey);
const proof: Proof = {
created: new Date(),
signatureValue: signature,
type: 'secp256r1Signature2020',
verificationMethod: method,
proofPurpose: 'assertionMethod'
};
logger.debug(`Successfully created ${version} proof ${JSON.stringify(proof)}`);
return (proof);
};

@@ -7,3 +7,3 @@ import { EncryptedData } from '@unumid/types';

/**
* Decrypt the data.
* Decrypt the data. Supports v3 and v4.
* @param privateRSAKey

@@ -10,0 +10,0 @@ * @param data

import { EncryptedData, PublicKeyInfo } from '@unumid/types';
import logger from '../logger';
import { encryptBytes } from '@unumid/library-crypto';
import { encryptBytes as encryptBytesDeprecated } from '@unumid/library-crypto-v1';
import { lt } from 'semver';

@@ -11,3 +13,7 @@ /**

*/
export const doEncrypt = (did: string, publicKeyObj: PublicKeyInfo, data: Uint8Array): EncryptedData => {
export const doEncrypt = (did: string, publicKeyObj: PublicKeyInfo, data: Uint8Array, version: string): EncryptedData => {
return lt(version, '4.0.0') ? _doEncryptV3(did, publicKeyObj, data) : _doEncrypt(did, publicKeyObj, data);
};
const _doEncrypt = (did: string, publicKeyObj: PublicKeyInfo, data: Uint8Array): EncryptedData => {
logger.debug('Performing byte array encryption using public key', publicKeyObj);

@@ -24,1 +30,14 @@

};
const _doEncryptV3 = (did: string, publicKeyObj: PublicKeyInfo, data: Uint8Array): EncryptedData => {
logger.debug('Performing byte array encryption using public key', publicKeyObj);
const result = encryptBytesDeprecated(
did + '#' + publicKeyObj.id,
publicKeyObj,
data
);
logger.debug(`Encrypted data result: ${result.data}`);
return result;
};

@@ -231,3 +231,4 @@ import { configData } from '../config';

privateKey,
unsignedPresentationRequest.verifier
unsignedPresentationRequest.verifier,
'3.0.0'
);

@@ -265,3 +266,4 @@

privateKey,
unsignedPresentationRequest.verifier
unsignedPresentationRequest.verifier,
'4.0.0'
);

@@ -268,0 +270,0 @@

@@ -42,3 +42,3 @@ import * as cryptoLib from '@unumid/library-crypto';

it('encrypt crypto library should have been called', () => {
encryptedData = doEncrypt(did, publicKeyObj[0], dataBytes);
encryptedData = doEncrypt(did, publicKeyObj[0], dataBytes, '4.0.0');
expect(encryptSpy).toBeCalled();

@@ -45,0 +45,0 @@ });

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc