From 02b4a55551208a4b69063f185b5b6966e5bd644e Mon Sep 17 00:00:00 2001 From: "@Andzi_dev" <100753538+Gitmazter@users.noreply.github.com> Date: Mon, 27 Nov 2023 16:33:26 +0700 Subject: [PATCH 1/2] feat: Add compatibility for publicKeys Ran into an issue where I was passing web3.publicKeys to createMintToInstruction but received an anonymous.toString() is undefined error. The error was that the docs allowed a (signer | publicKey) [ ] but the function only works with a signer[ ], my fix was to move my publicKeys into an object. {publicKey: myKey} I believe the changes to the logic in this file will resolve the issue for anyone encountering it in the future --- token/js/src/instructions/internal.ts | 28 +++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/token/js/src/instructions/internal.ts b/token/js/src/instructions/internal.ts index 7255fa2f7e7..f5570475149 100644 --- a/token/js/src/instructions/internal.ts +++ b/token/js/src/instructions/internal.ts @@ -1,5 +1,5 @@ import type { AccountMeta, Signer } from '@solana/web3.js'; -import { PublicKey } from '@solana/web3.js'; +import { PublicKey, Keypair } from '@solana/web3.js'; /** @internal */ export function addSigners( @@ -9,12 +9,28 @@ export function addSigners( ): AccountMeta[] { if (multiSigners.length) { keys.push({ pubkey: ownerOrAuthority, isSigner: false, isWritable: false }); + for (const signer of multiSigners) { - keys.push({ - pubkey: signer instanceof PublicKey ? signer : signer.publicKey, - isSigner: true, - isWritable: false, - }); + if (signer instanceof PublicKey || signer instanceof Keypair) { + keys.push({ + pubkey: signer instanceof PublicKey ? signer : signer.publicKey, + isSigner: true, + isWritable: false, + }); + } + else if (signer.toString()) { + try { + const compatiblePubkey = new PublicKey(signer.toString()) + keys.push({ + pubkey: compatiblePubkey, + isSigner: true, + isWritable: false, + }); + } + catch (e) { + // not a pubkey + } + } } } else { keys.push({ pubkey: ownerOrAuthority, isSigner: true, isWritable: false }); From ed3118105ea40c9a1ad96f9d64e7844efcb46003 Mon Sep 17 00:00:00 2001 From: "@Andzi_dev" <100753538+Gitmazter@users.noreply.github.com> Date: Wed, 29 Nov 2023 15:40:06 +0700 Subject: [PATCH 2/2] Update token/js/src/instructions/internal.ts Co-authored-by: Joe C --- token/js/src/instructions/internal.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/token/js/src/instructions/internal.ts b/token/js/src/instructions/internal.ts index f5570475149..9f03cbf2f9b 100644 --- a/token/js/src/instructions/internal.ts +++ b/token/js/src/instructions/internal.ts @@ -13,7 +13,7 @@ export function addSigners( for (const signer of multiSigners) { if (signer instanceof PublicKey || signer instanceof Keypair) { keys.push({ - pubkey: signer instanceof PublicKey ? signer : signer.publicKey, + pubkey: 'publicKey' in signer ? signer.publicKey : signer, isSigner: true, isWritable: false, });