MCPcopy
hub / github.com/BlueWallet/BlueWallet / toString

Method toString

blue_modules/ur/index.js:283–372  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

281 bbqrParts = {}; // key-value, payload->1
282
283 toString() {
284 if (Object.keys(this.bbqrParts).length > 0) {
285 // its BBQR, handle differently
286 const decodedBbqr = joinQRs(Object.keys(this.bbqrParts));
287 if (decodedBbqr.fileType === 'P') {
288 // if its psbt we return base64:
289 return uint8ArrayToBase64(decodedBbqr.raw);
290 }
291
292 // for everything else we covnert bytes to string directly
293 return uint8ArrayToString(decodedBbqr.raw);
294 }
295
296 const decoded = this.resultUR();
297
298 if (decoded.type === 'crypto-psbt') {
299 const cryptoPsbt = CryptoPSBT.fromCBOR(decoded.cbor);
300 return cryptoPsbt.getPSBT().toString('base64');
301 }
302
303 if (decoded.type === 'bytes') {
304 const bytes = Bytes.fromCBOR(decoded.cbor);
305 const data = bytes.getData();
306 return uint8ArrayToString(data);
307 }
308
309 if (decoded.type === 'crypto-account') {
310 const cryptoAccount = CryptoAccount.fromCBOR(decoded.cbor);
311
312 const results = [];
313 for (const outputDescriptor of cryptoAccount.outputDescriptors) {
314 // now, crafting zpub out of data we have
315 const hdKey = outputDescriptor.getCryptoKey();
316 const derivationPath = 'm/' + hdKey.getOrigin().getPath();
317 const script = cryptoAccount.outputDescriptors[0].getScriptExpressions()[0].getExpression();
318 const isMultisig =
319 script === ScriptExpressions.WITNESS_SCRIPT_HASH.getExpression() ||
320 // fallback to paths (unreliable).
321 // dont know how to add ms p2sh (legacy) or p2sh-p2wsh (wrapped segwit) atm
322 derivationPath === MultisigHDWallet.PATH_LEGACY ||
323 derivationPath === MultisigHDWallet.PATH_WRAPPED_SEGWIT ||
324 derivationPath === MultisigHDWallet.PATH_NATIVE_SEGWIT;
325 const version = hexToUint8Array(isMultisig ? '02aa7ed3' : '04b24746');
326 const parentFingerprint = hdKey.getParentFingerprint();
327 const depth = hdKey.getOrigin().getDepth();
328 const depthBuf = new Uint8Array(1);
329 depthBuf[0] = depth;
330 const components = hdKey.getOrigin().getComponents();
331 const lastComponents = components[components.length - 1];
332 const index = lastComponents.isHardened() ? lastComponents.getIndex() + 0x80000000 : lastComponents.getIndex();
333 const indexBuf = new Uint8Array(4);
334 new DataView(indexBuf.buffer).setUint32(0, index, false); // big-endian
335 const chainCode = hdKey.getChainCode();
336 const key = hdKey.getKey();
337 const data = concatUint8Arrays([version, depthBuf, parentFingerprint, indexBuf, chainCode, key]);
338
339 const zpub = b58.encode(data);
340

Callers 15

AmountInputFunction · 0.80
setIsHandOffUseEnabledFunction · 0.80
removeTrailingZerosFunction · 0.80
formatBalanceFunction · 0.80
formatBalancePlainFunction · 0.80
SelectFeeScreenFunction · 0.80
ReceiveDetailsFunction · 0.80
ScanLNDInvoiceFunction · 0.80

Calls 10

joinQRsFunction · 0.90
uint8ArrayToBase64Function · 0.90
uint8ArrayToStringFunction · 0.90
hexToUint8ArrayFunction · 0.90
concatUint8ArraysFunction · 0.90
uint8ArrayToHexFunction · 0.90
keysMethod · 0.80
getPathMethod · 0.80
getMasterFingerprintMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected