Skip to content

Commit

Permalink
Removes batched intents in favor of script composer
Browse files Browse the repository at this point in the history
  • Loading branch information
kaw2k committed Dec 19, 2024
1 parent 27b49e3 commit d7e7a56
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 149 deletions.
20 changes: 0 additions & 20 deletions src/api/transactionSubmission/build.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

import { get_wasm, initSync } from "@wgb5445/aptos-intent-npm";
import { AccountAddressInput } from "../../core";
import { generateTransaction } from "../../internal/transactionSubmission";
import { AptosScriptComposer } from "../../transactions";
Expand All @@ -12,7 +11,6 @@ import { Deserializer } from "../../bcs";
import { InputGenerateTransactionOptions, InputGenerateTransactionPayloadData } from "../../transactions/types";
import { generateRawTransaction } from "../../transactions/transactionBuilder/transactionBuilder";
import { TransactionPayloadScript } from "../../transactions/instances/transactionPayload";
import { AptosIntentBuilder } from "../../transactions/intent";

/**
* A class to handle all `Build` transaction operations.
Expand Down Expand Up @@ -102,24 +100,6 @@ export class Build {
return generateTransaction({ aptosConfig: this.config, ...args });
}

async batched_intents(args: {
sender: AccountAddressInput;
builder: (builder: AptosIntentBuilder) => Promise<AptosIntentBuilder>;
options?: InputGenerateTransactionOptions;
withFeePayer?: boolean;
}): Promise<SimpleTransaction> {
initSync(await get_wasm());
let builder = new AptosIntentBuilder(this.config);
builder = await args.builder(builder);
const bytes = builder.build();
const rawTxn = await generateRawTransaction({
aptosConfig: this.config,
payload: TransactionPayloadScript.load(new Deserializer(bytes)),
...args,
});
return new SimpleTransaction(rawTxn);
}

/**
* Build a transaction from a series of Move calls.
*
Expand Down
2 changes: 1 addition & 1 deletion src/core/crypto/ed25519.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { AuthenticationKey } from "../authenticationKey";
import { Hex } from "../hex";
import { HexInput, SigningScheme as AuthenticationKeyScheme, PrivateKeyVariants } from "../../types";
import { CKDPriv, deriveKey, HARDENED_OFFSET, isValidHardenedPath, mnemonicToSeed, splitPath } from "./hdKey";
import type { PrivateKey } from "./privateKey";
import { PrivateKey } from "./privateKey";
import type { VerifySignatureArgs } from "./publicKey";
import { AccountPublicKey, PublicKey } from "./publicKey";
import { Signature } from "./signature";
Expand Down
54 changes: 27 additions & 27 deletions src/internal/permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
* name namespace and without having a dependency cycle error.
*/

import { BatchArgument } from "@wgb5445/aptos-intent-npm";
import { CallArgument } from "@aptos-labs/script-composer-pack";
import { AptosConfig } from "../api/aptosConfig";
import { AccountAddress, Ed25519PublicKey } from "../core";
import { SimpleTransaction } from "../transactions/instances/simpleTransaction";
import { MoveString } from "../bcs";
import { AptosIntentBuilder } from "../transactions";
import { MoveVMPermissionType, Permission, FungibleAssetPermission, NFTPermission } from "../types/permissions";
import { Transaction } from "../api/transaction";
import { view } from "./view";
import { AptosScriptComposer } from "../transactions";

// functions
export async function getPermissions<T extends Permission>({
Expand Down Expand Up @@ -89,7 +89,7 @@ export async function requestPermission(args: {
subAccountPublicKey: permissionedAccountPublicKey,
});

return transaction.build.batched_intents({
return transaction.build.scriptComposer({
sender: primaryAccountAddress,
builder: async (builder) => {
// Get the permissioned signer - either create new one or use existing
Expand Down Expand Up @@ -157,26 +157,26 @@ export async function revokePermissions(args: {
const { aptosConfig, primaryAccountAddress, subAccountPublicKey, permissions } = args;

const transaction = new Transaction(aptosConfig);
return transaction.build.batched_intents({
return transaction.build.scriptComposer({
sender: primaryAccountAddress,
builder: async (builder) => {
const signer = await builder.add_batched_calls({
const signer = await builder.addBatchedCalls({
function: "0x1::permissioned_delegation::permissioned_signer_by_key",
functionArguments: [BatchArgument.new_signer(0), subAccountPublicKey.toUint8Array()],
functionArguments: [CallArgument.new_signer(0), subAccountPublicKey.toUint8Array()],
typeArguments: [],
});

const permissionPromises = permissions.map((permission) => {
if (permission instanceof FungibleAssetPermission) {
return builder.add_batched_calls({
return builder.addBatchedCalls({
function: "0x1::fungible_asset::revoke_permission",
functionArguments: [signer[0].borrow(), permission.asset],
typeArguments: [],
});
}
// TODO: object nft revoke
if (permission instanceof NFTPermission) {
return builder.add_batched_calls({
return builder.addBatchedCalls({
function: "0x1::object::revoke_permission",
functionArguments: [signer[0].borrow(), permission.assetAddress],
typeArguments: ["0x4::token::Token"],
Expand All @@ -195,29 +195,29 @@ export async function revokePermissions(args: {

// helper functions
async function getPermissionedSigner(
builder: AptosIntentBuilder,
builder: AptosScriptComposer,
args: {
existingHandleAddress: string | null;
permissionedAccountPublicKey: Ed25519PublicKey;
},
) {
if (args.existingHandleAddress) {
const signer = await builder.add_batched_calls({
const signer = await builder.addBatchedCalls({
function: "0x1::permissioned_delegation::permissioned_signer_by_key",
functionArguments: [BatchArgument.new_signer(0), args.permissionedAccountPublicKey.toUint8Array()],
functionArguments: [CallArgument.new_signer(0), args.permissionedAccountPublicKey.toUint8Array()],
typeArguments: [],
});
return { signer, isNewHandle: false };
}

// Create new handle and signer
const handle = await builder.add_batched_calls({
const handle = await builder.addBatchedCalls({
function: "0x1::permissioned_signer::create_storable_permissioned_handle",
functionArguments: [BatchArgument.new_signer(0), 360],
functionArguments: [CallArgument.new_signer(0), 360],
typeArguments: [],
});

const signer = await builder.add_batched_calls({
const signer = await builder.addBatchedCalls({
function: "0x1::permissioned_signer::signer_from_storable_permissioned",
functionArguments: [handle[0].borrow()],
typeArguments: [],
Expand All @@ -227,17 +227,17 @@ async function getPermissionedSigner(
}

async function grantPermission(
builder: AptosIntentBuilder,
builder: AptosScriptComposer,
args: {
permissionedSigner: BatchArgument[];
permissionedSigner: CallArgument[];
permission: Permission;
},
) {
if (args.permission instanceof FungibleAssetPermission) {
return builder.add_batched_calls({
return builder.addBatchedCalls({
function: "0x1::fungible_asset::grant_permission",
functionArguments: [
BatchArgument.new_signer(0),
CallArgument.new_signer(0),
args.permissionedSigner[0].borrow(),
args.permission.asset,
args.permission.amount,
Expand All @@ -246,12 +246,12 @@ async function grantPermission(
});
}
if (args.permission instanceof NFTPermission) {
const txn: Promise<BatchArgument[]>[] = [];
const txn: Promise<CallArgument[]>[] = [];
if (args.permission.capabilities.transfer) {
return builder.add_batched_calls({
return builder.addBatchedCalls({
function: "0x1::object::grant_permission",
functionArguments: [
BatchArgument.new_signer(0),
CallArgument.new_signer(0),
args.permissionedSigner[0].borrow(),
args.permission.assetAddress,
],
Expand All @@ -271,22 +271,22 @@ async function grantPermission(
}

async function finalizeNewHandle(
builder: AptosIntentBuilder,
builder: AptosScriptComposer,
args: {
permissionedAccountPublicKey: Ed25519PublicKey;
handle: BatchArgument[];
handle: CallArgument[];
},
) {
await builder.add_batched_calls({
await builder.addBatchedCalls({
function: "0x1::permissioned_delegation::add_permissioned_handle",
functionArguments: [BatchArgument.new_signer(0), args.permissionedAccountPublicKey.toUint8Array(), args.handle[0]],
functionArguments: [CallArgument.new_signer(0), args.permissionedAccountPublicKey.toUint8Array(), args.handle[0]],
typeArguments: [],
});

await builder.add_batched_calls({
await builder.addBatchedCalls({
function: "0x1::lite_account::add_dispatchable_authentication_function",
functionArguments: [
BatchArgument.new_signer(0),
CallArgument.new_signer(0),
AccountAddress.ONE,
new MoveString("permissioned_delegation"),
new MoveString("authenticate"),
Expand Down
1 change: 0 additions & 1 deletion src/transactions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ export * from "./typeTag";
export * from "./typeTag/parser";
export * from "./types";
export * from "./script-composer";
export * from "./intent";
68 changes: 0 additions & 68 deletions src/transactions/intent/index.ts

This file was deleted.

29 changes: 0 additions & 29 deletions src/transactions/transactionBuilder/remoteAbi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,35 +124,6 @@ export async function fetchMoveFunctionAbi(
};
}

/**
* Fetches the ABI for an entry function from the specified module address.
* This function validates if the ABI corresponds to an entry function and retrieves its parameters.
* @param moduleAddress
* @param moduleName
* @param functionName
* @param aptosConfig
*/
export async function fetchMoveFunctionAbi(
moduleAddress: string,
moduleName: string,
functionName: string,
aptosConfig: AptosConfig,
): Promise<FunctionABI> {
const functionAbi = await fetchFunctionAbi(moduleAddress, moduleName, functionName, aptosConfig);
if (!functionAbi) {
throw new Error(`Could not find entry function ABI for '${moduleAddress}::${moduleName}::${functionName}'`);
}
const params: TypeTag[] = [];
for (let i = 0; i < functionAbi.params.length; i += 1) {
params.push(parseTypeTag(functionAbi.params[i], { allowGenerics: true }));
}

return {
typeParameters: functionAbi.generic_type_params,
parameters: params,
};
}

/**
* Fetches the ABI for an entry function from the module
*
Expand Down
3 changes: 0 additions & 3 deletions tests/e2e/transaction/transactionSubmission.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

import { BatchArgument, get_wasm, initSync } from "@wgb5445/aptos-intent-npm";
import {
Account,
U64,
Expand All @@ -24,14 +23,12 @@ import { longTestTimeout } from "../../unit/helper";
import { getAptosClient } from "../helper";
import { fundAccounts, multiSignerScriptBytecode, publishTransferPackage, singleSignerScriptBytecode } from "./helper";
import { AccountAuthenticatorNoAccountAuthenticator } from "../../../src/transactions";
import { AbstractedEd25519Account } from "../../../src/account/AbstractedAccount";

const { aptos } = getAptosClient();

describe("transaction submission", () => {
const contractPublisherAccount = Account.generate();
const singleSignerED25519SenderAccount = Account.generate({ scheme: SigningSchemeInput.Ed25519, legacy: false });
const singleSignerAbstractionSenderAccount = AbstractedEd25519Account.generate();
const legacyED25519SenderAccount = Account.generate();
const receiverAccounts = [Account.generate(), Account.generate()];
const singleSignerSecp256k1Account = Account.generate({ scheme: SigningSchemeInput.Secp256k1Ecdsa });
Expand Down

0 comments on commit d7e7a56

Please sign in to comment.