Skip to content

Commit a17e485

Browse files
authored
feat: add challenge sign request (#20)
1 parent af6b2d4 commit a17e485

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

examples/demo/index.html

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ <h1 class="text-3xl font-bold text-center text-blue-600 mb-6">Mintlayer Wallet D
6969
<button onclick="toggleSection('createDelegation')" class="bg-gray-200 text-gray-700 py-2 px-4 rounded-md hover:bg-gray-300 transition">Create Delegation</button>
7070
<button onclick="toggleSection('delegationStake')" class="bg-gray-200 text-gray-700 py-2 px-4 rounded-md hover:bg-gray-300 transition">Delegation Stake</button>
7171
<button onclick="toggleSection('delegationWithdraw')" class="bg-gray-200 text-gray-700 py-2 px-4 rounded-md hover:bg-gray-300 transition">Delegation Withdraw</button>
72+
<button onclick="toggleSection('signChallenge')" class="bg-gray-200 text-gray-700 py-2 px-4 rounded-md hover:bg-gray-300 transition">Sign Challenge</button>
7273
</div>
7374

7475
<!-- Transfer Section -->
@@ -317,6 +318,16 @@ <h3 class="text-lg font-semibold text-gray-700 mb-4">Delegation Withdraw</h3>
317318
<button onclick="delegationWithdraw()" class="bg-green-500 text-white py-2 px-4 rounded-md shadow hover:bg-green-600 transition w-full">Withdraw</button>
318319
</div>
319320
</div>
321+
322+
<!-- Sign Challenge Section -->
323+
<div id="signChallenge" class="bg-white p-6 rounded-lg shadow-md hidden">
324+
<h3 class="text-lg font-semibold text-gray-700 mb-4">Sign Challenge</h3>
325+
<div class="space-y-4">
326+
<input type="text" id="sign_challenge_address" placeholder="Address (optional)" class="w-full border border-gray-300 rounded-md p-2 focus:ring-2 focus:ring-blue-500 focus:outline-none" />
327+
<input type="text" id="sign_challenge_message" placeholder="Message" class="w-full border border-gray-300 rounded-md p-2 focus:ring-2 focus:ring-blue-500 focus:outline-none" />
328+
<button onclick="signChallenge()" class="bg-green-500 text-white py-2 px-4 rounded-md shadow hover:bg-green-600 transition w-full">Sign Challenge</button>
329+
</div>
330+
</div>
320331
</div>
321332
</div>
322333

@@ -340,7 +351,7 @@ <h3 class="text-xl font-semibold text-gray-700 mb-4">Output</h3>
340351
'lockTokenSupply', 'changeTokenAuthority', 'changeTokenMetadata', 'createOrder',
341352
'fillOrder', 'concludeOrder', 'bridgeRequest', 'broadcastTx', 'freezeToken',
342353
'unfreezeToken', 'burn', 'dataDeposit', 'createDelegation', 'delegationStake',
343-
'delegationWithdraw'
354+
'delegationWithdraw', 'signChallenge'
344355
];
345356
sections.forEach(id => {
346357
const el = document.getElementById(id);
@@ -893,6 +904,23 @@ <h3 class="text-xl font-semibold text-gray-700 mb-4">Output</h3>
893904
}
894905
}
895906

907+
async function signChallenge () {
908+
const address = document.getElementById('sign_challenge_address').value;
909+
const message = document.getElementById('sign_challenge_message').value;
910+
911+
if (!message) {
912+
displayOutput('Please provide a message to sign.');
913+
return;
914+
}
915+
916+
try {
917+
const { signature } = await window.mintlayer.signChallenge({ address, message });
918+
displayOutput(`Signature: ${JSON.stringify(signature, null, 2)}`);
919+
} catch (error) {
920+
displayOutput(`Error: ${error.message}`);
921+
}
922+
}
923+
896924
if (window.mintlayer) displayOutput('Mintlayer Connect SDK detected!');
897925
else displayOutput('Mintlayer Connect SDK not found.');
898926
</script>

packages/sdk/src/mintlayer-connect-sdk.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,17 @@ export type BridgeRequestArgs = {
722722
intent: string;
723723
};
724724

725+
export type SignChallengeArgs = {
726+
message: string;
727+
address?: string;
728+
}
729+
730+
export type SignChallengeResponse = {
731+
message: string;
732+
address: string;
733+
signature: string;
734+
}
735+
725736
class Client {
726737
private network: 'mainnet' | 'testnet';
727738
private connectedAddresses: {
@@ -2779,6 +2790,22 @@ class Client {
27792790
});
27802791
}
27812792

2793+
/**
2794+
* Signs a challenge message with the given address.
2795+
* Used to prove ownership of the address.
2796+
* @param args
2797+
*/
2798+
async signChallenge(args: SignChallengeArgs): Promise<SignChallengeResponse> {
2799+
this.ensureInitialized();
2800+
return this.request({
2801+
method: 'signChallenge',
2802+
params: {
2803+
message: args.message,
2804+
address: args.address,
2805+
},
2806+
});
2807+
}
2808+
27822809
/**
27832810
* Returns a preview of UTXO changes (spent/created) for a built transaction.
27842811
*

0 commit comments

Comments
 (0)