Skip to content

Commit

Permalink
Feature: Support signing in the provider (#218)
Browse files Browse the repository at this point in the history
* support eth_sign/personal_sign in safe-apps-provider

* include dist files

* Add gitattributes file to ignore dist files in diff

* fix gitattrs

* fix format-dist in safe-apps-sdk to work on linux
  • Loading branch information
mmv08 authored Sep 20, 2021
1 parent 833501f commit 8d86ff2
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/healthy-experts-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@gnosis.pm/safe-apps-provider': minor
---

support eth_sign and personal_sign
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist linguist-generated=true
26 changes: 22 additions & 4 deletions packages/safe-apps-provider/dist/provider.js

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

2 changes: 1 addition & 1 deletion packages/safe-apps-provider/dist/provider.js.map

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

24 changes: 24 additions & 0 deletions packages/safe-apps-provider/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,30 @@ export class SafeAppProvider implements EIP1193Provider {
case 'eth_chainId':
return `0x${this.chainId.toString(16)}`;

case 'personal_sign': {
const [message, address] = params;

if (this.safe.safeAddress.toLowerCase() !== address.toLowerCase()) {
throw new Error('The address or message hash is invalid');
}

await this.sdk.txs.signMessage(message);

return '0x';
}

case 'eth_sign': {
const [address, messageHash] = params;

if (this.safe.safeAddress.toLowerCase() !== address.toLowerCase() || !messageHash.startsWith('0x')) {
throw new Error('The address or message hash is invalid');
}

await this.sdk.txs.signMessage(messageHash);

return '0x';
}

case 'eth_sendTransaction':
const tx = {
value: '0',
Expand Down
16 changes: 8 additions & 8 deletions packages/safe-apps-react-sdk/dist/index.js

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

2 changes: 1 addition & 1 deletion packages/safe-apps-react-sdk/dist/index.js.map

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

4 changes: 2 additions & 2 deletions packages/safe-apps-sdk/dist/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gnosis.pm/safe-apps-sdk",
"version": "4.3.0-next.1",
"version": "4.3.0-next.2",
"description": "SDK developed to integrate third-party apps with Safe-Multisig app.",
"main": "dist/src/index.js",
"typings": "dist/src/index.d.ts",
Expand All @@ -15,7 +15,7 @@
],
"scripts": {
"test": "jest",
"format-dist": "sed -i '' 's/\"files\":/\"_files\":/' dist/package.json",
"format-dist": "sed -i 's/\"files\":/\"_files\":/' dist/package.json",
"build": "yarn rimraf dist && tsc && yarn format-dist",
"lint": "tslint -p tsconfig.json"
},
Expand Down
Loading

0 comments on commit 8d86ff2

Please sign in to comment.