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

@dfinity/service-worker

v1.8.8

Published

Service worker to check certification when loading assets from the Internet Computer.

Downloads

41

Readme

DFINITY Service Worker

Service worker which transforms browser asset request to the IC to canister calls and verifies the asset certification.

Build

| Usage | Folder | Command | Note | | ---------------------- | --------- | ------------------- | ------------------------------------------------- | | dev build for testnets | dist-dev | npm run build-dev | - sets FORCE_FETCH_ROOT_KEY=1- not minified | | prod build for mainnet | dist-prod | npm run build | - uses IC root key- minified |

Prerequisites

  • Node.js 17
  • npm 8.5

Build With FORCE_FETCH_ROOT_KEY

By setting the FORCE_FETCH_ROOT_KEY=1 environment variable prior to building, the service worker will always fetch the root key of the network before doing the validation.

THIS SHOULD ONLY BE USED ON A TEST OR LOCAL NETWORK. The IC mainnet public key is hard coded in the agent and, for security reasons, should not be fetched by the agent.

Generating HTTP Gateway bindings

JavaScript binding

Generate the binding:

didc bind ./src/http-interface/canister_http_interface.did --target js > ./src/http-interface/canister_http_interface.ts

Then move the StreamingCallbackHttpResponse variable outside of the idlFactory function, rename to streamingCallbackHttpResponseType and then export it.

export const streamingCallbackHttpResponseType = // ...

then add the import { IDL } from '@dfinity/candid'; import, move the Token variable outside of the idlFactory function, and set its value to be IDL.Unknown.

import { IDL } from '@dfinity/candid';

const Token = IDL.Unknown;

then add the type IDL.InterfaceFactory to the idlFactory export.

export const idlFactory: IDL.InterfaceFactory = // ...

and finally remove the unused init method export const init.

TypeScript binding

Generate the binding:

didc bind ./src/http-interface/canister_http_interface.did --target ts > ./src/http-interface/canister_http_interface_types.d.ts

Add the following import:

import { IDL } from '@dfinity/candid';

and then replace:

export type Token = { type: any };

with:

export type Token = { type: <T>() => IDL.Type<T> };

Testing locally

  1. Install mkcert.
    brew install mkcert
    brew install nss # optional, for Firefox support
  2. Optionally, install the mkcert root CA
    mkcert -install
  3. Generate SSL certificates:
    npm run create-ssl-certs
  4. Add the following to your /etc/hosts file.
    127.0.0.1 ic0.local
    
    # Internet Identity
    127.0.0.1 rdmx6-jaaaa-aaaaa-aaadq-cai.ic0.local
    127.0.0.1 identity.ic0.local
    
    # NNS
    127.0.0.1 qoctq-giaaa-aaaaa-aaaea-cai.ic0.local
    127.0.0.1 nns.ic0.local
    
    # Distrikt
    127.0.0.1 az5sd-cqaaa-aaaae-aaarq-cai.ic0.local
    127.0.0.1 distrikt.ic0.local
    
    # Distrikt Staging
    127.0.0.1 am2do-dyaaa-aaaae-aaasa-cai.ic0.local
    127.0.0.1 distrikt-staging.ic0.local
    
    # DSCVR
    127.0.0.1 h5aet-waaaa-aaaab-qaamq-cai.ic0.local
    127.0.0.1 dscvr.ic0.local
    
    # Nuance
    127.0.0.1 exwqn-uaaaa-aaaaf-qaeaa-cai.ic0.local
    127.0.0.1 nuance.ic0.local
    
    # Open Chat
    127.0.0.1 6hsbt-vqaaa-aaaaf-aaafq-cai.ic0.local
    127.0.0.1 oc.ic0.local
    
    # Local custom domains for service worker
    127.0.0.1 demo.ic.local
    127.0.0.1 internetcomputer.ic.local
    127.0.0.1 distrikt.ic.local
    127.0.0.1 dscvr.ic.local
    127.0.0.1 nns.ic.local
  5. Set the hostnameCanisterIdMap value in the src/sw/domains/static.ts file (make sure to revert this before committing):
    export const hostnameCanisterIdMap: Map<string, Principal> = new Map(
          Object.entries({
                'identity.ic0.local': Principal.from('rdmx6-jaaaa-aaaaa-aaadq-cai'),
                'nns.ic0.local': Principal.from('qoctq-giaaa-aaaaa-aaaea-cai'),
                'dscvr.ic0.local': Principal.from('h5aet-waaaa-aaaab-qaamq-cai'),
                'distrikt.ic0.local': Principal.from('az5sd-cqaaa-aaaae-aaarq-cai'),
                'distrikt-staging.ic0.local': Principal.from('am2do-dyaaa-aaaae-aaasa-cai'),
                'nuance.ic0.local': Principal.from('exwqn-uaaaa-aaaaf-qaeaa-cai'),
                'oc.ic0.local': Principal.from('6hsbt-vqaaa-aaaaf-aaafq-cai'),
          })
    );
  6. Build and watch the service worker:
    npm run build-dev -- --watch
  7. In a separate shell, build and run the docker image:
    docker compose up
  8. If you installed the root CA, that's all there is to do. If you chose not to install the root CA, then you will need to launch your browser with certain flags:
    /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --user-data-dir=/tmp/no-ssl --ignore-certificate-errors

e2e Tests

Start e2e testing env:

./e2e/start-e2e-env.sh

Run e2e tests:

./e2e/run-e2e-tests.sh

Stop e2e testing env:

./e2e/stop-e2e-env.sh

Release

  1. Make an MR to bump the service worker version
    1. Update version in package.json
    2. Run npm i --package-lock-only
    3. Test the built artifact using testnet boundary node VMs
      • Currently needs to be done before making the MR as the boundary nodes are not built if only service worker files are updated
  2. Merge MR to master
  3. Tag the commit on master with service-worker_v${version}
  4. Verify that the desired version has been pushed to NPM: https://www.npmjs.com/package/@dfinity/service-worker
  5. Create an MR for the boundary nodes team that updates the sw_version and sw_sha256 in ic-os/boundary-guestos/rootfs/Dockerfile