33 lines
1.3 KiB
JavaScript
33 lines
1.3 KiB
JavaScript
import { parseQueryString } from "./url";
|
|
export function isWalletConnectSession(object) {
|
|
return typeof object.bridge !== "undefined";
|
|
}
|
|
export function parseWalletConnectUri(str) {
|
|
const pathStart = str.indexOf(":");
|
|
const pathEnd = str.indexOf("?") !== -1 ? str.indexOf("?") : undefined;
|
|
const protocol = str.substring(0, pathStart);
|
|
const path = str.substring(pathStart + 1, pathEnd);
|
|
function parseRequiredParams(path) {
|
|
const separator = "@";
|
|
const values = path.split(separator);
|
|
const requiredParams = {
|
|
handshakeTopic: values[0],
|
|
version: parseInt(values[1], 10),
|
|
};
|
|
return requiredParams;
|
|
}
|
|
const requiredParams = parseRequiredParams(path);
|
|
const queryString = typeof pathEnd !== "undefined" ? str.substr(pathEnd) : "";
|
|
function parseQueryParams(queryString) {
|
|
const result = parseQueryString(queryString);
|
|
const parameters = {
|
|
key: result.key || "",
|
|
bridge: result.bridge || "",
|
|
};
|
|
return parameters;
|
|
}
|
|
const queryParams = parseQueryParams(queryString);
|
|
const result = Object.assign(Object.assign({ protocol }, requiredParams), queryParams);
|
|
return result;
|
|
}
|
|
//# sourceMappingURL=session.js.map
|