Skip to content
This repository has been archived by the owner on Mar 7, 2023. It is now read-only.

Commit

Permalink
fix(keys): keys shorter than 32 bytes are now usable
Browse files Browse the repository at this point in the history
  • Loading branch information
sha49 committed Feb 20, 2016
1 parent 97fee6a commit 2617c1f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ module.exports = {
Shared: require('./src/shared'),
WalletTokenEndpoints: require('./src/wallet-token-endpoints'),
WalletNetwork: require('./src/wallet-network'),
RNG: require('./src/rng')
RNG: require('./src/rng'),
// Wallet: require('./blockchain-wallet'),
// Address: require('./address'),
Address: require('./src/address')
// HDAccount: require('./hd-account'),
// HDWallet: require('./hd-wallet'),
// KeyChain: require('./keychain'),
Expand Down
6 changes: 2 additions & 4 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ Helpers.isBitcoinPrivateKey = function(candidate) {
}
catch (e) { return false; };
};
Helpers.isBase58Key = function(k) {
return Helpers.isString(k) &&
(/^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{44}$/.test(k) ||
/^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{43}$/.test(k))
Helpers.isBase58Key = function(str) {
return Helpers.isString(str) && /^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]+$/.test(str);
};
Helpers.isXprivKey = function(k) {
return Helpers.isString(k) && k.substring(0, 4) === "xprv";
Expand Down
6 changes: 3 additions & 3 deletions src/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,9 @@ MyWallet.detectPrivateKeyFormat = function(key) {
return 'mini';
}

if (/^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]+$/.test(key))
return 'base58';

return null;

console.error('Unknown Key Format ' + key);
Expand Down Expand Up @@ -930,9 +933,6 @@ MyWallet.privateKeyStringToKey = function(value, format) {
throw 'Unsupported Key Format';
}

if (key_bytes.length != 32 && key_bytes.length != 33)
throw 'Result not 32 or 33 bytes in length';

return new ECKey(new BigInteger.fromByteArrayUnsigned(key_bytes), (format !== 'sipa'));
};
// used once
Expand Down

0 comments on commit 2617c1f

Please sign in to comment.