import { buildTransaction, getHolaParameters, getHolaParameters_LINK, buildERC20Transaction, getERC20HolaParameters, extractSignature, getERC20HolaParameters_LINK, verifyAddress, buildERC721Transaction, buildERC1155Transaction } from "."; import { hexToBytes } from "./TransactionHelper"; import * as mocha from 'mocha'; import * as chai from 'chai'; import { Network } from "./types"; const expect = chai.expect; describe('hw_eth address verification tests', () => { it('Should verify Ethereum address correctly' , () => { expect(verifyAddress("0x34c3e76432d9842cfe2bb6c882dad2b43505baaa")) .to.equal(true); }); it('Should fail verify Ethereum address correctly' , () => { expect(verifyAddress("0x34c3e76432d9842cfe2bb6c882dad2b43505baa")) .to.equal(false); }); it('Should fail verify Ethereum address correctly' , () => { expect(verifyAddress("0x34c3e76432d9842cfe2bb6c882dad2b4350ybaaa")) .to.equal(false); }); }); describe('hw_eth transaction building tests', () => { it('Should build unsigned Ethereum transaction correctly' , () => { expect(buildTransaction({nonce : "0", gasPrice: "50", gasLimit: 21000, toAddress: "0x34c3e76432d9842cfe2bb6c882dad2b43505baaa", amount: "0.05", network: Network.Testnet}).toString('hex')) .to.equal("02f00580850ba43b7400850ba43b74008252089434c3e76432d9842cfe2bb6c882dad2b43505baaa87b1a2bc2ec5000080c0"); }); let rD = hexToBytes("BBB2D06AB85B3AB1AF13560E2A18BB0E36DE6465FEE34C96953D28241F5E6724"); let sD = hexToBytes("57FB79AE09A7DA48693F4D8F861CA96CD71BD629DDEA972A181C5F65B5F56AF9"); it('Should build signed Ethereum transaction correctly' , () => { expect(buildTransaction({nonce : "0", gasPrice: "50", gasLimit: 21000, toAddress: "0x34c3e76432d9842cfe2bb6c882dad2b43505baaa", amount: "0.05", signature: {v:0x1C, r: rD, s: sD}, network: Network.Testnet}).toString('hex')) .to.equal("02f8730580850ba43b7400850ba43b74008252089434c3e76432d9842cfe2bb6c882dad2b43505baaa87b1a2bc2ec5000080c01ca0bbb2d06ab85b3ab1af13560e2a18bb0e36de6465fee34c96953d28241f5e6724a057fb79ae09a7da48693f4d8f861ca96cd71bd629ddea972a181c5f65b5f56af9"); }); }); describe('hw_eth transaction with data building tests', () => { it('Should build unsigned Ethereum transaction with data correctly' , () => { expect(buildTransaction({nonce : "338", gasPrice: "129.090672713", gasLimit: 142999, toAddress: "0x68b3465833fb72a70ecdf485e0e4c7bd8665fc45", amount: "0", data: Buffer.from("5ae401dc0000000000000000000000000000000000000000000000000000000061e16c0200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000e404e45aaf000000000000000000000000f4d2888d29d722226fafa5d9b24f9164c092421e000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000002710000000000000000000000000f4fe6141e8f9c614cfa6fd9c8f8b139ae3c249fe00000000000000000000000000000000000000000000001dfa72b234f63c29ee00000000000000000000000000000000000000000000000007df0f7fb8fd1856000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "hex"), network: Network.Mainnet}).toString('hex')) .to.equal("02f901d201820152851e0e675849851e0e67584983022e979468b3465833fb72a70ecdf485e0e4c7bd8665fc4580b901a45ae401dc0000000000000000000000000000000000000000000000000000000061e16c0200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000e404e45aaf000000000000000000000000f4d2888d29d722226fafa5d9b24f9164c092421e000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000002710000000000000000000000000f4fe6141e8f9c614cfa6fd9c8f8b139ae3c249fe00000000000000000000000000000000000000000000001dfa72b234f63c29ee00000000000000000000000000000000000000000000000007df0f7fb8fd1856000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0"); }); let rD = hexToBytes("f250e73b59a556a2c4089018b9c85c75acaf7ced8a89b48a6abf1ebdfbbc7266"); let sD = hexToBytes("67095cab0e53940b96fe68a28d497d395074b7aca5e264f6222cf1161ee08c"); it('Should build signed Ethereum transaction with data correctly' , () => { expect(buildTransaction({nonce : "338", gasPrice: "129.090672713", gasLimit: 142999, toAddress: "0x68b3465833fb72a70ecdf485e0e4c7bd8665fc45", amount: "0", data: Buffer.from("5ae401dc0000000000000000000000000000000000000000000000000000000061e16c0200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000e404e45aaf000000000000000000000000f4d2888d29d722226fafa5d9b24f9164c092421e000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000002710000000000000000000000000f4fe6141e8f9c614cfa6fd9c8f8b139ae3c249fe00000000000000000000000000000000000000000000001dfa72b234f63c29ee00000000000000000000000000000000000000000000000007df0f7fb8fd1856000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "hex"), signature: {v:0x00, r: rD, s: sD}, network: Network.Mainnet}).toString('hex')) .to.equal("02f9021401820152851e0e675849851e0e67584983022e979468b3465833fb72a70ecdf485e0e4c7bd8665fc4580b901a45ae401dc0000000000000000000000000000000000000000000000000000000061e16c0200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000e404e45aaf000000000000000000000000f4d2888d29d722226fafa5d9b24f9164c092421e000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000002710000000000000000000000000f4fe6141e8f9c614cfa6fd9c8f8b139ae3c249fe00000000000000000000000000000000000000000000001dfa72b234f63c29ee00000000000000000000000000000000000000000000000007df0f7fb8fd1856000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c080a0f250e73b59a556a2c4089018b9c85c75acaf7ced8a89b48a6abf1ebdfbbc72669f67095cab0e53940b96fe68a28d497d395074b7aca5e264f6222cf1161ee08c"); }); }); describe('hw_eth HOLa parameters generation tests', () => { it('Should generate HOLa parameters correctly' , () => { let parameters = getHolaParameters({nonce : "0", gasPrice: "50", gasLimit: 21000, toAddress: "0x34c3e76432d9842cfe2bb6c882dad2b43505baaa", amount: "0.05", network: Network.Testnet}); expect(parameters.blk[0].toString('hex')) .to.equal("02f00580850ba43b7400850ba43b74008252089434c3e76432d9842cfe2bb6c882dad2b43505baaa87b1a2bc2ec5000080c0"); let correctU32Data = [2,5]; let u32cont = 0 for(let u32 of parameters.u32){ expect(u32).to.equal(correctU32Data[u32cont]); u32cont++; } }); }); describe('hw_eth HOLa parameters generation tests (LINK)', () => { it('Should generate HOLa parameters correctly (LINK)' , () => { let parameters = getHolaParameters_LINK({nonce : "0", gasPrice: "50", gasLimit: 21000, toAddress: "0x34c3e76432d9842cfe2bb6c882dad2b43505baaa", amount: "0.05", network: Network.Testnet}); expect(parameters.blk[0].toString('hex')) .to.equal("8bc0e89948426cbaf53d82e757141ce2469577cf8f3b54a660f89f04ce843942"); }); }); describe('hw_eth erc20 transaction building tests', () => { it('Should build unsigned Ethereum erc20 transaction correctly' , () => { expect(buildERC20Transaction({nonce: "6", gasPrice: "25", gasLimit: 53979, contractAddress: "0x101848d5c5bbca18e6b4431eedf6b95e9adf82fa", toAddress: "0x34c3e76432d9842cfe2bb6c882dad2b43505baaa", amount: "0.25", contractDecimals: 18, contractName: "WEENUS", network: Network.Testnet}).toString('hex')) .to.equal("02f86e05068505d21dba008505d21dba0082d2db94101848d5c5bbca18e6b4431eedf6b95e9adf82fa80b844a9059cbb00000000000000000000000034c3e76432d9842cfe2bb6c882dad2b43505baaa00000000000000000000000000000000000000000000000003782dace9d90000c0"); }); let reD = hexToBytes("832524266CD28331296739BA9E899625374539256A5D522CF3E3B8D1C799FE99"); let seD = hexToBytes("0CAE1939CC630EB25A144EA2E8C0E54071EBC5E17D33C3F35959B2B32FDACDE2"); it('Should build signed Ethereum erc20 transaction correctly' , () => { expect(buildERC20Transaction({nonce: "6", gasPrice: "25", gasLimit: 53979, contractAddress: "0x101848d5c5bbca18e6b4431eedf6b95e9adf82fa", toAddress: "0x34c3e76432d9842cfe2bb6c882dad2b43505baaa", amount: "0.25", contractDecimals: 18, contractName: "WEENUS", signature: {v: 0x25, r: reD ,s: seD}, network: Network.Testnet}).toString('hex')) .to.equal("02f8b105068505d21dba008505d21dba0082d2db94101848d5c5bbca18e6b4431eedf6b95e9adf82fa80b844a9059cbb00000000000000000000000034c3e76432d9842cfe2bb6c882dad2b43505baaa00000000000000000000000000000000000000000000000003782dace9d90000c025a0832524266cd28331296739ba9e899625374539256a5d522cf3e3b8d1c799fe99a00cae1939cc630eb25a144ea2e8c0e54071ebc5e17d33c3f35959b2b32fdacde2"); }); }); describe('hw_eth erc20 HOLa parameters generation tests', () => { it('Should generate erc20 HOLa parameters correctly' , () => { let parametersERC = getERC20HolaParameters({nonce: "6", gasPrice: "25", gasLimit: 53979, contractAddress: "0x101848d5c5bbca18e6b4431eedf6b95e9adf82fa", toAddress: "0x34c3e76432d9842cfe2bb6c882dad2b43505baaa", amount: "0.25", contractDecimals: 18, contractName: "WEENUS", network: Network.Testnet}); let correctBlkData = ["02f86e05068505d21dba008505d21dba0082d2db94101848d5c5bbca18e6b4431eedf6b95e9adf82fa80b844a9059cbb00000000000000000000000034c3e76432d9842cfe2bb6c882dad2b43505baaa00000000000000000000000000000000000000000000000003782dace9d90000c0","0de0b6b3a7640000", "205745454e5553"]; let blkCont = 0; for(let blk of parametersERC.blk){ expect(blk.toString('hex')).to.equal(correctBlkData[blkCont]); blkCont++; } let correctU32Data = [2,9,27]; let u32cont = 0 for(let u32 of parametersERC.u32){ expect(u32).to.equal(correctU32Data[u32cont]); u32cont++; } }); }); describe('hw_eth erc20 HOLa parameters generation tests (LINK)', () => { it('Should generate erc20 HOLa parameters correctly (LINK)' , () => { let parametersERC = getERC20HolaParameters_LINK({nonce: "6", gasPrice: "25", gasLimit: 53979, contractAddress: "0x101848d5c5bbca18e6b4431eedf6b95e9adf82fa", toAddress: "0x34c3e76432d9842cfe2bb6c882dad2b43505baaa", amount: "0.25", contractDecimals: 18, contractName: "WEENUS", network: Network.Testnet}); let correctBlkData = ["713bef9e87e11abcdd4deb115176f9bc7264e44c7f1860f007f72e012dfca3f2"]; let blkCont = 0; for(let blk of parametersERC.blk){ expect(blk.toString('hex')).to.equal(correctBlkData[blkCont]); blkCont++; } }); }); describe('hw_eth erc721 transaction building tests', () => { it('Should build unsigned Ethereum erc721 transaction correctly' , () => { expect(buildERC721Transaction({nonce: "6", gasPrice: "25", gasLimit: 53979, contractAddress: "0x101848d5c5bbca18e6b4431eedf6b95e9adf82fa", toAddress: "0x34c3e76432d9842cfe2bb6c882dad2b43505baaa", contractName: "WEENUS", network: Network.Testnet, fromAddress: "0x34c3e76432d9842cfe2bb6c882dad2b43505baaa", tokenId: "5"}).toString('hex')) .to.equal("02f88e05068505d21dba008505d21dba0082d2db94101848d5c5bbca18e6b4431eedf6b95e9adf82fa80b86423b872dd00000000000000000000000034c3e76432d9842cfe2bb6c882dad2b43505baaa00000000000000000000000034c3e76432d9842cfe2bb6c882dad2b43505baaa0000000000000000000000000000000000000000000000000000000000000005c0"); }); let reD = hexToBytes("832524266CD28331296739BA9E899625374539256A5D522CF3E3B8D1C799FE99"); let seD = hexToBytes("0CAE1939CC630EB25A144EA2E8C0E54071EBC5E17D33C3F35959B2B32FDACDE2"); it('Should build signed Ethereum erc721 transaction correctly' , () => { expect(buildERC721Transaction({nonce: "6", gasPrice: "25", gasLimit: 53979, contractAddress: "0x101848d5c5bbca18e6b4431eedf6b95e9adf82fa", toAddress: "0x34c3e76432d9842cfe2bb6c882dad2b43505baaa", contractName: "WEENUS", signature: {v: 0x25, r: reD ,s: seD}, network: Network.Testnet, fromAddress: "0x34c3e76432d9842cfe2bb6c882dad2b43505baaa", tokenId: "5"}).toString('hex')) .to.equal("02f8d105068505d21dba008505d21dba0082d2db94101848d5c5bbca18e6b4431eedf6b95e9adf82fa80b86423b872dd00000000000000000000000034c3e76432d9842cfe2bb6c882dad2b43505baaa00000000000000000000000034c3e76432d9842cfe2bb6c882dad2b43505baaa0000000000000000000000000000000000000000000000000000000000000005c025a0832524266cd28331296739ba9e899625374539256a5d522cf3e3b8d1c799fe99a00cae1939cc630eb25a144ea2e8c0e54071ebc5e17d33c3f35959b2b32fdacde2"); }); }); describe('hw_eth erc1155 transaction building tests', () => { it('Should build unsigned Ethereum erc1155 transaction correctly' , () => { expect(buildERC1155Transaction({nonce: "6", gasPrice: "25", gasLimit: 53979, contractAddress: "0x495f947276749ce646f68ac8c248420045cb7b5e", toAddress: "0x79988CB69f0dc1149D9E34F84AB66d2D7F166FB6", network: Network.Testnet, fromAddress: "0xa4bc5572fc35a640022b7389e6e71f55c858381b", tokenId: "56767374309758688074450992602783872732159676284467209334583681875753922723841"}).toString('hex')) .to.equal("02f8ee05068505d21dba008505d21dba0082d2db94495f947276749ce646f68ac8c248420045cb7b5e80b8c4f242432a000000000000000000000000a4bc5572fc35a640022b7389e6e71f55c858381b00000000000000000000000079988cb69f0dc1149d9e34f84ab66d2d7f166fb67d8131fb7b37cff82a74263d41f32fa8e41d5090000000000000020000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000c0"); }); let reD = hexToBytes("832524266CD28331296739BA9E899625374539256A5D522CF3E3B8D1C799FE99"); let seD = hexToBytes("0CAE1939CC630EB25A144EA2E8C0E54071EBC5E17D33C3F35959B2B32FDACDE2"); it('Should build signed Ethereum erc1155 transaction correctly' , () => { expect(buildERC1155Transaction({nonce: "6", gasPrice: "25", gasLimit: 53979, contractAddress: "0x495f947276749ce646f68ac8c248420045cb7b5e", toAddress: "0x79988CB69f0dc1149D9E34F84AB66d2D7F166FB6", signature: {v: 0x25, r: reD ,s: seD}, network: Network.Testnet, fromAddress: "0xa4bc5572fc35a640022b7389e6e71f55c858381b", tokenId: "56767374309758688074450992602783872732159676284467209334583681875753922723841"}).toString('hex')) .to.equal("02f9013105068505d21dba008505d21dba0082d2db94495f947276749ce646f68ac8c248420045cb7b5e80b8c4f242432a000000000000000000000000a4bc5572fc35a640022b7389e6e71f55c858381b00000000000000000000000079988cb69f0dc1149d9e34f84ab66d2d7f166fb67d8131fb7b37cff82a74263d41f32fa8e41d5090000000000000020000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000c025a0832524266cd28331296739ba9e899625374539256a5d522cf3e3b8d1c799fe99a00cae1939cc630eb25a144ea2e8c0e54071ebc5e17d33c3f35959b2b32fdacde2"); }); }); describe('hw_eth big transaction building tests', () => { it('Should build unsigned Ethereum transaction with big amount correctly' , () => { expect(buildTransaction({nonce : "0", gasPrice: "50", gasLimit: 21000, toAddress: "0x34c3e76432d9842cfe2bb6c882dad2b43505baaa", "amount": "117084665.25", network: Network.Testnet}).toString('hex')) .to.equal("02f40580850ba43b7400850ba43b74008252089434c3e76432d9842cfe2bb6c882dad2b43505baaa8b60d9a46be373e25e1d000080c0"); }); let rD = hexToBytes("BBB2D06AB85B3AB1AF13560E2A18BB0E36DE6465FEE34C96953D28241F5E6724"); let sD = hexToBytes("57FB79AE09A7DA48693F4D8F861CA96CD71BD629DDEA972A181C5F65B5F56AF9"); it('Should build signed Ethereum transaction with big amount correctly' , () => { expect(buildTransaction({nonce : "0", gasPrice: "50", gasLimit: 21000, toAddress: "0x34c3e76432d9842cfe2bb6c882dad2b43505baaa", "amount": "117084665.25", signature: {v:0x1C, r: rD, s: sD}, network: Network.Testnet}).toString('hex')) .to.equal("02f8770580850ba43b7400850ba43b74008252089434c3e76432d9842cfe2bb6c882dad2b43505baaa8b60d9a46be373e25e1d000080c01ca0bbb2d06ab85b3ab1af13560e2a18bb0e36de6465fee34c96953d28241f5e6724a057fb79ae09a7da48693f4d8f861ca96cd71bd629ddea972a181c5f65b5f56af9"); }); }); describe('hw_eth small transaction building tests', () => { it('Should build unsigned Ethereum transaction with small amount correctly' , () => { expect(buildTransaction({nonce : "0", gasPrice: "50", gasLimit: 21000, toAddress: "0x34c3e76432d9842cfe2bb6c882dad2b43505baaa", "amount": "0.000000000000000001", network: Network.Testnet}).toString('hex')) .to.equal("02e90580850ba43b7400850ba43b74008252089434c3e76432d9842cfe2bb6c882dad2b43505baaa0180c0"); }); let rD = hexToBytes("BBB2D06AB85B3AB1AF13560E2A18BB0E36DE6465FEE34C96953D28241F5E6724"); let sD = hexToBytes("57FB79AE09A7DA48693F4D8F861CA96CD71BD629DDEA972A181C5F65B5F56AF9"); it('Should build signed Ethereum transaction with small amount correctly' , () => { expect(buildTransaction({nonce : "0", gasPrice: "50", gasLimit: 21000, toAddress: "0x34c3e76432d9842cfe2bb6c882dad2b43505baaa", "amount": "0.000000000000000001", signature: {v:0x1C, r: rD, s: sD}, network: Network.Testnet}).toString('hex')) .to.equal("02f86c0580850ba43b7400850ba43b74008252089434c3e76432d9842cfe2bb6c882dad2b43505baaa0180c01ca0bbb2d06ab85b3ab1af13560e2a18bb0e36de6465fee34c96953d28241f5e6724a057fb79ae09a7da48693f4d8f861ca96cd71bd629ddea972a181c5f65b5f56af9"); }); }); describe('hw_eth erc20 big transaction building tests', () => { it('Should build unsigned Ethereum erc20 transaction with big amount correctly' , () => { expect(buildERC20Transaction({nonce: "6", gasPrice: "25", gasLimit: 53979, contractAddress: "0x101848d5c5bbca18e6b4431eedf6b95e9adf82fa", toAddress: "0x34c3e76432d9842cfe2bb6c882dad2b43505baaa", amount: "117084665.25", contractDecimals: 18, contractName: "WEENUS", network: Network.Testnet}).toString('hex')) .to.equal("02f86e05068505d21dba008505d21dba0082d2db94101848d5c5bbca18e6b4431eedf6b95e9adf82fa80b844a9059cbb00000000000000000000000034c3e76432d9842cfe2bb6c882dad2b43505baaa00000000000000000000000000000000000000000060d9a46be373e25e1d0000c0"); }); let reD = hexToBytes("832524266CD28331296739BA9E899625374539256A5D522CF3E3B8D1C799FE99"); let seD = hexToBytes("0CAE1939CC630EB25A144EA2E8C0E54071EBC5E17D33C3F35959B2B32FDACDE2"); it('Should build signed Ethereum erc20 transaction with big amount correctly' , () => { expect(buildERC20Transaction({nonce: "6", gasPrice: "25", gasLimit: 53979, contractAddress: "0x101848d5c5bbca18e6b4431eedf6b95e9adf82fa", toAddress: "0x34c3e76432d9842cfe2bb6c882dad2b43505baaa", amount: "117084665.25", contractDecimals: 18, contractName: "WEENUS", signature: {v: 0x25, r: reD ,s: seD}, network: Network.Testnet}).toString('hex')) .to.equal("02f8b105068505d21dba008505d21dba0082d2db94101848d5c5bbca18e6b4431eedf6b95e9adf82fa80b844a9059cbb00000000000000000000000034c3e76432d9842cfe2bb6c882dad2b43505baaa00000000000000000000000000000000000000000060d9a46be373e25e1d0000c025a0832524266cd28331296739ba9e899625374539256a5d522cf3e3b8d1c799fe99a00cae1939cc630eb25a144ea2e8c0e54071ebc5e17d33c3f35959b2b32fdacde2"); }); }); describe('hw_eth erc20 small transaction building tests', () => { it('Should build unsigned Ethereum erc20 transaction with small amount correctly' , () => { expect(buildERC20Transaction({nonce: "6", gasPrice: "25", gasLimit: 53979, contractAddress: "0x101848d5c5bbca18e6b4431eedf6b95e9adf82fa", toAddress: "0x34c3e76432d9842cfe2bb6c882dad2b43505baaa", amount: "0.000000000000000001", contractName: "WEENUS", contractDecimals: 18, network: Network.Testnet}).toString('hex')) .to.equal("02f86e05068505d21dba008505d21dba0082d2db94101848d5c5bbca18e6b4431eedf6b95e9adf82fa80b844a9059cbb00000000000000000000000034c3e76432d9842cfe2bb6c882dad2b43505baaa0000000000000000000000000000000000000000000000000000000000000001c0"); }); let reD = hexToBytes("832524266CD28331296739BA9E899625374539256A5D522CF3E3B8D1C799FE99"); let seD = hexToBytes("0CAE1939CC630EB25A144EA2E8C0E54071EBC5E17D33C3F35959B2B32FDACDE2"); it('Should build signed Ethereum erc20 transaction with small amount correctly' , () => { expect(buildERC20Transaction({nonce: "6", gasPrice: "25", gasLimit: 53979, contractAddress: "0x101848d5c5bbca18e6b4431eedf6b95e9adf82fa", toAddress: "0x34c3e76432d9842cfe2bb6c882dad2b43505baaa", amount: "0.000000000000000001", contractName: "WEENUS", contractDecimals: 18, signature: {v: 0x25, r: reD ,s: seD}, network: Network.Testnet}).toString('hex')) .to.equal("02f8b105068505d21dba008505d21dba0082d2db94101848d5c5bbca18e6b4431eedf6b95e9adf82fa80b844a9059cbb00000000000000000000000034c3e76432d9842cfe2bb6c882dad2b43505baaa0000000000000000000000000000000000000000000000000000000000000001c025a0832524266cd28331296739ba9e899625374539256a5d522cf3e3b8d1c799fe99a00cae1939cc630eb25a144ea2e8c0e54071ebc5e17d33c3f35959b2b32fdacde2"); }); }); describe('hw_eth signature extraction tests', () => { it('Should extract v,r,s from a DER encoded signature' , () => { var e = Buffer.from("3045022100cbdfdf1c8e2ca101c513ec148d2debb56910c6c3811f5b65dc475fa3e2f61e08022078577310650f819271a8a13664838cc99ff583add6199a2988da4efbd94a7ce9", 'hex') var t = Buffer.from("F869038509502F900082C832946CE8DA28E2F864420840CF74474EFF5FD80E65B880B844A9059CBB00000000000000000000000034C3E76432D9842CFE2BB6C882DAD2B43505BAAA00000000000000000000000000000000000000000000000000038D7EA4C68000618080", 'hex') let sig = e; let message =t let signature = extractSignature({signature: sig, transaction: message, address: "0x1223de8a29a4820d3fed6a354f8d37c9efd9d943", net: Network.Testnet}) expect(signature.v) .to.equal(0); expect(signature.r.toString('hex')) .to.equal("cbdfdf1c8e2ca101c513ec148d2debb56910c6c3811f5b65dc475fa3e2f61e08"); expect(signature.s.toString('hex')) .to.equal("78577310650f819271a8a13664838cc99ff583add6199a2988da4efbd94a7ce9"); }); });