Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 9
version: 10

- name: Install dependencies
run: pnpm install
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@
"bn.js": "^5.2.1",
"bs58check": "^4.0.0",
"buffer": "^6.0.3",
"cbor": "^10.0.2",
"cbor-bigdecimal": "^10.0.2",
"cbor2": "1.12.0",
"crc-32": "^1.2.2",
"elliptic": "6.6.1",
"hash.js": "^1.1.7",
Expand Down
35 changes: 7 additions & 28 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 20 additions & 23 deletions src/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ import { SignTypedDataVersion, TypedDataUtils } from '@metamask/eth-sig-util';
import { Hash } from 'ox';
import { RLP } from '@ethereumjs/rlp';
import * as secp256k1 from 'secp256k1';
import * as cbor from 'cbor2';
import {
TransactionSerializable,
serializeTransaction,
type Hex,
hexToNumber,
} from 'viem';
import {
type SigningPath,
type FirmwareConstants,
TransactionRequest,
TRANSACTION_TYPE,
} from './types';
import { buildGenericSigningMsgRequest } from './genericSigning';
import { TransactionSchema, type FlexibleTransaction } from './schemas';
import {
ASCII_REGEX,
HANDLE_LARGER_CHAIN_ID,
Expand All @@ -21,26 +36,8 @@ import {
splitFrames,
convertRecoveryToV,
} from './util';
import * as cbor from 'cbor';
import bdec from 'cbor-bigdecimal';
import {
TransactionSerializable,
serializeTransaction,
type Hex,
hexToNumber,
} from 'viem';
import {
type SigningPath,
type FirmwareConstants,
TransactionRequest,
TRANSACTION_TYPE,
} from './types';
import { buildGenericSigningMsgRequest } from './genericSigning';
import { TransactionSchema, type FlexibleTransaction } from './schemas';

bdec(cbor);

const buildEthereumMsgRequest = function (input) {
const buildEthereumMsgRequest = (input) => {
if (!input.payload || !input.protocol || !input.signerPath)
throw new Error(
'You must provide `payload`, `signerPath`, and `protocol` arguments in the messsage request',
Expand All @@ -67,7 +64,7 @@ const buildEthereumMsgRequest = function (input) {
}
};

const validateEthereumMsgResponse = function (res, req) {
const validateEthereumMsgResponse = (res, req) => {
const { signer, sig } = res;
const { input, msg, prehash = null } = req;
if (input.protocol === 'signPersonal') {
Expand Down Expand Up @@ -181,7 +178,7 @@ function normalizeTypedDataForHashing(value: any): any {
return value;
}

const buildEthereumTxRequest = function (data) {
const buildEthereumTxRequest = (data) => {
try {
let { chainId = 1 } = data;
const { signerPath, eip155 = null, fwConstants, type = null } = data;
Expand Down Expand Up @@ -497,7 +494,7 @@ function stripZeros(a) {

// Given a 64-byte signature [r,s] we need to figure out the v value
// and attah the full signature to the end of the transaction payload
const buildEthRawTx = function (tx, sig, address) {
const buildEthRawTx = (tx, sig, address) => {
// RLP-encode the data we sent to the lattice
const hash = Buffer.from(
Hash.keccak256(get_rlp_encoded_preimage(tx.rawTx, tx.type)),
Expand Down Expand Up @@ -1024,7 +1021,7 @@ function parseEIP712Item(data, type, forJSParser = false) {
}
} else if (type.slice(0, 5) === 'bytes') {
// Fixed sizes bytes need to be buffer type. We also add some sanity checks.
const nBytes = parseInt(type.slice(5));
const nBytes = Number.parseInt(type.slice(5));
data = ensureHexBuffer(data);
// Edge case to handle empty bytesN values
if (data.length === 0) {
Expand Down
Loading