@dotdm/env 1.0.0 → 1.0.1-dev.1778555844

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 CHANGED
@@ -1,73 +1,130 @@
1
1
  export { DEFAULT_NODE_URL, REGISTRY_ADDRESS } from '@dotdm/utils';
2
2
  import * as polkadot_api from 'polkadot-api';
3
3
  import { PolkadotClient, TypedApi } from 'polkadot-api';
4
- import { ChainClient } from '@polkadot-apps/chain-client';
5
- import { paseo_asset_hub } from '@polkadot-apps/descriptors/paseo-asset-hub';
6
- import { bulletin } from '@polkadot-apps/descriptors/bulletin';
4
+ import { polkadot_asset_hub } from '@parity/product-sdk-descriptors/polkadot-asset-hub';
5
+ import { paseo_asset_hub } from '@parity/product-sdk-descriptors/paseo-asset-hub';
6
+ import { previewnet_asset_hub } from '@parity/product-sdk-descriptors/previewnet-asset-hub';
7
+ import { paseo_bulletin } from '@parity/product-sdk-descriptors/paseo-bulletin';
8
+ import { previewnet_bulletin } from '@parity/product-sdk-descriptors/previewnet-bulletin';
7
9
  export { ss58Address } from '@polkadot-labs/hdkd-helpers';
8
10
 
9
11
  interface ChainFaucet {
10
12
  label: string;
11
13
  url: string;
12
14
  }
15
+ type ProductSdkEnvironment = "paseo" | "previewnet";
13
16
  interface ChainPreset {
14
17
  assethubUrl: string;
15
18
  bulletinUrl: string;
16
19
  ipfsGatewayUrl: string;
17
- faucets?: ChainFaucet[];
20
+ registryAddress?: string;
21
+ productSdkEnvironment?: ProductSdkEnvironment;
22
+ faucets?: readonly ChainFaucet[];
18
23
  }
19
- declare const KNOWN_CHAINS: Record<string, ChainPreset>;
24
+ declare const KNOWN_CHAINS: {
25
+ readonly polkadot: {
26
+ readonly assethubUrl: "wss://polkadot-asset-hub-rpc.polkadot.io";
27
+ readonly bulletinUrl: "wss://polkadot-bulletin-rpc.polkadot.io";
28
+ readonly ipfsGatewayUrl: "https://polkadot-bulletin-rpc.polkadot.io/ipfs";
29
+ readonly registryAddress: "0xae344f7f0f91d3a2176032af2990abcc7606c7d4";
30
+ };
31
+ readonly paseo: {
32
+ readonly assethubUrl: "wss://asset-hub-paseo-rpc.n.dwellir.com";
33
+ readonly bulletinUrl: "wss://paseo-bulletin-rpc.polkadot.io";
34
+ readonly ipfsGatewayUrl: "https://paseo-ipfs.polkadot.io/ipfs";
35
+ readonly registryAddress: "0xae344f7f0f91d3a2176032af2990abcc7606c7d4";
36
+ readonly productSdkEnvironment: "paseo";
37
+ readonly faucets: readonly [{
38
+ readonly label: "Asset Hub";
39
+ readonly url: "https://faucet.polkadot.io/";
40
+ }, {
41
+ readonly label: "Bulletin";
42
+ readonly url: "https://paritytech.github.io/polkadot-bulletin-chain/authorizations?tab=faucet";
43
+ }];
44
+ };
45
+ readonly "preview-net": {
46
+ readonly assethubUrl: "wss://previewnet.substrate.dev/asset-hub";
47
+ readonly bulletinUrl: "wss://paseo-bulletin-rpc.polkadot.io";
48
+ readonly ipfsGatewayUrl: "https://paseo-ipfs.polkadot.io/ipfs";
49
+ readonly registryAddress: "0x5c7b23d386ff622c7f7a4e7a95d5c7a67b10a00d";
50
+ readonly productSdkEnvironment: "previewnet";
51
+ };
52
+ readonly local: {
53
+ readonly assethubUrl: "ws://127.0.0.1:10020";
54
+ readonly bulletinUrl: "ws://127.0.0.1:10030";
55
+ readonly ipfsGatewayUrl: "http://127.0.0.1:8283/ipfs";
56
+ readonly registryAddress: "0xae344f7f0f91d3a2176032af2990abcc7606c7d4";
57
+ };
58
+ };
20
59
  type KnownChainName = keyof typeof KNOWN_CHAINS;
60
+ declare function isKnownChainPreset(name: string): boolean;
21
61
  declare function getChainPreset(name: string): ChainPreset;
22
62
 
63
+ type CdmDeployAssetHubDescriptor = typeof paseo_asset_hub | typeof previewnet_asset_hub;
64
+ type CdmAssetHubDescriptor = CdmDeployAssetHubDescriptor | typeof polkadot_asset_hub;
65
+ type CdmBulletinDescriptor = typeof paseo_bulletin | typeof previewnet_bulletin;
66
+ type CdmDeployAssetHubApi = TypedApi<CdmDeployAssetHubDescriptor>;
67
+ type CdmAssetHubApi = TypedApi<CdmAssetHubDescriptor>;
68
+ type CdmBulletinApi = TypedApi<CdmBulletinDescriptor>;
23
69
  /**
24
70
  * Shape of a CDM chain client — both Asset Hub and Bulletin connected
25
- * under one `ChainClient` managed by `@polkadot-apps/chain-client`.
71
+ * under one chain-client-shaped object.
26
72
  *
27
- * Uses `@polkadot-apps/descriptors` for the chain descriptors so the
73
+ * Uses `@parity/product-sdk-descriptors` for the chain descriptors so the
28
74
  * resulting `TypedApi` types line up natively with `ContractDeployer`,
29
- * `MetadataPublisher`, and the @polkadot-apps batch/bulletin helpers
30
- * (no casts required). We pin AssetHub to the Paseo flavor — it's the
31
- * primary test target, and the pallet surface matches Polkadot/Kusama
32
- * AssetHub at the queries/txs we use.
75
+ * `MetadataPublisher`, and the product-sdk batch/bulletin helpers. TEMPORARY_PATCH! Preview-net
76
+ * currently uses its own Asset Hub descriptor and Paseo's Bulletin descriptor
77
+ * because CDM stores preview-net metadata on Paseo Bulletin.
33
78
  */
34
- type CdmChainClient = ChainClient<{
35
- assetHub: typeof paseo_asset_hub;
36
- bulletin: typeof bulletin;
37
- }>;
79
+ type CdmChainClient = {
80
+ assetHub: CdmDeployAssetHubApi;
81
+ bulletin: CdmBulletinApi;
82
+ raw: {
83
+ assetHub: PolkadotClient;
84
+ bulletin: PolkadotClient;
85
+ };
86
+ destroy: () => void;
87
+ };
38
88
  /** Asset-Hub-only variant for callers that don't need Bulletin (e.g., `install`). */
39
- type CdmAssetHubClient = ChainClient<{
40
- assetHub: typeof paseo_asset_hub;
41
- }>;
89
+ type CdmAssetHubClient = {
90
+ assetHub: CdmAssetHubApi;
91
+ raw: {
92
+ assetHub: PolkadotClient;
93
+ };
94
+ destroy: () => void;
95
+ };
42
96
  interface AssetHubConnection {
43
97
  client: PolkadotClient;
44
- api: TypedApi<typeof paseo_asset_hub>;
98
+ api: CdmAssetHubApi;
45
99
  }
46
100
  interface BulletinConnection {
47
101
  client: PolkadotClient;
48
- api: TypedApi<typeof bulletin>;
102
+ api: CdmBulletinApi;
49
103
  }
50
104
  interface CdmChainEndpoints {
51
105
  assethubUrl: string;
52
106
  bulletinUrl: string;
107
+ chainName?: string;
53
108
  }
54
109
  /**
55
- * Connect to both Asset Hub and Bulletin using `@polkadot-apps/chain-client`.
110
+ * Connect to both Asset Hub and Bulletin over direct WebSocket RPC.
56
111
  *
57
- * Accepts either a known chain name (`"polkadot"`, `"paseo"`, `"local"`,
58
- * `"preview-net"`) resolved through `getChainPreset`, or explicit URLs.
112
+ * Accepts either a supported deploy chain name (`"paseo"`, `"preview-net"`,
113
+ * `"local"`) resolved through `getChainPreset`, or explicit URLs. Polkadot
114
+ * remains available for Asset-Hub-only install reads, but product-sdk does
115
+ * not publish a Polkadot Bulletin descriptor yet.
59
116
  *
60
- * The returned `ChainClient` manages both connections — one `.destroy()`
61
- * call tears everything down. `chain-client` caches by genesis-hash
62
- * fingerprint, so repeated calls with the same descriptor set share a
63
- * single instance.
117
+ * The returned object matches product-sdk's `ChainClient` shape closely enough
118
+ * for callers to pass either one into CDM APIs. CDM builds this locally because
119
+ * product-sdk's published chain-client is host-provider-only and ignores RPC
120
+ * URLs, while the CLI must keep working as a standalone process.
64
121
  */
65
122
  declare function createCdmChainClient(arg: string | CdmChainEndpoints): Promise<CdmChainClient>;
66
123
  /**
67
124
  * Connect to Asset Hub only (no Bulletin). Used by commands that don't
68
125
  * publish metadata — e.g., `install`, `account map`, `deploy-registry`.
69
126
  */
70
- declare function createCdmAssetHubClient(assethubUrl: string): Promise<CdmAssetHubClient>;
127
+ declare function createCdmAssetHubClient(assethubUrl: string, chainName?: string): Promise<CdmAssetHubClient>;
71
128
  interface IpfsGateway {
72
129
  fetch: (cid: string) => Promise<Response>;
73
130
  }
@@ -76,11 +133,9 @@ interface IpfsGateway {
76
133
  * by CID. Unrelated to chain-client; kept here alongside the chain-connection
77
134
  * factory for convenience.
78
135
  *
79
- * `@polkadot-apps/bulletin` offers gateway helpers (`getGateway`, `fetchBytes`,
80
- * `fetchJson`), but those key off a fixed `Environment` enum
81
- * (polkadot/kusama/paseo) and don't yet cover CDM's custom networks
82
- * (local, preview-net). Keep this thin wrapper until CDM can map its
83
- * `KNOWN_CHAINS` onto that enum.
136
+ * Product SDK's Bulletin read helpers go through the host preimage
137
+ * subscription and do not cover CDM's custom gateway URLs (local,
138
+ * preview-net). Keep this thin wrapper for install flows.
84
139
  */
85
140
  declare function connectIpfsGateway(url: string): IpfsGateway;
86
141
 
@@ -100,4 +155,4 @@ declare function prepareSignerFromMnemonic(mnemonic: string): polkadot_api.Polka
100
155
  */
101
156
  declare function prepareSignerFromSuri(suri: string): polkadot_api.PolkadotSigner;
102
157
 
103
- 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 };
158
+ export { type AssetHubConnection, type BulletinConnection, type CdmAssetHubApi, type CdmAssetHubClient, type CdmBulletinApi, type CdmChainClient, type CdmChainEndpoints, type CdmDeployAssetHubApi, type ChainFaucet, type ChainPreset, type IpfsGateway, type KnownChainName, type ProductSdkEnvironment, connectIpfsGateway, createCdmAssetHubClient, createCdmChainClient, getChainPreset, isKnownChainPreset, prepareSigner, prepareSignerFromMnemonic, prepareSignerFromSuri };
package/dist/index.js CHANGED
@@ -1,14 +1,20 @@
1
1
  // src/known_chains.ts
2
+ import { BULLETIN_RPCS } from "@parity/product-sdk-host";
3
+ import { REGISTRY_ADDRESS } from "@dotdm/utils";
4
+ var PREVIEW_NET_REGISTRY_ADDRESS = "0x5c7b23d386ff622c7f7a4e7a95d5c7a67b10a00d";
2
5
  var KNOWN_CHAINS = {
3
6
  polkadot: {
4
7
  assethubUrl: "wss://polkadot-asset-hub-rpc.polkadot.io",
5
8
  bulletinUrl: "wss://polkadot-bulletin-rpc.polkadot.io",
6
- ipfsGatewayUrl: "https://polkadot-bulletin-rpc.polkadot.io/ipfs"
9
+ ipfsGatewayUrl: "https://polkadot-bulletin-rpc.polkadot.io/ipfs",
10
+ registryAddress: REGISTRY_ADDRESS
7
11
  },
8
12
  paseo: {
9
13
  assethubUrl: "wss://asset-hub-paseo-rpc.n.dwellir.com",
10
- bulletinUrl: "wss://paseo-bulletin-rpc.polkadot.io",
14
+ bulletinUrl: BULLETIN_RPCS.paseo[0],
11
15
  ipfsGatewayUrl: "https://paseo-ipfs.polkadot.io/ipfs",
16
+ registryAddress: REGISTRY_ADDRESS,
17
+ productSdkEnvironment: "paseo",
12
18
  faucets: [
13
19
  { label: "Asset Hub", url: "https://faucet.polkadot.io/" },
14
20
  {
@@ -19,17 +25,34 @@ var KNOWN_CHAINS = {
19
25
  },
20
26
  "preview-net": {
21
27
  assethubUrl: "wss://previewnet.substrate.dev/asset-hub",
22
- bulletinUrl: "wss://previewnet.substrate.dev/bulletin",
23
- ipfsGatewayUrl: "https://previewnet.substrate.dev/ipfs/"
28
+ // TEMPORARY_PATCH! Preview-net's IPFS gateway does not currently serve Bulletin CIDs,
29
+ // so CDM stores preview-net metadata on Paseo Bulletin for now.
30
+ bulletinUrl: BULLETIN_RPCS.paseo[0],
31
+ ipfsGatewayUrl: "https://paseo-ipfs.polkadot.io/ipfs",
32
+ registryAddress: PREVIEW_NET_REGISTRY_ADDRESS,
33
+ productSdkEnvironment: "previewnet"
24
34
  },
25
35
  local: {
26
36
  assethubUrl: "ws://127.0.0.1:10020",
27
37
  bulletinUrl: "ws://127.0.0.1:10030",
28
- ipfsGatewayUrl: "http://127.0.0.1:8283/ipfs"
38
+ ipfsGatewayUrl: "http://127.0.0.1:8283/ipfs",
39
+ registryAddress: REGISTRY_ADDRESS
29
40
  }
30
41
  };
42
+ function normalizeChainName(name) {
43
+ if (name === "previewnet") return "preview-net";
44
+ if (name === "preview-net" || name === "paseo" || name === "polkadot" || name === "local") {
45
+ return name;
46
+ }
47
+ if (name === "custom") return "custom";
48
+ }
49
+ function isKnownChainPreset(name) {
50
+ const normalized = normalizeChainName(name);
51
+ return normalized !== void 0 && normalized !== "custom";
52
+ }
31
53
  function getChainPreset(name) {
32
- const preset = KNOWN_CHAINS[name];
54
+ const normalized = normalizeChainName(name);
55
+ const preset = normalized && normalized !== "custom" ? KNOWN_CHAINS[normalized] : void 0;
33
56
  if (!preset) {
34
57
  const valid = Object.keys(KNOWN_CHAINS).join(", ");
35
58
  throw new Error(`Unknown chain "${name}". Valid names: ${valid}`);
@@ -38,39 +61,97 @@ function getChainPreset(name) {
38
61
  }
39
62
 
40
63
  // src/index.ts
41
- import { DEFAULT_NODE_URL, REGISTRY_ADDRESS } from "@dotdm/utils";
64
+ import { DEFAULT_NODE_URL, REGISTRY_ADDRESS as REGISTRY_ADDRESS2 } from "@dotdm/utils";
42
65
 
43
66
  // src/connection.ts
44
- import { createChainClient } from "@polkadot-apps/chain-client";
45
- import { paseo_asset_hub } from "@polkadot-apps/descriptors/paseo-asset-hub";
46
- import { bulletin } from "@polkadot-apps/descriptors/bulletin";
67
+ import {
68
+ createClient
69
+ } from "polkadot-api";
70
+ import { getWsProvider } from "polkadot-api/ws";
71
+ import { polkadot_asset_hub } from "@parity/product-sdk-descriptors/polkadot-asset-hub";
72
+ import { paseo_asset_hub } from "@parity/product-sdk-descriptors/paseo-asset-hub";
73
+ import { previewnet_asset_hub } from "@parity/product-sdk-descriptors/previewnet-asset-hub";
74
+ import { paseo_bulletin } from "@parity/product-sdk-descriptors/paseo-bulletin";
75
+ var DEPLOY_CHAIN_DESCRIPTORS = {
76
+ paseo: { assetHub: paseo_asset_hub, bulletin: paseo_bulletin },
77
+ "preview-net": { assetHub: previewnet_asset_hub, bulletin: paseo_bulletin },
78
+ local: { assetHub: paseo_asset_hub, bulletin: paseo_bulletin }
79
+ };
80
+ var ASSET_HUB_DESCRIPTORS = {
81
+ polkadot: polkadot_asset_hub,
82
+ paseo: paseo_asset_hub,
83
+ "preview-net": previewnet_asset_hub,
84
+ local: paseo_asset_hub
85
+ };
86
+ function resolveExplicitChainName(chainName) {
87
+ const normalized = normalizeChainName(chainName);
88
+ if (!normalized) {
89
+ throw new Error(
90
+ `Unknown chain "${chainName}". Valid names: polkadot, paseo, preview-net, local, custom`
91
+ );
92
+ }
93
+ return normalized;
94
+ }
95
+ function resolveAssetHubDescriptors(chainName) {
96
+ const normalized = chainName ? resolveExplicitChainName(chainName) : void 0;
97
+ return ASSET_HUB_DESCRIPTORS[normalized && normalized !== "custom" ? normalized : "paseo"];
98
+ }
99
+ function resolveDeployDescriptors(chainName) {
100
+ const normalized = chainName ? resolveExplicitChainName(chainName) : void 0;
101
+ const descriptorChain = normalized && normalized !== "custom" ? normalized : "paseo";
102
+ if (descriptorChain === "polkadot") {
103
+ throw new Error(
104
+ 'CDM deploy connections are only available for "paseo", "preview-net", and "local"; product-sdk does not publish a Polkadot Bulletin descriptor yet.'
105
+ );
106
+ }
107
+ return DEPLOY_CHAIN_DESCRIPTORS[descriptorChain];
108
+ }
47
109
  async function createCdmChainClient(arg) {
48
110
  const endpoints = typeof arg === "string" ? {
49
111
  assethubUrl: getChainPreset(arg).assethubUrl,
50
- bulletinUrl: getChainPreset(arg).bulletinUrl
112
+ bulletinUrl: getChainPreset(arg).bulletinUrl,
113
+ chainName: arg
51
114
  } : arg;
52
- return createChainClient({
53
- chains: { assetHub: paseo_asset_hub, bulletin },
54
- rpcs: {
55
- assetHub: [endpoints.assethubUrl],
56
- bulletin: [endpoints.bulletinUrl]
57
- }
115
+ return createDirectChainClient(resolveDeployDescriptors(endpoints.chainName), {
116
+ assetHub: endpoints.assethubUrl,
117
+ bulletin: endpoints.bulletinUrl
58
118
  });
59
119
  }
60
- async function createCdmAssetHubClient(assethubUrl) {
61
- return createChainClient({
62
- chains: { assetHub: paseo_asset_hub },
63
- rpcs: { assetHub: [assethubUrl] }
64
- });
120
+ async function createCdmAssetHubClient(assethubUrl, chainName) {
121
+ return createDirectChainClient(
122
+ { assetHub: resolveAssetHubDescriptors(chainName) },
123
+ { assetHub: assethubUrl }
124
+ );
125
+ }
126
+ function joinGatewayUrl(url, cid) {
127
+ return `${url.replace(/\/+$/, "")}/${cid.replace(/^\/+/, "")}`;
65
128
  }
66
129
  function connectIpfsGateway(url) {
67
130
  return {
68
- fetch: (cid) => globalThis.fetch(`${url}/${cid}`, { signal: AbortSignal.timeout(15e3) }).then((r) => {
131
+ fetch: (cid) => globalThis.fetch(joinGatewayUrl(url, cid), { signal: AbortSignal.timeout(15e3) }).then((r) => {
69
132
  if (!r.ok) throw new Error(`IPFS fetch failed: ${r.statusText}`);
70
133
  return r;
71
134
  })
72
135
  };
73
136
  }
137
+ function createDirectChainClient(chains, rpcs) {
138
+ const apis = {};
139
+ const raw = {};
140
+ for (const name of Object.keys(chains)) {
141
+ const client = createClient(getWsProvider(rpcs[name]));
142
+ raw[name] = client;
143
+ apis[name] = client.getTypedApi(chains[name]);
144
+ }
145
+ return {
146
+ ...apis,
147
+ raw,
148
+ destroy() {
149
+ for (const client of Object.values(raw)) {
150
+ client.destroy();
151
+ }
152
+ }
153
+ };
154
+ }
74
155
 
75
156
  // src/signer.ts
76
157
  import { getPolkadotSigner } from "polkadot-api/signer";
@@ -103,12 +184,12 @@ function prepareSignerFromSuri(suri) {
103
184
  }
104
185
  export {
105
186
  DEFAULT_NODE_URL,
106
- KNOWN_CHAINS,
107
- REGISTRY_ADDRESS,
187
+ REGISTRY_ADDRESS2 as REGISTRY_ADDRESS,
108
188
  connectIpfsGateway,
109
189
  createCdmAssetHubClient,
110
190
  createCdmChainClient,
111
191
  getChainPreset,
192
+ isKnownChainPreset,
112
193
  prepareSigner,
113
194
  prepareSignerFromMnemonic,
114
195
  prepareSignerFromSuri,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotdm/env",
3
- "version": "1.0.0",
3
+ "version": "1.0.1-dev.1778555844",
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
- "@polkadot-apps/chain-client": "^2.0.4",
21
- "@polkadot-apps/descriptors": "^1.0.1",
20
+ "@parity/product-sdk-descriptors": "^0.3.0",
21
+ "@parity/product-sdk-host": "^0.2.1",
22
22
  "@polkadot-labs/hdkd": "^0.0.26",
23
23
  "@polkadot-labs/hdkd-helpers": "^0.0.27",
24
- "polkadot-api": "^1.23.3",
24
+ "polkadot-api": "^2.1.2",
25
25
  "smoldot": "^2.0.40",
26
26
  "@dotdm/utils": "0.3.1"
27
27
  },