38 lines
1.5 KiB
JavaScript
38 lines
1.5 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.parseWalletConnectUri = exports.isWalletConnectSession = void 0;
|
|
const url_1 = require("./url");
|
|
function isWalletConnectSession(object) {
|
|
return typeof object.bridge !== "undefined";
|
|
}
|
|
exports.isWalletConnectSession = isWalletConnectSession;
|
|
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 = (0, url_1.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;
|
|
}
|
|
exports.parseWalletConnectUri = parseWalletConnectUri;
|
|
//# sourceMappingURL=session.js.map
|