mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 12:15:51 +00:00
Add isValidAddress
This commit is contained in:
@@ -15,5 +15,6 @@ module.exports = {
|
||||
convertExceptions: utils.convertExceptions,
|
||||
convertKeysFromSnakeCaseToCamelCase:
|
||||
utils.convertKeysFromSnakeCaseToCamelCase,
|
||||
promisify: utils.promisify
|
||||
promisify: utils.promisify,
|
||||
isValidAddress: require('./schema-validator').isValidAddress
|
||||
};
|
||||
|
||||
@@ -11,7 +11,7 @@ const ValidationError = require('./errors').ValidationError;
|
||||
|
||||
let SCHEMAS = {};
|
||||
|
||||
function isValidAddress(address) {
|
||||
function isValidAddress(address: string): boolean {
|
||||
return core.UInt160.is_valid(address);
|
||||
}
|
||||
|
||||
@@ -68,6 +68,7 @@ function schemaValidate(schemaName: string, object: any): void {
|
||||
SCHEMAS = loadSchemas(path.join(__dirname, './schemas'));
|
||||
module.exports = {
|
||||
schemaValidate: schemaValidate,
|
||||
isValidAddress: isValidAddress,
|
||||
loadSchema: loadSchema,
|
||||
SCHEMAS: SCHEMAS
|
||||
};
|
||||
|
||||
@@ -31,6 +31,7 @@ const convertExceptions = require('./common').convertExceptions;
|
||||
const generateWallet = convertExceptions(common.generateWallet);
|
||||
const computeLedgerHash = require('./offline/ledgerhash');
|
||||
const getLedger = require('./ledger/ledger');
|
||||
const isValidAddress = common.isValidAddress;
|
||||
|
||||
function RippleAPI(options: {}) {
|
||||
const _options = _.assign({}, options, {automatic_resubmission: false});
|
||||
@@ -65,6 +66,7 @@ RippleAPI.prototype = {
|
||||
submit,
|
||||
|
||||
computeLedgerHash,
|
||||
isValidAddress,
|
||||
generateWallet,
|
||||
errors
|
||||
};
|
||||
|
||||
@@ -793,4 +793,14 @@ describe('RippleAPI - offline', function() {
|
||||
requests.computeLedgerHash.transactions);
|
||||
assert.throws(() => api.computeLedgerHash(header));
|
||||
});
|
||||
|
||||
it('isValidAddress - valid', function() {
|
||||
const api = new RippleAPI();
|
||||
assert(api.isValidAddress(address));
|
||||
});
|
||||
|
||||
it('isValidAddress - invalid', function() {
|
||||
const api = new RippleAPI();
|
||||
assert(!api.isValidAddress(address.slice(0, -1) + 'a'));
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user