@ledgerhq/hw-transport-u2f
Advanced tools
Comparing version 1.2.0-beta.b4ba11b7 to 1.2.0-beta.df091f88
@@ -44,22 +44,2 @@ "use strict"; | ||
const normal64 = base64 => base64.replace(/-/g, "+").replace(/_/g, "/") + "==".substring(0, 3 * base64.length % 4); | ||
function u2fPromise(response, statusList) { | ||
const { signatureData } = response; | ||
return new Promise((resolve, reject) => { | ||
if (typeof signatureData === "string") { | ||
const data = Buffer.from(normal64(signatureData), "base64"); | ||
if (typeof statusList !== "undefined") { | ||
const sw = data.readUInt16BE(data.length - 2); | ||
const statusFound = statusList.some(s => s === sw); | ||
if (!statusFound) { | ||
reject("Invalid status " + sw.toString(16)); | ||
} | ||
} | ||
resolve(data.toString("hex", 5)); | ||
} else { | ||
reject(response); | ||
} | ||
}); | ||
} | ||
/** | ||
@@ -87,4 +67,3 @@ * U2F web Transport implementation | ||
exchange(apduHex, statusList) { | ||
const apdu = Buffer.from(apduHex, "hex"); | ||
exchange(apdu) { | ||
const keyHandle = wrapApdu(apdu, this.scrambleKey); | ||
@@ -98,3 +77,11 @@ const challenge = Buffer.from("0000000000000000000000000000000000000000000000000000000000000000", "hex"); | ||
}; | ||
return (0, _u2fApi.sign)(signRequest, this.timeoutSeconds).then(result => u2fPromise(result, statusList)); | ||
return (0, _u2fApi.sign)(signRequest, this.timeoutSeconds).then(response => { | ||
const { signatureData } = response; | ||
if (typeof signatureData === "string") { | ||
const data = Buffer.from(normal64(signatureData), "base64"); | ||
return data.slice(5); | ||
} else { | ||
throw response; | ||
} | ||
}); | ||
} | ||
@@ -114,6 +101,6 @@ | ||
TransportU2F.discover = observer => { | ||
TransportU2F.listen = observer => { | ||
let unsubscribed = false; | ||
(0, _u2fApi.isSupported)().then(supported => { | ||
if (!unsubscribed && supported) observer.next(null); | ||
if (!unsubscribed && supported) observer.next({ type: "add", descriptor: null }); | ||
}); | ||
@@ -120,0 +107,0 @@ return { |
{ | ||
"name": "@ledgerhq/hw-transport-u2f", | ||
"version": "1.2.0-beta.b4ba11b7", | ||
"version": "1.2.0-beta.df091f88", | ||
"description": "Ledger Hardware Wallet Web implementation of the communication layer, using U2F api", | ||
@@ -29,3 +29,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@ledgerhq/hw-transport": "^1.2.0-beta.b4ba11b7", | ||
"@ledgerhq/hw-transport": "^1.2.0-beta.df091f88", | ||
"u2f-api": "^0.2.7" | ||
@@ -32,0 +32,0 @@ }, |
@@ -41,22 +41,2 @@ /******************************************************************************** | ||
"==".substring(0, (3 * base64.length) % 4); | ||
function u2fPromise(response, statusList) { | ||
const { signatureData } = response; | ||
return new Promise((resolve, reject) => { | ||
if (typeof signatureData === "string") { | ||
const data = Buffer.from(normal64(signatureData), "base64"); | ||
if (typeof statusList !== "undefined") { | ||
const sw = data.readUInt16BE(data.length - 2); | ||
const statusFound = statusList.some(s => s === sw); | ||
if (!statusFound) { | ||
reject("Invalid status " + sw.toString(16)); | ||
} | ||
} | ||
resolve(data.toString("hex", 5)); | ||
} else { | ||
reject(response); | ||
} | ||
}); | ||
} | ||
/** | ||
@@ -75,6 +55,7 @@ * U2F web Transport implementation | ||
static discover = (observer: *) => { | ||
static listen = (observer: *) => { | ||
let unsubscribed = false; | ||
isSupported().then(supported => { | ||
if (!unsubscribed && supported) observer.next(null); | ||
if (!unsubscribed && supported) | ||
observer.next({ type: "add", descriptor: null }); | ||
}); | ||
@@ -103,4 +84,3 @@ return { | ||
exchange(apduHex: string, statusList: Array<number>): Promise<string> { | ||
const apdu = Buffer.from(apduHex, "hex"); | ||
exchange(apdu: Buffer): Promise<Buffer> { | ||
const keyHandle = wrapApdu(apdu, this.scrambleKey); | ||
@@ -117,5 +97,11 @@ const challenge = Buffer.from( | ||
}; | ||
return sign(signRequest, this.timeoutSeconds).then(result => | ||
u2fPromise(result, statusList) | ||
); | ||
return sign(signRequest, this.timeoutSeconds).then(response => { | ||
const { signatureData } = response; | ||
if (typeof signatureData === "string") { | ||
const data = Buffer.from(normal64(signatureData), "base64"); | ||
return data.slice(5); | ||
} else { | ||
throw response; | ||
} | ||
}); | ||
} | ||
@@ -122,0 +108,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
27106
452