From 2afd0e8a2326e77b29a73fbb4f22335a5a6e3ec2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Thu, 23 Oct 2025 14:48:20 +0200 Subject: [PATCH 1/3] feat: send AUTH_TOKEN in retrieval requests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduce an optional configuration option (Fly.io secret) adding Authorization header to retrieval requests. When the token is not configured, the requests will stay anonymous. This is useful for local testing. Signed-off-by: Miroslav Bajtoš --- bin/bot.js | 3 +++ index.js | 14 +++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/bin/bot.js b/bin/bot.js index 0fac179..b20966e 100644 --- a/bin/bot.js +++ b/bin/bot.js @@ -18,6 +18,7 @@ const { CDN_HOSTNAME = 'calibration.filbeam.io', DELAY = 1_000, FROM_DATA_SET_ID = 0, + AUTH_TOKEN, } = process.env const fetchRequest = new ethers.FetchRequest(RPC_URL) @@ -57,6 +58,7 @@ await Promise.all([ botLocation: FLY_REGION, CDN_HOSTNAME, FROM_DATA_SET_ID: BigInt(FROM_DATA_SET_ID), + AUTH_TOKEN, }) console.log('\n') await setTimeout(Number(DELAY)) @@ -71,6 +73,7 @@ await Promise.all([ botLocation: FLY_REGION, CDN_HOSTNAME, FROM_DATA_SET_ID: BigInt(FROM_DATA_SET_ID), + AUTH_TOKEN, }) console.log('\n') await setTimeout(Number(30_000)) // block time diff --git a/index.js b/index.js index a9456a7..f74f27c 100644 --- a/index.js +++ b/index.js @@ -135,6 +135,7 @@ export const serviceProviderRegistryAbi = [ * @param {BigInt} args.pieceId * @param {boolean} [args.retryOn404=true] Default is `true` * @param {number} [args.retryDelayMs=10_000] Default is `10_000` + * @param {string} [args.AUTH_TOKEN] * @returns {Promise} */ async function testRetrieval({ @@ -149,13 +150,20 @@ async function testRetrieval({ pieceId, retryOn404 = true, retryDelayMs = 10_000, + AUTH_TOKEN, }) { const url = `https://${clientAddress}.${CDN_HOSTNAME}/${pieceCid}` console.log('Fetching', url) let res try { - res = await fetch(url) + /** @type {Record} */ + const headers = {} + if (AUTH_TOKEN) { + headers['authorization'] = `Bearer ${AUTH_TOKEN}` + } + + res = await fetch(url, { headers }) } catch (err) { console.error( 'ALERT Cannot retrieve data set %s piece %sfrom %s via %s: %s', @@ -188,6 +196,7 @@ async function testRetrieval({ pieceCid, dataSetId, pieceId, + AUTH_TOKEN, retryOn404: false, }) } @@ -305,6 +314,7 @@ async function maybeGetResolvedDataSetRetrievalUrl({ * @param {string} [args.botLocation] Fly region where the bot is running * @param {string} args.CDN_HOSTNAME * @param {BigInt} args.FROM_DATA_SET_ID + * @param {string} [args.AUTH_TOKEN] */ export async function sampleRetrieval({ @@ -314,6 +324,7 @@ export async function sampleRetrieval({ botLocation = '', CDN_HOSTNAME, FROM_DATA_SET_ID, + AUTH_TOKEN, }) { const { pieceCid, dataSetId, pieceId, clientAddress } = await pickRandomFileWithCDN({ @@ -333,6 +344,7 @@ export async function sampleRetrieval({ pieceCid, dataSetId, pieceId, + AUTH_TOKEN, }) } From 0fa944f091c57ddb2a528fbc548d0ef363928de3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Fri, 24 Oct 2025 16:37:12 +0200 Subject: [PATCH 2/3] Update index.js Co-authored-by: Julian Gruber --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index f74f27c..8942feb 100644 --- a/index.js +++ b/index.js @@ -158,9 +158,9 @@ async function testRetrieval({ let res try { /** @type {Record} */ - const headers = {} + const headers = new Headers() if (AUTH_TOKEN) { - headers['authorization'] = `Bearer ${AUTH_TOKEN}` + headers.set('authorization', `Bearer ${AUTH_TOKEN}`) } res = await fetch(url, { headers }) From adf47610af1ed3ef9e032faea60f4cf8915864d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Fri, 24 Oct 2025 16:39:27 +0200 Subject: [PATCH 3/3] fixup! fix npm test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miroslav Bajtoš --- index.js | 2 +- package-lock.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 8942feb..1a07839 100644 --- a/index.js +++ b/index.js @@ -157,7 +157,6 @@ async function testRetrieval({ let res try { - /** @type {Record} */ const headers = new Headers() if (AUTH_TOKEN) { headers.set('authorization', `Bearer ${AUTH_TOKEN}`) @@ -486,6 +485,7 @@ async function pickRandomFileWithCDN({ * @param {string} [args.botLocation] Fly region where the bot is running * @param {string} args.CDN_HOSTNAME * @param {BigInt} args.FROM_DATA_SET_ID + * @param {string} [args.AUTH_TOKEN] */ export async function testLatestRetrievablePiece({ diff --git a/package-lock.json b/package-lock.json index 0a28a6d..19e175d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { - "name": "@filcdn/bot", + "name": "@filbeam/bot", "version": "0.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "@filcdn/bot", + "name": "@filbeam/bot", "version": "0.0.0", "license": "MIT", "dependencies": {