@@ -8,7 +8,7 @@ import type { SubjectInfo } from '@polkadot/ui-keyring/observable/types';
8
8
import type { KeypairType } from '@polkadot/util-crypto/types' ;
9
9
import type { AccountJson , AllowedPath , MessageTypes , RequestAccountChangePassword , RequestAccountCreateHardware , RequestAccountCreateSuri , RequestAccountEdit , RequestAccountExport , RequestAccountForget , RequestAccountShow , RequestAccountTie , RequestAccountValidate , RequestActiveTabUrlUpdate , RequestAuthorizeApprove , RequestAuthorizeReject , RequestBatchRestore , RequestDeriveCreate , RequestDeriveValidate , RequestJsonRestore , RequestMetadataApprove , RequestMetadataReject , RequestSeedCreate , RequestSeedValidate , RequestSigningApprovePassword , RequestSigningApproveSignature , RequestSigningCancel , RequestSigningIsLocked , RequestTypes , RequestUpdateAuthorizedAccounts , ResponseAccountExport , ResponseAuthorizeList , ResponseDeriveValidate , ResponseJsonGetAccountInfo , ResponseSeedCreate , ResponseSeedValidate , ResponseSigningIsLocked } from '../types' ;
10
10
11
- import { ALLOWED_PATH , PASSWORD_EXPIRY_MS } from '@polkadot/extension-base/defaults' ;
11
+ import { ALLOWED_PATH } from '@polkadot/extension-base/defaults' ;
12
12
import { isJsonAuthentic , signJson } from '@polkadot/extension-base/utils/accountJsonIntegrity' ;
13
13
import { metadataExpand } from '@polkadot/extension-chains' ;
14
14
import { wrapBytes } from '@polkadot/extension-dapp' ;
@@ -18,13 +18,12 @@ import { accounts as accountsObservable } from '@polkadot/ui-keyring/observable/
18
18
import { assert , isHex , u8aToHex } from '@polkadot/util' ;
19
19
import { keyExtractSuri , mnemonicGenerate , mnemonicValidate } from '@polkadot/util-crypto' ;
20
20
21
+ import chromeStorage from './chromeStorage' ;
21
22
import { POPUP_CREATE_WINDOW_DATA } from './consts' ;
22
23
import { openCenteredWindow } from './helpers' ;
23
24
import State from './State' ;
24
25
import { createSubscription , unsubscribe } from './subscriptions' ;
25
26
26
- type CachedUnlocks = Record < string , number > ;
27
-
28
27
type GetContentPort = ( tabId : number ) => chrome . runtime . Port
29
28
30
29
const SEED_DEFAULT_LENGTH = 12 ;
@@ -40,12 +39,9 @@ function isJsonPayload (value: SignerPayloadJSON | SignerPayloadRaw): value is S
40
39
}
41
40
42
41
export default class Extension {
43
- readonly #cachedUnlocks: CachedUnlocks ;
44
-
45
42
readonly #state: State ;
46
43
47
44
constructor ( state : State ) {
48
- this . #cachedUnlocks = { } ;
49
45
this . #state = state ;
50
46
}
51
47
@@ -137,14 +133,15 @@ export default class Extension {
137
133
return true ;
138
134
}
139
135
140
- private refreshAccountPasswordCache ( pair : KeyringPair ) : number {
136
+ private async refreshAccountPasswordCache ( pair : KeyringPair ) : Promise < number > {
141
137
const { address } = pair ;
142
138
143
- const savedExpiry = this . #cachedUnlocks[ address ] || 0 ;
139
+ const savedExpiry = await chromeStorage . getPasswordExpiry ( address ) ;
140
+
144
141
const remainingTime = savedExpiry - Date . now ( ) ;
145
142
146
143
if ( remainingTime < 0 ) {
147
- this . #cachedUnlocks [ address ] = 0 ;
144
+ await chromeStorage . removePassword ( address ) ;
148
145
pair . lock ( ) ;
149
146
150
147
return 0 ;
@@ -351,7 +348,7 @@ export default class Extension {
351
348
throw error ;
352
349
}
353
350
354
- this . refreshAccountPasswordCache ( pair ) ;
351
+ await this . refreshAccountPasswordCache ( pair ) ;
355
352
356
353
// if the keyring pair is locked, the password is needed
357
354
if ( pair . isLocked && ! password ) {
@@ -412,9 +409,15 @@ export default class Extension {
412
409
// unlike queued.account.address the following
413
410
// address is encoded with the default prefix
414
411
// which what is used for password caching mapping
415
- this . #cachedUnlocks [ pair . address ] = Date . now ( ) + PASSWORD_EXPIRY_MS ;
412
+ await chromeStorage . setPassword ( pair . address ) ;
416
413
} else {
417
- pair . lock ( ) ;
414
+ const savedExpiry = await chromeStorage . getPasswordExpiry ( pair . address ) ;
415
+
416
+ const remainingTime = savedExpiry - Date . now ( ) ;
417
+
418
+ if ( remainingTime <= 0 ) {
419
+ pair . lock ( ) ;
420
+ }
418
421
}
419
422
420
423
await this . #state. removeSignRequest ( id ) ;
@@ -449,7 +452,7 @@ export default class Extension {
449
452
450
453
assert ( pair , 'Unable to find pair' ) ;
451
454
452
- const remainingTime = this . refreshAccountPasswordCache ( pair ) ;
455
+ const remainingTime = await this . refreshAccountPasswordCache ( pair ) ;
453
456
454
457
return {
455
458
isLocked : pair . isLocked ,
0 commit comments