space-data-module-sdk 0.1.0 → 0.2.5
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/LICENSE +190 -0
- package/README.md +236 -73
- package/bin/space-data-module.js +24 -0
- package/package.json +16 -4
- package/schemas/ModuleBundle.fbs +108 -0
- package/schemas/PluginInvokeRequest.fbs +18 -0
- package/schemas/PluginInvokeResponse.fbs +30 -0
- package/schemas/PluginManifest.fbs +33 -1
- package/schemas/TypedArenaBuffer.fbs +23 -2
- package/src/bundle/codec.js +268 -0
- package/src/bundle/constants.js +8 -0
- package/src/bundle/index.js +3 -0
- package/src/bundle/wasm.js +447 -0
- package/src/compiler/compileModule.js +353 -37
- package/src/compiler/emceptionNode.js +217 -0
- package/src/compiler/flatcSupport.js +66 -0
- package/src/compiler/invokeGlue.js +884 -0
- package/src/compliance/pluginCompliance.js +575 -1
- package/src/generated/orbpro/invoke/plugin-invoke-request.d.ts +51 -0
- package/src/generated/orbpro/invoke/plugin-invoke-request.d.ts.map +1 -0
- package/src/generated/orbpro/invoke/plugin-invoke-request.js +131 -0
- package/src/generated/orbpro/invoke/plugin-invoke-request.js.map +1 -0
- package/src/generated/orbpro/invoke/plugin-invoke-request.ts +173 -0
- package/src/generated/orbpro/invoke/plugin-invoke-response.d.ts +76 -0
- package/src/generated/orbpro/invoke/plugin-invoke-response.d.ts.map +1 -0
- package/src/generated/orbpro/invoke/plugin-invoke-response.js +184 -0
- package/src/generated/orbpro/invoke/plugin-invoke-response.js.map +1 -0
- package/src/generated/orbpro/invoke/plugin-invoke-response.ts +243 -0
- package/src/generated/orbpro/invoke.d.ts +3 -0
- package/src/generated/orbpro/invoke.d.ts.map +1 -0
- package/src/generated/orbpro/invoke.js +5 -0
- package/src/generated/orbpro/invoke.js.map +1 -0
- package/src/generated/orbpro/invoke.ts +6 -0
- package/src/generated/orbpro/manifest/accepted-type-set.d.ts +4 -4
- package/src/generated/orbpro/manifest/accepted-type-set.d.ts.map +1 -1
- package/src/generated/orbpro/manifest/accepted-type-set.js +18 -11
- package/src/generated/orbpro/manifest/accepted-type-set.js.map +1 -1
- package/src/generated/orbpro/manifest/build-artifact.d.ts +1 -1
- package/src/generated/orbpro/manifest/build-artifact.d.ts.map +1 -1
- package/src/generated/orbpro/manifest/build-artifact.js +28 -15
- package/src/generated/orbpro/manifest/build-artifact.js.map +1 -1
- package/src/generated/orbpro/manifest/capability-kind.d.ts +26 -1
- package/src/generated/orbpro/manifest/capability-kind.d.ts.map +1 -1
- package/src/generated/orbpro/manifest/capability-kind.js +25 -0
- package/src/generated/orbpro/manifest/capability-kind.js.map +1 -1
- package/src/generated/orbpro/manifest/capability-kind.ts +25 -0
- package/src/generated/orbpro/manifest/drain-policy.d.ts.map +1 -1
- package/src/generated/orbpro/manifest/drain-policy.js.map +1 -1
- package/src/generated/orbpro/manifest/host-capability.d.ts +2 -2
- package/src/generated/orbpro/manifest/host-capability.d.ts.map +1 -1
- package/src/generated/orbpro/manifest/host-capability.js +19 -11
- package/src/generated/orbpro/manifest/host-capability.js.map +1 -1
- package/src/generated/orbpro/manifest/invoke-surface.d.ts +8 -0
- package/src/generated/orbpro/manifest/invoke-surface.d.ts.map +1 -0
- package/src/generated/orbpro/manifest/invoke-surface.js +11 -0
- package/src/generated/orbpro/manifest/invoke-surface.js.map +1 -0
- package/src/generated/orbpro/manifest/invoke-surface.ts +11 -0
- package/src/generated/orbpro/manifest/method-manifest.d.ts +6 -6
- package/src/generated/orbpro/manifest/method-manifest.d.ts.map +1 -1
- package/src/generated/orbpro/manifest/method-manifest.js +33 -16
- package/src/generated/orbpro/manifest/method-manifest.js.map +1 -1
- package/src/generated/orbpro/manifest/plugin-family.d.ts.map +1 -1
- package/src/generated/orbpro/manifest/plugin-family.js.map +1 -1
- package/src/generated/orbpro/manifest/plugin-manifest.d.ts +10 -2
- package/src/generated/orbpro/manifest/plugin-manifest.d.ts.map +1 -1
- package/src/generated/orbpro/manifest/plugin-manifest.js +48 -9
- package/src/generated/orbpro/manifest/plugin-manifest.js.map +1 -1
- package/src/generated/orbpro/manifest/plugin-manifest.ts +322 -491
- package/src/generated/orbpro/manifest/port-manifest.d.ts +4 -4
- package/src/generated/orbpro/manifest/port-manifest.d.ts.map +1 -1
- package/src/generated/orbpro/manifest/port-manifest.js +26 -13
- package/src/generated/orbpro/manifest/port-manifest.js.map +1 -1
- package/src/generated/orbpro/manifest/protocol-spec.d.ts +1 -1
- package/src/generated/orbpro/manifest/protocol-spec.d.ts.map +1 -1
- package/src/generated/orbpro/manifest/protocol-spec.js +28 -15
- package/src/generated/orbpro/manifest/protocol-spec.js.map +1 -1
- package/src/generated/orbpro/manifest/timer-spec.d.ts +1 -1
- package/src/generated/orbpro/manifest/timer-spec.d.ts.map +1 -1
- package/src/generated/orbpro/manifest/timer-spec.js +27 -16
- package/src/generated/orbpro/manifest/timer-spec.js.map +1 -1
- package/src/generated/orbpro/manifest.d.ts +13 -0
- package/src/generated/orbpro/manifest.d.ts.map +1 -0
- package/src/generated/orbpro/manifest.js +1 -0
- package/src/generated/orbpro/manifest.js.map +1 -0
- package/src/generated/orbpro/manifest.ts +16 -0
- package/src/generated/orbpro/module/canonicalization-rule.d.ts +48 -0
- package/src/generated/orbpro/module/canonicalization-rule.js +95 -0
- package/src/generated/orbpro/module/canonicalization-rule.ts +142 -0
- package/src/generated/orbpro/module/module-bundle-entry-role.d.ts +11 -0
- package/src/generated/orbpro/module/module-bundle-entry-role.js +14 -0
- package/src/generated/orbpro/module/module-bundle-entry-role.ts +15 -0
- package/src/generated/orbpro/module/module-bundle-entry.d.ts +97 -0
- package/src/generated/orbpro/module/module-bundle-entry.js +219 -0
- package/src/generated/orbpro/module/module-bundle-entry.ts +287 -0
- package/src/generated/orbpro/module/module-bundle.d.ts +86 -0
- package/src/generated/orbpro/module/module-bundle.js +213 -0
- package/src/generated/orbpro/module/module-bundle.ts +277 -0
- package/src/generated/orbpro/module/module-payload-encoding.d.ts +9 -0
- package/src/generated/orbpro/module/module-payload-encoding.js +12 -0
- package/src/generated/orbpro/module/module-payload-encoding.ts +13 -0
- package/src/generated/orbpro/module.d.ts +5 -0
- package/src/generated/orbpro/module.js +7 -0
- package/src/generated/orbpro/module.ts +9 -0
- package/src/generated/orbpro/stream/buffer-mutability.d.ts.map +1 -1
- package/src/generated/orbpro/stream/buffer-mutability.js.map +1 -1
- package/src/generated/orbpro/stream/buffer-ownership.d.ts.map +1 -1
- package/src/generated/orbpro/stream/buffer-ownership.js.map +1 -1
- package/src/generated/orbpro/stream/flat-buffer-type-ref.d.ts +22 -5
- package/src/generated/orbpro/stream/flat-buffer-type-ref.d.ts.map +1 -1
- package/src/generated/orbpro/stream/flat-buffer-type-ref.js +107 -17
- package/src/generated/orbpro/stream/flat-buffer-type-ref.js.map +1 -1
- package/src/generated/orbpro/stream/flat-buffer-type-ref.ts +126 -2
- package/src/generated/orbpro/stream/payload-wire-format.d.ts +8 -0
- package/src/generated/orbpro/stream/payload-wire-format.d.ts.map +1 -0
- package/src/generated/orbpro/stream/payload-wire-format.js +11 -0
- package/src/generated/orbpro/stream/payload-wire-format.js.map +1 -0
- package/src/generated/orbpro/stream/payload-wire-format.ts +11 -0
- package/src/generated/orbpro/stream/typed-arena-buffer.d.ts +4 -4
- package/src/generated/orbpro/stream/typed-arena-buffer.d.ts.map +1 -1
- package/src/generated/orbpro/stream/typed-arena-buffer.js +42 -24
- package/src/generated/orbpro/stream/typed-arena-buffer.js.map +1 -1
- package/src/host/abi.js +282 -0
- package/src/host/cron.js +247 -0
- package/src/host/index.js +3 -0
- package/src/host/nodeHost.js +2165 -0
- package/src/index.d.ts +958 -0
- package/src/index.js +12 -2
- package/src/invoke/codec.js +278 -0
- package/src/invoke/index.js +9 -0
- package/src/manifest/codec.js +10 -2
- package/src/manifest/index.js +5 -2
- package/src/manifest/normalize.js +90 -1
- package/src/runtime/constants.js +29 -0
- package/src/transport/pki.js +0 -5
- package/src/utils/encoding.js +9 -1
- package/src/utils/wasmCrypto.js +49 -1
package/src/index.js
CHANGED
|
@@ -3,6 +3,16 @@ export * from "./compliance/index.js";
|
|
|
3
3
|
export * from "./auth/index.js";
|
|
4
4
|
export * from "./transport/index.js";
|
|
5
5
|
export * from "./compiler/index.js";
|
|
6
|
+
export * from "./bundle/index.js";
|
|
6
7
|
export * from "./standards/index.js";
|
|
7
|
-
export
|
|
8
|
-
|
|
8
|
+
export * from "./host/index.js";
|
|
9
|
+
export * from "./invoke/index.js";
|
|
10
|
+
export {
|
|
11
|
+
DefaultInvokeExports,
|
|
12
|
+
DefaultManifestExports,
|
|
13
|
+
DrainPolicy,
|
|
14
|
+
ExternalInterfaceDirection,
|
|
15
|
+
ExternalInterfaceKind,
|
|
16
|
+
InvokeSurface,
|
|
17
|
+
RuntimeTarget,
|
|
18
|
+
} from "./runtime/constants.js";
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import * as flatbuffers from "flatbuffers";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
PluginInvokeRequest,
|
|
5
|
+
PluginInvokeRequestT,
|
|
6
|
+
} from "../generated/orbpro/invoke/plugin-invoke-request.js";
|
|
7
|
+
import {
|
|
8
|
+
PluginInvokeResponse,
|
|
9
|
+
PluginInvokeResponseT,
|
|
10
|
+
} from "../generated/orbpro/invoke/plugin-invoke-response.js";
|
|
11
|
+
import { InvokeSurface } from "../generated/orbpro/manifest/invoke-surface.js";
|
|
12
|
+
import { BufferMutability } from "../generated/orbpro/stream/buffer-mutability.js";
|
|
13
|
+
import { BufferOwnership } from "../generated/orbpro/stream/buffer-ownership.js";
|
|
14
|
+
import { FlatBufferTypeRefT } from "../generated/orbpro/stream/flat-buffer-type-ref.js";
|
|
15
|
+
import { TypedArenaBuffer, TypedArenaBufferT } from "../generated/orbpro/stream/typed-arena-buffer.js";
|
|
16
|
+
import { toUint8Array } from "../runtime/bufferLike.js";
|
|
17
|
+
|
|
18
|
+
function toByteBuffer(data) {
|
|
19
|
+
if (data instanceof flatbuffers.ByteBuffer) {
|
|
20
|
+
return data;
|
|
21
|
+
}
|
|
22
|
+
const bytes = toUint8Array(data);
|
|
23
|
+
if (bytes) {
|
|
24
|
+
return new flatbuffers.ByteBuffer(bytes);
|
|
25
|
+
}
|
|
26
|
+
throw new TypeError(
|
|
27
|
+
"Expected ByteBuffer, Uint8Array, ArrayBufferView, or ArrayBuffer.",
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function normalizeSchemaHash(value) {
|
|
32
|
+
if (!value) {
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
if (value instanceof Uint8Array) {
|
|
36
|
+
return Array.from(value);
|
|
37
|
+
}
|
|
38
|
+
if (ArrayBuffer.isView(value)) {
|
|
39
|
+
return Array.from(new Uint8Array(value.buffer, value.byteOffset, value.byteLength));
|
|
40
|
+
}
|
|
41
|
+
if (Array.isArray(value)) {
|
|
42
|
+
return value.map((byte) => Number(byte) & 0xff);
|
|
43
|
+
}
|
|
44
|
+
const normalized = String(value).trim().replace(/^0x/i, "");
|
|
45
|
+
if (!normalized || normalized.length % 2 !== 0) {
|
|
46
|
+
return [];
|
|
47
|
+
}
|
|
48
|
+
const bytes = [];
|
|
49
|
+
for (let index = 0; index < normalized.length; index += 2) {
|
|
50
|
+
bytes.push(parseInt(normalized.slice(index, index + 2), 16));
|
|
51
|
+
}
|
|
52
|
+
return bytes;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function normalizeUnsignedInteger(value, fallback = 0) {
|
|
56
|
+
const normalized = Number(value ?? fallback);
|
|
57
|
+
if (!Number.isFinite(normalized)) {
|
|
58
|
+
return fallback;
|
|
59
|
+
}
|
|
60
|
+
return Math.max(0, Math.trunc(normalized));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function normalizeBigInt(value, fallback = BigInt(0)) {
|
|
64
|
+
if (typeof value === "bigint") {
|
|
65
|
+
return value;
|
|
66
|
+
}
|
|
67
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
68
|
+
return BigInt(Math.trunc(value));
|
|
69
|
+
}
|
|
70
|
+
if (typeof value === "string" && value.trim()) {
|
|
71
|
+
try {
|
|
72
|
+
return BigInt(value.trim());
|
|
73
|
+
} catch {
|
|
74
|
+
return fallback;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return fallback;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function normalizePayloadWireFormat(value) {
|
|
81
|
+
if (value === 1 || value === "aligned-binary") {
|
|
82
|
+
return "aligned-binary";
|
|
83
|
+
}
|
|
84
|
+
return "flatbuffer";
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function toFlatBufferTypeRefT(value = {}, payloadLength = 0) {
|
|
88
|
+
if (value instanceof FlatBufferTypeRefT) {
|
|
89
|
+
return value;
|
|
90
|
+
}
|
|
91
|
+
const wireFormat = normalizePayloadWireFormat(value.wireFormat);
|
|
92
|
+
const requiredAlignment = normalizeUnsignedInteger(value.requiredAlignment);
|
|
93
|
+
const fixedStringLength = normalizeUnsignedInteger(value.fixedStringLength);
|
|
94
|
+
const byteLength =
|
|
95
|
+
wireFormat === "aligned-binary"
|
|
96
|
+
? normalizeUnsignedInteger(value.byteLength, payloadLength)
|
|
97
|
+
: normalizeUnsignedInteger(value.byteLength);
|
|
98
|
+
return new FlatBufferTypeRefT(
|
|
99
|
+
value.schemaName ?? null,
|
|
100
|
+
value.fileIdentifier ?? null,
|
|
101
|
+
normalizeSchemaHash(value.schemaHash),
|
|
102
|
+
value.acceptsAnyFlatbuffer === true,
|
|
103
|
+
wireFormat,
|
|
104
|
+
value.rootTypeName ?? null,
|
|
105
|
+
fixedStringLength,
|
|
106
|
+
byteLength,
|
|
107
|
+
requiredAlignment,
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function alignOffset(offset, alignment) {
|
|
112
|
+
if (alignment <= 1) {
|
|
113
|
+
return offset;
|
|
114
|
+
}
|
|
115
|
+
const remainder = offset % alignment;
|
|
116
|
+
return remainder === 0 ? offset : offset + alignment - remainder;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function normalizeArenaFrame(frame = {}, offset) {
|
|
120
|
+
const payload = toUint8Array(frame.payload ?? new Uint8Array()) ?? new Uint8Array();
|
|
121
|
+
const typeRef = toFlatBufferTypeRefT(frame.typeRef ?? frame.allowedType ?? {}, payload.length);
|
|
122
|
+
const alignment = Math.max(
|
|
123
|
+
1,
|
|
124
|
+
normalizeUnsignedInteger(
|
|
125
|
+
frame.alignment,
|
|
126
|
+
typeRef.requiredAlignment > 0 ? typeRef.requiredAlignment : 8,
|
|
127
|
+
),
|
|
128
|
+
);
|
|
129
|
+
const alignedOffset = alignOffset(offset, alignment);
|
|
130
|
+
return {
|
|
131
|
+
payload,
|
|
132
|
+
padding: alignedOffset - offset,
|
|
133
|
+
buffer: new TypedArenaBufferT(
|
|
134
|
+
typeRef,
|
|
135
|
+
frame.portId ?? null,
|
|
136
|
+
alignment,
|
|
137
|
+
alignedOffset,
|
|
138
|
+
payload.length,
|
|
139
|
+
frame.ownership ?? BufferOwnership.BORROWED,
|
|
140
|
+
normalizeUnsignedInteger(frame.generation),
|
|
141
|
+
frame.mutability ?? BufferMutability.IMMUTABLE,
|
|
142
|
+
normalizeBigInt(frame.traceId),
|
|
143
|
+
normalizeUnsignedInteger(frame.streamId),
|
|
144
|
+
normalizeBigInt(frame.sequence),
|
|
145
|
+
frame.endOfStream === true,
|
|
146
|
+
),
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function packArenaFrames(frames = []) {
|
|
151
|
+
const packedFrames = [];
|
|
152
|
+
const arena = [];
|
|
153
|
+
let offset = 0;
|
|
154
|
+
for (const frame of frames) {
|
|
155
|
+
const normalized = normalizeArenaFrame(frame, offset);
|
|
156
|
+
for (let index = 0; index < normalized.padding; index += 1) {
|
|
157
|
+
arena.push(0);
|
|
158
|
+
}
|
|
159
|
+
arena.push(...normalized.payload);
|
|
160
|
+
offset = normalized.buffer.offset + normalized.buffer.size;
|
|
161
|
+
packedFrames.push(normalized.buffer);
|
|
162
|
+
}
|
|
163
|
+
return {
|
|
164
|
+
frames: packedFrames,
|
|
165
|
+
arena: Uint8Array.from(arena),
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function materializeArenaFrames(frames = [], arenaBytes) {
|
|
170
|
+
return frames.map((frame) => {
|
|
171
|
+
const offset = normalizeUnsignedInteger(frame.offset);
|
|
172
|
+
const size = normalizeUnsignedInteger(frame.size);
|
|
173
|
+
const payload = new Uint8Array(arenaBytes.slice(offset, offset + size));
|
|
174
|
+
return {
|
|
175
|
+
...frame,
|
|
176
|
+
payload,
|
|
177
|
+
typeRef: frame.typeRef ?? null,
|
|
178
|
+
};
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function encodeRoot(builderFactory, finish, value) {
|
|
183
|
+
const builder = new flatbuffers.Builder(1024);
|
|
184
|
+
finish(builder, builderFactory(value).pack(builder));
|
|
185
|
+
return builder.asUint8Array();
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export function encodePluginInvokeRequest(request = {}) {
|
|
189
|
+
const { frames, arena } = packArenaFrames(
|
|
190
|
+
Array.isArray(request.inputs) ? request.inputs : request.inputFrames ?? [],
|
|
191
|
+
);
|
|
192
|
+
return encodeRoot(
|
|
193
|
+
(value) =>
|
|
194
|
+
new PluginInvokeRequestT(value.methodId ?? null, frames, Array.from(arena)),
|
|
195
|
+
PluginInvokeRequest.finishPluginInvokeRequestBuffer,
|
|
196
|
+
request,
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export function decodePluginInvokeRequest(data) {
|
|
201
|
+
const bb = toByteBuffer(data);
|
|
202
|
+
if (!PluginInvokeRequest.bufferHasIdentifier(bb)) {
|
|
203
|
+
throw new Error("Plugin invoke request buffer identifier mismatch.");
|
|
204
|
+
}
|
|
205
|
+
const unpacked = PluginInvokeRequest.getRootAsPluginInvokeRequest(bb).unpack();
|
|
206
|
+
const arena = Uint8Array.from(unpacked.payloadArena ?? []);
|
|
207
|
+
const inputs = materializeArenaFrames(unpacked.inputFrames ?? [], arena);
|
|
208
|
+
return {
|
|
209
|
+
methodId: unpacked.methodId ?? null,
|
|
210
|
+
inputFrames: inputs,
|
|
211
|
+
inputs,
|
|
212
|
+
payloadArena: arena,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export function encodePluginInvokeResponse(response = {}) {
|
|
217
|
+
const { frames, arena } = packArenaFrames(
|
|
218
|
+
Array.isArray(response.outputs) ? response.outputs : response.outputFrames ?? [],
|
|
219
|
+
);
|
|
220
|
+
return encodeRoot(
|
|
221
|
+
(value) =>
|
|
222
|
+
new PluginInvokeResponseT(
|
|
223
|
+
Number(value.statusCode ?? 0),
|
|
224
|
+
value.yielded === true,
|
|
225
|
+
normalizeUnsignedInteger(value.backlogRemaining),
|
|
226
|
+
frames,
|
|
227
|
+
Array.from(arena),
|
|
228
|
+
value.errorCode ?? null,
|
|
229
|
+
value.errorMessage ?? null,
|
|
230
|
+
),
|
|
231
|
+
PluginInvokeResponse.finishPluginInvokeResponseBuffer,
|
|
232
|
+
response,
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export function decodePluginInvokeResponse(data) {
|
|
237
|
+
const bb = toByteBuffer(data);
|
|
238
|
+
if (!PluginInvokeResponse.bufferHasIdentifier(bb)) {
|
|
239
|
+
throw new Error("Plugin invoke response buffer identifier mismatch.");
|
|
240
|
+
}
|
|
241
|
+
const unpacked = PluginInvokeResponse.getRootAsPluginInvokeResponse(bb).unpack();
|
|
242
|
+
const arena = Uint8Array.from(unpacked.payloadArena ?? []);
|
|
243
|
+
const outputs = materializeArenaFrames(unpacked.outputFrames ?? [], arena);
|
|
244
|
+
return {
|
|
245
|
+
statusCode: unpacked.statusCode ?? 0,
|
|
246
|
+
yielded: unpacked.yielded === true,
|
|
247
|
+
backlogRemaining: unpacked.backlogRemaining ?? 0,
|
|
248
|
+
outputFrames: outputs,
|
|
249
|
+
outputs,
|
|
250
|
+
payloadArena: arena,
|
|
251
|
+
errorCode: unpacked.errorCode ?? null,
|
|
252
|
+
errorMessage: unpacked.errorMessage ?? null,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export function normalizeInvokeSurfaceName(value) {
|
|
257
|
+
if (value === InvokeSurface.COMMAND || value === "command") {
|
|
258
|
+
return "command";
|
|
259
|
+
}
|
|
260
|
+
if (value === InvokeSurface.DIRECT || value === "direct") {
|
|
261
|
+
return "direct";
|
|
262
|
+
}
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export function normalizeInvokeSurfaces(value) {
|
|
267
|
+
if (!Array.isArray(value)) {
|
|
268
|
+
return [];
|
|
269
|
+
}
|
|
270
|
+
const surfaces = [];
|
|
271
|
+
for (const entry of value) {
|
|
272
|
+
const normalized = normalizeInvokeSurfaceName(entry);
|
|
273
|
+
if (normalized && !surfaces.includes(normalized)) {
|
|
274
|
+
surfaces.push(normalized);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return surfaces;
|
|
278
|
+
}
|
package/src/manifest/codec.js
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
PluginManifest,
|
|
5
5
|
PluginManifestT,
|
|
6
6
|
} from "../generated/orbpro/manifest.js";
|
|
7
|
+
import { normalizeInvokeSurfaceName } from "../invoke/codec.js";
|
|
7
8
|
import { toUint8Array } from "../runtime/bufferLike.js";
|
|
8
9
|
import { toEmbeddedPluginManifest } from "./normalize.js";
|
|
9
10
|
|
|
@@ -25,7 +26,15 @@ export function decodePluginManifest(data) {
|
|
|
25
26
|
if (!PluginManifest.bufferHasIdentifier(bb)) {
|
|
26
27
|
throw new Error("Plugin manifest buffer identifier mismatch.");
|
|
27
28
|
}
|
|
28
|
-
|
|
29
|
+
const unpacked = PluginManifest.getRootAsPluginManifest(bb).unpack();
|
|
30
|
+
return {
|
|
31
|
+
...unpacked,
|
|
32
|
+
invokeSurfaces: Array.isArray(unpacked.invokeSurfaces)
|
|
33
|
+
? unpacked.invokeSurfaces
|
|
34
|
+
.map((value) => normalizeInvokeSurfaceName(value))
|
|
35
|
+
.filter(Boolean)
|
|
36
|
+
: [],
|
|
37
|
+
};
|
|
29
38
|
}
|
|
30
39
|
|
|
31
40
|
export function encodePluginManifest(manifest) {
|
|
@@ -37,4 +46,3 @@ export function encodePluginManifest(manifest) {
|
|
|
37
46
|
PluginManifest.finishPluginManifestBuffer(builder, value.pack(builder));
|
|
38
47
|
return builder.asUint8Array();
|
|
39
48
|
}
|
|
40
|
-
|
package/src/manifest/index.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
export * from "../generated/orbpro/manifest.js";
|
|
2
|
-
export {
|
|
2
|
+
export { PayloadWireFormat } from "../generated/orbpro/stream/payload-wire-format.js";
|
|
3
|
+
export {
|
|
4
|
+
FlatBufferTypeRefT,
|
|
5
|
+
FlatBufferTypeRefT as PayloadTypeRef,
|
|
6
|
+
} from "../generated/orbpro/stream/flat-buffer-type-ref.js";
|
|
3
7
|
export { decodePluginManifest, encodePluginManifest } from "./codec.js";
|
|
4
8
|
export { toEmbeddedPluginManifest } from "./normalize.js";
|
|
5
9
|
export {
|
|
6
10
|
generateEmbeddedManifestSource,
|
|
7
11
|
writeEmbeddedManifestArtifacts,
|
|
8
12
|
} from "../embeddedManifest.js";
|
|
9
|
-
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
CapabilityKind,
|
|
5
5
|
DrainPolicy as ManifestDrainPolicy,
|
|
6
6
|
HostCapabilityT,
|
|
7
|
+
InvokeSurface,
|
|
7
8
|
MethodManifestT,
|
|
8
9
|
PluginFamily,
|
|
9
10
|
PluginManifestT,
|
|
@@ -39,15 +40,47 @@ const capabilityKindByName = Object.freeze({
|
|
|
39
40
|
random: CapabilityKind.RANDOM,
|
|
40
41
|
logging: CapabilityKind.LOGGING,
|
|
41
42
|
timers: CapabilityKind.TIMERS,
|
|
43
|
+
schedule_cron: CapabilityKind.SCHEDULE_CRON,
|
|
44
|
+
cron: CapabilityKind.SCHEDULE_CRON,
|
|
42
45
|
pubsub: CapabilityKind.PUBSUB,
|
|
46
|
+
http: CapabilityKind.HTTP,
|
|
47
|
+
filesystem: CapabilityKind.FILESYSTEM,
|
|
48
|
+
pipe: CapabilityKind.PIPE,
|
|
49
|
+
network: CapabilityKind.NETWORK,
|
|
50
|
+
database: CapabilityKind.DATABASE,
|
|
43
51
|
protocol_dial: CapabilityKind.PROTOCOL_DIAL,
|
|
44
52
|
protocol_handle: CapabilityKind.PROTOCOL_HANDLE,
|
|
53
|
+
tls: CapabilityKind.TLS,
|
|
54
|
+
mqtt: CapabilityKind.MQTT,
|
|
55
|
+
websocket: CapabilityKind.WEBSOCKET,
|
|
56
|
+
tcp: CapabilityKind.TCP,
|
|
57
|
+
udp: CapabilityKind.UDP,
|
|
58
|
+
process_exec: CapabilityKind.PROCESS_EXEC,
|
|
59
|
+
exec: CapabilityKind.PROCESS_EXEC,
|
|
60
|
+
context_read: CapabilityKind.CONTEXT_READ,
|
|
61
|
+
context_write: CapabilityKind.CONTEXT_WRITE,
|
|
62
|
+
storage_adapter: CapabilityKind.STORAGE_ADAPTER,
|
|
45
63
|
storage_query: CapabilityKind.STORAGE_QUERY,
|
|
64
|
+
storage_write: CapabilityKind.STORAGE_WRITE,
|
|
65
|
+
wallet_sign: CapabilityKind.WALLET_SIGN,
|
|
66
|
+
ipfs: CapabilityKind.IPFS,
|
|
67
|
+
crypto_hash: CapabilityKind.CRYPTO_HASH,
|
|
68
|
+
crypto_sign: CapabilityKind.CRYPTO_SIGN,
|
|
69
|
+
crypto_verify: CapabilityKind.CRYPTO_VERIFY,
|
|
70
|
+
crypto_encrypt: CapabilityKind.CRYPTO_ENCRYPT,
|
|
71
|
+
crypto_decrypt: CapabilityKind.CRYPTO_DECRYPT,
|
|
72
|
+
crypto_key_agreement: CapabilityKind.CRYPTO_KEY_AGREEMENT,
|
|
73
|
+
crypto_kdf: CapabilityKind.CRYPTO_KDF,
|
|
46
74
|
scene_access: CapabilityKind.SCENE_ACCESS,
|
|
47
75
|
entity_access: CapabilityKind.ENTITY_ACCESS,
|
|
48
76
|
render_hooks: CapabilityKind.RENDER_HOOKS,
|
|
49
77
|
});
|
|
50
78
|
|
|
79
|
+
const invokeSurfaceByName = Object.freeze({
|
|
80
|
+
direct: InvokeSurface.DIRECT,
|
|
81
|
+
command: InvokeSurface.COMMAND,
|
|
82
|
+
});
|
|
83
|
+
|
|
51
84
|
function normalizeSchemaHash(value) {
|
|
52
85
|
if (!value) {
|
|
53
86
|
return [];
|
|
@@ -66,6 +99,25 @@ function normalizeSchemaHash(value) {
|
|
|
66
99
|
return bytes;
|
|
67
100
|
}
|
|
68
101
|
|
|
102
|
+
function normalizePayloadWireFormat(value) {
|
|
103
|
+
if (value === 1) {
|
|
104
|
+
return "aligned-binary";
|
|
105
|
+
}
|
|
106
|
+
const normalized = String(value ?? "")
|
|
107
|
+
.trim()
|
|
108
|
+
.toLowerCase()
|
|
109
|
+
.replace(/_/g, "-");
|
|
110
|
+
return normalized === "aligned-binary" ? "aligned-binary" : "flatbuffer";
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function normalizeUnsignedInteger(value, fallback = 0) {
|
|
114
|
+
const normalized = Number(value ?? fallback);
|
|
115
|
+
if (!Number.isFinite(normalized)) {
|
|
116
|
+
return fallback;
|
|
117
|
+
}
|
|
118
|
+
return Math.max(0, Math.trunc(normalized));
|
|
119
|
+
}
|
|
120
|
+
|
|
69
121
|
function normalizePluginFamily(value) {
|
|
70
122
|
if (typeof value === "number") {
|
|
71
123
|
return value;
|
|
@@ -98,6 +150,33 @@ function normalizeCapabilityKind(value) {
|
|
|
98
150
|
return capabilityKindByName[normalized] ?? null;
|
|
99
151
|
}
|
|
100
152
|
|
|
153
|
+
function normalizeInvokeSurface(value) {
|
|
154
|
+
if (typeof value === "number") {
|
|
155
|
+
return value;
|
|
156
|
+
}
|
|
157
|
+
const normalized = String(value ?? "")
|
|
158
|
+
.trim()
|
|
159
|
+
.toLowerCase();
|
|
160
|
+
return invokeSurfaceByName[normalized] ?? null;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function normalizeInvokeSurfaces(value) {
|
|
164
|
+
if (!Array.isArray(value)) {
|
|
165
|
+
return [];
|
|
166
|
+
}
|
|
167
|
+
const seen = new Set();
|
|
168
|
+
const normalized = [];
|
|
169
|
+
for (const entry of value) {
|
|
170
|
+
const surface = normalizeInvokeSurface(entry);
|
|
171
|
+
if (surface === null || seen.has(surface)) {
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
seen.add(surface);
|
|
175
|
+
normalized.push(surface);
|
|
176
|
+
}
|
|
177
|
+
return normalized;
|
|
178
|
+
}
|
|
179
|
+
|
|
101
180
|
function toFlatBufferTypeRefT(value = {}) {
|
|
102
181
|
if (value instanceof FlatBufferTypeRefT) {
|
|
103
182
|
return value;
|
|
@@ -107,6 +186,11 @@ function toFlatBufferTypeRefT(value = {}) {
|
|
|
107
186
|
value.fileIdentifier ?? null,
|
|
108
187
|
normalizeSchemaHash(value.schemaHash),
|
|
109
188
|
value.acceptsAnyFlatbuffer === true,
|
|
189
|
+
normalizePayloadWireFormat(value.wireFormat),
|
|
190
|
+
value.rootTypeName ?? null,
|
|
191
|
+
normalizeUnsignedInteger(value.fixedStringLength),
|
|
192
|
+
normalizeUnsignedInteger(value.byteLength),
|
|
193
|
+
normalizeUnsignedInteger(value.requiredAlignment),
|
|
110
194
|
);
|
|
111
195
|
}
|
|
112
196
|
|
|
@@ -238,6 +322,11 @@ export function toEmbeddedPluginManifest(input = {}) {
|
|
|
238
322
|
"externalInterfaces are not yet representable in the embedded FlatBuffer manifest schema and were omitted from the compiled artifact.",
|
|
239
323
|
);
|
|
240
324
|
}
|
|
325
|
+
if (Array.isArray(input.runtimeTargets) && input.runtimeTargets.length > 0) {
|
|
326
|
+
warnings.push(
|
|
327
|
+
"runtimeTargets are not yet representable in the embedded FlatBuffer manifest schema and were omitted from the compiled artifact.",
|
|
328
|
+
);
|
|
329
|
+
}
|
|
241
330
|
|
|
242
331
|
const capabilities = Array.isArray(input.capabilities)
|
|
243
332
|
? input.capabilities
|
|
@@ -268,8 +357,8 @@ export function toEmbeddedPluginManifest(input = {}) {
|
|
|
268
357
|
? input.buildArtifacts.map((entry) => toBuildArtifactT(entry))
|
|
269
358
|
: [],
|
|
270
359
|
Number(input.abiVersion ?? 1),
|
|
360
|
+
normalizeInvokeSurfaces(input.invokeSurfaces),
|
|
271
361
|
),
|
|
272
362
|
warnings,
|
|
273
363
|
};
|
|
274
364
|
}
|
|
275
|
-
|
package/src/runtime/constants.js
CHANGED
|
@@ -14,17 +14,40 @@ export const ExternalInterfaceKind = Object.freeze({
|
|
|
14
14
|
CLOCK: "clock",
|
|
15
15
|
RANDOM: "random",
|
|
16
16
|
TIMER: "timer",
|
|
17
|
+
SCHEDULE: "schedule",
|
|
17
18
|
PUBSUB: "pubsub",
|
|
18
19
|
PROTOCOL: "protocol",
|
|
19
20
|
HTTP: "http",
|
|
21
|
+
WEBSOCKET: "websocket",
|
|
22
|
+
MQTT: "mqtt",
|
|
23
|
+
TCP: "tcp",
|
|
24
|
+
UDP: "udp",
|
|
25
|
+
TLS: "tls",
|
|
20
26
|
FILESYSTEM: "filesystem",
|
|
21
27
|
PIPE: "pipe",
|
|
22
28
|
NETWORK: "network",
|
|
23
29
|
DATABASE: "database",
|
|
30
|
+
EXEC: "exec",
|
|
31
|
+
CRYPTO: "crypto",
|
|
32
|
+
CONTEXT: "context",
|
|
24
33
|
LOCAL_RUNTIME: "local-runtime",
|
|
25
34
|
HOST_SERVICE: "host-service",
|
|
26
35
|
});
|
|
27
36
|
|
|
37
|
+
export const RuntimeTarget = Object.freeze({
|
|
38
|
+
NODE: "node",
|
|
39
|
+
BROWSER: "browser",
|
|
40
|
+
WASI: "wasi",
|
|
41
|
+
SERVER: "server",
|
|
42
|
+
DESKTOP: "desktop",
|
|
43
|
+
EDGE: "edge",
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
export const InvokeSurface = Object.freeze({
|
|
47
|
+
DIRECT: "direct",
|
|
48
|
+
COMMAND: "command",
|
|
49
|
+
});
|
|
50
|
+
|
|
28
51
|
export const DefaultManifestExports = Object.freeze({
|
|
29
52
|
pluginBytesSymbol: "plugin_get_manifest_flatbuffer",
|
|
30
53
|
pluginSizeSymbol: "plugin_get_manifest_flatbuffer_size",
|
|
@@ -32,3 +55,9 @@ export const DefaultManifestExports = Object.freeze({
|
|
|
32
55
|
flowSizeSymbol: "flow_get_manifest_flatbuffer_size",
|
|
33
56
|
});
|
|
34
57
|
|
|
58
|
+
export const DefaultInvokeExports = Object.freeze({
|
|
59
|
+
invokeSymbol: "plugin_invoke_stream",
|
|
60
|
+
allocSymbol: "plugin_alloc",
|
|
61
|
+
freeSymbol: "plugin_free",
|
|
62
|
+
commandSymbol: "_start",
|
|
63
|
+
});
|
package/src/transport/pki.js
CHANGED
|
@@ -14,8 +14,6 @@ import {
|
|
|
14
14
|
x25519SharedSecret,
|
|
15
15
|
} from "../utils/wasmCrypto.js";
|
|
16
16
|
|
|
17
|
-
const HKDF_SALT_LABEL = new TextEncoder().encode("space-data-module-sdk");
|
|
18
|
-
|
|
19
17
|
function normalizePublicKey(value) {
|
|
20
18
|
if (typeof value === "string") {
|
|
21
19
|
return hexToBytes(value);
|
|
@@ -66,9 +64,6 @@ export async function encryptBytesForRecipient({
|
|
|
66
64
|
}
|
|
67
65
|
const sender = senderKeyPair ?? (await generateX25519Keypair());
|
|
68
66
|
const salt = await randomBytes(32);
|
|
69
|
-
salt.set(
|
|
70
|
-
HKDF_SALT_LABEL.slice(0, Math.min(HKDF_SALT_LABEL.length, salt.length)),
|
|
71
|
-
);
|
|
72
67
|
const iv = await randomBytes(12);
|
|
73
68
|
const sharedSecret = await deriveSharedSecret(
|
|
74
69
|
sender.privateKey,
|
package/src/utils/encoding.js
CHANGED
|
@@ -48,7 +48,15 @@ export function bytesToBase64(bytes) {
|
|
|
48
48
|
return Buffer.from(toUint8Array(bytes)).toString("base64");
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
const MAX_BASE64_LENGTH = 256 * 1024 * 1024;
|
|
52
|
+
|
|
51
53
|
export function base64ToBytes(base64) {
|
|
52
|
-
|
|
54
|
+
const str = String(base64 ?? "").trim();
|
|
55
|
+
if (str.length > MAX_BASE64_LENGTH) {
|
|
56
|
+
throw new RangeError(
|
|
57
|
+
`Base64 input exceeds ${MAX_BASE64_LENGTH} character limit.`,
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
return new Uint8Array(Buffer.from(str, "base64"));
|
|
53
61
|
}
|
|
54
62
|
|
package/src/utils/wasmCrypto.js
CHANGED
|
@@ -24,6 +24,11 @@ export async function sha256Bytes(value) {
|
|
|
24
24
|
return wallet.utils.sha256(toUint8Array(value));
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
export async function sha512Bytes(value) {
|
|
28
|
+
const wallet = await getWasmWallet();
|
|
29
|
+
return wallet.utils.sha512(toUint8Array(value));
|
|
30
|
+
}
|
|
31
|
+
|
|
27
32
|
export async function hkdfBytes(ikm, salt, info, length) {
|
|
28
33
|
const wallet = await getWasmWallet();
|
|
29
34
|
return wallet.utils.hkdf(
|
|
@@ -47,6 +52,50 @@ export async function x25519SharedSecret(privateKey, publicKey) {
|
|
|
47
52
|
);
|
|
48
53
|
}
|
|
49
54
|
|
|
55
|
+
export async function secp256k1PublicKey(privateKey) {
|
|
56
|
+
const wallet = await getWasmWallet();
|
|
57
|
+
return wallet.curves.publicKeyFromPrivate(toUint8Array(privateKey));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export async function secp256k1SignDigest(digest, privateKey) {
|
|
61
|
+
const wallet = await getWasmWallet();
|
|
62
|
+
return wallet.curves.secp256k1.sign(
|
|
63
|
+
toUint8Array(digest),
|
|
64
|
+
toUint8Array(privateKey),
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export async function secp256k1VerifyDigest(digest, signature, publicKey) {
|
|
69
|
+
const wallet = await getWasmWallet();
|
|
70
|
+
return wallet.curves.secp256k1.verify(
|
|
71
|
+
toUint8Array(digest),
|
|
72
|
+
toUint8Array(signature),
|
|
73
|
+
toUint8Array(publicKey),
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export async function ed25519PublicKey(seed) {
|
|
78
|
+
const wallet = await getWasmWallet();
|
|
79
|
+
return wallet.curves.ed25519.publicKeyFromSeed(toUint8Array(seed));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export async function ed25519Sign(message, seed) {
|
|
83
|
+
const wallet = await getWasmWallet();
|
|
84
|
+
return wallet.curves.ed25519.sign(
|
|
85
|
+
toUint8Array(message),
|
|
86
|
+
toUint8Array(seed),
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export async function ed25519Verify(message, signature, publicKey) {
|
|
91
|
+
const wallet = await getWasmWallet();
|
|
92
|
+
return wallet.curves.ed25519.verify(
|
|
93
|
+
toUint8Array(message),
|
|
94
|
+
toUint8Array(signature),
|
|
95
|
+
toUint8Array(publicKey),
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
50
99
|
export async function aesGcmEncrypt(key, plaintext, iv, aad = null) {
|
|
51
100
|
const wallet = await getWasmWallet();
|
|
52
101
|
return wallet.utils.aesGcm.encrypt(
|
|
@@ -67,4 +116,3 @@ export async function aesGcmDecrypt(key, ciphertext, tag, iv, aad = null) {
|
|
|
67
116
|
aad ? toUint8Array(aad) : undefined,
|
|
68
117
|
);
|
|
69
118
|
}
|
|
70
|
-
|