npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@chromeos/android-package-signer

v0.1.3

Published

Implementation of android package signing with zipalign that runs in a browser

Downloads

18

Readme

android-package-sign-js

What is this?

android-package-sign-js allows developers to generate signing keys and sign their Android packages (APK and AAB) in a browser.

Use android-package-signer in a project

npm i @chromeos/android-package-signer

To build the package

npm ci
npm run build

API

Package Signer class

Everything is encapsulated in the PackageSigner class. To generate a package signer:

const packageSigner = new PackageSigner(password: string, alias: string = 'android');

The password is a user generated minimum 6 character password.

Key Generation

To generate a key, take your package signer and pass it a distinguished name JSON object

DName

export interface DName {
  commonName: string;
  organizationName: string;
  organizationUnit: string;
  countryCode: string;
}

Generate Key

async generateKey(dname: DName): Promise<string>;
  • The object that is passed to generateKey is a JSON object referencing a DName used to identify the certificate owner.
  • The password is a string and should be a minimum of six characters long. This will protect your keystore, so the longer the password, the better.
  • The response from the generateKey function is a base64-encoded der formatted PKCS12 keystore.

Package Signing

async signPackage(
    zipBlob: File,
    base64DerKey: string | undefined = undefined,
    creator: string = `Web Package Signer (${VERSION})`,
  ): Promise<string>;
  • signPackage signs a zip file that is read into the system and returns a base64 encoded zip file which the user can write to disk.
  • The base64DerKey can either be used from the previous step or can be read from disk.
  • The creator field is optional since by default it uses this package as the creator string.

Examples

Key generation

Generate a signing key for your Android app:

import { PackageSigner } from '@chromeos/android-package-signer';
async function keyGen(): Promise<string> {
  const packageSigner = new PackageSigner(password, alias);
  const base64Der = await packageSigner.generateKey({
      commonName: 'Alexander Nohe',
      organizationName: 'Google, Inc',
      organizationUnit: 'DevRel',
      countryCode: 'US',
    });

  // To download the keys.
  const downloadElement: HTMLAnchorElement = document.querySelector('#key-gen-results');
  downloadElement.href = base64Der;
  downloadElement.download = 'generatedKey.p12';
  downloadElement.innerText = 'Download Generated Key';
}
  • To save this keystore to a file, download the base64Der string contents to a file. In the above example we use an anchor element with a href attribute containing the base64 encoded keystore.

Bundle Signing

To sign Android App Bundles and APKs with v1 signing can be called like this:

import { PackageSigner } from '@chromeos/android-package-signer';

function loadStoredKeystore(): string {
  // returns a base64 encoded keystore that was previously loaded
}

async function signBundle(): Promise<string> {
  const packageSigner = new PackageSigner(password, alias);
  let fileHandle;
  [fileHandle] = await window.showOpenFilePicker();
  const zipBlob = await fileHandle.getFile();
  const creator = '0.1.0 (Android App Signer JS)';
  const p12b64Der = loadStoredKeystore();
  await packageSigner.signPackage(zipBlob, p12b64Der, creator);
}
  • The password is a string and should be a minimum of six characters. This should be the password used to load the already generated keystore.
  • The alias references the alias supplied in keystore generation. This identifies the key used.
  • Creator is the application creating the signed files (this is an optional parameter). By default we use 0.1.0 (Android App Signer JS) but this string could be your applications name.
  • p12b64Der is a base64 encoded keystore loaded from disk. This value can also be left as unspecified to use the keystore generated previously in Key Generation step.

Sample app

The sample can be found in the sample/ directory. To use this sample, run the following commands from the root folder:

npm ci
npm build
cd sample/
npm ci
npm build
npm serve

Then visit localhost:3000/sample.html in your browser to interact with the sample. If generating keys, the key will automatically be reused for package signing.

Disclaimer

This is not an officially supported Google product.