From ac91b3ca53a9fc1c45792744fc9ac1e4f5606f77 Mon Sep 17 00:00:00 2001 From: Oliver Date: Wed, 9 Oct 2024 00:47:28 -0400 Subject: [PATCH 1/3] Fix the federated keyless constructor --- src/account/AbstractKeylessAccount.ts | 5 +++-- src/account/FederatedKeylessAccount.ts | 5 +++-- src/account/KeylessAccount.ts | 12 ++++++++++-- tests/e2e/api/keyless.test.ts | 13 ++----------- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/account/AbstractKeylessAccount.ts b/src/account/AbstractKeylessAccount.ts index b1893cf46..4b2bdaab3 100644 --- a/src/account/AbstractKeylessAccount.ts +++ b/src/account/AbstractKeylessAccount.ts @@ -96,6 +96,7 @@ export abstract class AbstractKeylessAccount extends Serializable implements Acc // Use the static constructor 'create' instead. protected constructor(args: { address?: AccountAddress; + publicKey: KeylessPublicKey | FederatedKeylessPublicKey; ephemeralKeyPair: EphemeralKeyPair; iss: string; uidKey: string; @@ -107,9 +108,9 @@ export abstract class AbstractKeylessAccount extends Serializable implements Acc jwt: string; }) { super(); - const { address, ephemeralKeyPair, uidKey, uidVal, aud, pepper, proof, proofFetchCallback, jwt } = args; + const { address, ephemeralKeyPair, publicKey, uidKey, uidVal, aud, pepper, proof, proofFetchCallback, jwt } = args; this.ephemeralKeyPair = ephemeralKeyPair; - this.publicKey = KeylessPublicKey.create(args); + this.publicKey = publicKey; this.accountAddress = address ? AccountAddress.from(address) : this.publicKey.authKey().derivedAddress(); this.uidKey = uidKey; this.uidVal = uidVal; diff --git a/src/account/FederatedKeylessAccount.ts b/src/account/FederatedKeylessAccount.ts index 388bc6fc8..1ad8b7aa4 100644 --- a/src/account/FederatedKeylessAccount.ts +++ b/src/account/FederatedKeylessAccount.ts @@ -42,8 +42,9 @@ export class FederatedKeylessAccount extends AbstractKeylessAccount { proofFetchCallback?: ProofFetchCallback; jwt: string; }) { - super(args); - this.publicKey = FederatedKeylessPublicKey.create(args); + const publicKey = FederatedKeylessPublicKey.create(args); + super({ publicKey, ...args }); + this.publicKey = publicKey; } serialize(serializer: Serializer): void { diff --git a/src/account/KeylessAccount.ts b/src/account/KeylessAccount.ts index 526f0d0c0..820d4eaaf 100644 --- a/src/account/KeylessAccount.ts +++ b/src/account/KeylessAccount.ts @@ -4,7 +4,7 @@ import { JwtPayload, jwtDecode } from "jwt-decode"; import { HexInput } from "../types"; import { AccountAddress } from "../core/accountAddress"; -import { ZeroKnowledgeSig } from "../core/crypto"; +import { KeylessPublicKey, ZeroKnowledgeSig } from "../core/crypto"; import { EphemeralKeyPair } from "./EphemeralKeyPair"; import { Deserializer, Serializer } from "../bcs"; @@ -21,6 +21,12 @@ import { AbstractKeylessAccount, ProofFetchCallback } from "./AbstractKeylessAcc * EphemeralKeyPair, and corresponding proof. */ export class KeylessAccount extends AbstractKeylessAccount { + + /** + * The KeylessPublicKey associated with the account + */ + readonly publicKey: KeylessPublicKey + // Use the static constructor 'create' instead. private constructor(args: { address?: AccountAddress; @@ -34,7 +40,9 @@ export class KeylessAccount extends AbstractKeylessAccount { proofFetchCallback?: ProofFetchCallback; jwt: string; }) { - super(args); + const publicKey = KeylessPublicKey.create(args); + super({ publicKey, ...args }); + this.publicKey = publicKey; } serialize(serializer: Serializer): void { diff --git a/tests/e2e/api/keyless.test.ts b/tests/e2e/api/keyless.test.ts index 6ab02e75c..4cd264c8f 100644 --- a/tests/e2e/api/keyless.test.ts +++ b/tests/e2e/api/keyless.test.ts @@ -5,9 +5,7 @@ import { Account, FederatedKeylessAccount, - FederatedKeylessPublicKey, KeylessAccount, - KeylessPublicKey, ProofFetchStatus, } from "../../../src"; import { FUND_AMOUNT, TRANSFER_AMOUNT } from "../../unit/helper"; @@ -127,19 +125,12 @@ describe("keyless api", () => { "creates the keyless account via the static constructor and submits a transaction", async () => { const pepper = await aptos.getPepper({ jwt, ephemeralKeyPair }); - const publicKey = - jwkAddress === undefined - ? KeylessPublicKey.fromJwtAndPepper({ jwt, pepper }) - : FederatedKeylessPublicKey.fromJwtAndPepper({ jwt, pepper, jwkAddress }); - const address = await aptos.lookupOriginalAccountAddress({ - authenticationKey: publicKey.authKey().derivedAddress(), - }); const proof = await aptos.getProof({ jwt, ephemeralKeyPair, pepper }); const account = jwkAddress === undefined - ? KeylessAccount.create({ address, proof, jwt, ephemeralKeyPair, pepper }) - : FederatedKeylessAccount.create({ address, proof, jwt, ephemeralKeyPair, pepper, jwkAddress }); + ? KeylessAccount.create({ proof, jwt, ephemeralKeyPair, pepper }) + : FederatedKeylessAccount.create({ proof, jwt, ephemeralKeyPair, pepper, jwkAddress }); const recipient = Account.generate(); await simpleCoinTransactionHelper(aptos, account, recipient); }, From b3cb11e6d487eb73a28a4b2e2e01adcbeba6926b Mon Sep 17 00:00:00 2001 From: Oliver Date: Wed, 9 Oct 2024 00:48:39 -0400 Subject: [PATCH 2/3] update cl --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e09cb32c..210aa6f8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to the Aptos TypeScript SDK will be captured in this file. This changelog is written by hand for now. It adheres to the format set out by [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). # Unreleased +- Fix the `FederatedKeylessAccount` constructor to derive the correct address. # 1.29.0 (2024-10-04) From 9f85a19b7d2373e051e38eda785c3baf2218de96 Mon Sep 17 00:00:00 2001 From: Oliver Date: Wed, 9 Oct 2024 02:16:32 -0400 Subject: [PATCH 3/3] fmt --- src/account/KeylessAccount.ts | 3 +-- tests/e2e/api/keyless.test.ts | 7 +------ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/account/KeylessAccount.ts b/src/account/KeylessAccount.ts index 820d4eaaf..c2cb43f39 100644 --- a/src/account/KeylessAccount.ts +++ b/src/account/KeylessAccount.ts @@ -21,11 +21,10 @@ import { AbstractKeylessAccount, ProofFetchCallback } from "./AbstractKeylessAcc * EphemeralKeyPair, and corresponding proof. */ export class KeylessAccount extends AbstractKeylessAccount { - /** * The KeylessPublicKey associated with the account */ - readonly publicKey: KeylessPublicKey + readonly publicKey: KeylessPublicKey; // Use the static constructor 'create' instead. private constructor(args: { diff --git a/tests/e2e/api/keyless.test.ts b/tests/e2e/api/keyless.test.ts index 4cd264c8f..55d0ee7ef 100644 --- a/tests/e2e/api/keyless.test.ts +++ b/tests/e2e/api/keyless.test.ts @@ -2,12 +2,7 @@ // Copyright © Aptos Foundation // SPDX-License-Identifier: Apache-2.0 -import { - Account, - FederatedKeylessAccount, - KeylessAccount, - ProofFetchStatus, -} from "../../../src"; +import { Account, FederatedKeylessAccount, KeylessAccount, ProofFetchStatus } from "../../../src"; import { FUND_AMOUNT, TRANSFER_AMOUNT } from "../../unit/helper"; import { getAptosClient } from "../helper"; import { EPHEMERAL_KEY_PAIR, simpleCoinTransactionHeler as simpleCoinTransactionHelper } from "../transaction/helper";