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 3.24.1 to 3.25.0

1

build/config.d.ts
declare const configData: {
nodeEnv: string;
SaaSUrl: string;
unumWalletHolderApp: string;
debug: boolean;

@@ -5,0 +6,0 @@ logLevel: string;

@@ -31,2 +31,20 @@ "use strict";

}
/**
* Get saas url based on the provide UNUM_ENV env var.
* @param env
*/
function getUnumHolderAppUuid(env) {
switch (env) {
case 'local':
return '86810c13-47b4-4a2b-ae46-fb13b6a5177a';
case 'dev':
return '86810c13-47b4-4a2b-ae46-fb13b6a5177a';
case 'sandbox':
return 'b8820ef7-8ae8-4fa9-9a99-84629b2ea147';
case 'production':
return '7a1b0e37-efda-4b92-873b-ad7a8491175d';
default:
return 'b8820ef7-8ae8-4fa9-9a99-84629b2ea147';
}
}
// defaults to sandbox if not provided

@@ -37,2 +55,3 @@ var env = process.env.UNUM_ENV || 'sandbox';

SaaSUrl: process.env.UNUM_SAAS_URL || getSaasUrl(env),
unumWalletHolderApp: getUnumHolderAppUuid(env),
debug: process.env.UNUM_DEBUG === 'true' || process.env.DEBUG === 'true' || false,

@@ -39,0 +58,0 @@ logLevel: process.env.UNUM_LOG_LEVEL || process.env.LOG_LEVEL || 'info' // Winston defaults to info if not set however being explicit here

10

build/utils/verifyDidDocument.js

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

authToken = authorization;
return [4 /*yield*/, verifyDid(authToken, signedDid)];
return [4 /*yield*/, verifyDidSignature(authToken, signedDid)];
case 1:

@@ -103,3 +103,9 @@ result = _b.sent();

exports.verifySignedDid = verifySignedDid;
function verifyDid(authToken, did) {
/**
* Helper function to verify a Did signature.
* @param authToken
* @param did
* @returns
*/
function verifyDidSignature(authToken, did) {
return __awaiter(this, void 0, void 0, function () {

@@ -106,0 +112,0 @@ var verificationMethod, signatureValue, publicKeyInfoResponse, publicKeyInfoList, unsignedDid, bytes, isVerified, _i, publicKeyInfoList_1, publicKeyInfo, result_1, result;

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

import { PresentationRequestPostDto as PresentationRequestPostDtoDeprecatedV2, UnsignedPresentationRequest as UnsignedPresentationRequestDeprecatedV2, SignedPresentationRequest as SignedPresentationRequestDeprecatedV2 } from '@unumid/types-v2';
import { UnsignedPresentationRequest as UnsignedPresentationRequestDeprecatedV2, SignedPresentationRequest as SignedPresentationRequestDeprecatedV2 } from '@unumid/types-v2';
import { CredentialRequest, UnsignedPresentationRequestPb, PresentationRequestPb, CredentialRequestPb, PresentationRequestDto } from '@unumid/types';

@@ -30,3 +30,3 @@ import { SendRequestReqBody, UnumDto } from '../types';

*/
export declare const sendRequest: (authorization: string, verifier: string, credentialRequests: CredentialRequestPb[] | CredentialRequest[], eccPrivateKey: string, holderAppUuid: string, expirationDate?: Date | undefined, metadata?: Record<string, unknown> | undefined) => Promise<UnumDto<PresentationRequestDto>>;
export declare const sendRequest: (authorization: string, verifier: string, credentialRequests: CredentialRequestPb[] | CredentialRequest[], eccPrivateKey: string, holderAppUuid?: string, expirationDate?: Date | undefined, metadata?: Record<string, unknown> | undefined) => Promise<UnumDto<PresentationRequestDto>>;
/**

@@ -41,11 +41,2 @@ * Handler for sending a PresentationRequest to UnumID's SaaS.

export declare const sendRequestV3: (authorization: string, verifier: string, credentialRequests: CredentialRequestPb[], eccPrivateKey: string, holderAppUuid: string, id: string, expirationDate?: Date | undefined, metadata?: any) => Promise<UnumDto<PresentationRequestDto>>;
/**
* Handler for sending a PresentationRequest to UnumID's SaaS.
* @param authorization
* @param verifier
* @param credentialRequests
* @param eccPrivateKey
* @param holderAppUuid
*/
export declare const sendRequestDeprecated: (authorization: string, verifier: string, credentialRequests: CredentialRequest[], eccPrivateKey: string, holderAppUuid: string, id: string, expirationDate?: Date | undefined, metadata?: Record<string, unknown> | undefined) => Promise<UnumDto<PresentationRequestPostDtoDeprecatedV2>>;
//# sourceMappingURL=sendRequest.d.ts.map

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.sendRequestDeprecated = exports.sendRequestV3 = exports.sendRequest = exports.constructSignedPresentationRequest = exports.constructSignedPresentationRequestDeprecatedV2 = exports.constructUnsignedPresentationRequest = void 0;
exports.sendRequestV3 = exports.sendRequest = exports.constructSignedPresentationRequest = exports.constructSignedPresentationRequestDeprecatedV2 = exports.constructUnsignedPresentationRequest = void 0;
var config_1 = require("../config");

@@ -283,10 +283,14 @@ var requireAuth_1 = require("../requireAuth");

*/
exports.sendRequest = function (authorization, verifier, credentialRequests, eccPrivateKey, holderAppUuid, expirationDate, metadata) { return __awaiter(void 0, void 0, void 0, function () {
var id, response;
return __generator(this, function (_a) {
id = helpers_1.getUUID();
response = exports.sendRequestV3(authorization, verifier, credentialRequests, eccPrivateKey, holderAppUuid, id, expirationDate, metadata);
return [2 /*return*/, response];
exports.sendRequest = function (authorization, verifier, credentialRequests, eccPrivateKey, holderAppUuid, // defaults to the Unum ID Wallet Holder if no value is present
expirationDate, metadata) {
if (holderAppUuid === void 0) { holderAppUuid = config_1.configData.unumWalletHolderApp; }
return __awaiter(void 0, void 0, void 0, function () {
var id, response;
return __generator(this, function (_a) {
id = helpers_1.getUUID();
response = exports.sendRequestV3(authorization, verifier, credentialRequests, eccPrivateKey, holderAppUuid, id, expirationDate, metadata);
return [2 /*return*/, response];
});
});
}); };
};
/**

@@ -333,43 +337,2 @@ * Handler for sending a PresentationRequest to UnumID's SaaS.

}); };
/**
* Handler for sending a PresentationRequest to UnumID's SaaS.
* @param authorization
* @param verifier
* @param credentialRequests
* @param eccPrivateKey
* @param holderAppUuid
*/
exports.sendRequestDeprecated = function (authorization, verifier, credentialRequests, eccPrivateKey, holderAppUuid, id, expirationDate, metadata) { return __awaiter(void 0, void 0, void 0, function () {
var body, unsignedPresentationRequest, signedPR, restData, restResp, authToken, presentationRequestResponse, error_3;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
requireAuth_1.requireAuth(authorization);
body = { verifier: verifier, credentialRequests: credentialRequests, eccPrivateKey: eccPrivateKey, holderAppUuid: holderAppUuid, expiresAt: expirationDate, metadata: metadata, id: id };
// Validate inputs
validateSendRequestBodyDeprecated(body);
unsignedPresentationRequest = exports.constructUnsignedPresentationRequest(body, '2.0.0');
signedPR = exports.constructSignedPresentationRequestDeprecatedV2(unsignedPresentationRequest, eccPrivateKey);
restData = {
method: 'POST',
baseUrl: config_1.configData.SaaSUrl,
endPoint: 'presentationRequest',
header: { Authorization: authorization, version: '2.0.0' },
data: signedPR
};
return [4 /*yield*/, networkRequestHelper_1.makeNetworkRequest(restData)];
case 1:
restResp = _a.sent();
authToken = networkRequestHelper_1.handleAuthTokenHeader(restResp, authorization);
presentationRequestResponse = { body: __assign({}, restResp.body), authToken: authToken };
return [2 /*return*/, presentationRequestResponse];
case 2:
error_3 = _a.sent();
logger_1.default.error("Error sending request to use UnumID Saas. " + error_3);
throw error_3;
case 3: return [2 /*return*/];
}
});
}); };
//# sourceMappingURL=sendRequest.js.map
{
"name": "@unumid/server-sdk",
"version": "3.24.1",
"version": "3.25.0",
"main": "build/index.js",

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

@@ -223,3 +223,2 @@ # Unum ID Typescript Server-SDK

{
"authorization": string // auth token
"issuerDid": string // the did of your issuer

@@ -239,2 +238,35 @@ "subjectDid": string // the did of the subject

### verifySignedDid
Verify a signed Decentralized Identifier.
You need to provide the your issuer's `did` along with the signed DID object.
The DID string is signed by the subject's ECC private key. This function verifies the cryptographic signature is valid.
The main use case is for the `/userCredentialRequests` required Issuer endpoint. It facilitates getting DID information for users within your service. The User DID is necessary to then issue re-usable identity credentials to.
```typescript
export type DID = {
id: string; // the string matching the desire credential type
proof: Proof; //list of acceptable issuer DIDs that have issued the credential
}
```
Parameters
```typescript
{
"issuerDid": string // the did of your issuer
"signedDid": DID // the signed DID object
}
```
Response Body: [**VerifiedStatus**].
```typescript
export interface VerifiedStatus {
isVerified: boolean; // returns true if the signature of the DID is verified to be signed by the DID signing key
message?: string; // (optional) only populated iff isVerified is false
}
```
## Verifier

@@ -241,0 +273,0 @@ The Verifier functionality is used by a customer acting as a verifier. Most importantly, it allows customers to send PresentationRequests to the UnumID mobile SDK and to verify the encrypted Presentation responses.

@@ -28,2 +28,21 @@ /*

/**
* Get saas url based on the provide UNUM_ENV env var.
* @param env
*/
function getUnumHolderAppUuid (env: string) {
switch (env) {
case 'local':
return '86810c13-47b4-4a2b-ae46-fb13b6a5177a';
case 'dev':
return '86810c13-47b4-4a2b-ae46-fb13b6a5177a';
case 'sandbox':
return 'b8820ef7-8ae8-4fa9-9a99-84629b2ea147';
case 'production':
return '7a1b0e37-efda-4b92-873b-ad7a8491175d';
default:
return 'b8820ef7-8ae8-4fa9-9a99-84629b2ea147';
}
}
// defaults to sandbox if not provided

@@ -35,2 +54,3 @@ const env = process.env.UNUM_ENV || 'sandbox';

SaaSUrl: process.env.UNUM_SAAS_URL || getSaasUrl(env),
unumWalletHolderApp: getUnumHolderAppUuid(env),
debug: process.env.UNUM_DEBUG === 'true' || process.env.DEBUG === 'true' || false,

@@ -37,0 +57,0 @@ logLevel: process.env.UNUM_LOG_LEVEL || process.env.LOG_LEVEL || 'info' // Winston defaults to info if not set however being explicit here

@@ -44,3 +44,3 @@

const result: UnumDto<VerifiedStatus> = await verifyDid(authToken, signedDid);
const result: UnumDto<VerifiedStatus> = await verifyDidSignature(authToken, signedDid);
const { isVerified, message } = result.body;

@@ -61,3 +61,9 @@ authToken = result.authToken;

async function verifyDid (authToken: string, did: DID): Promise<UnumDto<VerifiedStatus>> {
/**
* Helper function to verify a Did signature.
* @param authToken
* @param did
* @returns
*/
async function verifyDidSignature (authToken: string, did: DID): Promise<UnumDto<VerifiedStatus>> {
const verificationMethod = did.proof.verificationMethod as string;

@@ -64,0 +70,0 @@ const signatureValue = did.proof.signatureValue as string;

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

eccPrivateKey: string,
holderAppUuid: string,
holderAppUuid: string = configData.unumWalletHolderApp, // defaults to the Unum ID Wallet Holder if no value is present
expirationDate?: Date,

@@ -327,6 +327,2 @@ metadata?: Record<string, unknown>

// // create and send a v2 presentation request for backwards compatibility
// const responseV2 = await sendRequestDeprecated(authorization, verifier, credentialRequests, eccPrivateKey, holderAppUuid, id, expirationDate, metadata);
// authorization = responseV2.authToken ? responseV2.authToken : authorization;
const response = sendRequestV3(authorization, verifier, credentialRequests, eccPrivateKey, holderAppUuid, id, expirationDate, metadata);

@@ -388,53 +384,1 @@ return response;

};
/**
* Handler for sending a PresentationRequest to UnumID's SaaS.
* @param authorization
* @param verifier
* @param credentialRequests
* @param eccPrivateKey
* @param holderAppUuid
*/
export const sendRequestDeprecated = async (
authorization:string,
verifier: string,
credentialRequests: CredentialRequest[],
eccPrivateKey: string,
holderAppUuid: string,
id: string,
expirationDate?: Date,
metadata?: Record<string, unknown>
): Promise<UnumDto<PresentationRequestPostDtoDeprecatedV2>> => {
try {
requireAuth(authorization);
const body: SendRequestReqBody = { verifier, credentialRequests, eccPrivateKey, holderAppUuid, expiresAt: expirationDate, metadata, id };
// Validate inputs
validateSendRequestBodyDeprecated(body);
const unsignedPresentationRequest: UnsignedPresentationRequestDeprecatedV2 = constructUnsignedPresentationRequest(body, '2.0.0');
// Create the signed presentation object from the unsignedPresentation object
const signedPR = constructSignedPresentationRequestDeprecatedV2(unsignedPresentationRequest, eccPrivateKey);
const restData: RESTData = {
method: 'POST',
baseUrl: configData.SaaSUrl,
endPoint: 'presentationRequest',
header: { Authorization: authorization, version: '2.0.0' },
data: signedPR
};
const restResp = await makeNetworkRequest<PresentationRequestPostDto>(restData);
const authToken: string = handleAuthTokenHeader(restResp, authorization);
const presentationRequestResponse: UnumDto<PresentationRequestPostDto> = { body: { ...restResp.body }, authToken };
return presentationRequestResponse as UnumDto<PresentationRequestPostDtoDeprecatedV2>;
} catch (error) {
logger.error(`Error sending request to use UnumID Saas. ${error}`);
throw error;
}
};

@@ -431,23 +431,2 @@ import { CredentialRequest, PresentationRequestPostDto, PresentationRequest } from '@unumid/types';

it('returns a 400 status code with a descriptive error message when holderAppUuid is missing', async () => {
const credRequest: CredentialRequest = { issuers: credentialRequests[0].issuers, type: undefined };
try {
await callSendRequests(
verifier,
credentialRequests,
metadata,
expiresAt,
eccPrivateKey,
undefined as unknown as string,
authToken
);
fail();
} catch (e) {
expect(e).toEqual(new CustError(400, 'Invalid PresentationRequest options: holderAppUuid is required.'));
expect(e.code).toEqual(400);
expect(e.message).toEqual('Invalid PresentationRequest options: holderAppUuid is required.');
}
});
it('returns a 400 status code with a descriptive error message when holderAppUuid is not a string', async () => {

@@ -454,0 +433,0 @@ const credRequest: CredentialRequest = { issuers: credentialRequests[0].issuers, type: undefined };

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