From a3a88025ab91ed622df86a5e08edfcbcd6ed2836 Mon Sep 17 00:00:00 2001 From: theanmolsharma Date: Sat, 7 Oct 2023 12:55:01 +0530 Subject: [PATCH] refactor: move tests to a seperate folder Signed-off-by: theanmolsharma --- jest.config.ts | 2 +- src/encoding.spec.ts | 93 ----- src/outputs.spec.ts | 752 -------------------------------------- src/scanning.spec.ts | 451 ----------------------- src/utility.spec.ts | 136 ------- test/encoding.spec.ts | 44 +++ test/fixtures/encoding.ts | 56 +++ test/fixtures/outputs.ts | 722 ++++++++++++++++++++++++++++++++++++ test/fixtures/scanning.ts | 416 +++++++++++++++++++++ test/fixtures/utility.ts | 117 ++++++ test/outputs.spec.ts | 32 ++ test/scanning.spec.ts | 37 ++ test/utility.spec.ts | 23 ++ 13 files changed, 1448 insertions(+), 1433 deletions(-) delete mode 100644 src/encoding.spec.ts delete mode 100644 src/outputs.spec.ts delete mode 100644 src/scanning.spec.ts delete mode 100644 src/utility.spec.ts create mode 100644 test/encoding.spec.ts create mode 100644 test/fixtures/encoding.ts create mode 100644 test/fixtures/outputs.ts create mode 100644 test/fixtures/scanning.ts create mode 100644 test/fixtures/utility.ts create mode 100644 test/outputs.spec.ts create mode 100644 test/scanning.spec.ts create mode 100644 test/utility.spec.ts diff --git a/jest.config.ts b/jest.config.ts index dfdfb50..43bbc6c 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -3,7 +3,7 @@ module.exports = { verbose: true, testEnvironment: 'node', rootDir: '.', - roots: ['/src/'], + roots: ['/test/'], testRegex: '.*\\.spec\\.ts$', transform: { '^.+\\.(t|j)s$': 'ts-jest', diff --git a/src/encoding.spec.ts b/src/encoding.spec.ts deleted file mode 100644 index 3a1454c..0000000 --- a/src/encoding.spec.ts +++ /dev/null @@ -1,93 +0,0 @@ -import { - createLabeledSilentPaymentAddress, - decodeSilentPaymentAddress, - encodeSilentPaymentAddress, -} from './encoding'; -import { Buffer } from 'buffer'; - -describe('Encoding', () => { - describe.each([ - { - scanKey: - '03b4cc0b090b6f49a684558852db60ee5eb1c5f74352839c3d18a8fc04ef7354e0', - spendKey: - '03bc95144daf15336db3456825c70ced0a4462f89aca42c4921ee7ccb2b3a44796', - address: - 'sp1qqw6vczcfpdh5nf5y2ky99kmqae0tr30hgdfg88parz50cp80wd2wqqauj52ymtc4xdkmx3tgyhrsemg2g3303xk2gtzfy8h8ejet8fz8jcw23zua', - }, - { - scanKey: - '03b4cc0b090b6f49a684558852db60ee5eb1c5f74352839c3d18a8fc04ef7354e0', - spendKey: - '03ffa54be08548c0eb8d81eca4d8ff18fca4a0eda4fd0a80fb1b663e947dd81d99', - address: - 'sp1qqw6vczcfpdh5nf5y2ky99kmqae0tr30hgdfg88parz50cp80wd2wqqll5497pp2gcr4cmq0v5nv07x8u5jswmf8ap2q0kxmx8628mkqanyu63ck8', - }, - { - scanKey: - '0220bcfac5b99e04ad1a06ddfb016ee13582609d60b6291e98d01a9bc9a16c96d4', - spendKey: - '025cc9856d6f8375350e123978daac200c260cb5b5ae83106cab90484dcd8fcf36', - address: - 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv', - }, - ])('Encode/Decode SP', (data) => { - it('should encode scan and spend key to silent payment address', () => { - expect( - encodeSilentPaymentAddress( - Buffer.from(data.scanKey, 'hex'), - Buffer.from(data.spendKey, 'hex'), - 'sp', - ), - ).toBe(data.address); - }); - - it('should decode scan and spend key from silent payment address', () => { - expect( - decodeSilentPaymentAddress(data.address, 'sp'), - ).toStrictEqual({ - scanKey: Buffer.from(data.scanKey, 'hex'), - spendKey: Buffer.from(data.spendKey, 'hex'), - }); - }); - }); - - it.each([ - { - scanKey: - '0220bcfac5b99e04ad1a06ddfb016ee13582609d60b6291e98d01a9bc9a16c96d4', - spendKey: - '025cc9856d6f8375350e123978daac200c260cb5b5ae83106cab90484dcd8fcf36', - label: '0000000000000000000000000000000000000000000000000000000000000001', - address: - 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqah4hxfsjdwyaeel4g8x2npkj7qlvf2692l5760z5ut0ggnlrhdzsy3cvsj', - }, - { - scanKey: - '0220bcfac5b99e04ad1a06ddfb016ee13582609d60b6291e98d01a9bc9a16c96d4', - spendKey: - '025cc9856d6f8375350e123978daac200c260cb5b5ae83106cab90484dcd8fcf36', - label: '0000000000000000000000000000000000000000000000000000000000000539', - address: - 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgq562yg7htxyg8eq60rl37uul37jy62apnf5ru62uef0eajpdfrnp5cmqndj', - }, - { - scanKey: - '03b4cc0b090b6f49a684558852db60ee5eb1c5f74352839c3d18a8fc04ef7354e0', - spendKey: - '03bc95144daf15336db3456825c70ced0a4462f89aca42c4921ee7ccb2b3a44796', - label: '91cb04398a508c9d995ff4a18e5eae24d5e9488309f189120a3fdbb977978c46', - address: - 'sp1qqw6vczcfpdh5nf5y2ky99kmqae0tr30hgdfg88parz50cp80wd2wqqll5497pp2gcr4cmq0v5nv07x8u5jswmf8ap2q0kxmx8628mkqanyu63ck8', - }, - ])('should create a labeled silent payment address', (data) => { - expect( - createLabeledSilentPaymentAddress( - Buffer.from(data.scanKey, 'hex'), - Buffer.from(data.spendKey, 'hex'), - Buffer.from(data.label, 'hex'), - 'sp', - ), - ).toBe(data.address); - }); -}); diff --git a/src/outputs.spec.ts b/src/outputs.spec.ts deleted file mode 100644 index 43adbd7..0000000 --- a/src/outputs.spec.ts +++ /dev/null @@ -1,752 +0,0 @@ -import { Outpoint, PrivateKey, RecipientAddress } from './interface'; -import { createOutputs } from './outputs'; - -describe('Outputs', () => { - it.each([ - { - privateKeys: [ - { - key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', - isXOnly: false, - }, - { - key: '93f5ed907ad5b2bdbbdcb5d9116ebc0a4e1f92f910d5260237fa45a9408aad16', - isXOnly: false, - }, - ], - outpoints: [ - { - txid: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', - vout: 0, - }, - { - txid: 'a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d', - vout: 0, - }, - ], - recipientAddresses: [ - { - address: - 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv', - amount: 0.1, - }, - ], - expected: [ - { - pubkey: '0239a1e5ff6206cd316151b9b34cee4f80bb48ce61adee0a12ce7ff05ea436a1d9', - value: 0.1, - }, - ], - }, - { - privateKeys: [ - { - key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', - isXOnly: false, - }, - { - key: '93f5ed907ad5b2bdbbdcb5d9116ebc0a4e1f92f910d5260237fa45a9408aad16', - isXOnly: false, - }, - ], - outpoints: [ - { - txid: 'a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d', - vout: 0, - }, - { - txid: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', - vout: 0, - }, - ], - recipientAddresses: [ - { - address: - 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv', - amount: 0.1, - }, - ], - expected: [ - { - pubkey: '0239a1e5ff6206cd316151b9b34cee4f80bb48ce61adee0a12ce7ff05ea436a1d9', - value: 0.1, - }, - ], - }, - { - privateKeys: [ - { - key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', - isXOnly: false, - }, - { - key: '93f5ed907ad5b2bdbbdcb5d9116ebc0a4e1f92f910d5260237fa45a9408aad16', - isXOnly: false, - }, - ], - outpoints: [ - { - txid: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', - vout: 3, - }, - { - txid: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', - vout: 7, - }, - ], - recipientAddresses: [ - { - address: - 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv', - amount: 0.1, - }, - ], - expected: [ - { - pubkey: '03162f2298705b3ddca01ce1d214eedff439df3927582938d08e29e464908db00b', - value: 0.1, - }, - ], - }, - { - privateKeys: [ - { - key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', - isXOnly: false, - }, - { - key: '93f5ed907ad5b2bdbbdcb5d9116ebc0a4e1f92f910d5260237fa45a9408aad16', - isXOnly: false, - }, - ], - outpoints: [ - { - txid: 'a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d', - vout: 7, - }, - { - txid: 'a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d', - vout: 3, - }, - ], - recipientAddresses: [ - { - address: - 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv', - amount: 0.1, - }, - ], - expected: [ - { - pubkey: '02d9ede52f7e1e64e36ccf895ca0250daad96b174987079c903519b17852b21a3f', - value: 0.1, - }, - ], - }, - { - privateKeys: [ - { - key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', - isXOnly: false, - }, - { - key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', - isXOnly: false, - }, - ], - outpoints: [ - { - txid: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', - vout: 0, - }, - { - txid: 'a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d', - vout: 0, - }, - ], - recipientAddresses: [ - { - address: - 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv', - amount: 0.1, - }, - ], - expected: [ - { - pubkey: '020aafdcdb5893ae813299b16eea75f34ec16653ac39171da04d7c4e6d2e09ab8e', - value: 0.1, - }, - ], - }, - { - privateKeys: [ - { - key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', - isXOnly: true, - }, - { - key: 'fc8716a97a48ba9a05a98ae47b5cd201a25a7fd5d8b73c203c5f7b6b6b3b6ad7', - isXOnly: true, - }, - ], - outpoints: [ - { - txid: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', - vout: 0, - }, - { - txid: 'a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d', - vout: 0, - }, - ], - recipientAddresses: [ - { - address: - 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv', - amount: 0.1, - }, - ], - expected: [ - { - pubkey: '0215d1dfe4403791509cf47f073be2eb3277decabe90da395e63b1f49a09fe965e', - value: 0.1, - }, - ], - }, - { - privateKeys: [ - { - key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', - isXOnly: true, - }, - { - key: '0378e95685b74565fa56751b84a32dfd18545d10d691641b8372e32164fad66a', - isXOnly: true, - }, - ], - outpoints: [ - { - txid: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', - vout: 0, - }, - { - txid: 'a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d', - vout: 0, - }, - ], - recipientAddresses: [ - { - address: - 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv', - amount: 0.1, - }, - ], - expected: [ - { - pubkey: '0215d1dfe4403791509cf47f073be2eb3277decabe90da395e63b1f49a09fe965e', - value: 0.1, - }, - ], - }, - { - privateKeys: [ - { - key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', - isXOnly: true, - }, - { - key: '8d4751f6e8a3586880fb66c19ae277969bd5aa06f61c4ee2f1e2486efdf666d3', - isXOnly: false, - }, - ], - outpoints: [ - { - txid: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', - vout: 0, - }, - { - txid: 'a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d', - vout: 0, - }, - ], - recipientAddresses: [ - { - address: - 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv', - amount: 0.1, - }, - ], - expected: [ - { - pubkey: '032b4ff8e5bc608cbdd12117171e7d265b6882ad597559caf67b5ecfaf15301dd0', - value: 0.1, - }, - ], - }, - { - privateKeys: [ - { - key: '0378e95685b74565fa56751b84a32dfd18545d10d691641b8372e32164fad66a', - isXOnly: true, - }, - { - key: '8d4751f6e8a3586880fb66c19ae277969bd5aa06f61c4ee2f1e2486efdf666d3', - isXOnly: false, - }, - ], - outpoints: [ - { - txid: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', - vout: 0, - }, - { - txid: 'a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d', - vout: 0, - }, - ], - recipientAddresses: [ - { - address: - 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv', - amount: 0.1, - }, - ], - expected: [ - { - pubkey: '0275f501f319db549aaa613717bd7af44da566d4d859b67fe436946564fafc47a3', - value: 0.1, - }, - ], - }, - { - privateKeys: [ - { - key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', - isXOnly: false, - }, - { - key: '0378e95685b74565fa56751b84a32dfd18545d10d691641b8372e32164fad66a', - isXOnly: false, - }, - ], - outpoints: [ - { - txid: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', - vout: 0, - }, - { - txid: 'a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d', - vout: 0, - }, - ], - recipientAddresses: [ - { - address: - 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv', - amount: 0.1, - }, - { - address: - 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv', - amount: 0.2, - }, - ], - expected: [ - { - pubkey: '0264f1c7e8992352d18cdbca600b9e1c3a6025050d56a3e1cc833222e4f3b59e18', - value: 0.1, - }, - { - pubkey: '030a48c6ccc1d516e8244dc0153dc88db45f8f264357667c2057a29ca3c2445d09', - value: 0.2, - }, - ], - }, - { - privateKeys: [ - { - key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', - isXOnly: false, - }, - { - key: '0378e95685b74565fa56751b84a32dfd18545d10d691641b8372e32164fad66a', - isXOnly: false, - }, - ], - outpoints: [ - { - txid: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', - vout: 0, - }, - { - txid: 'a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d', - vout: 0, - }, - ], - recipientAddresses: [ - { - address: - 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv', - amount: 0.1, - }, - { - address: - 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv', - amount: 0.2, - }, - { - address: - 'sp1qqgrz6j0lcqnc04vxccydl0kpsj4frfje0ktmgcl2t346hkw30226xqupawdf48k8882j0strrvcmgg2kdawz53a54dd376ngdhak364hzcmynqtn', - amount: 0.3, - }, - { - address: - 'sp1qqgrz6j0lcqnc04vxccydl0kpsj4frfje0ktmgcl2t346hkw30226xqupawdf48k8882j0strrvcmgg2kdawz53a54dd376ngdhak364hzcmynqtn', - amount: 0.4, - }, - ], - expected: [ - { - pubkey: '0264f1c7e8992352d18cdbca600b9e1c3a6025050d56a3e1cc833222e4f3b59e18', - value: 0.1, - }, - { - pubkey: '030a48c6ccc1d516e8244dc0153dc88db45f8f264357667c2057a29ca3c2445d09', - value: 0.2, - }, - { - pubkey: '02c58e121044b23cba9b4695052229a9fd9e044b579f92864eb886ae7c99b021c9', - value: 0.3, - }, - { - pubkey: '034b15b75f3f184328c4a2f7c79357481ed06cf3b6f95512d5ed946fdc0b60d62b', - value: 0.4, - }, - ], - }, - { - privateKeys: [ - { - key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', - isXOnly: false, - }, - { - key: '0378e95685b74565fa56751b84a32dfd18545d10d691641b8372e32164fad66a', - isXOnly: false, - }, - ], - outpoints: [ - { - txid: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', - vout: 0, - }, - { - txid: 'a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d', - vout: 0, - }, - ], - recipientAddresses: [ - { - address: - 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqhmem6grvs4nacsu0v5v5mjs934j7qfgkdkj8c95gyuru3tjpulvcwky2dz', - amount: 0.1, - }, - ], - expected: [ - { - pubkey: '022cbceeab2a4982841eb7dc34b8b4f19c04bf3bc083ebf984f5664366778eb50f', - value: 0.1, - }, - ], - }, - { - privateKeys: [ - { - key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', - isXOnly: false, - }, - { - key: '0378e95685b74565fa56751b84a32dfd18545d10d691641b8372e32164fad66a', - isXOnly: false, - }, - ], - outpoints: [ - { - txid: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', - vout: 0, - }, - { - txid: 'a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d', - vout: 0, - }, - ], - recipientAddresses: [ - { - address: - 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqc389f45lq7jyqt8jxq6fkskfukr2tlruf6w8cpcx2krntwe4fr9ykagp3j', - amount: 0.1, - }, - ], - expected: [ - { - pubkey: '036b4455de119f51bf4d4a12dea555f14a5dc2c1369af5fba4871c5367264c028d', - value: 0.1, - }, - ], - }, - { - privateKeys: [ - { - key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', - isXOnly: false, - }, - { - key: '0378e95685b74565fa56751b84a32dfd18545d10d691641b8372e32164fad66a', - isXOnly: false, - }, - ], - outpoints: [ - { - txid: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', - vout: 0, - }, - { - txid: 'a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d', - vout: 0, - }, - ], - recipientAddresses: [ - { - address: - 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgq4umqa5feskydh9xadc9jlc22c89tu0apcv72u2vkuwtsrgzf0uesq45zq9', - amount: 0.1, - }, - ], - expected: [ - { - pubkey: '03c3473bfcbe5e4d20d0790ae91f1b339bc15b46de64ca068d140118d0e325b849', - value: 0.1, - }, - ], - }, - { - privateKeys: [ - { - key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', - isXOnly: false, - }, - { - key: '0378e95685b74565fa56751b84a32dfd18545d10d691641b8372e32164fad66a', - isXOnly: false, - }, - ], - outpoints: [ - { - txid: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', - vout: 0, - }, - { - txid: 'a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d', - vout: 0, - }, - ], - recipientAddresses: [ - { - address: - 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv', - amount: 0.1, - }, - { - address: - 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqah4hxfsjdwyaeel4g8x2npkj7qlvf2692l5760z5ut0ggnlrhdzsy3cvsj', - amount: 0.2, - }, - ], - expected: [ - { - pubkey: '0264f1c7e8992352d18cdbca600b9e1c3a6025050d56a3e1cc833222e4f3b59e18', - value: 0.1, - }, - { - pubkey: '027956317130124c32afd07b3f2432a3e92c1447cf58da95491a307ae3d564535e', - value: 0.2, - }, - ], - }, - { - privateKeys: [ - { - key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', - isXOnly: false, - }, - { - key: '0378e95685b74565fa56751b84a32dfd18545d10d691641b8372e32164fad66a', - isXOnly: false, - }, - ], - outpoints: [ - { - txid: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', - vout: 0, - }, - { - txid: 'a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d', - vout: 0, - }, - ], - recipientAddresses: [ - { - address: - 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqah4hxfsjdwyaeel4g8x2npkj7qlvf2692l5760z5ut0ggnlrhdzsy3cvsj', - amount: 0.1, - }, - { - address: - 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqah4hxfsjdwyaeel4g8x2npkj7qlvf2692l5760z5ut0ggnlrhdzsy3cvsj', - amount: 0.2, - }, - ], - expected: [ - { - pubkey: '038890c19f005d6f6add5fef92d37ac6b161b7fdd5c1aef6eed1d32be3f216ac4c', - value: 0.1, - }, - { - pubkey: '027956317130124c32afd07b3f2432a3e92c1447cf58da95491a307ae3d564535e', - value: 0.2, - }, - ], - }, - { - privateKeys: [ - { - key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', - isXOnly: false, - }, - { - key: '0378e95685b74565fa56751b84a32dfd18545d10d691641b8372e32164fad66a', - isXOnly: false, - }, - ], - outpoints: [ - { - txid: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', - vout: 0, - }, - { - txid: 'a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d', - vout: 0, - }, - ], - recipientAddresses: [ - { - address: - 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv', - amount: 0.1, - }, - { - address: - 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqah4hxfsjdwyaeel4g8x2npkj7qlvf2692l5760z5ut0ggnlrhdzsy3cvsj', - amount: 0.2, - }, - { - address: - 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgq562yg7htxyg8eq60rl37uul37jy62apnf5ru62uef0eajpdfrnp5cmqndj', - amount: 0.3, - }, - { - address: - 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgq562yg7htxyg8eq60rl37uul37jy62apnf5ru62uef0eajpdfrnp5cmqndj', - amount: 0.4, - }, - ], - expected: [ - { - pubkey: '0264f1c7e8992352d18cdbca600b9e1c3a6025050d56a3e1cc833222e4f3b59e18', - value: 0.1, - }, - { - pubkey: '027956317130124c32afd07b3f2432a3e92c1447cf58da95491a307ae3d564535e', - value: 0.2, - }, - { - pubkey: '031b90a42136fef9ff2ca192abffc7be4536dc83d4e61cf18ae078f7e92b297cce', - value: 0.3, - }, - { - pubkey: '0287a82600c08a255bc97d172e10816e322967eed6a77c9f37dd926492d7fdc106', - value: 0.4, - }, - ], - }, - { - privateKeys: [ - { - key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', - isXOnly: false, - }, - { - key: '0378e95685b74565fa56751b84a32dfd18545d10d691641b8372e32164fad66a', - isXOnly: false, - }, - ], - outpoints: [ - { - txid: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', - vout: 0, - }, - { - txid: 'a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d', - vout: 0, - }, - ], - recipientAddresses: [ - { - address: - 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv', - amount: 0.1, - }, - { - address: - 'sp1qqw6vczcfpdh5nf5y2ky99kmqae0tr30hgdfg88parz50cp80wd2wqqll5497pp2gcr4cmq0v5nv07x8u5jswmf8ap2q0kxmx8628mkqanyu63ck8', - amount: 0.2, - }, - ], - expected: [ - { - pubkey: '0264f1c7e8992352d18cdbca600b9e1c3a6025050d56a3e1cc833222e4f3b59e18', - value: 0.1, - }, - { - pubkey: '020050c52a32566c0dfb517e473c68fedce4bd4543d219348d3bbdceeeb5755e34', - value: 0.2, - }, - ], - }, - ])( - 'should create silent payments public keys', - (data: { - privateKeys: PrivateKey[]; - outpoints: Outpoint[]; - recipientAddresses: RecipientAddress[]; - expected: { pubkey: string; value: number }[]; - }) => { - const outputs = createOutputs( - data.privateKeys, - data.outpoints, - data.recipientAddresses, - 'sp', - ); - expect( - outputs - .map((output) => ({ - pubkey: output.pubkey.toString('hex'), - value: output.value, - })) - .sort((a, b) => a.pubkey.localeCompare(b.pubkey)), - ).toStrictEqual( - data.expected.sort((a, b) => a.pubkey.localeCompare(b.pubkey)), - ); - }, - ); -}); diff --git a/src/scanning.spec.ts b/src/scanning.spec.ts deleted file mode 100644 index b81d4ba..0000000 --- a/src/scanning.spec.ts +++ /dev/null @@ -1,451 +0,0 @@ -import { scanOutputs } from './scanning'; -import { LabelMap } from './interface'; -import { Buffer } from 'buffer'; - -describe('Scanning', () => { - it.each([ - { - scanPrivateKey: - '0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c', - spendPublicKey: - '025cc9856d6f8375350e123978daac200c260cb5b5ae83106cab90484dcd8fcf36', - sumOfInputPublicKeys: - '032562c1ab2d6bd45d7ca4d78f569999e5333dffd3ac5263924fd00d00dedc4bee', - outpointHash: - '210fef5d624db17c965c7597e2c6c9f60ef440c831d149c43567c50158557f12', - outputs: [ - '0239a1e5ff6206cd316151b9b34cee4f80bb48ce61adee0a12ce7ff05ea436a1d9', - ], - matches: { - '0239a1e5ff6206cd316151b9b34cee4f80bb48ce61adee0a12ce7ff05ea436a1d9': - '8e4bbee712779f746337cadf39e8b1eab8e8869dd40f2e3a7281113e858ffc0b', - }, - }, - { - scanPrivateKey: - '0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c', - spendPublicKey: - '025cc9856d6f8375350e123978daac200c260cb5b5ae83106cab90484dcd8fcf36', - sumOfInputPublicKeys: - '032562c1ab2d6bd45d7ca4d78f569999e5333dffd3ac5263924fd00d00dedc4bee', - outpointHash: - '210fef5d624db17c965c7597e2c6c9f60ef440c831d149c43567c50158557f12', - outputs: [ - '0239a1e5ff6206cd316151b9b34cee4f80bb48ce61adee0a12ce7ff05ea436a1d9', - ], - matches: { - '0239a1e5ff6206cd316151b9b34cee4f80bb48ce61adee0a12ce7ff05ea436a1d9': - '8e4bbee712779f746337cadf39e8b1eab8e8869dd40f2e3a7281113e858ffc0b', - }, - }, - { - scanPrivateKey: - '0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c', - spendPublicKey: - '025cc9856d6f8375350e123978daac200c260cb5b5ae83106cab90484dcd8fcf36', - sumOfInputPublicKeys: - '032562c1ab2d6bd45d7ca4d78f569999e5333dffd3ac5263924fd00d00dedc4bee', - outpointHash: - 'dd7d2a8678cb65b52119af415b578437f5dfc0d9f5bf2daac5e25c21bf0731ce', - outputs: [ - '02162f2298705b3ddca01ce1d214eedff439df3927582938d08e29e464908db00b', - ], - matches: { - '02162f2298705b3ddca01ce1d214eedff439df3927582938d08e29e464908db00b': - 'f06d8d90561bdbc3e511c3bec7355ad3c858aaf38a132c772d6cd82ec04102ac', - }, - }, - { - scanPrivateKey: - '0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c', - spendPublicKey: - '025cc9856d6f8375350e123978daac200c260cb5b5ae83106cab90484dcd8fcf36', - sumOfInputPublicKeys: - '032562c1ab2d6bd45d7ca4d78f569999e5333dffd3ac5263924fd00d00dedc4bee', - outpointHash: - '1b85dfe15f0d5e1cedd47bdd70c24ecb0e3401c0a2ace659c422916626b66bce', - outputs: [ - '02d9ede52f7e1e64e36ccf895ca0250daad96b174987079c903519b17852b21a3f', - ], - matches: { - '02d9ede52f7e1e64e36ccf895ca0250daad96b174987079c903519b17852b21a3f': - '44b827516c2128287b1d571add7cfeb42f122e86bc40b4eb2b21ac144607fdb2', - }, - }, - { - scanPrivateKey: - '0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c', - spendPublicKey: - '025cc9856d6f8375350e123978daac200c260cb5b5ae83106cab90484dcd8fcf36', - sumOfInputPublicKeys: - '03e40664e222ba71e29b80efc907fa22a3c6c64f45e89dbb8511dc7a3712b0a186', - outpointHash: - '210fef5d624db17c965c7597e2c6c9f60ef440c831d149c43567c50158557f12', - outputs: [ - '020aafdcdb5893ae813299b16eea75f34ec16653ac39171da04d7c4e6d2e09ab8e', - ], - matches: { - '020aafdcdb5893ae813299b16eea75f34ec16653ac39171da04d7c4e6d2e09ab8e': - 'bf7336bdc02f624715aab385cc62b71f6f494bf8a7dd0fd621cfd365039c39d1', - }, - }, - { - scanPrivateKey: - '0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c', - spendPublicKey: - '025cc9856d6f8375350e123978daac200c260cb5b5ae83106cab90484dcd8fcf36', - sumOfInputPublicKeys: - '038180a2125f9d6dd116e1a6139be4d72fd5057dab6aaabaa5654817c11baeb3ba', - outpointHash: - '210fef5d624db17c965c7597e2c6c9f60ef440c831d149c43567c50158557f12', - outputs: [ - '0215d1dfe4403791509cf47f073be2eb3277decabe90da395e63b1f49a09fe965e', - ], - matches: { - '0215d1dfe4403791509cf47f073be2eb3277decabe90da395e63b1f49a09fe965e': - '0734de077e436e8f6f125e16287cb60dead8ebddc8532be3589ba27156f1add2', - }, - }, - { - scanPrivateKey: - '0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c', - spendPublicKey: - '025cc9856d6f8375350e123978daac200c260cb5b5ae83106cab90484dcd8fcf36', - sumOfInputPublicKeys: - '038180a2125f9d6dd116e1a6139be4d72fd5057dab6aaabaa5654817c11baeb3ba', - outpointHash: - '210fef5d624db17c965c7597e2c6c9f60ef440c831d149c43567c50158557f12', - outputs: [ - '0215d1dfe4403791509cf47f073be2eb3277decabe90da395e63b1f49a09fe965e', - ], - matches: { - '0215d1dfe4403791509cf47f073be2eb3277decabe90da395e63b1f49a09fe965e': - '0734de077e436e8f6f125e16287cb60dead8ebddc8532be3589ba27156f1add2', - }, - }, - { - scanPrivateKey: - '0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c', - spendPublicKey: - '025cc9856d6f8375350e123978daac200c260cb5b5ae83106cab90484dcd8fcf36', - sumOfInputPublicKeys: - '031ecda9c64faaa6cd57c9f3d7c62bcfc0763c2627ed8dc0e2c3018e9ff37a0bf0', - outpointHash: - '210fef5d624db17c965c7597e2c6c9f60ef440c831d149c43567c50158557f12', - outputs: [ - '022b4ff8e5bc608cbdd12117171e7d265b6882ad597559caf67b5ecfaf15301dd0', - ], - matches: { - '022b4ff8e5bc608cbdd12117171e7d265b6882ad597559caf67b5ecfaf15301dd0': - '17d93733d2acd8388279c24dc4413483802378c99f266f5961ac3338c5146861', - }, - }, - { - scanPrivateKey: - '0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c', - spendPublicKey: - '025cc9856d6f8375350e123978daac200c260cb5b5ae83106cab90484dcd8fcf36', - sumOfInputPublicKeys: - '02ef85ee8dc78102f2fd062d3b321f0b4527f0b954ed14b93b0090c8514c9b6a03', - outpointHash: - '210fef5d624db17c965c7597e2c6c9f60ef440c831d149c43567c50158557f12', - outputs: [ - '0275f501f319db549aaa613717bd7af44da566d4d859b67fe436946564fafc47a3', - ], - matches: { - '0275f501f319db549aaa613717bd7af44da566d4d859b67fe436946564fafc47a3': - '619a5a59a16d4a8e857ef48e63ef7c8195c858191d4e826205e8438ab70d059e', - }, - }, - { - scanPrivateKey: - '0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c', - spendPublicKey: - '025cc9856d6f8375350e123978daac200c260cb5b5ae83106cab90484dcd8fcf36', - sumOfInputPublicKeys: - '03853f51bef283502181e93238c8708ae27235dc51ae45a0c4053987c52fc6428b', - outpointHash: - '210fef5d624db17c965c7597e2c6c9f60ef440c831d149c43567c50158557f12', - outputs: [ - '0264f1c7e8992352d18cdbca600b9e1c3a6025050d56a3e1cc833222e4f3b59e18', - '020a48c6ccc1d516e8244dc0153dc88db45f8f264357667c2057a29ca3c2445d09', - '02c58e121044b23cba9b4695052229a9fd9e044b579f92864eb886ae7c99b021c9', - '024b15b75f3f184328c4a2f7c79357481ed06cf3b6f95512d5ed946fdc0b60d62b', - ], - matches: { - '0264f1c7e8992352d18cdbca600b9e1c3a6025050d56a3e1cc833222e4f3b59e18': - '96439446f13ddaab2c5bc5a59a08992fd9d33bf8563c8a1b362730f4dc022e30', - '020a48c6ccc1d516e8244dc0153dc88db45f8f264357667c2057a29ca3c2445d09': - 'd39df91bd0e7825bfa1d30096febc5bf6fa7da79d7f25b7b4bea9538cc9a9f7f', - }, - }, - { - scanPrivateKey: - '0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c', - spendPublicKey: - '025cc9856d6f8375350e123978daac200c260cb5b5ae83106cab90484dcd8fcf36', - sumOfInputPublicKeys: - '03853f51bef283502181e93238c8708ae27235dc51ae45a0c4053987c52fc6428b', - outpointHash: - '210fef5d624db17c965c7597e2c6c9f60ef440c831d149c43567c50158557f12', - outputs: [ - '0264f1c7e8992352d18cdbca600b9e1c3a6025050d56a3e1cc833222e4f3b59e18', - '020a48c6ccc1d516e8244dc0153dc88db45f8f264357667c2057a29ca3c2445d09', - '02c58e121044b23cba9b4695052229a9fd9e044b579f92864eb886ae7c99b021c9', - '024b15b75f3f184328c4a2f7c79357481ed06cf3b6f95512d5ed946fdc0b60d62b', - ], - matches: { - '0264f1c7e8992352d18cdbca600b9e1c3a6025050d56a3e1cc833222e4f3b59e18': - '96439446f13ddaab2c5bc5a59a08992fd9d33bf8563c8a1b362730f4dc022e30', - '020a48c6ccc1d516e8244dc0153dc88db45f8f264357667c2057a29ca3c2445d09': - 'd39df91bd0e7825bfa1d30096febc5bf6fa7da79d7f25b7b4bea9538cc9a9f7f', - }, - }, - { - scanPrivateKey: - '060b751d7892149006ed7b98606955a29fe284a1e900070c0971f5fb93dbf422', - spendPublicKey: - '0381eb9a9a9ec739d527c1631b31b421566f5c2a47b4ab5b1f6a686dfb68eab716', - sumOfInputPublicKeys: - '03853f51bef283502181e93238c8708ae27235dc51ae45a0c4053987c52fc6428b', - outpointHash: - '210fef5d624db17c965c7597e2c6c9f60ef440c831d149c43567c50158557f12', - outputs: [ - '0264f1c7e8992352d18cdbca600b9e1c3a6025050d56a3e1cc833222e4f3b59e18', - '020a48c6ccc1d516e8244dc0153dc88db45f8f264357667c2057a29ca3c2445d09', - '02c58e121044b23cba9b4695052229a9fd9e044b579f92864eb886ae7c99b021c9', - '024b15b75f3f184328c4a2f7c79357481ed06cf3b6f95512d5ed946fdc0b60d62b', - ], - matches: { - '02c58e121044b23cba9b4695052229a9fd9e044b579f92864eb886ae7c99b021c9': - '567710d07bdaacc8de3f1cec467bcb162ed7daa6b901b59af257bcd7e39dffcf', - '024b15b75f3f184328c4a2f7c79357481ed06cf3b6f95512d5ed946fdc0b60d62b': - '25dd11163a9a2853709c4c837aafb3347e2eaa875cf4c5170e2a3663879f4c58', - }, - }, - { - scanPrivateKey: - '0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c', - spendPublicKey: - '025cc9856d6f8375350e123978daac200c260cb5b5ae83106cab90484dcd8fcf36', - sumOfInputPublicKeys: - '03853f51bef283502181e93238c8708ae27235dc51ae45a0c4053987c52fc6428b', - outpointHash: - '210fef5d624db17c965c7597e2c6c9f60ef440c831d149c43567c50158557f12', - outputs: [ - '0264f1c7e8992352d18cdbca600b9e1c3a6025050d56a3e1cc833222e4f3b59e18', - '020050c52a32566c0dfb517e473c68fedce4bd4543d219348d3bbdceeeb5755e34', - ], - matches: { - '0264f1c7e8992352d18cdbca600b9e1c3a6025050d56a3e1cc833222e4f3b59e18': - '96439446f13ddaab2c5bc5a59a08992fd9d33bf8563c8a1b362730f4dc022e30', - }, - }, - { - scanPrivateKey: - '0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c', - spendPublicKey: - '025cc9856d6f8375350e123978daac200c260cb5b5ae83106cab90484dcd8fcf36', - sumOfInputPublicKeys: - '03853f51bef283502181e93238c8708ae27235dc51ae45a0c4053987c52fc6428b', - outpointHash: - '210fef5d624db17c965c7597e2c6c9f60ef440c831d149c43567c50158557f12', - outputs: [ - '022cbceeab2a4982841eb7dc34b8b4f19c04bf3bc083ebf984f5664366778eb50f', - ], - labels: { - '02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5': - '0000000000000000000000000000000000000000000000000000000000000002', - '02f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9': - '0000000000000000000000000000000000000000000000000000000000000003', - '03348b4f5feb64b557dac8cfa10044bdc2094fca9147163bf514f68687e0d1dba6': - '00000000000000000000000000000000000000000000000000000000000f4779', - }, - matches: { - '022cbceeab2a4982841eb7dc34b8b4f19c04bf3bc083ebf984f5664366778eb50f': - '96439446f13ddaab2c5bc5a59a08992fd9d33bf8563c8a1b362730f4dc022e32', - }, - }, - { - scanPrivateKey: - '0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c', - spendPublicKey: - '025cc9856d6f8375350e123978daac200c260cb5b5ae83106cab90484dcd8fcf36', - sumOfInputPublicKeys: - '03853f51bef283502181e93238c8708ae27235dc51ae45a0c4053987c52fc6428b', - outpointHash: - '210fef5d624db17c965c7597e2c6c9f60ef440c831d149c43567c50158557f12', - outputs: [ - '026b4455de119f51bf4d4a12dea555f14a5dc2c1369af5fba4871c5367264c028d', - ], - labels: { - '02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5': - '0000000000000000000000000000000000000000000000000000000000000002', - '02f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9': - '0000000000000000000000000000000000000000000000000000000000000003', - '03348b4f5feb64b557dac8cfa10044bdc2094fca9147163bf514f68687e0d1dba6': - '00000000000000000000000000000000000000000000000000000000000f4779', - }, - matches: { - '026b4455de119f51bf4d4a12dea555f14a5dc2c1369af5fba4871c5367264c028d': - '96439446f13ddaab2c5bc5a59a08992fd9d33bf8563c8a1b362730f4dc022e33', - }, - }, - { - scanPrivateKey: - '0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c', - spendPublicKey: - '025cc9856d6f8375350e123978daac200c260cb5b5ae83106cab90484dcd8fcf36', - sumOfInputPublicKeys: - '03853f51bef283502181e93238c8708ae27235dc51ae45a0c4053987c52fc6428b', - outpointHash: - '210fef5d624db17c965c7597e2c6c9f60ef440c831d149c43567c50158557f12', - outputs: [ - '02c3473bfcbe5e4d20d0790ae91f1b339bc15b46de64ca068d140118d0e325b849', - ], - labels: { - '02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5': - '0000000000000000000000000000000000000000000000000000000000000002', - '02f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9': - '0000000000000000000000000000000000000000000000000000000000000003', - '03348b4f5feb64b557dac8cfa10044bdc2094fca9147163bf514f68687e0d1dba6': - '00000000000000000000000000000000000000000000000000000000000f4779', - }, - matches: { - '02c3473bfcbe5e4d20d0790ae91f1b339bc15b46de64ca068d140118d0e325b849': - '96439446f13ddaab2c5bc5a59a08992fd9d33bf8563c8a1b362730f4dc1175a9', - }, - }, - { - scanPrivateKey: - '0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c', - spendPublicKey: - '025cc9856d6f8375350e123978daac200c260cb5b5ae83106cab90484dcd8fcf36', - sumOfInputPublicKeys: - '03853f51bef283502181e93238c8708ae27235dc51ae45a0c4053987c52fc6428b', - outpointHash: - '210fef5d624db17c965c7597e2c6c9f60ef440c831d149c43567c50158557f12', - outputs: [ - '0264f1c7e8992352d18cdbca600b9e1c3a6025050d56a3e1cc833222e4f3b59e18', - '027956317130124c32afd07b3f2432a3e92c1447cf58da95491a307ae3d564535e', - ], - labels: { - '0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798': - '0000000000000000000000000000000000000000000000000000000000000001', - }, - matches: { - '0264f1c7e8992352d18cdbca600b9e1c3a6025050d56a3e1cc833222e4f3b59e18': - '96439446f13ddaab2c5bc5a59a08992fd9d33bf8563c8a1b362730f4dc022e30', - '027956317130124c32afd07b3f2432a3e92c1447cf58da95491a307ae3d564535e': - 'd39df91bd0e7825bfa1d30096febc5bf6fa7da79d7f25b7b4bea9538cc9a9f80', - }, - }, - { - scanPrivateKey: - '0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c', - spendPublicKey: - '025cc9856d6f8375350e123978daac200c260cb5b5ae83106cab90484dcd8fcf36', - sumOfInputPublicKeys: - '03853f51bef283502181e93238c8708ae27235dc51ae45a0c4053987c52fc6428b', - outpointHash: - '210fef5d624db17c965c7597e2c6c9f60ef440c831d149c43567c50158557f12', - outputs: [ - '028890c19f005d6f6add5fef92d37ac6b161b7fdd5c1aef6eed1d32be3f216ac4c', - '027956317130124c32afd07b3f2432a3e92c1447cf58da95491a307ae3d564535e', - ], - labels: { - '0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798': - '0000000000000000000000000000000000000000000000000000000000000001', - }, - matches: { - '028890c19f005d6f6add5fef92d37ac6b161b7fdd5c1aef6eed1d32be3f216ac4c': - '96439446f13ddaab2c5bc5a59a08992fd9d33bf8563c8a1b362730f4dc022e31', - '027956317130124c32afd07b3f2432a3e92c1447cf58da95491a307ae3d564535e': - 'd39df91bd0e7825bfa1d30096febc5bf6fa7da79d7f25b7b4bea9538cc9a9f80', - }, - }, - { - scanPrivateKey: - '0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c', - spendPublicKey: - '025cc9856d6f8375350e123978daac200c260cb5b5ae83106cab90484dcd8fcf36', - sumOfInputPublicKeys: - '03853f51bef283502181e93238c8708ae27235dc51ae45a0c4053987c52fc6428b', - outpointHash: - '210fef5d624db17c965c7597e2c6c9f60ef440c831d149c43567c50158557f12', - outputs: [ - '0264f1c7e8992352d18cdbca600b9e1c3a6025050d56a3e1cc833222e4f3b59e18', - '027956317130124c32afd07b3f2432a3e92c1447cf58da95491a307ae3d564535e', - '021b90a42136fef9ff2ca192abffc7be4536dc83d4e61cf18ae078f7e92b297cce', - '0287a82600c08a255bc97d172e10816e322967eed6a77c9f37dd926492d7fdc106', - ], - labels: { - '0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798': - '0000000000000000000000000000000000000000000000000000000000000001', - '02db0c51cc634a4096374b0b895584a3ca2fb3bea4fd0ee2361f8db63a650fcee6': - '0000000000000000000000000000000000000000000000000000000000000539', - }, - matches: { - '0264f1c7e8992352d18cdbca600b9e1c3a6025050d56a3e1cc833222e4f3b59e18': - '96439446f13ddaab2c5bc5a59a08992fd9d33bf8563c8a1b362730f4dc022e30', - '027956317130124c32afd07b3f2432a3e92c1447cf58da95491a307ae3d564535e': - 'd39df91bd0e7825bfa1d30096febc5bf6fa7da79d7f25b7b4bea9538cc9a9f80', - '021b90a42136fef9ff2ca192abffc7be4536dc83d4e61cf18ae078f7e92b297cce': - '255a912ad6cdebc0842d49fd9f7b2d81ee37d66c62839879371b699010f78ef1', - '0287a82600c08a255bc97d172e10816e322967eed6a77c9f37dd926492d7fdc106': - 'd7535d792cb1388ab0b3bd5ff57337436d62f7719c1796beb5d80ab2fa34f307', - }, - }, - { - scanPrivateKey: - '11b7a82e06ca2648d5fded2366478078ec4fc9dc1d8ff487518226f229d768fd', - spendPublicKey: - '03bc95144daf15336db3456825c70ced0a4462f89aca42c4921ee7ccb2b3a44796', - sumOfInputPublicKeys: - '03853f51bef283502181e93238c8708ae27235dc51ae45a0c4053987c52fc6428b', - outpointHash: - '210fef5d624db17c965c7597e2c6c9f60ef440c831d149c43567c50158557f12', - outputs: [ - '0264f1c7e8992352d18cdbca600b9e1c3a6025050d56a3e1cc833222e4f3b59e18', - '020050c52a32566c0dfb517e473c68fedce4bd4543d219348d3bbdceeeb5755e34', - ], - labels: { - '02295dc38e877b754c0d0ed767434f1572cf34a82ccc06ffea1d9e04f1f7878e1a': - '91cb04398a508c9d995ff4a18e5eae24d5e9488309f189120a3fdbb977978c46', - }, - matches: { - '020050c52a32566c0dfb517e473c68fedce4bd4543d219348d3bbdceeeb5755e34': - '2e9c2a37cfa7827907d36357f0632d258dbd14b3a7854937ecf732fb6acefdc8', - }, - }, - ])( - 'should pass', - ({ - scanPrivateKey, - spendPublicKey, - sumOfInputPublicKeys, - outpointHash, - outputs, - labels, - matches, - }) => { - const result = scanOutputs( - Buffer.from(scanPrivateKey, 'hex'), - Buffer.from(spendPublicKey, 'hex'), - Buffer.from(sumOfInputPublicKeys, 'hex'), - Buffer.from(outpointHash, 'hex'), - outputs.map((output) => Buffer.from(output, 'hex')), - labels as unknown as LabelMap, - ); - - expect(result).toStrictEqual( - new Map( - Object.entries(matches).map(([output, tweak]) => [ - output, - Buffer.from(tweak as string, 'hex'), - ]), - ), - ); - }, - ); -}); diff --git a/src/utility.spec.ts b/src/utility.spec.ts deleted file mode 100644 index 04e8d33..0000000 --- a/src/utility.spec.ts +++ /dev/null @@ -1,136 +0,0 @@ -import { Outpoint, PrivateKey } from './interface'; -import { calculateSumOfPrivateKeys, hashOutpoints } from './utility'; - -describe('Utility', () => { - it.each([ - { - outpoints: [ - { - txid: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', - vout: 0, - }, - { - txid: 'a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d', - vout: 0, - }, - ], - expected: - '210fef5d624db17c965c7597e2c6c9f60ef440c831d149c43567c50158557f12', - }, - { - outpoints: [ - { - txid: 'a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d', - vout: 7, - }, - { - txid: 'a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d', - vout: 3, - }, - ], - expected: - '1b85dfe15f0d5e1cedd47bdd70c24ecb0e3401c0a2ace659c422916626b66bce', - }, - { - outpoints: [ - { - txid: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', - vout: 3, - }, - { - txid: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', - vout: 7, - }, - ], - expected: - 'dd7d2a8678cb65b52119af415b578437f5dfc0d9f5bf2daac5e25c21bf0731ce', - }, - ])( - 'should calculate hash of outpoints in tx', - (data: { outpoints: Outpoint[]; expected: string }) => { - const { outpoints, expected } = data; - const hash = hashOutpoints(outpoints); - expect(hash.toString('hex')).toBe(expected); - }, - ); - - it.each([ - { - keys: [ - { - key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', - isXOnly: false, - }, - { - key: '93f5ed907ad5b2bdbbdcb5d9116ebc0a4e1f92f910d5260237fa45a9408aad16', - isXOnly: false, - }, - ], - expected: - '7ed265a6dac7aba8508a32d6d6b84c7f1dbd0a0941dd01088d69e8d556345f86', - }, - { - keys: [ - { - key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', - isXOnly: true, - }, - { - key: 'fc8716a97a48ba9a05a98ae47b5cd201a25a7fd5d8b73c203c5f7b6b6b3b6ad7', - isXOnly: true, - }, - ], - expected: - 'e7638ebfda3ab3849a5707e240a6627671f7f6e609bf172691cf1e9780e51d47', - }, - { - keys: [ - { - key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', - isXOnly: false, - }, - { - key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', - isXOnly: false, - }, - ], - expected: - 'd5b8f02cbfe3f1d5295af9fb8a9320e859e9cb07115856486ab1a4e4fb89a621', - }, - { - keys: [ - { - key: '0378e95685b74565fa56751b84a32dfd18545d10d691641b8372e32164fad66a', - isXOnly: true, - }, - { - key: '8d4751f6e8a3586880fb66c19ae277969bd5aa06f61c4ee2f1e2486efdf666d3', - isXOnly: false, - }, - ], - expected: - '89ce68a062ec130286a4f1a6163f499983814cf61f8aeac76e6f654d98fb9069', - }, - { - keys: [ - { - key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', - isXOnly: false, - }, - { - key: '0378e95685b74565fa56751b84a32dfd18545d10d691641b8372e32164fad66a', - isXOnly: false, - }, - ], - expected: - 'ee55616ce5a93e508f03f21949ecbe70a2a0b107b6e1df5d98b4e4da4adaca1b', - }, - ])( - 'should calculate sum of private keys', - async (data: { keys: PrivateKey[]; expected: string }) => { - const { keys, expected } = data; - const sum = calculateSumOfPrivateKeys(keys); - expect(sum.toString('hex')).toBe(expected); - }, - ); -}); diff --git a/test/encoding.spec.ts b/test/encoding.spec.ts new file mode 100644 index 0000000..a58a711 --- /dev/null +++ b/test/encoding.spec.ts @@ -0,0 +1,44 @@ +import { + createLabeledSilentPaymentAddress, + decodeSilentPaymentAddress, + encodeSilentPaymentAddress, +} from '../src/encoding'; +import { Buffer } from 'buffer'; +import { unlabelled, labelled } from './fixtures/encoding'; + +describe('Encoding', () => { + describe.each(unlabelled)('Encode/Decode SP', (data) => { + it('should encode scan and spend key to silent payment address', () => { + expect( + encodeSilentPaymentAddress( + Buffer.from(data.scanKey, 'hex'), + Buffer.from(data.spendKey, 'hex'), + 'sp', + ), + ).toBe(data.address); + }); + + it('should decode scan and spend key from silent payment address', () => { + expect( + decodeSilentPaymentAddress(data.address, 'sp'), + ).toStrictEqual({ + scanKey: Buffer.from(data.scanKey, 'hex'), + spendKey: Buffer.from(data.spendKey, 'hex'), + }); + }); + }); + + it.each(labelled)( + 'should create a labeled silent payment address', + (data) => { + expect( + createLabeledSilentPaymentAddress( + Buffer.from(data.scanKey, 'hex'), + Buffer.from(data.spendKey, 'hex'), + Buffer.from(data.label, 'hex'), + 'sp', + ), + ).toBe(data.address); + }, + ); +}); diff --git a/test/fixtures/encoding.ts b/test/fixtures/encoding.ts new file mode 100644 index 0000000..7cdaa53 --- /dev/null +++ b/test/fixtures/encoding.ts @@ -0,0 +1,56 @@ +export const unlabelled = [ + { + scanKey: + '03b4cc0b090b6f49a684558852db60ee5eb1c5f74352839c3d18a8fc04ef7354e0', + spendKey: + '03bc95144daf15336db3456825c70ced0a4462f89aca42c4921ee7ccb2b3a44796', + address: + 'sp1qqw6vczcfpdh5nf5y2ky99kmqae0tr30hgdfg88parz50cp80wd2wqqauj52ymtc4xdkmx3tgyhrsemg2g3303xk2gtzfy8h8ejet8fz8jcw23zua', + }, + { + scanKey: + '03b4cc0b090b6f49a684558852db60ee5eb1c5f74352839c3d18a8fc04ef7354e0', + spendKey: + '03ffa54be08548c0eb8d81eca4d8ff18fca4a0eda4fd0a80fb1b663e947dd81d99', + address: + 'sp1qqw6vczcfpdh5nf5y2ky99kmqae0tr30hgdfg88parz50cp80wd2wqqll5497pp2gcr4cmq0v5nv07x8u5jswmf8ap2q0kxmx8628mkqanyu63ck8', + }, + { + scanKey: + '0220bcfac5b99e04ad1a06ddfb016ee13582609d60b6291e98d01a9bc9a16c96d4', + spendKey: + '025cc9856d6f8375350e123978daac200c260cb5b5ae83106cab90484dcd8fcf36', + address: + 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv', + }, +]; + +export const labelled = [ + { + scanKey: + '0220bcfac5b99e04ad1a06ddfb016ee13582609d60b6291e98d01a9bc9a16c96d4', + spendKey: + '025cc9856d6f8375350e123978daac200c260cb5b5ae83106cab90484dcd8fcf36', + label: '0000000000000000000000000000000000000000000000000000000000000001', + address: + 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqah4hxfsjdwyaeel4g8x2npkj7qlvf2692l5760z5ut0ggnlrhdzsy3cvsj', + }, + { + scanKey: + '0220bcfac5b99e04ad1a06ddfb016ee13582609d60b6291e98d01a9bc9a16c96d4', + spendKey: + '025cc9856d6f8375350e123978daac200c260cb5b5ae83106cab90484dcd8fcf36', + label: '0000000000000000000000000000000000000000000000000000000000000539', + address: + 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgq562yg7htxyg8eq60rl37uul37jy62apnf5ru62uef0eajpdfrnp5cmqndj', + }, + { + scanKey: + '03b4cc0b090b6f49a684558852db60ee5eb1c5f74352839c3d18a8fc04ef7354e0', + spendKey: + '03bc95144daf15336db3456825c70ced0a4462f89aca42c4921ee7ccb2b3a44796', + label: '91cb04398a508c9d995ff4a18e5eae24d5e9488309f189120a3fdbb977978c46', + address: + 'sp1qqw6vczcfpdh5nf5y2ky99kmqae0tr30hgdfg88parz50cp80wd2wqqll5497pp2gcr4cmq0v5nv07x8u5jswmf8ap2q0kxmx8628mkqanyu63ck8', + }, +]; diff --git a/test/fixtures/outputs.ts b/test/fixtures/outputs.ts new file mode 100644 index 0000000..7fb5784 --- /dev/null +++ b/test/fixtures/outputs.ts @@ -0,0 +1,722 @@ +export const testData = [ + { + privateKeys: [ + { + key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', + isXOnly: false, + }, + { + key: '93f5ed907ad5b2bdbbdcb5d9116ebc0a4e1f92f910d5260237fa45a9408aad16', + isXOnly: false, + }, + ], + outpoints: [ + { + txid: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', + vout: 0, + }, + { + txid: 'a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d', + vout: 0, + }, + ], + recipientAddresses: [ + { + address: + 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv', + amount: 0.1, + }, + ], + expected: [ + { + pubkey: '0239a1e5ff6206cd316151b9b34cee4f80bb48ce61adee0a12ce7ff05ea436a1d9', + value: 0.1, + }, + ], + }, + { + privateKeys: [ + { + key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', + isXOnly: false, + }, + { + key: '93f5ed907ad5b2bdbbdcb5d9116ebc0a4e1f92f910d5260237fa45a9408aad16', + isXOnly: false, + }, + ], + outpoints: [ + { + txid: 'a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d', + vout: 0, + }, + { + txid: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', + vout: 0, + }, + ], + recipientAddresses: [ + { + address: + 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv', + amount: 0.1, + }, + ], + expected: [ + { + pubkey: '0239a1e5ff6206cd316151b9b34cee4f80bb48ce61adee0a12ce7ff05ea436a1d9', + value: 0.1, + }, + ], + }, + { + privateKeys: [ + { + key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', + isXOnly: false, + }, + { + key: '93f5ed907ad5b2bdbbdcb5d9116ebc0a4e1f92f910d5260237fa45a9408aad16', + isXOnly: false, + }, + ], + outpoints: [ + { + txid: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', + vout: 3, + }, + { + txid: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', + vout: 7, + }, + ], + recipientAddresses: [ + { + address: + 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv', + amount: 0.1, + }, + ], + expected: [ + { + pubkey: '03162f2298705b3ddca01ce1d214eedff439df3927582938d08e29e464908db00b', + value: 0.1, + }, + ], + }, + { + privateKeys: [ + { + key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', + isXOnly: false, + }, + { + key: '93f5ed907ad5b2bdbbdcb5d9116ebc0a4e1f92f910d5260237fa45a9408aad16', + isXOnly: false, + }, + ], + outpoints: [ + { + txid: 'a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d', + vout: 7, + }, + { + txid: 'a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d', + vout: 3, + }, + ], + recipientAddresses: [ + { + address: + 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv', + amount: 0.1, + }, + ], + expected: [ + { + pubkey: '02d9ede52f7e1e64e36ccf895ca0250daad96b174987079c903519b17852b21a3f', + value: 0.1, + }, + ], + }, + { + privateKeys: [ + { + key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', + isXOnly: false, + }, + { + key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', + isXOnly: false, + }, + ], + outpoints: [ + { + txid: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', + vout: 0, + }, + { + txid: 'a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d', + vout: 0, + }, + ], + recipientAddresses: [ + { + address: + 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv', + amount: 0.1, + }, + ], + expected: [ + { + pubkey: '020aafdcdb5893ae813299b16eea75f34ec16653ac39171da04d7c4e6d2e09ab8e', + value: 0.1, + }, + ], + }, + { + privateKeys: [ + { + key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', + isXOnly: true, + }, + { + key: 'fc8716a97a48ba9a05a98ae47b5cd201a25a7fd5d8b73c203c5f7b6b6b3b6ad7', + isXOnly: true, + }, + ], + outpoints: [ + { + txid: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', + vout: 0, + }, + { + txid: 'a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d', + vout: 0, + }, + ], + recipientAddresses: [ + { + address: + 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv', + amount: 0.1, + }, + ], + expected: [ + { + pubkey: '0215d1dfe4403791509cf47f073be2eb3277decabe90da395e63b1f49a09fe965e', + value: 0.1, + }, + ], + }, + { + privateKeys: [ + { + key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', + isXOnly: true, + }, + { + key: '0378e95685b74565fa56751b84a32dfd18545d10d691641b8372e32164fad66a', + isXOnly: true, + }, + ], + outpoints: [ + { + txid: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', + vout: 0, + }, + { + txid: 'a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d', + vout: 0, + }, + ], + recipientAddresses: [ + { + address: + 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv', + amount: 0.1, + }, + ], + expected: [ + { + pubkey: '0215d1dfe4403791509cf47f073be2eb3277decabe90da395e63b1f49a09fe965e', + value: 0.1, + }, + ], + }, + { + privateKeys: [ + { + key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', + isXOnly: true, + }, + { + key: '8d4751f6e8a3586880fb66c19ae277969bd5aa06f61c4ee2f1e2486efdf666d3', + isXOnly: false, + }, + ], + outpoints: [ + { + txid: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', + vout: 0, + }, + { + txid: 'a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d', + vout: 0, + }, + ], + recipientAddresses: [ + { + address: + 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv', + amount: 0.1, + }, + ], + expected: [ + { + pubkey: '032b4ff8e5bc608cbdd12117171e7d265b6882ad597559caf67b5ecfaf15301dd0', + value: 0.1, + }, + ], + }, + { + privateKeys: [ + { + key: '0378e95685b74565fa56751b84a32dfd18545d10d691641b8372e32164fad66a', + isXOnly: true, + }, + { + key: '8d4751f6e8a3586880fb66c19ae277969bd5aa06f61c4ee2f1e2486efdf666d3', + isXOnly: false, + }, + ], + outpoints: [ + { + txid: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', + vout: 0, + }, + { + txid: 'a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d', + vout: 0, + }, + ], + recipientAddresses: [ + { + address: + 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv', + amount: 0.1, + }, + ], + expected: [ + { + pubkey: '0275f501f319db549aaa613717bd7af44da566d4d859b67fe436946564fafc47a3', + value: 0.1, + }, + ], + }, + { + privateKeys: [ + { + key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', + isXOnly: false, + }, + { + key: '0378e95685b74565fa56751b84a32dfd18545d10d691641b8372e32164fad66a', + isXOnly: false, + }, + ], + outpoints: [ + { + txid: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', + vout: 0, + }, + { + txid: 'a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d', + vout: 0, + }, + ], + recipientAddresses: [ + { + address: + 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv', + amount: 0.1, + }, + { + address: + 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv', + amount: 0.2, + }, + ], + expected: [ + { + pubkey: '0264f1c7e8992352d18cdbca600b9e1c3a6025050d56a3e1cc833222e4f3b59e18', + value: 0.1, + }, + { + pubkey: '030a48c6ccc1d516e8244dc0153dc88db45f8f264357667c2057a29ca3c2445d09', + value: 0.2, + }, + ], + }, + { + privateKeys: [ + { + key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', + isXOnly: false, + }, + { + key: '0378e95685b74565fa56751b84a32dfd18545d10d691641b8372e32164fad66a', + isXOnly: false, + }, + ], + outpoints: [ + { + txid: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', + vout: 0, + }, + { + txid: 'a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d', + vout: 0, + }, + ], + recipientAddresses: [ + { + address: + 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv', + amount: 0.1, + }, + { + address: + 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv', + amount: 0.2, + }, + { + address: + 'sp1qqgrz6j0lcqnc04vxccydl0kpsj4frfje0ktmgcl2t346hkw30226xqupawdf48k8882j0strrvcmgg2kdawz53a54dd376ngdhak364hzcmynqtn', + amount: 0.3, + }, + { + address: + 'sp1qqgrz6j0lcqnc04vxccydl0kpsj4frfje0ktmgcl2t346hkw30226xqupawdf48k8882j0strrvcmgg2kdawz53a54dd376ngdhak364hzcmynqtn', + amount: 0.4, + }, + ], + expected: [ + { + pubkey: '0264f1c7e8992352d18cdbca600b9e1c3a6025050d56a3e1cc833222e4f3b59e18', + value: 0.1, + }, + { + pubkey: '030a48c6ccc1d516e8244dc0153dc88db45f8f264357667c2057a29ca3c2445d09', + value: 0.2, + }, + { + pubkey: '02c58e121044b23cba9b4695052229a9fd9e044b579f92864eb886ae7c99b021c9', + value: 0.3, + }, + { + pubkey: '034b15b75f3f184328c4a2f7c79357481ed06cf3b6f95512d5ed946fdc0b60d62b', + value: 0.4, + }, + ], + }, + { + privateKeys: [ + { + key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', + isXOnly: false, + }, + { + key: '0378e95685b74565fa56751b84a32dfd18545d10d691641b8372e32164fad66a', + isXOnly: false, + }, + ], + outpoints: [ + { + txid: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', + vout: 0, + }, + { + txid: 'a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d', + vout: 0, + }, + ], + recipientAddresses: [ + { + address: + 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqhmem6grvs4nacsu0v5v5mjs934j7qfgkdkj8c95gyuru3tjpulvcwky2dz', + amount: 0.1, + }, + ], + expected: [ + { + pubkey: '022cbceeab2a4982841eb7dc34b8b4f19c04bf3bc083ebf984f5664366778eb50f', + value: 0.1, + }, + ], + }, + { + privateKeys: [ + { + key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', + isXOnly: false, + }, + { + key: '0378e95685b74565fa56751b84a32dfd18545d10d691641b8372e32164fad66a', + isXOnly: false, + }, + ], + outpoints: [ + { + txid: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', + vout: 0, + }, + { + txid: 'a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d', + vout: 0, + }, + ], + recipientAddresses: [ + { + address: + 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqc389f45lq7jyqt8jxq6fkskfukr2tlruf6w8cpcx2krntwe4fr9ykagp3j', + amount: 0.1, + }, + ], + expected: [ + { + pubkey: '036b4455de119f51bf4d4a12dea555f14a5dc2c1369af5fba4871c5367264c028d', + value: 0.1, + }, + ], + }, + { + privateKeys: [ + { + key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', + isXOnly: false, + }, + { + key: '0378e95685b74565fa56751b84a32dfd18545d10d691641b8372e32164fad66a', + isXOnly: false, + }, + ], + outpoints: [ + { + txid: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', + vout: 0, + }, + { + txid: 'a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d', + vout: 0, + }, + ], + recipientAddresses: [ + { + address: + 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgq4umqa5feskydh9xadc9jlc22c89tu0apcv72u2vkuwtsrgzf0uesq45zq9', + amount: 0.1, + }, + ], + expected: [ + { + pubkey: '03c3473bfcbe5e4d20d0790ae91f1b339bc15b46de64ca068d140118d0e325b849', + value: 0.1, + }, + ], + }, + { + privateKeys: [ + { + key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', + isXOnly: false, + }, + { + key: '0378e95685b74565fa56751b84a32dfd18545d10d691641b8372e32164fad66a', + isXOnly: false, + }, + ], + outpoints: [ + { + txid: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', + vout: 0, + }, + { + txid: 'a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d', + vout: 0, + }, + ], + recipientAddresses: [ + { + address: + 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv', + amount: 0.1, + }, + { + address: + 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqah4hxfsjdwyaeel4g8x2npkj7qlvf2692l5760z5ut0ggnlrhdzsy3cvsj', + amount: 0.2, + }, + ], + expected: [ + { + pubkey: '0264f1c7e8992352d18cdbca600b9e1c3a6025050d56a3e1cc833222e4f3b59e18', + value: 0.1, + }, + { + pubkey: '027956317130124c32afd07b3f2432a3e92c1447cf58da95491a307ae3d564535e', + value: 0.2, + }, + ], + }, + { + privateKeys: [ + { + key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', + isXOnly: false, + }, + { + key: '0378e95685b74565fa56751b84a32dfd18545d10d691641b8372e32164fad66a', + isXOnly: false, + }, + ], + outpoints: [ + { + txid: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', + vout: 0, + }, + { + txid: 'a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d', + vout: 0, + }, + ], + recipientAddresses: [ + { + address: + 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqah4hxfsjdwyaeel4g8x2npkj7qlvf2692l5760z5ut0ggnlrhdzsy3cvsj', + amount: 0.1, + }, + { + address: + 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqah4hxfsjdwyaeel4g8x2npkj7qlvf2692l5760z5ut0ggnlrhdzsy3cvsj', + amount: 0.2, + }, + ], + expected: [ + { + pubkey: '038890c19f005d6f6add5fef92d37ac6b161b7fdd5c1aef6eed1d32be3f216ac4c', + value: 0.1, + }, + { + pubkey: '027956317130124c32afd07b3f2432a3e92c1447cf58da95491a307ae3d564535e', + value: 0.2, + }, + ], + }, + { + privateKeys: [ + { + key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', + isXOnly: false, + }, + { + key: '0378e95685b74565fa56751b84a32dfd18545d10d691641b8372e32164fad66a', + isXOnly: false, + }, + ], + outpoints: [ + { + txid: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', + vout: 0, + }, + { + txid: 'a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d', + vout: 0, + }, + ], + recipientAddresses: [ + { + address: + 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv', + amount: 0.1, + }, + { + address: + 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqah4hxfsjdwyaeel4g8x2npkj7qlvf2692l5760z5ut0ggnlrhdzsy3cvsj', + amount: 0.2, + }, + { + address: + 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgq562yg7htxyg8eq60rl37uul37jy62apnf5ru62uef0eajpdfrnp5cmqndj', + amount: 0.3, + }, + { + address: + 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgq562yg7htxyg8eq60rl37uul37jy62apnf5ru62uef0eajpdfrnp5cmqndj', + amount: 0.4, + }, + ], + expected: [ + { + pubkey: '0264f1c7e8992352d18cdbca600b9e1c3a6025050d56a3e1cc833222e4f3b59e18', + value: 0.1, + }, + { + pubkey: '027956317130124c32afd07b3f2432a3e92c1447cf58da95491a307ae3d564535e', + value: 0.2, + }, + { + pubkey: '031b90a42136fef9ff2ca192abffc7be4536dc83d4e61cf18ae078f7e92b297cce', + value: 0.3, + }, + { + pubkey: '0287a82600c08a255bc97d172e10816e322967eed6a77c9f37dd926492d7fdc106', + value: 0.4, + }, + ], + }, + { + privateKeys: [ + { + key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', + isXOnly: false, + }, + { + key: '0378e95685b74565fa56751b84a32dfd18545d10d691641b8372e32164fad66a', + isXOnly: false, + }, + ], + outpoints: [ + { + txid: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', + vout: 0, + }, + { + txid: 'a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d', + vout: 0, + }, + ], + recipientAddresses: [ + { + address: + 'sp1qqgste7k9hx0qftg6qmwlkqtwuy6cycyavzmzj85c6qdfhjdpdjtdgqjuexzk6murw56suy3e0rd2cgqvycxttddwsvgxe2usfpxumr70xc9pkqwv', + amount: 0.1, + }, + { + address: + 'sp1qqw6vczcfpdh5nf5y2ky99kmqae0tr30hgdfg88parz50cp80wd2wqqll5497pp2gcr4cmq0v5nv07x8u5jswmf8ap2q0kxmx8628mkqanyu63ck8', + amount: 0.2, + }, + ], + expected: [ + { + pubkey: '0264f1c7e8992352d18cdbca600b9e1c3a6025050d56a3e1cc833222e4f3b59e18', + value: 0.1, + }, + { + pubkey: '020050c52a32566c0dfb517e473c68fedce4bd4543d219348d3bbdceeeb5755e34', + value: 0.2, + }, + ], + }, +]; diff --git a/test/fixtures/scanning.ts b/test/fixtures/scanning.ts new file mode 100644 index 0000000..00a778d --- /dev/null +++ b/test/fixtures/scanning.ts @@ -0,0 +1,416 @@ +export const testData = [ + { + scanPrivateKey: + '0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c', + spendPublicKey: + '025cc9856d6f8375350e123978daac200c260cb5b5ae83106cab90484dcd8fcf36', + sumOfInputPublicKeys: + '032562c1ab2d6bd45d7ca4d78f569999e5333dffd3ac5263924fd00d00dedc4bee', + outpointHash: + '210fef5d624db17c965c7597e2c6c9f60ef440c831d149c43567c50158557f12', + outputs: [ + '0239a1e5ff6206cd316151b9b34cee4f80bb48ce61adee0a12ce7ff05ea436a1d9', + ], + matches: { + '0239a1e5ff6206cd316151b9b34cee4f80bb48ce61adee0a12ce7ff05ea436a1d9': + '8e4bbee712779f746337cadf39e8b1eab8e8869dd40f2e3a7281113e858ffc0b', + }, + }, + { + scanPrivateKey: + '0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c', + spendPublicKey: + '025cc9856d6f8375350e123978daac200c260cb5b5ae83106cab90484dcd8fcf36', + sumOfInputPublicKeys: + '032562c1ab2d6bd45d7ca4d78f569999e5333dffd3ac5263924fd00d00dedc4bee', + outpointHash: + '210fef5d624db17c965c7597e2c6c9f60ef440c831d149c43567c50158557f12', + outputs: [ + '0239a1e5ff6206cd316151b9b34cee4f80bb48ce61adee0a12ce7ff05ea436a1d9', + ], + matches: { + '0239a1e5ff6206cd316151b9b34cee4f80bb48ce61adee0a12ce7ff05ea436a1d9': + '8e4bbee712779f746337cadf39e8b1eab8e8869dd40f2e3a7281113e858ffc0b', + }, + }, + { + scanPrivateKey: + '0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c', + spendPublicKey: + '025cc9856d6f8375350e123978daac200c260cb5b5ae83106cab90484dcd8fcf36', + sumOfInputPublicKeys: + '032562c1ab2d6bd45d7ca4d78f569999e5333dffd3ac5263924fd00d00dedc4bee', + outpointHash: + 'dd7d2a8678cb65b52119af415b578437f5dfc0d9f5bf2daac5e25c21bf0731ce', + outputs: [ + '02162f2298705b3ddca01ce1d214eedff439df3927582938d08e29e464908db00b', + ], + matches: { + '02162f2298705b3ddca01ce1d214eedff439df3927582938d08e29e464908db00b': + 'f06d8d90561bdbc3e511c3bec7355ad3c858aaf38a132c772d6cd82ec04102ac', + }, + }, + { + scanPrivateKey: + '0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c', + spendPublicKey: + '025cc9856d6f8375350e123978daac200c260cb5b5ae83106cab90484dcd8fcf36', + sumOfInputPublicKeys: + '032562c1ab2d6bd45d7ca4d78f569999e5333dffd3ac5263924fd00d00dedc4bee', + outpointHash: + '1b85dfe15f0d5e1cedd47bdd70c24ecb0e3401c0a2ace659c422916626b66bce', + outputs: [ + '02d9ede52f7e1e64e36ccf895ca0250daad96b174987079c903519b17852b21a3f', + ], + matches: { + '02d9ede52f7e1e64e36ccf895ca0250daad96b174987079c903519b17852b21a3f': + '44b827516c2128287b1d571add7cfeb42f122e86bc40b4eb2b21ac144607fdb2', + }, + }, + { + scanPrivateKey: + '0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c', + spendPublicKey: + '025cc9856d6f8375350e123978daac200c260cb5b5ae83106cab90484dcd8fcf36', + sumOfInputPublicKeys: + '03e40664e222ba71e29b80efc907fa22a3c6c64f45e89dbb8511dc7a3712b0a186', + outpointHash: + '210fef5d624db17c965c7597e2c6c9f60ef440c831d149c43567c50158557f12', + outputs: [ + '020aafdcdb5893ae813299b16eea75f34ec16653ac39171da04d7c4e6d2e09ab8e', + ], + matches: { + '020aafdcdb5893ae813299b16eea75f34ec16653ac39171da04d7c4e6d2e09ab8e': + 'bf7336bdc02f624715aab385cc62b71f6f494bf8a7dd0fd621cfd365039c39d1', + }, + }, + { + scanPrivateKey: + '0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c', + spendPublicKey: + '025cc9856d6f8375350e123978daac200c260cb5b5ae83106cab90484dcd8fcf36', + sumOfInputPublicKeys: + '038180a2125f9d6dd116e1a6139be4d72fd5057dab6aaabaa5654817c11baeb3ba', + outpointHash: + '210fef5d624db17c965c7597e2c6c9f60ef440c831d149c43567c50158557f12', + outputs: [ + '0215d1dfe4403791509cf47f073be2eb3277decabe90da395e63b1f49a09fe965e', + ], + matches: { + '0215d1dfe4403791509cf47f073be2eb3277decabe90da395e63b1f49a09fe965e': + '0734de077e436e8f6f125e16287cb60dead8ebddc8532be3589ba27156f1add2', + }, + }, + { + scanPrivateKey: + '0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c', + spendPublicKey: + '025cc9856d6f8375350e123978daac200c260cb5b5ae83106cab90484dcd8fcf36', + sumOfInputPublicKeys: + '038180a2125f9d6dd116e1a6139be4d72fd5057dab6aaabaa5654817c11baeb3ba', + outpointHash: + '210fef5d624db17c965c7597e2c6c9f60ef440c831d149c43567c50158557f12', + outputs: [ + '0215d1dfe4403791509cf47f073be2eb3277decabe90da395e63b1f49a09fe965e', + ], + matches: { + '0215d1dfe4403791509cf47f073be2eb3277decabe90da395e63b1f49a09fe965e': + '0734de077e436e8f6f125e16287cb60dead8ebddc8532be3589ba27156f1add2', + }, + }, + { + scanPrivateKey: + '0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c', + spendPublicKey: + '025cc9856d6f8375350e123978daac200c260cb5b5ae83106cab90484dcd8fcf36', + sumOfInputPublicKeys: + '031ecda9c64faaa6cd57c9f3d7c62bcfc0763c2627ed8dc0e2c3018e9ff37a0bf0', + outpointHash: + '210fef5d624db17c965c7597e2c6c9f60ef440c831d149c43567c50158557f12', + outputs: [ + '022b4ff8e5bc608cbdd12117171e7d265b6882ad597559caf67b5ecfaf15301dd0', + ], + matches: { + '022b4ff8e5bc608cbdd12117171e7d265b6882ad597559caf67b5ecfaf15301dd0': + '17d93733d2acd8388279c24dc4413483802378c99f266f5961ac3338c5146861', + }, + }, + { + scanPrivateKey: + '0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c', + spendPublicKey: + '025cc9856d6f8375350e123978daac200c260cb5b5ae83106cab90484dcd8fcf36', + sumOfInputPublicKeys: + '02ef85ee8dc78102f2fd062d3b321f0b4527f0b954ed14b93b0090c8514c9b6a03', + outpointHash: + '210fef5d624db17c965c7597e2c6c9f60ef440c831d149c43567c50158557f12', + outputs: [ + '0275f501f319db549aaa613717bd7af44da566d4d859b67fe436946564fafc47a3', + ], + matches: { + '0275f501f319db549aaa613717bd7af44da566d4d859b67fe436946564fafc47a3': + '619a5a59a16d4a8e857ef48e63ef7c8195c858191d4e826205e8438ab70d059e', + }, + }, + { + scanPrivateKey: + '0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c', + spendPublicKey: + '025cc9856d6f8375350e123978daac200c260cb5b5ae83106cab90484dcd8fcf36', + sumOfInputPublicKeys: + '03853f51bef283502181e93238c8708ae27235dc51ae45a0c4053987c52fc6428b', + outpointHash: + '210fef5d624db17c965c7597e2c6c9f60ef440c831d149c43567c50158557f12', + outputs: [ + '0264f1c7e8992352d18cdbca600b9e1c3a6025050d56a3e1cc833222e4f3b59e18', + '020a48c6ccc1d516e8244dc0153dc88db45f8f264357667c2057a29ca3c2445d09', + '02c58e121044b23cba9b4695052229a9fd9e044b579f92864eb886ae7c99b021c9', + '024b15b75f3f184328c4a2f7c79357481ed06cf3b6f95512d5ed946fdc0b60d62b', + ], + matches: { + '0264f1c7e8992352d18cdbca600b9e1c3a6025050d56a3e1cc833222e4f3b59e18': + '96439446f13ddaab2c5bc5a59a08992fd9d33bf8563c8a1b362730f4dc022e30', + '020a48c6ccc1d516e8244dc0153dc88db45f8f264357667c2057a29ca3c2445d09': + 'd39df91bd0e7825bfa1d30096febc5bf6fa7da79d7f25b7b4bea9538cc9a9f7f', + }, + }, + { + scanPrivateKey: + '0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c', + spendPublicKey: + '025cc9856d6f8375350e123978daac200c260cb5b5ae83106cab90484dcd8fcf36', + sumOfInputPublicKeys: + '03853f51bef283502181e93238c8708ae27235dc51ae45a0c4053987c52fc6428b', + outpointHash: + '210fef5d624db17c965c7597e2c6c9f60ef440c831d149c43567c50158557f12', + outputs: [ + '0264f1c7e8992352d18cdbca600b9e1c3a6025050d56a3e1cc833222e4f3b59e18', + '020a48c6ccc1d516e8244dc0153dc88db45f8f264357667c2057a29ca3c2445d09', + '02c58e121044b23cba9b4695052229a9fd9e044b579f92864eb886ae7c99b021c9', + '024b15b75f3f184328c4a2f7c79357481ed06cf3b6f95512d5ed946fdc0b60d62b', + ], + matches: { + '0264f1c7e8992352d18cdbca600b9e1c3a6025050d56a3e1cc833222e4f3b59e18': + '96439446f13ddaab2c5bc5a59a08992fd9d33bf8563c8a1b362730f4dc022e30', + '020a48c6ccc1d516e8244dc0153dc88db45f8f264357667c2057a29ca3c2445d09': + 'd39df91bd0e7825bfa1d30096febc5bf6fa7da79d7f25b7b4bea9538cc9a9f7f', + }, + }, + { + scanPrivateKey: + '060b751d7892149006ed7b98606955a29fe284a1e900070c0971f5fb93dbf422', + spendPublicKey: + '0381eb9a9a9ec739d527c1631b31b421566f5c2a47b4ab5b1f6a686dfb68eab716', + sumOfInputPublicKeys: + '03853f51bef283502181e93238c8708ae27235dc51ae45a0c4053987c52fc6428b', + outpointHash: + '210fef5d624db17c965c7597e2c6c9f60ef440c831d149c43567c50158557f12', + outputs: [ + '0264f1c7e8992352d18cdbca600b9e1c3a6025050d56a3e1cc833222e4f3b59e18', + '020a48c6ccc1d516e8244dc0153dc88db45f8f264357667c2057a29ca3c2445d09', + '02c58e121044b23cba9b4695052229a9fd9e044b579f92864eb886ae7c99b021c9', + '024b15b75f3f184328c4a2f7c79357481ed06cf3b6f95512d5ed946fdc0b60d62b', + ], + matches: { + '02c58e121044b23cba9b4695052229a9fd9e044b579f92864eb886ae7c99b021c9': + '567710d07bdaacc8de3f1cec467bcb162ed7daa6b901b59af257bcd7e39dffcf', + '024b15b75f3f184328c4a2f7c79357481ed06cf3b6f95512d5ed946fdc0b60d62b': + '25dd11163a9a2853709c4c837aafb3347e2eaa875cf4c5170e2a3663879f4c58', + }, + }, + { + scanPrivateKey: + '0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c', + spendPublicKey: + '025cc9856d6f8375350e123978daac200c260cb5b5ae83106cab90484dcd8fcf36', + sumOfInputPublicKeys: + '03853f51bef283502181e93238c8708ae27235dc51ae45a0c4053987c52fc6428b', + outpointHash: + '210fef5d624db17c965c7597e2c6c9f60ef440c831d149c43567c50158557f12', + outputs: [ + '0264f1c7e8992352d18cdbca600b9e1c3a6025050d56a3e1cc833222e4f3b59e18', + '020050c52a32566c0dfb517e473c68fedce4bd4543d219348d3bbdceeeb5755e34', + ], + matches: { + '0264f1c7e8992352d18cdbca600b9e1c3a6025050d56a3e1cc833222e4f3b59e18': + '96439446f13ddaab2c5bc5a59a08992fd9d33bf8563c8a1b362730f4dc022e30', + }, + }, + { + scanPrivateKey: + '0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c', + spendPublicKey: + '025cc9856d6f8375350e123978daac200c260cb5b5ae83106cab90484dcd8fcf36', + sumOfInputPublicKeys: + '03853f51bef283502181e93238c8708ae27235dc51ae45a0c4053987c52fc6428b', + outpointHash: + '210fef5d624db17c965c7597e2c6c9f60ef440c831d149c43567c50158557f12', + outputs: [ + '022cbceeab2a4982841eb7dc34b8b4f19c04bf3bc083ebf984f5664366778eb50f', + ], + labels: { + '02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5': + '0000000000000000000000000000000000000000000000000000000000000002', + '02f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9': + '0000000000000000000000000000000000000000000000000000000000000003', + '03348b4f5feb64b557dac8cfa10044bdc2094fca9147163bf514f68687e0d1dba6': + '00000000000000000000000000000000000000000000000000000000000f4779', + }, + matches: { + '022cbceeab2a4982841eb7dc34b8b4f19c04bf3bc083ebf984f5664366778eb50f': + '96439446f13ddaab2c5bc5a59a08992fd9d33bf8563c8a1b362730f4dc022e32', + }, + }, + { + scanPrivateKey: + '0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c', + spendPublicKey: + '025cc9856d6f8375350e123978daac200c260cb5b5ae83106cab90484dcd8fcf36', + sumOfInputPublicKeys: + '03853f51bef283502181e93238c8708ae27235dc51ae45a0c4053987c52fc6428b', + outpointHash: + '210fef5d624db17c965c7597e2c6c9f60ef440c831d149c43567c50158557f12', + outputs: [ + '026b4455de119f51bf4d4a12dea555f14a5dc2c1369af5fba4871c5367264c028d', + ], + labels: { + '02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5': + '0000000000000000000000000000000000000000000000000000000000000002', + '02f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9': + '0000000000000000000000000000000000000000000000000000000000000003', + '03348b4f5feb64b557dac8cfa10044bdc2094fca9147163bf514f68687e0d1dba6': + '00000000000000000000000000000000000000000000000000000000000f4779', + }, + matches: { + '026b4455de119f51bf4d4a12dea555f14a5dc2c1369af5fba4871c5367264c028d': + '96439446f13ddaab2c5bc5a59a08992fd9d33bf8563c8a1b362730f4dc022e33', + }, + }, + { + scanPrivateKey: + '0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c', + spendPublicKey: + '025cc9856d6f8375350e123978daac200c260cb5b5ae83106cab90484dcd8fcf36', + sumOfInputPublicKeys: + '03853f51bef283502181e93238c8708ae27235dc51ae45a0c4053987c52fc6428b', + outpointHash: + '210fef5d624db17c965c7597e2c6c9f60ef440c831d149c43567c50158557f12', + outputs: [ + '02c3473bfcbe5e4d20d0790ae91f1b339bc15b46de64ca068d140118d0e325b849', + ], + labels: { + '02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5': + '0000000000000000000000000000000000000000000000000000000000000002', + '02f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9': + '0000000000000000000000000000000000000000000000000000000000000003', + '03348b4f5feb64b557dac8cfa10044bdc2094fca9147163bf514f68687e0d1dba6': + '00000000000000000000000000000000000000000000000000000000000f4779', + }, + matches: { + '02c3473bfcbe5e4d20d0790ae91f1b339bc15b46de64ca068d140118d0e325b849': + '96439446f13ddaab2c5bc5a59a08992fd9d33bf8563c8a1b362730f4dc1175a9', + }, + }, + { + scanPrivateKey: + '0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c', + spendPublicKey: + '025cc9856d6f8375350e123978daac200c260cb5b5ae83106cab90484dcd8fcf36', + sumOfInputPublicKeys: + '03853f51bef283502181e93238c8708ae27235dc51ae45a0c4053987c52fc6428b', + outpointHash: + '210fef5d624db17c965c7597e2c6c9f60ef440c831d149c43567c50158557f12', + outputs: [ + '0264f1c7e8992352d18cdbca600b9e1c3a6025050d56a3e1cc833222e4f3b59e18', + '027956317130124c32afd07b3f2432a3e92c1447cf58da95491a307ae3d564535e', + ], + labels: { + '0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798': + '0000000000000000000000000000000000000000000000000000000000000001', + }, + matches: { + '0264f1c7e8992352d18cdbca600b9e1c3a6025050d56a3e1cc833222e4f3b59e18': + '96439446f13ddaab2c5bc5a59a08992fd9d33bf8563c8a1b362730f4dc022e30', + '027956317130124c32afd07b3f2432a3e92c1447cf58da95491a307ae3d564535e': + 'd39df91bd0e7825bfa1d30096febc5bf6fa7da79d7f25b7b4bea9538cc9a9f80', + }, + }, + { + scanPrivateKey: + '0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c', + spendPublicKey: + '025cc9856d6f8375350e123978daac200c260cb5b5ae83106cab90484dcd8fcf36', + sumOfInputPublicKeys: + '03853f51bef283502181e93238c8708ae27235dc51ae45a0c4053987c52fc6428b', + outpointHash: + '210fef5d624db17c965c7597e2c6c9f60ef440c831d149c43567c50158557f12', + outputs: [ + '028890c19f005d6f6add5fef92d37ac6b161b7fdd5c1aef6eed1d32be3f216ac4c', + '027956317130124c32afd07b3f2432a3e92c1447cf58da95491a307ae3d564535e', + ], + labels: { + '0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798': + '0000000000000000000000000000000000000000000000000000000000000001', + }, + matches: { + '028890c19f005d6f6add5fef92d37ac6b161b7fdd5c1aef6eed1d32be3f216ac4c': + '96439446f13ddaab2c5bc5a59a08992fd9d33bf8563c8a1b362730f4dc022e31', + '027956317130124c32afd07b3f2432a3e92c1447cf58da95491a307ae3d564535e': + 'd39df91bd0e7825bfa1d30096febc5bf6fa7da79d7f25b7b4bea9538cc9a9f80', + }, + }, + { + scanPrivateKey: + '0f694e068028a717f8af6b9411f9a133dd3565258714cc226594b34db90c1f2c', + spendPublicKey: + '025cc9856d6f8375350e123978daac200c260cb5b5ae83106cab90484dcd8fcf36', + sumOfInputPublicKeys: + '03853f51bef283502181e93238c8708ae27235dc51ae45a0c4053987c52fc6428b', + outpointHash: + '210fef5d624db17c965c7597e2c6c9f60ef440c831d149c43567c50158557f12', + outputs: [ + '0264f1c7e8992352d18cdbca600b9e1c3a6025050d56a3e1cc833222e4f3b59e18', + '027956317130124c32afd07b3f2432a3e92c1447cf58da95491a307ae3d564535e', + '021b90a42136fef9ff2ca192abffc7be4536dc83d4e61cf18ae078f7e92b297cce', + '0287a82600c08a255bc97d172e10816e322967eed6a77c9f37dd926492d7fdc106', + ], + labels: { + '0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798': + '0000000000000000000000000000000000000000000000000000000000000001', + '02db0c51cc634a4096374b0b895584a3ca2fb3bea4fd0ee2361f8db63a650fcee6': + '0000000000000000000000000000000000000000000000000000000000000539', + }, + matches: { + '0264f1c7e8992352d18cdbca600b9e1c3a6025050d56a3e1cc833222e4f3b59e18': + '96439446f13ddaab2c5bc5a59a08992fd9d33bf8563c8a1b362730f4dc022e30', + '027956317130124c32afd07b3f2432a3e92c1447cf58da95491a307ae3d564535e': + 'd39df91bd0e7825bfa1d30096febc5bf6fa7da79d7f25b7b4bea9538cc9a9f80', + '021b90a42136fef9ff2ca192abffc7be4536dc83d4e61cf18ae078f7e92b297cce': + '255a912ad6cdebc0842d49fd9f7b2d81ee37d66c62839879371b699010f78ef1', + '0287a82600c08a255bc97d172e10816e322967eed6a77c9f37dd926492d7fdc106': + 'd7535d792cb1388ab0b3bd5ff57337436d62f7719c1796beb5d80ab2fa34f307', + }, + }, + { + scanPrivateKey: + '11b7a82e06ca2648d5fded2366478078ec4fc9dc1d8ff487518226f229d768fd', + spendPublicKey: + '03bc95144daf15336db3456825c70ced0a4462f89aca42c4921ee7ccb2b3a44796', + sumOfInputPublicKeys: + '03853f51bef283502181e93238c8708ae27235dc51ae45a0c4053987c52fc6428b', + outpointHash: + '210fef5d624db17c965c7597e2c6c9f60ef440c831d149c43567c50158557f12', + outputs: [ + '0264f1c7e8992352d18cdbca600b9e1c3a6025050d56a3e1cc833222e4f3b59e18', + '020050c52a32566c0dfb517e473c68fedce4bd4543d219348d3bbdceeeb5755e34', + ], + labels: { + '02295dc38e877b754c0d0ed767434f1572cf34a82ccc06ffea1d9e04f1f7878e1a': + '91cb04398a508c9d995ff4a18e5eae24d5e9488309f189120a3fdbb977978c46', + }, + matches: { + '020050c52a32566c0dfb517e473c68fedce4bd4543d219348d3bbdceeeb5755e34': + '2e9c2a37cfa7827907d36357f0632d258dbd14b3a7854937ecf732fb6acefdc8', + }, + }, +]; diff --git a/test/fixtures/utility.ts b/test/fixtures/utility.ts new file mode 100644 index 0000000..3e3ede4 --- /dev/null +++ b/test/fixtures/utility.ts @@ -0,0 +1,117 @@ +export const outpoints = [ + { + outpoints: [ + { + txid: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', + vout: 0, + }, + { + txid: 'a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d', + vout: 0, + }, + ], + expected: + '210fef5d624db17c965c7597e2c6c9f60ef440c831d149c43567c50158557f12', + }, + { + outpoints: [ + { + txid: 'a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d', + vout: 7, + }, + { + txid: 'a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d', + vout: 3, + }, + ], + expected: + '1b85dfe15f0d5e1cedd47bdd70c24ecb0e3401c0a2ace659c422916626b66bce', + }, + { + outpoints: [ + { + txid: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', + vout: 3, + }, + { + txid: 'f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16', + vout: 7, + }, + ], + expected: + 'dd7d2a8678cb65b52119af415b578437f5dfc0d9f5bf2daac5e25c21bf0731ce', + }, +]; + +export const inputPrivateKeys = [ + { + keys: [ + { + key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', + isXOnly: false, + }, + { + key: '93f5ed907ad5b2bdbbdcb5d9116ebc0a4e1f92f910d5260237fa45a9408aad16', + isXOnly: false, + }, + ], + expected: + '7ed265a6dac7aba8508a32d6d6b84c7f1dbd0a0941dd01088d69e8d556345f86', + }, + { + keys: [ + { + key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', + isXOnly: true, + }, + { + key: 'fc8716a97a48ba9a05a98ae47b5cd201a25a7fd5d8b73c203c5f7b6b6b3b6ad7', + isXOnly: true, + }, + ], + expected: + 'e7638ebfda3ab3849a5707e240a6627671f7f6e609bf172691cf1e9780e51d47', + }, + { + keys: [ + { + key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', + isXOnly: false, + }, + { + key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', + isXOnly: false, + }, + ], + expected: + 'd5b8f02cbfe3f1d5295af9fb8a9320e859e9cb07115856486ab1a4e4fb89a621', + }, + { + keys: [ + { + key: '0378e95685b74565fa56751b84a32dfd18545d10d691641b8372e32164fad66a', + isXOnly: true, + }, + { + key: '8d4751f6e8a3586880fb66c19ae277969bd5aa06f61c4ee2f1e2486efdf666d3', + isXOnly: false, + }, + ], + expected: + '89ce68a062ec130286a4f1a6163f499983814cf61f8aeac76e6f654d98fb9069', + }, + { + keys: [ + { + key: 'eadc78165ff1f8ea94ad7cfdc54990738a4c53f6e0507b42154201b8e5dff3b1', + isXOnly: false, + }, + { + key: '0378e95685b74565fa56751b84a32dfd18545d10d691641b8372e32164fad66a', + isXOnly: false, + }, + ], + expected: + 'ee55616ce5a93e508f03f21949ecbe70a2a0b107b6e1df5d98b4e4da4adaca1b', + }, +]; diff --git a/test/outputs.spec.ts b/test/outputs.spec.ts new file mode 100644 index 0000000..0bf8d31 --- /dev/null +++ b/test/outputs.spec.ts @@ -0,0 +1,32 @@ +import { Outpoint, PrivateKey, RecipientAddress } from '../src/interface'; +import { createOutputs } from '../src'; +import { testData } from './fixtures/outputs'; + +describe('Outputs', () => { + it.each(testData)( + 'should create silent payments public keys', + (data: { + privateKeys: PrivateKey[]; + outpoints: Outpoint[]; + recipientAddresses: RecipientAddress[]; + expected: { pubkey: string; value: number }[]; + }) => { + const outputs = createOutputs( + data.privateKeys, + data.outpoints, + data.recipientAddresses, + 'sp', + ); + expect( + outputs + .map((output) => ({ + pubkey: output.pubkey.toString('hex'), + value: output.value, + })) + .sort((a, b) => a.pubkey.localeCompare(b.pubkey)), + ).toStrictEqual( + data.expected.sort((a, b) => a.pubkey.localeCompare(b.pubkey)), + ); + }, + ); +}); diff --git a/test/scanning.spec.ts b/test/scanning.spec.ts new file mode 100644 index 0000000..6e63667 --- /dev/null +++ b/test/scanning.spec.ts @@ -0,0 +1,37 @@ +import { scanOutputs } from '../src'; +import { LabelMap } from '../src/interface'; +import { Buffer } from 'buffer'; +import { testData } from './fixtures/scanning'; + +describe('Scanning', () => { + it.each(testData)( + 'should pass', + ({ + scanPrivateKey, + spendPublicKey, + sumOfInputPublicKeys, + outpointHash, + outputs, + labels, + matches, + }) => { + const result = scanOutputs( + Buffer.from(scanPrivateKey, 'hex'), + Buffer.from(spendPublicKey, 'hex'), + Buffer.from(sumOfInputPublicKeys, 'hex'), + Buffer.from(outpointHash, 'hex'), + outputs.map((output) => Buffer.from(output, 'hex')), + labels as unknown as LabelMap, + ); + + expect(result).toStrictEqual( + new Map( + Object.entries(matches).map(([output, tweak]) => [ + output, + Buffer.from(tweak as string, 'hex'), + ]), + ), + ); + }, + ); +}); diff --git a/test/utility.spec.ts b/test/utility.spec.ts new file mode 100644 index 0000000..e0c42b0 --- /dev/null +++ b/test/utility.spec.ts @@ -0,0 +1,23 @@ +import { Outpoint, PrivateKey } from '../src/interface'; +import { calculateSumOfPrivateKeys, hashOutpoints } from '../src'; +import { inputPrivateKeys, outpoints } from './fixtures/utility'; + +describe('Utility', () => { + it.each(outpoints)( + 'should calculate hash of outpoints in tx', + (data: { outpoints: Outpoint[]; expected: string }) => { + const { outpoints, expected } = data; + const hash = hashOutpoints(outpoints); + expect(hash.toString('hex')).toBe(expected); + }, + ); + + it.each(inputPrivateKeys)( + 'should calculate sum of private keys', + async (data: { keys: PrivateKey[]; expected: string }) => { + const { keys, expected } = data; + const sum = calculateSumOfPrivateKeys(keys); + expect(sum.toString('hex')).toBe(expected); + }, + ); +});