Skip to content

Commit

Permalink
fix: Add Logos as resources in Webpage and Ticket (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
jay-dee7 committed Nov 17, 2022
1 parent 5302c82 commit f140684
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 19 deletions.
33 changes: 26 additions & 7 deletions src/api/controllers/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Resolver, ResolverRegistry } from 'did-resolver'
import { CheqdDIDProvider, getResolver as CheqdDidResolver } from '@cheqd/did-provider-cheqd'
import { NetworkType } from '@cheqd/did-provider-cheqd/src/did-manager/cheqd-did-provider'
import { HEADERS, VC_CONTEXT, VC_EVENTRESERVATION_CONTEXT, VC_PERSON_CONTEXT, VC_PROOF_FORMAT, VC_REMOVE_ORIGINAL_FIELDS, VC_TICKET_CONTEXT, VC_TYPE, } from '../constants'
import { CredentialPayload, CredentialRequest, CredentialSubject, GenericAuthUser, VerifiableCredential } from '../types'
import { CredentialPayload, CredentialRequest, CredentialSubject, GenericAuthUser, VerifiableCredential, WebPage } from '../types'
import { Identity } from './identity'

export class Credentials {
Expand Down Expand Up @@ -61,22 +61,37 @@ export class Credentials {
})
}

getThumbnailURL(provider: string): string | undefined {
switch (provider) {
case 'twitter':
return `${RESOLVER_URL}/${ISSUER_ID}/resources/${TWITTER_RESOURCE_ID}`
case 'discord':
return `${RESOLVER_URL}/${ISSUER_ID}/resources/${DISCORD_RESOURCE_ID}`
case 'github':
return `${RESOLVER_URL}/${ISSUER_ID}/resources/${GITHUB_RESOURCE_ID}`
case 'eventbrite':
return `${RESOLVER_URL}/${ISSUER_ID}/resources/${EVENTBRITE_RESOURCE_ID}`
}
}

async issue_person_credential(user: GenericAuthUser, provider: string, subjectId?: string): Promise<Response> {
provider = provider.toLowerCase()
const credential_subject: CredentialSubject = {
id: subjectId,
type: undefined
}
const webpage:any = {

const webpage: WebPage = {
'@type': 'ProfilePage',
description: provider,
name: `${user?.nickname}` ?? '<unknown>',
identifier: `@${user?.nickname}` ?? '<unknown>',
lastReviewed: user?.updated_at
lastReviewed: user?.updated_at,
thumbnailUrl: this.getThumbnailURL(provider),
}

if(provider=='github' || provider == 'twitter') {
webpage.URL=`https://${provider.toLowerCase()}.com/${user?.nickname}`
if (provider == 'github' || provider == 'twitter') {
webpage.URL = `https://${provider.toLowerCase()}.com/${user?.nickname}`
}

const credential = {
Expand All @@ -103,13 +118,17 @@ export class Credentials {
credentialSubject: credential_subject,
reservationId,
reservationStatus: 'https://schema.org/ReservationConfirmed',
provider: {
brand: 'EventBrite',
image: this.getThumbnailURL('eventbrite')
},
reservationFor: {
'@type': 'Event',
name: 'Internet Identity Workshop IIWXXXV',
startDate: "2022-11-16T16:00:00",
endDate: "2022-11-18T00:00:00",
location: "Computer History Museum, 1401 N Shoreline Blvd, Mountain View, CA 94043",
logo: 'https://resolver.cheqd.net/1.0/identifiers/did:cheqd:testnet:z6jKUJA5YcZsNxZgsrQPKPipL2FRTf4s/resources/8140ec3a-d8bb-4f59-9784-a1cbf91a4a35'
logo: `${RESOLVER_URL}/${ISSUER_ID}/resources/${IIW_LOGO_RESOURCE_ID}`
}
}

Expand Down
25 changes: 13 additions & 12 deletions src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@ export type W3CVerifiablePresentation = VerifiablePresentation | CompactJWT
export type DateType = string | Date

export interface CredentialPayload {
issuer?: IssuerType
credentialSubject?: CredentialSubject
type?: string[]
'@context'?: string[]
issuanceDate?: DateType
expirationDate?: DateType
credentialStatus?: CredentialStatus
id?: string

[x: string]: any
issuer?: IssuerType
credentialSubject?: CredentialSubject
type?: string[]
'@context'?: string[]
issuanceDate?: DateType
expirationDate?: DateType
credentialStatus?: CredentialStatus
id?: string

[x: string]: any
}

export interface PresentationPayload {
Expand Down Expand Up @@ -103,9 +103,10 @@ export type WebPage = {
'@type': string,
description?: string,
name?: string
identifier: string
identifier?: string
URL?: string
lastReviewed: Date
lastReviewed?: Date
thumbnailUrl?: string
}

export type GenericAuthUser = Record<string, any> | null | undefined
6 changes: 6 additions & 0 deletions src/bindings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ declare global {
const AUTH0_SERVICE_ENDPOINT: string
const EVENT_CONTEXT: string
const PERSON_CONTEXT: string
const RESOLVER_URL: string
const DISCORD_RESOURCE_ID: string
const GITHUB_RESOURCE_ID: string
const TWITTER_RESOURCE_ID: string
const EVENTBRITE_RESOURCE_ID: string
const IIW_LOGO_RESOURCE_ID: string
}

export { }
Expand Down

0 comments on commit f140684

Please sign in to comment.