useRingVrfKeys
Ring-VRF keys a product has registered, with the opaque handles proofs and aliases need (RFC-0024)
useRingVrfKeys lists the ring-VRF keys registered by owner, this product
by default (its id comes from the host's product context). Each
RegisteredRingVrfKey carries the opaque handle that
useAccountAlias,
useCreateAccountProof and
useRingVrfSign take, plus the
rings it was declared for. Handles are the only way to name a key: product
code never hard-codes another product's derivation index.
With disclosure: "PublicKey" the host also returns each key's public key
(granted for your own keys, prompted for someone else's); the default
"Anonymized" omits it. Use findRingVrfKeyHandle(keys, ring) (exported
from the package) to pick the handle declared for a given ring.
Host-only: standalone the query errors with HostUnavailableError, so
gate it on useIsHost.
Usage
import { findRingVrfKeyHandle, useIsHost, useRingVrfKeys, type RingLocation } from "@use-truapi/react";
function KeyPicker({ ring }: { ring: RingLocation }) {
const isHost = useIsHost();
const { data: keys, isPending } = useRingVrfKeys(undefined, {
disclosure: "PublicKey",
query: { enabled: isHost },
});
const handle = keys ? findRingVrfKeyHandle(keys, ring) : undefined;
if (!isHost) return <p>Host only.</p>;
if (isPending) return <p>Loading keys…</p>;
return <p>{keys?.length ?? 0} keys · {handle ? "one declared for this ring" : "none for this ring"}</p>;
}<script setup lang="ts">
import { findRingVrfKeyHandle, useIsHost, useRingVrfKeys, type RingLocation } from "@use-truapi/vue";
import { computed } from "vue";
const props = defineProps<{ ring: RingLocation }>();
const isHost = useIsHost();
const keys = useRingVrfKeys(undefined, {
disclosure: "PublicKey",
query: { enabled: computed(() => isHost.value) },
});
const handle = computed(() =>
keys.data.value ? findRingVrfKeyHandle(keys.data.value, props.ring) : undefined,
);
</script>
<template>
<p v-if="!isHost">Host only.</p>
<p v-else>{{ keys.data.value?.length ?? 0 }} keys · {{ handle ? "declared for this ring" : "none" }}</p>
</template>Pass a getter as owner to list another product's keys reactively.
See also
useRegisterRingVrfKeyadds a key to this list.useHostChainInforesolves the People chain genesis aRingLocationpoints at.
API reference
React
function useRingVrfKeys(owner?, options?): UseQueryResult<RegisteredRingVrfKey[], Error>;RFC-0024 ring-VRF keys registered by owner (this product by default).
Use the returned handles for aliases and proofs instead of hard-coding a
derivation index. Host-only: standalone the query errors with HostUnavailableError.
Parameters
| Parameter | Type |
|---|---|
owner? | string |
options? | { disclosure?: RingVrfKeyDisclosure; query?: QueryOptions<RegisteredRingVrfKey[]>; } |
options.disclosure? | RingVrfKeyDisclosure |
options.query? | QueryOptions<RegisteredRingVrfKey[]> |
Returns
UseQueryResult<RegisteredRingVrfKey[], Error>
Vue
function useRingVrfKeys(owner?, options?): QueryResult<RegisteredRingVrfKey[]>;RFC-0024 ring-VRF keys registered by owner (this product by default).
Use the returned handles for aliases and proofs instead of hard-coding a
derivation index. Host-only: standalone the query errors with HostUnavailableError.
Parameters
| Parameter | Type |
|---|---|
owner? | MaybeGetter<string | undefined> |
options? | { disclosure?: RingVrfKeyDisclosure; query?: QueryOptions<RegisteredRingVrfKey[]>; } |
options.disclosure? | RingVrfKeyDisclosure |
options.query? | QueryOptions<RegisteredRingVrfKey[]> |
Returns
QueryResult<RegisteredRingVrfKey[]>