@solana/transactions 2.0.0-experimental.6910664 → 2.0.0-experimental.699bde0
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 +24 -66
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +26 -64
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +477 -549
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +26 -64
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +26 -66
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +24 -64
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +18 -20
- package/dist/types/accounts.d.ts +2 -2
- package/dist/types/compilable-transaction.d.ts +7 -0
- package/dist/types/compile-address-table-lookups.d.ts +2 -2
- package/dist/types/compile-static-accounts.d.ts +2 -2
- package/dist/types/compile-transaction.d.ts +5 -6
- package/dist/types/decompile-transaction.d.ts +2 -4
- package/dist/types/durable-nonce.d.ts +3 -3
- package/dist/types/fee-payer.d.ts +4 -4
- package/dist/types/index.d.ts +1 -0
- package/dist/types/message.d.ts +1 -5
- package/dist/types/serializers/transaction.d.ts +1 -3
- package/dist/types/signatures.d.ts +8 -13
- package/dist/types/types.d.ts +6 -13
- package/package.json +13 -14
- package/dist/types/accounts.d.ts.map +0 -1
- package/dist/types/blockhash.d.ts.map +0 -1
- package/dist/types/compile-address-table-lookups.d.ts.map +0 -1
- package/dist/types/compile-header.d.ts.map +0 -1
- package/dist/types/compile-instructions.d.ts.map +0 -1
- package/dist/types/compile-lifetime-token.d.ts.map +0 -1
- package/dist/types/compile-static-accounts.d.ts.map +0 -1
- package/dist/types/compile-transaction.d.ts.map +0 -1
- package/dist/types/create-transaction.d.ts.map +0 -1
- package/dist/types/decompile-transaction.d.ts.map +0 -1
- package/dist/types/durable-nonce.d.ts.map +0 -1
- package/dist/types/fee-payer.d.ts.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/instructions.d.ts.map +0 -1
- package/dist/types/message.d.ts.map +0 -1
- package/dist/types/serializers/address-table-lookup.d.ts.map +0 -1
- package/dist/types/serializers/header.d.ts.map +0 -1
- package/dist/types/serializers/index.d.ts.map +0 -1
- package/dist/types/serializers/instruction.d.ts.map +0 -1
- package/dist/types/serializers/message.d.ts.map +0 -1
- package/dist/types/serializers/transaction-version.d.ts.map +0 -1
- package/dist/types/serializers/transaction.d.ts.map +0 -1
- package/dist/types/signatures.d.ts.map +0 -1
- package/dist/types/types.d.ts.map +0 -1
- package/dist/types/unsigned-transaction.d.ts.map +0 -1
- package/dist/types/wire-transaction.d.ts.map +0 -1
|
@@ -2,39 +2,264 @@ this.globalThis = this.globalThis || {};
|
|
|
2
2
|
this.globalThis.solanaWeb3 = (function (exports) {
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
// ../codecs-core/dist/index.browser.js
|
|
6
|
+
function assertByteArrayIsNotEmptyForCodec(codecDescription, bytes, offset = 0) {
|
|
7
|
+
if (bytes.length - offset <= 0) {
|
|
8
|
+
throw new Error(`Codec [${codecDescription}] cannot decode empty byte arrays.`);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function assertByteArrayHasEnoughBytesForCodec(codecDescription, expected, bytes, offset = 0) {
|
|
12
|
+
const bytesLength = bytes.length - offset;
|
|
13
|
+
if (bytesLength < expected) {
|
|
14
|
+
throw new Error(`Codec [${codecDescription}] expected ${expected} bytes, got ${bytesLength}.`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
var mergeBytes = (byteArrays) => {
|
|
18
|
+
const nonEmptyByteArrays = byteArrays.filter((arr) => arr.length);
|
|
19
|
+
if (nonEmptyByteArrays.length === 0) {
|
|
20
|
+
return byteArrays.length ? byteArrays[0] : new Uint8Array();
|
|
21
|
+
}
|
|
22
|
+
if (nonEmptyByteArrays.length === 1) {
|
|
23
|
+
return nonEmptyByteArrays[0];
|
|
24
|
+
}
|
|
25
|
+
const totalLength = nonEmptyByteArrays.reduce((total, arr) => total + arr.length, 0);
|
|
26
|
+
const result = new Uint8Array(totalLength);
|
|
27
|
+
let offset = 0;
|
|
28
|
+
nonEmptyByteArrays.forEach((arr) => {
|
|
29
|
+
result.set(arr, offset);
|
|
30
|
+
offset += arr.length;
|
|
31
|
+
});
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
var padBytes = (bytes, length) => {
|
|
35
|
+
if (bytes.length >= length)
|
|
36
|
+
return bytes;
|
|
37
|
+
const paddedBytes = new Uint8Array(length).fill(0);
|
|
38
|
+
paddedBytes.set(bytes);
|
|
39
|
+
return paddedBytes;
|
|
10
40
|
};
|
|
41
|
+
var fixBytes = (bytes, length) => padBytes(bytes.length <= length ? bytes : bytes.slice(0, length), length);
|
|
42
|
+
function combineCodec(encoder, decoder, description) {
|
|
43
|
+
if (encoder.fixedSize !== decoder.fixedSize) {
|
|
44
|
+
throw new Error(
|
|
45
|
+
`Encoder and decoder must have the same fixed size, got [${encoder.fixedSize}] and [${decoder.fixedSize}].`
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
if (encoder.maxSize !== decoder.maxSize) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
`Encoder and decoder must have the same max size, got [${encoder.maxSize}] and [${decoder.maxSize}].`
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
if (description === void 0 && encoder.description !== decoder.description) {
|
|
54
|
+
throw new Error(
|
|
55
|
+
`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.`
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
decode: decoder.decode,
|
|
60
|
+
description: description != null ? description : encoder.description,
|
|
61
|
+
encode: encoder.encode,
|
|
62
|
+
fixedSize: encoder.fixedSize,
|
|
63
|
+
maxSize: encoder.maxSize
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function fixCodecHelper(data, fixedBytes, description) {
|
|
67
|
+
return {
|
|
68
|
+
description: description != null ? description : `fixed(${fixedBytes}, ${data.description})`,
|
|
69
|
+
fixedSize: fixedBytes,
|
|
70
|
+
maxSize: fixedBytes
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function fixEncoder(encoder, fixedBytes, description) {
|
|
74
|
+
return {
|
|
75
|
+
...fixCodecHelper(encoder, fixedBytes, description),
|
|
76
|
+
encode: (value) => fixBytes(encoder.encode(value), fixedBytes)
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function fixDecoder(decoder, fixedBytes, description) {
|
|
80
|
+
return {
|
|
81
|
+
...fixCodecHelper(decoder, fixedBytes, description),
|
|
82
|
+
decode: (bytes, offset = 0) => {
|
|
83
|
+
assertByteArrayHasEnoughBytesForCodec("fixCodec", fixedBytes, bytes, offset);
|
|
84
|
+
if (offset > 0 || bytes.length > fixedBytes) {
|
|
85
|
+
bytes = bytes.slice(offset, offset + fixedBytes);
|
|
86
|
+
}
|
|
87
|
+
if (decoder.fixedSize !== null) {
|
|
88
|
+
bytes = fixBytes(bytes, decoder.fixedSize);
|
|
89
|
+
}
|
|
90
|
+
const [value] = decoder.decode(bytes, 0);
|
|
91
|
+
return [value, offset + fixedBytes];
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function mapEncoder(encoder, unmap) {
|
|
96
|
+
return {
|
|
97
|
+
description: encoder.description,
|
|
98
|
+
encode: (value) => encoder.encode(unmap(value)),
|
|
99
|
+
fixedSize: encoder.fixedSize,
|
|
100
|
+
maxSize: encoder.maxSize
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function mapDecoder(decoder, map) {
|
|
104
|
+
return {
|
|
105
|
+
decode: (bytes, offset = 0) => {
|
|
106
|
+
const [value, length] = decoder.decode(bytes, offset);
|
|
107
|
+
return [map(value, bytes, offset), length];
|
|
108
|
+
},
|
|
109
|
+
description: decoder.description,
|
|
110
|
+
fixedSize: decoder.fixedSize,
|
|
111
|
+
maxSize: decoder.maxSize
|
|
112
|
+
};
|
|
113
|
+
}
|
|
11
114
|
|
|
12
|
-
//
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
115
|
+
// ../codecs-numbers/dist/index.browser.js
|
|
116
|
+
function assertNumberIsBetweenForCodec(codecDescription, min, max, value) {
|
|
117
|
+
if (value < min || value > max) {
|
|
118
|
+
throw new Error(
|
|
119
|
+
`Codec [${codecDescription}] expected number to be in the range [${min}, ${max}], got ${value}.`
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function sharedNumberFactory(input) {
|
|
124
|
+
var _a;
|
|
125
|
+
let littleEndian;
|
|
126
|
+
let defaultDescription = input.name;
|
|
127
|
+
if (input.size > 1) {
|
|
128
|
+
littleEndian = !("endian" in input.config) || input.config.endian === 0;
|
|
129
|
+
defaultDescription += littleEndian ? "(le)" : "(be)";
|
|
19
130
|
}
|
|
131
|
+
return {
|
|
132
|
+
description: (_a = input.config.description) != null ? _a : defaultDescription,
|
|
133
|
+
fixedSize: input.size,
|
|
134
|
+
littleEndian,
|
|
135
|
+
maxSize: input.size
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function numberEncoderFactory(input) {
|
|
139
|
+
const codecData = sharedNumberFactory(input);
|
|
140
|
+
return {
|
|
141
|
+
description: codecData.description,
|
|
142
|
+
encode(value) {
|
|
143
|
+
if (input.range) {
|
|
144
|
+
assertNumberIsBetweenForCodec(input.name, input.range[0], input.range[1], value);
|
|
145
|
+
}
|
|
146
|
+
const arrayBuffer = new ArrayBuffer(input.size);
|
|
147
|
+
input.set(new DataView(arrayBuffer), value, codecData.littleEndian);
|
|
148
|
+
return new Uint8Array(arrayBuffer);
|
|
149
|
+
},
|
|
150
|
+
fixedSize: codecData.fixedSize,
|
|
151
|
+
maxSize: codecData.maxSize
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
function numberDecoderFactory(input) {
|
|
155
|
+
const codecData = sharedNumberFactory(input);
|
|
156
|
+
return {
|
|
157
|
+
decode(bytes, offset = 0) {
|
|
158
|
+
assertByteArrayIsNotEmptyForCodec(codecData.description, bytes, offset);
|
|
159
|
+
assertByteArrayHasEnoughBytesForCodec(codecData.description, input.size, bytes, offset);
|
|
160
|
+
const view = new DataView(toArrayBuffer(bytes, offset, input.size));
|
|
161
|
+
return [input.get(view, codecData.littleEndian), offset + input.size];
|
|
162
|
+
},
|
|
163
|
+
description: codecData.description,
|
|
164
|
+
fixedSize: codecData.fixedSize,
|
|
165
|
+
maxSize: codecData.maxSize
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
function toArrayBuffer(bytes, offset, length) {
|
|
169
|
+
const bytesOffset = bytes.byteOffset + (offset != null ? offset : 0);
|
|
170
|
+
const bytesLength = length != null ? length : bytes.byteLength;
|
|
171
|
+
return bytes.buffer.slice(bytesOffset, bytesOffset + bytesLength);
|
|
172
|
+
}
|
|
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
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return new Uint8Array(bytes);
|
|
192
|
+
},
|
|
193
|
+
fixedSize: null,
|
|
194
|
+
maxSize: 3
|
|
195
|
+
};
|
|
20
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
|
+
}
|
|
211
|
+
}
|
|
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,
|
|
221
|
+
name: "u32",
|
|
222
|
+
range: [0, Number("0xffffffff")],
|
|
223
|
+
set: (view, value, le) => view.setUint32(0, value, le),
|
|
224
|
+
size: 4
|
|
225
|
+
});
|
|
226
|
+
var getU32Decoder = (config = {}) => numberDecoderFactory({
|
|
227
|
+
config,
|
|
228
|
+
get: (view, le) => view.getUint32(0, le),
|
|
229
|
+
name: "u32",
|
|
230
|
+
size: 4
|
|
231
|
+
});
|
|
232
|
+
var getU8Encoder = (config = {}) => numberEncoderFactory({
|
|
233
|
+
config,
|
|
234
|
+
name: "u8",
|
|
235
|
+
range: [0, Number("0xff")],
|
|
236
|
+
set: (view, value) => view.setUint8(0, value),
|
|
237
|
+
size: 1
|
|
238
|
+
});
|
|
239
|
+
var getU8Decoder = (config = {}) => numberDecoderFactory({
|
|
240
|
+
config,
|
|
241
|
+
get: (view) => view.getUint8(0),
|
|
242
|
+
name: "u8",
|
|
243
|
+
size: 1
|
|
244
|
+
});
|
|
21
245
|
|
|
22
|
-
//
|
|
23
|
-
|
|
24
|
-
|
|
246
|
+
// ../codecs-strings/dist/index.browser.js
|
|
247
|
+
function assertValidBaseString(alphabet4, testValue, givenValue = testValue) {
|
|
248
|
+
if (!testValue.match(new RegExp(`^[${alphabet4}]*$`))) {
|
|
249
|
+
throw new Error(`Expected a string of base ${alphabet4.length}, got [${givenValue}].`);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
var getBaseXEncoder = (alphabet4) => {
|
|
253
|
+
const base = alphabet4.length;
|
|
25
254
|
const baseBigInt = BigInt(base);
|
|
26
255
|
return {
|
|
27
256
|
description: `base${base}`,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
serialize(value) {
|
|
31
|
-
if (!value.match(new RegExp(`^[${alphabet}]*$`))) {
|
|
32
|
-
throw new InvalidBaseStringError(value, base);
|
|
33
|
-
}
|
|
257
|
+
encode(value) {
|
|
258
|
+
assertValidBaseString(alphabet4, value);
|
|
34
259
|
if (value === "")
|
|
35
260
|
return new Uint8Array();
|
|
36
261
|
const chars = [...value];
|
|
37
|
-
let trailIndex = chars.findIndex((c) => c !==
|
|
262
|
+
let trailIndex = chars.findIndex((c) => c !== alphabet4[0]);
|
|
38
263
|
trailIndex = trailIndex === -1 ? chars.length : trailIndex;
|
|
39
264
|
const leadingZeroes = Array(trailIndex).fill(0);
|
|
40
265
|
if (trailIndex === chars.length)
|
|
@@ -43,7 +268,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
43
268
|
let base10Number = 0n;
|
|
44
269
|
let baseXPower = 1n;
|
|
45
270
|
for (let i = tailChars.length - 1; i >= 0; i -= 1) {
|
|
46
|
-
base10Number += baseXPower * BigInt(
|
|
271
|
+
base10Number += baseXPower * BigInt(alphabet4.indexOf(tailChars[i]));
|
|
47
272
|
baseXPower *= baseBigInt;
|
|
48
273
|
}
|
|
49
274
|
const tailBytes = [];
|
|
@@ -53,28 +278,133 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
53
278
|
}
|
|
54
279
|
return Uint8Array.from(leadingZeroes.concat(tailBytes));
|
|
55
280
|
},
|
|
56
|
-
|
|
57
|
-
|
|
281
|
+
fixedSize: null,
|
|
282
|
+
maxSize: null
|
|
283
|
+
};
|
|
284
|
+
};
|
|
285
|
+
var getBaseXDecoder = (alphabet4) => {
|
|
286
|
+
const base = alphabet4.length;
|
|
287
|
+
const baseBigInt = BigInt(base);
|
|
288
|
+
return {
|
|
289
|
+
decode(rawBytes, offset = 0) {
|
|
290
|
+
const bytes = offset === 0 ? rawBytes : rawBytes.slice(offset);
|
|
291
|
+
if (bytes.length === 0)
|
|
58
292
|
return ["", 0];
|
|
59
|
-
const bytes = buffer.slice(offset);
|
|
60
293
|
let trailIndex = bytes.findIndex((n) => n !== 0);
|
|
61
294
|
trailIndex = trailIndex === -1 ? bytes.length : trailIndex;
|
|
62
|
-
const leadingZeroes =
|
|
295
|
+
const leadingZeroes = alphabet4[0].repeat(trailIndex);
|
|
63
296
|
if (trailIndex === bytes.length)
|
|
64
|
-
return [leadingZeroes,
|
|
297
|
+
return [leadingZeroes, rawBytes.length];
|
|
65
298
|
let base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
|
|
66
299
|
const tailChars = [];
|
|
67
300
|
while (base10Number > 0n) {
|
|
68
|
-
tailChars.unshift(
|
|
301
|
+
tailChars.unshift(alphabet4[Number(base10Number % baseBigInt)]);
|
|
69
302
|
base10Number /= baseBigInt;
|
|
70
303
|
}
|
|
71
|
-
return [leadingZeroes + tailChars.join(""),
|
|
72
|
-
}
|
|
304
|
+
return [leadingZeroes + tailChars.join(""), rawBytes.length];
|
|
305
|
+
},
|
|
306
|
+
description: `base${base}`,
|
|
307
|
+
fixedSize: null,
|
|
308
|
+
maxSize: null
|
|
73
309
|
};
|
|
74
310
|
};
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
var
|
|
311
|
+
var alphabet2 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
312
|
+
var getBase58Encoder = () => getBaseXEncoder(alphabet2);
|
|
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
|
+
};
|
|
328
|
+
var removeNullCharacters = (value) => (
|
|
329
|
+
// eslint-disable-next-line no-control-regex
|
|
330
|
+
value.replace(/\u0000/g, "")
|
|
331
|
+
);
|
|
332
|
+
var e = globalThis.TextDecoder;
|
|
333
|
+
var o = globalThis.TextEncoder;
|
|
334
|
+
var getUtf8Encoder = () => {
|
|
335
|
+
let textEncoder;
|
|
336
|
+
return {
|
|
337
|
+
description: "utf8",
|
|
338
|
+
encode: (value) => new Uint8Array((textEncoder || (textEncoder = new o())).encode(value)),
|
|
339
|
+
fixedSize: null,
|
|
340
|
+
maxSize: null
|
|
341
|
+
};
|
|
342
|
+
};
|
|
343
|
+
var getUtf8Decoder = () => {
|
|
344
|
+
let textDecoder;
|
|
345
|
+
return {
|
|
346
|
+
decode(bytes, offset = 0) {
|
|
347
|
+
const value = (textDecoder || (textDecoder = new e())).decode(bytes.slice(offset));
|
|
348
|
+
return [removeNullCharacters(value), bytes.length];
|
|
349
|
+
},
|
|
350
|
+
description: "utf8",
|
|
351
|
+
fixedSize: null,
|
|
352
|
+
maxSize: null
|
|
353
|
+
};
|
|
354
|
+
};
|
|
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)})`;
|
|
360
|
+
if (size === "variable") {
|
|
361
|
+
return { ...encoding, description };
|
|
362
|
+
}
|
|
363
|
+
if (typeof size === "number") {
|
|
364
|
+
return fixEncoder(encoding, size, description);
|
|
365
|
+
}
|
|
366
|
+
return {
|
|
367
|
+
description,
|
|
368
|
+
encode: (value) => {
|
|
369
|
+
const contentBytes = encoding.encode(value);
|
|
370
|
+
const lengthBytes = size.encode(contentBytes.length);
|
|
371
|
+
return mergeBytes([lengthBytes, contentBytes]);
|
|
372
|
+
},
|
|
373
|
+
fixedSize: null,
|
|
374
|
+
maxSize: null
|
|
375
|
+
};
|
|
376
|
+
};
|
|
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)})`;
|
|
382
|
+
if (size === "variable") {
|
|
383
|
+
return { ...encoding, description };
|
|
384
|
+
}
|
|
385
|
+
if (typeof size === "number") {
|
|
386
|
+
return fixDecoder(encoding, size, description);
|
|
387
|
+
}
|
|
388
|
+
return {
|
|
389
|
+
decode: (bytes, offset = 0) => {
|
|
390
|
+
assertByteArrayIsNotEmptyForCodec("string", bytes, offset);
|
|
391
|
+
const [lengthBigInt, lengthOffset] = size.decode(bytes, offset);
|
|
392
|
+
const length = Number(lengthBigInt);
|
|
393
|
+
offset = lengthOffset;
|
|
394
|
+
const contentBytes = bytes.slice(offset, offset + length);
|
|
395
|
+
assertByteArrayHasEnoughBytesForCodec("string", length, contentBytes);
|
|
396
|
+
const [value, contentOffset] = encoding.decode(contentBytes);
|
|
397
|
+
offset += contentOffset;
|
|
398
|
+
return [value, offset];
|
|
399
|
+
},
|
|
400
|
+
description,
|
|
401
|
+
fixedSize: null,
|
|
402
|
+
maxSize: null
|
|
403
|
+
};
|
|
404
|
+
};
|
|
405
|
+
function getSizeDescription(size) {
|
|
406
|
+
return typeof size === "object" ? size.description : `${size}`;
|
|
407
|
+
}
|
|
78
408
|
|
|
79
409
|
// src/unsigned-transaction.ts
|
|
80
410
|
function getUnsignedTransaction(transaction) {
|
|
@@ -91,7 +421,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
91
421
|
}
|
|
92
422
|
|
|
93
423
|
// src/blockhash.ts
|
|
424
|
+
var base58Encoder;
|
|
94
425
|
function assertIsBlockhash(putativeBlockhash) {
|
|
426
|
+
if (!base58Encoder)
|
|
427
|
+
base58Encoder = getBase58Encoder();
|
|
95
428
|
try {
|
|
96
429
|
if (
|
|
97
430
|
// Lowest value (32 bytes of zeroes)
|
|
@@ -100,7 +433,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
100
433
|
) {
|
|
101
434
|
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
102
435
|
}
|
|
103
|
-
const bytes =
|
|
436
|
+
const bytes = base58Encoder.encode(putativeBlockhash);
|
|
104
437
|
const numBytes = bytes.byteLength;
|
|
105
438
|
if (numBytes !== 32) {
|
|
106
439
|
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
@@ -181,9 +514,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
181
514
|
};
|
|
182
515
|
}
|
|
183
516
|
function isAdvanceNonceAccountInstruction(instruction) {
|
|
517
|
+
var _a;
|
|
184
518
|
return instruction.programAddress === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data
|
|
185
519
|
instruction.data != null && isAdvanceNonceAccountInstructionData(instruction.data) && // Test for exactly 3 accounts
|
|
186
|
-
instruction.accounts
|
|
520
|
+
((_a = instruction.accounts) == null ? void 0 : _a.length) === 3 && // First account is nonce account address
|
|
187
521
|
instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole.WRITABLE && // Second account is recent blockhashes sysvar
|
|
188
522
|
instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole.READONLY && // Third account is nonce authority account
|
|
189
523
|
instruction.accounts[2].address != null && isSignerRole(instruction.accounts[2].role);
|
|
@@ -224,280 +558,46 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
224
558
|
];
|
|
225
559
|
}
|
|
226
560
|
const out = {
|
|
227
|
-
...getUnsignedTransaction(transaction),
|
|
228
|
-
instructions: newInstructions,
|
|
229
|
-
lifetimeConstraint: {
|
|
230
|
-
nonce
|
|
231
|
-
}
|
|
232
|
-
};
|
|
233
|
-
Object.freeze(out);
|
|
234
|
-
return out;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
// src/fee-payer.ts
|
|
238
|
-
function setTransactionFeePayer(feePayer, transaction) {
|
|
239
|
-
if ("feePayer" in transaction && feePayer === transaction.feePayer) {
|
|
240
|
-
return transaction;
|
|
241
|
-
}
|
|
242
|
-
const out = {
|
|
243
|
-
...getUnsignedTransaction(transaction),
|
|
244
|
-
feePayer
|
|
245
|
-
};
|
|
246
|
-
Object.freeze(out);
|
|
247
|
-
return out;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
// src/instructions.ts
|
|
251
|
-
function appendTransactionInstruction(instruction, transaction) {
|
|
252
|
-
const out = {
|
|
253
|
-
...getUnsignedTransaction(transaction),
|
|
254
|
-
instructions: [...transaction.instructions, instruction]
|
|
255
|
-
};
|
|
256
|
-
Object.freeze(out);
|
|
257
|
-
return out;
|
|
258
|
-
}
|
|
259
|
-
function prependTransactionInstruction(instruction, transaction) {
|
|
260
|
-
const out = {
|
|
261
|
-
...getUnsignedTransaction(transaction),
|
|
262
|
-
instructions: [instruction, ...transaction.instructions]
|
|
263
|
-
};
|
|
264
|
-
Object.freeze(out);
|
|
265
|
-
return out;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
// ../codecs-core/dist/index.browser.js
|
|
269
|
-
function assertByteArrayIsNotEmptyForCodec(codecDescription, bytes, offset = 0) {
|
|
270
|
-
if (bytes.length - offset <= 0) {
|
|
271
|
-
throw new Error(`Codec [${codecDescription}] cannot decode empty byte arrays.`);
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
function assertByteArrayHasEnoughBytesForCodec(codecDescription, expected, bytes, offset = 0) {
|
|
275
|
-
const bytesLength = bytes.length - offset;
|
|
276
|
-
if (bytesLength < expected) {
|
|
277
|
-
throw new Error(`Codec [${codecDescription}] expected ${expected} bytes, got ${bytesLength}.`);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
var mergeBytes = (byteArrays) => {
|
|
281
|
-
const nonEmptyByteArrays = byteArrays.filter((arr) => arr.length);
|
|
282
|
-
if (nonEmptyByteArrays.length === 0) {
|
|
283
|
-
return byteArrays.length ? byteArrays[0] : new Uint8Array();
|
|
284
|
-
}
|
|
285
|
-
if (nonEmptyByteArrays.length === 1) {
|
|
286
|
-
return nonEmptyByteArrays[0];
|
|
287
|
-
}
|
|
288
|
-
const totalLength = nonEmptyByteArrays.reduce((total, arr) => total + arr.length, 0);
|
|
289
|
-
const result = new Uint8Array(totalLength);
|
|
290
|
-
let offset = 0;
|
|
291
|
-
nonEmptyByteArrays.forEach((arr) => {
|
|
292
|
-
result.set(arr, offset);
|
|
293
|
-
offset += arr.length;
|
|
294
|
-
});
|
|
295
|
-
return result;
|
|
296
|
-
};
|
|
297
|
-
var padBytes = (bytes, length) => {
|
|
298
|
-
if (bytes.length >= length)
|
|
299
|
-
return bytes;
|
|
300
|
-
const paddedBytes = new Uint8Array(length).fill(0);
|
|
301
|
-
paddedBytes.set(bytes);
|
|
302
|
-
return paddedBytes;
|
|
303
|
-
};
|
|
304
|
-
var fixBytes = (bytes, length) => padBytes(bytes.length <= length ? bytes : bytes.slice(0, length), length);
|
|
305
|
-
function combineCodec(encoder, decoder, description) {
|
|
306
|
-
if (encoder.fixedSize !== decoder.fixedSize) {
|
|
307
|
-
throw new Error(
|
|
308
|
-
`Encoder and decoder must have the same fixed size, got [${encoder.fixedSize}] and [${decoder.fixedSize}].`
|
|
309
|
-
);
|
|
310
|
-
}
|
|
311
|
-
if (encoder.maxSize !== decoder.maxSize) {
|
|
312
|
-
throw new Error(
|
|
313
|
-
`Encoder and decoder must have the same max size, got [${encoder.maxSize}] and [${decoder.maxSize}].`
|
|
314
|
-
);
|
|
315
|
-
}
|
|
316
|
-
if (description === void 0 && encoder.description !== decoder.description) {
|
|
317
|
-
throw new Error(
|
|
318
|
-
`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.`
|
|
319
|
-
);
|
|
320
|
-
}
|
|
321
|
-
return {
|
|
322
|
-
decode: decoder.decode,
|
|
323
|
-
description: description ?? encoder.description,
|
|
324
|
-
encode: encoder.encode,
|
|
325
|
-
fixedSize: encoder.fixedSize,
|
|
326
|
-
maxSize: encoder.maxSize
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
function fixCodecHelper(data, fixedBytes, description) {
|
|
330
|
-
return {
|
|
331
|
-
description: description ?? `fixed(${fixedBytes}, ${data.description})`,
|
|
332
|
-
fixedSize: fixedBytes,
|
|
333
|
-
maxSize: fixedBytes
|
|
334
|
-
};
|
|
335
|
-
}
|
|
336
|
-
function fixEncoder(encoder, fixedBytes, description) {
|
|
337
|
-
return {
|
|
338
|
-
...fixCodecHelper(encoder, fixedBytes, description),
|
|
339
|
-
encode: (value) => fixBytes(encoder.encode(value), fixedBytes)
|
|
340
|
-
};
|
|
341
|
-
}
|
|
342
|
-
function fixDecoder(decoder, fixedBytes, description) {
|
|
343
|
-
return {
|
|
344
|
-
...fixCodecHelper(decoder, fixedBytes, description),
|
|
345
|
-
decode: (bytes, offset = 0) => {
|
|
346
|
-
assertByteArrayHasEnoughBytesForCodec("fixCodec", fixedBytes, bytes, offset);
|
|
347
|
-
if (offset > 0 || bytes.length > fixedBytes) {
|
|
348
|
-
bytes = bytes.slice(offset, offset + fixedBytes);
|
|
349
|
-
}
|
|
350
|
-
if (decoder.fixedSize !== null) {
|
|
351
|
-
bytes = fixBytes(bytes, decoder.fixedSize);
|
|
352
|
-
}
|
|
353
|
-
const [value] = decoder.decode(bytes, 0);
|
|
354
|
-
return [value, offset + fixedBytes];
|
|
355
|
-
}
|
|
356
|
-
};
|
|
357
|
-
}
|
|
358
|
-
function mapEncoder(encoder, unmap) {
|
|
359
|
-
return {
|
|
360
|
-
description: encoder.description,
|
|
361
|
-
encode: (value) => encoder.encode(unmap(value)),
|
|
362
|
-
fixedSize: encoder.fixedSize,
|
|
363
|
-
maxSize: encoder.maxSize
|
|
364
|
-
};
|
|
365
|
-
}
|
|
366
|
-
function mapDecoder(decoder, map) {
|
|
367
|
-
return {
|
|
368
|
-
decode: (bytes, offset = 0) => {
|
|
369
|
-
const [value, length] = decoder.decode(bytes, offset);
|
|
370
|
-
return [map(value, bytes, offset), length];
|
|
371
|
-
},
|
|
372
|
-
description: decoder.description,
|
|
373
|
-
fixedSize: decoder.fixedSize,
|
|
374
|
-
maxSize: decoder.maxSize
|
|
375
|
-
};
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
// ../codecs-numbers/dist/index.browser.js
|
|
379
|
-
function assertNumberIsBetweenForCodec(codecDescription, min, max, value) {
|
|
380
|
-
if (value < min || value > max) {
|
|
381
|
-
throw new Error(
|
|
382
|
-
`Codec [${codecDescription}] expected number to be in the range [${min}, ${max}], got ${value}.`
|
|
383
|
-
);
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
function sharedNumberFactory(input) {
|
|
387
|
-
let littleEndian;
|
|
388
|
-
let defaultDescription = input.name;
|
|
389
|
-
if (input.size > 1) {
|
|
390
|
-
littleEndian = !("endian" in input.options) || input.options.endian === 0;
|
|
391
|
-
defaultDescription += littleEndian ? "(le)" : "(be)";
|
|
392
|
-
}
|
|
393
|
-
return {
|
|
394
|
-
description: input.options.description ?? defaultDescription,
|
|
395
|
-
fixedSize: input.size,
|
|
396
|
-
littleEndian,
|
|
397
|
-
maxSize: input.size
|
|
561
|
+
...getUnsignedTransaction(transaction),
|
|
562
|
+
instructions: newInstructions,
|
|
563
|
+
lifetimeConstraint: {
|
|
564
|
+
nonce
|
|
565
|
+
}
|
|
398
566
|
};
|
|
567
|
+
Object.freeze(out);
|
|
568
|
+
return out;
|
|
399
569
|
}
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
input.set(new DataView(arrayBuffer), value, codecData.littleEndian);
|
|
410
|
-
return new Uint8Array(arrayBuffer);
|
|
411
|
-
},
|
|
412
|
-
fixedSize: codecData.fixedSize,
|
|
413
|
-
maxSize: codecData.maxSize
|
|
570
|
+
|
|
571
|
+
// src/fee-payer.ts
|
|
572
|
+
function setTransactionFeePayer(feePayer, transaction) {
|
|
573
|
+
if ("feePayer" in transaction && feePayer === transaction.feePayer) {
|
|
574
|
+
return transaction;
|
|
575
|
+
}
|
|
576
|
+
const out = {
|
|
577
|
+
...getUnsignedTransaction(transaction),
|
|
578
|
+
feePayer
|
|
414
579
|
};
|
|
580
|
+
Object.freeze(out);
|
|
581
|
+
return out;
|
|
415
582
|
}
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
const view = new DataView(toArrayBuffer(bytes, offset, input.size));
|
|
423
|
-
return [input.get(view, codecData.littleEndian), offset + input.size];
|
|
424
|
-
},
|
|
425
|
-
description: codecData.description,
|
|
426
|
-
fixedSize: codecData.fixedSize,
|
|
427
|
-
maxSize: codecData.maxSize
|
|
583
|
+
|
|
584
|
+
// src/instructions.ts
|
|
585
|
+
function appendTransactionInstruction(instruction, transaction) {
|
|
586
|
+
const out = {
|
|
587
|
+
...getUnsignedTransaction(transaction),
|
|
588
|
+
instructions: [...transaction.instructions, instruction]
|
|
428
589
|
};
|
|
590
|
+
Object.freeze(out);
|
|
591
|
+
return out;
|
|
429
592
|
}
|
|
430
|
-
function
|
|
431
|
-
const
|
|
432
|
-
|
|
433
|
-
|
|
593
|
+
function prependTransactionInstruction(instruction, transaction) {
|
|
594
|
+
const out = {
|
|
595
|
+
...getUnsignedTransaction(transaction),
|
|
596
|
+
instructions: [instruction, ...transaction.instructions]
|
|
597
|
+
};
|
|
598
|
+
Object.freeze(out);
|
|
599
|
+
return out;
|
|
434
600
|
}
|
|
435
|
-
var getShortU16Encoder = (options = {}) => ({
|
|
436
|
-
description: options.description ?? "shortU16",
|
|
437
|
-
encode: (value) => {
|
|
438
|
-
assertNumberIsBetweenForCodec("shortU16", 0, 65535, value);
|
|
439
|
-
const bytes = [0];
|
|
440
|
-
for (let ii = 0; ; ii += 1) {
|
|
441
|
-
const alignedValue = value >> ii * 7;
|
|
442
|
-
if (alignedValue === 0) {
|
|
443
|
-
break;
|
|
444
|
-
}
|
|
445
|
-
const nextSevenBits = 127 & alignedValue;
|
|
446
|
-
bytes[ii] = nextSevenBits;
|
|
447
|
-
if (ii > 0) {
|
|
448
|
-
bytes[ii - 1] |= 128;
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
return new Uint8Array(bytes);
|
|
452
|
-
},
|
|
453
|
-
fixedSize: null,
|
|
454
|
-
maxSize: 3
|
|
455
|
-
});
|
|
456
|
-
var getShortU16Decoder = (options = {}) => ({
|
|
457
|
-
decode: (bytes, offset = 0) => {
|
|
458
|
-
let value = 0;
|
|
459
|
-
let byteCount = 0;
|
|
460
|
-
while (++byteCount) {
|
|
461
|
-
const byteIndex = byteCount - 1;
|
|
462
|
-
const currentByte = bytes[offset + byteIndex];
|
|
463
|
-
const nextSevenBits = 127 & currentByte;
|
|
464
|
-
value |= nextSevenBits << byteIndex * 7;
|
|
465
|
-
if ((currentByte & 128) === 0) {
|
|
466
|
-
break;
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
return [value, offset + byteCount];
|
|
470
|
-
},
|
|
471
|
-
description: options.description ?? "shortU16",
|
|
472
|
-
fixedSize: null,
|
|
473
|
-
maxSize: 3
|
|
474
|
-
});
|
|
475
|
-
var getU32Encoder = (options = {}) => numberEncoderFactory({
|
|
476
|
-
name: "u32",
|
|
477
|
-
options,
|
|
478
|
-
range: [0, Number("0xffffffff")],
|
|
479
|
-
set: (view, value, le) => view.setUint32(0, value, le),
|
|
480
|
-
size: 4
|
|
481
|
-
});
|
|
482
|
-
var getU32Decoder = (options = {}) => numberDecoderFactory({
|
|
483
|
-
get: (view, le) => view.getUint32(0, le),
|
|
484
|
-
name: "u32",
|
|
485
|
-
options,
|
|
486
|
-
size: 4
|
|
487
|
-
});
|
|
488
|
-
var getU8Encoder = (options = {}) => numberEncoderFactory({
|
|
489
|
-
name: "u8",
|
|
490
|
-
options,
|
|
491
|
-
range: [0, Number("0xff")],
|
|
492
|
-
set: (view, value) => view.setUint8(0, value),
|
|
493
|
-
size: 1
|
|
494
|
-
});
|
|
495
|
-
var getU8Decoder = (options = {}) => numberDecoderFactory({
|
|
496
|
-
get: (view) => view.getUint8(0),
|
|
497
|
-
name: "u8",
|
|
498
|
-
options,
|
|
499
|
-
size: 1
|
|
500
|
-
});
|
|
501
601
|
|
|
502
602
|
// ../codecs-data-structures/dist/index.browser.js
|
|
503
603
|
function sumCodecSizes(sizes) {
|
|
@@ -549,15 +649,16 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
549
649
|
throw new Error('Codecs of "remainder" size must have fixed-size items.');
|
|
550
650
|
}
|
|
551
651
|
return {
|
|
552
|
-
description: description
|
|
652
|
+
description: description != null ? description : `array(${item.description}; ${getArrayLikeCodecSizeDescription(size)})`,
|
|
553
653
|
fixedSize: getArrayLikeCodecSizeFromChildren(size, [item.fixedSize]),
|
|
554
654
|
maxSize: getArrayLikeCodecSizeFromChildren(size, [item.maxSize])
|
|
555
655
|
};
|
|
556
656
|
}
|
|
557
|
-
function getArrayEncoder(item,
|
|
558
|
-
|
|
657
|
+
function getArrayEncoder(item, config = {}) {
|
|
658
|
+
var _a;
|
|
659
|
+
const size = (_a = config.size) != null ? _a : getU32Encoder();
|
|
559
660
|
return {
|
|
560
|
-
...arrayCodecHelper(item, size,
|
|
661
|
+
...arrayCodecHelper(item, size, config.description),
|
|
561
662
|
encode: (value) => {
|
|
562
663
|
if (typeof size === "number") {
|
|
563
664
|
assertValidNumberOfItemsForCodec("array", size, value.length);
|
|
@@ -566,10 +667,11 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
566
667
|
}
|
|
567
668
|
};
|
|
568
669
|
}
|
|
569
|
-
function getArrayDecoder(item,
|
|
570
|
-
|
|
670
|
+
function getArrayDecoder(item, config = {}) {
|
|
671
|
+
var _a;
|
|
672
|
+
const size = (_a = config.size) != null ? _a : getU32Decoder();
|
|
571
673
|
return {
|
|
572
|
-
...arrayCodecHelper(item, size,
|
|
674
|
+
...arrayCodecHelper(item, size, config.description),
|
|
573
675
|
decode: (bytes, offset = 0) => {
|
|
574
676
|
if (typeof size === "object" && bytes.slice(offset).length === 0) {
|
|
575
677
|
return [[], offset];
|
|
@@ -586,10 +688,11 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
586
688
|
}
|
|
587
689
|
};
|
|
588
690
|
}
|
|
589
|
-
function getBytesEncoder(
|
|
590
|
-
|
|
691
|
+
function getBytesEncoder(config = {}) {
|
|
692
|
+
var _a, _b;
|
|
693
|
+
const size = (_a = config.size) != null ? _a : "variable";
|
|
591
694
|
const sizeDescription = typeof size === "object" ? size.description : `${size}`;
|
|
592
|
-
const description =
|
|
695
|
+
const description = (_b = config.description) != null ? _b : `bytes(${sizeDescription})`;
|
|
593
696
|
const byteEncoder = {
|
|
594
697
|
description,
|
|
595
698
|
encode: (value) => value,
|
|
@@ -611,10 +714,11 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
611
714
|
}
|
|
612
715
|
};
|
|
613
716
|
}
|
|
614
|
-
function getBytesDecoder(
|
|
615
|
-
|
|
717
|
+
function getBytesDecoder(config = {}) {
|
|
718
|
+
var _a, _b;
|
|
719
|
+
const size = (_a = config.size) != null ? _a : "variable";
|
|
616
720
|
const sizeDescription = typeof size === "object" ? size.description : `${size}`;
|
|
617
|
-
const description =
|
|
721
|
+
const description = (_b = config.description) != null ? _b : `bytes(${sizeDescription})`;
|
|
618
722
|
const byteDecoder = {
|
|
619
723
|
decode: (bytes, offset = 0) => {
|
|
620
724
|
const slice = bytes.slice(offset);
|
|
@@ -648,23 +752,23 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
648
752
|
function structCodecHelper(fields, description) {
|
|
649
753
|
const fieldDescriptions = fields.map(([name, codec]) => `${String(name)}: ${codec.description}`).join(", ");
|
|
650
754
|
return {
|
|
651
|
-
description: description
|
|
755
|
+
description: description != null ? description : `struct(${fieldDescriptions})`,
|
|
652
756
|
fixedSize: sumCodecSizes(fields.map(([, field]) => field.fixedSize)),
|
|
653
757
|
maxSize: sumCodecSizes(fields.map(([, field]) => field.maxSize))
|
|
654
758
|
};
|
|
655
759
|
}
|
|
656
|
-
function getStructEncoder(fields,
|
|
760
|
+
function getStructEncoder(fields, config = {}) {
|
|
657
761
|
return {
|
|
658
|
-
...structCodecHelper(fields,
|
|
762
|
+
...structCodecHelper(fields, config.description),
|
|
659
763
|
encode: (struct) => {
|
|
660
764
|
const fieldBytes = fields.map(([key, codec]) => codec.encode(struct[key]));
|
|
661
765
|
return mergeBytes(fieldBytes);
|
|
662
766
|
}
|
|
663
767
|
};
|
|
664
768
|
}
|
|
665
|
-
function getStructDecoder(fields,
|
|
769
|
+
function getStructDecoder(fields, config = {}) {
|
|
666
770
|
return {
|
|
667
|
-
...structCodecHelper(fields,
|
|
771
|
+
...structCodecHelper(fields, config.description),
|
|
668
772
|
decode: (bytes, offset = 0) => {
|
|
669
773
|
const struct = {};
|
|
670
774
|
fields.forEach(([key, codec]) => {
|
|
@@ -677,153 +781,6 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
677
781
|
};
|
|
678
782
|
}
|
|
679
783
|
|
|
680
|
-
// ../codecs-strings/dist/index.browser.js
|
|
681
|
-
function assertValidBaseString(alphabet4, testValue, givenValue = testValue) {
|
|
682
|
-
if (!testValue.match(new RegExp(`^[${alphabet4}]*$`))) {
|
|
683
|
-
throw new Error(`Expected a string of base ${alphabet4.length}, got [${givenValue}].`);
|
|
684
|
-
}
|
|
685
|
-
}
|
|
686
|
-
var getBaseXEncoder = (alphabet4) => {
|
|
687
|
-
const base = alphabet4.length;
|
|
688
|
-
const baseBigInt = BigInt(base);
|
|
689
|
-
return {
|
|
690
|
-
description: `base${base}`,
|
|
691
|
-
encode(value) {
|
|
692
|
-
assertValidBaseString(alphabet4, value);
|
|
693
|
-
if (value === "")
|
|
694
|
-
return new Uint8Array();
|
|
695
|
-
const chars = [...value];
|
|
696
|
-
let trailIndex = chars.findIndex((c) => c !== alphabet4[0]);
|
|
697
|
-
trailIndex = trailIndex === -1 ? chars.length : trailIndex;
|
|
698
|
-
const leadingZeroes = Array(trailIndex).fill(0);
|
|
699
|
-
if (trailIndex === chars.length)
|
|
700
|
-
return Uint8Array.from(leadingZeroes);
|
|
701
|
-
const tailChars = chars.slice(trailIndex);
|
|
702
|
-
let base10Number = 0n;
|
|
703
|
-
let baseXPower = 1n;
|
|
704
|
-
for (let i = tailChars.length - 1; i >= 0; i -= 1) {
|
|
705
|
-
base10Number += baseXPower * BigInt(alphabet4.indexOf(tailChars[i]));
|
|
706
|
-
baseXPower *= baseBigInt;
|
|
707
|
-
}
|
|
708
|
-
const tailBytes = [];
|
|
709
|
-
while (base10Number > 0n) {
|
|
710
|
-
tailBytes.unshift(Number(base10Number % 256n));
|
|
711
|
-
base10Number /= 256n;
|
|
712
|
-
}
|
|
713
|
-
return Uint8Array.from(leadingZeroes.concat(tailBytes));
|
|
714
|
-
},
|
|
715
|
-
fixedSize: null,
|
|
716
|
-
maxSize: null
|
|
717
|
-
};
|
|
718
|
-
};
|
|
719
|
-
var getBaseXDecoder = (alphabet4) => {
|
|
720
|
-
const base = alphabet4.length;
|
|
721
|
-
const baseBigInt = BigInt(base);
|
|
722
|
-
return {
|
|
723
|
-
decode(rawBytes, offset = 0) {
|
|
724
|
-
const bytes = offset === 0 ? rawBytes : rawBytes.slice(offset);
|
|
725
|
-
if (bytes.length === 0)
|
|
726
|
-
return ["", 0];
|
|
727
|
-
let trailIndex = bytes.findIndex((n) => n !== 0);
|
|
728
|
-
trailIndex = trailIndex === -1 ? bytes.length : trailIndex;
|
|
729
|
-
const leadingZeroes = alphabet4[0].repeat(trailIndex);
|
|
730
|
-
if (trailIndex === bytes.length)
|
|
731
|
-
return [leadingZeroes, rawBytes.length];
|
|
732
|
-
let base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
|
|
733
|
-
const tailChars = [];
|
|
734
|
-
while (base10Number > 0n) {
|
|
735
|
-
tailChars.unshift(alphabet4[Number(base10Number % baseBigInt)]);
|
|
736
|
-
base10Number /= baseBigInt;
|
|
737
|
-
}
|
|
738
|
-
return [leadingZeroes + tailChars.join(""), rawBytes.length];
|
|
739
|
-
},
|
|
740
|
-
description: `base${base}`,
|
|
741
|
-
fixedSize: null,
|
|
742
|
-
maxSize: null
|
|
743
|
-
};
|
|
744
|
-
};
|
|
745
|
-
var alphabet2 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
746
|
-
var getBase58Encoder = () => getBaseXEncoder(alphabet2);
|
|
747
|
-
var getBase58Decoder = () => getBaseXDecoder(alphabet2);
|
|
748
|
-
var removeNullCharacters = (value) => (
|
|
749
|
-
// eslint-disable-next-line no-control-regex
|
|
750
|
-
value.replace(/\u0000/g, "")
|
|
751
|
-
);
|
|
752
|
-
var e = globalThis.TextDecoder;
|
|
753
|
-
var o = globalThis.TextEncoder;
|
|
754
|
-
var getUtf8Encoder = () => {
|
|
755
|
-
let textEncoder;
|
|
756
|
-
return {
|
|
757
|
-
description: "utf8",
|
|
758
|
-
encode: (value) => new Uint8Array((textEncoder || (textEncoder = new o())).encode(value)),
|
|
759
|
-
fixedSize: null,
|
|
760
|
-
maxSize: null
|
|
761
|
-
};
|
|
762
|
-
};
|
|
763
|
-
var getUtf8Decoder = () => {
|
|
764
|
-
let textDecoder;
|
|
765
|
-
return {
|
|
766
|
-
decode(bytes, offset = 0) {
|
|
767
|
-
const value = (textDecoder || (textDecoder = new e())).decode(bytes.slice(offset));
|
|
768
|
-
return [removeNullCharacters(value), bytes.length];
|
|
769
|
-
},
|
|
770
|
-
description: "utf8",
|
|
771
|
-
fixedSize: null,
|
|
772
|
-
maxSize: null
|
|
773
|
-
};
|
|
774
|
-
};
|
|
775
|
-
var getStringEncoder = (options = {}) => {
|
|
776
|
-
const size = options.size ?? getU32Encoder();
|
|
777
|
-
const encoding = options.encoding ?? getUtf8Encoder();
|
|
778
|
-
const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
|
|
779
|
-
if (size === "variable") {
|
|
780
|
-
return { ...encoding, description };
|
|
781
|
-
}
|
|
782
|
-
if (typeof size === "number") {
|
|
783
|
-
return fixEncoder(encoding, size, description);
|
|
784
|
-
}
|
|
785
|
-
return {
|
|
786
|
-
description,
|
|
787
|
-
encode: (value) => {
|
|
788
|
-
const contentBytes = encoding.encode(value);
|
|
789
|
-
const lengthBytes = size.encode(contentBytes.length);
|
|
790
|
-
return mergeBytes([lengthBytes, contentBytes]);
|
|
791
|
-
},
|
|
792
|
-
fixedSize: null,
|
|
793
|
-
maxSize: null
|
|
794
|
-
};
|
|
795
|
-
};
|
|
796
|
-
var getStringDecoder = (options = {}) => {
|
|
797
|
-
const size = options.size ?? getU32Decoder();
|
|
798
|
-
const encoding = options.encoding ?? getUtf8Decoder();
|
|
799
|
-
const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
|
|
800
|
-
if (size === "variable") {
|
|
801
|
-
return { ...encoding, description };
|
|
802
|
-
}
|
|
803
|
-
if (typeof size === "number") {
|
|
804
|
-
return fixDecoder(encoding, size, description);
|
|
805
|
-
}
|
|
806
|
-
return {
|
|
807
|
-
decode: (bytes, offset = 0) => {
|
|
808
|
-
assertByteArrayIsNotEmptyForCodec("string", bytes, offset);
|
|
809
|
-
const [lengthBigInt, lengthOffset] = size.decode(bytes, offset);
|
|
810
|
-
const length = Number(lengthBigInt);
|
|
811
|
-
offset = lengthOffset;
|
|
812
|
-
const contentBytes = bytes.slice(offset, offset + length);
|
|
813
|
-
assertByteArrayHasEnoughBytesForCodec("string", length, contentBytes);
|
|
814
|
-
const [value, contentOffset] = encoding.decode(contentBytes);
|
|
815
|
-
offset += contentOffset;
|
|
816
|
-
return [value, offset];
|
|
817
|
-
},
|
|
818
|
-
description,
|
|
819
|
-
fixedSize: null,
|
|
820
|
-
maxSize: null
|
|
821
|
-
};
|
|
822
|
-
};
|
|
823
|
-
function getSizeDescription(size) {
|
|
824
|
-
return typeof size === "object" ? size.description : `${size}`;
|
|
825
|
-
}
|
|
826
|
-
|
|
827
784
|
// ../assertions/dist/index.browser.js
|
|
828
785
|
function assertIsSecureContext() {
|
|
829
786
|
if (!globalThis.isSecureContext) {
|
|
@@ -833,14 +790,16 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
833
790
|
}
|
|
834
791
|
}
|
|
835
792
|
async function assertKeyExporterIsAvailable() {
|
|
793
|
+
var _a;
|
|
836
794
|
assertIsSecureContext();
|
|
837
|
-
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle
|
|
795
|
+
if (typeof globalThis.crypto === "undefined" || typeof ((_a = globalThis.crypto.subtle) == null ? void 0 : _a.exportKey) !== "function") {
|
|
838
796
|
throw new Error("No key export implementation could be found");
|
|
839
797
|
}
|
|
840
798
|
}
|
|
841
799
|
async function assertSigningCapabilityIsAvailable() {
|
|
800
|
+
var _a;
|
|
842
801
|
assertIsSecureContext();
|
|
843
|
-
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle
|
|
802
|
+
if (typeof globalThis.crypto === "undefined" || typeof ((_a = globalThis.crypto.subtle) == null ? void 0 : _a.sign) !== "function") {
|
|
844
803
|
throw new Error("No signing implementation could be found");
|
|
845
804
|
}
|
|
846
805
|
}
|
|
@@ -858,35 +817,36 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
858
817
|
memoizedBase58Decoder = getBase58Decoder();
|
|
859
818
|
return memoizedBase58Decoder;
|
|
860
819
|
}
|
|
861
|
-
function assertIsAddress(
|
|
820
|
+
function assertIsAddress(putativeAddress) {
|
|
862
821
|
try {
|
|
863
822
|
if (
|
|
864
823
|
// Lowest address (32 bytes of zeroes)
|
|
865
|
-
|
|
866
|
-
|
|
824
|
+
putativeAddress.length < 32 || // Highest address (32 bytes of 255)
|
|
825
|
+
putativeAddress.length > 44
|
|
867
826
|
) {
|
|
868
827
|
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
869
828
|
}
|
|
870
|
-
const
|
|
871
|
-
const bytes =
|
|
829
|
+
const base58Encoder2 = getMemoizedBase58Encoder();
|
|
830
|
+
const bytes = base58Encoder2.encode(putativeAddress);
|
|
872
831
|
const numBytes = bytes.byteLength;
|
|
873
832
|
if (numBytes !== 32) {
|
|
874
833
|
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
875
834
|
}
|
|
876
835
|
} catch (e2) {
|
|
877
|
-
throw new Error(`\`${
|
|
836
|
+
throw new Error(`\`${putativeAddress}\` is not a base-58 encoded address`, {
|
|
878
837
|
cause: e2
|
|
879
838
|
});
|
|
880
839
|
}
|
|
881
840
|
}
|
|
882
|
-
function address(
|
|
883
|
-
assertIsAddress(
|
|
884
|
-
return
|
|
841
|
+
function address(putativeAddress) {
|
|
842
|
+
assertIsAddress(putativeAddress);
|
|
843
|
+
return putativeAddress;
|
|
885
844
|
}
|
|
886
845
|
function getAddressEncoder(config) {
|
|
846
|
+
var _a;
|
|
887
847
|
return mapEncoder(
|
|
888
848
|
getStringEncoder({
|
|
889
|
-
description: config
|
|
849
|
+
description: (_a = config == null ? void 0 : config.description) != null ? _a : "Address",
|
|
890
850
|
encoding: getMemoizedBase58Encoder(),
|
|
891
851
|
size: 32
|
|
892
852
|
}),
|
|
@@ -894,8 +854,9 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
894
854
|
);
|
|
895
855
|
}
|
|
896
856
|
function getAddressDecoder(config) {
|
|
857
|
+
var _a;
|
|
897
858
|
return getStringDecoder({
|
|
898
|
-
description: config
|
|
859
|
+
description: (_a = config == null ? void 0 : config.description) != null ? _a : "Address",
|
|
899
860
|
encoding: getMemoizedBase58Decoder(),
|
|
900
861
|
size: 32
|
|
901
862
|
});
|
|
@@ -922,7 +883,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
922
883
|
|
|
923
884
|
// src/accounts.ts
|
|
924
885
|
function upsert(addressMap, address2, update) {
|
|
925
|
-
|
|
886
|
+
var _a;
|
|
887
|
+
addressMap[address2] = update((_a = addressMap[address2]) != null ? _a : { role: AccountRole.READONLY });
|
|
926
888
|
}
|
|
927
889
|
var TYPE = Symbol("AddressMapTypeProperty");
|
|
928
890
|
function getAddressMapFromInstructions(feePayer, instructions) {
|
|
@@ -1192,12 +1154,13 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1192
1154
|
|
|
1193
1155
|
// src/compile-transaction.ts
|
|
1194
1156
|
function getCompiledTransaction(transaction) {
|
|
1157
|
+
var _a;
|
|
1195
1158
|
const compiledMessage = compileMessage(transaction);
|
|
1196
1159
|
let signatures;
|
|
1197
1160
|
if ("signatures" in transaction) {
|
|
1198
1161
|
signatures = [];
|
|
1199
1162
|
for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
|
|
1200
|
-
signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]]
|
|
1163
|
+
signatures[ii] = (_a = transaction.signatures[compiledMessage.staticAccounts[ii]]) != null ? _a : new Uint8Array(Array(64).fill(0));
|
|
1201
1164
|
}
|
|
1202
1165
|
} else {
|
|
1203
1166
|
signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
|
|
@@ -1251,11 +1214,12 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1251
1214
|
return accountMetas;
|
|
1252
1215
|
}
|
|
1253
1216
|
function convertInstruction(instruction, accountMetas) {
|
|
1254
|
-
|
|
1217
|
+
var _a, _b;
|
|
1218
|
+
const programAddress = (_a = accountMetas[instruction.programAddressIndex]) == null ? void 0 : _a.address;
|
|
1255
1219
|
if (!programAddress) {
|
|
1256
1220
|
throw new Error(`Could not find program address at index ${instruction.programAddressIndex}`);
|
|
1257
1221
|
}
|
|
1258
|
-
const accounts = instruction.accountIndices
|
|
1222
|
+
const accounts = (_b = instruction.accountIndices) == null ? void 0 : _b.map((accountIndex) => accountMetas[accountIndex]);
|
|
1259
1223
|
const { data } = instruction;
|
|
1260
1224
|
return {
|
|
1261
1225
|
programAddress,
|
|
@@ -1267,7 +1231,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1267
1231
|
if (!firstInstruction || !isAdvanceNonceAccountInstruction(firstInstruction)) {
|
|
1268
1232
|
return {
|
|
1269
1233
|
blockhash: messageLifetimeToken,
|
|
1270
|
-
lastValidBlockHeight: lastValidBlockHeight
|
|
1234
|
+
lastValidBlockHeight: lastValidBlockHeight != null ? lastValidBlockHeight : 2n ** 64n - 1n
|
|
1271
1235
|
// U64 MAX
|
|
1272
1236
|
};
|
|
1273
1237
|
} else {
|
|
@@ -1394,7 +1358,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1394
1358
|
const encoder = getMemoizedU8Encoder();
|
|
1395
1359
|
return {
|
|
1396
1360
|
...encoder,
|
|
1397
|
-
description: description
|
|
1361
|
+
description: description != null ? description : encoder.description
|
|
1398
1362
|
};
|
|
1399
1363
|
}
|
|
1400
1364
|
var memoizedU8Decoder;
|
|
@@ -1407,7 +1371,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1407
1371
|
const decoder = getMemoizedU8Decoder();
|
|
1408
1372
|
return {
|
|
1409
1373
|
...decoder,
|
|
1410
|
-
description: description
|
|
1374
|
+
description: description != null ? description : decoder.description
|
|
1411
1375
|
};
|
|
1412
1376
|
}
|
|
1413
1377
|
var numSignerAccountsDescription = "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction" ;
|
|
@@ -1461,13 +1425,14 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1461
1425
|
]),
|
|
1462
1426
|
// Convert an instruction to have all fields defined
|
|
1463
1427
|
(instruction) => {
|
|
1428
|
+
var _a, _b;
|
|
1464
1429
|
if (instruction.accountIndices !== void 0 && instruction.data !== void 0) {
|
|
1465
1430
|
return instruction;
|
|
1466
1431
|
}
|
|
1467
1432
|
return {
|
|
1468
1433
|
...instruction,
|
|
1469
|
-
accountIndices: instruction.accountIndices
|
|
1470
|
-
data: instruction.data
|
|
1434
|
+
accountIndices: (_a = instruction.accountIndices) != null ? _a : [],
|
|
1435
|
+
data: (_b = instruction.data) != null ? _b : new Uint8Array(0)
|
|
1471
1436
|
};
|
|
1472
1437
|
}
|
|
1473
1438
|
);
|
|
@@ -1559,12 +1524,13 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1559
1524
|
["addressTableLookups", getAddressTableLookupArrayEncoder()]
|
|
1560
1525
|
]),
|
|
1561
1526
|
(value) => {
|
|
1527
|
+
var _a;
|
|
1562
1528
|
if (value.version === "legacy") {
|
|
1563
1529
|
return value;
|
|
1564
1530
|
}
|
|
1565
1531
|
return {
|
|
1566
1532
|
...value,
|
|
1567
|
-
addressTableLookups: value.addressTableLookups
|
|
1533
|
+
addressTableLookups: (_a = value.addressTableLookups) != null ? _a : []
|
|
1568
1534
|
};
|
|
1569
1535
|
}
|
|
1570
1536
|
);
|
|
@@ -1659,7 +1625,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1659
1625
|
description: messageDescription
|
|
1660
1626
|
}),
|
|
1661
1627
|
({ addressTableLookups, ...restOfMessage }) => {
|
|
1662
|
-
if (restOfMessage.version === "legacy" || !addressTableLookups
|
|
1628
|
+
if (restOfMessage.version === "legacy" || !(addressTableLookups == null ? void 0 : addressTableLookups.length)) {
|
|
1663
1629
|
return restOfMessage;
|
|
1664
1630
|
}
|
|
1665
1631
|
return { ...restOfMessage, addressTableLookups };
|
|
@@ -1728,65 +1694,26 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1728
1694
|
}
|
|
1729
1695
|
|
|
1730
1696
|
// src/signatures.ts
|
|
1731
|
-
|
|
1732
|
-
try {
|
|
1733
|
-
if (
|
|
1734
|
-
// Lowest value (64 bytes of zeroes)
|
|
1735
|
-
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
1736
|
-
putativeTransactionSignature.length > 88
|
|
1737
|
-
) {
|
|
1738
|
-
throw new Error("Expected input string to decode to a byte array of length 64.");
|
|
1739
|
-
}
|
|
1740
|
-
const bytes = base58.serialize(putativeTransactionSignature);
|
|
1741
|
-
const numBytes = bytes.byteLength;
|
|
1742
|
-
if (numBytes !== 64) {
|
|
1743
|
-
throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
|
|
1744
|
-
}
|
|
1745
|
-
} catch (e2) {
|
|
1746
|
-
throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, {
|
|
1747
|
-
cause: e2
|
|
1748
|
-
});
|
|
1749
|
-
}
|
|
1750
|
-
}
|
|
1751
|
-
function isTransactionSignature(putativeTransactionSignature) {
|
|
1752
|
-
if (
|
|
1753
|
-
// Lowest value (64 bytes of zeroes)
|
|
1754
|
-
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
1755
|
-
putativeTransactionSignature.length > 88
|
|
1756
|
-
) {
|
|
1757
|
-
return false;
|
|
1758
|
-
}
|
|
1759
|
-
const bytes = base58.serialize(putativeTransactionSignature);
|
|
1760
|
-
const numBytes = bytes.byteLength;
|
|
1761
|
-
if (numBytes !== 64) {
|
|
1762
|
-
return false;
|
|
1763
|
-
}
|
|
1764
|
-
return true;
|
|
1765
|
-
}
|
|
1766
|
-
async function getCompiledMessageSignature(message, secretKey) {
|
|
1767
|
-
const wireMessageBytes = getCompiledMessageEncoder().encode(message);
|
|
1768
|
-
const signature = await signBytes(secretKey, wireMessageBytes);
|
|
1769
|
-
return signature;
|
|
1770
|
-
}
|
|
1697
|
+
var base58Decoder;
|
|
1771
1698
|
function getSignatureFromTransaction(transaction) {
|
|
1699
|
+
if (!base58Decoder)
|
|
1700
|
+
base58Decoder = getBase58Decoder();
|
|
1772
1701
|
const signatureBytes = transaction.signatures[transaction.feePayer];
|
|
1773
1702
|
if (!signatureBytes) {
|
|
1774
1703
|
throw new Error(
|
|
1775
1704
|
"Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
|
|
1776
1705
|
);
|
|
1777
1706
|
}
|
|
1778
|
-
const
|
|
1779
|
-
return
|
|
1707
|
+
const transactionSignature = base58Decoder.decode(signatureBytes)[0];
|
|
1708
|
+
return transactionSignature;
|
|
1780
1709
|
}
|
|
1781
|
-
async function
|
|
1710
|
+
async function partiallySignTransaction(keyPairs, transaction) {
|
|
1782
1711
|
const compiledMessage = compileMessage(transaction);
|
|
1783
1712
|
const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
|
|
1713
|
+
const wireMessageBytes = getCompiledMessageEncoder().encode(compiledMessage);
|
|
1784
1714
|
const publicKeySignaturePairs = await Promise.all(
|
|
1785
1715
|
keyPairs.map(
|
|
1786
|
-
(keyPair) => Promise.all([
|
|
1787
|
-
getAddressFromPublicKey(keyPair.publicKey),
|
|
1788
|
-
getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
|
|
1789
|
-
])
|
|
1716
|
+
(keyPair) => Promise.all([getAddressFromPublicKey(keyPair.publicKey), signBytes(keyPair.privateKey, wireMessageBytes)])
|
|
1790
1717
|
)
|
|
1791
1718
|
);
|
|
1792
1719
|
for (const [signerPublicKey, signature] of publicKeySignaturePairs) {
|
|
@@ -1799,12 +1726,17 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1799
1726
|
Object.freeze(out);
|
|
1800
1727
|
return out;
|
|
1801
1728
|
}
|
|
1802
|
-
function
|
|
1803
|
-
|
|
1804
|
-
|
|
1729
|
+
async function signTransaction(keyPairs, transaction) {
|
|
1730
|
+
const out = await partiallySignTransaction(keyPairs, transaction);
|
|
1731
|
+
assertTransactionIsFullySigned(out);
|
|
1732
|
+
Object.freeze(out);
|
|
1733
|
+
return out;
|
|
1805
1734
|
}
|
|
1806
1735
|
function assertTransactionIsFullySigned(transaction) {
|
|
1807
|
-
const signerAddressesFromInstructions = transaction.instructions.flatMap((i) =>
|
|
1736
|
+
const signerAddressesFromInstructions = transaction.instructions.flatMap((i) => {
|
|
1737
|
+
var _a, _b;
|
|
1738
|
+
return (_b = (_a = i.accounts) == null ? void 0 : _a.filter((a) => isSignerRole(a.role))) != null ? _b : [];
|
|
1739
|
+
}).map((a) => a.address);
|
|
1808
1740
|
const requiredSigners = /* @__PURE__ */ new Set([transaction.feePayer, ...signerAddressesFromInstructions]);
|
|
1809
1741
|
requiredSigners.forEach((address2) => {
|
|
1810
1742
|
if (!transaction.signatures[address2]) {
|
|
@@ -1816,15 +1748,12 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1816
1748
|
// src/wire-transaction.ts
|
|
1817
1749
|
function getBase64EncodedWireTransaction(transaction) {
|
|
1818
1750
|
const wireTransactionBytes = getTransactionEncoder().encode(transaction);
|
|
1819
|
-
|
|
1820
|
-
return btoa(String.fromCharCode(...wireTransactionBytes));
|
|
1821
|
-
}
|
|
1751
|
+
return getBase64Decoder().decode(wireTransactionBytes)[0];
|
|
1822
1752
|
}
|
|
1823
1753
|
|
|
1824
1754
|
exports.appendTransactionInstruction = appendTransactionInstruction;
|
|
1825
1755
|
exports.assertIsBlockhash = assertIsBlockhash;
|
|
1826
1756
|
exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
|
|
1827
|
-
exports.assertIsTransactionSignature = assertIsTransactionSignature;
|
|
1828
1757
|
exports.assertTransactionIsFullySigned = assertTransactionIsFullySigned;
|
|
1829
1758
|
exports.createTransaction = createTransaction;
|
|
1830
1759
|
exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
|
|
@@ -1833,13 +1762,12 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1833
1762
|
exports.getTransactionDecoder = getTransactionDecoder;
|
|
1834
1763
|
exports.getTransactionEncoder = getTransactionEncoder;
|
|
1835
1764
|
exports.isAdvanceNonceAccountInstruction = isAdvanceNonceAccountInstruction;
|
|
1836
|
-
exports.
|
|
1765
|
+
exports.partiallySignTransaction = partiallySignTransaction;
|
|
1837
1766
|
exports.prependTransactionInstruction = prependTransactionInstruction;
|
|
1838
1767
|
exports.setTransactionFeePayer = setTransactionFeePayer;
|
|
1839
1768
|
exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
|
|
1840
1769
|
exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
|
|
1841
1770
|
exports.signTransaction = signTransaction;
|
|
1842
|
-
exports.transactionSignature = transactionSignature;
|
|
1843
1771
|
|
|
1844
1772
|
return exports;
|
|
1845
1773
|
|