* Pull in first bits from old branch
* Extract styles
* Update for eslint
* Bump deps, react-qr-reader
* remove wrapped component, only QR{Display, Scan}
* Multipart display
* Track updates via xxhash
* Address display & scanning
* Bump deps
* DisplayExtrinsic -> DisplayPayload
* Rewrite yarn.lock
* Bumps
* Add direct string <-> u8a conversion utils
* Use encodeString everywhere
* Update deps
* Bump deps (final round, can merge now)
24 lines
671 B
TypeScript
24 lines
671 B
TypeScript
// Copyright 2017-2019 @polkadot/ui-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.
|
|
|
|
export function encodeNumber (value: number): Uint8Array {
|
|
return new Uint8Array([value >> 8, value & 256]);
|
|
}
|
|
|
|
export function encodeString (value: string): Uint8Array {
|
|
const u8a = new Uint8Array(value.length);
|
|
|
|
for (let i = 0; i < value.length; i++) {
|
|
u8a[i] = value.charCodeAt(i);
|
|
}
|
|
|
|
return u8a;
|
|
}
|
|
|
|
export function decodeString (value: Uint8Array): string {
|
|
return value.reduce((str, code): string => {
|
|
return str + String.fromCharCode(code);
|
|
}, '');
|
|
}
|