Skip to content

Commit 9d76728

Browse files
authored
Merge branch 'main' into phol/connection-status
Signed-off-by: Phillip Olesen <[email protected]>
2 parents 5bb518a + cb3149b commit 9d76728

File tree

20 files changed

+598
-248
lines changed

20 files changed

+598
-248
lines changed

api-specs/openrpc-dapp-api.json

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,7 @@
2323
"result": {
2424
"name": "result",
2525
"schema": {
26-
"title": "ConnectResult",
27-
"type": "object",
28-
"properties": {
29-
"status": {
30-
"$ref": "#/components/schemas/StatusEvent"
31-
},
32-
"sessionToken": {
33-
"title": "sessionToken",
34-
"type": "string",
35-
"description": "JWT authentication token (if applicable)."
36-
}
37-
},
38-
"required": ["status", "sessionToken"]
26+
"$ref": "#/components/schemas/StatusEvent"
3927
}
4028
},
4129
"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."
@@ -529,10 +517,53 @@
529517
"type": "string",
530518
"description": "If not connected to a network, the reason why."
531519
},
532-
"networkId": {
533-
"title": "networkId",
534-
"type": "string",
535-
"description": "A CAIP-2 compliant chain ID, e.g. 'canton:da-mainnet'."
520+
"userUrl": {
521+
"$ref": "#/components/schemas/UserUrl"
522+
},
523+
"network": {
524+
"title": "network",
525+
"type": "object",
526+
"description": "Network information, if connected to a network.",
527+
"properties": {
528+
"networkId": {
529+
"title": "networkId",
530+
"type": "string",
531+
"description": "A CAIP-2 compliant chain ID, e.g. 'canton:da-mainnet'."
532+
},
533+
"ledgerApi": {
534+
"title": "LedgerApiConfig",
535+
"type": "object",
536+
"description": "Ledger API configuration.",
537+
"properties": {
538+
"baseUrl": {
539+
"title": "baseUrl",
540+
"type": "string",
541+
"format": "uri",
542+
"description": "The base URL of the ledger API."
543+
}
544+
},
545+
"required": ["baseUrl"]
546+
}
547+
},
548+
"required": ["networkId"]
549+
},
550+
"session": {
551+
"title": "session",
552+
"type": "object",
553+
"description": "Session information, if authenticated.",
554+
"properties": {
555+
"accessToken": {
556+
"title": "accessToken",
557+
"type": "string",
558+
"description": "JWT authentication token."
559+
},
560+
"userId": {
561+
"title": "userId",
562+
"type": "string",
563+
"description": "The user identifier."
564+
}
565+
},
566+
"required": ["accessToken", "userId"]
536567
}
537568
},
538569
"required": ["kernel", "isConnected", "isNetworkConnected"]

api-specs/openrpc-dapp-remote-api.json

Lines changed: 49 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,7 @@
2323
"result": {
2424
"name": "result",
2525
"schema": {
26-
"title": "ConnectResult",
27-
"type": "object",
28-
"properties": {
29-
"status": {
30-
"$ref": "#/components/schemas/StatusEvent"
31-
},
32-
"sessionToken": {
33-
"title": "sessionToken",
34-
"type": "string",
35-
"description": "JWT authentication token (if applicable)."
36-
}
37-
},
38-
"required": ["status", "sessionToken"]
26+
"$ref": "#/components/schemas/StatusEvent"
3927
}
4028
},
4129
"description": "Ensures ledger connectivity and returns the connected network information along with the user access token. NetworkId should follow CAIP-2 and represent the synchronizerId."
@@ -166,19 +154,7 @@
166154
"result": {
167155
"name": "result",
168156
"schema": {
169-
"title": "OnConnectedEvent",
170-
"type": "object",
171-
"properties": {
172-
"status": {
173-
"$ref": "#/components/schemas/StatusEvent"
174-
},
175-
"sessionToken": {
176-
"title": "sessionToken",
177-
"type": "string",
178-
"description": "JWT authentication token (if applicable)."
179-
}
180-
},
181-
"required": ["kernel", "status"]
157+
"$ref": "#/components/schemas/StatusEvent"
182158
}
183159
},
184160
"description": "Informs when the user connects to a network."
@@ -558,10 +534,53 @@
558534
"type": "string",
559535
"description": "If not connected to a network, the reason why."
560536
},
561-
"networkId": {
562-
"title": "networkId",
563-
"type": "string",
564-
"description": "A CAIP-2 compliant chain ID, e.g. 'canton:da-mainnet'."
537+
"userUrl": {
538+
"$ref": "#/components/schemas/UserUrl"
539+
},
540+
"network": {
541+
"title": "network",
542+
"type": "object",
543+
"description": "Network information, if connected to a network.",
544+
"properties": {
545+
"networkId": {
546+
"title": "networkId",
547+
"type": "string",
548+
"description": "A CAIP-2 compliant chain ID, e.g. 'canton:da-mainnet'."
549+
},
550+
"ledgerApi": {
551+
"title": "LedgerApiConfig",
552+
"type": "object",
553+
"description": "Ledger API configuration.",
554+
"properties": {
555+
"baseUrl": {
556+
"title": "baseUrl",
557+
"type": "string",
558+
"format": "uri",
559+
"description": "The base URL of the ledger API."
560+
}
561+
},
562+
"required": ["baseUrl"]
563+
}
564+
},
565+
"required": ["networkId"]
566+
},
567+
"session": {
568+
"title": "session",
569+
"type": "object",
570+
"description": "Session information, if authenticated.",
571+
"properties": {
572+
"accessToken": {
573+
"title": "accessToken",
574+
"type": "string",
575+
"description": "JWT authentication token."
576+
},
577+
"userId": {
578+
"title": "userId",
579+
"type": "string",
580+
"description": "The user identifier."
581+
}
582+
},
583+
"required": ["accessToken", "userId"]
565584
}
566585
},
567586
"required": ["kernel", "isConnected", "isNetworkConnected"]

core/rpc-generator/src/components/client.ts

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,33 @@ export const stripAnyOfTypes = (content: string): string => {
6464

6565
const versionMap = new Map<string, string>()
6666

67+
// Derives the repository directory path from the destination path relative to repo root
68+
const getRepositoryDirectory = (destPath: string): string | null => {
69+
let currentPath = destPath
70+
const maxDepth = 10
71+
for (let i = 0; i < maxDepth; i++) {
72+
const packageJsonPath = path.join(currentPath, 'package.json')
73+
try {
74+
if (fs.existsSync(packageJsonPath)) {
75+
const pkgContent = fs.readFileSync(packageJsonPath, 'utf-8')
76+
const pkg = JSON.parse(pkgContent)
77+
if (pkg.workspaces || pkg.name === 'splice-wallet-kernel') {
78+
const relativePath = path.relative(currentPath, destPath)
79+
return relativePath.replace(/\\/g, '/') // Normalize to forward slashes
80+
}
81+
}
82+
} catch {
83+
// Continue searching
84+
}
85+
const parentPath = path.dirname(currentPath)
86+
if (parentPath === currentPath) {
87+
break
88+
}
89+
currentPath = parentPath
90+
}
91+
return null
92+
}
93+
6794
const hooks: IHooks = {
6895
afterCopyStatic: [
6996
async (dest, frm, component): Promise<void> => {
@@ -96,13 +123,24 @@ const hooks: IHooks = {
96123
const packagePath = path.join(dest, 'package.json')
97124
const fileContents = await readFile(packagePath)
98125
const pkg = JSON.parse(fileContents.toString())
99-
const updatedPkg = JSON.stringify({
126+
const updatedPkgObj: Record<string, unknown> = {
100127
...pkg,
101128
name: component.name,
102129
version:
103130
versionMap.get(component.name) ??
104131
openrpcDocument.info.version,
105-
})
132+
}
133+
134+
const repositoryDirectory = getRepositoryDirectory(dest)
135+
if (repositoryDirectory) {
136+
updatedPkgObj.repository = {
137+
type: 'git',
138+
url: 'git+https://github.com/hyperledger-labs/splice-wallet-kernel.git',
139+
directory: repositoryDirectory,
140+
}
141+
}
142+
// else - fallback to repository field in template
143+
const updatedPkg = JSON.stringify(updatedPkgObj)
106144
execSync(`yarn prettier --write ${dest}/src/**/*`)
107145
return await writeFile(packagePath, updatedPkg)
108146
}

core/splice-provider/src/SpliceProviderHttp.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,7 @@ export class SpliceProviderHttp extends SpliceProviderBase {
7676
// dappApi.OnConnectedEvent are mapped manually to avoid dependency.
7777
this.request({ method: 'status' })
7878
.then((status) => {
79-
this.emit('onConnected', {
80-
status: status,
81-
sessionToken: this.sessionToken,
82-
})
79+
this.emit('onConnected', status)
8380
})
8481
.catch((err) => {
8582
console.error(

core/wallet-dapp-remote-rpc-client/src/index.ts

Lines changed: 57 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -134,26 +134,65 @@ export type IsNetworkConnected = boolean
134134
*
135135
*/
136136
export type NetworkReason = string
137+
/**
138+
*
139+
* A URL that points to a user interface.
140+
*
141+
*/
142+
export type UserUrl = string
137143
/**
138144
*
139145
* The network ID the wallet corresponds to.
140146
*
141147
*/
142148
export type NetworkId = string
143-
export interface StatusEvent {
144-
kernel: KernelInfo
145-
isConnected: IsConnected
146-
isNetworkConnected: IsNetworkConnected
147-
networkReason?: NetworkReason
148-
networkId?: NetworkId
149+
/**
150+
*
151+
* The base URL of the ledger API.
152+
*
153+
*/
154+
export type BaseUrl = string
155+
/**
156+
*
157+
* Ledger API configuration.
158+
*
159+
*/
160+
export interface LedgerApiConfig {
161+
baseUrl: BaseUrl
149162
[k: string]: any
150163
}
151164
/**
152165
*
153-
* JWT authentication token (if applicable).
166+
* Network information, if connected to a network.
154167
*
155168
*/
156-
export type SessionToken = string
169+
export interface Network {
170+
networkId: NetworkId
171+
ledgerApi?: LedgerApiConfig
172+
[k: string]: any
173+
}
174+
/**
175+
*
176+
* JWT authentication token.
177+
*
178+
*/
179+
export type AccessToken = string
180+
/**
181+
*
182+
* The user identifier.
183+
*
184+
*/
185+
export type UserId = string
186+
/**
187+
*
188+
* Session information, if authenticated.
189+
*
190+
*/
191+
export interface Session {
192+
accessToken: AccessToken
193+
userId: UserId
194+
[k: string]: any
195+
}
157196
export type Dar = string
158197
export type Dars = Dar[]
159198
/**
@@ -178,12 +217,6 @@ export interface JsPrepareSubmissionResponse {
178217
preparedTransactionHash?: PreparedTransactionHash
179218
[k: string]: any
180219
}
181-
/**
182-
*
183-
* A URL that points to a user interface.
184-
*
185-
*/
186-
export type UserUrl = string
187220
export type Response = string
188221
/**
189222
*
@@ -393,9 +426,14 @@ export interface LedgerApiParams {
393426
body?: Body
394427
[k: string]: any
395428
}
396-
export interface ConnectResult {
397-
status: StatusEvent
398-
sessionToken: SessionToken
429+
export interface StatusEvent {
430+
kernel: KernelInfo
431+
isConnected: IsConnected
432+
isNetworkConnected: IsNetworkConnected
433+
networkReason?: NetworkReason
434+
userUrl?: UserUrl
435+
network?: Network
436+
session?: Session
399437
[k: string]: any
400438
}
401439
/**
@@ -422,11 +460,6 @@ export interface LedgerApiResult {
422460
response: Response
423461
[k: string]: any
424462
}
425-
export interface OnConnectedEvent {
426-
status: StatusEvent
427-
sessionToken?: SessionToken
428-
[k: string]: any
429-
}
430463
/**
431464
*
432465
* Event emitted when the user's accounts change.
@@ -456,7 +489,7 @@ export type TxChangedEvent =
456489
*/
457490

458491
export type Status = () => Promise<StatusEvent>
459-
export type Connect = () => Promise<ConnectResult>
492+
export type Connect = () => Promise<StatusEvent>
460493
export type Disconnect = () => Promise<Null>
461494
export type DarsAvailable = () => Promise<DarsAvailableResult>
462495
export type PrepareReturn = (
@@ -466,7 +499,7 @@ export type PrepareExecute = (
466499
params: PrepareExecuteParams
467500
) => Promise<PrepareExecuteResult>
468501
export type LedgerApi = (params: LedgerApiParams) => Promise<LedgerApiResult>
469-
export type OnConnected = () => Promise<OnConnectedEvent>
502+
export type OnConnected = () => Promise<StatusEvent>
470503
export type OnStatusChanged = () => Promise<StatusEvent>
471504
export type OnAccountsChanged = () => Promise<AccountsChangedEvent>
472505
export type RequestAccounts = () => Promise<RequestAccountsResult>

0 commit comments

Comments
 (0)