@solana/transactions 2.0.0-experimental.df45965 → 2.0.0-experimental.dfb72ea
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -46
- package/dist/index.browser.cjs +441 -240
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +431 -240
- package/dist/index.browser.js.map +1 -1
- package/dist/index.native.js +429 -240
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +439 -240
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +431 -240
- package/dist/index.node.js.map +1 -1
- package/dist/types/accounts.d.ts +2 -2
- package/dist/types/accounts.d.ts.map +1 -1
- package/dist/types/blockhash.d.ts +5 -7
- package/dist/types/blockhash.d.ts.map +1 -1
- package/dist/types/compilable-transaction.d.ts +7 -0
- package/dist/types/compilable-transaction.d.ts.map +1 -0
- package/dist/types/compile-address-table-lookups.d.ts +3 -3
- package/dist/types/compile-address-table-lookups.d.ts.map +1 -1
- package/dist/types/compile-header.d.ts +1 -1
- package/dist/types/compile-instructions.d.ts +1 -1
- package/dist/types/compile-lifetime-token.d.ts +1 -1
- package/dist/types/compile-static-accounts.d.ts +3 -3
- package/dist/types/compile-static-accounts.d.ts.map +1 -1
- package/dist/types/compile-transaction.d.ts +6 -7
- package/dist/types/compile-transaction.d.ts.map +1 -1
- package/dist/types/create-transaction.d.ts +1 -1
- package/dist/types/decompile-transaction.d.ts +13 -0
- package/dist/types/decompile-transaction.d.ts.map +1 -0
- package/dist/types/durable-nonce.d.ts +7 -8
- package/dist/types/durable-nonce.d.ts.map +1 -1
- package/dist/types/fee-payer.d.ts +6 -6
- package/dist/types/fee-payer.d.ts.map +1 -1
- package/dist/types/index.d.ts +13 -9
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/instructions.d.ts +4 -2
- package/dist/types/instructions.d.ts.map +1 -1
- package/dist/types/message.d.ts +6 -10
- package/dist/types/message.d.ts.map +1 -1
- package/dist/types/serializers/address-table-lookup.d.ts +5 -5
- package/dist/types/serializers/address-table-lookup.d.ts.map +1 -1
- package/dist/types/serializers/header.d.ts +5 -5
- package/dist/types/serializers/header.d.ts.map +1 -1
- package/dist/types/serializers/index.d.ts +2 -1
- package/dist/types/serializers/index.d.ts.map +1 -1
- package/dist/types/serializers/instruction.d.ts +5 -5
- package/dist/types/serializers/instruction.d.ts.map +1 -1
- package/dist/types/serializers/message.d.ts +5 -5
- package/dist/types/serializers/message.d.ts.map +1 -1
- package/dist/types/serializers/transaction-version.d.ts +5 -5
- package/dist/types/serializers/transaction-version.d.ts.map +1 -1
- package/dist/types/serializers/transaction.d.ts +9 -6
- package/dist/types/serializers/transaction.d.ts.map +1 -1
- package/dist/types/signatures.d.ts +9 -13
- package/dist/types/signatures.d.ts.map +1 -1
- package/dist/types/types.d.ts +6 -13
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/unsigned-transaction.d.ts +1 -1
- package/dist/types/wire-transaction.d.ts +1 -1
- package/dist/types/wire-transaction.d.ts.map +1 -1
- package/package.json +18 -39
- package/dist/index.development.js +0 -1378
- package/dist/index.development.js.map +0 -1
- package/dist/index.production.min.js +0 -26
|
@@ -1,1378 +0,0 @@
|
|
|
1
|
-
this.globalThis = this.globalThis || {};
|
|
2
|
-
this.globalThis.solanaWeb3 = (function (exports) {
|
|
3
|
-
'use strict';
|
|
4
|
-
|
|
5
|
-
var __defProp = Object.defineProperty;
|
|
6
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
-
var __publicField = (obj, key, value) => {
|
|
8
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
9
|
-
return value;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/errors.mjs
|
|
13
|
-
var InvalidBaseStringError = class extends Error {
|
|
14
|
-
constructor(value, base, cause) {
|
|
15
|
-
const message = `Expected a string of base ${base}, got [${value}].`;
|
|
16
|
-
super(message);
|
|
17
|
-
__publicField(this, "name", "InvalidBaseStringError");
|
|
18
|
-
this.cause = cause;
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/baseX.mjs
|
|
23
|
-
var baseX = (alphabet) => {
|
|
24
|
-
const base = alphabet.length;
|
|
25
|
-
const baseBigInt = BigInt(base);
|
|
26
|
-
return {
|
|
27
|
-
description: `base${base}`,
|
|
28
|
-
fixedSize: null,
|
|
29
|
-
maxSize: null,
|
|
30
|
-
serialize(value) {
|
|
31
|
-
if (!value.match(new RegExp(`^[${alphabet}]*$`))) {
|
|
32
|
-
throw new InvalidBaseStringError(value, base);
|
|
33
|
-
}
|
|
34
|
-
if (value === "")
|
|
35
|
-
return new Uint8Array();
|
|
36
|
-
const chars = [...value];
|
|
37
|
-
let trailIndex = chars.findIndex((c) => c !== alphabet[0]);
|
|
38
|
-
trailIndex = trailIndex === -1 ? chars.length : trailIndex;
|
|
39
|
-
const leadingZeroes = Array(trailIndex).fill(0);
|
|
40
|
-
if (trailIndex === chars.length)
|
|
41
|
-
return Uint8Array.from(leadingZeroes);
|
|
42
|
-
const tailChars = chars.slice(trailIndex);
|
|
43
|
-
let base10Number = 0n;
|
|
44
|
-
let baseXPower = 1n;
|
|
45
|
-
for (let i = tailChars.length - 1; i >= 0; i -= 1) {
|
|
46
|
-
base10Number += baseXPower * BigInt(alphabet.indexOf(tailChars[i]));
|
|
47
|
-
baseXPower *= baseBigInt;
|
|
48
|
-
}
|
|
49
|
-
const tailBytes = [];
|
|
50
|
-
while (base10Number > 0n) {
|
|
51
|
-
tailBytes.unshift(Number(base10Number % 256n));
|
|
52
|
-
base10Number /= 256n;
|
|
53
|
-
}
|
|
54
|
-
return Uint8Array.from(leadingZeroes.concat(tailBytes));
|
|
55
|
-
},
|
|
56
|
-
deserialize(buffer, offset = 0) {
|
|
57
|
-
if (buffer.length === 0)
|
|
58
|
-
return ["", 0];
|
|
59
|
-
const bytes = buffer.slice(offset);
|
|
60
|
-
let trailIndex = bytes.findIndex((n) => n !== 0);
|
|
61
|
-
trailIndex = trailIndex === -1 ? bytes.length : trailIndex;
|
|
62
|
-
const leadingZeroes = alphabet[0].repeat(trailIndex);
|
|
63
|
-
if (trailIndex === bytes.length)
|
|
64
|
-
return [leadingZeroes, buffer.length];
|
|
65
|
-
let base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
|
|
66
|
-
const tailChars = [];
|
|
67
|
-
while (base10Number > 0n) {
|
|
68
|
-
tailChars.unshift(alphabet[Number(base10Number % baseBigInt)]);
|
|
69
|
-
base10Number /= baseBigInt;
|
|
70
|
-
}
|
|
71
|
-
return [leadingZeroes + tailChars.join(""), buffer.length];
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/base58.mjs
|
|
77
|
-
var base58 = baseX("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
|
|
78
|
-
|
|
79
|
-
// src/unsigned-transaction.ts
|
|
80
|
-
function getUnsignedTransaction(transaction) {
|
|
81
|
-
if ("signatures" in transaction) {
|
|
82
|
-
const {
|
|
83
|
-
signatures: _,
|
|
84
|
-
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
85
|
-
...unsignedTransaction
|
|
86
|
-
} = transaction;
|
|
87
|
-
return unsignedTransaction;
|
|
88
|
-
} else {
|
|
89
|
-
return transaction;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// src/blockhash.ts
|
|
94
|
-
function assertIsBlockhash(putativeBlockhash) {
|
|
95
|
-
try {
|
|
96
|
-
if (
|
|
97
|
-
// Lowest value (32 bytes of zeroes)
|
|
98
|
-
putativeBlockhash.length < 32 || // Highest value (32 bytes of 255)
|
|
99
|
-
putativeBlockhash.length > 44
|
|
100
|
-
) {
|
|
101
|
-
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
102
|
-
}
|
|
103
|
-
const bytes = base58.serialize(putativeBlockhash);
|
|
104
|
-
const numBytes = bytes.byteLength;
|
|
105
|
-
if (numBytes !== 32) {
|
|
106
|
-
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
107
|
-
}
|
|
108
|
-
} catch (e2) {
|
|
109
|
-
throw new Error(`\`${putativeBlockhash}\` is not a blockhash`, {
|
|
110
|
-
cause: e2
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) {
|
|
115
|
-
if ("lifetimeConstraint" in transaction && transaction.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transaction.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
|
|
116
|
-
return transaction;
|
|
117
|
-
}
|
|
118
|
-
const out = {
|
|
119
|
-
...getUnsignedTransaction(transaction),
|
|
120
|
-
lifetimeConstraint: blockhashLifetimeConstraint
|
|
121
|
-
};
|
|
122
|
-
Object.freeze(out);
|
|
123
|
-
return out;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// src/create-transaction.ts
|
|
127
|
-
function createTransaction({
|
|
128
|
-
version
|
|
129
|
-
}) {
|
|
130
|
-
const out = {
|
|
131
|
-
instructions: [],
|
|
132
|
-
version
|
|
133
|
-
};
|
|
134
|
-
Object.freeze(out);
|
|
135
|
-
return out;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// ../instructions/dist/index.browser.js
|
|
139
|
-
var AccountRole = /* @__PURE__ */ ((AccountRole2) => {
|
|
140
|
-
AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */
|
|
141
|
-
3] = "WRITABLE_SIGNER";
|
|
142
|
-
AccountRole2[AccountRole2["READONLY_SIGNER"] = /* 2 */
|
|
143
|
-
2] = "READONLY_SIGNER";
|
|
144
|
-
AccountRole2[AccountRole2["WRITABLE"] = /* 1 */
|
|
145
|
-
1] = "WRITABLE";
|
|
146
|
-
AccountRole2[AccountRole2["READONLY"] = /* 0 */
|
|
147
|
-
0] = "READONLY";
|
|
148
|
-
return AccountRole2;
|
|
149
|
-
})(AccountRole || {});
|
|
150
|
-
var IS_WRITABLE_BITMASK = 1;
|
|
151
|
-
function isSignerRole(role) {
|
|
152
|
-
return role >= 2;
|
|
153
|
-
}
|
|
154
|
-
function isWritableRole(role) {
|
|
155
|
-
return (role & IS_WRITABLE_BITMASK) !== 0;
|
|
156
|
-
}
|
|
157
|
-
function mergeRoles(roleA, roleB) {
|
|
158
|
-
return roleA | roleB;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// src/durable-nonce.ts
|
|
162
|
-
var RECENT_BLOCKHASHES_SYSVAR_ADDRESS = "SysvarRecentB1ockHashes11111111111111111111";
|
|
163
|
-
var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
|
|
164
|
-
function assertIsDurableNonceTransaction(transaction) {
|
|
165
|
-
if (!isDurableNonceTransaction(transaction)) {
|
|
166
|
-
throw new Error("Transaction is not a durable nonce transaction");
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
function createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress) {
|
|
170
|
-
return {
|
|
171
|
-
accounts: [
|
|
172
|
-
{ address: nonceAccountAddress, role: AccountRole.WRITABLE },
|
|
173
|
-
{
|
|
174
|
-
address: RECENT_BLOCKHASHES_SYSVAR_ADDRESS,
|
|
175
|
-
role: AccountRole.READONLY
|
|
176
|
-
},
|
|
177
|
-
{ address: nonceAuthorityAddress, role: AccountRole.READONLY_SIGNER }
|
|
178
|
-
],
|
|
179
|
-
data: new Uint8Array([4, 0, 0, 0]),
|
|
180
|
-
programAddress: SYSTEM_PROGRAM_ADDRESS
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
function isAdvanceNonceAccountInstruction(instruction) {
|
|
184
|
-
return instruction.programAddress === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data
|
|
185
|
-
instruction.data != null && isAdvanceNonceAccountInstructionData(instruction.data) && // Test for exactly 3 accounts
|
|
186
|
-
instruction.accounts?.length === 3 && // First account is nonce account address
|
|
187
|
-
instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole.WRITABLE && // Second account is recent blockhashes sysvar
|
|
188
|
-
instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole.READONLY && // Third account is nonce authority account
|
|
189
|
-
instruction.accounts[2].address != null && instruction.accounts[2].role === AccountRole.READONLY_SIGNER;
|
|
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 setTransactionLifetimeUsingDurableNonce({
|
|
198
|
-
nonce,
|
|
199
|
-
nonceAccountAddress,
|
|
200
|
-
nonceAuthorityAddress
|
|
201
|
-
}, transaction) {
|
|
202
|
-
const isAlreadyDurableNonceTransaction = isDurableNonceTransaction(transaction);
|
|
203
|
-
if (isAlreadyDurableNonceTransaction && transaction.lifetimeConstraint.nonce === nonce && transaction.instructions[0].accounts[0].address === nonceAccountAddress && transaction.instructions[0].accounts[2].address === nonceAuthorityAddress) {
|
|
204
|
-
return transaction;
|
|
205
|
-
}
|
|
206
|
-
const out = {
|
|
207
|
-
...getUnsignedTransaction(transaction),
|
|
208
|
-
instructions: [
|
|
209
|
-
createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
|
|
210
|
-
...isAlreadyDurableNonceTransaction ? transaction.instructions.slice(1) : transaction.instructions
|
|
211
|
-
],
|
|
212
|
-
lifetimeConstraint: {
|
|
213
|
-
nonce
|
|
214
|
-
}
|
|
215
|
-
};
|
|
216
|
-
Object.freeze(out);
|
|
217
|
-
return out;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
// src/fee-payer.ts
|
|
221
|
-
function setTransactionFeePayer(feePayer, transaction) {
|
|
222
|
-
if ("feePayer" in transaction && feePayer === transaction.feePayer) {
|
|
223
|
-
return transaction;
|
|
224
|
-
}
|
|
225
|
-
const out = {
|
|
226
|
-
...getUnsignedTransaction(transaction),
|
|
227
|
-
feePayer
|
|
228
|
-
};
|
|
229
|
-
Object.freeze(out);
|
|
230
|
-
return out;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
// src/instructions.ts
|
|
234
|
-
function appendTransactionInstruction(instruction, transaction) {
|
|
235
|
-
const out = {
|
|
236
|
-
...getUnsignedTransaction(transaction),
|
|
237
|
-
instructions: [...transaction.instructions, instruction]
|
|
238
|
-
};
|
|
239
|
-
Object.freeze(out);
|
|
240
|
-
return out;
|
|
241
|
-
}
|
|
242
|
-
function prependTransactionInstruction(instruction, transaction) {
|
|
243
|
-
const out = {
|
|
244
|
-
...getUnsignedTransaction(transaction),
|
|
245
|
-
instructions: [instruction, ...transaction.instructions]
|
|
246
|
-
};
|
|
247
|
-
Object.freeze(out);
|
|
248
|
-
return out;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
// ../codecs-core/dist/index.browser.js
|
|
252
|
-
function assertByteArrayIsNotEmptyForCodec(codecDescription, bytes, offset = 0) {
|
|
253
|
-
if (bytes.length - offset <= 0) {
|
|
254
|
-
throw new Error(`Codec [${codecDescription}] cannot decode empty byte arrays.`);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
function assertByteArrayHasEnoughBytesForCodec(codecDescription, expected, bytes, offset = 0) {
|
|
258
|
-
const bytesLength = bytes.length - offset;
|
|
259
|
-
if (bytesLength < expected) {
|
|
260
|
-
throw new Error(`Codec [${codecDescription}] expected ${expected} bytes, got ${bytesLength}.`);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
var mergeBytes = (byteArrays) => {
|
|
264
|
-
const nonEmptyByteArrays = byteArrays.filter((arr) => arr.length);
|
|
265
|
-
if (nonEmptyByteArrays.length === 0) {
|
|
266
|
-
return byteArrays.length ? byteArrays[0] : new Uint8Array();
|
|
267
|
-
}
|
|
268
|
-
if (nonEmptyByteArrays.length === 1) {
|
|
269
|
-
return nonEmptyByteArrays[0];
|
|
270
|
-
}
|
|
271
|
-
const totalLength = nonEmptyByteArrays.reduce((total, arr) => total + arr.length, 0);
|
|
272
|
-
const result = new Uint8Array(totalLength);
|
|
273
|
-
let offset = 0;
|
|
274
|
-
nonEmptyByteArrays.forEach((arr) => {
|
|
275
|
-
result.set(arr, offset);
|
|
276
|
-
offset += arr.length;
|
|
277
|
-
});
|
|
278
|
-
return result;
|
|
279
|
-
};
|
|
280
|
-
var padBytes = (bytes, length) => {
|
|
281
|
-
if (bytes.length >= length)
|
|
282
|
-
return bytes;
|
|
283
|
-
const paddedBytes = new Uint8Array(length).fill(0);
|
|
284
|
-
paddedBytes.set(bytes);
|
|
285
|
-
return paddedBytes;
|
|
286
|
-
};
|
|
287
|
-
var fixBytes = (bytes, length) => padBytes(bytes.length <= length ? bytes : bytes.slice(0, length), length);
|
|
288
|
-
function fixCodecHelper(data, fixedBytes, description) {
|
|
289
|
-
return {
|
|
290
|
-
description: description ?? `fixed(${fixedBytes}, ${data.description})`,
|
|
291
|
-
fixedSize: fixedBytes,
|
|
292
|
-
maxSize: fixedBytes
|
|
293
|
-
};
|
|
294
|
-
}
|
|
295
|
-
function fixEncoder(encoder, fixedBytes, description) {
|
|
296
|
-
return {
|
|
297
|
-
...fixCodecHelper(encoder, fixedBytes, description),
|
|
298
|
-
encode: (value) => fixBytes(encoder.encode(value), fixedBytes)
|
|
299
|
-
};
|
|
300
|
-
}
|
|
301
|
-
function fixDecoder(decoder, fixedBytes, description) {
|
|
302
|
-
return {
|
|
303
|
-
...fixCodecHelper(decoder, fixedBytes, description),
|
|
304
|
-
decode: (bytes, offset = 0) => {
|
|
305
|
-
assertByteArrayHasEnoughBytesForCodec("fixCodec", fixedBytes, bytes, offset);
|
|
306
|
-
if (offset > 0 || bytes.length > fixedBytes) {
|
|
307
|
-
bytes = bytes.slice(offset, offset + fixedBytes);
|
|
308
|
-
}
|
|
309
|
-
if (decoder.fixedSize !== null) {
|
|
310
|
-
bytes = fixBytes(bytes, decoder.fixedSize);
|
|
311
|
-
}
|
|
312
|
-
const [value] = decoder.decode(bytes, 0);
|
|
313
|
-
return [value, offset + fixedBytes];
|
|
314
|
-
}
|
|
315
|
-
};
|
|
316
|
-
}
|
|
317
|
-
function mapEncoder(encoder, unmap) {
|
|
318
|
-
return {
|
|
319
|
-
description: encoder.description,
|
|
320
|
-
encode: (value) => encoder.encode(unmap(value)),
|
|
321
|
-
fixedSize: encoder.fixedSize,
|
|
322
|
-
maxSize: encoder.maxSize
|
|
323
|
-
};
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
// ../codecs-numbers/dist/index.browser.js
|
|
327
|
-
function assertNumberIsBetweenForCodec(codecDescription, min, max, value) {
|
|
328
|
-
if (value < min || value > max) {
|
|
329
|
-
throw new Error(
|
|
330
|
-
`Codec [${codecDescription}] expected number to be in the range [${min}, ${max}], got ${value}.`
|
|
331
|
-
);
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
function sharedNumberFactory(input) {
|
|
335
|
-
let littleEndian;
|
|
336
|
-
let defaultDescription = input.name;
|
|
337
|
-
if (input.size > 1) {
|
|
338
|
-
littleEndian = !("endian" in input.options) || input.options.endian === 0;
|
|
339
|
-
defaultDescription += littleEndian ? "(le)" : "(be)";
|
|
340
|
-
}
|
|
341
|
-
return {
|
|
342
|
-
description: input.options.description ?? defaultDescription,
|
|
343
|
-
fixedSize: input.size,
|
|
344
|
-
littleEndian,
|
|
345
|
-
maxSize: input.size
|
|
346
|
-
};
|
|
347
|
-
}
|
|
348
|
-
function numberEncoderFactory(input) {
|
|
349
|
-
const codecData = sharedNumberFactory(input);
|
|
350
|
-
return {
|
|
351
|
-
description: codecData.description,
|
|
352
|
-
encode(value) {
|
|
353
|
-
if (input.range) {
|
|
354
|
-
assertNumberIsBetweenForCodec(input.name, input.range[0], input.range[1], value);
|
|
355
|
-
}
|
|
356
|
-
const arrayBuffer = new ArrayBuffer(input.size);
|
|
357
|
-
input.set(new DataView(arrayBuffer), value, codecData.littleEndian);
|
|
358
|
-
return new Uint8Array(arrayBuffer);
|
|
359
|
-
},
|
|
360
|
-
fixedSize: codecData.fixedSize,
|
|
361
|
-
maxSize: codecData.maxSize
|
|
362
|
-
};
|
|
363
|
-
}
|
|
364
|
-
function numberDecoderFactory(input) {
|
|
365
|
-
const codecData = sharedNumberFactory(input);
|
|
366
|
-
return {
|
|
367
|
-
decode(bytes, offset = 0) {
|
|
368
|
-
assertByteArrayIsNotEmptyForCodec(codecData.description, bytes, offset);
|
|
369
|
-
assertByteArrayHasEnoughBytesForCodec(codecData.description, input.size, bytes, offset);
|
|
370
|
-
const view = new DataView(toArrayBuffer(bytes, offset, input.size));
|
|
371
|
-
return [input.get(view, codecData.littleEndian), offset + input.size];
|
|
372
|
-
},
|
|
373
|
-
description: codecData.description,
|
|
374
|
-
fixedSize: codecData.fixedSize,
|
|
375
|
-
maxSize: codecData.maxSize
|
|
376
|
-
};
|
|
377
|
-
}
|
|
378
|
-
function toArrayBuffer(bytes, offset, length) {
|
|
379
|
-
const bytesOffset = bytes.byteOffset + (offset ?? 0);
|
|
380
|
-
const bytesLength = length ?? bytes.byteLength;
|
|
381
|
-
return bytes.buffer.slice(bytesOffset, bytesOffset + bytesLength);
|
|
382
|
-
}
|
|
383
|
-
var getShortU16Encoder = (options = {}) => ({
|
|
384
|
-
description: options.description ?? "shortU16",
|
|
385
|
-
encode: (value) => {
|
|
386
|
-
assertNumberIsBetweenForCodec("shortU16", 0, 65535, value);
|
|
387
|
-
const bytes = [0];
|
|
388
|
-
for (let ii = 0; ; ii += 1) {
|
|
389
|
-
const alignedValue = value >> ii * 7;
|
|
390
|
-
if (alignedValue === 0) {
|
|
391
|
-
break;
|
|
392
|
-
}
|
|
393
|
-
const nextSevenBits = 127 & alignedValue;
|
|
394
|
-
bytes[ii] = nextSevenBits;
|
|
395
|
-
if (ii > 0) {
|
|
396
|
-
bytes[ii - 1] |= 128;
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
return new Uint8Array(bytes);
|
|
400
|
-
},
|
|
401
|
-
fixedSize: null,
|
|
402
|
-
maxSize: 3
|
|
403
|
-
});
|
|
404
|
-
var getU32Encoder = (options = {}) => numberEncoderFactory({
|
|
405
|
-
name: "u32",
|
|
406
|
-
options,
|
|
407
|
-
range: [0, Number("0xffffffff")],
|
|
408
|
-
set: (view, value, le) => view.setUint32(0, value, le),
|
|
409
|
-
size: 4
|
|
410
|
-
});
|
|
411
|
-
var getU32Decoder = (options = {}) => numberDecoderFactory({
|
|
412
|
-
get: (view, le) => view.getUint32(0, le),
|
|
413
|
-
name: "u32",
|
|
414
|
-
options,
|
|
415
|
-
size: 4
|
|
416
|
-
});
|
|
417
|
-
var getU8Encoder = (options = {}) => numberEncoderFactory({
|
|
418
|
-
name: "u8",
|
|
419
|
-
options,
|
|
420
|
-
range: [0, Number("0xff")],
|
|
421
|
-
set: (view, value) => view.setUint8(0, value),
|
|
422
|
-
size: 1
|
|
423
|
-
});
|
|
424
|
-
|
|
425
|
-
// ../codecs-data-structures/dist/index.browser.js
|
|
426
|
-
function sumCodecSizes(sizes) {
|
|
427
|
-
return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
|
|
428
|
-
}
|
|
429
|
-
function getArrayLikeCodecSizeDescription(size) {
|
|
430
|
-
return typeof size === "object" ? size.description : `${size}`;
|
|
431
|
-
}
|
|
432
|
-
function getArrayLikeCodecSizeFromChildren(size, childrenSizes) {
|
|
433
|
-
if (typeof size !== "number")
|
|
434
|
-
return null;
|
|
435
|
-
if (size === 0)
|
|
436
|
-
return 0;
|
|
437
|
-
const childrenSize = sumCodecSizes(childrenSizes);
|
|
438
|
-
return childrenSize === null ? null : childrenSize * size;
|
|
439
|
-
}
|
|
440
|
-
function getArrayLikeCodecSizePrefix(size, realSize) {
|
|
441
|
-
return typeof size === "object" ? size.encode(realSize) : new Uint8Array();
|
|
442
|
-
}
|
|
443
|
-
function assertValidNumberOfItemsForCodec(codecDescription, expected, actual) {
|
|
444
|
-
if (expected !== actual) {
|
|
445
|
-
throw new Error(`Expected [${codecDescription}] to have ${expected} items, got ${actual}.`);
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
function arrayCodecHelper(item, size, description) {
|
|
449
|
-
if (size === "remainder" && item.fixedSize === null) {
|
|
450
|
-
throw new Error('Codecs of "remainder" size must have fixed-size items.');
|
|
451
|
-
}
|
|
452
|
-
return {
|
|
453
|
-
description: description ?? `array(${item.description}; ${getArrayLikeCodecSizeDescription(size)})`,
|
|
454
|
-
fixedSize: getArrayLikeCodecSizeFromChildren(size, [item.fixedSize]),
|
|
455
|
-
maxSize: getArrayLikeCodecSizeFromChildren(size, [item.maxSize])
|
|
456
|
-
};
|
|
457
|
-
}
|
|
458
|
-
function getArrayEncoder(item, options = {}) {
|
|
459
|
-
const size = options.size ?? getU32Encoder();
|
|
460
|
-
return {
|
|
461
|
-
...arrayCodecHelper(item, size, options.description),
|
|
462
|
-
encode: (value) => {
|
|
463
|
-
if (typeof size === "number") {
|
|
464
|
-
assertValidNumberOfItemsForCodec("array", size, value.length);
|
|
465
|
-
}
|
|
466
|
-
return mergeBytes([getArrayLikeCodecSizePrefix(size, value.length), ...value.map((v) => item.encode(v))]);
|
|
467
|
-
}
|
|
468
|
-
};
|
|
469
|
-
}
|
|
470
|
-
function getBytesEncoder(options = {}) {
|
|
471
|
-
const size = options.size ?? "variable";
|
|
472
|
-
const sizeDescription = typeof size === "object" ? size.description : `${size}`;
|
|
473
|
-
const description = options.description ?? `bytes(${sizeDescription})`;
|
|
474
|
-
const byteEncoder = {
|
|
475
|
-
description,
|
|
476
|
-
encode: (value) => value,
|
|
477
|
-
fixedSize: null,
|
|
478
|
-
maxSize: null
|
|
479
|
-
};
|
|
480
|
-
if (size === "variable") {
|
|
481
|
-
return byteEncoder;
|
|
482
|
-
}
|
|
483
|
-
if (typeof size === "number") {
|
|
484
|
-
return fixEncoder(byteEncoder, size, description);
|
|
485
|
-
}
|
|
486
|
-
return {
|
|
487
|
-
...byteEncoder,
|
|
488
|
-
encode: (value) => {
|
|
489
|
-
const contentBytes = byteEncoder.encode(value);
|
|
490
|
-
const lengthBytes = size.encode(contentBytes.length);
|
|
491
|
-
return mergeBytes([lengthBytes, contentBytes]);
|
|
492
|
-
}
|
|
493
|
-
};
|
|
494
|
-
}
|
|
495
|
-
function structCodecHelper(fields, description) {
|
|
496
|
-
const fieldDescriptions = fields.map(([name, codec]) => `${String(name)}: ${codec.description}`).join(", ");
|
|
497
|
-
return {
|
|
498
|
-
description: description ?? `struct(${fieldDescriptions})`,
|
|
499
|
-
fixedSize: sumCodecSizes(fields.map(([, field]) => field.fixedSize)),
|
|
500
|
-
maxSize: sumCodecSizes(fields.map(([, field]) => field.maxSize))
|
|
501
|
-
};
|
|
502
|
-
}
|
|
503
|
-
function getStructEncoder(fields, options = {}) {
|
|
504
|
-
return {
|
|
505
|
-
...structCodecHelper(fields, options.description),
|
|
506
|
-
encode: (struct) => {
|
|
507
|
-
const fieldBytes = fields.map(([key, codec]) => codec.encode(struct[key]));
|
|
508
|
-
return mergeBytes(fieldBytes);
|
|
509
|
-
}
|
|
510
|
-
};
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
// ../codecs-strings/dist/index.browser.js
|
|
514
|
-
function assertValidBaseString(alphabet4, testValue, givenValue = testValue) {
|
|
515
|
-
if (!testValue.match(new RegExp(`^[${alphabet4}]*$`))) {
|
|
516
|
-
throw new Error(`Expected a string of base ${alphabet4.length}, got [${givenValue}].`);
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
var getBaseXEncoder = (alphabet4) => {
|
|
520
|
-
const base = alphabet4.length;
|
|
521
|
-
const baseBigInt = BigInt(base);
|
|
522
|
-
return {
|
|
523
|
-
description: `base${base}`,
|
|
524
|
-
encode(value) {
|
|
525
|
-
assertValidBaseString(alphabet4, value);
|
|
526
|
-
if (value === "")
|
|
527
|
-
return new Uint8Array();
|
|
528
|
-
const chars = [...value];
|
|
529
|
-
let trailIndex = chars.findIndex((c) => c !== alphabet4[0]);
|
|
530
|
-
trailIndex = trailIndex === -1 ? chars.length : trailIndex;
|
|
531
|
-
const leadingZeroes = Array(trailIndex).fill(0);
|
|
532
|
-
if (trailIndex === chars.length)
|
|
533
|
-
return Uint8Array.from(leadingZeroes);
|
|
534
|
-
const tailChars = chars.slice(trailIndex);
|
|
535
|
-
let base10Number = 0n;
|
|
536
|
-
let baseXPower = 1n;
|
|
537
|
-
for (let i = tailChars.length - 1; i >= 0; i -= 1) {
|
|
538
|
-
base10Number += baseXPower * BigInt(alphabet4.indexOf(tailChars[i]));
|
|
539
|
-
baseXPower *= baseBigInt;
|
|
540
|
-
}
|
|
541
|
-
const tailBytes = [];
|
|
542
|
-
while (base10Number > 0n) {
|
|
543
|
-
tailBytes.unshift(Number(base10Number % 256n));
|
|
544
|
-
base10Number /= 256n;
|
|
545
|
-
}
|
|
546
|
-
return Uint8Array.from(leadingZeroes.concat(tailBytes));
|
|
547
|
-
},
|
|
548
|
-
fixedSize: null,
|
|
549
|
-
maxSize: null
|
|
550
|
-
};
|
|
551
|
-
};
|
|
552
|
-
var getBaseXDecoder = (alphabet4) => {
|
|
553
|
-
const base = alphabet4.length;
|
|
554
|
-
const baseBigInt = BigInt(base);
|
|
555
|
-
return {
|
|
556
|
-
decode(rawBytes, offset = 0) {
|
|
557
|
-
const bytes = offset === 0 ? rawBytes : rawBytes.slice(offset);
|
|
558
|
-
if (bytes.length === 0)
|
|
559
|
-
return ["", 0];
|
|
560
|
-
let trailIndex = bytes.findIndex((n) => n !== 0);
|
|
561
|
-
trailIndex = trailIndex === -1 ? bytes.length : trailIndex;
|
|
562
|
-
const leadingZeroes = alphabet4[0].repeat(trailIndex);
|
|
563
|
-
if (trailIndex === bytes.length)
|
|
564
|
-
return [leadingZeroes, rawBytes.length];
|
|
565
|
-
let base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
|
|
566
|
-
const tailChars = [];
|
|
567
|
-
while (base10Number > 0n) {
|
|
568
|
-
tailChars.unshift(alphabet4[Number(base10Number % baseBigInt)]);
|
|
569
|
-
base10Number /= baseBigInt;
|
|
570
|
-
}
|
|
571
|
-
return [leadingZeroes + tailChars.join(""), rawBytes.length];
|
|
572
|
-
},
|
|
573
|
-
description: `base${base}`,
|
|
574
|
-
fixedSize: null,
|
|
575
|
-
maxSize: null
|
|
576
|
-
};
|
|
577
|
-
};
|
|
578
|
-
var alphabet2 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
579
|
-
var getBase58Encoder = () => getBaseXEncoder(alphabet2);
|
|
580
|
-
var getBase58Decoder = () => getBaseXDecoder(alphabet2);
|
|
581
|
-
var removeNullCharacters = (value) => (
|
|
582
|
-
// eslint-disable-next-line no-control-regex
|
|
583
|
-
value.replace(/\u0000/g, "")
|
|
584
|
-
);
|
|
585
|
-
var e = globalThis.TextDecoder;
|
|
586
|
-
var o = globalThis.TextEncoder;
|
|
587
|
-
var getUtf8Encoder = () => {
|
|
588
|
-
let textEncoder;
|
|
589
|
-
return {
|
|
590
|
-
description: "utf8",
|
|
591
|
-
encode: (value) => new Uint8Array((textEncoder || (textEncoder = new o())).encode(value)),
|
|
592
|
-
fixedSize: null,
|
|
593
|
-
maxSize: null
|
|
594
|
-
};
|
|
595
|
-
};
|
|
596
|
-
var getUtf8Decoder = () => {
|
|
597
|
-
let textDecoder;
|
|
598
|
-
return {
|
|
599
|
-
decode(bytes, offset = 0) {
|
|
600
|
-
const value = (textDecoder || (textDecoder = new e())).decode(bytes.slice(offset));
|
|
601
|
-
return [removeNullCharacters(value), bytes.length];
|
|
602
|
-
},
|
|
603
|
-
description: "utf8",
|
|
604
|
-
fixedSize: null,
|
|
605
|
-
maxSize: null
|
|
606
|
-
};
|
|
607
|
-
};
|
|
608
|
-
var getStringEncoder = (options = {}) => {
|
|
609
|
-
const size = options.size ?? getU32Encoder();
|
|
610
|
-
const encoding = options.encoding ?? getUtf8Encoder();
|
|
611
|
-
const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
|
|
612
|
-
if (size === "variable") {
|
|
613
|
-
return { ...encoding, description };
|
|
614
|
-
}
|
|
615
|
-
if (typeof size === "number") {
|
|
616
|
-
return fixEncoder(encoding, size, description);
|
|
617
|
-
}
|
|
618
|
-
return {
|
|
619
|
-
description,
|
|
620
|
-
encode: (value) => {
|
|
621
|
-
const contentBytes = encoding.encode(value);
|
|
622
|
-
const lengthBytes = size.encode(contentBytes.length);
|
|
623
|
-
return mergeBytes([lengthBytes, contentBytes]);
|
|
624
|
-
},
|
|
625
|
-
fixedSize: null,
|
|
626
|
-
maxSize: null
|
|
627
|
-
};
|
|
628
|
-
};
|
|
629
|
-
var getStringDecoder = (options = {}) => {
|
|
630
|
-
const size = options.size ?? getU32Decoder();
|
|
631
|
-
const encoding = options.encoding ?? getUtf8Decoder();
|
|
632
|
-
const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
|
|
633
|
-
if (size === "variable") {
|
|
634
|
-
return { ...encoding, description };
|
|
635
|
-
}
|
|
636
|
-
if (typeof size === "number") {
|
|
637
|
-
return fixDecoder(encoding, size, description);
|
|
638
|
-
}
|
|
639
|
-
return {
|
|
640
|
-
decode: (bytes, offset = 0) => {
|
|
641
|
-
assertByteArrayIsNotEmptyForCodec("string", bytes, offset);
|
|
642
|
-
const [lengthBigInt, lengthOffset] = size.decode(bytes, offset);
|
|
643
|
-
const length = Number(lengthBigInt);
|
|
644
|
-
offset = lengthOffset;
|
|
645
|
-
const contentBytes = bytes.slice(offset, offset + length);
|
|
646
|
-
assertByteArrayHasEnoughBytesForCodec("string", length, contentBytes);
|
|
647
|
-
const [value, contentOffset] = encoding.decode(contentBytes);
|
|
648
|
-
offset += contentOffset;
|
|
649
|
-
return [value, offset];
|
|
650
|
-
},
|
|
651
|
-
description,
|
|
652
|
-
fixedSize: null,
|
|
653
|
-
maxSize: null
|
|
654
|
-
};
|
|
655
|
-
};
|
|
656
|
-
function getSizeDescription(size) {
|
|
657
|
-
return typeof size === "object" ? size.description : `${size}`;
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
// ../assertions/dist/index.browser.js
|
|
661
|
-
function assertIsSecureContext() {
|
|
662
|
-
if (!globalThis.isSecureContext) {
|
|
663
|
-
throw new Error(
|
|
664
|
-
"Cryptographic operations are only allowed in secure browser contexts. Read more here: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts"
|
|
665
|
-
);
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
async function assertKeyExporterIsAvailable() {
|
|
669
|
-
assertIsSecureContext();
|
|
670
|
-
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.exportKey !== "function") {
|
|
671
|
-
throw new Error("No key export implementation could be found");
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
async function assertSigningCapabilityIsAvailable() {
|
|
675
|
-
assertIsSecureContext();
|
|
676
|
-
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.sign !== "function") {
|
|
677
|
-
throw new Error("No signing implementation could be found");
|
|
678
|
-
}
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
// ../addresses/dist/index.browser.js
|
|
682
|
-
var memoizedBase58Encoder;
|
|
683
|
-
var memoizedBase58Decoder;
|
|
684
|
-
function getMemoizedBase58Encoder() {
|
|
685
|
-
if (!memoizedBase58Encoder)
|
|
686
|
-
memoizedBase58Encoder = getBase58Encoder();
|
|
687
|
-
return memoizedBase58Encoder;
|
|
688
|
-
}
|
|
689
|
-
function getMemoizedBase58Decoder() {
|
|
690
|
-
if (!memoizedBase58Decoder)
|
|
691
|
-
memoizedBase58Decoder = getBase58Decoder();
|
|
692
|
-
return memoizedBase58Decoder;
|
|
693
|
-
}
|
|
694
|
-
function assertIsAddress(putativeBase58EncodedAddress) {
|
|
695
|
-
try {
|
|
696
|
-
if (
|
|
697
|
-
// Lowest address (32 bytes of zeroes)
|
|
698
|
-
putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
|
|
699
|
-
putativeBase58EncodedAddress.length > 44
|
|
700
|
-
) {
|
|
701
|
-
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
702
|
-
}
|
|
703
|
-
const base58Encoder = getMemoizedBase58Encoder();
|
|
704
|
-
const bytes = base58Encoder.encode(putativeBase58EncodedAddress);
|
|
705
|
-
const numBytes = bytes.byteLength;
|
|
706
|
-
if (numBytes !== 32) {
|
|
707
|
-
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
708
|
-
}
|
|
709
|
-
} catch (e2) {
|
|
710
|
-
throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, {
|
|
711
|
-
cause: e2
|
|
712
|
-
});
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
function address(putativeBase58EncodedAddress) {
|
|
716
|
-
assertIsAddress(putativeBase58EncodedAddress);
|
|
717
|
-
return putativeBase58EncodedAddress;
|
|
718
|
-
}
|
|
719
|
-
function getAddressEncoder(config) {
|
|
720
|
-
return mapEncoder(
|
|
721
|
-
getStringEncoder({
|
|
722
|
-
description: config?.description ?? "Base58EncodedAddress",
|
|
723
|
-
encoding: getMemoizedBase58Encoder(),
|
|
724
|
-
size: 32
|
|
725
|
-
}),
|
|
726
|
-
(putativeAddress) => address(putativeAddress)
|
|
727
|
-
);
|
|
728
|
-
}
|
|
729
|
-
function getAddressDecoder(config) {
|
|
730
|
-
return getStringDecoder({
|
|
731
|
-
description: config?.description ?? "Base58EncodedAddress",
|
|
732
|
-
encoding: getMemoizedBase58Decoder(),
|
|
733
|
-
size: 32
|
|
734
|
-
});
|
|
735
|
-
}
|
|
736
|
-
function getAddressComparator() {
|
|
737
|
-
return new Intl.Collator("en", {
|
|
738
|
-
caseFirst: "lower",
|
|
739
|
-
ignorePunctuation: false,
|
|
740
|
-
localeMatcher: "best fit",
|
|
741
|
-
numeric: false,
|
|
742
|
-
sensitivity: "variant",
|
|
743
|
-
usage: "sort"
|
|
744
|
-
}).compare;
|
|
745
|
-
}
|
|
746
|
-
async function getAddressFromPublicKey(publicKey) {
|
|
747
|
-
await assertKeyExporterIsAvailable();
|
|
748
|
-
if (publicKey.type !== "public" || publicKey.algorithm.name !== "Ed25519") {
|
|
749
|
-
throw new Error("The `CryptoKey` must be an `Ed25519` public key");
|
|
750
|
-
}
|
|
751
|
-
const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
|
|
752
|
-
const [base58EncodedAddress] = getAddressDecoder().decode(new Uint8Array(publicKeyBytes));
|
|
753
|
-
return base58EncodedAddress;
|
|
754
|
-
}
|
|
755
|
-
|
|
756
|
-
// src/accounts.ts
|
|
757
|
-
function upsert(addressMap, address2, update) {
|
|
758
|
-
addressMap[address2] = update(addressMap[address2] ?? { role: AccountRole.READONLY });
|
|
759
|
-
}
|
|
760
|
-
var TYPE = Symbol("AddressMapTypeProperty");
|
|
761
|
-
function getAddressMapFromInstructions(feePayer, instructions) {
|
|
762
|
-
const addressMap = {
|
|
763
|
-
[feePayer]: { [TYPE]: 0 /* FEE_PAYER */, role: AccountRole.WRITABLE_SIGNER }
|
|
764
|
-
};
|
|
765
|
-
const addressesOfInvokedPrograms = /* @__PURE__ */ new Set();
|
|
766
|
-
for (const instruction of instructions) {
|
|
767
|
-
upsert(addressMap, instruction.programAddress, (entry) => {
|
|
768
|
-
addressesOfInvokedPrograms.add(instruction.programAddress);
|
|
769
|
-
if (TYPE in entry) {
|
|
770
|
-
if (isWritableRole(entry.role)) {
|
|
771
|
-
switch (entry[TYPE]) {
|
|
772
|
-
case 0 /* FEE_PAYER */:
|
|
773
|
-
throw new Error(
|
|
774
|
-
`This transaction includes an address (\`${instruction.programAddress}\`) which is both invoked and set as the fee payer. Program addresses may not pay fees.`
|
|
775
|
-
);
|
|
776
|
-
default:
|
|
777
|
-
throw new Error(
|
|
778
|
-
`This transaction includes an address (\`${instruction.programAddress}\`) which is both invoked and marked writable. Program addresses may not be writable.`
|
|
779
|
-
);
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
if (entry[TYPE] === 2 /* STATIC */) {
|
|
783
|
-
return entry;
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
return { [TYPE]: 2 /* STATIC */, role: AccountRole.READONLY };
|
|
787
|
-
});
|
|
788
|
-
let addressComparator;
|
|
789
|
-
if (!instruction.accounts) {
|
|
790
|
-
continue;
|
|
791
|
-
}
|
|
792
|
-
for (const account of instruction.accounts) {
|
|
793
|
-
upsert(addressMap, account.address, (entry) => {
|
|
794
|
-
const {
|
|
795
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
796
|
-
address: _,
|
|
797
|
-
...accountMeta
|
|
798
|
-
} = account;
|
|
799
|
-
if (TYPE in entry) {
|
|
800
|
-
switch (entry[TYPE]) {
|
|
801
|
-
case 0 /* FEE_PAYER */:
|
|
802
|
-
return entry;
|
|
803
|
-
case 1 /* LOOKUP_TABLE */: {
|
|
804
|
-
const nextRole = mergeRoles(entry.role, accountMeta.role);
|
|
805
|
-
if ("lookupTableAddress" in accountMeta) {
|
|
806
|
-
const shouldReplaceEntry = (
|
|
807
|
-
// Consider using the new LOOKUP_TABLE if its address is different...
|
|
808
|
-
entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
|
|
809
|
-
(addressComparator || (addressComparator = getAddressComparator()))(
|
|
810
|
-
accountMeta.lookupTableAddress,
|
|
811
|
-
entry.lookupTableAddress
|
|
812
|
-
) < 0
|
|
813
|
-
);
|
|
814
|
-
if (shouldReplaceEntry) {
|
|
815
|
-
return {
|
|
816
|
-
[TYPE]: 1 /* LOOKUP_TABLE */,
|
|
817
|
-
...accountMeta,
|
|
818
|
-
role: nextRole
|
|
819
|
-
};
|
|
820
|
-
}
|
|
821
|
-
} else if (isSignerRole(accountMeta.role)) {
|
|
822
|
-
return {
|
|
823
|
-
[TYPE]: 2 /* STATIC */,
|
|
824
|
-
role: nextRole
|
|
825
|
-
};
|
|
826
|
-
}
|
|
827
|
-
if (entry.role !== nextRole) {
|
|
828
|
-
return {
|
|
829
|
-
...entry,
|
|
830
|
-
role: nextRole
|
|
831
|
-
};
|
|
832
|
-
} else {
|
|
833
|
-
return entry;
|
|
834
|
-
}
|
|
835
|
-
}
|
|
836
|
-
case 2 /* STATIC */: {
|
|
837
|
-
const nextRole = mergeRoles(entry.role, accountMeta.role);
|
|
838
|
-
if (
|
|
839
|
-
// Check to see if this address represents a program that is invoked
|
|
840
|
-
// in this transaction.
|
|
841
|
-
addressesOfInvokedPrograms.has(account.address)
|
|
842
|
-
) {
|
|
843
|
-
if (isWritableRole(accountMeta.role)) {
|
|
844
|
-
throw new Error(
|
|
845
|
-
`This transaction includes an address (\`${account.address}\`) which is both invoked and marked writable. Program addresses may not be writable.`
|
|
846
|
-
);
|
|
847
|
-
}
|
|
848
|
-
if (entry.role !== nextRole) {
|
|
849
|
-
return {
|
|
850
|
-
...entry,
|
|
851
|
-
role: nextRole
|
|
852
|
-
};
|
|
853
|
-
} else {
|
|
854
|
-
return entry;
|
|
855
|
-
}
|
|
856
|
-
} else if ("lookupTableAddress" in accountMeta && // Static accounts can be 'upgraded' to lookup table accounts as
|
|
857
|
-
// long as they are not require to sign the transaction.
|
|
858
|
-
!isSignerRole(entry.role)) {
|
|
859
|
-
return {
|
|
860
|
-
...accountMeta,
|
|
861
|
-
[TYPE]: 1 /* LOOKUP_TABLE */,
|
|
862
|
-
role: nextRole
|
|
863
|
-
};
|
|
864
|
-
} else {
|
|
865
|
-
if (entry.role !== nextRole) {
|
|
866
|
-
return {
|
|
867
|
-
...entry,
|
|
868
|
-
role: nextRole
|
|
869
|
-
};
|
|
870
|
-
} else {
|
|
871
|
-
return entry;
|
|
872
|
-
}
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
|
-
}
|
|
877
|
-
if ("lookupTableAddress" in accountMeta) {
|
|
878
|
-
return {
|
|
879
|
-
...accountMeta,
|
|
880
|
-
[TYPE]: 1 /* LOOKUP_TABLE */
|
|
881
|
-
};
|
|
882
|
-
} else {
|
|
883
|
-
return {
|
|
884
|
-
...accountMeta,
|
|
885
|
-
[TYPE]: 2 /* STATIC */
|
|
886
|
-
};
|
|
887
|
-
}
|
|
888
|
-
});
|
|
889
|
-
}
|
|
890
|
-
}
|
|
891
|
-
return addressMap;
|
|
892
|
-
}
|
|
893
|
-
function getOrderedAccountsFromAddressMap(addressMap) {
|
|
894
|
-
let addressComparator;
|
|
895
|
-
const orderedAccounts = Object.entries(addressMap).sort(([leftAddress, leftEntry], [rightAddress, rightEntry]) => {
|
|
896
|
-
if (leftEntry[TYPE] !== rightEntry[TYPE]) {
|
|
897
|
-
if (leftEntry[TYPE] === 0 /* FEE_PAYER */) {
|
|
898
|
-
return -1;
|
|
899
|
-
} else if (rightEntry[TYPE] === 0 /* FEE_PAYER */) {
|
|
900
|
-
return 1;
|
|
901
|
-
} else if (leftEntry[TYPE] === 2 /* STATIC */) {
|
|
902
|
-
return -1;
|
|
903
|
-
} else if (rightEntry[TYPE] === 2 /* STATIC */) {
|
|
904
|
-
return 1;
|
|
905
|
-
}
|
|
906
|
-
}
|
|
907
|
-
const leftIsSigner = isSignerRole(leftEntry.role);
|
|
908
|
-
if (leftIsSigner !== isSignerRole(rightEntry.role)) {
|
|
909
|
-
return leftIsSigner ? -1 : 1;
|
|
910
|
-
}
|
|
911
|
-
const leftIsWritable = isWritableRole(leftEntry.role);
|
|
912
|
-
if (leftIsWritable !== isWritableRole(rightEntry.role)) {
|
|
913
|
-
return leftIsWritable ? -1 : 1;
|
|
914
|
-
}
|
|
915
|
-
addressComparator || (addressComparator = getAddressComparator());
|
|
916
|
-
if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
|
|
917
|
-
return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
|
|
918
|
-
} else {
|
|
919
|
-
return addressComparator(leftAddress, rightAddress);
|
|
920
|
-
}
|
|
921
|
-
}).map(([address2, addressMeta]) => ({
|
|
922
|
-
address: address2,
|
|
923
|
-
...addressMeta
|
|
924
|
-
}));
|
|
925
|
-
return orderedAccounts;
|
|
926
|
-
}
|
|
927
|
-
|
|
928
|
-
// src/compile-address-table-lookups.ts
|
|
929
|
-
function getCompiledAddressTableLookups(orderedAccounts) {
|
|
930
|
-
var _a;
|
|
931
|
-
const index = {};
|
|
932
|
-
for (const account of orderedAccounts) {
|
|
933
|
-
if (!("lookupTableAddress" in account)) {
|
|
934
|
-
continue;
|
|
935
|
-
}
|
|
936
|
-
const entry = index[_a = account.lookupTableAddress] || (index[_a] = {
|
|
937
|
-
readableIndices: [],
|
|
938
|
-
writableIndices: []
|
|
939
|
-
});
|
|
940
|
-
if (account.role === AccountRole.WRITABLE) {
|
|
941
|
-
entry.writableIndices.push(account.addressIndex);
|
|
942
|
-
} else {
|
|
943
|
-
entry.readableIndices.push(account.addressIndex);
|
|
944
|
-
}
|
|
945
|
-
}
|
|
946
|
-
return Object.keys(index).sort(getAddressComparator()).map((lookupTableAddress) => ({
|
|
947
|
-
lookupTableAddress,
|
|
948
|
-
...index[lookupTableAddress]
|
|
949
|
-
}));
|
|
950
|
-
}
|
|
951
|
-
|
|
952
|
-
// src/compile-header.ts
|
|
953
|
-
function getCompiledMessageHeader(orderedAccounts) {
|
|
954
|
-
let numReadonlyNonSignerAccounts = 0;
|
|
955
|
-
let numReadonlySignerAccounts = 0;
|
|
956
|
-
let numSignerAccounts = 0;
|
|
957
|
-
for (const account of orderedAccounts) {
|
|
958
|
-
if ("lookupTableAddress" in account) {
|
|
959
|
-
break;
|
|
960
|
-
}
|
|
961
|
-
const accountIsWritable = isWritableRole(account.role);
|
|
962
|
-
if (isSignerRole(account.role)) {
|
|
963
|
-
numSignerAccounts++;
|
|
964
|
-
if (!accountIsWritable) {
|
|
965
|
-
numReadonlySignerAccounts++;
|
|
966
|
-
}
|
|
967
|
-
} else if (!accountIsWritable) {
|
|
968
|
-
numReadonlyNonSignerAccounts++;
|
|
969
|
-
}
|
|
970
|
-
}
|
|
971
|
-
return {
|
|
972
|
-
numReadonlyNonSignerAccounts,
|
|
973
|
-
numReadonlySignerAccounts,
|
|
974
|
-
numSignerAccounts
|
|
975
|
-
};
|
|
976
|
-
}
|
|
977
|
-
|
|
978
|
-
// src/compile-instructions.ts
|
|
979
|
-
function getAccountIndex(orderedAccounts) {
|
|
980
|
-
const out = {};
|
|
981
|
-
for (const [index, account] of orderedAccounts.entries()) {
|
|
982
|
-
out[account.address] = index;
|
|
983
|
-
}
|
|
984
|
-
return out;
|
|
985
|
-
}
|
|
986
|
-
function getCompiledInstructions(instructions, orderedAccounts) {
|
|
987
|
-
const accountIndex = getAccountIndex(orderedAccounts);
|
|
988
|
-
return instructions.map(({ accounts, data, programAddress }) => {
|
|
989
|
-
return {
|
|
990
|
-
programAddressIndex: accountIndex[programAddress],
|
|
991
|
-
...accounts ? { accountIndices: accounts.map(({ address: address2 }) => accountIndex[address2]) } : null,
|
|
992
|
-
...data ? { data } : null
|
|
993
|
-
};
|
|
994
|
-
});
|
|
995
|
-
}
|
|
996
|
-
|
|
997
|
-
// src/compile-lifetime-token.ts
|
|
998
|
-
function getCompiledLifetimeToken(lifetimeConstraint) {
|
|
999
|
-
if ("nonce" in lifetimeConstraint) {
|
|
1000
|
-
return lifetimeConstraint.nonce;
|
|
1001
|
-
}
|
|
1002
|
-
return lifetimeConstraint.blockhash;
|
|
1003
|
-
}
|
|
1004
|
-
|
|
1005
|
-
// src/compile-static-accounts.ts
|
|
1006
|
-
function getCompiledStaticAccounts(orderedAccounts) {
|
|
1007
|
-
const firstLookupTableAccountIndex = orderedAccounts.findIndex((account) => "lookupTableAddress" in account);
|
|
1008
|
-
const orderedStaticAccounts = firstLookupTableAccountIndex === -1 ? orderedAccounts : orderedAccounts.slice(0, firstLookupTableAccountIndex);
|
|
1009
|
-
return orderedStaticAccounts.map(({ address: address2 }) => address2);
|
|
1010
|
-
}
|
|
1011
|
-
|
|
1012
|
-
// src/message.ts
|
|
1013
|
-
function compileMessage(transaction) {
|
|
1014
|
-
const addressMap = getAddressMapFromInstructions(transaction.feePayer, transaction.instructions);
|
|
1015
|
-
const orderedAccounts = getOrderedAccountsFromAddressMap(addressMap);
|
|
1016
|
-
return {
|
|
1017
|
-
...transaction.version !== "legacy" ? { addressTableLookups: getCompiledAddressTableLookups(orderedAccounts) } : null,
|
|
1018
|
-
header: getCompiledMessageHeader(orderedAccounts),
|
|
1019
|
-
instructions: getCompiledInstructions(transaction.instructions, orderedAccounts),
|
|
1020
|
-
lifetimeToken: getCompiledLifetimeToken(transaction.lifetimeConstraint),
|
|
1021
|
-
staticAccounts: getCompiledStaticAccounts(orderedAccounts),
|
|
1022
|
-
version: transaction.version
|
|
1023
|
-
};
|
|
1024
|
-
}
|
|
1025
|
-
|
|
1026
|
-
// src/compile-transaction.ts
|
|
1027
|
-
function getCompiledTransaction(transaction) {
|
|
1028
|
-
const compiledMessage = compileMessage(transaction);
|
|
1029
|
-
let signatures;
|
|
1030
|
-
if ("signatures" in transaction) {
|
|
1031
|
-
signatures = [];
|
|
1032
|
-
for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
|
|
1033
|
-
signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
|
|
1034
|
-
}
|
|
1035
|
-
} else {
|
|
1036
|
-
signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
|
|
1037
|
-
}
|
|
1038
|
-
return {
|
|
1039
|
-
compiledMessage,
|
|
1040
|
-
signatures
|
|
1041
|
-
};
|
|
1042
|
-
}
|
|
1043
|
-
|
|
1044
|
-
// src/serializers/address-table-lookup.ts
|
|
1045
|
-
var lookupTableAddressDescription = "The address of the address lookup table account from which instruction addresses should be looked up" ;
|
|
1046
|
-
var writableIndicesDescription = "The indices of the accounts in the lookup table that should be loaded as writeable" ;
|
|
1047
|
-
var readableIndicesDescription = "The indices of the accounts in the lookup table that should be loaded as read-only" ;
|
|
1048
|
-
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" ;
|
|
1049
|
-
var memoizedAddressTableLookupEncoder;
|
|
1050
|
-
function getAddressTableLookupEncoder() {
|
|
1051
|
-
if (!memoizedAddressTableLookupEncoder) {
|
|
1052
|
-
memoizedAddressTableLookupEncoder = getStructEncoder(
|
|
1053
|
-
[
|
|
1054
|
-
["lookupTableAddress", getAddressEncoder({ description: lookupTableAddressDescription })],
|
|
1055
|
-
[
|
|
1056
|
-
"writableIndices",
|
|
1057
|
-
getArrayEncoder(getU8Encoder(), {
|
|
1058
|
-
description: writableIndicesDescription,
|
|
1059
|
-
size: getShortU16Encoder()
|
|
1060
|
-
})
|
|
1061
|
-
],
|
|
1062
|
-
[
|
|
1063
|
-
"readableIndices",
|
|
1064
|
-
getArrayEncoder(getU8Encoder(), {
|
|
1065
|
-
description: readableIndicesDescription,
|
|
1066
|
-
size: getShortU16Encoder()
|
|
1067
|
-
})
|
|
1068
|
-
]
|
|
1069
|
-
],
|
|
1070
|
-
{ description: addressTableLookupDescription }
|
|
1071
|
-
);
|
|
1072
|
-
}
|
|
1073
|
-
return memoizedAddressTableLookupEncoder;
|
|
1074
|
-
}
|
|
1075
|
-
|
|
1076
|
-
// src/serializers/header.ts
|
|
1077
|
-
var memoizedU8Encoder;
|
|
1078
|
-
function getMemoizedU8Encoder() {
|
|
1079
|
-
if (!memoizedU8Encoder)
|
|
1080
|
-
memoizedU8Encoder = getU8Encoder();
|
|
1081
|
-
return memoizedU8Encoder;
|
|
1082
|
-
}
|
|
1083
|
-
function getMemoizedU8EncoderDescription(description) {
|
|
1084
|
-
const encoder = getMemoizedU8Encoder();
|
|
1085
|
-
return {
|
|
1086
|
-
...encoder,
|
|
1087
|
-
description: description ?? encoder.description
|
|
1088
|
-
};
|
|
1089
|
-
}
|
|
1090
|
-
var numSignerAccountsDescription = "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction" ;
|
|
1091
|
-
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" ;
|
|
1092
|
-
var numReadonlyNonSignerAccountsDescription = "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable" ;
|
|
1093
|
-
var messageHeaderDescription = "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses" ;
|
|
1094
|
-
function getMessageHeaderEncoder() {
|
|
1095
|
-
return getStructEncoder(
|
|
1096
|
-
[
|
|
1097
|
-
["numSignerAccounts", getMemoizedU8EncoderDescription(numSignerAccountsDescription)],
|
|
1098
|
-
["numReadonlySignerAccounts", getMemoizedU8EncoderDescription(numReadonlySignerAccountsDescription)],
|
|
1099
|
-
["numReadonlyNonSignerAccounts", getMemoizedU8EncoderDescription(numReadonlyNonSignerAccountsDescription)]
|
|
1100
|
-
],
|
|
1101
|
-
{
|
|
1102
|
-
description: messageHeaderDescription
|
|
1103
|
-
}
|
|
1104
|
-
);
|
|
1105
|
-
}
|
|
1106
|
-
|
|
1107
|
-
// src/serializers/instruction.ts
|
|
1108
|
-
var programAddressIndexDescription = "The index of the program being called, according to the well-ordered accounts list for this transaction" ;
|
|
1109
|
-
var accountIndexDescription = "The index of an account, according to the well-ordered accounts list for this transaction" ;
|
|
1110
|
-
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" ;
|
|
1111
|
-
var dataDescription = "An optional buffer of data passed to the instruction" ;
|
|
1112
|
-
var memoizedGetInstructionEncoder;
|
|
1113
|
-
function getInstructionEncoder() {
|
|
1114
|
-
if (!memoizedGetInstructionEncoder) {
|
|
1115
|
-
memoizedGetInstructionEncoder = mapEncoder(
|
|
1116
|
-
getStructEncoder([
|
|
1117
|
-
["programAddressIndex", getU8Encoder({ description: programAddressIndexDescription })],
|
|
1118
|
-
[
|
|
1119
|
-
"accountIndices",
|
|
1120
|
-
getArrayEncoder(getU8Encoder({ description: accountIndexDescription }), {
|
|
1121
|
-
description: accountIndicesDescription,
|
|
1122
|
-
size: getShortU16Encoder()
|
|
1123
|
-
})
|
|
1124
|
-
],
|
|
1125
|
-
["data", getBytesEncoder({ description: dataDescription, size: getShortU16Encoder() })]
|
|
1126
|
-
]),
|
|
1127
|
-
// Convert an instruction to have all fields defined
|
|
1128
|
-
(instruction) => {
|
|
1129
|
-
if (instruction.accountIndices !== void 0 && instruction.data !== void 0) {
|
|
1130
|
-
return instruction;
|
|
1131
|
-
}
|
|
1132
|
-
return {
|
|
1133
|
-
...instruction,
|
|
1134
|
-
accountIndices: instruction.accountIndices ?? [],
|
|
1135
|
-
data: instruction.data ?? new Uint8Array(0)
|
|
1136
|
-
};
|
|
1137
|
-
}
|
|
1138
|
-
);
|
|
1139
|
-
}
|
|
1140
|
-
return memoizedGetInstructionEncoder;
|
|
1141
|
-
}
|
|
1142
|
-
|
|
1143
|
-
// src/serializers/transaction-version.ts
|
|
1144
|
-
var VERSION_FLAG_MASK = 128;
|
|
1145
|
-
var BASE_CONFIG = {
|
|
1146
|
-
description: "A single byte that encodes the version of the transaction" ,
|
|
1147
|
-
fixedSize: null,
|
|
1148
|
-
maxSize: 1
|
|
1149
|
-
};
|
|
1150
|
-
function encode(value) {
|
|
1151
|
-
if (value === "legacy") {
|
|
1152
|
-
return new Uint8Array();
|
|
1153
|
-
}
|
|
1154
|
-
if (value < 0 || value > 127) {
|
|
1155
|
-
throw new Error(`Transaction version must be in the range [0, 127]. \`${value}\` given.`);
|
|
1156
|
-
}
|
|
1157
|
-
return new Uint8Array([value | VERSION_FLAG_MASK]);
|
|
1158
|
-
}
|
|
1159
|
-
function getTransactionVersionEncoder() {
|
|
1160
|
-
return {
|
|
1161
|
-
...BASE_CONFIG,
|
|
1162
|
-
encode
|
|
1163
|
-
};
|
|
1164
|
-
}
|
|
1165
|
-
|
|
1166
|
-
// src/serializers/message.ts
|
|
1167
|
-
var staticAccountsDescription = "A compact-array of static account addresses belonging to this transaction" ;
|
|
1168
|
-
var lifetimeTokenDescription = "A 32-byte token that specifies the lifetime of this transaction (eg. a recent blockhash, or a durable nonce)" ;
|
|
1169
|
-
var instructionsDescription = "A compact-array of instructions belonging to this transaction" ;
|
|
1170
|
-
var addressTableLookupsDescription = "A compact array of address table lookups belonging to this transaction" ;
|
|
1171
|
-
function getCompiledMessageLegacyEncoder() {
|
|
1172
|
-
return getStructEncoder(getPreludeStructEncoderTuple());
|
|
1173
|
-
}
|
|
1174
|
-
function getCompiledMessageVersionedEncoder() {
|
|
1175
|
-
return mapEncoder(
|
|
1176
|
-
getStructEncoder([
|
|
1177
|
-
...getPreludeStructEncoderTuple(),
|
|
1178
|
-
["addressTableLookups", getAddressTableLookupArrayEncoder()]
|
|
1179
|
-
]),
|
|
1180
|
-
(value) => {
|
|
1181
|
-
if (value.version === "legacy") {
|
|
1182
|
-
return value;
|
|
1183
|
-
}
|
|
1184
|
-
return {
|
|
1185
|
-
...value,
|
|
1186
|
-
addressTableLookups: value.addressTableLookups ?? []
|
|
1187
|
-
};
|
|
1188
|
-
}
|
|
1189
|
-
);
|
|
1190
|
-
}
|
|
1191
|
-
function getPreludeStructEncoderTuple() {
|
|
1192
|
-
return [
|
|
1193
|
-
["version", getTransactionVersionEncoder()],
|
|
1194
|
-
["header", getMessageHeaderEncoder()],
|
|
1195
|
-
[
|
|
1196
|
-
"staticAccounts",
|
|
1197
|
-
getArrayEncoder(getAddressEncoder(), {
|
|
1198
|
-
description: staticAccountsDescription,
|
|
1199
|
-
size: getShortU16Encoder()
|
|
1200
|
-
})
|
|
1201
|
-
],
|
|
1202
|
-
[
|
|
1203
|
-
"lifetimeToken",
|
|
1204
|
-
getStringEncoder({
|
|
1205
|
-
description: lifetimeTokenDescription,
|
|
1206
|
-
encoding: getBase58Encoder(),
|
|
1207
|
-
size: 32
|
|
1208
|
-
})
|
|
1209
|
-
],
|
|
1210
|
-
[
|
|
1211
|
-
"instructions",
|
|
1212
|
-
getArrayEncoder(getInstructionEncoder(), {
|
|
1213
|
-
description: instructionsDescription,
|
|
1214
|
-
size: getShortU16Encoder()
|
|
1215
|
-
})
|
|
1216
|
-
]
|
|
1217
|
-
];
|
|
1218
|
-
}
|
|
1219
|
-
function getAddressTableLookupArrayEncoder() {
|
|
1220
|
-
return getArrayEncoder(getAddressTableLookupEncoder(), {
|
|
1221
|
-
description: addressTableLookupsDescription,
|
|
1222
|
-
size: getShortU16Encoder()
|
|
1223
|
-
});
|
|
1224
|
-
}
|
|
1225
|
-
var messageDescription = "The wire format of a Solana transaction message" ;
|
|
1226
|
-
function getCompiledMessageEncoder() {
|
|
1227
|
-
return {
|
|
1228
|
-
description: messageDescription,
|
|
1229
|
-
encode: (compiledMessage) => {
|
|
1230
|
-
if (compiledMessage.version === "legacy") {
|
|
1231
|
-
return getCompiledMessageLegacyEncoder().encode(compiledMessage);
|
|
1232
|
-
} else {
|
|
1233
|
-
return getCompiledMessageVersionedEncoder().encode(compiledMessage);
|
|
1234
|
-
}
|
|
1235
|
-
},
|
|
1236
|
-
fixedSize: null,
|
|
1237
|
-
maxSize: null
|
|
1238
|
-
};
|
|
1239
|
-
}
|
|
1240
|
-
|
|
1241
|
-
// src/serializers/transaction.ts
|
|
1242
|
-
var transactionDescription = "The wire format of a Solana transaction" ;
|
|
1243
|
-
var signaturesDescription = "A compact array of 64-byte, base-64 encoded Ed25519 signatures" ;
|
|
1244
|
-
function getCompiledTransactionEncoder() {
|
|
1245
|
-
return getStructEncoder(
|
|
1246
|
-
[
|
|
1247
|
-
[
|
|
1248
|
-
"signatures",
|
|
1249
|
-
getArrayEncoder(getBytesEncoder({ size: 64 }), {
|
|
1250
|
-
description: signaturesDescription,
|
|
1251
|
-
size: getShortU16Encoder()
|
|
1252
|
-
})
|
|
1253
|
-
],
|
|
1254
|
-
["compiledMessage", getCompiledMessageEncoder()]
|
|
1255
|
-
],
|
|
1256
|
-
{
|
|
1257
|
-
description: transactionDescription
|
|
1258
|
-
}
|
|
1259
|
-
);
|
|
1260
|
-
}
|
|
1261
|
-
function getTransactionEncoder() {
|
|
1262
|
-
return mapEncoder(getCompiledTransactionEncoder(), getCompiledTransaction);
|
|
1263
|
-
}
|
|
1264
|
-
|
|
1265
|
-
// ../keys/dist/index.browser.js
|
|
1266
|
-
async function signBytes(key, data) {
|
|
1267
|
-
await assertSigningCapabilityIsAvailable();
|
|
1268
|
-
const signedData = await crypto.subtle.sign("Ed25519", key, data);
|
|
1269
|
-
return new Uint8Array(signedData);
|
|
1270
|
-
}
|
|
1271
|
-
|
|
1272
|
-
// src/signatures.ts
|
|
1273
|
-
function assertIsTransactionSignature(putativeTransactionSignature) {
|
|
1274
|
-
try {
|
|
1275
|
-
if (
|
|
1276
|
-
// Lowest value (64 bytes of zeroes)
|
|
1277
|
-
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
1278
|
-
putativeTransactionSignature.length > 88
|
|
1279
|
-
) {
|
|
1280
|
-
throw new Error("Expected input string to decode to a byte array of length 64.");
|
|
1281
|
-
}
|
|
1282
|
-
const bytes = base58.serialize(putativeTransactionSignature);
|
|
1283
|
-
const numBytes = bytes.byteLength;
|
|
1284
|
-
if (numBytes !== 64) {
|
|
1285
|
-
throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
|
|
1286
|
-
}
|
|
1287
|
-
} catch (e2) {
|
|
1288
|
-
throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, {
|
|
1289
|
-
cause: e2
|
|
1290
|
-
});
|
|
1291
|
-
}
|
|
1292
|
-
}
|
|
1293
|
-
function isTransactionSignature(putativeTransactionSignature) {
|
|
1294
|
-
if (
|
|
1295
|
-
// Lowest value (64 bytes of zeroes)
|
|
1296
|
-
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
1297
|
-
putativeTransactionSignature.length > 88
|
|
1298
|
-
) {
|
|
1299
|
-
return false;
|
|
1300
|
-
}
|
|
1301
|
-
const bytes = base58.serialize(putativeTransactionSignature);
|
|
1302
|
-
const numBytes = bytes.byteLength;
|
|
1303
|
-
if (numBytes !== 64) {
|
|
1304
|
-
return false;
|
|
1305
|
-
}
|
|
1306
|
-
return true;
|
|
1307
|
-
}
|
|
1308
|
-
async function getCompiledMessageSignature(message, secretKey) {
|
|
1309
|
-
const wireMessageBytes = getCompiledMessageEncoder().encode(message);
|
|
1310
|
-
const signature = await signBytes(secretKey, wireMessageBytes);
|
|
1311
|
-
return signature;
|
|
1312
|
-
}
|
|
1313
|
-
function getSignatureFromTransaction(transaction) {
|
|
1314
|
-
const signatureBytes = transaction.signatures[transaction.feePayer];
|
|
1315
|
-
if (!signatureBytes) {
|
|
1316
|
-
throw new Error(
|
|
1317
|
-
"Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
|
|
1318
|
-
);
|
|
1319
|
-
}
|
|
1320
|
-
const transactionSignature2 = base58.deserialize(signatureBytes)[0];
|
|
1321
|
-
return transactionSignature2;
|
|
1322
|
-
}
|
|
1323
|
-
async function signTransaction(keyPairs, transaction) {
|
|
1324
|
-
const compiledMessage = compileMessage(transaction);
|
|
1325
|
-
const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
|
|
1326
|
-
const publicKeySignaturePairs = await Promise.all(
|
|
1327
|
-
keyPairs.map(
|
|
1328
|
-
(keyPair) => Promise.all([
|
|
1329
|
-
getAddressFromPublicKey(keyPair.publicKey),
|
|
1330
|
-
getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
|
|
1331
|
-
])
|
|
1332
|
-
)
|
|
1333
|
-
);
|
|
1334
|
-
for (const [signerPublicKey, signature] of publicKeySignaturePairs) {
|
|
1335
|
-
nextSignatures[signerPublicKey] = signature;
|
|
1336
|
-
}
|
|
1337
|
-
const out = {
|
|
1338
|
-
...transaction,
|
|
1339
|
-
signatures: nextSignatures
|
|
1340
|
-
};
|
|
1341
|
-
Object.freeze(out);
|
|
1342
|
-
return out;
|
|
1343
|
-
}
|
|
1344
|
-
function transactionSignature(putativeTransactionSignature) {
|
|
1345
|
-
assertIsTransactionSignature(putativeTransactionSignature);
|
|
1346
|
-
return putativeTransactionSignature;
|
|
1347
|
-
}
|
|
1348
|
-
|
|
1349
|
-
// src/wire-transaction.ts
|
|
1350
|
-
function getBase64EncodedWireTransaction(transaction) {
|
|
1351
|
-
const wireTransactionBytes = getTransactionEncoder().encode(transaction);
|
|
1352
|
-
{
|
|
1353
|
-
return btoa(String.fromCharCode(...wireTransactionBytes));
|
|
1354
|
-
}
|
|
1355
|
-
}
|
|
1356
|
-
|
|
1357
|
-
exports.appendTransactionInstruction = appendTransactionInstruction;
|
|
1358
|
-
exports.assertIsBlockhash = assertIsBlockhash;
|
|
1359
|
-
exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
|
|
1360
|
-
exports.assertIsTransactionSignature = assertIsTransactionSignature;
|
|
1361
|
-
exports.createTransaction = createTransaction;
|
|
1362
|
-
exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
|
|
1363
|
-
exports.getSignatureFromTransaction = getSignatureFromTransaction;
|
|
1364
|
-
exports.getTransactionEncoder = getTransactionEncoder;
|
|
1365
|
-
exports.isAdvanceNonceAccountInstruction = isAdvanceNonceAccountInstruction;
|
|
1366
|
-
exports.isTransactionSignature = isTransactionSignature;
|
|
1367
|
-
exports.prependTransactionInstruction = prependTransactionInstruction;
|
|
1368
|
-
exports.setTransactionFeePayer = setTransactionFeePayer;
|
|
1369
|
-
exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
|
|
1370
|
-
exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
|
|
1371
|
-
exports.signTransaction = signTransaction;
|
|
1372
|
-
exports.transactionSignature = transactionSignature;
|
|
1373
|
-
|
|
1374
|
-
return exports;
|
|
1375
|
-
|
|
1376
|
-
})({});
|
|
1377
|
-
//# sourceMappingURL=out.js.map
|
|
1378
|
-
//# sourceMappingURL=index.development.js.map
|