@gardenfi/swap 0.0.2-beta.2 → 0.0.2-beta.4
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/dist/index104.cjs +1 -1
- package/dist/index104.js +4 -4
- package/dist/index106.cjs +1 -1
- package/dist/index106.js +3 -3
- package/dist/index107.cjs +1 -1
- package/dist/index107.js +3 -3
- package/dist/index116.cjs +1 -1
- package/dist/index116.js +1 -1
- package/dist/index117.cjs +1 -1
- package/dist/index117.js +1 -1
- package/dist/index12.cjs +1 -1
- package/dist/index12.js +12 -12
- package/dist/index120.cjs +1 -1
- package/dist/index120.js +2 -2
- package/dist/index121.cjs +1 -1
- package/dist/index121.js +7 -7
- package/dist/index132.cjs +1 -1
- package/dist/index132.js +1 -1
- package/dist/index133.cjs +1 -1
- package/dist/index133.js +1 -1
- package/dist/index134.cjs +1 -1
- package/dist/index134.js +1 -1
- package/dist/index135.cjs +1 -1
- package/dist/index135.js +1 -1
- package/dist/index138.cjs +1 -1
- package/dist/index138.js +2 -2
- package/dist/index161.cjs +1 -1
- package/dist/index161.js +2 -2
- package/dist/index167.cjs +1 -1
- package/dist/index167.js +1 -1
- package/dist/index168.cjs +1 -1
- package/dist/index168.js +2 -2
- package/dist/index169.cjs +1 -1
- package/dist/index169.js +2 -2
- package/dist/index170.cjs +1 -1
- package/dist/index170.js +2 -2
- package/dist/index171.cjs +1 -1
- package/dist/index171.js +2 -2
- package/dist/index172.cjs +1 -1
- package/dist/index172.js +2 -2
- package/dist/index272.cjs +1 -1
- package/dist/index272.js +9 -174
- package/dist/index273.cjs +1 -2
- package/dist/index273.js +30 -91
- package/dist/index274.cjs +1 -1
- package/dist/index274.js +2 -41
- package/dist/index275.cjs +1 -1
- package/dist/index275.js +47 -4
- package/dist/index276.cjs +1 -1
- package/dist/index276.js +11 -9
- package/dist/index277.cjs +1 -1
- package/dist/index277.js +174 -30
- package/dist/index278.cjs +2 -1
- package/dist/index278.js +92 -2
- package/dist/index279.cjs +1 -1
- package/dist/index279.js +38 -45
- package/dist/index280.cjs +1 -1
- package/dist/index280.js +4 -11
- package/dist/index281.cjs +1 -1
- package/dist/index281.js +3 -3
- package/dist/index283.cjs +1 -2
- package/dist/index283.js +42 -41
- package/dist/index284.cjs +1 -1
- package/dist/index284.js +321 -2
- package/dist/index285.cjs +1 -1
- package/dist/index285.js +605 -5
- package/dist/index286.cjs +1 -1
- package/dist/index286.js +109 -10
- package/dist/index287.cjs +1 -1
- package/dist/index287.js +167 -19
- package/dist/index288.cjs +1 -1
- package/dist/index288.js +301 -8
- package/dist/index289.cjs +1 -1
- package/dist/index289.js +93 -72
- package/dist/index290.cjs +1 -1
- package/dist/index290.js +54 -63
- package/dist/index291.cjs +1 -1
- package/dist/index291.js +51 -186
- package/dist/index292.cjs +1 -1
- package/dist/index292.js +42 -20
- package/dist/index293.cjs +1 -1
- package/dist/index293.js +14 -41
- package/dist/index294.cjs +1 -1
- package/dist/index294.js +315 -23
- package/dist/index295.cjs +1 -1
- package/dist/index295.js +57 -88
- package/dist/index296.cjs +1 -1
- package/dist/index296.js +19 -40
- package/dist/index297.cjs +1 -1
- package/dist/index297.js +28 -15
- package/dist/index298.cjs +1 -1
- package/dist/index298.js +3 -13
- package/dist/index299.cjs +7 -1
- package/dist/index299.js +237 -7
- package/dist/index300.cjs +1 -1
- package/dist/index300.js +48 -38
- package/dist/index301.cjs +1 -1
- package/dist/index301.js +211 -14
- package/dist/index302.cjs +1 -1
- package/dist/index302.js +77 -38
- package/dist/index303.cjs +1 -1
- package/dist/index303.js +25 -316
- package/dist/index304.cjs +1 -1
- package/dist/index304.js +73 -602
- package/dist/index305.cjs +2 -1
- package/dist/index305.js +41 -109
- package/dist/index306.cjs +1 -1
- package/dist/index306.js +2 -168
- package/dist/index307.cjs +1 -1
- package/dist/index307.js +5 -301
- package/dist/index308.cjs +1 -1
- package/dist/index308.js +10 -93
- package/dist/index309.cjs +1 -1
- package/dist/index309.js +18 -55
- package/dist/index310.cjs +1 -1
- package/dist/index310.js +8 -53
- package/dist/index311.cjs +1 -1
- package/dist/index311.js +72 -44
- package/dist/index312.cjs +1 -1
- package/dist/index312.js +64 -14
- package/dist/index313.cjs +1 -1
- package/dist/index313.js +184 -313
- package/dist/index314.cjs +1 -1
- package/dist/index314.js +19 -56
- package/dist/index315.cjs +1 -1
- package/dist/index315.js +42 -19
- package/dist/index316.cjs +1 -1
- package/dist/index316.js +23 -27
- package/dist/index317.cjs +1 -1
- package/dist/index317.js +90 -3
- package/dist/index318.cjs +1 -7
- package/dist/index318.js +33 -230
- package/dist/index319.cjs +1 -1
- package/dist/index319.js +17 -48
- package/dist/index320.cjs +1 -1
- package/dist/index320.js +11 -210
- package/dist/index321.cjs +1 -1
- package/dist/index321.js +7 -81
- package/dist/index322.cjs +1 -1
- package/dist/index322.js +36 -28
- package/dist/index323.cjs +1 -1
- package/dist/index323.js +15 -76
- package/dist/index326.cjs +1 -1
- package/dist/index326.js +1 -1
- package/dist/index327.cjs +1 -1
- package/dist/index327.js +1 -1
- package/dist/index333.cjs +1 -1
- package/dist/index333.js +2 -2
- package/dist/index334.cjs +1 -1
- package/dist/index334.js +2 -2
- package/dist/index340.cjs +1 -1
- package/dist/index340.js +1 -1
- package/dist/index341.cjs +1 -1
- package/dist/index341.js +1 -1
- package/dist/index343.cjs +1 -1
- package/dist/index343.js +1 -1
- package/dist/index346.cjs +1 -1
- package/dist/index346.js +1 -1
- package/dist/index347.cjs +1 -1
- package/dist/index347.js +1 -1
- package/dist/index348.cjs +1 -1
- package/dist/index348.js +3 -3
- package/dist/index349.cjs +1 -2
- package/dist/index349.js +4 -193
- package/dist/index350.cjs +2 -1
- package/dist/index350.js +168 -52
- package/dist/index351.cjs +1 -1
- package/dist/index351.js +65 -331
- package/dist/index352.cjs +1 -1
- package/dist/index352.js +332 -149
- package/dist/index353.cjs +1 -1
- package/dist/index353.js +161 -5
- package/dist/index354.cjs +1 -1
- package/dist/index354.js +5 -5
- package/dist/index357.cjs +1 -1
- package/dist/index357.js +8 -205
- package/dist/index359.cjs +1 -1
- package/dist/index359.js +205 -8
- package/dist/index360.cjs +1 -1
- package/dist/index360.js +94 -68
- package/dist/index361.cjs +1 -1
- package/dist/index361.js +28 -94
- package/dist/index362.cjs +1 -1
- package/dist/index362.js +147 -27
- package/dist/index363.cjs +1 -1
- package/dist/index363.js +324 -118
- package/dist/index364.cjs +1 -1
- package/dist/index364.js +72 -353
- package/dist/index365.cjs +1 -1
- package/dist/index365.js +29 -71
- package/dist/index366.cjs +1 -1
- package/dist/index366.js +5 -31
- package/dist/index367.cjs +1 -1
- package/dist/index367.js +275 -5
- package/dist/index368.cjs +1 -1
- package/dist/index368.js +171 -4
- package/dist/index369.cjs +1 -1
- package/dist/index369.js +10 -141
- package/dist/index370.cjs +1 -1
- package/dist/index370.js +105 -273
- package/dist/index371.cjs +1 -1
- package/dist/index371.js +10 -171
- package/dist/index372.cjs +1 -1
- package/dist/index372.js +69 -10
- package/dist/index373.cjs +1 -1
- package/dist/index373.js +3 -107
- package/dist/index374.cjs +1 -1
- package/dist/index374.js +140 -9
- package/dist/index375.cjs +1 -1
- package/dist/index375.js +4 -4
- package/dist/index376.cjs +1 -1
- package/dist/index376.js +2 -79
- package/dist/index377.cjs +1 -1
- package/dist/index377.js +79 -2
- package/dist/index379.cjs +1 -1
- package/dist/index379.js +1 -1
- package/dist/index380.cjs +1 -1
- package/dist/index380.js +1 -1
- package/dist/index381.cjs +1 -1
- package/dist/index381.js +2 -22
- package/dist/index382.cjs +1 -1
- package/dist/index382.js +22 -2
- package/dist/index385.cjs +1 -1
- package/dist/index385.js +2 -2
- package/dist/index77.cjs +1 -1
- package/dist/index77.js +13 -13
- package/dist/index99.cjs +1 -1
- package/dist/index99.js +1 -1
- package/dist/src/lib/store/swapStore.d.ts +1 -1
- package/package.json +5 -5
package/dist/index361.js
CHANGED
|
@@ -1,97 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
* Read U16 value from the buffer and shift cursor by 2.
|
|
28
|
-
* @returns
|
|
29
|
-
*/
|
|
30
|
-
read16() {
|
|
31
|
-
const t = this.dataView.getUint16(this.bytePosition, !0);
|
|
32
|
-
return this.shift(2), t;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Read U32 value from the buffer and shift cursor by 4.
|
|
36
|
-
* @returns
|
|
37
|
-
*/
|
|
38
|
-
read32() {
|
|
39
|
-
const t = this.dataView.getUint32(this.bytePosition, !0);
|
|
40
|
-
return this.shift(4), t;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Read U64 value from the buffer and shift cursor by 8.
|
|
44
|
-
* @returns
|
|
45
|
-
*/
|
|
46
|
-
read64() {
|
|
47
|
-
const t = this.read32(), e = this.read32().toString(16) + t.toString(16).padStart(8, "0");
|
|
48
|
-
return BigInt("0x" + e).toString(10);
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Read U128 value from the buffer and shift cursor by 16.
|
|
52
|
-
*/
|
|
53
|
-
read128() {
|
|
54
|
-
const t = BigInt(this.read64()), e = BigInt(this.read64()).toString(16) + t.toString(16).padStart(16, "0");
|
|
55
|
-
return BigInt("0x" + e).toString(10);
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Read U128 value from the buffer and shift cursor by 32.
|
|
59
|
-
* @returns
|
|
60
|
-
*/
|
|
61
|
-
read256() {
|
|
62
|
-
const t = BigInt(this.read128()), e = BigInt(this.read128()).toString(16) + t.toString(16).padStart(32, "0");
|
|
63
|
-
return BigInt("0x" + e).toString(10);
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Read `num` number of bytes from the buffer and shift cursor by `num`.
|
|
67
|
-
* @param num Number of bytes to read.
|
|
68
|
-
*/
|
|
69
|
-
readBytes(t) {
|
|
70
|
-
const i = this.bytePosition + this.dataView.byteOffset, e = new Uint8Array(this.dataView.buffer, i, t);
|
|
71
|
-
return this.shift(t), e;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Read ULEB value - an integer of varying size. Used for enum indexes and
|
|
75
|
-
* vector lengths.
|
|
76
|
-
* @returns {Number} The ULEB value.
|
|
77
|
-
*/
|
|
78
|
-
readULEB() {
|
|
79
|
-
const t = this.bytePosition + this.dataView.byteOffset, i = new Uint8Array(this.dataView.buffer, t), { value: e, length: s } = r(i);
|
|
80
|
-
return this.shift(s), e;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Read a BCS vector: read a length and then apply function `cb` X times
|
|
84
|
-
* where X is the length of the vector, defined as ULEB in BCS bytes.
|
|
85
|
-
* @param cb Callback to process elements of vector.
|
|
86
|
-
* @returns {Array<Any>} Array of the resulting values, returned by callback.
|
|
87
|
-
*/
|
|
88
|
-
readVec(t) {
|
|
89
|
-
const i = this.readULEB(), e = [];
|
|
90
|
-
for (let s = 0; s < i; s++)
|
|
91
|
-
e.push(t(this, s, i));
|
|
92
|
-
return e;
|
|
93
|
-
}
|
|
1
|
+
function l(t) {
|
|
2
|
+
let e = BigInt(t);
|
|
3
|
+
const n = [];
|
|
4
|
+
let r = 0;
|
|
5
|
+
if (e === 0n)
|
|
6
|
+
return [0];
|
|
7
|
+
for (; e > 0; )
|
|
8
|
+
n[r] = Number(e & 0x7fn), e >>= 7n, e > 0n && (n[r] |= 128), r += 1;
|
|
9
|
+
return n;
|
|
10
|
+
}
|
|
11
|
+
function u(t) {
|
|
12
|
+
let e = 0n, n = 0n, r = 0;
|
|
13
|
+
for (; ; ) {
|
|
14
|
+
if (r >= t.length)
|
|
15
|
+
throw new Error("ULEB decode error: buffer overflow");
|
|
16
|
+
const o = t[r];
|
|
17
|
+
if (r += 1, e += BigInt(o & 127) << n, !(o & 128))
|
|
18
|
+
break;
|
|
19
|
+
n += 7n;
|
|
20
|
+
}
|
|
21
|
+
if (e > BigInt(Number.MAX_SAFE_INTEGER))
|
|
22
|
+
throw new Error("ULEB decode error: value exceeds MAX_SAFE_INTEGER");
|
|
23
|
+
return {
|
|
24
|
+
value: Number(e),
|
|
25
|
+
length: r
|
|
26
|
+
};
|
|
94
27
|
}
|
|
95
28
|
export {
|
|
96
|
-
|
|
29
|
+
u as ulebDecode,
|
|
30
|
+
l as ulebEncode
|
|
97
31
|
};
|
package/dist/index362.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("./index361.cjs"),o=require("./index297.cjs");class a{constructor({initialSize:t=1024,maxSize:i=1/0,allocateSize:e=1024}={}){this.bytePosition=0,this.size=t,this.maxSize=i,this.allocateSize=e,this.dataView=new DataView(new ArrayBuffer(t))}ensureSizeOrGrow(t){const i=this.bytePosition+t;if(i>this.size){const e=Math.min(this.maxSize,Math.max(this.size+i,this.size+this.allocateSize));if(i>e)throw new Error(`Attempting to serialize to BCS, but buffer does not have enough size. Allocated size: ${this.size}, Max size: ${this.maxSize}, Required size: ${i}`);this.size=e;const s=new ArrayBuffer(this.size);new Uint8Array(s).set(new Uint8Array(this.dataView.buffer)),this.dataView=new DataView(s)}}shift(t){return this.bytePosition+=t,this}write8(t){return this.ensureSizeOrGrow(1),this.dataView.setUint8(this.bytePosition,Number(t)),this.shift(1)}writeBytes(t){this.ensureSizeOrGrow(t.length);for(let i=0;i<t.length;i++)this.dataView.setUint8(this.bytePosition+i,t[i]);return this.shift(t.length)}write16(t){return this.ensureSizeOrGrow(2),this.dataView.setUint16(this.bytePosition,Number(t),!0),this.shift(2)}write32(t){return this.ensureSizeOrGrow(4),this.dataView.setUint32(this.bytePosition,Number(t),!0),this.shift(4)}write64(t){return n(BigInt(t),8).forEach(i=>this.write8(i)),this}write128(t){return n(BigInt(t),16).forEach(i=>this.write8(i)),this}write256(t){return n(BigInt(t),32).forEach(i=>this.write8(i)),this}writeULEB(t){return h.ulebEncode(t).forEach(i=>this.write8(i)),this}writeVec(t,i){return this.writeULEB(t.length),Array.from(t).forEach((e,s)=>i(this,e,s,t.length)),this}*[Symbol.iterator](){for(let t=0;t<this.bytePosition;t++)yield this.dataView.getUint8(t);return this.toBytes()}toBytes(){return new Uint8Array(this.dataView.buffer.slice(0,this.bytePosition))}toString(t){return o.encodeStr(this.toBytes(),t)}}function n(r,t){const i=new Uint8Array(t);let e=0;for(;r>0;)i[e]=Number(r%BigInt(256)),r=r/BigInt(256),e+=1;return i}exports.BcsWriter=a;
|
package/dist/index362.js
CHANGED
|
@@ -1,31 +1,151 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { ulebEncode as n } from "./index361.js";
|
|
2
|
+
import { encodeStr as o } from "./index297.js";
|
|
3
|
+
class u {
|
|
4
|
+
constructor({
|
|
5
|
+
initialSize: t = 1024,
|
|
6
|
+
maxSize: i = 1 / 0,
|
|
7
|
+
allocateSize: e = 1024
|
|
8
|
+
} = {}) {
|
|
9
|
+
this.bytePosition = 0, this.size = t, this.maxSize = i, this.allocateSize = e, this.dataView = new DataView(new ArrayBuffer(t));
|
|
10
|
+
}
|
|
11
|
+
ensureSizeOrGrow(t) {
|
|
12
|
+
const i = this.bytePosition + t;
|
|
13
|
+
if (i > this.size) {
|
|
14
|
+
const e = Math.min(
|
|
15
|
+
this.maxSize,
|
|
16
|
+
Math.max(this.size + i, this.size + this.allocateSize)
|
|
17
|
+
);
|
|
18
|
+
if (i > e)
|
|
19
|
+
throw new Error(
|
|
20
|
+
`Attempting to serialize to BCS, but buffer does not have enough size. Allocated size: ${this.size}, Max size: ${this.maxSize}, Required size: ${i}`
|
|
21
|
+
);
|
|
22
|
+
this.size = e;
|
|
23
|
+
const s = new ArrayBuffer(this.size);
|
|
24
|
+
new Uint8Array(s).set(new Uint8Array(this.dataView.buffer)), this.dataView = new DataView(s);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Shift current cursor position by `bytes`.
|
|
29
|
+
*
|
|
30
|
+
* @param {Number} bytes Number of bytes to
|
|
31
|
+
* @returns {this} Self for possible chaining.
|
|
32
|
+
*/
|
|
33
|
+
shift(t) {
|
|
34
|
+
return this.bytePosition += t, this;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Write a U8 value into a buffer and shift cursor position by 1.
|
|
38
|
+
* @param {Number} value Value to write.
|
|
39
|
+
* @returns {this}
|
|
40
|
+
*/
|
|
41
|
+
write8(t) {
|
|
42
|
+
return this.ensureSizeOrGrow(1), this.dataView.setUint8(this.bytePosition, Number(t)), this.shift(1);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Write a U8 value into a buffer and shift cursor position by 1.
|
|
46
|
+
* @param {Number} value Value to write.
|
|
47
|
+
* @returns {this}
|
|
48
|
+
*/
|
|
49
|
+
writeBytes(t) {
|
|
50
|
+
this.ensureSizeOrGrow(t.length);
|
|
51
|
+
for (let i = 0; i < t.length; i++)
|
|
52
|
+
this.dataView.setUint8(this.bytePosition + i, t[i]);
|
|
53
|
+
return this.shift(t.length);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Write a U16 value into a buffer and shift cursor position by 2.
|
|
57
|
+
* @param {Number} value Value to write.
|
|
58
|
+
* @returns {this}
|
|
59
|
+
*/
|
|
60
|
+
write16(t) {
|
|
61
|
+
return this.ensureSizeOrGrow(2), this.dataView.setUint16(this.bytePosition, Number(t), !0), this.shift(2);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Write a U32 value into a buffer and shift cursor position by 4.
|
|
65
|
+
* @param {Number} value Value to write.
|
|
66
|
+
* @returns {this}
|
|
67
|
+
*/
|
|
68
|
+
write32(t) {
|
|
69
|
+
return this.ensureSizeOrGrow(4), this.dataView.setUint32(this.bytePosition, Number(t), !0), this.shift(4);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Write a U64 value into a buffer and shift cursor position by 8.
|
|
73
|
+
* @param {bigint} value Value to write.
|
|
74
|
+
* @returns {this}
|
|
75
|
+
*/
|
|
76
|
+
write64(t) {
|
|
77
|
+
return h(BigInt(t), 8).forEach((i) => this.write8(i)), this;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Write a U128 value into a buffer and shift cursor position by 16.
|
|
81
|
+
*
|
|
82
|
+
* @param {bigint} value Value to write.
|
|
83
|
+
* @returns {this}
|
|
84
|
+
*/
|
|
85
|
+
write128(t) {
|
|
86
|
+
return h(BigInt(t), 16).forEach((i) => this.write8(i)), this;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Write a U256 value into a buffer and shift cursor position by 16.
|
|
90
|
+
*
|
|
91
|
+
* @param {bigint} value Value to write.
|
|
92
|
+
* @returns {this}
|
|
93
|
+
*/
|
|
94
|
+
write256(t) {
|
|
95
|
+
return h(BigInt(t), 32).forEach((i) => this.write8(i)), this;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Write a ULEB value into a buffer and shift cursor position by number of bytes
|
|
99
|
+
* written.
|
|
100
|
+
* @param {Number} value Value to write.
|
|
101
|
+
* @returns {this}
|
|
102
|
+
*/
|
|
103
|
+
writeULEB(t) {
|
|
104
|
+
return n(t).forEach((i) => this.write8(i)), this;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Write a vector into a buffer by first writing the vector length and then calling
|
|
108
|
+
* a callback on each passed value.
|
|
109
|
+
*
|
|
110
|
+
* @param {Array<Any>} vector Array of elements to write.
|
|
111
|
+
* @param {WriteVecCb} cb Callback to call on each element of the vector.
|
|
112
|
+
* @returns {this}
|
|
113
|
+
*/
|
|
114
|
+
writeVec(t, i) {
|
|
115
|
+
return this.writeULEB(t.length), Array.from(t).forEach((e, s) => i(this, e, s, t.length)), this;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Adds support for iterations over the object.
|
|
119
|
+
* @returns {Uint8Array}
|
|
120
|
+
*/
|
|
121
|
+
// oxlint-disable-next-line require-yields
|
|
122
|
+
*[Symbol.iterator]() {
|
|
123
|
+
for (let t = 0; t < this.bytePosition; t++)
|
|
124
|
+
yield this.dataView.getUint8(t);
|
|
125
|
+
return this.toBytes();
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Get underlying buffer taking only value bytes (in case initial buffer size was bigger).
|
|
129
|
+
* @returns {Uint8Array} Resulting bcs.
|
|
130
|
+
*/
|
|
131
|
+
toBytes() {
|
|
132
|
+
return new Uint8Array(this.dataView.buffer.slice(0, this.bytePosition));
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Represent data as 'hex' or 'base64'
|
|
136
|
+
* @param encoding Encoding to use: 'base64' or 'hex'
|
|
137
|
+
*/
|
|
138
|
+
toString(t) {
|
|
139
|
+
return o(this.toBytes(), t);
|
|
140
|
+
}
|
|
10
141
|
}
|
|
11
|
-
function
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (r += 1, e += BigInt(o & 127) << n, !(o & 128))
|
|
18
|
-
break;
|
|
19
|
-
n += 7n;
|
|
20
|
-
}
|
|
21
|
-
if (e > BigInt(Number.MAX_SAFE_INTEGER))
|
|
22
|
-
throw new Error("ULEB decode error: value exceeds MAX_SAFE_INTEGER");
|
|
23
|
-
return {
|
|
24
|
-
value: Number(e),
|
|
25
|
-
length: r
|
|
26
|
-
};
|
|
142
|
+
function h(r, t) {
|
|
143
|
+
const i = new Uint8Array(t);
|
|
144
|
+
let e = 0;
|
|
145
|
+
for (; r > 0; )
|
|
146
|
+
i[e] = Number(r % BigInt(256)), r = r / BigInt(256), e += 1;
|
|
147
|
+
return i;
|
|
27
148
|
}
|
|
28
149
|
export {
|
|
29
|
-
u as
|
|
30
|
-
l as ulebEncode
|
|
150
|
+
u as BcsWriter
|
|
31
151
|
};
|
package/dist/index363.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("./index284.cjs"),m=require("./index361.cjs");function y(e,r,a){return new d.BcsType({read:t=>{const n=new Array(e);for(let u=0;u<e;u++)n[u]=r.read(t);return n},write:(t,n)=>{for(const u of t)r.write(u,n)},...a,name:(a==null?void 0:a.name)??`${r.name}[${e}]`,validate:t=>{var n;if((n=a==null?void 0:a.validate)==null||n.call(a,t),!t||typeof t!="object"||!("length"in t))throw new TypeError(`Expected array, found ${typeof t}`);if(t.length!==e)throw new TypeError(`Expected array of length ${e}, found ${t.length}`)}})}function w(e){return c.enum(`Option<${e.name}>`,{None:null,Some:e}).transform({input:r=>r==null?{None:!0}:{Some:r},output:r=>r.$kind==="Some"?r.Some:null})}function f(e,r){return new d.BcsType({read:a=>{const t=a.readULEB(),n=new Array(t);for(let u=0;u<t;u++)n[u]=e.read(a);return n},write:(a,t)=>{t.writeULEB(a.length);for(const n of a)e.write(n,t)},...r,name:(r==null?void 0:r.name)??`vector<${e.name}>`,validate:a=>{var t;if((t=r==null?void 0:r.validate)==null||t.call(r,a),!a||typeof a!="object"||!("length"in a))throw new TypeError(`Expected array, found ${typeof a}`)}})}function l(e,r){return c.vector(c.tuple([e,r])).transform({name:`Map<${e.name}, ${r.name}>`,input:a=>[...a.entries()],output:a=>{const t=new Map;for(const[n,u]of a)t.set(n,u);return t}})}const c={u8(e){return d.uIntBcsType({readMethod:"read8",writeMethod:"write8",size:1,maxValue:2**8-1,...e,name:(e==null?void 0:e.name)??"u8"})},u16(e){return d.uIntBcsType({readMethod:"read16",writeMethod:"write16",size:2,maxValue:2**16-1,...e,name:(e==null?void 0:e.name)??"u16"})},u32(e){return d.uIntBcsType({readMethod:"read32",writeMethod:"write32",size:4,maxValue:2**32-1,...e,name:(e==null?void 0:e.name)??"u32"})},u64(e){return d.bigUIntBcsType({readMethod:"read64",writeMethod:"write64",size:8,maxValue:2n**64n-1n,...e,name:(e==null?void 0:e.name)??"u64"})},u128(e){return d.bigUIntBcsType({readMethod:"read128",writeMethod:"write128",size:16,maxValue:2n**128n-1n,...e,name:(e==null?void 0:e.name)??"u128"})},u256(e){return d.bigUIntBcsType({readMethod:"read256",writeMethod:"write256",size:32,maxValue:2n**256n-1n,...e,name:(e==null?void 0:e.name)??"u256"})},bool(e){return d.fixedSizeBcsType({size:1,read:r=>r.read8()===1,write:(r,a)=>a.write8(r?1:0),...e,name:(e==null?void 0:e.name)??"bool",validate:r=>{var a;if((a=e==null?void 0:e.validate)==null||a.call(e,r),typeof r!="boolean")throw new TypeError(`Expected boolean, found ${typeof r}`)}})},uleb128(e){return d.dynamicSizeBcsType({read:r=>r.readULEB(),serialize:r=>Uint8Array.from(m.ulebEncode(r)),...e,name:(e==null?void 0:e.name)??"uleb128"})},bytes(e,r){return d.fixedSizeBcsType({size:e,read:a=>a.readBytes(e),write:(a,t)=>{t.writeBytes(new Uint8Array(a))},...r,name:(r==null?void 0:r.name)??`bytes[${e}]`,validate:a=>{var t;if((t=r==null?void 0:r.validate)==null||t.call(r,a),!a||typeof a!="object"||!("length"in a))throw new TypeError(`Expected array, found ${typeof a}`);if(a.length!==e)throw new TypeError(`Expected array of length ${e}, found ${a.length}`)}})},byteVector(e){return new d.BcsType({read:r=>{const a=r.readULEB();return r.readBytes(a)},write:(r,a)=>{const t=new Uint8Array(r);a.writeULEB(t.length),a.writeBytes(t)},...e,name:(e==null?void 0:e.name)??"vector<u8>",serializedSize:r=>{const a="length"in r?r.length:null;return a==null?null:m.ulebEncode(a).length+a},validate:r=>{var a;if((a=e==null?void 0:e.validate)==null||a.call(e,r),!r||typeof r!="object"||!("length"in r))throw new TypeError(`Expected array, found ${typeof r}`)}})},string(e){return d.stringLikeBcsType({toBytes:r=>new TextEncoder().encode(r),fromBytes:r=>new TextDecoder().decode(r),...e,name:(e==null?void 0:e.name)??"string"})},fixedArray:y,option:w,vector:f,tuple(e,r){return new d.BcsTuple({fields:e,...r})},struct(e,r,a){return new d.BcsStruct({name:e,fields:r,...a})},enum(e,r,a){return new d.BcsEnum({name:e,fields:r,...a})},map:l,lazy(e){return d.lazyBcsType(e)}};exports.bcs=c;
|