@pezkuwi/react-qr 3.16.6

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 (132) hide show
  1. package/README.md +3 -0
  2. package/build/Display.d.ts +12 -0
  3. package/build/Display.js +91 -0
  4. package/build/DisplayAddress.d.ts +12 -0
  5. package/build/DisplayAddress.js +12 -0
  6. package/build/DisplayPayload.d.ts +15 -0
  7. package/build/DisplayPayload.js +12 -0
  8. package/build/LICENSE +201 -0
  9. package/build/NetworkSpecs.d.ts +11 -0
  10. package/build/NetworkSpecs.js +12 -0
  11. package/build/README.md +3 -0
  12. package/build/Scan.d.ts +12 -0
  13. package/build/Scan.js +53 -0
  14. package/build/ScanAddress.d.ts +19 -0
  15. package/build/ScanAddress.js +41 -0
  16. package/build/ScanSignature.d.ts +15 -0
  17. package/build/ScanSignature.js +8 -0
  18. package/build/bundle-pezkuwi-react-qr.js +26227 -0
  19. package/build/bundle.d.ts +6 -0
  20. package/build/bundle.js +6 -0
  21. package/build/cjs/Display.d.ts +12 -0
  22. package/build/cjs/Display.js +95 -0
  23. package/build/cjs/DisplayAddress.d.ts +12 -0
  24. package/build/cjs/DisplayAddress.js +16 -0
  25. package/build/cjs/DisplayPayload.d.ts +15 -0
  26. package/build/cjs/DisplayPayload.js +16 -0
  27. package/build/cjs/NetworkSpecs.d.ts +11 -0
  28. package/build/cjs/NetworkSpecs.js +16 -0
  29. package/build/cjs/Scan.d.ts +12 -0
  30. package/build/cjs/Scan.js +57 -0
  31. package/build/cjs/ScanAddress.d.ts +19 -0
  32. package/build/cjs/ScanAddress.js +45 -0
  33. package/build/cjs/ScanSignature.d.ts +15 -0
  34. package/build/cjs/ScanSignature.js +12 -0
  35. package/build/cjs/bundle.d.ts +6 -0
  36. package/build/cjs/bundle.js +15 -0
  37. package/build/cjs/constants.d.ts +9 -0
  38. package/build/cjs/constants.js +12 -0
  39. package/build/cjs/index.d.ts +2 -0
  40. package/build/cjs/index.js +5 -0
  41. package/build/cjs/package.json +3 -0
  42. package/build/cjs/packageDetect.d.ts +1 -0
  43. package/build/cjs/packageDetect.js +5 -0
  44. package/build/cjs/packageInfo.d.ts +6 -0
  45. package/build/cjs/packageInfo.js +4 -0
  46. package/build/cjs/qrcode.d.ts +3 -0
  47. package/build/cjs/qrcode.js +8 -0
  48. package/build/cjs/styled.d.ts +1 -0
  49. package/build/cjs/styled.js +5 -0
  50. package/build/cjs/util.d.ts +7 -0
  51. package/build/cjs/util.js +59 -0
  52. package/build/constants.d.ts +9 -0
  53. package/build/constants.js +9 -0
  54. package/build/index.d.ts +2 -0
  55. package/build/index.js +2 -0
  56. package/build/package.json +274 -0
  57. package/build/packageDetect.d.ts +1 -0
  58. package/build/packageDetect.js +3 -0
  59. package/build/packageInfo.d.ts +6 -0
  60. package/build/packageInfo.js +1 -0
  61. package/build/qrcode.d.ts +3 -0
  62. package/build/qrcode.js +4 -0
  63. package/build/styled.d.ts +1 -0
  64. package/build/styled.js +1 -0
  65. package/build/util.d.ts +7 -0
  66. package/build/util.js +50 -0
  67. package/build-tsc/Display.d.ts +12 -0
  68. package/build-tsc/DisplayAddress.d.ts +12 -0
  69. package/build-tsc/DisplayPayload.d.ts +15 -0
  70. package/build-tsc/NetworkSpecs.d.ts +11 -0
  71. package/build-tsc/Scan.d.ts +12 -0
  72. package/build-tsc/ScanAddress.d.ts +19 -0
  73. package/build-tsc/ScanSignature.d.ts +15 -0
  74. package/build-tsc/bundle.d.ts +6 -0
  75. package/build-tsc/constants.d.ts +9 -0
  76. package/build-tsc/index.d.ts +2 -0
  77. package/build-tsc/packageDetect.d.ts +1 -0
  78. package/build-tsc/packageInfo.d.ts +6 -0
  79. package/build-tsc/qrcode.d.ts +3 -0
  80. package/build-tsc/styled.d.ts +1 -0
  81. package/build-tsc/util.d.ts +7 -0
  82. package/build-tsc-cjs/Display.js +95 -0
  83. package/build-tsc-cjs/DisplayAddress.js +16 -0
  84. package/build-tsc-cjs/DisplayPayload.js +16 -0
  85. package/build-tsc-cjs/NetworkSpecs.js +16 -0
  86. package/build-tsc-cjs/Scan.js +57 -0
  87. package/build-tsc-cjs/ScanAddress.js +45 -0
  88. package/build-tsc-cjs/ScanSignature.js +12 -0
  89. package/build-tsc-cjs/bundle.js +15 -0
  90. package/build-tsc-cjs/constants.js +12 -0
  91. package/build-tsc-cjs/index.js +5 -0
  92. package/build-tsc-cjs/packageDetect.js +5 -0
  93. package/build-tsc-cjs/packageInfo.js +4 -0
  94. package/build-tsc-cjs/qrcode.js +8 -0
  95. package/build-tsc-cjs/styled.js +5 -0
  96. package/build-tsc-cjs/util.js +59 -0
  97. package/build-tsc-esm/Display.js +91 -0
  98. package/build-tsc-esm/DisplayAddress.js +12 -0
  99. package/build-tsc-esm/DisplayPayload.js +12 -0
  100. package/build-tsc-esm/NetworkSpecs.js +12 -0
  101. package/build-tsc-esm/Scan.js +53 -0
  102. package/build-tsc-esm/ScanAddress.js +41 -0
  103. package/build-tsc-esm/ScanSignature.js +8 -0
  104. package/build-tsc-esm/bundle.js +6 -0
  105. package/build-tsc-esm/constants.js +9 -0
  106. package/build-tsc-esm/index.js +2 -0
  107. package/build-tsc-esm/packageDetect.js +3 -0
  108. package/build-tsc-esm/packageInfo.js +1 -0
  109. package/build-tsc-esm/qrcode.js +4 -0
  110. package/build-tsc-esm/styled.js +1 -0
  111. package/build-tsc-esm/util.js +50 -0
  112. package/package.json +40 -0
  113. package/src/Display.tsx +153 -0
  114. package/src/DisplayAddress.tsx +40 -0
  115. package/src/DisplayPayload.tsx +42 -0
  116. package/src/NetworkSpecs.tsx +39 -0
  117. package/src/Scan.tsx +100 -0
  118. package/src/ScanAddress.tsx +82 -0
  119. package/src/ScanSignature.tsx +39 -0
  120. package/src/bundle.ts +9 -0
  121. package/src/constants.ts +12 -0
  122. package/src/index.ts +6 -0
  123. package/src/packageDetect.ts +11 -0
  124. package/src/packageInfo.ts +6 -0
  125. package/src/qrcode.ts +15 -0
  126. package/src/styled.ts +4 -0
  127. package/src/util.spec.ts +100 -0
  128. package/src/util.ts +83 -0
  129. package/tsconfig.build.json +14 -0
  130. package/tsconfig.build.tsbuildinfo +1 -0
  131. package/tsconfig.spec.json +16 -0
  132. package/tsconfig.spec.tsbuildinfo +1 -0
@@ -0,0 +1,6 @@
1
+ export { QrDisplayAddress } from './DisplayAddress.js';
2
+ export { QrDisplayPayload } from './DisplayPayload.js';
3
+ export { QrNetworkSpecs } from './NetworkSpecs.js';
4
+ export { packageInfo } from './packageInfo.js';
5
+ export { QrScanAddress } from './ScanAddress.js';
6
+ export { QrScanSignature } from './ScanSignature.js';
@@ -0,0 +1,6 @@
1
+ export { QrDisplayAddress } from './DisplayAddress.js';
2
+ export { QrDisplayPayload } from './DisplayPayload.js';
3
+ export { QrNetworkSpecs } from './NetworkSpecs.js';
4
+ export { packageInfo } from './packageInfo.js';
5
+ export { QrScanAddress } from './ScanAddress.js';
6
+ export { QrScanSignature } from './ScanSignature.js';
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ interface Props {
3
+ className?: string | undefined;
4
+ size?: string | number | undefined;
5
+ skipEncoding?: boolean;
6
+ style?: React.CSSProperties | undefined;
7
+ timerDelay?: number | undefined;
8
+ value: Uint8Array;
9
+ }
10
+ declare function Display({ className, size, skipEncoding, style, timerDelay, value }: Props): React.ReactElement<Props> | null;
11
+ export declare const QrDisplay: React.MemoExoticComponent<typeof Display>;
12
+ export {};
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QrDisplay = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const jsx_runtime_1 = require("react/jsx-runtime");
6
+ const react_1 = tslib_1.__importStar(require("react"));
7
+ const util_1 = require("@pezkuwi/util");
8
+ const util_crypto_1 = require("@pezkuwi/util-crypto");
9
+ const qrcode_js_1 = require("./qrcode.js");
10
+ const styled_js_1 = require("./styled.js");
11
+ const util_js_1 = require("./util.js");
12
+ const DEFAULT_FRAME_DELAY = 2750;
13
+ const TIMER_INC = 500;
14
+ function getDataUrl(value) {
15
+ const qr = (0, qrcode_js_1.qrcode)(0, 'M');
16
+ // HACK See our qrcode stringToBytes override as used internally. This
17
+ // will only work for the case where we actually pass `Bytes` in here
18
+ qr.addData(value, 'Byte');
19
+ qr.make();
20
+ return qr.createDataURL(16, 0);
21
+ }
22
+ function Display({ className = '', size, skipEncoding, style = {}, timerDelay = DEFAULT_FRAME_DELAY, value }) {
23
+ const [{ image }, setFrameState] = (0, react_1.useState)({ frameIdx: 0, frames: [], image: null, valueHash: null });
24
+ const timerRef = (0, react_1.useRef)({ timerDelay, timerId: null });
25
+ const containerStyle = (0, react_1.useMemo)(() => (0, util_js_1.createImgSize)(size), [size]);
26
+ // run on initial load to setup the global timer and provide and unsubscribe
27
+ (0, react_1.useEffect)(() => {
28
+ const nextFrame = () => setFrameState((state) => {
29
+ // when we have a single frame, we only ever fire once
30
+ if (state.frames.length <= 1) {
31
+ return state;
32
+ }
33
+ let frameIdx = state.frameIdx + 1;
34
+ // when we overflow, skip to the first and slightly increase the delay between frames
35
+ if (frameIdx === state.frames.length) {
36
+ frameIdx = 0;
37
+ timerRef.current.timerDelay = timerRef.current.timerDelay + TIMER_INC;
38
+ }
39
+ // only encode the frames on demand, not above as part of the
40
+ // state derivation - in the case of large payloads, this should
41
+ // be slightly more responsive on initial load
42
+ const newState = (0, util_1.objectSpread)({}, state, {
43
+ frameIdx,
44
+ image: getDataUrl(state.frames[frameIdx])
45
+ });
46
+ // set the new timer last
47
+ timerRef.current.timerId = setTimeout(nextFrame, timerRef.current.timerDelay);
48
+ return newState;
49
+ });
50
+ timerRef.current.timerId = setTimeout(nextFrame, timerRef.current.timerDelay);
51
+ return () => {
52
+ // eslint-disable-next-line react-hooks/exhaustive-deps
53
+ timerRef.current.timerId && clearTimeout(timerRef.current.timerId);
54
+ };
55
+ // eslint-disable-next-line react-hooks/exhaustive-deps
56
+ }, []);
57
+ (0, react_1.useEffect)(() => {
58
+ setFrameState((state) => {
59
+ const valueHash = (0, util_crypto_1.xxhashAsHex)(value);
60
+ if (valueHash === state.valueHash) {
61
+ return state;
62
+ }
63
+ const frames = skipEncoding
64
+ ? [value]
65
+ : (0, util_js_1.createFrames)(value);
66
+ // encode on demand
67
+ return {
68
+ frameIdx: 0,
69
+ frames,
70
+ image: getDataUrl(frames[0]),
71
+ valueHash
72
+ };
73
+ });
74
+ }, [skipEncoding, value]);
75
+ if (!image) {
76
+ return null;
77
+ }
78
+ return ((0, jsx_runtime_1.jsx)(StyledDiv, { className: className, style: containerStyle, children: (0, jsx_runtime_1.jsx)("div", { className: 'ui--qr-Display', style: style, children: (0, jsx_runtime_1.jsx)("img", { src: image }) }) }));
79
+ }
80
+ const StyledDiv = styled_js_1.styled.div `
81
+ .ui--qr-Display {
82
+ height: 100%;
83
+ width: 100%;
84
+
85
+ img,
86
+ svg {
87
+ background: white;
88
+ height: auto !important;
89
+ max-height: 100%;
90
+ max-width: 100%;
91
+ width: auto !important;
92
+ }
93
+ }
94
+ `;
95
+ exports.QrDisplay = react_1.default.memo(Display);
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ interface Props {
3
+ address: string;
4
+ genesisHash: string;
5
+ className?: string;
6
+ size?: string | number;
7
+ style?: React.CSSProperties;
8
+ timerDelay?: number;
9
+ }
10
+ declare function DisplayAddress({ address, className, genesisHash, size, style, timerDelay }: Props): React.ReactElement<Props> | null;
11
+ export declare const QrDisplayAddress: React.MemoExoticComponent<typeof DisplayAddress>;
12
+ export {};
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QrDisplayAddress = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const jsx_runtime_1 = require("react/jsx-runtime");
6
+ const react_1 = tslib_1.__importStar(require("react"));
7
+ const Display_js_1 = require("./Display.js");
8
+ const util_js_1 = require("./util.js");
9
+ function DisplayAddress({ address, className, genesisHash, size, style, timerDelay }) {
10
+ const data = (0, react_1.useMemo)(() => (0, util_js_1.createAddressPayload)(address, genesisHash), [address, genesisHash]);
11
+ if (!data) {
12
+ return null;
13
+ }
14
+ return ((0, jsx_runtime_1.jsx)(Display_js_1.QrDisplay, { className: className, size: size, skipEncoding: true, style: style, timerDelay: timerDelay, value: data }));
15
+ }
16
+ exports.QrDisplayAddress = react_1.default.memo(DisplayAddress);
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ interface Props {
3
+ address: string;
4
+ className?: string;
5
+ cmd: number;
6
+ delay?: number;
7
+ genesisHash: Uint8Array | string;
8
+ payload: Uint8Array;
9
+ size?: string | number;
10
+ style?: React.CSSProperties;
11
+ timerDelay?: number;
12
+ }
13
+ declare function DisplayPayload({ address, className, cmd, genesisHash, payload, size, style, timerDelay }: Props): React.ReactElement<Props> | null;
14
+ export declare const QrDisplayPayload: React.MemoExoticComponent<typeof DisplayPayload>;
15
+ export {};
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QrDisplayPayload = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const jsx_runtime_1 = require("react/jsx-runtime");
6
+ const react_1 = tslib_1.__importStar(require("react"));
7
+ const Display_js_1 = require("./Display.js");
8
+ const util_js_1 = require("./util.js");
9
+ function DisplayPayload({ address, className, cmd, genesisHash, payload, size, style, timerDelay }) {
10
+ const data = (0, react_1.useMemo)(() => (0, util_js_1.createSignPayload)(address, cmd, payload, genesisHash), [address, cmd, payload, genesisHash]);
11
+ if (!data) {
12
+ return null;
13
+ }
14
+ return ((0, jsx_runtime_1.jsx)(Display_js_1.QrDisplay, { className: className, size: size, style: style, timerDelay: timerDelay, value: data }));
15
+ }
16
+ exports.QrDisplayPayload = react_1.default.memo(DisplayPayload);
@@ -0,0 +1,11 @@
1
+ import type { NetworkSpecsStruct } from '@pezkuwi/ui-settings/types';
2
+ import React from 'react';
3
+ interface Props {
4
+ className?: string;
5
+ networkSpecs: NetworkSpecsStruct;
6
+ size?: string | number;
7
+ style?: React.CSSProperties;
8
+ }
9
+ declare function DisplayNetworkSpecs({ className, networkSpecs, size, style }: Props): React.ReactElement<Props> | null;
10
+ export declare const QrNetworkSpecs: React.MemoExoticComponent<typeof DisplayNetworkSpecs>;
11
+ export {};
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QrNetworkSpecs = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const jsx_runtime_1 = require("react/jsx-runtime");
6
+ const react_1 = tslib_1.__importStar(require("react"));
7
+ const Display_js_1 = require("./Display.js");
8
+ const util_js_1 = require("./util.js");
9
+ function DisplayNetworkSpecs({ className, networkSpecs, size, style }) {
10
+ const data = (0, react_1.useMemo)(() => (0, util_js_1.encodeString)(JSON.stringify(networkSpecs)), [networkSpecs]);
11
+ if (!data) {
12
+ return null;
13
+ }
14
+ return ((0, jsx_runtime_1.jsx)(Display_js_1.QrDisplay, { className: className, size: size, skipEncoding: true, style: style, value: data }));
15
+ }
16
+ exports.QrNetworkSpecs = react_1.default.memo(DisplayNetworkSpecs);
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ interface Props {
3
+ className?: string | undefined;
4
+ delay?: number;
5
+ onError?: undefined | ((error: Error) => void);
6
+ onScan: (data: string) => void;
7
+ size?: string | number | undefined;
8
+ style?: React.CSSProperties | undefined;
9
+ }
10
+ declare function Scan({ className, delay, onError, onScan, size, style }: Props): React.ReactElement<Props>;
11
+ export declare const QrScan: React.MemoExoticComponent<typeof Scan>;
12
+ export {};
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QrScan = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const jsx_runtime_1 = require("react/jsx-runtime");
6
+ const browser_1 = require("@zxing/browser");
7
+ const react_1 = tslib_1.__importStar(require("react"));
8
+ const styled_js_1 = require("./styled.js");
9
+ const util_js_1 = require("./util.js");
10
+ const DEFAULT_DELAY = 150;
11
+ const DEFAULT_ERROR = (error) => {
12
+ console.error('@pezkuwi/react-qr:Scan', error.message);
13
+ };
14
+ function Scan({ className = '', delay = DEFAULT_DELAY, onError = DEFAULT_ERROR, onScan, size, style = {} }) {
15
+ const videoRef = (0, react_1.useRef)(null);
16
+ const controlsRef = (0, react_1.useRef)(null);
17
+ const containerStyle = (0, react_1.useMemo)(() => (0, util_js_1.createImgSize)(size), [size]);
18
+ const _onError = (0, react_1.useCallback)((error) => onError(error), [onError]);
19
+ (0, react_1.useEffect)(() => {
20
+ const codeReader = new browser_1.BrowserQRCodeReader();
21
+ const startScanning = async () => {
22
+ try {
23
+ const videoInputDevices = await browser_1.BrowserQRCodeReader.listVideoInputDevices();
24
+ const selectedDeviceId = videoInputDevices[0].deviceId;
25
+ controlsRef.current = await codeReader.decodeFromVideoDevice(selectedDeviceId, videoRef.current ?? undefined, (result, error) => {
26
+ if (result) {
27
+ onScan(result.getText());
28
+ }
29
+ if (error && !(error instanceof Error)) {
30
+ _onError(new Error(error));
31
+ }
32
+ });
33
+ }
34
+ catch (error) {
35
+ _onError(error instanceof Error ? error : new Error('Unknown error occurred'));
36
+ }
37
+ };
38
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
39
+ const timeoutId = setTimeout(startScanning, delay);
40
+ return () => {
41
+ clearTimeout(timeoutId);
42
+ if (controlsRef.current) {
43
+ controlsRef.current.stop();
44
+ }
45
+ };
46
+ }, [onScan, _onError, delay]);
47
+ return ((0, jsx_runtime_1.jsx)(StyledDiv, { className: className, style: containerStyle, children: (0, jsx_runtime_1.jsx)("video", { className: 'ui--qr-Scan', ref: videoRef, style: style }) }));
48
+ }
49
+ const StyledDiv = styled_js_1.styled.div `
50
+ .ui--qr-Scan {
51
+ display: inline-block;
52
+ height: 100%;
53
+ transform: matrix(-1, 0, 0, 1, 0, 0);
54
+ width: 100%;
55
+ }
56
+ `;
57
+ exports.QrScan = react_1.default.memo(Scan);
@@ -0,0 +1,19 @@
1
+ import type { HexString } from '@pezkuwi/util/types';
2
+ import React from 'react';
3
+ interface ScanType {
4
+ isAddress: boolean;
5
+ content: string;
6
+ genesisHash: HexString | null;
7
+ name?: string | undefined;
8
+ }
9
+ interface Props {
10
+ className?: string;
11
+ onError?: (error: Error) => void;
12
+ onScan: (scanned: ScanType) => void;
13
+ size?: string | number;
14
+ style?: React.CSSProperties;
15
+ isEthereum?: boolean;
16
+ }
17
+ declare function ScanAddress({ className, isEthereum, onError, onScan, size, style }: Props): React.ReactElement<Props>;
18
+ export declare const QrScanAddress: React.MemoExoticComponent<typeof ScanAddress>;
19
+ export {};
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QrScanAddress = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const jsx_runtime_1 = require("react/jsx-runtime");
6
+ const react_1 = tslib_1.__importStar(require("react"));
7
+ const util_crypto_1 = require("@pezkuwi/util-crypto");
8
+ const constants_js_1 = require("./constants.js");
9
+ const Scan_js_1 = require("./Scan.js");
10
+ function ScanAddress({ className, isEthereum, onError, onScan, size, style }) {
11
+ const _onScan = (0, react_1.useCallback)((data) => {
12
+ if (data) {
13
+ try {
14
+ let prefix;
15
+ let content;
16
+ let genesisHash;
17
+ let name;
18
+ if (!isEthereum) {
19
+ [prefix, content, genesisHash, ...name] = data.split(':');
20
+ }
21
+ else {
22
+ [prefix, content, ...name] = data.split(':');
23
+ genesisHash = null;
24
+ content = content.substring(0, 42);
25
+ }
26
+ const expectedPrefix = (isEthereum ? 'ethereum' : constants_js_1.ADDRESS_PREFIX);
27
+ const isValidPrefix = (prefix === expectedPrefix) || (prefix === constants_js_1.SEED_PREFIX);
28
+ if (!isValidPrefix) {
29
+ throw new Error(`Invalid prefix received, expected '${expectedPrefix} or ${constants_js_1.SEED_PREFIX}' , found '${prefix}'`);
30
+ }
31
+ const isAddress = prefix === expectedPrefix;
32
+ if (isAddress && !isEthereum) {
33
+ (0, util_crypto_1.decodeAddress)(content);
34
+ }
35
+ onScan({ content, genesisHash: genesisHash, isAddress, name: name?.length ? name.join(':') : undefined });
36
+ }
37
+ catch (error) {
38
+ onError && onError(error);
39
+ console.error('@pezkuwi/react-qr:QrScanAddress', error.message, data);
40
+ }
41
+ }
42
+ }, [onScan, onError, isEthereum]);
43
+ return ((0, jsx_runtime_1.jsx)(Scan_js_1.QrScan, { className: className, onError: onError, onScan: _onScan, size: size, style: style }));
44
+ }
45
+ exports.QrScanAddress = react_1.default.memo(ScanAddress);
@@ -0,0 +1,15 @@
1
+ import type { HexString } from '@pezkuwi/util/types';
2
+ import React from 'react';
3
+ interface ScanType {
4
+ signature: HexString;
5
+ }
6
+ interface Props {
7
+ className?: string;
8
+ onError?: (error: Error) => void;
9
+ onScan: (scanned: ScanType) => void;
10
+ size?: string | number;
11
+ style?: React.CSSProperties;
12
+ }
13
+ declare function ScanSignature({ className, onError, onScan, size, style }: Props): React.ReactElement<Props>;
14
+ export declare const QrScanSignature: React.MemoExoticComponent<typeof ScanSignature>;
15
+ export {};
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QrScanSignature = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const jsx_runtime_1 = require("react/jsx-runtime");
6
+ const react_1 = tslib_1.__importStar(require("react"));
7
+ const Scan_js_1 = require("./Scan.js");
8
+ function ScanSignature({ className, onError, onScan, size, style }) {
9
+ const _onScan = (0, react_1.useCallback)((signature) => signature && onScan({ signature: `0x${signature}` }), [onScan]);
10
+ return ((0, jsx_runtime_1.jsx)(Scan_js_1.QrScan, { className: className, onError: onError, onScan: _onScan, size: size, style: style }));
11
+ }
12
+ exports.QrScanSignature = react_1.default.memo(ScanSignature);
@@ -0,0 +1,6 @@
1
+ export { QrDisplayAddress } from './DisplayAddress.js';
2
+ export { QrDisplayPayload } from './DisplayPayload.js';
3
+ export { QrNetworkSpecs } from './NetworkSpecs.js';
4
+ export { packageInfo } from './packageInfo.js';
5
+ export { QrScanAddress } from './ScanAddress.js';
6
+ export { QrScanSignature } from './ScanSignature.js';
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QrScanSignature = exports.QrScanAddress = exports.packageInfo = exports.QrNetworkSpecs = exports.QrDisplayPayload = exports.QrDisplayAddress = void 0;
4
+ var DisplayAddress_js_1 = require("./DisplayAddress.js");
5
+ Object.defineProperty(exports, "QrDisplayAddress", { enumerable: true, get: function () { return DisplayAddress_js_1.QrDisplayAddress; } });
6
+ var DisplayPayload_js_1 = require("./DisplayPayload.js");
7
+ Object.defineProperty(exports, "QrDisplayPayload", { enumerable: true, get: function () { return DisplayPayload_js_1.QrDisplayPayload; } });
8
+ var NetworkSpecs_js_1 = require("./NetworkSpecs.js");
9
+ Object.defineProperty(exports, "QrNetworkSpecs", { enumerable: true, get: function () { return NetworkSpecs_js_1.QrNetworkSpecs; } });
10
+ var packageInfo_js_1 = require("./packageInfo.js");
11
+ Object.defineProperty(exports, "packageInfo", { enumerable: true, get: function () { return packageInfo_js_1.packageInfo; } });
12
+ var ScanAddress_js_1 = require("./ScanAddress.js");
13
+ Object.defineProperty(exports, "QrScanAddress", { enumerable: true, get: function () { return ScanAddress_js_1.QrScanAddress; } });
14
+ var ScanSignature_js_1 = require("./ScanSignature.js");
15
+ Object.defineProperty(exports, "QrScanSignature", { enumerable: true, get: function () { return ScanSignature_js_1.QrScanSignature; } });
@@ -0,0 +1,9 @@
1
+ export declare const ADDRESS_PREFIX = "substrate";
2
+ export declare const SEED_PREFIX = "secret";
3
+ export declare const FRAME_SIZE = 1024;
4
+ export declare const SUBSTRATE_ID: Uint8Array;
5
+ export declare const CRYPTO_SR25519: Uint8Array;
6
+ export declare const CMD_SIGN_TX: Uint8Array;
7
+ export declare const CMD_SIGN_TX_HASH: Uint8Array;
8
+ export declare const CMD_SIGN_IMMORTAL_TX: Uint8Array;
9
+ export declare const CMD_SIGN_MSG: Uint8Array;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CMD_SIGN_MSG = exports.CMD_SIGN_IMMORTAL_TX = exports.CMD_SIGN_TX_HASH = exports.CMD_SIGN_TX = exports.CRYPTO_SR25519 = exports.SUBSTRATE_ID = exports.FRAME_SIZE = exports.SEED_PREFIX = exports.ADDRESS_PREFIX = void 0;
4
+ exports.ADDRESS_PREFIX = 'substrate';
5
+ exports.SEED_PREFIX = 'secret';
6
+ exports.FRAME_SIZE = 1024;
7
+ exports.SUBSTRATE_ID = new Uint8Array([0x53]);
8
+ exports.CRYPTO_SR25519 = new Uint8Array([0x01]);
9
+ exports.CMD_SIGN_TX = new Uint8Array([0]);
10
+ exports.CMD_SIGN_TX_HASH = new Uint8Array([1]);
11
+ exports.CMD_SIGN_IMMORTAL_TX = new Uint8Array([2]);
12
+ exports.CMD_SIGN_MSG = new Uint8Array([3]);
@@ -0,0 +1,2 @@
1
+ import './packageDetect.js';
2
+ export * from './bundle.js';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ require("./packageDetect.js");
5
+ tslib_1.__exportStar(require("./bundle.js"), exports);
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const util_1 = require("@pezkuwi/util");
4
+ const packageInfo_js_1 = require("./packageInfo.js");
5
+ (0, util_1.detectPackage)(packageInfo_js_1.packageInfo, null, []);
@@ -0,0 +1,6 @@
1
+ export declare const packageInfo: {
2
+ name: string;
3
+ path: string;
4
+ type: string;
5
+ version: string;
6
+ };
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.packageInfo = void 0;
4
+ exports.packageInfo = { name: '@pezkuwi/react-qr', path: typeof __dirname === 'string' ? __dirname : 'auto', type: 'cjs', version: '3.16.6' };
@@ -0,0 +1,3 @@
1
+ import _qrcode from 'qrcode-generator';
2
+ declare const qrcode: typeof _qrcode;
3
+ export { qrcode };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.qrcode = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const qrcode_generator_1 = tslib_1.__importDefault(require("qrcode-generator"));
6
+ const qrcode = qrcode_generator_1.default;
7
+ exports.qrcode = qrcode;
8
+ qrcode.stringToBytes = (data) => data;
@@ -0,0 +1 @@
1
+ export { styled } from 'styled-components';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.styled = void 0;
4
+ var styled_components_1 = require("styled-components");
5
+ Object.defineProperty(exports, "styled", { enumerable: true, get: function () { return styled_components_1.styled; } });
@@ -0,0 +1,7 @@
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>;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.encodeNumber = encodeNumber;
4
+ exports.encodeString = encodeString;
5
+ exports.decodeString = decodeString;
6
+ exports.createAddressPayload = createAddressPayload;
7
+ exports.createSignPayload = createSignPayload;
8
+ exports.createFrames = createFrames;
9
+ exports.createImgSize = createImgSize;
10
+ const util_1 = require("@pezkuwi/util");
11
+ const util_crypto_1 = require("@pezkuwi/util-crypto");
12
+ const constants_js_1 = require("./constants.js");
13
+ const MULTIPART = new Uint8Array([0]);
14
+ function encodeNumber(value) {
15
+ return new Uint8Array([value >> 8, value & 0xff]);
16
+ }
17
+ function encodeString(value) {
18
+ const count = value.length;
19
+ const u8a = new Uint8Array(count);
20
+ for (let i = 0; i < count; i++) {
21
+ u8a[i] = value.charCodeAt(i);
22
+ }
23
+ return u8a;
24
+ }
25
+ function decodeString(value) {
26
+ return value.reduce((str, code) => {
27
+ return str + String.fromCharCode(code);
28
+ }, '');
29
+ }
30
+ function createAddressPayload(address, genesisHash) {
31
+ return encodeString(`${constants_js_1.ADDRESS_PREFIX}:${address}:${genesisHash}`);
32
+ }
33
+ function createSignPayload(address, cmd, payload, genesisHash) {
34
+ return (0, util_1.u8aConcat)(constants_js_1.SUBSTRATE_ID, constants_js_1.CRYPTO_SR25519, new Uint8Array([cmd]), (0, util_crypto_1.decodeAddress)(address), (0, util_1.u8aToU8a)(payload), (0, util_1.u8aToU8a)(genesisHash));
35
+ }
36
+ function createFrames(input) {
37
+ const frames = [];
38
+ let idx = 0;
39
+ while (idx < input.length) {
40
+ frames.push(input.subarray(idx, idx + constants_js_1.FRAME_SIZE));
41
+ idx += constants_js_1.FRAME_SIZE;
42
+ }
43
+ return frames.map((frame, index) => (0, util_1.u8aConcat)(MULTIPART, encodeNumber(frames.length), encodeNumber(index), frame));
44
+ }
45
+ function createImgSize(size) {
46
+ if (!size) {
47
+ return {
48
+ height: 'auto',
49
+ width: '100%'
50
+ };
51
+ }
52
+ const height = (0, util_1.isString)(size)
53
+ ? size
54
+ : `${size}px`;
55
+ return {
56
+ height,
57
+ width: height
58
+ };
59
+ }
@@ -0,0 +1,9 @@
1
+ export declare const ADDRESS_PREFIX = "substrate";
2
+ export declare const SEED_PREFIX = "secret";
3
+ export declare const FRAME_SIZE = 1024;
4
+ export declare const SUBSTRATE_ID: Uint8Array;
5
+ export declare const CRYPTO_SR25519: Uint8Array;
6
+ export declare const CMD_SIGN_TX: Uint8Array;
7
+ export declare const CMD_SIGN_TX_HASH: Uint8Array;
8
+ export declare const CMD_SIGN_IMMORTAL_TX: Uint8Array;
9
+ export declare const CMD_SIGN_MSG: Uint8Array;
@@ -0,0 +1,9 @@
1
+ export const ADDRESS_PREFIX = 'substrate';
2
+ export const SEED_PREFIX = 'secret';
3
+ export const FRAME_SIZE = 1024;
4
+ export const SUBSTRATE_ID = new Uint8Array([0x53]);
5
+ export const CRYPTO_SR25519 = new Uint8Array([0x01]);
6
+ export const CMD_SIGN_TX = new Uint8Array([0]);
7
+ export const CMD_SIGN_TX_HASH = new Uint8Array([1]);
8
+ export const CMD_SIGN_IMMORTAL_TX = new Uint8Array([2]);
9
+ export const CMD_SIGN_MSG = new Uint8Array([3]);
@@ -0,0 +1,2 @@
1
+ import './packageDetect.js';
2
+ export * from './bundle.js';
package/build/index.js ADDED
@@ -0,0 +1,2 @@
1
+ import './packageDetect.js';
2
+ export * from './bundle.js';