Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@unumid/server-sdk

Package Overview
Dependencies
Maintainers
1
Versions
88
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@unumid/server-sdk - npm Package Compare versions

Comparing version 2.0.1 to 2.0.2

build/utils/versionList.d.ts

141

build/issuer/issueCredentials.js

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

var convertCredentialSubject_1 = require("../utils/convertCredentialSubject");
var semver_1 = require("semver");
var versionList_1 = require("../utils/versionList");
/**

@@ -100,2 +102,41 @@ * Creates an object of type EncryptedCredentialOptions which encapsulates information relating to the encrypted credential data

/**
* Creates an object of type EncryptedCredentialOptions which encapsulates information relating to the encrypted credential data
* @param cred Credential
* @param authorization String
*/
var constructEncryptedCredentialV1Opts = function (cred, authorization) { return __awaiter(void 0, void 0, void 0, function () {
var credentialSubject, subjectDid, didDocResponse, publicKeyInfos;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
credentialSubject = cred.credentialSubject;
subjectDid = credentialSubject.id;
return [4 /*yield*/, didHelper_1.getDIDDoc(config_1.configData.SaaSUrl, authorization, subjectDid)];
case 1:
didDocResponse = _a.sent();
if (didDocResponse instanceof Error) {
throw didDocResponse;
}
publicKeyInfos = didHelper_1.getKeyFromDIDDoc(didDocResponse.body, 'RSA');
if (publicKeyInfos.length === 0) {
throw new error_1.CustError(404, 'Public key not found for the DID');
}
// create an encrypted copy of the credential with each RSA public key
return [2 /*return*/, publicKeyInfos.map(function (publicKeyInfo) {
var subjectDidWithKeyFragment = subjectDid + "#" + publicKeyInfo.id;
var encryptedData = encrypt_1.doEncrypt(subjectDidWithKeyFragment, publicKeyInfo, cred);
var encryptedCredentialOptions = {
credentialId: cred.id,
subject: subjectDidWithKeyFragment,
issuer: cred.issuer,
type: cred.type,
data: encryptedData
// version: '1.0.0'
};
return encryptedCredentialOptions;
})];
}
});
}); };
/**
* Creates a signed credential with all the relevant information. The proof serves as a cryptographic signature.

@@ -121,2 +162,22 @@ * @param usCred UnsignedCredential

/**
* Creates a signed credential with all the relevant information. The proof serves as a cryptographic signature.
* @param usCred UnsignedCredential
* @param privateKey String
*/
var constructSignedCredentialV1Obj = function (usCred, privateKey) {
var proof = createProof_1.createProof(usCred, privateKey, usCred.issuer, 'pem');
var credential = {
'@context': usCred['@context'],
credentialStatus: usCred.credentialStatus,
credentialSubject: usCred.credentialSubject,
issuer: usCred.issuer,
type: usCred.type,
id: usCred.id,
issuanceDate: usCred.issuanceDate,
expirationDate: usCred.expirationDate,
proof: proof
};
return (credential);
};
/**
* Creates all the attributes associated with an unsigned credential.

@@ -126,2 +187,4 @@ * @param credOpts CredentialOptions

var constructUnsignedCredentialObj = function (credOpts) {
// CredentialSubject type is dependent on version. V2 is a string for passing to holder so iOS can handle it as a concrete type instead of a map of unknown keys.
var credentialSubject = JSON.stringify(credOpts.credentialSubject);
var credentialId = helpers_1.getUUID();

@@ -134,3 +197,3 @@ var unsCredObj = {

},
credentialSubject: JSON.stringify(credOpts.credentialSubject),
credentialSubject: credentialSubject,
issuer: credOpts.issuer,

@@ -142,5 +205,28 @@ type: __spreadArrays(['VerifiableCredential'], credOpts.type),

};
return (unsCredObj);
return unsCredObj;
};
/**
* Creates all the attributes associated with an unsigned credential.
* @param credOpts CredentialOptions
*/
var constructUnsignedCredentialV1Obj = function (credOpts, version) {
// CredentialSubject type is dependent on version. V2 is a string for passing to holder so iOS can handle it as a concrete type instead of a map of unknown keys.
var credentialSubject = credOpts.credentialSubject;
var credentialId = helpers_1.getUUID();
var unsCredObj = {
'@context': ['https://www.w3.org/2018/credentials/v1'],
credentialStatus: {
id: config_1.configData.SaaSUrl + "/credentialStatus/" + credentialId,
type: 'CredentialStatus'
},
credentialSubject: credentialSubject,
issuer: credOpts.issuer,
type: __spreadArrays(['VerifiableCredential'], credOpts.type),
id: credentialId,
issuanceDate: new Date(),
expirationDate: credOpts.expirationDate
};
return unsCredObj;
};
/**
* Handle input validation.

@@ -210,7 +296,7 @@ * @param type

exports.issueCredential = function (authorization, type, issuer, credentialSubject, signingPrivateKey, expirationDate) { return __awaiter(void 0, void 0, void 0, function () {
var credentialOptions, unsignedCredential, credential, encryptedCredentialOptions, encryptedCredentialUploadOptions, restData, restResp, authToken, issuedCredential, error_2;
var credentialOptions, v, version, unsignedCredential_1, credential_1, encryptedCredentialOptions_1, encryptedCredentialUploadOptions_1, restData_1, restResp_1, latestVersion, unsignedCredential, credential, encryptedCredentialOptions, encryptedCredentialUploadOptions, restData, restResp, authToken, issuedCredential, error_2;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 3, , 4]);
_a.trys.push([0, 8, , 9]);
// The authorization string needs to be passed for the SaaS to authorize getting the DID document associated with the holder / subject.

@@ -221,6 +307,41 @@ requireAuth_1.requireAuth(authorization);

credentialOptions = constructCredentialOptions(type, issuer, credentialSubject, signingPrivateKey, expirationDate);
v = 0;
_a.label = 1;
case 1:
if (!(v < versionList_1.versionList.length - 1)) return [3 /*break*/, 5];
version = versionList_1.versionList[v];
unsignedCredential_1 = constructUnsignedCredentialV1Obj(credentialOptions, version);
if (!semver_1.lt(version, '2.0.0')) return [3 /*break*/, 4];
credential_1 = constructSignedCredentialV1Obj(unsignedCredential_1, signingPrivateKey);
return [4 /*yield*/, constructEncryptedCredentialV1Opts(credential_1, authorization)];
case 2:
encryptedCredentialOptions_1 = _a.sent();
encryptedCredentialUploadOptions_1 = {
credentialId: credential_1.id,
subject: credentialSubject.id,
issuer: credential_1.issuer,
type: credential_1.type,
encryptedCredentials: encryptedCredentialOptions_1
};
restData_1 = {
method: 'POST',
baseUrl: config_1.configData.SaaSUrl,
endPoint: 'credentialRepository',
header: { Authorization: authorization, version: version },
data: encryptedCredentialUploadOptions_1
};
return [4 /*yield*/, networkRequestHelper_1.makeNetworkRequest(restData_1)];
case 3:
restResp_1 = _a.sent();
authorization = networkRequestHelper_1.handleAuthToken(restResp_1, authorization);
_a.label = 4;
case 4:
v++;
return [3 /*break*/, 1];
case 5:
latestVersion = versionList_1.versionList[versionList_1.versionList.length - 1];
unsignedCredential = constructUnsignedCredentialObj(credentialOptions);
credential = constructSignedCredentialObj(unsignedCredential, signingPrivateKey);
return [4 /*yield*/, constructEncryptedCredentialOpts(credential, authorization)];
case 1:
case 6:
encryptedCredentialOptions = _a.sent();

@@ -238,16 +359,16 @@ encryptedCredentialUploadOptions = {

endPoint: 'credentialRepository',
header: { Authorization: authorization },
header: { Authorization: authorization, version: latestVersion },
data: encryptedCredentialUploadOptions
};
return [4 /*yield*/, networkRequestHelper_1.makeNetworkRequest(restData)];
case 2:
case 7:
restResp = _a.sent();
authToken = networkRequestHelper_1.handleAuthToken(restResp);
authToken = networkRequestHelper_1.handleAuthToken(restResp, authorization);
issuedCredential = { body: credential, authToken: authToken };
return [2 /*return*/, issuedCredential];
case 3:
case 8:
error_2 = _a.sent();
logger_1.default.error("Error issuing a credential with UnumID SaaS. " + error_2);
throw error_2;
case 4: return [2 /*return*/];
case 9: return [2 /*return*/];
}

@@ -254,0 +375,0 @@ });

2

build/issuer/updateCredentialStatus.js

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

response = _a.sent();
authToken = networkRequestHelper_1.handleAuthToken(response);
authToken = networkRequestHelper_1.handleAuthToken(response, authorization);
revokedCredential = {

@@ -94,0 +94,0 @@ authToken: authToken,

@@ -28,5 +28,5 @@ "use strict";

};
logger_1.default.debug('Successfully created proof', proof);
logger_1.default.debug("Successfully created proof " + proof);
return (proof);
};
//# sourceMappingURL=createProof.js.map

@@ -12,3 +12,3 @@ import { RESTData, RESTResponse } from '../types';

*/
export declare const handleAuthToken: (response: JSONObj) => string;
export declare const handleAuthToken: (response: JSONObj, existingAuthToken?: string | undefined) => string;
//# sourceMappingURL=networkRequestHelper.d.ts.map

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

var helpers_1 = require("./helpers");
var versionList_1 = require("./versionList");
/**

@@ -75,3 +76,3 @@ * Helper to handle network requests.

body: JSON.stringify(inputObj.data),
headers: __assign(__assign({}, restHdr), { version: '1.0.0' // The api version to hit the UnumID SaaS with in the this version of the SDK
headers: __assign(__assign({}, restHdr), { version: restHdr.version ? restHdr.version : versionList_1.versionList[versionList_1.versionList.length - 1] // The api version to hit the UnumID SaaS with in the this version of the SDK
})

@@ -107,10 +108,10 @@ };

*/
exports.handleAuthToken = function (response) {
exports.handleAuthToken = function (response, existingAuthToken) {
var authTokenResp = response && response.headers && response.headers['x-auth-token'] ? response.headers['x-auth-token'] : '';
// Ensuring that the authToken attribute is presented as a string or undefined. The header values can be a string | string[] so hence the complex ternary.
var authToken = (helpers_1.isArrayEmpty(authTokenResp) && authTokenResp ? authTokenResp : (helpers_1.isArrayNotEmpty(authTokenResp) ? authTokenResp[0] : undefined));
// If authToken is undefined just return undefined, otherwise return a properly formatted Bearer token for use in subsequent requests.
var result = authToken ? (authToken.startsWith('Bearer ') ? authToken : "Bearer " + authToken) : authToken;
// If authToken is undefined see if the input existing auth token is a valid Bearer token (not an admin key), if an admin key just return undefined, otherwise return a properly formatted Bearer token for use in subsequent requests or the existing, inputting token.
var result = authToken ? (authToken.startsWith('Bearer ') ? authToken : "Bearer " + authToken) : ((existingAuthToken === null || existingAuthToken === void 0 ? void 0 : existingAuthToken.startsWith('Bearer ')) ? existingAuthToken : authToken);
return result;
};
//# sourceMappingURL=networkRequestHelper.js.map

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

credentialStatus = credentialStatusResponse.body;
authToken = networkRequestHelper_1.handleAuthToken(credentialStatusResponse);
authToken = networkRequestHelper_1.handleAuthToken(credentialStatusResponse, authorization);
result = {

@@ -65,0 +65,0 @@ authToken: authToken,

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

apiResponse = _a.sent();
authToken = networkRequestHelper_1.handleAuthToken(apiResponse);
authToken = networkRequestHelper_1.handleAuthToken(apiResponse, authorization);
result = {

@@ -99,0 +99,0 @@ authToken: authToken,

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

restResp = _a.sent();
authToken = networkRequestHelper_1.handleAuthToken(restResp);
authToken = networkRequestHelper_1.handleAuthToken(restResp, authorization);
presentationRequestResponse = { body: __assign({}, restResp.body), authToken: authToken };

@@ -198,0 +198,0 @@ return [2 /*return*/, presentationRequestResponse];

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

}
authToken = networkRequestHelper_1.handleAuthToken(apiResponse);
authToken = networkRequestHelper_1.handleAuthToken(apiResponse, authorization);
result = {

@@ -102,0 +102,0 @@ authToken: authToken,

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

}
authToken = networkRequestHelper_1.handleAuthToken(didDocumentResponse);
authToken = networkRequestHelper_1.handleAuthToken(didDocumentResponse, authorization);
publicKeyObject = didHelper_1.getKeyFromDIDDoc(didDocumentResponse.body, 'secp256r1');

@@ -70,0 +70,0 @@ data = lodash_1.omit(credential, 'proof');

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

}
authToken = networkRequestHelper_1.handleAuthToken(didDocumentResponse);
authToken = networkRequestHelper_1.handleAuthToken(didDocumentResponse, authorization);
publicKeyInfos = didHelper_1.getKeyFromDIDDoc(didDocumentResponse.body, 'secp256r1');

@@ -148,3 +148,3 @@ _b = publicKeyInfos[0], publicKey = _b.publicKey, encoding = _b.encoding;

resp = _c.sent();
authToken = networkRequestHelper_1.handleAuthToken(resp);
authToken = networkRequestHelper_1.handleAuthToken(resp, authToken);
result = {

@@ -151,0 +151,0 @@ authToken: authToken,

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

}
authToken = networkRequestHelper_1.handleAuthToken(didDocumentResponse);
authToken = networkRequestHelper_1.handleAuthToken(didDocumentResponse, authorization);
publicKeyInfos = didHelper_1.getKeyFromDIDDoc(didDocumentResponse.body, 'secp256r1');

@@ -125,0 +125,0 @@ _b = publicKeyInfos[0], publicKey = _b.publicKey, encoding = _b.encoding;

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

}
authToken = networkRequestHelper_1.handleAuthToken(didDocumentResponse);
authToken = networkRequestHelper_1.handleAuthToken(didDocumentResponse, authorization);
pubKeyObj = didHelper_1.getKeyFromDIDDoc(didDocumentResponse.body, 'secp256r1');

@@ -397,3 +397,3 @@ if (pubKeyObj.length === 0) {

resp = _b.sent();
authToken = networkRequestHelper_1.handleAuthToken(resp);
authToken = networkRequestHelper_1.handleAuthToken(resp, authToken);
result = {

@@ -400,0 +400,0 @@ authToken: authToken,

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

@@ -47,3 +47,4 @@ "repository": "git@github.com:UnumID/Server-SDK-TypeScript.git",

"@unumid/library-crypto": "https://github.com/UnumID/Library-Crypto-TypeScript.git#v1.2.0",
"@unumid/types": "https://github.com/UnumID/types.git#2.0.0",
"@unumid/types": "https://github.com/UnumID/types.git#2.1.0",
"@unumid/types-v1": "https://github.com/UnumID/types.git#1.5.1",
"dotenv": "^8.2.0",

@@ -50,0 +51,0 @@ "express": "^4.17.1",

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

import { CredentialSubject, EncryptedCredentialOptions, EncryptedData, Proof, UnsignedCredential, Credential, JSONObj } from '@unumid/types';
import { UnsignedCredential as UnsignedCredentialV1, Credential as CredentialV1 } from '@unumid/types-v1';

@@ -15,2 +16,4 @@ import logger from '../logger';

import { convertCredentialSubject } from '../utils/convertCredentialSubject';
import { lt } from 'semver';
import { versionList } from '../utils/versionList';

@@ -58,2 +61,43 @@ /**

/**
* Creates an object of type EncryptedCredentialOptions which encapsulates information relating to the encrypted credential data
* @param cred Credential
* @param authorization String
*/
const constructEncryptedCredentialV1Opts = async (cred: CredentialV1, authorization: string): Promise<EncryptedCredentialOptions[]> => {
const credentialSubject: CredentialSubject = cred.credentialSubject;
const subjectDid = credentialSubject.id;
// resolve the subject's DID
const didDocResponse = await getDIDDoc(configData.SaaSUrl, authorization, subjectDid);
if (didDocResponse instanceof Error) {
throw didDocResponse;
}
// get subject's public key info from its DID document
const publicKeyInfos = getKeyFromDIDDoc(didDocResponse.body, 'RSA');
if (publicKeyInfos.length === 0) {
throw new CustError(404, 'Public key not found for the DID');
}
// create an encrypted copy of the credential with each RSA public key
return publicKeyInfos.map(publicKeyInfo => {
const subjectDidWithKeyFragment = `${subjectDid}#${publicKeyInfo.id}`;
const encryptedData: EncryptedData = doEncrypt(subjectDidWithKeyFragment, publicKeyInfo, cred);
const encryptedCredentialOptions: EncryptedCredentialOptions = {
credentialId: cred.id,
subject: subjectDidWithKeyFragment,
issuer: cred.issuer,
type: cred.type,
data: encryptedData
// version: '1.0.0'
};
return encryptedCredentialOptions;
});
};
/**
* Creates a signed credential with all the relevant information. The proof serves as a cryptographic signature.

@@ -79,3 +123,26 @@ * @param usCred UnsignedCredential

};
/**
* Creates a signed credential with all the relevant information. The proof serves as a cryptographic signature.
* @param usCred UnsignedCredential
* @param privateKey String
*/
const constructSignedCredentialV1Obj = (usCred: UnsignedCredentialV1, privateKey: string): CredentialV1 => {
const proof: Proof = createProof(usCred, privateKey, usCred.issuer, 'pem');
const credential: CredentialV1 = {
'@context': usCred['@context'],
credentialStatus: usCred.credentialStatus,
credentialSubject: usCred.credentialSubject,
issuer: usCred.issuer,
type: usCred.type,
id: usCred.id,
issuanceDate: usCred.issuanceDate,
expirationDate: usCred.expirationDate,
proof: proof
};
return (credential);
};
/**
* Creates all the attributes associated with an unsigned credential.

@@ -85,2 +152,4 @@ * @param credOpts CredentialOptions

const constructUnsignedCredentialObj = (credOpts: CredentialOptions): UnsignedCredential => {
// CredentialSubject type is dependent on version. V2 is a string for passing to holder so iOS can handle it as a concrete type instead of a map of unknown keys.
const credentialSubject = JSON.stringify(credOpts.credentialSubject);
const credentialId: string = getUUID();

@@ -93,3 +162,3 @@ const unsCredObj: UnsignedCredential = {

},
credentialSubject: JSON.stringify(credOpts.credentialSubject), // Converting the CredentialSubject type to a string for passing to holder. Really so iOS can handle it as a concrete type instead of a map of unknown keys.
credentialSubject,
issuer: credOpts.issuer,

@@ -102,6 +171,31 @@ type: ['VerifiableCredential', ...credOpts.type],

return (unsCredObj);
return unsCredObj as UnsignedCredential;
};
/**
* Creates all the attributes associated with an unsigned credential.
* @param credOpts CredentialOptions
*/
const constructUnsignedCredentialV1Obj = (credOpts: CredentialOptions, version: string): UnsignedCredentialV1 => {
// CredentialSubject type is dependent on version. V2 is a string for passing to holder so iOS can handle it as a concrete type instead of a map of unknown keys.
const credentialSubject = credOpts.credentialSubject;
const credentialId: string = getUUID();
const unsCredObj: UnsignedCredentialV1 = {
'@context': ['https://www.w3.org/2018/credentials/v1'],
credentialStatus: {
id: `${configData.SaaSUrl}/credentialStatus/${credentialId}`,
type: 'CredentialStatus'
},
credentialSubject,
issuer: credOpts.issuer,
type: ['VerifiableCredential', ...credOpts.type],
id: credentialId,
issuanceDate: new Date(),
expirationDate: credOpts.expirationDate
};
return unsCredObj;
};
/**
* Handle input validation.

@@ -194,3 +288,45 @@ * @param type

// Create the UnsignedCredential object
/**
* Need to loop through all versions except most recent so that can issued credentials could be backwards compatible with older holder versions.
* However only care to return the most recent Credential type for customers to use.
*/
for (let v = 0; v < versionList.length - 1; v++) { // note: purposely terminating one index early, which ought to be the most recent version.
const version: string = versionList[v];
// Create the UnsignedCredential object
const unsignedCredential: UnsignedCredentialV1 = constructUnsignedCredentialV1Obj(credentialOptions, version);
if (lt(version, '2.0.0')) {
// Create the signed Credential object from the unsignedCredential object
const credential: CredentialV1 = constructSignedCredentialV1Obj(unsignedCredential as UnsignedCredentialV1, signingPrivateKey);
// 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 = await constructEncryptedCredentialV1Opts(credential, authorization as string);
const encryptedCredentialUploadOptions = {
credentialId: credential.id,
subject: credentialSubject.id,
issuer: credential.issuer,
type: credential.type,
encryptedCredentials: encryptedCredentialOptions
};
const restData: RESTData = {
method: 'POST',
baseUrl: configData.SaaSUrl,
endPoint: 'credentialRepository',
header: { Authorization: authorization, version },
data: encryptedCredentialUploadOptions
};
const restResp: JSONObj = await makeNetworkRequest(restData);
authorization = handleAuthToken(restResp, authorization as string);
}
}
// Grabbing the latest version as defined in the version list, 2.0.0
const latestVersion: string = versionList[versionList.length - 1];
// Create latest version of the UnsignedCredential object
const unsignedCredential = constructUnsignedCredentialObj(credentialOptions);

@@ -216,3 +352,3 @@

endPoint: 'credentialRepository',
header: { Authorization: authorization },
header: { Authorization: authorization, version: latestVersion },
data: encryptedCredentialUploadOptions

@@ -223,3 +359,3 @@ };

const authToken: string = handleAuthToken(restResp);
const authToken: string = handleAuthToken(restResp, authorization as string);

@@ -226,0 +362,0 @@ const issuedCredential: UnumDto<Credential> = { body: credential, authToken };

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

const authToken: string = handleAuthToken(response);
const authToken: string = handleAuthToken(response, authorization);

@@ -53,0 +53,0 @@ const revokedCredential: UnumDto<undefined> = {

@@ -28,4 +28,4 @@ import { sign } from '@unumid/library-crypto';

logger.debug('Successfully created proof', proof);
logger.debug(`Successfully created proof ${proof}`);
return (proof);
};

@@ -8,2 +8,3 @@ import fetch from 'node-fetch';

import { JSONObj } from '@unumid/types';
import { versionList } from './versionList';

@@ -25,3 +26,3 @@ /**

...restHdr,
version: '1.0.0' // The api version to hit the UnumID SaaS with in the this version of the SDK
version: restHdr.version ? restHdr.version : versionList[versionList.length - 1] // The api version to hit the UnumID SaaS with in the this version of the SDK
}

@@ -55,3 +56,3 @@ };

*/
export const handleAuthToken = (response:JSONObj): string => {
export const handleAuthToken = (response:JSONObj, existingAuthToken?:string): string => {
const authTokenResp = response && response.headers && response.headers['x-auth-token'] ? response.headers['x-auth-token'] : '';

@@ -61,5 +62,5 @@

const authToken: string = <string>(isArrayEmpty(authTokenResp) && authTokenResp ? authTokenResp : (isArrayNotEmpty(authTokenResp) ? authTokenResp[0] : undefined));
// If authToken is undefined just return undefined, otherwise return a properly formatted Bearer token for use in subsequent requests.
const result = authToken ? (authToken.startsWith('Bearer ') ? authToken : `Bearer ${authToken}`) : authToken;
// If authToken is undefined see if the input existing auth token is a valid Bearer token (not an admin key), if an admin key just return undefined, otherwise return a properly formatted Bearer token for use in subsequent requests or the existing, inputting token.
const result = authToken ? (authToken.startsWith('Bearer ') ? authToken : `Bearer ${authToken}`) : (existingAuthToken?.startsWith('Bearer ') ? existingAuthToken : authToken);
return result;
};

@@ -20,3 +20,3 @@ import { CredentialStatus, CredentialStatusInfo, UnumDto } from '../types';

const credentialStatus = credentialStatusResponse.body;
const authToken: string = handleAuthToken(credentialStatusResponse);
const authToken: string = handleAuthToken(credentialStatusResponse, authorization);

@@ -23,0 +23,0 @@ const result: UnumDto<CredentialStatusInfo> = {

@@ -65,3 +65,3 @@ import { ExternalChannelMessageInput } from '@unumid/types';

const authToken: string = handleAuthToken(apiResponse);
const authToken: string = handleAuthToken(apiResponse, authorization);

@@ -68,0 +68,0 @@ const result: UnumDto<undefined> = {

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

const authToken: string = handleAuthToken(restResp);
const authToken: string = handleAuthToken(restResp, authorization);

@@ -200,0 +200,0 @@ const presentationRequestResponse: UnumDto<PresentationRequestPostDto> = { body: { ...restResp.body }, authToken };

@@ -70,3 +70,3 @@ import { ExternalChannelMessageInput } from '@unumid/types';

const authToken: string = handleAuthToken(apiResponse);
const authToken: string = handleAuthToken(apiResponse, authorization);

@@ -73,0 +73,0 @@ const result: UnumDto<undefined> = {

@@ -26,3 +26,3 @@

const authToken: string = handleAuthToken(didDocumentResponse);
const authToken: string = handleAuthToken(didDocumentResponse, authorization);
const publicKeyObject = getKeyFromDIDDoc(didDocumentResponse.body, 'secp256r1');

@@ -29,0 +29,0 @@ const data = omit(credential, 'proof');

@@ -92,3 +92,3 @@

let authToken: string = handleAuthToken(didDocumentResponse);
let authToken: string = handleAuthToken(didDocumentResponse, authorization);
const publicKeyInfos = getKeyFromDIDDoc(didDocumentResponse.body, 'secp256r1');

@@ -132,3 +132,3 @@

authToken = handleAuthToken(resp);
authToken = handleAuthToken(resp, authToken);

@@ -135,0 +135,0 @@ const result: UnumDto<VerifiedStatus> = {

@@ -80,3 +80,3 @@

const authToken: string = handleAuthToken(didDocumentResponse);
const authToken: string = handleAuthToken(didDocumentResponse, authorization);
const publicKeyInfos = getKeyFromDIDDoc(didDocumentResponse.body, 'secp256r1');

@@ -83,0 +83,0 @@

@@ -287,3 +287,3 @@ import { omit } from 'lodash';

let authToken: string = handleAuthToken(didDocumentResponse); // Note: going to use authToken instead of authorization for subsequent requests in case saas rolls to token.
let authToken: string = handleAuthToken(didDocumentResponse, authorization); // Note: going to use authToken instead of authorization for subsequent requests in case saas rolls to token.
const pubKeyObj: PublicKeyInfo[] = getKeyFromDIDDoc(didDocumentResponse.body, 'secp256r1');

@@ -403,3 +403,3 @@

const resp: JSONObj = await makeNetworkRequest<JSONObj>(receiptCallOptions);
authToken = handleAuthToken(resp);
authToken = handleAuthToken(resp, authToken);

@@ -406,0 +406,0 @@ const result: UnumDto<VerifiedStatus> = {

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

mockGetDIDDoc.mockResolvedValue({ body: dummyDidDoc, headers });
mockMakeNetworkRequest.mockResolvedValueOnce({ body: { success: true }, headers });
mockMakeNetworkRequest.mockResolvedValue({ body: { success: true }, headers });

@@ -89,10 +89,22 @@ responseDto = await callIssueCreds(credentialSubject, type, issuer, expirationDate, eccPrivateKey, authHeader);

it('encrypts the credential for each public key', () => {
expect(mockDoEncrypt).toBeCalledTimes(2);
expect(mockDoEncrypt).toBeCalledTimes(4);
});
it('sends the encrypted credentials to the saas', () => {
it('sends encrypted credentials of all versions (1,2) to the saas', () => {
expect(mockMakeNetworkRequest).toBeCalled();
expect(mockMakeNetworkRequest.mock.calls.length).toEqual(2);
});
it('sends the encrypted credentials v1 to the saas', () => {
expect(mockMakeNetworkRequest).toBeCalled();
expect(mockMakeNetworkRequest.mock.calls[0][0].data.encryptedCredentials.length).toEqual(2);
expect(mockMakeNetworkRequest.mock.calls[0][0].header.version).toEqual('1.0.0');
});
it('sends the encrypted credentials v2 to the saas', () => {
expect(mockMakeNetworkRequest).toBeCalled();
expect(mockMakeNetworkRequest.mock.calls[1][0].data.encryptedCredentials.length).toEqual(2);
expect(mockMakeNetworkRequest.mock.calls[1][0].header.version).toEqual('2.0.0');
});
it('returns the credential', () => {

@@ -111,3 +123,3 @@ expect(response.id).toBeDefined();

it('does not return an auth token if the SaaS does not return an auth token', async () => {
mockMakeNetworkRequest.mockResolvedValueOnce({ body: { success: true } });
mockMakeNetworkRequest.mockResolvedValue({ body: { success: true } });
response = await callIssueCreds(credentialSubject, type, issuer, expirationDate, eccPrivateKey, dummyAdminKey);

@@ -119,3 +131,3 @@ responseAuthToken = response.authToken;

it('type array starts with and contains only one `VerifiableCredential` string despite type of the credential options including the preceeding string', async () => {
mockMakeNetworkRequest.mockResolvedValueOnce({ body: { success: true } });
mockMakeNetworkRequest.mockResolvedValue({ body: { success: true } });
response = await callIssueCreds(credentialSubject, type, issuer, expirationDate, eccPrivateKey, dummyAdminKey);

@@ -122,0 +134,0 @@ const types = response.body.type;

@@ -6,2 +6,3 @@ import express from 'express';

import bodyParser from 'body-parser';
import { versionList } from '../../src/utils/versionList';

@@ -93,1 +94,12 @@ const initServer = (): express.Application => {

});
describe('Version list definitions for default saas version header', () => {
it('Check that the version list has at least two versions: 1.0.0 & 2.0.0', async () => {
expect(versionList.length).toEqual(2);
expect(versionList[0]).toEqual('1.0.0');
expect(versionList[1]).toEqual('2.0.0');
// expecting latest version to be 2.0.0
expect(versionList[versionList.length - 1]).toEqual('2.0.0');
});
});

@@ -7,2 +7,3 @@ import fetch from 'node-fetch';

import { CustError } from '../../src/utils/error';
import { dummyAuthToken } from './mocks';

@@ -46,3 +47,3 @@ jest.mock('node-fetch');

body: JSON.stringify({ to, deeplink }),
headers: { Authorization: auth, 'Content-Type': 'application/json', version: '1.0.0' }
headers: { Authorization: auth, 'Content-Type': 'application/json', version: '2.0.0' }
};

@@ -78,3 +79,3 @@

apiResponseAuthToken = apiResponse.authToken;
expect(apiResponseAuthToken).toBe(undefined);
expect(apiResponseAuthToken).toBe(dummyAuthToken);
});

@@ -81,0 +82,0 @@ });

@@ -7,2 +7,3 @@ import fetch from 'node-fetch';

import { CustError } from '../../src/utils/error';
import { dummyAuthToken } from './mocks';

@@ -45,3 +46,3 @@ jest.mock('node-fetch');

body: JSON.stringify({ to, deeplink }),
headers: { Authorization: auth, 'Content-Type': 'application/json', version: '1.0.0' }
headers: { Authorization: auth, 'Content-Type': 'application/json', version: '2.0.0' }
};

@@ -82,3 +83,3 @@

apiResponseAuthToken = apiResponse.authToken;
expect(apiResponseAuthToken).toBe(undefined);
expect(apiResponseAuthToken).toBe(dummyAuthToken);
});

@@ -85,0 +86,0 @@ });

@@ -118,3 +118,4 @@ import { omit } from 'lodash';

response = await callVerifyNoPresentation(dummyNoPresentation, verifier, authHeader);
expect(response.authToken).toBeUndefined();
expect(response.authToken).toBe(authHeader);
});

@@ -121,0 +122,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

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

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc