Skip to content

Commit cb3149b

Browse files
feat: extend StatusEvent props (#977)
Signed-off-by: Pawel Stepien <[email protected]>
1 parent bc623c7 commit cb3149b

File tree

21 files changed

+600
-250
lines changed

21 files changed

+600
-250
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/rpc-generator/templates/client/typescript/_package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"version": "0.0.0",
44
"type": "module",
55
"description": "TypeScript client generated by OpenRPC",
6-
"repository": "github:hyperledger-labs/splice-wallet-kernel",
76
"license": "Apache-2.0",
87
"main": "dist/index.cjs",
98
"module": "dist/index.js",
@@ -42,5 +41,6 @@
4241
"tsup": "^8.5.1",
4342
"typedoc": "^0.28.14",
4443
"typescript": "^5.9.3"
45-
}
44+
},
45+
"repository": "github:hyperledger-labs/splice-wallet-kernel"
4646
}

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(

0 commit comments

Comments
 (0)