import appendQuery from 'append-query' ; import { injectable } from 'tsyringe' ; import { CertificateJwt } from '../../../../models/JWT/certificate-jwt' ; import { ContractService } from '../contractService/contractsService' ; import { WalletService } from '../walletService/walletService' ; import { JWTService } from './JWTService' ; @ injectable ( ) export class ArianeeAccessTokenService { constructor ( private jwtService , private walletService , private contractService ) { } param certificateId public createCertificateArianeeAccessToken = ( certificateId ) => { return this . jwtService . sign ( { sub : 'certificate' , subId : certificateId } ) ; } ; param url param certificateId public createActionArianeeAccessTokenLink = async ( url , certificateId ) => { const arianeeAccessToken = await this . createCertificateArianeeAccessToken ( certificateId ) ; return appendQuery ( url , { arianeeAccessToken } ) ; } ; param token public decodeArianeeAccessToken = ( token ) => { return this . jwtService . decode < CertificateJwt > ( token ) ; } ; param token public isCertificateArianeeAccessTokenValid = async ( token ) : Promise < boolean > => { const { payload } = this . jwtService . decode ( token ) ; const owner = await this . contractService . smartAssetContract . methods . ownerOf ( payload . subId ) . call ( ) . catch ( e => '' ) ; return this . jwtService . isValidJWT ( token , owner ) ; } ; }