Skip to content

Commit 62b3644

Browse files
committed
Use constants
1 parent f39b968 commit 62b3644

File tree

3 files changed

+27
-28
lines changed

3 files changed

+27
-28
lines changed

src/wrap_js/example.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var wally = require('./wally');
1+
const wally = require('./wally');
22

33
wally.wally_sha256(Buffer.from('test', 'ascii')).then(function(uint8Array) {
44
console.log(Buffer.from(uint8Array).toString('hex'))
@@ -10,13 +10,13 @@ wally.wally_base58_from_bytes(Buffer.from('xyz', 'ascii'), 0).then(function(s) {
1010
});
1111
});
1212

13-
var seed = Buffer.from('00000000000000000000000000000000', 'hex');
14-
wally.bip32_key_from_seed(seed, 0x0488ADE4, 0).then(function(s) {
13+
const seed = Buffer.from('00000000000000000000000000000000', 'hex');
14+
wally.bip32_key_from_seed(seed, wally.BIP32_VER_MAIN_PRIVATE, 0).then(function(s) {
1515
wally.wally_base58_from_bytes(s, 1).then(function (s) {
1616
console.log('privkey:', s);
1717
});
1818
wally.bip32_pubkey_from_parent(s, 1, 0).then(function (pub) {
19-
wally.wally_base58_from_bytes(pub, 1).then(function (s) {
19+
wally.wally_base58_from_bytes(pub, wally.BASE58_FLAG_CHECKSUM).then(function (s) {
2020
console.log('pubkey:', s);
2121
});
2222
});

src/wrap_js/test/test_bip32.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
var wally = require('../wally');
2-
var test = require('tape');
3-
const EC_PUBLIC_KEY_LEN = 33;
4-
var seed = Buffer.from('00000000000000000000000000000000', 'hex');
1+
const wally = require('../wally');
2+
const test = require('tape');
3+
const seed = Buffer.from('00000000000000000000000000000000', 'hex');
54

65
test('BIP32 from seed + derivation', function(t) {
76
t.plan(6);
8-
wally.bip32_key_from_seed(Buffer.from(seed), 0x0488ADE4, 0).then(function(s) {
9-
wally.wally_base58_from_bytes(s, 1).then(function (s) {
7+
8+
wally.bip32_key_from_seed(Buffer.from(seed), wally.BIP32_VER_MAIN_PRIVATE, wally.BIP32_FLAG_KEY_PRIVATE).then(function(s) {
9+
wally.wally_base58_from_bytes(s, wally.BASE58_FLAG_CHECKSUM).then(function (s) {
1010
t.equal(
1111
s,
1212
('xprv9s21ZrQH143K2JbpEjGU94NcdKSASB7LuXvJCTsxuENcGN1nVG7Q'+
@@ -15,8 +15,8 @@ test('BIP32 from seed + derivation', function(t) {
1515
);
1616
});
1717

18-
wally.bip32_pubkey_from_parent(s, 1, 0).then(function (pub) {
19-
wally.wally_base58_from_bytes(pub, 1).then(function (s) {
18+
wally.bip32_pubkey_from_parent(s, 1, wally.BIP32_FLAG_KEY_PRIVATE).then(function (pub) {
19+
wally.wally_base58_from_bytes(pub, wally.BASE58_FLAG_CHECKSUM).then(function (s) {
2020
t.equal(
2121
s,
2222
('xpub683nVy7Tt7baCKuqho7X5C7TGuskZAa4wQ5YEue2BxtYB6upN4Yg'+
@@ -36,8 +36,8 @@ test('BIP32 from seed + derivation', function(t) {
3636
});
3737
})
3838

39-
wally.bip32_privkey_from_parent(s, 0, 0).then(function (xpriv_0_0) {
40-
wally.wally_base58_from_bytes(xpriv_0_0, 1).then(function (base58_xpriv) {
39+
wally.bip32_privkey_from_parent(s, 0, wally.BIP32_FLAG_KEY_PRIVATE).then(function (xpriv_0_0) {
40+
wally.wally_base58_from_bytes(xpriv_0_0, wally.BASE58_FLAG_CHECKSUM).then(function (base58_xpriv) {
4141
t.equal(
4242
base58_xpriv,
4343
'xprv9u4S6Taa3k3GxnaHfWzboKwLPPPHpDyDHdLGqDArBejguBuv6GkerLy6MtAeFfo9RDfZy22FWEc1ExEShuRGZJpgVgeVu5KZ5obWbV2R3D2',
@@ -46,17 +46,17 @@ test('BIP32 from seed + derivation', function(t) {
4646
});
4747
});
4848

49-
wally.bip32_pubkey_from_parent(s, 0, 0).then(function (xpub_0_0) {
50-
wally.wally_base58_from_bytes(xpub_0_0, 1).then(function (base58_xpub) {
49+
wally.bip32_pubkey_from_parent(s, 0, wally.BIP32_FLAG_KEY_PRIVATE).then(function (xpub_0_0) {
50+
wally.wally_base58_from_bytes(xpub_0_0, wally.BASE58_FLAG_CHECKSUM).then(function (base58_xpub) {
5151
t.equal(
5252
base58_xpub,
5353
'xpub683nVy7Tt7baBGekmYXcATt4wRDnDgh4erFsdbaTjzGfmzF4dp4uQ9HaDCdvSqctrsbxZey5wozKyyy2J3zhDDHU3UhW4uCFQp6bESv8ewQ',
5454
'xpub M/0/0'
5555
);
5656
});
5757

58-
wally.bip32_pubkey_from_parent(xpub_0_0, 1, 1).then(function (xpub_0_0_1) {
59-
wally.wally_base58_from_bytes(xpub_0_0_1, 1).then(function (base58_xpub) {
58+
wally.bip32_pubkey_from_parent(xpub_0_0, 1, wally.BIP32_FLAG_KEY_PUBLIC).then(function (xpub_0_0_1) {
59+
wally.wally_base58_from_bytes(xpub_0_0_1, wally.BASE58_FLAG_CHECKSUM).then(function (base58_xpub) {
6060
t.equal(
6161
base58_xpub,
6262
'xpub6An6e2ai6kSDnnxJ3876JwfeigdQu9YNudcP7ayT828xDFzFQkP9oBoBNdvj7xDrDQd9TQDpzkLhM5L71rFDTmxMuzSvXwZKnLx56Es6MEg',
@@ -71,15 +71,15 @@ test('BIP32 from seed + derivation', function(t) {
7171
test('BIP32 from seed to address', function(t) {
7272
t.plan(1);
7373

74-
wally.bip32_key_from_seed(seed, 0x0488ADE4, 0).then(function(s) {
75-
return wally.bip32_pubkey_from_parent(s, 0, 1);
74+
wally.bip32_key_from_seed(seed, wally.BIP32_VER_MAIN_PRIVATE, wally.BIP32_FLAG_KEY_PRIVATE).then(function(s) {
75+
return wally.bip32_pubkey_from_parent(s, 0, wally.BIP32_FLAG_KEY_PUBLIC);
7676
}).then((xpubkey) => {
7777
return wally.bip32_key_get_pub_key(xpubkey);
7878
}).then((pubkey) => {
7979
return wally.wally_hash160(pubkey);
8080
}).then((script) => {
8181
const prefix = Buffer.from('eb', 'hex');
82-
return wally.wally_base58_from_bytes(Buffer.concat([prefix, script]), 1);
82+
return wally.wally_base58_from_bytes(Buffer.concat([prefix, script]), wally.BASE58_FLAG_CHECKSUM);
8383
}).then((address) => {
8484
t.equal(
8585
address,

src/wrap_js/test/test_script.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1-
var wally = require('../wally');
2-
var test = require('tape');
1+
const wally = require('../wally');
2+
const test = require('tape');
33

4-
const EC_PUBLIC_KEY_LEN = 33;
5-
var pubkeys = [
4+
const pubkeys = [
65
'02ad4199d0c53b564b39798c4c064a6e6093abbb71d56cc153abf75a02f85c8e99',
76
'03afeefeba0806711b6d3fc7c8b0b6a3eff5ea2ecf938aea1b6a093898097875f3'
87
];
98

109
test('Script', function(t) {
1110
t.plan(1);
1211

13-
var pubkey_bytes = Buffer.from(pubkeys[0] + pubkeys[1], 'hex');
14-
var redeem_script = '522102ad4199d0c53b564b39798c4c064a6e6093abbb71d56cc153abf75a02f85c8e992103afeefeba0806711b6d3fc7c8b0b6a3eff5ea2ecf938aea1b6a093898097875f352ae';
12+
const pubkey_bytes = Buffer.from(pubkeys[0] + pubkeys[1], 'hex');
13+
const redeem_script = '522102ad4199d0c53b564b39798c4c064a6e6093abbb71d56cc153abf75a02f85c8e992103afeefeba0806711b6d3fc7c8b0b6a3eff5ea2ecf938aea1b6a093898097875f352ae';
1514

1615
wally.wally_scriptpubkey_multisig_from_bytes(
1716
pubkey_bytes,
1817
2,
1918
0,
20-
(pubkey_bytes.byteLength / EC_PUBLIC_KEY_LEN) * 34 + 3
19+
(pubkey_bytes.byteLength / wally.EC_PUBLIC_KEY_LEN) * 34 + 3
2120
).then((res) => {
2221
t.equal(Buffer.from(res).toString('hex'), redeem_script);
2322
});

0 commit comments

Comments
 (0)