@solana/transactions 2.0.0-experimental.cf6ca9d → 2.0.0-experimental.d085c72
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -43
- package/dist/index.browser.cjs +158 -188
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +156 -186
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +662 -720
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +156 -186
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +158 -186
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +158 -186
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +22 -20
- package/dist/types/accounts.d.ts +2 -2
- package/dist/types/compilable-transaction.d.ts +7 -0
- package/dist/types/compile-address-table-lookups.d.ts +2 -2
- package/dist/types/compile-static-accounts.d.ts +2 -2
- package/dist/types/compile-transaction.d.ts +5 -6
- package/dist/types/decompile-transaction.d.ts +2 -4
- package/dist/types/durable-nonce.d.ts +3 -3
- package/dist/types/fee-payer.d.ts +4 -4
- package/dist/types/index.d.ts +2 -0
- package/dist/types/message.d.ts +1 -5
- package/dist/types/serializers/index.d.ts +1 -0
- package/dist/types/serializers/transaction.d.ts +1 -3
- package/dist/types/signatures.d.ts +8 -13
- package/dist/types/types.d.ts +6 -13
- package/package.json +12 -13
|
@@ -2,269 +2,6 @@ this.globalThis = this.globalThis || {};
|
|
|
2
2
|
this.globalThis.solanaWeb3 = (function (exports) {
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
5
|
-
var __defProp = Object.defineProperty;
|
|
6
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
-
var __publicField = (obj, key, value) => {
|
|
8
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
9
|
-
return value;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/errors.mjs
|
|
13
|
-
var InvalidBaseStringError = class extends Error {
|
|
14
|
-
constructor(value, base, cause) {
|
|
15
|
-
const message = `Expected a string of base ${base}, got [${value}].`;
|
|
16
|
-
super(message);
|
|
17
|
-
__publicField(this, "name", "InvalidBaseStringError");
|
|
18
|
-
this.cause = cause;
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/baseX.mjs
|
|
23
|
-
var baseX = (alphabet) => {
|
|
24
|
-
const base = alphabet.length;
|
|
25
|
-
const baseBigInt = BigInt(base);
|
|
26
|
-
return {
|
|
27
|
-
description: `base${base}`,
|
|
28
|
-
fixedSize: null,
|
|
29
|
-
maxSize: null,
|
|
30
|
-
serialize(value) {
|
|
31
|
-
if (!value.match(new RegExp(`^[${alphabet}]*$`))) {
|
|
32
|
-
throw new InvalidBaseStringError(value, base);
|
|
33
|
-
}
|
|
34
|
-
if (value === "")
|
|
35
|
-
return new Uint8Array();
|
|
36
|
-
const chars = [...value];
|
|
37
|
-
let trailIndex = chars.findIndex((c) => c !== alphabet[0]);
|
|
38
|
-
trailIndex = trailIndex === -1 ? chars.length : trailIndex;
|
|
39
|
-
const leadingZeroes = Array(trailIndex).fill(0);
|
|
40
|
-
if (trailIndex === chars.length)
|
|
41
|
-
return Uint8Array.from(leadingZeroes);
|
|
42
|
-
const tailChars = chars.slice(trailIndex);
|
|
43
|
-
let base10Number = 0n;
|
|
44
|
-
let baseXPower = 1n;
|
|
45
|
-
for (let i = tailChars.length - 1; i >= 0; i -= 1) {
|
|
46
|
-
base10Number += baseXPower * BigInt(alphabet.indexOf(tailChars[i]));
|
|
47
|
-
baseXPower *= baseBigInt;
|
|
48
|
-
}
|
|
49
|
-
const tailBytes = [];
|
|
50
|
-
while (base10Number > 0n) {
|
|
51
|
-
tailBytes.unshift(Number(base10Number % 256n));
|
|
52
|
-
base10Number /= 256n;
|
|
53
|
-
}
|
|
54
|
-
return Uint8Array.from(leadingZeroes.concat(tailBytes));
|
|
55
|
-
},
|
|
56
|
-
deserialize(buffer, offset = 0) {
|
|
57
|
-
if (buffer.length === 0)
|
|
58
|
-
return ["", 0];
|
|
59
|
-
const bytes = buffer.slice(offset);
|
|
60
|
-
let trailIndex = bytes.findIndex((n) => n !== 0);
|
|
61
|
-
trailIndex = trailIndex === -1 ? bytes.length : trailIndex;
|
|
62
|
-
const leadingZeroes = alphabet[0].repeat(trailIndex);
|
|
63
|
-
if (trailIndex === bytes.length)
|
|
64
|
-
return [leadingZeroes, buffer.length];
|
|
65
|
-
let base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
|
|
66
|
-
const tailChars = [];
|
|
67
|
-
while (base10Number > 0n) {
|
|
68
|
-
tailChars.unshift(alphabet[Number(base10Number % baseBigInt)]);
|
|
69
|
-
base10Number /= baseBigInt;
|
|
70
|
-
}
|
|
71
|
-
return [leadingZeroes + tailChars.join(""), buffer.length];
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/base58.mjs
|
|
77
|
-
var base58 = baseX("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
|
|
78
|
-
|
|
79
|
-
// src/unsigned-transaction.ts
|
|
80
|
-
function getUnsignedTransaction(transaction) {
|
|
81
|
-
if ("signatures" in transaction) {
|
|
82
|
-
const {
|
|
83
|
-
signatures: _,
|
|
84
|
-
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
85
|
-
...unsignedTransaction
|
|
86
|
-
} = transaction;
|
|
87
|
-
return unsignedTransaction;
|
|
88
|
-
} else {
|
|
89
|
-
return transaction;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// src/blockhash.ts
|
|
94
|
-
function assertIsBlockhash(putativeBlockhash) {
|
|
95
|
-
try {
|
|
96
|
-
if (
|
|
97
|
-
// Lowest value (32 bytes of zeroes)
|
|
98
|
-
putativeBlockhash.length < 32 || // Highest value (32 bytes of 255)
|
|
99
|
-
putativeBlockhash.length > 44
|
|
100
|
-
) {
|
|
101
|
-
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
102
|
-
}
|
|
103
|
-
const bytes = base58.serialize(putativeBlockhash);
|
|
104
|
-
const numBytes = bytes.byteLength;
|
|
105
|
-
if (numBytes !== 32) {
|
|
106
|
-
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
107
|
-
}
|
|
108
|
-
} catch (e2) {
|
|
109
|
-
throw new Error(`\`${putativeBlockhash}\` is not a blockhash`, {
|
|
110
|
-
cause: e2
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) {
|
|
115
|
-
if ("lifetimeConstraint" in transaction && transaction.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transaction.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
|
|
116
|
-
return transaction;
|
|
117
|
-
}
|
|
118
|
-
const out = {
|
|
119
|
-
...getUnsignedTransaction(transaction),
|
|
120
|
-
lifetimeConstraint: blockhashLifetimeConstraint
|
|
121
|
-
};
|
|
122
|
-
Object.freeze(out);
|
|
123
|
-
return out;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// src/create-transaction.ts
|
|
127
|
-
function createTransaction({
|
|
128
|
-
version
|
|
129
|
-
}) {
|
|
130
|
-
const out = {
|
|
131
|
-
instructions: [],
|
|
132
|
-
version
|
|
133
|
-
};
|
|
134
|
-
Object.freeze(out);
|
|
135
|
-
return out;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// ../instructions/dist/index.browser.js
|
|
139
|
-
var AccountRole = /* @__PURE__ */ ((AccountRole2) => {
|
|
140
|
-
AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */
|
|
141
|
-
3] = "WRITABLE_SIGNER";
|
|
142
|
-
AccountRole2[AccountRole2["READONLY_SIGNER"] = /* 2 */
|
|
143
|
-
2] = "READONLY_SIGNER";
|
|
144
|
-
AccountRole2[AccountRole2["WRITABLE"] = /* 1 */
|
|
145
|
-
1] = "WRITABLE";
|
|
146
|
-
AccountRole2[AccountRole2["READONLY"] = /* 0 */
|
|
147
|
-
0] = "READONLY";
|
|
148
|
-
return AccountRole2;
|
|
149
|
-
})(AccountRole || {});
|
|
150
|
-
var IS_WRITABLE_BITMASK = 1;
|
|
151
|
-
function isSignerRole(role) {
|
|
152
|
-
return role >= 2;
|
|
153
|
-
}
|
|
154
|
-
function isWritableRole(role) {
|
|
155
|
-
return (role & IS_WRITABLE_BITMASK) !== 0;
|
|
156
|
-
}
|
|
157
|
-
function mergeRoles(roleA, roleB) {
|
|
158
|
-
return roleA | roleB;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// src/durable-nonce.ts
|
|
162
|
-
var RECENT_BLOCKHASHES_SYSVAR_ADDRESS = "SysvarRecentB1ockHashes11111111111111111111";
|
|
163
|
-
var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
|
|
164
|
-
function assertIsDurableNonceTransaction(transaction) {
|
|
165
|
-
if (!isDurableNonceTransaction(transaction)) {
|
|
166
|
-
throw new Error("Transaction is not a durable nonce transaction");
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
function createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress) {
|
|
170
|
-
return {
|
|
171
|
-
accounts: [
|
|
172
|
-
{ address: nonceAccountAddress, role: AccountRole.WRITABLE },
|
|
173
|
-
{
|
|
174
|
-
address: RECENT_BLOCKHASHES_SYSVAR_ADDRESS,
|
|
175
|
-
role: AccountRole.READONLY
|
|
176
|
-
},
|
|
177
|
-
{ address: nonceAuthorityAddress, role: AccountRole.READONLY_SIGNER }
|
|
178
|
-
],
|
|
179
|
-
data: new Uint8Array([4, 0, 0, 0]),
|
|
180
|
-
programAddress: SYSTEM_PROGRAM_ADDRESS
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
function isAdvanceNonceAccountInstruction(instruction) {
|
|
184
|
-
return instruction.programAddress === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data
|
|
185
|
-
instruction.data != null && isAdvanceNonceAccountInstructionData(instruction.data) && // Test for exactly 3 accounts
|
|
186
|
-
instruction.accounts?.length === 3 && // First account is nonce account address
|
|
187
|
-
instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole.WRITABLE && // Second account is recent blockhashes sysvar
|
|
188
|
-
instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole.READONLY && // Third account is nonce authority account
|
|
189
|
-
instruction.accounts[2].address != null && isSignerRole(instruction.accounts[2].role);
|
|
190
|
-
}
|
|
191
|
-
function isAdvanceNonceAccountInstructionData(data) {
|
|
192
|
-
return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;
|
|
193
|
-
}
|
|
194
|
-
function isDurableNonceTransaction(transaction) {
|
|
195
|
-
return "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.nonce === "string" && transaction.instructions[0] != null && isAdvanceNonceAccountInstruction(transaction.instructions[0]);
|
|
196
|
-
}
|
|
197
|
-
function isAdvanceNonceAccountInstructionForNonce(instruction, nonceAccountAddress, nonceAuthorityAddress) {
|
|
198
|
-
return instruction.accounts[0].address === nonceAccountAddress && instruction.accounts[2].address === nonceAuthorityAddress;
|
|
199
|
-
}
|
|
200
|
-
function setTransactionLifetimeUsingDurableNonce({
|
|
201
|
-
nonce,
|
|
202
|
-
nonceAccountAddress,
|
|
203
|
-
nonceAuthorityAddress
|
|
204
|
-
}, transaction) {
|
|
205
|
-
let newInstructions;
|
|
206
|
-
const firstInstruction = transaction.instructions[0];
|
|
207
|
-
if (firstInstruction && isAdvanceNonceAccountInstruction(firstInstruction)) {
|
|
208
|
-
if (isAdvanceNonceAccountInstructionForNonce(firstInstruction, nonceAccountAddress, nonceAuthorityAddress)) {
|
|
209
|
-
if (isDurableNonceTransaction(transaction) && transaction.lifetimeConstraint.nonce === nonce) {
|
|
210
|
-
return transaction;
|
|
211
|
-
} else {
|
|
212
|
-
newInstructions = [firstInstruction, ...transaction.instructions.slice(1)];
|
|
213
|
-
}
|
|
214
|
-
} else {
|
|
215
|
-
newInstructions = [
|
|
216
|
-
createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
|
|
217
|
-
...transaction.instructions.slice(1)
|
|
218
|
-
];
|
|
219
|
-
}
|
|
220
|
-
} else {
|
|
221
|
-
newInstructions = [
|
|
222
|
-
createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
|
|
223
|
-
...transaction.instructions
|
|
224
|
-
];
|
|
225
|
-
}
|
|
226
|
-
const out = {
|
|
227
|
-
...getUnsignedTransaction(transaction),
|
|
228
|
-
instructions: newInstructions,
|
|
229
|
-
lifetimeConstraint: {
|
|
230
|
-
nonce
|
|
231
|
-
}
|
|
232
|
-
};
|
|
233
|
-
Object.freeze(out);
|
|
234
|
-
return out;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
// src/fee-payer.ts
|
|
238
|
-
function setTransactionFeePayer(feePayer, transaction) {
|
|
239
|
-
if ("feePayer" in transaction && feePayer === transaction.feePayer) {
|
|
240
|
-
return transaction;
|
|
241
|
-
}
|
|
242
|
-
const out = {
|
|
243
|
-
...getUnsignedTransaction(transaction),
|
|
244
|
-
feePayer
|
|
245
|
-
};
|
|
246
|
-
Object.freeze(out);
|
|
247
|
-
return out;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
// src/instructions.ts
|
|
251
|
-
function appendTransactionInstruction(instruction, transaction) {
|
|
252
|
-
const out = {
|
|
253
|
-
...getUnsignedTransaction(transaction),
|
|
254
|
-
instructions: [...transaction.instructions, instruction]
|
|
255
|
-
};
|
|
256
|
-
Object.freeze(out);
|
|
257
|
-
return out;
|
|
258
|
-
}
|
|
259
|
-
function prependTransactionInstruction(instruction, transaction) {
|
|
260
|
-
const out = {
|
|
261
|
-
...getUnsignedTransaction(transaction),
|
|
262
|
-
instructions: [instruction, ...transaction.instructions]
|
|
263
|
-
};
|
|
264
|
-
Object.freeze(out);
|
|
265
|
-
return out;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
5
|
// ../codecs-core/dist/index.browser.js
|
|
269
6
|
function assertByteArrayIsNotEmptyForCodec(codecDescription, bytes, offset = 0) {
|
|
270
7
|
if (bytes.length - offset <= 0) {
|
|
@@ -320,7 +57,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
320
57
|
}
|
|
321
58
|
return {
|
|
322
59
|
decode: decoder.decode,
|
|
323
|
-
description: description
|
|
60
|
+
description: description != null ? description : encoder.description,
|
|
324
61
|
encode: encoder.encode,
|
|
325
62
|
fixedSize: encoder.fixedSize,
|
|
326
63
|
maxSize: encoder.maxSize
|
|
@@ -328,7 +65,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
328
65
|
}
|
|
329
66
|
function fixCodecHelper(data, fixedBytes, description) {
|
|
330
67
|
return {
|
|
331
|
-
description: description
|
|
68
|
+
description: description != null ? description : `fixed(${fixedBytes}, ${data.description})`,
|
|
332
69
|
fixedSize: fixedBytes,
|
|
333
70
|
maxSize: fixedBytes
|
|
334
71
|
};
|
|
@@ -384,14 +121,15 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
384
121
|
}
|
|
385
122
|
}
|
|
386
123
|
function sharedNumberFactory(input) {
|
|
124
|
+
var _a;
|
|
387
125
|
let littleEndian;
|
|
388
126
|
let defaultDescription = input.name;
|
|
389
127
|
if (input.size > 1) {
|
|
390
|
-
littleEndian = !("endian" in input.
|
|
128
|
+
littleEndian = !("endian" in input.config) || input.config.endian === 0;
|
|
391
129
|
defaultDescription += littleEndian ? "(le)" : "(be)";
|
|
392
130
|
}
|
|
393
131
|
return {
|
|
394
|
-
description: input.
|
|
132
|
+
description: (_a = input.config.description) != null ? _a : defaultDescription,
|
|
395
133
|
fixedSize: input.size,
|
|
396
134
|
littleEndian,
|
|
397
135
|
maxSize: input.size
|
|
@@ -428,255 +166,83 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
428
166
|
};
|
|
429
167
|
}
|
|
430
168
|
function toArrayBuffer(bytes, offset, length) {
|
|
431
|
-
const bytesOffset = bytes.byteOffset + (offset
|
|
432
|
-
const bytesLength = length
|
|
169
|
+
const bytesOffset = bytes.byteOffset + (offset != null ? offset : 0);
|
|
170
|
+
const bytesLength = length != null ? length : bytes.byteLength;
|
|
433
171
|
return bytes.buffer.slice(bytesOffset, bytesOffset + bytesLength);
|
|
434
172
|
}
|
|
435
|
-
var getShortU16Encoder = (
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
const
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
bytes[ii
|
|
173
|
+
var getShortU16Encoder = (config = {}) => {
|
|
174
|
+
var _a;
|
|
175
|
+
return {
|
|
176
|
+
description: (_a = config.description) != null ? _a : "shortU16",
|
|
177
|
+
encode: (value) => {
|
|
178
|
+
assertNumberIsBetweenForCodec("shortU16", 0, 65535, value);
|
|
179
|
+
const bytes = [0];
|
|
180
|
+
for (let ii = 0; ; ii += 1) {
|
|
181
|
+
const alignedValue = value >> ii * 7;
|
|
182
|
+
if (alignedValue === 0) {
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
const nextSevenBits = 127 & alignedValue;
|
|
186
|
+
bytes[ii] = nextSevenBits;
|
|
187
|
+
if (ii > 0) {
|
|
188
|
+
bytes[ii - 1] |= 128;
|
|
189
|
+
}
|
|
449
190
|
}
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
}
|
|
456
|
-
var getShortU16Decoder = (
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
191
|
+
return new Uint8Array(bytes);
|
|
192
|
+
},
|
|
193
|
+
fixedSize: null,
|
|
194
|
+
maxSize: 3
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
var getShortU16Decoder = (config = {}) => {
|
|
198
|
+
var _a;
|
|
199
|
+
return {
|
|
200
|
+
decode: (bytes, offset = 0) => {
|
|
201
|
+
let value = 0;
|
|
202
|
+
let byteCount = 0;
|
|
203
|
+
while (++byteCount) {
|
|
204
|
+
const byteIndex = byteCount - 1;
|
|
205
|
+
const currentByte = bytes[offset + byteIndex];
|
|
206
|
+
const nextSevenBits = 127 & currentByte;
|
|
207
|
+
value |= nextSevenBits << byteIndex * 7;
|
|
208
|
+
if ((currentByte & 128) === 0) {
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
467
211
|
}
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
}
|
|
475
|
-
var getU32Encoder = (
|
|
212
|
+
return [value, offset + byteCount];
|
|
213
|
+
},
|
|
214
|
+
description: (_a = config.description) != null ? _a : "shortU16",
|
|
215
|
+
fixedSize: null,
|
|
216
|
+
maxSize: 3
|
|
217
|
+
};
|
|
218
|
+
};
|
|
219
|
+
var getU32Encoder = (config = {}) => numberEncoderFactory({
|
|
220
|
+
config,
|
|
476
221
|
name: "u32",
|
|
477
|
-
options,
|
|
478
222
|
range: [0, Number("0xffffffff")],
|
|
479
223
|
set: (view, value, le) => view.setUint32(0, value, le),
|
|
480
224
|
size: 4
|
|
481
225
|
});
|
|
482
|
-
var getU32Decoder = (
|
|
226
|
+
var getU32Decoder = (config = {}) => numberDecoderFactory({
|
|
227
|
+
config,
|
|
483
228
|
get: (view, le) => view.getUint32(0, le),
|
|
484
229
|
name: "u32",
|
|
485
|
-
options,
|
|
486
230
|
size: 4
|
|
487
231
|
});
|
|
488
|
-
var getU8Encoder = (
|
|
232
|
+
var getU8Encoder = (config = {}) => numberEncoderFactory({
|
|
233
|
+
config,
|
|
489
234
|
name: "u8",
|
|
490
|
-
options,
|
|
491
235
|
range: [0, Number("0xff")],
|
|
492
236
|
set: (view, value) => view.setUint8(0, value),
|
|
493
237
|
size: 1
|
|
494
238
|
});
|
|
495
|
-
var getU8Decoder = (
|
|
239
|
+
var getU8Decoder = (config = {}) => numberDecoderFactory({
|
|
240
|
+
config,
|
|
496
241
|
get: (view) => view.getUint8(0),
|
|
497
242
|
name: "u8",
|
|
498
|
-
options,
|
|
499
243
|
size: 1
|
|
500
244
|
});
|
|
501
245
|
|
|
502
|
-
// ../codecs-data-structures/dist/index.browser.js
|
|
503
|
-
function sumCodecSizes(sizes) {
|
|
504
|
-
return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
|
|
505
|
-
}
|
|
506
|
-
function decodeArrayLikeCodecSize(size, childrenSizes, bytes, offset) {
|
|
507
|
-
if (typeof size === "number") {
|
|
508
|
-
return [size, offset];
|
|
509
|
-
}
|
|
510
|
-
if (typeof size === "object") {
|
|
511
|
-
return size.decode(bytes, offset);
|
|
512
|
-
}
|
|
513
|
-
if (size === "remainder") {
|
|
514
|
-
const childrenSize = sumCodecSizes(childrenSizes);
|
|
515
|
-
if (childrenSize === null) {
|
|
516
|
-
throw new Error('Codecs of "remainder" size must have fixed-size items.');
|
|
517
|
-
}
|
|
518
|
-
const remainder = bytes.slice(offset).length;
|
|
519
|
-
if (remainder % childrenSize !== 0) {
|
|
520
|
-
throw new Error(
|
|
521
|
-
`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.`
|
|
522
|
-
);
|
|
523
|
-
}
|
|
524
|
-
return [remainder / childrenSize, offset];
|
|
525
|
-
}
|
|
526
|
-
throw new Error(`Unrecognized array-like codec size: ${JSON.stringify(size)}`);
|
|
527
|
-
}
|
|
528
|
-
function getArrayLikeCodecSizeDescription(size) {
|
|
529
|
-
return typeof size === "object" ? size.description : `${size}`;
|
|
530
|
-
}
|
|
531
|
-
function getArrayLikeCodecSizeFromChildren(size, childrenSizes) {
|
|
532
|
-
if (typeof size !== "number")
|
|
533
|
-
return null;
|
|
534
|
-
if (size === 0)
|
|
535
|
-
return 0;
|
|
536
|
-
const childrenSize = sumCodecSizes(childrenSizes);
|
|
537
|
-
return childrenSize === null ? null : childrenSize * size;
|
|
538
|
-
}
|
|
539
|
-
function getArrayLikeCodecSizePrefix(size, realSize) {
|
|
540
|
-
return typeof size === "object" ? size.encode(realSize) : new Uint8Array();
|
|
541
|
-
}
|
|
542
|
-
function assertValidNumberOfItemsForCodec(codecDescription, expected, actual) {
|
|
543
|
-
if (expected !== actual) {
|
|
544
|
-
throw new Error(`Expected [${codecDescription}] to have ${expected} items, got ${actual}.`);
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
function arrayCodecHelper(item, size, description) {
|
|
548
|
-
if (size === "remainder" && item.fixedSize === null) {
|
|
549
|
-
throw new Error('Codecs of "remainder" size must have fixed-size items.');
|
|
550
|
-
}
|
|
551
|
-
return {
|
|
552
|
-
description: description ?? `array(${item.description}; ${getArrayLikeCodecSizeDescription(size)})`,
|
|
553
|
-
fixedSize: getArrayLikeCodecSizeFromChildren(size, [item.fixedSize]),
|
|
554
|
-
maxSize: getArrayLikeCodecSizeFromChildren(size, [item.maxSize])
|
|
555
|
-
};
|
|
556
|
-
}
|
|
557
|
-
function getArrayEncoder(item, options = {}) {
|
|
558
|
-
const size = options.size ?? getU32Encoder();
|
|
559
|
-
return {
|
|
560
|
-
...arrayCodecHelper(item, size, options.description),
|
|
561
|
-
encode: (value) => {
|
|
562
|
-
if (typeof size === "number") {
|
|
563
|
-
assertValidNumberOfItemsForCodec("array", size, value.length);
|
|
564
|
-
}
|
|
565
|
-
return mergeBytes([getArrayLikeCodecSizePrefix(size, value.length), ...value.map((v) => item.encode(v))]);
|
|
566
|
-
}
|
|
567
|
-
};
|
|
568
|
-
}
|
|
569
|
-
function getArrayDecoder(item, options = {}) {
|
|
570
|
-
const size = options.size ?? getU32Decoder();
|
|
571
|
-
return {
|
|
572
|
-
...arrayCodecHelper(item, size, options.description),
|
|
573
|
-
decode: (bytes, offset = 0) => {
|
|
574
|
-
if (typeof size === "object" && bytes.slice(offset).length === 0) {
|
|
575
|
-
return [[], offset];
|
|
576
|
-
}
|
|
577
|
-
const [resolvedSize, newOffset] = decodeArrayLikeCodecSize(size, [item.fixedSize], bytes, offset);
|
|
578
|
-
offset = newOffset;
|
|
579
|
-
const values = [];
|
|
580
|
-
for (let i = 0; i < resolvedSize; i += 1) {
|
|
581
|
-
const [value, newOffset2] = item.decode(bytes, offset);
|
|
582
|
-
values.push(value);
|
|
583
|
-
offset = newOffset2;
|
|
584
|
-
}
|
|
585
|
-
return [values, offset];
|
|
586
|
-
}
|
|
587
|
-
};
|
|
588
|
-
}
|
|
589
|
-
function getBytesEncoder(options = {}) {
|
|
590
|
-
const size = options.size ?? "variable";
|
|
591
|
-
const sizeDescription = typeof size === "object" ? size.description : `${size}`;
|
|
592
|
-
const description = options.description ?? `bytes(${sizeDescription})`;
|
|
593
|
-
const byteEncoder = {
|
|
594
|
-
description,
|
|
595
|
-
encode: (value) => value,
|
|
596
|
-
fixedSize: null,
|
|
597
|
-
maxSize: null
|
|
598
|
-
};
|
|
599
|
-
if (size === "variable") {
|
|
600
|
-
return byteEncoder;
|
|
601
|
-
}
|
|
602
|
-
if (typeof size === "number") {
|
|
603
|
-
return fixEncoder(byteEncoder, size, description);
|
|
604
|
-
}
|
|
605
|
-
return {
|
|
606
|
-
...byteEncoder,
|
|
607
|
-
encode: (value) => {
|
|
608
|
-
const contentBytes = byteEncoder.encode(value);
|
|
609
|
-
const lengthBytes = size.encode(contentBytes.length);
|
|
610
|
-
return mergeBytes([lengthBytes, contentBytes]);
|
|
611
|
-
}
|
|
612
|
-
};
|
|
613
|
-
}
|
|
614
|
-
function getBytesDecoder(options = {}) {
|
|
615
|
-
const size = options.size ?? "variable";
|
|
616
|
-
const sizeDescription = typeof size === "object" ? size.description : `${size}`;
|
|
617
|
-
const description = options.description ?? `bytes(${sizeDescription})`;
|
|
618
|
-
const byteDecoder = {
|
|
619
|
-
decode: (bytes, offset = 0) => {
|
|
620
|
-
const slice = bytes.slice(offset);
|
|
621
|
-
return [slice, offset + slice.length];
|
|
622
|
-
},
|
|
623
|
-
description,
|
|
624
|
-
fixedSize: null,
|
|
625
|
-
maxSize: null
|
|
626
|
-
};
|
|
627
|
-
if (size === "variable") {
|
|
628
|
-
return byteDecoder;
|
|
629
|
-
}
|
|
630
|
-
if (typeof size === "number") {
|
|
631
|
-
return fixDecoder(byteDecoder, size, description);
|
|
632
|
-
}
|
|
633
|
-
return {
|
|
634
|
-
...byteDecoder,
|
|
635
|
-
decode: (bytes, offset = 0) => {
|
|
636
|
-
assertByteArrayIsNotEmptyForCodec("bytes", bytes, offset);
|
|
637
|
-
const [lengthBigInt, lengthOffset] = size.decode(bytes, offset);
|
|
638
|
-
const length = Number(lengthBigInt);
|
|
639
|
-
offset = lengthOffset;
|
|
640
|
-
const contentBytes = bytes.slice(offset, offset + length);
|
|
641
|
-
assertByteArrayHasEnoughBytesForCodec("bytes", length, contentBytes);
|
|
642
|
-
const [value, contentOffset] = byteDecoder.decode(contentBytes);
|
|
643
|
-
offset += contentOffset;
|
|
644
|
-
return [value, offset];
|
|
645
|
-
}
|
|
646
|
-
};
|
|
647
|
-
}
|
|
648
|
-
function structCodecHelper(fields, description) {
|
|
649
|
-
const fieldDescriptions = fields.map(([name, codec]) => `${String(name)}: ${codec.description}`).join(", ");
|
|
650
|
-
return {
|
|
651
|
-
description: description ?? `struct(${fieldDescriptions})`,
|
|
652
|
-
fixedSize: sumCodecSizes(fields.map(([, field]) => field.fixedSize)),
|
|
653
|
-
maxSize: sumCodecSizes(fields.map(([, field]) => field.maxSize))
|
|
654
|
-
};
|
|
655
|
-
}
|
|
656
|
-
function getStructEncoder(fields, options = {}) {
|
|
657
|
-
return {
|
|
658
|
-
...structCodecHelper(fields, options.description),
|
|
659
|
-
encode: (struct) => {
|
|
660
|
-
const fieldBytes = fields.map(([key, codec]) => codec.encode(struct[key]));
|
|
661
|
-
return mergeBytes(fieldBytes);
|
|
662
|
-
}
|
|
663
|
-
};
|
|
664
|
-
}
|
|
665
|
-
function getStructDecoder(fields, options = {}) {
|
|
666
|
-
return {
|
|
667
|
-
...structCodecHelper(fields, options.description),
|
|
668
|
-
decode: (bytes, offset = 0) => {
|
|
669
|
-
const struct = {};
|
|
670
|
-
fields.forEach(([key, codec]) => {
|
|
671
|
-
const [value, newOffset] = codec.decode(bytes, offset);
|
|
672
|
-
offset = newOffset;
|
|
673
|
-
struct[key] = value;
|
|
674
|
-
});
|
|
675
|
-
return [struct, offset];
|
|
676
|
-
}
|
|
677
|
-
};
|
|
678
|
-
}
|
|
679
|
-
|
|
680
246
|
// ../codecs-strings/dist/index.browser.js
|
|
681
247
|
function assertValidBaseString(alphabet4, testValue, givenValue = testValue) {
|
|
682
248
|
if (!testValue.match(new RegExp(`^[${alphabet4}]*$`))) {
|
|
@@ -745,6 +311,20 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
745
311
|
var alphabet2 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
746
312
|
var getBase58Encoder = () => getBaseXEncoder(alphabet2);
|
|
747
313
|
var getBase58Decoder = () => getBaseXDecoder(alphabet2);
|
|
314
|
+
var getBase64Decoder = () => {
|
|
315
|
+
{
|
|
316
|
+
return {
|
|
317
|
+
decode(bytes, offset = 0) {
|
|
318
|
+
const slice = bytes.slice(offset);
|
|
319
|
+
const value = btoa(String.fromCharCode(...slice));
|
|
320
|
+
return [value, bytes.length];
|
|
321
|
+
},
|
|
322
|
+
description: `base64`,
|
|
323
|
+
fixedSize: null,
|
|
324
|
+
maxSize: null
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
};
|
|
748
328
|
var removeNullCharacters = (value) => (
|
|
749
329
|
// eslint-disable-next-line no-control-regex
|
|
750
330
|
value.replace(/\u0000/g, "")
|
|
@@ -772,56 +352,251 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
772
352
|
maxSize: null
|
|
773
353
|
};
|
|
774
354
|
};
|
|
775
|
-
var getStringEncoder = (
|
|
776
|
-
|
|
777
|
-
const
|
|
778
|
-
const
|
|
355
|
+
var getStringEncoder = (config = {}) => {
|
|
356
|
+
var _a, _b, _c;
|
|
357
|
+
const size = (_a = config.size) != null ? _a : getU32Encoder();
|
|
358
|
+
const encoding = (_b = config.encoding) != null ? _b : getUtf8Encoder();
|
|
359
|
+
const description = (_c = config.description) != null ? _c : `string(${encoding.description}; ${getSizeDescription(size)})`;
|
|
779
360
|
if (size === "variable") {
|
|
780
361
|
return { ...encoding, description };
|
|
781
362
|
}
|
|
782
363
|
if (typeof size === "number") {
|
|
783
364
|
return fixEncoder(encoding, size, description);
|
|
784
365
|
}
|
|
785
|
-
return {
|
|
786
|
-
description,
|
|
787
|
-
encode: (value) => {
|
|
788
|
-
const contentBytes = encoding.encode(value);
|
|
789
|
-
const lengthBytes = size.encode(contentBytes.length);
|
|
790
|
-
return mergeBytes([lengthBytes, contentBytes]);
|
|
791
|
-
},
|
|
792
|
-
fixedSize: null,
|
|
793
|
-
maxSize: null
|
|
366
|
+
return {
|
|
367
|
+
description,
|
|
368
|
+
encode: (value) => {
|
|
369
|
+
const contentBytes = encoding.encode(value);
|
|
370
|
+
const lengthBytes = size.encode(contentBytes.length);
|
|
371
|
+
return mergeBytes([lengthBytes, contentBytes]);
|
|
372
|
+
},
|
|
373
|
+
fixedSize: null,
|
|
374
|
+
maxSize: null
|
|
375
|
+
};
|
|
376
|
+
};
|
|
377
|
+
var getStringDecoder = (config = {}) => {
|
|
378
|
+
var _a, _b, _c;
|
|
379
|
+
const size = (_a = config.size) != null ? _a : getU32Decoder();
|
|
380
|
+
const encoding = (_b = config.encoding) != null ? _b : getUtf8Decoder();
|
|
381
|
+
const description = (_c = config.description) != null ? _c : `string(${encoding.description}; ${getSizeDescription(size)})`;
|
|
382
|
+
if (size === "variable") {
|
|
383
|
+
return { ...encoding, description };
|
|
384
|
+
}
|
|
385
|
+
if (typeof size === "number") {
|
|
386
|
+
return fixDecoder(encoding, size, description);
|
|
387
|
+
}
|
|
388
|
+
return {
|
|
389
|
+
decode: (bytes, offset = 0) => {
|
|
390
|
+
assertByteArrayIsNotEmptyForCodec("string", bytes, offset);
|
|
391
|
+
const [lengthBigInt, lengthOffset] = size.decode(bytes, offset);
|
|
392
|
+
const length = Number(lengthBigInt);
|
|
393
|
+
offset = lengthOffset;
|
|
394
|
+
const contentBytes = bytes.slice(offset, offset + length);
|
|
395
|
+
assertByteArrayHasEnoughBytesForCodec("string", length, contentBytes);
|
|
396
|
+
const [value, contentOffset] = encoding.decode(contentBytes);
|
|
397
|
+
offset += contentOffset;
|
|
398
|
+
return [value, offset];
|
|
399
|
+
},
|
|
400
|
+
description,
|
|
401
|
+
fixedSize: null,
|
|
402
|
+
maxSize: null
|
|
403
|
+
};
|
|
404
|
+
};
|
|
405
|
+
function getSizeDescription(size) {
|
|
406
|
+
return typeof size === "object" ? size.description : `${size}`;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// src/unsigned-transaction.ts
|
|
410
|
+
function getUnsignedTransaction(transaction) {
|
|
411
|
+
if ("signatures" in transaction) {
|
|
412
|
+
const {
|
|
413
|
+
signatures: _,
|
|
414
|
+
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
415
|
+
...unsignedTransaction
|
|
416
|
+
} = transaction;
|
|
417
|
+
return unsignedTransaction;
|
|
418
|
+
} else {
|
|
419
|
+
return transaction;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
// src/blockhash.ts
|
|
424
|
+
var base58Encoder;
|
|
425
|
+
function assertIsBlockhash(putativeBlockhash) {
|
|
426
|
+
if (!base58Encoder)
|
|
427
|
+
base58Encoder = getBase58Encoder();
|
|
428
|
+
try {
|
|
429
|
+
if (
|
|
430
|
+
// Lowest value (32 bytes of zeroes)
|
|
431
|
+
putativeBlockhash.length < 32 || // Highest value (32 bytes of 255)
|
|
432
|
+
putativeBlockhash.length > 44
|
|
433
|
+
) {
|
|
434
|
+
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
435
|
+
}
|
|
436
|
+
const bytes = base58Encoder.encode(putativeBlockhash);
|
|
437
|
+
const numBytes = bytes.byteLength;
|
|
438
|
+
if (numBytes !== 32) {
|
|
439
|
+
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
440
|
+
}
|
|
441
|
+
} catch (e2) {
|
|
442
|
+
throw new Error(`\`${putativeBlockhash}\` is not a blockhash`, {
|
|
443
|
+
cause: e2
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) {
|
|
448
|
+
if ("lifetimeConstraint" in transaction && transaction.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transaction.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
|
|
449
|
+
return transaction;
|
|
450
|
+
}
|
|
451
|
+
const out = {
|
|
452
|
+
...getUnsignedTransaction(transaction),
|
|
453
|
+
lifetimeConstraint: blockhashLifetimeConstraint
|
|
454
|
+
};
|
|
455
|
+
Object.freeze(out);
|
|
456
|
+
return out;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
// src/create-transaction.ts
|
|
460
|
+
function createTransaction({
|
|
461
|
+
version
|
|
462
|
+
}) {
|
|
463
|
+
const out = {
|
|
464
|
+
instructions: [],
|
|
465
|
+
version
|
|
466
|
+
};
|
|
467
|
+
Object.freeze(out);
|
|
468
|
+
return out;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
// ../instructions/dist/index.browser.js
|
|
472
|
+
var AccountRole = /* @__PURE__ */ ((AccountRole2) => {
|
|
473
|
+
AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */
|
|
474
|
+
3] = "WRITABLE_SIGNER";
|
|
475
|
+
AccountRole2[AccountRole2["READONLY_SIGNER"] = /* 2 */
|
|
476
|
+
2] = "READONLY_SIGNER";
|
|
477
|
+
AccountRole2[AccountRole2["WRITABLE"] = /* 1 */
|
|
478
|
+
1] = "WRITABLE";
|
|
479
|
+
AccountRole2[AccountRole2["READONLY"] = /* 0 */
|
|
480
|
+
0] = "READONLY";
|
|
481
|
+
return AccountRole2;
|
|
482
|
+
})(AccountRole || {});
|
|
483
|
+
var IS_WRITABLE_BITMASK = 1;
|
|
484
|
+
function isSignerRole(role) {
|
|
485
|
+
return role >= 2;
|
|
486
|
+
}
|
|
487
|
+
function isWritableRole(role) {
|
|
488
|
+
return (role & IS_WRITABLE_BITMASK) !== 0;
|
|
489
|
+
}
|
|
490
|
+
function mergeRoles(roleA, roleB) {
|
|
491
|
+
return roleA | roleB;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
// src/durable-nonce.ts
|
|
495
|
+
var RECENT_BLOCKHASHES_SYSVAR_ADDRESS = "SysvarRecentB1ockHashes11111111111111111111";
|
|
496
|
+
var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
|
|
497
|
+
function assertIsDurableNonceTransaction(transaction) {
|
|
498
|
+
if (!isDurableNonceTransaction(transaction)) {
|
|
499
|
+
throw new Error("Transaction is not a durable nonce transaction");
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
function createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress) {
|
|
503
|
+
return {
|
|
504
|
+
accounts: [
|
|
505
|
+
{ address: nonceAccountAddress, role: AccountRole.WRITABLE },
|
|
506
|
+
{
|
|
507
|
+
address: RECENT_BLOCKHASHES_SYSVAR_ADDRESS,
|
|
508
|
+
role: AccountRole.READONLY
|
|
509
|
+
},
|
|
510
|
+
{ address: nonceAuthorityAddress, role: AccountRole.READONLY_SIGNER }
|
|
511
|
+
],
|
|
512
|
+
data: new Uint8Array([4, 0, 0, 0]),
|
|
513
|
+
programAddress: SYSTEM_PROGRAM_ADDRESS
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
function isAdvanceNonceAccountInstruction(instruction) {
|
|
517
|
+
var _a;
|
|
518
|
+
return instruction.programAddress === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data
|
|
519
|
+
instruction.data != null && isAdvanceNonceAccountInstructionData(instruction.data) && // Test for exactly 3 accounts
|
|
520
|
+
((_a = instruction.accounts) == null ? void 0 : _a.length) === 3 && // First account is nonce account address
|
|
521
|
+
instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole.WRITABLE && // Second account is recent blockhashes sysvar
|
|
522
|
+
instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole.READONLY && // Third account is nonce authority account
|
|
523
|
+
instruction.accounts[2].address != null && isSignerRole(instruction.accounts[2].role);
|
|
524
|
+
}
|
|
525
|
+
function isAdvanceNonceAccountInstructionData(data) {
|
|
526
|
+
return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;
|
|
527
|
+
}
|
|
528
|
+
function isDurableNonceTransaction(transaction) {
|
|
529
|
+
return "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.nonce === "string" && transaction.instructions[0] != null && isAdvanceNonceAccountInstruction(transaction.instructions[0]);
|
|
530
|
+
}
|
|
531
|
+
function isAdvanceNonceAccountInstructionForNonce(instruction, nonceAccountAddress, nonceAuthorityAddress) {
|
|
532
|
+
return instruction.accounts[0].address === nonceAccountAddress && instruction.accounts[2].address === nonceAuthorityAddress;
|
|
533
|
+
}
|
|
534
|
+
function setTransactionLifetimeUsingDurableNonce({
|
|
535
|
+
nonce,
|
|
536
|
+
nonceAccountAddress,
|
|
537
|
+
nonceAuthorityAddress
|
|
538
|
+
}, transaction) {
|
|
539
|
+
let newInstructions;
|
|
540
|
+
const firstInstruction = transaction.instructions[0];
|
|
541
|
+
if (firstInstruction && isAdvanceNonceAccountInstruction(firstInstruction)) {
|
|
542
|
+
if (isAdvanceNonceAccountInstructionForNonce(firstInstruction, nonceAccountAddress, nonceAuthorityAddress)) {
|
|
543
|
+
if (isDurableNonceTransaction(transaction) && transaction.lifetimeConstraint.nonce === nonce) {
|
|
544
|
+
return transaction;
|
|
545
|
+
} else {
|
|
546
|
+
newInstructions = [firstInstruction, ...transaction.instructions.slice(1)];
|
|
547
|
+
}
|
|
548
|
+
} else {
|
|
549
|
+
newInstructions = [
|
|
550
|
+
createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
|
|
551
|
+
...transaction.instructions.slice(1)
|
|
552
|
+
];
|
|
553
|
+
}
|
|
554
|
+
} else {
|
|
555
|
+
newInstructions = [
|
|
556
|
+
createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
|
|
557
|
+
...transaction.instructions
|
|
558
|
+
];
|
|
559
|
+
}
|
|
560
|
+
const out = {
|
|
561
|
+
...getUnsignedTransaction(transaction),
|
|
562
|
+
instructions: newInstructions,
|
|
563
|
+
lifetimeConstraint: {
|
|
564
|
+
nonce
|
|
565
|
+
}
|
|
794
566
|
};
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
if (typeof size === "number") {
|
|
804
|
-
return fixDecoder(encoding, size, description);
|
|
567
|
+
Object.freeze(out);
|
|
568
|
+
return out;
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
// src/fee-payer.ts
|
|
572
|
+
function setTransactionFeePayer(feePayer, transaction) {
|
|
573
|
+
if ("feePayer" in transaction && feePayer === transaction.feePayer) {
|
|
574
|
+
return transaction;
|
|
805
575
|
}
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
const [lengthBigInt, lengthOffset] = size.decode(bytes, offset);
|
|
810
|
-
const length = Number(lengthBigInt);
|
|
811
|
-
offset = lengthOffset;
|
|
812
|
-
const contentBytes = bytes.slice(offset, offset + length);
|
|
813
|
-
assertByteArrayHasEnoughBytesForCodec("string", length, contentBytes);
|
|
814
|
-
const [value, contentOffset] = encoding.decode(contentBytes);
|
|
815
|
-
offset += contentOffset;
|
|
816
|
-
return [value, offset];
|
|
817
|
-
},
|
|
818
|
-
description,
|
|
819
|
-
fixedSize: null,
|
|
820
|
-
maxSize: null
|
|
576
|
+
const out = {
|
|
577
|
+
...getUnsignedTransaction(transaction),
|
|
578
|
+
feePayer
|
|
821
579
|
};
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
580
|
+
Object.freeze(out);
|
|
581
|
+
return out;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
// src/instructions.ts
|
|
585
|
+
function appendTransactionInstruction(instruction, transaction) {
|
|
586
|
+
const out = {
|
|
587
|
+
...getUnsignedTransaction(transaction),
|
|
588
|
+
instructions: [...transaction.instructions, instruction]
|
|
589
|
+
};
|
|
590
|
+
Object.freeze(out);
|
|
591
|
+
return out;
|
|
592
|
+
}
|
|
593
|
+
function prependTransactionInstruction(instruction, transaction) {
|
|
594
|
+
const out = {
|
|
595
|
+
...getUnsignedTransaction(transaction),
|
|
596
|
+
instructions: [instruction, ...transaction.instructions]
|
|
597
|
+
};
|
|
598
|
+
Object.freeze(out);
|
|
599
|
+
return out;
|
|
825
600
|
}
|
|
826
601
|
|
|
827
602
|
// ../assertions/dist/index.browser.js
|
|
@@ -833,14 +608,16 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
833
608
|
}
|
|
834
609
|
}
|
|
835
610
|
async function assertKeyExporterIsAvailable() {
|
|
611
|
+
var _a;
|
|
836
612
|
assertIsSecureContext();
|
|
837
|
-
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle
|
|
613
|
+
if (typeof globalThis.crypto === "undefined" || typeof ((_a = globalThis.crypto.subtle) == null ? void 0 : _a.exportKey) !== "function") {
|
|
838
614
|
throw new Error("No key export implementation could be found");
|
|
839
615
|
}
|
|
840
616
|
}
|
|
841
617
|
async function assertSigningCapabilityIsAvailable() {
|
|
618
|
+
var _a;
|
|
842
619
|
assertIsSecureContext();
|
|
843
|
-
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle
|
|
620
|
+
if (typeof globalThis.crypto === "undefined" || typeof ((_a = globalThis.crypto.subtle) == null ? void 0 : _a.sign) !== "function") {
|
|
844
621
|
throw new Error("No signing implementation could be found");
|
|
845
622
|
}
|
|
846
623
|
}
|
|
@@ -858,35 +635,36 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
858
635
|
memoizedBase58Decoder = getBase58Decoder();
|
|
859
636
|
return memoizedBase58Decoder;
|
|
860
637
|
}
|
|
861
|
-
function assertIsAddress(
|
|
638
|
+
function assertIsAddress(putativeAddress) {
|
|
862
639
|
try {
|
|
863
640
|
if (
|
|
864
641
|
// Lowest address (32 bytes of zeroes)
|
|
865
|
-
|
|
866
|
-
|
|
642
|
+
putativeAddress.length < 32 || // Highest address (32 bytes of 255)
|
|
643
|
+
putativeAddress.length > 44
|
|
867
644
|
) {
|
|
868
645
|
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
869
646
|
}
|
|
870
|
-
const
|
|
871
|
-
const bytes =
|
|
647
|
+
const base58Encoder2 = getMemoizedBase58Encoder();
|
|
648
|
+
const bytes = base58Encoder2.encode(putativeAddress);
|
|
872
649
|
const numBytes = bytes.byteLength;
|
|
873
650
|
if (numBytes !== 32) {
|
|
874
651
|
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
875
652
|
}
|
|
876
653
|
} catch (e2) {
|
|
877
|
-
throw new Error(`\`${
|
|
654
|
+
throw new Error(`\`${putativeAddress}\` is not a base-58 encoded address`, {
|
|
878
655
|
cause: e2
|
|
879
656
|
});
|
|
880
657
|
}
|
|
881
658
|
}
|
|
882
|
-
function address(
|
|
883
|
-
assertIsAddress(
|
|
884
|
-
return
|
|
659
|
+
function address(putativeAddress) {
|
|
660
|
+
assertIsAddress(putativeAddress);
|
|
661
|
+
return putativeAddress;
|
|
885
662
|
}
|
|
886
663
|
function getAddressEncoder(config) {
|
|
664
|
+
var _a;
|
|
887
665
|
return mapEncoder(
|
|
888
666
|
getStringEncoder({
|
|
889
|
-
description: config
|
|
667
|
+
description: (_a = config == null ? void 0 : config.description) != null ? _a : "Address",
|
|
890
668
|
encoding: getMemoizedBase58Encoder(),
|
|
891
669
|
size: 32
|
|
892
670
|
}),
|
|
@@ -894,8 +672,9 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
894
672
|
);
|
|
895
673
|
}
|
|
896
674
|
function getAddressDecoder(config) {
|
|
675
|
+
var _a;
|
|
897
676
|
return getStringDecoder({
|
|
898
|
-
description: config
|
|
677
|
+
description: (_a = config == null ? void 0 : config.description) != null ? _a : "Address",
|
|
899
678
|
encoding: getMemoizedBase58Decoder(),
|
|
900
679
|
size: 32
|
|
901
680
|
});
|
|
@@ -922,7 +701,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
922
701
|
|
|
923
702
|
// src/accounts.ts
|
|
924
703
|
function upsert(addressMap, address2, update) {
|
|
925
|
-
|
|
704
|
+
var _a;
|
|
705
|
+
addressMap[address2] = update((_a = addressMap[address2]) != null ? _a : { role: AccountRole.READONLY });
|
|
926
706
|
}
|
|
927
707
|
var TYPE = Symbol("AddressMapTypeProperty");
|
|
928
708
|
function getAddressMapFromInstructions(feePayer, instructions) {
|
|
@@ -1190,139 +970,186 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1190
970
|
};
|
|
1191
971
|
}
|
|
1192
972
|
|
|
1193
|
-
//
|
|
1194
|
-
function
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
973
|
+
// ../codecs-data-structures/dist/index.browser.js
|
|
974
|
+
function sumCodecSizes(sizes) {
|
|
975
|
+
return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
|
|
976
|
+
}
|
|
977
|
+
function decodeArrayLikeCodecSize(size, childrenSizes, bytes, offset) {
|
|
978
|
+
if (typeof size === "number") {
|
|
979
|
+
return [size, offset];
|
|
980
|
+
}
|
|
981
|
+
if (typeof size === "object") {
|
|
982
|
+
return size.decode(bytes, offset);
|
|
983
|
+
}
|
|
984
|
+
if (size === "remainder") {
|
|
985
|
+
const childrenSize = sumCodecSizes(childrenSizes);
|
|
986
|
+
if (childrenSize === null) {
|
|
987
|
+
throw new Error('Codecs of "remainder" size must have fixed-size items.');
|
|
1201
988
|
}
|
|
1202
|
-
|
|
1203
|
-
|
|
989
|
+
const remainder = bytes.slice(offset).length;
|
|
990
|
+
if (remainder % childrenSize !== 0) {
|
|
991
|
+
throw new Error(
|
|
992
|
+
`The remainder of the byte array (${remainder} bytes) cannot be split into chunks of ${childrenSize} bytes. Codecs of "remainder" size must have a remainder that is a multiple of its item size. In other words, ${remainder} modulo ${childrenSize} should be equal to zero.`
|
|
993
|
+
);
|
|
994
|
+
}
|
|
995
|
+
return [remainder / childrenSize, offset];
|
|
996
|
+
}
|
|
997
|
+
throw new Error(`Unrecognized array-like codec size: ${JSON.stringify(size)}`);
|
|
998
|
+
}
|
|
999
|
+
function getArrayLikeCodecSizeDescription(size) {
|
|
1000
|
+
return typeof size === "object" ? size.description : `${size}`;
|
|
1001
|
+
}
|
|
1002
|
+
function getArrayLikeCodecSizeFromChildren(size, childrenSizes) {
|
|
1003
|
+
if (typeof size !== "number")
|
|
1004
|
+
return null;
|
|
1005
|
+
if (size === 0)
|
|
1006
|
+
return 0;
|
|
1007
|
+
const childrenSize = sumCodecSizes(childrenSizes);
|
|
1008
|
+
return childrenSize === null ? null : childrenSize * size;
|
|
1009
|
+
}
|
|
1010
|
+
function getArrayLikeCodecSizePrefix(size, realSize) {
|
|
1011
|
+
return typeof size === "object" ? size.encode(realSize) : new Uint8Array();
|
|
1012
|
+
}
|
|
1013
|
+
function assertValidNumberOfItemsForCodec(codecDescription, expected, actual) {
|
|
1014
|
+
if (expected !== actual) {
|
|
1015
|
+
throw new Error(`Expected [${codecDescription}] to have ${expected} items, got ${actual}.`);
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
function arrayCodecHelper(item, size, description) {
|
|
1019
|
+
if (size === "remainder" && item.fixedSize === null) {
|
|
1020
|
+
throw new Error('Codecs of "remainder" size must have fixed-size items.');
|
|
1204
1021
|
}
|
|
1205
1022
|
return {
|
|
1206
|
-
|
|
1207
|
-
|
|
1023
|
+
description: description != null ? description : `array(${item.description}; ${getArrayLikeCodecSizeDescription(size)})`,
|
|
1024
|
+
fixedSize: getArrayLikeCodecSizeFromChildren(size, [item.fixedSize]),
|
|
1025
|
+
maxSize: getArrayLikeCodecSizeFromChildren(size, [item.maxSize])
|
|
1208
1026
|
};
|
|
1209
1027
|
}
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
return
|
|
1028
|
+
function getArrayEncoder(item, config = {}) {
|
|
1029
|
+
var _a;
|
|
1030
|
+
const size = (_a = config.size) != null ? _a : getU32Encoder();
|
|
1031
|
+
return {
|
|
1032
|
+
...arrayCodecHelper(item, size, config.description),
|
|
1033
|
+
encode: (value) => {
|
|
1034
|
+
if (typeof size === "number") {
|
|
1035
|
+
assertValidNumberOfItemsForCodec("array", size, value.length);
|
|
1036
|
+
}
|
|
1037
|
+
return mergeBytes([getArrayLikeCodecSizePrefix(size, value.length), ...value.map((v) => item.encode(v))]);
|
|
1038
|
+
}
|
|
1039
|
+
};
|
|
1214
1040
|
}
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1041
|
+
function getArrayDecoder(item, config = {}) {
|
|
1042
|
+
var _a;
|
|
1043
|
+
const size = (_a = config.size) != null ? _a : getU32Decoder();
|
|
1044
|
+
return {
|
|
1045
|
+
...arrayCodecHelper(item, size, config.description),
|
|
1046
|
+
decode: (bytes, offset = 0) => {
|
|
1047
|
+
if (typeof size === "object" && bytes.slice(offset).length === 0) {
|
|
1048
|
+
return [[], offset];
|
|
1049
|
+
}
|
|
1050
|
+
const [resolvedSize, newOffset] = decodeArrayLikeCodecSize(size, [item.fixedSize], bytes, offset);
|
|
1051
|
+
offset = newOffset;
|
|
1052
|
+
const values = [];
|
|
1053
|
+
for (let i = 0; i < resolvedSize; i += 1) {
|
|
1054
|
+
const [value, newOffset2] = item.decode(bytes, offset);
|
|
1055
|
+
values.push(value);
|
|
1056
|
+
offset = newOffset2;
|
|
1057
|
+
}
|
|
1058
|
+
return [values, offset];
|
|
1059
|
+
}
|
|
1060
|
+
};
|
|
1061
|
+
}
|
|
1062
|
+
function getBytesEncoder(config = {}) {
|
|
1063
|
+
var _a, _b;
|
|
1064
|
+
const size = (_a = config.size) != null ? _a : "variable";
|
|
1065
|
+
const sizeDescription = typeof size === "object" ? size.description : `${size}`;
|
|
1066
|
+
const description = (_b = config.description) != null ? _b : `bytes(${sizeDescription})`;
|
|
1067
|
+
const byteEncoder = {
|
|
1068
|
+
description,
|
|
1069
|
+
encode: (value) => value,
|
|
1070
|
+
fixedSize: null,
|
|
1071
|
+
maxSize: null
|
|
1072
|
+
};
|
|
1073
|
+
if (size === "variable") {
|
|
1074
|
+
return byteEncoder;
|
|
1236
1075
|
}
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
address: message.staticAccounts[accountIndex],
|
|
1240
|
-
role: AccountRole.WRITABLE
|
|
1241
|
-
});
|
|
1242
|
-
accountIndex++;
|
|
1076
|
+
if (typeof size === "number") {
|
|
1077
|
+
return fixEncoder(byteEncoder, size, description);
|
|
1243
1078
|
}
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1079
|
+
return {
|
|
1080
|
+
...byteEncoder,
|
|
1081
|
+
encode: (value) => {
|
|
1082
|
+
const contentBytes = byteEncoder.encode(value);
|
|
1083
|
+
const lengthBytes = size.encode(contentBytes.length);
|
|
1084
|
+
return mergeBytes([lengthBytes, contentBytes]);
|
|
1085
|
+
}
|
|
1086
|
+
};
|
|
1087
|
+
}
|
|
1088
|
+
function getBytesDecoder(config = {}) {
|
|
1089
|
+
var _a, _b;
|
|
1090
|
+
const size = (_a = config.size) != null ? _a : "variable";
|
|
1091
|
+
const sizeDescription = typeof size === "object" ? size.description : `${size}`;
|
|
1092
|
+
const description = (_b = config.description) != null ? _b : `bytes(${sizeDescription})`;
|
|
1093
|
+
const byteDecoder = {
|
|
1094
|
+
decode: (bytes, offset = 0) => {
|
|
1095
|
+
const slice = bytes.slice(offset);
|
|
1096
|
+
return [slice, offset + slice.length];
|
|
1097
|
+
},
|
|
1098
|
+
description,
|
|
1099
|
+
fixedSize: null,
|
|
1100
|
+
maxSize: null
|
|
1101
|
+
};
|
|
1102
|
+
if (size === "variable") {
|
|
1103
|
+
return byteDecoder;
|
|
1250
1104
|
}
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
function convertInstruction(instruction, accountMetas) {
|
|
1254
|
-
const programAddress = accountMetas[instruction.programAddressIndex]?.address;
|
|
1255
|
-
if (!programAddress) {
|
|
1256
|
-
throw new Error(`Could not find program address at index ${instruction.programAddressIndex}`);
|
|
1105
|
+
if (typeof size === "number") {
|
|
1106
|
+
return fixDecoder(byteDecoder, size, description);
|
|
1257
1107
|
}
|
|
1258
|
-
const accounts = instruction.accountIndices?.map((accountIndex) => accountMetas[accountIndex]);
|
|
1259
|
-
const { data } = instruction;
|
|
1260
1108
|
return {
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1109
|
+
...byteDecoder,
|
|
1110
|
+
decode: (bytes, offset = 0) => {
|
|
1111
|
+
assertByteArrayIsNotEmptyForCodec("bytes", bytes, offset);
|
|
1112
|
+
const [lengthBigInt, lengthOffset] = size.decode(bytes, offset);
|
|
1113
|
+
const length = Number(lengthBigInt);
|
|
1114
|
+
offset = lengthOffset;
|
|
1115
|
+
const contentBytes = bytes.slice(offset, offset + length);
|
|
1116
|
+
assertByteArrayHasEnoughBytesForCodec("bytes", length, contentBytes);
|
|
1117
|
+
const [value, contentOffset] = byteDecoder.decode(contentBytes);
|
|
1118
|
+
offset += contentOffset;
|
|
1119
|
+
return [value, offset];
|
|
1120
|
+
}
|
|
1264
1121
|
};
|
|
1265
1122
|
}
|
|
1266
|
-
function
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
} else {
|
|
1274
|
-
const nonceAccountAddress = firstInstruction.accounts[0].address;
|
|
1275
|
-
assertIsAddress(nonceAccountAddress);
|
|
1276
|
-
const nonceAuthorityAddress = firstInstruction.accounts[2].address;
|
|
1277
|
-
assertIsAddress(nonceAuthorityAddress);
|
|
1278
|
-
return {
|
|
1279
|
-
nonce: messageLifetimeToken,
|
|
1280
|
-
nonceAccountAddress,
|
|
1281
|
-
nonceAuthorityAddress
|
|
1282
|
-
};
|
|
1283
|
-
}
|
|
1123
|
+
function structCodecHelper(fields, description) {
|
|
1124
|
+
const fieldDescriptions = fields.map(([name, codec]) => `${String(name)}: ${codec.description}`).join(", ");
|
|
1125
|
+
return {
|
|
1126
|
+
description: description != null ? description : `struct(${fieldDescriptions})`,
|
|
1127
|
+
fixedSize: sumCodecSizes(fields.map(([, field]) => field.fixedSize)),
|
|
1128
|
+
maxSize: sumCodecSizes(fields.map(([, field]) => field.maxSize))
|
|
1129
|
+
};
|
|
1284
1130
|
}
|
|
1285
|
-
function
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
return acc;
|
|
1294
|
-
const address2 = staticAccounts[index];
|
|
1295
|
-
return { ...acc, [address2]: sig };
|
|
1296
|
-
}, {});
|
|
1131
|
+
function getStructEncoder(fields, config = {}) {
|
|
1132
|
+
return {
|
|
1133
|
+
...structCodecHelper(fields, config.description),
|
|
1134
|
+
encode: (struct) => {
|
|
1135
|
+
const fieldBytes = fields.map(([key, codec]) => codec.encode(struct[key]));
|
|
1136
|
+
return mergeBytes(fieldBytes);
|
|
1137
|
+
}
|
|
1138
|
+
};
|
|
1297
1139
|
}
|
|
1298
|
-
function
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
const lifetimeConstraint = getLifetimeConstraint(
|
|
1312
|
-
compiledMessage.lifetimeToken,
|
|
1313
|
-
firstInstruction,
|
|
1314
|
-
lastValidBlockHeight
|
|
1315
|
-
);
|
|
1316
|
-
const signatures = convertSignatures(compiledTransaction);
|
|
1317
|
-
return pipe(
|
|
1318
|
-
createTransaction({ version: compiledMessage.version }),
|
|
1319
|
-
(tx) => setTransactionFeePayer(feePayer, tx),
|
|
1320
|
-
(tx) => instructions.reduce((acc, instruction) => {
|
|
1321
|
-
return appendTransactionInstruction(instruction, acc);
|
|
1322
|
-
}, tx),
|
|
1323
|
-
(tx) => "blockhash" in lifetimeConstraint ? setTransactionLifetimeUsingBlockhash(lifetimeConstraint, tx) : setTransactionLifetimeUsingDurableNonce(lifetimeConstraint, tx),
|
|
1324
|
-
(tx) => compiledTransaction.signatures.length ? { ...tx, signatures } : tx
|
|
1325
|
-
);
|
|
1140
|
+
function getStructDecoder(fields, config = {}) {
|
|
1141
|
+
return {
|
|
1142
|
+
...structCodecHelper(fields, config.description),
|
|
1143
|
+
decode: (bytes, offset = 0) => {
|
|
1144
|
+
const struct = {};
|
|
1145
|
+
fields.forEach(([key, codec]) => {
|
|
1146
|
+
const [value, newOffset] = codec.decode(bytes, offset);
|
|
1147
|
+
offset = newOffset;
|
|
1148
|
+
struct[key] = value;
|
|
1149
|
+
});
|
|
1150
|
+
return [struct, offset];
|
|
1151
|
+
}
|
|
1152
|
+
};
|
|
1326
1153
|
}
|
|
1327
1154
|
|
|
1328
1155
|
// src/serializers/address-table-lookup.ts
|
|
@@ -1394,7 +1221,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1394
1221
|
const encoder = getMemoizedU8Encoder();
|
|
1395
1222
|
return {
|
|
1396
1223
|
...encoder,
|
|
1397
|
-
description: description
|
|
1224
|
+
description: description != null ? description : encoder.description
|
|
1398
1225
|
};
|
|
1399
1226
|
}
|
|
1400
1227
|
var memoizedU8Decoder;
|
|
@@ -1407,7 +1234,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1407
1234
|
const decoder = getMemoizedU8Decoder();
|
|
1408
1235
|
return {
|
|
1409
1236
|
...decoder,
|
|
1410
|
-
description: description
|
|
1237
|
+
description: description != null ? description : decoder.description
|
|
1411
1238
|
};
|
|
1412
1239
|
}
|
|
1413
1240
|
var numSignerAccountsDescription = "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction" ;
|
|
@@ -1461,13 +1288,14 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1461
1288
|
]),
|
|
1462
1289
|
// Convert an instruction to have all fields defined
|
|
1463
1290
|
(instruction) => {
|
|
1291
|
+
var _a, _b;
|
|
1464
1292
|
if (instruction.accountIndices !== void 0 && instruction.data !== void 0) {
|
|
1465
1293
|
return instruction;
|
|
1466
1294
|
}
|
|
1467
1295
|
return {
|
|
1468
1296
|
...instruction,
|
|
1469
|
-
accountIndices: instruction.accountIndices
|
|
1470
|
-
data: instruction.data
|
|
1297
|
+
accountIndices: (_a = instruction.accountIndices) != null ? _a : [],
|
|
1298
|
+
data: (_b = instruction.data) != null ? _b : new Uint8Array(0)
|
|
1471
1299
|
};
|
|
1472
1300
|
}
|
|
1473
1301
|
);
|
|
@@ -1559,12 +1387,13 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1559
1387
|
["addressTableLookups", getAddressTableLookupArrayEncoder()]
|
|
1560
1388
|
]),
|
|
1561
1389
|
(value) => {
|
|
1390
|
+
var _a;
|
|
1562
1391
|
if (value.version === "legacy") {
|
|
1563
1392
|
return value;
|
|
1564
1393
|
}
|
|
1565
1394
|
return {
|
|
1566
1395
|
...value,
|
|
1567
|
-
addressTableLookups: value.addressTableLookups
|
|
1396
|
+
addressTableLookups: (_a = value.addressTableLookups) != null ? _a : []
|
|
1568
1397
|
};
|
|
1569
1398
|
}
|
|
1570
1399
|
);
|
|
@@ -1659,13 +1488,153 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1659
1488
|
description: messageDescription
|
|
1660
1489
|
}),
|
|
1661
1490
|
({ addressTableLookups, ...restOfMessage }) => {
|
|
1662
|
-
if (restOfMessage.version === "legacy" || !addressTableLookups
|
|
1491
|
+
if (restOfMessage.version === "legacy" || !(addressTableLookups == null ? void 0 : addressTableLookups.length)) {
|
|
1663
1492
|
return restOfMessage;
|
|
1664
1493
|
}
|
|
1665
1494
|
return { ...restOfMessage, addressTableLookups };
|
|
1666
1495
|
}
|
|
1667
1496
|
);
|
|
1668
1497
|
}
|
|
1498
|
+
function getCompiledMessageCodec() {
|
|
1499
|
+
return combineCodec(getCompiledMessageEncoder(), getCompiledMessageDecoder());
|
|
1500
|
+
}
|
|
1501
|
+
|
|
1502
|
+
// src/compile-transaction.ts
|
|
1503
|
+
function getCompiledTransaction(transaction) {
|
|
1504
|
+
var _a;
|
|
1505
|
+
const compiledMessage = compileMessage(transaction);
|
|
1506
|
+
let signatures;
|
|
1507
|
+
if ("signatures" in transaction) {
|
|
1508
|
+
signatures = [];
|
|
1509
|
+
for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
|
|
1510
|
+
signatures[ii] = (_a = transaction.signatures[compiledMessage.staticAccounts[ii]]) != null ? _a : new Uint8Array(Array(64).fill(0));
|
|
1511
|
+
}
|
|
1512
|
+
} else {
|
|
1513
|
+
signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
|
|
1514
|
+
}
|
|
1515
|
+
return {
|
|
1516
|
+
compiledMessage,
|
|
1517
|
+
signatures
|
|
1518
|
+
};
|
|
1519
|
+
}
|
|
1520
|
+
|
|
1521
|
+
// ../functional/dist/index.browser.js
|
|
1522
|
+
function pipe(init, ...fns) {
|
|
1523
|
+
return fns.reduce((acc, fn) => fn(acc), init);
|
|
1524
|
+
}
|
|
1525
|
+
|
|
1526
|
+
// src/decompile-transaction.ts
|
|
1527
|
+
function getAccountMetas(message) {
|
|
1528
|
+
const { header } = message;
|
|
1529
|
+
const numWritableSignerAccounts = header.numSignerAccounts - header.numReadonlySignerAccounts;
|
|
1530
|
+
const numWritableNonSignerAccounts = message.staticAccounts.length - header.numSignerAccounts - header.numReadonlyNonSignerAccounts;
|
|
1531
|
+
const accountMetas = [];
|
|
1532
|
+
let accountIndex = 0;
|
|
1533
|
+
for (let i = 0; i < numWritableSignerAccounts; i++) {
|
|
1534
|
+
accountMetas.push({
|
|
1535
|
+
address: message.staticAccounts[accountIndex],
|
|
1536
|
+
role: AccountRole.WRITABLE_SIGNER
|
|
1537
|
+
});
|
|
1538
|
+
accountIndex++;
|
|
1539
|
+
}
|
|
1540
|
+
for (let i = 0; i < header.numReadonlySignerAccounts; i++) {
|
|
1541
|
+
accountMetas.push({
|
|
1542
|
+
address: message.staticAccounts[accountIndex],
|
|
1543
|
+
role: AccountRole.READONLY_SIGNER
|
|
1544
|
+
});
|
|
1545
|
+
accountIndex++;
|
|
1546
|
+
}
|
|
1547
|
+
for (let i = 0; i < numWritableNonSignerAccounts; i++) {
|
|
1548
|
+
accountMetas.push({
|
|
1549
|
+
address: message.staticAccounts[accountIndex],
|
|
1550
|
+
role: AccountRole.WRITABLE
|
|
1551
|
+
});
|
|
1552
|
+
accountIndex++;
|
|
1553
|
+
}
|
|
1554
|
+
for (let i = 0; i < header.numReadonlyNonSignerAccounts; i++) {
|
|
1555
|
+
accountMetas.push({
|
|
1556
|
+
address: message.staticAccounts[accountIndex],
|
|
1557
|
+
role: AccountRole.READONLY
|
|
1558
|
+
});
|
|
1559
|
+
accountIndex++;
|
|
1560
|
+
}
|
|
1561
|
+
return accountMetas;
|
|
1562
|
+
}
|
|
1563
|
+
function convertInstruction(instruction, accountMetas) {
|
|
1564
|
+
var _a, _b;
|
|
1565
|
+
const programAddress = (_a = accountMetas[instruction.programAddressIndex]) == null ? void 0 : _a.address;
|
|
1566
|
+
if (!programAddress) {
|
|
1567
|
+
throw new Error(`Could not find program address at index ${instruction.programAddressIndex}`);
|
|
1568
|
+
}
|
|
1569
|
+
const accounts = (_b = instruction.accountIndices) == null ? void 0 : _b.map((accountIndex) => accountMetas[accountIndex]);
|
|
1570
|
+
const { data } = instruction;
|
|
1571
|
+
return {
|
|
1572
|
+
programAddress,
|
|
1573
|
+
...accounts && accounts.length ? { accounts } : {},
|
|
1574
|
+
...data && data.length ? { data } : {}
|
|
1575
|
+
};
|
|
1576
|
+
}
|
|
1577
|
+
function getLifetimeConstraint(messageLifetimeToken, firstInstruction, lastValidBlockHeight) {
|
|
1578
|
+
if (!firstInstruction || !isAdvanceNonceAccountInstruction(firstInstruction)) {
|
|
1579
|
+
return {
|
|
1580
|
+
blockhash: messageLifetimeToken,
|
|
1581
|
+
lastValidBlockHeight: lastValidBlockHeight != null ? lastValidBlockHeight : 2n ** 64n - 1n
|
|
1582
|
+
// U64 MAX
|
|
1583
|
+
};
|
|
1584
|
+
} else {
|
|
1585
|
+
const nonceAccountAddress = firstInstruction.accounts[0].address;
|
|
1586
|
+
assertIsAddress(nonceAccountAddress);
|
|
1587
|
+
const nonceAuthorityAddress = firstInstruction.accounts[2].address;
|
|
1588
|
+
assertIsAddress(nonceAuthorityAddress);
|
|
1589
|
+
return {
|
|
1590
|
+
nonce: messageLifetimeToken,
|
|
1591
|
+
nonceAccountAddress,
|
|
1592
|
+
nonceAuthorityAddress
|
|
1593
|
+
};
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
function convertSignatures(compiledTransaction) {
|
|
1597
|
+
const {
|
|
1598
|
+
compiledMessage: { staticAccounts },
|
|
1599
|
+
signatures
|
|
1600
|
+
} = compiledTransaction;
|
|
1601
|
+
return signatures.reduce((acc, sig, index) => {
|
|
1602
|
+
const allZeros = sig.every((byte) => byte === 0);
|
|
1603
|
+
if (allZeros)
|
|
1604
|
+
return acc;
|
|
1605
|
+
const address2 = staticAccounts[index];
|
|
1606
|
+
return { ...acc, [address2]: sig };
|
|
1607
|
+
}, {});
|
|
1608
|
+
}
|
|
1609
|
+
function decompileTransaction(compiledTransaction, lastValidBlockHeight) {
|
|
1610
|
+
const { compiledMessage } = compiledTransaction;
|
|
1611
|
+
if ("addressTableLookups" in compiledMessage && compiledMessage.addressTableLookups.length > 0) {
|
|
1612
|
+
throw new Error("Cannot convert transaction with addressTableLookups");
|
|
1613
|
+
}
|
|
1614
|
+
const feePayer = compiledMessage.staticAccounts[0];
|
|
1615
|
+
if (!feePayer)
|
|
1616
|
+
throw new Error("No fee payer set in CompiledTransaction");
|
|
1617
|
+
const accountMetas = getAccountMetas(compiledMessage);
|
|
1618
|
+
const instructions = compiledMessage.instructions.map(
|
|
1619
|
+
(compiledInstruction) => convertInstruction(compiledInstruction, accountMetas)
|
|
1620
|
+
);
|
|
1621
|
+
const firstInstruction = instructions[0];
|
|
1622
|
+
const lifetimeConstraint = getLifetimeConstraint(
|
|
1623
|
+
compiledMessage.lifetimeToken,
|
|
1624
|
+
firstInstruction,
|
|
1625
|
+
lastValidBlockHeight
|
|
1626
|
+
);
|
|
1627
|
+
const signatures = convertSignatures(compiledTransaction);
|
|
1628
|
+
return pipe(
|
|
1629
|
+
createTransaction({ version: compiledMessage.version }),
|
|
1630
|
+
(tx) => setTransactionFeePayer(feePayer, tx),
|
|
1631
|
+
(tx) => instructions.reduce((acc, instruction) => {
|
|
1632
|
+
return appendTransactionInstruction(instruction, acc);
|
|
1633
|
+
}, tx),
|
|
1634
|
+
(tx) => "blockhash" in lifetimeConstraint ? setTransactionLifetimeUsingBlockhash(lifetimeConstraint, tx) : setTransactionLifetimeUsingDurableNonce(lifetimeConstraint, tx),
|
|
1635
|
+
(tx) => compiledTransaction.signatures.length ? { ...tx, signatures } : tx
|
|
1636
|
+
);
|
|
1637
|
+
}
|
|
1669
1638
|
|
|
1670
1639
|
// src/serializers/transaction.ts
|
|
1671
1640
|
var signaturesDescription = "A compact array of 64-byte, base-64 encoded Ed25519 signatures" ;
|
|
@@ -1728,52 +1697,20 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1728
1697
|
}
|
|
1729
1698
|
|
|
1730
1699
|
// src/signatures.ts
|
|
1731
|
-
|
|
1732
|
-
try {
|
|
1733
|
-
if (
|
|
1734
|
-
// Lowest value (64 bytes of zeroes)
|
|
1735
|
-
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
1736
|
-
putativeTransactionSignature.length > 88
|
|
1737
|
-
) {
|
|
1738
|
-
throw new Error("Expected input string to decode to a byte array of length 64.");
|
|
1739
|
-
}
|
|
1740
|
-
const bytes = base58.serialize(putativeTransactionSignature);
|
|
1741
|
-
const numBytes = bytes.byteLength;
|
|
1742
|
-
if (numBytes !== 64) {
|
|
1743
|
-
throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
|
|
1744
|
-
}
|
|
1745
|
-
} catch (e2) {
|
|
1746
|
-
throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, {
|
|
1747
|
-
cause: e2
|
|
1748
|
-
});
|
|
1749
|
-
}
|
|
1750
|
-
}
|
|
1751
|
-
function isTransactionSignature(putativeTransactionSignature) {
|
|
1752
|
-
if (
|
|
1753
|
-
// Lowest value (64 bytes of zeroes)
|
|
1754
|
-
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
1755
|
-
putativeTransactionSignature.length > 88
|
|
1756
|
-
) {
|
|
1757
|
-
return false;
|
|
1758
|
-
}
|
|
1759
|
-
const bytes = base58.serialize(putativeTransactionSignature);
|
|
1760
|
-
const numBytes = bytes.byteLength;
|
|
1761
|
-
if (numBytes !== 64) {
|
|
1762
|
-
return false;
|
|
1763
|
-
}
|
|
1764
|
-
return true;
|
|
1765
|
-
}
|
|
1700
|
+
var base58Decoder;
|
|
1766
1701
|
function getSignatureFromTransaction(transaction) {
|
|
1702
|
+
if (!base58Decoder)
|
|
1703
|
+
base58Decoder = getBase58Decoder();
|
|
1767
1704
|
const signatureBytes = transaction.signatures[transaction.feePayer];
|
|
1768
1705
|
if (!signatureBytes) {
|
|
1769
1706
|
throw new Error(
|
|
1770
1707
|
"Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
|
|
1771
1708
|
);
|
|
1772
1709
|
}
|
|
1773
|
-
const
|
|
1774
|
-
return
|
|
1710
|
+
const transactionSignature = base58Decoder.decode(signatureBytes)[0];
|
|
1711
|
+
return transactionSignature;
|
|
1775
1712
|
}
|
|
1776
|
-
async function
|
|
1713
|
+
async function partiallySignTransaction(keyPairs, transaction) {
|
|
1777
1714
|
const compiledMessage = compileMessage(transaction);
|
|
1778
1715
|
const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
|
|
1779
1716
|
const wireMessageBytes = getCompiledMessageEncoder().encode(compiledMessage);
|
|
@@ -1792,12 +1729,17 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1792
1729
|
Object.freeze(out);
|
|
1793
1730
|
return out;
|
|
1794
1731
|
}
|
|
1795
|
-
function
|
|
1796
|
-
|
|
1797
|
-
|
|
1732
|
+
async function signTransaction(keyPairs, transaction) {
|
|
1733
|
+
const out = await partiallySignTransaction(keyPairs, transaction);
|
|
1734
|
+
assertTransactionIsFullySigned(out);
|
|
1735
|
+
Object.freeze(out);
|
|
1736
|
+
return out;
|
|
1798
1737
|
}
|
|
1799
1738
|
function assertTransactionIsFullySigned(transaction) {
|
|
1800
|
-
const signerAddressesFromInstructions = transaction.instructions.flatMap((i) =>
|
|
1739
|
+
const signerAddressesFromInstructions = transaction.instructions.flatMap((i) => {
|
|
1740
|
+
var _a, _b;
|
|
1741
|
+
return (_b = (_a = i.accounts) == null ? void 0 : _a.filter((a) => isSignerRole(a.role))) != null ? _b : [];
|
|
1742
|
+
}).map((a) => a.address);
|
|
1801
1743
|
const requiredSigners = /* @__PURE__ */ new Set([transaction.feePayer, ...signerAddressesFromInstructions]);
|
|
1802
1744
|
requiredSigners.forEach((address2) => {
|
|
1803
1745
|
if (!transaction.signatures[address2]) {
|
|
@@ -1809,30 +1751,30 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1809
1751
|
// src/wire-transaction.ts
|
|
1810
1752
|
function getBase64EncodedWireTransaction(transaction) {
|
|
1811
1753
|
const wireTransactionBytes = getTransactionEncoder().encode(transaction);
|
|
1812
|
-
|
|
1813
|
-
return btoa(String.fromCharCode(...wireTransactionBytes));
|
|
1814
|
-
}
|
|
1754
|
+
return getBase64Decoder().decode(wireTransactionBytes)[0];
|
|
1815
1755
|
}
|
|
1816
1756
|
|
|
1817
1757
|
exports.appendTransactionInstruction = appendTransactionInstruction;
|
|
1818
1758
|
exports.assertIsBlockhash = assertIsBlockhash;
|
|
1819
1759
|
exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
|
|
1820
|
-
exports.assertIsTransactionSignature = assertIsTransactionSignature;
|
|
1821
1760
|
exports.assertTransactionIsFullySigned = assertTransactionIsFullySigned;
|
|
1761
|
+
exports.compileMessage = compileMessage;
|
|
1822
1762
|
exports.createTransaction = createTransaction;
|
|
1823
1763
|
exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
|
|
1764
|
+
exports.getCompiledMessageCodec = getCompiledMessageCodec;
|
|
1765
|
+
exports.getCompiledMessageDecoder = getCompiledMessageDecoder;
|
|
1766
|
+
exports.getCompiledMessageEncoder = getCompiledMessageEncoder;
|
|
1824
1767
|
exports.getSignatureFromTransaction = getSignatureFromTransaction;
|
|
1825
1768
|
exports.getTransactionCodec = getTransactionCodec;
|
|
1826
1769
|
exports.getTransactionDecoder = getTransactionDecoder;
|
|
1827
1770
|
exports.getTransactionEncoder = getTransactionEncoder;
|
|
1828
1771
|
exports.isAdvanceNonceAccountInstruction = isAdvanceNonceAccountInstruction;
|
|
1829
|
-
exports.
|
|
1772
|
+
exports.partiallySignTransaction = partiallySignTransaction;
|
|
1830
1773
|
exports.prependTransactionInstruction = prependTransactionInstruction;
|
|
1831
1774
|
exports.setTransactionFeePayer = setTransactionFeePayer;
|
|
1832
1775
|
exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
|
|
1833
1776
|
exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
|
|
1834
1777
|
exports.signTransaction = signTransaction;
|
|
1835
|
-
exports.transactionSignature = transactionSignature;
|
|
1836
1778
|
|
|
1837
1779
|
return exports;
|
|
1838
1780
|
|