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

Test nested multikey in SDK #572

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
13 changes: 12 additions & 1 deletion src/core/crypto/singleKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { KeylessPublicKey, KeylessSignature } from "./keyless";
import { Signature } from "./signature";
import { FederatedKeylessPublicKey } from "./federatedKeyless";
import { MultiKey, MultiKeySignature } from "./multiKey";

Check failure on line 10 in src/core/crypto/singleKey.ts

View workflow job for this annotation

GitHub Actions / run-tests

Dependency cycle detected

/**
* Represents any public key supported by Aptos.
Expand Down Expand Up @@ -47,7 +48,9 @@
this.variant = AnyPublicKeyVariant.Keyless;
} else if (publicKey instanceof FederatedKeylessPublicKey) {
this.variant = AnyPublicKeyVariant.FederatedKeyless;
} else {
} else if (publicKey instanceof MultiKey) {
this.variant = AnyPublicKeyVariant.MultiKey;
}else {
throw new Error("Unsupported public key type");
}
}
Expand Down Expand Up @@ -139,6 +142,9 @@
case AnyPublicKeyVariant.FederatedKeyless:
publicKey = FederatedKeylessPublicKey.deserialize(deserializer);
break;
case AnyPublicKeyVariant.MultiKey:
publicKey = MultiKey.deserialize(deserializer);
break;
default:
throw new Error(`Unknown variant index for AnyPublicKey: ${variantIndex}`);
}
Expand Down Expand Up @@ -213,6 +219,8 @@
this.variant = AnySignatureVariant.Secp256k1;
} else if (signature instanceof KeylessSignature) {
this.variant = AnySignatureVariant.Keyless;
} else if (signature instanceof MultiKeySignature) {
this.variant = AnySignatureVariant.MultiKey;
} else {
throw new Error("Unsupported signature type");
}
Expand Down Expand Up @@ -254,6 +262,9 @@
case AnySignatureVariant.Keyless:
signature = KeylessSignature.deserialize(deserializer);
break;
case AnySignatureVariant.MultiKey:
signature = MultiKeySignature.deserialize(deserializer);
break;
default:
throw new Error(`Unknown variant index for AnySignature: ${variantIndex}`);
}
Expand Down
2 changes: 2 additions & 0 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export enum AnyPublicKeyVariant {
Secp256k1 = 1,
Keyless = 3,
FederatedKeyless = 4,
MultiKey = 5,
}

/**
Expand All @@ -133,6 +134,7 @@ export enum AnySignatureVariant {
Ed25519 = 0,
Secp256k1 = 1,
Keyless = 3,
MultiKey = 4,
}

/**
Expand Down
47 changes: 47 additions & 0 deletions tests/e2e/transaction/transactionSubmission.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,53 @@
expect(response.signature?.type).toBe("single_sender");
});

test.only("it submits a multi key transaction with nested multi keys", async () => {
const innerMultiKey = new MultiKey({
publicKeys: [
singleSignerED25519SenderAccount.publicKey,
legacyED25519SenderAccount.publicKey,
singleSignerSecp256k1Account.publicKey,
],
signaturesRequired: 1,
});

const mainAccount = Account.generate();
const multiKey = new MultiKey({
publicKeys: [mainAccount.publicKey, innerMultiKey],
signaturesRequired: 2,
});

const backupAccount = new MultiKeyAccount({
multiKey: innerMultiKey,
// the input to signers does not maintain ordering
signers: [singleSignerSecp256k1Account],
});

const account = new MultiKeyAccount({
multiKey,
signers: [mainAccount, backupAccount],
});

await aptos.fundAccount({ accountAddress: account.accountAddress, amount: 100_000_000 });

const transaction = await aptos.transaction.build.simple({
sender: account.accountAddress,
data: {
function: `0x${contractPublisherAccount.accountAddress.toStringWithoutPrefix()}::transfer::transfer`,
functionArguments: [1, receiverAccounts[0].accountAddress],
},
});

const senderAuthenticator = aptos.transaction.sign({ signer: account, transaction });

const response = await aptos.transaction.submit.simple({ transaction, senderAuthenticator });
console.log(response.hash);

Check warning on line 732 in tests/e2e/transaction/transactionSubmission.test.ts

View workflow job for this annotation

GitHub Actions / run-tests

Unexpected console statement
await aptos.waitForTransaction({
transactionHash: response.hash,
});
expect(response.signature?.type).toBe("single_sender");
});

test("it submits a multi key transaction with misordered signers", async () => {
const multiKey = new MultiKey({
publicKeys: [
Expand Down
Loading