ci / gate (push) Failing after 1m25s
Every open wallet with a phrase now shows its NEAR Intents account. Its NEP-649 key is derived from the seed on each look and dropped; only the public side leaves Rust. The account's name is a function of that key, b<base32 of the handle's first 10 bytes>.blackbeard-observer.near, so the sponsor (#81) creates it there, a restored phrase finds it again with nothing stored, and the leading b sorts it onto shard 8, which our nodes serve. The panel says whether the account exists and whether this wallet's key is on it, and shows its NEAR for gas and every token it holds inside Intents (one mt_batch_balance_of over the registry's Intents ids). The logic is wallet_core::near::account_summary, written against the NearRpc port and tested with a fake. The command is a shim, and the app now holds the shard-routed client from #73 and near.toml, which a file in the data directory can replace. Corrected on the way: the asset registry said no post-quantum asset is on Intents. QTC has been, as nep141:qtc.omft.near, since early October. Quantus's native QTC now maps to it, the token-list fixture gains 1Click's QTC entry, and the "unmapped asset" tests use Planck's token instead. The readme no longer says the swap module waits for Quantus's MPC fork. Verified in a dev run with the dev-phrase fixture: the panel showed bffbod6n6ey7jdk4j.blackbeard-observer.near as not created yet. Refs #74 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NUx7SPonBnB3ofU4mH41WT
260 lines
9.2 KiB
TypeScript
260 lines
9.2 KiB
TypeScript
// The only file in the webview that talks to Rust. One function per Tauri
|
|
// command, each typed with the ts-rs output in ./generated, and one place
|
|
// where a Rust `WalletError` becomes a thrown `WalletError`. Screens never
|
|
// call `invoke` themselves; CI counts the occurrences in this directory.
|
|
|
|
import { invoke } from '@tauri-apps/api/core'
|
|
import type { AccountBalance } from './generated/AccountBalance'
|
|
import type { AppInfo } from './generated/AppInfo'
|
|
import type { ChainId } from './generated/ChainId'
|
|
import type { ChainProfile } from './generated/ChainProfile'
|
|
import type { ChainStatus } from './generated/ChainStatus'
|
|
import type { PendingReversible } from './generated/PendingReversible'
|
|
import type { PreparedTransferInfo } from './generated/PreparedTransferInfo'
|
|
import type { CreationStart } from './generated/CreationStart'
|
|
import type { SessionStatusInfo } from './generated/SessionStatusInfo'
|
|
import type { Settings } from './generated/Settings'
|
|
import type { AccountScan } from './generated/AccountScan'
|
|
import type { AssetInfo } from './generated/AssetInfo'
|
|
import type { HistoryCursor } from './generated/HistoryCursor'
|
|
import type { Order } from './generated/Order'
|
|
import type { SwapAsk } from './generated/SwapAsk'
|
|
import type { SwapPreview } from './generated/SwapPreview'
|
|
import type { HistoryPage } from './generated/HistoryPage'
|
|
import type { WalletSummary } from './generated/WalletSummary'
|
|
import type { NearAccountSummary } from './generated/NearAccountSummary'
|
|
import type { WormholeSummary } from './generated/WormholeSummary'
|
|
import type { WalletError as WalletErrorShape } from './generated/WalletError'
|
|
|
|
export class WalletError extends Error {
|
|
readonly kind: WalletErrorShape['kind']
|
|
readonly detail: string
|
|
|
|
constructor(shape: WalletErrorShape) {
|
|
const detail = 'detail' in shape ? shape.detail : ''
|
|
super(detail ? `${shape.kind}: ${detail}` : shape.kind)
|
|
this.name = 'WalletError'
|
|
this.kind = shape.kind
|
|
this.detail = detail
|
|
}
|
|
}
|
|
|
|
function isWalletErrorShape(e: unknown): e is WalletErrorShape {
|
|
return (
|
|
typeof e === 'object' &&
|
|
e !== null &&
|
|
'kind' in e &&
|
|
typeof (e as { kind: unknown }).kind === 'string'
|
|
)
|
|
}
|
|
|
|
// Rust commands return `Result<T, WalletError>`; Tauri rejects the promise
|
|
// with the serialised error. Anything that is not a WalletError is a bug on
|
|
// one side of the boundary and is rethrown as-is so it is loud.
|
|
async function command<T>(name: string, args?: Record<string, unknown>): Promise<T> {
|
|
try {
|
|
return await invoke<T>(name, args)
|
|
} catch (e) {
|
|
if (isWalletErrorShape(e)) throw new WalletError(e)
|
|
throw e
|
|
}
|
|
}
|
|
|
|
export function appInfo(): Promise<AppInfo> {
|
|
return command<AppInfo>('app_info')
|
|
}
|
|
|
|
export function walletsList(): Promise<WalletSummary[]> {
|
|
return command<WalletSummary[]>('wallets_list')
|
|
}
|
|
|
|
// Creation is three steps so the phrase is shown once and then gone: begin
|
|
// returns the words and the challenge, confirm writes the wallet if the
|
|
// challenge passes, cancel forgets the phrase.
|
|
export function walletCreateBegin(): Promise<CreationStart> {
|
|
return command<CreationStart>('wallet_create_begin')
|
|
}
|
|
|
|
export function walletCreateConfirm(
|
|
name: string,
|
|
password: string,
|
|
answers: string[],
|
|
): Promise<WalletSummary> {
|
|
return command<WalletSummary>('wallet_create_confirm', { name, password, answers })
|
|
}
|
|
|
|
export function walletCreateCancel(): Promise<void> {
|
|
return command<void>('wallet_create_cancel')
|
|
}
|
|
|
|
// No scheme: a phrase opens with its ML-DSA-65 and ML-DSA-87 accounts both.
|
|
export function walletImportPhrase(
|
|
name: string,
|
|
password: string,
|
|
phrase: string,
|
|
): Promise<WalletSummary> {
|
|
return command<WalletSummary>('wallet_import_phrase', { name, password, phrase })
|
|
}
|
|
|
|
export function walletImportFile(path: string, password: string): Promise<WalletSummary> {
|
|
return command<WalletSummary>('wallet_import_file', { path, password })
|
|
}
|
|
|
|
export function checkphrase(address: string): Promise<string> {
|
|
return command<string>('checkphrase', { address })
|
|
}
|
|
|
|
// The session: one wallet open at a time, locked again after idling. The
|
|
// Rust side emits `session:locked` when the idle rule fires.
|
|
export function unlock(name: string, password: string): Promise<SessionStatusInfo> {
|
|
return command<SessionStatusInfo>('unlock', { name, password })
|
|
}
|
|
|
|
/**
|
|
* Add the next account number to an open wallet that carries a phrase,
|
|
* under both schemes. Remembered, so the next unlock brings it back.
|
|
*/
|
|
export function walletAddAccount(wallet: string): Promise<SessionStatusInfo> {
|
|
return command<SessionStatusInfo>('wallet_add_account', { wallet })
|
|
}
|
|
|
|
/**
|
|
* Find the account numbers a wallet's phrase already uses on `chain`: the
|
|
* chain is asked which derived addresses exist, and the ones found are
|
|
* opened and remembered.
|
|
*/
|
|
export function walletDiscoverAccounts(chain: ChainId, wallet: string): Promise<AccountScan> {
|
|
return command<AccountScan>('wallet_discover_accounts', { chain, wallet })
|
|
}
|
|
|
|
/** Lock one open wallet by name, or all of them when none is named. */
|
|
export function lock(wallet?: string): Promise<void> {
|
|
return command<void>('lock', { wallet: wallet ?? null })
|
|
}
|
|
|
|
export function sessionStatus(): Promise<SessionStatusInfo> {
|
|
return command<SessionStatusInfo>('session_status')
|
|
}
|
|
|
|
export function chainsList(): Promise<ChainProfile[]> {
|
|
return command<ChainProfile[]>('chains_list')
|
|
}
|
|
|
|
export function chainConnect(chain: ChainId): Promise<ChainStatus> {
|
|
return command<ChainStatus>('chain_connect', { chain })
|
|
}
|
|
|
|
export function chainStatus(chain: ChainId): Promise<ChainStatus> {
|
|
return command<ChainStatus>('chain_status', { chain })
|
|
}
|
|
|
|
// Balances are read from finalized state. `balancesWatch` makes Rust re-read
|
|
// them on every finalized head and emit `balances:updated`.
|
|
export function balances(chain: ChainId): Promise<AccountBalance[]> {
|
|
return command<AccountBalance[]>('balances', { chain })
|
|
}
|
|
|
|
export function balancesWatch(chain: ChainId): Promise<void> {
|
|
return command<void>('balances_watch', { chain })
|
|
}
|
|
|
|
// Sending is two steps so the review screen shows what Rust decoded from the
|
|
// bytes: prepare returns the summary and fee under an id, submit signs and
|
|
// sends that id. Progress arrives as `tx:status` events.
|
|
export function transferPrepare(
|
|
chain: ChainId,
|
|
from: string,
|
|
to: string,
|
|
amount: string,
|
|
reversibleFor?: number,
|
|
): Promise<PreparedTransferInfo> {
|
|
return command<PreparedTransferInfo>('transfer_prepare', {
|
|
chain,
|
|
from,
|
|
to,
|
|
amount,
|
|
reversibleFor: reversibleFor ?? null,
|
|
})
|
|
}
|
|
|
|
export function transferSubmit(id: string): Promise<string> {
|
|
return command<string>('transfer_submit', { id })
|
|
}
|
|
|
|
export function transferDiscard(id: string): Promise<void> {
|
|
return command<void>('transfer_discard', { id })
|
|
}
|
|
|
|
export function reversiblePending(chain: ChainId, address: string): Promise<PendingReversible[]> {
|
|
return command<PendingReversible[]>('reversible_pending', { chain, address })
|
|
}
|
|
|
|
export function reversibleCancelPrepare(
|
|
chain: ChainId,
|
|
from: string,
|
|
txId: string,
|
|
): Promise<PreparedTransferInfo> {
|
|
return command<PreparedTransferInfo>('reversible_cancel_prepare', { chain, from, txId })
|
|
}
|
|
|
|
export function settingsGet(): Promise<Settings> {
|
|
return command<Settings>('settings_get')
|
|
}
|
|
|
|
export function settingsSet(settings: Settings): Promise<Settings> {
|
|
return command<Settings>('settings_set', { settings })
|
|
}
|
|
|
|
// History: one page per call, from the indexer or, when it cannot be
|
|
// reached, from the local cache with `from_cache` set.
|
|
export function historyPage(
|
|
chain: ChainId,
|
|
address: string,
|
|
before?: HistoryCursor | null,
|
|
): Promise<HistoryPage> {
|
|
return command<HistoryPage>('history_page', { chain, address, before: before ?? null })
|
|
}
|
|
|
|
// The wormhole address behind the wallet's mining rewards and what the
|
|
// zk-tree holds for it. Scans on the Rust side; can take a while the first
|
|
// time on a long tree.
|
|
export function wormholeSummary(chain: ChainId, wallet: string): Promise<WormholeSummary> {
|
|
return command<WormholeSummary>('wormhole_summary', { chain, wallet })
|
|
}
|
|
|
|
// The wallet's NEAR Intents account: derived from its phrase, named by the
|
|
// sponsor from its key, read from NEAR. Only public fields come back.
|
|
export function nearAccount(wallet: string): Promise<NearAccountSummary> {
|
|
return command<NearAccountSummary>('near_account', { wallet })
|
|
}
|
|
|
|
// Swaps, in preview: the assets the provider and the registry agree on, a
|
|
// dry quote, an order (a wet quote persisted with its deposit address),
|
|
// and the list. Rust follows open orders and emits `orders:updated`.
|
|
export function swapAssets(): Promise<AssetInfo[]> {
|
|
return command<AssetInfo[]>('swap_assets')
|
|
}
|
|
|
|
export function swapPreview(ask: SwapAsk): Promise<SwapPreview> {
|
|
return command<SwapPreview>('swap_preview', { ask })
|
|
}
|
|
|
|
export function swapOrderCreate(ask: SwapAsk): Promise<Order> {
|
|
return command<Order>('swap_order_create', { ask })
|
|
}
|
|
|
|
export function ordersList(): Promise<Order[]> {
|
|
return command<Order[]>('orders_list')
|
|
}
|
|
|
|
// A fiat ramp session: Rust builds the URL (through the relay once a
|
|
// provider exists); the screen hands it to the opener. Buy or sell.
|
|
export function rampSession(
|
|
chain: ChainId,
|
|
address: string,
|
|
direction: 'buy' | 'sell',
|
|
fiatCurrency: string,
|
|
): Promise<string> {
|
|
return command<string>('ramp_session', { chain, address, direction, fiatCurrency })
|
|
}
|