Skip to content

Commit 168fad1

Browse files
committed
Merge branch 'develop' into feature/deprecated-crypto-warning
* develop: Update bitcoinjs-lib -- includes improvements to the native secp256k1 depedencies Update to typed `jsontokens` lib, fix all typing errors # Conflicts: # package-lock.json # package.json # tsconfig.browser.json # tsconfig.json
2 parents 9584daa + 0ee8292 commit 168fad1

13 files changed

Lines changed: 143 additions & 86 deletions

‎mdincludes/script-dist-file.md‎

Lines changed: 0 additions & 3 deletions
This file was deleted.

‎package-lock.json‎

Lines changed: 67 additions & 48 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@
8787
"@babel/preset-typescript": "^7.3.3",
8888
"@babel/register": "^7.0.0",
8989
"@types/cheerio": "^0.22.10",
90-
"@types/elliptic": "^6.4.5",
9190
"@types/fetch-mock": "^5.8.0",
9291
"@types/form-data": "^2.2.1",
9392
"@types/node": "^10",
@@ -130,15 +129,16 @@
130129
},
131130
"dependencies": {
132131
"@types/bn.js": "^4.11.5",
132+
"@types/elliptic": "^6.4.9",
133133
"ajv": "^4.11.5",
134134
"bip39": "^3.0.2",
135-
"bitcoinjs-lib": "^5.0.5",
135+
"bitcoinjs-lib": "^5.1.2",
136136
"bn.js": "^4.11.8",
137137
"cheerio": "^0.22.0",
138138
"cross-fetch": "^2.2.2",
139139
"elliptic": "^6.4.1",
140140
"form-data": "^2.3.3",
141-
"jsontokens": "^1.0.0",
141+
"jsontokens": "^2.0.2",
142142
"query-string": "^6.3.0",
143143
"request": "^2.88.0",
144144
"ripemd160": "^2.0.2",

‎src/auth/authApp.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,9 @@ export async function handlePendingSignIn(
296296
}
297297
if (!nameLookupURL) {
298298
const tokenPayload = decodeToken(authResponseToken).payload
299+
if (typeof tokenPayload === 'string') {
300+
throw new Error('Unexpected token payload type of string')
301+
}
299302
if (isLaterVersion(tokenPayload.version, '1.3.0')
300303
&& tokenPayload.blockstackAPIUrl !== null && tokenPayload.blockstackAPIUrl !== undefined) {
301304
// override globally
@@ -311,6 +314,10 @@ export async function handlePendingSignIn(
311314
throw new LoginFailedError('Invalid authentication response.')
312315
}
313316
const tokenPayload = decodeToken(authResponseToken).payload
317+
if (typeof tokenPayload === 'string') {
318+
throw new Error('Unexpected token payload type of string')
319+
}
320+
314321
// TODO: real version handling
315322
let appPrivateKey = tokenPayload.private_key
316323
let coreSessionToken = tokenPayload.core_token

‎src/auth/authProvider.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ export function fetchAppManifest(authRequest: string): Promise<any> {
4040
reject('Invalid auth request')
4141
} else {
4242
const payload = decodeToken(authRequest).payload
43+
if (typeof payload === 'string') {
44+
throw new Error('Unexpected token payload type of string')
45+
}
4346
const manifestURI = payload.manifest_uri
4447
try {
4548
Logger.debug(`Fetching manifest from ${manifestURI}`)
@@ -75,6 +78,9 @@ export function fetchAppManifest(authRequest: string): Promise<any> {
7578
*/
7679
export function redirectUserToApp(authRequest: string, authResponse: string) {
7780
const payload = decodeToken(authRequest).payload
81+
if (typeof payload === 'string') {
82+
throw new Error('Unexpected token payload type of string')
83+
}
7884
let redirectURI = payload.redirect_uri
7985
Logger.debug(redirectURI)
8086
if (redirectURI) {

‎src/auth/authSession.ts‎

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -135,33 +135,34 @@ export function getCoreSession(coreHost: string,
135135
return Promise.reject('No authRequest provided')
136136
}
137137

138-
let payload = null
139-
let authRequestObject = null
140138
try {
141-
authRequestObject = decodeToken(authRequest)
139+
const authRequestObject = decodeToken(authRequest)
142140
if (!authRequestObject) {
143141
return Promise.reject('Invalid authRequest in URL query string')
144142
}
145143
if (!authRequestObject.payload) {
146144
return Promise.reject('Invalid authRequest in URL query string')
147145
}
148-
payload = authRequestObject.payload
146+
const payload = authRequestObject.payload
147+
if (typeof payload === 'string') {
148+
throw new Error('Unexpected token payload type of string')
149+
}
150+
151+
const appDomain = payload.domain_name
152+
if (!appDomain) {
153+
return Promise.reject('No domain_name in authRequest')
154+
}
155+
const appMethods = payload.scopes
156+
157+
const coreAuthRequest = makeCoreSessionRequest(
158+
appDomain, appMethods, appPrivateKey, blockchainId, deviceId
159+
)
160+
161+
return sendCoreSessionRequest(
162+
coreHost, corePort, coreAuthRequest, apiPassword
163+
)
149164
} catch (e) {
150165
console.error(e.stack)
151166
return Promise.reject('Failed to parse authRequest in URL')
152167
}
153-
154-
const appDomain = payload.domain_name
155-
if (!appDomain) {
156-
return Promise.reject('No domain_name in authRequest')
157-
}
158-
const appMethods = payload.scopes
159-
160-
const coreAuthRequest = makeCoreSessionRequest(
161-
appDomain, appMethods, appPrivateKey, blockchainId, deviceId
162-
)
163-
164-
return sendCoreSessionRequest(
165-
coreHost, corePort, coreAuthRequest, apiPassword
166-
)
167168
}

0 commit comments

Comments
 (0)