Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@i3m/server-wallet

Package Overview
Dependencies
Maintainers
3
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@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.

  • 2.6.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-83.33%
Maintainers
3
Weekly downloads
 
Created
Source

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

Keywords

FAQs

Package last updated on 04 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc