libskynetnode
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -1,12 +0,3 @@ | ||
interface progressiveFetchResult { | ||
success: boolean; | ||
portal: string; | ||
response: Response; | ||
portalsFailed: string[]; | ||
responsesFailed: Response[]; | ||
messagesFailed: string[]; | ||
remainingPortals: string[]; | ||
logs: string[]; | ||
} | ||
import { progressiveFetchResult } from "libskynet"; | ||
declare function progressiveFetch(endpoint: string, fetchOpts: any, portals: string[], verifyFunction: any): Promise<progressiveFetchResult>; | ||
export { progressiveFetch, progressiveFetchResult }; |
@@ -1,76 +0,3 @@ | ||
import { addContextToErr, bufToHex, defaultPortalList, hexToBuf, verifyRegistrySignature } from "libskynet"; | ||
import { addContextToErr, bufToHex, defaultPortalList, verifyRegistryReadResponse, } from "libskynet"; | ||
import { progressiveFetch } from "./progressivefetch.js"; | ||
// Some helper consts to make returning empty values alongside an error easier. | ||
const nu8 = new Uint8Array(0); | ||
// verifyRegReadResp will check the response body of a registry read on a | ||
// portal. The first return value indicates whether the error that gets | ||
// returned is a problem with the portal, or a problem with the underlying | ||
// registry entry. If the problem is with the portal, the caller should try the | ||
// next portal. If the problem is with the underyling registry entry, the | ||
// caller should handle the error and not try any more portals. | ||
// | ||
// The result has type 'any' because it the object was built from an untrusted | ||
// blob of json. | ||
function verifyRegReadResp(response, result, pubkey, datakey) { | ||
// Check that the response status is a 200. | ||
if (response.status !== 200) { | ||
return "unexpected response status, expecting 200"; | ||
} | ||
// Verify the reponse has all required fields. | ||
if (!("data" in result) || !("revision" in result) || !("signature" in result)) { | ||
return "response is missing fields"; | ||
} | ||
if (!(typeof result.data === "string") || | ||
!(typeof result.revision === "number") || | ||
!(typeof result.signature === "string")) { | ||
return "portal response has an invalid format"; | ||
} | ||
let revision = BigInt(result.revision); | ||
// Attempt to decode the hex values of the results. | ||
let [data, err1] = hexToBuf(result.data); | ||
if (err1 !== null) { | ||
return "could not decode registry data from result"; | ||
} | ||
let [sig, err3] = hexToBuf(result.signature); | ||
if (err3 !== null) { | ||
return "could not decode signature from result"; | ||
} | ||
// Verify the signature. | ||
if (!verifyRegistrySignature(pubkey, datakey, data, revision, sig)) { | ||
return "signature mismatch"; | ||
} | ||
// TODO: If the registry entry has type 2, the signature here | ||
// will fail even if the portal is being honest, and we will | ||
// mistakenly assume that the portal is malicious. We need to | ||
// add a check that verifies the signature of a type 2 registry | ||
// entry correctly. | ||
// Verfifcation is complete! | ||
return null; | ||
} | ||
// verifyRegistryReadResponse will verify a response from a portal to a query | ||
// to read a registry entry. | ||
function verifyRegistryReadResponse(response, pubkey, datakey) { | ||
return new Promise((resolve) => { | ||
response | ||
.json() | ||
.then((j) => { | ||
// Check whether the response is valid. The response | ||
// may be invalid in a way that indicates a | ||
// disfunctional or malicious portal, which means that | ||
// we should try another portal. Or the response may be | ||
// invalid in a way that indicates a more fundamental | ||
// error (portal is honest but the entry itself is | ||
// corrupt), and we can't make progress. | ||
let errVRRR = verifyRegReadResp(response, j, pubkey, datakey); | ||
if (errVRRR !== null) { | ||
resolve(addContextToErr(errVRRR, "registry response verification failed")); | ||
return; | ||
} | ||
resolve(null); | ||
}) | ||
.catch((err) => { | ||
resolve(addContextToErr(err, "unable to decode response body")); | ||
}); | ||
}); | ||
} | ||
// readRegistryEntry will read and verify a registry entry. The tag strings | ||
@@ -108,3 +35,3 @@ // will be hashed with the user's seed to produce the correct entropy. | ||
exists: false, | ||
data: nu8, | ||
data: new Uint8Array(0), | ||
revision: 0n, | ||
@@ -111,0 +38,0 @@ }); |
@@ -129,5 +129,2 @@ import { addContextToErr, blake2bMerkleRoot, bufToB64, defaultPortalList, encodeU64, skylinkV1Bitfield, validateSkyfileMetadata, } from "libskynet"; | ||
return new Promise((resolve) => { | ||
console.log(response); | ||
console.log(response.text); | ||
console.log(response.json); | ||
response | ||
@@ -134,0 +131,0 @@ .json() |
{ | ||
"name": "libskynetnode", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "libksynet, but the non-isomorphic functions are written for node instead of the browser", | ||
@@ -27,5 +27,5 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"libskynet": "^0.0.32", | ||
"libskynet": "^0.0.33", | ||
"node-fetch": "^3.2.6" | ||
} | ||
} |
21548
470
+ Addedlibskynet@0.0.33(transitive)
- Removedlibskynet@0.0.32(transitive)
Updatedlibskynet@^0.0.33