Skip to content
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: createPresentation on AttestedClaim #398

Merged
merged 3 commits into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/example.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable no-console */
import Kilt from '@kiltprotocol/sdk-js'
import type {
AttestedClaim,
Actors,
Claim,
CType,
Expand Down Expand Up @@ -124,7 +125,7 @@ async function doAttestation(
attester: Identity,
claim: Claim
): Promise<{
credential: Actors.Credential
credential: AttestedClaim
revocationHandle: Actors.types.IRevocationHandle
}> {
console.log(
Expand Down Expand Up @@ -213,7 +214,7 @@ async function doAttestation(

async function doVerification(
claimer: Identity,
credential: Actors.Credential
credential: AttestedClaim
): Promise<void> {
console.log(
((s) => s.padEnd(40 + s.length / 2, SEP).padStart(80, SEP))(
Expand Down
7 changes: 3 additions & 4 deletions packages/actors_api/src/actors/Claimer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @group unit/actor
*/

import { CType, Identity, SDKErrors } from '@kiltprotocol/core'
import { AttestedClaim, CType, Identity, SDKErrors } from '@kiltprotocol/core'
import type {
IClaim,
ICType,
Expand All @@ -14,7 +14,6 @@ import { mockChainQueryReturn } from '@kiltprotocol/chain-helpers/lib/blockchain
import Message from '@kiltprotocol/messaging'
import { Crypto } from '@kiltprotocol/utils'
import { Attester, Claimer, Verifier } from '..'
import Credential from '../credential/Credential'
import type { ClaimerAttestationSession } from './Claimer'

jest.mock(
Expand All @@ -29,7 +28,7 @@ describe('Claimer', () => {
let verifier: Identity
let cType: CType
let claim: IClaim
let credential: Credential
let credential: AttestedClaim

beforeAll(async () => {
attester = Identity.buildFromURI('//Alice')
Expand Down Expand Up @@ -179,7 +178,7 @@ describe('Claimer', () => {
}: {
messageBody?: MessageBodyType
allowPE?: boolean
credentials?: Credential[]
credentials?: AttestedClaim[]
}): Message => {
return Claimer.createPresentation(
claimer,
Expand Down
19 changes: 9 additions & 10 deletions packages/actors_api/src/actors/Claimer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@ import type {
IRequestForAttestation,
} from '@kiltprotocol/types'
import Message from '@kiltprotocol/messaging'
import Credential from '../credential/Credential'

/**
* Creates a presentation for an arbitrary amount of [[Credential]]s which can be verified in [[verifyPresentation]].
* Creates a presentation for an arbitrary amount of [[AttestedClaim]]s which can be verified in [[verifyPresentation]].
*
* @param identity The Claimer [[Identity]] which owns the [[Credential]]s.
* @param identity The Claimer [[Identity]] which owns the [[AttestedClaim]]s.
* @param message The message which represents multiple [[CType]]s, [[IRequestClaimsForCTypes]]s and whether privacy
* enhancement is supported.
* @param verifier The [[IPublicIdentity]] of the verifier that requested the presentation.
* @param credentials The [[Credential]]s which should be verified.
* @param credentials The [[AttestedClaim]]s which should be verified.
* @throws [[ERROR_PE_MISMATCH]], [[ERROR_MESSAGE_TYPE]], [[ERROR_PE_CREDENTIAL_MISSING]].
* @returns A message which represents either an array of [[AttestedClaim]]s if privacy enhancement is not supported
* or a combined presentation. Both of these options can be verified.
Expand All @@ -36,7 +35,7 @@ export function createPresentation(
identity: Identity,
message: IMessage,
verifier: IPublicIdentity,
credentials: Credential[]
credentials: AttestedClaim[]
): Message {
// did we get the right message type?
if (message.body.type !== Message.BodyType.REQUEST_CLAIMS_FOR_CTYPES) {
Expand Down Expand Up @@ -95,7 +94,7 @@ export type ClaimerAttestationSession = {
* include into the [[Attestation]] as legitimations.
* @param option.delegationId The unique identifier of the desired delegation.
* @returns A message containing an [[IRequestAttestationForClaim]] and a [[ClaimerAttestationSession]] which together with an [[ISubmitAttestationForClaim]]
* object can be used to create a [[Credential]].
* object can be used to create an [[AttestedClaim]].
*/
export function requestAttestation(
claim: IClaim,
Expand Down Expand Up @@ -132,23 +131,23 @@ export function requestAttestation(
}

/**
* Builds a [[Credential]] which can be verified when used in [[createPresentation]].
* Builds a [[AttestedClaim]] which can be verified when used in [[createPresentation]].
*
* @param message The session object corresponding to the [[ISubmitAttestationForClaim]].
* @param session The [[ClaimerAttestationSession]] which corresponds to the message and [[AttestedClaim]].
* @returns A signed and valid [[Credential]].
* @returns A signed and valid [[AttestedClaim]].
*/
export function buildCredential(
message: IMessage,
session: ClaimerAttestationSession
): Credential {
): AttestedClaim {
if (message.body.type !== Message.BodyType.SUBMIT_ATTESTATION_FOR_CLAIM) {
throw SDKErrors.ERROR_MESSAGE_TYPE(
message.body.type,
Message.BodyType.SUBMIT_ATTESTATION_FOR_CLAIM
)
}
return Credential.fromRequestAndAttestation(
return AttestedClaim.fromRequestAndAttestation(
session.requestForAttestation,
message.body.content.attestation
)
Expand Down
5 changes: 2 additions & 3 deletions packages/actors_api/src/actors/Verifier.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
* @group unit/actor
*/

import { CType, Identity } from '@kiltprotocol/core'
import { AttestedClaim, CType, Identity } from '@kiltprotocol/core'
import type { IClaim, ICType } from '@kiltprotocol/types'
import { mockChainQueryReturn } from '@kiltprotocol/chain-helpers/lib/blockchainApiConnection/__mocks__/BlockchainQuery'
import Message from '@kiltprotocol/messaging'
import { Crypto } from '@kiltprotocol/utils'
import { Attester, Claimer, Verifier } from '..'
import Credential from '../credential/Credential'

jest.mock(
'@kiltprotocol/chain-helpers/lib/blockchainApiConnection/BlockchainApiConnection'
Expand All @@ -20,7 +19,7 @@ describe('Verifier', () => {
let verifier: Identity
let cType: CType
let claim: IClaim
let credential: Credential
let credential: AttestedClaim
const blockchainApi = require('@kiltprotocol/chain-helpers/lib/blockchainApiConnection/BlockchainApiConnection')
.__mocked_api

Expand Down
12 changes: 6 additions & 6 deletions packages/actors_api/src/actors/Verifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ export class PresentationRequestBuilder {
*
* @param p The parameter object.
* @param p.ctypeHash The SHA-256 hash of the [[CType]].
* @param p.properties A list of properties of the [[Credential]]s the verifier has to see in order to verify it.
* @param p.legitimations An optional boolean representing whether the verifier requests to see the legitimations of the attesters which signed the [[Credential]]s.
* @param p.properties A list of properties of the [[AttestedClaim]]s the verifier has to see in order to verify it.
* @param p.legitimations An optional boolean representing whether the verifier requests to see the legitimations of the attesters which signed the [[AttestedClaim]]s.
* @param p.delegation An optional boolean representing whether the verifier requests to see the attesters' unique delegation identifiers.
* The default value for this is the current date.
* @returns A [[PresentationRequestBuilder]] on which you need to call [[finalize]] to complete the presentation request.
Expand Down Expand Up @@ -120,7 +120,7 @@ export class PresentationRequestBuilder {
/**
* Initiates a verification by creating a request on the Verifier's side.
*
* @returns A [[PresentationRequestBuilder]] based on a [[CType]] and a list of required disclosed attributes of the [[Credential]]s.
* @returns A [[PresentationRequestBuilder]] based on a [[CType]] and a list of required disclosed attributes of the [[AttestedClaim]]s.
*/
export function newRequestBuilder(): PresentationRequestBuilder {
return new PresentationRequestBuilder()
Expand Down Expand Up @@ -173,13 +173,13 @@ async function verifyPublicPresentation(
}

/**
* [ASYNC] Verifies the Claimer's presentation of [[Credential]]s.
* [ASYNC] Verifies the Claimer's presentation of [[AttestedClaim]]s.
*
* @param message The Claimer's presentation of the [[Credential]]s that should be verified, the result of [[createPresentation]].
* @param message The Claimer's presentation of the [[AttestedClaim]]s that should be verified, the result of [[createPresentation]].
* @param session The Verifier's private verification session created in [[finalize]].
* @throws [[ERROR_MESSAGE_TYPE]].
* @returns An object containing the keys
* **verified** (which describes whether the [[Credential]]s could be verified)
* **verified** (which describes whether the [[AttestedClaim]]s could be verified)
* and **claims** (an array of [[Claim]]s restricted on the disclosed attributes selected in [[requestPresentationForCtype]]).
*/
export async function verifyPresentation(
Expand Down
88 changes: 0 additions & 88 deletions packages/actors_api/src/credential/Credential.spec.ts

This file was deleted.

118 changes: 0 additions & 118 deletions packages/actors_api/src/credential/Credential.ts

This file was deleted.

Loading