Skip to content

Commit

Permalink
refactor: remove originalAddress from AptosAclient
Browse files Browse the repository at this point in the history
  • Loading branch information
jjleng committed Sep 7, 2022
1 parent f0ba01e commit 0db2b59
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 48 deletions.
26 changes: 2 additions & 24 deletions ecosystem/typescript/sdk/src/aptos_account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { Memoize } from "typescript-memoize";
import { bytesToHex } from "./bytes_to_hex.js";
import { HexString, MaybeHexString } from "./hex_string";
import * as Gen from "./generated/index";
import { IAptosClient } from "./common.js";

export interface AptosAccountObject {
address?: Gen.HexEncodedBytes;
Expand All @@ -24,24 +23,13 @@ export class AptosAccount {
/**
* A private key and public key, associated with the given account
*/
private signingKeyInternal: Nacl.SignKeyPair;
readonly signingKey: Nacl.SignKeyPair;

/**
* Address associated with the given account
*/
private readonly accountAddress: HexString;

private client?: IAptosClient;

get signingKey() {
return this.signingKeyInternal;
}

/** @internal */
set signingKey(keyPair: Nacl.SignKeyPair) {
this.signingKeyInternal = keyPair;
}

static fromAptosAccountObject(obj: AptosAccountObject): AptosAccount {
return new AptosAccount(HexString.ensure(obj.privateKeyHex).toUint8Array(), obj.address);
}
Expand Down Expand Up @@ -85,17 +73,15 @@ export class AptosAccount {
* @param privateKeyBytes Private key from which account key pair will be generated.
* If not specified, new key pair is going to be created.
* @param address Account address (e.g. 0xe8012714cd17606cee7188a2a365eef3fe760be598750678c8c5954eb548a591).
* @param client
* If not specified, a new one will be generated from public key
*/
constructor(privateKeyBytes?: Uint8Array | undefined, address?: MaybeHexString, client?: IAptosClient) {
constructor(privateKeyBytes?: Uint8Array | undefined, address?: MaybeHexString) {
if (privateKeyBytes) {
this.signingKey = Nacl.sign.keyPair.fromSeed(privateKeyBytes.slice(0, 32));
} else {
this.signingKey = Nacl.sign.keyPair();
}
this.accountAddress = HexString.ensure(address || this.authKey().hex());
this.client = client;
}

/**
Expand All @@ -108,14 +94,6 @@ export class AptosAccount {
return this.accountAddress;
}

/**
* Lookup the original address by current account's auth key
* @returns
*/
async originalAddress(): Promise<HexString> {
return this.client.lookupOriginalAddress(this.authKey());
}

/**
* This key enables account owners to rotate their private key(s)
* associated with the account without changing the address that hosts their account.
Expand Down
4 changes: 1 addition & 3 deletions ecosystem/typescript/sdk/src/aptos_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ import {
TransactionBuilderRemoteABI,
RemoteABIBuilderConfig,
} from "./transaction_builder";
import { IAptosClient } from "./common";

/**
* Provides methods for retrieving data from Aptos node.
* For more detailed API specification see {@link https://fullnode.devnet.aptoslabs.com/v1/spec}
*/
export class AptosClient extends IAptosClient {
export class AptosClient {
client: Gen.AptosGeneratedClient;

/**
Expand All @@ -33,7 +32,6 @@ export class AptosClient extends IAptosClient {
* @param config Additional configuration options for the generated Axios client.
*/
constructor(nodeUrl: string, config?: Partial<Gen.OpenAPIConfig>, doNotFixNodeUrl: boolean = false) {
super();
if (!nodeUrl) {
throw new Error("Node URL cannot be empty.");
}
Expand Down
17 changes: 0 additions & 17 deletions ecosystem/typescript/sdk/src/common.ts

This file was deleted.

12 changes: 10 additions & 2 deletions ecosystem/typescript/sdk/src/transaction_builder/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import { ArgumentABI, EntryFunctionABI, ScriptABI, TransactionScriptABI, TypeArg
import { HexString, MaybeHexString } from "../hex_string";
import { argToTransactionArgument, TypeTagParser, serializeArg } from "./builder_utils";
import * as Gen from "../generated/index";
import { IAptosClient } from "../common";

export { TypeTagParser } from "./builder_utils.js";

Expand Down Expand Up @@ -308,13 +307,22 @@ export type RemoteABIBuilderConfig = Partial<Omit<ABIBuilderConfig, "sender">> &
sender: MaybeHexString | AccountAddress;
};

interface AptosClientInterface {
getAccountModules: (accountAddress: MaybeHexString) => Promise<Gen.MoveModuleBytecode[]>;
getAccount: (accountAddress: MaybeHexString) => Promise<Gen.AccountData>;
getChainId: () => Promise<number>;
}

/**
* This transaction builder downloads JSON ABIs from the fullnodes.
* It then translates the JSON ABIs to the format that is accepted by TransactionBuilderABI
*/
export class TransactionBuilderRemoteABI {
// We don't want the builder to depend on the actual AptosClient. There might be circular dependencies.
constructor(private readonly aptosClient: IAptosClient, private readonly builderConfig: RemoteABIBuilderConfig) {}
constructor(
private readonly aptosClient: AptosClientInterface,
private readonly builderConfig: RemoteABIBuilderConfig,
) {}

// Cache for 10 minutes
@MemoizeExpiring(10 * 60 * 1000)
Expand Down
3 changes: 1 addition & 2 deletions ecosystem/typescript/sdk/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"outDir": "./dist",
"sourceMap": true,
"target": "es2020",
"pretty": true,
"stripInternal":true
"pretty": true
},
"include": ["src"]
}

0 comments on commit 0db2b59

Please sign in to comment.