Skip to content

Commit

Permalink
Merge pull request #56 from discipl/feature/allow
Browse files Browse the repository at this point in the history
Allow feature, abundance refactoring
  • Loading branch information
bkaptijn authored Apr 18, 2019
2 parents 2b2473f + 962c56b commit 2d3c0d7
Show file tree
Hide file tree
Showing 9 changed files with 170 additions and 1,144 deletions.
1,030 changes: 36 additions & 994 deletions clerk-frontend/package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions clerk-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"version": "0.2.1",
"private": true,
"dependencies": {
"@discipl/abundance-service": "~0.3.0",
"@discipl/core-ephemeral": "^0.4.0",
"@discipl/paper-wallet": "^0.4.0",
"@discipl/abundance-service": "^0.4.1",
"@discipl/core-ephemeral": "^0.6.2",
"@discipl/paper-wallet": "^0.5.0",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "^2.1.8",
Expand Down
27 changes: 12 additions & 15 deletions clerk-frontend/src/need-wizard/ConfirmStep.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { Component } from 'react';
import * as abundance from '@discipl/abundance-service'
import { take } from 'rxjs/operators'

import CONFIGURATION from '../configuration/wpsvc.json'

Expand All @@ -20,29 +19,27 @@ class ConfirmStep extends Component {
async componentDidMount() {
await timeoutPromise(100)

let needSsid = await abundance.need('ephemeral', CONFIGURATION.PRODUCT_NEED)
await timeoutPromise(100)
let matchPromise = (await abundance.observe(needSsid.did, 'ephemeral')).pipe(take(1)).toPromise()
await timeoutPromise(100)
let need = await abundance.need('ephemeral', CONFIGURATION.PRODUCT_NEED)

await abundance.getCoreAPI().claim(needSsid, { [CONFIGURATION.SOURCE_ARGUMENT]: this.props.bsn })
await timeoutPromise(100)
let match = await matchPromise
let observeOffer = await abundance.observeOffer(need.theirPrivateDid, need.myPrivateSsid)
await observeOffer.readyPromise

let personalDid = match.did
await abundance.getCoreAPI().claim(need.myPrivateSsid, { [CONFIGURATION.SOURCE_ARGUMENT]: this.props.bsn })

if (this.props.ssidsChanged) {
this.props.ssidsChanged(personalDid, needSsid)
}

let result = await observeOffer.resultPromise

let brpPromise = (await abundance.getCoreAPI().observe(personalDid, null, true)).pipe(take(1)).toPromise()
if (this.props.ssidsChanged) {
this.props.ssidsChanged(need.theirPrivateDid, need.myPrivateSsid)
}

let brp = await brpPromise
if (this.props.resultLinkChanged) {
this.props.resultLinkChanged(result.link)
}

this.setState({
...this.state,
'data': brp.claim.data
'data': result.claim.data
})
}

Expand Down
13 changes: 3 additions & 10 deletions clerk-frontend/src/need-wizard/DeliveryStep.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import React, { Component } from 'react';
import * as abundance from '@discipl/abundance-service'
import * as paperWallet from '@discipl/paper-wallet'
import { take } from 'rxjs/operators'
import { createCanvas, loadImage } from 'canvas'
import { loadImage } from 'canvas'

import CONFIGURATION from '../configuration/wpsvc.json'

Expand All @@ -29,15 +27,10 @@ class ConfirmStep extends Component {
async componentDidMount() {
console.log(this.props)

let agreePromise = (await abundance.getCoreAPI().observe(this.props.personalDid, { [CONFIGURATION.PRODUCT_NAME]: null })).pipe(take(1)).toPromise()

// Express acceptance of document
await abundance.getCoreAPI().claim(this.props.needSsid, { [CONFIGURATION.PRODUCT_ACCEPT]: '' })

let agree = await agreePromise

let vc = await paperWallet.issue(agree.claim.data[CONFIGURATION.PRODUCT_NAME])
let vc = await paperWallet.issue(this.props.resultLink, this.props.myPrivateSsid)

console.log("Issued")

this.canvasRef.current.width = template.canvasWidth
this.canvasRef.current.height = template.canvasHeight
Expand Down
16 changes: 12 additions & 4 deletions clerk-frontend/src/need-wizard/NeedWizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class NeedWizard extends Component {
this.bsnChanged = this.bsnChanged.bind(this);
this.needChanged = this.needChanged.bind(this);
this.ssidsChanged = this.ssidsChanged.bind(this);
this.resultLinkChanged = this.resultLinkChanged.bind(this);
this.deliveryChanged = this.deliveryChanged.bind(this);
}

Expand Down Expand Up @@ -82,12 +83,19 @@ class NeedWizard extends Component {
})
}

ssidsChanged(personalDid, needSsid) {
ssidsChanged(personalDid, myPrivateSsid) {

this.setState({
...this.state,
'personalDid': personalDid,
'needSsid': needSsid
'myPrivateSsid': myPrivateSsid
})
}

resultLinkChanged(resultLink) {
this.setState({
...this.state,
'resultLink': resultLink
})
}

Expand All @@ -106,9 +114,9 @@ class NeedWizard extends Component {
case 1:
return <NeedStep needChanged={this.needChanged}/>
case 2:
return <ConfirmStep bsn={this.state.bsn} need={this.state.need} ssidsChanged={this.ssidsChanged}/>
return <ConfirmStep bsn={this.state.bsn} need={this.state.need} ssidsChanged={this.ssidsChanged} resultLinkChanged={this.resultLinkChanged}/>
case 3:
return <DeliveryStep personalDid={this.state.personalDid} needSsid={this.state.needSsid} deliveryChanged={this.deliveryChanged}/>
return <DeliveryStep personalDid={this.state.personalDid} myPrivateSsid={this.state.myPrivateSsid} resultLink={this.state.resultLink} deliveryChanged={this.deliveryChanged} />
default:
console.log('Unsupported step')
}
Expand Down
89 changes: 55 additions & 34 deletions waardepapieren-service/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions waardepapieren-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"@babel/core": "^7.4.3",
"@babel/preset-env": "^7.4.3",
"@babel/register": "^7.4.0",
"@discipl/abundance-service": "~0.3.0",
"@discipl/core-ephemeral": "^0.4.0",
"@discipl/abundance-service": "^0.4.1",
"@discipl/core-ephemeral": "^0.6.2",
"@discipl/core-nlx": "~0.2.0",
"babel-plugin-dynamic-import-node": "^2.2.0",
"jsonpath": "^1.0.1",
Expand Down
59 changes: 26 additions & 33 deletions waardepapieren-service/src/waardepapieren-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,58 +18,51 @@ class WaardenpapierenService {

const nlxConnector = await core.getConnector('nlx')
nlxConnector.configure(this.configuration.NLX_OUTWAY_ENDPOINT)
let ssid = await abundance.attendTo('ephemeral', this.configuration.PRODUCT_NEED)
let observer = await abundance.observe(ssid.did, 'ephemeral')
observer.subscribe(async (needClaim) => {
await this.serveNeed(ssid, needClaim)
let attendResult = await abundance.attendTo('ephemeral', this.configuration.PRODUCT_NEED, [this.configuration.SOURCE_ARGUMENT])

// TODO: Refactor to observableResult.subscribe when fix from core propagates
await attendResult.observableResult._observable.subscribe(async (need) => {
await this.serveNeed(need)
}, (e) => {
// If connection is dropped by remote peer, this is fine
if (e.code !== 1006) {
console.error('Error while listening to need')
console.error(e)
}
})

return ssid
await attendResult.observableResult._readyPromise
}

async serveNeed (serviceSsid, need) {
const core = abundance.getCoreAPI()
async serveNeed (need) {
let core = abundance.getCoreAPI()

let did = need.did
let needDetails = await need
let argumentClaim = await needDetails.informationPromise

const observer = await core.observe(did, { [this.configuration.SOURCE_ARGUMENT]: null })
let srcarg = argumentClaim['claim']['data'][this.configuration.SOURCE_ARGUMENT]

await observer.pipe(take(1)).subscribe(async (argumentClaim) => {
const srcarg = argumentClaim['claim']['data'][this.configuration.SOURCE_ARGUMENT]
const nlxConnector = await core.getConnector('nlx')
let nlxpath = this.configuration.SOURCE_NLX_PATH.replace('{'+this.configuration.SOURCE_ARGUMENT+'}', srcarg)
let identifier = await nlxConnector.claim(null, { 'path': nlxpath, 'params': {[this.configuration.SOURCE_ARGUMENT]:srcarg} })
const nlxConnector = await core.getConnector('nlx')
let nlxpath = this.configuration.SOURCE_NLX_PATH.replace('{'+this.configuration.SOURCE_ARGUMENT+'}', srcarg)
let identifier = await nlxConnector.claim(null, { 'path': nlxpath, 'params': {[this.configuration.SOURCE_ARGUMENT]:srcarg} })

let result = await nlxConnector.get(identifier)
let result = await nlxConnector.get(identifier)

let privateSvcSsid = await core.newSsid('ephemeral') // needs signing with NLX key
let resultArray = [{'Doel':this.configuration.PRODUCT_PURPOSE}]
let privateSvcSsid = await core.newSsid('ephemeral') // needs signing with NLX key
let resultArray = [{'Doel':this.configuration.PRODUCT_PURPOSE}]

for (let field in this.configuration.SOURCE_DATA_SELECTION) {
let key = Object.keys(this.configuration.SOURCE_DATA_SELECTION[field])[0]
let path = this.configuration.SOURCE_DATA_SELECTION[field][key]
let value = jp.query(result, path)
for (let field in this.configuration.SOURCE_DATA_SELECTION) {
let key = Object.keys(this.configuration.SOURCE_DATA_SELECTION[field])[0]
let path = this.configuration.SOURCE_DATA_SELECTION[field][key]
let value = jp.query(result, path)

resultArray.push({ [key]: value[0] })
}
resultArray.push({ [key]: value[0] })
}

let productClaim = await core.claim(privateSvcSsid, resultArray)
await abundance.match(privateSvcSsid, did)
let productClaim = await core.claim(privateSvcSsid, resultArray)

const acceptObserver = await core.observe(did, { [this.configuration.PRODUCT_ACCEPT]: null })
await core.allow(privateSvcSsid, productClaim, needDetails.theirPrivateDid)

acceptObserver.pipe(take(1)).subscribe(async (acceptClaim) => {
await core.attest(privateSvcSsid, this.configuration.PRODUCT_NAME, productClaim)
})
}, (e) => {
console.error(e)
})
await abundance.offer(needDetails.myPrivateSsid, productClaim)
}

async stop () {
Expand Down
Loading

0 comments on commit 2d3c0d7

Please sign in to comment.