Js sdk isValidKeypair

const privateKey = '4d881dd1917036cc231f9881a0db978c8899dd76a817252418606b02bf6ab9d22378f892b7cc82c2d2739e994ec9953aa36461f1eb5a4a49a5b0de17b3d23ae8';
const publicKey = 'ak_Gd6iMVsoonGuTF8LeswwDDN2NF5wYHAoTRtzwdEcfS32LWoxm';

console.log(Ae.Crypto.isValidKeypair(privateKey, publicKey));

I use

aepp-sdk.browser-script.js

It doesn’t seem to work. How should I use it?
Uncaught Error: bad secret key size
I have no problem using isaddressvalid. Should I convert secret to another format?

@nduchak.chain Can you help me?

Hello @LiuShao.chain,
So basically it’s expect publicKey and privateKey as Buffer. Probably i will extend this API with some additional validation/transformation, but for now you can use more high-lvl API or manually decode the publicKey and privateKey

const privateKey = '4d881dd1917036cc231f9881a0db978c8899dd76a817252418606b02bf6ab9d22378f892b7cc82c2d2739e994ec9953aa36461f1eb5a4a49a5b0de17b3d23ae8';
const publicKey = 'ak_Gd6iMVsoonGuTF8LeswwDDN2NF5wYHAoTRtzwdEcfS32LWoxm';

try {
  Ae.MemoryAccount({ keypair: { publicKey, privateKey }})
} catch (e) {
// here you will have any validation errors
}

// Or decode it manually and use Crypto API

 // Will not work in browser. Possible implementation -> https://github.com/LinusU/hex-to-array-buffer/blob/master/index.js
const decodedPriv = Buffer.from(privateKey, 'hex')
const decodedPub = Ae.Crypto.decodeBase58Check(Ae.Crypto.assertedType(publicKey, 'ak')

console.log(Ae.Crypto.isValidKeypair(privateKey, publicKey));
1 Like