From c43c0a7b7f0bbb8b00791d3cdcb4a645c36d4ac4 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Wed, 15 Nov 2023 23:15:32 +0300 Subject: [PATCH] fix: some validation for filecoin deal info --- package-lock.json | 41 ++++++++++++++++++++++++++++++++++++++- package.json | 1 + problems/7-commp/index.js | 28 ++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 73be456..c5f8656 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "@ipld/dag-json": "^10.1.5", "@ucanto/validator": "^9.0.0", "@web3-storage/access": "^17.1.0", + "@web3-storage/data-segment": "^5.0.0", "@web3-storage/w3up-client": "^11.0.0", "adventure": "^2.11.1", "execa": "^8.0.1", @@ -574,7 +575,7 @@ "@web3-storage/data-segment": "^3.2.0" } }, - "node_modules/@web3-storage/data-segment": { + "node_modules/@web3-storage/capabilities/node_modules/@web3-storage/data-segment": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/@web3-storage/data-segment/-/data-segment-3.2.0.tgz", "integrity": "sha512-SM6eNumXzrXiQE2/J59+eEgCRZNYPxKhRoHX2QvV3/scD4qgcf4g+paWBc3UriLEY1rCboygGoPsnqYJNyZyfA==", @@ -584,6 +585,25 @@ "sync-multihash-sha2": "^1.0.0" } }, + "node_modules/@web3-storage/capabilities/node_modules/multiformats": { + "version": "11.0.2", + "resolved": "https://registry.npmjs.org/multiformats/-/multiformats-11.0.2.tgz", + "integrity": "sha512-b5mYMkOkARIuVZCpvijFj9a6m5wMVLC7cf/jIPd5D/ARDOfLC5+IFkbgDXQgcU2goIsTD/O9NY4DI/Mt4OGvlg==", + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + } + }, + "node_modules/@web3-storage/data-segment": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/@web3-storage/data-segment/-/data-segment-5.0.0.tgz", + "integrity": "sha512-5CbElsxec2DsKhEHEh3XRGISAyna+bCjKjjvFrLcYyXLCaiSt/nF3ypcllxwjpE4newMUArymGKGzzZnRWL2kg==", + "dependencies": { + "@ipld/dag-cbor": "^9.0.5", + "multiformats": "^11.0.2", + "sync-multihash-sha2": "^1.0.0" + } + }, "node_modules/@web3-storage/data-segment/node_modules/multiformats": { "version": "11.0.2", "resolved": "https://registry.npmjs.org/multiformats/-/multiformats-11.0.2.tgz", @@ -691,6 +711,25 @@ "@web3-storage/data-segment": "^3.2.0" } }, + "node_modules/@web3-storage/w3up-client/node_modules/@web3-storage/data-segment": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/@web3-storage/data-segment/-/data-segment-3.2.0.tgz", + "integrity": "sha512-SM6eNumXzrXiQE2/J59+eEgCRZNYPxKhRoHX2QvV3/scD4qgcf4g+paWBc3UriLEY1rCboygGoPsnqYJNyZyfA==", + "dependencies": { + "@ipld/dag-cbor": "^9.0.5", + "multiformats": "^11.0.2", + "sync-multihash-sha2": "^1.0.0" + } + }, + "node_modules/@web3-storage/w3up-client/node_modules/@web3-storage/data-segment/node_modules/multiformats": { + "version": "11.0.2", + "resolved": "https://registry.npmjs.org/multiformats/-/multiformats-11.0.2.tgz", + "integrity": "sha512-b5mYMkOkARIuVZCpvijFj9a6m5wMVLC7cf/jIPd5D/ARDOfLC5+IFkbgDXQgcU2goIsTD/O9NY4DI/Mt4OGvlg==", + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + } + }, "node_modules/@web3-storage/w3up-client/node_modules/type-fest": { "version": "3.13.1", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-3.13.1.tgz", diff --git a/package.json b/package.json index a0181cc..c542a32 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "@ipld/dag-json": "^10.1.5", "@ucanto/validator": "^9.0.0", "@web3-storage/access": "^17.1.0", + "@web3-storage/data-segment": "^5.0.0", "@web3-storage/w3up-client": "^11.0.0", "adventure": "^2.11.1", "execa": "^8.0.1", diff --git a/problems/7-commp/index.js b/problems/7-commp/index.js index 8b7c06a..5ebd430 100644 --- a/problems/7-commp/index.js +++ b/problems/7-commp/index.js @@ -28,10 +28,38 @@ export const verify = (args, cb) => { return console.error(`Failed to parse deal info: ${err.message}`) } + if (!info.piece) { + cb(false) + return console.error(`Invalid deal info: missing piece`) + } + if (!Array.isArray(info.deals)) { + cb(false) + return console.error(`Invalid deal info: non-array deals`) + } + console.log(`\n Piece: ${info.piece}\n`) for (const deal of info.deals) { + if (!deal || typeof deal !== 'object') { + cb(false) + return console.error(`Invalid deal info: non-object deal`) + } + + if (!deal.provider) { + cb(false) + return console.error(`Invalid deal info: missing provider`) + } console.log(`Storage Provider: f0${deal.provider}`) + + if (!deal.aggregate) { + cb(false) + return console.error(`Invalid deal info: missing aggregate CID`) + } console.log(` Aggregate: ${deal.aggregate}`) + + if (!deal.aux?.dataSource?.dealID) { + cb(false) + return console.error(`Invalid deal info: missing deal ID`) + } console.log(` Deal ID: ${deal.aux.dataSource.dealID}\n`) }