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

v1.3.0

Published

Frontend SDK for Wallet Providers

Downloads

3,516

Readme

walletprovider-sdk

The client library for Silent Network Wallet Provider Service.

Installing

npm i @silencelaboratories/walletprovider-sdk

Quick start

Check the demo for a quick start guide.

Documentation

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

Features

  • Authentication
  • Keygen
  • Signing

Overview

The library provides API to authenticate, generate keys, and sign messages against the Silent Network. Before sending request for a distributed key or signature, users need to be authenticated to the Silent Network.

Once authenticated, users register an ephemeral signing key pair and associate it with their identity. The ephemeral signing keys can later be used to authorize signing requests for duration of the session without the need for repeated user interaction, providing a seamless and secure authentication mechanism.

Authentication

Users authenticate to Silent Network using 2 methods Wallet-based or Passkey.

  • Wallet-based authenticate users using their digital wallet, it runs at the same time users start doing keygen.

  • Passkey has 2 steps: register and login. The user registers a passkey with the network, then logs in with the passkey while starting the keygen process.

The ephemeral public claim will be associated with both EOAAuth and PasskeyAuth objects.

  • Users will use EphAuth to do non-interactive authenticate during signing.
  • The library supports 2 signing algorithms for ephemeral signing keys: secp256k1, ed25519

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 your keys, you need two other components. The WalletProviderServiceClient that connects to the Backend part of the SDK, and the authenticator module.

Authenticate with EOA wallet

We provide EOA authentication via EOAAuth module. Let's create the NetworkSigner with associated EOAAuth object.

const algSign = 'secp256k1'; // Signing algorithms of ephemeral key
// Generate ephemeral secret key esk
const sk = generateEphPrivateKey(algSign);
// Derive public part epk from esk
const ephPK = getEphPublicKey(sk, algSign);
// Arbitrary ID to identify the ephemeral key
const ephId = uuidv4();
// Create ephemeral key claim instance based on the ephemeral key
const ephClaim = new EphKeyClaim(
  ephId,
  ephPK,
  algSign,
  // Lifetime of one hour
  60 * 60,
);

// Create EOA authenticator, signature will include epk
const eoaAuth = new EOAAuth(
  accountsFromBrowserWallet[0],
  new BrowserWallet(),
  ephClaim
);

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

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

Now you can generate a key, using the generateKey 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.generateKey(JSON.stringify(permissions));

Calling this method will cause to the Digital Wallet window to pop up, requesting the User to sign the request.

The returned 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 ephemeral sk key can be later used in subsequent signgen requests for authenticating.

Authenticate with Passkey

First, we need to register user passkey to the network. We provide Passkey register via PasskeyRegister module.

const wpClient = await createWalletProviderService(clusterConfig);
const rpConfig: RelyingPartyConfig = {
  rpId: 'localhost',
  rpName: 'http://localhost:5173',
};
const userId = uuidv4();
const passkeyUser = {
  id: userId,
  displayName: 'Alice',
  name: '[email protected] ' + userId, // For development purposes
};

const passkeyAuth = new PasskeyRegister(rpConfig, passkeyUser);
// Create a new signer instance
const sdk = new NetworkSigner(wpClient, +threshold, +partiesNumber, passkeyAuth);

// Register a new passkey
let resp: RegisterPasskeyResponse = await sdk.registerPasskey();

We provide Passkey login authentication via PasskeyAuth module. Let's create the NetworkSigner with associated PasskeyAuth object.

const algSign = 'secp256k1'; // Signing algorithms of ephemeral key
// Generate ephemeral secret key esk
const sk = generateEphPrivateKey(algSign);
// Derive public part epk from esk
const ephPK = getEphPublicKey(sk, algSign);
// Arbitrary ID to identify the ephemeral key
const ephId = uuidv4();
// Create ephemeral key claim instance based on the ephemeral key
const ephClaim = new EphKeyClaim(
  ephId,
  ephPK,
  // Lifetime of one hour
  60 * 60,
);
// Create a client that connects to the backend service
const wpClient = await createWalletProviderService(clusterConfig);
// Here we configure the relying party for local development
const rpConfig: RelyingPartyConfig = {
  rpId: 'localhost',
  rpName: 'http://localhost:5173',
};

// Get passkey credential id from your storage
const credentialId = getPasskeyCredentialId();
// Create Passkey authenticator, signature will include epk
const passkeyAuth = new PasskeyAuth(
  rpConfig,
  // We will do passkey auth/login with the provided credentialId
  credentialId,
  ephClaim,
);

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

Now you can generate a key like in the EOA example by calling the generateKey method.

Calling this method will prompt the device to request Passkey User Verification. Once user verification is done, the KeygenResponse is returned.

The sk key can be later used in subsequent signgen requests.

Signing

The full signing example is here.

The workflow is similar to the keygen process. The core objects to use are the NetworkSigner, WalletProviderServiceClient, and the ephemeral authenticator module.

const authModule = new EphAuth(selectedEphId, ephSK, selectedEphSignAlg);
// Create a new signer instance
const sdk = new NetworkSigner(wpClient, threshold, partiesNumber, authModule);

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

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

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

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

Development

Build the library

npm i
npm run build

The output will be in the dist folder.

End to end tests

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

Generate the documentation

npm run docs

Lint the code

./local_ci.sh