diff --git a/src/utils/crypto.ts b/src/utils/crypto.ts index 62de8895b6..9e4b439aee 100644 --- a/src/utils/crypto.ts +++ b/src/utils/crypto.ts @@ -122,17 +122,16 @@ export function generateKeyPairFromSecret (secret: Uint8Array): SignKeyPair { /** * Generate a random ED25519 keypair - * @rtype (raw: Boolean) => {publicKey: String | Buffer, secretKey: String | Buffer} - * @param {Boolean} raw - Whether to return raw (binary) keys - * @return {Object} Key pair + * @param raw Whether to return raw (binary) keys + * @return Key pair */ -export function generateKeyPair (raw = false): { - publicKey: string | Buffer +export function generateKeyPair (raw?: true): { publicKey: Buffer, secretKey: Buffer } +export function generateKeyPair (raw: false): { publicKey: EncodedData<'ak'>, secretKey: string } +export function generateKeyPair (raw: boolean = false): { + publicKey: EncodedData<'ak'> | Buffer secretKey: string | Buffer } { - // /apps/aens/test/aens_test_utils.erl const keyPair = nacl.sign.keyPair() - const publicBuffer = Buffer.from(keyPair.publicKey) const secretBuffer = Buffer.from(keyPair.secretKey) diff --git a/src/utils/encoder.ts b/src/utils/encoder.ts index 3526ed6160..83f4991af4 100644 --- a/src/utils/encoder.ts +++ b/src/utils/encoder.ts @@ -94,7 +94,9 @@ export function decode (data: EncodedData): Buffer { * @param {string} type Prefix of Transaction * @return {EncodedData>} Encoded string Base58check or Base64check data */ -export function encode (data: Uint8Array, type: EncodingType): EncodedData { +export function encode ( + data: Uint8Array, type: Type +): EncodedData { const [, { encode }] = parseType(type) ensureValidLength(data, type) return `${type}_${encode(data)}`