@hazae41/stdbob 0.0.2 → 0.0.6
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 +25 -3
- package/package.json +2 -2
- package/src/mods/bigints/mod.ts +9 -9
- package/src/mods/blobs/mod.ts +23 -13
- package/src/mods/env/mod.ts +1 -1
- package/src/mods/mod.ts +1 -1
- package/src/mods/packs/mod.ts +2 -2
- package/src/mods/refs/mod.ts +2 -2
- package/src/mods/texts/mod.ts +47 -0
- package/src/mods/address/mod.ts +0 -33
package/README.md
CHANGED
|
@@ -1,9 +1,31 @@
|
|
|
1
1
|
# stdbob
|
|
2
2
|
|
|
3
|
-
Standard libraries for Bobine WebAssembly VM
|
|
3
|
+
Standard libraries for [Bobine WebAssembly VM](https://github.com/hazae41/bobine)
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
|
-
npm install @hazae41/
|
|
6
|
+
npm install @hazae41/stdbob
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
-
[**📦 NPM**](https://www.npmjs.com/package/@hazae41/stdbob)
|
|
9
|
+
[**📦 NPM**](https://www.npmjs.com/package/@hazae41/stdbob)
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### AssemblyScript
|
|
14
|
+
|
|
15
|
+
Just import the library from your AssemblyScript file
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import { modules, blobref } from "@hazae41/stdbob"
|
|
19
|
+
|
|
20
|
+
export function main(): blobref {
|
|
21
|
+
return modules.self()
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
And compile with `reference-types` enabled and `stub` runtime
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
asc ./mod.ts -o ./mod.wasm --runtime stub --enable reference-types
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Then deploy the .wasm file to your Bobine VM
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@hazae41/stdbob",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.6",
|
|
5
5
|
"description": "Standard libraries for Bobine WebAssembly VM",
|
|
6
6
|
"repository": "github:hazae41/stdbob",
|
|
7
7
|
"author": "hazae41",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"scripts": {
|
|
10
|
-
"
|
|
10
|
+
"prepack": "rm -rf ./out && asc ./src/bin.ts -o ./out/bin.wasm --runtime stub --enable reference-types"
|
|
11
11
|
},
|
|
12
12
|
"devDependencies": {
|
|
13
13
|
"assemblyscript": "^0.28.9"
|
package/src/mods/bigints/mod.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { blobref } from "../blobs/mod";
|
|
2
|
+
import { textref } from "../texts/mod";
|
|
2
3
|
|
|
3
4
|
export type bigintref = externref
|
|
4
5
|
|
|
@@ -84,20 +85,19 @@ export namespace bigints {
|
|
|
84
85
|
@external("bigints", "decode")
|
|
85
86
|
export declare function decode(blob: blobref): bigintref
|
|
86
87
|
|
|
87
|
-
// @ts-ignore: decorator
|
|
88
|
-
@external("bigints", "to_base16")
|
|
89
|
-
export declare function toBase16(bigint: bigintref): blobref
|
|
90
|
-
|
|
91
88
|
// @ts-ignore: decorator
|
|
92
89
|
@external("bigints", "from_base16")
|
|
93
|
-
export declare function fromBase16(
|
|
90
|
+
export declare function fromBase16(text: textref): bigintref
|
|
94
91
|
|
|
95
92
|
// @ts-ignore: decorator
|
|
96
|
-
@external("bigints", "
|
|
97
|
-
export declare function
|
|
98
|
-
|
|
93
|
+
@external("bigints", "to_base16")
|
|
94
|
+
export declare function toBase16(bigint: bigintref): textref
|
|
99
95
|
// @ts-ignore: decorator
|
|
100
96
|
@external("bigints", "from_base10")
|
|
101
|
-
export declare function fromBase10(
|
|
97
|
+
export declare function fromBase10(text: textref): bigintref
|
|
98
|
+
|
|
99
|
+
// @ts-ignore: decorator
|
|
100
|
+
@external("bigints", "to_base10")
|
|
101
|
+
export declare function toBase10(bigint: bigintref): textref
|
|
102
102
|
|
|
103
103
|
}
|
package/src/mods/blobs/mod.ts
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
|
+
import { textref } from "../texts/mod"
|
|
2
|
+
|
|
1
3
|
export type blobref = externref
|
|
2
4
|
|
|
3
5
|
export namespace blobs {
|
|
4
6
|
|
|
5
7
|
// @ts-ignore: decorator
|
|
6
8
|
@external("blobs", "save")
|
|
7
|
-
export declare function $save(offset:
|
|
8
|
-
|
|
9
|
-
// @ts-ignore: decorator
|
|
10
|
-
@external("blobs", "size")
|
|
11
|
-
export declare function $size(blob: blobref): usize
|
|
9
|
+
export declare function $save(offset: i32, length: i32): blobref
|
|
12
10
|
|
|
13
11
|
// @ts-ignore: decorator
|
|
14
12
|
@external("blobs", "load")
|
|
15
|
-
export declare function $load(blob: blobref, offset:
|
|
13
|
+
export declare function $load(blob: blobref, offset: i32): void
|
|
16
14
|
|
|
17
15
|
export function save(buffer: ArrayBuffer): blobref {
|
|
18
16
|
const bytes = Uint8Array.wrap(buffer)
|
|
@@ -23,13 +21,17 @@ export namespace blobs {
|
|
|
23
21
|
}
|
|
24
22
|
|
|
25
23
|
export function load(blob: blobref): ArrayBuffer {
|
|
26
|
-
const bytes = new Uint8Array(<i32
|
|
24
|
+
const bytes = new Uint8Array(<i32>length(blob))
|
|
27
25
|
|
|
28
26
|
$load(blob, bytes.dataStart)
|
|
29
27
|
|
|
30
28
|
return bytes.buffer
|
|
31
29
|
}
|
|
32
30
|
|
|
31
|
+
// @ts-ignore: decorator
|
|
32
|
+
@external("blobs", "length")
|
|
33
|
+
export declare function length(blob: blobref): i32
|
|
34
|
+
|
|
33
35
|
// @ts-ignore: decorator
|
|
34
36
|
@external("blobs", "concat")
|
|
35
37
|
export declare function concat(left: blobref, right: blobref): blobref
|
|
@@ -39,19 +41,27 @@ export namespace blobs {
|
|
|
39
41
|
export declare function equals(left: blobref, right: blobref): bool
|
|
40
42
|
|
|
41
43
|
// @ts-ignore: decorator
|
|
42
|
-
@external("blobs", "
|
|
43
|
-
export declare function
|
|
44
|
+
@external("blobs", "includes")
|
|
45
|
+
export declare function includes(haystack: blobref, needle: blobref): bool
|
|
46
|
+
|
|
47
|
+
// @ts-ignore: decorator
|
|
48
|
+
@external("blobs", "slice")
|
|
49
|
+
export declare function slice(blob: blobref, start: i32, until: i32): blobref
|
|
44
50
|
|
|
45
51
|
// @ts-ignore: decorator
|
|
46
52
|
@external("blobs", "from_base16")
|
|
47
|
-
export declare function fromBase16(
|
|
53
|
+
export declare function fromBase16(text: textref): blobref
|
|
48
54
|
|
|
49
55
|
// @ts-ignore: decorator
|
|
50
|
-
@external("blobs", "
|
|
51
|
-
export declare function
|
|
56
|
+
@external("blobs", "to_base16")
|
|
57
|
+
export declare function toBase16(blob: blobref): textref
|
|
52
58
|
|
|
53
59
|
// @ts-ignore: decorator
|
|
54
60
|
@external("blobs", "from_base64")
|
|
55
|
-
export declare function fromBase64(
|
|
61
|
+
export declare function fromBase64(text: textref): blobref
|
|
62
|
+
|
|
63
|
+
// @ts-ignore: decorator
|
|
64
|
+
@external("blobs", "to_base64")
|
|
65
|
+
export declare function toBase64(blob: blobref): textref
|
|
56
66
|
|
|
57
67
|
}
|
package/src/mods/env/mod.ts
CHANGED
package/src/mods/mod.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export * from "./address/mod";
|
|
2
1
|
export * from "./bigints/mod";
|
|
3
2
|
export * from "./blobs/mod";
|
|
4
3
|
export * from "./console/mod";
|
|
@@ -10,4 +9,5 @@ export * from "./refs/mod";
|
|
|
10
9
|
export * from "./sha256/mod";
|
|
11
10
|
export * from "./storage/mod";
|
|
12
11
|
export * from "./symbols/mod";
|
|
12
|
+
export * from "./texts/mod";
|
|
13
13
|
|
package/src/mods/packs/mod.ts
CHANGED
|
@@ -54,10 +54,10 @@ export namespace packs {
|
|
|
54
54
|
|
|
55
55
|
// @ts-ignore: decorator: decorator
|
|
56
56
|
@external("packs", "length")
|
|
57
|
-
export declare function length(pack: packref):
|
|
57
|
+
export declare function length(pack: packref): i32
|
|
58
58
|
|
|
59
59
|
// @ts-ignore: decorator
|
|
60
60
|
@external("packs", "get")
|
|
61
|
-
export declare function get<T>(pack: packref, index:
|
|
61
|
+
export declare function get<T>(pack: packref, index: i32): T
|
|
62
62
|
|
|
63
63
|
}
|
package/src/mods/refs/mod.ts
CHANGED
|
@@ -2,10 +2,10 @@ export namespace refs {
|
|
|
2
2
|
|
|
3
3
|
// @ts-ignore: decorator
|
|
4
4
|
@external("refs", "numerize")
|
|
5
|
-
export declare function numerize(ref: externref):
|
|
5
|
+
export declare function numerize(ref: externref): i32
|
|
6
6
|
|
|
7
7
|
// @ts-ignore: decorator
|
|
8
8
|
@external("refs", "denumerize")
|
|
9
|
-
export declare function denumerize(index:
|
|
9
|
+
export declare function denumerize(index: i32): externref
|
|
10
10
|
|
|
11
11
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { blobref } from "../mod";
|
|
2
|
+
|
|
3
|
+
export type textref = externref
|
|
4
|
+
|
|
5
|
+
export namespace texts {
|
|
6
|
+
|
|
7
|
+
// @ts-ignore: decorator
|
|
8
|
+
@external("texts", "length")
|
|
9
|
+
export declare function length(text: textref): i32
|
|
10
|
+
|
|
11
|
+
// @ts-ignore: decorator
|
|
12
|
+
@external("texts", "concat")
|
|
13
|
+
export declare function concat(left: textref, right: textref): textref
|
|
14
|
+
|
|
15
|
+
// @ts-ignore: decorator
|
|
16
|
+
@external("texts", "equals")
|
|
17
|
+
export declare function equals(left: textref, right: textref): bool
|
|
18
|
+
|
|
19
|
+
// @ts-ignore: decorator
|
|
20
|
+
@external("texts", "includes")
|
|
21
|
+
export declare function includes(haystack: textref, needle: textref): bool
|
|
22
|
+
|
|
23
|
+
// @ts-ignore: decorator
|
|
24
|
+
@external("texts", "slice")
|
|
25
|
+
export declare function slice(text: textref, start: i32, until: i32): textref
|
|
26
|
+
|
|
27
|
+
// @ts-ignore: decorator
|
|
28
|
+
@external("texts", "from_utf8")
|
|
29
|
+
export declare function fromUtf8(blob: blobref): textref
|
|
30
|
+
|
|
31
|
+
// @ts-ignore: decorator
|
|
32
|
+
@external("texts", "to_utf8")
|
|
33
|
+
export declare function toUtf8(text: textref): blobref
|
|
34
|
+
|
|
35
|
+
// @ts-ignore: decorator
|
|
36
|
+
@external("texts", "to_uppercase")
|
|
37
|
+
export declare function toUppercase(text: textref): textref
|
|
38
|
+
|
|
39
|
+
// @ts-ignore: decorator
|
|
40
|
+
@external("texts", "to_lowercase")
|
|
41
|
+
export declare function toLowercase(text: textref): textref
|
|
42
|
+
|
|
43
|
+
// @ts-ignore: decorator
|
|
44
|
+
@external("texts", "trim")
|
|
45
|
+
export declare function trim(text: textref): textref
|
|
46
|
+
|
|
47
|
+
}
|
package/src/mods/address/mod.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { blobref, blobs } from "../blobs/mod"
|
|
2
|
-
import { modules } from "../modules/mod"
|
|
3
|
-
import { packref, packs } from "../packs/mod"
|
|
4
|
-
import { sha256 } from "../sha256/mod"
|
|
5
|
-
|
|
6
|
-
export namespace addresses {
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Compute an address from a module and public key
|
|
10
|
-
* @param module
|
|
11
|
-
* @param pubkey
|
|
12
|
-
* @returns
|
|
13
|
-
*/
|
|
14
|
-
export function compute(module: blobref, pubkey: blobref): blobref {
|
|
15
|
-
return blobs.save(blobs.load(sha256.digest(packs.encode(packs.create2(module, pubkey)))).slice(12))
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Verify a session and return the address
|
|
20
|
-
* @param session
|
|
21
|
-
* @returns
|
|
22
|
-
*/
|
|
23
|
-
export function verify(session: packref): blobref {
|
|
24
|
-
const module = packs.get<blobref>(session, 0)
|
|
25
|
-
const pubkey = packs.get<blobref>(session, 1)
|
|
26
|
-
|
|
27
|
-
if (!packs.get<bool>(modules.call(module, blobs.save(String.UTF8.encode("verify")), packs.create1(session)), 0))
|
|
28
|
-
throw new Error("Invalid session")
|
|
29
|
-
|
|
30
|
-
return compute(module, pubkey)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
}
|