-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Add Create Account fromDerivePath #2073
Conversation
Great stuff! Lemme get some typescript ninjas on this. |
static isValidPath = (path: string): boolean => { | ||
if ( | ||
// eslint-disable-next-line prefer-regex-literals | ||
!new RegExp('^m\\/44+\'\\/637+\'\\/[0-9]+\'\\/[0-9]+\'\\/[0-9]+\'+$').test( |
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 doesn't look right:
- First of all, rebase and start using double quotes
- Let's follow the BIP44 standard, https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki#path-levels. The
change
andaddress_index
do not follow by a'
. In the link, a path looks likem / purpose' / coin_type' / account' / change / address_index
. - The regex has issues.
44+
would match44444
and637+
would match63777777
. 44 and 637 should be an exact match. 44 is the current BIP number and 637 is Apto's coin type.
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.
Because it uses the ed25519-hd-key module, the regex check uses a '
for all numbers. And other chains, such as near and solana are using a '
for all numbers.
.some(isNaN as any); | ||
}; | ||
|
||
static fromDerivePath(path: string, mnemonics: string): AptosAccount { |
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.
Also, check if mnemonics are empty and throw meaningful errors, just in case developers forgot to pass in the mnemonics.
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.
You still need to check if the mnemonics are empty. Why should we allow that to happen? Throw an error in such case.
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.
Add ts-doc for this method
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.
Please squash your commits and make sure your final commit message follows the Angular Conventional Commits. This is to help the SDK tooling find your commit and add it to release notes.
For your final commit, the message should look like this:
feat: add BIP44 to allow the creation of multiple accounts with the same key
if ( | ||
// eslint-disable-next-line prefer-regex-literals | ||
!new RegExp("^m\\/44'\\/637'\\/[0-9]+'\\/[0-9]+'\\/[0-9]+'+$").test( | ||
path, | ||
) |
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 not one line?
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'll fix it
static isValidPath = (path: string): boolean => { | ||
if ( | ||
// eslint-disable-next-line prefer-regex-literals | ||
!new RegExp("^m\\/44'\\/637'\\/[0-9]+'\\/[0-9]+'\\/[0-9]+'+$").test( |
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.
You can either:
new RegExp("^m/44'/637'/[0-9]+'/[0-9]+'/[0-9]+'+$").test
Or /^m\/44'\/637'\/[0-9]+'\/[0-9]+'\/[0-9]+'+$/.test
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.
The \\
is not needed
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'll fix it
.some(isNaN as any); | ||
}; | ||
|
||
static fromDerivePath(path: string, mnemonics: string): AptosAccount { |
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.
You still need to check if the mnemonics are empty. Why should we allow that to happen? Throw an error in such case.
@@ -30,6 +32,34 @@ export class AptosAccount { | |||
return new AptosAccount(HexString.ensure(obj.privateKeyHex).toUint8Array(), obj.address); | |||
} | |||
|
|||
static isValidPath = (path: string): boolean => { |
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.
Add @ts-doc for this method
.some(isNaN as any); | ||
}; | ||
|
||
static fromDerivePath(path: string, mnemonics: string): AptosAccount { |
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.
Add ts-doc for this method
function normalize(str: string) {
const norm = nfkd(str);
const words = norm.split(' ');
if (![12, 15, 18, 21, 24].includes(words.length)) throw new Error('Invalid mnemonic');
return { nfkd: norm, words };
} Length check of mnemonics is in the @scure/bip39 module. |
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.
Thanks
please rebase your PR |
Head branch was pushed to by a user without write access
I think you need to rebase, there's a ton of commits here that are already in the codebase |
❌ Forge test failure on
|
please update, it seems like this is stale |
@davidiw update was done thanks. |
https://github.com/satoshilabs/slips/pull/1364/files remove bip39-light Update aptos_account.ts Update aptos_account.ts Fix comma
Forge is running with
|
Description
Create Account with hdpath 637
Test Plan
This change is