@pooflabs/web 0.0.71 → 0.0.72

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.
@@ -0,0 +1,4867 @@
1
+ import { g as getDefaultExportFromCjs } from './index-u0Q8zhkj.esm.js';
2
+ import { s as startRemoteScenario, t as transact } from './index.browser-DZjyUgtx.esm.js';
3
+ import 'axios';
4
+ import '@solana/web3.js';
5
+ import '@coral-xyz/anchor';
6
+ import 'react';
7
+ import 'react/jsx-runtime';
8
+
9
+ /** Solana Mainnet (beta) cluster, e.g. https://api.mainnet-beta.solana.com */
10
+ const SOLANA_MAINNET_CHAIN = 'solana:mainnet';
11
+
12
+ /** Name of the feature. */
13
+ const SolanaSignAndSendTransaction = 'solana:signAndSendTransaction';
14
+
15
+ /** Name of the feature. */
16
+ const SolanaSignIn = 'solana:signIn';
17
+
18
+ /** Name of the feature. */
19
+ const SolanaSignMessage = 'solana:signMessage';
20
+
21
+ /** Name of the feature. */
22
+ const SolanaSignTransaction = 'solana:signTransaction';
23
+
24
+ var browser = {};
25
+
26
+ var canPromise;
27
+ var hasRequiredCanPromise;
28
+
29
+ function requireCanPromise () {
30
+ if (hasRequiredCanPromise) return canPromise;
31
+ hasRequiredCanPromise = 1;
32
+ // can-promise has a crash in some versions of react native that dont have
33
+ // standard global objects
34
+ // https://github.com/soldair/node-qrcode/issues/157
35
+
36
+ canPromise = function () {
37
+ return typeof Promise === 'function' && Promise.prototype && Promise.prototype.then
38
+ };
39
+ return canPromise;
40
+ }
41
+
42
+ var qrcode = {};
43
+
44
+ var utils$1 = {};
45
+
46
+ var hasRequiredUtils$1;
47
+
48
+ function requireUtils$1 () {
49
+ if (hasRequiredUtils$1) return utils$1;
50
+ hasRequiredUtils$1 = 1;
51
+ let toSJISFunction;
52
+ const CODEWORDS_COUNT = [
53
+ 0, // Not used
54
+ 26, 44, 70, 100, 134, 172, 196, 242, 292, 346,
55
+ 404, 466, 532, 581, 655, 733, 815, 901, 991, 1085,
56
+ 1156, 1258, 1364, 1474, 1588, 1706, 1828, 1921, 2051, 2185,
57
+ 2323, 2465, 2611, 2761, 2876, 3034, 3196, 3362, 3532, 3706
58
+ ];
59
+
60
+ /**
61
+ * Returns the QR Code size for the specified version
62
+ *
63
+ * @param {Number} version QR Code version
64
+ * @return {Number} size of QR code
65
+ */
66
+ utils$1.getSymbolSize = function getSymbolSize (version) {
67
+ if (!version) throw new Error('"version" cannot be null or undefined')
68
+ if (version < 1 || version > 40) throw new Error('"version" should be in range from 1 to 40')
69
+ return version * 4 + 17
70
+ };
71
+
72
+ /**
73
+ * Returns the total number of codewords used to store data and EC information.
74
+ *
75
+ * @param {Number} version QR Code version
76
+ * @return {Number} Data length in bits
77
+ */
78
+ utils$1.getSymbolTotalCodewords = function getSymbolTotalCodewords (version) {
79
+ return CODEWORDS_COUNT[version]
80
+ };
81
+
82
+ /**
83
+ * Encode data with Bose-Chaudhuri-Hocquenghem
84
+ *
85
+ * @param {Number} data Value to encode
86
+ * @return {Number} Encoded value
87
+ */
88
+ utils$1.getBCHDigit = function (data) {
89
+ let digit = 0;
90
+
91
+ while (data !== 0) {
92
+ digit++;
93
+ data >>>= 1;
94
+ }
95
+
96
+ return digit
97
+ };
98
+
99
+ utils$1.setToSJISFunction = function setToSJISFunction (f) {
100
+ if (typeof f !== 'function') {
101
+ throw new Error('"toSJISFunc" is not a valid function.')
102
+ }
103
+
104
+ toSJISFunction = f;
105
+ };
106
+
107
+ utils$1.isKanjiModeEnabled = function () {
108
+ return typeof toSJISFunction !== 'undefined'
109
+ };
110
+
111
+ utils$1.toSJIS = function toSJIS (kanji) {
112
+ return toSJISFunction(kanji)
113
+ };
114
+ return utils$1;
115
+ }
116
+
117
+ var errorCorrectionLevel = {};
118
+
119
+ var hasRequiredErrorCorrectionLevel;
120
+
121
+ function requireErrorCorrectionLevel () {
122
+ if (hasRequiredErrorCorrectionLevel) return errorCorrectionLevel;
123
+ hasRequiredErrorCorrectionLevel = 1;
124
+ (function (exports$1) {
125
+ exports$1.L = { bit: 1 };
126
+ exports$1.M = { bit: 0 };
127
+ exports$1.Q = { bit: 3 };
128
+ exports$1.H = { bit: 2 };
129
+
130
+ function fromString (string) {
131
+ if (typeof string !== 'string') {
132
+ throw new Error('Param is not a string')
133
+ }
134
+
135
+ const lcStr = string.toLowerCase();
136
+
137
+ switch (lcStr) {
138
+ case 'l':
139
+ case 'low':
140
+ return exports$1.L
141
+
142
+ case 'm':
143
+ case 'medium':
144
+ return exports$1.M
145
+
146
+ case 'q':
147
+ case 'quartile':
148
+ return exports$1.Q
149
+
150
+ case 'h':
151
+ case 'high':
152
+ return exports$1.H
153
+
154
+ default:
155
+ throw new Error('Unknown EC Level: ' + string)
156
+ }
157
+ }
158
+
159
+ exports$1.isValid = function isValid (level) {
160
+ return level && typeof level.bit !== 'undefined' &&
161
+ level.bit >= 0 && level.bit < 4
162
+ };
163
+
164
+ exports$1.from = function from (value, defaultValue) {
165
+ if (exports$1.isValid(value)) {
166
+ return value
167
+ }
168
+
169
+ try {
170
+ return fromString(value)
171
+ } catch (e) {
172
+ return defaultValue
173
+ }
174
+ };
175
+ } (errorCorrectionLevel));
176
+ return errorCorrectionLevel;
177
+ }
178
+
179
+ var bitBuffer;
180
+ var hasRequiredBitBuffer;
181
+
182
+ function requireBitBuffer () {
183
+ if (hasRequiredBitBuffer) return bitBuffer;
184
+ hasRequiredBitBuffer = 1;
185
+ function BitBuffer () {
186
+ this.buffer = [];
187
+ this.length = 0;
188
+ }
189
+
190
+ BitBuffer.prototype = {
191
+
192
+ get: function (index) {
193
+ const bufIndex = Math.floor(index / 8);
194
+ return ((this.buffer[bufIndex] >>> (7 - index % 8)) & 1) === 1
195
+ },
196
+
197
+ put: function (num, length) {
198
+ for (let i = 0; i < length; i++) {
199
+ this.putBit(((num >>> (length - i - 1)) & 1) === 1);
200
+ }
201
+ },
202
+
203
+ getLengthInBits: function () {
204
+ return this.length
205
+ },
206
+
207
+ putBit: function (bit) {
208
+ const bufIndex = Math.floor(this.length / 8);
209
+ if (this.buffer.length <= bufIndex) {
210
+ this.buffer.push(0);
211
+ }
212
+
213
+ if (bit) {
214
+ this.buffer[bufIndex] |= (0x80 >>> (this.length % 8));
215
+ }
216
+
217
+ this.length++;
218
+ }
219
+ };
220
+
221
+ bitBuffer = BitBuffer;
222
+ return bitBuffer;
223
+ }
224
+
225
+ /**
226
+ * Helper class to handle QR Code symbol modules
227
+ *
228
+ * @param {Number} size Symbol size
229
+ */
230
+
231
+ var bitMatrix;
232
+ var hasRequiredBitMatrix;
233
+
234
+ function requireBitMatrix () {
235
+ if (hasRequiredBitMatrix) return bitMatrix;
236
+ hasRequiredBitMatrix = 1;
237
+ function BitMatrix (size) {
238
+ if (!size || size < 1) {
239
+ throw new Error('BitMatrix size must be defined and greater than 0')
240
+ }
241
+
242
+ this.size = size;
243
+ this.data = new Uint8Array(size * size);
244
+ this.reservedBit = new Uint8Array(size * size);
245
+ }
246
+
247
+ /**
248
+ * Set bit value at specified location
249
+ * If reserved flag is set, this bit will be ignored during masking process
250
+ *
251
+ * @param {Number} row
252
+ * @param {Number} col
253
+ * @param {Boolean} value
254
+ * @param {Boolean} reserved
255
+ */
256
+ BitMatrix.prototype.set = function (row, col, value, reserved) {
257
+ const index = row * this.size + col;
258
+ this.data[index] = value;
259
+ if (reserved) this.reservedBit[index] = true;
260
+ };
261
+
262
+ /**
263
+ * Returns bit value at specified location
264
+ *
265
+ * @param {Number} row
266
+ * @param {Number} col
267
+ * @return {Boolean}
268
+ */
269
+ BitMatrix.prototype.get = function (row, col) {
270
+ return this.data[row * this.size + col]
271
+ };
272
+
273
+ /**
274
+ * Applies xor operator at specified location
275
+ * (used during masking process)
276
+ *
277
+ * @param {Number} row
278
+ * @param {Number} col
279
+ * @param {Boolean} value
280
+ */
281
+ BitMatrix.prototype.xor = function (row, col, value) {
282
+ this.data[row * this.size + col] ^= value;
283
+ };
284
+
285
+ /**
286
+ * Check if bit at specified location is reserved
287
+ *
288
+ * @param {Number} row
289
+ * @param {Number} col
290
+ * @return {Boolean}
291
+ */
292
+ BitMatrix.prototype.isReserved = function (row, col) {
293
+ return this.reservedBit[row * this.size + col]
294
+ };
295
+
296
+ bitMatrix = BitMatrix;
297
+ return bitMatrix;
298
+ }
299
+
300
+ var alignmentPattern = {};
301
+
302
+ /**
303
+ * Alignment pattern are fixed reference pattern in defined positions
304
+ * in a matrix symbology, which enables the decode software to re-synchronise
305
+ * the coordinate mapping of the image modules in the event of moderate amounts
306
+ * of distortion of the image.
307
+ *
308
+ * Alignment patterns are present only in QR Code symbols of version 2 or larger
309
+ * and their number depends on the symbol version.
310
+ */
311
+
312
+ var hasRequiredAlignmentPattern;
313
+
314
+ function requireAlignmentPattern () {
315
+ if (hasRequiredAlignmentPattern) return alignmentPattern;
316
+ hasRequiredAlignmentPattern = 1;
317
+ (function (exports$1) {
318
+ const getSymbolSize = requireUtils$1().getSymbolSize;
319
+
320
+ /**
321
+ * Calculate the row/column coordinates of the center module of each alignment pattern
322
+ * for the specified QR Code version.
323
+ *
324
+ * The alignment patterns are positioned symmetrically on either side of the diagonal
325
+ * running from the top left corner of the symbol to the bottom right corner.
326
+ *
327
+ * Since positions are simmetrical only half of the coordinates are returned.
328
+ * Each item of the array will represent in turn the x and y coordinate.
329
+ * @see {@link getPositions}
330
+ *
331
+ * @param {Number} version QR Code version
332
+ * @return {Array} Array of coordinate
333
+ */
334
+ exports$1.getRowColCoords = function getRowColCoords (version) {
335
+ if (version === 1) return []
336
+
337
+ const posCount = Math.floor(version / 7) + 2;
338
+ const size = getSymbolSize(version);
339
+ const intervals = size === 145 ? 26 : Math.ceil((size - 13) / (2 * posCount - 2)) * 2;
340
+ const positions = [size - 7]; // Last coord is always (size - 7)
341
+
342
+ for (let i = 1; i < posCount - 1; i++) {
343
+ positions[i] = positions[i - 1] - intervals;
344
+ }
345
+
346
+ positions.push(6); // First coord is always 6
347
+
348
+ return positions.reverse()
349
+ };
350
+
351
+ /**
352
+ * Returns an array containing the positions of each alignment pattern.
353
+ * Each array's element represent the center point of the pattern as (x, y) coordinates
354
+ *
355
+ * Coordinates are calculated expanding the row/column coordinates returned by {@link getRowColCoords}
356
+ * and filtering out the items that overlaps with finder pattern
357
+ *
358
+ * @example
359
+ * For a Version 7 symbol {@link getRowColCoords} returns values 6, 22 and 38.
360
+ * The alignment patterns, therefore, are to be centered on (row, column)
361
+ * positions (6,22), (22,6), (22,22), (22,38), (38,22), (38,38).
362
+ * Note that the coordinates (6,6), (6,38), (38,6) are occupied by finder patterns
363
+ * and are not therefore used for alignment patterns.
364
+ *
365
+ * let pos = getPositions(7)
366
+ * // [[6,22], [22,6], [22,22], [22,38], [38,22], [38,38]]
367
+ *
368
+ * @param {Number} version QR Code version
369
+ * @return {Array} Array of coordinates
370
+ */
371
+ exports$1.getPositions = function getPositions (version) {
372
+ const coords = [];
373
+ const pos = exports$1.getRowColCoords(version);
374
+ const posLength = pos.length;
375
+
376
+ for (let i = 0; i < posLength; i++) {
377
+ for (let j = 0; j < posLength; j++) {
378
+ // Skip if position is occupied by finder patterns
379
+ if ((i === 0 && j === 0) || // top-left
380
+ (i === 0 && j === posLength - 1) || // bottom-left
381
+ (i === posLength - 1 && j === 0)) { // top-right
382
+ continue
383
+ }
384
+
385
+ coords.push([pos[i], pos[j]]);
386
+ }
387
+ }
388
+
389
+ return coords
390
+ };
391
+ } (alignmentPattern));
392
+ return alignmentPattern;
393
+ }
394
+
395
+ var finderPattern = {};
396
+
397
+ var hasRequiredFinderPattern;
398
+
399
+ function requireFinderPattern () {
400
+ if (hasRequiredFinderPattern) return finderPattern;
401
+ hasRequiredFinderPattern = 1;
402
+ const getSymbolSize = requireUtils$1().getSymbolSize;
403
+ const FINDER_PATTERN_SIZE = 7;
404
+
405
+ /**
406
+ * Returns an array containing the positions of each finder pattern.
407
+ * Each array's element represent the top-left point of the pattern as (x, y) coordinates
408
+ *
409
+ * @param {Number} version QR Code version
410
+ * @return {Array} Array of coordinates
411
+ */
412
+ finderPattern.getPositions = function getPositions (version) {
413
+ const size = getSymbolSize(version);
414
+
415
+ return [
416
+ // top-left
417
+ [0, 0],
418
+ // top-right
419
+ [size - FINDER_PATTERN_SIZE, 0],
420
+ // bottom-left
421
+ [0, size - FINDER_PATTERN_SIZE]
422
+ ]
423
+ };
424
+ return finderPattern;
425
+ }
426
+
427
+ var maskPattern = {};
428
+
429
+ /**
430
+ * Data mask pattern reference
431
+ * @type {Object}
432
+ */
433
+
434
+ var hasRequiredMaskPattern;
435
+
436
+ function requireMaskPattern () {
437
+ if (hasRequiredMaskPattern) return maskPattern;
438
+ hasRequiredMaskPattern = 1;
439
+ (function (exports$1) {
440
+ exports$1.Patterns = {
441
+ PATTERN000: 0,
442
+ PATTERN001: 1,
443
+ PATTERN010: 2,
444
+ PATTERN011: 3,
445
+ PATTERN100: 4,
446
+ PATTERN101: 5,
447
+ PATTERN110: 6,
448
+ PATTERN111: 7
449
+ };
450
+
451
+ /**
452
+ * Weighted penalty scores for the undesirable features
453
+ * @type {Object}
454
+ */
455
+ const PenaltyScores = {
456
+ N1: 3,
457
+ N2: 3,
458
+ N3: 40,
459
+ N4: 10
460
+ };
461
+
462
+ /**
463
+ * Check if mask pattern value is valid
464
+ *
465
+ * @param {Number} mask Mask pattern
466
+ * @return {Boolean} true if valid, false otherwise
467
+ */
468
+ exports$1.isValid = function isValid (mask) {
469
+ return mask != null && mask !== '' && !isNaN(mask) && mask >= 0 && mask <= 7
470
+ };
471
+
472
+ /**
473
+ * Returns mask pattern from a value.
474
+ * If value is not valid, returns undefined
475
+ *
476
+ * @param {Number|String} value Mask pattern value
477
+ * @return {Number} Valid mask pattern or undefined
478
+ */
479
+ exports$1.from = function from (value) {
480
+ return exports$1.isValid(value) ? parseInt(value, 10) : undefined
481
+ };
482
+
483
+ /**
484
+ * Find adjacent modules in row/column with the same color
485
+ * and assign a penalty value.
486
+ *
487
+ * Points: N1 + i
488
+ * i is the amount by which the number of adjacent modules of the same color exceeds 5
489
+ */
490
+ exports$1.getPenaltyN1 = function getPenaltyN1 (data) {
491
+ const size = data.size;
492
+ let points = 0;
493
+ let sameCountCol = 0;
494
+ let sameCountRow = 0;
495
+ let lastCol = null;
496
+ let lastRow = null;
497
+
498
+ for (let row = 0; row < size; row++) {
499
+ sameCountCol = sameCountRow = 0;
500
+ lastCol = lastRow = null;
501
+
502
+ for (let col = 0; col < size; col++) {
503
+ let module = data.get(row, col);
504
+ if (module === lastCol) {
505
+ sameCountCol++;
506
+ } else {
507
+ if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5);
508
+ lastCol = module;
509
+ sameCountCol = 1;
510
+ }
511
+
512
+ module = data.get(col, row);
513
+ if (module === lastRow) {
514
+ sameCountRow++;
515
+ } else {
516
+ if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5);
517
+ lastRow = module;
518
+ sameCountRow = 1;
519
+ }
520
+ }
521
+
522
+ if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5);
523
+ if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5);
524
+ }
525
+
526
+ return points
527
+ };
528
+
529
+ /**
530
+ * Find 2x2 blocks with the same color and assign a penalty value
531
+ *
532
+ * Points: N2 * (m - 1) * (n - 1)
533
+ */
534
+ exports$1.getPenaltyN2 = function getPenaltyN2 (data) {
535
+ const size = data.size;
536
+ let points = 0;
537
+
538
+ for (let row = 0; row < size - 1; row++) {
539
+ for (let col = 0; col < size - 1; col++) {
540
+ const last = data.get(row, col) +
541
+ data.get(row, col + 1) +
542
+ data.get(row + 1, col) +
543
+ data.get(row + 1, col + 1);
544
+
545
+ if (last === 4 || last === 0) points++;
546
+ }
547
+ }
548
+
549
+ return points * PenaltyScores.N2
550
+ };
551
+
552
+ /**
553
+ * Find 1:1:3:1:1 ratio (dark:light:dark:light:dark) pattern in row/column,
554
+ * preceded or followed by light area 4 modules wide
555
+ *
556
+ * Points: N3 * number of pattern found
557
+ */
558
+ exports$1.getPenaltyN3 = function getPenaltyN3 (data) {
559
+ const size = data.size;
560
+ let points = 0;
561
+ let bitsCol = 0;
562
+ let bitsRow = 0;
563
+
564
+ for (let row = 0; row < size; row++) {
565
+ bitsCol = bitsRow = 0;
566
+ for (let col = 0; col < size; col++) {
567
+ bitsCol = ((bitsCol << 1) & 0x7FF) | data.get(row, col);
568
+ if (col >= 10 && (bitsCol === 0x5D0 || bitsCol === 0x05D)) points++;
569
+
570
+ bitsRow = ((bitsRow << 1) & 0x7FF) | data.get(col, row);
571
+ if (col >= 10 && (bitsRow === 0x5D0 || bitsRow === 0x05D)) points++;
572
+ }
573
+ }
574
+
575
+ return points * PenaltyScores.N3
576
+ };
577
+
578
+ /**
579
+ * Calculate proportion of dark modules in entire symbol
580
+ *
581
+ * Points: N4 * k
582
+ *
583
+ * k is the rating of the deviation of the proportion of dark modules
584
+ * in the symbol from 50% in steps of 5%
585
+ */
586
+ exports$1.getPenaltyN4 = function getPenaltyN4 (data) {
587
+ let darkCount = 0;
588
+ const modulesCount = data.data.length;
589
+
590
+ for (let i = 0; i < modulesCount; i++) darkCount += data.data[i];
591
+
592
+ const k = Math.abs(Math.ceil((darkCount * 100 / modulesCount) / 5) - 10);
593
+
594
+ return k * PenaltyScores.N4
595
+ };
596
+
597
+ /**
598
+ * Return mask value at given position
599
+ *
600
+ * @param {Number} maskPattern Pattern reference value
601
+ * @param {Number} i Row
602
+ * @param {Number} j Column
603
+ * @return {Boolean} Mask value
604
+ */
605
+ function getMaskAt (maskPattern, i, j) {
606
+ switch (maskPattern) {
607
+ case exports$1.Patterns.PATTERN000: return (i + j) % 2 === 0
608
+ case exports$1.Patterns.PATTERN001: return i % 2 === 0
609
+ case exports$1.Patterns.PATTERN010: return j % 3 === 0
610
+ case exports$1.Patterns.PATTERN011: return (i + j) % 3 === 0
611
+ case exports$1.Patterns.PATTERN100: return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 === 0
612
+ case exports$1.Patterns.PATTERN101: return (i * j) % 2 + (i * j) % 3 === 0
613
+ case exports$1.Patterns.PATTERN110: return ((i * j) % 2 + (i * j) % 3) % 2 === 0
614
+ case exports$1.Patterns.PATTERN111: return ((i * j) % 3 + (i + j) % 2) % 2 === 0
615
+
616
+ default: throw new Error('bad maskPattern:' + maskPattern)
617
+ }
618
+ }
619
+
620
+ /**
621
+ * Apply a mask pattern to a BitMatrix
622
+ *
623
+ * @param {Number} pattern Pattern reference number
624
+ * @param {BitMatrix} data BitMatrix data
625
+ */
626
+ exports$1.applyMask = function applyMask (pattern, data) {
627
+ const size = data.size;
628
+
629
+ for (let col = 0; col < size; col++) {
630
+ for (let row = 0; row < size; row++) {
631
+ if (data.isReserved(row, col)) continue
632
+ data.xor(row, col, getMaskAt(pattern, row, col));
633
+ }
634
+ }
635
+ };
636
+
637
+ /**
638
+ * Returns the best mask pattern for data
639
+ *
640
+ * @param {BitMatrix} data
641
+ * @return {Number} Mask pattern reference number
642
+ */
643
+ exports$1.getBestMask = function getBestMask (data, setupFormatFunc) {
644
+ const numPatterns = Object.keys(exports$1.Patterns).length;
645
+ let bestPattern = 0;
646
+ let lowerPenalty = Infinity;
647
+
648
+ for (let p = 0; p < numPatterns; p++) {
649
+ setupFormatFunc(p);
650
+ exports$1.applyMask(p, data);
651
+
652
+ // Calculate penalty
653
+ const penalty =
654
+ exports$1.getPenaltyN1(data) +
655
+ exports$1.getPenaltyN2(data) +
656
+ exports$1.getPenaltyN3(data) +
657
+ exports$1.getPenaltyN4(data);
658
+
659
+ // Undo previously applied mask
660
+ exports$1.applyMask(p, data);
661
+
662
+ if (penalty < lowerPenalty) {
663
+ lowerPenalty = penalty;
664
+ bestPattern = p;
665
+ }
666
+ }
667
+
668
+ return bestPattern
669
+ };
670
+ } (maskPattern));
671
+ return maskPattern;
672
+ }
673
+
674
+ var errorCorrectionCode = {};
675
+
676
+ var hasRequiredErrorCorrectionCode;
677
+
678
+ function requireErrorCorrectionCode () {
679
+ if (hasRequiredErrorCorrectionCode) return errorCorrectionCode;
680
+ hasRequiredErrorCorrectionCode = 1;
681
+ const ECLevel = requireErrorCorrectionLevel();
682
+
683
+ const EC_BLOCKS_TABLE = [
684
+ // L M Q H
685
+ 1, 1, 1, 1,
686
+ 1, 1, 1, 1,
687
+ 1, 1, 2, 2,
688
+ 1, 2, 2, 4,
689
+ 1, 2, 4, 4,
690
+ 2, 4, 4, 4,
691
+ 2, 4, 6, 5,
692
+ 2, 4, 6, 6,
693
+ 2, 5, 8, 8,
694
+ 4, 5, 8, 8,
695
+ 4, 5, 8, 11,
696
+ 4, 8, 10, 11,
697
+ 4, 9, 12, 16,
698
+ 4, 9, 16, 16,
699
+ 6, 10, 12, 18,
700
+ 6, 10, 17, 16,
701
+ 6, 11, 16, 19,
702
+ 6, 13, 18, 21,
703
+ 7, 14, 21, 25,
704
+ 8, 16, 20, 25,
705
+ 8, 17, 23, 25,
706
+ 9, 17, 23, 34,
707
+ 9, 18, 25, 30,
708
+ 10, 20, 27, 32,
709
+ 12, 21, 29, 35,
710
+ 12, 23, 34, 37,
711
+ 12, 25, 34, 40,
712
+ 13, 26, 35, 42,
713
+ 14, 28, 38, 45,
714
+ 15, 29, 40, 48,
715
+ 16, 31, 43, 51,
716
+ 17, 33, 45, 54,
717
+ 18, 35, 48, 57,
718
+ 19, 37, 51, 60,
719
+ 19, 38, 53, 63,
720
+ 20, 40, 56, 66,
721
+ 21, 43, 59, 70,
722
+ 22, 45, 62, 74,
723
+ 24, 47, 65, 77,
724
+ 25, 49, 68, 81
725
+ ];
726
+
727
+ const EC_CODEWORDS_TABLE = [
728
+ // L M Q H
729
+ 7, 10, 13, 17,
730
+ 10, 16, 22, 28,
731
+ 15, 26, 36, 44,
732
+ 20, 36, 52, 64,
733
+ 26, 48, 72, 88,
734
+ 36, 64, 96, 112,
735
+ 40, 72, 108, 130,
736
+ 48, 88, 132, 156,
737
+ 60, 110, 160, 192,
738
+ 72, 130, 192, 224,
739
+ 80, 150, 224, 264,
740
+ 96, 176, 260, 308,
741
+ 104, 198, 288, 352,
742
+ 120, 216, 320, 384,
743
+ 132, 240, 360, 432,
744
+ 144, 280, 408, 480,
745
+ 168, 308, 448, 532,
746
+ 180, 338, 504, 588,
747
+ 196, 364, 546, 650,
748
+ 224, 416, 600, 700,
749
+ 224, 442, 644, 750,
750
+ 252, 476, 690, 816,
751
+ 270, 504, 750, 900,
752
+ 300, 560, 810, 960,
753
+ 312, 588, 870, 1050,
754
+ 336, 644, 952, 1110,
755
+ 360, 700, 1020, 1200,
756
+ 390, 728, 1050, 1260,
757
+ 420, 784, 1140, 1350,
758
+ 450, 812, 1200, 1440,
759
+ 480, 868, 1290, 1530,
760
+ 510, 924, 1350, 1620,
761
+ 540, 980, 1440, 1710,
762
+ 570, 1036, 1530, 1800,
763
+ 570, 1064, 1590, 1890,
764
+ 600, 1120, 1680, 1980,
765
+ 630, 1204, 1770, 2100,
766
+ 660, 1260, 1860, 2220,
767
+ 720, 1316, 1950, 2310,
768
+ 750, 1372, 2040, 2430
769
+ ];
770
+
771
+ /**
772
+ * Returns the number of error correction block that the QR Code should contain
773
+ * for the specified version and error correction level.
774
+ *
775
+ * @param {Number} version QR Code version
776
+ * @param {Number} errorCorrectionLevel Error correction level
777
+ * @return {Number} Number of error correction blocks
778
+ */
779
+ errorCorrectionCode.getBlocksCount = function getBlocksCount (version, errorCorrectionLevel) {
780
+ switch (errorCorrectionLevel) {
781
+ case ECLevel.L:
782
+ return EC_BLOCKS_TABLE[(version - 1) * 4 + 0]
783
+ case ECLevel.M:
784
+ return EC_BLOCKS_TABLE[(version - 1) * 4 + 1]
785
+ case ECLevel.Q:
786
+ return EC_BLOCKS_TABLE[(version - 1) * 4 + 2]
787
+ case ECLevel.H:
788
+ return EC_BLOCKS_TABLE[(version - 1) * 4 + 3]
789
+ default:
790
+ return undefined
791
+ }
792
+ };
793
+
794
+ /**
795
+ * Returns the number of error correction codewords to use for the specified
796
+ * version and error correction level.
797
+ *
798
+ * @param {Number} version QR Code version
799
+ * @param {Number} errorCorrectionLevel Error correction level
800
+ * @return {Number} Number of error correction codewords
801
+ */
802
+ errorCorrectionCode.getTotalCodewordsCount = function getTotalCodewordsCount (version, errorCorrectionLevel) {
803
+ switch (errorCorrectionLevel) {
804
+ case ECLevel.L:
805
+ return EC_CODEWORDS_TABLE[(version - 1) * 4 + 0]
806
+ case ECLevel.M:
807
+ return EC_CODEWORDS_TABLE[(version - 1) * 4 + 1]
808
+ case ECLevel.Q:
809
+ return EC_CODEWORDS_TABLE[(version - 1) * 4 + 2]
810
+ case ECLevel.H:
811
+ return EC_CODEWORDS_TABLE[(version - 1) * 4 + 3]
812
+ default:
813
+ return undefined
814
+ }
815
+ };
816
+ return errorCorrectionCode;
817
+ }
818
+
819
+ var polynomial = {};
820
+
821
+ var galoisField = {};
822
+
823
+ var hasRequiredGaloisField;
824
+
825
+ function requireGaloisField () {
826
+ if (hasRequiredGaloisField) return galoisField;
827
+ hasRequiredGaloisField = 1;
828
+ const EXP_TABLE = new Uint8Array(512);
829
+ const LOG_TABLE = new Uint8Array(256)
830
+ /**
831
+ * Precompute the log and anti-log tables for faster computation later
832
+ *
833
+ * For each possible value in the galois field 2^8, we will pre-compute
834
+ * the logarithm and anti-logarithm (exponential) of this value
835
+ *
836
+ * ref {@link https://en.wikiversity.org/wiki/Reed%E2%80%93Solomon_codes_for_coders#Introduction_to_mathematical_fields}
837
+ */
838
+ ;(function initTables () {
839
+ let x = 1;
840
+ for (let i = 0; i < 255; i++) {
841
+ EXP_TABLE[i] = x;
842
+ LOG_TABLE[x] = i;
843
+
844
+ x <<= 1; // multiply by 2
845
+
846
+ // The QR code specification says to use byte-wise modulo 100011101 arithmetic.
847
+ // This means that when a number is 256 or larger, it should be XORed with 0x11D.
848
+ if (x & 0x100) { // similar to x >= 256, but a lot faster (because 0x100 == 256)
849
+ x ^= 0x11D;
850
+ }
851
+ }
852
+
853
+ // Optimization: double the size of the anti-log table so that we don't need to mod 255 to
854
+ // stay inside the bounds (because we will mainly use this table for the multiplication of
855
+ // two GF numbers, no more).
856
+ // @see {@link mul}
857
+ for (let i = 255; i < 512; i++) {
858
+ EXP_TABLE[i] = EXP_TABLE[i - 255];
859
+ }
860
+ }());
861
+
862
+ /**
863
+ * Returns log value of n inside Galois Field
864
+ *
865
+ * @param {Number} n
866
+ * @return {Number}
867
+ */
868
+ galoisField.log = function log (n) {
869
+ if (n < 1) throw new Error('log(' + n + ')')
870
+ return LOG_TABLE[n]
871
+ };
872
+
873
+ /**
874
+ * Returns anti-log value of n inside Galois Field
875
+ *
876
+ * @param {Number} n
877
+ * @return {Number}
878
+ */
879
+ galoisField.exp = function exp (n) {
880
+ return EXP_TABLE[n]
881
+ };
882
+
883
+ /**
884
+ * Multiplies two number inside Galois Field
885
+ *
886
+ * @param {Number} x
887
+ * @param {Number} y
888
+ * @return {Number}
889
+ */
890
+ galoisField.mul = function mul (x, y) {
891
+ if (x === 0 || y === 0) return 0
892
+
893
+ // should be EXP_TABLE[(LOG_TABLE[x] + LOG_TABLE[y]) % 255] if EXP_TABLE wasn't oversized
894
+ // @see {@link initTables}
895
+ return EXP_TABLE[LOG_TABLE[x] + LOG_TABLE[y]]
896
+ };
897
+ return galoisField;
898
+ }
899
+
900
+ var hasRequiredPolynomial;
901
+
902
+ function requirePolynomial () {
903
+ if (hasRequiredPolynomial) return polynomial;
904
+ hasRequiredPolynomial = 1;
905
+ (function (exports$1) {
906
+ const GF = requireGaloisField();
907
+
908
+ /**
909
+ * Multiplies two polynomials inside Galois Field
910
+ *
911
+ * @param {Uint8Array} p1 Polynomial
912
+ * @param {Uint8Array} p2 Polynomial
913
+ * @return {Uint8Array} Product of p1 and p2
914
+ */
915
+ exports$1.mul = function mul (p1, p2) {
916
+ const coeff = new Uint8Array(p1.length + p2.length - 1);
917
+
918
+ for (let i = 0; i < p1.length; i++) {
919
+ for (let j = 0; j < p2.length; j++) {
920
+ coeff[i + j] ^= GF.mul(p1[i], p2[j]);
921
+ }
922
+ }
923
+
924
+ return coeff
925
+ };
926
+
927
+ /**
928
+ * Calculate the remainder of polynomials division
929
+ *
930
+ * @param {Uint8Array} divident Polynomial
931
+ * @param {Uint8Array} divisor Polynomial
932
+ * @return {Uint8Array} Remainder
933
+ */
934
+ exports$1.mod = function mod (divident, divisor) {
935
+ let result = new Uint8Array(divident);
936
+
937
+ while ((result.length - divisor.length) >= 0) {
938
+ const coeff = result[0];
939
+
940
+ for (let i = 0; i < divisor.length; i++) {
941
+ result[i] ^= GF.mul(divisor[i], coeff);
942
+ }
943
+
944
+ // remove all zeros from buffer head
945
+ let offset = 0;
946
+ while (offset < result.length && result[offset] === 0) offset++;
947
+ result = result.slice(offset);
948
+ }
949
+
950
+ return result
951
+ };
952
+
953
+ /**
954
+ * Generate an irreducible generator polynomial of specified degree
955
+ * (used by Reed-Solomon encoder)
956
+ *
957
+ * @param {Number} degree Degree of the generator polynomial
958
+ * @return {Uint8Array} Buffer containing polynomial coefficients
959
+ */
960
+ exports$1.generateECPolynomial = function generateECPolynomial (degree) {
961
+ let poly = new Uint8Array([1]);
962
+ for (let i = 0; i < degree; i++) {
963
+ poly = exports$1.mul(poly, new Uint8Array([1, GF.exp(i)]));
964
+ }
965
+
966
+ return poly
967
+ };
968
+ } (polynomial));
969
+ return polynomial;
970
+ }
971
+
972
+ var reedSolomonEncoder;
973
+ var hasRequiredReedSolomonEncoder;
974
+
975
+ function requireReedSolomonEncoder () {
976
+ if (hasRequiredReedSolomonEncoder) return reedSolomonEncoder;
977
+ hasRequiredReedSolomonEncoder = 1;
978
+ const Polynomial = requirePolynomial();
979
+
980
+ function ReedSolomonEncoder (degree) {
981
+ this.genPoly = undefined;
982
+ this.degree = degree;
983
+
984
+ if (this.degree) this.initialize(this.degree);
985
+ }
986
+
987
+ /**
988
+ * Initialize the encoder.
989
+ * The input param should correspond to the number of error correction codewords.
990
+ *
991
+ * @param {Number} degree
992
+ */
993
+ ReedSolomonEncoder.prototype.initialize = function initialize (degree) {
994
+ // create an irreducible generator polynomial
995
+ this.degree = degree;
996
+ this.genPoly = Polynomial.generateECPolynomial(this.degree);
997
+ };
998
+
999
+ /**
1000
+ * Encodes a chunk of data
1001
+ *
1002
+ * @param {Uint8Array} data Buffer containing input data
1003
+ * @return {Uint8Array} Buffer containing encoded data
1004
+ */
1005
+ ReedSolomonEncoder.prototype.encode = function encode (data) {
1006
+ if (!this.genPoly) {
1007
+ throw new Error('Encoder not initialized')
1008
+ }
1009
+
1010
+ // Calculate EC for this data block
1011
+ // extends data size to data+genPoly size
1012
+ const paddedData = new Uint8Array(data.length + this.degree);
1013
+ paddedData.set(data);
1014
+
1015
+ // The error correction codewords are the remainder after dividing the data codewords
1016
+ // by a generator polynomial
1017
+ const remainder = Polynomial.mod(paddedData, this.genPoly);
1018
+
1019
+ // return EC data blocks (last n byte, where n is the degree of genPoly)
1020
+ // If coefficients number in remainder are less than genPoly degree,
1021
+ // pad with 0s to the left to reach the needed number of coefficients
1022
+ const start = this.degree - remainder.length;
1023
+ if (start > 0) {
1024
+ const buff = new Uint8Array(this.degree);
1025
+ buff.set(remainder, start);
1026
+
1027
+ return buff
1028
+ }
1029
+
1030
+ return remainder
1031
+ };
1032
+
1033
+ reedSolomonEncoder = ReedSolomonEncoder;
1034
+ return reedSolomonEncoder;
1035
+ }
1036
+
1037
+ var version = {};
1038
+
1039
+ var mode = {};
1040
+
1041
+ var versionCheck = {};
1042
+
1043
+ /**
1044
+ * Check if QR Code version is valid
1045
+ *
1046
+ * @param {Number} version QR Code version
1047
+ * @return {Boolean} true if valid version, false otherwise
1048
+ */
1049
+
1050
+ var hasRequiredVersionCheck;
1051
+
1052
+ function requireVersionCheck () {
1053
+ if (hasRequiredVersionCheck) return versionCheck;
1054
+ hasRequiredVersionCheck = 1;
1055
+ versionCheck.isValid = function isValid (version) {
1056
+ return !isNaN(version) && version >= 1 && version <= 40
1057
+ };
1058
+ return versionCheck;
1059
+ }
1060
+
1061
+ var regex = {};
1062
+
1063
+ var hasRequiredRegex;
1064
+
1065
+ function requireRegex () {
1066
+ if (hasRequiredRegex) return regex;
1067
+ hasRequiredRegex = 1;
1068
+ const numeric = '[0-9]+';
1069
+ const alphanumeric = '[A-Z $%*+\\-./:]+';
1070
+ let kanji = '(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|' +
1071
+ '[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|' +
1072
+ '[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|' +
1073
+ '[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+';
1074
+ kanji = kanji.replace(/u/g, '\\u');
1075
+
1076
+ const byte = '(?:(?![A-Z0-9 $%*+\\-./:]|' + kanji + ')(?:.|[\r\n]))+';
1077
+
1078
+ regex.KANJI = new RegExp(kanji, 'g');
1079
+ regex.BYTE_KANJI = new RegExp('[^A-Z0-9 $%*+\\-./:]+', 'g');
1080
+ regex.BYTE = new RegExp(byte, 'g');
1081
+ regex.NUMERIC = new RegExp(numeric, 'g');
1082
+ regex.ALPHANUMERIC = new RegExp(alphanumeric, 'g');
1083
+
1084
+ const TEST_KANJI = new RegExp('^' + kanji + '$');
1085
+ const TEST_NUMERIC = new RegExp('^' + numeric + '$');
1086
+ const TEST_ALPHANUMERIC = new RegExp('^[A-Z0-9 $%*+\\-./:]+$');
1087
+
1088
+ regex.testKanji = function testKanji (str) {
1089
+ return TEST_KANJI.test(str)
1090
+ };
1091
+
1092
+ regex.testNumeric = function testNumeric (str) {
1093
+ return TEST_NUMERIC.test(str)
1094
+ };
1095
+
1096
+ regex.testAlphanumeric = function testAlphanumeric (str) {
1097
+ return TEST_ALPHANUMERIC.test(str)
1098
+ };
1099
+ return regex;
1100
+ }
1101
+
1102
+ var hasRequiredMode;
1103
+
1104
+ function requireMode () {
1105
+ if (hasRequiredMode) return mode;
1106
+ hasRequiredMode = 1;
1107
+ (function (exports$1) {
1108
+ const VersionCheck = requireVersionCheck();
1109
+ const Regex = requireRegex();
1110
+
1111
+ /**
1112
+ * Numeric mode encodes data from the decimal digit set (0 - 9)
1113
+ * (byte values 30HEX to 39HEX).
1114
+ * Normally, 3 data characters are represented by 10 bits.
1115
+ *
1116
+ * @type {Object}
1117
+ */
1118
+ exports$1.NUMERIC = {
1119
+ id: 'Numeric',
1120
+ bit: 1 << 0,
1121
+ ccBits: [10, 12, 14]
1122
+ };
1123
+
1124
+ /**
1125
+ * Alphanumeric mode encodes data from a set of 45 characters,
1126
+ * i.e. 10 numeric digits (0 - 9),
1127
+ * 26 alphabetic characters (A - Z),
1128
+ * and 9 symbols (SP, $, %, *, +, -, ., /, :).
1129
+ * Normally, two input characters are represented by 11 bits.
1130
+ *
1131
+ * @type {Object}
1132
+ */
1133
+ exports$1.ALPHANUMERIC = {
1134
+ id: 'Alphanumeric',
1135
+ bit: 1 << 1,
1136
+ ccBits: [9, 11, 13]
1137
+ };
1138
+
1139
+ /**
1140
+ * In byte mode, data is encoded at 8 bits per character.
1141
+ *
1142
+ * @type {Object}
1143
+ */
1144
+ exports$1.BYTE = {
1145
+ id: 'Byte',
1146
+ bit: 1 << 2,
1147
+ ccBits: [8, 16, 16]
1148
+ };
1149
+
1150
+ /**
1151
+ * The Kanji mode efficiently encodes Kanji characters in accordance with
1152
+ * the Shift JIS system based on JIS X 0208.
1153
+ * The Shift JIS values are shifted from the JIS X 0208 values.
1154
+ * JIS X 0208 gives details of the shift coded representation.
1155
+ * Each two-byte character value is compacted to a 13-bit binary codeword.
1156
+ *
1157
+ * @type {Object}
1158
+ */
1159
+ exports$1.KANJI = {
1160
+ id: 'Kanji',
1161
+ bit: 1 << 3,
1162
+ ccBits: [8, 10, 12]
1163
+ };
1164
+
1165
+ /**
1166
+ * Mixed mode will contain a sequences of data in a combination of any of
1167
+ * the modes described above
1168
+ *
1169
+ * @type {Object}
1170
+ */
1171
+ exports$1.MIXED = {
1172
+ bit: -1
1173
+ };
1174
+
1175
+ /**
1176
+ * Returns the number of bits needed to store the data length
1177
+ * according to QR Code specifications.
1178
+ *
1179
+ * @param {Mode} mode Data mode
1180
+ * @param {Number} version QR Code version
1181
+ * @return {Number} Number of bits
1182
+ */
1183
+ exports$1.getCharCountIndicator = function getCharCountIndicator (mode, version) {
1184
+ if (!mode.ccBits) throw new Error('Invalid mode: ' + mode)
1185
+
1186
+ if (!VersionCheck.isValid(version)) {
1187
+ throw new Error('Invalid version: ' + version)
1188
+ }
1189
+
1190
+ if (version >= 1 && version < 10) return mode.ccBits[0]
1191
+ else if (version < 27) return mode.ccBits[1]
1192
+ return mode.ccBits[2]
1193
+ };
1194
+
1195
+ /**
1196
+ * Returns the most efficient mode to store the specified data
1197
+ *
1198
+ * @param {String} dataStr Input data string
1199
+ * @return {Mode} Best mode
1200
+ */
1201
+ exports$1.getBestModeForData = function getBestModeForData (dataStr) {
1202
+ if (Regex.testNumeric(dataStr)) return exports$1.NUMERIC
1203
+ else if (Regex.testAlphanumeric(dataStr)) return exports$1.ALPHANUMERIC
1204
+ else if (Regex.testKanji(dataStr)) return exports$1.KANJI
1205
+ else return exports$1.BYTE
1206
+ };
1207
+
1208
+ /**
1209
+ * Return mode name as string
1210
+ *
1211
+ * @param {Mode} mode Mode object
1212
+ * @returns {String} Mode name
1213
+ */
1214
+ exports$1.toString = function toString (mode) {
1215
+ if (mode && mode.id) return mode.id
1216
+ throw new Error('Invalid mode')
1217
+ };
1218
+
1219
+ /**
1220
+ * Check if input param is a valid mode object
1221
+ *
1222
+ * @param {Mode} mode Mode object
1223
+ * @returns {Boolean} True if valid mode, false otherwise
1224
+ */
1225
+ exports$1.isValid = function isValid (mode) {
1226
+ return mode && mode.bit && mode.ccBits
1227
+ };
1228
+
1229
+ /**
1230
+ * Get mode object from its name
1231
+ *
1232
+ * @param {String} string Mode name
1233
+ * @returns {Mode} Mode object
1234
+ */
1235
+ function fromString (string) {
1236
+ if (typeof string !== 'string') {
1237
+ throw new Error('Param is not a string')
1238
+ }
1239
+
1240
+ const lcStr = string.toLowerCase();
1241
+
1242
+ switch (lcStr) {
1243
+ case 'numeric':
1244
+ return exports$1.NUMERIC
1245
+ case 'alphanumeric':
1246
+ return exports$1.ALPHANUMERIC
1247
+ case 'kanji':
1248
+ return exports$1.KANJI
1249
+ case 'byte':
1250
+ return exports$1.BYTE
1251
+ default:
1252
+ throw new Error('Unknown mode: ' + string)
1253
+ }
1254
+ }
1255
+
1256
+ /**
1257
+ * Returns mode from a value.
1258
+ * If value is not a valid mode, returns defaultValue
1259
+ *
1260
+ * @param {Mode|String} value Encoding mode
1261
+ * @param {Mode} defaultValue Fallback value
1262
+ * @return {Mode} Encoding mode
1263
+ */
1264
+ exports$1.from = function from (value, defaultValue) {
1265
+ if (exports$1.isValid(value)) {
1266
+ return value
1267
+ }
1268
+
1269
+ try {
1270
+ return fromString(value)
1271
+ } catch (e) {
1272
+ return defaultValue
1273
+ }
1274
+ };
1275
+ } (mode));
1276
+ return mode;
1277
+ }
1278
+
1279
+ var hasRequiredVersion;
1280
+
1281
+ function requireVersion () {
1282
+ if (hasRequiredVersion) return version;
1283
+ hasRequiredVersion = 1;
1284
+ (function (exports$1) {
1285
+ const Utils = requireUtils$1();
1286
+ const ECCode = requireErrorCorrectionCode();
1287
+ const ECLevel = requireErrorCorrectionLevel();
1288
+ const Mode = requireMode();
1289
+ const VersionCheck = requireVersionCheck();
1290
+
1291
+ // Generator polynomial used to encode version information
1292
+ const G18 = (1 << 12) | (1 << 11) | (1 << 10) | (1 << 9) | (1 << 8) | (1 << 5) | (1 << 2) | (1 << 0);
1293
+ const G18_BCH = Utils.getBCHDigit(G18);
1294
+
1295
+ function getBestVersionForDataLength (mode, length, errorCorrectionLevel) {
1296
+ for (let currentVersion = 1; currentVersion <= 40; currentVersion++) {
1297
+ if (length <= exports$1.getCapacity(currentVersion, errorCorrectionLevel, mode)) {
1298
+ return currentVersion
1299
+ }
1300
+ }
1301
+
1302
+ return undefined
1303
+ }
1304
+
1305
+ function getReservedBitsCount (mode, version) {
1306
+ // Character count indicator + mode indicator bits
1307
+ return Mode.getCharCountIndicator(mode, version) + 4
1308
+ }
1309
+
1310
+ function getTotalBitsFromDataArray (segments, version) {
1311
+ let totalBits = 0;
1312
+
1313
+ segments.forEach(function (data) {
1314
+ const reservedBits = getReservedBitsCount(data.mode, version);
1315
+ totalBits += reservedBits + data.getBitsLength();
1316
+ });
1317
+
1318
+ return totalBits
1319
+ }
1320
+
1321
+ function getBestVersionForMixedData (segments, errorCorrectionLevel) {
1322
+ for (let currentVersion = 1; currentVersion <= 40; currentVersion++) {
1323
+ const length = getTotalBitsFromDataArray(segments, currentVersion);
1324
+ if (length <= exports$1.getCapacity(currentVersion, errorCorrectionLevel, Mode.MIXED)) {
1325
+ return currentVersion
1326
+ }
1327
+ }
1328
+
1329
+ return undefined
1330
+ }
1331
+
1332
+ /**
1333
+ * Returns version number from a value.
1334
+ * If value is not a valid version, returns defaultValue
1335
+ *
1336
+ * @param {Number|String} value QR Code version
1337
+ * @param {Number} defaultValue Fallback value
1338
+ * @return {Number} QR Code version number
1339
+ */
1340
+ exports$1.from = function from (value, defaultValue) {
1341
+ if (VersionCheck.isValid(value)) {
1342
+ return parseInt(value, 10)
1343
+ }
1344
+
1345
+ return defaultValue
1346
+ };
1347
+
1348
+ /**
1349
+ * Returns how much data can be stored with the specified QR code version
1350
+ * and error correction level
1351
+ *
1352
+ * @param {Number} version QR Code version (1-40)
1353
+ * @param {Number} errorCorrectionLevel Error correction level
1354
+ * @param {Mode} mode Data mode
1355
+ * @return {Number} Quantity of storable data
1356
+ */
1357
+ exports$1.getCapacity = function getCapacity (version, errorCorrectionLevel, mode) {
1358
+ if (!VersionCheck.isValid(version)) {
1359
+ throw new Error('Invalid QR Code version')
1360
+ }
1361
+
1362
+ // Use Byte mode as default
1363
+ if (typeof mode === 'undefined') mode = Mode.BYTE;
1364
+
1365
+ // Total codewords for this QR code version (Data + Error correction)
1366
+ const totalCodewords = Utils.getSymbolTotalCodewords(version);
1367
+
1368
+ // Total number of error correction codewords
1369
+ const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
1370
+
1371
+ // Total number of data codewords
1372
+ const dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8;
1373
+
1374
+ if (mode === Mode.MIXED) return dataTotalCodewordsBits
1375
+
1376
+ const usableBits = dataTotalCodewordsBits - getReservedBitsCount(mode, version);
1377
+
1378
+ // Return max number of storable codewords
1379
+ switch (mode) {
1380
+ case Mode.NUMERIC:
1381
+ return Math.floor((usableBits / 10) * 3)
1382
+
1383
+ case Mode.ALPHANUMERIC:
1384
+ return Math.floor((usableBits / 11) * 2)
1385
+
1386
+ case Mode.KANJI:
1387
+ return Math.floor(usableBits / 13)
1388
+
1389
+ case Mode.BYTE:
1390
+ default:
1391
+ return Math.floor(usableBits / 8)
1392
+ }
1393
+ };
1394
+
1395
+ /**
1396
+ * Returns the minimum version needed to contain the amount of data
1397
+ *
1398
+ * @param {Segment} data Segment of data
1399
+ * @param {Number} [errorCorrectionLevel=H] Error correction level
1400
+ * @param {Mode} mode Data mode
1401
+ * @return {Number} QR Code version
1402
+ */
1403
+ exports$1.getBestVersionForData = function getBestVersionForData (data, errorCorrectionLevel) {
1404
+ let seg;
1405
+
1406
+ const ecl = ECLevel.from(errorCorrectionLevel, ECLevel.M);
1407
+
1408
+ if (Array.isArray(data)) {
1409
+ if (data.length > 1) {
1410
+ return getBestVersionForMixedData(data, ecl)
1411
+ }
1412
+
1413
+ if (data.length === 0) {
1414
+ return 1
1415
+ }
1416
+
1417
+ seg = data[0];
1418
+ } else {
1419
+ seg = data;
1420
+ }
1421
+
1422
+ return getBestVersionForDataLength(seg.mode, seg.getLength(), ecl)
1423
+ };
1424
+
1425
+ /**
1426
+ * Returns version information with relative error correction bits
1427
+ *
1428
+ * The version information is included in QR Code symbols of version 7 or larger.
1429
+ * It consists of an 18-bit sequence containing 6 data bits,
1430
+ * with 12 error correction bits calculated using the (18, 6) Golay code.
1431
+ *
1432
+ * @param {Number} version QR Code version
1433
+ * @return {Number} Encoded version info bits
1434
+ */
1435
+ exports$1.getEncodedBits = function getEncodedBits (version) {
1436
+ if (!VersionCheck.isValid(version) || version < 7) {
1437
+ throw new Error('Invalid QR Code version')
1438
+ }
1439
+
1440
+ let d = version << 12;
1441
+
1442
+ while (Utils.getBCHDigit(d) - G18_BCH >= 0) {
1443
+ d ^= (G18 << (Utils.getBCHDigit(d) - G18_BCH));
1444
+ }
1445
+
1446
+ return (version << 12) | d
1447
+ };
1448
+ } (version));
1449
+ return version;
1450
+ }
1451
+
1452
+ var formatInfo = {};
1453
+
1454
+ var hasRequiredFormatInfo;
1455
+
1456
+ function requireFormatInfo () {
1457
+ if (hasRequiredFormatInfo) return formatInfo;
1458
+ hasRequiredFormatInfo = 1;
1459
+ const Utils = requireUtils$1();
1460
+
1461
+ const G15 = (1 << 10) | (1 << 8) | (1 << 5) | (1 << 4) | (1 << 2) | (1 << 1) | (1 << 0);
1462
+ const G15_MASK = (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1);
1463
+ const G15_BCH = Utils.getBCHDigit(G15);
1464
+
1465
+ /**
1466
+ * Returns format information with relative error correction bits
1467
+ *
1468
+ * The format information is a 15-bit sequence containing 5 data bits,
1469
+ * with 10 error correction bits calculated using the (15, 5) BCH code.
1470
+ *
1471
+ * @param {Number} errorCorrectionLevel Error correction level
1472
+ * @param {Number} mask Mask pattern
1473
+ * @return {Number} Encoded format information bits
1474
+ */
1475
+ formatInfo.getEncodedBits = function getEncodedBits (errorCorrectionLevel, mask) {
1476
+ const data = ((errorCorrectionLevel.bit << 3) | mask);
1477
+ let d = data << 10;
1478
+
1479
+ while (Utils.getBCHDigit(d) - G15_BCH >= 0) {
1480
+ d ^= (G15 << (Utils.getBCHDigit(d) - G15_BCH));
1481
+ }
1482
+
1483
+ // xor final data with mask pattern in order to ensure that
1484
+ // no combination of Error Correction Level and data mask pattern
1485
+ // will result in an all-zero data string
1486
+ return ((data << 10) | d) ^ G15_MASK
1487
+ };
1488
+ return formatInfo;
1489
+ }
1490
+
1491
+ var segments = {};
1492
+
1493
+ var numericData;
1494
+ var hasRequiredNumericData;
1495
+
1496
+ function requireNumericData () {
1497
+ if (hasRequiredNumericData) return numericData;
1498
+ hasRequiredNumericData = 1;
1499
+ const Mode = requireMode();
1500
+
1501
+ function NumericData (data) {
1502
+ this.mode = Mode.NUMERIC;
1503
+ this.data = data.toString();
1504
+ }
1505
+
1506
+ NumericData.getBitsLength = function getBitsLength (length) {
1507
+ return 10 * Math.floor(length / 3) + ((length % 3) ? ((length % 3) * 3 + 1) : 0)
1508
+ };
1509
+
1510
+ NumericData.prototype.getLength = function getLength () {
1511
+ return this.data.length
1512
+ };
1513
+
1514
+ NumericData.prototype.getBitsLength = function getBitsLength () {
1515
+ return NumericData.getBitsLength(this.data.length)
1516
+ };
1517
+
1518
+ NumericData.prototype.write = function write (bitBuffer) {
1519
+ let i, group, value;
1520
+
1521
+ // The input data string is divided into groups of three digits,
1522
+ // and each group is converted to its 10-bit binary equivalent.
1523
+ for (i = 0; i + 3 <= this.data.length; i += 3) {
1524
+ group = this.data.substr(i, 3);
1525
+ value = parseInt(group, 10);
1526
+
1527
+ bitBuffer.put(value, 10);
1528
+ }
1529
+
1530
+ // If the number of input digits is not an exact multiple of three,
1531
+ // the final one or two digits are converted to 4 or 7 bits respectively.
1532
+ const remainingNum = this.data.length - i;
1533
+ if (remainingNum > 0) {
1534
+ group = this.data.substr(i);
1535
+ value = parseInt(group, 10);
1536
+
1537
+ bitBuffer.put(value, remainingNum * 3 + 1);
1538
+ }
1539
+ };
1540
+
1541
+ numericData = NumericData;
1542
+ return numericData;
1543
+ }
1544
+
1545
+ var alphanumericData;
1546
+ var hasRequiredAlphanumericData;
1547
+
1548
+ function requireAlphanumericData () {
1549
+ if (hasRequiredAlphanumericData) return alphanumericData;
1550
+ hasRequiredAlphanumericData = 1;
1551
+ const Mode = requireMode();
1552
+
1553
+ /**
1554
+ * Array of characters available in alphanumeric mode
1555
+ *
1556
+ * As per QR Code specification, to each character
1557
+ * is assigned a value from 0 to 44 which in this case coincides
1558
+ * with the array index
1559
+ *
1560
+ * @type {Array}
1561
+ */
1562
+ const ALPHA_NUM_CHARS = [
1563
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
1564
+ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
1565
+ 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
1566
+ ' ', '$', '%', '*', '+', '-', '.', '/', ':'
1567
+ ];
1568
+
1569
+ function AlphanumericData (data) {
1570
+ this.mode = Mode.ALPHANUMERIC;
1571
+ this.data = data;
1572
+ }
1573
+
1574
+ AlphanumericData.getBitsLength = function getBitsLength (length) {
1575
+ return 11 * Math.floor(length / 2) + 6 * (length % 2)
1576
+ };
1577
+
1578
+ AlphanumericData.prototype.getLength = function getLength () {
1579
+ return this.data.length
1580
+ };
1581
+
1582
+ AlphanumericData.prototype.getBitsLength = function getBitsLength () {
1583
+ return AlphanumericData.getBitsLength(this.data.length)
1584
+ };
1585
+
1586
+ AlphanumericData.prototype.write = function write (bitBuffer) {
1587
+ let i;
1588
+
1589
+ // Input data characters are divided into groups of two characters
1590
+ // and encoded as 11-bit binary codes.
1591
+ for (i = 0; i + 2 <= this.data.length; i += 2) {
1592
+ // The character value of the first character is multiplied by 45
1593
+ let value = ALPHA_NUM_CHARS.indexOf(this.data[i]) * 45;
1594
+
1595
+ // The character value of the second digit is added to the product
1596
+ value += ALPHA_NUM_CHARS.indexOf(this.data[i + 1]);
1597
+
1598
+ // The sum is then stored as 11-bit binary number
1599
+ bitBuffer.put(value, 11);
1600
+ }
1601
+
1602
+ // If the number of input data characters is not a multiple of two,
1603
+ // the character value of the final character is encoded as a 6-bit binary number.
1604
+ if (this.data.length % 2) {
1605
+ bitBuffer.put(ALPHA_NUM_CHARS.indexOf(this.data[i]), 6);
1606
+ }
1607
+ };
1608
+
1609
+ alphanumericData = AlphanumericData;
1610
+ return alphanumericData;
1611
+ }
1612
+
1613
+ var byteData;
1614
+ var hasRequiredByteData;
1615
+
1616
+ function requireByteData () {
1617
+ if (hasRequiredByteData) return byteData;
1618
+ hasRequiredByteData = 1;
1619
+ const Mode = requireMode();
1620
+
1621
+ function ByteData (data) {
1622
+ this.mode = Mode.BYTE;
1623
+ if (typeof (data) === 'string') {
1624
+ this.data = new TextEncoder().encode(data);
1625
+ } else {
1626
+ this.data = new Uint8Array(data);
1627
+ }
1628
+ }
1629
+
1630
+ ByteData.getBitsLength = function getBitsLength (length) {
1631
+ return length * 8
1632
+ };
1633
+
1634
+ ByteData.prototype.getLength = function getLength () {
1635
+ return this.data.length
1636
+ };
1637
+
1638
+ ByteData.prototype.getBitsLength = function getBitsLength () {
1639
+ return ByteData.getBitsLength(this.data.length)
1640
+ };
1641
+
1642
+ ByteData.prototype.write = function (bitBuffer) {
1643
+ for (let i = 0, l = this.data.length; i < l; i++) {
1644
+ bitBuffer.put(this.data[i], 8);
1645
+ }
1646
+ };
1647
+
1648
+ byteData = ByteData;
1649
+ return byteData;
1650
+ }
1651
+
1652
+ var kanjiData;
1653
+ var hasRequiredKanjiData;
1654
+
1655
+ function requireKanjiData () {
1656
+ if (hasRequiredKanjiData) return kanjiData;
1657
+ hasRequiredKanjiData = 1;
1658
+ const Mode = requireMode();
1659
+ const Utils = requireUtils$1();
1660
+
1661
+ function KanjiData (data) {
1662
+ this.mode = Mode.KANJI;
1663
+ this.data = data;
1664
+ }
1665
+
1666
+ KanjiData.getBitsLength = function getBitsLength (length) {
1667
+ return length * 13
1668
+ };
1669
+
1670
+ KanjiData.prototype.getLength = function getLength () {
1671
+ return this.data.length
1672
+ };
1673
+
1674
+ KanjiData.prototype.getBitsLength = function getBitsLength () {
1675
+ return KanjiData.getBitsLength(this.data.length)
1676
+ };
1677
+
1678
+ KanjiData.prototype.write = function (bitBuffer) {
1679
+ let i;
1680
+
1681
+ // In the Shift JIS system, Kanji characters are represented by a two byte combination.
1682
+ // These byte values are shifted from the JIS X 0208 values.
1683
+ // JIS X 0208 gives details of the shift coded representation.
1684
+ for (i = 0; i < this.data.length; i++) {
1685
+ let value = Utils.toSJIS(this.data[i]);
1686
+
1687
+ // For characters with Shift JIS values from 0x8140 to 0x9FFC:
1688
+ if (value >= 0x8140 && value <= 0x9FFC) {
1689
+ // Subtract 0x8140 from Shift JIS value
1690
+ value -= 0x8140;
1691
+
1692
+ // For characters with Shift JIS values from 0xE040 to 0xEBBF
1693
+ } else if (value >= 0xE040 && value <= 0xEBBF) {
1694
+ // Subtract 0xC140 from Shift JIS value
1695
+ value -= 0xC140;
1696
+ } else {
1697
+ throw new Error(
1698
+ 'Invalid SJIS character: ' + this.data[i] + '\n' +
1699
+ 'Make sure your charset is UTF-8')
1700
+ }
1701
+
1702
+ // Multiply most significant byte of result by 0xC0
1703
+ // and add least significant byte to product
1704
+ value = (((value >>> 8) & 0xff) * 0xC0) + (value & 0xff);
1705
+
1706
+ // Convert result to a 13-bit binary string
1707
+ bitBuffer.put(value, 13);
1708
+ }
1709
+ };
1710
+
1711
+ kanjiData = KanjiData;
1712
+ return kanjiData;
1713
+ }
1714
+
1715
+ var dijkstra = {exports: {}};
1716
+
1717
+ var hasRequiredDijkstra;
1718
+
1719
+ function requireDijkstra () {
1720
+ if (hasRequiredDijkstra) return dijkstra.exports;
1721
+ hasRequiredDijkstra = 1;
1722
+ (function (module) {
1723
+
1724
+ /******************************************************************************
1725
+ * Created 2008-08-19.
1726
+ *
1727
+ * Dijkstra path-finding functions. Adapted from the Dijkstar Python project.
1728
+ *
1729
+ * Copyright (C) 2008
1730
+ * Wyatt Baldwin <self@wyattbaldwin.com>
1731
+ * All rights reserved
1732
+ *
1733
+ * Licensed under the MIT license.
1734
+ *
1735
+ * http://www.opensource.org/licenses/mit-license.php
1736
+ *
1737
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1738
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1739
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1740
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1741
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1742
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1743
+ * THE SOFTWARE.
1744
+ *****************************************************************************/
1745
+ var dijkstra = {
1746
+ single_source_shortest_paths: function(graph, s, d) {
1747
+ // Predecessor map for each node that has been encountered.
1748
+ // node ID => predecessor node ID
1749
+ var predecessors = {};
1750
+
1751
+ // Costs of shortest paths from s to all nodes encountered.
1752
+ // node ID => cost
1753
+ var costs = {};
1754
+ costs[s] = 0;
1755
+
1756
+ // Costs of shortest paths from s to all nodes encountered; differs from
1757
+ // `costs` in that it provides easy access to the node that currently has
1758
+ // the known shortest path from s.
1759
+ // XXX: Do we actually need both `costs` and `open`?
1760
+ var open = dijkstra.PriorityQueue.make();
1761
+ open.push(s, 0);
1762
+
1763
+ var closest,
1764
+ u, v,
1765
+ cost_of_s_to_u,
1766
+ adjacent_nodes,
1767
+ cost_of_e,
1768
+ cost_of_s_to_u_plus_cost_of_e,
1769
+ cost_of_s_to_v,
1770
+ first_visit;
1771
+ while (!open.empty()) {
1772
+ // In the nodes remaining in graph that have a known cost from s,
1773
+ // find the node, u, that currently has the shortest path from s.
1774
+ closest = open.pop();
1775
+ u = closest.value;
1776
+ cost_of_s_to_u = closest.cost;
1777
+
1778
+ // Get nodes adjacent to u...
1779
+ adjacent_nodes = graph[u] || {};
1780
+
1781
+ // ...and explore the edges that connect u to those nodes, updating
1782
+ // the cost of the shortest paths to any or all of those nodes as
1783
+ // necessary. v is the node across the current edge from u.
1784
+ for (v in adjacent_nodes) {
1785
+ if (adjacent_nodes.hasOwnProperty(v)) {
1786
+ // Get the cost of the edge running from u to v.
1787
+ cost_of_e = adjacent_nodes[v];
1788
+
1789
+ // Cost of s to u plus the cost of u to v across e--this is *a*
1790
+ // cost from s to v that may or may not be less than the current
1791
+ // known cost to v.
1792
+ cost_of_s_to_u_plus_cost_of_e = cost_of_s_to_u + cost_of_e;
1793
+
1794
+ // If we haven't visited v yet OR if the current known cost from s to
1795
+ // v is greater than the new cost we just found (cost of s to u plus
1796
+ // cost of u to v across e), update v's cost in the cost list and
1797
+ // update v's predecessor in the predecessor list (it's now u).
1798
+ cost_of_s_to_v = costs[v];
1799
+ first_visit = (typeof costs[v] === 'undefined');
1800
+ if (first_visit || cost_of_s_to_v > cost_of_s_to_u_plus_cost_of_e) {
1801
+ costs[v] = cost_of_s_to_u_plus_cost_of_e;
1802
+ open.push(v, cost_of_s_to_u_plus_cost_of_e);
1803
+ predecessors[v] = u;
1804
+ }
1805
+ }
1806
+ }
1807
+ }
1808
+
1809
+ if (typeof d !== 'undefined' && typeof costs[d] === 'undefined') {
1810
+ var msg = ['Could not find a path from ', s, ' to ', d, '.'].join('');
1811
+ throw new Error(msg);
1812
+ }
1813
+
1814
+ return predecessors;
1815
+ },
1816
+
1817
+ extract_shortest_path_from_predecessor_list: function(predecessors, d) {
1818
+ var nodes = [];
1819
+ var u = d;
1820
+ while (u) {
1821
+ nodes.push(u);
1822
+ predecessors[u];
1823
+ u = predecessors[u];
1824
+ }
1825
+ nodes.reverse();
1826
+ return nodes;
1827
+ },
1828
+
1829
+ find_path: function(graph, s, d) {
1830
+ var predecessors = dijkstra.single_source_shortest_paths(graph, s, d);
1831
+ return dijkstra.extract_shortest_path_from_predecessor_list(
1832
+ predecessors, d);
1833
+ },
1834
+
1835
+ /**
1836
+ * A very naive priority queue implementation.
1837
+ */
1838
+ PriorityQueue: {
1839
+ make: function (opts) {
1840
+ var T = dijkstra.PriorityQueue,
1841
+ t = {},
1842
+ key;
1843
+ opts = opts || {};
1844
+ for (key in T) {
1845
+ if (T.hasOwnProperty(key)) {
1846
+ t[key] = T[key];
1847
+ }
1848
+ }
1849
+ t.queue = [];
1850
+ t.sorter = opts.sorter || T.default_sorter;
1851
+ return t;
1852
+ },
1853
+
1854
+ default_sorter: function (a, b) {
1855
+ return a.cost - b.cost;
1856
+ },
1857
+
1858
+ /**
1859
+ * Add a new item to the queue and ensure the highest priority element
1860
+ * is at the front of the queue.
1861
+ */
1862
+ push: function (value, cost) {
1863
+ var item = {value: value, cost: cost};
1864
+ this.queue.push(item);
1865
+ this.queue.sort(this.sorter);
1866
+ },
1867
+
1868
+ /**
1869
+ * Return the highest priority element in the queue.
1870
+ */
1871
+ pop: function () {
1872
+ return this.queue.shift();
1873
+ },
1874
+
1875
+ empty: function () {
1876
+ return this.queue.length === 0;
1877
+ }
1878
+ }
1879
+ };
1880
+
1881
+
1882
+ // node.js module exports
1883
+ {
1884
+ module.exports = dijkstra;
1885
+ }
1886
+ } (dijkstra));
1887
+ return dijkstra.exports;
1888
+ }
1889
+
1890
+ var hasRequiredSegments;
1891
+
1892
+ function requireSegments () {
1893
+ if (hasRequiredSegments) return segments;
1894
+ hasRequiredSegments = 1;
1895
+ (function (exports$1) {
1896
+ const Mode = requireMode();
1897
+ const NumericData = requireNumericData();
1898
+ const AlphanumericData = requireAlphanumericData();
1899
+ const ByteData = requireByteData();
1900
+ const KanjiData = requireKanjiData();
1901
+ const Regex = requireRegex();
1902
+ const Utils = requireUtils$1();
1903
+ const dijkstra = requireDijkstra();
1904
+
1905
+ /**
1906
+ * Returns UTF8 byte length
1907
+ *
1908
+ * @param {String} str Input string
1909
+ * @return {Number} Number of byte
1910
+ */
1911
+ function getStringByteLength (str) {
1912
+ return unescape(encodeURIComponent(str)).length
1913
+ }
1914
+
1915
+ /**
1916
+ * Get a list of segments of the specified mode
1917
+ * from a string
1918
+ *
1919
+ * @param {Mode} mode Segment mode
1920
+ * @param {String} str String to process
1921
+ * @return {Array} Array of object with segments data
1922
+ */
1923
+ function getSegments (regex, mode, str) {
1924
+ const segments = [];
1925
+ let result;
1926
+
1927
+ while ((result = regex.exec(str)) !== null) {
1928
+ segments.push({
1929
+ data: result[0],
1930
+ index: result.index,
1931
+ mode: mode,
1932
+ length: result[0].length
1933
+ });
1934
+ }
1935
+
1936
+ return segments
1937
+ }
1938
+
1939
+ /**
1940
+ * Extracts a series of segments with the appropriate
1941
+ * modes from a string
1942
+ *
1943
+ * @param {String} dataStr Input string
1944
+ * @return {Array} Array of object with segments data
1945
+ */
1946
+ function getSegmentsFromString (dataStr) {
1947
+ const numSegs = getSegments(Regex.NUMERIC, Mode.NUMERIC, dataStr);
1948
+ const alphaNumSegs = getSegments(Regex.ALPHANUMERIC, Mode.ALPHANUMERIC, dataStr);
1949
+ let byteSegs;
1950
+ let kanjiSegs;
1951
+
1952
+ if (Utils.isKanjiModeEnabled()) {
1953
+ byteSegs = getSegments(Regex.BYTE, Mode.BYTE, dataStr);
1954
+ kanjiSegs = getSegments(Regex.KANJI, Mode.KANJI, dataStr);
1955
+ } else {
1956
+ byteSegs = getSegments(Regex.BYTE_KANJI, Mode.BYTE, dataStr);
1957
+ kanjiSegs = [];
1958
+ }
1959
+
1960
+ const segs = numSegs.concat(alphaNumSegs, byteSegs, kanjiSegs);
1961
+
1962
+ return segs
1963
+ .sort(function (s1, s2) {
1964
+ return s1.index - s2.index
1965
+ })
1966
+ .map(function (obj) {
1967
+ return {
1968
+ data: obj.data,
1969
+ mode: obj.mode,
1970
+ length: obj.length
1971
+ }
1972
+ })
1973
+ }
1974
+
1975
+ /**
1976
+ * Returns how many bits are needed to encode a string of
1977
+ * specified length with the specified mode
1978
+ *
1979
+ * @param {Number} length String length
1980
+ * @param {Mode} mode Segment mode
1981
+ * @return {Number} Bit length
1982
+ */
1983
+ function getSegmentBitsLength (length, mode) {
1984
+ switch (mode) {
1985
+ case Mode.NUMERIC:
1986
+ return NumericData.getBitsLength(length)
1987
+ case Mode.ALPHANUMERIC:
1988
+ return AlphanumericData.getBitsLength(length)
1989
+ case Mode.KANJI:
1990
+ return KanjiData.getBitsLength(length)
1991
+ case Mode.BYTE:
1992
+ return ByteData.getBitsLength(length)
1993
+ }
1994
+ }
1995
+
1996
+ /**
1997
+ * Merges adjacent segments which have the same mode
1998
+ *
1999
+ * @param {Array} segs Array of object with segments data
2000
+ * @return {Array} Array of object with segments data
2001
+ */
2002
+ function mergeSegments (segs) {
2003
+ return segs.reduce(function (acc, curr) {
2004
+ const prevSeg = acc.length - 1 >= 0 ? acc[acc.length - 1] : null;
2005
+ if (prevSeg && prevSeg.mode === curr.mode) {
2006
+ acc[acc.length - 1].data += curr.data;
2007
+ return acc
2008
+ }
2009
+
2010
+ acc.push(curr);
2011
+ return acc
2012
+ }, [])
2013
+ }
2014
+
2015
+ /**
2016
+ * Generates a list of all possible nodes combination which
2017
+ * will be used to build a segments graph.
2018
+ *
2019
+ * Nodes are divided by groups. Each group will contain a list of all the modes
2020
+ * in which is possible to encode the given text.
2021
+ *
2022
+ * For example the text '12345' can be encoded as Numeric, Alphanumeric or Byte.
2023
+ * The group for '12345' will contain then 3 objects, one for each
2024
+ * possible encoding mode.
2025
+ *
2026
+ * Each node represents a possible segment.
2027
+ *
2028
+ * @param {Array} segs Array of object with segments data
2029
+ * @return {Array} Array of object with segments data
2030
+ */
2031
+ function buildNodes (segs) {
2032
+ const nodes = [];
2033
+ for (let i = 0; i < segs.length; i++) {
2034
+ const seg = segs[i];
2035
+
2036
+ switch (seg.mode) {
2037
+ case Mode.NUMERIC:
2038
+ nodes.push([seg,
2039
+ { data: seg.data, mode: Mode.ALPHANUMERIC, length: seg.length },
2040
+ { data: seg.data, mode: Mode.BYTE, length: seg.length }
2041
+ ]);
2042
+ break
2043
+ case Mode.ALPHANUMERIC:
2044
+ nodes.push([seg,
2045
+ { data: seg.data, mode: Mode.BYTE, length: seg.length }
2046
+ ]);
2047
+ break
2048
+ case Mode.KANJI:
2049
+ nodes.push([seg,
2050
+ { data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) }
2051
+ ]);
2052
+ break
2053
+ case Mode.BYTE:
2054
+ nodes.push([
2055
+ { data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) }
2056
+ ]);
2057
+ }
2058
+ }
2059
+
2060
+ return nodes
2061
+ }
2062
+
2063
+ /**
2064
+ * Builds a graph from a list of nodes.
2065
+ * All segments in each node group will be connected with all the segments of
2066
+ * the next group and so on.
2067
+ *
2068
+ * At each connection will be assigned a weight depending on the
2069
+ * segment's byte length.
2070
+ *
2071
+ * @param {Array} nodes Array of object with segments data
2072
+ * @param {Number} version QR Code version
2073
+ * @return {Object} Graph of all possible segments
2074
+ */
2075
+ function buildGraph (nodes, version) {
2076
+ const table = {};
2077
+ const graph = { start: {} };
2078
+ let prevNodeIds = ['start'];
2079
+
2080
+ for (let i = 0; i < nodes.length; i++) {
2081
+ const nodeGroup = nodes[i];
2082
+ const currentNodeIds = [];
2083
+
2084
+ for (let j = 0; j < nodeGroup.length; j++) {
2085
+ const node = nodeGroup[j];
2086
+ const key = '' + i + j;
2087
+
2088
+ currentNodeIds.push(key);
2089
+ table[key] = { node: node, lastCount: 0 };
2090
+ graph[key] = {};
2091
+
2092
+ for (let n = 0; n < prevNodeIds.length; n++) {
2093
+ const prevNodeId = prevNodeIds[n];
2094
+
2095
+ if (table[prevNodeId] && table[prevNodeId].node.mode === node.mode) {
2096
+ graph[prevNodeId][key] =
2097
+ getSegmentBitsLength(table[prevNodeId].lastCount + node.length, node.mode) -
2098
+ getSegmentBitsLength(table[prevNodeId].lastCount, node.mode);
2099
+
2100
+ table[prevNodeId].lastCount += node.length;
2101
+ } else {
2102
+ if (table[prevNodeId]) table[prevNodeId].lastCount = node.length;
2103
+
2104
+ graph[prevNodeId][key] = getSegmentBitsLength(node.length, node.mode) +
2105
+ 4 + Mode.getCharCountIndicator(node.mode, version); // switch cost
2106
+ }
2107
+ }
2108
+ }
2109
+
2110
+ prevNodeIds = currentNodeIds;
2111
+ }
2112
+
2113
+ for (let n = 0; n < prevNodeIds.length; n++) {
2114
+ graph[prevNodeIds[n]].end = 0;
2115
+ }
2116
+
2117
+ return { map: graph, table: table }
2118
+ }
2119
+
2120
+ /**
2121
+ * Builds a segment from a specified data and mode.
2122
+ * If a mode is not specified, the more suitable will be used.
2123
+ *
2124
+ * @param {String} data Input data
2125
+ * @param {Mode | String} modesHint Data mode
2126
+ * @return {Segment} Segment
2127
+ */
2128
+ function buildSingleSegment (data, modesHint) {
2129
+ let mode;
2130
+ const bestMode = Mode.getBestModeForData(data);
2131
+
2132
+ mode = Mode.from(modesHint, bestMode);
2133
+
2134
+ // Make sure data can be encoded
2135
+ if (mode !== Mode.BYTE && mode.bit < bestMode.bit) {
2136
+ throw new Error('"' + data + '"' +
2137
+ ' cannot be encoded with mode ' + Mode.toString(mode) +
2138
+ '.\n Suggested mode is: ' + Mode.toString(bestMode))
2139
+ }
2140
+
2141
+ // Use Mode.BYTE if Kanji support is disabled
2142
+ if (mode === Mode.KANJI && !Utils.isKanjiModeEnabled()) {
2143
+ mode = Mode.BYTE;
2144
+ }
2145
+
2146
+ switch (mode) {
2147
+ case Mode.NUMERIC:
2148
+ return new NumericData(data)
2149
+
2150
+ case Mode.ALPHANUMERIC:
2151
+ return new AlphanumericData(data)
2152
+
2153
+ case Mode.KANJI:
2154
+ return new KanjiData(data)
2155
+
2156
+ case Mode.BYTE:
2157
+ return new ByteData(data)
2158
+ }
2159
+ }
2160
+
2161
+ /**
2162
+ * Builds a list of segments from an array.
2163
+ * Array can contain Strings or Objects with segment's info.
2164
+ *
2165
+ * For each item which is a string, will be generated a segment with the given
2166
+ * string and the more appropriate encoding mode.
2167
+ *
2168
+ * For each item which is an object, will be generated a segment with the given
2169
+ * data and mode.
2170
+ * Objects must contain at least the property "data".
2171
+ * If property "mode" is not present, the more suitable mode will be used.
2172
+ *
2173
+ * @param {Array} array Array of objects with segments data
2174
+ * @return {Array} Array of Segments
2175
+ */
2176
+ exports$1.fromArray = function fromArray (array) {
2177
+ return array.reduce(function (acc, seg) {
2178
+ if (typeof seg === 'string') {
2179
+ acc.push(buildSingleSegment(seg, null));
2180
+ } else if (seg.data) {
2181
+ acc.push(buildSingleSegment(seg.data, seg.mode));
2182
+ }
2183
+
2184
+ return acc
2185
+ }, [])
2186
+ };
2187
+
2188
+ /**
2189
+ * Builds an optimized sequence of segments from a string,
2190
+ * which will produce the shortest possible bitstream.
2191
+ *
2192
+ * @param {String} data Input string
2193
+ * @param {Number} version QR Code version
2194
+ * @return {Array} Array of segments
2195
+ */
2196
+ exports$1.fromString = function fromString (data, version) {
2197
+ const segs = getSegmentsFromString(data, Utils.isKanjiModeEnabled());
2198
+
2199
+ const nodes = buildNodes(segs);
2200
+ const graph = buildGraph(nodes, version);
2201
+ const path = dijkstra.find_path(graph.map, 'start', 'end');
2202
+
2203
+ const optimizedSegs = [];
2204
+ for (let i = 1; i < path.length - 1; i++) {
2205
+ optimizedSegs.push(graph.table[path[i]].node);
2206
+ }
2207
+
2208
+ return exports$1.fromArray(mergeSegments(optimizedSegs))
2209
+ };
2210
+
2211
+ /**
2212
+ * Splits a string in various segments with the modes which
2213
+ * best represent their content.
2214
+ * The produced segments are far from being optimized.
2215
+ * The output of this function is only used to estimate a QR Code version
2216
+ * which may contain the data.
2217
+ *
2218
+ * @param {string} data Input string
2219
+ * @return {Array} Array of segments
2220
+ */
2221
+ exports$1.rawSplit = function rawSplit (data) {
2222
+ return exports$1.fromArray(
2223
+ getSegmentsFromString(data, Utils.isKanjiModeEnabled())
2224
+ )
2225
+ };
2226
+ } (segments));
2227
+ return segments;
2228
+ }
2229
+
2230
+ var hasRequiredQrcode;
2231
+
2232
+ function requireQrcode () {
2233
+ if (hasRequiredQrcode) return qrcode;
2234
+ hasRequiredQrcode = 1;
2235
+ const Utils = requireUtils$1();
2236
+ const ECLevel = requireErrorCorrectionLevel();
2237
+ const BitBuffer = requireBitBuffer();
2238
+ const BitMatrix = requireBitMatrix();
2239
+ const AlignmentPattern = requireAlignmentPattern();
2240
+ const FinderPattern = requireFinderPattern();
2241
+ const MaskPattern = requireMaskPattern();
2242
+ const ECCode = requireErrorCorrectionCode();
2243
+ const ReedSolomonEncoder = requireReedSolomonEncoder();
2244
+ const Version = requireVersion();
2245
+ const FormatInfo = requireFormatInfo();
2246
+ const Mode = requireMode();
2247
+ const Segments = requireSegments();
2248
+
2249
+ /**
2250
+ * QRCode for JavaScript
2251
+ *
2252
+ * modified by Ryan Day for nodejs support
2253
+ * Copyright (c) 2011 Ryan Day
2254
+ *
2255
+ * Licensed under the MIT license:
2256
+ * http://www.opensource.org/licenses/mit-license.php
2257
+ *
2258
+ //---------------------------------------------------------------------
2259
+ // QRCode for JavaScript
2260
+ //
2261
+ // Copyright (c) 2009 Kazuhiko Arase
2262
+ //
2263
+ // URL: http://www.d-project.com/
2264
+ //
2265
+ // Licensed under the MIT license:
2266
+ // http://www.opensource.org/licenses/mit-license.php
2267
+ //
2268
+ // The word "QR Code" is registered trademark of
2269
+ // DENSO WAVE INCORPORATED
2270
+ // http://www.denso-wave.com/qrcode/faqpatent-e.html
2271
+ //
2272
+ //---------------------------------------------------------------------
2273
+ */
2274
+
2275
+ /**
2276
+ * Add finder patterns bits to matrix
2277
+ *
2278
+ * @param {BitMatrix} matrix Modules matrix
2279
+ * @param {Number} version QR Code version
2280
+ */
2281
+ function setupFinderPattern (matrix, version) {
2282
+ const size = matrix.size;
2283
+ const pos = FinderPattern.getPositions(version);
2284
+
2285
+ for (let i = 0; i < pos.length; i++) {
2286
+ const row = pos[i][0];
2287
+ const col = pos[i][1];
2288
+
2289
+ for (let r = -1; r <= 7; r++) {
2290
+ if (row + r <= -1 || size <= row + r) continue
2291
+
2292
+ for (let c = -1; c <= 7; c++) {
2293
+ if (col + c <= -1 || size <= col + c) continue
2294
+
2295
+ if ((r >= 0 && r <= 6 && (c === 0 || c === 6)) ||
2296
+ (c >= 0 && c <= 6 && (r === 0 || r === 6)) ||
2297
+ (r >= 2 && r <= 4 && c >= 2 && c <= 4)) {
2298
+ matrix.set(row + r, col + c, true, true);
2299
+ } else {
2300
+ matrix.set(row + r, col + c, false, true);
2301
+ }
2302
+ }
2303
+ }
2304
+ }
2305
+ }
2306
+
2307
+ /**
2308
+ * Add timing pattern bits to matrix
2309
+ *
2310
+ * Note: this function must be called before {@link setupAlignmentPattern}
2311
+ *
2312
+ * @param {BitMatrix} matrix Modules matrix
2313
+ */
2314
+ function setupTimingPattern (matrix) {
2315
+ const size = matrix.size;
2316
+
2317
+ for (let r = 8; r < size - 8; r++) {
2318
+ const value = r % 2 === 0;
2319
+ matrix.set(r, 6, value, true);
2320
+ matrix.set(6, r, value, true);
2321
+ }
2322
+ }
2323
+
2324
+ /**
2325
+ * Add alignment patterns bits to matrix
2326
+ *
2327
+ * Note: this function must be called after {@link setupTimingPattern}
2328
+ *
2329
+ * @param {BitMatrix} matrix Modules matrix
2330
+ * @param {Number} version QR Code version
2331
+ */
2332
+ function setupAlignmentPattern (matrix, version) {
2333
+ const pos = AlignmentPattern.getPositions(version);
2334
+
2335
+ for (let i = 0; i < pos.length; i++) {
2336
+ const row = pos[i][0];
2337
+ const col = pos[i][1];
2338
+
2339
+ for (let r = -2; r <= 2; r++) {
2340
+ for (let c = -2; c <= 2; c++) {
2341
+ if (r === -2 || r === 2 || c === -2 || c === 2 ||
2342
+ (r === 0 && c === 0)) {
2343
+ matrix.set(row + r, col + c, true, true);
2344
+ } else {
2345
+ matrix.set(row + r, col + c, false, true);
2346
+ }
2347
+ }
2348
+ }
2349
+ }
2350
+ }
2351
+
2352
+ /**
2353
+ * Add version info bits to matrix
2354
+ *
2355
+ * @param {BitMatrix} matrix Modules matrix
2356
+ * @param {Number} version QR Code version
2357
+ */
2358
+ function setupVersionInfo (matrix, version) {
2359
+ const size = matrix.size;
2360
+ const bits = Version.getEncodedBits(version);
2361
+ let row, col, mod;
2362
+
2363
+ for (let i = 0; i < 18; i++) {
2364
+ row = Math.floor(i / 3);
2365
+ col = i % 3 + size - 8 - 3;
2366
+ mod = ((bits >> i) & 1) === 1;
2367
+
2368
+ matrix.set(row, col, mod, true);
2369
+ matrix.set(col, row, mod, true);
2370
+ }
2371
+ }
2372
+
2373
+ /**
2374
+ * Add format info bits to matrix
2375
+ *
2376
+ * @param {BitMatrix} matrix Modules matrix
2377
+ * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level
2378
+ * @param {Number} maskPattern Mask pattern reference value
2379
+ */
2380
+ function setupFormatInfo (matrix, errorCorrectionLevel, maskPattern) {
2381
+ const size = matrix.size;
2382
+ const bits = FormatInfo.getEncodedBits(errorCorrectionLevel, maskPattern);
2383
+ let i, mod;
2384
+
2385
+ for (i = 0; i < 15; i++) {
2386
+ mod = ((bits >> i) & 1) === 1;
2387
+
2388
+ // vertical
2389
+ if (i < 6) {
2390
+ matrix.set(i, 8, mod, true);
2391
+ } else if (i < 8) {
2392
+ matrix.set(i + 1, 8, mod, true);
2393
+ } else {
2394
+ matrix.set(size - 15 + i, 8, mod, true);
2395
+ }
2396
+
2397
+ // horizontal
2398
+ if (i < 8) {
2399
+ matrix.set(8, size - i - 1, mod, true);
2400
+ } else if (i < 9) {
2401
+ matrix.set(8, 15 - i - 1 + 1, mod, true);
2402
+ } else {
2403
+ matrix.set(8, 15 - i - 1, mod, true);
2404
+ }
2405
+ }
2406
+
2407
+ // fixed module
2408
+ matrix.set(size - 8, 8, 1, true);
2409
+ }
2410
+
2411
+ /**
2412
+ * Add encoded data bits to matrix
2413
+ *
2414
+ * @param {BitMatrix} matrix Modules matrix
2415
+ * @param {Uint8Array} data Data codewords
2416
+ */
2417
+ function setupData (matrix, data) {
2418
+ const size = matrix.size;
2419
+ let inc = -1;
2420
+ let row = size - 1;
2421
+ let bitIndex = 7;
2422
+ let byteIndex = 0;
2423
+
2424
+ for (let col = size - 1; col > 0; col -= 2) {
2425
+ if (col === 6) col--;
2426
+
2427
+ while (true) {
2428
+ for (let c = 0; c < 2; c++) {
2429
+ if (!matrix.isReserved(row, col - c)) {
2430
+ let dark = false;
2431
+
2432
+ if (byteIndex < data.length) {
2433
+ dark = (((data[byteIndex] >>> bitIndex) & 1) === 1);
2434
+ }
2435
+
2436
+ matrix.set(row, col - c, dark);
2437
+ bitIndex--;
2438
+
2439
+ if (bitIndex === -1) {
2440
+ byteIndex++;
2441
+ bitIndex = 7;
2442
+ }
2443
+ }
2444
+ }
2445
+
2446
+ row += inc;
2447
+
2448
+ if (row < 0 || size <= row) {
2449
+ row -= inc;
2450
+ inc = -inc;
2451
+ break
2452
+ }
2453
+ }
2454
+ }
2455
+ }
2456
+
2457
+ /**
2458
+ * Create encoded codewords from data input
2459
+ *
2460
+ * @param {Number} version QR Code version
2461
+ * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level
2462
+ * @param {ByteData} data Data input
2463
+ * @return {Uint8Array} Buffer containing encoded codewords
2464
+ */
2465
+ function createData (version, errorCorrectionLevel, segments) {
2466
+ // Prepare data buffer
2467
+ const buffer = new BitBuffer();
2468
+
2469
+ segments.forEach(function (data) {
2470
+ // prefix data with mode indicator (4 bits)
2471
+ buffer.put(data.mode.bit, 4);
2472
+
2473
+ // Prefix data with character count indicator.
2474
+ // The character count indicator is a string of bits that represents the
2475
+ // number of characters that are being encoded.
2476
+ // The character count indicator must be placed after the mode indicator
2477
+ // and must be a certain number of bits long, depending on the QR version
2478
+ // and data mode
2479
+ // @see {@link Mode.getCharCountIndicator}.
2480
+ buffer.put(data.getLength(), Mode.getCharCountIndicator(data.mode, version));
2481
+
2482
+ // add binary data sequence to buffer
2483
+ data.write(buffer);
2484
+ });
2485
+
2486
+ // Calculate required number of bits
2487
+ const totalCodewords = Utils.getSymbolTotalCodewords(version);
2488
+ const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
2489
+ const dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8;
2490
+
2491
+ // Add a terminator.
2492
+ // If the bit string is shorter than the total number of required bits,
2493
+ // a terminator of up to four 0s must be added to the right side of the string.
2494
+ // If the bit string is more than four bits shorter than the required number of bits,
2495
+ // add four 0s to the end.
2496
+ if (buffer.getLengthInBits() + 4 <= dataTotalCodewordsBits) {
2497
+ buffer.put(0, 4);
2498
+ }
2499
+
2500
+ // If the bit string is fewer than four bits shorter, add only the number of 0s that
2501
+ // are needed to reach the required number of bits.
2502
+
2503
+ // After adding the terminator, if the number of bits in the string is not a multiple of 8,
2504
+ // pad the string on the right with 0s to make the string's length a multiple of 8.
2505
+ while (buffer.getLengthInBits() % 8 !== 0) {
2506
+ buffer.putBit(0);
2507
+ }
2508
+
2509
+ // Add pad bytes if the string is still shorter than the total number of required bits.
2510
+ // Extend the buffer to fill the data capacity of the symbol corresponding to
2511
+ // the Version and Error Correction Level by adding the Pad Codewords 11101100 (0xEC)
2512
+ // and 00010001 (0x11) alternately.
2513
+ const remainingByte = (dataTotalCodewordsBits - buffer.getLengthInBits()) / 8;
2514
+ for (let i = 0; i < remainingByte; i++) {
2515
+ buffer.put(i % 2 ? 0x11 : 0xEC, 8);
2516
+ }
2517
+
2518
+ return createCodewords(buffer, version, errorCorrectionLevel)
2519
+ }
2520
+
2521
+ /**
2522
+ * Encode input data with Reed-Solomon and return codewords with
2523
+ * relative error correction bits
2524
+ *
2525
+ * @param {BitBuffer} bitBuffer Data to encode
2526
+ * @param {Number} version QR Code version
2527
+ * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level
2528
+ * @return {Uint8Array} Buffer containing encoded codewords
2529
+ */
2530
+ function createCodewords (bitBuffer, version, errorCorrectionLevel) {
2531
+ // Total codewords for this QR code version (Data + Error correction)
2532
+ const totalCodewords = Utils.getSymbolTotalCodewords(version);
2533
+
2534
+ // Total number of error correction codewords
2535
+ const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
2536
+
2537
+ // Total number of data codewords
2538
+ const dataTotalCodewords = totalCodewords - ecTotalCodewords;
2539
+
2540
+ // Total number of blocks
2541
+ const ecTotalBlocks = ECCode.getBlocksCount(version, errorCorrectionLevel);
2542
+
2543
+ // Calculate how many blocks each group should contain
2544
+ const blocksInGroup2 = totalCodewords % ecTotalBlocks;
2545
+ const blocksInGroup1 = ecTotalBlocks - blocksInGroup2;
2546
+
2547
+ const totalCodewordsInGroup1 = Math.floor(totalCodewords / ecTotalBlocks);
2548
+
2549
+ const dataCodewordsInGroup1 = Math.floor(dataTotalCodewords / ecTotalBlocks);
2550
+ const dataCodewordsInGroup2 = dataCodewordsInGroup1 + 1;
2551
+
2552
+ // Number of EC codewords is the same for both groups
2553
+ const ecCount = totalCodewordsInGroup1 - dataCodewordsInGroup1;
2554
+
2555
+ // Initialize a Reed-Solomon encoder with a generator polynomial of degree ecCount
2556
+ const rs = new ReedSolomonEncoder(ecCount);
2557
+
2558
+ let offset = 0;
2559
+ const dcData = new Array(ecTotalBlocks);
2560
+ const ecData = new Array(ecTotalBlocks);
2561
+ let maxDataSize = 0;
2562
+ const buffer = new Uint8Array(bitBuffer.buffer);
2563
+
2564
+ // Divide the buffer into the required number of blocks
2565
+ for (let b = 0; b < ecTotalBlocks; b++) {
2566
+ const dataSize = b < blocksInGroup1 ? dataCodewordsInGroup1 : dataCodewordsInGroup2;
2567
+
2568
+ // extract a block of data from buffer
2569
+ dcData[b] = buffer.slice(offset, offset + dataSize);
2570
+
2571
+ // Calculate EC codewords for this data block
2572
+ ecData[b] = rs.encode(dcData[b]);
2573
+
2574
+ offset += dataSize;
2575
+ maxDataSize = Math.max(maxDataSize, dataSize);
2576
+ }
2577
+
2578
+ // Create final data
2579
+ // Interleave the data and error correction codewords from each block
2580
+ const data = new Uint8Array(totalCodewords);
2581
+ let index = 0;
2582
+ let i, r;
2583
+
2584
+ // Add data codewords
2585
+ for (i = 0; i < maxDataSize; i++) {
2586
+ for (r = 0; r < ecTotalBlocks; r++) {
2587
+ if (i < dcData[r].length) {
2588
+ data[index++] = dcData[r][i];
2589
+ }
2590
+ }
2591
+ }
2592
+
2593
+ // Apped EC codewords
2594
+ for (i = 0; i < ecCount; i++) {
2595
+ for (r = 0; r < ecTotalBlocks; r++) {
2596
+ data[index++] = ecData[r][i];
2597
+ }
2598
+ }
2599
+
2600
+ return data
2601
+ }
2602
+
2603
+ /**
2604
+ * Build QR Code symbol
2605
+ *
2606
+ * @param {String} data Input string
2607
+ * @param {Number} version QR Code version
2608
+ * @param {ErrorCorretionLevel} errorCorrectionLevel Error level
2609
+ * @param {MaskPattern} maskPattern Mask pattern
2610
+ * @return {Object} Object containing symbol data
2611
+ */
2612
+ function createSymbol (data, version, errorCorrectionLevel, maskPattern) {
2613
+ let segments;
2614
+
2615
+ if (Array.isArray(data)) {
2616
+ segments = Segments.fromArray(data);
2617
+ } else if (typeof data === 'string') {
2618
+ let estimatedVersion = version;
2619
+
2620
+ if (!estimatedVersion) {
2621
+ const rawSegments = Segments.rawSplit(data);
2622
+
2623
+ // Estimate best version that can contain raw splitted segments
2624
+ estimatedVersion = Version.getBestVersionForData(rawSegments, errorCorrectionLevel);
2625
+ }
2626
+
2627
+ // Build optimized segments
2628
+ // If estimated version is undefined, try with the highest version
2629
+ segments = Segments.fromString(data, estimatedVersion || 40);
2630
+ } else {
2631
+ throw new Error('Invalid data')
2632
+ }
2633
+
2634
+ // Get the min version that can contain data
2635
+ const bestVersion = Version.getBestVersionForData(segments, errorCorrectionLevel);
2636
+
2637
+ // If no version is found, data cannot be stored
2638
+ if (!bestVersion) {
2639
+ throw new Error('The amount of data is too big to be stored in a QR Code')
2640
+ }
2641
+
2642
+ // If not specified, use min version as default
2643
+ if (!version) {
2644
+ version = bestVersion;
2645
+
2646
+ // Check if the specified version can contain the data
2647
+ } else if (version < bestVersion) {
2648
+ throw new Error('\n' +
2649
+ 'The chosen QR Code version cannot contain this amount of data.\n' +
2650
+ 'Minimum version required to store current data is: ' + bestVersion + '.\n'
2651
+ )
2652
+ }
2653
+
2654
+ const dataBits = createData(version, errorCorrectionLevel, segments);
2655
+
2656
+ // Allocate matrix buffer
2657
+ const moduleCount = Utils.getSymbolSize(version);
2658
+ const modules = new BitMatrix(moduleCount);
2659
+
2660
+ // Add function modules
2661
+ setupFinderPattern(modules, version);
2662
+ setupTimingPattern(modules);
2663
+ setupAlignmentPattern(modules, version);
2664
+
2665
+ // Add temporary dummy bits for format info just to set them as reserved.
2666
+ // This is needed to prevent these bits from being masked by {@link MaskPattern.applyMask}
2667
+ // since the masking operation must be performed only on the encoding region.
2668
+ // These blocks will be replaced with correct values later in code.
2669
+ setupFormatInfo(modules, errorCorrectionLevel, 0);
2670
+
2671
+ if (version >= 7) {
2672
+ setupVersionInfo(modules, version);
2673
+ }
2674
+
2675
+ // Add data codewords
2676
+ setupData(modules, dataBits);
2677
+
2678
+ if (isNaN(maskPattern)) {
2679
+ // Find best mask pattern
2680
+ maskPattern = MaskPattern.getBestMask(modules,
2681
+ setupFormatInfo.bind(null, modules, errorCorrectionLevel));
2682
+ }
2683
+
2684
+ // Apply mask pattern
2685
+ MaskPattern.applyMask(maskPattern, modules);
2686
+
2687
+ // Replace format info bits with correct values
2688
+ setupFormatInfo(modules, errorCorrectionLevel, maskPattern);
2689
+
2690
+ return {
2691
+ modules: modules,
2692
+ version: version,
2693
+ errorCorrectionLevel: errorCorrectionLevel,
2694
+ maskPattern: maskPattern,
2695
+ segments: segments
2696
+ }
2697
+ }
2698
+
2699
+ /**
2700
+ * QR Code
2701
+ *
2702
+ * @param {String | Array} data Input data
2703
+ * @param {Object} options Optional configurations
2704
+ * @param {Number} options.version QR Code version
2705
+ * @param {String} options.errorCorrectionLevel Error correction level
2706
+ * @param {Function} options.toSJISFunc Helper func to convert utf8 to sjis
2707
+ */
2708
+ qrcode.create = function create (data, options) {
2709
+ if (typeof data === 'undefined' || data === '') {
2710
+ throw new Error('No input text')
2711
+ }
2712
+
2713
+ let errorCorrectionLevel = ECLevel.M;
2714
+ let version;
2715
+ let mask;
2716
+
2717
+ if (typeof options !== 'undefined') {
2718
+ // Use higher error correction level as default
2719
+ errorCorrectionLevel = ECLevel.from(options.errorCorrectionLevel, ECLevel.M);
2720
+ version = Version.from(options.version);
2721
+ mask = MaskPattern.from(options.maskPattern);
2722
+
2723
+ if (options.toSJISFunc) {
2724
+ Utils.setToSJISFunction(options.toSJISFunc);
2725
+ }
2726
+ }
2727
+
2728
+ return createSymbol(data, version, errorCorrectionLevel, mask)
2729
+ };
2730
+ return qrcode;
2731
+ }
2732
+
2733
+ var canvas = {};
2734
+
2735
+ var utils = {};
2736
+
2737
+ var hasRequiredUtils;
2738
+
2739
+ function requireUtils () {
2740
+ if (hasRequiredUtils) return utils;
2741
+ hasRequiredUtils = 1;
2742
+ (function (exports$1) {
2743
+ function hex2rgba (hex) {
2744
+ if (typeof hex === 'number') {
2745
+ hex = hex.toString();
2746
+ }
2747
+
2748
+ if (typeof hex !== 'string') {
2749
+ throw new Error('Color should be defined as hex string')
2750
+ }
2751
+
2752
+ let hexCode = hex.slice().replace('#', '').split('');
2753
+ if (hexCode.length < 3 || hexCode.length === 5 || hexCode.length > 8) {
2754
+ throw new Error('Invalid hex color: ' + hex)
2755
+ }
2756
+
2757
+ // Convert from short to long form (fff -> ffffff)
2758
+ if (hexCode.length === 3 || hexCode.length === 4) {
2759
+ hexCode = Array.prototype.concat.apply([], hexCode.map(function (c) {
2760
+ return [c, c]
2761
+ }));
2762
+ }
2763
+
2764
+ // Add default alpha value
2765
+ if (hexCode.length === 6) hexCode.push('F', 'F');
2766
+
2767
+ const hexValue = parseInt(hexCode.join(''), 16);
2768
+
2769
+ return {
2770
+ r: (hexValue >> 24) & 255,
2771
+ g: (hexValue >> 16) & 255,
2772
+ b: (hexValue >> 8) & 255,
2773
+ a: hexValue & 255,
2774
+ hex: '#' + hexCode.slice(0, 6).join('')
2775
+ }
2776
+ }
2777
+
2778
+ exports$1.getOptions = function getOptions (options) {
2779
+ if (!options) options = {};
2780
+ if (!options.color) options.color = {};
2781
+
2782
+ const margin = typeof options.margin === 'undefined' ||
2783
+ options.margin === null ||
2784
+ options.margin < 0
2785
+ ? 4
2786
+ : options.margin;
2787
+
2788
+ const width = options.width && options.width >= 21 ? options.width : undefined;
2789
+ const scale = options.scale || 4;
2790
+
2791
+ return {
2792
+ width: width,
2793
+ scale: width ? 4 : scale,
2794
+ margin: margin,
2795
+ color: {
2796
+ dark: hex2rgba(options.color.dark || '#000000ff'),
2797
+ light: hex2rgba(options.color.light || '#ffffffff')
2798
+ },
2799
+ type: options.type,
2800
+ rendererOpts: options.rendererOpts || {}
2801
+ }
2802
+ };
2803
+
2804
+ exports$1.getScale = function getScale (qrSize, opts) {
2805
+ return opts.width && opts.width >= qrSize + opts.margin * 2
2806
+ ? opts.width / (qrSize + opts.margin * 2)
2807
+ : opts.scale
2808
+ };
2809
+
2810
+ exports$1.getImageWidth = function getImageWidth (qrSize, opts) {
2811
+ const scale = exports$1.getScale(qrSize, opts);
2812
+ return Math.floor((qrSize + opts.margin * 2) * scale)
2813
+ };
2814
+
2815
+ exports$1.qrToImageData = function qrToImageData (imgData, qr, opts) {
2816
+ const size = qr.modules.size;
2817
+ const data = qr.modules.data;
2818
+ const scale = exports$1.getScale(size, opts);
2819
+ const symbolSize = Math.floor((size + opts.margin * 2) * scale);
2820
+ const scaledMargin = opts.margin * scale;
2821
+ const palette = [opts.color.light, opts.color.dark];
2822
+
2823
+ for (let i = 0; i < symbolSize; i++) {
2824
+ for (let j = 0; j < symbolSize; j++) {
2825
+ let posDst = (i * symbolSize + j) * 4;
2826
+ let pxColor = opts.color.light;
2827
+
2828
+ if (i >= scaledMargin && j >= scaledMargin &&
2829
+ i < symbolSize - scaledMargin && j < symbolSize - scaledMargin) {
2830
+ const iSrc = Math.floor((i - scaledMargin) / scale);
2831
+ const jSrc = Math.floor((j - scaledMargin) / scale);
2832
+ pxColor = palette[data[iSrc * size + jSrc] ? 1 : 0];
2833
+ }
2834
+
2835
+ imgData[posDst++] = pxColor.r;
2836
+ imgData[posDst++] = pxColor.g;
2837
+ imgData[posDst++] = pxColor.b;
2838
+ imgData[posDst] = pxColor.a;
2839
+ }
2840
+ }
2841
+ };
2842
+ } (utils));
2843
+ return utils;
2844
+ }
2845
+
2846
+ var hasRequiredCanvas;
2847
+
2848
+ function requireCanvas () {
2849
+ if (hasRequiredCanvas) return canvas;
2850
+ hasRequiredCanvas = 1;
2851
+ (function (exports$1) {
2852
+ const Utils = requireUtils();
2853
+
2854
+ function clearCanvas (ctx, canvas, size) {
2855
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
2856
+
2857
+ if (!canvas.style) canvas.style = {};
2858
+ canvas.height = size;
2859
+ canvas.width = size;
2860
+ canvas.style.height = size + 'px';
2861
+ canvas.style.width = size + 'px';
2862
+ }
2863
+
2864
+ function getCanvasElement () {
2865
+ try {
2866
+ return document.createElement('canvas')
2867
+ } catch (e) {
2868
+ throw new Error('You need to specify a canvas element')
2869
+ }
2870
+ }
2871
+
2872
+ exports$1.render = function render (qrData, canvas, options) {
2873
+ let opts = options;
2874
+ let canvasEl = canvas;
2875
+
2876
+ if (typeof opts === 'undefined' && (!canvas || !canvas.getContext)) {
2877
+ opts = canvas;
2878
+ canvas = undefined;
2879
+ }
2880
+
2881
+ if (!canvas) {
2882
+ canvasEl = getCanvasElement();
2883
+ }
2884
+
2885
+ opts = Utils.getOptions(opts);
2886
+ const size = Utils.getImageWidth(qrData.modules.size, opts);
2887
+
2888
+ const ctx = canvasEl.getContext('2d');
2889
+ const image = ctx.createImageData(size, size);
2890
+ Utils.qrToImageData(image.data, qrData, opts);
2891
+
2892
+ clearCanvas(ctx, canvasEl, size);
2893
+ ctx.putImageData(image, 0, 0);
2894
+
2895
+ return canvasEl
2896
+ };
2897
+
2898
+ exports$1.renderToDataURL = function renderToDataURL (qrData, canvas, options) {
2899
+ let opts = options;
2900
+
2901
+ if (typeof opts === 'undefined' && (!canvas || !canvas.getContext)) {
2902
+ opts = canvas;
2903
+ canvas = undefined;
2904
+ }
2905
+
2906
+ if (!opts) opts = {};
2907
+
2908
+ const canvasEl = exports$1.render(qrData, canvas, opts);
2909
+
2910
+ const type = opts.type || 'image/png';
2911
+ const rendererOpts = opts.rendererOpts || {};
2912
+
2913
+ return canvasEl.toDataURL(type, rendererOpts.quality)
2914
+ };
2915
+ } (canvas));
2916
+ return canvas;
2917
+ }
2918
+
2919
+ var svgTag = {};
2920
+
2921
+ var hasRequiredSvgTag;
2922
+
2923
+ function requireSvgTag () {
2924
+ if (hasRequiredSvgTag) return svgTag;
2925
+ hasRequiredSvgTag = 1;
2926
+ const Utils = requireUtils();
2927
+
2928
+ function getColorAttrib (color, attrib) {
2929
+ const alpha = color.a / 255;
2930
+ const str = attrib + '="' + color.hex + '"';
2931
+
2932
+ return alpha < 1
2933
+ ? str + ' ' + attrib + '-opacity="' + alpha.toFixed(2).slice(1) + '"'
2934
+ : str
2935
+ }
2936
+
2937
+ function svgCmd (cmd, x, y) {
2938
+ let str = cmd + x;
2939
+ if (typeof y !== 'undefined') str += ' ' + y;
2940
+
2941
+ return str
2942
+ }
2943
+
2944
+ function qrToPath (data, size, margin) {
2945
+ let path = '';
2946
+ let moveBy = 0;
2947
+ let newRow = false;
2948
+ let lineLength = 0;
2949
+
2950
+ for (let i = 0; i < data.length; i++) {
2951
+ const col = Math.floor(i % size);
2952
+ const row = Math.floor(i / size);
2953
+
2954
+ if (!col && !newRow) newRow = true;
2955
+
2956
+ if (data[i]) {
2957
+ lineLength++;
2958
+
2959
+ if (!(i > 0 && col > 0 && data[i - 1])) {
2960
+ path += newRow
2961
+ ? svgCmd('M', col + margin, 0.5 + row + margin)
2962
+ : svgCmd('m', moveBy, 0);
2963
+
2964
+ moveBy = 0;
2965
+ newRow = false;
2966
+ }
2967
+
2968
+ if (!(col + 1 < size && data[i + 1])) {
2969
+ path += svgCmd('h', lineLength);
2970
+ lineLength = 0;
2971
+ }
2972
+ } else {
2973
+ moveBy++;
2974
+ }
2975
+ }
2976
+
2977
+ return path
2978
+ }
2979
+
2980
+ svgTag.render = function render (qrData, options, cb) {
2981
+ const opts = Utils.getOptions(options);
2982
+ const size = qrData.modules.size;
2983
+ const data = qrData.modules.data;
2984
+ const qrcodesize = size + opts.margin * 2;
2985
+
2986
+ const bg = !opts.color.light.a
2987
+ ? ''
2988
+ : '<path ' + getColorAttrib(opts.color.light, 'fill') +
2989
+ ' d="M0 0h' + qrcodesize + 'v' + qrcodesize + 'H0z"/>';
2990
+
2991
+ const path =
2992
+ '<path ' + getColorAttrib(opts.color.dark, 'stroke') +
2993
+ ' d="' + qrToPath(data, size, opts.margin) + '"/>';
2994
+
2995
+ const viewBox = 'viewBox="' + '0 0 ' + qrcodesize + ' ' + qrcodesize + '"';
2996
+
2997
+ const width = !opts.width ? '' : 'width="' + opts.width + '" height="' + opts.width + '" ';
2998
+
2999
+ const svgTag = '<svg xmlns="http://www.w3.org/2000/svg" ' + width + viewBox + ' shape-rendering="crispEdges">' + bg + path + '</svg>\n';
3000
+
3001
+ if (typeof cb === 'function') {
3002
+ cb(null, svgTag);
3003
+ }
3004
+
3005
+ return svgTag
3006
+ };
3007
+ return svgTag;
3008
+ }
3009
+
3010
+ var hasRequiredBrowser;
3011
+
3012
+ function requireBrowser () {
3013
+ if (hasRequiredBrowser) return browser;
3014
+ hasRequiredBrowser = 1;
3015
+ const canPromise = requireCanPromise();
3016
+
3017
+ const QRCode = requireQrcode();
3018
+ const CanvasRenderer = requireCanvas();
3019
+ const SvgRenderer = requireSvgTag();
3020
+
3021
+ function renderCanvas (renderFunc, canvas, text, opts, cb) {
3022
+ const args = [].slice.call(arguments, 1);
3023
+ const argsNum = args.length;
3024
+ const isLastArgCb = typeof args[argsNum - 1] === 'function';
3025
+
3026
+ if (!isLastArgCb && !canPromise()) {
3027
+ throw new Error('Callback required as last argument')
3028
+ }
3029
+
3030
+ if (isLastArgCb) {
3031
+ if (argsNum < 2) {
3032
+ throw new Error('Too few arguments provided')
3033
+ }
3034
+
3035
+ if (argsNum === 2) {
3036
+ cb = text;
3037
+ text = canvas;
3038
+ canvas = opts = undefined;
3039
+ } else if (argsNum === 3) {
3040
+ if (canvas.getContext && typeof cb === 'undefined') {
3041
+ cb = opts;
3042
+ opts = undefined;
3043
+ } else {
3044
+ cb = opts;
3045
+ opts = text;
3046
+ text = canvas;
3047
+ canvas = undefined;
3048
+ }
3049
+ }
3050
+ } else {
3051
+ if (argsNum < 1) {
3052
+ throw new Error('Too few arguments provided')
3053
+ }
3054
+
3055
+ if (argsNum === 1) {
3056
+ text = canvas;
3057
+ canvas = opts = undefined;
3058
+ } else if (argsNum === 2 && !canvas.getContext) {
3059
+ opts = text;
3060
+ text = canvas;
3061
+ canvas = undefined;
3062
+ }
3063
+
3064
+ return new Promise(function (resolve, reject) {
3065
+ try {
3066
+ const data = QRCode.create(text, opts);
3067
+ resolve(renderFunc(data, canvas, opts));
3068
+ } catch (e) {
3069
+ reject(e);
3070
+ }
3071
+ })
3072
+ }
3073
+
3074
+ try {
3075
+ const data = QRCode.create(text, opts);
3076
+ cb(null, renderFunc(data, canvas, opts));
3077
+ } catch (e) {
3078
+ cb(e);
3079
+ }
3080
+ }
3081
+
3082
+ browser.create = QRCode.create;
3083
+ browser.toCanvas = renderCanvas.bind(null, CanvasRenderer.render);
3084
+ browser.toDataURL = renderCanvas.bind(null, CanvasRenderer.renderToDataURL);
3085
+
3086
+ // only svg for now.
3087
+ browser.toString = renderCanvas.bind(null, function (data, _, opts) {
3088
+ return SvgRenderer.render(data, opts)
3089
+ });
3090
+ return browser;
3091
+ }
3092
+
3093
+ var browserExports = requireBrowser();
3094
+ var QRCode = /*@__PURE__*/getDefaultExportFromCjs(browserExports);
3095
+
3096
+ /** Name of the feature. */
3097
+ const StandardConnect = 'standard:connect';
3098
+
3099
+ /** Name of the feature. */
3100
+ const StandardDisconnect = 'standard:disconnect';
3101
+
3102
+ /** Name of the feature. */
3103
+ const StandardEvents = 'standard:events';
3104
+
3105
+ var src;
3106
+ var hasRequiredSrc;
3107
+
3108
+ function requireSrc () {
3109
+ if (hasRequiredSrc) return src;
3110
+ hasRequiredSrc = 1;
3111
+ // base-x encoding / decoding
3112
+ // Copyright (c) 2018 base-x contributors
3113
+ // Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
3114
+ // Distributed under the MIT software license, see the accompanying
3115
+ // file LICENSE or http://www.opensource.org/licenses/mit-license.php.
3116
+ function base (ALPHABET) {
3117
+ if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
3118
+ var BASE_MAP = new Uint8Array(256);
3119
+ for (var j = 0; j < BASE_MAP.length; j++) {
3120
+ BASE_MAP[j] = 255;
3121
+ }
3122
+ for (var i = 0; i < ALPHABET.length; i++) {
3123
+ var x = ALPHABET.charAt(i);
3124
+ var xc = x.charCodeAt(0);
3125
+ if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
3126
+ BASE_MAP[xc] = i;
3127
+ }
3128
+ var BASE = ALPHABET.length;
3129
+ var LEADER = ALPHABET.charAt(0);
3130
+ var FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
3131
+ var iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
3132
+ function encode (source) {
3133
+ if (source instanceof Uint8Array) ; else if (ArrayBuffer.isView(source)) {
3134
+ source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
3135
+ } else if (Array.isArray(source)) {
3136
+ source = Uint8Array.from(source);
3137
+ }
3138
+ if (!(source instanceof Uint8Array)) { throw new TypeError('Expected Uint8Array') }
3139
+ if (source.length === 0) { return '' }
3140
+ // Skip & count leading zeroes.
3141
+ var zeroes = 0;
3142
+ var length = 0;
3143
+ var pbegin = 0;
3144
+ var pend = source.length;
3145
+ while (pbegin !== pend && source[pbegin] === 0) {
3146
+ pbegin++;
3147
+ zeroes++;
3148
+ }
3149
+ // Allocate enough space in big-endian base58 representation.
3150
+ var size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
3151
+ var b58 = new Uint8Array(size);
3152
+ // Process the bytes.
3153
+ while (pbegin !== pend) {
3154
+ var carry = source[pbegin];
3155
+ // Apply "b58 = b58 * 256 + ch".
3156
+ var i = 0;
3157
+ for (var it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
3158
+ carry += (256 * b58[it1]) >>> 0;
3159
+ b58[it1] = (carry % BASE) >>> 0;
3160
+ carry = (carry / BASE) >>> 0;
3161
+ }
3162
+ if (carry !== 0) { throw new Error('Non-zero carry') }
3163
+ length = i;
3164
+ pbegin++;
3165
+ }
3166
+ // Skip leading zeroes in base58 result.
3167
+ var it2 = size - length;
3168
+ while (it2 !== size && b58[it2] === 0) {
3169
+ it2++;
3170
+ }
3171
+ // Translate the result into a string.
3172
+ var str = LEADER.repeat(zeroes);
3173
+ for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]); }
3174
+ return str
3175
+ }
3176
+ function decodeUnsafe (source) {
3177
+ if (typeof source !== 'string') { throw new TypeError('Expected String') }
3178
+ if (source.length === 0) { return new Uint8Array() }
3179
+ var psz = 0;
3180
+ // Skip and count leading '1's.
3181
+ var zeroes = 0;
3182
+ var length = 0;
3183
+ while (source[psz] === LEADER) {
3184
+ zeroes++;
3185
+ psz++;
3186
+ }
3187
+ // Allocate enough space in big-endian base256 representation.
3188
+ var size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
3189
+ var b256 = new Uint8Array(size);
3190
+ // Process the characters.
3191
+ while (source[psz]) {
3192
+ // Find code of next character
3193
+ var charCode = source.charCodeAt(psz);
3194
+ // Base map can not be indexed using char code
3195
+ if (charCode > 255) { return }
3196
+ // Decode character
3197
+ var carry = BASE_MAP[charCode];
3198
+ // Invalid character
3199
+ if (carry === 255) { return }
3200
+ var i = 0;
3201
+ for (var it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
3202
+ carry += (BASE * b256[it3]) >>> 0;
3203
+ b256[it3] = (carry % 256) >>> 0;
3204
+ carry = (carry / 256) >>> 0;
3205
+ }
3206
+ if (carry !== 0) { throw new Error('Non-zero carry') }
3207
+ length = i;
3208
+ psz++;
3209
+ }
3210
+ // Skip leading zeroes in b256.
3211
+ var it4 = size - length;
3212
+ while (it4 !== size && b256[it4] === 0) {
3213
+ it4++;
3214
+ }
3215
+ var vch = new Uint8Array(zeroes + (size - it4));
3216
+ var j = zeroes;
3217
+ while (it4 !== size) {
3218
+ vch[j++] = b256[it4++];
3219
+ }
3220
+ return vch
3221
+ }
3222
+ function decode (string) {
3223
+ var buffer = decodeUnsafe(string);
3224
+ if (buffer) { return buffer }
3225
+ throw new Error('Non-base' + BASE + ' character')
3226
+ }
3227
+ return {
3228
+ encode: encode,
3229
+ decodeUnsafe: decodeUnsafe,
3230
+ decode: decode
3231
+ }
3232
+ }
3233
+ src = base;
3234
+ return src;
3235
+ }
3236
+
3237
+ var bs58;
3238
+ var hasRequiredBs58;
3239
+
3240
+ function requireBs58 () {
3241
+ if (hasRequiredBs58) return bs58;
3242
+ hasRequiredBs58 = 1;
3243
+ const basex = requireSrc();
3244
+ const ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
3245
+
3246
+ bs58 = basex(ALPHABET);
3247
+ return bs58;
3248
+ }
3249
+
3250
+ var bs58Exports = requireBs58();
3251
+ var base58 = /*@__PURE__*/getDefaultExportFromCjs(bs58Exports);
3252
+
3253
+ /******************************************************************************
3254
+ Copyright (c) Microsoft Corporation.
3255
+
3256
+ Permission to use, copy, modify, and/or distribute this software for any
3257
+ purpose with or without fee is hereby granted.
3258
+
3259
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
3260
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
3261
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
3262
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
3263
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
3264
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
3265
+ PERFORMANCE OF THIS SOFTWARE.
3266
+ ***************************************************************************** */
3267
+
3268
+ function __awaiter(thisArg, _arguments, P, generator) {
3269
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3270
+ return new (P || (P = Promise))(function (resolve, reject) {
3271
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
3272
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
3273
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
3274
+ step((generator = generator.apply(thisArg, [])).next());
3275
+ });
3276
+ }
3277
+
3278
+ function __classPrivateFieldGet$1(receiver, state, kind, f) {
3279
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3280
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
3281
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
3282
+ }
3283
+
3284
+ function __classPrivateFieldSet$1(receiver, state, value, kind, f) {
3285
+ if (typeof state === "function" ? receiver !== state || true : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
3286
+ return (state.set(receiver, value)), value;
3287
+ }
3288
+
3289
+ var _EmbeddedModal_instances, _EmbeddedModal_root, _EmbeddedModal_eventListeners, _EmbeddedModal_listenersAttached, _EmbeddedModal_injectHTML, _EmbeddedModal_attachEventListeners, _EmbeddedModal_removeEventListeners, _EmbeddedModal_handleKeyDown;
3290
+ const modalHtml = `
3291
+ <div class="mobile-wallet-adapter-embedded-modal-container" role="dialog" aria-modal="true" aria-labelledby="modal-title">
3292
+ <div data-modal-close style="position: absolute; width: 100%; height: 100%;"></div>
3293
+ <div class="mobile-wallet-adapter-embedded-modal-card">
3294
+ <div>
3295
+ <button data-modal-close class="mobile-wallet-adapter-embedded-modal-close">
3296
+ <svg width="14" height="14">
3297
+ <path d="M 6.7125,8.3036995 1.9082,13.108199 c -0.2113,0.2112 -0.4765,0.3168 -0.7957,0.3168 -0.3192,0 -0.5844,-0.1056 -0.7958,-0.3168 C 0.1056,12.896899 0,12.631699 0,12.312499 c 0,-0.3192 0.1056,-0.5844 0.3167,-0.7958 L 5.1212,6.7124995 0.3167,1.9082 C 0.1056,1.6969 0,1.4317 0,1.1125 0,0.7933 0.1056,0.5281 0.3167,0.3167 0.5281,0.1056 0.7933,0 1.1125,0 1.4317,0 1.6969,0.1056 1.9082,0.3167 L 6.7125,5.1212 11.5167,0.3167 C 11.7281,0.1056 11.9933,0 12.3125,0 c 0.3192,0 0.5844,0.1056 0.7957,0.3167 0.2112,0.2114 0.3168,0.4766 0.3168,0.7958 0,0.3192 -0.1056,0.5844 -0.3168,0.7957 L 8.3037001,6.7124995 13.1082,11.516699 c 0.2112,0.2114 0.3168,0.4766 0.3168,0.7958 0,0.3192 -0.1056,0.5844 -0.3168,0.7957 -0.2113,0.2112 -0.4765,0.3168 -0.7957,0.3168 -0.3192,0 -0.5844,-0.1056 -0.7958,-0.3168 z" />
3298
+ </svg>
3299
+ </button>
3300
+ </div>
3301
+ <div class="mobile-wallet-adapter-embedded-modal-content"></div>
3302
+ </div>
3303
+ </div>
3304
+ `;
3305
+ const css$2 = `
3306
+ .mobile-wallet-adapter-embedded-modal-container {
3307
+ display: flex; /* Use flexbox to center content */
3308
+ justify-content: center; /* Center horizontally */
3309
+ align-items: center; /* Center vertically */
3310
+ position: fixed; /* Stay in place */
3311
+ z-index: 1; /* Sit on top */
3312
+ left: 0;
3313
+ top: 0;
3314
+ width: 100%; /* Full width */
3315
+ height: 100%; /* Full height */
3316
+ background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
3317
+ overflow-y: auto; /* enable scrolling */
3318
+ }
3319
+
3320
+ .mobile-wallet-adapter-embedded-modal-card {
3321
+ display: flex;
3322
+ flex-direction: column;
3323
+ margin: auto 20px;
3324
+ max-width: 780px;
3325
+ padding: 20px;
3326
+ border-radius: 24px;
3327
+ background: #ffffff;
3328
+ font-family: "Inter Tight", "PT Sans", Calibri, sans-serif;
3329
+ transform: translateY(-200%);
3330
+ animation: slide-in 0.5s forwards;
3331
+ }
3332
+
3333
+ @keyframes slide-in {
3334
+ 100% { transform: translateY(0%); }
3335
+ }
3336
+
3337
+ .mobile-wallet-adapter-embedded-modal-close {
3338
+ display: flex;
3339
+ align-items: center;
3340
+ justify-content: center;
3341
+ width: 32px;
3342
+ height: 32px;
3343
+ cursor: pointer;
3344
+ background: #e4e9e9;
3345
+ border: none;
3346
+ border-radius: 50%;
3347
+ }
3348
+
3349
+ .mobile-wallet-adapter-embedded-modal-close:focus-visible {
3350
+ outline-color: red;
3351
+ }
3352
+
3353
+ .mobile-wallet-adapter-embedded-modal-close svg {
3354
+ fill: #546266;
3355
+ transition: fill 200ms ease 0s;
3356
+ }
3357
+
3358
+ .mobile-wallet-adapter-embedded-modal-close:hover svg {
3359
+ fill: #fff;
3360
+ }
3361
+ `;
3362
+ const fonts = `
3363
+ <link rel="preconnect" href="https://fonts.googleapis.com">
3364
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
3365
+ <link href="https://fonts.googleapis.com/css2?family=Inter+Tight:ital,wght@0,100..900;1,100..900&display=swap" rel="stylesheet">
3366
+ `;
3367
+ class EmbeddedModal {
3368
+ constructor() {
3369
+ _EmbeddedModal_instances.add(this);
3370
+ _EmbeddedModal_root.set(this, null);
3371
+ _EmbeddedModal_eventListeners.set(this, {});
3372
+ _EmbeddedModal_listenersAttached.set(this, false);
3373
+ this.dom = null;
3374
+ this.open = () => {
3375
+ console.debug('Modal open');
3376
+ __classPrivateFieldGet$1(this, _EmbeddedModal_instances, "m", _EmbeddedModal_attachEventListeners).call(this);
3377
+ if (__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f")) {
3378
+ __classPrivateFieldGet$1(this, _EmbeddedModal_root, "f").style.display = 'flex';
3379
+ }
3380
+ };
3381
+ this.close = (event = undefined) => {
3382
+ var _a;
3383
+ console.debug('Modal close');
3384
+ __classPrivateFieldGet$1(this, _EmbeddedModal_instances, "m", _EmbeddedModal_removeEventListeners).call(this);
3385
+ if (__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f")) {
3386
+ __classPrivateFieldGet$1(this, _EmbeddedModal_root, "f").style.display = 'none';
3387
+ }
3388
+ (_a = __classPrivateFieldGet$1(this, _EmbeddedModal_eventListeners, "f")['close']) === null || _a === void 0 ? void 0 : _a.forEach((listener) => listener(event));
3389
+ };
3390
+ _EmbeddedModal_handleKeyDown.set(this, (event) => {
3391
+ if (event.key === 'Escape')
3392
+ this.close(event);
3393
+ });
3394
+ // Bind methods to ensure `this` context is correct
3395
+ this.init = this.init.bind(this);
3396
+ __classPrivateFieldSet$1(this, _EmbeddedModal_root, document.getElementById('mobile-wallet-adapter-embedded-root-ui'));
3397
+ }
3398
+ init() {
3399
+ return __awaiter(this, void 0, void 0, function* () {
3400
+ console.log('Injecting modal');
3401
+ __classPrivateFieldGet$1(this, _EmbeddedModal_instances, "m", _EmbeddedModal_injectHTML).call(this);
3402
+ });
3403
+ }
3404
+ addEventListener(event, listener) {
3405
+ var _a;
3406
+ ((_a = __classPrivateFieldGet$1(this, _EmbeddedModal_eventListeners, "f")[event]) === null || _a === void 0 ? void 0 : _a.push(listener)) || (__classPrivateFieldGet$1(this, _EmbeddedModal_eventListeners, "f")[event] = [listener]);
3407
+ return () => this.removeEventListener(event, listener);
3408
+ }
3409
+ removeEventListener(event, listener) {
3410
+ var _a;
3411
+ __classPrivateFieldGet$1(this, _EmbeddedModal_eventListeners, "f")[event] = (_a = __classPrivateFieldGet$1(this, _EmbeddedModal_eventListeners, "f")[event]) === null || _a === void 0 ? void 0 : _a.filter((existingListener) => listener !== existingListener);
3412
+ }
3413
+ }
3414
+ _EmbeddedModal_root = new WeakMap(), _EmbeddedModal_eventListeners = new WeakMap(), _EmbeddedModal_listenersAttached = new WeakMap(), _EmbeddedModal_handleKeyDown = new WeakMap(), _EmbeddedModal_instances = new WeakSet(), _EmbeddedModal_injectHTML = function _EmbeddedModal_injectHTML() {
3415
+ // Check if the HTML has already been injected
3416
+ if (document.getElementById('mobile-wallet-adapter-embedded-root-ui')) {
3417
+ if (!__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f"))
3418
+ __classPrivateFieldSet$1(this, _EmbeddedModal_root, document.getElementById('mobile-wallet-adapter-embedded-root-ui'));
3419
+ return;
3420
+ }
3421
+ // Create a container for the modal
3422
+ __classPrivateFieldSet$1(this, _EmbeddedModal_root, document.createElement('div'));
3423
+ __classPrivateFieldGet$1(this, _EmbeddedModal_root, "f").id = 'mobile-wallet-adapter-embedded-root-ui';
3424
+ __classPrivateFieldGet$1(this, _EmbeddedModal_root, "f").innerHTML = modalHtml;
3425
+ __classPrivateFieldGet$1(this, _EmbeddedModal_root, "f").style.display = 'none';
3426
+ // Add modal content
3427
+ const content = __classPrivateFieldGet$1(this, _EmbeddedModal_root, "f").querySelector('.mobile-wallet-adapter-embedded-modal-content');
3428
+ if (content)
3429
+ content.innerHTML = this.contentHtml;
3430
+ // Apply styles
3431
+ const styles = document.createElement('style');
3432
+ styles.id = 'mobile-wallet-adapter-embedded-modal-styles';
3433
+ styles.textContent = css$2 + this.contentStyles;
3434
+ // Create a shadow DOM to encapsulate the modal
3435
+ const host = document.createElement('div');
3436
+ host.innerHTML = fonts;
3437
+ this.dom = host.attachShadow({ mode: 'closed' });
3438
+ this.dom.appendChild(styles);
3439
+ this.dom.appendChild(__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f"));
3440
+ // Append the shadow DOM host to the body
3441
+ document.body.appendChild(host);
3442
+ }, _EmbeddedModal_attachEventListeners = function _EmbeddedModal_attachEventListeners() {
3443
+ if (!__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f") || __classPrivateFieldGet$1(this, _EmbeddedModal_listenersAttached, "f"))
3444
+ return;
3445
+ const closers = [...__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f").querySelectorAll('[data-modal-close]')];
3446
+ closers.forEach(closer => closer === null || closer === void 0 ? void 0 : closer.addEventListener('click', this.close));
3447
+ window.addEventListener('load', this.close);
3448
+ document.addEventListener('keydown', __classPrivateFieldGet$1(this, _EmbeddedModal_handleKeyDown, "f"));
3449
+ __classPrivateFieldSet$1(this, _EmbeddedModal_listenersAttached, true);
3450
+ }, _EmbeddedModal_removeEventListeners = function _EmbeddedModal_removeEventListeners() {
3451
+ if (!__classPrivateFieldGet$1(this, _EmbeddedModal_listenersAttached, "f"))
3452
+ return;
3453
+ window.removeEventListener('load', this.close);
3454
+ document.removeEventListener('keydown', __classPrivateFieldGet$1(this, _EmbeddedModal_handleKeyDown, "f"));
3455
+ if (!__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f"))
3456
+ return;
3457
+ const closers = [...__classPrivateFieldGet$1(this, _EmbeddedModal_root, "f").querySelectorAll('[data-modal-close]')];
3458
+ closers.forEach(closer => closer === null || closer === void 0 ? void 0 : closer.removeEventListener('click', this.close));
3459
+ __classPrivateFieldSet$1(this, _EmbeddedModal_listenersAttached, false);
3460
+ };
3461
+
3462
+ class RemoteConnectionModal extends EmbeddedModal {
3463
+ constructor() {
3464
+ super(...arguments);
3465
+ this.contentStyles = css$1;
3466
+ this.contentHtml = QRCodeHtml;
3467
+ }
3468
+ initWithQR(qrCode) {
3469
+ const _super = Object.create(null, {
3470
+ init: { get: () => super.init }
3471
+ });
3472
+ return __awaiter(this, void 0, void 0, function* () {
3473
+ _super.init.call(this);
3474
+ this.populateQRCode(qrCode);
3475
+ });
3476
+ }
3477
+ populateQRCode(qrUrl) {
3478
+ var _a;
3479
+ return __awaiter(this, void 0, void 0, function* () {
3480
+ const qrcodeContainer = (_a = this.dom) === null || _a === void 0 ? void 0 : _a.getElementById('mobile-wallet-adapter-embedded-modal-qr-code-container');
3481
+ if (qrcodeContainer) {
3482
+ const qrCodeElement = yield QRCode.toCanvas(qrUrl, { width: 200, margin: 0 });
3483
+ if (qrcodeContainer.firstElementChild !== null) {
3484
+ qrcodeContainer.replaceChild(qrCodeElement, qrcodeContainer.firstElementChild);
3485
+ }
3486
+ else
3487
+ qrcodeContainer.appendChild(qrCodeElement);
3488
+ }
3489
+ else {
3490
+ console.error('QRCode Container not found');
3491
+ }
3492
+ });
3493
+ }
3494
+ }
3495
+ const QRCodeHtml = `
3496
+ <div class="mobile-wallet-adapter-embedded-modal-qr-content">
3497
+ <div>
3498
+ <svg class="mobile-wallet-adapter-embedded-modal-icon" width="100%" height="100%">
3499
+ <circle r="52" cx="53" cy="53" fill="#99b3be" stroke="#000000" stroke-width="2"/>
3500
+ <path d="m 53,82.7305 c -3.3116,0 -6.1361,-1.169 -8.4735,-3.507 -2.338,-2.338 -3.507,-5.1625 -3.507,-8.4735 0,-3.3116 1.169,-6.1364 3.507,-8.4744 2.3374,-2.338 5.1619,-3.507 8.4735,-3.507 3.3116,0 6.1361,1.169 8.4735,3.507 2.338,2.338 3.507,5.1628 3.507,8.4744 0,3.311 -1.169,6.1355 -3.507,8.4735 -2.3374,2.338 -5.1619,3.507 -8.4735,3.507 z m 0.007,-5.25 c 1.8532,0 3.437,-0.6598 4.7512,-1.9793 1.3149,-1.3195 1.9723,-2.9058 1.9723,-4.7591 0,-1.8526 -0.6598,-3.4364 -1.9793,-4.7512 -1.3195,-1.3149 -2.9055,-1.9723 -4.7582,-1.9723 -1.8533,0 -3.437,0.6598 -4.7513,1.9793 -1.3148,1.3195 -1.9722,2.9058 -1.9722,4.7591 0,1.8527 0.6597,3.4364 1.9792,4.7512 1.3195,1.3149 2.9056,1.9723 4.7583,1.9723 z m -28,-33.5729 -3.85,-3.6347 c 4.1195,-4.025 8.8792,-7.1984 14.2791,-9.52 5.4005,-2.3223 11.2551,-3.4834 17.5639,-3.4834 6.3087,0 12.1634,1.1611 17.5639,3.4834 5.3999,2.3216 10.1596,5.495 14.2791,9.52 l -3.85,3.6347 C 77.2999,40.358 73.0684,37.5726 68.2985,35.5514 63.5292,33.5301 58.4296,32.5195 53,32.5195 c -5.4297,0 -10.5292,1.0106 -15.2985,3.0319 -4.7699,2.0212 -9.0014,4.8066 -12.6945,8.3562 z m 44.625,10.8771 c -2.2709,-2.1046 -4.7962,-3.7167 -7.5758,-4.8361 -2.7795,-1.12 -5.7983,-1.68 -9.0562,-1.68 -3.2579,0 -6.2621,0.56 -9.0125,1.68 -2.7504,1.1194 -5.2903,2.7315 -7.6195,4.8361 L 32.5189,51.15 c 2.8355,-2.6028 5.9777,-4.6086 9.4263,-6.0174 3.4481,-1.4087 7.133,-2.1131 11.0548,-2.1131 3.9217,0 7.5979,0.7044 11.0285,2.1131 3.43,1.4088 6.5631,3.4146 9.3992,6.0174 z"/>
3501
+ </svg>
3502
+ <div class="mobile-wallet-adapter-embedded-modal-title">Remote Mobile Wallet Adapter</div>
3503
+ </div>
3504
+ <div>
3505
+ <div>
3506
+ <h4 class="mobile-wallet-adapter-embedded-modal-qr-label">
3507
+ Open your wallet and scan this code
3508
+ </h4>
3509
+ </div>
3510
+ <div id="mobile-wallet-adapter-embedded-modal-qr-code-container" class="mobile-wallet-adapter-embedded-modal-qr-code-container"></div>
3511
+ </div>
3512
+ </div>
3513
+ <div class="mobile-wallet-adapter-embedded-modal-divider"><hr></div>
3514
+ <div class="mobile-wallet-adapter-embedded-modal-footer">
3515
+ <div class="mobile-wallet-adapter-embedded-modal-subtitle">
3516
+ Follow the instructions on your device. When you're finished, this screen will update.
3517
+ </div>
3518
+ <div class="mobile-wallet-adapter-embedded-modal-progress-badge">
3519
+ <div>
3520
+ <div class="spinner">
3521
+ <div class="leftWrapper">
3522
+ <div class="left">
3523
+ <div class="circle"></div>
3524
+ </div>
3525
+ </div>
3526
+ <div class="rightWrapper">
3527
+ <div class="right">
3528
+ <div class="circle"></div>
3529
+ </div>
3530
+ </div>
3531
+ </div>
3532
+ </div>
3533
+ <div>Waiting for scan</div>
3534
+ </div>
3535
+ </div>
3536
+ `;
3537
+ const css$1 = `
3538
+ .mobile-wallet-adapter-embedded-modal-qr-content {
3539
+ display: flex;
3540
+ margin-top: 10px;
3541
+ padding: 10px;
3542
+ }
3543
+
3544
+ .mobile-wallet-adapter-embedded-modal-qr-content > div:first-child {
3545
+ display: flex;
3546
+ flex-direction: column;
3547
+ flex: 2;
3548
+ margin-top: auto;
3549
+ margin-right: 30px;
3550
+ }
3551
+
3552
+ .mobile-wallet-adapter-embedded-modal-qr-content > div:nth-child(2) {
3553
+ display: flex;
3554
+ flex-direction: column;
3555
+ flex: 1;
3556
+ margin-left: auto;
3557
+ }
3558
+
3559
+ .mobile-wallet-adapter-embedded-modal-footer {
3560
+ display: flex;
3561
+ padding: 10px;
3562
+ }
3563
+
3564
+ .mobile-wallet-adapter-embedded-modal-icon {}
3565
+
3566
+ .mobile-wallet-adapter-embedded-modal-title {
3567
+ color: #000000;
3568
+ font-size: 2.5em;
3569
+ font-weight: 600;
3570
+ }
3571
+
3572
+ .mobile-wallet-adapter-embedded-modal-qr-label {
3573
+ text-align: right;
3574
+ color: #000000;
3575
+ }
3576
+
3577
+ .mobile-wallet-adapter-embedded-modal-qr-code-container {
3578
+ margin-left: auto;
3579
+ }
3580
+
3581
+ .mobile-wallet-adapter-embedded-modal-divider {
3582
+ margin-top: 20px;
3583
+ padding-left: 10px;
3584
+ padding-right: 10px;
3585
+ }
3586
+
3587
+ .mobile-wallet-adapter-embedded-modal-divider hr {
3588
+ border-top: 1px solid #D9DEDE;
3589
+ }
3590
+
3591
+ .mobile-wallet-adapter-embedded-modal-subtitle {
3592
+ margin: auto;
3593
+ margin-right: 60px;
3594
+ padding: 20px;
3595
+ color: #6E8286;
3596
+ }
3597
+
3598
+ .mobile-wallet-adapter-embedded-modal-progress-badge {
3599
+ display: flex;
3600
+ background: #F7F8F8;
3601
+ height: 56px;
3602
+ min-width: 200px;
3603
+ margin: auto;
3604
+ padding-left: 20px;
3605
+ padding-right: 20px;
3606
+ border-radius: 18px;
3607
+ color: #A8B6B8;
3608
+ align-items: center;
3609
+ }
3610
+
3611
+ .mobile-wallet-adapter-embedded-modal-progress-badge > div:first-child {
3612
+ margin-left: auto;
3613
+ margin-right: 20px;
3614
+ }
3615
+
3616
+ .mobile-wallet-adapter-embedded-modal-progress-badge > div:nth-child(2) {
3617
+ margin-right: auto;
3618
+ }
3619
+
3620
+ /* Smaller screens */
3621
+ @media all and (max-width: 600px) {
3622
+ .mobile-wallet-adapter-embedded-modal-card {
3623
+ text-align: center;
3624
+ }
3625
+ .mobile-wallet-adapter-embedded-modal-qr-content {
3626
+ flex-direction: column;
3627
+ }
3628
+ .mobile-wallet-adapter-embedded-modal-qr-content > div:first-child {
3629
+ margin: auto;
3630
+ }
3631
+ .mobile-wallet-adapter-embedded-modal-qr-content > div:nth-child(2) {
3632
+ margin: auto;
3633
+ flex: 2 auto;
3634
+ }
3635
+ .mobile-wallet-adapter-embedded-modal-footer {
3636
+ flex-direction: column;
3637
+ }
3638
+ .mobile-wallet-adapter-embedded-modal-icon {
3639
+ display: none;
3640
+ }
3641
+ .mobile-wallet-adapter-embedded-modal-title {
3642
+ font-size: 1.5em;
3643
+ }
3644
+ .mobile-wallet-adapter-embedded-modal-subtitle {
3645
+ margin-right: unset;
3646
+ }
3647
+ .mobile-wallet-adapter-embedded-modal-qr-label {
3648
+ text-align: center;
3649
+ }
3650
+ .mobile-wallet-adapter-embedded-modal-qr-code-container {
3651
+ margin: auto;
3652
+ }
3653
+ }
3654
+
3655
+ /* Spinner */
3656
+ @keyframes spinLeft {
3657
+ 0% {
3658
+ transform: rotate(20deg);
3659
+ }
3660
+ 50% {
3661
+ transform: rotate(160deg);
3662
+ }
3663
+ 100% {
3664
+ transform: rotate(20deg);
3665
+ }
3666
+ }
3667
+ @keyframes spinRight {
3668
+ 0% {
3669
+ transform: rotate(160deg);
3670
+ }
3671
+ 50% {
3672
+ transform: rotate(20deg);
3673
+ }
3674
+ 100% {
3675
+ transform: rotate(160deg);
3676
+ }
3677
+ }
3678
+ @keyframes spin {
3679
+ 0% {
3680
+ transform: rotate(0deg);
3681
+ }
3682
+ 100% {
3683
+ transform: rotate(2520deg);
3684
+ }
3685
+ }
3686
+
3687
+ .spinner {
3688
+ position: relative;
3689
+ width: 1.5em;
3690
+ height: 1.5em;
3691
+ margin: auto;
3692
+ animation: spin 10s linear infinite;
3693
+ }
3694
+ .spinner::before {
3695
+ content: "";
3696
+ position: absolute;
3697
+ top: 0;
3698
+ bottom: 0;
3699
+ left: 0;
3700
+ right: 0;
3701
+ }
3702
+ .right, .rightWrapper, .left, .leftWrapper {
3703
+ position: absolute;
3704
+ top: 0;
3705
+ overflow: hidden;
3706
+ width: .75em;
3707
+ height: 1.5em;
3708
+ }
3709
+ .left, .leftWrapper {
3710
+ left: 0;
3711
+ }
3712
+ .right {
3713
+ left: -12px;
3714
+ }
3715
+ .rightWrapper {
3716
+ right: 0;
3717
+ }
3718
+ .circle {
3719
+ border: .125em solid #A8B6B8;
3720
+ width: 1.25em; /* 1.5em - 2*0.125em border */
3721
+ height: 1.25em; /* 1.5em - 2*0.125em border */
3722
+ border-radius: 0.75em; /* 0.5*1.5em spinner size 8 */
3723
+ }
3724
+ .left {
3725
+ transform-origin: 100% 50%;
3726
+ animation: spinLeft 2.5s cubic-bezier(.2,0,.8,1) infinite;
3727
+ }
3728
+ .right {
3729
+ transform-origin: 100% 50%;
3730
+ animation: spinRight 2.5s cubic-bezier(.2,0,.8,1) infinite;
3731
+ }
3732
+ `;
3733
+
3734
+ const icon = 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik03IDIuNUgxN0MxNy44Mjg0IDIuNSAxOC41IDMuMTcxNTcgMTguNSA0VjIwQzE4LjUgMjAuODI4NCAxNy44Mjg0IDIxLjUgMTcgMjEuNUg3QzYuMTcxNTcgMjEuNSA1LjUgMjAuODI4NCA1LjUgMjBWNEM1LjUgMy4xNzE1NyA2LjE3MTU3IDIuNSA3IDIuNVpNMyA0QzMgMS43OTA4NiA0Ljc5MDg2IDAgNyAwSDE3QzE5LjIwOTEgMCAyMSAxLjc5MDg2IDIxIDRWMjBDMjEgMjIuMjA5MSAxOS4yMDkxIDI0IDE3IDI0SDdDNC43OTA4NiAyNCAzIDIyLjIwOTEgMyAyMFY0Wk0xMSA0LjYxNTM4QzEwLjQ0NzcgNC42MTUzOCAxMCA1LjA2MzEgMTAgNS42MTUzOFY2LjM4NDYyQzEwIDYuOTM2OSAxMC40NDc3IDcuMzg0NjIgMTEgNy4zODQ2MkgxM0MxMy41NTIzIDcuMzg0NjIgMTQgNi45MzY5IDE0IDYuMzg0NjJWNS42MTUzOEMxNCA1LjA2MzEgMTMuNTUyMyA0LjYxNTM4IDEzIDQuNjE1MzhIMTFaIiBmaWxsPSIjRENCOEZGIi8+Cjwvc3ZnPgo=';
3735
+
3736
+ function fromUint8Array(byteArray) {
3737
+ return window.btoa(String.fromCharCode.call(null, ...byteArray));
3738
+ }
3739
+ function toUint8Array(base64EncodedByteArray) {
3740
+ return new Uint8Array(window
3741
+ .atob(base64EncodedByteArray)
3742
+ .split('')
3743
+ .map((c) => c.charCodeAt(0)));
3744
+ }
3745
+
3746
+ var _LocalSolanaMobileWalletAdapterWallet_instances, _LocalSolanaMobileWalletAdapterWallet_listeners, _LocalSolanaMobileWalletAdapterWallet_version, _LocalSolanaMobileWalletAdapterWallet_name, _LocalSolanaMobileWalletAdapterWallet_url, _LocalSolanaMobileWalletAdapterWallet_icon, _LocalSolanaMobileWalletAdapterWallet_appIdentity, _LocalSolanaMobileWalletAdapterWallet_authorization, _LocalSolanaMobileWalletAdapterWallet_authorizationCache, _LocalSolanaMobileWalletAdapterWallet_connecting, _LocalSolanaMobileWalletAdapterWallet_connectionGeneration, _LocalSolanaMobileWalletAdapterWallet_chains, _LocalSolanaMobileWalletAdapterWallet_chainSelector, _LocalSolanaMobileWalletAdapterWallet_optionalFeatures, _LocalSolanaMobileWalletAdapterWallet_onWalletNotFound, _LocalSolanaMobileWalletAdapterWallet_on, _LocalSolanaMobileWalletAdapterWallet_emit, _LocalSolanaMobileWalletAdapterWallet_off, _LocalSolanaMobileWalletAdapterWallet_connect, _LocalSolanaMobileWalletAdapterWallet_performAuthorization, _LocalSolanaMobileWalletAdapterWallet_handleAuthorizationResult, _LocalSolanaMobileWalletAdapterWallet_handleWalletCapabilitiesResult, _LocalSolanaMobileWalletAdapterWallet_performReauthorization, _LocalSolanaMobileWalletAdapterWallet_disconnect, _LocalSolanaMobileWalletAdapterWallet_transact, _LocalSolanaMobileWalletAdapterWallet_assertIsAuthorized, _LocalSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts, _LocalSolanaMobileWalletAdapterWallet_performSignTransactions, _LocalSolanaMobileWalletAdapterWallet_performSignAndSendTransaction, _LocalSolanaMobileWalletAdapterWallet_signAndSendTransaction, _LocalSolanaMobileWalletAdapterWallet_signTransaction, _LocalSolanaMobileWalletAdapterWallet_signMessage, _LocalSolanaMobileWalletAdapterWallet_signIn, _LocalSolanaMobileWalletAdapterWallet_performSignIn, _RemoteSolanaMobileWalletAdapterWallet_instances, _RemoteSolanaMobileWalletAdapterWallet_listeners, _RemoteSolanaMobileWalletAdapterWallet_version, _RemoteSolanaMobileWalletAdapterWallet_name, _RemoteSolanaMobileWalletAdapterWallet_url, _RemoteSolanaMobileWalletAdapterWallet_icon, _RemoteSolanaMobileWalletAdapterWallet_appIdentity, _RemoteSolanaMobileWalletAdapterWallet_authorization, _RemoteSolanaMobileWalletAdapterWallet_authorizationCache, _RemoteSolanaMobileWalletAdapterWallet_connecting, _RemoteSolanaMobileWalletAdapterWallet_connectionGeneration, _RemoteSolanaMobileWalletAdapterWallet_chains, _RemoteSolanaMobileWalletAdapterWallet_chainSelector, _RemoteSolanaMobileWalletAdapterWallet_optionalFeatures, _RemoteSolanaMobileWalletAdapterWallet_onWalletNotFound, _RemoteSolanaMobileWalletAdapterWallet_hostAuthority, _RemoteSolanaMobileWalletAdapterWallet_session, _RemoteSolanaMobileWalletAdapterWallet_on, _RemoteSolanaMobileWalletAdapterWallet_emit, _RemoteSolanaMobileWalletAdapterWallet_off, _RemoteSolanaMobileWalletAdapterWallet_connect, _RemoteSolanaMobileWalletAdapterWallet_performAuthorization, _RemoteSolanaMobileWalletAdapterWallet_handleAuthorizationResult, _RemoteSolanaMobileWalletAdapterWallet_handleWalletCapabilitiesResult, _RemoteSolanaMobileWalletAdapterWallet_performReauthorization, _RemoteSolanaMobileWalletAdapterWallet_disconnect, _RemoteSolanaMobileWalletAdapterWallet_transact, _RemoteSolanaMobileWalletAdapterWallet_assertIsAuthorized, _RemoteSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts, _RemoteSolanaMobileWalletAdapterWallet_performSignTransactions, _RemoteSolanaMobileWalletAdapterWallet_performSignAndSendTransaction, _RemoteSolanaMobileWalletAdapterWallet_signAndSendTransaction, _RemoteSolanaMobileWalletAdapterWallet_signTransaction, _RemoteSolanaMobileWalletAdapterWallet_signMessage, _RemoteSolanaMobileWalletAdapterWallet_signIn, _RemoteSolanaMobileWalletAdapterWallet_performSignIn;
3747
+ const SolanaMobileWalletAdapterWalletName = 'Mobile Wallet Adapter';
3748
+ const SolanaMobileWalletAdapterRemoteWalletName = 'Remote Mobile Wallet Adapter';
3749
+ const SIGNATURE_LENGTH_IN_BYTES = 64;
3750
+ const DEFAULT_FEATURES = [SolanaSignAndSendTransaction, SolanaSignTransaction, SolanaSignMessage, SolanaSignIn];
3751
+ class LocalSolanaMobileWalletAdapterWallet {
3752
+ constructor(config) {
3753
+ _LocalSolanaMobileWalletAdapterWallet_instances.add(this);
3754
+ _LocalSolanaMobileWalletAdapterWallet_listeners.set(this, {});
3755
+ _LocalSolanaMobileWalletAdapterWallet_version.set(this, '1.0.0'); // wallet-standard version
3756
+ _LocalSolanaMobileWalletAdapterWallet_name.set(this, SolanaMobileWalletAdapterWalletName);
3757
+ _LocalSolanaMobileWalletAdapterWallet_url.set(this, 'https://solanamobile.com/wallets');
3758
+ _LocalSolanaMobileWalletAdapterWallet_icon.set(this, icon);
3759
+ _LocalSolanaMobileWalletAdapterWallet_appIdentity.set(this, void 0);
3760
+ _LocalSolanaMobileWalletAdapterWallet_authorization.set(this, void 0);
3761
+ _LocalSolanaMobileWalletAdapterWallet_authorizationCache.set(this, void 0);
3762
+ _LocalSolanaMobileWalletAdapterWallet_connecting.set(this, false);
3763
+ /**
3764
+ * Every time the connection is recycled in some way (eg. `disconnect()` is called)
3765
+ * increment this and use it to make sure that `transact` calls from the previous
3766
+ * 'generation' don't continue to do work and throw exceptions.
3767
+ */
3768
+ _LocalSolanaMobileWalletAdapterWallet_connectionGeneration.set(this, 0);
3769
+ _LocalSolanaMobileWalletAdapterWallet_chains.set(this, []);
3770
+ _LocalSolanaMobileWalletAdapterWallet_chainSelector.set(this, void 0);
3771
+ _LocalSolanaMobileWalletAdapterWallet_optionalFeatures.set(this, void 0);
3772
+ _LocalSolanaMobileWalletAdapterWallet_onWalletNotFound.set(this, void 0);
3773
+ _LocalSolanaMobileWalletAdapterWallet_on.set(this, (event, listener) => {
3774
+ var _a;
3775
+ ((_a = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_listeners, "f")[event]) === null || _a === void 0 ? void 0 : _a.push(listener)) || (__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_listeners, "f")[event] = [listener]);
3776
+ return () => __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_instances, "m", _LocalSolanaMobileWalletAdapterWallet_off).call(this, event, listener);
3777
+ });
3778
+ _LocalSolanaMobileWalletAdapterWallet_connect.set(this, ({ silent } = {}) => __awaiter(this, void 0, void 0, function* () {
3779
+ if (__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_connecting, "f") || this.connected) {
3780
+ return { accounts: this.accounts };
3781
+ }
3782
+ __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_connecting, true);
3783
+ try {
3784
+ if (silent) {
3785
+ const cachedAuthorization = yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorizationCache, "f").get();
3786
+ if (cachedAuthorization) {
3787
+ yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_handleWalletCapabilitiesResult, "f").call(this, cachedAuthorization.capabilities);
3788
+ yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_handleAuthorizationResult, "f").call(this, cachedAuthorization);
3789
+ }
3790
+ else {
3791
+ return { accounts: this.accounts };
3792
+ }
3793
+ }
3794
+ else {
3795
+ yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performAuthorization, "f").call(this);
3796
+ }
3797
+ }
3798
+ catch (e) {
3799
+ throw new Error((e instanceof Error && e.message) || 'Unknown error');
3800
+ }
3801
+ finally {
3802
+ __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_connecting, false);
3803
+ }
3804
+ return { accounts: this.accounts };
3805
+ }));
3806
+ _LocalSolanaMobileWalletAdapterWallet_performAuthorization.set(this, (signInPayload) => __awaiter(this, void 0, void 0, function* () {
3807
+ try {
3808
+ const cachedAuthorizationResult = yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorizationCache, "f").get();
3809
+ if (cachedAuthorizationResult) {
3810
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
3811
+ __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_handleAuthorizationResult, "f").call(this, cachedAuthorizationResult);
3812
+ return cachedAuthorizationResult;
3813
+ }
3814
+ const selectedChain = yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_chainSelector, "f").select(__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_chains, "f"));
3815
+ return yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_transact, "f").call(this, (wallet) => __awaiter(this, void 0, void 0, function* () {
3816
+ const [capabilities, mwaAuthorizationResult] = yield Promise.all([
3817
+ wallet.getCapabilities(),
3818
+ wallet.authorize({
3819
+ chain: selectedChain,
3820
+ identity: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_appIdentity, "f"),
3821
+ sign_in_payload: signInPayload,
3822
+ })
3823
+ ]);
3824
+ const accounts = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts, "f").call(this, mwaAuthorizationResult.accounts);
3825
+ const authorization = Object.assign(Object.assign({}, mwaAuthorizationResult), { accounts, chain: selectedChain, capabilities: capabilities });
3826
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
3827
+ Promise.all([
3828
+ __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_handleWalletCapabilitiesResult, "f").call(this, capabilities),
3829
+ __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorizationCache, "f").set(authorization),
3830
+ __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_handleAuthorizationResult, "f").call(this, authorization),
3831
+ ]);
3832
+ return authorization;
3833
+ }));
3834
+ }
3835
+ catch (e) {
3836
+ throw new Error((e instanceof Error && e.message) || 'Unknown error');
3837
+ }
3838
+ }));
3839
+ _LocalSolanaMobileWalletAdapterWallet_handleAuthorizationResult.set(this, (authorization) => __awaiter(this, void 0, void 0, function* () {
3840
+ var _a;
3841
+ const didPublicKeysChange =
3842
+ // Case 1: We started from having no authorization.
3843
+ __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f") == null ||
3844
+ // Case 2: The number of authorized accounts changed.
3845
+ ((_a = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f")) === null || _a === void 0 ? void 0 : _a.accounts.length) !== authorization.accounts.length ||
3846
+ // Case 3: The new list of addresses isn't exactly the same as the old list, in the same order.
3847
+ __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f").accounts.some((account, ii) => account.address !== authorization.accounts[ii].address);
3848
+ __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, authorization);
3849
+ if (didPublicKeysChange) {
3850
+ __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_instances, "m", _LocalSolanaMobileWalletAdapterWallet_emit).call(this, 'change', { accounts: this.accounts });
3851
+ }
3852
+ }));
3853
+ _LocalSolanaMobileWalletAdapterWallet_handleWalletCapabilitiesResult.set(this, (capabilities) => __awaiter(this, void 0, void 0, function* () {
3854
+ // TODO: investigate why using SolanaSignTransactions constant breaks treeshaking
3855
+ const supportsSignTransaction = capabilities.features.includes('solana:signTransactions'); //SolanaSignTransactions);
3856
+ const supportsSignAndSendTransaction = capabilities.supports_sign_and_send_transactions;
3857
+ const didCapabilitiesChange = SolanaSignAndSendTransaction in this.features !== supportsSignAndSendTransaction ||
3858
+ SolanaSignTransaction in this.features !== supportsSignTransaction;
3859
+ __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_optionalFeatures, Object.assign(Object.assign({}, ((supportsSignAndSendTransaction || (!supportsSignAndSendTransaction && !supportsSignTransaction)) && {
3860
+ [SolanaSignAndSendTransaction]: {
3861
+ version: '1.0.0',
3862
+ supportedTransactionVersions: ['legacy', 0],
3863
+ signAndSendTransaction: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_signAndSendTransaction, "f"),
3864
+ },
3865
+ })), (supportsSignTransaction && {
3866
+ [SolanaSignTransaction]: {
3867
+ version: '1.0.0',
3868
+ supportedTransactionVersions: ['legacy', 0],
3869
+ signTransaction: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_signTransaction, "f"),
3870
+ },
3871
+ })));
3872
+ if (didCapabilitiesChange) {
3873
+ __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_instances, "m", _LocalSolanaMobileWalletAdapterWallet_emit).call(this, 'change', { features: this.features });
3874
+ }
3875
+ }));
3876
+ _LocalSolanaMobileWalletAdapterWallet_performReauthorization.set(this, (wallet, authToken, chain) => __awaiter(this, void 0, void 0, function* () {
3877
+ var _b, _c;
3878
+ try {
3879
+ const [capabilities, mwaAuthorizationResult] = yield Promise.all([
3880
+ (_c = (_b = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f")) === null || _b === void 0 ? void 0 : _b.capabilities) !== null && _c !== void 0 ? _c : yield wallet.getCapabilities(),
3881
+ wallet.authorize({
3882
+ auth_token: authToken,
3883
+ identity: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_appIdentity, "f"),
3884
+ chain: chain
3885
+ })
3886
+ ]);
3887
+ const accounts = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts, "f").call(this, mwaAuthorizationResult.accounts);
3888
+ const authorization = Object.assign(Object.assign({}, mwaAuthorizationResult), { accounts: accounts, chain: chain, capabilities: capabilities });
3889
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
3890
+ Promise.all([
3891
+ __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorizationCache, "f").set(authorization),
3892
+ __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_handleAuthorizationResult, "f").call(this, authorization),
3893
+ ]);
3894
+ }
3895
+ catch (e) {
3896
+ __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_disconnect, "f").call(this);
3897
+ throw new Error((e instanceof Error && e.message) || 'Unknown error');
3898
+ }
3899
+ }));
3900
+ _LocalSolanaMobileWalletAdapterWallet_disconnect.set(this, () => __awaiter(this, void 0, void 0, function* () {
3901
+ var _d;
3902
+ __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorizationCache, "f").clear(); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
3903
+ __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_connecting, false);
3904
+ __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_connectionGeneration, (_d = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_connectionGeneration, "f"), _d++, _d));
3905
+ __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, undefined);
3906
+ __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_instances, "m", _LocalSolanaMobileWalletAdapterWallet_emit).call(this, 'change', { accounts: this.accounts });
3907
+ }));
3908
+ _LocalSolanaMobileWalletAdapterWallet_transact.set(this, (callback) => __awaiter(this, void 0, void 0, function* () {
3909
+ var _e;
3910
+ const walletUriBase = (_e = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f")) === null || _e === void 0 ? void 0 : _e.wallet_uri_base;
3911
+ const config = walletUriBase ? { baseUri: walletUriBase } : undefined;
3912
+ const currentConnectionGeneration = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_connectionGeneration, "f");
3913
+ try {
3914
+ return yield transact(callback, config);
3915
+ }
3916
+ catch (e) {
3917
+ if (__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_connectionGeneration, "f") !== currentConnectionGeneration) {
3918
+ yield new Promise(() => { }); // Never resolve.
3919
+ }
3920
+ if (e instanceof Error &&
3921
+ e.name === 'SolanaMobileWalletAdapterError' &&
3922
+ e.code === 'ERROR_WALLET_NOT_FOUND') {
3923
+ yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_onWalletNotFound, "f").call(this, this);
3924
+ }
3925
+ throw e;
3926
+ }
3927
+ }));
3928
+ _LocalSolanaMobileWalletAdapterWallet_assertIsAuthorized.set(this, () => {
3929
+ if (!__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f"))
3930
+ throw new Error('Wallet not connected');
3931
+ return { authToken: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f").auth_token, chain: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f").chain };
3932
+ });
3933
+ _LocalSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts.set(this, (accounts) => {
3934
+ return accounts.map((account) => {
3935
+ var _a, _b;
3936
+ const publicKey = toUint8Array(account.address);
3937
+ return {
3938
+ address: base58.encode(publicKey),
3939
+ publicKey,
3940
+ label: account.label,
3941
+ icon: account.icon,
3942
+ chains: (_a = account.chains) !== null && _a !== void 0 ? _a : __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_chains, "f"),
3943
+ // TODO: get supported features from getCapabilities API
3944
+ features: (_b = account.features) !== null && _b !== void 0 ? _b : DEFAULT_FEATURES
3945
+ };
3946
+ });
3947
+ });
3948
+ _LocalSolanaMobileWalletAdapterWallet_performSignTransactions.set(this, (transactions) => __awaiter(this, void 0, void 0, function* () {
3949
+ const { authToken, chain } = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_assertIsAuthorized, "f").call(this);
3950
+ try {
3951
+ const base64Transactions = transactions.map((tx) => { return fromUint8Array(tx); });
3952
+ return yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_transact, "f").call(this, (wallet) => __awaiter(this, void 0, void 0, function* () {
3953
+ yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performReauthorization, "f").call(this, wallet, authToken, chain);
3954
+ const signedTransactions = (yield wallet.signTransactions({
3955
+ payloads: base64Transactions,
3956
+ })).signed_payloads.map(toUint8Array);
3957
+ return signedTransactions;
3958
+ }));
3959
+ }
3960
+ catch (e) {
3961
+ throw new Error((e instanceof Error && e.message) || 'Unknown error');
3962
+ }
3963
+ }));
3964
+ _LocalSolanaMobileWalletAdapterWallet_performSignAndSendTransaction.set(this, (transaction, options) => __awaiter(this, void 0, void 0, function* () {
3965
+ const { authToken, chain } = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_assertIsAuthorized, "f").call(this);
3966
+ try {
3967
+ return yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_transact, "f").call(this, (wallet) => __awaiter(this, void 0, void 0, function* () {
3968
+ const [capabilities, _1] = yield Promise.all([
3969
+ wallet.getCapabilities(),
3970
+ __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performReauthorization, "f").call(this, wallet, authToken, chain)
3971
+ ]);
3972
+ if (capabilities.supports_sign_and_send_transactions) {
3973
+ const base64Transaction = fromUint8Array(transaction);
3974
+ const signatures = (yield wallet.signAndSendTransactions(Object.assign(Object.assign({}, options), { payloads: [base64Transaction] }))).signatures.map(toUint8Array);
3975
+ return signatures[0];
3976
+ }
3977
+ else {
3978
+ throw new Error('connected wallet does not support signAndSendTransaction');
3979
+ }
3980
+ }));
3981
+ }
3982
+ catch (e) {
3983
+ throw new Error((e instanceof Error && e.message) || 'Unknown error');
3984
+ }
3985
+ }));
3986
+ _LocalSolanaMobileWalletAdapterWallet_signAndSendTransaction.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
3987
+ const outputs = [];
3988
+ for (const input of inputs) {
3989
+ const signature = yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performSignAndSendTransaction, "f").call(this, input.transaction, input.options);
3990
+ outputs.push({ signature });
3991
+ }
3992
+ return outputs;
3993
+ }));
3994
+ _LocalSolanaMobileWalletAdapterWallet_signTransaction.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
3995
+ return (yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performSignTransactions, "f").call(this, inputs.map(({ transaction }) => transaction)))
3996
+ .map((signedTransaction) => {
3997
+ return { signedTransaction };
3998
+ });
3999
+ }));
4000
+ _LocalSolanaMobileWalletAdapterWallet_signMessage.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
4001
+ const { authToken, chain } = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_assertIsAuthorized, "f").call(this);
4002
+ const addresses = inputs.map(({ account }) => fromUint8Array(account.publicKey));
4003
+ const messages = inputs.map(({ message }) => fromUint8Array(message));
4004
+ try {
4005
+ return yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_transact, "f").call(this, (wallet) => __awaiter(this, void 0, void 0, function* () {
4006
+ yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performReauthorization, "f").call(this, wallet, authToken, chain);
4007
+ const signedMessages = (yield wallet.signMessages({
4008
+ addresses: addresses,
4009
+ payloads: messages,
4010
+ })).signed_payloads.map(toUint8Array);
4011
+ return signedMessages.map((signedMessage) => {
4012
+ return { signedMessage: signedMessage, signature: signedMessage.slice(-SIGNATURE_LENGTH_IN_BYTES) };
4013
+ });
4014
+ }));
4015
+ }
4016
+ catch (e) {
4017
+ throw new Error((e instanceof Error && e.message) || 'Unknown error');
4018
+ }
4019
+ }));
4020
+ _LocalSolanaMobileWalletAdapterWallet_signIn.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
4021
+ const outputs = [];
4022
+ if (inputs.length > 1) {
4023
+ for (const input of inputs) {
4024
+ outputs.push(yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performSignIn, "f").call(this, input));
4025
+ }
4026
+ }
4027
+ else {
4028
+ return [yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performSignIn, "f").call(this, inputs[0])];
4029
+ }
4030
+ return outputs;
4031
+ }));
4032
+ _LocalSolanaMobileWalletAdapterWallet_performSignIn.set(this, (input) => __awaiter(this, void 0, void 0, function* () {
4033
+ var _f, _g, _h;
4034
+ __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_connecting, true);
4035
+ try {
4036
+ const authorizationResult = yield __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_performAuthorization, "f").call(this, Object.assign(Object.assign({}, input), { domain: (_f = input === null || input === void 0 ? void 0 : input.domain) !== null && _f !== void 0 ? _f : window.location.host }));
4037
+ if (!authorizationResult.sign_in_result) {
4038
+ throw new Error("Sign in failed, no sign in result returned by wallet");
4039
+ }
4040
+ const signedInAddress = authorizationResult.sign_in_result.address;
4041
+ const signedInAccount = authorizationResult.accounts.find(acc => acc.address == signedInAddress);
4042
+ return {
4043
+ account: Object.assign(Object.assign({}, signedInAccount !== null && signedInAccount !== void 0 ? signedInAccount : {
4044
+ address: base58.encode(toUint8Array(signedInAddress))
4045
+ }), { publicKey: toUint8Array(signedInAddress), chains: (_g = signedInAccount === null || signedInAccount === void 0 ? void 0 : signedInAccount.chains) !== null && _g !== void 0 ? _g : __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_chains, "f"), features: (_h = signedInAccount === null || signedInAccount === void 0 ? void 0 : signedInAccount.features) !== null && _h !== void 0 ? _h : authorizationResult.capabilities.features }),
4046
+ signedMessage: toUint8Array(authorizationResult.sign_in_result.signed_message),
4047
+ signature: toUint8Array(authorizationResult.sign_in_result.signature)
4048
+ };
4049
+ }
4050
+ catch (e) {
4051
+ throw new Error((e instanceof Error && e.message) || 'Unknown error');
4052
+ }
4053
+ finally {
4054
+ __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_connecting, false);
4055
+ }
4056
+ }));
4057
+ __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorizationCache, config.authorizationCache);
4058
+ __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_appIdentity, config.appIdentity);
4059
+ __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_chains, config.chains);
4060
+ __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_chainSelector, config.chainSelector);
4061
+ __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_onWalletNotFound, config.onWalletNotFound);
4062
+ __classPrivateFieldSet$1(this, _LocalSolanaMobileWalletAdapterWallet_optionalFeatures, {
4063
+ // In MWA 1.0, signAndSend is optional and signTransaction is mandatory. Whereas in MWA 2.0+,
4064
+ // signAndSend is mandatory and signTransaction is optional (and soft deprecated). As of mid
4065
+ // 2025, all MWA wallets support both signAndSendTransaction and signTransaction so its safe
4066
+ // assume both are supported here. The features will be updated based on the actual connected
4067
+ // wallets capabilities during connection regardless, so this is safe.
4068
+ [SolanaSignAndSendTransaction]: {
4069
+ version: '1.0.0',
4070
+ supportedTransactionVersions: ['legacy', 0],
4071
+ signAndSendTransaction: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_signAndSendTransaction, "f"),
4072
+ },
4073
+ [SolanaSignTransaction]: {
4074
+ version: '1.0.0',
4075
+ supportedTransactionVersions: ['legacy', 0],
4076
+ signTransaction: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_signTransaction, "f"),
4077
+ },
4078
+ });
4079
+ }
4080
+ get version() {
4081
+ return __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_version, "f");
4082
+ }
4083
+ get name() {
4084
+ return __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_name, "f");
4085
+ }
4086
+ get url() {
4087
+ return __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_url, "f");
4088
+ }
4089
+ get icon() {
4090
+ return __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_icon, "f");
4091
+ }
4092
+ get chains() {
4093
+ return __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_chains, "f");
4094
+ }
4095
+ get features() {
4096
+ return Object.assign({ [StandardConnect]: {
4097
+ version: '1.0.0',
4098
+ connect: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_connect, "f"),
4099
+ }, [StandardDisconnect]: {
4100
+ version: '1.0.0',
4101
+ disconnect: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_disconnect, "f"),
4102
+ }, [StandardEvents]: {
4103
+ version: '1.0.0',
4104
+ on: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_on, "f"),
4105
+ }, [SolanaSignMessage]: {
4106
+ version: '1.0.0',
4107
+ signMessage: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_signMessage, "f"),
4108
+ }, [SolanaSignIn]: {
4109
+ version: '1.0.0',
4110
+ signIn: __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_signIn, "f"),
4111
+ } }, __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_optionalFeatures, "f"));
4112
+ }
4113
+ get accounts() {
4114
+ var _a, _b;
4115
+ return (_b = (_a = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f")) === null || _a === void 0 ? void 0 : _a.accounts) !== null && _b !== void 0 ? _b : [];
4116
+ }
4117
+ get connected() {
4118
+ return !!__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f");
4119
+ }
4120
+ get isAuthorized() {
4121
+ return !!__classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f");
4122
+ }
4123
+ get currentAuthorization() {
4124
+ return __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorization, "f");
4125
+ }
4126
+ get cachedAuthorizationResult() {
4127
+ return __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_authorizationCache, "f").get();
4128
+ }
4129
+ }
4130
+ _LocalSolanaMobileWalletAdapterWallet_listeners = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_version = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_name = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_url = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_icon = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_appIdentity = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_authorization = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_authorizationCache = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_connecting = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_connectionGeneration = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_chains = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_chainSelector = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_optionalFeatures = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_onWalletNotFound = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_on = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_connect = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_performAuthorization = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_handleAuthorizationResult = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_handleWalletCapabilitiesResult = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_performReauthorization = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_disconnect = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_transact = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_assertIsAuthorized = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_performSignTransactions = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_performSignAndSendTransaction = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_signAndSendTransaction = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_signTransaction = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_signMessage = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_signIn = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_performSignIn = new WeakMap(), _LocalSolanaMobileWalletAdapterWallet_instances = new WeakSet(), _LocalSolanaMobileWalletAdapterWallet_emit = function _LocalSolanaMobileWalletAdapterWallet_emit(event, ...args) {
4131
+ var _a;
4132
+ // eslint-disable-next-line prefer-spread
4133
+ (_a = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_listeners, "f")[event]) === null || _a === void 0 ? void 0 : _a.forEach((listener) => listener.apply(null, args));
4134
+ }, _LocalSolanaMobileWalletAdapterWallet_off = function _LocalSolanaMobileWalletAdapterWallet_off(event, listener) {
4135
+ var _a;
4136
+ __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_listeners, "f")[event] = (_a = __classPrivateFieldGet$1(this, _LocalSolanaMobileWalletAdapterWallet_listeners, "f")[event]) === null || _a === void 0 ? void 0 : _a.filter((existingListener) => listener !== existingListener);
4137
+ };
4138
+ class RemoteSolanaMobileWalletAdapterWallet {
4139
+ constructor(config) {
4140
+ _RemoteSolanaMobileWalletAdapterWallet_instances.add(this);
4141
+ _RemoteSolanaMobileWalletAdapterWallet_listeners.set(this, {});
4142
+ _RemoteSolanaMobileWalletAdapterWallet_version.set(this, '1.0.0'); // wallet-standard version
4143
+ _RemoteSolanaMobileWalletAdapterWallet_name.set(this, SolanaMobileWalletAdapterRemoteWalletName);
4144
+ _RemoteSolanaMobileWalletAdapterWallet_url.set(this, 'https://solanamobile.com/wallets');
4145
+ _RemoteSolanaMobileWalletAdapterWallet_icon.set(this, icon);
4146
+ _RemoteSolanaMobileWalletAdapterWallet_appIdentity.set(this, void 0);
4147
+ _RemoteSolanaMobileWalletAdapterWallet_authorization.set(this, void 0);
4148
+ _RemoteSolanaMobileWalletAdapterWallet_authorizationCache.set(this, void 0);
4149
+ _RemoteSolanaMobileWalletAdapterWallet_connecting.set(this, false);
4150
+ /**
4151
+ * Every time the connection is recycled in some way (eg. `disconnect()` is called)
4152
+ * increment this and use it to make sure that `transact` calls from the previous
4153
+ * 'generation' don't continue to do work and throw exceptions.
4154
+ */
4155
+ _RemoteSolanaMobileWalletAdapterWallet_connectionGeneration.set(this, 0);
4156
+ _RemoteSolanaMobileWalletAdapterWallet_chains.set(this, []);
4157
+ _RemoteSolanaMobileWalletAdapterWallet_chainSelector.set(this, void 0);
4158
+ _RemoteSolanaMobileWalletAdapterWallet_optionalFeatures.set(this, void 0);
4159
+ _RemoteSolanaMobileWalletAdapterWallet_onWalletNotFound.set(this, void 0);
4160
+ _RemoteSolanaMobileWalletAdapterWallet_hostAuthority.set(this, void 0);
4161
+ _RemoteSolanaMobileWalletAdapterWallet_session.set(this, void 0);
4162
+ _RemoteSolanaMobileWalletAdapterWallet_on.set(this, (event, listener) => {
4163
+ var _a;
4164
+ ((_a = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_listeners, "f")[event]) === null || _a === void 0 ? void 0 : _a.push(listener)) || (__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_listeners, "f")[event] = [listener]);
4165
+ return () => __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_instances, "m", _RemoteSolanaMobileWalletAdapterWallet_off).call(this, event, listener);
4166
+ });
4167
+ _RemoteSolanaMobileWalletAdapterWallet_connect.set(this, ({ silent } = {}) => __awaiter(this, void 0, void 0, function* () {
4168
+ if (__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connecting, "f") || this.connected) {
4169
+ return { accounts: this.accounts };
4170
+ }
4171
+ __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connecting, true);
4172
+ try {
4173
+ yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_performAuthorization, "f").call(this);
4174
+ }
4175
+ catch (e) {
4176
+ throw new Error((e instanceof Error && e.message) || 'Unknown error');
4177
+ }
4178
+ finally {
4179
+ __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connecting, false);
4180
+ }
4181
+ return { accounts: this.accounts };
4182
+ }));
4183
+ _RemoteSolanaMobileWalletAdapterWallet_performAuthorization.set(this, (signInPayload) => __awaiter(this, void 0, void 0, function* () {
4184
+ try {
4185
+ const cachedAuthorizationResult = yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorizationCache, "f").get();
4186
+ if (cachedAuthorizationResult) {
4187
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
4188
+ __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_handleAuthorizationResult, "f").call(this, cachedAuthorizationResult);
4189
+ return cachedAuthorizationResult;
4190
+ }
4191
+ if (__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_session, "f"))
4192
+ __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_session, undefined, "f");
4193
+ const selectedChain = yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_chainSelector, "f").select(__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_chains, "f"));
4194
+ return yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_transact, "f").call(this, (wallet) => __awaiter(this, void 0, void 0, function* () {
4195
+ const [capabilities, mwaAuthorizationResult] = yield Promise.all([
4196
+ wallet.getCapabilities(),
4197
+ wallet.authorize({
4198
+ chain: selectedChain,
4199
+ identity: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_appIdentity, "f"),
4200
+ sign_in_payload: signInPayload,
4201
+ })
4202
+ ]);
4203
+ const accounts = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts, "f").call(this, mwaAuthorizationResult.accounts);
4204
+ const authorizationResult = Object.assign(Object.assign({}, mwaAuthorizationResult), { accounts, chain: selectedChain, capabilities: capabilities });
4205
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
4206
+ Promise.all([
4207
+ __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_handleWalletCapabilitiesResult, "f").call(this, capabilities),
4208
+ __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorizationCache, "f").set(authorizationResult),
4209
+ __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_handleAuthorizationResult, "f").call(this, authorizationResult),
4210
+ ]);
4211
+ return authorizationResult;
4212
+ }));
4213
+ }
4214
+ catch (e) {
4215
+ throw new Error((e instanceof Error && e.message) || 'Unknown error');
4216
+ }
4217
+ }));
4218
+ _RemoteSolanaMobileWalletAdapterWallet_handleAuthorizationResult.set(this, (authorization) => __awaiter(this, void 0, void 0, function* () {
4219
+ var _a;
4220
+ const didPublicKeysChange =
4221
+ // Case 1: We started from having no authorization.
4222
+ __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f") == null ||
4223
+ // Case 2: The number of authorized accounts changed.
4224
+ ((_a = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f")) === null || _a === void 0 ? void 0 : _a.accounts.length) !== authorization.accounts.length ||
4225
+ // Case 3: The new list of addresses isn't exactly the same as the old list, in the same order.
4226
+ __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f").accounts.some((account, ii) => account.address !== authorization.accounts[ii].address);
4227
+ __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, authorization);
4228
+ if (didPublicKeysChange) {
4229
+ __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_instances, "m", _RemoteSolanaMobileWalletAdapterWallet_emit).call(this, 'change', { accounts: this.accounts });
4230
+ }
4231
+ }));
4232
+ _RemoteSolanaMobileWalletAdapterWallet_handleWalletCapabilitiesResult.set(this, (capabilities) => __awaiter(this, void 0, void 0, function* () {
4233
+ // TODO: investigate why using SolanaSignTransactions constant breaks treeshaking
4234
+ const supportsSignTransaction = capabilities.features.includes('solana:signTransactions'); //SolanaSignTransactions);
4235
+ const supportsSignAndSendTransaction = capabilities.supports_sign_and_send_transactions ||
4236
+ capabilities.features.includes('solana:signAndSendTransaction');
4237
+ const didCapabilitiesChange = SolanaSignAndSendTransaction in this.features !== supportsSignAndSendTransaction ||
4238
+ SolanaSignTransaction in this.features !== supportsSignTransaction;
4239
+ __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_optionalFeatures, Object.assign(Object.assign({}, (supportsSignAndSendTransaction && {
4240
+ [SolanaSignAndSendTransaction]: {
4241
+ version: '1.0.0',
4242
+ supportedTransactionVersions: capabilities.supported_transaction_versions,
4243
+ signAndSendTransaction: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_signAndSendTransaction, "f"),
4244
+ },
4245
+ })), (supportsSignTransaction && {
4246
+ [SolanaSignTransaction]: {
4247
+ version: '1.0.0',
4248
+ supportedTransactionVersions: capabilities.supported_transaction_versions,
4249
+ signTransaction: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_signTransaction, "f"),
4250
+ },
4251
+ })));
4252
+ if (didCapabilitiesChange) {
4253
+ __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_instances, "m", _RemoteSolanaMobileWalletAdapterWallet_emit).call(this, 'change', { features: this.features });
4254
+ }
4255
+ }));
4256
+ _RemoteSolanaMobileWalletAdapterWallet_performReauthorization.set(this, (wallet, authToken, chain) => __awaiter(this, void 0, void 0, function* () {
4257
+ var _b, _c;
4258
+ try {
4259
+ const [capabilities, mwaAuthorizationResult] = yield Promise.all([
4260
+ (_c = (_b = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f")) === null || _b === void 0 ? void 0 : _b.capabilities) !== null && _c !== void 0 ? _c : yield wallet.getCapabilities(),
4261
+ wallet.authorize({
4262
+ auth_token: authToken,
4263
+ identity: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_appIdentity, "f"),
4264
+ chain: chain
4265
+ })
4266
+ ]);
4267
+ const accounts = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts, "f").call(this, mwaAuthorizationResult.accounts);
4268
+ const authorization = Object.assign(Object.assign({}, mwaAuthorizationResult), { accounts: accounts, chain: chain, capabilities: capabilities });
4269
+ // TODO: Evaluate whether there's any threat to not `awaiting` this expression
4270
+ Promise.all([
4271
+ __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorizationCache, "f").set(authorization),
4272
+ __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_handleAuthorizationResult, "f").call(this, authorization),
4273
+ ]);
4274
+ }
4275
+ catch (e) {
4276
+ __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_disconnect, "f").call(this);
4277
+ throw new Error((e instanceof Error && e.message) || 'Unknown error');
4278
+ }
4279
+ }));
4280
+ _RemoteSolanaMobileWalletAdapterWallet_disconnect.set(this, () => __awaiter(this, void 0, void 0, function* () {
4281
+ var _d;
4282
+ var _e;
4283
+ (_d = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_session, "f")) === null || _d === void 0 ? void 0 : _d.close();
4284
+ __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorizationCache, "f").clear(); // TODO: Evaluate whether there's any threat to not `awaiting` this expression
4285
+ __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connecting, false);
4286
+ __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connectionGeneration, (_e = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connectionGeneration, "f"), _e++, _e));
4287
+ __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, undefined);
4288
+ __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_session, undefined);
4289
+ __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_instances, "m", _RemoteSolanaMobileWalletAdapterWallet_emit).call(this, 'change', { accounts: this.accounts });
4290
+ }));
4291
+ _RemoteSolanaMobileWalletAdapterWallet_transact.set(this, (callback) => __awaiter(this, void 0, void 0, function* () {
4292
+ var _f;
4293
+ const walletUriBase = (_f = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f")) === null || _f === void 0 ? void 0 : _f.wallet_uri_base;
4294
+ const baseConfig = walletUriBase ? { baseUri: walletUriBase } : undefined;
4295
+ const remoteConfig = Object.assign(Object.assign({}, baseConfig), { remoteHostAuthority: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_hostAuthority, "f") });
4296
+ const currentConnectionGeneration = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connectionGeneration, "f");
4297
+ const modal = new RemoteConnectionModal();
4298
+ if (__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_session, "f")) {
4299
+ return callback(__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_session, "f").wallet);
4300
+ }
4301
+ try {
4302
+ const { associationUrl, close, wallet } = yield startRemoteScenario(remoteConfig);
4303
+ const removeCloseListener = modal.addEventListener('close', (event) => {
4304
+ if (event)
4305
+ close();
4306
+ });
4307
+ modal.initWithQR(associationUrl.toString());
4308
+ modal.open();
4309
+ __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_session, { close, wallet: yield wallet }, "f");
4310
+ removeCloseListener();
4311
+ modal.close();
4312
+ return yield callback(__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_session, "f").wallet);
4313
+ }
4314
+ catch (e) {
4315
+ modal.close();
4316
+ if (__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connectionGeneration, "f") !== currentConnectionGeneration) {
4317
+ yield new Promise(() => { }); // Never resolve.
4318
+ }
4319
+ if (e instanceof Error &&
4320
+ e.name === 'SolanaMobileWalletAdapterError' &&
4321
+ e.code === 'ERROR_WALLET_NOT_FOUND') {
4322
+ yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_onWalletNotFound, "f").call(this, this);
4323
+ }
4324
+ throw e;
4325
+ }
4326
+ }));
4327
+ _RemoteSolanaMobileWalletAdapterWallet_assertIsAuthorized.set(this, () => {
4328
+ if (!__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f"))
4329
+ throw new Error('Wallet not connected');
4330
+ return { authToken: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f").auth_token, chain: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f").chain };
4331
+ });
4332
+ _RemoteSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts.set(this, (accounts) => {
4333
+ return accounts.map((account) => {
4334
+ var _a, _b;
4335
+ const publicKey = toUint8Array(account.address);
4336
+ return {
4337
+ address: base58.encode(publicKey),
4338
+ publicKey,
4339
+ label: account.label,
4340
+ icon: account.icon,
4341
+ chains: (_a = account.chains) !== null && _a !== void 0 ? _a : __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_chains, "f"),
4342
+ // TODO: get supported features from getCapabilities API
4343
+ features: (_b = account.features) !== null && _b !== void 0 ? _b : DEFAULT_FEATURES
4344
+ };
4345
+ });
4346
+ });
4347
+ _RemoteSolanaMobileWalletAdapterWallet_performSignTransactions.set(this, (transactions) => __awaiter(this, void 0, void 0, function* () {
4348
+ const { authToken, chain } = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_assertIsAuthorized, "f").call(this);
4349
+ try {
4350
+ return yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_transact, "f").call(this, (wallet) => __awaiter(this, void 0, void 0, function* () {
4351
+ yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_performReauthorization, "f").call(this, wallet, authToken, chain);
4352
+ const signedTransactions = (yield wallet.signTransactions({
4353
+ payloads: transactions.map(fromUint8Array),
4354
+ })).signed_payloads.map(toUint8Array);
4355
+ return signedTransactions;
4356
+ }));
4357
+ }
4358
+ catch (e) {
4359
+ throw new Error((e instanceof Error && e.message) || 'Unknown error');
4360
+ }
4361
+ }));
4362
+ _RemoteSolanaMobileWalletAdapterWallet_performSignAndSendTransaction.set(this, (transaction, options) => __awaiter(this, void 0, void 0, function* () {
4363
+ const { authToken, chain } = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_assertIsAuthorized, "f").call(this);
4364
+ try {
4365
+ return yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_transact, "f").call(this, (wallet) => __awaiter(this, void 0, void 0, function* () {
4366
+ const [capabilities, _1] = yield Promise.all([
4367
+ wallet.getCapabilities(),
4368
+ __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_performReauthorization, "f").call(this, wallet, authToken, chain)
4369
+ ]);
4370
+ if (capabilities.supports_sign_and_send_transactions) {
4371
+ const signatures = (yield wallet.signAndSendTransactions(Object.assign(Object.assign({}, options), { payloads: [fromUint8Array(transaction)] }))).signatures.map(toUint8Array);
4372
+ return signatures[0];
4373
+ }
4374
+ else {
4375
+ throw new Error('connected wallet does not support signAndSendTransaction');
4376
+ }
4377
+ }));
4378
+ }
4379
+ catch (e) {
4380
+ throw new Error((e instanceof Error && e.message) || 'Unknown error');
4381
+ }
4382
+ }));
4383
+ _RemoteSolanaMobileWalletAdapterWallet_signAndSendTransaction.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
4384
+ const outputs = [];
4385
+ for (const input of inputs) {
4386
+ const signature = (yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_performSignAndSendTransaction, "f").call(this, input.transaction, input.options));
4387
+ outputs.push({ signature });
4388
+ }
4389
+ return outputs;
4390
+ }));
4391
+ _RemoteSolanaMobileWalletAdapterWallet_signTransaction.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
4392
+ return (yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_performSignTransactions, "f").call(this, inputs.map(({ transaction }) => transaction)))
4393
+ .map((signedTransaction) => {
4394
+ return { signedTransaction };
4395
+ });
4396
+ }));
4397
+ _RemoteSolanaMobileWalletAdapterWallet_signMessage.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
4398
+ const { authToken, chain } = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_assertIsAuthorized, "f").call(this);
4399
+ const addresses = inputs.map(({ account }) => fromUint8Array(account.publicKey));
4400
+ const messages = inputs.map(({ message }) => fromUint8Array(message));
4401
+ try {
4402
+ return yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_transact, "f").call(this, (wallet) => __awaiter(this, void 0, void 0, function* () {
4403
+ yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_performReauthorization, "f").call(this, wallet, authToken, chain);
4404
+ const signedMessages = (yield wallet.signMessages({
4405
+ addresses: addresses,
4406
+ payloads: messages,
4407
+ })).signed_payloads.map(toUint8Array);
4408
+ return signedMessages.map((signedMessage) => {
4409
+ return { signedMessage: signedMessage, signature: signedMessage.slice(-SIGNATURE_LENGTH_IN_BYTES) };
4410
+ });
4411
+ }));
4412
+ }
4413
+ catch (e) {
4414
+ throw new Error((e instanceof Error && e.message) || 'Unknown error');
4415
+ }
4416
+ }));
4417
+ _RemoteSolanaMobileWalletAdapterWallet_signIn.set(this, (...inputs) => __awaiter(this, void 0, void 0, function* () {
4418
+ const outputs = [];
4419
+ if (inputs.length > 1) {
4420
+ for (const input of inputs) {
4421
+ outputs.push(yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_performSignIn, "f").call(this, input));
4422
+ }
4423
+ }
4424
+ else {
4425
+ return [yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_performSignIn, "f").call(this, inputs[0])];
4426
+ }
4427
+ return outputs;
4428
+ }));
4429
+ _RemoteSolanaMobileWalletAdapterWallet_performSignIn.set(this, (input) => __awaiter(this, void 0, void 0, function* () {
4430
+ var _g, _h, _j;
4431
+ __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connecting, true);
4432
+ try {
4433
+ const authorizationResult = yield __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_performAuthorization, "f").call(this, Object.assign(Object.assign({}, input), { domain: (_g = input === null || input === void 0 ? void 0 : input.domain) !== null && _g !== void 0 ? _g : window.location.host }));
4434
+ if (!authorizationResult.sign_in_result) {
4435
+ throw new Error("Sign in failed, no sign in result returned by wallet");
4436
+ }
4437
+ const signedInAddress = authorizationResult.sign_in_result.address;
4438
+ const signedInAccount = authorizationResult.accounts.find(acc => acc.address == signedInAddress);
4439
+ return {
4440
+ account: Object.assign(Object.assign({}, signedInAccount !== null && signedInAccount !== void 0 ? signedInAccount : {
4441
+ address: base58.encode(toUint8Array(signedInAddress))
4442
+ }), { publicKey: toUint8Array(signedInAddress), chains: (_h = signedInAccount === null || signedInAccount === void 0 ? void 0 : signedInAccount.chains) !== null && _h !== void 0 ? _h : __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_chains, "f"), features: (_j = signedInAccount === null || signedInAccount === void 0 ? void 0 : signedInAccount.features) !== null && _j !== void 0 ? _j : authorizationResult.capabilities.features }),
4443
+ signedMessage: toUint8Array(authorizationResult.sign_in_result.signed_message),
4444
+ signature: toUint8Array(authorizationResult.sign_in_result.signature)
4445
+ };
4446
+ }
4447
+ catch (e) {
4448
+ throw new Error((e instanceof Error && e.message) || 'Unknown error');
4449
+ }
4450
+ finally {
4451
+ __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connecting, false);
4452
+ }
4453
+ }));
4454
+ __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorizationCache, config.authorizationCache);
4455
+ __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_appIdentity, config.appIdentity);
4456
+ __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_chains, config.chains);
4457
+ __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_chainSelector, config.chainSelector);
4458
+ __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_hostAuthority, config.remoteHostAuthority);
4459
+ __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_onWalletNotFound, config.onWalletNotFound);
4460
+ __classPrivateFieldSet$1(this, _RemoteSolanaMobileWalletAdapterWallet_optionalFeatures, {
4461
+ // In MWA 1.0, signAndSend is optional and signTransaction is mandatory. Whereas in MWA 2.0+,
4462
+ // signAndSend is mandatory and signTransaction is optional (and soft deprecated). As of mid
4463
+ // 2025, all MWA wallets support both signAndSendTransaction and signTransaction so its safe
4464
+ // assume both are supported here. The features will be updated based on the actual connected
4465
+ // wallets capabilities during connection regardless, so this is safe.
4466
+ [SolanaSignAndSendTransaction]: {
4467
+ version: '1.0.0',
4468
+ supportedTransactionVersions: ['legacy', 0],
4469
+ signAndSendTransaction: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_signAndSendTransaction, "f"),
4470
+ },
4471
+ [SolanaSignTransaction]: {
4472
+ version: '1.0.0',
4473
+ supportedTransactionVersions: ['legacy', 0],
4474
+ signTransaction: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_signTransaction, "f"),
4475
+ },
4476
+ });
4477
+ }
4478
+ get version() {
4479
+ return __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_version, "f");
4480
+ }
4481
+ get name() {
4482
+ return __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_name, "f");
4483
+ }
4484
+ get url() {
4485
+ return __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_url, "f");
4486
+ }
4487
+ get icon() {
4488
+ return __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_icon, "f");
4489
+ }
4490
+ get chains() {
4491
+ return __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_chains, "f");
4492
+ }
4493
+ get features() {
4494
+ return Object.assign({ [StandardConnect]: {
4495
+ version: '1.0.0',
4496
+ connect: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_connect, "f"),
4497
+ }, [StandardDisconnect]: {
4498
+ version: '1.0.0',
4499
+ disconnect: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_disconnect, "f"),
4500
+ }, [StandardEvents]: {
4501
+ version: '1.0.0',
4502
+ on: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_on, "f"),
4503
+ }, [SolanaSignMessage]: {
4504
+ version: '1.0.0',
4505
+ signMessage: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_signMessage, "f"),
4506
+ }, [SolanaSignIn]: {
4507
+ version: '1.0.0',
4508
+ signIn: __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_signIn, "f"),
4509
+ } }, __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_optionalFeatures, "f"));
4510
+ }
4511
+ get accounts() {
4512
+ var _a, _b;
4513
+ return (_b = (_a = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f")) === null || _a === void 0 ? void 0 : _a.accounts) !== null && _b !== void 0 ? _b : [];
4514
+ }
4515
+ get connected() {
4516
+ return !!__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_session, "f") && !!__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f");
4517
+ }
4518
+ get isAuthorized() {
4519
+ return !!__classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f");
4520
+ }
4521
+ get currentAuthorization() {
4522
+ return __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorization, "f");
4523
+ }
4524
+ get cachedAuthorizationResult() {
4525
+ return __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_authorizationCache, "f").get();
4526
+ }
4527
+ }
4528
+ _RemoteSolanaMobileWalletAdapterWallet_listeners = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_version = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_name = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_url = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_icon = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_appIdentity = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_authorization = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_authorizationCache = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_connecting = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_connectionGeneration = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_chains = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_chainSelector = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_optionalFeatures = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_onWalletNotFound = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_hostAuthority = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_session = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_on = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_connect = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_performAuthorization = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_handleAuthorizationResult = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_handleWalletCapabilitiesResult = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_performReauthorization = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_disconnect = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_transact = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_assertIsAuthorized = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_accountsToWalletStandardAccounts = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_performSignTransactions = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_performSignAndSendTransaction = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_signAndSendTransaction = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_signTransaction = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_signMessage = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_signIn = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_performSignIn = new WeakMap(), _RemoteSolanaMobileWalletAdapterWallet_instances = new WeakSet(), _RemoteSolanaMobileWalletAdapterWallet_emit = function _RemoteSolanaMobileWalletAdapterWallet_emit(event, ...args) {
4529
+ var _a;
4530
+ // eslint-disable-next-line prefer-spread
4531
+ (_a = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_listeners, "f")[event]) === null || _a === void 0 ? void 0 : _a.forEach((listener) => listener.apply(null, args));
4532
+ }, _RemoteSolanaMobileWalletAdapterWallet_off = function _RemoteSolanaMobileWalletAdapterWallet_off(event, listener) {
4533
+ var _a;
4534
+ __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_listeners, "f")[event] = (_a = __classPrivateFieldGet$1(this, _RemoteSolanaMobileWalletAdapterWallet_listeners, "f")[event]) === null || _a === void 0 ? void 0 : _a.filter((existingListener) => listener !== existingListener);
4535
+ };
4536
+
4537
+ var __classPrivateFieldSet = function (receiver, state, value, kind, f) {
4538
+ if (kind === "m") throw new TypeError("Private method is not writable");
4539
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4540
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
4541
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
4542
+ };
4543
+ var __classPrivateFieldGet = function (receiver, state, kind, f) {
4544
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4545
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4546
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
4547
+ };
4548
+ var _RegisterWalletEvent_detail;
4549
+ /**
4550
+ * Register a {@link "@wallet-standard/base".Wallet} as a Standard Wallet with the app.
4551
+ *
4552
+ * This dispatches a {@link "@wallet-standard/base".WindowRegisterWalletEvent} to notify the app that the Wallet is
4553
+ * ready to be registered.
4554
+ *
4555
+ * This also adds a listener for {@link "@wallet-standard/base".WindowAppReadyEvent} to listen for a notification from
4556
+ * the app that the app is ready to register the Wallet.
4557
+ *
4558
+ * This combination of event dispatch and listener guarantees that the Wallet will be registered synchronously as soon
4559
+ * as the app is ready whether the Wallet loads before or after the app.
4560
+ *
4561
+ * @param wallet Wallet to register.
4562
+ *
4563
+ * @group Wallet
4564
+ */
4565
+ function registerWallet(wallet) {
4566
+ const callback = ({ register }) => register(wallet);
4567
+ try {
4568
+ window.dispatchEvent(new RegisterWalletEvent(callback));
4569
+ }
4570
+ catch (error) {
4571
+ console.error('wallet-standard:register-wallet event could not be dispatched\n', error);
4572
+ }
4573
+ try {
4574
+ window.addEventListener('wallet-standard:app-ready', ({ detail: api }) => callback(api));
4575
+ }
4576
+ catch (error) {
4577
+ console.error('wallet-standard:app-ready event listener could not be added\n', error);
4578
+ }
4579
+ }
4580
+ class RegisterWalletEvent extends Event {
4581
+ constructor(callback) {
4582
+ super('wallet-standard:register-wallet', {
4583
+ bubbles: false,
4584
+ cancelable: false,
4585
+ composed: false,
4586
+ });
4587
+ _RegisterWalletEvent_detail.set(this, void 0);
4588
+ __classPrivateFieldSet(this, _RegisterWalletEvent_detail, callback, "f");
4589
+ }
4590
+ get detail() {
4591
+ return __classPrivateFieldGet(this, _RegisterWalletEvent_detail, "f");
4592
+ }
4593
+ get type() {
4594
+ return 'wallet-standard:register-wallet';
4595
+ }
4596
+ /** @deprecated */
4597
+ preventDefault() {
4598
+ throw new Error('preventDefault cannot be called');
4599
+ }
4600
+ /** @deprecated */
4601
+ stopImmediatePropagation() {
4602
+ throw new Error('stopImmediatePropagation cannot be called');
4603
+ }
4604
+ /** @deprecated */
4605
+ stopPropagation() {
4606
+ throw new Error('stopPropagation cannot be called');
4607
+ }
4608
+ }
4609
+ _RegisterWalletEvent_detail = new WeakMap();
4610
+
4611
+ function getIsLocalAssociationSupported() {
4612
+ return (typeof window !== 'undefined' &&
4613
+ window.isSecureContext &&
4614
+ typeof document !== 'undefined' &&
4615
+ /android/i.test(navigator.userAgent));
4616
+ }
4617
+ function getIsRemoteAssociationSupported() {
4618
+ return (typeof window !== 'undefined' &&
4619
+ window.isSecureContext &&
4620
+ typeof document !== 'undefined' &&
4621
+ !/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
4622
+ }
4623
+ // Source: https://github.com/anza-xyz/wallet-adapter/blob/master/packages/core/react/src/getEnvironment.ts#L14
4624
+ // This is the same implementation that gated MWA in the Anza wallet-adapter-react library.
4625
+ function isWebView(userAgentString) {
4626
+ return /(WebView|Version\/.+(Chrome)\/(\d+)\.(\d+)\.(\d+)\.(\d+)|; wv\).+(Chrome)\/(\d+)\.(\d+)\.(\d+)\.(\d+))/i.test(userAgentString);
4627
+ }
4628
+
4629
+ function registerMwa(config) {
4630
+ if (typeof window === 'undefined') {
4631
+ console.warn(`MWA not registered: no window object`);
4632
+ return;
4633
+ }
4634
+ if (!window.isSecureContext) {
4635
+ console.warn(`MWA not registered: secure context required (https)`);
4636
+ return;
4637
+ }
4638
+ // Local association technically is possible in a webview, but we prevent registration
4639
+ // by default because it usually fails in the most common cases (e.g wallet browsers).
4640
+ if (getIsLocalAssociationSupported() && !isWebView(navigator.userAgent)) {
4641
+ registerWallet(new LocalSolanaMobileWalletAdapterWallet(config));
4642
+ }
4643
+ else if (getIsRemoteAssociationSupported() && config.remoteHostAuthority !== undefined) {
4644
+ registerWallet(new RemoteSolanaMobileWalletAdapterWallet(Object.assign(Object.assign({}, config), { remoteHostAuthority: config.remoteHostAuthority })));
4645
+ }
4646
+ else ;
4647
+ }
4648
+
4649
+ const WALLET_NOT_FOUND_ERROR_MESSAGE = 'To use mobile wallet adapter, you must have a compatible mobile wallet application installed on your device.';
4650
+ const BROWSER_NOT_SUPPORTED_ERROR_MESSAGE = 'This browser appears to be incompatible with mobile wallet adapter. Open this page in a compatible mobile browser app and try again.';
4651
+ class ErrorModal extends EmbeddedModal {
4652
+ constructor() {
4653
+ super(...arguments);
4654
+ this.contentStyles = css;
4655
+ this.contentHtml = ErrorDialogHtml;
4656
+ }
4657
+ initWithError(error) {
4658
+ super.init();
4659
+ this.populateError(error);
4660
+ }
4661
+ populateError(error) {
4662
+ var _a, _b;
4663
+ const errorMessageElement = (_a = this.dom) === null || _a === void 0 ? void 0 : _a.getElementById('mobile-wallet-adapter-error-message');
4664
+ const actionBtn = (_b = this.dom) === null || _b === void 0 ? void 0 : _b.getElementById('mobile-wallet-adapter-error-action');
4665
+ if (errorMessageElement) {
4666
+ if (error.name === 'SolanaMobileWalletAdapterError') {
4667
+ switch (error.code) {
4668
+ case 'ERROR_WALLET_NOT_FOUND':
4669
+ errorMessageElement.innerHTML = WALLET_NOT_FOUND_ERROR_MESSAGE;
4670
+ if (actionBtn)
4671
+ actionBtn.addEventListener('click', () => {
4672
+ window.location.href = 'https://solanamobile.com/wallets';
4673
+ });
4674
+ return;
4675
+ case 'ERROR_BROWSER_NOT_SUPPORTED':
4676
+ errorMessageElement.innerHTML = BROWSER_NOT_SUPPORTED_ERROR_MESSAGE;
4677
+ if (actionBtn)
4678
+ actionBtn.style.display = 'none';
4679
+ return;
4680
+ }
4681
+ }
4682
+ errorMessageElement.innerHTML = `An unexpected error occurred: ${error.message}`;
4683
+ }
4684
+ else {
4685
+ console.log('Failed to locate error dialog element');
4686
+ }
4687
+ }
4688
+ }
4689
+ const ErrorDialogHtml = `
4690
+ <svg class="mobile-wallet-adapter-embedded-modal-error-icon" xmlns="http://www.w3.org/2000/svg" height="50px" viewBox="0 -960 960 960" width="50px" fill="#000000"><path d="M 280,-80 Q 197,-80 138.5,-138.5 80,-197 80,-280 80,-363 138.5,-421.5 197,-480 280,-480 q 83,0 141.5,58.5 58.5,58.5 58.5,141.5 0,83 -58.5,141.5 Q 363,-80 280,-80 Z M 824,-120 568,-376 Q 556,-389 542.5,-402.5 529,-416 516,-428 q 38,-24 61,-64 23,-40 23,-88 0,-75 -52.5,-127.5 Q 495,-760 420,-760 345,-760 292.5,-707.5 240,-655 240,-580 q 0,6 0.5,11.5 0.5,5.5 1.5,11.5 -18,2 -39.5,8 -21.5,6 -38.5,14 -2,-11 -3,-22 -1,-11 -1,-23 0,-109 75.5,-184.5 Q 311,-840 420,-840 q 109,0 184.5,75.5 75.5,75.5 75.5,184.5 0,43 -13.5,81.5 Q 653,-460 629,-428 l 251,252 z m -615,-61 71,-71 70,71 29,-28 -71,-71 71,-71 -28,-28 -71,71 -71,-71 -28,28 71,71 -71,71 z"/></svg>
4691
+ <div class="mobile-wallet-adapter-embedded-modal-title">We can't find a wallet.</div>
4692
+ <div id="mobile-wallet-adapter-error-message" class="mobile-wallet-adapter-embedded-modal-subtitle"></div>
4693
+ <div>
4694
+ <button data-error-action id="mobile-wallet-adapter-error-action" class="mobile-wallet-adapter-embedded-modal-error-action">
4695
+ Find a wallet
4696
+ </button>
4697
+ </div>
4698
+ `;
4699
+ const css = `
4700
+ .mobile-wallet-adapter-embedded-modal-content {
4701
+ text-align: center;
4702
+ }
4703
+
4704
+ .mobile-wallet-adapter-embedded-modal-error-icon {
4705
+ margin-top: 24px;
4706
+ }
4707
+
4708
+ .mobile-wallet-adapter-embedded-modal-title {
4709
+ margin: 18px 100px auto 100px;
4710
+ color: #000000;
4711
+ font-size: 2.75em;
4712
+ font-weight: 600;
4713
+ }
4714
+
4715
+ .mobile-wallet-adapter-embedded-modal-subtitle {
4716
+ margin: 30px 60px 40px 60px;
4717
+ color: #000000;
4718
+ font-size: 1.25em;
4719
+ font-weight: 400;
4720
+ }
4721
+
4722
+ .mobile-wallet-adapter-embedded-modal-error-action {
4723
+ display: block;
4724
+ width: 100%;
4725
+ height: 56px;
4726
+ /*margin-top: 40px;*/
4727
+ font-size: 1.25em;
4728
+ /*line-height: 24px;*/
4729
+ /*letter-spacing: -1%;*/
4730
+ background: #000000;
4731
+ color: #FFFFFF;
4732
+ border-radius: 18px;
4733
+ }
4734
+
4735
+ /* Smaller screens */
4736
+ @media all and (max-width: 600px) {
4737
+ .mobile-wallet-adapter-embedded-modal-title {
4738
+ font-size: 1.5em;
4739
+ margin-right: 12px;
4740
+ margin-left: 12px;
4741
+ }
4742
+ .mobile-wallet-adapter-embedded-modal-subtitle {
4743
+ margin-right: 12px;
4744
+ margin-left: 12px;
4745
+ }
4746
+ }
4747
+ `;
4748
+
4749
+ function defaultErrorModalWalletNotFoundHandler() {
4750
+ return __awaiter(this, void 0, void 0, function* () {
4751
+ if (typeof window !== 'undefined') {
4752
+ const userAgent = window.navigator.userAgent.toLowerCase();
4753
+ const errorDialog = new ErrorModal();
4754
+ if (userAgent.includes('wv')) { // Android WebView
4755
+ // MWA is not supported in this browser so we inform the user
4756
+ // errorDialog.initWithError(
4757
+ // new SolanaMobileWalletAdapterError(
4758
+ // SolanaMobileWalletAdapterErrorCode.ERROR_BROWSER_NOT_SUPPORTED,
4759
+ // ''
4760
+ // )
4761
+ // );
4762
+ // TODO: investigate why instantiating a new SolanaMobileWalletAdapterError here breaks treeshaking
4763
+ errorDialog.initWithError({
4764
+ name: 'SolanaMobileWalletAdapterError',
4765
+ code: 'ERROR_BROWSER_NOT_SUPPORTED',
4766
+ message: ''
4767
+ });
4768
+ }
4769
+ else { // Browser, user does not have a wallet installed.
4770
+ // errorDialog.initWithError(
4771
+ // new SolanaMobileWalletAdapterError(
4772
+ // SolanaMobileWalletAdapterErrorCode.ERROR_WALLET_NOT_FOUND,
4773
+ // ''
4774
+ // )
4775
+ // );
4776
+ // TODO: investigate why instantiating a new SolanaMobileWalletAdapterError here breaks treeshaking
4777
+ errorDialog.initWithError({
4778
+ name: 'SolanaMobileWalletAdapterError',
4779
+ code: 'ERROR_WALLET_NOT_FOUND',
4780
+ message: ''
4781
+ });
4782
+ }
4783
+ errorDialog.open();
4784
+ }
4785
+ });
4786
+ }
4787
+ function createDefaultWalletNotFoundHandler() {
4788
+ return () => __awaiter(this, void 0, void 0, function* () { defaultErrorModalWalletNotFoundHandler(); });
4789
+ }
4790
+
4791
+ const CACHE_KEY = 'SolanaMobileWalletAdapterDefaultAuthorizationCache';
4792
+ function createDefaultAuthorizationCache() {
4793
+ let storage;
4794
+ try {
4795
+ storage = window.localStorage;
4796
+ // eslint-disable-next-line no-empty
4797
+ }
4798
+ catch (_a) { }
4799
+ return {
4800
+ clear() {
4801
+ return __awaiter(this, void 0, void 0, function* () {
4802
+ if (!storage) {
4803
+ return;
4804
+ }
4805
+ try {
4806
+ storage.removeItem(CACHE_KEY);
4807
+ // eslint-disable-next-line no-empty
4808
+ }
4809
+ catch (_a) { }
4810
+ });
4811
+ },
4812
+ get() {
4813
+ return __awaiter(this, void 0, void 0, function* () {
4814
+ if (!storage) {
4815
+ return;
4816
+ }
4817
+ try {
4818
+ const parsed = JSON.parse(storage.getItem(CACHE_KEY));
4819
+ if (parsed && parsed.accounts) {
4820
+ const parsedAccounts = parsed.accounts.map((account) => {
4821
+ return Object.assign(Object.assign({}, account), { publicKey: 'publicKey' in account
4822
+ ? new Uint8Array(Object.values(account.publicKey)) // Rebuild publicKey for WalletAccount
4823
+ : base58.decode(account.address) });
4824
+ });
4825
+ return Object.assign(Object.assign({}, parsed), { accounts: parsedAccounts });
4826
+ }
4827
+ else
4828
+ return parsed || undefined;
4829
+ // eslint-disable-next-line no-empty
4830
+ }
4831
+ catch (_a) { }
4832
+ });
4833
+ },
4834
+ set(authorization) {
4835
+ return __awaiter(this, void 0, void 0, function* () {
4836
+ if (!storage) {
4837
+ return;
4838
+ }
4839
+ try {
4840
+ storage.setItem(CACHE_KEY, JSON.stringify(authorization));
4841
+ // eslint-disable-next-line no-empty
4842
+ }
4843
+ catch (_a) { }
4844
+ });
4845
+ },
4846
+ };
4847
+ }
4848
+
4849
+ function createDefaultChainSelector() {
4850
+ return {
4851
+ select(chains) {
4852
+ return __awaiter(this, void 0, void 0, function* () {
4853
+ if (chains.length === 1) {
4854
+ return chains[0];
4855
+ }
4856
+ else if (chains.includes(SOLANA_MAINNET_CHAIN)) {
4857
+ return SOLANA_MAINNET_CHAIN;
4858
+ }
4859
+ else
4860
+ return chains[0];
4861
+ });
4862
+ },
4863
+ };
4864
+ }
4865
+
4866
+ export { LocalSolanaMobileWalletAdapterWallet, RemoteSolanaMobileWalletAdapterWallet, SolanaMobileWalletAdapterRemoteWalletName, SolanaMobileWalletAdapterWalletName, createDefaultAuthorizationCache, createDefaultChainSelector, createDefaultWalletNotFoundHandler, defaultErrorModalWalletNotFoundHandler, registerMwa };
4867
+ //# sourceMappingURL=index.browser-C6e2ssNC.esm.js.map