# @ebsifnmt/wallet-lib

> EBSI Wallet Library

Latest version **1.0.0-rc.9** (published 2022-05-18) · EUPL-1.2 license · 0 weekly downloads

## Install

```sh
npm install @ebsifnmt/wallet-lib
pnpm add @ebsifnmt/wallet-lib
yarn add @ebsifnmt/wallet-lib
bun add @ebsifnmt/wallet-lib
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0-rc.9 |
| Published | 2022-05-18 |
| First published | 2022-05-18 |
| Weekly downloads | 0 |
| License | EUPL-1.2 |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 8 |
| Unpacked size | 51.9 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | fnmt |

## Links

- npm: https://www.npmjs.com/package/@ebsifnmt/wallet-lib
- Repository: https://ec.europa.eu/cefdigital/code/scm/ebsi/wallet-lib-lib
- npm.io page: https://npm.io/package/@ebsifnmt/wallet-lib

## Dependencies (8)

- [bn.js](https://npm.io/package/bn.js.md) ^5.2.0
- [did-jwt](https://npm.io/package/did-jwt.md) ^5.12.3
- [js-sha3](https://npm.io/package/js-sha3.md) ^0.8.0
- [elliptic](https://npm.io/package/elliptic.md) ^6.5.4
- [key-encoder](https://npm.io/package/key-encoder.md) ^2.0.3
- [multiformats](https://npm.io/package/multiformats.md) ^9.5.8
- [@ethersproject/random](https://npm.io/package/@ethersproject/random.md) ^5.5.1
- [@ethersproject/providers](https://npm.io/package/@ethersproject/providers.md) ^5.5.2

## Recent versions

- 1.0.0-rc.9 (latest) — 2022-05-18
- 1.0.0-rc.7 — 2022-05-18
- 1.0.0-rc.6 — 2022-05-18

## README

![EBSI Logo](https://ec.europa.eu/cefdigital/wiki/images/logo/default-space-logo.svg)

# Wallet Library

**EXPERIMENTAL**

> The Wallet Library is a TypeScript reference library implementing some generic EBSI-compliant wallet capabilities.

## Table of Contents

1. [Install](#install)
2. [Usage](#usage)
3. [Linting](#linting)
4. [Auditing the dependencies](#auditing-the-dependencies)
5. [Tests](#tests)
6. [Generate docs](#generate-docs)
7. [License](#license)

## Install

```sh
npm install @cef-ebsi/wallet-lib
```

## Usage

```typescript
import { EbsiWallet } from "@cef-ebsi/wallet-lib";
import { JsonRpcProvider } from "@ethersproject/providers";
import { BigNumber } from "@ethersproject/bignumber";

// Create a new random EBSI DID
const did = EbsiWallet.createDid();
console.log(did);
// prints "did:ebsi:zsSgDXeYPhZ3AuKhTFneDf1"

// Instantiating a new instance of EBSI Wallet
const privateKey =
  "0a9a229c18f1777949243bbe875b754b77fb9cb3612c8b5c37876888f54f9731";
const wallet = new EbsiWallet(privateKey);

// Get wallet's public key (different formats)
const publicKey = wallet.getPublicKey();
/*
046a6457531aefa19d1840cca004f9ef1cf50d30c508d960a63fceedf336da829501b3c54c16b2d4f325c602e23f17da353ad0ccba6397f082be1e3eaab07cf3c1
*/

const publicKeyPem = wallet.getPublicKey({ format: "pem" });
/*
-----BEGIN PUBLIC KEY-----
MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEamRXUxrvoZ0YQMygBPnvHPUNMMUI2WCm
P87t8zbagpUBs8VMFrLU8yXGAuI/F9o1OtDMumOX8IK+Hj6qsHzzwQ==
-----END PUBLIC KEY-----
*/

const publicKeyJwk = wallet.getPublicKey({ format: "jwk" });
/*
{
  kty: "EC",
  crv: "secp256k1",
  x: "amRXUxrvoZ0YQMygBPnvHPUNMMUI2WCmP87t8zbagpU",
  y: "AbPFTBay1PMlxgLiPxfaNTrQzLpjl_CCvh4-qrB888E",
}
*/

// Get wallet's Ethereum address
const publicKey = wallet.getEthereumAddress();
// returns 0xA2aa80C25AebE7d3b9984ef45179b4F39737fFBa

// Prepare an Ethereum transaction
const accessToken = ""; // This is an OAuth2 access token required by Ledger API, see @cef-ebsi/oauth2-auth library
const provider = new JsonRpcProvider({
  url: "https://api.test.intebsi.xyz/ledger/v2/blockchains/besu",
  headers: {
    authorization: `Bearer ${accessToken}`,
  },
});

const { chainId } = await ethersProvider.getNetwork();

// This is the raw transaction we want to prepare
const rawTransaction = {
  from: "0x32DEF047DeFd076DB21A2D759aff2A591c972248",
  gasPrice: BigNumber.from("0x4a817c800"),
  to: "0x6fC21092DA55B392b045eD78F4732bff3C580e2c",
  value: BigNumber.from("0x186cc6acd4b0000"),
  nonce: 0,
  data: "0xf2c298be000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000067269636d6f6f0000000000000000000000000000000000000000000000000000",
  chainId,
};

const txRequest = await EbsiWallet.prepareEthereumTransaction(
  rawTransaction,
  provider
);
// txRequest now contains rawTransaction with an estimated gasLimit
```

## Linting

You can lint the files (ESLint, OpenAPI, tsc) and run Prettier with one command:

```sh
yarn lint
```

Or you can run the different linters independently:

### ESLint

```sh
yarn lint:eslint
```

or with yarn:

```sh
yarn eslint . --ext .js,.ts
```

Run eslint and precommit rules:

```sh
.git/hooks/pre-commit
```

### Prettier

```sh
yarn lint:prettier
```

or with yarn:

```sh
yarn prettier . --check
```

### tsc

```sh
yarn lint:tsc
```

or with yarn:

```sh
yarn tsc --noEmit --incremental false
```

## Auditing the dependencies

Using [audit-ci](https://github.com/IBM/audit-ci) (this is the one we run during CI):

```sh
yarn run audit
```

Or using Yarn's built-in `audit` command, to get more information:

```sh
yarn audit
```

## Tests

Note: before running the e2e tests, make sure to create a local `.env` file and fill it with the correct environment variables. You can check `.env.example` to see what is expected.

Run all the tests:

```sh
yarn test
```

Run unit tests only:

```sh
yarn test:unit

# Or in CI mode (with coverage)
yarn test:ci
```

Run all the end-to-end tests:

```sh
yarn test:e2e
```

Run functional tests in a Node.js environment:

```sh
yarn test:e2e:node
```

Run functional tests in a browser environment:

```sh
yarn test:e2e:browser
```

## Generate docs

The documentation is generated with [TypeDoc](https://typedoc.org/), based on the [TSDoc](https://tsdoc.org/) comments we leave in the code.

Run the following command to generate the docs:

```sh
yarn generate:docs
```

Serve the docs:

```sh
yarn serve:docs
```

## License

Copyright (c) 2019 European Commission
Licensed under the EUPL, Version 1.2 or - as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "Licence");
You may not use this work except in compliance with the Licence.
You may obtain a copy of the Licence at:

- <https://joinup.ec.europa.eu/page/eupl-text-11-12>

Unless required by applicable law or agreed to in writing, software distributed under the Licence is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Licence for the specific language governing permissions and limitations under the Licence.

---
_Source: https://npm.io/package/@ebsifnmt/wallet-lib · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
