Merge pull request #1433 from bitcoinjs/addNamePayments
Add name attribute to Payments
This commit is contained in:
commit
19a126c205
23 changed files with 105 additions and 8 deletions
|
@ -24,7 +24,7 @@ function p2data(a, opts) {
|
||||||
a,
|
a,
|
||||||
);
|
);
|
||||||
const network = a.network || networks_1.bitcoin;
|
const network = a.network || networks_1.bitcoin;
|
||||||
const o = { network };
|
const o = { name: 'embed', network };
|
||||||
lazy.prop(o, 'output', () => {
|
lazy.prop(o, 'output', () => {
|
||||||
if (!a.data) return;
|
if (!a.data) return;
|
||||||
return bscript.compile([OPS.OP_RETURN].concat(a.data));
|
return bscript.compile([OPS.OP_RETURN].concat(a.data));
|
||||||
|
|
|
@ -93,6 +93,10 @@ function p2ms(a, opts) {
|
||||||
if (!o.input) return;
|
if (!o.input) return;
|
||||||
return [];
|
return [];
|
||||||
});
|
});
|
||||||
|
lazy.prop(o, 'name', () => {
|
||||||
|
if (!o.m || !o.n) return;
|
||||||
|
return `p2ms(${o.m} of ${o.n})`;
|
||||||
|
});
|
||||||
// extended validation
|
// extended validation
|
||||||
if (opts.validate) {
|
if (opts.validate) {
|
||||||
if (a.output) {
|
if (a.output) {
|
||||||
|
|
|
@ -26,7 +26,7 @@ function p2pk(a, opts) {
|
||||||
return bscript.decompile(a.input);
|
return bscript.decompile(a.input);
|
||||||
});
|
});
|
||||||
const network = a.network || networks_1.bitcoin;
|
const network = a.network || networks_1.bitcoin;
|
||||||
const o = { network };
|
const o = { name: 'p2pk', network };
|
||||||
lazy.prop(o, 'output', () => {
|
lazy.prop(o, 'output', () => {
|
||||||
if (!a.pubkey) return;
|
if (!a.pubkey) return;
|
||||||
return bscript.compile([a.pubkey, OPS.OP_CHECKSIG]);
|
return bscript.compile([a.pubkey, OPS.OP_CHECKSIG]);
|
||||||
|
|
|
@ -36,7 +36,7 @@ function p2pkh(a, opts) {
|
||||||
return bscript.decompile(a.input);
|
return bscript.decompile(a.input);
|
||||||
});
|
});
|
||||||
const network = a.network || networks_1.bitcoin;
|
const network = a.network || networks_1.bitcoin;
|
||||||
const o = { network };
|
const o = { name: 'p2pkh', network };
|
||||||
lazy.prop(o, 'address', () => {
|
lazy.prop(o, 'address', () => {
|
||||||
if (!o.hash) return;
|
if (!o.hash) return;
|
||||||
const payload = Buffer.allocUnsafe(21);
|
const payload = Buffer.allocUnsafe(21);
|
||||||
|
|
|
@ -93,6 +93,11 @@ function p2sh(a, opts) {
|
||||||
if (o.redeem && o.redeem.witness) return o.redeem.witness;
|
if (o.redeem && o.redeem.witness) return o.redeem.witness;
|
||||||
if (o.input) return [];
|
if (o.input) return [];
|
||||||
});
|
});
|
||||||
|
lazy.prop(o, 'name', () => {
|
||||||
|
const nameParts = ['p2sh'];
|
||||||
|
if (o.redeem !== undefined) nameParts.push(o.redeem.name);
|
||||||
|
return nameParts.join('-');
|
||||||
|
});
|
||||||
if (opts.validate) {
|
if (opts.validate) {
|
||||||
let hash = Buffer.from([]);
|
let hash = Buffer.from([]);
|
||||||
if (a.address) {
|
if (a.address) {
|
||||||
|
|
|
@ -40,7 +40,7 @@ function p2wpkh(a, opts) {
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
const network = a.network || networks_1.bitcoin;
|
const network = a.network || networks_1.bitcoin;
|
||||||
const o = { network };
|
const o = { name: 'p2wpkh', network };
|
||||||
lazy.prop(o, 'address', () => {
|
lazy.prop(o, 'address', () => {
|
||||||
if (!o.hash) return;
|
if (!o.hash) return;
|
||||||
const words = bech32.toWords(o.hash);
|
const words = bech32.toWords(o.hash);
|
||||||
|
|
|
@ -103,6 +103,11 @@ function p2wsh(a, opts) {
|
||||||
if (!a.redeem.witness) return;
|
if (!a.redeem.witness) return;
|
||||||
return [].concat(a.redeem.witness, a.redeem.output);
|
return [].concat(a.redeem.witness, a.redeem.output);
|
||||||
});
|
});
|
||||||
|
lazy.prop(o, 'name', () => {
|
||||||
|
const nameParts = ['p2wsh'];
|
||||||
|
if (o.redeem !== undefined) nameParts.push(o.redeem.name);
|
||||||
|
return nameParts.join('-');
|
||||||
|
});
|
||||||
// extended validation
|
// extended validation
|
||||||
if (opts.validate) {
|
if (opts.validate) {
|
||||||
let hash = Buffer.from([]);
|
let hash = Buffer.from([]);
|
||||||
|
|
7
test/fixtures/p2ms.json
vendored
7
test/fixtures/p2ms.json
vendored
|
@ -9,6 +9,7 @@
|
||||||
"expected": {
|
"expected": {
|
||||||
"m": 2,
|
"m": 2,
|
||||||
"n": 2,
|
"n": 2,
|
||||||
|
"name": "p2ms(2 of 2)",
|
||||||
"output": "OP_2 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 OP_2 OP_CHECKMULTISIG",
|
"output": "OP_2 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 OP_2 OP_CHECKMULTISIG",
|
||||||
"pubkeys": [
|
"pubkeys": [
|
||||||
"030000000000000000000000000000000000000000000000000000000000000001",
|
"030000000000000000000000000000000000000000000000000000000000000001",
|
||||||
|
@ -31,6 +32,7 @@
|
||||||
"expected": {
|
"expected": {
|
||||||
"m": 1,
|
"m": 1,
|
||||||
"n": 2,
|
"n": 2,
|
||||||
|
"name": "p2ms(1 of 2)",
|
||||||
"output": "OP_1 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 OP_2 OP_CHECKMULTISIG",
|
"output": "OP_1 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 OP_2 OP_CHECKMULTISIG",
|
||||||
"pubkeys": [
|
"pubkeys": [
|
||||||
"030000000000000000000000000000000000000000000000000000000000000001",
|
"030000000000000000000000000000000000000000000000000000000000000001",
|
||||||
|
@ -58,6 +60,7 @@
|
||||||
"expected": {
|
"expected": {
|
||||||
"m": 2,
|
"m": 2,
|
||||||
"n": 3,
|
"n": 3,
|
||||||
|
"name": "p2ms(2 of 3)",
|
||||||
"output": "OP_2 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 030000000000000000000000000000000000000000000000000000000000000003 OP_3 OP_CHECKMULTISIG",
|
"output": "OP_2 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 030000000000000000000000000000000000000000000000000000000000000003 OP_3 OP_CHECKMULTISIG",
|
||||||
"pubkeys": [
|
"pubkeys": [
|
||||||
"030000000000000000000000000000000000000000000000000000000000000001",
|
"030000000000000000000000000000000000000000000000000000000000000001",
|
||||||
|
@ -84,6 +87,7 @@
|
||||||
"expected": {
|
"expected": {
|
||||||
"m": 2,
|
"m": 2,
|
||||||
"n": 3,
|
"n": 3,
|
||||||
|
"name": "p2ms(2 of 3)",
|
||||||
"output": "OP_2 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 030000000000000000000000000000000000000000000000000000000000000003 OP_3 OP_CHECKMULTISIG",
|
"output": "OP_2 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 030000000000000000000000000000000000000000000000000000000000000003 OP_3 OP_CHECKMULTISIG",
|
||||||
"pubkeys": [
|
"pubkeys": [
|
||||||
"030000000000000000000000000000000000000000000000000000000000000001",
|
"030000000000000000000000000000000000000000000000000000000000000001",
|
||||||
|
@ -107,6 +111,7 @@
|
||||||
"expected": {
|
"expected": {
|
||||||
"m": 2,
|
"m": 2,
|
||||||
"n": 3,
|
"n": 3,
|
||||||
|
"name": "p2ms(2 of 3)",
|
||||||
"output": "OP_2 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 030000000000000000000000000000000000000000000000000000000000000003 OP_3 OP_CHECKMULTISIG",
|
"output": "OP_2 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 030000000000000000000000000000000000000000000000000000000000000003 OP_3 OP_CHECKMULTISIG",
|
||||||
"pubkeys": [
|
"pubkeys": [
|
||||||
"030000000000000000000000000000000000000000000000000000000000000001",
|
"030000000000000000000000000000000000000000000000000000000000000001",
|
||||||
|
@ -133,6 +138,7 @@
|
||||||
"expected": {
|
"expected": {
|
||||||
"m": 2,
|
"m": 2,
|
||||||
"n": 2,
|
"n": 2,
|
||||||
|
"name": "p2ms(2 of 2)",
|
||||||
"output": "OP_2 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 OP_2 OP_CHECKMULTISIG",
|
"output": "OP_2 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 OP_2 OP_CHECKMULTISIG",
|
||||||
"pubkeys": [
|
"pubkeys": [
|
||||||
"030000000000000000000000000000000000000000000000000000000000000001",
|
"030000000000000000000000000000000000000000000000000000000000000001",
|
||||||
|
@ -161,6 +167,7 @@
|
||||||
"expected": {
|
"expected": {
|
||||||
"m": 2,
|
"m": 2,
|
||||||
"n": 2,
|
"n": 2,
|
||||||
|
"name": "p2ms(2 of 2)",
|
||||||
"output": "OP_2 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 OP_2 OP_CHECKMULTISIG",
|
"output": "OP_2 030000000000000000000000000000000000000000000000000000000000000001 030000000000000000000000000000000000000000000000000000000000000002 OP_2 OP_CHECKMULTISIG",
|
||||||
"pubkeys": [
|
"pubkeys": [
|
||||||
"030000000000000000000000000000000000000000000000000000000000000001",
|
"030000000000000000000000000000000000000000000000000000000000000001",
|
||||||
|
|
5
test/fixtures/p2pk.json
vendored
5
test/fixtures/p2pk.json
vendored
|
@ -7,6 +7,7 @@
|
||||||
},
|
},
|
||||||
"options": {},
|
"options": {},
|
||||||
"expected": {
|
"expected": {
|
||||||
|
"name": "p2pk",
|
||||||
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001",
|
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001",
|
||||||
"signature": null,
|
"signature": null,
|
||||||
"input": null,
|
"input": null,
|
||||||
|
@ -19,6 +20,7 @@
|
||||||
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001"
|
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001"
|
||||||
},
|
},
|
||||||
"expected": {
|
"expected": {
|
||||||
|
"name": "p2pk",
|
||||||
"output": "030000000000000000000000000000000000000000000000000000000000000001 OP_CHECKSIG",
|
"output": "030000000000000000000000000000000000000000000000000000000000000001 OP_CHECKSIG",
|
||||||
"signature": null,
|
"signature": null,
|
||||||
"input": null,
|
"input": null,
|
||||||
|
@ -32,6 +34,7 @@
|
||||||
"signature": "300602010002010001"
|
"signature": "300602010002010001"
|
||||||
},
|
},
|
||||||
"expected": {
|
"expected": {
|
||||||
|
"name": "p2pk",
|
||||||
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001",
|
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001",
|
||||||
"input": "300602010002010001",
|
"input": "300602010002010001",
|
||||||
"witness": []
|
"witness": []
|
||||||
|
@ -44,6 +47,7 @@
|
||||||
"signature": "300602010002010001"
|
"signature": "300602010002010001"
|
||||||
},
|
},
|
||||||
"expected": {
|
"expected": {
|
||||||
|
"name": "p2pk",
|
||||||
"output": "030000000000000000000000000000000000000000000000000000000000000001 OP_CHECKSIG",
|
"output": "030000000000000000000000000000000000000000000000000000000000000001 OP_CHECKSIG",
|
||||||
"input": "300602010002010001",
|
"input": "300602010002010001",
|
||||||
"witness": []
|
"witness": []
|
||||||
|
@ -56,6 +60,7 @@
|
||||||
"input": "300602010002010001"
|
"input": "300602010002010001"
|
||||||
},
|
},
|
||||||
"expected": {
|
"expected": {
|
||||||
|
"name": "p2pk",
|
||||||
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001",
|
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001",
|
||||||
"signature": "300602010002010001",
|
"signature": "300602010002010001",
|
||||||
"witness": []
|
"witness": []
|
||||||
|
|
6
test/fixtures/p2pkh.json
vendored
6
test/fixtures/p2pkh.json
vendored
|
@ -7,6 +7,7 @@
|
||||||
},
|
},
|
||||||
"options": {},
|
"options": {},
|
||||||
"expected": {
|
"expected": {
|
||||||
|
"name": "p2pkh",
|
||||||
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1",
|
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1",
|
||||||
"output": "OP_DUP OP_HASH160 168b992bcfc44050310b3a94bd0771136d0b28d1 OP_EQUALVERIFY OP_CHECKSIG",
|
"output": "OP_DUP OP_HASH160 168b992bcfc44050310b3a94bd0771136d0b28d1 OP_EQUALVERIFY OP_CHECKSIG",
|
||||||
"signature": null,
|
"signature": null,
|
||||||
|
@ -20,6 +21,7 @@
|
||||||
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1"
|
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1"
|
||||||
},
|
},
|
||||||
"expected": {
|
"expected": {
|
||||||
|
"name": "p2pkh",
|
||||||
"address": "134D6gYy8DsR5m4416BnmgASuMBqKvogQh",
|
"address": "134D6gYy8DsR5m4416BnmgASuMBqKvogQh",
|
||||||
"output": "OP_DUP OP_HASH160 168b992bcfc44050310b3a94bd0771136d0b28d1 OP_EQUALVERIFY OP_CHECKSIG",
|
"output": "OP_DUP OP_HASH160 168b992bcfc44050310b3a94bd0771136d0b28d1 OP_EQUALVERIFY OP_CHECKSIG",
|
||||||
"signature": null,
|
"signature": null,
|
||||||
|
@ -33,6 +35,7 @@
|
||||||
"output": "OP_DUP OP_HASH160 168b992bcfc44050310b3a94bd0771136d0b28d1 OP_EQUALVERIFY OP_CHECKSIG"
|
"output": "OP_DUP OP_HASH160 168b992bcfc44050310b3a94bd0771136d0b28d1 OP_EQUALVERIFY OP_CHECKSIG"
|
||||||
},
|
},
|
||||||
"expected": {
|
"expected": {
|
||||||
|
"name": "p2pkh",
|
||||||
"address": "134D6gYy8DsR5m4416BnmgASuMBqKvogQh",
|
"address": "134D6gYy8DsR5m4416BnmgASuMBqKvogQh",
|
||||||
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1",
|
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1",
|
||||||
"signature": null,
|
"signature": null,
|
||||||
|
@ -46,6 +49,7 @@
|
||||||
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001"
|
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001"
|
||||||
},
|
},
|
||||||
"expected": {
|
"expected": {
|
||||||
|
"name": "p2pkh",
|
||||||
"address": "134D6gYy8DsR5m4416BnmgASuMBqKvogQh",
|
"address": "134D6gYy8DsR5m4416BnmgASuMBqKvogQh",
|
||||||
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1",
|
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1",
|
||||||
"output": "OP_DUP OP_HASH160 168b992bcfc44050310b3a94bd0771136d0b28d1 OP_EQUALVERIFY OP_CHECKSIG",
|
"output": "OP_DUP OP_HASH160 168b992bcfc44050310b3a94bd0771136d0b28d1 OP_EQUALVERIFY OP_CHECKSIG",
|
||||||
|
@ -61,6 +65,7 @@
|
||||||
"signature": "300602010002010001"
|
"signature": "300602010002010001"
|
||||||
},
|
},
|
||||||
"expected": {
|
"expected": {
|
||||||
|
"name": "p2pkh",
|
||||||
"address": "134D6gYy8DsR5m4416BnmgASuMBqKvogQh",
|
"address": "134D6gYy8DsR5m4416BnmgASuMBqKvogQh",
|
||||||
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1",
|
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1",
|
||||||
"output": "OP_DUP OP_HASH160 168b992bcfc44050310b3a94bd0771136d0b28d1 OP_EQUALVERIFY OP_CHECKSIG",
|
"output": "OP_DUP OP_HASH160 168b992bcfc44050310b3a94bd0771136d0b28d1 OP_EQUALVERIFY OP_CHECKSIG",
|
||||||
|
@ -74,6 +79,7 @@
|
||||||
"input": "300602010002010001 030000000000000000000000000000000000000000000000000000000000000001"
|
"input": "300602010002010001 030000000000000000000000000000000000000000000000000000000000000001"
|
||||||
},
|
},
|
||||||
"expected": {
|
"expected": {
|
||||||
|
"name": "p2pkh",
|
||||||
"address": "134D6gYy8DsR5m4416BnmgASuMBqKvogQh",
|
"address": "134D6gYy8DsR5m4416BnmgASuMBqKvogQh",
|
||||||
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1",
|
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1",
|
||||||
"output": "OP_DUP OP_HASH160 168b992bcfc44050310b3a94bd0771136d0b28d1 OP_EQUALVERIFY OP_CHECKSIG",
|
"output": "OP_DUP OP_HASH160 168b992bcfc44050310b3a94bd0771136d0b28d1 OP_EQUALVERIFY OP_CHECKSIG",
|
||||||
|
|
11
test/fixtures/p2sh.json
vendored
11
test/fixtures/p2sh.json
vendored
|
@ -7,6 +7,7 @@
|
||||||
},
|
},
|
||||||
"options": {},
|
"options": {},
|
||||||
"expected": {
|
"expected": {
|
||||||
|
"name": "p2sh",
|
||||||
"hash": "9f840a5fc02407ef0ad499c2ec0eb0b942fb0086",
|
"hash": "9f840a5fc02407ef0ad499c2ec0eb0b942fb0086",
|
||||||
"output": "OP_HASH160 9f840a5fc02407ef0ad499c2ec0eb0b942fb0086 OP_EQUAL",
|
"output": "OP_HASH160 9f840a5fc02407ef0ad499c2ec0eb0b942fb0086 OP_EQUAL",
|
||||||
"redeem": null,
|
"redeem": null,
|
||||||
|
@ -20,6 +21,7 @@
|
||||||
"hash": "9f840a5fc02407ef0ad499c2ec0eb0b942fb0086"
|
"hash": "9f840a5fc02407ef0ad499c2ec0eb0b942fb0086"
|
||||||
},
|
},
|
||||||
"expected": {
|
"expected": {
|
||||||
|
"name": "p2sh",
|
||||||
"address": "3GETYP4cuSesh2zsPEEYVZqnRedwe4FwUT",
|
"address": "3GETYP4cuSesh2zsPEEYVZqnRedwe4FwUT",
|
||||||
"output": "OP_HASH160 9f840a5fc02407ef0ad499c2ec0eb0b942fb0086 OP_EQUAL",
|
"output": "OP_HASH160 9f840a5fc02407ef0ad499c2ec0eb0b942fb0086 OP_EQUAL",
|
||||||
"redeem": null,
|
"redeem": null,
|
||||||
|
@ -33,6 +35,7 @@
|
||||||
"output": "OP_HASH160 9f840a5fc02407ef0ad499c2ec0eb0b942fb0086 OP_EQUAL"
|
"output": "OP_HASH160 9f840a5fc02407ef0ad499c2ec0eb0b942fb0086 OP_EQUAL"
|
||||||
},
|
},
|
||||||
"expected": {
|
"expected": {
|
||||||
|
"name": "p2sh",
|
||||||
"address": "3GETYP4cuSesh2zsPEEYVZqnRedwe4FwUT",
|
"address": "3GETYP4cuSesh2zsPEEYVZqnRedwe4FwUT",
|
||||||
"hash": "9f840a5fc02407ef0ad499c2ec0eb0b942fb0086",
|
"hash": "9f840a5fc02407ef0ad499c2ec0eb0b942fb0086",
|
||||||
"redeem": null,
|
"redeem": null,
|
||||||
|
@ -49,6 +52,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"expected": {
|
"expected": {
|
||||||
|
"name": "p2sh-p2pkh",
|
||||||
"address": "3GETYP4cuSesh2zsPEEYVZqnRedwe4FwUT",
|
"address": "3GETYP4cuSesh2zsPEEYVZqnRedwe4FwUT",
|
||||||
"hash": "9f840a5fc02407ef0ad499c2ec0eb0b942fb0086",
|
"hash": "9f840a5fc02407ef0ad499c2ec0eb0b942fb0086",
|
||||||
"output": "OP_HASH160 9f840a5fc02407ef0ad499c2ec0eb0b942fb0086 OP_EQUAL",
|
"output": "OP_HASH160 9f840a5fc02407ef0ad499c2ec0eb0b942fb0086 OP_EQUAL",
|
||||||
|
@ -65,6 +69,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"expected": {
|
"expected": {
|
||||||
|
"name": "p2sh-p2wpkh",
|
||||||
"address": "325CuTNSYmvurXaBmhNFer5zDkKnDXZggu",
|
"address": "325CuTNSYmvurXaBmhNFer5zDkKnDXZggu",
|
||||||
"hash": "0432515d8fe8de31be8207987fc6d67b29d5e7cc",
|
"hash": "0432515d8fe8de31be8207987fc6d67b29d5e7cc",
|
||||||
"output": "OP_HASH160 0432515d8fe8de31be8207987fc6d67b29d5e7cc OP_EQUAL",
|
"output": "OP_HASH160 0432515d8fe8de31be8207987fc6d67b29d5e7cc OP_EQUAL",
|
||||||
|
@ -81,6 +86,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"expected": {
|
"expected": {
|
||||||
|
"name": "p2sh-p2pk",
|
||||||
"address": "36TibC8RrPB9WrBdPoGXhHqDHJosyFVtVQ",
|
"address": "36TibC8RrPB9WrBdPoGXhHqDHJosyFVtVQ",
|
||||||
"hash": "3454c084887afe854e80221c69d6282926f809c4",
|
"hash": "3454c084887afe854e80221c69d6282926f809c4",
|
||||||
"output": "OP_HASH160 3454c084887afe854e80221c69d6282926f809c4 OP_EQUAL",
|
"output": "OP_HASH160 3454c084887afe854e80221c69d6282926f809c4 OP_EQUAL",
|
||||||
|
@ -97,6 +103,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"expected": {
|
"expected": {
|
||||||
|
"name": "p2sh-p2pkh",
|
||||||
"address": "3GETYP4cuSesh2zsPEEYVZqnRedwe4FwUT",
|
"address": "3GETYP4cuSesh2zsPEEYVZqnRedwe4FwUT",
|
||||||
"hash": "9f840a5fc02407ef0ad499c2ec0eb0b942fb0086",
|
"hash": "9f840a5fc02407ef0ad499c2ec0eb0b942fb0086",
|
||||||
"output": "OP_HASH160 9f840a5fc02407ef0ad499c2ec0eb0b942fb0086 OP_EQUAL",
|
"output": "OP_HASH160 9f840a5fc02407ef0ad499c2ec0eb0b942fb0086 OP_EQUAL",
|
||||||
|
@ -117,6 +124,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"expected": {
|
"expected": {
|
||||||
|
"name": "p2sh-p2wpkh",
|
||||||
"address": "325CuTNSYmvurXaBmhNFer5zDkKnDXZggu",
|
"address": "325CuTNSYmvurXaBmhNFer5zDkKnDXZggu",
|
||||||
"hash": "0432515d8fe8de31be8207987fc6d67b29d5e7cc",
|
"hash": "0432515d8fe8de31be8207987fc6d67b29d5e7cc",
|
||||||
"output": "OP_HASH160 0432515d8fe8de31be8207987fc6d67b29d5e7cc OP_EQUAL",
|
"output": "OP_HASH160 0432515d8fe8de31be8207987fc6d67b29d5e7cc OP_EQUAL",
|
||||||
|
@ -133,6 +141,7 @@
|
||||||
"input": "3045022100e4fce9ec72b609a2df1dc050c20dcf101d27faefb3e686b7a4cb067becdd5e8e022071287fced53806b08cf39b5ad58bbe614775b3776e98a9f8760af0d4d1d47a9501 2103e15819590382a9dd878f01e2f0cbce541564eb415e43b440472d883ecd283058ac"
|
"input": "3045022100e4fce9ec72b609a2df1dc050c20dcf101d27faefb3e686b7a4cb067becdd5e8e022071287fced53806b08cf39b5ad58bbe614775b3776e98a9f8760af0d4d1d47a9501 2103e15819590382a9dd878f01e2f0cbce541564eb415e43b440472d883ecd283058ac"
|
||||||
},
|
},
|
||||||
"expected": {
|
"expected": {
|
||||||
|
"name": "p2sh-p2pk",
|
||||||
"address": "36TibC8RrPB9WrBdPoGXhHqDHJosyFVtVQ",
|
"address": "36TibC8RrPB9WrBdPoGXhHqDHJosyFVtVQ",
|
||||||
"hash": "3454c084887afe854e80221c69d6282926f809c4",
|
"hash": "3454c084887afe854e80221c69d6282926f809c4",
|
||||||
"output": "OP_HASH160 3454c084887afe854e80221c69d6282926f809c4 OP_EQUAL",
|
"output": "OP_HASH160 3454c084887afe854e80221c69d6282926f809c4 OP_EQUAL",
|
||||||
|
@ -154,6 +163,7 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"expected": {
|
"expected": {
|
||||||
|
"name": "p2sh-p2wpkh",
|
||||||
"address": "325CuTNSYmvurXaBmhNFer5zDkKnDXZggu",
|
"address": "325CuTNSYmvurXaBmhNFer5zDkKnDXZggu",
|
||||||
"hash": "0432515d8fe8de31be8207987fc6d67b29d5e7cc",
|
"hash": "0432515d8fe8de31be8207987fc6d67b29d5e7cc",
|
||||||
"output": "OP_HASH160 0432515d8fe8de31be8207987fc6d67b29d5e7cc OP_EQUAL",
|
"output": "OP_HASH160 0432515d8fe8de31be8207987fc6d67b29d5e7cc OP_EQUAL",
|
||||||
|
@ -177,6 +187,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"expected": {
|
"expected": {
|
||||||
|
"name": "p2sh-p2pkh",
|
||||||
"address": "2N7nfc7zeWuADtpdR4MrR7Wq3dzr7LxTCgS",
|
"address": "2N7nfc7zeWuADtpdR4MrR7Wq3dzr7LxTCgS",
|
||||||
"hash": "9f840a5fc02407ef0ad499c2ec0eb0b942fb0086",
|
"hash": "9f840a5fc02407ef0ad499c2ec0eb0b942fb0086",
|
||||||
"output": "OP_HASH160 9f840a5fc02407ef0ad499c2ec0eb0b942fb0086 OP_EQUAL",
|
"output": "OP_HASH160 9f840a5fc02407ef0ad499c2ec0eb0b942fb0086 OP_EQUAL",
|
||||||
|
|
6
test/fixtures/p2wpkh.json
vendored
6
test/fixtures/p2wpkh.json
vendored
|
@ -7,6 +7,7 @@
|
||||||
},
|
},
|
||||||
"options": {},
|
"options": {},
|
||||||
"expected": {
|
"expected": {
|
||||||
|
"name": "p2wpkh",
|
||||||
"hash": "ea6d525c0c955d90d3dbd29a81ef8bfb79003727",
|
"hash": "ea6d525c0c955d90d3dbd29a81ef8bfb79003727",
|
||||||
"output": "OP_0 ea6d525c0c955d90d3dbd29a81ef8bfb79003727",
|
"output": "OP_0 ea6d525c0c955d90d3dbd29a81ef8bfb79003727",
|
||||||
"signature": null,
|
"signature": null,
|
||||||
|
@ -20,6 +21,7 @@
|
||||||
"hash": "ea6d525c0c955d90d3dbd29a81ef8bfb79003727"
|
"hash": "ea6d525c0c955d90d3dbd29a81ef8bfb79003727"
|
||||||
},
|
},
|
||||||
"expected": {
|
"expected": {
|
||||||
|
"name": "p2wpkh",
|
||||||
"address": "bc1qafk4yhqvj4wep57m62dgrmutldusqde8adh20d",
|
"address": "bc1qafk4yhqvj4wep57m62dgrmutldusqde8adh20d",
|
||||||
"output": "OP_0 ea6d525c0c955d90d3dbd29a81ef8bfb79003727",
|
"output": "OP_0 ea6d525c0c955d90d3dbd29a81ef8bfb79003727",
|
||||||
"signature": null,
|
"signature": null,
|
||||||
|
@ -33,6 +35,7 @@
|
||||||
"output": "OP_0 ea6d525c0c955d90d3dbd29a81ef8bfb79003727"
|
"output": "OP_0 ea6d525c0c955d90d3dbd29a81ef8bfb79003727"
|
||||||
},
|
},
|
||||||
"expected": {
|
"expected": {
|
||||||
|
"name": "p2wpkh",
|
||||||
"address": "bc1qafk4yhqvj4wep57m62dgrmutldusqde8adh20d",
|
"address": "bc1qafk4yhqvj4wep57m62dgrmutldusqde8adh20d",
|
||||||
"hash": "ea6d525c0c955d90d3dbd29a81ef8bfb79003727",
|
"hash": "ea6d525c0c955d90d3dbd29a81ef8bfb79003727",
|
||||||
"signature": null,
|
"signature": null,
|
||||||
|
@ -46,6 +49,7 @@
|
||||||
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001"
|
"pubkey": "030000000000000000000000000000000000000000000000000000000000000001"
|
||||||
},
|
},
|
||||||
"expected": {
|
"expected": {
|
||||||
|
"name": "p2wpkh",
|
||||||
"address": "bc1qz69ej270c3q9qvgt822t6pm3zdksk2x35j2jlm",
|
"address": "bc1qz69ej270c3q9qvgt822t6pm3zdksk2x35j2jlm",
|
||||||
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1",
|
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1",
|
||||||
"output": "OP_0 168b992bcfc44050310b3a94bd0771136d0b28d1",
|
"output": "OP_0 168b992bcfc44050310b3a94bd0771136d0b28d1",
|
||||||
|
@ -61,6 +65,7 @@
|
||||||
"signature": "300602010002010001"
|
"signature": "300602010002010001"
|
||||||
},
|
},
|
||||||
"expected": {
|
"expected": {
|
||||||
|
"name": "p2wpkh",
|
||||||
"address": "bc1qz69ej270c3q9qvgt822t6pm3zdksk2x35j2jlm",
|
"address": "bc1qz69ej270c3q9qvgt822t6pm3zdksk2x35j2jlm",
|
||||||
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1",
|
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1",
|
||||||
"output": "OP_0 168b992bcfc44050310b3a94bd0771136d0b28d1",
|
"output": "OP_0 168b992bcfc44050310b3a94bd0771136d0b28d1",
|
||||||
|
@ -80,6 +85,7 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"expected": {
|
"expected": {
|
||||||
|
"name": "p2wpkh",
|
||||||
"address": "bc1qz69ej270c3q9qvgt822t6pm3zdksk2x35j2jlm",
|
"address": "bc1qz69ej270c3q9qvgt822t6pm3zdksk2x35j2jlm",
|
||||||
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1",
|
"hash": "168b992bcfc44050310b3a94bd0771136d0b28d1",
|
||||||
"output": "OP_0 168b992bcfc44050310b3a94bd0771136d0b28d1",
|
"output": "OP_0 168b992bcfc44050310b3a94bd0771136d0b28d1",
|
||||||
|
|
11
test/fixtures/p2wsh.json
vendored
11
test/fixtures/p2wsh.json
vendored
|
@ -7,6 +7,7 @@
|
||||||
},
|
},
|
||||||
"options": {},
|
"options": {},
|
||||||
"expected": {
|
"expected": {
|
||||||
|
"name": "p2wsh",
|
||||||
"hash": "d0d1f8c5b1815bc471aef4f4720c64ecac38dfa501c0aac94f1434a866a02ae0",
|
"hash": "d0d1f8c5b1815bc471aef4f4720c64ecac38dfa501c0aac94f1434a866a02ae0",
|
||||||
"output": "OP_0 d0d1f8c5b1815bc471aef4f4720c64ecac38dfa501c0aac94f1434a866a02ae0",
|
"output": "OP_0 d0d1f8c5b1815bc471aef4f4720c64ecac38dfa501c0aac94f1434a866a02ae0",
|
||||||
"redeem": null,
|
"redeem": null,
|
||||||
|
@ -20,6 +21,7 @@
|
||||||
"hash": "d0d1f8c5b1815bc471aef4f4720c64ecac38dfa501c0aac94f1434a866a02ae0"
|
"hash": "d0d1f8c5b1815bc471aef4f4720c64ecac38dfa501c0aac94f1434a866a02ae0"
|
||||||
},
|
},
|
||||||
"expected": {
|
"expected": {
|
||||||
|
"name": "p2wsh",
|
||||||
"address": "bc1q6rgl33d3s9dugudw7n68yrryajkr3ha9q8q24j20zs62se4q9tsqdy0t2q",
|
"address": "bc1q6rgl33d3s9dugudw7n68yrryajkr3ha9q8q24j20zs62se4q9tsqdy0t2q",
|
||||||
"output": "OP_0 d0d1f8c5b1815bc471aef4f4720c64ecac38dfa501c0aac94f1434a866a02ae0",
|
"output": "OP_0 d0d1f8c5b1815bc471aef4f4720c64ecac38dfa501c0aac94f1434a866a02ae0",
|
||||||
"redeem": null,
|
"redeem": null,
|
||||||
|
@ -33,6 +35,7 @@
|
||||||
"output": "OP_0 d0d1f8c5b1815bc471aef4f4720c64ecac38dfa501c0aac94f1434a866a02ae0"
|
"output": "OP_0 d0d1f8c5b1815bc471aef4f4720c64ecac38dfa501c0aac94f1434a866a02ae0"
|
||||||
},
|
},
|
||||||
"expected": {
|
"expected": {
|
||||||
|
"name": "p2wsh",
|
||||||
"address": "bc1q6rgl33d3s9dugudw7n68yrryajkr3ha9q8q24j20zs62se4q9tsqdy0t2q",
|
"address": "bc1q6rgl33d3s9dugudw7n68yrryajkr3ha9q8q24j20zs62se4q9tsqdy0t2q",
|
||||||
"hash": "d0d1f8c5b1815bc471aef4f4720c64ecac38dfa501c0aac94f1434a866a02ae0",
|
"hash": "d0d1f8c5b1815bc471aef4f4720c64ecac38dfa501c0aac94f1434a866a02ae0",
|
||||||
"redeem": null,
|
"redeem": null,
|
||||||
|
@ -49,6 +52,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"expected": {
|
"expected": {
|
||||||
|
"name": "p2wsh-p2pkh",
|
||||||
"address": "bc1qusxlgq9quu27ucxs7a2fg8nv0pycdzvxsjk9npyupupxw3y892ss2cq5ar",
|
"address": "bc1qusxlgq9quu27ucxs7a2fg8nv0pycdzvxsjk9npyupupxw3y892ss2cq5ar",
|
||||||
"hash": "e40df400a0e715ee60d0f754941e6c784986898684ac59849c0f026744872aa1",
|
"hash": "e40df400a0e715ee60d0f754941e6c784986898684ac59849c0f026744872aa1",
|
||||||
"output": "OP_0 e40df400a0e715ee60d0f754941e6c784986898684ac59849c0f026744872aa1",
|
"output": "OP_0 e40df400a0e715ee60d0f754941e6c784986898684ac59849c0f026744872aa1",
|
||||||
|
@ -65,6 +69,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"expected": {
|
"expected": {
|
||||||
|
"name": "p2wsh-p2wpkh",
|
||||||
"address": "bc1qpsl7el8wcx22f3fpdt3lm2wmzug7yyx2q3n8wzgtf37kps9tqy7skc7m3e",
|
"address": "bc1qpsl7el8wcx22f3fpdt3lm2wmzug7yyx2q3n8wzgtf37kps9tqy7skc7m3e",
|
||||||
"hash": "0c3fecfceec194a4c5216ae3fda9db1711e210ca046677090b4c7d60c0ab013d",
|
"hash": "0c3fecfceec194a4c5216ae3fda9db1711e210ca046677090b4c7d60c0ab013d",
|
||||||
"output": "OP_0 0c3fecfceec194a4c5216ae3fda9db1711e210ca046677090b4c7d60c0ab013d",
|
"output": "OP_0 0c3fecfceec194a4c5216ae3fda9db1711e210ca046677090b4c7d60c0ab013d",
|
||||||
|
@ -81,6 +86,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"expected": {
|
"expected": {
|
||||||
|
"name": "p2wsh-p2pk",
|
||||||
"address": "bc1q6rgl33d3s9dugudw7n68yrryajkr3ha9q8q24j20zs62se4q9tsqdy0t2q",
|
"address": "bc1q6rgl33d3s9dugudw7n68yrryajkr3ha9q8q24j20zs62se4q9tsqdy0t2q",
|
||||||
"hash": "d0d1f8c5b1815bc471aef4f4720c64ecac38dfa501c0aac94f1434a866a02ae0",
|
"hash": "d0d1f8c5b1815bc471aef4f4720c64ecac38dfa501c0aac94f1434a866a02ae0",
|
||||||
"output": "OP_0 d0d1f8c5b1815bc471aef4f4720c64ecac38dfa501c0aac94f1434a866a02ae0",
|
"output": "OP_0 d0d1f8c5b1815bc471aef4f4720c64ecac38dfa501c0aac94f1434a866a02ae0",
|
||||||
|
@ -97,6 +103,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"expected": {
|
"expected": {
|
||||||
|
"name": "p2wsh-p2pkh",
|
||||||
"address": "bc1qusxlgq9quu27ucxs7a2fg8nv0pycdzvxsjk9npyupupxw3y892ss2cq5ar",
|
"address": "bc1qusxlgq9quu27ucxs7a2fg8nv0pycdzvxsjk9npyupupxw3y892ss2cq5ar",
|
||||||
"hash": "e40df400a0e715ee60d0f754941e6c784986898684ac59849c0f026744872aa1",
|
"hash": "e40df400a0e715ee60d0f754941e6c784986898684ac59849c0f026744872aa1",
|
||||||
"output": "OP_0 e40df400a0e715ee60d0f754941e6c784986898684ac59849c0f026744872aa1",
|
"output": "OP_0 e40df400a0e715ee60d0f754941e6c784986898684ac59849c0f026744872aa1",
|
||||||
|
@ -124,6 +131,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"expected": {
|
"expected": {
|
||||||
|
"name": "p2wsh-p2wpkh",
|
||||||
"address": "bc1qpsl7el8wcx22f3fpdt3lm2wmzug7yyx2q3n8wzgtf37kps9tqy7skc7m3e",
|
"address": "bc1qpsl7el8wcx22f3fpdt3lm2wmzug7yyx2q3n8wzgtf37kps9tqy7skc7m3e",
|
||||||
"hash": "0c3fecfceec194a4c5216ae3fda9db1711e210ca046677090b4c7d60c0ab013d",
|
"hash": "0c3fecfceec194a4c5216ae3fda9db1711e210ca046677090b4c7d60c0ab013d",
|
||||||
"output": "OP_0 0c3fecfceec194a4c5216ae3fda9db1711e210ca046677090b4c7d60c0ab013d",
|
"output": "OP_0 0c3fecfceec194a4c5216ae3fda9db1711e210ca046677090b4c7d60c0ab013d",
|
||||||
|
@ -144,6 +152,7 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"expected": {
|
"expected": {
|
||||||
|
"name": "p2wsh-p2pk",
|
||||||
"address": "bc1q6rgl33d3s9dugudw7n68yrryajkr3ha9q8q24j20zs62se4q9tsqdy0t2q",
|
"address": "bc1q6rgl33d3s9dugudw7n68yrryajkr3ha9q8q24j20zs62se4q9tsqdy0t2q",
|
||||||
"hash": "d0d1f8c5b1815bc471aef4f4720c64ecac38dfa501c0aac94f1434a866a02ae0",
|
"hash": "d0d1f8c5b1815bc471aef4f4720c64ecac38dfa501c0aac94f1434a866a02ae0",
|
||||||
"output": "OP_0 d0d1f8c5b1815bc471aef4f4720c64ecac38dfa501c0aac94f1434a866a02ae0",
|
"output": "OP_0 d0d1f8c5b1815bc471aef4f4720c64ecac38dfa501c0aac94f1434a866a02ae0",
|
||||||
|
@ -167,6 +176,7 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"expected": {
|
"expected": {
|
||||||
|
"name": "p2wsh-p2wpkh",
|
||||||
"address": "bc1qpsl7el8wcx22f3fpdt3lm2wmzug7yyx2q3n8wzgtf37kps9tqy7skc7m3e",
|
"address": "bc1qpsl7el8wcx22f3fpdt3lm2wmzug7yyx2q3n8wzgtf37kps9tqy7skc7m3e",
|
||||||
"hash": "0c3fecfceec194a4c5216ae3fda9db1711e210ca046677090b4c7d60c0ab013d",
|
"hash": "0c3fecfceec194a4c5216ae3fda9db1711e210ca046677090b4c7d60c0ab013d",
|
||||||
"output": "OP_0 0c3fecfceec194a4c5216ae3fda9db1711e210ca046677090b4c7d60c0ab013d",
|
"output": "OP_0 0c3fecfceec194a4c5216ae3fda9db1711e210ca046677090b4c7d60c0ab013d",
|
||||||
|
@ -190,6 +200,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"expected": {
|
"expected": {
|
||||||
|
"name": "p2wsh-p2pkh",
|
||||||
"address": "tb1qusxlgq9quu27ucxs7a2fg8nv0pycdzvxsjk9npyupupxw3y892ssaskm8v",
|
"address": "tb1qusxlgq9quu27ucxs7a2fg8nv0pycdzvxsjk9npyupupxw3y892ssaskm8v",
|
||||||
"hash": "e40df400a0e715ee60d0f754941e6c784986898684ac59849c0f026744872aa1",
|
"hash": "e40df400a0e715ee60d0f754941e6c784986898684ac59849c0f026744872aa1",
|
||||||
"output": "OP_0 e40df400a0e715ee60d0f754941e6c784986898684ac59849c0f026744872aa1",
|
"output": "OP_0 e40df400a0e715ee60d0f754941e6c784986898684ac59849c0f026744872aa1",
|
||||||
|
|
|
@ -41,6 +41,27 @@ const u = require('./payments.utils')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (p === 'p2sh') {
|
||||||
|
const p2wsh = require('../src/payments/p2wsh').p2wsh
|
||||||
|
const p2pk = require('../src/payments/p2pk').p2pk
|
||||||
|
it('properly assembles nested p2wsh with names', () => {
|
||||||
|
const actual = fn({
|
||||||
|
redeem: p2wsh({
|
||||||
|
redeem: p2pk({
|
||||||
|
pubkey: Buffer.from(
|
||||||
|
'03e15819590382a9dd878f01e2f0cbce541564eb415e43b440472d883ecd283058',
|
||||||
|
'hex',
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
assert.strictEqual(actual.address, '3MGbrbye4ttNUXM8WAvBFRKry4fkS9fjuw')
|
||||||
|
assert.strictEqual(actual.name, 'p2sh-p2wsh-p2pk')
|
||||||
|
assert.strictEqual(actual.redeem.name, 'p2wsh-p2pk')
|
||||||
|
assert.strictEqual(actual.redeem.redeem.name, 'p2pk')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// cross-verify dynamically too
|
// cross-verify dynamically too
|
||||||
if (!fixtures.dynamic) return
|
if (!fixtures.dynamic) return
|
||||||
const { depends, details } = fixtures.dynamic
|
const { depends, details } = fixtures.dynamic
|
||||||
|
|
|
@ -29,7 +29,7 @@ export function p2data(a: Payment, opts?: PaymentOpts): Payment {
|
||||||
);
|
);
|
||||||
|
|
||||||
const network = a.network || BITCOIN_NETWORK;
|
const network = a.network || BITCOIN_NETWORK;
|
||||||
const o = { network } as Payment;
|
const o = { name: 'embed', network } as Payment;
|
||||||
|
|
||||||
lazy.prop(o, 'output', () => {
|
lazy.prop(o, 'output', () => {
|
||||||
if (!a.data) return;
|
if (!a.data) return;
|
||||||
|
|
|
@ -8,6 +8,7 @@ import { p2wpkh } from './p2wpkh';
|
||||||
import { p2wsh } from './p2wsh';
|
import { p2wsh } from './p2wsh';
|
||||||
|
|
||||||
export interface Payment {
|
export interface Payment {
|
||||||
|
name?: string;
|
||||||
network?: Network;
|
network?: Network;
|
||||||
output?: Buffer;
|
output?: Buffer;
|
||||||
data?: Buffer[];
|
data?: Buffer[];
|
||||||
|
|
|
@ -102,6 +102,10 @@ export function p2ms(a: Payment, opts?: PaymentOpts): Payment {
|
||||||
if (!o.input) return;
|
if (!o.input) return;
|
||||||
return [];
|
return [];
|
||||||
});
|
});
|
||||||
|
lazy.prop(o, 'name', () => {
|
||||||
|
if (!o.m || !o.n) return;
|
||||||
|
return `p2ms(${o.m} of ${o.n})`;
|
||||||
|
});
|
||||||
|
|
||||||
// extended validation
|
// extended validation
|
||||||
if (opts.validate) {
|
if (opts.validate) {
|
||||||
|
|
|
@ -30,7 +30,7 @@ export function p2pk(a: Payment, opts?: PaymentOpts): Payment {
|
||||||
}) as StackFunction;
|
}) as StackFunction;
|
||||||
|
|
||||||
const network = a.network || BITCOIN_NETWORK;
|
const network = a.network || BITCOIN_NETWORK;
|
||||||
const o: Payment = { network };
|
const o: Payment = { name: 'p2pk', network };
|
||||||
|
|
||||||
lazy.prop(o, 'output', () => {
|
lazy.prop(o, 'output', () => {
|
||||||
if (!a.pubkey) return;
|
if (!a.pubkey) return;
|
||||||
|
|
|
@ -41,7 +41,7 @@ export function p2pkh(a: Payment, opts?: PaymentOpts): Payment {
|
||||||
}) as StackFunction;
|
}) as StackFunction;
|
||||||
|
|
||||||
const network = a.network || BITCOIN_NETWORK;
|
const network = a.network || BITCOIN_NETWORK;
|
||||||
const o: Payment = { network };
|
const o: Payment = { name: 'p2pkh', network };
|
||||||
|
|
||||||
lazy.prop(o, 'address', () => {
|
lazy.prop(o, 'address', () => {
|
||||||
if (!o.hash) return;
|
if (!o.hash) return;
|
||||||
|
|
|
@ -116,6 +116,11 @@ export function p2sh(a: Payment, opts?: PaymentOpts): Payment {
|
||||||
if (o.redeem && o.redeem.witness) return o.redeem.witness;
|
if (o.redeem && o.redeem.witness) return o.redeem.witness;
|
||||||
if (o.input) return [];
|
if (o.input) return [];
|
||||||
});
|
});
|
||||||
|
lazy.prop(o, 'name', () => {
|
||||||
|
const nameParts = ['p2sh'];
|
||||||
|
if (o.redeem !== undefined) nameParts.push(o.redeem.name!);
|
||||||
|
return nameParts.join('-');
|
||||||
|
});
|
||||||
|
|
||||||
if (opts.validate) {
|
if (opts.validate) {
|
||||||
let hash: Buffer = Buffer.from([]);
|
let hash: Buffer = Buffer.from([]);
|
||||||
|
|
|
@ -45,7 +45,7 @@ export function p2wpkh(a: Payment, opts?: PaymentOpts): Payment {
|
||||||
});
|
});
|
||||||
|
|
||||||
const network = a.network || BITCOIN_NETWORK;
|
const network = a.network || BITCOIN_NETWORK;
|
||||||
const o: Payment = { network };
|
const o: Payment = { name: 'p2wpkh', network };
|
||||||
|
|
||||||
lazy.prop(o, 'address', () => {
|
lazy.prop(o, 'address', () => {
|
||||||
if (!o.hash) return;
|
if (!o.hash) return;
|
||||||
|
|
|
@ -116,6 +116,11 @@ export function p2wsh(a: Payment, opts?: PaymentOpts): Payment {
|
||||||
if (!a.redeem.witness) return;
|
if (!a.redeem.witness) return;
|
||||||
return ([] as Buffer[]).concat(a.redeem.witness, a.redeem.output);
|
return ([] as Buffer[]).concat(a.redeem.witness, a.redeem.output);
|
||||||
});
|
});
|
||||||
|
lazy.prop(o, 'name', () => {
|
||||||
|
const nameParts = ['p2wsh'];
|
||||||
|
if (o.redeem !== undefined) nameParts.push(o.redeem.name!);
|
||||||
|
return nameParts.join('-');
|
||||||
|
});
|
||||||
|
|
||||||
// extended validation
|
// extended validation
|
||||||
if (opts.validate) {
|
if (opts.validate) {
|
||||||
|
|
1
types/payments/index.d.ts
vendored
1
types/payments/index.d.ts
vendored
|
@ -8,6 +8,7 @@ import { p2sh } from './p2sh';
|
||||||
import { p2wpkh } from './p2wpkh';
|
import { p2wpkh } from './p2wpkh';
|
||||||
import { p2wsh } from './p2wsh';
|
import { p2wsh } from './p2wsh';
|
||||||
export interface Payment {
|
export interface Payment {
|
||||||
|
name?: string;
|
||||||
network?: Network;
|
network?: Network;
|
||||||
output?: Buffer;
|
output?: Buffer;
|
||||||
data?: Buffer[];
|
data?: Buffer[];
|
||||||
|
|
Loading…
Reference in a new issue