Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

libkernel

Package Overview
Dependencies
Maintainers
1
Versions
127
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

libkernel - npm Package Compare versions

Comparing version 0.0.63 to 0.0.64

3

dist/index.d.ts
export { blake2b } from "./blake2b.js";
export { dictionary } from "./dictionary.js";
export { ed25519Sign, ed25519Verify } from "./ed25519.js";

@@ -9,5 +10,5 @@ export { b64ToBuf, bufToB64, bufToHex, encodePrefixedBytes, encodeU64, hexToBuf } from "./encoding.js";

export { taggedRegistryEntryKeys, deriveRegistryEntryID, resolverLink } from "./registry.js";
export { generateSeedPhrase, validSeedPhrase } from "./seed.js";
export { generateSeedPhraseDeterministic, validSeedPhrase } from "./seed.js";
export { skylinkV1Bitfield } from "./skylinkbitfield.js";
export { sha512 } from "./sha512.js";
export { validateSkyfileMetadata, validateSkyfilePath } from "./skylinkvalidate.js";
export { blake2b } from "./blake2b.js";
export { dictionary } from "./dictionary.js";
export { ed25519Sign, ed25519Verify } from "./ed25519.js";

@@ -9,5 +10,5 @@ export { b64ToBuf, bufToB64, bufToHex, encodePrefixedBytes, encodeU64, hexToBuf } from "./encoding.js";

export { taggedRegistryEntryKeys, deriveRegistryEntryID, resolverLink } from "./registry.js";
export { generateSeedPhrase, validSeedPhrase } from "./seed.js";
export { generateSeedPhraseDeterministic, validSeedPhrase } from "./seed.js";
export { skylinkV1Bitfield } from "./skylinkbitfield.js";
export { sha512 } from "./sha512.js";
export { validateSkyfileMetadata, validateSkyfilePath } from "./skylinkvalidate.js";
declare const SEED_BYTES = 16;
declare function generateSeedPhraseDeterministic(password: string): [string, string | null];
declare function seedToChecksumWords(seed: Uint8Array): [string, string, string | null];
declare function validSeedPhrase(seedPhrase: string): [Uint8Array, string | null];
declare function generateSeedPhrase(password: string | null): [string, string | null];
export { generateSeedPhrase, seedToChecksumWords, validSeedPhrase, SEED_BYTES };
export { generateSeedPhraseDeterministic, seedToChecksumWords, validSeedPhrase, SEED_BYTES };

@@ -1,2 +0,1 @@

import { randomBytes } from "crypto";
import { DICTIONARY_UNIQUE_PREFIX, dictionary } from "./dictionary.js";

@@ -9,2 +8,29 @@ import { sha512 } from "./sha512.js";

const SEED_BYTES = 16;
// generateSeedPhraseDeterministic will generate and verify a seed phrase for
// the user.
function generateSeedPhraseDeterministic(password) {
let u8 = new TextEncoder().encode(password);
let buf = sha512(u8);
let randNums = Uint16Array.from(buf);
// Generate the seed phrase from the randNums.
let seedWords = [];
for (let i = 0; i < SEED_ENTROPY_WORDS; i++) {
let wordIndex = randNums[i] % dictionary.length;
seedWords.push(dictionary[wordIndex]);
}
// Convert the seedWords to a seed.
let [seed, err1] = seedWordsToSeed(seedWords);
if (err1 !== null) {
return ["", err1];
}
// Compute the checksum.
let [checksumOne, checksumTwo, err2] = seedToChecksumWords(seed);
if (err2 !== null) {
return ["", err2];
}
// Assemble the final seed phrase and set the text field.
let allWords = [...seedWords, checksumOne, checksumTwo];
let seedPhrase = allWords.join(" ");
return [seedPhrase, null];
}
// seedToChecksumWords will compute the two checksum words for the provided

@@ -22,3 +48,3 @@ // seed. The two return values are the two checksum words.

// Get the hash.
const h = sha512(seed);
let h = sha512(seed);
// Turn the hash into two words.

@@ -39,16 +65,16 @@ let word1 = h[0] << 8;

// Create a helper function to make the below code more readable.
const prefix = function (s) {
let prefix = function (s) {
return s.slice(0, DICTIONARY_UNIQUE_PREFIX);
};
// Pull the seed into its respective parts.
const seedWordsAndChecksum = seedPhrase.split(" ");
const seedWords = seedWordsAndChecksum.slice(0, SEED_ENTROPY_WORDS);
const checksumOne = seedWordsAndChecksum[SEED_ENTROPY_WORDS];
const checksumTwo = seedWordsAndChecksum[SEED_ENTROPY_WORDS + 1];
let seedWordsAndChecksum = seedPhrase.split(" ");
let seedWords = seedWordsAndChecksum.slice(0, SEED_ENTROPY_WORDS);
let checksumOne = seedWordsAndChecksum[SEED_ENTROPY_WORDS];
let checksumTwo = seedWordsAndChecksum[SEED_ENTROPY_WORDS + 1];
// Convert the seedWords to a seed.
const [seed, err1] = seedWordsToSeed(seedWords);
let [seed, err1] = seedWordsToSeed(seedWords);
if (err1 !== null) {
return [new Uint8Array(0), addContextToErr(err1, "unable to parse seed phrase")];
}
const [checksumOneVerify, checksumTwoVerify, err2] = seedToChecksumWords(seed);
let [checksumOneVerify, checksumTwoVerify, err2] = seedToChecksumWords(seed);
if (err2 !== null) {

@@ -73,3 +99,3 @@ return [new Uint8Array(0), addContextToErr(err2, "could not compute checksum words")];

// We are getting 16 bytes of entropy.
const bytes = new Uint8Array(SEED_BYTES);
let bytes = new Uint8Array(SEED_BYTES);
let curByte = 0;

@@ -95,3 +121,3 @@ let curBit = 0;

for (let j = 0; j < wordBits; j++) {
const bitSet = (word & (1 << (wordBits - j - 1))) > 0;
let bitSet = (word & (1 << (wordBits - j - 1))) > 0;
if (bitSet) {

@@ -110,42 +136,2 @@ bytes[curByte] |= 1 << (8 - curBit - 1);

}
// generateSeedPhrase will generate and verify a seed phrase for the user.
function generateSeedPhrase(password) {
let randNums;
if (password === null) {
// Get the random numbers for the seed phrase. Typically, you need to
// have code that avoids bias by checking the random results and
// re-rolling the random numbers if the result is outside of the range
// of numbers that would produce no bias. Because the search space
// (1024) evenly divides the random number space (2^16), we can skip
// this step and just use a modulus instead. The result will have no
// bias, but only because the search space is a power of 2.
const buf = randomBytes(24);
randNums = Uint16Array.from(buf);
}
else {
const u8 = new TextEncoder().encode(password);
const buf = sha512(u8);
randNums = Uint16Array.from(buf);
}
// Generate the seed phrase from the randNums.
const seedWords = [];
for (let i = 0; i < SEED_ENTROPY_WORDS; i++) {
const wordIndex = randNums[i] % dictionary.length;
seedWords.push(dictionary[wordIndex]);
}
// Convert the seedWords to a seed.
const [seed, err1] = seedWordsToSeed(seedWords);
if (err1 !== null) {
return ["", err1];
}
// Compute the checksum.
const [checksumOne, checksumTwo, err2] = seedToChecksumWords(seed);
if (err2 !== null) {
return ["", err2];
}
// Assemble the final seed phrase and set the text field.
const allWords = [...seedWords, checksumOne, checksumTwo];
const seedPhrase = allWords.join(" ");
return [seedPhrase, null];
}
export { generateSeedPhrase, seedToChecksumWords, validSeedPhrase, SEED_BYTES };
export { generateSeedPhraseDeterministic, seedToChecksumWords, validSeedPhrase, SEED_BYTES };
{
"name": "libkernel",
"version": "0.0.63",
"version": "0.0.64",
"description": "helper library to interact with skynet and the skynet kernel",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc