@solana/transactions 2.0.0-experimental.71b920d → 2.0.0-experimental.72efece
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/dist/index.browser.cjs +343 -128
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +335 -130
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +899 -258
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +335 -130
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +343 -128
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +335 -130
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +16 -6
- 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/compile-transaction.d.ts +11 -0
- package/dist/types/durable-nonce.d.ts +20 -7
- package/dist/types/fee-payer.d.ts +3 -2
- package/dist/types/index.d.ts +2 -0
- package/dist/types/serializers/header.d.ts +4 -2
- package/dist/types/serializers/index.d.ts +2 -0
- package/dist/types/serializers/transaction-version.d.ts +4 -4
- package/dist/types/serializers/transaction.d.ts +6 -0
- package/dist/types/signatures.d.ts +13 -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 +6 -0
- package/package.json +23 -22
|
@@ -9,79 +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
|
|
12
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/bytes.mjs
|
|
85
13
|
var mergeBytes = (bytesArr) => {
|
|
86
14
|
const totalLength = bytesArr.reduce((total, arr) => total + arr.length, 0);
|
|
87
15
|
const result = new Uint8Array(totalLength);
|
|
@@ -101,7 +29,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
101
29
|
};
|
|
102
30
|
var fixBytes = (bytes2, length) => padBytes(bytes2.slice(0, length), length);
|
|
103
31
|
|
|
104
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.
|
|
32
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/errors.mjs
|
|
105
33
|
var DeserializingEmptyBufferError = class extends Error {
|
|
106
34
|
constructor(serializer) {
|
|
107
35
|
super(`Serializer [${serializer}] cannot deserialize empty buffers.`);
|
|
@@ -122,7 +50,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
122
50
|
}
|
|
123
51
|
};
|
|
124
52
|
|
|
125
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.
|
|
53
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/fixSerializer.mjs
|
|
126
54
|
function fixSerializer(serializer, fixedBytes, description) {
|
|
127
55
|
return {
|
|
128
56
|
description: description ?? `fixed(${fixedBytes}, ${serializer.description})`,
|
|
@@ -143,7 +71,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
143
71
|
};
|
|
144
72
|
}
|
|
145
73
|
|
|
146
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.
|
|
74
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/mapSerializer.mjs
|
|
147
75
|
function mapSerializer(serializer, unmap, map) {
|
|
148
76
|
return {
|
|
149
77
|
description: serializer.description,
|
|
@@ -157,7 +85,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
157
85
|
};
|
|
158
86
|
}
|
|
159
87
|
|
|
160
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.
|
|
88
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/errors.mjs
|
|
161
89
|
var InvalidBaseStringError = class extends Error {
|
|
162
90
|
constructor(value, base, cause) {
|
|
163
91
|
const message = `Expected a string of base ${base}, got [${value}].`;
|
|
@@ -167,7 +95,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
167
95
|
}
|
|
168
96
|
};
|
|
169
97
|
|
|
170
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.
|
|
98
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/baseX.mjs
|
|
171
99
|
var baseX = (alphabet) => {
|
|
172
100
|
const base = alphabet.length;
|
|
173
101
|
const baseBigInt = BigInt(base);
|
|
@@ -221,16 +149,16 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
221
149
|
};
|
|
222
150
|
};
|
|
223
151
|
|
|
224
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.
|
|
152
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/base58.mjs
|
|
225
153
|
var base58 = baseX("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
|
|
226
154
|
|
|
227
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.
|
|
155
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/nullCharacters.mjs
|
|
228
156
|
var removeNullCharacters = (value) => (
|
|
229
157
|
// eslint-disable-next-line no-control-regex
|
|
230
158
|
value.replace(/\u0000/g, "")
|
|
231
159
|
);
|
|
232
160
|
|
|
233
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.
|
|
161
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/utf8.mjs
|
|
234
162
|
var utf8 = {
|
|
235
163
|
description: "utf8",
|
|
236
164
|
fixedSize: null,
|
|
@@ -244,14 +172,14 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
244
172
|
}
|
|
245
173
|
};
|
|
246
174
|
|
|
247
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.
|
|
175
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/common.mjs
|
|
248
176
|
var Endian;
|
|
249
177
|
(function(Endian2) {
|
|
250
178
|
Endian2["Little"] = "le";
|
|
251
179
|
Endian2["Big"] = "be";
|
|
252
180
|
})(Endian || (Endian = {}));
|
|
253
181
|
|
|
254
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.
|
|
182
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/errors.mjs
|
|
255
183
|
var NumberOutOfRangeError = class extends RangeError {
|
|
256
184
|
constructor(serializer, min, max, actual) {
|
|
257
185
|
super(`Serializer [${serializer}] expected number to be between ${min} and ${max}, got ${actual}.`);
|
|
@@ -259,7 +187,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
259
187
|
}
|
|
260
188
|
};
|
|
261
189
|
|
|
262
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.
|
|
190
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/utils.mjs
|
|
263
191
|
function numberFactory(input) {
|
|
264
192
|
let littleEndian;
|
|
265
193
|
let defaultDescription = input.name;
|
|
@@ -303,7 +231,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
303
231
|
}
|
|
304
232
|
};
|
|
305
233
|
|
|
306
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.
|
|
234
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/u8.mjs
|
|
307
235
|
var u8 = (options = {}) => numberFactory({
|
|
308
236
|
name: "u8",
|
|
309
237
|
size: 1,
|
|
@@ -313,7 +241,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
313
241
|
options
|
|
314
242
|
});
|
|
315
243
|
|
|
316
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.
|
|
244
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/u32.mjs
|
|
317
245
|
var u32 = (options = {}) => numberFactory({
|
|
318
246
|
name: "u32",
|
|
319
247
|
size: 4,
|
|
@@ -323,7 +251,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
323
251
|
options
|
|
324
252
|
});
|
|
325
253
|
|
|
326
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.
|
|
254
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/shortU16.mjs
|
|
327
255
|
var shortU16 = (options = {}) => ({
|
|
328
256
|
description: options.description ?? "shortU16",
|
|
329
257
|
fixedSize: null,
|
|
@@ -360,7 +288,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
360
288
|
}
|
|
361
289
|
});
|
|
362
290
|
|
|
363
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.
|
|
291
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/errors.mjs
|
|
364
292
|
var InvalidNumberOfItemsError = class extends Error {
|
|
365
293
|
constructor(serializer, expected, actual) {
|
|
366
294
|
super(`Expected [${serializer}] to have ${expected} items, got ${actual}.`);
|
|
@@ -380,12 +308,12 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
380
308
|
}
|
|
381
309
|
};
|
|
382
310
|
|
|
383
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.
|
|
311
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/sumSerializerSizes.mjs
|
|
384
312
|
function sumSerializerSizes(sizes) {
|
|
385
313
|
return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
|
|
386
314
|
}
|
|
387
315
|
|
|
388
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.
|
|
316
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/utils.mjs
|
|
389
317
|
function getResolvedSize(size, childrenSizes, bytes2, offset) {
|
|
390
318
|
if (typeof size === "number") {
|
|
391
319
|
return [size, offset];
|
|
@@ -421,7 +349,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
421
349
|
return typeof size === "object" ? size.serialize(realSize) : new Uint8Array();
|
|
422
350
|
}
|
|
423
351
|
|
|
424
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.
|
|
352
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/array.mjs
|
|
425
353
|
function array(item, options = {}) {
|
|
426
354
|
const size = options.size ?? u32();
|
|
427
355
|
if (size === "remainder" && item.fixedSize === null) {
|
|
@@ -454,7 +382,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
454
382
|
};
|
|
455
383
|
}
|
|
456
384
|
|
|
457
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.
|
|
385
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/bytes.mjs
|
|
458
386
|
function bytes(options = {}) {
|
|
459
387
|
const size = options.size ?? "variable";
|
|
460
388
|
const description = options.description ?? `bytes(${getSizeDescription(size)})`;
|
|
@@ -501,86 +429,574 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
501
429
|
};
|
|
502
430
|
}
|
|
503
431
|
|
|
504
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.
|
|
432
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/string.mjs
|
|
505
433
|
function string(options = {}) {
|
|
506
434
|
const size = options.size ?? u32();
|
|
507
435
|
const encoding = options.encoding ?? utf8;
|
|
508
436
|
const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
|
|
509
437
|
if (size === "variable") {
|
|
510
|
-
return {
|
|
511
|
-
...encoding,
|
|
512
|
-
description
|
|
513
|
-
};
|
|
438
|
+
return {
|
|
439
|
+
...encoding,
|
|
440
|
+
description
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
if (typeof size === "number") {
|
|
444
|
+
return fixSerializer(encoding, size, description);
|
|
445
|
+
}
|
|
446
|
+
return {
|
|
447
|
+
description,
|
|
448
|
+
fixedSize: null,
|
|
449
|
+
maxSize: null,
|
|
450
|
+
serialize: (value) => {
|
|
451
|
+
const contentBytes = encoding.serialize(value);
|
|
452
|
+
const lengthBytes = size.serialize(contentBytes.length);
|
|
453
|
+
return mergeBytes([lengthBytes, contentBytes]);
|
|
454
|
+
},
|
|
455
|
+
deserialize: (buffer, offset = 0) => {
|
|
456
|
+
if (buffer.slice(offset).length === 0) {
|
|
457
|
+
throw new DeserializingEmptyBufferError("string");
|
|
458
|
+
}
|
|
459
|
+
const [lengthBigInt, lengthOffset] = size.deserialize(buffer, offset);
|
|
460
|
+
const length = Number(lengthBigInt);
|
|
461
|
+
offset = lengthOffset;
|
|
462
|
+
const contentBuffer = buffer.slice(offset, offset + length);
|
|
463
|
+
if (contentBuffer.length < length) {
|
|
464
|
+
throw new NotEnoughBytesError("string", length, contentBuffer.length);
|
|
465
|
+
}
|
|
466
|
+
const [value, contentOffset] = encoding.deserialize(contentBuffer);
|
|
467
|
+
offset += contentOffset;
|
|
468
|
+
return [value, offset];
|
|
469
|
+
}
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/struct.mjs
|
|
474
|
+
function struct(fields, options = {}) {
|
|
475
|
+
const fieldDescriptions = fields.map(([name, serializer]) => `${String(name)}: ${serializer.description}`).join(", ");
|
|
476
|
+
return {
|
|
477
|
+
description: options.description ?? `struct(${fieldDescriptions})`,
|
|
478
|
+
fixedSize: sumSerializerSizes(fields.map(([, field]) => field.fixedSize)),
|
|
479
|
+
maxSize: sumSerializerSizes(fields.map(([, field]) => field.maxSize)),
|
|
480
|
+
serialize: (struct2) => {
|
|
481
|
+
const fieldBytes = fields.map(([key, serializer]) => serializer.serialize(struct2[key]));
|
|
482
|
+
return mergeBytes(fieldBytes);
|
|
483
|
+
},
|
|
484
|
+
deserialize: (bytes2, offset = 0) => {
|
|
485
|
+
const struct2 = {};
|
|
486
|
+
fields.forEach(([key, serializer]) => {
|
|
487
|
+
const [value, newOffset] = serializer.deserialize(bytes2, offset);
|
|
488
|
+
offset = newOffset;
|
|
489
|
+
struct2[key] = value;
|
|
490
|
+
});
|
|
491
|
+
return [struct2, offset];
|
|
492
|
+
}
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// src/unsigned-transaction.ts
|
|
497
|
+
function getUnsignedTransaction(transaction) {
|
|
498
|
+
if ("signatures" in transaction) {
|
|
499
|
+
const {
|
|
500
|
+
signatures: _,
|
|
501
|
+
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
502
|
+
...unsignedTransaction
|
|
503
|
+
} = transaction;
|
|
504
|
+
return unsignedTransaction;
|
|
505
|
+
} else {
|
|
506
|
+
return transaction;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// src/blockhash.ts
|
|
511
|
+
function assertIsBlockhash(putativeBlockhash) {
|
|
512
|
+
try {
|
|
513
|
+
if (
|
|
514
|
+
// Lowest value (32 bytes of zeroes)
|
|
515
|
+
putativeBlockhash.length < 32 || // Highest value (32 bytes of 255)
|
|
516
|
+
putativeBlockhash.length > 44
|
|
517
|
+
) {
|
|
518
|
+
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
519
|
+
}
|
|
520
|
+
const bytes2 = base58.serialize(putativeBlockhash);
|
|
521
|
+
const numBytes = bytes2.byteLength;
|
|
522
|
+
if (numBytes !== 32) {
|
|
523
|
+
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
524
|
+
}
|
|
525
|
+
} catch (e2) {
|
|
526
|
+
throw new Error(`\`${putativeBlockhash}\` is not a blockhash`, {
|
|
527
|
+
cause: e2
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) {
|
|
532
|
+
if ("lifetimeConstraint" in transaction && transaction.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transaction.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
|
|
533
|
+
return transaction;
|
|
534
|
+
}
|
|
535
|
+
const out = {
|
|
536
|
+
...getUnsignedTransaction(transaction),
|
|
537
|
+
lifetimeConstraint: blockhashLifetimeConstraint
|
|
538
|
+
};
|
|
539
|
+
Object.freeze(out);
|
|
540
|
+
return out;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
// src/create-transaction.ts
|
|
544
|
+
function createTransaction({
|
|
545
|
+
version
|
|
546
|
+
}) {
|
|
547
|
+
const out = {
|
|
548
|
+
instructions: [],
|
|
549
|
+
version
|
|
550
|
+
};
|
|
551
|
+
Object.freeze(out);
|
|
552
|
+
return out;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
// ../instructions/dist/index.browser.js
|
|
556
|
+
var AccountRole = /* @__PURE__ */ ((AccountRole2) => {
|
|
557
|
+
AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */
|
|
558
|
+
3] = "WRITABLE_SIGNER";
|
|
559
|
+
AccountRole2[AccountRole2["READONLY_SIGNER"] = /* 2 */
|
|
560
|
+
2] = "READONLY_SIGNER";
|
|
561
|
+
AccountRole2[AccountRole2["WRITABLE"] = /* 1 */
|
|
562
|
+
1] = "WRITABLE";
|
|
563
|
+
AccountRole2[AccountRole2["READONLY"] = /* 0 */
|
|
564
|
+
0] = "READONLY";
|
|
565
|
+
return AccountRole2;
|
|
566
|
+
})(AccountRole || {});
|
|
567
|
+
var IS_WRITABLE_BITMASK = 1;
|
|
568
|
+
function isSignerRole(role) {
|
|
569
|
+
return role >= 2;
|
|
570
|
+
}
|
|
571
|
+
function isWritableRole(role) {
|
|
572
|
+
return (role & IS_WRITABLE_BITMASK) !== 0;
|
|
573
|
+
}
|
|
574
|
+
function mergeRoles(roleA, roleB) {
|
|
575
|
+
return roleA | roleB;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
// src/durable-nonce.ts
|
|
579
|
+
var RECENT_BLOCKHASHES_SYSVAR_ADDRESS = "SysvarRecentB1ockHashes11111111111111111111";
|
|
580
|
+
var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
|
|
581
|
+
function assertIsDurableNonceTransaction(transaction) {
|
|
582
|
+
if (!isDurableNonceTransaction(transaction)) {
|
|
583
|
+
throw new Error("Transaction is not a durable nonce transaction");
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
function createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress) {
|
|
587
|
+
return {
|
|
588
|
+
accounts: [
|
|
589
|
+
{ address: nonceAccountAddress, role: AccountRole.WRITABLE },
|
|
590
|
+
{
|
|
591
|
+
address: RECENT_BLOCKHASHES_SYSVAR_ADDRESS,
|
|
592
|
+
role: AccountRole.READONLY
|
|
593
|
+
},
|
|
594
|
+
{ address: nonceAuthorityAddress, role: AccountRole.READONLY_SIGNER }
|
|
595
|
+
],
|
|
596
|
+
data: new Uint8Array([4, 0, 0, 0]),
|
|
597
|
+
programAddress: SYSTEM_PROGRAM_ADDRESS
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
function isAdvanceNonceAccountInstruction(instruction) {
|
|
601
|
+
return instruction.programAddress === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data
|
|
602
|
+
instruction.data != null && isAdvanceNonceAccountInstructionData(instruction.data) && // Test for exactly 3 accounts
|
|
603
|
+
instruction.accounts?.length === 3 && // First account is nonce account address
|
|
604
|
+
instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole.WRITABLE && // Second account is recent blockhashes sysvar
|
|
605
|
+
instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole.READONLY && // Third account is nonce authority account
|
|
606
|
+
instruction.accounts[2].address != null && instruction.accounts[2].role === AccountRole.READONLY_SIGNER;
|
|
607
|
+
}
|
|
608
|
+
function isAdvanceNonceAccountInstructionData(data) {
|
|
609
|
+
return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;
|
|
610
|
+
}
|
|
611
|
+
function isDurableNonceTransaction(transaction) {
|
|
612
|
+
return "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.nonce === "string" && transaction.instructions[0] != null && isAdvanceNonceAccountInstruction(transaction.instructions[0]);
|
|
613
|
+
}
|
|
614
|
+
function setTransactionLifetimeUsingDurableNonce({
|
|
615
|
+
nonce,
|
|
616
|
+
nonceAccountAddress,
|
|
617
|
+
nonceAuthorityAddress
|
|
618
|
+
}, transaction) {
|
|
619
|
+
const isAlreadyDurableNonceTransaction = isDurableNonceTransaction(transaction);
|
|
620
|
+
if (isAlreadyDurableNonceTransaction && transaction.lifetimeConstraint.nonce === nonce && transaction.instructions[0].accounts[0].address === nonceAccountAddress && transaction.instructions[0].accounts[2].address === nonceAuthorityAddress) {
|
|
621
|
+
return transaction;
|
|
622
|
+
}
|
|
623
|
+
const out = {
|
|
624
|
+
...getUnsignedTransaction(transaction),
|
|
625
|
+
instructions: [
|
|
626
|
+
createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
|
|
627
|
+
...isAlreadyDurableNonceTransaction ? transaction.instructions.slice(1) : transaction.instructions
|
|
628
|
+
],
|
|
629
|
+
lifetimeConstraint: {
|
|
630
|
+
nonce
|
|
631
|
+
}
|
|
632
|
+
};
|
|
633
|
+
Object.freeze(out);
|
|
634
|
+
return out;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
// src/fee-payer.ts
|
|
638
|
+
function setTransactionFeePayer(feePayer, transaction) {
|
|
639
|
+
if ("feePayer" in transaction && feePayer === transaction.feePayer) {
|
|
640
|
+
return transaction;
|
|
641
|
+
}
|
|
642
|
+
const out = {
|
|
643
|
+
...getUnsignedTransaction(transaction),
|
|
644
|
+
feePayer
|
|
645
|
+
};
|
|
646
|
+
Object.freeze(out);
|
|
647
|
+
return out;
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
// src/instructions.ts
|
|
651
|
+
function appendTransactionInstruction(instruction, transaction) {
|
|
652
|
+
const out = {
|
|
653
|
+
...getUnsignedTransaction(transaction),
|
|
654
|
+
instructions: [...transaction.instructions, instruction]
|
|
655
|
+
};
|
|
656
|
+
Object.freeze(out);
|
|
657
|
+
return out;
|
|
658
|
+
}
|
|
659
|
+
function prependTransactionInstruction(instruction, transaction) {
|
|
660
|
+
const out = {
|
|
661
|
+
...getUnsignedTransaction(transaction),
|
|
662
|
+
instructions: [instruction, ...transaction.instructions]
|
|
663
|
+
};
|
|
664
|
+
Object.freeze(out);
|
|
665
|
+
return out;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
// ../codecs-core/dist/index.browser.js
|
|
669
|
+
function assertByteArrayIsNotEmptyForCodec(codecDescription, bytes2, offset = 0) {
|
|
670
|
+
if (bytes2.length - offset <= 0) {
|
|
671
|
+
throw new Error(`Codec [${codecDescription}] cannot decode empty byte arrays.`);
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
function assertByteArrayHasEnoughBytesForCodec(codecDescription, expected, bytes2, offset = 0) {
|
|
675
|
+
const bytesLength = bytes2.length - offset;
|
|
676
|
+
if (bytesLength < expected) {
|
|
677
|
+
throw new Error(`Codec [${codecDescription}] expected ${expected} bytes, got ${bytesLength}.`);
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
var mergeBytes2 = (byteArrays) => {
|
|
681
|
+
const nonEmptyByteArrays = byteArrays.filter((arr) => arr.length);
|
|
682
|
+
if (nonEmptyByteArrays.length === 0) {
|
|
683
|
+
return byteArrays.length ? byteArrays[0] : new Uint8Array();
|
|
684
|
+
}
|
|
685
|
+
if (nonEmptyByteArrays.length === 1) {
|
|
686
|
+
return nonEmptyByteArrays[0];
|
|
687
|
+
}
|
|
688
|
+
const totalLength = nonEmptyByteArrays.reduce((total, arr) => total + arr.length, 0);
|
|
689
|
+
const result = new Uint8Array(totalLength);
|
|
690
|
+
let offset = 0;
|
|
691
|
+
nonEmptyByteArrays.forEach((arr) => {
|
|
692
|
+
result.set(arr, offset);
|
|
693
|
+
offset += arr.length;
|
|
694
|
+
});
|
|
695
|
+
return result;
|
|
696
|
+
};
|
|
697
|
+
var padBytes2 = (bytes2, length) => {
|
|
698
|
+
if (bytes2.length >= length)
|
|
699
|
+
return bytes2;
|
|
700
|
+
const paddedBytes = new Uint8Array(length).fill(0);
|
|
701
|
+
paddedBytes.set(bytes2);
|
|
702
|
+
return paddedBytes;
|
|
703
|
+
};
|
|
704
|
+
var fixBytes2 = (bytes2, length) => padBytes2(bytes2.length <= length ? bytes2 : bytes2.slice(0, length), length);
|
|
705
|
+
function combineCodec(encoder, decoder, description) {
|
|
706
|
+
if (encoder.fixedSize !== decoder.fixedSize) {
|
|
707
|
+
throw new Error(
|
|
708
|
+
`Encoder and decoder must have the same fixed size, got [${encoder.fixedSize}] and [${decoder.fixedSize}].`
|
|
709
|
+
);
|
|
710
|
+
}
|
|
711
|
+
if (encoder.maxSize !== decoder.maxSize) {
|
|
712
|
+
throw new Error(
|
|
713
|
+
`Encoder and decoder must have the same max size, got [${encoder.maxSize}] and [${decoder.maxSize}].`
|
|
714
|
+
);
|
|
715
|
+
}
|
|
716
|
+
if (description === void 0 && encoder.description !== decoder.description) {
|
|
717
|
+
throw new Error(
|
|
718
|
+
`Encoder and decoder must have the same description, got [${encoder.description}] and [${decoder.description}]. Pass a custom description as a third argument if you want to override the description and bypass this error.`
|
|
719
|
+
);
|
|
720
|
+
}
|
|
721
|
+
return {
|
|
722
|
+
decode: decoder.decode,
|
|
723
|
+
description: description ?? encoder.description,
|
|
724
|
+
encode: encoder.encode,
|
|
725
|
+
fixedSize: encoder.fixedSize,
|
|
726
|
+
maxSize: encoder.maxSize
|
|
727
|
+
};
|
|
728
|
+
}
|
|
729
|
+
function fixCodecHelper(data, fixedBytes, description) {
|
|
730
|
+
return {
|
|
731
|
+
description: description ?? `fixed(${fixedBytes}, ${data.description})`,
|
|
732
|
+
fixedSize: fixedBytes,
|
|
733
|
+
maxSize: fixedBytes
|
|
734
|
+
};
|
|
735
|
+
}
|
|
736
|
+
function fixEncoder(encoder, fixedBytes, description) {
|
|
737
|
+
return {
|
|
738
|
+
...fixCodecHelper(encoder, fixedBytes, description),
|
|
739
|
+
encode: (value) => fixBytes2(encoder.encode(value), fixedBytes)
|
|
740
|
+
};
|
|
741
|
+
}
|
|
742
|
+
function fixDecoder(decoder, fixedBytes, description) {
|
|
743
|
+
return {
|
|
744
|
+
...fixCodecHelper(decoder, fixedBytes, description),
|
|
745
|
+
decode: (bytes2, offset = 0) => {
|
|
746
|
+
assertByteArrayHasEnoughBytesForCodec("fixCodec", fixedBytes, bytes2, offset);
|
|
747
|
+
if (offset > 0 || bytes2.length > fixedBytes) {
|
|
748
|
+
bytes2 = bytes2.slice(offset, offset + fixedBytes);
|
|
749
|
+
}
|
|
750
|
+
if (decoder.fixedSize !== null) {
|
|
751
|
+
bytes2 = fixBytes2(bytes2, decoder.fixedSize);
|
|
752
|
+
}
|
|
753
|
+
const [value] = decoder.decode(bytes2, 0);
|
|
754
|
+
return [value, offset + fixedBytes];
|
|
755
|
+
}
|
|
756
|
+
};
|
|
757
|
+
}
|
|
758
|
+
function mapEncoder(encoder, unmap) {
|
|
759
|
+
return {
|
|
760
|
+
description: encoder.description,
|
|
761
|
+
encode: (value) => encoder.encode(unmap(value)),
|
|
762
|
+
fixedSize: encoder.fixedSize,
|
|
763
|
+
maxSize: encoder.maxSize
|
|
764
|
+
};
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
// ../codecs-numbers/dist/index.browser.js
|
|
768
|
+
function assertNumberIsBetweenForCodec(codecDescription, min, max, value) {
|
|
769
|
+
if (value < min || value > max) {
|
|
770
|
+
throw new Error(
|
|
771
|
+
`Codec [${codecDescription}] expected number to be in the range [${min}, ${max}], got ${value}.`
|
|
772
|
+
);
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
function sharedNumberFactory(input) {
|
|
776
|
+
let littleEndian;
|
|
777
|
+
let defaultDescription = input.name;
|
|
778
|
+
if (input.size > 1) {
|
|
779
|
+
littleEndian = !("endian" in input.options) || input.options.endian === 0;
|
|
780
|
+
defaultDescription += littleEndian ? "(le)" : "(be)";
|
|
781
|
+
}
|
|
782
|
+
return {
|
|
783
|
+
description: input.options.description ?? defaultDescription,
|
|
784
|
+
fixedSize: input.size,
|
|
785
|
+
littleEndian,
|
|
786
|
+
maxSize: input.size
|
|
787
|
+
};
|
|
788
|
+
}
|
|
789
|
+
function numberEncoderFactory(input) {
|
|
790
|
+
const codecData = sharedNumberFactory(input);
|
|
791
|
+
return {
|
|
792
|
+
description: codecData.description,
|
|
793
|
+
encode(value) {
|
|
794
|
+
if (input.range) {
|
|
795
|
+
assertNumberIsBetweenForCodec(input.name, input.range[0], input.range[1], value);
|
|
796
|
+
}
|
|
797
|
+
const arrayBuffer = new ArrayBuffer(input.size);
|
|
798
|
+
input.set(new DataView(arrayBuffer), value, codecData.littleEndian);
|
|
799
|
+
return new Uint8Array(arrayBuffer);
|
|
800
|
+
},
|
|
801
|
+
fixedSize: codecData.fixedSize,
|
|
802
|
+
maxSize: codecData.maxSize
|
|
803
|
+
};
|
|
804
|
+
}
|
|
805
|
+
function numberDecoderFactory(input) {
|
|
806
|
+
const codecData = sharedNumberFactory(input);
|
|
807
|
+
return {
|
|
808
|
+
decode(bytes2, offset = 0) {
|
|
809
|
+
assertByteArrayIsNotEmptyForCodec(codecData.description, bytes2, offset);
|
|
810
|
+
assertByteArrayHasEnoughBytesForCodec(codecData.description, input.size, bytes2, offset);
|
|
811
|
+
const view = new DataView(toArrayBuffer2(bytes2, offset, input.size));
|
|
812
|
+
return [input.get(view, codecData.littleEndian), offset + input.size];
|
|
813
|
+
},
|
|
814
|
+
description: codecData.description,
|
|
815
|
+
fixedSize: codecData.fixedSize,
|
|
816
|
+
maxSize: codecData.maxSize
|
|
817
|
+
};
|
|
818
|
+
}
|
|
819
|
+
function toArrayBuffer2(bytes2, offset, length) {
|
|
820
|
+
const bytesOffset = bytes2.byteOffset + (offset ?? 0);
|
|
821
|
+
const bytesLength = length ?? bytes2.byteLength;
|
|
822
|
+
return bytes2.buffer.slice(bytesOffset, bytesOffset + bytesLength);
|
|
823
|
+
}
|
|
824
|
+
var getU32Encoder = (options = {}) => numberEncoderFactory({
|
|
825
|
+
name: "u32",
|
|
826
|
+
options,
|
|
827
|
+
range: [0, Number("0xffffffff")],
|
|
828
|
+
set: (view, value, le) => view.setUint32(0, value, le),
|
|
829
|
+
size: 4
|
|
830
|
+
});
|
|
831
|
+
var getU32Decoder = (options = {}) => numberDecoderFactory({
|
|
832
|
+
get: (view, le) => view.getUint32(0, le),
|
|
833
|
+
name: "u32",
|
|
834
|
+
options,
|
|
835
|
+
size: 4
|
|
836
|
+
});
|
|
837
|
+
var getU8Encoder = (options = {}) => numberEncoderFactory({
|
|
838
|
+
name: "u8",
|
|
839
|
+
options,
|
|
840
|
+
range: [0, Number("0xff")],
|
|
841
|
+
set: (view, value) => view.setUint8(0, value),
|
|
842
|
+
size: 1
|
|
843
|
+
});
|
|
844
|
+
var getU8Decoder = (options = {}) => numberDecoderFactory({
|
|
845
|
+
get: (view) => view.getUint8(0),
|
|
846
|
+
name: "u8",
|
|
847
|
+
options,
|
|
848
|
+
size: 1
|
|
849
|
+
});
|
|
850
|
+
var getU8Codec = (options = {}) => combineCodec(getU8Encoder(options), getU8Decoder(options));
|
|
851
|
+
|
|
852
|
+
// ../codecs-strings/dist/index.browser.js
|
|
853
|
+
function assertValidBaseString(alphabet4, testValue, givenValue = testValue) {
|
|
854
|
+
if (!testValue.match(new RegExp(`^[${alphabet4}]*$`))) {
|
|
855
|
+
throw new Error(`Expected a string of base ${alphabet4.length}, got [${givenValue}].`);
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
var getBaseXEncoder = (alphabet4) => {
|
|
859
|
+
const base = alphabet4.length;
|
|
860
|
+
const baseBigInt = BigInt(base);
|
|
861
|
+
return {
|
|
862
|
+
description: `base${base}`,
|
|
863
|
+
encode(value) {
|
|
864
|
+
assertValidBaseString(alphabet4, value);
|
|
865
|
+
if (value === "")
|
|
866
|
+
return new Uint8Array();
|
|
867
|
+
const chars = [...value];
|
|
868
|
+
let trailIndex = chars.findIndex((c) => c !== alphabet4[0]);
|
|
869
|
+
trailIndex = trailIndex === -1 ? chars.length : trailIndex;
|
|
870
|
+
const leadingZeroes = Array(trailIndex).fill(0);
|
|
871
|
+
if (trailIndex === chars.length)
|
|
872
|
+
return Uint8Array.from(leadingZeroes);
|
|
873
|
+
const tailChars = chars.slice(trailIndex);
|
|
874
|
+
let base10Number = 0n;
|
|
875
|
+
let baseXPower = 1n;
|
|
876
|
+
for (let i = tailChars.length - 1; i >= 0; i -= 1) {
|
|
877
|
+
base10Number += baseXPower * BigInt(alphabet4.indexOf(tailChars[i]));
|
|
878
|
+
baseXPower *= baseBigInt;
|
|
879
|
+
}
|
|
880
|
+
const tailBytes = [];
|
|
881
|
+
while (base10Number > 0n) {
|
|
882
|
+
tailBytes.unshift(Number(base10Number % 256n));
|
|
883
|
+
base10Number /= 256n;
|
|
884
|
+
}
|
|
885
|
+
return Uint8Array.from(leadingZeroes.concat(tailBytes));
|
|
886
|
+
},
|
|
887
|
+
fixedSize: null,
|
|
888
|
+
maxSize: null
|
|
889
|
+
};
|
|
890
|
+
};
|
|
891
|
+
var getBaseXDecoder = (alphabet4) => {
|
|
892
|
+
const base = alphabet4.length;
|
|
893
|
+
const baseBigInt = BigInt(base);
|
|
894
|
+
return {
|
|
895
|
+
decode(rawBytes, offset = 0) {
|
|
896
|
+
const bytes2 = offset === 0 ? rawBytes : rawBytes.slice(offset);
|
|
897
|
+
if (bytes2.length === 0)
|
|
898
|
+
return ["", 0];
|
|
899
|
+
let trailIndex = bytes2.findIndex((n) => n !== 0);
|
|
900
|
+
trailIndex = trailIndex === -1 ? bytes2.length : trailIndex;
|
|
901
|
+
const leadingZeroes = alphabet4[0].repeat(trailIndex);
|
|
902
|
+
if (trailIndex === bytes2.length)
|
|
903
|
+
return [leadingZeroes, rawBytes.length];
|
|
904
|
+
let base10Number = bytes2.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
|
|
905
|
+
const tailChars = [];
|
|
906
|
+
while (base10Number > 0n) {
|
|
907
|
+
tailChars.unshift(alphabet4[Number(base10Number % baseBigInt)]);
|
|
908
|
+
base10Number /= baseBigInt;
|
|
909
|
+
}
|
|
910
|
+
return [leadingZeroes + tailChars.join(""), rawBytes.length];
|
|
911
|
+
},
|
|
912
|
+
description: `base${base}`,
|
|
913
|
+
fixedSize: null,
|
|
914
|
+
maxSize: null
|
|
915
|
+
};
|
|
916
|
+
};
|
|
917
|
+
var alphabet2 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
918
|
+
var getBase58Encoder = () => getBaseXEncoder(alphabet2);
|
|
919
|
+
var getBase58Decoder = () => getBaseXDecoder(alphabet2);
|
|
920
|
+
var removeNullCharacters2 = (value) => (
|
|
921
|
+
// eslint-disable-next-line no-control-regex
|
|
922
|
+
value.replace(/\u0000/g, "")
|
|
923
|
+
);
|
|
924
|
+
var e = globalThis.TextDecoder;
|
|
925
|
+
var o = globalThis.TextEncoder;
|
|
926
|
+
var getUtf8Encoder = () => {
|
|
927
|
+
let textEncoder;
|
|
928
|
+
return {
|
|
929
|
+
description: "utf8",
|
|
930
|
+
encode: (value) => new Uint8Array((textEncoder || (textEncoder = new o())).encode(value)),
|
|
931
|
+
fixedSize: null,
|
|
932
|
+
maxSize: null
|
|
933
|
+
};
|
|
934
|
+
};
|
|
935
|
+
var getUtf8Decoder = () => {
|
|
936
|
+
let textDecoder;
|
|
937
|
+
return {
|
|
938
|
+
decode(bytes2, offset = 0) {
|
|
939
|
+
const value = (textDecoder || (textDecoder = new e())).decode(bytes2.slice(offset));
|
|
940
|
+
return [removeNullCharacters2(value), bytes2.length];
|
|
941
|
+
},
|
|
942
|
+
description: "utf8",
|
|
943
|
+
fixedSize: null,
|
|
944
|
+
maxSize: null
|
|
945
|
+
};
|
|
946
|
+
};
|
|
947
|
+
var getStringEncoder = (options = {}) => {
|
|
948
|
+
const size = options.size ?? getU32Encoder();
|
|
949
|
+
const encoding = options.encoding ?? getUtf8Encoder();
|
|
950
|
+
const description = options.description ?? `string(${encoding.description}; ${getSizeDescription2(size)})`;
|
|
951
|
+
if (size === "variable") {
|
|
952
|
+
return { ...encoding, description };
|
|
514
953
|
}
|
|
515
954
|
if (typeof size === "number") {
|
|
516
|
-
return
|
|
955
|
+
return fixEncoder(encoding, size, description);
|
|
517
956
|
}
|
|
518
957
|
return {
|
|
519
958
|
description,
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
const lengthBytes = size.serialize(contentBytes.length);
|
|
525
|
-
return mergeBytes([lengthBytes, contentBytes]);
|
|
959
|
+
encode: (value) => {
|
|
960
|
+
const contentBytes = encoding.encode(value);
|
|
961
|
+
const lengthBytes = size.encode(contentBytes.length);
|
|
962
|
+
return mergeBytes2([lengthBytes, contentBytes]);
|
|
526
963
|
},
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
964
|
+
fixedSize: null,
|
|
965
|
+
maxSize: null
|
|
966
|
+
};
|
|
967
|
+
};
|
|
968
|
+
var getStringDecoder = (options = {}) => {
|
|
969
|
+
const size = options.size ?? getU32Decoder();
|
|
970
|
+
const encoding = options.encoding ?? getUtf8Decoder();
|
|
971
|
+
const description = options.description ?? `string(${encoding.description}; ${getSizeDescription2(size)})`;
|
|
972
|
+
if (size === "variable") {
|
|
973
|
+
return { ...encoding, description };
|
|
974
|
+
}
|
|
975
|
+
if (typeof size === "number") {
|
|
976
|
+
return fixDecoder(encoding, size, description);
|
|
977
|
+
}
|
|
978
|
+
return {
|
|
979
|
+
decode: (bytes2, offset = 0) => {
|
|
980
|
+
assertByteArrayIsNotEmptyForCodec("string", bytes2, offset);
|
|
981
|
+
const [lengthBigInt, lengthOffset] = size.decode(bytes2, offset);
|
|
532
982
|
const length = Number(lengthBigInt);
|
|
533
983
|
offset = lengthOffset;
|
|
534
|
-
const
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
}
|
|
538
|
-
const [value, contentOffset] = encoding.deserialize(contentBuffer);
|
|
984
|
+
const contentBytes = bytes2.slice(offset, offset + length);
|
|
985
|
+
assertByteArrayHasEnoughBytesForCodec("string", length, contentBytes);
|
|
986
|
+
const [value, contentOffset] = encoding.decode(contentBytes);
|
|
539
987
|
offset += contentOffset;
|
|
540
988
|
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
989
|
},
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
const [value, newOffset] = serializer.deserialize(bytes2, offset);
|
|
560
|
-
offset = newOffset;
|
|
561
|
-
struct2[key] = value;
|
|
562
|
-
});
|
|
563
|
-
return [struct2, offset];
|
|
564
|
-
}
|
|
990
|
+
description,
|
|
991
|
+
fixedSize: null,
|
|
992
|
+
maxSize: null
|
|
565
993
|
};
|
|
994
|
+
};
|
|
995
|
+
function getSizeDescription2(size) {
|
|
996
|
+
return typeof size === "object" ? size.description : `${size}`;
|
|
566
997
|
}
|
|
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
|
-
}
|
|
998
|
+
|
|
999
|
+
// ../assertions/dist/index.browser.js
|
|
584
1000
|
function assertIsSecureContext() {
|
|
585
1001
|
if (!globalThis.isSecureContext) {
|
|
586
1002
|
throw new Error(
|
|
@@ -600,47 +1016,88 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
600
1016
|
throw new Error("No signing implementation could be found");
|
|
601
1017
|
}
|
|
602
1018
|
}
|
|
603
|
-
|
|
1019
|
+
|
|
1020
|
+
// ../addresses/dist/index.browser.js
|
|
1021
|
+
var memoizedBase58Encoder;
|
|
1022
|
+
var memoizedBase58Decoder;
|
|
1023
|
+
function getMemoizedBase58Encoder() {
|
|
1024
|
+
if (!memoizedBase58Encoder)
|
|
1025
|
+
memoizedBase58Encoder = getBase58Encoder();
|
|
1026
|
+
return memoizedBase58Encoder;
|
|
1027
|
+
}
|
|
1028
|
+
function getMemoizedBase58Decoder() {
|
|
1029
|
+
if (!memoizedBase58Decoder)
|
|
1030
|
+
memoizedBase58Decoder = getBase58Decoder();
|
|
1031
|
+
return memoizedBase58Decoder;
|
|
1032
|
+
}
|
|
1033
|
+
function assertIsAddress(putativeBase58EncodedAddress) {
|
|
1034
|
+
try {
|
|
1035
|
+
if (
|
|
1036
|
+
// Lowest address (32 bytes of zeroes)
|
|
1037
|
+
putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
|
|
1038
|
+
putativeBase58EncodedAddress.length > 44
|
|
1039
|
+
) {
|
|
1040
|
+
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
1041
|
+
}
|
|
1042
|
+
const base58Encoder = getMemoizedBase58Encoder();
|
|
1043
|
+
const bytes2 = base58Encoder.encode(putativeBase58EncodedAddress);
|
|
1044
|
+
const numBytes = bytes2.byteLength;
|
|
1045
|
+
if (numBytes !== 32) {
|
|
1046
|
+
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
1047
|
+
}
|
|
1048
|
+
} catch (e2) {
|
|
1049
|
+
throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, {
|
|
1050
|
+
cause: e2
|
|
1051
|
+
});
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
function address(putativeBase58EncodedAddress) {
|
|
1055
|
+
assertIsAddress(putativeBase58EncodedAddress);
|
|
1056
|
+
return putativeBase58EncodedAddress;
|
|
1057
|
+
}
|
|
1058
|
+
function getAddressEncoder(config) {
|
|
1059
|
+
return mapEncoder(
|
|
1060
|
+
getStringEncoder({
|
|
1061
|
+
description: config?.description ?? "Base58EncodedAddress",
|
|
1062
|
+
encoding: getMemoizedBase58Encoder(),
|
|
1063
|
+
size: 32
|
|
1064
|
+
}),
|
|
1065
|
+
(putativeAddress) => address(putativeAddress)
|
|
1066
|
+
);
|
|
1067
|
+
}
|
|
1068
|
+
function getAddressDecoder(config) {
|
|
1069
|
+
return getStringDecoder({
|
|
1070
|
+
description: config?.description ?? "Base58EncodedAddress",
|
|
1071
|
+
encoding: getMemoizedBase58Decoder(),
|
|
1072
|
+
size: 32
|
|
1073
|
+
});
|
|
1074
|
+
}
|
|
1075
|
+
function getAddressCodec(config) {
|
|
1076
|
+
return combineCodec(getAddressEncoder(config), getAddressDecoder(config));
|
|
1077
|
+
}
|
|
1078
|
+
function getAddressComparator() {
|
|
1079
|
+
return new Intl.Collator("en", {
|
|
1080
|
+
caseFirst: "lower",
|
|
1081
|
+
ignorePunctuation: false,
|
|
1082
|
+
localeMatcher: "best fit",
|
|
1083
|
+
numeric: false,
|
|
1084
|
+
sensitivity: "variant",
|
|
1085
|
+
usage: "sort"
|
|
1086
|
+
}).compare;
|
|
1087
|
+
}
|
|
1088
|
+
async function getAddressFromPublicKey(publicKey) {
|
|
604
1089
|
await assertKeyExporterIsAvailable();
|
|
605
1090
|
if (publicKey.type !== "public" || publicKey.algorithm.name !== "Ed25519") {
|
|
606
1091
|
throw new Error("The `CryptoKey` must be an `Ed25519` public key");
|
|
607
1092
|
}
|
|
608
1093
|
const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
|
|
609
|
-
const [base58EncodedAddress] =
|
|
1094
|
+
const [base58EncodedAddress] = getAddressDecoder().decode(new Uint8Array(publicKeyBytes));
|
|
610
1095
|
return base58EncodedAddress;
|
|
611
1096
|
}
|
|
612
|
-
async function signBytes(key, data) {
|
|
613
|
-
await assertSigningCapabilityIsAvailable();
|
|
614
|
-
const signedData = await crypto.subtle.sign("Ed25519", key, data);
|
|
615
|
-
return new Uint8Array(signedData);
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
// ../instructions/dist/index.browser.js
|
|
619
|
-
var AccountRole = /* @__PURE__ */ ((AccountRole2) => {
|
|
620
|
-
AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */
|
|
621
|
-
3] = "WRITABLE_SIGNER";
|
|
622
|
-
AccountRole2[AccountRole2["READONLY_SIGNER"] = /* 2 */
|
|
623
|
-
2] = "READONLY_SIGNER";
|
|
624
|
-
AccountRole2[AccountRole2["WRITABLE"] = /* 1 */
|
|
625
|
-
1] = "WRITABLE";
|
|
626
|
-
AccountRole2[AccountRole2["READONLY"] = /* 0 */
|
|
627
|
-
0] = "READONLY";
|
|
628
|
-
return AccountRole2;
|
|
629
|
-
})(AccountRole || {});
|
|
630
|
-
var IS_WRITABLE_BITMASK = 1;
|
|
631
|
-
function isSignerRole(role) {
|
|
632
|
-
return role >= 2;
|
|
633
|
-
}
|
|
634
|
-
function isWritableRole(role) {
|
|
635
|
-
return (role & IS_WRITABLE_BITMASK) !== 0;
|
|
636
|
-
}
|
|
637
|
-
function mergeRoles(roleA, roleB) {
|
|
638
|
-
return roleA | roleB;
|
|
639
|
-
}
|
|
640
1097
|
|
|
641
1098
|
// src/accounts.ts
|
|
642
|
-
function upsert(addressMap,
|
|
643
|
-
addressMap[
|
|
1099
|
+
function upsert(addressMap, address2, update) {
|
|
1100
|
+
addressMap[address2] = update(addressMap[address2] ?? { role: AccountRole.READONLY });
|
|
644
1101
|
}
|
|
645
1102
|
var TYPE = Symbol("AddressMapTypeProperty");
|
|
646
1103
|
function getAddressMapFromInstructions(feePayer, instructions) {
|
|
@@ -691,7 +1148,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
691
1148
|
const shouldReplaceEntry = (
|
|
692
1149
|
// Consider using the new LOOKUP_TABLE if its address is different...
|
|
693
1150
|
entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
|
|
694
|
-
(addressComparator || (addressComparator =
|
|
1151
|
+
(addressComparator || (addressComparator = getAddressComparator()))(
|
|
695
1152
|
accountMeta.lookupTableAddress,
|
|
696
1153
|
entry.lookupTableAddress
|
|
697
1154
|
) < 0
|
|
@@ -797,14 +1254,14 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
797
1254
|
if (leftIsWritable !== isWritableRole(rightEntry.role)) {
|
|
798
1255
|
return leftIsWritable ? -1 : 1;
|
|
799
1256
|
}
|
|
800
|
-
addressComparator || (addressComparator =
|
|
1257
|
+
addressComparator || (addressComparator = getAddressComparator());
|
|
801
1258
|
if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
|
|
802
1259
|
return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
|
|
803
1260
|
} else {
|
|
804
1261
|
return addressComparator(leftAddress, rightAddress);
|
|
805
1262
|
}
|
|
806
|
-
}).map(([
|
|
807
|
-
address,
|
|
1263
|
+
}).map(([address2, addressMeta]) => ({
|
|
1264
|
+
address: address2,
|
|
808
1265
|
...addressMeta
|
|
809
1266
|
}));
|
|
810
1267
|
return orderedAccounts;
|
|
@@ -828,7 +1285,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
828
1285
|
entry.readableIndices.push(account.addressIndex);
|
|
829
1286
|
}
|
|
830
1287
|
}
|
|
831
|
-
return Object.keys(index).sort(
|
|
1288
|
+
return Object.keys(index).sort(getAddressComparator()).map((lookupTableAddress) => ({
|
|
832
1289
|
lookupTableAddress,
|
|
833
1290
|
...index[lookupTableAddress]
|
|
834
1291
|
}));
|
|
@@ -873,7 +1330,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
873
1330
|
return instructions.map(({ accounts, data, programAddress }) => {
|
|
874
1331
|
return {
|
|
875
1332
|
programAddressIndex: accountIndex[programAddress],
|
|
876
|
-
...accounts ? { accountIndices: accounts.map(({ address }) => accountIndex[
|
|
1333
|
+
...accounts ? { accountIndices: accounts.map(({ address: address2 }) => accountIndex[address2]) } : null,
|
|
877
1334
|
...data ? { data } : null
|
|
878
1335
|
};
|
|
879
1336
|
});
|
|
@@ -891,7 +1348,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
891
1348
|
function getCompiledStaticAccounts(orderedAccounts) {
|
|
892
1349
|
const firstLookupTableAccountIndex = orderedAccounts.findIndex((account) => "lookupTableAddress" in account);
|
|
893
1350
|
const orderedStaticAccounts = firstLookupTableAccountIndex === -1 ? orderedAccounts : orderedAccounts.slice(0, firstLookupTableAccountIndex);
|
|
894
|
-
return orderedStaticAccounts.map(({ address }) =>
|
|
1351
|
+
return orderedStaticAccounts.map(({ address: address2 }) => address2);
|
|
895
1352
|
}
|
|
896
1353
|
|
|
897
1354
|
// src/message.ts
|
|
@@ -908,13 +1365,41 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
908
1365
|
};
|
|
909
1366
|
}
|
|
910
1367
|
|
|
1368
|
+
// src/compile-transaction.ts
|
|
1369
|
+
function getCompiledTransaction(transaction) {
|
|
1370
|
+
const compiledMessage = compileMessage(transaction);
|
|
1371
|
+
let signatures;
|
|
1372
|
+
if ("signatures" in transaction) {
|
|
1373
|
+
signatures = [];
|
|
1374
|
+
for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
|
|
1375
|
+
signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
|
|
1376
|
+
}
|
|
1377
|
+
} else {
|
|
1378
|
+
signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
|
|
1379
|
+
}
|
|
1380
|
+
return {
|
|
1381
|
+
compiledMessage,
|
|
1382
|
+
signatures
|
|
1383
|
+
};
|
|
1384
|
+
}
|
|
1385
|
+
|
|
911
1386
|
// src/serializers/address-table-lookup.ts
|
|
1387
|
+
function addressSerializerCompat(compat) {
|
|
1388
|
+
const codec = getAddressCodec();
|
|
1389
|
+
return {
|
|
1390
|
+
description: compat?.description ?? codec.description,
|
|
1391
|
+
deserialize: codec.decode,
|
|
1392
|
+
fixedSize: codec.fixedSize,
|
|
1393
|
+
maxSize: codec.maxSize,
|
|
1394
|
+
serialize: codec.encode
|
|
1395
|
+
};
|
|
1396
|
+
}
|
|
912
1397
|
function getAddressTableLookupCodec() {
|
|
913
1398
|
return struct(
|
|
914
1399
|
[
|
|
915
1400
|
[
|
|
916
1401
|
"lookupTableAddress",
|
|
917
|
-
|
|
1402
|
+
addressSerializerCompat(
|
|
918
1403
|
{
|
|
919
1404
|
description: "The address of the address lookup table account from which instruction addresses should be looked up"
|
|
920
1405
|
}
|
|
@@ -945,38 +1430,73 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
945
1430
|
);
|
|
946
1431
|
}
|
|
947
1432
|
|
|
1433
|
+
// ../codecs-data-structures/dist/index.browser.js
|
|
1434
|
+
function sumCodecSizes(sizes) {
|
|
1435
|
+
return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
|
|
1436
|
+
}
|
|
1437
|
+
function structCodecHelper(fields, description) {
|
|
1438
|
+
const fieldDescriptions = fields.map(([name, codec]) => `${String(name)}: ${codec.description}`).join(", ");
|
|
1439
|
+
return {
|
|
1440
|
+
description: description ?? `struct(${fieldDescriptions})`,
|
|
1441
|
+
fixedSize: sumCodecSizes(fields.map(([, field]) => field.fixedSize)),
|
|
1442
|
+
maxSize: sumCodecSizes(fields.map(([, field]) => field.maxSize))
|
|
1443
|
+
};
|
|
1444
|
+
}
|
|
1445
|
+
function getStructEncoder(fields, options = {}) {
|
|
1446
|
+
return {
|
|
1447
|
+
...structCodecHelper(fields, options.description),
|
|
1448
|
+
encode: (struct2) => {
|
|
1449
|
+
const fieldBytes = fields.map(([key, codec]) => codec.encode(struct2[key]));
|
|
1450
|
+
return mergeBytes2(fieldBytes);
|
|
1451
|
+
}
|
|
1452
|
+
};
|
|
1453
|
+
}
|
|
1454
|
+
function getStructDecoder(fields, options = {}) {
|
|
1455
|
+
return {
|
|
1456
|
+
...structCodecHelper(fields, options.description),
|
|
1457
|
+
decode: (bytes2, offset = 0) => {
|
|
1458
|
+
const struct2 = {};
|
|
1459
|
+
fields.forEach(([key, codec]) => {
|
|
1460
|
+
const [value, newOffset] = codec.decode(bytes2, offset);
|
|
1461
|
+
offset = newOffset;
|
|
1462
|
+
struct2[key] = value;
|
|
1463
|
+
});
|
|
1464
|
+
return [struct2, offset];
|
|
1465
|
+
}
|
|
1466
|
+
};
|
|
1467
|
+
}
|
|
1468
|
+
function getStructCodec(fields, options = {}) {
|
|
1469
|
+
return combineCodec(getStructEncoder(fields, options), getStructDecoder(fields, options));
|
|
1470
|
+
}
|
|
1471
|
+
|
|
948
1472
|
// src/serializers/header.ts
|
|
1473
|
+
var memoizedU8Codec;
|
|
1474
|
+
function getMemoizedU8Codec() {
|
|
1475
|
+
if (!memoizedU8Codec)
|
|
1476
|
+
memoizedU8Codec = getU8Codec();
|
|
1477
|
+
return memoizedU8Codec;
|
|
1478
|
+
}
|
|
1479
|
+
function getMemoizedU8CodecDescription(description) {
|
|
1480
|
+
const codec = getMemoizedU8Codec();
|
|
1481
|
+
return {
|
|
1482
|
+
...codec,
|
|
1483
|
+
description: description ?? codec.description
|
|
1484
|
+
};
|
|
1485
|
+
}
|
|
1486
|
+
var numSignerAccountsDescription = "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction" ;
|
|
1487
|
+
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" ;
|
|
1488
|
+
var numReadonlyNonSignerAccountsDescription = "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable" ;
|
|
1489
|
+
var messageHeaderDescription = "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses" ;
|
|
949
1490
|
function getMessageHeaderCodec() {
|
|
950
|
-
return
|
|
1491
|
+
return getStructCodec(
|
|
951
1492
|
[
|
|
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
|
-
]
|
|
1493
|
+
["numSignerAccounts", getMemoizedU8CodecDescription(numSignerAccountsDescription)],
|
|
1494
|
+
["numReadonlySignerAccounts", getMemoizedU8CodecDescription(numReadonlySignerAccountsDescription)],
|
|
1495
|
+
["numReadonlyNonSignerAccounts", getMemoizedU8CodecDescription(numReadonlyNonSignerAccountsDescription)]
|
|
976
1496
|
],
|
|
977
1497
|
{
|
|
978
|
-
description:
|
|
979
|
-
}
|
|
1498
|
+
description: messageHeaderDescription
|
|
1499
|
+
}
|
|
980
1500
|
);
|
|
981
1501
|
}
|
|
982
1502
|
|
|
@@ -993,7 +1513,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
993
1513
|
)
|
|
994
1514
|
],
|
|
995
1515
|
[
|
|
996
|
-
"
|
|
1516
|
+
"accountIndices",
|
|
997
1517
|
array(
|
|
998
1518
|
u8({
|
|
999
1519
|
description: "The index of an account, according to the well-ordered accounts list for this transaction"
|
|
@@ -1013,42 +1533,29 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1013
1533
|
]
|
|
1014
1534
|
]),
|
|
1015
1535
|
(value) => {
|
|
1016
|
-
if (value.
|
|
1536
|
+
if (value.accountIndices !== void 0 && value.data !== void 0) {
|
|
1017
1537
|
return value;
|
|
1018
1538
|
}
|
|
1019
1539
|
return {
|
|
1020
1540
|
...value,
|
|
1021
|
-
|
|
1541
|
+
accountIndices: value.accountIndices ?? [],
|
|
1022
1542
|
data: value.data ?? new Uint8Array(0)
|
|
1023
1543
|
};
|
|
1024
1544
|
},
|
|
1025
1545
|
(value) => {
|
|
1026
|
-
if (value.
|
|
1546
|
+
if (value.accountIndices.length && value.data.byteLength) {
|
|
1027
1547
|
return value;
|
|
1028
1548
|
}
|
|
1029
|
-
const {
|
|
1549
|
+
const { accountIndices, data, ...rest } = value;
|
|
1030
1550
|
return {
|
|
1031
1551
|
...rest,
|
|
1032
|
-
...
|
|
1552
|
+
...accountIndices.length ? { accountIndices } : null,
|
|
1033
1553
|
...data.byteLength ? { data } : null
|
|
1034
1554
|
};
|
|
1035
1555
|
}
|
|
1036
1556
|
);
|
|
1037
1557
|
}
|
|
1038
1558
|
|
|
1039
|
-
// src/serializers/unimplemented.ts
|
|
1040
|
-
function getError(type, name) {
|
|
1041
|
-
const functionSuffix = name + type[0].toUpperCase() + type.slice(1);
|
|
1042
|
-
return new Error(
|
|
1043
|
-
`No ${type} exists for ${name}. Use \`get${functionSuffix}()\` if you need a ${type}, and \`get${name}Codec()\` if you need to both encode and decode ${name}`
|
|
1044
|
-
);
|
|
1045
|
-
}
|
|
1046
|
-
function getUnimplementedDecoder(name) {
|
|
1047
|
-
return () => {
|
|
1048
|
-
throw getError("decoder", name);
|
|
1049
|
-
};
|
|
1050
|
-
}
|
|
1051
|
-
|
|
1052
1559
|
// src/serializers/transaction-version.ts
|
|
1053
1560
|
var VERSION_FLAG_MASK = 128;
|
|
1054
1561
|
var BASE_CONFIG = {
|
|
@@ -1056,7 +1563,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1056
1563
|
fixedSize: null,
|
|
1057
1564
|
maxSize: 1
|
|
1058
1565
|
};
|
|
1059
|
-
function
|
|
1566
|
+
function decode(bytes2, offset = 0) {
|
|
1060
1567
|
const firstByte = bytes2[offset];
|
|
1061
1568
|
if ((firstByte & VERSION_FLAG_MASK) === 0) {
|
|
1062
1569
|
return ["legacy", offset];
|
|
@@ -1065,7 +1572,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1065
1572
|
return [version, offset + 1];
|
|
1066
1573
|
}
|
|
1067
1574
|
}
|
|
1068
|
-
function
|
|
1575
|
+
function encode(value) {
|
|
1069
1576
|
if (value === "legacy") {
|
|
1070
1577
|
return new Uint8Array();
|
|
1071
1578
|
}
|
|
@@ -1074,11 +1581,32 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1074
1581
|
}
|
|
1075
1582
|
return new Uint8Array([value | VERSION_FLAG_MASK]);
|
|
1076
1583
|
}
|
|
1077
|
-
function
|
|
1584
|
+
function getTransactionVersionDecoder() {
|
|
1078
1585
|
return {
|
|
1079
1586
|
...BASE_CONFIG,
|
|
1080
|
-
|
|
1081
|
-
|
|
1587
|
+
decode
|
|
1588
|
+
};
|
|
1589
|
+
}
|
|
1590
|
+
function getTransactionVersionEncoder() {
|
|
1591
|
+
return {
|
|
1592
|
+
...BASE_CONFIG,
|
|
1593
|
+
encode
|
|
1594
|
+
};
|
|
1595
|
+
}
|
|
1596
|
+
function getTransactionVersionCodec() {
|
|
1597
|
+
return combineCodec(getTransactionVersionEncoder(), getTransactionVersionDecoder());
|
|
1598
|
+
}
|
|
1599
|
+
|
|
1600
|
+
// src/serializers/unimplemented.ts
|
|
1601
|
+
function getError(type, name) {
|
|
1602
|
+
const functionSuffix = name + type[0].toUpperCase() + type.slice(1);
|
|
1603
|
+
return new Error(
|
|
1604
|
+
`No ${type} exists for ${name}. Use \`get${functionSuffix}()\` if you need a ${type}, and \`get${name}Codec()\` if you need to both encode and decode ${name}`
|
|
1605
|
+
);
|
|
1606
|
+
}
|
|
1607
|
+
function getUnimplementedDecoder(name) {
|
|
1608
|
+
return () => {
|
|
1609
|
+
throw getError("decoder", name);
|
|
1082
1610
|
};
|
|
1083
1611
|
}
|
|
1084
1612
|
|
|
@@ -1088,7 +1616,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1088
1616
|
fixedSize: null,
|
|
1089
1617
|
maxSize: null
|
|
1090
1618
|
};
|
|
1091
|
-
function
|
|
1619
|
+
function serialize(compiledMessage) {
|
|
1092
1620
|
if (compiledMessage.version === "legacy") {
|
|
1093
1621
|
return struct(getPreludeStructSerializerTuple()).serialize(compiledMessage);
|
|
1094
1622
|
} else {
|
|
@@ -1109,13 +1637,22 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1109
1637
|
).serialize(compiledMessage);
|
|
1110
1638
|
}
|
|
1111
1639
|
}
|
|
1640
|
+
function toSerializer(codec) {
|
|
1641
|
+
return {
|
|
1642
|
+
description: codec.description,
|
|
1643
|
+
deserialize: codec.decode,
|
|
1644
|
+
fixedSize: codec.fixedSize,
|
|
1645
|
+
maxSize: codec.maxSize,
|
|
1646
|
+
serialize: codec.encode
|
|
1647
|
+
};
|
|
1648
|
+
}
|
|
1112
1649
|
function getPreludeStructSerializerTuple() {
|
|
1113
1650
|
return [
|
|
1114
|
-
["version", getTransactionVersionCodec()],
|
|
1115
|
-
["header", getMessageHeaderCodec()],
|
|
1651
|
+
["version", toSerializer(getTransactionVersionCodec())],
|
|
1652
|
+
["header", toSerializer(getMessageHeaderCodec())],
|
|
1116
1653
|
[
|
|
1117
1654
|
"staticAccounts",
|
|
1118
|
-
array(
|
|
1655
|
+
array(toSerializer(getAddressCodec()), {
|
|
1119
1656
|
description: "A compact-array of static account addresses belonging to this transaction" ,
|
|
1120
1657
|
size: shortU16()
|
|
1121
1658
|
})
|
|
@@ -1147,26 +1684,108 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1147
1684
|
return {
|
|
1148
1685
|
...BASE_CONFIG2,
|
|
1149
1686
|
deserialize: getUnimplementedDecoder("CompiledMessage"),
|
|
1687
|
+
serialize
|
|
1688
|
+
};
|
|
1689
|
+
}
|
|
1690
|
+
|
|
1691
|
+
// src/serializers/transaction.ts
|
|
1692
|
+
var BASE_CONFIG3 = {
|
|
1693
|
+
description: "The wire format of a Solana transaction" ,
|
|
1694
|
+
fixedSize: null,
|
|
1695
|
+
maxSize: null
|
|
1696
|
+
};
|
|
1697
|
+
function serialize2(transaction) {
|
|
1698
|
+
const compiledTransaction = getCompiledTransaction(transaction);
|
|
1699
|
+
return struct([
|
|
1700
|
+
[
|
|
1701
|
+
"signatures",
|
|
1702
|
+
array(bytes({ size: 64 }), {
|
|
1703
|
+
...{ description: "A compact array of 64-byte, base-64 encoded Ed25519 signatures" } ,
|
|
1704
|
+
size: shortU16()
|
|
1705
|
+
})
|
|
1706
|
+
],
|
|
1707
|
+
["compiledMessage", getCompiledMessageEncoder()]
|
|
1708
|
+
]).serialize(compiledTransaction);
|
|
1709
|
+
}
|
|
1710
|
+
function getTransactionEncoder() {
|
|
1711
|
+
return {
|
|
1712
|
+
...BASE_CONFIG3,
|
|
1713
|
+
deserialize: getUnimplementedDecoder("CompiledMessage"),
|
|
1150
1714
|
serialize: serialize2
|
|
1151
1715
|
};
|
|
1152
1716
|
}
|
|
1153
1717
|
|
|
1718
|
+
// ../keys/dist/index.browser.js
|
|
1719
|
+
async function signBytes(key, data) {
|
|
1720
|
+
await assertSigningCapabilityIsAvailable();
|
|
1721
|
+
const signedData = await crypto.subtle.sign("Ed25519", key, data);
|
|
1722
|
+
return new Uint8Array(signedData);
|
|
1723
|
+
}
|
|
1724
|
+
|
|
1154
1725
|
// src/signatures.ts
|
|
1726
|
+
function assertIsTransactionSignature(putativeTransactionSignature) {
|
|
1727
|
+
try {
|
|
1728
|
+
if (
|
|
1729
|
+
// Lowest value (64 bytes of zeroes)
|
|
1730
|
+
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
1731
|
+
putativeTransactionSignature.length > 88
|
|
1732
|
+
) {
|
|
1733
|
+
throw new Error("Expected input string to decode to a byte array of length 64.");
|
|
1734
|
+
}
|
|
1735
|
+
const bytes2 = base58.serialize(putativeTransactionSignature);
|
|
1736
|
+
const numBytes = bytes2.byteLength;
|
|
1737
|
+
if (numBytes !== 64) {
|
|
1738
|
+
throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
|
|
1739
|
+
}
|
|
1740
|
+
} catch (e2) {
|
|
1741
|
+
throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, {
|
|
1742
|
+
cause: e2
|
|
1743
|
+
});
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1746
|
+
function isTransactionSignature(putativeTransactionSignature) {
|
|
1747
|
+
if (
|
|
1748
|
+
// Lowest value (64 bytes of zeroes)
|
|
1749
|
+
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
1750
|
+
putativeTransactionSignature.length > 88
|
|
1751
|
+
) {
|
|
1752
|
+
return false;
|
|
1753
|
+
}
|
|
1754
|
+
const bytes2 = base58.serialize(putativeTransactionSignature);
|
|
1755
|
+
const numBytes = bytes2.byteLength;
|
|
1756
|
+
if (numBytes !== 64) {
|
|
1757
|
+
return false;
|
|
1758
|
+
}
|
|
1759
|
+
return true;
|
|
1760
|
+
}
|
|
1155
1761
|
async function getCompiledMessageSignature(message, secretKey) {
|
|
1156
1762
|
const wireMessageBytes = getCompiledMessageEncoder().serialize(message);
|
|
1157
1763
|
const signature = await signBytes(secretKey, wireMessageBytes);
|
|
1158
1764
|
return signature;
|
|
1159
1765
|
}
|
|
1160
|
-
|
|
1766
|
+
function getSignatureFromTransaction(transaction) {
|
|
1767
|
+
const signature = transaction.signatures[transaction.feePayer];
|
|
1768
|
+
if (!signature) {
|
|
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
|
+
return signature;
|
|
1774
|
+
}
|
|
1775
|
+
async function signTransaction(keyPairs, transaction) {
|
|
1161
1776
|
const compiledMessage = compileMessage(transaction);
|
|
1162
|
-
const
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1777
|
+
const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
|
|
1778
|
+
const publicKeySignaturePairs = await Promise.all(
|
|
1779
|
+
keyPairs.map(
|
|
1780
|
+
(keyPair) => Promise.all([
|
|
1781
|
+
getAddressFromPublicKey(keyPair.publicKey),
|
|
1782
|
+
getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
|
|
1783
|
+
])
|
|
1784
|
+
)
|
|
1785
|
+
);
|
|
1786
|
+
for (const [signerPublicKey, signature] of publicKeySignaturePairs) {
|
|
1787
|
+
nextSignatures[signerPublicKey] = signature;
|
|
1788
|
+
}
|
|
1170
1789
|
const out = {
|
|
1171
1790
|
...transaction,
|
|
1172
1791
|
signatures: nextSignatures
|
|
@@ -1174,12 +1793,34 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1174
1793
|
Object.freeze(out);
|
|
1175
1794
|
return out;
|
|
1176
1795
|
}
|
|
1796
|
+
function transactionSignature(putativeTransactionSignature) {
|
|
1797
|
+
assertIsTransactionSignature(putativeTransactionSignature);
|
|
1798
|
+
return putativeTransactionSignature;
|
|
1799
|
+
}
|
|
1800
|
+
|
|
1801
|
+
// src/wire-transaction.ts
|
|
1802
|
+
function getBase64EncodedWireTransaction(transaction) {
|
|
1803
|
+
const wireTransactionBytes = getTransactionEncoder().serialize(transaction);
|
|
1804
|
+
{
|
|
1805
|
+
return btoa(String.fromCharCode(...wireTransactionBytes));
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1177
1808
|
|
|
1178
1809
|
exports.appendTransactionInstruction = appendTransactionInstruction;
|
|
1810
|
+
exports.assertIsBlockhash = assertIsBlockhash;
|
|
1811
|
+
exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
|
|
1812
|
+
exports.assertIsTransactionSignature = assertIsTransactionSignature;
|
|
1179
1813
|
exports.createTransaction = createTransaction;
|
|
1814
|
+
exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
|
|
1815
|
+
exports.getSignatureFromTransaction = getSignatureFromTransaction;
|
|
1816
|
+
exports.getTransactionEncoder = getTransactionEncoder;
|
|
1817
|
+
exports.isTransactionSignature = isTransactionSignature;
|
|
1180
1818
|
exports.prependTransactionInstruction = prependTransactionInstruction;
|
|
1181
1819
|
exports.setTransactionFeePayer = setTransactionFeePayer;
|
|
1820
|
+
exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
|
|
1821
|
+
exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
|
|
1182
1822
|
exports.signTransaction = signTransaction;
|
|
1823
|
+
exports.transactionSignature = transactionSignature;
|
|
1183
1824
|
|
|
1184
1825
|
return exports;
|
|
1185
1826
|
|