@james-wu/tokenguard-sdk
v0.1.0
Published
TypeScript SDK for pre-sign transaction, domain, approval, reputation, and AI risk analysis in Web3 wallets and platforms.
Maintainers
Readme
@james-wu/tokenguard-sdk
TypeScript SDK for embedding TokenGuard risk analysis into wallets, exchanges, browser extensions, and Web3 security products.
Best for:
- wallet confirmation flows
- exchange or trading risk checks
- extension-side signing prompts
- internal security or analyst tooling
What It Does
The SDK wraps the TokenGuard HTTP API and gives you typed methods for:
- transaction and signature risk analysis
- domain and phishing analysis
- approval exposure checks
- address reputation lookup
- AI explanations and user advice
- quantum-readiness assessment
Installation
npm install @james-wu/tokenguard-sdkLinks
- Repository: James-Wuguoqing/tokenguard-ai
- Package: npmjs.com/package/@james-wu/tokenguard-sdk
- UI package: npmjs.com/package/@james-wu/tokenguard-ui
- Minimal integration example: demo/minimal-integration.html
- Embedded widget example: examples/embedded-widget
Quick Start
import { TokenGuardClient } from "@james-wu/tokenguard-sdk";
const client = new TokenGuardClient({
apiKey: "tg_demo_sandbox_key",
chainId: 1,
baseUrl: "http://localhost:8787",
language: "en-US",
userLevel: "beginner"
});
const result = await client.analyzeTransaction({
walletAddress: "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
to: "0x1111111111111111111111111111111111111111",
data: "0x095ea7b30000000000000000000000001111111111111111111111111111111111111111ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
value: "0",
context: {
url: "https://metamask-support-wallet.xyz"
}
});
console.log(result.riskLevel);
console.log(result.summary);
console.log(result.recommendations);Production And Local Base URLs
If you pass baseUrl, the SDK will call that origin directly.
const client = new TokenGuardClient({
apiKey: "YOUR_API_KEY",
chainId: 1,
baseUrl: "https://your-tokenguard-gateway.example.com"
});If baseUrl is omitted:
- in browsers, the SDK uses the current page origin
- in Node.js,
sandboxfalls back tohttp://localhost:8787 - in Node.js,
productionfalls back tohttps://api.tokenguard.ai
Core Methods
analyzeTransaction()analyzeDomain()checkApproval()getAddressReputation()getAIExplanation()generateLiveAIExplanation()assessQuantumExposure()getUserAdvice()getAIProviderSession()connectAIProvider()disconnectAIProvider()
Type Exports
The package also exports the request and response types used by the client, including:
TokenGuardConfigAnalyzeTransactionParamsAnalyzeTransactionResultDomainAnalyzeParamsDomainAnalyzeResultApprovalCheckParamsApprovalCheckResultAddressReputationParamsAddressReputationResultAIExplainParamsAIExplainResultLiveAIExplainParamsLiveAIExplainResultQuantumAssessParamsQuantumAssessResultUserAdviceParamsUserAdviceResult
Notes
- This package is an API client. The core risk rules run on the TokenGuard service, not inside the browser bundle.
- Node.js 18+ and modern browsers can use the built-in
fetchimplementation. - For local development in this repository, start the demo service with
npm run serve:managedfrom the project root before usinghttp://localhost:8787.
Local Try
If you want to try the SDK against the local demo service from this repository:
npm install
npm run serve:managedThen point baseUrl to:
http://localhost:8787