Skip to content

Commit

Permalink
Merge pull request #16 from MCN-ING/custom-txns-nosign
Browse files Browse the repository at this point in the history
see changelog 0.8.0
  • Loading branch information
SylvainMartel authored Nov 12, 2024
2 parents a11423f + 45e4a59 commit f99eecf
Show file tree
Hide file tree
Showing 8 changed files with 312 additions and 90 deletions.
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,33 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.8.0] - 2024-11-12

### Added

- New transaction preparation workflows
- Option to prepare transactions without signing
- Option to sign without submitting to ledger
- Visual indicators for transaction preparation state
- Transaction status feedback based on preparation options
- Enhanced documentation
- New Wallet Tool user guide
- Publishing Tool documentation
- Usage instructions and best practices
- Troubleshooting guides

### Changed

- Improved transaction handling system
- Renamed `write_signed_transaction_to_ledger` to `prepare_transaction` for clarity
- Added support for unsigned transaction preview
- Enhanced transaction preparation workflow
- Unified transaction display system

## [0.7.0] - 2024-11-12

[Previous changelog content...]

### Added

- Transaction preparation functionality
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "indyforge"
version = "0.7.0"
version = "0.8.0"
authors = ["Sylvain Martel <[email protected]>"]
edition = "2021"
include = ["LICENSE-APACHE", "LICENSE-MIT", "**/*.rs", "Cargo.toml"]
Expand Down
1 change: 0 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,6 @@ impl eframe::App for TemplateApp {
&mut self.txn_result,
&mut self.schema_info,
&mut self.txn,
&mut self.signed_txn_result,
&mut self.transaction_options,
).expect("Failed to render publish tool UI");
}
Expand Down
99 changes: 99 additions & 0 deletions src/docs/publish-tool.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Publishing Tool Guide / Guide de l'outil de Publication

## About / À propos

The Publishing Tool in IndyForge allows you to create and submit various transactions to an Indy ledger, with options to
prepare, sign, and verify transactions before submission.

L'outil de Publication dans IndyForge vous permet de créer et de soumettre diverses transactions au registre Indy, avec
des options pour préparer, signer et vérifier les transactions avant la soumission.

## Features / Fonctionnalités

- NYM transaction creation and registration / Création et enregistrement de transactions NYM
- Schema creation and publishing / Création et publication de schémas
- Custom transaction handling / Gestion des transactions personnalisées
- Transaction preparation and review / Préparation et révision des transactions
- Optional transaction signing and submission / Signature et soumission optionnelles des transactions

## Transaction Types / Types de Transactions

### NYM Transactions / Transactions NYM

1. Enter NYM Details / Saisissez les détails du NYM:
- DID: The DID to be registered / Le DID à enregistrer
- Verkey: The verification key / La clé de vérification
- Alias (optional): A human-readable name / Un nom lisible (optionnel)
- Role: Select from Author, Endorser, Network Monitor, Steward, or Trustee / Sélectionnez parmi Author, Endorser,
Network Monitor, Steward, ou Trustee

2. Transaction Options / Options de Transaction:
- Sign Transaction: Generate cryptographic signature / Générer une signature cryptographique
- Send to Ledger: Submit to the network / Soumettre au réseau

3. Review and Submit / Révision et Soumission:
- Verify transaction details / Vérifier les détails de la transaction
- Copy transaction for external use / Copier la transaction pour usage externe
- Submit when ready / Soumettre quand prêt

### Schema Transactions / Transactions de Schéma

1. Define Schema / Définir le Schéma:
- Name: Schema identifier / Identifiant du schéma
- Version: Format x.x.x / Format x.x.x
- Attributes: Add/remove as needed / Ajouter/supprimer selon les besoins

2. Preparation / Préparation:
- Review schema structure / Réviser la structure du schéma
- Verify attribute list / Vérifier la liste des attributs
- Choose signing and submission options / Choisir les options de signature et de soumission

### Custom Transactions / Transactions Personnalisées

1. Input Transaction / Saisie de la Transaction:
- Paste prepared transaction JSON / Coller le JSON de la transaction préparée
- Verify format and content / Vérifier le format et le contenu

2. Options / Options:
- Sign: Add cryptographic signature / Ajouter une signature cryptographique
- Submit: Send to ledger / Envoyer au registre
- Preview: Review without sending / Réviser sans envoyer

## Transaction Options / Options de Transaction

For all transaction types / Pour tous les types de transactions:

- **Sign Transaction / Signer la Transaction**:
- When enabled: Transaction will be cryptographically signed / Activé : La transaction sera signée
cryptographiquement
- When disabled: Transaction prepared without signature / Désactivé : Transaction préparée sans signature

- **Send to Ledger / Envoyer au Registre**:
- When enabled: Transaction is submitted to the network / Activé : La transaction est soumise au réseau
- When disabled: Transaction is prepared but not sent / Désactivé : La transaction est préparée mais pas envoyée

## Best Practices / Bonnes Pratiques

1. Transaction Review / Révision des Transactions:
- Always review transactions before signing / Toujours réviser les transactions avant de signer
- Verify all fields are correct / Vérifier que tous les champs sont corrects
- Check role permissions / Vérifier les permissions des rôles

2. Testing / Tests:
- Use preparation mode for verification / Utiliser le mode préparation pour la vérification
- Test on development networks first / Tester d'abord sur les réseaux de développement
- Keep track of transaction responses / Garder une trace des réponses des transactions

3. Security / Sécurité:
- Verify signing authority / Vérifier l'autorité de signature
- Double-check role assignments / Revérifier les attributions de rôles
- Maintain proper key management / Maintenir une bonne gestion des clés

## Troubleshooting / Dépannage

Common issues / Problèmes courants:

- Invalid DID format: Check DID syntax / Format DID invalide : Vérifier la syntaxe du DID
- Role permission errors: Verify authority / Erreurs de permission de rôle : Vérifier l'autorité
- Network issues: Check connection status / Problèmes réseau : Vérifier l'état de la connexion
- Transaction rejections: Review format and permissions / Rejets de transactions : Réviser le format et les permissions
71 changes: 71 additions & 0 deletions src/docs/wallet-tool.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Wallet Tool Guide / Guide de l'outil Wallet

## About / À propos

The Wallet Tool in IndyForge provides functionality for creating and managing DIDs (Decentralized Identifiers) for use
with Indy networks.

L'outil Wallet dans IndyForge fournit des fonctionnalités pour créer et gérer les DID (Identifiants Décentralisés) pour
une utilisation avec les réseaux Indy.

## Features / Fonctionnalités

- Create temporary wallets with DIDs / Créer des wallets temporaires avec des DID
- Support for both DID:SOV and DID:INDY formats / Prise en charge des formats DID:SOV et DID:INDY
- Secure seed-based DID generation / Génération sécurisée de DID basée sur une seed
- Genesis file management for network connectivity / Gestion des fichiers genesis pour la connectivité réseau

## Usage / Utilisation

### Creating a Wallet / Création d'un Wallet

1. Enter a 32-byte seed in the seed input field / Entrez une seed de 32 octets dans le champ de saisie
- This seed will be used to generate your DID / Cette seed sera utilisée pour générer votre DID
- The same seed will always generate the same DID / La même seed générera toujours le même DID
- Keep this seed secure as it controls the DID / Gardez cette seed en sécurité car elle contrôle le DID

2. Select DID Version / Sélectionnez la version du DID
- SOV: Traditional Sovrin DID format / Format DID Sovrin traditionnel
- Indy: Newer Indy DID format / Nouveau format DID Indy
- Choose based on your network requirements / Choisissez selon les exigences de votre réseau

3. Click "Create Wallet" / Cliquez sur "Create Wallet"
- The tool will generate and display your DID and Verkey / L'outil générera et affichera votre DID et Verkey
- This information will be used for ledger operations / Ces informations seront utilisées pour les opérations sur le
registre

### Connecting to a Network / Connexion à un Réseau

1. Select Genesis File Source / Sélectionnez la source du fichier Genesis:
- Local File: Use "Select Local Genesis File" to choose a file from your system / Fichier local : Utilisez "Select
Local Genesis File" pour choisir un fichier depuis votre système
- URL: Enter a genesis file URL and click "Load URL" / URL : Entrez l'URL d'un fichier genesis et cliquez sur "Load
URL"

2. Verify Connection / Vérifiez la Connexion
- The active genesis source will be displayed / La source genesis active sera affichée
- A successful connection is required for ledger operations / Une connexion réussie est nécessaire pour les
opérations sur le registre

## Best Practices / Bonnes Pratiques

1. Seed Management / Gestion des Seeds
- Use unique seeds for different DIDs / Utilisez des seeds uniques pour différents DID
- Store seeds securely / Stockez les seeds de manière sécurisée
- Never share your seeds / Ne partagez jamais vos seeds

2. Network Selection / Sélection du Réseau
- Ensure your genesis file matches your target network / Assurez-vous que votre fichier genesis correspond à votre
réseau cible
- Verify network compatibility before operations / Vérifiez la compatibilité du réseau avant les opérations
- Keep genesis files up to date / Gardez les fichiers genesis à jour

## Troubleshooting / Dépannage

Common issues and solutions / Problèmes courants et solutions:

- Invalid seed length: Ensure exactly 32 bytes / Longueur de seed invalide : Assurez-vous d'avoir exactement 32 octets
- Genesis file errors: Verify file format and network availability / Erreurs de fichier genesis : Vérifiez le format du
fichier et la disponibilité du réseau
- Connection issues: Check network connectivity and genesis file validity / Problèmes de connexion : Vérifiez la
connectivité réseau et la validité du fichier genesis
88 changes: 44 additions & 44 deletions src/helpers/ledgers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,11 @@ impl IndyLedger {
}

// function to only send a transaction that is already signed
pub async fn write_signed_transaction_to_ledger(
pub async fn prepare_transaction(
&self,
wallet: &IndyWallet,
signed_txn: &mut String,
options: &TransactionOptions,
) -> VdrResult<String> {
let mut req = PreparedRequest::from_request_json(signed_txn)?;

Expand All @@ -186,54 +187,53 @@ impl IndyLedger {
)
})?;

// If the transaction already has signatures, submit as is
if req_json.contains_key("signatures") {
return self._submit_request(&req).await;
}

// Don't try to modify transactions that already have a signature
if req_json.contains_key("signature") {
return Err(VdrError::new(
VdrErrorKind::Input,
Some("Transaction uses legacy single signature format. Please use multi-signature format.".to_string()),
None
));
}

// Get the operation type to validate the request
// let operation = req_json
// .get("operation")
// .and_then(|op| op.as_object())
// .and_then(|op| op.get("type"))
// .and_then(|t| t.as_str())
// .ok_or_else(|| {
// VdrError::new(
// VdrErrorKind::Input,
// Some("Missing or invalid operation type in request".to_string()),
// None,
// )
// })?;

// Sign the transaction using multi-signature format
match req.get_signature_input() {
Ok(sig_bytes) => {
let signature = wallet.sign(sig_bytes.as_bytes()).await;
req.set_multi_signature(&DidValue(wallet.did.clone()), &signature)
.map_err(|e| {
VdrError::new(
VdrErrorKind::Input,
Some("Failed to add multi-signature to request".to_string()),
Some(Box::new(e)),
)
})?;
if options.sign {
if req_json.contains_key("signatures") {
return Err(VdrError::new(
VdrErrorKind::Input,
Some("Transaction already has signatures".to_string()),
None,
));
}
Err(e) => {

if req_json.contains_key("signature") {
return Err(VdrError::new(
VdrErrorKind::Input,
Some("Failed to get signature input from request".to_string()),
Some(Box::new(e)),
Some("Transaction uses legacy single signature format. Please use multi-signature format.".to_string()),
None,
));
}

match req.get_signature_input() {
Ok(sig_bytes) => {
let signature = wallet.sign(sig_bytes.as_bytes()).await;
req.set_multi_signature(&DidValue(wallet.did.clone()), &signature)
.map_err(|e| {
VdrError::new(
VdrErrorKind::Input,
Some("Failed to add multi-signature to request".to_string()),
Some(Box::new(e)),
)
})?;
}
Err(e) => {
return Err(VdrError::new(
VdrErrorKind::Input,
Some("Failed to get signature input from request".to_string()),
Some(Box::new(e)),
));
}
}
}

if !options.send {
return serde_json::to_string_pretty(&req.req_json).map_err(|e| {
VdrError::new(
VdrErrorKind::Input,
Some(format!("Failed to serialize transaction: {}", e)),
None,
)
});
}

self._submit_request(&req).await
Expand Down
Loading

0 comments on commit f99eecf

Please sign in to comment.