Skip to content

Commit

Permalink
remove trace
Browse files Browse the repository at this point in the history
  • Loading branch information
Kolezhniuk committed Jul 18, 2023
1 parent 1cabc5e commit bb3fd7c
Showing 1 changed file with 50 additions and 58 deletions.
108 changes: 50 additions & 58 deletions src/iden3comm/handlers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,72 +139,64 @@ export class AuthHandler implements IAuthHandler {
authRequest: AuthorizationRequestMessage;
authResponse: AuthorizationResponseMessage;
}> {
try {
const {
did,
request,
packer: { mediaType, ...packerParams }
} = options;

const { unpackedMessage: message } = await this._packerMgr.unpack(request);
const authRequest = message as unknown as AuthorizationRequestMessage;
if (message.type !== PROTOCOL_MESSAGE_TYPE.AUTHORIZATION_REQUEST_MESSAGE_TYPE) {
throw new Error('Invalid media type');
}
const authRequestBody = message.body as unknown as AuthorizationRequestMessageBody;

const guid = uuid.v4();
const authResponse: AuthorizationResponseMessage = {
id: guid,
typ: mediaType,
type: PROTOCOL_MESSAGE_TYPE.AUTHORIZATION_RESPONSE_MESSAGE_TYPE,
thid: message.thid ?? guid,
body: {
did_doc: undefined, // slipped for now, todo: get did doc for id
message: authRequestBody.message,
scope: []
},
from: options.did.string(),
to: message.from
};
const {
did,
request,
packer: { mediaType, ...packerParams }
} = options;

for (const proofReq of authRequestBody.scope) {
const zkpReq: ZeroKnowledgeProofRequest = {
id: proofReq.id,
circuitId: proofReq.circuitId as CircuitId,
query: proofReq.query
};
const { unpackedMessage: message } = await this._packerMgr.unpack(request);
const authRequest = message as unknown as AuthorizationRequestMessage;
if (message.type !== PROTOCOL_MESSAGE_TYPE.AUTHORIZATION_REQUEST_MESSAGE_TYPE) {
throw new Error('Invalid media type');
}
const authRequestBody = message.body as unknown as AuthorizationRequestMessageBody;

const creds = await this._credentialWallet.findByQuery(proofReq.query);
const guid = uuid.v4();
const authResponse: AuthorizationResponseMessage = {
id: guid,
typ: mediaType,
type: PROTOCOL_MESSAGE_TYPE.AUTHORIZATION_RESPONSE_MESSAGE_TYPE,
thid: message.thid ?? guid,
body: {
did_doc: undefined, // slipped for now, todo: get did doc for id
message: authRequestBody.message,
scope: []
},
from: options.did.string(),
to: message.from
};

const credsForGenesisDID = await this._credentialWallet.filterByCredentialSubject(
creds,
did
);
if (credsForGenesisDID.length == 0) {
throw new Error(`no credential were issued on the given id ${did.string()}`);
}
for (const proofReq of authRequestBody.scope) {
const zkpReq: ZeroKnowledgeProofRequest = {
id: proofReq.id,
circuitId: proofReq.circuitId as CircuitId,
query: proofReq.query
};

const zkpRes: ZeroKnowledgeProofResponse = await this._proofService.generateProof(
zkpReq,
did,
credsForGenesisDID[0]
);
const creds = await this._credentialWallet.findByQuery(proofReq.query);

authResponse.body.scope.push(zkpRes);
const credsForGenesisDID = await this._credentialWallet.filterByCredentialSubject(creds, did);
if (credsForGenesisDID.length == 0) {
throw new Error(`no credential were issued on the given id ${did.string()}`);
}
const msgBytes = byteEncoder.encode(JSON.stringify(authResponse));
const token = byteDecoder.decode(
await this._packerMgr.pack(mediaType, msgBytes, {
senderDID: did,
...packerParams
})

const zkpRes: ZeroKnowledgeProofResponse = await this._proofService.generateProof(
zkpReq,
did,
credsForGenesisDID[0]
);
return { authRequest, authResponse, token };
} catch (e) {
console.trace(e);
throw e;

authResponse.body.scope.push(zkpRes);
}
const msgBytes = byteEncoder.encode(JSON.stringify(authResponse));
const token = byteDecoder.decode(
await this._packerMgr.pack(mediaType, msgBytes, {
senderDID: did,
...packerParams
})
);
return { authRequest, authResponse, token };
}

/**
Expand Down

0 comments on commit bb3fd7c

Please sign in to comment.