@dotdm/env 1.0.1 → 1.0.2-dev.1778613797

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,68 +1,125 @@
1
1
  export { DEFAULT_NODE_URL, REGISTRY_ADDRESS } from '@dotdm/utils';
2
2
  import * as polkadot_api from 'polkadot-api';
3
- import { PolkadotClient, TypedApi, ChainDefinition } from 'polkadot-api';
3
+ import { PolkadotClient, TypedApi } from 'polkadot-api';
4
+ import { polkadot_asset_hub } from '@parity/product-sdk-descriptors/polkadot-asset-hub';
4
5
  import { paseo_asset_hub } from '@parity/product-sdk-descriptors/paseo-asset-hub';
5
- import { bulletin } from '@parity/product-sdk-descriptors/bulletin';
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';
6
9
  export { ss58Address } from '@polkadot-labs/hdkd-helpers';
7
10
 
8
11
  interface ChainFaucet {
9
12
  label: string;
10
13
  url: string;
11
14
  }
15
+ type ProductSdkEnvironment = "paseo" | "previewnet";
12
16
  interface ChainPreset {
13
17
  assethubUrl: string;
14
18
  bulletinUrl: string;
15
19
  ipfsGatewayUrl: string;
16
- faucets?: ChainFaucet[];
20
+ registryAddress?: string;
21
+ productSdkEnvironment?: ProductSdkEnvironment;
22
+ faucets?: readonly ChainFaucet[];
17
23
  }
18
- 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://paseo-asset-hub-next-rpc.polkadot.io";
33
+ readonly bulletinUrl: "wss://paseo-bulletin-next-rpc.polkadot.io";
34
+ readonly ipfsGatewayUrl: "https://paseo-bulletin-next-ipfs.polkadot.io";
35
+ readonly registryAddress: "0x5c7b23d386ff622c7f7a4e7a95d5c7a67b10a00d";
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-next-rpc.polkadot.io";
48
+ readonly ipfsGatewayUrl: "https://paseo-bulletin-next-ipfs.polkadot.io";
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
+ };
19
59
  type KnownChainName = keyof typeof KNOWN_CHAINS;
60
+ declare function isKnownChainPreset(name: string): boolean;
20
61
  declare function getChainPreset(name: string): ChainPreset;
21
62
 
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
- };
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>;
30
69
  /**
31
70
  * Shape of a CDM chain client — both Asset Hub and Bulletin connected
32
71
  * under one chain-client-shaped object.
33
72
  *
34
73
  * Uses `@parity/product-sdk-descriptors` for the chain descriptors so the
35
74
  * 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.
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.
40
78
  */
41
- type CdmChainClient = CdmDirectChainClient<{
42
- assetHub: typeof paseo_asset_hub;
43
- bulletin: typeof bulletin;
44
- }>;
79
+ type CdmChainClient = {
80
+ assetHub: CdmDeployAssetHubApi;
81
+ bulletin: CdmBulletinApi;
82
+ raw: {
83
+ assetHub: PolkadotClient;
84
+ bulletin: PolkadotClient;
85
+ };
86
+ descriptors: {
87
+ assetHub: CdmDeployAssetHubDescriptor;
88
+ bulletin: CdmBulletinDescriptor;
89
+ };
90
+ destroy: () => void;
91
+ };
45
92
  /** 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
- }>;
93
+ type CdmAssetHubClient = {
94
+ assetHub: CdmAssetHubApi;
95
+ raw: {
96
+ assetHub: PolkadotClient;
97
+ };
98
+ descriptors: {
99
+ assetHub: CdmAssetHubDescriptor;
100
+ };
101
+ destroy: () => void;
102
+ };
49
103
  interface AssetHubConnection {
50
104
  client: PolkadotClient;
51
- api: TypedApi<typeof paseo_asset_hub>;
105
+ api: CdmAssetHubApi;
52
106
  }
53
107
  interface BulletinConnection {
54
108
  client: PolkadotClient;
55
- api: TypedApi<typeof bulletin>;
109
+ api: CdmBulletinApi;
56
110
  }
57
111
  interface CdmChainEndpoints {
58
112
  assethubUrl: string;
59
113
  bulletinUrl: string;
114
+ chainName?: string;
60
115
  }
61
116
  /**
62
117
  * Connect to both Asset Hub and Bulletin over direct WebSocket RPC.
63
118
  *
64
- * Accepts either a known chain name (`"polkadot"`, `"paseo"`, `"local"`,
65
- * `"preview-net"`) resolved through `getChainPreset`, or explicit URLs.
119
+ * Accepts either a supported deploy chain name (`"paseo"`, `"preview-net"`,
120
+ * `"local"`) resolved through `getChainPreset`, or explicit URLs. Polkadot
121
+ * remains available for Asset-Hub-only install reads, but product-sdk does
122
+ * not publish a Polkadot Bulletin descriptor yet.
66
123
  *
67
124
  * The returned object matches product-sdk's `ChainClient` shape closely enough
68
125
  * for callers to pass either one into CDM APIs. CDM builds this locally because
@@ -74,7 +131,7 @@ declare function createCdmChainClient(arg: string | CdmChainEndpoints): Promise<
74
131
  * Connect to Asset Hub only (no Bulletin). Used by commands that don't
75
132
  * publish metadata — e.g., `install`, `account map`, `deploy-registry`.
76
133
  */
77
- declare function createCdmAssetHubClient(assethubUrl: string): Promise<CdmAssetHubClient>;
134
+ declare function createCdmAssetHubClient(assethubUrl: string, chainName?: string): Promise<CdmAssetHubClient>;
78
135
  interface IpfsGateway {
79
136
  fetch: (cid: string) => Promise<Response>;
80
137
  }
@@ -105,4 +162,4 @@ declare function prepareSignerFromMnemonic(mnemonic: string): polkadot_api.Polka
105
162
  */
106
163
  declare function prepareSignerFromSuri(suri: string): polkadot_api.PolkadotSigner;
107
164
 
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 };
165
+ 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,23 @@
1
1
  // src/known_chains.ts
2
+ import { BULLETIN_RPCS } from "@parity/product-sdk-host";
3
+ import { REGISTRY_ADDRESS } from "@dotdm/utils";
4
+ var PASEO_V2_REGISTRY_ADDRESS = "0x5c7b23d386ff622c7f7a4e7a95d5c7a67b10a00d";
5
+ var PREVIEW_NET_REGISTRY_ADDRESS = "0x5c7b23d386ff622c7f7a4e7a95d5c7a67b10a00d";
6
+ var PASEO_ASSET_HUB_URL = "wss://paseo-asset-hub-next-rpc.polkadot.io";
7
+ var PASEO_IPFS_GATEWAY_URL = "https://paseo-bulletin-next-ipfs.polkadot.io";
2
8
  var KNOWN_CHAINS = {
3
9
  polkadot: {
4
10
  assethubUrl: "wss://polkadot-asset-hub-rpc.polkadot.io",
5
11
  bulletinUrl: "wss://polkadot-bulletin-rpc.polkadot.io",
6
- ipfsGatewayUrl: "https://polkadot-bulletin-rpc.polkadot.io/ipfs"
12
+ ipfsGatewayUrl: "https://polkadot-bulletin-rpc.polkadot.io/ipfs",
13
+ registryAddress: REGISTRY_ADDRESS
7
14
  },
8
15
  paseo: {
9
- assethubUrl: "wss://asset-hub-paseo-rpc.n.dwellir.com",
10
- bulletinUrl: "wss://paseo-bulletin-rpc.polkadot.io",
11
- ipfsGatewayUrl: "https://paseo-ipfs.polkadot.io/ipfs",
16
+ assethubUrl: PASEO_ASSET_HUB_URL,
17
+ bulletinUrl: BULLETIN_RPCS.paseo[0],
18
+ ipfsGatewayUrl: PASEO_IPFS_GATEWAY_URL,
19
+ registryAddress: PASEO_V2_REGISTRY_ADDRESS,
20
+ productSdkEnvironment: "paseo",
12
21
  faucets: [
13
22
  { label: "Asset Hub", url: "https://faucet.polkadot.io/" },
14
23
  {
@@ -19,17 +28,35 @@ var KNOWN_CHAINS = {
19
28
  },
20
29
  "preview-net": {
21
30
  assethubUrl: "wss://previewnet.substrate.dev/asset-hub",
22
- bulletinUrl: "wss://previewnet.substrate.dev/bulletin",
23
- ipfsGatewayUrl: "https://previewnet.substrate.dev/ipfs/"
31
+ // TEMPORARY_PATCH! Preview-net's IPFS gateway does not currently serve Bulletin CIDs,
32
+ // so CDM stores preview-net metadata on Paseo Bulletin for now.
33
+ bulletinUrl: BULLETIN_RPCS.paseo[0],
34
+ ipfsGatewayUrl: PASEO_IPFS_GATEWAY_URL,
35
+ registryAddress: PREVIEW_NET_REGISTRY_ADDRESS,
36
+ productSdkEnvironment: "previewnet"
24
37
  },
25
38
  local: {
26
39
  assethubUrl: "ws://127.0.0.1:10020",
27
40
  bulletinUrl: "ws://127.0.0.1:10030",
28
- ipfsGatewayUrl: "http://127.0.0.1:8283/ipfs"
41
+ ipfsGatewayUrl: "http://127.0.0.1:8283/ipfs",
42
+ registryAddress: REGISTRY_ADDRESS
29
43
  }
30
44
  };
45
+ function normalizeChainName(name) {
46
+ if (name === "previewnet") return "preview-net";
47
+ if (name === "paseo-next-v2" || name === "paseo-v2") return "paseo";
48
+ if (name === "preview-net" || name === "paseo" || name === "polkadot" || name === "local") {
49
+ return name;
50
+ }
51
+ if (name === "custom") return "custom";
52
+ }
53
+ function isKnownChainPreset(name) {
54
+ const normalized = normalizeChainName(name);
55
+ return normalized !== void 0 && normalized !== "custom";
56
+ }
31
57
  function getChainPreset(name) {
32
- const preset = KNOWN_CHAINS[name];
58
+ const normalized = normalizeChainName(name);
59
+ const preset = normalized && normalized !== "custom" ? KNOWN_CHAINS[normalized] : void 0;
33
60
  if (!preset) {
34
61
  const valid = Object.keys(KNOWN_CHAINS).join(", ");
35
62
  throw new Error(`Unknown chain "${name}". Valid names: ${valid}`);
@@ -38,31 +65,74 @@ function getChainPreset(name) {
38
65
  }
39
66
 
40
67
  // src/index.ts
41
- import { DEFAULT_NODE_URL, REGISTRY_ADDRESS } from "@dotdm/utils";
68
+ import { DEFAULT_NODE_URL, REGISTRY_ADDRESS as REGISTRY_ADDRESS2 } from "@dotdm/utils";
42
69
 
43
70
  // src/connection.ts
44
71
  import {
45
72
  createClient
46
73
  } from "polkadot-api";
47
74
  import { getWsProvider } from "polkadot-api/ws";
75
+ import { polkadot_asset_hub } from "@parity/product-sdk-descriptors/polkadot-asset-hub";
48
76
  import { paseo_asset_hub } from "@parity/product-sdk-descriptors/paseo-asset-hub";
49
- import { bulletin } from "@parity/product-sdk-descriptors/bulletin";
77
+ import { previewnet_asset_hub } from "@parity/product-sdk-descriptors/previewnet-asset-hub";
78
+ import { paseo_bulletin } from "@parity/product-sdk-descriptors/paseo-bulletin";
79
+ var DEPLOY_CHAIN_DESCRIPTORS = {
80
+ paseo: { assetHub: paseo_asset_hub, bulletin: paseo_bulletin },
81
+ "preview-net": { assetHub: previewnet_asset_hub, bulletin: paseo_bulletin },
82
+ local: { assetHub: paseo_asset_hub, bulletin: paseo_bulletin }
83
+ };
84
+ var ASSET_HUB_DESCRIPTORS = {
85
+ polkadot: polkadot_asset_hub,
86
+ paseo: paseo_asset_hub,
87
+ "preview-net": previewnet_asset_hub,
88
+ local: paseo_asset_hub
89
+ };
90
+ function resolveExplicitChainName(chainName) {
91
+ const normalized = normalizeChainName(chainName);
92
+ if (!normalized) {
93
+ throw new Error(
94
+ `Unknown chain "${chainName}". Valid names: polkadot, paseo, preview-net, local, custom`
95
+ );
96
+ }
97
+ return normalized;
98
+ }
99
+ function resolveAssetHubDescriptors(chainName) {
100
+ const normalized = chainName ? resolveExplicitChainName(chainName) : void 0;
101
+ return ASSET_HUB_DESCRIPTORS[normalized && normalized !== "custom" ? normalized : "paseo"];
102
+ }
103
+ function resolveDeployDescriptors(chainName) {
104
+ const normalized = chainName ? resolveExplicitChainName(chainName) : void 0;
105
+ const descriptorChain = normalized && normalized !== "custom" ? normalized : "paseo";
106
+ if (descriptorChain === "polkadot") {
107
+ throw new Error(
108
+ 'CDM deploy connections are only available for "paseo", "preview-net", and "local"; product-sdk does not publish a Polkadot Bulletin descriptor yet.'
109
+ );
110
+ }
111
+ return DEPLOY_CHAIN_DESCRIPTORS[descriptorChain];
112
+ }
50
113
  async function createCdmChainClient(arg) {
51
114
  const endpoints = typeof arg === "string" ? {
52
115
  assethubUrl: getChainPreset(arg).assethubUrl,
53
- bulletinUrl: getChainPreset(arg).bulletinUrl
116
+ bulletinUrl: getChainPreset(arg).bulletinUrl,
117
+ chainName: arg
54
118
  } : arg;
119
+ return createDirectChainClient(resolveDeployDescriptors(endpoints.chainName), {
120
+ assetHub: endpoints.assethubUrl,
121
+ bulletin: endpoints.bulletinUrl
122
+ });
123
+ }
124
+ async function createCdmAssetHubClient(assethubUrl, chainName) {
55
125
  return createDirectChainClient(
56
- { assetHub: paseo_asset_hub, bulletin },
57
- { assetHub: endpoints.assethubUrl, bulletin: endpoints.bulletinUrl }
126
+ { assetHub: resolveAssetHubDescriptors(chainName) },
127
+ { assetHub: assethubUrl }
58
128
  );
59
129
  }
60
- async function createCdmAssetHubClient(assethubUrl) {
61
- return createDirectChainClient({ assetHub: paseo_asset_hub }, { assetHub: assethubUrl });
130
+ function joinGatewayUrl(url, cid) {
131
+ return `${url.replace(/\/+$/, "")}/${cid.replace(/^\/+/, "")}`;
62
132
  }
63
133
  function connectIpfsGateway(url) {
64
134
  return {
65
- fetch: (cid) => globalThis.fetch(`${url}/${cid}`, { signal: AbortSignal.timeout(15e3) }).then((r) => {
135
+ fetch: (cid) => globalThis.fetch(joinGatewayUrl(url, cid), { signal: AbortSignal.timeout(15e3) }).then((r) => {
66
136
  if (!r.ok) throw new Error(`IPFS fetch failed: ${r.statusText}`);
67
137
  return r;
68
138
  })
@@ -79,6 +149,7 @@ function createDirectChainClient(chains, rpcs) {
79
149
  return {
80
150
  ...apis,
81
151
  raw,
152
+ descriptors: chains,
82
153
  destroy() {
83
154
  for (const client of Object.values(raw)) {
84
155
  client.destroy();
@@ -118,12 +189,12 @@ function prepareSignerFromSuri(suri) {
118
189
  }
119
190
  export {
120
191
  DEFAULT_NODE_URL,
121
- KNOWN_CHAINS,
122
- REGISTRY_ADDRESS,
192
+ REGISTRY_ADDRESS2 as REGISTRY_ADDRESS,
123
193
  connectIpfsGateway,
124
194
  createCdmAssetHubClient,
125
195
  createCdmChainClient,
126
196
  getChainPreset,
197
+ isKnownChainPreset,
127
198
  prepareSigner,
128
199
  prepareSignerFromMnemonic,
129
200
  prepareSignerFromSuri,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotdm/env",
3
- "version": "1.0.1",
3
+ "version": "1.0.2-dev.1778613797",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -17,7 +17,8 @@
17
17
  "access": "public"
18
18
  },
19
19
  "dependencies": {
20
- "@parity/product-sdk-descriptors": "^0.2.1",
20
+ "@parity/product-sdk-descriptors": "^0.4.0",
21
+ "@parity/product-sdk-host": "^0.2.2",
21
22
  "@polkadot-labs/hdkd": "^0.0.26",
22
23
  "@polkadot-labs/hdkd-helpers": "^0.0.27",
23
24
  "polkadot-api": "^2.1.2",