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