From f7e9fdf002e7355a122a86a8407b470b56bf3f59 Mon Sep 17 00:00:00 2001 From: Ian Coleman Date: Tue, 17 Dec 2019 11:44:54 +1100 Subject: Generate addresses for P2WSH and P2WSH-P2SH --- src/index.html | 4 ++-- src/js/index.js | 15 +++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/index.html b/src/index.html index 61fe022..64c25f4 100644 --- a/src/index.html +++ b/src/index.html @@ -509,8 +509,8 @@ diff --git a/src/js/index.js b/src/js/index.js index db47412..5fb0c47 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -1152,12 +1152,19 @@ address = bitcoinjs.bitcoin.address.fromOutputScript(scriptpubkey, network) } else if (isP2wsh) { - // TODO - address = ""; + // https://github.com/bitcoinjs/bitcoinjs-lib/blob/v3.3.2/test/integration/addresses.js#L71 + // This is a 1-of-1 + var witnessScript = bitcoinjs.bitcoin.script.multisig.output.encode(1, [key.getPublicKeyBuffer()]); + var scriptPubKey = bitcoinjs.bitcoin.script.witnessScriptHash.output.encode(bitcoinjs.bitcoin.crypto.sha256(witnessScript)); + address = bitcoinjs.bitcoin.address.fromOutputScript(scriptPubKey, network); } else if (isP2wshInP2sh) { - // TODO - address = ""; + // https://github.com/bitcoinjs/bitcoinjs-lib/blob/v3.3.2/test/integration/transactions.js#L183 + // This is a 1-of-1 + var witnessScript = bitcoinjs.bitcoin.script.multisig.output.encode(1, [key.getPublicKeyBuffer()]); + var redeemScript = bitcoinjs.bitcoin.script.witnessScriptHash.output.encode(bitcoinjs.bitcoin.crypto.sha256(witnessScript)); + var scriptPubKey = bitcoinjs.bitcoin.script.scriptHash.output.encode(bitcoinjs.bitcoin.crypto.hash160(redeemScript)); + address = bitcoinjs.bitcoin.address.fromOutputScript(scriptPubKey, network) } } -- cgit v1.2.3