-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
225 additions
and
168 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
dist |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"root": true, | ||
"ignorePatterns": ["dist/*", "node_modules/**"], | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/eslint-recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
"plugin:prettier/recommended" | ||
], | ||
"rules": { | ||
"prettier/prettier": "warn", | ||
"no-console": "warn", | ||
"sort-imports": [ | ||
"warn", | ||
{ | ||
"ignoreCase": true, | ||
"ignoreDeclarationSort": true | ||
} | ||
], | ||
"@typescript-eslint/explicit-module-boundary-types": "off", | ||
"@typescript-eslint/no-explicit-any": "off", | ||
"@typescript-eslint/no-namespace": "off", | ||
"@typescript-eslint/no-non-null-assertion": "off", | ||
"@typescript-eslint/no-empty-function": "warn", | ||
"no-inner-declarations": "off" | ||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
arrowParens: 'always' | ||
bracketSpacing: false | ||
endOfLine: 'lf' | ||
printWidth: 100 | ||
semi: false | ||
singleQuote: true | ||
tabWidth: 4 | ||
useTabs: true | ||
trailingComma: 'es5' | ||
parser: typescript |
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
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,26 +1,34 @@ | ||
{ | ||
"name": "lighthouse", | ||
"module": "src/index.ts", | ||
"type": "module", | ||
"scripts": { | ||
"start": "bun src/index.ts", | ||
"build": "bun build src/index.ts --compile --outfile dist/lighthouse", | ||
"dev": "bun --hot src/index.ts" | ||
}, | ||
"peerDependencies": { | ||
"typescript": "^5.0.0" | ||
}, | ||
"overrides": { | ||
"@wharfkit/antelope": "^1.0.7" | ||
}, | ||
"dependencies": { | ||
"@wharfkit/antelope": "^1.0.7", | ||
"@wharfkit/common": "^1.2.2", | ||
"bun-types": "latest", | ||
"eslint": "^8.56.0", | ||
"eslint-config-prettier": "^9.1.0" | ||
}, | ||
"devDependencies": { | ||
"@types/bun": "^1.0.8" | ||
} | ||
"name": "lighthouse", | ||
"module": "src/index.ts", | ||
"type": "module", | ||
"scripts": { | ||
"start": "bun src/index.ts", | ||
"build": "bun build src/index.ts --compile --outfile dist/lighthouse", | ||
"dev": "bun --hot src/index.ts" | ||
}, | ||
"peerDependencies": { | ||
"typescript": "^5.0.0" | ||
}, | ||
"overrides": { | ||
"@wharfkit/antelope": "^1.0.7" | ||
}, | ||
"dependencies": { | ||
"@wharfkit/antelope": "^1.0.7", | ||
"@wharfkit/common": "^1.2.2" | ||
}, | ||
"devDependencies": { | ||
"@types/bun": "^1.0.8", | ||
"@types/mocha": "^10.0.7", | ||
"@typescript-eslint/eslint-plugin": "^7.14.1", | ||
"bun-types": "latest", | ||
"chai": "^5.1.1", | ||
"eslint": "^8.56.0", | ||
"eslint-config-prettier": "^9.1.0", | ||
"eslint-plugin-prettier": "^5.1.3", | ||
"mocha": "^10.5.2", | ||
"prettier-plugin-svelte": "^3.2.5", | ||
"svelte-eslint-parser": "^0.39.2", | ||
"typescript-eslint": "^7.14.1" | ||
} | ||
} |
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,53 +1,47 @@ | ||
import { ChainDefinition, Chains } from "@wharfkit/common"; | ||
|
||
export type Chain = ChainDefinition | { | ||
id: string; | ||
name: string; | ||
url: string; | ||
}; | ||
import { Chains } from '@wharfkit/common'; | ||
|
||
const AYETU_MAINNET = { | ||
id: "9b06067cf9f0a293e854cbdbcf4bc0292bbf1137dd01d3d9300f403706444504", | ||
name: "Ayetu", | ||
url: "https://mainnet.ayetu.net", | ||
id: '9b06067cf9f0a293e854cbdbcf4bc0292bbf1137dd01d3d9300f403706444504', | ||
name: 'Ayetu', | ||
url: 'https://mainnet.ayetu.net' | ||
}; | ||
|
||
const KOY_MAINNET = { | ||
id: "adf3860dc671acafa2e4ce7ab4fd90920a487e8e82a36e8b4364aad5129552cd", | ||
name: "KOY", | ||
url: "https://api.mainnet.koynetwork.io", | ||
id: 'adf3860dc671acafa2e4ce7ab4fd90920a487e8e82a36e8b4364aad5129552cd', | ||
name: 'KOY', | ||
url: 'https://api.mainnet.koynetwork.io' | ||
}; | ||
|
||
const AYETU_TESTNET = { | ||
id: "38b20c9055b39035eaee7fdf450ce9b2572024bcc6d4ee8cddd50662a0cdeff1", | ||
name: "Ayetu (Testnet)", | ||
url: "https://testnet.ayetu.net", | ||
} | ||
id: '38b20c9055b39035eaee7fdf450ce9b2572024bcc6d4ee8cddd50662a0cdeff1', | ||
name: 'Ayetu (Testnet)', | ||
url: 'https://testnet.ayetu.net' | ||
}; | ||
|
||
const KOY_TESTNET = { | ||
id: "181e289803751d4e0fc257fd186edaa6df8169e28631f1bf63fc9287a80cfb5f", | ||
name: "KOY (Testnet)", | ||
url: "https://api.testnet.koynetwork.io", | ||
} | ||
id: '181e289803751d4e0fc257fd186edaa6df8169e28631f1bf63fc9287a80cfb5f', | ||
name: 'KOY (Testnet)', | ||
url: 'https://api.testnet.koynetwork.io' | ||
}; | ||
|
||
export const MAINNET_CHAINS = [ | ||
Chains.EOS, | ||
Chains.Telos, | ||
Chains.WAX, | ||
Chains.Proton, | ||
Chains.Libre, | ||
Chains.UX, | ||
Chains.FIO, | ||
AYETU_MAINNET, | ||
KOY_MAINNET, | ||
Chains.EOS, | ||
Chains.Telos, | ||
Chains.WAX, | ||
Chains.Proton, | ||
Chains.Libre, | ||
Chains.UX, | ||
Chains.FIO, | ||
AYETU_MAINNET, | ||
KOY_MAINNET | ||
]; | ||
|
||
export const TESTNET_CHAINS = [ | ||
Chains.TelosTestnet, | ||
Chains.WAXTestnet, | ||
Chains.LibreTestnet, | ||
Chains.FIOTestnet, | ||
Chains.Jungle4, | ||
AYETU_TESTNET, | ||
KOY_TESTNET, | ||
]; | ||
Chains.TelosTestnet, | ||
Chains.WAXTestnet, | ||
Chains.LibreTestnet, | ||
Chains.FIOTestnet, | ||
Chains.Jungle4, | ||
AYETU_TESTNET, | ||
KOY_TESTNET | ||
]; |
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,64 +1,74 @@ | ||
import { serve } from "bun"; | ||
import { APIClient, PublicKey } from "@wharfkit/antelope"; | ||
import { MAINNET_CHAINS, TESTNET_CHAINS, type Chain } from "./chains"; | ||
import { serve } from 'bun'; | ||
import { API, APIClient, PublicKey } from '@wharfkit/antelope'; | ||
import { MAINNET_CHAINS, TESTNET_CHAINS } from './chains'; | ||
import type { Chain } from './types'; | ||
|
||
export const accountLookup = async (req: Request) => { | ||
const url = new URL(req.url); | ||
const key = url.pathname.split("/")[2]; | ||
const includeTestnets = url.searchParams.get("includeTestnets") === "true"; | ||
const url = new URL(req.url); | ||
const key = url.pathname.split('/')[2]; | ||
const includeTestnets = url.searchParams.get('includeTestnets') === 'true'; | ||
|
||
let publicKey: PublicKey; | ||
let publicKey: PublicKey; | ||
|
||
try { | ||
publicKey = PublicKey.from(key) | ||
} catch (error) { | ||
return new Response(JSON.stringify({ error: "Invalid public key" }), { status: 400 }); | ||
} | ||
try { | ||
publicKey = PublicKey.from(key); | ||
} catch (error) { | ||
return new Response(JSON.stringify({ error: 'Invalid public key' }), { status: 400 }); | ||
} | ||
|
||
const chains: Chain[] = includeTestnets ? [...MAINNET_CHAINS, ...TESTNET_CHAINS] : MAINNET_CHAINS; | ||
const lookups = (await Promise.all(chains.map(chain => lookupNetwork(publicKey, chain)))).filter(({ accounts }) => accounts.length > 0) | ||
const chains: Chain[] = includeTestnets ? [...MAINNET_CHAINS, ...TESTNET_CHAINS] : MAINNET_CHAINS; | ||
const lookups = ( | ||
await Promise.all(chains.map((chain) => lookupNetwork(publicKey, chain))) | ||
).filter(({ accounts }) => accounts.length > 0); | ||
|
||
const networkAccounts = lookups.map(({ chain, accounts }) => ({ | ||
network: chain.name, | ||
chainId: chain.id, | ||
accounts, | ||
})); | ||
const networkAccounts = lookups.map(({ chain, accounts }) => ({ | ||
network: chain.name, | ||
chainId: chain.id, | ||
accounts | ||
})); | ||
|
||
const totalAccounts = networkAccounts.reduce((total, { accounts }) => total + accounts.length, 0); | ||
console.log(`Found ${totalAccounts} auth(s) across ${networkAccounts.length} network(s)`); | ||
const totalAccounts = networkAccounts.reduce((total, { accounts }) => total + accounts.length, 0); | ||
log(`Found ${totalAccounts} auth(s) across ${networkAccounts.length} network(s)`); | ||
|
||
return new Response(JSON.stringify(networkAccounts)); | ||
return new Response(JSON.stringify(networkAccounts)); | ||
}; | ||
|
||
export const lookupNetwork = async (publicKey: PublicKey, chain: Chain, apiClient?: APIClient) => { | ||
try { | ||
const accounts = await networkRequest(publicKey, chain, apiClient); | ||
return { chain, accounts }; | ||
} catch (error) { | ||
console.warn(`Lookup error on ${chain.name}: ${error}`); | ||
return { chain, accounts: [] };; | ||
} | ||
try { | ||
const accounts = await networkRequest(publicKey, chain, apiClient); | ||
return { chain, accounts }; | ||
} catch (error) { | ||
log(`Lookup error on ${chain.name}: ${error}`); | ||
return { chain, accounts: [] }; | ||
} | ||
}; | ||
|
||
const networkRequest = async (publicKey: PublicKey, chain: Chain, apiClient?: APIClient) => { | ||
const client = apiClient || new APIClient(chain); | ||
const response = await client.v1.chain.get_accounts_by_authorizers({ keys: [publicKey] }); | ||
return response.accounts.map((account: any) => ({ | ||
actor: account.account_name, | ||
permission: account.permission_name, | ||
})); | ||
const client = apiClient || new APIClient(chain); | ||
const response: API.v1.AccountsByAuthorizers = await client.v1.chain.get_accounts_by_authorizers({ | ||
keys: [publicKey] | ||
}); | ||
return response.accounts.map((account) => ({ | ||
actor: account.account_name, | ||
permission: account.permission_name | ||
})); | ||
}; | ||
|
||
function log(message: string) { | ||
// eslint-disable-next-line no-console | ||
console.warn(message); | ||
} | ||
|
||
serve({ | ||
fetch(req: Request) { | ||
const url = new URL(req.url); | ||
if (url.pathname.startsWith("/lookup")) { | ||
return accountLookup(req); | ||
} | ||
fetch(req: Request) { | ||
const url = new URL(req.url); | ||
if (url.pathname.startsWith('/lookup')) { | ||
return accountLookup(req); | ||
} | ||
|
||
return new Response("π‘π ", { status: 200 }); | ||
}, | ||
port: 3000, | ||
return new Response('π‘π ', { status: 200 }); | ||
}, | ||
port: 3000 | ||
}); | ||
|
||
console.log('Server running at http://localhost:3000/ π') | ||
log('Server running at http://localhost:3000/ π'); |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { ChainDefinition } from '@wharfkit/common'; | ||
|
||
export type Chain = | ||
| ChainDefinition | ||
| { | ||
id: string; | ||
name: string; | ||
url: string; | ||
}; |
Oops, something went wrong.