|
15 | 15 | * @packageDocumentation |
16 | 16 | */ |
17 | 17 |
|
18 | | -import type { ICredential, Did, SignerInterface, DidUrl } from '@kiltprotocol/types' |
| 18 | +import { dereference, signatureFromJson, verifyDidSignature } from '@kiltprotocol/did' |
| 19 | +import type { Did, DidUrl, ICredential, SignerInterface } from '@kiltprotocol/types' |
19 | 20 | import { Crypto, JsonSchema, Signers } from '@kiltprotocol/utils' |
| 21 | +import { IQuote, IQuoteAgreement, IQuoteAttesterSigned } from '../types/Quote.js' |
20 | 22 | import * as QuoteError from './Error.js' |
21 | | -import { dereference, verifyDidSignature, signatureFromJson } from '@kiltprotocol/did' |
22 | 23 | import { QuoteSchema } from './QuoteSchema.js' |
23 | | -import { IQuote, IQuoteAgreement, IQuoteAttesterSigned } from '../types/Quote.js' |
24 | 24 |
|
25 | 25 | /** |
26 | 26 | * Validates the quote against the meta schema and quote data against the provided schema. |
@@ -81,19 +81,21 @@ export async function createAttesterSignedQuote( |
81 | 81 | export async function verifyAttesterSignedQuote( |
82 | 82 | quote: IQuoteAttesterSigned, |
83 | 83 | { |
84 | | - didResolveKey, |
| 84 | + dereferenceDidUrl, |
85 | 85 | }: { |
86 | | - didResolveKey?: typeof dereference |
| 86 | + dereferenceDidUrl?: typeof dereference |
87 | 87 | } = {} |
88 | 88 | ): Promise<void> { |
89 | 89 | const { attesterSignature, ...basicQuote } = quote |
| 90 | + const { keyUri, signature } = signatureFromJson(attesterSignature) |
90 | 91 | await verifyDidSignature({ |
91 | | - ...signatureFromJson(attesterSignature), |
| 92 | + signerUrl: keyUri, |
| 93 | + signature, |
92 | 94 | message: Crypto.hashStr(Crypto.encodeObjectAsStr(basicQuote)), |
93 | 95 | expectedSigner: basicQuote.attesterDid, |
94 | 96 | expectedVerificationRelationship: 'authentication', |
95 | 97 | // @ts-expect-error this is dumb |
96 | | - dereferenceDidUrl: didResolveKey, |
| 98 | + dereferenceDidUrl, |
97 | 99 | }) |
98 | 100 |
|
99 | 101 | const messages: string[] = [] |
@@ -161,21 +163,23 @@ export async function createQuoteAgreement( |
161 | 163 | export async function verifyQuoteAgreement( |
162 | 164 | quote: IQuoteAgreement, |
163 | 165 | { |
164 | | - didResolveKey, |
| 166 | + dereferenceDidUrl, |
165 | 167 | }: { |
166 | | - didResolveKey?: typeof dereference |
| 168 | + dereferenceDidUrl?: typeof dereference |
167 | 169 | } = {} |
168 | 170 | ): Promise<void> { |
169 | 171 | const { claimerSignature, claimerDid, rootHash, ...attesterSignedQuote } = quote |
170 | 172 | // verify attester signature |
171 | | - await verifyAttesterSignedQuote(attesterSignedQuote, { didResolveKey }) |
| 173 | + await verifyAttesterSignedQuote(attesterSignedQuote, { dereferenceDidUrl }) |
172 | 174 | // verify claimer signature |
| 175 | + const { keyUri, signature } = signatureFromJson(claimerSignature) |
173 | 176 | await verifyDidSignature({ |
174 | | - ...signatureFromJson(claimerSignature), |
| 177 | + signature, |
| 178 | + signerUrl: keyUri, |
175 | 179 | message: Crypto.hashStr(Crypto.encodeObjectAsStr({ ...attesterSignedQuote, claimerDid, rootHash })), |
176 | 180 | expectedSigner: claimerDid, |
177 | 181 | expectedVerificationRelationship: 'authentication', |
178 | 182 | // @ts-expect-error why would this complain? |
179 | | - dereferenceDidUrl: didResolveKey, |
| 183 | + dereferenceDidUrl, |
180 | 184 | }) |
181 | 185 | } |
0 commit comments