Invocation Path
-
Dapp request
personal_sign
1const msg = `0x${Buffer.from(exampleMessage, 'utf8').toString('hex')}` console.log({ msg }) const networkId = networkDiv.innerHTML const extraParams = { networkId } const sign = await window.starcoin.request({ method: 'personal_sign', // params: [msg, from, 'Example password'], // extraParams = params[2] || {}; means it should be an object: // params: [msg, from, { pwd: 'Example password' }], params: [msg, from, extraParams], })
-
Starmask handling request
signPersonalMessage
Conclusion
Message signed at keyring:
/**
* Sign Personal Message
*
* Attempts to sign the provided message paramaters.
* Prefixes the hash before signing per the personal sign expectation.
*
* @param {Object} msgParams - The message parameters to sign.
* @returns {Promise<Buffer>} The raw signature.
*/
signPersonalMessage(msgParams, opts = {}) {
const address = normalizeAddress(msgParams.from)
return this.getKeyringForAccount(address)
.then((keyring) => {
return keyring.signPersonalMessage(address, msgParams.rawData, opts)
})
}
The rawData
is built at2:
const rawData = Buffer.from(stripHexPrefix(cleanMsgParams.data), 'hex').toString('utf8')
Then the getEd25519SignMsgBytes will be invoked:
export function getEd25519SignMsgBytes(
signingMessage: SigningMessage,
): bytes {
const hasher = createSigningMessageHasher();
const hashSeedBytes = hasher.get_salt();
const signingMessageBytes = (function () {
const se = new BcsSerializer();
signingMessage.serialize(se);
return se.getBytes();
})();
const msgBytes = ((a, b) => {
const tmp = new Uint8Array(a.length + b.length);
tmp.set(a, 0);
tmp.set(b, a.length);
return tmp;
})(hashSeedBytes, signingMessageBytes);
return msgBytes;
}
The msgBytes
is the combination of hashSeedBytes
and message itself.
-
https://github.com/starcoinorg/starmask-extension/blob/0b8f2c796f3bb45f5dcf46a0ead650fd51e14b2c/app/scripts/metamask-controller.js#L1688-L1691 ↩︎ ↩︎
-
https://github.com/starcoinorg/stc-keyring-controller/blob/master/index.js#L385-L400 ↩︎
-
https://github.com/starcoinorg/stc-keyring-controller/blob/master/index.js#L12-L20 ↩︎
-
https://github.com/starcoinorg/starmask-extension/blob/0b8f2c796f3bb45f5dcf46a0ead650fd51e14b2c/app/scripts/metamask-controller.js#L1695 ↩︎
-
https://github.com/starcoinorg/starcoin.js/blob/a9b21262f9550cb98aaf7bf9f7ef2d5d2967fc7a/src/utils/signed-message.ts#L55-L67 ↩︎