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