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) 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..c2cb43f39 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,11 @@ 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 +39,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..55d0ee7ef 100644 --- a/tests/e2e/api/keyless.test.ts +++ b/tests/e2e/api/keyless.test.ts @@ -2,14 +2,7 @@ // Copyright © Aptos Foundation // SPDX-License-Identifier: Apache-2.0 -import { - Account, - FederatedKeylessAccount, - FederatedKeylessPublicKey, - KeylessAccount, - KeylessPublicKey, - 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"; @@ -127,19 +120,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); },