encodeSuiPrivateKey function

String encodeSuiPrivateKey(
  1. Uint8List bytes,
  2. SignatureScheme scheme
)

This returns a Bech32 encoded string starting with suiprivkey, encoding 33-byte flag || bytes for the given the 32-byte private key and its signature scheme.

Implementation

String encodeSuiPrivateKey(Uint8List bytes, SignatureScheme scheme) {
	if (bytes.length != PRIVATE_KEY_SIZE) {
		throw ArgumentError('Invalid bytes length');
	}
	final flag = SIGNATURE_SCHEME_TO_FLAG.schemeToFlag(scheme);
	final privKeyBytes = Uint8List(bytes.length + 1);
	privKeyBytes.setAll(0, [flag]);
	privKeyBytes.setAll(1, bytes);
	return bech32.encode(Bech32(SUI_PRIVATE_KEY_PREFIX, bech32.toWords(privKeyBytes)));
}