-
Notifications
You must be signed in to change notification settings - Fork 525
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] Generate Wallet from secret numbers (#1799)
* add the possibility to create a wallet from Secret Numbers * Move it off the Wallet class
- Loading branch information
Showing
7 changed files
with
158 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Account } from 'xrpl-secret-numbers' | ||
|
||
import ECDSA from '../ECDSA' | ||
|
||
import { Wallet } from '.' | ||
|
||
/** | ||
* Derives a wallet from secret numbers. | ||
* NOTE: This uses a default encoding algorithm of secp256k1 to match the popular wallet | ||
* [Xumm (aka Xaman)](https://xumm.app/)'s behavior. | ||
* This may be different from the DEFAULT_ALGORITHM for other ways to generate a Wallet. | ||
* | ||
* @param secretNumbers - A string consisting of 8 times 6 numbers (whitespace delimited) used to derive a wallet. | ||
* @param opts - (Optional) Options to derive a Wallet. | ||
* @param opts.masterAddress - Include if a Wallet uses a Regular Key Pair. It must be the master address of the account. | ||
* @param opts.algorithm - The digital signature algorithm to generate an address for. | ||
* @returns A Wallet derived from secret numbers. | ||
* @throws ValidationError if unable to derive private key from secret number input. | ||
*/ | ||
export function walletFromSecretNumbers( | ||
secretNumbers: string[] | string, | ||
opts?: { masterAddress?: string; algorithm?: ECDSA }, | ||
): Wallet { | ||
const secret = new Account(secretNumbers).getFamilySeed() | ||
const updatedOpts: { masterAddress?: string; algorithm?: ECDSA } = { | ||
masterAddress: undefined, | ||
algorithm: undefined, | ||
} | ||
// Use secp256k1 since that's the algorithm used by popular wallets like Xumm when generating secret number accounts | ||
if (opts === undefined) { | ||
updatedOpts.algorithm = ECDSA.secp256k1 | ||
} else { | ||
updatedOpts.masterAddress = opts.masterAddress | ||
updatedOpts.algorithm = opts.algorithm ?? ECDSA.secp256k1 | ||
} | ||
return Wallet.fromSecret(secret, updatedOpts) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters