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 signMessage without random #5

Open
wants to merge 1 commit into
base: main
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/background/controller/provider/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ class ProviderController extends BaseController {
@Reflect.metadata('APPROVAL', ['SignText', () => {
// todo check text
}])
signMessage = async ({ data: { params: { text, type } } }) => {
signMessage = async ({ data: { params: { text, type, withRandom } } }) => {
if (type === 'bip322-simple') {
return wallet.signBIP322Simple(text)
} else {
return wallet.signMessage(text)
return wallet.signMessage(text, withRandom)
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/background/controller/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -693,10 +693,10 @@ export class WalletController extends BaseController {
return psbt;
};

signMessage = async (text: string) => {
signMessage = async (text: string, withRandom = true) => {
const account = preferenceService.getCurrentAccount();
if (!account) throw new Error('no current account');
return keyringService.signMessage(account.pubkey, text);
return keyringService.signMessage(account.pubkey, text, withRandom);
};

// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
Expand Down
6 changes: 3 additions & 3 deletions src/background/service/keyring/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export interface Keyring {
getAccounts(): Promise<string[]>;
getAccountsAndIndexAndDType: () => Promise<tempAccount[]>;
signTransaction(psbt: any, inputs: ToSignInput[]): Promise<any>;
signMessage(address: string, message: string): Promise<string>;
signMessage(address: string, message: string, withRandom: boolean): Promise<string>;
verifyMessage(address: string, message: string, sig: string): Promise<boolean>;
exportAccount(address: string): Promise<string>;
removeAccount(address: string): void;
Expand Down Expand Up @@ -566,9 +566,9 @@ class KeyringService extends EventEmitter {
* Attempts to sign the provided message parameters.
* address here means publickey string
*/
signMessage = async (pubkey: string, data: string) => {
signMessage = async (pubkey: string, data: string, withRandom = true) => {
const keyring = await this.getKeyringForAccount(pubkey);
const sig = await keyring.signMessage(pubkey, data);
const sig = await keyring.signMessage(pubkey, data, withRandom);
return sig;
};

Expand Down
8 changes: 5 additions & 3 deletions src/background/service/keyringclass/simple-keyring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,12 @@ class SimpleKeyring {
await psbt.sign(privateKeys);
return psbt;
};
signMessage(publicKey: string, text: string) {
signMessage(publicKey: string, text: string, withRandom = true) {
const keyPair = this._getPrivateKeyFor(publicKey);
const { signMessage } = this.kaspaWasm;
const signature = signMessage({ message: text, privateKey: keyPair.privateKey.toString() });
const { signMessage, signMessageWithoutRand } = this.kaspaWasm;
const signature = withRandom
? signMessage({ message: text, privateKey: keyPair.privateKey.toString() })
: signMessageWithoutRand({ message: text, privateKey: keyPair.privateKey.toString() });
return Promise.resolve(signature);
}
verifyMessage(publicKey: string, message: string, signature: string) {
Expand Down
5 changes: 3 additions & 2 deletions src/content-script/pageProvider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,13 @@ export class KaswareProvider extends EventEmitter {
});
};

signMessage = async (text: string, type: string) => {
signMessage = async (text: string, type: string, withRandom = true) => {
return this._request({
method: 'signMessage',
params: {
text,
type
type,
withRandom
}
});
};
Expand Down