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
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
})
Expand Down
16 changes: 10 additions & 6 deletions docs/wallet-integration-guide/examples/snippets/config-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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,
},
})
Expand Down
8 changes: 3 additions & 5 deletions examples/ping/src/components/Holdings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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('')
Expand All @@ -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),
})
}}
>
Expand Down
4 changes: 2 additions & 2 deletions examples/ping/src/hooks/useHoldings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any[]>()
Expand Down
11 changes: 11 additions & 0 deletions sdk/wallet-sdk/src/wallet/common.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -17,3 +18,13 @@ export function toURL(input: string | URL, error: SDKErrorHandler): URL {

return parsedUrl
}

export function parseAssets(
assets: Awaited<ReturnType<TokenStandardService['registriesToAssets']>>,
error: SDKErrorHandler
) {
return assets.map((asset) => ({
...asset,
registryUrl: toURL(asset.registryUrl, error),
}))
}
11 changes: 7 additions & 4 deletions sdk/wallet-sdk/src/wallet/init/initializedSDK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
),
})
},
Expand All @@ -128,7 +131,7 @@ const createNamespace: {
return new EventsNamespace({
commonCtx: ctx,
auth,
websocketURL: config.websocketURL,
websocketURL: config.websocketURL.href,
})
},
}
Expand Down
10 changes: 5 additions & 5 deletions sdk/wallet-sdk/src/wallet/init/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -22,6 +22,6 @@ export type AssetConfig = {
}

export type EventsConfig = {
websocketURL: string
websocketURL: URL
auth: TokenProviderConfig
}
4 changes: 2 additions & 2 deletions sdk/wallet-sdk/src/wallet/init/types/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ import { LedgerTypes } from '@canton-network/core-ledger-client-types'
*/
export type BasicSDKOptions<L extends LedgerTypes> = 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<L> }
)
>
Expand Down
37 changes: 22 additions & 15 deletions sdk/wallet-sdk/src/wallet/namespace/amulet/namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -38,13 +39,16 @@ export class AmuletNamespace {
}

private async amulet(): Promise<AssetBody> {
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
}
}

/**
Expand All @@ -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]
}
Expand Down Expand Up @@ -198,11 +202,14 @@ interface FeaturedAppNamespace {
export async function fetchAmulet(
amuletCtx: AmuletNamespaceConfig
): Promise<AssetBody> {
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
}
}
18 changes: 4 additions & 14 deletions sdk/wallet-sdk/src/wallet/namespace/asset/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type AssetBody = {
id: string
displayName: string
symbol: string
registryUrl: string
registryUrl: URL
admin: PartyId
}

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

public async find(
id: string,
registryUrl?: URL | string
): Promise<AssetBody> {
public async find(id: string, registryUrl?: URL): Promise<AssetBody> {
return await findAsset(this.list, id, this.ctx.error, registryUrl)
}
}
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand All @@ -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
)

Expand All @@ -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
)

Expand Down Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions sdk/wallet-sdk/src/wallet/namespace/token/transfer/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -61,10 +62,12 @@ export class TransferNamespace {
async create(
params: TransferParams
): Promise<PreparedCommand<'ExerciseCommand'>> {
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,
Expand All @@ -85,7 +88,7 @@ export class TransferNamespace {
params.amount,
asset.admin,
asset.id,
asset.registryUrl,
asset.registryUrl.href,
params.inputUtxos,
params.memo,
params.expirationDate,
Expand Down
7 changes: 5 additions & 2 deletions sdk/wallet-sdk/src/wallet/namespace/token/utxos/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading