Skip to content

Commit

Permalink
chore: Contact handling improvements for non DID use cases
Browse files Browse the repository at this point in the history
  • Loading branch information
nklomp committed Aug 24, 2024
1 parent 25dda34 commit 08b9caf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
29 changes: 18 additions & 11 deletions packages/oid4vci-holder/src/agent/OID4VCIHolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import {
getTypesFromObject,
Jwt,
NotificationRequest,
ProofOfPossessionCallbacks,
ProofOfPossessionCallbacks
} from '@sphereon/oid4vci-common'
import { SupportedDidMethodEnum } from '@sphereon/ssi-sdk-ext.did-utils'
import {
IIdentifierResolution,
isManagedIdentifierDidResult,
isManagedIdentifierJwkResult,
ManagedIdentifierOptsOrResult,
ManagedIdentifierOptsOrResult
} from '@sphereon/ssi-sdk-ext.identifier-resolution'
import { IJwtService, JwtHeader } from '@sphereon/ssi-sdk-ext.jwt-service'
import { signatureAlgorithmFromKey, SignatureAlgorithmJwa } from '@sphereon/ssi-sdk-ext.key-utils'
Expand All @@ -34,7 +34,7 @@ import {
IdentityOrigin,
IIssuerBranding,
NonPersistedIdentity,
Party,
Party
} from '@sphereon/ssi-sdk.data-store'
import {
CredentialMapper,
Expand All @@ -45,7 +45,7 @@ import {
Loggers,
OriginalVerifiableCredential,
parseDid,
SdJwtDecodedVerifiableCredentialPayload,
SdJwtDecodedVerifiableCredentialPayload
} from '@sphereon/ssi-types'
import {
CredentialPayload,
Expand All @@ -56,7 +56,7 @@ import {
IResolver,
ProofFormat,
VerifiableCredential,
W3CVerifiableCredential,
W3CVerifiableCredential
} from '@veramo/core'
import { asArray, computeEntryHash } from '@veramo/utils'
import { decodeJWT } from 'did-jwt'
Expand Down Expand Up @@ -90,7 +90,7 @@ import {
StartResult,
StoreCredentialBrandingArgs,
StoreCredentialsArgs,
VerificationResult,
VerificationResult
} from '../types/IOID4VCIHolder'
import {
getBasicIssuerLocaleBranding,
Expand All @@ -100,7 +100,7 @@ import {
getIssuanceOpts,
mapCredentialToAccept,
selectCredentialLocaleBranding,
verifyCredentialToAccept,
verifyCredentialToAccept
} from './OID4VCIHolderService'

/**
Expand Down Expand Up @@ -703,13 +703,20 @@ export class OID4VCIHolder implements IAgentPlugin {
return Promise.reject(Error('Missing credential offers in context'))
}

const correlationId: string = credentialsToAccept[0].correlationId
let correlationId: string = credentialsToAccept[0].correlationId
let identifierType = CorrelationIdentifierType.DID
if (!correlationId.toLowerCase().startsWith('did:')) {
identifierType = CorrelationIdentifierType.URL
if (correlationId.startsWith('http')) {
correlationId = new URL(correlationId).hostname
}
}
const identity: NonPersistedIdentity = {
alias: correlationId,
alias: credentialsToAccept[0].correlationId,
origin: IdentityOrigin.EXTERNAL,
roles: [CredentialRole.ISSUER],
identifier: {
type: CorrelationIdentifierType.DID,
type: identifierType,
correlationId,
},
}
Expand All @@ -718,7 +725,7 @@ export class OID4VCIHolder implements IAgentPlugin {
contactId: contact.id,
identity,
})
logger.log(`Contact added ${contact.id}`)
logger.log(`Contact added: ${correlationId}`)

return context.agent.cmAddIdentity({ contactId: contact.id, identity })
}
Expand Down
6 changes: 5 additions & 1 deletion packages/oid4vci-holder/src/machine/oid4vciMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ const oid4vciRequirePinGuard = (_ctx: OID4VCIMachineContext, _event: OID4VCIMach

const oid4vciHasNoContactIdentityGuard = (_ctx: OID4VCIMachineContext, _event: OID4VCIMachineEventTypes): boolean => {
const { contact, credentialsToAccept } = _ctx
return !contact?.identities.some((identity: Identity): boolean => identity.identifier.correlationId === credentialsToAccept[0].correlationId)
let toAcceptId = credentialsToAccept[0].correlationId
if (toAcceptId.match(/^https?:\/\/.*/)) {
toAcceptId = new URL(toAcceptId).hostname
}
return !contact?.identities.some((identity: Identity): boolean => identity.identifier.correlationId === toAcceptId)
}

const oid4vciVerificationCodeGuard = (_ctx: OID4VCIMachineContext, _event: OID4VCIMachineEventTypes): boolean => {
Expand Down

0 comments on commit 08b9caf

Please sign in to comment.