@hazae41/stdbob 0.0.1
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/.gitattributes +2 -0
- package/LICENSE.md +19 -0
- package/README.md +9 -0
- package/package.json +15 -0
- package/src/bin.ts +1 -0
- package/src/mod.ts +1 -0
- package/src/mods/address/mod.ts +33 -0
- package/src/mods/bigints/mod.ts +103 -0
- package/src/mods/blobs/mod.ts +57 -0
- package/src/mods/console/mod.ts +9 -0
- package/src/mods/ed25519/mod.ts +9 -0
- package/src/mods/env/mod.ts +17 -0
- package/src/mods/mod.ts +13 -0
- package/src/mods/modules/mod.ts +22 -0
- package/src/mods/packs/mod.ts +63 -0
- package/src/mods/refs/mod.ts +11 -0
- package/src/mods/sha256/mod.ts +9 -0
- package/src/mods/storage/mod.ts +13 -0
- package/src/mods/symbols/mod.ts +9 -0
- package/tsconfig.json +9 -0
package/.gitattributes
ADDED
package/LICENSE.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# MIT
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
package/README.md
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "module",
|
|
3
|
+
"name": "@hazae41/stdbob",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"description": "Standard libraries for Bobine WebAssembly VM",
|
|
6
|
+
"repository": "github:hazae41/stdbob",
|
|
7
|
+
"author": "hazae41",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"examine": "asc --noEmit ./src/bin.ts"
|
|
11
|
+
},
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"assemblyscript": "^0.28.9"
|
|
14
|
+
}
|
|
15
|
+
}
|
package/src/bin.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./mods/mod";
|
package/src/mod.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./mods/mod";
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { blobref } from "../blobs/mod";
|
|
2
|
+
|
|
3
|
+
export type bigintref = externref
|
|
4
|
+
|
|
5
|
+
export namespace bigints {
|
|
6
|
+
|
|
7
|
+
// @ts-ignore: decorator
|
|
8
|
+
@external("bigints", "zero")
|
|
9
|
+
export declare function zero(): bigintref
|
|
10
|
+
|
|
11
|
+
// @ts-ignore: decorator
|
|
12
|
+
@external("bigints", "one")
|
|
13
|
+
export declare function one(): bigintref
|
|
14
|
+
|
|
15
|
+
// @ts-ignore: decorator
|
|
16
|
+
@external("bigints", "two")
|
|
17
|
+
export declare function two(): bigintref
|
|
18
|
+
|
|
19
|
+
// @ts-ignore: decorator
|
|
20
|
+
@external("bigints", "three")
|
|
21
|
+
export declare function three(): bigintref
|
|
22
|
+
|
|
23
|
+
// @ts-ignore: decorator
|
|
24
|
+
@external("bigints", "four")
|
|
25
|
+
export declare function four(): bigintref
|
|
26
|
+
|
|
27
|
+
// @ts-ignore: decorator
|
|
28
|
+
@external("bigints", "five")
|
|
29
|
+
export declare function five(): bigintref
|
|
30
|
+
|
|
31
|
+
// @ts-ignore: decorator
|
|
32
|
+
@external("bigints", "six")
|
|
33
|
+
export declare function six(): bigintref
|
|
34
|
+
|
|
35
|
+
// @ts-ignore: decorator
|
|
36
|
+
@external("bigints", "seven")
|
|
37
|
+
export declare function seven(): bigintref
|
|
38
|
+
|
|
39
|
+
// @ts-ignore: decorator
|
|
40
|
+
@external("bigints", "eight")
|
|
41
|
+
export declare function eight(): bigintref
|
|
42
|
+
|
|
43
|
+
// @ts-ignore: decorator
|
|
44
|
+
@external("bigints", "nine")
|
|
45
|
+
export declare function nine(): bigintref
|
|
46
|
+
|
|
47
|
+
// @ts-ignore: decorator
|
|
48
|
+
@external("bigints", "ten")
|
|
49
|
+
export declare function ten(): bigintref
|
|
50
|
+
|
|
51
|
+
// @ts-ignore: decorator
|
|
52
|
+
@external("bigints", "inc")
|
|
53
|
+
export declare function inc(value: bigintref): bigintref
|
|
54
|
+
|
|
55
|
+
// @ts-ignore: decorator
|
|
56
|
+
@external("bigints", "dec")
|
|
57
|
+
export declare function dec(value: bigintref): bigintref
|
|
58
|
+
|
|
59
|
+
// @ts-ignore: decorator
|
|
60
|
+
@external("bigints", "add")
|
|
61
|
+
export declare function add(left: bigintref, right: bigintref): bigintref
|
|
62
|
+
|
|
63
|
+
// @ts-ignore: decorator
|
|
64
|
+
@external("bigints", "sub")
|
|
65
|
+
export declare function sub(left: bigintref, right: bigintref): bigintref
|
|
66
|
+
|
|
67
|
+
// @ts-ignore: decorator
|
|
68
|
+
@external("bigints", "mul")
|
|
69
|
+
export declare function mul(left: bigintref, right: bigintref): bigintref
|
|
70
|
+
|
|
71
|
+
// @ts-ignore: decorator
|
|
72
|
+
@external("bigints", "div")
|
|
73
|
+
export declare function div(left: bigintref, right: bigintref): bigintref
|
|
74
|
+
|
|
75
|
+
// @ts-ignore: decorator
|
|
76
|
+
@external("bigints", "pow")
|
|
77
|
+
export declare function pow(left: bigintref, right: bigintref): bigintref
|
|
78
|
+
|
|
79
|
+
// @ts-ignore: decorator
|
|
80
|
+
@external("bigints", "encode")
|
|
81
|
+
export declare function encode(bigint: bigintref): blobref
|
|
82
|
+
|
|
83
|
+
// @ts-ignore: decorator
|
|
84
|
+
@external("bigints", "decode")
|
|
85
|
+
export declare function decode(blob: blobref): bigintref
|
|
86
|
+
|
|
87
|
+
// @ts-ignore: decorator
|
|
88
|
+
@external("bigints", "to_base16")
|
|
89
|
+
export declare function toBase16(bigint: bigintref): blobref
|
|
90
|
+
|
|
91
|
+
// @ts-ignore: decorator
|
|
92
|
+
@external("bigints", "from_base16")
|
|
93
|
+
export declare function fromBase16(base16: blobref): bigintref
|
|
94
|
+
|
|
95
|
+
// @ts-ignore: decorator
|
|
96
|
+
@external("bigints", "to_base10")
|
|
97
|
+
export declare function toBase10(bigint: bigintref): blobref
|
|
98
|
+
|
|
99
|
+
// @ts-ignore: decorator
|
|
100
|
+
@external("bigints", "from_base10")
|
|
101
|
+
export declare function fromBase10(base10: blobref): bigintref
|
|
102
|
+
|
|
103
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export type blobref = externref
|
|
2
|
+
|
|
3
|
+
export namespace blobs {
|
|
4
|
+
|
|
5
|
+
// @ts-ignore: decorator
|
|
6
|
+
@external("blobs", "save")
|
|
7
|
+
export declare function $save(offset: usize, length: usize): blobref
|
|
8
|
+
|
|
9
|
+
// @ts-ignore: decorator
|
|
10
|
+
@external("blobs", "size")
|
|
11
|
+
export declare function $size(blob: blobref): usize
|
|
12
|
+
|
|
13
|
+
// @ts-ignore: decorator
|
|
14
|
+
@external("blobs", "load")
|
|
15
|
+
export declare function $load(blob: blobref, offset: usize): void
|
|
16
|
+
|
|
17
|
+
export function save(buffer: ArrayBuffer): blobref {
|
|
18
|
+
const bytes = Uint8Array.wrap(buffer)
|
|
19
|
+
|
|
20
|
+
const reference = $save(bytes.dataStart, bytes.length)
|
|
21
|
+
|
|
22
|
+
return reference
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function load(blob: blobref): ArrayBuffer {
|
|
26
|
+
const bytes = new Uint8Array(<i32>$size(blob))
|
|
27
|
+
|
|
28
|
+
$load(blob, bytes.dataStart)
|
|
29
|
+
|
|
30
|
+
return bytes.buffer
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// @ts-ignore: decorator
|
|
34
|
+
@external("blobs", "concat")
|
|
35
|
+
export declare function concat(left: blobref, right: blobref): blobref
|
|
36
|
+
|
|
37
|
+
// @ts-ignore: decorator
|
|
38
|
+
@external("blobs", "equals")
|
|
39
|
+
export declare function equals(left: blobref, right: blobref): bool
|
|
40
|
+
|
|
41
|
+
// @ts-ignore: decorator
|
|
42
|
+
@external("blobs", "to_base16")
|
|
43
|
+
export declare function toBase16(bytes: blobref): blobref
|
|
44
|
+
|
|
45
|
+
// @ts-ignore: decorator
|
|
46
|
+
@external("blobs", "from_base16")
|
|
47
|
+
export declare function fromBase16(base16: blobref): blobref
|
|
48
|
+
|
|
49
|
+
// @ts-ignore: decorator
|
|
50
|
+
@external("blobs", "to_base64")
|
|
51
|
+
export declare function toBase64(bytes: blobref): blobref
|
|
52
|
+
|
|
53
|
+
// @ts-ignore: decorator
|
|
54
|
+
@external("blobs", "from_base64")
|
|
55
|
+
export declare function fromBase64(base64: blobref): blobref
|
|
56
|
+
|
|
57
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { blobref } from "../blobs/mod";
|
|
2
|
+
|
|
3
|
+
export namespace env {
|
|
4
|
+
|
|
5
|
+
// @ts-ignore: decorator
|
|
6
|
+
@external("env", "mode")
|
|
7
|
+
export declare const mode: usize
|
|
8
|
+
|
|
9
|
+
// @ts-ignore: decorator
|
|
10
|
+
@external("env", "uuid")
|
|
11
|
+
export declare function uuid(): blobref
|
|
12
|
+
|
|
13
|
+
// @ts-ignore: decorator
|
|
14
|
+
@external("env", "test")
|
|
15
|
+
export declare function test(x: blobref): void
|
|
16
|
+
|
|
17
|
+
}
|
package/src/mods/mod.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from "./address/mod";
|
|
2
|
+
export * from "./bigints/mod";
|
|
3
|
+
export * from "./blobs/mod";
|
|
4
|
+
export * from "./console/mod";
|
|
5
|
+
export * from "./ed25519/mod";
|
|
6
|
+
export * from "./env/mod";
|
|
7
|
+
export * from "./modules/mod";
|
|
8
|
+
export * from "./packs/mod";
|
|
9
|
+
export * from "./refs/mod";
|
|
10
|
+
export * from "./sha256/mod";
|
|
11
|
+
export * from "./storage/mod";
|
|
12
|
+
export * from "./symbols/mod";
|
|
13
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { blobref } from "../blobs/mod";
|
|
2
|
+
import { packref } from "../packs/mod";
|
|
3
|
+
|
|
4
|
+
export namespace modules {
|
|
5
|
+
|
|
6
|
+
// @ts-ignore: decorator
|
|
7
|
+
@external("modules", "load")
|
|
8
|
+
export declare function load(module: blobref): blobref
|
|
9
|
+
|
|
10
|
+
// @ts-ignore: decorator
|
|
11
|
+
@external("modules", "call")
|
|
12
|
+
export declare function call(module: blobref, method: blobref, params: packref): packref
|
|
13
|
+
|
|
14
|
+
// @ts-ignore: decorator
|
|
15
|
+
@external("modules", "create")
|
|
16
|
+
export declare function create(code: blobref, salt: blobref): blobref
|
|
17
|
+
|
|
18
|
+
// @ts-ignore: decorator
|
|
19
|
+
@external("modules", "self")
|
|
20
|
+
export declare function self(): blobref
|
|
21
|
+
|
|
22
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { blobref } from "../blobs/mod";
|
|
2
|
+
|
|
3
|
+
export type packref = externref
|
|
4
|
+
|
|
5
|
+
export namespace packs {
|
|
6
|
+
|
|
7
|
+
// @ts-ignore: decorator
|
|
8
|
+
@external("packs", "decode")
|
|
9
|
+
export declare function decode(blob: blobref): packref
|
|
10
|
+
|
|
11
|
+
// @ts-ignore: decorator
|
|
12
|
+
@external("packs", "encode")
|
|
13
|
+
export declare function encode(pack: packref): blobref
|
|
14
|
+
|
|
15
|
+
// @ts-ignore: decorator
|
|
16
|
+
@external("packs", "concat")
|
|
17
|
+
export declare function concat(left: packref, right: packref): packref
|
|
18
|
+
|
|
19
|
+
// @ts-ignore: decorator
|
|
20
|
+
@external("packs", "create")
|
|
21
|
+
export declare function create1<A>(arg0: A): packref
|
|
22
|
+
|
|
23
|
+
// @ts-ignore: decorator
|
|
24
|
+
@external("packs", "create")
|
|
25
|
+
export declare function create2<A, B>(arg0: A, arg1: B): packref
|
|
26
|
+
|
|
27
|
+
// @ts-ignore: decorator
|
|
28
|
+
@external("packs", "create")
|
|
29
|
+
export declare function create3<A, B, C>(arg0: A, arg1: B, arg2: C): packref
|
|
30
|
+
|
|
31
|
+
// @ts-ignore: decorator
|
|
32
|
+
@external("packs", "create")
|
|
33
|
+
export declare function create4<A, B, C, D>(arg0: A, arg1: B, arg2: C, arg3: D): packref
|
|
34
|
+
|
|
35
|
+
// @ts-ignore: decorator
|
|
36
|
+
@external("packs", "create")
|
|
37
|
+
export declare function create5<A, B, C, D, E>(arg0: A, arg1: B, arg2: C, arg3: D, arg4: E): packref
|
|
38
|
+
|
|
39
|
+
// @ts-ignore: decorator
|
|
40
|
+
@external("packs", "create")
|
|
41
|
+
export declare function create6<A, B, C, D, E, F>(arg0: A, arg1: B, arg2: C, arg3: D, arg4: E, arg5: F): packref
|
|
42
|
+
|
|
43
|
+
// @ts-ignore: decorator
|
|
44
|
+
@external("packs", "create")
|
|
45
|
+
export declare function create7<A, B, C, D, E, F, G>(arg0: A, arg1: B, arg2: C, arg3: D, arg4: E, arg5: F, arg6: G): packref
|
|
46
|
+
|
|
47
|
+
// @ts-ignore: decorator
|
|
48
|
+
@external("packs", "create")
|
|
49
|
+
export declare function create8<A, B, C, D, E, F, G, H>(arg0: A, arg1: B, arg2: C, arg3: D, arg4: E, arg5: F, arg6: G, arg7: H): packref
|
|
50
|
+
|
|
51
|
+
// @ts-ignore: decorator
|
|
52
|
+
@external("packs", "create")
|
|
53
|
+
export declare function create9<A, B, C, D, E, F, G, H, I>(arg0: A, arg1: B, arg2: C, arg3: D, arg4: E, arg5: F, arg6: G, arg7: H, arg8: I): packref
|
|
54
|
+
|
|
55
|
+
// @ts-ignore: decorator: decorator
|
|
56
|
+
@external("packs", "length")
|
|
57
|
+
export declare function length(pack: packref): usize
|
|
58
|
+
|
|
59
|
+
// @ts-ignore: decorator
|
|
60
|
+
@external("packs", "get")
|
|
61
|
+
export declare function get<T>(pack: packref, index: usize): T
|
|
62
|
+
|
|
63
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export namespace refs {
|
|
2
|
+
|
|
3
|
+
// @ts-ignore: decorator
|
|
4
|
+
@external("refs", "numerize")
|
|
5
|
+
export declare function numerize(ref: externref): usize
|
|
6
|
+
|
|
7
|
+
// @ts-ignore: decorator
|
|
8
|
+
@external("refs", "denumerize")
|
|
9
|
+
export declare function denumerize(index: usize): externref
|
|
10
|
+
|
|
11
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { blobref } from "../blobs/mod";
|
|
2
|
+
|
|
3
|
+
export namespace storage {
|
|
4
|
+
|
|
5
|
+
// @ts-ignore: decorator
|
|
6
|
+
@external("storage", "get")
|
|
7
|
+
export declare function get(key: blobref): blobref;
|
|
8
|
+
|
|
9
|
+
// @ts-ignore: decorator
|
|
10
|
+
@external("storage", "set")
|
|
11
|
+
export declare function set(key: blobref, value: blobref): void;
|
|
12
|
+
|
|
13
|
+
}
|