The CryptoHDKey
class represents hierarchical deterministic key information
This is an instruction provided by the OneKey hardware, which includes the extened public key information.
isMaster
:boolean
Whether it is a master key.isPrivateKey
:boolean
Whether it is a private key.key
:Buffer
The key data.chainCode
:Buffer
The chain code.useInfo
:CryptoCoinInfo
Usage information.origin
:CryptoKeypath
The origin path.children
:CryptoKeypath
The children path.parentFingerprint
:Buffer
The parent fingerprint.name
:string
The name. optionalnote
:Note(string)
The note. optional- 'account.standard' : BIP44 Standard account
- "account.ledger_live" : Ledger Live account
- "account.ledger_legacy" : Ledger Legacy account
{% code overflow="wrap" %}
UR:CRYPTO-HDKEY/PDAXHDCLAOZTRDKBTKFPRFKBCWVEWYBGDPNTCPVLEOENJSWMBKFTLTRESNWTNLTLMKJYVYMWBSAAHDCXCSBNNLLNBZIAJZTPKPPKJOSTCEZSJEKGYKJOCSKNHFTPSWTIGHVABDIEGTBWWLTEAHTAADEHOYADCSFNAMTAADDYOYADLNCSDWYKCSFNYKAEYKATTAADDYOYADLRAEWKLAWKAYAEASINFPIAIAJLKPJTJYCXEHBKKOGHISINJKCXINJKCXHSC
{% endcode %}
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()
}