@solana/web3.js 2.0.0-experimental.bd21cc5 → 2.0.0-experimental.be3a154
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/README.md +4 -4
- package/dist/index.browser.cjs +1 -1
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +3 -1
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +538 -632
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +1 -1
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +1 -1
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +1 -1
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +82 -80
- package/dist/types/airdrop-confirmer.d.ts +4 -5
- package/dist/types/airdrop-confirmer.d.ts.map +1 -0
- package/dist/types/airdrop.d.ts +3 -5
- package/dist/types/airdrop.d.ts.map +1 -0
- package/dist/types/cached-abortable-iterable.d.ts.map +1 -0
- package/dist/types/index.d.ts +9 -9
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/rpc-default-config.d.ts.map +1 -0
- package/dist/types/rpc-integer-overflow-error.d.ts.map +1 -0
- package/dist/types/rpc-request-coalescer.d.ts +1 -1
- package/dist/types/rpc-request-coalescer.d.ts.map +1 -0
- package/dist/types/rpc-request-deduplication.d.ts.map +1 -0
- package/dist/types/rpc-subscription-coalescer.d.ts +1 -1
- package/dist/types/rpc-subscription-coalescer.d.ts.map +1 -0
- package/dist/types/rpc-transport.d.ts +1 -2
- package/dist/types/rpc-transport.d.ts.map +1 -0
- package/dist/types/rpc-websocket-autopinger.d.ts +1 -1
- package/dist/types/rpc-websocket-autopinger.d.ts.map +1 -0
- package/dist/types/rpc-websocket-connection-sharding.d.ts +1 -1
- package/dist/types/rpc-websocket-connection-sharding.d.ts.map +1 -0
- package/dist/types/rpc-websocket-transport.d.ts +1 -2
- package/dist/types/rpc-websocket-transport.d.ts.map +1 -0
- package/dist/types/rpc.d.ts +1 -2
- package/dist/types/rpc.d.ts.map +1 -0
- package/dist/types/send-transaction.d.ts +3 -3
- package/dist/types/send-transaction.d.ts.map +1 -0
- package/dist/types/transaction-confirmation-strategy-blockheight.d.ts +2 -3
- package/dist/types/transaction-confirmation-strategy-blockheight.d.ts.map +1 -0
- package/dist/types/transaction-confirmation-strategy-nonce.d.ts +2 -3
- package/dist/types/transaction-confirmation-strategy-nonce.d.ts.map +1 -0
- package/dist/types/transaction-confirmation-strategy-racer.d.ts +1 -1
- package/dist/types/transaction-confirmation-strategy-racer.d.ts.map +1 -0
- package/dist/types/transaction-confirmation-strategy-recent-signature.d.ts +2 -3
- package/dist/types/transaction-confirmation-strategy-recent-signature.d.ts.map +1 -0
- package/dist/types/transaction-confirmation-strategy-timeout.d.ts.map +1 -0
- package/dist/types/transaction-confirmation.d.ts +5 -10
- package/dist/types/transaction-confirmation.d.ts.map +1 -0
- package/package.json +13 -13
|
@@ -138,23 +138,6 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
138
138
|
throw new Error(`Codec [${codecDescription}] expected ${expected} bytes, got ${bytesLength}.`);
|
|
139
139
|
}
|
|
140
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);
|
|
150
|
-
const result = new Uint8Array(totalLength);
|
|
151
|
-
let offset = 0;
|
|
152
|
-
nonEmptyByteArrays.forEach((arr) => {
|
|
153
|
-
result.set(arr, offset);
|
|
154
|
-
offset += arr.length;
|
|
155
|
-
});
|
|
156
|
-
return result;
|
|
157
|
-
};
|
|
158
141
|
var padBytes = (bytes, length) => {
|
|
159
142
|
if (bytes.length >= length)
|
|
160
143
|
return bytes;
|
|
@@ -163,77 +146,100 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
163
146
|
return paddedBytes;
|
|
164
147
|
};
|
|
165
148
|
var fixBytes = (bytes, length) => padBytes(bytes.length <= length ? bytes : bytes.slice(0, length), length);
|
|
166
|
-
function
|
|
167
|
-
|
|
149
|
+
function getEncodedSize(value, encoder) {
|
|
150
|
+
return "fixedSize" in encoder ? encoder.fixedSize : encoder.getSizeFromValue(value);
|
|
151
|
+
}
|
|
152
|
+
function createEncoder(encoder) {
|
|
153
|
+
return Object.freeze({
|
|
154
|
+
...encoder,
|
|
155
|
+
encode: (value) => {
|
|
156
|
+
const bytes = new Uint8Array(getEncodedSize(value, encoder));
|
|
157
|
+
encoder.write(value, bytes, 0);
|
|
158
|
+
return bytes;
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
function createDecoder(decoder) {
|
|
163
|
+
return Object.freeze({
|
|
164
|
+
...decoder,
|
|
165
|
+
decode: (bytes, offset = 0) => decoder.read(bytes, offset)[0]
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
function isFixedSize(codec) {
|
|
169
|
+
return "fixedSize" in codec && typeof codec.fixedSize === "number";
|
|
170
|
+
}
|
|
171
|
+
function assertIsFixedSize(codec, message) {
|
|
172
|
+
if (!isFixedSize(codec)) {
|
|
173
|
+
throw new Error(message != null ? message : "Expected a fixed-size codec, got a variable-size one.");
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
function isVariableSize(codec) {
|
|
177
|
+
return !isFixedSize(codec);
|
|
178
|
+
}
|
|
179
|
+
function combineCodec(encoder, decoder) {
|
|
180
|
+
if (isFixedSize(encoder) !== isFixedSize(decoder)) {
|
|
181
|
+
throw new Error(`Encoder and decoder must either both be fixed-size or variable-size.`);
|
|
182
|
+
}
|
|
183
|
+
if (isFixedSize(encoder) && isFixedSize(decoder) && encoder.fixedSize !== decoder.fixedSize) {
|
|
168
184
|
throw new Error(
|
|
169
185
|
`Encoder and decoder must have the same fixed size, got [${encoder.fixedSize}] and [${decoder.fixedSize}].`
|
|
170
186
|
);
|
|
171
187
|
}
|
|
172
|
-
if (encoder.maxSize !== decoder.maxSize) {
|
|
188
|
+
if (!isFixedSize(encoder) && !isFixedSize(decoder) && encoder.maxSize !== decoder.maxSize) {
|
|
173
189
|
throw new Error(
|
|
174
190
|
`Encoder and decoder must have the same max size, got [${encoder.maxSize}] and [${decoder.maxSize}].`
|
|
175
191
|
);
|
|
176
192
|
}
|
|
177
|
-
if (description === void 0 && encoder.description !== decoder.description) {
|
|
178
|
-
throw new Error(
|
|
179
|
-
`Encoder and decoder must have the same description, got [${encoder.description}] and [${decoder.description}]. Pass a custom description as a third argument if you want to override the description and bypass this error.`
|
|
180
|
-
);
|
|
181
|
-
}
|
|
182
193
|
return {
|
|
194
|
+
...decoder,
|
|
195
|
+
...encoder,
|
|
183
196
|
decode: decoder.decode,
|
|
184
|
-
description: description != null ? description : encoder.description,
|
|
185
197
|
encode: encoder.encode,
|
|
186
|
-
|
|
187
|
-
|
|
198
|
+
read: decoder.read,
|
|
199
|
+
write: encoder.write
|
|
188
200
|
};
|
|
189
201
|
}
|
|
190
|
-
function
|
|
191
|
-
return {
|
|
192
|
-
description: description != null ? description : `fixed(${fixedBytes}, ${data.description})`,
|
|
202
|
+
function fixEncoder(encoder, fixedBytes) {
|
|
203
|
+
return createEncoder({
|
|
193
204
|
fixedSize: fixedBytes,
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
};
|
|
205
|
+
write: (value, bytes, offset) => {
|
|
206
|
+
const variableByteArray = encoder.encode(value);
|
|
207
|
+
const fixedByteArray = variableByteArray.length > fixedBytes ? variableByteArray.slice(0, fixedBytes) : variableByteArray;
|
|
208
|
+
bytes.set(fixedByteArray, offset);
|
|
209
|
+
return offset + fixedBytes;
|
|
210
|
+
}
|
|
211
|
+
});
|
|
202
212
|
}
|
|
203
|
-
function fixDecoder(decoder, fixedBytes
|
|
204
|
-
return {
|
|
205
|
-
|
|
206
|
-
|
|
213
|
+
function fixDecoder(decoder, fixedBytes) {
|
|
214
|
+
return createDecoder({
|
|
215
|
+
fixedSize: fixedBytes,
|
|
216
|
+
read: (bytes, offset) => {
|
|
207
217
|
assertByteArrayHasEnoughBytesForCodec("fixCodec", fixedBytes, bytes, offset);
|
|
208
218
|
if (offset > 0 || bytes.length > fixedBytes) {
|
|
209
219
|
bytes = bytes.slice(offset, offset + fixedBytes);
|
|
210
220
|
}
|
|
211
|
-
if (decoder
|
|
221
|
+
if (isFixedSize(decoder)) {
|
|
212
222
|
bytes = fixBytes(bytes, decoder.fixedSize);
|
|
213
223
|
}
|
|
214
|
-
const [value] = decoder.
|
|
224
|
+
const [value] = decoder.read(bytes, 0);
|
|
215
225
|
return [value, offset + fixedBytes];
|
|
216
226
|
}
|
|
217
|
-
};
|
|
227
|
+
});
|
|
218
228
|
}
|
|
219
229
|
function mapEncoder(encoder, unmap) {
|
|
220
|
-
return {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
maxSize: encoder.maxSize
|
|
225
|
-
};
|
|
230
|
+
return createEncoder({
|
|
231
|
+
...isVariableSize(encoder) ? { ...encoder, getSizeFromValue: (value) => encoder.getSizeFromValue(unmap(value)) } : encoder,
|
|
232
|
+
write: (value, bytes, offset) => encoder.write(unmap(value), bytes, offset)
|
|
233
|
+
});
|
|
226
234
|
}
|
|
227
235
|
function mapDecoder(decoder, map) {
|
|
228
|
-
return {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
maxSize: decoder.maxSize
|
|
236
|
-
};
|
|
236
|
+
return createDecoder({
|
|
237
|
+
...decoder,
|
|
238
|
+
read: (bytes, offset) => {
|
|
239
|
+
const [value, newOffset] = decoder.read(bytes, offset);
|
|
240
|
+
return [map(value, bytes, offset), newOffset];
|
|
241
|
+
}
|
|
242
|
+
});
|
|
237
243
|
}
|
|
238
244
|
|
|
239
245
|
// ../codecs-strings/dist/index.browser.js
|
|
@@ -248,102 +254,83 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
248
254
|
);
|
|
249
255
|
}
|
|
250
256
|
}
|
|
251
|
-
function
|
|
252
|
-
|
|
253
|
-
let littleEndian;
|
|
254
|
-
let defaultDescription = input.name;
|
|
255
|
-
if (input.size > 1) {
|
|
256
|
-
littleEndian = !("endian" in input.config) || input.config.endian === 0;
|
|
257
|
-
defaultDescription += littleEndian ? "(le)" : "(be)";
|
|
258
|
-
}
|
|
259
|
-
return {
|
|
260
|
-
description: (_a = input.config.description) != null ? _a : defaultDescription,
|
|
261
|
-
fixedSize: input.size,
|
|
262
|
-
littleEndian,
|
|
263
|
-
maxSize: input.size
|
|
264
|
-
};
|
|
257
|
+
function isLittleEndian(config) {
|
|
258
|
+
return (config == null ? void 0 : config.endian) === 1 ? false : true;
|
|
265
259
|
}
|
|
266
260
|
function numberEncoderFactory(input) {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
encode(value) {
|
|
261
|
+
return createEncoder({
|
|
262
|
+
fixedSize: input.size,
|
|
263
|
+
write(value, bytes, offset) {
|
|
271
264
|
if (input.range) {
|
|
272
265
|
assertNumberIsBetweenForCodec(input.name, input.range[0], input.range[1], value);
|
|
273
266
|
}
|
|
274
267
|
const arrayBuffer = new ArrayBuffer(input.size);
|
|
275
|
-
input.set(new DataView(arrayBuffer), value,
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
};
|
|
268
|
+
input.set(new DataView(arrayBuffer), value, isLittleEndian(input.config));
|
|
269
|
+
bytes.set(new Uint8Array(arrayBuffer), offset);
|
|
270
|
+
return offset + input.size;
|
|
271
|
+
}
|
|
272
|
+
});
|
|
281
273
|
}
|
|
282
274
|
function numberDecoderFactory(input) {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
assertByteArrayIsNotEmptyForCodec(
|
|
287
|
-
assertByteArrayHasEnoughBytesForCodec(
|
|
275
|
+
return createDecoder({
|
|
276
|
+
fixedSize: input.size,
|
|
277
|
+
read(bytes, offset = 0) {
|
|
278
|
+
assertByteArrayIsNotEmptyForCodec(input.name, bytes, offset);
|
|
279
|
+
assertByteArrayHasEnoughBytesForCodec(input.name, input.size, bytes, offset);
|
|
288
280
|
const view = new DataView(toArrayBuffer(bytes, offset, input.size));
|
|
289
|
-
return [input.get(view,
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
fixedSize: codecData.fixedSize,
|
|
293
|
-
maxSize: codecData.maxSize
|
|
294
|
-
};
|
|
281
|
+
return [input.get(view, isLittleEndian(input.config)), offset + input.size];
|
|
282
|
+
}
|
|
283
|
+
});
|
|
295
284
|
}
|
|
296
285
|
function toArrayBuffer(bytes, offset, length) {
|
|
297
286
|
const bytesOffset = bytes.byteOffset + (offset != null ? offset : 0);
|
|
298
287
|
const bytesLength = length != null ? length : bytes.byteLength;
|
|
299
288
|
return bytes.buffer.slice(bytesOffset, bytesOffset + bytesLength);
|
|
300
289
|
}
|
|
301
|
-
var getShortU16Encoder = (
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
}
|
|
290
|
+
var getShortU16Encoder = () => createEncoder({
|
|
291
|
+
getSizeFromValue: (value) => {
|
|
292
|
+
if (value <= 127)
|
|
293
|
+
return 1;
|
|
294
|
+
if (value <= 16383)
|
|
295
|
+
return 2;
|
|
296
|
+
return 3;
|
|
297
|
+
},
|
|
298
|
+
maxSize: 3,
|
|
299
|
+
write: (value, bytes, offset) => {
|
|
300
|
+
assertNumberIsBetweenForCodec("shortU16", 0, 65535, value);
|
|
301
|
+
const shortU16Bytes = [0];
|
|
302
|
+
for (let ii = 0; ; ii += 1) {
|
|
303
|
+
const alignedValue = value >> ii * 7;
|
|
304
|
+
if (alignedValue === 0) {
|
|
305
|
+
break;
|
|
318
306
|
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
};
|
|
324
|
-
};
|
|
325
|
-
var getShortU16Decoder = (config = {}) => {
|
|
326
|
-
var _a;
|
|
327
|
-
return {
|
|
328
|
-
decode: (bytes, offset = 0) => {
|
|
329
|
-
let value = 0;
|
|
330
|
-
let byteCount = 0;
|
|
331
|
-
while (++byteCount) {
|
|
332
|
-
const byteIndex = byteCount - 1;
|
|
333
|
-
const currentByte = bytes[offset + byteIndex];
|
|
334
|
-
const nextSevenBits = 127 & currentByte;
|
|
335
|
-
value |= nextSevenBits << byteIndex * 7;
|
|
336
|
-
if ((currentByte & 128) === 0) {
|
|
337
|
-
break;
|
|
338
|
-
}
|
|
307
|
+
const nextSevenBits = 127 & alignedValue;
|
|
308
|
+
shortU16Bytes[ii] = nextSevenBits;
|
|
309
|
+
if (ii > 0) {
|
|
310
|
+
shortU16Bytes[ii - 1] |= 128;
|
|
339
311
|
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
312
|
+
}
|
|
313
|
+
bytes.set(shortU16Bytes, offset);
|
|
314
|
+
return offset + shortU16Bytes.length;
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
var getShortU16Decoder = () => createDecoder({
|
|
318
|
+
maxSize: 3,
|
|
319
|
+
read: (bytes, offset) => {
|
|
320
|
+
let value = 0;
|
|
321
|
+
let byteCount = 0;
|
|
322
|
+
while (++byteCount) {
|
|
323
|
+
const byteIndex = byteCount - 1;
|
|
324
|
+
const currentByte = bytes[offset + byteIndex];
|
|
325
|
+
const nextSevenBits = 127 & currentByte;
|
|
326
|
+
value |= nextSevenBits << byteIndex * 7;
|
|
327
|
+
if ((currentByte & 128) === 0) {
|
|
328
|
+
break;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
return [value, offset + byteCount];
|
|
332
|
+
}
|
|
333
|
+
});
|
|
347
334
|
var getU32Encoder = (config = {}) => numberEncoderFactory({
|
|
348
335
|
config,
|
|
349
336
|
name: "u32",
|
|
@@ -357,15 +344,13 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
357
344
|
name: "u32",
|
|
358
345
|
size: 4
|
|
359
346
|
});
|
|
360
|
-
var getU8Encoder = (
|
|
361
|
-
config,
|
|
347
|
+
var getU8Encoder = () => numberEncoderFactory({
|
|
362
348
|
name: "u8",
|
|
363
349
|
range: [0, Number("0xff")],
|
|
364
350
|
set: (view, value) => view.setUint8(0, value),
|
|
365
351
|
size: 1
|
|
366
352
|
});
|
|
367
|
-
var getU8Decoder = (
|
|
368
|
-
config,
|
|
353
|
+
var getU8Decoder = () => numberDecoderFactory({
|
|
369
354
|
get: (view) => view.getUint8(0),
|
|
370
355
|
name: "u8",
|
|
371
356
|
size: 1
|
|
@@ -378,43 +363,38 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
378
363
|
}
|
|
379
364
|
}
|
|
380
365
|
var getBaseXEncoder = (alphabet4) => {
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
366
|
+
return createEncoder({
|
|
367
|
+
getSizeFromValue: (value) => {
|
|
368
|
+
const [leadingZeroes, tailChars] = partitionLeadingZeroes(value, alphabet4[0]);
|
|
369
|
+
if (tailChars === "")
|
|
370
|
+
return value.length;
|
|
371
|
+
const base10Number = getBigIntFromBaseX(tailChars, alphabet4);
|
|
372
|
+
return leadingZeroes.length + Math.ceil(base10Number.toString(16).length / 2);
|
|
373
|
+
},
|
|
374
|
+
write(value, bytes, offset) {
|
|
386
375
|
assertValidBaseString(alphabet4, value);
|
|
387
376
|
if (value === "")
|
|
388
|
-
return
|
|
389
|
-
const
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
if (trailIndex === chars.length)
|
|
394
|
-
return Uint8Array.from(leadingZeroes);
|
|
395
|
-
const tailChars = chars.slice(trailIndex);
|
|
396
|
-
let base10Number = 0n;
|
|
397
|
-
let baseXPower = 1n;
|
|
398
|
-
for (let i = tailChars.length - 1; i >= 0; i -= 1) {
|
|
399
|
-
base10Number += baseXPower * BigInt(alphabet4.indexOf(tailChars[i]));
|
|
400
|
-
baseXPower *= baseBigInt;
|
|
377
|
+
return offset;
|
|
378
|
+
const [leadingZeroes, tailChars] = partitionLeadingZeroes(value, alphabet4[0]);
|
|
379
|
+
if (tailChars === "") {
|
|
380
|
+
bytes.set(new Uint8Array(leadingZeroes.length).fill(0), offset);
|
|
381
|
+
return offset + leadingZeroes.length;
|
|
401
382
|
}
|
|
383
|
+
let base10Number = getBigIntFromBaseX(tailChars, alphabet4);
|
|
402
384
|
const tailBytes = [];
|
|
403
385
|
while (base10Number > 0n) {
|
|
404
386
|
tailBytes.unshift(Number(base10Number % 256n));
|
|
405
387
|
base10Number /= 256n;
|
|
406
388
|
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
};
|
|
389
|
+
const bytesToAdd = [...Array(leadingZeroes.length).fill(0), ...tailBytes];
|
|
390
|
+
bytes.set(bytesToAdd, offset);
|
|
391
|
+
return offset + bytesToAdd.length;
|
|
392
|
+
}
|
|
393
|
+
});
|
|
412
394
|
};
|
|
413
395
|
var getBaseXDecoder = (alphabet4) => {
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
return {
|
|
417
|
-
decode(rawBytes, offset = 0) {
|
|
396
|
+
return createDecoder({
|
|
397
|
+
read(rawBytes, offset) {
|
|
418
398
|
const bytes = offset === 0 ? rawBytes : rawBytes.slice(offset);
|
|
419
399
|
if (bytes.length === 0)
|
|
420
400
|
return ["", 0];
|
|
@@ -423,51 +403,63 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
423
403
|
const leadingZeroes = alphabet4[0].repeat(trailIndex);
|
|
424
404
|
if (trailIndex === bytes.length)
|
|
425
405
|
return [leadingZeroes, rawBytes.length];
|
|
426
|
-
|
|
427
|
-
const tailChars =
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
}
|
|
432
|
-
return [leadingZeroes + tailChars.join(""), rawBytes.length];
|
|
433
|
-
},
|
|
434
|
-
description: `base${base}`,
|
|
435
|
-
fixedSize: null,
|
|
436
|
-
maxSize: null
|
|
437
|
-
};
|
|
406
|
+
const base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
|
|
407
|
+
const tailChars = getBaseXFromBigInt(base10Number, alphabet4);
|
|
408
|
+
return [leadingZeroes + tailChars, rawBytes.length];
|
|
409
|
+
}
|
|
410
|
+
});
|
|
438
411
|
};
|
|
412
|
+
function partitionLeadingZeroes(value, zeroCharacter) {
|
|
413
|
+
const leadingZeroIndex = [...value].findIndex((c) => c !== zeroCharacter);
|
|
414
|
+
return leadingZeroIndex === -1 ? [value, ""] : [value.slice(0, leadingZeroIndex), value.slice(leadingZeroIndex)];
|
|
415
|
+
}
|
|
416
|
+
function getBigIntFromBaseX(value, alphabet4) {
|
|
417
|
+
const base = BigInt(alphabet4.length);
|
|
418
|
+
return [...value].reduce((sum, char) => sum * base + BigInt(alphabet4.indexOf(char)), 0n);
|
|
419
|
+
}
|
|
420
|
+
function getBaseXFromBigInt(value, alphabet4) {
|
|
421
|
+
const base = BigInt(alphabet4.length);
|
|
422
|
+
const tailChars = [];
|
|
423
|
+
while (value > 0n) {
|
|
424
|
+
tailChars.unshift(alphabet4[Number(value % base)]);
|
|
425
|
+
value /= base;
|
|
426
|
+
}
|
|
427
|
+
return tailChars.join("");
|
|
428
|
+
}
|
|
439
429
|
var alphabet2 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
440
430
|
var getBase58Encoder = () => getBaseXEncoder(alphabet2);
|
|
441
431
|
var getBase58Decoder = () => getBaseXDecoder(alphabet2);
|
|
442
432
|
var getBase64Encoder = () => {
|
|
443
433
|
{
|
|
444
|
-
return {
|
|
445
|
-
|
|
446
|
-
encode(value) {
|
|
434
|
+
return createEncoder({
|
|
435
|
+
getSizeFromValue: (value) => {
|
|
447
436
|
try {
|
|
448
|
-
|
|
449
|
-
return new Uint8Array(bytes);
|
|
437
|
+
return atob(value).length;
|
|
450
438
|
} catch (e23) {
|
|
451
439
|
throw new Error(`Expected a string of base 64, got [${value}].`);
|
|
452
440
|
}
|
|
453
441
|
},
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
442
|
+
write(value, bytes, offset) {
|
|
443
|
+
try {
|
|
444
|
+
const bytesToAdd = atob(value).split("").map((c) => c.charCodeAt(0));
|
|
445
|
+
bytes.set(bytesToAdd, offset);
|
|
446
|
+
return bytesToAdd.length + offset;
|
|
447
|
+
} catch (e23) {
|
|
448
|
+
throw new Error(`Expected a string of base 64, got [${value}].`);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
});
|
|
457
452
|
}
|
|
458
453
|
};
|
|
459
454
|
var getBase64Decoder = () => {
|
|
460
455
|
{
|
|
461
|
-
return {
|
|
462
|
-
|
|
456
|
+
return createDecoder({
|
|
457
|
+
read(bytes, offset = 0) {
|
|
463
458
|
const slice = bytes.slice(offset);
|
|
464
459
|
const value = btoa(String.fromCharCode(...slice));
|
|
465
460
|
return [value, bytes.length];
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
fixedSize: null,
|
|
469
|
-
maxSize: null
|
|
470
|
-
};
|
|
461
|
+
}
|
|
462
|
+
});
|
|
471
463
|
}
|
|
472
464
|
};
|
|
473
465
|
var removeNullCharacters = (value) => (
|
|
@@ -478,77 +470,69 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
478
470
|
var o = globalThis.TextEncoder;
|
|
479
471
|
var getUtf8Encoder = () => {
|
|
480
472
|
let textEncoder;
|
|
481
|
-
return {
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
473
|
+
return createEncoder({
|
|
474
|
+
getSizeFromValue: (value) => (textEncoder || (textEncoder = new o())).encode(value).length,
|
|
475
|
+
write: (value, bytes, offset) => {
|
|
476
|
+
const bytesToAdd = (textEncoder || (textEncoder = new o())).encode(value);
|
|
477
|
+
bytes.set(bytesToAdd, offset);
|
|
478
|
+
return offset + bytesToAdd.length;
|
|
479
|
+
}
|
|
480
|
+
});
|
|
487
481
|
};
|
|
488
482
|
var getUtf8Decoder = () => {
|
|
489
483
|
let textDecoder;
|
|
490
|
-
return {
|
|
491
|
-
|
|
484
|
+
return createDecoder({
|
|
485
|
+
read(bytes, offset) {
|
|
492
486
|
const value = (textDecoder || (textDecoder = new e())).decode(bytes.slice(offset));
|
|
493
487
|
return [removeNullCharacters(value), bytes.length];
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
fixedSize: null,
|
|
497
|
-
maxSize: null
|
|
498
|
-
};
|
|
488
|
+
}
|
|
489
|
+
});
|
|
499
490
|
};
|
|
500
|
-
|
|
501
|
-
var _a, _b
|
|
491
|
+
function getStringEncoder(config = {}) {
|
|
492
|
+
var _a, _b;
|
|
502
493
|
const size = (_a = config.size) != null ? _a : getU32Encoder();
|
|
503
494
|
const encoding = (_b = config.encoding) != null ? _b : getUtf8Encoder();
|
|
504
|
-
const description = (_c = config.description) != null ? _c : `string(${encoding.description}; ${getSizeDescription(size)})`;
|
|
505
495
|
if (size === "variable") {
|
|
506
|
-
return
|
|
496
|
+
return encoding;
|
|
507
497
|
}
|
|
508
498
|
if (typeof size === "number") {
|
|
509
|
-
return fixEncoder(encoding, size
|
|
499
|
+
return fixEncoder(encoding, size);
|
|
510
500
|
}
|
|
511
|
-
return {
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
const lengthBytes = size.encode(contentBytes.length);
|
|
516
|
-
return mergeBytes([lengthBytes, contentBytes]);
|
|
501
|
+
return createEncoder({
|
|
502
|
+
getSizeFromValue: (value) => {
|
|
503
|
+
const contentSize = getEncodedSize(value, encoding);
|
|
504
|
+
return getEncodedSize(contentSize, size) + contentSize;
|
|
517
505
|
},
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
506
|
+
write: (value, bytes, offset) => {
|
|
507
|
+
const contentSize = getEncodedSize(value, encoding);
|
|
508
|
+
offset = size.write(contentSize, bytes, offset);
|
|
509
|
+
return encoding.write(value, bytes, offset);
|
|
510
|
+
}
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
function getStringDecoder(config = {}) {
|
|
514
|
+
var _a, _b;
|
|
524
515
|
const size = (_a = config.size) != null ? _a : getU32Decoder();
|
|
525
516
|
const encoding = (_b = config.encoding) != null ? _b : getUtf8Decoder();
|
|
526
|
-
const description = (_c = config.description) != null ? _c : `string(${encoding.description}; ${getSizeDescription(size)})`;
|
|
527
517
|
if (size === "variable") {
|
|
528
|
-
return
|
|
518
|
+
return encoding;
|
|
529
519
|
}
|
|
530
520
|
if (typeof size === "number") {
|
|
531
|
-
return fixDecoder(encoding, size
|
|
521
|
+
return fixDecoder(encoding, size);
|
|
532
522
|
}
|
|
533
|
-
return {
|
|
534
|
-
|
|
523
|
+
return createDecoder({
|
|
524
|
+
read: (bytes, offset = 0) => {
|
|
535
525
|
assertByteArrayIsNotEmptyForCodec("string", bytes, offset);
|
|
536
|
-
const [lengthBigInt, lengthOffset] = size.
|
|
526
|
+
const [lengthBigInt, lengthOffset] = size.read(bytes, offset);
|
|
537
527
|
const length = Number(lengthBigInt);
|
|
538
528
|
offset = lengthOffset;
|
|
539
529
|
const contentBytes = bytes.slice(offset, offset + length);
|
|
540
530
|
assertByteArrayHasEnoughBytesForCodec("string", length, contentBytes);
|
|
541
|
-
const [value, contentOffset] = encoding.
|
|
531
|
+
const [value, contentOffset] = encoding.read(contentBytes, 0);
|
|
542
532
|
offset += contentOffset;
|
|
543
533
|
return [value, offset];
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
fixedSize: null,
|
|
547
|
-
maxSize: null
|
|
548
|
-
};
|
|
549
|
-
};
|
|
550
|
-
function getSizeDescription(size) {
|
|
551
|
-
return typeof size === "object" ? size.description : `${size}`;
|
|
534
|
+
}
|
|
535
|
+
});
|
|
552
536
|
}
|
|
553
537
|
|
|
554
538
|
// ../assertions/dist/index.browser.js
|
|
@@ -677,27 +661,17 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
677
661
|
assertIsAddress(putativeAddress);
|
|
678
662
|
return putativeAddress;
|
|
679
663
|
}
|
|
680
|
-
function getAddressEncoder(
|
|
681
|
-
var _a;
|
|
664
|
+
function getAddressEncoder() {
|
|
682
665
|
return mapEncoder(
|
|
683
|
-
getStringEncoder({
|
|
684
|
-
description: (_a = config == null ? void 0 : config.description) != null ? _a : "Address",
|
|
685
|
-
encoding: getMemoizedBase58Encoder(),
|
|
686
|
-
size: 32
|
|
687
|
-
}),
|
|
666
|
+
getStringEncoder({ encoding: getMemoizedBase58Encoder(), size: 32 }),
|
|
688
667
|
(putativeAddress) => address(putativeAddress)
|
|
689
668
|
);
|
|
690
669
|
}
|
|
691
|
-
function getAddressDecoder(
|
|
692
|
-
|
|
693
|
-
return getStringDecoder({
|
|
694
|
-
description: (_a = config == null ? void 0 : config.description) != null ? _a : "Address",
|
|
695
|
-
encoding: getMemoizedBase58Decoder(),
|
|
696
|
-
size: 32
|
|
697
|
-
});
|
|
670
|
+
function getAddressDecoder() {
|
|
671
|
+
return getStringDecoder({ encoding: getMemoizedBase58Decoder(), size: 32 });
|
|
698
672
|
}
|
|
699
|
-
function getAddressCodec(
|
|
700
|
-
return combineCodec(getAddressEncoder(
|
|
673
|
+
function getAddressCodec() {
|
|
674
|
+
return combineCodec(getAddressEncoder(), getAddressDecoder());
|
|
701
675
|
}
|
|
702
676
|
function getAddressComparator() {
|
|
703
677
|
return new Intl.Collator("en", {
|
|
@@ -862,7 +836,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
862
836
|
if (await compressedPointBytesAreOnCurve(addressBytes)) {
|
|
863
837
|
throw new PointOnCurveError("Invalid seeds; point must fall off the Ed25519 curve");
|
|
864
838
|
}
|
|
865
|
-
return base58EncodedAddressCodec.decode(addressBytes)
|
|
839
|
+
return base58EncodedAddressCodec.decode(addressBytes);
|
|
866
840
|
}
|
|
867
841
|
async function getProgramDerivedAddress({
|
|
868
842
|
programAddress,
|
|
@@ -887,21 +861,21 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
887
861
|
throw new Error("Unable to find a viable program address bump seed");
|
|
888
862
|
}
|
|
889
863
|
async function createAddressWithSeed({ baseAddress, programAddress, seed }) {
|
|
890
|
-
const { encode
|
|
864
|
+
const { encode, decode } = getAddressCodec();
|
|
891
865
|
const seedBytes = typeof seed === "string" ? new TextEncoder().encode(seed) : seed;
|
|
892
866
|
if (seedBytes.byteLength > MAX_SEED_LENGTH) {
|
|
893
867
|
throw new Error(`The seed exceeds the maximum length of 32 bytes`);
|
|
894
868
|
}
|
|
895
|
-
const programAddressBytes =
|
|
869
|
+
const programAddressBytes = encode(programAddress);
|
|
896
870
|
if (programAddressBytes.length >= PDA_MARKER_BYTES.length && programAddressBytes.slice(-PDA_MARKER_BYTES.length).every((byte, index) => byte === PDA_MARKER_BYTES[index])) {
|
|
897
871
|
throw new Error(`programAddress cannot end with the PDA marker`);
|
|
898
872
|
}
|
|
899
873
|
const addressBytesBuffer = await crypto.subtle.digest(
|
|
900
874
|
"SHA-256",
|
|
901
|
-
new Uint8Array([...
|
|
875
|
+
new Uint8Array([...encode(baseAddress), ...seedBytes, ...programAddressBytes])
|
|
902
876
|
);
|
|
903
877
|
const addressBytes = new Uint8Array(addressBytesBuffer);
|
|
904
|
-
return
|
|
878
|
+
return decode(addressBytes);
|
|
905
879
|
}
|
|
906
880
|
async function getAddressFromPublicKey(publicKey) {
|
|
907
881
|
await assertKeyExporterIsAvailable();
|
|
@@ -909,8 +883,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
909
883
|
throw new Error("The `CryptoKey` must be an `Ed25519` public key");
|
|
910
884
|
}
|
|
911
885
|
const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
|
|
912
|
-
|
|
913
|
-
return base58EncodedAddress;
|
|
886
|
+
return getAddressDecoder().decode(new Uint8Array(publicKeyBytes));
|
|
914
887
|
}
|
|
915
888
|
|
|
916
889
|
// ../instructions/dist/index.browser.js
|
|
@@ -966,6 +939,59 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
966
939
|
);
|
|
967
940
|
return keyPair;
|
|
968
941
|
}
|
|
942
|
+
function addPkcs8Header(bytes) {
|
|
943
|
+
return new Uint8Array([
|
|
944
|
+
/**
|
|
945
|
+
* PKCS#8 header
|
|
946
|
+
*/
|
|
947
|
+
48,
|
|
948
|
+
// ASN.1 sequence tag
|
|
949
|
+
46,
|
|
950
|
+
// Length of sequence (46 more bytes)
|
|
951
|
+
2,
|
|
952
|
+
// ASN.1 integer tag
|
|
953
|
+
1,
|
|
954
|
+
// Length of integer
|
|
955
|
+
0,
|
|
956
|
+
// Version number
|
|
957
|
+
48,
|
|
958
|
+
// ASN.1 sequence tag
|
|
959
|
+
5,
|
|
960
|
+
// Length of sequence
|
|
961
|
+
6,
|
|
962
|
+
// ASN.1 object identifier tag
|
|
963
|
+
3,
|
|
964
|
+
// Length of object identifier
|
|
965
|
+
// Edwards curve algorithms identifier https://oid-rep.orange-labs.fr/get/1.3.101.112
|
|
966
|
+
43,
|
|
967
|
+
// iso(1) / identified-organization(3) (The first node is multiplied by the decimal 40 and the result is added to the value of the second node)
|
|
968
|
+
101,
|
|
969
|
+
// thawte(101)
|
|
970
|
+
// Ed25519 identifier
|
|
971
|
+
112,
|
|
972
|
+
// id-Ed25519(112)
|
|
973
|
+
/**
|
|
974
|
+
* Private key payload
|
|
975
|
+
*/
|
|
976
|
+
4,
|
|
977
|
+
// ASN.1 octet string tag
|
|
978
|
+
34,
|
|
979
|
+
// String length (34 more bytes)
|
|
980
|
+
// Private key bytes as octet string
|
|
981
|
+
4,
|
|
982
|
+
// ASN.1 octet string tag
|
|
983
|
+
32,
|
|
984
|
+
// String length (32 bytes)
|
|
985
|
+
...bytes
|
|
986
|
+
]);
|
|
987
|
+
}
|
|
988
|
+
async function createPrivateKeyFromBytes(bytes, extractable) {
|
|
989
|
+
if (bytes.byteLength !== 32) {
|
|
990
|
+
throw new Error("Private key bytes must be of length 32");
|
|
991
|
+
}
|
|
992
|
+
const privateKeyBytesPkcs8 = addPkcs8Header(bytes);
|
|
993
|
+
return await crypto.subtle.importKey("pkcs8", privateKeyBytesPkcs8, "Ed25519", extractable != null ? extractable : false, ["sign"]);
|
|
994
|
+
}
|
|
969
995
|
var base58Encoder;
|
|
970
996
|
function assertIsSignature(putativeSignature) {
|
|
971
997
|
if (!base58Encoder)
|
|
@@ -1118,185 +1144,194 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1118
1144
|
|
|
1119
1145
|
// ../codecs-data-structures/dist/index.browser.js
|
|
1120
1146
|
init_env_shim();
|
|
1121
|
-
function sumCodecSizes(sizes) {
|
|
1122
|
-
return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
|
|
1123
|
-
}
|
|
1124
|
-
function decodeArrayLikeCodecSize(size, childrenSizes, bytes, offset) {
|
|
1125
|
-
if (typeof size === "number") {
|
|
1126
|
-
return [size, offset];
|
|
1127
|
-
}
|
|
1128
|
-
if (typeof size === "object") {
|
|
1129
|
-
return size.decode(bytes, offset);
|
|
1130
|
-
}
|
|
1131
|
-
if (size === "remainder") {
|
|
1132
|
-
const childrenSize = sumCodecSizes(childrenSizes);
|
|
1133
|
-
if (childrenSize === null) {
|
|
1134
|
-
throw new Error('Codecs of "remainder" size must have fixed-size items.');
|
|
1135
|
-
}
|
|
1136
|
-
const remainder = bytes.slice(offset).length;
|
|
1137
|
-
if (remainder % childrenSize !== 0) {
|
|
1138
|
-
throw new Error(
|
|
1139
|
-
`The remainder of the byte array (${remainder} bytes) cannot be split into chunks of ${childrenSize} bytes. Codecs of "remainder" size must have a remainder that is a multiple of its item size. In other words, ${remainder} modulo ${childrenSize} should be equal to zero.`
|
|
1140
|
-
);
|
|
1141
|
-
}
|
|
1142
|
-
return [remainder / childrenSize, offset];
|
|
1143
|
-
}
|
|
1144
|
-
throw new Error(`Unrecognized array-like codec size: ${JSON.stringify(size)}`);
|
|
1145
|
-
}
|
|
1146
|
-
function getArrayLikeCodecSizeDescription(size) {
|
|
1147
|
-
return typeof size === "object" ? size.description : `${size}`;
|
|
1148
|
-
}
|
|
1149
|
-
function getArrayLikeCodecSizeFromChildren(size, childrenSizes) {
|
|
1150
|
-
if (typeof size !== "number")
|
|
1151
|
-
return null;
|
|
1152
|
-
if (size === 0)
|
|
1153
|
-
return 0;
|
|
1154
|
-
const childrenSize = sumCodecSizes(childrenSizes);
|
|
1155
|
-
return childrenSize === null ? null : childrenSize * size;
|
|
1156
|
-
}
|
|
1157
|
-
function getArrayLikeCodecSizePrefix(size, realSize) {
|
|
1158
|
-
return typeof size === "object" ? size.encode(realSize) : new Uint8Array();
|
|
1159
|
-
}
|
|
1160
1147
|
function assertValidNumberOfItemsForCodec(codecDescription, expected, actual) {
|
|
1161
1148
|
if (expected !== actual) {
|
|
1162
1149
|
throw new Error(`Expected [${codecDescription}] to have ${expected} items, got ${actual}.`);
|
|
1163
1150
|
}
|
|
1164
1151
|
}
|
|
1165
|
-
function
|
|
1166
|
-
|
|
1167
|
-
throw new Error('Codecs of "remainder" size must have fixed-size items.');
|
|
1168
|
-
}
|
|
1169
|
-
return {
|
|
1170
|
-
description: description != null ? description : `array(${item.description}; ${getArrayLikeCodecSizeDescription(size)})`,
|
|
1171
|
-
fixedSize: getArrayLikeCodecSizeFromChildren(size, [item.fixedSize]),
|
|
1172
|
-
maxSize: getArrayLikeCodecSizeFromChildren(size, [item.maxSize])
|
|
1173
|
-
};
|
|
1152
|
+
function sumCodecSizes(sizes) {
|
|
1153
|
+
return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
|
|
1174
1154
|
}
|
|
1175
|
-
function
|
|
1155
|
+
function getFixedSize(codec) {
|
|
1156
|
+
return isFixedSize(codec) ? codec.fixedSize : null;
|
|
1157
|
+
}
|
|
1158
|
+
function getMaxSize(codec) {
|
|
1176
1159
|
var _a;
|
|
1160
|
+
return isFixedSize(codec) ? codec.fixedSize : (_a = codec.maxSize) != null ? _a : null;
|
|
1161
|
+
}
|
|
1162
|
+
function getArrayEncoder(item, config = {}) {
|
|
1163
|
+
var _a, _b;
|
|
1177
1164
|
const size = (_a = config.size) != null ? _a : getU32Encoder();
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1165
|
+
if (size === "remainder") {
|
|
1166
|
+
assertIsFixedSize(item, 'Codecs of "remainder" size must have fixed-size items.');
|
|
1167
|
+
}
|
|
1168
|
+
const fixedSize = computeArrayLikeCodecSize(size, getFixedSize(item));
|
|
1169
|
+
const maxSize = (_b = computeArrayLikeCodecSize(size, getMaxSize(item))) != null ? _b : void 0;
|
|
1170
|
+
return createEncoder({
|
|
1171
|
+
...fixedSize !== null ? { fixedSize } : {
|
|
1172
|
+
getSizeFromValue: (array) => {
|
|
1173
|
+
const prefixSize = typeof size === "object" ? getEncodedSize(array.length, size) : 0;
|
|
1174
|
+
return prefixSize + [...array].reduce((all, value) => all + getEncodedSize(value, item), 0);
|
|
1175
|
+
},
|
|
1176
|
+
maxSize
|
|
1177
|
+
},
|
|
1178
|
+
write: (array, bytes, offset) => {
|
|
1181
1179
|
if (typeof size === "number") {
|
|
1182
|
-
assertValidNumberOfItemsForCodec("array", size,
|
|
1180
|
+
assertValidNumberOfItemsForCodec("array", size, array.length);
|
|
1181
|
+
}
|
|
1182
|
+
if (typeof size === "object") {
|
|
1183
|
+
offset = size.write(array.length, bytes, offset);
|
|
1183
1184
|
}
|
|
1184
|
-
|
|
1185
|
+
array.forEach((value) => {
|
|
1186
|
+
offset = item.write(value, bytes, offset);
|
|
1187
|
+
});
|
|
1188
|
+
return offset;
|
|
1185
1189
|
}
|
|
1186
|
-
};
|
|
1190
|
+
});
|
|
1187
1191
|
}
|
|
1188
1192
|
function getArrayDecoder(item, config = {}) {
|
|
1189
|
-
var _a;
|
|
1193
|
+
var _a, _b;
|
|
1190
1194
|
const size = (_a = config.size) != null ? _a : getU32Decoder();
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1195
|
+
if (size === "remainder") {
|
|
1196
|
+
assertIsFixedSize(item, 'Codecs of "remainder" size must have fixed-size items.');
|
|
1197
|
+
}
|
|
1198
|
+
const itemSize = getFixedSize(item);
|
|
1199
|
+
const fixedSize = computeArrayLikeCodecSize(size, itemSize);
|
|
1200
|
+
const maxSize = (_b = computeArrayLikeCodecSize(size, getMaxSize(item))) != null ? _b : void 0;
|
|
1201
|
+
return createDecoder({
|
|
1202
|
+
...fixedSize !== null ? { fixedSize } : { maxSize },
|
|
1203
|
+
read: (bytes, offset) => {
|
|
1204
|
+
const array = [];
|
|
1194
1205
|
if (typeof size === "object" && bytes.slice(offset).length === 0) {
|
|
1195
|
-
return [
|
|
1206
|
+
return [array, offset];
|
|
1196
1207
|
}
|
|
1197
|
-
const [resolvedSize, newOffset] =
|
|
1208
|
+
const [resolvedSize, newOffset] = readArrayLikeCodecSize(size, itemSize, bytes, offset);
|
|
1198
1209
|
offset = newOffset;
|
|
1199
|
-
const values = [];
|
|
1200
1210
|
for (let i = 0; i < resolvedSize; i += 1) {
|
|
1201
|
-
const [value, newOffset2] = item.
|
|
1202
|
-
values.push(value);
|
|
1211
|
+
const [value, newOffset2] = item.read(bytes, offset);
|
|
1203
1212
|
offset = newOffset2;
|
|
1213
|
+
array.push(value);
|
|
1204
1214
|
}
|
|
1205
|
-
return [
|
|
1215
|
+
return [array, offset];
|
|
1206
1216
|
}
|
|
1207
|
-
};
|
|
1217
|
+
});
|
|
1218
|
+
}
|
|
1219
|
+
function readArrayLikeCodecSize(size, itemSize, bytes, offset) {
|
|
1220
|
+
if (typeof size === "number") {
|
|
1221
|
+
return [size, offset];
|
|
1222
|
+
}
|
|
1223
|
+
if (typeof size === "object") {
|
|
1224
|
+
return size.read(bytes, offset);
|
|
1225
|
+
}
|
|
1226
|
+
if (size === "remainder") {
|
|
1227
|
+
if (itemSize === null) {
|
|
1228
|
+
throw new Error('Codecs of "remainder" size must have fixed-size items.');
|
|
1229
|
+
}
|
|
1230
|
+
const remainder = Math.max(0, bytes.length - offset);
|
|
1231
|
+
if (remainder % itemSize !== 0) {
|
|
1232
|
+
throw new Error(
|
|
1233
|
+
`The remainder of the byte array (${remainder} bytes) cannot be split into chunks of ${itemSize} bytes. Codecs of "remainder" size must have a remainder that is a multiple of its item size. In other words, ${remainder} modulo ${itemSize} should be equal to zero.`
|
|
1234
|
+
);
|
|
1235
|
+
}
|
|
1236
|
+
return [remainder / itemSize, offset];
|
|
1237
|
+
}
|
|
1238
|
+
throw new Error(`Unrecognized array-like codec size: ${JSON.stringify(size)}`);
|
|
1239
|
+
}
|
|
1240
|
+
function computeArrayLikeCodecSize(size, itemSize) {
|
|
1241
|
+
if (typeof size !== "number")
|
|
1242
|
+
return null;
|
|
1243
|
+
if (size === 0)
|
|
1244
|
+
return 0;
|
|
1245
|
+
return itemSize === null ? null : itemSize * size;
|
|
1208
1246
|
}
|
|
1209
1247
|
function getBytesEncoder(config = {}) {
|
|
1210
|
-
var _a
|
|
1248
|
+
var _a;
|
|
1211
1249
|
const size = (_a = config.size) != null ? _a : "variable";
|
|
1212
|
-
const
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
};
|
|
1250
|
+
const byteEncoder = createEncoder({
|
|
1251
|
+
getSizeFromValue: (value) => value.length,
|
|
1252
|
+
write: (value, bytes, offset) => {
|
|
1253
|
+
bytes.set(value, offset);
|
|
1254
|
+
return offset + value.length;
|
|
1255
|
+
}
|
|
1256
|
+
});
|
|
1220
1257
|
if (size === "variable") {
|
|
1221
1258
|
return byteEncoder;
|
|
1222
1259
|
}
|
|
1223
1260
|
if (typeof size === "number") {
|
|
1224
|
-
return fixEncoder(byteEncoder, size
|
|
1261
|
+
return fixEncoder(byteEncoder, size);
|
|
1225
1262
|
}
|
|
1226
|
-
return {
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
return mergeBytes([lengthBytes, contentBytes]);
|
|
1263
|
+
return createEncoder({
|
|
1264
|
+
getSizeFromValue: (value) => getEncodedSize(value.length, size) + value.length,
|
|
1265
|
+
write: (value, bytes, offset) => {
|
|
1266
|
+
offset = size.write(value.length, bytes, offset);
|
|
1267
|
+
return byteEncoder.write(value, bytes, offset);
|
|
1232
1268
|
}
|
|
1233
|
-
};
|
|
1269
|
+
});
|
|
1234
1270
|
}
|
|
1235
1271
|
function getBytesDecoder(config = {}) {
|
|
1236
|
-
var _a
|
|
1272
|
+
var _a;
|
|
1237
1273
|
const size = (_a = config.size) != null ? _a : "variable";
|
|
1238
|
-
const
|
|
1239
|
-
|
|
1240
|
-
const byteDecoder = {
|
|
1241
|
-
decode: (bytes, offset = 0) => {
|
|
1274
|
+
const byteDecoder = createDecoder({
|
|
1275
|
+
read: (bytes, offset) => {
|
|
1242
1276
|
const slice = bytes.slice(offset);
|
|
1243
1277
|
return [slice, offset + slice.length];
|
|
1244
|
-
}
|
|
1245
|
-
|
|
1246
|
-
fixedSize: null,
|
|
1247
|
-
maxSize: null
|
|
1248
|
-
};
|
|
1278
|
+
}
|
|
1279
|
+
});
|
|
1249
1280
|
if (size === "variable") {
|
|
1250
1281
|
return byteDecoder;
|
|
1251
1282
|
}
|
|
1252
1283
|
if (typeof size === "number") {
|
|
1253
|
-
return fixDecoder(byteDecoder, size
|
|
1284
|
+
return fixDecoder(byteDecoder, size);
|
|
1254
1285
|
}
|
|
1255
|
-
return {
|
|
1256
|
-
|
|
1257
|
-
decode: (bytes, offset = 0) => {
|
|
1286
|
+
return createDecoder({
|
|
1287
|
+
read: (bytes, offset) => {
|
|
1258
1288
|
assertByteArrayIsNotEmptyForCodec("bytes", bytes, offset);
|
|
1259
|
-
const [lengthBigInt, lengthOffset] = size.
|
|
1289
|
+
const [lengthBigInt, lengthOffset] = size.read(bytes, offset);
|
|
1260
1290
|
const length = Number(lengthBigInt);
|
|
1261
1291
|
offset = lengthOffset;
|
|
1262
1292
|
const contentBytes = bytes.slice(offset, offset + length);
|
|
1263
1293
|
assertByteArrayHasEnoughBytesForCodec("bytes", length, contentBytes);
|
|
1264
|
-
const [value, contentOffset] = byteDecoder.
|
|
1294
|
+
const [value, contentOffset] = byteDecoder.read(contentBytes, 0);
|
|
1265
1295
|
offset += contentOffset;
|
|
1266
1296
|
return [value, offset];
|
|
1267
1297
|
}
|
|
1268
|
-
};
|
|
1269
|
-
}
|
|
1270
|
-
function structCodecHelper(fields, description) {
|
|
1271
|
-
const fieldDescriptions = fields.map(([name, codec]) => `${String(name)}: ${codec.description}`).join(", ");
|
|
1272
|
-
return {
|
|
1273
|
-
description: description != null ? description : `struct(${fieldDescriptions})`,
|
|
1274
|
-
fixedSize: sumCodecSizes(fields.map(([, field]) => field.fixedSize)),
|
|
1275
|
-
maxSize: sumCodecSizes(fields.map(([, field]) => field.maxSize))
|
|
1276
|
-
};
|
|
1298
|
+
});
|
|
1277
1299
|
}
|
|
1278
|
-
function getStructEncoder(fields
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1300
|
+
function getStructEncoder(fields) {
|
|
1301
|
+
var _a;
|
|
1302
|
+
const fieldCodecs = fields.map(([, codec]) => codec);
|
|
1303
|
+
const fixedSize = sumCodecSizes(fieldCodecs.map(getFixedSize));
|
|
1304
|
+
const maxSize = (_a = sumCodecSizes(fieldCodecs.map(getMaxSize))) != null ? _a : void 0;
|
|
1305
|
+
return createEncoder({
|
|
1306
|
+
...fixedSize === null ? {
|
|
1307
|
+
getSizeFromValue: (value) => fields.map(([key, codec]) => getEncodedSize(value[key], codec)).reduce((all, one) => all + one, 0),
|
|
1308
|
+
maxSize
|
|
1309
|
+
} : { fixedSize },
|
|
1310
|
+
write: (struct, bytes, offset) => {
|
|
1311
|
+
fields.forEach(([key, codec]) => {
|
|
1312
|
+
offset = codec.write(struct[key], bytes, offset);
|
|
1313
|
+
});
|
|
1314
|
+
return offset;
|
|
1284
1315
|
}
|
|
1285
|
-
};
|
|
1316
|
+
});
|
|
1286
1317
|
}
|
|
1287
|
-
function getStructDecoder(fields
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1318
|
+
function getStructDecoder(fields) {
|
|
1319
|
+
var _a;
|
|
1320
|
+
const fieldCodecs = fields.map(([, codec]) => codec);
|
|
1321
|
+
const fixedSize = sumCodecSizes(fieldCodecs.map(getFixedSize));
|
|
1322
|
+
const maxSize = (_a = sumCodecSizes(fieldCodecs.map(getMaxSize))) != null ? _a : void 0;
|
|
1323
|
+
return createDecoder({
|
|
1324
|
+
...fixedSize === null ? { maxSize } : { fixedSize },
|
|
1325
|
+
read: (bytes, offset) => {
|
|
1291
1326
|
const struct = {};
|
|
1292
1327
|
fields.forEach(([key, codec]) => {
|
|
1293
|
-
const [value, newOffset] = codec.
|
|
1328
|
+
const [value, newOffset] = codec.read(bytes, offset);
|
|
1294
1329
|
offset = newOffset;
|
|
1295
1330
|
struct[key] = value;
|
|
1296
1331
|
});
|
|
1297
1332
|
return [struct, offset];
|
|
1298
1333
|
}
|
|
1299
|
-
};
|
|
1334
|
+
});
|
|
1300
1335
|
}
|
|
1301
1336
|
|
|
1302
1337
|
// ../functional/dist/index.browser.js
|
|
@@ -1304,6 +1339,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1304
1339
|
function pipe(init, ...fns) {
|
|
1305
1340
|
return fns.reduce((acc, fn) => fn(acc), init);
|
|
1306
1341
|
}
|
|
1342
|
+
|
|
1343
|
+
// ../transactions/dist/index.browser.js
|
|
1307
1344
|
function getUnsignedTransaction(transaction) {
|
|
1308
1345
|
if ("signatures" in transaction) {
|
|
1309
1346
|
const {
|
|
@@ -1339,6 +1376,22 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1339
1376
|
});
|
|
1340
1377
|
}
|
|
1341
1378
|
}
|
|
1379
|
+
function isTransactionWithBlockhashLifetime(transaction) {
|
|
1380
|
+
const lifetimeConstraintShapeMatches = "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.blockhash === "string" && typeof transaction.lifetimeConstraint.lastValidBlockHeight === "bigint";
|
|
1381
|
+
if (!lifetimeConstraintShapeMatches)
|
|
1382
|
+
return false;
|
|
1383
|
+
try {
|
|
1384
|
+
assertIsBlockhash(transaction.lifetimeConstraint.blockhash);
|
|
1385
|
+
return true;
|
|
1386
|
+
} catch {
|
|
1387
|
+
return false;
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
function assertIsTransactionWithBlockhashLifetime(transaction) {
|
|
1391
|
+
if (!isTransactionWithBlockhashLifetime(transaction)) {
|
|
1392
|
+
throw new Error("Transaction does not have a blockhash lifetime");
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1342
1395
|
function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) {
|
|
1343
1396
|
if ("lifetimeConstraint" in transaction && transaction.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transaction.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
|
|
1344
1397
|
return transaction;
|
|
@@ -1742,59 +1795,31 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1742
1795
|
version: transaction.version
|
|
1743
1796
|
};
|
|
1744
1797
|
}
|
|
1745
|
-
var lookupTableAddressDescription = "The address of the address lookup table account from which instruction addresses should be looked up" ;
|
|
1746
|
-
var writableIndicesDescription = "The indices of the accounts in the lookup table that should be loaded as writeable" ;
|
|
1747
|
-
var readableIndicesDescription = "The indices of the accounts in the lookup table that should be loaded as read-only" ;
|
|
1748
|
-
var addressTableLookupDescription = "A pointer to the address of an address lookup table, along with the readonly/writeable indices of the addresses that should be loaded from it" ;
|
|
1749
1798
|
var memoizedAddressTableLookupEncoder;
|
|
1750
1799
|
function getAddressTableLookupEncoder() {
|
|
1751
1800
|
if (!memoizedAddressTableLookupEncoder) {
|
|
1752
|
-
memoizedAddressTableLookupEncoder = getStructEncoder(
|
|
1801
|
+
memoizedAddressTableLookupEncoder = getStructEncoder([
|
|
1802
|
+
["lookupTableAddress", getAddressEncoder()],
|
|
1753
1803
|
[
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
"writableIndices",
|
|
1757
|
-
getArrayEncoder(getU8Encoder(), {
|
|
1758
|
-
description: writableIndicesDescription,
|
|
1759
|
-
size: getShortU16Encoder()
|
|
1760
|
-
})
|
|
1761
|
-
],
|
|
1762
|
-
[
|
|
1763
|
-
"readableIndices",
|
|
1764
|
-
getArrayEncoder(getU8Encoder(), {
|
|
1765
|
-
description: readableIndicesDescription,
|
|
1766
|
-
size: getShortU16Encoder()
|
|
1767
|
-
})
|
|
1768
|
-
]
|
|
1804
|
+
"writableIndices",
|
|
1805
|
+
getArrayEncoder(getU8Encoder(), { size: getShortU16Encoder() })
|
|
1769
1806
|
],
|
|
1770
|
-
|
|
1771
|
-
|
|
1807
|
+
[
|
|
1808
|
+
"readableIndices",
|
|
1809
|
+
getArrayEncoder(getU8Encoder(), { size: getShortU16Encoder() })
|
|
1810
|
+
]
|
|
1811
|
+
]);
|
|
1772
1812
|
}
|
|
1773
1813
|
return memoizedAddressTableLookupEncoder;
|
|
1774
1814
|
}
|
|
1775
1815
|
var memoizedAddressTableLookupDecoder;
|
|
1776
1816
|
function getAddressTableLookupDecoder() {
|
|
1777
1817
|
if (!memoizedAddressTableLookupDecoder) {
|
|
1778
|
-
memoizedAddressTableLookupDecoder = getStructDecoder(
|
|
1779
|
-
[
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
getArrayDecoder(getU8Decoder(), {
|
|
1784
|
-
description: writableIndicesDescription,
|
|
1785
|
-
size: getShortU16Decoder()
|
|
1786
|
-
})
|
|
1787
|
-
],
|
|
1788
|
-
[
|
|
1789
|
-
"readableIndices",
|
|
1790
|
-
getArrayDecoder(getU8Decoder(), {
|
|
1791
|
-
description: readableIndicesDescription,
|
|
1792
|
-
size: getShortU16Decoder()
|
|
1793
|
-
})
|
|
1794
|
-
]
|
|
1795
|
-
],
|
|
1796
|
-
{ description: addressTableLookupDescription }
|
|
1797
|
-
);
|
|
1818
|
+
memoizedAddressTableLookupDecoder = getStructDecoder([
|
|
1819
|
+
["lookupTableAddress", getAddressDecoder()],
|
|
1820
|
+
["writableIndices", getArrayDecoder(getU8Decoder(), { size: getShortU16Decoder() })],
|
|
1821
|
+
["readableIndices", getArrayDecoder(getU8Decoder(), { size: getShortU16Decoder() })]
|
|
1822
|
+
]);
|
|
1798
1823
|
}
|
|
1799
1824
|
return memoizedAddressTableLookupDecoder;
|
|
1800
1825
|
}
|
|
@@ -1804,72 +1829,34 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1804
1829
|
memoizedU8Encoder = getU8Encoder();
|
|
1805
1830
|
return memoizedU8Encoder;
|
|
1806
1831
|
}
|
|
1807
|
-
function getMemoizedU8EncoderDescription(description) {
|
|
1808
|
-
const encoder = getMemoizedU8Encoder();
|
|
1809
|
-
return {
|
|
1810
|
-
...encoder,
|
|
1811
|
-
description: description != null ? description : encoder.description
|
|
1812
|
-
};
|
|
1813
|
-
}
|
|
1814
1832
|
var memoizedU8Decoder;
|
|
1815
1833
|
function getMemoizedU8Decoder() {
|
|
1816
1834
|
if (!memoizedU8Decoder)
|
|
1817
1835
|
memoizedU8Decoder = getU8Decoder();
|
|
1818
1836
|
return memoizedU8Decoder;
|
|
1819
1837
|
}
|
|
1820
|
-
function getMemoizedU8DecoderDescription(description) {
|
|
1821
|
-
const decoder = getMemoizedU8Decoder();
|
|
1822
|
-
return {
|
|
1823
|
-
...decoder,
|
|
1824
|
-
description: description != null ? description : decoder.description
|
|
1825
|
-
};
|
|
1826
|
-
}
|
|
1827
|
-
var numSignerAccountsDescription = "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction" ;
|
|
1828
|
-
var numReadonlySignerAccountsDescription = "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction, but may not be writable" ;
|
|
1829
|
-
var numReadonlyNonSignerAccountsDescription = "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable" ;
|
|
1830
|
-
var messageHeaderDescription = "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses" ;
|
|
1831
1838
|
function getMessageHeaderEncoder() {
|
|
1832
|
-
return getStructEncoder(
|
|
1833
|
-
[
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
],
|
|
1838
|
-
{
|
|
1839
|
-
description: messageHeaderDescription
|
|
1840
|
-
}
|
|
1841
|
-
);
|
|
1839
|
+
return getStructEncoder([
|
|
1840
|
+
["numSignerAccounts", getMemoizedU8Encoder()],
|
|
1841
|
+
["numReadonlySignerAccounts", getMemoizedU8Encoder()],
|
|
1842
|
+
["numReadonlyNonSignerAccounts", getMemoizedU8Encoder()]
|
|
1843
|
+
]);
|
|
1842
1844
|
}
|
|
1843
1845
|
function getMessageHeaderDecoder() {
|
|
1844
|
-
return getStructDecoder(
|
|
1845
|
-
[
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
],
|
|
1850
|
-
{
|
|
1851
|
-
description: messageHeaderDescription
|
|
1852
|
-
}
|
|
1853
|
-
);
|
|
1846
|
+
return getStructDecoder([
|
|
1847
|
+
["numSignerAccounts", getMemoizedU8Decoder()],
|
|
1848
|
+
["numReadonlySignerAccounts", getMemoizedU8Decoder()],
|
|
1849
|
+
["numReadonlyNonSignerAccounts", getMemoizedU8Decoder()]
|
|
1850
|
+
]);
|
|
1854
1851
|
}
|
|
1855
|
-
var programAddressIndexDescription = "The index of the program being called, according to the well-ordered accounts list for this transaction" ;
|
|
1856
|
-
var accountIndexDescription = "The index of an account, according to the well-ordered accounts list for this transaction" ;
|
|
1857
|
-
var accountIndicesDescription = "An optional list of account indices, according to the well-ordered accounts list for this transaction, in the order in which the program being called expects them" ;
|
|
1858
|
-
var dataDescription = "An optional buffer of data passed to the instruction" ;
|
|
1859
1852
|
var memoizedGetInstructionEncoder;
|
|
1860
1853
|
function getInstructionEncoder() {
|
|
1861
1854
|
if (!memoizedGetInstructionEncoder) {
|
|
1862
1855
|
memoizedGetInstructionEncoder = mapEncoder(
|
|
1863
1856
|
getStructEncoder([
|
|
1864
|
-
["programAddressIndex", getU8Encoder(
|
|
1865
|
-
[
|
|
1866
|
-
|
|
1867
|
-
getArrayEncoder(getU8Encoder({ description: accountIndexDescription }), {
|
|
1868
|
-
description: accountIndicesDescription,
|
|
1869
|
-
size: getShortU16Encoder()
|
|
1870
|
-
})
|
|
1871
|
-
],
|
|
1872
|
-
["data", getBytesEncoder({ description: dataDescription, size: getShortU16Encoder() })]
|
|
1857
|
+
["programAddressIndex", getU8Encoder()],
|
|
1858
|
+
["accountIndices", getArrayEncoder(getU8Encoder(), { size: getShortU16Encoder() })],
|
|
1859
|
+
["data", getBytesEncoder({ size: getShortU16Encoder() })]
|
|
1873
1860
|
]),
|
|
1874
1861
|
// Convert an instruction to have all fields defined
|
|
1875
1862
|
(instruction) => {
|
|
@@ -1892,15 +1879,9 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1892
1879
|
if (!memoizedGetInstructionDecoder) {
|
|
1893
1880
|
memoizedGetInstructionDecoder = mapDecoder(
|
|
1894
1881
|
getStructDecoder([
|
|
1895
|
-
["programAddressIndex", getU8Decoder(
|
|
1896
|
-
[
|
|
1897
|
-
|
|
1898
|
-
getArrayDecoder(getU8Decoder({ description: accountIndexDescription }), {
|
|
1899
|
-
description: accountIndicesDescription,
|
|
1900
|
-
size: getShortU16Decoder()
|
|
1901
|
-
})
|
|
1902
|
-
],
|
|
1903
|
-
["data", getBytesDecoder({ description: dataDescription, size: getShortU16Decoder() })]
|
|
1882
|
+
["programAddressIndex", getU8Decoder()],
|
|
1883
|
+
["accountIndices", getArrayDecoder(getU8Decoder(), { size: getShortU16Decoder() })],
|
|
1884
|
+
["data", getBytesDecoder({ size: getShortU16Decoder() })]
|
|
1904
1885
|
]),
|
|
1905
1886
|
// Convert an instruction to exclude optional fields if they are empty
|
|
1906
1887
|
(instruction) => {
|
|
@@ -1919,45 +1900,36 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1919
1900
|
return memoizedGetInstructionDecoder;
|
|
1920
1901
|
}
|
|
1921
1902
|
var VERSION_FLAG_MASK = 128;
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
if (value === "legacy") {
|
|
1938
|
-
return new Uint8Array();
|
|
1939
|
-
}
|
|
1940
|
-
if (value < 0 || value > 127) {
|
|
1941
|
-
throw new Error(`Transaction version must be in the range [0, 127]. \`${value}\` given.`);
|
|
1942
|
-
}
|
|
1943
|
-
return new Uint8Array([value | VERSION_FLAG_MASK]);
|
|
1903
|
+
function getTransactionVersionEncoder() {
|
|
1904
|
+
return createEncoder({
|
|
1905
|
+
getSizeFromValue: (value) => value === "legacy" ? 0 : 1,
|
|
1906
|
+
maxSize: 1,
|
|
1907
|
+
write: (value, bytes, offset) => {
|
|
1908
|
+
if (value === "legacy") {
|
|
1909
|
+
return offset;
|
|
1910
|
+
}
|
|
1911
|
+
if (value < 0 || value > 127) {
|
|
1912
|
+
throw new Error(`Transaction version must be in the range [0, 127]. \`${value}\` given.`);
|
|
1913
|
+
}
|
|
1914
|
+
bytes.set([value | VERSION_FLAG_MASK], offset);
|
|
1915
|
+
return offset + 1;
|
|
1916
|
+
}
|
|
1917
|
+
});
|
|
1944
1918
|
}
|
|
1945
1919
|
function getTransactionVersionDecoder() {
|
|
1946
|
-
return {
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1920
|
+
return createDecoder({
|
|
1921
|
+
maxSize: 1,
|
|
1922
|
+
read: (bytes, offset) => {
|
|
1923
|
+
const firstByte = bytes[offset];
|
|
1924
|
+
if ((firstByte & VERSION_FLAG_MASK) === 0) {
|
|
1925
|
+
return ["legacy", offset];
|
|
1926
|
+
} else {
|
|
1927
|
+
const version = firstByte ^ VERSION_FLAG_MASK;
|
|
1928
|
+
return [version, offset + 1];
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
});
|
|
1956
1932
|
}
|
|
1957
|
-
var staticAccountsDescription = "A compact-array of static account addresses belonging to this transaction" ;
|
|
1958
|
-
var lifetimeTokenDescription = "A 32-byte token that specifies the lifetime of this transaction (eg. a recent blockhash, or a durable nonce)" ;
|
|
1959
|
-
var instructionsDescription = "A compact-array of instructions belonging to this transaction" ;
|
|
1960
|
-
var addressTableLookupsDescription = "A compact array of address table lookups belonging to this transaction" ;
|
|
1961
1933
|
function getCompiledMessageLegacyEncoder() {
|
|
1962
1934
|
return getStructEncoder(getPreludeStructEncoderTuple());
|
|
1963
1935
|
}
|
|
@@ -1983,98 +1955,52 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1983
1955
|
return [
|
|
1984
1956
|
["version", getTransactionVersionEncoder()],
|
|
1985
1957
|
["header", getMessageHeaderEncoder()],
|
|
1986
|
-
[
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
description: staticAccountsDescription,
|
|
1990
|
-
size: getShortU16Encoder()
|
|
1991
|
-
})
|
|
1992
|
-
],
|
|
1993
|
-
[
|
|
1994
|
-
"lifetimeToken",
|
|
1995
|
-
getStringEncoder({
|
|
1996
|
-
description: lifetimeTokenDescription,
|
|
1997
|
-
encoding: getBase58Encoder(),
|
|
1998
|
-
size: 32
|
|
1999
|
-
})
|
|
2000
|
-
],
|
|
2001
|
-
[
|
|
2002
|
-
"instructions",
|
|
2003
|
-
getArrayEncoder(getInstructionEncoder(), {
|
|
2004
|
-
description: instructionsDescription,
|
|
2005
|
-
size: getShortU16Encoder()
|
|
2006
|
-
})
|
|
2007
|
-
]
|
|
1958
|
+
["staticAccounts", getArrayEncoder(getAddressEncoder(), { size: getShortU16Encoder() })],
|
|
1959
|
+
["lifetimeToken", getStringEncoder({ encoding: getBase58Encoder(), size: 32 })],
|
|
1960
|
+
["instructions", getArrayEncoder(getInstructionEncoder(), { size: getShortU16Encoder() })]
|
|
2008
1961
|
];
|
|
2009
1962
|
}
|
|
2010
1963
|
function getPreludeStructDecoderTuple() {
|
|
2011
1964
|
return [
|
|
2012
1965
|
["version", getTransactionVersionDecoder()],
|
|
2013
1966
|
["header", getMessageHeaderDecoder()],
|
|
2014
|
-
[
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
description: staticAccountsDescription,
|
|
2018
|
-
size: getShortU16Decoder()
|
|
2019
|
-
})
|
|
2020
|
-
],
|
|
2021
|
-
[
|
|
2022
|
-
"lifetimeToken",
|
|
2023
|
-
getStringDecoder({
|
|
2024
|
-
description: lifetimeTokenDescription,
|
|
2025
|
-
encoding: getBase58Decoder(),
|
|
2026
|
-
size: 32
|
|
2027
|
-
})
|
|
2028
|
-
],
|
|
2029
|
-
[
|
|
2030
|
-
"instructions",
|
|
2031
|
-
getArrayDecoder(getInstructionDecoder(), {
|
|
2032
|
-
description: instructionsDescription,
|
|
2033
|
-
size: getShortU16Decoder()
|
|
2034
|
-
})
|
|
2035
|
-
],
|
|
1967
|
+
["staticAccounts", getArrayDecoder(getAddressDecoder(), { size: getShortU16Decoder() })],
|
|
1968
|
+
["lifetimeToken", getStringDecoder({ encoding: getBase58Decoder(), size: 32 })],
|
|
1969
|
+
["instructions", getArrayDecoder(getInstructionDecoder(), { size: getShortU16Decoder() })],
|
|
2036
1970
|
["addressTableLookups", getAddressTableLookupArrayDecoder()]
|
|
2037
1971
|
];
|
|
2038
1972
|
}
|
|
2039
1973
|
function getAddressTableLookupArrayEncoder() {
|
|
2040
|
-
return getArrayEncoder(getAddressTableLookupEncoder(), {
|
|
2041
|
-
description: addressTableLookupsDescription,
|
|
2042
|
-
size: getShortU16Encoder()
|
|
2043
|
-
});
|
|
1974
|
+
return getArrayEncoder(getAddressTableLookupEncoder(), { size: getShortU16Encoder() });
|
|
2044
1975
|
}
|
|
2045
1976
|
function getAddressTableLookupArrayDecoder() {
|
|
2046
|
-
return getArrayDecoder(getAddressTableLookupDecoder(), {
|
|
2047
|
-
description: addressTableLookupsDescription,
|
|
2048
|
-
size: getShortU16Decoder()
|
|
2049
|
-
});
|
|
1977
|
+
return getArrayDecoder(getAddressTableLookupDecoder(), { size: getShortU16Decoder() });
|
|
2050
1978
|
}
|
|
2051
|
-
var messageDescription = "The wire format of a Solana transaction message" ;
|
|
2052
1979
|
function getCompiledMessageEncoder() {
|
|
2053
|
-
return {
|
|
2054
|
-
|
|
2055
|
-
encode: (compiledMessage) => {
|
|
1980
|
+
return createEncoder({
|
|
1981
|
+
getSizeFromValue: (compiledMessage) => {
|
|
2056
1982
|
if (compiledMessage.version === "legacy") {
|
|
2057
|
-
return getCompiledMessageLegacyEncoder().
|
|
1983
|
+
return getCompiledMessageLegacyEncoder().getSizeFromValue(compiledMessage);
|
|
2058
1984
|
} else {
|
|
2059
|
-
return getCompiledMessageVersionedEncoder().
|
|
1985
|
+
return getCompiledMessageVersionedEncoder().getSizeFromValue(compiledMessage);
|
|
2060
1986
|
}
|
|
2061
1987
|
},
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
1988
|
+
write: (compiledMessage, bytes, offset) => {
|
|
1989
|
+
if (compiledMessage.version === "legacy") {
|
|
1990
|
+
return getCompiledMessageLegacyEncoder().write(compiledMessage, bytes, offset);
|
|
1991
|
+
} else {
|
|
1992
|
+
return getCompiledMessageVersionedEncoder().write(compiledMessage, bytes, offset);
|
|
1993
|
+
}
|
|
1994
|
+
}
|
|
1995
|
+
});
|
|
2065
1996
|
}
|
|
2066
1997
|
function getCompiledMessageDecoder() {
|
|
2067
|
-
return mapDecoder(
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
}),
|
|
2071
|
-
({ addressTableLookups, ...restOfMessage }) => {
|
|
2072
|
-
if (restOfMessage.version === "legacy" || !(addressTableLookups == null ? void 0 : addressTableLookups.length)) {
|
|
2073
|
-
return restOfMessage;
|
|
2074
|
-
}
|
|
2075
|
-
return { ...restOfMessage, addressTableLookups };
|
|
1998
|
+
return mapDecoder(getStructDecoder(getPreludeStructDecoderTuple()), ({ addressTableLookups, ...restOfMessage }) => {
|
|
1999
|
+
if (restOfMessage.version === "legacy" || !(addressTableLookups == null ? void 0 : addressTableLookups.length)) {
|
|
2000
|
+
return restOfMessage;
|
|
2076
2001
|
}
|
|
2077
|
-
|
|
2002
|
+
return { ...restOfMessage, addressTableLookups };
|
|
2003
|
+
});
|
|
2078
2004
|
}
|
|
2079
2005
|
function getCompiledMessageCodec() {
|
|
2080
2006
|
return combineCodec(getCompiledMessageEncoder(), getCompiledMessageDecoder());
|
|
@@ -2207,44 +2133,22 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2207
2133
|
(tx) => compiledTransaction.signatures.length ? { ...tx, signatures } : tx
|
|
2208
2134
|
);
|
|
2209
2135
|
}
|
|
2210
|
-
var signaturesDescription = "A compact array of 64-byte, base-64 encoded Ed25519 signatures" ;
|
|
2211
|
-
var transactionDescription = "The wire format of a Solana transaction" ;
|
|
2212
2136
|
function getCompiledTransactionEncoder() {
|
|
2213
|
-
return getStructEncoder(
|
|
2214
|
-
[
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
getArrayEncoder(getBytesEncoder({ size: 64 }), {
|
|
2218
|
-
description: signaturesDescription,
|
|
2219
|
-
size: getShortU16Encoder()
|
|
2220
|
-
})
|
|
2221
|
-
],
|
|
2222
|
-
["compiledMessage", getCompiledMessageEncoder()]
|
|
2223
|
-
],
|
|
2224
|
-
{
|
|
2225
|
-
description: transactionDescription
|
|
2226
|
-
}
|
|
2227
|
-
);
|
|
2228
|
-
}
|
|
2229
|
-
function getSignatureDecoder() {
|
|
2230
|
-
return mapDecoder(getBytesDecoder({ size: 64 }), (bytes) => bytes);
|
|
2137
|
+
return getStructEncoder([
|
|
2138
|
+
["signatures", getArrayEncoder(getBytesEncoder({ size: 64 }), { size: getShortU16Encoder() })],
|
|
2139
|
+
["compiledMessage", getCompiledMessageEncoder()]
|
|
2140
|
+
]);
|
|
2231
2141
|
}
|
|
2232
2142
|
function getCompiledTransactionDecoder() {
|
|
2233
|
-
return getStructDecoder(
|
|
2143
|
+
return getStructDecoder([
|
|
2234
2144
|
[
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
size: getShortU16Decoder()
|
|
2240
|
-
})
|
|
2241
|
-
],
|
|
2242
|
-
["compiledMessage", getCompiledMessageDecoder()]
|
|
2145
|
+
"signatures",
|
|
2146
|
+
getArrayDecoder(getBytesDecoder({ size: 64 }), {
|
|
2147
|
+
size: getShortU16Decoder()
|
|
2148
|
+
})
|
|
2243
2149
|
],
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
}
|
|
2247
|
-
);
|
|
2150
|
+
["compiledMessage", getCompiledMessageDecoder()]
|
|
2151
|
+
]);
|
|
2248
2152
|
}
|
|
2249
2153
|
function getTransactionEncoder() {
|
|
2250
2154
|
return mapEncoder(getCompiledTransactionEncoder(), getCompiledTransaction);
|
|
@@ -2268,7 +2172,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2268
2172
|
"Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
|
|
2269
2173
|
);
|
|
2270
2174
|
}
|
|
2271
|
-
const transactionSignature = base58Decoder.decode(signatureBytes)
|
|
2175
|
+
const transactionSignature = base58Decoder.decode(signatureBytes);
|
|
2272
2176
|
return transactionSignature;
|
|
2273
2177
|
}
|
|
2274
2178
|
async function partiallySignTransaction(keyPairs, transaction) {
|
|
@@ -2310,7 +2214,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2310
2214
|
}
|
|
2311
2215
|
function getBase64EncodedWireTransaction(transaction) {
|
|
2312
2216
|
const wireTransactionBytes = getTransactionEncoder().encode(transaction);
|
|
2313
|
-
return getBase64Decoder().decode(wireTransactionBytes)
|
|
2217
|
+
return getBase64Decoder().decode(wireTransactionBytes);
|
|
2314
2218
|
}
|
|
2315
2219
|
|
|
2316
2220
|
// src/airdrop.ts
|
|
@@ -3927,7 +3831,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
3927
3831
|
function getNonceFromAccountData([base64EncodedBytes]) {
|
|
3928
3832
|
const data = base64Encoder.encode(base64EncodedBytes);
|
|
3929
3833
|
const nonceValueBytes = data.slice(NONCE_VALUE_OFFSET, NONCE_VALUE_OFFSET + 32);
|
|
3930
|
-
return base58Decoder2.decode(nonceValueBytes)
|
|
3834
|
+
return base58Decoder2.decode(nonceValueBytes);
|
|
3931
3835
|
}
|
|
3932
3836
|
const nonceAccountDidAdvancePromise = (async () => {
|
|
3933
3837
|
for await (const accountNotification of accountNotifications) {
|
|
@@ -4161,6 +4065,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
4161
4065
|
exports.assertIsSignature = assertIsSignature;
|
|
4162
4066
|
exports.assertIsStringifiedBigInt = assertIsStringifiedBigInt;
|
|
4163
4067
|
exports.assertIsStringifiedNumber = assertIsStringifiedNumber;
|
|
4068
|
+
exports.assertIsTransactionWithBlockhashLifetime = assertIsTransactionWithBlockhashLifetime;
|
|
4164
4069
|
exports.assertIsUnixTimestamp = assertIsUnixTimestamp;
|
|
4165
4070
|
exports.assertTransactionIsFullySigned = assertTransactionIsFullySigned;
|
|
4166
4071
|
exports.commitmentComparator = commitmentComparator;
|
|
@@ -4175,6 +4080,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
4175
4080
|
exports.createDefaultRpcTransport = createDefaultRpcTransport;
|
|
4176
4081
|
exports.createDefaultTransactionSender = createDefaultTransactionSender;
|
|
4177
4082
|
exports.createNonceInvalidationPromiseFactory = createNonceInvalidationPromiseFactory;
|
|
4083
|
+
exports.createPrivateKeyFromBytes = createPrivateKeyFromBytes;
|
|
4178
4084
|
exports.createRecentSignatureConfirmationPromiseFactory = createRecentSignatureConfirmationPromiseFactory;
|
|
4179
4085
|
exports.createSolanaRpc = createSolanaRpc;
|
|
4180
4086
|
exports.createSolanaRpcSubscriptions = createSolanaRpcSubscriptions;
|