Skip to content

Commit

Permalink
fix: add subject in claim request
Browse files Browse the repository at this point in the history
  • Loading branch information
JGiter committed Apr 8, 2021
1 parent c65e883 commit 7859337
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/iam.ts
Expand Up @@ -1285,22 +1285,25 @@ export class IAM extends IAMBase {
async createClaimRequest({
issuer,
claim,
did = this._did
subject
}: {
issuer: string[];
claim: { claimType: string; fields: { key: string; value: string | number }[] };
did?: string;
subject?: string;
}) {
if (!did) {
if (!this._did) {
throw new Error(ERROR_MESSAGES.USER_NOT_LOGGED_IN);
}
if (!subject) {
subject = this._did;
}

const [roleDefinition, didDocument] = await Promise.all([
this.getDefinition({
type: ENSNamespaceTypes.Roles,
namespace: claim.claimType
}),
this.getDidDocument({ did, includeClaims: true })
this.getDidDocument({ did: subject, includeClaims: true })
]);

if (!roleDefinition) {
Expand All @@ -1311,17 +1314,17 @@ export class IAM extends IAMBase {

this.verifyEnrolmentPreconditions({ claims: didDocument.service, enrolmentPreconditions });

const token = await this.createPublicClaim({ data: claim, subject: claim.claimType });
const token = await this.createPublicClaim({ data: claim, subject });
const message: IClaimRequest = {
id: uuid(),
token,
claimIssuer: issuer,
requester: did
requester: this._did,
};

if (!this._natsConnection) {
if (this._cacheClient) {
return this._cacheClient.requestClaim({ did, message });
return this._cacheClient.requestClaim({ did: subject, message });
}
throw new NATSConnectionNotEstablishedError();
}
Expand All @@ -1334,11 +1337,11 @@ export class IAM extends IAMBase {
}

async issueClaimRequest({
requesterDID,
requester,
id,
token
}: {
requesterDID: string;
requester: string;
token: string;
id: string;
}) {
Expand All @@ -1350,7 +1353,7 @@ export class IAM extends IAMBase {
const preparedData: IClaimIssuance = {
id,
issuedToken,
requester: requesterDID,
requester: requester,
claimIssuer: [this._did],
acceptedBy: this._did
};
Expand All @@ -1363,7 +1366,7 @@ export class IAM extends IAMBase {
}

const dataToSend = this._jsonCodec?.encode(preparedData);
this._natsConnection.publish(`${requesterDID}.${NATS_EXCHANGE_TOPIC}`, dataToSend);
this._natsConnection.publish(`${requester}.${NATS_EXCHANGE_TOPIC}`, dataToSend);
}

async rejectClaimRequest({ id, requesterDID }: { id: string; requesterDID: string }) {
Expand Down

0 comments on commit 7859337

Please sign in to comment.