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

skynet-js

Package Overview
Dependencies
Maintainers
2
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

skynet-js - npm Package Compare versions

Comparing version 2.6.0 to 2.7.0

11

CHANGELOG.md
# Changelog
## [2.7.0]
_Note: this version contains breaking changes to `deriveChildSeed`._
### Changed
- Fix `deriveChildSeed` bugs. It will now return hex-encoded strings. Note that it will now return different values than before these bugs were fixed.
- Fix `setJSON` function not using hex-encoded publickeys when making its request.
- Do not use a timeout for `setEntry` by default (was 5s previously).
- Fix a bug when calling `setJSON` with `revision = 0` where `setJSON` would fetch the latest revision anyway.
## [2.6.0]

@@ -4,0 +15,0 @@

2

dist/crypto.d.ts

@@ -6,3 +6,3 @@ import { pki } from "node-forge";

export declare type Signature = pki.ed25519.NativeBuffer;
export declare function hashAll(...args: any[]): Uint8Array;
export declare function hashAll(...args: Uint8Array[]): Uint8Array;
export declare function hashDataKey(datakey: string): Uint8Array;

@@ -9,0 +9,0 @@ export declare function hashRegistryEntry(registryEntry: RegistryEntry): Uint8Array;

@@ -22,3 +22,2 @@ "use strict";

var randombytes_1 = __importDefault(require("randombytes"));
var buffer_1 = require("buffer");
// Returns a blake2b 256bit hasher. See `NewHash` in Sia.

@@ -69,3 +68,3 @@ function newHash() {

function deriveChildSeed(masterSeed, seed) {
return hashAll(masterSeed, seed).toString();
return utils_1.toHexString(hashAll(encodeString(masterSeed), encodeString(seed)));
}

@@ -91,3 +90,3 @@ exports.deriveChildSeed = deriveChildSeed;

var _a = node_forge_1.pki.ed25519.generateKeyPair({ seed: seed }), publicKey = _a.publicKey, privateKey = _a.privateKey;
return { publicKey: buffer_1.Buffer.from(publicKey).toString("hex"), privateKey: buffer_1.Buffer.from(privateKey).toString("hex") };
return { publicKey: utils_1.toHexString(publicKey), privateKey: utils_1.toHexString(privateKey) };
}

@@ -99,3 +98,3 @@ exports.genKeyPairFromSeed = genKeyPairFromSeed;

var array = randombytes_1["default"](length);
return buffer_1.Buffer.from(array).toString("hex");
return utils_1.toHexString(array);
}

@@ -55,3 +55,4 @@ "use strict";

var crypto_1 = require("./crypto");
var defaultRegistryOptions = __assign(__assign({}, utils_1.defaultOptions("/skynet/registry")), { timeout: 5000 });
var defaultGetEntryOptions = __assign(__assign({}, utils_1.defaultOptions("/skynet/registry")), { timeout: 5000 });
var defaultSetEntryOptions = __assign({}, utils_1.defaultOptions("/skynet/registry"));
/**

@@ -71,3 +72,3 @@ * Gets the registry entry corresponding to the publicKey and dataKey.

case 0:
opts = __assign(__assign(__assign({}, defaultRegistryOptions), this.customOptions), customOptions);
opts = __assign(__assign(__assign({}, defaultGetEntryOptions), this.customOptions), customOptions);
publicKeyBuffer = buffer_1.Buffer.from(publicKey, "hex");

@@ -79,3 +80,3 @@ _a.label = 1;

publickey: "ed25519:" + publicKey,
datakey: buffer_1.Buffer.from(crypto_1.hashDataKey(dataKey)).toString("hex")
datakey: utils_1.toHexString(crypto_1.hashDataKey(dataKey))
}, timeout: opts.timeout }))];

@@ -118,6 +119,6 @@ case 2:

if (customOptions === void 0) { customOptions = {}; }
var opts = __assign(__assign(__assign({}, defaultRegistryOptions), this.customOptions), customOptions);
var opts = __assign(__assign(__assign({}, defaultGetEntryOptions), this.customOptions), customOptions);
var query = {
publickey: "ed25519:" + publicKey,
datakey: buffer_1.Buffer.from(crypto_1.hashDataKey(dataKey)).toString("hex")
datakey: utils_1.toHexString(crypto_1.hashDataKey(dataKey))
};

@@ -132,7 +133,7 @@ var url = utils_1.makeUrl(this.portalUrl, opts.endpointPath);

return __awaiter(this, void 0, void 0, function () {
var opts, privateKeyBuffer, signature, publickey, data;
var opts, privateKeyBuffer, signature, publicKeyBuffer, data;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
opts = __assign(__assign(__assign({}, defaultRegistryOptions), this.customOptions), customOptions);
opts = __assign(__assign(__assign({}, defaultSetEntryOptions), this.customOptions), customOptions);
privateKeyBuffer = buffer_1.Buffer.from(privateKey, "hex");

@@ -143,9 +144,9 @@ signature = node_forge_1.pki.ed25519.sign({

});
publickey = node_forge_1.pki.ed25519.publicKeyFromPrivateKey({ privateKey: privateKeyBuffer });
publicKeyBuffer = node_forge_1.pki.ed25519.publicKeyFromPrivateKey({ privateKey: privateKeyBuffer });
data = {
publickey: {
algorithm: "ed25519",
key: Array.from(publickey)
key: Array.from(publicKeyBuffer)
},
datakey: buffer_1.Buffer.from(crypto_1.hashDataKey(entry.datakey)).toString("hex"),
datakey: utils_1.toHexString(crypto_1.hashDataKey(entry.datakey)),
revision: entry.revision,

@@ -152,0 +153,0 @@ data: Array.from(buffer_1.Buffer.from(entry.data)),

@@ -13,3 +13,6 @@ import { SkynetClient } from "./client";

} | null>;
/**
* Sets a JSON object at the registry entry corresponding to the publicKey and dataKey.
*/
export declare function setJSON(this: SkynetClient, privateKey: string, dataKey: string, json: Record<string, unknown>, revision?: number, customOptions?: {}): Promise<void>;
//# sourceMappingURL=skydb.d.ts.map

@@ -53,2 +53,3 @@ "use strict";

var utils_1 = require("./utils");
var buffer_1 = require("buffer");
/**

@@ -85,2 +86,5 @@ * Gets the JSON object corresponding to the publicKey and dataKey.

exports.getJSON = getJSON;
/**
* Sets a JSON object at the registry entry corresponding to the publicKey and dataKey.
*/
function setJSON(privateKey, dataKey, json, revision, customOptions) {

@@ -94,3 +98,3 @@ if (customOptions === void 0) { customOptions = {}; }

opts = __assign(__assign({}, this.customOptions), customOptions);
privateKeyBuffer = Buffer.from(privateKey, "hex");
privateKeyBuffer = buffer_1.Buffer.from(privateKey, "hex");
file = new File([JSON.stringify(json)], dataKey, { type: "application/json" });

@@ -100,3 +104,3 @@ return [4 /*yield*/, this.uploadFileRequest(file, opts)];

skylink = (_a.sent()).skylink;
if (!!revision) return [3 /*break*/, 5];
if (!(revision === undefined)) return [3 /*break*/, 5];
_a.label = 2;

@@ -106,3 +110,3 @@ case 2:

publicKey = node_forge_1.pki.ed25519.publicKeyFromPrivateKey({ privateKey: privateKeyBuffer });
return [4 /*yield*/, this.registry.getEntry(publicKey, dataKey, opts)];
return [4 /*yield*/, this.registry.getEntry(utils_1.toHexString(publicKey), dataKey, opts)];
case 3:

@@ -109,0 +113,0 @@ entry_1 = _a.sent();

@@ -24,2 +24,7 @@ export declare const defaultSkynetPortalUrl = "https://siasky.net";

export declare function hexToUint8Array(str: string): Uint8Array;
/**
* Convert a byte array to a hex string.
* From https://stackoverflow.com/a/44608819.
*/
export declare function toHexString(byteArray: Uint8Array): string;
export declare function readData(file: File): Promise<string | ArrayBuffer>;

@@ -26,0 +31,0 @@ /**

@@ -13,3 +13,3 @@ "use strict";

exports.__esModule = true;
exports.getFileMimeType = exports.readData = exports.hexToUint8Array = exports.stringToUint8Array = exports.randomNumber = exports.trimUriPrefix = exports.parseSkylink = exports.makeUrl = exports.getRootDirectory = exports.getRelativeFilePath = exports.defaultPortalUrl = exports.defaultOptions = exports.addUrlQuery = exports.uriSkynetPrefix = exports.uriHandshakeResolverPrefix = exports.uriHandshakePrefix = exports.defaultSkynetPortalUrl = void 0;
exports.getFileMimeType = exports.readData = exports.toHexString = exports.hexToUint8Array = exports.stringToUint8Array = exports.randomNumber = exports.trimUriPrefix = exports.parseSkylink = exports.makeUrl = exports.getRootDirectory = exports.getRelativeFilePath = exports.defaultPortalUrl = exports.defaultOptions = exports.addUrlQuery = exports.uriSkynetPrefix = exports.uriHandshakeResolverPrefix = exports.uriHandshakePrefix = exports.defaultSkynetPortalUrl = void 0;
var mime_db_1 = __importDefault(require("mime-db"));

@@ -116,3 +116,3 @@ var path_browserify_1 = __importDefault(require("path-browserify"));

exports.randomNumber = randomNumber;
// stringToUint8Array converts a string to a uint8 array
// Converts a string to a uint8 array
function stringToUint8Array(str) {

@@ -122,3 +122,3 @@ return Uint8Array.from(buffer_1.Buffer.from(str));

exports.stringToUint8Array = stringToUint8Array;
// hexToUint8Array converts a hex encoded string to a uint8 array
// Converts a hex encoded string to a uint8 array
function hexToUint8Array(str) {

@@ -128,4 +128,16 @@ return new Uint8Array(str.match(/.{1,2}/g).map(function (byte) { return parseInt(byte, 16); }));

exports.hexToUint8Array = hexToUint8Array;
// readData is a helper function that uses a FileReader to read the contents of
// the given file
/**
* Convert a byte array to a hex string.
* From https://stackoverflow.com/a/44608819.
*/
function toHexString(byteArray) {
var s = "";
byteArray.forEach(function (byte) {
s += ("0" + (byte & 0xff).toString(16)).slice(-2);
});
return s;
}
exports.toHexString = toHexString;
// A helper function that uses a FileReader to read the contents of the given
// file
function readData(file) {

@@ -132,0 +144,0 @@ return new Promise(function (resolve, reject) {

{
"name": "skynet-js",
"version": "2.6.0",
"version": "2.7.0",
"description": "Sia Skynet Javascript Client",

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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