-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from Road2Crypto/ahmed/update
Update Package Name, Import style and Doc
- Loading branch information
Showing
5 changed files
with
93 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,50 @@ | ||
{ | ||
"name": "road2crypto-wallet-address-validator", | ||
"version": "1.1.1", | ||
"name": "r2c-wallet-validator", | ||
"version": "0.0.1", | ||
"description": "A simple utility to validate cryptocurrency wallet addresses for EVM, Solana, and Bitcoin chains.", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"exports": { | ||
".": { | ||
"import": "./dist/index.js", | ||
"require": "./dist/index.js" | ||
}, | ||
"./dist": "./dist", | ||
"./src": "./src" | ||
}, | ||
"scripts": { | ||
"build": "tsc", | ||
"setup": "npm i && npm run build", | ||
"test": "npm run setup && jest", | ||
"prepublishOnly": "npm run build", | ||
"publish": "npm test && npm publish --access public" | ||
"build": "tsc", | ||
"setup": "npm i && npm run build", | ||
"test": "npm run setup && jest", | ||
"prepublishOnly": "npm run build", | ||
"publish": "npm test && npm publish --access public" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/Road2Crypto/wallet-address-validator.git" | ||
"type": "git", | ||
"url": "https://github.com/Road2Crypto/wallet-address-validator.git" | ||
}, | ||
"keywords": [ | ||
"wallet", | ||
"address", | ||
"validator", | ||
"cryptocurrency", | ||
"EVM", | ||
"Solana", | ||
"Bitcoin" | ||
"wallet", | ||
"address", | ||
"validator", | ||
"cryptocurrency", | ||
"EVM", | ||
"Solana", | ||
"Bitcoin" | ||
], | ||
"author": "Road2Crypto", | ||
"license": "MIT", | ||
"dependencies": { | ||
"web3-validator": "2.0.5" | ||
"web3-validator": "2.0.5" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "7.24.5", | ||
"@babel/preset-env": "7.24.5", | ||
"@babel/preset-typescript": "7.24.1", | ||
"@types/jest": "29.5.12", | ||
"babel-jest": "29.7.0", | ||
"jest": "29.7.0", | ||
"ts-jest": "29.1.3", | ||
"typescript": "5.4.5" | ||
"@babel/core": "7.24.5", | ||
"@babel/preset-env": "7.24.5", | ||
"@babel/preset-typescript": "7.24.1", | ||
"@types/jest": "29.5.12", | ||
"babel-jest": "29.7.0", | ||
"jest": "29.7.0", | ||
"ts-jest": "29.1.3", | ||
"typescript": "5.4.5" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,27 @@ | ||
import { checkEmpty } from "./utils/checkEmpty"; | ||
import { getWalletType } from "./utils/getWalletType"; | ||
import { Response, ValidationErrorMessage } from "./types/response"; | ||
import { WalletValidationResponse, ValidationErrorMessage } from "./types/response"; | ||
|
||
// Function to check crypto address | ||
export const isWalletValid = (address: string): Response => { | ||
export const isWalletValid = (address: string): WalletValidationResponse => { | ||
// Remove extra spaces | ||
address = address.trim(); | ||
|
||
// Check if the address is empty | ||
if (checkEmpty(address)) return { valid: false, error: { statusCode: 400, message: ValidationErrorMessage.EMPTY_ADDRESS } }; | ||
if (checkEmpty(address)) { | ||
return { valid: false, error: { statusCode: 400, message: ValidationErrorMessage.EMPTY_ADDRESS } }; | ||
} | ||
|
||
// Get address type and validate it | ||
const walletAddressType = getWalletType(address); | ||
if (walletAddressType === null) return { valid: false, error: { statusCode: 400, message: ValidationErrorMessage.INVALID_ADDRESS } }; | ||
if (walletAddressType === null) { | ||
return { valid: false, error: { statusCode: 400, message: ValidationErrorMessage.INVALID_ADDRESS } }; | ||
} | ||
|
||
// Return success response | ||
return { valid: true, type: walletAddressType }; | ||
}; | ||
|
||
// Re-exporting types for easier import in other files | ||
export { ValidationErrorMessage } from "./types/response"; | ||
export { WalletType } from "./types/wallet"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters