space-data-module-sdk 0.1.0 → 0.2.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.
Files changed (44) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +174 -83
  3. package/bin/space-data-module.js +24 -0
  4. package/package.json +8 -3
  5. package/schemas/ModuleBundle.fbs +108 -0
  6. package/schemas/PluginManifest.fbs +26 -1
  7. package/src/bundle/codec.js +244 -0
  8. package/src/bundle/constants.js +8 -0
  9. package/src/bundle/index.js +3 -0
  10. package/src/bundle/wasm.js +447 -0
  11. package/src/compiler/compileModule.js +189 -41
  12. package/src/compliance/pluginCompliance.js +334 -0
  13. package/src/generated/orbpro/manifest/capability-kind.d.ts +27 -2
  14. package/src/generated/orbpro/manifest/capability-kind.js +26 -1
  15. package/src/generated/orbpro/manifest/capability-kind.ts +25 -0
  16. package/src/generated/orbpro/module/canonicalization-rule.d.ts +48 -0
  17. package/src/generated/orbpro/module/canonicalization-rule.js +95 -0
  18. package/src/generated/orbpro/module/canonicalization-rule.ts +142 -0
  19. package/src/generated/orbpro/module/module-bundle-entry-role.d.ts +11 -0
  20. package/src/generated/orbpro/module/module-bundle-entry-role.js +14 -0
  21. package/src/generated/orbpro/module/module-bundle-entry-role.ts +15 -0
  22. package/src/generated/orbpro/module/module-bundle-entry.d.ts +97 -0
  23. package/src/generated/orbpro/module/module-bundle-entry.js +219 -0
  24. package/src/generated/orbpro/module/module-bundle-entry.ts +287 -0
  25. package/src/generated/orbpro/module/module-bundle.d.ts +86 -0
  26. package/src/generated/orbpro/module/module-bundle.js +213 -0
  27. package/src/generated/orbpro/module/module-bundle.ts +277 -0
  28. package/src/generated/orbpro/module/module-payload-encoding.d.ts +9 -0
  29. package/src/generated/orbpro/module/module-payload-encoding.js +12 -0
  30. package/src/generated/orbpro/module/module-payload-encoding.ts +13 -0
  31. package/src/generated/orbpro/module.d.ts +5 -0
  32. package/src/generated/orbpro/module.js +7 -0
  33. package/src/generated/orbpro/module.ts +9 -0
  34. package/src/host/abi.js +282 -0
  35. package/src/host/cron.js +247 -0
  36. package/src/host/index.js +3 -0
  37. package/src/host/nodeHost.js +2165 -0
  38. package/src/index.d.ts +880 -0
  39. package/src/index.js +9 -2
  40. package/src/manifest/normalize.js +32 -1
  41. package/src/runtime/constants.js +18 -1
  42. package/src/transport/pki.js +0 -5
  43. package/src/utils/encoding.js +9 -1
  44. package/src/utils/wasmCrypto.js +49 -1
package/src/index.js CHANGED
@@ -3,6 +3,13 @@ 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 { DefaultManifestExports } from "./runtime/constants.js";
8
-
8
+ export * from "./host/index.js";
9
+ export {
10
+ DefaultManifestExports,
11
+ DrainPolicy,
12
+ ExternalInterfaceDirection,
13
+ ExternalInterfaceKind,
14
+ RuntimeTarget,
15
+ } from "./runtime/constants.js";
@@ -39,10 +39,37 @@ const capabilityKindByName = Object.freeze({
39
39
  random: CapabilityKind.RANDOM,
40
40
  logging: CapabilityKind.LOGGING,
41
41
  timers: CapabilityKind.TIMERS,
42
+ schedule_cron: CapabilityKind.SCHEDULE_CRON,
43
+ cron: CapabilityKind.SCHEDULE_CRON,
42
44
  pubsub: CapabilityKind.PUBSUB,
45
+ http: CapabilityKind.HTTP,
46
+ filesystem: CapabilityKind.FILESYSTEM,
47
+ pipe: CapabilityKind.PIPE,
48
+ network: CapabilityKind.NETWORK,
49
+ database: CapabilityKind.DATABASE,
43
50
  protocol_dial: CapabilityKind.PROTOCOL_DIAL,
44
51
  protocol_handle: CapabilityKind.PROTOCOL_HANDLE,
52
+ tls: CapabilityKind.TLS,
53
+ mqtt: CapabilityKind.MQTT,
54
+ websocket: CapabilityKind.WEBSOCKET,
55
+ tcp: CapabilityKind.TCP,
56
+ udp: CapabilityKind.UDP,
57
+ process_exec: CapabilityKind.PROCESS_EXEC,
58
+ exec: CapabilityKind.PROCESS_EXEC,
59
+ context_read: CapabilityKind.CONTEXT_READ,
60
+ context_write: CapabilityKind.CONTEXT_WRITE,
61
+ storage_adapter: CapabilityKind.STORAGE_ADAPTER,
45
62
  storage_query: CapabilityKind.STORAGE_QUERY,
63
+ storage_write: CapabilityKind.STORAGE_WRITE,
64
+ wallet_sign: CapabilityKind.WALLET_SIGN,
65
+ ipfs: CapabilityKind.IPFS,
66
+ crypto_hash: CapabilityKind.CRYPTO_HASH,
67
+ crypto_sign: CapabilityKind.CRYPTO_SIGN,
68
+ crypto_verify: CapabilityKind.CRYPTO_VERIFY,
69
+ crypto_encrypt: CapabilityKind.CRYPTO_ENCRYPT,
70
+ crypto_decrypt: CapabilityKind.CRYPTO_DECRYPT,
71
+ crypto_key_agreement: CapabilityKind.CRYPTO_KEY_AGREEMENT,
72
+ crypto_kdf: CapabilityKind.CRYPTO_KDF,
46
73
  scene_access: CapabilityKind.SCENE_ACCESS,
47
74
  entity_access: CapabilityKind.ENTITY_ACCESS,
48
75
  render_hooks: CapabilityKind.RENDER_HOOKS,
@@ -238,6 +265,11 @@ export function toEmbeddedPluginManifest(input = {}) {
238
265
  "externalInterfaces are not yet representable in the embedded FlatBuffer manifest schema and were omitted from the compiled artifact.",
239
266
  );
240
267
  }
268
+ if (Array.isArray(input.runtimeTargets) && input.runtimeTargets.length > 0) {
269
+ warnings.push(
270
+ "runtimeTargets are not yet representable in the embedded FlatBuffer manifest schema and were omitted from the compiled artifact.",
271
+ );
272
+ }
241
273
 
242
274
  const capabilities = Array.isArray(input.capabilities)
243
275
  ? input.capabilities
@@ -272,4 +304,3 @@ export function toEmbeddedPluginManifest(input = {}) {
272
304
  warnings,
273
305
  };
274
306
  }
275
-
@@ -14,21 +14,38 @@ 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
+
28
46
  export const DefaultManifestExports = Object.freeze({
29
47
  pluginBytesSymbol: "plugin_get_manifest_flatbuffer",
30
48
  pluginSizeSymbol: "plugin_get_manifest_flatbuffer_size",
31
49
  flowBytesSymbol: "flow_get_manifest_flatbuffer",
32
50
  flowSizeSymbol: "flow_get_manifest_flatbuffer_size",
33
51
  });
34
-
@@ -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,
@@ -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
- return new Uint8Array(Buffer.from(String(base64 ?? "").trim(), "base64"));
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
 
@@ -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
-