Update StandX API documentation and configuration

- Revised `.env.example` to reflect new API token generation process, emphasizing the use of creation date and validity days for token expiry management.
- Enhanced `auth.md` with detailed instructions for obtaining API tokens and signing transactions for both EVM and Solana wallets.
- Updated `maker-points-guide.md` to clarify the API token retrieval process and the significance of the Ed25519 private key.
- Refactored `config.ts` and `gateway.ts` to support new token expiry configuration methods and improved private key handling, including Base58 decoding.
- Improved overall documentation clarity and user guidance for new and existing users.
This commit is contained in:
discountry
2026-01-15 16:11:08 +08:00
parent 6496011d8f
commit 86670486a6
5 changed files with 499 additions and 104 deletions
+49 -4
View File
@@ -107,21 +107,66 @@ class StandxRequestSigner {
}
}
const BASE58_ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
function decodeBase58(input: string): Uint8Array | null {
try {
const bytes: number[] = [];
for (const char of input) {
const value = BASE58_ALPHABET.indexOf(char);
if (value === -1) return null;
let carry = value;
for (let i = 0; i < bytes.length; i += 1) {
const current = bytes[i] ?? 0;
carry += current * 58;
bytes[i] = carry & 0xff;
carry >>= 8;
}
while (carry > 0) {
bytes.push(carry & 0xff);
carry >>= 8;
}
}
// Handle leading zeros
for (const char of input) {
if (char !== "1") break;
bytes.push(0);
}
return Uint8Array.from(bytes.reverse());
} catch {
return null;
}
}
function parseSigningKey(value?: string): Uint8Array | null {
if (!value) return null;
const trimmed = value.trim();
if (!trimmed) return null;
// 0x-prefixed hex
if (/^0x[0-9a-fA-F]+$/.test(trimmed)) {
return Uint8Array.from(Buffer.from(trimmed.slice(2), "hex"));
}
// Pure hex (64 chars = 32 bytes for ed25519 private key)
if (/^[0-9a-fA-F]+$/.test(trimmed)) {
return Uint8Array.from(Buffer.from(trimmed, "hex"));
}
try {
return Uint8Array.from(Buffer.from(trimmed, "base64"));
} catch {
return null;
// Base58 (official StandX API format)
if (/^[1-9A-HJ-NP-Za-km-z]+$/.test(trimmed)) {
const decoded = decodeBase58(trimmed);
if (decoded && decoded.length === 32) {
return decoded;
}
}
// Base64 fallback
try {
const decoded = Uint8Array.from(Buffer.from(trimmed, "base64"));
if (decoded.length === 32) {
return decoded;
}
} catch {
// ignore
}
return null;
}
function normalizeSymbol(raw: string): string {