Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
0xmaayan committed Feb 27, 2025
1 parent 668bc73 commit 8b1d782
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 57 deletions.
70 changes: 14 additions & 56 deletions src/account/DomainAbstractedAccount.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import { sha3_256, sha3_256 as sha3Hash } from "@noble/hashes/sha3";
import { sha3_256 } from "@noble/hashes/sha3";
import { Serializer } from "../bcs/serializer";
import { AccountAddress, Signature } from "../core";
import {
AccountAuthenticatorAbstraction,
AnyRawTransaction,
generateSigningMessageForTransaction,
} from "../transactions";
import { HexInput, SigningScheme } from "../types";
import { AccountAddress } from "../core/accountAddress";
import { AccountAuthenticatorAbstraction } from "../transactions/authenticator/account";
import { HexInput } from "../types";
import { isValidFunctionInfo } from "../utils/helpers";
import { Account } from "./Account";
import { AbstractPublicKey, AbstractSignature } from "../core/crypto/abstraction";
import { AbstractedAccount } from "./AbstractedAccount";

type DomainAbstractedAccountArgs = {
/**
Expand Down Expand Up @@ -37,55 +32,28 @@ type DomainAbstractedAccountArgs = {
accountIdentity: Uint8Array;
};

export class DomainAbstractedAccount extends Account {
export class DomainAbstractedAccount extends AbstractedAccount {
/**
* The identity of the account.
* Depends on the use cases, most of the time it is the public key of the source wallet
*/
readonly accountIdentity: Uint8Array;

/**
* The address of the account.
* It is computed from the authentication function and the account identity
*/
readonly accountAddress: AccountAddress;

/**
* The authentication function that will be used to verify the signature.
*
* @example
* ```ts
* const authenticationFunction = `${accountAddress}::permissioned_delegation::authenticate`;
* ```
*/
readonly authenticationFunction: string;

/**
* The domain separator used to calculate the DAA account address.
*/
static readonly ADDRESS_DOMAIN_SEPERATOR: number = 5;

/**
* DAA does not have a Public Key, it is here because of the Account inheritance
*/
readonly publicKey: AbstractPublicKey;
/**
* DAA does not have a Signing Scheme (it is based on the provided authentication and signer function),
* it is here because of the Account inheritance
*/
readonly signingScheme = SigningScheme.SingleKey;

constructor({ signer, authenticationFunction, accountIdentity }: DomainAbstractedAccountArgs) {
super();
this.accountIdentity = accountIdentity;
this.authenticationFunction = authenticationFunction;

this.accountAddress = new AccountAddress(
const daAccountAddress = new AccountAddress(
DomainAbstractedAccount.computeAccountAddress(authenticationFunction, accountIdentity),
);
this.sign = (digest: HexInput) => new AbstractSignature(signer(digest));

this.publicKey = new AbstractPublicKey(this.accountAddress);
super({
accountAddress: daAccountAddress,
signer,
authenticationFunction,
});
this.accountIdentity = accountIdentity;
}

/**
Expand All @@ -103,7 +71,7 @@ export class DomainAbstractedAccount extends Account {
}
const [moduleAddress, moduleName, functionName] = functionInfo.split("::");

const hash = sha3Hash.create();
const hash = sha3_256.create();
// Serialize and append the function info
const serializer = new Serializer();
AccountAddress.fromString(moduleAddress).serialize(serializer);
Expand All @@ -122,8 +90,6 @@ export class DomainAbstractedAccount extends Account {
return hash.digest();
}

sign: (message: HexInput) => AbstractSignature;

signWithAuthenticator(message: HexInput): AccountAuthenticatorAbstraction {
return new AccountAuthenticatorAbstraction(
this.authenticationFunction,
Expand All @@ -132,12 +98,4 @@ export class DomainAbstractedAccount extends Account {
this.accountIdentity,
);
}

signTransactionWithAuthenticator(transaction: AnyRawTransaction): AccountAuthenticatorAbstraction {
return this.signWithAuthenticator(generateSigningMessageForTransaction(transaction));
}

signTransaction(transaction: AnyRawTransaction): Signature {
return this.sign(generateSigningMessageForTransaction(transaction));
}
}
2 changes: 1 addition & 1 deletion tests/e2e/api/abstraction.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AbstractedAccount, Account, Hex, MoveVector, Network, UserTransactionResponse } from "../../../src";
import { AbstractedAccount, Account, Hex, MoveVector, Network } from "../../../src";
import { DomainAbstractedAccount } from "../../../src/account/DomainAbstractedAccount";
import { Ed25519Account } from "../../../src/account/Ed25519Account";
import { FUND_AMOUNT } from "../../unit/helper";
Expand Down

0 comments on commit 8b1d782

Please sign in to comment.