@temple-digital-group/temple-canton-js 1.0.34 → 1.0.35
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.
- package/README.md +31 -56
- package/package.json +1 -1
- package/src/config/index.js +12 -0
- package/LICENSE +0 -21
package/README.md
CHANGED
|
@@ -10,11 +10,11 @@ npm install @temple-digital-group/temple-canton-js
|
|
|
10
10
|
|
|
11
11
|
## Configuration
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
Call `initializeConfig()` before using any SDK functions. This is required in all environments.
|
|
14
14
|
|
|
15
|
-
###
|
|
15
|
+
### Custom Validator
|
|
16
16
|
|
|
17
|
-
For
|
|
17
|
+
For apps connecting to your own validator (browser or server-side):
|
|
18
18
|
|
|
19
19
|
```javascript
|
|
20
20
|
import { initializeConfig } from '@temple-digital-group/temple-canton-js';
|
|
@@ -23,8 +23,14 @@ initializeConfig({
|
|
|
23
23
|
NETWORK: 'mainnet',
|
|
24
24
|
VALIDATOR_API_URL: 'https://your-validator-url',
|
|
25
25
|
VALIDATOR_SCAN_API_URL: 'https://your-scan-api-url',
|
|
26
|
-
|
|
27
|
-
|
|
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',
|
|
28
34
|
});
|
|
29
35
|
```
|
|
30
36
|
|
|
@@ -33,12 +39,27 @@ initializeConfig({
|
|
|
33
39
|
| `NETWORK` | Yes | `mainnet`, `testnet`, or `localhost` |
|
|
34
40
|
| `VALIDATOR_API_URL` | Yes | Base URL of the Canton validator ledger API |
|
|
35
41
|
| `VALIDATOR_SCAN_API_URL` | Yes | Base URL of the Canton Scan API |
|
|
36
|
-
| `JWT_TOKEN` | Yes | Pre-authenticated JWT token for ledger API calls |
|
|
37
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 |
|
|
38
49
|
|
|
39
|
-
|
|
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.
|
|
40
51
|
|
|
41
|
-
|
|
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.
|
|
42
63
|
|
|
43
64
|
```javascript
|
|
44
65
|
import { initializeConfig, createOrderProposal } from '@temple-digital-group/temple-canton-js';
|
|
@@ -47,57 +68,14 @@ initializeConfig({
|
|
|
47
68
|
NETWORK: 'mainnet'
|
|
48
69
|
});
|
|
49
70
|
|
|
50
|
-
// returnCommand=true returns the command for the wallet to sign
|
|
51
71
|
const command = await createOrderProposal(orderArgs, true, walletProvider);
|
|
52
|
-
const result = await walletProvider.signAndSubmit(command);
|
|
53
72
|
```
|
|
54
73
|
|
|
55
74
|
| Key | Required | Description |
|
|
56
75
|
|-----|----------|-------------|
|
|
57
76
|
| `NETWORK` | Yes | `mainnet`, `testnet`, or `localhost` |
|
|
58
77
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
For server-side applications. Uses environment variables directly — no `initializeConfig()` call needed. Create a `.env` file:
|
|
62
|
-
|
|
63
|
-
```env
|
|
64
|
-
NETWORK=mainnet
|
|
65
|
-
VALIDATOR_API_URL=https://your-validator-url
|
|
66
|
-
VALIDATOR_SCAN_API_URL=https://your-scan-api-url
|
|
67
|
-
|
|
68
|
-
AUTH0_TOKEN_URL=https://your-auth0-domain.auth0.com/oauth/token
|
|
69
|
-
AUTH0_USER_ID=your-auth0-user-id
|
|
70
|
-
AUTH0_CLIENT_ID=your-client-id
|
|
71
|
-
AUTH0_CLIENT_SECRET=your-client-secret
|
|
72
|
-
AUTH0_AUDIENCE=https://your-audience
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
| Parameter | Required | Description |
|
|
76
|
-
|-----------|----------|-------------|
|
|
77
|
-
| `NETWORK` | Yes | `mainnet`, `testnet`, or `localhost` |
|
|
78
|
-
| `VALIDATOR_API_URL` | Yes | Base URL of the Canton validator ledger API |
|
|
79
|
-
| `VALIDATOR_SCAN_API_URL` | Yes | Base URL of the Canton Scan API |
|
|
80
|
-
| `AUTH0_TOKEN_URL` | Yes | Auth0 OAuth token endpoint |
|
|
81
|
-
| `AUTH0_CLIENT_ID` | Yes | Auth0 application client ID |
|
|
82
|
-
| `AUTH0_CLIENT_SECRET` | Yes | Auth0 application client secret |
|
|
83
|
-
| `AUTH0_AUDIENCE` | Yes | Auth0 API audience identifier |
|
|
84
|
-
| `AUTH0_USER_ID` | Yes | Auth0 user ID for the service account |
|
|
85
|
-
|
|
86
|
-
The SDK fetches and caches JWT tokens automatically via Auth0.
|
|
87
|
-
|
|
88
|
-
You can also call `initializeConfig()` in Node.js to override specific environment variables at runtime. For example, if a frontend passes a JWT token to your server:
|
|
89
|
-
|
|
90
|
-
```javascript
|
|
91
|
-
import { initializeConfig, getUserBalances } from '@temple-digital-group/temple-canton-js';
|
|
92
|
-
|
|
93
|
-
// .env provides base config (NETWORK, VALIDATOR_API_URL, etc.)
|
|
94
|
-
// Override with a token received from the frontend
|
|
95
|
-
initializeConfig({ JWT_TOKEN: tokenFromFrontend });
|
|
96
|
-
|
|
97
|
-
const balances = await getUserBalances(partyId);
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
Runtime config values take precedence over environment variables.
|
|
78
|
+
> **Legacy:** Environment variables are still supported for backwards compatibility, but `initializeConfig()` is the recommended approach.
|
|
101
79
|
|
|
102
80
|
|
|
103
81
|
## Supported Instruments
|
|
@@ -184,6 +162,7 @@ if (counts.largestUnlocked >= requiredAmount) {
|
|
|
184
162
|
| Function | Description |
|
|
185
163
|
|----------|-------------|
|
|
186
164
|
| `initializeConfig(config)` | Initialize the library with a runtime config object |
|
|
165
|
+
| `setJWTToken(token)` | Update the JWT token without re-initializing the config |
|
|
187
166
|
| `getConfigValue(key)` | Get a config value from runtime config or environment |
|
|
188
167
|
|
|
189
168
|
### Authentication
|
|
@@ -253,7 +232,3 @@ These functions are synchronous and work in all environments (no ledger or provi
|
|
|
253
232
|
| Function | Description |
|
|
254
233
|
|----------|-------------|
|
|
255
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) |
|
|
256
|
-
|
|
257
|
-
## License
|
|
258
|
-
|
|
259
|
-
MIT
|
package/package.json
CHANGED
package/src/config/index.js
CHANGED
|
@@ -15,6 +15,18 @@ export function initializeConfig(config) {
|
|
|
15
15
|
appConfig = config;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Update the JWT token without re-initializing the full config.
|
|
20
|
+
* Useful when refreshing tokens for custom validator connections.
|
|
21
|
+
* @param {string} token - The new JWT token
|
|
22
|
+
*/
|
|
23
|
+
export function setJWTToken(token) {
|
|
24
|
+
if (!appConfig) {
|
|
25
|
+
appConfig = {};
|
|
26
|
+
}
|
|
27
|
+
appConfig.JWT_TOKEN = token;
|
|
28
|
+
}
|
|
29
|
+
|
|
18
30
|
/**
|
|
19
31
|
* Get a configuration value from:
|
|
20
32
|
* 1. App-provided config (if initializeConfig was called)
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Temple Digital Group
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|