async function submitAttestations ({
  rewardManagerProgramId,
  rewardManagerAccount,
  attestations,
  oracleAttestation,
  challengeId,
  specifier,
  feePayer,
  recipientEthAddress,
  tokenAmount,
  identityService,
  connection
}) {
  // Construct combined transfer ID
  const transferId = SolanaUtils.constructTransferId(challengeId, specifier)

  // Derive the message account we'll use to store the attestations
  const [
    rewardManagerAuthority,
    derivedMessageAccount
  ] = await deriveMessageAccount(
    transferId,
    rewardManagerProgramId,
    rewardManagerAccount
  )

  // Add instructions from DN attestations - each attestation
  // needs a pairing of SECP recovery instruction and submit
  // attestation instruction.
  let instructions = await Promise.all(
    attestations.reduce((instructions, meta, i) => {
      const verifyInstruction = generateSubmitAttestationInstruction({
        attestationMeta: meta,
        derivedMessageAccount,
        rewardManagerAccount,
        rewardManagerProgramId,
        rewardManagerAuthority,
        transferId,
        feePayer
      })
      const secpInstruction = Promise.resolve(
        generateSecpInstruction({
          attestationMeta: meta,
          recipientEthAddress,
          oracleAddress: oracleAttestation.ethAddress,
          tokenAmount,
          transferId,
          instructionIndex: 2 * i
        })
      )
      return [...instructions, secpInstruction, verifyInstruction]
    }, [])
  )

  // Add instructions from oracle attestation
  const oracleSecp = await generateSecpInstruction({
    attestationMeta: oracleAttestation,
    recipientEthAddress,
    instructionIndex: instructions.length,
    transferId,
    tokenAmount
  })
  const oracleTransfer = await generateSubmitAttestationInstruction({
    attestationMeta: oracleAttestation,
    derivedMessageAccount,
    rewardManagerAccount,
    rewardManagerProgramId,
    rewardManagerAuthority,
    transferId,
    feePayer
  })
  instructions = [...instructions, oracleSecp, oracleTransfer]

  // Prep transaction to be relayed and send it
  const relayable = instructions.map(SolanaUtils.prepareInstructionForRelay)
  const { blockhash: recentBlockhash } = await connection.getRecentBlockhash()
  const transactionData = {
    recentBlockhash,
    instructions: relayable
  }

  try {
    const response = await identityService.solanaRelay(transactionData)
    return response
  } catch (e) {
    console.error(e.message)
  }
}
/**
 * Submits attestations from Discovery Nodes and AAO that a user has completed a challenge.
 *
 * @param {{
 *   rewardManagerProgramId: PublicKey,
 *   rewardManagerAccount: PublicKey,
 *   attestations: AttestationMeta[]
 *   oracleAttestation: AttestationMeta
 *   challengeId: string,
 *   specifier: string,
 *   feePayer: PublicKey,
 *   attestationSignature: string,
 *   recipientEthAddress: string,
 *   tokenAmount: BN
 *   identityService: any
 *   connection: Connection
 * }} {
 *   rewardManagerProgramId,
 *   rewardManagerAccount,
 *   attestations,
 *   oracleAttestation,
 *   challengeId,
 *   specifier,
 *   feePayer,
 *   recipientEthAddress,
 *   tokenAmount,
 *   identityService,
 *   connection
 * }
 */
Submits attestations from Discovery Nodes and AAO that a user has completed a challenge.
Submits attestations from Discovery Nodes and AAO that a user has completed a challenge .
async function submitAttestations ({
  rewardManagerProgramId,
  rewardManagerAccount,
  attestations,
  oracleAttestation,
  challengeId,
  specifier,
  feePayer,
  recipientEthAddress,
  tokenAmount,
  identityService,
  connection
}) {
  const transferId = SolanaUtils.constructTransferId(challengeId, specifier)
  const [
    rewardManagerAuthority,
    derivedMessageAccount
  ] = await deriveMessageAccount(
    transferId,
    rewardManagerProgramId,
    rewardManagerAccount
  )
  let instructions = await Promise.all(
    attestations.reduce((instructions, meta, i) => {
      const verifyInstruction = generateSubmitAttestationInstruction({
        attestationMeta: meta,
        derivedMessageAccount,
        rewardManagerAccount,
        rewardManagerProgramId,
        rewardManagerAuthority,
        transferId,
        feePayer
      })
      const secpInstruction = Promise.resolve(
        generateSecpInstruction({
          attestationMeta: meta,
          recipientEthAddress,
          oracleAddress: oracleAttestation.ethAddress,
          tokenAmount,
          transferId,
          instructionIndex: 2 * i
        })
      )
      return [...instructions, secpInstruction, verifyInstruction]
    }, [])
  )
  const oracleSecp = await generateSecpInstruction({
    attestationMeta: oracleAttestation,
    recipientEthAddress,
    instructionIndex: instructions.length,
    transferId,
    tokenAmount
  })
  const oracleTransfer = await generateSubmitAttestationInstruction({
    attestationMeta: oracleAttestation,
    derivedMessageAccount,
    rewardManagerAccount,
    rewardManagerProgramId,
    rewardManagerAuthority,
    transferId,
    feePayer
  })
  instructions = [...instructions, oracleSecp, oracleTransfer]
  const relayable = instructions.map(SolanaUtils.prepareInstructionForRelay)
  const { blockhash: recentBlockhash } = await connection.getRecentBlockhash()
  const transactionData = {
    recentBlockhash,
    instructions: relayable
  }
  try {
    const response = await identityService.solanaRelay(transactionData)
    return response
  } catch (e) {
    console.error(e.message)
  }
}
async function submitAttestations ( { rewardManagerProgramId , rewardManagerAccount , attestations , oracleAttestation , challengeId , specifier , feePayer , recipientEthAddress , tokenAmount , identityService , connection } ) { const transferId = SolanaUtils . constructTransferId ( challengeId , specifier ) const [ rewardManagerAuthority , derivedMessageAccount ] = await deriveMessageAccount ( transferId , rewardManagerProgramId , rewardManagerAccount ) let instructions = await Promise . all ( attestations . reduce ( ( instructions , meta , i ) => { const verifyInstruction = generateSubmitAttestationInstruction ( { attestationMeta : meta , derivedMessageAccount , rewardManagerAccount , rewardManagerProgramId , rewardManagerAuthority , transferId , feePayer } ) const secpInstruction = Promise . resolve ( generateSecpInstruction ( { attestationMeta : meta , recipientEthAddress , oracleAddress : oracleAttestation . ethAddress , tokenAmount , transferId , instructionIndex : 2 * i } ) ) return [ ... instructions , secpInstruction , verifyInstruction ] } , [ ] ) ) const oracleSecp = await generateSecpInstruction ( { attestationMeta : oracleAttestation , recipientEthAddress , instructionIndex : instructions . length , transferId , tokenAmount } ) const oracleTransfer = await generateSubmitAttestationInstruction ( { attestationMeta : oracleAttestation , derivedMessageAccount , rewardManagerAccount , rewardManagerProgramId , rewardManagerAuthority , transferId , feePayer } ) instructions = [ ... instructions , oracleSecp , oracleTransfer ] const relayable = instructions . map ( SolanaUtils . prepareInstructionForRelay ) const { blockhash : recentBlockhash } = await connection . getRecentBlockhash ( ) const transactionData = { recentBlockhash , instructions : relayable } try { const response = await identityService . solanaRelay ( transactionData ) return response } catch ( e ) { console . error ( e . message ) } }
Submits attestations from Discovery Nodes and AAO that a user has completed a challenge.
Submits attestations from Discovery Nodes and AAO that a user has completed a challenge .
// Construct combined transfer ID // Derive the message account we'll use to store the attestations // Add instructions from DN attestations - each attestation // needs a pairing of SECP recovery instruction and submit // attestation instruction. // Add instructions from oracle attestation // Prep transaction to be relayed and send it