@hazae41/bobine 0.0.7 → 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 +48 -24
- package/out/mod.js +1 -16
- package/out/mods/server/bin.js +5 -5
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -4,6 +4,8 @@ A blockchain in your garage
|
|
|
4
4
|
|
|
5
5
|
https://bobine.tech/
|
|
6
6
|
|
|
7
|
+
[**📦 NPM**](https://www.npmjs.com/package/@hazae41/bobine) • [**📦 JSR**](https://jsr.io/@hazae41/bobine)
|
|
8
|
+
|
|
7
9
|
## Features
|
|
8
10
|
|
|
9
11
|
- Ultra simple
|
|
@@ -15,11 +17,19 @@ https://bobine.tech/
|
|
|
15
17
|
|
|
16
18
|
\* There are no built-in accounting concepts, only pure generic APIs for cryptography and storage
|
|
17
19
|
|
|
18
|
-
##
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
### Running the server
|
|
23
|
+
|
|
24
|
+
#### Running the server via binary
|
|
19
25
|
|
|
20
|
-
|
|
26
|
+
Install the binary with Deno
|
|
21
27
|
|
|
22
|
-
|
|
28
|
+
```bash
|
|
29
|
+
deno install -gf -A jsr:@hazae41/bobine
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Generate an Ed25519 keypair by running the following code in your browser/deno/node/bun console
|
|
23
33
|
|
|
24
34
|
```typescript
|
|
25
35
|
const keypair = await crypto.subtle.generateKey("Ed25519", true, ["sign", "verify"])
|
|
@@ -44,19 +54,35 @@ ED25519_PRIVATE_KEY_HEX=302e020100300506032b657004220420edff8b2503b91f58bc0f0435
|
|
|
44
54
|
ED25519_PUBLIC_KEY_HEX=90dcd81a473a4e59a84df6cb8f77af3d34c7fd6171ed959ca04a75f07a57b4b9
|
|
45
55
|
```
|
|
46
56
|
|
|
47
|
-
Run the server
|
|
57
|
+
Run the server
|
|
48
58
|
|
|
49
59
|
```bash
|
|
50
|
-
|
|
60
|
+
bobine serve --env=./.env.local
|
|
51
61
|
```
|
|
52
62
|
|
|
53
|
-
|
|
63
|
+
#### Running the server via library
|
|
54
64
|
|
|
55
65
|
Install `@hazae41/bobine` and use the `serve()` function
|
|
56
66
|
|
|
57
|
-
|
|
67
|
+
### Creating a module
|
|
68
|
+
|
|
69
|
+
#### Creating a module via binary
|
|
58
70
|
|
|
59
|
-
|
|
71
|
+
Install the binary with Deno
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
deno install -gf -A jsr:@hazae41/bobine
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Deploy your .wasm file
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
bobine create ./module.wasm --server=http://localhost:8080
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Using the HTTP API
|
|
84
|
+
|
|
85
|
+
#### POST /api/create
|
|
60
86
|
|
|
61
87
|
Creates a new module using some WebAssembly code and some unique salt
|
|
62
88
|
|
|
@@ -68,7 +94,7 @@ Accepts a form data with the following fields
|
|
|
68
94
|
|
|
69
95
|
- `effort` as bytes = some unique 32 bytes whose sha256 `hash` validates `((2n ** 256n) / BigInt("0x" + hash.toHex())) > (code.length + salt.length)`
|
|
70
96
|
|
|
71
|
-
|
|
97
|
+
#### POST /api/execute
|
|
72
98
|
|
|
73
99
|
Execute some function on a module
|
|
74
100
|
|
|
@@ -82,7 +108,7 @@ Accepts a form data with the following fields
|
|
|
82
108
|
|
|
83
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
|
|
84
110
|
|
|
85
|
-
|
|
111
|
+
#### POST /api/simulate
|
|
86
112
|
|
|
87
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)
|
|
88
114
|
|
|
@@ -96,11 +122,11 @@ Accepts a form data with the following fields
|
|
|
96
122
|
|
|
97
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
|
|
98
124
|
|
|
99
|
-
|
|
125
|
+
### Using the WebAssembly API
|
|
100
126
|
|
|
101
127
|
The WebAssembly VM extensively uses reference types for its API and for module-to-module communication
|
|
102
128
|
|
|
103
|
-
|
|
129
|
+
#### Using the WebAssembly API via AssemblyScript
|
|
104
130
|
|
|
105
131
|
You can use [stdbob](https://github.com/hazae41/stdbob) to easily import AssemblyScript declarations for all internal modules
|
|
106
132
|
|
|
@@ -118,9 +144,7 @@ And you can declare external modules by using the module address as hex
|
|
|
118
144
|
declare function add(x: externref, y: externref): externref
|
|
119
145
|
```
|
|
120
146
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
#### blobs
|
|
147
|
+
#### Blobs module
|
|
124
148
|
|
|
125
149
|
You can pass bytes between modules by storing them in the blob storage and loading them via reference
|
|
126
150
|
|
|
@@ -134,7 +158,7 @@ You can pass bytes between modules by storing them in the blob storage and loadi
|
|
|
134
158
|
|
|
135
159
|
- `blob.to_hex/from_hex/to_base64/from_base64(blob: blobref): blobref` = convert blobs to/from hex/base64 without loading them into memory
|
|
136
160
|
|
|
137
|
-
####
|
|
161
|
+
#### BigInts module
|
|
138
162
|
|
|
139
163
|
You can work with infinite-precision bigints
|
|
140
164
|
|
|
@@ -160,7 +184,7 @@ You can work with infinite-precision bigints
|
|
|
160
184
|
|
|
161
185
|
- `bigints.from_base10(base16: blobref): bigintref` = convert base10 utf8 bytes to bigint
|
|
162
186
|
|
|
163
|
-
####
|
|
187
|
+
#### Packs module
|
|
164
188
|
|
|
165
189
|
You can pack various arguments (numbers, refs) into a pack which can be passed between modules and/or encoded/decoded into bytes
|
|
166
190
|
|
|
@@ -217,7 +241,7 @@ function writePack(pack: packref) {
|
|
|
217
241
|
|
|
218
242
|
- `packs.length(pack: packref): i32` = get the length of a pack
|
|
219
243
|
|
|
220
|
-
####
|
|
244
|
+
#### Environment module
|
|
221
245
|
|
|
222
246
|
Get infos about the executing environment
|
|
223
247
|
|
|
@@ -225,7 +249,7 @@ Get infos about the executing environment
|
|
|
225
249
|
|
|
226
250
|
- `env.uuid(): blobref` = get the unique uuid of this environment (similar to a chain id)
|
|
227
251
|
|
|
228
|
-
####
|
|
252
|
+
#### Modules module
|
|
229
253
|
|
|
230
254
|
Modules are identified by their address as a blob of bytes (pure sha256-output 32-length bytes without any encoding)
|
|
231
255
|
|
|
@@ -237,7 +261,7 @@ Modules are identified by their address as a blob of bytes (pure sha256-output 3
|
|
|
237
261
|
|
|
238
262
|
- `modules.self(): blobref` = get your module address as blob
|
|
239
263
|
|
|
240
|
-
####
|
|
264
|
+
#### Storage module
|
|
241
265
|
|
|
242
266
|
You can use a private storage (it works like storage and events at the same time)
|
|
243
267
|
|
|
@@ -245,13 +269,13 @@ You can use a private storage (it works like storage and events at the same time
|
|
|
245
269
|
|
|
246
270
|
- `storage.get(key: blobref): blobref` = get the latest value from storage at key
|
|
247
271
|
|
|
248
|
-
####
|
|
272
|
+
#### SHA-256 module
|
|
249
273
|
|
|
250
274
|
Use the SHA-256 hashing algorithm
|
|
251
275
|
|
|
252
276
|
- `sha256.digest(payload: blobref): blobref` = hash the payload and returns the digest
|
|
253
277
|
|
|
254
|
-
####
|
|
278
|
+
#### Ed25519 module
|
|
255
279
|
|
|
256
280
|
Use the Ed25519 signing algorithm
|
|
257
281
|
|
|
@@ -259,11 +283,11 @@ Use the Ed25519 signing algorithm
|
|
|
259
283
|
|
|
260
284
|
- `ed25519.sign(payload: blobref): blobref` = (experimental) sign payload using the miner's private key
|
|
261
285
|
|
|
262
|
-
####
|
|
286
|
+
#### Symbols module (experimental)
|
|
263
287
|
|
|
264
288
|
- `symbols.create(): symbolref` = create a unique reference that can be passed around
|
|
265
289
|
|
|
266
|
-
####
|
|
290
|
+
#### References module (experimental)
|
|
267
291
|
|
|
268
292
|
- `refs.numerize(ref: symbolref/blobref/packref): i32` = translate any reference into a unique private pointer that can be stored into data structures
|
|
269
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("
|
|
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) {
|
package/out/mods/server/bin.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
13
|
+
options.port = Number(arg.slice("--port=".length));
|
|
14
14
|
continue;
|
|
15
15
|
}
|
|
16
16
|
if (arg.startsWith("--cert=")) {
|
|
17
|
-
|
|
17
|
+
options.cert = readFileSync(arg.slice("--cert=".length), "utf8");
|
|
18
18
|
continue;
|
|
19
19
|
}
|
|
20
20
|
if (arg.startsWith("--key=")) {
|
|
21
|
-
|
|
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, } =
|
|
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.
|
|
4
|
+
"version": "0.0.9",
|
|
5
5
|
"description": "A blockchain in your garage",
|
|
6
6
|
"repository": "github:hazae41/bobine",
|
|
7
7
|
"author": "hazae41",
|
|
@@ -46,6 +46,6 @@
|
|
|
46
46
|
"unit-tested"
|
|
47
47
|
],
|
|
48
48
|
"bin": {
|
|
49
|
-
"bobine": "./out/
|
|
49
|
+
"bobine": "./out/mod.js"
|
|
50
50
|
}
|
|
51
51
|
}
|