Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default to ed25519 on account creation #43

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions src/core/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,21 @@ export class Account {
/**
* Derives an account with random private key and address
*
* @param args.scheme SigningScheme - type of SigningScheme to use.
* Currently only Ed25519, MultiEd25519, and Secp256k1 are supported
* @param args.scheme optional SigningScheme - type of SigningScheme to use. Default to Ed25519
* Currently only Ed25519 and Secp256k1 are supported
*
* @returns Account
*/
static generate(args: { scheme: SigningScheme }): Account {
const { scheme } = args;
static generate(scheme?: SigningScheme): Account {
let privateKey: PrivateKey;

if (scheme === SigningScheme.Ed25519) {
privateKey = Ed25519PrivateKey.generate();
} else if (scheme === SigningScheme.Secp256k1Ecdsa) {
privateKey = Secp256k1PrivateKey.generate();
} else {
switch (scheme) {
case SigningScheme.Secp256k1Ecdsa:
privateKey = Secp256k1PrivateKey.generate();
break;
// TODO: Add support for MultiEd25519
throw new Error(`Can not generate new Private Key, unsupported signing scheme ${scheme}`);
default:
privateKey = Ed25519PrivateKey.generate();
}

const address = new AccountAddress({
Expand Down
13 changes: 6 additions & 7 deletions tests/e2e/api/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import { Account, Aptos, AptosConfig, Network } from "../../../src";
import { U64 } from "../../../src/bcs/serializable/move-primitives";
import { SigningScheme } from "../../../src/types";
import { sleep } from "../../../src/utils/helpers";
import { INDEXER_WAIT_TIME } from "../../unit/helper";

Expand Down Expand Up @@ -86,9 +85,9 @@ describe("account api", () => {
test("it fetches account transactions", async () => {
const config = new AptosConfig({ network: Network.LOCAL });
const aptos = new Aptos(config);
const senderAccount = Account.generate({ scheme: SigningScheme.Ed25519 });
const senderAccount = Account.generate();
await aptos.fundAccount({ accountAddress: senderAccount.accountAddress.toString(), amount: FUND_AMOUNT });
const bob = Account.generate({ scheme: SigningScheme.Ed25519 });
const bob = Account.generate();
const rawTxn = await aptos.generateTransaction({
sender: senderAccount.accountAddress.toString(),
data: {
Expand All @@ -115,7 +114,7 @@ describe("account api", () => {
test("it fetches account transactions count", async () => {
const config = new AptosConfig({ network: Network.LOCAL });
const aptos = new Aptos(config);
const senderAccount = Account.generate({ scheme: SigningScheme.Ed25519 });
const senderAccount = Account.generate();
const response = await aptos.fundAccount({
accountAddress: senderAccount.accountAddress.toString(),
amount: FUND_AMOUNT,
Expand All @@ -132,7 +131,7 @@ describe("account api", () => {
test("it fetches account coins data", async () => {
const config = new AptosConfig({ network: Network.LOCAL });
const aptos = new Aptos(config);
const senderAccount = Account.generate({ scheme: SigningScheme.Ed25519 });
const senderAccount = Account.generate();
const response = await aptos.fundAccount({
accountAddress: senderAccount.accountAddress.toString(),
amount: FUND_AMOUNT,
Expand All @@ -151,7 +150,7 @@ describe("account api", () => {
test("it fetches account coins count", async () => {
const config = new AptosConfig({ network: Network.LOCAL });
const aptos = new Aptos(config);
const senderAccount = Account.generate({ scheme: SigningScheme.Ed25519 });
const senderAccount = Account.generate();
const response = await aptos.fundAccount({
accountAddress: senderAccount.accountAddress.toString(),
amount: FUND_AMOUNT,
Expand All @@ -168,7 +167,7 @@ describe("account api", () => {
test("lookupOriginalAccountAddress - Look up account address before key rotation", async () => {
const config = new AptosConfig({ network: Network.LOCAL });
const aptos = new Aptos(config);
const account = Account.generate({ scheme: SigningScheme.Ed25519 });
const account = Account.generate();

// Fund and create account onchain
await aptos.fundAccount({ accountAddress: account.accountAddress.toString(), amount: FUND_AMOUNT });
Expand Down
13 changes: 6 additions & 7 deletions tests/e2e/api/coin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ import { AptosConfig, Network, Aptos, Account, Deserializer } from "../../../src
import { waitForTransaction } from "../../../src/internal/transaction";
import { RawTransaction, TransactionPayloadEntryFunction } from "../../../src/transactions/instances";
import { TypeTagStruct } from "../../../src/transactions/typeTag/typeTag";
import { SigningScheme } from "../../../src/types";
import { sleep } from "../../../src/utils/helpers";
import { FUND_AMOUNT, INDEXER_WAIT_TIME } from "../../unit/helper";

describe("coin", () => {
test("it generates a transfer coin transaction with AptosCoin coin type", async () => {
const config = new AptosConfig({ network: Network.LOCAL });
const aptos = new Aptos(config);
const sender = Account.generate({ scheme: SigningScheme.Ed25519 });
const recipient = Account.generate({ scheme: SigningScheme.Ed25519 });
const sender = Account.generate();
const recipient = Account.generate();
await aptos.fundAccount({ accountAddress: sender.accountAddress.toString(), amount: FUND_AMOUNT });

const transaction = await aptos.transferCoinTransaction({
Expand All @@ -31,8 +30,8 @@ describe("coin", () => {
test("it generates a transfer coin transaction with a custom coin type", async () => {
const config = new AptosConfig({ network: Network.LOCAL });
const aptos = new Aptos(config);
const sender = Account.generate({ scheme: SigningScheme.Ed25519 });
const recipient = Account.generate({ scheme: SigningScheme.Ed25519 });
const sender = Account.generate();
const recipient = Account.generate();
await aptos.fundAccount({ accountAddress: sender.accountAddress.toString(), amount: FUND_AMOUNT });

const transaction = await aptos.transferCoinTransaction({
Expand All @@ -53,8 +52,8 @@ describe("coin", () => {
test("it transfers APT coin amount from sender to recipient", async () => {
const config = new AptosConfig({ network: Network.LOCAL });
const aptos = new Aptos(config);
const sender = Account.generate({ scheme: SigningScheme.Ed25519 });
const recipient = Account.generate({ scheme: SigningScheme.Ed25519 });
const sender = Account.generate();
const recipient = Account.generate();

await aptos.fundAccount({ accountAddress: sender.accountAddress.toString(), amount: FUND_AMOUNT });
await sleep(INDEXER_WAIT_TIME);
Expand Down
3 changes: 1 addition & 2 deletions tests/e2e/api/faucet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
// SPDX-License-Identifier: Apache-2.0

import { Aptos, AptosConfig, Account, Network } from "../../../src";
import { SigningScheme } from "../../../src/types";
import { FUND_AMOUNT } from "../../unit/helper";

describe("Faucet", () => {
test("it should fund an account", async () => {
const config = new AptosConfig({ network: Network.LOCAL });
const aptos = new Aptos(config);
const testAccount = Account.generate({ scheme: SigningScheme.Ed25519 });
const testAccount = Account.generate();

// Fund the account
await aptos.fundAccount({ accountAddress: testAccount.accountAddress.toString(), amount: FUND_AMOUNT });
Expand Down
8 changes: 4 additions & 4 deletions tests/e2e/api/transaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ describe("transaction api", () => {
});

test("returns true when transaction is pending", async () => {
const senderAccount = Account.generate({ scheme: SigningScheme.Ed25519 });
const senderAccount = Account.generate();
await aptos.fundAccount({ accountAddress: senderAccount.accountAddress.toString(), amount: FUND_AMOUNT });
const bob = Account.generate({ scheme: SigningScheme.Ed25519 });
const bob = Account.generate();
const rawTxn = await aptos.generateTransaction({
sender: senderAccount.accountAddress.toString(),
data: {
Expand All @@ -47,9 +47,9 @@ describe("transaction api", () => {
describe("fetch transaction queries", () => {
let txn: TransactionResponse;
beforeAll(async () => {
const senderAccount = Account.generate({ scheme: SigningScheme.Ed25519 });
const senderAccount = Account.generate();
await aptos.fundAccount({ accountAddress: senderAccount.accountAddress.toString(), amount: FUND_AMOUNT });
const bob = Account.generate({ scheme: SigningScheme.Ed25519 });
const bob = Account.generate();
const rawTxn = await aptos.generateTransaction({
sender: senderAccount.accountAddress.toString(),
data: {
Expand Down
Loading
Loading