alice

package module
v0.0.0-...-cb14c9e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

README

alice

go language package for alicebiometrics.com

Before using it obtain a user and an apiKey from them, then call Init("your user", "your apiKey", "", "", "")

See alice_test.go to find out how to get an user_id, obtain a report and others.

Documentation

Overview

Package alice contains functions to interact with Alice Biometrics for doing the KYC.

@author Manuel Sales (assetverse.com 2020/08/03)

The link https://docs.alicebiometrics.com/onboarding/index.html contains how to communicate with Alice for doing the digital on-boarding and KYC/AML compliance. This module implements the calls to Alice backend to obtain the id and tokens used in the online client. The online client using the id, token and the web/android/ios sdk captures the photo, id front, id back and performs the liveness test. When done it communicates with the backend to complete the process generating the certificate and communicating to the entity that needs the KYC (in our case Pecunia)

Alice auth backend is at https://apis.alicebiometrics.com/auth/ui/#/ ; it is required to put in the header the apikey; the following services are used:

  • GET /login_token -H "accept: application/json"curl -H "X-Consumer-Custom-ID: User" -H "apikey: ApiKey"; returns a {token:sessionToken}
  • GET /backend_token/onboarding -H "accept: application/json" -H "Authorization: bearer sessionToken"; returns a {token:backendToken}
  • GET /user_token/onboarding/userId -H "accept: application/json" -H "Authorization: bearer sessionToken"; returns userToken

Alice onboarding backend is at https://apis.alicebiometrics.com/onboarding/ui/#/ ; the following services are used: - POST /user -H "accept: application/json" -H "Content-Type: multipart/form-data" -H "Authorization: bearer backendToken", returns {user_id:userId}

Steps to obtain the userToken: 1 GET login_token(apiKey)>>sessionToken, 2 GET backend_token(sessionToken)>>backendToken, 3 POST user(backendToken)>>userId

Index

Constants

View Source
const BadExpiry = 2
View Source
const BadMrz = 4
View Source
const BadPhoto = 5
View Source
const DateFormat = 3
View Source
const FaceOk = 0.5

Threshold values for the document face and the selfie; if the score returned is >= they are considered valid

View Source
const Incomplete = 1

error codes

View Source
const SelfieOk = 0.7
View Source
const ServiceOnboarding = "onboarding"

ServiceOnboarding Alice onboarding service

Variables

View Source
var ApiKey = "!!! PUT YOUR API KEY HERE !!!"

ApiKey the Alice provided apiKey

View Source
var BackendToken = make(map[string]AuthToken)

BackendToken map with the current backend tokens for each service

View Source
var BasePath = ""

BasePath contains the base path where the files are downloaded if no filePath set

View Source
var UrlAuth = "https://apis.alicebiometrics.com/auth"

UrlAuth the url of the Alice auth backend

View Source
var UrlOnboard = "https://apis.alicebiometrics.com/onboarding"

UrlOnboard the url of the Alice onboarding backend

View Source
var User = "!!! PUT YOUR USER ID HERE !!!"

User the Alice provided user

Functions

func CheckReport

func CheckReport(userId string, userToken *AuthToken, sd map[string]string, voidBad bool) (code int, raw map[string]interface{}, err error)

CheckReport returns a map for the Kyc; if voidBad it voids the selfie/document that not meets the validations

func CreateCertificate

func CreateCertificate(userId, template string, userToken *AuthToken) (certificateId string, err error)

CreateCertificate creates the user certificate (Signed PDF Report) from uploaded and processed data and if al ok returns the certificateId. Once obtained with GET ​/user​/certificate​/{certificateId} the certificate can be downloaded

func DoRequest

func DoRequest(backend, path, method string, headerParams, formParams map[string]string, jsonArr []byte, queryParams url.Values, filePath *string) (raw map[string]interface{}, err error)

DoRequest build the request (method POST, GET, ..; depending on the recuest, use the header/query/formParams)

func GetCertificate

func GetCertificate(certificateId, userId, filePath string, userToken *AuthToken) (fileLen int, err error)

GetCertificate downloads the pdf with the certificate.

func GetCertificates

func GetCertificates(userId string, userToken *AuthToken) (certificates []string, tss []int64, last int, err error)

GetCertificates the certificates for a userId; it returns an array of certificates, an array of the certificates timestamp and the index of the last timestamp.

func GetMultiMap

func GetMultiMap(raw map[string]interface{}, keys ...string) (val interface{}, ok bool)

GetMultiMap returns the value of a multimap with the keys provided (if the key can be parsed into a number the multimap is an array and the key is the index)

func GetMultiMapArr

func GetMultiMapArr(raw map[string]interface{}, keys ...string) (valArr []string, ok bool)

GetMultiMapArr returns the array string value of a multimap with the keys provided

func GetMultiMapBool

func GetMultiMapBool(raw map[string]interface{}, keys ...string) (valBool bool, ok bool)

GetMultiMapBool returns the boolean value of a multimap with the keys provided

func GetMultiMapFlo

func GetMultiMapFlo(raw map[string]interface{}, keys ...string) (valFlo float64, ok bool)

GetMultiMapFlo returns the float value of a multimap with the keys provided

func GetMultiMapMap

func GetMultiMapMap(raw map[string]interface{}, keys ...string) (valMap map[string]interface{}, ok bool)

GetMultiMapMap returns the array string value of a multimap with the keys provided

func GetMultiMapStr

func GetMultiMapStr(raw map[string]interface{}, keys ...string) (valStr string, ok bool)

GetMultiMapStr returns the string value of a multimap with the keys provided (as this function is used a lot to get the val it is not called GetMultiMap so it is more efficient)

func GetReport

func GetReport(userId string, userToken *AuthToken) (raw map[string]interface{}, err error)

GetReport obtains json report of a userId from the Alice Onboarding backend using the onboarding backend userToken (if not available the function obtains it automatically). The formParams are optional (can be nil); there are the following ones: device_model device_platform device_platform_version email first_name last_name

func GetUser

func GetUser(formParams map[string]string) (userId string, err error)

GetUser obtains the userId from the Alice Onboarding backend using the onboarding backendToken (if not available the function obtains it automatically). The formParams are optional (can be nil); there are the following ones: device_model device_platform device_platform_version email first_name last_name

func Init

func Init(user, apiKey, urlAuth, urlOnboard, basePath string)

Init initialize the Alice credentials and urls; the values empty are ignored.

func PrintMultiMap

func PrintMultiMap(raw map[string]interface{})

PrintMultiMap prints report decoded json structure

func WriteFile

func WriteFile(filePath string, stream io.Reader) (fileLen int, err error)

WriteFile saves in a file at filePath the stream

Types

type AuthToken

type AuthToken struct {
	Token string // token
	Till  int64  // valid till epoch timestamp when expires the session token
}

AuthToken struct to contain the token and its expiry (all Alice Auth backend tokens have 1h expiry)

var SessionToken AuthToken

SessionToken the current session token

func AuthBackendToken

func AuthBackendToken(service string) (backendToken *AuthToken, err error)

AuthBackendToken obtains the backendToken from the Alice Auth backend using the sessionToken (if not available the function obtains it automatically).

func AuthBackendUserToken

func AuthBackendUserToken(service, userId string) (userToken *AuthToken, err error)

AuthBackendUserToken obtains the backend userToken from the Alice Auth backend using the sessionToken (if not available the function obtains it automatically).

func AuthSessionToken

func AuthSessionToken() (sessionToken AuthToken, err error)

AuthSessionToken obtains the sessionToken from the Alice Auth backend using the apiKey; it also returns the expiry of the token.

func AuthUserToken

func AuthUserToken(service, userId string) (userToken AuthToken, err error)

AuthUserToken obtains the userToken from the Alice Auth backend using the sessionToken (if not available the function obtains it automatically).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL