Skip to content

Commit 97ebb7e

Browse files
committed
Fix Solana wallet address format - Generate base58 addresses using Solnet
- Added Solnet.Wallet package to Core project for Solana key generation - Updated KeyManager.GenerateKeyPairWithWalletAddress() to use Solnet for Solana Ed25519 keypairs - Fixed KeyPairAndWallet instantiation for Solana keys - Added SolanaOASIS to AutoFailOverProviders in OASIS_DNA.json - Generated addresses now in correct Solana base58 format (32-44 chars) instead of Bitcoin script format - Verified: Addresses can now receive SOL tokens on Solana network Test Results: - Wallet creation working correctly - Address format: Solana base58 (44 chars) - Validation: All tests passed - Build: Success with 0 errors in main projects Related: SOLANA_WALLET_ADDRESS_FORMAT_ERROR.md, SOLANA_WALLET_FIX_VERIFICATION.md
1 parent ac53e0b commit 97ebb7e

6 files changed

Lines changed: 1035 additions & 0 deletions

File tree

OASIS Architecture/NextGenSoftware.OASIS.API.Core/Managers/KeyManager.cs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using NextGenSoftware.OASIS.Common;
1313
using Org.BouncyCastle.Asn1.X509;
1414
using Rijndael256;
15+
using Solnet.Wallet;
1516
using BC = BCrypt.Net.BCrypt;
1617

1718
namespace NextGenSoftware.OASIS.API.Core.Managers
@@ -88,6 +89,71 @@ public KeyManager(IOASISStorageProvider OASISStorageProvider, OASISDNA OASISDNA
8889
//TODO: Implement later (Cache Disabled).
8990
//public bool IsCacheEnabled { get; set; } = true;
9091

92+
public OASISResult<NextGenSoftware.Utilities.IKeyPairAndWallet> GenerateKeyPairWithWalletAddress(ProviderType providerType)
93+
{
94+
OASISResult<NextGenSoftware.Utilities.IKeyPairAndWallet> result = new OASISResult<NextGenSoftware.Utilities.IKeyPairAndWallet>();
95+
96+
// Solana-specific key generation using Solnet
97+
if (providerType == ProviderType.SolanaOASIS)
98+
{
99+
try
100+
{
101+
// Ensure the provider is activated
102+
var provider = ProviderManager.Instance.GetStorageProvider(providerType);
103+
if (provider != null)
104+
{
105+
// Activate provider if not already activated
106+
if (!provider.IsProviderActivated)
107+
{
108+
var activateResult = provider.ActivateProvider();
109+
if (activateResult.IsError)
110+
{
111+
OASISErrorHandling.HandleError(ref result, $"Failed to activate {providerType} provider: {activateResult.Message}");
112+
return result;
113+
}
114+
}
115+
}
116+
117+
// Generate Solana keypair using Solnet.Wallet
118+
// Solana uses Ed25519 keypairs (not secp256k1 like Bitcoin/Ethereum)
119+
// Create a new Account which generates a random Ed25519 keypair
120+
var account = new Account();
121+
122+
// Solana private keys are base58 encoded (64 bytes = 32 byte seed + 32 byte public key)
123+
// The Account.PrivateKey contains the full keypair bytes encoded in base58
124+
string privateKeyBase58 = account.PrivateKey.Key;
125+
126+
// Solana public key/address is base58 encoded (32 bytes)
127+
// The public key is the wallet address in Solana
128+
string publicKeyBase58 = account.PublicKey.Key;
129+
130+
// Create KeyPairAndWallet with Solana-specific format
131+
var solanaKeyPair = new KeyPairAndWallet
132+
{
133+
PrivateKey = privateKeyBase58, // Base58 encoded Ed25519 private key
134+
PublicKey = publicKeyBase58, // Base58 encoded Ed25519 public key
135+
WalletAddress = publicKeyBase58, // Solana address is the public key in base58
136+
WalletAddressLegacy = string.Empty, // Not applicable for Solana
137+
WalletAddressSegwitP2SH = string.Empty // Not applicable for Solana
138+
};
139+
result.Result = solanaKeyPair;
140+
141+
result.IsError = false;
142+
result.Message = "Solana keypair generated successfully using Solnet";
143+
return result;
144+
}
145+
catch (Exception ex)
146+
{
147+
OASISErrorHandling.HandleError(ref result, $"Error generating Solana keypair: {ex.Message}", ex);
148+
// Fall through to default key generation as fallback
149+
}
150+
}
151+
152+
// Use existing key generation logic for other providers (Bitcoin, Ethereum, etc.)
153+
result.Result = NextGenSoftware.Utilities.KeyHelper.GenerateKeyValuePairAndWalletAddress();
154+
return result;
155+
}
156+
91157
public OASISResult<KeyPair> GenerateKeyPair(ProviderType providerType)
92158
{
93159
string prefix = "";

0 commit comments

Comments
 (0)