paid-services 3.2.0 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/capacity/accept_capacity_change.js +284 -0
  3. package/capacity/ask_for_change_details.js +505 -0
  4. package/capacity/ask_for_decrease.js +185 -0
  5. package/capacity/assemble_replacement_tx.js +171 -0
  6. package/capacity/capacity_change_requests.js +76 -0
  7. package/capacity/change_channel_capacity.js +183 -0
  8. package/capacity/encode_change_request.js +55 -0
  9. package/capacity/encode_sign_capacity_response.js +32 -0
  10. package/capacity/fee_for_replacement.js +108 -0
  11. package/capacity/finalize_capacity_replacement.js +67 -0
  12. package/capacity/get_capacity_change_requests.js +98 -0
  13. package/capacity/get_capacity_replacement.js +371 -0
  14. package/capacity/get_replacement_signature.js +232 -0
  15. package/capacity/index.js +4 -0
  16. package/capacity/initiate_capacity_change.js +506 -0
  17. package/capacity/interim_replacement_psbt.js +57 -0
  18. package/capacity/is_open_witness_script.js +40 -0
  19. package/capacity/parse_accept_request.js +58 -0
  20. package/capacity/parse_accept_response.js +52 -0
  21. package/capacity/parse_capacity_change_request.js +101 -0
  22. package/capacity/parse_sign_capacity_request.js +59 -0
  23. package/capacity/propose_capacity_change.js +361 -0
  24. package/capacity/service_types.json +6 -0
  25. package/capacity/sign_capacity_replacement.js +119 -0
  26. package/capacity/witness_script_from_close_txs.js +50 -0
  27. package/index.js +2 -0
  28. package/p2p/encode_peer_response.js +0 -1
  29. package/p2p/make_peer_request.js +3 -3
  30. package/package.json +6 -4
  31. package/test/capacity/test_assemble_replacement_tx.js +46 -0
  32. package/test/capacity/test_capacity_change_requests.js +54 -0
  33. package/test/capacity/test_encode_change_request.js +49 -0
  34. package/test/capacity/test_encode_sign_capacity_response.js +47 -0
  35. package/test/capacity/test_fee_for_replacement.js +40 -0
  36. package/test/capacity/test_finalize_capacity_replacement.js +45 -0
  37. package/test/capacity/test_interim_replacement_psbt.js +44 -0
  38. package/test/capacity/test_is_open_witness_script.js +40 -0
  39. package/test/capacity/test_parse_accept_request.js +42 -0
  40. package/test/capacity/test_parse_capacity_change_request.js +51 -0
  41. package/test/capacity/test_parse_sign_capacity_request.js +49 -0
  42. package/test/capacity/test_witness_script_from_close_txs.js +53 -0
  43. package/test/integration/test_accept_capacity_change.js +152 -0
  44. package/test/integration/test_change_channel_capacity.js +196 -0
  45. package/test/integration/test_decrease_channel_capacity.js +206 -0
  46. package/test/integration/test_increase_channel_capacity.js +197 -0
  47. package/test/integration/test_sign_capacity_replacement.js +142 -0
  48. package/test/p2p/test_encode_peer_request.js +53 -0
  49. package/test/p2p/test_encode_peer_response.js +38 -0
  50. package/test/p2p/test_encode_response_code.js +48 -0
  51. package/trades/network_from_network_record.js +6 -0
  52. package/trades/network_record_from_request.js +5 -0
@@ -0,0 +1,50 @@
1
+ const {Transaction} = require('bitcoinjs-lib');
2
+
3
+ const bufferAsHex = buffer => buffer.toString('hex');
4
+ const {fromHex} = Transaction;
5
+ const txIdAsHash = id => Buffer.from(id, 'hex').reverse();
6
+
7
+ /** Find the witness script in the list of transactions
8
+
9
+ {
10
+ closing_tx_id: <Close Channel Transaction Id Hex String>
11
+ transactions: [{
12
+ id: <Transaction Id Hex String>
13
+ [transaction]: <Raw Transaction hex String>
14
+ }]
15
+ transaction_id: <Original Channel Transaction Id Hex String>
16
+ transaction_vout: <Original Channel Transaction Output Index Number>
17
+ }
18
+
19
+ @returns
20
+ {
21
+ script: <Witness Script Hex Encoded String>
22
+ }
23
+ */
24
+ module.exports = args => {
25
+ const closing = args.transactions.find(tx => tx.id === args.closing_tx_id);
26
+
27
+ if (!closing || !closing.transaction) {
28
+ throw new Error('FailedToFindClosingTransactionToReplace');
29
+ }
30
+
31
+ const [{hash, index, witness}, other] = fromHex(closing.transaction).ins;
32
+
33
+ if (!!other) {
34
+ throw new Error('ExpectedSingleInputForClosingTransaction');
35
+ }
36
+
37
+ // The funding outpoint is spent in the closing transaction
38
+ if (index !== args.transaction_vout) {
39
+ throw new Error('ExpectedClosingTxSpendsFundingOutputIndex');
40
+ }
41
+
42
+ if (!hash.equals(txIdAsHash(args.transaction_id))) {
43
+ throw new Error('ExpectedCloseSpendingOpenTransactionId');
44
+ }
45
+
46
+ // The witness script is the final witness stack element
47
+ const [script] = witness.slice().reverse();
48
+
49
+ return {script: bufferAsHex(script)};
50
+ };
package/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ const {changeChannelCapacity} = require('./capacity');
1
2
  const {confirmServiceUse} = require('./client');
2
3
  const {getServiceSchema} = require('./client');
3
4
  const {getServicesList} = require('./client');
@@ -11,6 +12,7 @@ const {servicePeerRequests} = require('./p2p');
11
12
  const serviceIds = schema.types;
12
13
 
13
14
  module.exports = {
15
+ changeChannelCapacity,
14
16
  confirmServiceUse,
15
17
  getServiceSchema,
16
18
  getServicesList,
@@ -6,7 +6,6 @@ const encodeResponseCode = require('./encode_response_code');
6
6
 
7
7
  const headers = null;
8
8
  const params = null;
9
- const present = n => !!n;
10
9
  const version = null;
11
10
 
12
11
  /** Encode a response to a peer
@@ -24,8 +24,8 @@ const makeId = () => randomBytes(32).toString('hex');
24
24
  type: <Request Type Number String>
25
25
  }
26
26
 
27
- @throws error via cbk or Promise
28
- [408, PeerRequestTimeout]
27
+ @throws error via cbk or Promise
28
+ [0, PeerRequestTimeout]
29
29
 
30
30
  @returns via cbk or Promise
31
31
  {
@@ -80,7 +80,7 @@ module.exports = ({lnd, records, timeout, to, type}, cbk) => {
80
80
  return !timeout ? null : setTimeout(() => {
81
81
  sub.removeAllListeners();
82
82
 
83
- return cbk([408, 'PeerRequestTimeout']);
83
+ return cbk([0, 'PeerRequestTimeout']);
84
84
  },
85
85
  timeout);
86
86
  })();
package/package.json CHANGED
@@ -11,7 +11,8 @@
11
11
  "asyncjs-util": "1.2.7",
12
12
  "bolt01": "1.2.3",
13
13
  "invoices": "2.0.2",
14
- "ln-service": "53.1.2"
14
+ "ln-service": "53.2.0",
15
+ "ln-sync": "3.6.0"
15
16
  },
16
17
  "description": "Lightning Paid Services library",
17
18
  "devDependencies": {
@@ -21,7 +22,7 @@
21
22
  "secp256k1": "4.0.2"
22
23
  },
23
24
  "engines": {
24
- "node": ">=12"
25
+ "node": ">=12.20"
25
26
  },
26
27
  "keywords": [
27
28
  "lightning",
@@ -35,7 +36,8 @@
35
36
  "url": "https://github.com/alexbosworth/paid-services.git"
36
37
  },
37
38
  "scripts": {
38
- "test": "tap --branches=1 --functions=1 --lines=1 --statements=1 -t 60 test/actions/*.js test/client/*.js test/config/*.js test/records/*.js test/respond/*.js test/server/*.js test/server/*.js test/services/*.js"
39
+ "integration-tests": "tap --branches=1 --functions=1 --lines=1 --statements=1 -t 120 test/integration/*.js",
40
+ "test": "tap --branches=1 --functions=1 --lines=1 --statements=1 -t 60 test/actions/*.js test/capacity/*.js test/client/*.js test/config/*.js test/p2p/*.js test/records/*.js test/respond/*.js test/server/*.js test/server/*.js test/services/*.js"
39
41
  },
40
- "version": "3.2.0"
42
+ "version": "3.3.0"
41
43
  }
@@ -0,0 +1,46 @@
1
+ const {test} = require('@alexbosworth/tap');
2
+
3
+ const method = require('./../../capacity/assemble_replacement_tx');
4
+
5
+ const makeArgs = overrides => {
6
+ const args = {
7
+ bitcoinjs_network: 'regtest',
8
+ close_transaction: '020000000001015c07d1d67044b91aa50c232d134a2212cd1594e47a0e0c1324e6606511b800f500000000001cc06980024a01000000000000220020b7993cda6e49931239a7c2f34a7ad8bf0b5bf7237674dfacb596418474441ecdb2340f000000000022002053107a1c940c2c9f2d7094de76dcfbcf78951328004cd6391ac20d468f912fb0040047304402201fd0bc7f064d2bd1583f47d9927b73ff56c33c54fb35fec08c0db02510dcf73f02206912c81373ca2827b8a7dd815c6d33db5d4fb327f3cba8518cd87e3a81c08380014830450221009f5683258870e7e755fd9d0826c50b02a4aeec470ace43c2e042dcaf139379fc0220358509d18e2c8c0f485a51e8ed02d479177fc06692b67cb5c025020c9d337fe40147522103a6064236258e646d216aace3afda9d972b052c5c29c2c1c0907d83177675e8b52103acafeb5309c6a437888ccfadb7d06312bf0fca1963fffdfcba9890c4a233e8a652aee14a4320',
9
+ decrease: [],
10
+ funding_address: 'bcrt1qq6xywqkd2z94gwlkcge4n07u3vmg5zn0t5p2ymarcll23rvrtv3q5w9j04',
11
+ funding_tokens: 987247,
12
+ transaction_id: 'f500b8116560e624130c0e7ae49415cd12224a132d230ca51ab94470d6d1075c',
13
+ transaction_vout: 0,
14
+ };
15
+
16
+ Object.keys(overrides).forEach(k => args[k] = overrides[k]);
17
+
18
+ return args;
19
+ };
20
+
21
+ const tests = [
22
+ {
23
+ args: makeArgs({}),
24
+ description: 'Assemble a replacement transaction',
25
+ expected: {
26
+ transaction: '01000000015c07d1d67044b91aa50c232d134a2212cd1594e47a0e0c1324e6606511b800f5000000000000000000016f100f0000000000220020068c4702cd508b543bf6c23359bfdc8b368a0a6f5d02a26fa3c7fea88d835b2200000000',
27
+ transaction_id: '17aba571699841d6ed8cd5d0eea97ea2d439295a2883f12daf36763df63131e3',
28
+ transaction_vin: 0,
29
+ transaction_vout: 0,
30
+ },
31
+ },
32
+ ];
33
+
34
+ tests.forEach(({args, description, error, expected}) => {
35
+ return test(description, async ({end, strictSame, throws}) => {
36
+ if (!!error) {
37
+ throws(() => method(args), new Error(error), 'Got error');
38
+ } else {
39
+ const res = method(args);
40
+
41
+ strictSame(res, expected, 'Got expected result');
42
+ }
43
+
44
+ return end();
45
+ });
46
+ });
@@ -0,0 +1,54 @@
1
+ const {test} = require('@alexbosworth/tap');
2
+
3
+ const method = require('./../../capacity/capacity_change_requests');
4
+
5
+ const makeArgs = overrides => {
6
+ const args = {
7
+ channels: [{
8
+ capacity: 1,
9
+ id: '0x0x0',
10
+ partner_public_key: Buffer.alloc(33, 3).toString('hex'),
11
+ }],
12
+ requests: [{
13
+ channel: '0x0x0',
14
+ from: Buffer.alloc(33, 3).toString('hex'),
15
+ id: Buffer.alloc(32).toString('hex'),
16
+ }],
17
+ };
18
+
19
+ Object.keys(overrides).forEach(k => args[k] = overrides[k]);
20
+
21
+ return args;
22
+ };
23
+
24
+ const tests = [
25
+ {
26
+ args: makeArgs({}),
27
+ description: 'Map change requests to capacity change requests',
28
+ expected: {
29
+ requests: [{
30
+ address: undefined,
31
+ capacity: 1,
32
+ channel: '0x0x0',
33
+ decrease: undefined,
34
+ from: Buffer.alloc(33, 3).toString('hex'),
35
+ id: Buffer.alloc(32).toString('hex'),
36
+ increase: undefined,
37
+ }],
38
+ },
39
+ },
40
+ ];
41
+
42
+ tests.forEach(({args, description, error, expected}) => {
43
+ return test(description, async ({end, strictSame, throws}) => {
44
+ if (!!error) {
45
+ throws(() => method(args), new Error(error), 'Got error');
46
+ } else {
47
+ const res = method(args);
48
+
49
+ strictSame(res, expected, 'Got expected result');
50
+ }
51
+
52
+ return end();
53
+ });
54
+ });
@@ -0,0 +1,49 @@
1
+ const {test} = require('@alexbosworth/tap');
2
+
3
+ const method = require('./../../capacity/encode_change_request');
4
+
5
+ const makeArgs = overrides => {
6
+ const args = {
7
+ channel: '0x0x0',
8
+ decrease: 0,
9
+ id: Buffer.alloc(32).toString('hex'),
10
+ increase: undefined,
11
+ };
12
+
13
+ Object.keys(overrides).forEach(k => args[k] = overrides[k]);
14
+
15
+ return args;
16
+ };
17
+
18
+ const tests = [
19
+ {
20
+ args: makeArgs({}),
21
+ description: 'Encode change request parameters',
22
+ expected: {
23
+ records: [
24
+ {
25
+ type: '1',
26
+ value: '0000000000000000000000000000000000000000000000000000000000000000',
27
+ },
28
+ {
29
+ type: '2',
30
+ value: '0000000000000000',
31
+ },
32
+ ],
33
+ },
34
+ },
35
+ ];
36
+
37
+ tests.forEach(({args, description, error, expected}) => {
38
+ return test(description, async ({end, strictSame, throws}) => {
39
+ if (!!error) {
40
+ throws(() => method(args), new Error(error), 'Got error');
41
+ } else {
42
+ const res = method(args);
43
+
44
+ strictSame(res, expected, 'Got expected result');
45
+ }
46
+
47
+ return end();
48
+ });
49
+ });
@@ -0,0 +1,47 @@
1
+ const {test} = require('@alexbosworth/tap');
2
+
3
+ const method = require('./../../capacity/encode_sign_capacity_response');
4
+
5
+ const makeArgs = overrides => {
6
+ const args = {
7
+ id: Buffer.alloc(32).toString('hex'),
8
+ signature: Buffer.alloc(72).toString('hex'),
9
+ };
10
+
11
+ Object.keys(overrides).forEach(k => args[k] = overrides[k]);
12
+
13
+ return args;
14
+ };
15
+
16
+ const tests = [
17
+ {
18
+ args: makeArgs({}),
19
+ description: 'Encode sign capacity response',
20
+ expected: {
21
+ records: [
22
+ {
23
+ type: '0',
24
+ value: '0000000000000000000000000000000000000000000000000000000000000000',
25
+ },
26
+ {
27
+ type: '1',
28
+ value: '000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
29
+ },
30
+ ],
31
+ },
32
+ },
33
+ ];
34
+
35
+ tests.forEach(({args, description, error, expected}) => {
36
+ return test(description, async ({end, strictSame, throws}) => {
37
+ if (!!error) {
38
+ throws(() => method(args), new Error(error), 'Got error');
39
+ } else {
40
+ const res = method(args);
41
+
42
+ strictSame(res, expected, 'Got expected result');
43
+ }
44
+
45
+ return end();
46
+ });
47
+ });
@@ -0,0 +1,40 @@
1
+ const {test} = require('@alexbosworth/tap');
2
+
3
+ const method = require('./../../capacity/fee_for_replacement');
4
+
5
+ const makeArgs = overrides => {
6
+ const args = {
7
+ capacity: 1e6,
8
+ commit_transaction_fee: 500,
9
+ commit_transaction_weight: 1000,
10
+ decrease: [{output: '00', tokens: 1}],
11
+ increase1: 1,
12
+ tokens_per_vbyte: 1,
13
+ };
14
+
15
+ Object.keys(overrides).forEach(k => args[k] = overrides[k]);
16
+
17
+ return args;
18
+ };
19
+
20
+ const tests = [
21
+ {
22
+ args: makeArgs({}),
23
+ description: 'Calculate fee for replacement tx',
24
+ expected: {fee: 750},
25
+ },
26
+ ];
27
+
28
+ tests.forEach(({args, description, error, expected}) => {
29
+ return test(description, async ({end, strictSame, throws}) => {
30
+ if (!!error) {
31
+ throws(() => method(args), new Error(error), 'Got error');
32
+ } else {
33
+ const res = method(args);
34
+
35
+ strictSame(res, expected, 'Got expected result');
36
+ }
37
+
38
+ return end();
39
+ });
40
+ });
@@ -0,0 +1,45 @@
1
+ const {test} = require('@alexbosworth/tap');
2
+
3
+ const method = require('./../../capacity/finalize_capacity_replacement');
4
+
5
+ const makeArgs = overrides => {
6
+ const args = {
7
+ add_funds_vin: 1,
8
+ add_funds_public_key: '021461d967cd73a0daabfd3307612670a685f875505036fbffe6e8b6ad923b42b4',
9
+ add_funds_signature: '3045022100a2758040f91dafda44b4023f2d3c3c67e5f45cfc0124b3528ab17fe67efc8296022041dcf8fcb7ed7265a51c51bbf2f5256b6e6be99870ca01bd7272ddbdab0b0e58',
10
+ local_public_key: '02aff1b90d7db7d6efc4fce51ab8a862925f5bc1f36a3b481bc78f17c2d2eab6bd',
11
+ local_signature: '3045022100cb108c2828ee90e80aeadbe582fefafcfdecf051d90b64ffd4580c36d212519402200e3460309956f2b0f2104caf6c168d3d9ab8f35729083839bf7f535bb8976143',
12
+ funding_spend_vin: 0,
13
+ remote_signature: '3044022050e76c6cfe9de7cc5e370c26b40ff3538a71efeb8f872e3e1918c1d8efb3bec402207b60ae8486a499a5fb564613970aa9e5f443ad6da1608edff160b61169de91c3',
14
+ transaction: '01000000022f2b7182d7ecec0ff7f5657c6d99c03f7b04044d614e8e851cda7ef99a01b8c80000000000ffffffffc6e674e5f365bdf6b40c21823fee8a9d280f41b71e7b0d8865b0575617b67fb70000000000ffffffff01a31d1200000000002200208331f3c1e41346d1624934cade8330b106f34d7d7159e95cfcceaff1906aecf200000000',
15
+ witness_script: '522102aff1b90d7db7d6efc4fce51ab8a862925f5bc1f36a3b481bc78f17c2d2eab6bd2103f8a30f0d7c65ad71408006d79ee4da62adc9d47b3e752a3ef29c097f3a1e4afc52ae',
16
+ };
17
+
18
+ Object.keys(overrides).forEach(k => args[k] = overrides[k]);
19
+
20
+ return args;
21
+ };
22
+
23
+ const tests = [
24
+ {
25
+ args: makeArgs({}),
26
+ description: 'Finalize a capacity replacement',
27
+ expected: {
28
+ transaction: '010000000001022f2b7182d7ecec0ff7f5657c6d99c03f7b04044d614e8e851cda7ef99a01b8c80000000000ffffffffc6e674e5f365bdf6b40c21823fee8a9d280f41b71e7b0d8865b0575617b67fb70000000000ffffffff01a31d1200000000002200208331f3c1e41346d1624934cade8330b106f34d7d7159e95cfcceaff1906aecf20400483045022100cb108c2828ee90e80aeadbe582fefafcfdecf051d90b64ffd4580c36d212519402200e3460309956f2b0f2104caf6c168d3d9ab8f35729083839bf7f535bb897614301473044022050e76c6cfe9de7cc5e370c26b40ff3538a71efeb8f872e3e1918c1d8efb3bec402207b60ae8486a499a5fb564613970aa9e5f443ad6da1608edff160b61169de91c30147522102aff1b90d7db7d6efc4fce51ab8a862925f5bc1f36a3b481bc78f17c2d2eab6bd2103f8a30f0d7c65ad71408006d79ee4da62adc9d47b3e752a3ef29c097f3a1e4afc52ae02483045022100a2758040f91dafda44b4023f2d3c3c67e5f45cfc0124b3528ab17fe67efc8296022041dcf8fcb7ed7265a51c51bbf2f5256b6e6be99870ca01bd7272ddbdab0b0e580121021461d967cd73a0daabfd3307612670a685f875505036fbffe6e8b6ad923b42b400000000',
29
+ },
30
+ },
31
+ ];
32
+
33
+ tests.forEach(({args, description, error, expected}) => {
34
+ return test(description, async ({end, strictSame, throws}) => {
35
+ if (!!error) {
36
+ throws(() => method(args), new Error(error), 'Got error');
37
+ } else {
38
+ const res = method(args);
39
+
40
+ strictSame(res, expected, 'Got expected result');
41
+ }
42
+
43
+ return end();
44
+ });
45
+ });
@@ -0,0 +1,44 @@
1
+ const {test} = require('@alexbosworth/tap');
2
+
3
+ const method = require('./../../capacity/interim_replacement_psbt');
4
+
5
+ const makeArgs = overrides => {
6
+ const args = {
7
+ increase_public_key: '02f0de5929182b6300d1b3f4b3bd4e3455bb67ff171d9580679848aa140f52c7d0',
8
+ increase_signature: '304402207d3c92e6a512d5167edda7802bf41666196a5133cd299e86be10d84fbc7ca661022024f8f912adc955d3f79f344d52e566284d02161d6b76aa1b70f4ed4a9f25ab2b',
9
+ increase_transaction: '02000000000101003e82436e87b765489f9cb751d4fc274663de11d6ba3df262644b14af42dee60000000000ffffffff02400d03000000000016001421f75e4e4856f78428d064cb4727a5f69dbf2f2c36c9022a01000000160014f31af4302c0136489ece54214340aae4b33463e102483045022100bb39fb591305b4b160424cae3066ac3e73aa3c8b667ffdbfde1de13ed951fec00220196c02d47c051ae407e9072c4c76a0a06c18f4a7022f9a8c704a9aa2a4d34ae901210316acb9cd74b7836aceae5ffdb07cb2ef67ed65eaba2ea270869924036b7de45f00000000',
10
+ increase_transaction_vin: 1,
11
+ open_transaction: '02000000000101edad35ee0a8adb71c44e5d67164d5ccd7a56663645f0eed815d90c50a8c600e90000000000000000000240420f0000000000220020e75299243b0183e4590eb71df6f8aafba7de577ba7f3ff01ec42a82e5e5d97a7eb91f62901000000160014edd4f86b73acd6150895dcecd1aabebf8825db880247304402207a78ce93fbb062fec068b35c2c282e1dbc93d791eaff2ba177a86b8eca96128502207c5f53acf07a865228f776f7f5725c8e72204db9134fdb7b7ef6876bd3f30fe201210316acb9cd74b7836aceae5ffdb07cb2ef67ed65eaba2ea270869924036b7de45f00000000',
12
+ signature: '30450221009e2eeee8c0c9d14b95a4611e4fb83b931325e22dc5939ddc6cc81e1d84e5c51402200ae907b0b681442e327add8fadd3f46710b19880e143d41febdc3fe8decb1a12',
13
+ unsigned_transaction: '01000000026dbdcc66dc7ae49d0bbf7dd6b7c24989f8c510d2c8a8f72978b1eaf5a322d2090000000000ffffffff6f8ad13d8647cd2d00a0147841da0e7bb8439a9c48590ffa7347f86228db3cd70000000000ffffffff01af1d120000000000220020b994281c8afe338fff73a267398542f3f37136ee62db9fb1a8d6db40db1e5a4700000000',
14
+ witness_script: '5221021796f279ccded2657631746376c26c01e45837a8c58e81f9f186fc50581c5733210301117f54de2db419e379fe45e2eeaabd65482d871694be994a6c134ab6475c8a52ae',
15
+ };
16
+
17
+ Object.keys(overrides).forEach(k => args[k] = overrides[k]);
18
+
19
+ return args;
20
+ };
21
+
22
+ const tests = [
23
+ {
24
+ args: makeArgs({}),
25
+ description: 'Create interim replacement PSBT',
26
+ expected: {
27
+ psbt: '70736274ff01008701000000026dbdcc66dc7ae49d0bbf7dd6b7c24989f8c510d2c8a8f72978b1eaf5a322d2090000000000ffffffff6f8ad13d8647cd2d00a0147841da0e7bb8439a9c48590ffa7347f86228db3cd70000000000ffffffff01af1d120000000000220020b994281c8afe338fff73a267398542f3f37136ee62db9fb1a8d6db40db1e5a47000000000001012b40420f0000000000220020e75299243b0183e4590eb71df6f8aafba7de577ba7f3ff01ec42a82e5e5d97a72202021796f279ccded2657631746376c26c01e45837a8c58e81f9f186fc50581c57334830450221009e2eeee8c0c9d14b95a4611e4fb83b931325e22dc5939ddc6cc81e1d84e5c51402200ae907b0b681442e327add8fadd3f46710b19880e143d41febdc3fe8decb1a120122020301117f54de2db419e379fe45e2eeaabd65482d871694be994a6c134ab6475c8a4830450221009e2eeee8c0c9d14b95a4611e4fb83b931325e22dc5939ddc6cc81e1d84e5c51402200ae907b0b681442e327add8fadd3f46710b19880e143d41febdc3fe8decb1a1201010304010000000105475221021796f279ccded2657631746376c26c01e45837a8c58e81f9f186fc50581c5733210301117f54de2db419e379fe45e2eeaabd65482d871694be994a6c134ab6475c8a52ae0001011f400d03000000000016001421f75e4e4856f78428d064cb4727a5f69dbf2f2c220202f0de5929182b6300d1b3f4b3bd4e3455bb67ff171d9580679848aa140f52c7d047304402207d3c92e6a512d5167edda7802bf41666196a5133cd299e86be10d84fbc7ca661022024f8f912adc955d3f79f344d52e566284d02161d6b76aa1b70f4ed4a9f25ab2b01010304010000000000',
28
+ },
29
+ },
30
+ ];
31
+
32
+ tests.forEach(({args, description, error, expected}) => {
33
+ return test(description, async ({end, strictSame, throws}) => {
34
+ if (!!error) {
35
+ throws(() => method(args), new Error(error), 'Got error');
36
+ } else {
37
+ const res = method(args);
38
+
39
+ strictSame(res, expected, 'Got expected result');
40
+ }
41
+
42
+ return end();
43
+ });
44
+ });
@@ -0,0 +1,40 @@
1
+ const {test} = require('@alexbosworth/tap');
2
+
3
+ const method = require('./../../capacity/is_open_witness_script');
4
+
5
+ const makeArgs = overrides => {
6
+ const args = {
7
+ script: '5221034523c886226ad5986c0f27883f1dafe87da27dc0b17ae902aa0c04fe87017cd42103cfbabf006b8be8e2f9782f8a3bacef0641780528e0f75a44b43e302362b27e1f52ae',
8
+ };
9
+
10
+ Object.keys(overrides).forEach(k => args[k] = overrides[k]);
11
+
12
+ return args;
13
+ };
14
+
15
+ const tests = [
16
+ {
17
+ args: makeArgs({}),
18
+ description: 'Test if a witness script is a witness script',
19
+ expected: true,
20
+ },
21
+ {
22
+ args: makeArgs({script: '00'}),
23
+ description: 'Test if a nothing script is a witness script',
24
+ expected: false,
25
+ },
26
+ ];
27
+
28
+ tests.forEach(({args, description, error, expected}) => {
29
+ return test(description, async ({end, strictSame, throws}) => {
30
+ if (!!error) {
31
+ throws(() => method(args), new Error(error), 'Got error');
32
+ } else {
33
+ const res = method(args);
34
+
35
+ strictSame(res, expected, 'Got expected result');
36
+ }
37
+
38
+ return end();
39
+ });
40
+ });
@@ -0,0 +1,42 @@
1
+ const {test} = require('@alexbosworth/tap');
2
+
3
+ const method = require('./../../capacity/parse_accept_request');
4
+
5
+ const makeArgs = overrides => {
6
+ const args = {
7
+ records: [{
8
+ type: '0',
9
+ value: '1cc3b75541a20987ff2308d3c9c92cb8ee9b9975d698f6f82769d2da2596b76f'
10
+ }],
11
+ open_transaction: '02000000000101ddfc0b95d447db6ccef44a4a22d4e38adf570c2e0983f42a01a6e8076e7bb5420000000000000000000240420f00000000002200202e5eae1260152c8b22c27b85b2cee0729754caa1755f614f4779ab8405d4615aeb91f62901000000160014f44f2cbc9cf0b30458402066460d49090a1cdff10247304402201175d52acbcd349f8ea939408bef630be9931d3c6109e9ae2d035af42e012f3502206b00a1d4e9eecff8d3029ba28fa09ccbff9b57280bc521755146d8dd4cb2e00201210364af1cc058d131eab68a08259371348c58a3b2c336d021e8fbe10e19ae8d280b00000000',
12
+ transaction_id: '6e060748f54776964b42f3144965ccf67dab1bf079301f2016684f15fd01846d',
13
+ };
14
+
15
+ Object.keys(overrides).forEach(k => args[k] = overrides[k]);
16
+
17
+ return args;
18
+ };
19
+
20
+ const tests = [
21
+ {
22
+ args: makeArgs({}),
23
+ description: 'Accept requests should be parsed',
24
+ expected: {
25
+ transaction: '02000000000101ddfc0b95d447db6ccef44a4a22d4e38adf570c2e0983f42a01a6e8076e7bb5420000000000000000000240420f00000000002200202e5eae1260152c8b22c27b85b2cee0729754caa1755f614f4779ab8405d4615aeb91f62901000000160014f44f2cbc9cf0b30458402066460d49090a1cdff10247304402201175d52acbcd349f8ea939408bef630be9931d3c6109e9ae2d035af42e012f3502206b00a1d4e9eecff8d3029ba28fa09ccbff9b57280bc521755146d8dd4cb2e00201210364af1cc058d131eab68a08259371348c58a3b2c336d021e8fbe10e19ae8d280b00000000',
26
+ },
27
+ },
28
+ ];
29
+
30
+ tests.forEach(({args, description, error, expected}) => {
31
+ return test(description, async ({end, strictSame, throws}) => {
32
+ if (!!error) {
33
+ throws(() => method(args), new Error(error), 'Got error');
34
+ } else {
35
+ const res = method(args);
36
+
37
+ strictSame(res, expected, 'Got expected result');
38
+ }
39
+
40
+ return end();
41
+ });
42
+ });
@@ -0,0 +1,51 @@
1
+ const {test} = require('@alexbosworth/tap');
2
+
3
+ const method = require('./../../capacity/parse_capacity_change_request');
4
+
5
+ const makeArgs = overrides => {
6
+ const args = {
7
+ from: '0218819f4e0dbab6c6bc434913bace0b69f20d832f68934acd72fc610a9b76fe30',
8
+ records: [
9
+ {
10
+ type: '1',
11
+ value: '2bf4a6bf1b97aff5bbb760f1aa7a5705c885194b4e29d42e5576498107f02361',
12
+ },
13
+ {
14
+ type: '2',
15
+ value: '0000660000010000',
16
+ },
17
+ ],
18
+ };
19
+
20
+ Object.keys(overrides).forEach(k => args[k] = overrides[k]);
21
+
22
+ return args;
23
+ };
24
+
25
+ const tests = [
26
+ {
27
+ args: makeArgs({}),
28
+ description: 'A capacity change request should be parsed',
29
+ expected: {
30
+ request: {
31
+ channel: '102x1x0',
32
+ from: '0218819f4e0dbab6c6bc434913bace0b69f20d832f68934acd72fc610a9b76fe30',
33
+ id: '2bf4a6bf1b97aff5bbb760f1aa7a5705c885194b4e29d42e5576498107f02361',
34
+ },
35
+ },
36
+ },
37
+ ];
38
+
39
+ tests.forEach(({args, description, error, expected}) => {
40
+ return test(description, async ({end, strictSame, throws}) => {
41
+ if (!!error) {
42
+ throws(() => method(args), new Error(error), 'Got error');
43
+ } else {
44
+ const res = method(args);
45
+
46
+ strictSame(res, expected, 'Got expected result');
47
+ }
48
+
49
+ return end();
50
+ });
51
+ });
@@ -0,0 +1,49 @@
1
+ const {test} = require('@alexbosworth/tap');
2
+
3
+ const method = require('./../../capacity/parse_sign_capacity_request');
4
+
5
+ const makeArgs = overrides => {
6
+ const args = {
7
+ id: 'b213832d9ab1d735c42bda931e5be603141f379d05142a40fc1af8e7536cdbaf',
8
+ increase: undefined,
9
+ records: [
10
+ {
11
+ type: '0',
12
+ value: '9e6e9f9ed56c38e0e01d896b6188a050cde7fa48314f533c85156b35abd0b0fd',
13
+ },
14
+ {
15
+ type: '1',
16
+ value: '0100000001afdb6c53e7f81afc402a14059d371f1403e65b1e93da2bc435d7b19a2d8313b2000000000000000000016f100f00000000002200209c0b6154fc22ead29dc861cdbd135245c615a806b5268eb34f8e8d4f4225784200000000',
17
+ },
18
+ ],
19
+ vout: 0,
20
+ };
21
+
22
+ Object.keys(overrides).forEach(k => args[k] = overrides[k]);
23
+
24
+ return args;
25
+ };
26
+
27
+ const tests = [
28
+ {
29
+ args: makeArgs({}),
30
+ description: 'Parse a sign capacity change request',
31
+ expected: {
32
+ unsigned: '0100000001afdb6c53e7f81afc402a14059d371f1403e65b1e93da2bc435d7b19a2d8313b2000000000000000000016f100f00000000002200209c0b6154fc22ead29dc861cdbd135245c615a806b5268eb34f8e8d4f4225784200000000',
33
+ },
34
+ },
35
+ ];
36
+
37
+ tests.forEach(({args, description, error, expected}) => {
38
+ return test(description, async ({end, strictSame, throws}) => {
39
+ if (!!error) {
40
+ throws(() => method(args), new Error(error), 'Got error');
41
+ } else {
42
+ const res = method(args);
43
+
44
+ strictSame(res, expected, 'Got expected result');
45
+ }
46
+
47
+ return end();
48
+ });
49
+ });