-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: keiff3r <[email protected]>
- Loading branch information
Showing
5 changed files
with
139 additions
and
65 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
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
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,40 @@ | ||
import Transport from "@ledgerhq/hw-transport"; | ||
import { log } from "@ledgerhq/logs"; | ||
import axios from "axios"; | ||
|
||
export default class SpeculosTransport extends Transport { | ||
speculosUrl: string; | ||
|
||
constructor(speculosUrl: string) { | ||
super(); | ||
this.speculosUrl = speculosUrl; | ||
} | ||
|
||
async exchange(_apdu: Buffer): Promise<Buffer> { | ||
try { | ||
log("apdu", "=>" + _apdu.toString("hex")); | ||
const response = await axios.post(`${this.speculosUrl}/apdu`, { | ||
data: _apdu.toString("hex"), | ||
}); | ||
log("apdu", "<=" + response.data.data); | ||
return Buffer.from(response.data.data, "hex"); | ||
} catch (error) { | ||
console.error("Error communicating with Speculos:", error); | ||
throw error; | ||
} | ||
} | ||
|
||
setScrambleKey() { | ||
// No need for scrambling in Speculos | ||
} | ||
|
||
async close() { | ||
// No cleanup needed for Speculos | ||
} | ||
} | ||
|
||
async function createSpeculosTransport( | ||
speculosUrl: string | ||
): Promise<Transport> { | ||
return new SpeculosTransport(speculosUrl); | ||
} |