mirror of
https://github.com/arx-research/libhalo.git
synced 2026-01-08 20:58:02 -05:00
Split APIs to have different include files for each environment (web, desktop, react-native) (#197)
This commit is contained in:
committed by
GitHub
parent
7cd5784b2c
commit
df5f8e3146
34
api/common.js
Normal file
34
api/common.js
Normal file
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* LibHaLo - Programmatically interact with HaLo tags from the web browser, mobile application or the desktop.
|
||||
* Copyright by Arx Research, Inc., a Delaware corporation
|
||||
* License: MIT
|
||||
*/
|
||||
|
||||
const {
|
||||
HaloTagError,
|
||||
HaloLogicError,
|
||||
NFCPermissionRequestDenied,
|
||||
NFCMethodNotSupported,
|
||||
NFCAbortedError,
|
||||
NFCOperationError
|
||||
} = require("../halo/exceptions");
|
||||
const {parsePublicKeys, convertSignature, recoverPublicKey} = require("../halo/utils");
|
||||
|
||||
/**
|
||||
* The LibHaLo stable API. Please don't depend on the functions imported from anywhere else
|
||||
* except the lib's index.js. The library's structure is subject to change in the next versions.
|
||||
*/
|
||||
module.exports = {
|
||||
// exported utils
|
||||
haloParsePublicKeys: parsePublicKeys,
|
||||
haloConvertSignature: convertSignature,
|
||||
haloRecoverPublicKey: recoverPublicKey,
|
||||
|
||||
// exceptions
|
||||
HaloTagError,
|
||||
HaloLogicError,
|
||||
NFCPermissionRequestDenied,
|
||||
NFCMethodNotSupported,
|
||||
NFCAbortedError,
|
||||
NFCOperationError
|
||||
};
|
||||
16
api/desktop.js
Normal file
16
api/desktop.js
Normal file
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* LibHaLo - Programmatically interact with HaLo tags from the web browser, mobile application or the desktop.
|
||||
* Copyright by Arx Research, Inc., a Delaware corporation
|
||||
* License: MIT
|
||||
*/
|
||||
|
||||
const {execHaloCmdPCSC} = require("../drivers/pcsc");
|
||||
|
||||
/**
|
||||
* The LibHaLo stable API. Please don't depend on the functions imported from anywhere else
|
||||
* except the lib's index.js. The library's structure is subject to change in the next versions.
|
||||
*/
|
||||
module.exports = {
|
||||
// for desktop usage
|
||||
execHaloCmdPCSC
|
||||
};
|
||||
16
api/react-native.js
vendored
Normal file
16
api/react-native.js
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* LibHaLo - Programmatically interact with HaLo tags from the web browser, mobile application or the desktop.
|
||||
* Copyright by Arx Research, Inc., a Delaware corporation
|
||||
* License: MIT
|
||||
*/
|
||||
|
||||
const {execHaloCmdRN} = require("../drivers/nfc_manager");
|
||||
|
||||
/**
|
||||
* The LibHaLo stable API. Please don't depend on the functions imported from anywhere else
|
||||
* except the lib's index.js. The library's structure is subject to change in the next versions.
|
||||
*/
|
||||
module.exports = {
|
||||
// for usage with react-native-nfc-manager
|
||||
execHaloCmdRN
|
||||
};
|
||||
28
api/web.js
Normal file
28
api/web.js
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* LibHaLo - Programmatically interact with HaLo tags from the web browser, mobile application or the desktop.
|
||||
* Copyright by Arx Research, Inc., a Delaware corporation
|
||||
* License: MIT
|
||||
*/
|
||||
|
||||
const {
|
||||
execHaloCmdWeb, detectMethod
|
||||
} = require("../drivers/common");
|
||||
const {HaloGateway} = require("../halo/gateway/requestor");
|
||||
const {haloFindBridge} = require("../web/web_utils");
|
||||
const {haloGateExecutorCreateWs, haloGateExecutorUserConfirm} = require("../halo/gateway/executor");
|
||||
|
||||
/**
|
||||
* The LibHaLo stable API. Please don't depend on the functions imported from anywhere else
|
||||
* except the lib's index.js. The library's structure is subject to change in the next versions.
|
||||
*/
|
||||
module.exports = {
|
||||
// for web usage
|
||||
execHaloCmdWeb,
|
||||
haloFindBridge,
|
||||
haloGetDefaultMethod: detectMethod,
|
||||
|
||||
// for web usage with gateway
|
||||
HaloGateway,
|
||||
haloGateExecutorCreateWs,
|
||||
haloGateExecutorUserConfirm,
|
||||
};
|
||||
@@ -8,7 +8,6 @@ const Buffer = require('buffer/').Buffer;
|
||||
const {NFC} = require('nfc-pcsc');
|
||||
const open = require('open');
|
||||
|
||||
const {execHaloCmdPCSC} = require('../index.js');
|
||||
const {__runTestSuite} = require("../halo/tests");
|
||||
const util = require("util");
|
||||
const {
|
||||
@@ -19,6 +18,7 @@ const {
|
||||
wsEventCardIncompatible,
|
||||
wsEventReaderDisconnected
|
||||
} = require("./ws_server");
|
||||
const {execHaloCmdPCSC} = require("../api/desktop");
|
||||
|
||||
const nfc = new NFC();
|
||||
let stopPCSCTimeout = null;
|
||||
|
||||
@@ -2,7 +2,6 @@ const express = require('express');
|
||||
const nunjucks = require("nunjucks");
|
||||
const {WebSocketServer} = require('ws');
|
||||
const crypto = require('crypto').webcrypto;
|
||||
const {execHaloCmdPCSC} = require('../index.js');
|
||||
const {dirname, randomBuffer} = require("./util");
|
||||
const jwt = require('jsonwebtoken');
|
||||
const https = require("https");
|
||||
@@ -10,6 +9,7 @@ const fs = require("fs");
|
||||
const path = require("path");
|
||||
const os = require("os");
|
||||
const util = require("util");
|
||||
const {execHaloCmdPCSC} = require("../api/desktop");
|
||||
|
||||
let wss = null;
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
## Importing the method
|
||||
```javascript
|
||||
const {execHaloCmdPCSC} = require('@arx-research/libhalo');
|
||||
const {execHaloCmdPCSC} = require('@arx-research/libhalo/api/desktop');
|
||||
// or
|
||||
import {execHaloCmdPCSC} from '@arx-research/libhalo';
|
||||
import {execHaloCmdPCSC} from '@arx-research/libhalo/api/desktop.js';
|
||||
```
|
||||
|
||||
## Call specification
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
## Importing the method
|
||||
```javascript
|
||||
import {execHaloCmdRN} from '@arx-research/libhalo';
|
||||
import {execHaloCmdRN} from '@arx-research/libhalo/api/react-native.js';
|
||||
```
|
||||
|
||||
## Call specification
|
||||
|
||||
@@ -13,7 +13,7 @@ haloParsePublicKeys(queryParamStatic);
|
||||
|
||||
**Example function call:**
|
||||
```javascript
|
||||
import {haloParsePublicKeys} from '@arx-research/libhalo';
|
||||
import {haloParsePublicKeys} from '@arx-research/libhalo/api/common.js';
|
||||
|
||||
let pkeys = haloParsePublicKeys(
|
||||
"4104453D40D28E0BAA4D98AC86549DDC5FFFF5F674481A47141137F8A82CB666937A67AECE33B96E" +
|
||||
@@ -45,7 +45,8 @@ haloConvertSignature(digest, derSignature, publicKey);
|
||||
|
||||
**Example usage:**
|
||||
```javascript
|
||||
import {execHaloCmdWeb, haloConvertSignature} from '@arx-research/libhalo';
|
||||
import {execHaloCmdWeb} from '@arx-research/libhalo/api/web.js';
|
||||
import {haloConvertSignature} from '@arx-research/libhalo/api/common.js';
|
||||
|
||||
const KEY_NO = 1;
|
||||
|
||||
@@ -101,7 +102,8 @@ haloRecoverPublicKey(digest, derSignature);
|
||||
|
||||
**Example usage:**
|
||||
```javascript
|
||||
import {execHaloCmdWeb, haloRecoverPublicKey} from '@arx-research/libhalo';
|
||||
import {execHaloCmdWeb} from '@arx-research/libhalo/api/web.js';
|
||||
import {haloRecoverPublicKey} from '@arx-research/libhalo/api/common.js';
|
||||
|
||||
const KEY_NO = 1;
|
||||
|
||||
@@ -144,7 +146,8 @@ haloGetDefaultMethod();
|
||||
|
||||
**Example usage:**
|
||||
```
|
||||
import {execHaloCmdWeb, haloGetDefaultMethod} from '@arx-research/libhalo';
|
||||
import {execHaloCmdWeb} from '@arx-research/libhalo/api/web.js';
|
||||
import {haloGetDefaultMethod} from '@arx-research/libhalo/api/common.js';
|
||||
|
||||
let signRes = await execHaloCmdWeb({
|
||||
"name": "sign",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
## Importing the method
|
||||
```
|
||||
import {execHaloCmdWeb} from '@arx-research/libhalo';
|
||||
import {execHaloCmdWeb} from '@arx-research/libhalo/api/web.js';
|
||||
```
|
||||
|
||||
**Note:** This step is only necessary for module-based applications. You don't need to add this line if you
|
||||
|
||||
@@ -11,7 +11,7 @@ Import the libraries:
|
||||
|
||||
```javascript
|
||||
const {NFC} = require('nfc-pcsc');
|
||||
const {execHaloCmdPCSC} = require('@arx-research/libhalo');
|
||||
const {execHaloCmdPCSC} = require('@arx-research/libhalo/api/desktop');
|
||||
```
|
||||
|
||||
Implement basic code:
|
||||
|
||||
@@ -32,7 +32,7 @@ Example website: [https://bulk.vrfy.ch/](https://bulk.vrfy.ch/).
|
||||
Use `haloFindBridge()` library function in order to obtain the HaLo Bridge address:
|
||||
|
||||
```javascript
|
||||
import {haloFindBridge} from '@arx-research/libhalo';
|
||||
import {haloFindBridge} from '@arx-research/libhalo/api/web.js';
|
||||
|
||||
let wsAddress = await haloFindBridge();
|
||||
```
|
||||
|
||||
@@ -64,7 +64,7 @@ Import necessary functions:
|
||||
|
||||
```javascript
|
||||
import NfcManager, {NfcTech} from 'react-native-nfc-manager';
|
||||
import {execHaloCmdRN} from '@arx-research/libhalo';
|
||||
import {execHaloCmdRN} from '@arx-research/libhalo/api/react-native.js';
|
||||
```
|
||||
|
||||
Add basic code to process the NFC tags:
|
||||
|
||||
@@ -20,7 +20,7 @@ yarn add @arx-research/libhalo
|
||||
Import the library method:
|
||||
|
||||
```javascript
|
||||
import {execHaloCmdWeb} from '@arx-research/libhalo';
|
||||
import {execHaloCmdWeb} from '@arx-research/libhalo/api/web.js';
|
||||
```
|
||||
|
||||
Add a state for displaying information to the user:
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* License: MIT
|
||||
*/
|
||||
|
||||
const {HaloLogicError, HaloTagError} = require("../index");
|
||||
const {HaloLogicError, HaloTagError} = require("../api/common");
|
||||
const EC = require('elliptic').ec;
|
||||
|
||||
const ec = new EC('secp256k1');
|
||||
|
||||
50
index.js
50
index.js
@@ -4,52 +4,8 @@
|
||||
* License: MIT
|
||||
*/
|
||||
|
||||
const {execHaloCmdRN} = require("./drivers/nfc_manager");
|
||||
const {execHaloCmdPCSC} = require("./drivers/pcsc");
|
||||
const {
|
||||
execHaloCmdWeb, detectMethod
|
||||
} = require("./drivers/common");
|
||||
const {
|
||||
HaloTagError,
|
||||
HaloLogicError,
|
||||
NFCPermissionRequestDenied,
|
||||
NFCMethodNotSupported,
|
||||
NFCAbortedError,
|
||||
NFCOperationError
|
||||
} = require("./halo/exceptions");
|
||||
const {parsePublicKeys, convertSignature, recoverPublicKey} = require("./halo/utils");
|
||||
const {HaloGateway} = require("./halo/gateway/requestor");
|
||||
const {haloFindBridge} = require("./web/web_utils");
|
||||
|
||||
/**
|
||||
* The LibHaLo stable API. Please don't depend on the functions imported from anywhere else
|
||||
* except the lib's index.js. The library's structure is subject to change in the next versions.
|
||||
* The LibHaLo API was moved to api/ subdirectory.
|
||||
* Please include the appropriate file for your platform.
|
||||
*/
|
||||
module.exports = {
|
||||
// for desktop usage
|
||||
execHaloCmdPCSC,
|
||||
|
||||
// for web usage
|
||||
execHaloCmdWeb,
|
||||
haloFindBridge,
|
||||
haloGetDefaultMethod: detectMethod,
|
||||
|
||||
// for web usage with gateway
|
||||
HaloGateway,
|
||||
|
||||
// for usage with react-native-nfc-manager
|
||||
execHaloCmdRN,
|
||||
|
||||
// exported utils
|
||||
haloParsePublicKeys: parsePublicKeys,
|
||||
haloConvertSignature: convertSignature,
|
||||
haloRecoverPublicKey: recoverPublicKey,
|
||||
|
||||
// exceptions
|
||||
HaloTagError,
|
||||
HaloLogicError,
|
||||
NFCPermissionRequestDenied,
|
||||
NFCMethodNotSupported,
|
||||
NFCAbortedError,
|
||||
NFCOperationError
|
||||
};
|
||||
module.exports = {};
|
||||
|
||||
@@ -5,53 +5,23 @@
|
||||
*/
|
||||
|
||||
const {
|
||||
execHaloCmdWeb, detectMethod
|
||||
} = require("../drivers/common");
|
||||
const {
|
||||
HaloTagError,
|
||||
HaloLogicError,
|
||||
NFCPermissionRequestDenied,
|
||||
NFCMethodNotSupported,
|
||||
NFCAbortedError,
|
||||
NFCOperationError
|
||||
} = require("../halo/exceptions");
|
||||
const {
|
||||
arr2hex, hex2arr, parsePublicKeys, convertSignature, recoverPublicKey
|
||||
arr2hex, hex2arr
|
||||
} = require("../halo/utils");
|
||||
const {__runTestSuite} = require("../halo/tests");
|
||||
const {HaloGateway} = require("../halo/gateway/requestor");
|
||||
const {haloGateExecutorCreateWs, haloGateExecutorUserConfirm} = require("../halo/gateway/executor");
|
||||
const {haloFindBridge, haloCreateWs} = require("./web_utils");
|
||||
const {haloCreateWs} = require("./web_utils");
|
||||
|
||||
module.exports = {
|
||||
// utilities
|
||||
// libhalo web APIs
|
||||
...require('../api/common.js'),
|
||||
...require('../api/web.js'),
|
||||
|
||||
// extra utilities
|
||||
arr2hex,
|
||||
hex2arr,
|
||||
haloParsePublicKeys: parsePublicKeys,
|
||||
haloConvertSignature: convertSignature,
|
||||
haloRecoverPublicKey: recoverPublicKey,
|
||||
|
||||
// for web usage
|
||||
execHaloCmdWeb,
|
||||
haloFindBridge,
|
||||
haloGetDefaultMethod: detectMethod,
|
||||
|
||||
// for bridge demo
|
||||
// extra util for bridge demo
|
||||
haloCreateWs,
|
||||
|
||||
// for web usage with gateway
|
||||
HaloGateway,
|
||||
haloGateExecutorCreateWs,
|
||||
haloGateExecutorUserConfirm,
|
||||
|
||||
// exceptions
|
||||
HaloTagError,
|
||||
HaloLogicError,
|
||||
NFCPermissionRequestDenied,
|
||||
NFCMethodNotSupported,
|
||||
NFCAbortedError,
|
||||
NFCOperationError,
|
||||
|
||||
// internal, do not use
|
||||
__runTestSuite
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user