Skip to content

Commit

Permalink
sdk/node: expose Connection constructor, version 1.0.2
Browse files Browse the repository at this point in the history
Closes #437
  • Loading branch information
dominic authored and iampogo committed Jan 26, 2017
1 parent be47761 commit 9af97b2
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/core/get-started/sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ The Chain Node.js SDK is available [via npm](https://www.npmjs.com/package/chain
For most applications, you can simply add Chain to your `package.json` with the following command:

```
npm install --save [email protected].1
npm install --save [email protected].2
```
5 changes: 5 additions & 0 deletions sdk/node/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Chain Node.js SDK

## 1.0.2 (January 25, 2017)

* Use base URL and client token provided on initialization for MockHSM connection
* Allow users to instantiate `Connection` objects with `new chain.Connection()`

## 1.0.1 (January 24, 2017)

* README and documentation updates
Expand Down
12 changes: 11 additions & 1 deletion sdk/node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ For most applications, you can simply add Chain to your `package.json` with
the following command:

```
npm install --save [email protected].1
npm install --save [email protected].2
```

### In your code
Expand Down Expand Up @@ -49,6 +49,16 @@ let callback = (err, data) => {
client.transactions.query({}, callback)
```

## Using external signers

To connect to an HSM other than the built-in Mock HSM, you must create a new
`Connection` object:

```
const myHsmConnection = new chain.Connection('https://myhost.dev/mockhsm', 'tokenname:tokenvalue')
signer.addKey(myKey, myHsmConnection)
```

## Testing

To run integration tests, run an instance of Chain Core on localhost:1999.
Expand Down
2 changes: 1 addition & 1 deletion sdk/node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chain-sdk",
"version": "1.0.1",
"version": "1.0.2",
"description": "The Official Node.js SDK for Chain Core",
"homepage": "https://github.com/chain/chain/tree/main/sdk/node",
"main": "dist/index.js",
Expand Down
5 changes: 3 additions & 2 deletions sdk/node/src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class Client {
* @param {String} token - Chain Core client token for API access.
* @returns {Client}
*/
constructor(baseUrl, token) {
constructor(baseUrl, token = '') {
baseUrl = baseUrl || 'http://localhost:1999'
this.connection = new Connection(baseUrl, token)

/**
Expand Down Expand Up @@ -63,7 +64,7 @@ class Client {
*/
this.mockHsm = {
keys: mockHsmKeysAPI(this),
signerConnection: new Connection('http://localhost:1999/mockhsm')
signerConnection: new Connection(`${baseUrl}/mockhsm`, token)
}

/**
Expand Down
4 changes: 2 additions & 2 deletions sdk/node/src/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ class Connection {
* @param {String} token Chain Core client token for API access.
* @returns {Client}
*/
constructor(baseUrl, token) {
this.baseUrl = baseUrl || 'http://localhost:1999'
constructor(baseUrl, token = '') {
this.baseUrl = baseUrl
this.token = token || ''
}

Expand Down
4 changes: 3 additions & 1 deletion sdk/node/src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const Client = require('./client')
const HsmSigner = require('./hsmSigner')
const Connection = require('./connection')

module.exports = {
Client,
HsmSigner
HsmSigner,
Connection,
}

0 comments on commit 9af97b2

Please sign in to comment.