Comparing version 1.2.0 to 1.3.0-0
@@ -10,9 +10,14 @@ #!/usr/bin/env node | ||
let baseUrl = process.env.INSIGHT_BASE_URL || "https://insight.dash.org"; | ||
let dashsightBaseUrl = | ||
process.env.INSIGHT_BASE_URL || "https://insight.dash.org"; | ||
// "https://dashnode.duckdns.org/insight-api"; | ||
process.env.DASHSIGHT_BASE_URL || "https://insight.dash.org/insight-api"; | ||
if (!dashsightBaseUrl) { | ||
dashsightBaseUrl = `${baseUrl}/insight-api`; | ||
} | ||
let Dashsight = require("../"); | ||
let dashsight = Dashsight.create({ | ||
baseUrl: dashsightBaseUrl, | ||
baseUrl, | ||
dashsightBaseUrl, | ||
}); | ||
@@ -31,2 +36,6 @@ | ||
// debug | ||
console.error(); | ||
console.error("Dashsight Base URL:", dashsightBaseUrl); | ||
let result = await dashsight.instantSend(txHex); | ||
@@ -33,0 +42,0 @@ if (json) { |
@@ -12,3 +12,4 @@ #!/usr/bin/env node | ||
let baseUrl = `https://insight.dash.org`; | ||
let dashsocketBaseUrl = | ||
process.env.DASHSIGHT_WS_BASE_URL || `https://insight.dash.org/socket.io`; | ||
@@ -31,2 +32,4 @@ function help() { | ||
async function main() { | ||
console.info("WS Base URL:", dashsocketBaseUrl); | ||
// ex: inv,dashd/addresstxid | ||
@@ -50,3 +53,3 @@ let eventnames = (process.argv[2] || "inv").split(","); | ||
await DashSocket.listen( | ||
baseUrl, | ||
dashsocketBaseUrl, | ||
function finder(evname, data) { | ||
@@ -53,0 +56,0 @@ console.log(evname, data); |
@@ -16,8 +16,42 @@ (function (exports) { | ||
/** | ||
* @typedef DashsightInstance | ||
* TODO | ||
*/ | ||
/** | ||
* @param {Object} opts | ||
* @param {String} opts.baseUrl | ||
* @param {String} opts.baseUrl - for the Insight API | ||
* @param {String} [opts.insightBaseUrl] - for regular Insight features, includes prefix | ||
* @param {String} [opts.dashsightBaseUrl] - for Dash-specific features, such as instant send | ||
* @param {String} [opts.dashsocketBaseUrl] - for WebSocket notifications | ||
*/ | ||
Dashsight.create = function ({ baseUrl }) { | ||
Dashsight.create = function ({ | ||
baseUrl, | ||
dashsightBaseUrl, | ||
insightBaseUrl, | ||
dashsocketBaseUrl, | ||
}) { | ||
let insight = {}; | ||
if (!dashsightBaseUrl) { | ||
dashsightBaseUrl = `${baseUrl}/insight-api`; | ||
} | ||
if (dashsightBaseUrl.endsWith("/")) { | ||
dashsightBaseUrl = dashsightBaseUrl.slice(0, dashsightBaseUrl.length - 1); | ||
} | ||
if (!insightBaseUrl) { | ||
insightBaseUrl = dashsightBaseUrl; | ||
} | ||
if (insightBaseUrl.endsWith("/")) { | ||
insightBaseUrl = insightBaseUrl.slice(0, insightBaseUrl.length - 1); | ||
} | ||
if (!dashsocketBaseUrl) { | ||
dashsocketBaseUrl = `${baseUrl}/socket.io`; | ||
} | ||
if (dashsocketBaseUrl.endsWith("/")) { | ||
dashsocketBaseUrl = dashsocketBaseUrl.slice(0, dashsocketBaseUrl.length - 1); | ||
} | ||
/** | ||
@@ -31,3 +65,3 @@ * Don't use this with instantSend | ||
console.warn(` consider (await getUtxos()).reduce(countSatoshis)`); | ||
let txUrl = `${baseUrl}/insight-api/addr/${address}/?noTxList=1`; | ||
let txUrl = `${insightBaseUrl}/addr/${address}/?noTxList=1`; | ||
let txResp = await request({ url: txUrl, json: true }); | ||
@@ -70,3 +104,3 @@ | ||
insight.getUtxos = async function (address) { | ||
let utxoUrl = `${baseUrl}/insight-api/addr/${address}/utxo`; | ||
let utxoUrl = `${insightBaseUrl}/addr/${address}/utxo`; | ||
let utxoResp = await request({ url: utxoUrl, json: true }); | ||
@@ -101,3 +135,3 @@ | ||
insight.getTx = async function (txid) { | ||
let txUrl = `${baseUrl}/insight-api/tx/${txid}`; | ||
let txUrl = `${insightBaseUrl}/tx/${txid}`; | ||
let txResp = await request({ url: txUrl, json: true }); | ||
@@ -116,3 +150,3 @@ | ||
insight.getTxs = async function (addr, maxPages) { | ||
let txUrl = `${baseUrl}/insight-api/txs?address=${addr}&pageNum=0`; | ||
let txUrl = `${insightBaseUrl}/txs?address=${addr}&pageNum=0`; | ||
let txResp = await request({ url: txUrl, json: true }); | ||
@@ -136,3 +170,3 @@ | ||
let nextResp = await request({ | ||
url: `${baseUrl}/insight-api/txs?address=${addr}&pageNum=${cursor}`, | ||
url: `${insightBaseUrl}/txs?address=${addr}&pageNum=${cursor}`, | ||
json: true, | ||
@@ -151,3 +185,6 @@ }); | ||
insight.instantSend = async function (hexTx) { | ||
let instUrl = `${baseUrl}/insight-api-dash/tx/sendix`; | ||
// Ex: | ||
// - https://insight.dash.org/insight-api-dash/tx/sendix | ||
// - https://dashnode.duckdns.org/insight-api/tx/sendix | ||
let instUrl = `${dashsightBaseUrl}/tx/sendix`; | ||
let reqObj = { | ||
@@ -154,0 +191,0 @@ method: "POST", |
@@ -9,12 +9,18 @@ (function (exports) { | ||
/** | ||
* @param {Object} opts | ||
* @param {String} opts.baseUrl | ||
* @param {null} opts.cookieStore | ||
* @param {Boolean} opts.debug | ||
* @param {Function} opts.onClose | ||
* @param {Function} opts.onError | ||
* @param {Function} opts.onMessage | ||
* @typedef WsOpts | ||
* @prop {String} [baseUrl] - (deprecated by dashsocketBaseUrl) ex: https://insight.dash.org | ||
* @prop {CookieStore} cookieStore - only needed for insight APIs hosted behind an AWS load balancer | ||
* @prop {Boolean} debug | ||
* @prop {Function} onClose | ||
* @prop {Function} onError | ||
* @prop {Function} onMessage | ||
* @prop {String} dashsocketBaseUrl - ex: https://insight.dash.org/socket.io | ||
*/ | ||
/** | ||
* @param {WsOpts} opts | ||
*/ | ||
Ws.create = function ({ | ||
baseUrl, | ||
dashsocketBaseUrl, | ||
cookieStore = null, | ||
@@ -30,6 +36,16 @@ debug, | ||
if (!dashsocketBaseUrl) { | ||
dashsocketBaseUrl = `${baseUrl}/socket.io`; | ||
} | ||
if (dashsocketBaseUrl.endsWith("/")) { | ||
dashsocketBaseUrl = dashsocketBaseUrl.slice( | ||
0, | ||
dashsocketBaseUrl.length - 1, | ||
); | ||
} | ||
// Get `sid` (session id) and ping/pong params | ||
Eio3.connect = async function () { | ||
let now = Date.now(); | ||
let sidUrl = `${baseUrl}/socket.io/?EIO=3&transport=polling&t=${now}`; | ||
let sidUrl = `${dashsocketBaseUrl}/?EIO=3&transport=polling&t=${now}`; | ||
@@ -61,3 +77,3 @@ let sidResp = await window.fetch(sidUrl, { | ||
let now = Date.now(); | ||
let subUrl = `${baseUrl}/socket.io/?EIO=3&transport=polling&t=${now}&sid=${sid}`; | ||
let subUrl = `${dashsocketBaseUrl}/?EIO=3&transport=polling&t=${now}&sid=${sid}`; | ||
let body = stringifySub(eventname); | ||
@@ -87,3 +103,3 @@ | ||
let now = Date.now(); | ||
let pollUrl = `${baseUrl}/socket.io/?EIO=3&transport=polling&t=${now}&sid=${sid}`; | ||
let pollUrl = `${dashsocketBaseUrl}/?EIO=3&transport=polling&t=${now}&sid=${sid}`; | ||
@@ -116,8 +132,4 @@ let cookies = await cookieStore.get(pollUrl); | ||
Eio3.connectWs = async function (sid) { | ||
baseUrl = baseUrl.slice(4); // trim leading 'http' | ||
let url = | ||
`ws${baseUrl}/socket.io/?EIO=3&transport=websocket&sid=${sid}`.replace( | ||
"http", | ||
"ws", | ||
); | ||
let dashsocketBaseUrlPart = dashsocketBaseUrl.slice(4); // trim leading 'http' | ||
let url = `ws${dashsocketBaseUrlPart}/?EIO=3&transport=websocket&sid=${sid}`; | ||
@@ -324,7 +336,10 @@ let ws = new WebSocket(url, []); | ||
/** | ||
* @param {String} baseUrl | ||
* @param {String} dashsocketBaseUrl | ||
* @param {Finder} find | ||
* @param {Partial<WsOpts>} [opts] | ||
*/ | ||
Ws.listen = async function (baseUrl, find, opts) { | ||
Ws.listen = async function (dashsocketBaseUrl, find, opts) { | ||
if ("https://insight.dash.org" === dashsocketBaseUrl) { | ||
dashsocketBaseUrl = "https://insight.dash.org/socket.io"; | ||
} | ||
let ws; | ||
@@ -335,3 +350,3 @@ let p = new Promise(async function (resolve, reject) { | ||
Object.assign({}, opts, { | ||
baseUrl: baseUrl, | ||
dashsocketBaseUrl: dashsocketBaseUrl, | ||
cookieStore: null, | ||
@@ -338,0 +353,0 @@ debug: opts?.debug, |
{ | ||
"name": "dashsight", | ||
"version": "1.2.0", | ||
"version": "1.3.0-0", | ||
"description": "SDK for Dash's flavor of the Insight API", | ||
@@ -25,6 +25,7 @@ "main": "index.js", | ||
"bin", | ||
"lib", | ||
"dashrequest.js", | ||
"dashsight.js", | ||
"dashsocket.js", | ||
"index.js", | ||
"lib", | ||
"typings", | ||
@@ -57,7 +58,11 @@ "ws" | ||
"dependencies": { | ||
"@root/request": "^1.9.1" | ||
"@root/request": "^1.9.2" | ||
}, | ||
"devDependencies": { | ||
"@types/tough-cookie": "^4.0.2" | ||
"@dashevo/dashcore-lib": "^0.19.44", | ||
"@root/base58check": "^1.0.0", | ||
"@types/tough-cookie": "^4.0.2", | ||
"ripemd160": "^2.0.2", | ||
"secp256k1": "^4.0.3" | ||
} | ||
} |
@@ -21,6 +21,12 @@ # [dashsight.js](https://github.com/dashhive/dashsight.js) | ||
let dashsightBaseUrl = | ||
process.env.INSIGHT_BASE_URL || "https://insight.dash.org"; | ||
process.env.DASHSIGHT_BASE_URL || "https://dashnode.duckdns.org/insight-api"; | ||
let dashsocketBaseUrl = | ||
process.env.DASHSOCKET_BASE_URL || "https://insight.dash.org/socket.io"; | ||
let insightBaseUrl = | ||
process.env.DASHSIGHT_BASE_URL || "https://insight.dash.org/insight-api"; | ||
let dashsight = require("dashsight").create({ | ||
baseUrl: dashsightBaseUrl, | ||
dashsightBaseUrl: dashsightBaseUrl, | ||
dashsocketBaseUrl: dashsocketBaseUrl, | ||
insightBaseUrl: insightBaseUrl, | ||
}); | ||
@@ -45,3 +51,5 @@ | ||
let dashsight = window.DashSight.create({ | ||
baseUrl: "https://insight.dash.org", | ||
dashsightBaseUrl: "https://dashnode.duckdns.org/insight-api", | ||
dashsocketBaseUrl: "https://insight.dash.org/socket.io", | ||
insightBaseUrl: "https://insight.dash.org/insight-api", | ||
}); | ||
@@ -52,3 +60,3 @@ | ||
await window.DashSocket.listen( | ||
"https://insight.dash.org", | ||
"https://insight.dash.org/socket.io", | ||
function finder(evname, data) { | ||
@@ -78,13 +86,13 @@ console.log(evname, data); | ||
| `DashSight.create({ baseUrl })` | | ||
| -------------------------------------- | | ||
| `dashsight.getInstantBalance(addrStr)` | | ||
| `dashsight.getTx(txIdHex)` | | ||
| `dashsight.getTxs(addrStr, maxPages)` | | ||
| `dashsight.getUtxos(addrStr)` | | ||
| `dashsight.instantSend(txHex)` | | ||
| `DashSight.create({ dashsightBaseUrl, dashsocketBaseUrl })` | | ||
| ----------------------------------------------------------- | | ||
| `dashsight.getInstantBalance(addrStr)` | | ||
| `dashsight.getTx(txIdHex)` | | ||
| `dashsight.getTxs(addrStr, maxPages)` | | ||
| `dashsight.getUtxos(addrStr)` | | ||
| `dashsight.instantSend(txHex)` | | ||
## DashSight.create({ baseUrl }) | ||
## DashSight.create({ dashsightBaseUrl, dashsocketBaseUrl }) | ||
Creates an instance of the insight sdk bound to the given baseUrl. | ||
Creates an instance of the insight sdk bound to the given base urls. | ||
@@ -95,9 +103,11 @@ ```js | ||
let dashsight = DashSight.create({ | ||
baseUrl: "https://insight.dash.org", | ||
dashsightBaseUrl: "https://dashnode.duckdns.org/insight-api", | ||
dashsocketBaseUrl: "https://insight.dash.org/socket.io", | ||
insightBaseUrl: "https://insight.dash.org/insight-api", | ||
}); | ||
``` | ||
Note: There is no default `baseUrl` (this is supposed to be used in a | ||
decentralized fashion, after all), but `https://insight.dash.org` might be one | ||
you trust. | ||
Note: There are no default base URLs (this is supposed to be used in a | ||
decentralized fashion, after all), but the ones given above are a good starting | ||
point if you don't have your own. | ||
@@ -104,0 +114,0 @@ ## dashsight.getBalance(address) |
@@ -13,3 +13,3 @@ "use strict"; | ||
* @typedef {Object} WsOpts | ||
* @prop {String} baseUrl | ||
* @prop {String} [baseUrl] - (deprecated by dashsocketBaseUrl) ex: https://insight.dash.org | ||
* @prop {CookieStore} cookieStore - only needed for insight APIs hosted behind an AWS load balancer | ||
@@ -20,2 +20,3 @@ * @prop {Boolean} debug | ||
* @prop {Function} onMessage | ||
* @prop {String} dashsocketBaseUrl - ex: https://insight.dash.org/socket.io | ||
*/ | ||
@@ -28,2 +29,3 @@ | ||
baseUrl, | ||
dashsocketBaseUrl, | ||
cookieStore, | ||
@@ -39,6 +41,16 @@ debug, | ||
if (!dashsocketBaseUrl) { | ||
dashsocketBaseUrl = `${baseUrl}/socket.io`; | ||
} | ||
if (dashsocketBaseUrl.endsWith("/")) { | ||
dashsocketBaseUrl = dashsocketBaseUrl.slice( | ||
0, | ||
dashsocketBaseUrl.length - 1, | ||
); | ||
} | ||
// Get `sid` (session id) and ping/pong params | ||
Eio3.connect = async function () { | ||
let now = Date.now(); | ||
let sidUrl = `${baseUrl}/socket.io/?EIO=3&transport=polling&t=${now}`; | ||
let sidUrl = `${dashsocketBaseUrl}/?EIO=3&transport=polling&t=${now}`; | ||
@@ -86,3 +98,3 @@ let cookies = await cookieStore.get(sidUrl); | ||
let now = Date.now(); | ||
let subUrl = `${baseUrl}/socket.io/?EIO=3&transport=polling&t=${now}&sid=${sid}`; | ||
let subUrl = `${dashsocketBaseUrl}/?EIO=3&transport=polling&t=${now}&sid=${sid}`; | ||
let sub = JSON.stringify(["subscribe", eventname]); | ||
@@ -119,3 +131,3 @@ // not really sure what this is, couldn't find documentation for it | ||
let now = Date.now(); | ||
let pollUrl = `${baseUrl}/socket.io/?EIO=3&transport=polling&t=${now}&sid=${sid}`; | ||
let pollUrl = `${dashsocketBaseUrl}/?EIO=3&transport=polling&t=${now}&sid=${sid}`; | ||
@@ -148,10 +160,6 @@ let cookies = await cookieStore.get(pollUrl); | ||
Eio3.connectWs = async function (sid) { | ||
baseUrl = baseUrl.slice(4); // trim leading 'http' | ||
let url = | ||
`ws${baseUrl}/socket.io/?EIO=3&transport=websocket&sid=${sid}`.replace( | ||
"http", | ||
"ws", | ||
); | ||
let dashsocketBaseUrlPart = dashsocketBaseUrl.slice(4); // trim leading 'http' | ||
let url = `ws${dashsocketBaseUrlPart}/?EIO=3&transport=websocket&sid=${sid}`; | ||
let cookies = await cookieStore.get(`${baseUrl}/`); | ||
let cookies = await cookieStore.get(`${dashsocketBaseUrl}/`); | ||
let ws = new WSClient(url, { | ||
@@ -315,7 +323,11 @@ //agent: httpAgent, | ||
/** | ||
* @param {String} baseUrl | ||
* @param {String} dashsocketBaseUrl | ||
* @param {Finder} find | ||
* @param {Partial<WsOpts>} [opts] | ||
*/ | ||
Ws.listen = async function (baseUrl, find, opts) { | ||
Ws.listen = async function (dashsocketBaseUrl, find, opts) { | ||
if ("https://insight.dash.org" === dashsocketBaseUrl) { | ||
dashsocketBaseUrl = "https://insight.dash.org/socket.io"; | ||
} | ||
let ws; | ||
@@ -327,3 +339,3 @@ let Cookies = require("./cookies.js"); | ||
Object.assign({}, opts, { | ||
baseUrl: baseUrl, | ||
dashsocketBaseUrl: dashsocketBaseUrl, | ||
cookieStore: Cookies, | ||
@@ -361,3 +373,3 @@ debug: opts?.debug, | ||
/** | ||
* @param {String} baseUrl | ||
* @param {String} dashsocketBaseUrl | ||
* @param {String} addr | ||
@@ -370,12 +382,16 @@ * @param {Number} [amount] | ||
Ws.waitForVout = async function ( | ||
baseUrl, | ||
dashsocketBaseUrl, | ||
addr, | ||
amount = 0, | ||
maxTxLockWait = 3000, | ||
opts, | ||
opts = {}, | ||
) { | ||
if ("https://insight.dash.org" === dashsocketBaseUrl) { | ||
dashsocketBaseUrl = "https://insight.dash.org/socket.io"; | ||
} | ||
// Listen for Response | ||
/** @type SocketPayment */ | ||
let mempoolTx; | ||
return await Ws.listen(baseUrl, findResponse, opts); | ||
return await Ws.listen(dashsocketBaseUrl, findResponse, opts); | ||
@@ -382,0 +398,0 @@ /** |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
65205
21
1932
354
5
2
10
Updated@root/request@^1.9.2