Skip to content

Commit

Permalink
Merge pull request #9 from bigchaindb/update-dependencies
Browse files Browse the repository at this point in the history
Update dependencies
  • Loading branch information
getlarge authored Mar 9, 2021
2 parents 6378521 + 1d9de89 commit 9c25834
Show file tree
Hide file tree
Showing 28 changed files with 360 additions and 248 deletions.
20 changes: 12 additions & 8 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
{
"presets": ["env"],
"plugins": [
["transform-runtime", {
"helpers": false,
"polyfill": false,
"regenerator": true
}]
"presets": [
[
"@babel/preset-env",
{
"targets": [
"> 0.25%, not dead",
"not IE 11",
"maintained node versions"
]
}
]
],
"sourceMaps": true
}
}
9 changes: 8 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
extends: standard
{
"extends": [
"eslint:recommended",
"standard",
"plugin:node/recommended",
"plugin:promise/recommended"
],
}
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run lint-staged
9 changes: 9 additions & 0 deletions .mocharc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
"extension": ["js"],
"target": "esnext",
"recursive": true,
"timeout": 30000,
"spec": "test/*Spec.js",
"watch-files": ["test"],
"exit": true
}
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Crypto Conditions

[npm-url]: https://npmjs.org/package/js-crypto-conditions
[![npm][npm-image]][npm-url]
<!-- [![circle][circle-image]][circle-url] [![codecov][codecov-image]][codecov-url] -->

[npm-image]: https://img.shields.io/npm/v/crypto-conditions.svg?style=flat
[npm-url]: https://npmjs.org/package/crypto-conditions
<!-- [circle-image]: https://circleci.com/gh/interledgerjs/five-bells-condition.svg?style=shield -->
<!-- [circle-url]: https://circleci.com/gh/interledgerjs/five-bells-condition -->
<!-- [codecov-image]: https://codecov.io/gh/interledgerjs/five-bells-condition/branch/master/graph/badge.svg -->
<!-- [codecov-url]: https://codecov.io/gh/interledgerjs/five-bells-condition -->

> Implementation of crypto-conditions in JavaScript for Node.js and the browser
Expand Down Expand Up @@ -35,9 +43,12 @@ This specification is only a draft at this stage and has not been submitted.
- [Advanced: Parse a Condition](#advanced-parse-a-condition)
- [Advanced: Parse and Reserialize a THRESHOLD-SHA-256 Fulfillment](#advanced-parse-and-reserialize-a-threshold-sha-256-fulfillment)
- [Advanced: Manually Create a Condition](#advanced-manually-create-a-condition)
- [In browser environment](#in-browser-environment)

## API Documentation

TODO: Host doc on [https://www.bigchaindb.com/](https://www.bigchaindb.com/)

**[API Docs](https://interledger.org/five-bells-condition/jsdoc/)**

## Usage
Expand Down Expand Up @@ -310,3 +321,25 @@ myCondition.setCost(0)
console.log(myCondition.serializeUri())
// prints 'ni:///sha-256;47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU?fpt=preimage-sha-256&cost=0'
```

### In browser environment

```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>CryptoConditions</title>
</head>
<body>
<script src="https://unpkg.com/crypto-conditions@2.0.3/dist/browser/CryptoConditions.window.min.js"></script>
<script>
const conditionUri = 'ni:///sha-256;47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU?fpt=preimage-sha-256&cost=0'
const validationResult = CryptoConditions.validateCondition(condition)
console.log(`Condition ${conditionUri} is valid ? ${validationResult}`)
alert(JSON.stringify(CryptoConditions.Condition.fromUri(conditionUri), null, 2))
</script>
</body>
</html>
```
75 changes: 50 additions & 25 deletions docs/README.template.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Crypto Conditions

[![npm][npm-image]][npm-url] [![circle][circle-image]][circle-url] [![codecov][codecov-image]][codecov-url]
[![npm][npm-image]][npm-url]
<!-- [![circle][circle-image]][circle-url] [![codecov][codecov-image]][codecov-url] -->

[npm-image]: https://img.shields.io/npm/v/five-bells-condition.svg?style=flat
[npm-url]: https://npmjs.org/package/five-bells-condition
[circle-image]: https://circleci.com/gh/interledgerjs/five-bells-condition.svg?style=shield
[circle-url]: https://circleci.com/gh/interledgerjs/five-bells-condition
[codecov-image]: https://codecov.io/gh/interledgerjs/five-bells-condition/branch/master/graph/badge.svg
[codecov-url]: https://codecov.io/gh/interledgerjs/five-bells-condition
[npm-image]: https://img.shields.io/npm/v/crypto-conditions.svg?style=flat
[npm-url]: https://npmjs.org/package/crypto-conditions
<!-- [circle-image]: https://circleci.com/gh/interledgerjs/five-bells-condition.svg?style=shield -->
<!-- [circle-url]: https://circleci.com/gh/interledgerjs/five-bells-condition -->
<!-- [codecov-image]: https://codecov.io/gh/interledgerjs/five-bells-condition/branch/master/graph/badge.svg -->
<!-- [codecov-url]: https://codecov.io/gh/interledgerjs/five-bells-condition -->

> Implementation of crypto-conditions in JavaScript for Node.js and the browser
Expand All @@ -23,14 +24,16 @@ This specification is only a draft at this stage and has not been submitted.

## API Documentation

TODO: Host doc on [https://www.bigchaindb.com/](https://www.bigchaindb.com/)

**[API Docs](https://interledger.org/five-bells-condition/jsdoc/)**

## Usage

### Validate a Condition

``` js
const cc = require('five-bells-condition')
const cc = require('crypto-conditions')

// Check a condition for validity
const condition = 'ni:///sha-256;47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU?fpt=preimage-sha-256&cost=0'
Expand All @@ -44,7 +47,7 @@ all accepted by the current implementation.
### Validate a Fulfillment (No Message)

``` js
const cc = require('five-bells-condition')
const cc = require('crypto-conditions')

const condition = 'ni:///sha-256;47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU?fpt=preimage-sha-256&cost=0'
const fulfillment = 'oAKAAA'
Expand All @@ -57,7 +60,7 @@ This validates the fulfillment and ensures that it matches the given condition.
### Get Condition from Fulfillment And Validate

``` js
const cc = require('five-bells-condition')
const cc = require('crypto-conditions')

const fulfillment = 'oAKAAA'
const condition = cc.fulfillmentToCondition(fulfillment)
Expand All @@ -71,7 +74,7 @@ const validationResult = cc.validateFulfillment(fulfillment, condition)
### Create a PREIMAGE-SHA-256 Condition (Hashlock)

``` js
const cc = require('five-bells-condition')
const cc = require('crypto-conditions')

const myFulfillment = new cc.PreimageSha256()
myFulfillment.setPreimage(Buffer.from(''))
Expand All @@ -82,7 +85,7 @@ console.log(myFulfillment.getConditionUri())
### Create a PREIMAGE-SHA-256 Fullfillment (Hashlock)

``` js
const cc = require('five-bells-condition')
const cc = require('crypto-conditions')

const myFulfillment = new cc.PreimageSha256()
myFulfillment.setPreimage(Buffer.from(''))
Expand All @@ -93,7 +96,7 @@ console.log(myFulfillment.serializeUri())
### Parse a Fulfillment

``` js
const cc = require('five-bells-condition')
const cc = require('crypto-conditions')

const parsedFulfillment = cc.fromFulfillmentUri('oAKAAA')
// parsedFulfillment instanceof cc.PreimageSha256 === true
Expand All @@ -106,7 +109,7 @@ parsedFulfillment.validate()
### Create an ED25519 Condition

``` js
const cc = require('five-bells-condition')
const cc = require('crypto-conditions')

const ed25519Fulfillment = new cc.Ed25519Sha256()
ed25519Fulfillment.setPublicKey(Buffer.from('ec172b93ad5e563bf4932c70e1245034c35467ef2efd4d64ebf819683467e2bf', 'hex'))
Expand All @@ -117,7 +120,7 @@ console.log(ed25519Fulfillment.getConditionUri())
### Fulfill an ED25519 Condition

``` js
const cc = require('five-bells-condition')
const cc = require('crypto-conditions')

const edPrivateKey = Buffer.from('833fe62409237b9d62ec77587520911e9a759cec1d19755b7da901b96dca3d42', 'hex')

Expand All @@ -135,7 +138,7 @@ console.log(ed25519Fulfillment.serializeUri())
### Verify a Fulfillment (with Message)

``` js
const cc = require('five-bells-condition')
const cc = require('crypto-conditions')

const fulfillment = 'pGSAIOwXK5OtXlY79JMscOEkUDTDVGfvLv1NZOv4GWg0Z-K_gUC2IpH62UMvjymLnEpIldvik_b_2hpo2t8Mze9fR6DHISpf6jzal6P0wD6p8uisHOyGpR1FISer26CdG28zHAcK'
const condition = 'ni:///sha-256;U1YhFdW0lOI-SVF3PbDP4t_lVefj_-tB5P11yvfBaoE?fpt=ed25519-sha-256&cost=131072'
Expand All @@ -147,7 +150,7 @@ const result = cc.validateFulfillment(fulfillment, condition, message)

### Create a THRESHOLD-SHA-256 Condition
``` js
const cc = require('five-bells-condition')
const cc = require('crypto-conditions')

const thresholdFulfillment = new cc.ThresholdSha256()
thresholdFulfillment.addSubconditionUri('ni:///sha-256;U1YhFdW0lOI-SVF3PbDP4t_lVefj_-tB5P11yvfBaoE?fpt=ed25519-sha-256&cost=131072')
Expand All @@ -160,7 +163,7 @@ console.log(thresholdFulfillment.getConditionUri())
### Create a THRESHOLD-SHA-256 Fulfillment

``` js
const cc = require('five-bells-condition')
const cc = require('crypto-conditions')

const thresholdFulfillment = new cc.ThresholdSha256()
thresholdFulfillment.addSubfulfillmentUri('pGSAIOwXK5OtXlY79JMscOEkUDTDVGfvLv1NZOv4GWg0Z-K_gUC2IpH62UMvjymLnEpIldvik_b_2hpo2t8Mze9fR6DHISpf6jzal6P0wD6p8uisHOyGpR1FISer26CdG28zHAcK')
Expand All @@ -179,7 +182,7 @@ console.log(thresholdFulfillmentUri)
### Create a PREFIX-SHA-256 Condition

``` js
const cc = require('five-bells-condition')
const cc = require('crypto-conditions')

const prefix = new cc.PrefixSha256()
prefix.setPrefix(Buffer.from('2016:'))
Expand All @@ -192,7 +195,7 @@ console.log(prefix.getConditionUri())
### Create a PREFIX-SHA-256 Fulfillment

``` js
const cc = require('five-bells-condition')
const cc = require('crypto-conditions')

const prefix = new cc.PrefixSha256()
prefix.setPrefix(Buffer.from('Hello World! '))
Expand All @@ -210,7 +213,7 @@ cc.validateFulfillment(fulfillmentUri, conditionUri, message)
### Create an RSA-SHA-256 Condition

``` js
const cc = require('five-bells-condition')
const cc = require('crypto-conditions')

const rsaFulfillment = new cc.RsaSha256()
rsaFulfillment.setPublicModulus(Buffer.from('b30e7a938783babf836850ff49e14f87e3f92d5c46e33feca3e4f0b22358580b11765995f4b8eea7fb4712c2e1e316f7f775a953d232216a169d9a64ddc007120a400b37f2afc077b62fe304de74de6a119ec4076b529c4f6096b0baad4f533df0173b9b822fd85d65fa4befa92d8f524f69cbca0136bd80d095c169aec0e095', 'hex'))
Expand All @@ -221,7 +224,7 @@ console.log(rsaFulfillment.getConditionUri())
### Create an RSA-SHA-256 Fulfillment

``` js
const cc = require('five-bells-condition')
const cc = require('crypto-conditions')

const exampleMessage = Buffer.from('Hello World! Conditions are here!')
const privateKey =
Expand Down Expand Up @@ -257,7 +260,7 @@ cc.validateFulfillment(rsaFulfillmentUri, rsaConditionUri, exampleMessage)

### Advanced: Parse a Condition
``` js
const cc = require('five-bells-condition')
const cc = require('crypto-conditions')

// Parse a condition
const condition = 'ni:///sha-256;47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU?fpt=preimage-sha-256&cost=0'
Expand All @@ -272,7 +275,7 @@ console.log(parsedCondition.serializeUri())
### Advanced: Parse and Reserialize a THRESHOLD-SHA-256 Fulfillment

``` js
const cc = require('five-bells-condition')
const cc = require('crypto-conditions')

const thresholdFulfillmentUri = 'oi-gBKACgAChJ6AlgCB_g7Flf_H8U7ktwYFIodZd_C1LH6PWdyhK3dIAEm2QaYEBDA'
const reparsedFulfillment = cc.fromFulfillmentUri(thresholdFulfillmentUri)
Expand All @@ -285,7 +288,7 @@ console.log(reserializedFulfillment)
### Advanced: Manually Create a Condition

``` js
const cc = require('five-bells-condition')
const cc = require('crypto-conditions')

const myCondition = new cc.Condition()
myCondition.setTypeId(cc.PreimageSha256.TYPE_ID)
Expand All @@ -295,3 +298,25 @@ myCondition.setCost(0)
console.log(myCondition.serializeUri())
// prints 'ni:///sha-256;47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU?fpt=preimage-sha-256&cost=0'
```

### In browser environment

```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>CryptoConditions</title>
</head>
<body>
<script src="https://unpkg.com/crypto-conditions@2.0.3/dist/browser/CryptoConditions.window.min.js"></script>
<script>
const conditionUri = 'ni:///sha-256;47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU?fpt=preimage-sha-256&cost=0'
const validationResult = CryptoConditions.validateCondition(condition)
console.log(`Condition ${conditionUri} is valid ? ${validationResult}`)
alert(JSON.stringify(CryptoConditions.Condition.fromUri(conditionUri), null, 2))
</script>
</body>
</html>
```
31 changes: 21 additions & 10 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
const puppeteer = require('puppeteer')
process.env.CHROME_BIN = puppeteer.executablePath()

module.exports = function (karma) {
karma.set({
frameworks: [ 'mocha' ],
files: ['node_modules/babel-polyfill/dist/polyfill.js', 'test/index.js'],
frameworks: ['mocha'],
plugins: [
'karma-webpack',
'karma-mocha',
'karma-sourcemap-loader',
'karma-chrome-launcher'
],
files: [
{ pattern: 'test/*Spec.js', watched: false }
],
preprocessors: {
'test/index.js': [ 'webpack', 'sourcemap' ]
'test/*Spec.js': ['webpack', 'sourcemap']
},

webpack: {
entry: ['./index.js'],
devtool: 'inline-source-map',
module: {
rules: [
{ test: /\.js$/, exclude: /node_modules|dist/, loader: 'babel-loader' },
{
test: /\.js$/,
exclude: /node_modules|dist/,
loader: 'babel-loader'
}
],
noParse: [
/sinon/
]
noParse: [/sinon/]
},
resolve: {
alias: { sinon: 'sinon/pkg/sinon' }
Expand All @@ -29,6 +40,6 @@ module.exports = function (karma) {
stats: 'errors-only'
},

browsers: [ 'PhantomJS' ]
browsers: ['ChromeHeadless']
})
}
Loading

0 comments on commit 9c25834

Please sign in to comment.