Skip to content

Commit 0d52185

Browse files
committed
feat(multisig_create): make createKey a signer
1 parent 9e72b52 commit 0d52185

8 files changed

Lines changed: 72 additions & 63 deletions

File tree

programs/multisig/src/instructions/multisig_create.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ pub struct MultisigCreateArgs {
1212
pub threshold: u16,
1313
/// The members of the multisig.
1414
pub members: Vec<Member>,
15-
/// Any key that is used to seed the multisig pda. Used solely as bytes for the seed, doesn't have any other meaning.
16-
pub create_key: Pubkey,
1715
/// Memo isn't used for anything, but is included in `CreatedEvent` that can later be parsed and indexed.
1816
pub memo: Option<String>,
1917
}
@@ -25,11 +23,15 @@ pub struct MultisigCreate<'info> {
2523
init,
2624
payer = creator,
2725
space = Multisig::size(args.members.len()),
28-
seeds = [SEED_PREFIX, args.create_key.as_ref(), SEED_MULTISIG],
26+
seeds = [SEED_PREFIX, create_key.key().as_ref(), SEED_MULTISIG],
2927
bump
3028
)]
3129
pub multisig: Account<'info, Multisig>,
3230

31+
/// An ephemeral signer that is used as a seed for the Multisig PDA.
32+
/// Must be a signer to prevent the Multisig account from re-initialization by someone else but the original creator.
33+
pub create_key: Signer<'info>,
34+
3335
/// The creator of the multisig.
3436
#[account(mut)]
3537
pub creator: Signer<'info>,
@@ -71,7 +73,7 @@ impl MultisigCreate<'_> {
7173
multisig.authority_index = 1; // Default vault is the first authority.
7274
multisig.transaction_index = 0;
7375
multisig.stale_transaction_index = 0;
74-
multisig.create_key = args.create_key;
76+
multisig.create_key = ctx.accounts.create_key.to_account_info().key();
7577
multisig.bump = *ctx.bumps.get("multisig").unwrap();
7678

7779
multisig.invariant()?;

sdk/multisig/idl/multisig.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@
1313
"isMut": true,
1414
"isSigner": false
1515
},
16+
{
17+
"name": "createKey",
18+
"isMut": false,
19+
"isSigner": true,
20+
"docs": [
21+
"An ephemeral signer that is used as a seed for the Multisig PDA.",
22+
"Must be a signer to prevent the Multisig account from re-initialization by someone else but the original creator."
23+
]
24+
},
1625
{
1726
"name": "creator",
1827
"isMut": true,
@@ -520,13 +529,6 @@
520529
}
521530
}
522531
},
523-
{
524-
"name": "createKey",
525-
"docs": [
526-
"Any key that is used to seed the multisig pda. Used solely as bytes for the seed, doesn't have any other meaning."
527-
],
528-
"type": "publicKey"
529-
},
530532
{
531533
"name": "memo",
532534
"docs": [

sdk/multisig/src/generated/instructions/multisigCreate.ts

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/multisig/src/generated/types/MultisigCreateArgs.ts

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/multisig/src/instructions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ export function multisigCreate({
3838
return createMultisigCreateInstruction(
3939
{
4040
creator,
41+
createKey,
4142
multisig: multisigPda,
4243
},
4344
{
4445
args: {
4546
configAuthority,
4647
threshold,
4748
members,
48-
createKey,
4949
memo: memo ?? null,
5050
},
5151
}

sdk/multisig/src/rpc.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,39 @@ import { translateAndThrowAnchorError } from "./errors";
1414
/** Creates a new multisig. */
1515
export async function multisigCreate({
1616
connection,
17+
createKey,
1718
creator,
1819
multisigPda,
1920
configAuthority,
2021
threshold,
2122
members,
22-
createKey,
2323
memo,
2424
sendOptions,
2525
}: {
2626
connection: Connection;
27+
createKey: Signer;
2728
creator: Signer;
2829
multisigPda: PublicKey;
2930
configAuthority: PublicKey;
3031
threshold: number;
3132
members: Member[];
32-
createKey: PublicKey;
3333
memo?: string;
3434
sendOptions?: SendOptions;
3535
}): Promise<TransactionSignature> {
3636
const blockhash = (await connection.getLatestBlockhash()).blockhash;
3737

3838
const tx = transactions.multisigCreate({
3939
blockhash,
40+
createKey: createKey.publicKey,
4041
creator: creator.publicKey,
4142
multisigPda,
4243
configAuthority,
4344
threshold,
4445
members,
45-
createKey,
4646
memo,
4747
});
4848

49-
tx.sign([creator]);
49+
tx.sign([creator, createKey]);
5050

5151
try {
5252
return await connection.sendTransaction(tx, sendOptions);

sdk/multisig/src/transactions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,24 @@ import { getAuthorityPda, getTransactionPda } from "./pda";
1616
import { transactionMessageBeet } from "./types";
1717
import * as instructions from "./instructions.js";
1818

19-
/** Returns unsigned `VersionedTransaction` that needs to be signed by `creator` before sending it. */
19+
/** Returns unsigned `VersionedTransaction` that needs to be signed by `creator` and `createKey` before sending it. */
2020
export function multisigCreate({
2121
blockhash,
2222
configAuthority,
23+
createKey,
2324
creator,
2425
multisigPda,
2526
threshold,
2627
members,
27-
createKey,
2828
memo,
2929
}: {
3030
blockhash: string;
31+
createKey: PublicKey;
3132
creator: PublicKey;
3233
multisigPda: PublicKey;
3334
configAuthority: PublicKey;
3435
threshold: number;
3536
members: Member[];
36-
createKey: PublicKey;
3737
memo?: string;
3838
}): VersionedTransaction {
3939
const ix = instructions.multisigCreate({

0 commit comments

Comments
 (0)