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 +20
-4
lines changed Expand file tree Collapse file tree 1 file changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -98,11 +98,27 @@ 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+ // if the default key is not available, pretend the default key
109+ // isn't set
110+ keyId = undefined ;
111+ }
112+ }
113+ if ( ! keyId ) {
114+ // if no default SSSS key is set, fall back to a heuristic of using the
115+ // only available key, if only one key is set
116+ const keyInfoEntries = Object . entries ( keyInfos ) ;
117+ if ( keyInfoEntries . length > 1 ) {
118+ throw new Error ( "Multiple storage key requests not implemented" ) ;
119+ }
120+ [ keyId , keyInfo ] = keyInfoEntries [ 0 ] ;
104121 }
105- const [ keyId , keyInfo ] = keyInfoEntries [ 0 ] ;
106122
107123 // Check the in-memory cache
108124 if ( isCachingAllowed ( ) && secretStorageKeys [ keyId ] ) {
You can’t perform that action at this time.
0 commit comments