Skip to content

Commit

Permalink
feat: support universal resolver in verification lib (#637)
Browse files Browse the repository at this point in the history
  • Loading branch information
martines3000 authored Apr 24, 2024
1 parent 786b340 commit 411a30d
Show file tree
Hide file tree
Showing 20 changed files with 802 additions and 272 deletions.
5 changes: 5 additions & 0 deletions .changeset/dull-cows-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@blockchain-lab-um/did-provider-key": patch
---

Update Vitest
5 changes: 5 additions & 0 deletions .changeset/fair-elephants-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@blockchain-lab-um/veramo-datamanager": patch
---

Update Vitest
5 changes: 5 additions & 0 deletions .changeset/fifty-toes-beam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@blockchain-lab-um/utils": patch
---

Update Vitest
5 changes: 5 additions & 0 deletions .changeset/happy-otters-trade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@blockchain-lab-um/extended-verification": patch
---

Update Vitest
5 changes: 5 additions & 0 deletions .changeset/orange-sloths-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@blockchain-lab-um/extended-verification": minor
---

Add universal resolver support.
5 changes: 5 additions & 0 deletions .changeset/plenty-moles-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@blockchain-lab-um/oidc-client-plugin": patch
---

Update Vitest
5 changes: 5 additions & 0 deletions .changeset/short-birds-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@blockchain-lab-um/masca": patch
---

Update Vitest
6 changes: 6 additions & 0 deletions .changeset/wise-spoons-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@blockchain-lab-um/masca": patch
"@blockchain-lab-um/utils": patch
---

Move UniversalResolver service implementation to utils library.
8 changes: 4 additions & 4 deletions libs/did-provider-key/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@
"@veramo/did-resolver": "6.0.0",
"@veramo/key-manager": "6.0.0",
"@veramo/kms-local": "6.0.0",
"@vitest/coverage-v8": "1.3.1",
"@vitest/coverage-v8": "1.5.1",
"better-sqlite3": "^9.4.3",
"jest-extended": "4.0.2",
"multiformats": "^13.1.0",
"tsup": "^8.0.2",
"typeorm": "^0.3.20",
"vite": "^5.1.5",
"vite-tsconfig-paths": "^4.3.1",
"vitest": "1.3.1"
"vite": "^5.2.10",
"vite-tsconfig-paths": "^4.3.2",
"vitest": "1.5.1"
},
"publishConfig": {
"access": "public"
Expand Down
8 changes: 4 additions & 4 deletions libs/extended-verification/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@
"@veramo/did-provider-ethr": "6.0.0",
"@veramo/key-manager": "6.0.0",
"@veramo/kms-local": "6.0.0",
"@vitest/coverage-v8": "1.3.1",
"@vitest/coverage-v8": "1.5.1",
"desm": "^1.3.1",
"did-jwt": "^8.0.1",
"tsup": "^8.0.2",
"vite": "^5.1.5",
"vite-tsconfig-paths": "^4.3.1",
"vitest": "1.3.1"
"vite": "^5.2.10",
"vite-tsconfig-paths": "^4.3.2",
"vitest": "1.5.1"
},
"publishConfig": {
"access": "public"
Expand Down
4 changes: 4 additions & 0 deletions libs/extended-verification/src/createVeramoAgent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getDidKeyResolver as keyDidResolver } from '@blockchain-lab-um/did-provider-key';
import { UniversalResolverService } from '@blockchain-lab-um/utils';
import {
type ICredentialVerifier,
type IResolver,
Expand Down Expand Up @@ -44,6 +45,8 @@ export const createVeramoAgent = async (props?: CreateVeramoAgentProps) => {
},
];

UniversalResolverService.init();

return createAgent<IResolver & ICredentialVerifier>({
plugins: [
new CredentialPlugin(),
Expand All @@ -57,6 +60,7 @@ export const createVeramoAgent = async (props?: CreateVeramoAgentProps) => {
...ensDidResolver({
networks,
}),
...UniversalResolverService.getResolver(),
}),
}),
],
Expand Down
8 changes: 4 additions & 4 deletions libs/oidc/client-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
"devDependencies": {
"@sphereon/ssi-types": "^0.11.0",
"@types/qs": "^6.9.12",
"@vitest/coverage-v8": "1.3.1",
"@vitest/coverage-v8": "1.5.1",
"jest-extended": "4.0.2",
"tsup": "^8.0.2",
"vite": "^5.1.5",
"vite-tsconfig-paths": "^4.3.1",
"vitest": "1.3.1"
"vite": "^5.2.10",
"vite-tsconfig-paths": "^4.3.2",
"vitest": "1.5.1"
},
"veramo": {
"pluginInterfaces": {
Expand Down
62 changes: 62 additions & 0 deletions libs/utils/src/UniversalResolver.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import type {
DIDResolutionOptions,
DIDResolutionResult,
ParsedDID,
Resolvable,
} from 'did-resolver';

export class UniversalResolverService {
static universalResolverUrl: string | null = null;

static init(universalResolverUrl = 'https://masca.io/api/proxy/uniresolver') {
UniversalResolverService.universalResolverUrl = universalResolverUrl;
}

/**
* Function that resolves a DID string using the universal resolver
* @returns DIDResolutionResult
*/
static resolveDid = async (
did: string,
_parsed: ParsedDID,
_resolver: Resolvable,
_options: DIDResolutionOptions
): Promise<DIDResolutionResult> => {
try {
const response = await fetch(
`${UniversalResolverService.universalResolverUrl}/${did}`,
{
signal: AbortSignal.timeout(15000),
}
);
const data = (await response.json()) as DIDResolutionResult;
return data;
} catch (e) {
let errorMsg = 'Failed to resolve DID Document';
if (typeof e === 'string') {
errorMsg = e;
}
if ((e as Error).message && typeof (e as Error).message === 'string') {
errorMsg = (e as Error).message;
}
return {
didDocument: null,
didDocumentMetadata: {},
didResolutionMetadata: {
error: errorMsg,
},
};
}
};

static getResolver() {
return {
ens: UniversalResolverService.resolveDid,
ion: UniversalResolverService.resolveDid,
ebsi: UniversalResolverService.resolveDid,
web: UniversalResolverService.resolveDid,
github: UniversalResolverService.resolveDid,
cheqd: UniversalResolverService.resolveDid,
};
}
}
1 change: 1 addition & 0 deletions libs/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from './format.js';
export * from './jwk.js';
export * from './array.js';
export * from './qsCustomDecoder.js';
export * from './UniversalResolver.service.js';
8 changes: 4 additions & 4 deletions packages/datamanager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
"devDependencies": {
"@types/jsonpath": "^0.2.4",
"@types/uuid": "^9.0.8",
"@vitest/coverage-v8": "1.3.1",
"@vitest/coverage-v8": "1.5.1",
"jest-extended": "^4.0.2",
"tsup": "^8.0.2",
"vite": "^5.1.5",
"vite-tsconfig-paths": "^4.3.1",
"vitest": "1.3.1"
"vite": "^5.2.10",
"vite-tsconfig-paths": "^4.3.2",
"vitest": "1.5.1"
},
"publishConfig": {
"access": "public"
Expand Down
8 changes: 4 additions & 4 deletions packages/snap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@
"@types/jsonpath": "^0.2.4",
"@types/lodash.clonedeep": "^4.5.9",
"@types/qs": "^6.9.12",
"@vitest/coverage-v8": "1.3.1",
"@vitest/coverage-v8": "1.5.1",
"desm": "^1.3.1",
"esbuild": "0.20.1",
"jest-extended": "^4.0.2",
"jose": "^5.2.2",
"node-stdlib-browser": "^1.2.0",
"vite": "^5.1.5",
"vite-tsconfig-paths": "^4.3.1",
"vitest": "1.3.1"
"vite": "^5.2.10",
"vite-tsconfig-paths": "^4.3.2",
"vitest": "1.5.1"
},
"publishConfig": {
"access": "public",
Expand Down
2 changes: 1 addition & 1 deletion packages/snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"./files/circuits/credentialAtomicQuerySigV2/circuit_final.zkey",
"./files/circuits/credentialAtomicQuerySigV2/verification_key.json"
],
"shasum": "ojb0SBSAxtyw0jve30mjVcdByeY5rszbBwJlAfkvEuo="
"shasum": "Ml6z1doKdZGW/tsfT6uBILu5Z0D+79yLUz4hvIa37EI="
},
"initialPermissions": {
"endowment:ethereum-provider": {},
Expand Down
57 changes: 0 additions & 57 deletions packages/snap/src/UniversalResolver.service.ts

This file was deleted.

9 changes: 7 additions & 2 deletions packages/snap/src/veramo/Veramo.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ import type {
PresentationDefinition,
TokenResponse,
} from '@blockchain-lab-um/oidc-types';
import { type Result, isError } from '@blockchain-lab-um/utils';
import {
type Result,
isError,
UniversalResolverService,
} from '@blockchain-lab-um/utils';
import {
type AbstractDataStore,
DataManager,
Expand Down Expand Up @@ -91,7 +95,6 @@ import qs from 'qs';
import EthereumService from '../Ethereum.service';
import GeneralService from '../General.service';
import UIService from '../UI.service';
import UniversalResolverService from '../UniversalResolver.service';
import WalletService from '../Wallet.service';
import StorageService from '../storage/Storage.service';
import { normalizeCredential } from '../utils/credential';
Expand Down Expand Up @@ -995,6 +998,8 @@ class VeramoService {
vcStorePlugins.ceramic = new CeramicCredentialStore();
}

UniversalResolverService.init();

return createAgent<
IDIDManager &
IKeyManager &
Expand Down
Loading

0 comments on commit 411a30d

Please sign in to comment.