Skip to content
Open
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
2 changes: 1 addition & 1 deletion core/wallet-test-utils/src/otc-trade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class OTCTrade {

const amuletAsset = await this.sdk.asset.find(
'Amulet',
localNetStaticConfig.LOCALNET_REGISTRY_API_URL
new URL(localNetStaticConfig.LOCALNET_REGISTRY_API_URL)
)

// Define what holdings each party will trade
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ const sdk = await SDK.create({
auth: TOKEN_PROVIDER_CONFIG_DEFAULT,
ledgerClientUrl: localNetStaticConfig.LOCALNET_APP_USER_LEDGER_URL,
events: {
websocketURL: new URL(
`ws://${localNetStaticConfig.LOCALNET_APP_USER_LEDGER_URL.host}`
),
websocketURL: `ws://${new URL(localNetStaticConfig.LOCALNET_APP_USER_LEDGER_URL).host}`,
auth: TOKEN_PROVIDER_CONFIG_DEFAULT,
},
})
Expand Down
15 changes: 6 additions & 9 deletions sdk/wallet-sdk/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

const LOCALNET_APP_VALIDATOR_URL = new URL(
'http://localhost:2000/api/validator'
)
const LOCALNET_APP_VALIDATOR_URL = 'http://localhost:2000/api/validator'

const LOCALNET_SCAN_API_URL = new URL('http://scan.localhost:4000/api/scan')
const LOCALNET_SCAN_API_URL = 'http://scan.localhost:4000/api/scan'

const LOCALNET_APP_USER_LEDGER_URL = new URL('http://localhost:2975')
const LOCALNET_APP_USER_LEDGER_URL = 'http://localhost:2975'

const LOCALNET_TOKEN_STANDARD_URL = new URL('http://localhost:5003')
const LOCALNET_TOKEN_STANDARD_URL = 'http://localhost:5003'

//scan proxy exposes the registry endpoints as well
const LOCALNET_REGISTRY_API_URL = new URL(
LOCALNET_APP_VALIDATOR_URL.href + '/v0/scan-proxy'
)
const LOCALNET_REGISTRY_API_URL = LOCALNET_APP_VALIDATOR_URL + '/v0/scan-proxy'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const LOCALNET_REGISTRY_API_URL = LOCALNET_APP_VALIDATOR_URL + '/v0/scan-proxy'
const LOCALNET_REGISTRY_API_URL = new URL(LOCALNET_APP_VALIDATOR_URL + '/v0/scan-proxy')


const LOCALNET_USER_ID = 'ledger-api-user'

export const localNetStaticConfig = {
Expand Down
1 change: 1 addition & 0 deletions sdk/wallet-sdk/src/wallet/init/initializedSDK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ const createNamespace: {
config.registries.map((registry) => registry.toString())
)
),
commonCtx: ctx,
})
},
events: async (ctx: SDKContext, config: EventsConfig) => {
Expand Down
22 changes: 18 additions & 4 deletions sdk/wallet-sdk/src/wallet/namespace/asset/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import { TokenStandardService } from '@canton-network/core-token-standard-service'
import { PartyId } from '@canton-network/core-types'
import { SDKErrorHandler } from '../../error/index.js'
import { ParsedURL, URLInput } from '../utils/url.js'
import { SDKContext } from '@/wallet/sdk.js'

export type AssetBody = {
id: string
Expand All @@ -18,6 +20,7 @@ export type AssetContext = {
registries: URL[]
error: SDKErrorHandler
list: AssetBody[]
commonCtx: SDKContext
}

export class AssetNamespace {
Expand All @@ -27,19 +30,30 @@ export class AssetNamespace {
return this.ctx.list
}

public async find(id: string, registryUrl?: URL): Promise<AssetBody> {
return await findAsset(this.list, id, this.ctx.error, registryUrl)
public async find(id: string, registryUrl?: URLInput): Promise<AssetBody> {
return await findAsset(
this.list,
id,
this.ctx.error,
registryUrl
? new ParsedURL(this.ctx.commonCtx, registryUrl)
: undefined
)
}
}

export function findAsset(
assets: AssetBody[],
id: string,
error: SDKErrorHandler,
registryUrl?: URL
registryUrl?: ParsedURL
): AssetBody {
const asset = registryUrl
? assets.filter((asset) => asset.id === id && asset.registryUrl)
? assets.filter(
(asset) =>
asset.id === id &&
asset.registryUrl.toString() === registryUrl.toString()
)
: assets.filter((asset) => asset.id === id)

if (asset.length === 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import { LedgerTypes } from '../../../sdk.js'
import { FeaturedAppRight } from '../../amulet/types.js'
import { TokenStandardService } from '@canton-network/core-token-standard-service'
import { LedgerNamespace } from '../../ledger/index.js'
import { ParsedURL, URLInput } from '../../utils/url.js'

type ProxyDelegationCommandArgs = {
proxyCid: string
transferInstructionCid: string
registryUrl?: URL
registryUrl?: URLInput
featuredAppRight: FeaturedAppRight
beneficiaries?: Beneficiaries[]
}
Expand Down Expand Up @@ -114,7 +115,7 @@ export class ProxyDelegationNamespace {
const [command, disclosedContracts] = await cb(
proxyCid,
transferInstructionCid,
registryUrl,
new ParsedURL(this.ctx.commonCtx, registryUrl),
featuredAppRight.contract_id,
[...beneficiaries, defaultBeneficiary]
)
Expand Down
15 changes: 9 additions & 6 deletions sdk/wallet-sdk/src/wallet/namespace/token/transfer/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +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 '../../utils/url.js'
import { parseAssets, ParsedURL } from '../../utils/url.js'

export class TransferNamespace {
public readonly delegatedProxy: ProxyDelegationNamespace
Expand All @@ -32,7 +32,8 @@ export class TransferNamespace {
const [ExerciseCommand, disclosedContracts] =
await this.sdkContext.tokenStandardService.transfer.createAcceptTransferInstruction(
params.transferInstructionCid,
params.registryUrl.href
new ParsedURL(this.sdkContext.commonCtx, params.registryUrl)
.href
)
return [{ ExerciseCommand }, disclosedContracts]
}
Expand All @@ -43,7 +44,8 @@ export class TransferNamespace {
const [ExerciseCommand, disclosedContracts] =
await this.sdkContext.tokenStandardService.transfer.createWithdrawTransferInstruction(
params.transferInstructionCid,
params.registryUrl.href
new ParsedURL(this.sdkContext.commonCtx, params.registryUrl)
.href
)
return [{ ExerciseCommand }, disclosedContracts]
}
Expand All @@ -54,7 +56,8 @@ export class TransferNamespace {
const [ExerciseCommand, disclosedContracts] =
await this.sdkContext.tokenStandardService.transfer.createRejectTransferInstruction(
params.transferInstructionCid,
params.registryUrl.href
new ParsedURL(this.sdkContext.commonCtx, params.registryUrl)
.href
)
return [{ ExerciseCommand }, disclosedContracts]
}
Expand All @@ -72,12 +75,12 @@ export class TransferNamespace {
assets,
params.instrumentId,
this.sdkContext.commonCtx.error,
params.registryUrl
new ParsedURL(this.sdkContext.commonCtx, params.registryUrl)
)

if (!asset || asset === undefined) {
throw new Error(
`Asset with id ${params.instrumentId} not found in asset list for registry URL: ${params.registryUrl.href}`
`Asset with id ${params.instrumentId} not found in asset list for registry URL: ${params.registryUrl.toString()}`
)
}

Expand Down
5 changes: 3 additions & 2 deletions sdk/wallet-sdk/src/wallet/namespace/token/transfer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@

import { PartyId } from '@canton-network/core-types'
import { Metadata } from '@canton-network/core-token-standard'
import { URLInput } from '../../utils/url'

export type TransferParams = {
sender: PartyId
recipient: PartyId
amount: string
instrumentId: string
registryUrl: URL
registryUrl: URLInput
inputUtxos?: string[]
expirationDate?: Date
meta?: Metadata
Expand All @@ -18,5 +19,5 @@ export type TransferParams = {

export type TransferAllocationChoiceParams = {
transferInstructionCid: string
registryUrl: URL
registryUrl: URLInput
}