Created
May 25, 2017 04:57
-
-
Save akirattii/7f8b1e268f7b958ed880adf996f2e76e to your computer and use it in GitHub Desktop.
Function: Parses bitcoin protocol link
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const querystring = require('querystring'); | |
/** | |
* Parses "bitcoin:****" link | |
* | |
* @param {String} - link. | |
* eg: "bitcoin:1LRm2ebiM7S8Li3DXYj7N2QzyewQ36Deoh?amount=1&message=%EF%BC%BC(%5Eo%5E)%EF%BC%8F%EF%BD%B5%EF%BE%9C%EF%BE%80" | |
* @return {Object} - `{ link, to, amount, message }` | |
* Note: `message` is uri-decoded | |
*/ | |
function parseProtocolLink(link) { | |
let r = /^bitcoin:([a-zA-Z0-9]{27,34})(?:\?(.*))?$/; | |
let match = r.exec(link); | |
if (!match) return null; | |
let parsed = querystring.parse(match[2]); | |
parsed.address = match[1]; | |
return parsed; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment