1
1
/* eslint-disable @typescript-eslint/no-non-null-assertion */
2
2
import { openTransportReplayer , RecordStore } from "@ledgerhq/hw-transport-mocker" ;
3
3
import { TransportReplayer } from "@ledgerhq/hw-transport-mocker/lib/openTransportReplayer" ;
4
+ import SpeculosTransport from "../speculosTransport" ;
4
5
import ecc from "tiny-secp256k1" ;
5
6
import { getXpubComponents , pathArrayToString } from "../../src/bip32" ;
6
7
import AcreBtcNew from "../../src/AcreBtcNew" ;
@@ -57,9 +58,10 @@ test("testSignMessage", async () => {
57
58
await testSignMessageReplayer ( "m/44'/0'/0'" ) ;
58
59
} ) ;
59
60
60
- test ( "signWithdrawal" , async ( ) => {
61
- await testSignWithdrawalReplayer ( ) ;
62
- } ) ;
61
+
62
+ test ( "Sign ERC-4361 message" , async ( ) => {
63
+ await testSignERC4361Speculos ( ) ;
64
+ } , 60 * 10 * 1000 ) ; // 10-minute timeout (60 seconds * 10 minutes * 1000 milliseconds)
63
65
64
66
function testPaths ( type : StandardPurpose ) : { ins : string [ ] ; out ?: string } {
65
67
const basePath = `m/${ type } /1'/0'/` ;
@@ -228,6 +230,16 @@ async function testSignWithdrawalReplayer() {
228
230
} ) ;
229
231
}
230
232
233
+ async function testSignERC4361Speculos ( ) {
234
+ const transport = new SpeculosTransport ( 'http://localhost:5000' )
235
+ const client = new AppClient ( transport ) ;
236
+ const acreBtcNew = new AcreBtcNew ( client ) ;
237
+ const message = "stake.acre.fi wants you to sign in with your Bitcoin account:\nbc1q8fq0vs2f9g52cuk8px9f664qs0j7vtmx3r7wvx\n\n\nURI: https://stake.acre.fi\nVersion: 1\nNonce: cw73Kfdfn1lY42Jj8\nIssued At: 2024-10-01T11:03:05.707Z\nExpiration Time: 2024-10-08T11:03:05.707Z"
238
+ const path = "m/44'/0'/0'/0/0" ;
239
+ const result = await acreBtcNew . signERC4361Message ( { messageHex : Buffer . from ( message ) . toString ( "hex" ) , path : path } ) ;
240
+ console . log ( result ) ;
241
+ }
242
+
231
243
function verifyGetWalletPublicKeyResult (
232
244
result : { publicKey : string ; bitcoinAddress : string ; chainCode : string } ,
233
245
expectedXpub : string ,
@@ -318,4 +330,4 @@ class MockClient extends TestingClient {
318
330
) : string {
319
331
return walletPolicy . serialize ( ) . toString ( "hex" ) + change + addressIndex ;
320
332
}
321
- }
333
+ }
0 commit comments