Skip to content

Commit

Permalink
chore: remove patches, support jarm (#182)
Browse files Browse the repository at this point in the history
Signed-off-by: Timo Glastra <timo@animo.id>
Co-authored-by: Berend Sliedrecht <61358536+berendsliedrecht@users.noreply.github.com>
  • Loading branch information
TimoGlastra and berendsliedrecht authored Oct 8, 2024
1 parent 1b8c197 commit ccd7623
Show file tree
Hide file tree
Showing 22 changed files with 2,887 additions and 4,409 deletions.
1 change: 1 addition & 0 deletions apps/easypid/src/crypto/bPrime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ export const requestSdJwtVcFromSeedCredential = async ({

const [firstCredential] = credentialAndNotifications
if (!firstCredential) throw new Error('Error retrieving credential.')
if (typeof firstCredential === 'string') throw new Error('string cred not allowed here')

let record: SdJwtVcRecord

Expand Down
6 changes: 3 additions & 3 deletions apps/easypid/src/features/onboarding/onboardingContext.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { sendCommand } from '@animo-id/expo-ausweis-sdk'
import type { SdJwtVcHeader } from '@credo-ts/core'
import { MdocRecord, TypedArrayEncoder, utils } from '@credo-ts/core'
import { /*MdocRecord, */ TypedArrayEncoder, utils } from '@credo-ts/core'
import { type AppAgent, initializeAppAgent, useSecureUnlock } from '@easypid/agent'
import { deviceKeyPair } from '@easypid/storage/pidPin'
import { PinPossiblyReusedError, ReceivePidUseCaseBPrimeFlow } from '@easypid/use-cases/ReceivePidUseCaseBPrimeFlow'
Expand Down Expand Up @@ -710,12 +710,12 @@ export function OnboardingContextProvider({
entityHost: getHostNameFromUrl(parsed.prettyClaims.iss) as string,
entityName: issuerName,
})
} else if (credential instanceof MdocRecord) {
} /* else if (credential instanceof MdocRecord) {
await storeCredential(secureUnlock.context.agent, credential)
// NOTE: we don't set the userName here as we always get SD-JWT VC and MODC at the same time currently
// so it should be set
} else {
} */ else {
const payload = credential.credential.split('.')[1]
const {
iss,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export function FunkeOpenIdPresentationNotificationScreen() {
const disclosedPayload = getPidAttributesForDisplay(
credential.disclosedPayload ?? {},
credential.metadata ?? ({} as CredentialMetadata),
credential.claimFormat as ClaimFormat.SdJwtVc | ClaimFormat.MsoMdoc
credential.claimFormat as ClaimFormat.SdJwtVc /* | ClaimFormat.MsoMdoc */
)

await activityStorage.addActivity(agent, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ export function FunkePresentationNotificationScreen({

const disclosedAttributes = getPidDisclosedAttributeNames(
credential?.disclosedPayload ?? {},
credential?.claimFormat as ClaimFormat.SdJwtVc | ClaimFormat.MsoMdoc
credential?.claimFormat as ClaimFormat.SdJwtVc /* | ClaimFormat.MsoMdoc */
)

const disclosedPayload = getPidAttributesForDisplay(
credential?.disclosedPayload ?? {},
credential?.metadata ?? ({} as CredentialMetadata),
credential?.claimFormat as ClaimFormat.SdJwtVc | ClaimFormat.MsoMdoc
credential?.claimFormat as ClaimFormat.SdJwtVc /* | ClaimFormat.MsoMdoc */
)

const onStop = () => {
Expand Down
4 changes: 2 additions & 2 deletions apps/easypid/src/hooks/usePidCredential.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const attributeNameMapping = {
export function getPidAttributesForDisplay(
attributes: Partial<PidMdocAttributes | PidSdJwtVcAttributes>,
metadata: CredentialMetadata,
claimFormat: ClaimFormat.SdJwtVc | ClaimFormat.MsoMdoc
claimFormat: ClaimFormat.SdJwtVc /* | ClaimFormat.MsoMdoc */
) {
if (claimFormat === ClaimFormat.SdJwtVc) {
return getSdJwtPidAttributesForDisplay(attributes, metadata)
Expand Down Expand Up @@ -242,7 +242,7 @@ export function getMdocPidAttributesForDisplay(attributes: Partial<PidMdocAttrib

export function getPidDisclosedAttributeNames(
attributes: Partial<PidMdocAttributes | PidSdJwtVcAttributes>,
claimFormat: ClaimFormat.SdJwtVc | ClaimFormat.MsoMdoc
claimFormat: ClaimFormat.SdJwtVc /* | ClaimFormat.MsoMdoc */
) {
if (claimFormat === ClaimFormat.SdJwtVc) {
return getSdJwtPidDisclosedAttributeNames(attributes)
Expand Down
11 changes: 6 additions & 5 deletions apps/easypid/src/use-cases/ReceivePidUseCaseCFlow.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { MdocRecord } from '@credo-ts/core'
// import type { MdocRecord } from '@credo-ts/core'
import { pidSchemes } from '@easypid/constants'
import {
BiometricAuthenticationError,
Expand All @@ -7,15 +7,15 @@ import {
resolveOpenId4VciOffer,
} from '@package/agent'
import { ReceivePidUseCaseFlow, type ReceivePidUseCaseFlowOptions } from './ReceivePidUseCaseFlow'
import { C_SD_JWT_MDOC_OFFER } from './bdrPidIssuerOffers'
import { C_SD_JWT_OFFER } from './bdrPidIssuerOffers'

export class ReceivePidUseCaseCFlow extends ReceivePidUseCaseFlow {
private static REDIRECT_URI = 'https://funke.animo.id/redirect'

public static async initialize(options: ReceivePidUseCaseFlowOptions) {
const resolved = await resolveOpenId4VciOffer({
agent: options.agent,
offer: { uri: C_SD_JWT_MDOC_OFFER },
offer: { uri: C_SD_JWT_OFFER },
authorization: {
clientId: ReceivePidUseCaseCFlow.CLIENT_ID,
redirectUri: ReceivePidUseCaseCFlow.REDIRECT_URI,
Expand Down Expand Up @@ -56,12 +56,13 @@ export class ReceivePidUseCaseCFlow extends ReceivePidUseCaseFlow {
})

for (const credentialRecord of credentialRecords) {
if (credentialRecord.type !== 'SdJwtVcRecord' && credentialRecord.type !== 'MdocRecord') {
if (typeof credentialRecord === 'string') throw new Error('No string expected for c flow')
if (credentialRecord.type !== 'SdJwtVcRecord' /*&& credentialRecord.type !== 'MdocRecord' */) {
throw new Error(`Unexpected record type ${credentialRecord.type}`)
}
}

return credentialRecords as Array<SdJwtVcRecord | MdocRecord>
return credentialRecords as Array<SdJwtVcRecord /*| MdocRecord */>
} catch (error) {
// We can recover from this error, so we shouldn't set the state to error
if (error instanceof BiometricAuthenticationError) {
Expand Down
4 changes: 2 additions & 2 deletions apps/easypid/src/use-cases/ReceivePidUseCaseFlow.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AusweisAuthFlow, type AusweisAuthFlowOptions, sendCommand } from '@animo-id/expo-ausweis-sdk'
import type { MdocRecord } from '@credo-ts/core'
// import type { MdocRecord } from '@credo-ts/core'
import type { AppAgent } from '@easypid/agent'
import {
type OpenId4VcCredentialMetadata,
Expand Down Expand Up @@ -58,7 +58,7 @@ export abstract class ReceivePidUseCaseFlow<ExtraOptions = {}> {
]

public abstract retrieveCredentials(): Promise<
Array<SdJwtVcRecord | MdocRecord | { credential: string; openId4VcMetadata: OpenId4VcCredentialMetadata }>
Array<SdJwtVcRecord /* | MdocRecord */ | { credential: string; openId4VcMetadata: OpenId4VcCredentialMetadata }>
>

protected constructor(
Expand Down
3 changes: 3 additions & 0 deletions apps/easypid/src/use-cases/bdrPidIssuerOffers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ export const B_PRIME_SD_JWT_VC_OFFER =

export const C_SD_JWT_MDOC_OFFER =
'openid-credential-offer://?credential_offer=%7B%22credential_issuer%22%3A%22https%3A%2F%2Fdemo.pid-issuer.bundesdruckerei.de%2Fc%22%2C%22credential_configuration_ids%22%3A%5B%22pid-sd-jwt%22%2C%20%22pid-mso-mdoc%22%5D%2C%22grants%22%3A%7B%22authorization_code%22%3A%7B%7D%7D%7D'

export const C_SD_JWT_OFFER =
'openid-credential-offer://?credential_offer=%7B%22credential_issuer%22%3A%22https%3A%2F%2Fdemo.pid-issuer.bundesdruckerei.de%2Fc%22%2C%22credential_configuration_ids%22%3A%5B%22pid-sd-jwt%22%5D%2C%22grants%22%3A%7B%22authorization_code%22%3A%7B%7D%7D%7D'
35 changes: 18 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "wallets",
"private": true,
"scripts": {
"postinstall": "pnpm deps:check",
"postinstall": "pnpm deps:check && rm -rf node_modules/@credo-ts/anoncreds/src node_modules/@credo-ts/askar/src node_modules/@credo-ts/cheqd/src node_modules/@credo-ts/core/src node_modules/@credo-ts/indy-vdr/src node_modules/@credo-ts/openid4vc/src node_modules/@credo-ts/question-answer/src node_modules/@credo-ts/react-native/src",
"build": "pnpm -r build",
"upgrade:tamagui": "pnpm up '*tamagui*'@latest '@tamagui/*'@latest",
"upgrade:tamagui:canary": "pnpm up '*tamagui*'@canary '@tamagui/*'@canary",
Expand All @@ -28,31 +28,32 @@
"typescript": "~5.3.3",
"@unimodules/react-native-adapter": "./noop",
"@unimodules/core": "./noop",
"@hyperledger/anoncreds-react-native": "^0.2.2",
"@hyperledger/anoncreds-react-native": "^0.2.4",
"@hyperledger/aries-askar-react-native": "^0.2.3",
"@hyperledger/indy-vdr-react-native": "^0.2.0",
"@credo-ts/anoncreds": "0.5.11-pr-1996-20240827124430",
"@credo-ts/askar": "0.5.11-pr-1996-20240827124430",
"@credo-ts/cheqd": "0.5.11-pr-1996-20240827124430",
"@credo-ts/core": "0.5.11-pr-1996-20240827124430",
"@credo-ts/indy-vdr": "0.5.11-pr-1996-20240827124430",
"@credo-ts/openid4vc": "0.5.11-pr-1996-20240827124430",
"@credo-ts/question-answer": "0.5.11-pr-1996-20240827124430",
"@credo-ts/anoncreds": "https://gitpkg.vercel.app/animo/aries-framework-javascript/packages/anoncreds?funke",
"@credo-ts/askar": "https://gitpkg.vercel.app/animo/aries-framework-javascript/packages/askar?funke",
"@credo-ts/cheqd": "https://gitpkg.vercel.app/animo/aries-framework-javascript/packages/cheqd?funke",
"@credo-ts/core": "https://gitpkg.vercel.app/animo/aries-framework-javascript/packages/core?funke",
"@credo-ts/indy-vdr": "https://gitpkg.vercel.app/animo/aries-framework-javascript/packages/indy-vdr?funke",
"@credo-ts/openid4vc": "https://gitpkg.vercel.app/animo/aries-framework-javascript/packages/openid4vc?funke",
"@credo-ts/question-answer": "https://gitpkg.vercel.app/animo/aries-framework-javascript/packages/question-answer?funke",
"@credo-ts/react-native": "https://gitpkg.vercel.app/animo/aries-framework-javascript/packages/react-native?funke",
"@credo-ts/react-hooks": "0.6.1",
"@credo-ts/react-native": "0.5.11-pr-1996-20240827124430",
"@animo-id/expo-secure-environment": "0.1.0-alpha.5",
"@animo-id/expo-ausweis-sdk": "0.0.1-alpha.14",
"react-native": "0.74.5",
"@sphereon/did-auth-siop": "file:./sphereon-did-auth-siop-0.16.0.tgz",
"@sphereon/oid4vc-common": "0.16.1-next.14"
"@sphereon/did-auth-siop": "https://gitpkg.vercel.app/animo/OID4VC/packages/siop-oid4vp?funke",
"@sphereon/oid4vc-common": "https://gitpkg.vercel.app/animo/OID4VC/packages/common?funke",
"@sphereon/oid4vci-common": "https://gitpkg.vercel.app/animo/OID4VC/packages/oid4vci-common?funke",
"@sphereon/oid4vci-issuer": "https://gitpkg.vercel.app/animo/OID4VC/packages/issuer?funke",
"@sphereon/oid4vci-client": "https://gitpkg.vercel.app/animo/OID4VC/packages/client?funke",
"@sphereon/jarm": "https://gitpkg.vercel.app/animo/OID4VC/packages/jarm?funke",
"@sphereon/ssi-types": "0.29.1-unstable.208"
},
"patchedDependencies": {
"@credo-ts/openid4vc@0.5.11-pr-1996-20240827124430": "patches/@credo-ts__openid4vc@0.5.11-pr-1996-20240827124430.patch",
"@hyperledger/indy-vdr-react-native@0.2.2": "patches/@hyperledger__indy-vdr-react-native@0.2.2.patch",
"@hyperledger/anoncreds-react-native@0.2.2": "patches/@hyperledger__anoncreds-react-native@0.2.2.patch",
"@sphereon/oid4vci-client@0.16.1-next.14": "patches/@sphereon__oid4vci-client@0.16.1-next.14.patch",
"@sphereon/oid4vci-common@0.16.1-next.14": "patches/@sphereon__oid4vci-common@0.16.1-next.14.patch",
"@sphereon/oid4vc-common@0.16.1-next.14": "patches/@sphereon__oid4vc-common@0.16.1-next.14.patch"
"@credo-ts/openid4vc@0.5.11": "patches/@credo-ts__openid4vc@0.5.11.patch"
}
}
}
36 changes: 18 additions & 18 deletions packages/agent/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ export const initializeFullAgent = async ({
walletKey: string
keyDerivation: 'raw' | 'derive'
}) => {
// FIXME: in the easypid app importing the cheqd module gives errors. As we're not using cheqd in the EasyPid wallet
// we protect it like this, but I think the Paradym Wallet must be broken as well then?!?
const { CheqdAnonCredsRegistry, CheqdDidResolver, CheqdModule, CheqdModuleConfig } =
require('@credo-ts/cheqd') as typeof import('@credo-ts/cheqd')
// // FIXME: in the easypid app importing the cheqd module gives errors. As we're not using cheqd in the EasyPid wallet
// // we protect it like this, but I think the Paradym Wallet must be broken as well then?!?
// const { CheqdAnonCredsRegistry, CheqdDidResolver, CheqdModule, CheqdModuleConfig } =
// require('@credo-ts/cheqd') as typeof import('@credo-ts/cheqd')

const agent = new Agent({
dependencies: agentDependencies,
Expand All @@ -131,13 +131,13 @@ export const initializeFullAgent = async ({
new WebDidResolver(),
new KeyDidResolver(),
new JwkDidResolver(),
new CheqdDidResolver(),
// new CheqdDidResolver(),
new IndyVdrSovDidResolver(),
new IndyVdrIndyDidResolver(),
],
}),
anoncreds: new AnonCredsModule({
registries: [new IndyVdrAnonCredsRegistry(), new CheqdAnonCredsRegistry(), new DidWebAnonCredsRegistry()],
registries: [new IndyVdrAnonCredsRegistry() /* new CheqdAnonCredsRegistry(), new DidWebAnonCredsRegistry() */],
anoncreds,
}),

Expand All @@ -153,18 +153,18 @@ export const initializeFullAgent = async ({
connections: new ConnectionsModule({
autoAcceptConnections: true,
}),
cheqd: new CheqdModule(
new CheqdModuleConfig({
networks: [
{
network: 'testnet',
},
{
network: 'mainnet',
},
],
})
),
// cheqd: new CheqdModule(
// new CheqdModuleConfig({
// networks: [
// {
// network: 'testnet',
// },
// {
// network: 'mainnet',
// },
// ],
// })
// ),
credentials: new CredentialsModule({
autoAcceptCredentials: AutoAcceptCredential.ContentApproved,
credentialProtocols: [
Expand Down
56 changes: 28 additions & 28 deletions packages/agent/src/display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { CredentialForDisplayId } from './hooks'
import type { OpenId4VcCredentialMetadata } from './openid4vc/metadata'
import type { W3cCredentialJson, W3cIssuerJson } from './types'

import { ClaimFormat, Hasher, JsonTransformer, Mdoc, MdocRecord, SdJwtVcRecord } from '@credo-ts/core'
import { ClaimFormat, Hasher, JsonTransformer, /* Mdoc, MdocRecord, */ SdJwtVcRecord } from '@credo-ts/core'
import { getHostNameFromUrl, sanitizeString } from '@package/utils'
import { decodeSdJwtSync, getClaimsSync } from '@sd-jwt/decode'

Expand Down Expand Up @@ -361,7 +361,7 @@ export function getDisclosedAttributePaths(payload: object, prefix = ''): Array<
return attributes
}

export function getCredentialForDisplay(credentialRecord: W3cCredentialRecord | SdJwtVcRecord | MdocRecord) {
export function getCredentialForDisplay(credentialRecord: W3cCredentialRecord | SdJwtVcRecord /* | MdocRecord */) {
if (credentialRecord instanceof SdJwtVcRecord) {
// FIXME: we should probably add a decode method on the SdJwtVcRecord
// as you now need the agent context to decode the sd-jwt vc, while that's
Expand Down Expand Up @@ -389,32 +389,32 @@ export function getCredentialForDisplay(credentialRecord: W3cCredentialRecord |
claimFormat: ClaimFormat.SdJwtVc,
}
}
if (credentialRecord instanceof MdocRecord) {
const openId4VcMetadata = getOpenId4VcCredentialMetadata(credentialRecord)
const issuerDisplay = getOpenId4VcIssuerDisplay(openId4VcMetadata)
const credentialDisplay = getMdocCredentialDisplay({}, openId4VcMetadata)

const mdocInstance = Mdoc.fromIssuerSignedHex(credentialRecord.issuerSignedHex)

const attributes = Object.fromEntries(Object.values(mdocInstance.namespaces).flatMap((a) => Object.entries(a)))

return {
id: `mdoc-${credentialRecord.id}` satisfies CredentialForDisplayId,
createdAt: credentialRecord.createdAt,
display: {
...credentialDisplay,
issuer: issuerDisplay,
},
attributes,
// TODO:
metadata: {
holder: 'Unknown',
issuer: 'Unknown',
type: mdocInstance.docType,
} satisfies CredentialMetadata,
claimFormat: ClaimFormat.MsoMdoc,
}
}
// if (credentialRecord instanceof MdocRecord) {
// const openId4VcMetadata = getOpenId4VcCredentialMetadata(credentialRecord)
// const issuerDisplay = getOpenId4VcIssuerDisplay(openId4VcMetadata)
// const credentialDisplay = getMdocCredentialDisplay({}, openId4VcMetadata)

// const mdocInstance = Mdoc.fromIssuerSignedHex(credentialRecord.issuerSignedHex)

// const attributes = Object.fromEntries(Object.values(mdocInstance.namespaces).flatMap((a) => Object.entries(a)))

// return {
// id: `mdoc-${credentialRecord.id}` satisfies CredentialForDisplayId,
// createdAt: credentialRecord.createdAt,
// display: {
// ...credentialDisplay,
// issuer: issuerDisplay,
// },
// attributes,
// // TODO:
// metadata: {
// holder: 'Unknown',
// issuer: 'Unknown',
// type: mdocInstance.docType,
// } satisfies CredentialMetadata,
// claimFormat: ClaimFormat.MsoMdoc,
// }
// }

const credential = JsonTransformer.toJSON(
credentialRecord.credential.claimFormat === ClaimFormat.JwtVc
Expand Down
4 changes: 2 additions & 2 deletions packages/agent/src/format/formatPresentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ export function formatDifPexCredentialsForRequest(
let disclosedPayload = attributes
if (verifiableCredential.type === ClaimFormat.SdJwtVc) {
disclosedPayload = filterAndMapSdJwtKeys(verifiableCredential.disclosedPayload).visibleProperties
} else if (verifiableCredential.type === ClaimFormat.MsoMdoc) {
} /* else if (verifiableCredential.type === ClaimFormat.MsoMdoc) {
disclosedPayload = Object.fromEntries(
Object.values(verifiableCredential.disclosedPayload).flatMap((entry) => Object.entries(entry))
)
}
} */

return {
id: verifiableCredential.credentialRecord.id,
Expand Down
Loading

0 comments on commit ccd7623

Please sign in to comment.