@trustvc/trustvc 2.9.1 → 2.11.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/README.md +54 -0
- package/dist/cjs/__tests__/fixtures/sample-oa-document.json +61 -0
- package/dist/cjs/index.js +11 -0
- package/dist/cjs/open-attestation/decrypt.js +34 -0
- package/dist/cjs/open-attestation/encrypt.js +47 -0
- package/dist/cjs/open-attestation/index.js +30 -20
- package/dist/cjs/open-attestation/utils.js +43 -0
- package/dist/cjs/transaction/cancel.js +57 -0
- package/dist/cjs/transaction/index.js +10 -0
- package/dist/esm/__tests__/fixtures/sample-oa-document.json +61 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/open-attestation/decrypt.js +28 -0
- package/dist/esm/open-attestation/encrypt.js +41 -0
- package/dist/esm/open-attestation/index.js +2 -0
- package/dist/esm/open-attestation/utils.js +36 -1
- package/dist/esm/transaction/cancel.js +55 -0
- package/dist/esm/transaction/index.js +1 -0
- package/dist/types/index.d.ts +5 -2
- package/dist/types/open-attestation/decrypt.d.ts +12 -0
- package/dist/types/open-attestation/encrypt.d.ts +13 -0
- package/dist/types/open-attestation/index.d.ts +4 -2
- package/dist/types/open-attestation/types.d.ts +8 -1
- package/dist/types/open-attestation/utils.d.ts +32 -1
- package/dist/types/transaction/cancel.d.ts +37 -0
- package/dist/types/transaction/index.d.ts +1 -0
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -27,6 +27,7 @@ TrustVC is a comprehensive wrapper library designed to simplify the signing and
|
|
|
27
27
|
- [b) Token Registry V5](#b-token-registry-v5)
|
|
28
28
|
- [8. **Document Builder**](#8-document-builder)
|
|
29
29
|
- [9. **Document Store**](#9-document-store)
|
|
30
|
+
- [10. **Transaction Cancel**](#10-transaction-cancel)
|
|
30
31
|
|
|
31
32
|
## Installation
|
|
32
33
|
|
|
@@ -1107,3 +1108,56 @@ for (const hash of documentHashes) {
|
|
|
1107
1108
|
await documentStoreIssue(storeAddress, hash, signer);
|
|
1108
1109
|
}
|
|
1109
1110
|
```
|
|
1111
|
+
|
|
1112
|
+
---
|
|
1113
|
+
|
|
1114
|
+
## 10. Transaction Cancel
|
|
1115
|
+
|
|
1116
|
+
TrustVC provides a utility to cancel a pending Ethereum transaction by replacing it with a 0-value transaction to the same address, using the same nonce and a higher gas price (replace-by-fee). This works with both ethers v5 and v6 signers.
|
|
1117
|
+
|
|
1118
|
+
**Reference:** [How to cancel Ethereum pending transactions](https://info.etherscan.com/how-to-cancel-ethereum-pending-transactions/)
|
|
1119
|
+
|
|
1120
|
+
### cancelTransaction
|
|
1121
|
+
|
|
1122
|
+
#### Description
|
|
1123
|
+
|
|
1124
|
+
Cancels a pending transaction by sending a 0-value transaction to the signer’s address with the same nonce and a higher gas price. You can specify the pending transaction either by **transaction hash** (nonce and gas price are fetched; gas price is doubled) or by **nonce and gas price** explicitly. Transactions that use EIP-1559 (no legacy `gasPrice`) must be cancelled using nonce and gas price.
|
|
1125
|
+
|
|
1126
|
+
#### Parameters
|
|
1127
|
+
|
|
1128
|
+
- **signer** – Signer with a connected provider; type `CancelTransactionSigner` (compatible with ethers v5 and v6 signers).
|
|
1129
|
+
- **options** – `CancelTransactionOptions`:
|
|
1130
|
+
- **transactionHash** (optional): Pending transaction hash (`0x...`). If provided, nonce and gas price are read from the chain and gas price is increased by 100%.
|
|
1131
|
+
- **nonce** (optional): Pending transaction nonce. Must be used together with `gasPrice`.
|
|
1132
|
+
- **gasPrice** (optional): Gas price in wei for the replacement transaction. Must be used together with `nonce`.
|
|
1133
|
+
|
|
1134
|
+
Either `(nonce, gasPrice)` or `transactionHash` must be provided.
|
|
1135
|
+
|
|
1136
|
+
#### Returns
|
|
1137
|
+
|
|
1138
|
+
**Promise<string>** – The replacement transaction hash.
|
|
1139
|
+
|
|
1140
|
+
#### Throws
|
|
1141
|
+
|
|
1142
|
+
- If the signer has no provider.
|
|
1143
|
+
- If neither `(nonce, gasPrice)` nor `transactionHash` is provided.
|
|
1144
|
+
- If `transactionHash` is given but the transaction is not found.
|
|
1145
|
+
- If the transaction uses EIP-1559 (no `gasPrice`); in that case use nonce and gas price explicitly.
|
|
1146
|
+
|
|
1147
|
+
#### Example
|
|
1148
|
+
|
|
1149
|
+
```ts
|
|
1150
|
+
import { cancelTransaction } from '@trustvc/trustvc';
|
|
1151
|
+
|
|
1152
|
+
// Cancel by transaction hash (gas price is fetched and doubled)
|
|
1153
|
+
const replacementHash = await cancelTransaction(signer, {
|
|
1154
|
+
transactionHash: '0x...',
|
|
1155
|
+
});
|
|
1156
|
+
console.log('Replacement tx:', replacementHash);
|
|
1157
|
+
|
|
1158
|
+
// Or cancel by nonce and gas price (e.g. for EIP-1559 txs)
|
|
1159
|
+
const replacementHash2 = await cancelTransaction(signer, {
|
|
1160
|
+
nonce: '5',
|
|
1161
|
+
gasPrice: '25000000000', // 25 gwei in wei
|
|
1162
|
+
});
|
|
1163
|
+
```
|