diff --git a/src/credentials/status/did-resolver-revocation.ts b/src/credentials/status/did-resolver-revocation.ts index d8dd6ed7..23f7ed18 100644 --- a/src/credentials/status/did-resolver-revocation.ts +++ b/src/credentials/status/did-resolver-revocation.ts @@ -11,8 +11,9 @@ export class DidDocumentCredentialStatusResolver implements CredentialStatusReso throw new Error('IssuerDID is not set in options'); } - const didString = opts?.issuerDID.string().replace(/:/g, '%3A'); - const url = `${this.didResolverUrl}/1.0/credential-status/${didString}`; + const url = `${this.didResolverUrl}/1.0/credential-status/${encodeURIComponent( + opts.issuerDID.string() + )}`; const resp = await fetch(url, { method: 'POST', body: JSON.stringify(credentialStatus) diff --git a/src/storage/blockchain/did-resolver-readonly-storage.ts b/src/storage/blockchain/did-resolver-readonly-storage.ts index 2e96bdad..ef6b2dc1 100644 --- a/src/storage/blockchain/did-resolver-readonly-storage.ts +++ b/src/storage/blockchain/did-resolver-readonly-storage.ts @@ -20,13 +20,7 @@ export class DidResolverStateReadonlyStorage implements IStateStorage { DID.parseFromId(Id.fromBigInt(id)), this.resolverUrl ); - const vm = (didDocument as DIDDocument).verificationMethod?.find( - (i) => i.type === 'Iden3StateInfo2023' - ); - if (!vm) { - throw new Error('Iden3StateInfo2023 verification method not found'); - } - const { global } = vm as VerificationMethod; + const { global } = this.getIden3StateInfo2023(didDocument); if (!global) { throw new Error('GIST root not found'); } @@ -54,13 +48,7 @@ export class DidResolverStateReadonlyStorage implements IStateStorage { gist: Hash.fromBigInt(root) } ); - const vm = (didDocument as DIDDocument).verificationMethod?.find( - (i) => i.type === 'Iden3StateInfo2023' - ); - if (!vm) { - throw new Error('Iden3StateInfo2023 verification method not found'); - } - const { global } = vm as VerificationMethod; + const { global } = this.getIden3StateInfo2023(didDocument); if (!global) { throw new Error('GIST root not found'); } @@ -70,9 +58,11 @@ export class DidResolverStateReadonlyStorage implements IStateStorage { getRpcProvider(): JsonRpcProvider { return new JsonRpcProvider(); } + publishState(): Promise { throw new Error('publishState method not implemented.'); } + publishStateGeneric(): Promise { throw new Error('publishStateGeneric method not implemented.'); } @@ -84,13 +74,17 @@ export class DidResolverStateReadonlyStorage implements IStateStorage { this.resolverUrl, opts ); - const vm = (didDocument as DIDDocument).verificationMethod?.find( - (i) => i.type === 'Iden3StateInfo2023' + const { info } = this.getIden3StateInfo2023(didDocument); + return { ...info }; + } + + private getIden3StateInfo2023(didDocument: DIDDocument): VerificationMethod { + const vm: VerificationMethod | undefined = didDocument.verificationMethod?.find( + (i: VerificationMethod) => i.type === 'Iden3StateInfo2023' ); if (!vm) { throw new Error('Iden3StateInfo2023 verification method not found'); } - const { info } = vm as VerificationMethod; - return { ...info }; + return vm; } } diff --git a/src/storage/blockchain/onchain-zkp-verifier.ts b/src/storage/blockchain/onchain-zkp-verifier.ts index a7a1fd5b..271901aa 100644 --- a/src/storage/blockchain/onchain-zkp-verifier.ts +++ b/src/storage/blockchain/onchain-zkp-verifier.ts @@ -384,7 +384,7 @@ export class OnChainZKPVerifier implements IOnChainZKPVerifier { ); } - private static packGlobalStateMsg(msg: GlobalStateUpdate): string { + public static packGlobalStateMsg(msg: GlobalStateUpdate): string { return new ethers.AbiCoder().encode( [ 'tuple(' + diff --git a/src/utils/did-helper.ts b/src/utils/did-helper.ts index 63d7b3a5..132a5030 100644 --- a/src/utils/did-helper.ts +++ b/src/utils/did-helper.ts @@ -82,7 +82,7 @@ export const resolveDIDDocumentAuth = async ( resolveURL: string, state?: Hash ): Promise => { - let url = `${resolveURL}/${did.string().replace(/:/g, '%3A')}`; + let url = `${resolveURL}/${encodeURIComponent(did.string())}`; if (state) { url += `?state=${state.hex()}`; } @@ -115,11 +115,11 @@ export const resolveDidDocument = async ( signature?: DIDDocumentSignature; } ): Promise => { - let didString = did.string().replace(/:/g, '%3A'); + let didString = encodeURIComponent(did.string()); // for gist resolve we have to `hide` user did (look into resolver implementation) const isGistRequest = opts?.gist && !opts.state; if (isGistRequest) { - didString = emptyStateDID(did).string().replace(/:/g, '%3A'); + didString = encodeURIComponent(emptyStateDID(did).string()); } let url = `${resolverUrl}/1.0/identifiers/${didString}`;