-
Notifications
You must be signed in to change notification settings - Fork 28
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
feat: revoke in issuer #918
base: develop
Are you sure you want to change the base?
Conversation
packages/credentials/src/issuer.ts
Outdated
import * as Kilt from '@kiltprotocol/sdk-js' | ||
import * as KiltChain from '@kiltprotocol/chain-helpers' |
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.
As with the other PR, no imports from sdk-js here and no blanket imports.
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.
Done at: ccac9b9
packages/credentials/src/issuer.ts
Outdated
KeyringPair, | ||
DidUrl, | ||
} from '@kiltprotocol/types' | ||
import {authorizeTx} from "@kiltprotocol/did" |
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.
make sure you run prettier for auto-formatting
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.
Fixed at: ccac9b9
packages/credentials/src/issuer.ts
Outdated
attester: DidUrl, | ||
submitterAccount: KeyringPair, | ||
signCallback: any, | ||
credential: VerifiableCredential, |
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.
I'd like to only see two parameters here:
attester: DidUrl, | |
submitterAccount: KeyringPair, | |
signCallback: any, | |
credential: VerifiableCredential, | |
credential: VerifiableCredential, | |
issuer: IssuerOptions, |
This is enough for issuance, and will also be enough for revocation.
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.
Fixed at: ccac9b9
packages/credentials/src/issuer.ts
Outdated
try { | ||
const api = Kilt.ConfigService.get('api') | ||
const rootHash = credential.id?.split(':').pop()! | ||
const decodedroothash = base58Decode(rootHash); | ||
|
||
const revokeTx = api.tx.attestation.revoke(decodedroothash, null) as any | ||
const [submitter] = (await Kilt.getSignersForKeypair({ | ||
keypair: submitterAccount, | ||
type: 'Ed25519', | ||
})) as Array<SignerInterface<'Ed25519', KiltAddress>> | ||
|
||
const authorizedTx = await authorizeTx( | ||
attester, | ||
revokeTx, | ||
signCallback, | ||
submitter.id | ||
) | ||
|
||
const response = await KiltChain.Blockchain.signAndSubmitTx(authorizedTx, submitterAccount) as Object | ||
const responseObj = JSON.parse(JSON.stringify(response)); | ||
|
||
return { | ||
success: true, | ||
info: { | ||
blockNumber: responseObj.blockNumber, | ||
blockHash: responseObj.status.finalized, | ||
transactionHash: responseObj.txHash | ||
} | ||
} | ||
|
||
} catch (error: unknown) { | ||
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred'; | ||
return { | ||
success: false, | ||
error: [errorMessage], | ||
info: {} | ||
} | ||
} |
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.
In order to make sure we can support future credential- and proof types without breaking the function interfaces, this function should be set up to detect what kind of revocation status method we are dealing with, and if it's a of the KiltRevocationStatusV1
type, call the right logic to revoke the credential.
Can you move the implementation to packages/credentials/src/V1/KiltRevocationStatusV1.ts
, and in the function here only check which type of credentialStatus method we are dealing with, call the function implemented in KiltRevocationStatusV1.ts if it's the right one, and error if not? the issue
function above should give you an idea.
Btw all the info you need for revocation is contained in the credentialStatus id, which is composed as follows:
${chainId}/kilt:attestation/${base58Encode(rootHash)}
Because we have the chain id here as well, which contains the genesis hash of the chain on which the credential was attested, you can even check if we are connected to the right network (i.e., peregrine vs spiritnet)! See the check
function in KiltRevocationStatusV1.ts for an example.
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.
I am working on a second commit for this.
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.
Fixed at: 110a5cc
fixes KILTProtocol/ticket#3646
Please include a summary of the changes provided with this pull request and which issue has been fixed.
Please also provide some context if necessary.
How to test:
Please provide a brief step-by-step instruction.
If necessary provide information about dependencies (specific configuration, branches, database dumps, etc.)
Checklist: