Created
April 24, 2024 15:11
-
-
Save martykan/ff9ca7bdc31a62d73a86277bfb0571d4 to your computer and use it in GitHub Desktop.
Trezor Solana new_authority issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { | |
Connection, | |
PublicKey, | |
Transaction, | |
Keypair, | |
SystemProgram, | |
} = require("@solana/web3.js"); | |
const { | |
AuthorityType, | |
createSetAuthorityInstruction, | |
MINT_SIZE, | |
TOKEN_PROGRAM_ID, | |
getAssociatedTokenAddress, | |
createInitializeMintInstruction, | |
} = require("@solana/spl-token"); | |
const { default: TrezorConnect } = require("@trezor/connect"); | |
async function run() { | |
await TrezorConnect.init({ | |
manifest: { | |
email: "[email protected]", | |
appUrl: "https://trezor.io/", | |
}, | |
}); | |
// Testnet connection | |
const connection = new Connection("https://api.devnet.solana.com"); | |
// Get address from Trezor | |
const trezorAddr = await TrezorConnect.solanaGetAddress({ | |
path: "m/44'/501'/1'/0'", | |
address: walletPubkey.toBase58(), | |
showOnTrezor: false, | |
useEmptyPassphrase: true, | |
}); | |
console.log("trezorAddr", trezorAddr); | |
const mintKp = Keypair.generate(); | |
const walletPubkey = new PublicKey(trezorAddr.payload.address); | |
// Setup test mint | |
const tx = new Transaction(); | |
tx.recentBlockhash = (await connection.getRecentBlockhash()).blockhash; | |
tx.feePayer = walletPubkey; | |
tx.add( | |
SystemProgram.createAccount({ | |
fromPubkey: walletPubkey, | |
newAccountPubkey: mintKp.publicKey, | |
space: MINT_SIZE, | |
lamports: 1461600, | |
programId: TOKEN_PROGRAM_ID, | |
}) | |
); | |
tx.add( | |
createInitializeMintInstruction( | |
mintKp.publicKey, | |
6, | |
walletPubkey, | |
walletPubkey, | |
TOKEN_PROGRAM_ID | |
) | |
); | |
tx.add( | |
createSetAuthorityInstruction( | |
mintKp.publicKey, | |
walletPubkey, | |
AuthorityType.MintTokens, | |
null | |
// null - doesnt work | |
// new PublicKey("11111111111111111111111111111111") - works | |
) | |
); | |
const result = await TrezorConnect.solanaSignTransaction({ | |
path: "m/44'/501'/1'/0'", | |
serializedTx: tx.serializeMessage().toString("hex"), | |
useEmptyPassphrase: true, | |
}); | |
console.log("result", result); | |
} | |
run(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "trezor-spl-test", | |
"version": "1.0.0", | |
"main": "index.js", | |
"license": "MIT", | |
"dependencies": { | |
"@solana/spl-token": "^0.4.6", | |
"@solana/web3.js": "^1.91.7", | |
"@trezor/connect": "^9.2.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment