import { Connection , Keypair , PublicKey } from '@solana/web3.js' ; import { didToPublicKey , ExtendedCluster , isKeypair , pubkeyOf , } from '../lib/util' ; import { defaultSignCallback , SignCallback } from '../lib/wallet' ; import { SolariumTransaction } from '../lib/solana/transaction' ; import { AddressBook , UserDetails } from '../lib/UserDetails' ; import { SolariumCache } from '../lib/cache' ; const getUserDetailsDirect = async ( did , connection ) : Promise < UserDetails | null > => { const didKey = didToPublicKey ( did ) ; const encryptedUserDetails = await SolariumTransaction . getUserDetails ( connection , didKey ) ; if ( ! encryptedUserDetails ) return null ; return UserDetails . fromChainData ( encryptedUserDetails ) ; } ; export const userDetailsCache = new SolariumCache < UserDetails | null , ( key : string , connection : Connection ) => Promise < UserDetails | null > > ( getUserDetailsDirect ) ; export const getUserDetails = userDetailsCache . load . bind ( userDetailsCache ) ; param did param owner param payer param alias param size param signCallback param cluster export const createUserDetails = async ( did , owner , payer , alias , size ? , signCallback ? , cluster ? ) : Promise < void > => { const createSignedTx = signCallback || ( isKeypair ( payer ) && isKeypair ( owner ) && defaultSignCallback ( payer , owner ) ) ; if ( ! createSignedTx ) throw new Error ( 'No payer or sign callback specified' ) ; const ownerDIDKey = didToPublicKey ( did ) ; await SolariumTransaction . createUserDetails ( pubkeyOf ( payer ) , ownerDIDKey , pubkeyOf ( owner ) , createSignedTx , alias , size , cluster ) ; } ; param did param connection param owner param payer param alias param addressBook param signCallback param cluster export const updateUserDetails = async ( did , connection , owner , payer , alias ? , addressBook ? , signCallback ? , cluster ? ) : Promise < void > => { const createSignedTx = signCallback || ( isKeypair ( payer ) && isKeypair ( owner ) && defaultSignCallback ( payer , owner ) ) ; if ( ! createSignedTx ) throw new Error ( 'No payer or sign callback specified' ) ; const ownerDIDKey = didToPublicKey ( did ) ; const existingUserDetails = await getUserDetailsDirect ( did , connection ) ; if ( ! existingUserDetails ) throw new Error ( `DID ${ did } has no userDetails account` ) ; await SolariumTransaction . updateUserDetails ( ownerDIDKey , pubkeyOf ( owner ) , createSignedTx , alias || existingUserDetails . alias , ( addressBook || existingUserDetails . addressBook ) . toChainData ( ) , cluster ) ; } ;