@pezkuwi/react-qr 3.16.6 → 3.16.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/package.json +237 -3
  2. package/build/Display.js +0 -91
  3. package/build/DisplayAddress.js +0 -12
  4. package/build/DisplayPayload.js +0 -12
  5. package/build/NetworkSpecs.js +0 -12
  6. package/build/README.md +0 -3
  7. package/build/Scan.js +0 -53
  8. package/build/ScanAddress.js +0 -41
  9. package/build/ScanSignature.js +0 -8
  10. package/build/bundle.js +0 -6
  11. package/build/cjs/Display.d.ts +0 -12
  12. package/build/cjs/Display.js +0 -95
  13. package/build/cjs/DisplayAddress.d.ts +0 -12
  14. package/build/cjs/DisplayAddress.js +0 -16
  15. package/build/cjs/DisplayPayload.d.ts +0 -15
  16. package/build/cjs/DisplayPayload.js +0 -16
  17. package/build/cjs/NetworkSpecs.d.ts +0 -11
  18. package/build/cjs/NetworkSpecs.js +0 -16
  19. package/build/cjs/Scan.d.ts +0 -12
  20. package/build/cjs/Scan.js +0 -57
  21. package/build/cjs/ScanAddress.d.ts +0 -19
  22. package/build/cjs/ScanAddress.js +0 -45
  23. package/build/cjs/ScanSignature.d.ts +0 -15
  24. package/build/cjs/ScanSignature.js +0 -12
  25. package/build/cjs/bundle.d.ts +0 -6
  26. package/build/cjs/bundle.js +0 -15
  27. package/build/cjs/constants.js +0 -12
  28. package/build/cjs/index.js +0 -5
  29. package/build/cjs/packageDetect.js +0 -5
  30. package/build/cjs/packageInfo.js +0 -4
  31. package/build/cjs/qrcode.js +0 -8
  32. package/build/cjs/styled.js +0 -5
  33. package/build/cjs/util.js +0 -59
  34. package/build/constants.d.ts +0 -9
  35. package/build/constants.js +0 -9
  36. package/build/index.d.ts +0 -2
  37. package/build/index.js +0 -2
  38. package/build/package.json +0 -274
  39. package/build/packageDetect.d.ts +0 -1
  40. package/build/packageDetect.js +0 -3
  41. package/build/packageInfo.d.ts +0 -6
  42. package/build/packageInfo.js +0 -1
  43. package/build/qrcode.d.ts +0 -3
  44. package/build/qrcode.js +0 -4
  45. package/build/styled.d.ts +0 -1
  46. package/build/styled.js +0 -1
  47. package/build/util.d.ts +0 -7
  48. package/build/util.js +0 -50
  49. package/src/Display.tsx +0 -153
  50. package/src/DisplayAddress.tsx +0 -40
  51. package/src/DisplayPayload.tsx +0 -42
  52. package/src/NetworkSpecs.tsx +0 -39
  53. package/src/Scan.tsx +0 -100
  54. package/src/ScanAddress.tsx +0 -82
  55. package/src/ScanSignature.tsx +0 -39
  56. package/src/bundle.ts +0 -9
  57. package/src/constants.ts +0 -12
  58. package/src/index.ts +0 -6
  59. package/src/packageDetect.ts +0 -11
  60. package/src/packageInfo.ts +0 -6
  61. package/src/qrcode.ts +0 -15
  62. package/src/styled.ts +0 -4
  63. package/src/util.spec.ts +0 -100
  64. package/src/util.ts +0 -83
  65. package/tsconfig.build.json +0 -14
  66. package/tsconfig.build.tsbuildinfo +0 -1
  67. package/tsconfig.spec.json +0 -16
  68. package/tsconfig.spec.tsbuildinfo +0 -1
  69. /package/{build-tsc/Display.d.ts → Display.d.ts} +0 -0
  70. /package/{build-tsc-esm/Display.js → Display.js} +0 -0
  71. /package/{build-tsc/DisplayAddress.d.ts → DisplayAddress.d.ts} +0 -0
  72. /package/{build-tsc-esm/DisplayAddress.js → DisplayAddress.js} +0 -0
  73. /package/{build-tsc/DisplayPayload.d.ts → DisplayPayload.d.ts} +0 -0
  74. /package/{build-tsc-esm/DisplayPayload.js → DisplayPayload.js} +0 -0
  75. /package/{build/LICENSE → LICENSE} +0 -0
  76. /package/{build-tsc/NetworkSpecs.d.ts → NetworkSpecs.d.ts} +0 -0
  77. /package/{build-tsc-esm/NetworkSpecs.js → NetworkSpecs.js} +0 -0
  78. /package/{build-tsc/Scan.d.ts → Scan.d.ts} +0 -0
  79. /package/{build-tsc-esm/Scan.js → Scan.js} +0 -0
  80. /package/{build-tsc/ScanAddress.d.ts → ScanAddress.d.ts} +0 -0
  81. /package/{build-tsc-esm/ScanAddress.js → ScanAddress.js} +0 -0
  82. /package/{build-tsc/ScanSignature.d.ts → ScanSignature.d.ts} +0 -0
  83. /package/{build-tsc-esm/ScanSignature.js → ScanSignature.js} +0 -0
  84. /package/{build/bundle-pezkuwi-react-qr.js → bundle-pezkuwi-react-qr.js} +0 -0
  85. /package/{build-tsc/bundle.d.ts → bundle.d.ts} +0 -0
  86. /package/{build-tsc-esm/bundle.js → bundle.js} +0 -0
  87. /package/{build → cjs}/Display.d.ts +0 -0
  88. /package/{build-tsc-cjs → cjs}/Display.js +0 -0
  89. /package/{build → cjs}/DisplayAddress.d.ts +0 -0
  90. /package/{build-tsc-cjs → cjs}/DisplayAddress.js +0 -0
  91. /package/{build → cjs}/DisplayPayload.d.ts +0 -0
  92. /package/{build-tsc-cjs → cjs}/DisplayPayload.js +0 -0
  93. /package/{build → cjs}/NetworkSpecs.d.ts +0 -0
  94. /package/{build-tsc-cjs → cjs}/NetworkSpecs.js +0 -0
  95. /package/{build → cjs}/Scan.d.ts +0 -0
  96. /package/{build-tsc-cjs → cjs}/Scan.js +0 -0
  97. /package/{build → cjs}/ScanAddress.d.ts +0 -0
  98. /package/{build-tsc-cjs → cjs}/ScanAddress.js +0 -0
  99. /package/{build → cjs}/ScanSignature.d.ts +0 -0
  100. /package/{build-tsc-cjs → cjs}/ScanSignature.js +0 -0
  101. /package/{build → cjs}/bundle.d.ts +0 -0
  102. /package/{build-tsc-cjs → cjs}/bundle.js +0 -0
  103. /package/{build-tsc → cjs}/constants.d.ts +0 -0
  104. /package/{build-tsc-cjs → cjs}/constants.js +0 -0
  105. /package/{build-tsc → cjs}/index.d.ts +0 -0
  106. /package/{build-tsc-cjs → cjs}/index.js +0 -0
  107. /package/{build/cjs → cjs}/package.json +0 -0
  108. /package/{build-tsc → cjs}/packageDetect.d.ts +0 -0
  109. /package/{build-tsc-cjs → cjs}/packageDetect.js +0 -0
  110. /package/{build-tsc → cjs}/packageInfo.d.ts +0 -0
  111. /package/{build-tsc-cjs → cjs}/packageInfo.js +0 -0
  112. /package/{build-tsc → cjs}/qrcode.d.ts +0 -0
  113. /package/{build-tsc-cjs → cjs}/qrcode.js +0 -0
  114. /package/{build-tsc → cjs}/styled.d.ts +0 -0
  115. /package/{build-tsc-cjs → cjs}/styled.js +0 -0
  116. /package/{build-tsc → cjs}/util.d.ts +0 -0
  117. /package/{build-tsc-cjs → cjs}/util.js +0 -0
  118. /package/{build/cjs/constants.d.ts → constants.d.ts} +0 -0
  119. /package/{build-tsc-esm/constants.js → constants.js} +0 -0
  120. /package/{build/cjs/index.d.ts → index.d.ts} +0 -0
  121. /package/{build-tsc-esm/index.js → index.js} +0 -0
  122. /package/{build/cjs/packageDetect.d.ts → packageDetect.d.ts} +0 -0
  123. /package/{build-tsc-esm/packageDetect.js → packageDetect.js} +0 -0
  124. /package/{build/cjs/packageInfo.d.ts → packageInfo.d.ts} +0 -0
  125. /package/{build-tsc-esm/packageInfo.js → packageInfo.js} +0 -0
  126. /package/{build/cjs/qrcode.d.ts → qrcode.d.ts} +0 -0
  127. /package/{build-tsc-esm/qrcode.js → qrcode.js} +0 -0
  128. /package/{build/cjs/styled.d.ts → styled.d.ts} +0 -0
  129. /package/{build-tsc-esm/styled.js → styled.js} +0 -0
  130. /package/{build/cjs/util.d.ts → util.d.ts} +0 -0
  131. /package/{build-tsc-esm/util.js → util.js} +0 -0
package/build/qrcode.js DELETED
@@ -1,4 +0,0 @@
1
- import _qrcode from 'qrcode-generator';
2
- const qrcode = _qrcode;
3
- qrcode.stringToBytes = (data) => data;
4
- export { qrcode };
package/build/styled.d.ts DELETED
@@ -1 +0,0 @@
1
- export { styled } from 'styled-components';
package/build/styled.js DELETED
@@ -1 +0,0 @@
1
- export { styled } from 'styled-components';
package/build/util.d.ts DELETED
@@ -1,7 +0,0 @@
1
- export declare function encodeNumber(value: number): Uint8Array;
2
- export declare function encodeString(value: string): Uint8Array;
3
- export declare function decodeString(value: Uint8Array): string;
4
- export declare function createAddressPayload(address: string, genesisHash: string): Uint8Array;
5
- export declare function createSignPayload(address: string, cmd: number, payload: string | Uint8Array, genesisHash: string | Uint8Array): Uint8Array;
6
- export declare function createFrames(input: Uint8Array): Uint8Array[];
7
- export declare function createImgSize(size?: string | number): Record<string, string>;
package/build/util.js DELETED
@@ -1,50 +0,0 @@
1
- import { isString, u8aConcat, u8aToU8a } from '@pezkuwi/util';
2
- import { decodeAddress } from '@pezkuwi/util-crypto';
3
- import { ADDRESS_PREFIX, CRYPTO_SR25519, FRAME_SIZE, SUBSTRATE_ID } from './constants.js';
4
- const MULTIPART = new Uint8Array([0]);
5
- export function encodeNumber(value) {
6
- return new Uint8Array([value >> 8, value & 0xff]);
7
- }
8
- export function encodeString(value) {
9
- const count = value.length;
10
- const u8a = new Uint8Array(count);
11
- for (let i = 0; i < count; i++) {
12
- u8a[i] = value.charCodeAt(i);
13
- }
14
- return u8a;
15
- }
16
- export function decodeString(value) {
17
- return value.reduce((str, code) => {
18
- return str + String.fromCharCode(code);
19
- }, '');
20
- }
21
- export function createAddressPayload(address, genesisHash) {
22
- return encodeString(`${ADDRESS_PREFIX}:${address}:${genesisHash}`);
23
- }
24
- export function createSignPayload(address, cmd, payload, genesisHash) {
25
- return u8aConcat(SUBSTRATE_ID, CRYPTO_SR25519, new Uint8Array([cmd]), decodeAddress(address), u8aToU8a(payload), u8aToU8a(genesisHash));
26
- }
27
- export function createFrames(input) {
28
- const frames = [];
29
- let idx = 0;
30
- while (idx < input.length) {
31
- frames.push(input.subarray(idx, idx + FRAME_SIZE));
32
- idx += FRAME_SIZE;
33
- }
34
- return frames.map((frame, index) => u8aConcat(MULTIPART, encodeNumber(frames.length), encodeNumber(index), frame));
35
- }
36
- export function createImgSize(size) {
37
- if (!size) {
38
- return {
39
- height: 'auto',
40
- width: '100%'
41
- };
42
- }
43
- const height = isString(size)
44
- ? size
45
- : `${size}px`;
46
- return {
47
- height,
48
- width: height
49
- };
50
- }
package/src/Display.tsx DELETED
@@ -1,153 +0,0 @@
1
- // Copyright 2017-2025 @pezkuwi/react-qr authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import React, { useEffect, useMemo, useRef, useState } from 'react';
5
-
6
- import { objectSpread } from '@pezkuwi/util';
7
- import { xxhashAsHex } from '@pezkuwi/util-crypto';
8
-
9
- import { qrcode } from './qrcode.js';
10
- import { styled } from './styled.js';
11
- import { createFrames, createImgSize } from './util.js';
12
-
13
- interface Props {
14
- className?: string | undefined;
15
- size?: string | number | undefined;
16
- skipEncoding?: boolean;
17
- style?: React.CSSProperties | undefined;
18
- timerDelay?: number | undefined;
19
- value: Uint8Array;
20
- }
21
-
22
- interface FrameState {
23
- frames: Uint8Array[];
24
- frameIdx: number;
25
- image: string | null;
26
- valueHash: string | null;
27
- }
28
-
29
- interface TimerState {
30
- timerDelay: number;
31
- timerId: ReturnType<typeof setTimeout> | null;
32
- }
33
-
34
- const DEFAULT_FRAME_DELAY = 2750;
35
- const TIMER_INC = 500;
36
-
37
- function getDataUrl (value: Uint8Array): string {
38
- const qr = qrcode(0, 'M');
39
-
40
- // HACK See our qrcode stringToBytes override as used internally. This
41
- // will only work for the case where we actually pass `Bytes` in here
42
- qr.addData(value as unknown as string, 'Byte');
43
- qr.make();
44
-
45
- return qr.createDataURL(16, 0);
46
- }
47
-
48
- function Display ({ className = '', size, skipEncoding, style = {}, timerDelay = DEFAULT_FRAME_DELAY, value }: Props): React.ReactElement<Props> | null {
49
- const [{ image }, setFrameState] = useState<FrameState>({ frameIdx: 0, frames: [], image: null, valueHash: null });
50
- const timerRef = useRef<TimerState>({ timerDelay, timerId: null });
51
-
52
- const containerStyle = useMemo(
53
- () => createImgSize(size),
54
- [size]
55
- );
56
-
57
- // run on initial load to setup the global timer and provide and unsubscribe
58
- useEffect((): () => void => {
59
- const nextFrame = () => setFrameState((state): FrameState => {
60
- // when we have a single frame, we only ever fire once
61
- if (state.frames.length <= 1) {
62
- return state;
63
- }
64
-
65
- let frameIdx = state.frameIdx + 1;
66
-
67
- // when we overflow, skip to the first and slightly increase the delay between frames
68
- if (frameIdx === state.frames.length) {
69
- frameIdx = 0;
70
- timerRef.current.timerDelay = timerRef.current.timerDelay + TIMER_INC;
71
- }
72
-
73
- // only encode the frames on demand, not above as part of the
74
- // state derivation - in the case of large payloads, this should
75
- // be slightly more responsive on initial load
76
- const newState = objectSpread<FrameState>({}, state, {
77
- frameIdx,
78
- image: getDataUrl(state.frames[frameIdx])
79
- });
80
-
81
- // set the new timer last
82
- timerRef.current.timerId = setTimeout(nextFrame, timerRef.current.timerDelay);
83
-
84
- return newState;
85
- });
86
-
87
- timerRef.current.timerId = setTimeout(nextFrame, timerRef.current.timerDelay);
88
-
89
- return (): void => {
90
- // eslint-disable-next-line react-hooks/exhaustive-deps
91
- timerRef.current.timerId && clearTimeout(timerRef.current.timerId);
92
- };
93
- // eslint-disable-next-line react-hooks/exhaustive-deps
94
- }, []);
95
-
96
- useEffect((): void => {
97
- setFrameState((state): FrameState => {
98
- const valueHash = xxhashAsHex(value);
99
-
100
- if (valueHash === state.valueHash) {
101
- return state;
102
- }
103
-
104
- const frames: Uint8Array[] = skipEncoding
105
- ? [value]
106
- : createFrames(value);
107
-
108
- // encode on demand
109
- return {
110
- frameIdx: 0,
111
- frames,
112
- image: getDataUrl(frames[0]),
113
- valueHash
114
- };
115
- });
116
- }, [skipEncoding, value]);
117
-
118
- if (!image) {
119
- return null;
120
- }
121
-
122
- return (
123
- <StyledDiv
124
- className={className}
125
- style={containerStyle}
126
- >
127
- <div
128
- className='ui--qr-Display'
129
- style={style}
130
- >
131
- <img src={image} />
132
- </div>
133
- </StyledDiv>
134
- );
135
- }
136
-
137
- const StyledDiv = styled.div`
138
- .ui--qr-Display {
139
- height: 100%;
140
- width: 100%;
141
-
142
- img,
143
- svg {
144
- background: white;
145
- height: auto !important;
146
- max-height: 100%;
147
- max-width: 100%;
148
- width: auto !important;
149
- }
150
- }
151
- `;
152
-
153
- export const QrDisplay = React.memo(Display);
@@ -1,40 +0,0 @@
1
- // Copyright 2017-2025 @pezkuwi/react-qr authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import React, { useMemo } from 'react';
5
-
6
- import { QrDisplay } from './Display.js';
7
- import { createAddressPayload } from './util.js';
8
-
9
- interface Props {
10
- address: string;
11
- genesisHash: string;
12
- className?: string;
13
- size?: string | number;
14
- style?: React.CSSProperties;
15
- timerDelay?: number;
16
- }
17
-
18
- function DisplayAddress ({ address, className, genesisHash, size, style, timerDelay }: Props): React.ReactElement<Props> | null {
19
- const data = useMemo(
20
- () => createAddressPayload(address, genesisHash),
21
- [address, genesisHash]
22
- );
23
-
24
- if (!data) {
25
- return null;
26
- }
27
-
28
- return (
29
- <QrDisplay
30
- className={className}
31
- size={size}
32
- skipEncoding
33
- style={style}
34
- timerDelay={timerDelay}
35
- value={data}
36
- />
37
- );
38
- }
39
-
40
- export const QrDisplayAddress = React.memo(DisplayAddress);
@@ -1,42 +0,0 @@
1
- // Copyright 2017-2025 @pezkuwi/react-qr authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import React, { useMemo } from 'react';
5
-
6
- import { QrDisplay } from './Display.js';
7
- import { createSignPayload } from './util.js';
8
-
9
- interface Props {
10
- address: string;
11
- className?: string;
12
- cmd: number;
13
- delay?: number;
14
- genesisHash: Uint8Array | string;
15
- payload: Uint8Array;
16
- size?: string | number;
17
- style?: React.CSSProperties;
18
- timerDelay?: number;
19
- }
20
-
21
- function DisplayPayload ({ address, className, cmd, genesisHash, payload, size, style, timerDelay }: Props): React.ReactElement<Props> | null {
22
- const data = useMemo(
23
- () => createSignPayload(address, cmd, payload, genesisHash),
24
- [address, cmd, payload, genesisHash]
25
- );
26
-
27
- if (!data) {
28
- return null;
29
- }
30
-
31
- return (
32
- <QrDisplay
33
- className={className}
34
- size={size}
35
- style={style}
36
- timerDelay={timerDelay}
37
- value={data}
38
- />
39
- );
40
- }
41
-
42
- export const QrDisplayPayload = React.memo(DisplayPayload);
@@ -1,39 +0,0 @@
1
- // Copyright 2017-2025 @pezkuwi/react-qr authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import type { NetworkSpecsStruct } from '@pezkuwi/ui-settings/types';
5
-
6
- import React, { useMemo } from 'react';
7
-
8
- import { QrDisplay } from './Display.js';
9
- import { encodeString } from './util.js';
10
-
11
- interface Props {
12
- className?: string;
13
- networkSpecs: NetworkSpecsStruct;
14
- size?: string | number;
15
- style?: React.CSSProperties;
16
- }
17
-
18
- function DisplayNetworkSpecs ({ className, networkSpecs, size, style }: Props): React.ReactElement<Props> | null {
19
- const data = useMemo(
20
- () => encodeString(JSON.stringify(networkSpecs)),
21
- [networkSpecs]
22
- );
23
-
24
- if (!data) {
25
- return null;
26
- }
27
-
28
- return (
29
- <QrDisplay
30
- className={className}
31
- size={size}
32
- skipEncoding
33
- style={style}
34
- value={data}
35
- />
36
- );
37
- }
38
-
39
- export const QrNetworkSpecs = React.memo(DisplayNetworkSpecs);
package/src/Scan.tsx DELETED
@@ -1,100 +0,0 @@
1
- // Copyright 2017-2025 @pezkuwi/react-qr authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import { BrowserQRCodeReader, type IScannerControls } from '@zxing/browser';
5
- import React, { useCallback, useEffect, useMemo, useRef } from 'react';
6
-
7
- import { styled } from './styled.js';
8
- import { createImgSize } from './util.js';
9
-
10
- interface Props {
11
- className?: string | undefined;
12
- delay?: number;
13
- onError?: undefined | ((error: Error) => void);
14
- onScan: (data: string) => void;
15
- size?: string | number | undefined;
16
- style?: React.CSSProperties | undefined;
17
- }
18
-
19
- const DEFAULT_DELAY = 150;
20
-
21
- const DEFAULT_ERROR = (error: Error): void => {
22
- console.error('@pezkuwi/react-qr:Scan', error.message);
23
- };
24
-
25
- function Scan ({ className = '', delay = DEFAULT_DELAY, onError = DEFAULT_ERROR, onScan, size, style = {} }: Props): React.ReactElement<Props> {
26
- const videoRef = useRef<HTMLVideoElement>(null);
27
- const controlsRef = useRef<IScannerControls | null>(null);
28
-
29
- const containerStyle = useMemo(
30
- () => createImgSize(size),
31
- [size]
32
- );
33
-
34
- const _onError = useCallback(
35
- (error: Error) => onError(error),
36
- [onError]
37
- );
38
-
39
- useEffect(() => {
40
- const codeReader = new BrowserQRCodeReader();
41
-
42
- const startScanning = async () => {
43
- try {
44
- const videoInputDevices = await BrowserQRCodeReader.listVideoInputDevices();
45
- const selectedDeviceId = videoInputDevices[0].deviceId;
46
-
47
- controlsRef.current = await codeReader.decodeFromVideoDevice(
48
- selectedDeviceId,
49
- videoRef.current ?? undefined,
50
- (result, error) => {
51
- if (result) {
52
- onScan(result.getText());
53
- }
54
-
55
- if (error && !(error instanceof Error)) {
56
- _onError(new Error(error));
57
- }
58
- }
59
- );
60
- } catch (error) {
61
- _onError(error instanceof Error ? error : new Error('Unknown error occurred'));
62
- }
63
- };
64
-
65
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
66
- const timeoutId = setTimeout(startScanning, delay);
67
-
68
- return () => {
69
- clearTimeout(timeoutId);
70
-
71
- if (controlsRef.current) {
72
- controlsRef.current.stop();
73
- }
74
- };
75
- }, [onScan, _onError, delay]);
76
-
77
- return (
78
- <StyledDiv
79
- className={className}
80
- style={containerStyle}
81
- >
82
- <video
83
- className='ui--qr-Scan'
84
- ref={videoRef}
85
- style={style}
86
- />
87
- </StyledDiv>
88
- );
89
- }
90
-
91
- const StyledDiv = styled.div`
92
- .ui--qr-Scan {
93
- display: inline-block;
94
- height: 100%;
95
- transform: matrix(-1, 0, 0, 1, 0, 0);
96
- width: 100%;
97
- }
98
- `;
99
-
100
- export const QrScan = React.memo(Scan);
@@ -1,82 +0,0 @@
1
- // Copyright 2017-2025 @pezkuwi/react-qr authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import type { HexString } from '@pezkuwi/util/types';
5
-
6
- import React, { useCallback } from 'react';
7
-
8
- import { decodeAddress } from '@pezkuwi/util-crypto';
9
-
10
- import { ADDRESS_PREFIX, SEED_PREFIX } from './constants.js';
11
- import { QrScan } from './Scan.js';
12
-
13
- interface ScanType {
14
- isAddress: boolean;
15
- content: string;
16
- genesisHash: HexString | null;
17
- name?: string | undefined;
18
- }
19
-
20
- interface Props {
21
- className?: string;
22
- onError?: (error: Error) => void;
23
- onScan: (scanned: ScanType) => void;
24
- size?: string | number;
25
- style?: React.CSSProperties;
26
- isEthereum?: boolean
27
- }
28
-
29
- function ScanAddress ({ className, isEthereum, onError, onScan, size, style }: Props): React.ReactElement<Props> {
30
- const _onScan = useCallback(
31
- (data: string | null): void => {
32
- if (data) {
33
- try {
34
- let prefix: string;
35
- let content: string;
36
- let genesisHash: string | null;
37
- let name: string[];
38
-
39
- if (!isEthereum) {
40
- [prefix, content, genesisHash, ...name] = data.split(':');
41
- } else {
42
- [prefix, content, ...name] = data.split(':');
43
- genesisHash = null;
44
- content = content.substring(0, 42);
45
- }
46
-
47
- const expectedPrefix = (isEthereum ? 'ethereum' : ADDRESS_PREFIX);
48
- const isValidPrefix = (prefix === expectedPrefix) || (prefix === SEED_PREFIX);
49
-
50
- if (!isValidPrefix) {
51
- throw new Error(`Invalid prefix received, expected '${expectedPrefix} or ${SEED_PREFIX}' , found '${prefix}'`);
52
- }
53
-
54
- const isAddress = prefix === expectedPrefix;
55
-
56
- if (isAddress && !isEthereum) {
57
- decodeAddress(content);
58
- }
59
-
60
- onScan({ content, genesisHash: genesisHash as HexString, isAddress, name: name?.length ? name.join(':') : undefined });
61
- } catch (error) {
62
- onError && onError(error as Error);
63
-
64
- console.error('@pezkuwi/react-qr:QrScanAddress', (error as Error).message, data);
65
- }
66
- }
67
- },
68
- [onScan, onError, isEthereum]
69
- );
70
-
71
- return (
72
- <QrScan
73
- className={className}
74
- onError={onError}
75
- onScan={_onScan}
76
- size={size}
77
- style={style}
78
- />
79
- );
80
- }
81
-
82
- export const QrScanAddress = React.memo(ScanAddress);
@@ -1,39 +0,0 @@
1
- // Copyright 2017-2025 @pezkuwi/react-qr authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import type { HexString } from '@pezkuwi/util/types';
5
-
6
- import React, { useCallback } from 'react';
7
-
8
- import { QrScan } from './Scan.js';
9
-
10
- interface ScanType {
11
- signature: HexString;
12
- }
13
-
14
- interface Props {
15
- className?: string;
16
- onError?: (error: Error) => void;
17
- onScan: (scanned: ScanType) => void;
18
- size?: string | number;
19
- style?: React.CSSProperties;
20
- }
21
-
22
- function ScanSignature ({ className, onError, onScan, size, style }: Props): React.ReactElement<Props> {
23
- const _onScan = useCallback(
24
- (signature: string | null) => signature && onScan({ signature: `0x${signature}` }),
25
- [onScan]
26
- );
27
-
28
- return (
29
- <QrScan
30
- className={className}
31
- onError={onError}
32
- onScan={_onScan}
33
- size={size}
34
- style={style}
35
- />
36
- );
37
- }
38
-
39
- export const QrScanSignature = React.memo(ScanSignature);
package/src/bundle.ts DELETED
@@ -1,9 +0,0 @@
1
- // Copyright 2017-2025 @pezkuwi/react-qr authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- export { QrDisplayAddress } from './DisplayAddress.js';
5
- export { QrDisplayPayload } from './DisplayPayload.js';
6
- export { QrNetworkSpecs } from './NetworkSpecs.js';
7
- export { packageInfo } from './packageInfo.js';
8
- export { QrScanAddress } from './ScanAddress.js';
9
- export { QrScanSignature } from './ScanSignature.js';
package/src/constants.ts DELETED
@@ -1,12 +0,0 @@
1
- // Copyright 2017-2025 @pezkuwi/react-qr authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- export const ADDRESS_PREFIX = 'substrate';
5
- export const SEED_PREFIX = 'secret';
6
- export const FRAME_SIZE = 1024;
7
- export const SUBSTRATE_ID = new Uint8Array([0x53]);
8
- export const CRYPTO_SR25519 = new Uint8Array([0x01]);
9
- export const CMD_SIGN_TX = new Uint8Array([0]);
10
- export const CMD_SIGN_TX_HASH = new Uint8Array([1]);
11
- export const CMD_SIGN_IMMORTAL_TX = new Uint8Array([2]);
12
- export const CMD_SIGN_MSG = new Uint8Array([3]);
package/src/index.ts DELETED
@@ -1,6 +0,0 @@
1
- // Copyright 2017-2025 @pezkuwi/react-qr authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import './packageDetect.js';
5
-
6
- export * from './bundle.js';
@@ -1,11 +0,0 @@
1
- // Copyright 2017-2026 @pezkuwi/react-qr authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- // Do not edit, auto-generated by @pezkuwi/dev
5
- // (packageInfo imports will be kept as-is, user-editable)
6
-
7
- import { detectPackage } from '@pezkuwi/util';
8
-
9
- import { packageInfo } from './packageInfo.js';
10
-
11
- detectPackage(packageInfo, null, []);
@@ -1,6 +0,0 @@
1
- // Copyright 2017-2026 @pezkuwi/react-qr authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- // Do not edit, auto-generated by @pezkuwi/dev
5
-
6
- export const packageInfo = { name: '@pezkuwi/react-qr', path: 'auto', type: 'auto', version: '3.16.6' };
package/src/qrcode.ts DELETED
@@ -1,15 +0,0 @@
1
- // Copyright 2017-2025 @pezkuwi/react-qr authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import _qrcode from 'qrcode-generator';
5
-
6
- // A small hurdle to jump through, just to get the default/default correct (as generated)
7
- const qrcode: typeof _qrcode = _qrcode;
8
-
9
- // HACK The default function take string -> number[], the Uint8array is compatible
10
- // with that signature and the use thereof
11
- // eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-member-access
12
- (qrcode as any).stringToBytes = (data: Uint8Array): Uint8Array =>
13
- data;
14
-
15
- export { qrcode };
package/src/styled.ts DELETED
@@ -1,4 +0,0 @@
1
- // Copyright 2017-2025 @pezkuwi/react-qr authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- export { styled } from 'styled-components';