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

Create input submit transaction interface type #165

Merged
merged 2 commits into from
Nov 2, 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
10 changes: 2 additions & 8 deletions src/api/transactionSubmission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
InputSingleSignerTransaction,
InputSimulateTransactionData,
InputGenerateTransactionOptions,
InputSubmitTransactionData,
} from "../transactions/types";
import { UserTransactionResponse, PendingTransactionResponse, HexInput, TransactionResponse } from "../types";
import {
Expand Down Expand Up @@ -131,14 +132,7 @@ export class TransactionSubmission {
*
* @return PendingTransactionResponse
*/
async submitTransaction(args: {
transaction: AnyRawTransaction;
senderAuthenticator: AccountAuthenticator;
secondarySignerAuthenticators?: {
feePayerAuthenticator?: AccountAuthenticator;
additionalSignersAuthenticators?: Array<AccountAuthenticator>;
};
}): Promise<PendingTransactionResponse> {
async submitTransaction(args: InputSubmitTransactionData): Promise<PendingTransactionResponse> {
return submitTransaction({ aptosConfig: this.config, ...args });
}

Expand Down
4 changes: 1 addition & 3 deletions src/core/crypto/secp256k1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,7 @@ export class Secp256k1PrivateKey extends PrivateKey {
* @returns The generated key
*/
private static fromDerivationPathInner(path: string, seed: Uint8Array): Secp256k1PrivateKey {
const { privateKey, publicKey } = HDKey.fromMasterSeed(seed).derive(path);
console.log(privateKey);
console.log(publicKey);
const { privateKey } = HDKey.fromMasterSeed(seed).derive(path);
// library returns privateKey as Uint8Array | null
if (privateKey === null) {
throw new Error("Invalid key");
Expand Down
15 changes: 6 additions & 9 deletions src/internal/transactionSubmission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
InputGenerateTransactionOptions,
InputSingleSignerTransaction,
InputGenerateTransactionPayloadDataWithRemoteABI,
InputSubmitTransactionData,
} from "../transactions/types";
import { UserTransactionResponse, PendingTransactionResponse, MimeType, HexInput, TransactionResponse } from "../types";
import { getInfo } from "./account";
Expand Down Expand Up @@ -173,15 +174,11 @@ export async function simulateTransaction(
*
* @return PendingTransactionResponse
*/
export async function submitTransaction(args: {
aptosConfig: AptosConfig;
transaction: AnyRawTransaction;
senderAuthenticator: AccountAuthenticator;
secondarySignerAuthenticators?: {
feePayerAuthenticator?: AccountAuthenticator;
additionalSignersAuthenticators?: Array<AccountAuthenticator>;
};
}): Promise<PendingTransactionResponse> {
export async function submitTransaction(
args: {
aptosConfig: AptosConfig;
} & InputSubmitTransactionData,
): Promise<PendingTransactionResponse> {
const { aptosConfig } = args;
const signedTransaction = generateSignedTransaction({ ...args });
const { data } = await postAptosFullNode<Uint8Array, PendingTransactionResponse>({
Expand Down
37 changes: 14 additions & 23 deletions src/transactions/transactionBuilder/transactionBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,28 @@ import {
} from "../instances";
import { SignedTransaction } from "../instances/signedTransaction";
import {
InputGenerateTransactionOptions,
AnyRawTransaction,
AnyTransactionPayloadInstance,
AnyRawTransactionInstance,
EntryFunctionArgumentTypes,
EntryFunctionABI,
InputGenerateFeePayerRawTransactionArgs,
InputGenerateMultiAgentRawTransactionArgs,
InputGenerateRawTransactionArgs,
InputGenerateSingleSignerRawTransactionArgs,
InputSingleSignerTransaction,
AnyRawTransaction,
InputGenerateTransactionOptions,
InputFeePayerTransaction,
InputMultiAgentTransaction,
InputScriptData,
InputSimulateTransactionData,
EntryFunctionArgumentTypes,
EntryFunctionABI,
InputGenerateTransactionPayloadData,
InputEntryFunctionData,
InputMultiSigData,
InputMultiSigDataWithRemoteABI,
InputEntryFunctionDataWithRemoteABI,
InputGenerateTransactionPayloadDataWithRemoteABI,
InputSubmitTransactionData,
} from "../types";
import { convertArgument, fetchEntryFunctionAbi, standardizeTypeTags } from "./remoteAbi";
import { memoizeAsync } from "../../utils/memoize";
Expand Down Expand Up @@ -474,23 +475,17 @@ export function sign(args: { signer: Account; transaction: AnyRawTransaction }):
*
* @returns A SignedTransaction
*/
export function generateSignedTransaction(args: {
transaction: AnyRawTransaction;
senderAuthenticator: AccountAuthenticator;
secondarySignerAuthenticators?: {
feePayerAuthenticator?: AccountAuthenticator;
additionalSignersAuthenticators?: Array<AccountAuthenticator>;
};
}): Uint8Array {
const { transaction, senderAuthenticator, secondarySignerAuthenticators } = args;
export function generateSignedTransaction(args: InputSubmitTransactionData): Uint8Array {
const { transaction, senderAuthenticator, feePayerAuthenticator, additionalSignersAuthenticators } = args;

const transactionToSubmit = deriveTransactionType(transaction);

if (secondarySignerAuthenticators) {
if (feePayerAuthenticator || additionalSignersAuthenticators) {
return generateMultiSignersSignedTransaction(
transactionToSubmit as MultiAgentRawTransaction | FeePayerRawTransaction,
senderAuthenticator,
secondarySignerAuthenticators,
feePayerAuthenticator,
additionalSignersAuthenticators,
);
}

Expand Down Expand Up @@ -555,16 +550,13 @@ export function deriveTransactionType(transaction: AnyRawTransaction): AnyRawTra
export function generateMultiSignersSignedTransaction(
transaction: MultiAgentRawTransaction | FeePayerRawTransaction,
senderAuthenticator: AccountAuthenticator,
secondarySignerAuthenticators: {
feePayerAuthenticator?: AccountAuthenticator;
additionalSignersAuthenticators?: Array<AccountAuthenticator>;
},
feePayerAuthenticator?: AccountAuthenticator,
additionalSignersAuthenticators?: Array<AccountAuthenticator>,
) {
if (transaction instanceof FeePayerRawTransaction) {
if (!secondarySignerAuthenticators.feePayerAuthenticator) {
if (!feePayerAuthenticator) {
throw new Error("Must provide a feePayerAuthenticator argument to generate a signed fee payer transaction");
}
const { feePayerAuthenticator, additionalSignersAuthenticators } = secondarySignerAuthenticators;
const txAuthenticatorFeePayer = new TransactionAuthenticatorFeePayer(
senderAuthenticator,
transaction.secondary_signer_addresses,
Expand All @@ -577,12 +569,11 @@ export function generateMultiSignersSignedTransaction(
return new SignedTransaction(transaction.raw_txn, txAuthenticatorFeePayer).bcsToBytes();
}
if (transaction instanceof MultiAgentRawTransaction) {
if (!secondarySignerAuthenticators.additionalSignersAuthenticators) {
if (!additionalSignersAuthenticators) {
throw new Error(
"Must provide a additionalSignersAuthenticators argument to generate a signed multi agent transaction",
);
}
const { additionalSignersAuthenticators } = secondarySignerAuthenticators;
const multiAgentAuthenticator = new TransactionAuthenticatorMultiAgent(
senderAuthenticator,
transaction.secondary_signer_addresses,
Expand Down
11 changes: 11 additions & 0 deletions src/transactions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
} from "./instances";
import { AnyNumber, HexInput, MoveFunctionGenericTypeParam, MoveStructType } from "../types";
import { TypeTag } from "./typeTag";
import { AccountAuthenticator } from "./authenticator/account";

/**
* Entry function arguments to be used when building a raw transaction using remote ABI
Expand Down Expand Up @@ -301,3 +302,13 @@ export type InputGenerateTransactionData =
| InputGenerateMultiAgentRawTransactionData
| InputGenerateFeePayerRawTransactionData
| InputGenerateSingleSignerRawTransactionData;

/**
* Interface that holds the user data input when submitting a transaction
*/
export interface InputSubmitTransactionData {
transaction: AnyRawTransaction;
senderAuthenticator: AccountAuthenticator;
feePayerAuthenticator?: AccountAuthenticator;
additionalSignersAuthenticators?: Array<AccountAuthenticator>;
}
6 changes: 2 additions & 4 deletions tests/e2e/transaction/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,8 @@ export const rawTransactionMultiAgentHelper = async (
const transactionResponse = await aptos.submitTransaction({
transaction: generatedTransaction,
senderAuthenticator,
secondarySignerAuthenticators: {
additionalSignersAuthenticators: secondaryAuthenticators,
feePayerAuthenticator,
},
additionalSignersAuthenticators: secondaryAuthenticators,
feePayerAuthenticator,
});

const response = await aptos.waitForTransaction({
Expand Down
8 changes: 2 additions & 6 deletions tests/e2e/transaction/transactionBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,7 @@ describe("transaction builder", () => {
const bcsTransaction = await generateSignedTransaction({
transaction,
senderAuthenticator: authenticator,
secondarySignerAuthenticators: {
additionalSignersAuthenticators: [secondaryAuthenticator],
},
additionalSignersAuthenticators: [secondaryAuthenticator],
});
expect(bcsTransaction instanceof Uint8Array).toBeTruthy();
const deserializer = new Deserializer(bcsTransaction);
Expand Down Expand Up @@ -509,9 +507,7 @@ describe("transaction builder", () => {
const bcsTransaction = await generateSignedTransaction({
transaction,
senderAuthenticator: authenticator,
secondarySignerAuthenticators: {
feePayerAuthenticator,
},
feePayerAuthenticator,
});
expect(bcsTransaction instanceof Uint8Array).toBeTruthy();
const deserializer = new Deserializer(bcsTransaction);
Expand Down
42 changes: 18 additions & 24 deletions tests/e2e/transaction/transactionSubmission.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe("transaction submission", () => {
const response = await aptos.submitTransaction({
transaction,
senderAuthenticator,
secondarySignerAuthenticators: { additionalSignersAuthenticators: [secondarySignerAuthenticator] },
additionalSignersAuthenticators: [secondarySignerAuthenticator],
});

await waitForTransaction({
Expand Down Expand Up @@ -141,7 +141,7 @@ describe("transaction submission", () => {
const response = await aptos.submitTransaction({
transaction,
senderAuthenticator,
secondarySignerAuthenticators: { additionalSignersAuthenticators: [secondarySignerAuthenticator] },
additionalSignersAuthenticators: [secondarySignerAuthenticator],
});

await waitForTransaction({
Expand Down Expand Up @@ -170,7 +170,7 @@ describe("transaction submission", () => {
const response = await aptos.submitTransaction({
transaction,
senderAuthenticator,
secondarySignerAuthenticators: { feePayerAuthenticator: feePayerSignerAuthenticator },
feePayerAuthenticator: feePayerSignerAuthenticator,
});

await waitForTransaction({
Expand All @@ -194,7 +194,7 @@ describe("transaction submission", () => {
const response = await aptos.submitTransaction({
transaction,
senderAuthenticator,
secondarySignerAuthenticators: { feePayerAuthenticator: feePayerSignerAuthenticator },
feePayerAuthenticator: feePayerSignerAuthenticator,
});

await waitForTransaction({
Expand Down Expand Up @@ -227,10 +227,8 @@ describe("transaction submission", () => {
const response = await aptos.submitTransaction({
transaction,
senderAuthenticator,
secondarySignerAuthenticators: {
additionalSignersAuthenticators: [secondarySignerAuthenticator],
feePayerAuthenticator: feePayerSignerAuthenticator,
},
additionalSignersAuthenticators: [secondarySignerAuthenticator],
feePayerAuthenticator: feePayerSignerAuthenticator,
});

await waitForTransaction({
Expand Down Expand Up @@ -303,7 +301,7 @@ describe("transaction submission", () => {
const response = await aptos.submitTransaction({
transaction,
senderAuthenticator,
secondarySignerAuthenticators: { additionalSignersAuthenticators: [secondarySignerAuthenticator] },
additionalSignersAuthenticators: [secondarySignerAuthenticator],
});

await waitForTransaction({
Expand Down Expand Up @@ -337,7 +335,7 @@ describe("transaction submission", () => {
const response = await aptos.submitTransaction({
transaction,
senderAuthenticator,
secondarySignerAuthenticators: { additionalSignersAuthenticators: [secondarySignerAuthenticator] },
additionalSignersAuthenticators: [secondarySignerAuthenticator],
});

await waitForTransaction({
Expand Down Expand Up @@ -366,7 +364,7 @@ describe("transaction submission", () => {
const response = await aptos.submitTransaction({
transaction,
senderAuthenticator,
secondarySignerAuthenticators: { feePayerAuthenticator: feePayerSignerAuthenticator },
feePayerAuthenticator: feePayerSignerAuthenticator,
});

await waitForTransaction({
Expand All @@ -390,7 +388,7 @@ describe("transaction submission", () => {
const response = await aptos.submitTransaction({
transaction,
senderAuthenticator,
secondarySignerAuthenticators: { feePayerAuthenticator: feePayerSignerAuthenticator },
feePayerAuthenticator: feePayerSignerAuthenticator,
});

await waitForTransaction({
Expand Down Expand Up @@ -423,10 +421,8 @@ describe("transaction submission", () => {
const response = await aptos.submitTransaction({
transaction,
senderAuthenticator,
secondarySignerAuthenticators: {
additionalSignersAuthenticators: [secondarySignerAuthenticator],
feePayerAuthenticator: feePayerSignerAuthenticator,
},
additionalSignersAuthenticators: [secondarySignerAuthenticator],
feePayerAuthenticator: feePayerSignerAuthenticator,
});

await waitForTransaction({
Expand Down Expand Up @@ -499,7 +495,7 @@ describe("transaction submission", () => {
const response = await aptos.submitTransaction({
transaction,
senderAuthenticator,
secondarySignerAuthenticators: { additionalSignersAuthenticators: [secondarySignerAuthenticator] },
additionalSignersAuthenticators: [secondarySignerAuthenticator],
});

await waitForTransaction({
Expand Down Expand Up @@ -533,7 +529,7 @@ describe("transaction submission", () => {
const response = await aptos.submitTransaction({
transaction,
senderAuthenticator,
secondarySignerAuthenticators: { additionalSignersAuthenticators: [secondarySignerAuthenticator] },
additionalSignersAuthenticators: [secondarySignerAuthenticator],
});

await waitForTransaction({
Expand Down Expand Up @@ -562,7 +558,7 @@ describe("transaction submission", () => {
const response = await aptos.submitTransaction({
transaction,
senderAuthenticator,
secondarySignerAuthenticators: { feePayerAuthenticator: feePayerSignerAuthenticator },
feePayerAuthenticator: feePayerSignerAuthenticator,
});

await waitForTransaction({
Expand All @@ -586,7 +582,7 @@ describe("transaction submission", () => {
const response = await aptos.submitTransaction({
transaction,
senderAuthenticator,
secondarySignerAuthenticators: { feePayerAuthenticator: feePayerSignerAuthenticator },
feePayerAuthenticator: feePayerSignerAuthenticator,
});

await waitForTransaction({
Expand Down Expand Up @@ -619,10 +615,8 @@ describe("transaction submission", () => {
const response = await aptos.submitTransaction({
transaction,
senderAuthenticator,
secondarySignerAuthenticators: {
additionalSignersAuthenticators: [secondarySignerAuthenticator],
feePayerAuthenticator: feePayerSignerAuthenticator,
},
additionalSignersAuthenticators: [secondarySignerAuthenticator],
feePayerAuthenticator: feePayerSignerAuthenticator,
});

await waitForTransaction({
Expand Down
Loading