-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base64 Private key conversion suibase <> chrome wallets #75
Comments
I did a quick test with latest suibase 0.1.5 and it did work for me ... so lets keep digging to find the difference/bug. === Please try this test key in your add_private_keys:
- 0x4d45fcbfb15f15ca068d87055ee32f130c9ae57cc058c5f79b4d2d2bd36fd4a5 This was taken from latest suiet 0.2.58 on Chrome. After 'localnet regen' you should see the following public key: Works for me on Ubuntu. In meantime I will be working on adding this as an automated test case and verify on MacOS later today. |
It seems there is may be two question/issue in your post. base64 in suibase.yaml (and sui.keystore) context are for keypair with an extra leading byte to store the type. These are the 33 bytes Mysten Labs specific encoding. The TS SDK you have here expect a 32 bytes base64. More info here: https://suibase.io/cookbook/code/keypairs.html You can go from 33<->32 bytes encoding with the sui keytool. === I am thinking to write an utility that you can feed "anything in" and convert to relevant alternatives in a way easy to parse/understand (it is almost all done within Suibase code already, just have to make it a nice standalone script). Something like: $ keyinfo 0x4d45fcbfb15f15ca068d87055ee32f130c9ae57cc058c5f79b4d2d2bd36fd4a5
web wallet public key : 0xc86169fd08606e2edd73f1914945c707763315d335bba6b44d218e607e145906
web wallet private key: 0x4d45fcbfb15f15ca068d87055ee32f130c9ae57cc058c5f79b4d2d2bd36fd4a5
sui.keystore keypair : "AE1F/L+xXxXKBo2HBV7jLxMMmuV8wFjF95tNLSvTb9Sl"
fromsecretkey input : "..."
$ keyinfo AE1F/L+xXxXKBo2HBV7jLxMMmuV8wFjF95tNLSvTb9Sl
web wallet public key : 0xc86169fd08606e2edd73f1914945c707763315d335bba6b44d218e607e145906
web wallet private key: 0x4d45fcbfb15f15ca068d87055ee32f130c9ae57cc058c5f79b4d2d2bd36fd4a5
sui.keystore keypair : "AE1F/L+xXxXKBo2HBV7jLxMMmuV8wFjF95tNLSvTb9Sl"
fromsecretkey input : "..."
$ keyinfo run orient life curious antique major snake amused cruel labor bubble dizzy
web wallet public key : 0xc86169fd08606e2edd73f1914945c707763315d335bba6b44d218e607e145906
web wallet private key: 0x4d45fcbfb15f15ca068d87055ee32f130c9ae57cc058c5f79b4d2d2bd36fd4a5
sui.keystore keypair : "AE1F/L+xXxXKBo2HBV7jLxMMmuV8wFjF95tNLSvTb9Sl"
fromsecretkey input : "..."
|
Hi, That tool could be useful. Yes, during my tests, the typescript error mentioned that the function was expecting a 32-byte base64 pvt key. My challenge is indeed that there are 2 versions of the same base64 private key: It seems that the private keys in the chrome wallets are: |
👍 |
Maybe useful for in the cookbook: import { Ed25519Keypair } from '@mysten/sui.js/keypairs/ed25519';
import dotenv from 'dotenv';
dotenv.config();
// Ethos chrome wallet: PRIVATE_KEY_BASE64_32BYTES, PRIVATE_KEY_HEX_0X_REMOVED
// Suiet chrome wallet: PRIVATE_KEY_HEX_0X_REMOVED
// Sui chrome wallet: HEX including 0x --> remove the 0x manually to get PRIVATE_KEY_HEX_0X_REMOVED
// keystore file: PRIVATE_KEY_BASE64_33BYTES
// Suibase: PRIVATE_KEY_BASE64_33BYTES or HEX including 0x
const keypair = Ed25519Keypair.fromSecretKey(Buffer.from(process.env.PRIVATE_KEY_BASE64_32BYTES as string, 'base64'));
const keypair = Ed25519Keypair.fromSecretKey(Buffer.from(process.env.PRIVATE_KEY_BASE64_33BYTES as string, 'base64').slice(1,33));
const keypair = Ed25519Keypair.fromSecretKey(Buffer.from(process.env.PRIVATE_KEY_HEX_0X_REMOVED as string, 'hex'));
const publicKey= keypair.getPublicKey().toSuiAddress();
NOT REQUIRED ANYMORE:
import { fromB64 } from "@mysten/bcs"; |
Great. Please go ahead with this contribution to the cookbook (can conveniently be done with the "edit this page on github" link), and by the way, you are very welcome to edit a lot more if you want to 😄 I assume at this point you are all set with the initial issue (and you can load the private key in suibase). I will leave the case open so I can attach the following enhancement later:
|
How do I go from my Suibase required base64 private key to
TS SDK required pvt key which is the same as the pvt key in the chrome wallets.
The pvt key from the chrome wallets don't work on a regen.
Thx
The text was updated successfully, but these errors were encountered: