@wormhole-foundation/wormhole-connect 1.1.8 → 1.1.9-beta.0-development
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/assets/{algorand-Bg-MfjsH.js → algorand-vDDEz6KP.js} +2 -2
- package/dist/assets/{ccip-atE20ZEL.js → ccip-B1JPJPOY.js} +1 -1
- package/dist/assets/{cosmwasm-xANzAboS.js → cosmwasm-DP4CIVSM.js} +2 -2
- package/dist/assets/{evm-B20gvxWA.js → evm-BB3755Wr.js} +1 -1
- package/dist/assets/{evm-DiRlPnyB.js → evm-FvO3h1wl.js} +4 -4
- package/dist/assets/{index-C6qclzFA.js → index-B1mp7Z63.js} +1 -1
- package/dist/assets/{index-eLk_b8u9.js → index-BU0ECMia.js} +1 -1
- package/dist/assets/{index-DyD6kblh.js → index-BbJVBTsE.js} +1 -1
- package/dist/assets/{index-BYxgRLLh.js → index-BhEp9mlK.js} +1 -1
- package/dist/assets/{index-D3WFv54i.js → index-Bvun80fl.js} +1 -1
- package/dist/assets/{index-jD6ZZ5Tu.js → index-Bz-32kSJ.js} +1 -1
- package/dist/assets/{index-CLcPjTbq.js → index-CVb8oZT5.js} +2 -2
- package/dist/assets/index-DP2zLB5d.js +5 -0
- package/dist/assets/index-Dp6gvGvL.js +2 -0
- package/dist/assets/{index-CxijOPcm.js → index-re-SltAL.js} +1 -1
- package/dist/assets/{index-DOuohql9.js → index-tGkAuFX0.js} +1 -1
- package/dist/assets/{index.es-BxGbRBbk.js → index.es-D8YphuI4.js} +2 -2
- package/dist/assets/{solana-DOaiyZir.js → solana-Bc-ePjuF.js} +1 -1
- package/dist/assets/{sui-mXOoFb4M.js → sui-DVNpNCUB.js} +4 -4
- package/dist/assets/{unsignedTransaction-0WUum9tP.js → unsignedTransaction-CPy_oMd2.js} +1 -1
- package/dist/assets/unsignedTransaction-arVvzoJx.js +1 -0
- package/dist/main.js +58 -58
- package/dist/src/config/mainnet/tokens.d.ts.map +1 -1
- package/dist/src/config/testnet/tokens.d.ts.map +1 -1
- package/dist/src/hooks/useTransactionHistoryWHScan.d.ts.map +1 -1
- package/dist/src/icons/Chains/WORLD.d.ts.map +1 -1
- package/dist/src/icons/TokenIcons.d.ts.map +1 -1
- package/dist/src/icons/Tokens/WORLD.d.ts +4 -0
- package/dist/src/icons/Tokens/WORLD.d.ts.map +1 -0
- package/dist/src/utils/sdkv2.d.ts.map +1 -1
- package/lib/{algorand-DUcbNcTT.mjs → algorand-CprzAHj4.mjs} +3 -3
- package/lib/{algorand-BvtlkYvW.js → algorand-D2kn_YCP.js} +1 -1
- package/lib/{aptos-B4rlOyU6.mjs → aptos-Cbdd7TGX.mjs} +3 -3
- package/lib/{aptos-BhgRAjHC.js → aptos-CooxpMkq.js} +2 -2
- package/lib/{aptos-nQowjIcb.mjs → aptos-CxfujMIg.mjs} +1 -1
- package/lib/{aptos-DhzeFi4o.js → aptos-D4EZf1pL.js} +1 -1
- package/lib/{ccip-jzRXPLFO.mjs → ccip-B7sQsroM.mjs} +1 -1
- package/lib/{ccip-BGUsNrsA.js → ccip-l4G3agzc.js} +1 -1
- package/lib/{cosmwasm-CGeqw6cI.js → cosmwasm-CzoZmAov.js} +2 -2
- package/lib/{cosmwasm-DrywDSkp.mjs → cosmwasm-r9Dcfq2_.mjs} +6 -6
- package/lib/{events-DuoZYNKO.mjs → events-BD3jHr55.mjs} +1 -1
- package/lib/{events-COjha8bx.js → events-DPG_k7aT.js} +1 -1
- package/lib/{evm-BBDClE2g.js → evm-CWPWco3x.js} +4 -4
- package/lib/{evm-BuIItcEA.mjs → evm-CqZH4qDI.mjs} +12 -12
- package/lib/{evm-CYnUn08H.js → evm-DA0UVqiZ.js} +1 -1
- package/lib/{evm-CEj34i-Y.mjs → evm-MLYkwdYo.mjs} +7 -7
- package/lib/{index-CdExxm-8.mjs → index-1P7DtP2r.mjs} +2 -2
- package/lib/{index-CJEjOaWr.mjs → index-5sE8OCOP.mjs} +1 -1
- package/lib/{index-NNKFqYq6.js → index-B2ALlGbm.js} +1 -1
- package/lib/{index-BJvQdk3o.js → index-B72tCThM.js} +7 -7
- package/lib/{index-CWM3H2LC.js → index-B9-xYyXd.js} +1 -1
- package/lib/{index-Bbhbkgfa.mjs → index-B9mhdAdq.mjs} +2 -2
- package/lib/{index-D9h0sJ3x.mjs → index-BA3kjRAK.mjs} +1 -1
- package/lib/{index-BIVNmWjC.js → index-BKK6e2Zn.js} +1 -1
- package/lib/{index-CRv6XxH6.mjs → index-BYIBymjK.mjs} +2 -2
- package/lib/{index-Cyjyg63s.js → index-BbDtFGWT.js} +1 -1
- package/lib/{index-DKptU_Hc.mjs → index-Bp9D0p75.mjs} +4 -4
- package/lib/{index-uAstvLd8.mjs → index-Bt79Gcg4.mjs} +2 -2
- package/lib/{index-Dc5wV51P.mjs → index-BwifXygO.mjs} +218 -125
- package/lib/{index-B6AFQ_fB.js → index-C-_dVgsh.js} +1 -1
- package/lib/{index-Bh9u5bZu.mjs → index-C41sqz-E.mjs} +2 -2
- package/lib/{index-B2JFHCjY.js → index-CGpV5u19.js} +1 -1
- package/lib/{index-BTncL8og.js → index-CRM9RIQm.js} +1 -1
- package/lib/{index-B-LwhonE.js → index-CT6UJ_EL.js} +1 -1
- package/lib/{index-CTHiXye2.js → index-CWJxT6vs.js} +1 -1
- package/lib/{index-Ds_oSleh.js → index-CgdZLNBr.js} +1 -1
- package/lib/{index-CjexIr7B.mjs → index-Ch4JHScc.mjs} +2 -2
- package/lib/{index-BJuAlURA.mjs → index-CjBfG1PD.mjs} +3 -3
- package/lib/index-CuMsUIvK.js +5 -0
- package/lib/{index-Cdpg2Kj3.mjs → index-CzSNeEZ7.mjs} +2 -2
- package/lib/{index-BXkKxPSN.mjs → index-D0i-3BNU.mjs} +2 -2
- package/lib/{index-a5wU3oUB.js → index-D2NQOwWl.js} +1 -1
- package/lib/{index-vjvft509.js → index-D6IvMYTY.js} +1 -1
- package/lib/{index-CXIAreWV.js → index-D6_pFYbp.js} +1 -1
- package/lib/{index-BISC0EuN.mjs → index-D7o-xpfy.mjs} +2 -2
- package/lib/index-DG-zySXj.js +1 -0
- package/lib/index-DPkB79ju.mjs +3816 -0
- package/lib/{index-DcurocLc.mjs → index-DTDgv8BR.mjs} +2 -2
- package/lib/{index-DdeuHj0J.mjs → index-D_HXrfx2.mjs} +1 -1
- package/lib/{index-qoWS15WJ.mjs → index-DfZldCn-.mjs} +4 -4
- package/lib/{index-D9fbH3oE.mjs → index-Dfq8cOSZ.mjs} +11 -11
- package/lib/{index-A72nDBhY.mjs → index-DgCVdoY_.mjs} +1 -1
- package/lib/{index-BuGRcK_Q.js → index-DsaeOVzT.js} +1 -1
- package/lib/{index-8IabBseN.js → index-DtJmfQmV.js} +1 -1
- package/lib/{index-D5tJ7kz1.js → index-HoGFMJt0.js} +1 -1
- package/lib/{index-BeJsTgpu.mjs → index-JEf11FIl.mjs} +4 -4
- package/lib/{index-D7uCV0-2.mjs → index-LhBPWv5M.mjs} +140 -149
- package/lib/{index-DlnKgVH2.js → index-LnwD-DoX.js} +1 -1
- package/lib/{index-HLOU4jOA.mjs → index-QA9dpScn.mjs} +2 -2
- package/lib/{index-Bi4OJr6O.js → index-ZlQhJUEX.js} +1 -1
- package/lib/index-qXJjecnK.js +5 -0
- package/lib/{index-DEi8dfu-.js → index-ruz_whBI.js} +1 -1
- package/lib/{index.es-tj48a6VI.mjs → index.es-DpTW5wIE.mjs} +5 -5
- package/lib/{index.es-ex5QzFoQ.js → index.es-Pku98btF.js} +2 -2
- package/lib/index.js +1 -1
- package/lib/index.mjs +2 -2
- package/lib/{keccak-CVFfUSfU.mjs → keccak-DWESGy_C.mjs} +1 -1
- package/lib/{keccak-CzODwJ6V.js → keccak-Rx7RS8L6.js} +1 -1
- package/lib/{pbkdf2-DLmVRSHA.js → pbkdf2-6hG-XBJs.js} +1 -1
- package/lib/{pbkdf2-GUTNazYD.mjs → pbkdf2-BVpVer9L.mjs} +1 -1
- package/lib/{signer-rbcgQjZj.js → signer-DhWIDOWp.js} +1 -1
- package/lib/{signer-Cqs1I7RB.mjs → signer-Dz4VN8ZI.mjs} +1 -1
- package/lib/solana-B6zAgqCg.mjs +16 -0
- package/lib/{solana-DoqT3pca.js → solana-BWM14UIk.js} +1 -1
- package/lib/solana-CKkJ-kf3.js +1 -0
- package/lib/{solana-7ZFkKRtX.mjs → solana-Dvddqnn3.mjs} +4 -4
- package/lib/{solanaEmbed.esm-Bkti_f5v.js → solanaEmbed.esm-Ghqj1fn8.js} +1 -1
- package/lib/{solanaEmbed.esm-LdO_IpPZ.mjs → solanaEmbed.esm-qmqvaX26.mjs} +3 -3
- package/lib/src/config/mainnet/tokens.d.ts.map +1 -1
- package/lib/src/config/testnet/tokens.d.ts.map +1 -1
- package/lib/src/hooks/useTransactionHistoryWHScan.d.ts.map +1 -1
- package/lib/src/icons/Chains/WORLD.d.ts.map +1 -1
- package/lib/src/icons/TokenIcons.d.ts.map +1 -1
- package/lib/src/icons/Tokens/WORLD.d.ts +4 -0
- package/lib/src/icons/Tokens/WORLD.d.ts.map +1 -0
- package/lib/src/utils/sdkv2.d.ts.map +1 -1
- package/lib/{sui-DfRirJoo.js → sui-BAoaV0fk.js} +1 -1
- package/lib/{sui-Df7REI6I.js → sui-COMAcPz7.js} +2 -2
- package/lib/{sui-Ch7mNd_P.mjs → sui-DKW6LQmE.mjs} +74 -75
- package/lib/{sui-BffnXOND.mjs → sui-DWDf6r1T.mjs} +1 -1
- package/lib/{unsignedTransaction-CvjJdjtG.js → unsignedTransaction-B9dxNqAu.js} +1 -1
- package/lib/unsignedTransaction-BD81leu1.mjs +16 -0
- package/lib/unsignedTransaction-DzSLsK-p.js +1 -0
- package/lib/{unsignedTransaction-CsCwFMvo.mjs → unsignedTransaction-T9pxJxVn.mjs} +4 -4
- package/package.json +17 -17
- package/dist/assets/index-CKe5Sopa.js +0 -2
- package/dist/src/utils/repairVaa.d.ts +0 -4
- package/dist/src/utils/repairVaa.d.ts.map +0 -1
- package/lib/index-BsHKXTKU.js +0 -1
- package/lib/index-DgbQ-dwi.js +0 -5
- package/lib/solana-BYPpXpJs.js +0 -1
- package/lib/solana-CcjhlsWI.mjs +0 -16
- package/lib/src/utils/repairVaa.d.ts +0 -4
- package/lib/src/utils/repairVaa.d.ts.map +0 -1
|
@@ -0,0 +1,3816 @@
|
|
|
1
|
+
var Er = Object.defineProperty;
|
|
2
|
+
var xr = (e, t, r) => t in e ? Er(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var F = (e, t, r) => xr(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
+
import { ak as Ir, F as jr, cM as Or, bV as Ar, bT as kr, bU as Bt, u as _r, bW as Rt, bI as Cr } from "./index-BwifXygO.mjs";
|
|
5
|
+
import { S as Nt, u as Pt } from "./sui-DKW6LQmE.mjs";
|
|
6
|
+
import { S as $r } from "./unsignedTransaction-BD81leu1.mjs";
|
|
7
|
+
class Mr extends TypeError {
|
|
8
|
+
constructor(t, r) {
|
|
9
|
+
let n;
|
|
10
|
+
const { message: i, explanation: s, ...a } = t, { path: o } = t, u = o.length === 0 ? i : `At path: ${o.join(".")} -- ${i}`;
|
|
11
|
+
super(s ?? u), s != null && (this.cause = u), Object.assign(this, a), this.name = this.constructor.name, this.failures = () => n ?? (n = [t, ...r()]);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function Ur(e) {
|
|
15
|
+
return z(e) && typeof e[Symbol.iterator] == "function";
|
|
16
|
+
}
|
|
17
|
+
function z(e) {
|
|
18
|
+
return typeof e == "object" && e != null;
|
|
19
|
+
}
|
|
20
|
+
function V(e) {
|
|
21
|
+
return typeof e == "symbol" ? e.toString() : typeof e == "string" ? JSON.stringify(e) : `${e}`;
|
|
22
|
+
}
|
|
23
|
+
function Br(e) {
|
|
24
|
+
const { done: t, value: r } = e.next();
|
|
25
|
+
return t ? void 0 : r;
|
|
26
|
+
}
|
|
27
|
+
function Rr(e, t, r, n) {
|
|
28
|
+
if (e === !0)
|
|
29
|
+
return;
|
|
30
|
+
e === !1 ? e = {} : typeof e == "string" && (e = { message: e });
|
|
31
|
+
const { path: i, branch: s } = t, { type: a } = r, { refinement: o, message: u = `Expected a value of type \`${a}\`${o ? ` with refinement \`${o}\`` : ""}, but received: \`${V(n)}\`` } = e;
|
|
32
|
+
return {
|
|
33
|
+
value: n,
|
|
34
|
+
type: a,
|
|
35
|
+
refinement: o,
|
|
36
|
+
key: i[i.length - 1],
|
|
37
|
+
path: i,
|
|
38
|
+
branch: s,
|
|
39
|
+
...e,
|
|
40
|
+
message: u
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function* Dt(e, t, r, n) {
|
|
44
|
+
Ur(e) || (e = [e]);
|
|
45
|
+
for (const i of e) {
|
|
46
|
+
const s = Rr(i, t, r, n);
|
|
47
|
+
s && (yield s);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function* nt(e, t, r = {}) {
|
|
51
|
+
const { path: n = [], branch: i = [e], coerce: s = !1, mask: a = !1 } = r, o = { path: n, branch: i };
|
|
52
|
+
if (s && (e = t.coercer(e, o), a && t.type !== "type" && z(t.schema) && z(e) && !Array.isArray(e)))
|
|
53
|
+
for (const d in e)
|
|
54
|
+
t.schema[d] === void 0 && delete e[d];
|
|
55
|
+
let u = "valid";
|
|
56
|
+
for (const d of t.validator(e, o))
|
|
57
|
+
d.explanation = r.message, u = "not_valid", yield [d, void 0];
|
|
58
|
+
for (let [d, l, g] of t.entries(e, o)) {
|
|
59
|
+
const m = nt(l, g, {
|
|
60
|
+
path: d === void 0 ? n : [...n, d],
|
|
61
|
+
branch: d === void 0 ? i : [...i, l],
|
|
62
|
+
coerce: s,
|
|
63
|
+
mask: a,
|
|
64
|
+
message: r.message
|
|
65
|
+
});
|
|
66
|
+
for (const p of m)
|
|
67
|
+
p[0] ? (u = p[0].refinement != null ? "not_refined" : "not_valid", yield [p[0], void 0]) : s && (l = p[1], d === void 0 ? e = l : e instanceof Map ? e.set(d, l) : e instanceof Set ? e.add(l) : z(e) && (l !== void 0 || d in e) && (e[d] = l));
|
|
68
|
+
}
|
|
69
|
+
if (u !== "not_valid")
|
|
70
|
+
for (const d of t.refiner(e, o))
|
|
71
|
+
d.explanation = r.message, u = "not_refined", yield [d, void 0];
|
|
72
|
+
u === "valid" && (yield [void 0, e]);
|
|
73
|
+
}
|
|
74
|
+
class Z {
|
|
75
|
+
constructor(t) {
|
|
76
|
+
const { type: r, schema: n, validator: i, refiner: s, coercer: a = (u) => u, entries: o = function* () {
|
|
77
|
+
} } = t;
|
|
78
|
+
this.type = r, this.schema = n, this.entries = o, this.coercer = a, i ? this.validator = (u, d) => {
|
|
79
|
+
const l = i(u, d);
|
|
80
|
+
return Dt(l, d, this, u);
|
|
81
|
+
} : this.validator = () => [], s ? this.refiner = (u, d) => {
|
|
82
|
+
const l = s(u, d);
|
|
83
|
+
return Dt(l, d, this, u);
|
|
84
|
+
} : this.refiner = () => [];
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Assert that a value passes the struct's validation, throwing if it doesn't.
|
|
88
|
+
*/
|
|
89
|
+
assert(t, r) {
|
|
90
|
+
return qe(t, this, r);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Create a value with the struct's coercion logic, then validate it.
|
|
94
|
+
*/
|
|
95
|
+
create(t, r) {
|
|
96
|
+
return Lt(t, this, r);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Check if a value passes the struct's validation.
|
|
100
|
+
*/
|
|
101
|
+
is(t) {
|
|
102
|
+
return N(t, this);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Mask a value, coercing and validating it, but returning only the subset of
|
|
106
|
+
* properties defined by the struct's schema.
|
|
107
|
+
*/
|
|
108
|
+
mask(t, r) {
|
|
109
|
+
return Kt(t, this, r);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Validate a value with the struct's validation logic, returning a tuple
|
|
113
|
+
* representing the result.
|
|
114
|
+
*
|
|
115
|
+
* You may optionally pass `true` for the `withCoercion` argument to coerce
|
|
116
|
+
* the value before attempting to validate it. If you do, the result will
|
|
117
|
+
* contain the coerced result when successful.
|
|
118
|
+
*/
|
|
119
|
+
validate(t, r = {}) {
|
|
120
|
+
return Ee(t, this, r);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function qe(e, t, r) {
|
|
124
|
+
const n = Ee(e, t, { message: r });
|
|
125
|
+
if (n[0])
|
|
126
|
+
throw n[0];
|
|
127
|
+
}
|
|
128
|
+
function Lt(e, t, r) {
|
|
129
|
+
const n = Ee(e, t, { coerce: !0, message: r });
|
|
130
|
+
if (n[0])
|
|
131
|
+
throw n[0];
|
|
132
|
+
return n[1];
|
|
133
|
+
}
|
|
134
|
+
function Kt(e, t, r) {
|
|
135
|
+
const n = Ee(e, t, { coerce: !0, mask: !0, message: r });
|
|
136
|
+
if (n[0])
|
|
137
|
+
throw n[0];
|
|
138
|
+
return n[1];
|
|
139
|
+
}
|
|
140
|
+
function N(e, t) {
|
|
141
|
+
return !Ee(e, t)[0];
|
|
142
|
+
}
|
|
143
|
+
function Ee(e, t, r = {}) {
|
|
144
|
+
const n = nt(e, t, r), i = Br(n);
|
|
145
|
+
return i[0] ? [new Mr(i[0], function* () {
|
|
146
|
+
for (const a of n)
|
|
147
|
+
a[0] && (yield a[0]);
|
|
148
|
+
}), void 0] : [void 0, i[1]];
|
|
149
|
+
}
|
|
150
|
+
function we(...e) {
|
|
151
|
+
const t = e[0].type === "type", r = e.map((i) => i.schema), n = Object.assign({}, ...r);
|
|
152
|
+
return t ? Pr(n) : h(n);
|
|
153
|
+
}
|
|
154
|
+
function P(e, t) {
|
|
155
|
+
return new Z({ type: e, schema: null, validator: t });
|
|
156
|
+
}
|
|
157
|
+
function Ze() {
|
|
158
|
+
return P("any", () => !0);
|
|
159
|
+
}
|
|
160
|
+
function v(e) {
|
|
161
|
+
return new Z({
|
|
162
|
+
type: "array",
|
|
163
|
+
schema: e,
|
|
164
|
+
*entries(t) {
|
|
165
|
+
if (e && Array.isArray(t))
|
|
166
|
+
for (const [r, n] of t.entries())
|
|
167
|
+
yield [r, n, e];
|
|
168
|
+
},
|
|
169
|
+
coercer(t) {
|
|
170
|
+
return Array.isArray(t) ? t.slice() : t;
|
|
171
|
+
},
|
|
172
|
+
validator(t) {
|
|
173
|
+
return Array.isArray(t) || `Expected an array value, but received: ${V(t)}`;
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
function Nr() {
|
|
178
|
+
return P("bigint", (e) => typeof e == "bigint");
|
|
179
|
+
}
|
|
180
|
+
function U() {
|
|
181
|
+
return P("boolean", (e) => typeof e == "boolean");
|
|
182
|
+
}
|
|
183
|
+
function q() {
|
|
184
|
+
return P("integer", (e) => typeof e == "number" && !isNaN(e) && Number.isInteger(e) || `Expected an integer, but received: ${V(e)}`);
|
|
185
|
+
}
|
|
186
|
+
function b(e) {
|
|
187
|
+
const t = V(e), r = typeof e;
|
|
188
|
+
return new Z({
|
|
189
|
+
type: "literal",
|
|
190
|
+
schema: r === "string" || r === "number" || r === "boolean" ? e : null,
|
|
191
|
+
validator(n) {
|
|
192
|
+
return n === e || `Expected the literal \`${t}\`, but received: ${V(n)}`;
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
function Wt() {
|
|
197
|
+
return P("never", () => !1);
|
|
198
|
+
}
|
|
199
|
+
function O(e) {
|
|
200
|
+
return new Z({
|
|
201
|
+
...e,
|
|
202
|
+
validator: (t, r) => t === null || e.validator(t, r),
|
|
203
|
+
refiner: (t, r) => t === null || e.refiner(t, r)
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
function ue() {
|
|
207
|
+
return P("number", (e) => typeof e == "number" && !isNaN(e) || `Expected a number, but received: ${V(e)}`);
|
|
208
|
+
}
|
|
209
|
+
function h(e) {
|
|
210
|
+
const t = e ? Object.keys(e) : [], r = Wt();
|
|
211
|
+
return new Z({
|
|
212
|
+
type: "object",
|
|
213
|
+
schema: e || null,
|
|
214
|
+
*entries(n) {
|
|
215
|
+
if (e && z(n)) {
|
|
216
|
+
const i = new Set(Object.keys(n));
|
|
217
|
+
for (const s of t)
|
|
218
|
+
i.delete(s), yield [s, n[s], e[s]];
|
|
219
|
+
for (const s of i)
|
|
220
|
+
yield [s, n[s], r];
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
validator(n) {
|
|
224
|
+
return z(n) || `Expected an object, but received: ${V(n)}`;
|
|
225
|
+
},
|
|
226
|
+
coercer(n) {
|
|
227
|
+
return z(n) ? { ...n } : n;
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
function w(e) {
|
|
232
|
+
return new Z({
|
|
233
|
+
...e,
|
|
234
|
+
validator: (t, r) => t === void 0 || e.validator(t, r),
|
|
235
|
+
refiner: (t, r) => t === void 0 || e.refiner(t, r)
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
function H(e, t) {
|
|
239
|
+
return new Z({
|
|
240
|
+
type: "record",
|
|
241
|
+
schema: null,
|
|
242
|
+
*entries(r) {
|
|
243
|
+
if (z(r))
|
|
244
|
+
for (const n in r) {
|
|
245
|
+
const i = r[n];
|
|
246
|
+
yield [n, n, e], yield [n, i, t];
|
|
247
|
+
}
|
|
248
|
+
},
|
|
249
|
+
validator(r) {
|
|
250
|
+
return z(r) || `Expected an object, but received: ${V(r)}`;
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
function f() {
|
|
255
|
+
return P("string", (e) => typeof e == "string" || `Expected a string, but received: ${V(e)}`);
|
|
256
|
+
}
|
|
257
|
+
function Jt(e) {
|
|
258
|
+
const t = Wt();
|
|
259
|
+
return new Z({
|
|
260
|
+
type: "tuple",
|
|
261
|
+
schema: null,
|
|
262
|
+
*entries(r) {
|
|
263
|
+
if (Array.isArray(r)) {
|
|
264
|
+
const n = Math.max(e.length, r.length);
|
|
265
|
+
for (let i = 0; i < n; i++)
|
|
266
|
+
yield [i, r[i], e[i] || t];
|
|
267
|
+
}
|
|
268
|
+
},
|
|
269
|
+
validator(r) {
|
|
270
|
+
return Array.isArray(r) || `Expected an array, but received: ${V(r)}`;
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
function Pr(e) {
|
|
275
|
+
const t = Object.keys(e);
|
|
276
|
+
return new Z({
|
|
277
|
+
type: "type",
|
|
278
|
+
schema: e,
|
|
279
|
+
*entries(r) {
|
|
280
|
+
if (z(r))
|
|
281
|
+
for (const n of t)
|
|
282
|
+
yield [n, r[n], e[n]];
|
|
283
|
+
},
|
|
284
|
+
validator(r) {
|
|
285
|
+
return z(r) || `Expected an object, but received: ${V(r)}`;
|
|
286
|
+
},
|
|
287
|
+
coercer(r) {
|
|
288
|
+
return z(r) ? { ...r } : r;
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
function k(e) {
|
|
293
|
+
const t = e.map((r) => r.type).join(" | ");
|
|
294
|
+
return new Z({
|
|
295
|
+
type: "union",
|
|
296
|
+
schema: null,
|
|
297
|
+
coercer(r) {
|
|
298
|
+
for (const n of e) {
|
|
299
|
+
const [i, s] = n.validate(r, { coerce: !0 });
|
|
300
|
+
if (!i)
|
|
301
|
+
return s;
|
|
302
|
+
}
|
|
303
|
+
return r;
|
|
304
|
+
},
|
|
305
|
+
validator(r, n) {
|
|
306
|
+
const i = [];
|
|
307
|
+
for (const s of e) {
|
|
308
|
+
const [...a] = nt(r, s, n), [o] = a;
|
|
309
|
+
if (o[0])
|
|
310
|
+
for (const [u] of a)
|
|
311
|
+
u && i.push(u);
|
|
312
|
+
else
|
|
313
|
+
return [];
|
|
314
|
+
}
|
|
315
|
+
return [
|
|
316
|
+
`Expected the value to satisfy a union of \`${t}\`, but received: ${V(r)}`,
|
|
317
|
+
...i
|
|
318
|
+
];
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
function Ht() {
|
|
323
|
+
return P("unknown", () => !0);
|
|
324
|
+
}
|
|
325
|
+
const it = k([
|
|
326
|
+
h({
|
|
327
|
+
AddressOwner: f()
|
|
328
|
+
}),
|
|
329
|
+
h({
|
|
330
|
+
ObjectOwner: f()
|
|
331
|
+
}),
|
|
332
|
+
h({
|
|
333
|
+
Shared: h({
|
|
334
|
+
initial_shared_version: O(f())
|
|
335
|
+
})
|
|
336
|
+
}),
|
|
337
|
+
b("Immutable")
|
|
338
|
+
]);
|
|
339
|
+
P("SuiJsonValue", () => !0);
|
|
340
|
+
const Dr = k([
|
|
341
|
+
h({ u32: f() }),
|
|
342
|
+
h({ u64: f() }),
|
|
343
|
+
h({ f64: f() })
|
|
344
|
+
]);
|
|
345
|
+
h({
|
|
346
|
+
attributes: H(f(), O(Dr)),
|
|
347
|
+
featureFlags: H(f(), U()),
|
|
348
|
+
maxSupportedProtocolVersion: f(),
|
|
349
|
+
minSupportedProtocolVersion: f(),
|
|
350
|
+
protocolVersion: f()
|
|
351
|
+
});
|
|
352
|
+
k([f(), b("package")]);
|
|
353
|
+
const se = h({
|
|
354
|
+
/** Base64 string representing the object digest */
|
|
355
|
+
digest: f(),
|
|
356
|
+
/** Hex code as string representing the object id */
|
|
357
|
+
objectId: f(),
|
|
358
|
+
/** Object version */
|
|
359
|
+
version: k([ue(), f(), Nr()])
|
|
360
|
+
});
|
|
361
|
+
h({
|
|
362
|
+
owner: it,
|
|
363
|
+
reference: se
|
|
364
|
+
});
|
|
365
|
+
h({
|
|
366
|
+
objectId: f(),
|
|
367
|
+
sequenceNumber: f()
|
|
368
|
+
});
|
|
369
|
+
h({
|
|
370
|
+
payment: v(se),
|
|
371
|
+
/** Gas Object's owner */
|
|
372
|
+
owner: f(),
|
|
373
|
+
price: f(),
|
|
374
|
+
budget: f()
|
|
375
|
+
});
|
|
376
|
+
const zr = we(
|
|
377
|
+
se,
|
|
378
|
+
h({
|
|
379
|
+
type: f(),
|
|
380
|
+
owner: it,
|
|
381
|
+
previousTransaction: f()
|
|
382
|
+
})
|
|
383
|
+
), Vr = H(f(), Ze()), Gr = H(f(), Ht()), Fr = h({
|
|
384
|
+
/** Move type (e.g., "0x2::coin::Coin<0x2::sui::SUI>") */
|
|
385
|
+
type: f(),
|
|
386
|
+
/** Fields and values stored inside the Move object */
|
|
387
|
+
fields: Vr,
|
|
388
|
+
hasPublicTransfer: U()
|
|
389
|
+
}), Lr = h({
|
|
390
|
+
/** A mapping from module name to disassembled Move bytecode */
|
|
391
|
+
disassembled: Gr
|
|
392
|
+
}), Kr = k([
|
|
393
|
+
we(Fr, h({ dataType: b("moveObject") })),
|
|
394
|
+
we(Lr, h({ dataType: b("package") }))
|
|
395
|
+
]), Wr = h({
|
|
396
|
+
/** Move type (e.g., "0x2::coin::Coin<0x2::sui::SUI>") */
|
|
397
|
+
type: f(),
|
|
398
|
+
hasPublicTransfer: U(),
|
|
399
|
+
version: f(),
|
|
400
|
+
bcsBytes: f()
|
|
401
|
+
}), Jr = h({
|
|
402
|
+
id: f(),
|
|
403
|
+
/** A mapping from module name to Move bytecode enocded in base64*/
|
|
404
|
+
moduleMap: H(f(), f())
|
|
405
|
+
}), Hr = k([
|
|
406
|
+
we(Wr, h({ dataType: b("moveObject") })),
|
|
407
|
+
we(Jr, h({ dataType: b("package") }))
|
|
408
|
+
]);
|
|
409
|
+
BigInt(1e9);
|
|
410
|
+
const Xt = h({
|
|
411
|
+
code: f(),
|
|
412
|
+
error: w(f()),
|
|
413
|
+
object_id: w(f()),
|
|
414
|
+
parent_object_id: w(f()),
|
|
415
|
+
version: w(f()),
|
|
416
|
+
digest: w(f())
|
|
417
|
+
}), Xr = h({
|
|
418
|
+
data: O(w(H(f(), f()))),
|
|
419
|
+
error: O(w(Xt))
|
|
420
|
+
}), qr = k([
|
|
421
|
+
Xr,
|
|
422
|
+
w(H(f(), f()))
|
|
423
|
+
]), qt = h({
|
|
424
|
+
objectId: f(),
|
|
425
|
+
version: f(),
|
|
426
|
+
digest: f(),
|
|
427
|
+
/**
|
|
428
|
+
* Type of the object, default to be undefined unless SuiObjectDataOptions.showType is set to true
|
|
429
|
+
*/
|
|
430
|
+
type: O(w(f())),
|
|
431
|
+
/**
|
|
432
|
+
* Move object content or package content, default to be undefined unless SuiObjectDataOptions.showContent is set to true
|
|
433
|
+
*/
|
|
434
|
+
content: O(w(Kr)),
|
|
435
|
+
/**
|
|
436
|
+
* Move object content or package content in BCS bytes, default to be undefined unless SuiObjectDataOptions.showBcs is set to true
|
|
437
|
+
*/
|
|
438
|
+
bcs: O(w(Hr)),
|
|
439
|
+
/**
|
|
440
|
+
* The owner of this object. Default to be undefined unless SuiObjectDataOptions.showOwner is set to true
|
|
441
|
+
*/
|
|
442
|
+
owner: O(w(it)),
|
|
443
|
+
/**
|
|
444
|
+
* The digest of the transaction that created or last mutated this object.
|
|
445
|
+
* Default to be undefined unless SuiObjectDataOptions.showPreviousTransaction is set to true
|
|
446
|
+
*/
|
|
447
|
+
previousTransaction: O(w(f())),
|
|
448
|
+
/**
|
|
449
|
+
* The amount of SUI we would rebate if this object gets deleted.
|
|
450
|
+
* This number is re-calculated each time the object is mutated based on
|
|
451
|
+
* the present storage gas price.
|
|
452
|
+
* Default to be undefined unless SuiObjectDataOptions.showStorageRebate is set to true
|
|
453
|
+
*/
|
|
454
|
+
storageRebate: O(w(f())),
|
|
455
|
+
/**
|
|
456
|
+
* Display metadata for this object, default to be undefined unless SuiObjectDataOptions.showDisplay is set to true
|
|
457
|
+
* This can also be None if the struct type does not have Display defined
|
|
458
|
+
* See more details in https://forums.sui.io/t/nft-object-display-proposal/4872
|
|
459
|
+
*/
|
|
460
|
+
display: O(w(qr))
|
|
461
|
+
});
|
|
462
|
+
h({
|
|
463
|
+
/* Whether to fetch the object type, default to be true */
|
|
464
|
+
showType: O(w(U())),
|
|
465
|
+
/* Whether to fetch the object content, default to be false */
|
|
466
|
+
showContent: O(w(U())),
|
|
467
|
+
/* Whether to fetch the object content in BCS bytes, default to be false */
|
|
468
|
+
showBcs: O(w(U())),
|
|
469
|
+
/* Whether to fetch the object owner, default to be false */
|
|
470
|
+
showOwner: O(w(U())),
|
|
471
|
+
/* Whether to fetch the previous transaction digest, default to be false */
|
|
472
|
+
showPreviousTransaction: O(w(U())),
|
|
473
|
+
/* Whether to fetch the storage rebate, default to be false */
|
|
474
|
+
showStorageRebate: O(w(U())),
|
|
475
|
+
/* Whether to fetch the display metadata, default to be false */
|
|
476
|
+
showDisplay: O(w(U()))
|
|
477
|
+
});
|
|
478
|
+
k([b("Exists"), b("notExists"), b("Deleted")]);
|
|
479
|
+
v(zr);
|
|
480
|
+
const Zr = h({
|
|
481
|
+
data: O(w(qt)),
|
|
482
|
+
error: O(w(Xt))
|
|
483
|
+
});
|
|
484
|
+
function Yr(e) {
|
|
485
|
+
return e.data;
|
|
486
|
+
}
|
|
487
|
+
function Qr(e) {
|
|
488
|
+
if (e.error && "object_id" in e.error && "version" in e.error && "digest" in e.error) {
|
|
489
|
+
const t = e.error;
|
|
490
|
+
return {
|
|
491
|
+
objectId: t.object_id,
|
|
492
|
+
version: t.version,
|
|
493
|
+
digest: t.digest
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
function zt(e) {
|
|
498
|
+
if ("reference" in e)
|
|
499
|
+
return e.reference;
|
|
500
|
+
const t = Yr(e);
|
|
501
|
+
return t ? {
|
|
502
|
+
objectId: t.objectId,
|
|
503
|
+
version: t.version,
|
|
504
|
+
digest: t.digest
|
|
505
|
+
} : Qr(e);
|
|
506
|
+
}
|
|
507
|
+
h({
|
|
508
|
+
objectId: f(),
|
|
509
|
+
atCheckpoint: w(ue())
|
|
510
|
+
});
|
|
511
|
+
h({
|
|
512
|
+
data: v(Zr),
|
|
513
|
+
nextCursor: w(O(f())),
|
|
514
|
+
hasNextPage: U()
|
|
515
|
+
});
|
|
516
|
+
k([
|
|
517
|
+
h({
|
|
518
|
+
details: qt,
|
|
519
|
+
status: b("VersionFound")
|
|
520
|
+
}),
|
|
521
|
+
h({
|
|
522
|
+
details: f(),
|
|
523
|
+
status: b("ObjectNotExists")
|
|
524
|
+
}),
|
|
525
|
+
h({
|
|
526
|
+
details: se,
|
|
527
|
+
status: b("ObjectDeleted")
|
|
528
|
+
}),
|
|
529
|
+
h({
|
|
530
|
+
details: Jt([f(), ue()]),
|
|
531
|
+
status: b("VersionNotFound")
|
|
532
|
+
}),
|
|
533
|
+
h({
|
|
534
|
+
details: h({
|
|
535
|
+
asked_version: ue(),
|
|
536
|
+
latest_version: ue(),
|
|
537
|
+
object_id: f()
|
|
538
|
+
}),
|
|
539
|
+
status: b("VersionTooHigh")
|
|
540
|
+
})
|
|
541
|
+
]);
|
|
542
|
+
const en = k([f(), h({ Object: f() })]);
|
|
543
|
+
v(en);
|
|
544
|
+
const tn = h({
|
|
545
|
+
address: f(),
|
|
546
|
+
name: f()
|
|
547
|
+
}), rn = k([b("Private"), b("Public"), b("Friend")]), st = h({
|
|
548
|
+
abilities: v(f())
|
|
549
|
+
}), nn = h({
|
|
550
|
+
constraints: st,
|
|
551
|
+
isPhantom: U()
|
|
552
|
+
}), sn = h({
|
|
553
|
+
TypeParameter: ue()
|
|
554
|
+
}), Ge = Jt([
|
|
555
|
+
h({
|
|
556
|
+
module: f(),
|
|
557
|
+
package: f(),
|
|
558
|
+
function: f()
|
|
559
|
+
}),
|
|
560
|
+
f()
|
|
561
|
+
]);
|
|
562
|
+
h({
|
|
563
|
+
rank3Days: v(Ge),
|
|
564
|
+
rank7Days: v(Ge),
|
|
565
|
+
rank30Days: v(Ge)
|
|
566
|
+
});
|
|
567
|
+
function Zt(e) {
|
|
568
|
+
if (!e)
|
|
569
|
+
return !1;
|
|
570
|
+
if (typeof e == "string" || N(e, sn) || Yt(e))
|
|
571
|
+
return !0;
|
|
572
|
+
if (typeof e != "object")
|
|
573
|
+
return !1;
|
|
574
|
+
const t = e;
|
|
575
|
+
return !!(N(t.Reference, le) || N(t.MutableReference, le) || N(t.Vector, le));
|
|
576
|
+
}
|
|
577
|
+
const le = P(
|
|
578
|
+
"SuiMoveNormalizedType",
|
|
579
|
+
Zt
|
|
580
|
+
);
|
|
581
|
+
function Yt(e) {
|
|
582
|
+
if (!e || typeof e != "object")
|
|
583
|
+
return !1;
|
|
584
|
+
const t = e;
|
|
585
|
+
if (!t.Struct || typeof t.Struct != "object")
|
|
586
|
+
return !1;
|
|
587
|
+
const r = t.Struct;
|
|
588
|
+
return !(typeof r.address != "string" || typeof r.module != "string" || typeof r.name != "string" || !Array.isArray(r.typeArguments) || !r.typeArguments.every((n) => Zt(n)));
|
|
589
|
+
}
|
|
590
|
+
P(
|
|
591
|
+
"SuiMoveNormalizedStructType",
|
|
592
|
+
Yt
|
|
593
|
+
);
|
|
594
|
+
const an = h({
|
|
595
|
+
visibility: rn,
|
|
596
|
+
isEntry: U(),
|
|
597
|
+
typeParameters: v(st),
|
|
598
|
+
parameters: v(le),
|
|
599
|
+
return: v(le)
|
|
600
|
+
}), on = h({
|
|
601
|
+
name: f(),
|
|
602
|
+
type: le
|
|
603
|
+
}), cn = h({
|
|
604
|
+
abilities: st,
|
|
605
|
+
typeParameters: v(nn),
|
|
606
|
+
fields: v(on)
|
|
607
|
+
}), un = h({
|
|
608
|
+
fileFormatVersion: ue(),
|
|
609
|
+
address: f(),
|
|
610
|
+
name: f(),
|
|
611
|
+
friends: v(tn),
|
|
612
|
+
structs: H(f(), cn),
|
|
613
|
+
exposedFunctions: H(f(), an)
|
|
614
|
+
});
|
|
615
|
+
H(f(), un);
|
|
616
|
+
function Ye(e) {
|
|
617
|
+
return typeof e == "object" && "MutableReference" in e ? e.MutableReference : void 0;
|
|
618
|
+
}
|
|
619
|
+
function Qt(e) {
|
|
620
|
+
return typeof e == "object" && "Reference" in e ? e.Reference : void 0;
|
|
621
|
+
}
|
|
622
|
+
function at(e) {
|
|
623
|
+
if (typeof e == "object" && "Struct" in e)
|
|
624
|
+
return e;
|
|
625
|
+
const t = Qt(e), r = Ye(e);
|
|
626
|
+
if (typeof t == "object" && "Struct" in t)
|
|
627
|
+
return t;
|
|
628
|
+
if (typeof r == "object" && "Struct" in r)
|
|
629
|
+
return r;
|
|
630
|
+
}
|
|
631
|
+
function dn(e) {
|
|
632
|
+
if (e.length >= 255)
|
|
633
|
+
throw new TypeError("Alphabet too long");
|
|
634
|
+
for (var t = new Uint8Array(256), r = 0; r < t.length; r++)
|
|
635
|
+
t[r] = 255;
|
|
636
|
+
for (var n = 0; n < e.length; n++) {
|
|
637
|
+
var i = e.charAt(n), s = i.charCodeAt(0);
|
|
638
|
+
if (t[s] !== 255)
|
|
639
|
+
throw new TypeError(i + " is ambiguous");
|
|
640
|
+
t[s] = n;
|
|
641
|
+
}
|
|
642
|
+
var a = e.length, o = e.charAt(0), u = Math.log(a) / Math.log(256), d = Math.log(256) / Math.log(a);
|
|
643
|
+
function l(p) {
|
|
644
|
+
if (p instanceof Uint8Array || (ArrayBuffer.isView(p) ? p = new Uint8Array(p.buffer, p.byteOffset, p.byteLength) : Array.isArray(p) && (p = Uint8Array.from(p))), !(p instanceof Uint8Array))
|
|
645
|
+
throw new TypeError("Expected Uint8Array");
|
|
646
|
+
if (p.length === 0)
|
|
647
|
+
return "";
|
|
648
|
+
for (var y = 0, S = 0, E = 0, A = p.length; E !== A && p[E] === 0; )
|
|
649
|
+
E++, y++;
|
|
650
|
+
for (var _ = (A - E) * d + 1 >>> 0, D = new Uint8Array(_); E !== A; ) {
|
|
651
|
+
for (var X = p[E], ne = 0, G = _ - 1; (X !== 0 || ne < S) && G !== -1; G--, ne++)
|
|
652
|
+
X += 256 * D[G] >>> 0, D[G] = X % a >>> 0, X = X / a >>> 0;
|
|
653
|
+
if (X !== 0)
|
|
654
|
+
throw new Error("Non-zero carry");
|
|
655
|
+
S = ne, E++;
|
|
656
|
+
}
|
|
657
|
+
for (var Y = _ - S; Y !== _ && D[Y] === 0; )
|
|
658
|
+
Y++;
|
|
659
|
+
for (var Oe = o.repeat(y); Y < _; ++Y)
|
|
660
|
+
Oe += e.charAt(D[Y]);
|
|
661
|
+
return Oe;
|
|
662
|
+
}
|
|
663
|
+
function g(p) {
|
|
664
|
+
if (typeof p != "string")
|
|
665
|
+
throw new TypeError("Expected String");
|
|
666
|
+
if (p.length === 0)
|
|
667
|
+
return new Uint8Array();
|
|
668
|
+
for (var y = 0, S = 0, E = 0; p[y] === o; )
|
|
669
|
+
S++, y++;
|
|
670
|
+
for (var A = (p.length - y) * u + 1 >>> 0, _ = new Uint8Array(A); p[y]; ) {
|
|
671
|
+
var D = t[p.charCodeAt(y)];
|
|
672
|
+
if (D === 255)
|
|
673
|
+
return;
|
|
674
|
+
for (var X = 0, ne = A - 1; (D !== 0 || X < E) && ne !== -1; ne--, X++)
|
|
675
|
+
D += a * _[ne] >>> 0, _[ne] = D % 256 >>> 0, D = D / 256 >>> 0;
|
|
676
|
+
if (D !== 0)
|
|
677
|
+
throw new Error("Non-zero carry");
|
|
678
|
+
E = X, y++;
|
|
679
|
+
}
|
|
680
|
+
for (var G = A - E; G !== A && _[G] === 0; )
|
|
681
|
+
G++;
|
|
682
|
+
for (var Y = new Uint8Array(S + (A - G)), Oe = S; G !== A; )
|
|
683
|
+
Y[Oe++] = _[G++];
|
|
684
|
+
return Y;
|
|
685
|
+
}
|
|
686
|
+
function m(p) {
|
|
687
|
+
var y = g(p);
|
|
688
|
+
if (y)
|
|
689
|
+
return y;
|
|
690
|
+
throw new Error("Non-base" + a + " character");
|
|
691
|
+
}
|
|
692
|
+
return {
|
|
693
|
+
encode: l,
|
|
694
|
+
decodeUnsafe: g,
|
|
695
|
+
decode: m
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
var fn = dn;
|
|
699
|
+
const ln = fn, hn = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
700
|
+
var gn = ln(hn);
|
|
701
|
+
const er = /* @__PURE__ */ Ir(gn), xe = (e) => er.encode(e), ot = (e) => er.decode(e);
|
|
702
|
+
function ae(e) {
|
|
703
|
+
return Uint8Array.from(atob(e), (t) => t.charCodeAt(0));
|
|
704
|
+
}
|
|
705
|
+
const Fe = 8192;
|
|
706
|
+
function Ie(e) {
|
|
707
|
+
if (e.length < Fe)
|
|
708
|
+
return btoa(String.fromCharCode(...e));
|
|
709
|
+
let t = "";
|
|
710
|
+
for (var r = 0; r < e.length; r += Fe) {
|
|
711
|
+
const n = e.slice(r, r + Fe);
|
|
712
|
+
t += String.fromCharCode(...n);
|
|
713
|
+
}
|
|
714
|
+
return btoa(t);
|
|
715
|
+
}
|
|
716
|
+
function Ve(e) {
|
|
717
|
+
var i;
|
|
718
|
+
const t = e.startsWith("0x") ? e.slice(2) : e, n = ((i = (t.length % 2 === 0 ? t : `0${t}}`).match(/.{2}/g)) == null ? void 0 : i.map((s) => parseInt(s, 16))) ?? [];
|
|
719
|
+
return Uint8Array.from(n);
|
|
720
|
+
}
|
|
721
|
+
function je(e) {
|
|
722
|
+
return e.reduce((t, r) => t + r.toString(16).padStart(2, "0"), "");
|
|
723
|
+
}
|
|
724
|
+
function ct(e) {
|
|
725
|
+
let t = [], r = 0;
|
|
726
|
+
if (e === 0)
|
|
727
|
+
return [0];
|
|
728
|
+
for (; e > 0; )
|
|
729
|
+
t[r] = e & 127, (e >>= 7) && (t[r] |= 128), r += 1;
|
|
730
|
+
return t;
|
|
731
|
+
}
|
|
732
|
+
function pn(e) {
|
|
733
|
+
let t = 0, r = 0, n = 0;
|
|
734
|
+
for (; ; ) {
|
|
735
|
+
let i = e[n];
|
|
736
|
+
if (n += 1, t |= (i & 127) << r, !(i & 128))
|
|
737
|
+
break;
|
|
738
|
+
r += 7;
|
|
739
|
+
}
|
|
740
|
+
return {
|
|
741
|
+
value: t,
|
|
742
|
+
length: n
|
|
743
|
+
};
|
|
744
|
+
}
|
|
745
|
+
class tr {
|
|
746
|
+
/**
|
|
747
|
+
* @param {Uint8Array} data Data to use as a buffer.
|
|
748
|
+
*/
|
|
749
|
+
constructor(t) {
|
|
750
|
+
this.bytePosition = 0, this.dataView = new DataView(t.buffer);
|
|
751
|
+
}
|
|
752
|
+
/**
|
|
753
|
+
* Shift current cursor position by `bytes`.
|
|
754
|
+
*
|
|
755
|
+
* @param {Number} bytes Number of bytes to
|
|
756
|
+
* @returns {this} Self for possible chaining.
|
|
757
|
+
*/
|
|
758
|
+
shift(t) {
|
|
759
|
+
return this.bytePosition += t, this;
|
|
760
|
+
}
|
|
761
|
+
/**
|
|
762
|
+
* Read U8 value from the buffer and shift cursor by 1.
|
|
763
|
+
* @returns
|
|
764
|
+
*/
|
|
765
|
+
read8() {
|
|
766
|
+
let t = this.dataView.getUint8(this.bytePosition);
|
|
767
|
+
return this.shift(1), t;
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* Read U16 value from the buffer and shift cursor by 2.
|
|
771
|
+
* @returns
|
|
772
|
+
*/
|
|
773
|
+
read16() {
|
|
774
|
+
let t = this.dataView.getUint16(this.bytePosition, !0);
|
|
775
|
+
return this.shift(2), t;
|
|
776
|
+
}
|
|
777
|
+
/**
|
|
778
|
+
* Read U32 value from the buffer and shift cursor by 4.
|
|
779
|
+
* @returns
|
|
780
|
+
*/
|
|
781
|
+
read32() {
|
|
782
|
+
let t = this.dataView.getUint32(this.bytePosition, !0);
|
|
783
|
+
return this.shift(4), t;
|
|
784
|
+
}
|
|
785
|
+
/**
|
|
786
|
+
* Read U64 value from the buffer and shift cursor by 8.
|
|
787
|
+
* @returns
|
|
788
|
+
*/
|
|
789
|
+
read64() {
|
|
790
|
+
let t = this.read32(), n = this.read32().toString(16) + t.toString(16).padStart(8, "0");
|
|
791
|
+
return BigInt("0x" + n).toString(10);
|
|
792
|
+
}
|
|
793
|
+
/**
|
|
794
|
+
* Read U128 value from the buffer and shift cursor by 16.
|
|
795
|
+
*/
|
|
796
|
+
read128() {
|
|
797
|
+
let t = BigInt(this.read64()), n = BigInt(this.read64()).toString(16) + t.toString(16).padStart(16, "0");
|
|
798
|
+
return BigInt("0x" + n).toString(10);
|
|
799
|
+
}
|
|
800
|
+
/**
|
|
801
|
+
* Read U128 value from the buffer and shift cursor by 32.
|
|
802
|
+
* @returns
|
|
803
|
+
*/
|
|
804
|
+
read256() {
|
|
805
|
+
let t = BigInt(this.read128()), n = BigInt(this.read128()).toString(16) + t.toString(16).padStart(32, "0");
|
|
806
|
+
return BigInt("0x" + n).toString(10);
|
|
807
|
+
}
|
|
808
|
+
/**
|
|
809
|
+
* Read `num` number of bytes from the buffer and shift cursor by `num`.
|
|
810
|
+
* @param num Number of bytes to read.
|
|
811
|
+
*/
|
|
812
|
+
readBytes(t) {
|
|
813
|
+
let r = this.bytePosition + this.dataView.byteOffset, n = new Uint8Array(this.dataView.buffer, r, t);
|
|
814
|
+
return this.shift(t), n;
|
|
815
|
+
}
|
|
816
|
+
/**
|
|
817
|
+
* Read ULEB value - an integer of varying size. Used for enum indexes and
|
|
818
|
+
* vector lengths.
|
|
819
|
+
* @returns {Number} The ULEB value.
|
|
820
|
+
*/
|
|
821
|
+
readULEB() {
|
|
822
|
+
let t = this.bytePosition + this.dataView.byteOffset, r = new Uint8Array(this.dataView.buffer, t), { value: n, length: i } = pn(r);
|
|
823
|
+
return this.shift(i), n;
|
|
824
|
+
}
|
|
825
|
+
/**
|
|
826
|
+
* Read a BCS vector: read a length and then apply function `cb` X times
|
|
827
|
+
* where X is the length of the vector, defined as ULEB in BCS bytes.
|
|
828
|
+
* @param cb Callback to process elements of vector.
|
|
829
|
+
* @returns {Array<Any>} Array of the resulting values, returned by callback.
|
|
830
|
+
*/
|
|
831
|
+
readVec(t) {
|
|
832
|
+
let r = this.readULEB(), n = [];
|
|
833
|
+
for (let i = 0; i < r; i++)
|
|
834
|
+
n.push(t(this, i, r));
|
|
835
|
+
return n;
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
function mn(e, t) {
|
|
839
|
+
switch (t) {
|
|
840
|
+
case "base58":
|
|
841
|
+
return xe(e);
|
|
842
|
+
case "base64":
|
|
843
|
+
return Ie(e);
|
|
844
|
+
case "hex":
|
|
845
|
+
return je(e);
|
|
846
|
+
default:
|
|
847
|
+
throw new Error("Unsupported encoding, supported values are: base64, hex");
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
function yn(e, t) {
|
|
851
|
+
switch (t) {
|
|
852
|
+
case "base58":
|
|
853
|
+
return ot(e);
|
|
854
|
+
case "base64":
|
|
855
|
+
return ae(e);
|
|
856
|
+
case "hex":
|
|
857
|
+
return Ve(e);
|
|
858
|
+
default:
|
|
859
|
+
throw new Error("Unsupported encoding, supported values are: base64, hex");
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
function rr(e, t = ["<", ">"]) {
|
|
863
|
+
const [r, n] = t, i = [];
|
|
864
|
+
let s = "", a = 0;
|
|
865
|
+
for (let o = 0; o < e.length; o++) {
|
|
866
|
+
const u = e[o];
|
|
867
|
+
if (u === r && a++, u === n && a--, a === 0 && u === ",") {
|
|
868
|
+
i.push(s.trim()), s = "";
|
|
869
|
+
continue;
|
|
870
|
+
}
|
|
871
|
+
s += u;
|
|
872
|
+
}
|
|
873
|
+
return i.push(s.trim()), i;
|
|
874
|
+
}
|
|
875
|
+
class nr {
|
|
876
|
+
constructor({ size: t = 1024, maxSize: r, allocateSize: n = 1024 } = {}) {
|
|
877
|
+
this.bytePosition = 0, this.size = t, this.maxSize = r || t, this.allocateSize = n, this.dataView = new DataView(new ArrayBuffer(t));
|
|
878
|
+
}
|
|
879
|
+
ensureSizeOrGrow(t) {
|
|
880
|
+
const r = this.bytePosition + t;
|
|
881
|
+
if (r > this.size) {
|
|
882
|
+
const n = Math.min(this.maxSize, this.size + this.allocateSize);
|
|
883
|
+
if (r > n)
|
|
884
|
+
throw new Error(
|
|
885
|
+
`Attempting to serialize to BCS, but buffer does not have enough size. Allocated size: ${this.size}, Max size: ${this.maxSize}, Required size: ${r}`
|
|
886
|
+
);
|
|
887
|
+
this.size = n;
|
|
888
|
+
const i = new ArrayBuffer(this.size);
|
|
889
|
+
new Uint8Array(i).set(new Uint8Array(this.dataView.buffer)), this.dataView = new DataView(i);
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
/**
|
|
893
|
+
* Shift current cursor position by `bytes`.
|
|
894
|
+
*
|
|
895
|
+
* @param {Number} bytes Number of bytes to
|
|
896
|
+
* @returns {this} Self for possible chaining.
|
|
897
|
+
*/
|
|
898
|
+
shift(t) {
|
|
899
|
+
return this.bytePosition += t, this;
|
|
900
|
+
}
|
|
901
|
+
/**
|
|
902
|
+
* Write a U8 value into a buffer and shift cursor position by 1.
|
|
903
|
+
* @param {Number} value Value to write.
|
|
904
|
+
* @returns {this}
|
|
905
|
+
*/
|
|
906
|
+
write8(t) {
|
|
907
|
+
return this.ensureSizeOrGrow(1), this.dataView.setUint8(this.bytePosition, Number(t)), this.shift(1);
|
|
908
|
+
}
|
|
909
|
+
/**
|
|
910
|
+
* Write a U16 value into a buffer and shift cursor position by 2.
|
|
911
|
+
* @param {Number} value Value to write.
|
|
912
|
+
* @returns {this}
|
|
913
|
+
*/
|
|
914
|
+
write16(t) {
|
|
915
|
+
return this.ensureSizeOrGrow(2), this.dataView.setUint16(this.bytePosition, Number(t), !0), this.shift(2);
|
|
916
|
+
}
|
|
917
|
+
/**
|
|
918
|
+
* Write a U32 value into a buffer and shift cursor position by 4.
|
|
919
|
+
* @param {Number} value Value to write.
|
|
920
|
+
* @returns {this}
|
|
921
|
+
*/
|
|
922
|
+
write32(t) {
|
|
923
|
+
return this.ensureSizeOrGrow(4), this.dataView.setUint32(this.bytePosition, Number(t), !0), this.shift(4);
|
|
924
|
+
}
|
|
925
|
+
/**
|
|
926
|
+
* Write a U64 value into a buffer and shift cursor position by 8.
|
|
927
|
+
* @param {bigint} value Value to write.
|
|
928
|
+
* @returns {this}
|
|
929
|
+
*/
|
|
930
|
+
write64(t) {
|
|
931
|
+
return Le(BigInt(t), 8).forEach((r) => this.write8(r)), this;
|
|
932
|
+
}
|
|
933
|
+
/**
|
|
934
|
+
* Write a U128 value into a buffer and shift cursor position by 16.
|
|
935
|
+
*
|
|
936
|
+
* @param {bigint} value Value to write.
|
|
937
|
+
* @returns {this}
|
|
938
|
+
*/
|
|
939
|
+
write128(t) {
|
|
940
|
+
return Le(BigInt(t), 16).forEach((r) => this.write8(r)), this;
|
|
941
|
+
}
|
|
942
|
+
/**
|
|
943
|
+
* Write a U256 value into a buffer and shift cursor position by 16.
|
|
944
|
+
*
|
|
945
|
+
* @param {bigint} value Value to write.
|
|
946
|
+
* @returns {this}
|
|
947
|
+
*/
|
|
948
|
+
write256(t) {
|
|
949
|
+
return Le(BigInt(t), 32).forEach((r) => this.write8(r)), this;
|
|
950
|
+
}
|
|
951
|
+
/**
|
|
952
|
+
* Write a ULEB value into a buffer and shift cursor position by number of bytes
|
|
953
|
+
* written.
|
|
954
|
+
* @param {Number} value Value to write.
|
|
955
|
+
* @returns {this}
|
|
956
|
+
*/
|
|
957
|
+
writeULEB(t) {
|
|
958
|
+
return ct(t).forEach((r) => this.write8(r)), this;
|
|
959
|
+
}
|
|
960
|
+
/**
|
|
961
|
+
* Write a vector into a buffer by first writing the vector length and then calling
|
|
962
|
+
* a callback on each passed value.
|
|
963
|
+
*
|
|
964
|
+
* @param {Array<Any>} vector Array of elements to write.
|
|
965
|
+
* @param {WriteVecCb} cb Callback to call on each element of the vector.
|
|
966
|
+
* @returns {this}
|
|
967
|
+
*/
|
|
968
|
+
writeVec(t, r) {
|
|
969
|
+
return this.writeULEB(t.length), Array.from(t).forEach((n, i) => r(this, n, i, t.length)), this;
|
|
970
|
+
}
|
|
971
|
+
/**
|
|
972
|
+
* Adds support for iterations over the object.
|
|
973
|
+
* @returns {Uint8Array}
|
|
974
|
+
*/
|
|
975
|
+
*[Symbol.iterator]() {
|
|
976
|
+
for (let t = 0; t < this.bytePosition; t++)
|
|
977
|
+
yield this.dataView.getUint8(t);
|
|
978
|
+
return this.toBytes();
|
|
979
|
+
}
|
|
980
|
+
/**
|
|
981
|
+
* Get underlying buffer taking only value bytes (in case initial buffer size was bigger).
|
|
982
|
+
* @returns {Uint8Array} Resulting bcs.
|
|
983
|
+
*/
|
|
984
|
+
toBytes() {
|
|
985
|
+
return new Uint8Array(this.dataView.buffer.slice(0, this.bytePosition));
|
|
986
|
+
}
|
|
987
|
+
/**
|
|
988
|
+
* Represent data as 'hex' or 'base64'
|
|
989
|
+
* @param encoding Encoding to use: 'base64' or 'hex'
|
|
990
|
+
*/
|
|
991
|
+
toString(t) {
|
|
992
|
+
return mn(this.toBytes(), t);
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
function Le(e, t) {
|
|
996
|
+
let r = new Uint8Array(t), n = 0;
|
|
997
|
+
for (; e > 0; )
|
|
998
|
+
r[n] = Number(e % BigInt(256)), e = e / BigInt(256), n += 1;
|
|
999
|
+
return r;
|
|
1000
|
+
}
|
|
1001
|
+
var ir = (e, t, r) => {
|
|
1002
|
+
if (!t.has(e))
|
|
1003
|
+
throw TypeError("Cannot " + r);
|
|
1004
|
+
}, K = (e, t, r) => (ir(e, t, "read from private field"), r ? r.call(e) : t.get(e)), Be = (e, t, r) => {
|
|
1005
|
+
if (t.has(e))
|
|
1006
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
1007
|
+
t instanceof WeakSet ? t.add(e) : t.set(e, r);
|
|
1008
|
+
}, Re = (e, t, r, n) => (ir(e, t, "write to private field"), t.set(e, r), r), fe, ge, Ce, ie;
|
|
1009
|
+
const sr = class {
|
|
1010
|
+
constructor(e) {
|
|
1011
|
+
Be(this, fe, void 0), Be(this, ge, void 0), this.name = e.name, this.read = e.read, this.serializedSize = e.serializedSize ?? (() => null), Re(this, fe, e.write), Re(this, ge, e.serialize ?? ((t, r) => {
|
|
1012
|
+
const n = new nr({ size: this.serializedSize(t) ?? void 0, ...r });
|
|
1013
|
+
return K(this, fe).call(this, t, n), n.toBytes();
|
|
1014
|
+
})), this.validate = e.validate ?? (() => {
|
|
1015
|
+
});
|
|
1016
|
+
}
|
|
1017
|
+
write(e, t) {
|
|
1018
|
+
this.validate(e), K(this, fe).call(this, e, t);
|
|
1019
|
+
}
|
|
1020
|
+
serialize(e, t) {
|
|
1021
|
+
return this.validate(e), new wn(this, K(this, ge).call(this, e, t));
|
|
1022
|
+
}
|
|
1023
|
+
parse(e) {
|
|
1024
|
+
const t = new tr(e);
|
|
1025
|
+
return this.read(t);
|
|
1026
|
+
}
|
|
1027
|
+
transform({
|
|
1028
|
+
name: e,
|
|
1029
|
+
input: t,
|
|
1030
|
+
output: r
|
|
1031
|
+
}) {
|
|
1032
|
+
return new sr({
|
|
1033
|
+
name: e ?? this.name,
|
|
1034
|
+
read: (n) => r(this.read(n)),
|
|
1035
|
+
write: (n, i) => K(this, fe).call(this, t(n), i),
|
|
1036
|
+
serializedSize: (n) => this.serializedSize(t(n)),
|
|
1037
|
+
serialize: (n, i) => K(this, ge).call(this, t(n), i),
|
|
1038
|
+
validate: (n) => this.validate(t(n))
|
|
1039
|
+
});
|
|
1040
|
+
}
|
|
1041
|
+
};
|
|
1042
|
+
let W = sr;
|
|
1043
|
+
fe = /* @__PURE__ */ new WeakMap();
|
|
1044
|
+
ge = /* @__PURE__ */ new WeakMap();
|
|
1045
|
+
const ar = Symbol.for("@mysten/serialized-bcs");
|
|
1046
|
+
function ut(e) {
|
|
1047
|
+
return !!e && typeof e == "object" && e[ar] === !0;
|
|
1048
|
+
}
|
|
1049
|
+
class wn {
|
|
1050
|
+
constructor(t, r) {
|
|
1051
|
+
Be(this, Ce, void 0), Be(this, ie, void 0), Re(this, Ce, t), Re(this, ie, r);
|
|
1052
|
+
}
|
|
1053
|
+
// Used to brand SerializedBcs so that they can be identified, even between multiple copies
|
|
1054
|
+
// of the @mysten/bcs package are installed
|
|
1055
|
+
get [ar]() {
|
|
1056
|
+
return !0;
|
|
1057
|
+
}
|
|
1058
|
+
toBytes() {
|
|
1059
|
+
return K(this, ie);
|
|
1060
|
+
}
|
|
1061
|
+
toHex() {
|
|
1062
|
+
return je(K(this, ie));
|
|
1063
|
+
}
|
|
1064
|
+
toBase64() {
|
|
1065
|
+
return Ie(K(this, ie));
|
|
1066
|
+
}
|
|
1067
|
+
toBase58() {
|
|
1068
|
+
return xe(K(this, ie));
|
|
1069
|
+
}
|
|
1070
|
+
parse() {
|
|
1071
|
+
return K(this, Ce).parse(K(this, ie));
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
Ce = /* @__PURE__ */ new WeakMap();
|
|
1075
|
+
ie = /* @__PURE__ */ new WeakMap();
|
|
1076
|
+
function Ne({
|
|
1077
|
+
size: e,
|
|
1078
|
+
...t
|
|
1079
|
+
}) {
|
|
1080
|
+
return new W({
|
|
1081
|
+
...t,
|
|
1082
|
+
serializedSize: () => e
|
|
1083
|
+
});
|
|
1084
|
+
}
|
|
1085
|
+
function Ke({
|
|
1086
|
+
readMethod: e,
|
|
1087
|
+
writeMethod: t,
|
|
1088
|
+
...r
|
|
1089
|
+
}) {
|
|
1090
|
+
return Ne({
|
|
1091
|
+
...r,
|
|
1092
|
+
read: (n) => n[e](),
|
|
1093
|
+
write: (n, i) => i[t](n),
|
|
1094
|
+
validate: (n) => {
|
|
1095
|
+
var i;
|
|
1096
|
+
if (n < 0 || n > r.maxValue)
|
|
1097
|
+
throw new TypeError(
|
|
1098
|
+
`Invalid ${r.name} value: ${n}. Expected value in range 0-${r.maxValue}`
|
|
1099
|
+
);
|
|
1100
|
+
(i = r.validate) == null || i.call(r, n);
|
|
1101
|
+
}
|
|
1102
|
+
});
|
|
1103
|
+
}
|
|
1104
|
+
function We({
|
|
1105
|
+
readMethod: e,
|
|
1106
|
+
writeMethod: t,
|
|
1107
|
+
...r
|
|
1108
|
+
}) {
|
|
1109
|
+
return Ne({
|
|
1110
|
+
...r,
|
|
1111
|
+
read: (n) => n[e](),
|
|
1112
|
+
write: (n, i) => i[t](BigInt(n)),
|
|
1113
|
+
validate: (n) => {
|
|
1114
|
+
var s;
|
|
1115
|
+
const i = BigInt(n);
|
|
1116
|
+
if (i < 0 || i > r.maxValue)
|
|
1117
|
+
throw new TypeError(
|
|
1118
|
+
`Invalid ${r.name} value: ${i}. Expected value in range 0-${r.maxValue}`
|
|
1119
|
+
);
|
|
1120
|
+
(s = r.validate) == null || s.call(r, i);
|
|
1121
|
+
}
|
|
1122
|
+
});
|
|
1123
|
+
}
|
|
1124
|
+
function bn({
|
|
1125
|
+
serialize: e,
|
|
1126
|
+
...t
|
|
1127
|
+
}) {
|
|
1128
|
+
const r = new W({
|
|
1129
|
+
...t,
|
|
1130
|
+
serialize: e,
|
|
1131
|
+
write: (n, i) => {
|
|
1132
|
+
for (const s of r.serialize(n).toBytes())
|
|
1133
|
+
i.write8(s);
|
|
1134
|
+
}
|
|
1135
|
+
});
|
|
1136
|
+
return r;
|
|
1137
|
+
}
|
|
1138
|
+
function Sn({
|
|
1139
|
+
toBytes: e,
|
|
1140
|
+
fromBytes: t,
|
|
1141
|
+
...r
|
|
1142
|
+
}) {
|
|
1143
|
+
return new W({
|
|
1144
|
+
...r,
|
|
1145
|
+
read: (n) => {
|
|
1146
|
+
const i = n.readULEB(), s = n.readBytes(i);
|
|
1147
|
+
return t(s);
|
|
1148
|
+
},
|
|
1149
|
+
write: (n, i) => {
|
|
1150
|
+
const s = e(n);
|
|
1151
|
+
i.writeULEB(s.length);
|
|
1152
|
+
for (let a = 0; a < s.length; a++)
|
|
1153
|
+
i.write8(s[a]);
|
|
1154
|
+
},
|
|
1155
|
+
serialize: (n) => {
|
|
1156
|
+
const i = e(n), s = ct(i.length), a = new Uint8Array(s.length + i.length);
|
|
1157
|
+
return a.set(s, 0), a.set(i, s.length), a;
|
|
1158
|
+
},
|
|
1159
|
+
validate: (n) => {
|
|
1160
|
+
var i;
|
|
1161
|
+
if (typeof n != "string")
|
|
1162
|
+
throw new TypeError(`Invalid ${r.name} value: ${n}. Expected string`);
|
|
1163
|
+
(i = r.validate) == null || i.call(r, n);
|
|
1164
|
+
}
|
|
1165
|
+
});
|
|
1166
|
+
}
|
|
1167
|
+
function Tn(e) {
|
|
1168
|
+
let t = null;
|
|
1169
|
+
function r() {
|
|
1170
|
+
return t || (t = e()), t;
|
|
1171
|
+
}
|
|
1172
|
+
return new W({
|
|
1173
|
+
name: "lazy",
|
|
1174
|
+
read: (n) => r().read(n),
|
|
1175
|
+
serializedSize: (n) => r().serializedSize(n),
|
|
1176
|
+
write: (n, i) => r().write(n, i),
|
|
1177
|
+
serialize: (n, i) => r().serialize(n, i).toBytes()
|
|
1178
|
+
});
|
|
1179
|
+
}
|
|
1180
|
+
const c = {
|
|
1181
|
+
/**
|
|
1182
|
+
* Creates a BcsType that can be used to read and write an 8-bit unsigned integer.
|
|
1183
|
+
* @example
|
|
1184
|
+
* bcs.u8().serialize(255).toBytes() // Uint8Array [ 255 ]
|
|
1185
|
+
*/
|
|
1186
|
+
u8(e) {
|
|
1187
|
+
return Ke({
|
|
1188
|
+
name: "u8",
|
|
1189
|
+
readMethod: "read8",
|
|
1190
|
+
writeMethod: "write8",
|
|
1191
|
+
size: 1,
|
|
1192
|
+
maxValue: 2 ** 8 - 1,
|
|
1193
|
+
...e
|
|
1194
|
+
});
|
|
1195
|
+
},
|
|
1196
|
+
/**
|
|
1197
|
+
* Creates a BcsType that can be used to read and write a 16-bit unsigned integer.
|
|
1198
|
+
* @example
|
|
1199
|
+
* bcs.u16().serialize(65535).toBytes() // Uint8Array [ 255, 255 ]
|
|
1200
|
+
*/
|
|
1201
|
+
u16(e) {
|
|
1202
|
+
return Ke({
|
|
1203
|
+
name: "u16",
|
|
1204
|
+
readMethod: "read16",
|
|
1205
|
+
writeMethod: "write16",
|
|
1206
|
+
size: 2,
|
|
1207
|
+
maxValue: 2 ** 16 - 1,
|
|
1208
|
+
...e
|
|
1209
|
+
});
|
|
1210
|
+
},
|
|
1211
|
+
/**
|
|
1212
|
+
* Creates a BcsType that can be used to read and write a 32-bit unsigned integer.
|
|
1213
|
+
* @example
|
|
1214
|
+
* bcs.u32().serialize(4294967295).toBytes() // Uint8Array [ 255, 255, 255, 255 ]
|
|
1215
|
+
*/
|
|
1216
|
+
u32(e) {
|
|
1217
|
+
return Ke({
|
|
1218
|
+
name: "u32",
|
|
1219
|
+
readMethod: "read32",
|
|
1220
|
+
writeMethod: "write32",
|
|
1221
|
+
size: 4,
|
|
1222
|
+
maxValue: 2 ** 32 - 1,
|
|
1223
|
+
...e
|
|
1224
|
+
});
|
|
1225
|
+
},
|
|
1226
|
+
/**
|
|
1227
|
+
* Creates a BcsType that can be used to read and write a 64-bit unsigned integer.
|
|
1228
|
+
* @example
|
|
1229
|
+
* bcs.u64().serialize(1).toBytes() // Uint8Array [ 1, 0, 0, 0, 0, 0, 0, 0 ]
|
|
1230
|
+
*/
|
|
1231
|
+
u64(e) {
|
|
1232
|
+
return We({
|
|
1233
|
+
name: "u64",
|
|
1234
|
+
readMethod: "read64",
|
|
1235
|
+
writeMethod: "write64",
|
|
1236
|
+
size: 8,
|
|
1237
|
+
maxValue: 2n ** 64n - 1n,
|
|
1238
|
+
...e
|
|
1239
|
+
});
|
|
1240
|
+
},
|
|
1241
|
+
/**
|
|
1242
|
+
* Creates a BcsType that can be used to read and write a 128-bit unsigned integer.
|
|
1243
|
+
* @example
|
|
1244
|
+
* bcs.u128().serialize(1).toBytes() // Uint8Array [ 1, ..., 0 ]
|
|
1245
|
+
*/
|
|
1246
|
+
u128(e) {
|
|
1247
|
+
return We({
|
|
1248
|
+
name: "u128",
|
|
1249
|
+
readMethod: "read128",
|
|
1250
|
+
writeMethod: "write128",
|
|
1251
|
+
size: 16,
|
|
1252
|
+
maxValue: 2n ** 128n - 1n,
|
|
1253
|
+
...e
|
|
1254
|
+
});
|
|
1255
|
+
},
|
|
1256
|
+
/**
|
|
1257
|
+
* Creates a BcsType that can be used to read and write a 256-bit unsigned integer.
|
|
1258
|
+
* @example
|
|
1259
|
+
* bcs.u256().serialize(1).toBytes() // Uint8Array [ 1, ..., 0 ]
|
|
1260
|
+
*/
|
|
1261
|
+
u256(e) {
|
|
1262
|
+
return We({
|
|
1263
|
+
name: "u256",
|
|
1264
|
+
readMethod: "read256",
|
|
1265
|
+
writeMethod: "write256",
|
|
1266
|
+
size: 32,
|
|
1267
|
+
maxValue: 2n ** 256n - 1n,
|
|
1268
|
+
...e
|
|
1269
|
+
});
|
|
1270
|
+
},
|
|
1271
|
+
/**
|
|
1272
|
+
* Creates a BcsType that can be used to read and write boolean values.
|
|
1273
|
+
* @example
|
|
1274
|
+
* bcs.bool().serialize(true).toBytes() // Uint8Array [ 1 ]
|
|
1275
|
+
*/
|
|
1276
|
+
bool(e) {
|
|
1277
|
+
return Ne({
|
|
1278
|
+
name: "bool",
|
|
1279
|
+
size: 1,
|
|
1280
|
+
read: (t) => t.read8() === 1,
|
|
1281
|
+
write: (t, r) => r.write8(t ? 1 : 0),
|
|
1282
|
+
...e,
|
|
1283
|
+
validate: (t) => {
|
|
1284
|
+
var r;
|
|
1285
|
+
if ((r = e == null ? void 0 : e.validate) == null || r.call(e, t), typeof t != "boolean")
|
|
1286
|
+
throw new TypeError(`Expected boolean, found ${typeof t}`);
|
|
1287
|
+
}
|
|
1288
|
+
});
|
|
1289
|
+
},
|
|
1290
|
+
/**
|
|
1291
|
+
* Creates a BcsType that can be used to read and write unsigned LEB encoded integers
|
|
1292
|
+
* @example
|
|
1293
|
+
*
|
|
1294
|
+
*/
|
|
1295
|
+
uleb128(e) {
|
|
1296
|
+
return bn({
|
|
1297
|
+
name: "uleb128",
|
|
1298
|
+
read: (t) => t.readULEB(),
|
|
1299
|
+
serialize: (t) => Uint8Array.from(ct(t)),
|
|
1300
|
+
...e
|
|
1301
|
+
});
|
|
1302
|
+
},
|
|
1303
|
+
/**
|
|
1304
|
+
* Creates a BcsType representing a fixed length byte array
|
|
1305
|
+
* @param size The number of bytes this types represents
|
|
1306
|
+
* @example
|
|
1307
|
+
* bcs.bytes(3).serialize(new Uint8Array([1, 2, 3])).toBytes() // Uint8Array [1, 2, 3]
|
|
1308
|
+
*/
|
|
1309
|
+
bytes(e, t) {
|
|
1310
|
+
return Ne({
|
|
1311
|
+
name: `bytes[${e}]`,
|
|
1312
|
+
size: e,
|
|
1313
|
+
read: (r) => r.readBytes(e),
|
|
1314
|
+
write: (r, n) => {
|
|
1315
|
+
for (let i = 0; i < e; i++)
|
|
1316
|
+
n.write8(r[i] ?? 0);
|
|
1317
|
+
},
|
|
1318
|
+
...t,
|
|
1319
|
+
validate: (r) => {
|
|
1320
|
+
var n;
|
|
1321
|
+
if ((n = t == null ? void 0 : t.validate) == null || n.call(t, r), !("length" in r))
|
|
1322
|
+
throw new TypeError(`Expected array, found ${typeof r}`);
|
|
1323
|
+
if (r.length !== e)
|
|
1324
|
+
throw new TypeError(`Expected array of length ${e}, found ${r.length}`);
|
|
1325
|
+
}
|
|
1326
|
+
});
|
|
1327
|
+
},
|
|
1328
|
+
/**
|
|
1329
|
+
* Creates a BcsType that can ser/de string values. Strings will be UTF-8 encoded
|
|
1330
|
+
* @example
|
|
1331
|
+
* bcs.string().serialize('a').toBytes() // Uint8Array [ 1, 97 ]
|
|
1332
|
+
*/
|
|
1333
|
+
string(e) {
|
|
1334
|
+
return Sn({
|
|
1335
|
+
name: "string",
|
|
1336
|
+
toBytes: (t) => new TextEncoder().encode(t),
|
|
1337
|
+
fromBytes: (t) => new TextDecoder().decode(t),
|
|
1338
|
+
...e
|
|
1339
|
+
});
|
|
1340
|
+
},
|
|
1341
|
+
/**
|
|
1342
|
+
* Creates a BcsType that represents a fixed length array of a given type
|
|
1343
|
+
* @param size The number of elements in the array
|
|
1344
|
+
* @param type The BcsType of each element in the array
|
|
1345
|
+
* @example
|
|
1346
|
+
* bcs.fixedArray(3, bcs.u8()).serialize([1, 2, 3]).toBytes() // Uint8Array [ 1, 2, 3 ]
|
|
1347
|
+
*/
|
|
1348
|
+
fixedArray(e, t, r) {
|
|
1349
|
+
return new W({
|
|
1350
|
+
name: `${t.name}[${e}]`,
|
|
1351
|
+
read: (n) => {
|
|
1352
|
+
const i = new Array(e);
|
|
1353
|
+
for (let s = 0; s < e; s++)
|
|
1354
|
+
i[s] = t.read(n);
|
|
1355
|
+
return i;
|
|
1356
|
+
},
|
|
1357
|
+
write: (n, i) => {
|
|
1358
|
+
for (const s of n)
|
|
1359
|
+
t.write(s, i);
|
|
1360
|
+
},
|
|
1361
|
+
...r,
|
|
1362
|
+
validate: (n) => {
|
|
1363
|
+
var i;
|
|
1364
|
+
if ((i = r == null ? void 0 : r.validate) == null || i.call(r, n), !("length" in n))
|
|
1365
|
+
throw new TypeError(`Expected array, found ${typeof n}`);
|
|
1366
|
+
if (n.length !== e)
|
|
1367
|
+
throw new TypeError(`Expected array of length ${e}, found ${n.length}`);
|
|
1368
|
+
}
|
|
1369
|
+
});
|
|
1370
|
+
},
|
|
1371
|
+
/**
|
|
1372
|
+
* Creates a BcsType representing an optional value
|
|
1373
|
+
* @param type The BcsType of the optional value
|
|
1374
|
+
* @example
|
|
1375
|
+
* bcs.option(bcs.u8()).serialize(null).toBytes() // Uint8Array [ 0 ]
|
|
1376
|
+
* bcs.option(bcs.u8()).serialize(1).toBytes() // Uint8Array [ 1, 1 ]
|
|
1377
|
+
*/
|
|
1378
|
+
option(e) {
|
|
1379
|
+
return c.enum(`Option<${e.name}>`, {
|
|
1380
|
+
None: null,
|
|
1381
|
+
Some: e
|
|
1382
|
+
}).transform({
|
|
1383
|
+
input: (t) => t == null ? { None: !0 } : { Some: t },
|
|
1384
|
+
output: (t) => "Some" in t ? t.Some : null
|
|
1385
|
+
});
|
|
1386
|
+
},
|
|
1387
|
+
/**
|
|
1388
|
+
* Creates a BcsType representing a variable length vector of a given type
|
|
1389
|
+
* @param type The BcsType of each element in the vector
|
|
1390
|
+
*
|
|
1391
|
+
* @example
|
|
1392
|
+
* bcs.vector(bcs.u8()).toBytes([1, 2, 3]) // Uint8Array [ 3, 1, 2, 3 ]
|
|
1393
|
+
*/
|
|
1394
|
+
vector(e, t) {
|
|
1395
|
+
return new W({
|
|
1396
|
+
name: `vector<${e.name}>`,
|
|
1397
|
+
read: (r) => {
|
|
1398
|
+
const n = r.readULEB(), i = new Array(n);
|
|
1399
|
+
for (let s = 0; s < n; s++)
|
|
1400
|
+
i[s] = e.read(r);
|
|
1401
|
+
return i;
|
|
1402
|
+
},
|
|
1403
|
+
write: (r, n) => {
|
|
1404
|
+
n.writeULEB(r.length);
|
|
1405
|
+
for (const i of r)
|
|
1406
|
+
e.write(i, n);
|
|
1407
|
+
},
|
|
1408
|
+
...t,
|
|
1409
|
+
validate: (r) => {
|
|
1410
|
+
var n;
|
|
1411
|
+
if ((n = t == null ? void 0 : t.validate) == null || n.call(t, r), !("length" in r))
|
|
1412
|
+
throw new TypeError(`Expected array, found ${typeof r}`);
|
|
1413
|
+
}
|
|
1414
|
+
});
|
|
1415
|
+
},
|
|
1416
|
+
/**
|
|
1417
|
+
* Creates a BcsType representing a tuple of a given set of types
|
|
1418
|
+
* @param types The BcsTypes for each element in the tuple
|
|
1419
|
+
*
|
|
1420
|
+
* @example
|
|
1421
|
+
* const tuple = bcs.tuple([bcs.u8(), bcs.string(), bcs.bool()])
|
|
1422
|
+
* tuple.serialize([1, 'a', true]).toBytes() // Uint8Array [ 1, 1, 97, 1 ]
|
|
1423
|
+
*/
|
|
1424
|
+
tuple(e, t) {
|
|
1425
|
+
return new W({
|
|
1426
|
+
name: `(${e.map((r) => r.name).join(", ")})`,
|
|
1427
|
+
serializedSize: (r) => {
|
|
1428
|
+
let n = 0;
|
|
1429
|
+
for (let i = 0; i < e.length; i++) {
|
|
1430
|
+
const s = e[i].serializedSize(r[i]);
|
|
1431
|
+
if (s == null)
|
|
1432
|
+
return null;
|
|
1433
|
+
n += s;
|
|
1434
|
+
}
|
|
1435
|
+
return n;
|
|
1436
|
+
},
|
|
1437
|
+
read: (r) => {
|
|
1438
|
+
const n = [];
|
|
1439
|
+
for (const i of e)
|
|
1440
|
+
n.push(i.read(r));
|
|
1441
|
+
return n;
|
|
1442
|
+
},
|
|
1443
|
+
write: (r, n) => {
|
|
1444
|
+
for (let i = 0; i < e.length; i++)
|
|
1445
|
+
e[i].write(r[i], n);
|
|
1446
|
+
},
|
|
1447
|
+
...t,
|
|
1448
|
+
validate: (r) => {
|
|
1449
|
+
var n;
|
|
1450
|
+
if ((n = t == null ? void 0 : t.validate) == null || n.call(t, r), !Array.isArray(r))
|
|
1451
|
+
throw new TypeError(`Expected array, found ${typeof r}`);
|
|
1452
|
+
if (r.length !== e.length)
|
|
1453
|
+
throw new TypeError(`Expected array of length ${e.length}, found ${r.length}`);
|
|
1454
|
+
}
|
|
1455
|
+
});
|
|
1456
|
+
},
|
|
1457
|
+
/**
|
|
1458
|
+
* Creates a BcsType representing a struct of a given set of fields
|
|
1459
|
+
* @param name The name of the struct
|
|
1460
|
+
* @param fields The fields of the struct. The order of the fields affects how data is serialized and deserialized
|
|
1461
|
+
*
|
|
1462
|
+
* @example
|
|
1463
|
+
* const struct = bcs.struct('MyStruct', {
|
|
1464
|
+
* a: bcs.u8(),
|
|
1465
|
+
* b: bcs.string(),
|
|
1466
|
+
* })
|
|
1467
|
+
* struct.serialize({ a: 1, b: 'a' }).toBytes() // Uint8Array [ 1, 1, 97 ]
|
|
1468
|
+
*/
|
|
1469
|
+
struct(e, t, r) {
|
|
1470
|
+
const n = Object.entries(t);
|
|
1471
|
+
return new W({
|
|
1472
|
+
name: e,
|
|
1473
|
+
serializedSize: (i) => {
|
|
1474
|
+
let s = 0;
|
|
1475
|
+
for (const [a, o] of n) {
|
|
1476
|
+
const u = o.serializedSize(i[a]);
|
|
1477
|
+
if (u == null)
|
|
1478
|
+
return null;
|
|
1479
|
+
s += u;
|
|
1480
|
+
}
|
|
1481
|
+
return s;
|
|
1482
|
+
},
|
|
1483
|
+
read: (i) => {
|
|
1484
|
+
const s = {};
|
|
1485
|
+
for (const [a, o] of n)
|
|
1486
|
+
s[a] = o.read(i);
|
|
1487
|
+
return s;
|
|
1488
|
+
},
|
|
1489
|
+
write: (i, s) => {
|
|
1490
|
+
for (const [a, o] of n)
|
|
1491
|
+
o.write(i[a], s);
|
|
1492
|
+
},
|
|
1493
|
+
...r,
|
|
1494
|
+
validate: (i) => {
|
|
1495
|
+
var s;
|
|
1496
|
+
if ((s = r == null ? void 0 : r.validate) == null || s.call(r, i), typeof i != "object" || i == null)
|
|
1497
|
+
throw new TypeError(`Expected object, found ${typeof i}`);
|
|
1498
|
+
}
|
|
1499
|
+
});
|
|
1500
|
+
},
|
|
1501
|
+
/**
|
|
1502
|
+
* Creates a BcsType representing an enum of a given set of options
|
|
1503
|
+
* @param name The name of the enum
|
|
1504
|
+
* @param values The values of the enum. The order of the values affects how data is serialized and deserialized.
|
|
1505
|
+
* null can be used to represent a variant with no data.
|
|
1506
|
+
*
|
|
1507
|
+
* @example
|
|
1508
|
+
* const enum = bcs.enum('MyEnum', {
|
|
1509
|
+
* A: bcs.u8(),
|
|
1510
|
+
* B: bcs.string(),
|
|
1511
|
+
* C: null,
|
|
1512
|
+
* })
|
|
1513
|
+
* enum.serialize({ A: 1 }).toBytes() // Uint8Array [ 0, 1 ]
|
|
1514
|
+
* enum.serialize({ B: 'a' }).toBytes() // Uint8Array [ 1, 1, 97 ]
|
|
1515
|
+
* enum.serialize({ C: true }).toBytes() // Uint8Array [ 2 ]
|
|
1516
|
+
*/
|
|
1517
|
+
enum(e, t, r) {
|
|
1518
|
+
const n = Object.entries(t);
|
|
1519
|
+
return new W({
|
|
1520
|
+
name: e,
|
|
1521
|
+
read: (i) => {
|
|
1522
|
+
const s = i.readULEB(), [a, o] = n[s];
|
|
1523
|
+
return {
|
|
1524
|
+
[a]: (o == null ? void 0 : o.read(i)) ?? !0
|
|
1525
|
+
};
|
|
1526
|
+
},
|
|
1527
|
+
write: (i, s) => {
|
|
1528
|
+
const [a, o] = Object.entries(i)[0];
|
|
1529
|
+
for (let u = 0; u < n.length; u++) {
|
|
1530
|
+
const [d, l] = n[u];
|
|
1531
|
+
if (d === a) {
|
|
1532
|
+
s.writeULEB(u), l == null || l.write(o, s);
|
|
1533
|
+
return;
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
},
|
|
1537
|
+
...r,
|
|
1538
|
+
validate: (i) => {
|
|
1539
|
+
var o;
|
|
1540
|
+
if ((o = r == null ? void 0 : r.validate) == null || o.call(r, i), typeof i != "object" || i == null)
|
|
1541
|
+
throw new TypeError(`Expected object, found ${typeof i}`);
|
|
1542
|
+
const s = Object.keys(i);
|
|
1543
|
+
if (s.length !== 1)
|
|
1544
|
+
throw new TypeError(`Expected object with one key, found ${s.length}`);
|
|
1545
|
+
const [a] = s;
|
|
1546
|
+
if (!Object.hasOwn(t, a))
|
|
1547
|
+
throw new TypeError(`Invalid enum variant ${a}`);
|
|
1548
|
+
}
|
|
1549
|
+
});
|
|
1550
|
+
},
|
|
1551
|
+
/**
|
|
1552
|
+
* Creates a BcsType representing a map of a given key and value type
|
|
1553
|
+
* @param keyType The BcsType of the key
|
|
1554
|
+
* @param valueType The BcsType of the value
|
|
1555
|
+
* @example
|
|
1556
|
+
* const map = bcs.map(bcs.u8(), bcs.string())
|
|
1557
|
+
* map.serialize(new Map([[2, 'a']])).toBytes() // Uint8Array [ 1, 2, 1, 97 ]
|
|
1558
|
+
*/
|
|
1559
|
+
map(e, t) {
|
|
1560
|
+
return c.vector(c.tuple([e, t])).transform({
|
|
1561
|
+
name: `Map<${e.name}, ${t.name}>`,
|
|
1562
|
+
input: (r) => [...r.entries()],
|
|
1563
|
+
output: (r) => {
|
|
1564
|
+
const n = /* @__PURE__ */ new Map();
|
|
1565
|
+
for (const [i, s] of r)
|
|
1566
|
+
n.set(i, s);
|
|
1567
|
+
return n;
|
|
1568
|
+
}
|
|
1569
|
+
});
|
|
1570
|
+
},
|
|
1571
|
+
/**
|
|
1572
|
+
* @deprecated
|
|
1573
|
+
*
|
|
1574
|
+
* Generics should be implemented as generic typescript functions instead:
|
|
1575
|
+
*
|
|
1576
|
+
* ```ts
|
|
1577
|
+
* function VecMap<K, V>, (K: BcsType<K>, V: BcsType<V>) {
|
|
1578
|
+
* return bcs.struct('VecMap<K, V>', {
|
|
1579
|
+
* keys: bcs.vector(K),
|
|
1580
|
+
* values: bcs.vector(V),
|
|
1581
|
+
* })
|
|
1582
|
+
* }
|
|
1583
|
+
* ```
|
|
1584
|
+
*/
|
|
1585
|
+
generic(e, t) {
|
|
1586
|
+
return (...r) => t(...r).transform({
|
|
1587
|
+
name: `${t.name}<${r.map((n) => n.name).join(", ")}>`,
|
|
1588
|
+
input: (n) => n,
|
|
1589
|
+
output: (n) => n
|
|
1590
|
+
});
|
|
1591
|
+
},
|
|
1592
|
+
/**
|
|
1593
|
+
* Creates a BcsType that wraps another BcsType which is lazily evaluated. This is useful for creating recursive types.
|
|
1594
|
+
* @param cb A callback that returns the BcsType
|
|
1595
|
+
*/
|
|
1596
|
+
lazy(e) {
|
|
1597
|
+
return Tn(e);
|
|
1598
|
+
}
|
|
1599
|
+
}, vn = 32, pe = class {
|
|
1600
|
+
/**
|
|
1601
|
+
* Construct a BCS instance with a prepared schema.
|
|
1602
|
+
*
|
|
1603
|
+
* @param schema A prepared schema with type definitions
|
|
1604
|
+
* @param withPrimitives Whether to register primitive types by default
|
|
1605
|
+
*/
|
|
1606
|
+
constructor(e) {
|
|
1607
|
+
if (this.types = /* @__PURE__ */ new Map(), this.counter = 0, e instanceof pe) {
|
|
1608
|
+
this.schema = e.schema, this.types = new Map(e.types);
|
|
1609
|
+
return;
|
|
1610
|
+
}
|
|
1611
|
+
if (this.schema = e, this.registerAddressType(pe.ADDRESS, e.addressLength, e.addressEncoding), this.registerVectorType(e.vectorType), e.types && e.types.structs)
|
|
1612
|
+
for (let t of Object.keys(e.types.structs))
|
|
1613
|
+
this.registerStructType(t, e.types.structs[t]);
|
|
1614
|
+
if (e.types && e.types.enums)
|
|
1615
|
+
for (let t of Object.keys(e.types.enums))
|
|
1616
|
+
this.registerEnumType(t, e.types.enums[t]);
|
|
1617
|
+
if (e.types && e.types.aliases)
|
|
1618
|
+
for (let t of Object.keys(e.types.aliases))
|
|
1619
|
+
this.registerAlias(t, e.types.aliases[t]);
|
|
1620
|
+
e.withPrimitives !== !1 && En(this);
|
|
1621
|
+
}
|
|
1622
|
+
/**
|
|
1623
|
+
* Name of the key to use for temporary struct definitions.
|
|
1624
|
+
* Returns a temp key + index (for a case when multiple temp
|
|
1625
|
+
* structs are processed).
|
|
1626
|
+
*/
|
|
1627
|
+
tempKey() {
|
|
1628
|
+
return `bcs-struct-${++this.counter}`;
|
|
1629
|
+
}
|
|
1630
|
+
/**
|
|
1631
|
+
* Serialize data into bcs.
|
|
1632
|
+
*
|
|
1633
|
+
* @example
|
|
1634
|
+
* bcs.registerVectorType('vector<u8>', 'u8');
|
|
1635
|
+
*
|
|
1636
|
+
* let serialized = BCS
|
|
1637
|
+
* .set('vector<u8>', [1,2,3,4,5,6])
|
|
1638
|
+
* .toBytes();
|
|
1639
|
+
*
|
|
1640
|
+
* console.assert(toHex(serialized) === '06010203040506');
|
|
1641
|
+
*
|
|
1642
|
+
* @param type Name of the type to serialize (must be registered) or a struct type.
|
|
1643
|
+
* @param data Data to serialize.
|
|
1644
|
+
* @param size Serialization buffer size. Default 1024 = 1KB.
|
|
1645
|
+
* @return A BCS reader instance. Usually you'd want to call `.toBytes()`
|
|
1646
|
+
*/
|
|
1647
|
+
ser(e, t, r) {
|
|
1648
|
+
if (typeof e == "string" || Array.isArray(e)) {
|
|
1649
|
+
const { name: n, params: i } = this.parseTypeName(e);
|
|
1650
|
+
return this.getTypeInterface(n).encode(this, t, r, i);
|
|
1651
|
+
}
|
|
1652
|
+
if (typeof e == "object") {
|
|
1653
|
+
const n = this.tempKey();
|
|
1654
|
+
return new pe(this).registerStructType(n, e).ser(n, t, r);
|
|
1655
|
+
}
|
|
1656
|
+
throw new Error(`Incorrect type passed into the '.ser()' function.
|
|
1657
|
+
${JSON.stringify(e)}`);
|
|
1658
|
+
}
|
|
1659
|
+
/**
|
|
1660
|
+
* Deserialize BCS into a JS type.
|
|
1661
|
+
*
|
|
1662
|
+
* @example
|
|
1663
|
+
* let num = bcs.ser('u64', '4294967295').toString('hex');
|
|
1664
|
+
* let deNum = bcs.de('u64', num, 'hex');
|
|
1665
|
+
* console.assert(deNum.toString(10) === '4294967295');
|
|
1666
|
+
*
|
|
1667
|
+
* @param type Name of the type to deserialize (must be registered) or a struct type definition.
|
|
1668
|
+
* @param data Data to deserialize.
|
|
1669
|
+
* @param encoding Optional - encoding to use if data is of type String
|
|
1670
|
+
* @return Deserialized data.
|
|
1671
|
+
*/
|
|
1672
|
+
de(e, t, r) {
|
|
1673
|
+
if (typeof t == "string")
|
|
1674
|
+
if (r)
|
|
1675
|
+
t = yn(t, r);
|
|
1676
|
+
else
|
|
1677
|
+
throw new Error("To pass a string to `bcs.de`, specify encoding");
|
|
1678
|
+
if (typeof e == "string" || Array.isArray(e)) {
|
|
1679
|
+
const { name: n, params: i } = this.parseTypeName(e);
|
|
1680
|
+
return this.getTypeInterface(n).decode(this, t, i);
|
|
1681
|
+
}
|
|
1682
|
+
if (typeof e == "object") {
|
|
1683
|
+
const n = new pe(this), i = this.tempKey();
|
|
1684
|
+
return n.registerStructType(i, e).de(i, t, r);
|
|
1685
|
+
}
|
|
1686
|
+
throw new Error(`Incorrect type passed into the '.de()' function.
|
|
1687
|
+
${JSON.stringify(e)}`);
|
|
1688
|
+
}
|
|
1689
|
+
/**
|
|
1690
|
+
* Check whether a `TypeInterface` has been loaded for a `type`.
|
|
1691
|
+
* @param type Name of the type to check.
|
|
1692
|
+
* @returns
|
|
1693
|
+
*/
|
|
1694
|
+
hasType(e) {
|
|
1695
|
+
return this.types.has(e);
|
|
1696
|
+
}
|
|
1697
|
+
/**
|
|
1698
|
+
* Create an alias for a type.
|
|
1699
|
+
* WARNING: this can potentially lead to recursion
|
|
1700
|
+
* @param name Alias to use
|
|
1701
|
+
* @param forType Type to reference
|
|
1702
|
+
* @returns
|
|
1703
|
+
*
|
|
1704
|
+
* @example
|
|
1705
|
+
* ```
|
|
1706
|
+
* let bcs = new BCS(getSuiMoveConfig());
|
|
1707
|
+
* bcs.registerAlias('ObjectDigest', BCS.BASE58);
|
|
1708
|
+
* let b58_digest = bcs.de('ObjectDigest', '<digest_bytes>', 'base64');
|
|
1709
|
+
* ```
|
|
1710
|
+
*/
|
|
1711
|
+
registerAlias(e, t) {
|
|
1712
|
+
return this.types.set(e, t), this;
|
|
1713
|
+
}
|
|
1714
|
+
/**
|
|
1715
|
+
* Method to register new types for BCS internal representation.
|
|
1716
|
+
* For each registered type 2 callbacks must be specified and one is optional:
|
|
1717
|
+
*
|
|
1718
|
+
* - encodeCb(writer, data) - write a way to serialize data with BcsWriter;
|
|
1719
|
+
* - decodeCb(reader) - write a way to deserialize data with BcsReader;
|
|
1720
|
+
* - validateCb(data) - validate data - either return bool or throw an error
|
|
1721
|
+
*
|
|
1722
|
+
* @example
|
|
1723
|
+
* // our type would be a string that consists only of numbers
|
|
1724
|
+
* bcs.registerType('number_string',
|
|
1725
|
+
* (writer, data) => writer.writeVec(data, (w, el) => w.write8(el)),
|
|
1726
|
+
* (reader) => reader.readVec((r) => r.read8()).join(''), // read each value as u8
|
|
1727
|
+
* (value) => /[0-9]+/.test(value) // test that it has at least one digit
|
|
1728
|
+
* );
|
|
1729
|
+
* console.log(Array.from(bcs.ser('number_string', '12345').toBytes()) == [5,1,2,3,4,5]);
|
|
1730
|
+
*
|
|
1731
|
+
* @param name
|
|
1732
|
+
* @param encodeCb Callback to encode a value.
|
|
1733
|
+
* @param decodeCb Callback to decode a value.
|
|
1734
|
+
* @param validateCb Optional validator Callback to check type before serialization.
|
|
1735
|
+
*/
|
|
1736
|
+
registerType(e, t, r, n = () => !0) {
|
|
1737
|
+
const { name: i, params: s } = this.parseTypeName(e);
|
|
1738
|
+
return this.types.set(i, {
|
|
1739
|
+
encode(a, o, u, d) {
|
|
1740
|
+
const l = s.reduce((g, m, p) => Object.assign(g, { [m]: d[p] }), {});
|
|
1741
|
+
return this._encodeRaw.call(a, new nr(u), o, d, l);
|
|
1742
|
+
},
|
|
1743
|
+
decode(a, o, u) {
|
|
1744
|
+
const d = s.reduce((l, g, m) => Object.assign(l, { [g]: u[m] }), {});
|
|
1745
|
+
return this._decodeRaw.call(a, new tr(o), u, d);
|
|
1746
|
+
},
|
|
1747
|
+
// these methods should always be used with caution as they require pre-defined
|
|
1748
|
+
// reader and writer and mainly exist to allow multi-field (de)serialization;
|
|
1749
|
+
_encodeRaw(a, o, u, d) {
|
|
1750
|
+
if (n(o))
|
|
1751
|
+
return t.call(this, a, o, u, d);
|
|
1752
|
+
throw new Error(`Validation failed for type ${i}, data: ${o}`);
|
|
1753
|
+
},
|
|
1754
|
+
_decodeRaw(a, o, u) {
|
|
1755
|
+
return r.call(this, a, o, u);
|
|
1756
|
+
}
|
|
1757
|
+
}), this;
|
|
1758
|
+
}
|
|
1759
|
+
/**
|
|
1760
|
+
* Method to register BcsType instances to the registry
|
|
1761
|
+
* Types are registered with a callback that provides BcsType instances for each generic
|
|
1762
|
+
* passed to the type.
|
|
1763
|
+
*
|
|
1764
|
+
* - createType(...generics) - Return a BcsType instance
|
|
1765
|
+
*
|
|
1766
|
+
* @example
|
|
1767
|
+
* // our type would be a string that consists only of numbers
|
|
1768
|
+
* bcs.registerType('Box<T>', (T) => {
|
|
1769
|
+
* return bcs.struct({
|
|
1770
|
+
* value: T
|
|
1771
|
+
* });
|
|
1772
|
+
* });
|
|
1773
|
+
|
|
1774
|
+
* console.log(Array.from(bcs.ser('Box<string>', '12345').toBytes()) == [5,1,2,3,4,5]);
|
|
1775
|
+
*
|
|
1776
|
+
* @param name
|
|
1777
|
+
* @param createType a Callback to create the BcsType with any passed in generics
|
|
1778
|
+
*/
|
|
1779
|
+
registerBcsType(e, t) {
|
|
1780
|
+
return this.registerType(
|
|
1781
|
+
e,
|
|
1782
|
+
(r, n, i) => {
|
|
1783
|
+
const s = i.map(
|
|
1784
|
+
(a) => new W({
|
|
1785
|
+
name: String(a),
|
|
1786
|
+
write: (o, u) => {
|
|
1787
|
+
const { name: d, params: l } = this.parseTypeName(a), g = this.getTypeInterface(d), m = l.reduce((p, y, S) => Object.assign(p, { [y]: i[S] }), {});
|
|
1788
|
+
return g._encodeRaw.call(this, u, o, l, m);
|
|
1789
|
+
},
|
|
1790
|
+
read: () => {
|
|
1791
|
+
throw new Error("Not implemented");
|
|
1792
|
+
}
|
|
1793
|
+
})
|
|
1794
|
+
);
|
|
1795
|
+
return t(...s).write(n, r), r;
|
|
1796
|
+
},
|
|
1797
|
+
(r, n) => {
|
|
1798
|
+
const i = n.map(
|
|
1799
|
+
(s) => new W({
|
|
1800
|
+
name: String(s),
|
|
1801
|
+
write: (a, o) => {
|
|
1802
|
+
throw new Error("Not implemented");
|
|
1803
|
+
},
|
|
1804
|
+
read: (a) => {
|
|
1805
|
+
const { name: o, params: u } = this.parseTypeName(s), d = this.getTypeInterface(o), l = u.reduce((g, m, p) => Object.assign(g, { [m]: n[p] }), {});
|
|
1806
|
+
return d._decodeRaw.call(this, a, u, l);
|
|
1807
|
+
}
|
|
1808
|
+
})
|
|
1809
|
+
);
|
|
1810
|
+
return t(...i).read(r);
|
|
1811
|
+
}
|
|
1812
|
+
), this;
|
|
1813
|
+
}
|
|
1814
|
+
/**
|
|
1815
|
+
* Register an address type which is a sequence of U8s of specified length.
|
|
1816
|
+
* @example
|
|
1817
|
+
* bcs.registerAddressType('address', SUI_ADDRESS_LENGTH);
|
|
1818
|
+
* let addr = bcs.de('address', 'c3aca510c785c7094ac99aeaa1e69d493122444df50bb8a99dfa790c654a79af');
|
|
1819
|
+
*
|
|
1820
|
+
* @param name Name of the address type.
|
|
1821
|
+
* @param length Byte length of the address.
|
|
1822
|
+
* @param encoding Encoding to use for the address type
|
|
1823
|
+
* @returns
|
|
1824
|
+
*/
|
|
1825
|
+
registerAddressType(e, t, r = "hex") {
|
|
1826
|
+
switch (r) {
|
|
1827
|
+
case "base64":
|
|
1828
|
+
return this.registerType(
|
|
1829
|
+
e,
|
|
1830
|
+
function(i, s) {
|
|
1831
|
+
return ae(s).reduce((a, o) => a.write8(o), i);
|
|
1832
|
+
},
|
|
1833
|
+
function(i) {
|
|
1834
|
+
return Ie(i.readBytes(t));
|
|
1835
|
+
}
|
|
1836
|
+
);
|
|
1837
|
+
case "hex":
|
|
1838
|
+
return this.registerType(
|
|
1839
|
+
e,
|
|
1840
|
+
function(i, s) {
|
|
1841
|
+
return Ve(s).reduce((a, o) => a.write8(o), i);
|
|
1842
|
+
},
|
|
1843
|
+
function(i) {
|
|
1844
|
+
return je(i.readBytes(t));
|
|
1845
|
+
}
|
|
1846
|
+
);
|
|
1847
|
+
default:
|
|
1848
|
+
throw new Error("Unsupported encoding! Use either hex or base64");
|
|
1849
|
+
}
|
|
1850
|
+
}
|
|
1851
|
+
/**
|
|
1852
|
+
* Register custom vector type inside the bcs.
|
|
1853
|
+
*
|
|
1854
|
+
* @example
|
|
1855
|
+
* bcs.registerVectorType('vector<T>'); // generic registration
|
|
1856
|
+
* let array = bcs.de('vector<u8>', '06010203040506', 'hex'); // [1,2,3,4,5,6];
|
|
1857
|
+
* let again = bcs.ser('vector<u8>', [1,2,3,4,5,6]).toString('hex');
|
|
1858
|
+
*
|
|
1859
|
+
* @param name Name of the type to register
|
|
1860
|
+
* @param elementType Optional name of the inner type of the vector
|
|
1861
|
+
* @return Returns self for chaining.
|
|
1862
|
+
*/
|
|
1863
|
+
registerVectorType(e) {
|
|
1864
|
+
let { name: t, params: r } = this.parseTypeName(e);
|
|
1865
|
+
if (r.length > 1)
|
|
1866
|
+
throw new Error("Vector can have only one type parameter; got " + t);
|
|
1867
|
+
return this.registerType(
|
|
1868
|
+
e,
|
|
1869
|
+
function(i, s, a, o) {
|
|
1870
|
+
return i.writeVec(s, (u, d) => {
|
|
1871
|
+
let l = a[0];
|
|
1872
|
+
if (!l)
|
|
1873
|
+
throw new Error(`Incorrect number of type parameters passed a to vector '${e}'`);
|
|
1874
|
+
let { name: g, params: m } = this.parseTypeName(l);
|
|
1875
|
+
if (this.hasType(g))
|
|
1876
|
+
return this.getTypeInterface(g)._encodeRaw.call(this, u, d, m, o);
|
|
1877
|
+
if (!(g in o))
|
|
1878
|
+
throw new Error(
|
|
1879
|
+
`Unable to find a matching type definition for ${g} in vector; make sure you passed a generic`
|
|
1880
|
+
);
|
|
1881
|
+
let { name: p, params: y } = this.parseTypeName(o[g]);
|
|
1882
|
+
return this.getTypeInterface(p)._encodeRaw.call(
|
|
1883
|
+
this,
|
|
1884
|
+
u,
|
|
1885
|
+
d,
|
|
1886
|
+
y,
|
|
1887
|
+
o
|
|
1888
|
+
);
|
|
1889
|
+
});
|
|
1890
|
+
},
|
|
1891
|
+
function(i, s, a) {
|
|
1892
|
+
return i.readVec((o) => {
|
|
1893
|
+
let u = s[0];
|
|
1894
|
+
if (!u)
|
|
1895
|
+
throw new Error(`Incorrect number of type parameters passed to a vector '${e}'`);
|
|
1896
|
+
let { name: d, params: l } = this.parseTypeName(u);
|
|
1897
|
+
if (this.hasType(d))
|
|
1898
|
+
return this.getTypeInterface(d)._decodeRaw.call(this, o, l, a);
|
|
1899
|
+
if (!(d in a))
|
|
1900
|
+
throw new Error(
|
|
1901
|
+
`Unable to find a matching type definition for ${d} in vector; make sure you passed a generic`
|
|
1902
|
+
);
|
|
1903
|
+
let { name: g, params: m } = this.parseTypeName(a[d]);
|
|
1904
|
+
return this.getTypeInterface(g)._decodeRaw.call(
|
|
1905
|
+
this,
|
|
1906
|
+
o,
|
|
1907
|
+
m,
|
|
1908
|
+
a
|
|
1909
|
+
);
|
|
1910
|
+
});
|
|
1911
|
+
}
|
|
1912
|
+
);
|
|
1913
|
+
}
|
|
1914
|
+
/**
|
|
1915
|
+
* Safe method to register a custom Move struct. The first argument is a name of the
|
|
1916
|
+
* struct which is only used on the FrontEnd and has no affect on serialization results,
|
|
1917
|
+
* and the second is a struct description passed as an Object.
|
|
1918
|
+
*
|
|
1919
|
+
* The description object MUST have the same order on all of the platforms (ie in Move
|
|
1920
|
+
* or in Rust).
|
|
1921
|
+
*
|
|
1922
|
+
* @example
|
|
1923
|
+
* // Move / Rust struct
|
|
1924
|
+
* // struct Coin {
|
|
1925
|
+
* // value: u64,
|
|
1926
|
+
* // owner: vector<u8>, // name // Vec<u8> in Rust
|
|
1927
|
+
* // is_locked: bool,
|
|
1928
|
+
* // }
|
|
1929
|
+
*
|
|
1930
|
+
* bcs.registerStructType('Coin', {
|
|
1931
|
+
* value: bcs.U64,
|
|
1932
|
+
* owner: bcs.STRING,
|
|
1933
|
+
* is_locked: bcs.BOOL
|
|
1934
|
+
* });
|
|
1935
|
+
*
|
|
1936
|
+
* // Created in Rust with diem/bcs
|
|
1937
|
+
* // let rust_bcs_str = '80d1b105600000000e4269672057616c6c65742047757900';
|
|
1938
|
+
* let rust_bcs_str = [ // using an Array here as BCS works with Uint8Array
|
|
1939
|
+
* 128, 209, 177, 5, 96, 0, 0,
|
|
1940
|
+
* 0, 14, 66, 105, 103, 32, 87,
|
|
1941
|
+
* 97, 108, 108, 101, 116, 32, 71,
|
|
1942
|
+
* 117, 121, 0
|
|
1943
|
+
* ];
|
|
1944
|
+
*
|
|
1945
|
+
* // Let's encode the value as well
|
|
1946
|
+
* let test_set = bcs.ser('Coin', {
|
|
1947
|
+
* owner: 'Big Wallet Guy',
|
|
1948
|
+
* value: '412412400000',
|
|
1949
|
+
* is_locked: false,
|
|
1950
|
+
* });
|
|
1951
|
+
*
|
|
1952
|
+
* console.assert(Array.from(test_set.toBytes()) === rust_bcs_str, 'Whoopsie, result mismatch');
|
|
1953
|
+
*
|
|
1954
|
+
* @param name Name of the type to register.
|
|
1955
|
+
* @param fields Fields of the struct. Must be in the correct order.
|
|
1956
|
+
* @return Returns BCS for chaining.
|
|
1957
|
+
*/
|
|
1958
|
+
registerStructType(e, t) {
|
|
1959
|
+
for (let a in t) {
|
|
1960
|
+
let o = this.tempKey(), u = t[a];
|
|
1961
|
+
!Array.isArray(u) && typeof u != "string" && (t[a] = o, this.registerStructType(o, u));
|
|
1962
|
+
}
|
|
1963
|
+
let r = Object.freeze(t), n = Object.keys(r), { name: i, params: s } = this.parseTypeName(e);
|
|
1964
|
+
return this.registerType(
|
|
1965
|
+
e,
|
|
1966
|
+
function(o, u, d, l) {
|
|
1967
|
+
if (!u || u.constructor !== Object)
|
|
1968
|
+
throw new Error(`Expected ${i} to be an Object, got: ${u}`);
|
|
1969
|
+
if (d.length !== s.length)
|
|
1970
|
+
throw new Error(
|
|
1971
|
+
`Incorrect number of generic parameters passed; expected: ${s.length}, got: ${d.length}`
|
|
1972
|
+
);
|
|
1973
|
+
for (let g of n) {
|
|
1974
|
+
if (!(g in u))
|
|
1975
|
+
throw new Error(`Struct ${i} requires field ${g}:${r[g]}`);
|
|
1976
|
+
const { name: m, params: p } = this.parseTypeName(
|
|
1977
|
+
r[g]
|
|
1978
|
+
);
|
|
1979
|
+
if (!s.includes(m))
|
|
1980
|
+
this.getTypeInterface(m)._encodeRaw.call(
|
|
1981
|
+
this,
|
|
1982
|
+
o,
|
|
1983
|
+
u[g],
|
|
1984
|
+
p,
|
|
1985
|
+
l
|
|
1986
|
+
);
|
|
1987
|
+
else {
|
|
1988
|
+
const y = s.indexOf(m);
|
|
1989
|
+
let { name: S, params: E } = this.parseTypeName(d[y]);
|
|
1990
|
+
if (this.hasType(S)) {
|
|
1991
|
+
this.getTypeInterface(S)._encodeRaw.call(
|
|
1992
|
+
this,
|
|
1993
|
+
o,
|
|
1994
|
+
u[g],
|
|
1995
|
+
E,
|
|
1996
|
+
l
|
|
1997
|
+
);
|
|
1998
|
+
continue;
|
|
1999
|
+
}
|
|
2000
|
+
if (!(S in l))
|
|
2001
|
+
throw new Error(
|
|
2002
|
+
`Unable to find a matching type definition for ${S} in ${i}; make sure you passed a generic`
|
|
2003
|
+
);
|
|
2004
|
+
let { name: A, params: _ } = this.parseTypeName(l[S]);
|
|
2005
|
+
this.getTypeInterface(A)._encodeRaw.call(
|
|
2006
|
+
this,
|
|
2007
|
+
o,
|
|
2008
|
+
u[g],
|
|
2009
|
+
_,
|
|
2010
|
+
l
|
|
2011
|
+
);
|
|
2012
|
+
}
|
|
2013
|
+
}
|
|
2014
|
+
return o;
|
|
2015
|
+
},
|
|
2016
|
+
function(o, u, d) {
|
|
2017
|
+
if (u.length !== s.length)
|
|
2018
|
+
throw new Error(
|
|
2019
|
+
`Incorrect number of generic parameters passed; expected: ${s.length}, got: ${u.length}`
|
|
2020
|
+
);
|
|
2021
|
+
let l = {};
|
|
2022
|
+
for (let g of n) {
|
|
2023
|
+
const { name: m, params: p } = this.parseTypeName(
|
|
2024
|
+
r[g]
|
|
2025
|
+
);
|
|
2026
|
+
if (!s.includes(m))
|
|
2027
|
+
l[g] = this.getTypeInterface(m)._decodeRaw.call(
|
|
2028
|
+
this,
|
|
2029
|
+
o,
|
|
2030
|
+
p,
|
|
2031
|
+
d
|
|
2032
|
+
);
|
|
2033
|
+
else {
|
|
2034
|
+
const y = s.indexOf(m);
|
|
2035
|
+
let { name: S, params: E } = this.parseTypeName(u[y]);
|
|
2036
|
+
if (this.hasType(S)) {
|
|
2037
|
+
l[g] = this.getTypeInterface(S)._decodeRaw.call(
|
|
2038
|
+
this,
|
|
2039
|
+
o,
|
|
2040
|
+
E,
|
|
2041
|
+
d
|
|
2042
|
+
);
|
|
2043
|
+
continue;
|
|
2044
|
+
}
|
|
2045
|
+
if (!(S in d))
|
|
2046
|
+
throw new Error(
|
|
2047
|
+
`Unable to find a matching type definition for ${S} in ${i}; make sure you passed a generic`
|
|
2048
|
+
);
|
|
2049
|
+
let { name: A, params: _ } = this.parseTypeName(d[S]);
|
|
2050
|
+
l[g] = this.getTypeInterface(A)._decodeRaw.call(
|
|
2051
|
+
this,
|
|
2052
|
+
o,
|
|
2053
|
+
_,
|
|
2054
|
+
d
|
|
2055
|
+
);
|
|
2056
|
+
}
|
|
2057
|
+
}
|
|
2058
|
+
return l;
|
|
2059
|
+
}
|
|
2060
|
+
);
|
|
2061
|
+
}
|
|
2062
|
+
/**
|
|
2063
|
+
* Safe method to register custom enum type where each invariant holds the value of another type.
|
|
2064
|
+
* @example
|
|
2065
|
+
* bcs.registerStructType('Coin', { value: 'u64' });
|
|
2066
|
+
* bcs.registerEnumType('MyEnum', {
|
|
2067
|
+
* single: 'Coin',
|
|
2068
|
+
* multi: 'vector<Coin>',
|
|
2069
|
+
* empty: null
|
|
2070
|
+
* });
|
|
2071
|
+
*
|
|
2072
|
+
* console.log(
|
|
2073
|
+
* bcs.de('MyEnum', 'AICWmAAAAAAA', 'base64'), // { single: { value: 10000000 } }
|
|
2074
|
+
* bcs.de('MyEnum', 'AQIBAAAAAAAAAAIAAAAAAAAA', 'base64') // { multi: [ { value: 1 }, { value: 2 } ] }
|
|
2075
|
+
* )
|
|
2076
|
+
*
|
|
2077
|
+
* // and serialization
|
|
2078
|
+
* bcs.ser('MyEnum', { single: { value: 10000000 } }).toBytes();
|
|
2079
|
+
* bcs.ser('MyEnum', { multi: [ { value: 1 }, { value: 2 } ] });
|
|
2080
|
+
*
|
|
2081
|
+
* @param name
|
|
2082
|
+
* @param variants
|
|
2083
|
+
*/
|
|
2084
|
+
registerEnumType(e, t) {
|
|
2085
|
+
for (let a in t) {
|
|
2086
|
+
let o = this.tempKey(), u = t[a];
|
|
2087
|
+
u !== null && !Array.isArray(u) && typeof u != "string" && (t[a] = o, this.registerStructType(o, u));
|
|
2088
|
+
}
|
|
2089
|
+
let r = Object.freeze(t), n = Object.keys(r), { name: i, params: s } = this.parseTypeName(e);
|
|
2090
|
+
return this.registerType(
|
|
2091
|
+
e,
|
|
2092
|
+
function(o, u, d, l) {
|
|
2093
|
+
if (!u)
|
|
2094
|
+
throw new Error(`Unable to write enum "${i}", missing data.
|
|
2095
|
+
Received: "${u}"`);
|
|
2096
|
+
if (typeof u != "object")
|
|
2097
|
+
throw new Error(
|
|
2098
|
+
`Incorrect data passed into enum "${i}", expected object with properties: "${n.join(
|
|
2099
|
+
" | "
|
|
2100
|
+
)}".
|
|
2101
|
+
Received: "${JSON.stringify(u)}"`
|
|
2102
|
+
);
|
|
2103
|
+
let g = Object.keys(u)[0];
|
|
2104
|
+
if (g === void 0)
|
|
2105
|
+
throw new Error(`Empty object passed as invariant of the enum "${i}"`);
|
|
2106
|
+
let m = n.indexOf(g);
|
|
2107
|
+
if (m === -1)
|
|
2108
|
+
throw new Error(
|
|
2109
|
+
`Unknown invariant of the enum "${i}", allowed values: "${n.join(
|
|
2110
|
+
" | "
|
|
2111
|
+
)}"; received "${g}"`
|
|
2112
|
+
);
|
|
2113
|
+
let p = n[m], y = r[p];
|
|
2114
|
+
if (o.write8(m), y === null)
|
|
2115
|
+
return o;
|
|
2116
|
+
let S = s.indexOf(y), E = S === -1 ? y : d[S];
|
|
2117
|
+
{
|
|
2118
|
+
let { name: A, params: _ } = this.parseTypeName(E);
|
|
2119
|
+
return this.getTypeInterface(A)._encodeRaw.call(
|
|
2120
|
+
this,
|
|
2121
|
+
o,
|
|
2122
|
+
u[g],
|
|
2123
|
+
_,
|
|
2124
|
+
l
|
|
2125
|
+
);
|
|
2126
|
+
}
|
|
2127
|
+
},
|
|
2128
|
+
function(o, u, d) {
|
|
2129
|
+
let l = o.readULEB(), g = n[l], m = r[g];
|
|
2130
|
+
if (l === -1)
|
|
2131
|
+
throw new Error(
|
|
2132
|
+
`Decoding type mismatch, expected enum "${i}" invariant index, received "${l}"`
|
|
2133
|
+
);
|
|
2134
|
+
if (m === null)
|
|
2135
|
+
return { [g]: !0 };
|
|
2136
|
+
let p = s.indexOf(m), y = p === -1 ? m : u[p];
|
|
2137
|
+
{
|
|
2138
|
+
let { name: S, params: E } = this.parseTypeName(y);
|
|
2139
|
+
return {
|
|
2140
|
+
[g]: this.getTypeInterface(S)._decodeRaw.call(this, o, E, d)
|
|
2141
|
+
};
|
|
2142
|
+
}
|
|
2143
|
+
}
|
|
2144
|
+
);
|
|
2145
|
+
}
|
|
2146
|
+
/**
|
|
2147
|
+
* Get a set of encoders/decoders for specific type.
|
|
2148
|
+
* Mainly used to define custom type de/serialization logic.
|
|
2149
|
+
*
|
|
2150
|
+
* @param type
|
|
2151
|
+
* @returns {TypeInterface}
|
|
2152
|
+
*/
|
|
2153
|
+
getTypeInterface(e) {
|
|
2154
|
+
let t = this.types.get(e);
|
|
2155
|
+
if (typeof t == "string") {
|
|
2156
|
+
let r = [];
|
|
2157
|
+
for (; typeof t == "string"; ) {
|
|
2158
|
+
if (r.includes(t))
|
|
2159
|
+
throw new Error(`Recursive definition found: ${r.join(" -> ")} -> ${t}`);
|
|
2160
|
+
r.push(t), t = this.types.get(t);
|
|
2161
|
+
}
|
|
2162
|
+
}
|
|
2163
|
+
if (t === void 0)
|
|
2164
|
+
throw new Error(`Type ${e} is not registered`);
|
|
2165
|
+
return t;
|
|
2166
|
+
}
|
|
2167
|
+
/**
|
|
2168
|
+
* Parse a type name and get the type's generics.
|
|
2169
|
+
* @example
|
|
2170
|
+
* let { typeName, typeParams } = parseTypeName('Option<Coin<SUI>>');
|
|
2171
|
+
* // typeName: Option
|
|
2172
|
+
* // typeParams: [ 'Coin<SUI>' ]
|
|
2173
|
+
*
|
|
2174
|
+
* @param name Name of the type to process
|
|
2175
|
+
* @returns Object with typeName and typeParams listed as Array
|
|
2176
|
+
*/
|
|
2177
|
+
parseTypeName(e) {
|
|
2178
|
+
if (Array.isArray(e)) {
|
|
2179
|
+
let [o, ...u] = e;
|
|
2180
|
+
return { name: o, params: u };
|
|
2181
|
+
}
|
|
2182
|
+
if (typeof e != "string")
|
|
2183
|
+
throw new Error(`Illegal type passed as a name of the type: ${e}`);
|
|
2184
|
+
let [t, r] = this.schema.genericSeparators || ["<", ">"], n = e.indexOf(t), i = Array.from(e).reverse().indexOf(r);
|
|
2185
|
+
if (n === -1 && i === -1)
|
|
2186
|
+
return { name: e, params: [] };
|
|
2187
|
+
if (n === -1 || i === -1)
|
|
2188
|
+
throw new Error(`Unclosed generic in name '${e}'`);
|
|
2189
|
+
let s = e.slice(0, n), a = rr(
|
|
2190
|
+
e.slice(n + 1, e.length - i - 1),
|
|
2191
|
+
this.schema.genericSeparators
|
|
2192
|
+
);
|
|
2193
|
+
return { name: s, params: a };
|
|
2194
|
+
}
|
|
2195
|
+
};
|
|
2196
|
+
let j = pe;
|
|
2197
|
+
j.U8 = "u8";
|
|
2198
|
+
j.U16 = "u16";
|
|
2199
|
+
j.U32 = "u32";
|
|
2200
|
+
j.U64 = "u64";
|
|
2201
|
+
j.U128 = "u128";
|
|
2202
|
+
j.U256 = "u256";
|
|
2203
|
+
j.BOOL = "bool";
|
|
2204
|
+
j.VECTOR = "vector";
|
|
2205
|
+
j.ADDRESS = "address";
|
|
2206
|
+
j.STRING = "string";
|
|
2207
|
+
j.HEX = "hex-string";
|
|
2208
|
+
j.BASE58 = "base58-string";
|
|
2209
|
+
j.BASE64 = "base64-string";
|
|
2210
|
+
function En(e) {
|
|
2211
|
+
e.registerType(
|
|
2212
|
+
j.U8,
|
|
2213
|
+
function(t, r) {
|
|
2214
|
+
return t.write8(r);
|
|
2215
|
+
},
|
|
2216
|
+
function(t) {
|
|
2217
|
+
return t.read8();
|
|
2218
|
+
},
|
|
2219
|
+
(t) => t < 256
|
|
2220
|
+
), e.registerType(
|
|
2221
|
+
j.U16,
|
|
2222
|
+
function(t, r) {
|
|
2223
|
+
return t.write16(r);
|
|
2224
|
+
},
|
|
2225
|
+
function(t) {
|
|
2226
|
+
return t.read16();
|
|
2227
|
+
},
|
|
2228
|
+
(t) => t < 65536
|
|
2229
|
+
), e.registerType(
|
|
2230
|
+
j.U32,
|
|
2231
|
+
function(t, r) {
|
|
2232
|
+
return t.write32(r);
|
|
2233
|
+
},
|
|
2234
|
+
function(t) {
|
|
2235
|
+
return t.read32();
|
|
2236
|
+
},
|
|
2237
|
+
(t) => t <= 4294967296n
|
|
2238
|
+
), e.registerType(
|
|
2239
|
+
j.U64,
|
|
2240
|
+
function(t, r) {
|
|
2241
|
+
return t.write64(r);
|
|
2242
|
+
},
|
|
2243
|
+
function(t) {
|
|
2244
|
+
return t.read64();
|
|
2245
|
+
}
|
|
2246
|
+
), e.registerType(
|
|
2247
|
+
j.U128,
|
|
2248
|
+
function(t, r) {
|
|
2249
|
+
return t.write128(r);
|
|
2250
|
+
},
|
|
2251
|
+
function(t) {
|
|
2252
|
+
return t.read128();
|
|
2253
|
+
}
|
|
2254
|
+
), e.registerType(
|
|
2255
|
+
j.U256,
|
|
2256
|
+
function(t, r) {
|
|
2257
|
+
return t.write256(r);
|
|
2258
|
+
},
|
|
2259
|
+
function(t) {
|
|
2260
|
+
return t.read256();
|
|
2261
|
+
}
|
|
2262
|
+
), e.registerType(
|
|
2263
|
+
j.BOOL,
|
|
2264
|
+
function(t, r) {
|
|
2265
|
+
return t.write8(r);
|
|
2266
|
+
},
|
|
2267
|
+
function(t) {
|
|
2268
|
+
return t.read8().toString(10) === "1";
|
|
2269
|
+
}
|
|
2270
|
+
), e.registerType(
|
|
2271
|
+
j.STRING,
|
|
2272
|
+
function(t, r) {
|
|
2273
|
+
return t.writeVec(Array.from(r), (n, i) => n.write8(i.charCodeAt(0)));
|
|
2274
|
+
},
|
|
2275
|
+
function(t) {
|
|
2276
|
+
return t.readVec((r) => r.read8()).map((r) => String.fromCharCode(Number(r))).join("");
|
|
2277
|
+
},
|
|
2278
|
+
(t) => !0
|
|
2279
|
+
), e.registerType(
|
|
2280
|
+
j.HEX,
|
|
2281
|
+
function(t, r) {
|
|
2282
|
+
return t.writeVec(Array.from(Ve(r)), (n, i) => n.write8(i));
|
|
2283
|
+
},
|
|
2284
|
+
function(t) {
|
|
2285
|
+
let r = t.readVec((n) => n.read8());
|
|
2286
|
+
return je(new Uint8Array(r));
|
|
2287
|
+
}
|
|
2288
|
+
), e.registerType(
|
|
2289
|
+
j.BASE58,
|
|
2290
|
+
function(t, r) {
|
|
2291
|
+
return t.writeVec(Array.from(ot(r)), (n, i) => n.write8(i));
|
|
2292
|
+
},
|
|
2293
|
+
function(t) {
|
|
2294
|
+
let r = t.readVec((n) => n.read8());
|
|
2295
|
+
return xe(new Uint8Array(r));
|
|
2296
|
+
}
|
|
2297
|
+
), e.registerType(
|
|
2298
|
+
j.BASE64,
|
|
2299
|
+
function(t, r) {
|
|
2300
|
+
return t.writeVec(Array.from(ae(r)), (n, i) => n.write8(i));
|
|
2301
|
+
},
|
|
2302
|
+
function(t) {
|
|
2303
|
+
let r = t.readVec((n) => n.read8());
|
|
2304
|
+
return Ie(new Uint8Array(r));
|
|
2305
|
+
}
|
|
2306
|
+
);
|
|
2307
|
+
}
|
|
2308
|
+
function xn() {
|
|
2309
|
+
return {
|
|
2310
|
+
genericSeparators: ["<", ">"],
|
|
2311
|
+
vectorType: "vector",
|
|
2312
|
+
addressLength: vn,
|
|
2313
|
+
addressEncoding: "hex"
|
|
2314
|
+
};
|
|
2315
|
+
}
|
|
2316
|
+
const dt = 32;
|
|
2317
|
+
function In(e) {
|
|
2318
|
+
return jn(e) && On(e) === dt;
|
|
2319
|
+
}
|
|
2320
|
+
function M(e, t = !1) {
|
|
2321
|
+
let r = e.toLowerCase();
|
|
2322
|
+
return !t && r.startsWith("0x") && (r = r.slice(2)), `0x${r.padStart(dt * 2, "0")}`;
|
|
2323
|
+
}
|
|
2324
|
+
function be(e, t = !1) {
|
|
2325
|
+
return M(e, t);
|
|
2326
|
+
}
|
|
2327
|
+
function jn(e) {
|
|
2328
|
+
return /^(0x|0X)?[a-fA-F0-9]+$/.test(e) && e.length % 2 === 0;
|
|
2329
|
+
}
|
|
2330
|
+
function On(e) {
|
|
2331
|
+
return /^(0x|0X)/.test(e) ? (e.length - 2) / 2 : e.length / 2;
|
|
2332
|
+
}
|
|
2333
|
+
BigInt(1e9);
|
|
2334
|
+
const ft = "0x1", or = "0x2";
|
|
2335
|
+
be("0x6");
|
|
2336
|
+
const An = `${or}::sui::SUI`;
|
|
2337
|
+
be("0x5");
|
|
2338
|
+
const kn = "object", _n = "ID", Cn = "ascii", $n = "String", Mn = "string", Un = "String", Bn = "option", Rn = "Option", Nn = {
|
|
2339
|
+
address: or,
|
|
2340
|
+
module: kn,
|
|
2341
|
+
name: _n
|
|
2342
|
+
}, Pn = {
|
|
2343
|
+
address: ft,
|
|
2344
|
+
module: Cn,
|
|
2345
|
+
name: $n
|
|
2346
|
+
}, Dn = {
|
|
2347
|
+
address: ft,
|
|
2348
|
+
module: Mn,
|
|
2349
|
+
name: Un
|
|
2350
|
+
}, zn = {
|
|
2351
|
+
address: ft,
|
|
2352
|
+
module: Bn,
|
|
2353
|
+
name: Rn
|
|
2354
|
+
}, Ae = (e, t) => e.address === t.address && e.module === t.module && e.name === t.name;
|
|
2355
|
+
function Vn(e) {
|
|
2356
|
+
var r;
|
|
2357
|
+
const t = (r = at(e)) == null ? void 0 : r.Struct;
|
|
2358
|
+
return (t == null ? void 0 : t.address) === "0x2" && (t == null ? void 0 : t.module) === "tx_context" && (t == null ? void 0 : t.name) === "TxContext";
|
|
2359
|
+
}
|
|
2360
|
+
function Je(e, t) {
|
|
2361
|
+
if (!(typeof t > "u") && typeof t !== e)
|
|
2362
|
+
throw new Error(`Expect ${t} to be ${e}, received ${typeof t}`);
|
|
2363
|
+
}
|
|
2364
|
+
const Gn = ["Address", "Bool", "U8", "U16", "U32", "U64", "U128", "U256"];
|
|
2365
|
+
function Qe(e, t) {
|
|
2366
|
+
if (typeof e == "string" && Gn.includes(e)) {
|
|
2367
|
+
if (e in ["U8", "U16", "U32", "U64", "U128", "U256"])
|
|
2368
|
+
Je("number", t);
|
|
2369
|
+
else if (e === "Bool")
|
|
2370
|
+
Je("boolean", t);
|
|
2371
|
+
else if (e === "Address" && (Je("string", t), t && !In(t)))
|
|
2372
|
+
throw new Error("Invalid Sui Address");
|
|
2373
|
+
return e.toLowerCase();
|
|
2374
|
+
} else if (typeof e == "string")
|
|
2375
|
+
throw new Error(`Unknown pure normalized type ${JSON.stringify(e, null, 2)}`);
|
|
2376
|
+
if ("Vector" in e) {
|
|
2377
|
+
if ((t === void 0 || typeof t == "string") && e.Vector === "U8")
|
|
2378
|
+
return "string";
|
|
2379
|
+
if (t !== void 0 && !Array.isArray(t))
|
|
2380
|
+
throw new Error(`Expect ${t} to be a array, received ${typeof t}`);
|
|
2381
|
+
const r = Qe(
|
|
2382
|
+
e.Vector,
|
|
2383
|
+
// undefined when argVal is empty
|
|
2384
|
+
t ? t[0] : void 0
|
|
2385
|
+
);
|
|
2386
|
+
return r === void 0 ? void 0 : `vector<${r}>`;
|
|
2387
|
+
}
|
|
2388
|
+
if ("Struct" in e) {
|
|
2389
|
+
if (Ae(e.Struct, Pn))
|
|
2390
|
+
return "string";
|
|
2391
|
+
if (Ae(e.Struct, Dn))
|
|
2392
|
+
return "utf8string";
|
|
2393
|
+
if (Ae(e.Struct, Nn))
|
|
2394
|
+
return "address";
|
|
2395
|
+
if (Ae(e.Struct, zn)) {
|
|
2396
|
+
const r = {
|
|
2397
|
+
Vector: e.Struct.typeArguments[0]
|
|
2398
|
+
};
|
|
2399
|
+
return Qe(r, t);
|
|
2400
|
+
}
|
|
2401
|
+
}
|
|
2402
|
+
}
|
|
2403
|
+
const Fn = /^vector<(.+)>$/, Ln = /^([^:]+)::([^:]+)::([^<]+)(<(.+)>)?/;
|
|
2404
|
+
class ee {
|
|
2405
|
+
static parseFromStr(t, r = !1) {
|
|
2406
|
+
if (t === "address")
|
|
2407
|
+
return { address: null };
|
|
2408
|
+
if (t === "bool")
|
|
2409
|
+
return { bool: null };
|
|
2410
|
+
if (t === "u8")
|
|
2411
|
+
return { u8: null };
|
|
2412
|
+
if (t === "u16")
|
|
2413
|
+
return { u16: null };
|
|
2414
|
+
if (t === "u32")
|
|
2415
|
+
return { u32: null };
|
|
2416
|
+
if (t === "u64")
|
|
2417
|
+
return { u64: null };
|
|
2418
|
+
if (t === "u128")
|
|
2419
|
+
return { u128: null };
|
|
2420
|
+
if (t === "u256")
|
|
2421
|
+
return { u256: null };
|
|
2422
|
+
if (t === "signer")
|
|
2423
|
+
return { signer: null };
|
|
2424
|
+
const n = t.match(Fn);
|
|
2425
|
+
if (n)
|
|
2426
|
+
return {
|
|
2427
|
+
vector: ee.parseFromStr(n[1], r)
|
|
2428
|
+
};
|
|
2429
|
+
const i = t.match(Ln);
|
|
2430
|
+
if (i)
|
|
2431
|
+
return {
|
|
2432
|
+
struct: {
|
|
2433
|
+
address: r ? M(i[1]) : i[1],
|
|
2434
|
+
module: i[2],
|
|
2435
|
+
name: i[3],
|
|
2436
|
+
typeParams: i[5] === void 0 ? [] : ee.parseStructTypeArgs(i[5], r)
|
|
2437
|
+
}
|
|
2438
|
+
};
|
|
2439
|
+
throw new Error(`Encountered unexpected token when parsing type args for ${t}`);
|
|
2440
|
+
}
|
|
2441
|
+
static parseStructTypeArgs(t, r = !1) {
|
|
2442
|
+
return rr(t).map(
|
|
2443
|
+
(n) => ee.parseFromStr(n, r)
|
|
2444
|
+
);
|
|
2445
|
+
}
|
|
2446
|
+
static tagToString(t) {
|
|
2447
|
+
if ("bool" in t)
|
|
2448
|
+
return "bool";
|
|
2449
|
+
if ("u8" in t)
|
|
2450
|
+
return "u8";
|
|
2451
|
+
if ("u16" in t)
|
|
2452
|
+
return "u16";
|
|
2453
|
+
if ("u32" in t)
|
|
2454
|
+
return "u32";
|
|
2455
|
+
if ("u64" in t)
|
|
2456
|
+
return "u64";
|
|
2457
|
+
if ("u128" in t)
|
|
2458
|
+
return "u128";
|
|
2459
|
+
if ("u256" in t)
|
|
2460
|
+
return "u256";
|
|
2461
|
+
if ("address" in t)
|
|
2462
|
+
return "address";
|
|
2463
|
+
if ("signer" in t)
|
|
2464
|
+
return "signer";
|
|
2465
|
+
if ("vector" in t)
|
|
2466
|
+
return `vector<${ee.tagToString(t.vector)}>`;
|
|
2467
|
+
if ("struct" in t) {
|
|
2468
|
+
const r = t.struct, n = r.typeParams.map(ee.tagToString).join(", ");
|
|
2469
|
+
return `${r.address}::${r.module}::${r.name}${n ? `<${n}>` : ""}`;
|
|
2470
|
+
}
|
|
2471
|
+
throw new Error("Invalid TypeTag");
|
|
2472
|
+
}
|
|
2473
|
+
}
|
|
2474
|
+
const I = new j({
|
|
2475
|
+
...xn(),
|
|
2476
|
+
types: {
|
|
2477
|
+
enums: {
|
|
2478
|
+
"Option<T>": {
|
|
2479
|
+
None: null,
|
|
2480
|
+
Some: "T"
|
|
2481
|
+
}
|
|
2482
|
+
}
|
|
2483
|
+
}
|
|
2484
|
+
});
|
|
2485
|
+
function cr(e) {
|
|
2486
|
+
return c.u64({
|
|
2487
|
+
name: "unsafe_u64",
|
|
2488
|
+
...e
|
|
2489
|
+
}).transform({
|
|
2490
|
+
input: (t) => t,
|
|
2491
|
+
output: (t) => Number(t)
|
|
2492
|
+
});
|
|
2493
|
+
}
|
|
2494
|
+
function Kn(e) {
|
|
2495
|
+
return c.enum("Option", {
|
|
2496
|
+
None: null,
|
|
2497
|
+
Some: e
|
|
2498
|
+
});
|
|
2499
|
+
}
|
|
2500
|
+
function lt(e) {
|
|
2501
|
+
return e.transform({
|
|
2502
|
+
input: (t) => ({
|
|
2503
|
+
[t.kind]: t
|
|
2504
|
+
}),
|
|
2505
|
+
output: (t) => {
|
|
2506
|
+
const r = Object.keys(t)[0];
|
|
2507
|
+
return { kind: r, ...t[r] };
|
|
2508
|
+
}
|
|
2509
|
+
});
|
|
2510
|
+
}
|
|
2511
|
+
const J = c.bytes(dt).transform({
|
|
2512
|
+
input: (e) => typeof e == "string" ? Ve(M(e)) : e,
|
|
2513
|
+
output: (e) => M(je(e))
|
|
2514
|
+
}), ht = c.vector(c.u8()).transform({
|
|
2515
|
+
name: "ObjectDigest",
|
|
2516
|
+
input: (e) => ot(e),
|
|
2517
|
+
output: (e) => xe(new Uint8Array(e))
|
|
2518
|
+
}), Se = c.struct("SuiObjectRef", {
|
|
2519
|
+
objectId: J,
|
|
2520
|
+
version: c.u64(),
|
|
2521
|
+
digest: ht
|
|
2522
|
+
}), gt = c.struct("SharedObjectRef", {
|
|
2523
|
+
objectId: J,
|
|
2524
|
+
initialSharedVersion: c.u64(),
|
|
2525
|
+
mutable: c.bool()
|
|
2526
|
+
}), Pe = c.enum("ObjectArg", {
|
|
2527
|
+
ImmOrOwned: Se,
|
|
2528
|
+
Shared: gt,
|
|
2529
|
+
Receiving: Se
|
|
2530
|
+
}), pt = c.enum("CallArg", {
|
|
2531
|
+
Pure: c.vector(c.u8()),
|
|
2532
|
+
Object: Pe,
|
|
2533
|
+
ObjVec: c.vector(Pe)
|
|
2534
|
+
}), he = c.enum("TypeTag", {
|
|
2535
|
+
bool: null,
|
|
2536
|
+
u8: null,
|
|
2537
|
+
u64: null,
|
|
2538
|
+
u128: null,
|
|
2539
|
+
address: null,
|
|
2540
|
+
signer: null,
|
|
2541
|
+
vector: c.lazy(() => he),
|
|
2542
|
+
struct: c.lazy(() => Tt),
|
|
2543
|
+
u16: null,
|
|
2544
|
+
u32: null,
|
|
2545
|
+
u256: null
|
|
2546
|
+
}), L = lt(
|
|
2547
|
+
c.enum("Argument", {
|
|
2548
|
+
GasCoin: null,
|
|
2549
|
+
Input: c.struct("Input", { index: c.u16() }),
|
|
2550
|
+
Result: c.struct("Result", { index: c.u16() }),
|
|
2551
|
+
NestedResult: c.struct("NestedResult", { index: c.u16(), resultIndex: c.u16() })
|
|
2552
|
+
})
|
|
2553
|
+
), mt = c.struct("ProgrammableMoveCall", {
|
|
2554
|
+
package: J,
|
|
2555
|
+
module: c.string(),
|
|
2556
|
+
function: c.string(),
|
|
2557
|
+
type_arguments: c.vector(he),
|
|
2558
|
+
arguments: c.vector(L)
|
|
2559
|
+
}).transform({
|
|
2560
|
+
input: (e) => {
|
|
2561
|
+
const [t, r, n] = e.target.split("::"), i = e.typeArguments.map(
|
|
2562
|
+
(s) => ee.parseFromStr(s, !0)
|
|
2563
|
+
);
|
|
2564
|
+
return {
|
|
2565
|
+
package: M(t),
|
|
2566
|
+
module: r,
|
|
2567
|
+
function: n,
|
|
2568
|
+
type_arguments: i,
|
|
2569
|
+
arguments: e.arguments
|
|
2570
|
+
};
|
|
2571
|
+
},
|
|
2572
|
+
output: (e) => ({
|
|
2573
|
+
target: [e.package, e.module, e.function].join(
|
|
2574
|
+
"::"
|
|
2575
|
+
),
|
|
2576
|
+
arguments: e.arguments,
|
|
2577
|
+
typeArguments: e.type_arguments.map(ee.tagToString)
|
|
2578
|
+
})
|
|
2579
|
+
}), yt = lt(
|
|
2580
|
+
c.enum("Transaction", {
|
|
2581
|
+
/**
|
|
2582
|
+
* A Move Call - any public Move function can be called via
|
|
2583
|
+
* this transaction. The results can be used that instant to pass
|
|
2584
|
+
* into the next transaction.
|
|
2585
|
+
*/
|
|
2586
|
+
MoveCall: mt,
|
|
2587
|
+
/**
|
|
2588
|
+
* Transfer vector of objects to a receiver.
|
|
2589
|
+
*/
|
|
2590
|
+
TransferObjects: c.struct("TransferObjects", {
|
|
2591
|
+
objects: c.vector(L),
|
|
2592
|
+
address: L
|
|
2593
|
+
}),
|
|
2594
|
+
/**
|
|
2595
|
+
* Split `amount` from a `coin`.
|
|
2596
|
+
*/
|
|
2597
|
+
SplitCoins: c.struct("SplitCoins", { coin: L, amounts: c.vector(L) }),
|
|
2598
|
+
/**
|
|
2599
|
+
* Merge Vector of Coins (`sources`) into a `destination`.
|
|
2600
|
+
*/
|
|
2601
|
+
MergeCoins: c.struct("MergeCoins", { destination: L, sources: c.vector(L) }),
|
|
2602
|
+
/**
|
|
2603
|
+
* Publish a Move module.
|
|
2604
|
+
*/
|
|
2605
|
+
Publish: c.struct("Publish", {
|
|
2606
|
+
modules: c.vector(c.vector(c.u8())),
|
|
2607
|
+
dependencies: c.vector(J)
|
|
2608
|
+
}),
|
|
2609
|
+
/**
|
|
2610
|
+
* Build a vector of objects using the input arguments.
|
|
2611
|
+
* It is impossible to construct a `vector<T: key>` otherwise,
|
|
2612
|
+
* so this call serves a utility function.
|
|
2613
|
+
*/
|
|
2614
|
+
MakeMoveVec: c.struct("MakeMoveVec", {
|
|
2615
|
+
type: Kn(he),
|
|
2616
|
+
objects: c.vector(L)
|
|
2617
|
+
}),
|
|
2618
|
+
/** */
|
|
2619
|
+
Upgrade: c.struct("Upgrade", {
|
|
2620
|
+
modules: c.vector(c.vector(c.u8())),
|
|
2621
|
+
dependencies: c.vector(J),
|
|
2622
|
+
packageId: J,
|
|
2623
|
+
ticket: L
|
|
2624
|
+
})
|
|
2625
|
+
})
|
|
2626
|
+
), wt = c.struct("ProgrammableTransaction", {
|
|
2627
|
+
inputs: c.vector(pt),
|
|
2628
|
+
transactions: c.vector(yt)
|
|
2629
|
+
}), bt = c.enum("TransactionKind", {
|
|
2630
|
+
ProgrammableTransaction: wt,
|
|
2631
|
+
ChangeEpoch: null,
|
|
2632
|
+
Genesis: null,
|
|
2633
|
+
ConsensusCommitPrologue: null
|
|
2634
|
+
}), St = c.enum("TransactionExpiration", {
|
|
2635
|
+
None: null,
|
|
2636
|
+
Epoch: cr()
|
|
2637
|
+
}), Tt = c.struct("StructTag", {
|
|
2638
|
+
address: J,
|
|
2639
|
+
module: c.string(),
|
|
2640
|
+
name: c.string(),
|
|
2641
|
+
typeParams: c.vector(he)
|
|
2642
|
+
}), vt = c.struct("GasData", {
|
|
2643
|
+
payment: c.vector(Se),
|
|
2644
|
+
owner: J,
|
|
2645
|
+
price: c.u64(),
|
|
2646
|
+
budget: c.u64()
|
|
2647
|
+
}), Et = c.struct("TransactionDataV1", {
|
|
2648
|
+
kind: bt,
|
|
2649
|
+
sender: J,
|
|
2650
|
+
gasData: vt,
|
|
2651
|
+
expiration: St
|
|
2652
|
+
}), xt = c.enum("TransactionData", {
|
|
2653
|
+
V1: Et
|
|
2654
|
+
}), Wn = c.enum("IntentScope", {
|
|
2655
|
+
TransactionData: null,
|
|
2656
|
+
TransactionEffects: null,
|
|
2657
|
+
CheckpointSummary: null,
|
|
2658
|
+
PersonalMessage: null
|
|
2659
|
+
}), Jn = c.enum("IntentVersion", {
|
|
2660
|
+
V0: null
|
|
2661
|
+
}), Hn = c.enum("AppId", {
|
|
2662
|
+
Sui: null
|
|
2663
|
+
}), Xn = c.struct("Intent", {
|
|
2664
|
+
scope: Wn,
|
|
2665
|
+
version: Jn,
|
|
2666
|
+
appId: Hn
|
|
2667
|
+
}), qn = c.generic(
|
|
2668
|
+
["T"],
|
|
2669
|
+
(e) => c.struct("IntentMessage<T>", {
|
|
2670
|
+
intent: Xn,
|
|
2671
|
+
value: e
|
|
2672
|
+
})
|
|
2673
|
+
), It = c.enum("CompressedSignature", {
|
|
2674
|
+
ED25519: c.fixedArray(64, c.u8()),
|
|
2675
|
+
Secp256k1: c.fixedArray(64, c.u8()),
|
|
2676
|
+
Secp256r1: c.fixedArray(64, c.u8()),
|
|
2677
|
+
ZkLogin: c.vector(c.u8())
|
|
2678
|
+
}), jt = c.enum("PublicKey", {
|
|
2679
|
+
ED25519: c.fixedArray(32, c.u8()),
|
|
2680
|
+
Secp256k1: c.fixedArray(33, c.u8()),
|
|
2681
|
+
Secp256r1: c.fixedArray(33, c.u8()),
|
|
2682
|
+
ZkLogin: c.vector(c.u8())
|
|
2683
|
+
}), Ot = c.struct("MultiSigPkMap", {
|
|
2684
|
+
pubKey: jt,
|
|
2685
|
+
weight: c.u8()
|
|
2686
|
+
}), At = c.struct("MultiSigPublicKey", {
|
|
2687
|
+
pk_map: c.vector(Ot),
|
|
2688
|
+
threshold: c.u16()
|
|
2689
|
+
}), ur = c.struct("MultiSig", {
|
|
2690
|
+
sigs: c.vector(It),
|
|
2691
|
+
bitmap: c.u16(),
|
|
2692
|
+
multisig_pk: At
|
|
2693
|
+
}), Zn = c.vector(c.u8()).transform({
|
|
2694
|
+
input: (e) => typeof e == "string" ? ae(e) : e,
|
|
2695
|
+
output: (e) => Ie(new Uint8Array(e))
|
|
2696
|
+
}), dr = c.struct("SenderSignedTransaction", {
|
|
2697
|
+
intentMessage: qn(xt),
|
|
2698
|
+
txSignatures: c.vector(Zn)
|
|
2699
|
+
}), fr = c.vector(dr, {
|
|
2700
|
+
name: "SenderSignedData"
|
|
2701
|
+
}), C = {
|
|
2702
|
+
...c,
|
|
2703
|
+
U8: c.u8(),
|
|
2704
|
+
U16: c.u16(),
|
|
2705
|
+
U32: c.u32(),
|
|
2706
|
+
U64: c.u64(),
|
|
2707
|
+
U128: c.u128(),
|
|
2708
|
+
U256: c.u256(),
|
|
2709
|
+
ULEB128: c.uleb128(),
|
|
2710
|
+
Bool: c.bool(),
|
|
2711
|
+
String: c.string(),
|
|
2712
|
+
Address: J,
|
|
2713
|
+
Argument: L,
|
|
2714
|
+
CallArg: pt,
|
|
2715
|
+
CompressedSignature: It,
|
|
2716
|
+
GasData: vt,
|
|
2717
|
+
MultiSig: ur,
|
|
2718
|
+
MultiSigPkMap: Ot,
|
|
2719
|
+
MultiSigPublicKey: At,
|
|
2720
|
+
ObjectArg: Pe,
|
|
2721
|
+
ObjectDigest: ht,
|
|
2722
|
+
ProgrammableMoveCall: mt,
|
|
2723
|
+
ProgrammableTransaction: wt,
|
|
2724
|
+
PublicKey: jt,
|
|
2725
|
+
SenderSignedData: fr,
|
|
2726
|
+
SenderSignedTransaction: dr,
|
|
2727
|
+
SharedObjectRef: gt,
|
|
2728
|
+
StructTag: Tt,
|
|
2729
|
+
SuiObjectRef: Se,
|
|
2730
|
+
Transaction: yt,
|
|
2731
|
+
TransactionData: xt,
|
|
2732
|
+
TransactionDataV1: Et,
|
|
2733
|
+
TransactionExpiration: St,
|
|
2734
|
+
TransactionKind: bt,
|
|
2735
|
+
TypeTag: he,
|
|
2736
|
+
// preserve backwards compatibility with old bcs export
|
|
2737
|
+
ser: I.ser.bind(I),
|
|
2738
|
+
de: I.de.bind(I),
|
|
2739
|
+
getTypeInterface: I.getTypeInterface.bind(I),
|
|
2740
|
+
hasType: I.hasType.bind(I),
|
|
2741
|
+
parseTypeName: I.parseTypeName.bind(I),
|
|
2742
|
+
registerAddressType: I.registerAddressType.bind(I),
|
|
2743
|
+
registerAlias: I.registerAlias.bind(I),
|
|
2744
|
+
registerBcsType: I.registerBcsType.bind(I),
|
|
2745
|
+
registerEnumType: I.registerEnumType.bind(I),
|
|
2746
|
+
registerStructType: I.registerStructType.bind(I),
|
|
2747
|
+
registerType: I.registerType.bind(I),
|
|
2748
|
+
types: I.types
|
|
2749
|
+
};
|
|
2750
|
+
I.registerBcsType("utf8string", () => c.string({ name: "utf8string" }));
|
|
2751
|
+
I.registerBcsType("unsafe_u64", () => cr());
|
|
2752
|
+
I.registerBcsType("enumKind", (e) => lt(e));
|
|
2753
|
+
[
|
|
2754
|
+
J,
|
|
2755
|
+
L,
|
|
2756
|
+
pt,
|
|
2757
|
+
It,
|
|
2758
|
+
vt,
|
|
2759
|
+
ur,
|
|
2760
|
+
Ot,
|
|
2761
|
+
At,
|
|
2762
|
+
Pe,
|
|
2763
|
+
ht,
|
|
2764
|
+
mt,
|
|
2765
|
+
wt,
|
|
2766
|
+
jt,
|
|
2767
|
+
fr,
|
|
2768
|
+
gt,
|
|
2769
|
+
Tt,
|
|
2770
|
+
Se,
|
|
2771
|
+
yt,
|
|
2772
|
+
xt,
|
|
2773
|
+
Et,
|
|
2774
|
+
St,
|
|
2775
|
+
bt,
|
|
2776
|
+
he
|
|
2777
|
+
].forEach((e) => {
|
|
2778
|
+
I.registerBcsType(e.name, () => e);
|
|
2779
|
+
});
|
|
2780
|
+
const Yn = k([
|
|
2781
|
+
h({ ImmOrOwned: se }),
|
|
2782
|
+
h({
|
|
2783
|
+
Shared: h({
|
|
2784
|
+
objectId: f(),
|
|
2785
|
+
initialSharedVersion: k([q(), f()]),
|
|
2786
|
+
mutable: U()
|
|
2787
|
+
})
|
|
2788
|
+
}),
|
|
2789
|
+
h({ Receiving: se })
|
|
2790
|
+
]), De = h({ Pure: v(q()) }), et = h({ Object: Yn }), ze = k([De, et]);
|
|
2791
|
+
function Qn(e, t) {
|
|
2792
|
+
return {
|
|
2793
|
+
Pure: Array.from(
|
|
2794
|
+
e instanceof Uint8Array ? e : ut(e) ? e.toBytes() : (
|
|
2795
|
+
// NOTE: We explicitly set this to be growable to infinity, because we have maxSize validation at the builder-level:
|
|
2796
|
+
C.ser(t, e, { maxSize: 1 / 0 }).toBytes()
|
|
2797
|
+
)
|
|
2798
|
+
)
|
|
2799
|
+
};
|
|
2800
|
+
}
|
|
2801
|
+
const R = {
|
|
2802
|
+
Pure: Qn,
|
|
2803
|
+
ObjectRef({ objectId: e, digest: t, version: r }) {
|
|
2804
|
+
return {
|
|
2805
|
+
Object: {
|
|
2806
|
+
ImmOrOwned: {
|
|
2807
|
+
digest: t,
|
|
2808
|
+
version: r,
|
|
2809
|
+
objectId: M(e)
|
|
2810
|
+
}
|
|
2811
|
+
}
|
|
2812
|
+
};
|
|
2813
|
+
},
|
|
2814
|
+
SharedObjectRef({ objectId: e, mutable: t, initialSharedVersion: r }) {
|
|
2815
|
+
return {
|
|
2816
|
+
Object: {
|
|
2817
|
+
Shared: {
|
|
2818
|
+
mutable: t,
|
|
2819
|
+
initialSharedVersion: r,
|
|
2820
|
+
objectId: M(e)
|
|
2821
|
+
}
|
|
2822
|
+
}
|
|
2823
|
+
};
|
|
2824
|
+
},
|
|
2825
|
+
ReceivingRef({ objectId: e, digest: t, version: r }) {
|
|
2826
|
+
return {
|
|
2827
|
+
Object: {
|
|
2828
|
+
Receiving: {
|
|
2829
|
+
digest: t,
|
|
2830
|
+
version: r,
|
|
2831
|
+
objectId: M(e)
|
|
2832
|
+
}
|
|
2833
|
+
}
|
|
2834
|
+
};
|
|
2835
|
+
}
|
|
2836
|
+
};
|
|
2837
|
+
function Vt(e) {
|
|
2838
|
+
return typeof e == "string" ? M(e) : "ImmOrOwned" in e.Object ? M(e.Object.ImmOrOwned.objectId) : "Receiving" in e.Object ? M(e.Object.Receiving.objectId) : M(e.Object.Shared.objectId);
|
|
2839
|
+
}
|
|
2840
|
+
function ei(e) {
|
|
2841
|
+
return typeof e == "object" && "Object" in e && "Shared" in e.Object ? e.Object.Shared : void 0;
|
|
2842
|
+
}
|
|
2843
|
+
function ti(e) {
|
|
2844
|
+
var t;
|
|
2845
|
+
return ((t = ei(e)) == null ? void 0 : t.mutable) ?? !1;
|
|
2846
|
+
}
|
|
2847
|
+
function B(e, t) {
|
|
2848
|
+
return Lt(e, t);
|
|
2849
|
+
}
|
|
2850
|
+
const ri = (e) => k([h({ None: k([b(!0), b(null)]) }), h({ Some: e })]), Te = k([
|
|
2851
|
+
h({
|
|
2852
|
+
kind: b("Input"),
|
|
2853
|
+
index: q(),
|
|
2854
|
+
value: w(Ze()),
|
|
2855
|
+
type: w(b("object"))
|
|
2856
|
+
}),
|
|
2857
|
+
h({
|
|
2858
|
+
kind: b("Input"),
|
|
2859
|
+
index: q(),
|
|
2860
|
+
value: w(Ze()),
|
|
2861
|
+
type: b("pure")
|
|
2862
|
+
})
|
|
2863
|
+
]), ni = [
|
|
2864
|
+
Te,
|
|
2865
|
+
h({ kind: b("GasCoin") }),
|
|
2866
|
+
h({ kind: b("Result"), index: q() }),
|
|
2867
|
+
h({
|
|
2868
|
+
kind: b("NestedResult"),
|
|
2869
|
+
index: q(),
|
|
2870
|
+
resultIndex: q()
|
|
2871
|
+
})
|
|
2872
|
+
], re = k([...ni]), lr = h({
|
|
2873
|
+
kind: b("MoveCall"),
|
|
2874
|
+
target: P("target", f().validator),
|
|
2875
|
+
typeArguments: v(f()),
|
|
2876
|
+
arguments: v(re)
|
|
2877
|
+
}), hr = h({
|
|
2878
|
+
kind: b("TransferObjects"),
|
|
2879
|
+
objects: v(re),
|
|
2880
|
+
address: re
|
|
2881
|
+
}), gr = h({
|
|
2882
|
+
kind: b("SplitCoins"),
|
|
2883
|
+
coin: re,
|
|
2884
|
+
amounts: v(re)
|
|
2885
|
+
}), pr = h({
|
|
2886
|
+
kind: b("MergeCoins"),
|
|
2887
|
+
destination: re,
|
|
2888
|
+
sources: v(re)
|
|
2889
|
+
}), mr = h({
|
|
2890
|
+
kind: b("MakeMoveVec"),
|
|
2891
|
+
// TODO: ideally we should use `TypeTag` instead of `record()` here,
|
|
2892
|
+
// but TypeTag is recursively defined and it's tricky to define a
|
|
2893
|
+
// recursive struct in superstruct
|
|
2894
|
+
type: w(ri(H(f(), Ht()))),
|
|
2895
|
+
objects: v(re)
|
|
2896
|
+
}), yr = h({
|
|
2897
|
+
kind: b("Publish"),
|
|
2898
|
+
modules: v(v(q())),
|
|
2899
|
+
dependencies: v(f())
|
|
2900
|
+
}), wr = h({
|
|
2901
|
+
kind: b("Upgrade"),
|
|
2902
|
+
modules: v(v(q())),
|
|
2903
|
+
dependencies: v(f()),
|
|
2904
|
+
packageId: f(),
|
|
2905
|
+
ticket: re
|
|
2906
|
+
}), ii = [
|
|
2907
|
+
lr,
|
|
2908
|
+
hr,
|
|
2909
|
+
gr,
|
|
2910
|
+
pr,
|
|
2911
|
+
yr,
|
|
2912
|
+
wr,
|
|
2913
|
+
mr
|
|
2914
|
+
], si = k([...ii]), ce = {
|
|
2915
|
+
MoveCall(e) {
|
|
2916
|
+
return B(
|
|
2917
|
+
{
|
|
2918
|
+
kind: "MoveCall",
|
|
2919
|
+
target: e.target,
|
|
2920
|
+
arguments: e.arguments ?? [],
|
|
2921
|
+
typeArguments: e.typeArguments ?? []
|
|
2922
|
+
},
|
|
2923
|
+
lr
|
|
2924
|
+
);
|
|
2925
|
+
},
|
|
2926
|
+
TransferObjects(e, t) {
|
|
2927
|
+
return t.kind === "Input" && t.type === "pure" && typeof t.value != "object" && (t.value = R.Pure(C.Address.serialize(t.value))), B({ kind: "TransferObjects", objects: e, address: t }, hr);
|
|
2928
|
+
},
|
|
2929
|
+
SplitCoins(e, t) {
|
|
2930
|
+
return t.forEach((r) => {
|
|
2931
|
+
r.kind === "Input" && r.type === "pure" && typeof r.value != "object" && (r.value = R.Pure(C.U64.serialize(r.value)));
|
|
2932
|
+
}), B(
|
|
2933
|
+
{
|
|
2934
|
+
kind: "SplitCoins",
|
|
2935
|
+
coin: e,
|
|
2936
|
+
amounts: t
|
|
2937
|
+
},
|
|
2938
|
+
gr
|
|
2939
|
+
);
|
|
2940
|
+
},
|
|
2941
|
+
MergeCoins(e, t) {
|
|
2942
|
+
return B({ kind: "MergeCoins", destination: e, sources: t }, pr);
|
|
2943
|
+
},
|
|
2944
|
+
Publish({
|
|
2945
|
+
modules: e,
|
|
2946
|
+
dependencies: t
|
|
2947
|
+
}) {
|
|
2948
|
+
return B(
|
|
2949
|
+
{
|
|
2950
|
+
kind: "Publish",
|
|
2951
|
+
modules: e.map(
|
|
2952
|
+
(r) => typeof r == "string" ? Array.from(ae(r)) : r
|
|
2953
|
+
),
|
|
2954
|
+
dependencies: t.map((r) => be(r))
|
|
2955
|
+
},
|
|
2956
|
+
yr
|
|
2957
|
+
);
|
|
2958
|
+
},
|
|
2959
|
+
Upgrade({
|
|
2960
|
+
modules: e,
|
|
2961
|
+
dependencies: t,
|
|
2962
|
+
packageId: r,
|
|
2963
|
+
ticket: n
|
|
2964
|
+
}) {
|
|
2965
|
+
return B(
|
|
2966
|
+
{
|
|
2967
|
+
kind: "Upgrade",
|
|
2968
|
+
modules: e.map(
|
|
2969
|
+
(i) => typeof i == "string" ? Array.from(ae(i)) : i
|
|
2970
|
+
),
|
|
2971
|
+
dependencies: t.map((i) => be(i)),
|
|
2972
|
+
packageId: r,
|
|
2973
|
+
ticket: n
|
|
2974
|
+
},
|
|
2975
|
+
wr
|
|
2976
|
+
);
|
|
2977
|
+
},
|
|
2978
|
+
MakeMoveVec({
|
|
2979
|
+
type: e,
|
|
2980
|
+
objects: t
|
|
2981
|
+
}) {
|
|
2982
|
+
return B(
|
|
2983
|
+
{
|
|
2984
|
+
kind: "MakeMoveVec",
|
|
2985
|
+
type: e ? { Some: ee.parseFromStr(e) } : { None: null },
|
|
2986
|
+
objects: t
|
|
2987
|
+
},
|
|
2988
|
+
mr
|
|
2989
|
+
);
|
|
2990
|
+
}
|
|
2991
|
+
};
|
|
2992
|
+
function ai(e) {
|
|
2993
|
+
function t(r, n) {
|
|
2994
|
+
return e(r, n);
|
|
2995
|
+
}
|
|
2996
|
+
return t.u8 = (r) => e(C.U8.serialize(r)), t.u16 = (r) => e(C.U16.serialize(r)), t.u32 = (r) => e(C.U32.serialize(r)), t.u64 = (r) => e(C.U64.serialize(r)), t.u128 = (r) => e(C.U128.serialize(r)), t.u256 = (r) => e(C.U256.serialize(r)), t.bool = (r) => e(C.Bool.serialize(r)), t.string = (r) => e(C.String.serialize(r)), t.address = (r) => e(C.Address.serialize(r)), t.id = t.address, t;
|
|
2997
|
+
}
|
|
2998
|
+
function oi(e, t) {
|
|
2999
|
+
const r = Array.from(`${e}::`).map((i) => i.charCodeAt(0)), n = new Uint8Array(r.length + t.length);
|
|
3000
|
+
return n.set(r), n.set(t, r.length), jr(n, { dkLen: 32 });
|
|
3001
|
+
}
|
|
3002
|
+
const ci = w(
|
|
3003
|
+
O(
|
|
3004
|
+
k([h({ Epoch: q() }), h({ None: k([b(!0), b(null)]) })])
|
|
3005
|
+
)
|
|
3006
|
+
), Gt = P("StringEncodedBigint", (e) => {
|
|
3007
|
+
if (!["string", "number", "bigint"].includes(typeof e))
|
|
3008
|
+
return !1;
|
|
3009
|
+
try {
|
|
3010
|
+
return BigInt(e), !0;
|
|
3011
|
+
} catch {
|
|
3012
|
+
return !1;
|
|
3013
|
+
}
|
|
3014
|
+
}), ui = h({
|
|
3015
|
+
budget: w(Gt),
|
|
3016
|
+
price: w(Gt),
|
|
3017
|
+
payment: w(v(se)),
|
|
3018
|
+
owner: w(f())
|
|
3019
|
+
}), ke = h({
|
|
3020
|
+
version: b(1),
|
|
3021
|
+
sender: w(f()),
|
|
3022
|
+
expiration: ci,
|
|
3023
|
+
gasConfig: ui,
|
|
3024
|
+
inputs: v(Te),
|
|
3025
|
+
transactions: v(si)
|
|
3026
|
+
});
|
|
3027
|
+
function Ft(e) {
|
|
3028
|
+
return M(e).replace("0x", "");
|
|
3029
|
+
}
|
|
3030
|
+
class te {
|
|
3031
|
+
constructor(t) {
|
|
3032
|
+
this.version = 1, this.sender = t == null ? void 0 : t.sender, this.expiration = t == null ? void 0 : t.expiration, this.gasConfig = (t == null ? void 0 : t.gasConfig) ?? {}, this.inputs = (t == null ? void 0 : t.inputs) ?? [], this.transactions = (t == null ? void 0 : t.transactions) ?? [];
|
|
3033
|
+
}
|
|
3034
|
+
static fromKindBytes(t) {
|
|
3035
|
+
const r = C.TransactionKind.parse(t), n = "ProgrammableTransaction" in r ? r.ProgrammableTransaction : null;
|
|
3036
|
+
if (!n)
|
|
3037
|
+
throw new Error("Unable to deserialize from bytes.");
|
|
3038
|
+
const i = B(
|
|
3039
|
+
{
|
|
3040
|
+
version: 1,
|
|
3041
|
+
gasConfig: {},
|
|
3042
|
+
inputs: n.inputs.map(
|
|
3043
|
+
(s, a) => B(
|
|
3044
|
+
{
|
|
3045
|
+
kind: "Input",
|
|
3046
|
+
value: s,
|
|
3047
|
+
index: a,
|
|
3048
|
+
type: N(s, De) ? "pure" : "object"
|
|
3049
|
+
},
|
|
3050
|
+
Te
|
|
3051
|
+
)
|
|
3052
|
+
),
|
|
3053
|
+
transactions: n.transactions
|
|
3054
|
+
},
|
|
3055
|
+
ke
|
|
3056
|
+
);
|
|
3057
|
+
return te.restore(i);
|
|
3058
|
+
}
|
|
3059
|
+
static fromBytes(t) {
|
|
3060
|
+
var a;
|
|
3061
|
+
const r = C.TransactionData.parse(t), n = r == null ? void 0 : r.V1, i = "ProgrammableTransaction" in n.kind ? (a = n == null ? void 0 : n.kind) == null ? void 0 : a.ProgrammableTransaction : null;
|
|
3062
|
+
if (!n || !i)
|
|
3063
|
+
throw new Error("Unable to deserialize from bytes.");
|
|
3064
|
+
const s = B(
|
|
3065
|
+
{
|
|
3066
|
+
version: 1,
|
|
3067
|
+
sender: n.sender,
|
|
3068
|
+
expiration: n.expiration,
|
|
3069
|
+
gasConfig: n.gasData,
|
|
3070
|
+
inputs: i.inputs.map(
|
|
3071
|
+
(o, u) => B(
|
|
3072
|
+
{
|
|
3073
|
+
kind: "Input",
|
|
3074
|
+
value: o,
|
|
3075
|
+
index: u,
|
|
3076
|
+
type: N(o, De) ? "pure" : "object"
|
|
3077
|
+
},
|
|
3078
|
+
Te
|
|
3079
|
+
)
|
|
3080
|
+
),
|
|
3081
|
+
transactions: i.transactions
|
|
3082
|
+
},
|
|
3083
|
+
ke
|
|
3084
|
+
);
|
|
3085
|
+
return te.restore(s);
|
|
3086
|
+
}
|
|
3087
|
+
static restore(t) {
|
|
3088
|
+
qe(t, ke);
|
|
3089
|
+
const r = new te();
|
|
3090
|
+
return Object.assign(r, t), r;
|
|
3091
|
+
}
|
|
3092
|
+
/**
|
|
3093
|
+
* Generate transaction digest.
|
|
3094
|
+
*
|
|
3095
|
+
* @param bytes BCS serialized transaction data
|
|
3096
|
+
* @returns transaction digest.
|
|
3097
|
+
*/
|
|
3098
|
+
static getDigestFromBytes(t) {
|
|
3099
|
+
const r = oi("TransactionData", t);
|
|
3100
|
+
return xe(r);
|
|
3101
|
+
}
|
|
3102
|
+
build({
|
|
3103
|
+
maxSizeBytes: t = 1 / 0,
|
|
3104
|
+
overrides: r,
|
|
3105
|
+
onlyTransactionKind: n
|
|
3106
|
+
} = {}) {
|
|
3107
|
+
const i = this.inputs.map((l) => (qe(l.value, ze), l.value)), s = {
|
|
3108
|
+
ProgrammableTransaction: {
|
|
3109
|
+
inputs: i,
|
|
3110
|
+
transactions: this.transactions
|
|
3111
|
+
}
|
|
3112
|
+
};
|
|
3113
|
+
if (n)
|
|
3114
|
+
return C.TransactionKind.serialize(s, { maxSize: t }).toBytes();
|
|
3115
|
+
const a = (r == null ? void 0 : r.expiration) ?? this.expiration, o = (r == null ? void 0 : r.sender) ?? this.sender, u = { ...this.gasConfig, ...r == null ? void 0 : r.gasConfig };
|
|
3116
|
+
if (!o)
|
|
3117
|
+
throw new Error("Missing transaction sender");
|
|
3118
|
+
if (!u.budget)
|
|
3119
|
+
throw new Error("Missing gas budget");
|
|
3120
|
+
if (!u.payment)
|
|
3121
|
+
throw new Error("Missing gas payment");
|
|
3122
|
+
if (!u.price)
|
|
3123
|
+
throw new Error("Missing gas price");
|
|
3124
|
+
const d = {
|
|
3125
|
+
sender: Ft(o),
|
|
3126
|
+
expiration: a || { None: !0 },
|
|
3127
|
+
gasData: {
|
|
3128
|
+
payment: u.payment,
|
|
3129
|
+
owner: Ft(this.gasConfig.owner ?? o),
|
|
3130
|
+
price: BigInt(u.price),
|
|
3131
|
+
budget: BigInt(u.budget)
|
|
3132
|
+
},
|
|
3133
|
+
kind: {
|
|
3134
|
+
ProgrammableTransaction: {
|
|
3135
|
+
inputs: i,
|
|
3136
|
+
transactions: this.transactions
|
|
3137
|
+
}
|
|
3138
|
+
}
|
|
3139
|
+
};
|
|
3140
|
+
return C.TransactionData.serialize(
|
|
3141
|
+
{ V1: d },
|
|
3142
|
+
{ maxSize: t }
|
|
3143
|
+
).toBytes();
|
|
3144
|
+
}
|
|
3145
|
+
getDigest() {
|
|
3146
|
+
const t = this.build({ onlyTransactionKind: !1 });
|
|
3147
|
+
return te.getDigestFromBytes(t);
|
|
3148
|
+
}
|
|
3149
|
+
snapshot() {
|
|
3150
|
+
return B(this, ke);
|
|
3151
|
+
}
|
|
3152
|
+
}
|
|
3153
|
+
var kt = (e, t, r) => {
|
|
3154
|
+
if (!t.has(e))
|
|
3155
|
+
throw TypeError("Cannot " + r);
|
|
3156
|
+
}, x = (e, t, r) => (kt(e, t, "read from private field"), r ? r.call(e) : t.get(e)), Q = (e, t, r) => {
|
|
3157
|
+
if (t.has(e))
|
|
3158
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
3159
|
+
t instanceof WeakSet ? t.add(e) : t.set(e, r);
|
|
3160
|
+
}, _e = (e, t, r, n) => (kt(e, t, "write to private field"), t.set(e, r), r), $ = (e, t, r) => (kt(e, t, "access private method"), r), T, me, $e, ye, Me, oe, de, _t, br, Ct, Sr, $t, Tr, Mt, vr, Ue, tt;
|
|
3161
|
+
const di = {
|
|
3162
|
+
maxPureArgumentSize: 16 * 1024,
|
|
3163
|
+
maxTxGas: 5e10,
|
|
3164
|
+
maxGasObjects: 256,
|
|
3165
|
+
maxTxSizeBytes: 128 * 1024
|
|
3166
|
+
};
|
|
3167
|
+
function fi(e) {
|
|
3168
|
+
const t = { kind: "Result", index: e }, r = [], n = (i) => r[i] ?? (r[i] = {
|
|
3169
|
+
kind: "NestedResult",
|
|
3170
|
+
index: e,
|
|
3171
|
+
resultIndex: i
|
|
3172
|
+
});
|
|
3173
|
+
return new Proxy(t, {
|
|
3174
|
+
set() {
|
|
3175
|
+
throw new Error(
|
|
3176
|
+
"The transaction result is a proxy, and does not support setting properties directly"
|
|
3177
|
+
);
|
|
3178
|
+
},
|
|
3179
|
+
// TODO: Instead of making this return a concrete argument, we should ideally
|
|
3180
|
+
// make it reference-based (so that this gets resolved at build-time), which
|
|
3181
|
+
// allows re-ordering transactions.
|
|
3182
|
+
get(i, s) {
|
|
3183
|
+
if (s in i)
|
|
3184
|
+
return Reflect.get(i, s);
|
|
3185
|
+
if (s === Symbol.iterator)
|
|
3186
|
+
return function* () {
|
|
3187
|
+
let o = 0;
|
|
3188
|
+
for (; ; )
|
|
3189
|
+
yield n(o), o++;
|
|
3190
|
+
};
|
|
3191
|
+
if (typeof s == "symbol")
|
|
3192
|
+
return;
|
|
3193
|
+
const a = parseInt(s, 10);
|
|
3194
|
+
if (!(Number.isNaN(a) || a < 0))
|
|
3195
|
+
return n(a);
|
|
3196
|
+
}
|
|
3197
|
+
});
|
|
3198
|
+
}
|
|
3199
|
+
function li(e) {
|
|
3200
|
+
const t = at(e);
|
|
3201
|
+
return t ? t.Struct.address === "0x2" && t.Struct.module === "transfer" && t.Struct.name === "Receiving" : !1;
|
|
3202
|
+
}
|
|
3203
|
+
function ve(e) {
|
|
3204
|
+
if (!e.client)
|
|
3205
|
+
throw new Error(
|
|
3206
|
+
"No provider passed to Transaction#build, but transaction data was not sufficient to build offline."
|
|
3207
|
+
);
|
|
3208
|
+
return e.client;
|
|
3209
|
+
}
|
|
3210
|
+
const hi = Symbol.for("@mysten/transaction"), He = {
|
|
3211
|
+
// The maximum gas that is allowed.
|
|
3212
|
+
maxTxGas: "max_tx_gas",
|
|
3213
|
+
// The maximum number of gas objects that can be selected for one transaction.
|
|
3214
|
+
maxGasObjects: "max_gas_payment_objects",
|
|
3215
|
+
// The maximum size (in bytes) that the transaction can be:
|
|
3216
|
+
maxTxSizeBytes: "max_tx_size_bytes",
|
|
3217
|
+
// The maximum size (in bytes) that pure arguments can be:
|
|
3218
|
+
maxPureArgumentSize: "max_pure_argument_size"
|
|
3219
|
+
}, gi = 1000n, pi = 50, mi = (e, t) => Array.from(
|
|
3220
|
+
{ length: Math.ceil(e.length / t) },
|
|
3221
|
+
(r, n) => e.slice(n * t, n * t + t)
|
|
3222
|
+
), rt = class {
|
|
3223
|
+
constructor(e) {
|
|
3224
|
+
Q(this, me), Q(this, ye), Q(this, oe), Q(this, _t), Q(this, Ct), Q(this, $t), Q(this, Mt), Q(this, Ue), Q(this, T, void 0), _e(this, T, new te(
|
|
3225
|
+
e ? e.blockData : void 0
|
|
3226
|
+
));
|
|
3227
|
+
}
|
|
3228
|
+
/**
|
|
3229
|
+
* Converts from a serialize transaction kind (built with `build({ onlyTransactionKind: true })`) to a `Transaction` class.
|
|
3230
|
+
* Supports either a byte array, or base64-encoded bytes.
|
|
3231
|
+
*/
|
|
3232
|
+
static fromKind(e) {
|
|
3233
|
+
const t = new rt();
|
|
3234
|
+
return _e(t, T, te.fromKindBytes(
|
|
3235
|
+
typeof e == "string" ? ae(e) : e
|
|
3236
|
+
)), t;
|
|
3237
|
+
}
|
|
3238
|
+
/**
|
|
3239
|
+
* Converts from a serialized transaction format to a `Transaction` class.
|
|
3240
|
+
* There are two supported serialized formats:
|
|
3241
|
+
* - A string returned from `Transaction#serialize`. The serialized format must be compatible, or it will throw an error.
|
|
3242
|
+
* - A byte array (or base64-encoded bytes) containing BCS transaction data.
|
|
3243
|
+
*/
|
|
3244
|
+
static from(e) {
|
|
3245
|
+
const t = new rt();
|
|
3246
|
+
return typeof e != "string" || !e.startsWith("{") ? _e(t, T, te.fromBytes(
|
|
3247
|
+
typeof e == "string" ? ae(e) : e
|
|
3248
|
+
)) : _e(t, T, te.restore(JSON.parse(e))), t;
|
|
3249
|
+
}
|
|
3250
|
+
setSender(e) {
|
|
3251
|
+
x(this, T).sender = e;
|
|
3252
|
+
}
|
|
3253
|
+
/**
|
|
3254
|
+
* Sets the sender only if it has not already been set.
|
|
3255
|
+
* This is useful for sponsored transaction flows where the sender may not be the same as the signer address.
|
|
3256
|
+
*/
|
|
3257
|
+
setSenderIfNotSet(e) {
|
|
3258
|
+
x(this, T).sender || (x(this, T).sender = e);
|
|
3259
|
+
}
|
|
3260
|
+
setExpiration(e) {
|
|
3261
|
+
x(this, T).expiration = e;
|
|
3262
|
+
}
|
|
3263
|
+
setGasPrice(e) {
|
|
3264
|
+
x(this, T).gasConfig.price = String(e);
|
|
3265
|
+
}
|
|
3266
|
+
setGasBudget(e) {
|
|
3267
|
+
x(this, T).gasConfig.budget = String(e);
|
|
3268
|
+
}
|
|
3269
|
+
setGasOwner(e) {
|
|
3270
|
+
x(this, T).gasConfig.owner = e;
|
|
3271
|
+
}
|
|
3272
|
+
setGasPayment(e) {
|
|
3273
|
+
x(this, T).gasConfig.payment = e.map((t) => Kt(t, se));
|
|
3274
|
+
}
|
|
3275
|
+
/** Get a snapshot of the transaction data, in JSON form: */
|
|
3276
|
+
get blockData() {
|
|
3277
|
+
return x(this, T).snapshot();
|
|
3278
|
+
}
|
|
3279
|
+
// Used to brand transaction classes so that they can be identified, even between multiple copies
|
|
3280
|
+
// of the builder.
|
|
3281
|
+
get [hi]() {
|
|
3282
|
+
return !0;
|
|
3283
|
+
}
|
|
3284
|
+
// Temporary workaround for the wallet interface accidentally serializing transaction blocks via postMessage
|
|
3285
|
+
get pure() {
|
|
3286
|
+
return Object.defineProperty(this, "pure", {
|
|
3287
|
+
enumerable: !1,
|
|
3288
|
+
value: ai((e, t) => ut(e) ? $(this, me, $e).call(this, "pure", {
|
|
3289
|
+
Pure: Array.from(e.toBytes())
|
|
3290
|
+
}) : $(this, me, $e).call(this, "pure", e instanceof Uint8Array ? R.Pure(e) : t ? R.Pure(e, t) : e))
|
|
3291
|
+
}), this.pure;
|
|
3292
|
+
}
|
|
3293
|
+
/** Returns an argument for the gas coin, to be used in a transaction. */
|
|
3294
|
+
get gas() {
|
|
3295
|
+
return { kind: "GasCoin" };
|
|
3296
|
+
}
|
|
3297
|
+
/**
|
|
3298
|
+
* Add a new object input to the transaction.
|
|
3299
|
+
*/
|
|
3300
|
+
object(e) {
|
|
3301
|
+
if (typeof e == "object" && "kind" in e)
|
|
3302
|
+
return e;
|
|
3303
|
+
const t = Vt(e), r = x(this, T).inputs.find(
|
|
3304
|
+
(n) => n.type === "object" && t === Vt(n.value)
|
|
3305
|
+
);
|
|
3306
|
+
return r && N(r.value, et) && "Shared" in r.value.Object && N(e, et) && "Shared" in e.Object && (r.value.Object.Shared.mutable = r.value.Object.Shared.mutable || e.Object.Shared.mutable), r ?? $(this, me, $e).call(this, "object", typeof e == "string" ? M(e) : e);
|
|
3307
|
+
}
|
|
3308
|
+
/**
|
|
3309
|
+
* Add a new object input to the transaction using the fully-resolved object reference.
|
|
3310
|
+
* If you only have an object ID, use `builder.object(id)` instead.
|
|
3311
|
+
*/
|
|
3312
|
+
objectRef(...e) {
|
|
3313
|
+
return this.object(R.ObjectRef(...e));
|
|
3314
|
+
}
|
|
3315
|
+
/**
|
|
3316
|
+
* Add a new receiving input to the transaction using the fully-resolved object reference.
|
|
3317
|
+
* If you only have an object ID, use `builder.object(id)` instead.
|
|
3318
|
+
*/
|
|
3319
|
+
receivingRef(...e) {
|
|
3320
|
+
return this.object(R.ReceivingRef(...e));
|
|
3321
|
+
}
|
|
3322
|
+
/**
|
|
3323
|
+
* Add a new shared object input to the transaction using the fully-resolved shared object reference.
|
|
3324
|
+
* If you only have an object ID, use `builder.object(id)` instead.
|
|
3325
|
+
*/
|
|
3326
|
+
sharedObjectRef(...e) {
|
|
3327
|
+
return this.object(R.SharedObjectRef(...e));
|
|
3328
|
+
}
|
|
3329
|
+
/** Add a transaction to the transaction block. */
|
|
3330
|
+
add(e) {
|
|
3331
|
+
const t = x(this, T).transactions.push(e);
|
|
3332
|
+
return fi(t - 1);
|
|
3333
|
+
}
|
|
3334
|
+
// Method shorthands:
|
|
3335
|
+
splitCoins(e, t) {
|
|
3336
|
+
return this.add(
|
|
3337
|
+
ce.SplitCoins(
|
|
3338
|
+
typeof e == "string" ? this.object(e) : e,
|
|
3339
|
+
t.map(
|
|
3340
|
+
(r) => typeof r == "number" || typeof r == "bigint" || typeof r == "string" ? this.pure.u64(r) : $(this, ye, Me).call(this, r)
|
|
3341
|
+
)
|
|
3342
|
+
)
|
|
3343
|
+
);
|
|
3344
|
+
}
|
|
3345
|
+
mergeCoins(e, t) {
|
|
3346
|
+
return this.add(
|
|
3347
|
+
ce.MergeCoins(
|
|
3348
|
+
typeof e == "string" ? this.object(e) : e,
|
|
3349
|
+
t.map((r) => typeof r == "string" ? this.object(r) : r)
|
|
3350
|
+
)
|
|
3351
|
+
);
|
|
3352
|
+
}
|
|
3353
|
+
publish({ modules: e, dependencies: t }) {
|
|
3354
|
+
return this.add(
|
|
3355
|
+
ce.Publish({
|
|
3356
|
+
modules: e,
|
|
3357
|
+
dependencies: t
|
|
3358
|
+
})
|
|
3359
|
+
);
|
|
3360
|
+
}
|
|
3361
|
+
upgrade({
|
|
3362
|
+
modules: e,
|
|
3363
|
+
dependencies: t,
|
|
3364
|
+
packageId: r,
|
|
3365
|
+
ticket: n
|
|
3366
|
+
}) {
|
|
3367
|
+
return this.add(
|
|
3368
|
+
ce.Upgrade({
|
|
3369
|
+
modules: e,
|
|
3370
|
+
dependencies: t,
|
|
3371
|
+
packageId: r,
|
|
3372
|
+
ticket: typeof n == "string" ? this.object(n) : n
|
|
3373
|
+
})
|
|
3374
|
+
);
|
|
3375
|
+
}
|
|
3376
|
+
moveCall({
|
|
3377
|
+
arguments: e,
|
|
3378
|
+
typeArguments: t,
|
|
3379
|
+
target: r
|
|
3380
|
+
}) {
|
|
3381
|
+
return this.add(
|
|
3382
|
+
ce.MoveCall({
|
|
3383
|
+
arguments: e == null ? void 0 : e.map((n) => $(this, ye, Me).call(this, n)),
|
|
3384
|
+
typeArguments: t,
|
|
3385
|
+
target: r
|
|
3386
|
+
})
|
|
3387
|
+
);
|
|
3388
|
+
}
|
|
3389
|
+
transferObjects(e, t) {
|
|
3390
|
+
return this.add(
|
|
3391
|
+
ce.TransferObjects(
|
|
3392
|
+
e.map((r) => typeof r == "string" ? this.object(r) : r),
|
|
3393
|
+
typeof t == "string" ? this.pure.address(t) : $(this, ye, Me).call(this, t)
|
|
3394
|
+
)
|
|
3395
|
+
);
|
|
3396
|
+
}
|
|
3397
|
+
makeMoveVec({
|
|
3398
|
+
type: e,
|
|
3399
|
+
objects: t
|
|
3400
|
+
}) {
|
|
3401
|
+
return this.add(
|
|
3402
|
+
ce.MakeMoveVec({
|
|
3403
|
+
type: e,
|
|
3404
|
+
objects: t.map((r) => typeof r == "string" ? this.object(r) : r)
|
|
3405
|
+
})
|
|
3406
|
+
);
|
|
3407
|
+
}
|
|
3408
|
+
/**
|
|
3409
|
+
* Serialize the transaction to a string so that it can be sent to a separate context.
|
|
3410
|
+
* This is different from `build` in that it does not serialize to BCS bytes, and instead
|
|
3411
|
+
* uses a separate format that is unique to the transaction builder. This allows
|
|
3412
|
+
* us to serialize partially-complete transactions, that can then be completed and
|
|
3413
|
+
* built in a separate context.
|
|
3414
|
+
*
|
|
3415
|
+
* For example, a dapp can construct a transaction, but not provide gas objects
|
|
3416
|
+
* or a gas budget. The transaction then can be sent to the wallet, where this
|
|
3417
|
+
* information is automatically filled in (e.g. by querying for coin objects
|
|
3418
|
+
* and performing a dry run).
|
|
3419
|
+
*/
|
|
3420
|
+
serialize() {
|
|
3421
|
+
return JSON.stringify(x(this, T).snapshot());
|
|
3422
|
+
}
|
|
3423
|
+
/** Build the transaction to BCS bytes, and sign it with the provided keypair. */
|
|
3424
|
+
async sign(e) {
|
|
3425
|
+
const { signer: t, ...r } = e, n = await this.build(r);
|
|
3426
|
+
return t.signTransactionBlock(n);
|
|
3427
|
+
}
|
|
3428
|
+
/** Build the transaction to BCS bytes. */
|
|
3429
|
+
async build(e = {}) {
|
|
3430
|
+
return await $(this, Ue, tt).call(this, e), x(this, T).build({
|
|
3431
|
+
maxSizeBytes: $(this, oe, de).call(this, "maxTxSizeBytes", e),
|
|
3432
|
+
onlyTransactionKind: e.onlyTransactionKind
|
|
3433
|
+
});
|
|
3434
|
+
}
|
|
3435
|
+
/** Derive transaction digest */
|
|
3436
|
+
async getDigest(e = {}) {
|
|
3437
|
+
return await $(this, Ue, tt).call(this, e), x(this, T).getDigest();
|
|
3438
|
+
}
|
|
3439
|
+
};
|
|
3440
|
+
let Xe = rt;
|
|
3441
|
+
T = /* @__PURE__ */ new WeakMap();
|
|
3442
|
+
me = /* @__PURE__ */ new WeakSet();
|
|
3443
|
+
$e = function(e, t) {
|
|
3444
|
+
const r = x(this, T).inputs.length, n = B(
|
|
3445
|
+
{
|
|
3446
|
+
kind: "Input",
|
|
3447
|
+
// bigints can't be serialized to JSON, so just string-convert them here:
|
|
3448
|
+
value: typeof t == "bigint" ? String(t) : t,
|
|
3449
|
+
index: r,
|
|
3450
|
+
type: e
|
|
3451
|
+
},
|
|
3452
|
+
Te
|
|
3453
|
+
);
|
|
3454
|
+
return x(this, T).inputs.push(n), n;
|
|
3455
|
+
};
|
|
3456
|
+
ye = /* @__PURE__ */ new WeakSet();
|
|
3457
|
+
Me = function(e) {
|
|
3458
|
+
return ut(e) ? this.pure(e) : e;
|
|
3459
|
+
};
|
|
3460
|
+
oe = /* @__PURE__ */ new WeakSet();
|
|
3461
|
+
de = function(e, { protocolConfig: t, limits: r }) {
|
|
3462
|
+
if (r && typeof r[e] == "number")
|
|
3463
|
+
return r[e];
|
|
3464
|
+
if (!t)
|
|
3465
|
+
return di[e];
|
|
3466
|
+
const n = t == null ? void 0 : t.attributes[He[e]];
|
|
3467
|
+
if (!n)
|
|
3468
|
+
throw new Error(`Missing expected protocol config: "${He[e]}"`);
|
|
3469
|
+
const i = "u64" in n ? n.u64 : "u32" in n ? n.u32 : n.f64;
|
|
3470
|
+
if (!i)
|
|
3471
|
+
throw new Error(`Unexpected protocol config value found for: "${He[e]}"`);
|
|
3472
|
+
return Number(i);
|
|
3473
|
+
};
|
|
3474
|
+
_t = /* @__PURE__ */ new WeakSet();
|
|
3475
|
+
br = function(e) {
|
|
3476
|
+
const t = $(this, oe, de).call(this, "maxPureArgumentSize", e);
|
|
3477
|
+
x(this, T).inputs.forEach((r, n) => {
|
|
3478
|
+
if (N(r.value, De) && r.value.Pure.length > t)
|
|
3479
|
+
throw new Error(
|
|
3480
|
+
`Input at index ${n} is too large, max pure input size is ${t} bytes, got ${r.value.Pure.length} bytes`
|
|
3481
|
+
);
|
|
3482
|
+
});
|
|
3483
|
+
};
|
|
3484
|
+
Ct = /* @__PURE__ */ new WeakSet();
|
|
3485
|
+
Sr = async function(e) {
|
|
3486
|
+
if (x(this, T).gasConfig.payment) {
|
|
3487
|
+
const i = $(this, oe, de).call(this, "maxGasObjects", e);
|
|
3488
|
+
if (x(this, T).gasConfig.payment.length > i)
|
|
3489
|
+
throw new Error(`Payment objects exceed maximum amount: ${i}`);
|
|
3490
|
+
}
|
|
3491
|
+
if (e.onlyTransactionKind || x(this, T).gasConfig.payment)
|
|
3492
|
+
return;
|
|
3493
|
+
const t = x(this, T).gasConfig.owner ?? x(this, T).sender, n = (await ve(e).getCoins({
|
|
3494
|
+
owner: t,
|
|
3495
|
+
coinType: An
|
|
3496
|
+
})).data.filter((i) => !x(this, T).inputs.find((a) => N(a.value, ze) && "Object" in a.value && "ImmOrOwned" in a.value.Object ? i.coinObjectId === a.value.Object.ImmOrOwned.objectId : !1)).slice(0, $(this, oe, de).call(this, "maxGasObjects", e) - 1).map((i) => ({
|
|
3497
|
+
objectId: i.coinObjectId,
|
|
3498
|
+
digest: i.digest,
|
|
3499
|
+
version: i.version
|
|
3500
|
+
}));
|
|
3501
|
+
if (!n.length)
|
|
3502
|
+
throw new Error("No valid gas coins found for the transaction.");
|
|
3503
|
+
this.setGasPayment(n);
|
|
3504
|
+
};
|
|
3505
|
+
$t = /* @__PURE__ */ new WeakSet();
|
|
3506
|
+
Tr = async function(e) {
|
|
3507
|
+
e.onlyTransactionKind || x(this, T).gasConfig.price || this.setGasPrice(await ve(e).getReferenceGasPrice());
|
|
3508
|
+
};
|
|
3509
|
+
Mt = /* @__PURE__ */ new WeakSet();
|
|
3510
|
+
vr = async function(e) {
|
|
3511
|
+
const { inputs: t, transactions: r } = x(this, T), n = [], i = [];
|
|
3512
|
+
if (t.forEach((s) => {
|
|
3513
|
+
if (s.type === "object" && typeof s.value == "string") {
|
|
3514
|
+
i.push({ id: M(s.value), input: s });
|
|
3515
|
+
return;
|
|
3516
|
+
}
|
|
3517
|
+
}), r.forEach((s) => {
|
|
3518
|
+
if (s.kind === "MoveCall" && s.arguments.some(
|
|
3519
|
+
(o) => o.kind === "Input" && !N(t[o.index].value, ze)
|
|
3520
|
+
) && n.push(s), s.kind === "SplitCoins" && s.amounts.forEach((a) => {
|
|
3521
|
+
if (a.kind === "Input") {
|
|
3522
|
+
const o = t[a.index];
|
|
3523
|
+
typeof o.value != "object" && (o.value = R.Pure(C.U64.serialize(o.value)));
|
|
3524
|
+
}
|
|
3525
|
+
}), s.kind === "TransferObjects" && s.address.kind === "Input") {
|
|
3526
|
+
const a = t[s.address.index];
|
|
3527
|
+
typeof a.value != "object" && (a.value = R.Pure(C.Address.serialize(a.value)));
|
|
3528
|
+
}
|
|
3529
|
+
}), n.length && await Promise.all(
|
|
3530
|
+
n.map(async (s) => {
|
|
3531
|
+
const [a, o, u] = s.target.split("::"), d = await ve(e).getNormalizedMoveFunction({
|
|
3532
|
+
package: be(a),
|
|
3533
|
+
module: o,
|
|
3534
|
+
function: u
|
|
3535
|
+
}), g = d.parameters.length > 0 && Vn(d.parameters.at(-1)) ? d.parameters.slice(0, d.parameters.length - 1) : d.parameters;
|
|
3536
|
+
if (g.length !== s.arguments.length)
|
|
3537
|
+
throw new Error("Incorrect number of arguments.");
|
|
3538
|
+
g.forEach((m, p) => {
|
|
3539
|
+
const y = s.arguments[p];
|
|
3540
|
+
if (y.kind !== "Input")
|
|
3541
|
+
return;
|
|
3542
|
+
const S = t[y.index];
|
|
3543
|
+
if (N(S.value, ze))
|
|
3544
|
+
return;
|
|
3545
|
+
const E = S.value, A = Qe(m, E);
|
|
3546
|
+
if (A) {
|
|
3547
|
+
S.value = R.Pure(E, A);
|
|
3548
|
+
return;
|
|
3549
|
+
}
|
|
3550
|
+
if (at(m) != null || typeof m == "object" && "TypeParameter" in m) {
|
|
3551
|
+
if (typeof E != "string")
|
|
3552
|
+
throw new Error(
|
|
3553
|
+
`Expect the argument to be an object id string, got ${JSON.stringify(
|
|
3554
|
+
E,
|
|
3555
|
+
null,
|
|
3556
|
+
2
|
|
3557
|
+
)}`
|
|
3558
|
+
);
|
|
3559
|
+
i.push({
|
|
3560
|
+
id: E,
|
|
3561
|
+
input: S,
|
|
3562
|
+
normalizedType: m
|
|
3563
|
+
});
|
|
3564
|
+
return;
|
|
3565
|
+
}
|
|
3566
|
+
throw new Error(
|
|
3567
|
+
`Unknown call arg type ${JSON.stringify(m, null, 2)} for value ${JSON.stringify(
|
|
3568
|
+
E,
|
|
3569
|
+
null,
|
|
3570
|
+
2
|
|
3571
|
+
)}`
|
|
3572
|
+
);
|
|
3573
|
+
});
|
|
3574
|
+
})
|
|
3575
|
+
), i.length) {
|
|
3576
|
+
const s = [...new Set(i.map(({ id: l }) => l))], a = mi(s, pi), o = (await Promise.all(
|
|
3577
|
+
a.map(
|
|
3578
|
+
(l) => ve(e).multiGetObjects({
|
|
3579
|
+
ids: l,
|
|
3580
|
+
options: { showOwner: !0 }
|
|
3581
|
+
})
|
|
3582
|
+
)
|
|
3583
|
+
)).flat();
|
|
3584
|
+
let u = new Map(
|
|
3585
|
+
s.map((l, g) => [l, o[g]])
|
|
3586
|
+
);
|
|
3587
|
+
const d = Array.from(u).filter(([l, g]) => g.error).map(([l, g]) => l);
|
|
3588
|
+
if (d.length)
|
|
3589
|
+
throw new Error(`The following input objects are invalid: ${d.join(", ")}`);
|
|
3590
|
+
i.forEach(({ id: l, input: g, normalizedType: m }) => {
|
|
3591
|
+
var E;
|
|
3592
|
+
const p = u.get(l), y = (E = p.data) == null ? void 0 : E.owner, S = y && typeof y == "object" && "Shared" in y ? y.Shared.initial_shared_version : void 0;
|
|
3593
|
+
if (S) {
|
|
3594
|
+
const A = m != null && Ye(m) == null && Qt(m) == null, _ = ti(g.value) || A || m != null && Ye(m) != null;
|
|
3595
|
+
g.value = R.SharedObjectRef({
|
|
3596
|
+
objectId: l,
|
|
3597
|
+
initialSharedVersion: S,
|
|
3598
|
+
mutable: _
|
|
3599
|
+
});
|
|
3600
|
+
} else m && li(m) ? g.value = R.ReceivingRef(zt(p)) : g.value = R.ObjectRef(zt(p));
|
|
3601
|
+
});
|
|
3602
|
+
}
|
|
3603
|
+
};
|
|
3604
|
+
Ue = /* @__PURE__ */ new WeakSet();
|
|
3605
|
+
tt = async function(e) {
|
|
3606
|
+
if (!e.onlyTransactionKind && !x(this, T).sender)
|
|
3607
|
+
throw new Error("Missing transaction sender");
|
|
3608
|
+
if (!e.protocolConfig && !e.limits && e.client && (e.protocolConfig = await e.client.getProtocolConfig()), await Promise.all([$(this, $t, Tr).call(this, e), $(this, Mt, vr).call(this, e)]), !e.onlyTransactionKind && (await $(this, Ct, Sr).call(this, e), !x(this, T).gasConfig.budget)) {
|
|
3609
|
+
const t = await ve(e).dryRunTransactionBlock({
|
|
3610
|
+
transactionBlock: x(this, T).build({
|
|
3611
|
+
maxSizeBytes: $(this, oe, de).call(this, "maxTxSizeBytes", e),
|
|
3612
|
+
overrides: {
|
|
3613
|
+
gasConfig: {
|
|
3614
|
+
budget: String($(this, oe, de).call(this, "maxTxGas", e)),
|
|
3615
|
+
payment: []
|
|
3616
|
+
}
|
|
3617
|
+
}
|
|
3618
|
+
})
|
|
3619
|
+
});
|
|
3620
|
+
if (t.effects.status.status !== "success")
|
|
3621
|
+
throw new Error(
|
|
3622
|
+
`Dry run failed, could not automatically determine a budget: ${t.effects.status.error}`,
|
|
3623
|
+
{ cause: t }
|
|
3624
|
+
);
|
|
3625
|
+
const r = gi * BigInt(this.blockData.gasConfig.price || 1n), n = BigInt(t.effects.gasUsed.computationCost) + r, i = n + BigInt(t.effects.gasUsed.storageCost) - BigInt(t.effects.gasUsed.storageRebate);
|
|
3626
|
+
this.setGasBudget(
|
|
3627
|
+
i > n ? i : n
|
|
3628
|
+
);
|
|
3629
|
+
}
|
|
3630
|
+
$(this, _t, br).call(this, e);
|
|
3631
|
+
};
|
|
3632
|
+
const yi = [
|
|
3633
|
+
[
|
|
3634
|
+
"Testnet",
|
|
3635
|
+
{
|
|
3636
|
+
tokenMessengerState: "0x5252abd1137094ed1db3e0d75bc36abcd287aee4bc310f8e047727ef5682e7c2",
|
|
3637
|
+
messageTransmitterState: "0x98234bd0fa9ac12cc0a20a144a22e36d6a32f7e0a97baaeaf9c76cdc6d122d2e",
|
|
3638
|
+
usdcTreasury: "0x7170137d4a6431bf83351ac025baf462909bffe2877d87716374fb42b9629ebe"
|
|
3639
|
+
}
|
|
3640
|
+
],
|
|
3641
|
+
[
|
|
3642
|
+
"Mainnet",
|
|
3643
|
+
{
|
|
3644
|
+
tokenMessengerState: "0x45993eecc0382f37419864992c12faee2238f5cfe22b98ad3bf455baf65c8a2f",
|
|
3645
|
+
messageTransmitterState: "0xf68268c3d9b1df3215f2439400c1c4ea08ac4ef4bb7d6f3ca6a2a239e17510af",
|
|
3646
|
+
usdcTreasury: "0x57d6725e7a8b49a7b2a612f6bd66ab5f39fc95332ca48be421c3229d514a6de7"
|
|
3647
|
+
}
|
|
3648
|
+
]
|
|
3649
|
+
], wi = Or(yi, [0, 1]);
|
|
3650
|
+
class Ut {
|
|
3651
|
+
constructor(t, r, n, i) {
|
|
3652
|
+
F(this, "network");
|
|
3653
|
+
F(this, "chain");
|
|
3654
|
+
F(this, "provider");
|
|
3655
|
+
F(this, "contracts");
|
|
3656
|
+
F(this, "usdcId");
|
|
3657
|
+
F(this, "usdcTreasuryId");
|
|
3658
|
+
F(this, "tokenMessengerId");
|
|
3659
|
+
F(this, "tokenMessengerStateId");
|
|
3660
|
+
F(this, "messageTransmitterId");
|
|
3661
|
+
F(this, "messageTransmitterStateId");
|
|
3662
|
+
var d, l, g, m;
|
|
3663
|
+
if (this.network = t, this.chain = r, this.provider = n, this.contracts = i, t === "Devnet")
|
|
3664
|
+
throw new Error("CircleBridge not supported on Devnet");
|
|
3665
|
+
const s = Ar.get(this.network, this.chain);
|
|
3666
|
+
if (!s)
|
|
3667
|
+
throw new Error(`No USDC contract configured for network=${this.network} chain=${this.chain}`);
|
|
3668
|
+
const { tokenMessengerState: a, messageTransmitterState: o, usdcTreasury: u } = wi(t);
|
|
3669
|
+
if (!((d = i.cctp) != null && d.tokenMessenger))
|
|
3670
|
+
throw new Error(`Circle Token Messenger contract for domain ${r} not found`);
|
|
3671
|
+
if (!((l = i.cctp) != null && l.messageTransmitter))
|
|
3672
|
+
throw new Error(`Circle Message Transmitter contract for domain ${r} not found`);
|
|
3673
|
+
this.usdcId = s, this.usdcTreasuryId = u, this.tokenMessengerId = (g = i.cctp) == null ? void 0 : g.tokenMessenger, this.messageTransmitterId = (m = i.cctp) == null ? void 0 : m.messageTransmitter, this.tokenMessengerStateId = a, this.messageTransmitterStateId = o;
|
|
3674
|
+
}
|
|
3675
|
+
async *transfer(t, r, n) {
|
|
3676
|
+
const i = new Xe(), s = kr.get(this.network, r.chain), [a, ...o] = await Nt.getCoins(this.provider, t, this.usdcId);
|
|
3677
|
+
if (a === void 0)
|
|
3678
|
+
throw new Error("No USDC in wallet");
|
|
3679
|
+
const u = i.object(a.coinObjectId);
|
|
3680
|
+
o.length > 0 && i.mergeCoins(u, o.map((l) => i.object(l.coinObjectId)));
|
|
3681
|
+
const [d] = i.splitCoins(u, [n]);
|
|
3682
|
+
i.moveCall({
|
|
3683
|
+
target: `${this.tokenMessengerId}::deposit_for_burn::deposit_for_burn`,
|
|
3684
|
+
arguments: [
|
|
3685
|
+
d,
|
|
3686
|
+
i.pure.u32(s),
|
|
3687
|
+
// destination_domain
|
|
3688
|
+
i.pure.address(r.address.toUniversalAddress().toString()),
|
|
3689
|
+
// mint_recipient
|
|
3690
|
+
i.object(this.tokenMessengerStateId),
|
|
3691
|
+
// token_messenger_minter state
|
|
3692
|
+
i.object(this.messageTransmitterStateId),
|
|
3693
|
+
// message_transmitter state
|
|
3694
|
+
i.object("0x403"),
|
|
3695
|
+
// deny_list id, fixed address
|
|
3696
|
+
i.object(this.usdcTreasuryId)
|
|
3697
|
+
// treasury object Treasury<USDC>
|
|
3698
|
+
],
|
|
3699
|
+
typeArguments: [this.usdcId]
|
|
3700
|
+
}), yield this.createUnsignedTx(i, "Sui.CircleBridge.Transfer");
|
|
3701
|
+
}
|
|
3702
|
+
async isTransferCompleted(t) {
|
|
3703
|
+
const r = new Xe();
|
|
3704
|
+
r.moveCall({
|
|
3705
|
+
target: `${this.messageTransmitterId}::state::is_nonce_used`,
|
|
3706
|
+
arguments: [
|
|
3707
|
+
r.object(this.messageTransmitterStateId),
|
|
3708
|
+
r.pure.u32(t.sourceDomain),
|
|
3709
|
+
r.pure.u64(t.nonce)
|
|
3710
|
+
]
|
|
3711
|
+
});
|
|
3712
|
+
const n = await this.provider.devInspectTransactionBlock({
|
|
3713
|
+
sender: "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
3714
|
+
transactionBlock: r
|
|
3715
|
+
});
|
|
3716
|
+
try {
|
|
3717
|
+
return !!n.results[0].returnValues[0][0][0];
|
|
3718
|
+
} catch (i) {
|
|
3719
|
+
return console.error(`Error reading if nonce was used: ${i}`), !1;
|
|
3720
|
+
}
|
|
3721
|
+
}
|
|
3722
|
+
async *redeem(t, r, n) {
|
|
3723
|
+
const i = new Xe(), [s] = i.moveCall({
|
|
3724
|
+
target: `${this.messageTransmitterId}::receive_message::receive_message`,
|
|
3725
|
+
arguments: [
|
|
3726
|
+
i.pure(Pt(Bt.serialize(r))),
|
|
3727
|
+
i.pure(Pt(_r.decode(n))),
|
|
3728
|
+
i.object(this.messageTransmitterStateId)
|
|
3729
|
+
// message_transmitter state
|
|
3730
|
+
]
|
|
3731
|
+
});
|
|
3732
|
+
if (!s)
|
|
3733
|
+
throw new Error("Failed to produce receipt");
|
|
3734
|
+
const [a] = i.moveCall({
|
|
3735
|
+
target: `${this.tokenMessengerId}::handle_receive_message::handle_receive_message`,
|
|
3736
|
+
arguments: [
|
|
3737
|
+
s,
|
|
3738
|
+
// Receipt object returned from receive_message call
|
|
3739
|
+
i.object(this.tokenMessengerStateId),
|
|
3740
|
+
// token_messenger_minter state
|
|
3741
|
+
i.object("0x403"),
|
|
3742
|
+
// deny list, fixed address
|
|
3743
|
+
i.object(this.usdcTreasuryId)
|
|
3744
|
+
// usdc treasury object Treasury<T>
|
|
3745
|
+
],
|
|
3746
|
+
typeArguments: [this.usdcId]
|
|
3747
|
+
});
|
|
3748
|
+
if (!a)
|
|
3749
|
+
throw new Error("Failed to produce stamp receipt ticket with burn message");
|
|
3750
|
+
const [o] = i.moveCall({
|
|
3751
|
+
target: `${this.tokenMessengerId}::handle_receive_message::deconstruct_stamp_receipt_ticket_with_burn_message`,
|
|
3752
|
+
arguments: [a]
|
|
3753
|
+
});
|
|
3754
|
+
if (!o)
|
|
3755
|
+
throw new Error("Failed to produce stamp receipt ticket");
|
|
3756
|
+
const [u] = i.moveCall({
|
|
3757
|
+
target: `${this.messageTransmitterId}::receive_message::stamp_receipt`,
|
|
3758
|
+
arguments: [
|
|
3759
|
+
o,
|
|
3760
|
+
// Receipt ticket returned from deconstruct_stamp_receipt_ticket_with_burn_message call
|
|
3761
|
+
i.object(this.messageTransmitterStateId)
|
|
3762
|
+
// message_transmitter state
|
|
3763
|
+
],
|
|
3764
|
+
typeArguments: [
|
|
3765
|
+
`${this.tokenMessengerId}::message_transmitter_authenticator::MessageTransmitterAuthenticator`
|
|
3766
|
+
]
|
|
3767
|
+
});
|
|
3768
|
+
if (!u)
|
|
3769
|
+
throw new Error("Failed to produce stamped receipt");
|
|
3770
|
+
i.moveCall({
|
|
3771
|
+
target: `${this.messageTransmitterId}::receive_message::complete_receive_message`,
|
|
3772
|
+
arguments: [
|
|
3773
|
+
u,
|
|
3774
|
+
// Stamped receipt object returned from handle_receive_message call
|
|
3775
|
+
i.object(this.messageTransmitterStateId)
|
|
3776
|
+
// message_transmitter state
|
|
3777
|
+
]
|
|
3778
|
+
}), yield this.createUnsignedTx(i, "Sui.CircleBridge.Redeem");
|
|
3779
|
+
}
|
|
3780
|
+
async parseTransactionDetails(t) {
|
|
3781
|
+
var p;
|
|
3782
|
+
const r = await this.provider.waitForTransactionBlock({
|
|
3783
|
+
digest: t,
|
|
3784
|
+
options: { showEvents: !0, showEffects: !0, showInput: !0 }
|
|
3785
|
+
});
|
|
3786
|
+
if (!r)
|
|
3787
|
+
throw new Error("Transaction not found");
|
|
3788
|
+
if (!r.events)
|
|
3789
|
+
throw new Error("Transaction events not found");
|
|
3790
|
+
const n = (p = r.events) == null ? void 0 : p.find((y) => y.type.includes("send_message::MessageSent"));
|
|
3791
|
+
if (!n)
|
|
3792
|
+
throw new Error("No MessageSent event found");
|
|
3793
|
+
const i = new Uint8Array((n == null ? void 0 : n.parsedJson).message), [s, a] = Bt.deserialize(i), { payload: o } = s, u = o.messageSender, d = o.mintRecipient, l = Rt(this.network, s.sourceDomain), g = Rt(this.network, s.destinationDomain), m = { chain: l, address: o.burnToken };
|
|
3794
|
+
return {
|
|
3795
|
+
from: { chain: l, address: u },
|
|
3796
|
+
to: { chain: g, address: d },
|
|
3797
|
+
token: m,
|
|
3798
|
+
amount: o.amount,
|
|
3799
|
+
message: s,
|
|
3800
|
+
id: { hash: a }
|
|
3801
|
+
};
|
|
3802
|
+
}
|
|
3803
|
+
static async fromRpc(t, r) {
|
|
3804
|
+
const [n, i] = await Nt.chainFromRpc(t), s = r[i];
|
|
3805
|
+
if (s.network !== n)
|
|
3806
|
+
throw new Error(`Network mismatch: ${s.network} != ${n}`);
|
|
3807
|
+
return new Ut(n, i, t, s.contracts);
|
|
3808
|
+
}
|
|
3809
|
+
createUnsignedTx(t, r, n = !1) {
|
|
3810
|
+
return new $r(t, this.network, this.chain, r, n);
|
|
3811
|
+
}
|
|
3812
|
+
}
|
|
3813
|
+
Cr("Sui", "CircleBridge", Ut);
|
|
3814
|
+
export {
|
|
3815
|
+
Ut as SuiCircleBridge
|
|
3816
|
+
};
|