@solana/signers 2.0.0-experimental.3331786

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