64 lines
1.5 KiB
TypeScript
64 lines
1.5 KiB
TypeScript
/**
|
|
* Openfort Provider
|
|
*
|
|
* Creates embedded smart wallets for on-ramp users
|
|
* using Openfort's account abstraction SDK.
|
|
*
|
|
* Docs: https://www.openfort.io/docs
|
|
*/
|
|
|
|
import Openfort from '@openfort/openfort-node';
|
|
|
|
export interface OpenfortConfig {
|
|
apiKey: string;
|
|
publishableKey: string;
|
|
chainId: number;
|
|
}
|
|
|
|
export interface WalletInfo {
|
|
playerId: string;
|
|
accountId: string;
|
|
address: string;
|
|
chainId: number;
|
|
}
|
|
|
|
export class OpenfortProvider {
|
|
private client: Openfort;
|
|
private config: OpenfortConfig;
|
|
|
|
constructor(config: OpenfortConfig) {
|
|
this.config = config;
|
|
this.client = new Openfort(config.apiKey);
|
|
}
|
|
|
|
/**
|
|
* Create an embedded wallet for an on-ramp user.
|
|
* Each user gets an Openfort "player" with a smart account on Base.
|
|
*/
|
|
async createWallet(label: string, metadata?: Record<string, string>): Promise<WalletInfo> {
|
|
try {
|
|
const player = await this.client.players.create({
|
|
name: label,
|
|
metadata: metadata ?? {},
|
|
});
|
|
|
|
const account = await this.client.accounts.v1.create({
|
|
player: player.id,
|
|
chainId: this.config.chainId,
|
|
});
|
|
|
|
console.log(`[openfort] Created wallet: player=${player.id} address=${account.address} label=${label}`);
|
|
|
|
return {
|
|
playerId: player.id,
|
|
accountId: account.id,
|
|
address: account.address,
|
|
chainId: this.config.chainId,
|
|
};
|
|
} catch (error) {
|
|
console.error(`[openfort] Failed to create wallet for "${label}":`, error);
|
|
throw error;
|
|
}
|
|
}
|
|
}
|