Skip to content
Draft
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
25 changes: 24 additions & 1 deletion core/wallet-test-utils/src/otc-trade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,18 @@ export class OTCTrade {
PATH_TO_DAR_IN_LOCALNET
)

// Resolve the global synchronizer explicitly: the SDK no longer
// auto-selects one, and DAR upload cannot be autodetected when the
// participant is connected to multiple synchronizers.
const synchronizerId = await this.resolveGlobalSynchronizerId()

//upload dar
const darBytes = await fs.readFile(tradingDarPath)
await this.sdk.ledger.dar.upload(darBytes, TRADING_APP_PACKAGE_ID)
await this.sdk.ledger.dar.upload(
darBytes,
TRADING_APP_PACKAGE_ID,
synchronizerId
)

// Alice creates OTCTradeProposal

Expand Down Expand Up @@ -207,6 +216,20 @@ export class OTCTrade {
}
}

private async resolveGlobalSynchronizerId(): Promise<string> {
if (!this.sdk) throw new Error('SDK not initialized')

const { connectedSynchronizers } =
await this.sdk.ledger.connectedSynchronizers({})
const globalSynchronizer = (connectedSynchronizers ?? []).find(
(s) => s.synchronizerAlias === 'global'
)
if (!globalSynchronizer) {
throw new Error('Global synchronizer not found')
}
return globalSynchronizer.synchronizerId
}

private async acceptProposal(
approver: PartyId,
approverName: string
Expand Down
5 changes: 5 additions & 0 deletions docs/wallet-integration-guide/examples/scripts/01-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
TOKEN_NAMESPACE_CONFIG,
TOKEN_PROVIDER_CONFIG_DEFAULT,
AMULET_NAMESPACE_CONFIG,
getGlobalSynchronizerId,
} from './utils/index.js'

const logger = pino({ name: 'v1-01-ping-localnet', level: 'info' })
Expand All @@ -20,11 +21,14 @@ const sdk = await SDK.create({
amulet: AMULET_NAMESPACE_CONFIG,
})

const globalSynchronizerId = await getGlobalSynchronizerId(sdk)

const senderKeys = sdk.keys.generate()

const sender = await sdk.party.external
.create(senderKeys.publicKey, {
partyHint: 'v1-01-alice',
synchronizerId: globalSynchronizerId,
})
.sign(senderKeys.privateKey)
.execute()
Expand All @@ -42,6 +46,7 @@ const receiverPartyCreation = sdk.party.external.create(
receiverKeys.publicKey,
{
partyHint: 'v1-01-bob',
synchronizerId: globalSynchronizerId,
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
TOKEN_NAMESPACE_CONFIG,
TOKEN_PROVIDER_CONFIG_DEFAULT,
AMULET_NAMESPACE_CONFIG,
getGlobalSynchronizerId,
} from '../utils/index.js'

const logger = pino({ name: 'v1-02-two-step-transfer', level: 'info' })
Expand All @@ -20,11 +21,16 @@ const sdk = await SDK.create({
amulet: AMULET_NAMESPACE_CONFIG,
})

// The wallet SDK no longer auto-selects a synchronizer, so resolve the global
// synchronizer explicitly and pass it to external party creation.
const globalSynchronizerId = await getGlobalSynchronizerId(sdk)

const senderKeys = sdk.keys.generate()

const sender = await sdk.party.external
.create(senderKeys.publicKey, {
partyHint: 'v1-02-alice',
synchronizerId: globalSynchronizerId,
})
.sign(senderKeys.privateKey)
.execute()
Expand All @@ -34,6 +40,7 @@ const receiverKeys = sdk.keys.generate()
const receiver = await sdk.party.external
.create(receiverKeys.publicKey, {
partyHint: 'v1-02-bob',
synchronizerId: globalSynchronizerId,
})
.sign(receiverKeys.privateKey)
.execute()
Expand Down
10 changes: 9 additions & 1 deletion docs/wallet-integration-guide/examples/scripts/03-parties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { localNetStaticConfig, SDK } from '@canton-network/wallet-sdk'
import {
TOKEN_PROVIDER_CONFIG_DEFAULT,
AMULET_NAMESPACE_CONFIG,
getGlobalSynchronizerId,
} from './utils/index.js'

const logger = pino({ name: 'v1-03-parties', level: 'info' })
Expand All @@ -15,12 +16,15 @@ const sdk = await SDK.create({
amulet: AMULET_NAMESPACE_CONFIG,
})

const globalSynchronizerId = await getGlobalSynchronizerId(sdk)

const allocatedParties = await Promise.all(
['v1-03-alice', 'v1-03-bob'].map((partyHint) => {
const partyKeys = sdk.keys.generate()
return sdk.party.external
.create(partyKeys.publicKey, {
partyHint,
synchronizerId: globalSynchronizerId,
})
.sign(partyKeys.privateKey)
.execute()
Expand All @@ -43,7 +47,9 @@ if (!allocatedPartiesIds.isSubsetOf(new Set(listedParties))) {
)
}

const featuredAppRights = await sdk.amulet.featuredApp.grant()
const featuredAppRights = await sdk.amulet.featuredApp.grant({
synchronizerId: globalSynchronizerId,
})

if (!featuredAppRights) {
throw new Error(
Expand All @@ -69,6 +75,7 @@ const charlieKeys = sdk.keys.generate()
const charlie = await sdk.party.external
.create(charlieKeys.publicKey, {
partyHint: 'v1-03-charlie',
synchronizerId: globalSynchronizerId,
confirmingParticipantEndpoints: participantEndpoints,
})
.sign(charlieKeys.privateKey)
Expand Down Expand Up @@ -101,6 +108,7 @@ const observingCharlieKeys = sdk.keys.generate()
const observingCharlie = await sdk.party.external
.create(observingCharlieKeys.publicKey, {
partyHint: 'v1-03-observingCharlie',
synchronizerId: globalSynchronizerId,
observingParticipantEndpoints: participantEndpoints,
})
.sign(observingCharlieKeys.privateKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
TOKEN_NAMESPACE_CONFIG,
TOKEN_PROVIDER_CONFIG_DEFAULT,
AMULET_NAMESPACE_CONFIG,
getGlobalSynchronizerId,
} from './utils/index.js'

const logger = pino({ name: 'v1-token-standard-allocation', level: 'info' })
Expand Down Expand Up @@ -43,9 +44,18 @@ const tradingDarPath = path.join(
PATH_TO_DAR_IN_LOCALNET
)

// The wallet SDK no longer auto-selects a synchronizer, and DAR upload and party
// creation cannot be autodetected when the participant is connected to multiple
// synchronizers, so resolve the global synchronizer explicitly and pass it on.
const globalSynchronizerId = await getGlobalSynchronizerId(sdk)

//upload dar
const darBytes = await fs.readFile(tradingDarPath)
await sdk.ledger.dar.upload(darBytes, TRADING_APP_PACKAGE_ID)
await sdk.ledger.dar.upload(
darBytes,
TRADING_APP_PACKAGE_ID,
globalSynchronizerId
)

//allocate parties
const allocatedParties = await Promise.all(
Expand All @@ -54,6 +64,7 @@ const allocatedParties = await Promise.all(
const party = await sdk.party.external
.create(partyKeys.publicKey, {
partyHint,
synchronizerId: globalSynchronizerId,
})
.sign(partyKeys.privateKey)
.execute()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
TOKEN_NAMESPACE_CONFIG,
TOKEN_PROVIDER_CONFIG_DEFAULT,
AMULET_NAMESPACE_CONFIG,
getGlobalSynchronizerId,
} from './utils/index.js'

const logger = pino({ name: 'v1-05-preapproval', level: 'info' })
Expand All @@ -16,13 +17,16 @@ const sdk = await SDK.create({
amulet: AMULET_NAMESPACE_CONFIG,
})

const globalSynchronizerId = await getGlobalSynchronizerId(sdk)

await sdk.amulet.tapInternal('1000')

const aliceKeys = sdk.keys.generate()

const alice = await sdk.party.external
.create(aliceKeys.publicKey, {
partyHint: 'v1-05-alice',
synchronizerId: globalSynchronizerId,
})
.sign(aliceKeys.privateKey)
.execute()
Expand All @@ -46,6 +50,7 @@ const bobKeys = sdk.keys.generate()
const bob = await sdk.party.external
.create(bobKeys.publicKey, {
partyHint: 'v1-05-bob',
synchronizerId: globalSynchronizerId,
})
.sign(bobKeys.privateKey)
.execute()
Expand Down Expand Up @@ -169,6 +174,7 @@ await sdk.amulet.preapproval.renew({
receiver: bob.partyId,
},
expiresAt: newExpiresAt,
synchronizerId: globalSynchronizerId,
})

const fetchedStatusAfterRenew = await sdk.amulet.preapproval.fetchStatus(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
TOKEN_NAMESPACE_CONFIG,
TOKEN_PROVIDER_CONFIG_DEFAULT,
AMULET_NAMESPACE_CONFIG,
getGlobalSynchronizerId,
} from './utils/index.js'

const logger = pino({ name: 'v1-06-merge-utxos', level: 'info' })
Expand All @@ -15,11 +16,16 @@ const sdk = await SDK.create({
amulet: AMULET_NAMESPACE_CONFIG,
})

// The wallet SDK no longer auto-selects a synchronizer, so resolve the global
// synchronizer explicitly and pass it to external party creation.
const globalSynchronizerId = await getGlobalSynchronizerId(sdk)

const aliceKeys = sdk.keys.generate()

const alice = await sdk.party.external
.create(aliceKeys.publicKey, {
partyHint: 'v1-06-alice',
synchronizerId: globalSynchronizerId,
})
.sign(aliceKeys.privateKey)
.execute()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
TOKEN_NAMESPACE_CONFIG,
TOKEN_PROVIDER_CONFIG_DEFAULT,
AMULET_NAMESPACE_CONFIG,
getGlobalSynchronizerId,
} from './utils/index.js'

const logger = pino({ name: 'v1-06-merge-utxos', level: 'info' })
Expand All @@ -14,11 +15,15 @@ const sdk = await SDK.create({
token: TOKEN_NAMESPACE_CONFIG,
amulet: AMULET_NAMESPACE_CONFIG,
})

const globalSynchronizerId = await getGlobalSynchronizerId(sdk)

const aliceKeys = sdk.keys.generate()

const alice = await sdk.party.external
.create(aliceKeys.publicKey, {
partyHint: 'v1-07-alice',
synchronizerId: globalSynchronizerId,
})
.sign(aliceKeys.privateKey)
.execute()
Expand All @@ -28,6 +33,7 @@ const bobKeys = sdk.keys.generate()
const bob = await sdk.party.external
.create(bobKeys.publicKey, {
partyHint: 'v1-07-bob',
synchronizerId: globalSynchronizerId,
})
.sign(bobKeys.privateKey)
.execute()
Expand Down Expand Up @@ -66,7 +72,9 @@ await sdk.ledger

logger.info(`Tapped holdings for alice`)

const trafficStatusBeforePurchase = await sdk.amulet.traffic.status()
const trafficStatusBeforePurchase = await sdk.amulet.traffic.status({
synchronizerId: globalSynchronizerId,
})

logger.info(
`Traffic status before purchase: ${JSON.stringify(trafficStatusBeforePurchase)}`
Expand All @@ -79,6 +87,7 @@ const [buyTrafficCommand, buyTrafficDisclosedContracts] =
buyer: alice.partyId,
ccAmount,
inputUtxos: [],
synchronizerId: globalSynchronizerId,
})

await sdk.ledger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
TOKEN_NAMESPACE_CONFIG,
TOKEN_PROVIDER_CONFIG_DEFAULT,
AMULET_NAMESPACE_CONFIG,
getGlobalSynchronizerId,
} from './utils/index.js'

const logger = pino({ name: 'v1-08-merge-delegation', level: 'info' })
Expand Down Expand Up @@ -36,10 +37,16 @@ const sdk = await SDK.create({
amulet: AMULET_NAMESPACE_CONFIG,
})

// The wallet SDK no longer auto-selects a synchronizer, and DAR upload cannot be
// autodetected when the participant is connected to multiple synchronizers, so
// resolve the global synchronizer explicitly and pass it to the upload.
const synchronizerId = await getGlobalSynchronizerId(sdk)

const darBytes = await readFile(spliceUtilTokenStandardWalletDarPath)
await sdk.ledger.dar.upload(
darBytes,
SPLICE_UTIL_TOKEN_STANDARD_WALLET_PACKAGE_ID
SPLICE_UTIL_TOKEN_STANDARD_WALLET_PACKAGE_ID,
synchronizerId
)

logger.info(`DAR ${PATH_TO_DAR_IN_LOCALNET} successfully uploaded`)
Expand All @@ -49,6 +56,7 @@ const aliceKeys = sdk.keys.generate()
const alice = await sdk.party.external
.create(aliceKeys.publicKey, {
partyHint: 'v1-08-alice',
synchronizerId,
})
.sign(aliceKeys.privateKey)
.execute()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { localNetStaticConfig, SDK } from '@canton-network/wallet-sdk'
import { pino } from 'pino'
import { TOKEN_PROVIDER_CONFIG_DEFAULT } from './utils/index.js'
import {
TOKEN_PROVIDER_CONFIG_DEFAULT,
getGlobalSynchronizerId,
} from './utils/index.js'
const logger = pino({ name: 'v1-multi-user-setup', level: 'info' })

logger.info('Operator sets up users and primary parties')
Expand All @@ -10,16 +13,23 @@ const operatorSdk = await SDK.create({
ledgerClientUrl: localNetStaticConfig.LOCALNET_APP_USER_LEDGER_URL,
})

// The wallet SDK no longer auto-selects a synchronizer, so resolve the global
// synchronizer explicitly and pass it to external party creation.
const globalSynchronizerId = await getGlobalSynchronizerId(operatorSdk)

const aliceInternal = await operatorSdk.party.internal.allocate({
partyHint: 'v1-09-alice',
synchronizerId: globalSynchronizerId,
})

const bobInternal = await operatorSdk.party.internal.allocate({
partyHint: 'v1-09-bob',
synchronizerId: globalSynchronizerId,
})

const masterPartyInternal = await operatorSdk.party.internal.allocate({
partyHint: 'v1-09-master',
synchronizerId: globalSynchronizerId,
})

logger.info('Created the internal parties')
Expand Down Expand Up @@ -90,6 +100,7 @@ const aliceKeyPair = aliceSdk.keys.generate()
const aliceExternal = await aliceSdk.party.external
.create(aliceKeyPair.publicKey, {
partyHint: 'v1-09-alice',
synchronizerId: globalSynchronizerId,
})
.sign(aliceKeyPair.privateKey)
.execute()
Expand All @@ -114,6 +125,7 @@ const bobKeyPair = bobSdk.keys.generate()
const bobExternal = await bobSdk.party.external
.create(bobKeyPair.publicKey, {
partyHint: 'v1-09-bob',
synchronizerId: globalSynchronizerId,
})
.sign(bobKeyPair.privateKey)
.execute()
Expand Down
Loading