@temple-digital-group/temple-canton-js 1.0.35 → 1.0.37-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/README.md +339 -234
  2. package/dist/api/index.d.ts +76 -0
  3. package/dist/api/index.js +271 -0
  4. package/dist/api/tokenStore.d.ts +34 -0
  5. package/dist/api/tokenStore.js +65 -0
  6. package/dist/api/types.d.ts +111 -0
  7. package/dist/api/types.js +2 -0
  8. package/index.js +12 -9
  9. package/package.json +47 -40
  10. package/src/api/config.d.ts +17 -0
  11. package/src/api/index.ts +348 -0
  12. package/src/api/tokenStore.ts +74 -0
  13. package/src/api/types.ts +141 -0
  14. package/src/auth0/index.js +50 -50
  15. package/src/canton/index.js +3715 -4092
  16. package/src/canton/instrumentCatalog.js +171 -148
  17. package/src/canton/request_schemas/cancel_orders_amulet.json +77 -77
  18. package/src/canton/request_schemas/cancel_orders_utility.json +68 -68
  19. package/src/canton/request_schemas/create_order_proposal_amulet.json +94 -94
  20. package/src/canton/request_schemas/create_order_proposal_utility.json +121 -121
  21. package/src/canton/request_schemas/create_utility_credential.json +31 -31
  22. package/src/canton/request_schemas/execute_transfer_factory.json +43 -43
  23. package/src/canton/request_schemas/get_allocation_factory.json +21 -21
  24. package/src/canton/request_schemas/get_amulet_holdings.json +21 -21
  25. package/src/canton/request_schemas/get_instrument_configurations.json +21 -21
  26. package/src/canton/request_schemas/get_locked_amulet_holdings.json +21 -21
  27. package/src/canton/request_schemas/get_order_proposals.json +21 -21
  28. package/src/canton/request_schemas/get_orders.json +21 -21
  29. package/src/canton/request_schemas/get_sender_credentials.json +22 -22
  30. package/src/canton/request_schemas/get_transfer_factory.json +28 -28
  31. package/src/canton/request_schemas/get_utility_holdings.json +21 -21
  32. package/src/canton/request_schemas/unlock_amulet.json +38 -38
  33. package/src/config/index.d.ts +54 -0
  34. package/src/config/index.js +151 -145
package/README.md CHANGED
@@ -1,234 +1,339 @@
1
- # Temple Canton JS
2
-
3
- JavaScript SDK for interacting with the Temple Canton blockchain exchange. Supports Amulet, USDCx, and CBTC tokens on the Canton network.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- npm install @temple-digital-group/temple-canton-js
9
- ```
10
-
11
- ## Configuration
12
-
13
- Call `initializeConfig()` before using any SDK functions. This is required in all environments.
14
-
15
- ### Custom Validator
16
-
17
- For apps connecting to your own validator (browser or server-side):
18
-
19
- ```javascript
20
- import { initializeConfig } from '@temple-digital-group/temple-canton-js';
21
-
22
- initializeConfig({
23
- NETWORK: 'mainnet',
24
- VALIDATOR_API_URL: 'https://your-validator-url',
25
- VALIDATOR_SCAN_API_URL: 'https://your-scan-api-url',
26
- VALIDATOR_USER_PARTY_ID: 'your-user-party-id',
27
- JWT_TOKEN: 'your-jwt-token', // Browser: pass a pre-authenticated JWT
28
- // — OR for server-side Auth0 —
29
- // AUTH0_TOKEN_URL: 'https://your-auth0-domain/oauth/token',
30
- // AUTH0_USER_ID: 'your-auth0-user-id',
31
- // AUTH0_CLIENT_ID: 'your-client-id',
32
- // AUTH0_CLIENT_SECRET: 'your-client-secret',
33
- // AUTH0_AUDIENCE: 'your-audience',
34
- });
35
- ```
36
-
37
- | Key | Required | Description |
38
- |-----|----------|-------------|
39
- | `NETWORK` | Yes | `mainnet`, `testnet`, or `localhost` |
40
- | `VALIDATOR_API_URL` | Yes | Base URL of the Canton validator ledger API |
41
- | `VALIDATOR_SCAN_API_URL` | Yes | Base URL of the Canton Scan API |
42
- | `VALIDATOR_USER_PARTY_ID` | Yes | The user's party ID on the network |
43
- | `JWT_TOKEN` | Yes* | Pre-authenticated JWT token for ledger API calls |
44
- | `AUTH0_TOKEN_URL` | Yes* | Auth0 OAuth token endpoint |
45
- | `AUTH0_CLIENT_ID` | Yes* | Auth0 application client ID |
46
- | `AUTH0_CLIENT_SECRET` | Yes* | Auth0 application client secret |
47
- | `AUTH0_AUDIENCE` | Yes* | Auth0 API audience identifier |
48
- | `AUTH0_USER_ID` | Yes* | Auth0 user ID for the service account |
49
-
50
- \* Provide either `JWT_TOKEN` (browser) or the `AUTH0_*` fields (server-side). The SDK fetches and caches JWT tokens automatically when Auth0 credentials are provided.
51
-
52
- To update the JWT token later without re-initializing:
53
-
54
- ```javascript
55
- import { setJWTToken } from '@temple-digital-group/temple-canton-js';
56
-
57
- setJWTToken(newToken);
58
- ```
59
-
60
- ### Wallet Provider
61
-
62
- For apps using a wallet provider (e.g., Loop Wallet). Use `returnCommand = true` to get the command data back.
63
-
64
- ```javascript
65
- import { initializeConfig, createOrderProposal } from '@temple-digital-group/temple-canton-js';
66
-
67
- initializeConfig({
68
- NETWORK: 'mainnet'
69
- });
70
-
71
- const command = await createOrderProposal(orderArgs, true, walletProvider);
72
- ```
73
-
74
- | Key | Required | Description |
75
- |-----|----------|-------------|
76
- | `NETWORK` | Yes | `mainnet`, `testnet`, or `localhost` |
77
-
78
- > **Legacy:** Environment variables are still supported for backwards compatibility, but `initializeConfig()` is the recommended approach.
79
-
80
-
81
- ## Supported Instruments
82
-
83
- | Asset | Type | Networks |
84
- |---------|---------|-------------------|
85
- | Amulet | Amulet | testnet, mainnet |
86
- | USDCx | Utility | testnet, mainnet |
87
- | CBTC | Utility | testnet, mainnet |
88
-
89
- ## Supported Trading Pairs
90
-
91
- - `Amulet/USDCx`
92
- - `CBTC/USDCx`
93
-
94
- ## Usage
95
-
96
- ### Get User Balances
97
-
98
- ```javascript
99
- import { getUserBalances } from '@temple-digital-group/temple-canton-js';
100
-
101
- const balances = await getUserBalances(partyId);
102
- ```
103
-
104
- ### Create an Order
105
-
106
- ```javascript
107
- import { createOrderProposal } from '@temple-digital-group/temple-canton-js';
108
-
109
- const result = await createOrderProposal({
110
- party: partyId,
111
- symbol: 'Amulet/USDCx',
112
- side: 'Buy',
113
- quantity: '100',
114
- pricePerUnit: '1.5',
115
- expiration: new Date(Date.now() + 3600000).toISOString(),
116
- userId: auth0UserId,
117
- orderType: 'limit'
118
- });
119
- ```
120
-
121
- ### Get Orders and Proposals
122
-
123
- ```javascript
124
- import { getOrdersForParty, getOrderProposalsForParty } from '@temple-digital-group/temple-canton-js';
125
-
126
- const orders = await getOrdersForParty(partyId);
127
- const proposals = await getOrderProposalsForParty(partyId);
128
- ```
129
-
130
- ### Merge Holdings
131
-
132
- ```javascript
133
- import { mergeAmuletHoldingsForParty, mergeUtilityHoldingsForParty, getAmuletDisclosures, getUtxoCount } from '@temple-digital-group/temple-canton-js';
134
-
135
- // Custom Validator (server-side)
136
- await mergeAmuletHoldingsForParty(partyId);
137
- await mergeUtilityHoldingsForParty(partyId, 'USDCx');
138
-
139
- // Wallet Provider merge up to 5 smallest USDCx UTXOs
140
- const command = await mergeUtilityHoldingsForParty(partyId, 'USDCx', true, walletProvider, 5);
141
- const result = await walletProvider.signAndSubmit(command);
142
-
143
- // Wallet Provider — merge Amulet (requires amulet disclosures)
144
- const disclosures = await getAmuletDisclosures(partyId);
145
- const cmd = await mergeAmuletHoldingsForParty(partyId, true, walletProvider, 5, disclosures);
146
- const res = await walletProvider.signAndSubmit(cmd);
147
-
148
- // Check UTXO status after merge — confirm the order amount is now covered
149
- const counts = await getUtxoCount(partyId, 'USDCx', walletProvider);
150
- // { total: 5, unlocked: 1, locked: 4, largestUnlocked: 27.26, unlockedBalance: 27.26 }
151
- if (counts.largestUnlocked >= requiredAmount) {
152
- // Safe to retry createOrderProposal
153
- }
154
- ```
155
-
156
- ## API Reference
157
-
158
- > Functions marked with **W** support a wallet provider parameter. All other functions require a custom validator (ledger access via `VALIDATOR_API_URL` and `JWT_TOKEN`).
159
-
160
- ### Configuration
161
-
162
- | Function | Description |
163
- |----------|-------------|
164
- | `initializeConfig(config)` | Initialize the library with a runtime config object |
165
- | `setJWTToken(token)` | Update the JWT token without re-initializing the config |
166
- | `getConfigValue(key)` | Get a config value from runtime config or environment |
167
-
168
- ### Authentication
169
-
170
- | Function | Description |
171
- |----------|-------------|
172
- | `getJWTToken()` | Get Auth0 JWT access token (cached with auto-refresh) |
173
-
174
- ### Instrument Catalog
175
-
176
- These functions are synchronous and work in all environments (no ledger or provider needed).
177
-
178
- | Function | Description |
179
- |----------|-------------|
180
- | `resolveInstrumentDefinition(assetId)` | Look up an instrument definition from the catalog |
181
- | `getInstrumentRegistrar(assetId)` | Get the registrar party for a utility instrument |
182
- | `getSupportedTradingPairs()` | Get the list of supported trading pairs |
183
- | `getInstrumentCatalog()` | Get the full instrument catalog |
184
- | `checkAmuletContext(baseAsset, quoteAsset, side)` | Check if an order requires Amulet context |
185
-
186
- ### Holdings
187
-
188
- | Function | Provider | Description |
189
- |----------|----------|-------------|
190
- | `getAmuletHoldingsForParty(party)` | **W** | Get Amulet holdings |
191
- | `getUtilityHoldingsForParty(party)` | **W** | Get utility token holdings |
192
- | `getCandidateHoldingForOrderCreation(party, isAmulet, quantity, assetId)` | **W** | Find a holding suitable for an order |
193
- | `getUserBalances(party)` | | Get all balances for a party, grouped by asset |
194
- | `getLockedAmuletHoldingsForParty(party)` | | Get locked Amulet holdings |
195
-
196
- ### Orders
197
-
198
- | Function | Provider | Description |
199
- |----------|----------|-------------|
200
- | `createOrderProposal(orderArguments)` | **W** | Create an order proposal |
201
- | `getOrderProposalsForParty(party)` | | Get pending order proposals |
202
- | `getOrdersForParty(party)` | | Get active orders |
203
-
204
- ### Holding Operations
205
-
206
- | Function | Provider | Description |
207
- |----------|----------|-------------|
208
- | `mergeAmuletHoldingsForParty(party, returnCommand, provider, maxUtxos, amuletDisclosures)` | **W** | Merge Amulet holdings into one |
209
- | `mergeUtilityHoldingsForParty(party, utilityAsset, returnCommand, provider, maxUtxos)` | **W** | Merge utility holdings into one |
210
- | `getUtxoCount(party, assetId, provider)` | **W** | Get UTXO summary: counts, largest unlocked amount, and total unlocked balance |
211
- | `splitAmuletHoldingForParty(party, outputQuantity)` | | Split an Amulet holding |
212
- | `unlockLockedAmulets(party)` | | Unlock locked Amulet holdings |
213
-
214
- ### Ledger Queries
215
-
216
- | Function | Description |
217
- |----------|-------------|
218
- | `getTransferFactory(investor, admin, amount, holdingIds)` | Get transfer factory from Scan API |
219
- | `getAmuletDisclosures(party)` | Get Amulet disclosure contracts |
220
- | `getAmuletRules(dso)` | Get AmuletRules contract |
221
- | `getExternalAmuletRules(dso)` | Get ExternalPartyAmuletRules contract |
222
- | `getFeaturedAppRight()` | Get FeaturedAppRight contract |
223
- | `getOpenMiningRounds(dso)` | Get open mining rounds |
224
- | `getCandidateMiningRoundContract(dso)` | Get a currently-open mining round |
225
- | `getUtilityInstrumentConfigurations()` | Get utility instrument configurations |
226
- | `getUtilityAllocationFactory()` | Get utility allocation factory |
227
- | `getUtilitySenderCredentials(sender)` | Get sender credentials |
228
- | `createUtilityCredential(holder, registrar)` | Create a utility credential |
229
-
230
- ### Deprecated
231
-
232
- | Function | Description |
233
- |----------|-------------|
234
- | ~~`cancelOrders(party, orderContractIds, assetType)`~~ | Batch cancel orders (deprecated — use the [Cancel Order](https://apidocs.templedigitalgroup.com/reference/cancelorder) or [Cancel All Orders](https://apidocs.templedigitalgroup.com/reference/cancelallorders) REST API instead) |
1
+ # Temple Canton JS
2
+
3
+ JavaScript SDK for interacting with the Temple Canton blockchain exchange. Supports CC, USDCx, and CBTC tokens on the Canton network.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @temple-digital-group/temple-canton-js
9
+ ```
10
+
11
+ ## Configuration
12
+
13
+ Call `initialize()` before using any SDK functions. It sets up the config and optionally authenticates with the Temple REST API.
14
+
15
+ ### Custom Validator
16
+
17
+ For apps connecting to your own validator (browser or server-side):
18
+
19
+ ```javascript
20
+ import { initialize } from '@temple-digital-group/temple-canton-js';
21
+
22
+ await initialize({
23
+ NETWORK: 'mainnet',
24
+ VALIDATOR_API_URL: 'https://your-validator-url',
25
+ VALIDATOR_SCAN_API_URL: 'https://your-scan-api-url',
26
+ VALIDATOR_USER_PARTY_ID: 'your-user-party-id',
27
+ JWT_TOKEN: 'your-jwt-token', // Browser: pass a pre-authenticated JWT
28
+ // — OR for server-side Auth0 —
29
+ // AUTH0_TOKEN_URL: 'https://your-auth0-domain/oauth/token',
30
+ // AUTH0_USER_ID: 'your-auth0-user-id',
31
+ // AUTH0_CLIENT_ID: 'your-client-id',
32
+ // AUTH0_CLIENT_SECRET: 'your-client-secret',
33
+ // AUTH0_AUDIENCE: 'your-audience',
34
+ });
35
+ ```
36
+
37
+ ### Custom Validator + REST API
38
+
39
+ To also authenticate with the Temple REST API at init time, pass `API_EMAIL`/`API_PASSWORD`:
40
+
41
+ ```javascript
42
+ import { initialize } from '@temple-digital-group/temple-canton-js';
43
+
44
+ await initialize({
45
+ NETWORK: 'mainnet',
46
+ VALIDATOR_API_URL: 'https://your-validator-url',
47
+ VALIDATOR_SCAN_API_URL: 'https://your-scan-api-url',
48
+ VALIDATOR_USER_PARTY_ID: 'your-user-party-id',
49
+ JWT_TOKEN: 'your-jwt-token',
50
+ API_EMAIL: 'user@example.com', // REST API login (optional)
51
+ API_PASSWORD: 'password',
52
+ });
53
+ ```
54
+
55
+ | Key | Required | Description |
56
+ |-----|----------|-------------|
57
+ | `NETWORK` | Yes | `mainnet`, `testnet`, or `localhost` |
58
+ | `VALIDATOR_API_URL` | Yes | Base URL of the Canton validator ledger API |
59
+ | `VALIDATOR_SCAN_API_URL` | Yes | Base URL of the Canton Scan API |
60
+ | `VALIDATOR_USER_PARTY_ID` | Yes | The user's party ID on the network |
61
+ | `JWT_TOKEN` | Yes* | Pre-authenticated JWT token for ledger API calls |
62
+ | `AUTH0_TOKEN_URL` | Yes* | Auth0 OAuth token endpoint |
63
+ | `AUTH0_CLIENT_ID` | Yes* | Auth0 application client ID |
64
+ | `AUTH0_CLIENT_SECRET` | Yes* | Auth0 application client secret |
65
+ | `AUTH0_AUDIENCE` | Yes* | Auth0 API audience identifier |
66
+ | `AUTH0_USER_ID` | Yes* | Auth0 user ID for the service account |
67
+ | `API_EMAIL` | No | Temple REST API email (triggers login at init) |
68
+ | `API_PASSWORD` | No | Temple REST API password (required with `API_EMAIL`) |
69
+
70
+ \* Provide either `JWT_TOKEN` (browser) or the `AUTH0_*` fields (server-side). The SDK fetches and caches JWT tokens automatically when Auth0 credentials are provided.
71
+
72
+ To update the JWT token later without re-initializing:
73
+
74
+ ```javascript
75
+ import { setJWTToken } from '@temple-digital-group/temple-canton-js';
76
+
77
+ setJWTToken(newToken);
78
+ ```
79
+
80
+ ### Wallet Provider
81
+
82
+ For apps using a wallet provider (e.g., Loop Wallet). Use `returnCommand = true` to get the command data back.
83
+
84
+ ```javascript
85
+ import { initialize, createOrderProposal } from '@temple-digital-group/temple-canton-js';
86
+
87
+ await initialize({
88
+ NETWORK: 'mainnet',
89
+ });
90
+
91
+ const command = await createOrderProposal(orderArgs, true, walletProvider);
92
+ ```
93
+
94
+ | Key | Required | Description |
95
+ |-----|----------|-------------|
96
+ | `NETWORK` | Yes | `mainnet`, `testnet`, or `localhost` |
97
+
98
+ > You can optionally pass `API_EMAIL`/`API_PASSWORD` to any `initialize()` call to also authenticate with the REST API at init time.
99
+
100
+ > **Legacy:** `initializeConfig()` is still available as a sync-only alternative (no REST API auth). `initialize()` is the recommended approach.
101
+
102
+
103
+ ## Supported Instruments
104
+
105
+ | Asset | Type | Networks |
106
+ |---------|---------|-------------------|
107
+ | CC | Canton Coin | testnet, mainnet |
108
+ | USDCx | Utility | testnet, mainnet |
109
+ | CBTC | Utility | testnet, mainnet |
110
+
111
+ ## Supported Trading Pairs
112
+
113
+ - `CC/USDCx`
114
+ - `CBTC/USDCx`
115
+
116
+ ## Usage
117
+
118
+ ### Get User Balances
119
+
120
+ ```javascript
121
+ import { getUserBalances } from '@temple-digital-group/temple-canton-js';
122
+
123
+ // Custom Validator
124
+ const balances = await getUserBalances(partyId);
125
+
126
+ // Wallet Provider
127
+ const balances = await getUserBalances(partyId, walletProvider);
128
+ ```
129
+
130
+ Each entry in the returned array contains:
131
+
132
+ ```javascript
133
+ {
134
+ asset: 'USDCx', // Catalog symbol
135
+ total_balance: 170.5, // Unlocked + locked combined
136
+ available_balance: 150.5, // Unlocked balance (usable for orders)
137
+ locked_balance: 20.0, // Locked balance
138
+ dso: null, // DSO party (CC only)
139
+ registrar: '...', // Registrar party (utility tokens)
140
+ operator: '...', // Operator party
141
+ provider: '...', // Provider party
142
+ merge_warning: true, // true if multiple unlocked holdings exist
143
+ holdings: [...], // Unlocked holding contracts
144
+ locked_holdings: [...], // Locked holding contracts
145
+ utilityContext: { ... } // CIP-56 context (null when using wallet provider)
146
+ }
147
+ ```
148
+
149
+ > **Note:** `utilityContext` is only resolved when using a custom validator (ledger API access). When using a wallet provider, it will be `null`.
150
+
151
+ ### Create an Order
152
+
153
+ ```javascript
154
+ import { createOrderProposal } from '@temple-digital-group/temple-canton-js';
155
+
156
+ const result = await createOrderProposal({
157
+ party: partyId,
158
+ symbol: 'CC/USDCx',
159
+ side: 'Buy',
160
+ quantity: '100',
161
+ pricePerUnit: '1.5',
162
+ expiration: new Date(Date.now() + 3600000).toISOString(),
163
+ userId: auth0UserId,
164
+ orderType: 'limit'
165
+ });
166
+ ```
167
+
168
+ ### Get Orders and Proposals
169
+
170
+ ```javascript
171
+ import { getOrdersForParty, getOrderProposalsForParty } from '@temple-digital-group/temple-canton-js';
172
+
173
+ const orders = await getOrdersForParty(partyId);
174
+ const proposals = await getOrderProposalsForParty(partyId);
175
+ ```
176
+
177
+ ### REST API (Optional) — Market Data and Orders
178
+
179
+ The REST API functions are optional. If you pass `API_EMAIL`/`API_PASSWORD` in `initialize()`, the SDK authenticates at init time. You can also call `login()` directly.
180
+
181
+ ```javascript
182
+ import { initialize, getTicker, getOrderBook, getActiveOrders, cancelOrder } from '@temple-digital-group/temple-canton-js';
183
+
184
+ await initialize({
185
+ NETWORK: 'mainnet',
186
+ API_EMAIL: 'user@example.com',
187
+ API_PASSWORD: 'password',
188
+ });
189
+
190
+ // Market data
191
+ const ticker = await getTicker('CC/USDCx');
192
+ const book = await getOrderBook('CC/USDCx', { levels: 10 });
193
+
194
+ // Orders
195
+ const orders = await getActiveOrders({ symbol: 'CC/USDCx' });
196
+ const result = await cancelOrder('order-id-123');
197
+
198
+ // All functions return { error: true, status, code, message } on failure
199
+ if (result.error) {
200
+ console.log(`Failed: ${result.message}`);
201
+ }
202
+ ```
203
+
204
+ ### Merge Holdings
205
+
206
+ ```javascript
207
+ import { mergeAmuletHoldingsForParty, mergeUtilityHoldingsForParty, getAmuletDisclosures, getUtxoCount } from '@temple-digital-group/temple-canton-js';
208
+
209
+ // Custom Validator (server-side)
210
+ await mergeAmuletHoldingsForParty(partyId);
211
+ await mergeUtilityHoldingsForParty(partyId, 'USDCx');
212
+
213
+ // Wallet Provider — merge up to 5 smallest USDCx UTXOs
214
+ const command = await mergeUtilityHoldingsForParty(partyId, 'USDCx', true, walletProvider, 5);
215
+ const result = await walletProvider.signAndSubmit(command);
216
+
217
+ // Wallet Provider — merge CC (requires disclosures)
218
+ const disclosures = await getAmuletDisclosures(partyId);
219
+ const cmd = await mergeAmuletHoldingsForParty(partyId, true, walletProvider, 5, disclosures);
220
+ const res = await walletProvider.signAndSubmit(cmd);
221
+
222
+ // Check UTXO status after merge — confirm the order amount is now covered
223
+ const counts = await getUtxoCount(partyId, 'USDCx', walletProvider);
224
+ // { total: 5, unlocked: 1, locked: 4, largestUnlocked: 27.26, unlockedBalance: 27.26 }
225
+ if (counts.largestUnlocked >= requiredAmount) {
226
+ // Safe to retry createOrderProposal
227
+ }
228
+ ```
229
+
230
+ ## API Reference
231
+
232
+ > Functions marked with **W** support a wallet provider parameter. All other functions require a custom validator (ledger access via `VALIDATOR_API_URL` and `JWT_TOKEN`).
233
+
234
+ ### Configuration
235
+
236
+ | Function | Description |
237
+ |----------|-------------|
238
+ | `initialize(config)` | Initialize the SDK, set config, and optionally authenticate with the REST API |
239
+ | `initializeConfig(config)` | Sync-only config init (no REST API auth). Use `initialize()` instead |
240
+ | `setJWTToken(token)` | Update the JWT token without re-initializing the config |
241
+ | `getConfigValue(key)` | Get a config value from runtime config or environment |
242
+
243
+ ### Authentication
244
+
245
+ | Function | Description |
246
+ |----------|-------------|
247
+ | `getJWTToken()` | Get Auth0 JWT access token (cached with auto-refresh) |
248
+
249
+ ### Instrument Catalog
250
+
251
+ These functions are synchronous and work in all environments (no ledger or provider needed).
252
+
253
+ | Function | Description |
254
+ |----------|-------------|
255
+ | `resolveInstrumentDefinition(assetId)` | Look up an instrument definition from the catalog |
256
+ | `getInstrumentRegistrar(assetId)` | Get the registrar party for a utility instrument |
257
+ | `getSupportedTradingPairs()` | Get the list of supported trading pairs |
258
+ | `getInstrumentCatalog()` | Get the full instrument catalog |
259
+ | `checkAmuletContext(baseAsset, quoteAsset, side)` | Check if an order requires CC context |
260
+
261
+ ### Holdings
262
+
263
+ | Function | Provider | Description |
264
+ |----------|----------|-------------|
265
+ | `getAmuletHoldingsForParty(party, returnCommand, provider)` | **W** | Get CC holdings |
266
+ | `getLockedAmuletHoldingsForParty(party, returnCommand, provider)` | **W** | Get locked CC holdings |
267
+ | `getUtilityHoldingsForParty(party, returnCommand, provider)` | **W** | Get utility token holdings |
268
+ | `getCandidateHoldingForOrderCreation(party, isAmulet, quantity, assetId)` | **W** | Find a holding suitable for an order |
269
+ | `getUserBalances(party, provider)` | **W** | Get all balances grouped by asset (CC, locked CC, and utility) |
270
+
271
+ ### Orders
272
+
273
+ | Function | Provider | Description |
274
+ |----------|----------|-------------|
275
+ | `createOrderProposal(orderArguments)` | **W** | Create an order proposal |
276
+ | `getOrderProposalsForParty(party)` | | Get pending order proposals |
277
+ | `getOrdersForParty(party)` | | Get active orders |
278
+
279
+ ### Holding Operations
280
+
281
+ | Function | Provider | Description |
282
+ |----------|----------|-------------|
283
+ | `mergeAmuletHoldingsForParty(party, returnCommand, provider, maxUtxos, amuletDisclosures)` | **W** | Merge CC holdings into one |
284
+ | `mergeUtilityHoldingsForParty(party, utilityAsset, returnCommand, provider, maxUtxos)` | **W** | Merge utility holdings into one |
285
+ | `getUtxoCount(party, assetId, provider)` | **W** | Get UTXO summary: counts, largest unlocked amount, and total unlocked balance |
286
+ | `splitAmuletHoldingForParty(party, outputQuantity)` | | Split a CC holding |
287
+ | `unlockLockedAmulets(party)` | | Unlock locked CC holdings |
288
+
289
+ ### Ledger Queries
290
+
291
+ | Function | Description |
292
+ |----------|-------------|
293
+ | `getTransferFactory(investor, admin, amount, holdingIds)` | Get transfer factory from Scan API |
294
+ | `getAmuletDisclosures(party)` | Get CC disclosure contracts |
295
+ | `getAmuletRules(dso)` | Get CC rules contract |
296
+ | `getExternalAmuletRules(dso)` | Get external party CC rules contract |
297
+ | `getFeaturedAppRight()` | Get FeaturedAppRight contract |
298
+ | `getOpenMiningRounds(dso)` | Get open mining rounds |
299
+ | `getCandidateMiningRoundContract(dso)` | Get a currently-open mining round |
300
+ | `getUtilityInstrumentConfigurations()` | Get utility instrument configurations |
301
+ | `getUtilityAllocationFactory()` | Get utility allocation factory |
302
+ | `getUtilitySenderCredentials(sender)` | Get sender credentials |
303
+ | `createUtilityCredential(holder, registrar)` | Create a utility credential |
304
+
305
+ ### Temple REST API (Optional)
306
+
307
+ > These functions call the Temple public REST API and are entirely optional. Pass `API_EMAIL`/`API_PASSWORD` in `initialize()`, or call `login()` directly — tokens are stored and auto-refreshed.
308
+
309
+ #### Auth
310
+
311
+ | Function | Description |
312
+ |----------|-------------|
313
+ | `login(email, password)` | Login and store access/refresh tokens |
314
+ | `refreshAccessToken(refreshToken?)` | Refresh the access token (auto-called when expired) |
315
+ | `logout()` | Clear stored tokens |
316
+
317
+ #### Market Data
318
+
319
+ | Function | Description |
320
+ |----------|-------------|
321
+ | `getTicker(symbol?)` | Get ticker data for one or all trading pairs |
322
+ | `getOrderBook(symbol, options?)` | Get the order book (options: `levels`, `precision`) |
323
+ | `getSymbolConfig(symbol)` | Get symbol configuration (paused, decimals, min quantity) |
324
+ | `getOpenInterest(symbol)` | Get open interest for a trading pair |
325
+ | `getRecentTrades(symbol, options?)` | Get recent trades (options: `limit`, max 500) |
326
+
327
+ #### Orders
328
+
329
+ | Function | Description |
330
+ |----------|-------------|
331
+ | `getActiveOrders(options?)` | Get active orders (options: `symbol`, `limit`) |
332
+ | `cancelOrder(orderId)` | Cancel a specific order |
333
+ | `cancelAllOrders(options?)` | Cancel all orders (options: `symbol` filter) |
334
+
335
+ #### Disclosures
336
+
337
+ | Function | Description |
338
+ |----------|-------------|
339
+ | `getDisclosures(partyId)` | Get CC disclosure data (amulet rules, open mining rounds, external party rules) |
@@ -0,0 +1,76 @@
1
+ import type { ApiError, LoginResponse, RefreshResponse, Ticker, OrderBook, OrderBookOptions, SymbolConfig, OpenInterest, Trade, RecentTradesOptions, ActiveOrder, ActiveOrdersOptions, CancelOrderResponse, CancelAllOrdersOptions, CancelAllOrdersResponse, DisclosuresResponse } from "./types.js";
2
+ export type { ApiError, LoginResponse, RefreshResponse, Ticker, OrderBook, OrderBookOptions, SymbolConfig, OpenInterest, Trade, RecentTradesOptions, ActiveOrder, ActiveOrdersOptions, CancelOrderResponse, CancelAllOrdersOptions, CancelAllOrdersResponse, DisclosuresResponse, };
3
+ export { setApiKey } from "./tokenStore.js";
4
+ /**
5
+ * Initialize the Temple SDK — sets config and optionally authenticates with the REST API.
6
+ * Pass `API_EMAIL`/`API_PASSWORD` or `API_KEY` to authenticate eagerly at init time.
7
+ *
8
+ * @returns The login response on success, or an ApiError on failure.
9
+ * Returns `null` if no API credentials were provided (config-only init).
10
+ */
11
+ export declare function initialize(cfg: Record<string, unknown>): Promise<LoginResponse | ApiError | null>;
12
+ /**
13
+ * Login to the Temple REST API with email and password.
14
+ * Stores tokens automatically for subsequent API calls.
15
+ * @param email - User email
16
+ * @param password - User password
17
+ */
18
+ export declare function login(email: string, password: string): Promise<LoginResponse | ApiError>;
19
+ /**
20
+ * Refresh the access token using the stored or provided refresh token.
21
+ * Updates the token store automatically on success.
22
+ * @param refreshTokenOverride - Optional explicit refresh token (uses stored one if omitted)
23
+ */
24
+ export declare function refreshAccessToken(refreshTokenOverride?: string): Promise<RefreshResponse | ApiError>;
25
+ /**
26
+ * Logout: clear all stored REST API tokens.
27
+ */
28
+ export declare function logout(): void;
29
+ /**
30
+ * Get ticker data for one or all trading pairs.
31
+ * @param symbol - Optional symbol filter (e.g., "Amulet/USDCx")
32
+ */
33
+ export declare function getTicker(symbol?: string): Promise<Ticker | Ticker[] | ApiError>;
34
+ /**
35
+ * Get the order book for a trading pair.
36
+ * @param symbol - Trading pair symbol (required)
37
+ * @param options - Optional levels and precision parameters
38
+ */
39
+ export declare function getOrderBook(symbol: string, options?: OrderBookOptions): Promise<OrderBook | ApiError>;
40
+ /**
41
+ * Get symbol configuration (paused status, decimals, minimum quantity).
42
+ * @param symbol - Trading pair symbol (required)
43
+ */
44
+ export declare function getSymbolConfig(symbol: string): Promise<SymbolConfig | ApiError>;
45
+ /**
46
+ * Get open interest for a trading pair.
47
+ * @param symbol - Trading pair symbol (required)
48
+ */
49
+ export declare function getOpenInterest(symbol: string): Promise<OpenInterest | ApiError>;
50
+ /**
51
+ * Get recent trades for a trading pair.
52
+ * @param symbol - Trading pair symbol (required)
53
+ * @param options - Optional limit (max 500)
54
+ */
55
+ export declare function getRecentTrades(symbol: string, options?: RecentTradesOptions): Promise<Trade[] | ApiError>;
56
+ /**
57
+ * Get active orders, optionally filtered by symbol.
58
+ * @param options - Optional symbol and limit filters
59
+ */
60
+ export declare function getActiveOrders(options?: ActiveOrdersOptions): Promise<ActiveOrder[] | ApiError>;
61
+ /**
62
+ * Cancel a specific order by ID.
63
+ * @param orderId - The order ID to cancel
64
+ */
65
+ export declare function cancelOrder(orderId: string): Promise<CancelOrderResponse | ApiError>;
66
+ /**
67
+ * Cancel all active orders, optionally filtered by symbol.
68
+ * @param options - Optional symbol filter
69
+ */
70
+ export declare function cancelAllOrders(options?: CancelAllOrdersOptions): Promise<CancelAllOrdersResponse | ApiError>;
71
+ /**
72
+ * Get amulet disclosure data for a party from the Temple REST API.
73
+ * Returns protocol disclosures (amulet rules, open mining rounds, external party amulet rules).
74
+ * @param partyId - Canton party ID
75
+ */
76
+ export declare function getDisclosures(partyId: string): Promise<DisclosuresResponse | ApiError>;