Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: typed data params #13

Merged
merged 1 commit into from
Jan 11, 2024
Merged
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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@haqq/provider-ledger-react-native",
"version": "0.0.24",
"version": "0.0.25",
"description": "Provider for react-native ledger",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -34,7 +34,7 @@
"react-native-ble-plx": "*"
},
"devDependencies": {
"@haqq/provider-base": "^0.0.18",
"@haqq/provider-base": "0.0.20",
"@types/jest": "^29.4.0",
"@types/node": "^18.14.1",
"@types/react-native": "^0.71.3",
Expand Down
9 changes: 6 additions & 3 deletions src/provider.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import {TransactionRequest} from '@ethersproject/abstract-provider';
import {
compressPublicKey,
prepareHashedEip712Data,
stringToUtf8Bytes,
BytesLike,
Provider,
ProviderInterface,
TypedData,
} from '@haqq/provider-base';
import AppEth, {ledgerService} from '@ledgerhq/hw-app-eth';
import TransportBLE from '@ledgerhq/react-native-hw-transport-ble';
Expand Down Expand Up @@ -148,7 +150,7 @@ export class ProviderLedgerReactNative
return resp;
}

async signTypedData(hdPath: string, domainHash: string, valuesHash: string) {
async signTypedData(hdPath: string, typedData: TypedData) {
let resp = '';
try {
this.stop = false;
Expand All @@ -165,10 +167,11 @@ export class ProviderLedgerReactNative

const eth = new AppEth(transport);

const {domainSeparatorHex, hashStructMessageHex} = prepareHashedEip712Data(typedData);
const signature = await eth.signEIP712HashedMessage(
hdPath,
domainHash,
valuesHash,
domainSeparatorHex,
hashStructMessageHex,
);

const v = (signature.v - 27).toString(16).padStart(2, '0');
Expand Down
9 changes: 5 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1184,12 +1184,13 @@
dependencies:
"@hapi/hoek" "^9.0.0"

"@haqq/provider-base@^0.0.18":
version "0.0.18"
resolved "https://registry.yarnpkg.com/@haqq/provider-base/-/provider-base-0.0.18.tgz#aa5cc0ed43ef0d19a0fe7f667cde7f7d0b365619"
integrity sha512-JUFMkYZkz/QIujpVUDqpM+PYf0jj2Cazty1Zb4MgTY9HWoaWBbXnD2YKLRXA6LC2HaS1EPqcppX8RAoh5C/4jg==
"@haqq/[email protected].20":
version "0.0.20"
resolved "https://registry.yarnpkg.com/@haqq/provider-base/-/provider-base-0.0.20.tgz#34d3d6c8a564da54f60c5586da1ef2efb4bec713"
integrity sha512-UUbuLzZN/GH5K50NY8DDHNUaJ3u0DEVnNq/8JGmloTxlMGkYP+nHikXAKA6jXDapToNmFQEjjqtUCkHA17ri3w==
dependencies:
bech32-converting "^1.0.9"
ethers "^5.7.2"
events "^3.3.0"

"@istanbuljs/load-nyc-config@^1.0.0":
Expand Down
Loading