MCPcopy Create free account
hub / github.com/WICG/webpackage / readVerifyAndSignWebBundle

Function readVerifyAndSignWebBundle

js/sign/src/cli-sign.ts:395–431  ·  view source on GitHub ↗
(
  wbnFilePath: string,
  keyFilesPaths: string[],
  outputFilePath: string,
  maybeWebBundleId?: string
)

Source from the content-addressed store, hash-verified

393}
394
395async 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
433export async function main() {
434 await parseArguments();

Callers 1

parseArgumentsFunction · 0.85

Calls 7

isSignedWebBundleFunction · 0.90
isPureWebBundleFunction · 0.90
greenConsoleLogFunction · 0.90
fromWebBundleMethod · 0.80
getWebBundleIdMethod · 0.45

Tested by

no test coverage detected