-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
publish genesis state #133
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,13 +66,15 @@ export interface CredentialRequest { | |
* id: string; | ||
* nonce?: number; | ||
* type: CredentialStatusType; | ||
* issuerState?: string; | ||
* }} | ||
* @memberof CredentialRequest | ||
*/ | ||
revocationOpts: { | ||
id: string; | ||
nonce?: number; | ||
type: CredentialStatusType; | ||
issuerState?: string; | ||
}; | ||
} | ||
|
||
|
@@ -342,19 +344,40 @@ export class CredentialWallet implements ICredentialWallet { | |
type: VerifiableConstants.JSON_SCHEMA_VALIDATOR | ||
}; | ||
|
||
const id = | ||
request.revocationOpts.type === CredentialStatusType.SparseMerkleTreeProof | ||
? `${request.revocationOpts.id.replace(/\/$/, '')}/${request.revocationOpts.nonce}` | ||
: request.revocationOpts.id; | ||
|
||
cr.credentialStatus = { | ||
id, | ||
revocationNonce: request.revocationOpts.nonce, | ||
type: request.revocationOpts.type | ||
}; | ||
cr.credentialStatus = this.buildCredentialStatus(request); | ||
|
||
return cr; | ||
}; | ||
|
||
/** | ||
* Builds credential status | ||
* @param {CredentialRequest} request | ||
* @returns `CredentialStatus` | ||
*/ | ||
private buildCredentialStatus(request: CredentialRequest): CredentialStatus { | ||
const credentialStatus: CredentialStatus = { | ||
id: request.revocationOpts.id, | ||
type: request.revocationOpts.type, | ||
revocationNonce: request.revocationOpts.nonce | ||
}; | ||
|
||
switch (request.revocationOpts.type) { | ||
case (CredentialStatusType.SparseMerkleTreeProof, | ||
CredentialStatusType.Iden3commRevocationStatusV1): | ||
credentialStatus.id = `${request.revocationOpts.id.replace(/\/$/, '')}/${ | ||
request.revocationOpts.nonce | ||
}`; | ||
break; | ||
case CredentialStatusType.Iden3ReverseSparseMerkleTreeProof: | ||
credentialStatus.id = request.revocationOpts.issuerState | ||
? `${request.revocationOpts.id}/node?state=${request.revocationOpts.issuerState}` | ||
: `${request.revocationOpts.id}`; | ||
break; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would expect There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we need to modify id for Iden3commRevocationStatusV1. This is not right! Agent URL must remain the same. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How I understand this regexp cuts end '/'. We should cut the last '/' for the agent endpoint also to be sure that SDK will not create a URL like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Kolezhniuk @vmidylli about the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ilya-korotya ok, in case we don't need to throw an Error, I would expect
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
return credentialStatus; | ||
} | ||
|
||
/** | ||
* {@inheritDoc ICredentialWallet.findById} | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,8 +34,7 @@ import { | |
CredentialStatusType, | ||
ProofQuery | ||
} from '../verifiable'; | ||
import { CredentialRequest, ICredentialWallet } from '../credentials'; | ||
import { pushHashesToRHS, TreesModel } from '../credentials/rhs'; | ||
import { CredentialRequest, ICredentialWallet, pushHashesToRHS, TreesModel } from '../credentials'; | ||
import { TreeState } from '../circuits'; | ||
import { byteEncoder } from '../utils'; | ||
import { Options, getDocumentLoader } from '@iden3/js-jsonld-merklization'; | ||
|
@@ -223,6 +222,20 @@ export interface IIdentityWallet { | |
*/ | ||
publishStateToRHS(issuerDID: DID, rhsURL: string, revokedNonces?: number[]): Promise<void>; | ||
|
||
/** | ||
* | ||
* | ||
* @param {TreesModel} treeModel - trees model to publish | ||
* @param {string} rhsURL - reverse hash service URL | ||
* @param {number[]} [revokedNonces] - revoked nonces for the period from the last published | ||
* @returns `Promise<void>` | ||
*/ | ||
publishSpecificStateToRHS( | ||
treeModel: TreesModel, | ||
rhsURL: string, | ||
revokedNonces?: number[] | ||
): Promise<void>; | ||
|
||
/** | ||
* Extracts core claim from signature or merkle tree proof. If both proof persists core claim must be the same | ||
* | ||
|
@@ -370,7 +383,8 @@ export class IdentityWallet implements IIdentityWallet { | |
revocationOpts: { | ||
nonce: revNonce, | ||
id: opts.revocationOpts.id.replace(/\/$/, ''), | ||
type: opts.revocationOpts.type | ||
type: opts.revocationOpts.type, | ||
issuerState: currentState.hex() | ||
} | ||
}; | ||
|
||
|
@@ -409,6 +423,26 @@ export class IdentityWallet implements IIdentityWallet { | |
|
||
credential.proof = [mtpProof]; | ||
|
||
if (opts.revocationOpts.type === CredentialStatusType.Iden3ReverseSparseMerkleTreeProof) { | ||
const revocationTree = await this._storage.mt.getMerkleTreeByIdentifierAndType( | ||
did.string(), | ||
MerkleTreeType.Revocations | ||
); | ||
|
||
const rootOfRootsTree = await this._storage.mt.getMerkleTreeByIdentifierAndType( | ||
did.string(), | ||
MerkleTreeType.Roots | ||
); | ||
|
||
const trees: TreesModel = { | ||
state: currentState, | ||
claimsTree: claimsTree, | ||
revocationTree: revocationTree, | ||
rootsTree: rootOfRootsTree | ||
}; | ||
await pushHashesToRHS(currentState, trees, opts.revocationOpts.id); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can't we just call publishStateToRHS here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. I did it |
||
} | ||
|
||
await this._storage.identity.saveIdentity({ | ||
did: did.string(), | ||
state: currentState, | ||
|
@@ -618,6 +652,9 @@ export class IdentityWallet implements IIdentityWallet { | |
const jsonSchema = schema as JSONSchema; | ||
let credential: W3CCredential = new W3CCredential(); | ||
|
||
const issuerRoots = await this.getDIDTreeModel(issuerDID); | ||
req.revocationOpts.issuerState = issuerRoots.state.hex(); | ||
|
||
req.revocationOpts.nonce = | ||
typeof req.revocationOpts.nonce === 'number' | ||
? req.revocationOpts.nonce | ||
|
@@ -803,10 +840,18 @@ export class IdentityWallet implements IIdentityWallet { | |
return credentials; | ||
} | ||
|
||
/** {@inheritDoc IIdentityWallet.publishSpecificStateToRHS} */ | ||
async publishSpecificStateToRHS( | ||
treeModel: TreesModel, | ||
rhsURL: string, | ||
revokedNonces?: number[] | ||
): Promise<void> { | ||
await pushHashesToRHS(treeModel.state, treeModel, rhsURL, revokedNonces); | ||
} | ||
|
||
/** {@inheritDoc IIdentityWallet.publishStateToRHS} */ | ||
async publishStateToRHS(issuerDID: DID, rhsURL: string, revokedNonces?: number[]): Promise<void> { | ||
const treeState = await this.getDIDTreeModel(issuerDID); | ||
|
||
await pushHashesToRHS( | ||
treeState.state, | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better to write
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is already fixed