This plugin can be used to sign chunks so that their integrity can be verified before execution. You should consider code-signing your chunks when you are using CodeSplitting or ModuleFederation and want to deliver parts of your code remotely to the end-user. Compatible with both JS and Hermes-bytecode bundles.
stringPath to the private key. This can be either a relative path or an absolute one. Relative paths are resolved within context provided with project configuration.
booleantrueWhether to enable the plugin. You typically want to enable the plugin only for production builds and disable it for development.
string[] | RegExp | RegExp[][]Names of chunks to exclude from code-signing. You might want to use this if some of the chunks in your setup are not being delivered remotely and don't need to be verified.
To add code-signing to your app, you first need to generate a pair of cryptographic keys that will be used for both signing the bundles (private key) and verifying their integrity in runtime.
In terminal, navigate to your project directory and enter the following commands:
After that, you need to add CodeSigningPlugin to your configuration. Make sure the privateKeyPath points to the location of your code-signing.pem.
To be able to verify the bundles in runtime, we need to add the public key (code-signing.pem.pub) to the app assets. The public key needs to be included for every platform separately.
You need to add the public key to ios/<appName>/Info.plist under the name RepackPublicKey. Add the following to your Info.plist and then copy the contents of code-signing.pem.pub and paste them inside of the <string> tags:
You need to add the public key to android/app/src/main/res/values/strings.xml under the name RepackPublicKey. Add the following to your strings.xml and then copy the contents of code-signing.pem.pub and paste them inside of the <string> tags:
By default, the bundles are not verified since code-signing is entirely optional. You can enable bundle verification by modyifing the return value of resolver added through ScriptManager.shared.addResolver.
Go to index.js and modify your ScriptManager setup like this:
Integrity verification can be set (through verifyScriptSignature) to one of the 3 levels:
| Value | Description |
|---|---|
strict |
Always verify the integrity of the bundle |
lax |
Verify the integrity only if the signtarure is present |
off |
Never verify the integrity of the bundle |