forked from WICG/webpackage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wbn-sign: Add support for calculating the Web Bundle ID with CLI tool
This adds the support to automatically calculate the Web Bundle ID also when using the package's Node CLI tool without Webpack / Rollup plugins. There's two options how to output the ID: 1. Printing to the console 2. Creating a file where it is saved. In the case of a bash script, the file can be read and saved into an environment variable for example like this: `export DUMP_WEB_BUNDLE_ID="$(<webbundleid.txt )"`
- Loading branch information
Showing
9 changed files
with
177 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env node | ||
import { main } from '../lib/cli-dump-id.js'; | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/usr/bin/env node | ||
import { main } from '../lib/cli.js'; | ||
import { main } from '../lib/cli-sign.js'; | ||
|
||
main(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import commander from 'commander'; | ||
import { WebBundleId } from './wbn-sign.js'; | ||
import * as fs from 'fs'; | ||
import { greenConsoleLog, parseMaybeEncryptedKey } from './utils/cli-utils.js'; | ||
import { KeyObject } from 'crypto'; | ||
|
||
const program = new commander.Command() | ||
.name('wbn-dump-id') | ||
.description( | ||
'A simple CLI tool to dump the Web Bundle ID matching to the given private key.' | ||
); | ||
|
||
function readOptions() { | ||
return program | ||
.requiredOption( | ||
'-k, --privateKey <file>', | ||
'path to ed25519 private key (required)' | ||
) | ||
.option( | ||
'-s, --scheme', | ||
'Dumps the Web Bundle ID with isolated-app:// scheme. By default it only dumps the ID.', | ||
/*defaultValue=*/ false | ||
) | ||
.option( | ||
'-o, --output <"print"|<fileName>>', | ||
'Either prints the Web Bundle ID to the console or saves it into a file with the given name.', | ||
/*defaultValue=*/ 'print' | ||
) | ||
.parse(process.argv); | ||
} | ||
|
||
export async function main() { | ||
const options = readOptions(); | ||
const parsedPrivateKey: KeyObject = await parseMaybeEncryptedKey( | ||
fs.readFileSync(options.privateKey) | ||
); | ||
|
||
const webBundleId = options.scheme | ||
? new WebBundleId(parsedPrivateKey).serializeWithIsolatedWebAppOrigin() | ||
: new WebBundleId(parsedPrivateKey).serialize(); | ||
|
||
if (options.output === 'print') { | ||
greenConsoleLog(webBundleId); | ||
} else { | ||
fs.writeFileSync(options.output, webBundleId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import commander from 'commander'; | ||
import { | ||
NodeCryptoSigningStrategy, | ||
IntegrityBlockSigner, | ||
WebBundleId, | ||
} from './wbn-sign.js'; | ||
import * as fs from 'fs'; | ||
import { greenConsoleLog, parseMaybeEncryptedKey } from './utils/cli-utils.js'; | ||
import { KeyObject } from 'crypto'; | ||
|
||
const program = new commander.Command() | ||
.name('wbn-sign') | ||
.description( | ||
'A simple CLI tool to sign the given web bundle with the given private key.' | ||
); | ||
|
||
function readOptions() { | ||
return program | ||
.requiredOption( | ||
'-i, --input <file>', | ||
'input web bundle to be signed (required)' | ||
) | ||
.requiredOption( | ||
'-k, --privateKey <file>', | ||
'path to ed25519 private key (required)' | ||
) | ||
.option( | ||
'-o, --output <file>', | ||
'signed web bundle output file', | ||
/*defaultValue=*/ 'signed.swbn' | ||
) | ||
.parse(process.argv); | ||
} | ||
|
||
export async function main() { | ||
const options = readOptions(); | ||
const webBundle = fs.readFileSync(options.input); | ||
const parsedPrivateKey: KeyObject = await parseMaybeEncryptedKey( | ||
fs.readFileSync(options.privateKey) | ||
); | ||
const signer = new IntegrityBlockSigner( | ||
webBundle, | ||
new NodeCryptoSigningStrategy(parsedPrivateKey) | ||
); | ||
const { signedWebBundle } = await signer.sign(); | ||
greenConsoleLog(`${new WebBundleId(parsedPrivateKey)}`); | ||
fs.writeFileSync(options.output, signedWebBundle); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters