Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions packages/walletkit-android-bridge/src/api/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type {
Base64String,
UserFriendlyAddress,
Feature,
SignatureDomain,
} from '@ton/walletkit';
import type { WalletId } from '@ton/walletkit';
import type { TransactionRequest } from '@ton/walletkit';
Expand Down Expand Up @@ -131,16 +132,20 @@ export async function getBalance(args: { walletId: string }) {
return wallet(args.walletId, 'getBalance');
}

export async function createSignerFromMnemonic(args: { mnemonic: string[]; mnemonicType?: string }) {
export async function createSignerFromMnemonic(args: {
mnemonic: string[];
mnemonicType?: string;
domain?: SignatureDomain;
}) {
if (!Signer) throw new Error('Signer module not loaded');
const signer = await Signer.fromMnemonic(args.mnemonic, { type: args.mnemonicType ?? 'ton' });
const signer = await Signer.fromMnemonic(args.mnemonic, { type: args.mnemonicType ?? 'ton' }, args.domain);
const signerId = retain('signer', signer);
return { signerId, publicKey: signer.publicKey };
}

export async function createSignerFromPrivateKey(args: { secretKey: string }) {
export async function createSignerFromPrivateKey(args: { secretKey: string; domain?: SignatureDomain }) {
if (!Signer) throw new Error('Signer module not loaded');
const signer = await Signer.fromPrivateKey(args.secretKey);
const signer = await Signer.fromPrivateKey(args.secretKey, args.domain);
const signerId = retain('signer', signer);
return { signerId, publicKey: signer.publicKey };
}
Expand Down
32 changes: 26 additions & 6 deletions packages/walletkit-android-bridge/src/core/initialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* WalletKit initialization helpers used by the bridge entry point.
*/
import type { BridgeResponse, BridgeEvent } from '@ton/walletkit';
import { TONCONNECT_BRIDGE_EVENT } from '@ton/walletkit';
import { TONCONNECT_BRIDGE_EVENT, ApiClientTonApi, ApiClientToncenter } from '@ton/walletkit';
import { TONCONNECT_BRIDGE_RESPONSE } from '@ton/walletkit/bridge';

import type {
Expand Down Expand Up @@ -52,14 +52,34 @@ export async function initTonWalletKit(

await ensureWalletKitLoaded();

// Build networks config from networkConfigurations (like iOS bridge does)
const networksConfig: Record<string, { apiClient?: { url?: string; key?: string } | AndroidAPIClientAdapter }> = {};
type NetworkApiClient =
| ApiClientTonApi
| ApiClientToncenter
| AndroidAPIClientAdapter
| { url?: string; key?: string };
const networksConfig: Record<string, { apiClient?: NetworkApiClient }> = {};

if (config?.networkConfigurations && Array.isArray(config.networkConfigurations)) {
for (const netConfig of config.networkConfigurations) {
networksConfig[netConfig.network.chainId] = {
apiClient: netConfig.apiClientConfiguration,
};
const type = netConfig.apiClientType;
let apiClient: NetworkApiClient | undefined;

if (type === 'tonapi') {
apiClient = new ApiClientTonApi({
endpoint: netConfig.apiClientConfiguration?.url,
apiKey: netConfig.apiClientConfiguration?.key,
network: netConfig.network,
});
} else if (type === 'toncenter') {
apiClient = new ApiClientToncenter({
endpoint: netConfig.apiClientConfiguration?.url,
apiKey: netConfig.apiClientConfiguration?.key,
});
} else {
apiClient = netConfig.apiClientConfiguration;
}

networksConfig[netConfig.network.chainId] = { apiClient };
}
}

Expand Down
6 changes: 4 additions & 2 deletions packages/walletkit-android-bridge/src/core/moduleLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ const walletKitModulePromise = import('@ton/walletkit');

type TonWalletKitConstructor = new (options: Record<string, unknown>) => WalletKitInstance;

type SignerDomain = { type: string; globalId?: number };

type SignerFactory = {
fromMnemonic: (mnemonic: string[], options: { type: string }) => Promise<WalletKitSigner>;
fromPrivateKey: (secretKey: string) => Promise<WalletKitSigner>;
fromMnemonic: (mnemonic: string[], options: { type: string }, domain?: SignerDomain) => Promise<WalletKitSigner>;
fromPrivateKey: (secretKey: string, domain?: SignerDomain) => Promise<WalletKitSigner>;
};

type AdapterFactory = {
Expand Down
4 changes: 4 additions & 0 deletions packages/walletkit-android-bridge/src/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,14 @@ export interface CreateTonMnemonicArgs {
export interface CreateSignerFromMnemonicArgs {
mnemonic: string[];
mnemonicType?: string;
/** Optional signature domain for L2 chains (e.g. Tetra). */
domain?: { type: 'l2'; globalId: number } | { type: 'empty' };
}

export interface CreateSignerFromPrivateKeyArgs {
secretKey: string;
/** Optional signature domain for L2 chains (e.g. Tetra). */
domain?: { type: 'l2'; globalId: number } | { type: 'empty' };
}

export interface CreateSignerFromCustomArgs {
Expand Down
1 change: 1 addition & 0 deletions packages/walletkit-android-bridge/src/types/walletkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export interface WalletKitBridgeInitConfig {
url?: string;
key?: string;
};
apiClientType?: 'default' | 'toncenter' | 'tonapi' | 'custom';
}>;
}

Expand Down
Loading