Skip to content
This repository was archived by the owner on Oct 30, 2024. It is now read-only.

Commit ebd88c5

Browse files
committed
Update README, bump version to 0.4.0
1 parent 553485f commit ebd88c5

6 files changed

Lines changed: 37 additions & 46 deletions

File tree

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ npm install trezor-address-validator
2828

2929
> Returns true if the address (string) is a valid wallet address for the crypto currency specified, see below for supported currencies.
3030
31+
32+
##### getAddressType (address [, currency = 'bitcoin'[, networkType = 'prod']])
33+
34+
###### Parameters
35+
* address - Wallet address to validate.
36+
* currency - Optional. Currency name or symbol, e.g. `'bitcoin'` (default), `'litecoin'` or `'LTC'`
37+
* networkType - Optional. Use `'prod'` (default) to enforce standard address, `'testnet'` to enforce testnet address and `'both'` to enforce nothing.
38+
39+
> Returns address type (`'address' | 'p2pkh' | 'p2wpkh' | 'p2wsh' | 'p2sh' | 'p2tr' | 'pw-unknown'`) of the address or `undefined` if the address is invalid.
3140
### Supported crypto currencies
3241

3342
* 0x/zrx `'0x'` or `'zrx'`
@@ -57,6 +66,7 @@ npm install trezor-address-validator
5766
* BeaverCoin/bvc `'BeaverCoin'` or `'bvc'`
5867
* BetterBetting/betr `'BetterBetting'` or `'betr'`
5968
* Binance/bnb `'Binance'` or `'bnb'`
69+
* Binance Smart Chain/bsc `'Binance Smart Chain'` or `'bsc'`
6070
* Binance USD/busd `'Binance USD'` or `'busd'`
6171
* BioCoin/bio `'BioCoin'` or `'bio'`
6272
* Bitcoin/btc `'Bitcoin'` or `'btc'`

dist/wallet-address-validator.js

Lines changed: 23 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13590,12 +13590,8 @@ const addressType = {
1359013590
WITNESS_UNKNOWN: 'p2w-unknown',
1359113591
};
1359213592

13593-
function numberToHex(number) {
13594-
var hex = Math.round(number).toString(16)
13595-
if (hex.length === 1) {
13596-
hex = '0' + hex
13597-
}
13598-
return hex
13593+
function numberToHex(number, sizeInBytes) {
13594+
return Math.round(number).toString(16).padStart(sizeInBytes * 2, '0');
1359913595
}
1360013596

1360113597
function isHexChar(c) {
@@ -13663,10 +13659,11 @@ function hexStr2byteArray(str) {
1366313659
}
1366413660

1366513661
module.exports = {
13662+
numberToHex,
1366613663
toHex: function (arrayOfBytes) {
1366713664
var hex = '';
1366813665
for (var i = 0; i < arrayOfBytes.length; i++) {
13669-
hex += numberToHex(arrayOfBytes[i]);
13666+
hex += numberToHex(arrayOfBytes[i], 1);
1367013667
}
1367113668
return hex;
1367213669
},
@@ -14910,11 +14907,7 @@ var CURRENCIES = [
1491014907
name: 'Zilliqa',
1491114908
symbol: 'zil',
1491214909
validator: ZILValidator
14913-
}, {
14914-
name: 'Binance Smart Chain',
14915-
symbol: 'bsc',
14916-
validator: ETHValidator,
14917-
}
14910+
}
1491814911
];
1491914912

1492014913

@@ -15377,50 +15370,42 @@ module.exports = {
1537715370

1537815371
},{"../src/crypto/utils":144}],159:[function(require,module,exports){
1537915372
const { addressType } = require('../src/crypto/utils');
15380-
var baseX = require('base-x');
15381-
var crc = require('crc');
15382-
var cryptoUtils = require('./crypto/utils');
15373+
const baseX = require('base-x');
15374+
const crc = require('crc');
15375+
const cryptoUtils = require('./crypto/utils');
1538315376

15384-
var ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
15377+
const ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
1538515378

15386-
var base32 = baseX(ALPHABET);
15387-
var regexp = new RegExp('^[' + ALPHABET + ']{56}$');
15388-
var ed25519PublicKeyVersionByte = (6 << 3);
15379+
const base32 = baseX(ALPHABET);
15380+
const regexp = new RegExp('^[' + ALPHABET + ']{56}$');
15381+
const ed25519PublicKeyVersionByte = (6 << 3);
1538915382

15390-
function swap16(number) {
15391-
var lower = number & 0xFF;
15392-
var upper = (number >> 8) & 0xFF;
15383+
function swap16(number) {
15384+
const lower = number & 0xFF;
15385+
const upper = (number >> 8) & 0xFF;
1539315386
return (lower << 8) | upper;
1539415387
}
1539515388

15396-
function numberToHex(number) {
15397-
var hex = number.toString(16);
15398-
if(hex.length % 2 === 1) {
15399-
hex = '0' + hex;
15400-
}
15401-
return hex;
15402-
}
15403-
15404-
module.exports = {
15389+
module.exports = {
1540515390
isValidAddress: function (address) {
1540615391
if (regexp.test(address)) {
1540715392
return this.verifyChecksum(address);
1540815393
}
1540915394

15410-
return false;
15395+
return false;
1541115396
},
1541215397

1541315398
verifyChecksum: function (address) {
15414-
// based on https://github.com/stellar/js-stellar-base/blob/master/src/strkey.js#L126
15415-
var bytes = base32.decode(address);
15399+
// based on https://github.com/stellar/js-stellar-base/blob/master/src/strkey.js
15400+
const bytes = base32.decode(address);
1541615401
if (bytes[0] !== ed25519PublicKeyVersionByte) {
1541715402
return false;
1541815403
}
1541915404

15420-
var computedChecksum = numberToHex(swap16(crc.crc16xmodem(bytes.slice(0, -2))));
15421-
var checksum = cryptoUtils.toHex(bytes.slice(-2));
15422-
15423-
return computedChecksum === checksum
15405+
const payload = bytes.slice(0, -2);
15406+
const checksum = cryptoUtils.toHex(bytes.slice(-2));
15407+
const computedChecksum = cryptoUtils.numberToHex(swap16(crc.crc16xmodem(payload)), 2);
15408+
return computedChecksum === checksum;
1542415409
},
1542515410

1542615411
getAddressType: function (address, currency, networkType) {

dist/wallet-address-validator.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"browser",
3636
"nodejs"
3737
],
38-
"version": "0.3.22",
38+
"version": "0.4.0",
3939
"author": "Martin <martin.bohm@satoshilabs.com>",
4040
"homepage": "https://github.com/trezor/trezor-address-validator",
4141
"license": "MIT",

src/currencies.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,11 +1193,7 @@ var CURRENCIES = [
11931193
name: 'Zilliqa',
11941194
symbol: 'zil',
11951195
validator: ZILValidator
1196-
}, {
1197-
name: 'Binance Smart Chain',
1198-
symbol: 'bsc',
1199-
validator: ETHValidator,
1200-
}
1196+
}
12011197
];
12021198

12031199

src/wallet_address_validator.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ declare module 'trezor-address-validator' {
22
export interface Currency {
33
name: string,
44
symbol: string,
5-
};
5+
}
66
export type AddressType = 'address' | 'p2pkh' | 'p2wpkh' | 'p2wsh' | 'p2sh' | 'p2tr' | 'pw-unknown';
77
export function validate(address: string, currencyNameOrSymbol?: string, networkType?: string): boolean;
88
export function getAddressType(address: string, currencyNameOrSymbol?: string, networkType?: string): AddressType | undefined;

0 commit comments

Comments
 (0)