# stellar-auth-client

> Client side library for Stellar SEP 0010 implementation

Latest version **2.0.1** (published 2021-01-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install stellar-auth-client
pnpm add stellar-auth-client
yarn add stellar-auth-client
bun add stellar-auth-client
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2021-01-25 |
| First published | 2019-07-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=10.16.3 |
| Dependencies | 10 |
| Unpacked size | 16.3 KB |
| Known vulnerabilities | 0 (+24 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Juan P Lopez |
| Maintainers | dolcalmi |
| Keywords | stellar, sep0010, auth |

## Links

- npm: https://www.npmjs.com/package/stellar-auth-client
- Repository: https://github.com/dolcalmi/stellar-auth-client
- Issues: https://github.com/dolcalmi/stellar-auth-client/issues
- npm.io page: https://npm.io/package/stellar-auth-client

## Dependencies (10)

- [axios](https://npm.io/package/axios.md) ^0.21.1
- [urijs](https://npm.io/package/urijs.md) ^1.19.5
- [core-js](https://npm.io/package/core-js.md) ^3.8.3
- [detect-node](https://npm.io/package/detect-node.md) ^2.0.4
- [stellar-sdk](https://npm.io/package/stellar-sdk.md) ^7.0.0
- [lodash.merge](https://npm.io/package/lodash.merge.md) ^4.6.1
- [regenerator-runtime](https://npm.io/package/regenerator-runtime.md) ^0.13.7
- [@ledgerhq/hw-app-str](https://npm.io/package/@ledgerhq/hw-app-str.md) ^5.39.1
- [@ledgerhq/hw-transport-u2f](https://npm.io/package/@ledgerhq/hw-transport-u2f.md) ^5.36.0-deprecated
- [@ledgerhq/hw-transport-node-hid](https://npm.io/package/@ledgerhq/hw-transport-node-hid.md) ^5.39.1

## Alternatives

- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads
- [escher-request](https://npm.io/package/escher-request.md) — 545 weekly downloads

## Recent versions

- 2.0.1 (latest) — 2021-01-25
- 2.0.0 — 2021-01-20
- 1.0.1 — 2019-12-30
- 1.0.0 — 2019-09-04
- 0.1.6 — 2019-09-04
- 0.1.5 — 2019-08-02
- 0.1.4 — 2019-08-02
- 0.1.3 — 2019-08-01
- 0.1.2 — 2019-07-28
- 0.1.1 — 2019-07-28
- 0.1.0 — 2019-07-28

## README

# Stellar Auth client library
[![Version](https://img.shields.io/npm/v/stellar-auth-client.svg)](https://www.npmjs.org/package/stellar-auth-client)
[![Build Status](https://api.travis-ci.com/dolcalmi/stellar-auth-client.svg?branch=master)](https://travis-ci.com/dolcalmi/stellar-auth-client)
[![Coverage Status](https://coveralls.io/repos/github/dolcalmi/stellar-auth-client/badge.svg?branch=master)](https://coveralls.io/github/dolcalmi/stellar-auth-client?branch=master)
[![David](https://img.shields.io/david/dolcalmi/stellar-auth-client.svg)](https://david-dm.org/dolcalmi/stellar-auth-client)
[![David](https://img.shields.io/david/dev/dolcalmi/stellar-auth-client.svg)](https://david-dm.org/dolcalmi/stellar-auth-client?type=dev)
[![Try on RunKit](https://badge.runkitcdn.com/stellar-auth-client.svg)](https://runkit.com/npm/stellar-auth-client)

Client side library for [Stellar SEP 0010](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0010.md) implementation.

## Quick start

Using npm to include stellar-auth-client in your own project:

```shell
npm install --save stellar-auth-client
```

For browsers,
[use Bower to install stellar-auth-client](#to-self-host-for-use-in-the-browser). It
exports a variable `StellarAuthClient`. The example below assumes you have
`stellar-auth-client.js` relative to your html file.

```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/stellar-sdk/{version}/stellar-sdk.js"></script>
<script src="stellar-auth-client.js"></script>
<script>
  console.log(StellarAuthClient);
</script>
```

## Install

### To use as a module in a Node.js project

1. Install it using npm:

```shell
npm install --save stellar-auth-client
```

2. require/import it in your JavaScript:

```js
var StellarAuthClient = require('stellar-auth-client');
```

### To self host for use in the browser

1. Install it using [bower](http://bower.io):

```shell
bower install stellar-auth-client
```

2. Include it in the browser:

```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/stellar-sdk/{version}/stellar-sdk.js"></script>
<script src="./bower_components/stellar-auth-client/stellar-auth-client.js"></script>
<script>
  console.log(StellarAuthClient);
</script>
```

## Usage

### Initialization

``` js
const StellarAuthClient = require('stellar-auth-client');

// optional param
const options = {
  homeDomain: 'k.tempocrypto.com',
  bip32Path: `44'/148'/0'`,
  authAccount: null,
  authEndpoint: null,
  allowHttp: false
}

const auth = new StellarAuthClient('k.tempocrypto.com', options);
```

- **domain**\
Domain where is the toml file.\
Required: false
- **options**\
Object with optional params .\
Required: false
  - **homeDomain**\
  Default home domain. If value is not set then domain is used.\
  Default value: `domain`\
  Required: false
  - **bip32Path**\
  bip 32 path when you use loginWithLedger.\
  Default value: `'44'/148'/0'`\
  Required: false
  - **authAccount**\
  server public key (toml SIGNING_KEY).\
  Default value: `null`\
  Required: false
  - **authEndpoint**\
  Auth server endpoint (toml WEB_AUTH_ENDPOINT).\
  Default value: `null`\
  Required: false
  - **allowHttp**\
  HTTPS required by default, use this with false for testing.\
  Default value: `false`\
  Required: false


### loginWithSecret

``` js
const clientKeyPair = StellarSdk.Keypair.random();
auth
  .loginWithSecret(clientKeyPair.secret())
  .then(jwtToken => saveJwtToken(jwtToken))
```
With custom auth account and endpoint
``` js
const auth = new StellarAuthClient('yourdomain.com', {
  allowHttp: true,
  authAccount: 'GAJXKAG...your server public key...HP6PCHA',
  authEndpoint: 'http://localhost:3000/auth',
  networkPassphrase: 'Test SDF Network ; September 2015'
});

const clientKeyPair = StellarSdk.Keypair.random();
auth
  .loginWithSecret(clientKeyPair.secret())
  .then(jwtToken => saveJwtToken(jwtToken))
```

### loginWithLedger

``` js
auth
  .loginWithLedger(/*{ bip32Path: `44'/148'/13'` }*/)
  .then(jwtToken => saveJwtToken(jwtToken))
```


## Development

Run all tests:

```bash
$ npm install
$ npm test
```

To run a specific set of tests:

```shell
gulp test:node
gulp test:browser
```

Run a single test suite:

```bash
$ npm run mocha -- test/lib/index.spec.js
```

Run a single test (case sensitive):

```bash
$ npm run mocha -- test/lib/index.spec.js --grep 'allowHttp'
```
<sub><sup>Library based on [Stellar SEP-0010 implementation](https://github.com/gzigzigzeo/stellar-sep-0010-implementation)</sup></sub>

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