diff --git a/docs/wallet-integration-guide/examples/scripts/12-subscribe-to-events.ts b/docs/wallet-integration-guide/examples/scripts/12-subscribe-to-events.ts index 8ed4aee00..af1227ad5 100644 --- a/docs/wallet-integration-guide/examples/scripts/12-subscribe-to-events.ts +++ b/docs/wallet-integration-guide/examples/scripts/12-subscribe-to-events.ts @@ -10,7 +10,9 @@ const sdk = await SDK.create({ auth: TOKEN_PROVIDER_CONFIG_DEFAULT, ledgerClientUrl: localNetStaticConfig.LOCALNET_APP_USER_LEDGER_URL, events: { - websocketURL: `ws://${localNetStaticConfig.LOCALNET_APP_USER_LEDGER_URL.host}`, + websocketURL: new URL( + `ws://${localNetStaticConfig.LOCALNET_APP_USER_LEDGER_URL.host}` + ), auth: TOKEN_PROVIDER_CONFIG_DEFAULT, }, }) diff --git a/docs/wallet-integration-guide/examples/snippets/config-template.ts b/docs/wallet-integration-guide/examples/snippets/config-template.ts index 65efa427e..8c4a49bd9 100644 --- a/docs/wallet-integration-guide/examples/snippets/config-template.ts +++ b/docs/wallet-integration-guide/examples/snippets/config-template.ts @@ -12,10 +12,12 @@ export default async function () { scope: '', }, }, - ledgerClientUrl: 'http://localhost:2975', + ledgerClientUrl: new URL('http://localhost:2975'), token: { - validatorUrl: 'http://localhost:2000/api/validator', - registries: ['http://localhost:2000/api/validator/v0/scan-proxy'], + validatorUrl: new URL('http://localhost:2000/api/validator'), + registries: [ + new URL('http://localhost:2000/api/validator/v0/scan-proxy'), + ], auth: global.TOKEN_PROVIDER_CONFIG_DEFAULT, }, amulet: { @@ -49,14 +51,16 @@ export default async function () { scope: '', }, }, - ledgerClientUrl: 'http://localhost:2975', + ledgerClientUrl: new URL('http://localhost:2975'), }) // Extend with token namespace const tokenExtendedSDK = await basicSDK.extend({ token: { - validatorUrl: 'http://localhost:2000/api/validator', - registries: ['http://localhost:2000/api/validator/v0/scan-proxy'], + validatorUrl: new URL('http://localhost:2000/api/validator'), + registries: [ + new URL('http://localhost:2000/api/validator/v0/scan-proxy'), + ], auth: global.TOKEN_PROVIDER_CONFIG_DEFAULT, }, }) diff --git a/examples/ping/src/components/Holdings.tsx b/examples/ping/src/components/Holdings.tsx index 3cc3a4643..799b6354c 100644 --- a/examples/ping/src/components/Holdings.tsx +++ b/examples/ping/src/components/Holdings.tsx @@ -6,9 +6,7 @@ import { useState } from 'react' export default function Holdings(props: { connectResult?: sdk.dappAPI.ConnectResult }) { - const [urls, setUrls] = useState<{ validator?: string; registry?: string }>( - {} - ) + const [urls, setUrls] = useState<{ validator?: URL; registry?: URL }>({}) const [inputValidator, setInputValidator] = useState('') const [inputRegistry, setInputRegistry] = useState('') @@ -32,8 +30,8 @@ export default function Holdings(props: { onSubmit={(e) => { e.preventDefault() setUrls({ - validator: inputValidator, - registry: inputRegistry, + validator: new URL(inputValidator), + registry: new URL(inputRegistry), }) }} > diff --git a/examples/ping/src/hooks/useHoldings.ts b/examples/ping/src/hooks/useHoldings.ts index 0508ebe92..63c0dc4d1 100644 --- a/examples/ping/src/hooks/useHoldings.ts +++ b/examples/ping/src/hooks/useHoldings.ts @@ -8,8 +8,8 @@ import * as walletSDK from '@canton-network/wallet-sdk' export function useHoldings( connectResult?: sdk.dappAPI.ConnectResult, - validatorUrl?: string, - registryUrl?: string + validatorUrl?: URL, + registryUrl?: URL ) { // eslint-disable-next-line @typescript-eslint/no-explicit-any const [holdings, setHoldings] = useState() diff --git a/sdk/wallet-sdk/src/wallet/common.ts b/sdk/wallet-sdk/src/wallet/common.ts index 196edce93..baf459b80 100644 --- a/sdk/wallet-sdk/src/wallet/common.ts +++ b/sdk/wallet-sdk/src/wallet/common.ts @@ -1,6 +1,7 @@ // Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. // SPDX-License-Identifier: Apache-2.0 +import { TokenStandardService } from '@canton-network/core-token-standard-service' import { SDKErrorHandler } from './error/index.js' export function toURL(input: string | URL, error: SDKErrorHandler): URL { @@ -17,3 +18,13 @@ export function toURL(input: string | URL, error: SDKErrorHandler): URL { return parsedUrl } + +export function parseAssets( + assets: Awaited>, + error: SDKErrorHandler +) { + return assets.map((asset) => ({ + ...asset, + registryUrl: toURL(asset.registryUrl, error), + })) +} diff --git a/sdk/wallet-sdk/src/wallet/init/initializedSDK.ts b/sdk/wallet-sdk/src/wallet/init/initializedSDK.ts index 57d7dc701..582c71f54 100644 --- a/sdk/wallet-sdk/src/wallet/init/initializedSDK.ts +++ b/sdk/wallet-sdk/src/wallet/init/initializedSDK.ts @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { AuthTokenProvider } from '@canton-network/core-wallet-auth' -import { toURL } from '../common.js' +import { parseAssets, toURL } from '../common.js' import { KeysNamespace } from '../namespace/keys/index.js' import { LedgerNamespace } from '../namespace/ledger/index.js' import { PartyNamespace } from '../namespace/party/index.js' @@ -118,8 +118,11 @@ const createNamespace: { tokenStandardService, registries: config.registries, error: ctx.error, - list: await tokenStandardService.registriesToAssets( - config.registries.map((url) => url.href) + list: parseAssets( + await tokenStandardService.registriesToAssets( + config.registries.map((registry) => registry.href) + ), + ctx.error ), }) }, @@ -128,7 +131,7 @@ const createNamespace: { return new EventsNamespace({ commonCtx: ctx, auth, - websocketURL: config.websocketURL, + websocketURL: config.websocketURL.href, }) }, } diff --git a/sdk/wallet-sdk/src/wallet/init/types/config.ts b/sdk/wallet-sdk/src/wallet/init/types/config.ts index 37f2a3b5c..f97c41dbd 100644 --- a/sdk/wallet-sdk/src/wallet/init/types/config.ts +++ b/sdk/wallet-sdk/src/wallet/init/types/config.ts @@ -4,16 +4,16 @@ import { TokenProviderConfig } from '@canton-network/core-wallet-auth' export type AmuletConfig = { - validatorUrl: string | URL - scanApiUrl: string | URL + validatorUrl: URL + scanApiUrl: URL auth: TokenProviderConfig registryUrl: URL } export type TokenConfig = { - validatorUrl: string | URL + validatorUrl: URL auth: TokenProviderConfig - registries: URL[] | string[] + registries: URL[] } export type AssetConfig = { @@ -22,6 +22,6 @@ export type AssetConfig = { } export type EventsConfig = { - websocketURL: string + websocketURL: URL auth: TokenProviderConfig } diff --git a/sdk/wallet-sdk/src/wallet/init/types/sdk.ts b/sdk/wallet-sdk/src/wallet/init/types/sdk.ts index f3b24be7b..2aece0141 100644 --- a/sdk/wallet-sdk/src/wallet/init/types/sdk.ts +++ b/sdk/wallet-sdk/src/wallet/init/types/sdk.ts @@ -32,10 +32,10 @@ import { LedgerTypes } from '@canton-network/core-ledger-client-types' */ export type BasicSDKOptions = Readonly< { - websocketUrl?: string | URL // default to same host as ledgerClientUrl with ws protocol + websocketUrl?: URL // default to same host as ledgerClientUrl with ws protocol logAdapter?: AllowedLogAdapters } & ( - | { auth: TokenProviderConfig; ledgerClientUrl: string | URL } + | { auth: TokenProviderConfig; ledgerClientUrl: URL } | { ledgerProvider: Provider } ) > diff --git a/sdk/wallet-sdk/src/wallet/namespace/amulet/namespace.ts b/sdk/wallet-sdk/src/wallet/namespace/amulet/namespace.ts index 885fd7acc..9134e909d 100644 --- a/sdk/wallet-sdk/src/wallet/namespace/amulet/namespace.ts +++ b/sdk/wallet-sdk/src/wallet/namespace/amulet/namespace.ts @@ -15,6 +15,7 @@ import { TrafficNamespace } from './traffic.js' import { LedgerNamespace } from '../ledger/namespace.js' import { PreapprovalNamespace } from './preapproval.js' import { Decimal } from 'decimal.js' +import { parseAssets } from '../../common.js' const defaultMaxRetries = 10 const defaultDelayMs = 5000 @@ -38,13 +39,16 @@ export class AmuletNamespace { } private async amulet(): Promise { - return this.sdkContext.registry instanceof URL - ? ( - await this.sdkContext.tokenStandardService.registriesToAssets( - [this.sdkContext.registry.href] - ) - )[0] - : this.sdkContext.registry + if (this.sdkContext.registry instanceof URL) { + return parseAssets( + await this.sdkContext.tokenStandardService.registriesToAssets([ + this.sdkContext.registry.href, + ]), + this.sdkContext.commonCtx.error + )[0] + } else { + return this.sdkContext.registry + } } /** @@ -62,7 +66,7 @@ export class AmuletNamespace { new Decimal(amount).toFixed(10), amulet.admin, amulet.id, - amulet.registryUrl + amulet.registryUrl.href ) return [{ ExerciseCommand: tapCommand }, disclosedContracts] } @@ -198,11 +202,14 @@ interface FeaturedAppNamespace { export async function fetchAmulet( amuletCtx: AmuletNamespaceConfig ): Promise { - return amuletCtx.registry instanceof URL - ? ( - await amuletCtx.tokenStandardService.registriesToAssets([ - amuletCtx.registry.href, - ]) - )[0] - : amuletCtx.registry + if (amuletCtx.registry instanceof URL) { + return parseAssets( + await amuletCtx.tokenStandardService.registriesToAssets([ + amuletCtx.registry.href, + ]), + amuletCtx.commonCtx.error + )[0] + } else { + return amuletCtx.registry + } } diff --git a/sdk/wallet-sdk/src/wallet/namespace/asset/index.ts b/sdk/wallet-sdk/src/wallet/namespace/asset/index.ts index c8cd2cbeb..2dbf58162 100644 --- a/sdk/wallet-sdk/src/wallet/namespace/asset/index.ts +++ b/sdk/wallet-sdk/src/wallet/namespace/asset/index.ts @@ -9,7 +9,7 @@ export type AssetBody = { id: string displayName: string symbol: string - registryUrl: string + registryUrl: URL admin: PartyId } @@ -27,10 +27,7 @@ export class AssetNamespace { return this.ctx.list } - public async find( - id: string, - registryUrl?: URL | string - ): Promise { + public async find(id: string, registryUrl?: URL): Promise { return await findAsset(this.list, id, this.ctx.error, registryUrl) } } @@ -39,17 +36,10 @@ export function findAsset( assets: AssetBody[], id: string, error: SDKErrorHandler, - registryUrl?: URL | string + registryUrl?: URL ): AssetBody { const asset = registryUrl - ? assets.filter( - (asset) => - asset.id === id && - asset.registryUrl === - (registryUrl instanceof URL - ? registryUrl?.href - : registryUrl) - ) + ? assets.filter((asset) => asset.id === id && asset.registryUrl.href) : assets.filter((asset) => asset.id === id) if (asset.length === 0) { diff --git a/sdk/wallet-sdk/src/wallet/namespace/token/allocation/service.ts b/sdk/wallet-sdk/src/wallet/namespace/token/allocation/service.ts index 505652b2e..3f6a5ac81 100644 --- a/sdk/wallet-sdk/src/wallet/namespace/token/allocation/service.ts +++ b/sdk/wallet-sdk/src/wallet/namespace/token/allocation/service.ts @@ -44,7 +44,7 @@ export class AllocationNamespace { const [command, disclosedConctracts] = await this.sdkContext.tokenStandardService.allocation.createExecuteTransferAllocation( params.allocationCid, - params.asset.registryUrl, + params.asset.registryUrl.href, params.prefetchedRegistryChoiceContext ) @@ -55,7 +55,7 @@ export class AllocationNamespace { const [command, disclosedConctracts] = await this.sdkContext.tokenStandardService.allocation.createWithdrawAllocation( params.allocationCid, - params.asset.registryUrl, + params.asset.registryUrl.href, params.prefetchedRegistryChoiceContext ) @@ -66,7 +66,7 @@ export class AllocationNamespace { const [command, disclosedConctracts] = await this.sdkContext.tokenStandardService.allocation.createCancelAllocation( params.allocationCid, - params.asset.registryUrl, + params.asset.registryUrl.href, params.prefetchedRegistryChoiceContext ) @@ -122,7 +122,7 @@ export class AllocationNamespace { await this.sdkContext.tokenStandardService.allocation.createAllocationInstruction( params.allocationSpecification, params.asset.admin, - params.asset.registryUrl, + params.asset.registryUrl.href, params.inputUtxos, params.requestedAt, params.prefetchedRegistryChoiceContext diff --git a/sdk/wallet-sdk/src/wallet/namespace/token/transfer/service.ts b/sdk/wallet-sdk/src/wallet/namespace/token/transfer/service.ts index c18ebc997..dfb7658f5 100644 --- a/sdk/wallet-sdk/src/wallet/namespace/token/transfer/service.ts +++ b/sdk/wallet-sdk/src/wallet/namespace/token/transfer/service.ts @@ -11,6 +11,7 @@ import { TransferAllocationChoiceParams, TransferParams } from './types.js' import { PreparedCommand } from '../../transactions/types.js' import { ProxyDelegationNamespace } from './proxyDelegation.js' import { findAsset } from '../../asset/index.js' +import { parseAssets } from '../../../common.js' export class TransferNamespace { public readonly delegatedProxy: ProxyDelegationNamespace @@ -61,10 +62,12 @@ export class TransferNamespace { async create( params: TransferParams ): Promise> { - const assets = + const assets = parseAssets( await this.sdkContext.tokenStandardService.registriesToAssets( this.sdkContext.registryUrls.map((url) => url.href) - ) + ), + this.sdkContext.commonCtx.error + ) const asset = findAsset( assets, params.instrumentId, @@ -85,7 +88,7 @@ export class TransferNamespace { params.amount, asset.admin, asset.id, - asset.registryUrl, + asset.registryUrl.href, params.inputUtxos, params.memo, params.expirationDate, diff --git a/sdk/wallet-sdk/src/wallet/namespace/token/utxos/service.ts b/sdk/wallet-sdk/src/wallet/namespace/token/utxos/service.ts index 0216ad54f..8c3c13e4e 100644 --- a/sdk/wallet-sdk/src/wallet/namespace/token/utxos/service.ts +++ b/sdk/wallet-sdk/src/wallet/namespace/token/utxos/service.ts @@ -10,6 +10,7 @@ import { findAsset, LedgerTypes, TokenNamespaceConfig } from '../../../sdk.js' import { Decimal } from 'decimal.js' import { TransferNamespace } from '../transfer/index.js' import { MergeDelegationNamespace } from './mergeDelegation.js' +import { parseAssets } from '../../../common.js' export class UtxoNamespace { public readonly delegatedMerge: MergeDelegationNamespace @@ -61,10 +62,12 @@ export class UtxoNamespace { const { id: instrumentId } = group[0].interfaceViewValue.instrumentId - const assets = + const assets = parseAssets( await this.sdkContext.tokenStandardService.registriesToAssets( this.sdkContext.registryUrls.map((url) => url.href) - ) + ), + this.sdkContext.commonCtx.error + ) const registryUrl = new URL( findAsset(assets, instrumentId, this.sdkContext.commonCtx.error) diff --git a/yarn.lock b/yarn.lock index e19cd3088..144738dd3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -20243,7 +20243,6 @@ __metadata: resolution: "systeminformation@npm:5.31.6" bin: systeminformation: lib/cli.js - checksum: 10c0/fb0c9dae20e47277d26f3dd374f14c846567adba15a2bf9715e0a871f912424d31b75f6c27e0c8b819abc3fcd285ae8c1f6468acd8a161f18a1a39b632a01923 conditions: (os=darwin | os=linux | os=win32 | os=freebsd | os=openbsd | os=netbsd | os=sunos | os=android) languageName: node linkType: hard