55 * found in the LICENSE file in the root directory of this source tree.
66 */
77
8- import type { DidDocument , DidUrl , VerificationMethod } from '@kiltprotocol/types'
98import * as Did from '@kiltprotocol/did'
9+ import type { DidDocument , DidUrl , SignerInterface , VerificationMethod } from '@kiltprotocol/types'
10+ import { Signers } from '@kiltprotocol/utils'
11+ import { u8aToString } from '@polkadot/util'
1012import { randomAsHex } from '@polkadot/util-crypto'
1113import { DecryptCallback , EncryptCallback } from '../../../types/Message.js'
12-
13- import type { ISessionRequest , ISession , ISessionResponse } from '../../../types/index.js'
14+ import type { ISession , ISessionRequest , ISessionResponse } from '../../../types/index.js'
1415import { KeyError } from '../../Error.js'
15- import { u8aToString } from '@polkadot/util'
1616
1717/**
1818 * Requests a session with a given DID document and name.
@@ -54,10 +54,12 @@ export async function verifySession(
5454 { encryptedChallenge, nonce, encryptionKeyUri : receiverEncryptionKeyUri } : ISessionResponse ,
5555 decryptCallback : DecryptCallback ,
5656 encryptCallback : EncryptCallback ,
57- authenticationSigner : ISession [ 'authenticationSigner' ] ,
57+ signers : SignerInterface [ ] ,
5858 {
59+ didDocument,
5960 dereferenceDidUrl = Did . dereference ,
6061 } : {
62+ didDocument ?: DidDocument
6163 dereferenceDidUrl ?: typeof Did . dereference
6264 } = { }
6365) : Promise < ISession > {
@@ -67,6 +69,21 @@ export async function verifySession(
6769 if ( ( encryptionKey as VerificationMethod ) ?. type !== 'Multikey' ) {
6870 throw new Error ( 'An encryption key is required' )
6971 }
72+ if ( ! didDocument ) {
73+ didDocument = (
74+ await dereferenceDidUrl ( Did . parse ( encryptionKeyUri ) . did , {
75+ accept : 'application/did+json' ,
76+ } )
77+ ) . contentStream as DidDocument
78+ }
79+ const authenticationSigner = Signers . selectSigner < SignerInterface < Signers . DidPalletSupportedAlgorithms , DidUrl > > (
80+ signers ,
81+ Signers . select . byDid ( didDocument , { verificationRelationship : 'authentication' } ) ,
82+ Signers . select . verifiableOnChain ( )
83+ )
84+ if ( ! authenticationSigner ) {
85+ throw new Error ( 'a signer for the responder DID authentication method is required' )
86+ }
7087
7188 const decryptedBytes = await decryptCallback ( {
7289 data : encryptedChallenge ,
0 commit comments