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.
35 lines
1.2 KiB
35 lines
1.2 KiB
5 years ago
|
/**
|
||
|
* @packageDocumentation
|
||
|
* @ignore
|
||
|
*/
|
||
|
|
||
5 years ago
|
import * as keys from '../src/keyTool';
|
||
8 months ago
|
import { isPrivateKey, isAddress, isPublicKey } from '@woop-js/utils';
|
||
5 years ago
|
|
||
|
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`);
|
||
|
}
|
||
|
});
|
||
|
});
|