@getomnichain/omnichain 0.6.2 → 0.7.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.
- package/CHANGELOG.md +69 -0
- package/dist/cjs/chain_ids.js +2 -2
- package/dist/cjs/chain_ids.js.map +1 -1
- package/dist/cjs/errors.js +6 -0
- package/dist/cjs/errors.js.map +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/ton/index.js +12 -0
- package/dist/cjs/ton/index.js.map +1 -1
- package/dist/cjs/ton/ton_address.js +72 -14
- package/dist/cjs/ton/ton_address.js.map +1 -1
- package/dist/cjs/ton/ton_asset.js +21 -0
- package/dist/cjs/ton/ton_asset.js.map +1 -0
- package/dist/cjs/ton/ton_assets.js +10 -0
- package/dist/cjs/ton/ton_assets.js.map +1 -0
- package/dist/cjs/ton/ton_chain.js +483 -0
- package/dist/cjs/ton/ton_chain.js.map +1 -0
- package/dist/cjs/ton/ton_chains.js +21 -0
- package/dist/cjs/ton/ton_chains.js.map +1 -0
- package/dist/cjs/ton/ton_jetton_metadata.js +107 -0
- package/dist/cjs/ton/ton_jetton_metadata.js.map +1 -0
- package/dist/cjs/ton/ton_messages.js +174 -0
- package/dist/cjs/ton/ton_messages.js.map +1 -0
- package/dist/cjs/ton/ton_provider.js +456 -0
- package/dist/cjs/ton/ton_provider.js.map +1 -0
- package/dist/cjs/ton/ton_tonapi.js +243 -0
- package/dist/cjs/ton/ton_tonapi.js.map +1 -0
- package/dist/cjs/ton/ton_toncenter.js +252 -0
- package/dist/cjs/ton/ton_toncenter.js.map +1 -0
- package/dist/cjs/ton/ton_transaction_status.js +231 -0
- package/dist/cjs/ton/ton_transaction_status.js.map +1 -0
- package/dist/cjs/ton/ton_transactions.js +107 -0
- package/dist/cjs/ton/ton_transactions.js.map +1 -0
- package/dist/cjs/ton/ton_wallet.js +285 -0
- package/dist/cjs/ton/ton_wallet.js.map +1 -0
- package/dist/cjs/tron/index.js +1 -0
- package/dist/cjs/tron/index.js.map +1 -1
- package/dist/cjs/tron/tron_chain.js +88 -45
- package/dist/cjs/tron/tron_chain.js.map +1 -1
- package/dist/cjs/tron/tron_memo.js +17 -0
- package/dist/cjs/tron/tron_memo.js.map +1 -0
- package/dist/cjs/tron/tron_raw_data.js +213 -0
- package/dist/cjs/tron/tron_raw_data.js.map +1 -0
- package/dist/cjs/tron/tron_transaction_builder.js +34 -13
- package/dist/cjs/tron/tron_transaction_builder.js.map +1 -1
- package/dist/cjs/tron/tron_transaction_status.js +10 -7
- package/dist/cjs/tron/tron_transaction_status.js.map +1 -1
- package/dist/cjs/tron/tron_transactions.js +1 -1
- package/dist/cjs/tron/tron_transactions.js.map +1 -1
- package/dist/esm/chain_ids.js +2 -2
- package/dist/esm/chain_ids.js.map +1 -1
- package/dist/esm/errors.d.ts +3 -0
- package/dist/esm/errors.d.ts.map +1 -1
- package/dist/esm/errors.js +5 -0
- package/dist/esm/errors.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/ton/index.d.ts +12 -0
- package/dist/esm/ton/index.d.ts.map +1 -1
- package/dist/esm/ton/index.js +12 -0
- package/dist/esm/ton/index.js.map +1 -1
- package/dist/esm/ton/ton_address.d.ts +26 -2
- package/dist/esm/ton/ton_address.d.ts.map +1 -1
- package/dist/esm/ton/ton_address.js +70 -14
- package/dist/esm/ton/ton_address.js.map +1 -1
- package/dist/esm/ton/ton_asset.d.ts +12 -0
- package/dist/esm/ton/ton_asset.d.ts.map +1 -0
- package/dist/esm/ton/ton_asset.js +17 -0
- package/dist/esm/ton/ton_asset.js.map +1 -0
- package/dist/esm/ton/ton_assets.d.ts +6 -0
- package/dist/esm/ton/ton_assets.d.ts.map +1 -0
- package/dist/esm/ton/ton_assets.js +7 -0
- package/dist/esm/ton/ton_assets.js.map +1 -0
- package/dist/esm/ton/ton_chain.d.ts +205 -0
- package/dist/esm/ton/ton_chain.d.ts.map +1 -0
- package/dist/esm/ton/ton_chain.js +479 -0
- package/dist/esm/ton/ton_chain.js.map +1 -0
- package/dist/esm/ton/ton_chains.d.ts +11 -0
- package/dist/esm/ton/ton_chains.d.ts.map +1 -0
- package/dist/esm/ton/ton_chains.js +18 -0
- package/dist/esm/ton/ton_chains.js.map +1 -0
- package/dist/esm/ton/ton_jetton_metadata.d.ts +36 -0
- package/dist/esm/ton/ton_jetton_metadata.d.ts.map +1 -0
- package/dist/esm/ton/ton_jetton_metadata.js +103 -0
- package/dist/esm/ton/ton_jetton_metadata.js.map +1 -0
- package/dist/esm/ton/ton_messages.d.ts +133 -0
- package/dist/esm/ton/ton_messages.d.ts.map +1 -0
- package/dist/esm/ton/ton_messages.js +159 -0
- package/dist/esm/ton/ton_messages.js.map +1 -0
- package/dist/esm/ton/ton_provider.d.ts +261 -0
- package/dist/esm/ton/ton_provider.d.ts.map +1 -0
- package/dist/esm/ton/ton_provider.js +432 -0
- package/dist/esm/ton/ton_provider.js.map +1 -0
- package/dist/esm/ton/ton_tonapi.d.ts +39 -0
- package/dist/esm/ton/ton_tonapi.d.ts.map +1 -0
- package/dist/esm/ton/ton_tonapi.js +239 -0
- package/dist/esm/ton/ton_tonapi.js.map +1 -0
- package/dist/esm/ton/ton_toncenter.d.ts +25 -0
- package/dist/esm/ton/ton_toncenter.d.ts.map +1 -0
- package/dist/esm/ton/ton_toncenter.js +248 -0
- package/dist/esm/ton/ton_toncenter.js.map +1 -0
- package/dist/esm/ton/ton_transaction_status.d.ts +116 -0
- package/dist/esm/ton/ton_transaction_status.d.ts.map +1 -0
- package/dist/esm/ton/ton_transaction_status.js +226 -0
- package/dist/esm/ton/ton_transaction_status.js.map +1 -0
- package/dist/esm/ton/ton_transactions.d.ts +54 -0
- package/dist/esm/ton/ton_transactions.d.ts.map +1 -0
- package/dist/esm/ton/ton_transactions.js +100 -0
- package/dist/esm/ton/ton_transactions.js.map +1 -0
- package/dist/esm/ton/ton_wallet.d.ts +134 -0
- package/dist/esm/ton/ton_wallet.d.ts.map +1 -0
- package/dist/esm/ton/ton_wallet.js +278 -0
- package/dist/esm/ton/ton_wallet.js.map +1 -0
- package/dist/esm/tron/index.d.ts +1 -0
- package/dist/esm/tron/index.d.ts.map +1 -1
- package/dist/esm/tron/index.js +1 -0
- package/dist/esm/tron/index.js.map +1 -1
- package/dist/esm/tron/tron_chain.d.ts +13 -1
- package/dist/esm/tron/tron_chain.d.ts.map +1 -1
- package/dist/esm/tron/tron_chain.js +89 -46
- package/dist/esm/tron/tron_chain.js.map +1 -1
- package/dist/esm/tron/tron_memo.d.ts +2 -0
- package/dist/esm/tron/tron_memo.d.ts.map +1 -0
- package/dist/esm/tron/tron_memo.js +14 -0
- package/dist/esm/tron/tron_memo.js.map +1 -0
- package/dist/esm/tron/tron_raw_data.d.ts +4 -0
- package/dist/esm/tron/tron_raw_data.d.ts.map +1 -0
- package/dist/esm/tron/tron_raw_data.js +209 -0
- package/dist/esm/tron/tron_raw_data.js.map +1 -0
- package/dist/esm/tron/tron_transaction_builder.d.ts +4 -0
- package/dist/esm/tron/tron_transaction_builder.d.ts.map +1 -1
- package/dist/esm/tron/tron_transaction_builder.js +34 -13
- package/dist/esm/tron/tron_transaction_builder.js.map +1 -1
- package/dist/esm/tron/tron_transaction_status.d.ts +16 -2
- package/dist/esm/tron/tron_transaction_status.d.ts.map +1 -1
- package/dist/esm/tron/tron_transaction_status.js +10 -7
- package/dist/esm/tron/tron_transaction_status.js.map +1 -1
- package/dist/esm/tron/tron_transactions.js +1 -1
- package/dist/esm/tron/tron_transactions.js.map +1 -1
- package/docs/README.md +2 -1
- package/docs/ton.md +164 -0
- package/docs/tron.md +21 -11
- package/package.json +5 -1
package/docs/tron.md
CHANGED
|
@@ -36,7 +36,8 @@ const { transaction } = await TronMainnet.createTransferTransaction({
|
|
|
36
36
|
- Native TRX builds a `TransferContract`. With `isFullBalance: true` the amount is reduced by 0.3 TRX (`DEFAULT_TRX_FEE_LIMIT_SUN`).
|
|
37
37
|
- TRC-20 builds a `TriggerSmartContract` calling `transfer(address,uint256)` with a 15 TRX `fee_limit` (`DEFAULT_TRC20_TRANSFER_FEE_LIMIT_SUN`), or the `feeLimitSun` of an explicit `TronGasPricing`. `FeePriority` has no effect on Tron.
|
|
38
38
|
- `memo` is stored hex-encoded in `raw_data.data`.
|
|
39
|
-
- `raw_data` is built
|
|
39
|
+
- `raw_data` is built like tronpy: current timestamp, 60 s expiration, TAPoS reference from the latest solid block (`wallet/getnodeinfo`). The txID is computed locally: `sha256` of the protobuf-encoded `raw_data` (`transaction.rawDataHex`). `wallet/getsignweight` is called only when `permissionId(...)` is set, and its txID must equal the local one. Building therefore costs one node call.
|
|
40
|
+
- `TronTrx.buildTransaction(type, value)` builds `TransferContract`, `TriggerSmartContract` (any calldata and `call_value`), `FreezeBalanceV2Contract` and `DelegateResourceContract`, with `.memo()`, `.feeLimit()`, `.expiration()` and `.withOwner()`. These four are the contract types the local encoder supports; TRC-10 fields (`call_token_value`, `token_id`) must be 0.
|
|
40
41
|
- `transaction.canonicalTransaction` parses the wire JSON into the 12-contract discriminated union from `helpers/transaction.py` (`parseTronCanonicalTransaction`).
|
|
41
42
|
|
|
42
43
|
## Signing and broadcasting
|
|
@@ -48,12 +49,14 @@ const response = await TronMainnet.broadcastSignedTransaction(signed);
|
|
|
48
49
|
```
|
|
49
50
|
|
|
50
51
|
- Signatures are tronpy's: RFC 6979 recoverable `r || s || recid` over the txID, appended to the transaction's signature list (like tronpy, signing mutates the transaction). Messages use the TIP-191 `"\x19TRON Signed Message:\n"` keccak hash.
|
|
52
|
+
- Signing recomputes the txID from `raw_data` and signs only that. A carried `txID` or `raw_data_hex` that does not match `raw_data`, or an unsupported contract type, is refused with `InvalidArgument` before the key is used.
|
|
53
|
+
- Broadcasting re-checks the txID the same way before anything is sent, then requires the node's reply to name that txID (`RpcError` otherwise). A signed transaction can be stored with `signed.toJsonStr()` and re-broadcast later with `chain.broadcast(stored)` or `broadcastSignedTransaction(TronSignedTransaction.fromJson(stored))`: it is sent exactly as stored, with the same txID. A stored copy that was altered is refused with `InvalidArgument` and never reaches the node.
|
|
51
54
|
- `broadcastSignedTransaction` never throws: node rejections such as `DUP_TRANSACTION_ERROR`, `SERVER_BUSY` or `BLOCK_UNSOLIDIFIED` come back as `broadcastError` with the txID kept. A reply without `txid` is Python's `KeyError('txid')`. The TS `Chain.broadcast` adapter accepts the signed JSON and throws. It throws `BroadcastRejected` only for the codes java-tron returns before accepting the transaction (`SIGERROR`, `CONTRACT_VALIDATE_ERROR`, `CONTRACT_EXE_ERROR`, `BANDWITH_ERROR`) and `TransactionTooLarge` for `TOO_BIG_TRANSACTION_ERROR`. Everything else, including `DUP_TRANSACTION_ERROR`, `SERVER_BUSY`, `OTHER_ERROR`, unknown codes and a reply without `txid`, is `RpcError`: the transaction may be on-chain, so check its status and re-broadcast the same signed bytes rather than re-signing, as Python's warning says. `TRANSACTION_EXPIRATION_ERROR` and `TAPOS_ERROR` are `RpcError` too: java-tron checks expiry before its duplicate check, so re-broadcasting a transaction that already landed returns them after the 60 s expiry.
|
|
52
55
|
- `TronChain` constructs for any chain id (Nile, private networks) and never touches the network-type registry, as Python's constructor registers nothing.
|
|
53
|
-
- `broadcastSignedTransaction`
|
|
56
|
+
- `broadcastSignedTransaction` and the `broadcast` adapter return the signed txID (lowercase). A node reply naming a different txID, compared case-insensitively, is an `RpcError`.
|
|
54
57
|
- Loading a TRC-20 contract checks the `getcontract` reply like tronpy's `AsyncContract`: a `bytecode` that is not hex and an `abi` that is not an object raise tronpy's texts before any other call.
|
|
55
58
|
- A TronGrid reply that is valid JSON but not an object fails like Python's `payload.get` (`'str' object has no attribute 'get'`) as `RpcError`, without echoing the reply.
|
|
56
|
-
- External signers sign `transaction.txId` and attach the signature with `transaction.transaction.setSignature([...])`.
|
|
59
|
+
- External signers sign `transaction.txId` and attach the signature with `transaction.transaction.setSignature([...])`. `txId` is computed from `raw_data` and checked against any txID or `raw_data_hex` the payload carries, so a payload loaded from JSON cannot hand a signer someone else's txID: a mismatch throws `InvalidArgument`.
|
|
57
60
|
- `TronWallet.handleTransactionPrerequisite` handles `TronApproveTransactionPrerequisite`. It reads the current allowance, skips if it is enough, and otherwise approves (25 TRX fee limit). For USDT-style tokens it first resets the allowance to 0 and waits three blocks; these are tokens in `ZERO_RESET_APPROVAL_TRC20_ADDRESSES` or prerequisites with `requiresZeroResetFirst`.
|
|
58
61
|
|
|
59
62
|
## Reading state
|
|
@@ -66,6 +69,17 @@ const response = await TronMainnet.broadcastSignedTransaction(signed);
|
|
|
66
69
|
- plus the fee debited from the first contract's owner.
|
|
67
70
|
|
|
68
71
|
Unknown TRC-20 tokens are resolved through `symbol()`/`decimals()`. `fees` is a `TronTransactionFees`, whose constructor enforces Python's rule `energyUsageTotal = energyUsage + originEnergyUsage + energyFee / getEnergyFee`.
|
|
72
|
+
- Balance changes count only money that moved:
|
|
73
|
+
- an internal transaction counts as TRX only if it is not `rejected`, its `note` is `call` or `suicide` (staking and resource-delegation entries are skipped), and only its `callValueInfo` entries without a `tokenId` (TRC-10) are added up;
|
|
74
|
+
- the TRX a `TriggerSmartContract` sends as `call_value` is debited from the owner and credited to the contract;
|
|
75
|
+
- a `Transfer` log counts as TRC-20 only with exactly three topics and one 32-byte data word, so TRC-721 transfers are skipped.
|
|
76
|
+
These are the rules Clydner applies.
|
|
77
|
+
- Successful and failed statuses also carry, from the same two node calls:
|
|
78
|
+
- `blockNumber`: the block that included the transaction;
|
|
79
|
+
- `signers`: the owner account of the transaction's contract (the authorizing account, not the keys that signed under a multi-signature permission); `[]` when the raw transaction cannot be fetched;
|
|
80
|
+
- `memoHex`: `raw_data.data` in lowercase hex, and `memo`: that hex decoded by `decodeTronMemo` (strict UTF-8, a leading byte-order mark dropped, `null` for no memo, invalid UTF-8 or bad hex). Clydner decodes memos the same way.
|
|
81
|
+
Pending and not-found statuses carry `null`, `[]`, `null`, `null`.
|
|
82
|
+
- Confirmations are not on the status (`wait` and `confirmations` options stay refused). Compute them as `getChainTipHeight() − blockNumber + 1`. A poll loop should read the tip once per tick and reuse it for every transaction it checks in that tick, so confirmations cost one call per tick, not one per transaction.
|
|
69
83
|
- `simulateTransaction` dry-runs `TriggerSmartContract` through `wallet/triggerconstantcontract` and reports `energyUsed`; other contract types throw `FeatureNotSupported` (Python's `NotImplementedError`). `supportsFullTransactionSimulation` is `false`.
|
|
70
84
|
|
|
71
85
|
## Differences from omnichain-py
|
|
@@ -79,8 +93,11 @@ const response = await TronMainnet.broadcastSignedTransaction(signed);
|
|
|
79
93
|
| `private_key_hex` / `_private_key` are plain attributes | `#private` fields; `wallet.privateKeyHex` still returns the key | `JSON.stringify` and the default `util.inspect` never print the key or the TronGrid API key, and a non-JSON TronGrid reply never reaches an error text |
|
|
80
94
|
| `is_base58check_address` raises `ValueError` on a bad checksum | Returns `false`; callers raise their own error | TS predicates do not throw |
|
|
81
95
|
| `logger.warning` for non-NORMAL `FeePriority` | No logging | The TS SDK has no logger |
|
|
96
|
+
| The txID comes from `wallet/getsignweight` and is signed as given | The txID is computed locally from the protobuf-encoded `raw_data`; a mismatching carried txID or `raw_data_hex` is refused before signing or broadcasting | A node or payload must not be able to get a signature over a different transaction. Python's fix is on RIN-328 |
|
|
97
|
+
| Status counts rejected internal transactions, staking/delegation entries and TRC-10 `callValue` as TRX, and does not debit `call_value` | Only real TRX and TRC-20 moves are counted (see Reading state) | Deposits must not look larger than what arrived. Python's fix is on RIN-328 |
|
|
98
|
+
| Status has no block number, signers or memo | `blockNumber`, `signers`, `memo`, `memoHex` | Read from data the status already fetches; no extra node calls |
|
|
82
99
|
|
|
83
|
-
`TronClient` behaves like tronpy's httpx provider: it never follows redirects, it raises httpx's `raise_for_status` text on non-2xx responses, and its timeout restarts on every received chunk. Contract calls go through `tronAbiEncodeSingle` / `tronAbiDecodeSingle`, a port of tronpy's `trx_abi` (strict eth_abi decoding, Tron addresses inside arrays and tuples). `TronTransaction.sign`
|
|
100
|
+
`TronClient` behaves like tronpy's httpx provider: it never follows redirects, it raises httpx's `raise_for_status` text on non-2xx responses, and its timeout restarts on every received chunk. Contract calls go through `tronAbiEncodeSingle` / `tronAbiDecodeSingle`, a port of tronpy's `trx_abi` (strict eth_abi decoding, Tron addresses inside arrays and tuples). `TronTransaction.sign` keeps tronpy's texts for the refusals it shares with `AsyncTransaction.sign` (expired, permission list, signature list), and adds the local txID checks above.
|
|
84
101
|
|
|
85
102
|
Hex input (keys, signatures, txIDs, node messages) is parsed exactly like Python's `bytes.fromhex`: ASCII whitespace is skipped, `0x` is not hex, and errors report only a position. The TS `verifyMessageSignature` adapter additionally accepts TronWeb's `0x`-prefixed signatures.
|
|
86
103
|
|
|
@@ -94,10 +111,3 @@ Hex input (keys, signatures, txIDs, node messages) is parsed exactly like Python
|
|
|
94
111
|
## Known limitation
|
|
95
112
|
|
|
96
113
|
- TronGrid JSON integers above 2^53 lose precision in `JSON.parse` before they reach `BigInt`. Python's ints do not. Balances and amounts below 9,007,199,254 TRX (or 2^53 base units of a token) are exact.
|
|
97
|
-
|
|
98
|
-
## Known issues shared with omnichain-py
|
|
99
|
-
|
|
100
|
-
These are bugs in omnichain-py itself. They are kept for parity and tracked to be fixed in both SDKs:
|
|
101
|
-
|
|
102
|
-
- RIN-317 — status counts rejected internal transactions and TRC-10 `callValue` as TRX, and does not debit TRX sent as `call_value`.
|
|
103
|
-
- RIN-318 — the wallet signs the txID returned by the node (or found in a JSON payload) without recomputing it from `raw_data`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getomnichain/omnichain",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Multi-chain SDK for EVM, Solana, UTXO (BTC/LTC/DOGE/DASH/ZEC/BCH), Stellar, Tron, and TON. TypeScript parity port of omnichain-py.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"omnichain",
|
|
@@ -80,6 +80,7 @@
|
|
|
80
80
|
"build:cjs": "tsc -p tsconfig.build.cjs.json",
|
|
81
81
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
82
82
|
"test": "node --experimental-vm-modules --no-warnings node_modules/jest/bin/jest.js",
|
|
83
|
+
"test:live:ton": "node --experimental-vm-modules --no-warnings node_modules/jest/bin/jest.js -c jest.live.config.mjs ton/test/live",
|
|
83
84
|
"release": "bash scripts/release.sh",
|
|
84
85
|
"rango:refresh": "node scripts/refresh-rango-fixture.mjs",
|
|
85
86
|
"prepublishOnly": "npm test && npm run build"
|
|
@@ -88,6 +89,9 @@
|
|
|
88
89
|
"@solana/spl-token": "^0.4.14",
|
|
89
90
|
"@solana/web3.js": "^1.98.0",
|
|
90
91
|
"@stellar/stellar-sdk": "^15.1.0",
|
|
92
|
+
"@ton/core": "^0.63.1",
|
|
93
|
+
"@ton/crypto": "^3.3.0",
|
|
94
|
+
"@ton/ton": "^16.3.0",
|
|
91
95
|
"axios": "^1.7.0",
|
|
92
96
|
"bitcoinjs-lib": "^7.0.1",
|
|
93
97
|
"bitcoinjs-message": "^2.2.0",
|