This repository was archived by the owner on Sep 11, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +17
-4
lines changed Expand file tree Collapse file tree 1 file changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -98,11 +98,24 @@ async function getSecretStorageKey(
9898 { keys : keyInfos } : { keys : Record < string , ISecretStorageKeyInfo > } ,
9999 ssssItemName ,
100100) : Promise < [ string , Uint8Array ] > {
101- const keyInfoEntries = Object . entries ( keyInfos ) ;
102- if ( keyInfoEntries . length > 1 ) {
103- throw new Error ( "Multiple storage key requests not implemented" ) ;
101+ const cli = MatrixClientPeg . get ( ) ;
102+ let keyId = await cli . getDefaultSecretStorageKeyId ( ) ;
103+ let keyInfo ;
104+ if ( keyId ) {
105+ // use the default SSSS key if set
106+ keyInfo = keyInfos [ keyId ] ;
107+ if ( ! keyInfo ) {
108+ throw new Error ( "Unable to use default SSSS key" ) ;
109+ }
110+ } else {
111+ // if no default SSSS key is set, fall back to a heuristic of using the
112+ // only available key, if only one key is set
113+ const keyInfoEntries = Object . entries ( keyInfos ) ;
114+ if ( keyInfoEntries . length > 1 ) {
115+ throw new Error ( "Multiple storage key requests not implemented" ) ;
116+ }
117+ [ keyId , keyInfo ] = keyInfoEntries [ 0 ] ;
104118 }
105- const [ keyId , keyInfo ] = keyInfoEntries [ 0 ] ;
106119
107120 // Check the in-memory cache
108121 if ( isCachingAllowed ( ) && secretStorageKeys [ keyId ] ) {
You can’t perform that action at this time.
0 commit comments