-
Notifications
You must be signed in to change notification settings - Fork 777
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
Support SeedSigner SeedQR format for importing HD seeds #4959
Comments
do they have a js implementation? |
I couldn't find a JS implementation. |
well, looks like someone will have to write one. |
@Overtorment It doesn't need a whole library, just a quick helper function: const encodeCompactSeedQR = (wallet) => {
// private key or recovery phrase
// this assumes you get recovery phrase
const phrase = wallet.getSecret();
const data = phrase
// convert the words into an array
.split(' ')
// get the binary value of the index of each word, left padded
// this assumes wordList is an array of BIP39 words
.map((word) => wordList.indexOf(word).toString(2).padStart(11, '0'))
// concatenate the binary sting values together
.join('')
// group them into bytes as an array
.match(/[01]{8}/g)
// convert from binary string to number[]
.map((bin) => parseInt(bin, 2))
// remove the checksum bits to leave 16 bytes for 12 words and
// 32 bytes for 24 words
.slice(0, (parseInt(phrase.split(' ').length) * 32) / 3 / 8);
return [{ data, mode: 'byte' }]
}
// usage in your code base:
<QRCodeComponent
isMenuAvailable={false}
value={encodeCompactSeedQR(wallet)}
size={qrCodeSize}
logoSize={70}
/> I would not put a logo on it though. The point of seedQR is to reduce the number of QR Code modules to make it easier to transcribe your seed to paper or metal so probably set To scan compact SeedQR, you will just get bytes which you can add the checksum. You can then prompt the user for their BIP39 passphrase and generate an HD wallet in the usual way from there, that is to say that if the scanned seedQR is 128-bits it's a 12 word seed and if it is 256-bits it's a 24 word seed. Hope that helps. |
Great. Now need a decode func, I think it's more important, so backed up stuff can be imported into a hot wallet |
Sure, I'll take a look at your QR scanner lib docs and post something later |
SeedQR is also supported in Sparrow Wallet and I have a PR that's currently being reviewed to add it to Specter Desktop. It's also in the Foundation Device's Passport to-do list. The conversation here thus far has been around the more difficult Compact SeedQR format, but don't forget about the much easier Standard SeedQR format, which is just the BIP-39 wordlist indices of each word in the mnemonic.
|
My Specter Desktop PR is limited to Standard SeedQR only at the moment as the Specter QR decoder can't handle the binary format. So your work here could be a two-for-one if we leverage it in Specter Desktop, too. |
well, compact qr would be more interesing |
After doing a bit of digging through the code, it looks like BW is using react-native-camera which has been deprecated for about a year. Best bet might be to see what is in I realise that this is not the right place to put a scan for seedQR as it is a scan to pay someone, but I wanted to find an example of where scanning was used in the app. How the UX is done for that is up to you :) According to this So firstly, in any relevant wallet class, add a new method: generateFromCompactSeedQR(hexString) {
this.secret = bip39.entropyToMnemonic(hexString);
} Then, for example, in /screen/wallets/add.js Line 148ish where a user has created a wallet without entropy, before generating it for them, maybe prompt the user if they would like to scan a Compact seedQR or generate a brand new wallet - again, you are best placed to know where to add it to the UX. Next the user scans the Compact SeedQR and you call If To support standard SeedQR you will get the index numbers, get the words from the indices and call |
maybe even allow for both kinds in the method... generateFromSeedQR(qrString) {
try {
// compact seedQR should be between 32 - 64 chars long in hex format
if (qrString.length === 64 || qrString.length === 32) {
this.secret = bip39.entropyToMnemonic(hexString);
} else if (qrString.length === 96 || qrString.length === 48) { // standard seedQR
const words = qrString.match(/[\d]{4}/g)
.map(num => wordList[parseInt(num)])
.join(' ');
this.secret = words;
} else throw new Error('invalid QR');
} catch(e) {
// do something with e
}
} |
I'm trying to import this test QR codes but only the standard version works, the compact one isn't read |
I'd like to propose adding SeedQR import support for the Add Wallet->Import Wallet screen. Other than SeedSigner, there's now support in (at least) Blockstream Jade, Specter DYI.
The text was updated successfully, but these errors were encountered: