@tari-project/ootle 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +34 -10
- package/dist/index.js +418 -378
- package/package.json +11 -3
package/dist/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
-
import { aggregateInputMasks as e, borEncodeTransaction as t, buildStealthInputsStatement as n, createStealthOutputWitness as r, encryptedDataDhKdfAead as i, generateKeypair as a, generateStealthBalanceProofSignature as o, generateStealthOutputsStatement as s, parseOotleAddress as c, sealTransaction as
|
|
5
|
-
var
|
|
4
|
+
import { aggregateInputMasks as e, borEncodeTransaction as t, buildStealthInputsStatement as n, createStealthOutputWitness as r, encryptedDataDhKdfAead as i, generateKeypair as a, generateStealthBalanceProofSignature as o, generateStealthOutputsStatement as s, parseOotleAddress as c, sealTransaction as ee, stealthDhSecret as te, unblindOutput as ne, validateBalanceProofSignature as re, validateStealthTransfer as ie } from "@tari-project/ootle-wasm";
|
|
5
|
+
var l = /* @__PURE__ */ (function(e11) {
|
|
6
6
|
return e11[e11.MainNet = 0] = "MainNet", e11[e11.StageNet = 1] = "StageNet", e11[e11.NextNet = 2] = "NextNet", e11[e11.LocalNet = 16] = "LocalNet", e11[e11.Igor = 36] = "Igor", e11[e11.Esmeralda = 38] = "Esmeralda", e11;
|
|
7
|
-
})({}),
|
|
7
|
+
})({}), u = class extends Error {
|
|
8
8
|
constructor(e11, t2) {
|
|
9
9
|
super(e11, t2), this.name = new.target.name;
|
|
10
10
|
}
|
|
11
|
-
},
|
|
11
|
+
}, ae = class extends u {
|
|
12
12
|
constructor(e11, t2) {
|
|
13
13
|
super(e11, t2);
|
|
14
14
|
__publicField(this, "status");
|
|
@@ -16,7 +16,7 @@ var u = /* @__PURE__ */ (function(e11) {
|
|
|
16
16
|
__publicField(this, "url");
|
|
17
17
|
this.status = t2 == null ? void 0 : t2.status, this.body = t2 == null ? void 0 : t2.body, this.url = t2 == null ? void 0 : t2.url;
|
|
18
18
|
}
|
|
19
|
-
},
|
|
19
|
+
}, d = class extends u {
|
|
20
20
|
constructor(e11, t2) {
|
|
21
21
|
super(e11, t2);
|
|
22
22
|
__publicField(this, "txId");
|
|
@@ -24,208 +24,240 @@ var u = /* @__PURE__ */ (function(e11) {
|
|
|
24
24
|
__publicField(this, "rejectReason");
|
|
25
25
|
this.txId = t2.txId, this.reason = t2.reason, this.rejectReason = t2.rejectReason;
|
|
26
26
|
}
|
|
27
|
-
},
|
|
27
|
+
}, oe = class extends u {
|
|
28
28
|
constructor(e11, t2) {
|
|
29
29
|
super(e11, t2);
|
|
30
30
|
__publicField(this, "txId");
|
|
31
31
|
this.txId = t2.txId;
|
|
32
32
|
}
|
|
33
|
-
},
|
|
34
|
-
},
|
|
33
|
+
}, f = class extends u {
|
|
34
|
+
}, p = class extends f {
|
|
35
35
|
constructor(e11, t2) {
|
|
36
36
|
super(e11, t2);
|
|
37
37
|
__publicField(this, "address");
|
|
38
38
|
this.address = t2.address;
|
|
39
39
|
}
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
},
|
|
40
|
+
}, m = class extends f {
|
|
41
|
+
}, h = class extends u {
|
|
42
|
+
}, g = class extends u {
|
|
43
43
|
constructor(e11, t2) {
|
|
44
44
|
super(e11, t2);
|
|
45
45
|
__publicField(this, "context");
|
|
46
46
|
this.context = t2 == null ? void 0 : t2.context;
|
|
47
47
|
}
|
|
48
|
-
},
|
|
49
|
-
},
|
|
48
|
+
}, _ = class extends u {
|
|
49
|
+
}, se = class extends u {
|
|
50
50
|
};
|
|
51
|
-
function
|
|
52
|
-
throw new
|
|
51
|
+
function ce(e11, t2) {
|
|
52
|
+
throw new _(`assertUnreachable${t2 ? ` (${t2})` : ""}: ${JSON.stringify(e11)}`);
|
|
53
53
|
}
|
|
54
|
-
function
|
|
55
|
-
if (e11.length !== t2) throw new
|
|
54
|
+
function v(e11, t2, n2) {
|
|
55
|
+
if (e11.length !== t2) throw new _(`${n2} must be ${t2} bytes, got ${e11.length}`);
|
|
56
56
|
return e11;
|
|
57
57
|
}
|
|
58
|
-
function
|
|
58
|
+
function y(e11) {
|
|
59
59
|
return Array.from(e11, (e12) => e12.toString(16).padStart(2, "0")).join("");
|
|
60
60
|
}
|
|
61
|
-
var
|
|
62
|
-
function
|
|
63
|
-
if (e11.length % 2 != 0) throw new
|
|
64
|
-
if (!
|
|
61
|
+
var le = /^[0-9a-fA-F]*$/;
|
|
62
|
+
function b(e11) {
|
|
63
|
+
if (e11.length % 2 != 0) throw new _(`fromHexStr: hex string must have even length, got ${e11.length}`);
|
|
64
|
+
if (!le.test(e11)) throw new _("fromHexStr: hex string contains non-hex characters");
|
|
65
65
|
let t2 = new Uint8Array(e11.length / 2);
|
|
66
66
|
for (let n2 = 0; n2 < t2.length; n2++) t2[n2] = parseInt(e11.substring(n2 * 2, n2 * 2 + 2), 16);
|
|
67
67
|
return t2;
|
|
68
68
|
}
|
|
69
|
-
var
|
|
70
|
-
function
|
|
69
|
+
var x = (1n << 64n) - 1n, S = 32, ue = S * 2, de = 32, fe = 128, pe = 129, me = 130, C = 131, he = 132, ge = 136, _e = 137, ve = 138, ye = 141, w = 0, be = 32, T = 64, xe = 96, E = 128, Se = 160, D = 192;
|
|
70
|
+
function Ce(e11) {
|
|
71
71
|
switch (typeof e11) {
|
|
72
72
|
case "bigint":
|
|
73
|
-
return
|
|
73
|
+
return O(e11);
|
|
74
74
|
case "string":
|
|
75
|
-
return we(e11);
|
|
76
|
-
case "boolean":
|
|
77
75
|
return Te(e11);
|
|
76
|
+
case "boolean":
|
|
77
|
+
return Ee(e11);
|
|
78
78
|
default:
|
|
79
|
-
if (e11 instanceof Uint8Array) return
|
|
80
|
-
throw new
|
|
79
|
+
if (e11 instanceof Uint8Array) return k(e11);
|
|
80
|
+
throw new _(`literalArg: cannot CBOR-encode value of type ${typeof e11}`);
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
|
-
function
|
|
84
|
-
if (e11 < 0n) throw new
|
|
85
|
-
if (e11 >> 128n != 0n) throw new
|
|
83
|
+
function O(e11) {
|
|
84
|
+
if (e11 < 0n) throw new _(`amountLiteral: amount must be non-negative, got ${e11}`);
|
|
85
|
+
if (e11 >> 128n != 0n) throw new _(`amountLiteral: amount overflows u128: ${e11}`);
|
|
86
86
|
let t2 = [];
|
|
87
|
-
return
|
|
87
|
+
return F(t2, E, 2n), F(t2, w, e11 & x), F(t2, w, e11 >> 64n & x), I(t2);
|
|
88
88
|
}
|
|
89
|
-
function
|
|
89
|
+
function we(e11) {
|
|
90
90
|
let t2 = [];
|
|
91
91
|
if (e11 >= 0n) {
|
|
92
|
-
if (e11 >
|
|
93
|
-
|
|
92
|
+
if (e11 > x) throw new _(`intLiteral: value exceeds the 64-bit CBOR integer range: ${e11}`);
|
|
93
|
+
F(t2, w, e11);
|
|
94
94
|
} else {
|
|
95
95
|
let n2 = -1n - e11;
|
|
96
|
-
if (n2 >
|
|
97
|
-
|
|
96
|
+
if (n2 > x) throw new _(`intLiteral: value exceeds the 64-bit CBOR integer range: ${e11}`);
|
|
97
|
+
F(t2, be, n2);
|
|
98
98
|
}
|
|
99
|
-
return
|
|
99
|
+
return I(t2);
|
|
100
100
|
}
|
|
101
|
-
function
|
|
101
|
+
function Te(e11) {
|
|
102
102
|
let t2 = [];
|
|
103
|
-
return
|
|
103
|
+
return N(t2, e11), I(t2);
|
|
104
104
|
}
|
|
105
|
-
function
|
|
105
|
+
function k(e11) {
|
|
106
106
|
let t2 = [];
|
|
107
|
-
return
|
|
107
|
+
return F(t2, T, BigInt(e11.length)), P(t2, e11), I(t2);
|
|
108
108
|
}
|
|
109
|
-
function
|
|
109
|
+
function Ee(e11) {
|
|
110
110
|
return { Literal: e11 ? "f5" : "f4" };
|
|
111
111
|
}
|
|
112
|
-
function
|
|
113
|
-
return
|
|
114
|
-
}
|
|
115
|
-
function Ee(e11) {
|
|
116
|
-
return M(de, e11, "component_");
|
|
112
|
+
function A(e11) {
|
|
113
|
+
return j(C, e11, "resource_");
|
|
117
114
|
}
|
|
118
115
|
function De(e11) {
|
|
119
|
-
|
|
120
|
-
I(i2, O, BigInt(fe)), I(i2, xe, BigInt(r2.length));
|
|
121
|
-
for (let [e12, t3] of r2) P(i2, e12), P(i2, t3);
|
|
122
|
-
return L(i2);
|
|
116
|
+
return j(fe, e11, "component_");
|
|
123
117
|
}
|
|
124
118
|
function Oe(e11) {
|
|
125
|
-
|
|
119
|
+
let t2 = e11 instanceof Map ? e11 : new Map(Object.entries(e11)), n2 = new TextEncoder(), r2 = [...t2.entries()].sort(([e12], [t3]) => Re(n2.encode(e12), n2.encode(t3))), i2 = [];
|
|
120
|
+
F(i2, D, BigInt(pe)), F(i2, Se, BigInt(r2.length));
|
|
121
|
+
for (let [e12, t3] of r2) N(i2, e12), N(i2, t3);
|
|
122
|
+
return I(i2);
|
|
126
123
|
}
|
|
127
124
|
function ke(e11) {
|
|
128
|
-
return
|
|
125
|
+
return j(he, e11, "vault_");
|
|
129
126
|
}
|
|
130
127
|
function Ae(e11) {
|
|
131
|
-
return
|
|
128
|
+
return j(_e, e11, "template_");
|
|
132
129
|
}
|
|
133
130
|
function je(e11) {
|
|
134
|
-
return
|
|
131
|
+
return j(ge, e11, "tombstone_");
|
|
135
132
|
}
|
|
136
133
|
function Me(e11) {
|
|
137
|
-
|
|
138
|
-
return y(t2, ue, "publicKeyLiteral"), A(t2);
|
|
134
|
+
return j(ve, e11, "vnfp_");
|
|
139
135
|
}
|
|
140
136
|
function Ne(e11) {
|
|
141
|
-
let t2 =
|
|
142
|
-
return
|
|
137
|
+
let t2 = typeof e11 == "string" ? b(e11) : e11;
|
|
138
|
+
return v(t2, de, "publicKeyLiteral"), k(t2);
|
|
143
139
|
}
|
|
144
140
|
function Pe(e11) {
|
|
145
141
|
let t2 = [];
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
142
|
+
return F(t2, D, BigInt(me)), F(t2, E, 2n), M(t2, C, e11.resource_address, "resource_"), Ie(t2, e11.id), I(t2);
|
|
143
|
+
}
|
|
144
|
+
function Fe(e11) {
|
|
145
|
+
let t2 = [];
|
|
146
|
+
F(t2, D, BigInt(ye)), F(t2, E, 2n), M(t2, C, e11.resource_address, "resource_");
|
|
147
|
+
let n2 = b(e11.id);
|
|
148
|
+
return v(n2, S, "utxoAddressLiteral: id"), F(t2, T, BigInt(S)), P(t2, n2), I(t2);
|
|
149
149
|
}
|
|
150
|
-
function
|
|
150
|
+
function j(e11, t2, n2) {
|
|
151
151
|
let r2 = [];
|
|
152
|
-
return
|
|
152
|
+
return M(r2, e11, t2, n2), I(r2);
|
|
153
153
|
}
|
|
154
|
-
function
|
|
154
|
+
function M(e11, t2, n2, r2) {
|
|
155
155
|
let i2 = n2.startsWith(r2) ? n2.slice(r2.length) : n2;
|
|
156
|
-
if (i2.length !==
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
function
|
|
160
|
-
if (
|
|
161
|
-
|
|
162
|
-
let n2 =
|
|
163
|
-
|
|
164
|
-
} else if ("String" in t2)
|
|
165
|
-
else if ("Uint32" in t2)
|
|
166
|
-
else if ("Uint64" in t2)
|
|
167
|
-
else throw new
|
|
168
|
-
}
|
|
169
|
-
function
|
|
170
|
-
if (!Number.isInteger(t2) || t2 < 0) throw new
|
|
171
|
-
if (r2 > BigInt(2 ** 53 - 1) && t2 > 2 ** 53 - 1) throw new
|
|
156
|
+
if (i2.length !== ue) throw new _(`${r2}address must be 32 bytes (${ue} hex chars), got ${i2.length}`);
|
|
157
|
+
F(e11, D, BigInt(t2)), F(e11, T, BigInt(S)), P(e11, b(i2));
|
|
158
|
+
}
|
|
159
|
+
function Ie(e11, t2) {
|
|
160
|
+
if (F(e11, E, 2n), "U256" in t2) {
|
|
161
|
+
F(e11, w, 0n), F(e11, E, 1n);
|
|
162
|
+
let n2 = b(t2.U256);
|
|
163
|
+
v(n2, S, "NonFungibleId.U256"), F(e11, T, BigInt(S)), P(e11, n2);
|
|
164
|
+
} else if ("String" in t2) F(e11, w, 1n), F(e11, E, 1n), N(e11, t2.String);
|
|
165
|
+
else if ("Uint32" in t2) F(e11, w, 2n), F(e11, E, 1n), Le(e11, t2.Uint32, "NonFungibleId.Uint32", (1n << 32n) - 1n);
|
|
166
|
+
else if ("Uint64" in t2) F(e11, w, 3n), F(e11, E, 1n), Le(e11, t2.Uint64, "NonFungibleId.Uint64", x);
|
|
167
|
+
else throw new _(`nonFungibleAddressLiteral: unrecognised NonFungibleId variant: ${JSON.stringify(t2)}`);
|
|
168
|
+
}
|
|
169
|
+
function Le(e11, t2, n2, r2) {
|
|
170
|
+
if (!Number.isInteger(t2) || t2 < 0) throw new _(`${n2} must be a non-negative integer, got ${t2}`);
|
|
171
|
+
if (r2 > BigInt(2 ** 53 - 1) && t2 > 2 ** 53 - 1) throw new _(`${n2} value ${t2} exceeds Number.MAX_SAFE_INTEGER (2^53-1) and cannot be encoded without precision loss \u2014 the binding types this id as a JS number. Use a U256/String id for large values.`);
|
|
172
172
|
let i2 = BigInt(t2);
|
|
173
|
-
if (i2 > r2) throw new
|
|
174
|
-
|
|
173
|
+
if (i2 > r2) throw new _(`${n2} value ${t2} exceeds its maximum of ${r2}`);
|
|
174
|
+
F(e11, w, i2);
|
|
175
175
|
}
|
|
176
|
-
function
|
|
176
|
+
function N(e11, t2) {
|
|
177
177
|
let n2 = new TextEncoder().encode(t2);
|
|
178
|
-
|
|
178
|
+
F(e11, xe, BigInt(n2.length)), P(e11, n2);
|
|
179
179
|
}
|
|
180
|
-
function
|
|
180
|
+
function P(e11, t2) {
|
|
181
181
|
let n2 = e11.length;
|
|
182
182
|
e11.length = n2 + t2.length;
|
|
183
183
|
for (let r2 = 0; r2 < t2.length; r2++) e11[n2 + r2] = t2[r2];
|
|
184
184
|
}
|
|
185
|
-
function
|
|
185
|
+
function Re(e11, t2) {
|
|
186
186
|
let n2 = Math.min(e11.length, t2.length);
|
|
187
187
|
for (let r2 = 0; r2 < n2; r2++) if (e11[r2] !== t2[r2]) return e11[r2] < t2[r2] ? -1 : 1;
|
|
188
188
|
return e11.length - t2.length;
|
|
189
189
|
}
|
|
190
|
-
function
|
|
190
|
+
function F(e11, t2, n2) {
|
|
191
191
|
n2 < 24n ? e11.push(t2 | Number(n2)) : n2 < 1n << 8n ? e11.push(t2 | 24, Number(n2)) : n2 < 1n << 16n ? e11.push(t2 | 25, Number(n2 >> 8n & 255n), Number(n2 & 255n)) : n2 < 1n << 32n ? e11.push(t2 | 26, Number(n2 >> 24n & 255n), Number(n2 >> 16n & 255n), Number(n2 >> 8n & 255n), Number(n2 & 255n)) : e11.push(t2 | 27, Number(n2 >> 56n & 255n), Number(n2 >> 48n & 255n), Number(n2 >> 40n & 255n), Number(n2 >> 32n & 255n), Number(n2 >> 24n & 255n), Number(n2 >> 16n & 255n), Number(n2 >> 8n & 255n), Number(n2 & 255n));
|
|
192
192
|
}
|
|
193
|
-
function
|
|
194
|
-
return { Literal:
|
|
193
|
+
function I(e11) {
|
|
194
|
+
return { Literal: y(Uint8Array.from(e11)) };
|
|
195
195
|
}
|
|
196
|
-
function
|
|
197
|
-
return
|
|
196
|
+
function L(e11) {
|
|
197
|
+
return O(e11);
|
|
198
198
|
}
|
|
199
|
-
function
|
|
200
|
-
if (e11 < 0n) throw new
|
|
199
|
+
function ze(e11) {
|
|
200
|
+
if (e11 < 0n) throw new _(`microTariString: amount must be non-negative, got ${e11}`);
|
|
201
201
|
return e11.toString();
|
|
202
202
|
}
|
|
203
|
-
function
|
|
203
|
+
function Be(e11) {
|
|
204
204
|
let t2 = e11.split(".");
|
|
205
|
-
if (t2.length > 2) throw new
|
|
205
|
+
if (t2.length > 2) throw new _("Invalid workspace key format. Only one dot is allowed.");
|
|
206
206
|
let n2 = t2[0];
|
|
207
207
|
if (t2[1] === void 0) return {
|
|
208
208
|
name: n2,
|
|
209
209
|
offset: null
|
|
210
210
|
};
|
|
211
211
|
let r2 = Number.parseInt(t2[1], 10);
|
|
212
|
-
if (Number.isNaN(r2) || r2 < 0 || String(r2) !== t2[1]) throw new
|
|
212
|
+
if (Number.isNaN(r2) || r2 < 0 || String(r2) !== t2[1]) throw new _(`Invalid workspace key offset: "${t2[1]}"`);
|
|
213
213
|
return {
|
|
214
214
|
name: n2,
|
|
215
215
|
offset: r2
|
|
216
216
|
};
|
|
217
217
|
}
|
|
218
|
-
function
|
|
218
|
+
function Ve(e11) {
|
|
219
219
|
return e11.startsWith("template_") ? e11.slice(9) : e11;
|
|
220
220
|
}
|
|
221
|
-
function
|
|
222
|
-
return
|
|
221
|
+
function He(e11) {
|
|
222
|
+
return typeof e11 != "object" || !e11 ? null : "PutLastInstructionOutputOnWorkspace" in e11 ? e11.PutLastInstructionOutputOnWorkspace.key : "TakeFromBucket" in e11 ? e11.TakeFromBucket.output_bucket : "AllocateAddress" in e11 ? e11.AllocateAddress.workspace_id : null;
|
|
223
|
+
}
|
|
224
|
+
var Ue = class {
|
|
225
|
+
constructor() {
|
|
226
|
+
__publicField(this, "nextId", 0);
|
|
227
|
+
__publicField(this, "ids", /* @__PURE__ */ new Map());
|
|
228
|
+
}
|
|
229
|
+
insert(e11) {
|
|
230
|
+
let t2 = this.nextId;
|
|
231
|
+
return this.ids.set(e11, t2), this.nextId += 1, t2;
|
|
232
|
+
}
|
|
233
|
+
get(e11) {
|
|
234
|
+
return this.ids.get(e11);
|
|
235
|
+
}
|
|
236
|
+
get next() {
|
|
237
|
+
return this.nextId;
|
|
238
|
+
}
|
|
239
|
+
observeAllocated(e11) {
|
|
240
|
+
e11 + 1 > this.nextId && (this.nextId = e11 + 1);
|
|
241
|
+
}
|
|
242
|
+
reset() {
|
|
243
|
+
this.nextId = 0, this.ids.clear();
|
|
244
|
+
}
|
|
245
|
+
resetFrom(e11) {
|
|
246
|
+
this.reset();
|
|
247
|
+
for (let t2 of e11) {
|
|
248
|
+
let e12 = He(t2);
|
|
249
|
+
e12 !== null && this.observeAllocated(e12);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
function We(e11) {
|
|
254
|
+
return new _(`No workspace variable named "${e11}" has been defined. Call builder.saveVar(${JSON.stringify(e11)}) on a preceding instruction whose output you want to reference.`);
|
|
223
255
|
}
|
|
224
|
-
var
|
|
256
|
+
var R = class e2 {
|
|
225
257
|
constructor(e11) {
|
|
226
258
|
__publicField(this, "unsignedTransaction");
|
|
227
|
-
__publicField(this, "
|
|
228
|
-
__publicField(this, "
|
|
259
|
+
__publicField(this, "workspaceIds");
|
|
260
|
+
__publicField(this, "feeWorkspaceIds");
|
|
229
261
|
this.unsignedTransaction = {
|
|
230
262
|
network: e11,
|
|
231
263
|
fee_instructions: [],
|
|
@@ -236,7 +268,7 @@ var z = class e2 {
|
|
|
236
268
|
dry_run: false,
|
|
237
269
|
is_seal_signer_authorized: false,
|
|
238
270
|
blobs: []
|
|
239
|
-
}, this.
|
|
271
|
+
}, this.workspaceIds = new Ue(), this.feeWorkspaceIds = new Ue();
|
|
240
272
|
}
|
|
241
273
|
static new(t2) {
|
|
242
274
|
return new e2(t2);
|
|
@@ -244,7 +276,7 @@ var z = class e2 {
|
|
|
244
276
|
callFunction(e11, t2) {
|
|
245
277
|
let n2 = this.resolveArgs(t2);
|
|
246
278
|
return this.addInstruction({ CallFunction: {
|
|
247
|
-
address:
|
|
279
|
+
address: Ve(e11.templateAddress),
|
|
248
280
|
function: e11.functionName,
|
|
249
281
|
args: n2
|
|
250
282
|
} });
|
|
@@ -253,7 +285,7 @@ var z = class e2 {
|
|
|
253
285
|
let n2;
|
|
254
286
|
if (e11.componentAddress) n2 = { Address: e11.componentAddress };
|
|
255
287
|
else if (e11.fromWorkspace) n2 = { Workspace: this.requireNamedId(e11.fromWorkspace) };
|
|
256
|
-
else throw new
|
|
288
|
+
else throw new _("callMethod requires either `componentAddress` or `fromWorkspace` to be set on the method definition. Use `fromWorkspace` to call a method on a component returned by a previous saveVar; use `componentAddress` for an on-chain component.");
|
|
257
289
|
let r2 = this.resolveArgs(t2);
|
|
258
290
|
return this.addInstruction({ CallMethod: {
|
|
259
291
|
call: n2,
|
|
@@ -274,7 +306,7 @@ var z = class e2 {
|
|
|
274
306
|
return this.addInstruction({ CallMethod: {
|
|
275
307
|
call: { Address: e11 },
|
|
276
308
|
method: "create_proof_for_resource",
|
|
277
|
-
args: [
|
|
309
|
+
args: [A(t2)]
|
|
278
310
|
} });
|
|
279
311
|
}
|
|
280
312
|
claimBurn(e11, t2) {
|
|
@@ -298,11 +330,11 @@ var z = class e2 {
|
|
|
298
330
|
return this.addFeeInstruction({ CallMethod: {
|
|
299
331
|
call: { Address: e11 },
|
|
300
332
|
method: "pay_fee",
|
|
301
|
-
args: [
|
|
333
|
+
args: [L(t2)]
|
|
302
334
|
} });
|
|
303
335
|
}
|
|
304
336
|
feeTransactionPayFromComponentConfidential(e11, t2) {
|
|
305
|
-
throw new
|
|
337
|
+
throw new _("feeTransactionPayFromComponentConfidential is not implemented: a ConfidentialWithdrawProof Literal must be tari_bor-CBOR-encoded, which the TS SDK does not yet support.");
|
|
306
338
|
}
|
|
307
339
|
dropAllProofsInWorkspace() {
|
|
308
340
|
return this.addInstruction("DropAllProofsInWorkspace");
|
|
@@ -315,20 +347,26 @@ var z = class e2 {
|
|
|
315
347
|
} });
|
|
316
348
|
}
|
|
317
349
|
addInstruction(e11) {
|
|
318
|
-
return this.unsignedTransaction.instructions.push(e11), this;
|
|
350
|
+
return this.observeAllocations(this.workspaceIds, [e11]), this.unsignedTransaction.instructions.push(e11), this;
|
|
319
351
|
}
|
|
320
352
|
addFeeInstruction(e11) {
|
|
321
|
-
return this.unsignedTransaction.fee_instructions.push(e11), this;
|
|
353
|
+
return this.observeAllocations(this.feeWorkspaceIds, [e11]), this.unsignedTransaction.fee_instructions.push(e11), this;
|
|
322
354
|
}
|
|
323
355
|
withInstructions(e11) {
|
|
324
|
-
return this.unsignedTransaction.instructions.push(...e11), this;
|
|
356
|
+
return this.observeAllocations(this.workspaceIds, e11), this.unsignedTransaction.instructions.push(...e11), this;
|
|
325
357
|
}
|
|
326
358
|
withFeeInstructions(e11) {
|
|
327
|
-
return this.unsignedTransaction.fee_instructions.push(...e11), this;
|
|
359
|
+
return this.observeAllocations(this.feeWorkspaceIds, e11), this.unsignedTransaction.fee_instructions.push(...e11), this;
|
|
360
|
+
}
|
|
361
|
+
observeAllocations(e11, t2) {
|
|
362
|
+
for (let n2 of t2) {
|
|
363
|
+
let t3 = He(n2);
|
|
364
|
+
t3 !== null && e11.observeAllocated(t3);
|
|
365
|
+
}
|
|
328
366
|
}
|
|
329
367
|
withFeeInstructionsBuilder(t2) {
|
|
330
368
|
let n2 = t2(new e2(this.unsignedTransaction.network));
|
|
331
|
-
return this.unsignedTransaction.fee_instructions = n2.unsignedTransaction.instructions, this;
|
|
369
|
+
return this.unsignedTransaction.fee_instructions = n2.unsignedTransaction.instructions, this.feeWorkspaceIds.resetFrom(this.unsignedTransaction.fee_instructions), this;
|
|
332
370
|
}
|
|
333
371
|
addInput(e11) {
|
|
334
372
|
return this.unsignedTransaction.inputs.push(e11), this;
|
|
@@ -345,8 +383,11 @@ var z = class e2 {
|
|
|
345
383
|
withUnsignedTransaction(e11) {
|
|
346
384
|
return this.unsignedTransaction = {
|
|
347
385
|
...e11,
|
|
348
|
-
|
|
349
|
-
|
|
386
|
+
instructions: [...e11.instructions],
|
|
387
|
+
fee_instructions: [...e11.fee_instructions],
|
|
388
|
+
inputs: [...e11.inputs],
|
|
389
|
+
blobs: [...e11.blobs ?? []]
|
|
390
|
+
}, this.workspaceIds.resetFrom(this.unsignedTransaction.instructions), this.feeWorkspaceIds.resetFrom(this.unsignedTransaction.fee_instructions), this;
|
|
350
391
|
}
|
|
351
392
|
resolveWorkspaceOffsetId(e11) {
|
|
352
393
|
return this.getOffsetIdFromWorkspaceName(e11);
|
|
@@ -361,16 +402,15 @@ var z = class e2 {
|
|
|
361
402
|
};
|
|
362
403
|
}
|
|
363
404
|
addNamedId(e11) {
|
|
364
|
-
|
|
365
|
-
return this.allocatedIds.set(e11, t2), this.currentId += 1, t2;
|
|
405
|
+
return this.workspaceIds.insert(e11);
|
|
366
406
|
}
|
|
367
407
|
requireNamedId(e11) {
|
|
368
|
-
let t2 = this.
|
|
369
|
-
if (t2 === void 0) throw
|
|
408
|
+
let t2 = this.workspaceIds.get(e11);
|
|
409
|
+
if (t2 === void 0) throw We(e11);
|
|
370
410
|
return t2;
|
|
371
411
|
}
|
|
372
412
|
getOffsetIdFromWorkspaceName(e11) {
|
|
373
|
-
let t2 =
|
|
413
|
+
let t2 = Be(e11);
|
|
374
414
|
return {
|
|
375
415
|
id: this.requireNamedId(t2.name),
|
|
376
416
|
offset: t2.offset
|
|
@@ -379,27 +419,27 @@ var z = class e2 {
|
|
|
379
419
|
resolveArgs(e11) {
|
|
380
420
|
return e11.map((e12) => typeof e12 == "object" && e12 && "Workspace" in e12 && typeof e12.Workspace == "string" ? { Workspace: this.getOffsetIdFromWorkspaceName(e12.Workspace) } : e12);
|
|
381
421
|
}
|
|
382
|
-
},
|
|
383
|
-
[
|
|
384
|
-
[
|
|
422
|
+
}, Ge = {
|
|
423
|
+
[l.LocalNet]: "http://localhost:12500",
|
|
424
|
+
[l.Esmeralda]: "https://ootle-indexer-a.tari.com"
|
|
385
425
|
};
|
|
386
|
-
function
|
|
387
|
-
let t2 =
|
|
426
|
+
function Ke(e11) {
|
|
427
|
+
let t2 = Ge[e11];
|
|
388
428
|
if (t2 !== void 0) return t2;
|
|
389
|
-
throw new
|
|
429
|
+
throw new _(`No default indexer URL is configured for ${l[e11]}. Pass an explicit URL via ProviderBuilder.withUrl(...) or IndexerProvider.connect({ url, network: Network.${l[e11]} }).`);
|
|
390
430
|
}
|
|
391
|
-
var
|
|
392
|
-
function*
|
|
431
|
+
var qe = 132, Je = 32;
|
|
432
|
+
function* Ye(e11) {
|
|
393
433
|
let t2 = /* @__PURE__ */ new Set();
|
|
394
|
-
for (let n2 of
|
|
434
|
+
for (let n2 of z(e11, qe)) n2.length === Je * 2 && !t2.has(n2) && (t2.add(n2), yield `vault_${n2}`);
|
|
395
435
|
}
|
|
396
|
-
async function
|
|
436
|
+
async function Xe(e11, t2) {
|
|
397
437
|
let n2 = (await e11.getSubstate(t2)).substate;
|
|
398
|
-
return
|
|
438
|
+
return Qe(n2) ? Array.from(Ye(n2.Component.body.state)) : [];
|
|
399
439
|
}
|
|
400
|
-
function*
|
|
440
|
+
function* z(e11, t2) {
|
|
401
441
|
if (Array.isArray(e11)) {
|
|
402
|
-
for (let n3 of e11) yield*
|
|
442
|
+
for (let n3 of e11) yield* z(n3, t2);
|
|
403
443
|
return;
|
|
404
444
|
}
|
|
405
445
|
if (typeof e11 != "object" || !e11) return;
|
|
@@ -408,101 +448,101 @@ function* B(e11, t2) {
|
|
|
408
448
|
if (r2 === "tag") {
|
|
409
449
|
let e12 = n2.value;
|
|
410
450
|
if (n2.tag === t2) {
|
|
411
|
-
let t3 =
|
|
451
|
+
let t3 = Ze(e12);
|
|
412
452
|
t3 !== null && (yield t3);
|
|
413
453
|
}
|
|
414
|
-
yield*
|
|
454
|
+
yield* z(e12, t2);
|
|
415
455
|
} else if (r2 === "map") {
|
|
416
456
|
let e12 = n2.entries;
|
|
417
|
-
if (Array.isArray(e12)) for (let n3 of e12) Array.isArray(n3) && n3.length === 2 && (yield*
|
|
457
|
+
if (Array.isArray(e12)) for (let n3 of e12) Array.isArray(n3) && n3.length === 2 && (yield* z(n3[0], t2), yield* z(n3[1], t2));
|
|
418
458
|
}
|
|
419
459
|
return;
|
|
420
460
|
}
|
|
421
|
-
for (let e12 of Object.values(n2)) yield*
|
|
461
|
+
for (let e12 of Object.values(n2)) yield* z(e12, t2);
|
|
422
462
|
}
|
|
423
|
-
function
|
|
463
|
+
function Ze(e11) {
|
|
424
464
|
if (typeof e11 != "object" || !e11) return null;
|
|
425
465
|
let t2 = e11;
|
|
426
466
|
if (t2["@cbor"] !== "bytes") return null;
|
|
427
467
|
let n2 = t2.hex;
|
|
428
468
|
return typeof n2 == "string" ? n2 : null;
|
|
429
469
|
}
|
|
430
|
-
function
|
|
470
|
+
function Qe(e11) {
|
|
431
471
|
return typeof e11 == "object" && !!e11 && "Component" in e11;
|
|
432
472
|
}
|
|
433
|
-
var
|
|
434
|
-
function
|
|
473
|
+
var $e = "resource_0101010101010101010101010101010101010101010101010101010101010101", et = "component_0102030000000000000000000000000000000000000000000000000000000000", tt = "vault_0102030000000000000000000000000000000000000000000000000000000001", nt = "resource_0102030000000000000000000000000000000000000000000000000000000002", rt = "__ootleRawJson", it = "stealth_revealed_input", at = "stealth_revealed_change";
|
|
474
|
+
function ot(e11, t2) {
|
|
435
475
|
let n2 = e11.revealedInputBucket === null ? null : t2(e11.revealedInputBucket);
|
|
436
476
|
return { StealthTransfer: {
|
|
437
477
|
resource_address_ref: { Address: e11.resourceAddress },
|
|
438
|
-
statement:
|
|
478
|
+
statement: B(e11.statement),
|
|
439
479
|
revealed_input_bucket: n2
|
|
440
480
|
} };
|
|
441
481
|
}
|
|
442
|
-
function
|
|
443
|
-
return { [
|
|
482
|
+
function B(e11) {
|
|
483
|
+
return { [rt]: e11.toCompactJson() };
|
|
444
484
|
}
|
|
445
|
-
function
|
|
485
|
+
function V(e11) {
|
|
446
486
|
return typeof e11 == "object" && !!e11 && "StealthTransfer" in e11;
|
|
447
487
|
}
|
|
448
|
-
function
|
|
488
|
+
function H(e11) {
|
|
449
489
|
let t2 = [], n2 = (e12) => `__ootleRawJson:${e12}__`, r2 = JSON.stringify(e11, (e12, r3) => {
|
|
450
490
|
if (typeof r3 == "object" && r3 && "__ootleRawJson" in r3) {
|
|
451
491
|
let e13 = n2(t2.length);
|
|
452
|
-
return t2.push(r3[
|
|
492
|
+
return t2.push(r3[rt]), e13;
|
|
453
493
|
}
|
|
454
494
|
return r3;
|
|
455
495
|
});
|
|
456
496
|
for (let e12 = 0; e12 < t2.length; e12++) {
|
|
457
497
|
let i2 = JSON.stringify(n2(e12)), a2 = r2.indexOf(i2);
|
|
458
|
-
if (a2 < 0) throw new
|
|
459
|
-
if (r2.indexOf(i2, a2 + i2.length) >= 0) throw new
|
|
498
|
+
if (a2 < 0) throw new _(`serializeUnsignedTx: raw-JSON placeholder ${e12} was not emitted`);
|
|
499
|
+
if (r2.indexOf(i2, a2 + i2.length) >= 0) throw new _(`serializeUnsignedTx: raw-JSON placeholder ${e12} collided with transaction data`);
|
|
460
500
|
r2 = r2.slice(0, a2) + t2[e12] + r2.slice(a2 + i2.length);
|
|
461
501
|
}
|
|
462
502
|
return r2;
|
|
463
503
|
}
|
|
464
|
-
async function
|
|
504
|
+
async function U(e11, t2) {
|
|
465
505
|
let n2 = await e11.resolveInputs(t2.inputs);
|
|
466
506
|
return {
|
|
467
507
|
...t2,
|
|
468
508
|
inputs: n2
|
|
469
509
|
};
|
|
470
510
|
}
|
|
471
|
-
function
|
|
511
|
+
function st() {
|
|
472
512
|
let { secret_key: e11, public_key: t2 } = a();
|
|
473
513
|
return {
|
|
474
514
|
secret_key: e11,
|
|
475
515
|
public_key: t2
|
|
476
516
|
};
|
|
477
517
|
}
|
|
478
|
-
function
|
|
518
|
+
function ct(e11, t2) {
|
|
479
519
|
return {
|
|
480
|
-
public_key:
|
|
520
|
+
public_key: y(v(e11, 32, "publicKey")),
|
|
481
521
|
signature: {
|
|
482
|
-
public_nonce:
|
|
483
|
-
signature:
|
|
522
|
+
public_nonce: y(v(t2.public_nonce, 32, "schnorr.public_nonce")),
|
|
523
|
+
signature: y(v(t2.signature, 32, "schnorr.signature"))
|
|
484
524
|
}
|
|
485
525
|
};
|
|
486
526
|
}
|
|
487
|
-
async function
|
|
488
|
-
let r2 = n2 ?? a(), i2 =
|
|
527
|
+
async function W(e11, t2, n2) {
|
|
528
|
+
let r2 = n2 ?? a(), i2 = v(r2.secret_key, 32, "sealKeypair.secret_key"), o2 = v(r2.public_key, 32, "sealKeypair.public_key"), s2 = [];
|
|
489
529
|
for (let n3 of e11) {
|
|
490
530
|
let e12 = await n3.signTransaction(t2, o2);
|
|
491
531
|
s2.push(...e12);
|
|
492
532
|
}
|
|
493
|
-
let c2 =
|
|
533
|
+
let c2 = ee(`{"transaction":${H(t2)},"signatures":${JSON.stringify(s2)}}`, i2);
|
|
494
534
|
return {
|
|
495
535
|
sealedJson: c2,
|
|
496
536
|
transaction: JSON.parse(c2)
|
|
497
537
|
};
|
|
498
538
|
}
|
|
499
|
-
function
|
|
539
|
+
function G(e11) {
|
|
500
540
|
return t(e11.sealedJson);
|
|
501
541
|
}
|
|
502
|
-
async function
|
|
542
|
+
async function lt(e11, t2) {
|
|
503
543
|
return (await e11.submitTransaction(t2)).transaction_id;
|
|
504
544
|
}
|
|
505
|
-
function
|
|
545
|
+
function ut(e11) {
|
|
506
546
|
var _a, _b;
|
|
507
547
|
if (e11 === "Pending" || !("Finalized" in e11)) return null;
|
|
508
548
|
let t2 = e11.Finalized, n2 = t2.final_decision;
|
|
@@ -518,42 +558,42 @@ function st(e11) {
|
|
|
518
558
|
reason: e12
|
|
519
559
|
};
|
|
520
560
|
}
|
|
521
|
-
throw new
|
|
561
|
+
throw new _(`Unexpected final_decision variant: ${JSON.stringify(n2)}`);
|
|
522
562
|
}
|
|
523
|
-
async function
|
|
563
|
+
async function dt(e11, t2, n2) {
|
|
524
564
|
let r2 = (n2 == null ? void 0 : n2.pollIntervalMs) ?? 500, i2 = (n2 == null ? void 0 : n2.timeoutMs) ?? 6e4, a2 = Date.now() + i2;
|
|
525
565
|
for (; ; ) {
|
|
526
566
|
let n3 = await e11.getTransactionResult(t2), o2 = n3.result;
|
|
527
567
|
if (o2 !== "Pending" && "Finalized" in o2) {
|
|
528
|
-
let { outcome: e12, reason: r3 } =
|
|
529
|
-
if (e12 === "Reject") throw new
|
|
568
|
+
let { outcome: e12, reason: r3 } = ut(o2) ?? { outcome: "Reject" };
|
|
569
|
+
if (e12 === "Reject") throw new d(`Transaction ${t2} was rejected: ${r3}`, {
|
|
530
570
|
txId: t2,
|
|
531
571
|
reason: r3 ?? ""
|
|
532
572
|
});
|
|
533
|
-
if (e12 === "FeeIntentCommit") throw new
|
|
573
|
+
if (e12 === "FeeIntentCommit") throw new d(`Transaction ${t2} only committed fees (execution aborted): ${r3}`, {
|
|
534
574
|
txId: t2,
|
|
535
575
|
reason: `FeeIntentCommit: ${r3 ?? ""}`
|
|
536
576
|
});
|
|
537
577
|
return n3;
|
|
538
578
|
}
|
|
539
|
-
if (Date.now() >= a2) throw new
|
|
579
|
+
if (Date.now() >= a2) throw new oe(`Transaction ${t2} did not finalize within ${i2}ms`, { txId: t2 });
|
|
540
580
|
await new Promise((e12) => setTimeout(e12, r2));
|
|
541
581
|
}
|
|
542
582
|
}
|
|
543
|
-
async function
|
|
544
|
-
let i2 = await
|
|
545
|
-
return
|
|
583
|
+
async function ft(e11, t2, n2, r2) {
|
|
584
|
+
let i2 = await U(e11, n2);
|
|
585
|
+
return dt(e11, await lt(e11, G(await W(Array.isArray(t2) ? t2 : [t2], i2))), r2);
|
|
546
586
|
}
|
|
547
|
-
async function
|
|
548
|
-
return
|
|
587
|
+
async function pt(e11, t2, n2, r2) {
|
|
588
|
+
return ft(e11, t2, {
|
|
549
589
|
...n2,
|
|
550
590
|
dry_run: true
|
|
551
591
|
}, r2);
|
|
552
592
|
}
|
|
553
|
-
var
|
|
593
|
+
var mt = class {
|
|
554
594
|
constructor(e11) {
|
|
555
595
|
__publicField(this, "builder");
|
|
556
|
-
this.builder =
|
|
596
|
+
this.builder = R.new(e11);
|
|
557
597
|
}
|
|
558
598
|
withInputs(e11) {
|
|
559
599
|
return this.builder.withInputs(e11), this;
|
|
@@ -565,7 +605,7 @@ var dt = class {
|
|
|
565
605
|
return this.builder.callMethod({
|
|
566
606
|
componentAddress: e11,
|
|
567
607
|
methodName: "withdraw"
|
|
568
|
-
}, [
|
|
608
|
+
}, [A(t2), L(n2)]).saveVar("bucket").callMethod({
|
|
569
609
|
componentAddress: r2,
|
|
570
610
|
methodName: "deposit"
|
|
571
611
|
}, [{ Workspace: "bucket" }]), this;
|
|
@@ -576,11 +616,11 @@ var dt = class {
|
|
|
576
616
|
build() {
|
|
577
617
|
return this.builder.buildUnsignedTransaction();
|
|
578
618
|
}
|
|
579
|
-
},
|
|
619
|
+
}, ht = class {
|
|
580
620
|
constructor(e11, t2) {
|
|
581
621
|
__publicField(this, "builder");
|
|
582
622
|
__publicField(this, "faucetAddress");
|
|
583
|
-
this.builder =
|
|
623
|
+
this.builder = R.new(e11), this.faucetAddress = t2;
|
|
584
624
|
}
|
|
585
625
|
feeTransactionPayFromComponent(e11, t2) {
|
|
586
626
|
return this.builder.feeTransactionPayFromComponent(e11, t2), this;
|
|
@@ -589,7 +629,7 @@ var dt = class {
|
|
|
589
629
|
return this.builder.callMethod({
|
|
590
630
|
componentAddress: this.faucetAddress,
|
|
591
631
|
methodName: "take_free_coins"
|
|
592
|
-
}, [
|
|
632
|
+
}, [L(t2)]).saveVar("faucet_bucket").callMethod({
|
|
593
633
|
componentAddress: e11,
|
|
594
634
|
methodName: "deposit"
|
|
595
635
|
}, [{ Workspace: "faucet_bucket" }]), this;
|
|
@@ -613,7 +653,7 @@ var dt = class {
|
|
|
613
653
|
build() {
|
|
614
654
|
return this.builder.buildUnsignedTransaction();
|
|
615
655
|
}
|
|
616
|
-
},
|
|
656
|
+
}, gt = class {
|
|
617
657
|
constructor() {
|
|
618
658
|
__publicField(this, "keyProviders");
|
|
619
659
|
__publicField(this, "defaultSignerAddress", null);
|
|
@@ -626,7 +666,7 @@ var dt = class {
|
|
|
626
666
|
return this.requireKeyProvider(e11, "explicit"), this.defaultSignerAddress = e11, this;
|
|
627
667
|
}
|
|
628
668
|
async getAddress() {
|
|
629
|
-
if (!this.defaultSignerAddress) throw new
|
|
669
|
+
if (!this.defaultSignerAddress) throw new m("No default signer address set. Call setDefaultSigner() first.");
|
|
630
670
|
return Promise.resolve(this.defaultSignerAddress);
|
|
631
671
|
}
|
|
632
672
|
async getPublicKey() {
|
|
@@ -651,26 +691,26 @@ var dt = class {
|
|
|
651
691
|
return [...this.keyProviders.keys()];
|
|
652
692
|
}
|
|
653
693
|
getSignerOrThrow() {
|
|
654
|
-
if (!this.defaultSignerAddress) throw new
|
|
694
|
+
if (!this.defaultSignerAddress) throw new m("No default signer address set. Call setDefaultSigner() first.");
|
|
655
695
|
return this.requireKeyProvider(this.defaultSignerAddress, "default");
|
|
656
696
|
}
|
|
657
697
|
requireKeyProvider(e11, t2) {
|
|
658
698
|
let n2 = this.keyProviders.get(e11);
|
|
659
|
-
if (n2 === void 0) throw new
|
|
699
|
+
if (n2 === void 0) throw new p(t2 === "default" ? `No key provider registered for default address: ${e11}. Call wallet.registerKeyProvider(address, signer) for that address, or pick a different default with setDefaultSigner(otherAddress).` : `No key provider registered for address: ${e11}. Call wallet.registerKeyProvider(${JSON.stringify(e11)}, signer) before signing.`, { address: e11 });
|
|
660
700
|
return n2;
|
|
661
701
|
}
|
|
662
|
-
},
|
|
702
|
+
}, _t = class {
|
|
663
703
|
constructor(e11, t2) {
|
|
664
704
|
__publicField(this, "bytes");
|
|
665
|
-
this.bytes = new Uint8Array(
|
|
705
|
+
this.bytes = new Uint8Array(v(e11, 32, t2));
|
|
666
706
|
}
|
|
667
707
|
toBytes() {
|
|
668
708
|
return new Uint8Array(this.bytes);
|
|
669
709
|
}
|
|
670
710
|
toHex() {
|
|
671
|
-
return
|
|
711
|
+
return y(this.bytes);
|
|
672
712
|
}
|
|
673
|
-
},
|
|
713
|
+
}, K = class e3 extends _t {
|
|
674
714
|
constructor(e11) {
|
|
675
715
|
super(e11, "Mask");
|
|
676
716
|
}
|
|
@@ -681,44 +721,44 @@ var dt = class {
|
|
|
681
721
|
return new e3(t2);
|
|
682
722
|
}
|
|
683
723
|
static fromHex(t2) {
|
|
684
|
-
return new e3(
|
|
724
|
+
return new e3(b(t2));
|
|
685
725
|
}
|
|
686
|
-
},
|
|
726
|
+
}, vt = class e4 {
|
|
687
727
|
constructor(e11) {
|
|
688
728
|
__publicField(this, "bytes");
|
|
689
729
|
this.bytes = new Uint8Array(e11);
|
|
690
730
|
}
|
|
691
731
|
static fromHex(t2) {
|
|
692
|
-
return new e4(
|
|
732
|
+
return new e4(b(t2));
|
|
693
733
|
}
|
|
694
734
|
toBytes() {
|
|
695
735
|
return new Uint8Array(this.bytes);
|
|
696
736
|
}
|
|
697
737
|
toHex() {
|
|
698
|
-
return
|
|
738
|
+
return y(this.bytes);
|
|
699
739
|
}
|
|
700
|
-
},
|
|
701
|
-
function
|
|
702
|
-
if (e11.amount <= 0n) throw new
|
|
740
|
+
}, yt = Object.freeze({ StealthPublicKey: Object.freeze({}) });
|
|
741
|
+
function bt(e11) {
|
|
742
|
+
if (e11.amount <= 0n) throw new _(`Output amount must be > 0, got ${e11.amount}`);
|
|
703
743
|
return {
|
|
704
744
|
destination: e11.destination,
|
|
705
745
|
amount: e11.amount,
|
|
706
746
|
resourceAddress: e11.resourceAddress,
|
|
707
747
|
resourceViewKey: e11.resourceViewKey === void 0 ? void 0 : new Uint8Array(e11.resourceViewKey),
|
|
708
748
|
memo: e11.memo,
|
|
709
|
-
payTo: e11.payTo ??
|
|
749
|
+
payTo: e11.payTo ?? yt,
|
|
710
750
|
minimumValuePromise: e11.minimumValuePromise ?? 0n
|
|
711
751
|
};
|
|
712
752
|
}
|
|
713
|
-
function
|
|
714
|
-
if (e11.trim() === "") throw new
|
|
753
|
+
function xt(e11, t2) {
|
|
754
|
+
if (e11.trim() === "") throw new _(`${t2} must be a non-empty decimal string`);
|
|
715
755
|
return BigInt(e11);
|
|
716
756
|
}
|
|
717
|
-
function
|
|
757
|
+
function St(e11, t2) {
|
|
718
758
|
let n2 = e11.trim();
|
|
719
|
-
if (!n2.startsWith("{") || !n2.endsWith("}")) throw new
|
|
759
|
+
if (!n2.startsWith("{") || !n2.endsWith("}")) throw new _(`StealthTransferStatement.toCompactJson: ${t2} fragment is not a JSON object (got: ${e11.slice(0, 60)}...)`);
|
|
720
760
|
}
|
|
721
|
-
var
|
|
761
|
+
var q = class e5 extends _t {
|
|
722
762
|
constructor(e11) {
|
|
723
763
|
super(e11, "StealthInput.commitment");
|
|
724
764
|
}
|
|
@@ -729,13 +769,13 @@ var J = class e5 extends mt {
|
|
|
729
769
|
return { commitment: this.toHex() };
|
|
730
770
|
}
|
|
731
771
|
static fromJSON(t2) {
|
|
732
|
-
return new e5(
|
|
772
|
+
return new e5(b(t2.commitment));
|
|
733
773
|
}
|
|
734
|
-
},
|
|
774
|
+
}, J = class e6 {
|
|
735
775
|
constructor(e11, t2) {
|
|
736
776
|
__publicField(this, "_publicNonce");
|
|
737
777
|
__publicField(this, "_signature");
|
|
738
|
-
this._publicNonce = new Uint8Array(
|
|
778
|
+
this._publicNonce = new Uint8Array(v(e11, 32, "BalanceProofSignature.publicNonce")), this._signature = new Uint8Array(v(t2, 32, "BalanceProofSignature.signature"));
|
|
739
779
|
}
|
|
740
780
|
get publicNonce() {
|
|
741
781
|
return new Uint8Array(this._publicNonce);
|
|
@@ -745,14 +785,14 @@ var J = class e5 extends mt {
|
|
|
745
785
|
}
|
|
746
786
|
toJSON() {
|
|
747
787
|
return {
|
|
748
|
-
public_nonce:
|
|
749
|
-
signature:
|
|
788
|
+
public_nonce: y(this._publicNonce),
|
|
789
|
+
signature: y(this._signature)
|
|
750
790
|
};
|
|
751
791
|
}
|
|
752
792
|
static fromJSON(t2) {
|
|
753
|
-
return new e6(
|
|
793
|
+
return new e6(b(t2.public_nonce), b(t2.signature));
|
|
754
794
|
}
|
|
755
|
-
},
|
|
795
|
+
}, Y = class e7 {
|
|
756
796
|
constructor(e11, t2, n2) {
|
|
757
797
|
__publicField(this, "inputs");
|
|
758
798
|
__publicField(this, "revealedAmount");
|
|
@@ -765,13 +805,13 @@ var J = class e5 extends mt {
|
|
|
765
805
|
toJSON() {
|
|
766
806
|
return {
|
|
767
807
|
inputs: this.inputs.map((e11) => e11.toJSON()),
|
|
768
|
-
revealed_amount:
|
|
808
|
+
revealed_amount: ze(this.revealedAmount)
|
|
769
809
|
};
|
|
770
810
|
}
|
|
771
811
|
static fromJSON(t2) {
|
|
772
|
-
return new e7(t2.inputs.map(
|
|
812
|
+
return new e7(t2.inputs.map(q.fromJSON), xt(t2.revealed_amount, "revealed_amount"));
|
|
773
813
|
}
|
|
774
|
-
},
|
|
814
|
+
}, X = class e8 {
|
|
775
815
|
constructor(e11) {
|
|
776
816
|
__publicField(this, "statementJson");
|
|
777
817
|
this.statementJson = e11;
|
|
@@ -801,84 +841,84 @@ var J = class e5 extends mt {
|
|
|
801
841
|
}
|
|
802
842
|
toCompactJson() {
|
|
803
843
|
let e11 = this.inputsStatement.statementJson ?? JSON.stringify(this.inputsStatement.toJSON()), t2 = this.outputsStatement.statementJson;
|
|
804
|
-
|
|
805
|
-
let n2 = `{"inputs_statement":${e11},"outputs_statement":${t2}`;
|
|
844
|
+
St(e11, "inputs_statement"), St(t2, "outputs_statement");
|
|
845
|
+
let n2 = `{"inputs_statement":${e11},"outputs_statement":${t2},"covenant_claims":[]`;
|
|
806
846
|
return this.balanceProof !== void 0 && (n2 += `,"balance_proof":${JSON.stringify(this.balanceProof.toJSON())}`), n2 + "}";
|
|
807
847
|
}
|
|
808
848
|
static fromJSON(t2) {
|
|
809
|
-
return new e9(
|
|
849
|
+
return new e9(Y.fromJSON(t2.inputs), X.fromJSON(t2.outputs), t2.balance_proof === void 0 ? void 0 : J.fromJSON(t2.balance_proof));
|
|
810
850
|
}
|
|
811
851
|
};
|
|
812
|
-
function
|
|
852
|
+
function Ct(e11, t2) {
|
|
813
853
|
let n2 = new Uint8Array(e11.length * 32);
|
|
814
854
|
for (let r2 = 0; r2 < e11.length; r2++) {
|
|
815
855
|
let i2 = e11[r2];
|
|
816
|
-
|
|
856
|
+
v(i2, 32, `${t2}[${r2}]`), n2.set(i2, r2 * 32);
|
|
817
857
|
}
|
|
818
858
|
return n2;
|
|
819
859
|
}
|
|
820
|
-
var
|
|
821
|
-
constructor(e11 =
|
|
860
|
+
var Q = class {
|
|
861
|
+
constructor(e11 = l.LocalNet) {
|
|
822
862
|
__publicField(this, "network");
|
|
823
863
|
this.network = e11;
|
|
824
864
|
}
|
|
825
865
|
async generateOutputsStatement(e11, t2) {
|
|
826
866
|
let n2 = s(`[${e11.map((e12) => this.outputWitness(e12)).join(",")}]`, t2);
|
|
827
|
-
return
|
|
828
|
-
statement:
|
|
829
|
-
outputMask:
|
|
867
|
+
return v(n2.aggregated_output_mask, 32, "StealthOutputsResult.aggregated_output_mask"), {
|
|
868
|
+
statement: X.fromJSON(n2.statement_json),
|
|
869
|
+
outputMask: K.fromBytes(n2.aggregated_output_mask)
|
|
830
870
|
};
|
|
831
871
|
}
|
|
832
872
|
outputWitness(e11) {
|
|
833
|
-
let t2 = c(e11.destination), n2 =
|
|
873
|
+
let t2 = c(e11.destination), n2 = wt(e11.payTo) ? null : JSON.stringify(e11.payTo), i2 = e11.memo === void 0 ? null : JSON.stringify(e11.memo), a2 = e11.resourceViewKey ?? null;
|
|
834
874
|
return r(this.network, t2.owner_key, t2.view_key, e11.amount, e11.resourceAddress, a2, i2, n2, e11.minimumValuePromise);
|
|
835
875
|
}
|
|
836
876
|
async buildInputsStatement(e11, t2) {
|
|
837
|
-
return new
|
|
877
|
+
return new Y(e11, t2, n(Ct(e11.map((e12) => e12.commitment), "input commitment"), t2));
|
|
838
878
|
}
|
|
839
879
|
async generateBalanceProofSignature(e11, t2, n2, r2) {
|
|
840
880
|
let i2 = o(e11.toBytes(), t2.toBytes(), n2, r2);
|
|
841
|
-
return
|
|
881
|
+
return v(i2.public_nonce, 32, "balance proof public_nonce"), v(i2.signature, 32, "balance proof signature"), new J(i2.public_nonce, i2.signature);
|
|
842
882
|
}
|
|
843
883
|
async validateBalanceProofSignature(e11, t2, n2) {
|
|
844
|
-
return
|
|
884
|
+
return re(e11.publicNonce, e11.signature, t2, n2);
|
|
845
885
|
}
|
|
846
886
|
async deriveAeadKey(e11, t2) {
|
|
847
|
-
|
|
887
|
+
v(e11, 32, "deriveAeadKey privateKey"), v(t2, 32, "deriveAeadKey publicKey");
|
|
848
888
|
let n2 = i(e11, t2);
|
|
849
|
-
return
|
|
889
|
+
return v(n2, 32, "derived AEAD key"), n2;
|
|
850
890
|
}
|
|
851
891
|
async unblindOutput(e11, t2, n2, r2) {
|
|
852
|
-
|
|
853
|
-
let i2 =
|
|
892
|
+
v(e11, 32, "unblindOutput commitment"), v(n2, 32, "unblindOutput aeadKey");
|
|
893
|
+
let i2 = ne(e11, t2, n2, r2);
|
|
854
894
|
return {
|
|
855
|
-
mask:
|
|
895
|
+
mask: K.fromBytes(i2.mask),
|
|
856
896
|
value: i2.value,
|
|
857
897
|
memo: i2.memo_json ?? void 0
|
|
858
898
|
};
|
|
859
899
|
}
|
|
860
900
|
async aggregateInputMasks(t2) {
|
|
861
|
-
let n2 = e(
|
|
862
|
-
return
|
|
901
|
+
let n2 = e(Ct(t2.map((e11) => e11.toBytes()), "input mask"));
|
|
902
|
+
return K.fromBytes(n2);
|
|
863
903
|
}
|
|
864
904
|
async stealthDhSecret(e11, t2, n2) {
|
|
865
|
-
|
|
866
|
-
let r2 =
|
|
867
|
-
return
|
|
905
|
+
v(t2, 32, "stealthDhSecret ownerSecret"), v(n2, 32, "stealthDhSecret publicNonce");
|
|
906
|
+
let r2 = te(e11, t2, n2);
|
|
907
|
+
return v(r2, 32, "stealth DH secret"), r2;
|
|
868
908
|
}
|
|
869
909
|
async validateTransfer(e11) {
|
|
870
|
-
|
|
910
|
+
ie(e11.toCompactJson(), null);
|
|
871
911
|
}
|
|
872
912
|
};
|
|
873
|
-
function
|
|
913
|
+
function wt(e11) {
|
|
874
914
|
let t2 = Object.keys(e11);
|
|
875
915
|
if (t2.length !== 1 || t2[0] !== "StealthPublicKey") return false;
|
|
876
916
|
let n2 = e11.StealthPublicKey;
|
|
877
917
|
return typeof n2 == "object" && !!n2 && Object.keys(n2).length === 0;
|
|
878
918
|
}
|
|
879
|
-
var
|
|
880
|
-
function
|
|
881
|
-
return `${
|
|
919
|
+
var Tt = "utxo";
|
|
920
|
+
function $(e11, t2) {
|
|
921
|
+
return `${Tt}_${e11.startsWith("resource_") ? e11.slice(9) : e11}_${y(t2)}`;
|
|
882
922
|
}
|
|
883
923
|
var Et = 64;
|
|
884
924
|
function Dt(e11) {
|
|
@@ -889,9 +929,9 @@ function Ot(e11) {
|
|
|
889
929
|
}
|
|
890
930
|
function kt(e11) {
|
|
891
931
|
let t2 = e11.split("_");
|
|
892
|
-
if (t2.length < 3 || t2[0] !==
|
|
932
|
+
if (t2.length < 3 || t2[0] !== Tt) return null;
|
|
893
933
|
let n2 = t2[t2.length - 1];
|
|
894
|
-
return n2.length !== Et || !Ot(n2) ? null :
|
|
934
|
+
return n2.length !== Et || !Ot(n2) ? null : b(n2);
|
|
895
935
|
}
|
|
896
936
|
function At(e11, t2) {
|
|
897
937
|
let n2 = e11.substate;
|
|
@@ -905,13 +945,13 @@ function At(e11, t2) {
|
|
|
905
945
|
};
|
|
906
946
|
}
|
|
907
947
|
var jt = class {
|
|
908
|
-
constructor(e11, t2, n2 = new
|
|
948
|
+
constructor(e11, t2, n2 = new Q(e11.network())) {
|
|
909
949
|
__publicField(this, "provider");
|
|
910
950
|
__publicField(this, "crypto");
|
|
911
951
|
__publicField(this, "builder");
|
|
912
952
|
__publicField(this, "state");
|
|
913
953
|
__publicField(this, "prepared", false);
|
|
914
|
-
this.provider = e11, this.crypto = n2, this.builder =
|
|
954
|
+
this.provider = e11, this.crypto = n2, this.builder = R.new(e11.network()), this.state = {
|
|
915
955
|
resource: t2,
|
|
916
956
|
revealedInput: null,
|
|
917
957
|
inputsToSpend: /* @__PURE__ */ new Map(),
|
|
@@ -920,9 +960,9 @@ var jt = class {
|
|
|
920
960
|
};
|
|
921
961
|
}
|
|
922
962
|
spendRevealedInput(e11, t2) {
|
|
923
|
-
if (t2 <= 0n) throw new
|
|
963
|
+
if (t2 <= 0n) throw new _(`spendRevealedInput amount must be > 0, got ${t2}`);
|
|
924
964
|
let n2 = this.state.revealedInput;
|
|
925
|
-
if (n2 !== null && n2.source !== e11) throw new
|
|
965
|
+
if (n2 !== null && n2.source !== e11) throw new _(`spendRevealedInput: all revealed input must come from one account (${n2.source} != ${e11})`);
|
|
926
966
|
return this.state.revealedInput = {
|
|
927
967
|
source: e11,
|
|
928
968
|
amount: ((n2 == null ? void 0 : n2.amount) ?? 0n) + t2
|
|
@@ -932,20 +972,20 @@ var jt = class {
|
|
|
932
972
|
return this.state.outputs.push(e11), this;
|
|
933
973
|
}
|
|
934
974
|
toRevealedOutput(e11) {
|
|
935
|
-
if (e11 <= 0n) throw new
|
|
975
|
+
if (e11 <= 0n) throw new _(`toRevealedOutput amount must be > 0, got ${e11}`);
|
|
936
976
|
return this.state.revealedOutputAmount += e11, this;
|
|
937
977
|
}
|
|
938
978
|
payFeeFromRevealed(e11) {
|
|
939
|
-
if (this.state.revealedInput === null) throw new
|
|
940
|
-
if (e11 <= 0n) throw new
|
|
979
|
+
if (this.state.revealedInput === null) throw new _("payFeeFromRevealed: call spendRevealedInput first to set the source account");
|
|
980
|
+
if (e11 <= 0n) throw new _(`payFeeFromRevealed amount must be > 0, got ${e11}`);
|
|
941
981
|
return this.builder.feeTransactionPayFromComponent(this.state.revealedInput.source, e11), this;
|
|
942
982
|
}
|
|
943
983
|
withBuilder(e11) {
|
|
944
984
|
return this.builder = e11(this.builder), this;
|
|
945
985
|
}
|
|
946
986
|
spendStealthInput(e11, t2) {
|
|
947
|
-
let n2 = new
|
|
948
|
-
if (i2 !== void 0) throw new
|
|
987
|
+
let n2 = new q(t2), r2 = y(n2.commitment), i2 = this.state.inputsToSpend.get(r2);
|
|
988
|
+
if (i2 !== void 0) throw new _(`spendStealthInput: duplicate commitment ${r2} \u2014 each commitment is one UTXO and may be spent once (already added for owner ${i2.owner}). A commitment uniquely identifies a UTXO; adding it again (even under a different owner) would self-double-spend.`);
|
|
949
989
|
return this.state.inputsToSpend.set(r2, {
|
|
950
990
|
input: n2,
|
|
951
991
|
owner: e11
|
|
@@ -953,7 +993,7 @@ var jt = class {
|
|
|
953
993
|
}
|
|
954
994
|
async prepare() {
|
|
955
995
|
var _a;
|
|
956
|
-
if (this.prepared) throw new
|
|
996
|
+
if (this.prepared) throw new _("StealthTransfer.prepare: already prepared \u2014 create a new StealthTransfer to build again");
|
|
957
997
|
this.validate(), this.prepared = true;
|
|
958
998
|
let { statement: e11, outputMask: t2 } = await this.crypto.generateOutputsStatement(this.state.outputs, this.state.revealedOutputAmount), n2 = new Z(await this.crypto.buildInputsStatement([...this.state.inputsToSpend.values()].map((e12) => e12.input), ((_a = this.state.revealedInput) == null ? void 0 : _a.amount) ?? 0n), e11, void 0);
|
|
959
999
|
this.emitInstructions(n2);
|
|
@@ -964,20 +1004,20 @@ var jt = class {
|
|
|
964
1004
|
substate_id: e12,
|
|
965
1005
|
version: null
|
|
966
1006
|
}), r2.add(e12);
|
|
967
|
-
let t3 = await
|
|
1007
|
+
let t3 = await Xe(this.provider, e12);
|
|
968
1008
|
for (let e13 of t3) r2.has(e13) || (this.builder.addInput({
|
|
969
1009
|
substate_id: e13,
|
|
970
1010
|
version: null
|
|
971
1011
|
}), r2.add(e13));
|
|
972
1012
|
}
|
|
973
1013
|
for (let { input: e12 } of this.state.inputsToSpend.values()) {
|
|
974
|
-
let t3 =
|
|
1014
|
+
let t3 = $(this.state.resource, e12.commitment);
|
|
975
1015
|
r2.has(t3) || (this.builder.addInput({
|
|
976
1016
|
substate_id: t3,
|
|
977
1017
|
version: null
|
|
978
1018
|
}), r2.add(t3));
|
|
979
1019
|
}
|
|
980
|
-
let i2 = await
|
|
1020
|
+
let i2 = await U(this.provider, this.builder.buildUnsignedTransaction()), a2 = [...this.state.inputsToSpend.values()], o2 = this.collectRequiredSigners(a2);
|
|
981
1021
|
return {
|
|
982
1022
|
unsignedTx: i2,
|
|
983
1023
|
statement: n2,
|
|
@@ -996,13 +1036,13 @@ var jt = class {
|
|
|
996
1036
|
validate() {
|
|
997
1037
|
var _a;
|
|
998
1038
|
let e11 = this.state.inputsToSpend.size > 0, t2 = ((_a = this.state.revealedInput) == null ? void 0 : _a.amount) ?? 0n;
|
|
999
|
-
if (!(t2 > 0n || e11)) throw new
|
|
1000
|
-
if (this.state.outputs.length === 0 && this.state.revealedOutputAmount === 0n) throw new
|
|
1001
|
-
if (this.state.outputs.length === 0) throw new
|
|
1002
|
-
if (this.state.revealedOutputAmount > 0n && this.state.revealedInput === null) throw new
|
|
1039
|
+
if (!(t2 > 0n || e11)) throw new _("StealthTransfer.prepare: no inputs \u2014 call spendRevealedInput or spendStealthInput first");
|
|
1040
|
+
if (this.state.outputs.length === 0 && this.state.revealedOutputAmount === 0n) throw new _("StealthTransfer.prepare: no outputs \u2014 call toStealthOutput or toRevealedOutput first");
|
|
1041
|
+
if (this.state.outputs.length === 0) throw new _("StealthTransfer.prepare: at least one stealth output is required");
|
|
1042
|
+
if (this.state.revealedOutputAmount > 0n && this.state.revealedInput === null) throw new _("StealthTransfer.prepare: revealed change requires a revealed source account to deposit into");
|
|
1003
1043
|
if (!e11) {
|
|
1004
1044
|
let e12 = this.state.outputs.reduce((e13, t3) => e13 + t3.amount, 0n), n2 = e12 + this.state.revealedOutputAmount, r2 = t2;
|
|
1005
|
-
if (r2 !== n2) throw new
|
|
1045
|
+
if (r2 !== n2) throw new _(`StealthTransfer.prepare: unbalanced transfer \u2014 revealed input ${r2} != stealth out ${e12} + revealed out ${this.state.revealedOutputAmount} (= ${n2})`);
|
|
1006
1046
|
}
|
|
1007
1047
|
}
|
|
1008
1048
|
emitInstructions(e11) {
|
|
@@ -1010,38 +1050,38 @@ var jt = class {
|
|
|
1010
1050
|
t2 !== null && (this.builder.callMethod({
|
|
1011
1051
|
componentAddress: t2.source,
|
|
1012
1052
|
methodName: "withdraw"
|
|
1013
|
-
}, [
|
|
1053
|
+
}, [A(this.state.resource), O(t2.amount)]).saveVar(it), n2 = it), this.builder.addInstruction(ot({
|
|
1014
1054
|
resourceAddress: this.state.resource,
|
|
1015
1055
|
revealedInputBucket: n2,
|
|
1016
1056
|
statement: e11
|
|
1017
|
-
}, (e12) => this.builder.resolveWorkspaceOffsetId(e12))), this.state.revealedOutputAmount > 0n && t2 !== null && this.builder.saveVar(
|
|
1057
|
+
}, (e12) => this.builder.resolveWorkspaceOffsetId(e12))), this.state.revealedOutputAmount > 0n && t2 !== null && this.builder.saveVar(at).callMethod({
|
|
1018
1058
|
componentAddress: t2.source,
|
|
1019
1059
|
methodName: "deposit"
|
|
1020
|
-
}, [{ Workspace:
|
|
1060
|
+
}, [{ Workspace: at }]);
|
|
1021
1061
|
}
|
|
1022
1062
|
};
|
|
1023
1063
|
function Mt(e11) {
|
|
1024
1064
|
if (Nt(e11) || e11.statementJson !== void 0) return e11.statementJson;
|
|
1025
|
-
if (e11.inputs.length > 0) throw new
|
|
1065
|
+
if (e11.inputs.length > 0) throw new g("inputs statement has confidential inputs but no WASM statementJson \u2014 call buildInputsStatement first", { context: "statementJsonFor" });
|
|
1026
1066
|
return JSON.stringify(e11.toJSON());
|
|
1027
1067
|
}
|
|
1028
1068
|
function Nt(e11) {
|
|
1029
1069
|
return !("inputs" in e11);
|
|
1030
1070
|
}
|
|
1031
|
-
async function
|
|
1071
|
+
async function Pt(e11, t2, n2, r2, i2) {
|
|
1032
1072
|
let a2 = Mt(r2), o2 = Mt(i2);
|
|
1033
1073
|
return e11.generateBalanceProofSignature(t2, n2, a2, o2);
|
|
1034
1074
|
}
|
|
1035
|
-
async function
|
|
1075
|
+
async function Ft(e11, t2, n2, r2) {
|
|
1036
1076
|
let i2 = await e11.deriveAeadKey(r2.viewSecret, r2.senderPublicNonce);
|
|
1037
1077
|
return e11.unblindOutput(t2, n2, i2, r2.skipMemo);
|
|
1038
1078
|
}
|
|
1039
|
-
async function
|
|
1079
|
+
async function It(e11, t2, n2, r2) {
|
|
1040
1080
|
let i2 = At(n2, r2);
|
|
1041
1081
|
if (i2 === null) return null;
|
|
1042
|
-
let a2 =
|
|
1082
|
+
let a2 = b(i2.body.encrypted_data), o2 = b(i2.body.public_nonce);
|
|
1043
1083
|
try {
|
|
1044
|
-
return await
|
|
1084
|
+
return await Ft(e11, i2.commitment, a2, {
|
|
1045
1085
|
senderPublicNonce: o2,
|
|
1046
1086
|
viewSecret: t2,
|
|
1047
1087
|
skipMemo: false
|
|
@@ -1050,33 +1090,33 @@ async function Pt(e11, t2, n2, r2) {
|
|
|
1050
1090
|
return null;
|
|
1051
1091
|
}
|
|
1052
1092
|
}
|
|
1053
|
-
async function
|
|
1054
|
-
if (t2.length === 0) throw new
|
|
1093
|
+
async function Lt(e11, t2, n2) {
|
|
1094
|
+
if (t2.length === 0) throw new _("generateOutputsStatement: at least one stealth output is required");
|
|
1055
1095
|
let { statement: r2, outputMask: i2 } = await e11.generateOutputsStatement(t2, n2), a2 = await e11.buildInputsStatement([], 0n);
|
|
1056
|
-
return new Z(a2, r2, await
|
|
1096
|
+
return new Z(a2, r2, await Pt(e11, K.zero(), i2, a2, r2));
|
|
1057
1097
|
}
|
|
1058
|
-
var
|
|
1098
|
+
var Rt = class e10 {
|
|
1059
1099
|
constructor(e11, t2, n2, r2, i2) {
|
|
1060
1100
|
this.wallet = e11, this.spec = t2, this.crypto = n2, this.mustSignWithAccountKey = r2, this.viewSecret = i2;
|
|
1061
1101
|
}
|
|
1062
1102
|
static fromSpec(t2, n2, r2 = {}) {
|
|
1063
|
-
return new e10(t2, n2, r2.crypto ?? new
|
|
1103
|
+
return new e10(t2, n2, r2.crypto ?? new Q(), r2.mustSignWithAccountKey ?? true, r2.viewSecret);
|
|
1064
1104
|
}
|
|
1065
1105
|
async prepare(e11) {
|
|
1066
|
-
let t2 = await this.resolveStealthInputs(e11), n2 = t2.length === 0 ?
|
|
1106
|
+
let t2 = await this.resolveStealthInputs(e11), n2 = t2.length === 0 ? K.zero() : await this.crypto.aggregateInputMasks(t2.map((e12) => e12.mask)), r2 = await Pt(this.crypto, n2, this.spec.outputMask, this.spec.statement.inputsStatement, this.spec.statement.outputsStatement), i2 = new Z(this.spec.statement.inputsStatement, this.spec.statement.outputsStatement, r2);
|
|
1067
1107
|
await this.crypto.validateTransfer(i2);
|
|
1068
|
-
let a2 =
|
|
1108
|
+
let a2 = Bt(this.spec.unsignedTx, i2), o2 = {
|
|
1069
1109
|
...this.spec,
|
|
1070
1110
|
unsignedTx: a2,
|
|
1071
1111
|
statement: i2
|
|
1072
1112
|
};
|
|
1073
|
-
return new
|
|
1113
|
+
return new zt({
|
|
1074
1114
|
wallet: this.wallet,
|
|
1075
1115
|
crypto: this.crypto,
|
|
1076
1116
|
spec: o2,
|
|
1077
1117
|
resolvedInputs: t2,
|
|
1078
1118
|
mustSignWithAccountKey: this.mustSignWithAccountKey,
|
|
1079
|
-
sealKeypair:
|
|
1119
|
+
sealKeypair: st()
|
|
1080
1120
|
});
|
|
1081
1121
|
}
|
|
1082
1122
|
async resolveViewSecret() {
|
|
@@ -1085,9 +1125,9 @@ var It = class e10 {
|
|
|
1085
1125
|
if ((e11 == null ? void 0 : e11.getViewSecret) !== void 0) try {
|
|
1086
1126
|
return await e11.getViewSecret();
|
|
1087
1127
|
} catch (e12) {
|
|
1088
|
-
throw e12 instanceof
|
|
1128
|
+
throw e12 instanceof f ? e12 : new f("WalletStealthAuthorizer: spending stealth inputs needs a view secret to unblind them, but the wallet's default signer could not provide one. Pass `fromSpec(wallet, spec, { viewSecret })` or use a SecretKeyWallet (created with a view key) as the default signer.", { cause: e12 });
|
|
1089
1129
|
}
|
|
1090
|
-
throw new
|
|
1130
|
+
throw new f("WalletStealthAuthorizer: spending stealth inputs needs a view secret to unblind them, but none was supplied and the wallet's default signer cannot provide one. Pass `fromSpec(wallet, spec, { viewSecret })` or use a SecretKeyWallet (created with a view key) as the default signer.");
|
|
1091
1131
|
}
|
|
1092
1132
|
async safeDefaultAddress() {
|
|
1093
1133
|
try {
|
|
@@ -1099,19 +1139,19 @@ var It = class e10 {
|
|
|
1099
1139
|
async resolveStealthInputs(e11) {
|
|
1100
1140
|
if (this.spec.inputs.length === 0) return [];
|
|
1101
1141
|
let t2 = await this.resolveViewSecret(), n2 = this.spec.state.resource, r2 = await Promise.allSettled(this.spec.inputs.map(async ({ input: r3, owner: i3 }) => {
|
|
1102
|
-
let a2 =
|
|
1103
|
-
if (o2 === null) throw new
|
|
1104
|
-
let s2 = At(o2,
|
|
1105
|
-
if (s2 === null) throw new
|
|
1106
|
-
let c2 =
|
|
1142
|
+
let a2 = y(r3.commitment), o2 = await e11.getStealthUtxo(n2, r3.commitment);
|
|
1143
|
+
if (o2 === null) throw new f(`WalletStealthAuthorizer.prepare: stealth input UTXO not found (spent or never created) for ${a2}`);
|
|
1144
|
+
let s2 = At(o2, $(n2, r3.commitment));
|
|
1145
|
+
if (s2 === null) throw new f(`WalletStealthAuthorizer.prepare: stealth input ${a2} is not a live, spendable UTXO`);
|
|
1146
|
+
let c2 = b(s2.body.public_nonce), ee2;
|
|
1107
1147
|
try {
|
|
1108
|
-
|
|
1148
|
+
ee2 = await Ft(this.crypto, s2.commitment, b(s2.body.encrypted_data), {
|
|
1109
1149
|
senderPublicNonce: c2,
|
|
1110
1150
|
viewSecret: t2,
|
|
1111
1151
|
skipMemo: true
|
|
1112
1152
|
});
|
|
1113
1153
|
} catch (e12) {
|
|
1114
|
-
throw new
|
|
1154
|
+
throw new g(`WalletStealthAuthorizer.prepare: failed to decrypt stealth input with commitment ${y(r3.commitment)} (owner ${i3}). This usually means the supplied view secret does not own this UTXO. Pass the correct \`viewSecret\` via \`fromSpec(wallet, spec, { viewSecret })\`, or use the owning SecretKeyWallet (with its view key) as the default signer. Note: a single view secret is resolved for all inputs \u2014 spending UTXOs owned by distinct view keys in one transfer is not supported.`, {
|
|
1115
1155
|
cause: e12,
|
|
1116
1156
|
context: "unblindOutput"
|
|
1117
1157
|
});
|
|
@@ -1119,14 +1159,14 @@ var It = class e10 {
|
|
|
1119
1159
|
return {
|
|
1120
1160
|
ownerAddr: i3,
|
|
1121
1161
|
input: r3,
|
|
1122
|
-
mask:
|
|
1162
|
+
mask: ee2.mask,
|
|
1123
1163
|
publicNonce: c2
|
|
1124
1164
|
};
|
|
1125
1165
|
})), i2 = r2.find((e12) => e12.status === "rejected");
|
|
1126
1166
|
if (i2 !== void 0) throw i2.reason;
|
|
1127
1167
|
return r2.map((e12) => e12.value);
|
|
1128
1168
|
}
|
|
1129
|
-
},
|
|
1169
|
+
}, zt = class {
|
|
1130
1170
|
constructor(e11) {
|
|
1131
1171
|
__publicField(this, "wallet");
|
|
1132
1172
|
__publicField(this, "crypto");
|
|
@@ -1149,11 +1189,11 @@ var It = class e10 {
|
|
|
1149
1189
|
}
|
|
1150
1190
|
async computeAuthorizations() {
|
|
1151
1191
|
if (this.resolvedInputs.length === 0) return [];
|
|
1152
|
-
let e11 =
|
|
1192
|
+
let e11 = H(this.spec.unsignedTx), t2 = this.sealKeypair.public_key, n2 = [];
|
|
1153
1193
|
for (let r2 of this.resolvedInputs) {
|
|
1154
1194
|
let i2 = this.wallet.getKeyProvider(r2.ownerAddr);
|
|
1155
|
-
if (i2 === void 0) throw new
|
|
1156
|
-
if (i2.addStealthSignature === void 0) throw new
|
|
1195
|
+
if (i2 === void 0) throw new p(`AuthorizedTransfer.createAuthorizations: no signer registered for stealth-input owner ${r2.ownerAddr}. Register it via wallet.registerKeyProvider(owner, signer).`, { address: r2.ownerAddr });
|
|
1196
|
+
if (i2.addStealthSignature === void 0) throw new h(`AuthorizedTransfer.createAuthorizations: signer for ${r2.ownerAddr} cannot produce one-time stealth signatures. Use a SecretKeyWallet (which holds the owner secret).`);
|
|
1157
1197
|
let a2 = await i2.addStealthSignature(e11, r2.publicNonce, t2, { crypto: this.crypto });
|
|
1158
1198
|
n2.push({
|
|
1159
1199
|
signerAddress: r2.ownerAddr,
|
|
@@ -1169,115 +1209,115 @@ var It = class e10 {
|
|
|
1169
1209
|
let e11 = (await this.createAuthorizations()).flatMap((e12) => e12.signatures), t2 = [];
|
|
1170
1210
|
this.mustSignWithAccountKey && t2.push(this.wallet);
|
|
1171
1211
|
let n2 = [...e11, ...this.extraSignatures];
|
|
1172
|
-
return n2.length > 0 && t2.push(new
|
|
1212
|
+
return n2.length > 0 && t2.push(new Vt(n2)), G(await W(t2, this.spec.unsignedTx, this.sealKeypair));
|
|
1173
1213
|
}
|
|
1174
1214
|
};
|
|
1175
|
-
function
|
|
1176
|
-
let n2 = e11.instructions.findIndex(
|
|
1177
|
-
if (n2 < 0) throw new
|
|
1178
|
-
if (e11.instructions.slice(n2 + 1).findIndex(
|
|
1215
|
+
function Bt(e11, t2) {
|
|
1216
|
+
let n2 = e11.instructions.findIndex(V);
|
|
1217
|
+
if (n2 < 0) throw new _("patchStealthStatement: expected exactly one StealthTransfer instruction, found 0 (not a stealth tx)");
|
|
1218
|
+
if (e11.instructions.slice(n2 + 1).findIndex(V) >= 0) throw new _("patchStealthStatement: expected exactly one StealthTransfer instruction, found more than one (malformed)");
|
|
1179
1219
|
let r2 = { StealthTransfer: {
|
|
1180
1220
|
...e11.instructions[n2].StealthTransfer,
|
|
1181
|
-
statement:
|
|
1221
|
+
statement: B(t2)
|
|
1182
1222
|
} }, i2 = [...e11.instructions];
|
|
1183
1223
|
return i2[n2] = r2, {
|
|
1184
1224
|
...e11,
|
|
1185
1225
|
instructions: i2
|
|
1186
1226
|
};
|
|
1187
1227
|
}
|
|
1188
|
-
var
|
|
1228
|
+
var Vt = class {
|
|
1189
1229
|
constructor(e11) {
|
|
1190
1230
|
this.signatures = e11;
|
|
1191
1231
|
}
|
|
1192
1232
|
async getAddress() {
|
|
1193
|
-
throw new
|
|
1233
|
+
throw new h("StaticSignatureSigner has no address");
|
|
1194
1234
|
}
|
|
1195
1235
|
async getPublicKey() {
|
|
1196
|
-
throw new
|
|
1236
|
+
throw new h("StaticSignatureSigner has no public key");
|
|
1197
1237
|
}
|
|
1198
1238
|
async signTransaction(e11, t2) {
|
|
1199
1239
|
return this.signatures;
|
|
1200
1240
|
}
|
|
1201
1241
|
};
|
|
1202
1242
|
export {
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1243
|
+
mt as AccountInvokeBuilder,
|
|
1244
|
+
zt as AuthorizedTransfer,
|
|
1245
|
+
J as BalanceProofSignature,
|
|
1246
|
+
g as CryptoBridgeError,
|
|
1247
|
+
m as DefaultSignerNotSetError,
|
|
1248
|
+
vt as EncryptedData,
|
|
1249
|
+
ht as FaucetInvokeBuilder,
|
|
1250
|
+
ae as IndexerClientError,
|
|
1251
|
+
_ as InvalidArgumentError,
|
|
1252
|
+
p as KeyProviderNotFoundError,
|
|
1253
|
+
K as Mask,
|
|
1254
|
+
l as Network,
|
|
1255
|
+
u as OotleError,
|
|
1256
|
+
gt as OotleWallet,
|
|
1257
|
+
se as OperationCancelledError,
|
|
1258
|
+
h as SignerError,
|
|
1259
|
+
q as StealthInput,
|
|
1260
|
+
Y as StealthInputsStatement,
|
|
1261
|
+
X as StealthOutputsStatement,
|
|
1222
1262
|
jt as StealthTransfer,
|
|
1223
1263
|
Z as StealthTransferStatement,
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1264
|
+
$e as TARI_RESOURCE_ADDRESS,
|
|
1265
|
+
R as TransactionBuilder,
|
|
1266
|
+
d as TransactionRejectedError,
|
|
1267
|
+
oe as TransactionTimeoutError,
|
|
1268
|
+
f as WalletError,
|
|
1269
|
+
Rt as WalletStealthAuthorizer,
|
|
1270
|
+
Q as WasmStealthCrypto,
|
|
1271
|
+
nt as XTR_FAUCET_CLAIM_RESOURCE_ADDRESS,
|
|
1272
|
+
et as XTR_FAUCET_COMPONENT_ADDRESS,
|
|
1273
|
+
tt as XTR_FAUCET_VAULT_ADDRESS,
|
|
1274
|
+
O as amountLiteral,
|
|
1275
|
+
v as assertByteLength,
|
|
1276
|
+
ce as assertUnreachable,
|
|
1277
|
+
Ee as boolLiteral,
|
|
1278
|
+
ct as buildTransactionSignature,
|
|
1279
|
+
k as bytesLiteral,
|
|
1280
|
+
je as claimedOutputTombstoneAddressLiteral,
|
|
1281
|
+
ut as classifyOutcome,
|
|
1242
1282
|
kt as commitmentOf,
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1283
|
+
De as componentAddressLiteral,
|
|
1284
|
+
bt as createOutput,
|
|
1285
|
+
Ft as decryptInputData,
|
|
1286
|
+
It as decryptOwnedUtxo,
|
|
1287
|
+
Ke as defaultIndexerUrl,
|
|
1288
|
+
b as fromHexStr,
|
|
1289
|
+
Lt as generateOutputsStatement,
|
|
1290
|
+
st as generateSealKeypair,
|
|
1291
|
+
Xe as getVaultIdsForAccount,
|
|
1292
|
+
we as intLiteral,
|
|
1293
|
+
V as isStealthTransferInstruction,
|
|
1294
|
+
Ye as iterVaultIdsInState,
|
|
1295
|
+
Ce as literalArg,
|
|
1296
|
+
Oe as metadataLiteral,
|
|
1297
|
+
L as microTariLiteral,
|
|
1298
|
+
ze as microTariString,
|
|
1299
|
+
Pe as nonFungibleAddressLiteral,
|
|
1260
1300
|
At as parseSubstateUtxo,
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1301
|
+
Be as parseWorkspaceStringKey,
|
|
1302
|
+
Bt as patchStealthStatement,
|
|
1303
|
+
Ne as publicKeyLiteral,
|
|
1304
|
+
U as resolveTransaction,
|
|
1305
|
+
A as resourceAddressLiteral,
|
|
1306
|
+
G as sealTransaction,
|
|
1307
|
+
pt as sendDryRun,
|
|
1308
|
+
ft as sendTransaction,
|
|
1309
|
+
H as serializeUnsignedTx,
|
|
1310
|
+
Pt as signBalanceProof,
|
|
1311
|
+
W as signTransaction,
|
|
1312
|
+
B as statementAsWire,
|
|
1313
|
+
ot as stealthTransferInstruction,
|
|
1314
|
+
$ as stealthUtxoSubstateId,
|
|
1315
|
+
Te as stringLiteral,
|
|
1316
|
+
lt as submitTransaction,
|
|
1317
|
+
Ae as templateAddressLiteral,
|
|
1318
|
+
y as toHexStr,
|
|
1319
|
+
Fe as utxoAddressLiteral,
|
|
1320
|
+
Me as validatorFeePoolAddressLiteral,
|
|
1321
|
+
ke as vaultIdLiteral,
|
|
1322
|
+
dt as watchTransaction
|
|
1283
1323
|
};
|