@rialo/ts-cdk 0.2.0 → 0.3.0-alpha.1
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.mts +1856 -245
- package/dist/index.d.ts +1856 -245
- package/dist/index.js +1838 -674
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1824 -673
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -4
package/dist/index.js
CHANGED
|
@@ -1,34 +1,585 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var chacha20poly1305 = require('@hpke/chacha20poly1305');
|
|
4
|
+
var core = require('@hpke/core');
|
|
5
|
+
|
|
3
6
|
var __create = Object.create;
|
|
4
7
|
var __defProp = Object.defineProperty;
|
|
5
8
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
9
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
10
|
var __getProtoOf = Object.getPrototypeOf;
|
|
8
11
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __esm = (fn, res) => function __init() {
|
|
13
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
14
|
+
};
|
|
9
15
|
var __commonJS = (cb, mod) => function __require() {
|
|
10
16
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
11
17
|
};
|
|
18
|
+
var __export = (target, all) => {
|
|
19
|
+
for (var name in all)
|
|
20
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
21
|
+
};
|
|
12
22
|
var __copyProps = (to, from, except, desc) => {
|
|
13
23
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
24
|
for (let key of __getOwnPropNames(from))
|
|
15
25
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
26
|
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
27
|
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
__defProp(target, "default", { value: mod, enumerable: true }) ,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
+
return to;
|
|
29
|
+
};
|
|
30
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
31
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
32
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
33
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
34
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
35
|
+
__defProp(target, "default", { value: mod, enumerable: true }) ,
|
|
36
|
+
mod
|
|
37
|
+
));
|
|
38
|
+
|
|
39
|
+
// node_modules/@scure/base/index.js
|
|
40
|
+
var base_exports = {};
|
|
41
|
+
__export(base_exports, {
|
|
42
|
+
base16: () => base16,
|
|
43
|
+
base32: () => base32,
|
|
44
|
+
base32crockford: () => base32crockford,
|
|
45
|
+
base32hex: () => base32hex,
|
|
46
|
+
base32hexnopad: () => base32hexnopad,
|
|
47
|
+
base32nopad: () => base32nopad,
|
|
48
|
+
base58: () => base58,
|
|
49
|
+
base58check: () => base58check,
|
|
50
|
+
base58flickr: () => base58flickr,
|
|
51
|
+
base58xmr: () => base58xmr,
|
|
52
|
+
base58xrp: () => base58xrp,
|
|
53
|
+
base64: () => base64,
|
|
54
|
+
base64nopad: () => base64nopad,
|
|
55
|
+
base64url: () => base64url,
|
|
56
|
+
base64urlnopad: () => base64urlnopad,
|
|
57
|
+
bech32: () => bech32,
|
|
58
|
+
bech32m: () => bech32m,
|
|
59
|
+
bytes: () => bytes,
|
|
60
|
+
bytesToString: () => bytesToString,
|
|
61
|
+
createBase58check: () => createBase58check,
|
|
62
|
+
hex: () => hex,
|
|
63
|
+
str: () => str,
|
|
64
|
+
stringToBytes: () => stringToBytes,
|
|
65
|
+
utf8: () => utf8,
|
|
66
|
+
utils: () => utils
|
|
67
|
+
});
|
|
68
|
+
function isBytes3(a) {
|
|
69
|
+
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
70
|
+
}
|
|
71
|
+
function abytes3(b) {
|
|
72
|
+
if (!isBytes3(b))
|
|
73
|
+
throw new Error("Uint8Array expected");
|
|
74
|
+
}
|
|
75
|
+
function isArrayOf(isString, arr) {
|
|
76
|
+
if (!Array.isArray(arr))
|
|
77
|
+
return false;
|
|
78
|
+
if (arr.length === 0)
|
|
79
|
+
return true;
|
|
80
|
+
if (isString) {
|
|
81
|
+
return arr.every((item) => typeof item === "string");
|
|
82
|
+
} else {
|
|
83
|
+
return arr.every((item) => Number.isSafeInteger(item));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function afn(input) {
|
|
87
|
+
if (typeof input !== "function")
|
|
88
|
+
throw new Error("function expected");
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
function astr(label, input) {
|
|
92
|
+
if (typeof input !== "string")
|
|
93
|
+
throw new Error(`${label}: string expected`);
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
function anumber2(n) {
|
|
97
|
+
if (!Number.isSafeInteger(n))
|
|
98
|
+
throw new Error(`invalid integer: ${n}`);
|
|
99
|
+
}
|
|
100
|
+
function aArr(input) {
|
|
101
|
+
if (!Array.isArray(input))
|
|
102
|
+
throw new Error("array expected");
|
|
103
|
+
}
|
|
104
|
+
function astrArr(label, input) {
|
|
105
|
+
if (!isArrayOf(true, input))
|
|
106
|
+
throw new Error(`${label}: array of strings expected`);
|
|
107
|
+
}
|
|
108
|
+
function anumArr(label, input) {
|
|
109
|
+
if (!isArrayOf(false, input))
|
|
110
|
+
throw new Error(`${label}: array of numbers expected`);
|
|
111
|
+
}
|
|
112
|
+
// @__NO_SIDE_EFFECTS__
|
|
113
|
+
function chain(...args) {
|
|
114
|
+
const id = (a) => a;
|
|
115
|
+
const wrap = (a, b) => (c) => a(b(c));
|
|
116
|
+
const encode = args.map((x) => x.encode).reduceRight(wrap, id);
|
|
117
|
+
const decode = args.map((x) => x.decode).reduce(wrap, id);
|
|
118
|
+
return { encode, decode };
|
|
119
|
+
}
|
|
120
|
+
// @__NO_SIDE_EFFECTS__
|
|
121
|
+
function alphabet(letters) {
|
|
122
|
+
const lettersA = typeof letters === "string" ? letters.split("") : letters;
|
|
123
|
+
const len = lettersA.length;
|
|
124
|
+
astrArr("alphabet", lettersA);
|
|
125
|
+
const indexes = new Map(lettersA.map((l, i) => [l, i]));
|
|
126
|
+
return {
|
|
127
|
+
encode: (digits) => {
|
|
128
|
+
aArr(digits);
|
|
129
|
+
return digits.map((i) => {
|
|
130
|
+
if (!Number.isSafeInteger(i) || i < 0 || i >= len)
|
|
131
|
+
throw new Error(`alphabet.encode: digit index outside alphabet "${i}". Allowed: ${letters}`);
|
|
132
|
+
return lettersA[i];
|
|
133
|
+
});
|
|
134
|
+
},
|
|
135
|
+
decode: (input) => {
|
|
136
|
+
aArr(input);
|
|
137
|
+
return input.map((letter) => {
|
|
138
|
+
astr("alphabet.decode", letter);
|
|
139
|
+
const i = indexes.get(letter);
|
|
140
|
+
if (i === void 0)
|
|
141
|
+
throw new Error(`Unknown letter: "${letter}". Allowed: ${letters}`);
|
|
142
|
+
return i;
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
// @__NO_SIDE_EFFECTS__
|
|
148
|
+
function join(separator = "") {
|
|
149
|
+
astr("join", separator);
|
|
150
|
+
return {
|
|
151
|
+
encode: (from) => {
|
|
152
|
+
astrArr("join.decode", from);
|
|
153
|
+
return from.join(separator);
|
|
154
|
+
},
|
|
155
|
+
decode: (to) => {
|
|
156
|
+
astr("join.decode", to);
|
|
157
|
+
return to.split(separator);
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
// @__NO_SIDE_EFFECTS__
|
|
162
|
+
function padding(bits, chr = "=") {
|
|
163
|
+
anumber2(bits);
|
|
164
|
+
astr("padding", chr);
|
|
165
|
+
return {
|
|
166
|
+
encode(data) {
|
|
167
|
+
astrArr("padding.encode", data);
|
|
168
|
+
while (data.length * bits % 8)
|
|
169
|
+
data.push(chr);
|
|
170
|
+
return data;
|
|
171
|
+
},
|
|
172
|
+
decode(input) {
|
|
173
|
+
astrArr("padding.decode", input);
|
|
174
|
+
let end = input.length;
|
|
175
|
+
if (end * bits % 8)
|
|
176
|
+
throw new Error("padding: invalid, string should have whole number of bytes");
|
|
177
|
+
for (; end > 0 && input[end - 1] === chr; end--) {
|
|
178
|
+
const last = end - 1;
|
|
179
|
+
const byte = last * bits;
|
|
180
|
+
if (byte % 8 === 0)
|
|
181
|
+
throw new Error("padding: invalid, string has too much padding");
|
|
182
|
+
}
|
|
183
|
+
return input.slice(0, end);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
// @__NO_SIDE_EFFECTS__
|
|
188
|
+
function normalize(fn) {
|
|
189
|
+
afn(fn);
|
|
190
|
+
return { encode: (from) => from, decode: (to) => fn(to) };
|
|
191
|
+
}
|
|
192
|
+
function convertRadix(data, from, to) {
|
|
193
|
+
if (from < 2)
|
|
194
|
+
throw new Error(`convertRadix: invalid from=${from}, base cannot be less than 2`);
|
|
195
|
+
if (to < 2)
|
|
196
|
+
throw new Error(`convertRadix: invalid to=${to}, base cannot be less than 2`);
|
|
197
|
+
aArr(data);
|
|
198
|
+
if (!data.length)
|
|
199
|
+
return [];
|
|
200
|
+
let pos = 0;
|
|
201
|
+
const res = [];
|
|
202
|
+
const digits = Array.from(data, (d) => {
|
|
203
|
+
anumber2(d);
|
|
204
|
+
if (d < 0 || d >= from)
|
|
205
|
+
throw new Error(`invalid integer: ${d}`);
|
|
206
|
+
return d;
|
|
207
|
+
});
|
|
208
|
+
const dlen = digits.length;
|
|
209
|
+
while (true) {
|
|
210
|
+
let carry = 0;
|
|
211
|
+
let done = true;
|
|
212
|
+
for (let i = pos; i < dlen; i++) {
|
|
213
|
+
const digit = digits[i];
|
|
214
|
+
const fromCarry = from * carry;
|
|
215
|
+
const digitBase = fromCarry + digit;
|
|
216
|
+
if (!Number.isSafeInteger(digitBase) || fromCarry / from !== carry || digitBase - digit !== fromCarry) {
|
|
217
|
+
throw new Error("convertRadix: carry overflow");
|
|
218
|
+
}
|
|
219
|
+
const div = digitBase / to;
|
|
220
|
+
carry = digitBase % to;
|
|
221
|
+
const rounded = Math.floor(div);
|
|
222
|
+
digits[i] = rounded;
|
|
223
|
+
if (!Number.isSafeInteger(rounded) || rounded * to + carry !== digitBase)
|
|
224
|
+
throw new Error("convertRadix: carry overflow");
|
|
225
|
+
if (!done)
|
|
226
|
+
continue;
|
|
227
|
+
else if (!rounded)
|
|
228
|
+
pos = i;
|
|
229
|
+
else
|
|
230
|
+
done = false;
|
|
231
|
+
}
|
|
232
|
+
res.push(carry);
|
|
233
|
+
if (done)
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
for (let i = 0; i < data.length - 1 && data[i] === 0; i++)
|
|
237
|
+
res.push(0);
|
|
238
|
+
return res.reverse();
|
|
239
|
+
}
|
|
240
|
+
function convertRadix2(data, from, to, padding2) {
|
|
241
|
+
aArr(data);
|
|
242
|
+
if (from <= 0 || from > 32)
|
|
243
|
+
throw new Error(`convertRadix2: wrong from=${from}`);
|
|
244
|
+
if (to <= 0 || to > 32)
|
|
245
|
+
throw new Error(`convertRadix2: wrong to=${to}`);
|
|
246
|
+
if (/* @__PURE__ */ radix2carry(from, to) > 32) {
|
|
247
|
+
throw new Error(`convertRadix2: carry overflow from=${from} to=${to} carryBits=${/* @__PURE__ */ radix2carry(from, to)}`);
|
|
248
|
+
}
|
|
249
|
+
let carry = 0;
|
|
250
|
+
let pos = 0;
|
|
251
|
+
const max = powers[from];
|
|
252
|
+
const mask = powers[to] - 1;
|
|
253
|
+
const res = [];
|
|
254
|
+
for (const n of data) {
|
|
255
|
+
anumber2(n);
|
|
256
|
+
if (n >= max)
|
|
257
|
+
throw new Error(`convertRadix2: invalid data word=${n} from=${from}`);
|
|
258
|
+
carry = carry << from | n;
|
|
259
|
+
if (pos + from > 32)
|
|
260
|
+
throw new Error(`convertRadix2: carry overflow pos=${pos} from=${from}`);
|
|
261
|
+
pos += from;
|
|
262
|
+
for (; pos >= to; pos -= to)
|
|
263
|
+
res.push((carry >> pos - to & mask) >>> 0);
|
|
264
|
+
const pow = powers[pos];
|
|
265
|
+
if (pow === void 0)
|
|
266
|
+
throw new Error("invalid carry");
|
|
267
|
+
carry &= pow - 1;
|
|
268
|
+
}
|
|
269
|
+
carry = carry << to - pos & mask;
|
|
270
|
+
if (!padding2 && pos >= from)
|
|
271
|
+
throw new Error("Excess padding");
|
|
272
|
+
if (!padding2 && carry > 0)
|
|
273
|
+
throw new Error(`Non-zero padding: ${carry}`);
|
|
274
|
+
if (padding2 && pos > 0)
|
|
275
|
+
res.push(carry >>> 0);
|
|
276
|
+
return res;
|
|
277
|
+
}
|
|
278
|
+
// @__NO_SIDE_EFFECTS__
|
|
279
|
+
function radix(num) {
|
|
280
|
+
anumber2(num);
|
|
281
|
+
const _256 = 2 ** 8;
|
|
282
|
+
return {
|
|
283
|
+
encode: (bytes2) => {
|
|
284
|
+
if (!isBytes3(bytes2))
|
|
285
|
+
throw new Error("radix.encode input should be Uint8Array");
|
|
286
|
+
return convertRadix(Array.from(bytes2), _256, num);
|
|
287
|
+
},
|
|
288
|
+
decode: (digits) => {
|
|
289
|
+
anumArr("radix.decode", digits);
|
|
290
|
+
return Uint8Array.from(convertRadix(digits, num, _256));
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
// @__NO_SIDE_EFFECTS__
|
|
295
|
+
function radix2(bits, revPadding = false) {
|
|
296
|
+
anumber2(bits);
|
|
297
|
+
if (bits <= 0 || bits > 32)
|
|
298
|
+
throw new Error("radix2: bits should be in (0..32]");
|
|
299
|
+
if (/* @__PURE__ */ radix2carry(8, bits) > 32 || /* @__PURE__ */ radix2carry(bits, 8) > 32)
|
|
300
|
+
throw new Error("radix2: carry overflow");
|
|
301
|
+
return {
|
|
302
|
+
encode: (bytes2) => {
|
|
303
|
+
if (!isBytes3(bytes2))
|
|
304
|
+
throw new Error("radix2.encode input should be Uint8Array");
|
|
305
|
+
return convertRadix2(Array.from(bytes2), 8, bits, !revPadding);
|
|
306
|
+
},
|
|
307
|
+
decode: (digits) => {
|
|
308
|
+
anumArr("radix2.decode", digits);
|
|
309
|
+
return Uint8Array.from(convertRadix2(digits, bits, 8, revPadding));
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
function unsafeWrapper(fn) {
|
|
314
|
+
afn(fn);
|
|
315
|
+
return function(...args) {
|
|
316
|
+
try {
|
|
317
|
+
return fn.apply(null, args);
|
|
318
|
+
} catch (e) {
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
function checksum(len, fn) {
|
|
323
|
+
anumber2(len);
|
|
324
|
+
afn(fn);
|
|
325
|
+
return {
|
|
326
|
+
encode(data) {
|
|
327
|
+
if (!isBytes3(data))
|
|
328
|
+
throw new Error("checksum.encode: input should be Uint8Array");
|
|
329
|
+
const sum = fn(data).slice(0, len);
|
|
330
|
+
const res = new Uint8Array(data.length + len);
|
|
331
|
+
res.set(data);
|
|
332
|
+
res.set(sum, data.length);
|
|
333
|
+
return res;
|
|
334
|
+
},
|
|
335
|
+
decode(data) {
|
|
336
|
+
if (!isBytes3(data))
|
|
337
|
+
throw new Error("checksum.decode: input should be Uint8Array");
|
|
338
|
+
const payload = data.slice(0, -len);
|
|
339
|
+
const oldChecksum = data.slice(-len);
|
|
340
|
+
const newChecksum = fn(payload).slice(0, len);
|
|
341
|
+
for (let i = 0; i < len; i++)
|
|
342
|
+
if (newChecksum[i] !== oldChecksum[i])
|
|
343
|
+
throw new Error("Invalid checksum");
|
|
344
|
+
return payload;
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
function bech32Polymod(pre) {
|
|
349
|
+
const b = pre >> 25;
|
|
350
|
+
let chk = (pre & 33554431) << 5;
|
|
351
|
+
for (let i = 0; i < POLYMOD_GENERATORS.length; i++) {
|
|
352
|
+
if ((b >> i & 1) === 1)
|
|
353
|
+
chk ^= POLYMOD_GENERATORS[i];
|
|
354
|
+
}
|
|
355
|
+
return chk;
|
|
356
|
+
}
|
|
357
|
+
function bechChecksum(prefix, words, encodingConst = 1) {
|
|
358
|
+
const len = prefix.length;
|
|
359
|
+
let chk = 1;
|
|
360
|
+
for (let i = 0; i < len; i++) {
|
|
361
|
+
const c = prefix.charCodeAt(i);
|
|
362
|
+
if (c < 33 || c > 126)
|
|
363
|
+
throw new Error(`Invalid prefix (${prefix})`);
|
|
364
|
+
chk = bech32Polymod(chk) ^ c >> 5;
|
|
365
|
+
}
|
|
366
|
+
chk = bech32Polymod(chk);
|
|
367
|
+
for (let i = 0; i < len; i++)
|
|
368
|
+
chk = bech32Polymod(chk) ^ prefix.charCodeAt(i) & 31;
|
|
369
|
+
for (let v of words)
|
|
370
|
+
chk = bech32Polymod(chk) ^ v;
|
|
371
|
+
for (let i = 0; i < 6; i++)
|
|
372
|
+
chk = bech32Polymod(chk);
|
|
373
|
+
chk ^= encodingConst;
|
|
374
|
+
return BECH_ALPHABET.encode(convertRadix2([chk % powers[30]], 30, 5, false));
|
|
375
|
+
}
|
|
376
|
+
// @__NO_SIDE_EFFECTS__
|
|
377
|
+
function genBech32(encoding) {
|
|
378
|
+
const ENCODING_CONST = encoding === "bech32" ? 1 : 734539939;
|
|
379
|
+
const _words = /* @__PURE__ */ radix2(5);
|
|
380
|
+
const fromWords = _words.decode;
|
|
381
|
+
const toWords = _words.encode;
|
|
382
|
+
const fromWordsUnsafe = unsafeWrapper(fromWords);
|
|
383
|
+
function encode(prefix, words, limit = 90) {
|
|
384
|
+
astr("bech32.encode prefix", prefix);
|
|
385
|
+
if (isBytes3(words))
|
|
386
|
+
words = Array.from(words);
|
|
387
|
+
anumArr("bech32.encode", words);
|
|
388
|
+
const plen = prefix.length;
|
|
389
|
+
if (plen === 0)
|
|
390
|
+
throw new TypeError(`Invalid prefix length ${plen}`);
|
|
391
|
+
const actualLength = plen + 7 + words.length;
|
|
392
|
+
if (limit !== false && actualLength > limit)
|
|
393
|
+
throw new TypeError(`Length ${actualLength} exceeds limit ${limit}`);
|
|
394
|
+
const lowered = prefix.toLowerCase();
|
|
395
|
+
const sum = bechChecksum(lowered, words, ENCODING_CONST);
|
|
396
|
+
return `${lowered}1${BECH_ALPHABET.encode(words)}${sum}`;
|
|
397
|
+
}
|
|
398
|
+
function decode(str2, limit = 90) {
|
|
399
|
+
astr("bech32.decode input", str2);
|
|
400
|
+
const slen = str2.length;
|
|
401
|
+
if (slen < 8 || limit !== false && slen > limit)
|
|
402
|
+
throw new TypeError(`invalid string length: ${slen} (${str2}). Expected (8..${limit})`);
|
|
403
|
+
const lowered = str2.toLowerCase();
|
|
404
|
+
if (str2 !== lowered && str2 !== str2.toUpperCase())
|
|
405
|
+
throw new Error(`String must be lowercase or uppercase`);
|
|
406
|
+
const sepIndex = lowered.lastIndexOf("1");
|
|
407
|
+
if (sepIndex === 0 || sepIndex === -1)
|
|
408
|
+
throw new Error(`Letter "1" must be present between prefix and data only`);
|
|
409
|
+
const prefix = lowered.slice(0, sepIndex);
|
|
410
|
+
const data = lowered.slice(sepIndex + 1);
|
|
411
|
+
if (data.length < 6)
|
|
412
|
+
throw new Error("Data must be at least 6 characters long");
|
|
413
|
+
const words = BECH_ALPHABET.decode(data).slice(0, -6);
|
|
414
|
+
const sum = bechChecksum(prefix, words, ENCODING_CONST);
|
|
415
|
+
if (!data.endsWith(sum))
|
|
416
|
+
throw new Error(`Invalid checksum in ${str2}: expected "${sum}"`);
|
|
417
|
+
return { prefix, words };
|
|
418
|
+
}
|
|
419
|
+
const decodeUnsafe = unsafeWrapper(decode);
|
|
420
|
+
function decodeToBytes(str2) {
|
|
421
|
+
const { prefix, words } = decode(str2, false);
|
|
422
|
+
return { prefix, words, bytes: fromWords(words) };
|
|
423
|
+
}
|
|
424
|
+
function encodeFromBytes(prefix, bytes2) {
|
|
425
|
+
return encode(prefix, toWords(bytes2));
|
|
426
|
+
}
|
|
427
|
+
return {
|
|
428
|
+
encode,
|
|
429
|
+
decode,
|
|
430
|
+
encodeFromBytes,
|
|
431
|
+
decodeToBytes,
|
|
432
|
+
decodeUnsafe,
|
|
433
|
+
fromWords,
|
|
434
|
+
fromWordsUnsafe,
|
|
435
|
+
toWords
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
var gcd, radix2carry, powers, utils, base16, base32, base32nopad, base32hex, base32hexnopad, base32crockford, hasBase64Builtin, decodeBase64Builtin, base64, base64nopad, base64url, base64urlnopad, genBase58, base58, base58flickr, base58xrp, XMR_BLOCK_LEN, base58xmr, createBase58check, base58check, BECH_ALPHABET, POLYMOD_GENERATORS, bech32, bech32m, utf8, hasHexBuiltin, hexBuiltin, hex, CODERS, coderTypeError, bytesToString, str, stringToBytes, bytes;
|
|
439
|
+
var init_base = __esm({
|
|
440
|
+
"node_modules/@scure/base/index.js"() {
|
|
441
|
+
gcd = (a, b) => b === 0 ? a : gcd(b, a % b);
|
|
442
|
+
radix2carry = /* @__NO_SIDE_EFFECTS__ */ (from, to) => from + (to - gcd(from, to));
|
|
443
|
+
powers = /* @__PURE__ */ (() => {
|
|
444
|
+
let res = [];
|
|
445
|
+
for (let i = 0; i < 40; i++)
|
|
446
|
+
res.push(2 ** i);
|
|
447
|
+
return res;
|
|
448
|
+
})();
|
|
449
|
+
utils = {
|
|
450
|
+
alphabet,
|
|
451
|
+
chain,
|
|
452
|
+
checksum,
|
|
453
|
+
convertRadix,
|
|
454
|
+
convertRadix2,
|
|
455
|
+
radix,
|
|
456
|
+
radix2,
|
|
457
|
+
join,
|
|
458
|
+
padding
|
|
459
|
+
};
|
|
460
|
+
base16 = /* @__PURE__ */ chain(/* @__PURE__ */ radix2(4), /* @__PURE__ */ alphabet("0123456789ABCDEF"), /* @__PURE__ */ join(""));
|
|
461
|
+
base32 = /* @__PURE__ */ chain(/* @__PURE__ */ radix2(5), /* @__PURE__ */ alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"), /* @__PURE__ */ padding(5), /* @__PURE__ */ join(""));
|
|
462
|
+
base32nopad = /* @__PURE__ */ chain(/* @__PURE__ */ radix2(5), /* @__PURE__ */ alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"), /* @__PURE__ */ join(""));
|
|
463
|
+
base32hex = /* @__PURE__ */ chain(/* @__PURE__ */ radix2(5), /* @__PURE__ */ alphabet("0123456789ABCDEFGHIJKLMNOPQRSTUV"), /* @__PURE__ */ padding(5), /* @__PURE__ */ join(""));
|
|
464
|
+
base32hexnopad = /* @__PURE__ */ chain(/* @__PURE__ */ radix2(5), /* @__PURE__ */ alphabet("0123456789ABCDEFGHIJKLMNOPQRSTUV"), /* @__PURE__ */ join(""));
|
|
465
|
+
base32crockford = /* @__PURE__ */ chain(/* @__PURE__ */ radix2(5), /* @__PURE__ */ alphabet("0123456789ABCDEFGHJKMNPQRSTVWXYZ"), /* @__PURE__ */ join(""), /* @__PURE__ */ normalize((s) => s.toUpperCase().replace(/O/g, "0").replace(/[IL]/g, "1")));
|
|
466
|
+
hasBase64Builtin = /* @__PURE__ */ (() => typeof Uint8Array.from([]).toBase64 === "function" && typeof Uint8Array.fromBase64 === "function")();
|
|
467
|
+
decodeBase64Builtin = (s, isUrl) => {
|
|
468
|
+
astr("base64", s);
|
|
469
|
+
const re = isUrl ? /^[A-Za-z0-9=_-]+$/ : /^[A-Za-z0-9=+/]+$/;
|
|
470
|
+
const alphabet2 = isUrl ? "base64url" : "base64";
|
|
471
|
+
if (s.length > 0 && !re.test(s))
|
|
472
|
+
throw new Error("invalid base64");
|
|
473
|
+
return Uint8Array.fromBase64(s, { alphabet: alphabet2, lastChunkHandling: "strict" });
|
|
474
|
+
};
|
|
475
|
+
base64 = hasBase64Builtin ? {
|
|
476
|
+
encode(b) {
|
|
477
|
+
abytes3(b);
|
|
478
|
+
return b.toBase64();
|
|
479
|
+
},
|
|
480
|
+
decode(s) {
|
|
481
|
+
return decodeBase64Builtin(s, false);
|
|
482
|
+
}
|
|
483
|
+
} : /* @__PURE__ */ chain(/* @__PURE__ */ radix2(6), /* @__PURE__ */ alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), /* @__PURE__ */ padding(6), /* @__PURE__ */ join(""));
|
|
484
|
+
base64nopad = /* @__PURE__ */ chain(/* @__PURE__ */ radix2(6), /* @__PURE__ */ alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"), /* @__PURE__ */ join(""));
|
|
485
|
+
base64url = hasBase64Builtin ? {
|
|
486
|
+
encode(b) {
|
|
487
|
+
abytes3(b);
|
|
488
|
+
return b.toBase64({ alphabet: "base64url" });
|
|
489
|
+
},
|
|
490
|
+
decode(s) {
|
|
491
|
+
return decodeBase64Builtin(s, true);
|
|
492
|
+
}
|
|
493
|
+
} : /* @__PURE__ */ chain(/* @__PURE__ */ radix2(6), /* @__PURE__ */ alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"), /* @__PURE__ */ padding(6), /* @__PURE__ */ join(""));
|
|
494
|
+
base64urlnopad = /* @__PURE__ */ chain(/* @__PURE__ */ radix2(6), /* @__PURE__ */ alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"), /* @__PURE__ */ join(""));
|
|
495
|
+
genBase58 = /* @__NO_SIDE_EFFECTS__ */ (abc) => /* @__PURE__ */ chain(/* @__PURE__ */ radix(58), /* @__PURE__ */ alphabet(abc), /* @__PURE__ */ join(""));
|
|
496
|
+
base58 = /* @__PURE__ */ genBase58("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
|
|
497
|
+
base58flickr = /* @__PURE__ */ genBase58("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ");
|
|
498
|
+
base58xrp = /* @__PURE__ */ genBase58("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");
|
|
499
|
+
XMR_BLOCK_LEN = [0, 2, 3, 5, 6, 7, 9, 10, 11];
|
|
500
|
+
base58xmr = {
|
|
501
|
+
encode(data) {
|
|
502
|
+
let res = "";
|
|
503
|
+
for (let i = 0; i < data.length; i += 8) {
|
|
504
|
+
const block = data.subarray(i, i + 8);
|
|
505
|
+
res += base58.encode(block).padStart(XMR_BLOCK_LEN[block.length], "1");
|
|
506
|
+
}
|
|
507
|
+
return res;
|
|
508
|
+
},
|
|
509
|
+
decode(str2) {
|
|
510
|
+
let res = [];
|
|
511
|
+
for (let i = 0; i < str2.length; i += 11) {
|
|
512
|
+
const slice = str2.slice(i, i + 11);
|
|
513
|
+
const blockLen = XMR_BLOCK_LEN.indexOf(slice.length);
|
|
514
|
+
const block = base58.decode(slice);
|
|
515
|
+
for (let j = 0; j < block.length - blockLen; j++) {
|
|
516
|
+
if (block[j] !== 0)
|
|
517
|
+
throw new Error("base58xmr: wrong padding");
|
|
518
|
+
}
|
|
519
|
+
res = res.concat(Array.from(block.slice(block.length - blockLen)));
|
|
520
|
+
}
|
|
521
|
+
return Uint8Array.from(res);
|
|
522
|
+
}
|
|
523
|
+
};
|
|
524
|
+
createBase58check = (sha2563) => /* @__PURE__ */ chain(checksum(4, (data) => sha2563(sha2563(data))), base58);
|
|
525
|
+
base58check = createBase58check;
|
|
526
|
+
BECH_ALPHABET = /* @__PURE__ */ chain(/* @__PURE__ */ alphabet("qpzry9x8gf2tvdw0s3jn54khce6mua7l"), /* @__PURE__ */ join(""));
|
|
527
|
+
POLYMOD_GENERATORS = [996825010, 642813549, 513874426, 1027748829, 705979059];
|
|
528
|
+
bech32 = /* @__PURE__ */ genBech32("bech32");
|
|
529
|
+
bech32m = /* @__PURE__ */ genBech32("bech32m");
|
|
530
|
+
utf8 = {
|
|
531
|
+
encode: (data) => new TextDecoder().decode(data),
|
|
532
|
+
decode: (str2) => new TextEncoder().encode(str2)
|
|
533
|
+
};
|
|
534
|
+
hasHexBuiltin = /* @__PURE__ */ (() => typeof Uint8Array.from([]).toHex === "function" && typeof Uint8Array.fromHex === "function")();
|
|
535
|
+
hexBuiltin = {
|
|
536
|
+
encode(data) {
|
|
537
|
+
abytes3(data);
|
|
538
|
+
return data.toHex();
|
|
539
|
+
},
|
|
540
|
+
decode(s) {
|
|
541
|
+
astr("hex", s);
|
|
542
|
+
return Uint8Array.fromHex(s);
|
|
543
|
+
}
|
|
544
|
+
};
|
|
545
|
+
hex = hasHexBuiltin ? hexBuiltin : /* @__PURE__ */ chain(/* @__PURE__ */ radix2(4), /* @__PURE__ */ alphabet("0123456789abcdef"), /* @__PURE__ */ join(""), /* @__PURE__ */ normalize((s) => {
|
|
546
|
+
if (typeof s !== "string" || s.length % 2 !== 0)
|
|
547
|
+
throw new TypeError(`hex.decode: expected string, got ${typeof s} with length ${s.length}`);
|
|
548
|
+
return s.toLowerCase();
|
|
549
|
+
}));
|
|
550
|
+
CODERS = {
|
|
551
|
+
utf8,
|
|
552
|
+
hex,
|
|
553
|
+
base16,
|
|
554
|
+
base32,
|
|
555
|
+
base64,
|
|
556
|
+
base64url,
|
|
557
|
+
base58,
|
|
558
|
+
base58xmr
|
|
559
|
+
};
|
|
560
|
+
coderTypeError = "Invalid encoding type. Available types: utf8, hex, base16, base32, base64, base64url, base58, base58xmr";
|
|
561
|
+
bytesToString = (type, bytes2) => {
|
|
562
|
+
if (typeof type !== "string" || !CODERS.hasOwnProperty(type))
|
|
563
|
+
throw new TypeError(coderTypeError);
|
|
564
|
+
if (!isBytes3(bytes2))
|
|
565
|
+
throw new TypeError("bytesToString() expects Uint8Array");
|
|
566
|
+
return CODERS[type].encode(bytes2);
|
|
567
|
+
};
|
|
568
|
+
str = bytesToString;
|
|
569
|
+
stringToBytes = (type, str2) => {
|
|
570
|
+
if (!CODERS.hasOwnProperty(type))
|
|
571
|
+
throw new TypeError(coderTypeError);
|
|
572
|
+
if (typeof str2 !== "string")
|
|
573
|
+
throw new TypeError("stringToBytes() expects string");
|
|
574
|
+
return CODERS[type].decode(str2);
|
|
575
|
+
};
|
|
576
|
+
bytes = stringToBytes;
|
|
577
|
+
}
|
|
578
|
+
});
|
|
28
579
|
|
|
29
580
|
// node_modules/@protobufjs/float/index.js
|
|
30
581
|
var require_float = __commonJS({
|
|
31
|
-
"node_modules/@protobufjs/float/index.js"(exports, module) {
|
|
582
|
+
"node_modules/@protobufjs/float/index.js"(exports$1, module) {
|
|
32
583
|
module.exports = factory(factory);
|
|
33
584
|
function factory(exports2) {
|
|
34
585
|
if (typeof Float32Array !== "undefined") (function() {
|
|
@@ -221,9 +772,9 @@ var require_float = __commonJS({
|
|
|
221
772
|
|
|
222
773
|
// node_modules/@protobufjs/utf8/index.js
|
|
223
774
|
var require_utf8 = __commonJS({
|
|
224
|
-
"node_modules/@protobufjs/utf8/index.js"(exports) {
|
|
225
|
-
var
|
|
226
|
-
|
|
775
|
+
"node_modules/@protobufjs/utf8/index.js"(exports$1) {
|
|
776
|
+
var utf83 = exports$1;
|
|
777
|
+
utf83.length = function utf8_length(string) {
|
|
227
778
|
var len = 0, c = 0;
|
|
228
779
|
for (var i = 0; i < string.length; ++i) {
|
|
229
780
|
c = string.charCodeAt(i);
|
|
@@ -239,7 +790,7 @@ var require_utf8 = __commonJS({
|
|
|
239
790
|
}
|
|
240
791
|
return len;
|
|
241
792
|
};
|
|
242
|
-
|
|
793
|
+
utf83.read = function utf8_read(buffer, start, end) {
|
|
243
794
|
var len = end - start;
|
|
244
795
|
if (len < 1)
|
|
245
796
|
return "";
|
|
@@ -268,7 +819,7 @@ var require_utf8 = __commonJS({
|
|
|
268
819
|
}
|
|
269
820
|
return String.fromCharCode.apply(String, chunk.slice(0, i));
|
|
270
821
|
};
|
|
271
|
-
|
|
822
|
+
utf83.write = function utf8_write(string, buffer, offset) {
|
|
272
823
|
var start = offset, c1, c2;
|
|
273
824
|
for (var i = 0; i < string.length; ++i) {
|
|
274
825
|
c1 = string.charCodeAt(i);
|
|
@@ -301,7 +852,6 @@ var URL_MAINNET = "https://mainnet.rialo.io:4101";
|
|
|
301
852
|
var URL_TESTNET = "https://testnet.rialo.io:4101";
|
|
302
853
|
var URL_DEVNET = "https://devnet.rialo.io:4101";
|
|
303
854
|
var URL_LOCALNET = "http://localhost:4104";
|
|
304
|
-
var URL_SHITNET = "http://shitnet.rialo.io:4100";
|
|
305
855
|
var RIALO_MAINNET_CHAIN = {
|
|
306
856
|
id: "rialo:mainnet",
|
|
307
857
|
name: "Mainnet",
|
|
@@ -322,11 +872,6 @@ var RIALO_LOCALNET_CHAIN = {
|
|
|
322
872
|
name: "Localhost",
|
|
323
873
|
rpcUrl: URL_LOCALNET
|
|
324
874
|
};
|
|
325
|
-
var RIALO_SHITNET_CHAIN = {
|
|
326
|
-
id: "rialo:shitnet",
|
|
327
|
-
name: "Shitnet",
|
|
328
|
-
rpcUrl: URL_SHITNET
|
|
329
|
-
};
|
|
330
875
|
var SYSTEM_PROGRAM_ID = "11111111111111111111111111111111";
|
|
331
876
|
var BASE_DERIVATION_PATH = "m/44'/756'/";
|
|
332
877
|
var KELVIN_PER_RLO = 1e9;
|
|
@@ -412,13 +957,13 @@ var isBig = (n) => typeof n === "bigint";
|
|
|
412
957
|
var isStr = (s) => typeof s === "string";
|
|
413
958
|
var isBytes = (a) => a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
414
959
|
var abytes = (value, length, title = "") => {
|
|
415
|
-
const
|
|
960
|
+
const bytes2 = isBytes(value);
|
|
416
961
|
const len = value?.length;
|
|
417
962
|
const needsLen = length !== void 0;
|
|
418
|
-
if (!
|
|
963
|
+
if (!bytes2 || needsLen && len !== length) {
|
|
419
964
|
const prefix = title && `"${title}" `;
|
|
420
965
|
const ofLen = needsLen ? ` of length ${length}` : "";
|
|
421
|
-
const got =
|
|
966
|
+
const got = bytes2 ? `length=${len}` : `type=${typeof value}`;
|
|
422
967
|
err(prefix + "expected Uint8Array" + ofLen + ", got " + got);
|
|
423
968
|
}
|
|
424
969
|
return value;
|
|
@@ -437,18 +982,18 @@ var _ch = (ch) => {
|
|
|
437
982
|
return ch - (C.a - 10);
|
|
438
983
|
return;
|
|
439
984
|
};
|
|
440
|
-
var hexToBytes = (
|
|
985
|
+
var hexToBytes = (hex2) => {
|
|
441
986
|
const e = "hex invalid";
|
|
442
|
-
if (!isStr(
|
|
987
|
+
if (!isStr(hex2))
|
|
443
988
|
return err(e);
|
|
444
|
-
const hl =
|
|
989
|
+
const hl = hex2.length;
|
|
445
990
|
const al = hl / 2;
|
|
446
991
|
if (hl % 2)
|
|
447
992
|
return err(e);
|
|
448
993
|
const array = u8n(al);
|
|
449
994
|
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
450
|
-
const n1 = _ch(
|
|
451
|
-
const n2 = _ch(
|
|
995
|
+
const n1 = _ch(hex2.charCodeAt(hi));
|
|
996
|
+
const n2 = _ch(hex2.charCodeAt(hi + 1));
|
|
452
997
|
if (n1 === void 0 || n2 === void 0)
|
|
453
998
|
return err(e);
|
|
454
999
|
array[ai] = n1 * 16 + n2;
|
|
@@ -514,10 +1059,10 @@ var Point = class _Point {
|
|
|
514
1059
|
return new _Point(p.x, p.y, 1n, M(p.x * p.y));
|
|
515
1060
|
}
|
|
516
1061
|
/** RFC8032 5.1.3: Uint8Array to Point. */
|
|
517
|
-
static fromBytes(
|
|
1062
|
+
static fromBytes(hex2, zip215 = false) {
|
|
518
1063
|
const d = _d;
|
|
519
|
-
const normed = u8fr(abytes(
|
|
520
|
-
const lastByte =
|
|
1064
|
+
const normed = u8fr(abytes(hex2, L));
|
|
1065
|
+
const lastByte = hex2[31];
|
|
521
1066
|
normed[31] = lastByte & -129;
|
|
522
1067
|
const y = bytesToNumLE(normed);
|
|
523
1068
|
const max = zip215 ? B256 : P;
|
|
@@ -536,8 +1081,8 @@ var Point = class _Point {
|
|
|
536
1081
|
x = M(-x);
|
|
537
1082
|
return new _Point(x, y, 1n, M(x * y));
|
|
538
1083
|
}
|
|
539
|
-
static fromHex(
|
|
540
|
-
return _Point.fromBytes(hexToBytes(
|
|
1084
|
+
static fromHex(hex2, zip215) {
|
|
1085
|
+
return _Point.fromBytes(hexToBytes(hex2), zip215);
|
|
541
1086
|
}
|
|
542
1087
|
get x() {
|
|
543
1088
|
return this.toAffine().x;
|
|
@@ -876,13 +1421,13 @@ function anumber(n, title = "") {
|
|
|
876
1421
|
}
|
|
877
1422
|
}
|
|
878
1423
|
function abytes2(value, length, title = "") {
|
|
879
|
-
const
|
|
1424
|
+
const bytes2 = isBytes2(value);
|
|
880
1425
|
const len = value?.length;
|
|
881
1426
|
const needsLen = length !== void 0;
|
|
882
|
-
if (!
|
|
1427
|
+
if (!bytes2 || needsLen && len !== length) {
|
|
883
1428
|
const prefix = title && `"${title}" `;
|
|
884
1429
|
const ofLen = needsLen ? ` of length ${length}` : "";
|
|
885
|
-
const got =
|
|
1430
|
+
const got = bytes2 ? `length=${len}` : `type=${typeof value}`;
|
|
886
1431
|
throw new Error(prefix + "expected Uint8Array" + ofLen + ", got " + got);
|
|
887
1432
|
}
|
|
888
1433
|
return value;
|
|
@@ -1399,354 +1944,72 @@ var SHA2_64B = class extends HashMD {
|
|
|
1399
1944
|
Gl = Fl | 0;
|
|
1400
1945
|
Fh = Eh | 0;
|
|
1401
1946
|
Fl = El | 0;
|
|
1402
|
-
({ h: Eh, l: El } = add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
|
|
1403
|
-
Dh = Ch | 0;
|
|
1404
|
-
Dl = Cl | 0;
|
|
1405
|
-
Ch = Bh | 0;
|
|
1406
|
-
Cl = Bl | 0;
|
|
1407
|
-
Bh = Ah | 0;
|
|
1408
|
-
Bl = Al | 0;
|
|
1409
|
-
const All = add3L(T1l, sigma0l, MAJl);
|
|
1410
|
-
Ah = add3H(All, T1h, sigma0h, MAJh);
|
|
1411
|
-
Al = All | 0;
|
|
1412
|
-
}
|
|
1413
|
-
({ h: Ah, l: Al } = add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
|
|
1414
|
-
({ h: Bh, l: Bl } = add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
|
|
1415
|
-
({ h: Ch, l: Cl } = add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
|
|
1416
|
-
({ h: Dh, l: Dl } = add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
|
|
1417
|
-
({ h: Eh, l: El } = add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
|
|
1418
|
-
({ h: Fh, l: Fl } = add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
|
|
1419
|
-
({ h: Gh, l: Gl } = add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
|
|
1420
|
-
({ h: Hh, l: Hl } = add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
|
|
1421
|
-
this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
|
|
1422
|
-
}
|
|
1423
|
-
roundClean() {
|
|
1424
|
-
clean(SHA512_W_H, SHA512_W_L);
|
|
1425
|
-
}
|
|
1426
|
-
destroy() {
|
|
1427
|
-
clean(this.buffer);
|
|
1428
|
-
this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
1429
|
-
}
|
|
1430
|
-
};
|
|
1431
|
-
var _SHA512 = class extends SHA2_64B {
|
|
1432
|
-
Ah = SHA512_IV[0] | 0;
|
|
1433
|
-
Al = SHA512_IV[1] | 0;
|
|
1434
|
-
Bh = SHA512_IV[2] | 0;
|
|
1435
|
-
Bl = SHA512_IV[3] | 0;
|
|
1436
|
-
Ch = SHA512_IV[4] | 0;
|
|
1437
|
-
Cl = SHA512_IV[5] | 0;
|
|
1438
|
-
Dh = SHA512_IV[6] | 0;
|
|
1439
|
-
Dl = SHA512_IV[7] | 0;
|
|
1440
|
-
Eh = SHA512_IV[8] | 0;
|
|
1441
|
-
El = SHA512_IV[9] | 0;
|
|
1442
|
-
Fh = SHA512_IV[10] | 0;
|
|
1443
|
-
Fl = SHA512_IV[11] | 0;
|
|
1444
|
-
Gh = SHA512_IV[12] | 0;
|
|
1445
|
-
Gl = SHA512_IV[13] | 0;
|
|
1446
|
-
Hh = SHA512_IV[14] | 0;
|
|
1447
|
-
Hl = SHA512_IV[15] | 0;
|
|
1448
|
-
constructor() {
|
|
1449
|
-
super(64);
|
|
1450
|
-
}
|
|
1451
|
-
};
|
|
1452
|
-
var sha256 = /* @__PURE__ */ createHasher(
|
|
1453
|
-
() => new _SHA256(),
|
|
1454
|
-
/* @__PURE__ */ oidNist(1)
|
|
1455
|
-
);
|
|
1456
|
-
var sha512 = /* @__PURE__ */ createHasher(
|
|
1457
|
-
() => new _SHA512(),
|
|
1458
|
-
/* @__PURE__ */ oidNist(3)
|
|
1459
|
-
);
|
|
1460
|
-
|
|
1461
|
-
// node_modules/@scure/base/index.js
|
|
1462
|
-
function isBytes3(a) {
|
|
1463
|
-
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
1464
|
-
}
|
|
1465
|
-
function isArrayOf(isString, arr) {
|
|
1466
|
-
if (!Array.isArray(arr))
|
|
1467
|
-
return false;
|
|
1468
|
-
if (arr.length === 0)
|
|
1469
|
-
return true;
|
|
1470
|
-
if (isString) {
|
|
1471
|
-
return arr.every((item) => typeof item === "string");
|
|
1472
|
-
} else {
|
|
1473
|
-
return arr.every((item) => Number.isSafeInteger(item));
|
|
1474
|
-
}
|
|
1475
|
-
}
|
|
1476
|
-
function afn(input) {
|
|
1477
|
-
if (typeof input !== "function")
|
|
1478
|
-
throw new Error("function expected");
|
|
1479
|
-
return true;
|
|
1480
|
-
}
|
|
1481
|
-
function astr(label, input) {
|
|
1482
|
-
if (typeof input !== "string")
|
|
1483
|
-
throw new Error(`${label}: string expected`);
|
|
1484
|
-
return true;
|
|
1485
|
-
}
|
|
1486
|
-
function anumber2(n) {
|
|
1487
|
-
if (!Number.isSafeInteger(n))
|
|
1488
|
-
throw new Error(`invalid integer: ${n}`);
|
|
1489
|
-
}
|
|
1490
|
-
function aArr(input) {
|
|
1491
|
-
if (!Array.isArray(input))
|
|
1492
|
-
throw new Error("array expected");
|
|
1493
|
-
}
|
|
1494
|
-
function astrArr(label, input) {
|
|
1495
|
-
if (!isArrayOf(true, input))
|
|
1496
|
-
throw new Error(`${label}: array of strings expected`);
|
|
1497
|
-
}
|
|
1498
|
-
function anumArr(label, input) {
|
|
1499
|
-
if (!isArrayOf(false, input))
|
|
1500
|
-
throw new Error(`${label}: array of numbers expected`);
|
|
1501
|
-
}
|
|
1502
|
-
// @__NO_SIDE_EFFECTS__
|
|
1503
|
-
function chain(...args) {
|
|
1504
|
-
const id = (a) => a;
|
|
1505
|
-
const wrap = (a, b) => (c) => a(b(c));
|
|
1506
|
-
const encode = args.map((x) => x.encode).reduceRight(wrap, id);
|
|
1507
|
-
const decode = args.map((x) => x.decode).reduce(wrap, id);
|
|
1508
|
-
return { encode, decode };
|
|
1509
|
-
}
|
|
1510
|
-
// @__NO_SIDE_EFFECTS__
|
|
1511
|
-
function alphabet(letters) {
|
|
1512
|
-
const lettersA = typeof letters === "string" ? letters.split("") : letters;
|
|
1513
|
-
const len = lettersA.length;
|
|
1514
|
-
astrArr("alphabet", lettersA);
|
|
1515
|
-
const indexes = new Map(lettersA.map((l, i) => [l, i]));
|
|
1516
|
-
return {
|
|
1517
|
-
encode: (digits) => {
|
|
1518
|
-
aArr(digits);
|
|
1519
|
-
return digits.map((i) => {
|
|
1520
|
-
if (!Number.isSafeInteger(i) || i < 0 || i >= len)
|
|
1521
|
-
throw new Error(`alphabet.encode: digit index outside alphabet "${i}". Allowed: ${letters}`);
|
|
1522
|
-
return lettersA[i];
|
|
1523
|
-
});
|
|
1524
|
-
},
|
|
1525
|
-
decode: (input) => {
|
|
1526
|
-
aArr(input);
|
|
1527
|
-
return input.map((letter) => {
|
|
1528
|
-
astr("alphabet.decode", letter);
|
|
1529
|
-
const i = indexes.get(letter);
|
|
1530
|
-
if (i === void 0)
|
|
1531
|
-
throw new Error(`Unknown letter: "${letter}". Allowed: ${letters}`);
|
|
1532
|
-
return i;
|
|
1533
|
-
});
|
|
1534
|
-
}
|
|
1535
|
-
};
|
|
1536
|
-
}
|
|
1537
|
-
// @__NO_SIDE_EFFECTS__
|
|
1538
|
-
function join(separator = "") {
|
|
1539
|
-
astr("join", separator);
|
|
1540
|
-
return {
|
|
1541
|
-
encode: (from) => {
|
|
1542
|
-
astrArr("join.decode", from);
|
|
1543
|
-
return from.join(separator);
|
|
1544
|
-
},
|
|
1545
|
-
decode: (to) => {
|
|
1546
|
-
astr("join.decode", to);
|
|
1547
|
-
return to.split(separator);
|
|
1548
|
-
}
|
|
1549
|
-
};
|
|
1550
|
-
}
|
|
1551
|
-
// @__NO_SIDE_EFFECTS__
|
|
1552
|
-
function padding(bits, chr = "=") {
|
|
1553
|
-
anumber2(bits);
|
|
1554
|
-
astr("padding", chr);
|
|
1555
|
-
return {
|
|
1556
|
-
encode(data) {
|
|
1557
|
-
astrArr("padding.encode", data);
|
|
1558
|
-
while (data.length * bits % 8)
|
|
1559
|
-
data.push(chr);
|
|
1560
|
-
return data;
|
|
1561
|
-
},
|
|
1562
|
-
decode(input) {
|
|
1563
|
-
astrArr("padding.decode", input);
|
|
1564
|
-
let end = input.length;
|
|
1565
|
-
if (end * bits % 8)
|
|
1566
|
-
throw new Error("padding: invalid, string should have whole number of bytes");
|
|
1567
|
-
for (; end > 0 && input[end - 1] === chr; end--) {
|
|
1568
|
-
const last = end - 1;
|
|
1569
|
-
const byte = last * bits;
|
|
1570
|
-
if (byte % 8 === 0)
|
|
1571
|
-
throw new Error("padding: invalid, string has too much padding");
|
|
1572
|
-
}
|
|
1573
|
-
return input.slice(0, end);
|
|
1574
|
-
}
|
|
1575
|
-
};
|
|
1576
|
-
}
|
|
1577
|
-
function convertRadix(data, from, to) {
|
|
1578
|
-
if (from < 2)
|
|
1579
|
-
throw new Error(`convertRadix: invalid from=${from}, base cannot be less than 2`);
|
|
1580
|
-
if (to < 2)
|
|
1581
|
-
throw new Error(`convertRadix: invalid to=${to}, base cannot be less than 2`);
|
|
1582
|
-
aArr(data);
|
|
1583
|
-
if (!data.length)
|
|
1584
|
-
return [];
|
|
1585
|
-
let pos = 0;
|
|
1586
|
-
const res = [];
|
|
1587
|
-
const digits = Array.from(data, (d) => {
|
|
1588
|
-
anumber2(d);
|
|
1589
|
-
if (d < 0 || d >= from)
|
|
1590
|
-
throw new Error(`invalid integer: ${d}`);
|
|
1591
|
-
return d;
|
|
1592
|
-
});
|
|
1593
|
-
const dlen = digits.length;
|
|
1594
|
-
while (true) {
|
|
1595
|
-
let carry = 0;
|
|
1596
|
-
let done = true;
|
|
1597
|
-
for (let i = pos; i < dlen; i++) {
|
|
1598
|
-
const digit = digits[i];
|
|
1599
|
-
const fromCarry = from * carry;
|
|
1600
|
-
const digitBase = fromCarry + digit;
|
|
1601
|
-
if (!Number.isSafeInteger(digitBase) || fromCarry / from !== carry || digitBase - digit !== fromCarry) {
|
|
1602
|
-
throw new Error("convertRadix: carry overflow");
|
|
1603
|
-
}
|
|
1604
|
-
const div = digitBase / to;
|
|
1605
|
-
carry = digitBase % to;
|
|
1606
|
-
const rounded = Math.floor(div);
|
|
1607
|
-
digits[i] = rounded;
|
|
1608
|
-
if (!Number.isSafeInteger(rounded) || rounded * to + carry !== digitBase)
|
|
1609
|
-
throw new Error("convertRadix: carry overflow");
|
|
1610
|
-
if (!done)
|
|
1611
|
-
continue;
|
|
1612
|
-
else if (!rounded)
|
|
1613
|
-
pos = i;
|
|
1614
|
-
else
|
|
1615
|
-
done = false;
|
|
1947
|
+
({ h: Eh, l: El } = add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
|
|
1948
|
+
Dh = Ch | 0;
|
|
1949
|
+
Dl = Cl | 0;
|
|
1950
|
+
Ch = Bh | 0;
|
|
1951
|
+
Cl = Bl | 0;
|
|
1952
|
+
Bh = Ah | 0;
|
|
1953
|
+
Bl = Al | 0;
|
|
1954
|
+
const All = add3L(T1l, sigma0l, MAJl);
|
|
1955
|
+
Ah = add3H(All, T1h, sigma0h, MAJh);
|
|
1956
|
+
Al = All | 0;
|
|
1616
1957
|
}
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1958
|
+
({ h: Ah, l: Al } = add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
|
|
1959
|
+
({ h: Bh, l: Bl } = add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
|
|
1960
|
+
({ h: Ch, l: Cl } = add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
|
|
1961
|
+
({ h: Dh, l: Dl } = add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
|
|
1962
|
+
({ h: Eh, l: El } = add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
|
|
1963
|
+
({ h: Fh, l: Fl } = add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
|
|
1964
|
+
({ h: Gh, l: Gl } = add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
|
|
1965
|
+
({ h: Hh, l: Hl } = add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
|
|
1966
|
+
this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
|
|
1620
1967
|
}
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
return res.reverse();
|
|
1624
|
-
}
|
|
1625
|
-
var gcd = (a, b) => b === 0 ? a : gcd(b, a % b);
|
|
1626
|
-
var radix2carry = /* @__NO_SIDE_EFFECTS__ */ (from, to) => from + (to - gcd(from, to));
|
|
1627
|
-
var powers = /* @__PURE__ */ (() => {
|
|
1628
|
-
let res = [];
|
|
1629
|
-
for (let i = 0; i < 40; i++)
|
|
1630
|
-
res.push(2 ** i);
|
|
1631
|
-
return res;
|
|
1632
|
-
})();
|
|
1633
|
-
function convertRadix2(data, from, to, padding2) {
|
|
1634
|
-
aArr(data);
|
|
1635
|
-
if (from <= 0 || from > 32)
|
|
1636
|
-
throw new Error(`convertRadix2: wrong from=${from}`);
|
|
1637
|
-
if (to <= 0 || to > 32)
|
|
1638
|
-
throw new Error(`convertRadix2: wrong to=${to}`);
|
|
1639
|
-
if (/* @__PURE__ */ radix2carry(from, to) > 32) {
|
|
1640
|
-
throw new Error(`convertRadix2: carry overflow from=${from} to=${to} carryBits=${/* @__PURE__ */ radix2carry(from, to)}`);
|
|
1968
|
+
roundClean() {
|
|
1969
|
+
clean(SHA512_W_H, SHA512_W_L);
|
|
1641
1970
|
}
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1971
|
+
destroy() {
|
|
1972
|
+
clean(this.buffer);
|
|
1973
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
1974
|
+
}
|
|
1975
|
+
};
|
|
1976
|
+
var _SHA512 = class extends SHA2_64B {
|
|
1977
|
+
Ah = SHA512_IV[0] | 0;
|
|
1978
|
+
Al = SHA512_IV[1] | 0;
|
|
1979
|
+
Bh = SHA512_IV[2] | 0;
|
|
1980
|
+
Bl = SHA512_IV[3] | 0;
|
|
1981
|
+
Ch = SHA512_IV[4] | 0;
|
|
1982
|
+
Cl = SHA512_IV[5] | 0;
|
|
1983
|
+
Dh = SHA512_IV[6] | 0;
|
|
1984
|
+
Dl = SHA512_IV[7] | 0;
|
|
1985
|
+
Eh = SHA512_IV[8] | 0;
|
|
1986
|
+
El = SHA512_IV[9] | 0;
|
|
1987
|
+
Fh = SHA512_IV[10] | 0;
|
|
1988
|
+
Fl = SHA512_IV[11] | 0;
|
|
1989
|
+
Gh = SHA512_IV[12] | 0;
|
|
1990
|
+
Gl = SHA512_IV[13] | 0;
|
|
1991
|
+
Hh = SHA512_IV[14] | 0;
|
|
1992
|
+
Hl = SHA512_IV[15] | 0;
|
|
1993
|
+
constructor() {
|
|
1994
|
+
super(64);
|
|
1661
1995
|
}
|
|
1662
|
-
carry = carry << to - pos & mask;
|
|
1663
|
-
if (!padding2 && pos >= from)
|
|
1664
|
-
throw new Error("Excess padding");
|
|
1665
|
-
if (!padding2 && carry > 0)
|
|
1666
|
-
throw new Error(`Non-zero padding: ${carry}`);
|
|
1667
|
-
if (padding2 && pos > 0)
|
|
1668
|
-
res.push(carry >>> 0);
|
|
1669
|
-
return res;
|
|
1670
|
-
}
|
|
1671
|
-
// @__NO_SIDE_EFFECTS__
|
|
1672
|
-
function radix(num) {
|
|
1673
|
-
anumber2(num);
|
|
1674
|
-
const _256 = 2 ** 8;
|
|
1675
|
-
return {
|
|
1676
|
-
encode: (bytes) => {
|
|
1677
|
-
if (!isBytes3(bytes))
|
|
1678
|
-
throw new Error("radix.encode input should be Uint8Array");
|
|
1679
|
-
return convertRadix(Array.from(bytes), _256, num);
|
|
1680
|
-
},
|
|
1681
|
-
decode: (digits) => {
|
|
1682
|
-
anumArr("radix.decode", digits);
|
|
1683
|
-
return Uint8Array.from(convertRadix(digits, num, _256));
|
|
1684
|
-
}
|
|
1685
|
-
};
|
|
1686
|
-
}
|
|
1687
|
-
// @__NO_SIDE_EFFECTS__
|
|
1688
|
-
function radix2(bits, revPadding = false) {
|
|
1689
|
-
anumber2(bits);
|
|
1690
|
-
if (bits <= 0 || bits > 32)
|
|
1691
|
-
throw new Error("radix2: bits should be in (0..32]");
|
|
1692
|
-
if (/* @__PURE__ */ radix2carry(8, bits) > 32 || /* @__PURE__ */ radix2carry(bits, 8) > 32)
|
|
1693
|
-
throw new Error("radix2: carry overflow");
|
|
1694
|
-
return {
|
|
1695
|
-
encode: (bytes) => {
|
|
1696
|
-
if (!isBytes3(bytes))
|
|
1697
|
-
throw new Error("radix2.encode input should be Uint8Array");
|
|
1698
|
-
return convertRadix2(Array.from(bytes), 8, bits, !revPadding);
|
|
1699
|
-
},
|
|
1700
|
-
decode: (digits) => {
|
|
1701
|
-
anumArr("radix2.decode", digits);
|
|
1702
|
-
return Uint8Array.from(convertRadix2(digits, bits, 8, revPadding));
|
|
1703
|
-
}
|
|
1704
|
-
};
|
|
1705
|
-
}
|
|
1706
|
-
function checksum(len, fn) {
|
|
1707
|
-
anumber2(len);
|
|
1708
|
-
afn(fn);
|
|
1709
|
-
return {
|
|
1710
|
-
encode(data) {
|
|
1711
|
-
if (!isBytes3(data))
|
|
1712
|
-
throw new Error("checksum.encode: input should be Uint8Array");
|
|
1713
|
-
const sum = fn(data).slice(0, len);
|
|
1714
|
-
const res = new Uint8Array(data.length + len);
|
|
1715
|
-
res.set(data);
|
|
1716
|
-
res.set(sum, data.length);
|
|
1717
|
-
return res;
|
|
1718
|
-
},
|
|
1719
|
-
decode(data) {
|
|
1720
|
-
if (!isBytes3(data))
|
|
1721
|
-
throw new Error("checksum.decode: input should be Uint8Array");
|
|
1722
|
-
const payload = data.slice(0, -len);
|
|
1723
|
-
const oldChecksum = data.slice(-len);
|
|
1724
|
-
const newChecksum = fn(payload).slice(0, len);
|
|
1725
|
-
for (let i = 0; i < len; i++)
|
|
1726
|
-
if (newChecksum[i] !== oldChecksum[i])
|
|
1727
|
-
throw new Error("Invalid checksum");
|
|
1728
|
-
return payload;
|
|
1729
|
-
}
|
|
1730
|
-
};
|
|
1731
|
-
}
|
|
1732
|
-
var utils = {
|
|
1733
|
-
alphabet,
|
|
1734
|
-
chain,
|
|
1735
|
-
checksum,
|
|
1736
|
-
convertRadix,
|
|
1737
|
-
convertRadix2,
|
|
1738
|
-
radix,
|
|
1739
|
-
radix2,
|
|
1740
|
-
join,
|
|
1741
|
-
padding
|
|
1742
1996
|
};
|
|
1743
|
-
var
|
|
1744
|
-
|
|
1997
|
+
var sha256 = /* @__PURE__ */ createHasher(
|
|
1998
|
+
() => new _SHA256(),
|
|
1999
|
+
/* @__PURE__ */ oidNist(1)
|
|
2000
|
+
);
|
|
2001
|
+
var sha512 = /* @__PURE__ */ createHasher(
|
|
2002
|
+
() => new _SHA512(),
|
|
2003
|
+
/* @__PURE__ */ oidNist(3)
|
|
2004
|
+
);
|
|
2005
|
+
|
|
2006
|
+
// src/crypto/public-key.ts
|
|
2007
|
+
init_base();
|
|
1745
2008
|
|
|
1746
2009
|
// src/crypto/utils.ts
|
|
1747
|
-
function isOnCurve(
|
|
2010
|
+
function isOnCurve(bytes2) {
|
|
1748
2011
|
try {
|
|
1749
|
-
Point.fromBytes(
|
|
2012
|
+
Point.fromBytes(bytes2);
|
|
1750
2013
|
return true;
|
|
1751
2014
|
} catch {
|
|
1752
2015
|
return false;
|
|
@@ -1773,11 +2036,11 @@ var PDA_MARKER = new TextEncoder().encode("ProgramDerivedAddress");
|
|
|
1773
2036
|
var MAX_BUMP_SEED = 255;
|
|
1774
2037
|
var PublicKey = class _PublicKey {
|
|
1775
2038
|
bytes;
|
|
1776
|
-
constructor(
|
|
1777
|
-
if (
|
|
1778
|
-
throw CryptoError.invalidKeyLength(PUBLIC_KEY_LENGTH,
|
|
2039
|
+
constructor(bytes2) {
|
|
2040
|
+
if (bytes2.length !== PUBLIC_KEY_LENGTH) {
|
|
2041
|
+
throw CryptoError.invalidKeyLength(PUBLIC_KEY_LENGTH, bytes2.length);
|
|
1779
2042
|
}
|
|
1780
|
-
this.bytes = new Uint8Array(
|
|
2043
|
+
this.bytes = new Uint8Array(bytes2);
|
|
1781
2044
|
}
|
|
1782
2045
|
/**
|
|
1783
2046
|
* Creates a PublicKey from raw bytes.
|
|
@@ -1785,8 +2048,8 @@ var PublicKey = class _PublicKey {
|
|
|
1785
2048
|
* @param bytes - 32-byte Ed25519 public key
|
|
1786
2049
|
* @throws {CryptoError} If bytes length is not 32
|
|
1787
2050
|
*/
|
|
1788
|
-
static fromBytes(
|
|
1789
|
-
return new _PublicKey(
|
|
2051
|
+
static fromBytes(bytes2) {
|
|
2052
|
+
return new _PublicKey(bytes2);
|
|
1790
2053
|
}
|
|
1791
2054
|
/**
|
|
1792
2055
|
* Creates a PublicKey from a base58-encoded string.
|
|
@@ -1794,15 +2057,15 @@ var PublicKey = class _PublicKey {
|
|
|
1794
2057
|
* @param str - Base58-encoded public key
|
|
1795
2058
|
* @throws {CryptoError} If string is invalid or decodes to wrong length
|
|
1796
2059
|
*/
|
|
1797
|
-
static fromString(
|
|
2060
|
+
static fromString(str2) {
|
|
1798
2061
|
try {
|
|
1799
|
-
const
|
|
1800
|
-
return new _PublicKey(
|
|
2062
|
+
const bytes2 = base58.decode(str2);
|
|
2063
|
+
return new _PublicKey(bytes2);
|
|
1801
2064
|
} catch (error) {
|
|
1802
2065
|
throw new CryptoError(
|
|
1803
2066
|
"INVALID_PUBLIC_KEY" /* INVALID_PUBLIC_KEY */,
|
|
1804
2067
|
`Invalid base58 public key: ${error instanceof Error ? error.message : "unknown error"}`,
|
|
1805
|
-
{ input:
|
|
2068
|
+
{ input: str2 }
|
|
1806
2069
|
);
|
|
1807
2070
|
}
|
|
1808
2071
|
}
|
|
@@ -1840,14 +2103,14 @@ var PublicKey = class _PublicKey {
|
|
|
1840
2103
|
}
|
|
1841
2104
|
const seedBytes = [];
|
|
1842
2105
|
for (let i = 0; i < seeds.length; i++) {
|
|
1843
|
-
const
|
|
1844
|
-
if (
|
|
2106
|
+
const bytes2 = seedToBytes(seeds[i]);
|
|
2107
|
+
if (bytes2.length > MAX_SEED_LENGTH) {
|
|
1845
2108
|
throw new CryptoError(
|
|
1846
2109
|
"MAX_SEED_LENGTH_EXCEEDED" /* MAX_SEED_LENGTH_EXCEEDED */,
|
|
1847
2110
|
`Seed[${i}] exceeds ${MAX_SEED_LENGTH} bytes`
|
|
1848
2111
|
);
|
|
1849
2112
|
}
|
|
1850
|
-
seedBytes.push(
|
|
2113
|
+
seedBytes.push(bytes2);
|
|
1851
2114
|
}
|
|
1852
2115
|
const hash = sha256(concatBytes2(...seedBytes, programId.bytes, PDA_MARKER));
|
|
1853
2116
|
if (isOnCurve(hash)) {
|
|
@@ -2006,13 +2269,14 @@ var PublicKey = class _PublicKey {
|
|
|
2006
2269
|
};
|
|
2007
2270
|
|
|
2008
2271
|
// src/crypto/signature.ts
|
|
2272
|
+
init_base();
|
|
2009
2273
|
var Signature = class _Signature {
|
|
2010
2274
|
bytes;
|
|
2011
|
-
constructor(
|
|
2012
|
-
if (
|
|
2013
|
-
throw CryptoError.invalidKeyLength(SIGNATURE_LENGTH,
|
|
2275
|
+
constructor(bytes2) {
|
|
2276
|
+
if (bytes2.length !== SIGNATURE_LENGTH) {
|
|
2277
|
+
throw CryptoError.invalidKeyLength(SIGNATURE_LENGTH, bytes2.length);
|
|
2014
2278
|
}
|
|
2015
|
-
this.bytes = new Uint8Array(
|
|
2279
|
+
this.bytes = new Uint8Array(bytes2);
|
|
2016
2280
|
}
|
|
2017
2281
|
/**
|
|
2018
2282
|
* Creates a Signature from raw bytes.
|
|
@@ -2020,8 +2284,8 @@ var Signature = class _Signature {
|
|
|
2020
2284
|
* @param bytes - 64-byte Ed25519 signature
|
|
2021
2285
|
* @throws {CryptoError} If bytes length is not 64
|
|
2022
2286
|
*/
|
|
2023
|
-
static fromBytes(
|
|
2024
|
-
return new _Signature(
|
|
2287
|
+
static fromBytes(bytes2) {
|
|
2288
|
+
return new _Signature(bytes2);
|
|
2025
2289
|
}
|
|
2026
2290
|
/**
|
|
2027
2291
|
* Creates a Signature from a base58-encoded string.
|
|
@@ -2029,15 +2293,15 @@ var Signature = class _Signature {
|
|
|
2029
2293
|
* @param str - Base58-encoded signature
|
|
2030
2294
|
* @throws {CryptoError} If string is invalid or decodes to wrong length
|
|
2031
2295
|
*/
|
|
2032
|
-
static fromString(
|
|
2296
|
+
static fromString(str2) {
|
|
2033
2297
|
try {
|
|
2034
|
-
const
|
|
2035
|
-
return new _Signature(
|
|
2298
|
+
const bytes2 = base58.decode(str2);
|
|
2299
|
+
return new _Signature(bytes2);
|
|
2036
2300
|
} catch (error) {
|
|
2037
2301
|
throw new CryptoError(
|
|
2038
2302
|
"INVALID_SIGNATURE" /* INVALID_SIGNATURE */,
|
|
2039
2303
|
`Invalid base58 signature: ${error instanceof Error ? error.message : "unknown error"}`,
|
|
2040
|
-
{ input:
|
|
2304
|
+
{ input: str2 }
|
|
2041
2305
|
);
|
|
2042
2306
|
}
|
|
2043
2307
|
}
|
|
@@ -2259,14 +2523,14 @@ function anumber3(n, title = "") {
|
|
|
2259
2523
|
throw new Error(`${prefix}expected integer >= 0, got ${n}`);
|
|
2260
2524
|
}
|
|
2261
2525
|
}
|
|
2262
|
-
function
|
|
2263
|
-
const
|
|
2526
|
+
function abytes4(value, length, title = "") {
|
|
2527
|
+
const bytes2 = isBytes4(value);
|
|
2264
2528
|
const len = value?.length;
|
|
2265
2529
|
const needsLen = length !== void 0;
|
|
2266
|
-
if (!
|
|
2530
|
+
if (!bytes2 || needsLen && len !== length) {
|
|
2267
2531
|
const prefix = title && `"${title}" `;
|
|
2268
2532
|
const ofLen = needsLen ? ` of length ${length}` : "";
|
|
2269
|
-
const got =
|
|
2533
|
+
const got = bytes2 ? `length=${len}` : `type=${typeof value}`;
|
|
2270
2534
|
throw new Error(prefix + "expected Uint8Array" + ofLen + ", got " + got);
|
|
2271
2535
|
}
|
|
2272
2536
|
return value;
|
|
@@ -2284,7 +2548,7 @@ function aexists2(instance, checkFinished = true) {
|
|
|
2284
2548
|
throw new Error("Hash#digest() has already been called");
|
|
2285
2549
|
}
|
|
2286
2550
|
function aoutput2(out, instance) {
|
|
2287
|
-
|
|
2551
|
+
abytes4(out, void 0, "digestInto() output");
|
|
2288
2552
|
const min = instance.outputLen;
|
|
2289
2553
|
if (out.length < min) {
|
|
2290
2554
|
throw new Error('"digestInto() output" expected to be of length >=' + min);
|
|
@@ -2314,15 +2578,15 @@ async function asyncLoop(iters, tick, cb) {
|
|
|
2314
2578
|
ts += diff;
|
|
2315
2579
|
}
|
|
2316
2580
|
}
|
|
2317
|
-
function utf8ToBytes(
|
|
2318
|
-
if (typeof
|
|
2581
|
+
function utf8ToBytes(str2) {
|
|
2582
|
+
if (typeof str2 !== "string")
|
|
2319
2583
|
throw new Error("string expected");
|
|
2320
|
-
return new Uint8Array(new TextEncoder().encode(
|
|
2584
|
+
return new Uint8Array(new TextEncoder().encode(str2));
|
|
2321
2585
|
}
|
|
2322
2586
|
function kdfInputToBytes(data, errorTitle = "") {
|
|
2323
2587
|
if (typeof data === "string")
|
|
2324
2588
|
return utf8ToBytes(data);
|
|
2325
|
-
return
|
|
2589
|
+
return abytes4(data, void 0, errorTitle);
|
|
2326
2590
|
}
|
|
2327
2591
|
function checkOpts(defaults, opts) {
|
|
2328
2592
|
if (opts !== void 0 && {}.toString.call(opts) !== "[object Object]")
|
|
@@ -2359,7 +2623,7 @@ var _HMAC2 = class {
|
|
|
2359
2623
|
destroyed = false;
|
|
2360
2624
|
constructor(hash, key) {
|
|
2361
2625
|
ahash2(hash);
|
|
2362
|
-
|
|
2626
|
+
abytes4(key, void 0, "key");
|
|
2363
2627
|
this.iHash = hash.create();
|
|
2364
2628
|
if (typeof this.iHash.update !== "function")
|
|
2365
2629
|
throw new Error("Expected instance of class which extends utils.Hash");
|
|
@@ -2384,7 +2648,7 @@ var _HMAC2 = class {
|
|
|
2384
2648
|
}
|
|
2385
2649
|
digestInto(out) {
|
|
2386
2650
|
aexists2(this);
|
|
2387
|
-
|
|
2651
|
+
abytes4(out, this.outputLen, "output");
|
|
2388
2652
|
this.finished = true;
|
|
2389
2653
|
this.iHash.digestInto(out);
|
|
2390
2654
|
this.oHash.update(out);
|
|
@@ -2494,7 +2758,7 @@ var HashMD2 = class {
|
|
|
2494
2758
|
}
|
|
2495
2759
|
update(data) {
|
|
2496
2760
|
aexists2(this);
|
|
2497
|
-
|
|
2761
|
+
abytes4(data);
|
|
2498
2762
|
const { view, buffer, blockLen } = this;
|
|
2499
2763
|
const len = data.length;
|
|
2500
2764
|
for (let pos = 0; pos < len; ) {
|
|
@@ -2988,21 +3252,22 @@ var sha5122 = /* @__PURE__ */ createHasher2(
|
|
|
2988
3252
|
);
|
|
2989
3253
|
|
|
2990
3254
|
// node_modules/@scure/bip39/index.js
|
|
3255
|
+
init_base();
|
|
2991
3256
|
var isJapanese = (wordlist2) => wordlist2[0] === "\u3042\u3044\u3053\u304F\u3057\u3093";
|
|
2992
|
-
function nfkd(
|
|
2993
|
-
if (typeof
|
|
2994
|
-
throw new TypeError("invalid mnemonic type: " + typeof
|
|
2995
|
-
return
|
|
3257
|
+
function nfkd(str2) {
|
|
3258
|
+
if (typeof str2 !== "string")
|
|
3259
|
+
throw new TypeError("invalid mnemonic type: " + typeof str2);
|
|
3260
|
+
return str2.normalize("NFKD");
|
|
2996
3261
|
}
|
|
2997
|
-
function
|
|
2998
|
-
const norm = nfkd(
|
|
3262
|
+
function normalize2(str2) {
|
|
3263
|
+
const norm = nfkd(str2);
|
|
2999
3264
|
const words = norm.split(" ");
|
|
3000
3265
|
if (![12, 15, 18, 21, 24].includes(words.length))
|
|
3001
3266
|
throw new Error("Invalid mnemonic");
|
|
3002
3267
|
return { nfkd: norm, words };
|
|
3003
3268
|
}
|
|
3004
3269
|
function aentropy(ent) {
|
|
3005
|
-
|
|
3270
|
+
abytes4(ent);
|
|
3006
3271
|
if (![16, 20, 24, 28, 32].includes(ent.length))
|
|
3007
3272
|
throw new Error("invalid entropy length");
|
|
3008
3273
|
}
|
|
@@ -3026,7 +3291,7 @@ function getCoder(wordlist2) {
|
|
|
3026
3291
|
return utils.chain(utils.checksum(1, calcChecksum), utils.radix2(11, true), utils.alphabet(wordlist2));
|
|
3027
3292
|
}
|
|
3028
3293
|
function mnemonicToEntropy(mnemonic, wordlist2) {
|
|
3029
|
-
const { words } =
|
|
3294
|
+
const { words } = normalize2(mnemonic);
|
|
3030
3295
|
const entropy = getCoder(wordlist2).decode(words);
|
|
3031
3296
|
aentropy(entropy);
|
|
3032
3297
|
return entropy;
|
|
@@ -3046,7 +3311,7 @@ function validateMnemonic(mnemonic, wordlist2) {
|
|
|
3046
3311
|
}
|
|
3047
3312
|
var psalt = (passphrase) => nfkd("mnemonic" + passphrase);
|
|
3048
3313
|
function mnemonicToSeed(mnemonic, passphrase = "") {
|
|
3049
|
-
return pbkdf2Async(sha5122,
|
|
3314
|
+
return pbkdf2Async(sha5122, normalize2(mnemonic).nfkd, psalt(passphrase), { c: 2048, dkLen: 64 });
|
|
3050
3315
|
}
|
|
3051
3316
|
|
|
3052
3317
|
// node_modules/@scure/bip39/wordlists/english.js
|
|
@@ -5431,54 +5696,350 @@ var RialoError = class _RialoError extends Error {
|
|
|
5431
5696
|
);
|
|
5432
5697
|
}
|
|
5433
5698
|
/**
|
|
5434
|
-
* Creates a password error.
|
|
5699
|
+
* Creates a password error.
|
|
5700
|
+
*/
|
|
5701
|
+
static password(message) {
|
|
5702
|
+
return new _RialoError(
|
|
5703
|
+
"PASSWORD" /* PASSWORD */,
|
|
5704
|
+
`Password error: ${message}`
|
|
5705
|
+
);
|
|
5706
|
+
}
|
|
5707
|
+
/**
|
|
5708
|
+
* Creates an encryption error.
|
|
5709
|
+
*/
|
|
5710
|
+
static encryption(message) {
|
|
5711
|
+
return new _RialoError(
|
|
5712
|
+
"ENCRYPTION" /* ENCRYPTION */,
|
|
5713
|
+
`Encryption error: ${message}`
|
|
5714
|
+
);
|
|
5715
|
+
}
|
|
5716
|
+
/**
|
|
5717
|
+
* Creates a JSON error.
|
|
5718
|
+
*/
|
|
5719
|
+
static json(message, cause) {
|
|
5720
|
+
return new _RialoError("JSON" /* JSON */, `JSON error: ${message}`, cause);
|
|
5721
|
+
}
|
|
5722
|
+
/**
|
|
5723
|
+
* Creates a BIP32 error.
|
|
5724
|
+
*/
|
|
5725
|
+
static bip32(message) {
|
|
5726
|
+
return new _RialoError("BIP32" /* BIP32 */, `BIP32 error: ${message}`);
|
|
5727
|
+
}
|
|
5728
|
+
/**
|
|
5729
|
+
* Creates an invalid input error.
|
|
5730
|
+
*/
|
|
5731
|
+
static invalidInput(message) {
|
|
5732
|
+
return new _RialoError(
|
|
5733
|
+
"INVALID_INPUT" /* INVALID_INPUT */,
|
|
5734
|
+
`Invalid input: ${message}`
|
|
5735
|
+
);
|
|
5736
|
+
}
|
|
5737
|
+
/**
|
|
5738
|
+
* Creates a serialization error.
|
|
5739
|
+
*/
|
|
5740
|
+
static serialization(message) {
|
|
5741
|
+
return new _RialoError(
|
|
5742
|
+
"SERIALIZATION" /* SERIALIZATION */,
|
|
5743
|
+
`Serialization error: ${message}`
|
|
5744
|
+
);
|
|
5745
|
+
}
|
|
5746
|
+
};
|
|
5747
|
+
|
|
5748
|
+
// src/rex/errors.ts
|
|
5749
|
+
var HpkeErrorCode = /* @__PURE__ */ ((HpkeErrorCode2) => {
|
|
5750
|
+
HpkeErrorCode2["INVALID_KEY_LENGTH"] = "INVALID_KEY_LENGTH";
|
|
5751
|
+
HpkeErrorCode2["CIPHERTEXT_TOO_SHORT"] = "CIPHERTEXT_TOO_SHORT";
|
|
5752
|
+
HpkeErrorCode2["ENCRYPTION_FAILED"] = "ENCRYPTION_FAILED";
|
|
5753
|
+
HpkeErrorCode2["BORSH_DESERIALIZE_FAILED"] = "BORSH_DESERIALIZE_FAILED";
|
|
5754
|
+
HpkeErrorCode2["INVALID_REX_VALUE"] = "INVALID_REX_VALUE";
|
|
5755
|
+
return HpkeErrorCode2;
|
|
5756
|
+
})(HpkeErrorCode || {});
|
|
5757
|
+
var HpkeError = class _HpkeError extends Error {
|
|
5758
|
+
code;
|
|
5759
|
+
cause;
|
|
5760
|
+
constructor(code, message, cause) {
|
|
5761
|
+
super(message);
|
|
5762
|
+
this.name = "HpkeError";
|
|
5763
|
+
this.code = code;
|
|
5764
|
+
this.cause = cause;
|
|
5765
|
+
if (Error.captureStackTrace) {
|
|
5766
|
+
Error.captureStackTrace(this, _HpkeError);
|
|
5767
|
+
}
|
|
5768
|
+
}
|
|
5769
|
+
/**
|
|
5770
|
+
* Create an error for invalid key length.
|
|
5771
|
+
*
|
|
5772
|
+
* @param expected - Expected key length in bytes
|
|
5773
|
+
* @param actual - Actual key length in bytes
|
|
5774
|
+
* @param keyType - Description of the key type (e.g., "REX public key")
|
|
5775
|
+
*/
|
|
5776
|
+
static invalidKeyLength(expected, actual, keyType) {
|
|
5777
|
+
return new _HpkeError(
|
|
5778
|
+
"INVALID_KEY_LENGTH" /* INVALID_KEY_LENGTH */,
|
|
5779
|
+
`Invalid ${keyType} length: expected ${expected} bytes, got ${actual}`
|
|
5780
|
+
);
|
|
5781
|
+
}
|
|
5782
|
+
/**
|
|
5783
|
+
* Create an error for ciphertext that is too short.
|
|
5784
|
+
*
|
|
5785
|
+
* @param minLength - Minimum required length
|
|
5786
|
+
* @param actual - Actual length
|
|
5787
|
+
*/
|
|
5788
|
+
static ciphertextTooShort(minLength, actual) {
|
|
5789
|
+
return new _HpkeError(
|
|
5790
|
+
"CIPHERTEXT_TOO_SHORT" /* CIPHERTEXT_TOO_SHORT */,
|
|
5791
|
+
`Ciphertext too short: minimum ${minLength} bytes required, got ${actual}`
|
|
5792
|
+
);
|
|
5793
|
+
}
|
|
5794
|
+
/**
|
|
5795
|
+
* Create an error for encryption failure.
|
|
5796
|
+
*
|
|
5797
|
+
* @param cause - The underlying error
|
|
5798
|
+
*/
|
|
5799
|
+
static encryptionFailed(cause) {
|
|
5800
|
+
return new _HpkeError(
|
|
5801
|
+
"ENCRYPTION_FAILED" /* ENCRYPTION_FAILED */,
|
|
5802
|
+
`HPKE encryption failed: ${cause.message}`,
|
|
5803
|
+
cause
|
|
5804
|
+
);
|
|
5805
|
+
}
|
|
5806
|
+
/**
|
|
5807
|
+
* Create an error for Borsh deserialization failure.
|
|
5808
|
+
*
|
|
5809
|
+
* @param cause - The underlying error
|
|
5810
|
+
*/
|
|
5811
|
+
static borshDeserializeFailed(cause) {
|
|
5812
|
+
return new _HpkeError(
|
|
5813
|
+
"BORSH_DESERIALIZE_FAILED" /* BORSH_DESERIALIZE_FAILED */,
|
|
5814
|
+
`Borsh deserialization failed: ${cause.message}`,
|
|
5815
|
+
cause
|
|
5816
|
+
);
|
|
5817
|
+
}
|
|
5818
|
+
/**
|
|
5819
|
+
* Create an error for invalid RexValue variant.
|
|
5820
|
+
*
|
|
5821
|
+
* @param variant - The invalid variant byte
|
|
5822
|
+
*/
|
|
5823
|
+
static invalidRexValue(variant) {
|
|
5824
|
+
return new _HpkeError(
|
|
5825
|
+
"INVALID_REX_VALUE" /* INVALID_REX_VALUE */,
|
|
5826
|
+
`Invalid RexValue variant: ${variant}`
|
|
5827
|
+
);
|
|
5828
|
+
}
|
|
5829
|
+
};
|
|
5830
|
+
|
|
5831
|
+
// src/rex/constants.ts
|
|
5832
|
+
var USER_SECRET_AAD = new TextEncoder().encode("rex-secret-v1");
|
|
5833
|
+
var SECRET_SHARING_HPKE_INFO = new TextEncoder().encode(
|
|
5834
|
+
"rialo/tee/secret-sharing-hpke/v1"
|
|
5835
|
+
);
|
|
5836
|
+
var X25519_PUBLIC_KEY_LENGTH = 32;
|
|
5837
|
+
var ED25519_PUBLIC_KEY_LENGTH = 32;
|
|
5838
|
+
var HPKE_ENC_LENGTH = 32;
|
|
5839
|
+
var CHACHA20_POLY1305_TAG_LENGTH = 16;
|
|
5840
|
+
var HPKE_OVERHEAD_LENGTH = HPKE_ENC_LENGTH + CHACHA20_POLY1305_TAG_LENGTH;
|
|
5841
|
+
|
|
5842
|
+
// src/rex/rex-value.ts
|
|
5843
|
+
var RexValueVariant = /* @__PURE__ */ ((RexValueVariant2) => {
|
|
5844
|
+
RexValueVariant2[RexValueVariant2["Plain"] = 0] = "Plain";
|
|
5845
|
+
RexValueVariant2[RexValueVariant2["Encrypted"] = 1] = "Encrypted";
|
|
5846
|
+
return RexValueVariant2;
|
|
5847
|
+
})(RexValueVariant || {});
|
|
5848
|
+
var RexValue = class _RexValue {
|
|
5849
|
+
variant;
|
|
5850
|
+
data;
|
|
5851
|
+
constructor(variant, data) {
|
|
5852
|
+
this.variant = variant;
|
|
5853
|
+
this.data = data;
|
|
5854
|
+
}
|
|
5855
|
+
/**
|
|
5856
|
+
* Create a plain (unencrypted) RexValue from raw bytes.
|
|
5857
|
+
*
|
|
5858
|
+
* @param data - The raw byte data
|
|
5859
|
+
* @returns A new RexValue with Plain variant
|
|
5860
|
+
*/
|
|
5861
|
+
static plain(data) {
|
|
5862
|
+
return new _RexValue(0 /* Plain */, data);
|
|
5863
|
+
}
|
|
5864
|
+
/**
|
|
5865
|
+
* Create a plain (unencrypted) RexValue from a UTF-8 string.
|
|
5866
|
+
*
|
|
5867
|
+
* @param s - The string to encode
|
|
5868
|
+
* @returns A new RexValue with Plain variant
|
|
5869
|
+
*/
|
|
5870
|
+
static plainString(s) {
|
|
5871
|
+
return new _RexValue(
|
|
5872
|
+
0 /* Plain */,
|
|
5873
|
+
new TextEncoder().encode(s)
|
|
5874
|
+
);
|
|
5875
|
+
}
|
|
5876
|
+
/**
|
|
5877
|
+
* Create an encrypted RexValue from HPKE ciphertext.
|
|
5878
|
+
*
|
|
5879
|
+
* @param ciphertext - The HPKE-encrypted ciphertext (enc || ct || tag)
|
|
5880
|
+
* @returns A new RexValue with Encrypted variant
|
|
5881
|
+
*/
|
|
5882
|
+
static encrypted(ciphertext) {
|
|
5883
|
+
return new _RexValue(1 /* Encrypted */, ciphertext);
|
|
5884
|
+
}
|
|
5885
|
+
/**
|
|
5886
|
+
* Check if this is a plain (unencrypted) value.
|
|
5435
5887
|
*/
|
|
5436
|
-
|
|
5437
|
-
return
|
|
5438
|
-
"PASSWORD" /* PASSWORD */,
|
|
5439
|
-
`Password error: ${message}`
|
|
5440
|
-
);
|
|
5888
|
+
isPlain() {
|
|
5889
|
+
return this.variant === 0 /* Plain */;
|
|
5441
5890
|
}
|
|
5442
5891
|
/**
|
|
5443
|
-
*
|
|
5892
|
+
* Check if this is an encrypted value.
|
|
5444
5893
|
*/
|
|
5445
|
-
|
|
5446
|
-
return
|
|
5447
|
-
"ENCRYPTION" /* ENCRYPTION */,
|
|
5448
|
-
`Encryption error: ${message}`
|
|
5449
|
-
);
|
|
5894
|
+
isEncrypted() {
|
|
5895
|
+
return this.variant === 1 /* Encrypted */;
|
|
5450
5896
|
}
|
|
5451
5897
|
/**
|
|
5452
|
-
*
|
|
5898
|
+
* Get the variant type.
|
|
5453
5899
|
*/
|
|
5454
|
-
|
|
5455
|
-
return
|
|
5900
|
+
getVariant() {
|
|
5901
|
+
return this.variant;
|
|
5456
5902
|
}
|
|
5457
5903
|
/**
|
|
5458
|
-
*
|
|
5904
|
+
* Get the raw bytes (plaintext or ciphertext).
|
|
5905
|
+
*
|
|
5906
|
+
* For Plain values, returns the plaintext.
|
|
5907
|
+
* For Encrypted values, returns the ciphertext.
|
|
5459
5908
|
*/
|
|
5460
|
-
|
|
5461
|
-
return
|
|
5909
|
+
asBytes() {
|
|
5910
|
+
return this.data;
|
|
5462
5911
|
}
|
|
5463
5912
|
/**
|
|
5464
|
-
*
|
|
5913
|
+
* Try to decode the plain value as a UTF-8 string.
|
|
5914
|
+
*
|
|
5915
|
+
* @returns The decoded string, or null if encrypted or not valid UTF-8
|
|
5465
5916
|
*/
|
|
5466
|
-
|
|
5467
|
-
|
|
5468
|
-
|
|
5469
|
-
|
|
5470
|
-
|
|
5917
|
+
asString() {
|
|
5918
|
+
if (!this.isPlain()) {
|
|
5919
|
+
return null;
|
|
5920
|
+
}
|
|
5921
|
+
try {
|
|
5922
|
+
return new TextDecoder("utf-8", { fatal: true }).decode(this.data);
|
|
5923
|
+
} catch {
|
|
5924
|
+
return null;
|
|
5925
|
+
}
|
|
5471
5926
|
}
|
|
5472
5927
|
/**
|
|
5473
|
-
*
|
|
5928
|
+
* Serialize to Borsh format.
|
|
5929
|
+
*
|
|
5930
|
+
* Format: `[variant: u8] [length: u32 LE] [data bytes]`
|
|
5931
|
+
*
|
|
5932
|
+
* @returns The Borsh-serialized bytes
|
|
5474
5933
|
*/
|
|
5475
|
-
|
|
5476
|
-
|
|
5477
|
-
|
|
5478
|
-
|
|
5479
|
-
);
|
|
5934
|
+
toBorsh() {
|
|
5935
|
+
const result = new Uint8Array(1 + 4 + this.data.length);
|
|
5936
|
+
result[0] = this.variant;
|
|
5937
|
+
const dataView = new DataView(result.buffer);
|
|
5938
|
+
dataView.setUint32(1, this.data.length, true);
|
|
5939
|
+
result.set(this.data, 5);
|
|
5940
|
+
return result;
|
|
5941
|
+
}
|
|
5942
|
+
/**
|
|
5943
|
+
* Deserialize from Borsh format.
|
|
5944
|
+
*
|
|
5945
|
+
* @param data - The Borsh-serialized bytes
|
|
5946
|
+
* @returns A new RexValue
|
|
5947
|
+
* @throws {HpkeError} If deserialization fails
|
|
5948
|
+
*/
|
|
5949
|
+
static fromBorsh(data) {
|
|
5950
|
+
if (data.length < 5) {
|
|
5951
|
+
throw HpkeError.borshDeserializeFailed(
|
|
5952
|
+
new Error(`Buffer too short: expected at least 5 bytes, got ${data.length}`)
|
|
5953
|
+
);
|
|
5954
|
+
}
|
|
5955
|
+
const variant = data[0];
|
|
5956
|
+
if (variant !== 0 /* Plain */ && variant !== 1 /* Encrypted */) {
|
|
5957
|
+
throw HpkeError.invalidRexValue(variant);
|
|
5958
|
+
}
|
|
5959
|
+
const dataView = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
5960
|
+
const length = dataView.getUint32(1, true);
|
|
5961
|
+
if (data.length < 5 + length) {
|
|
5962
|
+
throw HpkeError.borshDeserializeFailed(
|
|
5963
|
+
new Error(`Buffer too short: expected ${5 + length} bytes, got ${data.length}`)
|
|
5964
|
+
);
|
|
5965
|
+
}
|
|
5966
|
+
const payload = data.slice(5, 5 + length);
|
|
5967
|
+
return new _RexValue(variant, payload);
|
|
5480
5968
|
}
|
|
5481
5969
|
};
|
|
5970
|
+
var hpkeSuite = new core.CipherSuite({
|
|
5971
|
+
kem: new core.DhkemX25519HkdfSha256(),
|
|
5972
|
+
kdf: new core.HkdfSha256(),
|
|
5973
|
+
aead: new chacha20poly1305.Chacha20Poly1305()
|
|
5974
|
+
});
|
|
5975
|
+
function buildAad(senderPubkey) {
|
|
5976
|
+
const aad = new Uint8Array(USER_SECRET_AAD.length + senderPubkey.length);
|
|
5977
|
+
aad.set(USER_SECRET_AAD, 0);
|
|
5978
|
+
aad.set(senderPubkey, USER_SECRET_AAD.length);
|
|
5979
|
+
return aad;
|
|
5980
|
+
}
|
|
5981
|
+
async function hpkeEncrypt(rexPubkey, data, senderPubkey) {
|
|
5982
|
+
if (rexPubkey.length !== X25519_PUBLIC_KEY_LENGTH) {
|
|
5983
|
+
throw HpkeError.invalidKeyLength(
|
|
5984
|
+
X25519_PUBLIC_KEY_LENGTH,
|
|
5985
|
+
rexPubkey.length,
|
|
5986
|
+
"REX public key"
|
|
5987
|
+
);
|
|
5988
|
+
}
|
|
5989
|
+
if (senderPubkey.length !== ED25519_PUBLIC_KEY_LENGTH) {
|
|
5990
|
+
throw HpkeError.invalidKeyLength(
|
|
5991
|
+
ED25519_PUBLIC_KEY_LENGTH,
|
|
5992
|
+
senderPubkey.length,
|
|
5993
|
+
"sender public key"
|
|
5994
|
+
);
|
|
5995
|
+
}
|
|
5996
|
+
try {
|
|
5997
|
+
const recipientKey = await hpkeSuite.kem.importKey(
|
|
5998
|
+
"raw",
|
|
5999
|
+
rexPubkey.buffer.slice(
|
|
6000
|
+
rexPubkey.byteOffset,
|
|
6001
|
+
rexPubkey.byteOffset + rexPubkey.byteLength
|
|
6002
|
+
)
|
|
6003
|
+
);
|
|
6004
|
+
const sender = await hpkeSuite.createSenderContext({
|
|
6005
|
+
recipientPublicKey: recipientKey,
|
|
6006
|
+
info: SECRET_SHARING_HPKE_INFO.buffer.slice(
|
|
6007
|
+
SECRET_SHARING_HPKE_INFO.byteOffset,
|
|
6008
|
+
SECRET_SHARING_HPKE_INFO.byteOffset + SECRET_SHARING_HPKE_INFO.byteLength
|
|
6009
|
+
)
|
|
6010
|
+
});
|
|
6011
|
+
const aad = buildAad(senderPubkey);
|
|
6012
|
+
const ciphertext = await sender.seal(
|
|
6013
|
+
data.buffer.slice(
|
|
6014
|
+
data.byteOffset,
|
|
6015
|
+
data.byteOffset + data.byteLength
|
|
6016
|
+
),
|
|
6017
|
+
aad.buffer.slice(
|
|
6018
|
+
aad.byteOffset,
|
|
6019
|
+
aad.byteOffset + aad.byteLength
|
|
6020
|
+
)
|
|
6021
|
+
);
|
|
6022
|
+
const enc = new Uint8Array(sender.enc);
|
|
6023
|
+
const result = new Uint8Array(enc.length + ciphertext.byteLength);
|
|
6024
|
+
result.set(enc, 0);
|
|
6025
|
+
result.set(new Uint8Array(ciphertext), enc.length);
|
|
6026
|
+
return result;
|
|
6027
|
+
} catch (error) {
|
|
6028
|
+
throw HpkeError.encryptionFailed(
|
|
6029
|
+
error instanceof Error ? error : new Error(String(error))
|
|
6030
|
+
);
|
|
6031
|
+
}
|
|
6032
|
+
}
|
|
6033
|
+
async function encryptForRex(rexPubkey, data, senderPubkey) {
|
|
6034
|
+
const ciphertext = await hpkeEncrypt(rexPubkey, data, senderPubkey);
|
|
6035
|
+
return RexValue.encrypted(ciphertext);
|
|
6036
|
+
}
|
|
6037
|
+
function getCiphertextLength(plaintextLength) {
|
|
6038
|
+
return HPKE_OVERHEAD_LENGTH + plaintextLength;
|
|
6039
|
+
}
|
|
6040
|
+
function isValidCiphertextLength(ciphertext) {
|
|
6041
|
+
return ciphertext.length >= HPKE_OVERHEAD_LENGTH;
|
|
6042
|
+
}
|
|
5482
6043
|
|
|
5483
6044
|
// src/rpc/errors.ts
|
|
5484
6045
|
var RpcErrorCode = /* @__PURE__ */ ((RpcErrorCode2) => {
|
|
@@ -5645,60 +6206,28 @@ var BaseRpcClient = class {
|
|
|
5645
6206
|
getUrl() {
|
|
5646
6207
|
return this.transport.getUrl();
|
|
5647
6208
|
}
|
|
6209
|
+
/**
|
|
6210
|
+
* Call an arbitrary RPC method with a JSON string body.
|
|
6211
|
+
*
|
|
6212
|
+
* Escape hatch for methods not yet in the typed interface.
|
|
6213
|
+
*
|
|
6214
|
+
* @param method - The RPC method name
|
|
6215
|
+
* @param params - JSON string of parameters
|
|
6216
|
+
* @returns JSON string of the result
|
|
6217
|
+
*/
|
|
6218
|
+
async callWithJson(method, params) {
|
|
6219
|
+
const parsedParams = JSON.parse(params);
|
|
6220
|
+
const result = await this.call(method, parsedParams);
|
|
6221
|
+
return JSON.stringify(result);
|
|
6222
|
+
}
|
|
5648
6223
|
};
|
|
5649
6224
|
|
|
5650
|
-
// src/
|
|
5651
|
-
|
|
5652
|
-
|
|
5653
|
-
const chunkSize = 8192;
|
|
5654
|
-
let result = "";
|
|
5655
|
-
for (let i = 0; i < bytes.length; i += chunkSize) {
|
|
5656
|
-
const chunk = bytes.slice(i, i + chunkSize);
|
|
5657
|
-
result += String.fromCharCode(...chunk);
|
|
5658
|
-
}
|
|
5659
|
-
return btoa(result);
|
|
5660
|
-
}
|
|
5661
|
-
if (typeof Buffer !== "undefined") {
|
|
5662
|
-
return Buffer.from(bytes).toString("base64");
|
|
5663
|
-
}
|
|
5664
|
-
throw new Error("No base64 encoding available in this environment");
|
|
5665
|
-
}
|
|
5666
|
-
function fromBase64(base64) {
|
|
5667
|
-
if (typeof atob !== "undefined") {
|
|
5668
|
-
const binary = atob(base64);
|
|
5669
|
-
const bytes = new Uint8Array(binary.length);
|
|
5670
|
-
for (let i = 0; i < binary.length; i++) {
|
|
5671
|
-
bytes[i] = binary.charCodeAt(i);
|
|
5672
|
-
}
|
|
5673
|
-
return bytes;
|
|
5674
|
-
}
|
|
5675
|
-
if (typeof Buffer !== "undefined") {
|
|
5676
|
-
return new Uint8Array(Buffer.from(base64, "base64"));
|
|
5677
|
-
}
|
|
5678
|
-
throw new Error("No base64 decoding available in this environment");
|
|
5679
|
-
}
|
|
5680
|
-
function sleep(ms) {
|
|
5681
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
5682
|
-
}
|
|
5683
|
-
function calculateBackoff(attempt, baseMs = 1e3, maxMs = 3e4) {
|
|
5684
|
-
const exponentialDelay = baseMs * 2 ** attempt;
|
|
5685
|
-
const jitter = Math.random() * 0.3 * exponentialDelay;
|
|
5686
|
-
return Math.min(exponentialDelay + jitter, maxMs);
|
|
5687
|
-
}
|
|
5688
|
-
function getDevnetUrl() {
|
|
5689
|
-
return URL_DEVNET;
|
|
5690
|
-
}
|
|
5691
|
-
function getTestnetUrl() {
|
|
5692
|
-
return URL_TESTNET;
|
|
5693
|
-
}
|
|
5694
|
-
function getMainnetUrl() {
|
|
5695
|
-
return URL_MAINNET;
|
|
5696
|
-
}
|
|
5697
|
-
function getLocalnetUrl() {
|
|
5698
|
-
return URL_LOCALNET;
|
|
5699
|
-
}
|
|
6225
|
+
// src/generated/rpc-client.ts
|
|
6226
|
+
var RpcClient = class {
|
|
6227
|
+
};
|
|
5700
6228
|
|
|
5701
6229
|
// src/rpc/clients/query-client.ts
|
|
6230
|
+
init_base();
|
|
5702
6231
|
var QueryRpcClient = class extends BaseRpcClient {
|
|
5703
6232
|
/**
|
|
5704
6233
|
* Retrieve the balance of an account in kelvins (smallest unit).
|
|
@@ -5743,11 +6272,12 @@ var QueryRpcClient = class extends BaseRpcClient {
|
|
|
5743
6272
|
return null;
|
|
5744
6273
|
}
|
|
5745
6274
|
return {
|
|
5746
|
-
|
|
6275
|
+
kelvin: BigInt(result.value.kelvin),
|
|
5747
6276
|
owner: PublicKey.fromString(result.value.owner),
|
|
5748
|
-
data:
|
|
6277
|
+
data: result.value.data,
|
|
5749
6278
|
executable: result.value.executable,
|
|
5750
|
-
rentEpoch: BigInt(result.value.rentEpoch)
|
|
6279
|
+
rentEpoch: BigInt(result.value.rentEpoch),
|
|
6280
|
+
space: BigInt(result.value.space ?? 0)
|
|
5751
6281
|
};
|
|
5752
6282
|
}
|
|
5753
6283
|
/**
|
|
@@ -5798,37 +6328,6 @@ var QueryRpcClient = class extends BaseRpcClient {
|
|
|
5798
6328
|
err: signature.err
|
|
5799
6329
|
}));
|
|
5800
6330
|
}
|
|
5801
|
-
/**
|
|
5802
|
-
* Retrieve detailed information about a confirmed transaction.
|
|
5803
|
-
*
|
|
5804
|
-
* Returns transaction metadata including the block height it was
|
|
5805
|
-
* confirmed in and any execution errors.
|
|
5806
|
-
*
|
|
5807
|
-
* @param signature - The transaction signature to query
|
|
5808
|
-
* @returns Transaction information, or null if the transaction is not found
|
|
5809
|
-
*
|
|
5810
|
-
* @example
|
|
5811
|
-
* ```typescript
|
|
5812
|
-
* const tx = await client.getTransaction(signature);
|
|
5813
|
-
* if (tx) {
|
|
5814
|
-
* console.log(`Confirmed in block: ${tx.blockHeight}`);
|
|
5815
|
-
* if (tx.err) {
|
|
5816
|
-
* console.log(`Transaction failed: ${tx.err}`);
|
|
5817
|
-
* }
|
|
5818
|
-
* }
|
|
5819
|
-
* ```
|
|
5820
|
-
*/
|
|
5821
|
-
async getTransaction(signature) {
|
|
5822
|
-
const result = await this.call("getTransaction", [{ signature }]);
|
|
5823
|
-
if (!result) {
|
|
5824
|
-
return null;
|
|
5825
|
-
}
|
|
5826
|
-
return {
|
|
5827
|
-
signature,
|
|
5828
|
-
blockHeight: result.block_height ? BigInt(result.block_height) : void 0,
|
|
5829
|
-
err: result.err ?? result.meta?.err ?? void 0
|
|
5830
|
-
};
|
|
5831
|
-
}
|
|
5832
6331
|
/**
|
|
5833
6332
|
* Retrieve the total number of transactions processed since genesis.
|
|
5834
6333
|
*
|
|
@@ -5993,11 +6492,12 @@ var QueryRpcClient = class extends BaseRpcClient {
|
|
|
5993
6492
|
return null;
|
|
5994
6493
|
}
|
|
5995
6494
|
return {
|
|
5996
|
-
|
|
6495
|
+
kelvin: BigInt(account.kelvin),
|
|
5997
6496
|
owner: PublicKey.fromString(account.owner),
|
|
5998
|
-
data:
|
|
6497
|
+
data: account.data,
|
|
5999
6498
|
executable: account.executable,
|
|
6000
|
-
rentEpoch: BigInt(account.rentEpoch)
|
|
6499
|
+
rentEpoch: BigInt(account.rentEpoch),
|
|
6500
|
+
space: BigInt(account.space ?? 0)
|
|
6001
6501
|
};
|
|
6002
6502
|
});
|
|
6003
6503
|
}
|
|
@@ -6031,22 +6531,24 @@ var QueryRpcClient = class extends BaseRpcClient {
|
|
|
6031
6531
|
} : void 0
|
|
6032
6532
|
}
|
|
6033
6533
|
]);
|
|
6034
|
-
|
|
6035
|
-
|
|
6534
|
+
const accounts = result.value.map(
|
|
6535
|
+
({ pubkey, account }) => ({
|
|
6036
6536
|
pubkey: PublicKey.fromString(pubkey),
|
|
6037
6537
|
account: {
|
|
6038
|
-
|
|
6538
|
+
kelvin: BigInt(account.kelvin),
|
|
6039
6539
|
owner: PublicKey.fromString(account.owner),
|
|
6040
|
-
data:
|
|
6540
|
+
data: account.data,
|
|
6041
6541
|
executable: account.executable,
|
|
6042
|
-
rentEpoch: BigInt(account.rentEpoch)
|
|
6542
|
+
rentEpoch: BigInt(account.rentEpoch),
|
|
6543
|
+
space: BigInt(account.space ?? 0)
|
|
6043
6544
|
}
|
|
6044
|
-
})
|
|
6045
|
-
|
|
6046
|
-
|
|
6047
|
-
|
|
6048
|
-
|
|
6049
|
-
};
|
|
6545
|
+
})
|
|
6546
|
+
);
|
|
6547
|
+
const pagination = result.pagination ? {
|
|
6548
|
+
hasMore: result.pagination.has_more,
|
|
6549
|
+
nextCursor: result.pagination.next_cursor
|
|
6550
|
+
} : void 0;
|
|
6551
|
+
return [accounts, pagination];
|
|
6050
6552
|
}
|
|
6051
6553
|
/**
|
|
6052
6554
|
* Get workflow lineage information for tracking execution history.
|
|
@@ -6088,11 +6590,11 @@ var QueryRpcClient = class extends BaseRpcClient {
|
|
|
6088
6590
|
},
|
|
6089
6591
|
subscriptions: node.subscriptions,
|
|
6090
6592
|
triggeredBy: node.triggeredBy ? {
|
|
6091
|
-
event: node.triggeredBy.event,
|
|
6593
|
+
event: { topic: node.triggeredBy.event.topic },
|
|
6092
6594
|
subscriptionPubkey: node.triggeredBy.subscriptionPubkey,
|
|
6093
6595
|
timestampRange: node.triggeredBy.timestampRange ? {
|
|
6094
|
-
|
|
6095
|
-
|
|
6596
|
+
start: BigInt(node.triggeredBy.timestampRange.from),
|
|
6597
|
+
end: BigInt(node.triggeredBy.timestampRange.to)
|
|
6096
6598
|
} : void 0,
|
|
6097
6599
|
eventAccount: node.triggeredBy.eventAccount
|
|
6098
6600
|
} : void 0,
|
|
@@ -6107,68 +6609,494 @@ var QueryRpcClient = class extends BaseRpcClient {
|
|
|
6107
6609
|
};
|
|
6108
6610
|
}
|
|
6109
6611
|
/**
|
|
6110
|
-
* Get subscriptions for a given subscriber address.
|
|
6612
|
+
* Get subscriptions for a given subscriber address.
|
|
6613
|
+
*
|
|
6614
|
+
* Returns subscriptions that will trigger transactions when matching events occur.
|
|
6615
|
+
*
|
|
6616
|
+
* @param subscriber - The subscriber's public key
|
|
6617
|
+
* @param nonce - The nonce identifying the subscription
|
|
6618
|
+
* @returns The subscription for the subscriber and nonce
|
|
6619
|
+
*
|
|
6620
|
+
* @example
|
|
6621
|
+
* ```typescript
|
|
6622
|
+
* const subscription = await client.getSubscription(subscriberPubkey, "my-nonce");
|
|
6623
|
+
* console.log(`Topic: ${subscription.topic}, Kind: ${subscription.kind}`);
|
|
6624
|
+
* ```
|
|
6625
|
+
*/
|
|
6626
|
+
async getSubscription(subscriber, nonce) {
|
|
6627
|
+
const result = await this.call("getSubscription", [
|
|
6628
|
+
{
|
|
6629
|
+
subscriber: subscriber.toString(),
|
|
6630
|
+
nonce
|
|
6631
|
+
}
|
|
6632
|
+
]);
|
|
6633
|
+
const sub = result.subscription;
|
|
6634
|
+
return {
|
|
6635
|
+
kind: sub.kind,
|
|
6636
|
+
topic: sub.topic,
|
|
6637
|
+
instructions: sub.instructions,
|
|
6638
|
+
subscriber: sub.subscriber,
|
|
6639
|
+
eventAccount: sub.eventAccount,
|
|
6640
|
+
timestampRange: sub.timestampRange ? [BigInt(sub.timestampRange[0]), BigInt(sub.timestampRange[1])] : void 0
|
|
6641
|
+
};
|
|
6642
|
+
}
|
|
6643
|
+
/**
|
|
6644
|
+
* Get transactions triggered by a subscription account.
|
|
6645
|
+
*
|
|
6646
|
+
* Returns the history of transactions that were automatically executed
|
|
6647
|
+
* in response to subscription matches.
|
|
6648
|
+
*
|
|
6649
|
+
* @param subscriptionAccount - The subscription account public key
|
|
6650
|
+
* @param limit - Optional limit on transactions returned
|
|
6651
|
+
* @returns Triggered transactions for the subscription
|
|
6652
|
+
*
|
|
6653
|
+
* @example
|
|
6654
|
+
* ```typescript
|
|
6655
|
+
* const result = await client.getTriggeredTransactions(subscriptionPubkey, 10);
|
|
6656
|
+
* result.transactions.forEach(tx => {
|
|
6657
|
+
* console.log(`Signature: ${tx.signature}, Block: ${tx.blockNumber}`);
|
|
6658
|
+
* });
|
|
6659
|
+
* ```
|
|
6660
|
+
*/
|
|
6661
|
+
async getTriggeredTransactions(subscriptionAccount, limit) {
|
|
6662
|
+
const params = [subscriptionAccount.toString()];
|
|
6663
|
+
if (limit !== void 0) {
|
|
6664
|
+
params.push(limit.toString());
|
|
6665
|
+
}
|
|
6666
|
+
const result = await this.call("getTriggeredTransactions", params);
|
|
6667
|
+
return result.transactions.map((tx) => ({
|
|
6668
|
+
signature: tx.signature,
|
|
6669
|
+
blockNumber: BigInt(tx.block_number)
|
|
6670
|
+
}));
|
|
6671
|
+
}
|
|
6672
|
+
/**
|
|
6673
|
+
* Retrieve the REX X25519 public key for secret sharing encryption.
|
|
6674
|
+
*
|
|
6675
|
+
* This key is used for HPKE encryption when sending encrypted data
|
|
6676
|
+
* that should only be decryptable within the REX execution environment.
|
|
6677
|
+
*
|
|
6678
|
+
* @returns The REX X25519 public key as a 32-byte Uint8Array
|
|
6679
|
+
*
|
|
6680
|
+
* @example
|
|
6681
|
+
* ```typescript
|
|
6682
|
+
* import { encryptForREX } from "@rialo/ts-cdk";
|
|
6683
|
+
*
|
|
6684
|
+
* // Get the REX public key
|
|
6685
|
+
* const rexPubkey = await client.getSecretSharingPubkey();
|
|
6686
|
+
*
|
|
6687
|
+
* // Use it for HPKE encryption
|
|
6688
|
+
* const encrypted = await encryptForRex(
|
|
6689
|
+
* rexPubkey,
|
|
6690
|
+
* new TextEncoder().encode("secret data"),
|
|
6691
|
+
* keypair.publicKey.toBytes()
|
|
6692
|
+
* );
|
|
6693
|
+
* ```
|
|
6694
|
+
*/
|
|
6695
|
+
async getSecretSharingPubkey() {
|
|
6696
|
+
const result = await this.call(
|
|
6697
|
+
"getSecretSharingPubkey",
|
|
6698
|
+
[]
|
|
6699
|
+
);
|
|
6700
|
+
const hexString = result.public_key;
|
|
6701
|
+
const bytes2 = new Uint8Array(hexString.length / 2);
|
|
6702
|
+
for (let i = 0; i < bytes2.length; i++) {
|
|
6703
|
+
bytes2[i] = Number.parseInt(hexString.slice(i * 2, i * 2 + 2), 16);
|
|
6704
|
+
}
|
|
6705
|
+
return bytes2;
|
|
6706
|
+
}
|
|
6707
|
+
/**
|
|
6708
|
+
* Get the config hash prefix for replay protection.
|
|
6709
|
+
*
|
|
6710
|
+
* Returns the first 64 bits of the config hash, which is used
|
|
6711
|
+
* for transaction replay protection across chains.
|
|
6712
|
+
*
|
|
6713
|
+
* @returns The config hash prefix as a bigint
|
|
6714
|
+
*
|
|
6715
|
+
* @example
|
|
6716
|
+
* ```typescript
|
|
6717
|
+
* const configHashPrefix = await client.getConfigHashPrefix();
|
|
6718
|
+
* const tx = TransactionBuilder.create()
|
|
6719
|
+
* .setPayer(payer)
|
|
6720
|
+
* .setValidFrom(validFrom)
|
|
6721
|
+
* .setConfigHashPrefix(configHashPrefix)
|
|
6722
|
+
* .addInstruction(instruction)
|
|
6723
|
+
* .build();
|
|
6724
|
+
* ```
|
|
6725
|
+
*/
|
|
6726
|
+
async getConfigHashPrefix() {
|
|
6727
|
+
const body = JSON.stringify({
|
|
6728
|
+
jsonrpc: "2.0",
|
|
6729
|
+
id: 1,
|
|
6730
|
+
method: "getRecentValidatorConfigHash",
|
|
6731
|
+
params: [{}]
|
|
6732
|
+
});
|
|
6733
|
+
const response = await fetch(this.transport.getUrl(), {
|
|
6734
|
+
method: "POST",
|
|
6735
|
+
headers: { "Content-Type": "application/json" },
|
|
6736
|
+
body
|
|
6737
|
+
});
|
|
6738
|
+
const text = await response.text();
|
|
6739
|
+
const match = text.match(/"configHashPrefix"\s*:\s*(\d+)/);
|
|
6740
|
+
if (!match) {
|
|
6741
|
+
throw new Error(
|
|
6742
|
+
`Failed to parse configHashPrefix from RPC response: ${text}`
|
|
6743
|
+
);
|
|
6744
|
+
}
|
|
6745
|
+
return BigInt(match[1]);
|
|
6746
|
+
}
|
|
6747
|
+
/**
|
|
6748
|
+
* Retrieve the current block height with an optional minimum context slot.
|
|
6749
|
+
*
|
|
6750
|
+
* When minContextSlot is provided, the RPC will only return a result
|
|
6751
|
+
* if the node has processed at least that slot.
|
|
6752
|
+
*
|
|
6753
|
+
* @param minContextSlot - Minimum slot the node must have processed
|
|
6754
|
+
* @returns The current block height
|
|
6755
|
+
*/
|
|
6756
|
+
async getBlockHeightWithConfig(minContextSlot) {
|
|
6757
|
+
if (minContextSlot !== void 0) {
|
|
6758
|
+
const result = await this.call("getBlockHeight", [
|
|
6759
|
+
{ min_context_slot: Number(minContextSlot) }
|
|
6760
|
+
]);
|
|
6761
|
+
return BigInt(result);
|
|
6762
|
+
}
|
|
6763
|
+
return await this.getBlockHeight();
|
|
6764
|
+
}
|
|
6765
|
+
/**
|
|
6766
|
+
* Retrieve full transaction details by signature.
|
|
6767
|
+
*
|
|
6768
|
+
* Returns the complete transaction including metadata (fee, errors, logs),
|
|
6769
|
+
* the transaction body (signatures, message, instructions), and block context.
|
|
6770
|
+
*
|
|
6771
|
+
* @param sig - Transaction signature (Uint8Array)
|
|
6772
|
+
* @returns Full transaction response with block height, metadata, and body
|
|
6773
|
+
*/
|
|
6774
|
+
async getTransactionDetails(sig) {
|
|
6775
|
+
const sigStr = base58.encode(sig);
|
|
6776
|
+
const result = await this.call("getTransaction", [{ signature: sigStr }]);
|
|
6777
|
+
return {
|
|
6778
|
+
blockHeight: BigInt(result.block_height ?? 0),
|
|
6779
|
+
blockTime: result.block_time != null ? BigInt(result.block_time) : void 0,
|
|
6780
|
+
meta: {
|
|
6781
|
+
fee: BigInt(result.meta.fee),
|
|
6782
|
+
err: result.meta.err ?? void 0,
|
|
6783
|
+
logMessages: result.meta.log_messages ?? void 0
|
|
6784
|
+
},
|
|
6785
|
+
transaction: {
|
|
6786
|
+
signatures: result.transaction.signatures.map(
|
|
6787
|
+
(s) => base58.decode(s)
|
|
6788
|
+
),
|
|
6789
|
+
message: {
|
|
6790
|
+
header: {
|
|
6791
|
+
numRequiredSignatures: result.transaction.message.header.num_required_signatures,
|
|
6792
|
+
numReadonlySignedAccounts: result.transaction.message.header.num_readonly_signed_accounts,
|
|
6793
|
+
numReadonlyUnsignedAccounts: result.transaction.message.header.num_readonly_unsigned_accounts
|
|
6794
|
+
},
|
|
6795
|
+
accountKeys: result.transaction.message.account_keys.map(
|
|
6796
|
+
(k) => PublicKey.fromString(k)
|
|
6797
|
+
),
|
|
6798
|
+
instructions: result.transaction.message.instructions.map((ix) => ({
|
|
6799
|
+
programIdIndex: ix.program_id_index,
|
|
6800
|
+
accounts: new Uint8Array(ix.accounts),
|
|
6801
|
+
data: ix.data
|
|
6802
|
+
}))
|
|
6803
|
+
},
|
|
6804
|
+
validFrom: BigInt(result.transaction.valid_from)
|
|
6805
|
+
}
|
|
6806
|
+
};
|
|
6807
|
+
}
|
|
6808
|
+
/**
|
|
6809
|
+
* Retrieve a paginated list of recent transactions.
|
|
6810
|
+
*
|
|
6811
|
+
* @param config - Optional pagination config (limit, before cursor)
|
|
6812
|
+
* @returns Array of transaction summaries with signature, slot, time, and error status
|
|
6813
|
+
*/
|
|
6814
|
+
async getTransactions(config) {
|
|
6815
|
+
const params = {};
|
|
6816
|
+
if (config) {
|
|
6817
|
+
if (config.limit !== void 0) params.limit = config.limit;
|
|
6818
|
+
if (config.before !== void 0) params.before = config.before;
|
|
6819
|
+
}
|
|
6820
|
+
const result = await this.call("getTransactions", [
|
|
6821
|
+
{ config: Object.keys(params).length > 0 ? params : void 0 }
|
|
6822
|
+
]);
|
|
6823
|
+
return result.value.map((t) => ({
|
|
6824
|
+
signature: t.signature,
|
|
6825
|
+
slot: BigInt(t.slot),
|
|
6826
|
+
blockTime: t.blockTime !== void 0 ? BigInt(t.blockTime) : void 0,
|
|
6827
|
+
err: t.err
|
|
6828
|
+
}));
|
|
6829
|
+
}
|
|
6830
|
+
/**
|
|
6831
|
+
* Check whether a blockhash is still valid for transaction submission.
|
|
6832
|
+
*
|
|
6833
|
+
* @param blockhash - The blockhash to check (Uint8Array)
|
|
6834
|
+
* @returns Slot context and validity boolean
|
|
6835
|
+
*/
|
|
6836
|
+
async isBlockhashValid(blockhash) {
|
|
6837
|
+
const { base58: base582 } = await Promise.resolve().then(() => (init_base(), base_exports));
|
|
6838
|
+
const hashStr = base582.encode(blockhash);
|
|
6839
|
+
const result = await this.call("isBlockhashValid", [{ blockhash: hashStr }]);
|
|
6840
|
+
return {
|
|
6841
|
+
slot: BigInt(result.context.slot),
|
|
6842
|
+
isValid: result.value
|
|
6843
|
+
};
|
|
6844
|
+
}
|
|
6845
|
+
/**
|
|
6846
|
+
* Get the health status of the validator node.
|
|
6111
6847
|
*
|
|
6112
|
-
*
|
|
6848
|
+
* @returns Validator health details
|
|
6849
|
+
*/
|
|
6850
|
+
async getValidatorHealth() {
|
|
6851
|
+
return await this.call("getValidatorHealth", [{}]);
|
|
6852
|
+
}
|
|
6853
|
+
/**
|
|
6854
|
+
* Get the list of full nodes connected to the validator or full node.
|
|
6113
6855
|
*
|
|
6114
|
-
* @
|
|
6115
|
-
|
|
6116
|
-
|
|
6856
|
+
* @returns Array of connected nodes with their public key and connection duration
|
|
6857
|
+
*/
|
|
6858
|
+
async getConnectedFullNodes() {
|
|
6859
|
+
const result = await this.call(
|
|
6860
|
+
"getConnectedFullNodes",
|
|
6861
|
+
[{}]
|
|
6862
|
+
);
|
|
6863
|
+
return result.map(([publicKey, connectedMs]) => ({
|
|
6864
|
+
publicKey,
|
|
6865
|
+
connectedMs: BigInt(connectedMs)
|
|
6866
|
+
}));
|
|
6867
|
+
}
|
|
6868
|
+
/**
|
|
6869
|
+
* Get all accounts in the system.
|
|
6117
6870
|
*
|
|
6118
|
-
* @
|
|
6119
|
-
*
|
|
6120
|
-
* const subscription = await client.getSubscription(subscriberPubkey, "my-nonce");
|
|
6121
|
-
* console.log(`Topic: ${subscription.topic}, Kind: ${subscription.kind}`);
|
|
6122
|
-
* ```
|
|
6871
|
+
* @param config - Optional filtering/pagination config
|
|
6872
|
+
* @returns Array of all account entries with pubkey and account data
|
|
6123
6873
|
*/
|
|
6124
|
-
async
|
|
6125
|
-
const result = await this.call("
|
|
6874
|
+
async getAllAccounts(config) {
|
|
6875
|
+
const result = await this.call("getAllAccounts", [{ config: config ?? void 0 }]);
|
|
6876
|
+
return result.value.map((entry) => ({
|
|
6877
|
+
pubkey: entry.pubkey,
|
|
6878
|
+
account: {
|
|
6879
|
+
kelvin: BigInt(entry.account.kelvin),
|
|
6880
|
+
owner: PublicKey.fromString(entry.account.owner),
|
|
6881
|
+
data: entry.account.data,
|
|
6882
|
+
executable: entry.account.executable,
|
|
6883
|
+
rentEpoch: BigInt(entry.account.rentEpoch),
|
|
6884
|
+
space: BigInt(entry.account.space ?? 0)
|
|
6885
|
+
}
|
|
6886
|
+
}));
|
|
6887
|
+
}
|
|
6888
|
+
/**
|
|
6889
|
+
* Get a block by its height.
|
|
6890
|
+
*
|
|
6891
|
+
* @param blockHeight - The height of the block to retrieve
|
|
6892
|
+
* @param config - Optional config to control transaction detail level
|
|
6893
|
+
* @returns Block info including hash, height, time, and optional signatures
|
|
6894
|
+
*/
|
|
6895
|
+
async getBlock(blockHeight, config) {
|
|
6896
|
+
const params = {
|
|
6897
|
+
block_height: Number(blockHeight)
|
|
6898
|
+
};
|
|
6899
|
+
if (config?.transactionDetails) {
|
|
6900
|
+
params.config = { transaction_details: config.transactionDetails };
|
|
6901
|
+
}
|
|
6902
|
+
const result = await this.call("getBlock", [params]);
|
|
6903
|
+
const block = result.value ?? result;
|
|
6904
|
+
return {
|
|
6905
|
+
blockhash: block.blockhash ?? "",
|
|
6906
|
+
blockHeight: BigInt(block.blockHeight ?? 0),
|
|
6907
|
+
blockTime: BigInt(block.blockTime ?? 0),
|
|
6908
|
+
signatures: block.signatures
|
|
6909
|
+
};
|
|
6910
|
+
}
|
|
6911
|
+
/**
|
|
6912
|
+
* Get a list of confirmed block heights in a range.
|
|
6913
|
+
*
|
|
6914
|
+
* @param startHeight - Start of the range (inclusive)
|
|
6915
|
+
* @param endHeight - End of the range (inclusive), or undefined for open-ended
|
|
6916
|
+
* @returns Array of confirmed block heights
|
|
6917
|
+
*/
|
|
6918
|
+
async getBlocks(startHeight, endHeight) {
|
|
6919
|
+
const result = await this.call("getBlocks", [
|
|
6126
6920
|
{
|
|
6127
|
-
|
|
6128
|
-
|
|
6921
|
+
start_slot: Number(startHeight),
|
|
6922
|
+
end_slot: endHeight !== void 0 ? Number(endHeight) : void 0
|
|
6129
6923
|
}
|
|
6130
6924
|
]);
|
|
6131
|
-
|
|
6925
|
+
return result.map((n) => BigInt(n));
|
|
6926
|
+
}
|
|
6927
|
+
/**
|
|
6928
|
+
* Get detailed information about a stake account.
|
|
6929
|
+
*
|
|
6930
|
+
* @param pubkey - The public key of the stake account
|
|
6931
|
+
* @returns Stake account info, or undefined if the account doesn't exist
|
|
6932
|
+
*/
|
|
6933
|
+
async getStakeAccount(pubkey) {
|
|
6934
|
+
const result = await this.call("getStakeAccount", [{ pubkey: pubkey.toString() }]);
|
|
6935
|
+
if (!result.value) return void 0;
|
|
6936
|
+
const s = result.value;
|
|
6132
6937
|
return {
|
|
6133
|
-
|
|
6134
|
-
|
|
6135
|
-
|
|
6136
|
-
|
|
6137
|
-
|
|
6138
|
-
|
|
6938
|
+
state: s.state,
|
|
6939
|
+
kelvins: BigInt(s.kelvins),
|
|
6940
|
+
delegatedBalance: BigInt(s.delegated_balance),
|
|
6941
|
+
undelegatedBalance: BigInt(s.undelegated_balance),
|
|
6942
|
+
activationRequested: s.activation_requested !== void 0 ? BigInt(s.activation_requested) : void 0,
|
|
6943
|
+
deactivationRequested: s.deactivation_requested !== void 0 ? BigInt(s.deactivation_requested) : void 0,
|
|
6944
|
+
validator: s.validator,
|
|
6945
|
+
adminAuthority: s.admin_authority,
|
|
6946
|
+
withdrawAuthority: s.withdraw_authority
|
|
6139
6947
|
};
|
|
6140
6948
|
}
|
|
6141
6949
|
/**
|
|
6142
|
-
* Get
|
|
6950
|
+
* Get all registered validator accounts.
|
|
6143
6951
|
*
|
|
6144
|
-
*
|
|
6145
|
-
*
|
|
6952
|
+
* @param request - Request config (e.g. whether to use frozen state)
|
|
6953
|
+
* @returns Array of validator account info
|
|
6954
|
+
*/
|
|
6955
|
+
async getValidatorAccounts(request) {
|
|
6956
|
+
const result = await this.call("getValidatorAccounts", [{ use_frozen: request.useFrozen }]);
|
|
6957
|
+
return result.value.map((v) => ({
|
|
6958
|
+
commission: BigInt(v.commission),
|
|
6959
|
+
pubkey: v.pubkey,
|
|
6960
|
+
nodeIdentity: v.node_identity,
|
|
6961
|
+
authorizedWithdrawer: v.authorized_withdrawer,
|
|
6962
|
+
stakeNext: BigInt(v.stake_next),
|
|
6963
|
+
stakeCurrent: v.stake_current !== void 0 ? BigInt(v.stake_current) : void 0,
|
|
6964
|
+
address: v.address
|
|
6965
|
+
}));
|
|
6966
|
+
}
|
|
6967
|
+
/**
|
|
6968
|
+
* Get the token balance of an SPL Token account.
|
|
6146
6969
|
*
|
|
6147
|
-
* @param
|
|
6148
|
-
* @
|
|
6149
|
-
|
|
6970
|
+
* @param pubkey - The public key of the token account
|
|
6971
|
+
* @returns Token balance with amount, decimals, and UI-formatted string
|
|
6972
|
+
*/
|
|
6973
|
+
async getTokenAccountBalance(pubkey) {
|
|
6974
|
+
const result = await this.call("getTokenAccountBalance", [{ address: pubkey.toString() }]);
|
|
6975
|
+
return {
|
|
6976
|
+
amount: result.value.amount,
|
|
6977
|
+
decimals: result.value.decimals,
|
|
6978
|
+
uiAmountString: result.value.uiAmountString
|
|
6979
|
+
};
|
|
6980
|
+
}
|
|
6981
|
+
/**
|
|
6982
|
+
* Get registered REX requests for a creator.
|
|
6983
|
+
*
|
|
6984
|
+
* REX (Remote EXecution) requests are scheduled jobs that validators
|
|
6985
|
+
* execute on behalf of a creator.
|
|
6986
|
+
*
|
|
6987
|
+
* @param creator - The creator's public key
|
|
6988
|
+
* @param nonce - Optional nonce to filter a specific request
|
|
6989
|
+
* @returns Array of REX request info with their assigned duties
|
|
6990
|
+
*/
|
|
6991
|
+
async getRexRequests(creator, nonce) {
|
|
6992
|
+
const result = await this.call("getRexRequests", [{ creator: creator.toString(), nonce }]);
|
|
6993
|
+
return result.rex_requests.map((r) => ({
|
|
6994
|
+
creator: r.creator,
|
|
6995
|
+
nonce: r.nonce,
|
|
6996
|
+
isActive: r.is_active,
|
|
6997
|
+
description: r.description,
|
|
6998
|
+
updateFrequency: r.update_frequency,
|
|
6999
|
+
startingTimestamp: r.starting_timestamp,
|
|
7000
|
+
createdAt: r.created_at,
|
|
7001
|
+
validatorsPerDuty: r.validators_per_duty,
|
|
7002
|
+
rexRequestDelayMs: BigInt(r.rex_request_delay_ms),
|
|
7003
|
+
computeUnitsLimit: r.compute_units_limit,
|
|
7004
|
+
heapSizeLimit: r.heap_size_limit,
|
|
7005
|
+
duties: r.duties.map((d) => ({
|
|
7006
|
+
targetTimestamp: d.target_timestamp,
|
|
7007
|
+
assignedValidators: d.assigned_validators
|
|
7008
|
+
}))
|
|
7009
|
+
}));
|
|
7010
|
+
}
|
|
7011
|
+
/**
|
|
7012
|
+
* Get missed REX duty proposal rounds for a specific REX request.
|
|
6150
7013
|
*
|
|
6151
|
-
* @
|
|
6152
|
-
*
|
|
6153
|
-
*
|
|
6154
|
-
* result.transactions.forEach(tx => {
|
|
6155
|
-
* console.log(`Signature: ${tx.signature}, Block: ${tx.blockNumber}`);
|
|
6156
|
-
* });
|
|
6157
|
-
* ```
|
|
7014
|
+
* @param creator - The creator's public key
|
|
7015
|
+
* @param nonce - The nonce identifying the REX request
|
|
7016
|
+
* @returns Array of proposal round numbers where duties were missed
|
|
6158
7017
|
*/
|
|
6159
|
-
async
|
|
6160
|
-
const
|
|
6161
|
-
|
|
6162
|
-
|
|
6163
|
-
|
|
6164
|
-
|
|
6165
|
-
|
|
6166
|
-
|
|
6167
|
-
|
|
7018
|
+
async getRexMissedDuties(creator, nonce) {
|
|
7019
|
+
const result = await this.call("getRexMissedDuties", [{ creator: creator.toString(), nonce }]);
|
|
7020
|
+
return result.missed_duties_at_proposal_rounds.map((n) => BigInt(n));
|
|
7021
|
+
}
|
|
7022
|
+
/**
|
|
7023
|
+
* Get information about all known cluster nodes.
|
|
7024
|
+
*
|
|
7025
|
+
* @returns Array of cluster node info with stake, addresses, and keys
|
|
7026
|
+
*/
|
|
7027
|
+
async getClusterNodes() {
|
|
7028
|
+
const result = await this.call("getClusterNodes", [null]);
|
|
7029
|
+
return result.nodes.map((n) => ({
|
|
7030
|
+
stake: BigInt(n.stake),
|
|
7031
|
+
address: n.address,
|
|
7032
|
+
hostname: n.hostname,
|
|
7033
|
+
authorityPubkey: n.authority_pubkey,
|
|
7034
|
+
protocolPubkey: n.protocol_pubkey,
|
|
7035
|
+
networkPubkey: n.network_pubkey,
|
|
7036
|
+
lastCommittedRound: n.last_committed_round
|
|
6168
7037
|
}));
|
|
6169
7038
|
}
|
|
7039
|
+
/**
|
|
7040
|
+
* Get the list of validator indices this node is connected to.
|
|
7041
|
+
*
|
|
7042
|
+
* @returns Array of validator indices
|
|
7043
|
+
*/
|
|
7044
|
+
async getConnectedValidators() {
|
|
7045
|
+
return await this.call("getConnectedValidators", [{}]);
|
|
7046
|
+
}
|
|
6170
7047
|
};
|
|
6171
7048
|
|
|
7049
|
+
// src/utils.ts
|
|
7050
|
+
function toBase64(bytes2) {
|
|
7051
|
+
if (typeof btoa !== "undefined") {
|
|
7052
|
+
const chunkSize = 8192;
|
|
7053
|
+
let result = "";
|
|
7054
|
+
for (let i = 0; i < bytes2.length; i += chunkSize) {
|
|
7055
|
+
const chunk = bytes2.slice(i, i + chunkSize);
|
|
7056
|
+
result += String.fromCharCode(...chunk);
|
|
7057
|
+
}
|
|
7058
|
+
return btoa(result);
|
|
7059
|
+
}
|
|
7060
|
+
if (typeof Buffer !== "undefined") {
|
|
7061
|
+
return Buffer.from(bytes2).toString("base64");
|
|
7062
|
+
}
|
|
7063
|
+
throw new Error("No base64 encoding available in this environment");
|
|
7064
|
+
}
|
|
7065
|
+
function fromBase64(base642) {
|
|
7066
|
+
if (typeof atob !== "undefined") {
|
|
7067
|
+
const binary = atob(base642);
|
|
7068
|
+
const bytes2 = new Uint8Array(binary.length);
|
|
7069
|
+
for (let i = 0; i < binary.length; i++) {
|
|
7070
|
+
bytes2[i] = binary.charCodeAt(i);
|
|
7071
|
+
}
|
|
7072
|
+
return bytes2;
|
|
7073
|
+
}
|
|
7074
|
+
if (typeof Buffer !== "undefined") {
|
|
7075
|
+
return new Uint8Array(Buffer.from(base642, "base64"));
|
|
7076
|
+
}
|
|
7077
|
+
throw new Error("No base64 decoding available in this environment");
|
|
7078
|
+
}
|
|
7079
|
+
function sleep(ms) {
|
|
7080
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
7081
|
+
}
|
|
7082
|
+
function calculateBackoff(attempt, baseMs = 1e3, maxMs = 3e4) {
|
|
7083
|
+
const exponentialDelay = baseMs * 2 ** attempt;
|
|
7084
|
+
const jitter = Math.random() * 0.3 * exponentialDelay;
|
|
7085
|
+
return Math.min(exponentialDelay + jitter, maxMs);
|
|
7086
|
+
}
|
|
7087
|
+
function getDevnetUrl() {
|
|
7088
|
+
return URL_DEVNET;
|
|
7089
|
+
}
|
|
7090
|
+
function getTestnetUrl() {
|
|
7091
|
+
return URL_TESTNET;
|
|
7092
|
+
}
|
|
7093
|
+
function getMainnetUrl() {
|
|
7094
|
+
return URL_MAINNET;
|
|
7095
|
+
}
|
|
7096
|
+
function getLocalnetUrl() {
|
|
7097
|
+
return URL_LOCALNET;
|
|
7098
|
+
}
|
|
7099
|
+
|
|
6172
7100
|
// src/rpc/clients/transaction-client.ts
|
|
6173
7101
|
var DEFAULT_MAX_RETRIES = 10;
|
|
6174
7102
|
var DEFAULT_RETRY_DELAY_MS = 200;
|
|
@@ -6224,10 +7152,10 @@ var TransactionRpcClient = class extends BaseRpcClient {
|
|
|
6224
7152
|
*/
|
|
6225
7153
|
async confirmTransaction(signature, options) {
|
|
6226
7154
|
const maxRetries = options?.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
6227
|
-
const
|
|
7155
|
+
const retryDelayMs = options?.retryDelayMs ?? DEFAULT_RETRY_DELAY_MS;
|
|
6228
7156
|
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
|
6229
7157
|
if (attempt > 0) {
|
|
6230
|
-
await this.sleep(
|
|
7158
|
+
await this.sleep(retryDelayMs);
|
|
6231
7159
|
}
|
|
6232
7160
|
try {
|
|
6233
7161
|
const txInfo = await this.getTransaction(signature);
|
|
@@ -6283,13 +7211,20 @@ var TransactionRpcClient = class extends BaseRpcClient {
|
|
|
6283
7211
|
* // With custom retry settings
|
|
6284
7212
|
* const result = await client.sendAndConfirmTransaction(signedTx, {
|
|
6285
7213
|
* maxRetries: 3,
|
|
6286
|
-
*
|
|
7214
|
+
* confirmMaxRetries: 10,
|
|
7215
|
+
* confirmRetryDelayMs: 500,
|
|
6287
7216
|
* });
|
|
6288
7217
|
* ```
|
|
6289
7218
|
*/
|
|
6290
7219
|
async sendAndConfirmTransaction(transaction, options) {
|
|
6291
|
-
const signature = await this.sendTransaction(transaction,
|
|
6292
|
-
|
|
7220
|
+
const signature = await this.sendTransaction(transaction, {
|
|
7221
|
+
skipPreflight: options?.skipPreflight,
|
|
7222
|
+
maxRetries: options?.maxRetries
|
|
7223
|
+
});
|
|
7224
|
+
return await this.confirmTransaction(signature, {
|
|
7225
|
+
maxRetries: options?.confirmMaxRetries,
|
|
7226
|
+
retryDelayMs: options?.confirmRetryDelayMs
|
|
7227
|
+
});
|
|
6293
7228
|
}
|
|
6294
7229
|
/**
|
|
6295
7230
|
* Request an airdrop of tokens to an account.
|
|
@@ -6316,10 +7251,12 @@ var TransactionRpcClient = class extends BaseRpcClient {
|
|
|
6316
7251
|
`Airdrop amount ${amount} exceeds maximum safe value`
|
|
6317
7252
|
);
|
|
6318
7253
|
}
|
|
6319
|
-
const signature = await this.call("requestAirdrop", [
|
|
6320
|
-
|
|
6321
|
-
|
|
6322
|
-
|
|
7254
|
+
const signature = await this.call("requestAirdrop", [
|
|
7255
|
+
{
|
|
7256
|
+
pubkey: pubkey.toString(),
|
|
7257
|
+
kelvins: Number(amount)
|
|
7258
|
+
}
|
|
7259
|
+
]);
|
|
6323
7260
|
return signature;
|
|
6324
7261
|
}
|
|
6325
7262
|
/**
|
|
@@ -6348,13 +7285,23 @@ var TransactionRpcClient = class extends BaseRpcClient {
|
|
|
6348
7285
|
const signature = await this.requestAirdrop(pubkey, amount);
|
|
6349
7286
|
return await this.confirmTransaction(signature, options);
|
|
6350
7287
|
}
|
|
7288
|
+
/**
|
|
7289
|
+
* Submit an epoch change transaction (admin-only).
|
|
7290
|
+
*
|
|
7291
|
+
* @param request - The epoch change request payload
|
|
7292
|
+
* @returns Response from the epoch change submission
|
|
7293
|
+
*/
|
|
7294
|
+
async sendAdminTransaction(request) {
|
|
7295
|
+
return await this.call("submitEpochChange", [
|
|
7296
|
+
request
|
|
7297
|
+
]);
|
|
7298
|
+
}
|
|
6351
7299
|
async getTransaction(signature) {
|
|
6352
7300
|
const result = await this.call("getTransaction", [{ signature }]);
|
|
6353
7301
|
if (!result) {
|
|
6354
7302
|
return null;
|
|
6355
7303
|
}
|
|
6356
7304
|
return {
|
|
6357
|
-
signature,
|
|
6358
7305
|
blockHeight: BigInt(result.block_height ?? 0),
|
|
6359
7306
|
err: result.err ?? result.meta?.err ?? void 0
|
|
6360
7307
|
};
|
|
@@ -6370,12 +7317,13 @@ var TransactionRpcClient = class extends BaseRpcClient {
|
|
|
6370
7317
|
};
|
|
6371
7318
|
|
|
6372
7319
|
// src/rpc/clients/client.ts
|
|
6373
|
-
var RialoClient = class {
|
|
7320
|
+
var RialoClient = class extends RpcClient {
|
|
6374
7321
|
queryClient;
|
|
6375
7322
|
transactionClient;
|
|
6376
7323
|
transport;
|
|
6377
7324
|
chain;
|
|
6378
7325
|
constructor(transport, chain2) {
|
|
7326
|
+
super();
|
|
6379
7327
|
this.chain = chain2;
|
|
6380
7328
|
this.transport = transport;
|
|
6381
7329
|
this.queryClient = new QueryRpcClient(transport);
|
|
@@ -6411,7 +7359,11 @@ var RialoClient = class {
|
|
|
6411
7359
|
* @returns Account info or null if account doesn't exist
|
|
6412
7360
|
*/
|
|
6413
7361
|
async getAccountInfo(pubkey) {
|
|
6414
|
-
|
|
7362
|
+
const result = await this.queryClient.getAccountInfo(pubkey);
|
|
7363
|
+
if (!result) {
|
|
7364
|
+
throw new Error(`Account does not exist: ${pubkey}`);
|
|
7365
|
+
}
|
|
7366
|
+
return result;
|
|
6415
7367
|
}
|
|
6416
7368
|
/**
|
|
6417
7369
|
* Retrieves the current block height.
|
|
@@ -6419,6 +7371,12 @@ var RialoClient = class {
|
|
|
6419
7371
|
async getBlockHeight() {
|
|
6420
7372
|
return await this.queryClient.getBlockHeight();
|
|
6421
7373
|
}
|
|
7374
|
+
/**
|
|
7375
|
+
* Retrieves the current block height with advanced configuration.
|
|
7376
|
+
*/
|
|
7377
|
+
async getBlockHeightWithConfig(minContextSlot) {
|
|
7378
|
+
return await this.queryClient.getBlockHeightWithConfig(minContextSlot);
|
|
7379
|
+
}
|
|
6422
7380
|
/**
|
|
6423
7381
|
* Retrieves the signatures for an address.
|
|
6424
7382
|
*/
|
|
@@ -6428,10 +7386,10 @@ var RialoClient = class {
|
|
|
6428
7386
|
/**
|
|
6429
7387
|
* Retrieves detailed information about a transaction.
|
|
6430
7388
|
*
|
|
6431
|
-
* @returns
|
|
7389
|
+
* @returns Full transaction response
|
|
6432
7390
|
*/
|
|
6433
|
-
async getTransaction(
|
|
6434
|
-
return await this.queryClient.
|
|
7391
|
+
async getTransaction(sig) {
|
|
7392
|
+
return await this.queryClient.getTransactionDetails(sig);
|
|
6435
7393
|
}
|
|
6436
7394
|
/**
|
|
6437
7395
|
* Retrieves the total number of transactions processed since genesis.
|
|
@@ -6443,7 +7401,10 @@ var RialoClient = class {
|
|
|
6443
7401
|
* Retrieves the status of multiple transaction signatures.
|
|
6444
7402
|
*/
|
|
6445
7403
|
async getSignatureStatuses(signatures) {
|
|
6446
|
-
|
|
7404
|
+
const { base58: base582 } = await Promise.resolve().then(() => (init_base(), base_exports));
|
|
7405
|
+
const sigStrings = signatures.map((s) => base582.encode(s));
|
|
7406
|
+
const results = await this.queryClient.getSignatureStatuses(sigStrings);
|
|
7407
|
+
return results.filter((s) => s !== null);
|
|
6447
7408
|
}
|
|
6448
7409
|
/**
|
|
6449
7410
|
* Retrieves current epoch information.
|
|
@@ -6467,7 +7428,12 @@ var RialoClient = class {
|
|
|
6467
7428
|
* @returns Transaction signature
|
|
6468
7429
|
*/
|
|
6469
7430
|
async sendTransaction(transaction, options) {
|
|
6470
|
-
|
|
7431
|
+
const sigStr = await this.transactionClient.sendTransaction(
|
|
7432
|
+
transaction,
|
|
7433
|
+
options
|
|
7434
|
+
);
|
|
7435
|
+
const { base58: base582 } = await Promise.resolve().then(() => (init_base(), base_exports));
|
|
7436
|
+
return base582.decode(sigStr);
|
|
6471
7437
|
}
|
|
6472
7438
|
/**
|
|
6473
7439
|
* Requests an airdrop of tokens to an account.
|
|
@@ -6479,7 +7445,9 @@ var RialoClient = class {
|
|
|
6479
7445
|
* @returns Transaction signature
|
|
6480
7446
|
*/
|
|
6481
7447
|
async requestAirdrop(pubkey, amount) {
|
|
6482
|
-
|
|
7448
|
+
const sigStr = await this.transactionClient.requestAirdrop(pubkey, amount);
|
|
7449
|
+
const { base58: base582 } = await Promise.resolve().then(() => (init_base(), base_exports));
|
|
7450
|
+
return base582.decode(sigStr);
|
|
6483
7451
|
}
|
|
6484
7452
|
/**
|
|
6485
7453
|
* Submits a signed transaction and waits for confirmation.
|
|
@@ -6509,19 +7477,18 @@ var RialoClient = class {
|
|
|
6509
7477
|
* @param options - Confirmation options
|
|
6510
7478
|
* @returns Confirmed transaction details
|
|
6511
7479
|
*/
|
|
6512
|
-
async confirmTransaction(
|
|
6513
|
-
return await this.transactionClient.confirmTransaction(
|
|
7480
|
+
async confirmTransaction(sig, options) {
|
|
7481
|
+
return await this.transactionClient.confirmTransaction(sig, options);
|
|
6514
7482
|
}
|
|
6515
7483
|
/**
|
|
6516
7484
|
* Requests an airdrop and waits for confirmation.
|
|
6517
7485
|
*
|
|
6518
7486
|
* **Note**: Only available on devnet and testnet.
|
|
6519
7487
|
*/
|
|
6520
|
-
async requestAirdropAndConfirm(pubkey, amount
|
|
7488
|
+
async requestAirdropAndConfirm(pubkey, amount) {
|
|
6521
7489
|
return await this.transactionClient.requestAirdropAndConfirm(
|
|
6522
7490
|
pubkey,
|
|
6523
|
-
amount
|
|
6524
|
-
options
|
|
7491
|
+
amount
|
|
6525
7492
|
);
|
|
6526
7493
|
}
|
|
6527
7494
|
/**
|
|
@@ -6530,19 +7497,20 @@ var RialoClient = class {
|
|
|
6530
7497
|
* @param accountDataSize - The size of the account data in bytes
|
|
6531
7498
|
* @returns The minimum balance in kelvins required for rent exemption
|
|
6532
7499
|
*/
|
|
6533
|
-
async getMinimumBalanceForRentExemption(
|
|
7500
|
+
async getMinimumBalanceForRentExemption(dataSize) {
|
|
6534
7501
|
return await this.queryClient.getMinimumBalanceForRentExemption(
|
|
6535
|
-
|
|
7502
|
+
Number(dataSize)
|
|
6536
7503
|
);
|
|
6537
7504
|
}
|
|
6538
7505
|
/**
|
|
6539
7506
|
* Get the fee required to process a specific message.
|
|
6540
7507
|
*
|
|
6541
7508
|
* @param message - Base64-encoded serialized versioned message
|
|
6542
|
-
* @returns Fee
|
|
7509
|
+
* @returns Fee response with value in kelvins
|
|
6543
7510
|
*/
|
|
6544
7511
|
async getFeeForMessage(message) {
|
|
6545
|
-
|
|
7512
|
+
const value = await this.queryClient.getFeeForMessage(message);
|
|
7513
|
+
return { value: value ?? void 0 };
|
|
6546
7514
|
}
|
|
6547
7515
|
/**
|
|
6548
7516
|
* Get information for multiple accounts in a single request.
|
|
@@ -6551,18 +7519,26 @@ var RialoClient = class {
|
|
|
6551
7519
|
* @returns Account information for each address
|
|
6552
7520
|
*/
|
|
6553
7521
|
async getMultipleAccounts(pubkeys) {
|
|
6554
|
-
|
|
7522
|
+
const results = await this.queryClient.getMultipleAccounts(pubkeys);
|
|
7523
|
+
return results.map(
|
|
7524
|
+
(r) => r === null ? void 0 : r
|
|
7525
|
+
);
|
|
6555
7526
|
}
|
|
6556
7527
|
/**
|
|
6557
7528
|
* Get all accounts owned by a specific program or address.
|
|
6558
7529
|
*
|
|
6559
7530
|
* @param owner - Program ID or owner public key
|
|
6560
|
-
* @param filter - Filter type (
|
|
7531
|
+
* @param filter - Filter type (programAccounts or tokenAccounts)
|
|
6561
7532
|
* @param config - Optional configuration for pagination and encoding
|
|
6562
|
-
* @returns
|
|
7533
|
+
* @returns Tuple of accounts and optional pagination info
|
|
6563
7534
|
*/
|
|
6564
7535
|
async getAccountsByOwner(owner, filter, config) {
|
|
6565
|
-
|
|
7536
|
+
const filterParam = filter === "tokenAccounts" ? { type: "tokenAccounts" } : { type: "programAccounts" };
|
|
7537
|
+
return await this.queryClient.getAccountsByOwner(
|
|
7538
|
+
owner,
|
|
7539
|
+
filterParam,
|
|
7540
|
+
config
|
|
7541
|
+
);
|
|
6566
7542
|
}
|
|
6567
7543
|
/**
|
|
6568
7544
|
* Get workflow lineage information for tracking execution history.
|
|
@@ -6596,6 +7572,117 @@ var RialoClient = class {
|
|
|
6596
7572
|
limit
|
|
6597
7573
|
);
|
|
6598
7574
|
}
|
|
7575
|
+
/**
|
|
7576
|
+
* Gets paginated transactions from the blockchain.
|
|
7577
|
+
*/
|
|
7578
|
+
async getTransactions(config) {
|
|
7579
|
+
return await this.queryClient.getTransactions(config);
|
|
7580
|
+
}
|
|
7581
|
+
/**
|
|
7582
|
+
* Checks if a blockhash is still valid for transaction submission.
|
|
7583
|
+
*/
|
|
7584
|
+
async isBlockhashValid(blockhash) {
|
|
7585
|
+
return await this.queryClient.isBlockhashValid(blockhash);
|
|
7586
|
+
}
|
|
7587
|
+
/**
|
|
7588
|
+
* Gets the health status of the validator.
|
|
7589
|
+
*/
|
|
7590
|
+
async getValidatorHealth() {
|
|
7591
|
+
return await this.queryClient.getValidatorHealth();
|
|
7592
|
+
}
|
|
7593
|
+
/**
|
|
7594
|
+
* Gets the list of full nodes connected to the validator or full node.
|
|
7595
|
+
*/
|
|
7596
|
+
async getConnectedFullNodes() {
|
|
7597
|
+
return await this.queryClient.getConnectedFullNodes();
|
|
7598
|
+
}
|
|
7599
|
+
/**
|
|
7600
|
+
* Gets the TEE's secret sharing public key for HPKE encryption.
|
|
7601
|
+
*/
|
|
7602
|
+
async getSecretSharingPubkey() {
|
|
7603
|
+
const rawBytes = await this.queryClient.getSecretSharingPubkey();
|
|
7604
|
+
const hex2 = Array.from(rawBytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
7605
|
+
return { publicKey: hex2 };
|
|
7606
|
+
}
|
|
7607
|
+
/**
|
|
7608
|
+
* Gets the config hash prefix for protecting against replay attacks.
|
|
7609
|
+
*/
|
|
7610
|
+
async getConfigHashPrefix() {
|
|
7611
|
+
return await this.queryClient.getConfigHashPrefix();
|
|
7612
|
+
}
|
|
7613
|
+
/**
|
|
7614
|
+
* Submits an epoch change transaction (admin-only).
|
|
7615
|
+
*/
|
|
7616
|
+
async sendAdminTransaction(request) {
|
|
7617
|
+
return await this.transactionClient.sendAdminTransaction(request);
|
|
7618
|
+
}
|
|
7619
|
+
/**
|
|
7620
|
+
* Gets all accounts in the system.
|
|
7621
|
+
*/
|
|
7622
|
+
async getAllAccounts(config) {
|
|
7623
|
+
return await this.queryClient.getAllAccounts(config);
|
|
7624
|
+
}
|
|
7625
|
+
/**
|
|
7626
|
+
* Gets a block by its height.
|
|
7627
|
+
*/
|
|
7628
|
+
async getBlock(blockHeight, config) {
|
|
7629
|
+
return await this.queryClient.getBlock(blockHeight, config);
|
|
7630
|
+
}
|
|
7631
|
+
/**
|
|
7632
|
+
* Gets a list of confirmed block heights in a range.
|
|
7633
|
+
*/
|
|
7634
|
+
async getBlocks(startHeight, endHeight) {
|
|
7635
|
+
return await this.queryClient.getBlocks(startHeight, endHeight);
|
|
7636
|
+
}
|
|
7637
|
+
/**
|
|
7638
|
+
* Gets detailed information about a stake account.
|
|
7639
|
+
*/
|
|
7640
|
+
async getStakeAccount(pubkey) {
|
|
7641
|
+
return await this.queryClient.getStakeAccount(pubkey);
|
|
7642
|
+
}
|
|
7643
|
+
/**
|
|
7644
|
+
* Gets all registered validator accounts.
|
|
7645
|
+
*/
|
|
7646
|
+
async getValidatorAccounts(request) {
|
|
7647
|
+
return await this.queryClient.getValidatorAccounts(request);
|
|
7648
|
+
}
|
|
7649
|
+
/**
|
|
7650
|
+
* Gets the token balance of an SPL Token account.
|
|
7651
|
+
*/
|
|
7652
|
+
async getTokenAccountBalance(pubkey) {
|
|
7653
|
+
return await this.queryClient.getTokenAccountBalance(pubkey);
|
|
7654
|
+
}
|
|
7655
|
+
/**
|
|
7656
|
+
* Gets registered REX requests for a creator.
|
|
7657
|
+
*/
|
|
7658
|
+
async getRexRequests(creator, nonce) {
|
|
7659
|
+
return await this.queryClient.getRexRequests(creator, nonce);
|
|
7660
|
+
}
|
|
7661
|
+
/**
|
|
7662
|
+
* Gets missed REX duty proposal rounds for a specific REX request.
|
|
7663
|
+
*/
|
|
7664
|
+
async getRexMissedDuties(creator, nonce) {
|
|
7665
|
+
return await this.queryClient.getRexMissedDuties(creator, nonce);
|
|
7666
|
+
}
|
|
7667
|
+
/**
|
|
7668
|
+
* Gets information about all known cluster nodes.
|
|
7669
|
+
*/
|
|
7670
|
+
async getClusterNodes() {
|
|
7671
|
+
return await this.queryClient.getClusterNodes();
|
|
7672
|
+
}
|
|
7673
|
+
/**
|
|
7674
|
+
* Gets the list of validator indices this node is connected to.
|
|
7675
|
+
*/
|
|
7676
|
+
async getConnectedValidators() {
|
|
7677
|
+
return await this.queryClient.getConnectedValidators();
|
|
7678
|
+
}
|
|
7679
|
+
/**
|
|
7680
|
+
* Calls an arbitrary RPC method with a JSON string body.
|
|
7681
|
+
* Utility method for methods not yet in the generated interface.
|
|
7682
|
+
*/
|
|
7683
|
+
async callWithJson(method, params) {
|
|
7684
|
+
return await this.queryClient.callWithJson(method, params);
|
|
7685
|
+
}
|
|
6599
7686
|
};
|
|
6600
7687
|
|
|
6601
7688
|
// src/rpc/http-transport.ts
|
|
@@ -6815,9 +7902,9 @@ var BincodeReader = class {
|
|
|
6815
7902
|
isExhausted() {
|
|
6816
7903
|
return this.offset >= this.bytes.length;
|
|
6817
7904
|
}
|
|
6818
|
-
skip(
|
|
6819
|
-
this.ensureAvailable(
|
|
6820
|
-
this.offset +=
|
|
7905
|
+
skip(bytes2) {
|
|
7906
|
+
this.ensureAvailable(bytes2);
|
|
7907
|
+
this.offset += bytes2;
|
|
6821
7908
|
return this;
|
|
6822
7909
|
}
|
|
6823
7910
|
/**
|
|
@@ -6933,9 +8020,9 @@ var BincodeReader = class {
|
|
|
6933
8020
|
// ========== Compound Types ==========
|
|
6934
8021
|
readBytes(length) {
|
|
6935
8022
|
this.ensureAvailable(length);
|
|
6936
|
-
const
|
|
8023
|
+
const bytes2 = this.bytes.slice(this.offset, this.offset + length);
|
|
6937
8024
|
this.offset += length;
|
|
6938
|
-
return
|
|
8025
|
+
return bytes2;
|
|
6939
8026
|
}
|
|
6940
8027
|
readFixedArray(length) {
|
|
6941
8028
|
return this.readBytes(length);
|
|
@@ -6945,8 +8032,8 @@ var BincodeReader = class {
|
|
|
6945
8032
|
return this.readBytes(length);
|
|
6946
8033
|
}
|
|
6947
8034
|
readString() {
|
|
6948
|
-
const
|
|
6949
|
-
return new TextDecoder().decode(
|
|
8035
|
+
const bytes2 = this.readVecBytes();
|
|
8036
|
+
return new TextDecoder().decode(bytes2);
|
|
6950
8037
|
}
|
|
6951
8038
|
readVariant() {
|
|
6952
8039
|
return this.readU32();
|
|
@@ -7002,10 +8089,10 @@ var BincodeReader = class {
|
|
|
7002
8089
|
}
|
|
7003
8090
|
return numLength;
|
|
7004
8091
|
}
|
|
7005
|
-
ensureAvailable(
|
|
7006
|
-
if (this.offset +
|
|
8092
|
+
ensureAvailable(bytes2) {
|
|
8093
|
+
if (this.offset + bytes2 > this.bytes.length) {
|
|
7007
8094
|
throw new Error(
|
|
7008
|
-
`Unexpected end of data: need ${
|
|
8095
|
+
`Unexpected end of data: need ${bytes2} bytes at offset ${this.offset}, but only ${this.bytes.length - this.offset} available`
|
|
7009
8096
|
);
|
|
7010
8097
|
}
|
|
7011
8098
|
}
|
|
@@ -7144,27 +8231,27 @@ var BincodeWriter = class {
|
|
|
7144
8231
|
return this;
|
|
7145
8232
|
}
|
|
7146
8233
|
// ========== Compound Types ==========
|
|
7147
|
-
writeBytes(
|
|
7148
|
-
this.ensureCapacity(
|
|
7149
|
-
this.buffer.set(
|
|
7150
|
-
this.offset +=
|
|
8234
|
+
writeBytes(bytes2) {
|
|
8235
|
+
this.ensureCapacity(bytes2.length);
|
|
8236
|
+
this.buffer.set(bytes2, this.offset);
|
|
8237
|
+
this.offset += bytes2.length;
|
|
7151
8238
|
return this;
|
|
7152
8239
|
}
|
|
7153
|
-
writeFixedArray(
|
|
7154
|
-
if (expectedLength !== void 0 &&
|
|
8240
|
+
writeFixedArray(bytes2, expectedLength) {
|
|
8241
|
+
if (expectedLength !== void 0 && bytes2.length !== expectedLength) {
|
|
7155
8242
|
throw new Error(
|
|
7156
|
-
`Fixed array length mismatch: expected ${expectedLength}, got ${
|
|
8243
|
+
`Fixed array length mismatch: expected ${expectedLength}, got ${bytes2.length}`
|
|
7157
8244
|
);
|
|
7158
8245
|
}
|
|
7159
|
-
return this.writeBytes(
|
|
8246
|
+
return this.writeBytes(bytes2);
|
|
7160
8247
|
}
|
|
7161
|
-
writeVecBytes(
|
|
7162
|
-
this.writeU64(BigInt(
|
|
7163
|
-
return this.writeBytes(
|
|
8248
|
+
writeVecBytes(bytes2) {
|
|
8249
|
+
this.writeU64(BigInt(bytes2.length));
|
|
8250
|
+
return this.writeBytes(bytes2);
|
|
7164
8251
|
}
|
|
7165
|
-
writeString(
|
|
7166
|
-
const
|
|
7167
|
-
return this.writeVecBytes(
|
|
8252
|
+
writeString(str2) {
|
|
8253
|
+
const bytes2 = new TextEncoder().encode(str2);
|
|
8254
|
+
return this.writeVecBytes(bytes2);
|
|
7168
8255
|
}
|
|
7169
8256
|
writeVariant(index) {
|
|
7170
8257
|
return this.writeU32(index);
|
|
@@ -7608,15 +8695,15 @@ function arrayToHex(arr, reverse = false) {
|
|
|
7608
8695
|
return [...reverse ? new Uint8Array(arr).reverse() : new Uint8Array(arr)].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
7609
8696
|
}
|
|
7610
8697
|
function toBigIntLE(buf) {
|
|
7611
|
-
const
|
|
7612
|
-
if (
|
|
8698
|
+
const hex2 = arrayToHex(buf, true);
|
|
8699
|
+
if (hex2.length === 0) {
|
|
7613
8700
|
return BigInt(0);
|
|
7614
8701
|
}
|
|
7615
|
-
return BigInt(`0x${
|
|
8702
|
+
return BigInt(`0x${hex2}`);
|
|
7616
8703
|
}
|
|
7617
8704
|
function writeBufferLEBigInt(num, width, buffer, offset) {
|
|
7618
|
-
const
|
|
7619
|
-
const padded =
|
|
8705
|
+
const hex2 = num.toString(16);
|
|
8706
|
+
const padded = hex2.padStart(width * 2, "0").slice(0, width * 2);
|
|
7620
8707
|
for (const [ix, value] of padded.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)).entries()) {
|
|
7621
8708
|
buffer[offset + width - 1 - ix] = value;
|
|
7622
8709
|
}
|
|
@@ -7679,11 +8766,11 @@ var readBigUInt64LE = (buf, offset) => {
|
|
|
7679
8766
|
return BigInt(lo);
|
|
7680
8767
|
};
|
|
7681
8768
|
function readUIntLE(buf, offset, width) {
|
|
7682
|
-
const
|
|
7683
|
-
if (
|
|
8769
|
+
const hex2 = arrayToHex(buf.subarray(offset, offset + width), true);
|
|
8770
|
+
if (hex2.length === 0) {
|
|
7684
8771
|
return BigInt(0);
|
|
7685
8772
|
}
|
|
7686
|
-
return BigInt(`0x${
|
|
8773
|
+
return BigInt(`0x${hex2}`);
|
|
7687
8774
|
}
|
|
7688
8775
|
var readUInt32LE = (buffer, offset) => {
|
|
7689
8776
|
const first = buffer[offset];
|
|
@@ -7845,24 +8932,24 @@ var BinaryWriter = class _BinaryWriter {
|
|
|
7845
8932
|
writer._writes = writer._writes.next = () => (0, import_float.writeDoubleLE)(value, writer._buf, offset);
|
|
7846
8933
|
writer.totalSize += 8;
|
|
7847
8934
|
}
|
|
7848
|
-
string(
|
|
7849
|
-
return _BinaryWriter.string(
|
|
8935
|
+
string(str2) {
|
|
8936
|
+
return _BinaryWriter.string(str2, this);
|
|
7850
8937
|
}
|
|
7851
|
-
static string(
|
|
7852
|
-
const len = stringLengthFn()(
|
|
8938
|
+
static string(str2, writer) {
|
|
8939
|
+
const len = stringLengthFn()(str2);
|
|
7853
8940
|
let offset = writer.totalSize;
|
|
7854
8941
|
writer._writes = writer._writes.next = () => {
|
|
7855
8942
|
writeUInt32LE(len, writer._buf, offset);
|
|
7856
|
-
writeStringBufferFn(len)(
|
|
8943
|
+
writeStringBufferFn(len)(str2, writer._buf, offset + 4);
|
|
7857
8944
|
};
|
|
7858
8945
|
writer.totalSize += 4 + len;
|
|
7859
8946
|
}
|
|
7860
|
-
static stringCustom(
|
|
7861
|
-
const len = import_utf8.default.length(
|
|
8947
|
+
static stringCustom(str2, writer, lengthWriter = writeUInt32LE, lengthSize = 4) {
|
|
8948
|
+
const len = import_utf8.default.length(str2);
|
|
7862
8949
|
let offset = writer.totalSize;
|
|
7863
8950
|
writer._writes = writer._writes.next = () => {
|
|
7864
8951
|
lengthWriter(len, writer._buf, offset);
|
|
7865
|
-
writeStringBufferFn(len)(
|
|
8952
|
+
writeStringBufferFn(len)(str2, writer._buf, offset + lengthSize);
|
|
7866
8953
|
};
|
|
7867
8954
|
writer.totalSize += lengthSize + len;
|
|
7868
8955
|
}
|
|
@@ -9002,14 +10089,20 @@ var Message = class _Message {
|
|
|
9002
10089
|
accountKeys;
|
|
9003
10090
|
/** Transaction valid from (milliseconds since Unix epoch) */
|
|
9004
10091
|
validFrom;
|
|
10092
|
+
/** Config hash prefix for replay protection across chains */
|
|
10093
|
+
configHashPrefix;
|
|
10094
|
+
/** Whether the transaction should use OCC (optimistic concurrency control) scheduling */
|
|
10095
|
+
occ;
|
|
9005
10096
|
/** Compiled instructions with account indices */
|
|
9006
10097
|
instructions;
|
|
9007
10098
|
/** Cached serialized bytes */
|
|
9008
10099
|
serializedCache;
|
|
9009
|
-
constructor(header, accountKeys, validFrom, instructions) {
|
|
10100
|
+
constructor(header, accountKeys, validFrom, configHashPrefix, occ, instructions) {
|
|
9010
10101
|
this.header = Object.freeze({ ...header });
|
|
9011
10102
|
this.accountKeys = Object.freeze([...accountKeys]);
|
|
9012
10103
|
this.validFrom = validFrom;
|
|
10104
|
+
this.configHashPrefix = configHashPrefix;
|
|
10105
|
+
this.occ = occ;
|
|
9013
10106
|
this.instructions = Object.freeze(
|
|
9014
10107
|
instructions.map((ix) => Object.freeze({ ...ix }))
|
|
9015
10108
|
);
|
|
@@ -9069,6 +10162,25 @@ var Message = class _Message {
|
|
|
9069
10162
|
new DataView(validFromBytes.buffer).getBigUint64(0, true)
|
|
9070
10163
|
);
|
|
9071
10164
|
cursor += 8;
|
|
10165
|
+
if (data.length < cursor + 8) {
|
|
10166
|
+
throw new TransactionError(
|
|
10167
|
+
"INSUFFICIENT_DATA" /* INSUFFICIENT_DATA */,
|
|
10168
|
+
"Insufficient data for configHashPrefix"
|
|
10169
|
+
);
|
|
10170
|
+
}
|
|
10171
|
+
const configHashPrefixBytes = data.slice(cursor, cursor + 8);
|
|
10172
|
+
const configHashPrefix = BigInt.asUintN(
|
|
10173
|
+
64,
|
|
10174
|
+
new DataView(configHashPrefixBytes.buffer).getBigUint64(0, true)
|
|
10175
|
+
);
|
|
10176
|
+
cursor += 8;
|
|
10177
|
+
if (data.length < cursor + 1) {
|
|
10178
|
+
throw new TransactionError(
|
|
10179
|
+
"INSUFFICIENT_DATA" /* INSUFFICIENT_DATA */,
|
|
10180
|
+
"Insufficient data for occ flag"
|
|
10181
|
+
);
|
|
10182
|
+
}
|
|
10183
|
+
const occ = data[cursor++] !== 0;
|
|
9072
10184
|
const [instructionsLength, newCursor2] = deserializeCompactU16(
|
|
9073
10185
|
data,
|
|
9074
10186
|
cursor
|
|
@@ -9114,7 +10226,7 @@ var Message = class _Message {
|
|
|
9114
10226
|
data: instructionData
|
|
9115
10227
|
});
|
|
9116
10228
|
}
|
|
9117
|
-
return new _Message(header, accountKeys, validFrom, instructions);
|
|
10229
|
+
return new _Message(header, accountKeys, validFrom, configHashPrefix, occ, instructions);
|
|
9118
10230
|
}
|
|
9119
10231
|
serializeInternal() {
|
|
9120
10232
|
const buffer = [];
|
|
@@ -9131,6 +10243,14 @@ var Message = class _Message {
|
|
|
9131
10243
|
true
|
|
9132
10244
|
);
|
|
9133
10245
|
buffer.push(...new Uint8Array(validFromBuffer));
|
|
10246
|
+
const configHashPrefixBuffer = new ArrayBuffer(8);
|
|
10247
|
+
new DataView(configHashPrefixBuffer).setBigUint64(
|
|
10248
|
+
0,
|
|
10249
|
+
this.configHashPrefix,
|
|
10250
|
+
true
|
|
10251
|
+
);
|
|
10252
|
+
buffer.push(...new Uint8Array(configHashPrefixBuffer));
|
|
10253
|
+
buffer.push(this.occ ? 1 : 0);
|
|
9134
10254
|
this.serializeCompactArray(buffer, this.instructions, (buf, ix) => {
|
|
9135
10255
|
buf.push(ix.programIdIndex);
|
|
9136
10256
|
this.serializeCompactArray(buf, ix.accountKeyIndexes, (b, idx) => {
|
|
@@ -9515,6 +10635,8 @@ var Transaction = class _Transaction {
|
|
|
9515
10635
|
var TransactionBuilder = class _TransactionBuilder {
|
|
9516
10636
|
payer;
|
|
9517
10637
|
validFrom;
|
|
10638
|
+
configHashPrefix;
|
|
10639
|
+
occ = false;
|
|
9518
10640
|
instructions = [];
|
|
9519
10641
|
constructor() {
|
|
9520
10642
|
}
|
|
@@ -9548,6 +10670,27 @@ var TransactionBuilder = class _TransactionBuilder {
|
|
|
9548
10670
|
this.validFrom = validFrom;
|
|
9549
10671
|
return this;
|
|
9550
10672
|
}
|
|
10673
|
+
/**
|
|
10674
|
+
* Set the config hash prefix for replay protection.
|
|
10675
|
+
*
|
|
10676
|
+
* This is the first 64 bits of the config hash, used to ensure
|
|
10677
|
+
* transactions cannot be replayed on different chains.
|
|
10678
|
+
*
|
|
10679
|
+
* @param configHashPrefix - config hash prefix as a u64
|
|
10680
|
+
*/
|
|
10681
|
+
setConfigHashPrefix(configHashPrefix) {
|
|
10682
|
+
this.configHashPrefix = configHashPrefix;
|
|
10683
|
+
return this;
|
|
10684
|
+
}
|
|
10685
|
+
/**
|
|
10686
|
+
* Enable OCC (optimistic concurrency control) scheduling for this transaction.
|
|
10687
|
+
*
|
|
10688
|
+
* @param occ - Whether to use OCC scheduling (default: false)
|
|
10689
|
+
*/
|
|
10690
|
+
setOcc(occ) {
|
|
10691
|
+
this.occ = occ;
|
|
10692
|
+
return this;
|
|
10693
|
+
}
|
|
9551
10694
|
/**
|
|
9552
10695
|
* Add an instruction to the transaction.
|
|
9553
10696
|
*
|
|
@@ -9593,6 +10736,12 @@ var TransactionBuilder = class _TransactionBuilder {
|
|
|
9593
10736
|
"Transaction must have a valid from. Use setValidFrom() to set the valid from."
|
|
9594
10737
|
);
|
|
9595
10738
|
}
|
|
10739
|
+
if (this.configHashPrefix === void 0) {
|
|
10740
|
+
throw new TransactionError(
|
|
10741
|
+
"INVALID_MESSAGE_FORMAT" /* INVALID_MESSAGE_FORMAT */,
|
|
10742
|
+
"Transaction must have a config hash prefix. Use setConfigHashPrefix() to set the config hash prefix."
|
|
10743
|
+
);
|
|
10744
|
+
}
|
|
9596
10745
|
if (this.instructions.length === 0) {
|
|
9597
10746
|
throw TransactionError.noInstructions();
|
|
9598
10747
|
}
|
|
@@ -9637,6 +10786,8 @@ var TransactionBuilder = class _TransactionBuilder {
|
|
|
9637
10786
|
header,
|
|
9638
10787
|
accountKeys,
|
|
9639
10788
|
this.validFrom,
|
|
10789
|
+
this.configHashPrefix,
|
|
10790
|
+
this.occ,
|
|
9640
10791
|
compiledInstructions
|
|
9641
10792
|
);
|
|
9642
10793
|
return Transaction.fromMessage(message);
|
|
@@ -9726,6 +10877,9 @@ var KeypairSigner = class {
|
|
|
9726
10877
|
};
|
|
9727
10878
|
/*! Bundled license information:
|
|
9728
10879
|
|
|
10880
|
+
@scure/base/index.js:
|
|
10881
|
+
(*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
10882
|
+
|
|
9729
10883
|
@noble/ed25519/index.js:
|
|
9730
10884
|
(*! noble-ed25519 - MIT License (c) 2019 Paul Miller (paulmillr.com) *)
|
|
9731
10885
|
|
|
@@ -9733,9 +10887,6 @@ var KeypairSigner = class {
|
|
|
9733
10887
|
@noble/hashes/utils.js:
|
|
9734
10888
|
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
9735
10889
|
|
|
9736
|
-
@scure/base/index.js:
|
|
9737
|
-
(*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
9738
|
-
|
|
9739
10890
|
@scure/bip39/index.js:
|
|
9740
10891
|
(*! scure-bip39 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) *)
|
|
9741
10892
|
*/
|
|
@@ -9745,9 +10896,15 @@ exports.BASE_DERIVATION_PATH = BASE_DERIVATION_PATH;
|
|
|
9745
10896
|
exports.BaseRpcClient = BaseRpcClient;
|
|
9746
10897
|
exports.BincodeReader = BincodeReader;
|
|
9747
10898
|
exports.BincodeWriter = BincodeWriter;
|
|
10899
|
+
exports.CHACHA20_POLY1305_TAG_LENGTH = CHACHA20_POLY1305_TAG_LENGTH;
|
|
9748
10900
|
exports.CryptoError = CryptoError;
|
|
9749
10901
|
exports.CryptoErrorCode = CryptoErrorCode;
|
|
9750
10902
|
exports.DEFAULT_NUM_ACCOUNTS = DEFAULT_NUM_ACCOUNTS;
|
|
10903
|
+
exports.ED25519_PUBLIC_KEY_LENGTH = ED25519_PUBLIC_KEY_LENGTH;
|
|
10904
|
+
exports.HPKE_ENC_LENGTH = HPKE_ENC_LENGTH;
|
|
10905
|
+
exports.HPKE_OVERHEAD_LENGTH = HPKE_OVERHEAD_LENGTH;
|
|
10906
|
+
exports.HpkeError = HpkeError;
|
|
10907
|
+
exports.HpkeErrorCode = HpkeErrorCode;
|
|
9751
10908
|
exports.HttpTransport = HttpTransport;
|
|
9752
10909
|
exports.KELVIN_PER_RLO = KELVIN_PER_RLO;
|
|
9753
10910
|
exports.Keypair = Keypair;
|
|
@@ -9760,14 +10917,16 @@ exports.QueryRpcClient = QueryRpcClient;
|
|
|
9760
10917
|
exports.RIALO_DEVNET_CHAIN = RIALO_DEVNET_CHAIN;
|
|
9761
10918
|
exports.RIALO_LOCALNET_CHAIN = RIALO_LOCALNET_CHAIN;
|
|
9762
10919
|
exports.RIALO_MAINNET_CHAIN = RIALO_MAINNET_CHAIN;
|
|
9763
|
-
exports.RIALO_SHITNET_CHAIN = RIALO_SHITNET_CHAIN;
|
|
9764
10920
|
exports.RIALO_TESTNET_CHAIN = RIALO_TESTNET_CHAIN;
|
|
10921
|
+
exports.RexValue = RexValue;
|
|
10922
|
+
exports.RexValueVariant = RexValueVariant;
|
|
9765
10923
|
exports.RialoClient = RialoClient;
|
|
9766
10924
|
exports.RialoError = RialoError;
|
|
9767
10925
|
exports.RialoErrorType = RialoErrorType;
|
|
9768
10926
|
exports.RpcError = RpcError;
|
|
9769
10927
|
exports.RpcErrorCode = RpcErrorCode;
|
|
9770
10928
|
exports.SECRET_KEY_LENGTH = SECRET_KEY_LENGTH;
|
|
10929
|
+
exports.SECRET_SHARING_HPKE_INFO = SECRET_SHARING_HPKE_INFO;
|
|
9771
10930
|
exports.SIGNATURE_LENGTH = SIGNATURE_LENGTH;
|
|
9772
10931
|
exports.SYSTEM_PROGRAM_ID = SYSTEM_PROGRAM_ID;
|
|
9773
10932
|
exports.Schema = Schema;
|
|
@@ -9781,8 +10940,9 @@ exports.TransactionRpcClient = TransactionRpcClient;
|
|
|
9781
10940
|
exports.URL_DEVNET = URL_DEVNET;
|
|
9782
10941
|
exports.URL_LOCALNET = URL_LOCALNET;
|
|
9783
10942
|
exports.URL_MAINNET = URL_MAINNET;
|
|
9784
|
-
exports.URL_SHITNET = URL_SHITNET;
|
|
9785
10943
|
exports.URL_TESTNET = URL_TESTNET;
|
|
10944
|
+
exports.USER_SECRET_AAD = USER_SECRET_AAD;
|
|
10945
|
+
exports.X25519_PUBLIC_KEY_LENGTH = X25519_PUBLIC_KEY_LENGTH;
|
|
9786
10946
|
exports.allocateInstruction = allocateInstruction;
|
|
9787
10947
|
exports.assignInstruction = assignInstruction;
|
|
9788
10948
|
exports.calculateBackoff = calculateBackoff;
|
|
@@ -9795,15 +10955,19 @@ exports.deserializeBorsh = deserializeBorsh;
|
|
|
9795
10955
|
exports.deserializeCompactU16 = deserializeCompactU162;
|
|
9796
10956
|
exports.deserializeStrict = deserializeStrict;
|
|
9797
10957
|
exports.encodeBorshData = encodeBorshData;
|
|
10958
|
+
exports.encryptForRex = encryptForRex;
|
|
9798
10959
|
exports.field = field;
|
|
9799
10960
|
exports.fixedArray = fixedArray;
|
|
9800
10961
|
exports.fromBase64 = fromBase64;
|
|
10962
|
+
exports.getCiphertextLength = getCiphertextLength;
|
|
9801
10963
|
exports.getDefaultRialoClientConfig = getDefaultRialoClientConfig;
|
|
9802
10964
|
exports.getDevnetUrl = getDevnetUrl;
|
|
9803
10965
|
exports.getLocalnetUrl = getLocalnetUrl;
|
|
9804
10966
|
exports.getMainnetUrl = getMainnetUrl;
|
|
9805
10967
|
exports.getTestnetUrl = getTestnetUrl;
|
|
10968
|
+
exports.hpkeEncrypt = hpkeEncrypt;
|
|
9806
10969
|
exports.isOnCurve = isOnCurve;
|
|
10970
|
+
exports.isValidCiphertextLength = isValidCiphertextLength;
|
|
9807
10971
|
exports.option = option;
|
|
9808
10972
|
exports.seedToBytes = seedToBytes;
|
|
9809
10973
|
exports.serialize = serialize;
|