-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
11 changed files
with
309 additions
and
44 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,24 @@ | ||
import { CredentialStatus, RevocationStatus } from '../../verifiable'; | ||
import { CredentialStatusResolveOptions, CredentialStatusResolver } from './resolver'; | ||
|
||
export class DidDocumentCredentialStatusResolver implements CredentialStatusResolver { | ||
constructor(private readonly didResolverUrl: string) {} | ||
async resolve( | ||
credentialStatus: CredentialStatus, | ||
opts?: CredentialStatusResolveOptions | undefined | ||
): Promise<RevocationStatus> { | ||
if (!opts?.issuerDID) { | ||
throw new Error('IssuerDID is not set in options'); | ||
} | ||
|
||
const url = `${this.didResolverUrl}/1.0/credential-status/${encodeURIComponent( | ||
opts.issuerDID.string() | ||
)}`; | ||
const resp = await fetch(url, { | ||
method: 'POST', | ||
body: JSON.stringify(credentialStatus) | ||
}); | ||
const data = await resp.json(); | ||
return data; | ||
} | ||
} |
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,90 @@ | ||
import { Hash } from '@iden3/js-merkletree'; | ||
import { DIDDocument, VerificationMethod } from '../../iden3comm'; | ||
import { resolveDidDocument } from '../../utils'; | ||
import { RootInfo, StateInfo, StateProof } from '../entities'; | ||
import { IStateStorage } from '../interfaces'; | ||
import { DID, Id } from '@iden3/js-iden3-core'; | ||
import { JsonRpcProvider } from 'ethers'; | ||
|
||
export class DidResolverStateReadonlyStorage implements IStateStorage { | ||
constructor(private readonly resolverUrl: string) {} | ||
async getLatestStateById(id: bigint): Promise<StateInfo> { | ||
return this.getStateInfo(id); | ||
} | ||
async getStateInfoByIdAndState(id: bigint, state: bigint): Promise<StateInfo> { | ||
return this.getStateInfo(id, state); | ||
} | ||
|
||
async getGISTProof(id: bigint): Promise<StateProof> { | ||
const { didDocument } = await resolveDidDocument( | ||
DID.parseFromId(Id.fromBigInt(id)), | ||
this.resolverUrl | ||
); | ||
const { global } = this.getIden3StateInfo2023(didDocument); | ||
if (!global) { | ||
throw new Error('GIST root not found'); | ||
} | ||
const { proof } = global; | ||
if (!proof) { | ||
throw new Error('GIST proof not found'); | ||
} | ||
return { | ||
root: global.root, | ||
existence: proof.existence, | ||
siblings: proof.siblings?.map((sibling) => BigInt(sibling)), | ||
index: BigInt(0), | ||
value: BigInt(0), | ||
auxExistence: !!proof.node_aux, | ||
auxIndex: proof.node_aux ? BigInt(proof.node_aux.key) : BigInt(0), | ||
auxValue: proof.node_aux ? BigInt(proof.node_aux.value) : BigInt(0) | ||
}; | ||
} | ||
|
||
async getGISTRootInfo(root: bigint, userId: bigint): Promise<RootInfo> { | ||
const { didDocument } = await resolveDidDocument( | ||
DID.parseFromId(Id.fromBigInt(userId)), | ||
this.resolverUrl, | ||
{ | ||
gist: Hash.fromBigInt(root) | ||
} | ||
); | ||
const { global } = this.getIden3StateInfo2023(didDocument); | ||
if (!global) { | ||
throw new Error('GIST root not found'); | ||
} | ||
return global; | ||
} | ||
|
||
getRpcProvider(): JsonRpcProvider { | ||
return new JsonRpcProvider(); | ||
} | ||
|
||
publishState(): Promise<string> { | ||
throw new Error('publishState method not implemented.'); | ||
} | ||
|
||
publishStateGeneric(): Promise<string> { | ||
throw new Error('publishStateGeneric method not implemented.'); | ||
} | ||
|
||
private async getStateInfo(id: bigint, state?: bigint): Promise<StateInfo> { | ||
const opts = state ? { state: Hash.fromBigInt(state) } : undefined; | ||
const { didDocument } = await resolveDidDocument( | ||
DID.parseFromId(Id.fromBigInt(id)), | ||
this.resolverUrl, | ||
opts | ||
); | ||
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'); | ||
} | ||
return vm; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './state'; | ||
export * from './onchain-zkp-verifier'; | ||
export * from './onchain-revocation'; | ||
export * from './did-resolver-readonly-storage'; | ||
export * from './erc20-permit-sig'; |
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
Oops, something went wrong.