script-path address creation will show control block to users now

This commit is contained in:
sairaj mote 2023-11-08 16:54:43 +05:30
parent d663512ab5
commit bbb0242166
4 changed files with 80 additions and 13 deletions

View File

@ -233,7 +233,7 @@ details[open] > summary .down-arrow {
transform: rotate(180deg); transform: rotate(180deg);
} }
fieldset { sm-form fieldset {
border: none; border: none;
} }
@ -1298,6 +1298,27 @@ body.loaded .nav-item__indicator {
background-color: var(--accent-color); background-color: var(--accent-color);
} }
#generate_script_path_address_popup fieldset {
padding: 1rem;
border-radius: 0.5rem;
border: solid thin rgba(var(--text-color), 0.3);
}
#generate_script_path_address_popup fieldset legend {
font-size: 0.9rem;
font-weight: 500;
padding: 0 0.5rem;
margin-left: -0.5rem;
}
#generate_script_path_address_popup .taproot-member sm-copy {
font-weight: 500;
font-size: 0.9rem;
}
#generate_script_path_address_popup .taproot-member:not(:last-of-type) {
padding-bottom: 1rem;
margin-bottom: 0.5rem;
border-bottom: solid thin rgba(var(--text-color), 0.3);
}
@media only screen and (max-width: 640px) { @media only screen and (max-width: 640px) {
.hide-on-small { .hide-on-small {
display: none; display: none;

2
css/main.min.css vendored

File diff suppressed because one or more lines are too long

View File

@ -212,8 +212,10 @@ details[open] {
transform: rotate(180deg); transform: rotate(180deg);
} }
} }
fieldset { sm-form {
border: none; fieldset {
border: none;
}
} }
sm-input { sm-input {
--border-radius: 0.5rem; --border-radius: 0.5rem;
@ -1203,6 +1205,30 @@ body.loaded .nav-item {
} }
} }
} }
#generate_script_path_address_popup {
fieldset {
padding: 1rem;
border-radius: 0.5rem;
border: solid thin rgba(var(--text-color), 0.3);
legend {
font-size: 0.9rem;
font-weight: 500;
padding: 0 0.5rem;
margin-left: -0.5rem;
}
}
.taproot-member {
sm-copy {
font-weight: 500;
font-size: 0.9rem;
}
&:not(:last-of-type) {
padding-bottom: 1rem;
margin-bottom: 0.5rem;
border-bottom: solid thin rgba(var(--text-color), 0.3);
}
}
}
@media only screen and (max-width: 640px) { @media only screen and (max-width: 640px) {
.hide-on-small { .hide-on-small {
display: none; display: none;

View File

@ -149,7 +149,7 @@
</button> </button>
</div> </div>
</header> </header>
<div id="generate_script_path_address_popup__content"></div> <div id="generate_script_path_address_popup__content" class="grid gap-2"></div>
</sm-popup> </sm-popup>
<sm-popup id="convert_to_taproot_popup"> <sm-popup id="convert_to_taproot_popup">
<header slot="header" class="popup__header"> <header slot="header" class="popup__header">
@ -296,7 +296,6 @@
case 'generate_script_path_address_popup': { case 'generate_script_path_address_popup': {
const { wif, tr: { address } } = getTaprootAddress() const { wif, tr: { address } } = getTaprootAddress()
const privateKey = coinjs.wif2privkey(wif).privkey const privateKey = coinjs.wif2privkey(wif).privkey
console.log(wif, address)
const scriptInputs = [1]; const scriptInputs = [1];
const renderScriptInput = (index) => html` const renderScriptInput = (index) => html`
<div class="flex gap-0-5"> <div class="flex gap-0-5">
@ -318,23 +317,44 @@
} }
function generateScriptPathAddress() { function generateScriptPathAddress() {
const schnorrPublicKey = secp256k1_schnorr.getPublicKey(hex.decode(privateKey)); const schnorrPublicKey = secp256k1_schnorr.getPublicKey(hex.decode(privateKey));
const taprootTree = [...document.querySelectorAll('.member-script-input')].map(input => { let memberScripts = [...document.querySelectorAll('.member-script-input')].map(input => input.value.trim());
memberScripts = [...new Set(memberScripts)] // remove duplicates
const taprootTree = memberScripts.map(script => {
return { return {
script: input.value.trim(), script,
leafVersion: 0xc0, leafVersion: 0xc0,
} }
}) })
const { address } = taproot.p2tr( const { address, leaves } = taproot.p2tr(
schnorrPublicKey, schnorrPublicKey,
taprootTree, taprootTree,
undefined, undefined,
true true
); );
renderElem(getRef('generate_script_path_address_popup__content'), html` renderElem(getRef('generate_script_path_address_popup__content'), html`
<div class="grid gap-1"> <fieldset class="grid gap-0-5">
<h4>Generated Taproot script-path address</h4> <legend>Taproot script-path address</legend>
<sm-copy value="${address}"></sm-copy> <sm-copy value="${address}"><b>${address}</b></sm-copy>
</div> </fieldset>
<fieldset class="grid gap-0-5">
<legend>Members</legend>
<ul class="grid gap-0-5">
${leaves.map((leaf, index) => html`
<li class="grid gap-1 taproot-member">
<h5>Member #${index + 1}</h5>
<div class="grid">
<p class="label">Script</p>
<sm-copy value="${hex.encode(leaf.script)}"></sm-copy>
</div>
<div class="grid">
<p class="label">Control block</p>
<sm-copy value="${hex.encode(leaf.controlBlock)}"></sm-copy>
</div>
</li>
`)}
</ul>
</fieldset>
`); `);
} }
function renderScriptInputList() { function renderScriptInputList() {