@hazae41/bobine 0.0.8 → 0.0.9

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
@@ -17,9 +17,11 @@ https://bobine.tech/
17
17
 
18
18
  \* There are no built-in accounting concepts, only pure generic APIs for cryptography and storage
19
19
 
20
- ## Running
20
+ ## Usage
21
21
 
22
- ### Binary
22
+ ### Running the server
23
+
24
+ #### Running the server via binary
23
25
 
24
26
  Install the binary with Deno
25
27
 
@@ -58,13 +60,29 @@ Run the server
58
60
  bobine serve --env=./.env.local
59
61
  ```
60
62
 
61
- ### Library
63
+ #### Running the server via library
62
64
 
63
65
  Install `@hazae41/bobine` and use the `serve()` function
64
66
 
65
- ## HTTP API
67
+ ### Creating a module
68
+
69
+ #### Creating a module via binary
70
+
71
+ Install the binary with Deno
72
+
73
+ ```bash
74
+ deno install -gf -A jsr:@hazae41/bobine
75
+ ```
76
+
77
+ Deploy your .wasm file
66
78
 
67
- ### POST /api/create
79
+ ```bash
80
+ bobine create ./module.wasm --server=http://localhost:8080
81
+ ```
82
+
83
+ ### Using the HTTP API
84
+
85
+ #### POST /api/create
68
86
 
69
87
  Creates a new module using some WebAssembly code and some unique salt
70
88
 
@@ -76,7 +94,7 @@ Accepts a form data with the following fields
76
94
 
77
95
  - `effort` as bytes = some unique 32 bytes whose sha256 `hash` validates `((2n ** 256n) / BigInt("0x" + hash.toHex())) > (code.length + salt.length)`
78
96
 
79
- ### POST /api/execute
97
+ #### POST /api/execute
80
98
 
81
99
  Execute some function on a module
82
100
 
@@ -90,7 +108,7 @@ Accepts a form data with the following fields
90
108
 
91
109
  - `effort` as bytes = some unique 32 bytes whose sha256 `hash` whose result in `((2n ** 256n) / BigInt("0x" + hash.toHex()))` will be the maximum number of sparks (gas) used
92
110
 
93
- ### POST /api/simulate
111
+ #### POST /api/simulate
94
112
 
95
113
  Simulate some function on a module (it won't write anything to storage and will execute in mode `2` so verifications such as signatures can be skipped)
96
114
 
@@ -104,11 +122,11 @@ Accepts a form data with the following fields
104
122
 
105
123
  - `effort` as bytes = some unique 32 bytes whose sha256 `hash` whose result in `((2n ** 256n) / BigInt("0x" + hash.toHex()))` will be the maximum number of sparks (gas) used
106
124
 
107
- ## WebAssembly API
125
+ ### Using the WebAssembly API
108
126
 
109
127
  The WebAssembly VM extensively uses reference types for its API and for module-to-module communication
110
128
 
111
- ### AssemblyScript
129
+ #### Using the WebAssembly API via AssemblyScript
112
130
 
113
131
  You can use [stdbob](https://github.com/hazae41/stdbob) to easily import AssemblyScript declarations for all internal modules
114
132
 
@@ -126,9 +144,7 @@ And you can declare external modules by using the module address as hex
126
144
  declare function add(x: externref, y: externref): externref
127
145
  ```
128
146
 
129
- ### All internal modules
130
-
131
- #### blobs
147
+ #### Blobs module
132
148
 
133
149
  You can pass bytes between modules by storing them in the blob storage and loading them via reference
134
150
 
@@ -142,7 +158,7 @@ You can pass bytes between modules by storing them in the blob storage and loadi
142
158
 
143
159
  - `blob.to_hex/from_hex/to_base64/from_base64(blob: blobref): blobref` = convert blobs to/from hex/base64 without loading them into memory
144
160
 
145
- #### bigints
161
+ #### BigInts module
146
162
 
147
163
  You can work with infinite-precision bigints
148
164
 
@@ -168,7 +184,7 @@ You can work with infinite-precision bigints
168
184
 
169
185
  - `bigints.from_base10(base16: blobref): bigintref` = convert base10 utf8 bytes to bigint
170
186
 
171
- #### packs
187
+ #### Packs module
172
188
 
173
189
  You can pack various arguments (numbers, refs) into a pack which can be passed between modules and/or encoded/decoded into bytes
174
190
 
@@ -225,7 +241,7 @@ function writePack(pack: packref) {
225
241
 
226
242
  - `packs.length(pack: packref): i32` = get the length of a pack
227
243
 
228
- #### env
244
+ #### Environment module
229
245
 
230
246
  Get infos about the executing environment
231
247
 
@@ -233,7 +249,7 @@ Get infos about the executing environment
233
249
 
234
250
  - `env.uuid(): blobref` = get the unique uuid of this environment (similar to a chain id)
235
251
 
236
- #### modules
252
+ #### Modules module
237
253
 
238
254
  Modules are identified by their address as a blob of bytes (pure sha256-output 32-length bytes without any encoding)
239
255
 
@@ -245,7 +261,7 @@ Modules are identified by their address as a blob of bytes (pure sha256-output 3
245
261
 
246
262
  - `modules.self(): blobref` = get your module address as blob
247
263
 
248
- #### storage
264
+ #### Storage module
249
265
 
250
266
  You can use a private storage (it works like storage and events at the same time)
251
267
 
@@ -253,13 +269,13 @@ You can use a private storage (it works like storage and events at the same time
253
269
 
254
270
  - `storage.get(key: blobref): blobref` = get the latest value from storage at key
255
271
 
256
- #### sha256
272
+ #### SHA-256 module
257
273
 
258
274
  Use the SHA-256 hashing algorithm
259
275
 
260
276
  - `sha256.digest(payload: blobref): blobref` = hash the payload and returns the digest
261
277
 
262
- #### ed25519
278
+ #### Ed25519 module
263
279
 
264
280
  Use the Ed25519 signing algorithm
265
281
 
@@ -267,11 +283,11 @@ Use the Ed25519 signing algorithm
267
283
 
268
284
  - `ed25519.sign(payload: blobref): blobref` = (experimental) sign payload using the miner's private key
269
285
 
270
- #### symbols (experimental)
286
+ #### Symbols module (experimental)
271
287
 
272
288
  - `symbols.create(): symbolref` = create a unique reference that can be passed around
273
289
 
274
- #### refs (experimental)
290
+ #### References module (experimental)
275
291
 
276
292
  - `refs.numerize(ref: symbolref/blobref/packref): i32` = translate any reference into a unique private pointer that can be stored into data structures
277
293
 
package/out/mod.js CHANGED
@@ -15,24 +15,9 @@ export async function main(args) {
15
15
  await server.main(subargs);
16
16
  return;
17
17
  }
18
- if (arg === "create") {
19
- console.log("Create command is not implemented yet.");
20
- return;
21
- }
22
- if (arg === "execute") {
23
- console.log("Execute command is not implemented yet.");
24
- return;
25
- }
26
- if (arg === "simulate") {
27
- console.log("Simulate command is not implemented yet.");
28
- return;
29
- }
30
18
  break;
31
19
  }
32
- console.log("- serve [--env=<env file as path>] [--port=<port>] [--dev]");
33
- console.log("- create <wasm file as path> [salt as hex]");
34
- console.log("- execute <module as hex> <function name> [args as pack as hex]");
35
- console.log("- simulate <module as hex> <function name> [args as pack as hex]");
20
+ console.log("serve [--env=<env file as path>] [--port=<port>] [--dev]");
36
21
  return;
37
22
  }
38
23
  if (import.meta.main) {
@@ -2,7 +2,7 @@ import { readFileSync } from "node:fs";
2
2
  import process from "node:process";
3
3
  import { serveWithEnv } from "./mod.js";
4
4
  export async function main(args) {
5
- const config = {};
5
+ const options = {};
6
6
  for (let i = 0; i < args.length; i++) {
7
7
  const arg = args[i];
8
8
  if (arg.startsWith("--env=")) {
@@ -10,15 +10,15 @@ export async function main(args) {
10
10
  continue;
11
11
  }
12
12
  if (arg.startsWith("--port=")) {
13
- config.port = Number(arg.slice("--port=".length));
13
+ options.port = Number(arg.slice("--port=".length));
14
14
  continue;
15
15
  }
16
16
  if (arg.startsWith("--cert=")) {
17
- config.cert = readFileSync(arg.slice("--cert=".length), "utf8");
17
+ options.cert = readFileSync(arg.slice("--cert=".length), "utf8");
18
18
  continue;
19
19
  }
20
20
  if (arg.startsWith("--key=")) {
21
- config.key = readFileSync(arg.slice("--key=".length), "utf8");
21
+ options.key = readFileSync(arg.slice("--key=".length), "utf8");
22
22
  continue;
23
23
  }
24
24
  if (arg === "--dev=true") {
@@ -35,7 +35,7 @@ export async function main(args) {
35
35
  }
36
36
  throw new Error(`Unknown argument: ${arg}`);
37
37
  }
38
- const { port = Number(process.env.PORT) || 8080, cert = process.env.CERT != null ? readFileSync(process.env.CERT, "utf8") : undefined, key = process.env.KEY != null ? readFileSync(process.env.KEY, "utf8") : undefined, } = config;
38
+ const { port = Number(process.env.PORT) || 8080, cert = process.env.CERT != null ? readFileSync(process.env.CERT, "utf8") : undefined, key = process.env.KEY != null ? readFileSync(process.env.KEY, "utf8") : undefined, } = options;
39
39
  const server = await serveWithEnv();
40
40
  const route = async (request) => {
41
41
  if (request.method === "OPTIONS")
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@hazae41/bobine",
4
- "version": "0.0.8",
4
+ "version": "0.0.9",
5
5
  "description": "A blockchain in your garage",
6
6
  "repository": "github:hazae41/bobine",
7
7
  "author": "hazae41",