gridplus-sdk
Advanced tools
Comparing version 0.9.6 to 0.9.7
{ | ||
"name": "gridplus-sdk", | ||
"version": "0.9.6", | ||
"version": "0.9.7", | ||
"description": "SDK to interact with GridPlus Lattice1 device", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -100,3 +100,3 @@ const bitwise = require('bitwise'); | ||
const param = this._buildRequest(deviceCodes.CONNECT, this.pubKeyBytes()); | ||
this._request(param, (err, res) => { | ||
this._request(param, null, (err, res) => { | ||
if (err) return cb(err); | ||
@@ -138,4 +138,3 @@ this.isPaired = this._handleConnect(res) || false; | ||
// Build the request | ||
const param = this._buildEncRequest(encReqCodes.FINALIZE_PAIRING, payload); | ||
this._request(param, (err, res) => { | ||
this._request(payload, 'FINALIZE_PAIRING', (err, res) => { | ||
if (err) return cb(err); | ||
@@ -161,4 +160,3 @@ // Recover the ephemeral key | ||
data.payload.copy(payload, 6); | ||
const param = this._buildEncRequest(encReqCodes.TEST, payload); | ||
this._request(param, (err, res) => { | ||
this._request(payload, 'TEST', (err, res) => { | ||
if (err) return cb(err); | ||
@@ -224,4 +222,3 @@ const decrypted = this._handleEncResponse(res, decResLengths.test); | ||
payload.writeUInt8(val, off); off++; | ||
const param = this._buildEncRequest(encReqCodes.GET_ADDRESSES, payload); | ||
return this._request(param, (err, res) => { | ||
return this._request(payload, 'GET_ADDRESSES', (err, res) => { | ||
if (err) return cb(err); | ||
@@ -284,4 +281,3 @@ const parsedRes = this._handleGetAddresses(res); | ||
// Construct the encrypted request and send it | ||
const param = this._buildEncRequest(encReqCodes.SIGN_TRANSACTION, payload); | ||
return this._request(param, (err, res) => { | ||
return this._request(payload, 'SIGN_TRANSACTION', (err, res) => { | ||
if (err) { | ||
@@ -323,4 +319,3 @@ // If there was another error caught, return it | ||
abiPayload.copy(payload, 10); | ||
const param = this._buildEncRequest(encReqCodes.ADD_ABI_DEFS, payload); | ||
return this._request(param, (err, res, responseCode) => { | ||
return this._request(payload, 'ADD_ABI_DEFS', (err, res, responseCode) => { | ||
if (responseCode && responseCode !== responseCodes.RESP_SUCCESS) | ||
@@ -367,4 +362,3 @@ return cb('Error making request.'); | ||
// Encrypt the request and send it to the Lattice. | ||
const param = this._buildEncRequest(encReqCodes.ADD_PERMISSION_V0, payload); | ||
return this._request(param, (err, res) => { | ||
return this._request(payload, 'ADD_PERMISSION_V0', (err, res) => { | ||
if (err) { | ||
@@ -398,4 +392,3 @@ // If there was another error caught, return it | ||
// Encrypt the request and send it to the Lattice. | ||
const param = this._buildEncRequest(encReqCodes.GET_KV_RECORDS, payload); | ||
return this._request(param, (err, res) => { | ||
return this._request(payload, 'GET_KV_RECORDS', (err, res) => { | ||
if (err) { | ||
@@ -471,4 +464,3 @@ // If there was another error caught, return it | ||
// Encrypt the request and send it to the Lattice. | ||
const param = this._buildEncRequest(encReqCodes.ADD_KV_RECORDS, payload); | ||
return this._request(param, (err, res) => { | ||
return this._request(payload, 'ADD_KV_RECORDS', (err, res) => { | ||
if (err) { | ||
@@ -504,4 +496,3 @@ // If there was another error caught, return it | ||
// Encrypt the request and send it to the Lattice. | ||
const param = this._buildEncRequest(encReqCodes.REMOVE_KV_RECORDS, payload); | ||
return this._request(param, (err, res) => { | ||
return this._request(payload, 'REMOVE_KV_RECORDS', (err, res) => { | ||
if (err) { | ||
@@ -537,4 +528,3 @@ // If there was another error caught, return it | ||
const payload = Buffer.alloc(0); | ||
const param = this._buildEncRequest(encReqCodes.GET_WALLETS, payload); | ||
return this._request(param, (err, res) => { | ||
return this._request(payload, 'GET_WALLETS', (err, res) => { | ||
if (err) { | ||
@@ -629,4 +619,12 @@ this._resetActiveWallets(); | ||
_request(data, cb, retryCount=this.retryCount) { | ||
if (!this.deviceId) return cb('Serial is not set. Please set it and try again.'); | ||
_request(payload, encReqCode, cb, retryCount=this.retryCount) { | ||
if (!this.deviceId) { | ||
return cb('Device ID is not set. Please set it and try again.'); | ||
} else if (encReqCode && encReqCodes[encReqCode] === undefined) { | ||
return cb('Unknown encrypted request code.'); | ||
} | ||
// Encrypt the data if appropriate. Most requests are end-to-end encrypted, | ||
// but some (e.g. CONNNECT) are not encrypted. | ||
const data = encReqCode ? this._buildEncRequest(encReqCodes[encReqCode], payload) : | ||
payload; | ||
const url = `${this.baseUrl}/${this.deviceId}`; | ||
@@ -659,3 +657,3 @@ superagent.post(url).timeout(this.timeout) | ||
setTimeout(() => { | ||
this._request(data, cb, retryCount-1); | ||
this._request(payload, encReqCode, cb, retryCount-1); | ||
}, 3000); | ||
@@ -673,3 +671,3 @@ } else if ((wrongWallet || invalidEphemId) && canRetry) { | ||
// Retry the original request | ||
this._request(data, cb, retryCount-1); | ||
this._request(payload, encReqCode, cb, retryCount-1); | ||
} | ||
@@ -676,0 +674,0 @@ }) |
125902
2864