Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump version #5

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
10 changes: 2 additions & 8 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@






{
"browser": true,
"node": true,
"esversion": 11,
"curly": true,
"sub": true,

"bitwise": true,

"bitwise": false,
"eqeqeq": true,
"forin": true,
"freeze": true,
Expand Down
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,28 @@ let parts = await b58c.verify(wif);
"check": "24aeb2e6"
}
*/

// Extended Public Key
let xpub = `xpub6EtdcAi4VMbZRDgSaA1WmrqB8asuswgz1toia3YULccxyJXYqdxwqFgeEexVxr8ytJPHZYTrhbYJjqaFumih45awabyaHwUmCvXbGf7sujG`;
let parts = await b58c.decode(xpub); // TODO checksum not checked
/*
{
"version": "0488b21e",
"pubKeyHash": "04832a89a60000000091dbdc89637be3d19851998ba2fac7f85b03b28a65de5c284899e7608f25ee4f0238eddc6cf0b2e8a1bae318affe3661cc071d13c9ad95e77a331a91b58a1b3a7f",
"check": "c1edc9ce"
}
*/

// Extended Public Key
let xprv = `xprvA1WUDWFxdE5UGW1XNTnkZnd3K6bdidZBTtzvtEQziBpS3N8tajC4QKyRLmas7DK4HXK76wSXgMV1uV6RbKyM5f4uu1VmguEhAqvzQwr2mrC`;
let parts = await b58c.decode(xprv); // TODO checksum not checked
/*
{
"version": "0488ade4",
"xprv": "04832a89a60000000091dbdc89637be3d19851998ba2fac7f85b03b28a65de5c284899e7608f25ee4f0079842279eca681d40ccc86c6c618f783f4d4339c2431e4ed29e57c7b73be0c69",
"check": "e986668d"
}
*/
```

### Options
Expand Down
50 changes: 48 additions & 2 deletions base58check-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,38 @@ async function toWif() {
"XFPxuUn5Epz625e6FXAVXL5W8C87iLc8q8KK8ioexsU8dwj9RidW",
"XFdqUukoCypRmmSrVWCZm5gFC7DGKNByHr66DmVL6JZTEPzmkoog",
"XCBPnETeYM3CESgw94wM19u6qR4YWkokHB9MuCD4faTMbVeBRkmT",
].reduce(async function (prev, prv) {
await b58c.verify(prv);
].reduce(async function (prev, wif) {
await b58c.verify(wif);

let decoded = await b58c.decode(wif);
let check = await b58c.checksum({
privateKey: decoded.privateKey,
});

try {
await b58c.checksum({
pubKeyHash: decoded.privateKey,
});
throw new Error("allowed checksum of wrong key type");
} catch (e) {
// ignore, expected
}

if (decoded.check !== check) {
throw new Error("checksum({ privateKey }) failed");
}

let encoded = await b58c.encode({
version: undefined,
privateKey: decoded.privateKey,
});
let decoded2 = await b58c.decode(encoded);
if (decoded.privateKey !== decoded2.privateKey) {
throw new Error(`private keys don't match`);
}
if (decoded.privateKey !== decoded2.privateKey) {
throw new Error(`checksums don't match`);
}
}, Promise.resolve());
}

Expand All @@ -47,6 +77,22 @@ async function toPubKeyHash() {
let parts = await b58c.verify(addr);
console.info(`\t` + JSON.stringify(parts));

let check = await b58c.checksum({
pubKeyHash: parts.pubKeyHash,
});
if (parts.check !== check) {
throw new Error("checksum({ privateKey }) failed");
}

try {
await b58c.checksum({
privateKey: parts.pubKeyHash,
});
throw new Error("allowed checksum of pubKeyHash for privateKey");
} catch (e) {
// ignore, expected
}

let full = await b58c.encode(parts);
console.info(`\t${full}`);

Expand Down
Loading