import { Account } from '../src/account'; import { Address, PublicKey } from '../src/crypto'; import { PrivateKey } from '../src/crypto'; import { CurveLabel } from '../src/crypto/CurveLabel'; import { KeyParameters } from '../src/crypto/Key'; import { ERROR_CODE } from '../src/error'; import * as utils from '../src/utils'; describe('test account', () => { // tslint:disable-next-line:one-variable-per-declaration let privateKey: PrivateKey, accountDataStr: string, account: Account, encryptedPrivateKey: PrivateKey; beforeAll(() => { privateKey = PrivateKey.random(); // console.log(privateKey.serializeJson()) console.log(privateKey.serializeWIF()); }); test('test create', () => { account = Account.create(privateKey, '123456', 'mickey'); encryptedPrivateKey = account.encryptedKey; accountDataStr = account.toJson(); // tslint:disable-next-line:no-console console.log('account: ' + accountDataStr); expect(accountDataStr).toBeDefined(); // tslint:disable:no-console console.log('address: ' + account.address.toBase58()); console.log('privateKey: ' + privateKey); console.log('addressU160: ' + account.address.serialize()); const pub = '120202d3d048aca7bdee582a611d0b8acc45642950dc6167aee63abbdcd1a5781c6319'; console.log('Address: ' + Address.fromPubKey(new PublicKey(pub)).toBase58()); }); test('test import account with correct password', () => { let a; try { a = Account.importAccount('mickey', encryptedPrivateKey, '123456', account.address, account.salt); } catch (err) { console.log(err); } expect(a.label).toBe('mickey'); }); test('test import with incorrect password', () => { try { const a = Account.importAccount('mickey', encryptedPrivateKey, '1234567', account.address, account.salt); } catch (err) { expect(err).toEqual(ERROR_CODE.Decrypto_ERROR); } }); test('create_sm2', () => { const keyParameter = new KeyParameters(CurveLabel.SM2P256V1); const pri = PrivateKey.random(KeyType.SM2, keyParameter); const acc = Account.create(pri, '123456', 'sm2Account'); const accJson = acc.toJsonObj(); console.log(accJson); expect(accJson.algorithm).toEqual('SM2'); }); });