Skip to content

Commit

Permalink
something
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterBenc committed Aug 3, 2020
1 parent 5fba8db commit de785e8
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 34 deletions.
53 changes: 35 additions & 18 deletions app/frontend/wallet/shelley/shelley-trezor-crypto-provider.ts
Expand Up @@ -8,9 +8,7 @@ import debugLog from '../../helpers/debugLog'
const CardanoTrezorCryptoProvider = ({network, config}) => {
const derivationScheme = derivationSchemes.v2

const TrezorConnect = config.ADALITE_TREZOR_CONNECT_URL
? (window as any).TrezorConnect
: require('../../libs/trezor-connect-local').default
const TrezorConnect = require('../../libs/trezor-connect-local').default

TrezorConnect.manifest({
email: ADALITE_SUPPORT_EMAIL,
Expand Down Expand Up @@ -78,7 +76,7 @@ const CardanoTrezorCryptoProvider = ({network, config}) => {
function prepareInput(input, addressToAbsPathMapper): CardanoTxInputType {
const data = {
address_n: addressToAbsPathMapper(input.address),
prev_hash: Buffer.from(input.txHash, 'hex'),
prev_hash: Buffer.from(input.txid, 'hex'),
prev_index: input.outputIndex,
}

Expand Down Expand Up @@ -106,27 +104,33 @@ const CardanoTrezorCryptoProvider = ({network, config}) => {
return {
type: cert.type,
path: addressToAbsPathMapper(cert.accountAddress),
pool: Buffer.from(cert.poolHash, 'hex'),
pool: cert.poolHash ? Buffer.from(cert.poolHash, 'hex') : null,
}
}

async function signTx(unsignedTx, rawInputTxs, addressToAbsPathMapper) {
const inputs = []
const _inputs = []
for (const input of unsignedTx.inputs) {
inputs.push(await prepareInput(input, addressToAbsPathMapper))
const data = prepareInput(input, addressToAbsPathMapper)
_inputs.push(data)
}
const inputs = await Promise.all(_inputs)

const outputs = []
const _outputs = []
for (const output of unsignedTx.outputs) {
const data = await prepareOutput(output, addressToAbsPathMapper)
outputs.push(data)
const data = prepareOutput(output, addressToAbsPathMapper)
_outputs.push(data)
}
const outputs = await Promise.all(_outputs)

const certificates = []
for (const cert of unsignedTx.certs) {
const data = await prepareCertificate(cert, addressToAbsPathMapper)
const data = prepareCertificate(cert, addressToAbsPathMapper)
certificates.push(data)
}

const fee = `${unsignedTx.fee.fee}`
const ttl = `${unsignedTx.ttl.ttl}`
const withdrawals = []
const metadata = null

Expand All @@ -140,7 +144,7 @@ const CardanoTrezorCryptoProvider = ({network, config}) => {
// withdrawals: List[CardanoTxWithdrawalType] = None,
// metadata: bytes = None,

console.log({
console.log('\n\n\n\n\n\n\n', {
inputs,
outputs,
protocol_magic: network.protocolMagic,
Expand All @@ -154,14 +158,26 @@ const CardanoTrezorCryptoProvider = ({network, config}) => {
const response = await TrezorConnect.cardanoSignTransaction({
inputs,
outputs,
protocol_magic: network.protocolMagic,
fee: unsignedTx.fee,
ttl: unsignedTx.ttl,
network_id: network.networkId,
certificates,
protocolMagic: network.protocolMagic,
fee,
ttl,
networkId: network.networkId,
// certificates,
// withdrawals,
// metadata,
}).catch((e) => console.log(e))
}).catch((e) =>
console.log(e, {
inputs,
outputs,
protocolMagic: network.protocolMagic,
fee: unsignedTx.fee.fee,
ttl: unsignedTx.ttl.ttl,
networkId: network.networkId,
certificates,
// withdrawals,
// metadata,
})
)

if (response.error || !response.success) {
debugLog(response)
Expand Down Expand Up @@ -202,6 +218,7 @@ const CardanoTrezorCryptoProvider = ({network, config}) => {
getHwWalletName,
_sign: sign,
_deriveHdNode: deriveHdNode,
network,
}
}

Expand Down
37 changes: 21 additions & 16 deletions app/public/js/init.js
Expand Up @@ -56,22 +56,27 @@ function loadScript(success) {
document.getElementsByTagName('head')[0].appendChild(mainScriptTag)
} else {
// display fallback HTML for browsers that fail the check
document.write(
'<!doctype html>' +
'<html>' +
'<head>' +
'<title>AdaLite - Cardano Wallet</title>' +
'<link rel="icon" type="image/ico" href="assets/favicon.ico">' +
'</head>' +
'<body>' +
'Unsupported browser. Please try updating it or install the latest version of a supported one. We recommend trying:' +
'<ul>' +
'<li><a href="https://www.google.com/chrome">Google Chrome</a></li>' +
'<li><a href="https://www.mozilla.org/en-US/firefox">Firefox</a></li>' +
'</ul>' +
'</body>' +
'</html>'
)
const mainScriptTag = document.createElement('script')
mainScriptTag.type = 'text/javascript'
mainScriptTag.src = 'js/frontend.bundle.js'
mainScriptTag.setAttribute('defer', '')
document.getElementsByTagName('head')[0].appendChild(mainScriptTag)
// document.write(
// '<!doctype html>' +
// '<html>' +
// '<head>' +
// '<title>AdaLite - Cardano Wallet</title>' +
// '<link rel="icon" type="image/ico" href="assets/favicon.ico">' +
// '</head>' +
// '<body>' +
// 'Unsupported browser. Please try updating it or install the latest version of a supported one. We recommend trying:' +
// '<ul>' +
// '<li><a href="https://www.google.com/chrome">Google Chrome</a></li>' +
// '<li><a href="https://www.mozilla.org/en-US/firefox">Firefox</a></li>' +
// '</ul>' +
// '</body>' +
// '</html>'
// )
}
}

Expand Down

0 comments on commit de785e8

Please sign in to comment.