@web3auth/ws-embed
Version:
Embed script
25 lines (22 loc) • 806 B
JavaScript
import { base58 } from '@scure/base';
const EVM_ADDRESS_REGEX = /^0x[a-fA-F0-9]{40}$/;
const SOLANA_PUBLIC_KEY_LENGTH = 32;
const htmlToElement = html => {
const template = window.document.createElement("template");
const trimmedHtml = html.trim(); // Never return a text node of whitespace as the result
template.innerHTML = trimmedHtml;
return template.content.firstChild;
};
const isEvmAddress = value => {
return typeof value === "string" && EVM_ADDRESS_REGEX.test(value);
};
const isSolanaAddress = value => {
if (typeof value !== "string") return false;
try {
// Solana public keys are base58-encoded 32-byte values.
return base58.decode(value).length === SOLANA_PUBLIC_KEY_LENGTH;
} catch {
return false;
}
};
export { htmlToElement, isEvmAddress, isSolanaAddress };