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