* Split into common wasm-bridge package * README * Adjust rollup bundling * Adjust * Adjust * Adjust, full re-usable * Cleanup deps * Restore initWasm exports from init* * Split base64 & fflate into wasm-util * sideEffects for wasm-util * Dedupe types * Additional * Adjust * Expose error on InitResult * Bump deps * CHANGELOG * Re-usable rollup config
23 lines
615 B
TypeScript
23 lines
615 B
TypeScript
// Copyright 2019-2022 @polkadot/wasm-util authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
|
|
export function base64Decode (data: string): Uint8Array {
|
|
const bytes = [];
|
|
let byte = 0;
|
|
let bits = 0;
|
|
|
|
for (let i = 0; i < data.length && data[i] !== '='; i++) {
|
|
// each character represents 6 bits
|
|
byte = (byte << 6) | chars.indexOf(data[i]);
|
|
|
|
// each byte needs to contain 8 bits
|
|
if ((bits += 6) >= 8) {
|
|
bytes.push((byte >>> (bits -= 8)) & 0xff);
|
|
}
|
|
}
|
|
|
|
return Uint8Array.from(bytes);
|
|
}
|