Skip to content

Commit

Permalink
Merge pull request #49 from leirbag95/issue/solana-signature
Browse files Browse the repository at this point in the history
Signing a message on solana fixed
  • Loading branch information
BjrInt authored Nov 3, 2022
2 parents 7b717d9 + 31ad279 commit 16121a7
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions src/api/solana.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,34 @@ function get_verification_buffer(message) {

export async function provider_sign(provider, message) {
let buffer = get_verification_buffer(message)
let signed = await provider._sendRequest('signTransaction', {
message: base58.encode(buffer),
});
return JSON.stringify(signed)
let signature;
if (typeof(provider.signTransaction) === 'function') {
signature = await provider.request({
method: "signMessage",
params: {
message: buffer
}
})
}
else if (typeof(provider._sendRequest) === 'function') {
try {
signature = await provider._sendRequest('signTransaction', {
message: base58.encode(buffer)
})
if (!signature) {
throw new Error('JSONRPC method not implemented')
}
} catch (error) {
console.log(error)
}
}
else{
throw new Error('Provider has no signing method')
}
return JSON.stringify({
signature: signature.signature,
publicKey: provider.publicKey.toString()
})
}

export async function pkey_sign(secretKey, address, message) {
Expand Down

0 comments on commit 16121a7

Please sign in to comment.