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

libskynet

Package Overview
Dependencies
Maintainers
1
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

libskynet - npm Package Compare versions

Comparing version 0.0.27 to 0.0.28

2

dist/defaultportals.js

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

const defaultPortalList = ["siasky.net", "eu-ger-12.siasky.net", "web3portal.com", "siasky.dev"];
const defaultPortalList = ["https://siasky.net", "https://web3portal.com", "https://siasky.dev"];
export { defaultPortalList };

@@ -24,3 +24,3 @@ import { tryStringify } from "./stringifytry.js";

let portal = pfm.remainingPortals.shift();
let query = "https://" + portal + pfm.endpoint;
let query = portal + pfm.endpoint;
// Create a helper function for trying the next portal.

@@ -27,0 +27,0 @@ let nextPortal = function (response, log) {

import { ed25519Keypair } from "./ed25519.js";
declare function taggedRegistryEntryKeys(seed: Uint8Array, keypairTagStr: string, datakeyTagStr: string): [ed25519Keypair, Uint8Array, string | null];
import { error } from "./types.js";
declare function computeRegistrySignature(secretKey: Uint8Array, dataKey: Uint8Array, data: Uint8Array, revision: bigint): [signature: Uint8Array, encodedData: Uint8Array, err: error];
declare function deriveRegistryEntryID(pubkey: Uint8Array, datakey: Uint8Array): [Uint8Array, string | null];
declare function entryIDToSkylink(entryID: Uint8Array): string;
declare function resolverLink(entryID: Uint8Array): [string, string | null];
declare function taggedRegistryEntryKeys(seed: Uint8Array, keypairTagStr: string, datakeyTagStr?: string): [ed25519Keypair, Uint8Array, string | null];
declare function verifyRegistrySignature(pubkey: Uint8Array, datakey: Uint8Array, data: Uint8Array, revision: bigint, sig: Uint8Array): boolean;
export { taggedRegistryEntryKeys, deriveRegistryEntryID, resolverLink, verifyRegistrySignature };
export { computeRegistrySignature, deriveRegistryEntryID, entryIDToSkylink, resolverLink, taggedRegistryEntryKeys, verifyRegistrySignature, };
import { blake2b } from "./blake2b.js";
import { bufToB64, encodePrefixedBytes, encodeU64 } from "./encoding.js";
import { addContextToErr } from "./err.js";
import { ed25519KeypairFromEntropy, ed25519Verify } from "./ed25519.js";
import { ed25519KeypairFromEntropy, ed25519Sign, ed25519Verify } from "./ed25519.js";
import { SEED_BYTES } from "./seed.js";

@@ -10,2 +10,86 @@ import { sha512 } from "./sha512.js";

const nkp = { publicKey: nu8, secretKey: nu8 };
// computeRegistrySignature will take a secret key and the required fields of a
// registry entry and use them to compute a registry signature, returning both
// the signature and the encoded data for the registry entry.
function computeRegistrySignature(secretKey, dataKey, data, revision) {
// Check that the data is the right size.
if (data.length > 86) {
return [nu8, nu8, "registry data must be at most 86 bytes"];
}
// Build the encoded data.
let [encodedData, errEPB] = encodePrefixedBytes(data);
if (errEPB !== null) {
return [nu8, nu8, addContextToErr(errEPB, "unable to encode provided registry data")];
}
let [encodedRevision, errEU64] = encodeU64(revision);
if (errEU64 !== null) {
return [nu8, nu8, addContextToErr(errEU64, "unable to encode the revision number")];
}
// Build the signing data.
let dataToSign = new Uint8Array(32 + 8 + data.length + 8);
dataToSign.set(dataKey, 0);
dataToSign.set(encodedData, 32);
dataToSign.set(encodedRevision, 32 + 8 + data.length);
let sigHash = blake2b(dataToSign);
// Sign the data.
let [sig, errS] = ed25519Sign(sigHash, secretKey);
if (errS !== null) {
return [nu8, nu8, addContextToErr(errS, "unable to sign registry entry")];
}
return [sig, encodedData, null];
}
// deriveRegistryEntryID derives a registry entry ID from a provided pubkey and
// datakey.
function deriveRegistryEntryID(pubkey, datakey) {
// Check the lengths of the inputs.
if (pubkey.length !== 32) {
return [nu8, "pubkey is invalid, length is wrong"];
}
if (datakey.length !== 32) {
return [nu8, "datakey is not a valid hash, length is wrong"];
}
// Establish the encoding. First 16 bytes is a specifier, second 8
// bytes declares the length of the pubkey, the next 32 bytes is the
// pubkey and the final 32 bytes is the datakey. This encoding is
// determined by the Sia protocol.
let encoding = new Uint8Array(16 + 8 + 32 + 32);
// Set the specifier.
encoding[0] = "e".charCodeAt(0);
encoding[1] = "d".charCodeAt(0);
encoding[2] = "2".charCodeAt(0);
encoding[3] = "5".charCodeAt(0);
encoding[4] = "5".charCodeAt(0);
encoding[5] = "1".charCodeAt(0);
encoding[6] = "9".charCodeAt(0);
// Set the pubkey.
let [encodedLen, errU64] = encodeU64(32n);
if (errU64 !== null) {
return [nu8, addContextToErr(errU64, "unable to encode pubkey length")];
}
encoding.set(encodedLen, 16);
encoding.set(pubkey, 16 + 8);
encoding.set(datakey, 16 + 8 + 32);
// Get the final ID by hashing the encoded data.
let id = blake2b(encoding);
return [id, null];
}
// entryIDToSkylink converts a registry entry id to a resolver skylink.
function entryIDToSkylink(entryID) {
let v2Skylink = new Uint8Array(34);
v2Skylink.set(entryID, 2);
v2Skylink[0] = 1;
return bufToB64(v2Skylink);
}
// resolverLink will take a registryEntryID and return the corresponding
// resolver link.
function resolverLink(entryID) {
if (entryID.length !== 32) {
return ["", "provided entry ID has the wrong length"];
}
let v2Skylink = new Uint8Array(34);
v2Skylink.set(entryID, 2);
v2Skylink[0] = 1;
let skylink = bufToB64(v2Skylink);
return [skylink, null];
}
// registryEntryKeys will use the user's seed to derive a keypair and a datakey

@@ -30,2 +114,6 @@ // using the provided seed and tags. The keypairTag is a tag which salts the

}
// If no datakey tag was provided, use the empty string.
if (datakeyTagStr === undefined) {
datakeyTagStr = "";
}
// Generate a unique set of entropy using the seed and keypairTag.

@@ -64,49 +152,2 @@ let keypairTag = new TextEncoder().encode(keypairTagStr);

}
// deriveRegistryEntryID derives a registry entry ID from a provided pubkey and
// datakey.
function deriveRegistryEntryID(pubkey, datakey) {
// Check the lengths of the inputs.
if (pubkey.length !== 32) {
return [nu8, "pubkey is invalid, length is wrong"];
}
if (datakey.length !== 32) {
return [nu8, "datakey is not a valid hash, length is wrong"];
}
// Establish the encoding. First 16 bytes is a specifier, second 8
// bytes declares the length of the pubkey, the next 32 bytes is the
// pubkey and the final 32 bytes is the datakey. This encoding is
// determined by the Sia protocol.
let encoding = new Uint8Array(16 + 8 + 32 + 32);
// Set the specifier.
encoding[0] = "e".charCodeAt(0);
encoding[1] = "d".charCodeAt(0);
encoding[2] = "2".charCodeAt(0);
encoding[3] = "5".charCodeAt(0);
encoding[4] = "5".charCodeAt(0);
encoding[5] = "1".charCodeAt(0);
encoding[6] = "9".charCodeAt(0);
// Set the pubkey.
let [encodedLen, errU64] = encodeU64(32n);
if (errU64 !== null) {
return [nu8, addContextToErr(errU64, "unable to encode pubkey length")];
}
encoding.set(encodedLen, 16);
encoding.set(pubkey, 16 + 8);
encoding.set(datakey, 16 + 8 + 32);
// Get the final ID by hashing the encoded data.
let id = blake2b(encoding);
return [id, null];
}
// resolverLink will take a registryEntryID and return the corresponding
// resolver link.
function resolverLink(entryID) {
if (entryID.length !== 32) {
return ["", "provided entry ID has the wrong length"];
}
let v2Skylink = new Uint8Array(34);
v2Skylink.set(entryID, 2);
v2Skylink[0] = 1;
let skylink = bufToB64(v2Skylink);
return [skylink, null];
}
// verifyRegistrySignature will verify the signature of a registry entry.

@@ -129,2 +170,2 @@ function verifyRegistrySignature(pubkey, datakey, data, revision, sig) {

}
export { taggedRegistryEntryKeys, deriveRegistryEntryID, resolverLink, verifyRegistrySignature };
export { computeRegistrySignature, deriveRegistryEntryID, entryIDToSkylink, resolverLink, taggedRegistryEntryKeys, verifyRegistrySignature, };
declare const SEED_BYTES = 16;
declare function deriveChildSeed(parentSeed: Uint8Array, derivationTag: string): Uint8Array;
declare function generateSeedPhraseDeterministic(password: string): [string, string | null];

@@ -6,2 +7,2 @@ declare function seedToChecksumWords(seed: Uint8Array): [string, string, string | null];

declare function seedPhraseToSeed(seedPhrase: string): [Uint8Array, string | null];
export { generateSeedPhraseDeterministic, seedToChecksumWords, seedPhraseToSeed, validSeedPhrase, SEED_BYTES };
export { deriveChildSeed, generateSeedPhraseDeterministic, seedToChecksumWords, seedPhraseToSeed, validSeedPhrase, SEED_BYTES, };

@@ -8,2 +8,10 @@ import { DICTIONARY_UNIQUE_PREFIX, dictionary } from "./dictionary.js";

const SEED_BYTES = 16;
// deriveChildSeed is a helper function to derive a child seed from a parent
// seed using a string as the path.
function deriveChildSeed(parentSeed, derivationTag) {
let u8 = new TextEncoder().encode(" - " + derivationTag);
let preimage = new Uint8Array(parentSeed.length + u8.length);
let hash = sha512(preimage);
return hash.slice(0, SEED_BYTES);
}
// generateSeedPhraseDeterministic will generate and verify a seed phrase for

@@ -141,2 +149,2 @@ // the user.

}
export { generateSeedPhraseDeterministic, seedToChecksumWords, seedPhraseToSeed, validSeedPhrase, SEED_BYTES };
export { deriveChildSeed, generateSeedPhraseDeterministic, seedToChecksumWords, seedPhraseToSeed, validSeedPhrase, SEED_BYTES, };
{
"name": "libskynet",
"version": "0.0.27",
"version": "0.0.28",
"description": "helper library to interact with skynet's low level primitives",

@@ -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