@hazae41/bobine 0.0.11 → 0.0.12

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
@@ -132,150 +132,45 @@ declare function add(x: externref, y: externref): externref
132
132
 
133
133
  You can pass bytes between modules by storing them in the blob storage and loading them via reference
134
134
 
135
- - `blobs.save(offset: i32, length: i32): blobref` = save `length` bytes at `offset` of your memory to the blob storage
136
-
137
- - `blobs.load(blob: blobref, offset: i32): void` = load some blob into your memory at `offset`
138
-
139
- - `blobs.equals(left: blobref, right: blobref): bool` = check if two blobs are equals without loading them into memory
140
-
141
- - `blobs.concat(left: blobref, right: blobref): blobref` = concatenate two blobs without loading them into memory
142
-
143
- - `blob.to_hex/from_hex/to_base64/from_base64(blob: blobref): blobref` = convert blobs to/from hex/base64 without loading them into memory
144
-
145
135
  #### BigInts module
146
136
 
147
- You can work with infinite-precision bigints
148
-
149
- - `bigints.add(left: bigintref, right: bigintref): bigintref` = add two bigints
150
-
151
- - `bigints.sub(left: bigintref, right: bigintref): bigintref` = subtract two bigints
152
-
153
- - `bigints.mul(left: bigintref, right: bigintref): bigintref` = multiply two bigints
154
-
155
- - `bigints.div(left: bigintref, right: bigintref): bigintref` = divide two bigints
137
+ You can work with infinite-precision bigints and convert them with blobs and texts
156
138
 
157
- - `bigints.pow(left: bigintref, right: bigintref): bigintref` = left ** right
158
-
159
- - `bigints.encode(bigint: bigintref): blobref` = convert bigint to bytes
160
-
161
- - `bigints.decode(base16: blobref): bigintref` = convert bytes to bigint
162
-
163
- - `bigints.to_base16(bigint: bigintref): blobref` = convert bigint to hex utf8 bytes
164
-
165
- - `bigints.from_base16(base16: blobref): bigintref` = convert hex utf8 bytes to bigint
166
-
167
- - `bigints.to_base10(bigint: bigintref): blobref` = convert bigint to base10 utf8 bytes
168
-
169
- - `bigints.from_base10(base16: blobref): bigintref` = convert base10 utf8 bytes to bigint
139
+ And many others
170
140
 
171
141
  #### Packs module
172
142
 
173
143
  You can pack various arguments (numbers, refs) into a pack which can be passed between modules and/or encoded/decoded into bytes
174
144
 
175
- - `packs.create(...values: any[]): packref` = create a new pack from the provided values (number, blobref, packref, null)
176
-
177
- - `packs.encode(pack: packref): blobref` = encodes values into bytes using the following pseudocode
178
-
179
- ```tsx
180
- function writePack(pack: packref) {
181
- for (const value of values) {
182
- if (isNull(value)) {
183
- writeUint8(1)
184
- continue
185
- }
186
-
187
- if (isNumber(value)) {
188
- writeUint8(2)
189
- writeFloat64(value, "little-endian")
190
- continue
191
- }
192
-
193
- if (isBigInt(value)) {
194
- writeUint8(3)
195
- writeUint32(value.toHex().length, "little-endian")
196
- writeBytes(value.toHex())
197
- continue
198
- }
199
-
200
- if (isBlobref(value)) {
201
- writeUint8(4)
202
- writeUint32(value.length, "little-endian")
203
- writeBytes(value)
204
- continue
205
- }
206
-
207
- if (isPackref(value)) {
208
- writeUint8(5)
209
- writePack(value)
210
- continue
211
- }
212
-
213
- throw new Error()
214
- }
215
-
216
- writeUint8(0)
217
- }
218
- ```
219
-
220
- - `packs.decode(blob: blobref): packref` = decodes bytes into a pack of values using the same pseudocode but for reading
221
-
222
- - `packs.concat(left: packref, right: packref)` = concatenate two packs into one (basically does `[...left, ...right]`)
223
-
224
- - `packs.get<T>(pack: packref, index: i32): T` = get the value of a pack at `index` (throws if not found)
225
-
226
- - `packs.length(pack: packref): i32` = get the length of a pack
227
-
228
145
  #### Environment module
229
146
 
230
147
  Get infos about the executing environment
231
148
 
232
- - `env.mode: i32` = `1` if execution, `2` is simulation
233
-
234
- - `env.uuid(): blobref` = get the unique uuid of this environment (similar to a chain id)
235
-
236
149
  #### Modules module
237
150
 
238
151
  Modules are identified by their address as a blob of bytes (pure sha256-output 32-length bytes without any encoding)
239
152
 
240
- - `modules.load(module: blobref): blobref` = get the code of module as a blob
241
-
242
- - `modules.call(module: blobref, method: blobref, params: packref): packref` = dynamically call a module method with the given params as pack and return value as a 1-length pack
243
-
244
- - `modules.create(code: blobref, salt: blobref): blobref` = dynamically create a new module with the given code and salt, returns the module address
245
-
246
- - `modules.self(): blobref` = get your module address as blob
153
+ You can dynamically create modules, call modules, get their bytecode
247
154
 
248
155
  #### Storage module
249
156
 
250
- You can use a private storage (it works like storage and events at the same time)
251
-
252
- - `storage.set(key: blobref, value: blobref): void` = set some value to storage at key
253
-
254
- - `storage.get(key: blobref): blobref` = get the latest value from storage at key
157
+ You can use a private key-value storage (it works like storage and events at the same time)
255
158
 
256
159
  #### SHA-256 module
257
160
 
258
161
  Use the SHA-256 hashing algorithm
259
162
 
260
- - `sha256.digest(payload: blobref): blobref` = hash the payload and returns the digest
261
-
262
163
  #### Ed25519 module
263
164
 
264
- Use the Ed25519 signing algorithm
265
-
266
- - `ed25519.verify(pubkey: blobref, signature: blobref, payload: blobref): boolean` = verify a signature
267
-
268
- - `ed25519.sign(payload: blobref): blobref` = (experimental) sign payload using the miner's private key
165
+ Use the Ed25519 signing algorithm to verify any signature and (experimentally) sign payload using the miner's private key
269
166
 
270
167
  #### Symbols module (experimental)
271
168
 
272
- - `symbols.create(): symbolref` = create a unique reference that can be passed around
169
+ Create unique references that can be passed around
273
170
 
274
171
  #### References module (experimental)
275
172
 
276
- - `refs.numerize(ref: symbolref/blobref/packref): i32` = translate any reference into a unique private pointer that can be stored into data structures
277
-
278
- - `refs.denumerize(pointer: i32): symbolref/blobref/packref` = get the exact same reference back from your private pointer
173
+ Translate any reference into a unique private pointer that can be stored into data structures
279
174
 
280
175
  This can be useful if you want to check a reference for authenticity
281
176
 
@@ -92,7 +92,7 @@ export async function serve(config) {
92
92
 
93
93
  module TEXT NOT NULL,
94
94
 
95
- key BLOB NOT NULL,
95
+ key TEXT NOT NULL,
96
96
  value BLOB NOT NULL
97
97
  );`);
98
98
  await database.exec(`CREATE TABLE IF NOT EXISTS moments (
@@ -11,8 +11,8 @@ const helper = new Worker(import.meta.resolve("../helper/bin.js"), { name: self.
11
11
  function run(module, method, params, mode, maxsparks) {
12
12
  let sparks = 0n;
13
13
  const exports = {};
14
- const caches = new Map();
15
14
  const logs = new Array();
15
+ const caches = new Map();
16
16
  const reads = new Array();
17
17
  const writes = new Array();
18
18
  const pack_encode = (pack) => {
@@ -239,14 +239,6 @@ function run(module, method, params, mode, maxsparks) {
239
239
  pow: (left, right) => {
240
240
  return left ** right;
241
241
  },
242
- encode: (bigint) => {
243
- const text = bigint.toString(16);
244
- const data = Uint8Array.fromHex(text.length % 2 === 1 ? "0" + text : text);
245
- return data;
246
- },
247
- decode: (bytes) => {
248
- return BigInt("0x" + bytes.toHex());
249
- },
250
242
  from_base16: (text) => {
251
243
  return BigInt("0x" + text);
252
244
  },
@@ -290,9 +282,10 @@ function run(module, method, params, mode, maxsparks) {
290
282
  }
291
283
  };
292
284
  imports["storage"] = {
293
- set: (key, value) => {
285
+ set: (key, fresh) => {
294
286
  const cache = caches.get(module);
295
- cache.set(key, value);
287
+ cache.set(key, fresh);
288
+ const value = pack_encode(fresh);
296
289
  writes.push([module, key, value]);
297
290
  return;
298
291
  },
@@ -309,9 +302,10 @@ function run(module, method, params, mode, maxsparks) {
309
302
  throw new Error("Internal error");
310
303
  if (result[1] === 2)
311
304
  return null;
312
- const fresh = new Uint8Array(result.buffer, 4 + 4 + 4, result[2]).slice();
305
+ const value = new Uint8Array(result.buffer, 4 + 4 + 4, result[2]).slice();
306
+ const fresh = pack_decode(value);
313
307
  cache.set(key, fresh);
314
- reads.push([module, key, fresh]);
308
+ reads.push([module, key, value]);
315
309
  return fresh;
316
310
  }
317
311
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@hazae41/bobine",
4
- "version": "0.0.11",
4
+ "version": "0.0.12",
5
5
  "description": "A blockchain in your garage",
6
6
  "repository": "github:hazae41/bobine",
7
7
  "author": "hazae41",