@vinicius16187/crypto-logos 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +189 -0
- package/dist/index.d.mts +27 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +78 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +69 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +47 -0
package/README.md
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
# @seu-scope/crypto-logos
|
|
2
|
+
|
|
3
|
+
Resolve logo URLs for blockchains and ERC-20 tokens using the [TrustWallet Assets](https://github.com/trustwallet/assets) repository via **jsDelivr CDN** with a pinned commit (never `@master`).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @seu-scope/crypto-logos
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @seu-scope/crypto-logos
|
|
11
|
+
# or
|
|
12
|
+
yarn add @seu-scope/crypto-logos
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
> **Note:** `ethers` v6 is a required peer dependency for EIP-55 address checksumming.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Supported Chains
|
|
20
|
+
|
|
21
|
+
| User-facing name | TrustWallet directory |
|
|
22
|
+
|---|---|
|
|
23
|
+
| `ethereum` / `eth` | `ethereum` |
|
|
24
|
+
| `polygon` / `matic` | `polygon` |
|
|
25
|
+
| `bsc` / `bnb` | `smartchain` |
|
|
26
|
+
| `arbitrum` / `arbitrum-one` | `arbitrum` |
|
|
27
|
+
| `avalanche` / `avax` | `avalanchec` |
|
|
28
|
+
| `optimism` / `op` | `optimism` |
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
### Native token logo
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { getNativeLogoUrl } from "@seu-scope/crypto-logos";
|
|
38
|
+
|
|
39
|
+
const ethLogo = getNativeLogoUrl({ chain: "ethereum" });
|
|
40
|
+
// https://cdn.jsdelivr.net/gh/trustwallet/assets@{COMMIT}/blockchains/ethereum/info/logo.png
|
|
41
|
+
|
|
42
|
+
const maticLogo = getNativeLogoUrl({ chain: "matic" }); // alias for polygon
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### ERC-20 token logo
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { getTokenLogoUrl } from "@seu-scope/crypto-logos";
|
|
49
|
+
|
|
50
|
+
const usdtLogo = getTokenLogoUrl({
|
|
51
|
+
chain: "ethereum",
|
|
52
|
+
address: "0xdac17f958d2ee523a2206206994597c13d831ec7",
|
|
53
|
+
// Address is automatically converted to EIP-55 checksum
|
|
54
|
+
});
|
|
55
|
+
// https://cdn.jsdelivr.net/gh/trustwallet/assets@{COMMIT}/blockchains/ethereum/assets/0xdAC17F958D2ee523a2206206994597C13D831ec7/logo.png
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### resolveLogo — unified resolver
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
import { resolveLogo } from "@seu-scope/crypto-logos";
|
|
62
|
+
|
|
63
|
+
// Priority: customLogoUrl → token (address) → native
|
|
64
|
+
resolveLogo({ chain: "ethereum" });
|
|
65
|
+
// → native ETH logo
|
|
66
|
+
|
|
67
|
+
resolveLogo({ chain: "polygon", address: "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174" });
|
|
68
|
+
// → USDC on Polygon logo (checksummed address)
|
|
69
|
+
|
|
70
|
+
resolveLogo({
|
|
71
|
+
chain: "bsc",
|
|
72
|
+
address: "0x55d398326f99059fF775485246999027B3197955",
|
|
73
|
+
customLogoUrl: "https://my-cdn.example.com/usdt.png",
|
|
74
|
+
});
|
|
75
|
+
// → "https://my-cdn.example.com/usdt.png" (customLogoUrl wins)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## API Reference
|
|
81
|
+
|
|
82
|
+
### `getNativeLogoUrl(options: NativeOptions): string`
|
|
83
|
+
|
|
84
|
+
| Param | Type | Description |
|
|
85
|
+
|---|---|---|
|
|
86
|
+
| `chain` | `string` | Chain name or alias (e.g. `"eth"`, `"matic"`) |
|
|
87
|
+
|
|
88
|
+
### `getTokenLogoUrl(options: TokenOptions): string`
|
|
89
|
+
|
|
90
|
+
| Param | Type | Description |
|
|
91
|
+
|---|---|---|
|
|
92
|
+
| `chain` | `string` | Chain name or alias |
|
|
93
|
+
| `address` | `string` | Token contract address (checksum applied automatically) |
|
|
94
|
+
|
|
95
|
+
### `resolveLogo(input: LogoInput): string`
|
|
96
|
+
|
|
97
|
+
| Param | Type | Description |
|
|
98
|
+
|---|---|---|
|
|
99
|
+
| `chain` | `string` | Chain name or alias |
|
|
100
|
+
| `address` | `string?` | Token contract address |
|
|
101
|
+
| `customLogoUrl` | `string?` | Override URL — returned as-is if provided |
|
|
102
|
+
|
|
103
|
+
### `normalizeChain(chain: string): SupportedChain`
|
|
104
|
+
|
|
105
|
+
Converts any chain alias to its canonical `SupportedChain` value. Throws if the chain is not supported.
|
|
106
|
+
|
|
107
|
+
### `toChecksum(address: string): string`
|
|
108
|
+
|
|
109
|
+
Converts an Ethereum address to its EIP-55 checksummed form using `ethers.getAddress`.
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## React example with fallback
|
|
114
|
+
|
|
115
|
+
```tsx
|
|
116
|
+
import { resolveLogo } from "@seu-scope/crypto-logos";
|
|
117
|
+
|
|
118
|
+
interface TokenLogoProps {
|
|
119
|
+
chain: string;
|
|
120
|
+
address?: string;
|
|
121
|
+
customLogoUrl?: string;
|
|
122
|
+
alt: string;
|
|
123
|
+
size?: number;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function TokenLogo({ chain, address, customLogoUrl, alt, size = 32 }: TokenLogoProps) {
|
|
127
|
+
const src = resolveLogo({ chain, address, customLogoUrl });
|
|
128
|
+
|
|
129
|
+
return (
|
|
130
|
+
<img
|
|
131
|
+
src={src}
|
|
132
|
+
alt={alt}
|
|
133
|
+
width={size}
|
|
134
|
+
height={size}
|
|
135
|
+
onError={(e) => {
|
|
136
|
+
(e.currentTarget as HTMLImageElement).src = "/fallback-token.png";
|
|
137
|
+
}}
|
|
138
|
+
/>
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Usage:
|
|
143
|
+
// <TokenLogo chain="ethereum" alt="ETH" />
|
|
144
|
+
// <TokenLogo chain="polygon" address="0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174" alt="USDC" />
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## Pinned commit
|
|
150
|
+
|
|
151
|
+
The CDN URL uses a **fixed commit hash** — never `@master` — to guarantee URL stability across deployments.
|
|
152
|
+
|
|
153
|
+
To update to a newer version of TrustWallet assets:
|
|
154
|
+
|
|
155
|
+
1. Find the latest commit at: https://github.com/trustwallet/assets/commits/master
|
|
156
|
+
2. Copy the full SHA
|
|
157
|
+
3. Update `TRUSTWALLET_COMMIT` in [src/constants.ts](src/constants.ts)
|
|
158
|
+
4. Rebuild: `npm run build`
|
|
159
|
+
|
|
160
|
+
```ts
|
|
161
|
+
// src/constants.ts
|
|
162
|
+
export const TRUSTWALLET_COMMIT = "YOUR_NEW_COMMIT_SHA_HERE";
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
## Build
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
npm install
|
|
171
|
+
npm run build
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Output in `dist/`:
|
|
175
|
+
- `index.js` — ESM
|
|
176
|
+
- `index.cjs` — CommonJS
|
|
177
|
+
- `index.d.ts` / `index.d.cts` — TypeScript declarations
|
|
178
|
+
|
|
179
|
+
## Publish
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
npm publish --access public
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
## License
|
|
188
|
+
|
|
189
|
+
MIT
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
interface NativeOptions {
|
|
2
|
+
chain: string;
|
|
3
|
+
}
|
|
4
|
+
interface TokenOptions {
|
|
5
|
+
chain: string;
|
|
6
|
+
address: string;
|
|
7
|
+
}
|
|
8
|
+
interface LogoInput {
|
|
9
|
+
chain: string;
|
|
10
|
+
address?: string;
|
|
11
|
+
customLogoUrl?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare function getNativeLogoUrl({ chain }: NativeOptions): string;
|
|
15
|
+
declare function getTokenLogoUrl({ chain, address }: TokenOptions): string;
|
|
16
|
+
declare function resolveLogo({ chain, address, customLogoUrl }: LogoInput): string;
|
|
17
|
+
|
|
18
|
+
type SupportedChain = "ethereum" | "polygon" | "bsc" | "arbitrum" | "avalanche" | "optimism";
|
|
19
|
+
declare const TRUSTWALLET_DIRS: Record<SupportedChain, string>;
|
|
20
|
+
declare function normalizeChain(chain: string): SupportedChain;
|
|
21
|
+
|
|
22
|
+
declare function toChecksum(address: string): string;
|
|
23
|
+
|
|
24
|
+
declare const TRUSTWALLET_COMMIT = "f26c0845ff29059965e316e1e5988e77e5087764";
|
|
25
|
+
declare const BASE_URL = "https://cdn.jsdelivr.net/gh/trustwallet/assets@f26c0845ff29059965e316e1e5988e77e5087764/blockchains";
|
|
26
|
+
|
|
27
|
+
export { BASE_URL, type LogoInput, type NativeOptions, type SupportedChain, TRUSTWALLET_COMMIT, TRUSTWALLET_DIRS, type TokenOptions, getNativeLogoUrl, getTokenLogoUrl, normalizeChain, resolveLogo, toChecksum };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
interface NativeOptions {
|
|
2
|
+
chain: string;
|
|
3
|
+
}
|
|
4
|
+
interface TokenOptions {
|
|
5
|
+
chain: string;
|
|
6
|
+
address: string;
|
|
7
|
+
}
|
|
8
|
+
interface LogoInput {
|
|
9
|
+
chain: string;
|
|
10
|
+
address?: string;
|
|
11
|
+
customLogoUrl?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare function getNativeLogoUrl({ chain }: NativeOptions): string;
|
|
15
|
+
declare function getTokenLogoUrl({ chain, address }: TokenOptions): string;
|
|
16
|
+
declare function resolveLogo({ chain, address, customLogoUrl }: LogoInput): string;
|
|
17
|
+
|
|
18
|
+
type SupportedChain = "ethereum" | "polygon" | "bsc" | "arbitrum" | "avalanche" | "optimism";
|
|
19
|
+
declare const TRUSTWALLET_DIRS: Record<SupportedChain, string>;
|
|
20
|
+
declare function normalizeChain(chain: string): SupportedChain;
|
|
21
|
+
|
|
22
|
+
declare function toChecksum(address: string): string;
|
|
23
|
+
|
|
24
|
+
declare const TRUSTWALLET_COMMIT = "f26c0845ff29059965e316e1e5988e77e5087764";
|
|
25
|
+
declare const BASE_URL = "https://cdn.jsdelivr.net/gh/trustwallet/assets@f26c0845ff29059965e316e1e5988e77e5087764/blockchains";
|
|
26
|
+
|
|
27
|
+
export { BASE_URL, type LogoInput, type NativeOptions, type SupportedChain, TRUSTWALLET_COMMIT, TRUSTWALLET_DIRS, type TokenOptions, getNativeLogoUrl, getTokenLogoUrl, normalizeChain, resolveLogo, toChecksum };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ethers = require('ethers');
|
|
4
|
+
|
|
5
|
+
// src/chains.ts
|
|
6
|
+
var CHAIN_ALIASES = {
|
|
7
|
+
ethereum: "ethereum",
|
|
8
|
+
eth: "ethereum",
|
|
9
|
+
polygon: "polygon",
|
|
10
|
+
matic: "polygon",
|
|
11
|
+
bsc: "bsc",
|
|
12
|
+
"binance-smart-chain": "bsc",
|
|
13
|
+
bnb: "bsc",
|
|
14
|
+
arbitrum: "arbitrum",
|
|
15
|
+
"arbitrum-one": "arbitrum",
|
|
16
|
+
avalanche: "avalanche",
|
|
17
|
+
avax: "avalanche",
|
|
18
|
+
optimism: "optimism",
|
|
19
|
+
op: "optimism"
|
|
20
|
+
};
|
|
21
|
+
var TRUSTWALLET_DIRS = {
|
|
22
|
+
ethereum: "ethereum",
|
|
23
|
+
polygon: "polygon",
|
|
24
|
+
bsc: "smartchain",
|
|
25
|
+
arbitrum: "arbitrum",
|
|
26
|
+
avalanche: "avalanchec",
|
|
27
|
+
optimism: "optimism"
|
|
28
|
+
};
|
|
29
|
+
function normalizeChain(chain) {
|
|
30
|
+
const key = chain.toLowerCase();
|
|
31
|
+
const normalized = CHAIN_ALIASES[key];
|
|
32
|
+
if (!normalized) {
|
|
33
|
+
throw new Error(
|
|
34
|
+
`Unsupported chain: "${chain}". Supported values: ${Object.keys(CHAIN_ALIASES).join(", ")}`
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
return normalized;
|
|
38
|
+
}
|
|
39
|
+
function toChecksum(address) {
|
|
40
|
+
return ethers.getAddress(address);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// src/constants.ts
|
|
44
|
+
var TRUSTWALLET_COMMIT = "f26c0845ff29059965e316e1e5988e77e5087764";
|
|
45
|
+
var BASE_URL = `https://cdn.jsdelivr.net/gh/trustwallet/assets@${TRUSTWALLET_COMMIT}/blockchains`;
|
|
46
|
+
|
|
47
|
+
// src/resolver.ts
|
|
48
|
+
function getNativeLogoUrl({ chain }) {
|
|
49
|
+
const normalized = normalizeChain(chain);
|
|
50
|
+
const dir = TRUSTWALLET_DIRS[normalized];
|
|
51
|
+
return `${BASE_URL}/${dir}/info/logo.png`;
|
|
52
|
+
}
|
|
53
|
+
function getTokenLogoUrl({ chain, address }) {
|
|
54
|
+
const normalized = normalizeChain(chain);
|
|
55
|
+
const dir = TRUSTWALLET_DIRS[normalized];
|
|
56
|
+
const checksumAddress = toChecksum(address);
|
|
57
|
+
return `${BASE_URL}/${dir}/assets/${checksumAddress}/logo.png`;
|
|
58
|
+
}
|
|
59
|
+
function resolveLogo({ chain, address, customLogoUrl }) {
|
|
60
|
+
if (customLogoUrl) {
|
|
61
|
+
return customLogoUrl;
|
|
62
|
+
}
|
|
63
|
+
if (address) {
|
|
64
|
+
return getTokenLogoUrl({ chain, address });
|
|
65
|
+
}
|
|
66
|
+
return getNativeLogoUrl({ chain });
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
exports.BASE_URL = BASE_URL;
|
|
70
|
+
exports.TRUSTWALLET_COMMIT = TRUSTWALLET_COMMIT;
|
|
71
|
+
exports.TRUSTWALLET_DIRS = TRUSTWALLET_DIRS;
|
|
72
|
+
exports.getNativeLogoUrl = getNativeLogoUrl;
|
|
73
|
+
exports.getTokenLogoUrl = getTokenLogoUrl;
|
|
74
|
+
exports.normalizeChain = normalizeChain;
|
|
75
|
+
exports.resolveLogo = resolveLogo;
|
|
76
|
+
exports.toChecksum = toChecksum;
|
|
77
|
+
//# sourceMappingURL=index.js.map
|
|
78
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/chains.ts","../src/checksum.ts","../src/constants.ts","../src/resolver.ts"],"names":["getAddress"],"mappings":";;;;;AAQA,IAAM,aAAA,GAAgD;AAAA,EACpD,QAAA,EAAU,UAAA;AAAA,EACV,GAAA,EAAK,UAAA;AAAA,EACL,OAAA,EAAS,SAAA;AAAA,EACT,KAAA,EAAO,SAAA;AAAA,EACP,GAAA,EAAK,KAAA;AAAA,EACL,qBAAA,EAAuB,KAAA;AAAA,EACvB,GAAA,EAAK,KAAA;AAAA,EACL,QAAA,EAAU,UAAA;AAAA,EACV,cAAA,EAAgB,UAAA;AAAA,EAChB,SAAA,EAAW,WAAA;AAAA,EACX,IAAA,EAAM,WAAA;AAAA,EACN,QAAA,EAAU,UAAA;AAAA,EACV,EAAA,EAAI;AACN,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,CAAA,CAAA,EAAI,GAAG,WAAW,eAAe,CAAA,SAAA,CAAA;AACrD;AAEO,SAAS,WAAA,CAAY,EAAE,KAAA,EAAO,OAAA,EAAS,eAAc,EAAsB;AAChF,EAAA,IAAI,aAAA,EAAe;AACjB,IAAA,OAAO,aAAA;AAAA,EACT;AAEA,EAAA,IAAI,OAAA,EAAS;AACX,IAAA,OAAO,eAAA,CAAgB,EAAE,KAAA,EAAO,OAAA,EAAS,CAAA;AAAA,EAC3C;AAEA,EAAA,OAAO,gBAAA,CAAiB,EAAE,KAAA,EAAO,CAAA;AACnC","file":"index.js","sourcesContent":["export type SupportedChain =\r\n | \"ethereum\"\r\n | \"polygon\"\r\n | \"bsc\"\r\n | \"arbitrum\"\r\n | \"avalanche\"\r\n | \"optimism\";\r\n\r\nconst CHAIN_ALIASES: Record<string, SupportedChain> = {\r\n ethereum: \"ethereum\",\r\n eth: \"ethereum\",\r\n polygon: \"polygon\",\r\n matic: \"polygon\",\r\n bsc: \"bsc\",\r\n \"binance-smart-chain\": \"bsc\",\r\n bnb: \"bsc\",\r\n arbitrum: \"arbitrum\",\r\n \"arbitrum-one\": \"arbitrum\",\r\n avalanche: \"avalanche\",\r\n avax: \"avalanche\",\r\n optimism: \"optimism\",\r\n op: \"optimism\",\r\n};\r\n\r\nexport const TRUSTWALLET_DIRS: Record<SupportedChain, string> = {\r\n ethereum: \"ethereum\",\r\n polygon: \"polygon\",\r\n bsc: \"smartchain\",\r\n arbitrum: \"arbitrum\",\r\n avalanche: \"avalanchec\",\r\n optimism: \"optimism\",\r\n};\r\n\r\nexport function normalizeChain(chain: string): SupportedChain {\r\n const key = chain.toLowerCase();\r\n const normalized = CHAIN_ALIASES[key];\r\n\r\n if (!normalized) {\r\n throw new Error(\r\n `Unsupported chain: \"${chain}\". Supported values: ${Object.keys(CHAIN_ALIASES).join(\", \")}`\r\n );\r\n }\r\n\r\n return normalized;\r\n}\r\n","import { getAddress } from \"ethers\";\r\n\r\nexport function toChecksum(address: string): string {\r\n return getAddress(address);\r\n}\r\n","export const TRUSTWALLET_COMMIT = \"f26c0845ff29059965e316e1e5988e77e5087764\";\r\n\r\nexport const BASE_URL = `https://cdn.jsdelivr.net/gh/trustwallet/assets@${TRUSTWALLET_COMMIT}/blockchains`;\r\n","import { normalizeChain, TRUSTWALLET_DIRS } from \"./chains\";\r\nimport { toChecksum } from \"./checksum\";\r\nimport { BASE_URL } from \"./constants\";\r\nimport type { LogoInput, NativeOptions, TokenOptions } from \"./types\";\r\n\r\nexport function getNativeLogoUrl({ chain }: NativeOptions): string {\r\n const normalized = normalizeChain(chain);\r\n const dir = TRUSTWALLET_DIRS[normalized];\r\n return `${BASE_URL}/${dir}/info/logo.png`;\r\n}\r\n\r\nexport function getTokenLogoUrl({ chain, address }: TokenOptions): string {\r\n const normalized = normalizeChain(chain);\r\n const dir = TRUSTWALLET_DIRS[normalized];\r\n const checksumAddress = toChecksum(address);\r\n return `${BASE_URL}/${dir}/assets/${checksumAddress}/logo.png`;\r\n}\r\n\r\nexport function resolveLogo({ chain, address, customLogoUrl }: LogoInput): string {\r\n if (customLogoUrl) {\r\n return customLogoUrl;\r\n }\r\n\r\n if (address) {\r\n return getTokenLogoUrl({ chain, address });\r\n }\r\n\r\n return getNativeLogoUrl({ chain });\r\n}\r\n"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { getAddress } from 'ethers';
|
|
2
|
+
|
|
3
|
+
// src/chains.ts
|
|
4
|
+
var CHAIN_ALIASES = {
|
|
5
|
+
ethereum: "ethereum",
|
|
6
|
+
eth: "ethereum",
|
|
7
|
+
polygon: "polygon",
|
|
8
|
+
matic: "polygon",
|
|
9
|
+
bsc: "bsc",
|
|
10
|
+
"binance-smart-chain": "bsc",
|
|
11
|
+
bnb: "bsc",
|
|
12
|
+
arbitrum: "arbitrum",
|
|
13
|
+
"arbitrum-one": "arbitrum",
|
|
14
|
+
avalanche: "avalanche",
|
|
15
|
+
avax: "avalanche",
|
|
16
|
+
optimism: "optimism",
|
|
17
|
+
op: "optimism"
|
|
18
|
+
};
|
|
19
|
+
var TRUSTWALLET_DIRS = {
|
|
20
|
+
ethereum: "ethereum",
|
|
21
|
+
polygon: "polygon",
|
|
22
|
+
bsc: "smartchain",
|
|
23
|
+
arbitrum: "arbitrum",
|
|
24
|
+
avalanche: "avalanchec",
|
|
25
|
+
optimism: "optimism"
|
|
26
|
+
};
|
|
27
|
+
function normalizeChain(chain) {
|
|
28
|
+
const key = chain.toLowerCase();
|
|
29
|
+
const normalized = CHAIN_ALIASES[key];
|
|
30
|
+
if (!normalized) {
|
|
31
|
+
throw new Error(
|
|
32
|
+
`Unsupported chain: "${chain}". Supported values: ${Object.keys(CHAIN_ALIASES).join(", ")}`
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
return normalized;
|
|
36
|
+
}
|
|
37
|
+
function toChecksum(address) {
|
|
38
|
+
return getAddress(address);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// src/constants.ts
|
|
42
|
+
var TRUSTWALLET_COMMIT = "f26c0845ff29059965e316e1e5988e77e5087764";
|
|
43
|
+
var BASE_URL = `https://cdn.jsdelivr.net/gh/trustwallet/assets@${TRUSTWALLET_COMMIT}/blockchains`;
|
|
44
|
+
|
|
45
|
+
// src/resolver.ts
|
|
46
|
+
function getNativeLogoUrl({ chain }) {
|
|
47
|
+
const normalized = normalizeChain(chain);
|
|
48
|
+
const dir = TRUSTWALLET_DIRS[normalized];
|
|
49
|
+
return `${BASE_URL}/${dir}/info/logo.png`;
|
|
50
|
+
}
|
|
51
|
+
function getTokenLogoUrl({ chain, address }) {
|
|
52
|
+
const normalized = normalizeChain(chain);
|
|
53
|
+
const dir = TRUSTWALLET_DIRS[normalized];
|
|
54
|
+
const checksumAddress = toChecksum(address);
|
|
55
|
+
return `${BASE_URL}/${dir}/assets/${checksumAddress}/logo.png`;
|
|
56
|
+
}
|
|
57
|
+
function resolveLogo({ chain, address, customLogoUrl }) {
|
|
58
|
+
if (customLogoUrl) {
|
|
59
|
+
return customLogoUrl;
|
|
60
|
+
}
|
|
61
|
+
if (address) {
|
|
62
|
+
return getTokenLogoUrl({ chain, address });
|
|
63
|
+
}
|
|
64
|
+
return getNativeLogoUrl({ chain });
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export { BASE_URL, TRUSTWALLET_COMMIT, TRUSTWALLET_DIRS, getNativeLogoUrl, getTokenLogoUrl, normalizeChain, resolveLogo, toChecksum };
|
|
68
|
+
//# sourceMappingURL=index.mjs.map
|
|
69
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/chains.ts","../src/checksum.ts","../src/constants.ts","../src/resolver.ts"],"names":[],"mappings":";;;AAQA,IAAM,aAAA,GAAgD;AAAA,EACpD,QAAA,EAAU,UAAA;AAAA,EACV,GAAA,EAAK,UAAA;AAAA,EACL,OAAA,EAAS,SAAA;AAAA,EACT,KAAA,EAAO,SAAA;AAAA,EACP,GAAA,EAAK,KAAA;AAAA,EACL,qBAAA,EAAuB,KAAA;AAAA,EACvB,GAAA,EAAK,KAAA;AAAA,EACL,QAAA,EAAU,UAAA;AAAA,EACV,cAAA,EAAgB,UAAA;AAAA,EAChB,SAAA,EAAW,WAAA;AAAA,EACX,IAAA,EAAM,WAAA;AAAA,EACN,QAAA,EAAU,UAAA;AAAA,EACV,EAAA,EAAI;AACN,CAAA;AAEO,IAAM,gBAAA,GAAmD;AAAA,EAC9D,QAAA,EAAU,UAAA;AAAA,EACV,OAAA,EAAS,SAAA;AAAA,EACT,GAAA,EAAK,YAAA;AAAA,EACL,QAAA,EAAU,UAAA;AAAA,EACV,SAAA,EAAW,YAAA;AAAA,EACX,QAAA,EAAU;AACZ;AAEO,SAAS,eAAe,KAAA,EAA+B;AAC5D,EAAA,MAAM,GAAA,GAAM,MAAM,WAAA,EAAY;AAC9B,EAAA,MAAM,UAAA,GAAa,cAAc,GAAG,CAA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AE,KAAA,EAAO,CAAA;AACnC","file":"index.mjs","sourcesContent":["export type SupportedChain =\r\n | \"ethereum\"\r\n | \"polygon\"\r\n | \"bsc\"\r\n | \"arbitrum\"\r\n | \"avalanche\"\r\n | \"optimism\";\r\n\r\nconst CHAIN_ALIASES: Record<string, SupportedChain> = {\r\n ethereum: \"ethereum\",\r\n eth: \"ethereum\",\r\n polygon: \"polygon\",\r\n matic: \"polygon\",\r\n bsc: \"bsc\",\r\n \"binance-smart-chain\": \"bsc\",\r\n bnb: \"bsc\",\r\n arbitrum: \"arbitrum\",\r\n \"arbitrum-one\": \"arbitrum\",\r\n avalanche: \"avalanche\",\r\n avax: \"avalanche\",\r\n optimism: \"optimism\",\r\n op: \"optimism\",\r\n};\r\n\r\nexport const TRUSTWALLET_DIRS: Record<SupportedChain, string> = {\r\n ethereum: \"ethereum\",\r\n polygon: \"polygon\",\r\n bsc: \"smartchain\",\r\n arbitrum: \"arbitrum\",\r\n avalanche: \"avalanchec\",\r\n optimism: \"optimism\",\r\n};\r\n\r\nexport function normalizeChain(chain: string): SupportedChain {\r\n const key = chain.toLowerCase();\r\n const normalized = CHAIN_ALIASES[key];\r\n\r\n if (!normalized) {\r\n throw new Error(\r\n `Unsupported chain: \"${chain}\". Supported values: ${Object.keys(CHAIN_ALIASES).join(\", \")}`\r\n );\r\n }\r\n\r\n return normalized;\r\n}\r\n","import { getAddress } from \"ethers\";\r\n\r\nexport function toChecksum(address: string): string {\r\n return getAddress(address);\r\n}\r\n","export const TRUSTWALLET_COMMIT = \"f26c0845ff29059965e316e1e5988e77e5087764\";\r\n\r\nexport const BASE_URL = `https://cdn.jsdelivr.net/gh/trustwallet/assets@${TRUSTWALLET_COMMIT}/blockchains`;\r\n","import { normalizeChain, TRUSTWALLET_DIRS } from \"./chains\";\r\nimport { toChecksum } from \"./checksum\";\r\nimport { BASE_URL } from \"./constants\";\r\nimport type { LogoInput, NativeOptions, TokenOptions } from \"./types\";\r\n\r\nexport function getNativeLogoUrl({ chain }: NativeOptions): string {\r\n const normalized = normalizeChain(chain);\r\n const dir = TRUSTWALLET_DIRS[normalized];\r\n return `${BASE_URL}/${dir}/info/logo.png`;\r\n}\r\n\r\nexport function getTokenLogoUrl({ chain, address }: TokenOptions): string {\r\n const normalized = normalizeChain(chain);\r\n const dir = TRUSTWALLET_DIRS[normalized];\r\n const checksumAddress = toChecksum(address);\r\n return `${BASE_URL}/${dir}/assets/${checksumAddress}/logo.png`;\r\n}\r\n\r\nexport function resolveLogo({ chain, address, customLogoUrl }: LogoInput): string {\r\n if (customLogoUrl) {\r\n return customLogoUrl;\r\n }\r\n\r\n if (address) {\r\n return getTokenLogoUrl({ chain, address });\r\n }\r\n\r\n return getNativeLogoUrl({ chain });\r\n}\r\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vinicius16187/crypto-logos",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Resolve TrustWallet asset logo URLs for blockchains and tokens via jsDelivr CDN",
|
|
5
|
+
"author": "",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "./dist/index.cjs",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
},
|
|
16
|
+
"require": {
|
|
17
|
+
"types": "./dist/index.d.cts",
|
|
18
|
+
"default": "./dist/index.cjs"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"keywords": [
|
|
26
|
+
"crypto",
|
|
27
|
+
"logos",
|
|
28
|
+
"trustwallet",
|
|
29
|
+
"blockchain",
|
|
30
|
+
"tokens",
|
|
31
|
+
"web3",
|
|
32
|
+
"ethereum",
|
|
33
|
+
"erc20"
|
|
34
|
+
],
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsup",
|
|
37
|
+
"dev": "tsup --watch",
|
|
38
|
+
"typecheck": "tsc --noEmit"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"ethers": "^6.13.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"tsup": "^8.3.0",
|
|
45
|
+
"typescript": "^5.6.0"
|
|
46
|
+
}
|
|
47
|
+
}
|