@polkadot/react-qr
Advanced tools
Comparing version 0.43.0-beta.5 to 0.43.0-beta.6
@@ -1,3 +0,2 @@ | ||
declare const DEFAULT_IMG_SIZE = 300; | ||
declare const ADDRESS_PREFIX = "substrate:"; | ||
declare const ADDRESS_PREFIX = "substrate"; | ||
declare const FRAME_SIZE = 2048; | ||
@@ -10,2 +9,2 @@ declare const SUBSTRATE_ID: Uint8Array; | ||
declare const CMD_SIGN_MSG: Uint8Array; | ||
export { ADDRESS_PREFIX, CMD_SIGN_TX, CMD_SIGN_TX_HASH, CMD_SIGN_IMMORTAL_TX, CMD_SIGN_MSG, CRYPTO_SR25519, DEFAULT_IMG_SIZE, FRAME_SIZE, SUBSTRATE_ID }; | ||
export { ADDRESS_PREFIX, CMD_SIGN_TX, CMD_SIGN_TX_HASH, CMD_SIGN_IMMORTAL_TX, CMD_SIGN_MSG, CRYPTO_SR25519, FRAME_SIZE, SUBSTRATE_ID }; |
@@ -6,9 +6,7 @@ "use strict"; | ||
}); | ||
exports.SUBSTRATE_ID = exports.FRAME_SIZE = exports.DEFAULT_IMG_SIZE = exports.CRYPTO_SR25519 = exports.CMD_SIGN_MSG = exports.CMD_SIGN_IMMORTAL_TX = exports.CMD_SIGN_TX_HASH = exports.CMD_SIGN_TX = exports.ADDRESS_PREFIX = void 0; | ||
exports.SUBSTRATE_ID = exports.FRAME_SIZE = exports.CRYPTO_SR25519 = exports.CMD_SIGN_MSG = exports.CMD_SIGN_IMMORTAL_TX = exports.CMD_SIGN_TX_HASH = exports.CMD_SIGN_TX = exports.ADDRESS_PREFIX = void 0; | ||
// Copyright 2017-2019 @polkadot/react-qr authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the Apache-2.0 license. See the LICENSE file for details. | ||
const DEFAULT_IMG_SIZE = 300; | ||
exports.DEFAULT_IMG_SIZE = DEFAULT_IMG_SIZE; | ||
const ADDRESS_PREFIX = 'substrate:'; | ||
const ADDRESS_PREFIX = 'substrate'; | ||
exports.ADDRESS_PREFIX = ADDRESS_PREFIX; | ||
@@ -15,0 +13,0 @@ const FRAME_SIZE = 2048; |
import { BaseProps } from './types'; | ||
import React from 'react'; | ||
interface Props extends BaseProps { | ||
size?: number; | ||
skipEncoding?: boolean; | ||
@@ -6,0 +5,0 @@ value: Uint8Array; |
@@ -5,2 +5,3 @@ import { BaseProps } from './types'; | ||
address: string; | ||
genesisHash: string; | ||
} | ||
@@ -13,5 +14,5 @@ interface State { | ||
state: State; | ||
static getDerivedStateFromProps({ address }: Props, prevState: State): State | null; | ||
static getDerivedStateFromProps({ address, genesisHash }: Props, prevState: State): State | null; | ||
render(): React.ReactNode; | ||
} | ||
export {}; |
@@ -32,5 +32,6 @@ "use strict"; | ||
let { | ||
address | ||
address, | ||
genesisHash | ||
} = _ref; | ||
const data = (0, _util.createAddressPayload)(address); | ||
const data = (0, _util.createAddressPayload)(address, genesisHash); | ||
const dataHash = (0, _utilCrypto.xxhashAsHex)(data); | ||
@@ -51,2 +52,3 @@ | ||
className, | ||
size, | ||
style | ||
@@ -65,2 +67,3 @@ } = this.props; | ||
skipEncoding: true, | ||
size: size, | ||
style: style, | ||
@@ -67,0 +70,0 @@ value: data |
@@ -52,2 +52,3 @@ "use strict"; | ||
className, | ||
size, | ||
style | ||
@@ -65,2 +66,3 @@ } = this.props; | ||
className: className, | ||
size: size, | ||
style: style, | ||
@@ -67,0 +69,0 @@ value: data |
{ | ||
"name": "@polkadot/react-qr", | ||
"version": "0.43.0-beta.5", | ||
"version": "0.43.0-beta.6", | ||
"description": "Generates and reads QR codes", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1,2 +0,3 @@ | ||
import qrcode from 'qrcode-generator'; | ||
import _qrcode from 'qrcode-generator'; | ||
declare const qrcode: typeof _qrcode; | ||
export default qrcode; |
@@ -15,8 +15,10 @@ "use strict"; | ||
// of the Apache-2.0 license. See the LICENSE file for details. | ||
// HACK The default function take string -> number[], the Uint8array is compatible | ||
// A small hurdle to jump through, just to get the default/default correct (as generated) | ||
const qrcode = _qrcodeGenerator.default; // HACK The default function take string -> number[], the Uint8array is compatible | ||
// with that signature and the use thereof | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
_qrcodeGenerator.default.stringToBytes = data => data; | ||
var _default = _qrcodeGenerator.default; | ||
qrcode.stringToBytes = data => data; | ||
var _default = qrcode; | ||
exports.default = _default; |
@@ -7,3 +7,2 @@ import { BaseProps } from './types'; | ||
onScan?: (data: string) => void; | ||
size?: number; | ||
} | ||
@@ -10,0 +9,0 @@ declare class Scan extends React.PureComponent<Props> { |
@@ -5,3 +5,3 @@ import { BaseProps } from './types'; | ||
onError?: (error: Error) => void; | ||
onScan?: (data: string) => void; | ||
onScan?: (aqddress: string, genesisHash: string) => void; | ||
} | ||
@@ -8,0 +8,0 @@ export default class ScanAddress extends React.PureComponent<Props> { |
@@ -12,2 +12,4 @@ "use strict"; | ||
var _util = require("@polkadot/util"); | ||
var _constants = require("./constants"); | ||
@@ -31,13 +33,13 @@ | ||
if (!data || !onScan || !data.startsWith(_constants.ADDRESS_PREFIX)) { | ||
if (!data || !onScan) { | ||
return; | ||
} | ||
const address = data.substr(_constants.ADDRESS_PREFIX.length); | ||
try { | ||
const [prefix, address, genesisHash] = data.split(':'); | ||
(0, _util.assert)(prefix === _constants.ADDRESS_PREFIX, "Invalid address received, expected '".concat(_constants.ADDRESS_PREFIX, "', found '").concat(prefix, "'")); | ||
(0, _utilCrypto.decodeAddress)(address); | ||
onScan(address); | ||
onScan(address, genesisHash); | ||
} catch (error) { | ||
console.error('@polkadot/react-qr:QrScanAddress', error.message); | ||
console.error('@polkadot/react-qr:QrScanAddress', error.message, data); | ||
} | ||
@@ -51,2 +53,3 @@ }; | ||
onError, | ||
size, | ||
style | ||
@@ -58,2 +61,3 @@ } = this.props; | ||
onScan: this.onScan, | ||
size: size, | ||
style: style | ||
@@ -60,0 +64,0 @@ }); |
@@ -40,2 +40,3 @@ "use strict"; | ||
onError, | ||
size, | ||
style | ||
@@ -47,2 +48,3 @@ } = this.props; | ||
onScan: this.onScan, | ||
size: size, | ||
style: style | ||
@@ -49,0 +51,0 @@ }); |
export interface BaseProps { | ||
className?: string; | ||
size?: string | number; | ||
style?: Record<string, string | number>; | ||
} |
export declare function encodeNumber(value: number): Uint8Array; | ||
export declare function encodeString(value: string): Uint8Array; | ||
export declare function decodeString(value: Uint8Array): string; | ||
export declare function createAddressPayload(address: string): Uint8Array; | ||
export declare function createAddressPayload(address: string, genesisHash: string): Uint8Array; | ||
export declare function createSignPayload(address: string, cmd: number, payload: string | Uint8Array): Uint8Array; | ||
export declare function createFrames(input: Uint8Array): Uint8Array[]; | ||
export declare function createImgSize(size?: number): Record<string, string>; | ||
export declare function createImgSize(size?: string | number): Record<string, string>; |
16
util.js
@@ -45,4 +45,4 @@ "use strict"; | ||
function createAddressPayload(address) { | ||
return (0, _util.u8aConcat)(encodeString(_constants.ADDRESS_PREFIX), encodeString(address)); | ||
function createAddressPayload(address, genesisHash) { | ||
return encodeString("".concat(_constants.ADDRESS_PREFIX, ":").concat(address, ":").concat(genesisHash)); | ||
} | ||
@@ -66,5 +66,11 @@ | ||
function createImgSize() { | ||
let size = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _constants.DEFAULT_IMG_SIZE; | ||
const height = "".concat(size, "px"); | ||
function createImgSize(size) { | ||
if (!size) { | ||
return { | ||
height: 'auto', | ||
width: '100%' | ||
}; | ||
} | ||
const height = (0, _util.isString)(size) ? size : "".concat(size, "px"); | ||
return { | ||
@@ -71,0 +77,0 @@ height, |
@@ -43,3 +43,3 @@ "use strict"; | ||
it('encodes an address properly', () => { | ||
expect((0, _util.u8aToString)((0, _util2.createAddressPayload)('5GKhfyctwmW5LQdGaHTyU9qq2yDtggdJo719bj5ZUxnVGtmX'))).toEqual('substrate:5GKhfyctwmW5LQdGaHTyU9qq2yDtggdJo719bj5ZUxnVGtmX'); | ||
expect((0, _util.u8aToString)((0, _util2.createAddressPayload)('5HbgaJEuVN5qGbkhgtuDQANivSWwHXWsC2erP1SQUXgciTVq', '0x'))).toEqual('substrate:' + '5HbgaJEuVN5qGbkhgtuDQANivSWwHXWsC2erP1SQUXgciTVq:' + '0x'); | ||
}); | ||
@@ -46,0 +46,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33864
669