Closed jim4067 closed 1 year ago
Hi there, the goal of these interfaces is to be as minimal and "to the point" as possible. If we started adding more inputs to these methods, we force all implementations to deal with parsing buffers when all they need to do is create a new keypair. Additionally, if we were to switch to encoded string instead of Uint8Array
s we'd need a systematic and consistent way to know which encodings the string is using (base58, base64, etc).
However we could offer a helper method that uses that interface to provide a more flexible signature such as the one you suggested. Doing so is not really a priority at this point so I'll close this issue but I'll give you the following workaround if you wanted to have this helper in a plugin or on your own apps.
import { Context, createSignerFromKeypair, KeypairSigner } from '@metaplex-foundation/umi';
import { base58 } from '@metaplex-foundation/umi/serializers';
function createSignerFromSecretKey(context: Pick<Context, 'eddsa'>, secretKey: string | Uint8Array): KeypairSigner {
if (typeof secretKey === 'string') {
secretKey = base58.deserialize(secretKey)[0];
}
return createSignerFromKeypair(context.eddsa.createKeypairFromSecretKey(secretKey));
}
I hope this helps.
Some wallet providers export the secret key as a bs58 string.
I think it would be nice to make the parameter type for
createKeypairFromSecretKey
a union ofstring | Uint8Array
.