@solana/web3.js 2.0.0-experimental.a8f1f88 → 2.0.0-experimental.a9e6db3
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 +4 -4
- package/dist/index.browser.cjs +572 -18
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +566 -20
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +2196 -853
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +555 -20
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +563 -18
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +555 -20
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +52 -32
- package/dist/types/airdrop-confirmer.d.ts +20 -0
- package/dist/types/airdrop.d.ts +18 -0
- package/dist/types/cached-abortable-iterable.d.ts +11 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/rpc-subscription-coalescer.d.ts +10 -0
- package/dist/types/rpc-websocket-connection-sharding.d.ts +13 -0
- package/dist/types/rpc-websocket-transport.d.ts +6 -0
- package/dist/types/rpc.d.ts +2 -1
- package/dist/types/transaction-confirmation-strategy-blockheight.d.ts +10 -0
- package/dist/types/transaction-confirmation-strategy-nonce.d.ts +15 -0
- package/dist/types/transaction-confirmation-strategy-racer.d.ts +10 -0
- package/dist/types/transaction-confirmation-strategy-recent-signature.d.ts +13 -0
- package/dist/types/transaction-confirmation-strategy-timeout.d.ts +8 -0
- package/dist/types/transaction-confirmation.d.ts +37 -0
- package/package.json +15 -13
|
@@ -125,19 +125,31 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
125
125
|
// ../addresses/dist/index.browser.js
|
|
126
126
|
init_env_shim();
|
|
127
127
|
|
|
128
|
-
//
|
|
129
|
-
init_env_shim();
|
|
130
|
-
|
|
131
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/index.mjs
|
|
128
|
+
// ../codecs-core/dist/index.browser.js
|
|
132
129
|
init_env_shim();
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
130
|
+
function assertByteArrayIsNotEmptyForCodec(codecDescription, bytes2, offset = 0) {
|
|
131
|
+
if (bytes2.length - offset <= 0) {
|
|
132
|
+
throw new Error(`Codec [${codecDescription}] cannot decode empty byte arrays.`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function assertByteArrayHasEnoughBytesForCodec(codecDescription, expected, bytes2, offset = 0) {
|
|
136
|
+
const bytesLength = bytes2.length - offset;
|
|
137
|
+
if (bytesLength < expected) {
|
|
138
|
+
throw new Error(`Codec [${codecDescription}] expected ${expected} bytes, got ${bytesLength}.`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
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);
|
|
138
150
|
const result = new Uint8Array(totalLength);
|
|
139
151
|
let offset = 0;
|
|
140
|
-
|
|
152
|
+
nonEmptyByteArrays.forEach((arr) => {
|
|
141
153
|
result.set(arr, offset);
|
|
142
154
|
offset += arr.length;
|
|
143
155
|
});
|
|
@@ -150,100 +162,175 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
150
162
|
paddedBytes.set(bytes2);
|
|
151
163
|
return paddedBytes;
|
|
152
164
|
};
|
|
153
|
-
var fixBytes = (bytes2, length) => padBytes(bytes2.slice(0, length), length);
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
super(`Serializer [${serializer}] cannot deserialize empty buffers.`);
|
|
160
|
-
__publicField(this, "name", "DeserializingEmptyBufferError");
|
|
165
|
+
var fixBytes = (bytes2, length) => padBytes(bytes2.length <= length ? bytes2 : bytes2.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
|
+
);
|
|
161
171
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
__publicField(this, "name", "NotEnoughBytesError");
|
|
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
|
+
);
|
|
167
176
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
super(message);
|
|
173
|
-
__publicField(this, "name", "ExpectedFixedSizeSerializerError");
|
|
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
|
+
);
|
|
174
181
|
}
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/fixSerializer.mjs
|
|
178
|
-
init_env_shim();
|
|
179
|
-
function fixSerializer(serializer, fixedBytes, description) {
|
|
180
182
|
return {
|
|
181
|
-
|
|
183
|
+
decode: decoder.decode,
|
|
184
|
+
description: description ?? encoder.description,
|
|
185
|
+
encode: encoder.encode,
|
|
186
|
+
fixedSize: encoder.fixedSize,
|
|
187
|
+
maxSize: encoder.maxSize
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
function fixCodecHelper(data, fixedBytes, description) {
|
|
191
|
+
return {
|
|
192
|
+
description: description ?? `fixed(${fixedBytes}, ${data.description})`,
|
|
182
193
|
fixedSize: fixedBytes,
|
|
183
|
-
maxSize: fixedBytes
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
194
|
+
maxSize: fixedBytes
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
function fixEncoder(encoder, fixedBytes, description) {
|
|
198
|
+
return {
|
|
199
|
+
...fixCodecHelper(encoder, fixedBytes, description),
|
|
200
|
+
encode: (value) => fixBytes(encoder.encode(value), fixedBytes)
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
function fixDecoder(decoder, fixedBytes, description) {
|
|
204
|
+
return {
|
|
205
|
+
...fixCodecHelper(decoder, fixedBytes, description),
|
|
206
|
+
decode: (bytes2, offset = 0) => {
|
|
207
|
+
assertByteArrayHasEnoughBytesForCodec("fixCodec", fixedBytes, bytes2, offset);
|
|
208
|
+
if (offset > 0 || bytes2.length > fixedBytes) {
|
|
209
|
+
bytes2 = bytes2.slice(offset, offset + fixedBytes);
|
|
189
210
|
}
|
|
190
|
-
if (
|
|
191
|
-
|
|
211
|
+
if (decoder.fixedSize !== null) {
|
|
212
|
+
bytes2 = fixBytes(bytes2, decoder.fixedSize);
|
|
192
213
|
}
|
|
193
|
-
const [value] =
|
|
214
|
+
const [value] = decoder.decode(bytes2, 0);
|
|
194
215
|
return [value, offset + fixedBytes];
|
|
195
216
|
}
|
|
196
217
|
};
|
|
197
218
|
}
|
|
198
|
-
|
|
199
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/mapSerializer.mjs
|
|
200
|
-
init_env_shim();
|
|
201
|
-
function mapSerializer(serializer, unmap, map) {
|
|
219
|
+
function mapEncoder(encoder, unmap) {
|
|
202
220
|
return {
|
|
203
|
-
description:
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
deserialize: (buffer, offset = 0) => {
|
|
208
|
-
const [value, length] = serializer.deserialize(buffer, offset);
|
|
209
|
-
return map ? [map(value, buffer, offset), length] : [value, length];
|
|
210
|
-
}
|
|
221
|
+
description: encoder.description,
|
|
222
|
+
encode: (value) => encoder.encode(unmap(value)),
|
|
223
|
+
fixedSize: encoder.fixedSize,
|
|
224
|
+
maxSize: encoder.maxSize
|
|
211
225
|
};
|
|
212
226
|
}
|
|
213
227
|
|
|
214
|
-
//
|
|
215
|
-
init_env_shim();
|
|
216
|
-
|
|
217
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/baseX.mjs
|
|
228
|
+
// ../codecs-strings/dist/index.browser.js
|
|
218
229
|
init_env_shim();
|
|
219
230
|
|
|
220
|
-
//
|
|
231
|
+
// ../codecs-numbers/dist/index.browser.js
|
|
221
232
|
init_env_shim();
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
this.cause = cause;
|
|
233
|
+
function assertNumberIsBetweenForCodec(codecDescription, min, max, value) {
|
|
234
|
+
if (value < min || value > max) {
|
|
235
|
+
throw new Error(
|
|
236
|
+
`Codec [${codecDescription}] expected number to be in the range [${min}, ${max}], got ${value}.`
|
|
237
|
+
);
|
|
228
238
|
}
|
|
229
|
-
}
|
|
239
|
+
}
|
|
240
|
+
function sharedNumberFactory(input) {
|
|
241
|
+
let littleEndian;
|
|
242
|
+
let defaultDescription = input.name;
|
|
243
|
+
if (input.size > 1) {
|
|
244
|
+
littleEndian = !("endian" in input.options) || input.options.endian === 0;
|
|
245
|
+
defaultDescription += littleEndian ? "(le)" : "(be)";
|
|
246
|
+
}
|
|
247
|
+
return {
|
|
248
|
+
description: input.options.description ?? defaultDescription,
|
|
249
|
+
fixedSize: input.size,
|
|
250
|
+
littleEndian,
|
|
251
|
+
maxSize: input.size
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
function numberEncoderFactory(input) {
|
|
255
|
+
const codecData = sharedNumberFactory(input);
|
|
256
|
+
return {
|
|
257
|
+
description: codecData.description,
|
|
258
|
+
encode(value) {
|
|
259
|
+
if (input.range) {
|
|
260
|
+
assertNumberIsBetweenForCodec(input.name, input.range[0], input.range[1], value);
|
|
261
|
+
}
|
|
262
|
+
const arrayBuffer = new ArrayBuffer(input.size);
|
|
263
|
+
input.set(new DataView(arrayBuffer), value, codecData.littleEndian);
|
|
264
|
+
return new Uint8Array(arrayBuffer);
|
|
265
|
+
},
|
|
266
|
+
fixedSize: codecData.fixedSize,
|
|
267
|
+
maxSize: codecData.maxSize
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
function numberDecoderFactory(input) {
|
|
271
|
+
const codecData = sharedNumberFactory(input);
|
|
272
|
+
return {
|
|
273
|
+
decode(bytes2, offset = 0) {
|
|
274
|
+
assertByteArrayIsNotEmptyForCodec(codecData.description, bytes2, offset);
|
|
275
|
+
assertByteArrayHasEnoughBytesForCodec(codecData.description, input.size, bytes2, offset);
|
|
276
|
+
const view = new DataView(toArrayBuffer(bytes2, offset, input.size));
|
|
277
|
+
return [input.get(view, codecData.littleEndian), offset + input.size];
|
|
278
|
+
},
|
|
279
|
+
description: codecData.description,
|
|
280
|
+
fixedSize: codecData.fixedSize,
|
|
281
|
+
maxSize: codecData.maxSize
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
function toArrayBuffer(bytes2, offset, length) {
|
|
285
|
+
const bytesOffset = bytes2.byteOffset + (offset ?? 0);
|
|
286
|
+
const bytesLength = length ?? bytes2.byteLength;
|
|
287
|
+
return bytes2.buffer.slice(bytesOffset, bytesOffset + bytesLength);
|
|
288
|
+
}
|
|
289
|
+
var getU32Encoder = (options = {}) => numberEncoderFactory({
|
|
290
|
+
name: "u32",
|
|
291
|
+
options,
|
|
292
|
+
range: [0, Number("0xffffffff")],
|
|
293
|
+
set: (view, value, le) => view.setUint32(0, value, le),
|
|
294
|
+
size: 4
|
|
295
|
+
});
|
|
296
|
+
var getU32Decoder = (options = {}) => numberDecoderFactory({
|
|
297
|
+
get: (view, le) => view.getUint32(0, le),
|
|
298
|
+
name: "u32",
|
|
299
|
+
options,
|
|
300
|
+
size: 4
|
|
301
|
+
});
|
|
302
|
+
var getU8Encoder = (options = {}) => numberEncoderFactory({
|
|
303
|
+
name: "u8",
|
|
304
|
+
options,
|
|
305
|
+
range: [0, Number("0xff")],
|
|
306
|
+
set: (view, value) => view.setUint8(0, value),
|
|
307
|
+
size: 1
|
|
308
|
+
});
|
|
309
|
+
var getU8Decoder = (options = {}) => numberDecoderFactory({
|
|
310
|
+
get: (view) => view.getUint8(0),
|
|
311
|
+
name: "u8",
|
|
312
|
+
options,
|
|
313
|
+
size: 1
|
|
314
|
+
});
|
|
315
|
+
var getU8Codec = (options = {}) => combineCodec(getU8Encoder(options), getU8Decoder(options));
|
|
230
316
|
|
|
231
|
-
//
|
|
232
|
-
|
|
233
|
-
|
|
317
|
+
// ../codecs-strings/dist/index.browser.js
|
|
318
|
+
function assertValidBaseString(alphabet4, testValue, givenValue = testValue) {
|
|
319
|
+
if (!testValue.match(new RegExp(`^[${alphabet4}]*$`))) {
|
|
320
|
+
throw new Error(`Expected a string of base ${alphabet4.length}, got [${givenValue}].`);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
var getBaseXEncoder = (alphabet4) => {
|
|
324
|
+
const base = alphabet4.length;
|
|
234
325
|
const baseBigInt = BigInt(base);
|
|
235
326
|
return {
|
|
236
327
|
description: `base${base}`,
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
serialize(value) {
|
|
240
|
-
if (!value.match(new RegExp(`^[${alphabet}]*$`))) {
|
|
241
|
-
throw new InvalidBaseStringError(value, base);
|
|
242
|
-
}
|
|
328
|
+
encode(value) {
|
|
329
|
+
assertValidBaseString(alphabet4, value);
|
|
243
330
|
if (value === "")
|
|
244
331
|
return new Uint8Array();
|
|
245
332
|
const chars = [...value];
|
|
246
|
-
let trailIndex = chars.findIndex((c) => c !==
|
|
333
|
+
let trailIndex = chars.findIndex((c) => c !== alphabet4[0]);
|
|
247
334
|
trailIndex = trailIndex === -1 ? chars.length : trailIndex;
|
|
248
335
|
const leadingZeroes = Array(trailIndex).fill(0);
|
|
249
336
|
if (trailIndex === chars.length)
|
|
@@ -252,7 +339,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
252
339
|
let base10Number = 0n;
|
|
253
340
|
let baseXPower = 1n;
|
|
254
341
|
for (let i = tailChars.length - 1; i >= 0; i -= 1) {
|
|
255
|
-
base10Number += baseXPower * BigInt(
|
|
342
|
+
base10Number += baseXPower * BigInt(alphabet4.indexOf(tailChars[i]));
|
|
256
343
|
baseXPower *= baseBigInt;
|
|
257
344
|
}
|
|
258
345
|
const tailBytes = [];
|
|
@@ -262,510 +349,283 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
262
349
|
}
|
|
263
350
|
return Uint8Array.from(leadingZeroes.concat(tailBytes));
|
|
264
351
|
},
|
|
265
|
-
|
|
266
|
-
|
|
352
|
+
fixedSize: null,
|
|
353
|
+
maxSize: null
|
|
354
|
+
};
|
|
355
|
+
};
|
|
356
|
+
var getBaseXDecoder = (alphabet4) => {
|
|
357
|
+
const base = alphabet4.length;
|
|
358
|
+
const baseBigInt = BigInt(base);
|
|
359
|
+
return {
|
|
360
|
+
decode(rawBytes, offset = 0) {
|
|
361
|
+
const bytes2 = offset === 0 ? rawBytes : rawBytes.slice(offset);
|
|
362
|
+
if (bytes2.length === 0)
|
|
267
363
|
return ["", 0];
|
|
268
|
-
const bytes2 = buffer.slice(offset);
|
|
269
364
|
let trailIndex = bytes2.findIndex((n) => n !== 0);
|
|
270
365
|
trailIndex = trailIndex === -1 ? bytes2.length : trailIndex;
|
|
271
|
-
const leadingZeroes =
|
|
366
|
+
const leadingZeroes = alphabet4[0].repeat(trailIndex);
|
|
272
367
|
if (trailIndex === bytes2.length)
|
|
273
|
-
return [leadingZeroes,
|
|
368
|
+
return [leadingZeroes, rawBytes.length];
|
|
274
369
|
let base10Number = bytes2.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
|
|
275
370
|
const tailChars = [];
|
|
276
371
|
while (base10Number > 0n) {
|
|
277
|
-
tailChars.unshift(
|
|
372
|
+
tailChars.unshift(alphabet4[Number(base10Number % baseBigInt)]);
|
|
278
373
|
base10Number /= baseBigInt;
|
|
279
374
|
}
|
|
280
|
-
return [leadingZeroes + tailChars.join(""),
|
|
281
|
-
}
|
|
375
|
+
return [leadingZeroes + tailChars.join(""), rawBytes.length];
|
|
376
|
+
},
|
|
377
|
+
description: `base${base}`,
|
|
378
|
+
fixedSize: null,
|
|
379
|
+
maxSize: null
|
|
282
380
|
};
|
|
283
381
|
};
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
var base58 = baseX("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
|
|
288
|
-
|
|
289
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/nullCharacters.mjs
|
|
290
|
-
init_env_shim();
|
|
382
|
+
var alphabet2 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
383
|
+
var getBase58Encoder = () => getBaseXEncoder(alphabet2);
|
|
384
|
+
var getBase58Decoder = () => getBaseXDecoder(alphabet2);
|
|
291
385
|
var removeNullCharacters = (value) => (
|
|
292
386
|
// eslint-disable-next-line no-control-regex
|
|
293
387
|
value.replace(/\u0000/g, "")
|
|
294
388
|
);
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
}
|
|
305
|
-
deserialize(buffer, offset = 0) {
|
|
306
|
-
const value = new TextDecoder().decode(buffer.slice(offset));
|
|
307
|
-
return [removeNullCharacters(value), buffer.length];
|
|
308
|
-
}
|
|
389
|
+
var e = globalThis.TextDecoder;
|
|
390
|
+
var o = globalThis.TextEncoder;
|
|
391
|
+
var getUtf8Encoder = () => {
|
|
392
|
+
let textEncoder;
|
|
393
|
+
return {
|
|
394
|
+
description: "utf8",
|
|
395
|
+
encode: (value) => new Uint8Array((textEncoder || (textEncoder = new o())).encode(value)),
|
|
396
|
+
fixedSize: null,
|
|
397
|
+
maxSize: null
|
|
398
|
+
};
|
|
309
399
|
};
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/errors.mjs
|
|
323
|
-
init_env_shim();
|
|
324
|
-
var NumberOutOfRangeError = class extends RangeError {
|
|
325
|
-
constructor(serializer, min, max, actual) {
|
|
326
|
-
super(`Serializer [${serializer}] expected number to be between ${min} and ${max}, got ${actual}.`);
|
|
327
|
-
__publicField(this, "name", "NumberOutOfRangeError");
|
|
328
|
-
}
|
|
400
|
+
var getUtf8Decoder = () => {
|
|
401
|
+
let textDecoder;
|
|
402
|
+
return {
|
|
403
|
+
decode(bytes2, offset = 0) {
|
|
404
|
+
const value = (textDecoder || (textDecoder = new e())).decode(bytes2.slice(offset));
|
|
405
|
+
return [removeNullCharacters(value), bytes2.length];
|
|
406
|
+
},
|
|
407
|
+
description: "utf8",
|
|
408
|
+
fixedSize: null,
|
|
409
|
+
maxSize: null
|
|
410
|
+
};
|
|
329
411
|
};
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
412
|
+
var getStringEncoder = (options = {}) => {
|
|
413
|
+
const size = options.size ?? getU32Encoder();
|
|
414
|
+
const encoding = options.encoding ?? getUtf8Encoder();
|
|
415
|
+
const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
|
|
416
|
+
if (size === "variable") {
|
|
417
|
+
return { ...encoding, description };
|
|
418
|
+
}
|
|
419
|
+
if (typeof size === "number") {
|
|
420
|
+
return fixEncoder(encoding, size, description);
|
|
339
421
|
}
|
|
340
422
|
return {
|
|
341
|
-
description
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
assertRange(input.name, input.range[0], input.range[1], value);
|
|
347
|
-
}
|
|
348
|
-
const buffer = new ArrayBuffer(input.size);
|
|
349
|
-
input.set(new DataView(buffer), value, littleEndian);
|
|
350
|
-
return new Uint8Array(buffer);
|
|
423
|
+
description,
|
|
424
|
+
encode: (value) => {
|
|
425
|
+
const contentBytes = encoding.encode(value);
|
|
426
|
+
const lengthBytes = size.encode(contentBytes.length);
|
|
427
|
+
return mergeBytes([lengthBytes, contentBytes]);
|
|
351
428
|
},
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
assertEnoughBytes("i8", slice, input.size);
|
|
355
|
-
const view = toDataView(slice);
|
|
356
|
-
return [input.get(view, littleEndian), offset + input.size];
|
|
357
|
-
}
|
|
429
|
+
fixedSize: null,
|
|
430
|
+
maxSize: null
|
|
358
431
|
};
|
|
359
|
-
}
|
|
360
|
-
var toArrayBuffer = (array2) => array2.buffer.slice(array2.byteOffset, array2.byteLength + array2.byteOffset);
|
|
361
|
-
var toDataView = (array2) => new DataView(toArrayBuffer(array2));
|
|
362
|
-
var assertRange = (serializer, min, max, value) => {
|
|
363
|
-
if (value < min || value > max) {
|
|
364
|
-
throw new NumberOutOfRangeError(serializer, min, max, value);
|
|
365
|
-
}
|
|
366
432
|
};
|
|
367
|
-
var
|
|
368
|
-
|
|
369
|
-
|
|
433
|
+
var getStringDecoder = (options = {}) => {
|
|
434
|
+
const size = options.size ?? getU32Decoder();
|
|
435
|
+
const encoding = options.encoding ?? getUtf8Decoder();
|
|
436
|
+
const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
|
|
437
|
+
if (size === "variable") {
|
|
438
|
+
return { ...encoding, description };
|
|
370
439
|
}
|
|
371
|
-
if (
|
|
372
|
-
|
|
440
|
+
if (typeof size === "number") {
|
|
441
|
+
return fixDecoder(encoding, size, description);
|
|
373
442
|
}
|
|
443
|
+
return {
|
|
444
|
+
decode: (bytes2, offset = 0) => {
|
|
445
|
+
assertByteArrayIsNotEmptyForCodec("string", bytes2, offset);
|
|
446
|
+
const [lengthBigInt, lengthOffset] = size.decode(bytes2, offset);
|
|
447
|
+
const length = Number(lengthBigInt);
|
|
448
|
+
offset = lengthOffset;
|
|
449
|
+
const contentBytes = bytes2.slice(offset, offset + length);
|
|
450
|
+
assertByteArrayHasEnoughBytesForCodec("string", length, contentBytes);
|
|
451
|
+
const [value, contentOffset] = encoding.decode(contentBytes);
|
|
452
|
+
offset += contentOffset;
|
|
453
|
+
return [value, offset];
|
|
454
|
+
},
|
|
455
|
+
description,
|
|
456
|
+
fixedSize: null,
|
|
457
|
+
maxSize: null
|
|
458
|
+
};
|
|
374
459
|
};
|
|
460
|
+
function getSizeDescription(size) {
|
|
461
|
+
return typeof size === "object" ? size.description : `${size}`;
|
|
462
|
+
}
|
|
375
463
|
|
|
376
|
-
//
|
|
377
|
-
init_env_shim();
|
|
378
|
-
var u8 = (options = {}) => numberFactory({
|
|
379
|
-
name: "u8",
|
|
380
|
-
size: 1,
|
|
381
|
-
range: [0, Number("0xff")],
|
|
382
|
-
set: (view, value) => view.setUint8(0, Number(value)),
|
|
383
|
-
get: (view) => view.getUint8(0),
|
|
384
|
-
options
|
|
385
|
-
});
|
|
386
|
-
|
|
387
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/u32.mjs
|
|
388
|
-
init_env_shim();
|
|
389
|
-
var u32 = (options = {}) => numberFactory({
|
|
390
|
-
name: "u32",
|
|
391
|
-
size: 4,
|
|
392
|
-
range: [0, Number("0xffffffff")],
|
|
393
|
-
set: (view, value, le) => view.setUint32(0, Number(value), le),
|
|
394
|
-
get: (view, le) => view.getUint32(0, le),
|
|
395
|
-
options
|
|
396
|
-
});
|
|
397
|
-
|
|
398
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/shortU16.mjs
|
|
464
|
+
// ../assertions/dist/index.browser.js
|
|
399
465
|
init_env_shim();
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
assertRange("shortU16", 0, 65535, value);
|
|
406
|
-
const bytes2 = [0];
|
|
407
|
-
for (let ii = 0; ; ii += 1) {
|
|
408
|
-
const alignedValue = value >> ii * 7;
|
|
409
|
-
if (alignedValue === 0) {
|
|
410
|
-
break;
|
|
411
|
-
}
|
|
412
|
-
const nextSevenBits = 127 & alignedValue;
|
|
413
|
-
bytes2[ii] = nextSevenBits;
|
|
414
|
-
if (ii > 0) {
|
|
415
|
-
bytes2[ii - 1] |= 128;
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
return new Uint8Array(bytes2);
|
|
419
|
-
},
|
|
420
|
-
deserialize: (bytes2, offset = 0) => {
|
|
421
|
-
let value = 0;
|
|
422
|
-
let byteCount = 0;
|
|
423
|
-
while (++byteCount) {
|
|
424
|
-
const byteIndex = byteCount - 1;
|
|
425
|
-
const currentByte = bytes2[offset + byteIndex];
|
|
426
|
-
const nextSevenBits = 127 & currentByte;
|
|
427
|
-
value |= nextSevenBits << byteIndex * 7;
|
|
428
|
-
if ((currentByte & 128) === 0) {
|
|
429
|
-
break;
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
return [value, offset + byteCount];
|
|
466
|
+
function assertIsSecureContext() {
|
|
467
|
+
if (!globalThis.isSecureContext) {
|
|
468
|
+
throw new Error(
|
|
469
|
+
"Cryptographic operations are only allowed in secure browser contexts. Read more here: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts"
|
|
470
|
+
);
|
|
433
471
|
}
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
472
|
+
}
|
|
473
|
+
var cachedEd25519Decision;
|
|
474
|
+
async function isEd25519CurveSupported(subtle) {
|
|
475
|
+
if (cachedEd25519Decision === void 0) {
|
|
476
|
+
cachedEd25519Decision = new Promise((resolve) => {
|
|
477
|
+
subtle.generateKey(
|
|
478
|
+
"Ed25519",
|
|
479
|
+
/* extractable */
|
|
480
|
+
false,
|
|
481
|
+
["sign", "verify"]
|
|
482
|
+
).catch(() => {
|
|
483
|
+
resolve(cachedEd25519Decision = false);
|
|
484
|
+
}).then(() => {
|
|
485
|
+
resolve(cachedEd25519Decision = true);
|
|
486
|
+
});
|
|
487
|
+
});
|
|
445
488
|
}
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
__publicField(this, "name", "InvalidArrayLikeRemainderSizeError");
|
|
489
|
+
if (typeof cachedEd25519Decision === "boolean") {
|
|
490
|
+
return cachedEd25519Decision;
|
|
491
|
+
} else {
|
|
492
|
+
return await cachedEd25519Decision;
|
|
451
493
|
}
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
494
|
+
}
|
|
495
|
+
async function assertDigestCapabilityIsAvailable() {
|
|
496
|
+
assertIsSecureContext();
|
|
497
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.digest !== "function") {
|
|
498
|
+
throw new Error("No digest implementation could be found");
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
async function assertKeyGenerationIsAvailable() {
|
|
502
|
+
assertIsSecureContext();
|
|
503
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.generateKey !== "function") {
|
|
504
|
+
throw new Error("No key generation implementation could be found");
|
|
505
|
+
}
|
|
506
|
+
if (!await isEd25519CurveSupported(globalThis.crypto.subtle)) {
|
|
507
|
+
throw new Error(
|
|
508
|
+
"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"
|
|
509
|
+
);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
async function assertKeyExporterIsAvailable() {
|
|
513
|
+
assertIsSecureContext();
|
|
514
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.exportKey !== "function") {
|
|
515
|
+
throw new Error("No key export implementation could be found");
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
async function assertSigningCapabilityIsAvailable() {
|
|
519
|
+
assertIsSecureContext();
|
|
520
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.sign !== "function") {
|
|
521
|
+
throw new Error("No signing implementation could be found");
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
async function assertVerificationCapabilityIsAvailable() {
|
|
525
|
+
assertIsSecureContext();
|
|
526
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.verify !== "function") {
|
|
527
|
+
throw new Error("No signature verification implementation could be found");
|
|
457
528
|
}
|
|
458
|
-
};
|
|
459
|
-
|
|
460
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/utils.mjs
|
|
461
|
-
init_env_shim();
|
|
462
|
-
|
|
463
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/sumSerializerSizes.mjs
|
|
464
|
-
init_env_shim();
|
|
465
|
-
function sumSerializerSizes(sizes) {
|
|
466
|
-
return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
|
|
467
529
|
}
|
|
468
530
|
|
|
469
|
-
//
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
531
|
+
// ../addresses/dist/index.browser.js
|
|
532
|
+
var memoizedBase58Encoder;
|
|
533
|
+
var memoizedBase58Decoder;
|
|
534
|
+
function getMemoizedBase58Encoder() {
|
|
535
|
+
if (!memoizedBase58Encoder)
|
|
536
|
+
memoizedBase58Encoder = getBase58Encoder();
|
|
537
|
+
return memoizedBase58Encoder;
|
|
538
|
+
}
|
|
539
|
+
function getMemoizedBase58Decoder() {
|
|
540
|
+
if (!memoizedBase58Decoder)
|
|
541
|
+
memoizedBase58Decoder = getBase58Decoder();
|
|
542
|
+
return memoizedBase58Decoder;
|
|
543
|
+
}
|
|
544
|
+
function isAddress(putativeBase58EncodedAddress) {
|
|
545
|
+
if (
|
|
546
|
+
// Lowest address (32 bytes of zeroes)
|
|
547
|
+
putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
|
|
548
|
+
putativeBase58EncodedAddress.length > 44
|
|
549
|
+
) {
|
|
550
|
+
return false;
|
|
473
551
|
}
|
|
474
|
-
|
|
475
|
-
|
|
552
|
+
const base58Encoder = getMemoizedBase58Encoder();
|
|
553
|
+
const bytes2 = base58Encoder.encode(putativeBase58EncodedAddress);
|
|
554
|
+
const numBytes = bytes2.byteLength;
|
|
555
|
+
if (numBytes !== 32) {
|
|
556
|
+
return false;
|
|
476
557
|
}
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
558
|
+
return true;
|
|
559
|
+
}
|
|
560
|
+
function assertIsAddress(putativeBase58EncodedAddress) {
|
|
561
|
+
try {
|
|
562
|
+
if (
|
|
563
|
+
// Lowest address (32 bytes of zeroes)
|
|
564
|
+
putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
|
|
565
|
+
putativeBase58EncodedAddress.length > 44
|
|
566
|
+
) {
|
|
567
|
+
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
481
568
|
}
|
|
482
|
-
const
|
|
483
|
-
|
|
484
|
-
|
|
569
|
+
const base58Encoder = getMemoizedBase58Encoder();
|
|
570
|
+
const bytes2 = base58Encoder.encode(putativeBase58EncodedAddress);
|
|
571
|
+
const numBytes = bytes2.byteLength;
|
|
572
|
+
if (numBytes !== 32) {
|
|
573
|
+
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
485
574
|
}
|
|
486
|
-
|
|
575
|
+
} catch (e3) {
|
|
576
|
+
throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, {
|
|
577
|
+
cause: e3
|
|
578
|
+
});
|
|
487
579
|
}
|
|
488
|
-
throw new UnrecognizedArrayLikeSerializerSizeError(size);
|
|
489
580
|
}
|
|
490
|
-
function
|
|
491
|
-
|
|
581
|
+
function address(putativeBase58EncodedAddress) {
|
|
582
|
+
assertIsAddress(putativeBase58EncodedAddress);
|
|
583
|
+
return putativeBase58EncodedAddress;
|
|
492
584
|
}
|
|
493
|
-
function
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
585
|
+
function getAddressEncoder(config) {
|
|
586
|
+
return mapEncoder(
|
|
587
|
+
getStringEncoder({
|
|
588
|
+
description: config?.description ?? "Base58EncodedAddress",
|
|
589
|
+
encoding: getMemoizedBase58Encoder(),
|
|
590
|
+
size: 32
|
|
591
|
+
}),
|
|
592
|
+
(putativeAddress) => address(putativeAddress)
|
|
593
|
+
);
|
|
500
594
|
}
|
|
501
|
-
function
|
|
502
|
-
return
|
|
595
|
+
function getAddressDecoder(config) {
|
|
596
|
+
return getStringDecoder({
|
|
597
|
+
description: config?.description ?? "Base58EncodedAddress",
|
|
598
|
+
encoding: getMemoizedBase58Decoder(),
|
|
599
|
+
size: 32
|
|
600
|
+
});
|
|
503
601
|
}
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
602
|
+
function getAddressCodec(config) {
|
|
603
|
+
return combineCodec(getAddressEncoder(config), getAddressDecoder(config));
|
|
604
|
+
}
|
|
605
|
+
function getAddressComparator() {
|
|
606
|
+
return new Intl.Collator("en", {
|
|
607
|
+
caseFirst: "lower",
|
|
608
|
+
ignorePunctuation: false,
|
|
609
|
+
localeMatcher: "best fit",
|
|
610
|
+
numeric: false,
|
|
611
|
+
sensitivity: "variant",
|
|
612
|
+
usage: "sort"
|
|
613
|
+
}).compare;
|
|
614
|
+
}
|
|
615
|
+
var D = 37095705934669439343138083508754565189542113879843219016388785533085940283555n;
|
|
616
|
+
var P = 57896044618658097711785492504343953926634992332820282019728792003956564819949n;
|
|
617
|
+
var RM1 = 19681161376707505956807079304988542015446066515923890162744021073123829784752n;
|
|
618
|
+
function mod(a) {
|
|
619
|
+
const r = a % P;
|
|
620
|
+
return r >= 0n ? r : P + r;
|
|
621
|
+
}
|
|
622
|
+
function pow2(x, power) {
|
|
623
|
+
let r = x;
|
|
624
|
+
while (power-- > 0n) {
|
|
625
|
+
r *= r;
|
|
626
|
+
r %= P;
|
|
510
627
|
}
|
|
511
|
-
return
|
|
512
|
-
description: options.description ?? `array(${item.description}; ${getSizeDescription(size)})`,
|
|
513
|
-
fixedSize: getSizeFromChildren(size, [item.fixedSize]),
|
|
514
|
-
maxSize: getSizeFromChildren(size, [item.maxSize]),
|
|
515
|
-
serialize: (value) => {
|
|
516
|
-
if (typeof size === "number" && value.length !== size) {
|
|
517
|
-
throw new InvalidNumberOfItemsError("array", size, value.length);
|
|
518
|
-
}
|
|
519
|
-
return mergeBytes([getSizePrefix(size, value.length), ...value.map((v) => item.serialize(v))]);
|
|
520
|
-
},
|
|
521
|
-
deserialize: (bytes2, offset = 0) => {
|
|
522
|
-
if (typeof size === "object" && bytes2.slice(offset).length === 0) {
|
|
523
|
-
return [[], offset];
|
|
524
|
-
}
|
|
525
|
-
const [resolvedSize, newOffset] = getResolvedSize(size, [item.fixedSize], bytes2, offset);
|
|
526
|
-
offset = newOffset;
|
|
527
|
-
const values = [];
|
|
528
|
-
for (let i = 0; i < resolvedSize; i += 1) {
|
|
529
|
-
const [value, newOffset2] = item.deserialize(bytes2, offset);
|
|
530
|
-
values.push(value);
|
|
531
|
-
offset = newOffset2;
|
|
532
|
-
}
|
|
533
|
-
return [values, offset];
|
|
534
|
-
}
|
|
535
|
-
};
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/bytes.mjs
|
|
539
|
-
init_env_shim();
|
|
540
|
-
function bytes(options = {}) {
|
|
541
|
-
const size = options.size ?? "variable";
|
|
542
|
-
const description = options.description ?? `bytes(${getSizeDescription(size)})`;
|
|
543
|
-
const byteSerializer = {
|
|
544
|
-
description,
|
|
545
|
-
fixedSize: null,
|
|
546
|
-
maxSize: null,
|
|
547
|
-
serialize: (value) => new Uint8Array(value),
|
|
548
|
-
deserialize: (bytes2, offset = 0) => {
|
|
549
|
-
const slice = bytes2.slice(offset);
|
|
550
|
-
return [slice, offset + slice.length];
|
|
551
|
-
}
|
|
552
|
-
};
|
|
553
|
-
if (size === "variable") {
|
|
554
|
-
return byteSerializer;
|
|
555
|
-
}
|
|
556
|
-
if (typeof size === "number") {
|
|
557
|
-
return fixSerializer(byteSerializer, size, description);
|
|
558
|
-
}
|
|
559
|
-
return {
|
|
560
|
-
description,
|
|
561
|
-
fixedSize: null,
|
|
562
|
-
maxSize: null,
|
|
563
|
-
serialize: (value) => {
|
|
564
|
-
const contentBytes = byteSerializer.serialize(value);
|
|
565
|
-
const lengthBytes = size.serialize(contentBytes.length);
|
|
566
|
-
return mergeBytes([lengthBytes, contentBytes]);
|
|
567
|
-
},
|
|
568
|
-
deserialize: (buffer, offset = 0) => {
|
|
569
|
-
if (buffer.slice(offset).length === 0) {
|
|
570
|
-
throw new DeserializingEmptyBufferError("bytes");
|
|
571
|
-
}
|
|
572
|
-
const [lengthBigInt, lengthOffset] = size.deserialize(buffer, offset);
|
|
573
|
-
const length = Number(lengthBigInt);
|
|
574
|
-
offset = lengthOffset;
|
|
575
|
-
const contentBuffer = buffer.slice(offset, offset + length);
|
|
576
|
-
if (contentBuffer.length < length) {
|
|
577
|
-
throw new NotEnoughBytesError("bytes", length, contentBuffer.length);
|
|
578
|
-
}
|
|
579
|
-
const [value, contentOffset] = byteSerializer.deserialize(contentBuffer);
|
|
580
|
-
offset += contentOffset;
|
|
581
|
-
return [value, offset];
|
|
582
|
-
}
|
|
583
|
-
};
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/string.mjs
|
|
587
|
-
init_env_shim();
|
|
588
|
-
function string(options = {}) {
|
|
589
|
-
const size = options.size ?? u32();
|
|
590
|
-
const encoding = options.encoding ?? utf8;
|
|
591
|
-
const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
|
|
592
|
-
if (size === "variable") {
|
|
593
|
-
return {
|
|
594
|
-
...encoding,
|
|
595
|
-
description
|
|
596
|
-
};
|
|
597
|
-
}
|
|
598
|
-
if (typeof size === "number") {
|
|
599
|
-
return fixSerializer(encoding, size, description);
|
|
600
|
-
}
|
|
601
|
-
return {
|
|
602
|
-
description,
|
|
603
|
-
fixedSize: null,
|
|
604
|
-
maxSize: null,
|
|
605
|
-
serialize: (value) => {
|
|
606
|
-
const contentBytes = encoding.serialize(value);
|
|
607
|
-
const lengthBytes = size.serialize(contentBytes.length);
|
|
608
|
-
return mergeBytes([lengthBytes, contentBytes]);
|
|
609
|
-
},
|
|
610
|
-
deserialize: (buffer, offset = 0) => {
|
|
611
|
-
if (buffer.slice(offset).length === 0) {
|
|
612
|
-
throw new DeserializingEmptyBufferError("string");
|
|
613
|
-
}
|
|
614
|
-
const [lengthBigInt, lengthOffset] = size.deserialize(buffer, offset);
|
|
615
|
-
const length = Number(lengthBigInt);
|
|
616
|
-
offset = lengthOffset;
|
|
617
|
-
const contentBuffer = buffer.slice(offset, offset + length);
|
|
618
|
-
if (contentBuffer.length < length) {
|
|
619
|
-
throw new NotEnoughBytesError("string", length, contentBuffer.length);
|
|
620
|
-
}
|
|
621
|
-
const [value, contentOffset] = encoding.deserialize(contentBuffer);
|
|
622
|
-
offset += contentOffset;
|
|
623
|
-
return [value, offset];
|
|
624
|
-
}
|
|
625
|
-
};
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/struct.mjs
|
|
629
|
-
init_env_shim();
|
|
630
|
-
function struct(fields, options = {}) {
|
|
631
|
-
const fieldDescriptions = fields.map(([name, serializer]) => `${String(name)}: ${serializer.description}`).join(", ");
|
|
632
|
-
return {
|
|
633
|
-
description: options.description ?? `struct(${fieldDescriptions})`,
|
|
634
|
-
fixedSize: sumSerializerSizes(fields.map(([, field]) => field.fixedSize)),
|
|
635
|
-
maxSize: sumSerializerSizes(fields.map(([, field]) => field.maxSize)),
|
|
636
|
-
serialize: (struct2) => {
|
|
637
|
-
const fieldBytes = fields.map(([key, serializer]) => serializer.serialize(struct2[key]));
|
|
638
|
-
return mergeBytes(fieldBytes);
|
|
639
|
-
},
|
|
640
|
-
deserialize: (bytes2, offset = 0) => {
|
|
641
|
-
const struct2 = {};
|
|
642
|
-
fields.forEach(([key, serializer]) => {
|
|
643
|
-
const [value, newOffset] = serializer.deserialize(bytes2, offset);
|
|
644
|
-
offset = newOffset;
|
|
645
|
-
struct2[key] = value;
|
|
646
|
-
});
|
|
647
|
-
return [struct2, offset];
|
|
648
|
-
}
|
|
649
|
-
};
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
// ../assertions/dist/index.browser.js
|
|
653
|
-
init_env_shim();
|
|
654
|
-
function assertIsSecureContext() {
|
|
655
|
-
if (!globalThis.isSecureContext) {
|
|
656
|
-
throw new Error(
|
|
657
|
-
"Cryptographic operations are only allowed in secure browser contexts. Read more here: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts"
|
|
658
|
-
);
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
var cachedEd25519Decision;
|
|
662
|
-
async function isEd25519CurveSupported(subtle) {
|
|
663
|
-
if (cachedEd25519Decision === void 0) {
|
|
664
|
-
cachedEd25519Decision = new Promise((resolve) => {
|
|
665
|
-
subtle.generateKey(
|
|
666
|
-
"Ed25519",
|
|
667
|
-
/* extractable */
|
|
668
|
-
false,
|
|
669
|
-
["sign", "verify"]
|
|
670
|
-
).catch(() => {
|
|
671
|
-
resolve(cachedEd25519Decision = false);
|
|
672
|
-
}).then(() => {
|
|
673
|
-
resolve(cachedEd25519Decision = true);
|
|
674
|
-
});
|
|
675
|
-
});
|
|
676
|
-
}
|
|
677
|
-
if (typeof cachedEd25519Decision === "boolean") {
|
|
678
|
-
return cachedEd25519Decision;
|
|
679
|
-
} else {
|
|
680
|
-
return await cachedEd25519Decision;
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
async function assertDigestCapabilityIsAvailable() {
|
|
684
|
-
assertIsSecureContext();
|
|
685
|
-
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.digest !== "function") {
|
|
686
|
-
throw new Error("No digest implementation could be found");
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
async function assertKeyGenerationIsAvailable() {
|
|
690
|
-
assertIsSecureContext();
|
|
691
|
-
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.generateKey !== "function") {
|
|
692
|
-
throw new Error("No key generation implementation could be found");
|
|
693
|
-
}
|
|
694
|
-
if (!await isEd25519CurveSupported(globalThis.crypto.subtle)) {
|
|
695
|
-
throw new Error(
|
|
696
|
-
"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"
|
|
697
|
-
);
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
async function assertKeyExporterIsAvailable() {
|
|
701
|
-
assertIsSecureContext();
|
|
702
|
-
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.exportKey !== "function") {
|
|
703
|
-
throw new Error("No key export implementation could be found");
|
|
704
|
-
}
|
|
705
|
-
}
|
|
706
|
-
async function assertSigningCapabilityIsAvailable() {
|
|
707
|
-
assertIsSecureContext();
|
|
708
|
-
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.sign !== "function") {
|
|
709
|
-
throw new Error("No signing implementation could be found");
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
async function assertVerificationCapabilityIsAvailable() {
|
|
713
|
-
assertIsSecureContext();
|
|
714
|
-
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.verify !== "function") {
|
|
715
|
-
throw new Error("No signature verification implementation could be found");
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
function assertIsBase58EncodedAddress(putativeBase58EncodedAddress) {
|
|
719
|
-
try {
|
|
720
|
-
if (
|
|
721
|
-
// Lowest address (32 bytes of zeroes)
|
|
722
|
-
putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
|
|
723
|
-
putativeBase58EncodedAddress.length > 44
|
|
724
|
-
) {
|
|
725
|
-
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
726
|
-
}
|
|
727
|
-
const bytes2 = base58.serialize(putativeBase58EncodedAddress);
|
|
728
|
-
const numBytes = bytes2.byteLength;
|
|
729
|
-
if (numBytes !== 32) {
|
|
730
|
-
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
731
|
-
}
|
|
732
|
-
} catch (e3) {
|
|
733
|
-
throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, {
|
|
734
|
-
cause: e3
|
|
735
|
-
});
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
function getBase58EncodedAddressCodec(config) {
|
|
739
|
-
return string({
|
|
740
|
-
description: config?.description ?? ("A 32-byte account address" ),
|
|
741
|
-
encoding: base58,
|
|
742
|
-
size: 32
|
|
743
|
-
});
|
|
744
|
-
}
|
|
745
|
-
function getBase58EncodedAddressComparator() {
|
|
746
|
-
return new Intl.Collator("en", {
|
|
747
|
-
caseFirst: "lower",
|
|
748
|
-
ignorePunctuation: false,
|
|
749
|
-
localeMatcher: "best fit",
|
|
750
|
-
numeric: false,
|
|
751
|
-
sensitivity: "variant",
|
|
752
|
-
usage: "sort"
|
|
753
|
-
}).compare;
|
|
754
|
-
}
|
|
755
|
-
var D = 37095705934669439343138083508754565189542113879843219016388785533085940283555n;
|
|
756
|
-
var P = 57896044618658097711785492504343953926634992332820282019728792003956564819949n;
|
|
757
|
-
var RM1 = 19681161376707505956807079304988542015446066515923890162744021073123829784752n;
|
|
758
|
-
function mod(a) {
|
|
759
|
-
const r = a % P;
|
|
760
|
-
return r >= 0n ? r : P + r;
|
|
761
|
-
}
|
|
762
|
-
function pow2(x, power) {
|
|
763
|
-
let r = x;
|
|
764
|
-
while (power-- > 0n) {
|
|
765
|
-
r *= r;
|
|
766
|
-
r %= P;
|
|
767
|
-
}
|
|
768
|
-
return r;
|
|
628
|
+
return r;
|
|
769
629
|
}
|
|
770
630
|
function pow_2_252_3(x) {
|
|
771
631
|
const x2 = x * x % P;
|
|
@@ -838,6 +698,21 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
838
698
|
const y = decompressPointBytes(bytes2);
|
|
839
699
|
return pointIsOnCurve(y, bytes2[31]);
|
|
840
700
|
}
|
|
701
|
+
function isProgramDerivedAddress(value) {
|
|
702
|
+
return Array.isArray(value) && value.length === 2 && typeof value[0] === "string" && typeof value[1] === "number" && value[1] >= 0 && value[1] <= 255 && isAddress(value[0]);
|
|
703
|
+
}
|
|
704
|
+
function assertIsProgramDerivedAddress(value) {
|
|
705
|
+
const validFormat = Array.isArray(value) && value.length === 2 && typeof value[0] === "string" && typeof value[1] === "number";
|
|
706
|
+
if (!validFormat) {
|
|
707
|
+
throw new Error(
|
|
708
|
+
`Expected given program derived address to have the following format: [Base58EncodedAddress, ProgramDerivedAddressBump].`
|
|
709
|
+
);
|
|
710
|
+
}
|
|
711
|
+
if (value[1] < 0 || value[1] > 255) {
|
|
712
|
+
throw new Error(`Expected program derived address bump to be in the range [0, 255], got: ${value[1]}.`);
|
|
713
|
+
}
|
|
714
|
+
assertIsAddress(value[0]);
|
|
715
|
+
}
|
|
841
716
|
var MAX_SEED_LENGTH = 32;
|
|
842
717
|
var MAX_SEEDS = 16;
|
|
843
718
|
var PDA_MARKER_BYTES = [
|
|
@@ -866,7 +741,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
866
741
|
];
|
|
867
742
|
var PointOnCurveError = class extends Error {
|
|
868
743
|
};
|
|
869
|
-
async function createProgramDerivedAddress({
|
|
744
|
+
async function createProgramDerivedAddress({
|
|
745
|
+
programAddress,
|
|
746
|
+
seeds
|
|
747
|
+
}) {
|
|
870
748
|
await assertDigestCapabilityIsAvailable();
|
|
871
749
|
if (seeds.length > MAX_SEEDS) {
|
|
872
750
|
throw new Error(`A maximum of ${MAX_SEEDS} seeds may be supplied when creating an address`);
|
|
@@ -880,8 +758,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
880
758
|
acc.push(...bytes2);
|
|
881
759
|
return acc;
|
|
882
760
|
}, []);
|
|
883
|
-
const base58EncodedAddressCodec =
|
|
884
|
-
const programAddressBytes = base58EncodedAddressCodec.
|
|
761
|
+
const base58EncodedAddressCodec = getAddressCodec();
|
|
762
|
+
const programAddressBytes = base58EncodedAddressCodec.encode(programAddress);
|
|
885
763
|
const addressBytesBuffer = await crypto.subtle.digest(
|
|
886
764
|
"SHA-256",
|
|
887
765
|
new Uint8Array([...seedBytes, ...programAddressBytes, ...PDA_MARKER_BYTES])
|
|
@@ -890,19 +768,20 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
890
768
|
if (await compressedPointBytesAreOnCurve(addressBytes)) {
|
|
891
769
|
throw new PointOnCurveError("Invalid seeds; point must fall off the Ed25519 curve");
|
|
892
770
|
}
|
|
893
|
-
return base58EncodedAddressCodec.
|
|
771
|
+
return base58EncodedAddressCodec.decode(addressBytes)[0];
|
|
894
772
|
}
|
|
895
|
-
async function getProgramDerivedAddress({
|
|
773
|
+
async function getProgramDerivedAddress({
|
|
774
|
+
programAddress,
|
|
775
|
+
seeds
|
|
776
|
+
}) {
|
|
896
777
|
let bumpSeed = 255;
|
|
897
778
|
while (bumpSeed > 0) {
|
|
898
779
|
try {
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
})
|
|
905
|
-
};
|
|
780
|
+
const address2 = await createProgramDerivedAddress({
|
|
781
|
+
programAddress,
|
|
782
|
+
seeds: [...seeds, new Uint8Array([bumpSeed])]
|
|
783
|
+
});
|
|
784
|
+
return [address2, bumpSeed];
|
|
906
785
|
} catch (e3) {
|
|
907
786
|
if (e3 instanceof PointOnCurveError) {
|
|
908
787
|
bumpSeed--;
|
|
@@ -910,105 +789,721 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
910
789
|
throw e3;
|
|
911
790
|
}
|
|
912
791
|
}
|
|
913
|
-
}
|
|
914
|
-
throw new Error("Unable to find a viable program address bump seed");
|
|
792
|
+
}
|
|
793
|
+
throw new Error("Unable to find a viable program address bump seed");
|
|
794
|
+
}
|
|
795
|
+
async function createAddressWithSeed({
|
|
796
|
+
baseAddress,
|
|
797
|
+
programAddress,
|
|
798
|
+
seed
|
|
799
|
+
}) {
|
|
800
|
+
const { encode: encode2, decode: decode2 } = getAddressCodec();
|
|
801
|
+
const seedBytes = typeof seed === "string" ? new TextEncoder().encode(seed) : seed;
|
|
802
|
+
if (seedBytes.byteLength > MAX_SEED_LENGTH) {
|
|
803
|
+
throw new Error(`The seed exceeds the maximum length of 32 bytes`);
|
|
804
|
+
}
|
|
805
|
+
const programAddressBytes = encode2(programAddress);
|
|
806
|
+
if (programAddressBytes.length >= PDA_MARKER_BYTES.length && programAddressBytes.slice(-PDA_MARKER_BYTES.length).every((byte, index) => byte === PDA_MARKER_BYTES[index])) {
|
|
807
|
+
throw new Error(`programAddress cannot end with the PDA marker`);
|
|
808
|
+
}
|
|
809
|
+
const addressBytesBuffer = await crypto.subtle.digest(
|
|
810
|
+
"SHA-256",
|
|
811
|
+
new Uint8Array([...encode2(baseAddress), ...seedBytes, ...programAddressBytes])
|
|
812
|
+
);
|
|
813
|
+
const addressBytes = new Uint8Array(addressBytesBuffer);
|
|
814
|
+
return decode2(addressBytes)[0];
|
|
815
|
+
}
|
|
816
|
+
async function getAddressFromPublicKey(publicKey) {
|
|
817
|
+
await assertKeyExporterIsAvailable();
|
|
818
|
+
if (publicKey.type !== "public" || publicKey.algorithm.name !== "Ed25519") {
|
|
819
|
+
throw new Error("The `CryptoKey` must be an `Ed25519` public key");
|
|
820
|
+
}
|
|
821
|
+
const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
|
|
822
|
+
const [base58EncodedAddress] = getAddressDecoder().decode(new Uint8Array(publicKeyBytes));
|
|
823
|
+
return base58EncodedAddress;
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
// ../instructions/dist/index.browser.js
|
|
827
|
+
init_env_shim();
|
|
828
|
+
var AccountRole = /* @__PURE__ */ ((AccountRole22) => {
|
|
829
|
+
AccountRole22[AccountRole22["WRITABLE_SIGNER"] = /* 3 */
|
|
830
|
+
3] = "WRITABLE_SIGNER";
|
|
831
|
+
AccountRole22[AccountRole22["READONLY_SIGNER"] = /* 2 */
|
|
832
|
+
2] = "READONLY_SIGNER";
|
|
833
|
+
AccountRole22[AccountRole22["WRITABLE"] = /* 1 */
|
|
834
|
+
1] = "WRITABLE";
|
|
835
|
+
AccountRole22[AccountRole22["READONLY"] = /* 0 */
|
|
836
|
+
0] = "READONLY";
|
|
837
|
+
return AccountRole22;
|
|
838
|
+
})(AccountRole || {});
|
|
839
|
+
var IS_SIGNER_BITMASK = 2;
|
|
840
|
+
var IS_WRITABLE_BITMASK = 1;
|
|
841
|
+
function downgradeRoleToNonSigner(role) {
|
|
842
|
+
return role & ~IS_SIGNER_BITMASK;
|
|
843
|
+
}
|
|
844
|
+
function downgradeRoleToReadonly(role) {
|
|
845
|
+
return role & ~IS_WRITABLE_BITMASK;
|
|
846
|
+
}
|
|
847
|
+
function isSignerRole(role) {
|
|
848
|
+
return role >= 2;
|
|
849
|
+
}
|
|
850
|
+
function isWritableRole(role) {
|
|
851
|
+
return (role & IS_WRITABLE_BITMASK) !== 0;
|
|
852
|
+
}
|
|
853
|
+
function mergeRoles(roleA, roleB) {
|
|
854
|
+
return roleA | roleB;
|
|
855
|
+
}
|
|
856
|
+
function upgradeRoleToSigner(role) {
|
|
857
|
+
return role | IS_SIGNER_BITMASK;
|
|
858
|
+
}
|
|
859
|
+
function upgradeRoleToWritable(role) {
|
|
860
|
+
return role | IS_WRITABLE_BITMASK;
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
// ../keys/dist/index.browser.js
|
|
864
|
+
init_env_shim();
|
|
865
|
+
async function generateKeyPair() {
|
|
866
|
+
await assertKeyGenerationIsAvailable();
|
|
867
|
+
const keyPair = await crypto.subtle.generateKey(
|
|
868
|
+
/* algorithm */
|
|
869
|
+
"Ed25519",
|
|
870
|
+
// Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20
|
|
871
|
+
/* extractable */
|
|
872
|
+
false,
|
|
873
|
+
// Prevents the bytes of the private key from being visible to JS.
|
|
874
|
+
/* allowed uses */
|
|
875
|
+
["sign", "verify"]
|
|
876
|
+
);
|
|
877
|
+
return keyPair;
|
|
878
|
+
}
|
|
879
|
+
async function signBytes(key, data) {
|
|
880
|
+
await assertSigningCapabilityIsAvailable();
|
|
881
|
+
const signedData = await crypto.subtle.sign("Ed25519", key, data);
|
|
882
|
+
return new Uint8Array(signedData);
|
|
883
|
+
}
|
|
884
|
+
async function verifySignature(key, signature, data) {
|
|
885
|
+
await assertVerificationCapabilityIsAvailable();
|
|
886
|
+
return await crypto.subtle.verify("Ed25519", key, signature, data);
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
// ../transactions/dist/index.browser.js
|
|
890
|
+
init_env_shim();
|
|
891
|
+
|
|
892
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/index.mjs
|
|
893
|
+
init_env_shim();
|
|
894
|
+
|
|
895
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/index.mjs
|
|
896
|
+
init_env_shim();
|
|
897
|
+
|
|
898
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/bytes.mjs
|
|
899
|
+
init_env_shim();
|
|
900
|
+
var mergeBytes2 = (bytesArr) => {
|
|
901
|
+
const totalLength = bytesArr.reduce((total, arr) => total + arr.length, 0);
|
|
902
|
+
const result = new Uint8Array(totalLength);
|
|
903
|
+
let offset = 0;
|
|
904
|
+
bytesArr.forEach((arr) => {
|
|
905
|
+
result.set(arr, offset);
|
|
906
|
+
offset += arr.length;
|
|
907
|
+
});
|
|
908
|
+
return result;
|
|
909
|
+
};
|
|
910
|
+
var padBytes2 = (bytes2, length) => {
|
|
911
|
+
if (bytes2.length >= length)
|
|
912
|
+
return bytes2;
|
|
913
|
+
const paddedBytes = new Uint8Array(length).fill(0);
|
|
914
|
+
paddedBytes.set(bytes2);
|
|
915
|
+
return paddedBytes;
|
|
916
|
+
};
|
|
917
|
+
var fixBytes2 = (bytes2, length) => padBytes2(bytes2.slice(0, length), length);
|
|
918
|
+
|
|
919
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/errors.mjs
|
|
920
|
+
init_env_shim();
|
|
921
|
+
var DeserializingEmptyBufferError = class extends Error {
|
|
922
|
+
constructor(serializer) {
|
|
923
|
+
super(`Serializer [${serializer}] cannot deserialize empty buffers.`);
|
|
924
|
+
__publicField(this, "name", "DeserializingEmptyBufferError");
|
|
925
|
+
}
|
|
926
|
+
};
|
|
927
|
+
var NotEnoughBytesError = class extends Error {
|
|
928
|
+
constructor(serializer, expected, actual) {
|
|
929
|
+
super(`Serializer [${serializer}] expected ${expected} bytes, got ${actual}.`);
|
|
930
|
+
__publicField(this, "name", "NotEnoughBytesError");
|
|
931
|
+
}
|
|
932
|
+
};
|
|
933
|
+
var ExpectedFixedSizeSerializerError = class extends Error {
|
|
934
|
+
constructor(message) {
|
|
935
|
+
message ?? (message = "Expected a fixed-size serializer, got a variable-size one.");
|
|
936
|
+
super(message);
|
|
937
|
+
__publicField(this, "name", "ExpectedFixedSizeSerializerError");
|
|
938
|
+
}
|
|
939
|
+
};
|
|
940
|
+
|
|
941
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/fixSerializer.mjs
|
|
942
|
+
init_env_shim();
|
|
943
|
+
function fixSerializer(serializer, fixedBytes, description) {
|
|
944
|
+
return {
|
|
945
|
+
description: description ?? `fixed(${fixedBytes}, ${serializer.description})`,
|
|
946
|
+
fixedSize: fixedBytes,
|
|
947
|
+
maxSize: fixedBytes,
|
|
948
|
+
serialize: (value) => fixBytes2(serializer.serialize(value), fixedBytes),
|
|
949
|
+
deserialize: (buffer, offset = 0) => {
|
|
950
|
+
buffer = buffer.slice(offset, offset + fixedBytes);
|
|
951
|
+
if (buffer.length < fixedBytes) {
|
|
952
|
+
throw new NotEnoughBytesError("fixSerializer", fixedBytes, buffer.length);
|
|
953
|
+
}
|
|
954
|
+
if (serializer.fixedSize !== null) {
|
|
955
|
+
buffer = fixBytes2(buffer, serializer.fixedSize);
|
|
956
|
+
}
|
|
957
|
+
const [value] = serializer.deserialize(buffer, 0);
|
|
958
|
+
return [value, offset + fixedBytes];
|
|
959
|
+
}
|
|
960
|
+
};
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/mapSerializer.mjs
|
|
964
|
+
init_env_shim();
|
|
965
|
+
function mapSerializer(serializer, unmap, map) {
|
|
966
|
+
return {
|
|
967
|
+
description: serializer.description,
|
|
968
|
+
fixedSize: serializer.fixedSize,
|
|
969
|
+
maxSize: serializer.maxSize,
|
|
970
|
+
serialize: (value) => serializer.serialize(unmap(value)),
|
|
971
|
+
deserialize: (buffer, offset = 0) => {
|
|
972
|
+
const [value, length] = serializer.deserialize(buffer, offset);
|
|
973
|
+
return map ? [map(value, buffer, offset), length] : [value, length];
|
|
974
|
+
}
|
|
975
|
+
};
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/index.mjs
|
|
979
|
+
init_env_shim();
|
|
980
|
+
|
|
981
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/baseX.mjs
|
|
982
|
+
init_env_shim();
|
|
983
|
+
|
|
984
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/errors.mjs
|
|
985
|
+
init_env_shim();
|
|
986
|
+
var InvalidBaseStringError = class extends Error {
|
|
987
|
+
constructor(value, base, cause) {
|
|
988
|
+
const message = `Expected a string of base ${base}, got [${value}].`;
|
|
989
|
+
super(message);
|
|
990
|
+
__publicField(this, "name", "InvalidBaseStringError");
|
|
991
|
+
this.cause = cause;
|
|
992
|
+
}
|
|
993
|
+
};
|
|
994
|
+
|
|
995
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/baseX.mjs
|
|
996
|
+
var baseX = (alphabet) => {
|
|
997
|
+
const base = alphabet.length;
|
|
998
|
+
const baseBigInt = BigInt(base);
|
|
999
|
+
return {
|
|
1000
|
+
description: `base${base}`,
|
|
1001
|
+
fixedSize: null,
|
|
1002
|
+
maxSize: null,
|
|
1003
|
+
serialize(value) {
|
|
1004
|
+
if (!value.match(new RegExp(`^[${alphabet}]*$`))) {
|
|
1005
|
+
throw new InvalidBaseStringError(value, base);
|
|
1006
|
+
}
|
|
1007
|
+
if (value === "")
|
|
1008
|
+
return new Uint8Array();
|
|
1009
|
+
const chars = [...value];
|
|
1010
|
+
let trailIndex = chars.findIndex((c) => c !== alphabet[0]);
|
|
1011
|
+
trailIndex = trailIndex === -1 ? chars.length : trailIndex;
|
|
1012
|
+
const leadingZeroes = Array(trailIndex).fill(0);
|
|
1013
|
+
if (trailIndex === chars.length)
|
|
1014
|
+
return Uint8Array.from(leadingZeroes);
|
|
1015
|
+
const tailChars = chars.slice(trailIndex);
|
|
1016
|
+
let base10Number = 0n;
|
|
1017
|
+
let baseXPower = 1n;
|
|
1018
|
+
for (let i = tailChars.length - 1; i >= 0; i -= 1) {
|
|
1019
|
+
base10Number += baseXPower * BigInt(alphabet.indexOf(tailChars[i]));
|
|
1020
|
+
baseXPower *= baseBigInt;
|
|
1021
|
+
}
|
|
1022
|
+
const tailBytes = [];
|
|
1023
|
+
while (base10Number > 0n) {
|
|
1024
|
+
tailBytes.unshift(Number(base10Number % 256n));
|
|
1025
|
+
base10Number /= 256n;
|
|
1026
|
+
}
|
|
1027
|
+
return Uint8Array.from(leadingZeroes.concat(tailBytes));
|
|
1028
|
+
},
|
|
1029
|
+
deserialize(buffer, offset = 0) {
|
|
1030
|
+
if (buffer.length === 0)
|
|
1031
|
+
return ["", 0];
|
|
1032
|
+
const bytes2 = buffer.slice(offset);
|
|
1033
|
+
let trailIndex = bytes2.findIndex((n) => n !== 0);
|
|
1034
|
+
trailIndex = trailIndex === -1 ? bytes2.length : trailIndex;
|
|
1035
|
+
const leadingZeroes = alphabet[0].repeat(trailIndex);
|
|
1036
|
+
if (trailIndex === bytes2.length)
|
|
1037
|
+
return [leadingZeroes, buffer.length];
|
|
1038
|
+
let base10Number = bytes2.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
|
|
1039
|
+
const tailChars = [];
|
|
1040
|
+
while (base10Number > 0n) {
|
|
1041
|
+
tailChars.unshift(alphabet[Number(base10Number % baseBigInt)]);
|
|
1042
|
+
base10Number /= baseBigInt;
|
|
1043
|
+
}
|
|
1044
|
+
return [leadingZeroes + tailChars.join(""), buffer.length];
|
|
1045
|
+
}
|
|
1046
|
+
};
|
|
1047
|
+
};
|
|
1048
|
+
|
|
1049
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/base58.mjs
|
|
1050
|
+
init_env_shim();
|
|
1051
|
+
var base58 = baseX("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
|
|
1052
|
+
|
|
1053
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/base64.mjs
|
|
1054
|
+
init_env_shim();
|
|
1055
|
+
|
|
1056
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/baseXReslice.mjs
|
|
1057
|
+
init_env_shim();
|
|
1058
|
+
var baseXReslice = (alphabet, bits) => {
|
|
1059
|
+
const base = alphabet.length;
|
|
1060
|
+
const reslice = (input, inputBits, outputBits, useRemainder) => {
|
|
1061
|
+
const output = [];
|
|
1062
|
+
let accumulator = 0;
|
|
1063
|
+
let bitsInAccumulator = 0;
|
|
1064
|
+
const mask = (1 << outputBits) - 1;
|
|
1065
|
+
for (const value of input) {
|
|
1066
|
+
accumulator = accumulator << inputBits | value;
|
|
1067
|
+
bitsInAccumulator += inputBits;
|
|
1068
|
+
while (bitsInAccumulator >= outputBits) {
|
|
1069
|
+
bitsInAccumulator -= outputBits;
|
|
1070
|
+
output.push(accumulator >> bitsInAccumulator & mask);
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
if (useRemainder && bitsInAccumulator > 0) {
|
|
1074
|
+
output.push(accumulator << outputBits - bitsInAccumulator & mask);
|
|
1075
|
+
}
|
|
1076
|
+
return output;
|
|
1077
|
+
};
|
|
1078
|
+
return {
|
|
1079
|
+
description: `base${base}`,
|
|
1080
|
+
fixedSize: null,
|
|
1081
|
+
maxSize: null,
|
|
1082
|
+
serialize(value) {
|
|
1083
|
+
if (!value.match(new RegExp(`^[${alphabet}]*$`))) {
|
|
1084
|
+
throw new InvalidBaseStringError(value, base);
|
|
1085
|
+
}
|
|
1086
|
+
if (value === "")
|
|
1087
|
+
return new Uint8Array();
|
|
1088
|
+
const charIndices = [...value].map((c) => alphabet.indexOf(c));
|
|
1089
|
+
const bytes2 = reslice(charIndices, bits, 8, false);
|
|
1090
|
+
return Uint8Array.from(bytes2);
|
|
1091
|
+
},
|
|
1092
|
+
deserialize(buffer, offset = 0) {
|
|
1093
|
+
if (buffer.length === 0)
|
|
1094
|
+
return ["", 0];
|
|
1095
|
+
const bytes2 = [...buffer.slice(offset)];
|
|
1096
|
+
const charIndices = reslice(bytes2, 8, bits, true);
|
|
1097
|
+
return [charIndices.map((i) => alphabet[i]).join(""), buffer.length];
|
|
1098
|
+
}
|
|
1099
|
+
};
|
|
1100
|
+
};
|
|
1101
|
+
|
|
1102
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/base64.mjs
|
|
1103
|
+
var base64 = mapSerializer(baseXReslice("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", 6), (value) => value.replace(/=/g, ""), (value) => value.padEnd(Math.ceil(value.length / 4) * 4, "="));
|
|
1104
|
+
|
|
1105
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/nullCharacters.mjs
|
|
1106
|
+
init_env_shim();
|
|
1107
|
+
var removeNullCharacters2 = (value) => (
|
|
1108
|
+
// eslint-disable-next-line no-control-regex
|
|
1109
|
+
value.replace(/\u0000/g, "")
|
|
1110
|
+
);
|
|
1111
|
+
|
|
1112
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/utf8.mjs
|
|
1113
|
+
init_env_shim();
|
|
1114
|
+
var utf8 = {
|
|
1115
|
+
description: "utf8",
|
|
1116
|
+
fixedSize: null,
|
|
1117
|
+
maxSize: null,
|
|
1118
|
+
serialize(value) {
|
|
1119
|
+
return new TextEncoder().encode(value);
|
|
1120
|
+
},
|
|
1121
|
+
deserialize(buffer, offset = 0) {
|
|
1122
|
+
const value = new TextDecoder().decode(buffer.slice(offset));
|
|
1123
|
+
return [removeNullCharacters2(value), buffer.length];
|
|
1124
|
+
}
|
|
1125
|
+
};
|
|
1126
|
+
|
|
1127
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/index.mjs
|
|
1128
|
+
init_env_shim();
|
|
1129
|
+
|
|
1130
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/common.mjs
|
|
1131
|
+
init_env_shim();
|
|
1132
|
+
var Endian;
|
|
1133
|
+
(function(Endian2) {
|
|
1134
|
+
Endian2["Little"] = "le";
|
|
1135
|
+
Endian2["Big"] = "be";
|
|
1136
|
+
})(Endian || (Endian = {}));
|
|
1137
|
+
|
|
1138
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/errors.mjs
|
|
1139
|
+
init_env_shim();
|
|
1140
|
+
var NumberOutOfRangeError = class extends RangeError {
|
|
1141
|
+
constructor(serializer, min, max, actual) {
|
|
1142
|
+
super(`Serializer [${serializer}] expected number to be between ${min} and ${max}, got ${actual}.`);
|
|
1143
|
+
__publicField(this, "name", "NumberOutOfRangeError");
|
|
1144
|
+
}
|
|
1145
|
+
};
|
|
1146
|
+
|
|
1147
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/utils.mjs
|
|
1148
|
+
init_env_shim();
|
|
1149
|
+
function numberFactory(input) {
|
|
1150
|
+
let littleEndian;
|
|
1151
|
+
let defaultDescription = input.name;
|
|
1152
|
+
if (input.size > 1) {
|
|
1153
|
+
littleEndian = !("endian" in input.options) || input.options.endian === Endian.Little;
|
|
1154
|
+
defaultDescription += littleEndian ? "(le)" : "(be)";
|
|
1155
|
+
}
|
|
1156
|
+
return {
|
|
1157
|
+
description: input.options.description ?? defaultDescription,
|
|
1158
|
+
fixedSize: input.size,
|
|
1159
|
+
maxSize: input.size,
|
|
1160
|
+
serialize(value) {
|
|
1161
|
+
if (input.range) {
|
|
1162
|
+
assertRange(input.name, input.range[0], input.range[1], value);
|
|
1163
|
+
}
|
|
1164
|
+
const buffer = new ArrayBuffer(input.size);
|
|
1165
|
+
input.set(new DataView(buffer), value, littleEndian);
|
|
1166
|
+
return new Uint8Array(buffer);
|
|
1167
|
+
},
|
|
1168
|
+
deserialize(bytes2, offset = 0) {
|
|
1169
|
+
const slice = bytes2.slice(offset, offset + input.size);
|
|
1170
|
+
assertEnoughBytes("i8", slice, input.size);
|
|
1171
|
+
const view = toDataView(slice);
|
|
1172
|
+
return [input.get(view, littleEndian), offset + input.size];
|
|
1173
|
+
}
|
|
1174
|
+
};
|
|
1175
|
+
}
|
|
1176
|
+
var toArrayBuffer2 = (array2) => array2.buffer.slice(array2.byteOffset, array2.byteLength + array2.byteOffset);
|
|
1177
|
+
var toDataView = (array2) => new DataView(toArrayBuffer2(array2));
|
|
1178
|
+
var assertRange = (serializer, min, max, value) => {
|
|
1179
|
+
if (value < min || value > max) {
|
|
1180
|
+
throw new NumberOutOfRangeError(serializer, min, max, value);
|
|
1181
|
+
}
|
|
1182
|
+
};
|
|
1183
|
+
var assertEnoughBytes = (serializer, bytes2, expected) => {
|
|
1184
|
+
if (bytes2.length === 0) {
|
|
1185
|
+
throw new DeserializingEmptyBufferError(serializer);
|
|
1186
|
+
}
|
|
1187
|
+
if (bytes2.length < expected) {
|
|
1188
|
+
throw new NotEnoughBytesError(serializer, expected, bytes2.length);
|
|
1189
|
+
}
|
|
1190
|
+
};
|
|
1191
|
+
|
|
1192
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/u8.mjs
|
|
1193
|
+
init_env_shim();
|
|
1194
|
+
var u8 = (options = {}) => numberFactory({
|
|
1195
|
+
name: "u8",
|
|
1196
|
+
size: 1,
|
|
1197
|
+
range: [0, Number("0xff")],
|
|
1198
|
+
set: (view, value) => view.setUint8(0, Number(value)),
|
|
1199
|
+
get: (view) => view.getUint8(0),
|
|
1200
|
+
options
|
|
1201
|
+
});
|
|
1202
|
+
|
|
1203
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/u32.mjs
|
|
1204
|
+
init_env_shim();
|
|
1205
|
+
var u32 = (options = {}) => numberFactory({
|
|
1206
|
+
name: "u32",
|
|
1207
|
+
size: 4,
|
|
1208
|
+
range: [0, Number("0xffffffff")],
|
|
1209
|
+
set: (view, value, le) => view.setUint32(0, Number(value), le),
|
|
1210
|
+
get: (view, le) => view.getUint32(0, le),
|
|
1211
|
+
options
|
|
1212
|
+
});
|
|
1213
|
+
|
|
1214
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/shortU16.mjs
|
|
1215
|
+
init_env_shim();
|
|
1216
|
+
var shortU16 = (options = {}) => ({
|
|
1217
|
+
description: options.description ?? "shortU16",
|
|
1218
|
+
fixedSize: null,
|
|
1219
|
+
maxSize: 3,
|
|
1220
|
+
serialize: (value) => {
|
|
1221
|
+
assertRange("shortU16", 0, 65535, value);
|
|
1222
|
+
const bytes2 = [0];
|
|
1223
|
+
for (let ii = 0; ; ii += 1) {
|
|
1224
|
+
const alignedValue = value >> ii * 7;
|
|
1225
|
+
if (alignedValue === 0) {
|
|
1226
|
+
break;
|
|
1227
|
+
}
|
|
1228
|
+
const nextSevenBits = 127 & alignedValue;
|
|
1229
|
+
bytes2[ii] = nextSevenBits;
|
|
1230
|
+
if (ii > 0) {
|
|
1231
|
+
bytes2[ii - 1] |= 128;
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
return new Uint8Array(bytes2);
|
|
1235
|
+
},
|
|
1236
|
+
deserialize: (bytes2, offset = 0) => {
|
|
1237
|
+
let value = 0;
|
|
1238
|
+
let byteCount = 0;
|
|
1239
|
+
while (++byteCount) {
|
|
1240
|
+
const byteIndex = byteCount - 1;
|
|
1241
|
+
const currentByte = bytes2[offset + byteIndex];
|
|
1242
|
+
const nextSevenBits = 127 & currentByte;
|
|
1243
|
+
value |= nextSevenBits << byteIndex * 7;
|
|
1244
|
+
if ((currentByte & 128) === 0) {
|
|
1245
|
+
break;
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
return [value, offset + byteCount];
|
|
1249
|
+
}
|
|
1250
|
+
});
|
|
1251
|
+
|
|
1252
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/array.mjs
|
|
1253
|
+
init_env_shim();
|
|
1254
|
+
|
|
1255
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/errors.mjs
|
|
1256
|
+
init_env_shim();
|
|
1257
|
+
var InvalidNumberOfItemsError = class extends Error {
|
|
1258
|
+
constructor(serializer, expected, actual) {
|
|
1259
|
+
super(`Expected [${serializer}] to have ${expected} items, got ${actual}.`);
|
|
1260
|
+
__publicField(this, "name", "InvalidNumberOfItemsError");
|
|
1261
|
+
}
|
|
1262
|
+
};
|
|
1263
|
+
var InvalidArrayLikeRemainderSizeError = class extends Error {
|
|
1264
|
+
constructor(remainderSize, itemSize) {
|
|
1265
|
+
super(`The remainder of the buffer (${remainderSize} bytes) cannot be split into chunks of ${itemSize} bytes. Serializers of "remainder" size must have a remainder that is a multiple of its item size. In other words, ${remainderSize} modulo ${itemSize} should be equal to zero.`);
|
|
1266
|
+
__publicField(this, "name", "InvalidArrayLikeRemainderSizeError");
|
|
1267
|
+
}
|
|
1268
|
+
};
|
|
1269
|
+
var UnrecognizedArrayLikeSerializerSizeError = class extends Error {
|
|
1270
|
+
constructor(size) {
|
|
1271
|
+
super(`Unrecognized array-like serializer size: ${JSON.stringify(size)}`);
|
|
1272
|
+
__publicField(this, "name", "UnrecognizedArrayLikeSerializerSizeError");
|
|
1273
|
+
}
|
|
1274
|
+
};
|
|
1275
|
+
|
|
1276
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/utils.mjs
|
|
1277
|
+
init_env_shim();
|
|
1278
|
+
|
|
1279
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/sumSerializerSizes.mjs
|
|
1280
|
+
init_env_shim();
|
|
1281
|
+
function sumSerializerSizes(sizes) {
|
|
1282
|
+
return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/utils.mjs
|
|
1286
|
+
function getResolvedSize(size, childrenSizes, bytes2, offset) {
|
|
1287
|
+
if (typeof size === "number") {
|
|
1288
|
+
return [size, offset];
|
|
1289
|
+
}
|
|
1290
|
+
if (typeof size === "object") {
|
|
1291
|
+
return size.deserialize(bytes2, offset);
|
|
1292
|
+
}
|
|
1293
|
+
if (size === "remainder") {
|
|
1294
|
+
const childrenSize = sumSerializerSizes(childrenSizes);
|
|
1295
|
+
if (childrenSize === null) {
|
|
1296
|
+
throw new ExpectedFixedSizeSerializerError('Serializers of "remainder" size must have fixed-size items.');
|
|
1297
|
+
}
|
|
1298
|
+
const remainder = bytes2.slice(offset).length;
|
|
1299
|
+
if (remainder % childrenSize !== 0) {
|
|
1300
|
+
throw new InvalidArrayLikeRemainderSizeError(remainder, childrenSize);
|
|
1301
|
+
}
|
|
1302
|
+
return [remainder / childrenSize, offset];
|
|
1303
|
+
}
|
|
1304
|
+
throw new UnrecognizedArrayLikeSerializerSizeError(size);
|
|
1305
|
+
}
|
|
1306
|
+
function getSizeDescription2(size) {
|
|
1307
|
+
return typeof size === "object" ? size.description : `${size}`;
|
|
1308
|
+
}
|
|
1309
|
+
function getSizeFromChildren(size, childrenSizes) {
|
|
1310
|
+
if (typeof size !== "number")
|
|
1311
|
+
return null;
|
|
1312
|
+
if (size === 0)
|
|
1313
|
+
return 0;
|
|
1314
|
+
const childrenSize = sumSerializerSizes(childrenSizes);
|
|
1315
|
+
return childrenSize === null ? null : childrenSize * size;
|
|
1316
|
+
}
|
|
1317
|
+
function getSizePrefix(size, realSize) {
|
|
1318
|
+
return typeof size === "object" ? size.serialize(realSize) : new Uint8Array();
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/array.mjs
|
|
1322
|
+
function array(item, options = {}) {
|
|
1323
|
+
const size = options.size ?? u32();
|
|
1324
|
+
if (size === "remainder" && item.fixedSize === null) {
|
|
1325
|
+
throw new ExpectedFixedSizeSerializerError('Serializers of "remainder" size must have fixed-size items.');
|
|
1326
|
+
}
|
|
1327
|
+
return {
|
|
1328
|
+
description: options.description ?? `array(${item.description}; ${getSizeDescription2(size)})`,
|
|
1329
|
+
fixedSize: getSizeFromChildren(size, [item.fixedSize]),
|
|
1330
|
+
maxSize: getSizeFromChildren(size, [item.maxSize]),
|
|
1331
|
+
serialize: (value) => {
|
|
1332
|
+
if (typeof size === "number" && value.length !== size) {
|
|
1333
|
+
throw new InvalidNumberOfItemsError("array", size, value.length);
|
|
1334
|
+
}
|
|
1335
|
+
return mergeBytes2([getSizePrefix(size, value.length), ...value.map((v) => item.serialize(v))]);
|
|
1336
|
+
},
|
|
1337
|
+
deserialize: (bytes2, offset = 0) => {
|
|
1338
|
+
if (typeof size === "object" && bytes2.slice(offset).length === 0) {
|
|
1339
|
+
return [[], offset];
|
|
1340
|
+
}
|
|
1341
|
+
const [resolvedSize, newOffset] = getResolvedSize(size, [item.fixedSize], bytes2, offset);
|
|
1342
|
+
offset = newOffset;
|
|
1343
|
+
const values = [];
|
|
1344
|
+
for (let i = 0; i < resolvedSize; i += 1) {
|
|
1345
|
+
const [value, newOffset2] = item.deserialize(bytes2, offset);
|
|
1346
|
+
values.push(value);
|
|
1347
|
+
offset = newOffset2;
|
|
1348
|
+
}
|
|
1349
|
+
return [values, offset];
|
|
1350
|
+
}
|
|
1351
|
+
};
|
|
915
1352
|
}
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
const
|
|
922
|
-
const
|
|
923
|
-
|
|
924
|
-
|
|
1353
|
+
|
|
1354
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/bytes.mjs
|
|
1355
|
+
init_env_shim();
|
|
1356
|
+
function bytes(options = {}) {
|
|
1357
|
+
const size = options.size ?? "variable";
|
|
1358
|
+
const description = options.description ?? `bytes(${getSizeDescription2(size)})`;
|
|
1359
|
+
const byteSerializer = {
|
|
1360
|
+
description,
|
|
1361
|
+
fixedSize: null,
|
|
1362
|
+
maxSize: null,
|
|
1363
|
+
serialize: (value) => new Uint8Array(value),
|
|
1364
|
+
deserialize: (bytes2, offset = 0) => {
|
|
1365
|
+
const slice = bytes2.slice(offset);
|
|
1366
|
+
return [slice, offset + slice.length];
|
|
1367
|
+
}
|
|
1368
|
+
};
|
|
1369
|
+
if (size === "variable") {
|
|
1370
|
+
return byteSerializer;
|
|
925
1371
|
}
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
throw new Error(`programAddress cannot end with the PDA marker`);
|
|
1372
|
+
if (typeof size === "number") {
|
|
1373
|
+
return fixSerializer(byteSerializer, size, description);
|
|
929
1374
|
}
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
1375
|
+
return {
|
|
1376
|
+
description,
|
|
1377
|
+
fixedSize: null,
|
|
1378
|
+
maxSize: null,
|
|
1379
|
+
serialize: (value) => {
|
|
1380
|
+
const contentBytes = byteSerializer.serialize(value);
|
|
1381
|
+
const lengthBytes = size.serialize(contentBytes.length);
|
|
1382
|
+
return mergeBytes2([lengthBytes, contentBytes]);
|
|
1383
|
+
},
|
|
1384
|
+
deserialize: (buffer, offset = 0) => {
|
|
1385
|
+
if (buffer.slice(offset).length === 0) {
|
|
1386
|
+
throw new DeserializingEmptyBufferError("bytes");
|
|
1387
|
+
}
|
|
1388
|
+
const [lengthBigInt, lengthOffset] = size.deserialize(buffer, offset);
|
|
1389
|
+
const length = Number(lengthBigInt);
|
|
1390
|
+
offset = lengthOffset;
|
|
1391
|
+
const contentBuffer = buffer.slice(offset, offset + length);
|
|
1392
|
+
if (contentBuffer.length < length) {
|
|
1393
|
+
throw new NotEnoughBytesError("bytes", length, contentBuffer.length);
|
|
1394
|
+
}
|
|
1395
|
+
const [value, contentOffset] = byteSerializer.deserialize(contentBuffer);
|
|
1396
|
+
offset += contentOffset;
|
|
1397
|
+
return [value, offset];
|
|
1398
|
+
}
|
|
1399
|
+
};
|
|
936
1400
|
}
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
1401
|
+
|
|
1402
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/string.mjs
|
|
1403
|
+
init_env_shim();
|
|
1404
|
+
function string(options = {}) {
|
|
1405
|
+
const size = options.size ?? u32();
|
|
1406
|
+
const encoding = options.encoding ?? utf8;
|
|
1407
|
+
const description = options.description ?? `string(${encoding.description}; ${getSizeDescription2(size)})`;
|
|
1408
|
+
if (size === "variable") {
|
|
1409
|
+
return {
|
|
1410
|
+
...encoding,
|
|
1411
|
+
description
|
|
1412
|
+
};
|
|
941
1413
|
}
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
1414
|
+
if (typeof size === "number") {
|
|
1415
|
+
return fixSerializer(encoding, size, description);
|
|
1416
|
+
}
|
|
1417
|
+
return {
|
|
1418
|
+
description,
|
|
1419
|
+
fixedSize: null,
|
|
1420
|
+
maxSize: null,
|
|
1421
|
+
serialize: (value) => {
|
|
1422
|
+
const contentBytes = encoding.serialize(value);
|
|
1423
|
+
const lengthBytes = size.serialize(contentBytes.length);
|
|
1424
|
+
return mergeBytes2([lengthBytes, contentBytes]);
|
|
1425
|
+
},
|
|
1426
|
+
deserialize: (buffer, offset = 0) => {
|
|
1427
|
+
if (buffer.slice(offset).length === 0) {
|
|
1428
|
+
throw new DeserializingEmptyBufferError("string");
|
|
1429
|
+
}
|
|
1430
|
+
const [lengthBigInt, lengthOffset] = size.deserialize(buffer, offset);
|
|
1431
|
+
const length = Number(lengthBigInt);
|
|
1432
|
+
offset = lengthOffset;
|
|
1433
|
+
const contentBuffer = buffer.slice(offset, offset + length);
|
|
1434
|
+
if (contentBuffer.length < length) {
|
|
1435
|
+
throw new NotEnoughBytesError("string", length, contentBuffer.length);
|
|
1436
|
+
}
|
|
1437
|
+
const [value, contentOffset] = encoding.deserialize(contentBuffer);
|
|
1438
|
+
offset += contentOffset;
|
|
1439
|
+
return [value, offset];
|
|
1440
|
+
}
|
|
1441
|
+
};
|
|
945
1442
|
}
|
|
946
1443
|
|
|
947
|
-
//
|
|
1444
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/struct.mjs
|
|
948
1445
|
init_env_shim();
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
return role >= 2;
|
|
970
|
-
}
|
|
971
|
-
function isWritableRole(role) {
|
|
972
|
-
return (role & IS_WRITABLE_BITMASK) !== 0;
|
|
973
|
-
}
|
|
974
|
-
function mergeRoles(roleA, roleB) {
|
|
975
|
-
return roleA | roleB;
|
|
976
|
-
}
|
|
977
|
-
function upgradeRoleToSigner(role) {
|
|
978
|
-
return role | IS_SIGNER_BITMASK;
|
|
979
|
-
}
|
|
980
|
-
function upgradeRoleToWritable(role) {
|
|
981
|
-
return role | IS_WRITABLE_BITMASK;
|
|
1446
|
+
function struct(fields, options = {}) {
|
|
1447
|
+
const fieldDescriptions = fields.map(([name, serializer]) => `${String(name)}: ${serializer.description}`).join(", ");
|
|
1448
|
+
return {
|
|
1449
|
+
description: options.description ?? `struct(${fieldDescriptions})`,
|
|
1450
|
+
fixedSize: sumSerializerSizes(fields.map(([, field]) => field.fixedSize)),
|
|
1451
|
+
maxSize: sumSerializerSizes(fields.map(([, field]) => field.maxSize)),
|
|
1452
|
+
serialize: (struct2) => {
|
|
1453
|
+
const fieldBytes = fields.map(([key, serializer]) => serializer.serialize(struct2[key]));
|
|
1454
|
+
return mergeBytes2(fieldBytes);
|
|
1455
|
+
},
|
|
1456
|
+
deserialize: (bytes2, offset = 0) => {
|
|
1457
|
+
const struct2 = {};
|
|
1458
|
+
fields.forEach(([key, serializer]) => {
|
|
1459
|
+
const [value, newOffset] = serializer.deserialize(bytes2, offset);
|
|
1460
|
+
offset = newOffset;
|
|
1461
|
+
struct2[key] = value;
|
|
1462
|
+
});
|
|
1463
|
+
return [struct2, offset];
|
|
1464
|
+
}
|
|
1465
|
+
};
|
|
982
1466
|
}
|
|
983
1467
|
|
|
984
|
-
// ../
|
|
1468
|
+
// ../codecs-data-structures/dist/index.browser.js
|
|
985
1469
|
init_env_shim();
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
const keyPair = await crypto.subtle.generateKey(
|
|
989
|
-
/* algorithm */
|
|
990
|
-
"Ed25519",
|
|
991
|
-
// Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20
|
|
992
|
-
/* extractable */
|
|
993
|
-
false,
|
|
994
|
-
// Prevents the bytes of the private key from being visible to JS.
|
|
995
|
-
/* allowed uses */
|
|
996
|
-
["sign", "verify"]
|
|
997
|
-
);
|
|
998
|
-
return keyPair;
|
|
1470
|
+
function sumCodecSizes(sizes) {
|
|
1471
|
+
return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
|
|
999
1472
|
}
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1473
|
+
function structCodecHelper(fields, description) {
|
|
1474
|
+
const fieldDescriptions = fields.map(([name, codec]) => `${String(name)}: ${codec.description}`).join(", ");
|
|
1475
|
+
return {
|
|
1476
|
+
description: description ?? `struct(${fieldDescriptions})`,
|
|
1477
|
+
fixedSize: sumCodecSizes(fields.map(([, field]) => field.fixedSize)),
|
|
1478
|
+
maxSize: sumCodecSizes(fields.map(([, field]) => field.maxSize))
|
|
1479
|
+
};
|
|
1004
1480
|
}
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1481
|
+
function getStructEncoder(fields, options = {}) {
|
|
1482
|
+
return {
|
|
1483
|
+
...structCodecHelper(fields, options.description),
|
|
1484
|
+
encode: (struct2) => {
|
|
1485
|
+
const fieldBytes = fields.map(([key, codec]) => codec.encode(struct2[key]));
|
|
1486
|
+
return mergeBytes(fieldBytes);
|
|
1487
|
+
}
|
|
1488
|
+
};
|
|
1489
|
+
}
|
|
1490
|
+
function getStructDecoder(fields, options = {}) {
|
|
1491
|
+
return {
|
|
1492
|
+
...structCodecHelper(fields, options.description),
|
|
1493
|
+
decode: (bytes2, offset = 0) => {
|
|
1494
|
+
const struct2 = {};
|
|
1495
|
+
fields.forEach(([key, codec]) => {
|
|
1496
|
+
const [value, newOffset] = codec.decode(bytes2, offset);
|
|
1497
|
+
offset = newOffset;
|
|
1498
|
+
struct2[key] = value;
|
|
1499
|
+
});
|
|
1500
|
+
return [struct2, offset];
|
|
1501
|
+
}
|
|
1502
|
+
};
|
|
1503
|
+
}
|
|
1504
|
+
function getStructCodec(fields, options = {}) {
|
|
1505
|
+
return combineCodec(getStructEncoder(fields, options), getStructDecoder(fields, options));
|
|
1008
1506
|
}
|
|
1009
|
-
|
|
1010
|
-
// ../transactions/dist/index.browser.js
|
|
1011
|
-
init_env_shim();
|
|
1012
1507
|
function getUnsignedTransaction(transaction) {
|
|
1013
1508
|
if ("signatures" in transaction) {
|
|
1014
1509
|
const {
|
|
@@ -1167,8 +1662,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1167
1662
|
Object.freeze(out);
|
|
1168
1663
|
return out;
|
|
1169
1664
|
}
|
|
1170
|
-
function upsert(addressMap,
|
|
1171
|
-
addressMap[
|
|
1665
|
+
function upsert(addressMap, address2, update) {
|
|
1666
|
+
addressMap[address2] = update(addressMap[address2] ?? { role: AccountRole2.READONLY });
|
|
1172
1667
|
}
|
|
1173
1668
|
var TYPE = Symbol("AddressMapTypeProperty");
|
|
1174
1669
|
function getAddressMapFromInstructions(feePayer, instructions) {
|
|
@@ -1219,7 +1714,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1219
1714
|
const shouldReplaceEntry = (
|
|
1220
1715
|
// Consider using the new LOOKUP_TABLE if its address is different...
|
|
1221
1716
|
entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
|
|
1222
|
-
(addressComparator || (addressComparator =
|
|
1717
|
+
(addressComparator || (addressComparator = getAddressComparator()))(
|
|
1223
1718
|
accountMeta.lookupTableAddress,
|
|
1224
1719
|
entry.lookupTableAddress
|
|
1225
1720
|
) < 0
|
|
@@ -1327,14 +1822,14 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1327
1822
|
if (leftIsWritable !== isWritableRole2(rightEntry.role)) {
|
|
1328
1823
|
return leftIsWritable ? -1 : 1;
|
|
1329
1824
|
}
|
|
1330
|
-
addressComparator || (addressComparator =
|
|
1825
|
+
addressComparator || (addressComparator = getAddressComparator());
|
|
1331
1826
|
if (leftEntry[TYPE] === 1 && rightEntry[TYPE] === 1 && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
|
|
1332
1827
|
return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
|
|
1333
1828
|
} else {
|
|
1334
1829
|
return addressComparator(leftAddress, rightAddress);
|
|
1335
1830
|
}
|
|
1336
|
-
}).map(([
|
|
1337
|
-
address,
|
|
1831
|
+
}).map(([address2, addressMeta]) => ({
|
|
1832
|
+
address: address2,
|
|
1338
1833
|
...addressMeta
|
|
1339
1834
|
}));
|
|
1340
1835
|
return orderedAccounts;
|
|
@@ -1356,7 +1851,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1356
1851
|
entry.readableIndices.push(account.addressIndex);
|
|
1357
1852
|
}
|
|
1358
1853
|
}
|
|
1359
|
-
return Object.keys(index).sort(
|
|
1854
|
+
return Object.keys(index).sort(getAddressComparator()).map((lookupTableAddress) => ({
|
|
1360
1855
|
lookupTableAddress,
|
|
1361
1856
|
...index[lookupTableAddress]
|
|
1362
1857
|
}));
|
|
@@ -1397,7 +1892,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1397
1892
|
return instructions.map(({ accounts, data, programAddress }) => {
|
|
1398
1893
|
return {
|
|
1399
1894
|
programAddressIndex: accountIndex[programAddress],
|
|
1400
|
-
...accounts ? { accountIndices: accounts.map(({ address }) => accountIndex[
|
|
1895
|
+
...accounts ? { accountIndices: accounts.map(({ address: address2 }) => accountIndex[address2]) } : null,
|
|
1401
1896
|
...data ? { data } : null
|
|
1402
1897
|
};
|
|
1403
1898
|
});
|
|
@@ -1406,23 +1901,49 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1406
1901
|
if ("nonce" in lifetimeConstraint) {
|
|
1407
1902
|
return lifetimeConstraint.nonce;
|
|
1408
1903
|
}
|
|
1409
|
-
return lifetimeConstraint.blockhash;
|
|
1410
|
-
}
|
|
1411
|
-
function getCompiledStaticAccounts(orderedAccounts) {
|
|
1412
|
-
const firstLookupTableAccountIndex = orderedAccounts.findIndex((account) => "lookupTableAddress" in account);
|
|
1413
|
-
const orderedStaticAccounts = firstLookupTableAccountIndex === -1 ? orderedAccounts : orderedAccounts.slice(0, firstLookupTableAccountIndex);
|
|
1414
|
-
return orderedStaticAccounts.map(({ address }) =>
|
|
1904
|
+
return lifetimeConstraint.blockhash;
|
|
1905
|
+
}
|
|
1906
|
+
function getCompiledStaticAccounts(orderedAccounts) {
|
|
1907
|
+
const firstLookupTableAccountIndex = orderedAccounts.findIndex((account) => "lookupTableAddress" in account);
|
|
1908
|
+
const orderedStaticAccounts = firstLookupTableAccountIndex === -1 ? orderedAccounts : orderedAccounts.slice(0, firstLookupTableAccountIndex);
|
|
1909
|
+
return orderedStaticAccounts.map(({ address: address2 }) => address2);
|
|
1910
|
+
}
|
|
1911
|
+
function compileMessage(transaction) {
|
|
1912
|
+
const addressMap = getAddressMapFromInstructions(transaction.feePayer, transaction.instructions);
|
|
1913
|
+
const orderedAccounts = getOrderedAccountsFromAddressMap(addressMap);
|
|
1914
|
+
return {
|
|
1915
|
+
...transaction.version !== "legacy" ? { addressTableLookups: getCompiledAddressTableLookups(orderedAccounts) } : null,
|
|
1916
|
+
header: getCompiledMessageHeader(orderedAccounts),
|
|
1917
|
+
instructions: getCompiledInstructions(transaction.instructions, orderedAccounts),
|
|
1918
|
+
lifetimeToken: getCompiledLifetimeToken(transaction.lifetimeConstraint),
|
|
1919
|
+
staticAccounts: getCompiledStaticAccounts(orderedAccounts),
|
|
1920
|
+
version: transaction.version
|
|
1921
|
+
};
|
|
1922
|
+
}
|
|
1923
|
+
function getCompiledTransaction(transaction) {
|
|
1924
|
+
const compiledMessage = compileMessage(transaction);
|
|
1925
|
+
let signatures;
|
|
1926
|
+
if ("signatures" in transaction) {
|
|
1927
|
+
signatures = [];
|
|
1928
|
+
for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
|
|
1929
|
+
signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
|
|
1930
|
+
}
|
|
1931
|
+
} else {
|
|
1932
|
+
signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
|
|
1933
|
+
}
|
|
1934
|
+
return {
|
|
1935
|
+
compiledMessage,
|
|
1936
|
+
signatures
|
|
1937
|
+
};
|
|
1415
1938
|
}
|
|
1416
|
-
function
|
|
1417
|
-
const
|
|
1418
|
-
const orderedAccounts = getOrderedAccountsFromAddressMap(addressMap);
|
|
1939
|
+
function addressSerializerCompat(compat) {
|
|
1940
|
+
const codec = getAddressCodec();
|
|
1419
1941
|
return {
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
version: transaction.version
|
|
1942
|
+
description: compat?.description ?? codec.description,
|
|
1943
|
+
deserialize: codec.decode,
|
|
1944
|
+
fixedSize: codec.fixedSize,
|
|
1945
|
+
maxSize: codec.maxSize,
|
|
1946
|
+
serialize: codec.encode
|
|
1426
1947
|
};
|
|
1427
1948
|
}
|
|
1428
1949
|
function getAddressTableLookupCodec() {
|
|
@@ -1430,7 +1951,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1430
1951
|
[
|
|
1431
1952
|
[
|
|
1432
1953
|
"lookupTableAddress",
|
|
1433
|
-
|
|
1954
|
+
addressSerializerCompat(
|
|
1434
1955
|
{
|
|
1435
1956
|
description: "The address of the address lookup table account from which instruction addresses should be looked up"
|
|
1436
1957
|
}
|
|
@@ -1460,37 +1981,33 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1460
1981
|
}
|
|
1461
1982
|
);
|
|
1462
1983
|
}
|
|
1984
|
+
var memoizedU8Codec;
|
|
1985
|
+
function getMemoizedU8Codec() {
|
|
1986
|
+
if (!memoizedU8Codec)
|
|
1987
|
+
memoizedU8Codec = getU8Codec();
|
|
1988
|
+
return memoizedU8Codec;
|
|
1989
|
+
}
|
|
1990
|
+
function getMemoizedU8CodecDescription(description) {
|
|
1991
|
+
const codec = getMemoizedU8Codec();
|
|
1992
|
+
return {
|
|
1993
|
+
...codec,
|
|
1994
|
+
description: description ?? codec.description
|
|
1995
|
+
};
|
|
1996
|
+
}
|
|
1997
|
+
var numSignerAccountsDescription = "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction" ;
|
|
1998
|
+
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" ;
|
|
1999
|
+
var numReadonlyNonSignerAccountsDescription = "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable" ;
|
|
2000
|
+
var messageHeaderDescription = "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses" ;
|
|
1463
2001
|
function getMessageHeaderCodec() {
|
|
1464
|
-
return
|
|
2002
|
+
return getStructCodec(
|
|
1465
2003
|
[
|
|
1466
|
-
[
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
{
|
|
1470
|
-
description: "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction"
|
|
1471
|
-
}
|
|
1472
|
-
)
|
|
1473
|
-
],
|
|
1474
|
-
[
|
|
1475
|
-
"numReadonlySignerAccounts",
|
|
1476
|
-
u8(
|
|
1477
|
-
{
|
|
1478
|
-
description: "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"
|
|
1479
|
-
}
|
|
1480
|
-
)
|
|
1481
|
-
],
|
|
1482
|
-
[
|
|
1483
|
-
"numReadonlyNonSignerAccounts",
|
|
1484
|
-
u8(
|
|
1485
|
-
{
|
|
1486
|
-
description: "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable"
|
|
1487
|
-
}
|
|
1488
|
-
)
|
|
1489
|
-
]
|
|
2004
|
+
["numSignerAccounts", getMemoizedU8CodecDescription(numSignerAccountsDescription)],
|
|
2005
|
+
["numReadonlySignerAccounts", getMemoizedU8CodecDescription(numReadonlySignerAccountsDescription)],
|
|
2006
|
+
["numReadonlyNonSignerAccounts", getMemoizedU8CodecDescription(numReadonlyNonSignerAccountsDescription)]
|
|
1490
2007
|
],
|
|
1491
2008
|
{
|
|
1492
|
-
description:
|
|
1493
|
-
}
|
|
2009
|
+
description: messageHeaderDescription
|
|
2010
|
+
}
|
|
1494
2011
|
);
|
|
1495
2012
|
}
|
|
1496
2013
|
function getInstructionCodec() {
|
|
@@ -1547,24 +2064,13 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1547
2064
|
}
|
|
1548
2065
|
);
|
|
1549
2066
|
}
|
|
1550
|
-
function getError(type, name) {
|
|
1551
|
-
const functionSuffix = name + type[0].toUpperCase() + type.slice(1);
|
|
1552
|
-
return new Error(
|
|
1553
|
-
`No ${type} exists for ${name}. Use \`get${functionSuffix}()\` if you need a ${type}, and \`get${name}Codec()\` if you need to both encode and decode ${name}`
|
|
1554
|
-
);
|
|
1555
|
-
}
|
|
1556
|
-
function getUnimplementedDecoder(name) {
|
|
1557
|
-
return () => {
|
|
1558
|
-
throw getError("decoder", name);
|
|
1559
|
-
};
|
|
1560
|
-
}
|
|
1561
2067
|
var VERSION_FLAG_MASK = 128;
|
|
1562
2068
|
var BASE_CONFIG = {
|
|
1563
2069
|
description: "A single byte that encodes the version of the transaction" ,
|
|
1564
2070
|
fixedSize: null,
|
|
1565
2071
|
maxSize: 1
|
|
1566
2072
|
};
|
|
1567
|
-
function
|
|
2073
|
+
function decode(bytes3, offset = 0) {
|
|
1568
2074
|
const firstByte = bytes3[offset];
|
|
1569
2075
|
if ((firstByte & VERSION_FLAG_MASK) === 0) {
|
|
1570
2076
|
return ["legacy", offset];
|
|
@@ -1573,7 +2079,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1573
2079
|
return [version, offset + 1];
|
|
1574
2080
|
}
|
|
1575
2081
|
}
|
|
1576
|
-
function
|
|
2082
|
+
function encode(value) {
|
|
1577
2083
|
if (value === "legacy") {
|
|
1578
2084
|
return new Uint8Array();
|
|
1579
2085
|
}
|
|
@@ -1582,11 +2088,30 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1582
2088
|
}
|
|
1583
2089
|
return new Uint8Array([value | VERSION_FLAG_MASK]);
|
|
1584
2090
|
}
|
|
1585
|
-
function
|
|
2091
|
+
function getTransactionVersionDecoder() {
|
|
1586
2092
|
return {
|
|
1587
2093
|
...BASE_CONFIG,
|
|
1588
|
-
|
|
1589
|
-
|
|
2094
|
+
decode
|
|
2095
|
+
};
|
|
2096
|
+
}
|
|
2097
|
+
function getTransactionVersionEncoder() {
|
|
2098
|
+
return {
|
|
2099
|
+
...BASE_CONFIG,
|
|
2100
|
+
encode
|
|
2101
|
+
};
|
|
2102
|
+
}
|
|
2103
|
+
function getTransactionVersionCodec() {
|
|
2104
|
+
return combineCodec(getTransactionVersionEncoder(), getTransactionVersionDecoder());
|
|
2105
|
+
}
|
|
2106
|
+
function getError(type, name) {
|
|
2107
|
+
const functionSuffix = name + type[0].toUpperCase() + type.slice(1);
|
|
2108
|
+
return new Error(
|
|
2109
|
+
`No ${type} exists for ${name}. Use \`get${functionSuffix}()\` if you need a ${type}, and \`get${name}Codec()\` if you need to both encode and decode ${name}`
|
|
2110
|
+
);
|
|
2111
|
+
}
|
|
2112
|
+
function getUnimplementedDecoder(name) {
|
|
2113
|
+
return () => {
|
|
2114
|
+
throw getError("decoder", name);
|
|
1590
2115
|
};
|
|
1591
2116
|
}
|
|
1592
2117
|
var BASE_CONFIG2 = {
|
|
@@ -1594,7 +2119,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1594
2119
|
fixedSize: null,
|
|
1595
2120
|
maxSize: null
|
|
1596
2121
|
};
|
|
1597
|
-
function
|
|
2122
|
+
function serialize(compiledMessage) {
|
|
1598
2123
|
if (compiledMessage.version === "legacy") {
|
|
1599
2124
|
return struct(getPreludeStructSerializerTuple()).serialize(compiledMessage);
|
|
1600
2125
|
} else {
|
|
@@ -1615,13 +2140,22 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1615
2140
|
).serialize(compiledMessage);
|
|
1616
2141
|
}
|
|
1617
2142
|
}
|
|
2143
|
+
function toSerializer(codec) {
|
|
2144
|
+
return {
|
|
2145
|
+
description: codec.description,
|
|
2146
|
+
deserialize: codec.decode,
|
|
2147
|
+
fixedSize: codec.fixedSize,
|
|
2148
|
+
maxSize: codec.maxSize,
|
|
2149
|
+
serialize: codec.encode
|
|
2150
|
+
};
|
|
2151
|
+
}
|
|
1618
2152
|
function getPreludeStructSerializerTuple() {
|
|
1619
2153
|
return [
|
|
1620
|
-
["version", getTransactionVersionCodec()],
|
|
1621
|
-
["header", getMessageHeaderCodec()],
|
|
2154
|
+
["version", toSerializer(getTransactionVersionCodec())],
|
|
2155
|
+
["header", toSerializer(getMessageHeaderCodec())],
|
|
1622
2156
|
[
|
|
1623
2157
|
"staticAccounts",
|
|
1624
|
-
array(
|
|
2158
|
+
array(toSerializer(getAddressCodec()), {
|
|
1625
2159
|
description: "A compact-array of static account addresses belonging to this transaction" ,
|
|
1626
2160
|
size: shortU16()
|
|
1627
2161
|
})
|
|
@@ -1653,45 +2187,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1653
2187
|
return {
|
|
1654
2188
|
...BASE_CONFIG2,
|
|
1655
2189
|
deserialize: getUnimplementedDecoder("CompiledMessage"),
|
|
1656
|
-
serialize
|
|
1657
|
-
};
|
|
1658
|
-
}
|
|
1659
|
-
async function getCompiledMessageSignature(message, secretKey) {
|
|
1660
|
-
const wireMessageBytes = getCompiledMessageEncoder().serialize(message);
|
|
1661
|
-
const signature = await signBytes(secretKey, wireMessageBytes);
|
|
1662
|
-
return signature;
|
|
1663
|
-
}
|
|
1664
|
-
async function signTransaction(keyPair, transaction) {
|
|
1665
|
-
const compiledMessage = compileMessage(transaction);
|
|
1666
|
-
const [signerPublicKey, signature] = await Promise.all([
|
|
1667
|
-
getAddressFromPublicKey(keyPair.publicKey),
|
|
1668
|
-
getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
|
|
1669
|
-
]);
|
|
1670
|
-
const nextSignatures = {
|
|
1671
|
-
..."signatures" in transaction ? transaction.signatures : null,
|
|
1672
|
-
...{ [signerPublicKey]: signature }
|
|
1673
|
-
};
|
|
1674
|
-
const out = {
|
|
1675
|
-
...transaction,
|
|
1676
|
-
signatures: nextSignatures
|
|
1677
|
-
};
|
|
1678
|
-
Object.freeze(out);
|
|
1679
|
-
return out;
|
|
1680
|
-
}
|
|
1681
|
-
function getCompiledTransaction(transaction) {
|
|
1682
|
-
const compiledMessage = compileMessage(transaction);
|
|
1683
|
-
let signatures;
|
|
1684
|
-
if ("signatures" in transaction) {
|
|
1685
|
-
signatures = [];
|
|
1686
|
-
for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
|
|
1687
|
-
signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
|
|
1688
|
-
}
|
|
1689
|
-
} else {
|
|
1690
|
-
signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
|
|
1691
|
-
}
|
|
1692
|
-
return {
|
|
1693
|
-
compiledMessage,
|
|
1694
|
-
signatures
|
|
2190
|
+
serialize
|
|
1695
2191
|
};
|
|
1696
2192
|
}
|
|
1697
2193
|
var BASE_CONFIG3 = {
|
|
@@ -1699,7 +2195,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1699
2195
|
fixedSize: null,
|
|
1700
2196
|
maxSize: null
|
|
1701
2197
|
};
|
|
1702
|
-
function
|
|
2198
|
+
function serialize2(transaction) {
|
|
1703
2199
|
const compiledTransaction = getCompiledTransaction(transaction);
|
|
1704
2200
|
return struct([
|
|
1705
2201
|
[
|
|
@@ -1716,8 +2212,82 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1716
2212
|
return {
|
|
1717
2213
|
...BASE_CONFIG3,
|
|
1718
2214
|
deserialize: getUnimplementedDecoder("CompiledMessage"),
|
|
1719
|
-
serialize:
|
|
2215
|
+
serialize: serialize2
|
|
2216
|
+
};
|
|
2217
|
+
}
|
|
2218
|
+
function assertIsTransactionSignature(putativeTransactionSignature) {
|
|
2219
|
+
try {
|
|
2220
|
+
if (
|
|
2221
|
+
// Lowest value (64 bytes of zeroes)
|
|
2222
|
+
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
2223
|
+
putativeTransactionSignature.length > 88
|
|
2224
|
+
) {
|
|
2225
|
+
throw new Error("Expected input string to decode to a byte array of length 64.");
|
|
2226
|
+
}
|
|
2227
|
+
const bytes3 = base58.serialize(putativeTransactionSignature);
|
|
2228
|
+
const numBytes = bytes3.byteLength;
|
|
2229
|
+
if (numBytes !== 64) {
|
|
2230
|
+
throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
|
|
2231
|
+
}
|
|
2232
|
+
} catch (e3) {
|
|
2233
|
+
throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, {
|
|
2234
|
+
cause: e3
|
|
2235
|
+
});
|
|
2236
|
+
}
|
|
2237
|
+
}
|
|
2238
|
+
function isTransactionSignature(putativeTransactionSignature) {
|
|
2239
|
+
if (
|
|
2240
|
+
// Lowest value (64 bytes of zeroes)
|
|
2241
|
+
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
2242
|
+
putativeTransactionSignature.length > 88
|
|
2243
|
+
) {
|
|
2244
|
+
return false;
|
|
2245
|
+
}
|
|
2246
|
+
const bytes3 = base58.serialize(putativeTransactionSignature);
|
|
2247
|
+
const numBytes = bytes3.byteLength;
|
|
2248
|
+
if (numBytes !== 64) {
|
|
2249
|
+
return false;
|
|
2250
|
+
}
|
|
2251
|
+
return true;
|
|
2252
|
+
}
|
|
2253
|
+
async function getCompiledMessageSignature(message, secretKey) {
|
|
2254
|
+
const wireMessageBytes = getCompiledMessageEncoder().serialize(message);
|
|
2255
|
+
const signature = await signBytes(secretKey, wireMessageBytes);
|
|
2256
|
+
return signature;
|
|
2257
|
+
}
|
|
2258
|
+
function getSignatureFromTransaction(transaction) {
|
|
2259
|
+
const signature = transaction.signatures[transaction.feePayer];
|
|
2260
|
+
if (!signature) {
|
|
2261
|
+
throw new Error(
|
|
2262
|
+
"Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
|
|
2263
|
+
);
|
|
2264
|
+
}
|
|
2265
|
+
return signature;
|
|
2266
|
+
}
|
|
2267
|
+
async function signTransaction(keyPairs, transaction) {
|
|
2268
|
+
const compiledMessage = compileMessage(transaction);
|
|
2269
|
+
const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
|
|
2270
|
+
const publicKeySignaturePairs = await Promise.all(
|
|
2271
|
+
keyPairs.map(
|
|
2272
|
+
(keyPair) => Promise.all([
|
|
2273
|
+
getAddressFromPublicKey(keyPair.publicKey),
|
|
2274
|
+
getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
|
|
2275
|
+
])
|
|
2276
|
+
)
|
|
2277
|
+
);
|
|
2278
|
+
for (const [signerPublicKey, signature] of publicKeySignaturePairs) {
|
|
2279
|
+
nextSignatures[signerPublicKey] = signature;
|
|
2280
|
+
}
|
|
2281
|
+
const out = {
|
|
2282
|
+
...transaction,
|
|
2283
|
+
signatures: nextSignatures
|
|
1720
2284
|
};
|
|
2285
|
+
Object.freeze(out);
|
|
2286
|
+
return out;
|
|
2287
|
+
}
|
|
2288
|
+
function transactionSignature(putativeTransactionSignature) {
|
|
2289
|
+
assertIsTransactionSignature(putativeTransactionSignature);
|
|
2290
|
+
return putativeTransactionSignature;
|
|
1721
2291
|
}
|
|
1722
2292
|
function getBase64EncodedWireTransaction(transaction) {
|
|
1723
2293
|
const wireTransactionBytes = getTransactionEncoder().serialize(transaction);
|
|
@@ -1726,11 +2296,65 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1726
2296
|
}
|
|
1727
2297
|
}
|
|
1728
2298
|
|
|
1729
|
-
// src/
|
|
2299
|
+
// src/airdrop.ts
|
|
2300
|
+
init_env_shim();
|
|
2301
|
+
|
|
2302
|
+
// src/airdrop-confirmer.ts
|
|
2303
|
+
init_env_shim();
|
|
2304
|
+
|
|
2305
|
+
// src/transaction-confirmation-strategy-racer.ts
|
|
2306
|
+
init_env_shim();
|
|
2307
|
+
async function raceStrategies(signature, config, getSpecificStrategiesForRace) {
|
|
2308
|
+
const { abortSignal: callerAbortSignal, commitment, getRecentSignatureConfirmationPromise } = config;
|
|
2309
|
+
callerAbortSignal.throwIfAborted();
|
|
2310
|
+
const abortController = new AbortController();
|
|
2311
|
+
function handleAbort() {
|
|
2312
|
+
abortController.abort();
|
|
2313
|
+
}
|
|
2314
|
+
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
2315
|
+
try {
|
|
2316
|
+
const specificStrategies = getSpecificStrategiesForRace({
|
|
2317
|
+
...config,
|
|
2318
|
+
abortSignal: abortController.signal
|
|
2319
|
+
});
|
|
2320
|
+
return await Promise.race([
|
|
2321
|
+
getRecentSignatureConfirmationPromise({
|
|
2322
|
+
abortSignal: abortController.signal,
|
|
2323
|
+
commitment,
|
|
2324
|
+
signature
|
|
2325
|
+
}),
|
|
2326
|
+
...specificStrategies
|
|
2327
|
+
]);
|
|
2328
|
+
} finally {
|
|
2329
|
+
abortController.abort();
|
|
2330
|
+
}
|
|
2331
|
+
}
|
|
2332
|
+
|
|
2333
|
+
// src/transaction-confirmation-strategy-recent-signature.ts
|
|
1730
2334
|
init_env_shim();
|
|
1731
2335
|
|
|
1732
2336
|
// ../rpc-core/dist/index.browser.js
|
|
1733
2337
|
init_env_shim();
|
|
2338
|
+
function getCommitmentScore(commitment) {
|
|
2339
|
+
switch (commitment) {
|
|
2340
|
+
case "finalized":
|
|
2341
|
+
return 2;
|
|
2342
|
+
case "confirmed":
|
|
2343
|
+
return 1;
|
|
2344
|
+
case "processed":
|
|
2345
|
+
return 0;
|
|
2346
|
+
default:
|
|
2347
|
+
return ((_) => {
|
|
2348
|
+
throw new Error(`Unrecognized commitment \`${commitment}\`.`);
|
|
2349
|
+
})();
|
|
2350
|
+
}
|
|
2351
|
+
}
|
|
2352
|
+
function commitmentComparator(a, b) {
|
|
2353
|
+
if (a === b) {
|
|
2354
|
+
return 0;
|
|
2355
|
+
}
|
|
2356
|
+
return getCommitmentScore(a) < getCommitmentScore(b) ? -1 : 1;
|
|
2357
|
+
}
|
|
1734
2358
|
function visitNode(value, keyPath, onIntegerOverflow) {
|
|
1735
2359
|
if (Array.isArray(value)) {
|
|
1736
2360
|
return value.map(
|
|
@@ -1757,68 +2381,215 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1757
2381
|
return visitNode(params, [], onIntegerOverflow);
|
|
1758
2382
|
}
|
|
1759
2383
|
var KEYPATH_WILDCARD = {};
|
|
2384
|
+
var jsonParsedTokenAccountsConfigs = [
|
|
2385
|
+
// parsed Token/Token22 token account
|
|
2386
|
+
["data", "parsed", "info", "tokenAmount", "decimals"],
|
|
2387
|
+
["data", "parsed", "info", "tokenAmount", "uiAmount"],
|
|
2388
|
+
["data", "parsed", "info", "rentExemptReserve", "decimals"],
|
|
2389
|
+
["data", "parsed", "info", "rentExemptReserve", "uiAmount"],
|
|
2390
|
+
["data", "parsed", "info", "delegatedAmount", "decimals"],
|
|
2391
|
+
["data", "parsed", "info", "delegatedAmount", "uiAmount"],
|
|
2392
|
+
["data", "parsed", "info", "extensions", KEYPATH_WILDCARD, "state", "olderTransferFee", "transferFeeBasisPoints"],
|
|
2393
|
+
["data", "parsed", "info", "extensions", KEYPATH_WILDCARD, "state", "newerTransferFee", "transferFeeBasisPoints"],
|
|
2394
|
+
["data", "parsed", "info", "extensions", KEYPATH_WILDCARD, "state", "preUpdateAverageRate"],
|
|
2395
|
+
["data", "parsed", "info", "extensions", KEYPATH_WILDCARD, "state", "currentRate"]
|
|
2396
|
+
];
|
|
2397
|
+
var jsonParsedAccountsConfigs = [
|
|
2398
|
+
...jsonParsedTokenAccountsConfigs,
|
|
2399
|
+
// parsed AddressTableLookup account
|
|
2400
|
+
["data", "parsed", "info", "lastExtendedSlotStartIndex"],
|
|
2401
|
+
// parsed Config account
|
|
2402
|
+
["data", "parsed", "info", "slashPenalty"],
|
|
2403
|
+
["data", "parsed", "info", "warmupCooldownRate"],
|
|
2404
|
+
// parsed Token/Token22 mint account
|
|
2405
|
+
["data", "parsed", "info", "decimals"],
|
|
2406
|
+
// parsed Token/Token22 multisig account
|
|
2407
|
+
["data", "parsed", "info", "numRequiredSigners"],
|
|
2408
|
+
["data", "parsed", "info", "numValidSigners"],
|
|
2409
|
+
// parsed Stake account
|
|
2410
|
+
["data", "parsed", "info", "stake", "delegation", "warmupCooldownRate"],
|
|
2411
|
+
// parsed Sysvar rent account
|
|
2412
|
+
["data", "parsed", "info", "exemptionThreshold"],
|
|
2413
|
+
["data", "parsed", "info", "burnPercent"],
|
|
2414
|
+
// parsed Vote account
|
|
2415
|
+
["data", "parsed", "info", "commission"],
|
|
2416
|
+
["data", "parsed", "info", "votes", KEYPATH_WILDCARD, "confirmationCount"]
|
|
2417
|
+
];
|
|
1760
2418
|
var memoizedNotificationKeypaths;
|
|
1761
2419
|
var memoizedResponseKeypaths;
|
|
1762
2420
|
function getAllowedNumericKeypathsForNotification() {
|
|
1763
2421
|
if (!memoizedNotificationKeypaths) {
|
|
1764
|
-
memoizedNotificationKeypaths = {
|
|
2422
|
+
memoizedNotificationKeypaths = {
|
|
2423
|
+
accountNotifications: jsonParsedAccountsConfigs.map((c) => ["value", ...c]),
|
|
2424
|
+
blockNotifications: [
|
|
2425
|
+
["value", "block", "blockTime"],
|
|
2426
|
+
[
|
|
2427
|
+
"value",
|
|
2428
|
+
"block",
|
|
2429
|
+
"transactions",
|
|
2430
|
+
KEYPATH_WILDCARD,
|
|
2431
|
+
"meta",
|
|
2432
|
+
"preTokenBalances",
|
|
2433
|
+
KEYPATH_WILDCARD,
|
|
2434
|
+
"accountIndex"
|
|
2435
|
+
],
|
|
2436
|
+
[
|
|
2437
|
+
"value",
|
|
2438
|
+
"block",
|
|
2439
|
+
"transactions",
|
|
2440
|
+
KEYPATH_WILDCARD,
|
|
2441
|
+
"meta",
|
|
2442
|
+
"preTokenBalances",
|
|
2443
|
+
KEYPATH_WILDCARD,
|
|
2444
|
+
"uiTokenAmount",
|
|
2445
|
+
"decimals"
|
|
2446
|
+
],
|
|
2447
|
+
[
|
|
2448
|
+
"value",
|
|
2449
|
+
"block",
|
|
2450
|
+
"transactions",
|
|
2451
|
+
KEYPATH_WILDCARD,
|
|
2452
|
+
"meta",
|
|
2453
|
+
"postTokenBalances",
|
|
2454
|
+
KEYPATH_WILDCARD,
|
|
2455
|
+
"accountIndex"
|
|
2456
|
+
],
|
|
2457
|
+
[
|
|
2458
|
+
"value",
|
|
2459
|
+
"block",
|
|
2460
|
+
"transactions",
|
|
2461
|
+
KEYPATH_WILDCARD,
|
|
2462
|
+
"meta",
|
|
2463
|
+
"postTokenBalances",
|
|
2464
|
+
KEYPATH_WILDCARD,
|
|
2465
|
+
"uiTokenAmount",
|
|
2466
|
+
"decimals"
|
|
2467
|
+
],
|
|
2468
|
+
["value", "block", "transactions", KEYPATH_WILDCARD, "meta", "rewards", KEYPATH_WILDCARD, "commission"],
|
|
2469
|
+
[
|
|
2470
|
+
"value",
|
|
2471
|
+
"block",
|
|
2472
|
+
"transactions",
|
|
2473
|
+
KEYPATH_WILDCARD,
|
|
2474
|
+
"meta",
|
|
2475
|
+
"innerInstructions",
|
|
2476
|
+
KEYPATH_WILDCARD,
|
|
2477
|
+
"index"
|
|
2478
|
+
],
|
|
2479
|
+
[
|
|
2480
|
+
"value",
|
|
2481
|
+
"block",
|
|
2482
|
+
"transactions",
|
|
2483
|
+
KEYPATH_WILDCARD,
|
|
2484
|
+
"meta",
|
|
2485
|
+
"innerInstructions",
|
|
2486
|
+
KEYPATH_WILDCARD,
|
|
2487
|
+
"instructions",
|
|
2488
|
+
KEYPATH_WILDCARD,
|
|
2489
|
+
"programIdIndex"
|
|
2490
|
+
],
|
|
2491
|
+
[
|
|
2492
|
+
"value",
|
|
2493
|
+
"block",
|
|
2494
|
+
"transactions",
|
|
2495
|
+
KEYPATH_WILDCARD,
|
|
2496
|
+
"meta",
|
|
2497
|
+
"innerInstructions",
|
|
2498
|
+
KEYPATH_WILDCARD,
|
|
2499
|
+
"instructions",
|
|
2500
|
+
KEYPATH_WILDCARD,
|
|
2501
|
+
"accounts",
|
|
2502
|
+
KEYPATH_WILDCARD
|
|
2503
|
+
],
|
|
2504
|
+
[
|
|
2505
|
+
"value",
|
|
2506
|
+
"block",
|
|
2507
|
+
"transactions",
|
|
2508
|
+
KEYPATH_WILDCARD,
|
|
2509
|
+
"transaction",
|
|
2510
|
+
"message",
|
|
2511
|
+
"addressTableLookups",
|
|
2512
|
+
KEYPATH_WILDCARD,
|
|
2513
|
+
"writableIndexes",
|
|
2514
|
+
KEYPATH_WILDCARD
|
|
2515
|
+
],
|
|
2516
|
+
[
|
|
2517
|
+
"value",
|
|
2518
|
+
"block",
|
|
2519
|
+
"transactions",
|
|
2520
|
+
KEYPATH_WILDCARD,
|
|
2521
|
+
"transaction",
|
|
2522
|
+
"message",
|
|
2523
|
+
"addressTableLookups",
|
|
2524
|
+
KEYPATH_WILDCARD,
|
|
2525
|
+
"readonlyIndexes",
|
|
2526
|
+
KEYPATH_WILDCARD
|
|
2527
|
+
],
|
|
2528
|
+
[
|
|
2529
|
+
"value",
|
|
2530
|
+
"block",
|
|
2531
|
+
"transactions",
|
|
2532
|
+
KEYPATH_WILDCARD,
|
|
2533
|
+
"transaction",
|
|
2534
|
+
"message",
|
|
2535
|
+
"instructions",
|
|
2536
|
+
KEYPATH_WILDCARD,
|
|
2537
|
+
"programIdIndex"
|
|
2538
|
+
],
|
|
2539
|
+
[
|
|
2540
|
+
"value",
|
|
2541
|
+
"block",
|
|
2542
|
+
"transactions",
|
|
2543
|
+
KEYPATH_WILDCARD,
|
|
2544
|
+
"transaction",
|
|
2545
|
+
"message",
|
|
2546
|
+
"instructions",
|
|
2547
|
+
KEYPATH_WILDCARD,
|
|
2548
|
+
"accounts",
|
|
2549
|
+
KEYPATH_WILDCARD
|
|
2550
|
+
],
|
|
2551
|
+
[
|
|
2552
|
+
"value",
|
|
2553
|
+
"block",
|
|
2554
|
+
"transactions",
|
|
2555
|
+
KEYPATH_WILDCARD,
|
|
2556
|
+
"transaction",
|
|
2557
|
+
"message",
|
|
2558
|
+
"header",
|
|
2559
|
+
"numReadonlySignedAccounts"
|
|
2560
|
+
],
|
|
2561
|
+
[
|
|
2562
|
+
"value",
|
|
2563
|
+
"block",
|
|
2564
|
+
"transactions",
|
|
2565
|
+
KEYPATH_WILDCARD,
|
|
2566
|
+
"transaction",
|
|
2567
|
+
"message",
|
|
2568
|
+
"header",
|
|
2569
|
+
"numReadonlyUnsignedAccounts"
|
|
2570
|
+
],
|
|
2571
|
+
[
|
|
2572
|
+
"value",
|
|
2573
|
+
"block",
|
|
2574
|
+
"transactions",
|
|
2575
|
+
KEYPATH_WILDCARD,
|
|
2576
|
+
"transaction",
|
|
2577
|
+
"message",
|
|
2578
|
+
"header",
|
|
2579
|
+
"numRequiredSignatures"
|
|
2580
|
+
],
|
|
2581
|
+
["value", "block", "rewards", KEYPATH_WILDCARD, "commission"]
|
|
2582
|
+
],
|
|
2583
|
+
programNotifications: jsonParsedAccountsConfigs.flatMap((c) => [
|
|
2584
|
+
["value", KEYPATH_WILDCARD, "account", ...c],
|
|
2585
|
+
[KEYPATH_WILDCARD, "account", ...c]
|
|
2586
|
+
])
|
|
2587
|
+
};
|
|
1765
2588
|
}
|
|
1766
2589
|
return memoizedNotificationKeypaths;
|
|
1767
2590
|
}
|
|
1768
2591
|
function getAllowedNumericKeypathsForResponse() {
|
|
1769
2592
|
if (!memoizedResponseKeypaths) {
|
|
1770
|
-
const jsonParsedTokenAccountsConfigs = [
|
|
1771
|
-
// parsed Token/Token22 token account
|
|
1772
|
-
["data", "parsed", "info", "tokenAmount", "decimals"],
|
|
1773
|
-
["data", "parsed", "info", "tokenAmount", "uiAmount"],
|
|
1774
|
-
["data", "parsed", "info", "rentExemptReserve", "decimals"],
|
|
1775
|
-
["data", "parsed", "info", "rentExemptReserve", "uiAmount"],
|
|
1776
|
-
["data", "parsed", "info", "delegatedAmount", "decimals"],
|
|
1777
|
-
["data", "parsed", "info", "delegatedAmount", "uiAmount"],
|
|
1778
|
-
[
|
|
1779
|
-
"data",
|
|
1780
|
-
"parsed",
|
|
1781
|
-
"info",
|
|
1782
|
-
"extensions",
|
|
1783
|
-
KEYPATH_WILDCARD,
|
|
1784
|
-
"state",
|
|
1785
|
-
"olderTransferFee",
|
|
1786
|
-
"transferFeeBasisPoints"
|
|
1787
|
-
],
|
|
1788
|
-
[
|
|
1789
|
-
"data",
|
|
1790
|
-
"parsed",
|
|
1791
|
-
"info",
|
|
1792
|
-
"extensions",
|
|
1793
|
-
KEYPATH_WILDCARD,
|
|
1794
|
-
"state",
|
|
1795
|
-
"newerTransferFee",
|
|
1796
|
-
"transferFeeBasisPoints"
|
|
1797
|
-
],
|
|
1798
|
-
["data", "parsed", "info", "extensions", KEYPATH_WILDCARD, "state", "preUpdateAverageRate"],
|
|
1799
|
-
["data", "parsed", "info", "extensions", KEYPATH_WILDCARD, "state", "currentRate"]
|
|
1800
|
-
];
|
|
1801
|
-
const jsonParsedAccountsConfigs = [
|
|
1802
|
-
...jsonParsedTokenAccountsConfigs,
|
|
1803
|
-
// parsed AddressTableLookup account
|
|
1804
|
-
["data", "parsed", "info", "lastExtendedSlotStartIndex"],
|
|
1805
|
-
// parsed Config account
|
|
1806
|
-
["data", "parsed", "info", "slashPenalty"],
|
|
1807
|
-
["data", "parsed", "info", "warmupCooldownRate"],
|
|
1808
|
-
// parsed Token/Token22 mint account
|
|
1809
|
-
["data", "parsed", "info", "decimals"],
|
|
1810
|
-
// parsed Token/Token22 multisig account
|
|
1811
|
-
["data", "parsed", "info", "numRequiredSigners"],
|
|
1812
|
-
["data", "parsed", "info", "numValidSigners"],
|
|
1813
|
-
// parsed Stake account
|
|
1814
|
-
["data", "parsed", "info", "stake", "delegation", "warmupCooldownRate"],
|
|
1815
|
-
// parsed Sysvar rent account
|
|
1816
|
-
["data", "parsed", "info", "exemptionThreshold"],
|
|
1817
|
-
["data", "parsed", "info", "burnPercent"],
|
|
1818
|
-
// parsed Vote account
|
|
1819
|
-
["data", "parsed", "info", "commission"],
|
|
1820
|
-
["data", "parsed", "info", "votes", KEYPATH_WILDCARD, "confirmationCount"]
|
|
1821
|
-
];
|
|
1822
2593
|
memoizedResponseKeypaths = {
|
|
1823
2594
|
getAccountInfo: jsonParsedAccountsConfigs.map((c) => ["value", ...c]),
|
|
1824
2595
|
getBlock: [
|
|
@@ -2083,6 +2854,138 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2083
2854
|
}
|
|
2084
2855
|
});
|
|
2085
2856
|
}
|
|
2857
|
+
function createSolanaRpcSubscriptionsApi_UNSTABLE(config) {
|
|
2858
|
+
return createSolanaRpcSubscriptionsApi(config);
|
|
2859
|
+
}
|
|
2860
|
+
|
|
2861
|
+
// src/transaction-confirmation-strategy-recent-signature.ts
|
|
2862
|
+
function createRecentSignatureConfirmationPromiseFactory(rpc, rpcSubscriptions) {
|
|
2863
|
+
return async function getRecentSignatureConfirmationPromise({
|
|
2864
|
+
abortSignal: callerAbortSignal,
|
|
2865
|
+
commitment,
|
|
2866
|
+
signature
|
|
2867
|
+
}) {
|
|
2868
|
+
const abortController = new AbortController();
|
|
2869
|
+
function handleAbort() {
|
|
2870
|
+
abortController.abort();
|
|
2871
|
+
}
|
|
2872
|
+
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
2873
|
+
const signatureStatusNotifications = await rpcSubscriptions.signatureNotifications(signature, { commitment }).subscribe({ abortSignal: abortController.signal });
|
|
2874
|
+
const signatureDidCommitPromise = (async () => {
|
|
2875
|
+
for await (const signatureStatusNotification of signatureStatusNotifications) {
|
|
2876
|
+
if (signatureStatusNotification.value.err) {
|
|
2877
|
+
throw new Error(`The transaction with signature \`${signature}\` failed.`, {
|
|
2878
|
+
cause: signatureStatusNotification.value.err
|
|
2879
|
+
});
|
|
2880
|
+
} else {
|
|
2881
|
+
return;
|
|
2882
|
+
}
|
|
2883
|
+
}
|
|
2884
|
+
})();
|
|
2885
|
+
const signatureStatusLookupPromise = (async () => {
|
|
2886
|
+
const { value: signatureStatusResults } = await rpc.getSignatureStatuses([signature]).send({ abortSignal: abortController.signal });
|
|
2887
|
+
const signatureStatus = signatureStatusResults[0];
|
|
2888
|
+
if (signatureStatus && signatureStatus.confirmationStatus && commitmentComparator(signatureStatus.confirmationStatus, commitment) >= 0) {
|
|
2889
|
+
return;
|
|
2890
|
+
} else {
|
|
2891
|
+
await new Promise(() => {
|
|
2892
|
+
});
|
|
2893
|
+
}
|
|
2894
|
+
})();
|
|
2895
|
+
try {
|
|
2896
|
+
return await Promise.race([signatureDidCommitPromise, signatureStatusLookupPromise]);
|
|
2897
|
+
} finally {
|
|
2898
|
+
abortController.abort();
|
|
2899
|
+
}
|
|
2900
|
+
};
|
|
2901
|
+
}
|
|
2902
|
+
|
|
2903
|
+
// src/transaction-confirmation-strategy-timeout.ts
|
|
2904
|
+
init_env_shim();
|
|
2905
|
+
async function getTimeoutPromise({ abortSignal: callerAbortSignal, commitment }) {
|
|
2906
|
+
return await new Promise((_, reject) => {
|
|
2907
|
+
const handleAbort = (e3) => {
|
|
2908
|
+
clearTimeout(timeoutId);
|
|
2909
|
+
const abortError = new DOMException(e3.target.reason, "AbortError");
|
|
2910
|
+
reject(abortError);
|
|
2911
|
+
};
|
|
2912
|
+
callerAbortSignal.addEventListener("abort", handleAbort);
|
|
2913
|
+
const timeoutMs = commitment === "processed" ? 3e4 : 6e4;
|
|
2914
|
+
const startMs = performance.now();
|
|
2915
|
+
const timeoutId = (
|
|
2916
|
+
// We use `setTimeout` instead of `AbortSignal.timeout()` because we want to measure
|
|
2917
|
+
// elapsed time instead of active time.
|
|
2918
|
+
// See https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/timeout_static
|
|
2919
|
+
setTimeout(() => {
|
|
2920
|
+
const elapsedMs = performance.now() - startMs;
|
|
2921
|
+
reject(new DOMException(`Timeout elapsed after ${elapsedMs} ms`, "TimeoutError"));
|
|
2922
|
+
}, timeoutMs)
|
|
2923
|
+
);
|
|
2924
|
+
});
|
|
2925
|
+
}
|
|
2926
|
+
|
|
2927
|
+
// src/airdrop-confirmer.ts
|
|
2928
|
+
function createDefaultSignatureOnlyRecentTransactionConfirmer({
|
|
2929
|
+
rpc,
|
|
2930
|
+
rpcSubscriptions
|
|
2931
|
+
}) {
|
|
2932
|
+
const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
|
|
2933
|
+
rpc,
|
|
2934
|
+
rpcSubscriptions
|
|
2935
|
+
);
|
|
2936
|
+
return async function confirmSignatureOnlyRecentTransaction(config) {
|
|
2937
|
+
await waitForRecentTransactionConfirmationUntilTimeout({
|
|
2938
|
+
...config,
|
|
2939
|
+
getRecentSignatureConfirmationPromise,
|
|
2940
|
+
getTimeoutPromise
|
|
2941
|
+
});
|
|
2942
|
+
};
|
|
2943
|
+
}
|
|
2944
|
+
async function waitForRecentTransactionConfirmationUntilTimeout(config) {
|
|
2945
|
+
await raceStrategies(
|
|
2946
|
+
config.signature,
|
|
2947
|
+
config,
|
|
2948
|
+
function getSpecificStrategiesForRace({ abortSignal, commitment, getTimeoutPromise: getTimeoutPromise2 }) {
|
|
2949
|
+
return [
|
|
2950
|
+
getTimeoutPromise2({
|
|
2951
|
+
abortSignal,
|
|
2952
|
+
commitment
|
|
2953
|
+
})
|
|
2954
|
+
];
|
|
2955
|
+
}
|
|
2956
|
+
);
|
|
2957
|
+
}
|
|
2958
|
+
|
|
2959
|
+
// src/airdrop.ts
|
|
2960
|
+
async function requestAndConfirmAirdrop({
|
|
2961
|
+
abortSignal,
|
|
2962
|
+
commitment,
|
|
2963
|
+
lamports,
|
|
2964
|
+
recipientAddress,
|
|
2965
|
+
rpc,
|
|
2966
|
+
rpcSubscriptions
|
|
2967
|
+
}) {
|
|
2968
|
+
const airdropTransactionSignature = await rpc.requestAirdrop(recipientAddress, lamports, { commitment }).send({ abortSignal });
|
|
2969
|
+
const confirmSignatureOnlyTransaction = createDefaultSignatureOnlyRecentTransactionConfirmer({
|
|
2970
|
+
rpc,
|
|
2971
|
+
rpcSubscriptions
|
|
2972
|
+
});
|
|
2973
|
+
await confirmSignatureOnlyTransaction({
|
|
2974
|
+
abortSignal,
|
|
2975
|
+
commitment,
|
|
2976
|
+
signature: airdropTransactionSignature
|
|
2977
|
+
});
|
|
2978
|
+
return airdropTransactionSignature;
|
|
2979
|
+
}
|
|
2980
|
+
|
|
2981
|
+
// src/rpc.ts
|
|
2982
|
+
init_env_shim();
|
|
2983
|
+
|
|
2984
|
+
// ../functional/dist/index.browser.js
|
|
2985
|
+
init_env_shim();
|
|
2986
|
+
function pipe(init, ...fns) {
|
|
2987
|
+
return fns.reduce((acc, fn) => fn(acc), init);
|
|
2988
|
+
}
|
|
2086
2989
|
|
|
2087
2990
|
// ../rpc-transport/dist/index.browser.js
|
|
2088
2991
|
init_env_shim();
|
|
@@ -2149,20 +3052,21 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2149
3052
|
function createJsonRpc(rpcConfig) {
|
|
2150
3053
|
return makeProxy(rpcConfig);
|
|
2151
3054
|
}
|
|
2152
|
-
function
|
|
3055
|
+
function registerIterableCleanup(iterable, cleanupFn) {
|
|
2153
3056
|
(async () => {
|
|
2154
3057
|
try {
|
|
2155
3058
|
for await (const _ of iterable)
|
|
2156
3059
|
;
|
|
2157
|
-
} catch
|
|
2158
|
-
|
|
3060
|
+
} catch {
|
|
3061
|
+
} finally {
|
|
3062
|
+
cleanupFn();
|
|
2159
3063
|
}
|
|
2160
3064
|
})();
|
|
2161
3065
|
}
|
|
2162
3066
|
function createPendingRpcSubscription(rpcConfig, { params, subscribeMethodName, unsubscribeMethodName, responseProcessor }) {
|
|
2163
3067
|
return {
|
|
2164
|
-
async subscribe(
|
|
2165
|
-
|
|
3068
|
+
async subscribe({ abortSignal }) {
|
|
3069
|
+
abortSignal.throwIfAborted();
|
|
2166
3070
|
let subscriptionId;
|
|
2167
3071
|
function handleCleanup() {
|
|
2168
3072
|
if (subscriptionId !== void 0) {
|
|
@@ -2174,17 +3078,17 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2174
3078
|
connectionAbortController.abort();
|
|
2175
3079
|
}
|
|
2176
3080
|
}
|
|
2177
|
-
|
|
3081
|
+
abortSignal.addEventListener("abort", handleCleanup);
|
|
2178
3082
|
const connectionAbortController = new AbortController();
|
|
2179
3083
|
const subscribeMessage = createJsonRpcMessage(subscribeMethodName, params);
|
|
2180
3084
|
const connection = await rpcConfig.transport({
|
|
2181
3085
|
payload: subscribeMessage,
|
|
2182
3086
|
signal: connectionAbortController.signal
|
|
2183
3087
|
});
|
|
2184
|
-
function
|
|
2185
|
-
|
|
3088
|
+
function handleConnectionCleanup() {
|
|
3089
|
+
abortSignal.removeEventListener("abort", handleCleanup);
|
|
2186
3090
|
}
|
|
2187
|
-
|
|
3091
|
+
registerIterableCleanup(connection, handleConnectionCleanup);
|
|
2188
3092
|
for await (const message of connection) {
|
|
2189
3093
|
if ("id" in message && message.id === subscribeMessage.id) {
|
|
2190
3094
|
if ("error" in message) {
|
|
@@ -2242,7 +3146,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2242
3146
|
function createJsonSubscriptionRpc(rpcConfig) {
|
|
2243
3147
|
return makeProxy2(rpcConfig);
|
|
2244
3148
|
}
|
|
2245
|
-
var
|
|
3149
|
+
var e2 = globalThis.fetch;
|
|
2246
3150
|
var SolanaHttpError = class extends Error {
|
|
2247
3151
|
constructor(details) {
|
|
2248
3152
|
super(`HTTP error (${details.statusCode}): ${details.message}`);
|
|
@@ -2330,7 +3234,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2330
3234
|
method: "POST",
|
|
2331
3235
|
signal
|
|
2332
3236
|
};
|
|
2333
|
-
const response = await
|
|
3237
|
+
const response = await e2(url, requestInfo);
|
|
2334
3238
|
if (!response.ok) {
|
|
2335
3239
|
throw new SolanaHttpError({
|
|
2336
3240
|
message: response.statusText,
|
|
@@ -2340,7 +3244,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2340
3244
|
return await response.json();
|
|
2341
3245
|
};
|
|
2342
3246
|
}
|
|
2343
|
-
var
|
|
3247
|
+
var e22 = globalThis.WebSocket;
|
|
3248
|
+
var EXPLICIT_ABORT_TOKEN = Symbol(
|
|
3249
|
+
"This symbol is thrown from a socket's iterator when the connection is explicity aborted by the user"
|
|
3250
|
+
);
|
|
2344
3251
|
async function createWebSocketConnection({
|
|
2345
3252
|
sendBufferHighWatermark,
|
|
2346
3253
|
signal,
|
|
@@ -2349,8 +3256,19 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2349
3256
|
return new Promise((resolve, reject) => {
|
|
2350
3257
|
signal.addEventListener("abort", handleAbort, { once: true });
|
|
2351
3258
|
const iteratorState = /* @__PURE__ */ new Map();
|
|
3259
|
+
function errorAndClearAllIteratorStates(reason) {
|
|
3260
|
+
const errorCallbacks = [...iteratorState.values()].filter((state) => state.__hasPolled).map(({ onError }) => onError);
|
|
3261
|
+
iteratorState.clear();
|
|
3262
|
+
errorCallbacks.forEach((cb) => {
|
|
3263
|
+
try {
|
|
3264
|
+
cb(reason);
|
|
3265
|
+
} catch {
|
|
3266
|
+
}
|
|
3267
|
+
});
|
|
3268
|
+
}
|
|
2352
3269
|
function handleAbort() {
|
|
2353
|
-
|
|
3270
|
+
errorAndClearAllIteratorStates(EXPLICIT_ABORT_TOKEN);
|
|
3271
|
+
if (webSocket.readyState !== e22.CLOSED && webSocket.readyState !== e22.CLOSING) {
|
|
2354
3272
|
webSocket.close(1e3);
|
|
2355
3273
|
}
|
|
2356
3274
|
}
|
|
@@ -2361,15 +3279,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2361
3279
|
webSocket.removeEventListener("error", handleError);
|
|
2362
3280
|
webSocket.removeEventListener("open", handleOpen);
|
|
2363
3281
|
webSocket.removeEventListener("message", handleMessage);
|
|
2364
|
-
|
|
2365
|
-
if (state.__hasPolled) {
|
|
2366
|
-
const { onError } = state;
|
|
2367
|
-
iteratorState.delete(iteratorKey);
|
|
2368
|
-
onError(ev);
|
|
2369
|
-
} else {
|
|
2370
|
-
iteratorState.delete(iteratorKey);
|
|
2371
|
-
}
|
|
2372
|
-
});
|
|
3282
|
+
errorAndClearAllIteratorStates(ev);
|
|
2373
3283
|
}
|
|
2374
3284
|
function handleError(ev) {
|
|
2375
3285
|
if (!hasConnected) {
|
|
@@ -2386,11 +3296,11 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2386
3296
|
resolve({
|
|
2387
3297
|
async send(payload) {
|
|
2388
3298
|
const message = JSON.stringify(payload);
|
|
2389
|
-
if (!bufferDrainWatcher && webSocket.readyState ===
|
|
3299
|
+
if (!bufferDrainWatcher && webSocket.readyState === e22.OPEN && webSocket.bufferedAmount > sendBufferHighWatermark) {
|
|
2390
3300
|
let onCancel;
|
|
2391
3301
|
const promise = new Promise((resolve2, reject2) => {
|
|
2392
3302
|
const intervalId = setInterval(() => {
|
|
2393
|
-
if (webSocket.readyState !==
|
|
3303
|
+
if (webSocket.readyState !== e22.OPEN || !(webSocket.bufferedAmount > sendBufferHighWatermark)) {
|
|
2394
3304
|
clearInterval(intervalId);
|
|
2395
3305
|
bufferDrainWatcher = void 0;
|
|
2396
3306
|
resolve2();
|
|
@@ -2437,15 +3347,15 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2437
3347
|
yield* queuedMessages;
|
|
2438
3348
|
} else {
|
|
2439
3349
|
try {
|
|
2440
|
-
yield await new Promise((
|
|
3350
|
+
yield await new Promise((resolve2, reject2) => {
|
|
2441
3351
|
iteratorState.set(iteratorKey, {
|
|
2442
3352
|
__hasPolled: true,
|
|
2443
|
-
onError,
|
|
2444
|
-
onMessage
|
|
3353
|
+
onError: reject2,
|
|
3354
|
+
onMessage: resolve2
|
|
2445
3355
|
});
|
|
2446
3356
|
});
|
|
2447
3357
|
} catch (e3) {
|
|
2448
|
-
if (e3
|
|
3358
|
+
if (e3 === EXPLICIT_ABORT_TOKEN) {
|
|
2449
3359
|
return;
|
|
2450
3360
|
} else {
|
|
2451
3361
|
throw new Error("WebSocket connection closed", { cause: e3 });
|
|
@@ -2471,7 +3381,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2471
3381
|
}
|
|
2472
3382
|
});
|
|
2473
3383
|
}
|
|
2474
|
-
const webSocket = new
|
|
3384
|
+
const webSocket = new e22(url);
|
|
2475
3385
|
webSocket.addEventListener("close", handleClose);
|
|
2476
3386
|
webSocket.addEventListener("error", handleError);
|
|
2477
3387
|
webSocket.addEventListener("open", handleOpen);
|
|
@@ -2501,6 +3411,9 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2501
3411
|
};
|
|
2502
3412
|
}
|
|
2503
3413
|
|
|
3414
|
+
// src/rpc.ts
|
|
3415
|
+
var import_fast_stable_stringify = __toESM(require_fast_stable_stringify(), 1);
|
|
3416
|
+
|
|
2504
3417
|
// src/rpc-default-config.ts
|
|
2505
3418
|
init_env_shim();
|
|
2506
3419
|
|
|
@@ -2541,6 +3454,197 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2541
3454
|
}
|
|
2542
3455
|
};
|
|
2543
3456
|
|
|
3457
|
+
// src/rpc-subscription-coalescer.ts
|
|
3458
|
+
init_env_shim();
|
|
3459
|
+
|
|
3460
|
+
// src/cached-abortable-iterable.ts
|
|
3461
|
+
init_env_shim();
|
|
3462
|
+
function registerIterableCleanup2(iterable, cleanupFn) {
|
|
3463
|
+
(async () => {
|
|
3464
|
+
try {
|
|
3465
|
+
for await (const _ of iterable)
|
|
3466
|
+
;
|
|
3467
|
+
} catch {
|
|
3468
|
+
} finally {
|
|
3469
|
+
cleanupFn();
|
|
3470
|
+
}
|
|
3471
|
+
})();
|
|
3472
|
+
}
|
|
3473
|
+
function getCachedAbortableIterableFactory({
|
|
3474
|
+
getAbortSignalFromInputArgs,
|
|
3475
|
+
getCacheEntryMissingError,
|
|
3476
|
+
getCacheKeyFromInputArgs,
|
|
3477
|
+
onCacheHit,
|
|
3478
|
+
onCreateIterable
|
|
3479
|
+
}) {
|
|
3480
|
+
const cache = /* @__PURE__ */ new Map();
|
|
3481
|
+
function getCacheEntryOrThrow(cacheKey) {
|
|
3482
|
+
const currentCacheEntry = cache.get(cacheKey);
|
|
3483
|
+
if (!currentCacheEntry) {
|
|
3484
|
+
throw getCacheEntryMissingError(cacheKey);
|
|
3485
|
+
}
|
|
3486
|
+
return currentCacheEntry;
|
|
3487
|
+
}
|
|
3488
|
+
return async (...args) => {
|
|
3489
|
+
const cacheKey = getCacheKeyFromInputArgs(...args);
|
|
3490
|
+
const signal = getAbortSignalFromInputArgs(...args);
|
|
3491
|
+
if (cacheKey === void 0) {
|
|
3492
|
+
return await onCreateIterable(signal, ...args);
|
|
3493
|
+
}
|
|
3494
|
+
const cleanup = () => {
|
|
3495
|
+
cache.delete(cacheKey);
|
|
3496
|
+
signal.removeEventListener("abort", handleAbort);
|
|
3497
|
+
};
|
|
3498
|
+
const handleAbort = () => {
|
|
3499
|
+
const cacheEntry = getCacheEntryOrThrow(cacheKey);
|
|
3500
|
+
if (cacheEntry.purgeScheduled !== true) {
|
|
3501
|
+
cacheEntry.purgeScheduled = true;
|
|
3502
|
+
globalThis.queueMicrotask(() => {
|
|
3503
|
+
cacheEntry.purgeScheduled = false;
|
|
3504
|
+
if (cacheEntry.referenceCount === 0) {
|
|
3505
|
+
cacheEntry.abortController.abort();
|
|
3506
|
+
cleanup();
|
|
3507
|
+
}
|
|
3508
|
+
});
|
|
3509
|
+
}
|
|
3510
|
+
cacheEntry.referenceCount--;
|
|
3511
|
+
};
|
|
3512
|
+
signal.addEventListener("abort", handleAbort);
|
|
3513
|
+
try {
|
|
3514
|
+
const cacheEntry = cache.get(cacheKey);
|
|
3515
|
+
if (!cacheEntry) {
|
|
3516
|
+
const singletonAbortController = new AbortController();
|
|
3517
|
+
const newIterablePromise = onCreateIterable(singletonAbortController.signal, ...args);
|
|
3518
|
+
const newCacheEntry = {
|
|
3519
|
+
abortController: singletonAbortController,
|
|
3520
|
+
iterable: newIterablePromise,
|
|
3521
|
+
purgeScheduled: false,
|
|
3522
|
+
referenceCount: 1
|
|
3523
|
+
};
|
|
3524
|
+
cache.set(cacheKey, newCacheEntry);
|
|
3525
|
+
const newIterable = await newIterablePromise;
|
|
3526
|
+
registerIterableCleanup2(newIterable, cleanup);
|
|
3527
|
+
newCacheEntry.iterable = newIterable;
|
|
3528
|
+
return newIterable;
|
|
3529
|
+
} else {
|
|
3530
|
+
cacheEntry.referenceCount++;
|
|
3531
|
+
const iterableOrIterablePromise = cacheEntry.iterable;
|
|
3532
|
+
const cachedIterable = "then" in iterableOrIterablePromise ? await iterableOrIterablePromise : iterableOrIterablePromise;
|
|
3533
|
+
await onCacheHit(cachedIterable, ...args);
|
|
3534
|
+
return cachedIterable;
|
|
3535
|
+
}
|
|
3536
|
+
} catch (e3) {
|
|
3537
|
+
cleanup();
|
|
3538
|
+
throw e3;
|
|
3539
|
+
}
|
|
3540
|
+
};
|
|
3541
|
+
}
|
|
3542
|
+
|
|
3543
|
+
// src/rpc-subscription-coalescer.ts
|
|
3544
|
+
var EXPLICIT_ABORT_TOKEN2 = Symbol(
|
|
3545
|
+
"This symbol is thrown from a subscription's iterator when the subscription is explicitly aborted by the user"
|
|
3546
|
+
);
|
|
3547
|
+
function registerIterableCleanup3(iterable, cleanupFn) {
|
|
3548
|
+
(async () => {
|
|
3549
|
+
try {
|
|
3550
|
+
for await (const _ of iterable)
|
|
3551
|
+
;
|
|
3552
|
+
} catch {
|
|
3553
|
+
} finally {
|
|
3554
|
+
cleanupFn();
|
|
3555
|
+
}
|
|
3556
|
+
})();
|
|
3557
|
+
}
|
|
3558
|
+
function getRpcSubscriptionsWithSubscriptionCoalescing({
|
|
3559
|
+
getDeduplicationKey,
|
|
3560
|
+
rpcSubscriptions
|
|
3561
|
+
}) {
|
|
3562
|
+
const cache = /* @__PURE__ */ new Map();
|
|
3563
|
+
return new Proxy(rpcSubscriptions, {
|
|
3564
|
+
defineProperty() {
|
|
3565
|
+
return false;
|
|
3566
|
+
},
|
|
3567
|
+
deleteProperty() {
|
|
3568
|
+
return false;
|
|
3569
|
+
},
|
|
3570
|
+
get(target, p, receiver) {
|
|
3571
|
+
const subscriptionMethod = Reflect.get(target, p, receiver);
|
|
3572
|
+
if (typeof subscriptionMethod !== "function") {
|
|
3573
|
+
return subscriptionMethod;
|
|
3574
|
+
}
|
|
3575
|
+
return function(...rawParams) {
|
|
3576
|
+
const deduplicationKey = getDeduplicationKey(p, rawParams);
|
|
3577
|
+
if (deduplicationKey === void 0) {
|
|
3578
|
+
return subscriptionMethod(...rawParams);
|
|
3579
|
+
}
|
|
3580
|
+
if (cache.has(deduplicationKey)) {
|
|
3581
|
+
return cache.get(deduplicationKey);
|
|
3582
|
+
}
|
|
3583
|
+
const iterableFactory = getCachedAbortableIterableFactory({
|
|
3584
|
+
getAbortSignalFromInputArgs: ({ abortSignal }) => abortSignal,
|
|
3585
|
+
getCacheEntryMissingError(deduplicationKey2) {
|
|
3586
|
+
return new Error(
|
|
3587
|
+
`Found no cache entry for subscription with deduplication key \`${deduplicationKey2?.toString()}\``
|
|
3588
|
+
);
|
|
3589
|
+
},
|
|
3590
|
+
getCacheKeyFromInputArgs: () => deduplicationKey,
|
|
3591
|
+
async onCacheHit(_iterable, _config) {
|
|
3592
|
+
},
|
|
3593
|
+
async onCreateIterable(abortSignal, config) {
|
|
3594
|
+
const pendingSubscription2 = subscriptionMethod(
|
|
3595
|
+
...rawParams
|
|
3596
|
+
);
|
|
3597
|
+
const iterable = await pendingSubscription2.subscribe({
|
|
3598
|
+
...config,
|
|
3599
|
+
abortSignal
|
|
3600
|
+
});
|
|
3601
|
+
registerIterableCleanup3(iterable, () => {
|
|
3602
|
+
cache.delete(deduplicationKey);
|
|
3603
|
+
});
|
|
3604
|
+
return iterable;
|
|
3605
|
+
}
|
|
3606
|
+
});
|
|
3607
|
+
const pendingSubscription = {
|
|
3608
|
+
async subscribe(...args) {
|
|
3609
|
+
const iterable = await iterableFactory(...args);
|
|
3610
|
+
const { abortSignal } = args[0];
|
|
3611
|
+
let abortPromise;
|
|
3612
|
+
return {
|
|
3613
|
+
...iterable,
|
|
3614
|
+
async *[Symbol.asyncIterator]() {
|
|
3615
|
+
abortPromise || (abortPromise = abortSignal.aborted ? Promise.reject(EXPLICIT_ABORT_TOKEN2) : new Promise((_, reject) => {
|
|
3616
|
+
abortSignal.addEventListener("abort", () => {
|
|
3617
|
+
reject(EXPLICIT_ABORT_TOKEN2);
|
|
3618
|
+
});
|
|
3619
|
+
}));
|
|
3620
|
+
try {
|
|
3621
|
+
const iterator = iterable[Symbol.asyncIterator]();
|
|
3622
|
+
while (true) {
|
|
3623
|
+
const iteratorResult = await Promise.race([iterator.next(), abortPromise]);
|
|
3624
|
+
if (iteratorResult.done) {
|
|
3625
|
+
return;
|
|
3626
|
+
} else {
|
|
3627
|
+
yield iteratorResult.value;
|
|
3628
|
+
}
|
|
3629
|
+
}
|
|
3630
|
+
} catch (e3) {
|
|
3631
|
+
if (e3 === EXPLICIT_ABORT_TOKEN2) {
|
|
3632
|
+
return;
|
|
3633
|
+
}
|
|
3634
|
+
cache.delete(deduplicationKey);
|
|
3635
|
+
throw e3;
|
|
3636
|
+
}
|
|
3637
|
+
}
|
|
3638
|
+
};
|
|
3639
|
+
}
|
|
3640
|
+
};
|
|
3641
|
+
cache.set(deduplicationKey, pendingSubscription);
|
|
3642
|
+
return pendingSubscription;
|
|
3643
|
+
};
|
|
3644
|
+
}
|
|
3645
|
+
});
|
|
3646
|
+
}
|
|
3647
|
+
|
|
2544
3648
|
// src/rpc.ts
|
|
2545
3649
|
function createSolanaRpc(config) {
|
|
2546
3650
|
return createJsonRpc({
|
|
@@ -2549,9 +3653,21 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2549
3653
|
});
|
|
2550
3654
|
}
|
|
2551
3655
|
function createSolanaRpcSubscriptions(config) {
|
|
3656
|
+
return pipe(
|
|
3657
|
+
createJsonSubscriptionRpc({
|
|
3658
|
+
...config,
|
|
3659
|
+
api: createSolanaRpcSubscriptionsApi(DEFAULT_RPC_CONFIG)
|
|
3660
|
+
}),
|
|
3661
|
+
(rpcSubscriptions) => getRpcSubscriptionsWithSubscriptionCoalescing({
|
|
3662
|
+
getDeduplicationKey: (...args) => (0, import_fast_stable_stringify.default)(args),
|
|
3663
|
+
rpcSubscriptions
|
|
3664
|
+
})
|
|
3665
|
+
);
|
|
3666
|
+
}
|
|
3667
|
+
function createSolanaRpcSubscriptions_UNSTABLE(config) {
|
|
2552
3668
|
return createJsonSubscriptionRpc({
|
|
2553
3669
|
...config,
|
|
2554
|
-
api:
|
|
3670
|
+
api: createSolanaRpcSubscriptionsApi_UNSTABLE(DEFAULT_RPC_CONFIG)
|
|
2555
3671
|
});
|
|
2556
3672
|
}
|
|
2557
3673
|
|
|
@@ -2613,14 +3729,15 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2613
3729
|
|
|
2614
3730
|
// src/rpc-request-deduplication.ts
|
|
2615
3731
|
init_env_shim();
|
|
2616
|
-
var
|
|
2617
|
-
function
|
|
3732
|
+
var import_fast_stable_stringify2 = __toESM(require_fast_stable_stringify(), 1);
|
|
3733
|
+
function isJsonRpcPayload(payload) {
|
|
2618
3734
|
if (payload == null || typeof payload !== "object" || Array.isArray(payload)) {
|
|
2619
|
-
return;
|
|
2620
|
-
}
|
|
2621
|
-
if ("jsonrpc" in payload && payload.jsonrpc === "2.0" && "method" in payload && "params" in payload) {
|
|
2622
|
-
return (0, import_fast_stable_stringify.default)([payload.method, payload.params]);
|
|
3735
|
+
return false;
|
|
2623
3736
|
}
|
|
3737
|
+
return "jsonrpc" in payload && payload.jsonrpc === "2.0" && "method" in payload && typeof payload.method === "string" && "params" in payload;
|
|
3738
|
+
}
|
|
3739
|
+
function getSolanaRpcPayloadDeduplicationKey(payload) {
|
|
3740
|
+
return isJsonRpcPayload(payload) ? (0, import_fast_stable_stringify2.default)([payload.method, payload.params]) : void 0;
|
|
2624
3741
|
}
|
|
2625
3742
|
|
|
2626
3743
|
// src/rpc-transport.ts
|
|
@@ -2632,7 +3749,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2632
3749
|
return out;
|
|
2633
3750
|
}
|
|
2634
3751
|
function createDefaultRpcTransport(config) {
|
|
2635
|
-
return
|
|
3752
|
+
return pipe(
|
|
2636
3753
|
createHttpTransport({
|
|
2637
3754
|
...config,
|
|
2638
3755
|
headers: {
|
|
@@ -2643,7 +3760,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2643
3760
|
}
|
|
2644
3761
|
}
|
|
2645
3762
|
}),
|
|
2646
|
-
getSolanaRpcPayloadDeduplicationKey
|
|
3763
|
+
(transport) => getRpcTransportWithRequestCoalescing(transport, getSolanaRpcPayloadDeduplicationKey)
|
|
2647
3764
|
);
|
|
2648
3765
|
}
|
|
2649
3766
|
|
|
@@ -2661,11 +3778,12 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2661
3778
|
return async (...args) => {
|
|
2662
3779
|
const connection = await transport(...args);
|
|
2663
3780
|
let intervalId;
|
|
3781
|
+
function sendPing() {
|
|
3782
|
+
connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(PING_PAYLOAD);
|
|
3783
|
+
}
|
|
2664
3784
|
function restartPingTimer() {
|
|
2665
3785
|
clearInterval(intervalId);
|
|
2666
|
-
intervalId = setInterval(
|
|
2667
|
-
connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(PING_PAYLOAD);
|
|
2668
|
-
}, intervalMs);
|
|
3786
|
+
intervalId = setInterval(sendPing, intervalMs);
|
|
2669
3787
|
}
|
|
2670
3788
|
if (pingableConnections.has(connection) === false) {
|
|
2671
3789
|
pingableConnections.set(connection, {
|
|
@@ -2684,58 +3802,283 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2684
3802
|
} finally {
|
|
2685
3803
|
pingableConnections.delete(connection);
|
|
2686
3804
|
clearInterval(intervalId);
|
|
3805
|
+
if (handleOffline) {
|
|
3806
|
+
globalThis.window.removeEventListener("offline", handleOffline);
|
|
3807
|
+
}
|
|
3808
|
+
if (handleOnline) {
|
|
3809
|
+
globalThis.window.removeEventListener("online", handleOnline);
|
|
3810
|
+
}
|
|
2687
3811
|
}
|
|
2688
3812
|
})();
|
|
2689
|
-
|
|
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);
|
|
3828
|
+
}
|
|
2690
3829
|
}
|
|
2691
3830
|
return pingableConnections.get(connection);
|
|
2692
3831
|
};
|
|
2693
3832
|
}
|
|
2694
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?.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
|
+
|
|
2695
3854
|
// src/rpc-websocket-transport.ts
|
|
2696
3855
|
function createDefaultRpcSubscriptionsTransport(config) {
|
|
2697
|
-
const { intervalMs, ...rest } = config;
|
|
2698
|
-
return
|
|
2699
|
-
|
|
2700
|
-
transport: createWebSocketTransport({
|
|
3856
|
+
const { getShard, intervalMs, ...rest } = config;
|
|
3857
|
+
return pipe(
|
|
3858
|
+
createWebSocketTransport({
|
|
2701
3859
|
...rest,
|
|
2702
3860
|
sendBufferHighWatermark: config.sendBufferHighWatermark ?? // Let 128KB of data into the WebSocket buffer before buffering it in the app.
|
|
2703
3861
|
131072
|
|
3862
|
+
}),
|
|
3863
|
+
(transport) => getWebSocketTransportWithAutoping({
|
|
3864
|
+
intervalMs: intervalMs ?? 5e3,
|
|
3865
|
+
transport
|
|
3866
|
+
}),
|
|
3867
|
+
(transport) => getWebSocketTransportWithConnectionSharding({
|
|
3868
|
+
getShard,
|
|
3869
|
+
transport
|
|
2704
3870
|
})
|
|
2705
|
-
|
|
3871
|
+
);
|
|
3872
|
+
}
|
|
3873
|
+
|
|
3874
|
+
// src/transaction-confirmation.ts
|
|
3875
|
+
init_env_shim();
|
|
3876
|
+
|
|
3877
|
+
// src/transaction-confirmation-strategy-blockheight.ts
|
|
3878
|
+
init_env_shim();
|
|
3879
|
+
function createBlockHeightExceedencePromiseFactory(rpcSubscriptions) {
|
|
3880
|
+
return async function getBlockHeightExceedencePromise({ abortSignal: callerAbortSignal, lastValidBlockHeight }) {
|
|
3881
|
+
const abortController = new AbortController();
|
|
3882
|
+
function handleAbort() {
|
|
3883
|
+
abortController.abort();
|
|
3884
|
+
}
|
|
3885
|
+
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
3886
|
+
const slotNotifications = await rpcSubscriptions.slotNotifications().subscribe({ abortSignal: abortController.signal });
|
|
3887
|
+
try {
|
|
3888
|
+
for await (const slotNotification of slotNotifications) {
|
|
3889
|
+
if (slotNotification.slot > lastValidBlockHeight) {
|
|
3890
|
+
throw new Error(
|
|
3891
|
+
"The network has progressed past the last block for which this transaction could have committed."
|
|
3892
|
+
);
|
|
3893
|
+
}
|
|
3894
|
+
}
|
|
3895
|
+
} finally {
|
|
3896
|
+
abortController.abort();
|
|
3897
|
+
}
|
|
3898
|
+
};
|
|
3899
|
+
}
|
|
3900
|
+
|
|
3901
|
+
// src/transaction-confirmation-strategy-nonce.ts
|
|
3902
|
+
init_env_shim();
|
|
3903
|
+
var NONCE_VALUE_OFFSET = 4 + // version(u32)
|
|
3904
|
+
4 + // state(u32)
|
|
3905
|
+
32;
|
|
3906
|
+
function createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions) {
|
|
3907
|
+
return async function getNonceInvalidationPromise({
|
|
3908
|
+
abortSignal: callerAbortSignal,
|
|
3909
|
+
commitment,
|
|
3910
|
+
currentNonceValue,
|
|
3911
|
+
nonceAccountAddress
|
|
3912
|
+
}) {
|
|
3913
|
+
const abortController = new AbortController();
|
|
3914
|
+
function handleAbort() {
|
|
3915
|
+
abortController.abort();
|
|
3916
|
+
}
|
|
3917
|
+
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
3918
|
+
const accountNotifications = await rpcSubscriptions.accountNotifications(nonceAccountAddress, { commitment, encoding: "base64" }).subscribe({ abortSignal: abortController.signal });
|
|
3919
|
+
function getNonceFromAccountData([base64EncodedBytes]) {
|
|
3920
|
+
const data = base64.serialize(base64EncodedBytes);
|
|
3921
|
+
const nonceValueBytes = data.slice(NONCE_VALUE_OFFSET, NONCE_VALUE_OFFSET + 32);
|
|
3922
|
+
return base58.deserialize(nonceValueBytes)[0];
|
|
3923
|
+
}
|
|
3924
|
+
const nonceAccountDidAdvancePromise = (async () => {
|
|
3925
|
+
for await (const accountNotification of accountNotifications) {
|
|
3926
|
+
const nonceValue = getNonceFromAccountData(accountNotification.value.data);
|
|
3927
|
+
if (nonceValue !== currentNonceValue) {
|
|
3928
|
+
throw new Error(
|
|
3929
|
+
`The nonce \`${currentNonceValue}\` is no longer valid. It has advanced to \`${nonceValue}\`.`
|
|
3930
|
+
);
|
|
3931
|
+
}
|
|
3932
|
+
}
|
|
3933
|
+
})();
|
|
3934
|
+
const nonceIsAlreadyInvalidPromise = (async () => {
|
|
3935
|
+
const { value: nonceAccount } = await rpc.getAccountInfo(nonceAccountAddress, {
|
|
3936
|
+
commitment,
|
|
3937
|
+
dataSlice: { length: 32, offset: NONCE_VALUE_OFFSET },
|
|
3938
|
+
encoding: "base58"
|
|
3939
|
+
}).send({ abortSignal: abortController.signal });
|
|
3940
|
+
if (!nonceAccount) {
|
|
3941
|
+
throw new Error(`No nonce account could be found at address \`${nonceAccountAddress}\`.`);
|
|
3942
|
+
}
|
|
3943
|
+
const nonceValue = (
|
|
3944
|
+
// This works because we asked for the exact slice of data representing the nonce
|
|
3945
|
+
// value, and furthermore asked for it in `base58` encoding.
|
|
3946
|
+
nonceAccount.data[0]
|
|
3947
|
+
);
|
|
3948
|
+
if (nonceValue !== currentNonceValue) {
|
|
3949
|
+
throw new Error(
|
|
3950
|
+
`The nonce \`${currentNonceValue}\` is no longer valid. It has advanced to \`${nonceValue}\`.`
|
|
3951
|
+
);
|
|
3952
|
+
} else {
|
|
3953
|
+
await new Promise(() => {
|
|
3954
|
+
});
|
|
3955
|
+
}
|
|
3956
|
+
})();
|
|
3957
|
+
try {
|
|
3958
|
+
return await Promise.race([nonceAccountDidAdvancePromise, nonceIsAlreadyInvalidPromise]);
|
|
3959
|
+
} finally {
|
|
3960
|
+
abortController.abort();
|
|
3961
|
+
}
|
|
3962
|
+
};
|
|
3963
|
+
}
|
|
3964
|
+
|
|
3965
|
+
// src/transaction-confirmation.ts
|
|
3966
|
+
function createDefaultDurableNonceTransactionConfirmer({
|
|
3967
|
+
rpc,
|
|
3968
|
+
rpcSubscriptions
|
|
3969
|
+
}) {
|
|
3970
|
+
const getNonceInvalidationPromise = createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions);
|
|
3971
|
+
const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
|
|
3972
|
+
rpc,
|
|
3973
|
+
rpcSubscriptions
|
|
3974
|
+
);
|
|
3975
|
+
return async function confirmDurableNonceTransaction(config) {
|
|
3976
|
+
await waitForDurableNonceTransactionConfirmation({
|
|
3977
|
+
...config,
|
|
3978
|
+
getNonceInvalidationPromise,
|
|
3979
|
+
getRecentSignatureConfirmationPromise
|
|
3980
|
+
});
|
|
3981
|
+
};
|
|
3982
|
+
}
|
|
3983
|
+
function createDefaultRecentTransactionConfirmer({
|
|
3984
|
+
rpc,
|
|
3985
|
+
rpcSubscriptions
|
|
3986
|
+
}) {
|
|
3987
|
+
const getBlockHeightExceedencePromise = createBlockHeightExceedencePromiseFactory(rpcSubscriptions);
|
|
3988
|
+
const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
|
|
3989
|
+
rpc,
|
|
3990
|
+
rpcSubscriptions
|
|
3991
|
+
);
|
|
3992
|
+
return async function confirmRecentTransaction(config) {
|
|
3993
|
+
await waitForRecentTransactionConfirmation({
|
|
3994
|
+
...config,
|
|
3995
|
+
getBlockHeightExceedencePromise,
|
|
3996
|
+
getRecentSignatureConfirmationPromise
|
|
3997
|
+
});
|
|
3998
|
+
};
|
|
3999
|
+
}
|
|
4000
|
+
async function waitForDurableNonceTransactionConfirmation(config) {
|
|
4001
|
+
await raceStrategies(
|
|
4002
|
+
getSignatureFromTransaction(config.transaction),
|
|
4003
|
+
config,
|
|
4004
|
+
function getSpecificStrategiesForRace({ abortSignal, commitment, getNonceInvalidationPromise, transaction }) {
|
|
4005
|
+
return [
|
|
4006
|
+
getNonceInvalidationPromise({
|
|
4007
|
+
abortSignal,
|
|
4008
|
+
commitment,
|
|
4009
|
+
currentNonceValue: transaction.lifetimeConstraint.nonce,
|
|
4010
|
+
nonceAccountAddress: transaction.instructions[0].accounts[0].address
|
|
4011
|
+
})
|
|
4012
|
+
];
|
|
4013
|
+
}
|
|
4014
|
+
);
|
|
4015
|
+
}
|
|
4016
|
+
async function waitForRecentTransactionConfirmation(config) {
|
|
4017
|
+
await raceStrategies(
|
|
4018
|
+
getSignatureFromTransaction(config.transaction),
|
|
4019
|
+
config,
|
|
4020
|
+
function getSpecificStrategiesForRace({ abortSignal, getBlockHeightExceedencePromise, transaction }) {
|
|
4021
|
+
return [
|
|
4022
|
+
getBlockHeightExceedencePromise({
|
|
4023
|
+
abortSignal,
|
|
4024
|
+
lastValidBlockHeight: transaction.lifetimeConstraint.lastValidBlockHeight
|
|
4025
|
+
})
|
|
4026
|
+
];
|
|
4027
|
+
}
|
|
4028
|
+
);
|
|
2706
4029
|
}
|
|
2707
4030
|
|
|
2708
4031
|
exports.AccountRole = AccountRole;
|
|
4032
|
+
exports.address = address;
|
|
2709
4033
|
exports.appendTransactionInstruction = appendTransactionInstruction;
|
|
2710
|
-
exports.
|
|
4034
|
+
exports.assertIsAddress = assertIsAddress;
|
|
2711
4035
|
exports.assertIsBlockhash = assertIsBlockhash;
|
|
2712
4036
|
exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
|
|
4037
|
+
exports.assertIsProgramDerivedAddress = assertIsProgramDerivedAddress;
|
|
4038
|
+
exports.assertIsTransactionSignature = assertIsTransactionSignature;
|
|
2713
4039
|
exports.createAddressWithSeed = createAddressWithSeed;
|
|
4040
|
+
exports.createBlockHeightExceedencePromiseFactory = createBlockHeightExceedencePromiseFactory;
|
|
4041
|
+
exports.createDefaultDurableNonceTransactionConfirmer = createDefaultDurableNonceTransactionConfirmer;
|
|
4042
|
+
exports.createDefaultRecentTransactionConfirmer = createDefaultRecentTransactionConfirmer;
|
|
2714
4043
|
exports.createDefaultRpcSubscriptionsTransport = createDefaultRpcSubscriptionsTransport;
|
|
2715
4044
|
exports.createDefaultRpcTransport = createDefaultRpcTransport;
|
|
4045
|
+
exports.createNonceInvalidationPromiseFactory = createNonceInvalidationPromiseFactory;
|
|
4046
|
+
exports.createRecentSignatureConfirmationPromiseFactory = createRecentSignatureConfirmationPromiseFactory;
|
|
2716
4047
|
exports.createSolanaRpc = createSolanaRpc;
|
|
2717
4048
|
exports.createSolanaRpcSubscriptions = createSolanaRpcSubscriptions;
|
|
4049
|
+
exports.createSolanaRpcSubscriptions_UNSTABLE = createSolanaRpcSubscriptions_UNSTABLE;
|
|
2718
4050
|
exports.createTransaction = createTransaction;
|
|
2719
4051
|
exports.downgradeRoleToNonSigner = downgradeRoleToNonSigner;
|
|
2720
4052
|
exports.downgradeRoleToReadonly = downgradeRoleToReadonly;
|
|
2721
4053
|
exports.generateKeyPair = generateKeyPair;
|
|
4054
|
+
exports.getAddressCodec = getAddressCodec;
|
|
4055
|
+
exports.getAddressComparator = getAddressComparator;
|
|
4056
|
+
exports.getAddressDecoder = getAddressDecoder;
|
|
4057
|
+
exports.getAddressEncoder = getAddressEncoder;
|
|
2722
4058
|
exports.getAddressFromPublicKey = getAddressFromPublicKey;
|
|
2723
|
-
exports.getBase58EncodedAddressCodec = getBase58EncodedAddressCodec;
|
|
2724
|
-
exports.getBase58EncodedAddressComparator = getBase58EncodedAddressComparator;
|
|
2725
4059
|
exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
|
|
2726
4060
|
exports.getProgramDerivedAddress = getProgramDerivedAddress;
|
|
4061
|
+
exports.getSignatureFromTransaction = getSignatureFromTransaction;
|
|
4062
|
+
exports.getTransactionEncoder = getTransactionEncoder;
|
|
4063
|
+
exports.isAddress = isAddress;
|
|
4064
|
+
exports.isProgramDerivedAddress = isProgramDerivedAddress;
|
|
2727
4065
|
exports.isSignerRole = isSignerRole;
|
|
4066
|
+
exports.isTransactionSignature = isTransactionSignature;
|
|
2728
4067
|
exports.isWritableRole = isWritableRole;
|
|
2729
4068
|
exports.mergeRoles = mergeRoles;
|
|
2730
4069
|
exports.prependTransactionInstruction = prependTransactionInstruction;
|
|
4070
|
+
exports.requestAndConfirmAirdrop = requestAndConfirmAirdrop;
|
|
2731
4071
|
exports.setTransactionFeePayer = setTransactionFeePayer;
|
|
2732
4072
|
exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
|
|
2733
4073
|
exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
|
|
2734
4074
|
exports.signBytes = signBytes;
|
|
2735
4075
|
exports.signTransaction = signTransaction;
|
|
4076
|
+
exports.transactionSignature = transactionSignature;
|
|
2736
4077
|
exports.upgradeRoleToSigner = upgradeRoleToSigner;
|
|
2737
4078
|
exports.upgradeRoleToWritable = upgradeRoleToWritable;
|
|
2738
4079
|
exports.verifySignature = verifySignature;
|
|
4080
|
+
exports.waitForDurableNonceTransactionConfirmation = waitForDurableNonceTransactionConfirmation;
|
|
4081
|
+
exports.waitForRecentTransactionConfirmation = waitForRecentTransactionConfirmation;
|
|
2739
4082
|
|
|
2740
4083
|
return exports;
|
|
2741
4084
|
|