-
Notifications
You must be signed in to change notification settings - Fork 25
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
Feat/HD-Wallet SLIP0010 #1190
Feat/HD-Wallet SLIP0010 #1190
Conversation
🦋 Changeset detectedLatest commit: 6b8ae3d The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 4 Ignored Deployments
|
packages/libs/hd-wallet/src/index.ts
Outdated
*/ | ||
export function kadenaGenMnemonic(): string { | ||
const words = bip39.generateMnemonic(wordlist); | ||
if (bip39.validateMnemonic(words, wordlist) === false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is it possible to create invalid words?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
valid point, only when the wordlist, that comes from @scure39 is diffetent, the generated words could be invalid, this check is redundant when words aren't manually passed
packages/libs/hd-wallet/src/index.ts
Outdated
} else { | ||
seed = encryptOrEncodeSeed(seedBuffer); | ||
} | ||
return { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe its better to just return the encrypted version.
then we decrypt it in the keyGeneration function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the current interface in the current implementation: https://github.com/kadena-io/cardano-crypto.js/blob/jam%40chainweaver-keygen/features/kadena-features.js
packages/libs/hd-wallet/src/index.ts
Outdated
const seedBuffer = await bip39.mnemonicToSeed(mnemonic); | ||
let seed: string; | ||
|
||
if (typeof password === 'string' && password.length > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why don't we allow empty string as password?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why would we? (please elaborate a case where it would be usefull?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From a wallet perspective, we're planning on allowing multiple mnemonics. For testnet and devnet I wouldn't care whether it has a password, so it being empty could be fine
packages/libs/hd-wallet/src/index.ts
Outdated
* @throws {Error} Throws an error if the seed buffer is not provided, if the indices are invalid, or if encryption fails. | ||
*/ | ||
export function kadenaGenKeypair( | ||
seedBuffer: Uint8Array, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should accept the encrypted seed instead.
we can decrypt it easily with the password
What do you say?
packages/libs/hd-wallet/src/index.ts
Outdated
* @returns {([string, string] | [string, string][])} - Depending on the input, either a tuple for a single key pair or an array of tuples for a range of key pairs, with the private key encrypted if a password is provided. | ||
* @throws {Error} Throws an error if the seed buffer is not provided, if the indices are invalid, or if encryption fails. | ||
*/ | ||
export function kadenaGenKeypair( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its good to write two overloads functions since the return type is also different
packages/libs/hd-wallet/src/index.ts
Outdated
export function kadenaRestoreSeedBufferFromSeed( | ||
seed: string, | ||
password?: string, | ||
): Uint8Array { | ||
if (typeof password !== 'undefined') { | ||
return extractSeedBuffer(seed, password); | ||
} else { | ||
return extractSeedBuffer(seed); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is part of the private API.
Password will be mandatory
packages/libs/hd-wallet/src/index.ts
Outdated
export function kadenaSignWithSeed( | ||
seed: Uint8Array, | ||
index: number, | ||
): (tx: IUnsignedCommand) => { sigs: { sig: string }[] } { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export function kadenaSignWithSeed(
password: string,
seed: Uint8Array,
derivationPath: string, // default value `m/44'/626'/{$index}'/0'/0'`
message: string,
): Uint8Array
f81b0a0
to
e51a405
Compare
export async function kadenaMnemonicToSeed( | ||
password: string, | ||
mnemonic: string, | ||
// wordList: string[] = wordlist, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can probably turn this on right?
e22c5f6
to
60578fb
Compare
added functions to match the legacy function but using standards.