Skip to content

Commit

Permalink
Merge pull request #156 from hypersign-protocol/HSSTUD-256
Browse files Browse the repository at this point in the history
some changes based on updated hs-ssi-sdk
  • Loading branch information
Pratap2018 authored Aug 7, 2023
2 parents 26216a8 + 91aaf91 commit 1623ec0
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 236 deletions.
4 changes: 2 additions & 2 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"express": "^4.17.1",
"express-validator": "^6.14.2",
"hid-hd-wallet": "git+https://github.com/hypersign-protocol/hid-hd-wallet.git#ssi-integration",
"hs-ssi-sdk": "github:hypersign-protocol/hs-ssi-sdk#fix-org-cred",
"hypersign-auth-node-sdk": "^6.1.0",
"hs-ssi-sdk": "github:hypersign-protocol/hs-ssi-sdk#develop",
"hypersign-auth-node-sdk": "git+https://github.com/hypersign-protocol/hypersign-auth-node-sdk.git#registration-on-registry-optional",
"jsonwebtoken": "^8.5.1",
"lds-sdk": "^4.0.1",
"mongoose": "^6.5.2",
Expand Down
24 changes: 12 additions & 12 deletions server/src/controllers/pController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { uuid } from 'uuidv4';
import ApiResponse from '../response/apiResponse';

import HIDWallet from 'hid-hd-wallet';
import HypersignSsiSDK from 'hs-ssi-sdk';
import { HypersignSSISdk } from 'hs-ssi-sdk';
import { walletOptions, mnemonic } from '../config';

const verifyPresentation = async (vp, challenge, issuerDid, holderDid, domain, holderDidDocSigned) => {
Expand All @@ -25,16 +25,16 @@ const verifyPresentation = async (vp, challenge, issuerDid, holderDid, domain, h
// TODO: This initialization need to be done one time globally
const hidWalletInstance = new HIDWallet(walletOptions);
await hidWalletInstance.generateWallet({ mnemonic });
const hsSdk = new HypersignSsiSDK(
hidWalletInstance.offlineSigner,
walletOptions.hidNodeRPCUrl,
walletOptions.hidNodeRestUrl,
'testnet'
);
const hsSdk = new HypersignSSISdk({
offlineSigner: hidWalletInstance.offlineSigner,
nodeRpcEndpoint: walletOptions.hidNodeRPCUrl,
nodeRestEndpoint: walletOptions.hidNodeRestUrl,
namespace: 'testnet',
});
await hsSdk.init();
const holderVerificationMethodId = vp.proof.verificationMethod;
const issuerVerificationMethodId = vp.verifiableCredential[0].proof.verificationMethod;
const result = await hsSdk.vp.verifyPresentation({
const result = await hsSdk.vp.verify({
signedPresentation: vp,
challenge,
domain,
Expand Down Expand Up @@ -107,8 +107,8 @@ export async function verify(req, res, next) {
holderDidDocSigned
);

const { verified } = result;
logger.debug(`Result of credential verification ${result.verified}`);
const verified = result['verified'];
logger.debug(`Result of credential verification ${result['verified']}`);
if (verified === true) {
// TODO: 4. send data or create JWT

Expand All @@ -119,7 +119,7 @@ export async function verify(req, res, next) {
holderDid: presentationInfo.holder,
credentialId: presentationInfo.verifiableCredential[0].id,
credentialDetail: presentationInfo.verifiableCredential[0].credentialSubject,
presentation: presentationInfo
presentation: presentationInfo,
});
const accessToken = JWT.sign({ id: userCredInfo._id }, jwtSecret, { expiresIn: '5m' });
PresentationRequestSchema.findOneAndUpdate({ challenge: challenge }, { status: 1, accessToken }).exec();
Expand Down Expand Up @@ -179,7 +179,7 @@ export async function getChallenge(req, res, next) {
appName: name,
challenge,
reason,
domain
domain,
},
};

Expand Down
14 changes: 7 additions & 7 deletions server/src/controllers/presentationController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Request, Response, NextFunction } from 'express';
import PresentationTemplateSchema, { IPresentationTemplate } from '../models/presentationTemplateSchema';

import HIDWallet from 'hid-hd-wallet';
import HypersignSsiSDK from 'hs-ssi-sdk';
import { HypersignSSISdk } from 'hs-ssi-sdk';
import { walletOptions, mnemonic, logger } from '../config';
import ApiResponse from '../response/apiResponse';

Expand All @@ -15,12 +15,12 @@ const verifyPresentation = async (req: Request, res: Response, next: NextFunctio
hidWalletInstance
.generateWallet({ mnemonic })
.then(async () => {
hsSdk = new HypersignSsiSDK(
hidWalletInstance.offlineSigner,
walletOptions.hidNodeRPCUrl,
walletOptions.hidNodeRestUrl,
'devnet'
);
hsSdk = new HypersignSSISdk({
offlineSigner: hidWalletInstance.offlineSigner,
nodeRpcEndpoint: walletOptions.hidNodeRPCUrl,
nodeRestEndpoint: walletOptions.hidNodeRestUrl,
namespace: 'testnet',
});
return hsSdk.init();
})
.then(async () => {
Expand Down
213 changes: 0 additions & 213 deletions server/src/controllers/presentationRequestController.ts

This file was deleted.

2 changes: 1 addition & 1 deletion server/src/models/userCredentialInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ export const UserCredential = new Schema({
holderDid: { type: String, required: true },
credentialId: { type: String, required: true },
credentialDetail: { type: Object, required: true },
presentation: { type: Object, required: true }
presentation: { type: Object, required: true },
});
export default mongoose.model<IUserPresentation>('userCredDetail', UserCredential);
2 changes: 1 addition & 1 deletion server/src/services/db.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export class DBService {
logger.debug(`Values = `, values);
db.all(query, values, (err, rows) => {
if (err) return reject(err);
return resolve(rows);
return resolve(rows as object[]);
});
});
}
Expand Down

0 comments on commit 1623ec0

Please sign in to comment.