1
1
/**
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.
13
3
*
14
4
* This source code is licensed under the BSD 4-Clause "Original" license
15
5
* found in the LICENSE file in the root directory of this source tree.
18
8
import { CType } from '@kiltprotocol/credentials'
19
9
import * as DidModule from '@kiltprotocol/did'
20
10
import { 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'
22
12
import { Crypto } from '@kiltprotocol/utils'
23
13
import { blake2AsU8a } from '@polkadot/util-crypto'
24
14
import { createLocalDemoFullDidFromKeypair , makeMockDereference , makeSigningKeyTool } from '../tests'
@@ -73,14 +63,15 @@ describe('Quote', () => {
73
63
// build credential with legitimations
74
64
credential = Credential . fromClaim ( claim )
75
65
76
- // @ts -ignore
66
+ // Initialize the variable with proper type
77
67
invalidCostQuoteData = {
68
+ attesterDid : attesterIdentity . id ,
78
69
cTypeHash : '0x12345678' ,
79
70
cost : invalidCost ,
80
71
currency : 'Euro' ,
81
72
timeframe : date ,
82
73
termsAndConditions : 'Lots of these' ,
83
- } as IQuote
74
+ }
84
75
85
76
invalidPropertiesQuoteData = {
86
77
cTypeHash : '0x12345678' ,
@@ -130,21 +121,27 @@ describe('Quote', () => {
130
121
const signer = (
131
122
await ( await claimer ) . getSigners ( claimerIdentity , { verificationRelationship : 'authentication' } )
132
123
) [ 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 ,
144
137
} )
145
138
expect ( signature ) . toEqual ( quoteBothAgreed . claimerSignature )
146
139
147
140
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
+ }
148
145
149
146
expect ( ( ) =>
150
147
Crypto . verify (
@@ -159,9 +156,7 @@ describe('Quote', () => {
159
156
} )
160
157
) ,
161
158
validAttesterSignedQuote . attesterSignature . signature ,
162
- DidModule . multibaseKeyToDidKey (
163
- attesterIdentity . verificationMethod ! . find ( ( { id } ) => id === attesterKeyId ) ! . publicKeyMultibase
164
- ) . publicKey
159
+ DidModule . multibaseKeyToDidKey ( attesterKey . publicKeyMultibase ) . publicKey
165
160
)
166
161
) . not . toThrow ( )
167
162
await expect (
@@ -218,12 +213,12 @@ describe('Quote', () => {
218
213
const { attesterSignature, ...attesterSignedQuote } = validAttesterSignedQuote
219
214
const wrongSignerAttester : IQuoteAttesterSigned = {
220
215
...attesterSignedQuote ,
221
- attesterSignature : DidModule . signatureToJson ( {
222
- signature : await signer . sign ( {
216
+ attesterSignature : {
217
+ signature : ( await signer . sign ( {
223
218
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
+ } ,
227
222
}
228
223
229
224
await expect (
@@ -241,15 +236,12 @@ describe('Quote', () => {
241
236
const { claimerSignature, ...restQuote } = quoteBothAgreed
242
237
const wrongSignerClaimer : IQuoteAgreement = {
243
238
...restQuote ,
244
- claimerSignature : DidModule . signatureToJson ( {
245
- signature : await signer . sign ( {
239
+ claimerSignature : {
240
+ signature : ( await signer . sign ( {
246
241
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
+ } ,
253
245
}
254
246
255
247
await expect (
0 commit comments