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