@hazae41/bobine 0.0.20 → 0.0.22

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/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Bobine
1
+ # Bobine 🧵
2
2
 
3
3
  A blockchain in your garage
4
4
 
@@ -19,6 +19,10 @@ deno install -gf -A npm:@hazae41/bobine
19
19
 
20
20
  \* There are no built-in accounting concepts, only pure generic APIs for cryptography and storage
21
21
 
22
+ ## Ecosystem
23
+
24
+ - [Awesome Bobine](https://github.com/hazae41/awesome-bobine) / A curated list on Bobine ecosystem
25
+
22
26
  ## Usage
23
27
 
24
28
  ### Running the server
@@ -1,12 +1,11 @@
1
- // deno-lint-ignore-file prefer-const
2
1
  import * as Wasm from "@hazae41/wasm";
3
2
  export function meter(module, from, name) {
4
3
  let wtype = module.body.sections.find(section => section.kind === Wasm.TypeSection.kind);
5
4
  let wimport = module.body.sections.find(section => section.kind === Wasm.ImportSection.kind);
6
- let wexport = module.body.sections.find(section => section.kind === Wasm.ExportSection.kind);
7
- let wcode = module.body.sections.find(section => section.kind === Wasm.CodeSection.kind);
8
- let welem = module.body.sections.find(section => section.kind === Wasm.ElementSection.kind);
9
- let wstart = module.body.sections.find(section => section.kind === Wasm.StartSection.kind);
5
+ const wexport = module.body.sections.find(section => section.kind === Wasm.ExportSection.kind);
6
+ const wcode = module.body.sections.find(section => section.kind === Wasm.CodeSection.kind);
7
+ const welem = module.body.sections.find(section => section.kind === Wasm.ElementSection.kind);
8
+ const wstart = module.body.sections.find(section => section.kind === Wasm.StartSection.kind);
10
9
  if (wtype == null) {
11
10
  wtype = new Wasm.TypeSection([]);
12
11
  module.body.sections.unshift(wtype);
@@ -1,4 +1,4 @@
1
- // deno-lint-ignore-file no-namespace
1
+ /// <reference types="../bytes/lib.d.ts"/>
2
2
  export class Packed {
3
3
  value;
4
4
  constructor(value) {
@@ -46,7 +46,7 @@ export class Packed {
46
46
  if (value == null)
47
47
  return 1;
48
48
  if (typeof value === "number")
49
- return 1 + 4;
49
+ return 1 + 8;
50
50
  if (value instanceof Uint8Array)
51
51
  return 1 + 4 + value.length;
52
52
  if (typeof value === "string")
@@ -1,7 +1,7 @@
1
1
  /// <reference lib="webworker" />
2
+ import { runAsImmediateOrThrow } from "../../libs/sql/mod.js";
2
3
  import { RpcMethodNotFoundError } from "@hazae41/jsonrpc";
3
4
  import { connect } from "@tursodatabase/database";
4
- import { runAsImmediateOrThrow } from "../../libs/sql/mod.js";
5
5
  const config = await fetch(self.name).then(res => res.json());
6
6
  const ed25519PvtkeyAsHex = config.ed25519.pvtKeyAsHex;
7
7
  const ed25519PvtkeyAsBytes = Uint8Array.fromHex(ed25519PvtkeyAsHex);
@@ -58,9 +58,11 @@ export async function main(args) {
58
58
  response.headers.set("Access-Control-Allow-Headers", "*");
59
59
  return response;
60
60
  }
61
- catch (cause) {
62
- console.error(cause);
63
- return new Response("Error", { status: 500 });
61
+ catch (error) {
62
+ console.error(error);
63
+ if (error instanceof Error)
64
+ return new Response(error.message, { status: 500 });
65
+ return new Response(null, { status: 500 });
64
66
  }
65
67
  };
66
68
  Deno.serve({ hostname: "0.0.0.0", port, cert, key }, onHttpRequest);
@@ -1,4 +1,3 @@
1
- // deno-lint-ignore-file no-cond-assign no-unused-vars require-await
2
1
  var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
3
2
  if (value !== null && value !== void 0) {
4
3
  if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
@@ -51,6 +50,7 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
51
50
  var e = new Error(message);
52
51
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
53
52
  });
53
+ import { Packed } from "../../libs/packed/mod.js";
54
54
  import { Readable, Writable } from "@hazae41/binary";
55
55
  import { RpcRequest, RpcResponse } from "@hazae41/jsonrpc";
56
56
  import { Mutex } from "@hazae41/mutex";
@@ -58,7 +58,6 @@ import { connect } from "@tursodatabase/database";
58
58
  import { existsSync, mkdirSync, symlinkSync, writeFileSync } from "node:fs";
59
59
  import { dirname } from "node:path";
60
60
  import process from "node:process";
61
- import { Packed } from "../../libs/packed/mod.js";
62
61
  export async function serveWithEnv(prefix = "") {
63
62
  const { DATABASE_PATH = process.env[prefix + "DATABASE_PATH"], SCRIPTS_PATH = process.env[prefix + "SCRIPTS_PATH"], ED25519_PRIVATE_KEY_HEX = process.env[prefix + "ED25519_PRIVATE_KEY_HEX"], ED25519_PUBLIC_KEY_HEX = process.env[prefix + "ED25519_PUBLIC_KEY_HEX"], } = {};
64
63
  if (DATABASE_PATH == null)
@@ -1,12 +1,12 @@
1
- // deno-lint-ignore-file no-explicit-any no-unused-vars ban-unused-ignore
2
1
  /// <reference lib="webworker" />
2
+ import { meter } from "../../libs/metering/mod.js";
3
+ import { Packed } from "../../libs/packed/mod.js";
3
4
  import { Readable, Writable } from "@hazae41/binary";
4
5
  import { RpcErr, RpcError, RpcMethodNotFoundError, RpcOk } from "@hazae41/jsonrpc";
5
6
  import * as Wasm from "@hazae41/wasm";
6
7
  import { Buffer } from "node:buffer";
7
8
  import { existsSync, readFileSync, symlinkSync, writeFileSync } from "node:fs";
8
- import { meter } from "../../libs/metering/mod.js";
9
- import { Packed } from "../../libs/packed/mod.js";
9
+ import process from "node:process";
10
10
  const config = await fetch(self.name).then(res => res.json());
11
11
  const helper = new Worker(import.meta.resolve("../helper/bin.js"), { name: self.name, type: "module" });
12
12
  function run(module, method, params, mode, maxsparks) {
@@ -24,9 +24,13 @@ function run(module, method, params, mode, maxsparks) {
24
24
  };
25
25
  const sparks_consume = (amount) => {
26
26
  sparks += amount;
27
- if (maxsparks != null && sparks > maxsparks)
28
- throw new Error("Out of sparks");
29
- return;
27
+ if (process.env.NODE_ENV !== "production")
28
+ return;
29
+ if (maxsparks == null)
30
+ return;
31
+ if (sparks < maxsparks)
32
+ return;
33
+ throw new Error("Out of sparks");
30
34
  };
31
35
  const sha256_digest = (payload) => {
32
36
  sparks_consume(BigInt(payload.length) * 256n);
@@ -65,12 +69,15 @@ function run(module, method, params, mode, maxsparks) {
65
69
  const imports = {};
66
70
  imports["env"] = {
67
71
  mode: mode,
68
- abort: () => {
69
- throw new Error("Aborted");
72
+ abort: (...args) => {
73
+ return;
70
74
  },
71
75
  uuid: () => {
72
76
  return "17fa1cb5-c5af-4cfd-9bea-1a36590b890d";
73
- }
77
+ },
78
+ panic: (message) => {
79
+ throw new Error(message);
80
+ },
74
81
  };
75
82
  imports["sparks"] = {
76
83
  remaining: () => {
@@ -83,6 +90,8 @@ function run(module, method, params, mode, maxsparks) {
83
90
  imports["console"] = {
84
91
  log: (text) => {
85
92
  logs.push(text);
93
+ console.log(text);
94
+ return;
86
95
  }
87
96
  };
88
97
  imports["blobs"] = {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@hazae41/bobine",
4
- "version": "0.0.20",
4
+ "version": "0.0.22",
5
5
  "description": "A blockchain in your garage",
6
6
  "repository": "github:hazae41/bobine",
7
7
  "author": "hazae41",