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