Skip to content
Open
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
4 changes: 2 additions & 2 deletions apps/wallets/quickstart-devkit/components/permissions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function Permissions() {
const fetchPermissions = async () => {
if (wallet != null) {
const signers = await wallet.delegatedSigners();
setPermissions(signers);
setPermissions(signers.map((signer) => ({ signer })));
}
};
fetchPermissions();
Expand All @@ -36,7 +36,7 @@ export function Permissions() {
setIsLoading(true);
await wallet.addDelegatedSigner({ signer: newSigner });
const signers = await wallet.delegatedSigners();
setPermissions(signers);
setPermissions(signers.map((signer) => ({ signer })));
} catch (err) {
console.error("Permissions: ", err);
alert(`Permissions: ${err}`);
Expand Down
8 changes: 7 additions & 1 deletion packages/wallets/src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ import type {
WalletsV1ControllerSubmitSignatureApprovals4Error,
} from "./gen/types.gen";

export type CreateWalletParams = CreateWalletV2025Dto;
export type CreateWalletParams = CreateWalletV2025Dto & {
config?: {
delegatedSigners?: Array<{
signer: string;
}>;
};
};
export type GetWalletSuccessResponse = WalletV2025ResponseDto;
export type CreateWalletResponse = GetWalletSuccessResponse | WalletV1Alpha2ErrorDto;
export type GetWalletResponse = GetWalletSuccessResponse | WalletV1Alpha2ErrorDto;
Expand Down
1 change: 1 addition & 0 deletions packages/wallets/src/wallets/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export type WalletArgsFor<C extends Chain> = {
owner?: string;
plugins?: WalletPlugin<C>[];
options?: WalletOptions;
delegatedSigners?: C extends "solana" ? string[] : never;
};

export type TokenBalance = {
Expand Down
39 changes: 35 additions & 4 deletions packages/wallets/src/wallets/wallet-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,26 @@ export class WalletFactory {

this.mutateSignerFromCustomAuth(args, true);

if (args.delegatedSigners && args.chain !== "solana") {
throw new WalletCreationError("Delegated signers are only supported for Solana smart wallets");
}

const adminSigner =
args.signer.type === "passkey" ? await this.createPasskeyAdminSigner(args.signer) : args.signer;

const config: any = {
adminSigner,
...(args?.plugins ? { plugins: args.plugins } : {}),
};

if (args.chain === "solana" && args.delegatedSigners) {
config.delegatedSigners = args.delegatedSigners.map((signer) => ({ signer }));
}

const walletResponse = await this.apiClient.createWallet({
type: "smart",
chainType: this.getChainType(args.chain),
config: {
adminSigner,
...(args?.plugins ? { plugins: args.plugins } : {}),
},
config,
owner: args.owner ?? undefined,
} as CreateWalletParams);

Expand Down Expand Up @@ -257,6 +267,27 @@ export class WalletFactory {
}
compareSignerConfigs(adminSignerArgs, existingWalletSigner);
}

if (args.delegatedSigners && args.chain === "solana") {
const existingDelegatedSigners = (existingWallet?.config as any)?.delegatedSigners;
if (existingDelegatedSigners) {
const existingSignerAddresses = existingDelegatedSigners.map((s: any) => s.locator);
const providedSignerAddresses = args.delegatedSigners;

const missingSigners = providedSignerAddresses.filter(
(addr: string) =>
!existingSignerAddresses.some((existing: string) =>
existing.endsWith(addr.replace("external-wallet:", ""))
)
);

if (missingSigners.length > 0) {
throw new WalletCreationError(
`Provided delegated signers do not match existing wallet's delegated signers. Missing: ${missingSigners.join(", ")}`
);
}
}
}
}

private getChainType(chain: Chain): "solana" | "evm" | "stellar" {
Expand Down
7 changes: 2 additions & 5 deletions packages/wallets/src/wallets/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import type {
GetTransactionsResponse,
} from "../api";
import type {
DelegatedSigner,
WalletOptions,
UserLocator,
Transaction,
Expand Down Expand Up @@ -346,7 +345,7 @@ export class Wallet<C extends Chain> {
}
}

public async delegatedSigners(): Promise<DelegatedSigner[]> {
public async delegatedSigners(): Promise<string[]> {
const walletResponse = await this.#apiClient.getWallet(this.walletLocator);
if ("error" in walletResponse) {
throw new WalletNotAvailableError(JSON.stringify(walletResponse));
Expand All @@ -369,9 +368,7 @@ export class Wallet<C extends Chain> {
const colonIndex = signer.locator.indexOf(":");
// If there's a colon, keep everything after it; otherwise treat the whole string as "rest"
const address = colonIndex >= 0 ? signer.locator.slice(colonIndex + 1) : signer.locator;
return {
signer: `external-wallet:${address}`,
};
return address;
}) ?? []
);
}
Expand Down