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

@i3m/server-wallet

v2.6.1

Published

Get a ready-to-go Wallet requiring no user interaction and using a simple file to store wallet data. It should be used only when no human interaction is possible.

Downloads

90

Readme

License: EUPL_1.2 Contributor Covenant JavaScript Style Guide

@i3m/server-wallet

Get a ready-to-go Wallet requiring no user interaction and using a simple file to store wallet data. It should be used only when no human interaction is possible.

Usage

@i3m/server-wallet can be imported to your project with npm:

npm install @i3m/server-wallet

Then either require (Node.js CJS):

const serverWallet = require('@i3m/server-wallet')

or import (JavaScript ES module):

import * as serverWallet from '@i3m/server-wallet'

The appropriate version (either cjs or esm) should be automatically chosen when importing. However, if your bundler does not import the appropriate module version, you can force it to use a specific one by just importing one of the followings:

  • @i3m/server-wallet/dist/cjs/index.node: for Node.js CJS module
  • @i3m/server-wallet/dist/esm/index.node: for Node.js ESM module

If you are coding TypeScript, types will not be automatically detected when using the specific versions. You can easily get the types in by creating adding to a types declaration file (.d.ts) the following line:

declare module '@i3m/server-wallet/dist/esm/index.browser' // use the specific file you were importing

The server wallet uses a file as storage. Optional filepath is the path to the Wallet's storage file. If you are using a container it should be a path to a file that persists (like one in a volume)

The wallet's storage-file can be encrypted for added security by passing an optional password.

Example of instantiation of a server wallet in typescript:

const wallet = await serverWalletBuilder({ password: '1735b07cb074bc1057vc130377$(==)(5v0bx23YGSA', filepath: '/path/where/the/wallet/will/store/things' })

For connecting to the blockchain, the wallet server requires an RPC endpoint. It comes with one configured by default, but just in case it is malfunctioning or you just need to use another one, you can create your wallet as:

const wallet = await serverWalletBuilder({
  password: '1735b07cb074bc1057vc130377$(==)(5v0bx23YGSA',
  filepath: '/path/where/the/wallet/will/store/things',
  provider: 'did:ethr:i3m', // should match the key in `providerData`
  providerData: {
    'did:ethr:i3m': {
      network: 'i3m',
      rpcUrl: 'http://95.211.3.249:8545' // The URL of your RPC endpoint
    }
  }
})

Create an identity (DID)

const resp = await wallet.identityCreate({
  alias: 'identity1'
})
console.log(`DID for identity1 created: `, resp.did)

List identities

const identities = await wallet.identityList({})
console.log('Identities: ', identities)

Generate a signet JWT

You can generate a signature as a JWT for a generic JSON object as, for instance:

const objectToSign = {
  field1: 'yellow',
  field2: 'brown'
}
jwt = (await wallet.identitySign({ did: 'one of the dids in the wallet' }, { type: 'JWT', data: { payload: objectToSign } })).signature

Verify a signed JWT

You can also use your wallet to verify a JWT signed by other wallets as:

const verification = await wallet.didJwtVerify({ jwt })
if (verification.verification === 'success') {
  // properly verified
} else {
  // failed with error msg in verification.error
}

The verification can also check for specific payload claims. An expected value of '' can be used to just check that the claim is in the payload.

const verification = await wallet.didJwtVerify({
  jwt,
  expectedPayloadClaims: {
    field1: 'yellow'  // check that "field1"="yellow" is in the JWT payload
    field2: '' // check that "field2" is defined in the JWT payload
  }
})
if (verification.verification === 'success') {
  // properly verified
} else {
  // failed with error msg in verification.error
}

API reference documentation

Check the API