From da69aa6715022d61b93491209e8577d839615f6d Mon Sep 17 00:00:00 2001 From: gallynaut Date: Tue, 17 Oct 2023 09:36:30 -0600 Subject: [PATCH] fix: functionRequestInit signer check gets ignored if not provided --- javascript/solana.js/package.json | 2 +- .../src/accounts/functionRequestAccount.ts | 36 ++++++++++++++++--- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/javascript/solana.js/package.json b/javascript/solana.js/package.json index 757ae6abe..9d0d7cb95 100644 --- a/javascript/solana.js/package.json +++ b/javascript/solana.js/package.json @@ -1,6 +1,6 @@ { "name": "@switchboard-xyz/solana.js", - "version": "2.7.1", + "version": "2.8.1", "author": "", "license": "MIT", "description": "A Typescript client to interact with Switchboard on Solana.", diff --git a/javascript/solana.js/src/accounts/functionRequestAccount.ts b/javascript/solana.js/src/accounts/functionRequestAccount.ts index a2dc9ba0f..a862e295a 100644 --- a/javascript/solana.js/src/accounts/functionRequestAccount.ts +++ b/javascript/solana.js/src/accounts/functionRequestAccount.ts @@ -1,3 +1,4 @@ +import { Idl, Program } from "@coral-xyz/anchor"; import { Account } from "../accounts/account.js"; import * as errors from "../errors.js"; import * as types from "../generated/attestation-program/index.js"; @@ -16,6 +17,7 @@ import { TOKEN_PROGRAM_ID, } from "@solana/spl-token"; import type { + AccountMeta, Commitment, PublicKey, TransactionInstruction, @@ -42,6 +44,12 @@ export interface FunctionRequestAccountInitParams { keypair?: Keypair; authority?: PublicKey; + + /** + * An optional keypair to be used to sign the transaction if the function requires + * authorization on request initialization. + */ + functionAuthority?: Keypair; } /** @@ -121,9 +129,6 @@ export class FunctionRequestAccount extends Account { - // TODO: Calculate the max size of data we can support up front then split into multiple txns - - // TODO: Add way to make this a PDA const requestKeypair = params.keypair ?? Keypair.generate(); await program.verifyNewKeypair(requestKeypair); @@ -147,7 +152,9 @@ export class FunctionRequestAccount extends Account + accountMeta.pubkey.equals(program.programId) + ? { + pubkey: accountMeta.pubkey, + isSigner: false, + isWritable: accountMeta.isWritable, + } + : accountMeta + ); + return [ new FunctionRequestAccount(program, requestKeypair.publicKey), - new TransactionObject(payer, [instruction], [requestKeypair], options), + new TransactionObject( + payer, + [instruction], + params.functionAuthority + ? [requestKeypair, params.functionAuthority] + : [requestKeypair], + options + ), ]; }