🗝️ Keys Generation

Key generation is carried out client-side through the Perpetual3 application.

Here's an overview of the process implemented in Dart code:

final idAlgorithm = Cryptography.instance.ed25519();
final ecDHalgorithm = Cryptography.instance.x25519();

// Generating ed25519 key pair
var walletIDsigner = await idAlgorithm.newKeyPair();

// Extracting private and public keys
var edPrivateKey = await walletIDsigner.extract();
var edPrivateKeyhex = hex.encode(edPrivateKey.bytes);

var edPubKey = await walletIDsigner.extractPublicKey();
var edPubKeyhex = hex.encode(edPubKey.bytes);

// Generating x25519 key pair
var walletIDencryptor = await ecDHalgorithm.newKeyPair();

// Extracting private and public keys
var ecPrivateKey = await walletIDencryptor.extract();
var ecPrivateKeyhex = hex.encode(ecPrivateKey.bytes);

var ecPubKey = await walletIDencryptor.extractPublicKey();
var ecPubKeyhex = hex.encode(ecPubKey.bytes);

After generating ed25519 and x25519 keys on the Perpetual3 application, the next crucial step is to securely associate these keys with your crypto wallet. This forms an integral part of establishing your unique merchant identity in the Perpetual3 ecosystem.

To achieve this, we've developed a safe and straightforward process:

  1. Transaction Creation: We create two special transactions where your wallet is both the sender and the receiver. The note field in each transaction is populated with the public keys from your ed25519 and x25519 key pairs respectively.

final walletAuthEd25519 = await (algo.PaymentTransactionBuilder()
    ..sender = ownerWalletaddr
    ..receiver = ownerWalletaddr
    ..note = edPubKeyhex.toBytes()
    ..suggestedParams = algo.TransactionParams.fromJson(authParams))
  .build();

final walletAuthx25519 = await (algo.PaymentTransactionBuilder()
    ..sender = ownerWalletaddr
    ..receiver = ownerWalletaddr
    ..note = ecPubKeyhex.toBytes()
    ..suggestedParams = algo.TransactionParams.fromJson(authParams))
  .build();
  1. Transaction Signing: Next, these transactions are signed using your crypto wallet. By signing these transactions, your wallet effectively associates itself with your ed25519 and x25519 keys, linking your merchant identity to your wallet.

dynamic txnSigner = await getTxnSigner();
var walletIDsig = await txnSigner.signTransactions([
    walletAuthEd25519.toBytes(),
    walletAuthx25519.toBytes()
]);

These steps ensure your merchant identity is robustly secured and uniquely tied to your crypto wallet, fortifying the safety of your Web3 commerce activities on Perpetual3.

Last updated