UNPKG

@hazae41/base58

Version:

Base58 adapter for WebAssembly and JS implementations

37 lines (33 loc) 1.17 kB
'use strict'; var tslib_es6 = require('../../../node_modules/tslib/tslib.es6.cjs'); var box = require('@hazae41/box'); function fromWasm(wasm) { const { Memory, base58_encode, base58_decode } = wasm; function getMemory(bytesOrCopiable) { if (bytesOrCopiable instanceof Memory) return new box.Ref(bytesOrCopiable); if (bytesOrCopiable instanceof Uint8Array) return box.Pin.from(new Memory(bytesOrCopiable)); return box.Pin.from(new Memory(bytesOrCopiable.bytes)); } function encodeOrThrow(bytes) { const env_1 = { stack: [], error: void 0, hasError: false }; try { const memory = tslib_es6.__addDisposableResource(env_1, getMemory(bytes), false); return base58_encode(memory.value); } catch (e_1) { env_1.error = e_1; env_1.hasError = true; } finally { tslib_es6.__disposeResources(env_1); } } function decodeOrThrow(text) { return base58_decode(text); } return { encodeOrThrow, decodeOrThrow }; } exports.fromWasm = fromWasm; //# sourceMappingURL=wasm.cjs.map