Skip to content
Closed
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
27 changes: 26 additions & 1 deletion core/types/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
// SPDX-License-Identifier: Apache-2.0

import { describe, expect, it } from 'vitest'
import { WalletEvent, isSpliceMessage, isSpliceMessageEvent } from './index'
import {
WalletEvent,
isSpliceMessage,
isSpliceMessageEvent,
SynchronizerId,
} from './index'

const SYNCHRONIZER_ID_EXAMPLE = 'sync::122012312312312312123'

describe('isSpliceMessage', () => {
it('accepts each splice message variant', () => {
Expand Down Expand Up @@ -54,6 +61,24 @@ describe('isSpliceMessage', () => {
})
})

describe('SynchronizerId', () => {
it('accepts a well-formed synchronizer id', () => {
expect(SynchronizerId.safeParse(SYNCHRONIZER_ID_EXAMPLE).success).toBe(
true
)
})

it('rejects values missing the "::" separator', () => {
expect(SynchronizerId.safeParse('not-a-synchronizer-id').success).toBe(
false
)
})

it('rejects values shorter than 10 characters', () => {
expect(SynchronizerId.safeParse('a::b').success).toBe(false)
})
})

describe('isSpliceMessageEvent', () => {
it('accepts objects with valid splice message data', () => {
const message = {
Expand Down
4 changes: 4 additions & 0 deletions core/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export const PartyId = z

export type PartyId = z.infer<typeof PartyId>

export const SynchronizerId = z.string().includes('::').min(10)

export type SynchronizerId = z.infer<typeof SynchronizerId>

export const HttpUrl = z
.url({
message: 'Must be a valid HTTP or HTTPS URL',
Expand Down
3 changes: 2 additions & 1 deletion sdk/wallet-sdk/src/wallet/init/types/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { AbstractLedgerProvider } from '@canton-network/core-provider-ledger'
import { SynchronizerId } from '@canton-network/core-types'
import { SDKLogger } from '../../logger/logger.js'
import { SDKErrorHandler } from '../../error/handler.js'

Expand All @@ -10,7 +11,7 @@ export type SDKContext = {
userId: string
logger: SDKLogger
error: SDKErrorHandler
defaultSynchronizerId: string
defaultSynchronizerId: SynchronizerId
}

export type OfflineSDKContext = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
OnboardingTransactions,
} from './types.js'

import { PartyId } from '@canton-network/core-types'
import { PartyId, SynchronizerId } from '@canton-network/core-types'
import {
AbstractLedgerProvider,
LedgerProvider,
Expand Down Expand Up @@ -315,7 +315,7 @@ export class SignedPartyCreationService {

private async allocate(
ledgerProvider: AbstractLedgerProvider,
synchronizerId: string,
synchronizerId: SynchronizerId,
onboardingTransactions: OnboardingTransactions,
multiHashSignatures: MultiHashSignatures
): Promise<Ops.PostV2PartiesExternalAllocate['ledgerApi']['result']> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
// SPDX-License-Identifier: Apache-2.0

import { Ops } from '@canton-network/core-provider-ledger'
import { SynchronizerId } from '@canton-network/core-types'
import { TokenProviderConfig } from '@canton-network/core-wallet-auth'

export type CreatePartyOptions = Partial<{
isAdmin: boolean
partyHint: string
confirmingThreshold: number
synchronizerId: string
synchronizerId: SynchronizerId
confirmingParticipantEndpoints: ParticipantEndpointConfig[]
observingParticipantEndpoints: ParticipantEndpointConfig[]
localParticipantObservationOnly: boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
ExerciseCommand,
} from '@canton-network/core-token-standard-service'
import { Holding, PrettyContract } from '@canton-network/core-tx-parser'
import { PartyId } from '@canton-network/core-types'
import { PartyId, SynchronizerId } from '@canton-network/core-types'
import { LedgerNamespace } from '../../ledger/index.js'
import { UtxoNamespace } from './index.js'
import { resolveProviderParty } from '../utils.js'
Expand All @@ -23,7 +23,7 @@ export class MergeDelegationNamespace {
this.ledger = new LedgerNamespace(ctx.commonCtx)
}

async setup(synchronizerId: string = '', validatorParty?: PartyId) {
async setup(synchronizerId: SynchronizerId = '', validatorParty?: PartyId) {
const providerParty = resolveProviderParty(
this.ctx,
'setup',
Expand Down