mirror of
https://github.com/pezkuwichain/pwap.git
synced 2026-04-22 07:57:55 +00:00
update: upgrade @pezkuwi/api to 16.5.36, clean up images and assets
- Upgrade @pezkuwi/api 16.5.11 -> 16.5.36 in supabase edge functions - Remove manual SS58-to-hex workaround, use native SS58 addresses - Add kurdistan flag and Dijital Kurdistan images - Add PezkuwiExplorer to web public assets - Remove unused react-logo and telegram_welcome images - Add *.bak to gitignore
This commit is contained in:
@@ -1,35 +1,11 @@
|
||||
// process-withdraw Edge Function
|
||||
// Processes withdrawal requests by sending tokens from hot wallet to user wallet
|
||||
// Uses @pezkuwi/api for blockchain transactions
|
||||
// Uses @pezkuwi/api for Asset Hub blockchain transactions
|
||||
|
||||
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts'
|
||||
import { createClient } from 'npm:@supabase/supabase-js@2'
|
||||
import { ApiPromise, WsProvider, Keyring } from 'npm:@pezkuwi/api@16.5.11'
|
||||
import { cryptoWaitReady } from 'npm:@pezkuwi/util-crypto@14.0.11'
|
||||
|
||||
// Decode SS58 address to raw 32-byte public key hex
|
||||
function ss58ToHex(address: string): string {
|
||||
const CHARS = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
|
||||
let leadingZeros = 0
|
||||
for (const c of address) {
|
||||
if (c !== '1') break
|
||||
leadingZeros++
|
||||
}
|
||||
let num = 0n
|
||||
for (const c of address) {
|
||||
num = num * 58n + BigInt(CHARS.indexOf(c))
|
||||
}
|
||||
const hex = num.toString(16)
|
||||
const paddedHex = hex.length % 2 ? '0' + hex : hex
|
||||
const decoded = new Uint8Array(leadingZeros + paddedHex.length / 2)
|
||||
for (let i = 0; i < leadingZeros; i++) decoded[i] = 0
|
||||
for (let i = 0; i < paddedHex.length / 2; i++) {
|
||||
decoded[leadingZeros + i] = parseInt(paddedHex.slice(i * 2, i * 2 + 2), 16)
|
||||
}
|
||||
// SS58: [1-byte prefix] [32 bytes pubkey] [2 bytes checksum]
|
||||
const pubkey = decoded.slice(1, 33)
|
||||
return '0x' + Array.from(pubkey, (b: number) => b.toString(16).padStart(2, '0')).join('')
|
||||
}
|
||||
import { ApiPromise, WsProvider, Keyring } from 'npm:@pezkuwi/api@16.5.36'
|
||||
import { cryptoWaitReady } from 'npm:@pezkuwi/util-crypto@14.0.25'
|
||||
|
||||
// Allowed origins for CORS
|
||||
const ALLOWED_ORIGINS = [
|
||||
@@ -119,22 +95,19 @@ async function sendTokens(
|
||||
// Convert amount to chain units
|
||||
const amountBN = BigInt(Math.floor(amount * Math.pow(10, DECIMALS)))
|
||||
|
||||
// Convert all addresses to hex (Deno npm shim breaks SS58 decoding in @pezkuwi/api types)
|
||||
const destHex = ss58ToHex(toAddress)
|
||||
const signerHex = '0x' + Array.from(hotWallet.publicKey, (b: number) => b.toString(16).padStart(2, '0')).join('')
|
||||
console.log(`Sending ${amount} ${token}: ${signerHex} → ${destHex}`)
|
||||
console.log(`Sending ${amount} ${token}: ${hotWallet.address} → ${toAddress}`)
|
||||
|
||||
let tx
|
||||
if (token === 'HEZ') {
|
||||
tx = api.tx.balances.transferKeepAlive({ Id: destHex }, amountBN)
|
||||
tx = api.tx.balances.transferKeepAlive(toAddress, amountBN)
|
||||
} else if (token === 'PEZ') {
|
||||
tx = api.tx.assets.transfer(PEZ_ASSET_ID, { Id: destHex }, amountBN)
|
||||
tx = api.tx.assets.transfer(PEZ_ASSET_ID, toAddress, amountBN)
|
||||
} else {
|
||||
return { success: false, error: 'Invalid token' }
|
||||
}
|
||||
|
||||
// Fetch nonce via hex pubkey to avoid SS58 → AccountId32 decoding issue
|
||||
const accountInfo = await api.query.system.account(signerHex)
|
||||
// Fetch nonce
|
||||
const accountInfo = await api.query.system.account(hotWallet.address)
|
||||
const nonce = accountInfo.nonce
|
||||
|
||||
// Sign and send transaction
|
||||
|
||||
Reference in New Issue
Block a user