11import assert from 'assert'
22
33import * as wally from './index.js'
4- import { bytesToHex , hexToBytes } from './index.js'
54import {
65 WALLY_NETWORK_BITCOIN_MAINNET , WALLY_ADDRESS_VERSION_WIF_MAINNET , WALLY_WIF_FLAG_COMPRESSED ,
76 BIP32_FLAG_KEY_PUBLIC , BIP32_INITIAL_HARDENED_CHILD ,
@@ -15,25 +14,25 @@ assert.throws(_ => wally.hex_verify('001'), 'WALLY_EINVAL')
1514assert . equal ( wally . bip39_get_word ( null , 10 ) , 'access' )
1615
1716// Test string argument and a string destination pointer
18- assert . equal ( bytesToHex ( wally . address_to_scriptpubkey ( "1EMBaSSyxMQPV2fmUsdB7mMfMoocgfiMNw" , WALLY_NETWORK_BITCOIN_MAINNET ) ) ,
17+ assert . equal ( wally . address_to_scriptpubkey ( "1EMBaSSyxMQPV2fmUsdB7mMfMoocgfiMNw" , WALLY_NETWORK_BITCOIN_MAINNET ) . toString ( 'hex' ) ,
1918 '76a914926ac8843cbca0ee59aa857188324d6d5b76c1c688ac' )
2019
2120// Test bytes buffer argument
22- assert . equal ( wally . bip39_mnemonic_from_bytes ( null , hexToBytes ( 'b5bb9d8014a0f9b1d61e21e796d78dcc' ) ) ,
21+ assert . equal ( wally . bip39_mnemonic_from_bytes ( null , Buffer . from ( 'b5bb9d8014a0f9b1d61e21e796d78dcc' , 'hex ') ) ,
2322 'remember table gas citizen auto suggest flash service travel repeat toddler occur' )
2423
2524// Test `written` pointer as the return value
2625assert . equal ( wally . wif_is_uncompressed ( "L5EZftvrYaSudiozVRzTqLcHLNDoVn7H5HSfM9BAN6tMJX8oTWz6" ) , 0 )
2726assert . equal ( wally . wif_is_uncompressed ( "5Kdc3UAwGmHHuj6fQD1LDmKR6J3SwYyFWyHgxKAZ2cKRzVCRETY" ) , 1 )
2827
29- assert . equal ( wally . wif_from_bytes ( hexToBytes ( 'b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c' ) , WALLY_ADDRESS_VERSION_WIF_MAINNET , WALLY_WIF_FLAG_COMPRESSED ) ,
28+ assert . equal ( wally . wif_from_bytes ( Buffer . from ( 'b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c' , 'hex ') , WALLY_ADDRESS_VERSION_WIF_MAINNET , WALLY_WIF_FLAG_COMPRESSED ) ,
3029 'L3JyYy6eC7JRohrc1XH1Y7caP966K5rbhFH7JEjpygufxTzEqR1Q' )
3130
3231// Test the use of returned opaque references
3332const txhex = '020000000001015720d1aa6ac6bed17730b5e852c82191b73d1bd14cae6d7ccb8a4deab03081390000000000fdffffff018e5a0f00000000001976a914422e4acaed40191100fc4d13632574b62ee2ca2588ac0247304402203371fbdb07d9fefbf9e0f6d31700979297f36a871962a5c601e3495874dbeeaa022071e323524a4aa2d849a1295430d68e8e2e46fc99662d1b8e46435ffb47a699ca01210381722a93622de13f6848663f854a896d5910aadf5461937bcf3f02464cd36a0cd1860b00'
34- const tx1 = wally . tx_from_hex ( txhex , null )
33+ const tx1 = wally . tx_from_hex ( txhex , 0 )
3534assert . equal ( wally . tx_get_witness_count ( tx1 ) , 1 )
36- assert . equal ( bytesToHex ( wally . tx_get_txid ( tx1 ) ) , "bc54928ad07bbe606ec27c8f9af9266b5c73cf01219f5cc545f849135c44bc90" )
35+ assert . equal ( wally . tx_get_txid ( tx1 ) . toString ( 'hex' ) , "bc54928ad07bbe606ec27c8f9af9266b5c73cf01219f5cc545f849135c44bc90" )
3736
3837// Test bigint return value
3938assert . equal ( wally . tx_get_total_output_satoshi ( tx1 ) , 1006222n )
@@ -58,10 +57,10 @@ wally.bip32_key_free(hdkey_child)
5857// Test varlen buffers (https://wally.readthedocs.io/en/latest/conventions/#variable-length-output-buffers)
5958const longhex = Array ( 200 ) . join ( '00' )
6059const bytes = wally . hex_to_bytes ( longhex )
61- assert . equal ( bytesToHex ( bytes ) , longhex )
60+ assert . equal ( bytes . toString ( 'hex' ) , longhex )
6261
63- const vbytes = wally . varbuff_to_bytes ( hexToBytes ( '133337' ) ) ;
64- assert . equal ( bytesToHex ( vbytes ) , '03133337' )
62+ const vbytes = wally . varbuff_to_bytes ( Buffer . from ( '133337' , 'hex ') ) ;
63+ assert . equal ( vbytes . toString ( 'hex' ) , '03133337' )
6564
6665// Test uint32 array as an argument and return value
6766const keypaths = wally . map_keypath_public_key_init ( 1 )
@@ -71,10 +70,11 @@ const keypaths = wally.map_keypath_public_key_init(1)
7170
7271wally . map_keypath_add ( keypaths , dummy_pubkey , dummy_fingerprint , dummy_path )
7372assert . equal ( wally . map_keypath_get_item_path ( keypaths , 0 ) . join ( ',' ) , dummy_path . join ( ',' ) )
73+ wally . map_free ( keypaths )
7474
7575// Test output buffers with a user-specified length (scrypt is the only instance of this)
7676const try_scrypt = size => wally . scrypt ( Buffer . from ( "password" ) , Buffer . from ( "NaCl" ) , 1024 , 8 , 16 , size )
77- assert ( wally . bytesToHex ( try_scrypt ( 32 ) ) , 'fdbabe1c9d3472007856e7190d01e9fe7c6ad7cbc8237830e77376634b373162' )
78- assert ( wally . bytesToHex ( try_scrypt ( 64 ) ) , 'fdbabe1c9d3472007856e7190d01e9fe7c6ad7cbc8237830e77376634b3731622eaf30d92e22a3886ff109279d9830dac727afb94a83ee6d8360cbdfa2cc0640' )
77+ assert ( try_scrypt ( 32 ) . toString ( 'hex' ) , 'fdbabe1c9d3472007856e7190d01e9fe7c6ad7cbc8237830e77376634b373162' )
78+ assert ( try_scrypt ( 64 ) . toString ( 'hex' ) , 'fdbabe1c9d3472007856e7190d01e9fe7c6ad7cbc8237830e77376634b3731622eaf30d92e22a3886ff109279d9830dac727afb94a83ee6d8360cbdfa2cc0640' )
7979
80- console . log ( 'Tests passed.' )
80+ console . log ( 'Tests passed.' )
0 commit comments