@carbonx3/cx3.js 0.3.3 → 0.3.5
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 +8 -8
- package/index.js +1 -1
- package/package.json +1 -1
- package/src/provider.js +4 -3
- package/src/utils.js +1 -1
package/README.md
CHANGED
|
@@ -145,12 +145,12 @@ Supported ABI shapes:
|
|
|
145
145
|
|
|
146
146
|
## Transactions and fees
|
|
147
147
|
|
|
148
|
-
|
|
148
|
+
Gas is paid in CX3 to the validator that produces the block: gas used × gas price (devnet default 0.0001 CX3 per gas).
|
|
149
149
|
|
|
150
|
-
- A native transfer uses 21,000 gas: **2.1 CX3**.
|
|
151
|
-
- A contract send or deploy is
|
|
150
|
+
- A native transfer uses 21,000 gas: **2.1 CX3**. The sender needs the amount plus the fee.
|
|
151
|
+
- A contract send or deploy through the gateway is relayed by the chain's own deploy account: the call still runs as your wallet (the chain checks your signature again), and your wallet pays no gas for it. The call's gas limit (100,000 by default) still bounds the work it may do.
|
|
152
152
|
|
|
153
|
-
Too little balance fails with `INSUFFICIENT_BALANCE`, and a gas price below the chain floor with `GAS_PRICE_TOO_LOW`. A send waits for its block by default; with `{ wait: 0 }` it returns at once, and `tx.wait()` polls the transaction status until it is confirmed or failed.
|
|
153
|
+
Too little balance for a native transfer fails with `INSUFFICIENT_BALANCE`, and a gas price below the chain floor with `GAS_PRICE_TOO_LOW`. A send waits for its block by default; with `{ wait: 0 }` it returns at once, and `tx.wait()` polls the transaction status until it is confirmed or failed.
|
|
154
154
|
|
|
155
155
|
## Deploying tokens
|
|
156
156
|
|
|
@@ -179,7 +179,7 @@ Token symbols are capital letters `A-Z` and digits `0-9` only. The SDK checks th
|
|
|
179
179
|
|
|
180
180
|
A private token is sent, received and seen only by its owner and its authorized wallets. The token contract enforces this on the chain, and the SDK follows the same rules:
|
|
181
181
|
|
|
182
|
-
- **Lists:** `getTokens` shows a private token only to its owner, its authorized wallets and its holders; `listContracts()` shows it only when the application's wallet is its owner or an authorized wallet. Its holders and raw state answer `403 PRIVATE_TOKEN` to every application except the owner's.
|
|
182
|
+
- **Lists:** `getTokens` shows a private token only to its owner, its authorized wallets and its holders, and only with that wallet's own signed proof (header `X-CX3-Wallet-Proof`, since 2026-10-19; CX3Wallet sends it for its own lists), so an application gets the public tokens; `listContracts()` shows it only when the application's wallet is its owner or an authorized wallet. Its holders and raw state answer `403 PRIVATE_TOKEN` to every application except the owner's.
|
|
183
183
|
- **Sends:** before a `transfer`, `transferFrom` or `mint` of a private token, the wallet asks the token whether both ends are authorized. If one is not, it throws `PRIVATE_TOKEN_SENDER` or `PRIVATE_TOKEN_RECIPIENT` instead of signing a send the block would refuse. `{ privateCheck: false }` skips the check.
|
|
184
184
|
- **Checks:** `provider.isPrivateToken(token)` and `provider.isTokenAuthorized(token, wallet)`, which returns `true` for the owner or a listed wallet, `false` otherwise and `null` when the node does not answer.
|
|
185
185
|
|
|
@@ -233,7 +233,7 @@ try {
|
|
|
233
233
|
| `invalid_client` | The token endpoint refused the application (wrong secret, or revoked) |
|
|
234
234
|
| `insufficient_scope`, `ROUTE_NOT_ALLOWED` | The route needs another scope, or is not open to applications (403) |
|
|
235
235
|
| `RATE_LIMITED` | The application's rate limit was reached (429) |
|
|
236
|
-
| `INSUFFICIENT_BALANCE`, `GAS_PRICE_TOO_LOW` |
|
|
236
|
+
| `INSUFFICIENT_BALANCE`, `GAS_PRICE_TOO_LOW` | A native transfer's sender cannot pay the amount plus gas, or the gas price is below the chain floor |
|
|
237
237
|
| `INVALID_TOKEN_SYMBOL`, `DUPLICATE_TOKEN_SYMBOL` | The symbol is not `A-Z` / `0-9`, or is already in use (409) |
|
|
238
238
|
| `PRIVATE_TOKEN_SENDER`, `PRIVATE_TOKEN_RECIPIENT`, `PRIVATE_TOKEN` | Private token rules (see above) |
|
|
239
239
|
| `TX_FAILED`, `TX_TRACK_TIMEOUT` | The transaction failed, or `tx.wait()` did not see it confirmed in time |
|
|
@@ -242,7 +242,7 @@ try {
|
|
|
242
242
|
|
|
243
243
|
## Browser applications
|
|
244
244
|
|
|
245
|
-
This package is for Node.js servers. Web pages use the **CX3 IIFE** (`window.cx3`) together with the CX3Wallet extension: [`@carbonx3/cx3-iife`](https://www.npmjs.com/package/@carbonx3/cx3-iife) on npm and jsDelivr, or [download it](https://cx3script.com/download/cx3-0.2.
|
|
245
|
+
This package is for Node.js servers. Web pages use the **CX3 IIFE** (`window.cx3`) together with the CX3Wallet extension: [`@carbonx3/cx3-iife`](https://www.npmjs.com/package/@carbonx3/cx3-iife) on npm and jsDelivr, or [download it](https://cx3script.com/download/cx3-0.2.7.min.js); see the [CX3 IIFE guide](https://cx3script.com/docs?doc=cx3iife). Keep the application's credentials on your server behind a same-origin proxy, and never put a client secret, an API key or a private key in browser JavaScript.
|
|
246
246
|
|
|
247
247
|
## Environment variables
|
|
248
248
|
|
|
@@ -258,7 +258,7 @@ Type declarations (`index.d.ts`) ship with the package.
|
|
|
258
258
|
|
|
259
259
|
## Upgrading from 0.2.x
|
|
260
260
|
|
|
261
|
-
Version 0.3.0 signs native transfers for the network's new signing format (0.3.1 to 0.3.
|
|
261
|
+
Version 0.3.0 signs native transfers for the network's new signing format (0.3.1 to 0.3.4 change only this README, the file headers and comments, not the code). In 0.3.5, `bindApiKey` with a wallet API key asks the gateway's `/wallet/api-key/bind` (before, it asked `/whoami`, which the gateway refuses, so it always failed).
|
|
262
262
|
|
|
263
263
|
- **The genesis hash is signed.** `transferNative` asks the network for its chain id and genesis hash (`provider.getChainIdentity()`) unless both are given as `opts.chainId` and `opts.genesisHash`. 0.2.x transfers no longer verify on the chain.
|
|
264
264
|
- **No fallback chain id.** `buildTransferPayload` throws `NO_CHAIN_IDENTITY` without `chainId` and `genesisHash`; the `CX3_CHAIN_ID` variable and the `chainIdBind` option are gone.
|
package/index.js
CHANGED
|
@@ -33,7 +33,7 @@ const {
|
|
|
33
33
|
} = require("./src/crypto");
|
|
34
34
|
const { normalizeAbi, argsToParams } = require("./src/abi");
|
|
35
35
|
|
|
36
|
-
const VERSION = "0.3.
|
|
36
|
+
const VERSION = "0.3.5";
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
39
|
* Convenience: provider from `options.url` or env `CX3_NODE_URL` — the CX3Api gateway
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carbonx3/cx3.js",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
4
4
|
"description": "Official Node.js SDK (CX3js) for CarbonX3 Green Chain: OAuth2 app access, local secp256k1 signing, ABI-bound contracts and token deploys over REST + JSON",
|
|
5
5
|
"homepage": "https://cx3script.com",
|
|
6
6
|
"publishConfig": {
|
package/src/provider.js
CHANGED
|
@@ -502,7 +502,8 @@ class Cx3Provider {
|
|
|
502
502
|
/**
|
|
503
503
|
* Check that this wallet is the one the credentials belong to (an app and a wallet API key are
|
|
504
504
|
* both bound to one wallet): `{ ok: true }`, or `wallet_mismatch`.
|
|
505
|
-
* OAuth2 app → GET `/wallet/api-key/bind
|
|
505
|
+
* OAuth2 app and cx3wk_ key → GET `/wallet/api-key/bind` (the gateway route; it has no `/whoami`);
|
|
506
|
+
* a cx3wk_ key falls back to `/whoami` on 404 (a same-origin proxy that only forwards that).
|
|
506
507
|
* A development node has no credentials: `{ ok: true, devNode: true }`.
|
|
507
508
|
*/
|
|
508
509
|
async bindApiKey(address) {
|
|
@@ -518,11 +519,11 @@ class Cx3Provider {
|
|
|
518
519
|
return { ok: true, devNode: true };
|
|
519
520
|
}
|
|
520
521
|
try {
|
|
521
|
-
const json = await this.request("/
|
|
522
|
+
const json = await this.request("/wallet/api-key/bind", { query });
|
|
522
523
|
return this._rejectEnvelope(json);
|
|
523
524
|
} catch (e) {
|
|
524
525
|
if (e && e.status === 404) {
|
|
525
|
-
const json = await this.request("/
|
|
526
|
+
const json = await this.request("/whoami", { query });
|
|
526
527
|
return this._rejectEnvelope(json);
|
|
527
528
|
}
|
|
528
529
|
throw e;
|
package/src/utils.js
CHANGED
|
@@ -71,7 +71,7 @@ function toJsonSafe(value) {
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
/**
|
|
74
|
-
* Same rules as
|
|
74
|
+
* Same rules as DappsExamples/CX3AssetDashboard `cx3_dapp_key_mode`:
|
|
75
75
|
* empty → public (any wallet); valid cx3wk_ → private (that wallet); else invalid.
|
|
76
76
|
*/
|
|
77
77
|
function walletApiKeyMode(key) {
|