Skip to content

Commit 04e45a4

Browse files
committed
add corresponding getEffectiveAuditorHint function
1 parent 15e01f4 commit 04e45a4

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

confidential-assets/src/api/confidentialAsset.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
ConfidentialAssetTransactionBuilder,
1919
ConfidentialBalance,
2020
getBalance,
21+
getEffectiveAuditorHint,
2122
getEncryptionKey,
2223
hasUserRegistered,
2324
isBalanceNormalized,
@@ -478,6 +479,27 @@ export class ConfidentialAsset {
478479
});
479480
}
480481

482+
/**
483+
* Get the effective auditor hint for a user's confidential store.
484+
* Indicates which auditor (global vs asset-specific) and epoch the balance ciphertext is encrypted for.
485+
*
486+
* @param args.accountAddress - The account address to query
487+
* @param args.tokenAddress - The token address of the asset
488+
* @param args.options - Optional ledger version for the view call
489+
* @returns The auditor hint, or undefined if no auditor hint is set
490+
*/
491+
async getEffectiveAuditorHint(args: {
492+
accountAddress: AccountAddressInput;
493+
tokenAddress: AccountAddressInput;
494+
options?: LedgerVersionArg;
495+
}): Promise<{ isGlobal: boolean; epoch: bigint } | undefined> {
496+
return getEffectiveAuditorHint({
497+
client: this.client(),
498+
moduleAddress: this.moduleAddress(),
499+
...args,
500+
});
501+
}
502+
481503
/**
482504
* Normalize a user's balance.
483505
*

confidential-assets/src/internal/viewFunctions.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,44 @@ export async function hasUserRegistered(args: ViewFunctionParams): Promise<boole
257257
* @returns The encryption key as a TwistedEd25519PublicKey
258258
* @throws {Error} If the encryption key cannot be retrieved
259259
*/
260+
/**
261+
* Response type for the effective auditor hint view function.
262+
* Mirrors Move's `Option<EffectiveAuditorHint::V1 { is_global: bool, epoch: u64 }>`.
263+
*/
264+
export type EffectiveAuditorHintResponse = {
265+
vec: { is_global: boolean; epoch: string }[];
266+
};
267+
268+
/**
269+
* Get the effective auditor hint for a user's confidential store.
270+
* Indicates which auditor (global vs asset-specific) and epoch the balance ciphertext is encrypted for.
271+
*
272+
* @returns The auditor hint, or undefined if no auditor hint is set (e.g., balance is zero or no auditor was active).
273+
*/
274+
export async function getEffectiveAuditorHint(
275+
args: ViewFunctionParams,
276+
): Promise<{ isGlobal: boolean; epoch: bigint } | undefined> {
277+
const {
278+
client,
279+
accountAddress,
280+
tokenAddress,
281+
options,
282+
moduleAddress = DEFAULT_CONFIDENTIAL_COIN_MODULE_ADDRESS,
283+
} = args;
284+
const [hint] = await client.view<[EffectiveAuditorHintResponse]>({
285+
options,
286+
payload: {
287+
function: `${moduleAddress}::${MODULE_NAME}::get_effective_auditor_hint`,
288+
typeArguments: [],
289+
functionArguments: [accountAddress, tokenAddress],
290+
},
291+
});
292+
if (hint.vec.length === 0) {
293+
return undefined;
294+
}
295+
return { isGlobal: hint.vec[0].is_global, epoch: BigInt(hint.vec[0].epoch) };
296+
}
297+
260298
export async function getEncryptionKey(
261299
args: ViewFunctionParams & {
262300
useCachedValue?: boolean;

confidential-assets/tests/e2e/confidentialAsset.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ describe("Confidential Asset Sender API", () => {
436436
longTestTimeout,
437437
);
438438

439-
// Effective-auditor e2e tests require calling set_auditor_for_asset_type as the @aptos_framework (0x1)
439+
// Effective-auditor e2e tests require calling set_asset_specific_auditor as the @aptos_framework (0x1)
440440
// signer, which we can't do on localnet without the framework private key. The effective-auditor
441441
// sigma protocol is fully covered by Move unit tests (all 6 configs) and SDK unit tests.
442442
// TODO: once an `aptos` CLI profile for 0x1 is available on localnet, add e2e tests for:

0 commit comments

Comments
 (0)