@solana/web3.js 2.0.0-experimental.3b1c7d5 → 2.0.0-experimental.3b54eda
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/LICENSE +1 -1
- package/README.md +1155 -43
- package/dist/index.browser.cjs +782 -10
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +751 -13
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +3572 -355
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +740 -11
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +771 -10
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +740 -11
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +85 -14
- package/dist/types/airdrop-confirmer.d.ts +19 -0
- package/dist/types/airdrop-confirmer.d.ts.map +1 -0
- package/dist/types/airdrop.d.ts +21 -0
- package/dist/types/airdrop.d.ts.map +1 -0
- package/dist/types/cached-abortable-iterable.d.ts +11 -0
- package/dist/types/cached-abortable-iterable.d.ts.map +1 -0
- package/dist/types/index.d.ts +12 -2
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/rpc-default-config.d.ts.map +1 -0
- package/dist/types/rpc-integer-overflow-error.d.ts.map +1 -0
- package/dist/types/rpc-request-coalescer.d.ts +1 -1
- package/dist/types/rpc-request-coalescer.d.ts.map +1 -0
- package/dist/types/rpc-request-deduplication.d.ts.map +1 -0
- package/dist/types/rpc-subscription-coalescer.d.ts +10 -0
- package/dist/types/rpc-subscription-coalescer.d.ts.map +1 -0
- package/dist/types/rpc-transport.d.ts +1 -2
- package/dist/types/rpc-transport.d.ts.map +1 -0
- package/dist/types/rpc-websocket-autopinger.d.ts +8 -0
- package/dist/types/rpc-websocket-autopinger.d.ts.map +1 -0
- package/dist/types/rpc-websocket-connection-sharding.d.ts +13 -0
- package/dist/types/rpc-websocket-connection-sharding.d.ts.map +1 -0
- package/dist/types/rpc-websocket-transport.d.ts +12 -0
- package/dist/types/rpc-websocket-transport.d.ts.map +1 -0
- package/dist/types/rpc.d.ts +4 -3
- package/dist/types/rpc.d.ts.map +1 -0
- package/dist/types/send-transaction.d.ts +38 -0
- package/dist/types/send-transaction.d.ts.map +1 -0
- package/dist/types/transaction-confirmation-strategy-blockheight.d.ts +9 -0
- package/dist/types/transaction-confirmation-strategy-blockheight.d.ts.map +1 -0
- package/dist/types/transaction-confirmation-strategy-nonce.d.ts +14 -0
- package/dist/types/transaction-confirmation-strategy-nonce.d.ts.map +1 -0
- package/dist/types/transaction-confirmation-strategy-racer.d.ts +14 -0
- package/dist/types/transaction-confirmation-strategy-racer.d.ts.map +1 -0
- package/dist/types/transaction-confirmation-strategy-recent-signature.d.ts +12 -0
- package/dist/types/transaction-confirmation-strategy-recent-signature.d.ts.map +1 -0
- package/dist/types/transaction-confirmation-strategy-timeout.d.ts +8 -0
- package/dist/types/transaction-confirmation-strategy-timeout.d.ts.map +1 -0
- package/dist/types/transaction-confirmation.d.ts +32 -0
- package/dist/types/transaction-confirmation.d.ts.map +1 -0
- package/package.json +27 -25
|
@@ -12,8 +12,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
12
12
|
var __esm = (fn, res) => function __init() {
|
|
13
13
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
14
14
|
};
|
|
15
|
-
var __commonJS = (cb,
|
|
16
|
-
return
|
|
15
|
+
var __commonJS = (cb, mod2) => function __require() {
|
|
16
|
+
return mod2 || (0, cb[__getOwnPropNames(cb)[0]])((mod2 = { exports: {} }).exports, mod2), mod2.exports;
|
|
17
17
|
};
|
|
18
18
|
var __copyProps = (to, from, except, desc) => {
|
|
19
19
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
@@ -23,13 +23,13 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
23
23
|
}
|
|
24
24
|
return to;
|
|
25
25
|
};
|
|
26
|
-
var __toESM = (
|
|
26
|
+
var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__getProtoOf(mod2)) : {}, __copyProps(
|
|
27
27
|
// If the importer is in node compatibility mode or this is not an ESM
|
|
28
28
|
// file that has been converted to a CommonJS file using a Babel-
|
|
29
29
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
30
30
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
31
|
-
isNodeMode || !
|
|
32
|
-
|
|
31
|
+
isNodeMode || !mod2 || !mod2.__esModule ? __defProp(target, "default", { value: mod2, enumerable: true }) : target,
|
|
32
|
+
mod2
|
|
33
33
|
));
|
|
34
34
|
var __publicField = (obj, key, value) => {
|
|
35
35
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
@@ -122,18 +122,782 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
122
122
|
// src/index.ts
|
|
123
123
|
init_env_shim();
|
|
124
124
|
|
|
125
|
+
// ../addresses/dist/index.browser.js
|
|
126
|
+
init_env_shim();
|
|
127
|
+
|
|
128
|
+
// ../codecs-core/dist/index.browser.js
|
|
129
|
+
init_env_shim();
|
|
130
|
+
function assertByteArrayIsNotEmptyForCodec(codecDescription, bytes, offset = 0) {
|
|
131
|
+
if (bytes.length - offset <= 0) {
|
|
132
|
+
throw new Error(`Codec [${codecDescription}] cannot decode empty byte arrays.`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function assertByteArrayHasEnoughBytesForCodec(codecDescription, expected, bytes, offset = 0) {
|
|
136
|
+
const bytesLength = bytes.length - offset;
|
|
137
|
+
if (bytesLength < expected) {
|
|
138
|
+
throw new Error(`Codec [${codecDescription}] expected ${expected} bytes, got ${bytesLength}.`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
var padBytes = (bytes, length) => {
|
|
142
|
+
if (bytes.length >= length)
|
|
143
|
+
return bytes;
|
|
144
|
+
const paddedBytes = new Uint8Array(length).fill(0);
|
|
145
|
+
paddedBytes.set(bytes);
|
|
146
|
+
return paddedBytes;
|
|
147
|
+
};
|
|
148
|
+
var fixBytes = (bytes, length) => padBytes(bytes.length <= length ? bytes : bytes.slice(0, length), length);
|
|
149
|
+
function getEncodedSize(value, encoder) {
|
|
150
|
+
return "fixedSize" in encoder ? encoder.fixedSize : encoder.getSizeFromValue(value);
|
|
151
|
+
}
|
|
152
|
+
function createEncoder(encoder) {
|
|
153
|
+
return Object.freeze({
|
|
154
|
+
...encoder,
|
|
155
|
+
encode: (value) => {
|
|
156
|
+
const bytes = new Uint8Array(getEncodedSize(value, encoder));
|
|
157
|
+
encoder.write(value, bytes, 0);
|
|
158
|
+
return bytes;
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
function createDecoder(decoder) {
|
|
163
|
+
return Object.freeze({
|
|
164
|
+
...decoder,
|
|
165
|
+
decode: (bytes, offset = 0) => decoder.read(bytes, offset)[0]
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
function isFixedSize(codec) {
|
|
169
|
+
return "fixedSize" in codec && typeof codec.fixedSize === "number";
|
|
170
|
+
}
|
|
171
|
+
function assertIsFixedSize(codec, message) {
|
|
172
|
+
if (!isFixedSize(codec)) {
|
|
173
|
+
throw new Error(message != null ? message : "Expected a fixed-size codec, got a variable-size one.");
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
function isVariableSize(codec) {
|
|
177
|
+
return !isFixedSize(codec);
|
|
178
|
+
}
|
|
179
|
+
function combineCodec(encoder, decoder) {
|
|
180
|
+
if (isFixedSize(encoder) !== isFixedSize(decoder)) {
|
|
181
|
+
throw new Error(`Encoder and decoder must either both be fixed-size or variable-size.`);
|
|
182
|
+
}
|
|
183
|
+
if (isFixedSize(encoder) && isFixedSize(decoder) && encoder.fixedSize !== decoder.fixedSize) {
|
|
184
|
+
throw new Error(
|
|
185
|
+
`Encoder and decoder must have the same fixed size, got [${encoder.fixedSize}] and [${decoder.fixedSize}].`
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
if (!isFixedSize(encoder) && !isFixedSize(decoder) && encoder.maxSize !== decoder.maxSize) {
|
|
189
|
+
throw new Error(
|
|
190
|
+
`Encoder and decoder must have the same max size, got [${encoder.maxSize}] and [${decoder.maxSize}].`
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
return {
|
|
194
|
+
...decoder,
|
|
195
|
+
...encoder,
|
|
196
|
+
decode: decoder.decode,
|
|
197
|
+
encode: encoder.encode,
|
|
198
|
+
read: decoder.read,
|
|
199
|
+
write: encoder.write
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
function fixEncoder(encoder, fixedBytes) {
|
|
203
|
+
return createEncoder({
|
|
204
|
+
fixedSize: fixedBytes,
|
|
205
|
+
write: (value, bytes, offset) => {
|
|
206
|
+
const variableByteArray = encoder.encode(value);
|
|
207
|
+
const fixedByteArray = variableByteArray.length > fixedBytes ? variableByteArray.slice(0, fixedBytes) : variableByteArray;
|
|
208
|
+
bytes.set(fixedByteArray, offset);
|
|
209
|
+
return offset + fixedBytes;
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
function fixDecoder(decoder, fixedBytes) {
|
|
214
|
+
return createDecoder({
|
|
215
|
+
fixedSize: fixedBytes,
|
|
216
|
+
read: (bytes, offset) => {
|
|
217
|
+
assertByteArrayHasEnoughBytesForCodec("fixCodec", fixedBytes, bytes, offset);
|
|
218
|
+
if (offset > 0 || bytes.length > fixedBytes) {
|
|
219
|
+
bytes = bytes.slice(offset, offset + fixedBytes);
|
|
220
|
+
}
|
|
221
|
+
if (isFixedSize(decoder)) {
|
|
222
|
+
bytes = fixBytes(bytes, decoder.fixedSize);
|
|
223
|
+
}
|
|
224
|
+
const [value] = decoder.read(bytes, 0);
|
|
225
|
+
return [value, offset + fixedBytes];
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
function mapEncoder(encoder, unmap) {
|
|
230
|
+
return createEncoder({
|
|
231
|
+
...isVariableSize(encoder) ? { ...encoder, getSizeFromValue: (value) => encoder.getSizeFromValue(unmap(value)) } : encoder,
|
|
232
|
+
write: (value, bytes, offset) => encoder.write(unmap(value), bytes, offset)
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
function mapDecoder(decoder, map) {
|
|
236
|
+
return createDecoder({
|
|
237
|
+
...decoder,
|
|
238
|
+
read: (bytes, offset) => {
|
|
239
|
+
const [value, newOffset] = decoder.read(bytes, offset);
|
|
240
|
+
return [map(value, bytes, offset), newOffset];
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// ../codecs-strings/dist/index.browser.js
|
|
246
|
+
init_env_shim();
|
|
247
|
+
|
|
248
|
+
// ../codecs-numbers/dist/index.browser.js
|
|
249
|
+
init_env_shim();
|
|
250
|
+
function assertNumberIsBetweenForCodec(codecDescription, min, max, value) {
|
|
251
|
+
if (value < min || value > max) {
|
|
252
|
+
throw new Error(
|
|
253
|
+
`Codec [${codecDescription}] expected number to be in the range [${min}, ${max}], got ${value}.`
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
function isLittleEndian(config) {
|
|
258
|
+
return (config == null ? void 0 : config.endian) === 1 ? false : true;
|
|
259
|
+
}
|
|
260
|
+
function numberEncoderFactory(input) {
|
|
261
|
+
return createEncoder({
|
|
262
|
+
fixedSize: input.size,
|
|
263
|
+
write(value, bytes, offset) {
|
|
264
|
+
if (input.range) {
|
|
265
|
+
assertNumberIsBetweenForCodec(input.name, input.range[0], input.range[1], value);
|
|
266
|
+
}
|
|
267
|
+
const arrayBuffer = new ArrayBuffer(input.size);
|
|
268
|
+
input.set(new DataView(arrayBuffer), value, isLittleEndian(input.config));
|
|
269
|
+
bytes.set(new Uint8Array(arrayBuffer), offset);
|
|
270
|
+
return offset + input.size;
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
function numberDecoderFactory(input) {
|
|
275
|
+
return createDecoder({
|
|
276
|
+
fixedSize: input.size,
|
|
277
|
+
read(bytes, offset = 0) {
|
|
278
|
+
assertByteArrayIsNotEmptyForCodec(input.name, bytes, offset);
|
|
279
|
+
assertByteArrayHasEnoughBytesForCodec(input.name, input.size, bytes, offset);
|
|
280
|
+
const view = new DataView(toArrayBuffer(bytes, offset, input.size));
|
|
281
|
+
return [input.get(view, isLittleEndian(input.config)), offset + input.size];
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
function toArrayBuffer(bytes, offset, length) {
|
|
286
|
+
const bytesOffset = bytes.byteOffset + (offset != null ? offset : 0);
|
|
287
|
+
const bytesLength = length != null ? length : bytes.byteLength;
|
|
288
|
+
return bytes.buffer.slice(bytesOffset, bytesOffset + bytesLength);
|
|
289
|
+
}
|
|
290
|
+
var getShortU16Encoder = () => createEncoder({
|
|
291
|
+
getSizeFromValue: (value) => {
|
|
292
|
+
if (value <= 127)
|
|
293
|
+
return 1;
|
|
294
|
+
if (value <= 16383)
|
|
295
|
+
return 2;
|
|
296
|
+
return 3;
|
|
297
|
+
},
|
|
298
|
+
maxSize: 3,
|
|
299
|
+
write: (value, bytes, offset) => {
|
|
300
|
+
assertNumberIsBetweenForCodec("shortU16", 0, 65535, value);
|
|
301
|
+
const shortU16Bytes = [0];
|
|
302
|
+
for (let ii = 0; ; ii += 1) {
|
|
303
|
+
const alignedValue = value >> ii * 7;
|
|
304
|
+
if (alignedValue === 0) {
|
|
305
|
+
break;
|
|
306
|
+
}
|
|
307
|
+
const nextSevenBits = 127 & alignedValue;
|
|
308
|
+
shortU16Bytes[ii] = nextSevenBits;
|
|
309
|
+
if (ii > 0) {
|
|
310
|
+
shortU16Bytes[ii - 1] |= 128;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
bytes.set(shortU16Bytes, offset);
|
|
314
|
+
return offset + shortU16Bytes.length;
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
var getShortU16Decoder = () => createDecoder({
|
|
318
|
+
maxSize: 3,
|
|
319
|
+
read: (bytes, offset) => {
|
|
320
|
+
let value = 0;
|
|
321
|
+
let byteCount = 0;
|
|
322
|
+
while (++byteCount) {
|
|
323
|
+
const byteIndex = byteCount - 1;
|
|
324
|
+
const currentByte = bytes[offset + byteIndex];
|
|
325
|
+
const nextSevenBits = 127 & currentByte;
|
|
326
|
+
value |= nextSevenBits << byteIndex * 7;
|
|
327
|
+
if ((currentByte & 128) === 0) {
|
|
328
|
+
break;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
return [value, offset + byteCount];
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
var getU32Encoder = (config = {}) => numberEncoderFactory({
|
|
335
|
+
config,
|
|
336
|
+
name: "u32",
|
|
337
|
+
range: [0, Number("0xffffffff")],
|
|
338
|
+
set: (view, value, le) => view.setUint32(0, value, le),
|
|
339
|
+
size: 4
|
|
340
|
+
});
|
|
341
|
+
var getU32Decoder = (config = {}) => numberDecoderFactory({
|
|
342
|
+
config,
|
|
343
|
+
get: (view, le) => view.getUint32(0, le),
|
|
344
|
+
name: "u32",
|
|
345
|
+
size: 4
|
|
346
|
+
});
|
|
347
|
+
var getU8Encoder = () => numberEncoderFactory({
|
|
348
|
+
name: "u8",
|
|
349
|
+
range: [0, Number("0xff")],
|
|
350
|
+
set: (view, value) => view.setUint8(0, value),
|
|
351
|
+
size: 1
|
|
352
|
+
});
|
|
353
|
+
var getU8Decoder = () => numberDecoderFactory({
|
|
354
|
+
get: (view) => view.getUint8(0),
|
|
355
|
+
name: "u8",
|
|
356
|
+
size: 1
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
// ../codecs-strings/dist/index.browser.js
|
|
360
|
+
function assertValidBaseString(alphabet4, testValue, givenValue = testValue) {
|
|
361
|
+
if (!testValue.match(new RegExp(`^[${alphabet4}]*$`))) {
|
|
362
|
+
throw new Error(`Expected a string of base ${alphabet4.length}, got [${givenValue}].`);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
var getBaseXEncoder = (alphabet4) => {
|
|
366
|
+
return createEncoder({
|
|
367
|
+
getSizeFromValue: (value) => {
|
|
368
|
+
const [leadingZeroes, tailChars] = partitionLeadingZeroes(value, alphabet4[0]);
|
|
369
|
+
if (tailChars === "")
|
|
370
|
+
return value.length;
|
|
371
|
+
const base10Number = getBigIntFromBaseX(tailChars, alphabet4);
|
|
372
|
+
return leadingZeroes.length + Math.ceil(base10Number.toString(16).length / 2);
|
|
373
|
+
},
|
|
374
|
+
write(value, bytes, offset) {
|
|
375
|
+
assertValidBaseString(alphabet4, value);
|
|
376
|
+
if (value === "")
|
|
377
|
+
return offset;
|
|
378
|
+
const [leadingZeroes, tailChars] = partitionLeadingZeroes(value, alphabet4[0]);
|
|
379
|
+
if (tailChars === "") {
|
|
380
|
+
bytes.set(new Uint8Array(leadingZeroes.length).fill(0), offset);
|
|
381
|
+
return offset + leadingZeroes.length;
|
|
382
|
+
}
|
|
383
|
+
let base10Number = getBigIntFromBaseX(tailChars, alphabet4);
|
|
384
|
+
const tailBytes = [];
|
|
385
|
+
while (base10Number > 0n) {
|
|
386
|
+
tailBytes.unshift(Number(base10Number % 256n));
|
|
387
|
+
base10Number /= 256n;
|
|
388
|
+
}
|
|
389
|
+
const bytesToAdd = [...Array(leadingZeroes.length).fill(0), ...tailBytes];
|
|
390
|
+
bytes.set(bytesToAdd, offset);
|
|
391
|
+
return offset + bytesToAdd.length;
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
};
|
|
395
|
+
var getBaseXDecoder = (alphabet4) => {
|
|
396
|
+
return createDecoder({
|
|
397
|
+
read(rawBytes, offset) {
|
|
398
|
+
const bytes = offset === 0 ? rawBytes : rawBytes.slice(offset);
|
|
399
|
+
if (bytes.length === 0)
|
|
400
|
+
return ["", 0];
|
|
401
|
+
let trailIndex = bytes.findIndex((n) => n !== 0);
|
|
402
|
+
trailIndex = trailIndex === -1 ? bytes.length : trailIndex;
|
|
403
|
+
const leadingZeroes = alphabet4[0].repeat(trailIndex);
|
|
404
|
+
if (trailIndex === bytes.length)
|
|
405
|
+
return [leadingZeroes, rawBytes.length];
|
|
406
|
+
const base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
|
|
407
|
+
const tailChars = getBaseXFromBigInt(base10Number, alphabet4);
|
|
408
|
+
return [leadingZeroes + tailChars, rawBytes.length];
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
};
|
|
412
|
+
function partitionLeadingZeroes(value, zeroCharacter) {
|
|
413
|
+
const leadingZeroIndex = [...value].findIndex((c) => c !== zeroCharacter);
|
|
414
|
+
return leadingZeroIndex === -1 ? [value, ""] : [value.slice(0, leadingZeroIndex), value.slice(leadingZeroIndex)];
|
|
415
|
+
}
|
|
416
|
+
function getBigIntFromBaseX(value, alphabet4) {
|
|
417
|
+
const base = BigInt(alphabet4.length);
|
|
418
|
+
return [...value].reduce((sum, char) => sum * base + BigInt(alphabet4.indexOf(char)), 0n);
|
|
419
|
+
}
|
|
420
|
+
function getBaseXFromBigInt(value, alphabet4) {
|
|
421
|
+
const base = BigInt(alphabet4.length);
|
|
422
|
+
const tailChars = [];
|
|
423
|
+
while (value > 0n) {
|
|
424
|
+
tailChars.unshift(alphabet4[Number(value % base)]);
|
|
425
|
+
value /= base;
|
|
426
|
+
}
|
|
427
|
+
return tailChars.join("");
|
|
428
|
+
}
|
|
429
|
+
var alphabet2 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
430
|
+
var getBase58Encoder = () => getBaseXEncoder(alphabet2);
|
|
431
|
+
var getBase58Decoder = () => getBaseXDecoder(alphabet2);
|
|
432
|
+
var getBase64Encoder = () => {
|
|
433
|
+
{
|
|
434
|
+
return createEncoder({
|
|
435
|
+
getSizeFromValue: (value) => {
|
|
436
|
+
try {
|
|
437
|
+
return atob(value).length;
|
|
438
|
+
} catch (e23) {
|
|
439
|
+
throw new Error(`Expected a string of base 64, got [${value}].`);
|
|
440
|
+
}
|
|
441
|
+
},
|
|
442
|
+
write(value, bytes, offset) {
|
|
443
|
+
try {
|
|
444
|
+
const bytesToAdd = atob(value).split("").map((c) => c.charCodeAt(0));
|
|
445
|
+
bytes.set(bytesToAdd, offset);
|
|
446
|
+
return bytesToAdd.length + offset;
|
|
447
|
+
} catch (e23) {
|
|
448
|
+
throw new Error(`Expected a string of base 64, got [${value}].`);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
var getBase64Decoder = () => {
|
|
455
|
+
{
|
|
456
|
+
return createDecoder({
|
|
457
|
+
read(bytes, offset = 0) {
|
|
458
|
+
const slice = bytes.slice(offset);
|
|
459
|
+
const value = btoa(String.fromCharCode(...slice));
|
|
460
|
+
return [value, bytes.length];
|
|
461
|
+
}
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
var removeNullCharacters = (value) => (
|
|
466
|
+
// eslint-disable-next-line no-control-regex
|
|
467
|
+
value.replace(/\u0000/g, "")
|
|
468
|
+
);
|
|
469
|
+
var e = globalThis.TextDecoder;
|
|
470
|
+
var o = globalThis.TextEncoder;
|
|
471
|
+
var getUtf8Encoder = () => {
|
|
472
|
+
let textEncoder;
|
|
473
|
+
return createEncoder({
|
|
474
|
+
getSizeFromValue: (value) => (textEncoder || (textEncoder = new o())).encode(value).length,
|
|
475
|
+
write: (value, bytes, offset) => {
|
|
476
|
+
const bytesToAdd = (textEncoder || (textEncoder = new o())).encode(value);
|
|
477
|
+
bytes.set(bytesToAdd, offset);
|
|
478
|
+
return offset + bytesToAdd.length;
|
|
479
|
+
}
|
|
480
|
+
});
|
|
481
|
+
};
|
|
482
|
+
var getUtf8Decoder = () => {
|
|
483
|
+
let textDecoder;
|
|
484
|
+
return createDecoder({
|
|
485
|
+
read(bytes, offset) {
|
|
486
|
+
const value = (textDecoder || (textDecoder = new e())).decode(bytes.slice(offset));
|
|
487
|
+
return [removeNullCharacters(value), bytes.length];
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
};
|
|
491
|
+
function getStringEncoder(config = {}) {
|
|
492
|
+
var _a, _b;
|
|
493
|
+
const size = (_a = config.size) != null ? _a : getU32Encoder();
|
|
494
|
+
const encoding = (_b = config.encoding) != null ? _b : getUtf8Encoder();
|
|
495
|
+
if (size === "variable") {
|
|
496
|
+
return encoding;
|
|
497
|
+
}
|
|
498
|
+
if (typeof size === "number") {
|
|
499
|
+
return fixEncoder(encoding, size);
|
|
500
|
+
}
|
|
501
|
+
return createEncoder({
|
|
502
|
+
getSizeFromValue: (value) => {
|
|
503
|
+
const contentSize = getEncodedSize(value, encoding);
|
|
504
|
+
return getEncodedSize(contentSize, size) + contentSize;
|
|
505
|
+
},
|
|
506
|
+
write: (value, bytes, offset) => {
|
|
507
|
+
const contentSize = getEncodedSize(value, encoding);
|
|
508
|
+
offset = size.write(contentSize, bytes, offset);
|
|
509
|
+
return encoding.write(value, bytes, offset);
|
|
510
|
+
}
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
function getStringDecoder(config = {}) {
|
|
514
|
+
var _a, _b;
|
|
515
|
+
const size = (_a = config.size) != null ? _a : getU32Decoder();
|
|
516
|
+
const encoding = (_b = config.encoding) != null ? _b : getUtf8Decoder();
|
|
517
|
+
if (size === "variable") {
|
|
518
|
+
return encoding;
|
|
519
|
+
}
|
|
520
|
+
if (typeof size === "number") {
|
|
521
|
+
return fixDecoder(encoding, size);
|
|
522
|
+
}
|
|
523
|
+
return createDecoder({
|
|
524
|
+
read: (bytes, offset = 0) => {
|
|
525
|
+
assertByteArrayIsNotEmptyForCodec("string", bytes, offset);
|
|
526
|
+
const [lengthBigInt, lengthOffset] = size.read(bytes, offset);
|
|
527
|
+
const length = Number(lengthBigInt);
|
|
528
|
+
offset = lengthOffset;
|
|
529
|
+
const contentBytes = bytes.slice(offset, offset + length);
|
|
530
|
+
assertByteArrayHasEnoughBytesForCodec("string", length, contentBytes);
|
|
531
|
+
const [value, contentOffset] = encoding.read(contentBytes, 0);
|
|
532
|
+
offset += contentOffset;
|
|
533
|
+
return [value, offset];
|
|
534
|
+
}
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
// ../assertions/dist/index.browser.js
|
|
539
|
+
init_env_shim();
|
|
540
|
+
function assertIsSecureContext() {
|
|
541
|
+
if (!globalThis.isSecureContext) {
|
|
542
|
+
throw new Error(
|
|
543
|
+
"Cryptographic operations are only allowed in secure browser contexts. Read more here: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts"
|
|
544
|
+
);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
var cachedEd25519Decision;
|
|
548
|
+
async function isEd25519CurveSupported(subtle) {
|
|
549
|
+
if (cachedEd25519Decision === void 0) {
|
|
550
|
+
cachedEd25519Decision = new Promise((resolve) => {
|
|
551
|
+
subtle.generateKey(
|
|
552
|
+
"Ed25519",
|
|
553
|
+
/* extractable */
|
|
554
|
+
false,
|
|
555
|
+
["sign", "verify"]
|
|
556
|
+
).catch(() => {
|
|
557
|
+
resolve(cachedEd25519Decision = false);
|
|
558
|
+
}).then(() => {
|
|
559
|
+
resolve(cachedEd25519Decision = true);
|
|
560
|
+
});
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
if (typeof cachedEd25519Decision === "boolean") {
|
|
564
|
+
return cachedEd25519Decision;
|
|
565
|
+
} else {
|
|
566
|
+
return await cachedEd25519Decision;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
async function assertDigestCapabilityIsAvailable() {
|
|
570
|
+
var _a;
|
|
571
|
+
assertIsSecureContext();
|
|
572
|
+
if (typeof globalThis.crypto === "undefined" || typeof ((_a = globalThis.crypto.subtle) == null ? void 0 : _a.digest) !== "function") {
|
|
573
|
+
throw new Error("No digest implementation could be found");
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
async function assertKeyGenerationIsAvailable() {
|
|
577
|
+
var _a;
|
|
578
|
+
assertIsSecureContext();
|
|
579
|
+
if (typeof globalThis.crypto === "undefined" || typeof ((_a = globalThis.crypto.subtle) == null ? void 0 : _a.generateKey) !== "function") {
|
|
580
|
+
throw new Error("No key generation implementation could be found");
|
|
581
|
+
}
|
|
582
|
+
if (!await isEd25519CurveSupported(globalThis.crypto.subtle)) {
|
|
583
|
+
throw new Error(
|
|
584
|
+
"This runtime does not support the generation of Ed25519 key pairs.\n\nInstall and import `@solana/webcrypto-ed25519-polyfill` before generating keys in environments that do not support Ed25519.\n\nFor a list of runtimes that currently support Ed25519 operations, visit https://github.com/WICG/webcrypto-secure-curves/issues/20"
|
|
585
|
+
);
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
async function assertKeyExporterIsAvailable() {
|
|
589
|
+
var _a;
|
|
590
|
+
assertIsSecureContext();
|
|
591
|
+
if (typeof globalThis.crypto === "undefined" || typeof ((_a = globalThis.crypto.subtle) == null ? void 0 : _a.exportKey) !== "function") {
|
|
592
|
+
throw new Error("No key export implementation could be found");
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
async function assertSigningCapabilityIsAvailable() {
|
|
596
|
+
var _a;
|
|
597
|
+
assertIsSecureContext();
|
|
598
|
+
if (typeof globalThis.crypto === "undefined" || typeof ((_a = globalThis.crypto.subtle) == null ? void 0 : _a.sign) !== "function") {
|
|
599
|
+
throw new Error("No signing implementation could be found");
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
async function assertVerificationCapabilityIsAvailable() {
|
|
603
|
+
var _a;
|
|
604
|
+
assertIsSecureContext();
|
|
605
|
+
if (typeof globalThis.crypto === "undefined" || typeof ((_a = globalThis.crypto.subtle) == null ? void 0 : _a.verify) !== "function") {
|
|
606
|
+
throw new Error("No signature verification implementation could be found");
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
// ../addresses/dist/index.browser.js
|
|
611
|
+
var memoizedBase58Encoder;
|
|
612
|
+
var memoizedBase58Decoder;
|
|
613
|
+
function getMemoizedBase58Encoder() {
|
|
614
|
+
if (!memoizedBase58Encoder)
|
|
615
|
+
memoizedBase58Encoder = getBase58Encoder();
|
|
616
|
+
return memoizedBase58Encoder;
|
|
617
|
+
}
|
|
618
|
+
function getMemoizedBase58Decoder() {
|
|
619
|
+
if (!memoizedBase58Decoder)
|
|
620
|
+
memoizedBase58Decoder = getBase58Decoder();
|
|
621
|
+
return memoizedBase58Decoder;
|
|
622
|
+
}
|
|
623
|
+
function isAddress(putativeAddress) {
|
|
624
|
+
if (
|
|
625
|
+
// Lowest address (32 bytes of zeroes)
|
|
626
|
+
putativeAddress.length < 32 || // Highest address (32 bytes of 255)
|
|
627
|
+
putativeAddress.length > 44
|
|
628
|
+
) {
|
|
629
|
+
return false;
|
|
630
|
+
}
|
|
631
|
+
const base58Encoder3 = getMemoizedBase58Encoder();
|
|
632
|
+
const bytes = base58Encoder3.encode(putativeAddress);
|
|
633
|
+
const numBytes = bytes.byteLength;
|
|
634
|
+
if (numBytes !== 32) {
|
|
635
|
+
return false;
|
|
636
|
+
}
|
|
637
|
+
return true;
|
|
638
|
+
}
|
|
639
|
+
function assertIsAddress(putativeAddress) {
|
|
640
|
+
try {
|
|
641
|
+
if (
|
|
642
|
+
// Lowest address (32 bytes of zeroes)
|
|
643
|
+
putativeAddress.length < 32 || // Highest address (32 bytes of 255)
|
|
644
|
+
putativeAddress.length > 44
|
|
645
|
+
) {
|
|
646
|
+
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
647
|
+
}
|
|
648
|
+
const base58Encoder3 = getMemoizedBase58Encoder();
|
|
649
|
+
const bytes = base58Encoder3.encode(putativeAddress);
|
|
650
|
+
const numBytes = bytes.byteLength;
|
|
651
|
+
if (numBytes !== 32) {
|
|
652
|
+
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
653
|
+
}
|
|
654
|
+
} catch (e3) {
|
|
655
|
+
throw new Error(`\`${putativeAddress}\` is not a base-58 encoded address`, {
|
|
656
|
+
cause: e3
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
function address(putativeAddress) {
|
|
661
|
+
assertIsAddress(putativeAddress);
|
|
662
|
+
return putativeAddress;
|
|
663
|
+
}
|
|
664
|
+
function getAddressEncoder() {
|
|
665
|
+
return mapEncoder(
|
|
666
|
+
getStringEncoder({ encoding: getMemoizedBase58Encoder(), size: 32 }),
|
|
667
|
+
(putativeAddress) => address(putativeAddress)
|
|
668
|
+
);
|
|
669
|
+
}
|
|
670
|
+
function getAddressDecoder() {
|
|
671
|
+
return getStringDecoder({ encoding: getMemoizedBase58Decoder(), size: 32 });
|
|
672
|
+
}
|
|
673
|
+
function getAddressCodec() {
|
|
674
|
+
return combineCodec(getAddressEncoder(), getAddressDecoder());
|
|
675
|
+
}
|
|
676
|
+
function getAddressComparator() {
|
|
677
|
+
return new Intl.Collator("en", {
|
|
678
|
+
caseFirst: "lower",
|
|
679
|
+
ignorePunctuation: false,
|
|
680
|
+
localeMatcher: "best fit",
|
|
681
|
+
numeric: false,
|
|
682
|
+
sensitivity: "variant",
|
|
683
|
+
usage: "sort"
|
|
684
|
+
}).compare;
|
|
685
|
+
}
|
|
686
|
+
var D = 37095705934669439343138083508754565189542113879843219016388785533085940283555n;
|
|
687
|
+
var P = 57896044618658097711785492504343953926634992332820282019728792003956564819949n;
|
|
688
|
+
var RM1 = 19681161376707505956807079304988542015446066515923890162744021073123829784752n;
|
|
689
|
+
function mod(a) {
|
|
690
|
+
const r = a % P;
|
|
691
|
+
return r >= 0n ? r : P + r;
|
|
692
|
+
}
|
|
693
|
+
function pow2(x, power) {
|
|
694
|
+
let r = x;
|
|
695
|
+
while (power-- > 0n) {
|
|
696
|
+
r *= r;
|
|
697
|
+
r %= P;
|
|
698
|
+
}
|
|
699
|
+
return r;
|
|
700
|
+
}
|
|
701
|
+
function pow_2_252_3(x) {
|
|
702
|
+
const x2 = x * x % P;
|
|
703
|
+
const b2 = x2 * x % P;
|
|
704
|
+
const b4 = pow2(b2, 2n) * b2 % P;
|
|
705
|
+
const b5 = pow2(b4, 1n) * x % P;
|
|
706
|
+
const b10 = pow2(b5, 5n) * b5 % P;
|
|
707
|
+
const b20 = pow2(b10, 10n) * b10 % P;
|
|
708
|
+
const b40 = pow2(b20, 20n) * b20 % P;
|
|
709
|
+
const b80 = pow2(b40, 40n) * b40 % P;
|
|
710
|
+
const b160 = pow2(b80, 80n) * b80 % P;
|
|
711
|
+
const b240 = pow2(b160, 80n) * b80 % P;
|
|
712
|
+
const b250 = pow2(b240, 10n) * b10 % P;
|
|
713
|
+
const pow_p_5_8 = pow2(b250, 2n) * x % P;
|
|
714
|
+
return pow_p_5_8;
|
|
715
|
+
}
|
|
716
|
+
function uvRatio(u, v) {
|
|
717
|
+
const v3 = mod(v * v * v);
|
|
718
|
+
const v7 = mod(v3 * v3 * v);
|
|
719
|
+
const pow = pow_2_252_3(u * v7);
|
|
720
|
+
let x = mod(u * v3 * pow);
|
|
721
|
+
const vx2 = mod(v * x * x);
|
|
722
|
+
const root1 = x;
|
|
723
|
+
const root2 = mod(x * RM1);
|
|
724
|
+
const useRoot1 = vx2 === u;
|
|
725
|
+
const useRoot2 = vx2 === mod(-u);
|
|
726
|
+
const noRoot = vx2 === mod(-u * RM1);
|
|
727
|
+
if (useRoot1)
|
|
728
|
+
x = root1;
|
|
729
|
+
if (useRoot2 || noRoot)
|
|
730
|
+
x = root2;
|
|
731
|
+
if ((mod(x) & 1n) === 1n)
|
|
732
|
+
x = mod(-x);
|
|
733
|
+
if (!useRoot1 && !useRoot2) {
|
|
734
|
+
return null;
|
|
735
|
+
}
|
|
736
|
+
return x;
|
|
737
|
+
}
|
|
738
|
+
function pointIsOnCurve(y, lastByte) {
|
|
739
|
+
const y2 = mod(y * y);
|
|
740
|
+
const u = mod(y2 - 1n);
|
|
741
|
+
const v = mod(D * y2 + 1n);
|
|
742
|
+
const x = uvRatio(u, v);
|
|
743
|
+
if (x === null) {
|
|
744
|
+
return false;
|
|
745
|
+
}
|
|
746
|
+
const isLastByteOdd = (lastByte & 128) !== 0;
|
|
747
|
+
if (x === 0n && isLastByteOdd) {
|
|
748
|
+
return false;
|
|
749
|
+
}
|
|
750
|
+
return true;
|
|
751
|
+
}
|
|
752
|
+
function byteToHex(byte) {
|
|
753
|
+
const hexString = byte.toString(16);
|
|
754
|
+
if (hexString.length === 1) {
|
|
755
|
+
return `0${hexString}`;
|
|
756
|
+
} else {
|
|
757
|
+
return hexString;
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
function decompressPointBytes(bytes) {
|
|
761
|
+
const hexString = bytes.reduce((acc, byte, ii) => `${byteToHex(ii === 31 ? byte & ~128 : byte)}${acc}`, "");
|
|
762
|
+
const integerLiteralString = `0x${hexString}`;
|
|
763
|
+
return BigInt(integerLiteralString);
|
|
764
|
+
}
|
|
765
|
+
async function compressedPointBytesAreOnCurve(bytes) {
|
|
766
|
+
if (bytes.byteLength !== 32) {
|
|
767
|
+
return false;
|
|
768
|
+
}
|
|
769
|
+
const y = decompressPointBytes(bytes);
|
|
770
|
+
return pointIsOnCurve(y, bytes[31]);
|
|
771
|
+
}
|
|
772
|
+
function isProgramDerivedAddress(value) {
|
|
773
|
+
return Array.isArray(value) && value.length === 2 && typeof value[0] === "string" && typeof value[1] === "number" && value[1] >= 0 && value[1] <= 255 && isAddress(value[0]);
|
|
774
|
+
}
|
|
775
|
+
function assertIsProgramDerivedAddress(value) {
|
|
776
|
+
const validFormat = Array.isArray(value) && value.length === 2 && typeof value[0] === "string" && typeof value[1] === "number";
|
|
777
|
+
if (!validFormat) {
|
|
778
|
+
throw new Error(
|
|
779
|
+
`Expected given program derived address to have the following format: [Address, ProgramDerivedAddressBump].`
|
|
780
|
+
);
|
|
781
|
+
}
|
|
782
|
+
if (value[1] < 0 || value[1] > 255) {
|
|
783
|
+
throw new Error(`Expected program derived address bump to be in the range [0, 255], got: ${value[1]}.`);
|
|
784
|
+
}
|
|
785
|
+
assertIsAddress(value[0]);
|
|
786
|
+
}
|
|
787
|
+
var MAX_SEED_LENGTH = 32;
|
|
788
|
+
var MAX_SEEDS = 16;
|
|
789
|
+
var PDA_MARKER_BYTES = [
|
|
790
|
+
// The string 'ProgramDerivedAddress'
|
|
791
|
+
80,
|
|
792
|
+
114,
|
|
793
|
+
111,
|
|
794
|
+
103,
|
|
795
|
+
114,
|
|
796
|
+
97,
|
|
797
|
+
109,
|
|
798
|
+
68,
|
|
799
|
+
101,
|
|
800
|
+
114,
|
|
801
|
+
105,
|
|
802
|
+
118,
|
|
803
|
+
101,
|
|
804
|
+
100,
|
|
805
|
+
65,
|
|
806
|
+
100,
|
|
807
|
+
100,
|
|
808
|
+
114,
|
|
809
|
+
101,
|
|
810
|
+
115,
|
|
811
|
+
115
|
|
812
|
+
];
|
|
813
|
+
var PointOnCurveError = class extends Error {
|
|
814
|
+
};
|
|
815
|
+
async function createProgramDerivedAddress({ programAddress, seeds }) {
|
|
816
|
+
await assertDigestCapabilityIsAvailable();
|
|
817
|
+
if (seeds.length > MAX_SEEDS) {
|
|
818
|
+
throw new Error(`A maximum of ${MAX_SEEDS} seeds may be supplied when creating an address`);
|
|
819
|
+
}
|
|
820
|
+
let textEncoder;
|
|
821
|
+
const seedBytes = seeds.reduce((acc, seed, ii) => {
|
|
822
|
+
const bytes = typeof seed === "string" ? (textEncoder || (textEncoder = new TextEncoder())).encode(seed) : seed;
|
|
823
|
+
if (bytes.byteLength > MAX_SEED_LENGTH) {
|
|
824
|
+
throw new Error(`The seed at index ${ii} exceeds the maximum length of 32 bytes`);
|
|
825
|
+
}
|
|
826
|
+
acc.push(...bytes);
|
|
827
|
+
return acc;
|
|
828
|
+
}, []);
|
|
829
|
+
const base58EncodedAddressCodec = getAddressCodec();
|
|
830
|
+
const programAddressBytes = base58EncodedAddressCodec.encode(programAddress);
|
|
831
|
+
const addressBytesBuffer = await crypto.subtle.digest(
|
|
832
|
+
"SHA-256",
|
|
833
|
+
new Uint8Array([...seedBytes, ...programAddressBytes, ...PDA_MARKER_BYTES])
|
|
834
|
+
);
|
|
835
|
+
const addressBytes = new Uint8Array(addressBytesBuffer);
|
|
836
|
+
if (await compressedPointBytesAreOnCurve(addressBytes)) {
|
|
837
|
+
throw new PointOnCurveError("Invalid seeds; point must fall off the Ed25519 curve");
|
|
838
|
+
}
|
|
839
|
+
return base58EncodedAddressCodec.decode(addressBytes);
|
|
840
|
+
}
|
|
841
|
+
async function getProgramDerivedAddress({
|
|
842
|
+
programAddress,
|
|
843
|
+
seeds
|
|
844
|
+
}) {
|
|
845
|
+
let bumpSeed = 255;
|
|
846
|
+
while (bumpSeed > 0) {
|
|
847
|
+
try {
|
|
848
|
+
const address2 = await createProgramDerivedAddress({
|
|
849
|
+
programAddress,
|
|
850
|
+
seeds: [...seeds, new Uint8Array([bumpSeed])]
|
|
851
|
+
});
|
|
852
|
+
return [address2, bumpSeed];
|
|
853
|
+
} catch (e3) {
|
|
854
|
+
if (e3 instanceof PointOnCurveError) {
|
|
855
|
+
bumpSeed--;
|
|
856
|
+
} else {
|
|
857
|
+
throw e3;
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
throw new Error("Unable to find a viable program address bump seed");
|
|
862
|
+
}
|
|
863
|
+
async function createAddressWithSeed({ baseAddress, programAddress, seed }) {
|
|
864
|
+
const { encode, decode } = getAddressCodec();
|
|
865
|
+
const seedBytes = typeof seed === "string" ? new TextEncoder().encode(seed) : seed;
|
|
866
|
+
if (seedBytes.byteLength > MAX_SEED_LENGTH) {
|
|
867
|
+
throw new Error(`The seed exceeds the maximum length of 32 bytes`);
|
|
868
|
+
}
|
|
869
|
+
const programAddressBytes = encode(programAddress);
|
|
870
|
+
if (programAddressBytes.length >= PDA_MARKER_BYTES.length && programAddressBytes.slice(-PDA_MARKER_BYTES.length).every((byte, index) => byte === PDA_MARKER_BYTES[index])) {
|
|
871
|
+
throw new Error(`programAddress cannot end with the PDA marker`);
|
|
872
|
+
}
|
|
873
|
+
const addressBytesBuffer = await crypto.subtle.digest(
|
|
874
|
+
"SHA-256",
|
|
875
|
+
new Uint8Array([...encode(baseAddress), ...seedBytes, ...programAddressBytes])
|
|
876
|
+
);
|
|
877
|
+
const addressBytes = new Uint8Array(addressBytesBuffer);
|
|
878
|
+
return decode(addressBytes);
|
|
879
|
+
}
|
|
880
|
+
async function getAddressFromPublicKey(publicKey) {
|
|
881
|
+
await assertKeyExporterIsAvailable();
|
|
882
|
+
if (publicKey.type !== "public" || publicKey.algorithm.name !== "Ed25519") {
|
|
883
|
+
throw new Error("The `CryptoKey` must be an `Ed25519` public key");
|
|
884
|
+
}
|
|
885
|
+
const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
|
|
886
|
+
return getAddressDecoder().decode(new Uint8Array(publicKeyBytes));
|
|
887
|
+
}
|
|
888
|
+
|
|
125
889
|
// ../instructions/dist/index.browser.js
|
|
126
890
|
init_env_shim();
|
|
127
|
-
var AccountRole = /* @__PURE__ */ ((
|
|
128
|
-
|
|
891
|
+
var AccountRole = /* @__PURE__ */ ((AccountRole22) => {
|
|
892
|
+
AccountRole22[AccountRole22["WRITABLE_SIGNER"] = /* 3 */
|
|
129
893
|
3] = "WRITABLE_SIGNER";
|
|
130
|
-
|
|
894
|
+
AccountRole22[AccountRole22["READONLY_SIGNER"] = /* 2 */
|
|
131
895
|
2] = "READONLY_SIGNER";
|
|
132
|
-
|
|
896
|
+
AccountRole22[AccountRole22["WRITABLE"] = /* 1 */
|
|
133
897
|
1] = "WRITABLE";
|
|
134
|
-
|
|
898
|
+
AccountRole22[AccountRole22["READONLY"] = /* 0 */
|
|
135
899
|
0] = "READONLY";
|
|
136
|
-
return
|
|
900
|
+
return AccountRole22;
|
|
137
901
|
})(AccountRole || {});
|
|
138
902
|
var IS_SIGNER_BITMASK = 2;
|
|
139
903
|
var IS_WRITABLE_BITMASK = 1;
|
|
@@ -161,327 +925,1462 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
161
925
|
|
|
162
926
|
// ../keys/dist/index.browser.js
|
|
163
927
|
init_env_shim();
|
|
928
|
+
async function generateKeyPair() {
|
|
929
|
+
await assertKeyGenerationIsAvailable();
|
|
930
|
+
const keyPair = await crypto.subtle.generateKey(
|
|
931
|
+
/* algorithm */
|
|
932
|
+
"Ed25519",
|
|
933
|
+
// Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20
|
|
934
|
+
/* extractable */
|
|
935
|
+
false,
|
|
936
|
+
// Prevents the bytes of the private key from being visible to JS.
|
|
937
|
+
/* allowed uses */
|
|
938
|
+
["sign", "verify"]
|
|
939
|
+
);
|
|
940
|
+
return keyPair;
|
|
941
|
+
}
|
|
942
|
+
function addPkcs8Header(bytes) {
|
|
943
|
+
return new Uint8Array([
|
|
944
|
+
/**
|
|
945
|
+
* PKCS#8 header
|
|
946
|
+
*/
|
|
947
|
+
48,
|
|
948
|
+
// ASN.1 sequence tag
|
|
949
|
+
46,
|
|
950
|
+
// Length of sequence (46 more bytes)
|
|
951
|
+
2,
|
|
952
|
+
// ASN.1 integer tag
|
|
953
|
+
1,
|
|
954
|
+
// Length of integer
|
|
955
|
+
0,
|
|
956
|
+
// Version number
|
|
957
|
+
48,
|
|
958
|
+
// ASN.1 sequence tag
|
|
959
|
+
5,
|
|
960
|
+
// Length of sequence
|
|
961
|
+
6,
|
|
962
|
+
// ASN.1 object identifier tag
|
|
963
|
+
3,
|
|
964
|
+
// Length of object identifier
|
|
965
|
+
// Edwards curve algorithms identifier https://oid-rep.orange-labs.fr/get/1.3.101.112
|
|
966
|
+
43,
|
|
967
|
+
// iso(1) / identified-organization(3) (The first node is multiplied by the decimal 40 and the result is added to the value of the second node)
|
|
968
|
+
101,
|
|
969
|
+
// thawte(101)
|
|
970
|
+
// Ed25519 identifier
|
|
971
|
+
112,
|
|
972
|
+
// id-Ed25519(112)
|
|
973
|
+
/**
|
|
974
|
+
* Private key payload
|
|
975
|
+
*/
|
|
976
|
+
4,
|
|
977
|
+
// ASN.1 octet string tag
|
|
978
|
+
34,
|
|
979
|
+
// String length (34 more bytes)
|
|
980
|
+
// Private key bytes as octet string
|
|
981
|
+
4,
|
|
982
|
+
// ASN.1 octet string tag
|
|
983
|
+
32,
|
|
984
|
+
// String length (32 bytes)
|
|
985
|
+
...bytes
|
|
986
|
+
]);
|
|
987
|
+
}
|
|
988
|
+
async function createPrivateKeyFromBytes(bytes, extractable) {
|
|
989
|
+
if (bytes.byteLength !== 32) {
|
|
990
|
+
throw new Error("Private key bytes must be of length 32");
|
|
991
|
+
}
|
|
992
|
+
const privateKeyBytesPkcs8 = addPkcs8Header(bytes);
|
|
993
|
+
return await crypto.subtle.importKey("pkcs8", privateKeyBytesPkcs8, "Ed25519", extractable != null ? extractable : false, ["sign"]);
|
|
994
|
+
}
|
|
995
|
+
var base58Encoder;
|
|
996
|
+
function assertIsSignature(putativeSignature) {
|
|
997
|
+
if (!base58Encoder)
|
|
998
|
+
base58Encoder = getBase58Encoder();
|
|
999
|
+
try {
|
|
1000
|
+
if (
|
|
1001
|
+
// Lowest value (64 bytes of zeroes)
|
|
1002
|
+
putativeSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
1003
|
+
putativeSignature.length > 88
|
|
1004
|
+
) {
|
|
1005
|
+
throw new Error("Expected input string to decode to a byte array of length 64.");
|
|
1006
|
+
}
|
|
1007
|
+
const bytes = base58Encoder.encode(putativeSignature);
|
|
1008
|
+
const numBytes = bytes.byteLength;
|
|
1009
|
+
if (numBytes !== 64) {
|
|
1010
|
+
throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
|
|
1011
|
+
}
|
|
1012
|
+
} catch (e3) {
|
|
1013
|
+
throw new Error(`\`${putativeSignature}\` is not a signature`, {
|
|
1014
|
+
cause: e3
|
|
1015
|
+
});
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
function isSignature(putativeSignature) {
|
|
1019
|
+
if (!base58Encoder)
|
|
1020
|
+
base58Encoder = getBase58Encoder();
|
|
1021
|
+
if (
|
|
1022
|
+
// Lowest value (64 bytes of zeroes)
|
|
1023
|
+
putativeSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
1024
|
+
putativeSignature.length > 88
|
|
1025
|
+
) {
|
|
1026
|
+
return false;
|
|
1027
|
+
}
|
|
1028
|
+
const bytes = base58Encoder.encode(putativeSignature);
|
|
1029
|
+
const numBytes = bytes.byteLength;
|
|
1030
|
+
if (numBytes !== 64) {
|
|
1031
|
+
return false;
|
|
1032
|
+
}
|
|
1033
|
+
return true;
|
|
1034
|
+
}
|
|
1035
|
+
async function signBytes(key, data) {
|
|
1036
|
+
await assertSigningCapabilityIsAvailable();
|
|
1037
|
+
const signedData = await crypto.subtle.sign("Ed25519", key, data);
|
|
1038
|
+
return new Uint8Array(signedData);
|
|
1039
|
+
}
|
|
1040
|
+
function signature(putativeSignature) {
|
|
1041
|
+
assertIsSignature(putativeSignature);
|
|
1042
|
+
return putativeSignature;
|
|
1043
|
+
}
|
|
1044
|
+
async function verifySignature(key, signature2, data) {
|
|
1045
|
+
await assertVerificationCapabilityIsAvailable();
|
|
1046
|
+
return await crypto.subtle.verify("Ed25519", key, signature2, data);
|
|
1047
|
+
}
|
|
164
1048
|
|
|
165
|
-
//
|
|
1049
|
+
// ../rpc-types/dist/index.browser.js
|
|
166
1050
|
init_env_shim();
|
|
1051
|
+
function getCommitmentScore(commitment) {
|
|
1052
|
+
switch (commitment) {
|
|
1053
|
+
case "finalized":
|
|
1054
|
+
return 2;
|
|
1055
|
+
case "confirmed":
|
|
1056
|
+
return 1;
|
|
1057
|
+
case "processed":
|
|
1058
|
+
return 0;
|
|
1059
|
+
default:
|
|
1060
|
+
return ((_) => {
|
|
1061
|
+
throw new Error(`Unrecognized commitment \`${commitment}\`.`);
|
|
1062
|
+
})();
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
function commitmentComparator(a, b) {
|
|
1066
|
+
if (a === b) {
|
|
1067
|
+
return 0;
|
|
1068
|
+
}
|
|
1069
|
+
return getCommitmentScore(a) < getCommitmentScore(b) ? -1 : 1;
|
|
1070
|
+
}
|
|
1071
|
+
var maxU64Value = 18446744073709551615n;
|
|
1072
|
+
function isLamports(putativeLamports) {
|
|
1073
|
+
return putativeLamports >= 0 && putativeLamports <= maxU64Value;
|
|
1074
|
+
}
|
|
1075
|
+
function assertIsLamports(putativeLamports) {
|
|
1076
|
+
if (putativeLamports < 0) {
|
|
1077
|
+
throw new Error("Input for 64-bit unsigned integer cannot be negative");
|
|
1078
|
+
}
|
|
1079
|
+
if (putativeLamports > maxU64Value) {
|
|
1080
|
+
throw new Error("Input number is too large to be represented as a 64-bit unsigned integer");
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
function lamports(putativeLamports) {
|
|
1084
|
+
assertIsLamports(putativeLamports);
|
|
1085
|
+
return putativeLamports;
|
|
1086
|
+
}
|
|
1087
|
+
function isStringifiedBigInt(putativeBigInt) {
|
|
1088
|
+
try {
|
|
1089
|
+
BigInt(putativeBigInt);
|
|
1090
|
+
return true;
|
|
1091
|
+
} catch (_) {
|
|
1092
|
+
return false;
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
function assertIsStringifiedBigInt(putativeBigInt) {
|
|
1096
|
+
try {
|
|
1097
|
+
BigInt(putativeBigInt);
|
|
1098
|
+
} catch (e3) {
|
|
1099
|
+
throw new Error(`\`${putativeBigInt}\` cannot be parsed as a BigInt`, {
|
|
1100
|
+
cause: e3
|
|
1101
|
+
});
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
function stringifiedBigInt(putativeBigInt) {
|
|
1105
|
+
assertIsStringifiedBigInt(putativeBigInt);
|
|
1106
|
+
return putativeBigInt;
|
|
1107
|
+
}
|
|
1108
|
+
function isStringifiedNumber(putativeNumber) {
|
|
1109
|
+
return !Number.isNaN(Number(putativeNumber));
|
|
1110
|
+
}
|
|
1111
|
+
function assertIsStringifiedNumber(putativeNumber) {
|
|
1112
|
+
if (Number.isNaN(Number(putativeNumber))) {
|
|
1113
|
+
throw new Error(`\`${putativeNumber}\` cannot be parsed as a Number`);
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
function stringifiedNumber(putativeNumber) {
|
|
1117
|
+
assertIsStringifiedNumber(putativeNumber);
|
|
1118
|
+
return putativeNumber;
|
|
1119
|
+
}
|
|
1120
|
+
function isUnixTimestamp(putativeTimestamp) {
|
|
1121
|
+
if (putativeTimestamp > 864e13 || putativeTimestamp < -864e13) {
|
|
1122
|
+
return false;
|
|
1123
|
+
}
|
|
1124
|
+
return true;
|
|
1125
|
+
}
|
|
1126
|
+
function assertIsUnixTimestamp(putativeTimestamp) {
|
|
1127
|
+
try {
|
|
1128
|
+
if (putativeTimestamp > 864e13 || putativeTimestamp < -864e13) {
|
|
1129
|
+
throw new Error("Expected input number to be in the range [-8.64e15, 8.64e15]");
|
|
1130
|
+
}
|
|
1131
|
+
} catch (e3) {
|
|
1132
|
+
throw new Error(`\`${putativeTimestamp}\` is not a timestamp`, {
|
|
1133
|
+
cause: e3
|
|
1134
|
+
});
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
function unixTimestamp(putativeTimestamp) {
|
|
1138
|
+
assertIsUnixTimestamp(putativeTimestamp);
|
|
1139
|
+
return putativeTimestamp;
|
|
1140
|
+
}
|
|
167
1141
|
|
|
168
|
-
//
|
|
1142
|
+
// ../transactions/dist/index.browser.js
|
|
169
1143
|
init_env_shim();
|
|
170
1144
|
|
|
171
|
-
//
|
|
1145
|
+
// ../codecs-data-structures/dist/index.browser.js
|
|
172
1146
|
init_env_shim();
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
1147
|
+
function assertValidNumberOfItemsForCodec(codecDescription, expected, actual) {
|
|
1148
|
+
if (expected !== actual) {
|
|
1149
|
+
throw new Error(`Expected [${codecDescription}] to have ${expected} items, got ${actual}.`);
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
function sumCodecSizes(sizes) {
|
|
1153
|
+
return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
|
|
1154
|
+
}
|
|
1155
|
+
function getFixedSize(codec) {
|
|
1156
|
+
return isFixedSize(codec) ? codec.fixedSize : null;
|
|
1157
|
+
}
|
|
1158
|
+
function getMaxSize(codec) {
|
|
1159
|
+
var _a;
|
|
1160
|
+
return isFixedSize(codec) ? codec.fixedSize : (_a = codec.maxSize) != null ? _a : null;
|
|
1161
|
+
}
|
|
1162
|
+
function getArrayEncoder(item, config = {}) {
|
|
1163
|
+
var _a, _b;
|
|
1164
|
+
const size = (_a = config.size) != null ? _a : getU32Encoder();
|
|
1165
|
+
if (size === "remainder") {
|
|
1166
|
+
assertIsFixedSize(item, 'Codecs of "remainder" size must have fixed-size items.');
|
|
1167
|
+
}
|
|
1168
|
+
const fixedSize = computeArrayLikeCodecSize(size, getFixedSize(item));
|
|
1169
|
+
const maxSize = (_b = computeArrayLikeCodecSize(size, getMaxSize(item))) != null ? _b : void 0;
|
|
1170
|
+
return createEncoder({
|
|
1171
|
+
...fixedSize !== null ? { fixedSize } : {
|
|
1172
|
+
getSizeFromValue: (array) => {
|
|
1173
|
+
const prefixSize = typeof size === "object" ? getEncodedSize(array.length, size) : 0;
|
|
1174
|
+
return prefixSize + [...array].reduce((all, value) => all + getEncodedSize(value, item), 0);
|
|
1175
|
+
},
|
|
1176
|
+
maxSize
|
|
1177
|
+
},
|
|
1178
|
+
write: (array, bytes, offset) => {
|
|
1179
|
+
if (typeof size === "number") {
|
|
1180
|
+
assertValidNumberOfItemsForCodec("array", size, array.length);
|
|
1181
|
+
}
|
|
1182
|
+
if (typeof size === "object") {
|
|
1183
|
+
offset = size.write(array.length, bytes, offset);
|
|
1184
|
+
}
|
|
1185
|
+
array.forEach((value) => {
|
|
1186
|
+
offset = item.write(value, bytes, offset);
|
|
1187
|
+
});
|
|
1188
|
+
return offset;
|
|
1189
|
+
}
|
|
180
1190
|
});
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
1191
|
+
}
|
|
1192
|
+
function getArrayDecoder(item, config = {}) {
|
|
1193
|
+
var _a, _b;
|
|
1194
|
+
const size = (_a = config.size) != null ? _a : getU32Decoder();
|
|
1195
|
+
if (size === "remainder") {
|
|
1196
|
+
assertIsFixedSize(item, 'Codecs of "remainder" size must have fixed-size items.');
|
|
1197
|
+
}
|
|
1198
|
+
const itemSize = getFixedSize(item);
|
|
1199
|
+
const fixedSize = computeArrayLikeCodecSize(size, itemSize);
|
|
1200
|
+
const maxSize = (_b = computeArrayLikeCodecSize(size, getMaxSize(item))) != null ? _b : void 0;
|
|
1201
|
+
return createDecoder({
|
|
1202
|
+
...fixedSize !== null ? { fixedSize } : { maxSize },
|
|
1203
|
+
read: (bytes, offset) => {
|
|
1204
|
+
const array = [];
|
|
1205
|
+
if (typeof size === "object" && bytes.slice(offset).length === 0) {
|
|
1206
|
+
return [array, offset];
|
|
1207
|
+
}
|
|
1208
|
+
const [resolvedSize, newOffset] = readArrayLikeCodecSize(size, itemSize, bytes, offset);
|
|
1209
|
+
offset = newOffset;
|
|
1210
|
+
for (let i = 0; i < resolvedSize; i += 1) {
|
|
1211
|
+
const [value, newOffset2] = item.read(bytes, offset);
|
|
1212
|
+
offset = newOffset2;
|
|
1213
|
+
array.push(value);
|
|
1214
|
+
}
|
|
1215
|
+
return [array, offset];
|
|
1216
|
+
}
|
|
1217
|
+
});
|
|
1218
|
+
}
|
|
1219
|
+
function readArrayLikeCodecSize(size, itemSize, bytes, offset) {
|
|
1220
|
+
if (typeof size === "number") {
|
|
1221
|
+
return [size, offset];
|
|
1222
|
+
}
|
|
1223
|
+
if (typeof size === "object") {
|
|
1224
|
+
return size.read(bytes, offset);
|
|
1225
|
+
}
|
|
1226
|
+
if (size === "remainder") {
|
|
1227
|
+
if (itemSize === null) {
|
|
1228
|
+
throw new Error('Codecs of "remainder" size must have fixed-size items.');
|
|
1229
|
+
}
|
|
1230
|
+
const remainder = Math.max(0, bytes.length - offset);
|
|
1231
|
+
if (remainder % itemSize !== 0) {
|
|
1232
|
+
throw new Error(
|
|
1233
|
+
`The remainder of the byte array (${remainder} bytes) cannot be split into chunks of ${itemSize} bytes. Codecs of "remainder" size must have a remainder that is a multiple of its item size. In other words, ${remainder} modulo ${itemSize} should be equal to zero.`
|
|
1234
|
+
);
|
|
1235
|
+
}
|
|
1236
|
+
return [remainder / itemSize, offset];
|
|
1237
|
+
}
|
|
1238
|
+
throw new Error(`Unrecognized array-like codec size: ${JSON.stringify(size)}`);
|
|
1239
|
+
}
|
|
1240
|
+
function computeArrayLikeCodecSize(size, itemSize) {
|
|
1241
|
+
if (typeof size !== "number")
|
|
1242
|
+
return null;
|
|
1243
|
+
if (size === 0)
|
|
1244
|
+
return 0;
|
|
1245
|
+
return itemSize === null ? null : itemSize * size;
|
|
1246
|
+
}
|
|
1247
|
+
function getBytesEncoder(config = {}) {
|
|
1248
|
+
var _a;
|
|
1249
|
+
const size = (_a = config.size) != null ? _a : "variable";
|
|
1250
|
+
const byteEncoder = createEncoder({
|
|
1251
|
+
getSizeFromValue: (value) => value.length,
|
|
1252
|
+
write: (value, bytes, offset) => {
|
|
1253
|
+
bytes.set(value, offset);
|
|
1254
|
+
return offset + value.length;
|
|
1255
|
+
}
|
|
1256
|
+
});
|
|
1257
|
+
if (size === "variable") {
|
|
1258
|
+
return byteEncoder;
|
|
1259
|
+
}
|
|
1260
|
+
if (typeof size === "number") {
|
|
1261
|
+
return fixEncoder(byteEncoder, size);
|
|
1262
|
+
}
|
|
1263
|
+
return createEncoder({
|
|
1264
|
+
getSizeFromValue: (value) => getEncodedSize(value.length, size) + value.length,
|
|
1265
|
+
write: (value, bytes, offset) => {
|
|
1266
|
+
offset = size.write(value.length, bytes, offset);
|
|
1267
|
+
return byteEncoder.write(value, bytes, offset);
|
|
1268
|
+
}
|
|
1269
|
+
});
|
|
1270
|
+
}
|
|
1271
|
+
function getBytesDecoder(config = {}) {
|
|
1272
|
+
var _a;
|
|
1273
|
+
const size = (_a = config.size) != null ? _a : "variable";
|
|
1274
|
+
const byteDecoder = createDecoder({
|
|
1275
|
+
read: (bytes, offset) => {
|
|
1276
|
+
const slice = bytes.slice(offset);
|
|
1277
|
+
return [slice, offset + slice.length];
|
|
1278
|
+
}
|
|
1279
|
+
});
|
|
1280
|
+
if (size === "variable") {
|
|
1281
|
+
return byteDecoder;
|
|
1282
|
+
}
|
|
1283
|
+
if (typeof size === "number") {
|
|
1284
|
+
return fixDecoder(byteDecoder, size);
|
|
1285
|
+
}
|
|
1286
|
+
return createDecoder({
|
|
1287
|
+
read: (bytes, offset) => {
|
|
1288
|
+
assertByteArrayIsNotEmptyForCodec("bytes", bytes, offset);
|
|
1289
|
+
const [lengthBigInt, lengthOffset] = size.read(bytes, offset);
|
|
1290
|
+
const length = Number(lengthBigInt);
|
|
1291
|
+
offset = lengthOffset;
|
|
1292
|
+
const contentBytes = bytes.slice(offset, offset + length);
|
|
1293
|
+
assertByteArrayHasEnoughBytesForCodec("bytes", length, contentBytes);
|
|
1294
|
+
const [value, contentOffset] = byteDecoder.read(contentBytes, 0);
|
|
1295
|
+
offset += contentOffset;
|
|
1296
|
+
return [value, offset];
|
|
1297
|
+
}
|
|
1298
|
+
});
|
|
1299
|
+
}
|
|
1300
|
+
function getStructEncoder(fields) {
|
|
1301
|
+
var _a;
|
|
1302
|
+
const fieldCodecs = fields.map(([, codec]) => codec);
|
|
1303
|
+
const fixedSize = sumCodecSizes(fieldCodecs.map(getFixedSize));
|
|
1304
|
+
const maxSize = (_a = sumCodecSizes(fieldCodecs.map(getMaxSize))) != null ? _a : void 0;
|
|
1305
|
+
return createEncoder({
|
|
1306
|
+
...fixedSize === null ? {
|
|
1307
|
+
getSizeFromValue: (value) => fields.map(([key, codec]) => getEncodedSize(value[key], codec)).reduce((all, one) => all + one, 0),
|
|
1308
|
+
maxSize
|
|
1309
|
+
} : { fixedSize },
|
|
1310
|
+
write: (struct, bytes, offset) => {
|
|
1311
|
+
fields.forEach(([key, codec]) => {
|
|
1312
|
+
offset = codec.write(struct[key], bytes, offset);
|
|
1313
|
+
});
|
|
1314
|
+
return offset;
|
|
1315
|
+
}
|
|
1316
|
+
});
|
|
1317
|
+
}
|
|
1318
|
+
function getStructDecoder(fields) {
|
|
1319
|
+
var _a;
|
|
1320
|
+
const fieldCodecs = fields.map(([, codec]) => codec);
|
|
1321
|
+
const fixedSize = sumCodecSizes(fieldCodecs.map(getFixedSize));
|
|
1322
|
+
const maxSize = (_a = sumCodecSizes(fieldCodecs.map(getMaxSize))) != null ? _a : void 0;
|
|
1323
|
+
return createDecoder({
|
|
1324
|
+
...fixedSize === null ? { maxSize } : { fixedSize },
|
|
1325
|
+
read: (bytes, offset) => {
|
|
1326
|
+
const struct = {};
|
|
1327
|
+
fields.forEach(([key, codec]) => {
|
|
1328
|
+
const [value, newOffset] = codec.read(bytes, offset);
|
|
1329
|
+
offset = newOffset;
|
|
1330
|
+
struct[key] = value;
|
|
1331
|
+
});
|
|
1332
|
+
return [struct, offset];
|
|
1333
|
+
}
|
|
1334
|
+
});
|
|
1335
|
+
}
|
|
191
1336
|
|
|
192
|
-
//
|
|
1337
|
+
// ../functional/dist/index.browser.js
|
|
193
1338
|
init_env_shim();
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
1339
|
+
function pipe(init, ...fns) {
|
|
1340
|
+
return fns.reduce((acc, fn) => fn(acc), init);
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
// ../transactions/dist/index.browser.js
|
|
1344
|
+
function getUnsignedTransaction(transaction) {
|
|
1345
|
+
if ("signatures" in transaction) {
|
|
1346
|
+
const {
|
|
1347
|
+
signatures: _,
|
|
1348
|
+
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
1349
|
+
...unsignedTransaction
|
|
1350
|
+
} = transaction;
|
|
1351
|
+
return unsignedTransaction;
|
|
1352
|
+
} else {
|
|
1353
|
+
return transaction;
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
var base58Encoder2;
|
|
1357
|
+
function assertIsBlockhash(putativeBlockhash) {
|
|
1358
|
+
if (!base58Encoder2)
|
|
1359
|
+
base58Encoder2 = getBase58Encoder();
|
|
1360
|
+
try {
|
|
1361
|
+
if (
|
|
1362
|
+
// Lowest value (32 bytes of zeroes)
|
|
1363
|
+
putativeBlockhash.length < 32 || // Highest value (32 bytes of 255)
|
|
1364
|
+
putativeBlockhash.length > 44
|
|
1365
|
+
) {
|
|
1366
|
+
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
1367
|
+
}
|
|
1368
|
+
const bytes = base58Encoder2.encode(putativeBlockhash);
|
|
1369
|
+
const numBytes = bytes.byteLength;
|
|
1370
|
+
if (numBytes !== 32) {
|
|
1371
|
+
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
1372
|
+
}
|
|
1373
|
+
} catch (e3) {
|
|
1374
|
+
throw new Error(`\`${putativeBlockhash}\` is not a blockhash`, {
|
|
1375
|
+
cause: e3
|
|
1376
|
+
});
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
function isTransactionWithBlockhashLifetime(transaction) {
|
|
1380
|
+
const lifetimeConstraintShapeMatches = "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.blockhash === "string" && typeof transaction.lifetimeConstraint.lastValidBlockHeight === "bigint";
|
|
1381
|
+
if (!lifetimeConstraintShapeMatches)
|
|
1382
|
+
return false;
|
|
1383
|
+
try {
|
|
1384
|
+
assertIsBlockhash(transaction.lifetimeConstraint.blockhash);
|
|
1385
|
+
return true;
|
|
1386
|
+
} catch {
|
|
1387
|
+
return false;
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
function assertIsTransactionWithBlockhashLifetime(transaction) {
|
|
1391
|
+
if (!isTransactionWithBlockhashLifetime(transaction)) {
|
|
1392
|
+
throw new Error("Transaction does not have a blockhash lifetime");
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) {
|
|
1396
|
+
if ("lifetimeConstraint" in transaction && transaction.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transaction.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
|
|
1397
|
+
return transaction;
|
|
1398
|
+
}
|
|
1399
|
+
const out = {
|
|
1400
|
+
...getUnsignedTransaction(transaction),
|
|
1401
|
+
lifetimeConstraint: blockhashLifetimeConstraint
|
|
1402
|
+
};
|
|
1403
|
+
Object.freeze(out);
|
|
1404
|
+
return out;
|
|
1405
|
+
}
|
|
1406
|
+
function createTransaction({
|
|
1407
|
+
version
|
|
1408
|
+
}) {
|
|
1409
|
+
const out = {
|
|
1410
|
+
instructions: [],
|
|
1411
|
+
version
|
|
1412
|
+
};
|
|
1413
|
+
Object.freeze(out);
|
|
1414
|
+
return out;
|
|
1415
|
+
}
|
|
1416
|
+
var AccountRole2 = /* @__PURE__ */ ((AccountRole22) => {
|
|
1417
|
+
AccountRole22[AccountRole22["WRITABLE_SIGNER"] = /* 3 */
|
|
1418
|
+
3] = "WRITABLE_SIGNER";
|
|
1419
|
+
AccountRole22[AccountRole22["READONLY_SIGNER"] = /* 2 */
|
|
1420
|
+
2] = "READONLY_SIGNER";
|
|
1421
|
+
AccountRole22[AccountRole22["WRITABLE"] = /* 1 */
|
|
1422
|
+
1] = "WRITABLE";
|
|
1423
|
+
AccountRole22[AccountRole22["READONLY"] = /* 0 */
|
|
1424
|
+
0] = "READONLY";
|
|
1425
|
+
return AccountRole22;
|
|
1426
|
+
})(AccountRole2 || {});
|
|
1427
|
+
var IS_WRITABLE_BITMASK2 = 1;
|
|
1428
|
+
function isSignerRole2(role) {
|
|
1429
|
+
return role >= 2;
|
|
1430
|
+
}
|
|
1431
|
+
function isWritableRole2(role) {
|
|
1432
|
+
return (role & IS_WRITABLE_BITMASK2) !== 0;
|
|
1433
|
+
}
|
|
1434
|
+
function mergeRoles2(roleA, roleB) {
|
|
1435
|
+
return roleA | roleB;
|
|
1436
|
+
}
|
|
1437
|
+
var RECENT_BLOCKHASHES_SYSVAR_ADDRESS = "SysvarRecentB1ockHashes11111111111111111111";
|
|
1438
|
+
var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
|
|
1439
|
+
function assertIsDurableNonceTransaction(transaction) {
|
|
1440
|
+
if (!isDurableNonceTransaction(transaction)) {
|
|
1441
|
+
throw new Error("Transaction is not a durable nonce transaction");
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
function createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress) {
|
|
1445
|
+
return {
|
|
1446
|
+
accounts: [
|
|
1447
|
+
{ address: nonceAccountAddress, role: AccountRole2.WRITABLE },
|
|
1448
|
+
{
|
|
1449
|
+
address: RECENT_BLOCKHASHES_SYSVAR_ADDRESS,
|
|
1450
|
+
role: AccountRole2.READONLY
|
|
1451
|
+
},
|
|
1452
|
+
{ address: nonceAuthorityAddress, role: AccountRole2.READONLY_SIGNER }
|
|
1453
|
+
],
|
|
1454
|
+
data: new Uint8Array([4, 0, 0, 0]),
|
|
1455
|
+
programAddress: SYSTEM_PROGRAM_ADDRESS
|
|
1456
|
+
};
|
|
1457
|
+
}
|
|
1458
|
+
function isAdvanceNonceAccountInstruction(instruction) {
|
|
1459
|
+
var _a;
|
|
1460
|
+
return instruction.programAddress === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data
|
|
1461
|
+
instruction.data != null && isAdvanceNonceAccountInstructionData(instruction.data) && // Test for exactly 3 accounts
|
|
1462
|
+
((_a = instruction.accounts) == null ? void 0 : _a.length) === 3 && // First account is nonce account address
|
|
1463
|
+
instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole2.WRITABLE && // Second account is recent blockhashes sysvar
|
|
1464
|
+
instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole2.READONLY && // Third account is nonce authority account
|
|
1465
|
+
instruction.accounts[2].address != null && isSignerRole2(instruction.accounts[2].role);
|
|
1466
|
+
}
|
|
1467
|
+
function isAdvanceNonceAccountInstructionData(data) {
|
|
1468
|
+
return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;
|
|
1469
|
+
}
|
|
1470
|
+
function isDurableNonceTransaction(transaction) {
|
|
1471
|
+
return "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.nonce === "string" && transaction.instructions[0] != null && isAdvanceNonceAccountInstruction(transaction.instructions[0]);
|
|
1472
|
+
}
|
|
1473
|
+
function isAdvanceNonceAccountInstructionForNonce(instruction, nonceAccountAddress, nonceAuthorityAddress) {
|
|
1474
|
+
return instruction.accounts[0].address === nonceAccountAddress && instruction.accounts[2].address === nonceAuthorityAddress;
|
|
1475
|
+
}
|
|
1476
|
+
function setTransactionLifetimeUsingDurableNonce({
|
|
1477
|
+
nonce,
|
|
1478
|
+
nonceAccountAddress,
|
|
1479
|
+
nonceAuthorityAddress
|
|
1480
|
+
}, transaction) {
|
|
1481
|
+
let newInstructions;
|
|
1482
|
+
const firstInstruction = transaction.instructions[0];
|
|
1483
|
+
if (firstInstruction && isAdvanceNonceAccountInstruction(firstInstruction)) {
|
|
1484
|
+
if (isAdvanceNonceAccountInstructionForNonce(firstInstruction, nonceAccountAddress, nonceAuthorityAddress)) {
|
|
1485
|
+
if (isDurableNonceTransaction(transaction) && transaction.lifetimeConstraint.nonce === nonce) {
|
|
1486
|
+
return transaction;
|
|
1487
|
+
} else {
|
|
1488
|
+
newInstructions = [firstInstruction, ...transaction.instructions.slice(1)];
|
|
1489
|
+
}
|
|
1490
|
+
} else {
|
|
1491
|
+
newInstructions = [
|
|
1492
|
+
createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
|
|
1493
|
+
...transaction.instructions.slice(1)
|
|
1494
|
+
];
|
|
1495
|
+
}
|
|
1496
|
+
} else {
|
|
1497
|
+
newInstructions = [
|
|
1498
|
+
createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
|
|
1499
|
+
...transaction.instructions
|
|
1500
|
+
];
|
|
1501
|
+
}
|
|
1502
|
+
const out = {
|
|
1503
|
+
...getUnsignedTransaction(transaction),
|
|
1504
|
+
instructions: newInstructions,
|
|
1505
|
+
lifetimeConstraint: {
|
|
1506
|
+
nonce
|
|
1507
|
+
}
|
|
1508
|
+
};
|
|
1509
|
+
Object.freeze(out);
|
|
1510
|
+
return out;
|
|
1511
|
+
}
|
|
1512
|
+
function setTransactionFeePayer(feePayer, transaction) {
|
|
1513
|
+
if ("feePayer" in transaction && feePayer === transaction.feePayer) {
|
|
1514
|
+
return transaction;
|
|
1515
|
+
}
|
|
1516
|
+
const out = {
|
|
1517
|
+
...getUnsignedTransaction(transaction),
|
|
1518
|
+
feePayer
|
|
1519
|
+
};
|
|
1520
|
+
Object.freeze(out);
|
|
1521
|
+
return out;
|
|
1522
|
+
}
|
|
1523
|
+
function appendTransactionInstruction(instruction, transaction) {
|
|
1524
|
+
const out = {
|
|
1525
|
+
...getUnsignedTransaction(transaction),
|
|
1526
|
+
instructions: [...transaction.instructions, instruction]
|
|
1527
|
+
};
|
|
1528
|
+
Object.freeze(out);
|
|
1529
|
+
return out;
|
|
1530
|
+
}
|
|
1531
|
+
function prependTransactionInstruction(instruction, transaction) {
|
|
1532
|
+
const out = {
|
|
1533
|
+
...getUnsignedTransaction(transaction),
|
|
1534
|
+
instructions: [instruction, ...transaction.instructions]
|
|
1535
|
+
};
|
|
1536
|
+
Object.freeze(out);
|
|
1537
|
+
return out;
|
|
1538
|
+
}
|
|
1539
|
+
function upsert(addressMap, address2, update) {
|
|
1540
|
+
var _a;
|
|
1541
|
+
addressMap[address2] = update((_a = addressMap[address2]) != null ? _a : { role: AccountRole2.READONLY });
|
|
1542
|
+
}
|
|
1543
|
+
var TYPE = Symbol("AddressMapTypeProperty");
|
|
1544
|
+
function getAddressMapFromInstructions(feePayer, instructions) {
|
|
1545
|
+
const addressMap = {
|
|
1546
|
+
[feePayer]: { [TYPE]: 0, role: AccountRole2.WRITABLE_SIGNER }
|
|
1547
|
+
};
|
|
1548
|
+
const addressesOfInvokedPrograms = /* @__PURE__ */ new Set();
|
|
1549
|
+
for (const instruction of instructions) {
|
|
1550
|
+
upsert(addressMap, instruction.programAddress, (entry) => {
|
|
1551
|
+
addressesOfInvokedPrograms.add(instruction.programAddress);
|
|
1552
|
+
if (TYPE in entry) {
|
|
1553
|
+
if (isWritableRole2(entry.role)) {
|
|
1554
|
+
switch (entry[TYPE]) {
|
|
1555
|
+
case 0:
|
|
1556
|
+
throw new Error(
|
|
1557
|
+
`This transaction includes an address (\`${instruction.programAddress}\`) which is both invoked and set as the fee payer. Program addresses may not pay fees.`
|
|
1558
|
+
);
|
|
1559
|
+
default:
|
|
1560
|
+
throw new Error(
|
|
1561
|
+
`This transaction includes an address (\`${instruction.programAddress}\`) which is both invoked and marked writable. Program addresses may not be writable.`
|
|
1562
|
+
);
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
if (entry[TYPE] === 2) {
|
|
1566
|
+
return entry;
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1569
|
+
return { [TYPE]: 2, role: AccountRole2.READONLY };
|
|
1570
|
+
});
|
|
1571
|
+
let addressComparator;
|
|
1572
|
+
if (!instruction.accounts) {
|
|
1573
|
+
continue;
|
|
1574
|
+
}
|
|
1575
|
+
for (const account of instruction.accounts) {
|
|
1576
|
+
upsert(addressMap, account.address, (entry) => {
|
|
1577
|
+
const {
|
|
1578
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1579
|
+
address: _,
|
|
1580
|
+
...accountMeta
|
|
1581
|
+
} = account;
|
|
1582
|
+
if (TYPE in entry) {
|
|
1583
|
+
switch (entry[TYPE]) {
|
|
1584
|
+
case 0:
|
|
1585
|
+
return entry;
|
|
1586
|
+
case 1: {
|
|
1587
|
+
const nextRole = mergeRoles2(entry.role, accountMeta.role);
|
|
1588
|
+
if ("lookupTableAddress" in accountMeta) {
|
|
1589
|
+
const shouldReplaceEntry = (
|
|
1590
|
+
// Consider using the new LOOKUP_TABLE if its address is different...
|
|
1591
|
+
entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
|
|
1592
|
+
(addressComparator || (addressComparator = getAddressComparator()))(
|
|
1593
|
+
accountMeta.lookupTableAddress,
|
|
1594
|
+
entry.lookupTableAddress
|
|
1595
|
+
) < 0
|
|
1596
|
+
);
|
|
1597
|
+
if (shouldReplaceEntry) {
|
|
1598
|
+
return {
|
|
1599
|
+
[TYPE]: 1,
|
|
1600
|
+
...accountMeta,
|
|
1601
|
+
role: nextRole
|
|
1602
|
+
};
|
|
1603
|
+
}
|
|
1604
|
+
} else if (isSignerRole2(accountMeta.role)) {
|
|
1605
|
+
return {
|
|
1606
|
+
[TYPE]: 2,
|
|
1607
|
+
role: nextRole
|
|
1608
|
+
};
|
|
1609
|
+
}
|
|
1610
|
+
if (entry.role !== nextRole) {
|
|
1611
|
+
return {
|
|
1612
|
+
...entry,
|
|
1613
|
+
role: nextRole
|
|
1614
|
+
};
|
|
1615
|
+
} else {
|
|
1616
|
+
return entry;
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
case 2: {
|
|
1620
|
+
const nextRole = mergeRoles2(entry.role, accountMeta.role);
|
|
1621
|
+
if (
|
|
1622
|
+
// Check to see if this address represents a program that is invoked
|
|
1623
|
+
// in this transaction.
|
|
1624
|
+
addressesOfInvokedPrograms.has(account.address)
|
|
1625
|
+
) {
|
|
1626
|
+
if (isWritableRole2(accountMeta.role)) {
|
|
1627
|
+
throw new Error(
|
|
1628
|
+
`This transaction includes an address (\`${account.address}\`) which is both invoked and marked writable. Program addresses may not be writable.`
|
|
1629
|
+
);
|
|
1630
|
+
}
|
|
1631
|
+
if (entry.role !== nextRole) {
|
|
1632
|
+
return {
|
|
1633
|
+
...entry,
|
|
1634
|
+
role: nextRole
|
|
1635
|
+
};
|
|
1636
|
+
} else {
|
|
1637
|
+
return entry;
|
|
1638
|
+
}
|
|
1639
|
+
} else if ("lookupTableAddress" in accountMeta && // Static accounts can be 'upgraded' to lookup table accounts as
|
|
1640
|
+
// long as they are not require to sign the transaction.
|
|
1641
|
+
!isSignerRole2(entry.role)) {
|
|
1642
|
+
return {
|
|
1643
|
+
...accountMeta,
|
|
1644
|
+
[TYPE]: 1,
|
|
1645
|
+
role: nextRole
|
|
1646
|
+
};
|
|
1647
|
+
} else {
|
|
1648
|
+
if (entry.role !== nextRole) {
|
|
1649
|
+
return {
|
|
1650
|
+
...entry,
|
|
1651
|
+
role: nextRole
|
|
1652
|
+
};
|
|
1653
|
+
} else {
|
|
1654
|
+
return entry;
|
|
1655
|
+
}
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
if ("lookupTableAddress" in accountMeta) {
|
|
1661
|
+
return {
|
|
1662
|
+
...accountMeta,
|
|
1663
|
+
[TYPE]: 1
|
|
1664
|
+
/* LOOKUP_TABLE */
|
|
1665
|
+
};
|
|
1666
|
+
} else {
|
|
1667
|
+
return {
|
|
1668
|
+
...accountMeta,
|
|
1669
|
+
[TYPE]: 2
|
|
1670
|
+
/* STATIC */
|
|
1671
|
+
};
|
|
1672
|
+
}
|
|
1673
|
+
});
|
|
1674
|
+
}
|
|
1675
|
+
}
|
|
1676
|
+
return addressMap;
|
|
1677
|
+
}
|
|
1678
|
+
function getOrderedAccountsFromAddressMap(addressMap) {
|
|
1679
|
+
let addressComparator;
|
|
1680
|
+
const orderedAccounts = Object.entries(addressMap).sort(([leftAddress, leftEntry], [rightAddress, rightEntry]) => {
|
|
1681
|
+
if (leftEntry[TYPE] !== rightEntry[TYPE]) {
|
|
1682
|
+
if (leftEntry[TYPE] === 0) {
|
|
1683
|
+
return -1;
|
|
1684
|
+
} else if (rightEntry[TYPE] === 0) {
|
|
1685
|
+
return 1;
|
|
1686
|
+
} else if (leftEntry[TYPE] === 2) {
|
|
1687
|
+
return -1;
|
|
1688
|
+
} else if (rightEntry[TYPE] === 2) {
|
|
1689
|
+
return 1;
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
const leftIsSigner = isSignerRole2(leftEntry.role);
|
|
1693
|
+
if (leftIsSigner !== isSignerRole2(rightEntry.role)) {
|
|
1694
|
+
return leftIsSigner ? -1 : 1;
|
|
1695
|
+
}
|
|
1696
|
+
const leftIsWritable = isWritableRole2(leftEntry.role);
|
|
1697
|
+
if (leftIsWritable !== isWritableRole2(rightEntry.role)) {
|
|
1698
|
+
return leftIsWritable ? -1 : 1;
|
|
1699
|
+
}
|
|
1700
|
+
addressComparator || (addressComparator = getAddressComparator());
|
|
1701
|
+
if (leftEntry[TYPE] === 1 && rightEntry[TYPE] === 1 && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
|
|
1702
|
+
return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
|
|
1703
|
+
} else {
|
|
1704
|
+
return addressComparator(leftAddress, rightAddress);
|
|
1705
|
+
}
|
|
1706
|
+
}).map(([address2, addressMeta]) => ({
|
|
1707
|
+
address: address2,
|
|
1708
|
+
...addressMeta
|
|
1709
|
+
}));
|
|
1710
|
+
return orderedAccounts;
|
|
1711
|
+
}
|
|
1712
|
+
function getCompiledAddressTableLookups(orderedAccounts) {
|
|
1713
|
+
var _a;
|
|
1714
|
+
const index = {};
|
|
1715
|
+
for (const account of orderedAccounts) {
|
|
1716
|
+
if (!("lookupTableAddress" in account)) {
|
|
1717
|
+
continue;
|
|
1718
|
+
}
|
|
1719
|
+
const entry = index[_a = account.lookupTableAddress] || (index[_a] = {
|
|
1720
|
+
readableIndices: [],
|
|
1721
|
+
writableIndices: []
|
|
1722
|
+
});
|
|
1723
|
+
if (account.role === AccountRole2.WRITABLE) {
|
|
1724
|
+
entry.writableIndices.push(account.addressIndex);
|
|
1725
|
+
} else {
|
|
1726
|
+
entry.readableIndices.push(account.addressIndex);
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1729
|
+
return Object.keys(index).sort(getAddressComparator()).map((lookupTableAddress) => ({
|
|
1730
|
+
lookupTableAddress,
|
|
1731
|
+
...index[lookupTableAddress]
|
|
1732
|
+
}));
|
|
1733
|
+
}
|
|
1734
|
+
function getCompiledMessageHeader(orderedAccounts) {
|
|
1735
|
+
let numReadonlyNonSignerAccounts = 0;
|
|
1736
|
+
let numReadonlySignerAccounts = 0;
|
|
1737
|
+
let numSignerAccounts = 0;
|
|
1738
|
+
for (const account of orderedAccounts) {
|
|
1739
|
+
if ("lookupTableAddress" in account) {
|
|
1740
|
+
break;
|
|
1741
|
+
}
|
|
1742
|
+
const accountIsWritable = isWritableRole2(account.role);
|
|
1743
|
+
if (isSignerRole2(account.role)) {
|
|
1744
|
+
numSignerAccounts++;
|
|
1745
|
+
if (!accountIsWritable) {
|
|
1746
|
+
numReadonlySignerAccounts++;
|
|
1747
|
+
}
|
|
1748
|
+
} else if (!accountIsWritable) {
|
|
1749
|
+
numReadonlyNonSignerAccounts++;
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
return {
|
|
1753
|
+
numReadonlyNonSignerAccounts,
|
|
1754
|
+
numReadonlySignerAccounts,
|
|
1755
|
+
numSignerAccounts
|
|
1756
|
+
};
|
|
1757
|
+
}
|
|
1758
|
+
function getAccountIndex(orderedAccounts) {
|
|
1759
|
+
const out = {};
|
|
1760
|
+
for (const [index, account] of orderedAccounts.entries()) {
|
|
1761
|
+
out[account.address] = index;
|
|
198
1762
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
1763
|
+
return out;
|
|
1764
|
+
}
|
|
1765
|
+
function getCompiledInstructions(instructions, orderedAccounts) {
|
|
1766
|
+
const accountIndex = getAccountIndex(orderedAccounts);
|
|
1767
|
+
return instructions.map(({ accounts, data, programAddress }) => {
|
|
1768
|
+
return {
|
|
1769
|
+
programAddressIndex: accountIndex[programAddress],
|
|
1770
|
+
...accounts ? { accountIndices: accounts.map(({ address: address2 }) => accountIndex[address2]) } : null,
|
|
1771
|
+
...data ? { data } : null
|
|
1772
|
+
};
|
|
1773
|
+
});
|
|
1774
|
+
}
|
|
1775
|
+
function getCompiledLifetimeToken(lifetimeConstraint) {
|
|
1776
|
+
if ("nonce" in lifetimeConstraint) {
|
|
1777
|
+
return lifetimeConstraint.nonce;
|
|
204
1778
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
1779
|
+
return lifetimeConstraint.blockhash;
|
|
1780
|
+
}
|
|
1781
|
+
function getCompiledStaticAccounts(orderedAccounts) {
|
|
1782
|
+
const firstLookupTableAccountIndex = orderedAccounts.findIndex((account) => "lookupTableAddress" in account);
|
|
1783
|
+
const orderedStaticAccounts = firstLookupTableAccountIndex === -1 ? orderedAccounts : orderedAccounts.slice(0, firstLookupTableAccountIndex);
|
|
1784
|
+
return orderedStaticAccounts.map(({ address: address2 }) => address2);
|
|
1785
|
+
}
|
|
1786
|
+
function compileMessage(transaction) {
|
|
1787
|
+
const addressMap = getAddressMapFromInstructions(transaction.feePayer, transaction.instructions);
|
|
1788
|
+
const orderedAccounts = getOrderedAccountsFromAddressMap(addressMap);
|
|
210
1789
|
return {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
1790
|
+
...transaction.version !== "legacy" ? { addressTableLookups: getCompiledAddressTableLookups(orderedAccounts) } : null,
|
|
1791
|
+
header: getCompiledMessageHeader(orderedAccounts),
|
|
1792
|
+
instructions: getCompiledInstructions(transaction.instructions, orderedAccounts),
|
|
1793
|
+
lifetimeToken: getCompiledLifetimeToken(transaction.lifetimeConstraint),
|
|
1794
|
+
staticAccounts: getCompiledStaticAccounts(orderedAccounts),
|
|
1795
|
+
version: transaction.version
|
|
1796
|
+
};
|
|
1797
|
+
}
|
|
1798
|
+
var memoizedAddressTableLookupEncoder;
|
|
1799
|
+
function getAddressTableLookupEncoder() {
|
|
1800
|
+
if (!memoizedAddressTableLookupEncoder) {
|
|
1801
|
+
memoizedAddressTableLookupEncoder = getStructEncoder([
|
|
1802
|
+
["lookupTableAddress", getAddressEncoder()],
|
|
1803
|
+
[
|
|
1804
|
+
"writableIndices",
|
|
1805
|
+
getArrayEncoder(getU8Encoder(), { size: getShortU16Encoder() })
|
|
1806
|
+
],
|
|
1807
|
+
[
|
|
1808
|
+
"readableIndices",
|
|
1809
|
+
getArrayEncoder(getU8Encoder(), { size: getShortU16Encoder() })
|
|
1810
|
+
]
|
|
1811
|
+
]);
|
|
1812
|
+
}
|
|
1813
|
+
return memoizedAddressTableLookupEncoder;
|
|
1814
|
+
}
|
|
1815
|
+
var memoizedAddressTableLookupDecoder;
|
|
1816
|
+
function getAddressTableLookupDecoder() {
|
|
1817
|
+
if (!memoizedAddressTableLookupDecoder) {
|
|
1818
|
+
memoizedAddressTableLookupDecoder = getStructDecoder([
|
|
1819
|
+
["lookupTableAddress", getAddressDecoder()],
|
|
1820
|
+
["writableIndices", getArrayDecoder(getU8Decoder(), { size: getShortU16Decoder() })],
|
|
1821
|
+
["readableIndices", getArrayDecoder(getU8Decoder(), { size: getShortU16Decoder() })]
|
|
1822
|
+
]);
|
|
1823
|
+
}
|
|
1824
|
+
return memoizedAddressTableLookupDecoder;
|
|
1825
|
+
}
|
|
1826
|
+
var memoizedU8Encoder;
|
|
1827
|
+
function getMemoizedU8Encoder() {
|
|
1828
|
+
if (!memoizedU8Encoder)
|
|
1829
|
+
memoizedU8Encoder = getU8Encoder();
|
|
1830
|
+
return memoizedU8Encoder;
|
|
1831
|
+
}
|
|
1832
|
+
var memoizedU8Decoder;
|
|
1833
|
+
function getMemoizedU8Decoder() {
|
|
1834
|
+
if (!memoizedU8Decoder)
|
|
1835
|
+
memoizedU8Decoder = getU8Decoder();
|
|
1836
|
+
return memoizedU8Decoder;
|
|
1837
|
+
}
|
|
1838
|
+
function getMessageHeaderEncoder() {
|
|
1839
|
+
return getStructEncoder([
|
|
1840
|
+
["numSignerAccounts", getMemoizedU8Encoder()],
|
|
1841
|
+
["numReadonlySignerAccounts", getMemoizedU8Encoder()],
|
|
1842
|
+
["numReadonlyNonSignerAccounts", getMemoizedU8Encoder()]
|
|
1843
|
+
]);
|
|
1844
|
+
}
|
|
1845
|
+
function getMessageHeaderDecoder() {
|
|
1846
|
+
return getStructDecoder([
|
|
1847
|
+
["numSignerAccounts", getMemoizedU8Decoder()],
|
|
1848
|
+
["numReadonlySignerAccounts", getMemoizedU8Decoder()],
|
|
1849
|
+
["numReadonlyNonSignerAccounts", getMemoizedU8Decoder()]
|
|
1850
|
+
]);
|
|
1851
|
+
}
|
|
1852
|
+
var memoizedGetInstructionEncoder;
|
|
1853
|
+
function getInstructionEncoder() {
|
|
1854
|
+
if (!memoizedGetInstructionEncoder) {
|
|
1855
|
+
memoizedGetInstructionEncoder = mapEncoder(
|
|
1856
|
+
getStructEncoder([
|
|
1857
|
+
["programAddressIndex", getU8Encoder()],
|
|
1858
|
+
["accountIndices", getArrayEncoder(getU8Encoder(), { size: getShortU16Encoder() })],
|
|
1859
|
+
["data", getBytesEncoder({ size: getShortU16Encoder() })]
|
|
1860
|
+
]),
|
|
1861
|
+
// Convert an instruction to have all fields defined
|
|
1862
|
+
(instruction) => {
|
|
1863
|
+
var _a, _b;
|
|
1864
|
+
if (instruction.accountIndices !== void 0 && instruction.data !== void 0) {
|
|
1865
|
+
return instruction;
|
|
1866
|
+
}
|
|
1867
|
+
return {
|
|
1868
|
+
...instruction,
|
|
1869
|
+
accountIndices: (_a = instruction.accountIndices) != null ? _a : [],
|
|
1870
|
+
data: (_b = instruction.data) != null ? _b : new Uint8Array(0)
|
|
1871
|
+
};
|
|
1872
|
+
}
|
|
1873
|
+
);
|
|
1874
|
+
}
|
|
1875
|
+
return memoizedGetInstructionEncoder;
|
|
1876
|
+
}
|
|
1877
|
+
var memoizedGetInstructionDecoder;
|
|
1878
|
+
function getInstructionDecoder() {
|
|
1879
|
+
if (!memoizedGetInstructionDecoder) {
|
|
1880
|
+
memoizedGetInstructionDecoder = mapDecoder(
|
|
1881
|
+
getStructDecoder([
|
|
1882
|
+
["programAddressIndex", getU8Decoder()],
|
|
1883
|
+
["accountIndices", getArrayDecoder(getU8Decoder(), { size: getShortU16Decoder() })],
|
|
1884
|
+
["data", getBytesDecoder({ size: getShortU16Decoder() })]
|
|
1885
|
+
]),
|
|
1886
|
+
// Convert an instruction to exclude optional fields if they are empty
|
|
1887
|
+
(instruction) => {
|
|
1888
|
+
if (instruction.accountIndices.length && instruction.data.byteLength) {
|
|
1889
|
+
return instruction;
|
|
1890
|
+
}
|
|
1891
|
+
const { accountIndices, data, ...rest } = instruction;
|
|
1892
|
+
return {
|
|
1893
|
+
...rest,
|
|
1894
|
+
...accountIndices.length ? { accountIndices } : null,
|
|
1895
|
+
...data.byteLength ? { data } : null
|
|
1896
|
+
};
|
|
1897
|
+
}
|
|
1898
|
+
);
|
|
1899
|
+
}
|
|
1900
|
+
return memoizedGetInstructionDecoder;
|
|
1901
|
+
}
|
|
1902
|
+
var VERSION_FLAG_MASK = 128;
|
|
1903
|
+
function getTransactionVersionEncoder() {
|
|
1904
|
+
return createEncoder({
|
|
1905
|
+
getSizeFromValue: (value) => value === "legacy" ? 0 : 1,
|
|
1906
|
+
maxSize: 1,
|
|
1907
|
+
write: (value, bytes, offset) => {
|
|
1908
|
+
if (value === "legacy") {
|
|
1909
|
+
return offset;
|
|
219
1910
|
}
|
|
220
|
-
if (
|
|
221
|
-
|
|
1911
|
+
if (value < 0 || value > 127) {
|
|
1912
|
+
throw new Error(`Transaction version must be in the range [0, 127]. \`${value}\` given.`);
|
|
222
1913
|
}
|
|
223
|
-
|
|
224
|
-
return
|
|
1914
|
+
bytes.set([value | VERSION_FLAG_MASK], offset);
|
|
1915
|
+
return offset + 1;
|
|
225
1916
|
}
|
|
226
|
-
};
|
|
1917
|
+
});
|
|
227
1918
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
constructor(value, base, cause) {
|
|
239
|
-
const message = `Expected a string of base ${base}, got [${value}].`;
|
|
240
|
-
super(message);
|
|
241
|
-
__publicField(this, "name", "InvalidBaseStringError");
|
|
242
|
-
this.cause = cause;
|
|
243
|
-
}
|
|
244
|
-
};
|
|
245
|
-
|
|
246
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/baseX.mjs
|
|
247
|
-
var baseX = (alphabet) => {
|
|
248
|
-
const base = alphabet.length;
|
|
249
|
-
const baseBigInt = BigInt(base);
|
|
250
|
-
return {
|
|
251
|
-
description: `base${base}`,
|
|
252
|
-
fixedSize: null,
|
|
253
|
-
maxSize: null,
|
|
254
|
-
serialize(value) {
|
|
255
|
-
if (!value.match(new RegExp(`^[${alphabet}]*$`))) {
|
|
256
|
-
throw new InvalidBaseStringError(value, base);
|
|
1919
|
+
function getTransactionVersionDecoder() {
|
|
1920
|
+
return createDecoder({
|
|
1921
|
+
maxSize: 1,
|
|
1922
|
+
read: (bytes, offset) => {
|
|
1923
|
+
const firstByte = bytes[offset];
|
|
1924
|
+
if ((firstByte & VERSION_FLAG_MASK) === 0) {
|
|
1925
|
+
return ["legacy", offset];
|
|
1926
|
+
} else {
|
|
1927
|
+
const version = firstByte ^ VERSION_FLAG_MASK;
|
|
1928
|
+
return [version, offset + 1];
|
|
257
1929
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
1930
|
+
}
|
|
1931
|
+
});
|
|
1932
|
+
}
|
|
1933
|
+
function getCompiledMessageLegacyEncoder() {
|
|
1934
|
+
return getStructEncoder(getPreludeStructEncoderTuple());
|
|
1935
|
+
}
|
|
1936
|
+
function getCompiledMessageVersionedEncoder() {
|
|
1937
|
+
return mapEncoder(
|
|
1938
|
+
getStructEncoder([
|
|
1939
|
+
...getPreludeStructEncoderTuple(),
|
|
1940
|
+
["addressTableLookups", getAddressTableLookupArrayEncoder()]
|
|
1941
|
+
]),
|
|
1942
|
+
(value) => {
|
|
1943
|
+
var _a;
|
|
1944
|
+
if (value.version === "legacy") {
|
|
1945
|
+
return value;
|
|
272
1946
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
1947
|
+
return {
|
|
1948
|
+
...value,
|
|
1949
|
+
addressTableLookups: (_a = value.addressTableLookups) != null ? _a : []
|
|
1950
|
+
};
|
|
1951
|
+
}
|
|
1952
|
+
);
|
|
1953
|
+
}
|
|
1954
|
+
function getPreludeStructEncoderTuple() {
|
|
1955
|
+
return [
|
|
1956
|
+
["version", getTransactionVersionEncoder()],
|
|
1957
|
+
["header", getMessageHeaderEncoder()],
|
|
1958
|
+
["staticAccounts", getArrayEncoder(getAddressEncoder(), { size: getShortU16Encoder() })],
|
|
1959
|
+
["lifetimeToken", getStringEncoder({ encoding: getBase58Encoder(), size: 32 })],
|
|
1960
|
+
["instructions", getArrayEncoder(getInstructionEncoder(), { size: getShortU16Encoder() })]
|
|
1961
|
+
];
|
|
1962
|
+
}
|
|
1963
|
+
function getPreludeStructDecoderTuple() {
|
|
1964
|
+
return [
|
|
1965
|
+
["version", getTransactionVersionDecoder()],
|
|
1966
|
+
["header", getMessageHeaderDecoder()],
|
|
1967
|
+
["staticAccounts", getArrayDecoder(getAddressDecoder(), { size: getShortU16Decoder() })],
|
|
1968
|
+
["lifetimeToken", getStringDecoder({ encoding: getBase58Decoder(), size: 32 })],
|
|
1969
|
+
["instructions", getArrayDecoder(getInstructionDecoder(), { size: getShortU16Decoder() })],
|
|
1970
|
+
["addressTableLookups", getAddressTableLookupArrayDecoder()]
|
|
1971
|
+
];
|
|
1972
|
+
}
|
|
1973
|
+
function getAddressTableLookupArrayEncoder() {
|
|
1974
|
+
return getArrayEncoder(getAddressTableLookupEncoder(), { size: getShortU16Encoder() });
|
|
1975
|
+
}
|
|
1976
|
+
function getAddressTableLookupArrayDecoder() {
|
|
1977
|
+
return getArrayDecoder(getAddressTableLookupDecoder(), { size: getShortU16Decoder() });
|
|
1978
|
+
}
|
|
1979
|
+
function getCompiledMessageEncoder() {
|
|
1980
|
+
return createEncoder({
|
|
1981
|
+
getSizeFromValue: (compiledMessage) => {
|
|
1982
|
+
if (compiledMessage.version === "legacy") {
|
|
1983
|
+
return getCompiledMessageLegacyEncoder().getSizeFromValue(compiledMessage);
|
|
1984
|
+
} else {
|
|
1985
|
+
return getCompiledMessageVersionedEncoder().getSizeFromValue(compiledMessage);
|
|
277
1986
|
}
|
|
278
|
-
return Uint8Array.from(leadingZeroes.concat(tailBytes));
|
|
279
1987
|
},
|
|
280
|
-
|
|
281
|
-
if (
|
|
282
|
-
return
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
trailIndex = trailIndex === -1 ? bytes.length : trailIndex;
|
|
286
|
-
const leadingZeroes = alphabet[0].repeat(trailIndex);
|
|
287
|
-
if (trailIndex === bytes.length)
|
|
288
|
-
return [leadingZeroes, buffer.length];
|
|
289
|
-
let base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
|
|
290
|
-
const tailChars = [];
|
|
291
|
-
while (base10Number > 0n) {
|
|
292
|
-
tailChars.unshift(alphabet[Number(base10Number % baseBigInt)]);
|
|
293
|
-
base10Number /= baseBigInt;
|
|
1988
|
+
write: (compiledMessage, bytes, offset) => {
|
|
1989
|
+
if (compiledMessage.version === "legacy") {
|
|
1990
|
+
return getCompiledMessageLegacyEncoder().write(compiledMessage, bytes, offset);
|
|
1991
|
+
} else {
|
|
1992
|
+
return getCompiledMessageVersionedEncoder().write(compiledMessage, bytes, offset);
|
|
294
1993
|
}
|
|
295
|
-
return [leadingZeroes + tailChars.join(""), buffer.length];
|
|
296
1994
|
}
|
|
1995
|
+
});
|
|
1996
|
+
}
|
|
1997
|
+
function getCompiledMessageDecoder() {
|
|
1998
|
+
return mapDecoder(getStructDecoder(getPreludeStructDecoderTuple()), ({ addressTableLookups, ...restOfMessage }) => {
|
|
1999
|
+
if (restOfMessage.version === "legacy" || !(addressTableLookups == null ? void 0 : addressTableLookups.length)) {
|
|
2000
|
+
return restOfMessage;
|
|
2001
|
+
}
|
|
2002
|
+
return { ...restOfMessage, addressTableLookups };
|
|
2003
|
+
});
|
|
2004
|
+
}
|
|
2005
|
+
function getCompiledMessageCodec() {
|
|
2006
|
+
return combineCodec(getCompiledMessageEncoder(), getCompiledMessageDecoder());
|
|
2007
|
+
}
|
|
2008
|
+
function getCompiledTransaction(transaction) {
|
|
2009
|
+
var _a;
|
|
2010
|
+
const compiledMessage = compileMessage(transaction);
|
|
2011
|
+
let signatures;
|
|
2012
|
+
if ("signatures" in transaction) {
|
|
2013
|
+
signatures = [];
|
|
2014
|
+
for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
|
|
2015
|
+
signatures[ii] = (_a = transaction.signatures[compiledMessage.staticAccounts[ii]]) != null ? _a : new Uint8Array(Array(64).fill(0));
|
|
2016
|
+
}
|
|
2017
|
+
} else {
|
|
2018
|
+
signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
|
|
2019
|
+
}
|
|
2020
|
+
return {
|
|
2021
|
+
compiledMessage,
|
|
2022
|
+
signatures
|
|
297
2023
|
};
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/utf8.mjs
|
|
312
|
-
init_env_shim();
|
|
313
|
-
var utf8 = {
|
|
314
|
-
description: "utf8",
|
|
315
|
-
fixedSize: null,
|
|
316
|
-
maxSize: null,
|
|
317
|
-
serialize(value) {
|
|
318
|
-
return new TextEncoder().encode(value);
|
|
319
|
-
},
|
|
320
|
-
deserialize(buffer, offset = 0) {
|
|
321
|
-
const value = new TextDecoder().decode(buffer.slice(offset));
|
|
322
|
-
return [removeNullCharacters(value), buffer.length];
|
|
2024
|
+
}
|
|
2025
|
+
function getAccountMetas(message) {
|
|
2026
|
+
const { header } = message;
|
|
2027
|
+
const numWritableSignerAccounts = header.numSignerAccounts - header.numReadonlySignerAccounts;
|
|
2028
|
+
const numWritableNonSignerAccounts = message.staticAccounts.length - header.numSignerAccounts - header.numReadonlyNonSignerAccounts;
|
|
2029
|
+
const accountMetas = [];
|
|
2030
|
+
let accountIndex = 0;
|
|
2031
|
+
for (let i = 0; i < numWritableSignerAccounts; i++) {
|
|
2032
|
+
accountMetas.push({
|
|
2033
|
+
address: message.staticAccounts[accountIndex],
|
|
2034
|
+
role: AccountRole2.WRITABLE_SIGNER
|
|
2035
|
+
});
|
|
2036
|
+
accountIndex++;
|
|
323
2037
|
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
init_env_shim();
|
|
331
|
-
var Endian;
|
|
332
|
-
(function(Endian2) {
|
|
333
|
-
Endian2["Little"] = "le";
|
|
334
|
-
Endian2["Big"] = "be";
|
|
335
|
-
})(Endian || (Endian = {}));
|
|
336
|
-
|
|
337
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/errors.mjs
|
|
338
|
-
init_env_shim();
|
|
339
|
-
var NumberOutOfRangeError = class extends RangeError {
|
|
340
|
-
constructor(serializer, min, max, actual) {
|
|
341
|
-
super(`Serializer [${serializer}] expected number to be between ${min} and ${max}, got ${actual}.`);
|
|
342
|
-
__publicField(this, "name", "NumberOutOfRangeError");
|
|
2038
|
+
for (let i = 0; i < header.numReadonlySignerAccounts; i++) {
|
|
2039
|
+
accountMetas.push({
|
|
2040
|
+
address: message.staticAccounts[accountIndex],
|
|
2041
|
+
role: AccountRole2.READONLY_SIGNER
|
|
2042
|
+
});
|
|
2043
|
+
accountIndex++;
|
|
343
2044
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
2045
|
+
for (let i = 0; i < numWritableNonSignerAccounts; i++) {
|
|
2046
|
+
accountMetas.push({
|
|
2047
|
+
address: message.staticAccounts[accountIndex],
|
|
2048
|
+
role: AccountRole2.WRITABLE
|
|
2049
|
+
});
|
|
2050
|
+
accountIndex++;
|
|
2051
|
+
}
|
|
2052
|
+
for (let i = 0; i < header.numReadonlyNonSignerAccounts; i++) {
|
|
2053
|
+
accountMetas.push({
|
|
2054
|
+
address: message.staticAccounts[accountIndex],
|
|
2055
|
+
role: AccountRole2.READONLY
|
|
2056
|
+
});
|
|
2057
|
+
accountIndex++;
|
|
2058
|
+
}
|
|
2059
|
+
return accountMetas;
|
|
2060
|
+
}
|
|
2061
|
+
function convertInstruction(instruction, accountMetas) {
|
|
2062
|
+
var _a, _b;
|
|
2063
|
+
const programAddress = (_a = accountMetas[instruction.programAddressIndex]) == null ? void 0 : _a.address;
|
|
2064
|
+
if (!programAddress) {
|
|
2065
|
+
throw new Error(`Could not find program address at index ${instruction.programAddressIndex}`);
|
|
354
2066
|
}
|
|
2067
|
+
const accounts = (_b = instruction.accountIndices) == null ? void 0 : _b.map((accountIndex) => accountMetas[accountIndex]);
|
|
2068
|
+
const { data } = instruction;
|
|
355
2069
|
return {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
serialize(value) {
|
|
360
|
-
if (input.range) {
|
|
361
|
-
assertRange(input.name, input.range[0], input.range[1], value);
|
|
362
|
-
}
|
|
363
|
-
const buffer = new ArrayBuffer(input.size);
|
|
364
|
-
input.set(new DataView(buffer), value, littleEndian);
|
|
365
|
-
return new Uint8Array(buffer);
|
|
366
|
-
},
|
|
367
|
-
deserialize(bytes, offset = 0) {
|
|
368
|
-
const slice = bytes.slice(offset, offset + input.size);
|
|
369
|
-
assertEnoughBytes("i8", slice, input.size);
|
|
370
|
-
const view = toDataView(slice);
|
|
371
|
-
return [input.get(view, littleEndian), offset + input.size];
|
|
372
|
-
}
|
|
2070
|
+
programAddress,
|
|
2071
|
+
...accounts && accounts.length ? { accounts } : {},
|
|
2072
|
+
...data && data.length ? { data } : {}
|
|
373
2073
|
};
|
|
374
2074
|
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
2075
|
+
function getLifetimeConstraint(messageLifetimeToken, firstInstruction, lastValidBlockHeight) {
|
|
2076
|
+
if (!firstInstruction || !isAdvanceNonceAccountInstruction(firstInstruction)) {
|
|
2077
|
+
return {
|
|
2078
|
+
blockhash: messageLifetimeToken,
|
|
2079
|
+
lastValidBlockHeight: lastValidBlockHeight != null ? lastValidBlockHeight : 2n ** 64n - 1n
|
|
2080
|
+
// U64 MAX
|
|
2081
|
+
};
|
|
2082
|
+
} else {
|
|
2083
|
+
const nonceAccountAddress = firstInstruction.accounts[0].address;
|
|
2084
|
+
assertIsAddress(nonceAccountAddress);
|
|
2085
|
+
const nonceAuthorityAddress = firstInstruction.accounts[2].address;
|
|
2086
|
+
assertIsAddress(nonceAuthorityAddress);
|
|
2087
|
+
return {
|
|
2088
|
+
nonce: messageLifetimeToken,
|
|
2089
|
+
nonceAccountAddress,
|
|
2090
|
+
nonceAuthorityAddress
|
|
2091
|
+
};
|
|
380
2092
|
}
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
2093
|
+
}
|
|
2094
|
+
function convertSignatures(compiledTransaction) {
|
|
2095
|
+
const {
|
|
2096
|
+
compiledMessage: { staticAccounts },
|
|
2097
|
+
signatures
|
|
2098
|
+
} = compiledTransaction;
|
|
2099
|
+
return signatures.reduce((acc, sig, index) => {
|
|
2100
|
+
const allZeros = sig.every((byte) => byte === 0);
|
|
2101
|
+
if (allZeros)
|
|
2102
|
+
return acc;
|
|
2103
|
+
const address2 = staticAccounts[index];
|
|
2104
|
+
return { ...acc, [address2]: sig };
|
|
2105
|
+
}, {});
|
|
2106
|
+
}
|
|
2107
|
+
function decompileTransaction(compiledTransaction, lastValidBlockHeight) {
|
|
2108
|
+
const { compiledMessage } = compiledTransaction;
|
|
2109
|
+
if ("addressTableLookups" in compiledMessage && compiledMessage.addressTableLookups.length > 0) {
|
|
2110
|
+
throw new Error("Cannot convert transaction with addressTableLookups");
|
|
385
2111
|
}
|
|
386
|
-
|
|
387
|
-
|
|
2112
|
+
const feePayer = compiledMessage.staticAccounts[0];
|
|
2113
|
+
if (!feePayer)
|
|
2114
|
+
throw new Error("No fee payer set in CompiledTransaction");
|
|
2115
|
+
const accountMetas = getAccountMetas(compiledMessage);
|
|
2116
|
+
const instructions = compiledMessage.instructions.map(
|
|
2117
|
+
(compiledInstruction) => convertInstruction(compiledInstruction, accountMetas)
|
|
2118
|
+
);
|
|
2119
|
+
const firstInstruction = instructions[0];
|
|
2120
|
+
const lifetimeConstraint = getLifetimeConstraint(
|
|
2121
|
+
compiledMessage.lifetimeToken,
|
|
2122
|
+
firstInstruction,
|
|
2123
|
+
lastValidBlockHeight
|
|
2124
|
+
);
|
|
2125
|
+
const signatures = convertSignatures(compiledTransaction);
|
|
2126
|
+
return pipe(
|
|
2127
|
+
createTransaction({ version: compiledMessage.version }),
|
|
2128
|
+
(tx) => setTransactionFeePayer(feePayer, tx),
|
|
2129
|
+
(tx) => instructions.reduce((acc, instruction) => {
|
|
2130
|
+
return appendTransactionInstruction(instruction, acc);
|
|
2131
|
+
}, tx),
|
|
2132
|
+
(tx) => "blockhash" in lifetimeConstraint ? setTransactionLifetimeUsingBlockhash(lifetimeConstraint, tx) : setTransactionLifetimeUsingDurableNonce(lifetimeConstraint, tx),
|
|
2133
|
+
(tx) => compiledTransaction.signatures.length ? { ...tx, signatures } : tx
|
|
2134
|
+
);
|
|
2135
|
+
}
|
|
2136
|
+
function getCompiledTransactionEncoder() {
|
|
2137
|
+
return getStructEncoder([
|
|
2138
|
+
["signatures", getArrayEncoder(getBytesEncoder({ size: 64 }), { size: getShortU16Encoder() })],
|
|
2139
|
+
["compiledMessage", getCompiledMessageEncoder()]
|
|
2140
|
+
]);
|
|
2141
|
+
}
|
|
2142
|
+
function getCompiledTransactionDecoder() {
|
|
2143
|
+
return getStructDecoder([
|
|
2144
|
+
[
|
|
2145
|
+
"signatures",
|
|
2146
|
+
getArrayDecoder(getBytesDecoder({ size: 64 }), {
|
|
2147
|
+
size: getShortU16Decoder()
|
|
2148
|
+
})
|
|
2149
|
+
],
|
|
2150
|
+
["compiledMessage", getCompiledMessageDecoder()]
|
|
2151
|
+
]);
|
|
2152
|
+
}
|
|
2153
|
+
function getTransactionEncoder() {
|
|
2154
|
+
return mapEncoder(getCompiledTransactionEncoder(), getCompiledTransaction);
|
|
2155
|
+
}
|
|
2156
|
+
function getTransactionDecoder(lastValidBlockHeight) {
|
|
2157
|
+
return mapDecoder(
|
|
2158
|
+
getCompiledTransactionDecoder(),
|
|
2159
|
+
(compiledTransaction) => decompileTransaction(compiledTransaction, lastValidBlockHeight)
|
|
2160
|
+
);
|
|
2161
|
+
}
|
|
2162
|
+
function getTransactionCodec(lastValidBlockHeight) {
|
|
2163
|
+
return combineCodec(getTransactionEncoder(), getTransactionDecoder(lastValidBlockHeight));
|
|
2164
|
+
}
|
|
2165
|
+
var base58Decoder;
|
|
2166
|
+
function getSignatureFromTransaction(transaction) {
|
|
2167
|
+
if (!base58Decoder)
|
|
2168
|
+
base58Decoder = getBase58Decoder();
|
|
2169
|
+
const signatureBytes = transaction.signatures[transaction.feePayer];
|
|
2170
|
+
if (!signatureBytes) {
|
|
2171
|
+
throw new Error(
|
|
2172
|
+
"Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
|
|
2173
|
+
);
|
|
388
2174
|
}
|
|
389
|
-
|
|
2175
|
+
const transactionSignature = base58Decoder.decode(signatureBytes);
|
|
2176
|
+
return transactionSignature;
|
|
2177
|
+
}
|
|
2178
|
+
async function partiallySignTransaction(keyPairs, transaction) {
|
|
2179
|
+
const compiledMessage = compileMessage(transaction);
|
|
2180
|
+
const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
|
|
2181
|
+
const wireMessageBytes = getCompiledMessageEncoder().encode(compiledMessage);
|
|
2182
|
+
const publicKeySignaturePairs = await Promise.all(
|
|
2183
|
+
keyPairs.map(
|
|
2184
|
+
(keyPair) => Promise.all([getAddressFromPublicKey(keyPair.publicKey), signBytes(keyPair.privateKey, wireMessageBytes)])
|
|
2185
|
+
)
|
|
2186
|
+
);
|
|
2187
|
+
for (const [signerPublicKey, signature2] of publicKeySignaturePairs) {
|
|
2188
|
+
nextSignatures[signerPublicKey] = signature2;
|
|
2189
|
+
}
|
|
2190
|
+
const out = {
|
|
2191
|
+
...transaction,
|
|
2192
|
+
signatures: nextSignatures
|
|
2193
|
+
};
|
|
2194
|
+
Object.freeze(out);
|
|
2195
|
+
return out;
|
|
2196
|
+
}
|
|
2197
|
+
async function signTransaction(keyPairs, transaction) {
|
|
2198
|
+
const out = await partiallySignTransaction(keyPairs, transaction);
|
|
2199
|
+
assertTransactionIsFullySigned(out);
|
|
2200
|
+
Object.freeze(out);
|
|
2201
|
+
return out;
|
|
2202
|
+
}
|
|
2203
|
+
function assertTransactionIsFullySigned(transaction) {
|
|
2204
|
+
const signerAddressesFromInstructions = transaction.instructions.flatMap((i) => {
|
|
2205
|
+
var _a, _b;
|
|
2206
|
+
return (_b = (_a = i.accounts) == null ? void 0 : _a.filter((a) => isSignerRole2(a.role))) != null ? _b : [];
|
|
2207
|
+
}).map((a) => a.address);
|
|
2208
|
+
const requiredSigners = /* @__PURE__ */ new Set([transaction.feePayer, ...signerAddressesFromInstructions]);
|
|
2209
|
+
requiredSigners.forEach((address2) => {
|
|
2210
|
+
if (!transaction.signatures[address2]) {
|
|
2211
|
+
throw new Error(`Transaction is missing signature for address \`${address2}\``);
|
|
2212
|
+
}
|
|
2213
|
+
});
|
|
2214
|
+
}
|
|
2215
|
+
function getBase64EncodedWireTransaction(transaction) {
|
|
2216
|
+
const wireTransactionBytes = getTransactionEncoder().encode(transaction);
|
|
2217
|
+
return getBase64Decoder().decode(wireTransactionBytes);
|
|
2218
|
+
}
|
|
390
2219
|
|
|
391
|
-
//
|
|
2220
|
+
// src/airdrop.ts
|
|
392
2221
|
init_env_shim();
|
|
393
|
-
var u32 = (options = {}) => numberFactory({
|
|
394
|
-
name: "u32",
|
|
395
|
-
size: 4,
|
|
396
|
-
range: [0, Number("0xffffffff")],
|
|
397
|
-
set: (view, value, le) => view.setUint32(0, Number(value), le),
|
|
398
|
-
get: (view, le) => view.getUint32(0, le),
|
|
399
|
-
options
|
|
400
|
-
});
|
|
401
2222
|
|
|
402
|
-
//
|
|
2223
|
+
// src/airdrop-confirmer.ts
|
|
403
2224
|
init_env_shim();
|
|
404
|
-
function getSizeDescription(size) {
|
|
405
|
-
return typeof size === "object" ? size.description : `${size}`;
|
|
406
|
-
}
|
|
407
2225
|
|
|
408
|
-
//
|
|
2226
|
+
// src/transaction-confirmation-strategy-racer.ts
|
|
409
2227
|
init_env_shim();
|
|
410
|
-
function
|
|
411
|
-
const
|
|
412
|
-
|
|
413
|
-
const
|
|
414
|
-
if (
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
description
|
|
2228
|
+
async function raceStrategies(signature2, config, getSpecificStrategiesForRace) {
|
|
2229
|
+
const { abortSignal: callerAbortSignal, commitment, getRecentSignatureConfirmationPromise } = config;
|
|
2230
|
+
callerAbortSignal == null ? void 0 : callerAbortSignal.throwIfAborted();
|
|
2231
|
+
const abortController = new AbortController();
|
|
2232
|
+
if (callerAbortSignal) {
|
|
2233
|
+
const handleAbort = () => {
|
|
2234
|
+
abortController.abort();
|
|
418
2235
|
};
|
|
2236
|
+
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
419
2237
|
}
|
|
420
|
-
|
|
421
|
-
|
|
2238
|
+
try {
|
|
2239
|
+
const specificStrategies = getSpecificStrategiesForRace({
|
|
2240
|
+
...config,
|
|
2241
|
+
abortSignal: abortController.signal
|
|
2242
|
+
});
|
|
2243
|
+
return await Promise.race([
|
|
2244
|
+
getRecentSignatureConfirmationPromise({
|
|
2245
|
+
abortSignal: abortController.signal,
|
|
2246
|
+
commitment,
|
|
2247
|
+
signature: signature2
|
|
2248
|
+
}),
|
|
2249
|
+
...specificStrategies
|
|
2250
|
+
]);
|
|
2251
|
+
} finally {
|
|
2252
|
+
abortController.abort();
|
|
422
2253
|
}
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
2254
|
+
}
|
|
2255
|
+
|
|
2256
|
+
// src/transaction-confirmation-strategy-recent-signature.ts
|
|
2257
|
+
init_env_shim();
|
|
2258
|
+
function createRecentSignatureConfirmationPromiseFactory(rpc, rpcSubscriptions) {
|
|
2259
|
+
return async function getRecentSignatureConfirmationPromise({
|
|
2260
|
+
abortSignal: callerAbortSignal,
|
|
2261
|
+
commitment,
|
|
2262
|
+
signature: signature2
|
|
2263
|
+
}) {
|
|
2264
|
+
const abortController = new AbortController();
|
|
2265
|
+
function handleAbort() {
|
|
2266
|
+
abortController.abort();
|
|
2267
|
+
}
|
|
2268
|
+
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
2269
|
+
const signatureStatusNotifications = await rpcSubscriptions.signatureNotifications(signature2, { commitment }).subscribe({ abortSignal: abortController.signal });
|
|
2270
|
+
const signatureDidCommitPromise = (async () => {
|
|
2271
|
+
for await (const signatureStatusNotification of signatureStatusNotifications) {
|
|
2272
|
+
if (signatureStatusNotification.value.err) {
|
|
2273
|
+
throw new Error(`The transaction with signature \`${signature2}\` failed.`, {
|
|
2274
|
+
cause: signatureStatusNotification.value.err
|
|
2275
|
+
});
|
|
2276
|
+
} else {
|
|
2277
|
+
return;
|
|
2278
|
+
}
|
|
435
2279
|
}
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
const
|
|
440
|
-
if (
|
|
441
|
-
|
|
2280
|
+
})();
|
|
2281
|
+
const signatureStatusLookupPromise = (async () => {
|
|
2282
|
+
const { value: signatureStatusResults } = await rpc.getSignatureStatuses([signature2]).send({ abortSignal: abortController.signal });
|
|
2283
|
+
const signatureStatus = signatureStatusResults[0];
|
|
2284
|
+
if (signatureStatus && signatureStatus.confirmationStatus && commitmentComparator(signatureStatus.confirmationStatus, commitment) >= 0) {
|
|
2285
|
+
return;
|
|
2286
|
+
} else {
|
|
2287
|
+
await new Promise(() => {
|
|
2288
|
+
});
|
|
442
2289
|
}
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
return [
|
|
2290
|
+
})();
|
|
2291
|
+
try {
|
|
2292
|
+
return await Promise.race([signatureDidCommitPromise, signatureStatusLookupPromise]);
|
|
2293
|
+
} finally {
|
|
2294
|
+
abortController.abort();
|
|
446
2295
|
}
|
|
447
2296
|
};
|
|
448
2297
|
}
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
2298
|
+
|
|
2299
|
+
// src/transaction-confirmation-strategy-timeout.ts
|
|
2300
|
+
init_env_shim();
|
|
2301
|
+
async function getTimeoutPromise({ abortSignal: callerAbortSignal, commitment }) {
|
|
2302
|
+
return await new Promise((_, reject) => {
|
|
2303
|
+
const handleAbort = (e3) => {
|
|
2304
|
+
clearTimeout(timeoutId);
|
|
2305
|
+
const abortError = new DOMException(e3.target.reason, "AbortError");
|
|
2306
|
+
reject(abortError);
|
|
2307
|
+
};
|
|
2308
|
+
callerAbortSignal.addEventListener("abort", handleAbort);
|
|
2309
|
+
const timeoutMs = commitment === "processed" ? 3e4 : 6e4;
|
|
2310
|
+
const startMs = performance.now();
|
|
2311
|
+
const timeoutId = (
|
|
2312
|
+
// We use `setTimeout` instead of `AbortSignal.timeout()` because we want to measure
|
|
2313
|
+
// elapsed time instead of active time.
|
|
2314
|
+
// See https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/timeout_static
|
|
2315
|
+
setTimeout(() => {
|
|
2316
|
+
const elapsedMs = performance.now() - startMs;
|
|
2317
|
+
reject(new DOMException(`Timeout elapsed after ${elapsedMs} ms`, "TimeoutError"));
|
|
2318
|
+
}, timeoutMs)
|
|
2319
|
+
);
|
|
2320
|
+
});
|
|
2321
|
+
}
|
|
2322
|
+
|
|
2323
|
+
// src/airdrop-confirmer.ts
|
|
2324
|
+
function createDefaultSignatureOnlyRecentTransactionConfirmer({
|
|
2325
|
+
rpc,
|
|
2326
|
+
rpcSubscriptions
|
|
2327
|
+
}) {
|
|
2328
|
+
const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
|
|
2329
|
+
rpc,
|
|
2330
|
+
rpcSubscriptions
|
|
2331
|
+
);
|
|
2332
|
+
return async function confirmSignatureOnlyRecentTransaction(config) {
|
|
2333
|
+
await waitForRecentTransactionConfirmationUntilTimeout({
|
|
2334
|
+
...config,
|
|
2335
|
+
getRecentSignatureConfirmationPromise,
|
|
2336
|
+
getTimeoutPromise
|
|
466
2337
|
});
|
|
467
|
-
}
|
|
2338
|
+
};
|
|
2339
|
+
}
|
|
2340
|
+
async function waitForRecentTransactionConfirmationUntilTimeout(config) {
|
|
2341
|
+
await raceStrategies(
|
|
2342
|
+
config.signature,
|
|
2343
|
+
config,
|
|
2344
|
+
function getSpecificStrategiesForRace({ abortSignal, commitment, getTimeoutPromise: getTimeoutPromise2 }) {
|
|
2345
|
+
return [
|
|
2346
|
+
getTimeoutPromise2({
|
|
2347
|
+
abortSignal,
|
|
2348
|
+
commitment
|
|
2349
|
+
})
|
|
2350
|
+
];
|
|
2351
|
+
}
|
|
2352
|
+
);
|
|
468
2353
|
}
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
2354
|
+
|
|
2355
|
+
// src/airdrop.ts
|
|
2356
|
+
function createDefaultAirdropRequester({ rpc, rpcSubscriptions }) {
|
|
2357
|
+
const confirmSignatureOnlyTransaction = createDefaultSignatureOnlyRecentTransactionConfirmer({
|
|
2358
|
+
rpc,
|
|
2359
|
+
rpcSubscriptions
|
|
474
2360
|
});
|
|
2361
|
+
return async function requestAirdrop(config) {
|
|
2362
|
+
return await requestAndConfirmAirdrop({
|
|
2363
|
+
...config,
|
|
2364
|
+
confirmSignatureOnlyTransaction,
|
|
2365
|
+
rpc
|
|
2366
|
+
});
|
|
2367
|
+
};
|
|
475
2368
|
}
|
|
476
|
-
function
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
}).
|
|
2369
|
+
async function requestAndConfirmAirdrop({
|
|
2370
|
+
abortSignal,
|
|
2371
|
+
commitment,
|
|
2372
|
+
confirmSignatureOnlyTransaction,
|
|
2373
|
+
lamports: lamports2,
|
|
2374
|
+
recipientAddress,
|
|
2375
|
+
rpc
|
|
2376
|
+
}) {
|
|
2377
|
+
const airdropTransactionSignature = await rpc.requestAirdrop(recipientAddress, lamports2, { commitment }).send({ abortSignal });
|
|
2378
|
+
await confirmSignatureOnlyTransaction({
|
|
2379
|
+
abortSignal,
|
|
2380
|
+
commitment,
|
|
2381
|
+
signature: airdropTransactionSignature
|
|
2382
|
+
});
|
|
2383
|
+
return airdropTransactionSignature;
|
|
485
2384
|
}
|
|
486
2385
|
|
|
487
2386
|
// src/rpc.ts
|
|
@@ -515,36 +2414,393 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
515
2414
|
return visitNode(params, [], onIntegerOverflow);
|
|
516
2415
|
}
|
|
517
2416
|
var KEYPATH_WILDCARD = {};
|
|
518
|
-
var
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
],
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
],
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
]
|
|
547
|
-
|
|
2417
|
+
var jsonParsedTokenAccountsConfigs = [
|
|
2418
|
+
// parsed Token/Token22 token account
|
|
2419
|
+
["data", "parsed", "info", "tokenAmount", "decimals"],
|
|
2420
|
+
["data", "parsed", "info", "tokenAmount", "uiAmount"],
|
|
2421
|
+
["data", "parsed", "info", "rentExemptReserve", "decimals"],
|
|
2422
|
+
["data", "parsed", "info", "rentExemptReserve", "uiAmount"],
|
|
2423
|
+
["data", "parsed", "info", "delegatedAmount", "decimals"],
|
|
2424
|
+
["data", "parsed", "info", "delegatedAmount", "uiAmount"],
|
|
2425
|
+
["data", "parsed", "info", "extensions", KEYPATH_WILDCARD, "state", "olderTransferFee", "transferFeeBasisPoints"],
|
|
2426
|
+
["data", "parsed", "info", "extensions", KEYPATH_WILDCARD, "state", "newerTransferFee", "transferFeeBasisPoints"],
|
|
2427
|
+
["data", "parsed", "info", "extensions", KEYPATH_WILDCARD, "state", "preUpdateAverageRate"],
|
|
2428
|
+
["data", "parsed", "info", "extensions", KEYPATH_WILDCARD, "state", "currentRate"]
|
|
2429
|
+
];
|
|
2430
|
+
var jsonParsedAccountsConfigs = [
|
|
2431
|
+
...jsonParsedTokenAccountsConfigs,
|
|
2432
|
+
// parsed AddressTableLookup account
|
|
2433
|
+
["data", "parsed", "info", "lastExtendedSlotStartIndex"],
|
|
2434
|
+
// parsed Config account
|
|
2435
|
+
["data", "parsed", "info", "slashPenalty"],
|
|
2436
|
+
["data", "parsed", "info", "warmupCooldownRate"],
|
|
2437
|
+
// parsed Token/Token22 mint account
|
|
2438
|
+
["data", "parsed", "info", "decimals"],
|
|
2439
|
+
// parsed Token/Token22 multisig account
|
|
2440
|
+
["data", "parsed", "info", "numRequiredSigners"],
|
|
2441
|
+
["data", "parsed", "info", "numValidSigners"],
|
|
2442
|
+
// parsed Stake account
|
|
2443
|
+
["data", "parsed", "info", "stake", "delegation", "warmupCooldownRate"],
|
|
2444
|
+
// parsed Sysvar rent account
|
|
2445
|
+
["data", "parsed", "info", "exemptionThreshold"],
|
|
2446
|
+
["data", "parsed", "info", "burnPercent"],
|
|
2447
|
+
// parsed Vote account
|
|
2448
|
+
["data", "parsed", "info", "commission"],
|
|
2449
|
+
["data", "parsed", "info", "votes", KEYPATH_WILDCARD, "confirmationCount"]
|
|
2450
|
+
];
|
|
2451
|
+
var memoizedNotificationKeypaths;
|
|
2452
|
+
var memoizedResponseKeypaths;
|
|
2453
|
+
function getAllowedNumericKeypathsForNotification() {
|
|
2454
|
+
if (!memoizedNotificationKeypaths) {
|
|
2455
|
+
memoizedNotificationKeypaths = {
|
|
2456
|
+
accountNotifications: jsonParsedAccountsConfigs.map((c) => ["value", ...c]),
|
|
2457
|
+
blockNotifications: [
|
|
2458
|
+
["value", "block", "blockTime"],
|
|
2459
|
+
[
|
|
2460
|
+
"value",
|
|
2461
|
+
"block",
|
|
2462
|
+
"transactions",
|
|
2463
|
+
KEYPATH_WILDCARD,
|
|
2464
|
+
"meta",
|
|
2465
|
+
"preTokenBalances",
|
|
2466
|
+
KEYPATH_WILDCARD,
|
|
2467
|
+
"accountIndex"
|
|
2468
|
+
],
|
|
2469
|
+
[
|
|
2470
|
+
"value",
|
|
2471
|
+
"block",
|
|
2472
|
+
"transactions",
|
|
2473
|
+
KEYPATH_WILDCARD,
|
|
2474
|
+
"meta",
|
|
2475
|
+
"preTokenBalances",
|
|
2476
|
+
KEYPATH_WILDCARD,
|
|
2477
|
+
"uiTokenAmount",
|
|
2478
|
+
"decimals"
|
|
2479
|
+
],
|
|
2480
|
+
[
|
|
2481
|
+
"value",
|
|
2482
|
+
"block",
|
|
2483
|
+
"transactions",
|
|
2484
|
+
KEYPATH_WILDCARD,
|
|
2485
|
+
"meta",
|
|
2486
|
+
"postTokenBalances",
|
|
2487
|
+
KEYPATH_WILDCARD,
|
|
2488
|
+
"accountIndex"
|
|
2489
|
+
],
|
|
2490
|
+
[
|
|
2491
|
+
"value",
|
|
2492
|
+
"block",
|
|
2493
|
+
"transactions",
|
|
2494
|
+
KEYPATH_WILDCARD,
|
|
2495
|
+
"meta",
|
|
2496
|
+
"postTokenBalances",
|
|
2497
|
+
KEYPATH_WILDCARD,
|
|
2498
|
+
"uiTokenAmount",
|
|
2499
|
+
"decimals"
|
|
2500
|
+
],
|
|
2501
|
+
["value", "block", "transactions", KEYPATH_WILDCARD, "meta", "rewards", KEYPATH_WILDCARD, "commission"],
|
|
2502
|
+
[
|
|
2503
|
+
"value",
|
|
2504
|
+
"block",
|
|
2505
|
+
"transactions",
|
|
2506
|
+
KEYPATH_WILDCARD,
|
|
2507
|
+
"meta",
|
|
2508
|
+
"innerInstructions",
|
|
2509
|
+
KEYPATH_WILDCARD,
|
|
2510
|
+
"index"
|
|
2511
|
+
],
|
|
2512
|
+
[
|
|
2513
|
+
"value",
|
|
2514
|
+
"block",
|
|
2515
|
+
"transactions",
|
|
2516
|
+
KEYPATH_WILDCARD,
|
|
2517
|
+
"meta",
|
|
2518
|
+
"innerInstructions",
|
|
2519
|
+
KEYPATH_WILDCARD,
|
|
2520
|
+
"instructions",
|
|
2521
|
+
KEYPATH_WILDCARD,
|
|
2522
|
+
"programIdIndex"
|
|
2523
|
+
],
|
|
2524
|
+
[
|
|
2525
|
+
"value",
|
|
2526
|
+
"block",
|
|
2527
|
+
"transactions",
|
|
2528
|
+
KEYPATH_WILDCARD,
|
|
2529
|
+
"meta",
|
|
2530
|
+
"innerInstructions",
|
|
2531
|
+
KEYPATH_WILDCARD,
|
|
2532
|
+
"instructions",
|
|
2533
|
+
KEYPATH_WILDCARD,
|
|
2534
|
+
"accounts",
|
|
2535
|
+
KEYPATH_WILDCARD
|
|
2536
|
+
],
|
|
2537
|
+
[
|
|
2538
|
+
"value",
|
|
2539
|
+
"block",
|
|
2540
|
+
"transactions",
|
|
2541
|
+
KEYPATH_WILDCARD,
|
|
2542
|
+
"transaction",
|
|
2543
|
+
"message",
|
|
2544
|
+
"addressTableLookups",
|
|
2545
|
+
KEYPATH_WILDCARD,
|
|
2546
|
+
"writableIndexes",
|
|
2547
|
+
KEYPATH_WILDCARD
|
|
2548
|
+
],
|
|
2549
|
+
[
|
|
2550
|
+
"value",
|
|
2551
|
+
"block",
|
|
2552
|
+
"transactions",
|
|
2553
|
+
KEYPATH_WILDCARD,
|
|
2554
|
+
"transaction",
|
|
2555
|
+
"message",
|
|
2556
|
+
"addressTableLookups",
|
|
2557
|
+
KEYPATH_WILDCARD,
|
|
2558
|
+
"readonlyIndexes",
|
|
2559
|
+
KEYPATH_WILDCARD
|
|
2560
|
+
],
|
|
2561
|
+
[
|
|
2562
|
+
"value",
|
|
2563
|
+
"block",
|
|
2564
|
+
"transactions",
|
|
2565
|
+
KEYPATH_WILDCARD,
|
|
2566
|
+
"transaction",
|
|
2567
|
+
"message",
|
|
2568
|
+
"instructions",
|
|
2569
|
+
KEYPATH_WILDCARD,
|
|
2570
|
+
"programIdIndex"
|
|
2571
|
+
],
|
|
2572
|
+
[
|
|
2573
|
+
"value",
|
|
2574
|
+
"block",
|
|
2575
|
+
"transactions",
|
|
2576
|
+
KEYPATH_WILDCARD,
|
|
2577
|
+
"transaction",
|
|
2578
|
+
"message",
|
|
2579
|
+
"instructions",
|
|
2580
|
+
KEYPATH_WILDCARD,
|
|
2581
|
+
"accounts",
|
|
2582
|
+
KEYPATH_WILDCARD
|
|
2583
|
+
],
|
|
2584
|
+
[
|
|
2585
|
+
"value",
|
|
2586
|
+
"block",
|
|
2587
|
+
"transactions",
|
|
2588
|
+
KEYPATH_WILDCARD,
|
|
2589
|
+
"transaction",
|
|
2590
|
+
"message",
|
|
2591
|
+
"header",
|
|
2592
|
+
"numReadonlySignedAccounts"
|
|
2593
|
+
],
|
|
2594
|
+
[
|
|
2595
|
+
"value",
|
|
2596
|
+
"block",
|
|
2597
|
+
"transactions",
|
|
2598
|
+
KEYPATH_WILDCARD,
|
|
2599
|
+
"transaction",
|
|
2600
|
+
"message",
|
|
2601
|
+
"header",
|
|
2602
|
+
"numReadonlyUnsignedAccounts"
|
|
2603
|
+
],
|
|
2604
|
+
[
|
|
2605
|
+
"value",
|
|
2606
|
+
"block",
|
|
2607
|
+
"transactions",
|
|
2608
|
+
KEYPATH_WILDCARD,
|
|
2609
|
+
"transaction",
|
|
2610
|
+
"message",
|
|
2611
|
+
"header",
|
|
2612
|
+
"numRequiredSignatures"
|
|
2613
|
+
],
|
|
2614
|
+
["value", "block", "rewards", KEYPATH_WILDCARD, "commission"]
|
|
2615
|
+
],
|
|
2616
|
+
programNotifications: jsonParsedAccountsConfigs.flatMap((c) => [
|
|
2617
|
+
["value", KEYPATH_WILDCARD, "account", ...c],
|
|
2618
|
+
[KEYPATH_WILDCARD, "account", ...c]
|
|
2619
|
+
])
|
|
2620
|
+
};
|
|
2621
|
+
}
|
|
2622
|
+
return memoizedNotificationKeypaths;
|
|
2623
|
+
}
|
|
2624
|
+
function getAllowedNumericKeypathsForResponse() {
|
|
2625
|
+
if (!memoizedResponseKeypaths) {
|
|
2626
|
+
memoizedResponseKeypaths = {
|
|
2627
|
+
getAccountInfo: jsonParsedAccountsConfigs.map((c) => ["value", ...c]),
|
|
2628
|
+
getBlock: [
|
|
2629
|
+
["blockTime"],
|
|
2630
|
+
["transactions", KEYPATH_WILDCARD, "meta", "preTokenBalances", KEYPATH_WILDCARD, "accountIndex"],
|
|
2631
|
+
[
|
|
2632
|
+
"transactions",
|
|
2633
|
+
KEYPATH_WILDCARD,
|
|
2634
|
+
"meta",
|
|
2635
|
+
"preTokenBalances",
|
|
2636
|
+
KEYPATH_WILDCARD,
|
|
2637
|
+
"uiTokenAmount",
|
|
2638
|
+
"decimals"
|
|
2639
|
+
],
|
|
2640
|
+
["transactions", KEYPATH_WILDCARD, "meta", "postTokenBalances", KEYPATH_WILDCARD, "accountIndex"],
|
|
2641
|
+
[
|
|
2642
|
+
"transactions",
|
|
2643
|
+
KEYPATH_WILDCARD,
|
|
2644
|
+
"meta",
|
|
2645
|
+
"postTokenBalances",
|
|
2646
|
+
KEYPATH_WILDCARD,
|
|
2647
|
+
"uiTokenAmount",
|
|
2648
|
+
"decimals"
|
|
2649
|
+
],
|
|
2650
|
+
["transactions", KEYPATH_WILDCARD, "meta", "rewards", KEYPATH_WILDCARD, "commission"],
|
|
2651
|
+
["transactions", KEYPATH_WILDCARD, "meta", "innerInstructions", KEYPATH_WILDCARD, "index"],
|
|
2652
|
+
[
|
|
2653
|
+
"transactions",
|
|
2654
|
+
KEYPATH_WILDCARD,
|
|
2655
|
+
"meta",
|
|
2656
|
+
"innerInstructions",
|
|
2657
|
+
KEYPATH_WILDCARD,
|
|
2658
|
+
"instructions",
|
|
2659
|
+
KEYPATH_WILDCARD,
|
|
2660
|
+
"programIdIndex"
|
|
2661
|
+
],
|
|
2662
|
+
[
|
|
2663
|
+
"transactions",
|
|
2664
|
+
KEYPATH_WILDCARD,
|
|
2665
|
+
"meta",
|
|
2666
|
+
"innerInstructions",
|
|
2667
|
+
KEYPATH_WILDCARD,
|
|
2668
|
+
"instructions",
|
|
2669
|
+
KEYPATH_WILDCARD,
|
|
2670
|
+
"accounts",
|
|
2671
|
+
KEYPATH_WILDCARD
|
|
2672
|
+
],
|
|
2673
|
+
[
|
|
2674
|
+
"transactions",
|
|
2675
|
+
KEYPATH_WILDCARD,
|
|
2676
|
+
"transaction",
|
|
2677
|
+
"message",
|
|
2678
|
+
"addressTableLookups",
|
|
2679
|
+
KEYPATH_WILDCARD,
|
|
2680
|
+
"writableIndexes",
|
|
2681
|
+
KEYPATH_WILDCARD
|
|
2682
|
+
],
|
|
2683
|
+
[
|
|
2684
|
+
"transactions",
|
|
2685
|
+
KEYPATH_WILDCARD,
|
|
2686
|
+
"transaction",
|
|
2687
|
+
"message",
|
|
2688
|
+
"addressTableLookups",
|
|
2689
|
+
KEYPATH_WILDCARD,
|
|
2690
|
+
"readonlyIndexes",
|
|
2691
|
+
KEYPATH_WILDCARD
|
|
2692
|
+
],
|
|
2693
|
+
[
|
|
2694
|
+
"transactions",
|
|
2695
|
+
KEYPATH_WILDCARD,
|
|
2696
|
+
"transaction",
|
|
2697
|
+
"message",
|
|
2698
|
+
"instructions",
|
|
2699
|
+
KEYPATH_WILDCARD,
|
|
2700
|
+
"programIdIndex"
|
|
2701
|
+
],
|
|
2702
|
+
[
|
|
2703
|
+
"transactions",
|
|
2704
|
+
KEYPATH_WILDCARD,
|
|
2705
|
+
"transaction",
|
|
2706
|
+
"message",
|
|
2707
|
+
"instructions",
|
|
2708
|
+
KEYPATH_WILDCARD,
|
|
2709
|
+
"accounts",
|
|
2710
|
+
KEYPATH_WILDCARD
|
|
2711
|
+
],
|
|
2712
|
+
["transactions", KEYPATH_WILDCARD, "transaction", "message", "header", "numReadonlySignedAccounts"],
|
|
2713
|
+
["transactions", KEYPATH_WILDCARD, "transaction", "message", "header", "numReadonlyUnsignedAccounts"],
|
|
2714
|
+
["transactions", KEYPATH_WILDCARD, "transaction", "message", "header", "numRequiredSignatures"],
|
|
2715
|
+
["rewards", KEYPATH_WILDCARD, "commission"]
|
|
2716
|
+
],
|
|
2717
|
+
getBlockTime: [[]],
|
|
2718
|
+
getClusterNodes: [
|
|
2719
|
+
[KEYPATH_WILDCARD, "featureSet"],
|
|
2720
|
+
[KEYPATH_WILDCARD, "shredVersion"]
|
|
2721
|
+
],
|
|
2722
|
+
getInflationGovernor: [["initial"], ["foundation"], ["foundationTerm"], ["taper"], ["terminal"]],
|
|
2723
|
+
getInflationRate: [["foundation"], ["total"], ["validator"]],
|
|
2724
|
+
getInflationReward: [[KEYPATH_WILDCARD, "commission"]],
|
|
2725
|
+
getMultipleAccounts: jsonParsedAccountsConfigs.map((c) => ["value", KEYPATH_WILDCARD, ...c]),
|
|
2726
|
+
getProgramAccounts: jsonParsedAccountsConfigs.flatMap((c) => [
|
|
2727
|
+
["value", KEYPATH_WILDCARD, "account", ...c],
|
|
2728
|
+
[KEYPATH_WILDCARD, "account", ...c]
|
|
2729
|
+
]),
|
|
2730
|
+
getRecentPerformanceSamples: [[KEYPATH_WILDCARD, "samplePeriodSecs"]],
|
|
2731
|
+
getTokenAccountBalance: [
|
|
2732
|
+
["value", "decimals"],
|
|
2733
|
+
["value", "uiAmount"]
|
|
2734
|
+
],
|
|
2735
|
+
getTokenAccountsByDelegate: jsonParsedTokenAccountsConfigs.map((c) => [
|
|
2736
|
+
"value",
|
|
2737
|
+
KEYPATH_WILDCARD,
|
|
2738
|
+
"account",
|
|
2739
|
+
...c
|
|
2740
|
+
]),
|
|
2741
|
+
getTokenAccountsByOwner: jsonParsedTokenAccountsConfigs.map((c) => [
|
|
2742
|
+
"value",
|
|
2743
|
+
KEYPATH_WILDCARD,
|
|
2744
|
+
"account",
|
|
2745
|
+
...c
|
|
2746
|
+
]),
|
|
2747
|
+
getTokenLargestAccounts: [
|
|
2748
|
+
["value", KEYPATH_WILDCARD, "decimals"],
|
|
2749
|
+
["value", KEYPATH_WILDCARD, "uiAmount"]
|
|
2750
|
+
],
|
|
2751
|
+
getTokenSupply: [
|
|
2752
|
+
["value", "decimals"],
|
|
2753
|
+
["value", "uiAmount"]
|
|
2754
|
+
],
|
|
2755
|
+
getTransaction: [
|
|
2756
|
+
["meta", "preTokenBalances", KEYPATH_WILDCARD, "accountIndex"],
|
|
2757
|
+
["meta", "preTokenBalances", KEYPATH_WILDCARD, "uiTokenAmount", "decimals"],
|
|
2758
|
+
["meta", "postTokenBalances", KEYPATH_WILDCARD, "accountIndex"],
|
|
2759
|
+
["meta", "postTokenBalances", KEYPATH_WILDCARD, "uiTokenAmount", "decimals"],
|
|
2760
|
+
["meta", "rewards", KEYPATH_WILDCARD, "commission"],
|
|
2761
|
+
["meta", "innerInstructions", KEYPATH_WILDCARD, "index"],
|
|
2762
|
+
["meta", "innerInstructions", KEYPATH_WILDCARD, "instructions", KEYPATH_WILDCARD, "programIdIndex"],
|
|
2763
|
+
[
|
|
2764
|
+
"meta",
|
|
2765
|
+
"innerInstructions",
|
|
2766
|
+
KEYPATH_WILDCARD,
|
|
2767
|
+
"instructions",
|
|
2768
|
+
KEYPATH_WILDCARD,
|
|
2769
|
+
"accounts",
|
|
2770
|
+
KEYPATH_WILDCARD
|
|
2771
|
+
],
|
|
2772
|
+
[
|
|
2773
|
+
"transaction",
|
|
2774
|
+
"message",
|
|
2775
|
+
"addressTableLookups",
|
|
2776
|
+
KEYPATH_WILDCARD,
|
|
2777
|
+
"writableIndexes",
|
|
2778
|
+
KEYPATH_WILDCARD
|
|
2779
|
+
],
|
|
2780
|
+
[
|
|
2781
|
+
"transaction",
|
|
2782
|
+
"message",
|
|
2783
|
+
"addressTableLookups",
|
|
2784
|
+
KEYPATH_WILDCARD,
|
|
2785
|
+
"readonlyIndexes",
|
|
2786
|
+
KEYPATH_WILDCARD
|
|
2787
|
+
],
|
|
2788
|
+
["transaction", "message", "instructions", KEYPATH_WILDCARD, "programIdIndex"],
|
|
2789
|
+
["transaction", "message", "instructions", KEYPATH_WILDCARD, "accounts", KEYPATH_WILDCARD],
|
|
2790
|
+
["transaction", "message", "header", "numReadonlySignedAccounts"],
|
|
2791
|
+
["transaction", "message", "header", "numReadonlyUnsignedAccounts"],
|
|
2792
|
+
["transaction", "message", "header", "numRequiredSignatures"]
|
|
2793
|
+
],
|
|
2794
|
+
getVersion: [["feature-set"]],
|
|
2795
|
+
getVoteAccounts: [
|
|
2796
|
+
["current", KEYPATH_WILDCARD, "commission"],
|
|
2797
|
+
["delinquent", KEYPATH_WILDCARD, "commission"]
|
|
2798
|
+
],
|
|
2799
|
+
simulateTransaction: jsonParsedAccountsConfigs.map((c) => ["value", "accounts", KEYPATH_WILDCARD, ...c])
|
|
2800
|
+
};
|
|
2801
|
+
}
|
|
2802
|
+
return memoizedResponseKeypaths;
|
|
2803
|
+
}
|
|
548
2804
|
function getNextAllowedKeypaths(keyPaths, property) {
|
|
549
2805
|
return keyPaths.filter((keyPath) => keyPath[0] === KEYPATH_WILDCARD && typeof property === "number" || keyPath[0] === property).map((keyPath) => keyPath.slice(1));
|
|
550
2806
|
}
|
|
@@ -560,20 +2816,51 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
560
2816
|
const nextAllowedKeypaths = getNextAllowedKeypaths(allowedKeypaths, propName);
|
|
561
2817
|
out[propName] = visitNode2(innerValue, nextAllowedKeypaths);
|
|
562
2818
|
}
|
|
563
|
-
return out;
|
|
564
|
-
} else if (typeof value === "number" && // The presence of an allowed keypath on the route to this value implies it's allowlisted;
|
|
565
|
-
// Upcast the value to `bigint` unless an allowed keypath is present.
|
|
566
|
-
allowedKeypaths.length === 0
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
2819
|
+
return out;
|
|
2820
|
+
} else if (typeof value === "number" && // The presence of an allowed keypath on the route to this value implies it's allowlisted;
|
|
2821
|
+
// Upcast the value to `bigint` unless an allowed keypath is present.
|
|
2822
|
+
allowedKeypaths.length === 0 && // Only try to upcast an Integer to `bigint`
|
|
2823
|
+
Number.isInteger(value)) {
|
|
2824
|
+
return BigInt(value);
|
|
2825
|
+
} else {
|
|
2826
|
+
return value;
|
|
2827
|
+
}
|
|
2828
|
+
}
|
|
2829
|
+
function patchResponseForSolanaLabsRpc(rawResponse, methodName) {
|
|
2830
|
+
const allowedKeypaths = methodName ? getAllowedNumericKeypathsForResponse()[methodName] : void 0;
|
|
2831
|
+
return visitNode2(rawResponse, allowedKeypaths != null ? allowedKeypaths : []);
|
|
2832
|
+
}
|
|
2833
|
+
function patchResponseForSolanaLabsRpcSubscriptions(rawResponse, methodName) {
|
|
2834
|
+
const allowedKeypaths = methodName ? getAllowedNumericKeypathsForNotification()[methodName] : void 0;
|
|
2835
|
+
return visitNode2(rawResponse, allowedKeypaths != null ? allowedKeypaths : []);
|
|
2836
|
+
}
|
|
2837
|
+
function createSolanaRpcApi(config) {
|
|
2838
|
+
return new Proxy({}, {
|
|
2839
|
+
defineProperty() {
|
|
2840
|
+
return false;
|
|
2841
|
+
},
|
|
2842
|
+
deleteProperty() {
|
|
2843
|
+
return false;
|
|
2844
|
+
},
|
|
2845
|
+
get(...args) {
|
|
2846
|
+
const [_, p] = args;
|
|
2847
|
+
const methodName = p.toString();
|
|
2848
|
+
return function(...rawParams) {
|
|
2849
|
+
const handleIntegerOverflow = config == null ? void 0 : config.onIntegerOverflow;
|
|
2850
|
+
const params = patchParamsForSolanaLabsRpc(
|
|
2851
|
+
rawParams,
|
|
2852
|
+
handleIntegerOverflow ? (keyPath, value) => handleIntegerOverflow(methodName, keyPath, value) : void 0
|
|
2853
|
+
);
|
|
2854
|
+
return {
|
|
2855
|
+
methodName,
|
|
2856
|
+
params,
|
|
2857
|
+
responseProcessor: (rawResponse) => patchResponseForSolanaLabsRpc(rawResponse, methodName)
|
|
2858
|
+
};
|
|
2859
|
+
};
|
|
2860
|
+
}
|
|
2861
|
+
});
|
|
575
2862
|
}
|
|
576
|
-
function
|
|
2863
|
+
function createSolanaRpcSubscriptionsApi(config) {
|
|
577
2864
|
return new Proxy({}, {
|
|
578
2865
|
defineProperty() {
|
|
579
2866
|
return false;
|
|
@@ -583,28 +2870,34 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
583
2870
|
},
|
|
584
2871
|
get(...args) {
|
|
585
2872
|
const [_, p] = args;
|
|
586
|
-
const
|
|
2873
|
+
const notificationName = p.toString();
|
|
587
2874
|
return function(...rawParams) {
|
|
588
|
-
const handleIntegerOverflow = config
|
|
2875
|
+
const handleIntegerOverflow = config == null ? void 0 : config.onIntegerOverflow;
|
|
589
2876
|
const params = patchParamsForSolanaLabsRpc(
|
|
590
2877
|
rawParams,
|
|
591
|
-
handleIntegerOverflow ? (keyPath, value) => handleIntegerOverflow(
|
|
2878
|
+
handleIntegerOverflow ? (keyPath, value) => handleIntegerOverflow(notificationName, keyPath, value) : void 0
|
|
592
2879
|
);
|
|
593
2880
|
return {
|
|
594
|
-
methodName,
|
|
595
2881
|
params,
|
|
596
|
-
responseProcessor: (rawResponse) =>
|
|
2882
|
+
responseProcessor: (rawResponse) => patchResponseForSolanaLabsRpcSubscriptions(rawResponse, notificationName),
|
|
2883
|
+
subscribeMethodName: notificationName.replace(/Notifications$/, "Subscribe"),
|
|
2884
|
+
unsubscribeMethodName: notificationName.replace(/Notifications$/, "Unsubscribe")
|
|
597
2885
|
};
|
|
598
2886
|
};
|
|
599
2887
|
}
|
|
600
2888
|
});
|
|
601
2889
|
}
|
|
2890
|
+
function createSolanaRpcSubscriptionsApi_UNSTABLE(config) {
|
|
2891
|
+
return createSolanaRpcSubscriptionsApi(config);
|
|
2892
|
+
}
|
|
602
2893
|
|
|
603
2894
|
// ../rpc-transport/dist/index.browser.js
|
|
604
2895
|
init_env_shim();
|
|
605
2896
|
var SolanaJsonRpcError = class extends Error {
|
|
606
2897
|
constructor(details) {
|
|
607
2898
|
super(`JSON-RPC 2.0 error (${details.code}): ${details.message}`);
|
|
2899
|
+
__publicField(this, "code");
|
|
2900
|
+
__publicField(this, "data");
|
|
608
2901
|
Error.captureStackTrace(this, this.constructor);
|
|
609
2902
|
this.code = details.code;
|
|
610
2903
|
this.data = details.data;
|
|
@@ -634,7 +2927,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
634
2927
|
const payload = createJsonRpcMessage(methodName, params);
|
|
635
2928
|
const response = await rpcConfig.transport({
|
|
636
2929
|
payload,
|
|
637
|
-
signal: options
|
|
2930
|
+
signal: options == null ? void 0 : options.abortSignal
|
|
638
2931
|
});
|
|
639
2932
|
if ("error" in response) {
|
|
640
2933
|
throw new SolanaJsonRpcError(response.error);
|
|
@@ -665,10 +2958,105 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
665
2958
|
function createJsonRpc(rpcConfig) {
|
|
666
2959
|
return makeProxy(rpcConfig);
|
|
667
2960
|
}
|
|
668
|
-
|
|
2961
|
+
function registerIterableCleanup(iterable, cleanupFn) {
|
|
2962
|
+
(async () => {
|
|
2963
|
+
try {
|
|
2964
|
+
for await (const _ of iterable)
|
|
2965
|
+
;
|
|
2966
|
+
} catch {
|
|
2967
|
+
} finally {
|
|
2968
|
+
cleanupFn();
|
|
2969
|
+
}
|
|
2970
|
+
})();
|
|
2971
|
+
}
|
|
2972
|
+
function createPendingRpcSubscription(rpcConfig, { params, subscribeMethodName, unsubscribeMethodName, responseProcessor }) {
|
|
2973
|
+
return {
|
|
2974
|
+
async subscribe({ abortSignal }) {
|
|
2975
|
+
abortSignal.throwIfAborted();
|
|
2976
|
+
let subscriptionId;
|
|
2977
|
+
function handleCleanup() {
|
|
2978
|
+
if (subscriptionId !== void 0) {
|
|
2979
|
+
const payload = createJsonRpcMessage(unsubscribeMethodName, [subscriptionId]);
|
|
2980
|
+
connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(payload).finally(() => {
|
|
2981
|
+
connectionAbortController.abort();
|
|
2982
|
+
});
|
|
2983
|
+
} else {
|
|
2984
|
+
connectionAbortController.abort();
|
|
2985
|
+
}
|
|
2986
|
+
}
|
|
2987
|
+
abortSignal.addEventListener("abort", handleCleanup);
|
|
2988
|
+
const connectionAbortController = new AbortController();
|
|
2989
|
+
const subscribeMessage = createJsonRpcMessage(subscribeMethodName, params);
|
|
2990
|
+
const connection = await rpcConfig.transport({
|
|
2991
|
+
payload: subscribeMessage,
|
|
2992
|
+
signal: connectionAbortController.signal
|
|
2993
|
+
});
|
|
2994
|
+
function handleConnectionCleanup() {
|
|
2995
|
+
abortSignal.removeEventListener("abort", handleCleanup);
|
|
2996
|
+
}
|
|
2997
|
+
registerIterableCleanup(connection, handleConnectionCleanup);
|
|
2998
|
+
for await (const message of connection) {
|
|
2999
|
+
if ("id" in message && message.id === subscribeMessage.id) {
|
|
3000
|
+
if ("error" in message) {
|
|
3001
|
+
throw new SolanaJsonRpcError(message.error);
|
|
3002
|
+
} else {
|
|
3003
|
+
subscriptionId = message.result;
|
|
3004
|
+
break;
|
|
3005
|
+
}
|
|
3006
|
+
}
|
|
3007
|
+
}
|
|
3008
|
+
if (subscriptionId == null) {
|
|
3009
|
+
throw new Error("Failed to obtain a subscription id from the server");
|
|
3010
|
+
}
|
|
3011
|
+
return {
|
|
3012
|
+
async *[Symbol.asyncIterator]() {
|
|
3013
|
+
for await (const message of connection) {
|
|
3014
|
+
if (!("params" in message) || message.params.subscription !== subscriptionId) {
|
|
3015
|
+
continue;
|
|
3016
|
+
}
|
|
3017
|
+
const notification = message.params.result;
|
|
3018
|
+
yield responseProcessor ? responseProcessor(notification) : notification;
|
|
3019
|
+
}
|
|
3020
|
+
}
|
|
3021
|
+
};
|
|
3022
|
+
}
|
|
3023
|
+
};
|
|
3024
|
+
}
|
|
3025
|
+
function makeProxy2(rpcConfig) {
|
|
3026
|
+
return new Proxy(rpcConfig.api, {
|
|
3027
|
+
defineProperty() {
|
|
3028
|
+
return false;
|
|
3029
|
+
},
|
|
3030
|
+
deleteProperty() {
|
|
3031
|
+
return false;
|
|
3032
|
+
},
|
|
3033
|
+
get(target, p, receiver) {
|
|
3034
|
+
return function(...rawParams) {
|
|
3035
|
+
const methodName = p.toString();
|
|
3036
|
+
const createRpcSubscription = Reflect.get(target, methodName, receiver);
|
|
3037
|
+
if (p.toString().endsWith("Notifications") === false && !createRpcSubscription) {
|
|
3038
|
+
throw new Error(
|
|
3039
|
+
"Either the notification name must end in 'Notifications' or the API must supply a subscription creator function to map between the notification name and the subscribe/unsubscribe method names."
|
|
3040
|
+
);
|
|
3041
|
+
}
|
|
3042
|
+
const newRequest = createRpcSubscription ? createRpcSubscription(...rawParams) : {
|
|
3043
|
+
params: rawParams,
|
|
3044
|
+
subscribeMethodName: methodName.replace(/Notifications$/, "Subscribe"),
|
|
3045
|
+
unsubscribeMethodName: methodName.replace(/Notifications$/, "Unsubscribe")
|
|
3046
|
+
};
|
|
3047
|
+
return createPendingRpcSubscription(rpcConfig, newRequest);
|
|
3048
|
+
};
|
|
3049
|
+
}
|
|
3050
|
+
});
|
|
3051
|
+
}
|
|
3052
|
+
function createJsonSubscriptionRpc(rpcConfig) {
|
|
3053
|
+
return makeProxy2(rpcConfig);
|
|
3054
|
+
}
|
|
3055
|
+
var e2 = globalThis.fetch;
|
|
669
3056
|
var SolanaHttpError = class extends Error {
|
|
670
3057
|
constructor(details) {
|
|
671
3058
|
super(`HTTP error (${details.statusCode}): ${details.message}`);
|
|
3059
|
+
__publicField(this, "statusCode");
|
|
672
3060
|
Error.captureStackTrace(this, this.constructor);
|
|
673
3061
|
this.statusCode = details.statusCode;
|
|
674
3062
|
}
|
|
@@ -724,16 +3112,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
724
3112
|
}
|
|
725
3113
|
return out;
|
|
726
3114
|
}
|
|
727
|
-
function createHttpTransport({
|
|
3115
|
+
function createHttpTransport({ headers, url }) {
|
|
728
3116
|
if (headers) {
|
|
729
3117
|
assertIsAllowedHttpRequestHeaders(headers);
|
|
730
3118
|
}
|
|
731
|
-
const agent = void 0;
|
|
732
|
-
if (httpAgentNodeOnly != null) {
|
|
733
|
-
console.warn(
|
|
734
|
-
"createHttpTransport(): The `httpAgentNodeOnly` config you supplied has been ignored; HTTP agents are only usable in Node environments."
|
|
735
|
-
);
|
|
736
|
-
}
|
|
737
3119
|
const customHeaders = headers && normalizeHeaders(headers);
|
|
738
3120
|
return async function makeHttpRequest({
|
|
739
3121
|
payload,
|
|
@@ -741,7 +3123,6 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
741
3123
|
}) {
|
|
742
3124
|
const body = JSON.stringify(payload);
|
|
743
3125
|
const requestInfo = {
|
|
744
|
-
agent,
|
|
745
3126
|
body,
|
|
746
3127
|
headers: {
|
|
747
3128
|
...customHeaders,
|
|
@@ -753,7 +3134,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
753
3134
|
method: "POST",
|
|
754
3135
|
signal
|
|
755
3136
|
};
|
|
756
|
-
const response = await
|
|
3137
|
+
const response = await e2(url, requestInfo);
|
|
757
3138
|
if (!response.ok) {
|
|
758
3139
|
throw new SolanaHttpError({
|
|
759
3140
|
message: response.statusText,
|
|
@@ -763,6 +3144,175 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
763
3144
|
return await response.json();
|
|
764
3145
|
};
|
|
765
3146
|
}
|
|
3147
|
+
var e22 = globalThis.WebSocket;
|
|
3148
|
+
var EXPLICIT_ABORT_TOKEN = Symbol(
|
|
3149
|
+
"This symbol is thrown from a socket's iterator when the connection is explicitly aborted by the user"
|
|
3150
|
+
);
|
|
3151
|
+
async function createWebSocketConnection({
|
|
3152
|
+
sendBufferHighWatermark,
|
|
3153
|
+
signal,
|
|
3154
|
+
url
|
|
3155
|
+
}) {
|
|
3156
|
+
return new Promise((resolve, reject) => {
|
|
3157
|
+
signal.addEventListener("abort", handleAbort, { once: true });
|
|
3158
|
+
const iteratorState = /* @__PURE__ */ new Map();
|
|
3159
|
+
function errorAndClearAllIteratorStates(reason) {
|
|
3160
|
+
const errorCallbacks = [...iteratorState.values()].filter((state) => state.__hasPolled).map(({ onError }) => onError);
|
|
3161
|
+
iteratorState.clear();
|
|
3162
|
+
errorCallbacks.forEach((cb) => {
|
|
3163
|
+
try {
|
|
3164
|
+
cb(reason);
|
|
3165
|
+
} catch {
|
|
3166
|
+
}
|
|
3167
|
+
});
|
|
3168
|
+
}
|
|
3169
|
+
function handleAbort() {
|
|
3170
|
+
errorAndClearAllIteratorStates(EXPLICIT_ABORT_TOKEN);
|
|
3171
|
+
if (webSocket.readyState !== e22.CLOSED && webSocket.readyState !== e22.CLOSING) {
|
|
3172
|
+
webSocket.close(1e3);
|
|
3173
|
+
}
|
|
3174
|
+
}
|
|
3175
|
+
function handleClose(ev) {
|
|
3176
|
+
bufferDrainWatcher == null ? void 0 : bufferDrainWatcher.onCancel();
|
|
3177
|
+
signal.removeEventListener("abort", handleAbort);
|
|
3178
|
+
webSocket.removeEventListener("close", handleClose);
|
|
3179
|
+
webSocket.removeEventListener("error", handleError);
|
|
3180
|
+
webSocket.removeEventListener("open", handleOpen);
|
|
3181
|
+
webSocket.removeEventListener("message", handleMessage);
|
|
3182
|
+
errorAndClearAllIteratorStates(ev);
|
|
3183
|
+
}
|
|
3184
|
+
function handleError(ev) {
|
|
3185
|
+
if (!hasConnected) {
|
|
3186
|
+
reject(
|
|
3187
|
+
// TODO: Coded error
|
|
3188
|
+
new Error("WebSocket failed to connect", { cause: ev })
|
|
3189
|
+
);
|
|
3190
|
+
}
|
|
3191
|
+
}
|
|
3192
|
+
let hasConnected = false;
|
|
3193
|
+
let bufferDrainWatcher;
|
|
3194
|
+
function handleOpen() {
|
|
3195
|
+
hasConnected = true;
|
|
3196
|
+
resolve({
|
|
3197
|
+
async send(payload) {
|
|
3198
|
+
const message = JSON.stringify(payload);
|
|
3199
|
+
if (!bufferDrainWatcher && webSocket.readyState === e22.OPEN && webSocket.bufferedAmount > sendBufferHighWatermark) {
|
|
3200
|
+
let onCancel;
|
|
3201
|
+
const promise = new Promise((resolve2, reject2) => {
|
|
3202
|
+
const intervalId = setInterval(() => {
|
|
3203
|
+
if (webSocket.readyState !== e22.OPEN || !(webSocket.bufferedAmount > sendBufferHighWatermark)) {
|
|
3204
|
+
clearInterval(intervalId);
|
|
3205
|
+
bufferDrainWatcher = void 0;
|
|
3206
|
+
resolve2();
|
|
3207
|
+
}
|
|
3208
|
+
}, 16);
|
|
3209
|
+
onCancel = () => {
|
|
3210
|
+
bufferDrainWatcher = void 0;
|
|
3211
|
+
clearInterval(intervalId);
|
|
3212
|
+
reject2(
|
|
3213
|
+
// TODO: Coded error
|
|
3214
|
+
new Error("WebSocket was closed before payload could be sent")
|
|
3215
|
+
);
|
|
3216
|
+
};
|
|
3217
|
+
});
|
|
3218
|
+
bufferDrainWatcher = {
|
|
3219
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
3220
|
+
// @ts-ignore
|
|
3221
|
+
onCancel,
|
|
3222
|
+
promise
|
|
3223
|
+
};
|
|
3224
|
+
}
|
|
3225
|
+
if (bufferDrainWatcher) {
|
|
3226
|
+
await bufferDrainWatcher.promise;
|
|
3227
|
+
}
|
|
3228
|
+
webSocket.send(message);
|
|
3229
|
+
},
|
|
3230
|
+
async *[Symbol.asyncIterator]() {
|
|
3231
|
+
const iteratorKey = Symbol();
|
|
3232
|
+
iteratorState.set(iteratorKey, { __hasPolled: false, queuedMessages: [] });
|
|
3233
|
+
try {
|
|
3234
|
+
while (true) {
|
|
3235
|
+
const state = iteratorState.get(iteratorKey);
|
|
3236
|
+
if (!state) {
|
|
3237
|
+
throw new Error("Invariant: WebSocket message iterator is missing state storage");
|
|
3238
|
+
}
|
|
3239
|
+
if (state.__hasPolled) {
|
|
3240
|
+
throw new Error(
|
|
3241
|
+
"Invariant: WebSocket message iterator state is corrupt; iterated without first resolving existing message promise"
|
|
3242
|
+
);
|
|
3243
|
+
}
|
|
3244
|
+
const queuedMessages = state.queuedMessages;
|
|
3245
|
+
if (queuedMessages.length) {
|
|
3246
|
+
state.queuedMessages = [];
|
|
3247
|
+
yield* queuedMessages;
|
|
3248
|
+
} else {
|
|
3249
|
+
try {
|
|
3250
|
+
yield await new Promise((resolve2, reject2) => {
|
|
3251
|
+
iteratorState.set(iteratorKey, {
|
|
3252
|
+
__hasPolled: true,
|
|
3253
|
+
onError: reject2,
|
|
3254
|
+
onMessage: resolve2
|
|
3255
|
+
});
|
|
3256
|
+
});
|
|
3257
|
+
} catch (e3) {
|
|
3258
|
+
if (e3 === EXPLICIT_ABORT_TOKEN) {
|
|
3259
|
+
return;
|
|
3260
|
+
} else {
|
|
3261
|
+
throw new Error("WebSocket connection closed", { cause: e3 });
|
|
3262
|
+
}
|
|
3263
|
+
}
|
|
3264
|
+
}
|
|
3265
|
+
}
|
|
3266
|
+
} finally {
|
|
3267
|
+
iteratorState.delete(iteratorKey);
|
|
3268
|
+
}
|
|
3269
|
+
}
|
|
3270
|
+
});
|
|
3271
|
+
}
|
|
3272
|
+
function handleMessage({ data }) {
|
|
3273
|
+
const message = JSON.parse(data);
|
|
3274
|
+
iteratorState.forEach((state, iteratorKey) => {
|
|
3275
|
+
if (state.__hasPolled) {
|
|
3276
|
+
const { onMessage } = state;
|
|
3277
|
+
iteratorState.set(iteratorKey, { __hasPolled: false, queuedMessages: [] });
|
|
3278
|
+
onMessage(message);
|
|
3279
|
+
} else {
|
|
3280
|
+
state.queuedMessages.push(message);
|
|
3281
|
+
}
|
|
3282
|
+
});
|
|
3283
|
+
}
|
|
3284
|
+
const webSocket = new e22(url);
|
|
3285
|
+
webSocket.addEventListener("close", handleClose);
|
|
3286
|
+
webSocket.addEventListener("error", handleError);
|
|
3287
|
+
webSocket.addEventListener("open", handleOpen);
|
|
3288
|
+
webSocket.addEventListener("message", handleMessage);
|
|
3289
|
+
});
|
|
3290
|
+
}
|
|
3291
|
+
function createWebSocketTransport({ sendBufferHighWatermark, url }) {
|
|
3292
|
+
if (/^wss?:/i.test(url) === false) {
|
|
3293
|
+
const protocolMatch = url.match(/^([^:]+):/);
|
|
3294
|
+
throw new DOMException(
|
|
3295
|
+
protocolMatch ? `Failed to construct 'WebSocket': The URL's scheme must be either 'ws' or 'wss'. '${protocolMatch[1]}:' is not allowed.` : `Failed to construct 'WebSocket': The URL '${url}' is invalid.`
|
|
3296
|
+
);
|
|
3297
|
+
}
|
|
3298
|
+
return async function sendWebSocketMessage({ payload, signal }) {
|
|
3299
|
+
signal == null ? void 0 : signal.throwIfAborted();
|
|
3300
|
+
const connection = await createWebSocketConnection({
|
|
3301
|
+
sendBufferHighWatermark,
|
|
3302
|
+
signal,
|
|
3303
|
+
url
|
|
3304
|
+
});
|
|
3305
|
+
signal == null ? void 0 : signal.throwIfAborted();
|
|
3306
|
+
await connection.send(payload);
|
|
3307
|
+
return {
|
|
3308
|
+
[Symbol.asyncIterator]: connection[Symbol.asyncIterator].bind(connection),
|
|
3309
|
+
send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: connection.send.bind(connection)
|
|
3310
|
+
};
|
|
3311
|
+
};
|
|
3312
|
+
}
|
|
3313
|
+
|
|
3314
|
+
// src/rpc.ts
|
|
3315
|
+
var import_fast_stable_stringify = __toESM(require_fast_stable_stringify(), 1);
|
|
766
3316
|
|
|
767
3317
|
// src/rpc-default-config.ts
|
|
768
3318
|
init_env_shim();
|
|
@@ -788,6 +3338,9 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
788
3338
|
super(
|
|
789
3339
|
`The ${ordinal} argument to the \`${methodName}\` RPC method${path ? ` at path \`${path}\`` : ""} was \`${value}\`. This number is unsafe for use with the Solana JSON-RPC because it exceeds \`Number.MAX_SAFE_INTEGER\`.`
|
|
790
3340
|
);
|
|
3341
|
+
__publicField(this, "methodName");
|
|
3342
|
+
__publicField(this, "keyPath");
|
|
3343
|
+
__publicField(this, "value");
|
|
791
3344
|
this.keyPath = keyPath;
|
|
792
3345
|
this.methodName = methodName;
|
|
793
3346
|
this.value = value;
|
|
@@ -804,6 +3357,197 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
804
3357
|
}
|
|
805
3358
|
};
|
|
806
3359
|
|
|
3360
|
+
// src/rpc-subscription-coalescer.ts
|
|
3361
|
+
init_env_shim();
|
|
3362
|
+
|
|
3363
|
+
// src/cached-abortable-iterable.ts
|
|
3364
|
+
init_env_shim();
|
|
3365
|
+
function registerIterableCleanup2(iterable, cleanupFn) {
|
|
3366
|
+
(async () => {
|
|
3367
|
+
try {
|
|
3368
|
+
for await (const _ of iterable)
|
|
3369
|
+
;
|
|
3370
|
+
} catch {
|
|
3371
|
+
} finally {
|
|
3372
|
+
cleanupFn();
|
|
3373
|
+
}
|
|
3374
|
+
})();
|
|
3375
|
+
}
|
|
3376
|
+
function getCachedAbortableIterableFactory({
|
|
3377
|
+
getAbortSignalFromInputArgs,
|
|
3378
|
+
getCacheEntryMissingError,
|
|
3379
|
+
getCacheKeyFromInputArgs,
|
|
3380
|
+
onCacheHit,
|
|
3381
|
+
onCreateIterable
|
|
3382
|
+
}) {
|
|
3383
|
+
const cache = /* @__PURE__ */ new Map();
|
|
3384
|
+
function getCacheEntryOrThrow(cacheKey) {
|
|
3385
|
+
const currentCacheEntry = cache.get(cacheKey);
|
|
3386
|
+
if (!currentCacheEntry) {
|
|
3387
|
+
throw getCacheEntryMissingError(cacheKey);
|
|
3388
|
+
}
|
|
3389
|
+
return currentCacheEntry;
|
|
3390
|
+
}
|
|
3391
|
+
return async (...args) => {
|
|
3392
|
+
const cacheKey = getCacheKeyFromInputArgs(...args);
|
|
3393
|
+
const signal = getAbortSignalFromInputArgs(...args);
|
|
3394
|
+
if (cacheKey === void 0) {
|
|
3395
|
+
return await onCreateIterable(signal, ...args);
|
|
3396
|
+
}
|
|
3397
|
+
const cleanup = () => {
|
|
3398
|
+
cache.delete(cacheKey);
|
|
3399
|
+
signal.removeEventListener("abort", handleAbort);
|
|
3400
|
+
};
|
|
3401
|
+
const handleAbort = () => {
|
|
3402
|
+
const cacheEntry = getCacheEntryOrThrow(cacheKey);
|
|
3403
|
+
if (cacheEntry.purgeScheduled !== true) {
|
|
3404
|
+
cacheEntry.purgeScheduled = true;
|
|
3405
|
+
globalThis.queueMicrotask(() => {
|
|
3406
|
+
cacheEntry.purgeScheduled = false;
|
|
3407
|
+
if (cacheEntry.referenceCount === 0) {
|
|
3408
|
+
cacheEntry.abortController.abort();
|
|
3409
|
+
cleanup();
|
|
3410
|
+
}
|
|
3411
|
+
});
|
|
3412
|
+
}
|
|
3413
|
+
cacheEntry.referenceCount--;
|
|
3414
|
+
};
|
|
3415
|
+
signal.addEventListener("abort", handleAbort);
|
|
3416
|
+
try {
|
|
3417
|
+
const cacheEntry = cache.get(cacheKey);
|
|
3418
|
+
if (!cacheEntry) {
|
|
3419
|
+
const singletonAbortController = new AbortController();
|
|
3420
|
+
const newIterablePromise = onCreateIterable(singletonAbortController.signal, ...args);
|
|
3421
|
+
const newCacheEntry = {
|
|
3422
|
+
abortController: singletonAbortController,
|
|
3423
|
+
iterable: newIterablePromise,
|
|
3424
|
+
purgeScheduled: false,
|
|
3425
|
+
referenceCount: 1
|
|
3426
|
+
};
|
|
3427
|
+
cache.set(cacheKey, newCacheEntry);
|
|
3428
|
+
const newIterable = await newIterablePromise;
|
|
3429
|
+
registerIterableCleanup2(newIterable, cleanup);
|
|
3430
|
+
newCacheEntry.iterable = newIterable;
|
|
3431
|
+
return newIterable;
|
|
3432
|
+
} else {
|
|
3433
|
+
cacheEntry.referenceCount++;
|
|
3434
|
+
const iterableOrIterablePromise = cacheEntry.iterable;
|
|
3435
|
+
const cachedIterable = "then" in iterableOrIterablePromise ? await iterableOrIterablePromise : iterableOrIterablePromise;
|
|
3436
|
+
await onCacheHit(cachedIterable, ...args);
|
|
3437
|
+
return cachedIterable;
|
|
3438
|
+
}
|
|
3439
|
+
} catch (e3) {
|
|
3440
|
+
cleanup();
|
|
3441
|
+
throw e3;
|
|
3442
|
+
}
|
|
3443
|
+
};
|
|
3444
|
+
}
|
|
3445
|
+
|
|
3446
|
+
// src/rpc-subscription-coalescer.ts
|
|
3447
|
+
var EXPLICIT_ABORT_TOKEN2 = Symbol(
|
|
3448
|
+
"This symbol is thrown from a subscription's iterator when the subscription is explicitly aborted by the user"
|
|
3449
|
+
);
|
|
3450
|
+
function registerIterableCleanup3(iterable, cleanupFn) {
|
|
3451
|
+
(async () => {
|
|
3452
|
+
try {
|
|
3453
|
+
for await (const _ of iterable)
|
|
3454
|
+
;
|
|
3455
|
+
} catch {
|
|
3456
|
+
} finally {
|
|
3457
|
+
cleanupFn();
|
|
3458
|
+
}
|
|
3459
|
+
})();
|
|
3460
|
+
}
|
|
3461
|
+
function getRpcSubscriptionsWithSubscriptionCoalescing({
|
|
3462
|
+
getDeduplicationKey,
|
|
3463
|
+
rpcSubscriptions
|
|
3464
|
+
}) {
|
|
3465
|
+
const cache = /* @__PURE__ */ new Map();
|
|
3466
|
+
return new Proxy(rpcSubscriptions, {
|
|
3467
|
+
defineProperty() {
|
|
3468
|
+
return false;
|
|
3469
|
+
},
|
|
3470
|
+
deleteProperty() {
|
|
3471
|
+
return false;
|
|
3472
|
+
},
|
|
3473
|
+
get(target, p, receiver) {
|
|
3474
|
+
const subscriptionMethod = Reflect.get(target, p, receiver);
|
|
3475
|
+
if (typeof subscriptionMethod !== "function") {
|
|
3476
|
+
return subscriptionMethod;
|
|
3477
|
+
}
|
|
3478
|
+
return function(...rawParams) {
|
|
3479
|
+
const deduplicationKey = getDeduplicationKey(p, rawParams);
|
|
3480
|
+
if (deduplicationKey === void 0) {
|
|
3481
|
+
return subscriptionMethod(...rawParams);
|
|
3482
|
+
}
|
|
3483
|
+
if (cache.has(deduplicationKey)) {
|
|
3484
|
+
return cache.get(deduplicationKey);
|
|
3485
|
+
}
|
|
3486
|
+
const iterableFactory = getCachedAbortableIterableFactory({
|
|
3487
|
+
getAbortSignalFromInputArgs: ({ abortSignal }) => abortSignal,
|
|
3488
|
+
getCacheEntryMissingError(deduplicationKey2) {
|
|
3489
|
+
return new Error(
|
|
3490
|
+
`Found no cache entry for subscription with deduplication key \`${deduplicationKey2 == null ? void 0 : deduplicationKey2.toString()}\``
|
|
3491
|
+
);
|
|
3492
|
+
},
|
|
3493
|
+
getCacheKeyFromInputArgs: () => deduplicationKey,
|
|
3494
|
+
async onCacheHit(_iterable, _config) {
|
|
3495
|
+
},
|
|
3496
|
+
async onCreateIterable(abortSignal, config) {
|
|
3497
|
+
const pendingSubscription2 = subscriptionMethod(
|
|
3498
|
+
...rawParams
|
|
3499
|
+
);
|
|
3500
|
+
const iterable = await pendingSubscription2.subscribe({
|
|
3501
|
+
...config,
|
|
3502
|
+
abortSignal
|
|
3503
|
+
});
|
|
3504
|
+
registerIterableCleanup3(iterable, () => {
|
|
3505
|
+
cache.delete(deduplicationKey);
|
|
3506
|
+
});
|
|
3507
|
+
return iterable;
|
|
3508
|
+
}
|
|
3509
|
+
});
|
|
3510
|
+
const pendingSubscription = {
|
|
3511
|
+
async subscribe(...args) {
|
|
3512
|
+
const iterable = await iterableFactory(...args);
|
|
3513
|
+
const { abortSignal } = args[0];
|
|
3514
|
+
let abortPromise;
|
|
3515
|
+
return {
|
|
3516
|
+
...iterable,
|
|
3517
|
+
async *[Symbol.asyncIterator]() {
|
|
3518
|
+
abortPromise || (abortPromise = abortSignal.aborted ? Promise.reject(EXPLICIT_ABORT_TOKEN2) : new Promise((_, reject) => {
|
|
3519
|
+
abortSignal.addEventListener("abort", () => {
|
|
3520
|
+
reject(EXPLICIT_ABORT_TOKEN2);
|
|
3521
|
+
});
|
|
3522
|
+
}));
|
|
3523
|
+
try {
|
|
3524
|
+
const iterator = iterable[Symbol.asyncIterator]();
|
|
3525
|
+
while (true) {
|
|
3526
|
+
const iteratorResult = await Promise.race([iterator.next(), abortPromise]);
|
|
3527
|
+
if (iteratorResult.done) {
|
|
3528
|
+
return;
|
|
3529
|
+
} else {
|
|
3530
|
+
yield iteratorResult.value;
|
|
3531
|
+
}
|
|
3532
|
+
}
|
|
3533
|
+
} catch (e3) {
|
|
3534
|
+
if (e3 === EXPLICIT_ABORT_TOKEN2) {
|
|
3535
|
+
return;
|
|
3536
|
+
}
|
|
3537
|
+
cache.delete(deduplicationKey);
|
|
3538
|
+
throw e3;
|
|
3539
|
+
}
|
|
3540
|
+
}
|
|
3541
|
+
};
|
|
3542
|
+
}
|
|
3543
|
+
};
|
|
3544
|
+
cache.set(deduplicationKey, pendingSubscription);
|
|
3545
|
+
return pendingSubscription;
|
|
3546
|
+
};
|
|
3547
|
+
}
|
|
3548
|
+
});
|
|
3549
|
+
}
|
|
3550
|
+
|
|
807
3551
|
// src/rpc.ts
|
|
808
3552
|
function createSolanaRpc(config) {
|
|
809
3553
|
return createJsonRpc({
|
|
@@ -811,6 +3555,24 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
811
3555
|
api: createSolanaRpcApi(DEFAULT_RPC_CONFIG)
|
|
812
3556
|
});
|
|
813
3557
|
}
|
|
3558
|
+
function createSolanaRpcSubscriptions(config) {
|
|
3559
|
+
return pipe(
|
|
3560
|
+
createJsonSubscriptionRpc({
|
|
3561
|
+
...config,
|
|
3562
|
+
api: createSolanaRpcSubscriptionsApi(DEFAULT_RPC_CONFIG)
|
|
3563
|
+
}),
|
|
3564
|
+
(rpcSubscriptions) => getRpcSubscriptionsWithSubscriptionCoalescing({
|
|
3565
|
+
getDeduplicationKey: (...args) => (0, import_fast_stable_stringify.default)(args),
|
|
3566
|
+
rpcSubscriptions
|
|
3567
|
+
})
|
|
3568
|
+
);
|
|
3569
|
+
}
|
|
3570
|
+
function createSolanaRpcSubscriptions_UNSTABLE(config) {
|
|
3571
|
+
return createJsonSubscriptionRpc({
|
|
3572
|
+
...config,
|
|
3573
|
+
api: createSolanaRpcSubscriptionsApi_UNSTABLE(DEFAULT_RPC_CONFIG)
|
|
3574
|
+
});
|
|
3575
|
+
}
|
|
814
3576
|
|
|
815
3577
|
// src/rpc-transport.ts
|
|
816
3578
|
init_env_shim();
|
|
@@ -847,14 +3609,14 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
847
3609
|
if (signal) {
|
|
848
3610
|
const responsePromise = coalescedRequest.responsePromise;
|
|
849
3611
|
return await new Promise((resolve, reject) => {
|
|
850
|
-
const handleAbort = (
|
|
3612
|
+
const handleAbort = (e3) => {
|
|
851
3613
|
signal.removeEventListener("abort", handleAbort);
|
|
852
3614
|
coalescedRequest.numConsumers -= 1;
|
|
853
3615
|
if (coalescedRequest.numConsumers === 0) {
|
|
854
3616
|
const abortController = coalescedRequest.abortController;
|
|
855
3617
|
abortController.abort();
|
|
856
3618
|
}
|
|
857
|
-
const abortError = new DOMException(
|
|
3619
|
+
const abortError = new DOMException(e3.target.reason, "AbortError");
|
|
858
3620
|
reject(abortError);
|
|
859
3621
|
};
|
|
860
3622
|
signal.addEventListener("abort", handleAbort);
|
|
@@ -870,14 +3632,15 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
870
3632
|
|
|
871
3633
|
// src/rpc-request-deduplication.ts
|
|
872
3634
|
init_env_shim();
|
|
873
|
-
var
|
|
874
|
-
function
|
|
3635
|
+
var import_fast_stable_stringify2 = __toESM(require_fast_stable_stringify(), 1);
|
|
3636
|
+
function isJsonRpcPayload(payload) {
|
|
875
3637
|
if (payload == null || typeof payload !== "object" || Array.isArray(payload)) {
|
|
876
|
-
return;
|
|
877
|
-
}
|
|
878
|
-
if ("jsonrpc" in payload && payload.jsonrpc === "2.0" && "method" in payload && "params" in payload) {
|
|
879
|
-
return (0, import_fast_stable_stringify.default)([payload.method, payload.params]);
|
|
3638
|
+
return false;
|
|
880
3639
|
}
|
|
3640
|
+
return "jsonrpc" in payload && payload.jsonrpc === "2.0" && "method" in payload && typeof payload.method === "string" && "params" in payload;
|
|
3641
|
+
}
|
|
3642
|
+
function getSolanaRpcPayloadDeduplicationKey(payload) {
|
|
3643
|
+
return isJsonRpcPayload(payload) ? (0, import_fast_stable_stringify2.default)([payload.method, payload.params]) : void 0;
|
|
881
3644
|
}
|
|
882
3645
|
|
|
883
3646
|
// src/rpc-transport.ts
|
|
@@ -889,34 +3652,488 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
889
3652
|
return out;
|
|
890
3653
|
}
|
|
891
3654
|
function createDefaultRpcTransport(config) {
|
|
892
|
-
|
|
3655
|
+
var _a;
|
|
3656
|
+
return pipe(
|
|
893
3657
|
createHttpTransport({
|
|
894
3658
|
...config,
|
|
895
3659
|
headers: {
|
|
896
3660
|
...config.headers ? normalizeHeaders2(config.headers) : void 0,
|
|
897
3661
|
...{
|
|
898
3662
|
// Keep these headers lowercase so they will override any user-supplied headers above.
|
|
899
|
-
"solana-client": `js/${"2.0.0-development"}`
|
|
3663
|
+
"solana-client": (_a = `js/${"2.0.0-development"}`) != null ? _a : "UNKNOWN"
|
|
3664
|
+
}
|
|
3665
|
+
}
|
|
3666
|
+
}),
|
|
3667
|
+
(transport) => getRpcTransportWithRequestCoalescing(transport, getSolanaRpcPayloadDeduplicationKey)
|
|
3668
|
+
);
|
|
3669
|
+
}
|
|
3670
|
+
|
|
3671
|
+
// src/rpc-websocket-transport.ts
|
|
3672
|
+
init_env_shim();
|
|
3673
|
+
|
|
3674
|
+
// src/rpc-websocket-autopinger.ts
|
|
3675
|
+
init_env_shim();
|
|
3676
|
+
var PING_PAYLOAD = {
|
|
3677
|
+
jsonrpc: "2.0",
|
|
3678
|
+
method: "ping"
|
|
3679
|
+
};
|
|
3680
|
+
function getWebSocketTransportWithAutoping({ intervalMs, transport }) {
|
|
3681
|
+
const pingableConnections = /* @__PURE__ */ new Map();
|
|
3682
|
+
return async (...args) => {
|
|
3683
|
+
const connection = await transport(...args);
|
|
3684
|
+
let intervalId;
|
|
3685
|
+
function sendPing() {
|
|
3686
|
+
connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(PING_PAYLOAD);
|
|
3687
|
+
}
|
|
3688
|
+
function restartPingTimer() {
|
|
3689
|
+
clearInterval(intervalId);
|
|
3690
|
+
intervalId = setInterval(sendPing, intervalMs);
|
|
3691
|
+
}
|
|
3692
|
+
if (pingableConnections.has(connection) === false) {
|
|
3693
|
+
pingableConnections.set(connection, {
|
|
3694
|
+
[Symbol.asyncIterator]: connection[Symbol.asyncIterator].bind(connection),
|
|
3695
|
+
send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: (...args2) => {
|
|
3696
|
+
restartPingTimer();
|
|
3697
|
+
return connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(...args2);
|
|
3698
|
+
}
|
|
3699
|
+
});
|
|
3700
|
+
(async () => {
|
|
3701
|
+
try {
|
|
3702
|
+
for await (const _ of connection) {
|
|
3703
|
+
restartPingTimer();
|
|
3704
|
+
}
|
|
3705
|
+
} catch {
|
|
3706
|
+
} finally {
|
|
3707
|
+
pingableConnections.delete(connection);
|
|
3708
|
+
clearInterval(intervalId);
|
|
3709
|
+
if (handleOffline) {
|
|
3710
|
+
globalThis.window.removeEventListener("offline", handleOffline);
|
|
3711
|
+
}
|
|
3712
|
+
if (handleOnline) {
|
|
3713
|
+
globalThis.window.removeEventListener("online", handleOnline);
|
|
3714
|
+
}
|
|
900
3715
|
}
|
|
3716
|
+
})();
|
|
3717
|
+
if (globalThis.navigator.onLine) {
|
|
3718
|
+
restartPingTimer();
|
|
901
3719
|
}
|
|
3720
|
+
let handleOffline;
|
|
3721
|
+
let handleOnline;
|
|
3722
|
+
{
|
|
3723
|
+
handleOffline = () => {
|
|
3724
|
+
clearInterval(intervalId);
|
|
3725
|
+
};
|
|
3726
|
+
handleOnline = () => {
|
|
3727
|
+
sendPing();
|
|
3728
|
+
restartPingTimer();
|
|
3729
|
+
};
|
|
3730
|
+
globalThis.window.addEventListener("offline", handleOffline);
|
|
3731
|
+
globalThis.window.addEventListener("online", handleOnline);
|
|
3732
|
+
}
|
|
3733
|
+
}
|
|
3734
|
+
return pingableConnections.get(connection);
|
|
3735
|
+
};
|
|
3736
|
+
}
|
|
3737
|
+
|
|
3738
|
+
// src/rpc-websocket-connection-sharding.ts
|
|
3739
|
+
init_env_shim();
|
|
3740
|
+
var NULL_SHARD_CACHE_KEY = Symbol(
|
|
3741
|
+
"Cache key to use when there is no connection sharding strategy"
|
|
3742
|
+
);
|
|
3743
|
+
function getWebSocketTransportWithConnectionSharding({ getShard, transport }) {
|
|
3744
|
+
return getCachedAbortableIterableFactory({
|
|
3745
|
+
getAbortSignalFromInputArgs: ({ signal }) => signal,
|
|
3746
|
+
getCacheEntryMissingError(shardKey) {
|
|
3747
|
+
return new Error(`Found no cache entry for connection with shard key \`${shardKey == null ? void 0 : shardKey.toString()}\``);
|
|
3748
|
+
},
|
|
3749
|
+
getCacheKeyFromInputArgs: ({ payload }) => getShard ? getShard(payload) : NULL_SHARD_CACHE_KEY,
|
|
3750
|
+
onCacheHit: (connection, { payload }) => connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(payload),
|
|
3751
|
+
onCreateIterable: (abortSignal, config) => transport({
|
|
3752
|
+
...config,
|
|
3753
|
+
signal: abortSignal
|
|
3754
|
+
})
|
|
3755
|
+
});
|
|
3756
|
+
}
|
|
3757
|
+
|
|
3758
|
+
// src/rpc-websocket-transport.ts
|
|
3759
|
+
function createDefaultRpcSubscriptionsTransport(config) {
|
|
3760
|
+
var _a;
|
|
3761
|
+
const { getShard, intervalMs, ...rest } = config;
|
|
3762
|
+
return pipe(
|
|
3763
|
+
createWebSocketTransport({
|
|
3764
|
+
...rest,
|
|
3765
|
+
sendBufferHighWatermark: (_a = config.sendBufferHighWatermark) != null ? _a : (
|
|
3766
|
+
// Let 128KB of data into the WebSocket buffer before buffering it in the app.
|
|
3767
|
+
131072
|
|
3768
|
+
)
|
|
902
3769
|
}),
|
|
903
|
-
|
|
3770
|
+
(transport) => getWebSocketTransportWithAutoping({
|
|
3771
|
+
intervalMs: intervalMs != null ? intervalMs : 5e3,
|
|
3772
|
+
transport
|
|
3773
|
+
}),
|
|
3774
|
+
(transport) => getWebSocketTransportWithConnectionSharding({
|
|
3775
|
+
getShard,
|
|
3776
|
+
transport
|
|
3777
|
+
})
|
|
3778
|
+
);
|
|
3779
|
+
}
|
|
3780
|
+
|
|
3781
|
+
// src/send-transaction.ts
|
|
3782
|
+
init_env_shim();
|
|
3783
|
+
|
|
3784
|
+
// src/transaction-confirmation.ts
|
|
3785
|
+
init_env_shim();
|
|
3786
|
+
|
|
3787
|
+
// src/transaction-confirmation-strategy-blockheight.ts
|
|
3788
|
+
init_env_shim();
|
|
3789
|
+
function createBlockHeightExceedencePromiseFactory(rpcSubscriptions) {
|
|
3790
|
+
return async function getBlockHeightExceedencePromise({ abortSignal: callerAbortSignal, lastValidBlockHeight }) {
|
|
3791
|
+
const abortController = new AbortController();
|
|
3792
|
+
function handleAbort() {
|
|
3793
|
+
abortController.abort();
|
|
3794
|
+
}
|
|
3795
|
+
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
3796
|
+
const slotNotifications = await rpcSubscriptions.slotNotifications().subscribe({ abortSignal: abortController.signal });
|
|
3797
|
+
try {
|
|
3798
|
+
for await (const slotNotification of slotNotifications) {
|
|
3799
|
+
if (slotNotification.slot > lastValidBlockHeight) {
|
|
3800
|
+
throw new Error(
|
|
3801
|
+
"The network has progressed past the last block for which this transaction could have committed."
|
|
3802
|
+
);
|
|
3803
|
+
}
|
|
3804
|
+
}
|
|
3805
|
+
} finally {
|
|
3806
|
+
abortController.abort();
|
|
3807
|
+
}
|
|
3808
|
+
};
|
|
3809
|
+
}
|
|
3810
|
+
|
|
3811
|
+
// src/transaction-confirmation-strategy-nonce.ts
|
|
3812
|
+
init_env_shim();
|
|
3813
|
+
var NONCE_VALUE_OFFSET = 4 + // version(u32)
|
|
3814
|
+
4 + // state(u32)
|
|
3815
|
+
32;
|
|
3816
|
+
function createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions) {
|
|
3817
|
+
return async function getNonceInvalidationPromise({
|
|
3818
|
+
abortSignal: callerAbortSignal,
|
|
3819
|
+
commitment,
|
|
3820
|
+
currentNonceValue,
|
|
3821
|
+
nonceAccountAddress
|
|
3822
|
+
}) {
|
|
3823
|
+
const abortController = new AbortController();
|
|
3824
|
+
function handleAbort() {
|
|
3825
|
+
abortController.abort();
|
|
3826
|
+
}
|
|
3827
|
+
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
3828
|
+
const accountNotifications = await rpcSubscriptions.accountNotifications(nonceAccountAddress, { commitment, encoding: "base64" }).subscribe({ abortSignal: abortController.signal });
|
|
3829
|
+
const base58Decoder2 = getBase58Decoder();
|
|
3830
|
+
const base64Encoder = getBase64Encoder();
|
|
3831
|
+
function getNonceFromAccountData([base64EncodedBytes]) {
|
|
3832
|
+
const data = base64Encoder.encode(base64EncodedBytes);
|
|
3833
|
+
const nonceValueBytes = data.slice(NONCE_VALUE_OFFSET, NONCE_VALUE_OFFSET + 32);
|
|
3834
|
+
return base58Decoder2.decode(nonceValueBytes);
|
|
3835
|
+
}
|
|
3836
|
+
const nonceAccountDidAdvancePromise = (async () => {
|
|
3837
|
+
for await (const accountNotification of accountNotifications) {
|
|
3838
|
+
const nonceValue = getNonceFromAccountData(accountNotification.value.data);
|
|
3839
|
+
if (nonceValue !== currentNonceValue) {
|
|
3840
|
+
throw new Error(
|
|
3841
|
+
`The nonce \`${currentNonceValue}\` is no longer valid. It has advanced to \`${nonceValue}\`.`
|
|
3842
|
+
);
|
|
3843
|
+
}
|
|
3844
|
+
}
|
|
3845
|
+
})();
|
|
3846
|
+
const nonceIsAlreadyInvalidPromise = (async () => {
|
|
3847
|
+
const { value: nonceAccount } = await rpc.getAccountInfo(nonceAccountAddress, {
|
|
3848
|
+
commitment,
|
|
3849
|
+
dataSlice: { length: 32, offset: NONCE_VALUE_OFFSET },
|
|
3850
|
+
encoding: "base58"
|
|
3851
|
+
}).send({ abortSignal: abortController.signal });
|
|
3852
|
+
if (!nonceAccount) {
|
|
3853
|
+
throw new Error(`No nonce account could be found at address \`${nonceAccountAddress}\`.`);
|
|
3854
|
+
}
|
|
3855
|
+
const nonceValue = (
|
|
3856
|
+
// This works because we asked for the exact slice of data representing the nonce
|
|
3857
|
+
// value, and furthermore asked for it in `base58` encoding.
|
|
3858
|
+
nonceAccount.data[0]
|
|
3859
|
+
);
|
|
3860
|
+
if (nonceValue !== currentNonceValue) {
|
|
3861
|
+
throw new Error(
|
|
3862
|
+
`The nonce \`${currentNonceValue}\` is no longer valid. It has advanced to \`${nonceValue}\`.`
|
|
3863
|
+
);
|
|
3864
|
+
} else {
|
|
3865
|
+
await new Promise(() => {
|
|
3866
|
+
});
|
|
3867
|
+
}
|
|
3868
|
+
})();
|
|
3869
|
+
try {
|
|
3870
|
+
return await Promise.race([nonceAccountDidAdvancePromise, nonceIsAlreadyInvalidPromise]);
|
|
3871
|
+
} finally {
|
|
3872
|
+
abortController.abort();
|
|
3873
|
+
}
|
|
3874
|
+
};
|
|
3875
|
+
}
|
|
3876
|
+
|
|
3877
|
+
// src/transaction-confirmation.ts
|
|
3878
|
+
function createDefaultDurableNonceTransactionConfirmer({
|
|
3879
|
+
rpc,
|
|
3880
|
+
rpcSubscriptions
|
|
3881
|
+
}) {
|
|
3882
|
+
const getNonceInvalidationPromise = createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions);
|
|
3883
|
+
const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
|
|
3884
|
+
rpc,
|
|
3885
|
+
rpcSubscriptions
|
|
3886
|
+
);
|
|
3887
|
+
return async function confirmDurableNonceTransaction(config) {
|
|
3888
|
+
await waitForDurableNonceTransactionConfirmation({
|
|
3889
|
+
...config,
|
|
3890
|
+
getNonceInvalidationPromise,
|
|
3891
|
+
getRecentSignatureConfirmationPromise
|
|
3892
|
+
});
|
|
3893
|
+
};
|
|
3894
|
+
}
|
|
3895
|
+
function createDefaultRecentTransactionConfirmer({
|
|
3896
|
+
rpc,
|
|
3897
|
+
rpcSubscriptions
|
|
3898
|
+
}) {
|
|
3899
|
+
const getBlockHeightExceedencePromise = createBlockHeightExceedencePromiseFactory(rpcSubscriptions);
|
|
3900
|
+
const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
|
|
3901
|
+
rpc,
|
|
3902
|
+
rpcSubscriptions
|
|
3903
|
+
);
|
|
3904
|
+
return async function confirmRecentTransaction(config) {
|
|
3905
|
+
await waitForRecentTransactionConfirmation({
|
|
3906
|
+
...config,
|
|
3907
|
+
getBlockHeightExceedencePromise,
|
|
3908
|
+
getRecentSignatureConfirmationPromise
|
|
3909
|
+
});
|
|
3910
|
+
};
|
|
3911
|
+
}
|
|
3912
|
+
async function waitForDurableNonceTransactionConfirmation(config) {
|
|
3913
|
+
await raceStrategies(
|
|
3914
|
+
getSignatureFromTransaction(config.transaction),
|
|
3915
|
+
config,
|
|
3916
|
+
function getSpecificStrategiesForRace({ abortSignal, commitment, getNonceInvalidationPromise, transaction }) {
|
|
3917
|
+
return [
|
|
3918
|
+
getNonceInvalidationPromise({
|
|
3919
|
+
abortSignal,
|
|
3920
|
+
commitment,
|
|
3921
|
+
currentNonceValue: transaction.lifetimeConstraint.nonce,
|
|
3922
|
+
nonceAccountAddress: transaction.instructions[0].accounts[0].address
|
|
3923
|
+
})
|
|
3924
|
+
];
|
|
3925
|
+
}
|
|
3926
|
+
);
|
|
3927
|
+
}
|
|
3928
|
+
async function waitForRecentTransactionConfirmation(config) {
|
|
3929
|
+
await raceStrategies(
|
|
3930
|
+
getSignatureFromTransaction(config.transaction),
|
|
3931
|
+
config,
|
|
3932
|
+
function getSpecificStrategiesForRace({ abortSignal, getBlockHeightExceedencePromise, transaction }) {
|
|
3933
|
+
return [
|
|
3934
|
+
getBlockHeightExceedencePromise({
|
|
3935
|
+
abortSignal,
|
|
3936
|
+
lastValidBlockHeight: transaction.lifetimeConstraint.lastValidBlockHeight
|
|
3937
|
+
})
|
|
3938
|
+
];
|
|
3939
|
+
}
|
|
904
3940
|
);
|
|
905
3941
|
}
|
|
906
3942
|
|
|
3943
|
+
// src/send-transaction.ts
|
|
3944
|
+
function getSendTransactionConfigWithAdjustedPreflightCommitment(commitment, config) {
|
|
3945
|
+
if (
|
|
3946
|
+
// The developer has supplied no value for `preflightCommitment`.
|
|
3947
|
+
!(config == null ? void 0 : config.preflightCommitment) && // The value of `commitment` is lower than the server default of `preflightCommitment`.
|
|
3948
|
+
commitmentComparator(
|
|
3949
|
+
commitment,
|
|
3950
|
+
"finalized"
|
|
3951
|
+
/* default value of `preflightCommitment` */
|
|
3952
|
+
) < 0
|
|
3953
|
+
) {
|
|
3954
|
+
return {
|
|
3955
|
+
...config,
|
|
3956
|
+
// In the common case, it is unlikely that you want to simulate a transaction at
|
|
3957
|
+
// `finalized` commitment when your standard of commitment for confirming the
|
|
3958
|
+
// transaction is lower. Cap the simulation commitment level to the level of the
|
|
3959
|
+
// confirmation commitment.
|
|
3960
|
+
preflightCommitment: commitment
|
|
3961
|
+
};
|
|
3962
|
+
}
|
|
3963
|
+
return config;
|
|
3964
|
+
}
|
|
3965
|
+
async function sendTransaction_INTERNAL({
|
|
3966
|
+
abortSignal,
|
|
3967
|
+
commitment,
|
|
3968
|
+
rpc,
|
|
3969
|
+
transaction,
|
|
3970
|
+
...sendTransactionConfig
|
|
3971
|
+
}) {
|
|
3972
|
+
const base64EncodedWireTransaction = getBase64EncodedWireTransaction(transaction);
|
|
3973
|
+
return await rpc.sendTransaction(base64EncodedWireTransaction, {
|
|
3974
|
+
...getSendTransactionConfigWithAdjustedPreflightCommitment(commitment, sendTransactionConfig),
|
|
3975
|
+
encoding: "base64"
|
|
3976
|
+
}).send({ abortSignal });
|
|
3977
|
+
}
|
|
3978
|
+
function createDefaultDurableNonceTransactionSender({
|
|
3979
|
+
rpc,
|
|
3980
|
+
rpcSubscriptions
|
|
3981
|
+
}) {
|
|
3982
|
+
const confirmDurableNonceTransaction = createDefaultDurableNonceTransactionConfirmer({
|
|
3983
|
+
rpc,
|
|
3984
|
+
rpcSubscriptions
|
|
3985
|
+
});
|
|
3986
|
+
return async function sendDurableNonceTransaction(transaction, config) {
|
|
3987
|
+
await sendAndConfirmDurableNonceTransaction({
|
|
3988
|
+
...config,
|
|
3989
|
+
confirmDurableNonceTransaction,
|
|
3990
|
+
rpc,
|
|
3991
|
+
transaction
|
|
3992
|
+
});
|
|
3993
|
+
};
|
|
3994
|
+
}
|
|
3995
|
+
function createDefaultTransactionSender({
|
|
3996
|
+
rpc,
|
|
3997
|
+
rpcSubscriptions
|
|
3998
|
+
}) {
|
|
3999
|
+
const confirmRecentTransaction = createDefaultRecentTransactionConfirmer({
|
|
4000
|
+
rpc,
|
|
4001
|
+
rpcSubscriptions
|
|
4002
|
+
});
|
|
4003
|
+
return async function sendTransaction(transaction, config) {
|
|
4004
|
+
await sendAndConfirmTransaction({
|
|
4005
|
+
...config,
|
|
4006
|
+
confirmRecentTransaction,
|
|
4007
|
+
rpc,
|
|
4008
|
+
transaction
|
|
4009
|
+
});
|
|
4010
|
+
};
|
|
4011
|
+
}
|
|
4012
|
+
async function sendAndConfirmDurableNonceTransaction({
|
|
4013
|
+
abortSignal,
|
|
4014
|
+
commitment,
|
|
4015
|
+
confirmDurableNonceTransaction,
|
|
4016
|
+
rpc,
|
|
4017
|
+
transaction,
|
|
4018
|
+
...sendTransactionConfig
|
|
4019
|
+
}) {
|
|
4020
|
+
const transactionSignature = await sendTransaction_INTERNAL({
|
|
4021
|
+
...sendTransactionConfig,
|
|
4022
|
+
abortSignal,
|
|
4023
|
+
commitment,
|
|
4024
|
+
rpc,
|
|
4025
|
+
transaction
|
|
4026
|
+
});
|
|
4027
|
+
await confirmDurableNonceTransaction({
|
|
4028
|
+
abortSignal,
|
|
4029
|
+
commitment,
|
|
4030
|
+
transaction
|
|
4031
|
+
});
|
|
4032
|
+
return transactionSignature;
|
|
4033
|
+
}
|
|
4034
|
+
async function sendAndConfirmTransaction({
|
|
4035
|
+
abortSignal,
|
|
4036
|
+
commitment,
|
|
4037
|
+
confirmRecentTransaction,
|
|
4038
|
+
rpc,
|
|
4039
|
+
transaction,
|
|
4040
|
+
...sendTransactionConfig
|
|
4041
|
+
}) {
|
|
4042
|
+
const transactionSignature = await sendTransaction_INTERNAL({
|
|
4043
|
+
...sendTransactionConfig,
|
|
4044
|
+
abortSignal,
|
|
4045
|
+
commitment,
|
|
4046
|
+
rpc,
|
|
4047
|
+
transaction
|
|
4048
|
+
});
|
|
4049
|
+
await confirmRecentTransaction({
|
|
4050
|
+
abortSignal,
|
|
4051
|
+
commitment,
|
|
4052
|
+
transaction
|
|
4053
|
+
});
|
|
4054
|
+
return transactionSignature;
|
|
4055
|
+
}
|
|
4056
|
+
|
|
907
4057
|
exports.AccountRole = AccountRole;
|
|
908
|
-
exports.
|
|
4058
|
+
exports.address = address;
|
|
4059
|
+
exports.appendTransactionInstruction = appendTransactionInstruction;
|
|
4060
|
+
exports.assertIsAddress = assertIsAddress;
|
|
4061
|
+
exports.assertIsBlockhash = assertIsBlockhash;
|
|
4062
|
+
exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
|
|
4063
|
+
exports.assertIsLamports = assertIsLamports;
|
|
4064
|
+
exports.assertIsProgramDerivedAddress = assertIsProgramDerivedAddress;
|
|
4065
|
+
exports.assertIsSignature = assertIsSignature;
|
|
4066
|
+
exports.assertIsStringifiedBigInt = assertIsStringifiedBigInt;
|
|
4067
|
+
exports.assertIsStringifiedNumber = assertIsStringifiedNumber;
|
|
4068
|
+
exports.assertIsTransactionWithBlockhashLifetime = assertIsTransactionWithBlockhashLifetime;
|
|
4069
|
+
exports.assertIsUnixTimestamp = assertIsUnixTimestamp;
|
|
4070
|
+
exports.assertTransactionIsFullySigned = assertTransactionIsFullySigned;
|
|
4071
|
+
exports.commitmentComparator = commitmentComparator;
|
|
4072
|
+
exports.compileMessage = compileMessage;
|
|
4073
|
+
exports.createAddressWithSeed = createAddressWithSeed;
|
|
4074
|
+
exports.createBlockHeightExceedencePromiseFactory = createBlockHeightExceedencePromiseFactory;
|
|
4075
|
+
exports.createDefaultAirdropRequester = createDefaultAirdropRequester;
|
|
4076
|
+
exports.createDefaultDurableNonceTransactionConfirmer = createDefaultDurableNonceTransactionConfirmer;
|
|
4077
|
+
exports.createDefaultDurableNonceTransactionSender = createDefaultDurableNonceTransactionSender;
|
|
4078
|
+
exports.createDefaultRecentTransactionConfirmer = createDefaultRecentTransactionConfirmer;
|
|
4079
|
+
exports.createDefaultRpcSubscriptionsTransport = createDefaultRpcSubscriptionsTransport;
|
|
909
4080
|
exports.createDefaultRpcTransport = createDefaultRpcTransport;
|
|
4081
|
+
exports.createDefaultTransactionSender = createDefaultTransactionSender;
|
|
4082
|
+
exports.createNonceInvalidationPromiseFactory = createNonceInvalidationPromiseFactory;
|
|
4083
|
+
exports.createPrivateKeyFromBytes = createPrivateKeyFromBytes;
|
|
4084
|
+
exports.createRecentSignatureConfirmationPromiseFactory = createRecentSignatureConfirmationPromiseFactory;
|
|
910
4085
|
exports.createSolanaRpc = createSolanaRpc;
|
|
4086
|
+
exports.createSolanaRpcSubscriptions = createSolanaRpcSubscriptions;
|
|
4087
|
+
exports.createSolanaRpcSubscriptions_UNSTABLE = createSolanaRpcSubscriptions_UNSTABLE;
|
|
4088
|
+
exports.createTransaction = createTransaction;
|
|
911
4089
|
exports.downgradeRoleToNonSigner = downgradeRoleToNonSigner;
|
|
912
4090
|
exports.downgradeRoleToReadonly = downgradeRoleToReadonly;
|
|
913
|
-
exports.
|
|
914
|
-
exports.
|
|
4091
|
+
exports.generateKeyPair = generateKeyPair;
|
|
4092
|
+
exports.getAddressCodec = getAddressCodec;
|
|
4093
|
+
exports.getAddressComparator = getAddressComparator;
|
|
4094
|
+
exports.getAddressDecoder = getAddressDecoder;
|
|
4095
|
+
exports.getAddressEncoder = getAddressEncoder;
|
|
4096
|
+
exports.getAddressFromPublicKey = getAddressFromPublicKey;
|
|
4097
|
+
exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
|
|
4098
|
+
exports.getCompiledMessageCodec = getCompiledMessageCodec;
|
|
4099
|
+
exports.getCompiledMessageDecoder = getCompiledMessageDecoder;
|
|
4100
|
+
exports.getCompiledMessageEncoder = getCompiledMessageEncoder;
|
|
4101
|
+
exports.getProgramDerivedAddress = getProgramDerivedAddress;
|
|
4102
|
+
exports.getSignatureFromTransaction = getSignatureFromTransaction;
|
|
4103
|
+
exports.getTransactionCodec = getTransactionCodec;
|
|
4104
|
+
exports.getTransactionDecoder = getTransactionDecoder;
|
|
4105
|
+
exports.getTransactionEncoder = getTransactionEncoder;
|
|
4106
|
+
exports.isAddress = isAddress;
|
|
4107
|
+
exports.isAdvanceNonceAccountInstruction = isAdvanceNonceAccountInstruction;
|
|
4108
|
+
exports.isLamports = isLamports;
|
|
4109
|
+
exports.isProgramDerivedAddress = isProgramDerivedAddress;
|
|
4110
|
+
exports.isSignature = isSignature;
|
|
915
4111
|
exports.isSignerRole = isSignerRole;
|
|
4112
|
+
exports.isStringifiedBigInt = isStringifiedBigInt;
|
|
4113
|
+
exports.isStringifiedNumber = isStringifiedNumber;
|
|
4114
|
+
exports.isUnixTimestamp = isUnixTimestamp;
|
|
916
4115
|
exports.isWritableRole = isWritableRole;
|
|
4116
|
+
exports.lamports = lamports;
|
|
917
4117
|
exports.mergeRoles = mergeRoles;
|
|
4118
|
+
exports.partiallySignTransaction = partiallySignTransaction;
|
|
4119
|
+
exports.prependTransactionInstruction = prependTransactionInstruction;
|
|
4120
|
+
exports.requestAndConfirmAirdrop = requestAndConfirmAirdrop;
|
|
4121
|
+
exports.sendAndConfirmDurableNonceTransaction = sendAndConfirmDurableNonceTransaction;
|
|
4122
|
+
exports.sendAndConfirmTransaction = sendAndConfirmTransaction;
|
|
4123
|
+
exports.setTransactionFeePayer = setTransactionFeePayer;
|
|
4124
|
+
exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
|
|
4125
|
+
exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
|
|
4126
|
+
exports.signBytes = signBytes;
|
|
4127
|
+
exports.signTransaction = signTransaction;
|
|
4128
|
+
exports.signature = signature;
|
|
4129
|
+
exports.stringifiedBigInt = stringifiedBigInt;
|
|
4130
|
+
exports.stringifiedNumber = stringifiedNumber;
|
|
4131
|
+
exports.unixTimestamp = unixTimestamp;
|
|
918
4132
|
exports.upgradeRoleToSigner = upgradeRoleToSigner;
|
|
919
4133
|
exports.upgradeRoleToWritable = upgradeRoleToWritable;
|
|
4134
|
+
exports.verifySignature = verifySignature;
|
|
4135
|
+
exports.waitForDurableNonceTransactionConfirmation = waitForDurableNonceTransactionConfirmation;
|
|
4136
|
+
exports.waitForRecentTransactionConfirmation = waitForRecentTransactionConfirmation;
|
|
920
4137
|
|
|
921
4138
|
return exports;
|
|
922
4139
|
|