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

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoxianming committed Aug 16, 2018
2 parents a4356c6 + abc0d07 commit a46b7af
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
4 changes: 2 additions & 2 deletions chains/iris/iris_keypair.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ class CosmosKeypair {
}

static isValidAddress(address) {
//return /^[0-9a-fA-F]{40}$/i.test(address);
return true;
let prefix = Constants.IrisNetConfig.PREFIX_BECH32_ACCADDR;
return Codec.Bech32.isBech32(prefix,address);
}

static isValidPrivate(privateKey) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "irisnet-crypto",
"version": "1.1.0",
"version": "1.1.1",
"description": "irisnet-crypto",
"main": "index.js",
"scripts": {
Expand Down
11 changes: 6 additions & 5 deletions test/crypto_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,12 @@ describe('CryPto test', function () {
console.log(sigByte.toString());
});

it('test codec', function () {
let s = Codec.Hex.hexToBytes("1EC2E86065D5EF88A3ED65B8B3A43210FAD9C7B2")
let s1 = Codec.Bech32.fromBech32("cosmosaccaddr1mgtyzhvfj424q9r35dmr70qtt63cpc58dct7jq");
console.log(s);
console.log(s1);
it('test isValidAddress', function () {
let addr = "faa1a89us8tvt3d9qpq7j6p06dc3z88n576shj8k2h";
let crypto = Irisnet.getCrypto(Irisnet.Constants.COMM.Chains.IRIS);
let result = crypto.isValidAddress(addr)
assert.isTrue(result);
})

});
});
17 changes: 16 additions & 1 deletion util/codec.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,24 @@ const bech32 = class {
* @returns {*} bech32编码后的字符串
*/
static toBech32(prefix, str) {
let strByte = BECH32.toWords(Buffer.from(str, 'hex'))
let strByte = BECH32.toWords(Buffer.from(str, 'hex'));
return BECH32.encode(prefix, strByte)
}

/**
*
* @param prefix bech32编码
* @param str 待编码的字符串
* @returns
*/
static isBech32(prefix, str) {
if (!prefix || prefix.length == 0) {
return false
}
let preReg = new RegExp('^' + prefix + '1');
let allReg = new RegExp(/^[0-9a-zA-Z]*$/i);
return preReg.test(str) && allReg.test(str)
}
};

Codec.Hex = hex;
Expand Down

0 comments on commit a46b7af

Please sign in to comment.