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

feat: support EIP-7524 PLUME signatures #2047

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions _raw/locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,14 @@
"description": "Description"
}
},
"signPlume": {
"title": "Sign PLUME",
"message": "Message",
"createKey": {
"interactDapp": "Interact Dapp",
"description": "Description"
}
},
"securityEngine": {
"yes": "Yes",
"no": "No",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@rabby-wallet/eth-gnosis-keyring": "0.0.1",
"@rabby-wallet/eth-hd-keyring": "4.1.0",
"@rabby-wallet/eth-lattice-keyring": "1.0.5",
"@rabby-wallet/eth-simple-keyring": "5.0.1",
"@rabby-wallet/eth-simple-keyring": "5.1.0",
"@rabby-wallet/eth-trezor-keyring": "2.3.0",
"@rabby-wallet/eth-walletconnect-keyring": "2.0.4",
"@rabby-wallet/eth-watch-keyring": "1.0.0",
Expand Down
49 changes: 49 additions & 0 deletions src/background/controller/provider/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,55 @@ class ProviderController extends BaseController {
}
};

@Reflect.metadata('APPROVAL', [
'SignPlume',
({
data: {
params: [_, from],
},
}) => {
const currentAddress = preferenceService
.getCurrentAccount()
?.address.toLowerCase();
if (from.toLowerCase() !== currentAddress)
throw ethErrors.rpc.invalidParams(
'from should be same as current address'
);
},
])
ethGetPlumeSignature = async ({ data, approvalRes, session }) => {
if (!data.params) return;
const currentAccount = preferenceService.getCurrentAccount()!;
try {
const [msg, from] = data.params;
const keyring = await this._checkAddress(from);
const result = await keyringService.signPlumeMessage(
keyring,
{ data: msg, from },
approvalRes?.extra
);
signTextHistoryService.createHistory({
address: from,
text: msg,
origin: session.origin,
type: 'ethGetPlumeSignature',
});
reportSignText({
account: currentAccount,
method: 'ethGetPlumeSignature',
success: true,
});
return result;
} catch (e) {
reportSignText({
account: currentAccount,
method: 'ethGetPlumeSignature',
success: false,
});
throw e;
}
};

@Reflect.metadata('APPROVAL', [
'AddChain',
({
Expand Down
2 changes: 1 addition & 1 deletion src/background/controller/provider/rpcFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import stats from '@/stats';
import { addHexPrefix, stripHexPrefix } from 'ethereumjs-util';

const isSignApproval = (type: string) => {
const SIGN_APPROVALS = ['SignText', 'SignTypedData', 'SignTx'];
const SIGN_APPROVALS = ['SignText', 'SignTypedData', 'SignTx', 'SignPlume'];
return SIGN_APPROVALS.includes(type);
};

Expand Down
22 changes: 22 additions & 0 deletions src/background/controller/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2665,6 +2665,28 @@ export class WalletController extends BaseController {
return res;
};

signPlumeMessage = async (
type: string,
from: string,
data: string,
options?: any
) => {
const keyring = await keyringService.getKeyringForAccount(from, type);
const res = await keyringService.signPlumeMessage(
keyring,
{ from, data },
options
);
eventBus.emit(EVENTS.broadcastToUI, {
method: EVENTS.SIGN_FINISHED,
params: {
success: true,
data: res,
},
});
return res;
};

signTransaction = async (
type: string,
from: string,
Expand Down
15 changes: 15 additions & 0 deletions src/background/service/keyring/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,21 @@ export class KeyringService extends EventEmitter {
return keyring.signTypedData(address, msgParams.data, opts);
}

/**
* Sign PLUME Message
* (EIP 7524 https://github.com/ethereum/ERCs/pull/37/files?short_path=d698c69#diff-d698c694be4189f928935d8c63c0df0a03e5cca1521c388a97949dc0436dc4ca)
*
* Attempts to sign the message using the keyring of given address. The
* message data should be utf8 encoded.
*
* @param {Object} msgParams - The message parameters.
* @returns {Promise<Object>} The raw signature components.
*/
signPlumeMessage(keyring, msgParams, opts = {}) {
const address = normalizeAddress(msgParams.from);
return keyring.signPlumeMessage(address, msgParams.data, opts);
}

/**
* Get encryption public key
*
Expand Down
1 change: 1 addition & 0 deletions src/background/service/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const QUEUE_APPROVAL_COMPONENTS_WHITELIST = [
'SignTx',
'SignText',
'SignTypedData',
'SignPlume',
'LedgerHardwareWaiting',
'QRHardWareWaiting',
'WatchAddressWaiting',
Expand Down
3 changes: 2 additions & 1 deletion src/background/service/signTextHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export interface SignTextHistoryItem {
| 'ethSignTypedData'
| 'ethSignTypedDataV1'
| 'ethSignTypedDataV3'
| 'ethSignTypedDataV4';
| 'ethSignTypedDataV4'
| 'ethGetPlumeSignature';
}

interface SignTextHistoryStore {
Expand Down