space-data-module-sdk 0.9.3 → 0.9.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.
@@ -159,6 +159,7 @@
159
159
  <li><code>expect</code> (<code>&quot;ok&quot; | &quot;guest-error&quot; | &quot;trap&quot;</code>) is optional; without it the case only requires the class to be IDENTICAL across lanes (malformed-input fixtures compare error/trap classes this way).</li>
160
160
  <li>Payloads: <code>payloadFile</code> (relative to the fixture), <code>payloadBase64</code>, <code>payloadHex</code>, <code>payloadUtf8</code>.</li>
161
161
  <li>Committed payload binaries are regenerated deterministically by <code>node fixtures/parity/generate-fixtures.mjs</code>.</li>
162
+ <li><code>config</code> (an object, on the fixture or a case; the case's replaces the fixture's, <code>{}</code> by default) is what a module's <code>plugin.getConfig</code> hostcall answers. Every lane serves the typed hostcall bridge (<code>space_data_module_host.call</code> / <code>response_len</code> / <code>read_response</code>): <code>plugin.getConfig</code> answers the case's config as one <code>ModuleConfig</code> on raw <code>config</code> (the answer the SDK JS hosts give), and every other operation a STATUS FAILED <code>unsupported</code> $PIV answer. The WasmEdge CLI provides no host imports, so the wasmedge lanes run an artifact that imports the bridge on the SDK runner (single-thread or not), which replays answers the orchestrator encodes with the SDK's own encoder.</li>
162
163
  </ul>
163
164
  <h2 id="scope-and-current-limits-v1"><a class="anchor" href="#scope-and-current-limits-v1" aria-hidden="true">#</a>Scope and current limits (v1)</h2>
164
165
  <ul>
@@ -113,6 +113,16 @@ Every lane receives EXACTLY the same guest-observable inputs:
113
113
  `payloadHex`, `payloadUtf8`.
114
114
  - Committed payload binaries are regenerated deterministically by
115
115
  `node fixtures/parity/generate-fixtures.mjs`.
116
+ - `config` (an object, on the fixture or a case; the case's replaces the
117
+ fixture's, `{}` by default) is what a module's `plugin.getConfig` hostcall
118
+ answers. Every lane serves the typed hostcall bridge
119
+ (`space_data_module_host.call` / `response_len` / `read_response`):
120
+ `plugin.getConfig` answers the case's config as one `ModuleConfig` on raw
121
+ `config` (the answer the SDK JS hosts give), and every other operation a
122
+ STATUS FAILED `unsupported` $PIV answer. The WasmEdge CLI provides no host
123
+ imports, so the wasmedge lanes run an artifact that imports the bridge on the
124
+ SDK runner (single-thread or not), which replays answers the orchestrator
125
+ encodes with the SDK's own encoder.
116
126
 
117
127
  ## Scope and current limits (v1)
118
128
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "space-data-module-sdk",
3
- "version": "0.9.3",
3
+ "version": "0.9.5",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Module SDK for building, validating, signing, and deploying WebAssembly modules on the Space Data Network.",
6
6
  "type": "module",
@@ -52,6 +52,14 @@ export async function createDeploymentAuthorization(options = {}) {
52
52
  };
53
53
  }
54
54
 
55
+ // Authorization signatures ("secp256k1-sha256"): ECDSA over sha256(canonical bytes), hashed exactly once; the
56
+ // signature is 64 raw bytes (r || s). node:crypto verifies it with crypto.verify("sha256", bytes, ...).
57
+
58
+ /**
59
+ * A signer for authorizations: `signDigest(digest)` signs the 32-byte sha256 of the canonical bytes AS GIVEN, with no
60
+ * further hashing - e.g. hd-wallet-wasm's secp256k1.signRecoverable(digest, key).signature, or the SDK's
61
+ * secp256k1SignDigest. Never hd-wallet-wasm's secp256k1.sign(digest): it hashes its input again.
62
+ */
55
63
  export function createHdWalletSigner(options = {}) {
56
64
  if (typeof options.signDigest !== "function") {
57
65
  throw new Error("createHdWalletSigner requires signDigest.");
@@ -73,6 +81,10 @@ export function createHdWalletSigner(options = {}) {
73
81
  };
74
82
  }
75
83
 
84
+ /**
85
+ * A verifier for authorizations: `verifyDigest(digest, signature, header, payload)` checks a signature over the
86
+ * 32-byte sha256 of the canonical bytes AS GIVEN, with no further hashing (e.g. the SDK's secp256k1VerifyDigest).
87
+ */
76
88
  export function createHdWalletVerifier(options = {}) {
77
89
  if (typeof options.verifyDigest !== "function") {
78
90
  throw new Error("createHdWalletVerifier requires verifyDigest.");
@@ -80,7 +92,7 @@ export function createHdWalletVerifier(options = {}) {
80
92
  return {
81
93
  async verify(bytes, signature, header, payload) {
82
94
  const digest = await sha256Bytes(bytes);
83
- return options.verifyDigest(digest, signature, header, payload);
95
+ return Boolean(await options.verifyDigest(digest, signature, header, payload));
84
96
  },
85
97
  };
86
98
  }
@@ -1397,11 +1397,12 @@ export async function protectModuleArtifact(options = {}) {
1397
1397
  publicKeyHex: bytesToHex(identity.signingKey.publicKey),
1398
1398
  derivationPath: identity.signingKey.path,
1399
1399
  keyId: artifactId,
1400
+ // the digest as given: signRecoverable signs its 32-byte input, secp256k1.sign would hash it again
1400
1401
  async signDigest(digest) {
1401
- return identity.wallet.curves.secp256k1.sign(
1402
+ return identity.wallet.curves.secp256k1.signRecoverable(
1402
1403
  digest,
1403
1404
  identity.signingKey.privateKey,
1404
- );
1405
+ ).signature;
1405
1406
  },
1406
1407
  });
1407
1408
 
@@ -40,6 +40,16 @@ export const ADAPTER_OPERATIONS = Object.freeze({
40
40
  "node_activity_read.activity": { capability: "node_activity_read", adapter: "node", method: "activity" },
41
41
  });
42
42
 
43
+ /**
44
+ * The Go node's other ipfs operations, served by the host's ipfs adapter (options.ipfs / capabilityAdapters.ipfs) as
45
+ * adapter.<method>(params) or adapter.invoke(method, params): the IpfsParams record's set fields as lower-case keys
46
+ * ({cid, name, type, lifetime, ttl}), answered the way Kubo answers ({Objects: [{Links}]}, {Pins}, {Keys}, {ID, ...}).
47
+ */
48
+ export const IPFS_ADAPTER_OPERATIONS = Object.freeze([
49
+ "ipfs.ls", "ipfs.pin_add", "ipfs.pin_rm", "ipfs.pin_ls", "ipfs.dag_get", "ipfs.id", "ipfs.swarm_peers",
50
+ "ipfs.name_resolve", "ipfs.name_publish", "ipfs.pubsub_publish",
51
+ ]);
52
+
43
53
  /** The capabilities those operations need. */
44
54
  export const ADAPTER_CAPABILITIES = Object.freeze(
45
55
  [...new Set(Object.values(ADAPTER_OPERATIONS).map((o) => o.capability).filter(Boolean))],
@@ -22,6 +22,7 @@ import { createBrowserEdgeShims } from "./browserEdgeShims.js";
22
22
  import {
23
23
  ADAPTER_CAPABILITIES,
24
24
  ADAPTER_OPERATIONS,
25
+ IPFS_ADAPTER_OPERATIONS,
25
26
  callServiceAdapter,
26
27
  normalizePluginConfig,
27
28
  resolveServiceAdapters,
@@ -87,6 +88,7 @@ export const BrowserHostSupportedOperations = Object.freeze([
87
88
  "ipfs.invoke",
88
89
  "ipfs.add",
89
90
  "ipfs.cat",
91
+ ...IPFS_ADAPTER_OPERATIONS,
90
92
  "protocol_handle.register",
91
93
  "protocol_handle.unregister",
92
94
  "protocol_dial.dial",
@@ -314,7 +316,7 @@ async function keyslotSign(walletSignAdapter, wasmWallet, params = {}) {
314
316
  }
315
317
 
316
318
  if (algorithm === "secp256k1") {
317
- if (!wasmWallet?.utils?.sha256 || !wasmWallet?.curves?.secp256k1?.sign) {
319
+ if (!wasmWallet?.curves?.secp256k1?.sign) {
318
320
  throw new Error(
319
321
  "Browser host keyslot.sign requires a preloaded wasmWallet.",
320
322
  );
@@ -324,9 +326,9 @@ async function keyslotSign(walletSignAdapter, wasmWallet, params = {}) {
324
326
  `keyslot "${slotId}" is not a 32-byte secp256k1 private key`,
325
327
  );
326
328
  }
327
- const digest = new Uint8Array(wasmWallet.utils.sha256(payload));
329
+ // ECDSA over sha256(payload), as the Go node: the wallet's sign hashes once.
328
330
  const rawSignature = new Uint8Array(
329
- wasmWallet.curves.secp256k1.sign(digest, keyMaterial),
331
+ wasmWallet.curves.secp256k1.sign(payload, keyMaterial),
330
332
  );
331
333
  return {
332
334
  signature: bytesToBase64(rawSignatureToDer(rawSignature)),
@@ -640,6 +642,11 @@ export class BrowserHost {
640
642
  this.#assertCapability("ipfs", "ipfs.cat");
641
643
  return invokeAdapterMethod(ipfsAdapter, "cat", params, "ipfs");
642
644
  },
645
+ // ls, pin_add, pin_rm, pin_ls, dag_get, id, swarm_peers, name_resolve, name_publish, pubsub_publish
646
+ ...Object.fromEntries(IPFS_ADAPTER_OPERATIONS.map((operation) => [operation.slice(5), async (params = {}) => {
647
+ this.#assertCapability("ipfs", operation);
648
+ return invokeAdapterMethod(ipfsAdapter, operation.slice(5), params, "ipfs");
649
+ }])),
643
650
  });
644
651
 
645
652
  this.protocolHandle = Object.freeze({
@@ -911,37 +918,26 @@ export class BrowserHost {
911
918
  },
912
919
  sign: (message, privateKey) => {
913
920
  this.#assertCapability("crypto_sign", "crypto.secp256k1.sign");
914
- if (
915
- !wasmWallet?.utils?.sha256 ||
916
- !wasmWallet?.curves?.secp256k1?.sign
917
- ) {
921
+ if (!wasmWallet?.curves?.secp256k1?.sign) {
918
922
  throw new Error(
919
923
  "Browser host crypto.secp256k1.sign requires a preloaded wasmWallet.",
920
924
  );
921
925
  }
922
- const digest = new Uint8Array(
923
- wasmWallet.utils.sha256(toUint8Array(message)),
924
- );
926
+ // ECDSA over sha256(message): the wallet's sign hashes once
925
927
  const rawSignature = new Uint8Array(
926
- wasmWallet.curves.secp256k1.sign(digest, toUint8Array(privateKey)),
928
+ wasmWallet.curves.secp256k1.sign(toUint8Array(message), toUint8Array(privateKey)),
927
929
  );
928
930
  return rawSignatureToDer(rawSignature);
929
931
  },
930
932
  verify: (message, signature, publicKey) => {
931
933
  this.#assertCapability("crypto_verify", "crypto.secp256k1.verify");
932
- if (
933
- !wasmWallet?.utils?.sha256 ||
934
- !wasmWallet?.curves?.secp256k1?.verify
935
- ) {
934
+ if (!wasmWallet?.curves?.secp256k1?.verify) {
936
935
  throw new Error(
937
936
  "Browser host crypto.secp256k1.verify requires a preloaded wasmWallet.",
938
937
  );
939
938
  }
940
- const digest = new Uint8Array(
941
- wasmWallet.utils.sha256(toUint8Array(message)),
942
- );
943
939
  const result = wasmWallet.curves.secp256k1.verify(
944
- digest,
940
+ toUint8Array(message),
945
941
  derSignatureToRaw(signature),
946
942
  toUint8Array(publicKey),
947
943
  );
@@ -1226,6 +1222,9 @@ export class BrowserHost {
1226
1222
  if (ADAPTER_OPERATIONS[normalized]) {
1227
1223
  return this.serveAdapterOperation(normalized, params);
1228
1224
  }
1225
+ if (IPFS_ADAPTER_OPERATIONS.includes(normalized)) {
1226
+ return this.ipfs[normalized.slice(5)](params);
1227
+ }
1229
1228
  throw new Error(`Unknown browser host operation "${normalized}".`);
1230
1229
  }
1231
1230
  }