Register Identifier
Before you can lookup identifiers using the SocialConnect protocol, the identifier needs to be registered either your own issuer or some other issuer.
Below is the code snippet to register an identifier under your issuer.
Before you use your issuer to register an identifier you need to setup your issuer, steps are here.
Get obfuscated Id and Register Obfuscated Id on FederatedAttestations.sol
import { IdentifierPrefix } from "@celo/identity/lib/odis/identifier";
import { federatedAttestationsABI } from "@celo/abis";
import {
createWalletClient
getContract,
http,
Hex,
http
} from "viem";
import { celo, celoAlfajores } from "viem/chains";
import { getObfuscatedId } from "./getObfuscatedId";
const chain =
process.env.NEXT_PUBLIC_ENVIRONMENT === "TESTNET" ? celoAlfajores : celo;
const publicClient = createPublicClient({
chain,
transport: http(),
});
let wallet = createWalletClient({
account,
chain,
transport: http(),
});
const FA_PROXY_ADDRESS =
process.env.NEXT_PUBLIC_ENVIRONMENT === "TESTNET"
? "0x70F9314aF173c246669cFb0EEe79F9Cfd9C34ee3"
: "0x0aD5b1d0C25ecF6266Dd951403723B2687d6aff2";
const NOW_TIMESTAMP = BigInt(Math.floor(new Date().getTime() / 1000)); // Current UNIX timestamp
const federatedAttestationsContract = getContract({
address: FA_PROXY_ADDRESS,
abi: federatedAttestationsABI,
client: wallet,
});
async function registerIdentifier(plaintextId, address) {
const obfuscatedId = await getObfuscatedId(
plaintextId,
IdentifierPrefix.PHONE_NUMBER
);
const hash =
await federatedAttestationsContract.write.registerAttestationAsIssuer(
[obfuscatedId, address, NOW_TIMESTAMP]
);
const receipt = await publicClient.waitForTransactionReceipt({ hash });
return receipt;
}