@le-space/shared-types 0.6.1 → 0.6.2
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 +20 -1
- package/index.js +122 -0
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -326,4 +326,23 @@ interface VmBootstrapConfigSignalRecord {
|
|
|
326
326
|
browserBootstrapMultiaddrs?: string[];
|
|
327
327
|
}
|
|
328
328
|
|
|
329
|
-
|
|
329
|
+
interface UcanStoreBootstrapPackage {
|
|
330
|
+
operatorAddress: string;
|
|
331
|
+
adminDid: string;
|
|
332
|
+
serviceDid?: string | null;
|
|
333
|
+
spaceDid: string;
|
|
334
|
+
rootDelegationProof: string;
|
|
335
|
+
allowedCapabilities: string[];
|
|
336
|
+
defaultUserDelegationExpiration?: number | null;
|
|
337
|
+
maxUserDelegationExpiration?: number | null;
|
|
338
|
+
pwaOrigin: string;
|
|
339
|
+
serviceOrigin: string;
|
|
340
|
+
}
|
|
341
|
+
interface UcanStoreBootstrapValidationResult {
|
|
342
|
+
valid: boolean;
|
|
343
|
+
errors: string[];
|
|
344
|
+
bootstrapPackage: UcanStoreBootstrapPackage | null;
|
|
345
|
+
}
|
|
346
|
+
declare function validateUcanStoreBootstrapPackage(value: unknown): UcanStoreBootstrapValidationResult;
|
|
347
|
+
|
|
348
|
+
export { type AlephAggregateContent, type AlephBroadcastMessage, type AlephBroadcastResponse, type AlephInstanceContent, type AlephMessageType, type AlephSenderChain, type CrnRecord, type CrnSystemUsage, type DeploymentInspectionResult, type DeploymentIntent, type DeploymentIntentEnvelope, type DeploymentProgressEvent, type DeploymentProgressListener, type DeploymentProgressStage, type DeploymentResult, type GatewayProbeStatus, type InstanceAllocation, type InstanceAllocationNode, type InstanceAllocationPeriod, type InstanceExecution, type InstanceExecutionNetworking, type InstanceExecutionStatus, type InstanceRuntimeDetails, type InstanceWebAccess, type MessageHasher, type MessageInspectionResult, type MessageReference, type MessageSigner, type MessageStatus, type PortForwardAggregate, type PortForwardAggregateEntry, type PortForwardFlags, type PortMapping, type ReferenceStatus, type RootfsInstallStrategy, type RootfsManifest, type RootfsManifestState, type RootfsRequiredPortForward, type RootfsResolution, type RuntimeDiagnostics, type RuntimeMetadata, type UcanStoreBootstrapPackage, type UcanStoreBootstrapValidationResult, type VmBootstrapConfigAggregate, type VmBootstrapConfigBootstrap, type VmBootstrapConfigRecord, type VmBootstrapConfigRuntime, type VmBootstrapConfigSignalRecord, type VmBootstrapConfigSignalType, type VmBootstrapConfigStatus, validateUcanStoreBootstrapPackage };
|
package/index.js
CHANGED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// src/ucan-store-bootstrap.ts
|
|
2
|
+
function isRecord(value) {
|
|
3
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
4
|
+
}
|
|
5
|
+
function normalizeNonEmptyString(value) {
|
|
6
|
+
if (typeof value !== "string") return null;
|
|
7
|
+
const normalized = value.trim();
|
|
8
|
+
return normalized ? normalized : null;
|
|
9
|
+
}
|
|
10
|
+
function normalizeDid(value) {
|
|
11
|
+
const did = normalizeNonEmptyString(value);
|
|
12
|
+
return did && did.startsWith("did:") ? did : null;
|
|
13
|
+
}
|
|
14
|
+
function normalizeOrigin(value) {
|
|
15
|
+
const raw = normalizeNonEmptyString(value);
|
|
16
|
+
if (!raw) return null;
|
|
17
|
+
try {
|
|
18
|
+
const parsed = new URL(raw);
|
|
19
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:" || !parsed.hostname || parsed.pathname && parsed.pathname !== "/" || parsed.search || parsed.hash) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
return parsed.origin;
|
|
23
|
+
} catch {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function normalizeExpiration(value) {
|
|
28
|
+
if (value == null) return void 0;
|
|
29
|
+
if (value === null) return null;
|
|
30
|
+
if (!Number.isInteger(value) || Number(value) < 0) return void 0;
|
|
31
|
+
return Number(value);
|
|
32
|
+
}
|
|
33
|
+
function validateUcanStoreBootstrapPackage(value) {
|
|
34
|
+
if (!isRecord(value)) {
|
|
35
|
+
return {
|
|
36
|
+
valid: false,
|
|
37
|
+
errors: ["Bootstrap package must be a JSON object."],
|
|
38
|
+
bootstrapPackage: null
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const errors = [];
|
|
42
|
+
const operatorAddress = normalizeNonEmptyString(value.operatorAddress);
|
|
43
|
+
if (!operatorAddress || !/^0x[a-fA-F0-9]{40}$/.test(operatorAddress)) {
|
|
44
|
+
errors.push("operatorAddress must be a 0x-prefixed 20-byte Ethereum address.");
|
|
45
|
+
}
|
|
46
|
+
const adminDid = normalizeDid(value.adminDid);
|
|
47
|
+
if (!adminDid) {
|
|
48
|
+
errors.push("adminDid must be a non-empty DID string.");
|
|
49
|
+
}
|
|
50
|
+
const serviceDidRaw = value.serviceDid;
|
|
51
|
+
const serviceDid = serviceDidRaw == null || serviceDidRaw === "" ? null : normalizeDid(serviceDidRaw);
|
|
52
|
+
if (serviceDidRaw != null && serviceDidRaw !== "" && !serviceDid) {
|
|
53
|
+
errors.push("serviceDid must be empty or a non-empty DID string.");
|
|
54
|
+
}
|
|
55
|
+
const spaceDid = normalizeDid(value.spaceDid);
|
|
56
|
+
if (!spaceDid) {
|
|
57
|
+
errors.push("spaceDid must be a non-empty DID string.");
|
|
58
|
+
}
|
|
59
|
+
const rootDelegationProof = normalizeNonEmptyString(value.rootDelegationProof);
|
|
60
|
+
if (!rootDelegationProof) {
|
|
61
|
+
errors.push("rootDelegationProof must be a non-empty proof string.");
|
|
62
|
+
}
|
|
63
|
+
const allowedCapabilities = Array.isArray(value.allowedCapabilities) ? value.allowedCapabilities.map((entry) => normalizeNonEmptyString(entry)).filter((entry) => Boolean(entry)) : [];
|
|
64
|
+
if (allowedCapabilities.length === 0) {
|
|
65
|
+
errors.push("allowedCapabilities must contain at least one capability string.");
|
|
66
|
+
}
|
|
67
|
+
const defaultUserDelegationExpiration = normalizeExpiration(
|
|
68
|
+
value.defaultUserDelegationExpiration
|
|
69
|
+
);
|
|
70
|
+
if (value.defaultUserDelegationExpiration != null && defaultUserDelegationExpiration === void 0) {
|
|
71
|
+
errors.push(
|
|
72
|
+
"defaultUserDelegationExpiration must be null or a non-negative integer number of seconds."
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
const maxUserDelegationExpiration = normalizeExpiration(
|
|
76
|
+
value.maxUserDelegationExpiration
|
|
77
|
+
);
|
|
78
|
+
if (value.maxUserDelegationExpiration != null && maxUserDelegationExpiration === void 0) {
|
|
79
|
+
errors.push(
|
|
80
|
+
"maxUserDelegationExpiration must be null or a non-negative integer number of seconds."
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
if (typeof defaultUserDelegationExpiration === "number" && typeof maxUserDelegationExpiration === "number" && defaultUserDelegationExpiration > maxUserDelegationExpiration) {
|
|
84
|
+
errors.push(
|
|
85
|
+
"defaultUserDelegationExpiration cannot exceed maxUserDelegationExpiration."
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
const pwaOrigin = normalizeOrigin(value.pwaOrigin);
|
|
89
|
+
if (!pwaOrigin) {
|
|
90
|
+
errors.push("pwaOrigin must be an http(s) origin without path, query, or hash.");
|
|
91
|
+
}
|
|
92
|
+
const serviceOrigin = normalizeOrigin(value.serviceOrigin);
|
|
93
|
+
if (!serviceOrigin) {
|
|
94
|
+
errors.push("serviceOrigin must be an http(s) origin without path, query, or hash.");
|
|
95
|
+
}
|
|
96
|
+
if (errors.length > 0) {
|
|
97
|
+
return {
|
|
98
|
+
valid: false,
|
|
99
|
+
errors,
|
|
100
|
+
bootstrapPackage: null
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
valid: true,
|
|
105
|
+
errors: [],
|
|
106
|
+
bootstrapPackage: {
|
|
107
|
+
operatorAddress,
|
|
108
|
+
adminDid,
|
|
109
|
+
serviceDid,
|
|
110
|
+
spaceDid,
|
|
111
|
+
rootDelegationProof,
|
|
112
|
+
allowedCapabilities,
|
|
113
|
+
defaultUserDelegationExpiration,
|
|
114
|
+
maxUserDelegationExpiration,
|
|
115
|
+
pwaOrigin,
|
|
116
|
+
serviceOrigin
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
export {
|
|
121
|
+
validateUcanStoreBootstrapPackage
|
|
122
|
+
};
|