# @baseline-protocol/api

> Baseline core registry, key management and RPC APIs

Latest version **0.2.0** (published 2020-12-12) · CC0 1.0 Universal license · 0 weekly downloads

## Install

```sh
npm install @baseline-protocol/api
pnpm add @baseline-protocol/api
yarn add @baseline-protocol/api
bun add @baseline-protocol/api
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2020-12-12 |
| First published | 2020-07-01 |
| Weekly downloads | 0 |
| License | CC0 1.0 Universal |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 323.7 KB |
| Known vulnerabilities | 0 (+25 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | prvd |

## Links

- npm: https://www.npmjs.com/package/@baseline-protocol/api
- npm.io page: https://npm.io/package/@baseline-protocol/api

## Dependencies (3)

- [axios](https://npm.io/package/axios.md) ^0.19.2
- [ethers](https://npm.io/package/ethers.md) ^4.0.47
- [provide-js](https://npm.io/package/provide-js.md) ^1.3.1

## Recent versions

- 0.2.0 (latest) — 2020-12-12
- 0.1.0 — 2020-08-26
- 0.0.4 — 2020-07-06
- 0.0.3 — 2020-07-06
- 0.0.2 — 2020-07-05
- 0.0.1 — 2020-07-01

## README

# @baseline-protocol/api

Baseline core API package.

## Installation

`npm install @baseline-protocol/api`

## Building

You can build the package locally with `npm run build`.

## Baseline JSON-RPC Module

An initial set of JSON-RPC methods have been defined for inclusion in the specification. These methods allow easy interaction with on-chain shield contracts (which contain merkle-tree fragments) and maintain full merkle-trees (along with metadata) in local off-chain storage.

| Method | Params | Description |
| -------- | ----- | ----------- |
| `baseline_getCommit` | address, commitIndex | Retrieve a single commit from a tree at the given shield contract address |
| `baseline_getCommits` | address, startIndex, count | Retrieve multiple commits from a tree at the given shield contract address |
| `baseline_getRoot` | address | Retrieve the root of a tree at the given shield contract address |
| `baseline_getSiblings` | address, commitIndex | Retrieve sibling paths (proof) of the given commit index |
| `baseline_getTracked` | | Retrieve a list of the shield contract addresses being tracked and persisted |
| `baseline_verifyAndPush` | sender, address, proof, publicInputs, commit | Inserts a single commit in a tree for a given shield contract address |
| `baseline_track` | address | Initialize a merkle tree database for the given shield contract address |
| `baseline_untrack` | address | Remove event listeners for a given shield contract address |
| `baseline_verify` | address, value, siblings | Verify a sibling path for a given root and commit value |

### Ethereum Clients

- [Nethermind](https://github.com/NethermindEth/nethermind) .NET client

## Interfaces

__IBaselineRPC__

This interface provides methods to deploy Shield contracts on the blockchain, and execute read/write operations on them. Writes are necessary when adding new hashes (commitments) to the on-chain merkle tree. Reads are necessary to verify consistency of off-chain records with on-chain state.

```javascript
getCommit(address: string, index: number): Promise<MerkleTreeNode>;
getCommits(address: string, startIndex: number, count: number): Promise<MerkleTreeNode[]>;
getRoot(address: string): Promise<string>;
getSiblings(address: string, commitIndex: number): Promise<MerkleTreeNode[]>;
getTracked(): Promise<string[]>;
verifyAndPush(sender: string, address: string, proof: number[], publicInputs: string[], commit: string): Promise<string>;
track(address: string): Promise<boolean>;
untrack(address: string): Promise<boolean>;
verify(address: string, root: string, commit: string, siblingPath: MerkleTreeNode[]): Promise<boolean>;
```

![IBaselineRPC](https://user-images.githubusercontent.com/35908605/93899621-7d0bc600-fcc2-11ea-9dae-46497acf204a.png)

__IRegistry__

This interface provides methods to establish an on-chain OrgRegistry, which is used to identify the parties involved in a particular workgroup.

```javascript
// workgroups
createWorkgroup(params: object): Promise<any>;
updateWorkgroup(workgroupId: string, params: object): Promise<any>;
fetchWorkgroups(params: object): Promise<any>;
fetchWorkgroupDetails(workgroupId: string): Promise<any>;
fetchWorkgroupOrganizations(workgroupId: string, params: object): Promise<any>;
createWorkgroupOrganization(workgroupId: string, params: object): Promise<any>;
updateWorkgroupOrganization(workgroupId: string, organizationId: string, params: object): Promise<any>;
fetchWorkgroupInvitations(workgroupId: string, params: object): Promise<any>;
fetchWorkgroupUsers(workgroupId: string, params: object): Promise<any>;
createWorkgroupUser(workgroupId: string, params: object): Promise<any>;
updateWorkgroupUser(workgroupId: string, userId: string, params: object): Promise<any>;
deleteWorkgroupUser(workgroupId: string, userId: string): Promise<any>;

// organizations
createOrganization(params: object): Promise<any>;
fetchOrganizations(params: object): Promise<any>;
fetchOrganizationDetails(organizationId: string): Promise<any>;
updateOrganization(organizationId: string, params: object): Promise<any>;

// organization users
fetchOrganizationInvitations(organizationId: string, params: object): Promise<any>;
fetchOrganizationUsers(organizationId: string, params: object): Promise<any>;
inviteOrganizationUser(organizationId: string, params: object): Promise<any>;
```

__IVault__

This interface provides methods to securely sign and encrypt/decrypt data. Private/public key pairs are stored in a Vault service, then requests are sent to the service to use those keys. This is more secure because it limits the attack vector compared to alternatives such as allowing signing keys to reside within a blockchain client.

```javascript
createVault(params: object): Promise<any>;
fetchVaults(params: object): Promise<any>;
fetchVaultKeys(vaultId: string, params: object): Promise<any>;
createVaultKey(vaultId: string, params: object): Promise<any>;
deleteVaultKey(vaultId: string, keyId: string): Promise<any>;
encrypt(vaultId: string, keyId: string, payload: string): Promise<any>;
decrypt(vaultId: string, keyId: string, payload: string): Promise<any>;
signMessage(vaultId: string, keyId: string, msg: string): Promise<any>;
verifySignature(vaultId: string, keyId: string, msg: string, sig: string): Promise<any>;
fetchVaultSecrets(vaultId: string, params: object): Promise<any>;
createVaultSecret(vaultId: string, params: object): Promise<any>;
deleteVaultSecret(vaultId: string, secretId: string): Promise<any>;
```

## Supported Providers & Protocols

The following providers of the Baseline API are available:

- Ethers.js - *example provider; not yet implemented*
- [Provide](https://provide.services) - enterprise-grade reference implementation (see [examples/bri-1/base-example](https://github.com/ethereum-oasis/baseline/tree/master/examples/bri-1/base-example))
- RPC - generic JSON-RPC provider

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