Skip to content
Merged
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
65 changes: 48 additions & 17 deletions api-specs/openrpc-dapp-api.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,7 @@
"result": {
"name": "result",
"schema": {
"title": "ConnectResult",
"type": "object",
"properties": {
"status": {
"$ref": "#/components/schemas/StatusEvent"
},
"sessionToken": {
"title": "sessionToken",
"type": "string",
"description": "JWT authentication token (if applicable)."
}
},
"required": ["status", "sessionToken"]
"$ref": "#/components/schemas/StatusEvent"
}
},
"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."
Expand Down Expand Up @@ -529,10 +517,53 @@
"type": "string",
"description": "If not connected to a network, the reason why."
},
"networkId": {
"title": "networkId",
"type": "string",
"description": "A CAIP-2 compliant chain ID, e.g. 'canton:da-mainnet'."
"userUrl": {
"$ref": "#/components/schemas/UserUrl"
},
"network": {
"title": "network",
"type": "object",
"description": "Network information, if connected to a network.",
"properties": {
"networkId": {
"title": "networkId",
"type": "string",
"description": "A CAIP-2 compliant chain ID, e.g. 'canton:da-mainnet'."
},
"ledgerApi": {
"title": "LedgerApiConfig",
"type": "object",
"description": "Ledger API configuration.",
"properties": {
"baseUrl": {
"title": "baseUrl",
"type": "string",
"format": "uri",
"description": "The base URL of the ledger API."
}
},
"required": ["baseUrl"]
}
},
"required": ["networkId"]
},
"session": {
"title": "session",
"type": "object",
"description": "Session information, if authenticated.",
"properties": {
"accessToken": {
"title": "accessToken",
"type": "string",
"description": "JWT authentication token."
},
"userId": {
"title": "userId",
"type": "string",
"description": "The user identifier."
}
},
"required": ["accessToken", "userId"]
}
},
"required": ["kernel", "isConnected", "isNetworkConnected"]
Expand Down
79 changes: 49 additions & 30 deletions api-specs/openrpc-dapp-remote-api.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,7 @@
"result": {
"name": "result",
"schema": {
"title": "ConnectResult",
"type": "object",
"properties": {
"status": {
"$ref": "#/components/schemas/StatusEvent"
},
"sessionToken": {
"title": "sessionToken",
"type": "string",
"description": "JWT authentication token (if applicable)."
}
},
"required": ["status", "sessionToken"]
"$ref": "#/components/schemas/StatusEvent"
}
},
"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."
Expand Down Expand Up @@ -166,19 +154,7 @@
"result": {
"name": "result",
"schema": {
"title": "OnConnectedEvent",
"type": "object",
"properties": {
"status": {
"$ref": "#/components/schemas/StatusEvent"
},
"sessionToken": {
"title": "sessionToken",
"type": "string",
"description": "JWT authentication token (if applicable)."
}
},
"required": ["kernel", "status"]
"$ref": "#/components/schemas/StatusEvent"
}
},
"description": "Informs when the user connects to a network."
Expand Down Expand Up @@ -558,10 +534,53 @@
"type": "string",
"description": "If not connected to a network, the reason why."
},
"networkId": {
"title": "networkId",
"type": "string",
"description": "A CAIP-2 compliant chain ID, e.g. 'canton:da-mainnet'."
"userUrl": {
"$ref": "#/components/schemas/UserUrl"
},
"network": {
"title": "network",
"type": "object",
"description": "Network information, if connected to a network.",
"properties": {
"networkId": {
"title": "networkId",
"type": "string",
"description": "A CAIP-2 compliant chain ID, e.g. 'canton:da-mainnet'."
},
"ledgerApi": {
"title": "LedgerApiConfig",
"type": "object",
"description": "Ledger API configuration.",
"properties": {
"baseUrl": {
"title": "baseUrl",
"type": "string",
"format": "uri",
"description": "The base URL of the ledger API."
}
},
"required": ["baseUrl"]
}
},
"required": ["networkId"]
},
"session": {
"title": "session",
"type": "object",
"description": "Session information, if authenticated.",
"properties": {
"accessToken": {
"title": "accessToken",
"type": "string",
"description": "JWT authentication token."
},
"userId": {
"title": "userId",
"type": "string",
"description": "The user identifier."
}
},
"required": ["accessToken", "userId"]
}
},
"required": ["kernel", "isConnected", "isNetworkConnected"]
Expand Down
42 changes: 40 additions & 2 deletions core/rpc-generator/src/components/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,33 @@ export const stripAnyOfTypes = (content: string): string => {

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

// Derives the repository directory path from the destination path relative to repo root
const getRepositoryDirectory = (destPath: string): string | null => {
let currentPath = destPath
const maxDepth = 10
for (let i = 0; i < maxDepth; i++) {
const packageJsonPath = path.join(currentPath, 'package.json')
try {
if (fs.existsSync(packageJsonPath)) {
const pkgContent = fs.readFileSync(packageJsonPath, 'utf-8')
const pkg = JSON.parse(pkgContent)
if (pkg.workspaces || pkg.name === 'splice-wallet-kernel') {
const relativePath = path.relative(currentPath, destPath)
return relativePath.replace(/\\/g, '/') // Normalize to forward slashes
}
}
} catch {
// Continue searching
}
const parentPath = path.dirname(currentPath)
if (parentPath === currentPath) {
break
}
currentPath = parentPath
}
return null
}

const hooks: IHooks = {
afterCopyStatic: [
async (dest, frm, component): Promise<void> => {
Expand Down Expand Up @@ -96,13 +123,24 @@ const hooks: IHooks = {
const packagePath = path.join(dest, 'package.json')
const fileContents = await readFile(packagePath)
const pkg = JSON.parse(fileContents.toString())
const updatedPkg = JSON.stringify({
const updatedPkgObj: Record<string, unknown> = {
...pkg,
name: component.name,
version:
versionMap.get(component.name) ??
openrpcDocument.info.version,
})
}

const repositoryDirectory = getRepositoryDirectory(dest)
if (repositoryDirectory) {
updatedPkgObj.repository = {
type: 'git',
url: 'git+https://github.com/hyperledger-labs/splice-wallet-kernel.git',
directory: repositoryDirectory,
}
}
// else - fallback to repository field in template
const updatedPkg = JSON.stringify(updatedPkgObj)
execSync(`yarn prettier --write ${dest}/src/**/*`)
return await writeFile(packagePath, updatedPkg)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"version": "0.0.0",
"type": "module",
"description": "TypeScript client generated by OpenRPC",
"repository": "github:hyperledger-labs/splice-wallet-kernel",
"license": "Apache-2.0",
"main": "dist/index.cjs",
"module": "dist/index.js",
Expand Down Expand Up @@ -42,5 +41,6 @@
"tsup": "^8.5.1",
"typedoc": "^0.28.14",
"typescript": "^5.9.3"
}
},
"repository": "github:hyperledger-labs/splice-wallet-kernel"
}
5 changes: 1 addition & 4 deletions core/splice-provider/src/SpliceProviderHttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ export class SpliceProviderHttp extends SpliceProviderBase {
// dappApi.OnConnectedEvent are mapped manually to avoid dependency.
this.request({ method: 'status' })
.then((status) => {
this.emit('onConnected', {
status: status,
sessionToken: this.sessionToken,
})
this.emit('onConnected', status)
})
.catch((err) => {
console.error(
Expand Down
Loading
Loading