0.1.4 • Published 3 years ago

typescript-lib-example-caui v0.1.4

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

Web API Docs

Here some instructions to make website communicate with the extension

Lib Path

The lib is a JS/TS file that create functions to run commands direct from webpage to extension. TS file are located at web-lib-generator\src\sign.ts JS file can be generated by the command yarn build-lib, and the minified js file will be generated at web-lib-generator\dist\Sign.min.js

Using Lib

const SITE = window.location.protocol + "//" + window.location.host

const MY_KEY = btoa(JSON.stringify({sitesEnabled: SITE}))

  1. Import Lib (Sign.min.js or sign.ts)
  2. Instantiate the signer object passing the key const signer = new Sign(MY_KEY)
  3. Use methods from signer object (sign, getCertificates, hasSoftware, hasExtension)

Types

interface Certificate {
  isValid: boolean
  issuer: string
  name: string
  notAfter: string
  notBefore: string
  pem: string
  provider: string
  specialName: string
  type: string
  personId?: string
}

interface Signature {
  key: number
  signature: string
}

interface ErrorResponse {
  level: "BACKGROUND" | "CONTENT" | "CLI" | "LIB" | "EXTENSION_RUNTIME" // specify where the error occurred
  error: string // user friendly message
  code: number // code based on error level, explained later...
  originalErrorMessage?: string // original error message if it exist (set if level is "EXTENSION_RUNTIME" or "CLI")
}

Error Codes

All error codes can be found at ../extension-ts/shared/errorMessagesAndCodes.ts Code

Functions

List certificates

const searchResponse = await signer.getCertificates()
// will return: Certificate[] | ErrorResponse

Sign

const dataToSignArray = [{
  dataToSign, // string of data to sign
  key: 1,
}]
const signResponse = await signer.sign({ dataToSignArray, certificate })
// will return: Signature[] | ErrorResponse

Has Extension

const hasExtension = await signer.hasExtension() // timeout = 1000ms
// wil return: true | ErrorResponse

Has Software

const hasSoftware = await signer.hasSoftware() // timeout = 1000ms
// wil return: true | ErrorResponse

Download extension

const  = await signer.downloadExtension()
// wil return: void | ErrorResponse
// void response will open a new tab with the download link

Download software

const  = await signer.downloadSoftware()
// wil return: void | ErrorResponse
// void response will open a new tab with the download link
0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago