0.0.9 • Published 4 years ago

qredo-client-js v0.0.9

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
4 years ago

Qredo-Client-JS

For v0.08 docs click here

The Qredo JavaScript SDK enables you to build applications that can work with the Qredo enterprise server and connect to the Qredo network to create, swap and settle crypto currency assets.

The qredo-client-js does two things:

  1. Sets up BLS encryption keys for signing messages
  2. Connects to Qredo's Matrix messaging service for communication with Qredo (for more information about Matrix click here)

Qredo-Client-JS uses https://github.com/apache/incubator-milagro-crypto-js

Examples

Browser Example

The browser example stores the bls key seed in the browser's local storage. This is not recommended in a production setting!

This app is witten as an SPA in plain JavaScript, using webpack as a packager. The code is written to keep all the Qredo client operations (src/index.js) away from the view components (src/view.js) so the code looks a bit strange!

To run this example

cd .../qredo-client-js/examples/browser
npm install
npx webpack

You will then need to run a web server and point it to:

.../qredo-client-js/examples/browser/index.html

for example:

npx http-server ./examples/browser

ReactNative Example

In a production system the BLS keypair seed needs to be absolutely secure and for this reason Qredo reccommends using a mobile device with a secure enclave and biometric security for signing transactions. This is a small demonstration of how such an app could be built using this JavaScript SDK and reactNative.

This app uses this package https://github.com/oblador/react-native-keychain to interact with the secure element of IoS and Android devices.

Haul

Unfortunately the milagro-crypto-js library prevents us from using the standard Metro packager (due to a dynamic require) so this this app uses Haul (which relies on webpack). This has the beneficial side effect of allowing us to use NPM simlinks, which is handy if you want to work with the sdk code.

To install the example:

cd .../qredo-client-js/examples/reactNative
npm install
yarn haul
cd ios
pod install

//Then in another terminal

react-native run-ios

To symlink the NPM package first link the package

~/qredo-client.js

npm link

then connect the link to the example

~/qredo-client-js/examples/reactNative

npm link qredo-client-js

Developer Notes

First install the sdk

npm i -s qredo-client-js

To inititate a new connection to the Qredo service

import Qredo from 'qredo-client-js'

  let user = {
        username: "foo",
        password: "bah"
    }

    let config = {
        server: "your server"
    }

    qredo = new Qredo(user, config)

Seed

The most important thing your app has to do is to generate and store a seed that is used to generate a BLS keypair. The client code does not handle the generation of the seeds. The example code uses this approach:

const array = new Uint32Array(8)
let seed = window.crypto.getRandomValues(array)

Callbacks

You can set up a few optional callbacks to trigger events in your app by overriding these properties:

  • statusCallback
  • genericMessageCallback
  • newWalletCallback

The details for each one can be found in the docs

The usage is very simple - just set a new function with the correct params like this...

let q = new Qredo(user, config)
q.newWalletCallback = (type, address) => {alert(`I got a new ${type} wallet with address ${address}`)}

The usage is very simple - just set a new function with the correct params like this...

let q = new Qredo(user, config)
q.newWalletCallback = (type, address) => {alert(`I got a new ${type} wallet with address ${address}`)}
0.0.9

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.3

4 years ago

0.0.1

4 years ago