From 46280c87a3926e4370315005c5e78303d917538a Mon Sep 17 00:00:00 2001 From: Marc Juchli Date: Fri, 7 Nov 2025 11:59:36 +0100 Subject: [PATCH] feat: return user id upon connect Signed-off-by: Marc Juchli --- api-specs/openrpc-dapp-api.json | 7 ++++++- api-specs/openrpc-dapp-remote-api.json | 5 +++++ api-specs/openrpc-user-api.json | 5 +++++ core/splice-provider/src/SpliceProviderHttp.ts | 6 +++++- core/wallet-dapp-remote-rpc-client/src/index.ts | 7 +++++++ core/wallet-dapp-remote-rpc-client/src/openrpc.json | 5 +++++ core/wallet-dapp-rpc-client/src/index.ts | 7 +++++++ core/wallet-dapp-rpc-client/src/openrpc.json | 7 ++++++- core/wallet-user-rpc-client/src/index.ts | 8 ++++++++ core/wallet-user-rpc-client/src/openrpc.json | 5 +++++ sdk/dapp-sdk/src/dapp-api/rpc-gen/typings.ts | 7 +++++++ sdk/dapp-sdk/src/provider.ts | 10 ++++++++-- .../extension/src/dapp-api/rpc-gen/typings.ts | 7 +++++++ wallet-gateway/remote/src/dapp-api/controller.ts | 1 + wallet-gateway/remote/src/dapp-api/rpc-gen/typings.ts | 7 +++++++ wallet-gateway/remote/src/user-api/rpc-gen/typings.ts | 8 ++++++++ 16 files changed, 97 insertions(+), 5 deletions(-) diff --git a/api-specs/openrpc-dapp-api.json b/api-specs/openrpc-dapp-api.json index b194a2021..f5f6c7e1b 100644 --- a/api-specs/openrpc-dapp-api.json +++ b/api-specs/openrpc-dapp-api.json @@ -29,13 +29,18 @@ "status": { "$ref": "#/components/schemas/StatusEvent" }, + "userId": { + "title": "userId", + "type": "string", + "description": "The user ID associated with the session." + }, "sessionToken": { "title": "sessionToken", "type": "string", "description": "JWT authentication token (if applicable)." } }, - "required": ["status", "sessionToken"] + "required": ["status", "userId", "sessionToken"] } }, "description": "Ensures ledger connectivity and returns the connected network information along with the user access token. Network ID should follow CAIP-2 and represent the synchronizerId." diff --git a/api-specs/openrpc-dapp-remote-api.json b/api-specs/openrpc-dapp-remote-api.json index 259bc12af..29db86d05 100644 --- a/api-specs/openrpc-dapp-remote-api.json +++ b/api-specs/openrpc-dapp-remote-api.json @@ -189,6 +189,11 @@ "type": "string", "description": "A CAIP-2 compliant network ID, e.g. 'canton:da-mainnet'." }, + "userId": { + "title": "userId", + "type": "string", + "description": "The user ID associated with the session." + }, "sessionToken": { "title": "sessionToken", "type": "string", diff --git a/api-specs/openrpc-user-api.json b/api-specs/openrpc-user-api.json index de62dd138..fe97486a7 100644 --- a/api-specs/openrpc-user-api.json +++ b/api-specs/openrpc-user-api.json @@ -611,6 +611,11 @@ "network": { "$ref": "#/components/schemas/Network" }, + "userId": { + "title": "userId", + "type": "string", + "description": "The user ID associated with the session." + }, "accessToken": { "title": "accessToken", "type": "string", diff --git a/core/splice-provider/src/SpliceProviderHttp.ts b/core/splice-provider/src/SpliceProviderHttp.ts index 74104c4b6..042abe026 100644 --- a/core/splice-provider/src/SpliceProviderHttp.ts +++ b/core/splice-provider/src/SpliceProviderHttp.ts @@ -13,6 +13,7 @@ import { popupHref } from '@canton-network/core-wallet-ui-components' export class SpliceProviderHttp extends SpliceProviderBase { private sessionToken?: string + private userId?: string private socket: Socket private transport: HttpTransport @@ -42,11 +43,13 @@ export class SpliceProviderHttp extends SpliceProviderBase { constructor( private url: URL, - sessionToken?: string + sessionToken?: string, + userId?: string ) { super() if (sessionToken) this.sessionToken = sessionToken + if (userId) this.userId = userId this.transport = new HttpTransport(url, sessionToken) this.socket = this.openSocket(url) @@ -78,6 +81,7 @@ export class SpliceProviderHttp extends SpliceProviderBase { kernel: statusResult.kernel, networkId: statusResult.networkId, sessionToken: this.sessionToken, + userId: this.userId, }) }) .catch((err) => { diff --git a/core/wallet-dapp-remote-rpc-client/src/index.ts b/core/wallet-dapp-remote-rpc-client/src/index.ts index 9a4b13364..a9499e2c3 100644 --- a/core/wallet-dapp-remote-rpc-client/src/index.ts +++ b/core/wallet-dapp-remote-rpc-client/src/index.ts @@ -98,6 +98,12 @@ export interface JsPrepareSubmissionResponse { */ export type UserUrl = string export type Response = string +/** + * + * The user ID associated with the session. + * + */ +export type UserId = string /** * * Set as primary wallet for dApp usage. @@ -307,6 +313,7 @@ export interface LedgerApiResult { export interface OnConnectedEvent { kernel: KernelInfo networkId: NetworkId + userId?: UserId sessionToken?: SessionToken [k: string]: any } diff --git a/core/wallet-dapp-remote-rpc-client/src/openrpc.json b/core/wallet-dapp-remote-rpc-client/src/openrpc.json index 259bc12af..29db86d05 100644 --- a/core/wallet-dapp-remote-rpc-client/src/openrpc.json +++ b/core/wallet-dapp-remote-rpc-client/src/openrpc.json @@ -189,6 +189,11 @@ "type": "string", "description": "A CAIP-2 compliant network ID, e.g. 'canton:da-mainnet'." }, + "userId": { + "title": "userId", + "type": "string", + "description": "The user ID associated with the session." + }, "sessionToken": { "title": "sessionToken", "type": "string", diff --git a/core/wallet-dapp-rpc-client/src/index.ts b/core/wallet-dapp-rpc-client/src/index.ts index 195d89447..66007719b 100644 --- a/core/wallet-dapp-rpc-client/src/index.ts +++ b/core/wallet-dapp-rpc-client/src/index.ts @@ -68,6 +68,12 @@ export interface StatusEvent { networkId?: NetworkId [k: string]: any } +/** + * + * The user ID associated with the session. + * + */ +export type UserId = string /** * * JWT authentication token (if applicable). @@ -278,6 +284,7 @@ export interface LedgerApiParams { } export interface ConnectResult { status: StatusEvent + userId: UserId sessionToken: SessionToken [k: string]: any } diff --git a/core/wallet-dapp-rpc-client/src/openrpc.json b/core/wallet-dapp-rpc-client/src/openrpc.json index b194a2021..f5f6c7e1b 100644 --- a/core/wallet-dapp-rpc-client/src/openrpc.json +++ b/core/wallet-dapp-rpc-client/src/openrpc.json @@ -29,13 +29,18 @@ "status": { "$ref": "#/components/schemas/StatusEvent" }, + "userId": { + "title": "userId", + "type": "string", + "description": "The user ID associated with the session." + }, "sessionToken": { "title": "sessionToken", "type": "string", "description": "JWT authentication token (if applicable)." } }, - "required": ["status", "sessionToken"] + "required": ["status", "userId", "sessionToken"] } }, "description": "Ensures ledger connectivity and returns the connected network information along with the user access token. Network ID should follow CAIP-2 and represent the synchronizerId." diff --git a/core/wallet-user-rpc-client/src/index.ts b/core/wallet-user-rpc-client/src/index.ts index c2e9fcf84..cfd030727 100644 --- a/core/wallet-user-rpc-client/src/index.ts +++ b/core/wallet-user-rpc-client/src/index.ts @@ -173,6 +173,12 @@ export interface Wallet { export type Added = Wallet[] export type Removed = Wallet[] export type Networks = Network[] +/** + * + * The user ID associated with the session. + * + */ +export type UserId = string /** * * The access token for the session. @@ -187,6 +193,7 @@ export type Status = 'connected' | 'disconnected' */ export interface Session { network: Network + userId?: UserId accessToken: AccessToken status: Status } @@ -285,6 +292,7 @@ export interface ListNetworksResult { */ export interface AddSessionResult { network: Network + userId?: UserId accessToken: AccessToken status: Status } diff --git a/core/wallet-user-rpc-client/src/openrpc.json b/core/wallet-user-rpc-client/src/openrpc.json index de62dd138..fe97486a7 100644 --- a/core/wallet-user-rpc-client/src/openrpc.json +++ b/core/wallet-user-rpc-client/src/openrpc.json @@ -611,6 +611,11 @@ "network": { "$ref": "#/components/schemas/Network" }, + "userId": { + "title": "userId", + "type": "string", + "description": "The user ID associated with the session." + }, "accessToken": { "title": "accessToken", "type": "string", diff --git a/sdk/dapp-sdk/src/dapp-api/rpc-gen/typings.ts b/sdk/dapp-sdk/src/dapp-api/rpc-gen/typings.ts index e9567b2e1..c8a27e40a 100644 --- a/sdk/dapp-sdk/src/dapp-api/rpc-gen/typings.ts +++ b/sdk/dapp-sdk/src/dapp-api/rpc-gen/typings.ts @@ -68,6 +68,12 @@ export interface StatusEvent { networkId?: NetworkId [k: string]: any } +/** + * + * The user ID associated with the session. + * + */ +export type UserId = string /** * * JWT authentication token (if applicable). @@ -278,6 +284,7 @@ export interface LedgerApiParams { } export interface ConnectResult { status: StatusEvent + userId: UserId sessionToken: SessionToken [k: string]: any } diff --git a/sdk/dapp-sdk/src/provider.ts b/sdk/dapp-sdk/src/provider.ts index fb1b42e5c..42bc3783e 100644 --- a/sdk/dapp-sdk/src/provider.ts +++ b/sdk/dapp-sdk/src/provider.ts @@ -35,7 +35,11 @@ export class Provider implements SpliceProvider { private httpProvider?: SpliceProvider private windowProvider?: SpliceProvider - constructor({ walletType, url }: DiscoverResult, sessionToken?: string) { + constructor( + { walletType, url }: DiscoverResult, + sessionToken?: string, + userId?: string + ) { if (walletType == 'extension') { this.providerType = ProviderType.WINDOW this.windowProvider = new SpliceProviderWindow() @@ -43,7 +47,8 @@ export class Provider implements SpliceProvider { this.providerType = ProviderType.HTTP this.httpProvider = new SpliceProviderHttp( new URL(url), - sessionToken + sessionToken, + userId ) } else { throw new Error(`Unsupported wallet type ${walletType}`) @@ -170,6 +175,7 @@ export const dappController = (provider: SpliceProvider) => (event) => { clearTimeout(timeout) const result: dappAPI.ConnectResult = { + userId: event.userId ?? '', sessionToken: event.sessionToken ?? '', status: { ...event, diff --git a/wallet-gateway/extension/src/dapp-api/rpc-gen/typings.ts b/wallet-gateway/extension/src/dapp-api/rpc-gen/typings.ts index e9567b2e1..c8a27e40a 100644 --- a/wallet-gateway/extension/src/dapp-api/rpc-gen/typings.ts +++ b/wallet-gateway/extension/src/dapp-api/rpc-gen/typings.ts @@ -68,6 +68,12 @@ export interface StatusEvent { networkId?: NetworkId [k: string]: any } +/** + * + * The user ID associated with the session. + * + */ +export type UserId = string /** * * JWT authentication token (if applicable). @@ -278,6 +284,7 @@ export interface LedgerApiParams { } export interface ConnectResult { status: StatusEvent + userId: UserId sessionToken: SessionToken [k: string]: any } diff --git a/wallet-gateway/remote/src/dapp-api/controller.ts b/wallet-gateway/remote/src/dapp-api/controller.ts index 122437770..e314f4d31 100644 --- a/wallet-gateway/remote/src/dapp-api/controller.ts +++ b/wallet-gateway/remote/src/dapp-api/controller.ts @@ -58,6 +58,7 @@ export const dappController = ( const logger = _logger.child({ component: 'dapp-controller' }) return buildController({ connect: async () => ({ + userId: '', sessionToken: '', status: { kernel: kernelInfo, diff --git a/wallet-gateway/remote/src/dapp-api/rpc-gen/typings.ts b/wallet-gateway/remote/src/dapp-api/rpc-gen/typings.ts index e0bbac7a4..9d39e437b 100644 --- a/wallet-gateway/remote/src/dapp-api/rpc-gen/typings.ts +++ b/wallet-gateway/remote/src/dapp-api/rpc-gen/typings.ts @@ -98,6 +98,12 @@ export interface JsPrepareSubmissionResponse { */ export type UserUrl = string export type Response = string +/** + * + * The user ID associated with the session. + * + */ +export type UserId = string /** * * Set as primary wallet for dApp usage. @@ -307,6 +313,7 @@ export interface LedgerApiResult { export interface OnConnectedEvent { kernel: KernelInfo networkId: NetworkId + userId?: UserId sessionToken?: SessionToken [k: string]: any } diff --git a/wallet-gateway/remote/src/user-api/rpc-gen/typings.ts b/wallet-gateway/remote/src/user-api/rpc-gen/typings.ts index 073d5f29c..ce5345b3d 100644 --- a/wallet-gateway/remote/src/user-api/rpc-gen/typings.ts +++ b/wallet-gateway/remote/src/user-api/rpc-gen/typings.ts @@ -173,6 +173,12 @@ export interface Wallet { export type Added = Wallet[] export type Removed = Wallet[] export type Networks = Network[] +/** + * + * The user ID associated with the session. + * + */ +export type UserId = string /** * * The access token for the session. @@ -187,6 +193,7 @@ export type Status = 'connected' | 'disconnected' */ export interface Session { network: Network + userId?: UserId accessToken: AccessToken status: Status } @@ -285,6 +292,7 @@ export interface ListNetworksResult { */ export interface AddSessionResult { network: Network + userId?: UserId accessToken: AccessToken status: Status }