Skip to content

Commit

Permalink
seems to work
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsmkl committed Aug 31, 2022
1 parent cfd4d5d commit 8f03e98
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/access/access.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,25 @@ export class AccessController {
return (await getAssetUrl(req.user.did, index)).url;
}

@Get('nft-access-proof/:agreement_id/:index')
@ApiOperation({
description: 'NFT Access asset w/ DTP proof',
summary: 'Public',
})
@ApiResponse({
status: 200,
description: 'Return the url of asset',
type: String,
})
@ApiBearerAuth('Authorization')
async doNFTAccessProof(
@Req() req: Request<unknown>,
@Response({ passthrough: true }) res,
@Param('index') index: number,
): Promise<string> {
return (await getAssetUrl(req.user.did, index)).url;
}

@Get('nft-access/:agreement_id/:index')
@ApiOperation({
description: 'Access asset',
Expand Down
6 changes: 5 additions & 1 deletion src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ export class AuthService {
const ddo = await nevermined.assets.resolve(did);
const service = ddo.findServiceByType('nft-access-proof');
if (!service) {
// console.log('its 721');
await this.validateNft721AccessProof(agreement_id, did, consumer_address, buyer, babysig);
return;
}
Expand All @@ -247,6 +248,7 @@ export class AuthService {
if (await nevermined.keeper.nftUpgradeable.balance(consumer_address, did) < numberNfts) {
throw new UnauthorizedException(`Address ${consumer_address} hasn't enough ${did} NFT balance, ${numberNfts.toString()} required`);
}
// console.log('no agreement?');
return;
}
const instanceConfig = {
Expand All @@ -266,11 +268,13 @@ export class AuthService {
throw new UnauthorizedException(`Bad signature for address ${consumer_address}`);
}

// console.log('number', numberNfts.toNumber());
const params = dtp.nftAccessProofTemplate.params(consumer, consumer_address, numberNfts.toNumber());
const conditions = [
{name: 'holder', fulfill: false},
{name: 'access', fulfill: true, condition: dtp.accessProofCondition, extra},
];
// console.log('going to validate', consumer_address);
await validateAgreement({
agreement_id,
did,
Expand Down Expand Up @@ -305,7 +309,7 @@ export class AuthService {
await this.validateAccess(payload.sub, payload.did as string, payload.iss);
} else if (payload.aud === BASE_URL + 'access-proof') {
await this.validateAccessProof(payload.sub, payload.did as string, payload.iss, payload.buyer as string, payload.babysig as Babysig);
} else if (payload.aud === BASE_URL + 'access-proof') {
} else if (payload.aud === BASE_URL + 'nft-access-proof') {
await this.validateNftAccessProof(payload.sub, payload.did as string, payload.iss, payload.buyer as string, payload.babysig as Babysig);
} else if (payload.aud === BASE_URL + 'nft-transfer-proof') {
await this.validateTransferProof(payload.sub, payload.did as string, payload.iss, payload.buyer as string, payload.babysig as Babysig);
Expand Down

0 comments on commit 8f03e98

Please sign in to comment.