Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add credential-ld plugin to local browser agent #174

Merged
merged 3 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/agent-explore/craco.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = {
url: require.resolve('url/'),
zlib: require.resolve('browserify-zlib'),
https: require.resolve('https-browserify'),
process: false
}
/* ... */
return webpackConfig
Expand Down
50 changes: 27 additions & 23 deletions packages/agent-explore/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
"test": "craco test --watchAll=false",
"release": "semantic-release",
"agent-explore": "./bin/bin.js",
"upgrade-veramo": "pnpm add -D @veramo/core @veramo/core-types @veramo/did-discovery @veramo/credential-w3c @veramo/data-store @veramo/did-comm @veramo/did-jwt @veramo/did-resolver @veramo/message-handler @veramo/remote-client @veramo/selective-disclosure @veramo/credential-eip712 @veramo/data-store-json @veramo/did-manager @veramo/kms-web3 @veramo/key-manager @veramo/did-provider-ethr @veramo/utils @veramo/did-provider-peer @veramo/kms-local",
"upgrade-veramo:next": "pnpm add -D @veramo/core@next @veramo/core-types@next @veramo/did-discovery@next @veramo/credential-w3c@next @veramo/data-store@next @veramo/did-comm@next @veramo/did-jwt@next @veramo/did-resolver@next @veramo/message-handler@next @veramo/remote-client@next @veramo/selective-disclosure@next @veramo/credential-eip712@next @veramo/data-store-json@next @veramo/did-manager@next @veramo/kms-web3@next @veramo/key-manager@next @veramo/did-provider-ethr@next @veramo/utils@next @veramo/did-provider-peer@next @veramo/kms-local@next",
"upgrade-veramo": "pnpm add -D @veramo/core @veramo/core-types @veramo/did-discovery @veramo/credential-w3c @veramo/credential-ld @veramo/credential-eip712 @veramo/data-store @veramo/did-comm @veramo/did-jwt @veramo/did-resolver @veramo/message-handler @veramo/remote-client @veramo/selective-disclosure @veramo/credential-eip712 @veramo/data-store-json @veramo/did-manager @veramo/kms-web3 @veramo/key-manager @veramo/did-provider-ethr @veramo/utils @veramo/did-provider-peer @veramo/did-provider-key @veramo/did-provider-jwk @veramo/did-provider-pkh @veramo/kms-local",
"upgrade-veramo:next": "pnpm add -D @veramo/core@next @veramo/core-types@next @veramo/did-discovery@next @veramo/credential-w3c@next @veramo/credential-ld@next @veramo/credential-eip712@next @veramo/data-store@next @veramo/did-comm@next @veramo/did-jwt@next @veramo/did-resolver@next @veramo/message-handler@next @veramo/remote-client@next @veramo/selective-disclosure@next @veramo/credential-eip712@next @veramo/data-store-json@next @veramo/did-manager@next @veramo/kms-web3@next @veramo/key-manager@next @veramo/did-provider-ethr@next @veramo/utils@next @veramo/did-provider-peer@next @veramo/did-provider-key@next @veramo/did-provider-jwk@next @veramo/did-provider-pkh@next @veramo/kms-local@next",
"build-electron": "cross-env PUBLIC_URL=./ craco build",
"electron": "electron .",
"electron-dev": "cross-env ELECTRON_START_URL=http://localhost:3000 electron .",
Expand Down Expand Up @@ -93,6 +93,7 @@
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.4.3",
"@transmute/credentials-context": "0.7.0-unstable.81",
"@types/express": "^4.17.17",
"@types/jest": "^29.5.1",
"@types/md5": "^2.3.2",
Expand All @@ -105,27 +106,30 @@
"@typescript-eslint/parser": "^6.4.0",
"@veramo-community/agent-explorer-plugin": "workspace:*",
"@veramo-community/veramo-react": "^1.1.0",
"@veramo/core": "5.5.2-next.9",
"@veramo/core-types": "5.5.2-next.9",
"@veramo/credential-eip712": "5.5.2-next.9",
"@veramo/credential-w3c": "5.5.2-next.9",
"@veramo/data-store": "5.5.2-next.9",
"@veramo/data-store-json": "5.5.2-next.9",
"@veramo/did-comm": "5.5.2-next.9",
"@veramo/did-discovery": "5.5.2-next.9",
"@veramo/did-jwt": "5.5.2-next.9",
"@veramo/did-manager": "5.5.2-next.9",
"@veramo/did-provider-ethr": "5.5.2-next.9",
"@veramo/did-provider-peer": "5.5.2-next.9",
"@veramo/did-provider-pkh": "5.5.2-next.9",
"@veramo/did-resolver": "5.5.2-next.9",
"@veramo/key-manager": "5.5.2-next.9",
"@veramo/kms-local": "5.5.2-next.9",
"@veramo/kms-web3": "5.5.2-next.9",
"@veramo/message-handler": "5.5.2-next.9",
"@veramo/remote-client": "5.5.2-next.9",
"@veramo/selective-disclosure": "5.5.2-next.9",
"@veramo/utils": "5.5.2-next.9",
"@veramo/core": "5.5.2-next.10",
"@veramo/core-types": "5.5.2-next.10",
"@veramo/credential-eip712": "5.5.2-next.10",
"@veramo/credential-ld": "5.5.2-next.10",
"@veramo/credential-w3c": "5.5.2-next.10",
"@veramo/data-store": "5.5.2-next.10",
"@veramo/data-store-json": "5.5.2-next.10",
"@veramo/did-comm": "5.5.2-next.10",
"@veramo/did-discovery": "5.5.2-next.10",
"@veramo/did-jwt": "5.5.2-next.10",
"@veramo/did-manager": "5.5.2-next.10",
"@veramo/did-provider-ethr": "5.5.2-next.10",
"@veramo/did-provider-jwk": "5.5.2-next.10",
"@veramo/did-provider-key": "5.5.2-next.10",
"@veramo/did-provider-peer": "5.5.2-next.10",
"@veramo/did-provider-pkh": "5.5.2-next.10",
"@veramo/did-resolver": "5.5.2-next.10",
"@veramo/key-manager": "5.5.2-next.10",
"@veramo/kms-local": "5.5.2-next.10",
"@veramo/kms-web3": "5.5.2-next.10",
"@veramo/message-handler": "5.5.2-next.10",
"@veramo/remote-client": "5.5.2-next.10",
"@veramo/selective-disclosure": "5.5.2-next.10",
"@veramo/utils": "5.5.2-next.10",
"@web3modal/wagmi": "^3.0.2",
"@yudiel/react-qr-scanner": "^1.1.8",
"antd": "~5.8.4",
Expand Down
56 changes: 37 additions & 19 deletions packages/agent-explore/src/context/web3/web3Agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import { getResolver as ethrDidResolver } from 'ethr-did-resolver'
import { getResolver as webDidResolver } from 'web-did-resolver'
import { EthrDIDProvider } from '@veramo/did-provider-ethr'
import { PkhDIDProvider, getDidPkhResolver } from '@veramo/did-provider-pkh'
import { KeyDIDProvider, getDidKeyResolver } from '@veramo/did-provider-key'
import { JwkDIDProvider, getDidJwkResolver } from '@veramo/did-provider-jwk'
import {
PeerDIDProvider,
getResolver as peerDidResolver,
Expand All @@ -51,10 +53,19 @@ import {
IIdentifierProfilePlugin,
} from '@veramo-community/agent-explorer-plugin'
import { DIDDiscovery } from '@veramo/did-discovery'
// FIXME: This import causes an error: Module not found: Error: Can't resolve 'react-native-sqlite-storage' in '[...]/node_modules/typeorm/browser/driver/react-native'
// import { DataStoreDiscoveryProvider } from '@veramo/data-store'
// FIXME: This import causes an error: Module not found: Error: Can't resolve 'react-native-sqlite-storage' in
// '[...]/node_modules/typeorm/browser/driver/react-native' import { DataStoreDiscoveryProvider } from
// '@veramo/data-store'
import { DataStoreDiscoveryProvider } from '../plugins/did-discovery-provider'
import { AliasDiscoveryProvider } from '../plugins/AliasDiscoveryProvider'
import {
CredentialIssuerLD,
ICredentialIssuerLD,
LdDefaultContexts,
VeramoEcdsaSecp256k1RecoverySignature2020,
VeramoEd25519Signature2018,
} from '@veramo/credential-ld'
import { contexts as credential_contexts } from '@transmute/credentials-context'

const dataStore = BrowserLocalStorageStore.fromLocalStorage('veramo-state')
const identifierDataStore =
Expand All @@ -69,12 +80,15 @@ export interface ConnectorInfo {
isActive: boolean
}

export async function createWeb3Agent({
connectors,
}: {
export async function createWeb3Agent({ connectors, }: {
connectors: ConnectorInfo[]
}) {
const didProviders: Record<string, AbstractIdentifierProvider> = {}
const didProviders: Record<string, AbstractIdentifierProvider> = {
'did:peer': new PeerDIDProvider({ defaultKms: 'local' }),
'did:key': new KeyDIDProvider({ defaultKms: 'local' }),
'did:jwk': new JwkDIDProvider({ defaultKms: 'local' }),
// TODO: add ethr and pkh providers backed by kmsLocal here too?
}
const web3Providers: Record<string, Web3Provider> = {}

connectors.forEach((info) => {
Expand All @@ -89,17 +103,17 @@ export async function createWeb3Agent({
})
web3Providers[info.name] = info.provider
})
didProviders['did:peer'] = new PeerDIDProvider({ defaultKms: 'local' })

const id = 'web3Agent'
const agent = createAgent<
IDIDManager &
IKeyManager &
IResolver &
ICredentialIssuerEIP712 &
ICredentialPlugin &
IIdentifierProfilePlugin &
DIDDiscovery
IKeyManager &
IResolver &
ICredentialIssuerEIP712 &
ICredentialPlugin &
IIdentifierProfilePlugin &
DIDDiscovery &
ICredentialIssuerLD
>({
context: {
id,
Expand All @@ -109,12 +123,12 @@ export async function createWeb3Agent({
plugins: [
new DIDResolverPlugin({
resolver: new Resolver({
ethr: ethrDidResolver({
infuraProjectId,
}).ethr,
pkh: getDidPkhResolver().pkh,
web: webDidResolver().web,
peer: peerDidResolver().peer,
...ethrDidResolver({ infuraProjectId, }),
...getDidPkhResolver(),
...webDidResolver(),
...peerDidResolver(),
...getDidJwkResolver(),
...getDidKeyResolver(),
}, { cache: true }),
}),
new KeyManager({
Expand All @@ -133,6 +147,10 @@ export async function createWeb3Agent({
}),
new CredentialPlugin(),
new CredentialIssuerEIP712(),
new CredentialIssuerLD({
contextMaps: [LdDefaultContexts, credential_contexts as any],
suites: [new VeramoEcdsaSecp256k1RecoverySignature2020(), new VeramoEd25519Signature2018()],
}),
new DataStoreJson(dataStore),
new MessageHandler({
messageHandlers: [
Expand Down
Loading