ghost-portal/packages/ui-qr/src/util.ts
Jaco Greeff e13d79e10a
Parity Signer QR support (#592)
* 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)
2019-07-19 13:47:52 +02:00

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);
}, '');
}