CryptoHDkey
The CryptoHDKey class represents hierarchical deterministic key information
This is an instruction provided by the OneKey hardware, which includes the extened public key information.
Parameters
- isMaster:- booleanWhether it is a master key.
- isPrivateKey:- booleanWhether it is a private key.
- key:- BufferThe key data.
- chainCode:- BufferThe chain code.
- useInfo:- CryptoCoinInfoUsage information.
- origin:- CryptoKeypathThe origin path.
- children:- CryptoKeypathThe children path.
- parentFingerprint:- BufferThe parent fingerprint.
- name:- stringThe name. optional
- note:- Note(string)The note. optional- 'account.standard' : BIP44 Standard account 
- "account.ledger_live" : Ledger Live account 
- "account.ledger_legacy" : Ledger Legacy account 
 
URL Example
UR:CRYPTO-HDKEY/PDAXHDCLAOZTRDKBTKFPRFKBCWVEWYBGDPNTCPVLEOENJSWMBKFTLTRESNWTNLTLMKJYVYMWBSAAHDCXCSBNNLLNBZIAJZTPKPPKJOSTCEZSJEKGYKJOCSKNHFTPSWTIGHVABDIEGTBWWLTEAHTAADEHOYADCSFNAMTAADDYOYADLNCSDWYKCSFNYKAEYKATTAADDYOYADLRAEWKLAWKAYAEASINFPIAIAJLKPJTJYCXEHBKKOGHISINJKCXINJKCXHSCExample
import { URRegistryDecoder } from '@onekeyfe/hd-air-gap-sdk'
const decoder = new URRegistryDecoder();
// for scan qr
while (!decoder.isSuccess()){
    const UR = ScanQRCode();
    decoder.receivePart(UR);
}
if(decoder.isSuccess()) {
    const cryptoHDkey = decoder.resultRegistryType();
    
    const name = cryptoHDKey.getName();
    const note = cryptoHDKey.getNote();
    
    const extendPubKey = hdKey.getKey();
    const chainCode = hdKey.getChainCode();
    
    const xpub = hdKey.getBip32Key();
    const childrenPath = hdKey.getChildren()?.getPath() ?? DEFAULT_CHILDREN_PATH;
    const hdPath = `m/${cryptoHDKey.getOrigin().getPath()}`;
    // This parameter is required for subsequent eth sign request assembly.
    const xfp = cryptoHDKey.getOrigin().getSourceFingerprint()?.toString("hex");
    
    // derive child
    const accountIndex = 0
    const derivePath = childrenPath
            .replace("*", String(accountIndex))
            .replace(/\*/g, "0");
    
    const hdk = HDKey.fromExtendedKey(xpub);
    const dkey = hdk.derive(`m/${derivePath}`);
    const address =
            "0x" + publicToAddress(dkey.publicKey, true).toString("hex");
    const addressWithChecksum = toChecksumAddress(address);
} else if(decoder.isError()){
    // logic for error handling
    throw new Error() 
}Last updated
Was this helpful?
