Skip to content
This repository has been archived by the owner on Nov 24, 2022. It is now read-only.

Commit

Permalink
SDK Compatibility (#245)
Browse files Browse the repository at this point in the history
* chore: dsk refactoring compatibility

* chore: sdk refactoring compatibility

* chore: sdk refactoring compatibility

* chore: update compatibility

* chore: update compatibility

* fix: incomplete Ctype registration
  • Loading branch information
LeonFLK authored and tjwelde committed Jan 9, 2020
1 parent c25307c commit cc5e937
Show file tree
Hide file tree
Showing 24 changed files with 63 additions and 60 deletions.
2 changes: 1 addition & 1 deletion src/components/AttestationStatus/AttestationStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class AttestationStatus extends React.Component<Props, State> {
})
if (isAttestedClaim(attestation)) {
PersistentStore.store.dispatch(
Claims.Store.revokeAttestation(attestation.request.hash)
Claims.Store.revokeAttestation(attestation.request.rootHash)
)
} else {
PersistentStore.store.dispatch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class AttestedClaimVerificationView extends React.Component<Props, State> {
inline={true}
/>
<CTypePresentation
cTypeHash={attestedClaim.request.claim.cType}
cTypeHash={attestedClaim.request.claim.cTypeHash}
interactive={true}
linked={true}
inline={true}
Expand Down
2 changes: 1 addition & 1 deletion src/components/CTypePresentation/CTypePresentation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class CTypePresentation extends React.Component<Props, State> {
UiState.Store.updateCurrentTaskAction({
objective: sdk.MessageBodyType.SUBMIT_LEGITIMATIONS,
props: {
claim: { cType: cTypeHash },
claim: { cTypeHash: cTypeHash },
} as SubmitLegitimationsProps,
})
)
Expand Down
2 changes: 1 addition & 1 deletion src/components/ClaimDetailView/ClaimDetailView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ClaimDetailView extends Component<Props, State> {
<label>Ctype</label>
<div>
<CTypePresentation
cTypeHash={claim.cType}
cTypeHash={claim.cTypeHash}
linked={true}
interactive={true}
/>
Expand Down
10 changes: 5 additions & 5 deletions src/components/DevTools/DevTools.attestations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@ class BsAttestation {
)
}

return new sdk.RequestForAttestation(
return sdk.RequestForAttestation.fromClaimAndIdentity(
claimToAttest.claim,
_legitimations,
claimerIdentity.identity,
delegation ? delegation.id : undefined
_legitimations,
delegation ? delegation.id : null
)
}

Expand Down Expand Up @@ -220,7 +220,7 @@ class BsAttestation {
// store attestation locally
AttestationService.saveInStore({
attestation: attestedClaim.attestation,
cTypeHash: attestedClaim.request.claim.cType,
cTypeHash: attestedClaim.request.claim.cTypeHash,
claimerAddress: claimerIdentity.identity.address,
claimerAlias: claimerIdentity.metaData.name,
created: Date.now(),
Expand All @@ -243,7 +243,7 @@ class BsAttestation {
const cType: ICType = await BsCType.getByKey(bsClaim.cTypeKey)

const partialClaim = {
cType: cType.cType.hash as string,
cTypeHash: cType.cType.hash as string,
contents: bsClaim.data,
owner: claimerIdentity.identity.address,
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/DevTools/DevTools.claims.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class BsClaim {
): Promise<void | sdk.Claim> {
const identity = await BsIdentity.getByKey(BS_claimData.claimerKey)
const cType = (await BsCType.getByKey(BS_claimData.cTypeKey)).cType
const claim = new sdk.Claim(
sdk.CType.fromObject(cType),
const claim = sdk.Claim.fromCTypeAndClaimContents(
sdk.CType.fromCType(cType),
BS_claimData.data,
identity.identity
identity.identity.address
)

PersistentStore.store.dispatch(
Expand Down
2 changes: 1 addition & 1 deletion src/components/DevTools/DevTools.ctypes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class BsCType {
const ownerIdentity = (await BsIdentity.getByKey(bsCTypeData.owner))
.identity

const cType = sdk.CType.fromObject({
const cType = sdk.CType.fromCType({
...bsCTypeData,
owner: ownerIdentity.address,
})
Expand Down
8 changes: 4 additions & 4 deletions src/components/MyClaimCreateView/MyClaimCreateView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ class MyClaimCreateView extends Component<Props, State> {

public componentDidMount() {
const { partialClaim } = this.state
const { cType: cTypeHash } = partialClaim
const { cTypeHash: cTypeHash } = partialClaim

const blockUi: BlockUi = FeedbackService.addBlockUi({
headline: 'Fetching CTYPE',
})

CTypeRepository.findByHash(cTypeHash)
.then((dbCtype: ICType) => {
const cType = new sdk.CType(dbCtype.cType)
const cType = sdk.CType.fromCType(dbCtype.cType)
this.setState({ cType })
blockUi.remove()
})
Expand Down Expand Up @@ -149,10 +149,10 @@ class MyClaimCreateView extends Component<Props, State> {
const { contents } = partialClaim

if (cType && selectedIdentity) {
const newClaim: sdk.IClaim = new sdk.Claim(
const newClaim: sdk.IClaim = sdk.Claim.fromCTypeAndClaimContents(
cType,
contents || {},
selectedIdentity.identity
selectedIdentity.identity.address
)
saveClaim(newClaim, { alias: name })
notifySuccess(`Claim ${name} successfully created & saved.`)
Expand Down
2 changes: 1 addition & 1 deletion src/components/MyClaimListView/MyClaimListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class MyClaimListView extends React.Component<Props, State> {
</td>
<td className="cType">
<CTypePresentation
cTypeHash={claimEntry.claim.cType}
cTypeHash={claimEntry.claim.cTypeHash}
interactive={true}
linked={true}
/>
Expand Down
8 changes: 4 additions & 4 deletions src/components/SelectAttestedClaims/SelectAttestedClaims.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class SelectAttestedClaims extends React.Component<Props, State> {
}

return (_cTypeHashes || []).map(
(cTypeHash: Claims.Entry['claim']['cType']) => (
(cTypeHash: Claims.Entry['claim']['cTypeHash']) => (
<div className="cType-container" key={cTypeHash}>
<h4>
CType{' '}
Expand Down Expand Up @@ -154,7 +154,7 @@ class SelectAttestedClaims extends React.Component<Props, State> {

private getSelectAttestedClaim(
claimEntry: Claims.Entry,
cTypeHash?: Claims.Entry['claim']['cType']
cTypeHash?: Claims.Entry['claim']['cTypeHash']
) {
return (
<SelectAttestedClaim
Expand All @@ -174,7 +174,7 @@ class SelectAttestedClaims extends React.Component<Props, State> {
cTypeHashes && cTypeHashes.length
? claimEntries.filter(
(claimEntry: Claims.Entry) =>
cTypeHashes.indexOf(claimEntry.claim.cType) !== -1
cTypeHashes.indexOf(claimEntry.claim.cTypeHash) !== -1
)
: claimEntries

Expand All @@ -183,7 +183,7 @@ class SelectAttestedClaims extends React.Component<Props, State> {
(claimEntry: Claims.Entry) =>
claimEntry.attestations && claimEntry.attestations.length
),
(claimEntry: Claims.Entry) => claimEntry.claim.cType
(claimEntry: Claims.Entry) => claimEntry.claim.cTypeHash
)
}

Expand Down
2 changes: 1 addition & 1 deletion src/containers/ClaimCreate/ClaimCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ClaimCreate extends Component<Props, State> {
return (
cTypeHash && (
<MyClaimCreateView
partialClaim={{ cType: cTypeHash }}
partialClaim={{ cTypeHash: cTypeHash }}
onCreate={this.claimCreated}
onCancel={this.handleCancel}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/containers/ClaimView/ClaimView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class ClaimView extends React.Component<Props, State> {
UiState.Store.updateCurrentTaskAction({
objective: sdk.MessageBodyType.REQUEST_LEGITIMATIONS,
props: {
cTypeHash: claimEntry.claim.cType,
cTypeHash: claimEntry.claim.cTypeHash,
preSelectedClaimEntries: [claimEntry],
} as RequestLegitimationsProps,
})
Expand Down
2 changes: 1 addition & 1 deletion src/containers/CtypeCreate/CtypeCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class CTypeCreate extends React.Component<Props, State> {
let cType: sdk.CType

try {
cType = fromInputModel(this.state.cType)
cType = fromInputModel(this.state.cType, selectedIdentity.identity.address)
} catch (error) {
errorService.log({
error,
Expand Down
2 changes: 1 addition & 1 deletion src/containers/CtypeView/CtypeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class CtypeView extends React.Component<Props, State> {
private finishSelectAttesters(selectedAttesters: Contact[]) {
if (this.cTypeToLegitimate.cType.hash) {
attestationWorkflow.requestLegitimations(
[{ cType: this.cTypeToLegitimate.cType.hash }],
[{ cTypeHash: this.cTypeToLegitimate.cType.hash }],
selectedAttesters.map(
(contact: Contact) => contact.publicIdentity.address
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class RequestAttestation extends React.Component<

const myClaims = Claims.getClaimsByCTypeHash(
PersistentStore.store.getState(),
claim.cType
claim.cTypeHash
)

const withPreFilledClaim = !!(
Expand Down Expand Up @@ -140,7 +140,7 @@ class RequestAttestation extends React.Component<
<section className="selectClaim">
<h2>Select claim</h2>
<SelectClaims
cTypeHash={claim.cType}
cTypeHash={claim.cTypeHash}
onChange={this.onSelectClaims}
isMulti={false}
/>
Expand Down Expand Up @@ -202,7 +202,7 @@ class RequestAttestation extends React.Component<
savedClaimEntry.claim,
receiverAddresses,
(legitimations || []).map((legitimation: sdk.IAttestedClaim) =>
sdk.AttestedClaim.fromObject(legitimation)
sdk.AttestedClaim.fromAttestedClaim(legitimation)
),
delegationId
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class RequestLegitimation extends React.Component<
const { cTypeHash, receiverAddresses, onFinished } = this.props
const { selectedClaimEntries } = this.state
let claims: sdk.IPartialClaim[] = [
{ cType: cTypeHash } as sdk.IPartialClaim,
{ cTypeHash: cTypeHash } as sdk.IPartialClaim,
]

if (selectedClaimEntries && selectedClaimEntries.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ class SubmitLegitimations extends React.Component<Props, State> {
public componentDidMount() {
const { claim } = this.state

CTypeRepository.findByHash(claim.cType).then((cType: ICType) => {
CTypeRepository.findByHash(claim.cTypeHash).then((cType: ICType) => {
this.setState({
cType: sdk.CType.fromObject(cType.cType),
cType: sdk.CType.fromCType(cType.cType),
})
})
}
Expand Down
4 changes: 2 additions & 2 deletions src/containers/Tasks/Tasks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class Tasks extends React.Component<Props, State> {
}
case sdk.MessageBodyType.SUBMIT_LEGITIMATIONS: {
const props = currentTask.props
const cTypeHash = props.claim ? props.claim.cType : undefined
const cTypeHash = props.claim ? props.claim.cTypeHash : undefined
return this.getModal(
'Submit legitimations',
<>
Expand All @@ -157,7 +157,7 @@ class Tasks extends React.Component<Props, State> {
!!selectedReceivers.length ? (
<SubmitLegitimations
{...props}
claim={{ cType: selectedCTypes[0].cType.hash }}
claim={{ cTypeHash: selectedCTypes[0].cType.hash }}
receiverAddresses={selectedReceiverAddresses}
enablePreFilledClaim={true}
onFinished={this.onTaskFinished}
Expand Down
15 changes: 8 additions & 7 deletions src/services/AttestationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ class AttestationService {
throw new Error('No identity selected')
}

const attestation = new Kilt.Attestation(
const attestation = Kilt.Attestation.fromRequestAndPublicIdentity(
requestForAttestation,
selectedIdentity
selectedIdentity,
null
)

const attestedClaim = new Kilt.AttestedClaim(
const attestedClaim = Kilt.AttestedClaim.fromRequestAndAttestation(
requestForAttestation,
attestation
)
Expand All @@ -64,7 +65,7 @@ class AttestationService {
public static async revokeAttestation(
iAttestation: IAttestation
): Promise<void> {
const attestation = Kilt.Attestation.fromObject(iAttestation)
const attestation = Kilt.Attestation.fromAttestation(iAttestation)
const selectedIdentity = await AttestationService.getIdentity()

if (!selectedIdentity) {
Expand Down Expand Up @@ -111,14 +112,14 @@ class AttestationService {
public static async verifyAttestatedClaim(
attestedClaim: IAttestedClaim
): Promise<boolean> {
const _attestedClaim = Kilt.AttestedClaim.fromObject(attestedClaim)
const _attestedClaim = Kilt.AttestedClaim.fromAttestedClaim(attestedClaim)
return _attestedClaim.verify()
}

public static async verifyAttestation(
attestation: IAttestation
): Promise<boolean> {
const _attestation = Kilt.Attestation.fromObject(attestation)
const _attestation = Kilt.Attestation.fromAttestation(attestation)
return _attestation.verify()
}

Expand Down Expand Up @@ -158,7 +159,7 @@ class AttestationService {
state.selectedAttestedClaims.forEach(
(selectedAttestedClaim: IAttestedClaim) => {
attestedClaims.push(
Kilt.AttestedClaim.fromObject(
Kilt.AttestedClaim.fromAttestedClaim(
selectedAttestedClaim
).createPresentation(
AttestationService.getExcludedProperties(
Expand Down
6 changes: 3 additions & 3 deletions src/services/AttestationWorkflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ class AttestationWorkflow {
const identity: sdk.Identity = Wallet.getSelectedIdentity(
persistentStore.store.getState()
).identity
const requestForAttestation: sdk.IRequestForAttestation = new sdk.RequestForAttestation(
const requestForAttestation: sdk.IRequestForAttestation = sdk.RequestForAttestation.fromClaimAndIdentity(
claim,
legitimations,
identity,
legitimations,
delegationId
)
const messageBody = {
Expand Down Expand Up @@ -145,7 +145,7 @@ class AttestationWorkflow {
// store attestation locally
AttestationService.saveInStore({
attestation: attestedClaim.attestation,
cTypeHash: attestedClaim.request.claim.cType,
cTypeHash: attestedClaim.request.claim.cTypeHash,
claimerAddress: attestedClaim.request.claim.owner,
claimerAlias: claimer.metaData.name,
created: Date.now(),
Expand Down
18 changes: 9 additions & 9 deletions src/services/MessageRepository.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,24 +231,24 @@ class MessageRepository {

switch (type) {
case sdk.MessageBodyType.REQUEST_LEGITIMATIONS:
return [(message.body as sdk.IRequestLegitimations).content.cType]
return [(message.body as sdk.IRequestLegitimations).content.cTypeHash]
case sdk.MessageBodyType.SUBMIT_LEGITIMATIONS:
return [(message.body as sdk.ISubmitLegitimations).content.claim.cType]
return [(message.body as sdk.ISubmitLegitimations).content.claim.cTypeHash]
case sdk.MessageBodyType.REJECT_LEGITIMATIONS:
return [(message.body as sdk.IRejectLegitimations).content.claim.cType]
return [(message.body as sdk.IRejectLegitimations).content.claim.cTypeHash]

case sdk.MessageBodyType.REQUEST_ATTESTATION_FOR_CLAIM:
return [
(message.body as sdk.IRequestAttestationForClaim).content.claim.cType,
(message.body as sdk.IRequestAttestationForClaim).content.claim.cTypeHash,
]
case sdk.MessageBodyType.SUBMIT_ATTESTATION_FOR_CLAIM:
return [
(message.body as ISubmitAttestationForClaim).content.request.claim
.cType,
.cTypeHash,
]
case sdk.MessageBodyType.REJECT_ATTESTATION_FOR_CLAIM:
return [
(message.body as sdk.IRejectAttestationForClaim).content.claim.cType,
(message.body as sdk.IRejectAttestationForClaim).content.claim.cTypeHash,
]

case sdk.MessageBodyType.REQUEST_CLAIMS_FOR_CTYPES:
Expand All @@ -257,7 +257,7 @@ class MessageRepository {
const cTypeHashes: Array<
ICType['cType']['hash']
> = (message.body as sdk.ISubmitClaimsForCTypes).content.map(
(attestedClaim: IAttestedClaim) => attestedClaim.request.claim.cType
(attestedClaim: IAttestedClaim) => attestedClaim.request.claim.cTypeHash
)
const uniqueCTypeHashes: Array<
ICType['cType']['hash']
Expand All @@ -268,11 +268,11 @@ class MessageRepository {
return uniqueCTypeHashes
case sdk.MessageBodyType.ACCEPT_CLAIMS_FOR_CTYPES:
return [
(message.body as sdk.IAcceptClaimsForCTypes).content[0].request.hash,
(message.body as sdk.IAcceptClaimsForCTypes).content[0].request.rootHash,
]
case sdk.MessageBodyType.REJECT_CLAIMS_FOR_CTYPES:
return [
(message.body as sdk.IRejectClaimsForCTypes).content[0].request.hash,
(message.body as sdk.IRejectClaimsForCTypes).content[0].request.rootHash,
]

case sdk.MessageBodyType.REQUEST_ACCEPT_DELEGATION:
Expand Down
Loading

0 comments on commit cc5e937

Please sign in to comment.