@btc-vision/btc-runtime 1.2.6 → 1.3.0
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 +73 -37
- package/package.json +7 -4
- package/runtime/buffer/BytesReader.ts +11 -6
- package/runtime/buffer/BytesWriter.ts +9 -17
- package/runtime/contracts/DeployableOP_20.ts +4 -16
- package/runtime/contracts/OP_NET.ts +2 -2
- package/runtime/contracts/interfaces/IOP_20.ts +0 -2
- package/runtime/env/BlockchainEnvironment.ts +13 -10
- package/runtime/generic/AddressMap.ts +62 -0
- package/runtime/generic/Map.ts +9 -8
- package/runtime/index.ts +18 -4
- package/runtime/memory/AddressMemoryMap.ts +8 -7
- package/runtime/memory/MultiAddressMemoryMap.ts +7 -7
- package/runtime/memory/MultiStringMemoryMap.ts +62 -0
- package/runtime/memory/StringMemoryMap.ts +57 -0
- package/runtime/memory/Uint8ArrayMerger.ts +67 -0
- package/runtime/secp256k1/ECPoint.ts +121 -0
- package/runtime/storage/StorageBacked.ts +5 -0
- package/runtime/storage/StorageLayout.ts +7 -0
- package/runtime/storage/StorageSlot.ts +106 -0
- package/runtime/storage/StorageStruct.ts +23 -0
- package/runtime/storage/StorageValue.ts +36 -0
- package/runtime/storage/StoredAddress.ts +47 -0
- package/runtime/storage/StoredU256.ts +5 -0
- package/runtime/tests/assert.ts +6 -3
- package/runtime/tests/env.ts +2 -2
- package/runtime/tests/tests.ts +18 -16
- package/runtime/types/Address.ts +121 -2
- package/runtime/types/SafeMath.ts +24 -0
- package/runtime/utils/b32.ts +243 -0
- package/runtime/utils/box.ts +126 -107
- package/runtime/utils/encodings.ts +46 -0
- package/runtime/utils/hex.ts +50 -47
- package/runtime/utils/index.ts +3 -2
package/runtime/utils/hex.ts
CHANGED
|
@@ -1,60 +1,63 @@
|
|
|
1
1
|
const hexLookupTable: StaticArray<u8> = [
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
100, 57, 100, 97, 100, 98, 100, 99, 100, 100, 100, 101, 100, 102, 101, 48,
|
|
26
|
-
101, 49, 101, 50, 101, 51, 101, 52, 101, 53, 101, 54, 101, 55, 101, 56, 101,
|
|
27
|
-
57, 101, 97, 101, 98, 101, 99, 101, 100, 101, 101, 101, 102, 102, 48, 102, 49,
|
|
28
|
-
102, 50, 102, 51, 102, 52, 102, 53, 102, 54, 102, 55, 102, 56, 102, 57, 102,
|
|
29
|
-
97, 102, 98, 102, 99, 102, 100, 102, 101, 102, 102,
|
|
2
|
+
48, 48, 48, 49, 48, 50, 48, 51, 48, 52, 48, 53, 48, 54, 48, 55, 48, 56, 48, 57, 48, 97, 48, 98,
|
|
3
|
+
48, 99, 48, 100, 48, 101, 48, 102, 49, 48, 49, 49, 49, 50, 49, 51, 49, 52, 49, 53, 49, 54, 49,
|
|
4
|
+
55, 49, 56, 49, 57, 49, 97, 49, 98, 49, 99, 49, 100, 49, 101, 49, 102, 50, 48, 50, 49, 50, 50,
|
|
5
|
+
50, 51, 50, 52, 50, 53, 50, 54, 50, 55, 50, 56, 50, 57, 50, 97, 50, 98, 50, 99, 50, 100, 50,
|
|
6
|
+
101, 50, 102, 51, 48, 51, 49, 51, 50, 51, 51, 51, 52, 51, 53, 51, 54, 51, 55, 51, 56, 51, 57,
|
|
7
|
+
51, 97, 51, 98, 51, 99, 51, 100, 51, 101, 51, 102, 52, 48, 52, 49, 52, 50, 52, 51, 52, 52, 52,
|
|
8
|
+
53, 52, 54, 52, 55, 52, 56, 52, 57, 52, 97, 52, 98, 52, 99, 52, 100, 52, 101, 52, 102, 53, 48,
|
|
9
|
+
53, 49, 53, 50, 53, 51, 53, 52, 53, 53, 53, 54, 53, 55, 53, 56, 53, 57, 53, 97, 53, 98, 53, 99,
|
|
10
|
+
53, 100, 53, 101, 53, 102, 54, 48, 54, 49, 54, 50, 54, 51, 54, 52, 54, 53, 54, 54, 54, 55, 54,
|
|
11
|
+
56, 54, 57, 54, 97, 54, 98, 54, 99, 54, 100, 54, 101, 54, 102, 55, 48, 55, 49, 55, 50, 55, 51,
|
|
12
|
+
55, 52, 55, 53, 55, 54, 55, 55, 55, 56, 55, 57, 55, 97, 55, 98, 55, 99, 55, 100, 55, 101, 55,
|
|
13
|
+
102, 56, 48, 56, 49, 56, 50, 56, 51, 56, 52, 56, 53, 56, 54, 56, 55, 56, 56, 56, 57, 56, 97, 56,
|
|
14
|
+
98, 56, 99, 56, 100, 56, 101, 56, 102, 57, 48, 57, 49, 57, 50, 57, 51, 57, 52, 57, 53, 57, 54,
|
|
15
|
+
57, 55, 57, 56, 57, 57, 57, 97, 57, 98, 57, 99, 57, 100, 57, 101, 57, 102, 97, 48, 97, 49, 97,
|
|
16
|
+
50, 97, 51, 97, 52, 97, 53, 97, 54, 97, 55, 97, 56, 97, 57, 97, 97, 97, 98, 97, 99, 97, 100, 97,
|
|
17
|
+
101, 97, 102, 98, 48, 98, 49, 98, 50, 98, 51, 98, 52, 98, 53, 98, 54, 98, 55, 98, 56, 98, 57,
|
|
18
|
+
98, 97, 98, 98, 98, 99, 98, 100, 98, 101, 98, 102, 99, 48, 99, 49, 99, 50, 99, 51, 99, 52, 99,
|
|
19
|
+
53, 99, 54, 99, 55, 99, 56, 99, 57, 99, 97, 99, 98, 99, 99, 99, 100, 99, 101, 99, 102, 100, 48,
|
|
20
|
+
100, 49, 100, 50, 100, 51, 100, 52, 100, 53, 100, 54, 100, 55, 100, 56, 100, 57, 100, 97, 100,
|
|
21
|
+
98, 100, 99, 100, 100, 100, 101, 100, 102, 101, 48, 101, 49, 101, 50, 101, 51, 101, 52, 101, 53,
|
|
22
|
+
101, 54, 101, 55, 101, 56, 101, 57, 101, 97, 101, 98, 101, 99, 101, 100, 101, 101, 101, 102,
|
|
23
|
+
102, 48, 102, 49, 102, 50, 102, 51, 102, 52, 102, 53, 102, 54, 102, 55, 102, 56, 102, 57, 102,
|
|
24
|
+
97, 102, 98, 102, 99, 102, 100, 102, 101, 102, 102,
|
|
30
25
|
];
|
|
31
26
|
|
|
32
27
|
export function encodeHexUTF8(start: usize, len: usize): ArrayBuffer {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
28
|
+
const result = new ArrayBuffer(2 + <i32>len * 2);
|
|
29
|
+
store<u16>(changetype<usize>(result), <u16>0x7830);
|
|
30
|
+
for (let i: usize = 0; i < len; i++) {
|
|
31
|
+
store<u16>(
|
|
32
|
+
2 + changetype<usize>(result) + i * 2,
|
|
33
|
+
load<u16>(changetype<usize>(hexLookupTable) + 2 * load<u8>(start + i)),
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
42
37
|
}
|
|
38
|
+
|
|
43
39
|
export function encodeHex(start: usize, len: usize): string {
|
|
44
|
-
|
|
40
|
+
return String.UTF8.decode(encodeHexUTF8(start, len));
|
|
45
41
|
}
|
|
46
42
|
|
|
47
43
|
export function encodeHexFromBuffer(data: ArrayBuffer): string {
|
|
48
|
-
|
|
44
|
+
return encodeHex(changetype<usize>(data), data.byteLength);
|
|
49
45
|
}
|
|
50
46
|
|
|
51
47
|
export function decodeHex(hex: string): ArrayBuffer {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
48
|
+
const result = new ArrayBuffer(hex.length / 2);
|
|
49
|
+
for (let i = 0; i < hex.length; i += 2) {
|
|
50
|
+
store<u8>(changetype<usize>(result) + i / 2, <u8>parseInt(hex.substring(i, i + 2), 16));
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function decodeHexArray(hex: string): u8[] {
|
|
56
|
+
const result = new Array<u8>(hex.length / 2);
|
|
57
|
+
|
|
58
|
+
for (let i = 0; i < hex.length; i += 2) {
|
|
59
|
+
store<u8>(changetype<usize>(result) + i / 2, <u8>parseInt(hex.substring(i, i + 2), 16));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return result;
|
|
60
63
|
}
|
package/runtime/utils/index.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from './hex';
|
|
2
|
+
export * from './box';
|
|
3
|
+
export * from './encodings';
|