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.4.0 to 2.5.0

11

CHANGELOG.md
# Changelog
## [2.5.0]
_Note: this version contains breaking changes in the SkyDB and Registry APIs._
### Changed
- Rename `keyPairFromSeed` to `genKeyPairFromSeed` and have it return keys in the form of hex strings.
- Rename `generateKeyPairAndSeed` to `genKeyPairAndSeed` and have it return keys in the form of hex strings.
- Use hex strings as keys as inputs to `getJSON`, `setJSON`, `getEntry`, and `setEntry`.
- `setEntry` no longer takes a `datakey` argument as it is already in `entry`.
## [2.4.0]

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

18

dist/crypto.d.ts

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

export declare type Signature = pki.ed25519.NativeBuffer;
export declare function HashAll(...args: any[]): Uint8Array;
export declare function HashDataKey(datakey: string): Uint8Array;
export declare function HashRegistryEntry(registryEntry: RegistryEntry): Uint8Array;
export declare function hashAll(...args: any[]): Uint8Array;
export declare function hashDataKey(datakey: string): Uint8Array;
export declare function hashRegistryEntry(registryEntry: RegistryEntry): Uint8Array;
export declare function deriveChildSeed(masterSeed: string, seed: string): string;

@@ -15,5 +15,5 @@ /**

*/
export declare function generateKeyPairAndSeed(length?: number): {
publicKey: PublicKey;
privateKey: SecretKey;
export declare function genKeyPairAndSeed(length?: number): {
publicKey: string;
privateKey: string;
seed: string;

@@ -25,6 +25,6 @@ };

*/
export declare function keyPairFromSeed(seed: string): {
publicKey: PublicKey;
privateKey: SecretKey;
export declare function genKeyPairFromSeed(seed: string): {
publicKey: string;
privateKey: string;
};
//# sourceMappingURL=crypto.d.ts.map

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

exports.__esModule = true;
exports.keyPairFromSeed = exports.generateKeyPairAndSeed = exports.deriveChildSeed = exports.HashRegistryEntry = exports.HashDataKey = exports.HashAll = void 0;
exports.genKeyPairFromSeed = exports.genKeyPairAndSeed = exports.deriveChildSeed = exports.hashRegistryEntry = exports.hashDataKey = exports.hashAll = void 0;
var node_forge_1 = require("node-forge");

@@ -23,8 +23,8 @@ var blakejs_1 = __importDefault(require("blakejs"));

var randombytes_1 = __importDefault(require("randombytes"));
// NewHash returns a blake2b 256bit hasher.
function NewHash() {
// Returns a blake2b 256bit hasher. See `NewHash` in Sia.
function newHash() {
return blakejs_1["default"].blake2bInit(32, null);
}
// HashAll takes all given arguments and hashes them.
function HashAll() {
// Takes all given arguments and hashes them.
function hashAll() {
var args = [];

@@ -34,20 +34,20 @@ for (var _i = 0; _i < arguments.length; _i++) {

}
var h = NewHash();
var hasher = newHash();
for (var i = 0; i < args.length; i++) {
blakejs_1["default"].blake2bUpdate(h, args[i]);
blakejs_1["default"].blake2bUpdate(hasher, args[i]);
}
return blakejs_1["default"].blake2bFinal(h);
return blakejs_1["default"].blake2bFinal(hasher);
}
exports.HashAll = HashAll;
exports.hashAll = hashAll;
// Hash the given data key.
function HashDataKey(datakey) {
return HashAll(encodeString(datakey));
function hashDataKey(datakey) {
return hashAll(encodeString(datakey));
}
exports.HashDataKey = HashDataKey;
exports.hashDataKey = hashDataKey;
// Hashes the given registry entry.
function HashRegistryEntry(registryEntry) {
return HashAll(HashDataKey(registryEntry.datakey), encodeString(registryEntry.data), encodeNumber(registryEntry.revision));
function hashRegistryEntry(registryEntry) {
return hashAll(hashDataKey(registryEntry.datakey), encodeString(registryEntry.data), encodeNumber(registryEntry.revision));
}
exports.HashRegistryEntry = HashRegistryEntry;
// encodeNumber converts the given number into a uint8 array
exports.hashRegistryEntry = hashRegistryEntry;
// Converts the given number into a uint8 array
function encodeNumber(num) {

@@ -62,3 +62,3 @@ var encoded = new Uint8Array(8);

}
// encodeString converts the given string into a uint8 array
// Converts the given string into a uint8 array
function encodeString(str) {

@@ -71,3 +71,3 @@ var encoded = new Uint8Array(8 + str.length);

function deriveChildSeed(masterSeed, seed) {
return HashAll(masterSeed, seed).toString();
return hashAll(masterSeed, seed).toString();
}

@@ -79,8 +79,8 @@ exports.deriveChildSeed = deriveChildSeed;

*/
function generateKeyPairAndSeed(length) {
function genKeyPairAndSeed(length) {
if (length === void 0) { length = 64; }
var seed = makeSeed(length);
return __assign(__assign({}, keyPairFromSeed(seed)), { seed: seed });
return __assign(__assign({}, genKeyPairFromSeed(seed)), { seed: seed });
}
exports.generateKeyPairAndSeed = generateKeyPairAndSeed;
exports.genKeyPairAndSeed = genKeyPairAndSeed;
/**

@@ -90,8 +90,9 @@ * Generates a public and private key from a provided, secure seed.

*/
function keyPairFromSeed(seed) {
function genKeyPairFromSeed(seed) {
// Get a 32-byte seed.
seed = node_forge_1.pkcs5.pbkdf2(seed, "", 1000, 32, node_forge_1.md.sha256.create());
return node_forge_1.pki.ed25519.generateKeyPair({ seed: seed });
var _a = node_forge_1.pki.ed25519.generateKeyPair({ seed: seed }), publicKey = _a.publicKey, privateKey = _a.privateKey;
return { publicKey: publicKey.toString("hex"), privateKey: privateKey.toString("hex") };
}
exports.keyPairFromSeed = keyPairFromSeed;
exports.genKeyPairFromSeed = genKeyPairFromSeed;
function makeSeed(length) {

@@ -98,0 +99,0 @@ // Cryptographically-secure random number generator. It should use the

export { SkynetClient } from "./client";
export { deriveChildSeed, generateKeyPairAndSeed, keyPairFromSeed } from "./crypto";
export { deriveChildSeed, genKeyPairAndSeed, genKeyPairFromSeed } from "./crypto";
export type { PublicKey, SecretKey, Signature } from "./crypto";

@@ -4,0 +4,0 @@ export type { SignedRegistryEntry, RegistryEntry } from "./registry";

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

exports.__esModule = true;
exports.uriSkynetPrefix = exports.uriHandshakeResolverPrefix = exports.uriHandshakePrefix = exports.parseSkylink = exports.getRootDirectory = exports.getRelativeFilePath = exports.defaultSkynetPortalUrl = exports.defaultPortalUrl = exports.keyPairFromSeed = exports.generateKeyPairAndSeed = exports.deriveChildSeed = exports.SkynetClient = void 0;
exports.uriSkynetPrefix = exports.uriHandshakeResolverPrefix = exports.uriHandshakePrefix = exports.parseSkylink = exports.getRootDirectory = exports.getRelativeFilePath = exports.defaultSkynetPortalUrl = exports.defaultPortalUrl = exports.genKeyPairFromSeed = exports.genKeyPairAndSeed = exports.deriveChildSeed = exports.SkynetClient = void 0;
var client_1 = require("./client");

@@ -16,4 +16,4 @@ __createBinding(exports, client_1, "SkynetClient");

__createBinding(exports, crypto_1, "deriveChildSeed");
__createBinding(exports, crypto_1, "generateKeyPairAndSeed");
__createBinding(exports, crypto_1, "keyPairFromSeed");
__createBinding(exports, crypto_1, "genKeyPairAndSeed");
__createBinding(exports, crypto_1, "genKeyPairFromSeed");
var utils_1 = require("./utils");

@@ -20,0 +20,0 @@ __createBinding(exports, utils_1, "defaultPortalUrl");

import { SkynetClient } from "./client";
import { PublicKey, SecretKey, Signature } from "./crypto";
import { Signature } from "./crypto";
export declare type RegistryEntry = {

@@ -19,4 +19,4 @@ datakey: string;

*/
export declare function getEntry(this: SkynetClient, publicKey: PublicKey, datakey: string, customOptions?: {}): Promise<SignedRegistryEntry | null>;
export declare function setEntry(this: SkynetClient, privateKey: SecretKey, datakey: string, entry: RegistryEntry, customOptions?: {}): Promise<void>;
export declare function getEntry(this: SkynetClient, publicKey: string, dataKey: string, customOptions?: {}): Promise<SignedRegistryEntry | null>;
export declare function setEntry(this: SkynetClient, privateKey: string, entry: RegistryEntry, customOptions?: {}): Promise<void>;
//# sourceMappingURL=registry.d.ts.map

@@ -63,6 +63,6 @@ "use strict";

*/
function getEntry(publicKey, datakey, customOptions) {
function getEntry(publicKey, dataKey, customOptions) {
if (customOptions === void 0) { customOptions = {}; }
return __awaiter(this, void 0, void 0, function () {
var opts, response, err_1, entry;
var opts, publicKeyBuffer, response, err_1, entry;
return __generator(this, function (_a) {

@@ -72,2 +72,3 @@ switch (_a.label) {

opts = __assign(__assign(__assign({}, defaultRegistryOptions), this.customOptions), customOptions);
publicKeyBuffer = buffer_1.Buffer.from(publicKey, "hex");
_a.label = 1;

@@ -77,4 +78,4 @@ case 1:

return [4 /*yield*/, this.executeRequest(__assign(__assign({}, opts), { method: "get", query: {
publickey: "ed25519:" + buffer_1.Buffer.from(publicKey).toString("hex"),
datakey: buffer_1.Buffer.from(crypto_1.HashDataKey(datakey)).toString("hex")
publickey: "ed25519:" + publicKey,
datakey: buffer_1.Buffer.from(crypto_1.hashDataKey(dataKey)).toString("hex")
}, timeout: opts.timeout }))];

@@ -87,10 +88,10 @@ case 2:

// unfortunately axios rejects anything that's not >= 200 and < 300
return [2 /*return*/, null];
return [2 /*return*/, { entry: null, signature: null }];
case 4:
if (response.status !== 200) {
return [2 /*return*/, null];
return [2 /*return*/, { entry: null, signature: null }];
}
entry = {
entry: {
datakey: datakey,
datakey: dataKey,
data: buffer_1.Buffer.from(utils_1.hexToUint8Array(response.data.data)).toString(),

@@ -104,5 +105,5 @@ // TODO: Handle uint64 properly.

!node_forge_1.pki.ed25519.verify({
message: crypto_1.HashRegistryEntry(entry.entry),
message: crypto_1.hashRegistryEntry(entry.entry),
signature: entry.signature,
publicKey: publicKey
publicKey: publicKeyBuffer
})) {

@@ -117,6 +118,6 @@ throw new Error("could not verify signature from retrieved, signed registry entry -- possible corrupted entry");

exports.getEntry = getEntry;
function setEntry(privateKey, datakey, entry, customOptions) {
function setEntry(privateKey, entry, customOptions) {
if (customOptions === void 0) { customOptions = {}; }
return __awaiter(this, void 0, void 0, function () {
var opts, signature, publickey, data;
var opts, privateKeyBuffer, signature, publickey, data;
return __generator(this, function (_a) {

@@ -126,7 +127,8 @@ switch (_a.label) {

opts = __assign(__assign(__assign({}, defaultRegistryOptions), this.customOptions), customOptions);
privateKeyBuffer = buffer_1.Buffer.from(privateKey, "hex");
signature = node_forge_1.pki.ed25519.sign({
message: crypto_1.HashRegistryEntry(entry),
privateKey: privateKey
message: crypto_1.hashRegistryEntry(entry),
privateKey: privateKeyBuffer
});
publickey = node_forge_1.pki.ed25519.publicKeyFromPrivateKey({ privateKey: privateKey });
publickey = node_forge_1.pki.ed25519.publicKeyFromPrivateKey({ privateKey: privateKeyBuffer });
data = {

@@ -137,3 +139,3 @@ publickey: {

},
datakey: buffer_1.Buffer.from(crypto_1.HashDataKey(datakey)).toString("hex"),
datakey: buffer_1.Buffer.from(crypto_1.hashDataKey(entry.datakey)).toString("hex"),
revision: entry.revision,

@@ -140,0 +142,0 @@ data: Array.from(buffer_1.Buffer.from(entry.data)),

import { SkynetClient } from "./client";
import { PublicKey, SecretKey } from "./crypto";
/**

@@ -10,7 +9,7 @@ * Gets the JSON object corresponding to the publicKey and dataKey.

*/
export declare function getJSON(this: SkynetClient, publicKey: PublicKey, dataKey: string, customOptions?: {}): Promise<{
export declare function getJSON(this: SkynetClient, publicKey: string, dataKey: string, customOptions?: {}): Promise<{
data: Record<string, unknown>;
revision: number;
} | null>;
export declare function setJSON(this: SkynetClient, privateKey: SecretKey, dataKey: string, json: Record<string, unknown>, revision?: number, customOptions?: {}): Promise<void>;
export declare function setJSON(this: SkynetClient, privateKey: string, dataKey: string, json: Record<string, unknown>, revision?: number, customOptions?: {}): Promise<void>;
//# sourceMappingURL=skydb.d.ts.map

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

return __awaiter(this, void 0, void 0, function () {
var opts, file, skylink, entry_1, publicKey, err_1, entry;
var opts, privateKeyBuffer, file, skylink, entry_1, publicKey, err_1, entry;
return __generator(this, function (_a) {

@@ -93,2 +93,3 @@ switch (_a.label) {

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

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

_a.trys.push([2, 4, , 5]);
publicKey = node_forge_1.pki.ed25519.publicKeyFromPrivateKey({ privateKey: privateKey });
publicKey = node_forge_1.pki.ed25519.publicKeyFromPrivateKey({ privateKey: privateKeyBuffer });
return [4 /*yield*/, this.registry.getEntry(publicKey, dataKey, opts)];

@@ -120,3 +121,3 @@ case 3:

// update the registry
return [4 /*yield*/, this.registry.setEntry(privateKey, dataKey, entry)];
return [4 /*yield*/, this.registry.setEntry(privateKey, entry)];
case 6:

@@ -123,0 +124,0 @@ // update the registry

{
"name": "skynet-js",
"version": "2.4.0",
"version": "2.5.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