Comparing version 0.0.58 to 0.0.59
@@ -0,1 +1,3 @@ | ||
import { bufToB64 } from "./encoding.js"; | ||
import { sha512 } from "./sha512.js"; | ||
// namespaceInode is a function for namespacing inodes based on the type of | ||
@@ -7,5 +9,7 @@ // file that is being used, this way a file that is created using | ||
// files on Skynet. | ||
// | ||
// No cryptography is needed here, the inodes don't get exposed publicly. | ||
function namespaceInode(filetype, inode) { | ||
// We pad out the filetype to 32 characters to ensure that two different | ||
// filetypes can never have a filetype+inode combination that will collide. | ||
// If the filetype is different, the final result will definitely also be | ||
// different. | ||
if (filetype.length > 32) { | ||
@@ -15,6 +19,15 @@ return ["", "filetype can be at most 32 characters"]; | ||
while (filetype.length < 32) { | ||
filetype += "__"; | ||
filetype += "_"; | ||
} | ||
return [filetype + inode, null]; | ||
// Add the inode to the extended filetype. | ||
filetype += inode; | ||
// We hash the result to make it smaller. Because we use this as an | ||
// encryption key and not for authentication, our security model only | ||
// requires 16 bits of entropy. We therefore only take the first 16 bytes | ||
// of the hash and return the base64 encoded string. | ||
const fullHash = sha512(new TextEncoder().encode(filetype + inode)); | ||
const quarterHash = fullHash.slice(0, 16); | ||
const b64 = bufToB64(quarterHash); | ||
return [b64, null]; | ||
} | ||
export { namespaceInode }; |
{ | ||
"name": "libskynet", | ||
"version": "0.0.58", | ||
"version": "0.0.59", | ||
"author": "Skynet Labs", | ||
@@ -5,0 +5,0 @@ "description": "helper library to interact with skynet's low level primitives", |
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
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
187631
5507