-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
101 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { | ||
EthrDIDMethod, | ||
KeyDIDMethod, | ||
getSupportedResolvers, | ||
} from "@jpmorganchase/onyx-ssi-sdk"; | ||
import { Resolvable } from "did-resolver"; | ||
import { ethrProvider, VIDOS_API_KEY, VIDOS_RESOLVER_URL } from "../../config"; | ||
import { VidosResolver } from "./vidosResolver"; | ||
|
||
/** | ||
* Utility method for creation of DID resolver and DID methods. | ||
* If there is configuration for Vidos, it will create a VidosResolver, otherwise it will create a resolver with the `getDIDResolver` method from the supported DID methods. | ||
*/ | ||
export function createDidResolver() { | ||
const keyDidMethod = new KeyDIDMethod(); | ||
const ethrDidMethod = new EthrDIDMethod(ethrProvider); | ||
let didResolver: Resolvable; | ||
|
||
if (VIDOS_API_KEY || VIDOS_RESOLVER_URL) { | ||
if (VIDOS_API_KEY && VIDOS_RESOLVER_URL) { | ||
didResolver = new VidosResolver(VIDOS_RESOLVER_URL, VIDOS_API_KEY); | ||
} else { | ||
throw new Error( | ||
"Cannot create VidosResolver, VIDOS_API_KEY and VIDOS_RESOLVER_URL must be set together" | ||
); | ||
} | ||
} else { | ||
didResolver = getSupportedResolvers([]); | ||
} | ||
|
||
return { | ||
didMethods: { key: keyDidMethod, ethr: ethrDidMethod }, | ||
didResolver, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import type { | ||
DIDResolutionOptions, | ||
DIDResolutionResult, | ||
Resolvable | ||
} from "did-resolver"; | ||
|
||
/** | ||
* Create resolver that is using the Vidos service to resolve DIDs. | ||
* | ||
* - For more info: [https://vidos.id/](https://vidos.id/). | ||
* - For resolver configuration: [https://dashboard.vidos.id/](https://dashboard.vidos.id/). | ||
* - For docs: [https://vidos.id/docs/](https://vidos.id/docs/). | ||
*/ | ||
export class VidosResolver implements Resolvable { | ||
constructor(readonly instanceUrl: string, readonly apiKey: string) {} | ||
|
||
async resolve( | ||
didUrl: string, | ||
options?: DIDResolutionOptions | undefined | ||
): Promise<DIDResolutionResult> { | ||
const resolutionResponse = await fetch(`${this.instanceUrl}/${didUrl}`, { | ||
method: "GET", | ||
headers: { | ||
Authorization: `Bearer ${this.apiKey}`, | ||
Accept: options?.accept ?? "", | ||
}, | ||
}); | ||
|
||
return resolutionResponse.json(); | ||
} | ||
|
||
async getSupportedDidMethods(): Promise<string[]> { | ||
const methodsResponse = await fetch(`${this.instanceUrl}/methods`, { | ||
method: "GET", | ||
}); | ||
if (methodsResponse.ok) { | ||
const { methods } = await methodsResponse.json(); | ||
return methods; | ||
} | ||
throw new Error("Failed to fetch supported DID methods"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters