This repository has been archived by the owner on Oct 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
248 changed files
with
84,890 additions
and
76,214 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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Diff not rendered.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Oops, something went wrong.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Diff not rendered.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Oops, something went wrong.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Diff not rendered.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Oops, something went wrong.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Oops, something went wrong.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
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,144 @@ | ||
/** ****************************************************************************** | ||
* (c) 2020 Zondax GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
******************************************************************************* */ | ||
|
||
import Zemu, { DEFAULT_START_OPTIONS } from '@zondax/zemu' | ||
import { newKusamaApp } from '@zondax/ledger-substrate' | ||
import { APP_SEED, models } from './common' | ||
|
||
// @ts-expect-error missing typings | ||
import ed25519 from 'ed25519-supercop' | ||
import { blake2bFinal, blake2bInit, blake2bUpdate } from 'blakejs' | ||
import { txBalances_transfer, txSession_setKeys, txStaking_nominate, txProxy_proxy, txUtility_batch } from './zemu_blobs' | ||
|
||
const defaultOptions = { | ||
...DEFAULT_START_OPTIONS, | ||
logging: true, | ||
custom: `-s "${APP_SEED}"`, | ||
X11: false, | ||
} | ||
|
||
jest.setTimeout(180000) | ||
|
||
const TXNS = [ | ||
{ | ||
name: 'balances_transfer', | ||
blob: txBalances_transfer, | ||
}, | ||
{ | ||
name: 'session_setkeys', | ||
blob: txSession_setKeys, | ||
}, | ||
{ | ||
name: 'staking_nominate', | ||
blob: txStaking_nominate, | ||
}, | ||
{ | ||
name: 'proxy_proxy', | ||
blob: txProxy_proxy, | ||
}, | ||
{ | ||
name: 'txUtility_batch', | ||
blob: txUtility_batch, | ||
}, | ||
] | ||
|
||
describe.each(TXNS)('Transactions', function (data) { | ||
test.concurrent.each(models)(`Test: ${data.name}`, async function (m) { | ||
const sim = new Zemu(m.path) | ||
try { | ||
await sim.start({ ...defaultOptions, model: m.name }) | ||
const app = newKusamaApp(sim.getTransport()) | ||
const pathAccount = 0x80000000 | ||
const pathChange = 0x80000000 | ||
const pathIndex = 0x80000000 | ||
|
||
const txBlob = Buffer.from(data.blob, 'hex') | ||
|
||
const responseAddr = await app.getAddress(pathAccount, pathChange, pathIndex) | ||
const pubKey = Buffer.from(responseAddr.pubKey, 'hex') | ||
|
||
// do not wait here.. we need to navigate | ||
const signatureRequest = app.sign(pathAccount, pathChange, pathIndex, txBlob) | ||
// Wait until we are not in the main menu | ||
await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot()) | ||
|
||
await sim.compareSnapshotsAndApprove('.', `${m.prefix.toLowerCase()}-${data.name}`) | ||
|
||
const signatureResponse = await signatureRequest | ||
console.log(signatureResponse) | ||
|
||
expect(signatureResponse.return_code).toEqual(0x9000) | ||
expect(signatureResponse.error_message).toEqual('No errors') | ||
|
||
// Now verify the signature | ||
let prehash = txBlob | ||
if (txBlob.length > 256) { | ||
const context = blake2bInit(32) | ||
blake2bUpdate(context, txBlob) | ||
prehash = Buffer.from(blake2bFinal(context)) | ||
} | ||
const valid = ed25519.verify(signatureResponse.signature.subarray(1), prehash, pubKey) | ||
expect(valid).toEqual(true) | ||
} finally { | ||
await sim.close() | ||
} | ||
}) | ||
}) | ||
|
||
test.concurrent.each(models)('balances transfer expert', async function (m) { | ||
const sim = new Zemu(m.path) | ||
try { | ||
await sim.start({ ...defaultOptions, model: m.name }) | ||
const app = newKusamaApp(sim.getTransport()) | ||
const pathAccount = 0x80000000 | ||
const pathChange = 0x80000000 | ||
const pathIndex = 0x80000000 | ||
|
||
// Change to expert mode | ||
await sim.toggleExpertMode() | ||
|
||
const txBlob = Buffer.from(txBalances_transfer, 'hex') | ||
|
||
const responseAddr = await app.getAddress(pathAccount, pathChange, pathIndex) | ||
const pubKey = Buffer.from(responseAddr.pubKey, 'hex') | ||
|
||
// do not wait here.. we need to navigate | ||
const signatureRequest = app.sign(pathAccount, pathChange, pathIndex, txBlob) | ||
|
||
// Wait until we are not in the main menu | ||
await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot()) | ||
|
||
await sim.compareSnapshotsAndApprove('.', `${m.prefix.toLowerCase()}-balances_transfer_expert`) | ||
|
||
const signatureResponse = await signatureRequest | ||
console.log(signatureResponse) | ||
|
||
expect(signatureResponse.return_code).toEqual(0x9000) | ||
expect(signatureResponse.error_message).toEqual('No errors') | ||
|
||
// Now verify the signature | ||
let prehash = txBlob | ||
if (txBlob.length > 256) { | ||
const context = blake2bInit(32) | ||
blake2bUpdate(context, txBlob) | ||
prehash = Buffer.from(blake2bFinal(context)) | ||
} | ||
const valid = ed25519.verify(signatureResponse.signature.subarray(1), prehash, pubKey) | ||
expect(valid).toEqual(true) | ||
} finally { | ||
await sim.close() | ||
} | ||
}) |
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
Oops, something went wrong.