-
Notifications
You must be signed in to change notification settings - Fork 50
feat(example-test-token-v1-registry): create backend registry example #2182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mateuszpiatkowski-da
wants to merge
42
commits into
main
Choose a base branch
from
mateuszpiatkowski-da/ref-token-backend-registry-v1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
abc4829
refactor(core-token-standard): update type export
mateuszpiatkowski-da 8455fa6
fix(core-token-standard-service): revert code
mateuszpiatkowski-da 36825ea
refactor(wallet-sdk,core-ledger-client-types): move wrappedcommand type
mateuszpiatkowski-da 71ffc8e
feat(core-test-token): update test token core export
mateuszpiatkowski-da fc46701
chore: docs minor corrections (#2172)
mjuchli-da e6e0f81
feat: add generate types script (#2171)
mateuszpiatkowski-da 0acd2f6
fix(core-token-standard-service): revert code
mateuszpiatkowski-da b91d3a2
chore: splice provide readme (#2174)
mjuchli-da f51f3ae
feat: show an offers count badge in the sidebar (#2162)
fayi-da 1c5198c
chore: provider diagram (#2175)
mjuchli-da ed79d51
chore(deps): bump axios from 1.16.0 to 1.18.1 (#2178)
dependabot[bot] 3ac3556
chore(deps): bump body-parser from 1.20.4 to 1.20.6 (#2180)
dependabot[bot] 87b5ae4
chore(deps): bump tar from 7.5.11 to 7.5.20 (#2181)
dependabot[bot] e953107
chore: readme (#2179)
mjuchli-da abe5325
chore: refactor portfolio registry discovery and reachability (#2177)
fayi-da 088f8a8
feat(example-test-token-v1-registry): create backend registry example
mateuszpiatkowski-da 1ed77b2
fix(example-test-token-v1-registry): adjust code after rebase
mateuszpiatkowski-da e6377bf
chore(deps): migrate monorepo library builds from tsup to tsdown (#2173)
singhyash05 7006d92
fix: add pagination to list tx (#2166)
rukmini-basu-da 83da103
feat: update core-test-token, add type export refactor (#2170)
mateuszpiatkowski-da 7cc19e9
feat(example-test-token-v1-registry): adjust after merge
mateuszpiatkowski-da 33b5ff8
chore: reinstall yarn deps
mateuszpiatkowski-da 2fa8c16
Merge remote-tracking branch 'origin/main' into mateuszpiatkowski-da/…
mateuszpiatkowski-da 974cb7d
fix(example-portfolio): fix build
mateuszpiatkowski-da 8809a6b
fix(example-test-token-v1-registry): fix path
mateuszpiatkowski-da 5973b19
fix(core-test-token): fix circular dependency
mateuszpiatkowski-da abbc086
test(example-test-token-v1-registry): add test, fix coverage
mateuszpiatkowski-da 42c4596
docs(example-test-token-v1-registry): add openapi-ts files
mateuszpiatkowski-da f60e582
refactor(example-test-token-v1-registry): removed unused code
mateuszpiatkowski-da daea919
refactor(example-test-token-v1-registry): change package commands, es…
mateuszpiatkowski-da bb61773
refactor(example-test-token-v1-registry): change backend port
mateuszpiatkowski-da b6f337e
docs(example-test-token-v1-registry): update docs
mateuszpiatkowski-da 67fcfbf
docs(example-test-token-v1-registry): add inline comments
mateuszpiatkowski-da 9950f44
docs(example-test-token-v1-registry): add explanatory comments
mateuszpiatkowski-da 2000aca
refactor(example-test-token-v1-registry): split boolean
mateuszpiatkowski-da 7e7b421
refactor(example-test-token-v1-registry): rename admin to operator
mateuszpiatkowski-da ae67839
feat(core-token-standard): enable using off-ledger interfaces
mateuszpiatkowski-da 26a37be
feat(example-test-token-v1-registry): switch to core-token-standard i…
mateuszpiatkowski-da d9f7a53
docs(example-test-token-v1-registry): add mermaid diagram
mateuszpiatkowski-da 39f752e
test(example-test-token-v1-registry): update tests
mateuszpiatkowski-da 6cc94da
Merge branch 'main' into mateuszpiatkowski-da/ref-token-backend-regis…
mateuszpiatkowski-da e4c0c32
fix(core-wallet-test-utils): fix build
mateuszpiatkowski-da File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,5 @@ | ||
| // Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { Splice } from '@daml.js/test-token-v1' | ||
|
|
||
| export { packageId } from '@daml.js/test-token-v1' | ||
| export const TestTokenV1 = Splice.Testing.Tokens.TestTokenV1 | ||
| export * from './token' | ||
| export * from './commands' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| // Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { Splice } from '@daml.js/test-token-v1' | ||
|
|
||
| export { packageId } from '@daml.js/test-token-v1' | ||
| export const TestTokenV1 = Splice.Testing.Tokens.TestTokenV1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| // Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| export * as AllocationInstructionV1 from './splice-api-token-allocation-instruction-v1/allocation-instruction-v1' | ||
| export * as AllocationV1 from './splice-api-token-allocation-v1/allocation-v1' | ||
| export * as MetadataV1 from './splice-api-token-metadata-v1/token-metadata-v1' | ||
| export * as TransferInstructionV1 from './splice-api-token-transfer-instruction-v1/transfer-instruction-v1' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,188 @@ | ||
| # @canton-network/example-test-token-v1-registry | ||
|
|
||
| Example backend registry implementation for CIP-0056 token flows on Canton. | ||
|
|
||
| ## Overall Description | ||
|
|
||
| This project is a reference implementation of a token registry backend for the Test Token V1 standard. It exposes registry API endpoints for: | ||
|
|
||
| - token metadata | ||
| - transfer instructions | ||
| - allocations | ||
| - allocation instructions | ||
|
|
||
| ### Purpose | ||
|
|
||
| - provides a reusable second CIP-0056 test token backend (beyond Amulet) so application tests do not become Amulet-specific | ||
| - reduces duplication across teams by offering a shared, easy-to-deploy testing token instead of requiring each team to build a token from scratch | ||
| - modernizes and harden the earlier prototype by aligning with current Wallet SDK usage and adding verification via automated tests | ||
| - provides practical coverage of registry-facing CIP-0056 workflows to complement on-ledger-only token examples | ||
|
|
||
| ### App Logic Flow | ||
|
|
||
| ```mermaid | ||
| flowchart LR | ||
| subgraph MAIN[Main request path] | ||
| direction LR | ||
| REQ[/HTTP Request/] --> APP[Registry App] --> ROUTER[Router] --> HANDLER[API handlers] --> RES[/HTTP Response/] | ||
| end | ||
|
|
||
| subgraph INIT[Startup and initialization] | ||
| direction TB | ||
| APP --> ADMIN[Admin initialization] | ||
| APP --> VET[DAR vetting in dev mode] | ||
| end | ||
|
|
||
| subgraph DEPS[Package dependencies] | ||
| direction TB | ||
| WSDK{{"@canton-network/wallet-sdk"}} | ||
| CORETEST{{"@canton-network/core-test-token"}} | ||
| CORESTD{{"@canton-network/core-token-standard"}} | ||
| end | ||
|
|
||
| WSDK --> ADMIN | ||
| WSDK --> VET | ||
| WSDK --> HANDLER | ||
| CORETEST --> HANDLER | ||
| CORESTD --> HANDLER | ||
| ``` | ||
|
|
||
| ## Getting Started | ||
|
|
||
| ### Prerequisites | ||
|
|
||
| - Node.js 20+ | ||
| - Yarn 4.x | ||
| - dependencies installed at repository root | ||
| - local Canton/localnet setup if you want full end-to-end behavior | ||
|
|
||
| ### Installation | ||
|
|
||
| From repository root: | ||
|
|
||
| ```bash | ||
| yarn install | ||
| ``` | ||
|
|
||
| Build only this example: | ||
|
|
||
| ```bash | ||
| yarn workspace @canton-network/example-test-token-v1-registry build | ||
| ``` | ||
|
|
||
| Run in development mode: | ||
|
|
||
| ```bash | ||
| yarn workspace @canton-network/example-test-token-v1-registry dev | ||
| ``` | ||
|
|
||
| The API listens on `http://localhost:5634`. | ||
|
|
||
| ## Project Structure | ||
|
|
||
| ### Local Structure Overview | ||
|
|
||
| ```text | ||
| examples/test-token-v1-registry/ | ||
| src/ | ||
| index.ts # app startup, admin init, dev vetting hook | ||
| router.ts # route prefix to API handler mapping | ||
| common/ | ||
| sdk.ts # Wallet SDK bootstrap/auth | ||
| admin.ts # admin party initialization | ||
| vetDaml.ts # dev-only DAR vetting helper | ||
| getOpenApiPath.ts # OpenAPI source path resolution | ||
| api/ | ||
| metadata/ # metadata endpoints + tests | ||
| transfer-instruction/ # transfer-instruction endpoints + tests | ||
| allocation/ # allocation endpoints + tests | ||
| allocation-instruction/ # allocation-instruction endpoints + tests | ||
| common.ts # shared API context typing helpers | ||
| openapi-ts/ # generated TypeScript types from OpenAPI | ||
| scripts/ | ||
| generateTypes.ts # regenerates openapi-ts bindings | ||
| __test__/ | ||
| mocks.ts # test mocks | ||
| vitest.config.ts # node+browser test projects and coverage | ||
| tsup.config.ts # build configuration | ||
| tsconfig.json | ||
| ``` | ||
|
|
||
| ## Testing | ||
|
|
||
| Run tests: | ||
|
|
||
| ```bash | ||
| yarn workspace @canton-network/example-test-token-v1-registry test | ||
| ``` | ||
|
|
||
| Run tests with coverage: | ||
|
|
||
| ```bash | ||
| yarn workspace @canton-network/example-test-token-v1-registry test:coverage | ||
| ``` | ||
|
|
||
| Notes: | ||
|
|
||
| - tests are discovered under `src/**/*.test.ts` | ||
| - both node and browser projects are executed | ||
| - coverage thresholds are defined in `vitest.config.ts` | ||
|
|
||
| ## Development & Contribution Guide | ||
|
|
||
| ## @customize Flag | ||
|
|
||
| This example includes `@customize` comments in selected files. | ||
|
|
||
| What it is for: | ||
|
|
||
| - marks places that are intentionally project-specific | ||
| - highlights decisions made for this reference implementation that you will likely want to change in your own token backend | ||
| - acts as a migration checklist when copying this project into a new repository or package | ||
|
|
||
| When to look it up: | ||
|
|
||
| - right after copying/scaffolding this example for your own token | ||
| - before first production-like deployment | ||
| - when replacing test/demo behavior with your real business logic and infrastructure | ||
|
|
||
| How to use it: | ||
|
|
||
| 1. Search the project for `@customize`. | ||
| 1. Review each marked location and decide whether to keep, replace, or remove that logic. | ||
| 1. Prioritize security, auth, persistence, and startup/init code paths first. | ||
|
|
||
| Development loop: | ||
|
|
||
| 1. Modify API handlers and domain logic in `src/api/**`. | ||
| 2. If API specs change, regenerate types: | ||
|
|
||
| ```bash | ||
| yarn workspace @canton-network/example-test-token-v1-registry generate:types | ||
| ``` | ||
|
|
||
| 3. Run tests and coverage. | ||
| 4. Build before opening a PR. | ||
|
|
||
| General contribution guidelines for the monorepo: [Contributing Guide](https://github.com/canton-network/wallet/blob/main/docs/CONTRIBUTING.md) | ||
|
|
||
| ## 6. License | ||
|
|
||
| Apache-2.0 | ||
|
|
||
| ## 7. Additional Resources | ||
|
|
||
| - [Wallet Repository](https://github.com/canton-network/wallet) | ||
| - [dApp Building Documentation](https://github.com/canton-network/wallet/tree/main/docs/dapp-building) | ||
| - [Wallet Integration Guide](https://github.com/canton-network/wallet/tree/main/docs/wallet-integration-guide) | ||
| - [CIP Repository (including CIP-0056 context)](https://github.com/canton-foundation/cips) | ||
|
|
||
| ## 8. Bug Reporting | ||
|
|
||
| If you find a bug: | ||
|
|
||
| 1. Open an issue at: [canton-network/wallet issues](https://github.com/canton-network/wallet/issues) | ||
| 1. Include reproduction steps, expected behavior, and actual behavior. | ||
| 1. Attach logs and relevant request/response payloads when possible. | ||
|
|
||
| If issue templates are available in the repository, prefer using the most specific template. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| { | ||
| "name": "@canton-network/example-test-token-v1-registry", | ||
| "version": "1.0.0", | ||
| "type": "module", | ||
| "description": "Example registry backend app for CIP-0056 token.", | ||
| "license": "Apache-2.0", | ||
| "author": "Mateusz Piątkowski <mateusz.piatkowski@digitalasset.com>", | ||
| "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": "tsdown --onSuccess \"tsc\"", | ||
| "dev": "NODE_ENV=development tsx --watch src/index.ts", | ||
| "clean": "tsc -b --clean; rm -rf dist", | ||
| "flatpack": "yarn pack --out \"$FLATPACK_OUTDIR\"", | ||
| "test": "vitest run --project node --project browser", | ||
| "test:coverage": "vitest run --project node --project browser --coverage" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/koa": "^3", | ||
| "@types/koa-bodyparser": "^4", | ||
| "@types/lodash": "^4.17.24", | ||
| "@types/node": "^25.9.3", | ||
| "@vitest/browser-playwright": "^4.1.8", | ||
| "@vitest/coverage-v8": "^4.1.8", | ||
| "openapicmd": "^2.9.2", | ||
| "playwright": "^1.60.0", | ||
| "typescript": "^5.9.3", | ||
| "vitest": "^4.1.8" | ||
| }, | ||
| "dependencies": { | ||
| "@canton-network/core-test-token": "workspace:^", | ||
| "@canton-network/core-token-standard": "workspace:^", | ||
| "@canton-network/core-types": "workspace:^", | ||
| "@canton-network/wallet-sdk": "workspace:^", | ||
| "koa": "^3.2.1", | ||
| "koa-bodyparser": "^4.4.1", | ||
| "openapi-backend": "^5.18.0", | ||
| "tsdown": "^0.22.12", | ||
| "tsx": "^4.23.0", | ||
| "zod": "^4.4.3" | ||
| }, | ||
| "files": [ | ||
| "dist/**" | ||
| ], | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/canton-network/wallet.git", | ||
| "directory": "examples/test-token-v1-registry" | ||
| }, | ||
| "homepage": "https://github.com/canton-network/wallet/tree/main/examples/test-token-v1-registry#readme", | ||
| "bugs": { | ||
| "url": "https://github.com/canton-network/wallet/issues" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { vi } from 'vitest' | ||
|
|
||
| const execute = vi.fn().mockResolvedValue({ | ||
| completionOffset: 100, | ||
| }) | ||
| const sign = vi.fn().mockReturnValue({ execute }) | ||
| const prepare = vi.fn().mockReturnValue({ sign }) | ||
| const create = vi.fn().mockReturnValue({ sign }) | ||
|
|
||
| const sdk = { | ||
| ledger: { | ||
| acsReader: { | ||
| readJsContracts: vi.fn(), | ||
| }, | ||
| prepare, | ||
| }, | ||
| keys: { | ||
| generate: vi.fn().mockReturnValue({ | ||
| publicKey: 'test-public-key', | ||
| privateKey: 'test-private-key', | ||
| }), | ||
| }, | ||
| testToken: { | ||
| create: { | ||
| rules: vi.fn(), | ||
| }, | ||
| }, | ||
| party: { | ||
| external: { | ||
| create, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| export const mock = { | ||
| sdk, | ||
| prepare, | ||
| sign, | ||
| execute, | ||
| create, | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.