@dotdm/env 2.0.0 → 2.0.1-dev.1779942376

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.
@@ -0,0 +1,12 @@
1
+ // src/registry.ts
2
+ var PASEO_V2_REGISTRY_ADDRESS = "0xf62c2ece29cd8df2e10040ecfa5a894a5c5d9cb0";
3
+ function getRegistryAddress(name = "paseo") {
4
+ if (name === "paseo" || name === "paseo-next-v2" || name === "paseo-v2") {
5
+ return PASEO_V2_REGISTRY_ADDRESS;
6
+ }
7
+ return PASEO_V2_REGISTRY_ADDRESS;
8
+ }
9
+
10
+ export {
11
+ getRegistryAddress
12
+ };
package/dist/index.d.ts CHANGED
@@ -5,9 +5,7 @@ import * as polkadot_api from 'polkadot-api';
5
5
  import { PolkadotClient, TypedApi } from 'polkadot-api';
6
6
  import { polkadot_asset_hub } from '@parity/product-sdk-descriptors/polkadot-asset-hub';
7
7
  import { paseo_asset_hub } from '@parity/product-sdk-descriptors/paseo-asset-hub';
8
- import { previewnet_asset_hub } from '@parity/product-sdk-descriptors/previewnet-asset-hub';
9
8
  import { paseo_bulletin } from '@parity/product-sdk-descriptors/paseo-bulletin';
10
- import { previewnet_bulletin } from '@parity/product-sdk-descriptors/previewnet-bulletin';
11
9
  export { ss58Address } from '@polkadot-labs/hdkd-helpers';
12
10
 
13
11
  interface ChainFaucet {
@@ -44,13 +42,6 @@ declare const KNOWN_CHAINS: {
44
42
  readonly url: "https://paritytech.github.io/polkadot-bulletin-chain/authorizations?tab=faucet";
45
43
  }];
46
44
  };
47
- readonly "preview-net": {
48
- readonly assethubUrl: "wss://previewnet.substrate.dev/asset-hub";
49
- readonly bulletinUrl: "wss://previewnet.substrate.dev/bulletin";
50
- readonly ipfsGatewayUrl: "https://previewnet.substrate.dev/ipfs";
51
- readonly registryAddress: string;
52
- readonly productSdkEnvironment: "previewnet";
53
- };
54
45
  readonly local: {
55
46
  readonly assethubUrl: "ws://127.0.0.1:10020";
56
47
  readonly bulletinUrl: "ws://127.0.0.1:10030";
@@ -62,9 +53,15 @@ type KnownChainName = keyof typeof KNOWN_CHAINS;
62
53
  declare function isKnownChainPreset(name: string): boolean;
63
54
  declare function getChainPreset(name: string): ChainPreset;
64
55
 
65
- type CdmDeployAssetHubDescriptor = typeof paseo_asset_hub | typeof previewnet_asset_hub;
56
+ interface QueryOriginTarget {
57
+ chainName?: string;
58
+ assethubUrl?: string;
59
+ }
60
+ declare function resolveQueryOrigin(target?: string | QueryOriginTarget): string;
61
+
62
+ type CdmDeployAssetHubDescriptor = typeof paseo_asset_hub;
66
63
  type CdmAssetHubDescriptor = CdmDeployAssetHubDescriptor | typeof polkadot_asset_hub;
67
- type CdmBulletinDescriptor = typeof paseo_bulletin | typeof previewnet_bulletin;
64
+ type CdmBulletinDescriptor = typeof paseo_bulletin;
68
65
  type CdmDeployAssetHubApi = TypedApi<CdmDeployAssetHubDescriptor>;
69
66
  type CdmAssetHubApi = TypedApi<CdmAssetHubDescriptor>;
70
67
  type CdmBulletinApi = TypedApi<CdmBulletinDescriptor>;
@@ -116,10 +113,10 @@ interface CdmChainEndpoints {
116
113
  /**
117
114
  * Connect to both Asset Hub and Bulletin over direct WebSocket RPC.
118
115
  *
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.
116
+ * Accepts either a supported deploy chain name (`"paseo"` or `"local"`)
117
+ * resolved through `getChainPreset`, or explicit URLs. Polkadot remains
118
+ * available for Asset-Hub-only install reads, but product-sdk does not publish
119
+ * a Polkadot Bulletin descriptor yet.
123
120
  *
124
121
  * The returned object matches product-sdk's `ChainClient` shape closely enough
125
122
  * for callers to pass either one into CDM APIs. CDM builds this locally because
@@ -141,8 +138,8 @@ interface IpfsGateway {
141
138
  * factory for convenience.
142
139
  *
143
140
  * Product SDK's Bulletin read helpers go through the host preimage
144
- * subscription and do not cover CDM's custom gateway URLs (local,
145
- * preview-net). Keep this thin wrapper for install flows.
141
+ * subscription and do not cover CDM's custom gateway URLs (local/custom).
142
+ * Keep this thin wrapper for install flows.
146
143
  */
147
144
  declare function connectIpfsGateway(url: string): IpfsGateway;
148
145
 
@@ -162,4 +159,4 @@ declare function prepareSignerFromMnemonic(mnemonic: string): polkadot_api.Polka
162
159
  */
163
160
  declare function prepareSignerFromSuri(suri: string): polkadot_api.PolkadotSigner;
164
161
 
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, ProductSdkEnvironment, connectIpfsGateway, createCdmAssetHubClient, createCdmChainClient, getChainPreset, isKnownChainPreset, prepareSigner, prepareSignerFromMnemonic, prepareSignerFromSuri };
162
+ 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, ProductSdkEnvironment, connectIpfsGateway, createCdmAssetHubClient, createCdmChainClient, getChainPreset, isKnownChainPreset, prepareSigner, prepareSignerFromMnemonic, prepareSignerFromSuri, resolveQueryOrigin };
package/dist/index.js CHANGED
@@ -1,13 +1,11 @@
1
1
  import {
2
2
  getRegistryAddress
3
- } from "./chunk-3LTEJCST.js";
3
+ } from "./chunk-HTQLXSDE.js";
4
4
 
5
5
  // src/known_chains.ts
6
6
  import { BULLETIN_RPCS } from "@parity/product-sdk-host";
7
7
  var PASEO_ASSET_HUB_URL = "wss://paseo-asset-hub-next-rpc.polkadot.io";
8
- var PREVIEW_NET_ASSET_HUB_URL = "wss://previewnet.substrate.dev/asset-hub";
9
8
  var PASEO_IPFS_GATEWAY_URL = "https://paseo-bulletin-next-ipfs.polkadot.io/ipfs";
10
- var PREVIEW_NET_IPFS_GATEWAY_URL = "https://previewnet.substrate.dev/ipfs";
11
9
  var KNOWN_CHAINS = {
12
10
  polkadot: {
13
11
  assethubUrl: "wss://polkadot-asset-hub-rpc.polkadot.io",
@@ -29,13 +27,6 @@ var KNOWN_CHAINS = {
29
27
  }
30
28
  ]
31
29
  },
32
- "preview-net": {
33
- assethubUrl: PREVIEW_NET_ASSET_HUB_URL,
34
- bulletinUrl: BULLETIN_RPCS.previewnet[0],
35
- ipfsGatewayUrl: PREVIEW_NET_IPFS_GATEWAY_URL,
36
- registryAddress: getRegistryAddress("preview-net"),
37
- productSdkEnvironment: "previewnet"
38
- },
39
30
  local: {
40
31
  assethubUrl: "ws://127.0.0.1:10020",
41
32
  bulletinUrl: "ws://127.0.0.1:10030",
@@ -44,9 +35,8 @@ var KNOWN_CHAINS = {
44
35
  }
45
36
  };
46
37
  function normalizeChainName(name) {
47
- if (name === "previewnet") return "preview-net";
48
38
  if (name === "paseo-next-v2" || name === "paseo-v2") return "paseo";
49
- if (name === "preview-net" || name === "paseo" || name === "polkadot" || name === "local") {
39
+ if (name === "paseo" || name === "polkadot" || name === "local") {
50
40
  return name;
51
41
  }
52
42
  if (name === "custom") return "custom";
@@ -64,6 +54,81 @@ function getChainPreset(name) {
64
54
  }
65
55
  return preset;
66
56
  }
57
+ function findKnownChainByAssetHubUrl(url) {
58
+ const normalizedUrl = url.replace(/\/+$/, "");
59
+ return Object.entries(KNOWN_CHAINS).find(
60
+ ([, preset]) => preset.assethubUrl.replace(/\/+$/, "") === normalizedUrl
61
+ )?.[0];
62
+ }
63
+
64
+ // src/query_origin.ts
65
+ import { ALICE_SS58 } from "@dotdm/utils";
66
+ import { getAccount } from "@dotdm/utils/accounts";
67
+ function resolveQueryAccountName(target) {
68
+ const chainName = typeof target === "string" ? target : target?.chainName;
69
+ const normalized = chainName ? normalizeChainName(chainName) : void 0;
70
+ if (normalized && normalized !== "custom") return normalized;
71
+ const assethubUrl = typeof target === "string" ? void 0 : target?.assethubUrl;
72
+ return assethubUrl ? findKnownChainByAssetHubUrl(assethubUrl) : void 0;
73
+ }
74
+ function resolveQueryOrigin(target) {
75
+ const accountName = resolveQueryAccountName(target);
76
+ if (accountName) {
77
+ const account = getAccount(accountName);
78
+ if (account) return account.address;
79
+ }
80
+ return ALICE_SS58;
81
+ }
82
+ if (import.meta.vitest) {
83
+ const { afterEach, describe, expect, test } = import.meta.vitest;
84
+ const { mkdtempSync, rmSync } = await import("fs");
85
+ const { tmpdir } = await import("os");
86
+ const { join } = await import("path");
87
+ const { saveAccount } = await import("@dotdm/utils/accounts");
88
+ describe("resolveQueryOrigin", () => {
89
+ const originalCdmRoot = process.env.CDM_ROOT;
90
+ afterEach(() => {
91
+ if (originalCdmRoot === void 0) {
92
+ delete process.env.CDM_ROOT;
93
+ } else {
94
+ process.env.CDM_ROOT = originalCdmRoot;
95
+ }
96
+ });
97
+ test("uses the normalized chain account when present", () => {
98
+ const root = mkdtempSync(join(tmpdir(), "cdm-query-origin-"));
99
+ process.env.CDM_ROOT = root;
100
+ try {
101
+ saveAccount("paseo", { mnemonic: "test", address: "paseo-address" });
102
+ expect(resolveQueryOrigin("paseo-v2")).toBe("paseo-address");
103
+ } finally {
104
+ rmSync(root, { recursive: true, force: true });
105
+ }
106
+ });
107
+ test("infers a known chain account from the Asset Hub URL", () => {
108
+ const root = mkdtempSync(join(tmpdir(), "cdm-query-origin-"));
109
+ process.env.CDM_ROOT = root;
110
+ try {
111
+ saveAccount("paseo", { mnemonic: "test", address: "paseo-address" });
112
+ expect(
113
+ resolveQueryOrigin({
114
+ assethubUrl: "wss://paseo-asset-hub-next-rpc.polkadot.io"
115
+ })
116
+ ).toBe("paseo-address");
117
+ } finally {
118
+ rmSync(root, { recursive: true, force: true });
119
+ }
120
+ });
121
+ test("falls back to Alice when no chain account is available", () => {
122
+ const root = mkdtempSync(join(tmpdir(), "cdm-query-origin-"));
123
+ process.env.CDM_ROOT = root;
124
+ try {
125
+ expect(resolveQueryOrigin("paseo")).toBe(ALICE_SS58);
126
+ } finally {
127
+ rmSync(root, { recursive: true, force: true });
128
+ }
129
+ });
130
+ });
131
+ }
67
132
 
68
133
  // src/index.ts
69
134
  import { DEFAULT_NODE_URL } from "@dotdm/utils";
@@ -75,25 +140,21 @@ import {
75
140
  import { getWsProvider } from "polkadot-api/ws";
76
141
  import { polkadot_asset_hub } from "@parity/product-sdk-descriptors/polkadot-asset-hub";
77
142
  import { paseo_asset_hub } from "@parity/product-sdk-descriptors/paseo-asset-hub";
78
- import { previewnet_asset_hub } from "@parity/product-sdk-descriptors/previewnet-asset-hub";
79
143
  import { paseo_bulletin } from "@parity/product-sdk-descriptors/paseo-bulletin";
80
- import { previewnet_bulletin } from "@parity/product-sdk-descriptors/previewnet-bulletin";
81
144
  var DEPLOY_CHAIN_DESCRIPTORS = {
82
145
  paseo: { assetHub: paseo_asset_hub, bulletin: paseo_bulletin },
83
- "preview-net": { assetHub: previewnet_asset_hub, bulletin: previewnet_bulletin },
84
146
  local: { assetHub: paseo_asset_hub, bulletin: paseo_bulletin }
85
147
  };
86
148
  var ASSET_HUB_DESCRIPTORS = {
87
149
  polkadot: polkadot_asset_hub,
88
150
  paseo: paseo_asset_hub,
89
- "preview-net": previewnet_asset_hub,
90
151
  local: paseo_asset_hub
91
152
  };
92
153
  function resolveExplicitChainName(chainName) {
93
154
  const normalized = normalizeChainName(chainName);
94
155
  if (!normalized) {
95
156
  throw new Error(
96
- `Unknown chain "${chainName}". Valid names: polkadot, paseo, preview-net, local, custom`
157
+ `Unknown chain "${chainName}". Valid names: polkadot, paseo, local, custom`
97
158
  );
98
159
  }
99
160
  return normalized;
@@ -107,7 +168,7 @@ function resolveDeployDescriptors(chainName) {
107
168
  const descriptorChain = normalized && normalized !== "custom" ? normalized : "paseo";
108
169
  if (descriptorChain === "polkadot") {
109
170
  throw new Error(
110
- 'CDM deploy connections are only available for "paseo", "preview-net", and "local"; product-sdk does not publish a Polkadot Bulletin descriptor yet.'
171
+ 'CDM deploy connections are only available for "paseo" and "local"; product-sdk does not publish a Polkadot Bulletin descriptor yet.'
111
172
  );
112
173
  }
113
174
  return DEPLOY_CHAIN_DESCRIPTORS[descriptorChain];
@@ -161,11 +222,10 @@ function createDirectChainClient(chains, rpcs) {
161
222
  }
162
223
  if (import.meta.vitest) {
163
224
  const { test, expect } = import.meta.vitest;
164
- test("preview-net deploy connections use previewnet descriptors", () => {
165
- const descriptors = resolveDeployDescriptors("preview-net");
166
- expect(descriptors.assetHub).toBe(previewnet_asset_hub);
167
- expect(descriptors.bulletin).toBe(previewnet_bulletin);
168
- expect(descriptors.bulletin).not.toBe(paseo_bulletin);
225
+ test("local deploy connections use paseo descriptors", () => {
226
+ const descriptors = resolveDeployDescriptors("local");
227
+ expect(descriptors.assetHub).toBe(paseo_asset_hub);
228
+ expect(descriptors.bulletin).toBe(paseo_bulletin);
169
229
  });
170
230
  }
171
231
 
@@ -209,5 +269,6 @@ export {
209
269
  prepareSigner,
210
270
  prepareSignerFromMnemonic,
211
271
  prepareSignerFromSuri,
272
+ resolveQueryOrigin,
212
273
  ss58Address
213
274
  };
@@ -1,4 +1,4 @@
1
- type ProductSdkEnvironment = "paseo" | "previewnet";
1
+ type ProductSdkEnvironment = "paseo";
2
2
  declare function getRegistryAddress(name?: string): string;
3
3
 
4
4
  export { type ProductSdkEnvironment, getRegistryAddress };
package/dist/registry.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getRegistryAddress
3
- } from "./chunk-3LTEJCST.js";
3
+ } from "./chunk-HTQLXSDE.js";
4
4
  export {
5
5
  getRegistryAddress
6
6
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotdm/env",
3
- "version": "2.0.0",
3
+ "version": "2.0.1-dev.1779942376",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -21,8 +21,8 @@
21
21
  "access": "public"
22
22
  },
23
23
  "dependencies": {
24
- "@parity/product-sdk-descriptors": "^0.4.0",
25
- "@parity/product-sdk-host": "^0.3.0",
24
+ "@parity/product-sdk-descriptors": "^0.5.0",
25
+ "@parity/product-sdk-host": "^0.5.0",
26
26
  "@polkadot-labs/hdkd": "^0.0.26",
27
27
  "@polkadot-labs/hdkd-helpers": "^0.0.27",
28
28
  "polkadot-api": "^2.1.2",
@@ -1,16 +0,0 @@
1
- // src/registry.ts
2
- var PASEO_V2_REGISTRY_ADDRESS = "0xa7ae171c78f06c248a9b2556c793aa1df5c9173a";
3
- var PREVIEW_NET_REGISTRY_ADDRESS = "0xa7ae171c78f06c248a9b2556c793aa1df5c9173a";
4
- function getRegistryAddress(name = "paseo") {
5
- if (name === "paseo" || name === "paseo-next-v2" || name === "paseo-v2") {
6
- return PASEO_V2_REGISTRY_ADDRESS;
7
- }
8
- if (name === "preview-net" || name === "previewnet") {
9
- return PREVIEW_NET_REGISTRY_ADDRESS;
10
- }
11
- return PASEO_V2_REGISTRY_ADDRESS;
12
- }
13
-
14
- export {
15
- getRegistryAddress
16
- };