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

skynet-js

Package Overview
Dependencies
Maintainers
3
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 4.0.7-beta to 4.0.8-beta

dist/cjs/utils/array.d.ts

3

dist/cjs/client.d.ts

@@ -76,6 +76,9 @@ import { AxiosResponse } from "axios";

getJSON: (userID: string, path: string, customOptions?: import("./skydb").CustomGetJSONOptions | undefined) => Promise<import("./skydb").JSONResponse>;
getEntryLink: (userID: string, path: string) => Promise<string>;
};
db: {
deleteJSON: (privateKey: string, dataKey: string, customOptions?: import("./skydb").CustomSetJSONOptions | undefined) => Promise<void>;
getJSON: (publicKey: string, dataKey: string, customOptions?: import("./skydb").CustomGetJSONOptions | undefined) => Promise<import("./skydb").JSONResponse>;
setJSON: (privateKey: string, dataKey: string, json: import("./skydb").JsonData, customOptions?: import("./skydb").CustomSetJSONOptions | undefined) => Promise<import("./skydb").JSONResponse>;
setDataLink: (privateKey: string, dataKey: string, dataLink: string, customOptions?: import("./skydb").CustomSetJSONOptions | undefined) => Promise<void>;
};

@@ -82,0 +85,0 @@ registry: {

@@ -55,7 +55,10 @@ "use strict";

getJSON: file_1.getJSON.bind(this),
getEntryLink: file_1.getEntryLink.bind(this),
};
// SkyDB
this.db = {
deleteJSON: skydb_1.deleteJSON.bind(this),
getJSON: skydb_1.getJSON.bind(this),
setJSON: skydb_1.setJSON.bind(this),
setDataLink: skydb_1.setDataLink.bind(this),
};

@@ -62,0 +65,0 @@ // SkyDB helpers

8

dist/cjs/crypto.js

@@ -103,9 +103,3 @@ "use strict";

}
let dataBytes;
if (typeof registryEntry.data === "string") {
dataBytes = encoding_1.encodeUtf8String(registryEntry.data);
}
else {
dataBytes = encoding_1.encodePrefixedBytes(registryEntry.data);
}
const dataBytes = encoding_1.encodePrefixedBytes(registryEntry.data);
return hashAll(dataKeyBytes, dataBytes, encoding_1.encodeBigintAsUint64(registryEntry.revision));

@@ -112,0 +106,0 @@ }

import { SkynetClient } from "./client";
import { JsonData } from "./skydb";
import { BaseCustomOptions } from "./utils/options";

@@ -41,3 +42,2 @@ /**

* @property contentType - The type of the content.
* @property metadata - The metadata in JSON format.
* @property portalUrl - The URL of the portal.

@@ -55,3 +55,2 @@ * @property skylink - 46-character skylink.

*
* @property contentType - The type of the content.
* @property metadata - The metadata in JSON format.

@@ -63,2 +62,4 @@ * @property portalUrl - The URL of the portal.

metadata: Record<string, unknown>;
portalUrl: string;
skylink: string;
};

@@ -71,2 +72,3 @@ /**

export declare type ResolveHnsResponse = {
data: JsonData;
skylink: string;

@@ -217,3 +219,3 @@ };

/**
* Resolves the given HNS domain to its TXT record and returns the data.
* Resolves the given HNS domain to its skylink and returns it and the raw data.
*

@@ -224,3 +226,3 @@ * @param this - SkynetClient

* @param [customOptions.endpointResolveHns="/hnsres"] - The relative URL path of the portal endpoint to contact.
* @returns - The data for the TXT record.
* @returns - The raw data and corresponding skylink.
* @throws - Will throw if the input domain is not a string.

@@ -227,0 +229,0 @@ */

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveHns = exports.openFileHns = exports.openFile = exports.getFileContentRequest = exports.getFileContentHns = exports.getFileContent = exports.getMetadata = exports.getHnsresUrl = exports.getHnsUrl = exports.getSkylinkUrlForPortal = exports.getSkylinkUrl = exports.downloadFileHns = exports.downloadFile = exports.defaultDownloadOptions = void 0;
const options_1 = require("./utils/options");
const format_1 = require("./skylink/format");
const parse_1 = require("./skylink/parse");
const string_1 = require("./utils/string");
const options_1 = require("./utils/options");
const url_1 = require("./utils/url");

@@ -193,3 +193,3 @@ const validation_1 = require("./utils/validation");

const opts = { ...defaultResolveHnsOptions, ...this.customOptions, ...customOptions };
domain = string_1.trimUriPrefix(domain, url_1.uriHandshakeResolverPrefix);
domain = string_1.trimUriPrefix(domain, url_1.uriHandshakePrefix);
const portalUrl = await this.portalUrl();

@@ -211,2 +211,3 @@ return url_1.makeUrl(portalUrl, opts.endpointResolveHns, domain);

// Validation is done in `getSkylinkUrl`.
var _a;
const opts = { ...defaultGetMetadataOptions, ...this.customOptions, ...customOptions };

@@ -228,12 +229,8 @@ // Don't include the path for now since the endpoint doesn't support it.

const metadata = response.data;
// TODO: Add back in once the endpoint supports these headers.
// if (typeof response.headers === "undefined") {
// throw new Error(
// "Did not get 'headers' in response despite a successful request. Please try again and report this issue to the devs if it persists."
// );
// }
// const contentType = response.headers["content-type"] ?? "";
// const portalUrl = response.headers["skynet-portal-api"] ?? "";
// const skylink = response.headers["skynet-skylink"] ? formatSkylink(response.headers["skynet-skylink"]) : "";
return { metadata };
if (typeof response.headers === "undefined") {
throw new Error("Did not get 'headers' in response despite a successful request. Please try again and report this issue to the devs if it persists.");
}
const portalUrl = (_a = response.headers["skynet-portal-api"]) !== null && _a !== void 0 ? _a : "";
const skylink = response.headers["skynet-skylink"] ? format_1.formatSkylink(response.headers["skynet-skylink"]) : "";
return { metadata, portalUrl, skylink };
}

@@ -345,3 +342,3 @@ exports.getMetadata = getMetadata;

/**
* Resolves the given HNS domain to its TXT record and returns the data.
* Resolves the given HNS domain to its skylink and returns it and the raw data.
*

@@ -352,3 +349,3 @@ * @param this - SkynetClient

* @param [customOptions.endpointResolveHns="/hnsres"] - The relative URL path of the portal endpoint to contact.
* @returns - The data for the TXT record.
* @returns - The raw data and corresponding skylink.
* @throws - Will throw if the input domain is not a string.

@@ -368,3 +365,11 @@ */

validateResolveHnsResponse(response);
return response.data;
if (response.data.skylink) {
return { data: response.data, skylink: response.data.skylink };
}
else {
const skylink = await this.registry.getEntryLink(response.data.registry.publickey, response.data.registry.datakey, {
hashedDataKeyHex: true,
});
return { data: response.data, skylink };
}
}

@@ -393,3 +398,13 @@ exports.resolveHns = resolveHns;

}
validation_1.validateString("response.data.skylink", response.data.skylink, "upload response field");
if (response.data.skylink) {
validation_1.validateString("response.data.skylink", response.data.skylink, "resolveHns response field");
}
else if (response.data.registry) {
validation_1.validateObject("response.data.registry", response.data.registry, "resolveHns response field");
validation_1.validateString("response.data.registry.publickey", response.data.registry.publickey, "resolveHns response field");
validation_1.validateString("response.data.registry.datakey", response.data.registry.datakey, "resolveHns response field");
}
else {
validation_1.throwValidationError("response.data", response.data, "response data object", "object containing skylink or registry field");
}
}

@@ -396,0 +411,0 @@ catch (err) {

import { SkynetClient } from "./client";
import { CustomGetJSONOptions, JSONResponse } from "./skydb";
/**
* Gets Discoverable JSON at the given data path for the given public user ID.
*
* @param this - SkynetClient
* @param userID - The public user ID.
* @param path - The data path.
* @param [customOptions] - Additional settings that can optionally be set.
* @returns - An object containing the json data as well as the skylink for the data.
*/
export declare function getJSON(this: SkynetClient, userID: string, path: string, customOptions?: CustomGetJSONOptions): Promise<JSONResponse>;
/**
* Gets the entry link for the entry at the given data path, for the given
* public user ID. This is a v2 skylink. This link stays the same even if the
* content at the entry changes.
*
* @param this - SkynetClient
* @param userID - The public user ID.
* @param path - The data path.
* @returns - The entry link.
*/
export declare function getEntryLink(this: SkynetClient, userID: string, path: string): Promise<string>;
//# sourceMappingURL=file.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getJSON = void 0;
exports.getEntryLink = exports.getJSON = void 0;
const tweak_1 = require("./mysky/tweak");
const registry_1 = require("./registry");
const skydb_1 = require("./skydb");
const validation_1 = require("./utils/validation");
/**
* Gets Discoverable JSON at the given data path for the given public user ID.
*
* @param this - SkynetClient
* @param userID - The public user ID.
* @param path - The data path.
* @param [customOptions] - Additional settings that can optionally be set.
* @returns - An object containing the json data as well as the skylink for the data.
*/
async function getJSON(userID, path, customOptions) {

@@ -21,1 +31,20 @@ validation_1.validateString("userID", userID, "parameter");

exports.getJSON = getJSON;
/**
* Gets the entry link for the entry at the given data path, for the given
* public user ID. This is a v2 skylink. This link stays the same even if the
* content at the entry changes.
*
* @param this - SkynetClient
* @param userID - The public user ID.
* @param path - The data path.
* @returns - The entry link.
*/
async function getEntryLink(userID, path) {
validation_1.validateString("userID", userID, "parameter");
validation_1.validateString("path", path, "parameter");
const dataKey = tweak_1.deriveDiscoverableTweak(path);
const opts = registry_1.defaultGetEntryOptions;
opts.hashedDataKeyHex = true; // Do not hash the tweak anymore.
return await this.registry.getEntryLink(userID, dataKey, opts);
}
exports.getEntryLink = getEntryLink;

@@ -8,9 +8,10 @@ export { SkynetClient } from "./client";

export { parseSkylink } from "./skylink/parse";
export { isSkylinkV1, isSkylinkV2 } from "./skylink/sia";
export { getRelativeFilePath, getRootDirectory } from "./utils/file";
export { MAX_REVISION } from "./utils/number";
export { stringToUint8ArrayUtf8, uint8ArrayToStringUtf8 } from "./utils/string";
export { defaultPortalUrl, defaultSkynetPortalUrl, extractDomainForPortal, getFullDomainUrlForPortal, uriHandshakePrefix, uriHandshakeResolverPrefix, uriSkynetPrefix, } from "./utils/url";
export { defaultPortalUrl, defaultSkynetPortalUrl, extractDomainForPortal, getFullDomainUrlForPortal, uriHandshakePrefix, uriSkynetPrefix, } from "./utils/url";
export { Permission, PermCategory, PermType, PermRead, PermWrite, PermHidden, PermDiscoverable, PermLegacySkyID, } from "skynet-mysky-utils";
export type { CustomClientOptions, RequestConfig } from "./client";
export type { Signature } from "./crypto";
export type { KeyPair, KeyPairAndSeed, Signature } from "./crypto";
export type { CustomDownloadOptions, ResolveHnsResponse } from "./download";

@@ -17,0 +18,0 @@ export type { CustomConnectorOptions, MySky } from "./mysky";

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PermLegacySkyID = exports.PermDiscoverable = exports.PermHidden = exports.PermWrite = exports.PermRead = exports.PermType = exports.PermCategory = exports.Permission = exports.uriSkynetPrefix = exports.uriHandshakeResolverPrefix = exports.uriHandshakePrefix = exports.getFullDomainUrlForPortal = exports.extractDomainForPortal = exports.defaultSkynetPortalUrl = exports.defaultPortalUrl = exports.uint8ArrayToStringUtf8 = exports.stringToUint8ArrayUtf8 = exports.MAX_REVISION = exports.getRootDirectory = exports.getRelativeFilePath = exports.parseSkylink = exports.convertSkylinkToBase32 = exports.mySkyDevDomain = exports.mySkyDomain = exports.DacLibrary = exports.signEntry = exports.getEntryUrlForPortal = exports.getSkylinkUrlForPortal = exports.genKeyPairFromSeed = exports.genKeyPairAndSeed = exports.deriveChildSeed = exports.SkynetClient = void 0;
exports.PermLegacySkyID = exports.PermDiscoverable = exports.PermHidden = exports.PermWrite = exports.PermRead = exports.PermType = exports.PermCategory = exports.Permission = exports.uriSkynetPrefix = exports.uriHandshakePrefix = exports.getFullDomainUrlForPortal = exports.extractDomainForPortal = exports.defaultSkynetPortalUrl = exports.defaultPortalUrl = exports.uint8ArrayToStringUtf8 = exports.stringToUint8ArrayUtf8 = exports.MAX_REVISION = exports.getRootDirectory = exports.getRelativeFilePath = exports.isSkylinkV2 = exports.isSkylinkV1 = exports.parseSkylink = exports.convertSkylinkToBase32 = exports.mySkyDevDomain = exports.mySkyDomain = exports.DacLibrary = exports.signEntry = exports.getEntryUrlForPortal = exports.getSkylinkUrlForPortal = exports.genKeyPairFromSeed = exports.genKeyPairAndSeed = exports.deriveChildSeed = exports.SkynetClient = void 0;
var client_1 = require("./client");

@@ -23,2 +23,5 @@ Object.defineProperty(exports, "SkynetClient", { enumerable: true, get: function () { return client_1.SkynetClient; } });

Object.defineProperty(exports, "parseSkylink", { enumerable: true, get: function () { return parse_1.parseSkylink; } });
var sia_1 = require("./skylink/sia");
Object.defineProperty(exports, "isSkylinkV1", { enumerable: true, get: function () { return sia_1.isSkylinkV1; } });
Object.defineProperty(exports, "isSkylinkV2", { enumerable: true, get: function () { return sia_1.isSkylinkV2; } });
var file_1 = require("./utils/file");

@@ -38,3 +41,2 @@ Object.defineProperty(exports, "getRelativeFilePath", { enumerable: true, get: function () { return file_1.getRelativeFilePath; } });

Object.defineProperty(exports, "uriHandshakePrefix", { enumerable: true, get: function () { return url_1.uriHandshakePrefix; } });
Object.defineProperty(exports, "uriHandshakeResolverPrefix", { enumerable: true, get: function () { return url_1.uriHandshakeResolverPrefix; } });
Object.defineProperty(exports, "uriSkynetPrefix", { enumerable: true, get: function () { return url_1.uriSkynetPrefix; } });

@@ -41,0 +43,0 @@ // Re-export Permission API.

@@ -15,2 +15,10 @@ export type { CustomConnectorOptions } from "./connector";

export declare const mySkyAlphaDomain = "sandbridge.hns";
/**
* Loads MySky. Note that this does not log in the user.
*
* @param this - The Skynet client.
* @param skappDomain - The domain of the host skapp. For this domain permissions will be requested and, by default, automatically granted.
* @param [customOptions] - Additional settings that can optionally be set.
* @returns - Loaded (but not logged-in) MySky instance.
*/
export declare function loadMySky(this: SkynetClient, skappDomain?: string, customOptions?: CustomConnectorOptions): Promise<MySky>;

@@ -28,2 +36,4 @@ export declare class MySky {

* Loads the given DACs.
*
* @param dacs - The DAC library instances to call `init` on.
*/

@@ -47,3 +57,3 @@ loadDacs(...dacs: DacLibrary[]): Promise<void>;

/**
* Gets Discoverable JSON at the given path through MySky, if the user has given permissions to do so.
* Gets Discoverable JSON at the given path through MySky, if the user has given Read permissions to do so.
*

@@ -64,3 +74,3 @@ * @param path - The data path.

/**
* Sets Discoverable JSON at the given path through MySky, if the user has given permissions to do so.
* Sets Discoverable JSON at the given path through MySky, if the user has given Write permissions to do so.
*

@@ -82,2 +92,11 @@ * @param path - The data path.

setDataLink(path: string, dataLink: string, customOptions?: CustomSetJSONOptions): Promise<void>;
/**
* Deletes Discoverable JSON at the given path through MySky, if the user has given Write permissions to do so.
*
* @param path - The data path.
* @param [customOptions] - Additional settings that can optionally be set.
* @returns - An empty promise.
* @throws - Will throw if the revision is already the maximum value.
*/
deleteJSON(path: string, customOptions?: CustomSetJSONOptions): Promise<void>;
protected catchError(errorMsg: string): Promise<void>;

@@ -84,0 +103,0 @@ protected launchUI(): Promise<Window>;

@@ -11,9 +11,6 @@ "use strict";

const skydb_1 = require("../skydb");
const string_1 = require("../utils/string");
const tweak_1 = require("./tweak");
const utils_1 = require("./utils");
const options_1 = require("../utils/options");
const validation_1 = require("../utils/validation");
const options_1 = require("../utils/options");
const url_1 = require("../utils/url");
const encoding_1 = require("../utils/encoding");
exports.mySkyDomain = "skynet-mysky.hns";

@@ -25,2 +22,10 @@ exports.mySkyDevDomain = "skynet-mysky-dev.hns";

const [mySkyUiW, mySkyUiH] = [600, 600];
/**
* Loads MySky. Note that this does not log in the user.
*
* @param this - The Skynet client.
* @param skappDomain - The domain of the host skapp. For this domain permissions will be requested and, by default, automatically granted.
* @param [customOptions] - Additional settings that can optionally be set.
* @returns - Loaded (but not logged-in) MySky instance.
*/
async function loadMySky(skappDomain, customOptions) {

@@ -38,3 +43,5 @@ const mySky = await MySky.New(this, skappDomain, customOptions);

this.hostDomain = hostDomain;
// Holds the loaded DACs.
this.dacs = [];
// Holds the currently granted permissions.
this.grantedPermissions = [];

@@ -73,2 +80,4 @@ this.pendingPermissions = permissions;

* Loads the given DACs.
*
* @param dacs - The DAC library instances to call `init` on.
*/

@@ -181,3 +190,3 @@ async loadDacs(...dacs) {

/**
* Gets Discoverable JSON at the given path through MySky, if the user has given permissions to do so.
* Gets Discoverable JSON at the given path through MySky, if the user has given Read permissions to do so.
*

@@ -217,3 +226,3 @@ * @param path - The data path.

/**
* Sets Discoverable JSON at the given path through MySky, if the user has given permissions to do so.
* Sets Discoverable JSON at the given path through MySky, if the user has given Write permissions to do so.
*

@@ -237,3 +246,3 @@ * @param path - The data path.

opts.hashedDataKeyHex = true; // Do not hash the tweak anymore.
const [entry, dataLink] = await skydb_1.getOrCreateRegistryEntry(this.connector.client, string_1.hexToUint8Array(publicKey), dataKey, json, opts);
const [entry, dataLink] = await skydb_1.getOrCreateRegistryEntry(this.connector.client, publicKey, dataKey, json, opts);
const signature = await this.signRegistryEntry(entry, path);

@@ -264,15 +273,27 @@ const setEntryOpts = options_1.extractOptions(opts, registry_1.defaultSetEntryOptions);

opts.hashedDataKeyHex = true; // Do not hash the tweak anymore.
// Get the latest entry.
// TODO: Can remove this once we start caching the latest revision.
const getEntryOpts = options_1.extractOptions(opts, registry_1.defaultGetEntryOptions);
const signedEntry = await this.connector.client.registry.getEntry(publicKey, dataKey, getEntryOpts);
const revision = skydb_1.getRevisionFromSignedEntry(signedEntry);
// Add padding
const paddedDataLink = `${string_1.trimUriPrefix(dataLink, url_1.uriSkynetPrefix)}==`;
// Build the registry entry.
const entry = {
dataKey,
data: encoding_1.base64RawUrlToUint8Array(paddedDataLink),
revision,
const entry = await skydb_1.getDataLinkRegistryEntry(this.connector.client, publicKey, dataKey, dataLink, opts);
const signature = await this.signRegistryEntry(entry, path);
const setEntryOpts = options_1.extractOptions(opts, registry_1.defaultSetEntryOptions);
await this.connector.client.registry.postSignedEntry(publicKey, entry, signature, setEntryOpts);
}
/**
* Deletes Discoverable JSON at the given path through MySky, if the user has given Write permissions to do so.
*
* @param path - The data path.
* @param [customOptions] - Additional settings that can optionally be set.
* @returns - An empty promise.
* @throws - Will throw if the revision is already the maximum value.
*/
async deleteJSON(path, customOptions) {
validation_1.validateString("path", path, "parameter");
validation_1.validateOptionalObject("customOptions", customOptions, "parameter", skydb_1.defaultSetJSONOptions);
const opts = {
...skydb_1.defaultSetJSONOptions,
...this.connector.client.customOptions,
...customOptions,
};
const publicKey = await this.userID();
const dataKey = tweak_1.deriveDiscoverableTweak(path);
opts.hashedDataKeyHex = true; // Do not hash the tweak anymore.
const entry = await skydb_1.getDeletionRegistryEntry(this.connector.client, publicKey, dataKey, opts);
const signature = await this.signRegistryEntry(entry, path);

@@ -279,0 +300,0 @@ const setEntryOpts = options_1.extractOptions(opts, registry_1.defaultSetEntryOptions);

@@ -22,4 +22,10 @@ import { SkynetClient } from "../client";

* Create a new popup window. From SkyID.
*
* @param url - The URL to open.
* @param title - The title of the popup window.
* @param w - The width of the popup window.
* @param h - the height of the popup window.
* @returns - The window.
*/
export declare function popupCenter(url: string, title: string, w: number, h: number): Window;
//# sourceMappingURL=utils.d.ts.map

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

* Create a new popup window. From SkyID.
*
* @param url - The URL to open.
* @param title - The title of the popup window.
* @param w - The width of the popup window.
* @param h - the height of the popup window.
* @returns - The window.
*/
/* istanbul ignore next */
function popupCenter(url, title, w, h) {

@@ -37,0 +44,0 @@ url = skynet_mysky_utils_1.ensureUrl(url);

@@ -122,5 +122,30 @@ import { SkynetClient } from "./client";

export declare function setEntry(this: SkynetClient, privateKey: string, entry: RegistryEntry, customOptions?: CustomSetEntryOptions): Promise<void>;
/**
* Signs the entry with the given private key.
*
* @param privateKey - The user private key.
* @param entry - The entry to sign.
* @param hashedDataKeyHex - Whether the data key is already hashed and in hex format. If not, we hash the data key.
* @returns - The signature.
*/
export declare function signEntry(privateKey: string, entry: RegistryEntry, hashedDataKeyHex: boolean): Promise<Uint8Array>;
/**
* Posts the entry with the given public key and signature to Skynet.
*
* @param this - The Skynet client.
* @param publicKey - The user public key.
* @param entry - The entry to set.
* @param signature - The signature.
* @param [customOptions] - Additional settings that can optionally be set.
* @returns - An empty promise.
*/
export declare function postSignedEntry(this: SkynetClient, publicKey: string, entry: RegistryEntry, signature: Uint8Array, customOptions?: CustomSetEntryOptions): Promise<void>;
/**
* Validates the given registry entry.
*
* @param name - The name of the value.
* @param value - The actual value.
* @param valueKind - The kind of value that is being checked (e.g. "parameter", "response field", etc.)
*/
export declare function validateRegistryEntry(name: string, value: unknown, valueKind: string): void;
//# sourceMappingURL=registry.d.ts.map

@@ -155,5 +155,3 @@ "use strict";

publicKey = string_1.trimPrefix(publicKey, "ed25519:");
if (!string_1.isHexString(publicKey)) {
throw new Error(`Given public key '${publicKey}' is not a valid hex-encoded string or contains an invalid prefix`);
}
validateTrimmedPublicKey("publicKey", publicKey, "parameter");
// Hash and hex encode the given data key if it is not a hash already.

@@ -194,5 +192,3 @@ let dataKeyHashHex = dataKey;

publicKey = string_1.trimPrefix(publicKey, "ed25519:");
if (!string_1.isHexString(publicKey)) {
throw new Error(`Given public key '${publicKey}' is not a valid hex-encoded string or contains an invalid prefix`);
}
validateTrimmedPublicKey("publicKey", publicKey, "parameter");
const siaPublicKey = sia_1.newEd25519PublicKey(publicKey);

@@ -237,2 +233,10 @@ let tweak;

exports.setEntry = setEntry;
/**
* Signs the entry with the given private key.
*
* @param privateKey - The user private key.
* @param entry - The entry to sign.
* @param hashedDataKeyHex - Whether the data key is already hashed and in hex format. If not, we hash the data key.
* @returns - The signature.
*/
async function signEntry(privateKey, entry, hashedDataKeyHex) {

@@ -246,2 +250,12 @@ // TODO: Publicly available, validate input.

exports.signEntry = signEntry;
/**
* Posts the entry with the given public key and signature to Skynet.
*
* @param this - The Skynet client.
* @param publicKey - The user public key.
* @param entry - The entry to set.
* @param signature - The signature.
* @param [customOptions] - Additional settings that can optionally be set.
* @returns - An empty promise.
*/
async function postSignedEntry(publicKey, entry, signature, customOptions) {

@@ -292,2 +306,9 @@ validation_1.validateHexString("publicKey", publicKey, "parameter");

exports.postSignedEntry = postSignedEntry;
/**
* Validates the given registry entry.
*
* @param name - The name of the value.
* @param value - The actual value.
* @param valueKind - The kind of value that is being checked (e.g. "parameter", "response field", etc.)
*/
function validateRegistryEntry(name, value, valueKind) {

@@ -322,1 +343,14 @@ validation_1.validateObject(name, value, valueKind);

}
/**
* Validates the given value as a hex-encoded public key.
*
* @param name - The name of the value.
* @param publicKey - The public key.
* @param valueKind - The kind of value that is being checked (e.g. "parameter", "response field", etc.)
* @throws - Will throw if not a valid hex-encoded public key.
*/
function validateTrimmedPublicKey(name, publicKey, valueKind) {
if (!string_1.isHexString(publicKey)) {
validation_1.throwValidationError(name, publicKey, valueKind, "a hex-encoded string with a valid prefix");
}
}
import { SkynetClient } from "./client";
import { CustomGetEntryOptions, RegistryEntry, SignedRegistryEntry, CustomSetEntryOptions } from "./registry";
import { CustomDownloadOptions } from "./download";
import { CustomGetEntryOptions, RegistryEntry, CustomSetEntryOptions } from "./registry";
import { CustomUploadOptions } from "./upload";
import { CustomDownloadOptions } from "./download";
export declare const JSON_RESPONSE_VERSION = 2;
export declare type JsonData = Record<string, unknown>;

@@ -75,7 +74,32 @@ /**

* @param [customOptions] - Additional settings that can optionally be set.
* @returns - The returned JSON and revision number.
* @throws - Will throw if the input keys are not valid strings.
*/
export declare function setJSON(this: SkynetClient, privateKey: string, dataKey: string, json: JsonData, customOptions?: CustomSetJSONOptions): Promise<JSONResponse>;
export declare function getOrCreateRegistryEntry(client: SkynetClient, publicKeyArray: Uint8Array, dataKey: string, json: JsonData, customOptions?: CustomSetJSONOptions): Promise<[RegistryEntry, string]>;
export declare function getRevisionFromSignedEntry(signedEntry: SignedRegistryEntry): bigint;
/**
* Deletes a JSON object at the registry entry corresponding to the publicKey and dataKey.
*
* @param this - SkynetClient
* @param privateKey - The user private key.
* @param dataKey - The key of the data to fetch for the given user.
* @param [customOptions] - Additional settings that can optionally be set.
* @throws - Will throw if the input keys are not valid strings.
*/
export declare function deleteJSON(this: SkynetClient, privateKey: string, dataKey: string, customOptions?: CustomSetJSONOptions): Promise<void>;
export declare function getDeletionRegistryEntry(client: SkynetClient, publicKey: string, dataKey: string, customOptions?: CustomGetJSONOptions): Promise<RegistryEntry>;
export declare function setDataLink(this: SkynetClient, privateKey: string, dataKey: string, dataLink: string, customOptions?: CustomSetJSONOptions): Promise<void>;
export declare function getDataLinkRegistryEntry(client: SkynetClient, publicKey: string, dataKey: string, dataLink: string, customOptions?: CustomSetJSONOptions): Promise<RegistryEntry>;
/**
* Gets the registry entry and data link or creates the entry if it doesn't exist.
*
* @param client - The Skynet client.
* @param publicKeyArray - The user public key.
* @param dataKey - The dat akey.
* @param json - The JSON to set.
* @param [customOptions] - Additional settings that can optionally be set.
* @returns - The registry entry and corresponding data link.
* @throws - Will throw if the revision is already the maximum value.
*/
export declare function getOrCreateRegistryEntry(client: SkynetClient, publicKey: string, dataKey: string, json: JsonData, customOptions?: CustomSetJSONOptions): Promise<[RegistryEntry, string]>;
export declare function getRevisionFromEntry(entry: RegistryEntry | null): bigint;
//# sourceMappingURL=skydb.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getRevisionFromSignedEntry = exports.getOrCreateRegistryEntry = exports.setJSON = exports.getJSON = exports.defaultSetJSONOptions = exports.defaultGetJSONOptions = exports.JSON_RESPONSE_VERSION = void 0;
exports.getRevisionFromEntry = exports.getOrCreateRegistryEntry = exports.getDataLinkRegistryEntry = exports.setDataLink = exports.getDeletionRegistryEntry = exports.deleteJSON = exports.setJSON = exports.getJSON = exports.defaultSetJSONOptions = exports.defaultGetJSONOptions = void 0;
const tweetnacl_1 = require("tweetnacl");
const download_1 = require("./download");
const registry_1 = require("./registry");

@@ -10,8 +11,10 @@ const sia_1 = require("./skylink/sia");

const string_1 = require("./utils/string");
const format_1 = require("./skylink/format");
const parse_1 = require("./skylink/parse");
const upload_1 = require("./upload");
const download_1 = require("./download");
const encoding_1 = require("./utils/encoding");
const options_1 = require("./utils/options");
const validation_1 = require("./utils/validation");
exports.JSON_RESPONSE_VERSION = 2;
const array_1 = require("./utils/array");
const JSON_RESPONSE_VERSION = 2;
exports.defaultGetJSONOptions = {

@@ -50,3 +53,3 @@ ...options_1.defaultBaseOptions,

const { entry } = await this.registry.getEntry(publicKey, dataKey, getEntryOpts);
if (entry === null) {
if (entry === null || array_1.areEqualUint8Arrays(entry.data, sia_1.EMPTY_SKYLINK)) {
return { data: null, dataLink: null };

@@ -59,11 +62,11 @@ }

}
let dataLink;
let rawDataLink;
if (entry.data.length === 46) {
// Legacy data, convert to string.
dataLink = string_1.uint8ArrayToStringUtf8(entry.data);
rawDataLink = string_1.uint8ArrayToStringUtf8(entry.data);
}
else if (entry.data.length === sia_1.RAW_SKYLINK_SIZE) {
// Convert the bytes to a base64 skylink.
dataLink = encoding_1.uint8ArrayToBase64RawUrl(entry.data);
dataLink = string_1.trimSuffix(dataLink, "=");
rawDataLink = encoding_1.uint8ArrayToBase64RawUrl(entry.data);
rawDataLink = string_1.trimSuffix(rawDataLink, "=");
}

@@ -73,4 +76,5 @@ else {

}
const dataLink = format_1.formatSkylink(rawDataLink);
// If a cached data link is provided and the data link hasn't changed, return.
if (opts.cachedDataLink && dataLink === opts.cachedDataLink) {
if (opts.cachedDataLink && rawDataLink === parse_1.parseSkylink(opts.cachedDataLink)) {
return { data: null, dataLink };

@@ -103,2 +107,3 @@ }

* @param [customOptions] - Additional settings that can optionally be set.
* @returns - The returned JSON and revision number.
* @throws - Will throw if the input keys are not valid strings.

@@ -117,18 +122,115 @@ */

const { publicKey: publicKeyArray } = tweetnacl_1.sign.keyPair.fromSecretKey(string_1.hexToUint8Array(privateKey));
const [entry, skylink] = await getOrCreateRegistryEntry(this, publicKeyArray, dataKey, json, opts);
const [entry, dataLink] = await getOrCreateRegistryEntry(this, string_1.toHexString(publicKeyArray), dataKey, json, opts);
// Update the registry.
const setEntryOpts = options_1.extractOptions(opts, registry_1.defaultSetEntryOptions);
await this.registry.setEntry(privateKey, entry, setEntryOpts);
return { data: json, dataLink: skylink };
return { data: json, dataLink: format_1.formatSkylink(dataLink) };
}
exports.setJSON = setJSON;
async function getOrCreateRegistryEntry(client, publicKeyArray, dataKey, json, customOptions) {
/**
* Deletes a JSON object at the registry entry corresponding to the publicKey and dataKey.
*
* @param this - SkynetClient
* @param privateKey - The user private key.
* @param dataKey - The key of the data to fetch for the given user.
* @param [customOptions] - Additional settings that can optionally be set.
* @throws - Will throw if the input keys are not valid strings.
*/
async function deleteJSON(privateKey, dataKey, customOptions) {
validation_1.validateHexString("privateKey", privateKey, "parameter");
validation_1.validateString("dataKey", dataKey, "parameter");
validation_1.validateOptionalObject("customOptions", customOptions, "parameter", exports.defaultSetJSONOptions);
const opts = {
...exports.defaultSetJSONOptions,
...this.customOptions,
...customOptions,
};
const { publicKey: publicKeyArray } = tweetnacl_1.sign.keyPair.fromSecretKey(string_1.hexToUint8Array(privateKey));
const entry = await getDeletionRegistryEntry(this, string_1.toHexString(publicKeyArray), dataKey, opts);
// Update the registry.
const setEntryOpts = options_1.extractOptions(opts, registry_1.defaultSetEntryOptions);
await this.registry.setEntry(privateKey, entry, setEntryOpts);
}
exports.deleteJSON = deleteJSON;
async function getDeletionRegistryEntry(client, publicKey, dataKey, customOptions) {
// Not publicly available, don't validate input.
const opts = {
...exports.defaultGetJSONOptions,
...client.customOptions,
...customOptions,
};
// Fetch the current value to find out the revision.
const getEntryOpts = options_1.extractOptions(opts, registry_1.defaultGetEntryOptions);
const signedEntry = await client.registry.getEntry(publicKey, dataKey, getEntryOpts);
const revision = getRevisionFromEntry(signedEntry.entry);
// Build the registry value. Use empty bytes for the data.
const data = new Uint8Array(sia_1.RAW_SKYLINK_SIZE);
const entry = {
dataKey,
data,
revision,
};
return entry;
}
exports.getDeletionRegistryEntry = getDeletionRegistryEntry;
async function setDataLink(privateKey, dataKey, dataLink, customOptions) {
validation_1.validateHexString("privateKey", privateKey, "parameter");
validation_1.validateString("dataKey", dataKey, "parameter");
validation_1.validateString("dataLink", dataLink, "parameter");
validation_1.validateOptionalObject("customOptions", customOptions, "parameter", exports.defaultSetJSONOptions);
const opts = {
...exports.defaultSetJSONOptions,
...this.customOptions,
...customOptions,
};
const { publicKey: publicKeyArray } = tweetnacl_1.sign.keyPair.fromSecretKey(string_1.hexToUint8Array(privateKey));
const entry = await getDataLinkRegistryEntry(this, string_1.toHexString(publicKeyArray), dataKey, dataLink, opts);
// Update the registry.
const setEntryOpts = options_1.extractOptions(opts, registry_1.defaultSetEntryOptions);
await this.registry.setEntry(privateKey, entry, setEntryOpts);
}
exports.setDataLink = setDataLink;
async function getDataLinkRegistryEntry(client, publicKey, dataKey, dataLink, customOptions) {
// Not publicly available, don't validate input.
const opts = {
...exports.defaultSetJSONOptions,
...client.customOptions,
...customOptions,
};
// Get the latest entry.
// TODO: Can remove this once we start caching the latest revision.
const getEntryOpts = options_1.extractOptions(opts, registry_1.defaultGetEntryOptions);
const signedEntry = await client.registry.getEntry(publicKey, dataKey, getEntryOpts);
const revision = getRevisionFromEntry(signedEntry.entry);
// Add padding
const paddedDataLink = `${string_1.trimUriPrefix(dataLink, url_1.uriSkynetPrefix)}==`;
// Build the registry entry.
const entry = {
dataKey,
data: encoding_1.base64RawUrlToUint8Array(paddedDataLink),
revision,
};
return entry;
}
exports.getDataLinkRegistryEntry = getDataLinkRegistryEntry;
/**
* Gets the registry entry and data link or creates the entry if it doesn't exist.
*
* @param client - The Skynet client.
* @param publicKeyArray - The user public key.
* @param dataKey - The dat akey.
* @param json - The JSON to set.
* @param [customOptions] - Additional settings that can optionally be set.
* @returns - The registry entry and corresponding data link.
* @throws - Will throw if the revision is already the maximum value.
*/
async function getOrCreateRegistryEntry(client, publicKey, dataKey, json, customOptions) {
// Not publicly available, don't validate input.
const opts = {
...exports.defaultSetJSONOptions,
...client.customOptions,
...customOptions,
};
// Set the hidden _data and _v fields.
const fullData = { _data: json, _v: exports.JSON_RESPONSE_VERSION };
const fullData = { _data: json, _v: JSON_RESPONSE_VERSION };
// Create the data to upload to acquire its skylink.

@@ -147,3 +249,3 @@ let dataKeyHex = dataKey;

const getEntryOpts = options_1.extractOptions(opts, registry_1.defaultGetEntryOptions);
const entryPromise = client.registry.getEntry(string_1.toHexString(publicKeyArray), dataKey, getEntryOpts);
const entryPromise = client.registry.getEntry(publicKey, dataKey, getEntryOpts);
// Block until both getEntry and uploadFile are finished.

@@ -154,3 +256,3 @@ const [signedEntry, skyfile] = await Promise.all([

]);
const revision = getRevisionFromSignedEntry(signedEntry);
const revision = getRevisionFromEntry(signedEntry.entry);
// Build the registry entry.

@@ -168,12 +270,12 @@ const dataLink = skyfile.skylink;

};
return [entry, dataLink];
return [entry, format_1.formatSkylink(dataLink)];
}
exports.getOrCreateRegistryEntry = getOrCreateRegistryEntry;
function getRevisionFromSignedEntry(signedEntry) {
function getRevisionFromEntry(entry) {
let revision;
if (signedEntry.entry === null) {
if (entry === null) {
revision = BigInt(0);
}
else {
revision = signedEntry.entry.revision + BigInt(1);
revision = entry.revision + BigInt(1);
}

@@ -188,2 +290,2 @@ // Throw if the revision is already the maximum value.

}
exports.getRevisionFromSignedEntry = getRevisionFromSignedEntry;
exports.getRevisionFromEntry = getRevisionFromEntry;

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

function formatSkylink(skylink) {
if (skylink == "") {
if (skylink === "") {
return skylink;

@@ -31,0 +31,0 @@ }

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

/**
* The raw size in bytes of the data that gets put into a link.
*/
export declare const RAW_SKYLINK_SIZE = 34;
/**
* An empty skylink.
*/
export declare const EMPTY_SKYLINK: Uint8Array;
export declare class SiaSkylink {

@@ -10,2 +17,14 @@ bitfield: number;

/**
* Checks if the given string is a v1 skylink.
*
* @param s
*/
export declare function isSkylinkV1(s: string): boolean;
/**
* Checks if the given string is a v2 skylink.
*
* @param s
*/
export declare function isSkylinkV2(s: string): boolean;
/**
* Returns a specifier for given name, a specifier can only be 16 bytes so we

@@ -39,3 +58,12 @@ * panic if the given name is too long.

export declare function newSkylinkV2(siaPublicKey: SiaPublicKey, tweak: Uint8Array): SiaSkylink;
/**
* A helper function that decodes the given string representation of a skylink
* into raw bytes. It either performs a base32 decoding, or base64 decoding,
* depending on the length.
*
* @param encoded - The encoded string.
* @returns - The decoded raw bytes.
*/
export declare function decodeSkylink(encoded: string): Uint8Array;
export {};
//# sourceMappingURL=sia.d.ts.map
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.newSkylinkV2 = exports.newEd25519PublicKey = exports.newSpecifier = exports.SiaSkylink = exports.RAW_SKYLINK_SIZE = void 0;
const base64_js_1 = require("base64-js");
exports.decodeSkylink = exports.newSkylinkV2 = exports.newEd25519PublicKey = exports.newSpecifier = exports.isSkylinkV2 = exports.isSkylinkV1 = exports.SiaSkylink = exports.EMPTY_SKYLINK = exports.RAW_SKYLINK_SIZE = void 0;
const base32_decode_1 = __importDefault(require("base32-decode"));
const crypto_1 = require("../crypto");

@@ -9,4 +12,23 @@ const encoding_1 = require("../utils/encoding");

const validation_1 = require("../utils/validation");
// The raw size of the data that gets put into a link.
/**
* The string length of the Skylink after it has been encoded using base32.
*/
const BASE32_ENCODED_SKYLINK_SIZE = 55;
/**
* The string length of the Skylink after it has been encoded using base64.
*/
const BASE64_ENCODED_SKYLINK_SIZE = 46;
/**
* Returned when a string could not be decoded into a Skylink due to it having
* an incorrect size.
*/
const ERR_SKYLINK_INCORRECT_SIZE = "skylink has incorrect size";
/**
* The raw size in bytes of the data that gets put into a link.
*/
exports.RAW_SKYLINK_SIZE = 34;
/**
* An empty skylink.
*/
exports.EMPTY_SKYLINK = new Uint8Array(exports.RAW_SKYLINK_SIZE);
class SiaSkylink {

@@ -28,5 +50,3 @@ constructor(bitfield, merkleRoot) {

toString() {
let base64 = base64_js_1.fromByteArray(this.toBytes());
// Change to URL encoding.
base64 = base64.replace(/\+/g, "-").replace(/\//g, "_");
const base64 = encoding_1.uint8ArrayToBase64RawUrl(this.toBytes());
// Remove padding characters.

@@ -37,2 +57,47 @@ return string_1.trimSuffix(base64, "=");

exports.SiaSkylink = SiaSkylink;
/**
* Checks if the given string is a v1 skylink.
*
* @param s
*/
function isSkylinkV1(s) {
const raw = decodeSkylink(s);
// Load and check the bitfield.
const view = new DataView(raw.buffer);
const bitfield = view.getUint16(0, true);
return isBitfieldSkylinkV1(bitfield);
}
exports.isSkylinkV1 = isSkylinkV1;
/**
* Checks if the given string is a v2 skylink.
*
* @param s
*/
function isSkylinkV2(s) {
// Decode the base into raw data.
const raw = decodeSkylink(s);
// Load and check the bitfield.
const view = new DataView(raw.buffer);
const bitfield = view.getUint16(0, true);
return isBitfieldSkylinkV2(bitfield);
}
exports.isSkylinkV2 = isSkylinkV2;
/**
* Returns a boolean indicating if the Skylink is a V1 skylink
*
* @param bitfield
*/
function isBitfieldSkylinkV1(bitfield) {
return (bitfield & 3) === 0;
}
/**
* Returns a boolean indicating if the Skylink is a V2 skylink
*
* @param bitfield
*/
function isBitfieldSkylinkV2(bitfield) {
// We compare against 1 here because a V2 skylink only uses the version
// bits. All other bits should be set to 0.
return bitfield == 1;
}
const SPECIFIER_LEN = 16;

@@ -47,3 +112,3 @@ /**

function newSpecifier(name) {
validateSpecifier(name);
validation_1.validateString("name", name, "parameter");
const specifier = new Uint8Array(SPECIFIER_LEN);

@@ -96,2 +161,31 @@ specifier.set(string_1.stringToUint8ArrayUtf8(name));

/**
* A helper function that decodes the given string representation of a skylink
* into raw bytes. It either performs a base32 decoding, or base64 decoding,
* depending on the length.
*
* @param encoded - The encoded string.
* @returns - The decoded raw bytes.
*/
function decodeSkylink(encoded) {
let bytes;
if (encoded.length === BASE32_ENCODED_SKYLINK_SIZE) {
encoded = encoded.toUpperCase();
bytes = new Uint8Array(base32_decode_1.default(encoded, "RFC4648-HEX"));
}
else if (encoded.length === BASE64_ENCODED_SKYLINK_SIZE) {
// Add padding.
encoded = `${encoded}==`;
bytes = encoding_1.base64RawUrlToUint8Array(encoded);
}
else {
throw new Error(ERR_SKYLINK_INCORRECT_SIZE);
}
// Sanity check the size of the given data.
if (bytes.length != exports.RAW_SKYLINK_SIZE) {
throw new Error("failed to load skylink data");
}
return bytes;
}
exports.decodeSkylink = decodeSkylink;
/**
* A helper to derive an entry id for a registry key value pair. Matches `DeriveRegistryEntryID` in sia.

@@ -106,17 +200,1 @@ *

}
/**
* Performs validation checks on the specifier name, it panics when the input is
* invalid seeing we want to catch this on runtime.
* Matches `validateSpecifier` in sia.
*
* @param name - The specifier name.
* @throws - Will throw if the specifier name is not valid.
*/
function validateSpecifier(name) {
if (!string_1.isASCIIString(name)) {
throw new Error("specifier has to be ASCII");
}
if (name.length > SPECIFIER_LEN) {
throw new Error("specifier max length exceeded");
}
}
/**
* Returns a boolean indicating whether the String contains only ASCII bytes.
* From https://stackoverflow.com/a/14313213/6085242.
*
* @param str - The input string.
* @returns - Whether the string is ASCII.
*/
export declare function isASCIIString(str: string): boolean;
/**
* Removes slashes from the beginning and end of the string.

@@ -11,0 +3,0 @@ *

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.toHexString = exports.isHexString = exports.hexToUint8Array = exports.uint8ArrayToStringUtf8 = exports.stringToUint8ArrayUtf8 = exports.trimUriPrefix = exports.trimSuffix = exports.trimPrefix = exports.trimForwardSlash = exports.isASCIIString = void 0;
exports.toHexString = exports.isHexString = exports.hexToUint8Array = exports.uint8ArrayToStringUtf8 = exports.stringToUint8ArrayUtf8 = exports.trimUriPrefix = exports.trimSuffix = exports.trimPrefix = exports.trimForwardSlash = void 0;
const buffer_1 = require("buffer");
const validation_1 = require("./validation");
/**
* Returns a boolean indicating whether the String contains only ASCII bytes.
* From https://stackoverflow.com/a/14313213/6085242.
*
* @param str - The input string.
* @returns - Whether the string is ASCII.
*/
function isASCIIString(str) {
// eslint-disable-next-line
return /^[\x00-\x7F]*$/.test(str);
}
exports.isASCIIString = isASCIIString;
/**
* Removes slashes from the beginning and end of the string.

@@ -80,10 +68,10 @@ *

function trimUriPrefix(str, prefix) {
const longPrefix = `${prefix}//`;
if (str.startsWith(longPrefix)) {
const shortPrefix = trimSuffix(prefix, "/");
if (str.startsWith(prefix)) {
// longPrefix is exactly at the beginning
return str.slice(longPrefix.length);
return str.slice(prefix.length);
}
if (str.startsWith(prefix)) {
if (str.startsWith(shortPrefix)) {
// else prefix is exactly at the beginning
return str.slice(prefix.length);
return str.slice(shortPrefix.length);
}

@@ -90,0 +78,0 @@ return str;

export declare const defaultSkynetPortalUrl = "https://siasky.net";
export declare const uriHandshakePrefix = "hns:";
export declare const uriHandshakeResolverPrefix = "hnsres:";
export declare const uriSkynetPrefix = "sia:";
export declare const uriHandshakePrefix = "hns://";
export declare const uriSkynetPrefix = "sia://";
/**

@@ -6,0 +5,0 @@ * Returns the default portal URL.

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.extractDomainForPortal = exports.getFullDomainUrlForPortal = exports.makeUrl = exports.addUrlQuery = exports.addSubdomain = exports.addPath = exports.defaultPortalUrl = exports.uriSkynetPrefix = exports.uriHandshakeResolverPrefix = exports.uriHandshakePrefix = exports.defaultSkynetPortalUrl = void 0;
exports.extractDomainForPortal = exports.getFullDomainUrlForPortal = exports.makeUrl = exports.addUrlQuery = exports.addSubdomain = exports.addPath = exports.defaultPortalUrl = exports.uriSkynetPrefix = exports.uriHandshakePrefix = exports.defaultSkynetPortalUrl = void 0;
const url_parse_1 = __importDefault(require("url-parse"));

@@ -13,5 +13,4 @@ const url_join_1 = __importDefault(require("url-join"));

exports.defaultSkynetPortalUrl = "https://siasky.net";
exports.uriHandshakePrefix = "hns:";
exports.uriHandshakeResolverPrefix = "hnsres:";
exports.uriSkynetPrefix = "sia:";
exports.uriHandshakePrefix = "hns://";
exports.uriSkynetPrefix = "sia://";
// TODO: This will be smarter. See

@@ -39,5 +38,4 @@ // https://github.com/NebulousLabs/skynet-docs/issues/21.

function addPath(url, path) {
if (!path) {
return url;
}
validation_1.validateString("url", url, "parameter");
validation_1.validateString("path", path, "parameter");
path = string_1.trimForwardSlash(path);

@@ -44,0 +42,0 @@ let str;

@@ -76,13 +76,2 @@ /**

/**
* Validates the given value using all the given fns and throws if all of them fail.
*
* @param fns - The functions to validate with.
* @param name - The name of the value.
* @param value - The actual value.
* @param valueKind - The kind of value that is being checked (e.g. "parameter", "response field", etc.)
* @param expected - The expected types.
* @throws - Will throw if all of the given functions throw.
*/
export declare function validateAny(fns: Array<(name: string, value: unknown, valueKind: string) => void>, name: string, value: unknown, valueKind: string, expected: string): void;
/**
* Throws an error for the given value

@@ -89,0 +78,0 @@ *

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.throwValidationError = exports.validateAny = exports.validateUint8ArrayLen = exports.validateUint8Array = exports.validateHexString = exports.validateString = exports.validateNumber = exports.validateOptionalObject = exports.validateObject = exports.validateBigint = void 0;
exports.throwValidationError = exports.validateUint8ArrayLen = exports.validateUint8Array = exports.validateHexString = exports.validateString = exports.validateNumber = exports.validateOptionalObject = exports.validateObject = exports.validateBigint = void 0;
const string_1 = require("./string");

@@ -134,28 +134,2 @@ /**

/**
* Validates the given value using all the given fns and throws if all of them fail.
*
* @param fns - The functions to validate with.
* @param name - The name of the value.
* @param value - The actual value.
* @param valueKind - The kind of value that is being checked (e.g. "parameter", "response field", etc.)
* @param expected - The expected types.
* @throws - Will throw if all of the given functions throw.
*/
function validateAny(fns, name, value, valueKind, expected) {
let success = false;
for (const fn of fns) {
try {
fn(name, value, valueKind);
success = true;
}
catch {
// Don't propogate thrown error.
}
}
if (!success) {
throwValidationError(name, value, valueKind, expected);
}
}
exports.validateAny = validateAny;
/**
* Throws an error for the given value

@@ -162,0 +136,0 @@ *

@@ -76,6 +76,9 @@ import { AxiosResponse } from "axios";

getJSON: (userID: string, path: string, customOptions?: import("./skydb").CustomGetJSONOptions | undefined) => Promise<import("./skydb").JSONResponse>;
getEntryLink: (userID: string, path: string) => Promise<string>;
};
db: {
deleteJSON: (privateKey: string, dataKey: string, customOptions?: import("./skydb").CustomSetJSONOptions | undefined) => Promise<void>;
getJSON: (publicKey: string, dataKey: string, customOptions?: import("./skydb").CustomGetJSONOptions | undefined) => Promise<import("./skydb").JSONResponse>;
setJSON: (privateKey: string, dataKey: string, json: import("./skydb").JsonData, customOptions?: import("./skydb").CustomSetJSONOptions | undefined) => Promise<import("./skydb").JSONResponse>;
setDataLink: (privateKey: string, dataKey: string, dataLink: string, customOptions?: import("./skydb").CustomSetJSONOptions | undefined) => Promise<void>;
};

@@ -82,0 +85,0 @@ registry: {

import axios from "axios";
import { uploadFile, uploadDirectory, uploadDirectoryRequest, uploadFileRequest } from "./upload";
import { downloadFile, downloadFileHns, getSkylinkUrl, getHnsUrl, getHnsresUrl, getMetadata, getFileContent, getFileContentHns, getFileContentRequest, openFile, openFileHns, resolveHns, } from "./download";
import { getJSON as fileGetJSON } from "./file";
import { getJSON, setJSON } from "./skydb";
import { getEntryLink as fileGetEntryLink, getJSON as fileGetJSON } from "./file";
import { deleteJSON, getJSON, setJSON, setDataLink } from "./skydb";
import { getEntry, getEntryUrl, getEntryLink, setEntry, postSignedEntry } from "./registry";

@@ -49,7 +49,10 @@ import { addUrlQuery, defaultPortalUrl, makeUrl } from "./utils/url";

getJSON: fileGetJSON.bind(this),
getEntryLink: fileGetEntryLink.bind(this),
};
// SkyDB
this.db = {
deleteJSON: deleteJSON.bind(this),
getJSON: getJSON.bind(this),
setJSON: setJSON.bind(this),
setDataLink: setDataLink.bind(this),
};

@@ -56,0 +59,0 @@ // SkyDB helpers

@@ -92,9 +92,3 @@ import { misc, codec } from "sjcl";

}
let dataBytes;
if (typeof registryEntry.data === "string") {
dataBytes = encodeUtf8String(registryEntry.data);
}
else {
dataBytes = encodePrefixedBytes(registryEntry.data);
}
const dataBytes = encodePrefixedBytes(registryEntry.data);
return hashAll(dataKeyBytes, dataBytes, encodeBigintAsUint64(registryEntry.revision));

@@ -101,0 +95,0 @@ }

import { SkynetClient } from "./client";
import { JsonData } from "./skydb";
import { BaseCustomOptions } from "./utils/options";

@@ -41,3 +42,2 @@ /**

* @property contentType - The type of the content.
* @property metadata - The metadata in JSON format.
* @property portalUrl - The URL of the portal.

@@ -55,3 +55,2 @@ * @property skylink - 46-character skylink.

*
* @property contentType - The type of the content.
* @property metadata - The metadata in JSON format.

@@ -63,2 +62,4 @@ * @property portalUrl - The URL of the portal.

metadata: Record<string, unknown>;
portalUrl: string;
skylink: string;
};

@@ -71,2 +72,3 @@ /**

export declare type ResolveHnsResponse = {
data: JsonData;
skylink: string;

@@ -217,3 +219,3 @@ };

/**
* Resolves the given HNS domain to its TXT record and returns the data.
* Resolves the given HNS domain to its skylink and returns it and the raw data.
*

@@ -224,3 +226,3 @@ * @param this - SkynetClient

* @param [customOptions.endpointResolveHns="/hnsres"] - The relative URL path of the portal endpoint to contact.
* @returns - The data for the TXT record.
* @returns - The raw data and corresponding skylink.
* @throws - Will throw if the input domain is not a string.

@@ -227,0 +229,0 @@ */

@@ -1,7 +0,7 @@

import { defaultBaseOptions } from "./utils/options";
import { convertSkylinkToBase32, formatSkylink } from "./skylink/format";
import { parseSkylink } from "./skylink/parse";
import { trimUriPrefix } from "./utils/string";
import { addSubdomain, addUrlQuery, makeUrl, uriHandshakePrefix, uriHandshakeResolverPrefix } from "./utils/url";
import { validateOptionalObject, validateString } from "./utils/validation";
import { defaultBaseOptions } from "./utils/options";
import { addSubdomain, addUrlQuery, makeUrl, uriHandshakePrefix } from "./utils/url";
import { throwValidationError, validateObject, validateOptionalObject, validateString } from "./utils/validation";
export const defaultDownloadOptions = {

@@ -185,3 +185,3 @@ ...defaultBaseOptions,

const opts = { ...defaultResolveHnsOptions, ...this.customOptions, ...customOptions };
domain = trimUriPrefix(domain, uriHandshakeResolverPrefix);
domain = trimUriPrefix(domain, uriHandshakePrefix);
const portalUrl = await this.portalUrl();

@@ -202,2 +202,3 @@ return makeUrl(portalUrl, opts.endpointResolveHns, domain);

// Validation is done in `getSkylinkUrl`.
var _a;
const opts = { ...defaultGetMetadataOptions, ...this.customOptions, ...customOptions };

@@ -219,12 +220,8 @@ // Don't include the path for now since the endpoint doesn't support it.

const metadata = response.data;
// TODO: Add back in once the endpoint supports these headers.
// if (typeof response.headers === "undefined") {
// throw new Error(
// "Did not get 'headers' in response despite a successful request. Please try again and report this issue to the devs if it persists."
// );
// }
// const contentType = response.headers["content-type"] ?? "";
// const portalUrl = response.headers["skynet-portal-api"] ?? "";
// const skylink = response.headers["skynet-skylink"] ? formatSkylink(response.headers["skynet-skylink"]) : "";
return { metadata };
if (typeof response.headers === "undefined") {
throw new Error("Did not get 'headers' in response despite a successful request. Please try again and report this issue to the devs if it persists.");
}
const portalUrl = (_a = response.headers["skynet-portal-api"]) !== null && _a !== void 0 ? _a : "";
const skylink = response.headers["skynet-skylink"] ? formatSkylink(response.headers["skynet-skylink"]) : "";
return { metadata, portalUrl, skylink };
}

@@ -330,3 +327,3 @@ /**

/**
* Resolves the given HNS domain to its TXT record and returns the data.
* Resolves the given HNS domain to its skylink and returns it and the raw data.
*

@@ -337,3 +334,3 @@ * @param this - SkynetClient

* @param [customOptions.endpointResolveHns="/hnsres"] - The relative URL path of the portal endpoint to contact.
* @returns - The data for the TXT record.
* @returns - The raw data and corresponding skylink.
* @throws - Will throw if the input domain is not a string.

@@ -353,3 +350,11 @@ */

validateResolveHnsResponse(response);
return response.data;
if (response.data.skylink) {
return { data: response.data, skylink: response.data.skylink };
}
else {
const skylink = await this.registry.getEntryLink(response.data.registry.publickey, response.data.registry.datakey, {
hashedDataKeyHex: true,
});
return { data: response.data, skylink };
}
}

@@ -377,3 +382,13 @@ /**

}
validateString("response.data.skylink", response.data.skylink, "upload response field");
if (response.data.skylink) {
validateString("response.data.skylink", response.data.skylink, "resolveHns response field");
}
else if (response.data.registry) {
validateObject("response.data.registry", response.data.registry, "resolveHns response field");
validateString("response.data.registry.publickey", response.data.registry.publickey, "resolveHns response field");
validateString("response.data.registry.datakey", response.data.registry.datakey, "resolveHns response field");
}
else {
throwValidationError("response.data", response.data, "response data object", "object containing skylink or registry field");
}
}

@@ -380,0 +395,0 @@ catch (err) {

import { SkynetClient } from "./client";
import { CustomGetJSONOptions, JSONResponse } from "./skydb";
/**
* Gets Discoverable JSON at the given data path for the given public user ID.
*
* @param this - SkynetClient
* @param userID - The public user ID.
* @param path - The data path.
* @param [customOptions] - Additional settings that can optionally be set.
* @returns - An object containing the json data as well as the skylink for the data.
*/
export declare function getJSON(this: SkynetClient, userID: string, path: string, customOptions?: CustomGetJSONOptions): Promise<JSONResponse>;
/**
* Gets the entry link for the entry at the given data path, for the given
* public user ID. This is a v2 skylink. This link stays the same even if the
* content at the entry changes.
*
* @param this - SkynetClient
* @param userID - The public user ID.
* @param path - The data path.
* @returns - The entry link.
*/
export declare function getEntryLink(this: SkynetClient, userID: string, path: string): Promise<string>;
//# sourceMappingURL=file.d.ts.map
import { deriveDiscoverableTweak } from "./mysky/tweak";
import { defaultGetEntryOptions } from "./registry";
import { defaultGetJSONOptions } from "./skydb";
import { validateOptionalObject, validateString } from "./utils/validation";
/**
* Gets Discoverable JSON at the given data path for the given public user ID.
*
* @param this - SkynetClient
* @param userID - The public user ID.
* @param path - The data path.
* @param [customOptions] - Additional settings that can optionally be set.
* @returns - An object containing the json data as well as the skylink for the data.
*/
export async function getJSON(userID, path, customOptions) {

@@ -17,1 +27,19 @@ validateString("userID", userID, "parameter");

}
/**
* Gets the entry link for the entry at the given data path, for the given
* public user ID. This is a v2 skylink. This link stays the same even if the
* content at the entry changes.
*
* @param this - SkynetClient
* @param userID - The public user ID.
* @param path - The data path.
* @returns - The entry link.
*/
export async function getEntryLink(userID, path) {
validateString("userID", userID, "parameter");
validateString("path", path, "parameter");
const dataKey = deriveDiscoverableTweak(path);
const opts = defaultGetEntryOptions;
opts.hashedDataKeyHex = true; // Do not hash the tweak anymore.
return await this.registry.getEntryLink(userID, dataKey, opts);
}

@@ -8,9 +8,10 @@ export { SkynetClient } from "./client";

export { parseSkylink } from "./skylink/parse";
export { isSkylinkV1, isSkylinkV2 } from "./skylink/sia";
export { getRelativeFilePath, getRootDirectory } from "./utils/file";
export { MAX_REVISION } from "./utils/number";
export { stringToUint8ArrayUtf8, uint8ArrayToStringUtf8 } from "./utils/string";
export { defaultPortalUrl, defaultSkynetPortalUrl, extractDomainForPortal, getFullDomainUrlForPortal, uriHandshakePrefix, uriHandshakeResolverPrefix, uriSkynetPrefix, } from "./utils/url";
export { defaultPortalUrl, defaultSkynetPortalUrl, extractDomainForPortal, getFullDomainUrlForPortal, uriHandshakePrefix, uriSkynetPrefix, } from "./utils/url";
export { Permission, PermCategory, PermType, PermRead, PermWrite, PermHidden, PermDiscoverable, PermLegacySkyID, } from "skynet-mysky-utils";
export type { CustomClientOptions, RequestConfig } from "./client";
export type { Signature } from "./crypto";
export type { KeyPair, KeyPairAndSeed, Signature } from "./crypto";
export type { CustomDownloadOptions, ResolveHnsResponse } from "./download";

@@ -17,0 +18,0 @@ export type { CustomConnectorOptions, MySky } from "./mysky";

@@ -8,7 +8,8 @@ export { SkynetClient } from "./client";

export { parseSkylink } from "./skylink/parse";
export { isSkylinkV1, isSkylinkV2 } from "./skylink/sia";
export { getRelativeFilePath, getRootDirectory } from "./utils/file";
export { MAX_REVISION } from "./utils/number";
export { stringToUint8ArrayUtf8, uint8ArrayToStringUtf8 } from "./utils/string";
export { defaultPortalUrl, defaultSkynetPortalUrl, extractDomainForPortal, getFullDomainUrlForPortal, uriHandshakePrefix, uriHandshakeResolverPrefix, uriSkynetPrefix, } from "./utils/url";
export { defaultPortalUrl, defaultSkynetPortalUrl, extractDomainForPortal, getFullDomainUrlForPortal, uriHandshakePrefix, uriSkynetPrefix, } from "./utils/url";
// Re-export Permission API.
export { Permission, PermCategory, PermType, PermRead, PermWrite, PermHidden, PermDiscoverable, PermLegacySkyID, } from "skynet-mysky-utils";

@@ -15,2 +15,10 @@ export type { CustomConnectorOptions } from "./connector";

export declare const mySkyAlphaDomain = "sandbridge.hns";
/**
* Loads MySky. Note that this does not log in the user.
*
* @param this - The Skynet client.
* @param skappDomain - The domain of the host skapp. For this domain permissions will be requested and, by default, automatically granted.
* @param [customOptions] - Additional settings that can optionally be set.
* @returns - Loaded (but not logged-in) MySky instance.
*/
export declare function loadMySky(this: SkynetClient, skappDomain?: string, customOptions?: CustomConnectorOptions): Promise<MySky>;

@@ -28,2 +36,4 @@ export declare class MySky {

* Loads the given DACs.
*
* @param dacs - The DAC library instances to call `init` on.
*/

@@ -47,3 +57,3 @@ loadDacs(...dacs: DacLibrary[]): Promise<void>;

/**
* Gets Discoverable JSON at the given path through MySky, if the user has given permissions to do so.
* Gets Discoverable JSON at the given path through MySky, if the user has given Read permissions to do so.
*

@@ -64,3 +74,3 @@ * @param path - The data path.

/**
* Sets Discoverable JSON at the given path through MySky, if the user has given permissions to do so.
* Sets Discoverable JSON at the given path through MySky, if the user has given Write permissions to do so.
*

@@ -82,2 +92,11 @@ * @param path - The data path.

setDataLink(path: string, dataLink: string, customOptions?: CustomSetJSONOptions): Promise<void>;
/**
* Deletes Discoverable JSON at the given path through MySky, if the user has given Write permissions to do so.
*
* @param path - The data path.
* @param [customOptions] - Additional settings that can optionally be set.
* @returns - An empty promise.
* @throws - Will throw if the revision is already the maximum value.
*/
deleteJSON(path: string, customOptions?: CustomSetJSONOptions): Promise<void>;
protected catchError(errorMsg: string): Promise<void>;

@@ -84,0 +103,0 @@ protected launchUI(): Promise<Window>;

@@ -6,10 +6,7 @@ export { DacLibrary } from "./dac";

import { defaultGetEntryOptions, defaultSetEntryOptions } from "../registry";
import { defaultGetJSONOptions, defaultSetJSONOptions, getOrCreateRegistryEntry, getRevisionFromSignedEntry, } from "../skydb";
import { hexToUint8Array, trimUriPrefix } from "../utils/string";
import { defaultGetJSONOptions, defaultSetJSONOptions, getOrCreateRegistryEntry, getDataLinkRegistryEntry, getDeletionRegistryEntry, } from "../skydb";
import { deriveDiscoverableTweak } from "./tweak";
import { popupCenter } from "./utils";
import { extractOptions } from "../utils/options";
import { validateObject, validateOptionalObject, validateString } from "../utils/validation";
import { extractOptions } from "../utils/options";
import { uriSkynetPrefix } from "../utils/url";
import { base64RawUrlToUint8Array } from "../utils/encoding";
export const mySkyDomain = "skynet-mysky.hns";

@@ -21,2 +18,10 @@ export const mySkyDevDomain = "skynet-mysky-dev.hns";

const [mySkyUiW, mySkyUiH] = [600, 600];
/**
* Loads MySky. Note that this does not log in the user.
*
* @param this - The Skynet client.
* @param skappDomain - The domain of the host skapp. For this domain permissions will be requested and, by default, automatically granted.
* @param [customOptions] - Additional settings that can optionally be set.
* @returns - Loaded (but not logged-in) MySky instance.
*/
export async function loadMySky(skappDomain, customOptions) {

@@ -33,3 +38,5 @@ const mySky = await MySky.New(this, skappDomain, customOptions);

this.hostDomain = hostDomain;
// Holds the loaded DACs.
this.dacs = [];
// Holds the currently granted permissions.
this.grantedPermissions = [];

@@ -68,2 +75,4 @@ this.pendingPermissions = permissions;

* Loads the given DACs.
*
* @param dacs - The DAC library instances to call `init` on.
*/

@@ -176,3 +185,3 @@ async loadDacs(...dacs) {

/**
* Gets Discoverable JSON at the given path through MySky, if the user has given permissions to do so.
* Gets Discoverable JSON at the given path through MySky, if the user has given Read permissions to do so.
*

@@ -212,3 +221,3 @@ * @param path - The data path.

/**
* Sets Discoverable JSON at the given path through MySky, if the user has given permissions to do so.
* Sets Discoverable JSON at the given path through MySky, if the user has given Write permissions to do so.
*

@@ -232,3 +241,3 @@ * @param path - The data path.

opts.hashedDataKeyHex = true; // Do not hash the tweak anymore.
const [entry, dataLink] = await getOrCreateRegistryEntry(this.connector.client, hexToUint8Array(publicKey), dataKey, json, opts);
const [entry, dataLink] = await getOrCreateRegistryEntry(this.connector.client, publicKey, dataKey, json, opts);
const signature = await this.signRegistryEntry(entry, path);

@@ -259,15 +268,27 @@ const setEntryOpts = extractOptions(opts, defaultSetEntryOptions);

opts.hashedDataKeyHex = true; // Do not hash the tweak anymore.
// Get the latest entry.
// TODO: Can remove this once we start caching the latest revision.
const getEntryOpts = extractOptions(opts, defaultGetEntryOptions);
const signedEntry = await this.connector.client.registry.getEntry(publicKey, dataKey, getEntryOpts);
const revision = getRevisionFromSignedEntry(signedEntry);
// Add padding
const paddedDataLink = `${trimUriPrefix(dataLink, uriSkynetPrefix)}==`;
// Build the registry entry.
const entry = {
dataKey,
data: base64RawUrlToUint8Array(paddedDataLink),
revision,
const entry = await getDataLinkRegistryEntry(this.connector.client, publicKey, dataKey, dataLink, opts);
const signature = await this.signRegistryEntry(entry, path);
const setEntryOpts = extractOptions(opts, defaultSetEntryOptions);
await this.connector.client.registry.postSignedEntry(publicKey, entry, signature, setEntryOpts);
}
/**
* Deletes Discoverable JSON at the given path through MySky, if the user has given Write permissions to do so.
*
* @param path - The data path.
* @param [customOptions] - Additional settings that can optionally be set.
* @returns - An empty promise.
* @throws - Will throw if the revision is already the maximum value.
*/
async deleteJSON(path, customOptions) {
validateString("path", path, "parameter");
validateOptionalObject("customOptions", customOptions, "parameter", defaultSetJSONOptions);
const opts = {
...defaultSetJSONOptions,
...this.connector.client.customOptions,
...customOptions,
};
const publicKey = await this.userID();
const dataKey = deriveDiscoverableTweak(path);
opts.hashedDataKeyHex = true; // Do not hash the tweak anymore.
const entry = await getDeletionRegistryEntry(this.connector.client, publicKey, dataKey, opts);
const signature = await this.signRegistryEntry(entry, path);

@@ -274,0 +295,0 @@ const setEntryOpts = extractOptions(opts, defaultSetEntryOptions);

@@ -22,4 +22,10 @@ import { SkynetClient } from "../client";

* Create a new popup window. From SkyID.
*
* @param url - The URL to open.
* @param title - The title of the popup window.
* @param w - The width of the popup window.
* @param h - the height of the popup window.
* @returns - The window.
*/
export declare function popupCenter(url: string, title: string, w: number, h: number): Window;
//# sourceMappingURL=utils.d.ts.map

@@ -29,3 +29,10 @@ import { ensureUrl } from "skynet-mysky-utils";

* Create a new popup window. From SkyID.
*
* @param url - The URL to open.
* @param title - The title of the popup window.
* @param w - The width of the popup window.
* @param h - the height of the popup window.
* @returns - The window.
*/
/* istanbul ignore next */
export function popupCenter(url, title, w, h) {

@@ -32,0 +39,0 @@ url = ensureUrl(url);

@@ -122,5 +122,30 @@ import { SkynetClient } from "./client";

export declare function setEntry(this: SkynetClient, privateKey: string, entry: RegistryEntry, customOptions?: CustomSetEntryOptions): Promise<void>;
/**
* Signs the entry with the given private key.
*
* @param privateKey - The user private key.
* @param entry - The entry to sign.
* @param hashedDataKeyHex - Whether the data key is already hashed and in hex format. If not, we hash the data key.
* @returns - The signature.
*/
export declare function signEntry(privateKey: string, entry: RegistryEntry, hashedDataKeyHex: boolean): Promise<Uint8Array>;
/**
* Posts the entry with the given public key and signature to Skynet.
*
* @param this - The Skynet client.
* @param publicKey - The user public key.
* @param entry - The entry to set.
* @param signature - The signature.
* @param [customOptions] - Additional settings that can optionally be set.
* @returns - An empty promise.
*/
export declare function postSignedEntry(this: SkynetClient, publicKey: string, entry: RegistryEntry, signature: Uint8Array, customOptions?: CustomSetEntryOptions): Promise<void>;
/**
* Validates the given registry entry.
*
* @param name - The name of the value.
* @param value - The actual value.
* @param valueKind - The kind of value that is being checked (e.g. "parameter", "response field", etc.)
*/
export declare function validateRegistryEntry(name: string, value: unknown, valueKind: string): void;
//# sourceMappingURL=registry.d.ts.map

@@ -8,3 +8,3 @@ import { Buffer } from "buffer";

import { hashDataKey, hashRegistryEntry } from "./crypto";
import { validateBigint, validateHexString, validateObject, validateOptionalObject, validateString, validateUint8Array, } from "./utils/validation";
import { throwValidationError, validateBigint, validateHexString, validateObject, validateOptionalObject, validateString, validateUint8Array, } from "./utils/validation";
import { newEd25519PublicKey, newSkylinkV2 } from "./skylink/sia";

@@ -151,5 +151,3 @@ import { formatSkylink } from "./skylink/format";

publicKey = trimPrefix(publicKey, "ed25519:");
if (!isHexString(publicKey)) {
throw new Error(`Given public key '${publicKey}' is not a valid hex-encoded string or contains an invalid prefix`);
}
validateTrimmedPublicKey("publicKey", publicKey, "parameter");
// Hash and hex encode the given data key if it is not a hash already.

@@ -189,5 +187,3 @@ let dataKeyHashHex = dataKey;

publicKey = trimPrefix(publicKey, "ed25519:");
if (!isHexString(publicKey)) {
throw new Error(`Given public key '${publicKey}' is not a valid hex-encoded string or contains an invalid prefix`);
}
validateTrimmedPublicKey("publicKey", publicKey, "parameter");
const siaPublicKey = newEd25519PublicKey(publicKey);

@@ -230,2 +226,10 @@ let tweak;

}
/**
* Signs the entry with the given private key.
*
* @param privateKey - The user private key.
* @param entry - The entry to sign.
* @param hashedDataKeyHex - Whether the data key is already hashed and in hex format. If not, we hash the data key.
* @returns - The signature.
*/
export async function signEntry(privateKey, entry, hashedDataKeyHex) {

@@ -238,2 +242,12 @@ // TODO: Publicly available, validate input.

}
/**
* Posts the entry with the given public key and signature to Skynet.
*
* @param this - The Skynet client.
* @param publicKey - The user public key.
* @param entry - The entry to set.
* @param signature - The signature.
* @param [customOptions] - Additional settings that can optionally be set.
* @returns - An empty promise.
*/
export async function postSignedEntry(publicKey, entry, signature, customOptions) {

@@ -283,2 +297,9 @@ validateHexString("publicKey", publicKey, "parameter");

}
/**
* Validates the given registry entry.
*
* @param name - The name of the value.
* @param value - The actual value.
* @param valueKind - The kind of value that is being checked (e.g. "parameter", "response field", etc.)
*/
export function validateRegistryEntry(name, value, valueKind) {

@@ -312,1 +333,14 @@ validateObject(name, value, valueKind);

}
/**
* Validates the given value as a hex-encoded public key.
*
* @param name - The name of the value.
* @param publicKey - The public key.
* @param valueKind - The kind of value that is being checked (e.g. "parameter", "response field", etc.)
* @throws - Will throw if not a valid hex-encoded public key.
*/
function validateTrimmedPublicKey(name, publicKey, valueKind) {
if (!isHexString(publicKey)) {
throwValidationError(name, publicKey, valueKind, "a hex-encoded string with a valid prefix");
}
}
import { SkynetClient } from "./client";
import { CustomGetEntryOptions, RegistryEntry, SignedRegistryEntry, CustomSetEntryOptions } from "./registry";
import { CustomDownloadOptions } from "./download";
import { CustomGetEntryOptions, RegistryEntry, CustomSetEntryOptions } from "./registry";
import { CustomUploadOptions } from "./upload";
import { CustomDownloadOptions } from "./download";
export declare const JSON_RESPONSE_VERSION = 2;
export declare type JsonData = Record<string, unknown>;

@@ -75,7 +74,32 @@ /**

* @param [customOptions] - Additional settings that can optionally be set.
* @returns - The returned JSON and revision number.
* @throws - Will throw if the input keys are not valid strings.
*/
export declare function setJSON(this: SkynetClient, privateKey: string, dataKey: string, json: JsonData, customOptions?: CustomSetJSONOptions): Promise<JSONResponse>;
export declare function getOrCreateRegistryEntry(client: SkynetClient, publicKeyArray: Uint8Array, dataKey: string, json: JsonData, customOptions?: CustomSetJSONOptions): Promise<[RegistryEntry, string]>;
export declare function getRevisionFromSignedEntry(signedEntry: SignedRegistryEntry): bigint;
/**
* Deletes a JSON object at the registry entry corresponding to the publicKey and dataKey.
*
* @param this - SkynetClient
* @param privateKey - The user private key.
* @param dataKey - The key of the data to fetch for the given user.
* @param [customOptions] - Additional settings that can optionally be set.
* @throws - Will throw if the input keys are not valid strings.
*/
export declare function deleteJSON(this: SkynetClient, privateKey: string, dataKey: string, customOptions?: CustomSetJSONOptions): Promise<void>;
export declare function getDeletionRegistryEntry(client: SkynetClient, publicKey: string, dataKey: string, customOptions?: CustomGetJSONOptions): Promise<RegistryEntry>;
export declare function setDataLink(this: SkynetClient, privateKey: string, dataKey: string, dataLink: string, customOptions?: CustomSetJSONOptions): Promise<void>;
export declare function getDataLinkRegistryEntry(client: SkynetClient, publicKey: string, dataKey: string, dataLink: string, customOptions?: CustomSetJSONOptions): Promise<RegistryEntry>;
/**
* Gets the registry entry and data link or creates the entry if it doesn't exist.
*
* @param client - The Skynet client.
* @param publicKeyArray - The user public key.
* @param dataKey - The dat akey.
* @param json - The JSON to set.
* @param [customOptions] - Additional settings that can optionally be set.
* @returns - The registry entry and corresponding data link.
* @throws - Will throw if the revision is already the maximum value.
*/
export declare function getOrCreateRegistryEntry(client: SkynetClient, publicKey: string, dataKey: string, json: JsonData, customOptions?: CustomSetJSONOptions): Promise<[RegistryEntry, string]>;
export declare function getRevisionFromEntry(entry: RegistryEntry | null): bigint;
//# sourceMappingURL=skydb.d.ts.map
import { sign } from "tweetnacl";
import { defaultDownloadOptions } from "./download";
import { defaultGetEntryOptions, defaultSetEntryOptions, } from "./registry";
import { RAW_SKYLINK_SIZE } from "./skylink/sia";
import { EMPTY_SKYLINK, RAW_SKYLINK_SIZE } from "./skylink/sia";
import { assertUint64, MAX_REVISION } from "./utils/number";
import { uriSkynetPrefix } from "./utils/url";
import { hexToUint8Array, trimUriPrefix, toHexString, stringToUint8ArrayUtf8, trimSuffix, uint8ArrayToStringUtf8, } from "./utils/string";
import { formatSkylink } from "./skylink/format";
import { parseSkylink } from "./skylink/parse";
import { defaultUploadOptions } from "./upload";
import { defaultDownloadOptions } from "./download";
import { base64RawUrlToUint8Array, uint8ArrayToBase64RawUrl } from "./utils/encoding";
import { defaultBaseOptions, extractOptions } from "./utils/options";
import { validateHexString, validateObject, validateOptionalObject, validateString, validateUint8ArrayLen, } from "./utils/validation";
export const JSON_RESPONSE_VERSION = 2;
import { areEqualUint8Arrays } from "./utils/array";
const JSON_RESPONSE_VERSION = 2;
export const defaultGetJSONOptions = {

@@ -46,3 +49,3 @@ ...defaultBaseOptions,

const { entry } = await this.registry.getEntry(publicKey, dataKey, getEntryOpts);
if (entry === null) {
if (entry === null || areEqualUint8Arrays(entry.data, EMPTY_SKYLINK)) {
return { data: null, dataLink: null };

@@ -55,11 +58,11 @@ }

}
let dataLink;
let rawDataLink;
if (entry.data.length === 46) {
// Legacy data, convert to string.
dataLink = uint8ArrayToStringUtf8(entry.data);
rawDataLink = uint8ArrayToStringUtf8(entry.data);
}
else if (entry.data.length === RAW_SKYLINK_SIZE) {
// Convert the bytes to a base64 skylink.
dataLink = uint8ArrayToBase64RawUrl(entry.data);
dataLink = trimSuffix(dataLink, "=");
rawDataLink = uint8ArrayToBase64RawUrl(entry.data);
rawDataLink = trimSuffix(rawDataLink, "=");
}

@@ -69,4 +72,5 @@ else {

}
const dataLink = formatSkylink(rawDataLink);
// If a cached data link is provided and the data link hasn't changed, return.
if (opts.cachedDataLink && dataLink === opts.cachedDataLink) {
if (opts.cachedDataLink && rawDataLink === parseSkylink(opts.cachedDataLink)) {
return { data: null, dataLink };

@@ -98,2 +102,3 @@ }

* @param [customOptions] - Additional settings that can optionally be set.
* @returns - The returned JSON and revision number.
* @throws - Will throw if the input keys are not valid strings.

@@ -112,15 +117,108 @@ */

const { publicKey: publicKeyArray } = sign.keyPair.fromSecretKey(hexToUint8Array(privateKey));
const [entry, skylink] = await getOrCreateRegistryEntry(this, publicKeyArray, dataKey, json, opts);
const [entry, dataLink] = await getOrCreateRegistryEntry(this, toHexString(publicKeyArray), dataKey, json, opts);
// Update the registry.
const setEntryOpts = extractOptions(opts, defaultSetEntryOptions);
await this.registry.setEntry(privateKey, entry, setEntryOpts);
return { data: json, dataLink: skylink };
return { data: json, dataLink: formatSkylink(dataLink) };
}
export async function getOrCreateRegistryEntry(client, publicKeyArray, dataKey, json, customOptions) {
/**
* Deletes a JSON object at the registry entry corresponding to the publicKey and dataKey.
*
* @param this - SkynetClient
* @param privateKey - The user private key.
* @param dataKey - The key of the data to fetch for the given user.
* @param [customOptions] - Additional settings that can optionally be set.
* @throws - Will throw if the input keys are not valid strings.
*/
export async function deleteJSON(privateKey, dataKey, customOptions) {
validateHexString("privateKey", privateKey, "parameter");
validateString("dataKey", dataKey, "parameter");
validateOptionalObject("customOptions", customOptions, "parameter", defaultSetJSONOptions);
const opts = {
...defaultSetJSONOptions,
...this.customOptions,
...customOptions,
};
const { publicKey: publicKeyArray } = sign.keyPair.fromSecretKey(hexToUint8Array(privateKey));
const entry = await getDeletionRegistryEntry(this, toHexString(publicKeyArray), dataKey, opts);
// Update the registry.
const setEntryOpts = extractOptions(opts, defaultSetEntryOptions);
await this.registry.setEntry(privateKey, entry, setEntryOpts);
}
export async function getDeletionRegistryEntry(client, publicKey, dataKey, customOptions) {
// Not publicly available, don't validate input.
const opts = {
...defaultGetJSONOptions,
...client.customOptions,
...customOptions,
};
// Fetch the current value to find out the revision.
const getEntryOpts = extractOptions(opts, defaultGetEntryOptions);
const signedEntry = await client.registry.getEntry(publicKey, dataKey, getEntryOpts);
const revision = getRevisionFromEntry(signedEntry.entry);
// Build the registry value. Use empty bytes for the data.
const data = new Uint8Array(RAW_SKYLINK_SIZE);
const entry = {
dataKey,
data,
revision,
};
return entry;
}
export async function setDataLink(privateKey, dataKey, dataLink, customOptions) {
validateHexString("privateKey", privateKey, "parameter");
validateString("dataKey", dataKey, "parameter");
validateString("dataLink", dataLink, "parameter");
validateOptionalObject("customOptions", customOptions, "parameter", defaultSetJSONOptions);
const opts = {
...defaultSetJSONOptions,
...this.customOptions,
...customOptions,
};
const { publicKey: publicKeyArray } = sign.keyPair.fromSecretKey(hexToUint8Array(privateKey));
const entry = await getDataLinkRegistryEntry(this, toHexString(publicKeyArray), dataKey, dataLink, opts);
// Update the registry.
const setEntryOpts = extractOptions(opts, defaultSetEntryOptions);
await this.registry.setEntry(privateKey, entry, setEntryOpts);
}
export async function getDataLinkRegistryEntry(client, publicKey, dataKey, dataLink, customOptions) {
// Not publicly available, don't validate input.
const opts = {
...defaultSetJSONOptions,
...client.customOptions,
...customOptions,
};
// Get the latest entry.
// TODO: Can remove this once we start caching the latest revision.
const getEntryOpts = extractOptions(opts, defaultGetEntryOptions);
const signedEntry = await client.registry.getEntry(publicKey, dataKey, getEntryOpts);
const revision = getRevisionFromEntry(signedEntry.entry);
// Add padding
const paddedDataLink = `${trimUriPrefix(dataLink, uriSkynetPrefix)}==`;
// Build the registry entry.
const entry = {
dataKey,
data: base64RawUrlToUint8Array(paddedDataLink),
revision,
};
return entry;
}
/**
* Gets the registry entry and data link or creates the entry if it doesn't exist.
*
* @param client - The Skynet client.
* @param publicKeyArray - The user public key.
* @param dataKey - The dat akey.
* @param json - The JSON to set.
* @param [customOptions] - Additional settings that can optionally be set.
* @returns - The registry entry and corresponding data link.
* @throws - Will throw if the revision is already the maximum value.
*/
export async function getOrCreateRegistryEntry(client, publicKey, dataKey, json, customOptions) {
// Not publicly available, don't validate input.
const opts = {
...defaultSetJSONOptions,
...client.customOptions,
...customOptions,
};
// Set the hidden _data and _v fields.

@@ -141,3 +239,3 @@ const fullData = { _data: json, _v: JSON_RESPONSE_VERSION };

const getEntryOpts = extractOptions(opts, defaultGetEntryOptions);
const entryPromise = client.registry.getEntry(toHexString(publicKeyArray), dataKey, getEntryOpts);
const entryPromise = client.registry.getEntry(publicKey, dataKey, getEntryOpts);
// Block until both getEntry and uploadFile are finished.

@@ -148,3 +246,3 @@ const [signedEntry, skyfile] = await Promise.all([

]);
const revision = getRevisionFromSignedEntry(signedEntry);
const revision = getRevisionFromEntry(signedEntry.entry);
// Build the registry entry.

@@ -162,11 +260,11 @@ const dataLink = skyfile.skylink;

};
return [entry, dataLink];
return [entry, formatSkylink(dataLink)];
}
export function getRevisionFromSignedEntry(signedEntry) {
export function getRevisionFromEntry(entry) {
let revision;
if (signedEntry.entry === null) {
if (entry === null) {
revision = BigInt(0);
}
else {
revision = signedEntry.entry.revision + BigInt(1);
revision = entry.revision + BigInt(1);
}

@@ -173,0 +271,0 @@ // Throw if the revision is already the maximum value.

@@ -21,3 +21,3 @@ import base64 from "base64-js";

export function formatSkylink(skylink) {
if (skylink == "") {
if (skylink === "") {
return skylink;

@@ -24,0 +24,0 @@ }

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

/**
* The raw size in bytes of the data that gets put into a link.
*/
export declare const RAW_SKYLINK_SIZE = 34;
/**
* An empty skylink.
*/
export declare const EMPTY_SKYLINK: Uint8Array;
export declare class SiaSkylink {

@@ -10,2 +17,14 @@ bitfield: number;

/**
* Checks if the given string is a v1 skylink.
*
* @param s
*/
export declare function isSkylinkV1(s: string): boolean;
/**
* Checks if the given string is a v2 skylink.
*
* @param s
*/
export declare function isSkylinkV2(s: string): boolean;
/**
* Returns a specifier for given name, a specifier can only be 16 bytes so we

@@ -39,3 +58,12 @@ * panic if the given name is too long.

export declare function newSkylinkV2(siaPublicKey: SiaPublicKey, tweak: Uint8Array): SiaSkylink;
/**
* A helper function that decodes the given string representation of a skylink
* into raw bytes. It either performs a base32 decoding, or base64 decoding,
* depending on the length.
*
* @param encoded - The encoded string.
* @returns - The decoded raw bytes.
*/
export declare function decodeSkylink(encoded: string): Uint8Array;
export {};
//# sourceMappingURL=sia.d.ts.map

@@ -1,8 +0,27 @@

import { fromByteArray } from "base64-js";
import base32Decode from "base32-decode";
import { hashAll } from "../crypto";
import { encodePrefixedBytes } from "../utils/encoding";
import { hexToUint8Array, isASCIIString, stringToUint8ArrayUtf8, trimSuffix } from "../utils/string";
import { validateHexString, validateNumber, validateUint8ArrayLen } from "../utils/validation";
// The raw size of the data that gets put into a link.
import { base64RawUrlToUint8Array, uint8ArrayToBase64RawUrl, encodePrefixedBytes } from "../utils/encoding";
import { hexToUint8Array, stringToUint8ArrayUtf8, trimSuffix } from "../utils/string";
import { validateHexString, validateNumber, validateString, validateUint8ArrayLen } from "../utils/validation";
/**
* The string length of the Skylink after it has been encoded using base32.
*/
const BASE32_ENCODED_SKYLINK_SIZE = 55;
/**
* The string length of the Skylink after it has been encoded using base64.
*/
const BASE64_ENCODED_SKYLINK_SIZE = 46;
/**
* Returned when a string could not be decoded into a Skylink due to it having
* an incorrect size.
*/
const ERR_SKYLINK_INCORRECT_SIZE = "skylink has incorrect size";
/**
* The raw size in bytes of the data that gets put into a link.
*/
export const RAW_SKYLINK_SIZE = 34;
/**
* An empty skylink.
*/
export const EMPTY_SKYLINK = new Uint8Array(RAW_SKYLINK_SIZE);
export class SiaSkylink {

@@ -24,5 +43,3 @@ constructor(bitfield, merkleRoot) {

toString() {
let base64 = fromByteArray(this.toBytes());
// Change to URL encoding.
base64 = base64.replace(/\+/g, "-").replace(/\//g, "_");
const base64 = uint8ArrayToBase64RawUrl(this.toBytes());
// Remove padding characters.

@@ -32,2 +49,45 @@ return trimSuffix(base64, "=");

}
/**
* Checks if the given string is a v1 skylink.
*
* @param s
*/
export function isSkylinkV1(s) {
const raw = decodeSkylink(s);
// Load and check the bitfield.
const view = new DataView(raw.buffer);
const bitfield = view.getUint16(0, true);
return isBitfieldSkylinkV1(bitfield);
}
/**
* Checks if the given string is a v2 skylink.
*
* @param s
*/
export function isSkylinkV2(s) {
// Decode the base into raw data.
const raw = decodeSkylink(s);
// Load and check the bitfield.
const view = new DataView(raw.buffer);
const bitfield = view.getUint16(0, true);
return isBitfieldSkylinkV2(bitfield);
}
/**
* Returns a boolean indicating if the Skylink is a V1 skylink
*
* @param bitfield
*/
function isBitfieldSkylinkV1(bitfield) {
return (bitfield & 3) === 0;
}
/**
* Returns a boolean indicating if the Skylink is a V2 skylink
*
* @param bitfield
*/
function isBitfieldSkylinkV2(bitfield) {
// We compare against 1 here because a V2 skylink only uses the version
// bits. All other bits should be set to 0.
return bitfield == 1;
}
const SPECIFIER_LEN = 16;

@@ -42,3 +102,3 @@ /**

export function newSpecifier(name) {
validateSpecifier(name);
validateString("name", name, "parameter");
const specifier = new Uint8Array(SPECIFIER_LEN);

@@ -88,2 +148,30 @@ specifier.set(stringToUint8ArrayUtf8(name));

/**
* A helper function that decodes the given string representation of a skylink
* into raw bytes. It either performs a base32 decoding, or base64 decoding,
* depending on the length.
*
* @param encoded - The encoded string.
* @returns - The decoded raw bytes.
*/
export function decodeSkylink(encoded) {
let bytes;
if (encoded.length === BASE32_ENCODED_SKYLINK_SIZE) {
encoded = encoded.toUpperCase();
bytes = new Uint8Array(base32Decode(encoded, "RFC4648-HEX"));
}
else if (encoded.length === BASE64_ENCODED_SKYLINK_SIZE) {
// Add padding.
encoded = `${encoded}==`;
bytes = base64RawUrlToUint8Array(encoded);
}
else {
throw new Error(ERR_SKYLINK_INCORRECT_SIZE);
}
// Sanity check the size of the given data.
if (bytes.length != RAW_SKYLINK_SIZE) {
throw new Error("failed to load skylink data");
}
return bytes;
}
/**
* A helper to derive an entry id for a registry key value pair. Matches `DeriveRegistryEntryID` in sia.

@@ -98,17 +186,1 @@ *

}
/**
* Performs validation checks on the specifier name, it panics when the input is
* invalid seeing we want to catch this on runtime.
* Matches `validateSpecifier` in sia.
*
* @param name - The specifier name.
* @throws - Will throw if the specifier name is not valid.
*/
function validateSpecifier(name) {
if (!isASCIIString(name)) {
throw new Error("specifier has to be ASCII");
}
if (name.length > SPECIFIER_LEN) {
throw new Error("specifier max length exceeded");
}
}
/**
* Returns a boolean indicating whether the String contains only ASCII bytes.
* From https://stackoverflow.com/a/14313213/6085242.
*
* @param str - The input string.
* @returns - Whether the string is ASCII.
*/
export declare function isASCIIString(str: string): boolean;
/**
* Removes slashes from the beginning and end of the string.

@@ -11,0 +3,0 @@ *

import { Buffer } from "buffer";
import { throwValidationError, validateHexString, validateString } from "./validation";
/**
* Returns a boolean indicating whether the String contains only ASCII bytes.
* From https://stackoverflow.com/a/14313213/6085242.
*
* @param str - The input string.
* @returns - Whether the string is ASCII.
*/
export function isASCIIString(str) {
// eslint-disable-next-line
return /^[\x00-\x7F]*$/.test(str);
}
/**
* Removes slashes from the beginning and end of the string.

@@ -73,10 +62,10 @@ *

export function trimUriPrefix(str, prefix) {
const longPrefix = `${prefix}//`;
if (str.startsWith(longPrefix)) {
const shortPrefix = trimSuffix(prefix, "/");
if (str.startsWith(prefix)) {
// longPrefix is exactly at the beginning
return str.slice(longPrefix.length);
return str.slice(prefix.length);
}
if (str.startsWith(prefix)) {
if (str.startsWith(shortPrefix)) {
// else prefix is exactly at the beginning
return str.slice(prefix.length);
return str.slice(shortPrefix.length);
}

@@ -83,0 +72,0 @@ return str;

export declare const defaultSkynetPortalUrl = "https://siasky.net";
export declare const uriHandshakePrefix = "hns:";
export declare const uriHandshakeResolverPrefix = "hnsres:";
export declare const uriSkynetPrefix = "sia:";
export declare const uriHandshakePrefix = "hns://";
export declare const uriSkynetPrefix = "sia://";
/**

@@ -6,0 +5,0 @@ * Returns the default portal URL.

@@ -6,5 +6,4 @@ import parse from "url-parse";

export const defaultSkynetPortalUrl = "https://siasky.net";
export const uriHandshakePrefix = "hns:";
export const uriHandshakeResolverPrefix = "hnsres:";
export const uriSkynetPrefix = "sia:";
export const uriHandshakePrefix = "hns://";
export const uriSkynetPrefix = "sia://";
// TODO: This will be smarter. See

@@ -31,5 +30,4 @@ // https://github.com/NebulousLabs/skynet-docs/issues/21.

export function addPath(url, path) {
if (!path) {
return url;
}
validateString("url", url, "parameter");
validateString("path", path, "parameter");
path = trimForwardSlash(path);

@@ -36,0 +34,0 @@ let str;

@@ -76,13 +76,2 @@ /**

/**
* Validates the given value using all the given fns and throws if all of them fail.
*
* @param fns - The functions to validate with.
* @param name - The name of the value.
* @param value - The actual value.
* @param valueKind - The kind of value that is being checked (e.g. "parameter", "response field", etc.)
* @param expected - The expected types.
* @throws - Will throw if all of the given functions throw.
*/
export declare function validateAny(fns: Array<(name: string, value: unknown, valueKind: string) => void>, name: string, value: unknown, valueKind: string, expected: string): void;
/**
* Throws an error for the given value

@@ -89,0 +78,0 @@ *

@@ -123,27 +123,2 @@ import { isHexString } from "./string";

/**
* Validates the given value using all the given fns and throws if all of them fail.
*
* @param fns - The functions to validate with.
* @param name - The name of the value.
* @param value - The actual value.
* @param valueKind - The kind of value that is being checked (e.g. "parameter", "response field", etc.)
* @param expected - The expected types.
* @throws - Will throw if all of the given functions throw.
*/
export function validateAny(fns, name, value, valueKind, expected) {
let success = false;
for (const fn of fns) {
try {
fn(name, value, valueKind);
success = true;
}
catch {
// Don't propogate thrown error.
}
}
if (!success) {
throwValidationError(name, value, valueKind, expected);
}
}
/**
* Throws an error for the given value

@@ -150,0 +125,0 @@ *

{
"name": "skynet-js",
"version": "4.0.7-beta",
"version": "4.0.8-beta",
"description": "Sia Skynet Javascript Client",

@@ -10,4 +10,4 @@ "main": "dist/cjs/index.js",

".": {
"import": "./dist/mjs/index.js",
"require": "./dist/cjs/index.js"
"import": "./dist/mjs/index.js",
"require": "./dist/cjs/index.js"
}

@@ -58,2 +58,3 @@ },

"axios": "^0.21.0",
"base32-decode": "^1.0.0",
"base32-encode": "^1.1.1",

@@ -60,0 +61,0 @@ "base64-js": "^1.3.1",

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

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

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

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

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

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

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