Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

The secretKey property on the Keypair class from @solana/web3.js behaves differently since 1.54.1 #27684

Closed
beeman opened this issue Sep 8, 2022 · 2 comments · Fixed by #27700
Assignees
Labels
community Community contribution

Comments

@beeman
Copy link
Contributor

beeman commented Sep 8, 2022

Problem

While updating my @solana/web3.js deps, I found a difference between v1.54.0 and 1.54.1, probably introduced here.

To test this, we can use the following snippet from the Solana Cookbook:

const {Keypair} = require('@solana/web3.js')
const bs58 = require('bs58')

const keypair = Keypair.fromSecretKey(
  bs58.decode("5MaiiCavjCmn9Hs1o3eznqDEhRwxo7pXiAYez7keQUviUkauRiTMD8DrESdrNjN8zd9mTmVhRvBJeg5vhyvgrAhG")
);

console.log(JSON.stringify({
  publicKey: keypair.publicKey.toString(),
  secretKey: keypair.secretKey.toString(),
}, null, 2));

Using @solana/web3.js@1.54.0 and before, the output looks like this, exposing the secretKey property as a Uint8Array:

yarn add -D @solana/web3.js@1.54.0
node index.js
{
  "publicKey": "5pVyoAeURQHNMVU7DmfMHvCDNmTEYXWfEwc136GYhTKG",
  "secretKey": "217,209,11,117,20,116,176,35,106,179,68,60,223,114,201,199,74,254,15,14,253,15,137,41,116,68,148,190,213,78,166,97,71,153,208,10,192,117,37,246,54,188,173,16,84,68,22,36,78,90,214,115,15,225,215,92,166,174,42,53,72,101,107,155"
}

Using @solana/web3.js@1.54.1 and higher, the output looks like this, exposing the secretKey as some binary string:

yarn add -D @solana/web3.js@1.54.1
node index.js
{
  "publicKey": "5pVyoAeURQHNMVU7DmfMHvCDNmTEYXWfEwc136GYhTKG",
  "secretKey": "��\u000bu\u0014t�#j�D<�r��J�\u000f\u000e\u000f�)tD���N�aG��\n�u%�6��\u0010TD\u0016$NZ�s\u000f��\\��*5Hek�"
}

Proposed Solution

Make sure the Keypair class returns a Uint8Array as suggested by its type.

@jstarry
Copy link
Contributor

jstarry commented Sep 9, 2022

Thanks for the report @beeman, I've opened a PR to fix this regression here: #27700

@beeman
Copy link
Contributor Author

beeman commented Sep 9, 2022

Thanks for the report @beeman, I've opened a PR to fix this regression here: #27700

Thanks a lot for the quick fix 🥳

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
community Community contribution
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants