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

@substrate/connect

Package Overview
Dependencies
Maintainers
16
Versions
113
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@substrate/connect - npm Package Compare versions

Comparing version 0.8.11 to 1.0.0

105

dist/index.d.ts

@@ -1,95 +0,5 @@

/**
* List of popular chains that are likely to be connected to.
*
* The values in this enum correspond to the `id` field of the relevant chain specification.
*/
declare enum WellKnownChain {
polkadot = "polkadot",
ksmcc3 = "ksmcc3",
rococo_v2_2 = "rococo_v2_2",
westend2 = "westend2"
}
import { AddChain, AddWellKnownChain } from '@substrate/smoldot-discovery/types';
export { AddChain, AddWellKnownChain, AlreadyDestroyedError, Chain, CrashError, JsonRpcCallback, JsonRpcDisabledError, WellKnownChain } from '@substrate/smoldot-discovery/types';
/**
* Active connection to a blockchain.
*/
interface Chain {
/**
* Enqueues a JSON-RPC request that the client will process as soon as possible.
*
* The response will be sent back using the callback passed when adding the chain.
*
* See <https://www.jsonrpc.org/specification> for a specification of the JSON-RPC format. Only
* version 2 is supported.
* Be aware that some requests will cause notifications to be sent back using the same callback
* as the responses.
*
* No response is generated if the request isn't a valid JSON-RPC request or if the request is
* unreasonably large (8 MiB at the time of writing of this comment). The request is then
* silently discarded.
* If, however, the request is a valid JSON-RPC request but that concerns an unknown method, a
* error response is properly generated.
*
* Two JSON-RPC APIs are supported:
*
* - The "legacy" one, documented here: <https://polkadot.js.org/docs/substrate/rpc>
* - The more recent one: <https://github.com/paritytech/json-rpc-interface-spec>
*
* @param rpc JSON-encoded RPC request.
*
* @throws {AlreadyDestroyedError} If the chain has been removed.
* @throws {JsonRpcDisabledError} If no JSON-RPC callback was passed in the options of the chain.
* @throws {CrashError} If the background client has crashed.
*/
sendJsonRpc(rpc: string): void;
/**
* Disconnects from the blockchain.
*
* The JSON-RPC callback will no longer be called.
*
* Trying to use the chain again will lead to an exception being thrown.
*
* If this chain is a relay chain, then all parachains that use it will continue to work. Smoldot
* automatically keeps alive all relay chains that have an active parachains. There is no need
* to track parachains and relaychains, or to destroy them in the correct order, as this is
* handled automatically.
*
* @throws {AlreadyDestroyedError} If the chain has already been removed.
* @throws {CrashError} If the background client has crashed.
*/
remove(): void;
/**
* Connects to a parachain.
*
* Throws an exception if the chain specification isn't valid, or if the chain specification
* concerns a parachain but no corresponding relay chain can be found.
*
* Substrate-connect will automatically de-duplicate chains if multiple identical chains are
* added, in order to save resources. In other words, it is not a problem to call `addChain`
* multiple times with the same chain specifications and obtain multiple `Chain`.
* When the same client is used for multiple different purposes, you are in fact strongly
* encouraged to trust substrate-connect and not attempt to de-duplicate chains yourself, as
* determining whether two chains are identical is complicated and might have security
* implications.
*
* Substrate-connect tries to distribute CPU resources equally between all active `Chain`
* objects.
*
* @param chainSpec Specification of the chain to add.
* @param jsonRpcCallback Callback invoked in response to calling {Chain.sendJsonRpc}.
* This field is optional. If no callback is provided, the client will save up resources by not
* starting the JSON-RPC endpoint, and it is forbidden to call {Chain.sendJsonRpc}.
* Will never be called after ̀{Chain.remove} has been called or if a {CrashError} has been
* generated.
*
* @throws {AddChainError} If the chain can't be added.
* @throws {CrashError} If the background client has crashed.
*/
addChain: AddChain;
}
type JsonRpcCallback = (response: string) => void;
type AddChain = (chainSpec: string, jsonRpcCallback?: JsonRpcCallback, databaseContent?: string) => Promise<Chain>;
type AddWellKnownChain = (id: WellKnownChain, jsonRpcCallback?: JsonRpcCallback, databaseContent?: string) => Promise<Chain>;
/**
* Client that allows connecting to chains.

@@ -158,11 +68,2 @@ *

}
declare class AlreadyDestroyedError extends Error {
constructor();
}
declare class CrashError extends Error {
constructor(message: string);
}
declare class JsonRpcDisabledError extends Error {
constructor();
}

@@ -222,2 +123,2 @@ /**

export { type AddChain, type AddWellKnownChain, AlreadyDestroyedError, type Chain, type Config, CrashError, type Config$1 as EmbeddedNodeConfig, type JsonRpcCallback, JsonRpcDisabledError, type ScClient, WellKnownChain, createScClient };
export { type Config, type Config$1 as EmbeddedNodeConfig, type ScClient, createScClient };

74

dist/index.js

@@ -41,11 +41,13 @@ var __defProp = Object.defineProperty;

// src/WellKnownChain.ts
var WellKnownChain = /* @__PURE__ */ ((WellKnownChain2) => {
WellKnownChain2["polkadot"] = "polkadot";
WellKnownChain2["ksmcc3"] = "ksmcc3";
WellKnownChain2["rococo_v2_2"] = "rococo_v2_2";
WellKnownChain2["westend2"] = "westend2";
return WellKnownChain2;
})(WellKnownChain || {});
// src/index.ts
import { WellKnownChain as WellKnownChain3 } from "@substrate/smoldot-discovery/types";
// src/connector/types.ts
import {
WellKnownChain,
AlreadyDestroyedError,
CrashError,
JsonRpcDisabledError
} from "@substrate/smoldot-discovery/types";
// src/connector/getSpec.ts

@@ -60,5 +62,5 @@ var chains = /* @__PURE__ */ new Map();

switch (knownChain) {
case "polkadot" /* polkadot */: {
case WellKnownChain.polkadot: {
chains.set(
"polkadot" /* polkadot */,
WellKnownChain.polkadot,
import("@substrate/connect-known-chains/polkadot")

@@ -68,5 +70,5 @@ );

}
case "ksmcc3" /* ksmcc3 */: {
case WellKnownChain.ksmcc3: {
chains.set(
"ksmcc3" /* ksmcc3 */,
WellKnownChain.ksmcc3,
import("@substrate/connect-known-chains/ksmcc3")

@@ -76,5 +78,5 @@ );

}
case "westend2" /* westend2 */: {
case WellKnownChain.westend2: {
chains.set(
"westend2" /* westend2 */,
WellKnownChain.westend2,
import("@substrate/connect-known-chains/westend2")

@@ -84,5 +86,5 @@ );

}
case "rococo_v2_2" /* rococo_v2_2 */: {
case WellKnownChain.rococo_v2_2: {
chains.set(
"rococo_v2_2" /* rococo_v2_2 */,
WellKnownChain.rococo_v2_2,
import("@substrate/connect-known-chains/rococo_v2_2")

@@ -97,22 +99,2 @@ );

// src/connector/types.ts
var AlreadyDestroyedError = class extends Error {
constructor() {
super();
this.name = "AlreadyDestroyedError";
}
};
var CrashError = class extends Error {
constructor(message) {
super(message);
this.name = "CrashError";
}
};
var JsonRpcDisabledError = class extends Error {
constructor() {
super();
this.name = "JsonRpcDisabledError";
}
};
// src/connector/smoldot-light.ts

@@ -386,2 +368,3 @@ var isBrowser = ![typeof window, typeof document].includes("undefined");

// src/connector/index.ts
import { Unstable } from "@substrate/connect-discovery";
var createScClient3 = (config) => {

@@ -416,15 +399,6 @@ if (config == null ? void 0 : config.forceEmbeddedNode)

return;
let lightClientProviderPromise;
window.dispatchEvent(
new CustomEvent("lightClient:requestProvider", {
detail: {
onProvider(detail) {
if (detail.info.rdns === "io.github.paritytech.SubstrateConnectLightClient") {
lightClientProviderPromise = detail.provider;
}
}
}
})
);
return lightClientProviderPromise;
const lightClientProvider = Unstable.getSubstrateConnectExtensionProviders().filter(
(detail) => detail.info.rdns.startsWith("io.github.paritytech.SubstrateConnect")
).map((detail) => detail.provider)[0];
return lightClientProvider;
}

@@ -435,5 +409,5 @@ export {

JsonRpcDisabledError,
WellKnownChain,
WellKnownChain3 as WellKnownChain,
createScClient3 as createScClient
};
//# sourceMappingURL=index.js.map
{
"name": "@substrate/connect",
"version": "0.8.11",
"version": "1.0.0",
"description": "Substrate-connect to Smoldot clients. Using either substrate extension with predefined clients or an internal smoldot client based on chainSpecs provided.",

@@ -38,5 +38,6 @@ "author": "Parity Team <admin@parity.io>",

"smoldot": "2.0.26",
"@substrate/light-client-extension-helpers": "^1.0.0",
"@substrate/connect-extension-protocol": "^2.0.0",
"@substrate/connect-known-chains": "^1.1.5"
"@substrate/smoldot-discovery": "^0.0.6",
"@substrate/connect-discovery": "^0.0.6",
"@substrate/connect-known-chains": "^1.1.5",
"@substrate/connect-extension-protocol": "^2.0.0"
},

@@ -43,0 +44,0 @@ "devDependencies": {

import type { Chain, JsonRpcCallback, ScClient } from "./types.js"
import type {
RawChain,
LightClientProvider,
} from "@substrate/light-client-extension-helpers/web-page"
import { WellKnownChain } from "../WellKnownChain.js"
import type { Unstable } from "@substrate/connect-discovery"
import { WellKnownChain } from "./types.js"

@@ -28,3 +25,3 @@ const wellKnownChainGenesisHashes: Record<string, string> = {

export const createScClient = (
lightClientProviderPromise: Promise<LightClientProvider>,
lightClientProviderPromise: Promise<Unstable.Provider>,
): ScClient => {

@@ -39,3 +36,3 @@ const internalAddChain = async (

let chain: RawChain
let chain: Unstable.RawChain
if (isWellKnown) {

@@ -42,0 +39,0 @@ const foundChain = Object.values(lightClientProvider.getChains()).find(

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

import { WellKnownChain } from "../WellKnownChain.js"
import { WellKnownChain } from "./types"

@@ -3,0 +3,0 @@ const chains: Map<WellKnownChain, Promise<{ chainSpec: string }>> = new Map()

@@ -7,6 +7,3 @@ import {

import type { ScClient } from "./types.js"
import type {
LightClientProvider,
LightClientOnProvider,
} from "@substrate/light-client-extension-helpers/web-page"
import { Unstable } from "@substrate/connect-discovery"

@@ -70,21 +67,12 @@ export * from "./types.js"

function getExtensionLightClientProviderPromise():
| Promise<LightClientProvider>
| Promise<Unstable.Provider>
| undefined {
if (typeof document !== "object" || typeof CustomEvent !== "function") return
let lightClientProviderPromise: Promise<LightClientProvider> | undefined
window.dispatchEvent(
new CustomEvent<LightClientOnProvider>("lightClient:requestProvider", {
detail: {
onProvider(detail) {
if (
detail.info.rdns ===
"io.github.paritytech.SubstrateConnectLightClient"
) {
lightClientProviderPromise = detail.provider
}
},
},
}),
)
return lightClientProviderPromise
const lightClientProvider = Unstable.getSubstrateConnectExtensionProviders()
.filter((detail) =>
detail.info.rdns.startsWith("io.github.paritytech.SubstrateConnect"),
)
.map((detail) => detail.provider)[0]
return lightClientProvider
}
// eslint-disable-next-line import/no-extraneous-dependencies
import { beforeEach, beforeAll, it, describe, expect, vi } from "vitest"
import type { AddChainOptions, ClientOptions } from "smoldot"
import { WellKnownChain } from "../WellKnownChain.js"
import { WellKnownChain } from "./types"

@@ -6,0 +6,0 @@ class SdAlreadyDestroyedError extends Error {

@@ -17,4 +17,4 @@ import type {

AddChain,
WellKnownChain,
} from "./types.js"
import { WellKnownChain } from "../WellKnownChain.js"

@@ -21,0 +21,0 @@ const isBrowser = ![typeof window, typeof document].includes("undefined")

@@ -1,99 +0,4 @@

import { WellKnownChain } from "../WellKnownChain.js"
import { AddChain, AddWellKnownChain } from "@substrate/smoldot-discovery/types"
/**
* Active connection to a blockchain.
*/
export interface Chain {
/**
* Enqueues a JSON-RPC request that the client will process as soon as possible.
*
* The response will be sent back using the callback passed when adding the chain.
*
* See <https://www.jsonrpc.org/specification> for a specification of the JSON-RPC format. Only
* version 2 is supported.
* Be aware that some requests will cause notifications to be sent back using the same callback
* as the responses.
*
* No response is generated if the request isn't a valid JSON-RPC request or if the request is
* unreasonably large (8 MiB at the time of writing of this comment). The request is then
* silently discarded.
* If, however, the request is a valid JSON-RPC request but that concerns an unknown method, a
* error response is properly generated.
*
* Two JSON-RPC APIs are supported:
*
* - The "legacy" one, documented here: <https://polkadot.js.org/docs/substrate/rpc>
* - The more recent one: <https://github.com/paritytech/json-rpc-interface-spec>
*
* @param rpc JSON-encoded RPC request.
*
* @throws {AlreadyDestroyedError} If the chain has been removed.
* @throws {JsonRpcDisabledError} If no JSON-RPC callback was passed in the options of the chain.
* @throws {CrashError} If the background client has crashed.
*/
sendJsonRpc(rpc: string): void
/**
* Disconnects from the blockchain.
*
* The JSON-RPC callback will no longer be called.
*
* Trying to use the chain again will lead to an exception being thrown.
*
* If this chain is a relay chain, then all parachains that use it will continue to work. Smoldot
* automatically keeps alive all relay chains that have an active parachains. There is no need
* to track parachains and relaychains, or to destroy them in the correct order, as this is
* handled automatically.
*
* @throws {AlreadyDestroyedError} If the chain has already been removed.
* @throws {CrashError} If the background client has crashed.
*/
remove(): void
/**
* Connects to a parachain.
*
* Throws an exception if the chain specification isn't valid, or if the chain specification
* concerns a parachain but no corresponding relay chain can be found.
*
* Substrate-connect will automatically de-duplicate chains if multiple identical chains are
* added, in order to save resources. In other words, it is not a problem to call `addChain`
* multiple times with the same chain specifications and obtain multiple `Chain`.
* When the same client is used for multiple different purposes, you are in fact strongly
* encouraged to trust substrate-connect and not attempt to de-duplicate chains yourself, as
* determining whether two chains are identical is complicated and might have security
* implications.
*
* Substrate-connect tries to distribute CPU resources equally between all active `Chain`
* objects.
*
* @param chainSpec Specification of the chain to add.
* @param jsonRpcCallback Callback invoked in response to calling {Chain.sendJsonRpc}.
* This field is optional. If no callback is provided, the client will save up resources by not
* starting the JSON-RPC endpoint, and it is forbidden to call {Chain.sendJsonRpc}.
* Will never be called after ̀{Chain.remove} has been called or if a {CrashError} has been
* generated.
*
* @throws {AddChainError} If the chain can't be added.
* @throws {CrashError} If the background client has crashed.
*/
addChain: AddChain
}
export type JsonRpcCallback = (response: string) => void
export type AddChain = (
chainSpec: string,
jsonRpcCallback?: JsonRpcCallback,
databaseContent?: string,
) => Promise<Chain>
export type AddWellKnownChain = (
id: WellKnownChain,
jsonRpcCallback?: JsonRpcCallback,
databaseContent?: string,
) => Promise<Chain>
/**
* Client that allows connecting to chains.

@@ -164,21 +69,13 @@ *

export class AlreadyDestroyedError extends Error {
constructor() {
super()
this.name = "AlreadyDestroyedError"
}
}
export class CrashError extends Error {
constructor(message: string) {
super(message)
this.name = "CrashError"
}
}
export class JsonRpcDisabledError extends Error {
constructor() {
super()
this.name = "JsonRpcDisabledError"
}
}
export {
WellKnownChain,
AlreadyDestroyedError,
CrashError,
JsonRpcDisabledError,
} from "@substrate/smoldot-discovery/types"
export type {
Chain,
JsonRpcCallback,
AddChain,
AddWellKnownChain,
} from "@substrate/smoldot-discovery/types"

@@ -98,3 +98,9 @@ /**

export { WellKnownChain } from "./WellKnownChain.js"
export { WellKnownChain } from "@substrate/smoldot-discovery/types"
export * from "./connector/index.js"
export type {
JsonRpcCallback,
Chain,
AddChain,
AddWellKnownChain,
} from "./connector/index.js"

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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