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

@silencelaboratories/walletprovider-sdk

v0.1.0

Published

Frontend SDK for Wallet Providers

Downloads

4,269

Readme

walletprovider-sdk

The frontend library for Silent Network.

Demo

Under the demo directory we provide the sample webpage that shows example usage of the library. In order to run it execute the following:

  1. Build the library
bun install
bun run build
  1. Run the demo
cd demo
npm install
npm run dev

The demo fetches configuration from the .env file. We provided example .env here.

The demo communicates with backend service. Run it before using the demo page.

Using the library

The library is published on npmjs registry.

Install it in your project as usual:

npm i @silencelaboratories/walletprovider-sdk

The backend

The library communicates with backend service. The example implementation of such service is accessible here. Please refer to backend documentation in order to run the service.

Frontend uses WalletProviderServiceClient object in order to connect to the backend and send requests.

Documentation

For description of classes, interfaces, types, please refer to documentation.

Authentication

Users authenticate using an EOA wallet during key generation and register an ephemeral signing key pair and associates it with their identity.

Frontend can later use the ephemeral signing key pair to authorize signing requests for duration of the session without the need for repeated user interaction, providing a seamless and secure authentication mechanism.

We use EOAAuth to authenticate the user during keygen. The EOAAuth object is created with the user's wallet address, ephemeral public key, and lifetime of the key in seconds.

We then use EphAuth to authenticate the user during signing. The EphAuth object is created with the user's wallet address and ephemeral keypair.

Keygen

The full working example is in the demo. The core object to use is the NetworkSigner.

It allows to generate keys and do signatures. In order to create, you need two other components. The WalletProviderServiceClient that connects to the Backend part of the SDK, and the authentication module. Currently we provide EOA authentication via EOAAuth.

Let's create the NetworkSigner

// Generate ephemeral secret key esk
const sk = ed.utils.randomPrivateKey();
ephSK = sk;
// Derive public part epk from esk
ephPK = await ed.getPublicKeyAsync(sk);

// Create a client that connects to the backend service
const wpClient = await createWalletProviderService(clusterConfig);

// Create EOA authenticator, signature will include epk
const eoaAuth = new EOAAuth(
  accountsFromBrowserWallet[0],
  new BrowserWallet(),
  ephPK,
  // Lifetime of one hour
  60 * 60,
);

// Create a new signer instance
const sdk = new NetworkSigner(wpClient, threshold, partiesNumber, eoaAuth);

Now you can generate a key, using the authenticateAndCreateKey method. The method accepts optional permissions. No permissions means allow all operations.

const permissions = {
  permissions: [
    {
      type: 'erc20',
      method: 'approve',
      to: '0x1234567890123456789012345678901234567890',
      args: {
        spender: '0x1234567890123456789012345678901234567890',
        value: 10000,
        eq: '<',
      },
    },
  ],
};

// Generate a new key
let resp: KeygenResponse = await sdk.authenticateAndCreateKey(JSON.stringify(permissions));

Calling this method will cause to the Browser Wallet window to pop up, requesting the User to sign the request. After execution KeygenResponse is returned.

The KeygenResponse contains keyId and publicKey. The publicKey is the public part of the key generated by Silent Network. Use the keyId in subsequent calls to sign.

The esk key can be later used by the frontend in subsequent signgen requests for authenticating.

Signing

The full signing example is here.

Let's create NetworkSigner for signing. Note the EphAuth is used to avoid user interaction when generating the signatures.

const authModule = new EphAuth(accountsFromBrowserWallet[0], ephSK!);
// Create a new signer instance
const sdk = new NetworkSigner(wpClient, threshold, partiesNumber, authModule);

Use the NetworkSigner.authenticateAndSign method in order to generate a signature.

let signMessage = JSON.stringify({
  userOperation: {
    sender: '0x8d4cb2540d993fe34c646299f1ab4af3012ff34c',
    nonce: '0x7',
    initCode: '',
    callData: '0000189a...',
    callGasLimit: '123130',
    verificationGasLimit: '153427',
    preVerificationGas: '66768',
    maxFeePerGas: '',
    maxPriorityFeePerGas: '',
    paymasterAndData: '',
  },
  entryPointVersion: 'v0.6.0',
  entryPointAddress: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789',
  chainId: 80002,
});

let resp = await sdk.authenticateAndSign(selectedKeyId, signMessage);

The SignResponse contains the signature sign and the recovery ID recid.

Developing the library

Audience of this section are library developers.

Bun runtime is required

Install bun from https://bun.sh

Install dependencies

bun install

Build

bun run build

The output will be in the dist folder.

Test

Create *.test.ts files and run tests with:

bun run test
# or watch test
bun run test:watch

End to end tests

Please refer to README.md for instructions how to execute them.

Format the code

bun run format

Generate the documentation

bun run docs