@hazae41/stdbob 0.1.0 → 0.1.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/package.json +1 -1
- package/src/mods/bigints/mod.ts +142 -0
- package/src/mods/blobs/mod.ts +64 -2
- package/src/mods/console/mod.ts +7 -0
- package/src/mods/ed25519/mod.ts +9 -0
- package/src/mods/env/mod.ts +13 -0
- package/src/mods/modules/mod.ts +21 -0
- package/src/mods/packs/mod.ts +53 -0
- package/src/mods/refs/mod.ts +11 -0
- package/src/mods/sha256/mod.ts +7 -0
- package/src/mods/storage/mod.ts +12 -0
- package/src/mods/symbols/mod.ts +6 -0
- package/src/mods/texts/mod.ts +58 -0
package/package.json
CHANGED
package/src/mods/bigints/mod.ts
CHANGED
|
@@ -2,140 +2,282 @@ import { textref } from "../texts/mod"
|
|
|
2
2
|
|
|
3
3
|
export type bigintref = externref
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* BigInts are external references to arbitrary-precision negatable integers (e.g. BigInt in JavaScript)
|
|
7
|
+
*/
|
|
5
8
|
export namespace bigints {
|
|
6
9
|
|
|
10
|
+
/**
|
|
11
|
+
* 0n
|
|
12
|
+
*/
|
|
7
13
|
// @ts-ignore: decorator
|
|
8
14
|
@external("bigints", "zero")
|
|
9
15
|
export declare function zero(): bigintref
|
|
10
16
|
|
|
17
|
+
/**
|
|
18
|
+
* 1n
|
|
19
|
+
*/
|
|
11
20
|
// @ts-ignore: decorator
|
|
12
21
|
@external("bigints", "one")
|
|
13
22
|
export declare function one(): bigintref
|
|
14
23
|
|
|
24
|
+
/**
|
|
25
|
+
* 2n
|
|
26
|
+
*/
|
|
15
27
|
// @ts-ignore: decorator
|
|
16
28
|
@external("bigints", "two")
|
|
17
29
|
export declare function two(): bigintref
|
|
18
30
|
|
|
31
|
+
/**
|
|
32
|
+
* 3n
|
|
33
|
+
*/
|
|
19
34
|
// @ts-ignore: decorator
|
|
20
35
|
@external("bigints", "three")
|
|
21
36
|
export declare function three(): bigintref
|
|
22
37
|
|
|
38
|
+
/**
|
|
39
|
+
* 4n
|
|
40
|
+
*/
|
|
23
41
|
// @ts-ignore: decorator
|
|
24
42
|
@external("bigints", "four")
|
|
25
43
|
export declare function four(): bigintref
|
|
26
44
|
|
|
45
|
+
/**
|
|
46
|
+
* 5n
|
|
47
|
+
*/
|
|
27
48
|
// @ts-ignore: decorator
|
|
28
49
|
@external("bigints", "five")
|
|
29
50
|
export declare function five(): bigintref
|
|
30
51
|
|
|
52
|
+
/**
|
|
53
|
+
* 6n
|
|
54
|
+
*/
|
|
31
55
|
// @ts-ignore: decorator
|
|
32
56
|
@external("bigints", "six")
|
|
33
57
|
export declare function six(): bigintref
|
|
34
58
|
|
|
59
|
+
/**
|
|
60
|
+
* 7n
|
|
61
|
+
*/
|
|
35
62
|
// @ts-ignore: decorator
|
|
36
63
|
@external("bigints", "seven")
|
|
37
64
|
export declare function seven(): bigintref
|
|
38
65
|
|
|
66
|
+
/**
|
|
67
|
+
* 8n
|
|
68
|
+
*/
|
|
39
69
|
// @ts-ignore: decorator
|
|
40
70
|
@external("bigints", "eight")
|
|
41
71
|
export declare function eight(): bigintref
|
|
42
72
|
|
|
73
|
+
/**
|
|
74
|
+
* 9n
|
|
75
|
+
*/
|
|
43
76
|
// @ts-ignore: decorator
|
|
44
77
|
@external("bigints", "nine")
|
|
45
78
|
export declare function nine(): bigintref
|
|
46
79
|
|
|
80
|
+
/**
|
|
81
|
+
* 10n
|
|
82
|
+
*/
|
|
47
83
|
// @ts-ignore: decorator
|
|
48
84
|
@external("bigints", "ten")
|
|
49
85
|
export declare function ten(): bigintref
|
|
50
86
|
|
|
87
|
+
/**
|
|
88
|
+
* Increment a bigint by 1n
|
|
89
|
+
* @param value
|
|
90
|
+
*/
|
|
51
91
|
// @ts-ignore: decorator
|
|
52
92
|
@external("bigints", "inc")
|
|
53
93
|
export declare function inc(value: bigintref): bigintref
|
|
54
94
|
|
|
95
|
+
/**
|
|
96
|
+
* Decrement a bigint by 1n
|
|
97
|
+
* @param value
|
|
98
|
+
*/
|
|
55
99
|
// @ts-ignore: decorator
|
|
56
100
|
@external("bigints", "dec")
|
|
57
101
|
export declare function dec(value: bigintref): bigintref
|
|
58
102
|
|
|
103
|
+
/**
|
|
104
|
+
* Negate a bigint
|
|
105
|
+
* @param value
|
|
106
|
+
*/
|
|
59
107
|
// @ts-ignore: decorator
|
|
60
108
|
@external("bigints", "neg")
|
|
61
109
|
export declare function neg(value: bigintref): bigintref
|
|
62
110
|
|
|
111
|
+
/**
|
|
112
|
+
* Add left and right
|
|
113
|
+
* @param left
|
|
114
|
+
* @param right
|
|
115
|
+
*/
|
|
63
116
|
// @ts-ignore: decorator
|
|
64
117
|
@external("bigints", "add")
|
|
65
118
|
export declare function add(left: bigintref, right: bigintref): bigintref
|
|
66
119
|
|
|
120
|
+
/**
|
|
121
|
+
* Subtract right from left
|
|
122
|
+
* @param left
|
|
123
|
+
* @param right
|
|
124
|
+
*/
|
|
67
125
|
// @ts-ignore: decorator
|
|
68
126
|
@external("bigints", "sub")
|
|
69
127
|
export declare function sub(left: bigintref, right: bigintref): bigintref
|
|
70
128
|
|
|
129
|
+
/**
|
|
130
|
+
* Multiply left by right
|
|
131
|
+
* @param left
|
|
132
|
+
* @param right
|
|
133
|
+
*/
|
|
71
134
|
// @ts-ignore: decorator
|
|
72
135
|
@external("bigints", "mul")
|
|
73
136
|
export declare function mul(left: bigintref, right: bigintref): bigintref
|
|
74
137
|
|
|
138
|
+
/**
|
|
139
|
+
* Divide left by right (throw if right is zero)
|
|
140
|
+
* @param left
|
|
141
|
+
* @param right
|
|
142
|
+
*/
|
|
75
143
|
// @ts-ignore: decorator
|
|
76
144
|
@external("bigints", "div")
|
|
77
145
|
export declare function div(left: bigintref, right: bigintref): bigintref
|
|
78
146
|
|
|
147
|
+
/**
|
|
148
|
+
* Raise left to the power of right
|
|
149
|
+
* @param left
|
|
150
|
+
* @param right
|
|
151
|
+
*/
|
|
79
152
|
// @ts-ignore: decorator
|
|
80
153
|
@external("bigints", "pow")
|
|
81
154
|
export declare function pow(left: bigintref, right: bigintref): bigintref
|
|
82
155
|
|
|
156
|
+
/**
|
|
157
|
+
* Remainder of left divided by right
|
|
158
|
+
* @param left
|
|
159
|
+
* @param right
|
|
160
|
+
*/
|
|
83
161
|
// @ts-ignore: decorator
|
|
84
162
|
@external("bigints", "mod")
|
|
85
163
|
export declare function mod(left: bigintref, right: bigintref): bigintref
|
|
86
164
|
|
|
165
|
+
/**
|
|
166
|
+
* True if left is less than right
|
|
167
|
+
* @param left
|
|
168
|
+
* @param right
|
|
169
|
+
*/
|
|
87
170
|
// @ts-ignore: decorator
|
|
88
171
|
@external("bigints", "lt")
|
|
89
172
|
export declare function lt(left: bigintref, right: bigintref): bool
|
|
90
173
|
|
|
174
|
+
/**
|
|
175
|
+
* True if left is less than or equal to right
|
|
176
|
+
* @param left
|
|
177
|
+
* @param right
|
|
178
|
+
*/
|
|
91
179
|
// @ts-ignore: decorator
|
|
92
180
|
@external("bigints", "lte")
|
|
93
181
|
export declare function lte(left: bigintref, right: bigintref): bool
|
|
94
182
|
|
|
183
|
+
/**
|
|
184
|
+
* True if left is greater than right
|
|
185
|
+
* @param left
|
|
186
|
+
* @param right
|
|
187
|
+
*/
|
|
95
188
|
// @ts-ignore: decorator
|
|
96
189
|
@external("bigints", "gt")
|
|
97
190
|
export declare function gt(left: bigintref, right: bigintref): bool
|
|
98
191
|
|
|
192
|
+
/**
|
|
193
|
+
* True if left is greater than or equal to right
|
|
194
|
+
* @param left
|
|
195
|
+
* @param right
|
|
196
|
+
*/
|
|
99
197
|
// @ts-ignore: decorator
|
|
100
198
|
@external("bigints", "gte")
|
|
101
199
|
export declare function gte(left: bigintref, right: bigintref): bool
|
|
102
200
|
|
|
201
|
+
/**
|
|
202
|
+
* True if left is equal to right
|
|
203
|
+
* @param left
|
|
204
|
+
* @param right
|
|
205
|
+
*/
|
|
103
206
|
// @ts-ignore: decorator
|
|
104
207
|
@external("bigints", "eq")
|
|
105
208
|
export declare function eq(left: bigintref, right: bigintref): bool
|
|
106
209
|
|
|
210
|
+
/**
|
|
211
|
+
* True if left is not equal to right
|
|
212
|
+
* @param left
|
|
213
|
+
* @param right
|
|
214
|
+
*/
|
|
107
215
|
// @ts-ignore: decorator
|
|
108
216
|
@external("bigints", "neq")
|
|
109
217
|
export declare function neq(left: bigintref, right: bigintref): bool
|
|
110
218
|
|
|
219
|
+
/**
|
|
220
|
+
* The smaller of left and right
|
|
221
|
+
* @param left
|
|
222
|
+
* @param right
|
|
223
|
+
*/
|
|
111
224
|
// @ts-ignore: decorator
|
|
112
225
|
@external("bigints", "min")
|
|
113
226
|
export declare function min(left: bigintref, right: bigintref): bigintref
|
|
114
227
|
|
|
228
|
+
/**
|
|
229
|
+
* The larger of left and right
|
|
230
|
+
* @param left
|
|
231
|
+
* @param right
|
|
232
|
+
*/
|
|
115
233
|
// @ts-ignore: decorator
|
|
116
234
|
@external("bigints", "max")
|
|
117
235
|
export declare function max(left: bigintref, right: bigintref): bigintref
|
|
118
236
|
|
|
237
|
+
/**
|
|
238
|
+
* Create a bigint from a base-16 string
|
|
239
|
+
* @param text
|
|
240
|
+
*/
|
|
119
241
|
// @ts-ignore: decorator
|
|
120
242
|
@external("bigints", "from_base16")
|
|
121
243
|
export declare function fromBase16(text: textref): bigintref
|
|
122
244
|
|
|
245
|
+
/**
|
|
246
|
+
* Convert a bigint to a base-16 string
|
|
247
|
+
* @param bigint
|
|
248
|
+
*/
|
|
123
249
|
// @ts-ignore: decorator
|
|
124
250
|
@external("bigints", "to_base16")
|
|
125
251
|
export declare function toBase16(bigint: bigintref): textref
|
|
126
252
|
|
|
253
|
+
/**
|
|
254
|
+
* Create a bigint from a base-10 string
|
|
255
|
+
* @param text
|
|
256
|
+
*/
|
|
127
257
|
// @ts-ignore: decorator
|
|
128
258
|
@external("bigints", "from_base10")
|
|
129
259
|
export declare function fromBase10(text: textref): bigintref
|
|
130
260
|
|
|
261
|
+
/**
|
|
262
|
+
* Convert a bigint to a base-10 string
|
|
263
|
+
* @param bigint
|
|
264
|
+
*/
|
|
131
265
|
// @ts-ignore: decorator
|
|
132
266
|
@external("bigints", "to_base10")
|
|
133
267
|
export declare function toBase10(bigint: bigintref): textref
|
|
134
268
|
|
|
269
|
+
/**
|
|
270
|
+
* Create a bigint from a 64-bit integer
|
|
271
|
+
* @param bigint
|
|
272
|
+
*/
|
|
135
273
|
// @ts-ignore: decorator
|
|
136
274
|
@external("bigints", "identity")
|
|
137
275
|
export declare function fromInt64(bigint: i64): bigintref
|
|
138
276
|
|
|
277
|
+
/**
|
|
278
|
+
* Convert a bigint to a 64-bit integer
|
|
279
|
+
* @param bigint
|
|
280
|
+
*/
|
|
139
281
|
// @ts-ignore: decorator
|
|
140
282
|
@external("bigints", "identity")
|
|
141
283
|
export declare function toInt64(bigint: bigintref): i64
|
package/src/mods/blobs/mod.ts
CHANGED
|
@@ -2,16 +2,24 @@ import { textref } from "../texts/mod"
|
|
|
2
2
|
|
|
3
3
|
export type blobref = externref
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Blobs are external references to bytes (e.g. Uint8Array in JavaScript)
|
|
7
|
+
*/
|
|
5
8
|
export namespace blobs {
|
|
6
9
|
|
|
7
10
|
// @ts-ignore: decorator
|
|
8
11
|
@external("blobs", "save")
|
|
9
|
-
|
|
12
|
+
declare function $save(offset: i32, length: i32): blobref
|
|
10
13
|
|
|
11
14
|
// @ts-ignore: decorator
|
|
12
15
|
@external("blobs", "load")
|
|
13
|
-
|
|
16
|
+
declare function $load(blob: blobref, offset: i32): void
|
|
14
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Save the given buffer into a blob
|
|
20
|
+
* @param buffer
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
15
23
|
export function save(buffer: ArrayBuffer): blobref {
|
|
16
24
|
const bytes = Uint8Array.wrap(buffer)
|
|
17
25
|
|
|
@@ -20,6 +28,11 @@ export namespace blobs {
|
|
|
20
28
|
return reference
|
|
21
29
|
}
|
|
22
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Load the given blob into a buffer
|
|
33
|
+
* @param blob
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
23
36
|
export function load(blob: blobref): ArrayBuffer {
|
|
24
37
|
const bytes = new Uint8Array(length(blob))
|
|
25
38
|
|
|
@@ -28,46 +41,95 @@ export namespace blobs {
|
|
|
28
41
|
return bytes.buffer
|
|
29
42
|
}
|
|
30
43
|
|
|
44
|
+
/**
|
|
45
|
+
* The length of the given blob
|
|
46
|
+
* @param blob
|
|
47
|
+
*/
|
|
31
48
|
// @ts-ignore: decorator
|
|
32
49
|
@external("blobs", "length")
|
|
33
50
|
export declare function length(blob: blobref): i32
|
|
34
51
|
|
|
52
|
+
/**
|
|
53
|
+
* Concatenate two blobs
|
|
54
|
+
* @param left
|
|
55
|
+
* @param right
|
|
56
|
+
*/
|
|
35
57
|
// @ts-ignore: decorator
|
|
36
58
|
@external("blobs", "concat")
|
|
37
59
|
export declare function concat(left: blobref, right: blobref): blobref
|
|
38
60
|
|
|
61
|
+
/**
|
|
62
|
+
* True if left and right have the same data
|
|
63
|
+
* @param left
|
|
64
|
+
* @param right
|
|
65
|
+
*/
|
|
39
66
|
// @ts-ignore: decorator
|
|
40
67
|
@external("blobs", "equals")
|
|
41
68
|
export declare function equals(left: blobref, right: blobref): bool
|
|
42
69
|
|
|
70
|
+
/**
|
|
71
|
+
* True if the data in haystack contains the data in needle (at any offset)
|
|
72
|
+
* @param haystack
|
|
73
|
+
* @param needle
|
|
74
|
+
*/
|
|
43
75
|
// @ts-ignore: decorator
|
|
44
76
|
@external("blobs", "includes")
|
|
45
77
|
export declare function includes(haystack: blobref, needle: blobref): bool
|
|
46
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Slice the given blob from start (inclusive) to until (exclusive)
|
|
81
|
+
* @param blob
|
|
82
|
+
* @param start
|
|
83
|
+
* @param until
|
|
84
|
+
*/
|
|
47
85
|
// @ts-ignore: decorator
|
|
48
86
|
@external("blobs", "slice")
|
|
49
87
|
export declare function slice(blob: blobref, start: i32, until: i32): blobref
|
|
50
88
|
|
|
89
|
+
/**
|
|
90
|
+
* Create a blob from a base-16 string
|
|
91
|
+
* @param text
|
|
92
|
+
*/
|
|
51
93
|
// @ts-ignore: decorator
|
|
52
94
|
@external("blobs", "from_base16")
|
|
53
95
|
export declare function fromBase16(text: textref): blobref
|
|
54
96
|
|
|
97
|
+
/**
|
|
98
|
+
* Convert a blob to a base-16 string
|
|
99
|
+
* @param blob
|
|
100
|
+
*/
|
|
55
101
|
// @ts-ignore: decorator
|
|
56
102
|
@external("blobs", "to_base16")
|
|
57
103
|
export declare function toBase16(blob: blobref): textref
|
|
58
104
|
|
|
105
|
+
/**
|
|
106
|
+
* Create a blob from a base-64 string
|
|
107
|
+
* @param text
|
|
108
|
+
*/
|
|
59
109
|
// @ts-ignore: decorator
|
|
60
110
|
@external("blobs", "from_base64")
|
|
61
111
|
export declare function fromBase64(text: textref): blobref
|
|
62
112
|
|
|
113
|
+
/**
|
|
114
|
+
* Convert a blob to a base-64 string
|
|
115
|
+
* @param blob
|
|
116
|
+
*/
|
|
63
117
|
// @ts-ignore: decorator
|
|
64
118
|
@external("blobs", "to_base64")
|
|
65
119
|
export declare function toBase64(blob: blobref): textref
|
|
66
120
|
|
|
121
|
+
/**
|
|
122
|
+
* Encode the given value into a blob
|
|
123
|
+
* @param value
|
|
124
|
+
*/
|
|
67
125
|
// @ts-ignore: decorator
|
|
68
126
|
@external("blobs", "encode")
|
|
69
127
|
export declare function encode<T>(value: T): blobref
|
|
70
128
|
|
|
129
|
+
/**
|
|
130
|
+
* Decode the given blob into a value of type T (assuming it was encoded from a value of type T)
|
|
131
|
+
* @param blob
|
|
132
|
+
*/
|
|
71
133
|
// @ts-ignore: decorator
|
|
72
134
|
@external("blobs", "decode")
|
|
73
135
|
export declare function decode<T>(blob: blobref): T
|
package/src/mods/console/mod.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { textref } from "../mod";
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Log messages to the console
|
|
5
|
+
*/
|
|
3
6
|
export namespace console {
|
|
4
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Log the given message to the console
|
|
10
|
+
* @param message
|
|
11
|
+
*/
|
|
5
12
|
// @ts-ignore: decorator
|
|
6
13
|
@external("console", "log")
|
|
7
14
|
export declare function log(message: textref): void
|
package/src/mods/ed25519/mod.ts
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import { blobref } from "../blobs/mod";
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Ed25519 elliptic curve digital signature algorithm
|
|
5
|
+
*/
|
|
3
6
|
export namespace ed25519 {
|
|
4
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Verify that the given signature is valid for the given payload and public key
|
|
10
|
+
* @param pubkey
|
|
11
|
+
* @param signature
|
|
12
|
+
* @param payload
|
|
13
|
+
*/
|
|
5
14
|
// @ts-ignore: decorator
|
|
6
15
|
@external("ed25519", "verify")
|
|
7
16
|
export declare function verify(pubkey: blobref, signature: blobref, payload: blobref): bool
|
package/src/mods/env/mod.ts
CHANGED
|
@@ -1,15 +1,28 @@
|
|
|
1
1
|
import { textref } from "../mod"
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Execution environment
|
|
5
|
+
*/
|
|
3
6
|
export namespace env {
|
|
4
7
|
|
|
8
|
+
/**
|
|
9
|
+
* 1 = execution, 2 = simulation
|
|
10
|
+
*/
|
|
5
11
|
// @ts-ignore: decorator
|
|
6
12
|
@external("env", "mode")
|
|
7
13
|
export declare const mode: i32
|
|
8
14
|
|
|
15
|
+
/**
|
|
16
|
+
* The environment UUID (aka chain ID)
|
|
17
|
+
*/
|
|
9
18
|
// @ts-ignore: decorator
|
|
10
19
|
@external("env", "uuid")
|
|
11
20
|
export declare function uuid(): textref
|
|
12
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Stop execution with the given message
|
|
24
|
+
* @param message
|
|
25
|
+
*/
|
|
13
26
|
// @ts-ignore: decorator
|
|
14
27
|
@external("env", "panic")
|
|
15
28
|
export declare function panic<T>(message: textref): T
|
package/src/mods/modules/mod.ts
CHANGED
|
@@ -2,20 +2,41 @@ import { blobref } from "../blobs/mod"
|
|
|
2
2
|
import { packref } from "../packs/mod"
|
|
3
3
|
import { textref } from "../texts/mod"
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Modules have an address and can be called by other modules
|
|
7
|
+
*/
|
|
5
8
|
export namespace modules {
|
|
6
9
|
|
|
10
|
+
/**
|
|
11
|
+
* The address of the current module
|
|
12
|
+
*/
|
|
7
13
|
// @ts-ignore: decorator
|
|
8
14
|
@external("modules", "self")
|
|
9
15
|
export declare function self(): textref
|
|
10
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Get the code of the given module
|
|
19
|
+
* @param module
|
|
20
|
+
*/
|
|
11
21
|
// @ts-ignore: decorator
|
|
12
22
|
@external("modules", "load")
|
|
13
23
|
export declare function load(module: textref): blobref
|
|
14
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Call the given method of the given module with the given parameters then return the result in a 1-sized pack
|
|
27
|
+
* @param module
|
|
28
|
+
* @param method
|
|
29
|
+
* @param params
|
|
30
|
+
*/
|
|
15
31
|
// @ts-ignore: decorator
|
|
16
32
|
@external("modules", "call")
|
|
17
33
|
export declare function call(module: textref, method: textref, params: packref): packref
|
|
18
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Create a new module with the given code and salt then return its address
|
|
37
|
+
* @param code
|
|
38
|
+
* @param salt
|
|
39
|
+
*/
|
|
19
40
|
// @ts-ignore: decorator
|
|
20
41
|
@external("modules", "create")
|
|
21
42
|
export declare function create<T>(code: blobref, salt: T): textref
|
package/src/mods/packs/mod.ts
CHANGED
|
@@ -1,52 +1,105 @@
|
|
|
1
1
|
|
|
2
2
|
export type packref = externref
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Packs are external references to tuples of values (e.g. arrays in JavaScript)
|
|
6
|
+
*/
|
|
4
7
|
export namespace packs {
|
|
5
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Concatenate two packs (e.g. [...left, ...right] in JavaScript)
|
|
11
|
+
* @param left
|
|
12
|
+
* @param right
|
|
13
|
+
*/
|
|
6
14
|
// @ts-ignore: decorator
|
|
7
15
|
@external("packs", "concat")
|
|
8
16
|
export declare function concat(left: packref, right: packref): packref
|
|
9
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Create a new pack with the given arguments
|
|
20
|
+
* @param arg0
|
|
21
|
+
*/
|
|
10
22
|
// @ts-ignore: decorator
|
|
11
23
|
@external("packs", "create")
|
|
12
24
|
export declare function create1<A>(arg0: A): packref
|
|
13
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Create a new pack with the given arguments
|
|
28
|
+
* @param arg0
|
|
29
|
+
*/
|
|
14
30
|
// @ts-ignore: decorator
|
|
15
31
|
@external("packs", "create")
|
|
16
32
|
export declare function create2<A, B>(arg0: A, arg1: B): packref
|
|
17
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Create a new pack with the given arguments
|
|
36
|
+
* @param arg0
|
|
37
|
+
*/
|
|
18
38
|
// @ts-ignore: decorator
|
|
19
39
|
@external("packs", "create")
|
|
20
40
|
export declare function create3<A, B, C>(arg0: A, arg1: B, arg2: C): packref
|
|
21
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Create a new pack with the given arguments
|
|
44
|
+
* @param arg0
|
|
45
|
+
*/
|
|
22
46
|
// @ts-ignore: decorator
|
|
23
47
|
@external("packs", "create")
|
|
24
48
|
export declare function create4<A, B, C, D>(arg0: A, arg1: B, arg2: C, arg3: D): packref
|
|
25
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Create a new pack with the given arguments
|
|
52
|
+
* @param arg0
|
|
53
|
+
*/
|
|
26
54
|
// @ts-ignore: decorator
|
|
27
55
|
@external("packs", "create")
|
|
28
56
|
export declare function create5<A, B, C, D, E>(arg0: A, arg1: B, arg2: C, arg3: D, arg4: E): packref
|
|
29
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Create a new pack with the given arguments
|
|
60
|
+
* @param arg0
|
|
61
|
+
*/
|
|
30
62
|
// @ts-ignore: decorator
|
|
31
63
|
@external("packs", "create")
|
|
32
64
|
export declare function create6<A, B, C, D, E, F>(arg0: A, arg1: B, arg2: C, arg3: D, arg4: E, arg5: F): packref
|
|
33
65
|
|
|
66
|
+
/**
|
|
67
|
+
* Create a new pack with the given arguments
|
|
68
|
+
* @param arg0
|
|
69
|
+
*/
|
|
34
70
|
// @ts-ignore: decorator
|
|
35
71
|
@external("packs", "create")
|
|
36
72
|
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
|
|
37
73
|
|
|
74
|
+
/**
|
|
75
|
+
* Create a new pack with the given arguments
|
|
76
|
+
* @param arg0
|
|
77
|
+
*/
|
|
38
78
|
// @ts-ignore: decorator
|
|
39
79
|
@external("packs", "create")
|
|
40
80
|
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
|
|
41
81
|
|
|
82
|
+
/**
|
|
83
|
+
* Create a new pack with the given arguments
|
|
84
|
+
* @param arg0
|
|
85
|
+
*/
|
|
42
86
|
// @ts-ignore: decorator
|
|
43
87
|
@external("packs", "create")
|
|
44
88
|
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
|
|
45
89
|
|
|
90
|
+
/**
|
|
91
|
+
* Get the length of the given pack
|
|
92
|
+
* @param pack
|
|
93
|
+
*/
|
|
46
94
|
// @ts-ignore: decorator: decorator
|
|
47
95
|
@external("packs", "length")
|
|
48
96
|
export declare function length(pack: packref): i32
|
|
49
97
|
|
|
98
|
+
/**
|
|
99
|
+
* Get the value at the given index in the given pack (throw if not found)
|
|
100
|
+
* @param pack
|
|
101
|
+
* @param index
|
|
102
|
+
*/
|
|
50
103
|
// @ts-ignore: decorator
|
|
51
104
|
@external("packs", "get")
|
|
52
105
|
export declare function get<T>(pack: packref, index: i32): T
|
package/src/mods/refs/mod.ts
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert between externrefs and local i32 indices (for use in data structures)
|
|
3
|
+
*/
|
|
1
4
|
export namespace refs {
|
|
2
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Convert an externref to an i32 index
|
|
8
|
+
* @param ref
|
|
9
|
+
*/
|
|
3
10
|
// @ts-ignore: decorator
|
|
4
11
|
@external("refs", "numerize")
|
|
5
12
|
export declare function numerize(ref: externref): i32
|
|
6
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Convert an i32 index back to an externref
|
|
16
|
+
* @param index
|
|
17
|
+
*/
|
|
7
18
|
// @ts-ignore: decorator
|
|
8
19
|
@external("refs", "denumerize")
|
|
9
20
|
export declare function denumerize(index: i32): externref
|
package/src/mods/sha256/mod.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { blobref } from "../blobs/mod";
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* SHA-256 cryptographic hash function
|
|
5
|
+
*/
|
|
3
6
|
export namespace sha256 {
|
|
4
7
|
|
|
8
|
+
/**
|
|
9
|
+
* The SHA-256 digest of the given payload
|
|
10
|
+
* @param payload
|
|
11
|
+
*/
|
|
5
12
|
// @ts-ignore: decorator
|
|
6
13
|
@external("sha256", "digest")
|
|
7
14
|
export declare function digest(payload: blobref): blobref
|
package/src/mods/storage/mod.ts
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
import { packref, textref } from "../mod";
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Persistent public key-value storage
|
|
5
|
+
*/
|
|
3
6
|
export namespace storage {
|
|
4
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Get the value associated with the given key in a 1-sized pack or null if not found
|
|
10
|
+
* @param key
|
|
11
|
+
*/
|
|
5
12
|
// @ts-ignore: decorator
|
|
6
13
|
@external("storage", "get")
|
|
7
14
|
export declare function get(key: textref): packref
|
|
8
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Set the value associated with the given key
|
|
18
|
+
* @param key
|
|
19
|
+
* @param value
|
|
20
|
+
*/
|
|
9
21
|
// @ts-ignore: decorator
|
|
10
22
|
@external("storage", "set")
|
|
11
23
|
export declare function set<T>(key: textref, value: T): void
|
package/src/mods/symbols/mod.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
export type symbolref = externref
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Symbols are unique external references (e.g. Symbol in JavaScript)
|
|
5
|
+
*/
|
|
3
6
|
export namespace symbols {
|
|
4
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Create a new unique symbol
|
|
10
|
+
*/
|
|
5
11
|
// @ts-ignore: decorator
|
|
6
12
|
@external("symbols", "create")
|
|
7
13
|
export declare function create(): symbolref
|
package/src/mods/texts/mod.ts
CHANGED
|
@@ -2,48 +2,101 @@ import { blobref, blobs } from "../mod"
|
|
|
2
2
|
|
|
3
3
|
export type textref = externref
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Texts are external references to strings (e.g. string in JavaScript)
|
|
7
|
+
*/
|
|
5
8
|
export namespace texts {
|
|
6
9
|
|
|
10
|
+
/**
|
|
11
|
+
* The length of the given text
|
|
12
|
+
* @param text
|
|
13
|
+
*/
|
|
7
14
|
// @ts-ignore: decorator
|
|
8
15
|
@external("texts", "length")
|
|
9
16
|
export declare function length(text: textref): i32
|
|
10
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Concatenate two texts
|
|
20
|
+
* @param left
|
|
21
|
+
* @param right
|
|
22
|
+
*/
|
|
11
23
|
// @ts-ignore: decorator
|
|
12
24
|
@external("texts", "concat")
|
|
13
25
|
export declare function concat(left: textref, right: textref): textref
|
|
14
26
|
|
|
27
|
+
/**
|
|
28
|
+
* True if left and right are equal
|
|
29
|
+
* @param left
|
|
30
|
+
* @param right
|
|
31
|
+
*/
|
|
15
32
|
// @ts-ignore: decorator
|
|
16
33
|
@external("texts", "equals")
|
|
17
34
|
export declare function equals(left: textref, right: textref): bool
|
|
18
35
|
|
|
36
|
+
/**
|
|
37
|
+
* True if left includes right (at any offset)
|
|
38
|
+
* @param haystack
|
|
39
|
+
* @param needle
|
|
40
|
+
*/
|
|
19
41
|
// @ts-ignore: decorator
|
|
20
42
|
@external("texts", "includes")
|
|
21
43
|
export declare function includes(haystack: textref, needle: textref): bool
|
|
22
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Slice the given text from start (inclusive) to until (exclusive)
|
|
47
|
+
* @param text
|
|
48
|
+
* @param start
|
|
49
|
+
* @param until
|
|
50
|
+
*/
|
|
23
51
|
// @ts-ignore: decorator
|
|
24
52
|
@external("texts", "slice")
|
|
25
53
|
export declare function slice(text: textref, start: i32, until: i32): textref
|
|
26
54
|
|
|
55
|
+
/**
|
|
56
|
+
* Create a text from a UTF-8 blob
|
|
57
|
+
* @param blob
|
|
58
|
+
*/
|
|
27
59
|
// @ts-ignore: decorator
|
|
28
60
|
@external("texts", "from_utf8")
|
|
29
61
|
export declare function fromUtf8(blob: blobref): textref
|
|
30
62
|
|
|
63
|
+
/**
|
|
64
|
+
* Convert a text to a UTF-8 blob
|
|
65
|
+
* @param text
|
|
66
|
+
*/
|
|
31
67
|
// @ts-ignore: decorator
|
|
32
68
|
@external("texts", "to_utf8")
|
|
33
69
|
export declare function toUtf8(text: textref): blobref
|
|
34
70
|
|
|
71
|
+
/**
|
|
72
|
+
* Convert the given text to uppercase
|
|
73
|
+
* @param text
|
|
74
|
+
*/
|
|
35
75
|
// @ts-ignore: decorator
|
|
36
76
|
@external("texts", "to_uppercase")
|
|
37
77
|
export declare function toUppercase(text: textref): textref
|
|
38
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Convert the given text to lowercase
|
|
81
|
+
* @param text
|
|
82
|
+
*/
|
|
39
83
|
// @ts-ignore: decorator
|
|
40
84
|
@external("texts", "to_lowercase")
|
|
41
85
|
export declare function toLowercase(text: textref): textref
|
|
42
86
|
|
|
87
|
+
/**
|
|
88
|
+
* Trim the given text by removing whitespace from both ends
|
|
89
|
+
* @param text
|
|
90
|
+
*/
|
|
43
91
|
// @ts-ignore: decorator
|
|
44
92
|
@external("texts", "trim")
|
|
45
93
|
export declare function trim(text: textref): textref
|
|
46
94
|
|
|
95
|
+
/**
|
|
96
|
+
* Create a text from a string
|
|
97
|
+
* @param string
|
|
98
|
+
* @returns
|
|
99
|
+
*/
|
|
47
100
|
export function fromString(string: string): textref {
|
|
48
101
|
const utf8 = String.UTF8.encode(string)
|
|
49
102
|
|
|
@@ -53,6 +106,11 @@ export namespace texts {
|
|
|
53
106
|
return text
|
|
54
107
|
}
|
|
55
108
|
|
|
109
|
+
/**
|
|
110
|
+
* Convert a text to a string
|
|
111
|
+
* @param text
|
|
112
|
+
* @returns
|
|
113
|
+
*/
|
|
56
114
|
export function toString(text: textref): string {
|
|
57
115
|
const blob = toUtf8(text)
|
|
58
116
|
const utf8 = blobs.load(blob)
|