Skip to content

Instantly share code, notes, and snippets.

@npty
Last active September 16, 2024 07:49
Show Gist options
  • Save npty/35ec1600440336d9ef8b7e6d3483414d to your computer and use it in GitHub Desktop.
Save npty/35ec1600440336d9ef8b7e6d3483414d to your computer and use it in GitHub Desktop.
const { Ed25519Keypair } = require('@mysten/sui/keypairs/ed25519');
const { toB64 } = require('@mysten/sui/utils');
function compareUint8Arrays(a, b) {
for (let i = 0; i < a.length && i < b.length; i++) {
if (a[i] < b[i]) return -1;
if (a[i] > b[i]) return 1;
}
return a.length - b.length;
}
function generateSUIWallets(count) {
const publicKeysUint8Array = [];
for (let i = 0; i < count; i++) {
const keypair = new Ed25519Keypair();
const publicKeyBytes = keypair.getPublicKey().toSuiBytes();
publicKeysUint8Array.push(publicKeyBytes);
}
// Sort the public keys (Uint8Array format)
publicKeysUint8Array.sort(compareUint8Arrays);
// Convert sorted Uint8Array public keys to base64
const sortedPublicKeysBase64 = publicKeysUint8Array.map((pubKey) => toB64(pubKey));
return sortedPublicKeysBase64;
}
// Generate 70 wallets and get sorted public keys
const sortedPublicKeys = generateSUIWallets(70);
console.log(
'Sorted Public Keys (Base64):',
sortedPublicKeys.map((pubKey) => pubKey),
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment