@@ -207,8 +207,8 @@ export async function toAddress(name: string, provider: EthersProvider) {
207207/**
208208 * @notice Returns public keys from the recipientId
209209 * @dev When providing a public key, transaction hash, or address with advanced mode, the spending and viewing
210- * public keys will be the same. Only keys retrieved from the StealthKeyRegistry will have different spending
211- * and viewing keys
210+ * public keys will be the same. Only keys retrieved from the StealthKeyRegistry (or the subgraph) will have different spending
211+ * and viewing keys. Additionally, the block number when the user registered will be returned.
212212 * @param id Recipient identifier, must be an ENS name, CNS name, address, transaction hash, or public key
213213 * @param provider ethers provider to use
214214 * @param options Object containing lookup options:
@@ -230,15 +230,15 @@ export async function lookupRecipient(
230230 const isPublicKey = id . length === 132 && isHexString ( id ) ;
231231 if ( supportPubKey && isPublicKey ) {
232232 assertValidPoint ( id ) ;
233- return { spendingPublicKey : id , viewingPublicKey : id } ;
233+ return { spendingPublicKey : id , viewingPublicKey : id , block : undefined } ;
234234 }
235235
236236 // Check if identifier is a transaction hash. If so, we recover the sender's public keys from the transaction
237237 const isTxHash = id . length === 66 && isHexString ( id ) ;
238238 if ( supportTxHash && isTxHash ) {
239239 const publicKey = await recoverPublicKeyFromTransaction ( id , provider ) ;
240240 assertValidPoint ( publicKey ) ;
241- return { spendingPublicKey : publicKey , viewingPublicKey : publicKey } ;
241+ return { spendingPublicKey : publicKey , viewingPublicKey : publicKey , block : undefined } ;
242242 }
243243
244244 // The remaining checks are dependent on the advanced mode option. The provided identifier is now either an
@@ -259,7 +259,11 @@ export async function lookupRecipient(
259259 stealthKeyChangedEvent . viewingPubKey ,
260260 stealthKeyChangedEvent . viewingPubKeyPrefix . toString ( )
261261 ) ;
262- return { spendingPublicKey : spendingPublicKey , viewingPublicKey : viewingPublicKey } ;
262+ return {
263+ spendingPublicKey : spendingPublicKey ,
264+ viewingPublicKey : viewingPublicKey ,
265+ block : stealthKeyChangedEvent . block ,
266+ } ;
263267 } catch ( error ) {
264268 if ( error instanceof Error ) {
265269 console . log ( 'Public key subgraph fetch error: ' , error . message ) ;
@@ -268,7 +272,8 @@ export async function lookupRecipient(
268272 }
269273 console . log ( 'Error using subgraph to lookup receipient stealth keys, will query registry contract' ) ;
270274 const registry = new StealthKeyRegistry ( provider ) ;
271- return registry . getStealthKeys ( address ) ;
275+ const { spendingPublicKey, viewingPublicKey } = await registry . getStealthKeys ( address ) ;
276+ return { spendingPublicKey, viewingPublicKey, block : undefined } ;
272277 }
273278 }
274279
@@ -277,7 +282,7 @@ export async function lookupRecipient(
277282 if ( ! txHash ) throw new Error ( 'Could not get public key because the provided account has not sent any transactions' ) ;
278283 const publicKey = await recoverPublicKeyFromTransaction ( txHash , provider ) ;
279284 assertValidPoint ( publicKey ) ;
280- return { spendingPublicKey : publicKey , viewingPublicKey : publicKey } ;
285+ return { spendingPublicKey : publicKey , viewingPublicKey : publicKey , block : undefined } ;
281286}
282287
283288export async function getBlockNumberUserRegistered (
0 commit comments