@parity/product-sdk-chain-client 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +9 -1
- package/dist/index.js +9 -4
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +1 -1
- package/src/presets.ts +47 -10
- package/src/types.ts +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,9 @@ import { kusama_asset_hub } from '@parity/product-sdk-descriptors/kusama-asset-h
|
|
|
4
4
|
import { paseo_asset_hub } from '@parity/product-sdk-descriptors/paseo-asset-hub';
|
|
5
5
|
import { paseo_bulletin } from '@parity/product-sdk-descriptors/paseo-bulletin';
|
|
6
6
|
import { paseo_individuality } from '@parity/product-sdk-descriptors/paseo-individuality';
|
|
7
|
+
import { summit_asset_hub } from '@parity/product-sdk-descriptors/summit-asset-hub';
|
|
8
|
+
import { summit_bulletin } from '@parity/product-sdk-descriptors/summit-bulletin';
|
|
9
|
+
import { summit_individuality } from '@parity/product-sdk-descriptors/summit-individuality';
|
|
7
10
|
export { ChainNotSupportedError, isInsideContainer, isInsideContainerSync } from '@parity/product-sdk-host';
|
|
8
11
|
|
|
9
12
|
/**
|
|
@@ -121,7 +124,7 @@ declare function getClient(descriptor: ChainDefinition): PolkadotClient;
|
|
|
121
124
|
declare function isConnected(descriptor: ChainDefinition): boolean;
|
|
122
125
|
|
|
123
126
|
/** Known network environment with built-in descriptors. */
|
|
124
|
-
type Environment = "polkadot" | "kusama" | "paseo";
|
|
127
|
+
type Environment = "polkadot" | "kusama" | "paseo" | "summit";
|
|
125
128
|
/** Per-environment descriptor types for each chain in the preset. */
|
|
126
129
|
type PresetDescriptors = {
|
|
127
130
|
polkadot: {
|
|
@@ -139,6 +142,11 @@ type PresetDescriptors = {
|
|
|
139
142
|
bulletin: typeof paseo_bulletin;
|
|
140
143
|
individuality: typeof paseo_individuality;
|
|
141
144
|
};
|
|
145
|
+
summit: {
|
|
146
|
+
assetHub: typeof summit_asset_hub;
|
|
147
|
+
bulletin: typeof summit_bulletin;
|
|
148
|
+
individuality: typeof summit_individuality;
|
|
149
|
+
};
|
|
142
150
|
};
|
|
143
151
|
/** The chain shape returned by {@link getChainAPI} for a given environment. */
|
|
144
152
|
type PresetChains<E extends Environment> = PresetDescriptors[E];
|
package/dist/index.js
CHANGED
|
@@ -161,7 +161,7 @@ function isConnected(descriptor) {
|
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
// src/presets.ts
|
|
164
|
-
var AVAILABLE_ENVIRONMENTS = /* @__PURE__ */ new Set(["paseo"]);
|
|
164
|
+
var AVAILABLE_ENVIRONMENTS = /* @__PURE__ */ new Set(["paseo", "summit"]);
|
|
165
165
|
async function loadDescriptors(env) {
|
|
166
166
|
const loaders = {
|
|
167
167
|
polkadot: () => Promise.all([
|
|
@@ -180,12 +180,17 @@ async function loadDescriptors(env) {
|
|
|
180
180
|
import('@parity/product-sdk-descriptors/paseo-asset-hub'),
|
|
181
181
|
import('@parity/product-sdk-descriptors/paseo-bulletin'),
|
|
182
182
|
import('@parity/product-sdk-descriptors/paseo-individuality')
|
|
183
|
+
]),
|
|
184
|
+
summit: () => Promise.all([
|
|
185
|
+
import('@parity/product-sdk-descriptors/summit-asset-hub'),
|
|
186
|
+
import('@parity/product-sdk-descriptors/summit-bulletin'),
|
|
187
|
+
import('@parity/product-sdk-descriptors/summit-individuality')
|
|
183
188
|
])
|
|
184
189
|
};
|
|
185
190
|
const [ahMod, bulletinMod, individualityMod] = await loaders[env]();
|
|
186
|
-
const assetHub = "polkadot_asset_hub" in ahMod ? ahMod.polkadot_asset_hub : "kusama_asset_hub" in ahMod ? ahMod.kusama_asset_hub : ahMod.paseo_asset_hub;
|
|
187
|
-
const bulletin = bulletinMod.paseo_bulletin;
|
|
188
|
-
const individuality = individualityMod.paseo_individuality;
|
|
191
|
+
const assetHub = "polkadot_asset_hub" in ahMod ? ahMod.polkadot_asset_hub : "kusama_asset_hub" in ahMod ? ahMod.kusama_asset_hub : "summit_asset_hub" in ahMod ? ahMod.summit_asset_hub : ahMod.paseo_asset_hub;
|
|
192
|
+
const bulletin = "summit_bulletin" in bulletinMod ? bulletinMod.summit_bulletin : bulletinMod.paseo_bulletin;
|
|
193
|
+
const individuality = "summit_individuality" in individualityMod ? individualityMod.summit_individuality : individualityMod.paseo_individuality;
|
|
189
194
|
return { assetHub, bulletin, individuality };
|
|
190
195
|
}
|
|
191
196
|
async function getChainAPI(env) {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/providers.ts","../src/hmr.ts","../src/clients.ts","../src/presets.ts","../src/well-known-chain.ts"],"names":[],"mappings":";;;;;;AAaA,eAAsB,eAAe,WAAA,EAA+C;AAChF,EAAA,MAAM,YAAA,GAAe,MAAM,eAAA,CAAgB,WAA4B,CAAA;AACvE,EAAA,IAAI,CAAC,YAAA,EAAc;AACf,IAAA,MAAM,IAAI,KAAA;AAAA,MACN,uCAAuC,WAAW,CAAA,8EAAA;AAAA,KACtD;AAAA,EACJ;AACA,EAAA,OAAO,YAAA;AACX;;;ACZO,SAAS,cAAA,GAA0C;AACtD,EAAA,UAAA,CAAW,kBAAA,yBAA2B,GAAA,EAAI;AAC1C,EAAA,OAAO,UAAA,CAAW,kBAAA;AACtB;AAGO,SAAS,gBAAA,GAAyB;AACrC,EAAA,MAAM,QAAQ,cAAA,EAAe;AAC7B,EAAA,KAAA,MAAW,KAAA,IAAS,KAAA,CAAM,MAAA,EAAO,EAAG;AAChC,IAAA,IAAI;AACA,MAAA,KAAA,CAAM,OAAO,OAAA,EAAQ;AAAA,IACzB,CAAA,CAAA,MAAQ;AAAA,IAER;AAAA,EACJ;AACA,EAAA,KAAA,CAAM,KAAA,EAAM;AAChB;;;ACfA,IAAM,GAAA,GAAM,aAAa,cAAc,CAAA;AAQvC,SAAS,oBAAoB,KAAA,EAAsC;AAC/D,EAAA,MAAM,OAAA,G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,GAAG,CAAA,sBAAA,CAAwB,CAAA;AAAA,EACjE;AAEA,EAAA,MAAM,WAAA,GAAc,MAAM,eAAA,CAAgB,GAAG,CAAA;AAE7C,EAAA,OAAO,iBAAA,CAAkB;AAAA,IACrB,MAAA,EAAQ;AAAA,MACJ,UAAU,WAAA,CAAY,QAAA;AAAA,MACtB,UAAU,WAAA,CAAY,QAAA;AAAA,MACtB,eAAe,WAAA,CAAY;AAAA;AAC/B,GACH,CAAA;AACL;;;ACpIO,IAAM,cAAA,GAAiB;AAAA,EAC1B,aAAA,EAAe,oEAAA;AAAA,EACf,gBAAA,EAAkB,oEAAA;AAAA,EAClB,WAAA,EAAa,oEAAA;AAAA,EACb,cAAA,EAAgB,oEAAA;AAAA,EAChB,YAAA,EAAc,oEAAA;AAAA,EACd,eAAA,EAAiB,oEAAA;AAAA,EACjB,MAAA,EAAQ;AACZ","file":"index.js","sourcesContent":["// Copyright 2026 Parity Technologies (UK) Ltd.\n// SPDX-License-Identifier: Apache-2.0\nimport { getHostProvider } from \"@parity/product-sdk-host\";\nimport type { JsonRpcProvider } from \"polkadot-api\";\n\n/**\n * Create a PAPI-compatible JSON-RPC provider for a chain.\n *\n * Routes connections through the host provider (`@parity/product-sdk-host`).\n * The SDK is designed to run exclusively inside a host container.\n *\n * @throws {Error} If the host provider is unavailable (not inside a container).\n */\nexport async function createProvider(genesisHash: string): Promise<JsonRpcProvider> {\n const hostProvider = await getHostProvider(genesisHash as `0x${string}`);\n if (!hostProvider) {\n throw new Error(\n `Host provider unavailable for chain ${genesisHash}. Ensure you are running inside a host container (Polkadot Browser / Desktop).`,\n );\n }\n return hostProvider;\n}\n\nif (import.meta.vitest) {\n const { test, expect, vi, beforeEach } = import.meta.vitest;\n\n // Shared state between hoisted mocks and tests\n const state = vi.hoisted(() => ({\n fakeProvider: (() => {}) as unknown as JsonRpcProvider,\n hostProviderCalls: [] as unknown[][],\n hostProviderAvailable: true,\n hostProviderError: null as Error | null,\n }));\n\n vi.mock(\"@parity/product-sdk-host\", async (importOriginal) => ({\n ...(await importOriginal<typeof import(\"@parity/product-sdk-host\")>()),\n getHostProvider: async (...args: unknown[]) => {\n state.hostProviderCalls.push(args);\n if (state.hostProviderError) throw state.hostProviderError;\n if (!state.hostProviderAvailable) return null;\n return state.fakeProvider;\n },\n }));\n\n beforeEach(() => {\n state.hostProviderCalls = [];\n state.hostProviderAvailable = true;\n state.hostProviderError = null;\n });\n\n test(\"returns host provider when available\", async () => {\n const result = await createProvider(\"0xabc\");\n expect(result).toBe(state.fakeProvider);\n expect(state.hostProviderCalls.length).toBe(1);\n expect(state.hostProviderCalls[0][0]).toBe(\"0xabc\");\n });\n\n test(\"throws when host provider unavailable\", async () => {\n state.hostProviderAvailable = false;\n await expect(createProvider(\"0xabc\")).rejects.toThrow(/Host provider unavailable/);\n });\n\n test(\"propagates ChainNotSupportedError from the host provider\", async () => {\n const { ChainNotSupportedError } = await import(\"@parity/product-sdk-host\");\n state.hostProviderError = new ChainNotSupportedError(\"0xabc\");\n // The unsupported-chain error must surface to the caller rather than being\n // collapsed into the generic \"unavailable\" path or swallowed.\n await expect(createProvider(\"0xabc\")).rejects.toBeInstanceOf(ChainNotSupportedError);\n });\n}\n","// Copyright 2026 Parity Technologies (UK) Ltd.\n// SPDX-License-Identifier: Apache-2.0\nimport type { ChainEntry } from \"./types.js\";\n\ndeclare global {\n var __chainClientCache: Map<string, ChainEntry> | undefined;\n}\n\n/** Get the HMR-safe client cache, keyed by genesis hash. */\nexport function getClientCache(): Map<string, ChainEntry> {\n globalThis.__chainClientCache ??= new Map();\n return globalThis.__chainClientCache;\n}\n\n/** Clear all entries from the client cache. Destroys active clients. */\nexport function clearClientCache(): void {\n const cache = getClientCache();\n for (const entry of cache.values()) {\n try {\n entry.client.destroy();\n } catch {\n // client may already be destroyed\n }\n }\n cache.clear();\n}\n\nif (import.meta.vitest) {\n const { test, expect } = import.meta.vitest;\n\n test(\"getClientCache returns a Map\", () => {\n const cache = getClientCache();\n expect(cache).toBeInstanceOf(Map);\n });\n\n test(\"getClientCache returns the same instance on repeated calls\", () => {\n const a = getClientCache();\n const b = getClientCache();\n expect(a).toBe(b);\n });\n}\n","// Copyright 2026 Parity Technologies (UK) Ltd.\n// SPDX-License-Identifier: Apache-2.0\nimport type { ChainDefinition, PolkadotClient } from \"polkadot-api\";\nimport { createClient } from \"polkadot-api\";\nimport { createLogger } from \"@parity/product-sdk-logger\";\nimport { ChainNotSupportedError } from \"@parity/product-sdk-host\";\nimport { createProvider } from \"./providers.js\";\nimport { getClientCache, clearClientCache } from \"./hmr.js\";\nimport type { ChainEntry, ChainClientConfig, ChainClient } from \"./types.js\";\n\nconst log = createLogger(\"chain-client\");\n\n/**\n * Build a stand-in for a chain the host can't serve. Any property access (e.g.\n * `.query`, `.tx`) or call throws the original {@link ChainNotSupportedError},\n * so touching an unsupported chain surfaces a clear, detectable error rather\n * than hanging — without tanking the supported chains in the same client.\n */\nfunction unsupportedChainApi(error: ChainNotSupportedError): never {\n const handler: ProxyHandler<() => void> = {\n get: () => {\n throw error;\n },\n apply: () => {\n throw error;\n },\n };\n return new Proxy((() => {}) as () => void, handler) as never;\n}\n\n// Cache keys are scoped by a fingerprint of the config so that two\n// `createChainClient` calls with different chain sets don't collide.\nconst cacheKey = (fingerprint: string, genesis: string) => `${fingerprint}:${genesis}`;\n\nfunction findEntryByGenesis(genesis: string): ChainEntry | undefined {\n for (const [key, entry] of getClientCache()) {\n if (key.endsWith(`:${genesis}`)) return entry;\n }\n}\n\nconst clientInstances = new Map<string, Promise<ChainClient<any>>>();\n\n/** Build a stable fingerprint from sorted chain names + genesis hashes. */\nfunction configFingerprint(chains: Record<string, ChainDefinition>): string {\n return Object.entries(chains)\n .sort(([a], [b]) => a.localeCompare(b))\n .map(([name, desc]) => `${name}:${desc.genesis ?? \"unknown\"}`)\n .join(\"|\");\n}\n\n/**\n * Create a multi-chain client with user-provided descriptors and RPC endpoints.\n *\n * Returns fully-typed APIs for each chain plus raw `PolkadotClient` access via `.raw`.\n * Connections route through the host provider (`@parity/product-sdk-host`) — the SDK\n * is designed to run exclusively inside a host container (Polkadot Browser / Desktop).\n * Throws if no host provider is available; there is no direct-WebSocket fallback.\n *\n * Results are cached by genesis-hash fingerprint — calling with the same descriptors\n * returns the same instance.\n *\n * @example\n * ```ts\n * import { createChainClient } from \"@parity/product-sdk-chain-client\";\n * import { paseo_asset_hub } from \"@parity/product-sdk-descriptors/paseo-asset-hub\";\n * import { paseo_bulletin } from \"@parity/product-sdk-descriptors/paseo-bulletin\";\n *\n * const client = await createChainClient({\n * chains: { assetHub: paseo_asset_hub, bulletin: paseo_bulletin },\n * });\n *\n * // Fully typed from your descriptors\n * const account = await client.assetHub.query.System.Account.getValue(addr);\n * const fee = await client.bulletin.query.TransactionStorage.ByteFee.getValue();\n *\n * // Raw client for advanced use (e.g., a ContractRuntime for pallet-revive contracts)\n * import { createContractRuntimeFromClient } from \"@parity/product-sdk-contracts\";\n * const runtime = createContractRuntimeFromClient(client.raw.assetHub, paseo_asset_hub);\n *\n * // Cleanup\n * client.destroy();\n * ```\n */\nexport async function createChainClient<const TChains extends Record<string, ChainDefinition>>(\n config: ChainClientConfig<TChains>,\n): Promise<ChainClient<TChains>> {\n const fingerprint = configFingerprint(config.chains);\n\n const existing = clientInstances.get(fingerprint);\n if (existing) return existing as Promise<ChainClient<TChains>>;\n\n const promise = initChainClient(config, fingerprint).catch((err) => {\n // Clean up any clients created before the failure to avoid leaking\n // WebSocket connections that are unreachable except via destroyAll().\n const cache = getClientCache();\n for (const [key, entry] of cache) {\n if (key.startsWith(`${fingerprint}:`)) {\n try {\n entry.client.destroy();\n } catch {\n /* already destroyed */\n }\n cache.delete(key);\n }\n }\n clientInstances.delete(fingerprint);\n throw err;\n });\n clientInstances.set(fingerprint, promise);\n return promise;\n}\n\n/* @integration */\nasync function initChainClient<const TChains extends Record<string, ChainDefinition>>(\n config: ChainClientConfig<TChains>,\n fingerprint: string,\n): Promise<ChainClient<TChains>> {\n const names = Object.keys(config.chains) as (string & keyof TChains)[];\n const clientCache = getClientCache();\n\n // Create providers and clients in parallel\n const entries = await Promise.all(\n names.map(async (name) => {\n const descriptor = config.chains[name] as ChainDefinition;\n const genesis = descriptor.genesis;\n if (!genesis) {\n throw new Error(`Descriptor for chain \"${name}\" has no genesis hash.`);\n }\n try {\n const provider = await createProvider(genesis);\n const client = createClient(provider);\n\n // Populate HMR cache so getClient() and isConnected() work\n const key = cacheKey(fingerprint, genesis);\n if (!clientCache.has(key)) {\n clientCache.set(key, {\n client,\n api: new Map(),\n } satisfies ChainEntry);\n }\n\n return { name, descriptor, client, genesis, error: undefined };\n } catch (err) {\n // A chain the host can't serve must not tank the whole multi-chain\n // client — the supported chains stay usable, and this one surfaces a\n // clear error on first use instead of hanging. Any other failure\n // (e.g. not inside a container) is a hard error and still rejects.\n if (err instanceof ChainNotSupportedError) {\n log.warn(\n `Chain \"${name}\" is not supported by the host; its API will throw on use.`,\n { genesis },\n );\n return { name, descriptor, client: null, genesis, error: err };\n }\n throw err;\n }\n }),\n );\n\n // Build typed APIs and raw client map. Unsupported chains get a stand-in\n // whose access throws the original ChainNotSupportedError.\n const apis = {} as Record<string, unknown>;\n const raw = {} as Record<string, PolkadotClient>;\n\n for (const { name, descriptor, client, error } of entries) {\n if (client) {\n apis[name] = client.getTypedApi(descriptor);\n raw[name] = client;\n } else {\n const api = unsupportedChainApi(error as ChainNotSupportedError);\n apis[name] = api;\n raw[name] = api as unknown as PolkadotClient;\n }\n }\n\n return {\n ...apis,\n raw,\n destroy() {\n for (const { genesis } of entries) {\n const key = cacheKey(fingerprint, genesis);\n const entry = clientCache.get(key);\n if (entry) {\n try {\n entry.client.destroy();\n } catch {\n /* already destroyed */\n }\n clientCache.delete(key);\n }\n }\n clientInstances.delete(fingerprint);\n },\n } as ChainClient<TChains>;\n}\n\n/**\n * Destroy all chain client instances and reset internal caches.\n *\n * Tears down every connection created by {@link createChainClient}.\n */\nexport function destroyAll(): void {\n clearClientCache();\n clientInstances.clear();\n}\n\n/**\n * Get the raw `PolkadotClient` for a connected chain by its descriptor.\n *\n * The chain must have been initialized via {@link createChainClient} first.\n * Alternatively, use `client.raw.<name>` on the returned {@link ChainClient}.\n *\n * @throws If the chain has not been connected yet.\n */\nexport function getClient(descriptor: ChainDefinition): PolkadotClient {\n const genesis = descriptor.genesis;\n if (!genesis) throw new Error(\"Descriptor has no genesis hash.\");\n const entry = findEntryByGenesis(genesis);\n if (!entry?.client) {\n throw new Error(\n `Chain not connected (genesis: ${genesis}). Call createChainClient() first to establish connections.`,\n );\n }\n return entry.client;\n}\n\n/**\n * Check if a chain is currently connected.\n *\n * Synchronous — no side effects, no initialization.\n */\nexport function isConnected(descriptor: ChainDefinition): boolean {\n const genesis = descriptor.genesis;\n if (!genesis) return false;\n return findEntryByGenesis(genesis) !== undefined;\n}\n\nif (import.meta.vitest) {\n const { test, expect, beforeEach, vi } = import.meta.vitest;\n\n // Mock the provider + PAPI client factories so initChainClient can run without\n // a real host. Tests that pre-seed clientInstances short-circuit before these.\n vi.mock(\"./providers.js\", () => ({ createProvider: vi.fn() }));\n vi.mock(\"polkadot-api\", async (importOriginal) => ({\n ...(await importOriginal<typeof import(\"polkadot-api\")>()),\n createClient: vi.fn(),\n }));\n\n const fakeDescriptor = { genesis: \"0xtest\" } as ChainDefinition;\n const fakeClient = {\n destroy: () => {},\n getTypedApi: () => ({}),\n } as unknown as PolkadotClient;\n\n function seedCache(genesis: string, client: PolkadotClient, fp = \"test\") {\n getClientCache().set(cacheKey(fp, genesis), {\n client,\n api: new Map(),\n });\n }\n\n beforeEach(() => {\n clearClientCache();\n clientInstances.clear();\n });\n\n // --- isConnected ---\n\n test(\"isConnected returns false for unknown chain\", () => {\n expect(isConnected(fakeDescriptor)).toBe(false);\n });\n\n test(\"isConnected returns true after cache is populated\", () => {\n seedCache(\"0xtest\", fakeClient);\n expect(isConnected(fakeDescriptor)).toBe(true);\n });\n\n test(\"isConnected returns false for descriptor without genesis\", () => {\n expect(isConnected({} as ChainDefinition)).toBe(false);\n });\n\n // --- getClient ---\n\n test(\"getClient returns client from cache\", () => {\n seedCache(\"0xtest\", fakeClient);\n expect(getClient(fakeDescriptor)).toBe(fakeClient);\n });\n\n test(\"getClient throws for unconnected chain\", () => {\n expect(() => getClient(fakeDescriptor)).toThrow(/Chain not connected/);\n });\n\n test(\"getClient throws for descriptor without genesis\", () => {\n expect(() => getClient({} as ChainDefinition)).toThrow(/no genesis hash/);\n });\n\n // --- destroyAll ---\n\n test(\"destroyAll calls client.destroy() and clears caches\", () => {\n let destroyed = false;\n const trackableClient = {\n destroy: () => {\n destroyed = true;\n },\n getTypedApi: () => ({}),\n } as unknown as PolkadotClient;\n seedCache(\"0xtest\", trackableClient);\n clientInstances.set(\"test\", Promise.resolve({} as ChainClient<any>));\n destroyAll();\n expect(destroyed).toBe(true);\n expect(isConnected(fakeDescriptor)).toBe(false);\n expect(clientInstances.size).toBe(0);\n });\n\n // --- createChainClient ---\n\n test(\"createChainClient returns same promise for identical config\", async () => {\n const fakeResult = {} as ChainClient<any>;\n const fp = configFingerprint({ a: fakeDescriptor });\n clientInstances.set(fp, Promise.resolve(fakeResult));\n const result = await createChainClient({\n chains: { a: fakeDescriptor },\n });\n expect(result).toBe(fakeResult);\n });\n\n test(\"createChainClient deduplicates concurrent calls\", async () => {\n const fakeResult = {} as ChainClient<any>;\n const fp = configFingerprint({ x: fakeDescriptor });\n clientInstances.set(fp, Promise.resolve(fakeResult));\n const [a, b] = await Promise.all([\n createChainClient({ chains: { x: fakeDescriptor } }),\n createChainClient({ chains: { x: fakeDescriptor } }),\n ]);\n expect(a).toBe(b);\n });\n\n test(\"createChainClient keeps supported chains usable and defers unsupported-chain errors\", async () => {\n // initChainClient runs for real here — drive the mocked factories.\n const { createProvider } = await import(\"./providers.js\");\n const { createClient } = await import(\"polkadot-api\");\n const fakeTyped = { query: {} };\n vi.mocked(createClient).mockReturnValue({\n getTypedApi: () => fakeTyped,\n destroy: () => {},\n } as unknown as PolkadotClient);\n vi.mocked(createProvider).mockImplementation(async (genesis: string) => {\n if (genesis === \"0xbad\") throw new ChainNotSupportedError(genesis);\n return (() => {}) as never;\n });\n\n const good = { genesis: \"0xgood\" } as ChainDefinition;\n const bad = { genesis: \"0xbad\" } as ChainDefinition;\n const client = (await createChainClient({\n chains: { good, bad },\n })) as any;\n\n // The whole client still resolves; the supported chain is fully usable.\n expect(client.good).toBe(fakeTyped);\n // The unsupported chain surfaces the original error on use — no hang.\n expect(() => client.bad.query).toThrow(ChainNotSupportedError);\n });\n\n test(\"createChainClient returns different results for different configs\", async () => {\n const descA = { genesis: \"0xaaa\" } as ChainDefinition;\n const descB = { genesis: \"0xbbb\" } as ChainDefinition;\n const resultA = {} as ChainClient<any>;\n const resultB = {} as ChainClient<any>;\n clientInstances.set(configFingerprint({ a: descA }), Promise.resolve(resultA));\n clientInstances.set(configFingerprint({ b: descB }), Promise.resolve(resultB));\n const a = await createChainClient({ chains: { a: descA } });\n const b = await createChainClient({ chains: { b: descB } });\n expect(a).not.toBe(b);\n });\n\n // --- configFingerprint ---\n\n test(\"configFingerprint is stable regardless of key order\", () => {\n const d1 = { genesis: \"0x1\" } as ChainDefinition;\n const d2 = { genesis: \"0x2\" } as ChainDefinition;\n expect(configFingerprint({ a: d1, b: d2 })).toBe(configFingerprint({ b: d2, a: d1 }));\n });\n\n // --- findEntryByGenesis ---\n\n test(\"findEntryByGenesis returns undefined for missing genesis\", () => {\n expect(findEntryByGenesis(\"0xnonexistent\")).toBeUndefined();\n });\n\n // --- full lifecycle ---\n\n test(\"full lifecycle: seed, verify connected, destroy, verify disconnected\", () => {\n seedCache(\"0xtest\", fakeClient);\n expect(isConnected(fakeDescriptor)).toBe(true);\n expect(getClient(fakeDescriptor)).toBe(fakeClient);\n destroyAll();\n expect(isConnected(fakeDescriptor)).toBe(false);\n expect(() => getClient(fakeDescriptor)).toThrow(/Chain not connected/);\n });\n\n test(\"two fingerprints cached independently, destroy one leaves other intact\", () => {\n const sharedGenesis = \"0xshared\";\n const clientA = { destroy: () => {} } as PolkadotClient;\n const clientB = { destroy: () => {} } as PolkadotClient;\n const descriptorShared = { genesis: sharedGenesis } as ChainDefinition;\n\n seedCache(sharedGenesis, clientA, \"fpA\");\n seedCache(sharedGenesis, clientB, \"fpB\");\n\n expect(isConnected(descriptorShared)).toBe(true);\n\n // Destroy only fpA's entry\n const cache = getClientCache();\n const keyA = cacheKey(\"fpA\", sharedGenesis);\n cache.get(keyA)?.client.destroy();\n cache.delete(keyA);\n\n // fpB's entry still alive\n expect(isConnected(descriptorShared)).toBe(true);\n expect(getClient(descriptorShared)).toBe(clientB);\n });\n}\n","// Copyright 2026 Parity Technologies (UK) Ltd.\n// SPDX-License-Identifier: Apache-2.0\nimport type { ChainDefinition } from \"polkadot-api\";\nimport { createChainClient } from \"./clients.js\";\nimport type { ChainClient } from \"./types.js\";\n\n// Type-only imports — erased at compile time, zero bundle cost.\n// These give us per-chain TypedApi types without importing runtime descriptor data.\n// Every environment ships its own descriptor for each chain (asset hub, bulletin,\n// individuality) so that genesis hashes and metadata reflect the live chain\n// instance the consumer connects to.\nimport type { polkadot_asset_hub as PolkadotAssetHubDef } from \"@parity/product-sdk-descriptors/polkadot-asset-hub\";\nimport type { kusama_asset_hub as KusamaAssetHubDef } from \"@parity/product-sdk-descriptors/kusama-asset-hub\";\nimport type { paseo_asset_hub as PaseoAssetHubDef } from \"@parity/product-sdk-descriptors/paseo-asset-hub\";\nimport type { paseo_bulletin as PaseoBulletinDef } from \"@parity/product-sdk-descriptors/paseo-bulletin\";\nimport type { paseo_individuality as PaseoIndividualityDef } from \"@parity/product-sdk-descriptors/paseo-individuality\";\n\n/** Known network environment with built-in descriptors. */\nexport type Environment = \"polkadot\" | \"kusama\" | \"paseo\";\n\n/** Environments where all chains (asset hub, bulletin, individuality) are live. */\nconst AVAILABLE_ENVIRONMENTS: Set<Environment> = new Set([\"paseo\"]);\n\n/**\n * Lazy-load descriptors for a specific environment.\n *\n * Every chain (asset hub, bulletin, individuality) ships a per-environment\n * descriptor so that genesis hashes and metadata reflect the live chain\n * instance the consumer connects to. Dynamic imports are code-split per\n * environment, so a consumer using one environment doesn't bundle the others.\n */\nasync function loadDescriptors(env: Environment) {\n const loaders = {\n polkadot: () =>\n Promise.all([\n import(\"@parity/product-sdk-descriptors/polkadot-asset-hub\"),\n // Polkadot bulletin/individuality are not yet live; gated by\n // AVAILABLE_ENVIRONMENTS so this branch is unreachable today.\n Promise.reject(new Error(\"polkadot bulletin descriptor not yet available\")),\n Promise.reject(new Error(\"polkadot individuality descriptor not yet available\")),\n ]),\n kusama: () =>\n Promise.all([\n import(\"@parity/product-sdk-descriptors/kusama-asset-hub\"),\n Promise.reject(new Error(\"kusama bulletin descriptor not yet available\")),\n Promise.reject(new Error(\"kusama individuality descriptor not yet available\")),\n ]),\n paseo: () =>\n Promise.all([\n import(\"@parity/product-sdk-descriptors/paseo-asset-hub\"),\n import(\"@parity/product-sdk-descriptors/paseo-bulletin\"),\n import(\"@parity/product-sdk-descriptors/paseo-individuality\"),\n ]),\n };\n\n const [ahMod, bulletinMod, individualityMod] = await loaders[env]();\n\n const assetHub =\n \"polkadot_asset_hub\" in ahMod\n ? ahMod.polkadot_asset_hub\n : \"kusama_asset_hub\" in ahMod\n ? ahMod.kusama_asset_hub\n : (ahMod as { paseo_asset_hub: typeof PaseoAssetHubDef }).paseo_asset_hub;\n\n const bulletin = (bulletinMod as { paseo_bulletin: typeof PaseoBulletinDef }).paseo_bulletin;\n\n const individuality = (\n individualityMod as { paseo_individuality: typeof PaseoIndividualityDef }\n ).paseo_individuality;\n\n return { assetHub, bulletin, individuality };\n}\n\n/** Per-environment descriptor types for each chain in the preset. */\ntype PresetDescriptors = {\n polkadot: {\n assetHub: typeof PolkadotAssetHubDef;\n // Bulletin/individuality not yet live on polkadot — types reuse paseo\n // shape so the API surface stays consistent; runtime path is gated.\n bulletin: typeof PaseoBulletinDef;\n individuality: typeof PaseoIndividualityDef;\n };\n kusama: {\n assetHub: typeof KusamaAssetHubDef;\n bulletin: typeof PaseoBulletinDef;\n individuality: typeof PaseoIndividualityDef;\n };\n paseo: {\n assetHub: typeof PaseoAssetHubDef;\n bulletin: typeof PaseoBulletinDef;\n individuality: typeof PaseoIndividualityDef;\n };\n};\n\n/** The chain shape returned by {@link getChainAPI} for a given environment. */\nexport type PresetChains<E extends Environment> = PresetDescriptors[E];\n\n/**\n * Get a chain client for a known environment with built-in descriptors.\n *\n * This is the **zero-config** path — no need to import descriptors or specify\n * endpoints. For custom chains or BYOD descriptors, use\n * {@link createChainClient} instead.\n *\n * Returns the same {@link ChainClient} type as `createChainClient`, with\n * `assetHub`, `bulletin`, and `individuality` chain keys.\n *\n * @example\n * ```ts\n * import { getChainAPI } from \"@parity/product-sdk-chain-client\";\n *\n * const client = await getChainAPI(\"paseo\");\n *\n * // Fully typed — no descriptor imports needed\n * const account = await client.assetHub.query.System.Account.getValue(addr);\n * const fee = await client.bulletin.query.TransactionStorage.ByteFee.getValue();\n *\n * // Raw client for advanced use (e.g., a ContractRuntime for pallet-revive contracts)\n * import { createContractRuntimeFromClient } from \"@parity/product-sdk-contracts\";\n * import { paseo_asset_hub } from \"@parity/product-sdk-descriptors/paseo-asset-hub\";\n * const runtime = createContractRuntimeFromClient(client.raw.assetHub, paseo_asset_hub);\n *\n * client.destroy();\n * ```\n */\nexport async function getChainAPI<E extends Environment>(\n env: E,\n): Promise<ChainClient<PresetChains<E>>> {\n if (!AVAILABLE_ENVIRONMENTS.has(env)) {\n throw new Error(`Chain API for \"${env}\" is not yet available`);\n }\n\n const descriptors = await loadDescriptors(env);\n\n return createChainClient({\n chains: {\n assetHub: descriptors.assetHub,\n bulletin: descriptors.bulletin,\n individuality: descriptors.individuality,\n },\n }) as Promise<ChainClient<PresetChains<E>>>;\n}\n\nif (import.meta.vitest) {\n const { test, expect, beforeEach } = import.meta.vitest;\n const { destroyAll } = await import(\"./clients.js\");\n\n // Test-only genesis hashes for assertion — not used in production code.\n const GENESIS = {\n polkadot_asset_hub: \"0x68d56f15f85d3136970ec16946040bc1752654e906147f7e43e9d539d7c3de2f\",\n kusama_asset_hub: \"0x48239ef607d7928874027a43a67689209727dfb3d3dc5e5b03a39bdc2eda771a\",\n paseo_asset_hub: \"0xbf0488dbe9daa1de1c08c5f743e26fdc2a4ecd74cf87dd1b4b1eeb99ae4ef19f\",\n paseo_bulletin: \"0x8cfe6717dc4becfda2e13c488a1e2061ff2dfee96e7d031157f72d36716c0a22\",\n paseo_individuality: \"0xc5af1826b31493f08b7e2a823842f98575b806a784126f28da9608c68665afa5\",\n } as const;\n\n beforeEach(() => {\n destroyAll();\n });\n\n // --- GENESIS constants ---\n\n test(\"genesis constants are valid hex hashes\", () => {\n for (const hash of Object.values(GENESIS)) {\n expect(hash).toMatch(/^0x[a-f0-9]{64}$/);\n }\n });\n\n // --- getChainAPI ---\n\n test(\"polkadot and kusama throw as not yet available\", async () => {\n await expect(getChainAPI(\"polkadot\")).rejects.toThrow(\"not yet available\");\n await expect(getChainAPI(\"kusama\")).rejects.toThrow(\"not yet available\");\n });\n\n // --- loadDescriptors ---\n\n test(\"loadDescriptors returns descriptors with genesis hashes for paseo\", async () => {\n const descriptors = await loadDescriptors(\"paseo\");\n expect(descriptors).toBeDefined();\n expect(descriptors.assetHub).toBeDefined();\n expect(descriptors.bulletin).toBeDefined();\n expect(descriptors.individuality).toBeDefined();\n expect(descriptors.assetHub.genesis).toBe(GENESIS.paseo_asset_hub);\n expect(descriptors.bulletin.genesis).toBe(GENESIS.paseo_bulletin);\n expect(descriptors.individuality.genesis).toBe(GENESIS.paseo_individuality);\n });\n\n // --- AVAILABLE_ENVIRONMENTS ---\n\n test(\"paseo is currently available\", () => {\n expect(AVAILABLE_ENVIRONMENTS.has(\"paseo\")).toBe(true);\n expect(AVAILABLE_ENVIRONMENTS.has(\"polkadot\")).toBe(false);\n expect(AVAILABLE_ENVIRONMENTS.has(\"kusama\")).toBe(false);\n });\n}\n","// Copyright 2026 Parity Technologies (UK) Ltd.\n// SPDX-License-Identifier: Apache-2.0\n/**\n * Genesis hashes of well-known chains.\n *\n * Mirrors `WellKnownChain` from `@novasamatech/host-api-wrapper`. Hand-copied\n * (not re-exported) so chain-client doesn't pick up a direct Novasama\n * runtime dependency; genesis hashes are immutable so drift is impossible.\n */\nexport const WellKnownChain = {\n polkadotRelay: \"0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3\",\n polkadotAssetHub: \"0x68d56f15f85d3136970ec16946040bc1752654e906147f7e43e9d539d7c3de2f\",\n kusamaRelay: \"0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe\",\n kusamaAssetHub: \"0x48239ef607d7928874027a43a67689209727dfb3d3dc5e5b03a39bdc2eda771a\",\n westendRelay: \"0xe143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e\",\n westendAssetHub: \"0x67f9723393ef76214df0118c34bbbd3dbebc8ed46a10973a8c969d48fe7598c9\",\n rococo: \"0x6408de7737c59c238890533af25896a2c20608d8b380bb01029acb392781063e\",\n} as const;\n\n/** Genesis hash of a well-known chain - the value type of {@link WellKnownChain}. */\nexport type WellKnownChainHash = (typeof WellKnownChain)[keyof typeof WellKnownChain];\n\nif (import.meta.vitest) {\n const { test, expect } = import.meta.vitest;\n\n test(\"WellKnownChain entries are 0x-prefixed 32-byte hex strings\", () => {\n for (const hash of Object.values(WellKnownChain)) {\n expect(hash).toMatch(/^0x[0-9a-f]{64}$/);\n }\n });\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/providers.ts","../src/hmr.ts","../src/clients.ts","../src/presets.ts","../src/well-known-chain.ts"],"names":[],"mappings":";;;;;;AAaA,eAAsB,eAAe,WAAA,EAA+C;AAChF,EAAA,MAAM,YAAA,GAAe,MAAM,eAAA,CAAgB,WAA4B,CAAA;AACvE,EAAA,IAAI,CAAC,YAAA,EAAc;AACf,IAAA,MAAM,IAAI,KAAA;AAAA,MACN,uCAAuC,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cAAA,GAAiB;AAAA,EAC1B,aAAA,EAAe,oEAAA;AAAA,EACf,gBAAA,EAAkB,oEAAA;AAAA,EAClB,WAAA,EAAa,oEAAA;AAAA,EACb,cAAA,EAAgB,oEAAA;AAAA,EAChB,YAAA,EAAc,oEAAA;AAAA,EACd,eAAA,EAAiB,oEAAA;AAAA,EACjB,MAAA,EAAQ;AACZ","file":"index.js","sourcesContent":["// Copyright 2026 Parity Technologies (UK) Ltd.\n// SPDX-License-Identifier: Apache-2.0\nimport { getHostProvider } from \"@parity/product-sdk-host\";\nimport type { JsonRpcProvider } from \"polkadot-api\";\n\n/**\n * Create a PAPI-compatible JSON-RPC provider for a chain.\n *\n * Routes connections through the host provider (`@parity/product-sdk-host`).\n * The SDK is designed to run exclusively inside a host container.\n *\n * @throws {Error} If the host provider is unavailable (not inside a container).\n */\nexport async function createProvider(genesisHash: string): Promise<JsonRpcProvider> {\n const hostProvider = await getHostProvider(genesisHash as `0x${string}`);\n if (!hostProvider) {\n throw new Error(\n `Host provider unavailable for chain ${genesisHash}. Ensure you are running inside a host container (Polkadot Browser / Desktop).`,\n );\n }\n return hostProvider;\n}\n\nif (import.meta.vitest) {\n const { test, expect, vi, beforeEach } = import.meta.vitest;\n\n // Shared state between hoisted mocks and tests\n const state = vi.hoisted(() => ({\n fakeProvider: (() => {}) as unknown as JsonRpcProvider,\n hostProviderCalls: [] as unknown[][],\n hostProviderAvailable: true,\n hostProviderError: null as Error | null,\n }));\n\n vi.mock(\"@parity/product-sdk-host\", async (importOriginal) => ({\n ...(await importOriginal<typeof import(\"@parity/product-sdk-host\")>()),\n getHostProvider: async (...args: unknown[]) => {\n state.hostProviderCalls.push(args);\n if (state.hostProviderError) throw state.hostProviderError;\n if (!state.hostProviderAvailable) return null;\n return state.fakeProvider;\n },\n }));\n\n beforeEach(() => {\n state.hostProviderCalls = [];\n state.hostProviderAvailable = true;\n state.hostProviderError = null;\n });\n\n test(\"returns host provider when available\", async () => {\n const result = await createProvider(\"0xabc\");\n expect(result).toBe(state.fakeProvider);\n expect(state.hostProviderCalls.length).toBe(1);\n expect(state.hostProviderCalls[0][0]).toBe(\"0xabc\");\n });\n\n test(\"throws when host provider unavailable\", async () => {\n state.hostProviderAvailable = false;\n await expect(createProvider(\"0xabc\")).rejects.toThrow(/Host provider unavailable/);\n });\n\n test(\"propagates ChainNotSupportedError from the host provider\", async () => {\n const { ChainNotSupportedError } = await import(\"@parity/product-sdk-host\");\n state.hostProviderError = new ChainNotSupportedError(\"0xabc\");\n // The unsupported-chain error must surface to the caller rather than being\n // collapsed into the generic \"unavailable\" path or swallowed.\n await expect(createProvider(\"0xabc\")).rejects.toBeInstanceOf(ChainNotSupportedError);\n });\n}\n","// Copyright 2026 Parity Technologies (UK) Ltd.\n// SPDX-License-Identifier: Apache-2.0\nimport type { ChainEntry } from \"./types.js\";\n\ndeclare global {\n var __chainClientCache: Map<string, ChainEntry> | undefined;\n}\n\n/** Get the HMR-safe client cache, keyed by genesis hash. */\nexport function getClientCache(): Map<string, ChainEntry> {\n globalThis.__chainClientCache ??= new Map();\n return globalThis.__chainClientCache;\n}\n\n/** Clear all entries from the client cache. Destroys active clients. */\nexport function clearClientCache(): void {\n const cache = getClientCache();\n for (const entry of cache.values()) {\n try {\n entry.client.destroy();\n } catch {\n // client may already be destroyed\n }\n }\n cache.clear();\n}\n\nif (import.meta.vitest) {\n const { test, expect } = import.meta.vitest;\n\n test(\"getClientCache returns a Map\", () => {\n const cache = getClientCache();\n expect(cache).toBeInstanceOf(Map);\n });\n\n test(\"getClientCache returns the same instance on repeated calls\", () => {\n const a = getClientCache();\n const b = getClientCache();\n expect(a).toBe(b);\n });\n}\n","// Copyright 2026 Parity Technologies (UK) Ltd.\n// SPDX-License-Identifier: Apache-2.0\nimport type { ChainDefinition, PolkadotClient } from \"polkadot-api\";\nimport { createClient } from \"polkadot-api\";\nimport { createLogger } from \"@parity/product-sdk-logger\";\nimport { ChainNotSupportedError } from \"@parity/product-sdk-host\";\nimport { createProvider } from \"./providers.js\";\nimport { getClientCache, clearClientCache } from \"./hmr.js\";\nimport type { ChainEntry, ChainClientConfig, ChainClient } from \"./types.js\";\n\nconst log = createLogger(\"chain-client\");\n\n/**\n * Build a stand-in for a chain the host can't serve. Any property access (e.g.\n * `.query`, `.tx`) or call throws the original {@link ChainNotSupportedError},\n * so touching an unsupported chain surfaces a clear, detectable error rather\n * than hanging — without tanking the supported chains in the same client.\n */\nfunction unsupportedChainApi(error: ChainNotSupportedError): never {\n const handler: ProxyHandler<() => void> = {\n get: () => {\n throw error;\n },\n apply: () => {\n throw error;\n },\n };\n return new Proxy((() => {}) as () => void, handler) as never;\n}\n\n// Cache keys are scoped by a fingerprint of the config so that two\n// `createChainClient` calls with different chain sets don't collide.\nconst cacheKey = (fingerprint: string, genesis: string) => `${fingerprint}:${genesis}`;\n\nfunction findEntryByGenesis(genesis: string): ChainEntry | undefined {\n for (const [key, entry] of getClientCache()) {\n if (key.endsWith(`:${genesis}`)) return entry;\n }\n}\n\nconst clientInstances = new Map<string, Promise<ChainClient<any>>>();\n\n/** Build a stable fingerprint from sorted chain names + genesis hashes. */\nfunction configFingerprint(chains: Record<string, ChainDefinition>): string {\n return Object.entries(chains)\n .sort(([a], [b]) => a.localeCompare(b))\n .map(([name, desc]) => `${name}:${desc.genesis ?? \"unknown\"}`)\n .join(\"|\");\n}\n\n/**\n * Create a multi-chain client with user-provided descriptors and RPC endpoints.\n *\n * Returns fully-typed APIs for each chain plus raw `PolkadotClient` access via `.raw`.\n * Connections route through the host provider (`@parity/product-sdk-host`) — the SDK\n * is designed to run exclusively inside a host container (Polkadot Browser / Desktop).\n * Throws if no host provider is available; there is no direct-WebSocket fallback.\n *\n * Results are cached by genesis-hash fingerprint — calling with the same descriptors\n * returns the same instance.\n *\n * @example\n * ```ts\n * import { createChainClient } from \"@parity/product-sdk-chain-client\";\n * import { paseo_asset_hub } from \"@parity/product-sdk-descriptors/paseo-asset-hub\";\n * import { paseo_bulletin } from \"@parity/product-sdk-descriptors/paseo-bulletin\";\n *\n * const client = await createChainClient({\n * chains: { assetHub: paseo_asset_hub, bulletin: paseo_bulletin },\n * });\n *\n * // Fully typed from your descriptors\n * const account = await client.assetHub.query.System.Account.getValue(addr);\n * const fee = await client.bulletin.query.TransactionStorage.ByteFee.getValue();\n *\n * // Raw client for advanced use (e.g., a ContractRuntime for pallet-revive contracts)\n * import { createContractRuntimeFromClient } from \"@parity/product-sdk-contracts\";\n * const runtime = createContractRuntimeFromClient(client.raw.assetHub, paseo_asset_hub);\n *\n * // Cleanup\n * client.destroy();\n * ```\n */\nexport async function createChainClient<const TChains extends Record<string, ChainDefinition>>(\n config: ChainClientConfig<TChains>,\n): Promise<ChainClient<TChains>> {\n const fingerprint = configFingerprint(config.chains);\n\n const existing = clientInstances.get(fingerprint);\n if (existing) return existing as Promise<ChainClient<TChains>>;\n\n const promise = initChainClient(config, fingerprint).catch((err) => {\n // Clean up any clients created before the failure to avoid leaking\n // WebSocket connections that are unreachable except via destroyAll().\n const cache = getClientCache();\n for (const [key, entry] of cache) {\n if (key.startsWith(`${fingerprint}:`)) {\n try {\n entry.client.destroy();\n } catch {\n /* already destroyed */\n }\n cache.delete(key);\n }\n }\n clientInstances.delete(fingerprint);\n throw err;\n });\n clientInstances.set(fingerprint, promise);\n return promise;\n}\n\n/* @integration */\nasync function initChainClient<const TChains extends Record<string, ChainDefinition>>(\n config: ChainClientConfig<TChains>,\n fingerprint: string,\n): Promise<ChainClient<TChains>> {\n const names = Object.keys(config.chains) as (string & keyof TChains)[];\n const clientCache = getClientCache();\n\n // Create providers and clients in parallel\n const entries = await Promise.all(\n names.map(async (name) => {\n const descriptor = config.chains[name] as ChainDefinition;\n const genesis = descriptor.genesis;\n if (!genesis) {\n throw new Error(`Descriptor for chain \"${name}\" has no genesis hash.`);\n }\n try {\n const provider = await createProvider(genesis);\n const client = createClient(provider);\n\n // Populate HMR cache so getClient() and isConnected() work\n const key = cacheKey(fingerprint, genesis);\n if (!clientCache.has(key)) {\n clientCache.set(key, {\n client,\n api: new Map(),\n } satisfies ChainEntry);\n }\n\n return { name, descriptor, client, genesis, error: undefined };\n } catch (err) {\n // A chain the host can't serve must not tank the whole multi-chain\n // client — the supported chains stay usable, and this one surfaces a\n // clear error on first use instead of hanging. Any other failure\n // (e.g. not inside a container) is a hard error and still rejects.\n if (err instanceof ChainNotSupportedError) {\n log.warn(\n `Chain \"${name}\" is not supported by the host; its API will throw on use.`,\n { genesis },\n );\n return { name, descriptor, client: null, genesis, error: err };\n }\n throw err;\n }\n }),\n );\n\n // Build typed APIs and raw client map. Unsupported chains get a stand-in\n // whose access throws the original ChainNotSupportedError.\n const apis = {} as Record<string, unknown>;\n const raw = {} as Record<string, PolkadotClient>;\n\n for (const { name, descriptor, client, error } of entries) {\n if (client) {\n apis[name] = client.getTypedApi(descriptor);\n raw[name] = client;\n } else {\n const api = unsupportedChainApi(error as ChainNotSupportedError);\n apis[name] = api;\n raw[name] = api as unknown as PolkadotClient;\n }\n }\n\n return {\n ...apis,\n raw,\n destroy() {\n for (const { genesis } of entries) {\n const key = cacheKey(fingerprint, genesis);\n const entry = clientCache.get(key);\n if (entry) {\n try {\n entry.client.destroy();\n } catch {\n /* already destroyed */\n }\n clientCache.delete(key);\n }\n }\n clientInstances.delete(fingerprint);\n },\n } as ChainClient<TChains>;\n}\n\n/**\n * Destroy all chain client instances and reset internal caches.\n *\n * Tears down every connection created by {@link createChainClient}.\n */\nexport function destroyAll(): void {\n clearClientCache();\n clientInstances.clear();\n}\n\n/**\n * Get the raw `PolkadotClient` for a connected chain by its descriptor.\n *\n * The chain must have been initialized via {@link createChainClient} first.\n * Alternatively, use `client.raw.<name>` on the returned {@link ChainClient}.\n *\n * @throws If the chain has not been connected yet.\n */\nexport function getClient(descriptor: ChainDefinition): PolkadotClient {\n const genesis = descriptor.genesis;\n if (!genesis) throw new Error(\"Descriptor has no genesis hash.\");\n const entry = findEntryByGenesis(genesis);\n if (!entry?.client) {\n throw new Error(\n `Chain not connected (genesis: ${genesis}). Call createChainClient() first to establish connections.`,\n );\n }\n return entry.client;\n}\n\n/**\n * Check if a chain is currently connected.\n *\n * Synchronous — no side effects, no initialization.\n */\nexport function isConnected(descriptor: ChainDefinition): boolean {\n const genesis = descriptor.genesis;\n if (!genesis) return false;\n return findEntryByGenesis(genesis) !== undefined;\n}\n\nif (import.meta.vitest) {\n const { test, expect, beforeEach, vi } = import.meta.vitest;\n\n // Mock the provider + PAPI client factories so initChainClient can run without\n // a real host. Tests that pre-seed clientInstances short-circuit before these.\n vi.mock(\"./providers.js\", () => ({ createProvider: vi.fn() }));\n vi.mock(\"polkadot-api\", async (importOriginal) => ({\n ...(await importOriginal<typeof import(\"polkadot-api\")>()),\n createClient: vi.fn(),\n }));\n\n const fakeDescriptor = { genesis: \"0xtest\" } as ChainDefinition;\n const fakeClient = {\n destroy: () => {},\n getTypedApi: () => ({}),\n } as unknown as PolkadotClient;\n\n function seedCache(genesis: string, client: PolkadotClient, fp = \"test\") {\n getClientCache().set(cacheKey(fp, genesis), {\n client,\n api: new Map(),\n });\n }\n\n beforeEach(() => {\n clearClientCache();\n clientInstances.clear();\n });\n\n // --- isConnected ---\n\n test(\"isConnected returns false for unknown chain\", () => {\n expect(isConnected(fakeDescriptor)).toBe(false);\n });\n\n test(\"isConnected returns true after cache is populated\", () => {\n seedCache(\"0xtest\", fakeClient);\n expect(isConnected(fakeDescriptor)).toBe(true);\n });\n\n test(\"isConnected returns false for descriptor without genesis\", () => {\n expect(isConnected({} as ChainDefinition)).toBe(false);\n });\n\n // --- getClient ---\n\n test(\"getClient returns client from cache\", () => {\n seedCache(\"0xtest\", fakeClient);\n expect(getClient(fakeDescriptor)).toBe(fakeClient);\n });\n\n test(\"getClient throws for unconnected chain\", () => {\n expect(() => getClient(fakeDescriptor)).toThrow(/Chain not connected/);\n });\n\n test(\"getClient throws for descriptor without genesis\", () => {\n expect(() => getClient({} as ChainDefinition)).toThrow(/no genesis hash/);\n });\n\n // --- destroyAll ---\n\n test(\"destroyAll calls client.destroy() and clears caches\", () => {\n let destroyed = false;\n const trackableClient = {\n destroy: () => {\n destroyed = true;\n },\n getTypedApi: () => ({}),\n } as unknown as PolkadotClient;\n seedCache(\"0xtest\", trackableClient);\n clientInstances.set(\"test\", Promise.resolve({} as ChainClient<any>));\n destroyAll();\n expect(destroyed).toBe(true);\n expect(isConnected(fakeDescriptor)).toBe(false);\n expect(clientInstances.size).toBe(0);\n });\n\n // --- createChainClient ---\n\n test(\"createChainClient returns same promise for identical config\", async () => {\n const fakeResult = {} as ChainClient<any>;\n const fp = configFingerprint({ a: fakeDescriptor });\n clientInstances.set(fp, Promise.resolve(fakeResult));\n const result = await createChainClient({\n chains: { a: fakeDescriptor },\n });\n expect(result).toBe(fakeResult);\n });\n\n test(\"createChainClient deduplicates concurrent calls\", async () => {\n const fakeResult = {} as ChainClient<any>;\n const fp = configFingerprint({ x: fakeDescriptor });\n clientInstances.set(fp, Promise.resolve(fakeResult));\n const [a, b] = await Promise.all([\n createChainClient({ chains: { x: fakeDescriptor } }),\n createChainClient({ chains: { x: fakeDescriptor } }),\n ]);\n expect(a).toBe(b);\n });\n\n test(\"createChainClient keeps supported chains usable and defers unsupported-chain errors\", async () => {\n // initChainClient runs for real here — drive the mocked factories.\n const { createProvider } = await import(\"./providers.js\");\n const { createClient } = await import(\"polkadot-api\");\n const fakeTyped = { query: {} };\n vi.mocked(createClient).mockReturnValue({\n getTypedApi: () => fakeTyped,\n destroy: () => {},\n } as unknown as PolkadotClient);\n vi.mocked(createProvider).mockImplementation(async (genesis: string) => {\n if (genesis === \"0xbad\") throw new ChainNotSupportedError(genesis);\n return (() => {}) as never;\n });\n\n const good = { genesis: \"0xgood\" } as ChainDefinition;\n const bad = { genesis: \"0xbad\" } as ChainDefinition;\n const client = (await createChainClient({\n chains: { good, bad },\n })) as any;\n\n // The whole client still resolves; the supported chain is fully usable.\n expect(client.good).toBe(fakeTyped);\n // The unsupported chain surfaces the original error on use — no hang.\n expect(() => client.bad.query).toThrow(ChainNotSupportedError);\n });\n\n test(\"createChainClient returns different results for different configs\", async () => {\n const descA = { genesis: \"0xaaa\" } as ChainDefinition;\n const descB = { genesis: \"0xbbb\" } as ChainDefinition;\n const resultA = {} as ChainClient<any>;\n const resultB = {} as ChainClient<any>;\n clientInstances.set(configFingerprint({ a: descA }), Promise.resolve(resultA));\n clientInstances.set(configFingerprint({ b: descB }), Promise.resolve(resultB));\n const a = await createChainClient({ chains: { a: descA } });\n const b = await createChainClient({ chains: { b: descB } });\n expect(a).not.toBe(b);\n });\n\n // --- configFingerprint ---\n\n test(\"configFingerprint is stable regardless of key order\", () => {\n const d1 = { genesis: \"0x1\" } as ChainDefinition;\n const d2 = { genesis: \"0x2\" } as ChainDefinition;\n expect(configFingerprint({ a: d1, b: d2 })).toBe(configFingerprint({ b: d2, a: d1 }));\n });\n\n // --- findEntryByGenesis ---\n\n test(\"findEntryByGenesis returns undefined for missing genesis\", () => {\n expect(findEntryByGenesis(\"0xnonexistent\")).toBeUndefined();\n });\n\n // --- full lifecycle ---\n\n test(\"full lifecycle: seed, verify connected, destroy, verify disconnected\", () => {\n seedCache(\"0xtest\", fakeClient);\n expect(isConnected(fakeDescriptor)).toBe(true);\n expect(getClient(fakeDescriptor)).toBe(fakeClient);\n destroyAll();\n expect(isConnected(fakeDescriptor)).toBe(false);\n expect(() => getClient(fakeDescriptor)).toThrow(/Chain not connected/);\n });\n\n test(\"two fingerprints cached independently, destroy one leaves other intact\", () => {\n const sharedGenesis = \"0xshared\";\n const clientA = { destroy: () => {} } as PolkadotClient;\n const clientB = { destroy: () => {} } as PolkadotClient;\n const descriptorShared = { genesis: sharedGenesis } as ChainDefinition;\n\n seedCache(sharedGenesis, clientA, \"fpA\");\n seedCache(sharedGenesis, clientB, \"fpB\");\n\n expect(isConnected(descriptorShared)).toBe(true);\n\n // Destroy only fpA's entry\n const cache = getClientCache();\n const keyA = cacheKey(\"fpA\", sharedGenesis);\n cache.get(keyA)?.client.destroy();\n cache.delete(keyA);\n\n // fpB's entry still alive\n expect(isConnected(descriptorShared)).toBe(true);\n expect(getClient(descriptorShared)).toBe(clientB);\n });\n}\n","// Copyright 2026 Parity Technologies (UK) Ltd.\n// SPDX-License-Identifier: Apache-2.0\nimport type { ChainDefinition } from \"polkadot-api\";\nimport { createChainClient } from \"./clients.js\";\nimport type { ChainClient } from \"./types.js\";\n\n// Type-only imports — erased at compile time, zero bundle cost.\n// These give us per-chain TypedApi types without importing runtime descriptor data.\n// Every environment ships its own descriptor for each chain (asset hub, bulletin,\n// individuality) so that genesis hashes and metadata reflect the live chain\n// instance the consumer connects to.\nimport type { polkadot_asset_hub as PolkadotAssetHubDef } from \"@parity/product-sdk-descriptors/polkadot-asset-hub\";\nimport type { kusama_asset_hub as KusamaAssetHubDef } from \"@parity/product-sdk-descriptors/kusama-asset-hub\";\nimport type { paseo_asset_hub as PaseoAssetHubDef } from \"@parity/product-sdk-descriptors/paseo-asset-hub\";\nimport type { paseo_bulletin as PaseoBulletinDef } from \"@parity/product-sdk-descriptors/paseo-bulletin\";\nimport type { paseo_individuality as PaseoIndividualityDef } from \"@parity/product-sdk-descriptors/paseo-individuality\";\nimport type { summit_asset_hub as SummitAssetHubDef } from \"@parity/product-sdk-descriptors/summit-asset-hub\";\nimport type { summit_bulletin as SummitBulletinDef } from \"@parity/product-sdk-descriptors/summit-bulletin\";\nimport type { summit_individuality as SummitIndividualityDef } from \"@parity/product-sdk-descriptors/summit-individuality\";\n\n/** Known network environment with built-in descriptors. */\nexport type Environment = \"polkadot\" | \"kusama\" | \"paseo\" | \"summit\";\n\n/** Environments where all chains (asset hub, bulletin, individuality) are live. */\nconst AVAILABLE_ENVIRONMENTS: Set<Environment> = new Set([\"paseo\", \"summit\"]);\n\n/**\n * Lazy-load descriptors for a specific environment.\n *\n * Every chain (asset hub, bulletin, individuality) ships a per-environment\n * descriptor so that genesis hashes and metadata reflect the live chain\n * instance the consumer connects to. Dynamic imports are code-split per\n * environment, so a consumer using one environment doesn't bundle the others.\n */\nasync function loadDescriptors(env: Environment) {\n const loaders = {\n polkadot: () =>\n Promise.all([\n import(\"@parity/product-sdk-descriptors/polkadot-asset-hub\"),\n // Polkadot bulletin/individuality are not yet live; gated by\n // AVAILABLE_ENVIRONMENTS so this branch is unreachable today.\n Promise.reject(new Error(\"polkadot bulletin descriptor not yet available\")),\n Promise.reject(new Error(\"polkadot individuality descriptor not yet available\")),\n ]),\n kusama: () =>\n Promise.all([\n import(\"@parity/product-sdk-descriptors/kusama-asset-hub\"),\n Promise.reject(new Error(\"kusama bulletin descriptor not yet available\")),\n Promise.reject(new Error(\"kusama individuality descriptor not yet available\")),\n ]),\n paseo: () =>\n Promise.all([\n import(\"@parity/product-sdk-descriptors/paseo-asset-hub\"),\n import(\"@parity/product-sdk-descriptors/paseo-bulletin\"),\n import(\"@parity/product-sdk-descriptors/paseo-individuality\"),\n ]),\n summit: () =>\n Promise.all([\n import(\"@parity/product-sdk-descriptors/summit-asset-hub\"),\n import(\"@parity/product-sdk-descriptors/summit-bulletin\"),\n import(\"@parity/product-sdk-descriptors/summit-individuality\"),\n ]),\n };\n\n const [ahMod, bulletinMod, individualityMod] = await loaders[env]();\n\n const assetHub =\n \"polkadot_asset_hub\" in ahMod\n ? ahMod.polkadot_asset_hub\n : \"kusama_asset_hub\" in ahMod\n ? ahMod.kusama_asset_hub\n : \"summit_asset_hub\" in ahMod\n ? (ahMod as { summit_asset_hub: typeof SummitAssetHubDef }).summit_asset_hub\n : (ahMod as { paseo_asset_hub: typeof PaseoAssetHubDef }).paseo_asset_hub;\n\n const bulletin =\n \"summit_bulletin\" in bulletinMod\n ? (bulletinMod as { summit_bulletin: typeof SummitBulletinDef }).summit_bulletin\n : (bulletinMod as { paseo_bulletin: typeof PaseoBulletinDef }).paseo_bulletin;\n\n const individuality =\n \"summit_individuality\" in individualityMod\n ? (individualityMod as { summit_individuality: typeof SummitIndividualityDef })\n .summit_individuality\n : (individualityMod as { paseo_individuality: typeof PaseoIndividualityDef })\n .paseo_individuality;\n\n return { assetHub, bulletin, individuality };\n}\n\n/** Per-environment descriptor types for each chain in the preset. */\ntype PresetDescriptors = {\n polkadot: {\n assetHub: typeof PolkadotAssetHubDef;\n // Bulletin/individuality not yet live on polkadot — types reuse paseo\n // shape so the API surface stays consistent; runtime path is gated.\n bulletin: typeof PaseoBulletinDef;\n individuality: typeof PaseoIndividualityDef;\n };\n kusama: {\n assetHub: typeof KusamaAssetHubDef;\n bulletin: typeof PaseoBulletinDef;\n individuality: typeof PaseoIndividualityDef;\n };\n paseo: {\n assetHub: typeof PaseoAssetHubDef;\n bulletin: typeof PaseoBulletinDef;\n individuality: typeof PaseoIndividualityDef;\n };\n summit: {\n assetHub: typeof SummitAssetHubDef;\n bulletin: typeof SummitBulletinDef;\n individuality: typeof SummitIndividualityDef;\n };\n};\n\n/** The chain shape returned by {@link getChainAPI} for a given environment. */\nexport type PresetChains<E extends Environment> = PresetDescriptors[E];\n\n/**\n * Get a chain client for a known environment with built-in descriptors.\n *\n * This is the **zero-config** path — no need to import descriptors or specify\n * endpoints. For custom chains or BYOD descriptors, use\n * {@link createChainClient} instead.\n *\n * Returns the same {@link ChainClient} type as `createChainClient`, with\n * `assetHub`, `bulletin`, and `individuality` chain keys.\n *\n * @example\n * ```ts\n * import { getChainAPI } from \"@parity/product-sdk-chain-client\";\n *\n * const client = await getChainAPI(\"paseo\");\n *\n * // Fully typed — no descriptor imports needed\n * const account = await client.assetHub.query.System.Account.getValue(addr);\n * const fee = await client.bulletin.query.TransactionStorage.ByteFee.getValue();\n *\n * // Raw client for advanced use (e.g., a ContractRuntime for pallet-revive contracts)\n * import { createContractRuntimeFromClient } from \"@parity/product-sdk-contracts\";\n * import { paseo_asset_hub } from \"@parity/product-sdk-descriptors/paseo-asset-hub\";\n * const runtime = createContractRuntimeFromClient(client.raw.assetHub, paseo_asset_hub);\n *\n * client.destroy();\n * ```\n */\nexport async function getChainAPI<E extends Environment>(\n env: E,\n): Promise<ChainClient<PresetChains<E>>> {\n if (!AVAILABLE_ENVIRONMENTS.has(env)) {\n throw new Error(`Chain API for \"${env}\" is not yet available`);\n }\n\n const descriptors = await loadDescriptors(env);\n\n return createChainClient({\n chains: {\n assetHub: descriptors.assetHub,\n bulletin: descriptors.bulletin,\n individuality: descriptors.individuality,\n },\n }) as Promise<ChainClient<PresetChains<E>>>;\n}\n\nif (import.meta.vitest) {\n const { test, expect, beforeEach } = import.meta.vitest;\n const { destroyAll } = await import(\"./clients.js\");\n\n // Test-only genesis hashes for assertion — not used in production code.\n const GENESIS = {\n polkadot_asset_hub: \"0x68d56f15f85d3136970ec16946040bc1752654e906147f7e43e9d539d7c3de2f\",\n kusama_asset_hub: \"0x48239ef607d7928874027a43a67689209727dfb3d3dc5e5b03a39bdc2eda771a\",\n paseo_asset_hub: \"0xbf0488dbe9daa1de1c08c5f743e26fdc2a4ecd74cf87dd1b4b1eeb99ae4ef19f\",\n paseo_bulletin: \"0x8cfe6717dc4becfda2e13c488a1e2061ff2dfee96e7d031157f72d36716c0a22\",\n paseo_individuality: \"0xc5af1826b31493f08b7e2a823842f98575b806a784126f28da9608c68665afa5\",\n summit_asset_hub: \"0xf388dc6d6cdf6fb77eac3c4a91f31bc0c8642b142f1a757512ab7849f9f70660\",\n summit_bulletin: \"0x147aae0d60625af72300d4d5ebd5dcb869f7ac4c6c1a326be1cbb14a4a65ae77\",\n summit_individuality: \"0xbe5238f82c3553bc57ac3be43bef110bd58c49ad0744110814985195ca7d8c4e\",\n } as const;\n\n beforeEach(() => {\n destroyAll();\n });\n\n // --- GENESIS constants ---\n\n test(\"genesis constants are valid hex hashes\", () => {\n for (const hash of Object.values(GENESIS)) {\n expect(hash).toMatch(/^0x[a-f0-9]{64}$/);\n }\n });\n\n // --- getChainAPI ---\n\n test(\"polkadot and kusama throw as not yet available\", async () => {\n await expect(getChainAPI(\"polkadot\")).rejects.toThrow(\"not yet available\");\n await expect(getChainAPI(\"kusama\")).rejects.toThrow(\"not yet available\");\n });\n\n // --- loadDescriptors ---\n\n test(\"loadDescriptors returns descriptors with genesis hashes for paseo\", async () => {\n const descriptors = await loadDescriptors(\"paseo\");\n expect(descriptors).toBeDefined();\n expect(descriptors.assetHub).toBeDefined();\n expect(descriptors.bulletin).toBeDefined();\n expect(descriptors.individuality).toBeDefined();\n expect(descriptors.assetHub.genesis).toBe(GENESIS.paseo_asset_hub);\n expect(descriptors.bulletin.genesis).toBe(GENESIS.paseo_bulletin);\n expect(descriptors.individuality.genesis).toBe(GENESIS.paseo_individuality);\n });\n\n test(\"loadDescriptors returns descriptors with genesis hashes for summit\", async () => {\n const descriptors = await loadDescriptors(\"summit\");\n expect(descriptors).toBeDefined();\n expect(descriptors.assetHub).toBeDefined();\n expect(descriptors.bulletin).toBeDefined();\n expect(descriptors.individuality).toBeDefined();\n expect(descriptors.assetHub.genesis).toBe(GENESIS.summit_asset_hub);\n expect(descriptors.bulletin.genesis).toBe(GENESIS.summit_bulletin);\n expect(descriptors.individuality.genesis).toBe(GENESIS.summit_individuality);\n });\n\n // --- AVAILABLE_ENVIRONMENTS ---\n\n test(\"paseo and summit are currently available\", () => {\n expect(AVAILABLE_ENVIRONMENTS.has(\"paseo\")).toBe(true);\n expect(AVAILABLE_ENVIRONMENTS.has(\"summit\")).toBe(true);\n expect(AVAILABLE_ENVIRONMENTS.has(\"polkadot\")).toBe(false);\n expect(AVAILABLE_ENVIRONMENTS.has(\"kusama\")).toBe(false);\n });\n}\n","// Copyright 2026 Parity Technologies (UK) Ltd.\n// SPDX-License-Identifier: Apache-2.0\n/**\n * Genesis hashes of well-known chains.\n *\n * Mirrors `WellKnownChain` from `@novasamatech/host-api-wrapper`. Hand-copied\n * (not re-exported) so chain-client doesn't pick up a direct Novasama\n * runtime dependency; genesis hashes are immutable so drift is impossible.\n */\nexport const WellKnownChain = {\n polkadotRelay: \"0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3\",\n polkadotAssetHub: \"0x68d56f15f85d3136970ec16946040bc1752654e906147f7e43e9d539d7c3de2f\",\n kusamaRelay: \"0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe\",\n kusamaAssetHub: \"0x48239ef607d7928874027a43a67689209727dfb3d3dc5e5b03a39bdc2eda771a\",\n westendRelay: \"0xe143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e\",\n westendAssetHub: \"0x67f9723393ef76214df0118c34bbbd3dbebc8ed46a10973a8c969d48fe7598c9\",\n rococo: \"0x6408de7737c59c238890533af25896a2c20608d8b380bb01029acb392781063e\",\n} as const;\n\n/** Genesis hash of a well-known chain - the value type of {@link WellKnownChain}. */\nexport type WellKnownChainHash = (typeof WellKnownChain)[keyof typeof WellKnownChain];\n\nif (import.meta.vitest) {\n const { test, expect } = import.meta.vitest;\n\n test(\"WellKnownChain entries are 0x-prefixed 32-byte hex strings\", () => {\n for (const hash of Object.values(WellKnownChain)) {\n expect(hash).toMatch(/^0x[0-9a-f]{64}$/);\n }\n });\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parity/product-sdk-chain-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Multi-chain Polkadot API client with typed access to Asset Hub, Bulletin, and other chains",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"polkadot-api": "^2.1.5",
|
|
22
|
-
"@parity/product-sdk-
|
|
22
|
+
"@parity/product-sdk-descriptors": "0.6.0",
|
|
23
23
|
"@parity/product-sdk-logger": "0.1.1",
|
|
24
|
-
"@parity/product-sdk-
|
|
24
|
+
"@parity/product-sdk-host": "0.8.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"tsup": "^8.5.1",
|
package/src/index.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Pick the entry point that fits how much you want to wire up yourself:
|
|
7
7
|
* `getChainAPI` is the zero-config path with built-in descriptors and RPC endpoints
|
|
8
|
-
* (Paseo
|
|
8
|
+
* (Paseo and Summit are live today; Polkadot and Kusama are reserved but not yet enabled), and
|
|
9
9
|
* `createChainClient` is the bring-your-own-descriptors path for custom or
|
|
10
10
|
* pre-release chains.
|
|
11
11
|
*
|
package/src/presets.ts
CHANGED
|
@@ -14,12 +14,15 @@ import type { kusama_asset_hub as KusamaAssetHubDef } from "@parity/product-sdk-
|
|
|
14
14
|
import type { paseo_asset_hub as PaseoAssetHubDef } from "@parity/product-sdk-descriptors/paseo-asset-hub";
|
|
15
15
|
import type { paseo_bulletin as PaseoBulletinDef } from "@parity/product-sdk-descriptors/paseo-bulletin";
|
|
16
16
|
import type { paseo_individuality as PaseoIndividualityDef } from "@parity/product-sdk-descriptors/paseo-individuality";
|
|
17
|
+
import type { summit_asset_hub as SummitAssetHubDef } from "@parity/product-sdk-descriptors/summit-asset-hub";
|
|
18
|
+
import type { summit_bulletin as SummitBulletinDef } from "@parity/product-sdk-descriptors/summit-bulletin";
|
|
19
|
+
import type { summit_individuality as SummitIndividualityDef } from "@parity/product-sdk-descriptors/summit-individuality";
|
|
17
20
|
|
|
18
21
|
/** Known network environment with built-in descriptors. */
|
|
19
|
-
export type Environment = "polkadot" | "kusama" | "paseo";
|
|
22
|
+
export type Environment = "polkadot" | "kusama" | "paseo" | "summit";
|
|
20
23
|
|
|
21
24
|
/** Environments where all chains (asset hub, bulletin, individuality) are live. */
|
|
22
|
-
const AVAILABLE_ENVIRONMENTS: Set<Environment> = new Set(["paseo"]);
|
|
25
|
+
const AVAILABLE_ENVIRONMENTS: Set<Environment> = new Set(["paseo", "summit"]);
|
|
23
26
|
|
|
24
27
|
/**
|
|
25
28
|
* Lazy-load descriptors for a specific environment.
|
|
@@ -51,6 +54,12 @@ async function loadDescriptors(env: Environment) {
|
|
|
51
54
|
import("@parity/product-sdk-descriptors/paseo-bulletin"),
|
|
52
55
|
import("@parity/product-sdk-descriptors/paseo-individuality"),
|
|
53
56
|
]),
|
|
57
|
+
summit: () =>
|
|
58
|
+
Promise.all([
|
|
59
|
+
import("@parity/product-sdk-descriptors/summit-asset-hub"),
|
|
60
|
+
import("@parity/product-sdk-descriptors/summit-bulletin"),
|
|
61
|
+
import("@parity/product-sdk-descriptors/summit-individuality"),
|
|
62
|
+
]),
|
|
54
63
|
};
|
|
55
64
|
|
|
56
65
|
const [ahMod, bulletinMod, individualityMod] = await loaders[env]();
|
|
@@ -60,13 +69,21 @@ async function loadDescriptors(env: Environment) {
|
|
|
60
69
|
? ahMod.polkadot_asset_hub
|
|
61
70
|
: "kusama_asset_hub" in ahMod
|
|
62
71
|
? ahMod.kusama_asset_hub
|
|
63
|
-
:
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
72
|
+
: "summit_asset_hub" in ahMod
|
|
73
|
+
? (ahMod as { summit_asset_hub: typeof SummitAssetHubDef }).summit_asset_hub
|
|
74
|
+
: (ahMod as { paseo_asset_hub: typeof PaseoAssetHubDef }).paseo_asset_hub;
|
|
75
|
+
|
|
76
|
+
const bulletin =
|
|
77
|
+
"summit_bulletin" in bulletinMod
|
|
78
|
+
? (bulletinMod as { summit_bulletin: typeof SummitBulletinDef }).summit_bulletin
|
|
79
|
+
: (bulletinMod as { paseo_bulletin: typeof PaseoBulletinDef }).paseo_bulletin;
|
|
80
|
+
|
|
81
|
+
const individuality =
|
|
82
|
+
"summit_individuality" in individualityMod
|
|
83
|
+
? (individualityMod as { summit_individuality: typeof SummitIndividualityDef })
|
|
84
|
+
.summit_individuality
|
|
85
|
+
: (individualityMod as { paseo_individuality: typeof PaseoIndividualityDef })
|
|
86
|
+
.paseo_individuality;
|
|
70
87
|
|
|
71
88
|
return { assetHub, bulletin, individuality };
|
|
72
89
|
}
|
|
@@ -90,6 +107,11 @@ type PresetDescriptors = {
|
|
|
90
107
|
bulletin: typeof PaseoBulletinDef;
|
|
91
108
|
individuality: typeof PaseoIndividualityDef;
|
|
92
109
|
};
|
|
110
|
+
summit: {
|
|
111
|
+
assetHub: typeof SummitAssetHubDef;
|
|
112
|
+
bulletin: typeof SummitBulletinDef;
|
|
113
|
+
individuality: typeof SummitIndividualityDef;
|
|
114
|
+
};
|
|
93
115
|
};
|
|
94
116
|
|
|
95
117
|
/** The chain shape returned by {@link getChainAPI} for a given environment. */
|
|
@@ -152,6 +174,9 @@ if (import.meta.vitest) {
|
|
|
152
174
|
paseo_asset_hub: "0xbf0488dbe9daa1de1c08c5f743e26fdc2a4ecd74cf87dd1b4b1eeb99ae4ef19f",
|
|
153
175
|
paseo_bulletin: "0x8cfe6717dc4becfda2e13c488a1e2061ff2dfee96e7d031157f72d36716c0a22",
|
|
154
176
|
paseo_individuality: "0xc5af1826b31493f08b7e2a823842f98575b806a784126f28da9608c68665afa5",
|
|
177
|
+
summit_asset_hub: "0xf388dc6d6cdf6fb77eac3c4a91f31bc0c8642b142f1a757512ab7849f9f70660",
|
|
178
|
+
summit_bulletin: "0x147aae0d60625af72300d4d5ebd5dcb869f7ac4c6c1a326be1cbb14a4a65ae77",
|
|
179
|
+
summit_individuality: "0xbe5238f82c3553bc57ac3be43bef110bd58c49ad0744110814985195ca7d8c4e",
|
|
155
180
|
} as const;
|
|
156
181
|
|
|
157
182
|
beforeEach(() => {
|
|
@@ -186,10 +211,22 @@ if (import.meta.vitest) {
|
|
|
186
211
|
expect(descriptors.individuality.genesis).toBe(GENESIS.paseo_individuality);
|
|
187
212
|
});
|
|
188
213
|
|
|
214
|
+
test("loadDescriptors returns descriptors with genesis hashes for summit", async () => {
|
|
215
|
+
const descriptors = await loadDescriptors("summit");
|
|
216
|
+
expect(descriptors).toBeDefined();
|
|
217
|
+
expect(descriptors.assetHub).toBeDefined();
|
|
218
|
+
expect(descriptors.bulletin).toBeDefined();
|
|
219
|
+
expect(descriptors.individuality).toBeDefined();
|
|
220
|
+
expect(descriptors.assetHub.genesis).toBe(GENESIS.summit_asset_hub);
|
|
221
|
+
expect(descriptors.bulletin.genesis).toBe(GENESIS.summit_bulletin);
|
|
222
|
+
expect(descriptors.individuality.genesis).toBe(GENESIS.summit_individuality);
|
|
223
|
+
});
|
|
224
|
+
|
|
189
225
|
// --- AVAILABLE_ENVIRONMENTS ---
|
|
190
226
|
|
|
191
|
-
test("paseo
|
|
227
|
+
test("paseo and summit are currently available", () => {
|
|
192
228
|
expect(AVAILABLE_ENVIRONMENTS.has("paseo")).toBe(true);
|
|
229
|
+
expect(AVAILABLE_ENVIRONMENTS.has("summit")).toBe(true);
|
|
193
230
|
expect(AVAILABLE_ENVIRONMENTS.has("polkadot")).toBe(false);
|
|
194
231
|
expect(AVAILABLE_ENVIRONMENTS.has("kusama")).toBe(false);
|
|
195
232
|
});
|
package/src/types.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import type { ChainDefinition, PolkadotClient, TypedApi } from "polkadot-api";
|
|
4
4
|
|
|
5
5
|
/** Supported chain environments for the Polkadot ecosystem. */
|
|
6
|
-
export type Environment = "polkadot" | "kusama" | "paseo" | "local" | "westend";
|
|
6
|
+
export type Environment = "polkadot" | "kusama" | "paseo" | "summit" | "local" | "westend";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Configuration for {@link createChainClient}.
|