function packAddress(derivationPath, xpub, hdPassphrase, derivationScheme) { validateBuffer(xpub, 64) validateDerivationScheme(derivationScheme) if (derivationScheme === 1) { validateArray(derivationPath) validateBuffer(hdPassphrase, 32) } let addressPayload, addressAttributes if (derivationScheme === 1 && derivationPath.length > 0) { addressPayload = encryptDerivationPath(derivationPath, hdPassphrase) addressAttributes = new Map([[1, cbor.encode(addressPayload)]]) } else { addressPayload = Buffer.from([]) addressAttributes = new Map() } const addressRoot = getAddressHash([ 0, [0, xpub], addressPayload.length > 0 ? new Map([[1, cbor.encode(addressPayload)]]) : new Map(), ]) const addressType = 0 // Public key address const addressData = [addressRoot, addressAttributes, addressType] const addressDataEncoded = cbor.encode(addressData) return base58.encode( cbor.encode([new cbor.Tagged(24, addressDataEncoded), crc32(addressDataEncoded)]) ) }
function encryptDerivationPath(derivationPath, hdPassphrase) { const serializedDerivationPath = cbor.encode(new CborIndefiniteLengthArray(derivationPath)) return chacha20poly1305Encrypt( serializedDerivationPath, hdPassphrase, Buffer.from('serokellfore') ) }
function getAddressHash(input) { // eslint-disable-next-line camelcase const firstHash = sha3_256(cbor.encode(input)) return blake2b(firstHash, 28) }