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