@solana/transactions 2.0.0-experimental.fc4e943 → 2.0.0-experimental.fcff844
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 +272 -5
- package/dist/index.browser.cjs +411 -334
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +405 -337
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +941 -1142
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +405 -335
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +411 -336
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +405 -335
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +23 -16
- package/dist/types/accounts.d.ts +2 -2
- package/dist/types/accounts.d.ts.map +1 -0
- package/dist/types/blockhash.d.ts +1 -0
- package/dist/types/blockhash.d.ts.map +1 -0
- package/dist/types/compilable-transaction.d.ts +7 -0
- package/dist/types/compilable-transaction.d.ts.map +1 -0
- package/dist/types/compile-address-table-lookups.d.ts +2 -2
- package/dist/types/compile-address-table-lookups.d.ts.map +1 -0
- package/dist/types/compile-header.d.ts.map +1 -0
- package/dist/types/compile-instructions.d.ts.map +1 -0
- package/dist/types/compile-lifetime-token.d.ts.map +1 -0
- package/dist/types/compile-static-accounts.d.ts +2 -2
- package/dist/types/compile-static-accounts.d.ts.map +1 -0
- package/dist/types/compile-transaction.d.ts +5 -6
- package/dist/types/compile-transaction.d.ts.map +1 -0
- package/dist/types/create-transaction.d.ts.map +1 -0
- package/dist/types/decompile-transaction.d.ts +5 -0
- package/dist/types/decompile-transaction.d.ts.map +1 -0
- package/dist/types/durable-nonce.d.ts +6 -6
- package/dist/types/durable-nonce.d.ts.map +1 -0
- package/dist/types/fee-payer.d.ts +4 -4
- package/dist/types/fee-payer.d.ts.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/instructions.d.ts.map +1 -0
- package/dist/types/message.d.ts +1 -5
- package/dist/types/message.d.ts.map +1 -0
- package/dist/types/serializers/address-table-lookup.d.ts +5 -3
- package/dist/types/serializers/address-table-lookup.d.ts.map +1 -0
- package/dist/types/serializers/header.d.ts +4 -4
- package/dist/types/serializers/header.d.ts.map +1 -0
- package/dist/types/serializers/index.d.ts +1 -0
- package/dist/types/serializers/index.d.ts.map +1 -0
- package/dist/types/serializers/instruction.d.ts +4 -2
- package/dist/types/serializers/instruction.d.ts.map +1 -0
- package/dist/types/serializers/message.d.ts +4 -4
- package/dist/types/serializers/message.d.ts.map +1 -0
- package/dist/types/serializers/transaction-version.d.ts +4 -4
- package/dist/types/serializers/transaction-version.d.ts.map +1 -0
- package/dist/types/serializers/transaction.d.ts +6 -5
- package/dist/types/serializers/transaction.d.ts.map +1 -0
- package/dist/types/signatures.d.ts +8 -12
- package/dist/types/signatures.d.ts.map +1 -0
- package/dist/types/types.d.ts +6 -13
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/unsigned-transaction.d.ts.map +1 -0
- package/dist/types/wire-transaction.d.ts +1 -1
- package/dist/types/wire-transaction.d.ts.map +1 -0
- package/package.json +15 -14
- package/dist/types/serializers/unimplemented.d.ts +0 -3
|
@@ -2,282 +2,198 @@ this.globalThis = this.globalThis || {};
|
|
|
2
2
|
this.globalThis.solanaWeb3 = (function (exports) {
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
});
|
|
21
|
-
return result;
|
|
22
|
-
};
|
|
23
|
-
var padBytes = (bytes2, length) => {
|
|
24
|
-
if (bytes2.length >= length)
|
|
25
|
-
return bytes2;
|
|
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 padBytes = (bytes, length) => {
|
|
18
|
+
if (bytes.length >= length)
|
|
19
|
+
return bytes;
|
|
26
20
|
const paddedBytes = new Uint8Array(length).fill(0);
|
|
27
|
-
paddedBytes.set(
|
|
21
|
+
paddedBytes.set(bytes);
|
|
28
22
|
return paddedBytes;
|
|
29
23
|
};
|
|
30
|
-
var fixBytes = (
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
24
|
+
var fixBytes = (bytes, length) => padBytes(bytes.length <= length ? bytes : bytes.slice(0, length), length);
|
|
25
|
+
function getEncodedSize(value, encoder) {
|
|
26
|
+
return "fixedSize" in encoder ? encoder.fixedSize : encoder.getSizeFromValue(value);
|
|
27
|
+
}
|
|
28
|
+
function createEncoder(encoder) {
|
|
29
|
+
return Object.freeze({
|
|
30
|
+
...encoder,
|
|
31
|
+
encode: (value) => {
|
|
32
|
+
const bytes = new Uint8Array(getEncodedSize(value, encoder));
|
|
33
|
+
encoder.write(value, bytes, 0);
|
|
34
|
+
return bytes;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
function createDecoder(decoder) {
|
|
39
|
+
return Object.freeze({
|
|
40
|
+
...decoder,
|
|
41
|
+
decode: (bytes, offset = 0) => decoder.read(bytes, offset)[0]
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
function isFixedSize(codec) {
|
|
45
|
+
return "fixedSize" in codec && typeof codec.fixedSize === "number";
|
|
46
|
+
}
|
|
47
|
+
function assertIsFixedSize(codec, message) {
|
|
48
|
+
if (!isFixedSize(codec)) {
|
|
49
|
+
throw new Error(message != null ? message : "Expected a fixed-size codec, got a variable-size one.");
|
|
37
50
|
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
51
|
+
}
|
|
52
|
+
function isVariableSize(codec) {
|
|
53
|
+
return !isFixedSize(codec);
|
|
54
|
+
}
|
|
55
|
+
function combineCodec(encoder, decoder) {
|
|
56
|
+
if (isFixedSize(encoder) !== isFixedSize(decoder)) {
|
|
57
|
+
throw new Error(`Encoder and decoder must either both be fixed-size or variable-size.`);
|
|
43
58
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
59
|
+
if (isFixedSize(encoder) && isFixedSize(decoder) && encoder.fixedSize !== decoder.fixedSize) {
|
|
60
|
+
throw new Error(
|
|
61
|
+
`Encoder and decoder must have the same fixed size, got [${encoder.fixedSize}] and [${decoder.fixedSize}].`
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
if (!isFixedSize(encoder) && !isFixedSize(decoder) && encoder.maxSize !== decoder.maxSize) {
|
|
65
|
+
throw new Error(
|
|
66
|
+
`Encoder and decoder must have the same max size, got [${encoder.maxSize}] and [${decoder.maxSize}].`
|
|
67
|
+
);
|
|
50
68
|
}
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/fixSerializer.mjs
|
|
54
|
-
function fixSerializer(serializer, fixedBytes, description) {
|
|
55
69
|
return {
|
|
56
|
-
|
|
70
|
+
...decoder,
|
|
71
|
+
...encoder,
|
|
72
|
+
decode: decoder.decode,
|
|
73
|
+
encode: encoder.encode,
|
|
74
|
+
read: decoder.read,
|
|
75
|
+
write: encoder.write
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function fixEncoder(encoder, fixedBytes) {
|
|
79
|
+
return createEncoder({
|
|
80
|
+
fixedSize: fixedBytes,
|
|
81
|
+
write: (value, bytes, offset) => {
|
|
82
|
+
const variableByteArray = encoder.encode(value);
|
|
83
|
+
const fixedByteArray = variableByteArray.length > fixedBytes ? variableByteArray.slice(0, fixedBytes) : variableByteArray;
|
|
84
|
+
bytes.set(fixedByteArray, offset);
|
|
85
|
+
return offset + fixedBytes;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
function fixDecoder(decoder, fixedBytes) {
|
|
90
|
+
return createDecoder({
|
|
57
91
|
fixedSize: fixedBytes,
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (buffer.length < fixedBytes) {
|
|
63
|
-
throw new NotEnoughBytesError("fixSerializer", fixedBytes, buffer.length);
|
|
92
|
+
read: (bytes, offset) => {
|
|
93
|
+
assertByteArrayHasEnoughBytesForCodec("fixCodec", fixedBytes, bytes, offset);
|
|
94
|
+
if (offset > 0 || bytes.length > fixedBytes) {
|
|
95
|
+
bytes = bytes.slice(offset, offset + fixedBytes);
|
|
64
96
|
}
|
|
65
|
-
if (
|
|
66
|
-
|
|
97
|
+
if (isFixedSize(decoder)) {
|
|
98
|
+
bytes = fixBytes(bytes, decoder.fixedSize);
|
|
67
99
|
}
|
|
68
|
-
const [value] =
|
|
100
|
+
const [value] = decoder.read(bytes, 0);
|
|
69
101
|
return [value, offset + fixedBytes];
|
|
70
102
|
}
|
|
71
|
-
};
|
|
103
|
+
});
|
|
72
104
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
fixedSize: serializer.fixedSize,
|
|
79
|
-
maxSize: serializer.maxSize,
|
|
80
|
-
serialize: (value) => serializer.serialize(unmap(value)),
|
|
81
|
-
deserialize: (buffer, offset = 0) => {
|
|
82
|
-
const [value, length] = serializer.deserialize(buffer, offset);
|
|
83
|
-
return map ? [map(value, buffer, offset), length] : [value, length];
|
|
84
|
-
}
|
|
85
|
-
};
|
|
105
|
+
function mapEncoder(encoder, unmap) {
|
|
106
|
+
return createEncoder({
|
|
107
|
+
...isVariableSize(encoder) ? { ...encoder, getSizeFromValue: (value) => encoder.getSizeFromValue(unmap(value)) } : encoder,
|
|
108
|
+
write: (value, bytes, offset) => encoder.write(unmap(value), bytes, offset)
|
|
109
|
+
});
|
|
86
110
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
__publicField(this, "name", "InvalidBaseStringError");
|
|
94
|
-
this.cause = cause;
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/baseX.mjs
|
|
99
|
-
var baseX = (alphabet) => {
|
|
100
|
-
const base = alphabet.length;
|
|
101
|
-
const baseBigInt = BigInt(base);
|
|
102
|
-
return {
|
|
103
|
-
description: `base${base}`,
|
|
104
|
-
fixedSize: null,
|
|
105
|
-
maxSize: null,
|
|
106
|
-
serialize(value) {
|
|
107
|
-
if (!value.match(new RegExp(`^[${alphabet}]*$`))) {
|
|
108
|
-
throw new InvalidBaseStringError(value, base);
|
|
109
|
-
}
|
|
110
|
-
if (value === "")
|
|
111
|
-
return new Uint8Array();
|
|
112
|
-
const chars = [...value];
|
|
113
|
-
let trailIndex = chars.findIndex((c) => c !== alphabet[0]);
|
|
114
|
-
trailIndex = trailIndex === -1 ? chars.length : trailIndex;
|
|
115
|
-
const leadingZeroes = Array(trailIndex).fill(0);
|
|
116
|
-
if (trailIndex === chars.length)
|
|
117
|
-
return Uint8Array.from(leadingZeroes);
|
|
118
|
-
const tailChars = chars.slice(trailIndex);
|
|
119
|
-
let base10Number = 0n;
|
|
120
|
-
let baseXPower = 1n;
|
|
121
|
-
for (let i = tailChars.length - 1; i >= 0; i -= 1) {
|
|
122
|
-
base10Number += baseXPower * BigInt(alphabet.indexOf(tailChars[i]));
|
|
123
|
-
baseXPower *= baseBigInt;
|
|
124
|
-
}
|
|
125
|
-
const tailBytes = [];
|
|
126
|
-
while (base10Number > 0n) {
|
|
127
|
-
tailBytes.unshift(Number(base10Number % 256n));
|
|
128
|
-
base10Number /= 256n;
|
|
129
|
-
}
|
|
130
|
-
return Uint8Array.from(leadingZeroes.concat(tailBytes));
|
|
131
|
-
},
|
|
132
|
-
deserialize(buffer, offset = 0) {
|
|
133
|
-
if (buffer.length === 0)
|
|
134
|
-
return ["", 0];
|
|
135
|
-
const bytes2 = buffer.slice(offset);
|
|
136
|
-
let trailIndex = bytes2.findIndex((n) => n !== 0);
|
|
137
|
-
trailIndex = trailIndex === -1 ? bytes2.length : trailIndex;
|
|
138
|
-
const leadingZeroes = alphabet[0].repeat(trailIndex);
|
|
139
|
-
if (trailIndex === bytes2.length)
|
|
140
|
-
return [leadingZeroes, buffer.length];
|
|
141
|
-
let base10Number = bytes2.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
|
|
142
|
-
const tailChars = [];
|
|
143
|
-
while (base10Number > 0n) {
|
|
144
|
-
tailChars.unshift(alphabet[Number(base10Number % baseBigInt)]);
|
|
145
|
-
base10Number /= baseBigInt;
|
|
146
|
-
}
|
|
147
|
-
return [leadingZeroes + tailChars.join(""), buffer.length];
|
|
111
|
+
function mapDecoder(decoder, map) {
|
|
112
|
+
return createDecoder({
|
|
113
|
+
...decoder,
|
|
114
|
+
read: (bytes, offset) => {
|
|
115
|
+
const [value, newOffset] = decoder.read(bytes, offset);
|
|
116
|
+
return [map(value, bytes, offset), newOffset];
|
|
148
117
|
}
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/base58.mjs
|
|
153
|
-
var base58 = baseX("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
|
|
154
|
-
|
|
155
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/nullCharacters.mjs
|
|
156
|
-
var removeNullCharacters = (value) => (
|
|
157
|
-
// eslint-disable-next-line no-control-regex
|
|
158
|
-
value.replace(/\u0000/g, "")
|
|
159
|
-
);
|
|
160
|
-
|
|
161
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/utf8.mjs
|
|
162
|
-
var utf8 = {
|
|
163
|
-
description: "utf8",
|
|
164
|
-
fixedSize: null,
|
|
165
|
-
maxSize: null,
|
|
166
|
-
serialize(value) {
|
|
167
|
-
return new TextEncoder().encode(value);
|
|
168
|
-
},
|
|
169
|
-
deserialize(buffer, offset = 0) {
|
|
170
|
-
const value = new TextDecoder().decode(buffer.slice(offset));
|
|
171
|
-
return [removeNullCharacters(value), buffer.length];
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/common.mjs
|
|
176
|
-
var Endian;
|
|
177
|
-
(function(Endian2) {
|
|
178
|
-
Endian2["Little"] = "le";
|
|
179
|
-
Endian2["Big"] = "be";
|
|
180
|
-
})(Endian || (Endian = {}));
|
|
181
|
-
|
|
182
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/errors.mjs
|
|
183
|
-
var NumberOutOfRangeError = class extends RangeError {
|
|
184
|
-
constructor(serializer, min, max, actual) {
|
|
185
|
-
super(`Serializer [${serializer}] expected number to be between ${min} and ${max}, got ${actual}.`);
|
|
186
|
-
__publicField(this, "name", "NumberOutOfRangeError");
|
|
187
|
-
}
|
|
188
|
-
};
|
|
118
|
+
});
|
|
119
|
+
}
|
|
189
120
|
|
|
190
|
-
//
|
|
191
|
-
function
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
defaultDescription += littleEndian ? "(le)" : "(be)";
|
|
121
|
+
// ../codecs-numbers/dist/index.browser.js
|
|
122
|
+
function assertNumberIsBetweenForCodec(codecDescription, min, max, value) {
|
|
123
|
+
if (value < min || value > max) {
|
|
124
|
+
throw new Error(
|
|
125
|
+
`Codec [${codecDescription}] expected number to be in the range [${min}, ${max}], got ${value}.`
|
|
126
|
+
);
|
|
197
127
|
}
|
|
198
|
-
|
|
199
|
-
|
|
128
|
+
}
|
|
129
|
+
function isLittleEndian(config) {
|
|
130
|
+
return (config == null ? void 0 : config.endian) === 1 ? false : true;
|
|
131
|
+
}
|
|
132
|
+
function numberEncoderFactory(input) {
|
|
133
|
+
return createEncoder({
|
|
200
134
|
fixedSize: input.size,
|
|
201
|
-
|
|
202
|
-
serialize(value) {
|
|
135
|
+
write(value, bytes, offset) {
|
|
203
136
|
if (input.range) {
|
|
204
|
-
|
|
137
|
+
assertNumberIsBetweenForCodec(input.name, input.range[0], input.range[1], value);
|
|
205
138
|
}
|
|
206
|
-
const
|
|
207
|
-
input.set(new DataView(
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
deserialize(bytes2, offset = 0) {
|
|
211
|
-
const slice = bytes2.slice(offset, offset + input.size);
|
|
212
|
-
assertEnoughBytes("i8", slice, input.size);
|
|
213
|
-
const view = toDataView(slice);
|
|
214
|
-
return [input.get(view, littleEndian), offset + input.size];
|
|
139
|
+
const arrayBuffer = new ArrayBuffer(input.size);
|
|
140
|
+
input.set(new DataView(arrayBuffer), value, isLittleEndian(input.config));
|
|
141
|
+
bytes.set(new Uint8Array(arrayBuffer), offset);
|
|
142
|
+
return offset + input.size;
|
|
215
143
|
}
|
|
216
|
-
};
|
|
144
|
+
});
|
|
217
145
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/u32.mjs
|
|
245
|
-
var u32 = (options = {}) => numberFactory({
|
|
246
|
-
name: "u32",
|
|
247
|
-
size: 4,
|
|
248
|
-
range: [0, Number("0xffffffff")],
|
|
249
|
-
set: (view, value, le) => view.setUint32(0, Number(value), le),
|
|
250
|
-
get: (view, le) => view.getUint32(0, le),
|
|
251
|
-
options
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/shortU16.mjs
|
|
255
|
-
var shortU16 = (options = {}) => ({
|
|
256
|
-
description: options.description ?? "shortU16",
|
|
257
|
-
fixedSize: null,
|
|
146
|
+
function numberDecoderFactory(input) {
|
|
147
|
+
return createDecoder({
|
|
148
|
+
fixedSize: input.size,
|
|
149
|
+
read(bytes, offset = 0) {
|
|
150
|
+
assertByteArrayIsNotEmptyForCodec(input.name, bytes, offset);
|
|
151
|
+
assertByteArrayHasEnoughBytesForCodec(input.name, input.size, bytes, offset);
|
|
152
|
+
const view = new DataView(toArrayBuffer(bytes, offset, input.size));
|
|
153
|
+
return [input.get(view, isLittleEndian(input.config)), offset + input.size];
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
function toArrayBuffer(bytes, offset, length) {
|
|
158
|
+
const bytesOffset = bytes.byteOffset + (offset != null ? offset : 0);
|
|
159
|
+
const bytesLength = length != null ? length : bytes.byteLength;
|
|
160
|
+
return bytes.buffer.slice(bytesOffset, bytesOffset + bytesLength);
|
|
161
|
+
}
|
|
162
|
+
var getShortU16Encoder = () => createEncoder({
|
|
163
|
+
getSizeFromValue: (value) => {
|
|
164
|
+
if (value <= 127)
|
|
165
|
+
return 1;
|
|
166
|
+
if (value <= 16383)
|
|
167
|
+
return 2;
|
|
168
|
+
return 3;
|
|
169
|
+
},
|
|
258
170
|
maxSize: 3,
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
const
|
|
171
|
+
write: (value, bytes, offset) => {
|
|
172
|
+
assertNumberIsBetweenForCodec("shortU16", 0, 65535, value);
|
|
173
|
+
const shortU16Bytes = [0];
|
|
262
174
|
for (let ii = 0; ; ii += 1) {
|
|
263
175
|
const alignedValue = value >> ii * 7;
|
|
264
176
|
if (alignedValue === 0) {
|
|
265
177
|
break;
|
|
266
178
|
}
|
|
267
179
|
const nextSevenBits = 127 & alignedValue;
|
|
268
|
-
|
|
180
|
+
shortU16Bytes[ii] = nextSevenBits;
|
|
269
181
|
if (ii > 0) {
|
|
270
|
-
|
|
182
|
+
shortU16Bytes[ii - 1] |= 128;
|
|
271
183
|
}
|
|
272
184
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
185
|
+
bytes.set(shortU16Bytes, offset);
|
|
186
|
+
return offset + shortU16Bytes.length;
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
var getShortU16Decoder = () => createDecoder({
|
|
190
|
+
maxSize: 3,
|
|
191
|
+
read: (bytes, offset) => {
|
|
276
192
|
let value = 0;
|
|
277
193
|
let byteCount = 0;
|
|
278
194
|
while (++byteCount) {
|
|
279
195
|
const byteIndex = byteCount - 1;
|
|
280
|
-
const currentByte =
|
|
196
|
+
const currentByte = bytes[offset + byteIndex];
|
|
281
197
|
const nextSevenBits = 127 & currentByte;
|
|
282
198
|
value |= nextSevenBits << byteIndex * 7;
|
|
283
199
|
if ((currentByte & 128) === 0) {
|
|
@@ -287,210 +203,186 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
287
203
|
return [value, offset + byteCount];
|
|
288
204
|
}
|
|
289
205
|
});
|
|
206
|
+
var getU32Encoder = (config = {}) => numberEncoderFactory({
|
|
207
|
+
config,
|
|
208
|
+
name: "u32",
|
|
209
|
+
range: [0, Number("0xffffffff")],
|
|
210
|
+
set: (view, value, le) => view.setUint32(0, value, le),
|
|
211
|
+
size: 4
|
|
212
|
+
});
|
|
213
|
+
var getU32Decoder = (config = {}) => numberDecoderFactory({
|
|
214
|
+
config,
|
|
215
|
+
get: (view, le) => view.getUint32(0, le),
|
|
216
|
+
name: "u32",
|
|
217
|
+
size: 4
|
|
218
|
+
});
|
|
219
|
+
var getU8Encoder = () => numberEncoderFactory({
|
|
220
|
+
name: "u8",
|
|
221
|
+
range: [0, Number("0xff")],
|
|
222
|
+
set: (view, value) => view.setUint8(0, value),
|
|
223
|
+
size: 1
|
|
224
|
+
});
|
|
225
|
+
var getU8Decoder = () => numberDecoderFactory({
|
|
226
|
+
get: (view) => view.getUint8(0),
|
|
227
|
+
name: "u8",
|
|
228
|
+
size: 1
|
|
229
|
+
});
|
|
290
230
|
|
|
291
|
-
//
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
__publicField(this, "name", "InvalidNumberOfItemsError");
|
|
296
|
-
}
|
|
297
|
-
};
|
|
298
|
-
var InvalidArrayLikeRemainderSizeError = class extends Error {
|
|
299
|
-
constructor(remainderSize, itemSize) {
|
|
300
|
-
super(`The remainder of the buffer (${remainderSize} bytes) cannot be split into chunks of ${itemSize} bytes. Serializers of "remainder" size must have a remainder that is a multiple of its item size. In other words, ${remainderSize} modulo ${itemSize} should be equal to zero.`);
|
|
301
|
-
__publicField(this, "name", "InvalidArrayLikeRemainderSizeError");
|
|
302
|
-
}
|
|
303
|
-
};
|
|
304
|
-
var UnrecognizedArrayLikeSerializerSizeError = class extends Error {
|
|
305
|
-
constructor(size) {
|
|
306
|
-
super(`Unrecognized array-like serializer size: ${JSON.stringify(size)}`);
|
|
307
|
-
__publicField(this, "name", "UnrecognizedArrayLikeSerializerSizeError");
|
|
231
|
+
// ../codecs-strings/dist/index.browser.js
|
|
232
|
+
function assertValidBaseString(alphabet4, testValue, givenValue = testValue) {
|
|
233
|
+
if (!testValue.match(new RegExp(`^[${alphabet4}]*$`))) {
|
|
234
|
+
throw new Error(`Expected a string of base ${alphabet4.length}, got [${givenValue}].`);
|
|
308
235
|
}
|
|
309
|
-
};
|
|
310
|
-
|
|
311
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/sumSerializerSizes.mjs
|
|
312
|
-
function sumSerializerSizes(sizes) {
|
|
313
|
-
return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
|
|
314
236
|
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
237
|
+
var getBaseXEncoder = (alphabet4) => {
|
|
238
|
+
return createEncoder({
|
|
239
|
+
getSizeFromValue: (value) => {
|
|
240
|
+
const [leadingZeroes, tailChars] = partitionLeadingZeroes(value, alphabet4[0]);
|
|
241
|
+
if (tailChars === "")
|
|
242
|
+
return value.length;
|
|
243
|
+
const base10Number = getBigIntFromBaseX(tailChars, alphabet4);
|
|
244
|
+
return leadingZeroes.length + Math.ceil(base10Number.toString(16).length / 2);
|
|
245
|
+
},
|
|
246
|
+
write(value, bytes, offset) {
|
|
247
|
+
assertValidBaseString(alphabet4, value);
|
|
248
|
+
if (value === "")
|
|
249
|
+
return offset;
|
|
250
|
+
const [leadingZeroes, tailChars] = partitionLeadingZeroes(value, alphabet4[0]);
|
|
251
|
+
if (tailChars === "") {
|
|
252
|
+
bytes.set(new Uint8Array(leadingZeroes.length).fill(0), offset);
|
|
253
|
+
return offset + leadingZeroes.length;
|
|
254
|
+
}
|
|
255
|
+
let base10Number = getBigIntFromBaseX(tailChars, alphabet4);
|
|
256
|
+
const tailBytes = [];
|
|
257
|
+
while (base10Number > 0n) {
|
|
258
|
+
tailBytes.unshift(Number(base10Number % 256n));
|
|
259
|
+
base10Number /= 256n;
|
|
260
|
+
}
|
|
261
|
+
const bytesToAdd = [...Array(leadingZeroes.length).fill(0), ...tailBytes];
|
|
262
|
+
bytes.set(bytesToAdd, offset);
|
|
263
|
+
return offset + bytesToAdd.length;
|
|
328
264
|
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
265
|
+
});
|
|
266
|
+
};
|
|
267
|
+
var getBaseXDecoder = (alphabet4) => {
|
|
268
|
+
return createDecoder({
|
|
269
|
+
read(rawBytes, offset) {
|
|
270
|
+
const bytes = offset === 0 ? rawBytes : rawBytes.slice(offset);
|
|
271
|
+
if (bytes.length === 0)
|
|
272
|
+
return ["", 0];
|
|
273
|
+
let trailIndex = bytes.findIndex((n) => n !== 0);
|
|
274
|
+
trailIndex = trailIndex === -1 ? bytes.length : trailIndex;
|
|
275
|
+
const leadingZeroes = alphabet4[0].repeat(trailIndex);
|
|
276
|
+
if (trailIndex === bytes.length)
|
|
277
|
+
return [leadingZeroes, rawBytes.length];
|
|
278
|
+
const base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
|
|
279
|
+
const tailChars = getBaseXFromBigInt(base10Number, alphabet4);
|
|
280
|
+
return [leadingZeroes + tailChars, rawBytes.length];
|
|
332
281
|
}
|
|
333
|
-
|
|
282
|
+
});
|
|
283
|
+
};
|
|
284
|
+
function partitionLeadingZeroes(value, zeroCharacter) {
|
|
285
|
+
const leadingZeroIndex = [...value].findIndex((c) => c !== zeroCharacter);
|
|
286
|
+
return leadingZeroIndex === -1 ? [value, ""] : [value.slice(0, leadingZeroIndex), value.slice(leadingZeroIndex)];
|
|
287
|
+
}
|
|
288
|
+
function getBigIntFromBaseX(value, alphabet4) {
|
|
289
|
+
const base = BigInt(alphabet4.length);
|
|
290
|
+
return [...value].reduce((sum, char) => sum * base + BigInt(alphabet4.indexOf(char)), 0n);
|
|
291
|
+
}
|
|
292
|
+
function getBaseXFromBigInt(value, alphabet4) {
|
|
293
|
+
const base = BigInt(alphabet4.length);
|
|
294
|
+
const tailChars = [];
|
|
295
|
+
while (value > 0n) {
|
|
296
|
+
tailChars.unshift(alphabet4[Number(value % base)]);
|
|
297
|
+
value /= base;
|
|
334
298
|
}
|
|
335
|
-
|
|
336
|
-
}
|
|
337
|
-
function getSizeDescription(size) {
|
|
338
|
-
return typeof size === "object" ? size.description : `${size}`;
|
|
339
|
-
}
|
|
340
|
-
function getSizeFromChildren(size, childrenSizes) {
|
|
341
|
-
if (typeof size !== "number")
|
|
342
|
-
return null;
|
|
343
|
-
if (size === 0)
|
|
344
|
-
return 0;
|
|
345
|
-
const childrenSize = sumSerializerSizes(childrenSizes);
|
|
346
|
-
return childrenSize === null ? null : childrenSize * size;
|
|
347
|
-
}
|
|
348
|
-
function getSizePrefix(size, realSize) {
|
|
349
|
-
return typeof size === "object" ? size.serialize(realSize) : new Uint8Array();
|
|
299
|
+
return tailChars.join("");
|
|
350
300
|
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
maxSize: getSizeFromChildren(size, [item.maxSize]),
|
|
362
|
-
serialize: (value) => {
|
|
363
|
-
if (typeof size === "number" && value.length !== size) {
|
|
364
|
-
throw new InvalidNumberOfItemsError("array", size, value.length);
|
|
365
|
-
}
|
|
366
|
-
return mergeBytes([getSizePrefix(size, value.length), ...value.map((v) => item.serialize(v))]);
|
|
367
|
-
},
|
|
368
|
-
deserialize: (bytes2, offset = 0) => {
|
|
369
|
-
if (typeof size === "object" && bytes2.slice(offset).length === 0) {
|
|
370
|
-
return [[], offset];
|
|
371
|
-
}
|
|
372
|
-
const [resolvedSize, newOffset] = getResolvedSize(size, [item.fixedSize], bytes2, offset);
|
|
373
|
-
offset = newOffset;
|
|
374
|
-
const values = [];
|
|
375
|
-
for (let i = 0; i < resolvedSize; i += 1) {
|
|
376
|
-
const [value, newOffset2] = item.deserialize(bytes2, offset);
|
|
377
|
-
values.push(value);
|
|
378
|
-
offset = newOffset2;
|
|
301
|
+
var alphabet2 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
302
|
+
var getBase58Encoder = () => getBaseXEncoder(alphabet2);
|
|
303
|
+
var getBase58Decoder = () => getBaseXDecoder(alphabet2);
|
|
304
|
+
var getBase64Decoder = () => {
|
|
305
|
+
{
|
|
306
|
+
return createDecoder({
|
|
307
|
+
read(bytes, offset = 0) {
|
|
308
|
+
const slice = bytes.slice(offset);
|
|
309
|
+
const value = btoa(String.fromCharCode(...slice));
|
|
310
|
+
return [value, bytes.length];
|
|
379
311
|
}
|
|
380
|
-
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
var removeNullCharacters = (value) => (
|
|
316
|
+
// eslint-disable-next-line no-control-regex
|
|
317
|
+
value.replace(/\u0000/g, "")
|
|
318
|
+
);
|
|
319
|
+
var e = globalThis.TextDecoder;
|
|
320
|
+
var o = globalThis.TextEncoder;
|
|
321
|
+
var getUtf8Encoder = () => {
|
|
322
|
+
let textEncoder;
|
|
323
|
+
return createEncoder({
|
|
324
|
+
getSizeFromValue: (value) => (textEncoder || (textEncoder = new o())).encode(value).length,
|
|
325
|
+
write: (value, bytes, offset) => {
|
|
326
|
+
const bytesToAdd = (textEncoder || (textEncoder = new o())).encode(value);
|
|
327
|
+
bytes.set(bytesToAdd, offset);
|
|
328
|
+
return offset + bytesToAdd.length;
|
|
381
329
|
}
|
|
382
|
-
};
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
description,
|
|
391
|
-
fixedSize: null,
|
|
392
|
-
maxSize: null,
|
|
393
|
-
serialize: (value) => new Uint8Array(value),
|
|
394
|
-
deserialize: (bytes2, offset = 0) => {
|
|
395
|
-
const slice = bytes2.slice(offset);
|
|
396
|
-
return [slice, offset + slice.length];
|
|
330
|
+
});
|
|
331
|
+
};
|
|
332
|
+
var getUtf8Decoder = () => {
|
|
333
|
+
let textDecoder;
|
|
334
|
+
return createDecoder({
|
|
335
|
+
read(bytes, offset) {
|
|
336
|
+
const value = (textDecoder || (textDecoder = new e())).decode(bytes.slice(offset));
|
|
337
|
+
return [removeNullCharacters(value), bytes.length];
|
|
397
338
|
}
|
|
398
|
-
};
|
|
339
|
+
});
|
|
340
|
+
};
|
|
341
|
+
function getStringEncoder(config = {}) {
|
|
342
|
+
var _a, _b;
|
|
343
|
+
const size = (_a = config.size) != null ? _a : getU32Encoder();
|
|
344
|
+
const encoding = (_b = config.encoding) != null ? _b : getUtf8Encoder();
|
|
399
345
|
if (size === "variable") {
|
|
400
|
-
return
|
|
346
|
+
return encoding;
|
|
401
347
|
}
|
|
402
348
|
if (typeof size === "number") {
|
|
403
|
-
return
|
|
349
|
+
return fixEncoder(encoding, size);
|
|
404
350
|
}
|
|
405
|
-
return {
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
serialize: (value) => {
|
|
410
|
-
const contentBytes = byteSerializer.serialize(value);
|
|
411
|
-
const lengthBytes = size.serialize(contentBytes.length);
|
|
412
|
-
return mergeBytes([lengthBytes, contentBytes]);
|
|
351
|
+
return createEncoder({
|
|
352
|
+
getSizeFromValue: (value) => {
|
|
353
|
+
const contentSize = getEncodedSize(value, encoding);
|
|
354
|
+
return getEncodedSize(contentSize, size) + contentSize;
|
|
413
355
|
},
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
const [lengthBigInt, lengthOffset] = size.deserialize(buffer, offset);
|
|
419
|
-
const length = Number(lengthBigInt);
|
|
420
|
-
offset = lengthOffset;
|
|
421
|
-
const contentBuffer = buffer.slice(offset, offset + length);
|
|
422
|
-
if (contentBuffer.length < length) {
|
|
423
|
-
throw new NotEnoughBytesError("bytes", length, contentBuffer.length);
|
|
424
|
-
}
|
|
425
|
-
const [value, contentOffset] = byteSerializer.deserialize(contentBuffer);
|
|
426
|
-
offset += contentOffset;
|
|
427
|
-
return [value, offset];
|
|
356
|
+
write: (value, bytes, offset) => {
|
|
357
|
+
const contentSize = getEncodedSize(value, encoding);
|
|
358
|
+
offset = size.write(contentSize, bytes, offset);
|
|
359
|
+
return encoding.write(value, bytes, offset);
|
|
428
360
|
}
|
|
429
|
-
};
|
|
361
|
+
});
|
|
430
362
|
}
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
const
|
|
435
|
-
const encoding = options.encoding ?? utf8;
|
|
436
|
-
const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
|
|
363
|
+
function getStringDecoder(config = {}) {
|
|
364
|
+
var _a, _b;
|
|
365
|
+
const size = (_a = config.size) != null ? _a : getU32Decoder();
|
|
366
|
+
const encoding = (_b = config.encoding) != null ? _b : getUtf8Decoder();
|
|
437
367
|
if (size === "variable") {
|
|
438
|
-
return
|
|
439
|
-
...encoding,
|
|
440
|
-
description
|
|
441
|
-
};
|
|
368
|
+
return encoding;
|
|
442
369
|
}
|
|
443
370
|
if (typeof size === "number") {
|
|
444
|
-
return
|
|
371
|
+
return fixDecoder(encoding, size);
|
|
445
372
|
}
|
|
446
|
-
return {
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
serialize: (value) => {
|
|
451
|
-
const contentBytes = encoding.serialize(value);
|
|
452
|
-
const lengthBytes = size.serialize(contentBytes.length);
|
|
453
|
-
return mergeBytes([lengthBytes, contentBytes]);
|
|
454
|
-
},
|
|
455
|
-
deserialize: (buffer, offset = 0) => {
|
|
456
|
-
if (buffer.slice(offset).length === 0) {
|
|
457
|
-
throw new DeserializingEmptyBufferError("string");
|
|
458
|
-
}
|
|
459
|
-
const [lengthBigInt, lengthOffset] = size.deserialize(buffer, offset);
|
|
373
|
+
return createDecoder({
|
|
374
|
+
read: (bytes, offset = 0) => {
|
|
375
|
+
assertByteArrayIsNotEmptyForCodec("string", bytes, offset);
|
|
376
|
+
const [lengthBigInt, lengthOffset] = size.read(bytes, offset);
|
|
460
377
|
const length = Number(lengthBigInt);
|
|
461
378
|
offset = lengthOffset;
|
|
462
|
-
const
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
}
|
|
466
|
-
const [value, contentOffset] = encoding.deserialize(contentBuffer);
|
|
379
|
+
const contentBytes = bytes.slice(offset, offset + length);
|
|
380
|
+
assertByteArrayHasEnoughBytesForCodec("string", length, contentBytes);
|
|
381
|
+
const [value, contentOffset] = encoding.read(contentBytes, 0);
|
|
467
382
|
offset += contentOffset;
|
|
468
383
|
return [value, offset];
|
|
469
384
|
}
|
|
470
|
-
};
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/struct.mjs
|
|
474
|
-
function struct(fields, options = {}) {
|
|
475
|
-
const fieldDescriptions = fields.map(([name, serializer]) => `${String(name)}: ${serializer.description}`).join(", ");
|
|
476
|
-
return {
|
|
477
|
-
description: options.description ?? `struct(${fieldDescriptions})`,
|
|
478
|
-
fixedSize: sumSerializerSizes(fields.map(([, field]) => field.fixedSize)),
|
|
479
|
-
maxSize: sumSerializerSizes(fields.map(([, field]) => field.maxSize)),
|
|
480
|
-
serialize: (struct2) => {
|
|
481
|
-
const fieldBytes = fields.map(([key, serializer]) => serializer.serialize(struct2[key]));
|
|
482
|
-
return mergeBytes(fieldBytes);
|
|
483
|
-
},
|
|
484
|
-
deserialize: (bytes2, offset = 0) => {
|
|
485
|
-
const struct2 = {};
|
|
486
|
-
fields.forEach(([key, serializer]) => {
|
|
487
|
-
const [value, newOffset] = serializer.deserialize(bytes2, offset);
|
|
488
|
-
offset = newOffset;
|
|
489
|
-
struct2[key] = value;
|
|
490
|
-
});
|
|
491
|
-
return [struct2, offset];
|
|
492
|
-
}
|
|
493
|
-
};
|
|
385
|
+
});
|
|
494
386
|
}
|
|
495
387
|
|
|
496
388
|
// src/unsigned-transaction.ts
|
|
@@ -508,7 +400,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
508
400
|
}
|
|
509
401
|
|
|
510
402
|
// src/blockhash.ts
|
|
403
|
+
var base58Encoder;
|
|
511
404
|
function assertIsBlockhash(putativeBlockhash) {
|
|
405
|
+
if (!base58Encoder)
|
|
406
|
+
base58Encoder = getBase58Encoder();
|
|
512
407
|
try {
|
|
513
408
|
if (
|
|
514
409
|
// Lowest value (32 bytes of zeroes)
|
|
@@ -517,8 +412,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
517
412
|
) {
|
|
518
413
|
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
519
414
|
}
|
|
520
|
-
const
|
|
521
|
-
const numBytes =
|
|
415
|
+
const bytes = base58Encoder.encode(putativeBlockhash);
|
|
416
|
+
const numBytes = bytes.byteLength;
|
|
522
417
|
if (numBytes !== 32) {
|
|
523
418
|
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
524
419
|
}
|
|
@@ -528,9 +423,25 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
528
423
|
});
|
|
529
424
|
}
|
|
530
425
|
}
|
|
531
|
-
function
|
|
532
|
-
|
|
533
|
-
|
|
426
|
+
function isTransactionWithBlockhashLifetime(transaction) {
|
|
427
|
+
const lifetimeConstraintShapeMatches = "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.blockhash === "string" && typeof transaction.lifetimeConstraint.lastValidBlockHeight === "bigint";
|
|
428
|
+
if (!lifetimeConstraintShapeMatches)
|
|
429
|
+
return false;
|
|
430
|
+
try {
|
|
431
|
+
assertIsBlockhash(transaction.lifetimeConstraint.blockhash);
|
|
432
|
+
return true;
|
|
433
|
+
} catch {
|
|
434
|
+
return false;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
function assertIsTransactionWithBlockhashLifetime(transaction) {
|
|
438
|
+
if (!isTransactionWithBlockhashLifetime(transaction)) {
|
|
439
|
+
throw new Error("Transaction does not have a blockhash lifetime");
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) {
|
|
443
|
+
if ("lifetimeConstraint" in transaction && transaction.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transaction.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
|
|
444
|
+
return transaction;
|
|
534
445
|
}
|
|
535
446
|
const out = {
|
|
536
447
|
...getUnsignedTransaction(transaction),
|
|
@@ -598,12 +509,13 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
598
509
|
};
|
|
599
510
|
}
|
|
600
511
|
function isAdvanceNonceAccountInstruction(instruction) {
|
|
512
|
+
var _a;
|
|
601
513
|
return instruction.programAddress === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data
|
|
602
514
|
instruction.data != null && isAdvanceNonceAccountInstructionData(instruction.data) && // Test for exactly 3 accounts
|
|
603
|
-
instruction.accounts
|
|
515
|
+
((_a = instruction.accounts) == null ? void 0 : _a.length) === 3 && // First account is nonce account address
|
|
604
516
|
instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole.WRITABLE && // Second account is recent blockhashes sysvar
|
|
605
517
|
instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole.READONLY && // Third account is nonce authority account
|
|
606
|
-
instruction.accounts[2].address != null && instruction.accounts[2].role
|
|
518
|
+
instruction.accounts[2].address != null && isSignerRole(instruction.accounts[2].role);
|
|
607
519
|
}
|
|
608
520
|
function isAdvanceNonceAccountInstructionData(data) {
|
|
609
521
|
return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;
|
|
@@ -611,21 +523,38 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
611
523
|
function isDurableNonceTransaction(transaction) {
|
|
612
524
|
return "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.nonce === "string" && transaction.instructions[0] != null && isAdvanceNonceAccountInstruction(transaction.instructions[0]);
|
|
613
525
|
}
|
|
526
|
+
function isAdvanceNonceAccountInstructionForNonce(instruction, nonceAccountAddress, nonceAuthorityAddress) {
|
|
527
|
+
return instruction.accounts[0].address === nonceAccountAddress && instruction.accounts[2].address === nonceAuthorityAddress;
|
|
528
|
+
}
|
|
614
529
|
function setTransactionLifetimeUsingDurableNonce({
|
|
615
530
|
nonce,
|
|
616
531
|
nonceAccountAddress,
|
|
617
532
|
nonceAuthorityAddress
|
|
618
533
|
}, transaction) {
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
534
|
+
let newInstructions;
|
|
535
|
+
const firstInstruction = transaction.instructions[0];
|
|
536
|
+
if (firstInstruction && isAdvanceNonceAccountInstruction(firstInstruction)) {
|
|
537
|
+
if (isAdvanceNonceAccountInstructionForNonce(firstInstruction, nonceAccountAddress, nonceAuthorityAddress)) {
|
|
538
|
+
if (isDurableNonceTransaction(transaction) && transaction.lifetimeConstraint.nonce === nonce) {
|
|
539
|
+
return transaction;
|
|
540
|
+
} else {
|
|
541
|
+
newInstructions = [firstInstruction, ...transaction.instructions.slice(1)];
|
|
542
|
+
}
|
|
543
|
+
} else {
|
|
544
|
+
newInstructions = [
|
|
545
|
+
createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
|
|
546
|
+
...transaction.instructions.slice(1)
|
|
547
|
+
];
|
|
548
|
+
}
|
|
549
|
+
} else {
|
|
550
|
+
newInstructions = [
|
|
551
|
+
createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
|
|
552
|
+
...transaction.instructions
|
|
553
|
+
];
|
|
622
554
|
}
|
|
623
555
|
const out = {
|
|
624
556
|
...getUnsignedTransaction(transaction),
|
|
625
|
-
instructions:
|
|
626
|
-
createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
|
|
627
|
-
...isAlreadyDurableNonceTransaction ? transaction.instructions.slice(1) : transaction.instructions
|
|
628
|
-
],
|
|
557
|
+
instructions: newInstructions,
|
|
629
558
|
lifetimeConstraint: {
|
|
630
559
|
nonce
|
|
631
560
|
}
|
|
@@ -665,337 +594,6 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
665
594
|
return out;
|
|
666
595
|
}
|
|
667
596
|
|
|
668
|
-
// ../codecs-core/dist/index.browser.js
|
|
669
|
-
function assertByteArrayIsNotEmptyForCodec(codecDescription, bytes2, offset = 0) {
|
|
670
|
-
if (bytes2.length - offset <= 0) {
|
|
671
|
-
throw new Error(`Codec [${codecDescription}] cannot decode empty byte arrays.`);
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
function assertByteArrayHasEnoughBytesForCodec(codecDescription, expected, bytes2, offset = 0) {
|
|
675
|
-
const bytesLength = bytes2.length - offset;
|
|
676
|
-
if (bytesLength < expected) {
|
|
677
|
-
throw new Error(`Codec [${codecDescription}] expected ${expected} bytes, got ${bytesLength}.`);
|
|
678
|
-
}
|
|
679
|
-
}
|
|
680
|
-
var mergeBytes2 = (byteArrays) => {
|
|
681
|
-
const nonEmptyByteArrays = byteArrays.filter((arr) => arr.length);
|
|
682
|
-
if (nonEmptyByteArrays.length === 0) {
|
|
683
|
-
return byteArrays.length ? byteArrays[0] : new Uint8Array();
|
|
684
|
-
}
|
|
685
|
-
if (nonEmptyByteArrays.length === 1) {
|
|
686
|
-
return nonEmptyByteArrays[0];
|
|
687
|
-
}
|
|
688
|
-
const totalLength = nonEmptyByteArrays.reduce((total, arr) => total + arr.length, 0);
|
|
689
|
-
const result = new Uint8Array(totalLength);
|
|
690
|
-
let offset = 0;
|
|
691
|
-
nonEmptyByteArrays.forEach((arr) => {
|
|
692
|
-
result.set(arr, offset);
|
|
693
|
-
offset += arr.length;
|
|
694
|
-
});
|
|
695
|
-
return result;
|
|
696
|
-
};
|
|
697
|
-
var padBytes2 = (bytes2, length) => {
|
|
698
|
-
if (bytes2.length >= length)
|
|
699
|
-
return bytes2;
|
|
700
|
-
const paddedBytes = new Uint8Array(length).fill(0);
|
|
701
|
-
paddedBytes.set(bytes2);
|
|
702
|
-
return paddedBytes;
|
|
703
|
-
};
|
|
704
|
-
var fixBytes2 = (bytes2, length) => padBytes2(bytes2.length <= length ? bytes2 : bytes2.slice(0, length), length);
|
|
705
|
-
function combineCodec(encoder, decoder, description) {
|
|
706
|
-
if (encoder.fixedSize !== decoder.fixedSize) {
|
|
707
|
-
throw new Error(
|
|
708
|
-
`Encoder and decoder must have the same fixed size, got [${encoder.fixedSize}] and [${decoder.fixedSize}].`
|
|
709
|
-
);
|
|
710
|
-
}
|
|
711
|
-
if (encoder.maxSize !== decoder.maxSize) {
|
|
712
|
-
throw new Error(
|
|
713
|
-
`Encoder and decoder must have the same max size, got [${encoder.maxSize}] and [${decoder.maxSize}].`
|
|
714
|
-
);
|
|
715
|
-
}
|
|
716
|
-
if (description === void 0 && encoder.description !== decoder.description) {
|
|
717
|
-
throw new Error(
|
|
718
|
-
`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.`
|
|
719
|
-
);
|
|
720
|
-
}
|
|
721
|
-
return {
|
|
722
|
-
decode: decoder.decode,
|
|
723
|
-
description: description ?? encoder.description,
|
|
724
|
-
encode: encoder.encode,
|
|
725
|
-
fixedSize: encoder.fixedSize,
|
|
726
|
-
maxSize: encoder.maxSize
|
|
727
|
-
};
|
|
728
|
-
}
|
|
729
|
-
function fixCodecHelper(data, fixedBytes, description) {
|
|
730
|
-
return {
|
|
731
|
-
description: description ?? `fixed(${fixedBytes}, ${data.description})`,
|
|
732
|
-
fixedSize: fixedBytes,
|
|
733
|
-
maxSize: fixedBytes
|
|
734
|
-
};
|
|
735
|
-
}
|
|
736
|
-
function fixEncoder(encoder, fixedBytes, description) {
|
|
737
|
-
return {
|
|
738
|
-
...fixCodecHelper(encoder, fixedBytes, description),
|
|
739
|
-
encode: (value) => fixBytes2(encoder.encode(value), fixedBytes)
|
|
740
|
-
};
|
|
741
|
-
}
|
|
742
|
-
function fixDecoder(decoder, fixedBytes, description) {
|
|
743
|
-
return {
|
|
744
|
-
...fixCodecHelper(decoder, fixedBytes, description),
|
|
745
|
-
decode: (bytes2, offset = 0) => {
|
|
746
|
-
assertByteArrayHasEnoughBytesForCodec("fixCodec", fixedBytes, bytes2, offset);
|
|
747
|
-
if (offset > 0 || bytes2.length > fixedBytes) {
|
|
748
|
-
bytes2 = bytes2.slice(offset, offset + fixedBytes);
|
|
749
|
-
}
|
|
750
|
-
if (decoder.fixedSize !== null) {
|
|
751
|
-
bytes2 = fixBytes2(bytes2, decoder.fixedSize);
|
|
752
|
-
}
|
|
753
|
-
const [value] = decoder.decode(bytes2, 0);
|
|
754
|
-
return [value, offset + fixedBytes];
|
|
755
|
-
}
|
|
756
|
-
};
|
|
757
|
-
}
|
|
758
|
-
function mapEncoder(encoder, unmap) {
|
|
759
|
-
return {
|
|
760
|
-
description: encoder.description,
|
|
761
|
-
encode: (value) => encoder.encode(unmap(value)),
|
|
762
|
-
fixedSize: encoder.fixedSize,
|
|
763
|
-
maxSize: encoder.maxSize
|
|
764
|
-
};
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
// ../codecs-numbers/dist/index.browser.js
|
|
768
|
-
function assertNumberIsBetweenForCodec(codecDescription, min, max, value) {
|
|
769
|
-
if (value < min || value > max) {
|
|
770
|
-
throw new Error(
|
|
771
|
-
`Codec [${codecDescription}] expected number to be in the range [${min}, ${max}], got ${value}.`
|
|
772
|
-
);
|
|
773
|
-
}
|
|
774
|
-
}
|
|
775
|
-
function sharedNumberFactory(input) {
|
|
776
|
-
let littleEndian;
|
|
777
|
-
let defaultDescription = input.name;
|
|
778
|
-
if (input.size > 1) {
|
|
779
|
-
littleEndian = !("endian" in input.options) || input.options.endian === 0;
|
|
780
|
-
defaultDescription += littleEndian ? "(le)" : "(be)";
|
|
781
|
-
}
|
|
782
|
-
return {
|
|
783
|
-
description: input.options.description ?? defaultDescription,
|
|
784
|
-
fixedSize: input.size,
|
|
785
|
-
littleEndian,
|
|
786
|
-
maxSize: input.size
|
|
787
|
-
};
|
|
788
|
-
}
|
|
789
|
-
function numberEncoderFactory(input) {
|
|
790
|
-
const codecData = sharedNumberFactory(input);
|
|
791
|
-
return {
|
|
792
|
-
description: codecData.description,
|
|
793
|
-
encode(value) {
|
|
794
|
-
if (input.range) {
|
|
795
|
-
assertNumberIsBetweenForCodec(input.name, input.range[0], input.range[1], value);
|
|
796
|
-
}
|
|
797
|
-
const arrayBuffer = new ArrayBuffer(input.size);
|
|
798
|
-
input.set(new DataView(arrayBuffer), value, codecData.littleEndian);
|
|
799
|
-
return new Uint8Array(arrayBuffer);
|
|
800
|
-
},
|
|
801
|
-
fixedSize: codecData.fixedSize,
|
|
802
|
-
maxSize: codecData.maxSize
|
|
803
|
-
};
|
|
804
|
-
}
|
|
805
|
-
function numberDecoderFactory(input) {
|
|
806
|
-
const codecData = sharedNumberFactory(input);
|
|
807
|
-
return {
|
|
808
|
-
decode(bytes2, offset = 0) {
|
|
809
|
-
assertByteArrayIsNotEmptyForCodec(codecData.description, bytes2, offset);
|
|
810
|
-
assertByteArrayHasEnoughBytesForCodec(codecData.description, input.size, bytes2, offset);
|
|
811
|
-
const view = new DataView(toArrayBuffer2(bytes2, offset, input.size));
|
|
812
|
-
return [input.get(view, codecData.littleEndian), offset + input.size];
|
|
813
|
-
},
|
|
814
|
-
description: codecData.description,
|
|
815
|
-
fixedSize: codecData.fixedSize,
|
|
816
|
-
maxSize: codecData.maxSize
|
|
817
|
-
};
|
|
818
|
-
}
|
|
819
|
-
function toArrayBuffer2(bytes2, offset, length) {
|
|
820
|
-
const bytesOffset = bytes2.byteOffset + (offset ?? 0);
|
|
821
|
-
const bytesLength = length ?? bytes2.byteLength;
|
|
822
|
-
return bytes2.buffer.slice(bytesOffset, bytesOffset + bytesLength);
|
|
823
|
-
}
|
|
824
|
-
var getU32Encoder = (options = {}) => numberEncoderFactory({
|
|
825
|
-
name: "u32",
|
|
826
|
-
options,
|
|
827
|
-
range: [0, Number("0xffffffff")],
|
|
828
|
-
set: (view, value, le) => view.setUint32(0, value, le),
|
|
829
|
-
size: 4
|
|
830
|
-
});
|
|
831
|
-
var getU32Decoder = (options = {}) => numberDecoderFactory({
|
|
832
|
-
get: (view, le) => view.getUint32(0, le),
|
|
833
|
-
name: "u32",
|
|
834
|
-
options,
|
|
835
|
-
size: 4
|
|
836
|
-
});
|
|
837
|
-
var getU8Encoder = (options = {}) => numberEncoderFactory({
|
|
838
|
-
name: "u8",
|
|
839
|
-
options,
|
|
840
|
-
range: [0, Number("0xff")],
|
|
841
|
-
set: (view, value) => view.setUint8(0, value),
|
|
842
|
-
size: 1
|
|
843
|
-
});
|
|
844
|
-
var getU8Decoder = (options = {}) => numberDecoderFactory({
|
|
845
|
-
get: (view) => view.getUint8(0),
|
|
846
|
-
name: "u8",
|
|
847
|
-
options,
|
|
848
|
-
size: 1
|
|
849
|
-
});
|
|
850
|
-
var getU8Codec = (options = {}) => combineCodec(getU8Encoder(options), getU8Decoder(options));
|
|
851
|
-
|
|
852
|
-
// ../codecs-strings/dist/index.browser.js
|
|
853
|
-
function assertValidBaseString(alphabet4, testValue, givenValue = testValue) {
|
|
854
|
-
if (!testValue.match(new RegExp(`^[${alphabet4}]*$`))) {
|
|
855
|
-
throw new Error(`Expected a string of base ${alphabet4.length}, got [${givenValue}].`);
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
var getBaseXEncoder = (alphabet4) => {
|
|
859
|
-
const base = alphabet4.length;
|
|
860
|
-
const baseBigInt = BigInt(base);
|
|
861
|
-
return {
|
|
862
|
-
description: `base${base}`,
|
|
863
|
-
encode(value) {
|
|
864
|
-
assertValidBaseString(alphabet4, value);
|
|
865
|
-
if (value === "")
|
|
866
|
-
return new Uint8Array();
|
|
867
|
-
const chars = [...value];
|
|
868
|
-
let trailIndex = chars.findIndex((c) => c !== alphabet4[0]);
|
|
869
|
-
trailIndex = trailIndex === -1 ? chars.length : trailIndex;
|
|
870
|
-
const leadingZeroes = Array(trailIndex).fill(0);
|
|
871
|
-
if (trailIndex === chars.length)
|
|
872
|
-
return Uint8Array.from(leadingZeroes);
|
|
873
|
-
const tailChars = chars.slice(trailIndex);
|
|
874
|
-
let base10Number = 0n;
|
|
875
|
-
let baseXPower = 1n;
|
|
876
|
-
for (let i = tailChars.length - 1; i >= 0; i -= 1) {
|
|
877
|
-
base10Number += baseXPower * BigInt(alphabet4.indexOf(tailChars[i]));
|
|
878
|
-
baseXPower *= baseBigInt;
|
|
879
|
-
}
|
|
880
|
-
const tailBytes = [];
|
|
881
|
-
while (base10Number > 0n) {
|
|
882
|
-
tailBytes.unshift(Number(base10Number % 256n));
|
|
883
|
-
base10Number /= 256n;
|
|
884
|
-
}
|
|
885
|
-
return Uint8Array.from(leadingZeroes.concat(tailBytes));
|
|
886
|
-
},
|
|
887
|
-
fixedSize: null,
|
|
888
|
-
maxSize: null
|
|
889
|
-
};
|
|
890
|
-
};
|
|
891
|
-
var getBaseXDecoder = (alphabet4) => {
|
|
892
|
-
const base = alphabet4.length;
|
|
893
|
-
const baseBigInt = BigInt(base);
|
|
894
|
-
return {
|
|
895
|
-
decode(rawBytes, offset = 0) {
|
|
896
|
-
const bytes2 = offset === 0 ? rawBytes : rawBytes.slice(offset);
|
|
897
|
-
if (bytes2.length === 0)
|
|
898
|
-
return ["", 0];
|
|
899
|
-
let trailIndex = bytes2.findIndex((n) => n !== 0);
|
|
900
|
-
trailIndex = trailIndex === -1 ? bytes2.length : trailIndex;
|
|
901
|
-
const leadingZeroes = alphabet4[0].repeat(trailIndex);
|
|
902
|
-
if (trailIndex === bytes2.length)
|
|
903
|
-
return [leadingZeroes, rawBytes.length];
|
|
904
|
-
let base10Number = bytes2.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
|
|
905
|
-
const tailChars = [];
|
|
906
|
-
while (base10Number > 0n) {
|
|
907
|
-
tailChars.unshift(alphabet4[Number(base10Number % baseBigInt)]);
|
|
908
|
-
base10Number /= baseBigInt;
|
|
909
|
-
}
|
|
910
|
-
return [leadingZeroes + tailChars.join(""), rawBytes.length];
|
|
911
|
-
},
|
|
912
|
-
description: `base${base}`,
|
|
913
|
-
fixedSize: null,
|
|
914
|
-
maxSize: null
|
|
915
|
-
};
|
|
916
|
-
};
|
|
917
|
-
var alphabet2 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
918
|
-
var getBase58Encoder = () => getBaseXEncoder(alphabet2);
|
|
919
|
-
var getBase58Decoder = () => getBaseXDecoder(alphabet2);
|
|
920
|
-
var removeNullCharacters2 = (value) => (
|
|
921
|
-
// eslint-disable-next-line no-control-regex
|
|
922
|
-
value.replace(/\u0000/g, "")
|
|
923
|
-
);
|
|
924
|
-
var e = globalThis.TextDecoder;
|
|
925
|
-
var o = globalThis.TextEncoder;
|
|
926
|
-
var getUtf8Encoder = () => {
|
|
927
|
-
let textEncoder;
|
|
928
|
-
return {
|
|
929
|
-
description: "utf8",
|
|
930
|
-
encode: (value) => new Uint8Array((textEncoder || (textEncoder = new o())).encode(value)),
|
|
931
|
-
fixedSize: null,
|
|
932
|
-
maxSize: null
|
|
933
|
-
};
|
|
934
|
-
};
|
|
935
|
-
var getUtf8Decoder = () => {
|
|
936
|
-
let textDecoder;
|
|
937
|
-
return {
|
|
938
|
-
decode(bytes2, offset = 0) {
|
|
939
|
-
const value = (textDecoder || (textDecoder = new e())).decode(bytes2.slice(offset));
|
|
940
|
-
return [removeNullCharacters2(value), bytes2.length];
|
|
941
|
-
},
|
|
942
|
-
description: "utf8",
|
|
943
|
-
fixedSize: null,
|
|
944
|
-
maxSize: null
|
|
945
|
-
};
|
|
946
|
-
};
|
|
947
|
-
var getStringEncoder = (options = {}) => {
|
|
948
|
-
const size = options.size ?? getU32Encoder();
|
|
949
|
-
const encoding = options.encoding ?? getUtf8Encoder();
|
|
950
|
-
const description = options.description ?? `string(${encoding.description}; ${getSizeDescription2(size)})`;
|
|
951
|
-
if (size === "variable") {
|
|
952
|
-
return { ...encoding, description };
|
|
953
|
-
}
|
|
954
|
-
if (typeof size === "number") {
|
|
955
|
-
return fixEncoder(encoding, size, description);
|
|
956
|
-
}
|
|
957
|
-
return {
|
|
958
|
-
description,
|
|
959
|
-
encode: (value) => {
|
|
960
|
-
const contentBytes = encoding.encode(value);
|
|
961
|
-
const lengthBytes = size.encode(contentBytes.length);
|
|
962
|
-
return mergeBytes2([lengthBytes, contentBytes]);
|
|
963
|
-
},
|
|
964
|
-
fixedSize: null,
|
|
965
|
-
maxSize: null
|
|
966
|
-
};
|
|
967
|
-
};
|
|
968
|
-
var getStringDecoder = (options = {}) => {
|
|
969
|
-
const size = options.size ?? getU32Decoder();
|
|
970
|
-
const encoding = options.encoding ?? getUtf8Decoder();
|
|
971
|
-
const description = options.description ?? `string(${encoding.description}; ${getSizeDescription2(size)})`;
|
|
972
|
-
if (size === "variable") {
|
|
973
|
-
return { ...encoding, description };
|
|
974
|
-
}
|
|
975
|
-
if (typeof size === "number") {
|
|
976
|
-
return fixDecoder(encoding, size, description);
|
|
977
|
-
}
|
|
978
|
-
return {
|
|
979
|
-
decode: (bytes2, offset = 0) => {
|
|
980
|
-
assertByteArrayIsNotEmptyForCodec("string", bytes2, offset);
|
|
981
|
-
const [lengthBigInt, lengthOffset] = size.decode(bytes2, offset);
|
|
982
|
-
const length = Number(lengthBigInt);
|
|
983
|
-
offset = lengthOffset;
|
|
984
|
-
const contentBytes = bytes2.slice(offset, offset + length);
|
|
985
|
-
assertByteArrayHasEnoughBytesForCodec("string", length, contentBytes);
|
|
986
|
-
const [value, contentOffset] = encoding.decode(contentBytes);
|
|
987
|
-
offset += contentOffset;
|
|
988
|
-
return [value, offset];
|
|
989
|
-
},
|
|
990
|
-
description,
|
|
991
|
-
fixedSize: null,
|
|
992
|
-
maxSize: null
|
|
993
|
-
};
|
|
994
|
-
};
|
|
995
|
-
function getSizeDescription2(size) {
|
|
996
|
-
return typeof size === "object" ? size.description : `${size}`;
|
|
997
|
-
}
|
|
998
|
-
|
|
999
597
|
// ../assertions/dist/index.browser.js
|
|
1000
598
|
function assertIsSecureContext() {
|
|
1001
599
|
if (!globalThis.isSecureContext) {
|
|
@@ -1005,14 +603,16 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1005
603
|
}
|
|
1006
604
|
}
|
|
1007
605
|
async function assertKeyExporterIsAvailable() {
|
|
606
|
+
var _a;
|
|
1008
607
|
assertIsSecureContext();
|
|
1009
|
-
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle
|
|
608
|
+
if (typeof globalThis.crypto === "undefined" || typeof ((_a = globalThis.crypto.subtle) == null ? void 0 : _a.exportKey) !== "function") {
|
|
1010
609
|
throw new Error("No key export implementation could be found");
|
|
1011
610
|
}
|
|
1012
611
|
}
|
|
1013
612
|
async function assertSigningCapabilityIsAvailable() {
|
|
613
|
+
var _a;
|
|
1014
614
|
assertIsSecureContext();
|
|
1015
|
-
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle
|
|
615
|
+
if (typeof globalThis.crypto === "undefined" || typeof ((_a = globalThis.crypto.subtle) == null ? void 0 : _a.sign) !== "function") {
|
|
1016
616
|
throw new Error("No signing implementation could be found");
|
|
1017
617
|
}
|
|
1018
618
|
}
|
|
@@ -1030,50 +630,39 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1030
630
|
memoizedBase58Decoder = getBase58Decoder();
|
|
1031
631
|
return memoizedBase58Decoder;
|
|
1032
632
|
}
|
|
1033
|
-
function assertIsAddress(
|
|
633
|
+
function assertIsAddress(putativeAddress) {
|
|
1034
634
|
try {
|
|
1035
635
|
if (
|
|
1036
636
|
// Lowest address (32 bytes of zeroes)
|
|
1037
|
-
|
|
1038
|
-
|
|
637
|
+
putativeAddress.length < 32 || // Highest address (32 bytes of 255)
|
|
638
|
+
putativeAddress.length > 44
|
|
1039
639
|
) {
|
|
1040
640
|
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
1041
641
|
}
|
|
1042
|
-
const
|
|
1043
|
-
const
|
|
1044
|
-
const numBytes =
|
|
642
|
+
const base58Encoder2 = getMemoizedBase58Encoder();
|
|
643
|
+
const bytes = base58Encoder2.encode(putativeAddress);
|
|
644
|
+
const numBytes = bytes.byteLength;
|
|
1045
645
|
if (numBytes !== 32) {
|
|
1046
646
|
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
1047
647
|
}
|
|
1048
648
|
} catch (e2) {
|
|
1049
|
-
throw new Error(`\`${
|
|
649
|
+
throw new Error(`\`${putativeAddress}\` is not a base-58 encoded address`, {
|
|
1050
650
|
cause: e2
|
|
1051
651
|
});
|
|
1052
652
|
}
|
|
1053
653
|
}
|
|
1054
|
-
function address(
|
|
1055
|
-
assertIsAddress(
|
|
1056
|
-
return
|
|
654
|
+
function address(putativeAddress) {
|
|
655
|
+
assertIsAddress(putativeAddress);
|
|
656
|
+
return putativeAddress;
|
|
1057
657
|
}
|
|
1058
|
-
function getAddressEncoder(
|
|
658
|
+
function getAddressEncoder() {
|
|
1059
659
|
return mapEncoder(
|
|
1060
|
-
getStringEncoder({
|
|
1061
|
-
description: config?.description ?? "Base58EncodedAddress",
|
|
1062
|
-
encoding: getMemoizedBase58Encoder(),
|
|
1063
|
-
size: 32
|
|
1064
|
-
}),
|
|
660
|
+
getStringEncoder({ encoding: getMemoizedBase58Encoder(), size: 32 }),
|
|
1065
661
|
(putativeAddress) => address(putativeAddress)
|
|
1066
662
|
);
|
|
1067
663
|
}
|
|
1068
|
-
function getAddressDecoder(
|
|
1069
|
-
return getStringDecoder({
|
|
1070
|
-
description: config?.description ?? "Base58EncodedAddress",
|
|
1071
|
-
encoding: getMemoizedBase58Decoder(),
|
|
1072
|
-
size: 32
|
|
1073
|
-
});
|
|
1074
|
-
}
|
|
1075
|
-
function getAddressCodec(config) {
|
|
1076
|
-
return combineCodec(getAddressEncoder(config), getAddressDecoder(config));
|
|
664
|
+
function getAddressDecoder() {
|
|
665
|
+
return getStringDecoder({ encoding: getMemoizedBase58Decoder(), size: 32 });
|
|
1077
666
|
}
|
|
1078
667
|
function getAddressComparator() {
|
|
1079
668
|
return new Intl.Collator("en", {
|
|
@@ -1091,13 +680,13 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1091
680
|
throw new Error("The `CryptoKey` must be an `Ed25519` public key");
|
|
1092
681
|
}
|
|
1093
682
|
const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
|
|
1094
|
-
|
|
1095
|
-
return base58EncodedAddress;
|
|
683
|
+
return getAddressDecoder().decode(new Uint8Array(publicKeyBytes));
|
|
1096
684
|
}
|
|
1097
685
|
|
|
1098
686
|
// src/accounts.ts
|
|
1099
687
|
function upsert(addressMap, address2, update) {
|
|
1100
|
-
|
|
688
|
+
var _a;
|
|
689
|
+
addressMap[address2] = update((_a = addressMap[address2]) != null ? _a : { role: AccountRole.READONLY });
|
|
1101
690
|
}
|
|
1102
691
|
var TYPE = Symbol("AddressMapTypeProperty");
|
|
1103
692
|
function getAddressMapFromInstructions(feePayer, instructions) {
|
|
@@ -1365,354 +954,583 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1365
954
|
};
|
|
1366
955
|
}
|
|
1367
956
|
|
|
1368
|
-
//
|
|
1369
|
-
function
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
957
|
+
// ../codecs-data-structures/dist/index.browser.js
|
|
958
|
+
function assertValidNumberOfItemsForCodec(codecDescription, expected, actual) {
|
|
959
|
+
if (expected !== actual) {
|
|
960
|
+
throw new Error(`Expected [${codecDescription}] to have ${expected} items, got ${actual}.`);
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
function sumCodecSizes(sizes) {
|
|
964
|
+
return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
|
|
965
|
+
}
|
|
966
|
+
function getFixedSize(codec) {
|
|
967
|
+
return isFixedSize(codec) ? codec.fixedSize : null;
|
|
968
|
+
}
|
|
969
|
+
function getMaxSize(codec) {
|
|
970
|
+
var _a;
|
|
971
|
+
return isFixedSize(codec) ? codec.fixedSize : (_a = codec.maxSize) != null ? _a : null;
|
|
972
|
+
}
|
|
973
|
+
function getArrayEncoder(item, config = {}) {
|
|
974
|
+
var _a, _b;
|
|
975
|
+
const size = (_a = config.size) != null ? _a : getU32Encoder();
|
|
976
|
+
if (size === "remainder") {
|
|
977
|
+
assertIsFixedSize(item, 'Codecs of "remainder" size must have fixed-size items.');
|
|
978
|
+
}
|
|
979
|
+
const fixedSize = computeArrayLikeCodecSize(size, getFixedSize(item));
|
|
980
|
+
const maxSize = (_b = computeArrayLikeCodecSize(size, getMaxSize(item))) != null ? _b : void 0;
|
|
981
|
+
return createEncoder({
|
|
982
|
+
...fixedSize !== null ? { fixedSize } : {
|
|
983
|
+
getSizeFromValue: (array) => {
|
|
984
|
+
const prefixSize = typeof size === "object" ? getEncodedSize(array.length, size) : 0;
|
|
985
|
+
return prefixSize + [...array].reduce((all, value) => all + getEncodedSize(value, item), 0);
|
|
986
|
+
},
|
|
987
|
+
maxSize
|
|
988
|
+
},
|
|
989
|
+
write: (array, bytes, offset) => {
|
|
990
|
+
if (typeof size === "number") {
|
|
991
|
+
assertValidNumberOfItemsForCodec("array", size, array.length);
|
|
992
|
+
}
|
|
993
|
+
if (typeof size === "object") {
|
|
994
|
+
offset = size.write(array.length, bytes, offset);
|
|
995
|
+
}
|
|
996
|
+
array.forEach((value) => {
|
|
997
|
+
offset = item.write(value, bytes, offset);
|
|
998
|
+
});
|
|
999
|
+
return offset;
|
|
1376
1000
|
}
|
|
1377
|
-
}
|
|
1378
|
-
|
|
1001
|
+
});
|
|
1002
|
+
}
|
|
1003
|
+
function getArrayDecoder(item, config = {}) {
|
|
1004
|
+
var _a, _b;
|
|
1005
|
+
const size = (_a = config.size) != null ? _a : getU32Decoder();
|
|
1006
|
+
if (size === "remainder") {
|
|
1007
|
+
assertIsFixedSize(item, 'Codecs of "remainder" size must have fixed-size items.');
|
|
1379
1008
|
}
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1009
|
+
const itemSize = getFixedSize(item);
|
|
1010
|
+
const fixedSize = computeArrayLikeCodecSize(size, itemSize);
|
|
1011
|
+
const maxSize = (_b = computeArrayLikeCodecSize(size, getMaxSize(item))) != null ? _b : void 0;
|
|
1012
|
+
return createDecoder({
|
|
1013
|
+
...fixedSize !== null ? { fixedSize } : { maxSize },
|
|
1014
|
+
read: (bytes, offset) => {
|
|
1015
|
+
const array = [];
|
|
1016
|
+
if (typeof size === "object" && bytes.slice(offset).length === 0) {
|
|
1017
|
+
return [array, offset];
|
|
1018
|
+
}
|
|
1019
|
+
const [resolvedSize, newOffset] = readArrayLikeCodecSize(size, itemSize, bytes, offset);
|
|
1020
|
+
offset = newOffset;
|
|
1021
|
+
for (let i = 0; i < resolvedSize; i += 1) {
|
|
1022
|
+
const [value, newOffset2] = item.read(bytes, offset);
|
|
1023
|
+
offset = newOffset2;
|
|
1024
|
+
array.push(value);
|
|
1025
|
+
}
|
|
1026
|
+
return [array, offset];
|
|
1027
|
+
}
|
|
1028
|
+
});
|
|
1384
1029
|
}
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1030
|
+
function readArrayLikeCodecSize(size, itemSize, bytes, offset) {
|
|
1031
|
+
if (typeof size === "number") {
|
|
1032
|
+
return [size, offset];
|
|
1033
|
+
}
|
|
1034
|
+
if (typeof size === "object") {
|
|
1035
|
+
return size.read(bytes, offset);
|
|
1036
|
+
}
|
|
1037
|
+
if (size === "remainder") {
|
|
1038
|
+
if (itemSize === null) {
|
|
1039
|
+
throw new Error('Codecs of "remainder" size must have fixed-size items.');
|
|
1040
|
+
}
|
|
1041
|
+
const remainder = Math.max(0, bytes.length - offset);
|
|
1042
|
+
if (remainder % itemSize !== 0) {
|
|
1043
|
+
throw new Error(
|
|
1044
|
+
`The remainder of the byte array (${remainder} bytes) cannot be split into chunks of ${itemSize} bytes. Codecs of "remainder" size must have a remainder that is a multiple of its item size. In other words, ${remainder} modulo ${itemSize} should be equal to zero.`
|
|
1045
|
+
);
|
|
1046
|
+
}
|
|
1047
|
+
return [remainder / itemSize, offset];
|
|
1048
|
+
}
|
|
1049
|
+
throw new Error(`Unrecognized array-like codec size: ${JSON.stringify(size)}`);
|
|
1396
1050
|
}
|
|
1397
|
-
function
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
{
|
|
1404
|
-
description: "The address of the address lookup table account from which instruction addresses should be looked up"
|
|
1405
|
-
}
|
|
1406
|
-
)
|
|
1407
|
-
],
|
|
1408
|
-
[
|
|
1409
|
-
"writableIndices",
|
|
1410
|
-
array(u8(), {
|
|
1411
|
-
...{
|
|
1412
|
-
description: "The indices of the accounts in the lookup table that should be loaded as writeable"
|
|
1413
|
-
} ,
|
|
1414
|
-
size: shortU16()
|
|
1415
|
-
})
|
|
1416
|
-
],
|
|
1417
|
-
[
|
|
1418
|
-
"readableIndices",
|
|
1419
|
-
array(u8(), {
|
|
1420
|
-
...{
|
|
1421
|
-
description: "The indices of the accounts in the lookup table that should be loaded as read-only"
|
|
1422
|
-
} ,
|
|
1423
|
-
size: shortU16()
|
|
1424
|
-
})
|
|
1425
|
-
]
|
|
1426
|
-
],
|
|
1427
|
-
{
|
|
1428
|
-
description: "A pointer to the address of an address lookup table, along with the readonly/writeable indices of the addresses that should be loaded from it"
|
|
1429
|
-
}
|
|
1430
|
-
);
|
|
1051
|
+
function computeArrayLikeCodecSize(size, itemSize) {
|
|
1052
|
+
if (typeof size !== "number")
|
|
1053
|
+
return null;
|
|
1054
|
+
if (size === 0)
|
|
1055
|
+
return 0;
|
|
1056
|
+
return itemSize === null ? null : itemSize * size;
|
|
1431
1057
|
}
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1058
|
+
function getBytesEncoder(config = {}) {
|
|
1059
|
+
var _a;
|
|
1060
|
+
const size = (_a = config.size) != null ? _a : "variable";
|
|
1061
|
+
const byteEncoder = createEncoder({
|
|
1062
|
+
getSizeFromValue: (value) => value.length,
|
|
1063
|
+
write: (value, bytes, offset) => {
|
|
1064
|
+
bytes.set(value, offset);
|
|
1065
|
+
return offset + value.length;
|
|
1066
|
+
}
|
|
1067
|
+
});
|
|
1068
|
+
if (size === "variable") {
|
|
1069
|
+
return byteEncoder;
|
|
1070
|
+
}
|
|
1071
|
+
if (typeof size === "number") {
|
|
1072
|
+
return fixEncoder(byteEncoder, size);
|
|
1073
|
+
}
|
|
1074
|
+
return createEncoder({
|
|
1075
|
+
getSizeFromValue: (value) => getEncodedSize(value.length, size) + value.length,
|
|
1076
|
+
write: (value, bytes, offset) => {
|
|
1077
|
+
offset = size.write(value.length, bytes, offset);
|
|
1078
|
+
return byteEncoder.write(value, bytes, offset);
|
|
1079
|
+
}
|
|
1080
|
+
});
|
|
1436
1081
|
}
|
|
1437
|
-
function
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1082
|
+
function getBytesDecoder(config = {}) {
|
|
1083
|
+
var _a;
|
|
1084
|
+
const size = (_a = config.size) != null ? _a : "variable";
|
|
1085
|
+
const byteDecoder = createDecoder({
|
|
1086
|
+
read: (bytes, offset) => {
|
|
1087
|
+
const slice = bytes.slice(offset);
|
|
1088
|
+
return [slice, offset + slice.length];
|
|
1089
|
+
}
|
|
1090
|
+
});
|
|
1091
|
+
if (size === "variable") {
|
|
1092
|
+
return byteDecoder;
|
|
1093
|
+
}
|
|
1094
|
+
if (typeof size === "number") {
|
|
1095
|
+
return fixDecoder(byteDecoder, size);
|
|
1096
|
+
}
|
|
1097
|
+
return createDecoder({
|
|
1098
|
+
read: (bytes, offset) => {
|
|
1099
|
+
assertByteArrayIsNotEmptyForCodec("bytes", bytes, offset);
|
|
1100
|
+
const [lengthBigInt, lengthOffset] = size.read(bytes, offset);
|
|
1101
|
+
const length = Number(lengthBigInt);
|
|
1102
|
+
offset = lengthOffset;
|
|
1103
|
+
const contentBytes = bytes.slice(offset, offset + length);
|
|
1104
|
+
assertByteArrayHasEnoughBytesForCodec("bytes", length, contentBytes);
|
|
1105
|
+
const [value, contentOffset] = byteDecoder.read(contentBytes, 0);
|
|
1106
|
+
offset += contentOffset;
|
|
1107
|
+
return [value, offset];
|
|
1108
|
+
}
|
|
1109
|
+
});
|
|
1444
1110
|
}
|
|
1445
|
-
function getStructEncoder(fields
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1111
|
+
function getStructEncoder(fields) {
|
|
1112
|
+
var _a;
|
|
1113
|
+
const fieldCodecs = fields.map(([, codec]) => codec);
|
|
1114
|
+
const fixedSize = sumCodecSizes(fieldCodecs.map(getFixedSize));
|
|
1115
|
+
const maxSize = (_a = sumCodecSizes(fieldCodecs.map(getMaxSize))) != null ? _a : void 0;
|
|
1116
|
+
return createEncoder({
|
|
1117
|
+
...fixedSize === null ? {
|
|
1118
|
+
getSizeFromValue: (value) => fields.map(([key, codec]) => getEncodedSize(value[key], codec)).reduce((all, one) => all + one, 0),
|
|
1119
|
+
maxSize
|
|
1120
|
+
} : { fixedSize },
|
|
1121
|
+
write: (struct, bytes, offset) => {
|
|
1122
|
+
fields.forEach(([key, codec]) => {
|
|
1123
|
+
offset = codec.write(struct[key], bytes, offset);
|
|
1124
|
+
});
|
|
1125
|
+
return offset;
|
|
1451
1126
|
}
|
|
1452
|
-
};
|
|
1127
|
+
});
|
|
1453
1128
|
}
|
|
1454
|
-
function getStructDecoder(fields
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1129
|
+
function getStructDecoder(fields) {
|
|
1130
|
+
var _a;
|
|
1131
|
+
const fieldCodecs = fields.map(([, codec]) => codec);
|
|
1132
|
+
const fixedSize = sumCodecSizes(fieldCodecs.map(getFixedSize));
|
|
1133
|
+
const maxSize = (_a = sumCodecSizes(fieldCodecs.map(getMaxSize))) != null ? _a : void 0;
|
|
1134
|
+
return createDecoder({
|
|
1135
|
+
...fixedSize === null ? { maxSize } : { fixedSize },
|
|
1136
|
+
read: (bytes, offset) => {
|
|
1137
|
+
const struct = {};
|
|
1459
1138
|
fields.forEach(([key, codec]) => {
|
|
1460
|
-
const [value, newOffset] = codec.
|
|
1139
|
+
const [value, newOffset] = codec.read(bytes, offset);
|
|
1461
1140
|
offset = newOffset;
|
|
1462
|
-
|
|
1141
|
+
struct[key] = value;
|
|
1463
1142
|
});
|
|
1464
|
-
return [
|
|
1143
|
+
return [struct, offset];
|
|
1465
1144
|
}
|
|
1466
|
-
};
|
|
1145
|
+
});
|
|
1467
1146
|
}
|
|
1468
|
-
|
|
1469
|
-
|
|
1147
|
+
|
|
1148
|
+
// src/serializers/address-table-lookup.ts
|
|
1149
|
+
var memoizedAddressTableLookupEncoder;
|
|
1150
|
+
function getAddressTableLookupEncoder() {
|
|
1151
|
+
if (!memoizedAddressTableLookupEncoder) {
|
|
1152
|
+
memoizedAddressTableLookupEncoder = getStructEncoder([
|
|
1153
|
+
["lookupTableAddress", getAddressEncoder()],
|
|
1154
|
+
[
|
|
1155
|
+
"writableIndices",
|
|
1156
|
+
getArrayEncoder(getU8Encoder(), { size: getShortU16Encoder() })
|
|
1157
|
+
],
|
|
1158
|
+
[
|
|
1159
|
+
"readableIndices",
|
|
1160
|
+
getArrayEncoder(getU8Encoder(), { size: getShortU16Encoder() })
|
|
1161
|
+
]
|
|
1162
|
+
]);
|
|
1163
|
+
}
|
|
1164
|
+
return memoizedAddressTableLookupEncoder;
|
|
1165
|
+
}
|
|
1166
|
+
var memoizedAddressTableLookupDecoder;
|
|
1167
|
+
function getAddressTableLookupDecoder() {
|
|
1168
|
+
if (!memoizedAddressTableLookupDecoder) {
|
|
1169
|
+
memoizedAddressTableLookupDecoder = getStructDecoder([
|
|
1170
|
+
["lookupTableAddress", getAddressDecoder()],
|
|
1171
|
+
["writableIndices", getArrayDecoder(getU8Decoder(), { size: getShortU16Decoder() })],
|
|
1172
|
+
["readableIndices", getArrayDecoder(getU8Decoder(), { size: getShortU16Decoder() })]
|
|
1173
|
+
]);
|
|
1174
|
+
}
|
|
1175
|
+
return memoizedAddressTableLookupDecoder;
|
|
1470
1176
|
}
|
|
1471
1177
|
|
|
1472
1178
|
// src/serializers/header.ts
|
|
1473
|
-
var
|
|
1474
|
-
function
|
|
1475
|
-
if (!
|
|
1476
|
-
|
|
1477
|
-
return
|
|
1478
|
-
}
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1179
|
+
var memoizedU8Encoder;
|
|
1180
|
+
function getMemoizedU8Encoder() {
|
|
1181
|
+
if (!memoizedU8Encoder)
|
|
1182
|
+
memoizedU8Encoder = getU8Encoder();
|
|
1183
|
+
return memoizedU8Encoder;
|
|
1184
|
+
}
|
|
1185
|
+
var memoizedU8Decoder;
|
|
1186
|
+
function getMemoizedU8Decoder() {
|
|
1187
|
+
if (!memoizedU8Decoder)
|
|
1188
|
+
memoizedU8Decoder = getU8Decoder();
|
|
1189
|
+
return memoizedU8Decoder;
|
|
1190
|
+
}
|
|
1191
|
+
function getMessageHeaderEncoder() {
|
|
1192
|
+
return getStructEncoder([
|
|
1193
|
+
["numSignerAccounts", getMemoizedU8Encoder()],
|
|
1194
|
+
["numReadonlySignerAccounts", getMemoizedU8Encoder()],
|
|
1195
|
+
["numReadonlyNonSignerAccounts", getMemoizedU8Encoder()]
|
|
1196
|
+
]);
|
|
1197
|
+
}
|
|
1198
|
+
function getMessageHeaderDecoder() {
|
|
1199
|
+
return getStructDecoder([
|
|
1200
|
+
["numSignerAccounts", getMemoizedU8Decoder()],
|
|
1201
|
+
["numReadonlySignerAccounts", getMemoizedU8Decoder()],
|
|
1202
|
+
["numReadonlyNonSignerAccounts", getMemoizedU8Decoder()]
|
|
1203
|
+
]);
|
|
1485
1204
|
}
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
var
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1205
|
+
|
|
1206
|
+
// src/serializers/instruction.ts
|
|
1207
|
+
var memoizedGetInstructionEncoder;
|
|
1208
|
+
function getInstructionEncoder() {
|
|
1209
|
+
if (!memoizedGetInstructionEncoder) {
|
|
1210
|
+
memoizedGetInstructionEncoder = mapEncoder(
|
|
1211
|
+
getStructEncoder([
|
|
1212
|
+
["programAddressIndex", getU8Encoder()],
|
|
1213
|
+
["accountIndices", getArrayEncoder(getU8Encoder(), { size: getShortU16Encoder() })],
|
|
1214
|
+
["data", getBytesEncoder({ size: getShortU16Encoder() })]
|
|
1215
|
+
]),
|
|
1216
|
+
// Convert an instruction to have all fields defined
|
|
1217
|
+
(instruction) => {
|
|
1218
|
+
var _a, _b;
|
|
1219
|
+
if (instruction.accountIndices !== void 0 && instruction.data !== void 0) {
|
|
1220
|
+
return instruction;
|
|
1221
|
+
}
|
|
1222
|
+
return {
|
|
1223
|
+
...instruction,
|
|
1224
|
+
accountIndices: (_a = instruction.accountIndices) != null ? _a : [],
|
|
1225
|
+
data: (_b = instruction.data) != null ? _b : new Uint8Array(0)
|
|
1226
|
+
};
|
|
1227
|
+
}
|
|
1228
|
+
);
|
|
1229
|
+
}
|
|
1230
|
+
return memoizedGetInstructionEncoder;
|
|
1231
|
+
}
|
|
1232
|
+
var memoizedGetInstructionDecoder;
|
|
1233
|
+
function getInstructionDecoder() {
|
|
1234
|
+
if (!memoizedGetInstructionDecoder) {
|
|
1235
|
+
memoizedGetInstructionDecoder = mapDecoder(
|
|
1236
|
+
getStructDecoder([
|
|
1237
|
+
["programAddressIndex", getU8Decoder()],
|
|
1238
|
+
["accountIndices", getArrayDecoder(getU8Decoder(), { size: getShortU16Decoder() })],
|
|
1239
|
+
["data", getBytesDecoder({ size: getShortU16Decoder() })]
|
|
1240
|
+
]),
|
|
1241
|
+
// Convert an instruction to exclude optional fields if they are empty
|
|
1242
|
+
(instruction) => {
|
|
1243
|
+
if (instruction.accountIndices.length && instruction.data.byteLength) {
|
|
1244
|
+
return instruction;
|
|
1245
|
+
}
|
|
1246
|
+
const { accountIndices, data, ...rest } = instruction;
|
|
1247
|
+
return {
|
|
1248
|
+
...rest,
|
|
1249
|
+
...accountIndices.length ? { accountIndices } : null,
|
|
1250
|
+
...data.byteLength ? { data } : null
|
|
1251
|
+
};
|
|
1252
|
+
}
|
|
1253
|
+
);
|
|
1254
|
+
}
|
|
1255
|
+
return memoizedGetInstructionDecoder;
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1258
|
+
// src/serializers/transaction-version.ts
|
|
1259
|
+
var VERSION_FLAG_MASK = 128;
|
|
1260
|
+
function getTransactionVersionEncoder() {
|
|
1261
|
+
return createEncoder({
|
|
1262
|
+
getSizeFromValue: (value) => value === "legacy" ? 0 : 1,
|
|
1263
|
+
maxSize: 1,
|
|
1264
|
+
write: (value, bytes, offset) => {
|
|
1265
|
+
if (value === "legacy") {
|
|
1266
|
+
return offset;
|
|
1267
|
+
}
|
|
1268
|
+
if (value < 0 || value > 127) {
|
|
1269
|
+
throw new Error(`Transaction version must be in the range [0, 127]. \`${value}\` given.`);
|
|
1270
|
+
}
|
|
1271
|
+
bytes.set([value | VERSION_FLAG_MASK], offset);
|
|
1272
|
+
return offset + 1;
|
|
1499
1273
|
}
|
|
1500
|
-
);
|
|
1274
|
+
});
|
|
1275
|
+
}
|
|
1276
|
+
function getTransactionVersionDecoder() {
|
|
1277
|
+
return createDecoder({
|
|
1278
|
+
maxSize: 1,
|
|
1279
|
+
read: (bytes, offset) => {
|
|
1280
|
+
const firstByte = bytes[offset];
|
|
1281
|
+
if ((firstByte & VERSION_FLAG_MASK) === 0) {
|
|
1282
|
+
return ["legacy", offset];
|
|
1283
|
+
} else {
|
|
1284
|
+
const version = firstByte ^ VERSION_FLAG_MASK;
|
|
1285
|
+
return [version, offset + 1];
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
});
|
|
1501
1289
|
}
|
|
1502
1290
|
|
|
1503
|
-
// src/serializers/
|
|
1504
|
-
function
|
|
1505
|
-
return
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
}
|
|
1513
|
-
)
|
|
1514
|
-
],
|
|
1515
|
-
[
|
|
1516
|
-
"accountIndices",
|
|
1517
|
-
array(
|
|
1518
|
-
u8({
|
|
1519
|
-
description: "The index of an account, according to the well-ordered accounts list for this transaction"
|
|
1520
|
-
}),
|
|
1521
|
-
{
|
|
1522
|
-
description: "An optional list of account indices, according to the well-ordered accounts list for this transaction, in the order in which the program being called expects them" ,
|
|
1523
|
-
size: shortU16()
|
|
1524
|
-
}
|
|
1525
|
-
)
|
|
1526
|
-
],
|
|
1527
|
-
[
|
|
1528
|
-
"data",
|
|
1529
|
-
bytes({
|
|
1530
|
-
description: "An optional buffer of data passed to the instruction" ,
|
|
1531
|
-
size: shortU16()
|
|
1532
|
-
})
|
|
1533
|
-
]
|
|
1291
|
+
// src/serializers/message.ts
|
|
1292
|
+
function getCompiledMessageLegacyEncoder() {
|
|
1293
|
+
return getStructEncoder(getPreludeStructEncoderTuple());
|
|
1294
|
+
}
|
|
1295
|
+
function getCompiledMessageVersionedEncoder() {
|
|
1296
|
+
return mapEncoder(
|
|
1297
|
+
getStructEncoder([
|
|
1298
|
+
...getPreludeStructEncoderTuple(),
|
|
1299
|
+
["addressTableLookups", getAddressTableLookupArrayEncoder()]
|
|
1534
1300
|
]),
|
|
1535
1301
|
(value) => {
|
|
1536
|
-
|
|
1302
|
+
var _a;
|
|
1303
|
+
if (value.version === "legacy") {
|
|
1537
1304
|
return value;
|
|
1538
1305
|
}
|
|
1539
1306
|
return {
|
|
1540
1307
|
...value,
|
|
1541
|
-
|
|
1542
|
-
data: value.data ?? new Uint8Array(0)
|
|
1543
|
-
};
|
|
1544
|
-
},
|
|
1545
|
-
(value) => {
|
|
1546
|
-
if (value.accountIndices.length && value.data.byteLength) {
|
|
1547
|
-
return value;
|
|
1548
|
-
}
|
|
1549
|
-
const { accountIndices, data, ...rest } = value;
|
|
1550
|
-
return {
|
|
1551
|
-
...rest,
|
|
1552
|
-
...accountIndices.length ? { accountIndices } : null,
|
|
1553
|
-
...data.byteLength ? { data } : null
|
|
1308
|
+
addressTableLookups: (_a = value.addressTableLookups) != null ? _a : []
|
|
1554
1309
|
};
|
|
1555
1310
|
}
|
|
1556
1311
|
);
|
|
1557
1312
|
}
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
function decode(bytes2, offset = 0) {
|
|
1567
|
-
const firstByte = bytes2[offset];
|
|
1568
|
-
if ((firstByte & VERSION_FLAG_MASK) === 0) {
|
|
1569
|
-
return ["legacy", offset];
|
|
1570
|
-
} else {
|
|
1571
|
-
const version = firstByte ^ VERSION_FLAG_MASK;
|
|
1572
|
-
return [version, offset + 1];
|
|
1573
|
-
}
|
|
1313
|
+
function getPreludeStructEncoderTuple() {
|
|
1314
|
+
return [
|
|
1315
|
+
["version", getTransactionVersionEncoder()],
|
|
1316
|
+
["header", getMessageHeaderEncoder()],
|
|
1317
|
+
["staticAccounts", getArrayEncoder(getAddressEncoder(), { size: getShortU16Encoder() })],
|
|
1318
|
+
["lifetimeToken", getStringEncoder({ encoding: getBase58Encoder(), size: 32 })],
|
|
1319
|
+
["instructions", getArrayEncoder(getInstructionEncoder(), { size: getShortU16Encoder() })]
|
|
1320
|
+
];
|
|
1574
1321
|
}
|
|
1575
|
-
function
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1322
|
+
function getPreludeStructDecoderTuple() {
|
|
1323
|
+
return [
|
|
1324
|
+
["version", getTransactionVersionDecoder()],
|
|
1325
|
+
["header", getMessageHeaderDecoder()],
|
|
1326
|
+
["staticAccounts", getArrayDecoder(getAddressDecoder(), { size: getShortU16Decoder() })],
|
|
1327
|
+
["lifetimeToken", getStringDecoder({ encoding: getBase58Decoder(), size: 32 })],
|
|
1328
|
+
["instructions", getArrayDecoder(getInstructionDecoder(), { size: getShortU16Decoder() })],
|
|
1329
|
+
["addressTableLookups", getAddressTableLookupArrayDecoder()]
|
|
1330
|
+
];
|
|
1583
1331
|
}
|
|
1584
|
-
function
|
|
1585
|
-
return {
|
|
1586
|
-
...BASE_CONFIG,
|
|
1587
|
-
decode
|
|
1588
|
-
};
|
|
1332
|
+
function getAddressTableLookupArrayEncoder() {
|
|
1333
|
+
return getArrayEncoder(getAddressTableLookupEncoder(), { size: getShortU16Encoder() });
|
|
1589
1334
|
}
|
|
1590
|
-
function
|
|
1591
|
-
return {
|
|
1592
|
-
...BASE_CONFIG,
|
|
1593
|
-
encode
|
|
1594
|
-
};
|
|
1335
|
+
function getAddressTableLookupArrayDecoder() {
|
|
1336
|
+
return getArrayDecoder(getAddressTableLookupDecoder(), { size: getShortU16Decoder() });
|
|
1595
1337
|
}
|
|
1596
|
-
function
|
|
1597
|
-
return
|
|
1338
|
+
function getCompiledMessageEncoder() {
|
|
1339
|
+
return createEncoder({
|
|
1340
|
+
getSizeFromValue: (compiledMessage) => {
|
|
1341
|
+
if (compiledMessage.version === "legacy") {
|
|
1342
|
+
return getCompiledMessageLegacyEncoder().getSizeFromValue(compiledMessage);
|
|
1343
|
+
} else {
|
|
1344
|
+
return getCompiledMessageVersionedEncoder().getSizeFromValue(compiledMessage);
|
|
1345
|
+
}
|
|
1346
|
+
},
|
|
1347
|
+
write: (compiledMessage, bytes, offset) => {
|
|
1348
|
+
if (compiledMessage.version === "legacy") {
|
|
1349
|
+
return getCompiledMessageLegacyEncoder().write(compiledMessage, bytes, offset);
|
|
1350
|
+
} else {
|
|
1351
|
+
return getCompiledMessageVersionedEncoder().write(compiledMessage, bytes, offset);
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
});
|
|
1598
1355
|
}
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
);
|
|
1356
|
+
function getCompiledMessageDecoder() {
|
|
1357
|
+
return mapDecoder(getStructDecoder(getPreludeStructDecoderTuple()), ({ addressTableLookups, ...restOfMessage }) => {
|
|
1358
|
+
if (restOfMessage.version === "legacy" || !(addressTableLookups == null ? void 0 : addressTableLookups.length)) {
|
|
1359
|
+
return restOfMessage;
|
|
1360
|
+
}
|
|
1361
|
+
return { ...restOfMessage, addressTableLookups };
|
|
1362
|
+
});
|
|
1606
1363
|
}
|
|
1607
|
-
function
|
|
1608
|
-
return ()
|
|
1609
|
-
throw getError("decoder", name);
|
|
1610
|
-
};
|
|
1364
|
+
function getCompiledMessageCodec() {
|
|
1365
|
+
return combineCodec(getCompiledMessageEncoder(), getCompiledMessageDecoder());
|
|
1611
1366
|
}
|
|
1612
1367
|
|
|
1613
|
-
// src/
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1368
|
+
// src/compile-transaction.ts
|
|
1369
|
+
function getCompiledTransaction(transaction) {
|
|
1370
|
+
var _a;
|
|
1371
|
+
const compiledMessage = compileMessage(transaction);
|
|
1372
|
+
let signatures;
|
|
1373
|
+
if ("signatures" in transaction) {
|
|
1374
|
+
signatures = [];
|
|
1375
|
+
for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
|
|
1376
|
+
signatures[ii] = (_a = transaction.signatures[compiledMessage.staticAccounts[ii]]) != null ? _a : new Uint8Array(Array(64).fill(0));
|
|
1377
|
+
}
|
|
1622
1378
|
} else {
|
|
1623
|
-
|
|
1624
|
-
struct([
|
|
1625
|
-
...getPreludeStructSerializerTuple(),
|
|
1626
|
-
["addressTableLookups", getAddressTableLookupsSerializer()]
|
|
1627
|
-
]),
|
|
1628
|
-
(value) => {
|
|
1629
|
-
if (value.version === "legacy") {
|
|
1630
|
-
return value;
|
|
1631
|
-
}
|
|
1632
|
-
return {
|
|
1633
|
-
...value,
|
|
1634
|
-
addressTableLookups: value.addressTableLookups ?? []
|
|
1635
|
-
};
|
|
1636
|
-
}
|
|
1637
|
-
).serialize(compiledMessage);
|
|
1379
|
+
signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
|
|
1638
1380
|
}
|
|
1639
|
-
}
|
|
1640
|
-
function toSerializer(codec) {
|
|
1641
1381
|
return {
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
fixedSize: codec.fixedSize,
|
|
1645
|
-
maxSize: codec.maxSize,
|
|
1646
|
-
serialize: codec.encode
|
|
1382
|
+
compiledMessage,
|
|
1383
|
+
signatures
|
|
1647
1384
|
};
|
|
1648
1385
|
}
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
[
|
|
1654
|
-
"staticAccounts",
|
|
1655
|
-
array(toSerializer(getAddressCodec()), {
|
|
1656
|
-
description: "A compact-array of static account addresses belonging to this transaction" ,
|
|
1657
|
-
size: shortU16()
|
|
1658
|
-
})
|
|
1659
|
-
],
|
|
1660
|
-
[
|
|
1661
|
-
"lifetimeToken",
|
|
1662
|
-
string({
|
|
1663
|
-
description: "A 32-byte token that specifies the lifetime of this transaction (eg. a recent blockhash, or a durable nonce)" ,
|
|
1664
|
-
encoding: base58,
|
|
1665
|
-
size: 32
|
|
1666
|
-
})
|
|
1667
|
-
],
|
|
1668
|
-
[
|
|
1669
|
-
"instructions",
|
|
1670
|
-
array(getInstructionCodec(), {
|
|
1671
|
-
description: "A compact-array of instructions belonging to this transaction" ,
|
|
1672
|
-
size: shortU16()
|
|
1673
|
-
})
|
|
1674
|
-
]
|
|
1675
|
-
];
|
|
1386
|
+
|
|
1387
|
+
// ../functional/dist/index.browser.js
|
|
1388
|
+
function pipe(init, ...fns) {
|
|
1389
|
+
return fns.reduce((acc, fn) => fn(acc), init);
|
|
1676
1390
|
}
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1391
|
+
|
|
1392
|
+
// src/decompile-transaction.ts
|
|
1393
|
+
function getAccountMetas(message) {
|
|
1394
|
+
const { header } = message;
|
|
1395
|
+
const numWritableSignerAccounts = header.numSignerAccounts - header.numReadonlySignerAccounts;
|
|
1396
|
+
const numWritableNonSignerAccounts = message.staticAccounts.length - header.numSignerAccounts - header.numReadonlyNonSignerAccounts;
|
|
1397
|
+
const accountMetas = [];
|
|
1398
|
+
let accountIndex = 0;
|
|
1399
|
+
for (let i = 0; i < numWritableSignerAccounts; i++) {
|
|
1400
|
+
accountMetas.push({
|
|
1401
|
+
address: message.staticAccounts[accountIndex],
|
|
1402
|
+
role: AccountRole.WRITABLE_SIGNER
|
|
1403
|
+
});
|
|
1404
|
+
accountIndex++;
|
|
1405
|
+
}
|
|
1406
|
+
for (let i = 0; i < header.numReadonlySignerAccounts; i++) {
|
|
1407
|
+
accountMetas.push({
|
|
1408
|
+
address: message.staticAccounts[accountIndex],
|
|
1409
|
+
role: AccountRole.READONLY_SIGNER
|
|
1410
|
+
});
|
|
1411
|
+
accountIndex++;
|
|
1412
|
+
}
|
|
1413
|
+
for (let i = 0; i < numWritableNonSignerAccounts; i++) {
|
|
1414
|
+
accountMetas.push({
|
|
1415
|
+
address: message.staticAccounts[accountIndex],
|
|
1416
|
+
role: AccountRole.WRITABLE
|
|
1417
|
+
});
|
|
1418
|
+
accountIndex++;
|
|
1419
|
+
}
|
|
1420
|
+
for (let i = 0; i < header.numReadonlyNonSignerAccounts; i++) {
|
|
1421
|
+
accountMetas.push({
|
|
1422
|
+
address: message.staticAccounts[accountIndex],
|
|
1423
|
+
role: AccountRole.READONLY
|
|
1424
|
+
});
|
|
1425
|
+
accountIndex++;
|
|
1426
|
+
}
|
|
1427
|
+
return accountMetas;
|
|
1682
1428
|
}
|
|
1683
|
-
function
|
|
1429
|
+
function convertInstruction(instruction, accountMetas) {
|
|
1430
|
+
var _a, _b;
|
|
1431
|
+
const programAddress = (_a = accountMetas[instruction.programAddressIndex]) == null ? void 0 : _a.address;
|
|
1432
|
+
if (!programAddress) {
|
|
1433
|
+
throw new Error(`Could not find program address at index ${instruction.programAddressIndex}`);
|
|
1434
|
+
}
|
|
1435
|
+
const accounts = (_b = instruction.accountIndices) == null ? void 0 : _b.map((accountIndex) => accountMetas[accountIndex]);
|
|
1436
|
+
const { data } = instruction;
|
|
1684
1437
|
return {
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1438
|
+
programAddress,
|
|
1439
|
+
...accounts && accounts.length ? { accounts } : {},
|
|
1440
|
+
...data && data.length ? { data } : {}
|
|
1688
1441
|
};
|
|
1689
1442
|
}
|
|
1443
|
+
function getLifetimeConstraint(messageLifetimeToken, firstInstruction, lastValidBlockHeight) {
|
|
1444
|
+
if (!firstInstruction || !isAdvanceNonceAccountInstruction(firstInstruction)) {
|
|
1445
|
+
return {
|
|
1446
|
+
blockhash: messageLifetimeToken,
|
|
1447
|
+
lastValidBlockHeight: lastValidBlockHeight != null ? lastValidBlockHeight : 2n ** 64n - 1n
|
|
1448
|
+
// U64 MAX
|
|
1449
|
+
};
|
|
1450
|
+
} else {
|
|
1451
|
+
const nonceAccountAddress = firstInstruction.accounts[0].address;
|
|
1452
|
+
assertIsAddress(nonceAccountAddress);
|
|
1453
|
+
const nonceAuthorityAddress = firstInstruction.accounts[2].address;
|
|
1454
|
+
assertIsAddress(nonceAuthorityAddress);
|
|
1455
|
+
return {
|
|
1456
|
+
nonce: messageLifetimeToken,
|
|
1457
|
+
nonceAccountAddress,
|
|
1458
|
+
nonceAuthorityAddress
|
|
1459
|
+
};
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
function convertSignatures(compiledTransaction) {
|
|
1463
|
+
const {
|
|
1464
|
+
compiledMessage: { staticAccounts },
|
|
1465
|
+
signatures
|
|
1466
|
+
} = compiledTransaction;
|
|
1467
|
+
return signatures.reduce((acc, sig, index) => {
|
|
1468
|
+
const allZeros = sig.every((byte) => byte === 0);
|
|
1469
|
+
if (allZeros)
|
|
1470
|
+
return acc;
|
|
1471
|
+
const address2 = staticAccounts[index];
|
|
1472
|
+
return { ...acc, [address2]: sig };
|
|
1473
|
+
}, {});
|
|
1474
|
+
}
|
|
1475
|
+
function decompileTransaction(compiledTransaction, lastValidBlockHeight) {
|
|
1476
|
+
const { compiledMessage } = compiledTransaction;
|
|
1477
|
+
if ("addressTableLookups" in compiledMessage && compiledMessage.addressTableLookups.length > 0) {
|
|
1478
|
+
throw new Error("Cannot convert transaction with addressTableLookups");
|
|
1479
|
+
}
|
|
1480
|
+
const feePayer = compiledMessage.staticAccounts[0];
|
|
1481
|
+
if (!feePayer)
|
|
1482
|
+
throw new Error("No fee payer set in CompiledTransaction");
|
|
1483
|
+
const accountMetas = getAccountMetas(compiledMessage);
|
|
1484
|
+
const instructions = compiledMessage.instructions.map(
|
|
1485
|
+
(compiledInstruction) => convertInstruction(compiledInstruction, accountMetas)
|
|
1486
|
+
);
|
|
1487
|
+
const firstInstruction = instructions[0];
|
|
1488
|
+
const lifetimeConstraint = getLifetimeConstraint(
|
|
1489
|
+
compiledMessage.lifetimeToken,
|
|
1490
|
+
firstInstruction,
|
|
1491
|
+
lastValidBlockHeight
|
|
1492
|
+
);
|
|
1493
|
+
const signatures = convertSignatures(compiledTransaction);
|
|
1494
|
+
return pipe(
|
|
1495
|
+
createTransaction({ version: compiledMessage.version }),
|
|
1496
|
+
(tx) => setTransactionFeePayer(feePayer, tx),
|
|
1497
|
+
(tx) => instructions.reduce((acc, instruction) => {
|
|
1498
|
+
return appendTransactionInstruction(instruction, acc);
|
|
1499
|
+
}, tx),
|
|
1500
|
+
(tx) => "blockhash" in lifetimeConstraint ? setTransactionLifetimeUsingBlockhash(lifetimeConstraint, tx) : setTransactionLifetimeUsingDurableNonce(lifetimeConstraint, tx),
|
|
1501
|
+
(tx) => compiledTransaction.signatures.length ? { ...tx, signatures } : tx
|
|
1502
|
+
);
|
|
1503
|
+
}
|
|
1690
1504
|
|
|
1691
1505
|
// src/serializers/transaction.ts
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
return
|
|
1506
|
+
function getCompiledTransactionEncoder() {
|
|
1507
|
+
return getStructEncoder([
|
|
1508
|
+
["signatures", getArrayEncoder(getBytesEncoder({ size: 64 }), { size: getShortU16Encoder() })],
|
|
1509
|
+
["compiledMessage", getCompiledMessageEncoder()]
|
|
1510
|
+
]);
|
|
1511
|
+
}
|
|
1512
|
+
function getCompiledTransactionDecoder() {
|
|
1513
|
+
return getStructDecoder([
|
|
1700
1514
|
[
|
|
1701
1515
|
"signatures",
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
size: shortU16()
|
|
1516
|
+
getArrayDecoder(getBytesDecoder({ size: 64 }), {
|
|
1517
|
+
size: getShortU16Decoder()
|
|
1705
1518
|
})
|
|
1706
1519
|
],
|
|
1707
|
-
["compiledMessage",
|
|
1708
|
-
])
|
|
1520
|
+
["compiledMessage", getCompiledMessageDecoder()]
|
|
1521
|
+
]);
|
|
1709
1522
|
}
|
|
1710
1523
|
function getTransactionEncoder() {
|
|
1711
|
-
return
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1524
|
+
return mapEncoder(getCompiledTransactionEncoder(), getCompiledTransaction);
|
|
1525
|
+
}
|
|
1526
|
+
function getTransactionDecoder(lastValidBlockHeight) {
|
|
1527
|
+
return mapDecoder(
|
|
1528
|
+
getCompiledTransactionDecoder(),
|
|
1529
|
+
(compiledTransaction) => decompileTransaction(compiledTransaction, lastValidBlockHeight)
|
|
1530
|
+
);
|
|
1531
|
+
}
|
|
1532
|
+
function getTransactionCodec(lastValidBlockHeight) {
|
|
1533
|
+
return combineCodec(getTransactionEncoder(), getTransactionDecoder(lastValidBlockHeight));
|
|
1716
1534
|
}
|
|
1717
1535
|
|
|
1718
1536
|
// ../keys/dist/index.browser.js
|
|
@@ -1723,64 +1541,26 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1723
1541
|
}
|
|
1724
1542
|
|
|
1725
1543
|
// src/signatures.ts
|
|
1726
|
-
|
|
1727
|
-
try {
|
|
1728
|
-
if (
|
|
1729
|
-
// Lowest value (64 bytes of zeroes)
|
|
1730
|
-
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
1731
|
-
putativeTransactionSignature.length > 88
|
|
1732
|
-
) {
|
|
1733
|
-
throw new Error("Expected input string to decode to a byte array of length 64.");
|
|
1734
|
-
}
|
|
1735
|
-
const bytes2 = base58.serialize(putativeTransactionSignature);
|
|
1736
|
-
const numBytes = bytes2.byteLength;
|
|
1737
|
-
if (numBytes !== 64) {
|
|
1738
|
-
throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
|
|
1739
|
-
}
|
|
1740
|
-
} catch (e2) {
|
|
1741
|
-
throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, {
|
|
1742
|
-
cause: e2
|
|
1743
|
-
});
|
|
1744
|
-
}
|
|
1745
|
-
}
|
|
1746
|
-
function isTransactionSignature(putativeTransactionSignature) {
|
|
1747
|
-
if (
|
|
1748
|
-
// Lowest value (64 bytes of zeroes)
|
|
1749
|
-
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
1750
|
-
putativeTransactionSignature.length > 88
|
|
1751
|
-
) {
|
|
1752
|
-
return false;
|
|
1753
|
-
}
|
|
1754
|
-
const bytes2 = base58.serialize(putativeTransactionSignature);
|
|
1755
|
-
const numBytes = bytes2.byteLength;
|
|
1756
|
-
if (numBytes !== 64) {
|
|
1757
|
-
return false;
|
|
1758
|
-
}
|
|
1759
|
-
return true;
|
|
1760
|
-
}
|
|
1761
|
-
async function getCompiledMessageSignature(message, secretKey) {
|
|
1762
|
-
const wireMessageBytes = getCompiledMessageEncoder().serialize(message);
|
|
1763
|
-
const signature = await signBytes(secretKey, wireMessageBytes);
|
|
1764
|
-
return signature;
|
|
1765
|
-
}
|
|
1544
|
+
var base58Decoder;
|
|
1766
1545
|
function getSignatureFromTransaction(transaction) {
|
|
1767
|
-
|
|
1768
|
-
|
|
1546
|
+
if (!base58Decoder)
|
|
1547
|
+
base58Decoder = getBase58Decoder();
|
|
1548
|
+
const signatureBytes = transaction.signatures[transaction.feePayer];
|
|
1549
|
+
if (!signatureBytes) {
|
|
1769
1550
|
throw new Error(
|
|
1770
1551
|
"Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
|
|
1771
1552
|
);
|
|
1772
1553
|
}
|
|
1773
|
-
|
|
1554
|
+
const transactionSignature = base58Decoder.decode(signatureBytes);
|
|
1555
|
+
return transactionSignature;
|
|
1774
1556
|
}
|
|
1775
|
-
async function
|
|
1557
|
+
async function partiallySignTransaction(keyPairs, transaction) {
|
|
1776
1558
|
const compiledMessage = compileMessage(transaction);
|
|
1777
1559
|
const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
|
|
1560
|
+
const wireMessageBytes = getCompiledMessageEncoder().encode(compiledMessage);
|
|
1778
1561
|
const publicKeySignaturePairs = await Promise.all(
|
|
1779
1562
|
keyPairs.map(
|
|
1780
|
-
(keyPair) => Promise.all([
|
|
1781
|
-
getAddressFromPublicKey(keyPair.publicKey),
|
|
1782
|
-
getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
|
|
1783
|
-
])
|
|
1563
|
+
(keyPair) => Promise.all([getAddressFromPublicKey(keyPair.publicKey), signBytes(keyPair.privateKey, wireMessageBytes)])
|
|
1784
1564
|
)
|
|
1785
1565
|
);
|
|
1786
1566
|
for (const [signerPublicKey, signature] of publicKeySignaturePairs) {
|
|
@@ -1793,34 +1573,53 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1793
1573
|
Object.freeze(out);
|
|
1794
1574
|
return out;
|
|
1795
1575
|
}
|
|
1796
|
-
function
|
|
1797
|
-
|
|
1798
|
-
|
|
1576
|
+
async function signTransaction(keyPairs, transaction) {
|
|
1577
|
+
const out = await partiallySignTransaction(keyPairs, transaction);
|
|
1578
|
+
assertTransactionIsFullySigned(out);
|
|
1579
|
+
Object.freeze(out);
|
|
1580
|
+
return out;
|
|
1581
|
+
}
|
|
1582
|
+
function assertTransactionIsFullySigned(transaction) {
|
|
1583
|
+
const signerAddressesFromInstructions = transaction.instructions.flatMap((i) => {
|
|
1584
|
+
var _a, _b;
|
|
1585
|
+
return (_b = (_a = i.accounts) == null ? void 0 : _a.filter((a) => isSignerRole(a.role))) != null ? _b : [];
|
|
1586
|
+
}).map((a) => a.address);
|
|
1587
|
+
const requiredSigners = /* @__PURE__ */ new Set([transaction.feePayer, ...signerAddressesFromInstructions]);
|
|
1588
|
+
requiredSigners.forEach((address2) => {
|
|
1589
|
+
if (!transaction.signatures[address2]) {
|
|
1590
|
+
throw new Error(`Transaction is missing signature for address \`${address2}\``);
|
|
1591
|
+
}
|
|
1592
|
+
});
|
|
1799
1593
|
}
|
|
1800
1594
|
|
|
1801
1595
|
// src/wire-transaction.ts
|
|
1802
1596
|
function getBase64EncodedWireTransaction(transaction) {
|
|
1803
|
-
const wireTransactionBytes = getTransactionEncoder().
|
|
1804
|
-
|
|
1805
|
-
return btoa(String.fromCharCode(...wireTransactionBytes));
|
|
1806
|
-
}
|
|
1597
|
+
const wireTransactionBytes = getTransactionEncoder().encode(transaction);
|
|
1598
|
+
return getBase64Decoder().decode(wireTransactionBytes);
|
|
1807
1599
|
}
|
|
1808
1600
|
|
|
1809
1601
|
exports.appendTransactionInstruction = appendTransactionInstruction;
|
|
1810
1602
|
exports.assertIsBlockhash = assertIsBlockhash;
|
|
1811
1603
|
exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
|
|
1812
|
-
exports.
|
|
1604
|
+
exports.assertIsTransactionWithBlockhashLifetime = assertIsTransactionWithBlockhashLifetime;
|
|
1605
|
+
exports.assertTransactionIsFullySigned = assertTransactionIsFullySigned;
|
|
1606
|
+
exports.compileMessage = compileMessage;
|
|
1813
1607
|
exports.createTransaction = createTransaction;
|
|
1814
1608
|
exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
|
|
1609
|
+
exports.getCompiledMessageCodec = getCompiledMessageCodec;
|
|
1610
|
+
exports.getCompiledMessageDecoder = getCompiledMessageDecoder;
|
|
1611
|
+
exports.getCompiledMessageEncoder = getCompiledMessageEncoder;
|
|
1815
1612
|
exports.getSignatureFromTransaction = getSignatureFromTransaction;
|
|
1613
|
+
exports.getTransactionCodec = getTransactionCodec;
|
|
1614
|
+
exports.getTransactionDecoder = getTransactionDecoder;
|
|
1816
1615
|
exports.getTransactionEncoder = getTransactionEncoder;
|
|
1817
|
-
exports.
|
|
1616
|
+
exports.isAdvanceNonceAccountInstruction = isAdvanceNonceAccountInstruction;
|
|
1617
|
+
exports.partiallySignTransaction = partiallySignTransaction;
|
|
1818
1618
|
exports.prependTransactionInstruction = prependTransactionInstruction;
|
|
1819
1619
|
exports.setTransactionFeePayer = setTransactionFeePayer;
|
|
1820
1620
|
exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
|
|
1821
1621
|
exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
|
|
1822
1622
|
exports.signTransaction = signTransaction;
|
|
1823
|
-
exports.transactionSignature = transactionSignature;
|
|
1824
1623
|
|
|
1825
1624
|
return exports;
|
|
1826
1625
|
|