@le-space/core 0.3.11 → 0.3.12
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 +109 -12
- package/index.js +372 -1
- package/package.json +3 -3
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, DeploymentProgressListener, 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, VmBootstrapConfigRecord, VmBootstrapConfigAggregate } from '@le-space/shared-types';
|
|
3
3
|
|
|
4
4
|
declare const DEFAULT_ALEPH_CHANNEL = "TEST";
|
|
5
5
|
|
|
@@ -197,7 +197,7 @@ interface JsonFetchLikeResponse {
|
|
|
197
197
|
status: number;
|
|
198
198
|
json(): Promise<unknown>;
|
|
199
199
|
}
|
|
200
|
-
type JsonFetchLike = (url: string, init?: RequestInit) => Promise<JsonFetchLikeResponse>;
|
|
200
|
+
type JsonFetchLike$1 = (url: string, init?: RequestInit) => Promise<JsonFetchLikeResponse>;
|
|
201
201
|
declare function signaturePayload(message: Pick<AlephBroadcastMessage, 'chain' | 'sender' | 'type' | 'item_hash'>): string;
|
|
202
202
|
declare function signAlephMessage(unsignedMessage: Omit<AlephBroadcastMessage, 'signature'>, signer: MessageSigner): Promise<AlephBroadcastMessage>;
|
|
203
203
|
declare function normalizeBroadcastStatus(httpStatus: number, responseStatus: unknown): MessageStatus;
|
|
@@ -209,7 +209,7 @@ declare function isRetryableBroadcastFailure(response: {
|
|
|
209
209
|
}, payload: AlephBroadcastResponse): boolean;
|
|
210
210
|
declare function postBroadcastPayload(body: Record<string, unknown>, options: {
|
|
211
211
|
apiHost?: string;
|
|
212
|
-
fetch: JsonFetchLike;
|
|
212
|
+
fetch: JsonFetchLike$1;
|
|
213
213
|
}): Promise<{
|
|
214
214
|
response: AlephBroadcastResponse;
|
|
215
215
|
httpStatus: number;
|
|
@@ -217,7 +217,7 @@ declare function postBroadcastPayload(body: Record<string, unknown>, options: {
|
|
|
217
217
|
declare function broadcastAlephMessage(message: AlephBroadcastMessage, options: {
|
|
218
218
|
apiHost?: string;
|
|
219
219
|
sync?: boolean;
|
|
220
|
-
fetch: JsonFetchLike;
|
|
220
|
+
fetch: JsonFetchLike$1;
|
|
221
221
|
}): Promise<{
|
|
222
222
|
response: AlephBroadcastResponse;
|
|
223
223
|
httpStatus: number;
|
|
@@ -239,7 +239,7 @@ declare function forgetAlephMessages(args: {
|
|
|
239
239
|
reason?: string;
|
|
240
240
|
signer: MessageSigner;
|
|
241
241
|
hasher: MessageHasher;
|
|
242
|
-
fetch: JsonFetchLike;
|
|
242
|
+
fetch: JsonFetchLike$1;
|
|
243
243
|
channel?: string;
|
|
244
244
|
apiHost?: string;
|
|
245
245
|
sync?: boolean;
|
|
@@ -258,7 +258,7 @@ declare function cleanupFailedDeployment(args: {
|
|
|
258
258
|
reason?: string;
|
|
259
259
|
signer: MessageSigner;
|
|
260
260
|
hasher: MessageHasher;
|
|
261
|
-
fetch: JsonFetchLike;
|
|
261
|
+
fetch: JsonFetchLike$1;
|
|
262
262
|
channel?: string;
|
|
263
263
|
apiHost?: string;
|
|
264
264
|
}): Promise<{
|
|
@@ -286,7 +286,7 @@ interface RetentionRecord {
|
|
|
286
286
|
declare function fetchAggregateKey(args: {
|
|
287
287
|
address: string;
|
|
288
288
|
key: string;
|
|
289
|
-
fetch: JsonFetchLike;
|
|
289
|
+
fetch: JsonFetchLike$1;
|
|
290
290
|
apiHost?: string;
|
|
291
291
|
}): Promise<unknown>;
|
|
292
292
|
declare function publishAggregateKey(args: {
|
|
@@ -295,7 +295,7 @@ declare function publishAggregateKey(args: {
|
|
|
295
295
|
content: Record<string, unknown>;
|
|
296
296
|
signer: MessageSigner;
|
|
297
297
|
hasher: MessageHasher;
|
|
298
|
-
fetch: JsonFetchLike;
|
|
298
|
+
fetch: JsonFetchLike$1;
|
|
299
299
|
channel?: string;
|
|
300
300
|
apiHost?: string;
|
|
301
301
|
now?: number;
|
|
@@ -311,7 +311,7 @@ declare function retainSuccessfulDeployments(args: {
|
|
|
311
311
|
keepCount: number;
|
|
312
312
|
signer: MessageSigner;
|
|
313
313
|
hasher: MessageHasher;
|
|
314
|
-
fetch: JsonFetchLike;
|
|
314
|
+
fetch: JsonFetchLike$1;
|
|
315
315
|
aggregateKey?: string;
|
|
316
316
|
extraForgetHashes?: string[];
|
|
317
317
|
reason?: string;
|
|
@@ -381,7 +381,7 @@ declare function ensureInstancePortForwards(args: {
|
|
|
381
381
|
manifest: RootfsManifest | null;
|
|
382
382
|
signer: MessageSigner;
|
|
383
383
|
hasher: MessageHasher;
|
|
384
|
-
fetch: JsonFetchLike;
|
|
384
|
+
fetch: JsonFetchLike$1;
|
|
385
385
|
channel?: string;
|
|
386
386
|
apiHost?: string;
|
|
387
387
|
sync?: boolean;
|
|
@@ -406,6 +406,8 @@ interface PaymentQuote {
|
|
|
406
406
|
}
|
|
407
407
|
declare function normalizeSshPublicKey(value: string): string;
|
|
408
408
|
declare function isValidSshPublicKey(value: string): boolean;
|
|
409
|
+
declare function createDeploymentToken(): string;
|
|
410
|
+
declare function appendDeploymentTokenToSshPublicKey(sshPublicKey: string, ownerAddress: string, deploymentToken: string): string;
|
|
409
411
|
declare function createReleaseMetadata(name: string, rootfsVersion: string, deployer?: string): {
|
|
410
412
|
name: string;
|
|
411
413
|
rootfs_version: string;
|
|
@@ -619,6 +621,7 @@ declare function configureOrbitdbRelaySetup(args: {
|
|
|
619
621
|
declare function fetchUcGoPeerMetadata(args: {
|
|
620
622
|
hostIpv4: string;
|
|
621
623
|
setupPort: number;
|
|
624
|
+
metadataUrl?: string | null;
|
|
622
625
|
fetch: FetchLike;
|
|
623
626
|
attempts?: number;
|
|
624
627
|
delayMs?: number;
|
|
@@ -690,7 +693,7 @@ declare function publishRelayBootstrapRegistration(args: {
|
|
|
690
693
|
sender: string;
|
|
691
694
|
signer: MessageSigner;
|
|
692
695
|
hasher: MessageHasher;
|
|
693
|
-
fetch: JsonFetchLike;
|
|
696
|
+
fetch: JsonFetchLike$1;
|
|
694
697
|
peerId: string;
|
|
695
698
|
multiaddrs: string[];
|
|
696
699
|
browserMultiaddrs?: string[];
|
|
@@ -716,4 +719,98 @@ declare function publishRelayBootstrapRegistration(args: {
|
|
|
716
719
|
now?: number;
|
|
717
720
|
}): Promise<RelayBootstrapPublicationResult>;
|
|
718
721
|
|
|
719
|
-
|
|
722
|
+
declare const VM_BOOTSTRAP_CONFIG_AGGREGATE_KEY = "vm-bootstrap-config";
|
|
723
|
+
declare function fetchVmBootstrapConfigAggregate(address: string, options: {
|
|
724
|
+
apiHost?: string;
|
|
725
|
+
fetch: JsonFetchLike$1;
|
|
726
|
+
}): Promise<VmBootstrapConfigAggregate>;
|
|
727
|
+
declare function createVmBootstrapConfigAggregateContent(args: {
|
|
728
|
+
sender: string;
|
|
729
|
+
record: VmBootstrapConfigRecord;
|
|
730
|
+
existingAggregate?: VmBootstrapConfigAggregate | null;
|
|
731
|
+
now?: number;
|
|
732
|
+
}): AlephAggregateContent<VmBootstrapConfigAggregate>;
|
|
733
|
+
declare function publishVmBootstrapConfig(args: {
|
|
734
|
+
sender: string;
|
|
735
|
+
record: VmBootstrapConfigRecord;
|
|
736
|
+
signer: MessageSigner;
|
|
737
|
+
hasher: MessageHasher;
|
|
738
|
+
fetch: JsonFetchLike$1;
|
|
739
|
+
channel?: string;
|
|
740
|
+
apiHost?: string;
|
|
741
|
+
sync?: boolean;
|
|
742
|
+
}): Promise<{
|
|
743
|
+
aggregateItemHash: string;
|
|
744
|
+
aggregateStatus: MessageStatus;
|
|
745
|
+
aggregate: VmBootstrapConfigAggregate;
|
|
746
|
+
}>;
|
|
747
|
+
declare function deleteVmBootstrapConfig(args: {
|
|
748
|
+
sender: string;
|
|
749
|
+
deploymentToken: string;
|
|
750
|
+
signer: MessageSigner;
|
|
751
|
+
hasher: MessageHasher;
|
|
752
|
+
fetch: JsonFetchLike$1;
|
|
753
|
+
channel?: string;
|
|
754
|
+
apiHost?: string;
|
|
755
|
+
sync?: boolean;
|
|
756
|
+
}): Promise<{
|
|
757
|
+
aggregateItemHash: string;
|
|
758
|
+
aggregateStatus: MessageStatus;
|
|
759
|
+
aggregate: VmBootstrapConfigAggregate;
|
|
760
|
+
}>;
|
|
761
|
+
|
|
762
|
+
type JsonFetchLike = FetchLike;
|
|
763
|
+
type RelayMetadataShape = {
|
|
764
|
+
peerId: string;
|
|
765
|
+
probeMultiaddrs: string[];
|
|
766
|
+
browserBootstrapMultiaddrs: string[];
|
|
767
|
+
};
|
|
768
|
+
interface OwnerRelayBootstrapReconcileResult {
|
|
769
|
+
refreshedRegistrations: string[];
|
|
770
|
+
forgottenHashes: string[];
|
|
771
|
+
skippedInstanceHashes: string[];
|
|
772
|
+
errors: Array<{
|
|
773
|
+
phase: string;
|
|
774
|
+
itemHash?: string;
|
|
775
|
+
registrationId?: string;
|
|
776
|
+
message: string;
|
|
777
|
+
}>;
|
|
778
|
+
}
|
|
779
|
+
declare function createRelayBootstrapRegistrationId(profile: string, instanceName: string | null | undefined, itemHash: string): string;
|
|
780
|
+
declare function fetchRelayMetadataForRuntime(args: {
|
|
781
|
+
runtime: Awaited<ReturnType<typeof fetchVmRuntime>>;
|
|
782
|
+
fetch: JsonFetchLike;
|
|
783
|
+
preferSecureMetadata?: boolean;
|
|
784
|
+
attempts?: number;
|
|
785
|
+
delayMs?: number;
|
|
786
|
+
timeoutMs?: number;
|
|
787
|
+
}): Promise<RelayMetadataShape | null>;
|
|
788
|
+
declare function reconcileOwnerRelayBootstrapRegistrations(args: {
|
|
789
|
+
instanceOwnerAddress: string;
|
|
790
|
+
sender: string;
|
|
791
|
+
signer: MessageSigner;
|
|
792
|
+
hasher: MessageHasher;
|
|
793
|
+
fetch: JsonFetchLike;
|
|
794
|
+
profile: string;
|
|
795
|
+
apiHost?: string;
|
|
796
|
+
channel?: string;
|
|
797
|
+
ref?: string;
|
|
798
|
+
postType?: string;
|
|
799
|
+
version?: string;
|
|
800
|
+
ownerAddress?: string;
|
|
801
|
+
ownerSigner?: MessageSigner;
|
|
802
|
+
publisherAddress?: string;
|
|
803
|
+
publisherSigner?: MessageSigner;
|
|
804
|
+
crns?: CrnRecord[];
|
|
805
|
+
crnListUrl?: string;
|
|
806
|
+
preferSecureMetadata?: boolean;
|
|
807
|
+
current?: {
|
|
808
|
+
itemHash: string;
|
|
809
|
+
registrationId: string;
|
|
810
|
+
peerId: string;
|
|
811
|
+
probeMultiaddrs: string[];
|
|
812
|
+
browserBootstrapMultiaddrs?: string[];
|
|
813
|
+
} | null;
|
|
814
|
+
}): Promise<OwnerRelayBootstrapReconcileResult>;
|
|
815
|
+
|
|
816
|
+
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$1 as JsonFetchLike, type JsonFetchLikeResponse, type OwnerRelayBootstrapReconcileResult, type PaymentQuote, type RelayBootstrapPublicationResult, type RelayMetadataShape, type RetentionRecord, SSH_PUBLIC_KEY_PATTERN, SUCCESSFUL_DEPLOYMENTS_AGGREGATE_KEY, type TcpProbeResult, type TierSpec, VM_BOOTSTRAP_CONFIG_AGGREGATE_KEY, appendDeploymentTokenToSshPublicKey, broadcastAlephMessage, buildPaymentQuote, cleanupFailedDeployment, configureOrbitdbRelaySetup, configureUcGoPeer, createDeploymentIntent, createDeploymentToken, createInstanceContent, createPortForwardAggregateContent, createRelayBootstrapRegistrationId, createReleaseMetadata, createUnsignedAggregateMessage, createUnsignedForgetMessage, createUnsignedInstanceMessage, createVmBootstrapConfigAggregateContent, deleteVmBootstrapConfig, deployInstance, describeRejectedDeployment, describeRuntimeAvailability, enrichCrnsWithGeo, ensureInstancePortForwards, extractInsufficientBalanceMessage, extractProxyUrl, extractReferenceHashes, fetch2n6WebAccessUrl, fetchAggregateKey, fetchCrnExecutionMap, fetchCrns, fetchMessageEnvelope, fetchPortForwardAggregate, fetchRelayMetadataForRuntime, fetchSchedulerAllocation, fetchUcGoPeerMetadata, fetchVmBootstrapConfigAggregate, 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, publishVmBootstrapConfig, quoteRequiredBudgetUnits, rankCandidateCrns, reconcileOwnerRelayBootstrapRegistrations, requestedPortFlags, requiredInstancePortForwards, resolveRootfsReference, retainSuccessfulDeployments, selectPreferredCrn, selectedTier, signAlephMessage, signaturePayload, tierSpec, validateRootfsManifest, verifyRootfsExists, verifyUcGoPeerReachability, waitForDeploymentResult, waitForSetupEndpoint, waitForVmRuntime };
|
package/index.js
CHANGED
|
@@ -1289,6 +1289,24 @@ function normalizeSshPublicKey(value) {
|
|
|
1289
1289
|
function isValidSshPublicKey(value) {
|
|
1290
1290
|
return SSH_PUBLIC_KEY_PATTERN.test(normalizeSshPublicKey(value));
|
|
1291
1291
|
}
|
|
1292
|
+
function createDeploymentToken() {
|
|
1293
|
+
const randomUuid = globalThis.crypto?.randomUUID?.();
|
|
1294
|
+
if (typeof randomUuid === "string" && randomUuid.trim()) {
|
|
1295
|
+
return randomUuid;
|
|
1296
|
+
}
|
|
1297
|
+
return `deploy-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 12)}`;
|
|
1298
|
+
}
|
|
1299
|
+
function appendDeploymentTokenToSshPublicKey(sshPublicKey, ownerAddress, deploymentToken) {
|
|
1300
|
+
const normalized = normalizeSshPublicKey(sshPublicKey);
|
|
1301
|
+
if (!normalized) return normalized;
|
|
1302
|
+
const [algorithm = "", key = ""] = normalized.split(/\s+/, 3);
|
|
1303
|
+
const owner = ownerAddress.trim().toLowerCase();
|
|
1304
|
+
const token = deploymentToken.trim();
|
|
1305
|
+
if (!algorithm || !key || !owner || !token) {
|
|
1306
|
+
return normalized;
|
|
1307
|
+
}
|
|
1308
|
+
return `${algorithm} ${key} aleph-bootstrap-config:${owner}:${token}`;
|
|
1309
|
+
}
|
|
1292
1310
|
function createReleaseMetadata(name, rootfsVersion, deployer = "shared-aleph-tooling") {
|
|
1293
1311
|
return {
|
|
1294
1312
|
name,
|
|
@@ -1965,8 +1983,9 @@ async function fetchUcGoPeerMetadata(args) {
|
|
|
1965
1983
|
Number(args.timeoutMs ?? 18e4)
|
|
1966
1984
|
);
|
|
1967
1985
|
try {
|
|
1986
|
+
const requestUrl = args.metadataUrl && args.metadataUrl.trim() ? args.metadataUrl : `http://${args.hostIpv4}:${args.setupPort}/metadata`;
|
|
1968
1987
|
const response = await args.fetch(
|
|
1969
|
-
|
|
1988
|
+
requestUrl,
|
|
1970
1989
|
{
|
|
1971
1990
|
signal: controller.signal
|
|
1972
1991
|
}
|
|
@@ -2100,6 +2119,9 @@ function asNumber3(value) {
|
|
|
2100
2119
|
function normalizeHost(host) {
|
|
2101
2120
|
return host.trim().toLowerCase();
|
|
2102
2121
|
}
|
|
2122
|
+
function normalizeAddress(address) {
|
|
2123
|
+
return address.trim().toLowerCase();
|
|
2124
|
+
}
|
|
2103
2125
|
function normalizeSignature(signature) {
|
|
2104
2126
|
const trimmed = signature.trim();
|
|
2105
2127
|
return trimmed.startsWith("0x") ? trimmed : `0x${trimmed}`;
|
|
@@ -2401,6 +2423,40 @@ async function fetchAlephBootstrapPosts(options = {}) {
|
|
|
2401
2423
|
const payload = await response.json();
|
|
2402
2424
|
return (payload.posts ?? []).map((entry) => normalizeRelayBootstrapPostRecord(entry)).filter((entry) => entry != null);
|
|
2403
2425
|
}
|
|
2426
|
+
function compareRelayBootstrapPostRecency(left, right) {
|
|
2427
|
+
const leftUpdatedAt = left.content?.updatedAt ?? 0;
|
|
2428
|
+
const rightUpdatedAt = right.content?.updatedAt ?? 0;
|
|
2429
|
+
if (leftUpdatedAt !== rightUpdatedAt) return leftUpdatedAt - rightUpdatedAt;
|
|
2430
|
+
const leftTime = left.time ?? 0;
|
|
2431
|
+
const rightTime = right.time ?? 0;
|
|
2432
|
+
return leftTime - rightTime;
|
|
2433
|
+
}
|
|
2434
|
+
function relayBootstrapRecordIdentity(post) {
|
|
2435
|
+
const content = post.content;
|
|
2436
|
+
if (!content) return null;
|
|
2437
|
+
if (content.registrationId) return `registration:${content.registrationId}`;
|
|
2438
|
+
if (post.address) return `sender:${normalizeAddress(post.address)}`;
|
|
2439
|
+
return content.peerId ? `peer:${content.peerId}` : null;
|
|
2440
|
+
}
|
|
2441
|
+
function selectCurrentRelayBootstrapPosts(posts, options = {}) {
|
|
2442
|
+
const maxAgeMs = options.maxAgeMs ?? DEFAULT_BOOTSTRAP_MAX_AGE_MS;
|
|
2443
|
+
const now = options.now ?? Date.now();
|
|
2444
|
+
const selected = /* @__PURE__ */ new Map();
|
|
2445
|
+
for (const post of posts) {
|
|
2446
|
+
const content = post.content;
|
|
2447
|
+
if (!content) continue;
|
|
2448
|
+
if (now - content.updatedAt > maxAgeMs) continue;
|
|
2449
|
+
const identity = relayBootstrapRecordIdentity(post);
|
|
2450
|
+
if (!identity) continue;
|
|
2451
|
+
const previous = selected.get(identity);
|
|
2452
|
+
if (!previous || compareRelayBootstrapPostRecency(post, previous) > 0) {
|
|
2453
|
+
selected.set(identity, post);
|
|
2454
|
+
}
|
|
2455
|
+
}
|
|
2456
|
+
return [...selected.values()].sort(
|
|
2457
|
+
(left, right) => compareRelayBootstrapPostRecency(right, left)
|
|
2458
|
+
);
|
|
2459
|
+
}
|
|
2404
2460
|
|
|
2405
2461
|
// src/bootstrap-registration.ts
|
|
2406
2462
|
async function publishRelayBootstrapRegistration(args) {
|
|
@@ -2506,6 +2562,311 @@ async function publishRelayBootstrapRegistration(args) {
|
|
|
2506
2562
|
forgetResult
|
|
2507
2563
|
};
|
|
2508
2564
|
}
|
|
2565
|
+
|
|
2566
|
+
// src/bootstrap-config.ts
|
|
2567
|
+
var VM_BOOTSTRAP_CONFIG_AGGREGATE_KEY = "vm-bootstrap-config";
|
|
2568
|
+
async function fetchVmBootstrapConfigAggregate(address, options) {
|
|
2569
|
+
const requestUrl = new URL(`/api/v0/aggregates/${address}.json`, options.apiHost ?? DEFAULT_ALEPH_API_HOST);
|
|
2570
|
+
requestUrl.searchParams.set("keys", VM_BOOTSTRAP_CONFIG_AGGREGATE_KEY);
|
|
2571
|
+
const response = await options.fetch(requestUrl.toString(), { cache: "no-cache" });
|
|
2572
|
+
if (response.status === 404) return {};
|
|
2573
|
+
if (!response.ok) {
|
|
2574
|
+
throw new Error(`VM bootstrap config aggregate request failed: ${response.status}`);
|
|
2575
|
+
}
|
|
2576
|
+
const payload = await response.json();
|
|
2577
|
+
const aggregate = payload.data?.[VM_BOOTSTRAP_CONFIG_AGGREGATE_KEY];
|
|
2578
|
+
if (!aggregate || typeof aggregate !== "object" || Array.isArray(aggregate)) return {};
|
|
2579
|
+
return aggregate;
|
|
2580
|
+
}
|
|
2581
|
+
function normalizeVmBootstrapConfigAggregate(aggregate) {
|
|
2582
|
+
if (!aggregate || typeof aggregate !== "object") return {};
|
|
2583
|
+
return Object.fromEntries(
|
|
2584
|
+
Object.entries(aggregate).filter(
|
|
2585
|
+
(entry) => Boolean(entry[1] && typeof entry[1] === "object" && !Array.isArray(entry[1]))
|
|
2586
|
+
)
|
|
2587
|
+
);
|
|
2588
|
+
}
|
|
2589
|
+
function createVmBootstrapConfigAggregateContent(args) {
|
|
2590
|
+
const content = normalizeVmBootstrapConfigAggregate(args.existingAggregate);
|
|
2591
|
+
content[args.record.deploymentToken] = args.record;
|
|
2592
|
+
return {
|
|
2593
|
+
address: args.sender,
|
|
2594
|
+
key: VM_BOOTSTRAP_CONFIG_AGGREGATE_KEY,
|
|
2595
|
+
content,
|
|
2596
|
+
time: args.now ?? Date.now() / 1e3
|
|
2597
|
+
};
|
|
2598
|
+
}
|
|
2599
|
+
async function createUnsignedVmBootstrapConfigAggregateMessage(args) {
|
|
2600
|
+
const itemContent = JSON.stringify(args.content);
|
|
2601
|
+
const itemHash = await args.hasher(itemContent);
|
|
2602
|
+
return {
|
|
2603
|
+
sender: args.sender,
|
|
2604
|
+
chain: "ETH",
|
|
2605
|
+
type: "AGGREGATE",
|
|
2606
|
+
item_hash: itemHash,
|
|
2607
|
+
item_type: "inline",
|
|
2608
|
+
item_content: itemContent,
|
|
2609
|
+
time: args.now ?? Date.now() / 1e3,
|
|
2610
|
+
channel: args.channel ?? DEFAULT_ALEPH_CHANNEL
|
|
2611
|
+
};
|
|
2612
|
+
}
|
|
2613
|
+
async function publishVmBootstrapConfigAggregate(args) {
|
|
2614
|
+
const unsignedMessage = await createUnsignedVmBootstrapConfigAggregateMessage({
|
|
2615
|
+
sender: args.sender,
|
|
2616
|
+
content: args.content,
|
|
2617
|
+
hasher: args.hasher,
|
|
2618
|
+
channel: args.channel
|
|
2619
|
+
});
|
|
2620
|
+
const message = await signAlephMessage(unsignedMessage, args.signer);
|
|
2621
|
+
const { response, httpStatus } = await broadcastAlephMessage(message, {
|
|
2622
|
+
apiHost: args.apiHost,
|
|
2623
|
+
sync: args.sync,
|
|
2624
|
+
fetch: args.fetch
|
|
2625
|
+
});
|
|
2626
|
+
const aggregateStatus = httpStatus >= 200 && httpStatus < 300 ? response.message_status ?? "processed" : "unknown";
|
|
2627
|
+
if (aggregateStatus === "rejected") {
|
|
2628
|
+
throw new Error(`VM bootstrap config aggregate was rejected by Aleph: ${JSON.stringify(response.details ?? response)}`);
|
|
2629
|
+
}
|
|
2630
|
+
return {
|
|
2631
|
+
aggregateItemHash: message.item_hash,
|
|
2632
|
+
aggregateStatus
|
|
2633
|
+
};
|
|
2634
|
+
}
|
|
2635
|
+
async function publishVmBootstrapConfig(args) {
|
|
2636
|
+
const aggregate = await fetchVmBootstrapConfigAggregate(args.sender, {
|
|
2637
|
+
apiHost: args.apiHost,
|
|
2638
|
+
fetch: args.fetch
|
|
2639
|
+
});
|
|
2640
|
+
const content = createVmBootstrapConfigAggregateContent({
|
|
2641
|
+
sender: args.sender,
|
|
2642
|
+
record: args.record,
|
|
2643
|
+
existingAggregate: aggregate
|
|
2644
|
+
});
|
|
2645
|
+
const result = await publishVmBootstrapConfigAggregate({
|
|
2646
|
+
sender: args.sender,
|
|
2647
|
+
content,
|
|
2648
|
+
signer: args.signer,
|
|
2649
|
+
hasher: args.hasher,
|
|
2650
|
+
fetch: args.fetch,
|
|
2651
|
+
channel: args.channel,
|
|
2652
|
+
apiHost: args.apiHost,
|
|
2653
|
+
sync: args.sync
|
|
2654
|
+
});
|
|
2655
|
+
return {
|
|
2656
|
+
...result,
|
|
2657
|
+
aggregate: content.content
|
|
2658
|
+
};
|
|
2659
|
+
}
|
|
2660
|
+
async function deleteVmBootstrapConfig(args) {
|
|
2661
|
+
const aggregate = await fetchVmBootstrapConfigAggregate(args.sender, {
|
|
2662
|
+
apiHost: args.apiHost,
|
|
2663
|
+
fetch: args.fetch
|
|
2664
|
+
});
|
|
2665
|
+
const content = normalizeVmBootstrapConfigAggregate(aggregate);
|
|
2666
|
+
delete content[args.deploymentToken];
|
|
2667
|
+
const publishResult = await publishVmBootstrapConfigAggregate({
|
|
2668
|
+
sender: args.sender,
|
|
2669
|
+
content: {
|
|
2670
|
+
address: args.sender,
|
|
2671
|
+
key: VM_BOOTSTRAP_CONFIG_AGGREGATE_KEY,
|
|
2672
|
+
content,
|
|
2673
|
+
time: Date.now() / 1e3
|
|
2674
|
+
},
|
|
2675
|
+
signer: args.signer,
|
|
2676
|
+
hasher: args.hasher,
|
|
2677
|
+
fetch: args.fetch,
|
|
2678
|
+
channel: args.channel,
|
|
2679
|
+
apiHost: args.apiHost,
|
|
2680
|
+
sync: args.sync
|
|
2681
|
+
});
|
|
2682
|
+
return {
|
|
2683
|
+
...publishResult,
|
|
2684
|
+
aggregate: content
|
|
2685
|
+
};
|
|
2686
|
+
}
|
|
2687
|
+
|
|
2688
|
+
// src/bootstrap-reconcile.ts
|
|
2689
|
+
function createRelayBootstrapRegistrationId(profile, instanceName, itemHash) {
|
|
2690
|
+
const normalizedName = String(instanceName ?? "").trim();
|
|
2691
|
+
const normalizedHash = String(itemHash ?? "").trim();
|
|
2692
|
+
if (!normalizedHash) {
|
|
2693
|
+
return `relay:${profile}:${normalizedName || "instance"}`;
|
|
2694
|
+
}
|
|
2695
|
+
return `relay:${profile}:${normalizedName || normalizedHash}:${normalizedHash}`;
|
|
2696
|
+
}
|
|
2697
|
+
function secureBootstrapMetadataUrl(proxyUrl) {
|
|
2698
|
+
const normalized = String(proxyUrl ?? "").trim();
|
|
2699
|
+
if (!normalized) return null;
|
|
2700
|
+
try {
|
|
2701
|
+
return new URL("/bootstrap/metadata", normalized).toString();
|
|
2702
|
+
} catch {
|
|
2703
|
+
return null;
|
|
2704
|
+
}
|
|
2705
|
+
}
|
|
2706
|
+
function extractRelayMetadata(payload) {
|
|
2707
|
+
const metadata = payload && typeof payload === "object" && payload.metadata && typeof payload.metadata === "object" ? payload.metadata : null;
|
|
2708
|
+
const peerId = typeof metadata?.peer_id === "string" ? metadata.peer_id : null;
|
|
2709
|
+
const probeMultiaddrs = Array.isArray(metadata?.probe_multiaddrs) ? metadata.probe_multiaddrs.filter((entry) => typeof entry === "string") : [];
|
|
2710
|
+
const browserBootstrapMultiaddrs = Array.isArray(metadata?.browser_bootstrap_multiaddrs) ? metadata.browser_bootstrap_multiaddrs.filter((entry) => typeof entry === "string") : [];
|
|
2711
|
+
if (!peerId || probeMultiaddrs.length === 0) return null;
|
|
2712
|
+
return {
|
|
2713
|
+
peerId,
|
|
2714
|
+
probeMultiaddrs,
|
|
2715
|
+
browserBootstrapMultiaddrs
|
|
2716
|
+
};
|
|
2717
|
+
}
|
|
2718
|
+
async function fetchOwnerInstances(address, options) {
|
|
2719
|
+
const url = new URL("/api/v0/messages.json", options.apiHost ?? DEFAULT_ALEPH_API_HOST);
|
|
2720
|
+
url.searchParams.set("msgTypes", "INSTANCE");
|
|
2721
|
+
url.searchParams.set("addresses", address);
|
|
2722
|
+
url.searchParams.set("message_statuses", "processed,pending,rejected,removing");
|
|
2723
|
+
url.searchParams.set("pagination", "100");
|
|
2724
|
+
url.searchParams.set("page", "1");
|
|
2725
|
+
url.searchParams.set("sortOrder", "-1");
|
|
2726
|
+
const response = await options.fetch(url.toString(), { cache: "no-cache" });
|
|
2727
|
+
if (!response.ok) {
|
|
2728
|
+
throw new Error(`Instance list request failed: ${response.status}`);
|
|
2729
|
+
}
|
|
2730
|
+
const payload = await response.json();
|
|
2731
|
+
return (payload.messages ?? []).map((message) => ({
|
|
2732
|
+
...message,
|
|
2733
|
+
status: typeof message.status === "string" && message.status.trim() ? message.status : message.confirmed ? "processed" : "pending"
|
|
2734
|
+
}));
|
|
2735
|
+
}
|
|
2736
|
+
async function fetchRelayMetadataForRuntime(args) {
|
|
2737
|
+
const setupPort = args.runtime.mappedPorts?.["80"]?.host ?? 80;
|
|
2738
|
+
const metadataUrl = args.preferSecureMetadata ? secureBootstrapMetadataUrl(args.runtime.proxyUrl) : null;
|
|
2739
|
+
if (args.preferSecureMetadata && !metadataUrl) {
|
|
2740
|
+
return null;
|
|
2741
|
+
}
|
|
2742
|
+
const payload = await fetchUcGoPeerMetadata({
|
|
2743
|
+
hostIpv4: args.runtime.hostIpv4 ?? "",
|
|
2744
|
+
setupPort,
|
|
2745
|
+
metadataUrl,
|
|
2746
|
+
fetch: args.fetch,
|
|
2747
|
+
attempts: args.attempts,
|
|
2748
|
+
delayMs: args.delayMs,
|
|
2749
|
+
timeoutMs: args.timeoutMs
|
|
2750
|
+
}).catch(() => null);
|
|
2751
|
+
return extractRelayMetadata(payload);
|
|
2752
|
+
}
|
|
2753
|
+
async function reconcileOwnerRelayBootstrapRegistrations(args) {
|
|
2754
|
+
const result = {
|
|
2755
|
+
refreshedRegistrations: [],
|
|
2756
|
+
forgottenHashes: [],
|
|
2757
|
+
skippedInstanceHashes: [],
|
|
2758
|
+
errors: []
|
|
2759
|
+
};
|
|
2760
|
+
const liveRegistrationIds = /* @__PURE__ */ new Set();
|
|
2761
|
+
if (args.current?.registrationId) {
|
|
2762
|
+
liveRegistrationIds.add(args.current.registrationId);
|
|
2763
|
+
result.refreshedRegistrations.push(args.current.registrationId);
|
|
2764
|
+
}
|
|
2765
|
+
const instances = await fetchOwnerInstances(args.instanceOwnerAddress, {
|
|
2766
|
+
apiHost: args.apiHost,
|
|
2767
|
+
fetch: args.fetch
|
|
2768
|
+
});
|
|
2769
|
+
const processedInstances = instances.filter((instance) => {
|
|
2770
|
+
const status = String(instance.status ?? "").trim().toLowerCase();
|
|
2771
|
+
return status === "processed";
|
|
2772
|
+
});
|
|
2773
|
+
for (const instance of processedInstances) {
|
|
2774
|
+
if (instance.item_hash === args.current?.itemHash) continue;
|
|
2775
|
+
const registrationId = createRelayBootstrapRegistrationId(
|
|
2776
|
+
args.profile,
|
|
2777
|
+
instance.content?.metadata?.name,
|
|
2778
|
+
instance.item_hash
|
|
2779
|
+
);
|
|
2780
|
+
try {
|
|
2781
|
+
const runtime = await fetchVmRuntime({
|
|
2782
|
+
itemHash: instance.item_hash,
|
|
2783
|
+
fetch: args.fetch,
|
|
2784
|
+
crns: args.crns,
|
|
2785
|
+
crnListUrl: args.crnListUrl
|
|
2786
|
+
});
|
|
2787
|
+
if (!runtime.hostIpv4 || Object.keys(runtime.mappedPorts ?? {}).length === 0) {
|
|
2788
|
+
result.skippedInstanceHashes.push(instance.item_hash);
|
|
2789
|
+
continue;
|
|
2790
|
+
}
|
|
2791
|
+
const relayMetadata = await fetchRelayMetadataForRuntime({
|
|
2792
|
+
runtime,
|
|
2793
|
+
fetch: args.fetch,
|
|
2794
|
+
preferSecureMetadata: args.preferSecureMetadata,
|
|
2795
|
+
attempts: 3,
|
|
2796
|
+
delayMs: 1e3,
|
|
2797
|
+
timeoutMs: 1e4
|
|
2798
|
+
});
|
|
2799
|
+
if (!relayMetadata) {
|
|
2800
|
+
result.skippedInstanceHashes.push(instance.item_hash);
|
|
2801
|
+
continue;
|
|
2802
|
+
}
|
|
2803
|
+
liveRegistrationIds.add(registrationId);
|
|
2804
|
+
await publishRelayBootstrapRegistration({
|
|
2805
|
+
sender: args.sender,
|
|
2806
|
+
signer: args.signer,
|
|
2807
|
+
hasher: args.hasher,
|
|
2808
|
+
fetch: args.fetch,
|
|
2809
|
+
apiHost: args.apiHost,
|
|
2810
|
+
channel: args.channel,
|
|
2811
|
+
ref: args.ref,
|
|
2812
|
+
postType: args.postType,
|
|
2813
|
+
peerId: relayMetadata.peerId,
|
|
2814
|
+
multiaddrs: relayMetadata.probeMultiaddrs,
|
|
2815
|
+
browserMultiaddrs: relayMetadata.browserBootstrapMultiaddrs,
|
|
2816
|
+
registrationId,
|
|
2817
|
+
ownerAddress: args.ownerAddress,
|
|
2818
|
+
publisherAddress: args.publisherAddress,
|
|
2819
|
+
ownerSigner: args.ownerSigner,
|
|
2820
|
+
publisherSigner: args.publisherSigner,
|
|
2821
|
+
forgetPrevious: true,
|
|
2822
|
+
profile: args.profile,
|
|
2823
|
+
version: args.version,
|
|
2824
|
+
instanceItemHash: instance.item_hash,
|
|
2825
|
+
sync: true
|
|
2826
|
+
});
|
|
2827
|
+
result.refreshedRegistrations.push(registrationId);
|
|
2828
|
+
} catch (error) {
|
|
2829
|
+
result.errors.push({
|
|
2830
|
+
phase: "publish",
|
|
2831
|
+
itemHash: instance.item_hash,
|
|
2832
|
+
registrationId,
|
|
2833
|
+
message: error instanceof Error ? error.message : String(error)
|
|
2834
|
+
});
|
|
2835
|
+
}
|
|
2836
|
+
}
|
|
2837
|
+
try {
|
|
2838
|
+
const bootstrapPosts = await fetchAlephBootstrapPosts({
|
|
2839
|
+
apiHost: args.apiHost ?? DEFAULT_ALEPH_API_HOST,
|
|
2840
|
+
channel: args.channel,
|
|
2841
|
+
ref: args.ref,
|
|
2842
|
+
postType: args.postType,
|
|
2843
|
+
fetch: args.fetch
|
|
2844
|
+
});
|
|
2845
|
+
const currentPosts = selectCurrentRelayBootstrapPosts(bootstrapPosts);
|
|
2846
|
+
const staleHashes = currentPosts.filter(
|
|
2847
|
+
(post) => post.address?.toLowerCase() === args.sender.toLowerCase() && post.content?.profile === args.profile && post.content?.registrationId && !liveRegistrationIds.has(post.content.registrationId)
|
|
2848
|
+
).map((post) => post.itemHash ?? post.hash ?? "").filter(Boolean);
|
|
2849
|
+
if (staleHashes.length > 0) {
|
|
2850
|
+
await forgetAlephMessages({
|
|
2851
|
+
sender: args.sender,
|
|
2852
|
+
hashes: staleHashes,
|
|
2853
|
+
reason: `Forget stale ${args.profile} relay bootstrap registrations after owner reconcile`,
|
|
2854
|
+
signer: args.signer,
|
|
2855
|
+
hasher: args.hasher,
|
|
2856
|
+
fetch: args.fetch,
|
|
2857
|
+
apiHost: args.apiHost ?? DEFAULT_ALEPH_API_HOST,
|
|
2858
|
+
sync: true
|
|
2859
|
+
});
|
|
2860
|
+
result.forgottenHashes.push(...staleHashes);
|
|
2861
|
+
}
|
|
2862
|
+
} catch (error) {
|
|
2863
|
+
result.errors.push({
|
|
2864
|
+
phase: "forget",
|
|
2865
|
+
message: error instanceof Error ? error.message : String(error)
|
|
2866
|
+
});
|
|
2867
|
+
}
|
|
2868
|
+
return result;
|
|
2869
|
+
}
|
|
2509
2870
|
export {
|
|
2510
2871
|
DEFAULT_ALEPH_API_HOST,
|
|
2511
2872
|
DEFAULT_ALEPH_CHANNEL,
|
|
@@ -2519,18 +2880,24 @@ export {
|
|
|
2519
2880
|
ITEM_HASH_RE,
|
|
2520
2881
|
SSH_PUBLIC_KEY_PATTERN,
|
|
2521
2882
|
SUCCESSFUL_DEPLOYMENTS_AGGREGATE_KEY,
|
|
2883
|
+
VM_BOOTSTRAP_CONFIG_AGGREGATE_KEY,
|
|
2884
|
+
appendDeploymentTokenToSshPublicKey,
|
|
2522
2885
|
broadcastAlephMessage,
|
|
2523
2886
|
buildPaymentQuote,
|
|
2524
2887
|
cleanupFailedDeployment,
|
|
2525
2888
|
configureOrbitdbRelaySetup,
|
|
2526
2889
|
configureUcGoPeer,
|
|
2527
2890
|
createDeploymentIntent,
|
|
2891
|
+
createDeploymentToken,
|
|
2528
2892
|
createInstanceContent,
|
|
2529
2893
|
createPortForwardAggregateContent,
|
|
2894
|
+
createRelayBootstrapRegistrationId,
|
|
2530
2895
|
createReleaseMetadata,
|
|
2531
2896
|
createUnsignedAggregateMessage2 as createUnsignedAggregateMessage,
|
|
2532
2897
|
createUnsignedForgetMessage,
|
|
2533
2898
|
createUnsignedInstanceMessage,
|
|
2899
|
+
createVmBootstrapConfigAggregateContent,
|
|
2900
|
+
deleteVmBootstrapConfig,
|
|
2534
2901
|
deployInstance,
|
|
2535
2902
|
describeRejectedDeployment,
|
|
2536
2903
|
describeRuntimeAvailability,
|
|
@@ -2545,8 +2912,10 @@ export {
|
|
|
2545
2912
|
fetchCrns,
|
|
2546
2913
|
fetchMessageEnvelope,
|
|
2547
2914
|
fetchPortForwardAggregate,
|
|
2915
|
+
fetchRelayMetadataForRuntime,
|
|
2548
2916
|
fetchSchedulerAllocation,
|
|
2549
2917
|
fetchUcGoPeerMetadata,
|
|
2918
|
+
fetchVmBootstrapConfigAggregate,
|
|
2550
2919
|
fetchVmRuntime,
|
|
2551
2920
|
filterDeployableCrns,
|
|
2552
2921
|
findCrnByHash,
|
|
@@ -2573,8 +2942,10 @@ export {
|
|
|
2573
2942
|
probeRootfsGateway,
|
|
2574
2943
|
publishAggregateKey,
|
|
2575
2944
|
publishRelayBootstrapRegistration,
|
|
2945
|
+
publishVmBootstrapConfig,
|
|
2576
2946
|
quoteRequiredBudgetUnits,
|
|
2577
2947
|
rankCandidateCrns,
|
|
2948
|
+
reconcileOwnerRelayBootstrapRegistrations,
|
|
2578
2949
|
requestedPortFlags,
|
|
2579
2950
|
requiredInstancePortForwards,
|
|
2580
2951
|
resolveRootfsReference,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@le-space/core",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.12",
|
|
4
4
|
"description": "Reusable Aleph deployment, runtime, and guest lifecycle logic.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"access": "public"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@le-space/aleph-bootstrap": "0.3.
|
|
20
|
-
"@le-space/shared-types": "0.3.
|
|
19
|
+
"@le-space/aleph-bootstrap": "0.3.12",
|
|
20
|
+
"@le-space/shared-types": "0.3.12"
|
|
21
21
|
}
|
|
22
22
|
}
|