@dotdm/env 0.3.2 → 1.0.0-dev.1778274929
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 +59 -22
- package/dist/index.js +37 -35
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export { DEFAULT_NODE_URL, REGISTRY_ADDRESS } from '@dotdm/utils';
|
|
2
2
|
import * as polkadot_api from 'polkadot-api';
|
|
3
|
-
import { PolkadotClient, TypedApi } from 'polkadot-api';
|
|
4
|
-
import {
|
|
3
|
+
import { PolkadotClient, TypedApi, ChainDefinition } from 'polkadot-api';
|
|
4
|
+
import { paseo_asset_hub } from '@parity/product-sdk-descriptors/paseo-asset-hub';
|
|
5
|
+
import { bulletin } from '@parity/product-sdk-descriptors/bulletin';
|
|
5
6
|
export { ss58Address } from '@polkadot-labs/hdkd-helpers';
|
|
6
7
|
|
|
7
8
|
interface ChainFaucet {
|
|
@@ -18,38 +19,74 @@ declare const KNOWN_CHAINS: Record<string, ChainPreset>;
|
|
|
18
19
|
type KnownChainName = keyof typeof KNOWN_CHAINS;
|
|
19
20
|
declare function getChainPreset(name: string): ChainPreset;
|
|
20
21
|
|
|
22
|
+
type CdmDirectChainClient<TChains extends Record<string, ChainDefinition>> = {
|
|
23
|
+
[K in keyof TChains]: TypedApi<TChains[K]>;
|
|
24
|
+
} & {
|
|
25
|
+
raw: {
|
|
26
|
+
[K in keyof TChains]: PolkadotClient;
|
|
27
|
+
};
|
|
28
|
+
destroy: () => void;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Shape of a CDM chain client — both Asset Hub and Bulletin connected
|
|
32
|
+
* under one chain-client-shaped object.
|
|
33
|
+
*
|
|
34
|
+
* Uses `@parity/product-sdk-descriptors` for the chain descriptors so the
|
|
35
|
+
* resulting `TypedApi` types line up natively with `ContractDeployer`,
|
|
36
|
+
* `MetadataPublisher`, and the product-sdk batch/bulletin helpers
|
|
37
|
+
* (no casts required). We pin AssetHub to the Paseo flavor — it's the
|
|
38
|
+
* primary test target, and the pallet surface matches Polkadot/Kusama
|
|
39
|
+
* AssetHub at the queries/txs we use.
|
|
40
|
+
*/
|
|
41
|
+
type CdmChainClient = CdmDirectChainClient<{
|
|
42
|
+
assetHub: typeof paseo_asset_hub;
|
|
43
|
+
bulletin: typeof bulletin;
|
|
44
|
+
}>;
|
|
45
|
+
/** Asset-Hub-only variant for callers that don't need Bulletin (e.g., `install`). */
|
|
46
|
+
type CdmAssetHubClient = CdmDirectChainClient<{
|
|
47
|
+
assetHub: typeof paseo_asset_hub;
|
|
48
|
+
}>;
|
|
21
49
|
interface AssetHubConnection {
|
|
22
50
|
client: PolkadotClient;
|
|
23
|
-
api: TypedApi<
|
|
51
|
+
api: TypedApi<typeof paseo_asset_hub>;
|
|
24
52
|
}
|
|
25
|
-
/**
|
|
26
|
-
* Detect connection type from URL.
|
|
27
|
-
* - ws:// or wss:// -> WebSocket
|
|
28
|
-
* - file path -> smoldot with chainspec
|
|
29
|
-
*/
|
|
30
|
-
declare function detectConnectionType(url: string): "websocket" | "smoldot";
|
|
31
|
-
/**
|
|
32
|
-
* Connect to a chain via WebSocket.
|
|
33
|
-
*/
|
|
34
|
-
declare function connectAssetHubWebSocket(url: string): AssetHubConnection;
|
|
35
53
|
interface BulletinConnection {
|
|
36
54
|
client: PolkadotClient;
|
|
37
|
-
api: TypedApi<
|
|
55
|
+
api: TypedApi<typeof bulletin>;
|
|
56
|
+
}
|
|
57
|
+
interface CdmChainEndpoints {
|
|
58
|
+
assethubUrl: string;
|
|
59
|
+
bulletinUrl: string;
|
|
38
60
|
}
|
|
39
61
|
/**
|
|
40
|
-
* Connect to
|
|
62
|
+
* Connect to both Asset Hub and Bulletin over direct WebSocket RPC.
|
|
63
|
+
*
|
|
64
|
+
* Accepts either a known chain name (`"polkadot"`, `"paseo"`, `"local"`,
|
|
65
|
+
* `"preview-net"`) resolved through `getChainPreset`, or explicit URLs.
|
|
66
|
+
*
|
|
67
|
+
* The returned object matches product-sdk's `ChainClient` shape closely enough
|
|
68
|
+
* for callers to pass either one into CDM APIs. CDM builds this locally because
|
|
69
|
+
* product-sdk's published chain-client is host-provider-only and ignores RPC
|
|
70
|
+
* URLs, while the CLI must keep working as a standalone process.
|
|
41
71
|
*/
|
|
42
|
-
declare function
|
|
72
|
+
declare function createCdmChainClient(arg: string | CdmChainEndpoints): Promise<CdmChainClient>;
|
|
43
73
|
/**
|
|
44
|
-
* Connect to
|
|
45
|
-
*
|
|
46
|
-
* @param parachainChainspec - Path to the parachain chainspec JSON file
|
|
47
|
-
* @param relayChainspec - Path to the relay chain chainspec JSON file
|
|
74
|
+
* Connect to Asset Hub only (no Bulletin). Used by commands that don't
|
|
75
|
+
* publish metadata — e.g., `install`, `account map`, `deploy-registry`.
|
|
48
76
|
*/
|
|
49
|
-
declare function
|
|
77
|
+
declare function createCdmAssetHubClient(assethubUrl: string): Promise<CdmAssetHubClient>;
|
|
50
78
|
interface IpfsGateway {
|
|
51
79
|
fetch: (cid: string) => Promise<Response>;
|
|
52
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Minimal IPFS gateway HTTP client used by `install` to fetch metadata JSON
|
|
83
|
+
* by CID. Unrelated to chain-client; kept here alongside the chain-connection
|
|
84
|
+
* factory for convenience.
|
|
85
|
+
*
|
|
86
|
+
* Product SDK's Bulletin read helpers go through the host preimage
|
|
87
|
+
* subscription and do not cover CDM's custom gateway URLs (local,
|
|
88
|
+
* preview-net). Keep this thin wrapper for install flows.
|
|
89
|
+
*/
|
|
53
90
|
declare function connectIpfsGateway(url: string): IpfsGateway;
|
|
54
91
|
|
|
55
92
|
/**
|
|
@@ -68,4 +105,4 @@ declare function prepareSignerFromMnemonic(mnemonic: string): polkadot_api.Polka
|
|
|
68
105
|
*/
|
|
69
106
|
declare function prepareSignerFromSuri(suri: string): polkadot_api.PolkadotSigner;
|
|
70
107
|
|
|
71
|
-
export { type AssetHubConnection, type BulletinConnection, type ChainFaucet, type ChainPreset, type IpfsGateway, KNOWN_CHAINS, type KnownChainName,
|
|
108
|
+
export { type AssetHubConnection, type BulletinConnection, type CdmAssetHubClient, type CdmChainClient, type CdmChainEndpoints, type ChainFaucet, type ChainPreset, type IpfsGateway, KNOWN_CHAINS, type KnownChainName, connectIpfsGateway, createCdmAssetHubClient, createCdmChainClient, getChainPreset, prepareSigner, prepareSignerFromMnemonic, prepareSignerFromSuri };
|
package/dist/index.js
CHANGED
|
@@ -41,38 +41,24 @@ function getChainPreset(name) {
|
|
|
41
41
|
import { DEFAULT_NODE_URL, REGISTRY_ADDRESS } from "@dotdm/utils";
|
|
42
42
|
|
|
43
43
|
// src/connection.ts
|
|
44
|
-
import {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
import { getWsProvider } from "polkadot-api/ws
|
|
48
|
-
import {
|
|
49
|
-
import {
|
|
50
|
-
function
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
function connectBulletinWebSocket(url) {
|
|
61
|
-
const client = createClient(withPolkadotSdkCompat(getWsProvider(url)));
|
|
62
|
-
return { client, api: client.getTypedApi(bulletin) };
|
|
44
|
+
import {
|
|
45
|
+
createClient
|
|
46
|
+
} from "polkadot-api";
|
|
47
|
+
import { getWsProvider } from "polkadot-api/ws";
|
|
48
|
+
import { paseo_asset_hub } from "@parity/product-sdk-descriptors/paseo-asset-hub";
|
|
49
|
+
import { bulletin } from "@parity/product-sdk-descriptors/bulletin";
|
|
50
|
+
async function createCdmChainClient(arg) {
|
|
51
|
+
const endpoints = typeof arg === "string" ? {
|
|
52
|
+
assethubUrl: getChainPreset(arg).assethubUrl,
|
|
53
|
+
bulletinUrl: getChainPreset(arg).bulletinUrl
|
|
54
|
+
} : arg;
|
|
55
|
+
return createDirectChainClient(
|
|
56
|
+
{ assetHub: paseo_asset_hub, bulletin },
|
|
57
|
+
{ assetHub: endpoints.assethubUrl, bulletin: endpoints.bulletinUrl }
|
|
58
|
+
);
|
|
63
59
|
}
|
|
64
|
-
async function
|
|
65
|
-
|
|
66
|
-
const { readFileSync } = await import("fs");
|
|
67
|
-
const relaySpec = readFileSync(relayChainspec, "utf-8");
|
|
68
|
-
const parachainSpec = readFileSync(parachainChainspec, "utf-8");
|
|
69
|
-
const relayChain = await smoldot.addChain({ chainSpec: relaySpec });
|
|
70
|
-
const parachain = await smoldot.addChain({
|
|
71
|
-
chainSpec: parachainSpec,
|
|
72
|
-
potentialRelayChains: [relayChain]
|
|
73
|
-
});
|
|
74
|
-
const client = createClient(getSmProvider(parachain));
|
|
75
|
-
return { client, api: client.getTypedApi(assetHub) };
|
|
60
|
+
async function createCdmAssetHubClient(assethubUrl) {
|
|
61
|
+
return createDirectChainClient({ assetHub: paseo_asset_hub }, { assetHub: assethubUrl });
|
|
76
62
|
}
|
|
77
63
|
function connectIpfsGateway(url) {
|
|
78
64
|
return {
|
|
@@ -82,6 +68,24 @@ function connectIpfsGateway(url) {
|
|
|
82
68
|
})
|
|
83
69
|
};
|
|
84
70
|
}
|
|
71
|
+
function createDirectChainClient(chains, rpcs) {
|
|
72
|
+
const apis = {};
|
|
73
|
+
const raw = {};
|
|
74
|
+
for (const name of Object.keys(chains)) {
|
|
75
|
+
const client = createClient(getWsProvider(rpcs[name]));
|
|
76
|
+
raw[name] = client;
|
|
77
|
+
apis[name] = client.getTypedApi(chains[name]);
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
...apis,
|
|
81
|
+
raw,
|
|
82
|
+
destroy() {
|
|
83
|
+
for (const client of Object.values(raw)) {
|
|
84
|
+
client.destroy();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
85
89
|
|
|
86
90
|
// src/signer.ts
|
|
87
91
|
import { getPolkadotSigner } from "polkadot-api/signer";
|
|
@@ -116,11 +120,9 @@ export {
|
|
|
116
120
|
DEFAULT_NODE_URL,
|
|
117
121
|
KNOWN_CHAINS,
|
|
118
122
|
REGISTRY_ADDRESS,
|
|
119
|
-
connectAssetHubWebSocket,
|
|
120
|
-
connectBulletinWebSocket,
|
|
121
123
|
connectIpfsGateway,
|
|
122
|
-
|
|
123
|
-
|
|
124
|
+
createCdmAssetHubClient,
|
|
125
|
+
createCdmChainClient,
|
|
124
126
|
getChainPreset,
|
|
125
127
|
prepareSigner,
|
|
126
128
|
prepareSignerFromMnemonic,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotdm/env",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-dev.1778274929",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -17,11 +17,11 @@
|
|
|
17
17
|
"access": "public"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
+
"@parity/product-sdk-descriptors": "^0.2.1",
|
|
20
21
|
"@polkadot-labs/hdkd": "^0.0.26",
|
|
21
22
|
"@polkadot-labs/hdkd-helpers": "^0.0.27",
|
|
22
|
-
"polkadot-api": "^1.
|
|
23
|
+
"polkadot-api": "^2.1.2",
|
|
23
24
|
"smoldot": "^2.0.40",
|
|
24
|
-
"@dotdm/descriptors": "0.1.9",
|
|
25
25
|
"@dotdm/utils": "0.3.1"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|