diff --git a/src/connectors/webwallet/helpers/trpc.ts b/src/connectors/webwallet/helpers/trpc.ts index 3c47028..7a270cf 100644 --- a/src/connectors/webwallet/helpers/trpc.ts +++ b/src/connectors/webwallet/helpers/trpc.ts @@ -68,6 +68,17 @@ const appRouter = t.router({ }), ) .mutation(async () => ({})), + connectWebwalletSSO: t.procedure + .input( + z.object({ token: z.string(), authorizedPartyId: z.string().optional() }), + ) + .output( + z.object({ + account: z.string().array().optional(), + chainId: z.string().optional(), + }), + ) + .mutation(async () => ({})), enable: t.procedure.output(z.string()).mutation(async () => ""), execute: t.procedure .input(StarknetMethodArgumentsSchemas.execute) diff --git a/src/connectors/webwallet/index.ts b/src/connectors/webwallet/index.ts index fe7964f..b3518e0 100644 --- a/src/connectors/webwallet/index.ts +++ b/src/connectors/webwallet/index.ts @@ -34,6 +34,8 @@ let _address: string | null = null interface WebWalletConnectorOptions { url?: string + ssoToken?: string + authorizedPartyId?: string } export class WebWalletConnector extends Connector { @@ -108,9 +110,24 @@ export class WebWalletConnector extends Connector { } try { - const { account, chainId } = await ( - this._wallet as WebWalletStarknetWindowObject - ).connectWebwallet() + let account, chainId + + if (this._options.ssoToken) { + const ssoReponse = await ( + this._wallet as WebWalletStarknetWindowObject + ).connectWebwalletSSO( + this._options.ssoToken, + this._options.authorizedPartyId, + ) + account = ssoReponse.account + chainId = ssoReponse.chainId + } else { + const connectResponse = await ( + this._wallet as WebWalletStarknetWindowObject + ).connectWebwallet() + account = connectResponse.account + chainId = connectResponse.chainId + } if (!account || !chainId) { return {} diff --git a/src/connectors/webwallet/starknetWindowObject/argentStarknetWindowObject.ts b/src/connectors/webwallet/starknetWindowObject/argentStarknetWindowObject.ts index 77f9311..4f67d4a 100644 --- a/src/connectors/webwallet/starknetWindowObject/argentStarknetWindowObject.ts +++ b/src/connectors/webwallet/starknetWindowObject/argentStarknetWindowObject.ts @@ -39,6 +39,13 @@ export type WebWalletStarknetWindowObject = StarknetWindowObject & { account?: string[] chainId?: string }> + connectWebwalletSSO( + token: string, + authorizedPartyId?: string, + ): Promise<{ + account?: string[] + chainId?: string + }> } export const getArgentStarknetWindowObject = ( @@ -53,6 +60,9 @@ export const getArgentStarknetWindowObject = ( connectWebwallet: () => { return proxyLink.connectWebwallet.mutate() }, + connectWebwalletSSO: (token, authorizedPartyId) => { + return proxyLink.connectWebwalletSSO.mutate({ token, authorizedPartyId }) + }, async request(call) { switch (call.type) { case "wallet_requestAccounts": { diff --git a/src/main.ts b/src/main.ts index 57e0fa8..c06021d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -21,7 +21,6 @@ import type { let selectedConnector: StarknetkitConnector | null = null - /** * * @param [modalMode="canAsk"] - Choose connection behavior: