Download wp-calypso/desktop/app/lib/keychain/index.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 797 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/desktop/app/lib/keychain/index.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/desktop/app/lib/keychain/index.js
-
curl -L -o index.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/desktop/app/lib/keychain/index.js
797 Bytes
| const { safeStorage } = require( 'electron' ); | |
| const ElectronStore = require( 'electron-store' ); | |
| const keychainService = 'WordPress.com'; | |
| const encoding = 'utf8'; | |
| const store = new ElectronStore( { | |
| name: keychainService, | |
| watch: true, | |
| } ); | |
| async function write( key, value ) { | |
| if ( ! safeStorage.isEncryptionAvailable() ) { | |
| throw new Error( 'Encryption is not avaialble.' ); | |
| } | |
| const buffer = safeStorage.encryptString( value ); | |
| store.set( key, buffer.toString( encoding ) ); | |
| } | |
| async function read( key ) { | |
| if ( store.has( key ) ) { | |
| const buffer = store.get( key ); | |
| return safeStorage.decryptString( Buffer.from( buffer, encoding ) ); | |
| } | |
| throw new Error( 'Requested value not found.' ); | |
| } | |
| async function clear() { | |
| store.clear(); | |
| } | |
| module.exports = { | |
| clear, | |
| write, | |
| read, | |
| }; | |