( wbnFilePath: string, keyFilesPaths: string[], outputFilePath: string, maybeWebBundleId?: string )
| 393 | } |
| 394 | |
| 395 | async function readVerifyAndSignWebBundle( |
| 396 | wbnFilePath: string, |
| 397 | keyFilesPaths: string[], |
| 398 | outputFilePath: string, |
| 399 | maybeWebBundleId?: string |
| 400 | ) { |
| 401 | const webBundle = await fs.promises.readFile(wbnFilePath); |
| 402 | if (isSignedWebBundle(webBundle)) { |
| 403 | throw new Error( |
| 404 | 'Web bundle already signed. Use `add-signature` command instead.' |
| 405 | ); |
| 406 | } |
| 407 | if (!isPureWebBundle(webBundle)) { |
| 408 | throw new Error('Not a web bundle.'); |
| 409 | } |
| 410 | |
| 411 | const privateKeys = new Array<KeyObject>(); |
| 412 | for (const privateKey of keyFilesPaths) { |
| 413 | privateKeys.push(await parseMaybeEncryptedKeyFromFile(privateKey)); |
| 414 | } |
| 415 | |
| 416 | const signingStrategies = privateKeys.map( |
| 417 | (privateKey) => new NodeCryptoSigningStrategy(privateKey) |
| 418 | ); |
| 419 | |
| 420 | const signedWebBundle = await SignedWebBundle.fromWebBundle( |
| 421 | Uint8Array.from(webBundle), |
| 422 | signingStrategies, |
| 423 | maybeWebBundleId ? { webBundleId: maybeWebBundleId } : undefined |
| 424 | ); |
| 425 | |
| 426 | greenConsoleLog(`${signedWebBundle.getWebBundleId()}`); |
| 427 | await fs.promises.writeFile( |
| 428 | outputFilePath, |
| 429 | signedWebBundle.getSignedWebBundleBytes() |
| 430 | ); |
| 431 | } |
| 432 | |
| 433 | export async function main() { |
| 434 | await parseArguments(); |
no test coverage detected