@@ -6,19 +6,33 @@ import java.io.File
66import java.io.FileInputStream
77
88class FileSystemScriptLoader (private val reactContext : ReactContext , private val nativeLoader : NativeScriptLoader ) {
9+ fun verifyBundle (code : ByteArray , config : ScriptConfig ): ByteArray {
10+ val (bundle, token) = code?.let {
11+ CodeSigningUtils .extractBundleAndToken(code)
12+ } ? : Pair (null , null )
13+
14+ if (config.verifyScriptSignature == " strict" || (config.verifyScriptSignature == " lax" && token != null )) {
15+ CodeSigningUtils .verifyBundle(reactContext, token, bundle)
16+ }
17+
18+ return bundle
19+ }
20+
921 fun load (config : ScriptConfig , promise : Promise ) {
1022 try {
23+ val code: ByteArray ;
24+
1125 if (config.absolute) {
1226 val path = config.url.path
1327 val file = File (path)
14- val code: ByteArray = FileInputStream (file).use { it.readBytes() }
15- nativeLoader.evaluate(code, config.sourceUrl, promise)
28+ code = FileInputStream (file).use { it.readBytes() }
1629 } else {
1730 val assetName = config.url.file.split(" /" ).last()
1831 val inputStream = reactContext.assets.open(assetName)
19- val code: ByteArray = inputStream.use { it.readBytes() }
20- nativeLoader.evaluate(code, config.sourceUrl, promise)
32+ code = inputStream.use { it.readBytes() }
2133 }
34+ val bundle: ByteArray = verifyBundle(code, config)
35+ nativeLoader.evaluate(bundle, config.sourceUrl, promise)
2236 } catch (error: Exception ) {
2337 promise.reject(
2438 ScriptLoadingError .ScriptEvalFailure .code,
0 commit comments