Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 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
51 changes: 47 additions & 4 deletions api-specs/openrpc-dapp-api.json
Original file line number Diff line number Diff line change
Expand Up @@ -529,10 +529,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
51 changes: 47 additions & 4 deletions api-specs/openrpc-dapp-remote-api.json
Original file line number Diff line number Diff line change
Expand Up @@ -558,10 +558,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"
}
63 changes: 56 additions & 7 deletions core/wallet-dapp-remote-rpc-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,73 @@ export type IsNetworkConnected = boolean
*
*/
export type NetworkReason = string
/**
*
* A URL that points to a user interface.
*
*/
export type UserUrl = string
/**
*
* The network ID the wallet corresponds to.
*
*/
export type NetworkId = string
/**
*
* The base URL of the ledger API.
*
*/
export type BaseUrl = string
/**
*
* Ledger API configuration.
*
*/
export interface LedgerApiConfig {
baseUrl: BaseUrl
[k: string]: any
}
/**
*
* Network information, if connected to a network.
*
*/
export interface Network {
networkId: NetworkId
ledgerApi?: LedgerApiConfig
[k: string]: any
}
/**
*
* JWT authentication token.
*
*/
export type AccessToken = string
/**
*
* The user identifier.
*
*/
export type UserId = string
/**
*
* Session information, if authenticated.
*
*/
export interface Session {
accessToken: AccessToken
userId: UserId
[k: string]: any
}
export interface StatusEvent {
kernel: KernelInfo
isConnected: IsConnected
isNetworkConnected: IsNetworkConnected
networkReason?: NetworkReason
networkId?: NetworkId
userUrl?: UserUrl
network?: Network
session?: Session
[k: string]: any
}
/**
Expand Down Expand Up @@ -178,12 +233,6 @@ export interface JsPrepareSubmissionResponse {
preparedTransactionHash?: PreparedTransactionHash
[k: string]: any
}
/**
*
* A URL that points to a user interface.
*
*/
export type UserUrl = string
export type Response = string
/**
*
Expand Down
51 changes: 47 additions & 4 deletions core/wallet-dapp-remote-rpc-client/src/openrpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -558,10 +558,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
Loading
Loading