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