|
| 1 | +# Migration Guide: Transaction Signing in Hedera SDK |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +The Hedera SDK has updated its transaction signing mechanism to provide functionaly that can work with multi-node chunked transaction and a more structured approach to managing signatures. This guide will help you migrate from the legacy mode to the new mode. |
| 6 | + |
| 7 | +## Key Changes |
| 8 | + |
| 9 | +### Signing a transaction |
| 10 | + |
| 11 | +- Legacy mode returns raw signatures as `Uint8Array` or `Uint8Array[]` when signing transactions with a private keys |
| 12 | +- New mode returns `SignatureMap` when signing transactions with a private key |
| 13 | + |
| 14 | +### Adding a signature |
| 15 | + |
| 16 | +#### Legacy mode: |
| 17 | + |
| 18 | +- Signatures are raw byte arrays (`Uint8Array`) |
| 19 | +- No built-in organization of signatures by node or transaction ID |
| 20 | +- Simpler but less structured approach |
| 21 | + |
| 22 | +#### New Mode: |
| 23 | + |
| 24 | +- **Supports signing of chunked transactions e.g FileAppend chunk transaction** |
| 25 | +- Signatures are organized in a SignatureMap class |
| 26 | +- Signatures are mapped to specific node IDs and transaction IDs |
| 27 | +- More structured and type-safe approach |
| 28 | + |
| 29 | +## Important Considerations |
| 30 | + |
| 31 | +1. Backward Compatibility - Legacy mode still works but new code should always use the new mode |
| 32 | +2. Performance wasn't reduced with these latest changes |
| 33 | +3. Error Handling: |
| 34 | + |
| 35 | +- New mode provides better error messages |
| 36 | +- Easier to debug signature-related issues |
| 37 | + |
| 38 | +4. Multi-signature Operations: |
| 39 | + |
| 40 | +- Much cleaner handling of multiple signatures |
| 41 | +- Better tracking of which keys have signed |
| 42 | + |
| 43 | +5. Users can still use both legacy and non-legacy signing of transactions |
| 44 | + |
| 45 | +## Code examples: |
| 46 | + |
| 47 | +### Signing a transaction |
| 48 | + |
| 49 | +#### Legacy mode: |
| 50 | + |
| 51 | +``` |
| 52 | +const transaction = new AccountCreateTransaction() |
| 53 | + .setKey(newKey.publicKey) |
| 54 | + .freezeWith(client); |
| 55 | +
|
| 56 | +const signature = privateKey.signTransaction(transaction, true); |
| 57 | +``` |
| 58 | + |
| 59 | +#### New mode |
| 60 | + |
| 61 | +``` |
| 62 | +const transaction = new AccountCreateTransaction() |
| 63 | + .setKey(newKey.publicKey) |
| 64 | + .freezeWith(client); |
| 65 | +
|
| 66 | +// Modern signing - returns SignatureMap |
| 67 | +const signatureMap = privateKey.signTransaction(transaction); // legacy parameter defaults to false |
| 68 | +``` |
| 69 | + |
| 70 | +### Adding signatures |
| 71 | + |
| 72 | +#### Legacy mode |
| 73 | + |
| 74 | +``` |
| 75 | +// Adding signatures directly with Uint8Array |
| 76 | +const signatures = privateKey.signTransaction(transaction, true); |
| 77 | +transaction.addSignature(privateKey.publicKey, signatures); |
| 78 | +``` |
| 79 | + |
| 80 | +#### New Mode: |
| 81 | + |
| 82 | +``` |
| 83 | +// SignatureMap handles the signature organization |
| 84 | +const signatureMap = privateKey.signTransaction(transaction); |
| 85 | +transaction.addSignature(privateKey.publicKey, signatureMap); |
| 86 | +``` |
| 87 | + |
| 88 | +### Why and when? |
| 89 | + |
| 90 | +## When did we make this change? |
| 91 | + |
| 92 | +- Current Status: The change is being implemented in response to issue [#2595](https://github.com/hiero-ledger/hiero-sdk-js/issues/2595) |
| 93 | + |
| 94 | +## Implementation Timeline: |
| 95 | + |
| 96 | +- Available now: New signature mode with SignatureMap |
| 97 | +- Deprecation: Legacy mode is deprecated and will be removed in v3.0.0 |
| 98 | +- Migration Period: Users should migrate their code before updating to v1.0.0 |
| 99 | + |
| 100 | +## Legacy Signature Mode Deprecation Notice |
| 101 | + |
| 102 | +The legacy transaction signing mode (using signTransaction(transaction, true) and raw Uint8Array signatures) is scheduled for removal in the next major version (v3.0.0) of the SDK. This legacy mode has been deprecated in favor of the new SignatureMap-based signature system, which provides better type safety, improved signature organization, and more robust multi-signature support. Users should migrate their applications to use the new signature mode before updating to v1.0.0. The new mode is already available and can be used by simply removing the legacy parameter from signTransaction() calls and updating signature handling to work with SignatureMap. For migration assistance, please refer to our Migration Guide. After v3.0.0, only the new signature mode will be supported, and applications using the legacy mode will need to be updated to continue functioning. |
0 commit comments