Skip to content

Commit

Permalink
consolidate BTC(Input|Output)ScriptType
Browse files Browse the repository at this point in the history
  • Loading branch information
mrnerdhair committed Feb 12, 2022
1 parent fc5e32f commit 40e7138
Show file tree
Hide file tree
Showing 28 changed files with 357 additions and 385 deletions.
70 changes: 36 additions & 34 deletions examples/sandbox/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ $getXpubs.on("click", async (e) => {
curve: "secp256k1",
showDisplay: true, // Not supported by TrezorConnect or Ledger, but KeepKey should do it
coin: "Bitcoin",
scriptType: core.BTCInputScriptType.SpendP2SHWitness,
scriptType: core.BTCScriptType.ScriptHashWitness,
},
{
addressNList: [0x80000000 + 44, 0x80000000 + 2, 0x80000000 + 0],
Expand Down Expand Up @@ -993,7 +993,7 @@ $thorchainSignSwap.on("click", async (e) => {
let inputs = [
{
addressNList: [0x80000000 + 44, 0x80000000 + 0, 0x80000000 + 0, 0, 0],
scriptType: core.BTCInputScriptType.SpendAddress,
scriptType: core.BTCScriptType.KeyHash,
amount: String(10000),
vout: 1,
txid: txid,
Expand Down Expand Up @@ -1152,7 +1152,7 @@ $thorchainSignAddLiquidity.on("click", async (e) => {
let inputs = [
{
addressNList: [0x80000000 + 44, 0x80000000 + 0, 0x80000000 + 0, 0, 0],
scriptType: core.BTCInputScriptType.SpendAddress,
scriptType: core.BTCScriptType.KeyHash,
amount: String(10000),
vout: 1,
txid: txid,
Expand Down Expand Up @@ -1879,7 +1879,7 @@ $btcAddr.on("click", async (e) => {
let res = await wallet.btcGetAddress({
addressNList: [0x80000000 + 44, 0x80000000 + 0, 0x80000000 + 0, 0, 0],
coin: "Bitcoin",
scriptType: core.BTCInputScriptType.SpendAddress,
scriptType: core.BTCScriptType.KeyHash,
showDisplay: true,
});
$btcResults.val(res);
Expand All @@ -1904,7 +1904,7 @@ $btcTx.on("click", async (e) => {
let inputs = [
{
addressNList: [0x80000000 + 44, 0x80000000 + 0, 0x80000000 + 0, 0, 0],
scriptType: core.BTCInputScriptType.SpendAddress,
scriptType: core.BTCScriptType.KeyHash,
amount: String(10000),
vout: 1,
txid: txid,
Expand All @@ -1917,7 +1917,7 @@ $btcTx.on("click", async (e) => {
{
address: "1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1",
addressType: core.BTCOutputAddressType.Spend,
scriptType: core.BTCOutputScriptType.PayToAddress,
scriptType: core.BTCScriptType.KeyHash,
amount: String(10000 - 1000),
isChange: false,
},
Expand Down Expand Up @@ -1948,7 +1948,7 @@ $btcSign.on("click", async (e) => {
let res = await wallet.btcSignMessage({
addressNList: core.bip32ToAddressNList("m/44'/0'/0'/0/0"),
coin: "Bitcoin",
scriptType: core.BTCInputScriptType.SpendAddress,
scriptType: core.BTCScriptType.KeyHash,
message: "Hello World",
});
$btcResults.val(res.address + " " + res.signature);
Expand Down Expand Up @@ -1992,7 +1992,7 @@ const $ltcVerify = $("#ltcVerify");
const $ltcResults = $("#ltcResults");

const ltcBip44 = {
scriptType: core.BTCInputScriptType.SpendAddress,
scriptType: core.BTCScriptType.KeyHash,
addressNList: [0x80000000 + 44, 0x80000000 + 2, 0x80000000 + 0, 0, 0],
};

Expand Down Expand Up @@ -2030,7 +2030,7 @@ $ltcTx.on("click", async (e) => {
const inputs = [
{
addressNList: ltcBip44.addressNList,
scriptType: core.BTCInputScriptType.SpendAddress,
scriptType: core.BTCScriptType.KeyHash,
amount: String(2160258),
vout: 0,
txid,
Expand All @@ -2044,7 +2044,7 @@ $ltcTx.on("click", async (e) => {
{
address: "LLe4PciAJgMMJSAtQQ5nkC13t6SSMmERJ3",
addressType: core.BTCOutputAddressType.Spend,
scriptType: core.BTCOutputScriptType.PayToAddress,
scriptType: core.BTCScriptType.KeyHash,
amount: String(261614),
isChange: false,
},
Expand Down Expand Up @@ -2074,7 +2074,7 @@ $ltcSign.on("click", async (e) => {
let res = await wallet.btcSignMessage({
addressNList: ltcBip44.addressNList,
coin: "Litecoin",
scriptType: core.BTCInputScriptType.SpendAddress,
scriptType: core.BTCScriptType.KeyHash,
message: "Hello World",
});
$ltcResults.val(res.address + " " + res.signature);
Expand All @@ -2098,7 +2098,7 @@ const $dogeTx = $("#dogeTx");
const $dogeResults = $("#dogeResults");

const dogeBip44 = {
scriptType: core.BTCInputScriptType.SpendAddress,
scriptType: core.BTCScriptType.KeyHash,
addressNList: [0x80000000 + 44, 0x80000000 + 3, 0x80000000 + 0],
};
$dogeAddr.on("click", async (e) => {
Expand Down Expand Up @@ -2135,7 +2135,7 @@ $dogeTx.on("click", async (e) => {
const inputs = [
{
addressNList: dogeBip44.addressNList.concat([0, 0]),
scriptType: core.BTCInputScriptType.SpendAddress,
scriptType: core.BTCScriptType.KeyHash,
amount: String(35577380098),
vout: 1,
txid: txid,
Expand All @@ -2149,7 +2149,7 @@ $dogeTx.on("click", async (e) => {
{
address: "DMEHVGRsELY5zyYbfgta3pAhedKGeaDeJd",
addressType: core.BTCOutputAddressType.Spend,
scriptType: core.BTCOutputScriptType.PayToAddress,
scriptType: core.BTCScriptType.KeyHash,
amount: String(35577380098),
isChange: false,
},
Expand Down Expand Up @@ -2181,7 +2181,7 @@ const $bchTx = $("#bchTx");
const $bchResults = $("#bchResults");

const bchBip44 = {
scriptType: core.BTCInputScriptType.SpendAddress,
scriptType: core.BTCScriptType.KeyHash,
addressNList: [0x80000000 + 44, 0x80000000 + 145, 0x80000000 + 0],
};

Expand Down Expand Up @@ -2219,7 +2219,7 @@ $bchTx.on("click", async (e) => {
const inputs = [
{
addressNList: bchBip44.addressNList.concat([0, 0]),
scriptType: core.BTCInputScriptType.SpendAddress,
scriptType: core.BTCScriptType.KeyHash,
amount: String(13813640),
vout: 0,
txid: txid,
Expand All @@ -2230,11 +2230,13 @@ $bchTx.on("click", async (e) => {

const outputs = [
{
address: (await wallet.btcSupportsScriptType("BitcoinCash", core.BTCInputScriptType.CashAddr))
? "bitcoincash:qq5mg2xtp9y5pvvgy7m4k2af5a7s5suulueyywgvnf"
: "14oWXZFPhgP9DA3ggPzhHpUUaikDSjAuMC",
// TODO: replace with btcSupportsAddressFormat
// address: (await wallet.btcSupportsAddressFormat("BitcoinCash", core.BTCAddressFormat.CashAddr))
// ? "bitcoincash:qq5mg2xtp9y5pvvgy7m4k2af5a7s5suulueyywgvnf"
// : "14oWXZFPhgP9DA3ggPzhHpUUaikDSjAuMC",
address: "14oWXZFPhgP9DA3ggPzhHpUUaikDSjAuMC",
addressType: core.BTCOutputAddressType.Spend,
scriptType: core.BTCOutputScriptType.PayToAddress,
scriptType: core.BTCScriptType.KeyHash,
amount: String(13813640),
isChange: false,
},
Expand Down Expand Up @@ -2266,7 +2268,7 @@ const $dashTx = $("#dashTx");
const $dashResults = $("#dashResults");

const dashBip44 = {
scriptType: core.BTCInputScriptType.SpendAddress,
scriptType: core.BTCScriptType.KeyHash,
addressNList: [0x80000000 + 44, 0x80000000 + 5, 0x80000000 + 0],
};

Expand Down Expand Up @@ -2304,7 +2306,7 @@ $dashTx.on("click", async (e) => {
const inputs = [
{
addressNList: dashBip44.addressNList.concat([0, 0]),
scriptType: core.BTCInputScriptType.SpendAddress,
scriptType: core.BTCScriptType.KeyHash,
amount: String(4954359),
vout: 0,
txid: txid,
Expand All @@ -2318,7 +2320,7 @@ $dashTx.on("click", async (e) => {
{
address: "XexybzTUtH9V9eY4UJN2aCcBT3utan5C8N",
addressType: core.BTCOutputAddressType.Spend,
scriptType: core.BTCOutputScriptType.PayToAddress,
scriptType: core.BTCScriptType.KeyHash,
amount: String(4000000),
isChange: false,
},
Expand Down Expand Up @@ -2349,7 +2351,7 @@ const $dgbTx = $("#dgbTx");
const $dgbResults = $("#dgbResults");

const dgbBip44 = {
scriptType: core.BTCInputScriptType.SpendAddress,
scriptType: core.BTCScriptType.KeyHash,
addressNList: [0x80000000 + 44, 0x80000000 + 20, 0x80000000 + 0],
};

Expand Down Expand Up @@ -2389,7 +2391,7 @@ $dgbTx.on("click", async (e) => {
const inputs = [
{
addressNList: dgbBip44.addressNList.concat([0, 0]),
scriptType: core.BTCInputScriptType.SpendAddress,
scriptType: core.BTCScriptType.KeyHash,
amount: String(480000000),
vout: 15,
txid: "be150359df4123b379f1f12de978bfced92644645da17b97c7613879f4306a90",
Expand All @@ -2398,7 +2400,7 @@ $dgbTx.on("click", async (e) => {
},
{
addressNList: dgbBip44.addressNList.concat([0, 0]),
scriptType: core.BTCInputScriptType.SpendAddress,
scriptType: core.BTCScriptType.KeyHash,
amount: String(10000000),
vout: 0,
txid: "528ec23eaf123282e9bce297ebb3edfb05e8b4d5875cbc9c271a98d72a202340",
Expand All @@ -2411,14 +2413,14 @@ $dgbTx.on("click", async (e) => {
{
address: "SWpe93hQL2pLUDLy7swsDPWQJGCHSsgmun",
addressType: null,
scriptType: core.BTCOutputScriptType.PayToMultisig,
scriptType: core.BTCScriptType.ScriptHash,
amount: String(400000000),
isChange: false,
},
{
address: "DNLcBry65dHehGExGYjBkM8kxDYr7mZ3BT",
addressType: null,
scriptType: core.BTCOutputScriptType.PayToAddress,
scriptType: core.BTCScriptType.KeyHash,
relpath: "1/9",
amount: String(90000000),
isChange: true,
Expand Down Expand Up @@ -2467,7 +2469,7 @@ $btcAddrSegWit.on("click", async (e) => {
let res = await wallet.btcGetAddress({
addressNList: [0x80000000 + 49, 0x80000000 + 0, 0x80000000 + 0, 0, 0],
coin: "Bitcoin",
scriptType: core.BTCInputScriptType.SpendP2SHWitness,
scriptType: core.BTCScriptType.ScriptHashWitness,
showDisplay: true,
});

Expand All @@ -2490,7 +2492,7 @@ $btcAddrSegWitNative.on("click", async (e) => {
let res = await wallet.btcGetAddress({
addressNList: [0x80000000 + 84, 0x80000000 + 0, 0x80000000 + 0, 0, 0],
coin: "Bitcoin",
scriptType: core.BTCInputScriptType.SpendWitness,
scriptType: core.BTCScriptType.Witness,
showDisplay: true,
});
$btcResultsSegWit.val(res);
Expand All @@ -2517,7 +2519,7 @@ $btcTxSegWit.on("click", async (e) => {
amount: String(100000),
vout: 0,
txid: txid,
scriptType: core.BTCInputScriptType.SpendP2SHWitness,
scriptType: core.BTCScriptType.ScriptHashWitness,
tx: btcSegWitTxJson,
hex,
},
Expand All @@ -2527,7 +2529,7 @@ $btcTxSegWit.on("click", async (e) => {
{
address: "3Eq3agTHEhMCC8sZHnJJcCcZFB7BBSJKWr",
addressType: core.BTCOutputAddressType.Spend,
scriptType: core.BTCOutputScriptType.PayToAddress,
scriptType: core.BTCScriptType.KeyHash,
amount: String(89869),
isChange: false,
},
Expand Down Expand Up @@ -2569,7 +2571,7 @@ $btcTxSegWitNative.on("click", async (e) => {
amount: String(9426),
vout: 0,
txid: txid,
scriptType: core.BTCInputScriptType.SpendWitness,
scriptType: core.BTCScriptType.Witness,
tx: btcBech32TxJson,
hex,
},
Expand All @@ -2579,7 +2581,7 @@ $btcTxSegWitNative.on("click", async (e) => {
{
address: "bc1qc5dgazasye0yrzdavnw6wau5up8td8gdqh7t6m",
addressType: core.BTCOutputAddressType.Spend,
scriptType: core.BTCOutputScriptType.PayToAddress,
scriptType: core.BTCScriptType.KeyHash,
amount: String(1337),
isChange: false,
},
Expand Down
Loading

0 comments on commit 40e7138

Please sign in to comment.