mirror of
https://github.com/pezkuwichain/bizinikiwi-connect.git
synced 2026-04-22 02:57:55 +00:00
feat: initial commit for bizinikiwi-connect with clean CI
This commit is contained in:
@@ -0,0 +1 @@
|
||||
dist
|
||||
@@ -0,0 +1,209 @@
|
||||
# @bizinikiwi/smoldot-discovery
|
||||
|
||||
## 2.0.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 92316c0: chore(deps-dev): bump vitest in the npm_and_yarn group
|
||||
|
||||
Bumps the npm_and_yarn group with 1 update: [vitest](https://github.com/vitest-dev/vitest/tree/HEAD/packages/vitest).
|
||||
|
||||
Updates `vitest` from 2.1.4 to 2.1.9
|
||||
|
||||
- [Release notes](https://github.com/vitest-dev/vitest/releases)
|
||||
- [Commits](https://github.com/vitest-dev/vitest/commits/v2.1.9/packages/vitest)
|
||||
|
||||
***
|
||||
|
||||
updated-dependencies:
|
||||
|
||||
- dependency-name: vitest
|
||||
dependency-type: direct:development
|
||||
dependency-group: npm_and_yarn
|
||||
...
|
||||
|
||||
Signed-off-by: dependabot[bot] <support@github.com>
|
||||
|
||||
- Updated dependencies [92316c0]
|
||||
- @bizinikiwi/discovery@0.2.2
|
||||
|
||||
## 2.0.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 09f1c22: chore(deps-dev): bump vitest from 2.0.5 to 2.1.4
|
||||
|
||||
Bumps [vitest](https://github.com/vitest-dev/vitest/tree/HEAD/packages/vitest) from 2.0.5 to 2.1.4.
|
||||
|
||||
- [Release notes](https://github.com/vitest-dev/vitest/releases)
|
||||
- [Commits](https://github.com/vitest-dev/vitest/commits/v2.1.4/packages/vitest)
|
||||
|
||||
***
|
||||
|
||||
updated-dependencies:
|
||||
|
||||
- dependency-name: vitest
|
||||
dependency-type: direct:development
|
||||
update-type: version-update:semver-minor
|
||||
...
|
||||
|
||||
Signed-off-by: dependabot[bot] <support@github.com>
|
||||
|
||||
- Updated dependencies [09f1c22]
|
||||
- @bizinikiwi/discovery@0.2.1
|
||||
|
||||
## 2.0.0
|
||||
|
||||
### Major Changes
|
||||
|
||||
- e2a5cef: ## Breaking Changes
|
||||
|
||||
- Modified `addChain` and `addWellKnownChain` methods:
|
||||
- Now accept a single `options` object parameter instead of separate `jsonRpcCallback` and `databaseContent` parameters
|
||||
- The `jsonRpcCallback` is now passed as `options.jsonRpcCallback`
|
||||
- The `databaseContent` is now passed as `options.databaseContent`
|
||||
- Removed `JsonRpcCallback` type export. Use the callback type from the `options` parameter of `addChain` and `addWellKnownChain` instead.
|
||||
- Updated peer dependency for `@bizinikiwi/smoldot-discovery` to "^2"
|
||||
|
||||
## New Features
|
||||
|
||||
- Added new methods to the Chain interface to conform with smoldot's interface:
|
||||
- `nextJsonRpcResponse`: Returns a promise that resolves with the next JSON-RPC response
|
||||
- `jsonRpcResponses`: Returns an async iterable of JSON-RPC responses
|
||||
|
||||
## Other Changes
|
||||
|
||||
- Updated internal implementation to use Effect for streaming JSON RPC responses in a Queue.
|
||||
- Updated error handling to include `QueueFullError`.
|
||||
|
||||
## Migration Guide
|
||||
|
||||
Users of this package will need to update their code to use the new method signatures for `addChain` and `addWellKnownChain`, and adapt to the removed `JsonRpcCallback` type export. Please refer to the updated documentation for the new usage patterns.
|
||||
|
||||
When upgrading, ensure you're using version 3 or higher of `@bizinikiwi/smoldot-discovery` as a peer dependency.
|
||||
|
||||
## 1.2.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- 198b375: chore: catalog and upgrade papi dependencies
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [198b375]
|
||||
- @bizinikiwi/discovery@0.2.0
|
||||
|
||||
## 1.1.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- b476e7e: update build system to tshy
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [b476e7e]
|
||||
- @bizinikiwi/discovery@0.1.0
|
||||
|
||||
## 1.0.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- e8fef4e: update docs
|
||||
- 0ce9864: simplify isSmoldotExtension
|
||||
- Updated dependencies [e8fef4e]
|
||||
- @bizinikiwi/discovery@0.0.2
|
||||
|
||||
## 1.0.0
|
||||
|
||||
### Major Changes
|
||||
|
||||
- 4123a5e: ## Breaking Changes
|
||||
|
||||
### Change Summary
|
||||
|
||||
- Removes the connector function and extracts its into a different package.
|
||||
- Remove `@bizinikiwi/light-client-extension-helpers` dependency.
|
||||
- Re-export `@bizinikiwi/discovery` types
|
||||
|
||||
### Motivation
|
||||
|
||||
`@bizinikiwi/smoldot-discovery` is intended for dapp consumption only. However by having a connector function that was used by extensions, we forced dapps to have a dependency on `@bizinikiwi/light-client-extension-helpers`. This is unacceptable since `@bizinikiwi/light-client-extension-helpers` should be used by extensions only. As a result, the connector function has been extracted into a separate package
|
||||
and the dependency on `bizinikiwi/light-client-extension-helpers` has been removed.
|
||||
|
||||
### How to Update
|
||||
|
||||
#### Dapps
|
||||
|
||||
No code changes are required. Simply update the package and remove the `@bizinikiwi/light-client-extension-helpers` peer dependency.
|
||||
|
||||
#### Extensions
|
||||
|
||||
Extensions must install the `@bizinikiwi/smoldot-discovery-connector` package.
|
||||
|
||||
Then the connector can be consumed as follows:
|
||||
|
||||
```ts
|
||||
import { getLightClientProvider } from "@bizinikiwi/light-client-extension-helpers/web-page"
|
||||
import {
|
||||
make as makeSmoldotDiscoveryConnector,
|
||||
SmoldotExtensionProviderDetail,
|
||||
} from "@bizinikiwi/smoldot-discovery-connector"
|
||||
|
||||
const CHANNEL_ID = "YOUR_CHANNEL_ID"
|
||||
|
||||
const lightClientProvider = getLightClientProvider(CHANNEL_ID)
|
||||
|
||||
// #region Smoldot Discovery Provider
|
||||
{
|
||||
const provider = lightClientProvider.then(makeSmoldotDiscoveryConnector)
|
||||
|
||||
const detail: SmoldotExtensionProviderDetail = Object.freeze({
|
||||
kind: "smoldot-v1",
|
||||
info: PROVIDER_INFO,
|
||||
provider,
|
||||
})
|
||||
|
||||
window.addEventListener(
|
||||
"bizinikiwiDiscovery:requestProvider",
|
||||
({ detail: { onProvider } }) => onProvider(detail),
|
||||
)
|
||||
|
||||
window.dispatchEvent(
|
||||
new CustomEvent("bizinikiwiDiscovery:announceProvider", {
|
||||
detail,
|
||||
}),
|
||||
)
|
||||
}
|
||||
// #endregion
|
||||
```
|
||||
|
||||
### Additional Notes
|
||||
|
||||
- The connector `make` function now accepts two parameters instead of one. The `lightClientProvider` is now the first parameter.
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- e35a0e8: add paseo testnet
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- cef7d50: update chainspecs
|
||||
|
||||
## 0.0.9
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 444503f: chore: update READMEs across repo
|
||||
|
||||
## 0.0.8
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- c358405: fix(smoldot-discovery): peer dependencies constraint
|
||||
- bdd728d: fix: re-export missing types from light client ext helpers webpage
|
||||
|
||||
## 0.0.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 78ca884: chore: add smoldot discovery connector
|
||||
@@ -0,0 +1,39 @@
|
||||
<br /><br />
|
||||
|
||||
<div align="center">
|
||||
<h1 align="center">@bizinikiwi/smoldot-discovery</h1>
|
||||
<p align="center">
|
||||
<a href="https://www.npmjs.com/package/@bizinikiwi/smoldot-discovery">
|
||||
<img alt="npm" src="https://img.shields.io/npm/v/@bizinikiwi/smoldot-discovery" />
|
||||
</a>
|
||||
<a href="https://github.com/pezkuwichain/bizinikiwi-connect/blob/master/LICENSE">
|
||||
<img alt="GPL-3.0-or-later" src="https://img.shields.io/npm/l/@bizinikiwi/smoldot-discovery" />
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<br /><br />
|
||||
|
||||
A TypeScript package extended from the [`@bizinikiwi/discovery`](../discovery/README.md) NPM package, which enables the discovery and filtering of Smoldot extension providers from a list of providers.
|
||||
|
||||
To be utilized by dApps, extensions should implement the `SmoldotExtensionProviderDetail` interface. This can be achieved by following the extension side of the discovery protocol as detailed [here](../discovery/README.md), and then returning the implemented interface.
|
||||
|
||||
## Installation
|
||||
|
||||
You can install the package using npm or yarn:
|
||||
|
||||
```sh
|
||||
corepack pnpm i @bizinikiwi/smoldot-discovery
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Here's an example of how to use the package:
|
||||
|
||||
```ts
|
||||
import { getSmoldotExtensionProviders } from "@bizinikiwi/smoldot-discovery"
|
||||
|
||||
const smoldotProviders = getSmoldotExtensionProviders()
|
||||
|
||||
console.log(smoldotProviders)
|
||||
```
|
||||
@@ -0,0 +1,73 @@
|
||||
{
|
||||
"name": "@bizinikiwi/smoldot-discovery",
|
||||
"version": "2.0.3",
|
||||
"author": "Parity Technologies (https://github.com/pezkuwichain)",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/pezkuwichain/bizinikiwi-connect.git"
|
||||
},
|
||||
"type": "module",
|
||||
"main": "./dist/commonjs/index.js",
|
||||
"types": "./dist/commonjs/index.d.ts",
|
||||
"module": "./dist/esm/index.js",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"./package.json": "./package.json",
|
||||
".": {
|
||||
"import": {
|
||||
"@bizinikiwi-connect/source": "./src/index.ts",
|
||||
"types": "./dist/esm/index.d.ts",
|
||||
"default": "./dist/esm/index.js"
|
||||
},
|
||||
"require": {
|
||||
"types": "./dist/commonjs/index.d.ts",
|
||||
"default": "./dist/commonjs/index.js"
|
||||
}
|
||||
},
|
||||
"./types": {
|
||||
"import": {
|
||||
"@bizinikiwi-connect/source": "./src/types/index.ts",
|
||||
"types": "./dist/esm/types/index.d.ts",
|
||||
"default": "./dist/esm/types/index.js"
|
||||
},
|
||||
"require": {
|
||||
"types": "./dist/commonjs/types/index.d.ts",
|
||||
"default": "./dist/commonjs/types/index.js"
|
||||
}
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"tshy": {
|
||||
"project": "./tsconfig.build.json",
|
||||
"exports": {
|
||||
"./package.json": "./package.json",
|
||||
".": "./src/index.ts",
|
||||
"./types": "./src/types/index.ts"
|
||||
},
|
||||
"sourceDialects": [
|
||||
"@bizinikiwi-connect/source"
|
||||
]
|
||||
},
|
||||
"scripts": {
|
||||
"prepare": "corepack pnpm turbo build",
|
||||
"deep-clean": "npm run clean && rimraf dist node_modules",
|
||||
"clean": "rimraf dist .tshy .tshy-build",
|
||||
"build": "npm run clean && tshy",
|
||||
"dev": "pnpm build --watch",
|
||||
"lint": "prettier --check README.md \"src/**/*.{js,jsx,ts,tsx,json,md}\""
|
||||
},
|
||||
"prettier": {
|
||||
"printWidth": 80,
|
||||
"semi": false,
|
||||
"trailingComma": "all"
|
||||
},
|
||||
"dependencies": {
|
||||
"@bizinikiwi/discovery": "^0.2.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "5.6.2",
|
||||
"vitest": "^2.1.9"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { getProviders, type ProviderDetail } from "@bizinikiwi/discovery"
|
||||
import type { SmoldotExtensionProviderDetail } from "./types/index.js"
|
||||
|
||||
export const Kind: SmoldotExtensionProviderDetail["kind"] = "smoldot-v1"
|
||||
|
||||
export const isSmoldotExtension = (
|
||||
provider: ProviderDetail,
|
||||
): provider is SmoldotExtensionProviderDetail => provider.kind === Kind
|
||||
|
||||
export const getSmoldotExtensionProviders = () => {
|
||||
return getProviders().filter(isSmoldotExtension)
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
import type { ProviderInfo } from "@bizinikiwi/discovery"
|
||||
export type * from "@bizinikiwi/discovery"
|
||||
|
||||
export type SmoldotExtensionAPI = Readonly<{
|
||||
addChain: AddChain
|
||||
addWellKnownChain: AddWellKnownChain
|
||||
}>
|
||||
|
||||
export type SmoldotExtensionProviderDetail = Readonly<{
|
||||
kind: "smoldot-v1"
|
||||
info: ProviderInfo
|
||||
provider: Promise<SmoldotExtensionAPI>
|
||||
}>
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
export const WellKnownChain = {
|
||||
pezkuwi: "pezkuwi",
|
||||
ksmcc3: "ksmcc3",
|
||||
pezkuwichain_v2_2: "pezkuwichain_v2_2",
|
||||
zagros2: "zagros2",
|
||||
paseo: "paseo",
|
||||
} as const
|
||||
|
||||
export type WellKnownChain =
|
||||
(typeof WellKnownChain)[keyof typeof WellKnownChain]
|
||||
|
||||
export namespace WellKnownChain {
|
||||
export type pezkuwi = typeof WellKnownChain.pezkuwi
|
||||
export type ksmcc3 = typeof WellKnownChain.ksmcc3
|
||||
export type pezkuwichain_v2_2 = typeof WellKnownChain.pezkuwichain_v2_2
|
||||
export type zagros2 = typeof WellKnownChain.zagros2
|
||||
export type paseo = typeof WellKnownChain.paseo
|
||||
}
|
||||
|
||||
/**
|
||||
* 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://pezkuwi.js.org/docs/bizinikiwi/rpc>
|
||||
* - The more recent one: <https://github.com/pezkuwichain/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.
|
||||
*/
|
||||
readonly sendJsonRpc: (rpc: string) => void
|
||||
|
||||
/**
|
||||
* Waits for a JSON-RPC response or notification to be generated.
|
||||
*
|
||||
* Each chain contains a buffer of the responses waiting to be sent out. Calling this function
|
||||
* pulls one element from the buffer. If this function is called at a slower rate than
|
||||
* responses are generated, then the buffer will eventually become full, at which point calling
|
||||
* {@link Chain.sendJsonRpc} will throw an exception. The size of this buffer can be configured
|
||||
* through {@link AddChainOptions.jsonRpcMaxPendingRequests}.
|
||||
*
|
||||
* If this function is called multiple times "simultaneously" (generating multiple different
|
||||
* `Promise`s), each `Promise` will return a different JSON-RPC response or notification. In
|
||||
* that situation, there is no guarantee in the ordering in which the responses or notifications
|
||||
* are yielded. Calling this function multiple times "simultaneously" is in general a niche
|
||||
* corner case that you are encouraged to avoid.
|
||||
*
|
||||
* @throws {@link AlreadyDestroyedError} If the chain has been removed or the client has been terminated.
|
||||
* @throws {@link JsonRpcDisabledError} If the JSON-RPC system was disabled in the options of the chain.
|
||||
* @throws {@link CrashError} If the background client has crashed.
|
||||
*/
|
||||
readonly nextJsonRpcResponse: () => Promise<string>
|
||||
|
||||
/**
|
||||
* JSON-RPC responses or notifications async iterable.
|
||||
*
|
||||
* Each chain contains a buffer of the responses waiting to be sent out. Iterating over this
|
||||
* pulls one element from the buffer. If the iteration happen at a slower rate than
|
||||
* responses are generated, then the buffer will eventually become full, at which point calling
|
||||
* {@link Chain.sendJsonRpc} will throw an exception. The size of this buffer can be configured
|
||||
* through {@link AddChainOptions.jsonRpcMaxPendingRequests}.
|
||||
*
|
||||
* @throws {@link JsonRpcDisabledError} If the JSON-RPC system was disabled in the options of the chain.
|
||||
* @throws {@link CrashError} If the background client has crashed.
|
||||
*/
|
||||
readonly jsonRpcResponses: AsyncIterableIterator<string>
|
||||
/**
|
||||
* 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 {@link AlreadyDestroyedError} If the chain has already been removed.
|
||||
* @throws {@link CrashError} If the background client has crashed.
|
||||
*/
|
||||
readonly 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.
|
||||
*
|
||||
* Smoldot 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 smoldot and not attempt to de-duplicate chains yourself, as
|
||||
* determining whether two chains are identical is complicated and might have security
|
||||
* implications.
|
||||
*
|
||||
* Smoldot tries to distribute CPU resources equally between all active `Chain`
|
||||
* objects.
|
||||
*
|
||||
* @param chainSpec Specification of the chain to add.
|
||||
*
|
||||
* @throws {@link AddChainError} If the chain can't be added.
|
||||
* @throws {@link CrashError} If the background client has crashed.
|
||||
*/
|
||||
readonly addChain: AddChain
|
||||
}
|
||||
|
||||
export type AddChainOptions = Readonly<{
|
||||
disableJsonRpc?: boolean
|
||||
databaseContent?: string | undefined
|
||||
jsonRpcMaxPendingRequests?: number
|
||||
}>
|
||||
|
||||
export type AddChain = (
|
||||
chainSpec: string,
|
||||
options?: AddChainOptions,
|
||||
) => Promise<Chain>
|
||||
export type AddWellKnownChain = (
|
||||
id: WellKnownChain,
|
||||
options?: AddChainOptions,
|
||||
) => Promise<Chain>
|
||||
|
||||
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 class QueueFullError extends Error {
|
||||
constructor() {
|
||||
super()
|
||||
this.name = "QueueFullError"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "../../tsconfig.build.json",
|
||||
"include": ["src"]
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base",
|
||||
"include": ["src", "tests"]
|
||||
}
|
||||
Reference in New Issue
Block a user