Skip to content

Commit 2ee5d7d

Browse files
authored
chore: upgrade sdk to v0.35 (#81)
## fixes KILTProtocol/ticket#NoTicket Upgrades to SDK version v0.35 It also fixes a bug that stoped the `did-configuration` from running succesfully.
1 parent 0882d58 commit 2ee5d7d

File tree

8 files changed

+215
-158
lines changed

8 files changed

+215
-158
lines changed

backend/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
"build": "tsc"
1212
},
1313
"dependencies": {
14-
"@kiltprotocol/sdk-js": "^0.32.0",
15-
"@kiltprotocol/types": "^0.32.0",
16-
"@kiltprotocol/vc-export": "^0.32.0",
14+
"@kiltprotocol/sdk-js": "^0.35.0",
15+
"@kiltprotocol/types": "^0.35.0",
16+
"@kiltprotocol/vc-export": "^0.35.0",
1717
"body-parser": "^1.20.1",
1818
"cookie-parser": "^1.4.6",
1919
"cors": "^2.8.5",

backend/src/credentials/verifySubmittedCredential.ts

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { readCredentialCookie } from './readCredentialCookie'
1313
export async function verifySubmittedCredential(
1414
request: Request,
1515
response: Response,
16-
cTypeRequested: Kilt.IRequestCredentialContent
16+
cTypesRequested: Kilt.IRequestCredentialContent
1717
): Promise<Kilt.ICredentialPresentation> {
1818
const encryptedMessage = request.body
1919
console.log(
@@ -23,7 +23,7 @@ export async function verifySubmittedCredential(
2323
2
2424
)}`
2525
)
26-
const api = await getApi()
26+
await getApi()
2727

2828
const { keyAgreement } = generateKeyPairs(DAPP_DID_MNEMONIC)
2929
const decryptedMessage = await Kilt.Message.decrypt(
@@ -44,51 +44,46 @@ export async function verifySubmittedCredential(
4444

4545
console.log('Decrypted Credential being verify: \n', credential)
4646

47+
const chosenCType = cTypesRequested.cTypes.find(
48+
(ctype) => ctype.cTypeHash === credential.claim.cTypeHash
49+
)
50+
51+
if (!chosenCType) {
52+
throw new Error(
53+
"The User did not complied to the Credential Request. The Server does not accept the submitted Credential's Type."
54+
)
55+
}
56+
4757
// Know against to what structure you want to compare to:
48-
const requestedCTypeHash = cTypeRequested.cTypes[0].cTypeHash
49-
const requestedCTypeDetailed = await Kilt.CType.fetchFromChain(
58+
const requestedCTypeHash = chosenCType.cTypeHash
59+
const { cType: requestedCType } = await Kilt.CType.fetchFromChain(
5060
`kilt:ctype:${requestedCTypeHash}`
5161
)
5262

53-
// The function Credential.verifyPresentation can check against a specific cType structure.
54-
// This cType needs to match the ICType-interface.
55-
// To fullfil this structure we need to remove the 'creator' and 'createdAt' properties from our fetched object.
56-
const { $id, $schema, title, properties, type } = requestedCTypeDetailed
57-
const requestedCType = { $id, $schema, title, properties, type }
58-
5963
const challengeOnRequest = await readCredentialCookie(
6064
request,
6165
response,
6266
JWT_SIGNER_SECRET
6367
)
6468

65-
await Kilt.Credential.verifyPresentation(credential, {
66-
challenge: challengeOnRequest,
67-
ctype: requestedCType
68-
})
69-
70-
const attestationChain = await api.query.attestation.attestations(
71-
credential.rootHash
72-
)
73-
74-
const attestation = Kilt.Attestation.fromChain(
75-
attestationChain,
76-
credential.rootHash
69+
const verifiedCredential = await Kilt.Credential.verifyPresentation(
70+
credential,
71+
{
72+
challenge: challengeOnRequest,
73+
ctype: requestedCType
74+
}
7775
)
7876

79-
if (attestation.revoked) {
77+
if (verifiedCredential.revoked) {
8078
throw new Error("Credential has been revoked and hence it's not valid.")
8179
}
8280

8381
// Check if the credentials was issued by one of our "trusted attesters"
84-
const attesterOfTheirCredential = attestation.owner
85-
const ourTrustedAttesters = cTypeRequested.cTypes.find((ctype) => {
86-
ctype.cTypeHash === credential.claim.cTypeHash
87-
})?.trustedAttesters
82+
const ourTrustedAttesters = chosenCType.trustedAttesters
8883

8984
// If you don't include a list of trusted attester on the credential-request, this check would be skipped
9085
if (ourTrustedAttesters) {
91-
if (!ourTrustedAttesters.includes(attesterOfTheirCredential)) {
86+
if (!ourTrustedAttesters.includes(verifiedCredential.attester)) {
9287
throw new Error(
9388
`The Credential was not issued by any of the trusted Attesters that the dApp relies on. \n List of trusted attesters: ${ourTrustedAttesters}`
9489
)

backend/src/server.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as Kilt from '@kiltprotocol/sdk-js'
21
import express, { Express, NextFunction, Request, Response } from 'express'
32
import cors from 'cors'
43
import bodyParser from 'body-parser'
@@ -23,6 +22,7 @@ import {
2322

2423
import { logout } from './access/logout'
2524
import { checkAccessCookie } from './access/checkAccessCookie'
25+
import { getApi } from './utils/connection'
2626

2727
const app: Express = express()
2828

@@ -117,7 +117,8 @@ validateEnvironmentConstants()
117117

118118
async function connectToKiltWebSocket() {
119119
try {
120-
await Kilt.connect(WSS_ADDRESS)
120+
// internally calls Kilt.connect(WSS_ADDRESS)
121+
await getApi()
121122
console.log(
122123
`🔗[websocket]: Connected to WebSocket server at ${WSS_ADDRESS}`
123124
)

backend/src/utils/fetchDidDocument.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,5 @@ export async function fetchDidDocument(): Promise<Kilt.DidDocument> {
4444
)
4545
}
4646

47-
Kilt.disconnect()
48-
4947
return didDocument
5048
}

frontend/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
"private": true,
55
"proxy": "http://localhost:2525/",
66
"dependencies": {
7-
"@kiltprotocol/sdk-js": "^0.32.0",
8-
"@kiltprotocol/types": "^0.31.0",
9-
"@kiltprotocol/vc-export": "^0.31.0",
7+
"@kiltprotocol/sdk-js": "^0.35.0",
8+
"@kiltprotocol/types": "^0.35.0",
9+
"@kiltprotocol/vc-export": "^0.35.0",
1010
"@polkadot/util": "^10.4.2",
1111
"kilt-extension-api": "0.1.0",
1212
"react": "^18.2.0",

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@
4949
"typescript": "^5.0.4"
5050
},
5151
"dependencies": {
52-
"@kiltprotocol/sdk-js": "^0.32.0",
53-
"@kiltprotocol/types": "^0.32.0",
54-
"@kiltprotocol/vc-export": "^0.32.0",
52+
"@kiltprotocol/sdk-js": "^0.35.0",
53+
"@kiltprotocol/types": "^0.35.0",
54+
"@kiltprotocol/vc-export": "^0.35.0",
5555
"@polkadot/util": "10.4.2",
5656
"@polkadot/util-crypto": "10.4.2",
5757
"@types/valid-url": "^1.0.7",

scripts/wellKnownDIDConfiguration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export async function createCredential(
7676
// Make sure that `ctypeDomainLinkage` contains the correct Domain Linkage CType.
7777
// Extensions expect this specific CTypes other CTypes will not be recognized.
7878
const cTypeUri =
79-
'kilt:ctype:0x9d271c790775ee831352291f01c5d04c7979713a5896dcf5e81708184cc5c643'
79+
'kilt:ctype:0xb08800a574c436831a2b9fce00fd16e9df489b2b3695e88a0895d148eca0311e'
8080
if (ctypeDomainLinkage.$id !== cTypeUri) {
8181
console.log(
8282
'The following CType URI is not the expected one:',

0 commit comments

Comments
 (0)