Compare commits
3 Commits
v0.2.0-dev
...
v0.2.0-dev
Author | SHA1 | Date |
---|---|---|
semantic-release-bot | 85cbf2afe5 | |
Derrick Hammer | 872fab5455 | |
Derrick Hammer | 747aeb7d2e |
|
@ -1,3 +1,10 @@
|
|||
# [0.2.0-develop.30](https://git.lumeweb.com/LumeWeb/libweb/compare/v0.2.0-develop.29...v0.2.0-develop.30) (2023-08-10)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add new downloadSmallObject function that only hashes the data and compares it and does not verify it in real time ([747aeb7](https://git.lumeweb.com/LumeWeb/libweb/commit/747aeb7d2e34b702b764eae367f90b062aabc1f3))
|
||||
|
||||
# [0.2.0-develop.29](https://git.lumeweb.com/LumeWeb/libweb/compare/v0.2.0-develop.28...v0.2.0-develop.29) (2023-08-10)
|
||||
|
||||
|
||||
|
|
|
@ -1,18 +1,19 @@
|
|||
{
|
||||
"name": "@lumeweb/libweb",
|
||||
"version": "0.2.0-develop.29",
|
||||
"version": "0.2.0-develop.30",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@lumeweb/libweb",
|
||||
"version": "0.2.0-develop.29",
|
||||
"version": "0.2.0-develop.30",
|
||||
"dependencies": {
|
||||
"@lumeweb/community-portals": "^0.1.0-develop.6",
|
||||
"@lumeweb/libportal": "0.2.0-develop.17",
|
||||
"@lumeweb/node-library-preset": "0.2.7",
|
||||
"@noble/curves": "^1.1.0",
|
||||
"@noble/hashes": "^1.3.1"
|
||||
"@noble/hashes": "^1.3.1",
|
||||
"binconv": "^0.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@semantic-release/changelog": "^6.0.3",
|
||||
|
@ -3814,6 +3815,11 @@
|
|||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/binconv": {
|
||||
"version": "0.2.0",
|
||||
"resolved": "https://registry.npmjs.org/binconv/-/binconv-0.2.0.tgz",
|
||||
"integrity": "sha512-FAVbv8Fe1lsk1XQeWaYzfIQ9EnBgLJxjlqVA5XzbusP1YCzFgXUfIfmuanNmfM7i0XsNCNnYOnnq7NRLVKRgdQ=="
|
||||
},
|
||||
"node_modules/bottleneck": {
|
||||
"version": "2.19.5",
|
||||
"resolved": "https://registry.npmjs.org/bottleneck/-/bottleneck-2.19.5.tgz",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@lumeweb/libweb",
|
||||
"version": "0.2.0-develop.29",
|
||||
"version": "0.2.0-develop.30",
|
||||
"main": "lib/index.js",
|
||||
"type": "module",
|
||||
"repository": {
|
||||
|
@ -25,7 +25,8 @@
|
|||
"@lumeweb/libportal": "0.2.0-develop.17",
|
||||
"@lumeweb/node-library-preset": "0.2.7",
|
||||
"@noble/curves": "^1.1.0",
|
||||
"@noble/hashes": "^1.3.1"
|
||||
"@noble/hashes": "^1.3.1",
|
||||
"binconv": "^0.2.0"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
import { getActivePortals } from "#portal.js";
|
||||
import { ErrTuple } from "#types.js";
|
||||
import { decodeCid, getVerifiableStream } from "@lumeweb/libportal";
|
||||
import {
|
||||
readableStreamToUint8Array,
|
||||
uint8ArrayToReadableStream,
|
||||
} from "binconv";
|
||||
import { equalBytes } from "@noble/curves/abstract/utils";
|
||||
import { blake3 } from "@noble/hashes/blake3";
|
||||
|
||||
const NO_PORTALS_ERROR = [null, "no active portals"] as ErrTuple;
|
||||
|
||||
|
@ -37,3 +43,40 @@ export async function downloadObject(cid: string): Promise<ErrTuple> {
|
|||
|
||||
return NO_PORTALS_ERROR;
|
||||
}
|
||||
|
||||
export async function downloadSmallObject(cid: string): Promise<ErrTuple> {
|
||||
const activePortals = getActivePortals();
|
||||
|
||||
if (!activePortals.length) {
|
||||
return NO_PORTALS_ERROR;
|
||||
}
|
||||
|
||||
for (const portal of activePortals) {
|
||||
if (!(await portal.isLoggedIn())) {
|
||||
try {
|
||||
await portal.register();
|
||||
} catch {}
|
||||
|
||||
await portal.login();
|
||||
}
|
||||
|
||||
let stream;
|
||||
|
||||
try {
|
||||
stream = await portal.downloadFile(cid);
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
|
||||
const CID = decodeCid(cid);
|
||||
const data = await readableStreamToUint8Array(stream);
|
||||
|
||||
if (!equalBytes(blake3(data), CID.hash)) {
|
||||
return [null, "cid verification failed"];
|
||||
}
|
||||
|
||||
return [uint8ArrayToReadableStream(data), null];
|
||||
}
|
||||
|
||||
return NO_PORTALS_ERROR;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue