Skip to content

Commit

Permalink
feat: Add uniresolver && update policies
Browse files Browse the repository at this point in the history
  • Loading branch information
DaevMithran committed Jun 26, 2023
1 parent 453339f commit 0413ca6
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 52 deletions.
6 changes: 3 additions & 3 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import cors from 'cors'
import swaggerUi from 'swagger-ui-express'
import session from 'express-session'
import cookieParser from 'cookie-parser'
import {withLogto, handleAuthRoutes } from '@logto/express'
import { withLogto, handleAuthRoutes } from '@logto/express'

import { CredentialController } from './controllers/credentials.js'
import { StoreController } from './controllers/store.js'
Expand Down Expand Up @@ -55,9 +55,9 @@ class App {
this.express.use(cookieParser())
if (process.env.ENABLE_AUTHENTICATION === 'true') {
this.express.use(session({secret: process.env.COOKIE_SECRET, cookie: { maxAge: 14 * 24 * 60 * 60 }}))
this.express.use(handleAuthRoutes(configLogToExpress))
this.express.use(withLogto(configLogToExpress))
}
this.express.use(handleAuthRoutes(configLogToExpress))
this.express.use(withLogto(configLogToExpress))
this.express.use(express.text())

this.express.use(
Expand Down
2 changes: 1 addition & 1 deletion src/services/connectors/verida.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Context, Network } from '@verida/client-ts'
import { AutoAccount } from '@verida/account-node'

import { CredentialDataRecord, DataRecord } from '../../types/verida.js'
import { VC_CONTEXT, VERIDA_APP_NAME, VERIDA_CREDENTIAL_RECORD_SCHEMA } from '../../types/constants.js'
import { VERIDA_APP_NAME, VERIDA_CREDENTIAL_RECORD_SCHEMA } from '../../types/constants.js'

import * as dotenv from 'dotenv'
import { VerifiableCredential } from '@veramo/core'
Expand Down
10 changes: 5 additions & 5 deletions src/services/identity/IIdentity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type {
} from '@veramo/core'
import type { AbstractPrivateKeyStore } from '@veramo/key-manager'
import type { ResourcePayload } from '@cheqd/did-provider-cheqd'
import type { RevocationResult, SuspensionResult, UnsuspensionResult } from '@cheqd/did-provider-cheqd/build/types/agent/ICheqd'
import type { BulkRevocationResult, BulkSuspensionResult, BulkUnsuspensionResult, CreateEncryptedStatusList2021Result, CreateStatusList2021Result, RevocationResult, SuspensionResult, UnsuspensionResult } from '@cheqd/did-provider-cheqd/build/types/agent/ICheqd'
import type { CreateStatusListOptions, CredentialRequest, StatusOptions, VeramoAgent, VerifyCredentialStatusOptions, VerifyPresentationStatusOptions } from '../../types/types'

export interface IIdentity {
Expand All @@ -30,8 +30,8 @@ export interface IIdentity {
createCredential(credential: CredentialPayload, format: CredentialRequest['format'], statusListOptions: StatusOptions | null, agentId?: string): Promise<VerifiableCredential>
verifyCredential(credential: VerifiableCredential | string, statusOptions: VerifyCredentialStatusOptions | null, agentId?: string): Promise<IVerifyResult>
verifyPresentation(presentation: VerifiablePresentation | string, statusOptions: VerifyPresentationStatusOptions, agentId?: string): Promise<IVerifyResult>
createStatusList2021(did: string, network: string, resourceOptions: ResourcePayload, statusOptions: CreateStatusListOptions, agentId: string): Promise<boolean>
revokeCredentials(credential: VerifiableCredential | VerifiableCredential[], publish: boolean, agentId?: string): Promise<RevocationResult| RevocationResult[]>
suspendCredentials(credential: VerifiableCredential | VerifiableCredential[], publish: boolean, agentId?: string): Promise<SuspensionResult| SuspensionResult[]>
reinstateCredentials(credential: VerifiableCredential | VerifiableCredential[], publish: boolean, agentId?: string): Promise<UnsuspensionResult| UnsuspensionResult[]>
createStatusList2021(did: string, network: string, resourceOptions: ResourcePayload, statusOptions: CreateStatusListOptions, agentId: string): Promise<CreateStatusList2021Result | CreateEncryptedStatusList2021Result>
revokeCredentials(credential: VerifiableCredential | VerifiableCredential[], publish: boolean, agentId?: string): Promise<RevocationResult| BulkRevocationResult>
suspendCredentials(credential: VerifiableCredential | VerifiableCredential[], publish: boolean, agentId?: string): Promise<SuspensionResult| BulkSuspensionResult>
reinstateCredentials(credential: VerifiableCredential | VerifiableCredential[], publish: boolean, agentId?: string): Promise<UnsuspensionResult| BulkUnsuspensionResult>
}
25 changes: 12 additions & 13 deletions src/services/identity/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,20 @@ import {
import { KeyManager } from '@veramo/key-manager'
import { DIDStore, KeyStore } from '@veramo/data-store'
import { DIDManager } from '@veramo/did-manager'
import { DIDResolverPlugin } from '@veramo/did-resolver'
import { DIDResolverPlugin, getUniversalResolver as UniversalResolver } from '@veramo/did-resolver'
import { getResolver as VeridaResolver } from '@verida/vda-did-resolver'
import { CredentialPlugin } from '@veramo/credential-w3c'
import { CredentialIssuerLD, LdDefaultContexts, VeramoEd25519Signature2018 } from '@veramo/credential-ld'
import { Cheqd, getResolver as CheqdDidResolver, ResourcePayload } from '@cheqd/did-provider-cheqd'
import { getDidKeyResolver as KeyDidResolver } from '@veramo/did-provider-key'
import { CheqdNetwork } from '@cheqd/sdk'
import { Resolver, ResolverRegistry } from 'did-resolver'
import { fromString } from 'uint8arrays'
import {
ICheqdCreateStatusList2021Args,
ICheqdGenerateStatusList2021Args,
ICheqdVerifyCredentialWithStatusList2021Args,
ICheqdVerifyPresentationWithStatusList2021Args
} from '@cheqd/did-provider-cheqd/build/types/agent/ICheqd.js'
import { v4 } from 'uuid'

import {
cheqdDidRegex,
Expand Down Expand Up @@ -84,7 +83,9 @@ export class Veramo {
new DIDResolverPlugin({
resolver: new Resolver({
...CheqdDidResolver({ url: process.env.RESOLVER_URL }) as ResolverRegistry,
...KeyDidResolver(),
...KeyDidResolver(),
...VeridaResolver(),
...UniversalResolver()
})
})
)
Expand Down Expand Up @@ -219,7 +220,7 @@ export class Veramo {
...statusOptions
} as ICheqdVerifyPresentationWithStatusList2021Args)
}
return await agent.verifyPresentation({ presentation, fetchRemoteContexts: true })
return await agent.verifyPresentation({ presentation, fetchRemoteContexts: true, policies: {audience: false} })
}

async createStatusList2021(agent: VeramoAgent, did: string, network: string, resourceOptions: ResourcePayload, statusOptions: CreateStatusListOptions) {
Expand All @@ -233,14 +234,12 @@ export class Veramo {

return await agent.cheqdCreateStatusList2021({
kms,
payload: {
collectionId: did.split(':')[3],
data: fromString(statusList, statusOptions.encoding || 'base64url'),
resourceType: 'StatusList2021',
version: resourceOptions.version,
name: resourceOptions.name,
id: v4(),
},
issuerDid: did,
statusListName: resourceOptions.name,
statusPurpose: statusOptions.statusPurpose,
statusListEncoding: statusOptions.encoding || 'base64url',
statusListLength: statusOptions.length,
encrypted: statusOptions.encrypted,
network: network as CheqdNetwork
} as ICheqdCreateStatusList2021Args)
}
Expand Down
9 changes: 5 additions & 4 deletions src/services/identity/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { IIdentity } from './IIdentity.js'
import { Veramo } from './agent.js'

import * as dotenv from 'dotenv'
import { CreateEncryptedStatusList2021Result, CreateStatusList2021Result } from '@cheqd/did-provider-cheqd/build/types/agent/ICheqd.js'

dotenv.config()

Expand Down Expand Up @@ -141,19 +142,19 @@ export class LocalIdentity implements IIdentity {
return await Veramo.instance.verifyPresentation(this.initAgent(), presentation, statusOptions)
}

async createStatusList2021(did: string, network: string, resourceOptions: ResourcePayload, statusListOptions: CreateStatusListOptions): Promise<boolean> {
async createStatusList2021(did: string, network: string, resourceOptions: ResourcePayload, statusListOptions: CreateStatusListOptions): Promise<CreateStatusList2021Result | CreateEncryptedStatusList2021Result> {
return await Veramo.instance.createStatusList2021(this.initAgent(), did, network, resourceOptions, statusListOptions)
}

async revokeCredentials(credentials: VerifiableCredential | VerifiableCredential[], publish: boolean, agentId: string) {
async revokeCredentials(credentials: VerifiableCredential | VerifiableCredential[], publish: boolean) {
return await Veramo.instance.revokeCredentials(this.initAgent(), credentials, publish)
}

async suspendCredentials(credentials: VerifiableCredential | VerifiableCredential[], publish: boolean, agentId: string) {
async suspendCredentials(credentials: VerifiableCredential | VerifiableCredential[], publish: boolean) {
return await Veramo.instance.suspendCredentials(this.initAgent(), credentials, publish)
}

async reinstateCredentials(credentials: VerifiableCredential | VerifiableCredential[], publish: boolean, agentId: string) {
async reinstateCredentials(credentials: VerifiableCredential | VerifiableCredential[], publish: boolean) {
return await Veramo.instance.unsuspendCredentials(this.initAgent(), credentials, publish)
}
}
3 changes: 2 additions & 1 deletion src/services/identity/postgres.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { CustomerService } from '../customer.js'
import { Veramo } from './agent.js'

import * as dotenv from 'dotenv'
import { CreateEncryptedStatusList2021Result, CreateStatusList2021Result } from '@cheqd/did-provider-cheqd/build/types/agent/ICheqd.js'
dotenv.config()

const {
Expand Down Expand Up @@ -188,7 +189,7 @@ export class PostgresIdentity implements IIdentity {
return await Veramo.instance.verifyPresentation(agent, presentation, statusOptions)
}

async createStatusList2021(did: string, network: string, resourceOptions: ResourcePayload, statusListOptions: CreateStatusListOptions, agentId: string): Promise<boolean> {
async createStatusList2021(did: string, network: string, resourceOptions: ResourcePayload, statusListOptions: CreateStatusListOptions, agentId: string): Promise<CreateStatusList2021Result | CreateEncryptedStatusList2021Result> {
const agent = await this.createAgent(agentId)
return await Veramo.instance.createStatusList2021(agent, did, network, resourceOptions, statusListOptions)
}
Expand Down
42 changes: 21 additions & 21 deletions src/static/custom-button.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
window.addEventListener("load", function () {
const base_url: string = window.location.origin;
const base_url: string = window.location.origin

const login_button: HTMLButtonElement = document.createElement('button');
login_button.innerHTML = 'Log in';
login_button.classList.add('btn', 'authorize');
const login_button: HTMLButtonElement = document.createElement('button')
login_button.innerHTML = 'Log in'
login_button.classList.add('btn', 'authorize')
login_button.onclick = function () {
window.location.href = base_url + '/logto/sign-in';
};
window.location.href = base_url + '/logto/sign-in'
}

const user_button: HTMLButtonElement = document.createElement('button');
user_button.innerHTML = 'User info';
user_button.classList.add('btn', 'authorize');
const user_button: HTMLButtonElement = document.createElement('button')
user_button.innerHTML = 'User info'
user_button.classList.add('btn', 'authorize')
user_button.onclick = function () {
window.location.href = base_url + '/user';
};
window.location.href = base_url + '/user'
}

const logout_button: HTMLButtonElement = document.createElement('button');
logout_button.innerHTML = 'Log out';
logout_button.classList.add('btn', 'authorize');
const logout_button: HTMLButtonElement = document.createElement('button')
logout_button.innerHTML = 'Log out'
logout_button.classList.add('btn', 'authorize')
logout_button.onclick = function () {
window.location.href = base_url + '/logto/sign-out';
};
window.location.href = base_url + '/logto/sign-out'
}

const auth_pan: Element = document.getElementsByClassName('auth-wrapper')[0];
auth_pan.appendChild(login_button);
auth_pan.appendChild(user_button);
auth_pan.appendChild(logout_button);
});
const auth_pan: Element = document.getElementsByClassName('auth-wrapper')[0]
auth_pan.appendChild(login_button)
auth_pan.appendChild(user_button)
auth_pan.appendChild(logout_button)
})

10 changes: 6 additions & 4 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ export type CreateAgentRequest = {
export type CreateStatusListOptions = {
length?: number | undefined,
encoding?: 'base64' | 'base64url' | 'hex' | undefined
statusPurpose?: 'revocation' | 'suspension'
encrypted?: boolean
}

export type StatusOptions = {
Expand Down Expand Up @@ -235,8 +237,8 @@ export interface ResourceMetadata {
mediaType: string
created:
| Date
| undefined;
checksum: string;
previousVersionId: string;
nextVersionId: string;
| undefined
checksum: string
previousVersionId: string
nextVersionId: string
}

0 comments on commit 0413ca6

Please sign in to comment.