Javascript SDK of WoopChain protocol
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
sdk/packages/woop-crypto/test/keyTool.test.ts

34 lines
1.2 KiB

/**
* @packageDocumentation
* @ignore
*/
import * as keys from '../src/keyTool';
import { isPrivateKey, isAddress, isPublicKey } from '@woop-js/utils';
describe('test keyTools', () => {
it('test keygen', () => {
const prv = keys.generatePrivateKey();
const pub = keys.getPubkeyFromPrivateKey(prv);
const addr = keys.getAddressFromPublicKey(pub);
const addrPrv = keys.getAddressFromPrivateKey(prv);
expect(isPrivateKey(prv)).toEqual(true);
expect(isPublicKey(pub)).toEqual(true);
expect(isAddress(addr)).toEqual(true);
expect(isAddress(addrPrv)).toEqual(true);
expect(addr).toEqual(addrPrv);
});
it('should test sign', () => {
const unsigned = '0xdc80808080809401234567890123456789012345678901234567898080';
const privateKey = '0x0123456789012345678901234567890123456789012345678901234567890123';
const pub = keys.getPubkeyFromPrivateKey(privateKey);
const signature = keys.sign(unsigned, privateKey);
expect(keys.verifySignature(unsigned, signature, pub)).toEqual(true);
try {
keys.sign(unsigned, '111');
} catch (error) {
expect(error.message).toEqual(`111 is not PrivateKey`);
}
});
});