@solana/transactions 2.0.0-experimental.a23ca33 → 2.0.0-experimental.a293578
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 +1 -43
- package/dist/index.browser.cjs +150 -188
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +149 -191
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +436 -431
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +149 -189
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +150 -188
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +149 -189
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +22 -20
- package/dist/types/accounts.d.ts +2 -2
- package/dist/types/accounts.d.ts.map +1 -1
- package/dist/types/compilable-transaction.d.ts +3 -2
- package/dist/types/compilable-transaction.d.ts.map +1 -1
- package/dist/types/compile-address-table-lookups.d.ts +2 -2
- package/dist/types/compile-address-table-lookups.d.ts.map +1 -1
- package/dist/types/compile-static-accounts.d.ts +2 -2
- package/dist/types/compile-static-accounts.d.ts.map +1 -1
- package/dist/types/compile-transaction.d.ts +2 -2
- package/dist/types/compile-transaction.d.ts.map +1 -1
- package/dist/types/durable-nonce.d.ts +3 -3
- package/dist/types/durable-nonce.d.ts.map +1 -1
- package/dist/types/fee-payer.d.ts +4 -4
- package/dist/types/fee-payer.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/serializers/index.d.ts +1 -0
- package/dist/types/serializers/index.d.ts.map +1 -1
- package/dist/types/signatures.d.ts +6 -11
- package/dist/types/signatures.d.ts.map +1 -1
- package/dist/types/types.d.ts +6 -13
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/wire-transaction.d.ts.map +1 -1
- package/package.json +10 -10
|
@@ -57,7 +57,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
57
57
|
}
|
|
58
58
|
return {
|
|
59
59
|
decode: decoder.decode,
|
|
60
|
-
description: description
|
|
60
|
+
description: description != null ? description : encoder.description,
|
|
61
61
|
encode: encoder.encode,
|
|
62
62
|
fixedSize: encoder.fixedSize,
|
|
63
63
|
maxSize: encoder.maxSize
|
|
@@ -65,7 +65,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
65
65
|
}
|
|
66
66
|
function fixCodecHelper(data, fixedBytes, description) {
|
|
67
67
|
return {
|
|
68
|
-
description: description
|
|
68
|
+
description: description != null ? description : `fixed(${fixedBytes}, ${data.description})`,
|
|
69
69
|
fixedSize: fixedBytes,
|
|
70
70
|
maxSize: fixedBytes
|
|
71
71
|
};
|
|
@@ -121,14 +121,15 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
function sharedNumberFactory(input) {
|
|
124
|
+
var _a;
|
|
124
125
|
let littleEndian;
|
|
125
126
|
let defaultDescription = input.name;
|
|
126
127
|
if (input.size > 1) {
|
|
127
|
-
littleEndian = !("endian" in input.
|
|
128
|
+
littleEndian = !("endian" in input.config) || input.config.endian === 0;
|
|
128
129
|
defaultDescription += littleEndian ? "(le)" : "(be)";
|
|
129
130
|
}
|
|
130
131
|
return {
|
|
131
|
-
description: input.
|
|
132
|
+
description: (_a = input.config.description) != null ? _a : defaultDescription,
|
|
132
133
|
fixedSize: input.size,
|
|
133
134
|
littleEndian,
|
|
134
135
|
maxSize: input.size
|
|
@@ -165,74 +166,80 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
165
166
|
};
|
|
166
167
|
}
|
|
167
168
|
function toArrayBuffer(bytes, offset, length) {
|
|
168
|
-
const bytesOffset = bytes.byteOffset + (offset
|
|
169
|
-
const bytesLength = length
|
|
169
|
+
const bytesOffset = bytes.byteOffset + (offset != null ? offset : 0);
|
|
170
|
+
const bytesLength = length != null ? length : bytes.byteLength;
|
|
170
171
|
return bytes.buffer.slice(bytesOffset, bytesOffset + bytesLength);
|
|
171
172
|
}
|
|
172
|
-
var getShortU16Encoder = (
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
bytes[ii
|
|
173
|
+
var getShortU16Encoder = (config = {}) => {
|
|
174
|
+
var _a;
|
|
175
|
+
return {
|
|
176
|
+
description: (_a = config.description) != null ? _a : "shortU16",
|
|
177
|
+
encode: (value) => {
|
|
178
|
+
assertNumberIsBetweenForCodec("shortU16", 0, 65535, value);
|
|
179
|
+
const bytes = [0];
|
|
180
|
+
for (let ii = 0; ; ii += 1) {
|
|
181
|
+
const alignedValue = value >> ii * 7;
|
|
182
|
+
if (alignedValue === 0) {
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
const nextSevenBits = 127 & alignedValue;
|
|
186
|
+
bytes[ii] = nextSevenBits;
|
|
187
|
+
if (ii > 0) {
|
|
188
|
+
bytes[ii - 1] |= 128;
|
|
189
|
+
}
|
|
186
190
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
}
|
|
193
|
-
var getShortU16Decoder = (
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
191
|
+
return new Uint8Array(bytes);
|
|
192
|
+
},
|
|
193
|
+
fixedSize: null,
|
|
194
|
+
maxSize: 3
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
var getShortU16Decoder = (config = {}) => {
|
|
198
|
+
var _a;
|
|
199
|
+
return {
|
|
200
|
+
decode: (bytes, offset = 0) => {
|
|
201
|
+
let value = 0;
|
|
202
|
+
let byteCount = 0;
|
|
203
|
+
while (++byteCount) {
|
|
204
|
+
const byteIndex = byteCount - 1;
|
|
205
|
+
const currentByte = bytes[offset + byteIndex];
|
|
206
|
+
const nextSevenBits = 127 & currentByte;
|
|
207
|
+
value |= nextSevenBits << byteIndex * 7;
|
|
208
|
+
if ((currentByte & 128) === 0) {
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
204
211
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
}
|
|
212
|
-
var getU32Encoder = (
|
|
212
|
+
return [value, offset + byteCount];
|
|
213
|
+
},
|
|
214
|
+
description: (_a = config.description) != null ? _a : "shortU16",
|
|
215
|
+
fixedSize: null,
|
|
216
|
+
maxSize: 3
|
|
217
|
+
};
|
|
218
|
+
};
|
|
219
|
+
var getU32Encoder = (config = {}) => numberEncoderFactory({
|
|
220
|
+
config,
|
|
213
221
|
name: "u32",
|
|
214
|
-
options,
|
|
215
222
|
range: [0, Number("0xffffffff")],
|
|
216
223
|
set: (view, value, le) => view.setUint32(0, value, le),
|
|
217
224
|
size: 4
|
|
218
225
|
});
|
|
219
|
-
var getU32Decoder = (
|
|
226
|
+
var getU32Decoder = (config = {}) => numberDecoderFactory({
|
|
227
|
+
config,
|
|
220
228
|
get: (view, le) => view.getUint32(0, le),
|
|
221
229
|
name: "u32",
|
|
222
|
-
options,
|
|
223
230
|
size: 4
|
|
224
231
|
});
|
|
225
|
-
var getU8Encoder = (
|
|
232
|
+
var getU8Encoder = (config = {}) => numberEncoderFactory({
|
|
233
|
+
config,
|
|
226
234
|
name: "u8",
|
|
227
|
-
options,
|
|
228
235
|
range: [0, Number("0xff")],
|
|
229
236
|
set: (view, value) => view.setUint8(0, value),
|
|
230
237
|
size: 1
|
|
231
238
|
});
|
|
232
|
-
var getU8Decoder = (
|
|
239
|
+
var getU8Decoder = (config = {}) => numberDecoderFactory({
|
|
240
|
+
config,
|
|
233
241
|
get: (view) => view.getUint8(0),
|
|
234
242
|
name: "u8",
|
|
235
|
-
options,
|
|
236
243
|
size: 1
|
|
237
244
|
});
|
|
238
245
|
|
|
@@ -304,6 +311,20 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
304
311
|
var alphabet2 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
305
312
|
var getBase58Encoder = () => getBaseXEncoder(alphabet2);
|
|
306
313
|
var getBase58Decoder = () => getBaseXDecoder(alphabet2);
|
|
314
|
+
var getBase64Decoder = () => {
|
|
315
|
+
{
|
|
316
|
+
return {
|
|
317
|
+
decode(bytes, offset = 0) {
|
|
318
|
+
const slice = bytes.slice(offset);
|
|
319
|
+
const value = btoa(String.fromCharCode(...slice));
|
|
320
|
+
return [value, bytes.length];
|
|
321
|
+
},
|
|
322
|
+
description: `base64`,
|
|
323
|
+
fixedSize: null,
|
|
324
|
+
maxSize: null
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
};
|
|
307
328
|
var removeNullCharacters = (value) => (
|
|
308
329
|
// eslint-disable-next-line no-control-regex
|
|
309
330
|
value.replace(/\u0000/g, "")
|
|
@@ -331,10 +352,11 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
331
352
|
maxSize: null
|
|
332
353
|
};
|
|
333
354
|
};
|
|
334
|
-
var getStringEncoder = (
|
|
335
|
-
|
|
336
|
-
const
|
|
337
|
-
const
|
|
355
|
+
var getStringEncoder = (config = {}) => {
|
|
356
|
+
var _a, _b, _c;
|
|
357
|
+
const size = (_a = config.size) != null ? _a : getU32Encoder();
|
|
358
|
+
const encoding = (_b = config.encoding) != null ? _b : getUtf8Encoder();
|
|
359
|
+
const description = (_c = config.description) != null ? _c : `string(${encoding.description}; ${getSizeDescription(size)})`;
|
|
338
360
|
if (size === "variable") {
|
|
339
361
|
return { ...encoding, description };
|
|
340
362
|
}
|
|
@@ -352,10 +374,11 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
352
374
|
maxSize: null
|
|
353
375
|
};
|
|
354
376
|
};
|
|
355
|
-
var getStringDecoder = (
|
|
356
|
-
|
|
357
|
-
const
|
|
358
|
-
const
|
|
377
|
+
var getStringDecoder = (config = {}) => {
|
|
378
|
+
var _a, _b, _c;
|
|
379
|
+
const size = (_a = config.size) != null ? _a : getU32Decoder();
|
|
380
|
+
const encoding = (_b = config.encoding) != null ? _b : getUtf8Decoder();
|
|
381
|
+
const description = (_c = config.description) != null ? _c : `string(${encoding.description}; ${getSizeDescription(size)})`;
|
|
359
382
|
if (size === "variable") {
|
|
360
383
|
return { ...encoding, description };
|
|
361
384
|
}
|
|
@@ -491,9 +514,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
491
514
|
};
|
|
492
515
|
}
|
|
493
516
|
function isAdvanceNonceAccountInstruction(instruction) {
|
|
517
|
+
var _a;
|
|
494
518
|
return instruction.programAddress === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data
|
|
495
519
|
instruction.data != null && isAdvanceNonceAccountInstructionData(instruction.data) && // Test for exactly 3 accounts
|
|
496
|
-
instruction.accounts
|
|
520
|
+
((_a = instruction.accounts) == null ? void 0 : _a.length) === 3 && // First account is nonce account address
|
|
497
521
|
instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole.WRITABLE && // Second account is recent blockhashes sysvar
|
|
498
522
|
instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole.READONLY && // Third account is nonce authority account
|
|
499
523
|
instruction.accounts[2].address != null && isSignerRole(instruction.accounts[2].role);
|
|
@@ -575,184 +599,6 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
575
599
|
return out;
|
|
576
600
|
}
|
|
577
601
|
|
|
578
|
-
// ../codecs-data-structures/dist/index.browser.js
|
|
579
|
-
function sumCodecSizes(sizes) {
|
|
580
|
-
return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
|
|
581
|
-
}
|
|
582
|
-
function decodeArrayLikeCodecSize(size, childrenSizes, bytes, offset) {
|
|
583
|
-
if (typeof size === "number") {
|
|
584
|
-
return [size, offset];
|
|
585
|
-
}
|
|
586
|
-
if (typeof size === "object") {
|
|
587
|
-
return size.decode(bytes, offset);
|
|
588
|
-
}
|
|
589
|
-
if (size === "remainder") {
|
|
590
|
-
const childrenSize = sumCodecSizes(childrenSizes);
|
|
591
|
-
if (childrenSize === null) {
|
|
592
|
-
throw new Error('Codecs of "remainder" size must have fixed-size items.');
|
|
593
|
-
}
|
|
594
|
-
const remainder = bytes.slice(offset).length;
|
|
595
|
-
if (remainder % childrenSize !== 0) {
|
|
596
|
-
throw new Error(
|
|
597
|
-
`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.`
|
|
598
|
-
);
|
|
599
|
-
}
|
|
600
|
-
return [remainder / childrenSize, offset];
|
|
601
|
-
}
|
|
602
|
-
throw new Error(`Unrecognized array-like codec size: ${JSON.stringify(size)}`);
|
|
603
|
-
}
|
|
604
|
-
function getArrayLikeCodecSizeDescription(size) {
|
|
605
|
-
return typeof size === "object" ? size.description : `${size}`;
|
|
606
|
-
}
|
|
607
|
-
function getArrayLikeCodecSizeFromChildren(size, childrenSizes) {
|
|
608
|
-
if (typeof size !== "number")
|
|
609
|
-
return null;
|
|
610
|
-
if (size === 0)
|
|
611
|
-
return 0;
|
|
612
|
-
const childrenSize = sumCodecSizes(childrenSizes);
|
|
613
|
-
return childrenSize === null ? null : childrenSize * size;
|
|
614
|
-
}
|
|
615
|
-
function getArrayLikeCodecSizePrefix(size, realSize) {
|
|
616
|
-
return typeof size === "object" ? size.encode(realSize) : new Uint8Array();
|
|
617
|
-
}
|
|
618
|
-
function assertValidNumberOfItemsForCodec(codecDescription, expected, actual) {
|
|
619
|
-
if (expected !== actual) {
|
|
620
|
-
throw new Error(`Expected [${codecDescription}] to have ${expected} items, got ${actual}.`);
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
function arrayCodecHelper(item, size, description) {
|
|
624
|
-
if (size === "remainder" && item.fixedSize === null) {
|
|
625
|
-
throw new Error('Codecs of "remainder" size must have fixed-size items.');
|
|
626
|
-
}
|
|
627
|
-
return {
|
|
628
|
-
description: description ?? `array(${item.description}; ${getArrayLikeCodecSizeDescription(size)})`,
|
|
629
|
-
fixedSize: getArrayLikeCodecSizeFromChildren(size, [item.fixedSize]),
|
|
630
|
-
maxSize: getArrayLikeCodecSizeFromChildren(size, [item.maxSize])
|
|
631
|
-
};
|
|
632
|
-
}
|
|
633
|
-
function getArrayEncoder(item, options = {}) {
|
|
634
|
-
const size = options.size ?? getU32Encoder();
|
|
635
|
-
return {
|
|
636
|
-
...arrayCodecHelper(item, size, options.description),
|
|
637
|
-
encode: (value) => {
|
|
638
|
-
if (typeof size === "number") {
|
|
639
|
-
assertValidNumberOfItemsForCodec("array", size, value.length);
|
|
640
|
-
}
|
|
641
|
-
return mergeBytes([getArrayLikeCodecSizePrefix(size, value.length), ...value.map((v) => item.encode(v))]);
|
|
642
|
-
}
|
|
643
|
-
};
|
|
644
|
-
}
|
|
645
|
-
function getArrayDecoder(item, options = {}) {
|
|
646
|
-
const size = options.size ?? getU32Decoder();
|
|
647
|
-
return {
|
|
648
|
-
...arrayCodecHelper(item, size, options.description),
|
|
649
|
-
decode: (bytes, offset = 0) => {
|
|
650
|
-
if (typeof size === "object" && bytes.slice(offset).length === 0) {
|
|
651
|
-
return [[], offset];
|
|
652
|
-
}
|
|
653
|
-
const [resolvedSize, newOffset] = decodeArrayLikeCodecSize(size, [item.fixedSize], bytes, offset);
|
|
654
|
-
offset = newOffset;
|
|
655
|
-
const values = [];
|
|
656
|
-
for (let i = 0; i < resolvedSize; i += 1) {
|
|
657
|
-
const [value, newOffset2] = item.decode(bytes, offset);
|
|
658
|
-
values.push(value);
|
|
659
|
-
offset = newOffset2;
|
|
660
|
-
}
|
|
661
|
-
return [values, offset];
|
|
662
|
-
}
|
|
663
|
-
};
|
|
664
|
-
}
|
|
665
|
-
function getBytesEncoder(options = {}) {
|
|
666
|
-
const size = options.size ?? "variable";
|
|
667
|
-
const sizeDescription = typeof size === "object" ? size.description : `${size}`;
|
|
668
|
-
const description = options.description ?? `bytes(${sizeDescription})`;
|
|
669
|
-
const byteEncoder = {
|
|
670
|
-
description,
|
|
671
|
-
encode: (value) => value,
|
|
672
|
-
fixedSize: null,
|
|
673
|
-
maxSize: null
|
|
674
|
-
};
|
|
675
|
-
if (size === "variable") {
|
|
676
|
-
return byteEncoder;
|
|
677
|
-
}
|
|
678
|
-
if (typeof size === "number") {
|
|
679
|
-
return fixEncoder(byteEncoder, size, description);
|
|
680
|
-
}
|
|
681
|
-
return {
|
|
682
|
-
...byteEncoder,
|
|
683
|
-
encode: (value) => {
|
|
684
|
-
const contentBytes = byteEncoder.encode(value);
|
|
685
|
-
const lengthBytes = size.encode(contentBytes.length);
|
|
686
|
-
return mergeBytes([lengthBytes, contentBytes]);
|
|
687
|
-
}
|
|
688
|
-
};
|
|
689
|
-
}
|
|
690
|
-
function getBytesDecoder(options = {}) {
|
|
691
|
-
const size = options.size ?? "variable";
|
|
692
|
-
const sizeDescription = typeof size === "object" ? size.description : `${size}`;
|
|
693
|
-
const description = options.description ?? `bytes(${sizeDescription})`;
|
|
694
|
-
const byteDecoder = {
|
|
695
|
-
decode: (bytes, offset = 0) => {
|
|
696
|
-
const slice = bytes.slice(offset);
|
|
697
|
-
return [slice, offset + slice.length];
|
|
698
|
-
},
|
|
699
|
-
description,
|
|
700
|
-
fixedSize: null,
|
|
701
|
-
maxSize: null
|
|
702
|
-
};
|
|
703
|
-
if (size === "variable") {
|
|
704
|
-
return byteDecoder;
|
|
705
|
-
}
|
|
706
|
-
if (typeof size === "number") {
|
|
707
|
-
return fixDecoder(byteDecoder, size, description);
|
|
708
|
-
}
|
|
709
|
-
return {
|
|
710
|
-
...byteDecoder,
|
|
711
|
-
decode: (bytes, offset = 0) => {
|
|
712
|
-
assertByteArrayIsNotEmptyForCodec("bytes", bytes, offset);
|
|
713
|
-
const [lengthBigInt, lengthOffset] = size.decode(bytes, offset);
|
|
714
|
-
const length = Number(lengthBigInt);
|
|
715
|
-
offset = lengthOffset;
|
|
716
|
-
const contentBytes = bytes.slice(offset, offset + length);
|
|
717
|
-
assertByteArrayHasEnoughBytesForCodec("bytes", length, contentBytes);
|
|
718
|
-
const [value, contentOffset] = byteDecoder.decode(contentBytes);
|
|
719
|
-
offset += contentOffset;
|
|
720
|
-
return [value, offset];
|
|
721
|
-
}
|
|
722
|
-
};
|
|
723
|
-
}
|
|
724
|
-
function structCodecHelper(fields, description) {
|
|
725
|
-
const fieldDescriptions = fields.map(([name, codec]) => `${String(name)}: ${codec.description}`).join(", ");
|
|
726
|
-
return {
|
|
727
|
-
description: description ?? `struct(${fieldDescriptions})`,
|
|
728
|
-
fixedSize: sumCodecSizes(fields.map(([, field]) => field.fixedSize)),
|
|
729
|
-
maxSize: sumCodecSizes(fields.map(([, field]) => field.maxSize))
|
|
730
|
-
};
|
|
731
|
-
}
|
|
732
|
-
function getStructEncoder(fields, options = {}) {
|
|
733
|
-
return {
|
|
734
|
-
...structCodecHelper(fields, options.description),
|
|
735
|
-
encode: (struct) => {
|
|
736
|
-
const fieldBytes = fields.map(([key, codec]) => codec.encode(struct[key]));
|
|
737
|
-
return mergeBytes(fieldBytes);
|
|
738
|
-
}
|
|
739
|
-
};
|
|
740
|
-
}
|
|
741
|
-
function getStructDecoder(fields, options = {}) {
|
|
742
|
-
return {
|
|
743
|
-
...structCodecHelper(fields, options.description),
|
|
744
|
-
decode: (bytes, offset = 0) => {
|
|
745
|
-
const struct = {};
|
|
746
|
-
fields.forEach(([key, codec]) => {
|
|
747
|
-
const [value, newOffset] = codec.decode(bytes, offset);
|
|
748
|
-
offset = newOffset;
|
|
749
|
-
struct[key] = value;
|
|
750
|
-
});
|
|
751
|
-
return [struct, offset];
|
|
752
|
-
}
|
|
753
|
-
};
|
|
754
|
-
}
|
|
755
|
-
|
|
756
602
|
// ../assertions/dist/index.browser.js
|
|
757
603
|
function assertIsSecureContext() {
|
|
758
604
|
if (!globalThis.isSecureContext) {
|
|
@@ -762,14 +608,16 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
762
608
|
}
|
|
763
609
|
}
|
|
764
610
|
async function assertKeyExporterIsAvailable() {
|
|
611
|
+
var _a;
|
|
765
612
|
assertIsSecureContext();
|
|
766
|
-
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle
|
|
613
|
+
if (typeof globalThis.crypto === "undefined" || typeof ((_a = globalThis.crypto.subtle) == null ? void 0 : _a.exportKey) !== "function") {
|
|
767
614
|
throw new Error("No key export implementation could be found");
|
|
768
615
|
}
|
|
769
616
|
}
|
|
770
617
|
async function assertSigningCapabilityIsAvailable() {
|
|
618
|
+
var _a;
|
|
771
619
|
assertIsSecureContext();
|
|
772
|
-
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle
|
|
620
|
+
if (typeof globalThis.crypto === "undefined" || typeof ((_a = globalThis.crypto.subtle) == null ? void 0 : _a.sign) !== "function") {
|
|
773
621
|
throw new Error("No signing implementation could be found");
|
|
774
622
|
}
|
|
775
623
|
}
|
|
@@ -787,35 +635,36 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
787
635
|
memoizedBase58Decoder = getBase58Decoder();
|
|
788
636
|
return memoizedBase58Decoder;
|
|
789
637
|
}
|
|
790
|
-
function assertIsAddress(
|
|
638
|
+
function assertIsAddress(putativeAddress) {
|
|
791
639
|
try {
|
|
792
640
|
if (
|
|
793
641
|
// Lowest address (32 bytes of zeroes)
|
|
794
|
-
|
|
795
|
-
|
|
642
|
+
putativeAddress.length < 32 || // Highest address (32 bytes of 255)
|
|
643
|
+
putativeAddress.length > 44
|
|
796
644
|
) {
|
|
797
645
|
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
798
646
|
}
|
|
799
|
-
const
|
|
800
|
-
const bytes =
|
|
647
|
+
const base58Encoder2 = getMemoizedBase58Encoder();
|
|
648
|
+
const bytes = base58Encoder2.encode(putativeAddress);
|
|
801
649
|
const numBytes = bytes.byteLength;
|
|
802
650
|
if (numBytes !== 32) {
|
|
803
651
|
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
804
652
|
}
|
|
805
653
|
} catch (e2) {
|
|
806
|
-
throw new Error(`\`${
|
|
654
|
+
throw new Error(`\`${putativeAddress}\` is not a base-58 encoded address`, {
|
|
807
655
|
cause: e2
|
|
808
656
|
});
|
|
809
657
|
}
|
|
810
658
|
}
|
|
811
|
-
function address(
|
|
812
|
-
assertIsAddress(
|
|
813
|
-
return
|
|
659
|
+
function address(putativeAddress) {
|
|
660
|
+
assertIsAddress(putativeAddress);
|
|
661
|
+
return putativeAddress;
|
|
814
662
|
}
|
|
815
663
|
function getAddressEncoder(config) {
|
|
664
|
+
var _a;
|
|
816
665
|
return mapEncoder(
|
|
817
666
|
getStringEncoder({
|
|
818
|
-
description: config
|
|
667
|
+
description: (_a = config == null ? void 0 : config.description) != null ? _a : "Address",
|
|
819
668
|
encoding: getMemoizedBase58Encoder(),
|
|
820
669
|
size: 32
|
|
821
670
|
}),
|
|
@@ -823,8 +672,9 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
823
672
|
);
|
|
824
673
|
}
|
|
825
674
|
function getAddressDecoder(config) {
|
|
675
|
+
var _a;
|
|
826
676
|
return getStringDecoder({
|
|
827
|
-
description: config
|
|
677
|
+
description: (_a = config == null ? void 0 : config.description) != null ? _a : "Address",
|
|
828
678
|
encoding: getMemoizedBase58Decoder(),
|
|
829
679
|
size: 32
|
|
830
680
|
});
|
|
@@ -851,7 +701,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
851
701
|
|
|
852
702
|
// src/accounts.ts
|
|
853
703
|
function upsert(addressMap, address2, update) {
|
|
854
|
-
|
|
704
|
+
var _a;
|
|
705
|
+
addressMap[address2] = update((_a = addressMap[address2]) != null ? _a : { role: AccountRole.READONLY });
|
|
855
706
|
}
|
|
856
707
|
var TYPE = Symbol("AddressMapTypeProperty");
|
|
857
708
|
function getAddressMapFromInstructions(feePayer, instructions) {
|
|
@@ -1119,139 +970,186 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1119
970
|
};
|
|
1120
971
|
}
|
|
1121
972
|
|
|
1122
|
-
//
|
|
1123
|
-
function
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
973
|
+
// ../codecs-data-structures/dist/index.browser.js
|
|
974
|
+
function sumCodecSizes(sizes) {
|
|
975
|
+
return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
|
|
976
|
+
}
|
|
977
|
+
function decodeArrayLikeCodecSize(size, childrenSizes, bytes, offset) {
|
|
978
|
+
if (typeof size === "number") {
|
|
979
|
+
return [size, offset];
|
|
980
|
+
}
|
|
981
|
+
if (typeof size === "object") {
|
|
982
|
+
return size.decode(bytes, offset);
|
|
983
|
+
}
|
|
984
|
+
if (size === "remainder") {
|
|
985
|
+
const childrenSize = sumCodecSizes(childrenSizes);
|
|
986
|
+
if (childrenSize === null) {
|
|
987
|
+
throw new Error('Codecs of "remainder" size must have fixed-size items.');
|
|
1130
988
|
}
|
|
1131
|
-
|
|
1132
|
-
|
|
989
|
+
const remainder = bytes.slice(offset).length;
|
|
990
|
+
if (remainder % childrenSize !== 0) {
|
|
991
|
+
throw new Error(
|
|
992
|
+
`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.`
|
|
993
|
+
);
|
|
994
|
+
}
|
|
995
|
+
return [remainder / childrenSize, offset];
|
|
1133
996
|
}
|
|
1134
|
-
|
|
1135
|
-
compiledMessage,
|
|
1136
|
-
signatures
|
|
1137
|
-
};
|
|
997
|
+
throw new Error(`Unrecognized array-like codec size: ${JSON.stringify(size)}`);
|
|
1138
998
|
}
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
function pipe(init, ...fns) {
|
|
1142
|
-
return fns.reduce((acc, fn) => fn(acc), init);
|
|
999
|
+
function getArrayLikeCodecSizeDescription(size) {
|
|
1000
|
+
return typeof size === "object" ? size.description : `${size}`;
|
|
1143
1001
|
}
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
const
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
}
|
|
1159
|
-
for (let i = 0; i < header.numReadonlySignerAccounts; i++) {
|
|
1160
|
-
accountMetas.push({
|
|
1161
|
-
address: message.staticAccounts[accountIndex],
|
|
1162
|
-
role: AccountRole.READONLY_SIGNER
|
|
1163
|
-
});
|
|
1164
|
-
accountIndex++;
|
|
1165
|
-
}
|
|
1166
|
-
for (let i = 0; i < numWritableNonSignerAccounts; i++) {
|
|
1167
|
-
accountMetas.push({
|
|
1168
|
-
address: message.staticAccounts[accountIndex],
|
|
1169
|
-
role: AccountRole.WRITABLE
|
|
1170
|
-
});
|
|
1171
|
-
accountIndex++;
|
|
1002
|
+
function getArrayLikeCodecSizeFromChildren(size, childrenSizes) {
|
|
1003
|
+
if (typeof size !== "number")
|
|
1004
|
+
return null;
|
|
1005
|
+
if (size === 0)
|
|
1006
|
+
return 0;
|
|
1007
|
+
const childrenSize = sumCodecSizes(childrenSizes);
|
|
1008
|
+
return childrenSize === null ? null : childrenSize * size;
|
|
1009
|
+
}
|
|
1010
|
+
function getArrayLikeCodecSizePrefix(size, realSize) {
|
|
1011
|
+
return typeof size === "object" ? size.encode(realSize) : new Uint8Array();
|
|
1012
|
+
}
|
|
1013
|
+
function assertValidNumberOfItemsForCodec(codecDescription, expected, actual) {
|
|
1014
|
+
if (expected !== actual) {
|
|
1015
|
+
throw new Error(`Expected [${codecDescription}] to have ${expected} items, got ${actual}.`);
|
|
1172
1016
|
}
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
});
|
|
1178
|
-
accountIndex++;
|
|
1017
|
+
}
|
|
1018
|
+
function arrayCodecHelper(item, size, description) {
|
|
1019
|
+
if (size === "remainder" && item.fixedSize === null) {
|
|
1020
|
+
throw new Error('Codecs of "remainder" size must have fixed-size items.');
|
|
1179
1021
|
}
|
|
1180
|
-
return
|
|
1022
|
+
return {
|
|
1023
|
+
description: description != null ? description : `array(${item.description}; ${getArrayLikeCodecSizeDescription(size)})`,
|
|
1024
|
+
fixedSize: getArrayLikeCodecSizeFromChildren(size, [item.fixedSize]),
|
|
1025
|
+
maxSize: getArrayLikeCodecSizeFromChildren(size, [item.maxSize])
|
|
1026
|
+
};
|
|
1181
1027
|
}
|
|
1182
|
-
function
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1028
|
+
function getArrayEncoder(item, config = {}) {
|
|
1029
|
+
var _a;
|
|
1030
|
+
const size = (_a = config.size) != null ? _a : getU32Encoder();
|
|
1031
|
+
return {
|
|
1032
|
+
...arrayCodecHelper(item, size, config.description),
|
|
1033
|
+
encode: (value) => {
|
|
1034
|
+
if (typeof size === "number") {
|
|
1035
|
+
assertValidNumberOfItemsForCodec("array", size, value.length);
|
|
1036
|
+
}
|
|
1037
|
+
return mergeBytes([getArrayLikeCodecSizePrefix(size, value.length), ...value.map((v) => item.encode(v))]);
|
|
1038
|
+
}
|
|
1039
|
+
};
|
|
1040
|
+
}
|
|
1041
|
+
function getArrayDecoder(item, config = {}) {
|
|
1042
|
+
var _a;
|
|
1043
|
+
const size = (_a = config.size) != null ? _a : getU32Decoder();
|
|
1044
|
+
return {
|
|
1045
|
+
...arrayCodecHelper(item, size, config.description),
|
|
1046
|
+
decode: (bytes, offset = 0) => {
|
|
1047
|
+
if (typeof size === "object" && bytes.slice(offset).length === 0) {
|
|
1048
|
+
return [[], offset];
|
|
1049
|
+
}
|
|
1050
|
+
const [resolvedSize, newOffset] = decodeArrayLikeCodecSize(size, [item.fixedSize], bytes, offset);
|
|
1051
|
+
offset = newOffset;
|
|
1052
|
+
const values = [];
|
|
1053
|
+
for (let i = 0; i < resolvedSize; i += 1) {
|
|
1054
|
+
const [value, newOffset2] = item.decode(bytes, offset);
|
|
1055
|
+
values.push(value);
|
|
1056
|
+
offset = newOffset2;
|
|
1057
|
+
}
|
|
1058
|
+
return [values, offset];
|
|
1059
|
+
}
|
|
1060
|
+
};
|
|
1061
|
+
}
|
|
1062
|
+
function getBytesEncoder(config = {}) {
|
|
1063
|
+
var _a, _b;
|
|
1064
|
+
const size = (_a = config.size) != null ? _a : "variable";
|
|
1065
|
+
const sizeDescription = typeof size === "object" ? size.description : `${size}`;
|
|
1066
|
+
const description = (_b = config.description) != null ? _b : `bytes(${sizeDescription})`;
|
|
1067
|
+
const byteEncoder = {
|
|
1068
|
+
description,
|
|
1069
|
+
encode: (value) => value,
|
|
1070
|
+
fixedSize: null,
|
|
1071
|
+
maxSize: null
|
|
1072
|
+
};
|
|
1073
|
+
if (size === "variable") {
|
|
1074
|
+
return byteEncoder;
|
|
1075
|
+
}
|
|
1076
|
+
if (typeof size === "number") {
|
|
1077
|
+
return fixEncoder(byteEncoder, size, description);
|
|
1186
1078
|
}
|
|
1187
|
-
const accounts = instruction.accountIndices?.map((accountIndex) => accountMetas[accountIndex]);
|
|
1188
|
-
const { data } = instruction;
|
|
1189
1079
|
return {
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1080
|
+
...byteEncoder,
|
|
1081
|
+
encode: (value) => {
|
|
1082
|
+
const contentBytes = byteEncoder.encode(value);
|
|
1083
|
+
const lengthBytes = size.encode(contentBytes.length);
|
|
1084
|
+
return mergeBytes([lengthBytes, contentBytes]);
|
|
1085
|
+
}
|
|
1193
1086
|
};
|
|
1194
1087
|
}
|
|
1195
|
-
function
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1088
|
+
function getBytesDecoder(config = {}) {
|
|
1089
|
+
var _a, _b;
|
|
1090
|
+
const size = (_a = config.size) != null ? _a : "variable";
|
|
1091
|
+
const sizeDescription = typeof size === "object" ? size.description : `${size}`;
|
|
1092
|
+
const description = (_b = config.description) != null ? _b : `bytes(${sizeDescription})`;
|
|
1093
|
+
const byteDecoder = {
|
|
1094
|
+
decode: (bytes, offset = 0) => {
|
|
1095
|
+
const slice = bytes.slice(offset);
|
|
1096
|
+
return [slice, offset + slice.length];
|
|
1097
|
+
},
|
|
1098
|
+
description,
|
|
1099
|
+
fixedSize: null,
|
|
1100
|
+
maxSize: null
|
|
1101
|
+
};
|
|
1102
|
+
if (size === "variable") {
|
|
1103
|
+
return byteDecoder;
|
|
1104
|
+
}
|
|
1105
|
+
if (typeof size === "number") {
|
|
1106
|
+
return fixDecoder(byteDecoder, size, description);
|
|
1212
1107
|
}
|
|
1108
|
+
return {
|
|
1109
|
+
...byteDecoder,
|
|
1110
|
+
decode: (bytes, offset = 0) => {
|
|
1111
|
+
assertByteArrayIsNotEmptyForCodec("bytes", bytes, offset);
|
|
1112
|
+
const [lengthBigInt, lengthOffset] = size.decode(bytes, offset);
|
|
1113
|
+
const length = Number(lengthBigInt);
|
|
1114
|
+
offset = lengthOffset;
|
|
1115
|
+
const contentBytes = bytes.slice(offset, offset + length);
|
|
1116
|
+
assertByteArrayHasEnoughBytesForCodec("bytes", length, contentBytes);
|
|
1117
|
+
const [value, contentOffset] = byteDecoder.decode(contentBytes);
|
|
1118
|
+
offset += contentOffset;
|
|
1119
|
+
return [value, offset];
|
|
1120
|
+
}
|
|
1121
|
+
};
|
|
1213
1122
|
}
|
|
1214
|
-
function
|
|
1215
|
-
const {
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
if (allZeros)
|
|
1222
|
-
return acc;
|
|
1223
|
-
const address2 = staticAccounts[index];
|
|
1224
|
-
return { ...acc, [address2]: sig };
|
|
1225
|
-
}, {});
|
|
1123
|
+
function structCodecHelper(fields, description) {
|
|
1124
|
+
const fieldDescriptions = fields.map(([name, codec]) => `${String(name)}: ${codec.description}`).join(", ");
|
|
1125
|
+
return {
|
|
1126
|
+
description: description != null ? description : `struct(${fieldDescriptions})`,
|
|
1127
|
+
fixedSize: sumCodecSizes(fields.map(([, field]) => field.fixedSize)),
|
|
1128
|
+
maxSize: sumCodecSizes(fields.map(([, field]) => field.maxSize))
|
|
1129
|
+
};
|
|
1226
1130
|
}
|
|
1227
|
-
function
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
(tx) => instructions.reduce((acc, instruction) => {
|
|
1250
|
-
return appendTransactionInstruction(instruction, acc);
|
|
1251
|
-
}, tx),
|
|
1252
|
-
(tx) => "blockhash" in lifetimeConstraint ? setTransactionLifetimeUsingBlockhash(lifetimeConstraint, tx) : setTransactionLifetimeUsingDurableNonce(lifetimeConstraint, tx),
|
|
1253
|
-
(tx) => compiledTransaction.signatures.length ? { ...tx, signatures } : tx
|
|
1254
|
-
);
|
|
1131
|
+
function getStructEncoder(fields, config = {}) {
|
|
1132
|
+
return {
|
|
1133
|
+
...structCodecHelper(fields, config.description),
|
|
1134
|
+
encode: (struct) => {
|
|
1135
|
+
const fieldBytes = fields.map(([key, codec]) => codec.encode(struct[key]));
|
|
1136
|
+
return mergeBytes(fieldBytes);
|
|
1137
|
+
}
|
|
1138
|
+
};
|
|
1139
|
+
}
|
|
1140
|
+
function getStructDecoder(fields, config = {}) {
|
|
1141
|
+
return {
|
|
1142
|
+
...structCodecHelper(fields, config.description),
|
|
1143
|
+
decode: (bytes, offset = 0) => {
|
|
1144
|
+
const struct = {};
|
|
1145
|
+
fields.forEach(([key, codec]) => {
|
|
1146
|
+
const [value, newOffset] = codec.decode(bytes, offset);
|
|
1147
|
+
offset = newOffset;
|
|
1148
|
+
struct[key] = value;
|
|
1149
|
+
});
|
|
1150
|
+
return [struct, offset];
|
|
1151
|
+
}
|
|
1152
|
+
};
|
|
1255
1153
|
}
|
|
1256
1154
|
|
|
1257
1155
|
// src/serializers/address-table-lookup.ts
|
|
@@ -1323,7 +1221,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1323
1221
|
const encoder = getMemoizedU8Encoder();
|
|
1324
1222
|
return {
|
|
1325
1223
|
...encoder,
|
|
1326
|
-
description: description
|
|
1224
|
+
description: description != null ? description : encoder.description
|
|
1327
1225
|
};
|
|
1328
1226
|
}
|
|
1329
1227
|
var memoizedU8Decoder;
|
|
@@ -1336,7 +1234,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1336
1234
|
const decoder = getMemoizedU8Decoder();
|
|
1337
1235
|
return {
|
|
1338
1236
|
...decoder,
|
|
1339
|
-
description: description
|
|
1237
|
+
description: description != null ? description : decoder.description
|
|
1340
1238
|
};
|
|
1341
1239
|
}
|
|
1342
1240
|
var numSignerAccountsDescription = "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction" ;
|
|
@@ -1390,13 +1288,14 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1390
1288
|
]),
|
|
1391
1289
|
// Convert an instruction to have all fields defined
|
|
1392
1290
|
(instruction) => {
|
|
1291
|
+
var _a, _b;
|
|
1393
1292
|
if (instruction.accountIndices !== void 0 && instruction.data !== void 0) {
|
|
1394
1293
|
return instruction;
|
|
1395
1294
|
}
|
|
1396
1295
|
return {
|
|
1397
1296
|
...instruction,
|
|
1398
|
-
accountIndices: instruction.accountIndices
|
|
1399
|
-
data: instruction.data
|
|
1297
|
+
accountIndices: (_a = instruction.accountIndices) != null ? _a : [],
|
|
1298
|
+
data: (_b = instruction.data) != null ? _b : new Uint8Array(0)
|
|
1400
1299
|
};
|
|
1401
1300
|
}
|
|
1402
1301
|
);
|
|
@@ -1488,12 +1387,13 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1488
1387
|
["addressTableLookups", getAddressTableLookupArrayEncoder()]
|
|
1489
1388
|
]),
|
|
1490
1389
|
(value) => {
|
|
1390
|
+
var _a;
|
|
1491
1391
|
if (value.version === "legacy") {
|
|
1492
1392
|
return value;
|
|
1493
1393
|
}
|
|
1494
1394
|
return {
|
|
1495
1395
|
...value,
|
|
1496
|
-
addressTableLookups: value.addressTableLookups
|
|
1396
|
+
addressTableLookups: (_a = value.addressTableLookups) != null ? _a : []
|
|
1497
1397
|
};
|
|
1498
1398
|
}
|
|
1499
1399
|
);
|
|
@@ -1588,13 +1488,153 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1588
1488
|
description: messageDescription
|
|
1589
1489
|
}),
|
|
1590
1490
|
({ addressTableLookups, ...restOfMessage }) => {
|
|
1591
|
-
if (restOfMessage.version === "legacy" || !addressTableLookups
|
|
1491
|
+
if (restOfMessage.version === "legacy" || !(addressTableLookups == null ? void 0 : addressTableLookups.length)) {
|
|
1592
1492
|
return restOfMessage;
|
|
1593
1493
|
}
|
|
1594
1494
|
return { ...restOfMessage, addressTableLookups };
|
|
1595
1495
|
}
|
|
1596
1496
|
);
|
|
1597
1497
|
}
|
|
1498
|
+
function getCompiledMessageCodec() {
|
|
1499
|
+
return combineCodec(getCompiledMessageEncoder(), getCompiledMessageDecoder());
|
|
1500
|
+
}
|
|
1501
|
+
|
|
1502
|
+
// src/compile-transaction.ts
|
|
1503
|
+
function getCompiledTransaction(transaction) {
|
|
1504
|
+
var _a;
|
|
1505
|
+
const compiledMessage = compileMessage(transaction);
|
|
1506
|
+
let signatures;
|
|
1507
|
+
if ("signatures" in transaction) {
|
|
1508
|
+
signatures = [];
|
|
1509
|
+
for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
|
|
1510
|
+
signatures[ii] = (_a = transaction.signatures[compiledMessage.staticAccounts[ii]]) != null ? _a : new Uint8Array(Array(64).fill(0));
|
|
1511
|
+
}
|
|
1512
|
+
} else {
|
|
1513
|
+
signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
|
|
1514
|
+
}
|
|
1515
|
+
return {
|
|
1516
|
+
compiledMessage,
|
|
1517
|
+
signatures
|
|
1518
|
+
};
|
|
1519
|
+
}
|
|
1520
|
+
|
|
1521
|
+
// ../functional/dist/index.browser.js
|
|
1522
|
+
function pipe(init, ...fns) {
|
|
1523
|
+
return fns.reduce((acc, fn) => fn(acc), init);
|
|
1524
|
+
}
|
|
1525
|
+
|
|
1526
|
+
// src/decompile-transaction.ts
|
|
1527
|
+
function getAccountMetas(message) {
|
|
1528
|
+
const { header } = message;
|
|
1529
|
+
const numWritableSignerAccounts = header.numSignerAccounts - header.numReadonlySignerAccounts;
|
|
1530
|
+
const numWritableNonSignerAccounts = message.staticAccounts.length - header.numSignerAccounts - header.numReadonlyNonSignerAccounts;
|
|
1531
|
+
const accountMetas = [];
|
|
1532
|
+
let accountIndex = 0;
|
|
1533
|
+
for (let i = 0; i < numWritableSignerAccounts; i++) {
|
|
1534
|
+
accountMetas.push({
|
|
1535
|
+
address: message.staticAccounts[accountIndex],
|
|
1536
|
+
role: AccountRole.WRITABLE_SIGNER
|
|
1537
|
+
});
|
|
1538
|
+
accountIndex++;
|
|
1539
|
+
}
|
|
1540
|
+
for (let i = 0; i < header.numReadonlySignerAccounts; i++) {
|
|
1541
|
+
accountMetas.push({
|
|
1542
|
+
address: message.staticAccounts[accountIndex],
|
|
1543
|
+
role: AccountRole.READONLY_SIGNER
|
|
1544
|
+
});
|
|
1545
|
+
accountIndex++;
|
|
1546
|
+
}
|
|
1547
|
+
for (let i = 0; i < numWritableNonSignerAccounts; i++) {
|
|
1548
|
+
accountMetas.push({
|
|
1549
|
+
address: message.staticAccounts[accountIndex],
|
|
1550
|
+
role: AccountRole.WRITABLE
|
|
1551
|
+
});
|
|
1552
|
+
accountIndex++;
|
|
1553
|
+
}
|
|
1554
|
+
for (let i = 0; i < header.numReadonlyNonSignerAccounts; i++) {
|
|
1555
|
+
accountMetas.push({
|
|
1556
|
+
address: message.staticAccounts[accountIndex],
|
|
1557
|
+
role: AccountRole.READONLY
|
|
1558
|
+
});
|
|
1559
|
+
accountIndex++;
|
|
1560
|
+
}
|
|
1561
|
+
return accountMetas;
|
|
1562
|
+
}
|
|
1563
|
+
function convertInstruction(instruction, accountMetas) {
|
|
1564
|
+
var _a, _b;
|
|
1565
|
+
const programAddress = (_a = accountMetas[instruction.programAddressIndex]) == null ? void 0 : _a.address;
|
|
1566
|
+
if (!programAddress) {
|
|
1567
|
+
throw new Error(`Could not find program address at index ${instruction.programAddressIndex}`);
|
|
1568
|
+
}
|
|
1569
|
+
const accounts = (_b = instruction.accountIndices) == null ? void 0 : _b.map((accountIndex) => accountMetas[accountIndex]);
|
|
1570
|
+
const { data } = instruction;
|
|
1571
|
+
return {
|
|
1572
|
+
programAddress,
|
|
1573
|
+
...accounts && accounts.length ? { accounts } : {},
|
|
1574
|
+
...data && data.length ? { data } : {}
|
|
1575
|
+
};
|
|
1576
|
+
}
|
|
1577
|
+
function getLifetimeConstraint(messageLifetimeToken, firstInstruction, lastValidBlockHeight) {
|
|
1578
|
+
if (!firstInstruction || !isAdvanceNonceAccountInstruction(firstInstruction)) {
|
|
1579
|
+
return {
|
|
1580
|
+
blockhash: messageLifetimeToken,
|
|
1581
|
+
lastValidBlockHeight: lastValidBlockHeight != null ? lastValidBlockHeight : 2n ** 64n - 1n
|
|
1582
|
+
// U64 MAX
|
|
1583
|
+
};
|
|
1584
|
+
} else {
|
|
1585
|
+
const nonceAccountAddress = firstInstruction.accounts[0].address;
|
|
1586
|
+
assertIsAddress(nonceAccountAddress);
|
|
1587
|
+
const nonceAuthorityAddress = firstInstruction.accounts[2].address;
|
|
1588
|
+
assertIsAddress(nonceAuthorityAddress);
|
|
1589
|
+
return {
|
|
1590
|
+
nonce: messageLifetimeToken,
|
|
1591
|
+
nonceAccountAddress,
|
|
1592
|
+
nonceAuthorityAddress
|
|
1593
|
+
};
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
function convertSignatures(compiledTransaction) {
|
|
1597
|
+
const {
|
|
1598
|
+
compiledMessage: { staticAccounts },
|
|
1599
|
+
signatures
|
|
1600
|
+
} = compiledTransaction;
|
|
1601
|
+
return signatures.reduce((acc, sig, index) => {
|
|
1602
|
+
const allZeros = sig.every((byte) => byte === 0);
|
|
1603
|
+
if (allZeros)
|
|
1604
|
+
return acc;
|
|
1605
|
+
const address2 = staticAccounts[index];
|
|
1606
|
+
return { ...acc, [address2]: sig };
|
|
1607
|
+
}, {});
|
|
1608
|
+
}
|
|
1609
|
+
function decompileTransaction(compiledTransaction, lastValidBlockHeight) {
|
|
1610
|
+
const { compiledMessage } = compiledTransaction;
|
|
1611
|
+
if ("addressTableLookups" in compiledMessage && compiledMessage.addressTableLookups.length > 0) {
|
|
1612
|
+
throw new Error("Cannot convert transaction with addressTableLookups");
|
|
1613
|
+
}
|
|
1614
|
+
const feePayer = compiledMessage.staticAccounts[0];
|
|
1615
|
+
if (!feePayer)
|
|
1616
|
+
throw new Error("No fee payer set in CompiledTransaction");
|
|
1617
|
+
const accountMetas = getAccountMetas(compiledMessage);
|
|
1618
|
+
const instructions = compiledMessage.instructions.map(
|
|
1619
|
+
(compiledInstruction) => convertInstruction(compiledInstruction, accountMetas)
|
|
1620
|
+
);
|
|
1621
|
+
const firstInstruction = instructions[0];
|
|
1622
|
+
const lifetimeConstraint = getLifetimeConstraint(
|
|
1623
|
+
compiledMessage.lifetimeToken,
|
|
1624
|
+
firstInstruction,
|
|
1625
|
+
lastValidBlockHeight
|
|
1626
|
+
);
|
|
1627
|
+
const signatures = convertSignatures(compiledTransaction);
|
|
1628
|
+
return pipe(
|
|
1629
|
+
createTransaction({ version: compiledMessage.version }),
|
|
1630
|
+
(tx) => setTransactionFeePayer(feePayer, tx),
|
|
1631
|
+
(tx) => instructions.reduce((acc, instruction) => {
|
|
1632
|
+
return appendTransactionInstruction(instruction, acc);
|
|
1633
|
+
}, tx),
|
|
1634
|
+
(tx) => "blockhash" in lifetimeConstraint ? setTransactionLifetimeUsingBlockhash(lifetimeConstraint, tx) : setTransactionLifetimeUsingDurableNonce(lifetimeConstraint, tx),
|
|
1635
|
+
(tx) => compiledTransaction.signatures.length ? { ...tx, signatures } : tx
|
|
1636
|
+
);
|
|
1637
|
+
}
|
|
1598
1638
|
|
|
1599
1639
|
// src/serializers/transaction.ts
|
|
1600
1640
|
var signaturesDescription = "A compact array of 64-byte, base-64 encoded Ed25519 signatures" ;
|
|
@@ -1657,47 +1697,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1657
1697
|
}
|
|
1658
1698
|
|
|
1659
1699
|
// src/signatures.ts
|
|
1660
|
-
var base58Encoder2;
|
|
1661
1700
|
var base58Decoder;
|
|
1662
|
-
function assertIsTransactionSignature(putativeTransactionSignature) {
|
|
1663
|
-
if (!base58Encoder2)
|
|
1664
|
-
base58Encoder2 = getBase58Encoder();
|
|
1665
|
-
try {
|
|
1666
|
-
if (
|
|
1667
|
-
// Lowest value (64 bytes of zeroes)
|
|
1668
|
-
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
1669
|
-
putativeTransactionSignature.length > 88
|
|
1670
|
-
) {
|
|
1671
|
-
throw new Error("Expected input string to decode to a byte array of length 64.");
|
|
1672
|
-
}
|
|
1673
|
-
const bytes = base58Encoder2.encode(putativeTransactionSignature);
|
|
1674
|
-
const numBytes = bytes.byteLength;
|
|
1675
|
-
if (numBytes !== 64) {
|
|
1676
|
-
throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
|
|
1677
|
-
}
|
|
1678
|
-
} catch (e2) {
|
|
1679
|
-
throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, {
|
|
1680
|
-
cause: e2
|
|
1681
|
-
});
|
|
1682
|
-
}
|
|
1683
|
-
}
|
|
1684
|
-
function isTransactionSignature(putativeTransactionSignature) {
|
|
1685
|
-
if (!base58Encoder2)
|
|
1686
|
-
base58Encoder2 = getBase58Encoder();
|
|
1687
|
-
if (
|
|
1688
|
-
// Lowest value (64 bytes of zeroes)
|
|
1689
|
-
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
1690
|
-
putativeTransactionSignature.length > 88
|
|
1691
|
-
) {
|
|
1692
|
-
return false;
|
|
1693
|
-
}
|
|
1694
|
-
const bytes = base58Encoder2.encode(putativeTransactionSignature);
|
|
1695
|
-
const numBytes = bytes.byteLength;
|
|
1696
|
-
if (numBytes !== 64) {
|
|
1697
|
-
return false;
|
|
1698
|
-
}
|
|
1699
|
-
return true;
|
|
1700
|
-
}
|
|
1701
1701
|
function getSignatureFromTransaction(transaction) {
|
|
1702
1702
|
if (!base58Decoder)
|
|
1703
1703
|
base58Decoder = getBase58Decoder();
|
|
@@ -1707,10 +1707,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1707
1707
|
"Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
|
|
1708
1708
|
);
|
|
1709
1709
|
}
|
|
1710
|
-
const
|
|
1711
|
-
return
|
|
1710
|
+
const transactionSignature = base58Decoder.decode(signatureBytes)[0];
|
|
1711
|
+
return transactionSignature;
|
|
1712
1712
|
}
|
|
1713
|
-
async function
|
|
1713
|
+
async function partiallySignTransaction(keyPairs, transaction) {
|
|
1714
1714
|
const compiledMessage = compileMessage(transaction);
|
|
1715
1715
|
const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
|
|
1716
1716
|
const wireMessageBytes = getCompiledMessageEncoder().encode(compiledMessage);
|
|
@@ -1729,12 +1729,17 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1729
1729
|
Object.freeze(out);
|
|
1730
1730
|
return out;
|
|
1731
1731
|
}
|
|
1732
|
-
function
|
|
1733
|
-
|
|
1734
|
-
|
|
1732
|
+
async function signTransaction(keyPairs, transaction) {
|
|
1733
|
+
const out = await partiallySignTransaction(keyPairs, transaction);
|
|
1734
|
+
assertTransactionIsFullySigned(out);
|
|
1735
|
+
Object.freeze(out);
|
|
1736
|
+
return out;
|
|
1735
1737
|
}
|
|
1736
1738
|
function assertTransactionIsFullySigned(transaction) {
|
|
1737
|
-
const signerAddressesFromInstructions = transaction.instructions.flatMap((i) =>
|
|
1739
|
+
const signerAddressesFromInstructions = transaction.instructions.flatMap((i) => {
|
|
1740
|
+
var _a, _b;
|
|
1741
|
+
return (_b = (_a = i.accounts) == null ? void 0 : _a.filter((a) => isSignerRole(a.role))) != null ? _b : [];
|
|
1742
|
+
}).map((a) => a.address);
|
|
1738
1743
|
const requiredSigners = /* @__PURE__ */ new Set([transaction.feePayer, ...signerAddressesFromInstructions]);
|
|
1739
1744
|
requiredSigners.forEach((address2) => {
|
|
1740
1745
|
if (!transaction.signatures[address2]) {
|
|
@@ -1746,30 +1751,30 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1746
1751
|
// src/wire-transaction.ts
|
|
1747
1752
|
function getBase64EncodedWireTransaction(transaction) {
|
|
1748
1753
|
const wireTransactionBytes = getTransactionEncoder().encode(transaction);
|
|
1749
|
-
|
|
1750
|
-
return btoa(String.fromCharCode(...wireTransactionBytes));
|
|
1751
|
-
}
|
|
1754
|
+
return getBase64Decoder().decode(wireTransactionBytes)[0];
|
|
1752
1755
|
}
|
|
1753
1756
|
|
|
1754
1757
|
exports.appendTransactionInstruction = appendTransactionInstruction;
|
|
1755
1758
|
exports.assertIsBlockhash = assertIsBlockhash;
|
|
1756
1759
|
exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
|
|
1757
|
-
exports.assertIsTransactionSignature = assertIsTransactionSignature;
|
|
1758
1760
|
exports.assertTransactionIsFullySigned = assertTransactionIsFullySigned;
|
|
1761
|
+
exports.compileMessage = compileMessage;
|
|
1759
1762
|
exports.createTransaction = createTransaction;
|
|
1760
1763
|
exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
|
|
1764
|
+
exports.getCompiledMessageCodec = getCompiledMessageCodec;
|
|
1765
|
+
exports.getCompiledMessageDecoder = getCompiledMessageDecoder;
|
|
1766
|
+
exports.getCompiledMessageEncoder = getCompiledMessageEncoder;
|
|
1761
1767
|
exports.getSignatureFromTransaction = getSignatureFromTransaction;
|
|
1762
1768
|
exports.getTransactionCodec = getTransactionCodec;
|
|
1763
1769
|
exports.getTransactionDecoder = getTransactionDecoder;
|
|
1764
1770
|
exports.getTransactionEncoder = getTransactionEncoder;
|
|
1765
1771
|
exports.isAdvanceNonceAccountInstruction = isAdvanceNonceAccountInstruction;
|
|
1766
|
-
exports.
|
|
1772
|
+
exports.partiallySignTransaction = partiallySignTransaction;
|
|
1767
1773
|
exports.prependTransactionInstruction = prependTransactionInstruction;
|
|
1768
1774
|
exports.setTransactionFeePayer = setTransactionFeePayer;
|
|
1769
1775
|
exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
|
|
1770
1776
|
exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
|
|
1771
1777
|
exports.signTransaction = signTransaction;
|
|
1772
|
-
exports.transactionSignature = transactionSignature;
|
|
1773
1778
|
|
|
1774
1779
|
return exports;
|
|
1775
1780
|
|