|
5 | 5 | WALLY_NETWORK_BITCOIN_MAINNET, WALLY_ADDRESS_VERSION_WIF_MAINNET, WALLY_WIF_FLAG_COMPRESSED,
|
6 | 6 | BIP32_FLAG_KEY_PUBLIC, BIP32_INITIAL_HARDENED_CHILD,
|
7 | 7 | } from './index.js'
|
| 8 | +import { toWallyMap, fromWallyMap } from './util.js' |
8 | 9 |
|
9 | 10 | // Test simple invocation, with a return code only and no destination pointer
|
10 | 11 | wally.hex_verify('00') // should not throw
|
@@ -77,6 +78,19 @@ const try_scrypt = size => wally.scrypt(Buffer.from("password"), Buffer.from("Na
|
77 | 78 | assert.equal(try_scrypt(32).toString('hex'), 'fdbabe1c9d3472007856e7190d01e9fe7c6ad7cbc8237830e77376634b373162')
|
78 | 79 | assert.equal(try_scrypt(64).toString('hex'), 'fdbabe1c9d3472007856e7190d01e9fe7c6ad7cbc8237830e77376634b3731622eaf30d92e22a3886ff109279d9830dac727afb94a83ee6d8360cbdfa2cc0640')
|
79 | 80 |
|
| 81 | +// Test JS<->wally map conversion |
| 82 | +let m1, m2 |
| 83 | +const js_map = new Map([ |
| 84 | + [0, Buffer.from('zero')], |
| 85 | + [1, Buffer.from('one')], |
| 86 | + ['k1', Buffer.from('v1')], |
| 87 | + ['k2', Buffer.from('v2')], |
| 88 | +]) |
| 89 | +assert.deepEqual(fromWallyMap(m1=toWallyMap(js_map)), js_map) |
| 90 | +// works with plain objects and string values (auto-converted to a Map of Buffer values) |
| 91 | +assert.deepEqual(fromWallyMap(m2=toWallyMap({ 'foo': 'bar' })), new Map([['foo', Buffer.from('bar')]])) |
| 92 | +wally.map_free(m1); wally.map_free(m2) |
| 93 | + |
80 | 94 | // Test base58 conversion (depends on a JS length function)
|
81 | 95 | assert.equal(wally.base58_to_bytes('1EMBaSSyxMQPV2fmUsdB7mMfMoocgfiMNw', 0).toString('hex'), '00926ac8843cbca0ee59aa857188324d6d5b76c1c6f0bcc3b0')
|
82 | 96 | assert.equal(wally.base58_n_to_bytes('1EMBaSSyxMQPV2fmUsdB7mMfMoocgfiMNw', 34, 0).toString('hex'), '00926ac8843cbca0ee59aa857188324d6d5b76c1c6f0bcc3b0')
|
|
0 commit comments