@le-space/core 0.1.52 → 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 +60 -3
- package/index.js +406 -31
- package/le-space-core-0.3.0.tgz +0 -0
- package/package.json +3 -2
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _le_space_shared_types from '@le-space/shared-types';
|
|
2
|
-
import { RootfsResolution, RootfsManifest, RootfsManifestState, CrnRecord, RootfsRequiredPortForward, PortForwardAggregate, PortForwardFlags, PortForwardAggregateEntry, MessageReference, InstanceExecution, MessageStatus, DeploymentInspectionResult, MessageInspectionResult, AlephBroadcastMessage, AlephBroadcastResponse, MessageSigner, MessageHasher, AlephAggregateContent, AlephInstanceContent, DeploymentIntentEnvelope, DeploymentResult, InstanceAllocation, InstanceRuntimeDetails, InstanceWebAccess, RuntimeDiagnostics, PortMapping } from '@le-space/shared-types';
|
|
2
|
+
import { RootfsResolution, RootfsManifest, RootfsManifestState, CrnRecord, RootfsRequiredPortForward, PortForwardAggregate, PortForwardFlags, PortForwardAggregateEntry, MessageReference, InstanceExecution, MessageStatus, DeploymentInspectionResult, MessageInspectionResult, AlephBroadcastMessage, AlephBroadcastResponse, MessageSigner, MessageHasher, DeploymentProgressListener, AlephAggregateContent, AlephInstanceContent, DeploymentIntentEnvelope, DeploymentResult, InstanceAllocation, InstanceRuntimeDetails, InstanceWebAccess, RuntimeDiagnostics, PortMapping } from '@le-space/shared-types';
|
|
3
3
|
|
|
4
4
|
declare const DEFAULT_ALEPH_CHANNEL = "TEST";
|
|
5
5
|
|
|
@@ -243,6 +243,7 @@ declare function forgetAlephMessages(args: {
|
|
|
243
243
|
apiHost?: string;
|
|
244
244
|
sync?: boolean;
|
|
245
245
|
now?: number;
|
|
246
|
+
onProgress?: DeploymentProgressListener;
|
|
246
247
|
}): Promise<{
|
|
247
248
|
sender: string;
|
|
248
249
|
itemHash: string;
|
|
@@ -479,6 +480,7 @@ declare function deployInstance(args: {
|
|
|
479
480
|
channel?: string;
|
|
480
481
|
sync?: boolean;
|
|
481
482
|
now?: number;
|
|
483
|
+
onProgress?: DeploymentProgressListener;
|
|
482
484
|
}): Promise<DeploymentResult>;
|
|
483
485
|
|
|
484
486
|
declare const DEFAULT_SCHEDULER_ALLOCATION_URL = "https://scheduler.api.aleph.cloud/api/v0/allocation";
|
|
@@ -547,7 +549,20 @@ declare function notifyCrnAllocation(args: {
|
|
|
547
549
|
itemHash: string;
|
|
548
550
|
fetch: FetchLike;
|
|
549
551
|
}): Promise<{
|
|
550
|
-
status:
|
|
552
|
+
status: "confirmed" | "unconfirmed" | "skipped";
|
|
553
|
+
reason?: string;
|
|
554
|
+
payload?: unknown;
|
|
555
|
+
}>;
|
|
556
|
+
declare function notifyCrnAllocationWithRetry(args: {
|
|
557
|
+
crnUrl: string | null | undefined;
|
|
558
|
+
itemHash: string;
|
|
559
|
+
fetch: FetchLike;
|
|
560
|
+
attempts?: number;
|
|
561
|
+
delayMs?: number;
|
|
562
|
+
sleep?: (ms: number) => Promise<void>;
|
|
563
|
+
onProgress?: DeploymentProgressListener;
|
|
564
|
+
}): Promise<{
|
|
565
|
+
status: "confirmed" | "unconfirmed" | "skipped";
|
|
551
566
|
reason?: string;
|
|
552
567
|
payload?: unknown;
|
|
553
568
|
}>;
|
|
@@ -574,6 +589,20 @@ declare function configureUcGoPeer(args: {
|
|
|
574
589
|
fetch: FetchLike;
|
|
575
590
|
timeoutMs?: number;
|
|
576
591
|
}): Promise<unknown>;
|
|
592
|
+
declare function configureOrbitdbRelaySetup(args: {
|
|
593
|
+
hostIpv4: string;
|
|
594
|
+
setupPort: number;
|
|
595
|
+
publicIpv6?: string | null;
|
|
596
|
+
tcpPort: number;
|
|
597
|
+
wsPort: number;
|
|
598
|
+
metricsPort?: number | null;
|
|
599
|
+
metricsHttpsPort?: number | null;
|
|
600
|
+
webrtcPort?: number | null;
|
|
601
|
+
quicPort?: number | null;
|
|
602
|
+
proxyUrl?: string | null;
|
|
603
|
+
fetch: FetchLike;
|
|
604
|
+
timeoutMs?: number;
|
|
605
|
+
}): Promise<unknown>;
|
|
577
606
|
declare function fetchUcGoPeerMetadata(args: {
|
|
578
607
|
hostIpv4: string;
|
|
579
608
|
setupPort: number;
|
|
@@ -600,4 +629,32 @@ declare function verifyUcGoPeerReachability(args: {
|
|
|
600
629
|
checks: Record<string, Record<string, unknown>>;
|
|
601
630
|
}>;
|
|
602
631
|
|
|
603
|
-
|
|
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
|
@@ -778,6 +778,16 @@ async function createUnsignedForgetMessage(args) {
|
|
|
778
778
|
};
|
|
779
779
|
}
|
|
780
780
|
async function forgetAlephMessages(args) {
|
|
781
|
+
args.onProgress?.({
|
|
782
|
+
stage: "building-delete-message",
|
|
783
|
+
label: "Building delete message",
|
|
784
|
+
progress: 18,
|
|
785
|
+
status: "info",
|
|
786
|
+
itemHash: null,
|
|
787
|
+
detail: [...new Set((args.hashes ?? []).filter(Boolean))].join(", ") || null,
|
|
788
|
+
error: null,
|
|
789
|
+
timestamp: Date.now()
|
|
790
|
+
});
|
|
781
791
|
const unsignedMessage = await createUnsignedForgetMessage({
|
|
782
792
|
sender: args.sender,
|
|
783
793
|
hashes: args.hashes,
|
|
@@ -787,18 +797,49 @@ async function forgetAlephMessages(args) {
|
|
|
787
797
|
channel: args.channel,
|
|
788
798
|
now: args.now
|
|
789
799
|
});
|
|
800
|
+
args.onProgress?.({
|
|
801
|
+
stage: "signing-delete-message",
|
|
802
|
+
label: "Waiting for delete signature",
|
|
803
|
+
progress: 42,
|
|
804
|
+
status: "info",
|
|
805
|
+
itemHash: unsignedMessage.item_hash,
|
|
806
|
+
detail: unsignedMessage.item_hash,
|
|
807
|
+
error: null,
|
|
808
|
+
timestamp: Date.now()
|
|
809
|
+
});
|
|
790
810
|
const message = await signAlephMessage(unsignedMessage, args.signer);
|
|
811
|
+
args.onProgress?.({
|
|
812
|
+
stage: "broadcasting-delete",
|
|
813
|
+
label: "Broadcasting delete to Aleph",
|
|
814
|
+
progress: 68,
|
|
815
|
+
status: "warning",
|
|
816
|
+
itemHash: message.item_hash,
|
|
817
|
+
detail: message.item_hash,
|
|
818
|
+
error: null,
|
|
819
|
+
timestamp: Date.now()
|
|
820
|
+
});
|
|
791
821
|
const { response, httpStatus } = await broadcastAlephMessage(message, {
|
|
792
822
|
apiHost: args.apiHost,
|
|
793
823
|
sync: args.sync,
|
|
794
824
|
fetch: args.fetch
|
|
795
825
|
});
|
|
826
|
+
const status = normalizeBroadcastStatus(httpStatus, response?.message_status);
|
|
827
|
+
args.onProgress?.({
|
|
828
|
+
stage: status === "rejected" ? "error" : "delete-completed",
|
|
829
|
+
label: status === "rejected" ? "Delete rejected by Aleph" : "Delete submitted to Aleph",
|
|
830
|
+
progress: 100,
|
|
831
|
+
status: status === "rejected" ? "error" : "success",
|
|
832
|
+
itemHash: message.item_hash,
|
|
833
|
+
detail: status === "rejected" ? String(response?.details ?? "Aleph rejected this delete request.") : null,
|
|
834
|
+
error: status === "rejected" ? String(response?.details ?? "Aleph rejected this delete request.") : null,
|
|
835
|
+
timestamp: Date.now()
|
|
836
|
+
});
|
|
796
837
|
return {
|
|
797
838
|
sender: args.sender,
|
|
798
839
|
itemHash: message.item_hash,
|
|
799
840
|
response,
|
|
800
841
|
httpStatus,
|
|
801
|
-
status
|
|
842
|
+
status
|
|
802
843
|
};
|
|
803
844
|
}
|
|
804
845
|
async function cleanupFailedDeployment(args) {
|
|
@@ -1355,6 +1396,16 @@ async function createDeploymentIntent(args) {
|
|
|
1355
1396
|
};
|
|
1356
1397
|
}
|
|
1357
1398
|
async function deployInstance(args) {
|
|
1399
|
+
args.onProgress?.({
|
|
1400
|
+
stage: "building-message",
|
|
1401
|
+
label: "Building deployment message",
|
|
1402
|
+
progress: 32,
|
|
1403
|
+
status: "info",
|
|
1404
|
+
detail: args.content.metadata?.name ?? null,
|
|
1405
|
+
itemHash: null,
|
|
1406
|
+
error: null,
|
|
1407
|
+
timestamp: Date.now()
|
|
1408
|
+
});
|
|
1358
1409
|
const unsignedMessage = await createUnsignedInstanceMessage({
|
|
1359
1410
|
sender: args.sender,
|
|
1360
1411
|
content: args.content,
|
|
@@ -1362,17 +1413,47 @@ async function deployInstance(args) {
|
|
|
1362
1413
|
channel: args.channel,
|
|
1363
1414
|
now: args.now
|
|
1364
1415
|
});
|
|
1416
|
+
args.onProgress?.({
|
|
1417
|
+
stage: "signing-message",
|
|
1418
|
+
label: "Waiting for MetaMask signature",
|
|
1419
|
+
progress: 48,
|
|
1420
|
+
status: "info",
|
|
1421
|
+
detail: unsignedMessage.item_hash,
|
|
1422
|
+
itemHash: unsignedMessage.item_hash,
|
|
1423
|
+
error: null,
|
|
1424
|
+
timestamp: Date.now()
|
|
1425
|
+
});
|
|
1365
1426
|
const signature = await args.signer(unsignedMessage.sender, [unsignedMessage.chain, unsignedMessage.sender, unsignedMessage.type, unsignedMessage.item_hash].join("\n"));
|
|
1366
1427
|
const message = {
|
|
1367
1428
|
...unsignedMessage,
|
|
1368
1429
|
signature: signature.startsWith("0x") ? signature : `0x${signature}`
|
|
1369
1430
|
};
|
|
1431
|
+
args.onProgress?.({
|
|
1432
|
+
stage: "broadcasting",
|
|
1433
|
+
label: "Broadcasting to Aleph",
|
|
1434
|
+
progress: 64,
|
|
1435
|
+
status: "info",
|
|
1436
|
+
detail: message.item_hash,
|
|
1437
|
+
itemHash: message.item_hash,
|
|
1438
|
+
error: null,
|
|
1439
|
+
timestamp: Date.now()
|
|
1440
|
+
});
|
|
1370
1441
|
const { response, httpStatus } = await broadcastAlephMessage(message, {
|
|
1371
1442
|
apiHost: args.apiHost,
|
|
1372
1443
|
sync: args.sync,
|
|
1373
1444
|
fetch: args.fetch
|
|
1374
1445
|
});
|
|
1375
1446
|
const status = httpStatus === 202 ? "pending" : typeof response.message_status === "string" ? response.message_status : "unknown";
|
|
1447
|
+
args.onProgress?.({
|
|
1448
|
+
stage: status === "processed" ? "deployment-confirmed" : status === "rejected" ? "deployment-rejected" : "waiting-for-aleph",
|
|
1449
|
+
label: status === "processed" ? "Deployment accepted by Aleph" : status === "rejected" ? "Deployment rejected by Aleph" : "Deployment submitted to Aleph",
|
|
1450
|
+
progress: status === "processed" ? 88 : status === "rejected" ? 100 : 78,
|
|
1451
|
+
status: status === "processed" ? "success" : status === "rejected" ? "error" : "warning",
|
|
1452
|
+
detail: status === "rejected" ? String(response.details ?? "Aleph rejected this deployment.") : null,
|
|
1453
|
+
itemHash: message.item_hash,
|
|
1454
|
+
error: status === "rejected" ? String(response.details ?? "Aleph rejected this deployment.") : null,
|
|
1455
|
+
timestamp: Date.now()
|
|
1456
|
+
});
|
|
1376
1457
|
return {
|
|
1377
1458
|
itemHash: message.item_hash,
|
|
1378
1459
|
httpStatus,
|
|
@@ -1668,18 +1749,22 @@ async function notifyCrnAllocation(args) {
|
|
|
1668
1749
|
};
|
|
1669
1750
|
}
|
|
1670
1751
|
try {
|
|
1671
|
-
const response = await args.fetch(
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1752
|
+
const response = await args.fetch(
|
|
1753
|
+
`${normalizedCrnUrl}/control/allocation/notify`,
|
|
1754
|
+
{
|
|
1755
|
+
method: "POST",
|
|
1756
|
+
headers: {
|
|
1757
|
+
"content-type": "application/json"
|
|
1758
|
+
},
|
|
1759
|
+
body: JSON.stringify({ instance: args.itemHash })
|
|
1760
|
+
}
|
|
1761
|
+
);
|
|
1678
1762
|
const payload = await response.json().catch(() => null);
|
|
1763
|
+
const responseText = payload == null ? "" : typeof payload === "string" ? payload : JSON.stringify(payload);
|
|
1679
1764
|
if (!response.ok) {
|
|
1680
1765
|
return {
|
|
1681
1766
|
status: "unconfirmed",
|
|
1682
|
-
reason: `CRN allocation notify returned ${response.status}.`,
|
|
1767
|
+
reason: `CRN allocation notify returned ${response.status}${responseText ? ` ${responseText}` : ""}.`,
|
|
1683
1768
|
payload
|
|
1684
1769
|
};
|
|
1685
1770
|
}
|
|
@@ -1694,24 +1779,76 @@ async function notifyCrnAllocation(args) {
|
|
|
1694
1779
|
};
|
|
1695
1780
|
}
|
|
1696
1781
|
}
|
|
1782
|
+
function isRetryableAllocationNotifyReason(reason) {
|
|
1783
|
+
const normalized = String(reason ?? "").toLowerCase();
|
|
1784
|
+
return normalized.includes("503") && (normalized.includes("node hash not yet discovered") || normalized.includes("cannot accept targeted allocations"));
|
|
1785
|
+
}
|
|
1786
|
+
async function notifyCrnAllocationWithRetry(args) {
|
|
1787
|
+
const attempts = Math.max(1, Number(args.attempts ?? 6));
|
|
1788
|
+
const delayMs = Math.max(0, Number(args.delayMs ?? 2e3));
|
|
1789
|
+
const sleep = args.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
1790
|
+
let lastResult = null;
|
|
1791
|
+
for (let attempt = 0; attempt < attempts; attempt += 1) {
|
|
1792
|
+
args.onProgress?.({
|
|
1793
|
+
stage: "notifying-crn",
|
|
1794
|
+
label: "Notifying selected CRN",
|
|
1795
|
+
progress: 84,
|
|
1796
|
+
status: "info",
|
|
1797
|
+
itemHash: args.itemHash,
|
|
1798
|
+
detail: `${attempt + 1}/${attempts} ${String(args.crnUrl ?? "").trim() || "selected CRN"}`,
|
|
1799
|
+
error: null,
|
|
1800
|
+
timestamp: Date.now()
|
|
1801
|
+
});
|
|
1802
|
+
const result = await notifyCrnAllocation({
|
|
1803
|
+
crnUrl: args.crnUrl,
|
|
1804
|
+
itemHash: args.itemHash,
|
|
1805
|
+
fetch: args.fetch
|
|
1806
|
+
});
|
|
1807
|
+
if (result.status === "confirmed" || result.status === "skipped") {
|
|
1808
|
+
return result;
|
|
1809
|
+
}
|
|
1810
|
+
lastResult = result;
|
|
1811
|
+
if (!isRetryableAllocationNotifyReason(result.reason)) {
|
|
1812
|
+
return result;
|
|
1813
|
+
}
|
|
1814
|
+
if (attempt < attempts - 1) {
|
|
1815
|
+
await sleep(delayMs);
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1818
|
+
return lastResult ?? {
|
|
1819
|
+
status: "unconfirmed",
|
|
1820
|
+
reason: "CRN allocation notify was not confirmed."
|
|
1821
|
+
};
|
|
1822
|
+
}
|
|
1697
1823
|
async function waitForSetupEndpoint(args) {
|
|
1698
1824
|
const attempts = Math.max(1, Number(args.attempts ?? 15));
|
|
1699
1825
|
const delayMs = Math.max(0, Number(args.delayMs ?? 4e3));
|
|
1700
1826
|
const sleep = args.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
1701
1827
|
const url = `http://${args.hostIpv4}:${args.setupPort}/health`;
|
|
1702
|
-
let result = await defaultHttpProbe(
|
|
1828
|
+
let result = await defaultHttpProbe(
|
|
1829
|
+
args.fetch,
|
|
1830
|
+
url,
|
|
1831
|
+
Number(args.httpTimeoutMs ?? 1e4)
|
|
1832
|
+
);
|
|
1703
1833
|
args.onAttempt?.(result, 1, attempts);
|
|
1704
1834
|
for (let attempt = 1; attempt < attempts; attempt += 1) {
|
|
1705
1835
|
if (result.ok) return result;
|
|
1706
1836
|
await sleep(delayMs);
|
|
1707
|
-
result = await defaultHttpProbe(
|
|
1837
|
+
result = await defaultHttpProbe(
|
|
1838
|
+
args.fetch,
|
|
1839
|
+
url,
|
|
1840
|
+
Number(args.httpTimeoutMs ?? 1e4)
|
|
1841
|
+
);
|
|
1708
1842
|
args.onAttempt?.(result, attempt + 1, attempts);
|
|
1709
1843
|
}
|
|
1710
1844
|
return result;
|
|
1711
1845
|
}
|
|
1712
1846
|
async function configureUcGoPeer(args) {
|
|
1713
1847
|
const controller = new AbortController();
|
|
1714
|
-
const timeout = setTimeout(
|
|
1848
|
+
const timeout = setTimeout(
|
|
1849
|
+
() => controller.abort(),
|
|
1850
|
+
Number(args.timeoutMs ?? 18e4)
|
|
1851
|
+
);
|
|
1715
1852
|
const payload = {
|
|
1716
1853
|
public_ipv4: args.hostIpv4,
|
|
1717
1854
|
public_ipv6: args.publicIpv6 ?? void 0,
|
|
@@ -1723,14 +1860,57 @@ async function configureUcGoPeer(args) {
|
|
|
1723
1860
|
webrtc_port: args.webrtcPort ?? void 0
|
|
1724
1861
|
};
|
|
1725
1862
|
try {
|
|
1726
|
-
const response = await args.fetch(
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1863
|
+
const response = await args.fetch(
|
|
1864
|
+
`http://${args.hostIpv4}:${args.setupPort}/configure`,
|
|
1865
|
+
{
|
|
1866
|
+
method: "POST",
|
|
1867
|
+
headers: {
|
|
1868
|
+
"content-type": "application/json"
|
|
1869
|
+
},
|
|
1870
|
+
body: JSON.stringify(payload),
|
|
1871
|
+
signal: controller.signal
|
|
1872
|
+
}
|
|
1873
|
+
);
|
|
1874
|
+
const responsePayload = await response.json().catch(() => null);
|
|
1875
|
+
if (!response.ok) {
|
|
1876
|
+
throw new Error(
|
|
1877
|
+
`Relay setup request failed: ${response.status} ${typeof responsePayload === "string" ? responsePayload : JSON.stringify(responsePayload ?? {})}`
|
|
1878
|
+
);
|
|
1879
|
+
}
|
|
1880
|
+
return responsePayload;
|
|
1881
|
+
} finally {
|
|
1882
|
+
clearTimeout(timeout);
|
|
1883
|
+
}
|
|
1884
|
+
}
|
|
1885
|
+
async function configureOrbitdbRelaySetup(args) {
|
|
1886
|
+
const controller = new AbortController();
|
|
1887
|
+
const timeout = setTimeout(
|
|
1888
|
+
() => controller.abort(),
|
|
1889
|
+
Number(args.timeoutMs ?? 18e4)
|
|
1890
|
+
);
|
|
1891
|
+
const payload = {
|
|
1892
|
+
public_ipv4: args.hostIpv4,
|
|
1893
|
+
public_ipv6: args.publicIpv6 ?? void 0,
|
|
1894
|
+
tcp_port: args.tcpPort,
|
|
1895
|
+
ws_port: args.wsPort,
|
|
1896
|
+
proxy_url: args.proxyUrl ?? void 0,
|
|
1897
|
+
metrics_port: args.metricsPort ?? void 0,
|
|
1898
|
+
metrics_https_port: args.metricsHttpsPort ?? void 0,
|
|
1899
|
+
webrtc_port: args.webrtcPort ?? void 0,
|
|
1900
|
+
quic_port: args.quicPort ?? void 0
|
|
1901
|
+
};
|
|
1902
|
+
try {
|
|
1903
|
+
const response = await args.fetch(
|
|
1904
|
+
`http://${args.hostIpv4}:${args.setupPort}/configure`,
|
|
1905
|
+
{
|
|
1906
|
+
method: "POST",
|
|
1907
|
+
headers: {
|
|
1908
|
+
"content-type": "application/json"
|
|
1909
|
+
},
|
|
1910
|
+
body: JSON.stringify(payload),
|
|
1911
|
+
signal: controller.signal
|
|
1912
|
+
}
|
|
1913
|
+
);
|
|
1734
1914
|
const responsePayload = await response.json().catch(() => null);
|
|
1735
1915
|
if (!response.ok) {
|
|
1736
1916
|
throw new Error(
|
|
@@ -1749,16 +1929,24 @@ async function fetchUcGoPeerMetadata(args) {
|
|
|
1749
1929
|
let lastPayload = null;
|
|
1750
1930
|
for (let attempt = 0; attempt < attempts; attempt += 1) {
|
|
1751
1931
|
const controller = new AbortController();
|
|
1752
|
-
const timeout = setTimeout(
|
|
1932
|
+
const timeout = setTimeout(
|
|
1933
|
+
() => controller.abort(),
|
|
1934
|
+
Number(args.timeoutMs ?? 18e4)
|
|
1935
|
+
);
|
|
1753
1936
|
try {
|
|
1754
|
-
const response = await args.fetch(
|
|
1755
|
-
|
|
1756
|
-
|
|
1937
|
+
const response = await args.fetch(
|
|
1938
|
+
`http://${args.hostIpv4}:${args.setupPort}/metadata`,
|
|
1939
|
+
{
|
|
1940
|
+
signal: controller.signal
|
|
1941
|
+
}
|
|
1942
|
+
);
|
|
1757
1943
|
const payload = await response.json().catch(() => null);
|
|
1758
1944
|
lastPayload = payload;
|
|
1759
1945
|
args.onAttempt?.(
|
|
1760
1946
|
payload,
|
|
1761
|
-
Boolean(
|
|
1947
|
+
Boolean(
|
|
1948
|
+
response.ok && payload && typeof payload === "object" && payload.status === "ready"
|
|
1949
|
+
),
|
|
1762
1950
|
attempt + 1,
|
|
1763
1951
|
attempts
|
|
1764
1952
|
);
|
|
@@ -1785,7 +1973,9 @@ async function verifyUcGoPeerReachability(args) {
|
|
|
1785
1973
|
const checks = {};
|
|
1786
1974
|
const mappedPorts = args.mappedPorts ?? {};
|
|
1787
1975
|
const hostIpv4 = args.hostIpv4;
|
|
1788
|
-
const skippedInternalPorts = new Set(
|
|
1976
|
+
const skippedInternalPorts = new Set(
|
|
1977
|
+
(args.skipInternalPorts ?? ["80"]).map((value) => String(value))
|
|
1978
|
+
);
|
|
1789
1979
|
const httpProbe = args.httpProbe ?? ((url, timeoutMs) => defaultHttpProbe(args.fetch, url, timeoutMs));
|
|
1790
1980
|
if (hostIpv4) {
|
|
1791
1981
|
for (const [internalPort, mapping] of Object.entries(mappedPorts)) {
|
|
@@ -1794,7 +1984,11 @@ async function verifyUcGoPeerReachability(args) {
|
|
|
1794
1984
|
checks[`tcp:${internalPort}`] = {
|
|
1795
1985
|
host: hostIpv4,
|
|
1796
1986
|
port: mapping.host,
|
|
1797
|
-
...await args.tcpProbe(
|
|
1987
|
+
...await args.tcpProbe(
|
|
1988
|
+
hostIpv4,
|
|
1989
|
+
mapping.host,
|
|
1990
|
+
Number(args.tcpTimeoutMs ?? 5e3)
|
|
1991
|
+
)
|
|
1798
1992
|
};
|
|
1799
1993
|
} else if (mapping?.udp === true && mapping?.host) {
|
|
1800
1994
|
checks[`udp:${internalPort}`] = {
|
|
@@ -1807,18 +2001,196 @@ async function verifyUcGoPeerReachability(args) {
|
|
|
1807
2001
|
}
|
|
1808
2002
|
}
|
|
1809
2003
|
if (args.proxyUrl && args.verifyProxyHttp !== false) {
|
|
1810
|
-
checks["https:proxy"] = await httpProbe(
|
|
2004
|
+
checks["https:proxy"] = await httpProbe(
|
|
2005
|
+
args.proxyUrl,
|
|
2006
|
+
Number(args.httpTimeoutMs ?? 1e4)
|
|
2007
|
+
);
|
|
1811
2008
|
}
|
|
1812
2009
|
const proxyHostname = proxyHostnameFromUrl(args.proxyUrl);
|
|
1813
2010
|
if (proxyHostname) {
|
|
1814
|
-
checks["tcp:proxy-443"] = await args.tcpProbe(
|
|
1815
|
-
|
|
1816
|
-
|
|
2011
|
+
checks["tcp:proxy-443"] = await args.tcpProbe(
|
|
2012
|
+
proxyHostname,
|
|
2013
|
+
443,
|
|
2014
|
+
Number(args.tcpTimeoutMs ?? 5e3)
|
|
2015
|
+
);
|
|
2016
|
+
}
|
|
2017
|
+
const failedChecks = Object.entries(checks).filter(
|
|
2018
|
+
([, value]) => value?.ok === false
|
|
2019
|
+
);
|
|
1817
2020
|
return {
|
|
1818
2021
|
ok: failedChecks.length === 0,
|
|
1819
2022
|
checks
|
|
1820
2023
|
};
|
|
1821
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
|
+
}
|
|
1822
2194
|
export {
|
|
1823
2195
|
DEFAULT_ALEPH_API_HOST,
|
|
1824
2196
|
DEFAULT_ALEPH_CHANNEL,
|
|
@@ -1835,6 +2207,7 @@ export {
|
|
|
1835
2207
|
broadcastAlephMessage,
|
|
1836
2208
|
buildPaymentQuote,
|
|
1837
2209
|
cleanupFailedDeployment,
|
|
2210
|
+
configureOrbitdbRelaySetup,
|
|
1838
2211
|
configureUcGoPeer,
|
|
1839
2212
|
createDeploymentIntent,
|
|
1840
2213
|
createInstanceContent,
|
|
@@ -1878,10 +2251,12 @@ export {
|
|
|
1878
2251
|
normalizeProxyUrl,
|
|
1879
2252
|
normalizeSshPublicKey,
|
|
1880
2253
|
notifyCrnAllocation,
|
|
2254
|
+
notifyCrnAllocationWithRetry,
|
|
1881
2255
|
portForwardLabel,
|
|
1882
2256
|
postBroadcastPayload,
|
|
1883
2257
|
probeRootfsGateway,
|
|
1884
2258
|
publishAggregateKey,
|
|
2259
|
+
publishRelayBootstrapRegistration,
|
|
1885
2260
|
quoteRequiredBudgetUnits,
|
|
1886
2261
|
rankCandidateCrns,
|
|
1887
2262
|
requestedPortFlags,
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@le-space/core",
|
|
3
|
-
"version": "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/
|
|
19
|
+
"@le-space/aleph-bootstrap": "0.3.0",
|
|
20
|
+
"@le-space/shared-types": "0.3.0"
|
|
20
21
|
}
|
|
21
22
|
}
|