UNPKG

@web3auth/ws-embed

Version:

Embed script

29 lines (25 loc) 885 B
'use strict'; var base = require('@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 base.base58.decode(value).length === SOLANA_PUBLIC_KEY_LENGTH; } catch { return false; } }; exports.htmlToElement = htmlToElement; exports.isEvmAddress = isEvmAddress; exports.isSolanaAddress = isSolanaAddress;