0.1.4 • Published 1 month ago

@verified-orchestration/client-js v0.1.4

Weekly downloads
-
License
MIT
Repository
-
Last release
1 month ago

Verified Orchestration Client - JavaScript

A JavaScript client for the Verified Orchestration API suitable for use in the browser or via NPM.

The client can use either subscriptions over websockets (default) or polling over HTTP to receive events.

Note: if you are using a UI framework like React, Kotlin or Swift already, you may prefer to use Apollo Client to access the Verified Orchestration API directly.

Usage in the browser

Add a reference to the client script to your HTML page:

<script type="text/javascript" src="https://unpkg.com/@verified-orchestration/client-js/index.min.js"></script>

Use the client in your JavaScript code:

<!doctype html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>Verified Orchestration client - browser usage example</title>
    <script type="text/javascript" src="https://unpkg.com/@verified-orchestration/client-js/index.min.js"></script>
  </head>
  <body>
    <script type="text/javascript">
      const verifiedOrchestrationApiUrl = 'TODO: fill this in'
      const credentialTypes = ['VerifiedEmployee', 'KycVerifiedIdentity'] // TODO: fill this in

      acquirePresentationToken().then((accessToken) => {
        const client = new verifiedOrchestrationClientJs.VerifiedOrchestrationClient({
          url: verifiedOrchestrationApiUrl,
          accessToken,
        })

        const promptForPresentation = (presentationRequest) => console.log
        const onPresentationEvent = (event) => console.log

        client
          .createPresentationRequest(
            { clientName: 'Test client', requestedCredentials: credentialTypes.map((credentialType) => ({ type: credentialType })) },
            onPresentationEvent,
          )
          .then(promptForPresentation)
      })
    </script>
  </body>
</html>

Usage via npm

Install the package and peer dependencies:

npm install @verified-orchestration/client-js graphql-ws ws

Import and use the client + types:

import type { PresentationEventData, PresentationResponse } from '@verified-orchestration/client-js'
import { VerifiedOrchestrationClient } from '@verified-orchestration/client-js'

const verifiedOrchestrationApiUrl = 'TODO: fill this in'
const acquireAccessToken = async (): Promise<string> => throw new Error('TODO: acquireAccessToken')

const showQrCodeOrOpenUrl = (presentationRequest: PresentationResponse) => console.log // TODO: show the QR code or open the presentation URL
const onPresentationEvent = (event: PresentationEventData) => console.log // TODO: use the presentation data

const client = new VerifiedOrchestrationClient({
  url: verifiedOrchestrationApiUrl,
  accessToken: await acquireAccessToken(),
})

client
  .createPresentationRequest(
    { clientName: 'Test client', requestedCredentials: credentialTypes.map((credentialType) => ({ type: credentialType })) },
    onPresentationEvent,
  )
  .then(showQrCodeOrOpenUrl)
0.1.4

1 month ago

0.1.3

4 months ago

0.1.2

6 months ago

0.1.1

6 months ago

0.1.0

6 months ago

0.0.7

6 months ago

0.0.6

7 months ago

0.0.5

7 months ago

0.0.4

7 months ago

0.0.3

7 months ago

0.0.2

7 months ago

0.0.1

7 months ago