# digiasset-metadata-server

> REST API server for fetching and sharing DigiAsset transactions metadata

Latest version **0.3.1** (published 2020-02-05) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install digiasset-metadata-server
pnpm add digiasset-metadata-server
yarn add digiasset-metadata-server
bun add digiasset-metadata-server
```

Provides the command `digiasset-metadata-server`.

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.1 |
| Published | 2020-02-05 |
| First published | 2020-02-05 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 10 |
| Unpacked size | 28.1 KB |
| Known vulnerabilities | 0 (+2 in 2 direct dependencies) |
| Install scripts | no |
| Author | oleiba |
| Maintainers | digibyte |
| Keywords | torrent, digiassets, bitcoin, digibyte, blockchain, cryptocurrency |

## Links

- npm: https://www.npmjs.com/package/digiasset-metadata-server
- Repository: https://github.com/DigiByte-Core/DigiAsset-Metadata-Server
- Homepage: https://github.com/DigiByte-Core/DigiAsset-Metadata-Server#readme
- Issues: https://github.com/DigiByte-Core/DigiAsset-Metadata-Server/issues
- npm.io page: https://npm.io/package/digiasset-metadata-server

## Dependencies (10)

- [mime](https://npm.io/package/mime.md) ^1.3.4
- [async](https://npm.io/package/async.md) ^2.1.4
- [minio](https://npm.io/package/minio.md) ^7.0.12
- [moment](https://npm.io/package/moment.md) ^2.9.0
- [aws-sdk](https://npm.io/package/aws-sdk.md) ^2.1.16
- [jsonfile](https://npm.io/package/jsonfile.md) ^2.0.0
- [jwt-simple](https://npm.io/package/jwt-simple.md) ^0.3.1
- [casimircore](https://npm.io/package/casimircore.md) ^0.11.3
- [graceful-fs](https://npm.io/package/graceful-fs.md) ^4.1.2
- [digiasset-metadata-handler](https://npm.io/package/digiasset-metadata-handler.md) ^0.8.0

## Alternatives

- [@gemini-wallet/core](https://npm.io/package/@gemini-wallet/core.md) — 515.6K weekly downloads
- [utility](https://npm.io/package/utility.md) — 416.6K weekly downloads
- [@primno/dpapi](https://npm.io/package/@primno/dpapi.md) — 7.2K weekly downloads
- [pi-readseek](https://npm.io/package/pi-readseek.md) — 3.7K weekly downloads
- [@emilia-protocol/verify](https://npm.io/package/@emilia-protocol/verify.md) — 1.1K weekly downloads

## Recent versions

- 0.3.1 (latest) — 2020-02-05
- 0.3.0 — 2020-02-05

## README

# DigiAssets Metadata Server

REST API server for fetching and sharing DigiAssets transactions metadata. To learn how this repo fits into the DigiAssets stack please read the [API docs & wiki](https://github.com/DigiByte-Core/DigiAssets-Protocol-Specifications/wiki/API-Docs). 

## Getting Started

### Installation
```
$ npm i -g digiasset-metadata-server
```

### Run

Currently, the server uses [AWS S3](http://docs.aws.amazon.com/AmazonS3/latest/dev/Welcome.html) storage service as a caching layer.
So, in order to use the server one needs to set the environment variables:

```
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
AWS_S3_BUCKET
```

Then, you can run the DigiAssets metadata server with the following options:

```sh
$ digiasset-metadata-server [options]

  Options:

    -h, --help                                         output usage information
    -V, --version                                      output the version number
    -p, --port <port>                                  Port to listen on
```

Or just run it with the defaults using:

```sh
$ digiasset-metadata-server
```

## API

### `GET /getMetadata`

* Query Parameters:
  * `torrentHash` hex string of length 40, representing the SHA1 result of the origin metadata torrent file
  * `sha2` hex string of length 64, the SHA256 result of `JSON.stringify()` of the origin metadata

* Success Response:
    
   **Code:** 200 OK<br>
   **Content:** The origin metadata JSON

* Error Response:

   **Code:** 400 Bad Request<br>
   **Content:** `"Can't get metadata"`<br>
   In case no file which correponds to given `torrentHash` and `sha2` is found.

### `POST /addMetadata`

* Body Parameters:
  * `metadata` JSON
  * `token` JWT encoded by secret given in environment variable `JWTTOKENSECRET`. Decode is of the format `{iss: 'admin', exp: 'expiration'}`.</br>
  If `JWTTOKENSECRET` environment variable (or corresponding properties file field) is not given, this parameter is ignored.

* Success Response:

  **Code:** 200 OK<br>
  **Content:** Object which consists of the following:
    * `torrentHash` hex string of length 40, representing the SHA1 result of the origin metadata torrent file
    * `sha2` hex string of length 64, the SHA256 result of `JSON.stringify()` of the origin metadata

* Error Response:

   **Code:** 401 Unauthorized<br>
   In case given `token` is not as expected.

### `GET /shareMetadata`

*  Query parameters
   * `torrentHash` hex string of length 40, representing the SHA1 result of the origin metadata torrent file
   * `token` JWT encoded by secret given in environment variable `JWTTOKENSECRET`. Decode is of the format `{iss: 'admin', exp: 'expiration'}`.</br>
   If `JWTTOKENSECRET` environment variable (or corresponding properties file field) is not given, this parameter is ignored.

* Success Response:

  **Code:** 200 OK<br>
  **Content:** The metadata file which has torrent which corresponds to `torrentHash`, is seeded to BitTorrent network.

* Error Response:

   **Code:** 401 Unauthorized<br>
   In case given `token` is not as expected.

   **Code:** 400 Bad Request<br>
   **Content:** `"Can't share metadata"`<br>
   In case no file which corresponds to `torrentHash` is found.

**Note:** this call should be preceded by a call to `POST /addMetadata`

## Configuration

Default configuration per environment (`NODE_ENV` value) can be found in the [`config` directory](./config). 
You can use custom properties by adding `properties.conf` to that folder.

## Development

1. Fork this repo
2. npm install
3. use the Standard coding style when hacking the code - https://github.com/feross/standard
4. Send us a pull request

## Hosted Server

DigiAssets maintains a hosted version of this server at:<br>
`https://DigiAssets.net`

## License

[Apache-2.0](http://www.apache.org/licenses/LICENSE-2.0)

---
_Source: https://npm.io/package/digiasset-metadata-server · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
