Skip to content

Commit

Permalink
refactor(account)!: remove getAddressFromPriv
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `getAddressFromPriv` removed
Use MemoryAccount instead.
```diff
- address = getAddressFromPriv(secretKeyOldFormat)
+ address = new MemoryAccount(secretKeyNewFormat).address
```
Use SDK tools page to convert secret keys
https://docs.aeternity.com/aepp-sdk-js/develop/examples/browser/tools/
  • Loading branch information
davidyuk committed Jul 3, 2024
1 parent 18c6789 commit 9446639
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/index-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export {
} from './chain';
export { InvalidTxError, sendTransaction } from './send-transaction';
export {
getAddressFromPriv, isAddressValid, genSalt, encodeUnsigned, hash, encodeContractAddress,
isAddressValid, genSalt, encodeUnsigned, hash, encodeContractAddress,
sign, verify, messageToHash, signMessage, verifyMessage, isValidKeypair,
} from './utils/crypto';
export {
Expand Down
11 changes: 0 additions & 11 deletions src/utils/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,6 @@ import {
} from './encoder';
import { ArgumentError } from './errors';

/**
* Generate address from secret key
* @param secret - Private key as hex string
* @returns Public key encoded as address
*/
export function getAddressFromPriv(secret: string | Uint8Array): Encoded.AccountAddress {
const secretBuffer = typeof secret === 'string' ? Buffer.from(secret, 'hex') : secret;
const keys = nacl.sign.keyPair.fromSecretKey(secretBuffer);
return encode(keys.publicKey, Encoding.AccountAddress);
}

/**
* Check if address is valid
* @param maybeAddress - Address to check
Expand Down
6 changes: 1 addition & 5 deletions test/unit/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { describe, it } from 'mocha';
import { assert, expect } from 'chai';
import {
buildTxHash, decode, Encoded,
getAddressFromPriv, verifyMessage, isValidKeypair, isAddressValid, hash, genSalt,
verifyMessage, isValidKeypair, isAddressValid, hash, genSalt,
sign, verify, messageToHash, signMessage, Encoding,
} from '../../src';

Expand Down Expand Up @@ -31,10 +31,6 @@ const txRaw = 'tx_+QTlCwH4QrhA4xEWFIGZUVn0NhnYl9TwGX30YJ9/Y6x6LHU6ALfiupJPORvjbi
const expectedHash = 'th_HZMNgTvEiyKeATpauJjjeWwZcyHapKG8bDgy2S1sCUEUQnbwK';

describe('crypto', () => {
it('Address from secret', () => {
getAddressFromPriv(privateKeyAsHex).should.be.equal(address);
});

describe('isValidKeypair', () => {
it('verify the generated key pair', () => {
const keyPair = {
Expand Down

0 comments on commit 9446639

Please sign in to comment.