Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

wallet.ts

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wallet.ts - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

dist/BitcoinAddress/index.d.ts

33

dist/EthereumAddress/index.js

@@ -7,6 +7,2 @@ 'use strict';

var _elliptic = require('elliptic');
var _elliptic2 = _interopRequireDefault(_elliptic);
var _js = require('keccak/js');

@@ -16,11 +12,9 @@

var _util = require('../util');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const secp256k1 = new _elliptic2.default.ec('secp256k1');
class EthereumAddress {
constructor(publicKey) {
if (!isPublicKeyValid(publicKey)) {
throw new Error('invalid public key');
}
this._publicKey = uncompressPublicKey(publicKey);
this._publicKey = (0, _util.uncompressPublicKey)(publicKey);
}

@@ -55,3 +49,9 @@ static from(publicKey) {

}
return addr === EthereumAddress.checksumAddress(addr).slice(2);
let checksumAddress;
try {
checksumAddress = EthereumAddress.checksumAddress(addr);
} catch (_err) {
return false;
}
return addr === checksumAddress.slice(2);
}

@@ -75,13 +75,2 @@ get publicKey() {

}
exports.default = EthereumAddress;
function isPublicKeyValid(publicKey) {
const length = publicKey.length;
if (length !== 33 && length !== 65) {
return false;
}
const firstByte = publicKey[0];
return firstByte >= 2 && firstByte <= 4;
}
function uncompressPublicKey(publicKey) {
return Buffer.from(secp256k1.keyFromPublic(publicKey).getPublic().encode());
}
exports.default = EthereumAddress;

@@ -89,2 +89,8 @@ 'use strict';

});
test('rejects addresses with invalid characters', () => {
expect(_2.default.isValid('0x5aAeb60!3F3E94C9b9A09f33669435E7Ef1BeAed')).toBe(false);
expect(_2.default.isValid('0xfB 916095ca1df60bB79Ce92cE3Ea74c37c5d359')).toBe(false);
expect(_2.default.isValid('5aAeb6$53F3E94C9b9A09f33669435E7Ef1BeAed')).toBe(false);
expect(_2.default.isValid('fB6916095ca1df60#B79Ce92cE3Ea74c37c5d359')).toBe(false);
});
test('accepts addresses with valid mixed-case checksum', () => {

@@ -91,0 +97,0 @@ expect(_2.default.isValid('0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed')).toBe(true);

/// <reference types="node" />
import { VersionBytes } from './versions';
import { VersionBytes } from '../versions';
export interface HDKeyConstructorOptions {

@@ -4,0 +4,0 @@ chainCode: Buffer;

@@ -15,3 +15,3 @@ 'use strict';

var _versions = require('./versions');
var _versions = require('../versions');

@@ -60,3 +60,3 @@ var _versions2 = _interopRequireDefault(_versions);

// version_bytes[4] || depth[1] || parent_fingerprint[4] || index[4] || chain_code[32] || key_data[33] || checksum[4]
const decoded = new Buffer(_bs2.default.decode(key));
const decoded = Buffer.from(_bs2.default.decode(key));
if (decoded.length > 112) {

@@ -85,3 +85,3 @@ throw new Error('invalid extended key');

const publicKey = keyData[0] !== 0 ? keyData : undefined;
if (privateKey && versionRead !== version.private || publicKey && versionRead !== version.public) {
if (privateKey && versionRead !== version.bip32.private || publicKey && versionRead !== version.bip32.public) {
throw new Error('invalid version bytes');

@@ -127,6 +127,6 @@ }

get extendedPrivateKey() {
return this._privateKey ? this.serialize(this._version.private, this._privateKey) : null;
return this._privateKey ? this.serialize(this._version.bip32.private, this._privateKey) : null;
}
get extendedPublicKey() {
return this.serialize(this._version.public, this._publicKey);
return this.serialize(this._version.bip32.public, this._publicKey);
}

@@ -158,3 +158,3 @@ derive(chain) {

let index = childIndex;
const data = new Buffer(37);
const data = Buffer.alloc(37);
let o = 0;

@@ -206,3 +206,3 @@ if (hardened) {

}
const compressedChildKey = new Buffer(childKey.encode(null, true));
const compressedChildKey = Buffer.from(childKey.encode(null, true));
return new HDKey({

@@ -220,3 +220,3 @@ depth: this.depth + 1,

// version_bytes[4] || depth[1] || parent_fingerprint[4] || index[4] || chain_code[32] || key_data[33] || checksum[4]
const buf = new Buffer(78);
const buf = Buffer.alloc(78);
let o = buf.writeUInt32BE(version, 0);

@@ -223,0 +223,0 @@ o = buf.writeUInt8(this.depth, o);

@@ -0,10 +1,17 @@

/// <reference types="node" />
import BitcoinAddress from './BitcoinAddress';
import EthereumAddress from './EthereumAddress';
import HDKey from './HDKey';
import Mnemonic from './Mnemonic';
export { EthereumAddress, HDKey, Mnemonic };
import util from './util';
export { BitcoinAddress, EthereumAddress, HDKey, Mnemonic, util };
declare const _default: {
BitcoinAddress: typeof BitcoinAddress;
EthereumAddress: typeof EthereumAddress;
HDKey: typeof HDKey;
Mnemonic: typeof Mnemonic;
util: {
uncompressPublicKey: (publicKey: Buffer) => Buffer;
};
};
export default _default;

@@ -6,4 +6,8 @@ 'use strict';

});
exports.Mnemonic = exports.HDKey = exports.EthereumAddress = undefined;
exports.util = exports.Mnemonic = exports.HDKey = exports.EthereumAddress = exports.BitcoinAddress = undefined;
var _BitcoinAddress = require('./BitcoinAddress');
var _BitcoinAddress2 = _interopRequireDefault(_BitcoinAddress);
var _EthereumAddress = require('./EthereumAddress');

@@ -21,11 +25,19 @@

var _util = require('./util');
var _util2 = _interopRequireDefault(_util);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.BitcoinAddress = _BitcoinAddress2.default;
exports.EthereumAddress = _EthereumAddress2.default;
exports.HDKey = _HDKey2.default;
exports.Mnemonic = _Mnemonic2.default;
exports.util = _util2.default;
exports.default = {
BitcoinAddress: _BitcoinAddress2.default,
EthereumAddress: _EthereumAddress2.default,
HDKey: _HDKey2.default,
Mnemonic: _Mnemonic2.default
Mnemonic: _Mnemonic2.default,
util: _util2.default
};
{
"name": "wallet.ts",
"version": "0.1.1",
"version": "0.2.0",
"description": "Utilities for cryptocurrency wallets, written in TypeScript",

@@ -5,0 +5,0 @@ "keywords": ["crypto", "cryptocurrency", "bip32", "bip39", "bip44", "hdkey", "mnemonic", "bitcoin", "ethereum", "litecoin", "eip55", "erc20", "wallet", "typescript"],

@@ -36,2 +36,4 @@ wallet.ts

[View Source](https://github.com/petejkim/wallet.ts/blob/master/src/HDKey/index.ts)
## Mnemonic code for generating deterministic keys [(BIP 38)](https://github.com/bitcoin/bips/blob/master/bip-38.mediawiki)

@@ -56,2 +58,23 @@

[View Source](https://github.com/petejkim/wallet.ts/blob/master/src/Mnemonic/index.ts)
## Bitcoin Address
```javascript
const { BitcoinAddress } = require('wallet.ts')
const publicKey = Buffer.from(
'0250863ad64a87ae8a2fe83c1af1a8403cb53f53e486d8511dad8a04887e5b2352',
'hex'
)
const address = BitcoinAddress.from(publicKey).address
// => '16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM'
const valid = BitcoinAddress.isValid(address)
// => true
```
[View Source](https://github.com/petejkim/wallet.ts/blob/master/src/BitcoinAddress/index.ts)
## Ethereum Address / EIP 55 checksum

@@ -67,3 +90,3 @@

const address = EthereumAddress.from(publicKey)
const address = EthereumAddress.from(publicKey).address
// => 0xD11A13f484E2f2bD22d93c3C3131f61c05E876a

@@ -78,3 +101,5 @@

[View Source](https://github.com/petejkim/wallet.ts/blob/master/src/EthereumAddress/index.ts)
- - -
Copyright © 2017 Peter Jihoon Kim. This project is licensed under the [ISC license](https://raw.githubusercontent.com/petejkim/wallet.ts/master/LICENSE).
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc