Skip to content

Commit

Permalink
Add sign method to handle signing requests in the API endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Inkvi committed Dec 6, 2024
1 parent a5ed3d3 commit 50ca469
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ kmsProvider.setPath({
keyRingId: keyRingId
});

function bigintToBuffer(bigint: bigint): Buffer {
const hex = bigint.toString(16);
return Buffer.from(hex.padStart(hex.length + (hex.length % 2), '0'), 'hex');
}

app.post('/', async (request, reply) => {
const {method, params} = request.body as { method: string, params: any };

Expand All @@ -55,6 +60,10 @@ app.post('/', async (request, reply) => {
return;
case 'health_status':
return reply.code(200).send({result: 'ok'});
case 'sign':
const signature = await wallets.ecsign({keyId: keyId}, Buffer.from(params[0].slice(2), 'hex'), 1);
const res = Buffer.concat([signature.r, signature.s, bigintToBuffer(signature.v)]).toString('hex');
return reply.code(200).send({result: res});
default:
reply.code(400).send({error: 'Method not supported'});
}
Expand Down

0 comments on commit 50ca469

Please sign in to comment.