Skip to content

Commit f14c77f

Browse files
committed
added signMessage method to provider
1 parent a8b7f41 commit f14c77f

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export * from './src/address/index';
22
export * from './src/provider';
33
export * from './src/call';
44
export * from './src/transactions/signTransaction';
5+
export * from './src/signatures';

src/provider/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ import { SignTransactionResponse } from '../transactions/signTransaction';
22
import { GetAddressResponse } from '../address';
33

44
export interface BitcoinNetwork {
5-
type: string;
6-
address: string;
5+
type: 'Mainnet' | 'Testnet';
6+
address?: string;
77
}
88

99
export interface BitcoinProvider {
1010
connect: (request: string) => Promise<GetAddressResponse>;
1111
call: (request: string) => Promise<Record<string, any>>;
1212
signTransaction: (request: string) => Promise<SignTransactionResponse>;
13+
signMessage: (request: string) => Promise<string>
1314
}
1415

1516
declare global {

src/signatures/index.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { createUnsecuredToken, Json } from 'jsontokens';
2+
import { SignMessageOptions } from './types';
3+
4+
export const signMessage = async (options: SignMessageOptions) => {
5+
const provider = window.BitcoinProvider;
6+
if (!provider) {
7+
throw new Error('No Bitcoin Wallet installed');
8+
}
9+
try {
10+
const request = createUnsecuredToken(options.payload as unknown as Json);
11+
const response = await provider.signMessage(request);
12+
options.onFinish?.(response);
13+
} catch (error) {
14+
console.error('[Connect] Error during Signing request', error);
15+
options.onCancel?.();
16+
}
17+
};
18+
19+
export * from './types';

src/signatures/types.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { BitcoinNetwork } from '../provider';
2+
3+
export interface SignMessagePayload {
4+
address: string;
5+
message: string;
6+
network: BitcoinNetwork;
7+
}
8+
9+
export interface SignMessageOptions {
10+
onFinish: (response: string) => void;
11+
onCancel: () => void;
12+
payload: SignMessagePayload;
13+
}

0 commit comments

Comments
 (0)