@le-space/core 0.2.0 → 0.3.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/index.d.ts CHANGED
@@ -629,4 +629,32 @@ declare function verifyUcGoPeerReachability(args: {
629
629
  checks: Record<string, Record<string, unknown>>;
630
630
  }>;
631
631
 
632
- export { type CrnCapacitySpec, DEFAULT_ALEPH_API_HOST, DEFAULT_ALEPH_CHANNEL, DEFAULT_COUNTRY_LOOKUP_BASE_URL, DEFAULT_CRN_LIST_URL, DEFAULT_DNS_RESOLVE_URL, DEFAULT_INSTANCE_PORT_FORWARDS, DEFAULT_IPFS_GATEWAY_BASE_URL, DEFAULT_SCHEDULER_ALLOCATION_URL, DEFAULT_TWO_N_SIX_HASH_URL, type FetchLike, type FetchLikeResponse, type HttpProbeResult, ITEM_HASH_RE, type JsonFetchLike, type JsonFetchLikeResponse, type PaymentQuote, type RetentionRecord, SSH_PUBLIC_KEY_PATTERN, SUCCESSFUL_DEPLOYMENTS_AGGREGATE_KEY, type TcpProbeResult, type TierSpec, broadcastAlephMessage, buildPaymentQuote, cleanupFailedDeployment, configureOrbitdbRelaySetup, configureUcGoPeer, createDeploymentIntent, createInstanceContent, createPortForwardAggregateContent, createReleaseMetadata, createUnsignedAggregateMessage, createUnsignedForgetMessage, createUnsignedInstanceMessage, deployInstance, describeRejectedDeployment, describeRuntimeAvailability, enrichCrnsWithGeo, ensureInstancePortForwards, extractProxyUrl, extractReferenceHashes, fetch2n6WebAccessUrl, fetchAggregateKey, fetchCrnExecutionMap, fetchCrns, fetchMessageEnvelope, fetchPortForwardAggregate, fetchSchedulerAllocation, fetchUcGoPeerMetadata, fetchVmRuntime, filterDeployableCrns, findCrnByHash, forgetAlephMessages, inspectDeploymentResult, inspectMessageResult, isInvalidMessageFormatResponse, isRetryableBroadcastFailure, isValidSshPublicKey, listGeocodedCrns, mergePortFlagMaps, mergeRequiredPortForwards, messageTypeFromEnvelope, normalizeBroadcastStatus, normalizeExecution, normalizeExistingPortForwardEntry, normalizeMessageStatus, normalizeProxyUrl, normalizeSshPublicKey, notifyCrnAllocation, notifyCrnAllocationWithRetry, portForwardLabel, postBroadcastPayload, probeRootfsGateway, publishAggregateKey, quoteRequiredBudgetUnits, rankCandidateCrns, requestedPortFlags, requiredInstancePortForwards, resolveRootfsReference, retainSuccessfulDeployments, selectPreferredCrn, selectedTier, signAlephMessage, signaturePayload, tierSpec, validateRootfsManifest, verifyRootfsExists, verifyUcGoPeerReachability, waitForDeploymentResult, waitForSetupEndpoint, waitForVmRuntime };
632
+ interface RelayBootstrapPublicationResult {
633
+ status: "published" | "skipped";
634
+ reason?: string;
635
+ itemHash?: string;
636
+ message?: AlephBroadcastMessage;
637
+ response?: AlephBroadcastResponse;
638
+ httpStatus?: number;
639
+ publishedMultiaddrs?: string[];
640
+ publishedBrowserMultiaddrs?: string[];
641
+ }
642
+ declare function publishRelayBootstrapRegistration(args: {
643
+ sender: string;
644
+ signer: MessageSigner;
645
+ hasher: MessageHasher;
646
+ fetch: JsonFetchLike;
647
+ peerId: string;
648
+ multiaddrs: string[];
649
+ browserMultiaddrs?: string[];
650
+ apiHost?: string;
651
+ channel?: string;
652
+ ref?: string;
653
+ postType?: string;
654
+ profile?: string;
655
+ version?: string;
656
+ sync?: boolean;
657
+ now?: number;
658
+ }): Promise<RelayBootstrapPublicationResult>;
659
+
660
+ export { type CrnCapacitySpec, DEFAULT_ALEPH_API_HOST, DEFAULT_ALEPH_CHANNEL, DEFAULT_COUNTRY_LOOKUP_BASE_URL, DEFAULT_CRN_LIST_URL, DEFAULT_DNS_RESOLVE_URL, DEFAULT_INSTANCE_PORT_FORWARDS, DEFAULT_IPFS_GATEWAY_BASE_URL, DEFAULT_SCHEDULER_ALLOCATION_URL, DEFAULT_TWO_N_SIX_HASH_URL, type FetchLike, type FetchLikeResponse, type HttpProbeResult, ITEM_HASH_RE, type JsonFetchLike, type JsonFetchLikeResponse, type PaymentQuote, type RelayBootstrapPublicationResult, type RetentionRecord, SSH_PUBLIC_KEY_PATTERN, SUCCESSFUL_DEPLOYMENTS_AGGREGATE_KEY, type TcpProbeResult, type TierSpec, broadcastAlephMessage, buildPaymentQuote, cleanupFailedDeployment, configureOrbitdbRelaySetup, configureUcGoPeer, createDeploymentIntent, createInstanceContent, createPortForwardAggregateContent, createReleaseMetadata, createUnsignedAggregateMessage, createUnsignedForgetMessage, createUnsignedInstanceMessage, deployInstance, describeRejectedDeployment, describeRuntimeAvailability, enrichCrnsWithGeo, ensureInstancePortForwards, extractProxyUrl, extractReferenceHashes, fetch2n6WebAccessUrl, fetchAggregateKey, fetchCrnExecutionMap, fetchCrns, fetchMessageEnvelope, fetchPortForwardAggregate, fetchSchedulerAllocation, fetchUcGoPeerMetadata, fetchVmRuntime, filterDeployableCrns, findCrnByHash, forgetAlephMessages, inspectDeploymentResult, inspectMessageResult, isInvalidMessageFormatResponse, isRetryableBroadcastFailure, isValidSshPublicKey, listGeocodedCrns, mergePortFlagMaps, mergeRequiredPortForwards, messageTypeFromEnvelope, normalizeBroadcastStatus, normalizeExecution, normalizeExistingPortForwardEntry, normalizeMessageStatus, normalizeProxyUrl, normalizeSshPublicKey, notifyCrnAllocation, notifyCrnAllocationWithRetry, portForwardLabel, postBroadcastPayload, probeRootfsGateway, publishAggregateKey, publishRelayBootstrapRegistration, quoteRequiredBudgetUnits, rankCandidateCrns, requestedPortFlags, requiredInstancePortForwards, resolveRootfsReference, retainSuccessfulDeployments, selectPreferredCrn, selectedTier, signAlephMessage, signaturePayload, tierSpec, validateRootfsManifest, verifyRootfsExists, verifyUcGoPeerReachability, waitForDeploymentResult, waitForSetupEndpoint, waitForVmRuntime };
package/index.js CHANGED
@@ -2022,6 +2022,175 @@ async function verifyUcGoPeerReachability(args) {
2022
2022
  checks
2023
2023
  };
2024
2024
  }
2025
+
2026
+ // ../aleph-bootstrap/src/index.ts
2027
+ var DEFAULT_ALEPH_API_HOST2 = "https://api2.aleph.im";
2028
+ var DEFAULT_ALEPH_BOOTSTRAP_CHANNEL = "simple-todo";
2029
+ var DEFAULT_ALEPH_BOOTSTRAP_REF = "simple-todo-bootstrap";
2030
+ var DEFAULT_ALEPH_BOOTSTRAP_POST_TYPE = "relay-bootstrap";
2031
+ var DEFAULT_BOOTSTRAP_MAX_AGE_MS = 7 * 24 * 60 * 60 * 1e3;
2032
+ function normalizeHost(host) {
2033
+ return host.trim().toLowerCase();
2034
+ }
2035
+ function splitMultiaddr(addr) {
2036
+ return addr.split("/").filter(Boolean);
2037
+ }
2038
+ function isPrivateIpv4(ip) {
2039
+ const parts = ip.split(".").map((part) => Number(part));
2040
+ if (parts.length !== 4 || parts.some((part) => !Number.isInteger(part) || part < 0 || part > 255)) {
2041
+ return false;
2042
+ }
2043
+ if (parts[0] === 10) return true;
2044
+ if (parts[0] === 127) return true;
2045
+ if (parts[0] === 0) return true;
2046
+ if (parts[0] === 169 && parts[1] === 254) return true;
2047
+ if (parts[0] === 172 && parts[1] >= 16 && parts[1] <= 31) return true;
2048
+ if (parts[0] === 192 && parts[1] === 168) return true;
2049
+ if (parts[0] === 100 && parts[1] >= 64 && parts[1] <= 127) return true;
2050
+ return false;
2051
+ }
2052
+ function isPrivateIpv6(ip) {
2053
+ const normalized = ip.trim().toLowerCase();
2054
+ return normalized === "::1" || normalized.startsWith("fc") || normalized.startsWith("fd") || normalized.startsWith("fe8") || normalized.startsWith("fe9") || normalized.startsWith("fea") || normalized.startsWith("feb");
2055
+ }
2056
+ function isLocalHostname(host) {
2057
+ const normalized = normalizeHost(host);
2058
+ return normalized === "localhost" || normalized.endsWith(".localhost") || normalized.endsWith(".local");
2059
+ }
2060
+ function hasPeerId(addr) {
2061
+ return splitMultiaddr(addr).includes("p2p");
2062
+ }
2063
+ function isBrowserDialableMultiaddr(addr) {
2064
+ const normalized = addr.toLowerCase();
2065
+ return normalized.includes("/ws") || normalized.includes("/wss") || normalized.includes("/webtransport") || normalized.includes("/webrtc-direct");
2066
+ }
2067
+ function dedupeMultiaddrs(addrs) {
2068
+ const seen = /* @__PURE__ */ new Set();
2069
+ const result = [];
2070
+ for (const value of addrs) {
2071
+ const trimmed = value.trim();
2072
+ if (!trimmed || seen.has(trimmed)) continue;
2073
+ seen.add(trimmed);
2074
+ result.push(trimmed);
2075
+ }
2076
+ return result;
2077
+ }
2078
+ function isPublicMultiaddr(addr) {
2079
+ const parts = splitMultiaddr(addr);
2080
+ for (let index = 0; index < parts.length; index += 1) {
2081
+ const protocol = parts[index];
2082
+ const value = parts[index + 1];
2083
+ if (protocol === "ip4" && value) {
2084
+ return !isPrivateIpv4(value);
2085
+ }
2086
+ if (protocol === "ip6" && value) {
2087
+ return !isPrivateIpv6(value);
2088
+ }
2089
+ if ((protocol === "dns4" || protocol === "dns6" || protocol === "dnsaddr") && value) {
2090
+ return !isLocalHostname(value);
2091
+ }
2092
+ }
2093
+ return false;
2094
+ }
2095
+ function filterPublicMultiaddrs(addrs, options = {}) {
2096
+ return dedupeMultiaddrs(addrs).filter((addr) => {
2097
+ if (!isPublicMultiaddr(addr)) return false;
2098
+ if (options.requirePeerId !== false && !hasPeerId(addr)) return false;
2099
+ if (options.browserDialableOnly && !isBrowserDialableMultiaddr(addr)) {
2100
+ return false;
2101
+ }
2102
+ return true;
2103
+ });
2104
+ }
2105
+ function buildRelayBootstrapPostContent(args) {
2106
+ const now = args.now ?? Date.now() / 1e3;
2107
+ const updatedAt = args.now ?? Date.now();
2108
+ return {
2109
+ type: args.postType ?? DEFAULT_ALEPH_BOOTSTRAP_POST_TYPE,
2110
+ address: args.sender,
2111
+ ...args.ref ? { ref: args.ref } : {},
2112
+ content: {
2113
+ peerId: args.peerId,
2114
+ multiaddrs: filterPublicMultiaddrs(args.multiaddrs),
2115
+ browserMultiaddrs: args.browserMultiaddrs ? filterPublicMultiaddrs(args.browserMultiaddrs, {
2116
+ browserDialableOnly: true
2117
+ }) : void 0,
2118
+ profile: args.profile,
2119
+ version: args.version,
2120
+ updatedAt: Math.round(updatedAt)
2121
+ },
2122
+ time: now
2123
+ };
2124
+ }
2125
+ async function createRelayBootstrapPost(args) {
2126
+ const nowMillis = args.now ?? Date.now();
2127
+ const nowSeconds = nowMillis / 1e3;
2128
+ const itemContent = buildRelayBootstrapPostContent({
2129
+ sender: args.sender,
2130
+ peerId: args.peerId,
2131
+ multiaddrs: args.multiaddrs,
2132
+ browserMultiaddrs: args.browserMultiaddrs,
2133
+ ref: args.ref ?? DEFAULT_ALEPH_BOOTSTRAP_REF,
2134
+ postType: args.postType ?? DEFAULT_ALEPH_BOOTSTRAP_POST_TYPE,
2135
+ profile: args.profile,
2136
+ version: args.version,
2137
+ now: nowMillis
2138
+ });
2139
+ itemContent.time = nowSeconds;
2140
+ const serialized = JSON.stringify(itemContent);
2141
+ const itemHash = await args.hasher(serialized);
2142
+ return {
2143
+ channel: args.channel ?? DEFAULT_ALEPH_BOOTSTRAP_CHANNEL,
2144
+ sender: args.sender,
2145
+ chain: "ETH",
2146
+ type: "POST",
2147
+ time: nowSeconds,
2148
+ item_type: "inline",
2149
+ item_content: serialized,
2150
+ item_hash: itemHash
2151
+ };
2152
+ }
2153
+
2154
+ // src/bootstrap-registration.ts
2155
+ async function publishRelayBootstrapRegistration(args) {
2156
+ const unsigned = await createRelayBootstrapPost({
2157
+ sender: args.sender,
2158
+ peerId: args.peerId,
2159
+ multiaddrs: args.multiaddrs,
2160
+ browserMultiaddrs: args.browserMultiaddrs,
2161
+ channel: args.channel,
2162
+ ref: args.ref,
2163
+ postType: args.postType,
2164
+ profile: args.profile,
2165
+ version: args.version,
2166
+ now: args.now,
2167
+ hasher: args.hasher
2168
+ });
2169
+ const content = JSON.parse(unsigned.item_content);
2170
+ if ((content.content?.multiaddrs?.length ?? 0) === 0) {
2171
+ return {
2172
+ status: "skipped",
2173
+ reason: "No public relay multiaddrs remained after filtering.",
2174
+ publishedMultiaddrs: [],
2175
+ publishedBrowserMultiaddrs: content.content?.browserMultiaddrs ?? []
2176
+ };
2177
+ }
2178
+ const message = await signAlephMessage(unsigned, args.signer);
2179
+ const { response, httpStatus } = await broadcastAlephMessage(message, {
2180
+ apiHost: args.apiHost ?? DEFAULT_ALEPH_API_HOST2,
2181
+ sync: args.sync ?? true,
2182
+ fetch: args.fetch
2183
+ });
2184
+ return {
2185
+ status: "published",
2186
+ itemHash: unsigned.item_hash,
2187
+ message,
2188
+ response,
2189
+ httpStatus,
2190
+ publishedMultiaddrs: content.content?.multiaddrs ?? [],
2191
+ publishedBrowserMultiaddrs: content.content?.browserMultiaddrs ?? []
2192
+ };
2193
+ }
2025
2194
  export {
2026
2195
  DEFAULT_ALEPH_API_HOST,
2027
2196
  DEFAULT_ALEPH_CHANNEL,
@@ -2087,6 +2256,7 @@ export {
2087
2256
  postBroadcastPayload,
2088
2257
  probeRootfsGateway,
2089
2258
  publishAggregateKey,
2259
+ publishRelayBootstrapRegistration,
2090
2260
  quoteRequiredBudgetUnits,
2091
2261
  rankCandidateCrns,
2092
2262
  requestedPortFlags,
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@le-space/core",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Reusable Aleph deployment, runtime, and guest lifecycle logic.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -16,6 +16,7 @@
16
16
  "access": "public"
17
17
  },
18
18
  "dependencies": {
19
- "@le-space/shared-types": "0.2.0"
19
+ "@le-space/aleph-bootstrap": "0.3.0",
20
+ "@le-space/shared-types": "0.3.0"
20
21
  }
21
22
  }