private static void loadSecp256k1NativeLibrary ( ) throws Exception { if ( extracted ) { return ; } // Try loading library from fr.acinq.secp256k1.lib.path library path */ String secp256k1NativeLibraryPath = System . getProperty ( "fr.acinq.secp256k1.lib.path" ) ; String secp256k1NativeLibraryName = System . getProperty ( "fr.acinq.secp256k1.lib.name" ) ; if ( secp256k1NativeLibraryName == null ) { secp256k1NativeLibraryName = System . mapLibraryName ( "secp256k1" ) ; if ( secp256k1NativeLibraryName != null && secp256k1NativeLibraryName . endsWith ( ".dylib" ) ) { secp256k1NativeLibraryName = secp256k1NativeLibraryName . replace ( ".dylib" , ".jnilib" ) ; } } if ( secp256k1NativeLibraryPath != null ) { if ( loadNativeLibrary ( secp256k1NativeLibraryPath , secp256k1NativeLibraryName ) ) { extracted = true ; return ; } } // Load the os-dependent library from the jar file String packagePath = Secp256k1Loader . class . getPackage ( ) . getName ( ) . replaceAll ( "\\." , "/" ) ; secp256k1NativeLibraryPath = String . format ( "/%s/native/%s" , packagePath , OSInfo . getNativeLibFolderPathForCurrentOS ( ) ) ; boolean hasNativeLib = hasResource ( secp256k1NativeLibraryPath + "/" + secp256k1NativeLibraryName ) ; if ( ! hasNativeLib ) { if ( OSInfo . getOSName ( ) . equals ( "Mac" ) ) { // Fix for openjdk7 for Mac String altName = "libsecp256k1.jnilib" ; if ( hasResource ( secp256k1NativeLibraryPath + "/" + altName ) ) { secp256k1NativeLibraryName = altName ; hasNativeLib = true ; } } } if ( ! hasNativeLib ) { extracted = false ; throw new Exception ( String . format ( "No native library is found for os.name=%s and os.arch=%s. path=%s" , OSInfo . getOSName ( ) , OSInfo . getArchName ( ) , secp256k1NativeLibraryPath ) ) ; } // temporary library folder String tempFolder = getTempDir ( ) . getAbsolutePath ( ) ; // Try extracting the library from jar if ( extractAndLoadLibraryFile ( secp256k1NativeLibraryPath , secp256k1NativeLibraryName , tempFolder ) ) { extracted = true ; return ; } extracted = false ; return ; }
Loads secp256k1 native library using given path and name of the library .