Skip to content

blockpass-org/blockpass-websdk

Repository files navigation

Blockpass SdkWeb

Structure

This packages contains:

  • ES6 source code src/
  • Transpiler for node (below 6) dist/node
  • Transpiler for web-browser dist/browser

Getting started (browser)

  1. Add blockpass-web package via <script> tag
<script src="https://cdn.blockpass.org/sdk/v2.0.1/blockpass.dev.js"></script>
  1. Init SDK
/*
Blockpass Clientid
*/
const clientId = "...";

/*
Blockpass Environments:
  - staging: Our testing enviroment (Blockpass partner and tester)
  - prod: Live enviroment of Blockpass
*/
const env = "staging|prod";

/*
Reference Id: Your generated code. Which use to match KycRecord with your userId
*/
const refId = "";

sdk = new window.Blockpass.WebSDK({
  clientId,
  env,
  refreshRateMs: 1000
});
  1. Subscribe to SDK events
function onBlockpassCodeRefresh(params) {
  // session code ready to use now

  // demo qrcode images ( using demo online qrserver ).
  // DON'T USE THIS FOR YOUR SERVICE
  document.getElementById(
    "step1-qr"
  ).src = `http://api.qrserver.com/v1/create-qr-code/?data=${JSON.stringify({
    clientId: "...",
    session: params.session,
    refId
  })}`;
}

function onBlockpassProcessing(params) {
  // session code invalid from now
  // Show loading indicator
}

function onBlockpassSSoResult(params) {
  // sso complete. handle your logic here
}

function onBlockpassSessionExpired() {
  // session code expired.
  // Note: You can reset new code via
  //    sdk.generateSSOData()
  //
}

// Setup events handler
sdk.on("code-refresh", onBlockpassCodeRefresh);
sdk.on("sso-processing", onBlockpassProcessing);
sdk.on("sso-complete", onBlockpassSSoResult);
sdk.on("code-expired", onBlockpassSessionExpired);

// request for new sso code
sdk.generateSSOData();

Development Instalation

$ yarn install

Development Commands

$ npm test # run tests with Jest
$ npm run coverage # run tests with coverage and open it on browser
$ npm run lint # lint code
$ npm run docs # generate docs
$ npm run build # generate docs and transpile code
$ npm run watch # watch code changes and run scripts automatically

API

Table of Contents

WebSDK

Extends EventEmitter

Blockpass WebSDK

Parameters

generateSSOData

Generate new SSO code and monitor status

destroy

Deconstructor

getApplink

Generate appLink string Example: blockpass-local://service-register/3rd_service_demo?session=c33ab4f2-c208-4cc0-9adf-e49cccff6d2c

Returns Promise<string?>


ConstructorParams

Type: object

Properties

  • env string Deployment env (local|staging|prod).
  • clientId string Blockpass ClientId (obtain when register with Blockpass platform).

WebSDK#code-refresh

Generated session code, can only be used once. Life cycles (created -> processing -> success|failed) Client must refresh code after sso failed / timeout

Type: object

Properties

WebSDK#sso-processing

Session code switch to processing

Type: object

Properties

  • status string status of session code

WebSDK#sso-complete

Session code switch to processing

Type: object

Properties

  • status string status of session code (success|failed)
  • customData object customData
    • customData.sessionData string session code
    • customData.extraData object Services' extra data

WebSDK#code-expired

Session code expired

Type: object

License

ApacheV2