@ethernity-cloud/sdk-js 1.5.1 → 1.5.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.
@@ -60,6 +60,7 @@ function configure({ identityPriv, swiftStreamService, bucket, contractAddress,
60
60
  _bucket = bucket;
61
61
  _contractAddress = contractAddress;
62
62
  _provider = provider;
63
+ _esrLedger = [];
63
64
  }
64
65
 
65
66
  function keccak256(buf) {
@@ -157,11 +158,20 @@ function keyHash(key) {
157
158
 
158
159
  const ESR_ABI = [
159
160
  'function commit(bytes32 key, string newCID, uint256 expectedVersion)',
161
+ 'function commitFor(address enclave, bytes32 key, string newCID, uint256 expectedVersion, uint256 relayNonce, bytes signature)',
162
+ 'function commitDigest(address enclave, bytes32 key, string newCID, uint256 expectedVersion, uint256 relayNonce) view returns (bytes32)',
163
+ 'function relayNonce(address enclave) view returns (uint256)',
160
164
  'function getState(address enclave, bytes32 key) view returns (string cid, uint256 version, uint64 updatedAt)',
161
165
  'function getVersion(address enclave, bytes32 key) view returns (uint256)',
162
166
  'function exists(address enclave, bytes32 key) view returns (bool)'
163
167
  ];
164
168
 
169
+ // Order-wide ledger of signed authorizations. ESR commits do NOT pay their own
170
+ // gas (see contracts/esr/RELAY-DESIGN.md): the enclave only SIGNS each commit
171
+ // (commitFor); the NODE relays it and pays, and does all gas accounting. The
172
+ // securelock does no gas math -- nothing it could claim about cost is trusted.
173
+ let _esrLedger = [];
174
+
165
175
  class StateRegistry {
166
176
  constructor() {
167
177
  if (!_contractAddress) {
@@ -290,9 +300,39 @@ class StateRegistry {
290
300
  }
291
301
 
292
302
  async _sendCommit(keyHashHex, cid, expectedVersion) {
293
- const contract = this._contract(this._signer());
294
- const tx = await contract.commit(keyHashHex, cid, expectedVersion);
295
- return tx.wait();
303
+ // The enclave never pays gas and does NO gas math: it SIGNS the commit
304
+ // (commitFor) and stages the signed authorization for the node, which
305
+ // relays it and pays. The trustedzone independently re-prices the whole
306
+ // ledger and adjudicates. Nothing the securelock could claim about cost is
307
+ // trusted, so it claims nothing.
308
+ const signer = this._signer();
309
+ const enclave = await signer.getAddress();
310
+ const contract = this._contract();
311
+
312
+ const relayNonce = await contract.relayNonce(enclave);
313
+ const digest = await contract.commitDigest(
314
+ enclave, keyHashHex, cid, expectedVersion, relayNonce);
315
+ // Sign the raw 32-byte digest as an eth_sign message (matches the
316
+ // contract's "\x19Ethereum Signed Message:\n32" recovery).
317
+ const signature = await signer.signMessage(ethers.utils.arrayify(digest));
318
+
319
+ const auth = {
320
+ enclave,
321
+ keyHash: keyHashHex,
322
+ cid,
323
+ expectedVersion: Number(expectedVersion),
324
+ relayNonce: Number(relayNonce),
325
+ signature
326
+ };
327
+
328
+ _esrLedger.push(auth);
329
+ await _swift.putFileContent(
330
+ _bucket, 'esr.authorizations.json', '',
331
+ Buffer.from(JSON.stringify(_esrLedger), 'utf8'));
332
+ await _swift.putFileContent(
333
+ _bucket, `esr.commit.${Number(relayNonce)}.json`, '',
334
+ Buffer.from(JSON.stringify(auth), 'utf8'));
335
+ return { relayed: true, relayNonce: Number(relayNonce) };
296
336
  }
297
337
  }
298
338
 
@@ -15,6 +15,8 @@ class TaskStatus {
15
15
  // address that was never baked into the sealed image). Reported eagerly
16
16
  // with the variable named, instead of a confusing downstream crash.
17
17
  static CONFIG_ERROR = 32;
18
+ static EXECUTION_TIMEOUT = 33; // Started but produced no result within the order duration.
19
+ static ESR_GAS_LIMIT_EXCEEDED = 34; // ESR commits would exceed the per-order relayed-gas budget.
18
20
  }
19
21
 
20
22
  module.exports = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ethernity-cloud/sdk-js",
3
- "version": "1.5.1",
3
+ "version": "1.5.2",
4
4
  "description": "A package to run ethernity cloud build scripts",
5
5
  "scripts": {
6
6
  "ecld-build": "cross-env node ./node_modules/@ethernity-cloud/sdk-js/build.js",