Skip to content

Commit

Permalink
feat: Public Creation removal of CType Creation (#260)
Browse files Browse the repository at this point in the history
* feat: removing ctype creation from public crdentials section

* feat: dry code and updating language
  • Loading branch information
Dudleyneedham authored Aug 16, 2023
1 parent 651e4ed commit 5529bfa
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 106 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
import * as Kilt from '@kiltprotocol/sdk-js'

// CType definition.
const ctype = Kilt.CType.fromProperties(`NFT Collection Certification CType`, {
name: {
type: 'string'
},
pieces: {
type: 'integer'
},
creationDate: {
type: 'string'
},
artistIdentity: {
type: 'string'
}
})

export function createNftCollectionCredential(
ctype: Kilt.ICType,
assetDid: Kilt.AssetDidUri,
artistDid: Kilt.DidUri
): Kilt.IPublicCredentialInput {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ import * as Kilt from '@kiltprotocol/sdk-js'

import { createCompleteFullDid } from '../did/05_full_did_complete'

import { createNftCollectionCType } from './01_create_ctype'
import { createNftCollectionCredential } from './02_create_credential'
import { fetchCredentialById } from './04_retrieve_credential_by_id'
import { issueCredential } from './03_issue_credential'
import { reclaimDeposit } from './10_reclaim_deposit'
import { retrieveAllAssetCredentials } from './05_retrieve_credentials_by_subject'
import { revokeCredential } from './08_revoke_remove_credential_by_content'
import { revokeCredentialById } from './07_revoke_remove_credential_by_id'
import { unrevokeCredential } from './09_unrevoke_credential'
import { verifyCredential } from './06_verify_credential'
import { createNftCollectionCredential } from './01_create_credential'
import { fetchCredentialById } from './03_retrieve_credential_by_id'
import { issueCredential } from './02_issue_credential'
import { reclaimDeposit } from './09_reclaim_deposit'
import { retrieveAllAssetCredentials } from './04_retrieve_credentials_by_subject'
import { revokeCredential } from './07_revoke_remove_credential_by_content'
import { revokeCredentialById } from './06_revoke_remove_credential_by_id'
import { unrevokeCredential } from './08_unrevoke_credential'
import { verifyCredential } from './05_verify_credential'

import { generateKeypairs } from '../utils/generateKeypairs'

Expand All @@ -29,27 +28,13 @@ export async function runAll(
})
)

console.log('1 public credentials) Create CType')
const ctype = await createNftCollectionCType(
attesterDid.uri,
submitterAccount,
async ({ data }) => ({
signature: keypairs.assertionMethod.sign(data),
keyType: keypairs.assertionMethod.type
})
)

console.log('2 public credentials) Create credential object')
console.log('1 public credentials) Create credential object')
const { authentication } = generateKeypairs()
const artistDid = Kilt.Did.getFullDidUriFromKey(authentication)
const collectionDid: Kilt.AssetDidUri =
'did:asset:eip155:1.erc721:0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb'
const credential = createNftCollectionCredential(
ctype,
collectionDid,
artistDid
)
console.log('3 public credentials) Issue credential')
const credential = createNftCollectionCredential(collectionDid, artistDid)
console.log('2 public credentials) Issue credential')
await issueCredential(
attesterDid.uri,
submitterAccount,
Expand All @@ -59,7 +44,7 @@ export async function runAll(
}),
credential
)
console.log('4 public credentials) Fetch credential by ID')
console.log('3 public credentials) Fetch credential by ID')
const credentialId = Kilt.PublicCredential.getIdForCredential(
credential,
attesterDid.uri
Expand All @@ -70,17 +55,17 @@ export async function runAll(
`Was not possible to retrieve just-issued credential with ID ${credentialId}`
)
}
console.log('5 public credentials) Retrieve credentials by subject')
console.log('4 public credentials) Retrieve credentials by subject')
const retrievedCredentials = await retrieveAllAssetCredentials(collectionDid)
if (!retrievedCredentials) {
throw new Error(
`Was not possible to retrieve just-issued credentials for asset ${collectionDid}`
)
}
console.log('6 public credentials) Verify credential')
console.log('5 public credentials) Verify credential')
await verifyCredential(fetchedCredential)
await verifyCredential(retrievedCredentials[0])
console.log('7 public credentials) Revoke and remove credential by ID')
console.log('6 public credentials) Revoke and remove credential by ID')
await revokeCredentialById(
attesterDid.uri,
submitterAccount,
Expand All @@ -91,7 +76,7 @@ export async function runAll(
credentialId,
true
)
console.log('8.1 public credentials) Re-issue credential')
console.log('7.1 public credentials) Re-issue credential')
await issueCredential(
attesterDid.uri,
submitterAccount,
Expand All @@ -101,7 +86,7 @@ export async function runAll(
}),
credential
)
console.log('8.2 public credentials) Revoke credential')
console.log('7.2 public credentials) Revoke credential')
await revokeCredential(
attesterDid.uri,
submitterAccount,
Expand All @@ -111,7 +96,7 @@ export async function runAll(
}),
credential
)
console.log('9 public credentials) Unrevoke credential')
console.log('8 public credentials) Unrevoke credential')
await unrevokeCredential(
attesterDid.uri,
submitterAccount,
Expand All @@ -121,7 +106,7 @@ export async function runAll(
}),
credential
)
console.log('10 public credentials) Reclaim deposit')
console.log('9 public credentials) Reclaim deposit')
await reclaimDeposit(submitterAccount, fetchedCredential)

console.log('Public credentials flow completed!')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,18 @@ title: Credential Issuance

import TsJsBlock from '@site/src/components/TsJsBlock';

import CreateCType from '!!raw-loader!@site/code_examples/sdk_examples/src/core_features/public_credentials/01_create_ctype.ts';
import CreateCredential from '!!raw-loader!@site/code_examples/sdk_examples/src/core_features/public_credentials/02_create_credential.ts';
import IssueCredential from '!!raw-loader!@site/code_examples/sdk_examples/src/core_features/public_credentials/03_issue_credential.ts';
import CreateCredential from '!!raw-loader!@site/code_examples/sdk_examples/src/core_features/public_credentials/01_create_credential.ts';
import IssueCredential from '!!raw-loader!@site/code_examples/sdk_examples/src/core_features/public_credentials/02_issue_credential.ts';

As for traditional KILT credentials, public credentials also have their structure defined by a [CType][ctypes-link], although CTypes that can be used to represent information about assets would probably differ from the ones used to represent information about people.

As mentioned in the section about credentials, the creation of a CType in KILT involves two steps: the definition of a CType and the anchoring of its hash on the KILT blockchain.

:::info
The creator of a CType is required to have a full DID with an attestation key.
To see how to manage DIDs, please refer to the [DID section](../01_dids/03_full_did_update.md).
:::

The following snippets show how to create a CType:

<TsJsBlock>
{CreateCType}
</TsJsBlock>
We will not cover the creation of a CType, please refer to the [CType creation](../04_claiming/01_ctype_creation.md)

## Create and Issue the Credential
## Create and Issue the Credential

With the new CType written to the chain, the new public credential object can be created with the actual content, and then written to the chain for the rest of the KILT users (and beyond) to consume.
Using the existing CType, the new public credential object can be created with the actual content, and then written to the chain for the rest of the KILT users (and beyond) to consume.

Creating a public credential is as simple as creating an object that conforms to the required structure of the CType:

Expand All @@ -51,4 +41,4 @@ This is to save space on credentials that actually benefit from CBOR compression
Hence, creating public credentials without the SDK requires the credential to be CBOR-encoded!
:::

[ctypes-link]: ../../../../concepts/05_credentials/02_ctypes.md
[ctypes-link]: ../../../../concepts/05_credentials/02_ctypes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ title: Retrieve Public Credentials

import TsJsBlock from '@site/src/components/TsJsBlock';

import RetrieveCredentialbyId from '!!raw-loader!@site/code_examples/sdk_examples/src/core_features/public_credentials/04_retrieve_credential_by_id.ts';
import RetrieveCredentialsbySubject from '!!raw-loader!@site/code_examples/sdk_examples/src/core_features/public_credentials/05_retrieve_credentials_by_subject.ts';
import VerifyCredential from '!!raw-loader!@site/code_examples/sdk_examples/src/core_features/public_credentials/06_verify_credential.ts';
import RetrieveCredentialbyId from '!!raw-loader!@site/code_examples/sdk_examples/src/core_features/public_credentials/03_retrieve_credential_by_id.ts';
import RetrieveCredentialsbySubject from '!!raw-loader!@site/code_examples/sdk_examples/src/core_features/public_credentials/04_retrieve_credentials_by_subject.ts';
import VerifyCredential from '!!raw-loader!@site/code_examples/sdk_examples/src/core_features/public_credentials/05_verify_credential.ts';

Public credentials have their best capability in the fact that they are, indeed, public by design.
This means that once issued, anyone who has access to an archive or full node for the KILT blockchain can retrieve them, making them very decentralized in nature.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ title: Revoke (and remove) Public Credentials

import TsJsBlock from '@site/src/components/TsJsBlock';

import RevokeRemoveCredentialById from '!!raw-loader!@site/code_examples/sdk_examples/src/core_features/public_credentials/07_revoke_remove_credential_by_id.ts';
import RevokeCredential from '!!raw-loader!@site/code_examples/sdk_examples/src/core_features/public_credentials/08_revoke_remove_credential_by_content.ts';
import UnrevokeCredential from '!!raw-loader!@site/code_examples/sdk_examples/src/core_features/public_credentials/09_unrevoke_credential.ts';
import ReclaimDeposit from '!!raw-loader!@site/code_examples/sdk_examples/src/core_features/public_credentials/10_reclaim_deposit.ts';
import RevokeRemoveCredentialById from '!!raw-loader!@site/code_examples/sdk_examples/src/core_features/public_credentials/06_revoke_remove_credential_by_id.ts';
import RevokeCredential from '!!raw-loader!@site/code_examples/sdk_examples/src/core_features/public_credentials/07_revoke_remove_credential_by_content.ts';
import UnrevokeCredential from '!!raw-loader!@site/code_examples/sdk_examples/src/core_features/public_credentials/08_unrevoke_credential.ts';
import ReclaimDeposit from '!!raw-loader!@site/code_examples/sdk_examples/src/core_features/public_credentials/09_reclaim_deposit.ts';

Depending on the use cases, some credentials, as with any other type of credential, might need to be temporarily or permanently revoked.

Expand Down

0 comments on commit 5529bfa

Please sign in to comment.