repack icon indicating copy to clipboard operation
repack copied to clipboard

A clear working example of how code signing works with repack

Open Nazehs opened this issue 5 months ago • 12 comments

Ask your Question

I am using repack and I am not absolutely sure how repack works with code signing. When i add the below configurations to Webpack config my bundling seems to fail and I need a clear understanding of which file/folder i need to make a change to get the mini app to work with code signing

I have generated a private and public key using the below shell command

ssh-keygen -t rsa -b 4096 -m PEM -f code-signing.key
# Don't add passphrase
openssl rsa -in jwtRS256.key -pubout -outform PEM -out code-signing.key.pub
cat code-signing.key
cat code-signing.key.pub

wepack config

  new Repack.plugins.CodeSigningPlugin({
                privateKeyPath: './code-signing.key',
                outputFile: 'code_signing_mapping.json',
                outputPath: path.join(dirname, 'build/outputs', platform, 'remotes'),
            })

index.js

/**
 * @format
 */

import { AppRegistry } from 'react-native';
import App from './src/App';
import { name as appName } from './app.json';
import { ScriptManager, Script, Federated } from '@callstack/repack/client';

const resolveURL = Federated.createURLResolver({
    containers: {
        ECG: 'http://localhost:9000/[name][ext]',
    },
});
ScriptManager.shared.addResolver(async (scriptId, caller) => {
    // obtain your code-signing-mapping.json from filesystem?
    // how do i read the file locally based on the platform? for the tokens
    const resolveToken = Federated.createTokenResolver(tokens);
    let url;
    let token;
    if (caller === 'main') {
        url = Script.getDevServerURL(scriptId);
    } else {
        url = resolveURL(scriptId, caller);
        token = resolveToken(scriptId, caller);
    }
    if (!url) {
        return undefined;
    }
    return {
        url,
        token,
        cache: false,
        // verifyScriptSignature: true,
        verifyScriptSignature: __DEV__ ? 'off' : 'strict',
        query: {
            platform: Platform.OS,
        },
    };
});

AppRegistry.registerComponent(appName, () => App);

Nazehs avatar Mar 08 '24 10:03 Nazehs