@sphereon/ssi-sdk-ext.did-utils
Advanced tools
Comparing version 0.13.1-next.4 to 0.13.1-next.5
@@ -53,9 +53,17 @@ import { DIDDocument, DIDDocumentSection, DIDResolutionResult, IAgentContext, IDIDManager, IIdentifier, IKey, IResolver } from '@veramo/core'; | ||
export declare function getSupportedDIDMethods(didOpts: IDIDOptions, context: IAgentContext<IDIDManager>): Promise<string[]>; | ||
export declare function getAgentResolver(context: IAgentContext<IResolver>, opts?: { | ||
uniresolverFallback: boolean; | ||
export declare function getAgentResolver(context: IAgentContext<IResolver & IDIDManager>, opts?: { | ||
localResolution?: boolean; | ||
uniresolverResolution?: boolean; | ||
resolverResolution?: boolean; | ||
}): Resolvable; | ||
export declare class AgentDIDResolver implements Resolvable { | ||
private readonly context; | ||
private readonly uniresolverFallback; | ||
constructor(context: IAgentContext<IResolver>, uniresolverFallback?: boolean); | ||
private readonly resolverResolution; | ||
private readonly uniresolverResolution; | ||
private readonly localResolution; | ||
constructor(context: IAgentContext<IResolver & IDIDManager>, opts?: { | ||
uniresolverResolution?: boolean; | ||
localResolution?: boolean; | ||
resolverResolution?: boolean; | ||
}); | ||
resolve(didUrl: string, options?: DIDResolutionOptions): Promise<DIDResolutionResult>; | ||
@@ -62,0 +70,0 @@ } |
@@ -270,22 +270,49 @@ "use strict"; | ||
function getAgentResolver(context, opts) { | ||
var _a; | ||
return new AgentDIDResolver(context, (_a = opts === null || opts === void 0 ? void 0 : opts.uniresolverFallback) !== null && _a !== void 0 ? _a : true); | ||
return new AgentDIDResolver(context, opts); | ||
} | ||
exports.getAgentResolver = getAgentResolver; | ||
class AgentDIDResolver { | ||
constructor(context, uniresolverFallback) { | ||
constructor(context, opts) { | ||
this.context = context; | ||
this.uniresolverFallback = uniresolverFallback === true; | ||
this.resolverResolution = (opts === null || opts === void 0 ? void 0 : opts.resolverResolution) !== false; | ||
this.uniresolverResolution = (opts === null || opts === void 0 ? void 0 : opts.uniresolverResolution) !== false; | ||
this.localResolution = (opts === null || opts === void 0 ? void 0 : opts.localResolution) !== false; | ||
} | ||
resolve(didUrl, options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
return yield this.context.agent.resolveDid({ didUrl, options }); | ||
let resolutionResult; | ||
let err; | ||
if (this.resolverResolution) { | ||
try { | ||
resolutionResult = yield this.context.agent.resolveDid({ didUrl, options }); | ||
} | ||
catch (error) { | ||
err = error; | ||
} | ||
} | ||
catch (error) { | ||
if (this.uniresolverFallback) { | ||
return yield new did_uni_client_1.UniResolver().resolve(didUrl, options); | ||
if (!resolutionResult && this.localResolution) { | ||
try { | ||
const did = didUrl.split('#')[0]; | ||
const iIdentifier = yield this.context.agent.didManagerGet({ did }); | ||
resolutionResult = toDidResolutionResult(iIdentifier, { did }); | ||
err = undefined; | ||
} | ||
throw error; | ||
catch (error) { | ||
if (!err) { | ||
err = error; | ||
} | ||
} | ||
} | ||
if (!resolutionResult && this.uniresolverResolution) { | ||
resolutionResult = yield new did_uni_client_1.UniResolver().resolve(didUrl, options); | ||
err = undefined; | ||
} | ||
if (err) { | ||
// throw original error | ||
throw err; | ||
} | ||
if (!resolutionResult) { | ||
throw `Could not resolve ${didUrl}. Resolutions tried: online: ${this.resolverResolution}, local: ${this.localResolution}, uni resolver: ${this.uniresolverResolution}`; | ||
} | ||
return resolutionResult; | ||
}); | ||
@@ -292,0 +319,0 @@ } |
{ | ||
"name": "@sphereon/ssi-sdk-ext.did-utils", | ||
"description": "DID Utils", | ||
"version": "0.13.1-next.4+1e78d70", | ||
"version": "0.13.1-next.5+91def9c", | ||
"source": "src/index.ts", | ||
@@ -14,3 +14,3 @@ "main": "dist/index.js", | ||
"@sphereon/did-uni-client": "^0.6.0", | ||
"@sphereon/ssi-sdk-ext.key-utils": "0.13.1-next.4+1e78d70", | ||
"@sphereon/ssi-sdk-ext.key-utils": "0.13.1-next.5+91def9c", | ||
"@veramo/core": "4.2.0", | ||
@@ -38,3 +38,3 @@ "@veramo/utils": "4.2.0", | ||
"keywords": [], | ||
"gitHead": "1e78d70679ce8a70d82d2b7320c6f7489ff1a870" | ||
"gitHead": "91def9c446849521f5e9da5beb07bab6871501d1" | ||
} |
@@ -243,28 +243,63 @@ import { UniResolver } from '@sphereon/did-uni-client' | ||
export function getAgentResolver( | ||
context: IAgentContext<IResolver>, | ||
context: IAgentContext<IResolver & IDIDManager>, | ||
opts?: { | ||
uniresolverFallback: boolean | ||
localResolution?: boolean // Resolve identifiers hosted by the agent | ||
uniresolverResolution?: boolean // Resolve identifiers using universal resolver | ||
resolverResolution?: boolean // Use registered drivers | ||
} | ||
): Resolvable { | ||
return new AgentDIDResolver(context, opts?.uniresolverFallback ?? true) | ||
return new AgentDIDResolver(context, opts) | ||
} | ||
export class AgentDIDResolver implements Resolvable { | ||
private readonly context: IAgentContext<IResolver> | ||
private readonly uniresolverFallback: boolean | ||
private readonly context: IAgentContext<IResolver & IDIDManager> | ||
private readonly resolverResolution: boolean | ||
private readonly uniresolverResolution: boolean | ||
private readonly localResolution: boolean | ||
constructor(context: IAgentContext<IResolver>, uniresolverFallback?: boolean) { | ||
constructor( | ||
context: IAgentContext<IResolver & IDIDManager>, | ||
opts?: { uniresolverResolution?: boolean; localResolution?: boolean; resolverResolution?: boolean } | ||
) { | ||
this.context = context | ||
this.uniresolverFallback = uniresolverFallback === true | ||
this.resolverResolution = opts?.resolverResolution !== false | ||
this.uniresolverResolution = opts?.uniresolverResolution !== false | ||
this.localResolution = opts?.localResolution !== false | ||
} | ||
async resolve(didUrl: string, options?: DIDResolutionOptions): Promise<DIDResolutionResult> { | ||
try { | ||
return await this.context.agent.resolveDid({ didUrl, options }) | ||
} catch (error: unknown) { | ||
if (this.uniresolverFallback) { | ||
return await new UniResolver().resolve(didUrl, options) | ||
let resolutionResult: DIDResolutionResult | undefined | ||
let err: any | ||
if (this.resolverResolution) { | ||
try { | ||
resolutionResult = await this.context.agent.resolveDid({ didUrl, options }) | ||
} catch (error: unknown) { | ||
err = error | ||
} | ||
throw error | ||
} | ||
if (!resolutionResult && this.localResolution) { | ||
try { | ||
const did = didUrl.split('#')[0] | ||
const iIdentifier = await this.context.agent.didManagerGet({ did }) | ||
resolutionResult = toDidResolutionResult(iIdentifier, { did }) | ||
err = undefined | ||
} catch (error: unknown) { | ||
if (!err) { | ||
err = error | ||
} | ||
} | ||
} | ||
if (!resolutionResult && this.uniresolverResolution) { | ||
resolutionResult = await new UniResolver().resolve(didUrl, options) | ||
err = undefined | ||
} | ||
if (err) { | ||
// throw original error | ||
throw err | ||
} | ||
if (!resolutionResult) { | ||
throw `Could not resolve ${didUrl}. Resolutions tried: online: ${this.resolverResolution}, local: ${this.localResolution}, uni resolver: ${this.uniresolverResolution}` | ||
} | ||
return resolutionResult | ||
} | ||
@@ -271,0 +306,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
70392
900