Skip to content

Commit

Permalink
sdk/node: tick version to 1.1.0
Browse files Browse the repository at this point in the history
Closes #585
  • Loading branch information
jeffomatic authored and iampogo committed Feb 24, 2017
1 parent 78942dd commit b1d697c
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 11 deletions.
145 changes: 145 additions & 0 deletions sdk/node/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,150 @@
# Chain Node.js SDK

## 1.1.0 (February 24, 2017)

This release is a minor version update, and contains **new features** and **deprecations**. It is not compatible with cored 1.0.x; please upgrade cored before updating your SDKs.

### New object: receivers

Chain Core 1.1.x introduces the concept of a **receiver**, a cross-core payment primitive that supersedes the Chain Core 1.0.x pattern of creating and paying to control programs. Control programs still exist in the Chain protocol, but are no longer used directly to facilitate cross-core payments.

A receiver wraps a control program with other pieces of payment-related metadata, such as expiration dates. Receivers provide the basis for future payment features, such as the transfer of blinding factors for encrypted outputs, as well as off-chain proof of payment via X.509 certificates or some other cryptographic authentication scheme.

Initially, receivers consist of a **control program** and an **expiration date**. Transactions that pay to a receiver after the expiration date may not be tracked by Chain Core, and application logic should regard such payments as invalid. As long as both the payer and payee do not tamper with receiver objects, the Chain Core API will ensure that transactions that pay to expired receivers will fail to validate.

Working with receivers is very similar to working with control programs, and should require only small adjustments to your application code.

#### Creating receivers

The `createControlProgram` method is **deprecated**. Instead, use `createReceiver`.

##### Deprecated (1.0.x)

```
controlProgramPromise = client.accounts.createControlProgram({
alias: 'alice'
})
```

##### New (1.1.x)

You can create receivers with an expiration time. This parameter is optional and defaults to 30 days into the future.

```
receiverPromise = client.accounts.createReceiver({
accountAlias: 'alice',
expiresAt: '2017-01-01T00:00:00Z'
})
```

#### Using receivers in transactions

The `controlWithProgram` transaction builder method is **deprecated**. Use `controlWithReceiver` instead.

##### Deprecated (1.0.x)

```
templatePromise = client.transactions.build(builder => {
builder.controlWithProgram({
controlProgram: controlProgram.controlProgram,
assetAlias: 'gold',
amount: 1
})
...
})
```

##### New (1.1.x)

```
templatePromise = client.transactions.build(builder => {
builder.controlWithReceiver({
receiver: receiver,
assetAlias: 'gold',
amount: 1
})
...
})
```

Transactions that pay to expired receivers will fail during validation, i.e., while they are being submitted.

### New output property: unique IDs

In Chain Core 1.0.x, transaction outputs were addressed using a compound value consisting of a transaction ID and output position. Chain Core 1.1.x introduces an ID property for each output that is unique across the blockchain.

#### Updates to data structures

##### Transaction outputs and unspent outputs

Transaction output objects and unspent outputs now have an `id` property, which is unique for that output across the history of the blockchain.

```
console.log(tx.outputs[0].id)
console.log(utxo.id)
```

##### Transaction inputs

The `spentOutput` property on transaction inputs is **deprecated**. Use `spentOutputId` instead.

```
console.log(tx.inputs[0].spentOutputId)
```

#### Spending unspent outputs in transactions

The `spendUnspentOutput` method now takes an `outputId` parameter. The `transactionId` and `position` parameters are **deprecated**.

##### Deprecated (1.0.x)

```
templatePromise = client.transactions.build(builder => {
builder.spendUnspentOutput({
transactionId: 'abc123',
position: 0
})
...
})
```

##### New (1.1.x)

```
templatePromise = client.transactions.build(builder => {
builder.spendAccountUnspentOutput({
outputId: 'xyz789'
})
...
})
```

#### Querying previous transactions

To retrieve transactions that were partially consumed by a given transaction input, you can query against a specific output ID.

##### Deprecated (1.0.x)

```
client.transactions.queryAll({
filter: 'id=$1',
filterParameters: [spendingTx.inputs[0].spentOutput.transactionId]
}, (tx, next, done, fail) => {
...
})
```

##### New (1.1.x)

```
client.transactions.queryAll({
filter: 'outputs(id=$1)',
filterParameters: [spendingTx.inputs[0].spentOutputId]
}, (tx, next, done, fail) => {
...
})
```

## 1.0.2 (January 25, 2017)

* Use base URL and client token provided on initialization for MockHSM connection
Expand Down
15 changes: 5 additions & 10 deletions sdk/node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@

### Get the package

The Chain Node SDK is available [via npm](https://www.npmjs.com/package/chain-sdk). Make sure to use the most recent
version whose major and minor components (`major.minor.x`) match your version
of Chain Core. Node 4 or greater is required.
The Chain Node SDK is available [via npm](https://www.npmjs.com/package/chain-sdk). Make sure to use the most recent version whose major and minor components (`major.minor.x`) match your version of Chain Core. Node 4 or greater is required.

For most applications, you can simply add Chain to your `package.json` with
the following command:
For most applications, you can simply add Chain to your `package.json` with the following command:

```
npm install --save chain-sdk@1.0.2
npm install --save chain-sdk@1.1.0
```

### In your code
Expand All @@ -26,8 +23,7 @@ const signer = new chain.HsmSigner()

## Asynchronous Operation

There are two options for interacting with the SDK asynchronously: promises and
callbacks.
There are two options for interacting with the SDK asynchronously: promises and callbacks.

With promises:

Expand All @@ -51,8 +47,7 @@ client.transactions.query({}, callback)

## Using external signers

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

```
const myHsmConnection = new chain.Connection('https://myhost.dev/mockhsm', 'tokenname:tokenvalue')
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.2",
"version": "1.1.0",
"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

0 comments on commit b1d697c

Please sign in to comment.