export const hasSetPasswordIdentifier = 'stacks-wallet-has-set-password' as const ; export const userHasAllowedDiagnosticsKey = 'stacks-wallet-has-allowed-diagnostics' ; export enum StorageKey { 'authenticationRequests' , 'transactionRequests' } interface RequestInfo { tabId : number ; origin : string ; } export function getKeyForRequest ( storageKey , request ) { return `${ storageKey }-${ request }` ; } export function storePayload ( { payload , storageKey , port , } ) { if ( ! port . sender ) return ; const { tab , url } = port . sender ; if ( ! tab ?. id || ! url ) return ; const origin = new URL ( url ) . origin ; const key = getKeyForRequest ( storageKey , payload ) ; const requestInfo = { tabId : tab . id , origin , } ; localStorage . setItem ( key , JSON . stringify ( requestInfo ) ) ; } function getRequestInfo ( storageKey , request ) { const key = getKeyForRequest ( storageKey , request ) ; const valueJSON = localStorage . getItem ( key ) ; if ( ! valueJSON ) return undefined ; const existing = JSON . parse ( valueJSON ) ; return existing ; } export function getTab ( storageKey , request ) { const existing = getRequestInfo ( storageKey , request ) ; if ( ! existing ?. tabId ) { throw new Error ( `Unable to get tab ID for request: ${ request }` ) ; } return existing . tabId ; } export function getRequestOrigin ( storageKey , request ) { const existing = getRequestInfo ( storageKey , request ) ; if ( ! existing ?. origin ) { throw new Error ( `Unable to get origin for request: ${ request }` ) ; } return existing . origin ; } export function deleteTabForRequest ( storageKey , request ) { const key = getKeyForRequest ( storageKey , request ) ; localStorage . removeItem ( key ) ; } export function getHasSetPassword ( ) { const persisted = localStorage . getItem ( hasSetPasswordIdentifier ) ; if ( persisted !== null ) { return JSON . parse ( persisted ) ; } return false ; } export function setToLocalstorageIfDefined ( storageKey , value ? ) { if ( value ) { localStorage . setItem ( storageKey , value ) ; } }