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