-
Notifications
You must be signed in to change notification settings - Fork 622
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add v0.6.0 changes from individual repos
- Loading branch information
Showing
13 changed files
with
376 additions
and
176 deletions.
There are no files selected for viewing
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
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
2 changes: 0 additions & 2 deletions
2
...es/walletconnect-core/src/generate-key.js → ...ges/walletconnect-core/src/generateKey.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
/* global Promise */ | ||
|
||
import crypto from 'crypto' | ||
|
||
export default async function generateKey(n = 256 / 8) { | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import 'idempotent-babel-polyfill' | ||
|
||
import Connector from './connector' | ||
import Listener from './listener' | ||
import generateKey from './generate-key' | ||
import generateKey from './generateKey' | ||
|
||
export default { Connector, Listener, generateKey } | ||
export { Connector, Listener, generateKey } |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Parse EIP681 and EIP1328 standard URI formats | ||
// (c) Pedro Gomes <pedrouid@protonmail.com> | ||
// MIT License | ||
|
||
function parseRequiredParams(path, prefix, keys) { | ||
const required = { prefix } | ||
path = path.replace(`${prefix}-`, '') | ||
const values = path.split('@') | ||
keys.forEach((key, idx) => (required[key] = values[idx] || '')) | ||
return required | ||
} | ||
|
||
function parseParamsString(paramsString) { | ||
if (!paramsString) return {} | ||
|
||
let parameters = {} | ||
|
||
let pairs = (paramsString[0] === '?' | ||
? paramsString.substr(1) | ||
: paramsString | ||
).split('&') | ||
|
||
for (let i = 0; i < pairs.length; i++) { | ||
const key = pairs[i].match(/\w+(?==)/i) | ||
? pairs[i].match(/\w+(?==)/i)[0] | ||
: null | ||
const value = pairs[i].match(/=.+/i) | ||
? pairs[i].match(/=.+/i)[0].substr(1) | ||
: '' | ||
if (key) { | ||
parameters[decodeURIComponent(key)] = decodeURIComponent(value) | ||
} | ||
} | ||
return parameters | ||
} | ||
|
||
function parseStandardURI(string) { | ||
if (!string || typeof string !== 'string') { | ||
throw new Error('URI is not a string') | ||
} | ||
|
||
const pathStart = string.indexOf(':') | ||
|
||
const pathEnd = string.indexOf('?') | ||
|
||
const protocol = string.substring(0, pathStart) | ||
|
||
let required = {} | ||
|
||
let path = | ||
string.indexOf('?') !== -1 | ||
? string.substring(pathStart + 1, pathEnd) | ||
: string.substring(pathStart + 1) | ||
|
||
if (path.startsWith('pay')) { | ||
required = parseRequiredParams(path, 'pay', ['targetAddress', 'chainID']) | ||
} else if (path.startsWith('wc')) { | ||
required = parseRequiredParams(path, 'wc', ['sessionID', 'version']) | ||
} else { | ||
throw new Error('URI missing prefix') | ||
} | ||
|
||
const paramsString = | ||
string.indexOf('?') !== -1 ? string.substring(pathEnd) : '' | ||
|
||
const parameters = parseParamsString(paramsString) | ||
|
||
return { protocol, ...required, ...parameters } | ||
} | ||
|
||
export default parseStandardURI |
101 changes: 101 additions & 0 deletions
101
packages/walletconnect-core/src/parseStandardURIwithFallback.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// Parse EIP681 and EIP1328 standard URI formats | ||
// (c) Pedro Gomes <pedrouid@protonmail.com> | ||
// MIT License | ||
|
||
function parseRequiredParams(path, prefix, keys) { | ||
const required = { prefix } | ||
path = path.replace(`${prefix}-`, '') | ||
const values = path.split('@') | ||
keys.forEach((key, idx) => (required[key] = values[idx] || '')) | ||
return required | ||
} | ||
|
||
function parseRequiredFallback(path) { | ||
let required = {} | ||
let prefix = '' | ||
const values = path.split('@') | ||
values.forEach((value, idx) => { | ||
if (idx === 0) { | ||
if ( | ||
value.match( | ||
/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i | ||
) | ||
) { | ||
prefix = 'wc' | ||
required.prefix = prefix | ||
required.sessionID = value | ||
} else { | ||
prefix = 'pay' | ||
required.prefix = prefix | ||
required.targetAddress = value | ||
} | ||
} else if (idx === 1) { | ||
if (prefix === 'wc') { | ||
required.version = value | ||
} else if (prefix === 'pay') { | ||
required.chainID = value | ||
} | ||
} | ||
}) | ||
return required | ||
} | ||
|
||
function parseParamsString(paramsString) { | ||
if (!paramsString) return {} | ||
|
||
let parameters = {} | ||
|
||
let pairs = (paramsString[0] === '?' | ||
? paramsString.substr(1) | ||
: paramsString | ||
).split('&') | ||
|
||
for (let i = 0; i < pairs.length; i++) { | ||
const key = pairs[i].match(/\w+(?==)/i) | ||
? pairs[i].match(/\w+(?==)/i)[0] | ||
: null | ||
const value = pairs[i].match(/=.+/i) | ||
? pairs[i].match(/=.+/i)[0].substr(1) | ||
: '' | ||
if (key) { | ||
parameters[decodeURIComponent(key)] = decodeURIComponent(value) | ||
} | ||
} | ||
return parameters | ||
} | ||
|
||
function parseStandardURIwithFallback(string) { | ||
if (!string || typeof string !== 'string') { | ||
throw new Error('URI is not a string') | ||
} | ||
|
||
const pathStart = string.indexOf(':') | ||
|
||
const pathEnd = string.indexOf('?') | ||
|
||
const protocol = string.substring(0, pathStart) | ||
|
||
let required = {} | ||
|
||
let path = | ||
string.indexOf('?') !== -1 | ||
? string.substring(pathStart + 1, pathEnd) | ||
: string.substring(pathStart + 1) | ||
|
||
if (path.startsWith('pay')) { | ||
required = parseRequiredParams(path, 'pay', ['targetAddress', 'chainID']) | ||
} else if (path.startsWith('wc')) { | ||
required = parseRequiredParams(path, 'wc', ['sessionID', 'version']) | ||
} else { | ||
required = parseRequiredFallback(path) | ||
} | ||
|
||
const paramsString = | ||
string.indexOf('?') !== -1 ? string.substring(pathEnd) : '' | ||
|
||
const parameters = parseParamsString(paramsString) | ||
|
||
return { protocol, ...required, ...parameters } | ||
} | ||
|
||
export default parseStandardURIwithFallback |
Oops, something went wrong.