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
55 changes: 55 additions & 0 deletions core/amulet-ops/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"name": "@canton-network/core-amulet-ops",
"version": "0.0.1",
"type": "module",
"description": "SDK-level Amulet operations (tap/mint, allocate) built on the wallet SDK",
"license": "Apache-2.0",
"packageManager": "yarn@4.9.4",
"main": "dist/index.cjs",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"require": "./dist/index.cjs",
"default": "./dist/index.js"
}
},
"scripts": {
"build": "tsup --onSuccess \"tsc\"",
"dev": "tsup --watch --onSuccess \"tsc\"",
"clean": "tsc -b --clean; rm -rf dist",
"flatpack": "yarn pack --out \"$FLATPACK_OUTDIR\"",
"test": "vitest run --project node --passWithNoTests",
"test:coverage": "vitest run --project node --coverage --passWithNoTests"
},
"dependencies": {
"@canton-network/core-amulet-service": "workspace:^"
},
"peerDependencies": {
"@canton-network/core-signing-lib": "workspace:^",
"@canton-network/wallet-sdk": "workspace:^",
"pino": "^10.3.1"
},
"devDependencies": {
"@canton-network/core-signing-lib": "workspace:^",
"@canton-network/wallet-sdk": "workspace:^",
"@vitest/coverage-v8": "^4.1.2",
"pino": "^10.3.1",
"tsup": "^8.5.1",
"typescript": "^5.9.3",
"vitest": "^4.1.2"
},
"files": [
"dist/**"
],
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "git+https://github.com/canton-network/wallet.git",
"directory": "core/amulet-ops"
}
}
95 changes: 95 additions & 0 deletions core/amulet-ops/src/allocation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import type { Logger } from 'pino'
import type { SDKInterface } from '@canton-network/wallet-sdk'
import { AMULET_TEMPLATE_ID } from '@canton-network/core-amulet-service'
import type { SigningParty } from './tap.js'

const AMULET_INSTRUMENT = {
id: 'Amulet',
displayName: 'Amulet',
symbol: 'CC',
} as const

export interface AllocateAmuletParams {
sdk: SDKInterface<'token'>
sender: SigningParty
adminPartyId: string
registryUrl: URL
globalSynchronizerId: string
logger?: Logger
}

/**
* Allocates the sender's Amulet holding against its leg of a pending token
* allocation request.
*
* Looks up the sender's transfer leg in the pending allocation request, reads its
* Amulet holding, builds the allocation instruction for the Amulet instrument, and
* submits it signed by the sender.
*
* @returns The transfer-leg id that was allocated.
*/
export async function allocateAmulet(
params: AllocateAmuletParams
): Promise<string> {
const {
sdk,
sender,
adminPartyId,
registryUrl,
globalSynchronizerId,
logger,
} = params
const token = sdk.token

const pendingRequests = await token.allocation.request.pending(
sender.partyId
)
const requestView = pendingRequests[0].interfaceViewValue!
const legId = Object.keys(requestView.transferLegs).find(
(key) => requestView.transferLegs[key].sender === sender.partyId
)!
if (!legId) throw new Error('No transfer leg found for sender')

const amuletHoldings = await sdk.ledger.acsReader.readJsContracts({
templateIds: [AMULET_TEMPLATE_ID],
parties: [sender.partyId],
filterByParty: true,
})
const amuletHoldingCid = amuletHoldings[0]?.contractId
if (!amuletHoldingCid)
throw new Error('Amulet holding not found for sender')

const [command, disclosedContracts] =
await token.allocation.instruction.create({
allocationSpecification: {
settlement: requestView.settlement,
transferLegId: legId,
transferLeg: requestView.transferLegs[legId],
},
asset: {
id: AMULET_INSTRUMENT.id,
displayName: AMULET_INSTRUMENT.displayName,
symbol: AMULET_INSTRUMENT.symbol,
registryUrl,
admin: adminPartyId,
},
inputUtxos: [amuletHoldingCid],
requestedAt: new Date().toISOString(),
})

await sdk.ledger
.prepare({
partyId: sender.partyId,
commands: [command],
disclosedContracts,
synchronizerId: globalSynchronizerId,
})
.sign(sender.privateKey)
.execute({ partyId: sender.partyId })

logger?.info('Amulet allocated for sender leg (global synchronizer)')
return legId
}
8 changes: 8 additions & 0 deletions core/amulet-ops/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

export { mintAmulet } from './tap.js'
export type { MintAmuletParams, SigningParty } from './tap.js'

export { allocateAmulet } from './allocation.js'
export type { AllocateAmuletParams } from './allocation.js'
46 changes: 46 additions & 0 deletions core/amulet-ops/src/tap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import type { Logger } from 'pino'
import type { PrivateKey } from '@canton-network/core-signing-lib'
import type { SDKInterface } from '@canton-network/wallet-sdk'

export interface SigningParty {
partyId: string
privateKey: PrivateKey
}

export interface MintAmuletParams {
sdk: SDKInterface<'amulet'>
receiver: SigningParty
amount: string
synchronizerId: string
logger?: Logger
}

/**
* Taps (mints) `amount` Amulet into `receiver`'s wallet on `synchronizerId`.
*
* Builds the tap command via the SDK's `amulet` namespace, then prepares, signs,
* and executes it as a single-party submission by the receiver.
*/
export async function mintAmulet(params: MintAmuletParams): Promise<void> {
const { sdk, receiver, amount, synchronizerId, logger } = params

const [tapCommand, disclosedContracts] = await sdk.amulet.tap(
receiver.partyId,
amount
)

await sdk.ledger
.prepare({
partyId: receiver.partyId,
commands: tapCommand,
disclosedContracts,
synchronizerId,
})
.sign(receiver.privateKey)
.execute({ partyId: receiver.partyId })

logger?.info(`Amulet minted (${amount}) for receiver on synchronizer`)
}
8 changes: 8 additions & 0 deletions core/amulet-ops/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.web.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist"
},
"include": ["src"]
}
11 changes: 11 additions & 0 deletions core/amulet-ops/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import { defineConfig } from 'tsup'
import { base } from '../../tsup.base'

export default defineConfig({
...base,
entry: ['src/index.ts'],
platform: 'node',
})
29 changes: 29 additions & 0 deletions core/amulet-ops/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

import { defineConfig, defineProject } from 'vitest/config'

export default defineConfig({
test: {
coverage: {
include: ['src/**/*.ts'],
provider: 'v8',
reporter: ['text', 'html', 'lcov'],
thresholds: {
lines: 0,
functions: 0,
branches: 0,
statements: 0,
},
},
projects: [
defineProject({
test: {
name: 'node',
environment: 'node',
include: ['src/**/*.test.ts'],
},
}),
],
},
})
8 changes: 8 additions & 0 deletions core/test-token/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,20 @@
"@daml/types": "^3.5.0",
"@mojotech/json-type-validation": "^3.1.0"
},
"peerDependencies": {
"@canton-network/core-signing-lib": "workspace:^",
"@canton-network/wallet-sdk": "workspace:^",
"pino": "^10.3.1"
},
"devDependencies": {
"@canton-network/core-signing-lib": "workspace:^",
"@canton-network/wallet-sdk": "workspace:^",
"@rollup/plugin-alias": "^5.0.0",
"@rollup/plugin-commonjs": "^29.0.0",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^16.0.3",
"@rollup/plugin-typescript": "^12.3.0",
"pino": "^10.3.1",
"rollup": "^4.59.0",
"rollup-plugin-dts": "^6.3.0",
"tslib": "^2.8.1",
Expand Down
Loading