11/**
2- * Copyright (c) 2018-2024, Built on KILT.
3- *
4- * This source code is licensed under the BSD 4-Clause "Original" license
5- * found in the LICENSE file in the root directory of this source tree.
6- */
7-
8- /* eslint-disable @typescript-eslint/no-non-null-assertion */
9- /* eslint-disable @typescript-eslint/ban-ts-comment */
10-
11- /**
12- * Copyright (c) 2018-2024, BOTLabs GmbH.
2+ * Copyright (c) 2025, Built on KILT.
133 *
144 * This source code is licensed under the BSD 4-Clause "Original" license
155 * found in the LICENSE file in the root directory of this source tree.
188import { CType } from '@kiltprotocol/credentials'
199import * as DidModule from '@kiltprotocol/did'
2010import { Credential } from '@kiltprotocol/legacy-credentials'
21- import type { DidDocument , ICType , IClaim , ICredential , VerificationMethod } from '@kiltprotocol/types'
11+ import type { DidDocument , ICType , IClaim , ICredential } from '@kiltprotocol/types'
2212import { Crypto } from '@kiltprotocol/utils'
2313import { blake2AsU8a } from '@polkadot/util-crypto'
2414import { createLocalDemoFullDidFromKeypair , makeMockDereference , makeSigningKeyTool } from '../tests'
@@ -73,14 +63,15 @@ describe('Quote', () => {
7363 // build credential with legitimations
7464 credential = Credential . fromClaim ( claim )
7565
76- // @ts -ignore
66+ // Initialize the variable with proper type
7767 invalidCostQuoteData = {
68+ attesterDid : attesterIdentity . id ,
7869 cTypeHash : '0x12345678' ,
7970 cost : invalidCost ,
8071 currency : 'Euro' ,
8172 timeframe : date ,
8273 termsAndConditions : 'Lots of these' ,
83- } as IQuote
74+ }
8475
8576 invalidPropertiesQuoteData = {
8677 cTypeHash : '0x12345678' ,
@@ -130,21 +121,27 @@ describe('Quote', () => {
130121 const signer = (
131122 await ( await claimer ) . getSigners ( claimerIdentity , { verificationRelationship : 'authentication' } )
132123 ) [ 0 ]
133- const signature = DidModule . signatureToJson ( {
134- signature : await signer . sign ( {
135- data : blake2AsU8a (
136- Crypto . encodeObjectAsStr ( {
137- ...validAttesterSignedQuote ,
138- claimerDid : claimerIdentity . id ,
139- rootHash : credential . rootHash ,
140- } )
141- ) ,
142- } ) ,
143- verificationMethod : { id : `#${ signer . id . split ( '#' ) [ 1 ] } ` , controller : claimerIdentity . id } as VerificationMethod ,
124+ const sig = await signer . sign ( {
125+ data : blake2AsU8a (
126+ Crypto . encodeObjectAsStr ( {
127+ ...validAttesterSignedQuote ,
128+ claimerDid : claimerIdentity . id ,
129+ rootHash : credential . rootHash ,
130+ } )
131+ ) ,
132+ } )
133+
134+ const signature = DidModule . signatureFromJson ( {
135+ signature : sig . toString ( ) ,
136+ keyId : signer . id ,
144137 } )
145138 expect ( signature ) . toEqual ( quoteBothAgreed . claimerSignature )
146139
147140 const { fragment : attesterKeyId } = DidModule . parse ( validAttesterSignedQuote . attesterSignature . keyUri )
141+ const attesterKey = attesterIdentity . verificationMethod ?. find ( ( { id } ) => id === `#${ attesterKeyId } ` )
142+ if ( ! attesterKey ) {
143+ throw new Error ( 'Attester key not found' )
144+ }
148145
149146 expect ( ( ) =>
150147 Crypto . verify (
@@ -159,9 +156,7 @@ describe('Quote', () => {
159156 } )
160157 ) ,
161158 validAttesterSignedQuote . attesterSignature . signature ,
162- DidModule . multibaseKeyToDidKey (
163- attesterIdentity . verificationMethod ! . find ( ( { id } ) => id === attesterKeyId ) ! . publicKeyMultibase
164- ) . publicKey
159+ DidModule . multibaseKeyToDidKey ( attesterKey . publicKeyMultibase ) . publicKey
165160 )
166161 ) . not . toThrow ( )
167162 await expect (
@@ -218,12 +213,12 @@ describe('Quote', () => {
218213 const { attesterSignature, ...attesterSignedQuote } = validAttesterSignedQuote
219214 const wrongSignerAttester : IQuoteAttesterSigned = {
220215 ...attesterSignedQuote ,
221- attesterSignature : DidModule . signatureToJson ( {
222- signature : await signer . sign ( {
216+ attesterSignature : {
217+ signature : ( await signer . sign ( {
223218 data : Crypto . hash ( Crypto . encodeObjectAsStr ( attesterSignedQuote ) ) ,
224- } ) ,
225- verificationMethod : { id : `# ${ signer . id . split ( '#' ) [ 1 ] } ` , controller : claimerIdentity . id } as VerificationMethod ,
226- } ) ,
219+ } ) ) . toString ( ) ,
220+ keyUri : signer . id ,
221+ } ,
227222 }
228223
229224 await expect (
@@ -241,15 +236,12 @@ describe('Quote', () => {
241236 const { claimerSignature, ...restQuote } = quoteBothAgreed
242237 const wrongSignerClaimer : IQuoteAgreement = {
243238 ...restQuote ,
244- claimerSignature : DidModule . signatureToJson ( {
245- signature : await signer . sign ( {
239+ claimerSignature : {
240+ signature : ( await signer . sign ( {
246241 data : Crypto . hash ( Crypto . encodeObjectAsStr ( restQuote ) ) ,
247- } ) ,
248- verificationMethod : {
249- id : `#${ signer . id . split ( '#' ) [ 1 ] } ` ,
250- controller : attesterIdentity . id ,
251- } as VerificationMethod ,
252- } ) ,
242+ } ) ) . toString ( ) ,
243+ keyUri : signer . id ,
244+ } ,
253245 }
254246
255247 await expect (
0 commit comments