interface Methods { open ( buffer , nonce , secretKey ) : Buffer | null ; close ( opusPacket , nonce , secretKey ) : Buffer ; random ( bytes , nonce ) : Buffer ; } const libs = { sodium : ( sodium ) : Methods => ( { open : sodium . api . crypto_secretbox_open_easy , close : sodium . api . crypto_secretbox_easy , random : ( n , buffer ? ) => { if ( ! buffer ) buffer = Buffer . allocUnsafe ( n ) ; sodium . api . randombytes_buf ( buffer ) ; return buffer ; } , } ) , 'libsodium-wrappers' : ( sodium ) : Methods => ( { open : sodium . crypto_secretbox_open_easy , close : sodium . crypto_secretbox_easy , random : ( n ) => sodium . randombytes_buf ( n ) , } ) , tweetnacl : ( tweetnacl ) : Methods => ( { open : tweetnacl . secretbox . open , close : tweetnacl . secretbox , random : ( n ) => tweetnacl . randomBytes ( n ) , } ) , } as const ; const fallbackError = ( ) => { throw new Error ( `Cannot play audio as no valid encryption package is installed.
- Install sodium, libsodium-wrappers, or tweetnacl.
- Use the generateDependencyReport() function for more information.\n` ) ; } ; const methods = { open : fallbackError , close : fallbackError , random : fallbackError , } ; void ( async ( ) => { for ( const libName of Object . keys ( libs ) as ( keyof typeof libs ) [ ] ) { try { const lib = require ( libName ) ; if ( libName === 'libsodium-wrappers' && lib . ready ) await lib . ready ; Object . assign ( methods , libs [ libName ] ( lib ) ) ; break ; } catch { } } } ) ( ) ; export { methods } ;