|
| 1 | +# NameAI SDK |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +[NameAI](https://nameai.dev) extends [NameGuard](https://nameguard.io) with sophisticated natural language processing capabilities to help evaluate and understand Ethereum Name Service (ENS) names. |
| 6 | + |
| 7 | +[NameGuard](https://nameguard.io) is designed to inspect and prevent malicious use of ENS names by providing comprehensive security checks. See the [NameGuard SDK documentation](../nameguard-sdk/README.md) for details about the base security features. |
| 8 | + |
| 9 | +⚠️ **This SDK is BETA. Things will change based on the community feedback.** |
| 10 | + |
| 11 | +## Features |
| 12 | + |
| 13 | +Additional features provided by NameAI on top of NameGuard: |
| 14 | +- **Natural Language Processing**: Evaluate how well ENS names represent meaningful words or phrases |
| 15 | +- **Tokenization**: Break down names into meaningful word components with probability scoring |
| 16 | +- **Purity Scoring**: Assess the cleanliness and quality of ENS names |
| 17 | +- **Sort Scoring**: Get relative ranking scores for ENS names |
| 18 | + |
| 19 | +The `@namehash/nameai` SDK provides full type-safety when working with the NameAI API. |
| 20 | + |
| 21 | +## Install |
| 22 | + |
| 23 | +Install NameAI via npm, yarn or pnpm: |
| 24 | + |
| 25 | +```bash |
| 26 | +npm install @namehash/nameai |
| 27 | +``` |
| 28 | + |
| 29 | +## Usage |
| 30 | + |
| 31 | +Import `nameai`: |
| 32 | + |
| 33 | +```ts |
| 34 | +import { nameai } from "@namehash/nameai"; |
| 35 | +``` |
| 36 | + |
| 37 | +### Basic Name Inspection |
| 38 | + |
| 39 | +Inspect a name: |
| 40 | + |
| 41 | +```ts |
| 42 | +const report = await nameai.inspectName("vitalik.eth"); |
| 43 | + |
| 44 | +// Example response: |
| 45 | +{ |
| 46 | + nameai: { |
| 47 | + // Quality score (0.0 to 1.0) for the first label |
| 48 | + purity_score: 0.29, |
| 49 | + |
| 50 | + // Ranking score (0.0 to 1.0) for the first label |
| 51 | + sort_score: 0.35, |
| 52 | + |
| 53 | + analysis: { // undefined for uninspected names |
| 54 | + // The normalization status of the name (normalized, unnormalized, or unknown) |
| 55 | + status: "normalized", |
| 56 | + |
| 57 | + // Details about the inspected name component |
| 58 | + inspection: { |
| 59 | + label: "vitalik", |
| 60 | + // ... other inspection details |
| 61 | + }, |
| 62 | + |
| 63 | + // Text meaningfulness (0.0 to 1.0) |
| 64 | + probability: 0.95, |
| 65 | + |
| 66 | + // Natural log of probability (≤ 0.0) |
| 67 | + log_probability: -0.05, |
| 68 | + |
| 69 | + // Minimum words in valid tokenizations |
| 70 | + word_count: 1, |
| 71 | + |
| 72 | + // Recommended word breakdown (may be undefined) |
| 73 | + top_tokenization: ["vitalik"], |
| 74 | + |
| 75 | + // All possible tokenizations (up to 1000) |
| 76 | + tokenizations: [ |
| 77 | + { |
| 78 | + tokens: ["vitalik"], |
| 79 | + probability: 0.95, |
| 80 | + log_probability: -0.05 |
| 81 | + } |
| 82 | + ] |
| 83 | + } |
| 84 | + }, |
| 85 | + nameguard: NameGuardReport // Standard NameGuard security inspection |
| 86 | +} |
| 87 | +``` |
| 88 | + |
| 89 | +### Tokenization Inspection |
| 90 | + |
| 91 | +The SDK provides detailed tokenization inspection: |
| 92 | + |
| 93 | +```ts |
| 94 | +const { nameai: { analysis } } = await nameai.inspectName("cryptowallet.eth"); |
| 95 | + |
| 96 | +console.log(analysis.top_tokenization); // ["crypto", "wallet"] |
| 97 | +console.log(analysis.tokenizations); // Array of possible tokenizations with probabilities |
| 98 | +``` |
| 99 | + |
| 100 | +### Custom Client |
| 101 | + |
| 102 | +You can create a custom client with different settings: |
| 103 | + |
| 104 | +```ts |
| 105 | +import { createClient } from "@namehash/nameai"; |
| 106 | + |
| 107 | +const nameai = createClient({ |
| 108 | + nameaiEndpoint: "...", |
| 109 | + network: "sepolia" |
| 110 | +}); |
| 111 | +``` |
| 112 | + |
| 113 | +## Limitations |
| 114 | + |
| 115 | +- Maximum name length: 200 characters (including dots) |
| 116 | +- Maximum unknown labels: 5 |
| 117 | +- Names exceeding these limits will have undefined analysis |
| 118 | + |
| 119 | +## Contact Us |
| 120 | + |
| 121 | +Visit our [website](https://namehashlabs.org/) to get in contact. |
| 122 | + |
| 123 | +## License |
| 124 | + |
| 125 | +Licensed under the MIT License, Copyright © 2023-present [NameHash Labs](https://namehashlabs.org). |
| 126 | + |
| 127 | +See [LICENSE](./LICENSE) for more information. |
0 commit comments